Added SILC Thread Queue API
[silc.git] / lib / silcutil / silcstrutil.h
index 23451d50c3ab86aaf59597a585f27b6967b93d7b..bc692975259bc59632b126fa4b7556d720482ea8 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2002 - 2005 Pekka Riikonen
+  Copyright (C) 2002 - 2007 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
@@ -67,90 +67,7 @@ typedef enum {
 } SilcStringEncoding;
 /***/
 
-/****f* silcutil/SilcStrUtilAPI/silc_pem_encode
- *
- * SYNOPSIS
- *
- *    char *silc_pem_encode(unsigned char *data, SilcUInt32 len);
- *
- * DESCRIPTION
- *
- *    Encodes data into PEM encoding. Returns NULL terminated PEM encoded
- *    data string. Note: This is originally public domain code and is
- *    still PD.
- *
- ***/
-char *silc_pem_encode(unsigned char *data, SilcUInt32 len);
-
-/****f* silcutil/SilcStrUtilAPI/silc_pem_encode_file
- *
- * SYNOPSIS
- *
- *    char *silc_pem_encode_file(unsigned char *data, SilcUInt32 data_len);
- *
- * DESCRIPTION
- *
- *    Same as silc_pem_encode() but puts newline ('\n') every 72 characters.
- *
- ***/
-char *silc_pem_encode_file(unsigned char *data, SilcUInt32 data_len);
-
-/****f* silcutil/SilcStrUtilAPI/silc_pem_decode
- *
- * SYNOPSIS
- *
- *    unsigned char *silc_pem_decode(unsigned char *pem, SilcUInt32 pem_len,
- *                                   SilcUInt32 *ret_len);
- *
- * DESCRIPTION
- *
- *    Decodes PEM into data. Returns the decoded data. Note: This is
- *    originally public domain code and is still PD.
- *
- ***/
-unsigned char *silc_pem_decode(unsigned char *pem, SilcUInt32 pem_len,
-                              SilcUInt32 *ret_len);
-
-/****f* silcutil/SilcStrUtilAPI/silc_mime_parse
- *
- * SYNOPSIS
- *
- *    SilcBool
- *    silc_mime_parse(const unsigned char *mime, SilcUInt32 mime_len,
- *                    char *version, SilcUInt32 version_size,
- *                    char *content_type, SilcUInt32 content_type_size,
- *                    char *transfer_encoding,
- *                    SilcUInt32 transfer_encoding_size,
- *                    unsigned char **mime_data_ptr,
- *                    SilcUInt32 *mime_data_len);
- *
- * DESCRIPTION
- *
- *    Parses MIME header indicated by `mime' data block of length of
- *    `mime_len'.  Returns TRUE if the `mime' is valid MIME object.
- *    Parses from the MIME header the MIME Version (if present) and
- *    copies it to the `version' pointer if provided, content type
- *    indicating the data in the MIME object and copies it to the
- *    `content_type' if provided, and the tranfer encoding (if present)
- *    indicating the encoding of the data and copies it to the
- *    `content_transfer_encoding' if provided.
- *
- *    The pointer to the actual data in the MIME object is saved into
- *    `mime_data_ptr'.  The pointer is a location in the `mime' and it
- *    does not allocate or copy anything, ie. the `mime_data_ptr' is a
- *    pointer to the `mime'.  The `mime_data_len' indicates the length of
- *    the data without the MIME header.  The caller is responsible of
- *    NULL terminating the buffers it provides.
- *
- ***/
-SilcBool
-silc_mime_parse(const unsigned char *mime, SilcUInt32 mime_len,
-                char *version, SilcUInt32 version_size,
-                char *content_type, SilcUInt32 content_type_size,
-                char *transfer_encoding, SilcUInt32 transfer_encoding_size,
-                unsigned char **mime_data_ptr, SilcUInt32 *mime_data_len);
-
-/****f* silcutil/SilcStrUtilAPI/silc_strncat
+/****f* silcutil/SilcStrStrUtilAPI/silc_strncat
  *
  * SYNOPSIS
  *
@@ -167,152 +84,64 @@ silc_mime_parse(const unsigned char *mime, SilcUInt32 mime_len,
 char *silc_strncat(char *dest, SilcUInt32 dest_size,
                   const char *src, SilcUInt32 src_len);
 
-/****f* silcutil/SilcStrUtilAPI/silc_identifier_check
+/****f* silcutil/SilcStrUtilAPI/silc_string_regexify
  *
  * SYNOPSIS
  *
- *    unsigned char *
- *    silc_identifier_check(const unsigned char *identifier,
- *                          SilcUInt32 identifier_len,
- *                          SilcStringEncoding identifier_encoding,
- *                          SilcUInt32 max_allowed_length,
- *                          SilcUInt32 *out_len);
+ *    char *silc_string_regexify(const char *string);
  *
  * DESCRIPTION
  *
- *    Checks that the 'identifier' string is valid identifier string
- *    and does not contain any unassigned or prohibited character.  This
- *    function is used to check for valid nicknames, server names, 
- *    usernames, hostnames, service names, algorithm names, other security 
- *    property names, and SILC Public Key name.
- *
- *    If the 'max_allowed_length' is non-zero the identifier cannot be
- *    longer than that, and NULL is returned if it is.  If zero (0), no
- *    length limit exist.  For nicknames the max length must be 128 bytes.
- *    Other identifiers has no default limit, but application may choose 
-*     one anyway.
- *
- *    Returns the validated string, that the caller must free.  Returns
- *    NULL if the identifier string is not valid or contain unassigned or
- *    prohibited characters.  Such identifier strings must not be used
- *    SILC protocol.  The returned string is always in UTF-8 encoding.
- *    The length of the returned string is in 'out_len'.
- *
- * NOTES
- *
- *    In addition of validating the identifier string, this function
- *    may map characters to other characters or remove characters from the
- *    original string.  This is done as defined in the SILC protocol.  Error
- *    is returned only if the string contains unassigned or prohibited
- *    characters.  The original 'identifier' is not modified at any point.
+ *    Inspects the `string' for wildcards and returns regex string that can
+ *    be used by the GNU regex library. A comma (`,') in the `string' means
+ *    that the string is list.
  *
  ***/
