Protocol version 1.2 integrations
[silc.git] / lib / silccore / silcargument.h
1 /*
2
3   silcargument.h 
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2001 - 2002 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 /****h* silccore/SILC Argument Interface
21  *
22  * DESCRIPTION
23  *
24  * Implementation of the Argument Payload, that is used to include 
25  * argument to other payload that needs arguments.
26  *
27  ***/
28
29 #ifndef SILCPAYLOAD_H
30 #define SILCPAYLOAD_H
31
32 /****s* silccore/SilcArgumentAPI/SilcArgumentPayload
33  *
34  * NAME
35  * 
36  *    typedef struct SilcArgumentPayloadStruct *SilcArgumentPayload;
37  *
38  * DESCRIPTION
39  *
40  *    This context is the actual Argument Payload and is allocated
41  *    by silc_argument_payload_parse and given as argument usually to
42  *    all silc_argument_payload_* functions.  It is freed by the
43  *    silc_argument_payload_free function.
44  *
45  ***/
46 typedef struct SilcArgumentPayloadStruct *SilcArgumentPayload;
47
48 /****f* silccore/SilcArgumentAPI/silc_argument_payload_parse
49  *
50  * SYNOPSIS
51  *
52  *    SilcArgumentPayload 
53  *    silc_argument_payload_parse(const unsigned char *payload,
54  *                                SilcUInt32 payload_len,
55  *                                SilcUInt32 argc);
56  *
57  * DESCRIPTION
58  *
59  *    Parses arguments and returns them into Argument Payload structure.
60  *    the `buffer' is raw Argument Payload data buffer. The `argc' is
61  *    the number of arguments in the Argument Payload. The caller must
62  *    know the number of the arguments. This is always known as the
63  *    Argument payload is associated with other payloads which defines
64  *    the number of the arguments.
65  *
66  ***/
67 SilcArgumentPayload silc_argument_payload_parse(const unsigned char *payload,
68                                                 SilcUInt32 payload_len,
69                                                 SilcUInt32 argc);
70
71 /****f* silccore/SilcArgumentAPI/silc_argument_payload_encode
72  *
73  * SYNOPSIS
74  *
75  *    SilcBuffer silc_argument_payload_encode(SilcUInt32 argc,
76  *                                            unsigned char **argv,
77  *                                            SilcUInt32 *argv_lens,
78  *                                            SilcUInt32 *argv_types);
79  *
80  * DESCRIPTION
81  *
82  *    Encodes arguments in to Argument Paylods returning them to SilcBuffer.
83  *    The `argv' is the array of the arguments, the `argv_lens' array of
84  *    the length of the `argv' arguments and the `argv_types' array of
85  *    the argument types of the `argv' arguments. The `argc' is the 
86  *    number of arguments.
87  *
88  ***/
89 SilcBuffer silc_argument_payload_encode(SilcUInt32 argc,
90                                         unsigned char **argv,
91                                         SilcUInt32 *argv_lens,
92                                         SilcUInt32 *argv_types);
93
94 /****f* silccore/SilcArgumentAPI/silc_argument_payload_encode_payload
95  *
96  * SYNOPSIS
97  *
98  *    SilcBuffer 
99  *    silc_argument_payload_encode_payload(SilcArgumentPayload payload);
100  *
101  * DESCRIPTION
102  *
103  *    Same as silc_argument_payload_encode but encodes the payload from
104  *    already allocated SilcArgumentPayload structure instead of raw data.
105  *
106  ***/
107 SilcBuffer silc_argument_payload_encode_payload(SilcArgumentPayload payload);
108
109 /****f* silccore/SilcArgumentAPI/silc_argument_payload_free
110  *
111  * SYNOPSIS
112  *
113  *    void silc_argument_payload_free(SilcArgumentPayload payload);
114  *
115  * DESCRIPTION
116  *
117  *    Frees the Argument Payload and all data in it.
118  *
119  ***/
120 void silc_argument_payload_free(SilcArgumentPayload payload);
121
122 /****f* silccore/SilcArgumentAPI/silc_argument_get_arg_num
123  *
124  * SYNOPSIS
125  *
126  *    SilcUInt32 silc_argument_get_arg_num(SilcArgumentPayload payload);
127  *
128  * DESCRIPTION
129  *
130  *    Returns the number of argument in the Argument Payload.
131  *
132  ***/
133 SilcUInt32 silc_argument_get_arg_num(SilcArgumentPayload payload);
134
135 /****f* silccore/SilcArgumentAPI/silc_argument_get_first_arg
136  *
137  * SYNOPSIS
138  *
139  *    unsigned char *silc_argument_get_first_arg(SilcArgumentPayload payload,
140  *                                               SilcUInt32 *ret_len);
141  *
142  * DESCRIPTION
143  *
144  *    Returns the first argument in the Argument Payload. The lenght
145  *    of the argument is returned to `ret_len'. The caller must not
146  *    free the returned argument. Returns NULL on error.
147  *
148  ***/
149 unsigned char *silc_argument_get_first_arg(SilcArgumentPayload payload,
150                                            SilcUInt32 *ret_len);
151
152 /****f* silccore/SilcArgumentAPI/silc_argument_get_next_arg
153  *
154  * SYNOPSIS
155  *
156  *    unsigned char *silc_argument_get_next_arg(SilcArgumentPayload payload,
157  *                                              SilcUInt32 *ret_len);
158  *
159  * DESCRIPTION
160  *
161  *    Returns next argument from the Argument Payload. The length of
162  *    the argument is returned to `ret_len'. The caller must not free
163  *    the returned argument. This returns NULL when there are no more
164  *    arguments in the payload.
165  *
166  ***/
167 unsigned char *silc_argument_get_next_arg(SilcArgumentPayload payload,
168                                           SilcUInt32 *ret_len);
169
170 /****f* silccore/SilcArgumentAPI/silc_argument_get_arg_type
171  *
172  * SYNOPSIS
173  *
174  *    unsigned char *silc_argument_get_arg_type(SilcArgumentPayload payload,
175  *                                              SilcUInt32 type,
176  *                                              SilcUInt32 *ret_len);
177  *
178  * DESCRIPTION
179  *
180  *    Returns argument by type. The returned argument has type `type'
181  *    in the Argument Payload. Each argument has their own type (or zero
182  *    if no specific type is set). The length of the argument is returned
183  *    to the `ret_len'. The caller must not free the returned argument.
184  *    Returns NULL on error.
185  *
186  ***/
187 unsigned char *silc_argument_get_arg_type(SilcArgumentPayload payload,
188                                           SilcUInt32 type,
189                                           SilcUInt32 *ret_len);
190
191 #endif