5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1997 - 2002 Pekka Riikonen
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.
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.
20 /****h* silcutil/SILC Utilities
31 /****f* silcutil/SilcUtilAPI/silc_gets
35 * int silc_gets(char *dest, int destlen, const char *src, int srclen,
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.
45 int silc_gets(char *dest, int destlen, const char *src, int srclen, int begin);
47 /****f* silcutil/SilcUtilAPI/silc_check_line
51 * int silc_check_line(char *buf);
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.
60 int silc_check_line(char *buf);
62 /****f* silcutil/SilcUtilAPI/silc_get_time
66 * const char *silc_get_time(SilcUInt32 timeval)
70 * Returns time as string. If the the `timeval' is non-zero that
71 * value is returned as string. If it is zero the current time of the
72 * local machine is returned.
75 const char *silc_get_time(SilcUInt32 timeval);
77 /****f* silcutil/SilcUtilAPI/silc_to_upper
81 * bool silc_to_upper(const char *string, char *dest, SilcUInt32 dest_size);
85 * Converts string to capital characters.
88 bool silc_to_upper(const char *string, char *dest, SilcUInt32 dest_size);
90 /****f* silcutil/SilcUtilAPI/silc_to_lower
94 * bool silc_to_lower(const char *string, char *dest, SilcUInt32 dest_size);
98 * Converts string to capital characters.
101 bool silc_to_lower(const char *string, char *dest, SilcUInt32 dest_size);
103 /****f* silcutil/SilcUtilAPI/silc_parse_userfqdn
107 * bool silc_parse_userfqdn(const char *string, char **left, char **right);
111 * Parse userfqdn string which is in user@fqdn format.
114 bool silc_parse_userfqdn(const char *string, char **left, char **right);
116 /****f* silcutil/SilcUtilAPI/silc_parse_command_line
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);
129 * Parses command line. At most `max_args' is taken. Rest of the line
130 * will be allocated as the last argument if there are more than `max_args'
131 * arguments in the line. Note that the command name is counted as one
132 * argument and is saved.
135 void silc_parse_command_line(unsigned char *buffer,
136 unsigned char ***parsed,
137 SilcUInt32 **parsed_lens,
138 SilcUInt32 **parsed_types,
139 SilcUInt32 *parsed_num,
140 SilcUInt32 max_args);
142 /****f* silcutil/SilcUtilAPI/silc_format
146 * char *silc_format(char *fmt, ...);
150 * Formats arguments to a string and returns it after allocating memory
151 * for it. It must be remembered to free it later.
154 char *silc_format(char *fmt, ...);
156 /****f* silcutil/SilcUtilAPI/silc_id_render
160 * char *silc_id_render(void *id, SilcUInt16 type);
164 * Renders ID to suitable to print for example to log file.
167 char *silc_id_render(void *id, SilcUInt16 type);
169 /****f* silcutil/SilcUtilAPI/silc_string_compare
173 * int silc_string_compare(char *string1, char *string2);
177 * Compares two strings. Strings may include wildcards '*' and '?'.
178 * Returns TRUE if strings match.
181 int silc_string_compare(char *string1, char *string2);
183 /****f* silcutil/SilcUtilAPI/silc_hash_string
187 * SilcUInt32 silc_hash_string(void *key, void *user_context);
191 * Basic has function to hash strings. May be used with the SilcHashTable.
192 * Note that this lowers the characters of the string (with tolower()) so
193 * this is used usually with nicknames, channel and server names to provide
194 * case insensitive keys.
197 SilcUInt32 silc_hash_string(void *key, void *user_context);
199 /****f* silcutil/SilcUtilAPI/silc_hash_uint
203 * SilcUInt32 silc_hash_uint(void *key, void *user_context);
207 * Basic hash function to hash integers. May be used with the SilcHashTable.
210 SilcUInt32 silc_hash_uint(void *key, void *user_context);
212 /****f* silcutil/SilcUtilAPI/silc_hash_ptr
216 * SilcUInt32 silc_hash_ptr(void *key, void *user_context);
220 * Basic hash funtion to hash pointers. May be used with the SilcHashTable.
223 SilcUInt32 silc_hash_ptr(void *key, void *user_context);
225 /****f* silcutil/SilcUtilAPI/silc_hash_id
229 * SilcUInt32 silc_hash_id(void *key, void *user_context);
233 * Hash a ID. The `user_context' is the ID type.
236 SilcUInt32 silc_hash_id(void *key, void *user_context);
238 /****f* silcutil/SilcUtilAPI/silc_hash_client_id_hash
242 * SilcUInt32 silc_hash_client_id_hash(void *key, void *user_context)
246 * Hash Client ID's hash.
249 SilcUInt32 silc_hash_client_id_hash(void *key, void *user_context);
251 /****f* silcutil/SilcUtilAPI/silc_hash_data
255 * SilcUInt32 silc_hash_data(void *key, void *user_context);
259 * Hash binary data. The `user_context' is the data length.
262 SilcUInt32 silc_hash_data(void *key, void *user_context);
264 /****f* silcutil/SilcUtilAPI/silc_hash_public_key
268 * SilcUInt32 silc_hash_public_key(void *key, void *user_context);
272 * Hashed SILC Public key.
275 SilcUInt32 silc_hash_public_key(void *key, void *user_context);
277 /****f* silcutil/SilcUtilAPI/silc_hash_string_compare
281 * bool silc_hash_string_compare(void *key1, void *key2,
282 * void *user_context);
286 * Compares two strings. It may be used as SilcHashTable comparison
290 bool silc_hash_string_compare(void *key1, void *key2, void *user_context);
292 /****f* silcutil/SilcUtilAPI/silc_hash_id_compare
296 * bool silc_hash_id_compare(void *key1, void *key2, void *user_context);
300 * Compares two ID's. May be used as SilcHashTable comparison function.
301 * The Client ID's compares only the hash of the Client ID not any other
302 * part of the Client ID. Other ID's are fully compared.
305 bool silc_hash_id_compare(void *key1, void *key2, void *user_context);
307 /****f* silcutil/SilcUtilAPI/silc_hash_client_id_compare
311 * bool silc_hash_client_id_compare(void *key1, void *key2, void *user_context);
315 * Compare two Client ID's entirely and not just the hash from the ID.
318 bool silc_hash_client_id_compare(void *key1, void *key2, void *user_context);
320 /****f* silcutil/SilcUtilAPI/silc_hash_data_compare
324 * bool silc_hash_data_compare(void *key1, void *key2, void *user_context);
328 * Compares binary data. May be used as SilcHashTable comparison function.
331 bool silc_hash_data_compare(void *key1, void *key2, void *user_context);
333 /****f* silcutil/SilcUtilAPI/silc_hash_public_key_compare
337 * bool silc_hash_public_key_compare(void *key1, void *key2, void *user_context);
341 * Compares two SILC Public keys. It may be used as SilcHashTable
342 * comparison function.
345 bool silc_hash_public_key_compare(void *key1, void *key2, void *user_context);
347 /****f* silcutil/SilcUtilAPI/silc_client_chmode
351 * char *silc_client_chmode(SilcUInt32 mode, const char *cipher,
356 * Parses mode mask and returns the mode as string.
359 char *silc_client_chmode(SilcUInt32 mode, const char *cipher,
362 /****f* silcutil/SilcUtilAPI/silc_client_chumode
366 * char *silc_client_chumode(SilcUInt32 mode);
370 * Parses channel user mode mask and returns te mode as string.
373 char *silc_client_chumode(SilcUInt32 mode);
375 /****f* silcutil/SilcUtilAPI/silc_client_chumode_char
379 * char *silc_client_chumode_char(SilcUInt32 mode);
383 * Parses channel user mode and returns it as special mode character.
386 char *silc_client_chumode_char(SilcUInt32 mode);
388 /****f* silcutil/SilcUtilAPI/silc_fingerprint
392 * char *silc_fingerprint(const unsigned char *data, SilcUInt32 data_len);
396 * Creates fingerprint from data, usually used with SHA1 digests.
399 char *silc_fingerprint(const unsigned char *data, SilcUInt32 data_len);
401 /****f* silcutil/SilcUtilAPI/silc_string_is_ascii
405 * bool silc_string_is_ascii(const unsigned char *data,
406 * SilcUInt32 data_len);
410 * Return TRUE if the `data' is ASCII string.
413 bool silc_string_is_ascii(const unsigned char *data, SilcUInt32 data_len);
415 /****f* silcutil/SilcUtilAPI/silc_parse_version_string
419 * bool silc_parse_version_string(const char *version,
420 * SilcUInt32 *protocol_version,
421 * char **protocol_version_string,
422 * SilcUInt32 *software_version,
423 * char **software_version_string,
424 * char **vendor_version);
428 * Parses SILC protocol style version string.
431 bool silc_parse_version_string(const char *version,
432 SilcUInt32 *protocol_version,
433 char **protocol_version_string,
434 SilcUInt32 *software_version,
435 char **software_version_string,
436 char **vendor_version);
438 /****f* silcutil/SilcUtilAPI/silc_version_to_num
442 * SilcUInt32 silc_version_to_num(const char *version);
446 * Converts version string x.x into number representation.
449 SilcUInt32 silc_version_to_num(const char *version);
451 /****f* silcutil/SilcUtilAPI/silc_get_input
455 * char *silc_get_input(const char *prompt, bool echo_off);
459 * Displays input prompt on command line and takes input data from user.
462 char *silc_get_input(const char *prompt, bool echo_off);
464 /* System dependant prototypes */
466 /****f* silcutil/SilcUtilAPI/silc_gettimeofday
470 * int silc_gettimeofday(struct timeval *p);
474 * Return current time to struct timeval. This function is system
475 * dependant. Returns 0 on success and -1 on error.
478 int silc_gettimeofday(struct timeval *p);
480 /****f* silcutil/SilcUtilAPI/silc_compare_timeval
484 * bool silc_compare_timeval(struct timeval *smaller,
485 * struct timeval *bigger)
489 * Compare two timeval structures and return TRUE if the first
490 * time value is smaller than the second time value.
493 bool silc_compare_timeval(struct timeval *smaller,
494 struct timeval *bigger);
496 /****f* silcutil/SilcUtilAPI/silc_string_regexify
500 * char *silc_string_regexify(const char *string);
504 * Inspects the `string' for wildcards and returns regex string that can
505 * be used by the GNU regex library. A comma (`,') in the `string' means
506 * that the string is list.
508 * This function is system dependant.
511 char *silc_string_regexify(const char *string);
513 /****f* silcutil/SilcUtilAPI/silc_string_regex_match
517 * int silc_string_regex_match(const char *regex, const char *string);
521 * Matches the two strings and returns TRUE if the strings match.
523 * This function is system dependant.
526 int silc_string_regex_match(const char *regex, const char *string);
528 /****f* silcutil/SilcUtilAPI/silc_string_match
532 * int silc_string_match(const char *string1, const char *string2);
536 * Do regex match to the two strings `string1' and `string2'. If the
537 * `string2' matches the `string1' this returns TRUE.
539 * This function is system dependant.
542 int silc_string_match(const char *string1, const char *string2);
544 /****f* silcutil/SilcUtilAPI/silc_get_username
548 * char *silc_get_username();
552 * Returns the username of the user. If the global variable LOGNAME
553 * does not exists we will get the name from the passwd file.
555 * This function is system dependant.
558 char *silc_get_username();
560 /****f* silcutil/SilcUtilAPI/silc_get_real_name
564 * char *silc_get_real_name();
568 * Returns the real name of ther user from the passwd file.
570 * This function is system dependant.
573 char *silc_get_real_name();
575 /****f* silcutil/SilcUtilAPI/silc_get_mode_list
579 * bool silc_get_mode_list(SilcBuffer mode_list, SilcUInt32 mode_list_count,
580 * SilcUInt32 **list);
584 * Returns modes from list of 32 bit MSB first order values that are
585 * encoded one after the other in the `mode_list' into the `list'
586 * array. The caller must free the returned list. Return FALSE if
587 * there is error parsing the list.
590 bool silc_get_mode_list(SilcBuffer mode_list, SilcUInt32 mode_list_count,
593 /****f* silcutil/SilcUtilAPI/silc_get_status_message
597 * char *silc_get_status_message(SilcStatus status)
601 * Returns status message string
604 const char *silc_get_status_message(unsigned char status);
606 /****f* silcutil/SilcUtilAPI/silc_get_packet_name
610 * char *silc_get_packet_name(SilcPacketType type);
614 * Returns the name corresponding packet type `type'.
617 const char *silc_get_packet_name(unsigned char type);
619 /****f* silcutil/SilcUtilAPI/silc_get_command_name
623 * char *silc_get_command_name(SilcCommand command);
627 * Returns the name corresponding SILC command `command'.
630 const char *silc_get_command_name(unsigned char command);
632 #endif /* !SILCUTIL_H */