-unsigned char *silc_identifier_check(const unsigned char *identifier,
-                                    SilcUInt32 identifier_len,
-                                    SilcStringEncoding identifier_encoding,
-                                    SilcUInt32 max_allowed_length,
-                                    SilcUInt32 *out_len);
+char *silc_string_regexify(const char *string);
 
-/****f* silcutil/SilcStrUtilAPI/silc_identifier_verify
+/****f* silcutil/SilcStrUtilAPI/silc_string_match
  *
  * SYNOPSIS
  *
- *    SilcBool
- *    silc_identifier_check(const unsigned char *identifier,
- *                          SilcUInt32 identifier_len,
- *                          SilcStringEncoding identifier_encoding,
- *                          SilcUInt32 max_allowed_length);
+ *    int silc_string_match(const char *string1, const char *string2);
  *
  * DESCRIPTION
  *
- *    Checks that the 'identifier' string is valid identifier string
- *    and does not contain any unassigned or prohibited character.  This
- *    function is used to check for valid nicknames, server names, 
- *    usernames, hostnames, service names, algorithm names, other security 
- *    property names, and SILC Public Key name.
- *
- *    If the 'max_allowed_length' is non-zero the identifier cannot be
- *    longer than that, and NULL is returned if it is.  If zero (0), no
- *    length limit exist.  For nicknames the max length must be 128 bytes.
- *    Other identifiers has no default limit, but application may choose 
- *    one anyway.
- *
- *    Returns TRUE if the string is valid and FALSE if it is prohibited.
+ *    Do regex match to the two strings `string1' and `string2'. If the
+ *    `string2' matches the `string1' this returns TRUE.
  *
  ***/
