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