Added preliminary Symbian support.
[silc.git] / lib / silcutil / silcstrutil.h
1 /*
2
3   silcstrutil.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2002 - 2007 Pekka Riikonen
8
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.
12
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.
17
18 */
19
20 /****h* silcutil/SILC String Utilities
21  *
22  * DESCRIPTION
23  *
24  * String manipulation utility routines.  These routines provides
25  * various helper functions for encoding, decoding and otherwise
26  * managing strings.
27  *
28  ***/
29
30 #ifndef SILCSTRUTIL_H
31 #define SILCSTRUTIL_H
32
33 /****d* silcutil/SilcStrUtilAPI/SilcStringEncoding
34  *
35  * NAME
36  *
37  *    typedef enum { ... } SilcStringEncoding;
38  *
39  * DESCRIPTION
40  *
41  *    String encoding definitions used with various string manipulation
42  *    routines.  By default, applications are suggested to use
43  *    SILC_STRING_LOCALE since it encodes and decodes correctly according
44  *    to local system language and character set (locale).
45  *
46  * SOURCE
47  */
48 typedef enum {
49   SILC_STRING_ASCII         = 0,  /* Any 8 bit ASCII encoding (default) */
50   SILC_STRING_ASCII_ESC     = 1,  /* 7 bit ASCII (>0x7f escaped) */
51   SILC_STRING_BMP           = 2,  /* 16 bit, UCS-2, BMP, ISO/IEC 10646 */
52   SILC_STRING_BMP_LSB       = 3,  /* BMP, least significant byte first */
53   SILC_STRING_UNIVERSAL     = 4,  /* 32 bit, UCS-4, Universal, ISO/IEC 10646 */
54   SILC_STRING_UNIVERSAL_LSB = 5,  /* Universal, least significant byte first */
55   SILC_STRING_LOCALE        = 6,  /* A locale specific conversion on
56                                      those platforms that support iconv().
57                                      Fallback is SILC_STRING_ASCII. */
58   SILC_STRING_UTF8          = 7,  /* UTF-8 encoding */
59   SILC_STRING_PRINTABLE     = 8,  /* Printable ASCII (no escaping) */
60   SILC_STRING_VISIBLE       = 9,  /* Visible ASCII string */
61   SILC_STRING_TELETEX       = 10, /* Teletex ASCII string */
62   SILC_STRING_NUMERICAL     = 11, /* Numerical ASCII string (digits) */
63   SILC_STRING_LDAP_DN       = 12, /* Strings for LDAP DNs, RFC 2253 */
64   SILC_STRING_UTF8_ESCAPE   = 12, /* Escaped UTF-8 as defined in RFC 2253 */
65
66   SILC_STRING_LANGUAGE      = 6,  /* _Deprecated_, use SILC_STRING_LOCALE. */
67 } SilcStringEncoding;
68 /***/
69
70 /****f* silcutil/SilcStrUtilAPI/silc_pem_encode
71  *
72  * SYNOPSIS
73  *
74  *    char *silc_pem_encode(unsigned char *data, SilcUInt32 len);
75  *
76  * DESCRIPTION
77  *
78  *    Encodes data into PEM encoding. Returns NULL terminated PEM encoded
79  *    data string. Note: This is originally public domain code and is
80  *    still PD.
81  *
82  ***/
83 char *silc_pem_encode(unsigned char *data, SilcUInt32 len);
84
85 /****f* silcutil/SilcStrUtilAPI/silc_pem_encode_file
86  *
87  * SYNOPSIS
88  *
89  *    char *silc_pem_encode_file(unsigned char *data, SilcUInt32 data_len);
90  *
91  * DESCRIPTION
92  *
93  *    Same as silc_pem_encode() but puts newline ('\n') every 72 characters.
94  *
95  ***/
96 char *silc_pem_encode_file(unsigned char *data, SilcUInt32 data_len);
97
98 /****f* silcutil/SilcStrUtilAPI/silc_pem_decode
99  *
100  * SYNOPSIS
101  *
102  *    unsigned char *silc_pem_decode(unsigned char *pem, SilcUInt32 pem_len,
103  *                                   SilcUInt32 *ret_len);
104  *
105  * DESCRIPTION
106  *
107  *    Decodes PEM into data. Returns the decoded data. Note: This is
108  *    originally public domain code and is still PD.
109  *
110  ***/
111 unsigned char *silc_pem_decode(unsigned char *pem, SilcUInt32 pem_len,
112                                SilcUInt32 *ret_len);
113
114 /****f* silcutil/SilcStrStrUtilAPI/silc_snprintf
115  *
116  * SYNOPSIS
117  *
118  *    int silc_snprintf(char *str, SilcUInt32 size, const char *format, ...);
119  *
120  * DESCRIPTION
121  *
122  *    Produces output string according to the `format'.  The formatting
123  *    is equivalent to silc_snprintf(3) and sprintf(3).  Returns the number of
124  *    characters output into `str', at most `size' characters including the
125  *    trailing '\0' character.  Returns negative value on error.
126  *
127  ***/
128 #ifndef SILC_SNPRINTF
129 int silc_snprintf(char *str, SilcUInt32 size, const char *format, ...);
130 #else
131 #define silc_snprintf snprintf
132 #endif /* SILC_SNPRINTF */
133
134 /****f* silcutil/SilcStrStrUtilAPI/silc_strncat
135  *
136  * SYNOPSIS
137  *
138  *    char *silc_strncat(char *dest, SilcUInt32 dest_size,
139  *                       const char *src, SilcUInt32 src_len);
140  *
141  * DESCRIPTION
142  *
143  *    Concatenates the `src' into `dest'.  If `src_len' is more than the
144  *    size of the `dest' (minus NULL at the end) the `src' will be
145  *    truncated to fit.
146  *
147  ***/
148 char *silc_strncat(char *dest, SilcUInt32 dest_size,
149                    const char *src, SilcUInt32 src_len);
150
151 /****f* silcutil/SilcStrUtilAPI/silc_string_regexify
152  *
153  * SYNOPSIS
154  *
155  *    char *silc_string_regexify(const char *string);
156  *
157  * DESCRIPTION
158  *
159  *    Inspects the `string' for wildcards and returns regex string that can
160  *    be used by the GNU regex library. A comma (`,') in the `string' means
161  *    that the string is list.
162  *
163  *    This function is system dependant.
164  *
165  ***/
166 char *silc_string_regexify(const char *string);
167
168 /****f* silcutil/SilcStrUtilAPI/silc_string_regex_match
169  *
170  * SYNOPSIS
171  *
172  *    int silc_string_regex_match(const char *regex, const char *string);
173  *
174  * DESCRIPTION
175  *
176  *    Matches the two strings and returns TRUE if the strings match.
177  *
178  *    This function is system dependant.
179  *
180  ***/
181 int silc_string_regex_match(const char *regex, const char *string);
182
183 /****f* silcutil/SilcStrUtilAPI/silc_string_match
184  *
185  * SYNOPSIS
186  *
187  *    int silc_string_match(const char *string1, const char *string2);
188  *
189  * DESCRIPTION
190  *
191  *    Do regex match to the two strings `string1' and `string2'. If the
192  *    `string2' matches the `string1' this returns TRUE.
193  *
194  *    This function is system dependant.
195  *
196  ***/
197 int silc_string_match(const char *string1, const char *string2);
198
199 /****f* silcutil/SilcStrUtilAPI/silc_string_compare
200  *
201  * SYNOPSIS
202  *
203  *    int silc_string_compare(char *string1, char *string2);
204  *
205  * DESCRIPTION
206  *
207  *    Compares two strings. Strings may include wildcards '*' and '?'.
208  *    Returns TRUE if strings match.
209  *
210  ***/
211 int silc_string_compare(char *string1, char *string2);
212
213 /****f* silcutil/SilcStrUtilAPI/silc_string_split
214  *
215  * SYNOPSIS
216  *
217  *    char **silc_string_split(const char *string, char ch, int *ret_count);
218  *
219  * DESCRIPTION
220  *
221  *    Splits a `string' that has a separator `ch' into an array of strings
222  *    and returns the array.  The `ret_count' will contain the number of
223  *    strings in the array.  Caller must free the strings and the array.
224  *    Returns NULL on error.  If the string does not have `ch' separator
225  *    this returns the `string' in the array.
226  *
227  ***/
228 char **silc_string_split(const char *string, char ch, int *ret_count);
229
230 #endif /* SILCSTRUTIL_H */