added more robodoc entries (for system dependant functions)
[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  *    Utility functions.
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_parse_userfqdn
89  *
90  * SYNOPSIS
91  *
92  *    bool silc_parse_userfqdn(const char *string, char **left, char **right);
93  *
94  * DESCRIPTION
95  *
96  *    Parse userfqdn string which is in user@fqdn format.
97  *
98  ***/
99 bool silc_parse_userfqdn(const char *string, char **left, char **right);
100
101 /****f* silcutil/SilcUtilAPI/silc_parse_command_line
102  *
103  * SYNOPSIS
104  *
105  *    void silc_parse_command_line(unsigned char *buffer,
106  *                                 unsigned char ***parsed,
107  *                                 SilcUInt32 **parsed_lens,
108  *                                 SilcUInt32 **parsed_types,
109  *                                 SilcUInt32 *parsed_num,
110  *                                 SilcUInt32 max_args);
111  *
112  * DESCRIPTION
113  *
114  *    Parses command line. At most `max_args' is taken. Rest of the line
115  *    will be allocated as the last argument if there are more than `max_args'
116  *    arguments in the line. Note that the command name is counted as one
117  *    argument and is saved.
118  *
119  ***/
120 void silc_parse_command_line(unsigned char *buffer,
121                              unsigned char ***parsed,
122                              SilcUInt32 **parsed_lens,
123                              SilcUInt32 **parsed_types,
124                              SilcUInt32 *parsed_num,
125                              SilcUInt32 max_args);
126
127 /****f* silcutil/SilcUtilAPI/silc_format
128  *
129  * SYNOPSIS
130  *
131  *    char *silc_format(char *fmt, ...);
132  *
133  * DESCRIPTION
134  *
135  *    Formats arguments to a string and returns it after allocating memory
136  *    for it. It must be remembered to free it later.
137  *
138  ***/
139 char *silc_format(char *fmt, ...);
140
141 /****f* silcutil/SilcUtilAPI/silc_id_render
142  *
143  * SYNOPSIS
144  *
145  *    char *silc_id_render(void *id, SilcUInt16 type);
146  *
147  * DESCRIPTION
148  *
149  *    Renders ID to suitable to print for example to log file.
150  *
151  ***/
152 char *silc_id_render(void *id, SilcUInt16 type);
153
154 /****f* silcutil/SilcUtilAPI/silc_string_compare
155  *
156  * SYNOPSIS
157  *
158  *    int silc_string_compare(char *string1, char *string2);
159  *
160  * DESCRIPTION
161  *
162  *    Compares two strings. Strings may include wildcards '*' and '?'.
163  *    Returns TRUE if strings match.
164  *
165  ***/
166 int silc_string_compare(char *string1, char *string2);
167
168 /****f* silcutil/SilcUtilAPI/silc_hash_string
169  *
170  * SYNOPSIS
171  *
172  *    SilcUInt32 silc_hash_string(void *key, void *user_context);
173  *
174  * DESCRIPTION
175  *
176  *    Basic has function to hash strings. May be used with the SilcHashTable.
177  *    Note that this lowers the characters of the string (with tolower()) so
178  *    this is used usually with nicknames, channel and server names to provide
179  *    case insensitive keys.
180  *
181  ***/
182 SilcUInt32 silc_hash_string(void *key, void *user_context);
183
184 /****f* silcutil/SilcUtilAPI/silc_hash_uint
185  *
186  * SYNOPSIS
187  *
188  *    SilcUInt32 silc_hash_uint(void *key, void *user_context);
189  *
190  * DESCRIPTION
191  *
192  *    Basic hash function to hash integers. May be used with the SilcHashTable.
193  *
194  ***/
195 SilcUInt32 silc_hash_uint(void *key, void *user_context);
196
197 /****f* silcutil/SilcUtilAPI/silc_hash_ptr
198  *
199  * SYNOPSIS
200  *
201  *    SilcUInt32 silc_hash_ptr(void *key, void *user_context);
202  *
203  * DESCRIPTION
204  *
205  *    Basic hash funtion to hash pointers. May be used with the SilcHashTable.
206  *
207  ***/
208 SilcUInt32 silc_hash_ptr(void *key, void *user_context);
209
210 /****f* silcutil/SilcUtilAPI/silc_hash_id
211  *
212  * SYNOPSIS
213  *
214  *    SilcUInt32 silc_hash_id(void *key, void *user_context);
215  *
216  * DESCRIPTION
217  *
218  *    Hash a ID. The `user_context' is the ID type.
219  *
220  ***/
221 SilcUInt32 silc_hash_id(void *key, void *user_context);
222
223 /****f* silcutil/SilcUtilAPI/silc_hash_data
224  *
225  * SYNOPSIS
226  *
227  *    SilcUInt32 silc_hash_data(void *key, void *user_context);
228  *
229  * DESCRIPTION
230  *
231  *    Hash binary data. The `user_context' is the data length.
232  *
233  ***/
234 SilcUInt32 silc_hash_data(void *key, void *user_context);
235
236 /****f* silcutil/SilcUtilAPI/silc_hash_public_key
237  *
238  * SYNOPSIS
239  *
240  *    SilcUInt32 silc_hash_public_key(void *key, void *user_context);
241  *
242  * DESCRIPTION
243  *
244  *    Hashed SILC Public key.
245  *
246  ***/
247 SilcUInt32 silc_hash_public_key(void *key, void *user_context);
248
249 /****f* silcutil/SilcUtilAPI/silc_hash_string_compare
250  *
251  * SYNOPSIS
252  *
253  *    bool silc_hash_string_compare(void *key1, void *key2,
254  *                                  void *user_context);
255  *
256  * DESCRIPTION
257  *
258  *    Compares two strings. It may be used as SilcHashTable comparison
259  *    function.
260  *
261  ***/
262 bool silc_hash_string_compare(void *key1, void *key2, void *user_context);
263
264 /****f* silcutil/SilcUtilAPI/silc_hash_id_compare
265  *
266  * SYNOPSIS
267  *
268  *    bool silc_hash_id_compare(void *key1, void *key2, void *user_context);
269  *
270  * DESCRIPTION
271  *
272  *    Compares two ID's. May be used as SilcHashTable comparison function.
273  *    The Client ID's compares only the hash of the Client ID not any other
274  *    part of the Client ID. Other ID's are fully compared.
275  *
276  ***/
277 bool silc_hash_id_compare(void *key1, void *key2, void *user_context);
278
279 /****f* silcutil/SilcUtilAPI/silc_hash_client_id_compare
280  *
281  * SYNOPSIS
282  *
283  *    bool silc_hash_client_id_compare(void *key1, void *key2, void *user_context);
284  *
285  * DESCRIPTION
286  *
287  *    Compare two Client ID's entirely and not just the hash from the ID.
288  *
289  ***/
290 bool silc_hash_client_id_compare(void *key1, void *key2, void *user_context);
291
292 /****f* silcutil/SilcUtilAPI/silc_hash_data_compare
293  *
294  * SYNOPSIS
295  *
296  *    bool silc_hash_data_compare(void *key1, void *key2, void *user_context);
297  *
298  * DESCRIPTION
299  *
300  *    Compares binary data. May be used as SilcHashTable comparison function.
301  *
302  ***/
303 bool silc_hash_data_compare(void *key1, void *key2, void *user_context);
304
305 /****f* silcutil/SilcUtilAPI/silc_hash_public_key_compare
306  *
307  * SYNOPSIS
308  *
309  *    bool silc_hash_public_key_compare(void *key1, void *key2, void *user_context);
310  *
311  * DESCRIPTION
312  *
313  *    Compares two SILC Public keys. It may be used as SilcHashTable
314  *    comparison function.
315  *
316  ***/
317 bool silc_hash_public_key_compare(void *key1, void *key2, void *user_context);
318
319 /****f* silcutil/SilcUtilAPI/silc_client_chmode
320  *
321  * SYNOPSIS
322  *
323  *    char *silc_client_chmode(SilcUInt32 mode, const char *cipher,
324  *                             const char *hmac);
325  *
326  * DESCRIPTION
327  *
328  *    Parses mode mask and returns the mode as string.
329  *
330  ***/
331 char *silc_client_chmode(SilcUInt32 mode, const char *cipher,
332                          const char *hmac);
333
334 /****f* silcutil/SilcUtilAPI/silc_client_chumode
335  *
336  * SYNOPSIS
337  *
338  *    char *silc_client_chumode(SilcUInt32 mode);
339  *
340  * DESCRIPTION
341  *
342  *    Parses channel user mode mask and returns te mode as string.
343  *
344  ***/
345 char *silc_client_chumode(SilcUInt32 mode);
346
347 /****f* silcutil/SilcUtilAPI/silc_client_chumode_char
348  *
349  * SYNOPSIS
350  *
351  *    char *silc_client_chumode_char(SilcUInt32 mode);
352  *
353  * DESCRIPTION
354  *
355  *    Parses channel user mode and returns it as special mode character.
356  *
357  ***/
358 char *silc_client_chumode_char(SilcUInt32 mode);
359
360 /****f* silcutil/SilcUtilAPI/silc_fingerprint
361  *
362  * SYNOPSIS
363  *
364  *    char *silc_fingerprint(const unsigned char *data, SilcUInt32 data_len);
365  *
366  * DESCRIPTION
367  *
368  *    Creates fingerprint from data, usually used with SHA1 digests.
369  *
370  ***/
371 char *silc_fingerprint(const unsigned char *data, SilcUInt32 data_len);
372
373 /****f* silcutil/SilcUtilAPI/silc_string_is_ascii
374  *
375  * SYNOPSIS
376  *
377  *    bool silc_string_is_ascii(const unsigned char *data,
378  *                              SilcUInt32 data_len);
379  *
380  * DESCRIPTION
381  *
382  *    Return TRUE if the `data' is ASCII string.
383  *
384  ***/
385 bool silc_string_is_ascii(const unsigned char *data, SilcUInt32 data_len);
386
387 /****f* silcutil/SilcUtilAPI/silc_parse_version_string
388  *
389  * SYNOPSIS
390  *
391  *    bool silc_parse_version_string(const char *version,
392  *                                   SilcUInt32 *protocol_version,
393  *                                   char **protocol_version_string,
394  *                                   SilcUInt32 *software_version,
395  *                                   char **software_version_string,
396  *                                   char **vendor_version);
397  *
398  * DESCRIPTION
399  *
400  *    Parses SILC protocol style version string.
401  *
402  ***/
403 bool silc_parse_version_string(const char *version,
404                                SilcUInt32 *protocol_version,
405                                char **protocol_version_string,
406                                SilcUInt32 *software_version,
407                                char **software_version_string,
408                                char **vendor_version);
409
410 /****f* silcutil/SilcUtilAPI/silc_version_to_num
411  *
412  * SYNOPSIS
413  *
414  *    SilcUInt32 silc_version_to_num(const char *version);
415  *
416  * DESCRIPTION
417  *
418  *    Converts version string x.x into number representation.
419  *
420  ***/
421 SilcUInt32 silc_version_to_num(const char *version);
422
423 /****f* silcutil/SilcUtilAPI/silc_get_input
424  *
425  * SYNOPSIS
426  *
427  *    char *silc_get_input(const char *prompt, bool echo_off);
428  *
429  * DESCRIPTION
430  *
431  *    Displays input prompt on command line and takes input data from user.
432  *
433  ***/
434 char *silc_get_input(const char *prompt, bool echo_off);
435
436 /* System dependant prototypes */
437
438 /****f* silcutil/SilcUtilAPI/silc_gettimeofday
439  *
440  * SYNOPSIS
441  *
442  *    int silc_gettimeofday(struct timeval *p);
443  *
444  * DESCRIPTION
445  *
446  *    Return current time to struct timeval.
447  *
448  *    This function is system dependant.
449  *
450  ***/
451 int silc_gettimeofday(struct timeval *p);
452
453 /****f* silcutil/SilcUtilAPI/silc_string_regexify
454  *
455  * SYNOPSIS
456  *
457  *    char *silc_string_regexify(const char *string);
458  *
459  * DESCRIPTION
460  *
461  *    Inspects the `string' for wildcards and returns regex string that can
462  *    be used by the GNU regex library. A comma (`,') in the `string' means
463  *    that the string is list.
464  *
465  *    This function is system dependant.
466  *
467  ***/
468 char *silc_string_regexify(const char *string);
469
470 /****f* silcutil/SilcUtilAPI/silc_string_regex_match
471  *
472  * SYNOPSIS
473  *
474  *    int silc_string_regex_match(const char *regex, const char *string);
475  *
476  * DESCRIPTION
477  *
478  *    Matches the two strings and returns TRUE if the strings match.
479  *
480  *    This function is system dependant.
481  *
482  ***/
483 int silc_string_regex_match(const char *regex, const char *string);
484
485 /****f* silcutil/SilcUtilAPI/silc_string_match
486  *
487  * SYNOPSIS
488  *
489  *    int silc_string_match(const char *string1, const char *string2);
490  *
491  * DESCRIPTION
492  *
493  *    Do regex match to the two strings `string1' and `string2'. If the
494  *    `string2' matches the `string1' this returns TRUE.
495  *
496  *    This function is system dependant.
497  *
498  ***/
499 int silc_string_match(const char *string1, const char *string2);
500
501 /****f* silcutil/SilcUtilAPI/silc_get_username
502  *
503  * SYNOPSIS
504  *
505  *    char *silc_get_username();
506  *
507  * DESCRIPTION
508  *
509  *    Returns the username of the user. If the global variable LOGNAME
510  *    does not exists we will get the name from the passwd file.
511  *
512  *    This function is system dependant.
513  *
514  ***/
515 char *silc_get_username();
516
517 /****f* silcutil/SilcUtilAPI/silc_get_real_name
518  *
519  * SYNOPSIS
520  *
521  *    char *silc_get_real_name();
522  *
523  * DESCRIPTION
524  *
525  *    Returns the real name of ther user from the passwd file.
526  *
527  *    This function is system dependant.
528  *
529  ***/
530 char *silc_get_real_name();
531
532 #endif  /* !SILCUTIL_H */