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/Misc Utilities
31 /****f* silcutil/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/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/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/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/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/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/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/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/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/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/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/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 #define silc_va_copy(dest, src) __SILC_VA_COPY(dest, src)
228 /****f* silcutil/silc_hexdump
232 * void silc_hexdump(const unsigned char *data, SilcUInt32 data_len,
237 * Dumps the `data' of length of `data_len' bytes as HEX. The `output'
238 * file specifies the destination.
241 void silc_hexdump(const unsigned char *data, SilcUInt32 data_len,
244 /****f* silcutil/silc_hex2data
248 * SilcBool silc_hex2data(const char *hex, unsigned char *data,
249 * SilcUInt32 data_size, SilcUInt32 *ret_data_len);
253 * Converts HEX character string to binary data. Each HEX numbers must
254 * have two characters in the `hex' string.
257 SilcBool silc_hex2data(const char *hex, unsigned char *data,
258 SilcUInt32 data_size, SilcUInt32 *ret_data_len);
260 /****f* silcutil/silc_data2hex
264 * SilcBool silc_data2hex(const unsigned char *data, SilcUInt32 data_len,
265 * char *hex, SilcUInt32 hex_size);
269 * Converts binary data to HEX string. This NULL terminates the `hex'
270 * buffer automatically.
273 SilcBool silc_data2hex(const unsigned char *data, SilcUInt32 data_len,
274 char *hex, SilcUInt32 hex_size);
276 /****f* silcutil/silc_get_num_cpu
280 * int silc_get_num_cpu(void);
284 * Returns the number of CPU cores in the current machine. Returns 0
285 * if the routine could not determine the number of cores.
288 int silc_get_num_cpu(void);
290 #endif /* !SILCUTIL_H */