Mercurial > pidgin.yaz
annotate src/util.h @ 5943:a4f2aba0848d
[gaim-migrate @ 6384]
This should fix corruption in the blist, accounts, and pounces when some
protocol plugins cannot load. Some parts of gaim now use the new unique
Plugin or Protocol Plugin IDs, while some still use the old protocol
numbers. Accounts kind of used both, and when prpls were missing, it had
trouble finding accounts. It would find the names, even without mapping the
protocol numbers to IDs, and any duplicate accounts would get nuked. That
would then affect pounce saving. Anyhow, long story short (well, it's
already long, too late for that), this should fix all that mess. And
introduce new mess, but hopefully temporary mess.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Mon, 23 Jun 2003 02:00:15 +0000 |
parents | 964e4f94fc56 |
children | 158196b2db19 |
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 * Returns the date and time in human-readable form. | |
130 * | |
131 * The returned string is stored in a static buffer, so the result | |
132 * should be g_strdup()'d if it's intended to be used for long. | |
133 * | |
134 * @return The date and time in human-readable form. | |
135 * | |
136 * @see date() | |
137 */ | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5532
diff
changeset
|
138 char *full_date(void); |
4890 | 139 |
140 /** | |
141 * Looks for %n, %d, or %t in a string, and replaces them with the | |
142 * specified name, date, and time, respectively. | |
143 * | |
144 * The returned string is stored in a static buffer, so the result | |
145 * should be g_strdup()'d if it's intended to be used for long. | |
146 * | |
147 * @param str The string that may contain the special variables. | |
148 * @param name The sender name. | |
149 * | |
150 * @return A new string where the special variables are expanded. | |
151 */ | |
152 char *away_subs(const char *str, const char *name); | |
153 | |
154 /**` | |
155 * Returns the user's home directory. | |
156 * | |
157 * @return The user's home directory. | |
158 * | |
159 * @see gaim_user_dir() | |
160 */ | |
161 const gchar *gaim_home_dir(void); | |
162 | |
163 /** | |
164 * Returns the gaim settings directory in the user's home directory. | |
165 * | |
166 * @return The gaim settings directory. | |
167 * | |
168 * @see gaim_home_dir() | |
169 */ | |
170 char *gaim_user_dir(void); | |
171 | |
172 /** | |
173 * Copies a string and replaces all HTML linebreaks with newline characters. | |
174 * | |
175 * @param dest The destination string. | |
176 * @param src The source string. | |
177 * @param dest_len The destination string length. | |
178 * | |
179 * @see strncpy_withhtml() | |
180 * @see strdup_withhtml() | |
181 */ | |
182 void strncpy_nohtml(gchar *dest, const gchar *src, size_t dest_len); | |
183 | |
184 /** | |
185 * Copies a string and replaces all newline characters with HTML linebreaks. | |
186 * | |
187 * @param dest The destination string. | |
188 * @param src The source string. | |
189 * @param dest_len The destination string length. | |
190 * | |
191 * @see strncpy_nohtml() | |
192 * @see strdup_withhtml() | |
193 */ | |
194 void strncpy_withhtml(gchar *dest, const gchar *src, size_t dest_len); | |
195 | |
196 /** | |
197 * Duplicates a string and replaces all newline characters from the | |
198 * source string with HTML linebreaks. | |
199 * | |
200 * @param src The source string. | |
201 * | |
202 * @return The new string. | |
203 * | |
204 * @see strncpy_nohtml() | |
205 * @see strncpy_withhtml() | |
206 */ | |
207 gchar *strdup_withhtml(const gchar *src); | |
208 | |
209 /** | |
210 * Ensures that all linefeeds have a matching carriage return. | |
211 * | |
212 * @param str The source string. | |
213 * | |
214 * @return The string with carriage returns. | |
215 */ | |
5136 | 216 char *add_cr(const char *); |
4890 | 217 |
218 /** | |
219 * Strips all linefeeds from a string. | |
220 * | |
221 * @param str The string to strip linefeeds from. | |
222 */ | |
223 void strip_linefeed(char *str); | |
224 | |
225 /** | |
226 * Builds a time_t from the supplied information. | |
227 * | |
228 * @param year The year. | |
229 * @param month The month. | |
230 * @param day The day. | |
231 * @param hour The hour. | |
232 * @param min The minute. | |
233 * @param sec The second. | |
234 * | |
235 * @return A time_t. | |
236 */ | |
237 time_t get_time(int year, int month, int day, | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5532
diff
changeset
|
238 int hour, int min, int sec); |
4890 | 239 |
240 /** | |
241 * Creates a temporary file and returns a file pointer to it. | |
242 * | |
243 * This is like mkstemp(), but returns a file pointer and uses a | |
244 * pre-set template. It uses the semantics of tempnam() for the | |
245 * directory to use and allocates the space for the file path. | |
246 * | |
247 * The caller is responsible for closing the file and removing it when | |
248 * done, as well as freeing the space pointed to by @a path with | |
249 * g_free(). | |
250 * | |
251 * @param path The returned path to the temp file. | |
252 * | |
253 * @return A file pointer to the temporary file, or @c NULL on failure. | |
254 */ | |
255 FILE *gaim_mkstemp(gchar **path); | |
256 | |
257 /** | |
258 * Attempts to convert a string to UTF-8 from an unknown encoding. | |
259 * | |
260 * This function checks the locale and tries sane defaults. | |
261 * | |
262 * @param str The source string. | |
263 * | |
264 * @return The UTF-8 string, or @c NULL if it could not be converted. | |
265 */ | |
266 char *gaim_try_conv_to_utf8(const char *str); | |
267 | |
268 /** | |
269 * Returns the IP address from a socket file descriptor. | |
270 * | |
271 * @param fd The socket file descriptor. | |
272 * | |
273 * @return The IP address, or @c NULL on error. | |
274 */ | |
275 char *gaim_getip_from_fd(int fd); | |
276 | |
277 /** | |
278 * Compares two UTF-8 strings. | |
279 * | |
280 * @param a The first string. | |
281 * @param b The second string. | |
282 * | |
283 * @return -1 if @a is less than @a b. | |
284 * 0 if @a is equal to @a b. | |
285 * 1 if @a is greater than @a b. | |
286 */ | |
287 gint gaim_utf8_strcasecmp(const gchar *a, const gchar *b); | |
288 | |
5515 | 289 /** |
290 * Given a string, this replaces one substring with another | |
291 * and returns a newly allocated string. | |
292 * | |
293 * @param string The string from which to replace stuff. | |
294 * @param delimiter The substring you want replaced. | |
295 * @param replacement The substring you want inserted in place | |
296 * of the delimiting substring. | |
297 */ | |
5874
964e4f94fc56
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
298 gchar *gaim_strreplace(const gchar *string, const gchar *delimiter, |
964e4f94fc56
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
299 const gchar *replacement); |
5515 | 300 |
5826 | 301 /** |
302 * Returns a string representing a filesize in the appropriate units (MB, KB, GB, etc.) | |
303 * | |
304 * @param size The size | |
305 */ | |
306 char *gaim_get_size_string(size_t size); | |
307 | |
4890 | 308 #endif /* _GAIM_UTIL_H_ */ |