5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1997 - 2003 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,
48 /****f* silcutil/SilcUtilAPI/silc_check_line
52 * int silc_check_line(char *buf);
56 * Checks line for illegal characters. Return -1 when illegal character
57 * were found. This is used to check for bad lines when reading data from
58 * for example a configuration file.
61 int silc_check_line(char *buf);
63 /****f* silcutil/SilcUtilAPI/silc_get_time
67 * const char *silc_get_time(SilcUInt32 timeval)
71 * Returns time as string. If the the `timeval' is non-zero that
72 * value is returned as string. If it is zero the current time of the
73 * local machine is returned.
76 const char *silc_get_time(SilcUInt32 timeval);
78 /****f* silcutil/SilcUtilAPI/silc_to_upper
82 * bool silc_to_upper(const char *string, char *dest, SilcUInt32 dest_size);
86 * Converts string to capital characters.
89 bool silc_to_upper(const char *string, char *dest, SilcUInt32 dest_size);
91 /****f* silcutil/SilcUtilAPI/silc_to_lower
95 * bool silc_to_lower(const char *string, char *dest, SilcUInt32 dest_size);
99 * Converts string to capital characters.
102 bool silc_to_lower(const char *string, char *dest, SilcUInt32 dest_size);
104 /****f* silcutil/SilcUtilAPI/silc_parse_userfqdn
108 * bool silc_parse_userfqdn(const char *string, char **left, char **right);
112 * Parse userfqdn string which is in user@fqdn format.
115 bool silc_parse_userfqdn(const char *string, char **left, char **right);
117 /****f* silcutil/SilcUtilAPI/silc_parse_command_line
121 * void silc_parse_command_line(unsigned char *buffer,
122 * unsigned char ***parsed,
123 * SilcUInt32 **parsed_lens,
124 * SilcUInt32 **parsed_types,
125 * SilcUInt32 *parsed_num,
126 * SilcUInt32 max_args);
130 * Parses command line. At most `max_args' is taken. Rest of the line
131 * will be allocated as the last argument if there are more than `max_args'
132 * arguments in the line. Note that the command name is counted as one
133 * argument and is saved.
136 void silc_parse_command_line(unsigned char *buffer,
137 unsigned char ***parsed,
138 SilcUInt32 **parsed_lens,
139 SilcUInt32 **parsed_types,
140 SilcUInt32 *parsed_num,
141 SilcUInt32 max_args);
143 /****f* silcutil/SilcUtilAPI/silc_format
147 * char *silc_format(char *fmt, ...);
151 * Formats arguments to a string and returns it after allocating memory
152 * for it. It must be remembered to free it later.
155 char *silc_format(char *fmt, ...);
157 /****f* silcutil/SilcUtilAPI/silc_id_render
161 * char *silc_id_render(void *id, SilcUInt16 type);
165 * Renders ID to suitable to print for example to log file.
168 char *silc_id_render(void *id, SilcUInt16 type);
170 /****f* silcutil/SilcUtilAPI/silc_string_compare
174 * int silc_string_compare(char *string1, char *string2);
178 * Compares two strings. Strings may include wildcards '*' and '?'.
179 * Returns TRUE if strings match.
182 int silc_string_compare(char *string1, char *string2);
184 /****f* silcutil/SilcUtilAPI/silc_hash_string
188 * SilcUInt32 silc_hash_string(void *key, void *user_context);
192 * Basic has function to hash strings. May be used with the SilcHashTable.
193 * Note that this lowers the characters of the string (with tolower()) so
194 * this is used usually with nicknames, channel and server names to provide
195 * case insensitive keys.
198 SilcUInt32 silc_hash_string(void *key, void *user_context);
200 /****f* silcutil/SilcUtilAPI/silc_hash_uint
204 * SilcUInt32 silc_hash_uint(void *key, void *user_context);
208 * Basic hash function to hash integers. May be used with the SilcHashTable.
211 SilcUInt32 silc_hash_uint(void *key, void *user_context);
213 /****f* silcutil/SilcUtilAPI/silc_hash_ptr
217 * SilcUInt32 silc_hash_ptr(void *key, void *user_context);
221 * Basic hash funtion to hash pointers. May be used with the SilcHashTable.
224 SilcUInt32 silc_hash_ptr(void *key, void *user_context);
226 /****f* silcutil/SilcUtilAPI/silc_hash_id
230 * SilcUInt32 silc_hash_id(void *key, void *user_context);
234 * Hash a ID. The `user_context' is the ID type.
237 SilcUInt32 silc_hash_id(void *key, void *user_context);
239 /****f* silcutil/SilcUtilAPI/silc_hash_client_id_hash
243 * SilcUInt32 silc_hash_client_id_hash(void *key, void *user_context)
247 * Hash Client ID's hash.
250 SilcUInt32 silc_hash_client_id_hash(void *key, void *user_context);
252 /****f* silcutil/SilcUtilAPI/silc_hash_data
256 * SilcUInt32 silc_hash_data(void *key, void *user_context);
260 * Hash binary data. The `user_context' is the data length.
263 SilcUInt32 silc_hash_data(void *key, void *user_context);
265 /****f* silcutil/SilcUtilAPI/silc_hash_public_key
269 * SilcUInt32 silc_hash_public_key(void *key, void *user_context);
273 * Hashed SILC Public key.
276 SilcUInt32 silc_hash_public_key(void *key, void *user_context);
278 /****f* silcutil/SilcUtilAPI/silc_hash_string_compare
282 * bool silc_hash_string_compare(void *key1, void *key2,
283 * void *user_context);
287 * Compares two strings. It may be used as SilcHashTable comparison
291 bool silc_hash_string_compare(void *key1, void *key2, void *user_context);
293 /****f* silcutil/SilcUtilAPI/silc_hash_id_compare
297 * bool silc_hash_id_compare(void *key1, void *key2, void *user_context);
301 * Compares two ID's. May be used as SilcHashTable comparison function.
302 * The Client ID's compares only the hash of the Client ID not any other
303 * part of the Client ID. Other ID's are fully compared.
306 bool silc_hash_id_compare(void *key1, void *key2, void *user_context);
308 /****f* silcutil/SilcUtilAPI/silc_hash_client_id_compare
312 * bool silc_hash_client_id_compare(void *key1, void *key2, void *user_context);
316 * Compare two Client ID's entirely and not just the hash from the ID.
319 bool silc_hash_client_id_compare(void *key1, void *key2, void *user_context);
321 /****f* silcutil/SilcUtilAPI/silc_hash_data_compare
325 * bool silc_hash_data_compare(void *key1, void *key2, void *user_context);
329 * Compares binary data. May be used as SilcHashTable comparison function.
332 bool silc_hash_data_compare(void *key1, void *key2, void *user_context);
334 /****f* silcutil/SilcUtilAPI/silc_hash_public_key_compare
338 * bool silc_hash_public_key_compare(void *key1, void *key2, void *user_context);
342 * Compares two SILC Public keys. It may be used as SilcHashTable
343 * comparison function.
346 bool silc_hash_public_key_compare(void *key1, void *key2, void *user_context);
348 /****f* silcutil/SilcUtilAPI/silc_client_chmode
352 * char *silc_client_chmode(SilcUInt32 mode, const char *cipher,
357 * Parses mode mask and returns the mode as string.
360 char *silc_client_chmode(SilcUInt32 mode, const char *cipher,
363 /****f* silcutil/SilcUtilAPI/silc_client_chumode
367 * char *silc_client_chumode(SilcUInt32 mode);
371 * Parses channel user mode mask and returns te mode as string.
374 char *silc_client_chumode(SilcUInt32 mode);
376 /****f* silcutil/SilcUtilAPI/silc_client_chumode_char
380 * char *silc_client_chumode_char(SilcUInt32 mode);
384 * Parses channel user mode and returns it as special mode character.
387 char *silc_client_chumode_char(SilcUInt32 mode);
389 /****f* silcutil/SilcUtilAPI/silc_fingerprint
393 * char *silc_fingerprint(const unsigned char *data, SilcUInt32 data_len);
397 * Return a textual representation of the fingerprint in *data, the
398 * caller must free the returned string.
401 char *silc_fingerprint(const unsigned char *data, SilcUInt32 data_len);
403 /****f* silcutil/SilcUtilAPI/silc_string_is_ascii
407 * bool silc_string_is_ascii(const unsigned char *data,
408 * SilcUInt32 data_len);
412 * Return TRUE if the `data' is ASCII string.
415 bool silc_string_is_ascii(const unsigned char *data, SilcUInt32 data_len);
417 /****f* silcutil/SilcUtilAPI/silc_parse_version_string
421 * bool silc_parse_version_string(const char *version,
422 * SilcUInt32 *protocol_version,
423 * char **protocol_version_string,
424 * SilcUInt32 *software_version,
425 * char **software_version_string,
426 * char **vendor_version);
430 * Parses SILC protocol style version string.
433 bool silc_parse_version_string(const char *version,
434 SilcUInt32 *protocol_version,
435 char **protocol_version_string,
436 SilcUInt32 *software_version,
437 char **software_version_string,
438 char **vendor_version);
440 /****f* silcutil/SilcUtilAPI/silc_version_to_num
444 * SilcUInt32 silc_version_to_num(const char *version);
448 * Converts version string x.x into number representation.
451 SilcUInt32 silc_version_to_num(const char *version);
453 /****f* silcutil/SilcUtilAPI/silc_get_input
457 * char *silc_get_input(const char *prompt, bool echo_off);
461 * Displays input prompt on command line and takes input data from user.
464 char *silc_get_input(const char *prompt, bool echo_off);
466 /* System dependant prototypes */
468 /****f* silcutil/SilcUtilAPI/silc_gettimeofday
472 * int silc_gettimeofday(struct timeval *p);
476 * Return current time to struct timeval. This function is system
477 * dependant. Returns 0 on success and -1 on error.
480 int silc_gettimeofday(struct timeval *p);
482 /****f* silcutil/SilcUtilAPI/silc_compare_timeval
486 * bool silc_compare_timeval(struct timeval *smaller,
487 * struct timeval *bigger)
491 * Compare two timeval structures and return TRUE if the first
492 * time value is smaller than the second time value.
495 bool silc_compare_timeval(struct timeval *smaller,
496 struct timeval *bigger);
498 /****f* silcutil/SilcUtilAPI/silc_string_regexify
502 * char *silc_string_regexify(const char *string);
506 * Inspects the `string' for wildcards and returns regex string that can
507 * be used by the GNU regex library. A comma (`,') in the `string' means
508 * that the string is list.
510 * This function is system dependant.
513 char *silc_string_regexify(const char *string);
515 /****f* silcutil/SilcUtilAPI/silc_string_regex_match
519 * int silc_string_regex_match(const char *regex, const char *string);
523 * Matches the two strings and returns TRUE if the strings match.
525 * This function is system dependant.
528 int silc_string_regex_match(const char *regex, const char *string);
530 /****f* silcutil/SilcUtilAPI/silc_string_match
534 * int silc_string_match(const char *string1, const char *string2);
538 * Do regex match to the two strings `string1' and `string2'. If the
539 * `string2' matches the `string1' this returns TRUE.
541 * This function is system dependant.
544 int silc_string_match(const char *string1, const char *string2);
546 /****f* silcutil/SilcUtilAPI/silc_get_username
550 * char *silc_get_username();
554 * Returns the username of the user. If the global variable LOGNAME
555 * does not exists we will get the name from the passwd file. The
556 * caller must free the returned name.
558 * This function is system dependant.
561 char *silc_get_username();
563 /****f* silcutil/SilcUtilAPI/silc_get_real_name
567 * char *silc_get_real_name();
571 * Returns the real name of ther user from the passwd file. The
572 * caller must free the returned name.
574 * This function is system dependant.
577 char *silc_get_real_name();
579 /****f* silcutil/SilcUtilAPI/silc_get_mode_list
583 * bool silc_get_mode_list(SilcBuffer mode_list, SilcUInt32 mode_list_count,
584 * SilcUInt32 **list);
588 * Returns modes from list of 32 bit MSB first order values that are
589 * encoded one after the other in the `mode_list' into the `list'
590 * array. The caller must free the returned list. Return FALSE if
591 * there is error parsing the list.
594 bool silc_get_mode_list(SilcBuffer mode_list, SilcUInt32 mode_list_count,
597 /****f* silcutil/SilcUtilAPI/silc_get_status_message
601 * char *silc_get_status_message(SilcStatus status)
605 * Returns status message string
608 const char *silc_get_status_message(unsigned char status);
610 /****f* silcutil/SilcUtilAPI/silc_get_packet_name
614 * char *silc_get_packet_name(SilcPacketType type);
618 * Returns the name corresponding packet type `type'.
621 const char *silc_get_packet_name(unsigned char type);
623 /****f* silcutil/SilcUtilAPI/silc_get_command_name
627 * char *silc_get_command_name(SilcCommand command);
631 * Returns the name corresponding SILC command `command'.
634 const char *silc_get_command_name(unsigned char command);
636 #endif /* !SILCUTIL_H */