5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1997 - 2005 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 * SilcBool silc_to_upper(const char *string, char *dest, SilcUInt32 dest_size);
85 * Converts string to capital characters.
88 SilcBool silc_to_upper(const char *string, char *dest, SilcUInt32 dest_size);
90 /****f* silcutil/SilcUtilAPI/silc_to_lower
94 * SilcBool silc_to_lower(const char *string, char *dest, SilcUInt32 dest_size);
98 * Converts string to capital characters.
101 SilcBool silc_to_lower(const char *string, char *dest, SilcUInt32 dest_size);
103 /****f* silcutil/SilcUtilAPI/silc_parse_userfqdn
107 * int silc_parse_userfqdn(const char *string,
108 * char *user, SilcUInt32 user_size,
109 * char *fqdn, SilcUInt32 fqdn_size);
113 * Parse userfqdn string which is in user@fqdn format. Returns 0 on
114 * error, 1 if `user' was filled and 2 if both `user' and `fqdn'
118 int silc_parse_userfqdn(const char *string,
119 char *user, SilcUInt32 user_size,
120 char *fqdn, SilcUInt32 fqdn_size);
122 /****f* silcutil/SilcUtilAPI/silc_parse_command_line
126 * void silc_parse_command_line(unsigned char *buffer,
127 * unsigned char ***parsed,
128 * SilcUInt32 **parsed_lens,
129 * SilcUInt32 **parsed_types,
130 * SilcUInt32 *parsed_num,
131 * SilcUInt32 max_args);
135 * Parses command line. At most `max_args' is taken. Rest of the line
136 * will be allocated as the last argument if there are more than `max_args'
137 * arguments in the line. Note that the command name is counted as one
138 * argument and is saved.
141 void silc_parse_command_line(unsigned char *buffer,
142 unsigned char ***parsed,
143 SilcUInt32 **parsed_lens,
144 SilcUInt32 **parsed_types,
145 SilcUInt32 *parsed_num,
146 SilcUInt32 max_args);
148 /****f* silcutil/SilcUtilAPI/silc_format
152 * char *silc_format(char *fmt, ...);
156 * Formats arguments to a string and returns it after allocating memory
157 * for it. It must be remembered to free it later.
160 char *silc_format(char *fmt, ...);
162 /****f* silcutil/SilcUtilAPI/silc_id_render
166 * char *silc_id_render(void *id, SilcUInt16 type);
170 * Renders ID to suitable to print for example to log file.
173 char *silc_id_render(void *id, SilcUInt16 type);
175 /****f* silcutil/SilcUtilAPI/silc_string_compare
179 * int silc_string_compare(char *string1, char *string2);
183 * Compares two strings. Strings may include wildcards '*' and '?'.
184 * Returns TRUE if strings match.
187 int silc_string_compare(char *string1, char *string2);
189 /****f* silcutil/SilcUtilAPI/silc_hash_string
193 * SilcUInt32 silc_hash_string(void *key, void *user_context);
197 * Basic has function to hash strings. May be used with the SilcHashTable.
198 * Note that this lowers the characters of the string (with tolower()) so
199 * this is used usually with nicknames, channel and server names to provide
200 * case insensitive keys.
203 SilcUInt32 silc_hash_string(void *key, void *user_context);
205 /****f* silcutil/SilcUtilAPI/silc_hash_utf8_string
209 * SilcUInt32 silc_hash_utf8_string(void *key, void *user_context);
213 * Basic has function to hash UTF-8 strings. May be used with the
214 * SilcHashTable. Used with identifier strings. The key is
215 * expected to be casefolded.
218 SilcUInt32 silc_hash_utf8_string(void *key, void *user_context);
220 /****f* silcutil/SilcUtilAPI/silc_hash_uint
224 * SilcUInt32 silc_hash_uint(void *key, void *user_context);
228 * Basic hash function to hash integers. May be used with the SilcHashTable.
231 SilcUInt32 silc_hash_uint(void *key, void *user_context);
233 /****f* silcutil/SilcUtilAPI/silc_hash_ptr
237 * SilcUInt32 silc_hash_ptr(void *key, void *user_context);
241 * Basic hash funtion to hash pointers. May be used with the SilcHashTable.
244 SilcUInt32 silc_hash_ptr(void *key, void *user_context);
246 /****f* silcutil/SilcUtilAPI/silc_hash_id
250 * SilcUInt32 silc_hash_id(void *key, void *user_context);
254 * Hash a ID. The `user_context' is the ID type.
257 SilcUInt32 silc_hash_id(void *key, void *user_context);
259 /****f* silcutil/SilcUtilAPI/silc_hash_client_id_hash
263 * SilcUInt32 silc_hash_client_id_hash(void *key, void *user_context)
267 * Hash Client ID's hash.
270 SilcUInt32 silc_hash_client_id_hash(void *key, void *user_context);
272 /****f* silcutil/SilcUtilAPI/silc_hash_data
276 * SilcUInt32 silc_hash_data(void *key, void *user_context);
280 * Hash binary data. The `user_context' is the data length.
283 SilcUInt32 silc_hash_data(void *key, void *user_context);
285 /****f* silcutil/SilcUtilAPI/silc_hash_public_key
289 * SilcUInt32 silc_hash_public_key(void *key, void *user_context);
293 * Hashed SILC Public key.
296 SilcUInt32 silc_hash_public_key(void *key, void *user_context);
298 /****f* silcutil/SilcUtilAPI/silc_hash_string_compare
302 * SilcBool silc_hash_string_compare(void *key1, void *key2,
303 * void *user_context);
307 * Compares two strings. It may be used as SilcHashTable comparison
311 SilcBool silc_hash_string_compare(void *key1, void *key2, void *user_context);
313 /****f* silcutil/SilcUtilAPI/silc_hash_id_compare
317 * SilcBool silc_hash_id_compare(void *key1, void *key2,
318 * void *user_context);
322 * Compares two ID's. May be used as SilcHashTable comparison function.
323 * The Client ID's compares only the hash of the Client ID not any other
324 * part of the Client ID. Other ID's are fully compared.
327 SilcBool silc_hash_id_compare(void *key1, void *key2, void *user_context);
329 /****f* silcutil/SilcUtilAPI/silc_hash_id_compare_full
333 * SilcBool silc_hash_id_compare_full(void *key1, void *key2,
334 * void *user_context)
338 * Compares two ID's. May be used as SilcHashTable comparison function.
339 * To compare full ID's instead of only partial, like the
340 * silc_hash_id_compare does, use this function.
343 SilcBool silc_hash_id_compare_full(void *key1, void *key2, void *user_context);
345 /****f* silcutil/SilcUtilAPI/silc_hash_client_id_compare
349 * SilcBool silc_hash_client_id_compare(void *key1, void *key2,
350 * void *user_context);
354 * Compare two Client ID's entirely and not just the hash from the ID.
357 SilcBool silc_hash_client_id_compare(void *key1, void *key2,
360 /****f* silcutil/SilcUtilAPI/silc_hash_data_compare
364 * SilcBool silc_hash_data_compare(void *key1, void *key2,
365 * void *user_context);
369 * Compares binary data. May be used as SilcHashTable comparison function.
372 SilcBool silc_hash_data_compare(void *key1, void *key2, void *user_context);
374 /****f* silcutil/SilcUtilAPI/silc_hash_utf8_compare
378 * SilcBool silc_hash_utf8_compare(void *key1, void *key2,
379 * void *user_context);
383 * Compares UTF-8 strings. Casefolded and NULL terminated strings are
384 * expected. May be used as SilcHashTable comparison function.
387 SilcBool silc_hash_utf8_compare(void *key1, void *key2, void *user_context);
389 /****f* silcutil/SilcUtilAPI/silc_hash_public_key_compare
393 * SilcBool silc_hash_public_key_compare(void *key1, void *key2,
394 * void *user_context);
398 * Compares two SILC Public keys. It may be used as SilcHashTable
399 * comparison function.
402 SilcBool silc_hash_public_key_compare(void *key1, void *key2,
405 /****f* silcutil/SilcUtilAPI/silc_client_chmode
409 * char *silc_client_chmode(SilcUInt32 mode, const char *cipher,
414 * Parses mode mask and returns the mode as string.
417 char *silc_client_chmode(SilcUInt32 mode, const char *cipher,
420 /****f* silcutil/SilcUtilAPI/silc_client_chumode
424 * char *silc_client_chumode(SilcUInt32 mode);
428 * Parses channel user mode mask and returns te mode as string.
431 char *silc_client_chumode(SilcUInt32 mode);
433 /****f* silcutil/SilcUtilAPI/silc_client_chumode_char
437 * char *silc_client_chumode_char(SilcUInt32 mode);
441 * Parses channel user mode and returns it as special mode character.
444 char *silc_client_chumode_char(SilcUInt32 mode);
446 /****f* silcutil/SilcUtilAPI/silc_fingerprint
450 * char *silc_fingerprint(const unsigned char *data, SilcUInt32 data_len);
454 * Return a textual representation of the fingerprint in *data, the
455 * caller must free the returned string.
458 char *silc_fingerprint(const unsigned char *data, SilcUInt32 data_len);
460 /****f* silcutil/SilcUtilAPI/silc_string_is_ascii
464 * SilcBool silc_string_is_ascii(const unsigned char *data,
465 * SilcUInt32 data_len);
469 * Return TRUE if the `data' is ASCII string.
472 SilcBool silc_string_is_ascii(const unsigned char *data, SilcUInt32 data_len);
474 /****f* silcutil/SilcUtilAPI/silc_parse_version_string
478 * SilcBool silc_parse_version_string(const char *version,
479 * SilcUInt32 *protocol_version,
480 * char **protocol_version_string,
481 * SilcUInt32 *software_version,
482 * char **software_version_string,
483 * char **vendor_version);
487 * Parses SILC protocol style version string.
490 SilcBool silc_parse_version_string(const char *version,
491 SilcUInt32 *protocol_version,
492 char **protocol_version_string,
493 SilcUInt32 *software_version,
494 char **software_version_string,
495 char **vendor_version);
497 /****f* silcutil/SilcUtilAPI/silc_version_to_num
501 * SilcUInt32 silc_version_to_num(const char *version);
505 * Converts version string x.x into number representation.
508 SilcUInt32 silc_version_to_num(const char *version);
510 /****f* silcutil/SilcUtilAPI/silc_get_input
514 * char *silc_get_input(const char *prompt, SilcBool echo_off);
518 * Displays input prompt on command line and takes input data from user.
521 char *silc_get_input(const char *prompt, SilcBool echo_off);
523 /* System dependant prototypes */
525 /****f* silcutil/SilcUtilAPI/silc_gettimeofday
529 * int silc_gettimeofday(struct timeval *p);
533 * Return current time to struct timeval. This function is system
534 * dependant. Returns 0 on success and -1 on error.
537 int silc_gettimeofday(struct timeval *p);
539 /****f* silcutil/SilcUtilAPI/silc_compare_timeval
543 * SilcBool silc_compare_timeval(struct timeval *smaller,
544 * struct timeval *bigger)
548 * Compare two timeval structures and return TRUE if the first
549 * time value is smaller than the second time value.
552 SilcBool silc_compare_timeval(struct timeval *smaller,
553 struct timeval *bigger);
555 /****f* silcutil/SilcUtilAPI/silc_string_regexify
559 * char *silc_string_regexify(const char *string);
563 * Inspects the `string' for wildcards and returns regex string that can
564 * be used by the GNU regex library. A comma (`,') in the `string' means
565 * that the string is list.
567 * This function is system dependant.
570 char *silc_string_regexify(const char *string);
572 /****f* silcutil/SilcUtilAPI/silc_string_regex_match
576 * int silc_string_regex_match(const char *regex, const char *string);
580 * Matches the two strings and returns TRUE if the strings match.
582 * This function is system dependant.
585 int silc_string_regex_match(const char *regex, const char *string);
587 /****f* silcutil/SilcUtilAPI/silc_string_match
591 * int silc_string_match(const char *string1, const char *string2);
595 * Do regex match to the two strings `string1' and `string2'. If the
596 * `string2' matches the `string1' this returns TRUE.
598 * This function is system dependant.
601 int silc_string_match(const char *string1, const char *string2);
603 /****f* silcutil/SilcUtilAPI/silc_get_username
607 * char *silc_get_username();
611 * Returns the username of the user. If the global variable LOGNAME
612 * does not exists we will get the name from the passwd file. The
613 * caller must free the returned name.
615 * This function is system dependant.
618 char *silc_get_username();
620 /****f* silcutil/SilcUtilAPI/silc_get_real_name
624 * char *silc_get_real_name();
628 * Returns the real name of ther user from the passwd file. The
629 * caller must free the returned name.
631 * This function is system dependant.
634 char *silc_get_real_name();
636 /****f* silcutil/SilcUtilAPI/silc_get_mode_list
640 * SilcBool silc_get_mode_list(SilcBuffer mode_list, SilcUInt32 mode_list_count,
641 * SilcUInt32 **list);
645 * Returns modes from list of 32 bit MSB first order values that are
646 * encoded one after the other in the `mode_list' into the `list'
647 * array. The caller must free the returned list. Return FALSE if
648 * there is error parsing the list.
651 SilcBool silc_get_mode_list(SilcBuffer mode_list, SilcUInt32 mode_list_count,
654 /****f* silcutil/SilcUtilAPI/silc_get_status_message
658 * char *silc_get_status_message(SilcStatus status)
662 * Returns status message string
665 const char *silc_get_status_message(unsigned char status);
667 /****f* silcutil/SilcUtilAPI/silc_get_packet_name
671 * char *silc_get_packet_name(SilcPacketType type);
675 * Returns the name corresponding packet type `type'.
678 const char *silc_get_packet_name(unsigned char type);
680 /****f* silcutil/SilcUtilAPI/silc_get_command_name
684 * char *silc_get_command_name(SilcCommand command);
688 * Returns the name corresponding SILC command `command'.
691 const char *silc_get_command_name(unsigned char command);
693 #endif /* !SILCUTIL_H */