Merged silc_1_0_branch to trunk.
[silc.git] / lib / silcutil / silcutil.h
index ecaf5796e326315291d3134fcf1ade643fe14383..72aac63e4aad830e7325ed8a067b726e985bd05e 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2002 Pekka Riikonen
+  Copyright (C) 1997 - 2005 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -63,27 +63,42 @@ int silc_check_line(char *buf);
  *
  * SYNOPSIS
  *
- *    char *silc_get_time();
+ *    const char *silc_get_time(SilcUInt32 timeval)
  *
  * DESCRIPTION
  *
- *    Returns current time as string.
+ *    Returns time as string.  If the the `timeval' is non-zero that
+ *    value is returned as string.  If it is zero the current time of the
+ *    local machine is returned.
  *
  ***/
-char *silc_get_time();
+const char *silc_get_time(SilcUInt32 timeval);
 
 /****f* silcutil/SilcUtilAPI/silc_to_upper
  *
  * SYNOPSIS
  *
- *    char *silc_to_upper(char *string);
+ *    bool silc_to_upper(const char *string, char *dest, SilcUInt32 dest_size);
  *
  * DESCRIPTION
  *
  *    Converts string to capital characters.
  *
  ***/
-char *silc_to_upper(char *string);
+bool silc_to_upper(const char *string, char *dest, SilcUInt32 dest_size);
+
+/****f* silcutil/SilcUtilAPI/silc_to_lower
+ *
+ * SYNOPSIS
+ *
+ *    bool silc_to_lower(const char *string, char *dest, SilcUInt32 dest_size);
+ *
+ * DESCRIPTION
+ *
+ *    Converts string to capital characters.
+ *
+ ***/
+bool silc_to_lower(const char *string, char *dest, SilcUInt32 dest_size);
 
 /****f* silcutil/SilcUtilAPI/silc_parse_userfqdn
  *
@@ -181,6 +196,21 @@ int silc_string_compare(char *string1, char *string2);
  ***/
 SilcUInt32 silc_hash_string(void *key, void *user_context);
 
+/****f* silcutil/SilcUtilAPI/silc_hash_utf8_string
+ *
+ * SYNOPSIS
+ *
+ *    SilcUInt32 silc_hash_utf8_string(void *key, void *user_context);
+ *
+ * DESCRIPTION
+ *
+ *    Basic has function to hash UTF-8 strings. May be used with the
+ *    SilcHashTable.  Used with identifier strings.  The key is
+ *    expected to be casefolded.
+ *
+ ***/
+SilcUInt32 silc_hash_utf8_string(void *key, void *user_context);
+
 /****f* silcutil/SilcUtilAPI/silc_hash_uint
  *
  * SYNOPSIS
@@ -220,6 +250,19 @@ SilcUInt32 silc_hash_ptr(void *key, void *user_context);
  ***/
 SilcUInt32 silc_hash_id(void *key, void *user_context);
 
+/****f* silcutil/SilcUtilAPI/silc_hash_client_id_hash
+ *
+ * SYNOPSIS
+ *
+ *    SilcUInt32 silc_hash_client_id_hash(void *key, void *user_context)
+ *
+ * DESCRIPTION
+ *
+ *    Hash Client ID's hash.
+ *
+ ***/
+SilcUInt32 silc_hash_client_id_hash(void *key, void *user_context);
+
 /****f* silcutil/SilcUtilAPI/silc_hash_data
  *
  * SYNOPSIS
@@ -302,11 +345,26 @@ bool silc_hash_client_id_compare(void *key1, void *key2, void *user_context);
  ***/
 bool silc_hash_data_compare(void *key1, void *key2, void *user_context);
 
+/****f* silcutil/SilcUtilAPI/silc_hash_utf8_compare
+ *
+ * SYNOPSIS
+ *
+ *    bool silc_hash_utf8_compare(void *key1, void *key2, void *user_context);
+ *
+ * DESCRIPTION
+ *
+ *    Compares UTF-8 strings.  Casefolded and NULL terminated strings are
+ *    expected.  May be used as SilcHashTable comparison function.
+ *
+ ***/
+bool silc_hash_utf8_compare(void *key1, void *key2, void *user_context);
+
 /****f* silcutil/SilcUtilAPI/silc_hash_public_key_compare
  *
  * SYNOPSIS
  *
- *    bool silc_hash_public_key_compare(void *key1, void *key2, void *user_context);
+ *    bool silc_hash_public_key_compare(void *key1, void *key2,
+ *                                      void *user_context);
  *
  * DESCRIPTION
  *
@@ -365,7 +423,8 @@ char *silc_client_chumode_char(SilcUInt32 mode);
  *
  * DESCRIPTION
  *
- *    Creates fingerprint from data, usually used with SHA1 digests.
+ *    Return a textual representation of the fingerprint in *data, the
+ *    caller must free the returned string.
  *
  ***/
 char *silc_fingerprint(const unsigned char *data, SilcUInt32 data_len);
@@ -443,13 +502,28 @@ char *silc_get_input(const char *prompt, bool echo_off);
  *
  * DESCRIPTION
  *
- *    Return current time to struct timeval.
- *
- *    This function is system dependant.
+ *    Return current time to struct timeval.  This function is system
+ *    dependant.  Returns 0 on success and -1 on error.
  *
  ***/
 int silc_gettimeofday(struct timeval *p);
 
+/****f* silcutil/SilcUtilAPI/silc_compare_timeval
+ *
+ * SYNOPSIS
+ *
+ *    bool silc_compare_timeval(struct timeval *smaller,
+ *                              struct timeval *bigger)
+ *
+ * DESCRIPTION
+ *
+ *    Compare two timeval structures and return TRUE if the first
+ *    time value is smaller than the second time value.
+ *
+ ***/
+bool silc_compare_timeval(struct timeval *smaller,
+                         struct timeval *bigger);
+
 /****f* silcutil/SilcUtilAPI/silc_string_regexify
  *
  * SYNOPSIS
@@ -507,7 +581,8 @@ int silc_string_match(const char *string1, const char *string2);
  * DESCRIPTION
  *
  *    Returns the username of the user. If the global variable LOGNAME
- *    does not exists we will get the name from the passwd file.
+ *    does not exists we will get the name from the passwd file.  The
+ *    caller must free the returned name.
  *
  *    This function is system dependant.
  *
@@ -522,7 +597,8 @@ char *silc_get_username();
  *
  * DESCRIPTION
  *
- *    Returns the real name of ther user from the passwd file.
+ *    Returns the real name of ther user from the passwd file.  The
+ *    caller must free the returned name.
  *
  *    This function is system dependant.
  *
@@ -547,4 +623,43 @@ char *silc_get_real_name();
 bool silc_get_mode_list(SilcBuffer mode_list, SilcUInt32 mode_list_count,
                        SilcUInt32 **list);
 
+/****f* silcutil/SilcUtilAPI/silc_get_status_message
+ *
+ * SYNOPSIS
+ *
+ *    char *silc_get_status_message(SilcStatus status)
+ *
+ * DESCRIPTION
+ *
+ *    Returns status message string
+ *
+ ***/
+const char *silc_get_status_message(unsigned char status);
+
+/****f* silcutil/SilcUtilAPI/silc_get_packet_name
+ *
+ * SYNOPSIS
+ *
+ *    char *silc_get_packet_name(SilcPacketType type);
+ *
+ * DESCRIPTION
+ *
+ *    Returns the name corresponding packet type `type'.
+ *
+ ***/
+const char *silc_get_packet_name(unsigned char type);
+
+/****f* silcutil/SilcUtilAPI/silc_get_command_name
+ *
+ * SYNOPSIS
+ *
+ *    char *silc_get_command_name(SilcCommand command);
+ *
+ * DESCRIPTION
+ *
+ *    Returns the name corresponding SILC command `command'.
+ *
+ ***/
+const char *silc_get_command_name(unsigned char command);
+
 #endif /* !SILCUTIL_H */