-SilcBool silc_identifier_verify(const unsigned char *identifier,
-                           SilcUInt32 identifier_len,
-                           SilcStringEncoding identifier_encoding,
-                           SilcUInt32 max_allowed_length);
+int silc_string_match(const char *string1, const char *string2);
 
-/****f* silcutil/SilcStrUtilAPI/silc_channel_name_check
+/****f* silcutil/SilcStrUtilAPI/silc_string_compare
  *
  * SYNOPSIS
  *
- *    unsigned char *
- *    silc_channel_name_check(const unsigned char *identifier,
- *                            SilcUInt32 identifier_len,
- *                            SilcStringEncoding identifier_encoding,
- *                            SilcUInt32 max_allowed_length,
- *                            SilcUInt32 *out_len);
+ *    int silc_string_compare(char *string1, char *string2);
  *
  * DESCRIPTION
  *
- *    Checks that the 'identifier' string is valid channel name string
- *    and does not contain any unassigned or prohibited character.
- *
- *    If the 'max_allowed_length' is non-zero the identifier cannot be
- *    longer than that, and NULL is returned if it is.  If zero (0), no
- *    length limit exist.  For channel names the max length must be 256
- *    bytes.
- *
- *    Returns the validated string, that the caller must free.  Returns
- *    NULL if the identifier string is not valid or contain unassigned or
- *    prohibited characters.  Such identifier strings must not be used
- *    SILC protocol.  The returned string is always in UTF-8 encoding.
- *    The length of the returned string is in 'out_len'.
- *
- * NOTES
- *
- *    In addition of validating the channel name string, this function
- *    may map characters to other characters or remove characters from the
- *    original string.  This is done as defined in the SILC protocol.  Error
- *    is returned only if the string contains unassigned or prohibited
- *    characters.  The original 'identifier' is not modified at any point.
+ *    Compares two strings. Strings may include wildcards '*' and '?'.
+ *    Returns TRUE if strings match.
  *
  ***/
-unsigned char *silc_channel_name_check(const unsigned char *identifier,
-                                      SilcUInt32 identifier_len,
-                                      SilcStringEncoding identifier_encoding,
-                                      SilcUInt32 max_allowed_length,
-                                      SilcUInt32 *out_len);
+int silc_string_compare(char *string1, char *string2);
 
-/****f* silcutil/SilcStrUtilAPI/silc_channel_name_verify
+/****f* silcutil/SilcStrUtilAPI/silc_string_split
  *
  * SYNOPSIS
  *
- *    SilcBool
- *    silc_channel_name_check(const unsigned char *identifier,
- *                            SilcUInt32 identifier_len,
- *                            SilcStringEncoding identifier_encoding,
- *                            SilcUInt32 max_allowed_length);
+ *    char **silc_string_split(const char *string, char ch, int *ret_count);
  *
  * DESCRIPTION
  *
- *    Checks that the 'identifier' string is valid channel name string
- *    and does not contain any unassigned or prohibited character.
- *
- *    If the 'max_allowed_length' is non-zero the identifier cannot be
- *    longer than that, and NULL is returned if it is.  If zero (0), no
- *    length limit exist.  For channel names the max length must be 256
- *    bytes.
- *
- *    Returns TRUE if the string is valid and FALSE if it is prohibited.
+ *    Splits a `string' that has a separator `ch' into an array of strings
+ *    and returns the array.  The `ret_count' will contain the number of
+ *    strings in the array.  Caller must free the strings and the array.
+ *    Returns NULL on error.  If the string does not have `ch' separator
+ *    this returns the `string' in the array.
  *
  ***/
-SilcBool silc_channel_name_verify(const unsigned char *identifier,
-                             SilcUInt32 identifier_len,
-                             SilcStringEncoding identifier_encoding,
-                             SilcUInt32 max_allowed_length);
+char **silc_string_split(const char *string, char ch, int *ret_count);
 
 #endif /* SILCSTRUTIL_H */