5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1997 - 2008 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_to_upper
51 * SilcBool silc_to_upper(const char *string, char *dest,
52 * SilcUInt32 dest_size);
56 * Converts string to capital characters.
59 SilcBool silc_to_upper(const char *string, char *dest, SilcUInt32 dest_size);
61 /****f* silcutil/SilcUtilAPI/silc_to_lower
65 * SilcBool silc_to_lower(const char *string, char *dest,
66 * SilcUInt32 dest_size);
70 * Converts string to capital characters.
73 SilcBool silc_to_lower(const char *string, char *dest, SilcUInt32 dest_size);
75 /****f* silcutil/SilcUtilAPI/silc_parse_userfqdn
79 * int silc_parse_userfqdn(const char *string,
80 * char *user, SilcUInt32 user_size,
81 * char *fqdn, SilcUInt32 fqdn_size);
85 * Parse userfqdn string which is in user@fqdn format. Returns 0 on
86 * error, 1 if `user' was filled and 2 if both `user' and `fqdn'
90 int silc_parse_userfqdn(const char *string,
91 char *user, SilcUInt32 user_size,
92 char *fqdn, SilcUInt32 fqdn_size);
94 /****f* silcutil/SilcUtilAPI/silc_parse_command_line
98 * void silc_parse_command_line(unsigned char *buffer,
99 * unsigned char ***parsed,
100 * SilcUInt32 **parsed_lens,
101 * SilcUInt32 **parsed_types,
102 * SilcUInt32 *parsed_num,
103 * SilcUInt32 max_args);
107 * Parses command line. At most `max_args' is taken. Rest of the line
108 * will be allocated as the last argument if there are more than `max_args'
109 * arguments in the line. Note that the command name is counted as one
110 * argument and is saved.
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);
120 /****f* silcutil/SilcUtilAPI/silc_format
124 * char *silc_format(char *fmt, ...);
128 * Formats arguments to a string and returns it after allocating memory
129 * for it. It must be remembered to free it later.
132 char *silc_format(char *fmt, ...);
134 /****f* silcutil/SilcUtilAPI/silc_fingerprint
138 * char *silc_fingerprint(const unsigned char *data, SilcUInt32 data_len);
142 * Return a textual representation of the fingerprint in *data, the
143 * caller must free the returned string. Returns NULL on error. If
144 * the `data_len' is longer than 255 bytes, only the first 255 bytes are
145 * used to create the fingerprint.
148 char *silc_fingerprint(const unsigned char *data, SilcUInt32 data_len);
150 /****f* silcutil/SilcUtilAPI/silc_string_is_ascii
154 * SilcBool silc_string_is_ascii(const unsigned char *data,
155 * SilcUInt32 data_len);
159 * Return TRUE if the `data' is ASCII string.
162 SilcBool silc_string_is_ascii(const unsigned char *data, SilcUInt32 data_len);
164 /****f* silcutil/SilcUtilAPI/silc_get_input
168 * char *silc_get_input(const char *prompt, SilcBool echo_off);
172 * Displays input prompt on command line and takes input data from user.
175 char *silc_get_input(const char *prompt, SilcBool echo_off);
177 /* System dependant prototypes */
179 /****f* silcutil/SilcUtilAPI/silc_get_username
183 * char *silc_get_username();
187 * Returns the username of the user. If the global variable LOGNAME
188 * does not exists we will get the name from the passwd file. The
189 * caller must free the returned name.
191 * This function is system dependant.
194 char *silc_get_username();
196 /****f* silcutil/SilcUtilAPI/silc_get_real_name
200 * char *silc_get_real_name();
204 * Returns the real name of ther user from the passwd file. The
205 * caller must free the returned name.
207 * This function is system dependant.
210 char *silc_get_real_name();
212 /****f* silcutil/SilcUtilAPI/silc_va_copy
216 * void silc_va_copy(va_list dest, va_list src);
220 * Copies variable argument list. This must be called in case the
221 * variable argument list must be evaluated multiple times. For each
222 * evaluation the list must be copied and va_end must be called for
226 #if defined(HAVE_VA_COPY)
227 #define silc_va_copy(dest, src) va_copy(dest, src);
228 #elif defined(HAVE___VA_COPY)
229 #define silc_va_copy(dest, src) __va_copy(dest, src);
230 #elif defined(SILC_VA_COPY_ARRAY)
231 #define silc_va_copy(dest, src) memmove(dest, src, sizeof(va_list));
233 #define silc_va_copy(dest, src) dest = src;
236 /****f* silcutil/SilcUtilAPI/silc_hexdump
240 * void silc_hexdump(const unsigned char *data, SilcUInt32 data_len,
245 * Dumps the `data' of length of `data_len' bytes as HEX. The `output'
246 * file specifies the destination.
249 void silc_hexdump(const unsigned char *data, SilcUInt32 data_len,
252 /****f* silcutil/SilcUtilAPI/silc_hex2data
256 * SilcBool silc_hex2data(const char *hex, unsigned char *data,
257 * SilcUInt32 data_size, SilcUInt32 *ret_data_len);
261 * Converts HEX character string to binary data. Each HEX numbers must
262 * have two characters in the `hex' string.
265 SilcBool silc_hex2data(const char *hex, unsigned char *data,
266 SilcUInt32 data_size, SilcUInt32 *ret_data_len);
268 /****f* silcutil/SilcUtilAPI/silc_data2hex
272 * SilcBool silc_data2hex(const unsigned char *data, SilcUInt32 data_len,
273 * char *hex, SilcUInt32 hex_size);
277 * Converts binary data to HEX string. This NULL terminates the `hex'
278 * buffer automatically.
281 SilcBool silc_data2hex(const unsigned char *data, SilcUInt32 data_len,
282 char *hex, SilcUInt32 hex_size);
284 #endif /* !SILCUTIL_H */