robodocumented lib/silcutil/silcutil.h.
[crypto.git] / lib / silcutil / silcutil.h
1 /*
2
3   silcutil.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 1997 - 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* silcutil/SILC Utilities
21  *
22  * DESCRIPTION
23  *
24  *    XXX
25  *
26  ***/
27
28 #ifndef SILCUTIL_H
29 #define SILCUTIL_H
30
31 /****f* silcutil/SilcUtilAPI/silc_gets
32  *
33  * SYNOPSIS
34  *
35  *    int silc_gets(char *dest, int destlen, const char *src, int srclen,
36  *                  int begin);
37  *
38  * DESCRIPTION
39  *
40  *    Gets line from a buffer. Stops reading when a newline or EOF occurs.
41  *    This doesn't remove the newline sign from the destination buffer. The
42  *    argument begin is returned and should be passed again for the function.
43  *
44  ***/
45 int silc_gets(char *dest, int destlen, const char *src, int srclen, int begin);
46
47 /****f* silcutil/SilcUtilAPI/silc_check_line
48  *
49  * SYNOPSIS
50  *
51  *    int silc_check_line(char *buf);
52  *
53  * DESCRIPTION
54  *
55  *    Checks line for illegal characters. Return -1 when illegal character
56  *    were found. This is used to check for bad lines when reading data from
57  *    for example a configuration file.
58  *
59  ***/
60 int silc_check_line(char *buf);
61
62 /****f* silcutil/SilcUtilAPI/silc_get_time
63  *
64  * SYNOPSIS
65  *
66  *    char *silc_get_time();
67  *
68  * DESCRIPTION
69  *
70  *    Returns current time as string.
71  *
72  ***/
73 char *silc_get_time();
74
75 /****f* silcutil/SilcUtilAPI/silc_to_upper
76  *
77  * SYNOPSIS
78  *
79  *    char *silc_to_upper(char *string);
80  *
81  * DESCRIPTION
82  *
83  *    Converts string to capital characters.
84  *
85  ***/
86 char *silc_to_upper(char *string);
87
88 /****f* silcutil/SilcUtilAPI/silc_encode_pem
89  *
90  * SYNOPSIS
91  *
92  *    char *silc_encode_pem(unsigned char *data, SilcUInt32 len);
93  *
94  * DESCRIPTION
95  *
96  *    Encodes data into PEM encoding. Returns NULL terminated PEM encoded
97  *    data string. Note: This is originally public domain code and is
98  *    still PD.
99  *
100  ***/
101 char *silc_encode_pem(unsigned char *data, SilcUInt32 len);
102
103 /****f* silcutil/SilcUtilAPI/silc_encode_pem_file
104  *
105  * SYNOPSIS
106  *
107  *    char *silc_encode_pem_file(unsigned char *data, SilcUInt32 data_len);
108  *
109  * DESCRIPTION
110  *
111  *    Same as silc_encode_pem() but puts newline ('\n') every 72 characters.
112  *
113  ***/
114 char *silc_encode_pem_file(unsigned char *data, SilcUInt32 data_len);
115
116 /****f* silcutil/SilcUtilAPI/silc_decode_pem
117  *
118  * SYNOPSIS
119  *
120  *    unsigned char *silc_decode_pem(unsigned char *pem, SilcUInt32 pem_len,
121  *                                   SilcUInt32 *ret_len);
122  *
123  * DESCRIPTION
124  *
125  *    Decodes PEM into data. Returns the decoded data. Note: This is
126  *    originally public domain code and is still PD.
127  *
128  ***/
129 unsigned char *silc_decode_pem(unsigned char *pem, SilcUInt32 pem_len,
130                                SilcUInt32 *ret_len);
131
132 /****f* silcutil/SilcUtilAPI/silc_parse_userfqdn
133  *
134  * SYNOPSIS
135  *
136  *    bool silc_parse_userfqdn(const char *string, char **left, char **right);
137  *
138  * DESCRIPTION
139  *
140  *    Parse userfqdn string which is in user@fqdn format.
141  *
142  ***/
143 bool silc_parse_userfqdn(const char *string, char **left, char **right);
144
145 /****f* silcutil/SilcUtilAPI/silc_parse_command_line
146  *
147  * SYNOPSIS
148  *
149  *    void silc_parse_command_line(unsigned char *buffer,
150  *                                 unsigned char ***parsed,
151  *                                 SilcUInt32 **parsed_lens,
152  *                                 SilcUInt32 **parsed_types,
153  *                                 SilcUInt32 *parsed_num,
154  *                                 SilcUInt32 max_args);
155  *
156  * DESCRIPTION
157  *
158  *    Parses command line. At most `max_args' is taken. Rest of the line
159  *    will be allocated as the last argument if there are more than `max_args'
160  *    arguments in the line. Note that the command name is counted as one
161  *    argument and is saved.
162  *
163  ***/
164 void silc_parse_command_line(unsigned char *buffer,
165                              unsigned char ***parsed,
166                              SilcUInt32 **parsed_lens,
167                              SilcUInt32 **parsed_types,
168                              SilcUInt32 *parsed_num,
169                              SilcUInt32 max_args);
170
171 /****f* silcutil/SilcUtilAPI/silc_format
172  *
173  * SYNOPSIS
174  *
175  *    char *silc_format(char *fmt, ...);
176  *
177  * DESCRIPTION
178  *
179  *    Formats arguments to a string and returns it after allocating memory
180  *    for it. It must be remembered to free it later.
181  *
182  ***/
183 char *silc_format(char *fmt, ...);
184
185 /****f* silcutil/SilcUtilAPI/silc_id_render
186  *
187  * SYNOPSIS
188  *
189  *    char *silc_id_render(void *id, SilcUInt16 type);
190  *
191  * DESCRIPTION
192  *
193  *    Renders ID to suitable to print for example to log file.
194  *
195  ***/
196 char *silc_id_render(void *id, SilcUInt16 type);
197
198 /****f* silcutil/SilcUtilAPI/silc_string_compare
199  *
200  * SYNOPSIS
201  *
202  *    int silc_string_compare(char *string1, char *string2);
203  *
204  * DESCRIPTION
205  *
206  *    Compares two strings. Strings may include wildcards '*' and '?'.
207  *    Returns TRUE if strings match.
208  *
209  ***/
210 int silc_string_compare(char *string1, char *string2);
211
212 /****f* silcutil/SilcUtilAPI/silc_hash_string
213  *
214  * SYNOPSIS
215  *
216  *    SilcUInt32 silc_hash_string(void *key, void *user_context);
217  *
218  * DESCRIPTION
219  *
220  *    Basic has function to hash strings. May be used with the SilcHashTable.
221  *    Note that this lowers the characters of the string (with tolower()) so
222  *    this is used usually with nicknames, channel and server names to provide
223  *    case insensitive keys.
224  *
225  ***/
226 SilcUInt32 silc_hash_string(void *key, void *user_context);
227
228 /****f* silcutil/SilcUtilAPI/silc_hash_uint
229  *
230  * SYNOPSIS
231  *
232  *    SilcUInt32 silc_hash_uint(void *key, void *user_context);
233  *
234  * DESCRIPTION
235  *
236  *    Basic hash function to hash integers. May be used with the SilcHashTable.
237  *
238  ***/
239 SilcUInt32 silc_hash_uint(void *key, void *user_context);
240
241 /****f* silcutil/SilcUtilAPI/silc_hash_ptr
242  *
243  * SYNOPSIS
244  *
245  *    SilcUInt32 silc_hash_ptr(void *key, void *user_context);
246  *
247  * DESCRIPTION
248  *
249  *    Basic hash funtion to hash pointers. May be used with the SilcHashTable.
250  *
251  ***/
252 SilcUInt32 silc_hash_ptr(void *key, void *user_context);
253
254 /****f* silcutil/SilcUtilAPI/silc_hash_id
255  *
256  * SYNOPSIS
257  *
258  *    SilcUInt32 silc_hash_id(void *key, void *user_context);
259  *
260  * DESCRIPTION
261  *
262  *    Hash a ID. The `user_context' is the ID type.
263  *
264  ***/
265 SilcUInt32 silc_hash_id(void *key, void *user_context);
266
267 /****f* silcutil/SilcUtilAPI/silc_hash_data
268  *
269  * SYNOPSIS
270  *
271  *    SilcUInt32 silc_hash_data(void *key, void *user_context);
272  *
273  * DESCRIPTION
274  *
275  *    Hash binary data. The `user_context' is the data length.
276  *
277  ***/
278 SilcUInt32 silc_hash_data(void *key, void *user_context);
279
280 /****f* silcutil/SilcUtilAPI/silc_hash_public_key
281  *
282  * SYNOPSIS
283  *
284  *    SilcUInt32 silc_hash_public_key(void *key, void *user_context);
285  *
286  * DESCRIPTION
287  *
288  *    Hashed SILC Public key.
289  *
290  ***/
291 SilcUInt32 silc_hash_public_key(void *key, void *user_context);
292
293 /****f* silcutil/SilcUtilAPI/silc_hash_string_compare
294  *
295  * SYNOPSIS
296  *
297  *    bool silc_hash_string_compare(void *key1, void *key2,
298  *                                  void *user_context);
299  *
300  * DESCRIPTION
301  *
302  *    Compares two strings. It may be used as SilcHashTable comparison
303  *    function.
304  *
305  ***/
306 bool silc_hash_string_compare(void *key1, void *key2, void *user_context);
307
308 /****f* silcutil/SilcUtilAPI/silc_hash_id_compare
309  *
310  * SYNOPSIS
311  *
312  *    bool silc_hash_id_compare(void *key1, void *key2, void *user_context);
313  *
314  * DESCRIPTION
315  *
316  *    Compares two ID's. May be used as SilcHashTable comparison function.
317  *    The Client ID's compares only the hash of the Client ID not any other
318  *    part of the Client ID. Other ID's are fully compared.
319  *
320  ***/
321 bool silc_hash_id_compare(void *key1, void *key2, void *user_context);
322
323 /****f* silcutil/SilcUtilAPI/silc_hash_client_id_compare
324  *
325  * SYNOPSIS
326  *
327  *    bool silc_hash_client_id_compare(void *key1, void *key2, void *user_context);
328  *
329  * DESCRIPTION
330  *
331  *    Compare two Client ID's entirely and not just the hash from the ID.
332  *
333  ***/
334 bool silc_hash_client_id_compare(void *key1, void *key2, void *user_context);
335
336 /****f* silcutil/SilcUtilAPI/silc_hash_data_compare
337  *
338  * SYNOPSIS
339  *
340  *    bool silc_hash_data_compare(void *key1, void *key2, void *user_context);
341  *
342  * DESCRIPTION
343  *
344  *    Compares binary data. May be used as SilcHashTable comparison function.
345  *
346  ***/
347 bool silc_hash_data_compare(void *key1, void *key2, void *user_context);
348
349 /****f* silcutil/SilcUtilAPI/silc_hash_public_key_compare
350  *
351  * SYNOPSIS
352  *
353  *    bool silc_hash_public_key_compare(void *key1, void *key2, void *user_context);
354  *
355  * DESCRIPTION
356  *
357  *    Compares two SILC Public keys. It may be used as SilcHashTable
358  *    comparison function.
359  *
360  ***/
361 bool silc_hash_public_key_compare(void *key1, void *key2, void *user_context);
362
363 /****f* silcutil/SilcUtilAPI/silc_client_chmode
364  *
365  * SYNOPSIS
366  *
367  *    char *silc_client_chmode(SilcUInt32 mode, const char *cipher,
368  *                             const char *hmac);
369  *
370  * DESCRIPTION
371  *
372  *    Parses mode mask and returns the mode as string.
373  *
374  ***/
375 char *silc_client_chmode(SilcUInt32 mode, const char *cipher,
376                          const char *hmac);
377
378 /****f* silcutil/SilcUtilAPI/silc_client_chumode
379  *
380  * SYNOPSIS
381  *
382  *    char *silc_client_chumode(SilcUInt32 mode);
383  *
384  * DESCRIPTION
385  *
386  *    Parses channel user mode mask and returns te mode as string.
387  *
388  ***/
389 char *silc_client_chumode(SilcUInt32 mode);
390
391 /****f* silcutil/SilcUtilAPI/silc_client_chumode_char
392  *
393  * SYNOPSIS
394  *
395  *    char *silc_client_chumode_char(SilcUInt32 mode);
396  *
397  * DESCRIPTION
398  *
399  *    Parses channel user mode and returns it as special mode character.
400  *
401  ***/
402 char *silc_client_chumode_char(SilcUInt32 mode);
403
404 /****f* silcutil/SilcUtilAPI/silc_fingerprint
405  *
406  * SYNOPSIS
407  *
408  *    char *silc_fingerprint(const unsigned char *data, SilcUInt32 data_len);
409  *
410  * DESCRIPTION
411  *
412  *    Creates fingerprint from data, usually used with SHA1 digests.
413  *
414  ***/
415 char *silc_fingerprint(const unsigned char *data, SilcUInt32 data_len);
416
417 /****f* silcutil/SilcUtilAPI/silc_string_is_ascii
418  *
419  * SYNOPSIS
420  *
421  *    bool silc_string_is_ascii(const unsigned char *data,
422  *                              SilcUInt32 data_len);
423  *
424  * DESCRIPTION
425  *
426  *    Return TRUE if the `data' is ASCII string.
427  *
428  ***/
429 bool silc_string_is_ascii(const unsigned char *data, SilcUInt32 data_len);
430
431 /****f* silcutil/SilcUtilAPI/silc_parse_version_string
432  *
433  * SYNOPSIS
434  *
435  *    bool silc_parse_version_string(const char *version,
436  *                                   SilcUInt32 *protocol_version,
437  *                                   char **protocol_version_string,
438  *                                   SilcUInt32 *software_version,
439  *                                   char **software_version_string,
440  *                                   char **vendor_version);
441  *
442  * DESCRIPTION
443  *
444  *    Parses SILC protocol style version string.
445  *
446  ***/
447 bool silc_parse_version_string(const char *version,
448                                SilcUInt32 *protocol_version,
449                                char **protocol_version_string,
450                                SilcUInt32 *software_version,
451                                char **software_version_string,
452                                char **vendor_version);
453
454 /****f* silcutil/SilcUtilAPI/silc_version_to_num
455  *
456  * SYNOPSIS
457  *
458  *    SilcUInt32 silc_version_to_num(const char *version);
459  *
460  * DESCRIPTION
461  *
462  *    Converts version string x.x into number representation.
463  *
464  ***/
465 SilcUInt32 silc_version_to_num(const char *version);
466
467 /****f* silcutil/SilcUtilAPI/silc_get_input
468  *
469  * SYNOPSIS
470  *
471  *    char *silc_get_input(const char *prompt, bool echo_off);
472  *
473  * DESCRIPTION
474  *
475  *    Displays input prompt on command line and takes input data from user.
476  *
477  ***/
478 char *silc_get_input(const char *prompt, bool echo_off);
479
480 /* XXX - System dependant prototypes */
481
482 int silc_gettimeofday(struct timeval *p);
483 char *silc_string_regexify(const char *string);
484 int silc_string_regex_match(const char *regex, const char *string);
485 int silc_string_match(const char *string1, const char *string2);
486 char *silc_get_username();
487 char *silc_get_real_name();
488
489 #endif  /* !SILCUTIL_H */