Mercurial > pidgin
annotate src/util.h @ 5864:417b1001d2b1
[gaim-migrate @ 6295]
Rewrote the pounce API again. Now it's even MORE core/UI-split, and will
allow for loading/saving.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Sat, 14 Jun 2003 11:14:49 +0000 |
parents | bd0d0e89cac3 |
children | 059d95c67cda |
rev | line source |
---|---|
4890 | 1 /** |
2 * @file util.h Utility Functions | |
5034
4691c5936c01
[gaim-migrate @ 5377]
Christian Hammond <chipx86@chipx86.com>
parents:
4890
diff
changeset
|
3 * @ingroup core |
4890 | 4 * |
5 * gaim | |
6 * | |
7 * Copyright (C) 2002-2003, Christian Hammond <chipx86@gnupdate.org> | |
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; either version 2 of the License, or | |
12 * (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
22 * | |
23 * @todo Rename the functions so that they live somewhere in the gaim | |
24 * namespace. | |
25 */ | |
26 #ifndef _GAIM_UTIL_H_ | |
27 #define _GAIM_UTIL_H_ | |
28 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5532
diff
changeset
|
29 #include "account.h" |
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5532
diff
changeset
|
30 |
4890 | 31 /** |
32 * Normalizes a string, so that it is suitable for comparison. | |
33 * | |
34 * The returned string will point to a static buffer, so if the | |
35 * string is intended to be kept long-term, you <i>must</i> | |
36 * g_strdup() it. Also, calling normalize() twice in the same line | |
37 * will lead to problems. | |
38 * | |
39 * @param str The string to normalize. | |
40 * | |
41 * @return A pointer to the normalized version stored in a static buffer. | |
42 */ | |
43 char *normalize(const char *str); | |
44 | |
45 /** | |
46 * Converts a string to its base-64 equivalent. | |
47 * | |
5426 | 48 * @param buf The data to convert. |
5532 | 49 * @param len The length of the data. |
4890 | 50 * |
51 * @return The base-64 version of @a str. | |
52 * | |
53 * @see frombase64() | |
54 */ | |
5426 | 55 char *tobase64(const unsigned char *buf, size_t len); |
4890 | 56 |
57 /** | |
58 * Converts a string back from its base-64 equivalent. | |
59 * | |
60 * @param str The string to convert back. | |
61 * @param ret_str The returned, non-base-64 string. | |
62 * @param ret_len The returned string length. | |
63 * | |
64 * @see tobase64() | |
65 */ | |
66 void frombase64(const char *str, char **ret_str, int *ret_len); | |
67 | |
68 /** | |
69 * Converts a string to its base-16 equivalent. | |
70 * | |
71 * @param str The string to convert. | |
72 * @param len The length of the string. | |
73 * | |
74 * @return The base-16 string. | |
75 * | |
76 * @see frombase16() | |
77 */ | |
5451 | 78 unsigned char *tobase16(const unsigned char *str, int len); |
4890 | 79 |
80 /** | |
81 * Converts a string back from its base-16 equivalent. | |
82 * | |
83 * @param str The string to convert back. | |
84 * @param ret_str The returned, non-base-16 string. | |
5451 | 85 * |
4890 | 86 * @return The length of the returned string. |
87 * | |
88 * @see tobase16() | |
89 */ | |
5497 | 90 int frombase16(const char *str, unsigned char **ret_str); |
4890 | 91 |
92 /** | |
93 * Waits for all child processes to terminate. | |
94 */ | |
95 void clean_pid(void); | |
96 | |
97 /** | |
98 * Returns the current local time in hour:minute:second form. | |
99 * | |
100 * The returned string is stored in a static buffer, so the result | |
101 * should be g_strdup()'d if it's intended to be used for long. | |
102 * | |
103 * @return The current local time. | |
104 * | |
105 * @see full_date() | |
106 */ | |
107 char *date(void); | |
108 | |
109 /** | |
110 * Adds the necessary HTML code to turn URIs into HTML links in a string. | |
111 * | |
5136 | 112 * @param str The string to linkify. |
4890 | 113 * |
5136 | 114 * @return The linkified text. |
4890 | 115 */ |
5136 | 116 char *linkify_text(const char *str); |
4890 | 117 |
118 /** | |
119 * Converts seconds into a human-readable form. | |
120 * | |
121 * @param sec The seconds. | |
122 * | |
123 * @return A human-readable form, containing days, hours, minutes, and | |
124 * seconds. | |
125 */ | |
126 char *sec_to_text(guint sec); | |
127 | |
128 /** | |
129 * Finds a gaim_account with the specified name and protocol ID. | |
130 * | |
131 * @param name The name of the account. | |
132 * @param protocol The protocol type. | |
133 * | |
134 * @return The gaim_account, if found, or @c NULL otherwise. | |
135 */ | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5532
diff
changeset
|
136 GaimAccount *gaim_account_find(const char *name, int protocol); |
4890 | 137 |
138 /** | |
139 * Returns the date and time in human-readable form. | |
140 * | |
141 * The returned string is stored in a static buffer, so the result | |
142 * should be g_strdup()'d if it's intended to be used for long. | |
143 * | |
144 * @return The date and time in human-readable form. | |
145 * | |
146 * @see date() | |
147 */ | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5532
diff
changeset
|
148 char *full_date(void); |
4890 | 149 |
150 /** | |
151 * Looks for %n, %d, or %t in a string, and replaces them with the | |
152 * specified name, date, and time, respectively. | |
153 * | |
154 * The returned string is stored in a static buffer, so the result | |
155 * should be g_strdup()'d if it's intended to be used for long. | |
156 * | |
157 * @param str The string that may contain the special variables. | |
158 * @param name The sender name. | |
159 * | |
160 * @return A new string where the special variables are expanded. | |
161 */ | |
162 char *away_subs(const char *str, const char *name); | |
163 | |
164 /** | |
165 * Stylizes the specified text using HTML, according to the current | |
166 * font options. | |
167 * | |
168 * @param text The text to stylize. | |
169 * @param len The intended length of the new buffer. | |
170 * | |
171 * @return A newly allocated string of length @a len, containing the | |
172 * stylized version of @a text. | |
173 * | |
174 * @todo Move this to a UI-specific file. | |
175 */ | |
176 char *stylize(const gchar *text, int len); | |
177 | |
178 /** | |
179 * Shows the usage options for the gaim binary. | |
180 * | |
181 * @param mode @c 0 for full options, or @c 1 for a short summary. | |
182 * @param name The name of the binary. | |
183 * | |
184 * @todo Move this to the binary, when a library is formed. | |
185 */ | |
186 void show_usage(int mode, const char *name); | |
187 | |
188 /**` | |
189 * Returns the user's home directory. | |
190 * | |
191 * @return The user's home directory. | |
192 * | |
193 * @see gaim_user_dir() | |
194 */ | |
195 const gchar *gaim_home_dir(void); | |
196 | |
197 /** | |
198 * Returns the gaim settings directory in the user's home directory. | |
199 * | |
200 * @return The gaim settings directory. | |
201 * | |
202 * @see gaim_home_dir() | |
203 */ | |
204 char *gaim_user_dir(void); | |
205 | |
206 /** | |
207 * Copies a string and replaces all HTML linebreaks with newline characters. | |
208 * | |
209 * @param dest The destination string. | |
210 * @param src The source string. | |
211 * @param dest_len The destination string length. | |
212 * | |
213 * @see strncpy_withhtml() | |
214 * @see strdup_withhtml() | |
215 */ | |
216 void strncpy_nohtml(gchar *dest, const gchar *src, size_t dest_len); | |
217 | |
218 /** | |
219 * Copies a string and replaces all newline characters with HTML linebreaks. | |
220 * | |
221 * @param dest The destination string. | |
222 * @param src The source string. | |
223 * @param dest_len The destination string length. | |
224 * | |
225 * @see strncpy_nohtml() | |
226 * @see strdup_withhtml() | |
227 */ | |
228 void strncpy_withhtml(gchar *dest, const gchar *src, size_t dest_len); | |
229 | |
230 /** | |
231 * Duplicates a string and replaces all newline characters from the | |
232 * source string with HTML linebreaks. | |
233 * | |
234 * @param src The source string. | |
235 * | |
236 * @return The new string. | |
237 * | |
238 * @see strncpy_nohtml() | |
239 * @see strncpy_withhtml() | |
240 */ | |
241 gchar *strdup_withhtml(const gchar *src); | |
242 | |
243 /** | |
244 * Ensures that all linefeeds have a matching carriage return. | |
245 * | |
246 * @param str The source string. | |
247 * | |
248 * @return The string with carriage returns. | |
249 */ | |
5136 | 250 char *add_cr(const char *); |
4890 | 251 |
252 /** | |
253 * Strips all linefeeds from a string. | |
254 * | |
255 * @param str The string to strip linefeeds from. | |
256 */ | |
257 void strip_linefeed(char *str); | |
258 | |
259 /** | |
260 * Builds a time_t from the supplied information. | |
261 * | |
262 * @param year The year. | |
263 * @param month The month. | |
264 * @param day The day. | |
265 * @param hour The hour. | |
266 * @param min The minute. | |
267 * @param sec The second. | |
268 * | |
269 * @return A time_t. | |
270 */ | |
271 time_t get_time(int year, int month, int day, | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5532
diff
changeset
|
272 int hour, int min, int sec); |
4890 | 273 |
274 /** | |
275 * Creates a temporary file and returns a file pointer to it. | |
276 * | |
277 * This is like mkstemp(), but returns a file pointer and uses a | |
278 * pre-set template. It uses the semantics of tempnam() for the | |
279 * directory to use and allocates the space for the file path. | |
280 * | |
281 * The caller is responsible for closing the file and removing it when | |
282 * done, as well as freeing the space pointed to by @a path with | |
283 * g_free(). | |
284 * | |
285 * @param path The returned path to the temp file. | |
286 * | |
287 * @return A file pointer to the temporary file, or @c NULL on failure. | |
288 */ | |
289 FILE *gaim_mkstemp(gchar **path); | |
290 | |
291 /** | |
292 * Acts upon an aim: URI. | |
293 * | |
294 * @param uri The URI. | |
295 * | |
296 * @return The response based off the action in the URI. | |
297 */ | |
298 const char *handle_uri(char *uri); | |
299 | |
300 /* This guy does its best to convert a string to UTF-8 from an unknown | |
301 * encoding by checking the locale and trying some sane defaults ... | |
302 * if everything fails it returns NULL. */ | |
303 | |
304 /** | |
305 * Attempts to convert a string to UTF-8 from an unknown encoding. | |
306 * | |
307 * This function checks the locale and tries sane defaults. | |
308 * | |
309 * @param str The source string. | |
310 * | |
311 * @return The UTF-8 string, or @c NULL if it could not be converted. | |
312 */ | |
313 char *gaim_try_conv_to_utf8(const char *str); | |
314 | |
315 /** | |
316 * Returns the IP address from a socket file descriptor. | |
317 * | |
318 * @param fd The socket file descriptor. | |
319 * | |
320 * @return The IP address, or @c NULL on error. | |
321 */ | |
322 char *gaim_getip_from_fd(int fd); | |
323 | |
324 /** | |
325 * Compares two UTF-8 strings. | |
326 * | |
327 * @param a The first string. | |
328 * @param b The second string. | |
329 * | |
330 * @return -1 if @a is less than @a b. | |
331 * 0 if @a is equal to @a b. | |
332 * 1 if @a is greater than @a b. | |
333 */ | |
334 gint gaim_utf8_strcasecmp(const gchar *a, const gchar *b); | |
335 | |
5515 | 336 /** |
337 * Given a string, this replaces one substring with another | |
338 * and returns a newly allocated string. | |
339 * | |
340 * @param string The string from which to replace stuff. | |
341 * @param delimiter The substring you want replaced. | |
342 * @param replacement The substring you want inserted in place | |
343 * of the delimiting substring. | |
344 */ | |
345 gchar *gaim_strreplace(const gchar *string, const gchar *delimiter, const gchar *replacement); | |
346 | |
5826 | 347 /** |
348 * Returns a string representing a filesize in the appropriate units (MB, KB, GB, etc.) | |
349 * | |
350 * @param size The size | |
351 */ | |
352 char *gaim_get_size_string(size_t size); | |
353 | |
4890 | 354 #endif /* _GAIM_UTIL_H_ */ |