Mercurial > pidgin
annotate src/protocols/silc/util.c @ 10714:ad57a8b5495e
[gaim-migrate @ 12308]
Some minor status changes.
* Using the "enable?" checkbox in the account window will now sign on
an account if it was offline. I'm starting to get a feel for how
some of this stuff should work...
* Signing on an account that doesn't support available messages no
longer shows some warnings.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 21 Mar 2005 05:22:09 +0000 |
parents | 0f7452b1f777 |
children | bf5e48215158 |
rev | line source |
---|---|
8849 | 1 /* |
2 | |
3 silcgaim_util.c | |
4 | |
5 Author: Pekka Riikonen <priikone@silcnet.org> | |
6 | |
7 Copyright (C) 2004 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 #include "silcincludes.h" | |
21 #include "silcclient.h" | |
22 #include "silcgaim.h" | |
23 | |
24 /**************************** Utility Routines *******************************/ | |
25 | |
26 static char str[256], str2[256]; | |
27 | |
28 const char *silcgaim_silcdir(void) | |
29 { | |
30 const char *hd = gaim_home_dir(); | |
31 memset(str, 0, sizeof(str)); | |
32 g_snprintf(str, sizeof(str) - 1, "%s" G_DIR_SEPARATOR_S ".silc", hd ? hd : "/tmp"); | |
33 return (const char *)str; | |
34 } | |
35 | |
36 const char *silcgaim_session_file(const char *account) | |
37 { | |
38 memset(str2, 0, sizeof(str2)); | |
39 g_snprintf(str2, sizeof(str2) - 1, "%s" G_DIR_SEPARATOR_S "%s_session", | |
40 silcgaim_silcdir(), account); | |
41 return (const char *)str2; | |
42 } | |
43 | |
44 gboolean silcgaim_ip_is_private(const char *ip) | |
45 { | |
46 if (silc_net_is_ip4(ip)) { | |
47 if (!strncmp(ip, "10.", 3)) { | |
48 return TRUE; | |
49 } else if (!strncmp(ip, "172.", 4) && strlen(ip) > 6) { | |
50 char tmp[3]; | |
8910 | 51 int s; |
8849 | 52 memset(tmp, 0, sizeof(tmp)); |
53 strncpy(tmp, ip + 4, 2); | |
8910 | 54 s = atoi(tmp); |
8849 | 55 if (s >= 16 && s <= 31) |
56 return TRUE; | |
57 } else if (!strncmp(ip, "192.168.", 8)) { | |
58 return TRUE; | |
59 } | |
60 } | |
61 | |
62 return FALSE; | |
63 } | |
64 | |
65 /* This checks stats for various SILC files and directories. First it | |
66 checks if ~/.silc directory exist and is owned by the correct user. If | |
67 it doesn't exist, it will create the directory. After that it checks if | |
68 user's Public and Private key files exists and creates them if needed. */ | |
69 | |
70 gboolean silcgaim_check_silc_dir(GaimConnection *gc) | |
71 { | |
72 char filename[256], file_public_key[256], file_private_key[256]; | |
73 char servfilename[256], clientfilename[256], friendsfilename[256]; | |
74 struct stat st; | |
75 struct passwd *pw; | |
76 | |
77 pw = getpwuid(getuid()); | |
78 if (!pw) { | |
9272 | 79 gaim_debug_error("silc", "silc: %s\n", strerror(errno)); |
8849 | 80 return FALSE; |
81 } | |
82 | |
9353 | 83 g_snprintf(filename, sizeof(filename) - 1, "%s", silcgaim_silcdir()); |
8849 | 84 g_snprintf(servfilename, sizeof(servfilename) - 1, "%s" G_DIR_SEPARATOR_S "serverkeys", |
85 silcgaim_silcdir()); | |
86 g_snprintf(clientfilename, sizeof(clientfilename) - 1, "%s" G_DIR_SEPARATOR_S "clientkeys", | |
87 silcgaim_silcdir()); | |
88 g_snprintf(friendsfilename, sizeof(friendsfilename) - 1, "%s" G_DIR_SEPARATOR_S "friends", | |
89 silcgaim_silcdir()); | |
90 | |
91 /* | |
92 * Check ~/.silc directory | |
93 */ | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
9488
diff
changeset
|
94 if ((g_stat(filename, &st)) == -1) { |
8849 | 95 /* If dir doesn't exist */ |
96 if (errno == ENOENT) { | |
97 if (pw->pw_uid == geteuid()) { | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
9488
diff
changeset
|
98 if ((g_mkdir(filename, 0755)) == -1) { |
9272 | 99 gaim_debug_error("silc", "Couldn't create '%s' directory\n", filename); |
8849 | 100 return FALSE; |
101 } | |
102 } else { | |
9272 | 103 gaim_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", |
8849 | 104 filename); |
105 return FALSE; | |
106 } | |
107 } else { | |
9272 | 108 gaim_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", filename, strerror(errno)); |
8849 | 109 return FALSE; |
110 } | |
111 } else { | |
9353 | 112 #ifndef _WIN32 |
8849 | 113 /* Check the owner of the dir */ |
114 if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { | |
9272 | 115 gaim_debug_error("silc", "You don't seem to own '%s' directory\n", |
8849 | 116 filename); |
117 return FALSE; | |
118 } | |
9353 | 119 #endif |
8849 | 120 } |
121 | |
122 /* | |
123 * Check ~./silc/serverkeys directory | |
124 */ | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
9488
diff
changeset
|
125 if ((g_stat(servfilename, &st)) == -1) { |
8849 | 126 /* If dir doesn't exist */ |
127 if (errno == ENOENT) { | |
128 if (pw->pw_uid == geteuid()) { | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
9488
diff
changeset
|
129 if ((g_mkdir(servfilename, 0755)) == -1) { |
9272 | 130 gaim_debug_error("silc", "Couldn't create '%s' directory\n", servfilename); |
8849 | 131 return FALSE; |
132 } | |
133 } else { | |
9272 | 134 gaim_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", |
8849 | 135 servfilename); |
136 return FALSE; | |
137 } | |
138 } else { | |
9272 | 139 gaim_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", |
140 servfilename, strerror(errno)); | |
8849 | 141 return FALSE; |
142 } | |
143 } | |
144 | |
145 /* | |
146 * Check ~./silc/clientkeys directory | |
147 */ | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
9488
diff
changeset
|
148 if ((g_stat(clientfilename, &st)) == -1) { |
8849 | 149 /* If dir doesn't exist */ |
150 if (errno == ENOENT) { | |
151 if (pw->pw_uid == geteuid()) { | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
9488
diff
changeset
|
152 if ((g_mkdir(clientfilename, 0755)) == -1) { |
9272 | 153 gaim_debug_error("silc", "Couldn't create '%s' directory\n", clientfilename); |
8849 | 154 return FALSE; |
155 } | |
156 } else { | |
9272 | 157 gaim_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", |
8849 | 158 clientfilename); |
159 return FALSE; | |
160 } | |
161 } else { | |
9272 | 162 gaim_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", |
163 clientfilename, strerror(errno)); | |
8849 | 164 return FALSE; |
165 } | |
166 } | |
167 | |
168 /* | |
169 * Check ~./silc/friends directory | |
170 */ | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
9488
diff
changeset
|
171 if ((g_stat(friendsfilename, &st)) == -1) { |
8849 | 172 /* If dir doesn't exist */ |
173 if (errno == ENOENT) { | |
174 if (pw->pw_uid == geteuid()) { | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
9488
diff
changeset
|
175 if ((g_mkdir(friendsfilename, 0755)) == -1) { |
9272 | 176 gaim_debug_error("silc", "Couldn't create '%s' directory\n", friendsfilename); |
8849 | 177 return FALSE; |
178 } | |
179 } else { | |
9272 | 180 gaim_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", |
8849 | 181 friendsfilename); |
182 return FALSE; | |
183 } | |
184 } else { | |
9272 | 185 gaim_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", |
186 friendsfilename, strerror(errno)); | |
8849 | 187 return FALSE; |
188 } | |
189 } | |
190 | |
191 /* | |
192 * Check Public and Private keys | |
193 */ | |
194 g_snprintf(file_public_key, sizeof(file_public_key) - 1, "%s", | |
195 gaim_prefs_get_string("/plugins/prpl/silc/pubkey")); | |
196 g_snprintf(file_private_key, sizeof(file_public_key) - 1, "%s", | |
197 gaim_prefs_get_string("/plugins/prpl/silc/privkey")); | |
198 | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
9488
diff
changeset
|
199 if ((g_stat(file_public_key, &st)) == -1) { |
8849 | 200 /* If file doesn't exist */ |
201 if (errno == ENOENT) { | |
202 gaim_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); | |
203 silc_create_key_pair(SILCGAIM_DEF_PKCS, | |
204 SILCGAIM_DEF_PKCS_LEN, | |
205 file_public_key, file_private_key, NULL, | |
9272 | 206 (gc->account->password == NULL) ? "" : gc->account->password, |
207 NULL, NULL, NULL, FALSE); | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
9488
diff
changeset
|
208 g_stat(file_public_key, &st); |
8849 | 209 } else { |
9272 | 210 gaim_debug_error("silc", "Couldn't stat '%s' public key, error: %s\n", |
211 file_public_key, strerror(errno)); | |
8849 | 212 return FALSE; |
213 } | |
214 } | |
215 | |
9353 | 216 #ifndef _WIN32 |
8849 | 217 /* Check the owner of the public key */ |
218 if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { | |
9272 | 219 gaim_debug_error("silc", "You don't seem to own your public key!?\n"); |
8849 | 220 return FALSE; |
221 } | |
9353 | 222 #endif |
8849 | 223 |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
9488
diff
changeset
|
224 if ((g_stat(file_private_key, &st)) == -1) { |
8849 | 225 /* If file doesn't exist */ |
226 if (errno == ENOENT) { | |
227 gaim_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); | |
228 silc_create_key_pair(SILCGAIM_DEF_PKCS, | |
229 SILCGAIM_DEF_PKCS_LEN, | |
230 file_public_key, file_private_key, NULL, | |
9272 | 231 (gc->account->password == NULL) ? "" : gc->account->password, |
232 NULL, NULL, NULL, FALSE); | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
9488
diff
changeset
|
233 g_stat(file_private_key, &st); |
8849 | 234 } else { |
9272 | 235 gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
236 file_private_key, strerror(errno)); | |
8849 | 237 return FALSE; |
238 } | |
239 } | |
240 | |
9353 | 241 #ifndef _WIN32 |
8849 | 242 /* Check the owner of the private key */ |
243 if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { | |
9272 | 244 gaim_debug_error("silc", "You don't seem to own your private key!?\n"); |
8849 | 245 return FALSE; |
246 } | |
247 | |
248 /* Check the permissions for the private key */ | |
249 if ((st.st_mode & 0777) != 0600) { | |
9272 | 250 gaim_debug_warning("silc", "Wrong permissions in your private key file `%s'!\n" |
8849 | 251 "Trying to change them ... ", file_private_key); |
252 if ((chmod(file_private_key, 0600)) == -1) { | |
9272 | 253 gaim_debug_error("silc", |
8849 | 254 "Failed to change permissions for private key file!\n" |
255 "Permissions for your private key file must be 0600.\n"); | |
256 return FALSE; | |
257 } | |
9272 | 258 gaim_debug_warning("silc", "Done.\n\n"); |
8849 | 259 } |
9353 | 260 #endif |
8849 | 261 |
262 return TRUE; | |
263 } | |
264 | |
9353 | 265 #ifdef _WIN32 |
266 struct passwd *getpwuid(uid_t uid) { | |
267 struct passwd *pwd = calloc(1, sizeof(struct passwd)); | |
268 return pwd; | |
269 } | |
270 | |
271 uid_t getuid() { | |
272 return 0; | |
273 } | |
274 | |
275 uid_t geteuid() { | |
276 return 0; | |
277 } | |
278 #endif | |
279 | |
8849 | 280 void silcgaim_show_public_key(SilcGaim sg, |
281 const char *name, SilcPublicKey public_key, | |
282 GCallback callback, void *context) | |
283 { | |
284 SilcPublicKeyIdentifier ident; | |
285 SilcPKCS pkcs; | |
286 char *fingerprint, *babbleprint; | |
287 unsigned char *pk; | |
288 SilcUInt32 pk_len, key_len = 0; | |
289 GString *s; | |
290 char *buf; | |
291 | |
292 ident = silc_pkcs_decode_identifier(public_key->identifier); | |
293 if (!ident) | |
294 return; | |
295 | |
296 pk = silc_pkcs_public_key_encode(public_key, &pk_len); | |
297 fingerprint = silc_hash_fingerprint(NULL, pk, pk_len); | |
298 babbleprint = silc_hash_babbleprint(NULL, pk, pk_len); | |
299 | |
300 if (silc_pkcs_alloc(public_key->name, &pkcs)) { | |
301 key_len = silc_pkcs_public_key_set(pkcs, public_key); | |
302 silc_pkcs_free(pkcs); | |
303 } | |
304 | |
305 s = g_string_new(""); | |
306 if (ident->realname) | |
9274 | 307 /* Hint for translators: Please check the tabulator width here and in |
308 the next strings (short strings: 2 tabs, longer strings 1 tab, | |
309 sum: 3 tabs or 24 characters) */ | |
310 g_string_append_printf(s, _("Real Name: \t%s\n"), ident->realname); | |
8849 | 311 if (ident->username) |
9274 | 312 g_string_append_printf(s, _("User Name: \t%s\n"), ident->username); |
8849 | 313 if (ident->email) |
9274 | 314 g_string_append_printf(s, _("EMail: \t\t%s\n"), ident->email); |
8849 | 315 if (ident->host) |
9274 | 316 g_string_append_printf(s, _("Host Name: \t%s\n"), ident->host); |
8849 | 317 if (ident->org) |
9274 | 318 g_string_append_printf(s, _("Organization: \t%s\n"), ident->org); |
8849 | 319 if (ident->country) |
9274 | 320 g_string_append_printf(s, _("Country: \t%s\n"), ident->country); |
9488 | 321 g_string_append_printf(s, _("Algorithm: \t%s\n"), public_key->name); |
9274 | 322 g_string_append_printf(s, _("Key Length: \t%d bits\n"), (int)key_len); |
323 g_string_append_printf(s, "\n"); | |
324 g_string_append_printf(s, _("Public Key Fingerprint:\n%s\n\n"), fingerprint); | |
325 g_string_append_printf(s, _("Public Key Babbleprint:\n%s"), babbleprint); | |
8849 | 326 |
327 buf = g_string_free(s, FALSE); | |
328 | |
329 gaim_request_action(NULL, _("Public Key Information"), | |
330 _("Public Key Information"), | |
331 buf, 0, context, 1, | |
332 _("Close"), callback); | |
333 | |
334 g_free(buf); | |
335 silc_free(fingerprint); | |
336 silc_free(babbleprint); | |
337 silc_free(pk); | |
338 silc_pkcs_free_identifier(ident); | |
339 } | |
340 | |
341 SilcAttributePayload | |
342 silcgaim_get_attr(SilcDList attrs, SilcAttribute attribute) | |
343 { | |
344 SilcAttributePayload attr = NULL; | |
345 | |
346 if (!attrs) | |
347 return NULL; | |
348 | |
349 silc_dlist_start(attrs); | |
350 while ((attr = silc_dlist_get(attrs)) != SILC_LIST_END) | |
351 if (attribute == silc_attribute_get_attribute(attr)) | |
352 break; | |
353 | |
354 return attr; | |
355 } | |
356 | |
357 void silcgaim_get_umode_string(SilcUInt32 mode, char *buf, | |
358 SilcUInt32 buf_size) | |
359 { | |
360 memset(buf, 0, buf_size); | |
361 if ((mode & SILC_UMODE_SERVER_OPERATOR) || | |
362 (mode & SILC_UMODE_ROUTER_OPERATOR)) { | |
363 strcat(buf, (mode & SILC_UMODE_SERVER_OPERATOR) ? | |
364 "[server operator] " : | |
365 (mode & SILC_UMODE_ROUTER_OPERATOR) ? | |
366 "[SILC operator] " : "[unknown mode] "); | |
367 } | |
368 if (mode & SILC_UMODE_GONE) | |
369 strcat(buf, "[away] "); | |
370 if (mode & SILC_UMODE_INDISPOSED) | |
371 strcat(buf, "[indisposed] "); | |
372 if (mode & SILC_UMODE_BUSY) | |
373 strcat(buf, "[busy] "); | |
374 if (mode & SILC_UMODE_PAGE) | |
375 strcat(buf, "[wake me up] "); | |
376 if (mode & SILC_UMODE_HYPER) | |
377 strcat(buf, "[hyperactive] "); | |
378 if (mode & SILC_UMODE_ROBOT) | |
379 strcat(buf, "[robot] "); | |
380 if (mode & SILC_UMODE_ANONYMOUS) | |
381 strcat(buf, "[anonymous] "); | |
382 if (mode & SILC_UMODE_BLOCK_PRIVMSG) | |
383 strcat(buf, "[blocks private messages] "); | |
384 if (mode & SILC_UMODE_DETACHED) | |
385 strcat(buf, "[detached] "); | |
386 if (mode & SILC_UMODE_REJECT_WATCHING) | |
387 strcat(buf, "[rejects watching] "); | |
388 if (mode & SILC_UMODE_BLOCK_INVITE) | |
389 strcat(buf, "[blocks invites] "); | |
390 } | |
391 | |
392 void silcgaim_get_chmode_string(SilcUInt32 mode, char *buf, | |
393 SilcUInt32 buf_size) | |
394 { | |
395 memset(buf, 0, buf_size); | |
396 if (mode & SILC_CHANNEL_MODE_FOUNDER_AUTH) | |
397 strcat(buf, "[permanent] "); | |
398 if (mode & SILC_CHANNEL_MODE_PRIVATE) | |
399 strcat(buf, "[private] "); | |
400 if (mode & SILC_CHANNEL_MODE_SECRET) | |
401 strcat(buf, "[secret] "); | |
402 if (mode & SILC_CHANNEL_MODE_SECRET) | |
403 strcat(buf, "[secret] "); | |
404 if (mode & SILC_CHANNEL_MODE_PRIVKEY) | |
405 strcat(buf, "[private key] "); | |
406 if (mode & SILC_CHANNEL_MODE_INVITE) | |
407 strcat(buf, "[invite only] "); | |
408 if (mode & SILC_CHANNEL_MODE_TOPIC) | |
409 strcat(buf, "[topic restricted] "); | |
410 if (mode & SILC_CHANNEL_MODE_ULIMIT) | |
411 strcat(buf, "[user count limit] "); | |
412 if (mode & SILC_CHANNEL_MODE_PASSPHRASE) | |
413 strcat(buf, "[passphrase auth] "); | |
414 if (mode & SILC_CHANNEL_MODE_CHANNEL_AUTH) | |
415 strcat(buf, "[public key auth] "); | |
416 if (mode & SILC_CHANNEL_MODE_SILENCE_USERS) | |
417 strcat(buf, "[users silenced] "); | |
418 if (mode & SILC_CHANNEL_MODE_SILENCE_OPERS) | |
419 strcat(buf, "[operators silenced] "); | |
420 } | |
421 | |
422 void silcgaim_get_chumode_string(SilcUInt32 mode, char *buf, | |
423 SilcUInt32 buf_size) | |
424 { | |
425 memset(buf, 0, buf_size); | |
426 if (mode & SILC_CHANNEL_UMODE_CHANFO) | |
427 strcat(buf, "[founder] "); | |
428 if (mode & SILC_CHANNEL_UMODE_CHANOP) | |
429 strcat(buf, "[operator] "); | |
430 if (mode & SILC_CHANNEL_UMODE_BLOCK_MESSAGES) | |
431 strcat(buf, "[blocks messages] "); | |
432 if (mode & SILC_CHANNEL_UMODE_BLOCK_MESSAGES_USERS) | |
433 strcat(buf, "[blocks user messages] "); | |
434 if (mode & SILC_CHANNEL_UMODE_BLOCK_MESSAGES_ROBOTS) | |
435 strcat(buf, "[blocks robot messages] "); | |
436 if (mode & SILC_CHANNEL_UMODE_QUIET) | |
437 strcat(buf, "[quieted] "); | |
438 } | |
9488 | 439 |
440 void | |
441 silcgaim_parse_attrs(SilcDList attrs, char **moodstr, char **statusstr, | |
442 char **contactstr, char **langstr, char **devicestr, | |
443 char **tzstr, char **geostr) | |
444 { | |
445 SilcAttributePayload attr; | |
446 SilcAttributeMood mood = 0; | |
447 SilcAttributeContact contact; | |
448 SilcAttributeObjDevice device; | |
449 SilcAttributeObjGeo geo; | |
450 | |
451 char tmp[1024]; | |
452 GString *s; | |
453 | |
454 *moodstr = NULL; | |
455 *statusstr = NULL; | |
456 *contactstr = NULL; | |
457 *langstr = NULL; | |
458 *devicestr = NULL; | |
459 *tzstr = NULL; | |
460 *geostr = NULL; | |
461 | |
462 if (!attrs) | |
463 return; | |
464 | |
465 s = g_string_new(""); | |
466 attr = silcgaim_get_attr(attrs, SILC_ATTRIBUTE_STATUS_MOOD); | |
467 if (attr && silc_attribute_get_object(attr, &mood, sizeof(mood))) { | |
468 if (mood & SILC_ATTRIBUTE_MOOD_HAPPY) | |
469 g_string_append_printf(s, "[%s] ", _("Happy")); | |
470 if (mood & SILC_ATTRIBUTE_MOOD_SAD) | |
471 g_string_append_printf(s, "[%s] ", _("Sad")); | |
472 if (mood & SILC_ATTRIBUTE_MOOD_ANGRY) | |
473 g_string_append_printf(s, "[%s] ", _("Angry")); | |
474 if (mood & SILC_ATTRIBUTE_MOOD_JEALOUS) | |
475 g_string_append_printf(s, "[%s] ", _("Jealous")); | |
476 if (mood & SILC_ATTRIBUTE_MOOD_ASHAMED) | |
477 g_string_append_printf(s, "[%s] ", _("Ashamed")); | |
478 if (mood & SILC_ATTRIBUTE_MOOD_INVINCIBLE) | |
479 g_string_append_printf(s, "[%s] ", _("Invincible")); | |
480 if (mood & SILC_ATTRIBUTE_MOOD_INLOVE) | |
481 g_string_append_printf(s, "[%s] ", _("In Love")); | |
482 if (mood & SILC_ATTRIBUTE_MOOD_SLEEPY) | |
483 g_string_append_printf(s, "[%s] ", _("Sleepy")); | |
484 if (mood & SILC_ATTRIBUTE_MOOD_BORED) | |
485 g_string_append_printf(s, "[%s] ", _("Bored")); | |
486 if (mood & SILC_ATTRIBUTE_MOOD_EXCITED) | |
487 g_string_append_printf(s, "[%s] ", _("Excited")); | |
488 if (mood & SILC_ATTRIBUTE_MOOD_ANXIOUS) | |
489 g_string_append_printf(s, "[%s] ", _("Anxious")); | |
490 } | |
491 if (strlen(s->str)) { | |
492 *moodstr = s->str; | |
493 g_string_free(s, FALSE); | |
494 } else | |
495 g_string_free(s, TRUE); | |
496 | |
497 attr = silcgaim_get_attr(attrs, SILC_ATTRIBUTE_STATUS_FREETEXT); | |
498 memset(tmp, 0, sizeof(tmp)); | |
499 if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp))) | |
500 *statusstr = g_strdup(tmp); | |
501 | |
502 s = g_string_new(""); | |
503 attr = silcgaim_get_attr(attrs, SILC_ATTRIBUTE_PREFERRED_CONTACT); | |
504 if (attr && silc_attribute_get_object(attr, &contact, sizeof(contact))) { | |
505 if (contact & SILC_ATTRIBUTE_CONTACT_CHAT) | |
506 g_string_append_printf(s, "[%s] ", _("Chat")); | |
507 if (contact & SILC_ATTRIBUTE_CONTACT_EMAIL) | |
508 g_string_append_printf(s, "[%s] ", _("Email")); | |
509 if (contact & SILC_ATTRIBUTE_CONTACT_CALL) | |
510 g_string_append_printf(s, "[%s] ", _("Phone")); | |
511 if (contact & SILC_ATTRIBUTE_CONTACT_PAGE) | |
512 g_string_append_printf(s, "[%s] ", _("Paging")); | |
513 if (contact & SILC_ATTRIBUTE_CONTACT_SMS) | |
514 g_string_append_printf(s, "[%s] ", _("SMS")); | |
515 if (contact & SILC_ATTRIBUTE_CONTACT_MMS) | |
516 g_string_append_printf(s, "[%s] ", _("MMS")); | |
517 if (contact & SILC_ATTRIBUTE_CONTACT_VIDEO) | |
518 g_string_append_printf(s, "[%s] ", _("Video Conferencing")); | |
519 } | |
520 if (strlen(s->str)) { | |
521 *contactstr = s->str; | |
522 g_string_free(s, FALSE); | |
523 } else | |
524 g_string_free(s, TRUE); | |
525 | |
526 attr = silcgaim_get_attr(attrs, SILC_ATTRIBUTE_PREFERRED_LANGUAGE); | |
527 memset(tmp, 0, sizeof(tmp)); | |
528 if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp))) | |
529 *langstr = g_strdup(tmp); | |
530 | |
531 s = g_string_new(""); | |
532 attr = silcgaim_get_attr(attrs, SILC_ATTRIBUTE_DEVICE_INFO); | |
533 memset(&device, 0, sizeof(device)); | |
534 if (attr && silc_attribute_get_object(attr, &device, sizeof(device))) { | |
535 if (device.type == SILC_ATTRIBUTE_DEVICE_COMPUTER) | |
536 g_string_append_printf(s, "%s: ", _("Computer")); | |
537 if (device.type == SILC_ATTRIBUTE_DEVICE_MOBILE_PHONE) | |
538 g_string_append_printf(s, "%s: ", _("Mobile Phone")); | |
539 if (device.type == SILC_ATTRIBUTE_DEVICE_PDA) | |
540 g_string_append_printf(s, "%s: ", _("PDA")); | |
541 if (device.type == SILC_ATTRIBUTE_DEVICE_TERMINAL) | |
542 g_string_append_printf(s, "%s: ", _("Terminal")); | |
543 g_string_append_printf(s, "%s %s %s %s", | |
544 device.manufacturer ? device.manufacturer : "", | |
545 device.version ? device.version : "", | |
546 device.model ? device.model : "", | |
547 device.language ? device.language : ""); | |
548 } | |
549 if (strlen(s->str)) { | |
550 *devicestr = s->str; | |
551 g_string_free(s, FALSE); | |
552 } else | |
553 g_string_free(s, TRUE); | |
554 | |
555 attr = silcgaim_get_attr(attrs, SILC_ATTRIBUTE_TIMEZONE); | |
556 memset(tmp, 0, sizeof(tmp)); | |
557 if (attr && silc_attribute_get_object(attr, tmp, sizeof(tmp))) | |
558 *tzstr = g_strdup(tmp); | |
559 | |
560 attr = silcgaim_get_attr(attrs, SILC_ATTRIBUTE_GEOLOCATION); | |
561 memset(&geo, 0, sizeof(geo)); | |
562 if (attr && silc_attribute_get_object(attr, &geo, sizeof(geo))) | |
563 *geostr = g_strdup_printf("%s %s %s (%s)", | |
564 geo.longitude ? geo.longitude : "", | |
565 geo.latitude ? geo.latitude : "", | |
566 geo.altitude ? geo.altitude : "", | |
567 geo.accuracy ? geo.accuracy : ""); | |
568 } |