pidgin/gtkutils.c

changeset 41379
b271cf41c92d
parent 41319
04d027ed3d63
child 41477
34907838c401
equal deleted inserted replaced
41378:14cda54c3fbf 41379:b271cf41c92d
304 304
305 pidgin_retrieve_user_info(conn, who ? who : name); 305 pidgin_retrieve_user_info(conn, who ? who : name);
306 g_free(who); 306 g_free(who);
307 } 307 }
308 308
309 gboolean
310 pidgin_parse_x_im_contact(const char *msg, gboolean all_accounts,
311 PurpleAccount **ret_account, char **ret_protocol,
312 char **ret_username, char **ret_alias)
313 {
314 char *protocol = NULL;
315 char *username = NULL;
316 char *alias = NULL;
317 char *str;
318 char *s;
319 gboolean valid;
320
321 g_return_val_if_fail(msg != NULL, FALSE);
322 g_return_val_if_fail(ret_protocol != NULL, FALSE);
323 g_return_val_if_fail(ret_username != NULL, FALSE);
324
325 s = str = g_strdup(msg);
326
327 while (*s != '\r' && *s != '\n' && *s != '\0')
328 {
329 char *key, *value;
330
331 key = s;
332
333 /* Grab the key */
334 while (*s != '\r' && *s != '\n' && *s != '\0' && *s != ' ')
335 s++;
336
337 if (*s == '\r') s++;
338
339 if (*s == '\n')
340 {
341 s++;
342 continue;
343 }
344
345 if (*s != '\0') *s++ = '\0';
346
347 /* Clear past any whitespace */
348 while (*s == ' ')
349 s++;
350
351 /* Now let's grab until the end of the line. */
352 value = s;
353
354 while (*s != '\r' && *s != '\n' && *s != '\0')
355 s++;
356
357 if (*s == '\r') *s++ = '\0';
358 if (*s == '\n') *s++ = '\0';
359
360 if (strchr(key, ':') != NULL)
361 {
362 if (!g_ascii_strcasecmp(key, "X-IM-Username:"))
363 username = g_strdup(value);
364 else if (!g_ascii_strcasecmp(key, "X-IM-Protocol:"))
365 protocol = g_strdup(value);
366 else if (!g_ascii_strcasecmp(key, "X-IM-Alias:"))
367 alias = g_strdup(value);
368 }
369 }
370
371 if (username != NULL && protocol != NULL)
372 {
373 valid = TRUE;
374
375 *ret_username = username;
376 *ret_protocol = protocol;
377
378 if (ret_alias != NULL)
379 *ret_alias = alias;
380
381 /* Check for a compatible account. */
382 if(ret_account != NULL) {
383 PurpleAccount *account = NULL;
384 GList *list;
385 GList *l;
386 const char *protoname;
387
388
389 if(all_accounts) {
390 PurpleAccountManager *manager = NULL;
391
392 manager = purple_account_manager_get_default();
393 list = purple_account_manager_get_all(manager);
394 } else {
395 list = purple_connections_get_all();
396 }
397
398 for (l = list; l != NULL; l = l->next)
399 {
400 PurpleConnection *gc;
401 PurpleProtocol *proto = NULL;
402
403 if (all_accounts)
404 {
405 account = (PurpleAccount *)l->data;
406
407 proto = purple_account_get_protocol(account);
408
409 if (proto == NULL)
410 {
411 account = NULL;
412
413 continue;
414 }
415 }
416 else
417 {
418 gc = (PurpleConnection *)l->data;
419 account = purple_connection_get_account(gc);
420
421 proto = purple_connection_get_protocol(gc);
422 }
423
424 protoname = purple_protocol_get_list_icon(proto, account, NULL);
425
426 if (purple_strequal(protoname, protocol))
427 break;
428
429 account = NULL;
430 }
431
432 *ret_account = account;
433 }
434 }
435 else
436 {
437 valid = FALSE;
438
439 g_free(username);
440 g_free(protocol);
441 g_free(alias);
442 }
443
444 g_free(str);
445
446 return valid;
447 }
448
449 void 309 void
450 pidgin_set_accessible_label(GtkWidget *w, GtkLabel *l) 310 pidgin_set_accessible_label(GtkWidget *w, GtkLabel *l)
451 { 311 {
452 AtkObject *acc; 312 AtkObject *acc;
453 const gchar *label_text; 313 const gchar *label_text;

mercurial