5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1997 - 2006 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_to_upper
66 * SilcBool silc_to_upper(const char *string, char *dest,
67 * SilcUInt32 dest_size);
71 * Converts string to capital characters.
74 SilcBool silc_to_upper(const char *string, char *dest, SilcUInt32 dest_size);
76 /****f* silcutil/SilcUtilAPI/silc_to_lower
80 * SilcBool silc_to_lower(const char *string, char *dest,
81 * SilcUInt32 dest_size);
85 * Converts string to capital characters.
88 SilcBool silc_to_lower(const char *string, char *dest, SilcUInt32 dest_size);
90 /****f* silcutil/SilcUtilAPI/silc_parse_userfqdn
94 * int silc_parse_userfqdn(const char *string,
95 * char *user, SilcUInt32 user_size,
96 * char *fqdn, SilcUInt32 fqdn_size);
100 * Parse userfqdn string which is in user@fqdn format. Returns 0 on
101 * error, 1 if `user' was filled and 2 if both `user' and `fqdn'
105 int silc_parse_userfqdn(const char *string,
106 char *user, SilcUInt32 user_size,
107 char *fqdn, SilcUInt32 fqdn_size);
109 /****f* silcutil/SilcUtilAPI/silc_parse_command_line
113 * void silc_parse_command_line(unsigned char *buffer,
114 * unsigned char ***parsed,
115 * SilcUInt32 **parsed_lens,
116 * SilcUInt32 **parsed_types,
117 * SilcUInt32 *parsed_num,
118 * SilcUInt32 max_args);
122 * Parses command line. At most `max_args' is taken. Rest of the line
123 * will be allocated as the last argument if there are more than `max_args'
124 * arguments in the line. Note that the command name is counted as one
125 * argument and is saved.
128 void silc_parse_command_line(unsigned char *buffer,
129 unsigned char ***parsed,
130 SilcUInt32 **parsed_lens,
131 SilcUInt32 **parsed_types,
132 SilcUInt32 *parsed_num,
133 SilcUInt32 max_args);
135 /****f* silcutil/SilcUtilAPI/silc_format
139 * char *silc_format(char *fmt, ...);
143 * Formats arguments to a string and returns it after allocating memory
144 * for it. It must be remembered to free it later.
147 char *silc_format(char *fmt, ...);
149 /****f* silcutil/SilcUtilAPI/silc_hash_string
153 * SilcUInt32 silc_hash_string(void *key, void *user_context);
157 * Basic has function to hash strings. May be used with the SilcHashTable.
158 * Note that this lowers the characters of the string (with tolower()) so
159 * this is used usually with nicknames, channel and server names to provide
160 * case insensitive keys.
163 SilcUInt32 silc_hash_string(void *key, void *user_context);
165 /****f* silcutil/SilcUtilAPI/silc_hash_utf8_string
169 * SilcUInt32 silc_hash_utf8_string(void *key, void *user_context);
173 * Basic has function to hash UTF-8 strings. May be used with the
174 * SilcHashTable. Used with identifier strings. The key is
175 * expected to be casefolded.
178 SilcUInt32 silc_hash_utf8_string(void *key, void *user_context);
180 /****f* silcutil/SilcUtilAPI/silc_hash_uint
184 * SilcUInt32 silc_hash_uint(void *key, void *user_context);
188 * Basic hash function to hash integers. May be used with the SilcHashTable.
191 SilcUInt32 silc_hash_uint(void *key, void *user_context);
193 /****f* silcutil/SilcUtilAPI/silc_hash_ptr
197 * SilcUInt32 silc_hash_ptr(void *key, void *user_context);
201 * Basic hash funtion to hash pointers. May be used with the SilcHashTable.
204 SilcUInt32 silc_hash_ptr(void *key, void *user_context);
206 /****f* silcutil/SilcUtilAPI/silc_hash_id
210 * SilcUInt32 silc_hash_id(void *key, void *user_context);
214 * Hash a ID. The `user_context' is the ID type.
217 SilcUInt32 silc_hash_id(void *key, void *user_context);
219 /****f* silcutil/SilcUtilAPI/silc_hash_client_id_hash
223 * SilcUInt32 silc_hash_client_id_hash(void *key, void *user_context)
227 * Hash Client ID's hash.
230 SilcUInt32 silc_hash_client_id_hash(void *key, void *user_context);
232 /****f* silcutil/SilcUtilAPI/silc_hash_data
236 * SilcUInt32 silc_hash_data(void *key, void *user_context);
240 * Hash binary data. The `user_context' is the data length.
243 SilcUInt32 silc_hash_data(void *key, void *user_context);
245 /****f* silcutil/SilcUtilAPI/silc_hash_public_key
249 * SilcUInt32 silc_hash_public_key(void *key, void *user_context);
253 * Hash public key of any type.
256 SilcUInt32 silc_hash_public_key(void *key, void *user_context);
258 /****f* silcutil/SilcUtilAPI/silc_hash_string_compare
262 * SilcBool silc_hash_string_compare(void *key1, void *key2,
263 * void *user_context);
267 * Compares two strings. It may be used as SilcHashTable comparison
271 SilcBool silc_hash_string_compare(void *key1, void *key2, void *user_context);
273 /****f* silcutil/SilcUtilAPI/silc_hash_id_compare
277 * SilcBool silc_hash_id_compare(void *key1, void *key2,
278 * void *user_context);
282 * Compares two ID's. May be used as SilcHashTable comparison function.
283 * The Client ID's compares only the hash of the Client ID not any other
284 * part of the Client ID. Other ID's are fully compared.
287 SilcBool silc_hash_id_compare(void *key1, void *key2, void *user_context);
289 /****f* silcutil/SilcUtilAPI/silc_hash_id_compare_full
293 * SilcBool silc_hash_id_compare_full(void *key1, void *key2,
294 * void *user_context)
298 * Compares two ID's. May be used as SilcHashTable comparison function.
299 * To compare full ID's instead of only partial, like the
300 * silc_hash_id_compare does, use this function.
303 SilcBool silc_hash_id_compare_full(void *key1, void *key2, void *user_context);
305 /****f* silcutil/SilcUtilAPI/silc_hash_client_id_compare
309 * SilcBool silc_hash_client_id_compare(void *key1, void *key2,
310 * void *user_context);
314 * Compare two Client ID's entirely and not just the hash from the ID.
317 SilcBool silc_hash_client_id_compare(void *key1, void *key2,
320 /****f* silcutil/SilcUtilAPI/silc_hash_data_compare
324 * SilcBool silc_hash_data_compare(void *key1, void *key2,
325 * void *user_context);
329 * Compares binary data. May be used as SilcHashTable comparison function.
332 SilcBool silc_hash_data_compare(void *key1, void *key2, void *user_context);
334 /****f* silcutil/SilcUtilAPI/silc_hash_utf8_compare
338 * SilcBool silc_hash_utf8_compare(void *key1, void *key2,
339 * void *user_context);
343 * Compares UTF-8 strings. Casefolded and NULL terminated strings are
344 * expected. May be used as SilcHashTable comparison function.
347 SilcBool silc_hash_utf8_compare(void *key1, void *key2, void *user_context);
349 /****f* silcutil/SilcUtilAPI/silc_hash_public_key_compare
353 * SilcBool silc_hash_public_key_compare(void *key1, void *key2,
354 * void *user_context);
358 * Compares two SILC Public keys. It may be used as SilcHashTable
359 * comparison function.
362 SilcBool silc_hash_public_key_compare(void *key1, void *key2,
365 /****f* silcutil/SilcUtilAPI/silc_fingerprint
369 * char *silc_fingerprint(const unsigned char *data, SilcUInt32 data_len);
373 * Return a textual representation of the fingerprint in *data, the
374 * caller must free the returned string.
377 char *silc_fingerprint(const unsigned char *data, SilcUInt32 data_len);
379 /****f* silcutil/SilcUtilAPI/silc_string_is_ascii
383 * SilcBool silc_string_is_ascii(const unsigned char *data,
384 * SilcUInt32 data_len);
388 * Return TRUE if the `data' is ASCII string.
391 SilcBool silc_string_is_ascii(const unsigned char *data, SilcUInt32 data_len);
393 /****f* silcutil/SilcUtilAPI/silc_get_input
397 * char *silc_get_input(const char *prompt, SilcBool echo_off);
401 * Displays input prompt on command line and takes input data from user.
404 char *silc_get_input(const char *prompt, SilcBool echo_off);
406 /* System dependant prototypes */
408 /****f* silcutil/SilcUtilAPI/silc_get_username
412 * char *silc_get_username();
416 * Returns the username of the user. If the global variable LOGNAME
417 * does not exists we will get the name from the passwd file. The
418 * caller must free the returned name.
420 * This function is system dependant.
423 char *silc_get_username();
425 /****f* silcutil/SilcUtilAPI/silc_get_real_name
429 * char *silc_get_real_name();
433 * Returns the real name of ther user from the passwd file. The
434 * caller must free the returned name.
436 * This function is system dependant.
439 char *silc_get_real_name();
441 /****f* silcutil/SilcUtilAPI/silc_va_copy
445 * void silc_va_copy(va_list dest, va_list src);
449 * Copies variable argument list. This must be called in case the
450 * variable argument list must be evaluated multiple times. For each
451 * evaluation the list must be copied and va_end must be called for
455 #if defined(HAVE_VA_COPY)
456 #define silc_va_copy(dest, src) va_copy(dest, src);
457 #elif defined(HAVE___VA_COPY)
458 #define silc_va_copy(dest, src) __va_copy(dest, src);
459 #elif defined(SILC_VA_COPY_ARRAY)
460 #define silc_va_copy(dest, src) memmove(dest, src, sizeof(va_list));
462 #define silc_va_copy(dest, src) dest = src;
465 #endif /* !SILCUTIL_H */