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 * char *silc_to_upper(char *string);
83 * Converts string to capital characters.
86 char *silc_to_upper(char *string);
88 /****f* silcutil/SilcUtilAPI/silc_encode_pem
92 * char *silc_encode_pem(unsigned char *data, SilcUInt32 len);
96 * Encodes data into PEM encoding. Returns NULL terminated PEM encoded
97 * data string. Note: This is originally public domain code and is
101 char *silc_encode_pem(unsigned char *data, SilcUInt32 len);
103 /****f* silcutil/SilcUtilAPI/silc_encode_pem_file
107 * char *silc_encode_pem_file(unsigned char *data, SilcUInt32 data_len);
111 * Same as silc_encode_pem() but puts newline ('\n') every 72 characters.
114 char *silc_encode_pem_file(unsigned char *data, SilcUInt32 data_len);
116 /****f* silcutil/SilcUtilAPI/silc_decode_pem
120 * unsigned char *silc_decode_pem(unsigned char *pem, SilcUInt32 pem_len,
121 * SilcUInt32 *ret_len);
125 * Decodes PEM into data. Returns the decoded data. Note: This is
126 * originally public domain code and is still PD.
129 unsigned char *silc_decode_pem(unsigned char *pem, SilcUInt32 pem_len,
130 SilcUInt32 *ret_len);
132 /****f* silcutil/SilcUtilAPI/silc_parse_userfqdn
136 * bool silc_parse_userfqdn(const char *string, char **left, char **right);
140 * Parse userfqdn string which is in user@fqdn format.
143 bool silc_parse_userfqdn(const char *string, char **left, char **right);
145 /****f* silcutil/SilcUtilAPI/silc_parse_command_line
149 * void silc_parse_command_line(unsigned char *buffer,
150 * unsigned char ***parsed,
151 * SilcUInt32 **parsed_lens,
152 * SilcUInt32 **parsed_types,
153 * SilcUInt32 *parsed_num,
154 * SilcUInt32 max_args);
158 * Parses command line. At most `max_args' is taken. Rest of the line
159 * will be allocated as the last argument if there are more than `max_args'
160 * arguments in the line. Note that the command name is counted as one
161 * argument and is saved.
164 void silc_parse_command_line(unsigned char *buffer,
165 unsigned char ***parsed,
166 SilcUInt32 **parsed_lens,
167 SilcUInt32 **parsed_types,
168 SilcUInt32 *parsed_num,
169 SilcUInt32 max_args);
171 /****f* silcutil/SilcUtilAPI/silc_format
175 * char *silc_format(char *fmt, ...);
179 * Formats arguments to a string and returns it after allocating memory
180 * for it. It must be remembered to free it later.
183 char *silc_format(char *fmt, ...);
185 /****f* silcutil/SilcUtilAPI/silc_id_render
189 * char *silc_id_render(void *id, SilcUInt16 type);
193 * Renders ID to suitable to print for example to log file.
196 char *silc_id_render(void *id, SilcUInt16 type);
198 /****f* silcutil/SilcUtilAPI/silc_string_compare
202 * int silc_string_compare(char *string1, char *string2);
206 * Compares two strings. Strings may include wildcards '*' and '?'.
207 * Returns TRUE if strings match.
210 int silc_string_compare(char *string1, char *string2);
212 /****f* silcutil/SilcUtilAPI/silc_hash_string
216 * SilcUInt32 silc_hash_string(void *key, void *user_context);
220 * Basic has function to hash strings. May be used with the SilcHashTable.
221 * Note that this lowers the characters of the string (with tolower()) so
222 * this is used usually with nicknames, channel and server names to provide
223 * case insensitive keys.
226 SilcUInt32 silc_hash_string(void *key, void *user_context);
228 /****f* silcutil/SilcUtilAPI/silc_hash_uint
232 * SilcUInt32 silc_hash_uint(void *key, void *user_context);
236 * Basic hash function to hash integers. May be used with the SilcHashTable.
239 SilcUInt32 silc_hash_uint(void *key, void *user_context);
241 /****f* silcutil/SilcUtilAPI/silc_hash_ptr
245 * SilcUInt32 silc_hash_ptr(void *key, void *user_context);
249 * Basic hash funtion to hash pointers. May be used with the SilcHashTable.
252 SilcUInt32 silc_hash_ptr(void *key, void *user_context);
254 /****f* silcutil/SilcUtilAPI/silc_hash_id
258 * SilcUInt32 silc_hash_id(void *key, void *user_context);
262 * Hash a ID. The `user_context' is the ID type.
265 SilcUInt32 silc_hash_id(void *key, void *user_context);
267 /****f* silcutil/SilcUtilAPI/silc_hash_data
271 * SilcUInt32 silc_hash_data(void *key, void *user_context);
275 * Hash binary data. The `user_context' is the data length.
278 SilcUInt32 silc_hash_data(void *key, void *user_context);
280 /****f* silcutil/SilcUtilAPI/silc_hash_public_key
284 * SilcUInt32 silc_hash_public_key(void *key, void *user_context);
288 * Hashed SILC Public key.
291 SilcUInt32 silc_hash_public_key(void *key, void *user_context);
293 /****f* silcutil/SilcUtilAPI/silc_hash_string_compare
297 * bool silc_hash_string_compare(void *key1, void *key2,
298 * void *user_context);
302 * Compares two strings. It may be used as SilcHashTable comparison
306 bool silc_hash_string_compare(void *key1, void *key2, void *user_context);
308 /****f* silcutil/SilcUtilAPI/silc_hash_id_compare
312 * bool silc_hash_id_compare(void *key1, void *key2, void *user_context);
316 * Compares two ID's. May be used as SilcHashTable comparison function.
317 * The Client ID's compares only the hash of the Client ID not any other
318 * part of the Client ID. Other ID's are fully compared.
321 bool silc_hash_id_compare(void *key1, void *key2, void *user_context);
323 /****f* silcutil/SilcUtilAPI/silc_hash_client_id_compare
327 * bool silc_hash_client_id_compare(void *key1, void *key2, void *user_context);
331 * Compare two Client ID's entirely and not just the hash from the ID.
334 bool silc_hash_client_id_compare(void *key1, void *key2, void *user_context);
336 /****f* silcutil/SilcUtilAPI/silc_hash_data_compare
340 * bool silc_hash_data_compare(void *key1, void *key2, void *user_context);
344 * Compares binary data. May be used as SilcHashTable comparison function.
347 bool silc_hash_data_compare(void *key1, void *key2, void *user_context);
349 /****f* silcutil/SilcUtilAPI/silc_hash_public_key_compare
353 * bool silc_hash_public_key_compare(void *key1, void *key2, void *user_context);
357 * Compares two SILC Public keys. It may be used as SilcHashTable
358 * comparison function.
361 bool silc_hash_public_key_compare(void *key1, void *key2, void *user_context);
363 /****f* silcutil/SilcUtilAPI/silc_client_chmode
367 * char *silc_client_chmode(SilcUInt32 mode, const char *cipher,
372 * Parses mode mask and returns the mode as string.
375 char *silc_client_chmode(SilcUInt32 mode, const char *cipher,
378 /****f* silcutil/SilcUtilAPI/silc_client_chumode
382 * char *silc_client_chumode(SilcUInt32 mode);
386 * Parses channel user mode mask and returns te mode as string.
389 char *silc_client_chumode(SilcUInt32 mode);
391 /****f* silcutil/SilcUtilAPI/silc_client_chumode_char
395 * char *silc_client_chumode_char(SilcUInt32 mode);
399 * Parses channel user mode and returns it as special mode character.
402 char *silc_client_chumode_char(SilcUInt32 mode);
404 /****f* silcutil/SilcUtilAPI/silc_fingerprint
408 * char *silc_fingerprint(const unsigned char *data, SilcUInt32 data_len);
412 * Creates fingerprint from data, usually used with SHA1 digests.
415 char *silc_fingerprint(const unsigned char *data, SilcUInt32 data_len);
417 /****f* silcutil/SilcUtilAPI/silc_string_is_ascii
421 * bool silc_string_is_ascii(const unsigned char *data,
422 * SilcUInt32 data_len);
426 * Return TRUE if the `data' is ASCII string.
429 bool silc_string_is_ascii(const unsigned char *data, SilcUInt32 data_len);
431 /****f* silcutil/SilcUtilAPI/silc_parse_version_string
435 * bool silc_parse_version_string(const char *version,
436 * SilcUInt32 *protocol_version,
437 * char **protocol_version_string,
438 * SilcUInt32 *software_version,
439 * char **software_version_string,
440 * char **vendor_version);
444 * Parses SILC protocol style version string.
447 bool silc_parse_version_string(const char *version,
448 SilcUInt32 *protocol_version,
449 char **protocol_version_string,
450 SilcUInt32 *software_version,
451 char **software_version_string,
452 char **vendor_version);
454 /****f* silcutil/SilcUtilAPI/silc_version_to_num
458 * SilcUInt32 silc_version_to_num(const char *version);
462 * Converts version string x.x into number representation.
465 SilcUInt32 silc_version_to_num(const char *version);
467 /****f* silcutil/SilcUtilAPI/silc_get_input
471 * char *silc_get_input(const char *prompt, bool echo_off);
475 * Displays input prompt on command line and takes input data from user.
478 char *silc_get_input(const char *prompt, bool echo_off);
480 /* XXX - System dependant prototypes */
482 int silc_gettimeofday(struct timeval *p);
483 char *silc_string_regexify(const char *string);
484 int silc_string_regex_match(const char *regex, const char *string);
485 int silc_string_match(const char *string1, const char *string2);
486 char *silc_get_username();
487 char *silc_get_real_name();
489 #endif /* !SILCUTIL_H */