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 * char *silc_get_time();
70 * Returns current time as string.
73 char *silc_get_time();
75 /****f* silcutil/SilcUtilAPI/silc_to_upper
79 * bool silc_to_upper(const char *string, char *dest, SilcUInt32 dest_size);
83 * Converts string to capital characters.
86 bool silc_to_upper(const char *string, char *dest, SilcUInt32 dest_size);
88 /****f* silcutil/SilcUtilAPI/silc_to_lower
92 * bool silc_to_lower(const char *string, char *dest, SilcUInt32 dest_size);
96 * Converts string to capital characters.
99 bool silc_to_lower(const char *string, char *dest, SilcUInt32 dest_size);
101 /****f* silcutil/SilcUtilAPI/silc_parse_userfqdn
105 * bool silc_parse_userfqdn(const char *string, char **left, char **right);
109 * Parse userfqdn string which is in user@fqdn format.
112 bool silc_parse_userfqdn(const char *string, char **left, char **right);
114 /****f* silcutil/SilcUtilAPI/silc_parse_command_line
118 * void silc_parse_command_line(unsigned char *buffer,
119 * unsigned char ***parsed,
120 * SilcUInt32 **parsed_lens,
121 * SilcUInt32 **parsed_types,
122 * SilcUInt32 *parsed_num,
123 * SilcUInt32 max_args);
127 * Parses command line. At most `max_args' is taken. Rest of the line
128 * will be allocated as the last argument if there are more than `max_args'
129 * arguments in the line. Note that the command name is counted as one
130 * argument and is saved.
133 void silc_parse_command_line(unsigned char *buffer,
134 unsigned char ***parsed,
135 SilcUInt32 **parsed_lens,
136 SilcUInt32 **parsed_types,
137 SilcUInt32 *parsed_num,
138 SilcUInt32 max_args);
140 /****f* silcutil/SilcUtilAPI/silc_format
144 * char *silc_format(char *fmt, ...);
148 * Formats arguments to a string and returns it after allocating memory
149 * for it. It must be remembered to free it later.
152 char *silc_format(char *fmt, ...);
154 /****f* silcutil/SilcUtilAPI/silc_id_render
158 * char *silc_id_render(void *id, SilcUInt16 type);
162 * Renders ID to suitable to print for example to log file.
165 char *silc_id_render(void *id, SilcUInt16 type);
167 /****f* silcutil/SilcUtilAPI/silc_string_compare
171 * int silc_string_compare(char *string1, char *string2);
175 * Compares two strings. Strings may include wildcards '*' and '?'.
176 * Returns TRUE if strings match.
179 int silc_string_compare(char *string1, char *string2);
181 /****f* silcutil/SilcUtilAPI/silc_hash_string
185 * SilcUInt32 silc_hash_string(void *key, void *user_context);
189 * Basic has function to hash strings. May be used with the SilcHashTable.
190 * Note that this lowers the characters of the string (with tolower()) so
191 * this is used usually with nicknames, channel and server names to provide
192 * case insensitive keys.
195 SilcUInt32 silc_hash_string(void *key, void *user_context);
197 /****f* silcutil/SilcUtilAPI/silc_hash_uint
201 * SilcUInt32 silc_hash_uint(void *key, void *user_context);
205 * Basic hash function to hash integers. May be used with the SilcHashTable.
208 SilcUInt32 silc_hash_uint(void *key, void *user_context);
210 /****f* silcutil/SilcUtilAPI/silc_hash_ptr
214 * SilcUInt32 silc_hash_ptr(void *key, void *user_context);
218 * Basic hash funtion to hash pointers. May be used with the SilcHashTable.
221 SilcUInt32 silc_hash_ptr(void *key, void *user_context);
223 /****f* silcutil/SilcUtilAPI/silc_hash_id
227 * SilcUInt32 silc_hash_id(void *key, void *user_context);
231 * Hash a ID. The `user_context' is the ID type.
234 SilcUInt32 silc_hash_id(void *key, void *user_context);
236 /****f* silcutil/SilcUtilAPI/silc_hash_client_id_hash
240 * SilcUInt32 silc_hash_client_id_hash(void *key, void *user_context)
244 * Hash Client ID's hash.
247 SilcUInt32 silc_hash_client_id_hash(void *key, void *user_context);
249 /****f* silcutil/SilcUtilAPI/silc_hash_data
253 * SilcUInt32 silc_hash_data(void *key, void *user_context);
257 * Hash binary data. The `user_context' is the data length.
260 SilcUInt32 silc_hash_data(void *key, void *user_context);
262 /****f* silcutil/SilcUtilAPI/silc_hash_public_key
266 * SilcUInt32 silc_hash_public_key(void *key, void *user_context);
270 * Hashed SILC Public key.
273 SilcUInt32 silc_hash_public_key(void *key, void *user_context);
275 /****f* silcutil/SilcUtilAPI/silc_hash_string_compare
279 * bool silc_hash_string_compare(void *key1, void *key2,
280 * void *user_context);
284 * Compares two strings. It may be used as SilcHashTable comparison
288 bool silc_hash_string_compare(void *key1, void *key2, void *user_context);
290 /****f* silcutil/SilcUtilAPI/silc_hash_id_compare
294 * bool silc_hash_id_compare(void *key1, void *key2, void *user_context);
298 * Compares two ID's. May be used as SilcHashTable comparison function.
299 * The Client ID's compares only the hash of the Client ID not any other
300 * part of the Client ID. Other ID's are fully compared.
303 bool silc_hash_id_compare(void *key1, void *key2, void *user_context);
305 /****f* silcutil/SilcUtilAPI/silc_hash_client_id_compare
309 * bool silc_hash_client_id_compare(void *key1, void *key2, void *user_context);
313 * Compare two Client ID's entirely and not just the hash from the ID.
316 bool silc_hash_client_id_compare(void *key1, void *key2, void *user_context);
318 /****f* silcutil/SilcUtilAPI/silc_hash_data_compare
322 * bool silc_hash_data_compare(void *key1, void *key2, void *user_context);
326 * Compares binary data. May be used as SilcHashTable comparison function.
329 bool silc_hash_data_compare(void *key1, void *key2, void *user_context);
331 /****f* silcutil/SilcUtilAPI/silc_hash_public_key_compare
335 * bool silc_hash_public_key_compare(void *key1, void *key2, void *user_context);
339 * Compares two SILC Public keys. It may be used as SilcHashTable
340 * comparison function.
343 bool silc_hash_public_key_compare(void *key1, void *key2, void *user_context);
345 /****f* silcutil/SilcUtilAPI/silc_client_chmode
349 * char *silc_client_chmode(SilcUInt32 mode, const char *cipher,
354 * Parses mode mask and returns the mode as string.
357 char *silc_client_chmode(SilcUInt32 mode, const char *cipher,
360 /****f* silcutil/SilcUtilAPI/silc_client_chumode
364 * char *silc_client_chumode(SilcUInt32 mode);
368 * Parses channel user mode mask and returns te mode as string.
371 char *silc_client_chumode(SilcUInt32 mode);
373 /****f* silcutil/SilcUtilAPI/silc_client_chumode_char
377 * char *silc_client_chumode_char(SilcUInt32 mode);
381 * Parses channel user mode and returns it as special mode character.
384 char *silc_client_chumode_char(SilcUInt32 mode);
386 /****f* silcutil/SilcUtilAPI/silc_fingerprint
390 * char *silc_fingerprint(const unsigned char *data, SilcUInt32 data_len);
394 * Creates fingerprint from data, usually used with SHA1 digests.
397 char *silc_fingerprint(const unsigned char *data, SilcUInt32 data_len);
399 /****f* silcutil/SilcUtilAPI/silc_string_is_ascii
403 * bool silc_string_is_ascii(const unsigned char *data,
404 * SilcUInt32 data_len);
408 * Return TRUE if the `data' is ASCII string.
411 bool silc_string_is_ascii(const unsigned char *data, SilcUInt32 data_len);
413 /****f* silcutil/SilcUtilAPI/silc_parse_version_string
417 * bool silc_parse_version_string(const char *version,
418 * SilcUInt32 *protocol_version,
419 * char **protocol_version_string,
420 * SilcUInt32 *software_version,
421 * char **software_version_string,
422 * char **vendor_version);
426 * Parses SILC protocol style version string.
429 bool silc_parse_version_string(const char *version,
430 SilcUInt32 *protocol_version,
431 char **protocol_version_string,
432 SilcUInt32 *software_version,
433 char **software_version_string,
434 char **vendor_version);
436 /****f* silcutil/SilcUtilAPI/silc_version_to_num
440 * SilcUInt32 silc_version_to_num(const char *version);
444 * Converts version string x.x into number representation.
447 SilcUInt32 silc_version_to_num(const char *version);
449 /****f* silcutil/SilcUtilAPI/silc_get_input
453 * char *silc_get_input(const char *prompt, bool echo_off);
457 * Displays input prompt on command line and takes input data from user.
460 char *silc_get_input(const char *prompt, bool echo_off);
462 /* System dependant prototypes */
464 /****f* silcutil/SilcUtilAPI/silc_gettimeofday
468 * int silc_gettimeofday(struct timeval *p);
472 * Return current time to struct timeval.
474 * This function is system dependant.
477 int silc_gettimeofday(struct timeval *p);
479 /****f* silcutil/SilcUtilAPI/silc_string_regexify
483 * char *silc_string_regexify(const char *string);
487 * Inspects the `string' for wildcards and returns regex string that can
488 * be used by the GNU regex library. A comma (`,') in the `string' means
489 * that the string is list.
491 * This function is system dependant.
494 char *silc_string_regexify(const char *string);
496 /****f* silcutil/SilcUtilAPI/silc_string_regex_match
500 * int silc_string_regex_match(const char *regex, const char *string);
504 * Matches the two strings and returns TRUE if the strings match.
506 * This function is system dependant.
509 int silc_string_regex_match(const char *regex, const char *string);
511 /****f* silcutil/SilcUtilAPI/silc_string_match
515 * int silc_string_match(const char *string1, const char *string2);
519 * Do regex match to the two strings `string1' and `string2'. If the
520 * `string2' matches the `string1' this returns TRUE.
522 * This function is system dependant.
525 int silc_string_match(const char *string1, const char *string2);
527 /****f* silcutil/SilcUtilAPI/silc_get_username
531 * char *silc_get_username();
535 * Returns the username of the user. If the global variable LOGNAME
536 * does not exists we will get the name from the passwd file.
538 * This function is system dependant.
541 char *silc_get_username();
543 /****f* silcutil/SilcUtilAPI/silc_get_real_name
547 * char *silc_get_real_name();
551 * Returns the real name of ther user from the passwd file.
553 * This function is system dependant.
556 char *silc_get_real_name();
558 /****f* silcutil/SilcUtilAPI/silc_get_mode_list
562 * bool silc_get_mode_list(SilcBuffer mode_list, SilcUInt32 mode_list_count,
563 * SilcUInt32 **list);
567 * Returns modes from list of 32 bit MSB first order values that are
568 * encoded one after the other in the `mode_list' into the `list'
569 * array. The caller must free the returned list. Return FALSE if
570 * there is error parsing the list.
573 bool silc_get_mode_list(SilcBuffer mode_list, SilcUInt32 mode_list_count,
576 #endif /* !SILCUTIL_H */