Mercurial > ~mikael > mcabber > hg
comparison mcabber/mcabber/caps.c @ 2001:76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
author | Hermitifier |
---|---|
date | Tue, 11 Oct 2011 12:28:08 +0200 |
parents | 51f032d5ca22 |
children | 01485f807811 |
comparison
equal
deleted
inserted
replaced
2000:1fe1e8d1d1ea | 2001:76d7c5721210 |
---|---|
72 } | 72 } |
73 | 73 |
74 void field_destroy(gpointer data) | 74 void field_destroy(gpointer data) |
75 { | 75 { |
76 GList *v = data; | 76 GList *v = data; |
77 g_list_free_full(v, g_free); | 77 g_list_foreach (v, (GFunc) g_free, NULL); |
78 g_list_free (v); | |
78 } | 79 } |
79 | 80 |
80 void caps_init(void) | 81 void caps_init(void) |
81 { | 82 { |
82 if (!caps_cache) | 83 if (!caps_cache) |
108 if (!hash) | 109 if (!hash) |
109 return; | 110 return; |
110 g_hash_table_remove(caps_cache, hash); | 111 g_hash_table_remove(caps_cache, hash); |
111 } | 112 } |
112 | 113 |
114 /* if hash is not verified, this will bind capabilities set only with bare jid */ | |
113 void caps_move_to_local(char *hash, char *bjid) | 115 void caps_move_to_local(char *hash, char *bjid) |
114 { | 116 { |
115 char *orig_hash; | 117 char *orig_hash; |
116 caps *c = NULL; | 118 caps *c = NULL; |
117 if (!hash || !bjid) | 119 if (!hash || !bjid) |
125 // hash will not appear in base64 encoded hash | 127 // hash will not appear in base64 encoded hash |
126 // sequence "/#" is deterministic separator, and allows to identify local cache entry | 128 // sequence "/#" is deterministic separator, and allows to identify local cache entry |
127 } | 129 } |
128 } | 130 } |
129 | 131 |
132 /*if bjid is NULL, it will check only verified hashes */ | |
130 int caps_has_hash(const char *hash, const char *bjid) | 133 int caps_has_hash(const char *hash, const char *bjid) |
131 { | 134 { |
132 caps *c = NULL; | 135 caps *c = NULL; |
133 if (!hash) | 136 if (!hash) |
134 return 0; | 137 return 0; |
228 char *f = g_strdup(feature); | 231 char *f = g_strdup(feature); |
229 g_hash_table_replace(c->features, f, f); | 232 g_hash_table_replace(c->features, f, f); |
230 } | 233 } |
231 } | 234 } |
232 | 235 |
236 /* If hash is verified, then bare jid is ignored. | |
237 * If there is no globally verified hash, and bare jid is not null, | |
238 * then local storage for that jid will be checked */ | |
233 int caps_has_feature(const char *hash, char *feature, char *bjid) | 239 int caps_has_feature(const char *hash, char *feature, char *bjid) |
234 { | 240 { |
235 caps *c = NULL; | 241 caps *c = NULL; |
236 if (!hash || !feature) | 242 if (!hash || !feature) |
237 return 0; | 243 return 0; |
406 return match; | 412 return match; |
407 } | 413 } |
408 | 414 |
409 static gchar* caps_get_filename(const char* hash) | 415 static gchar* caps_get_filename(const char* hash) |
410 { | 416 { |
411 gchar *hash_fs = g_strdup (hash); | 417 gchar *hash_fs; |
412 gchar *dir = (gchar *) settings_opt_get ("caps_directory"); | 418 gchar *dir = (gchar *) settings_opt_get ("caps_directory"); |
413 gchar *file = NULL; | 419 gchar *file = NULL; |
414 | 420 |
415 if (!dir) | 421 if (!dir) |
416 goto caps_filename_return; | 422 goto caps_filename_return; |
417 | 423 |
424 hash_fs = g_strdup (hash); | |
418 { | 425 { |
419 const gchar *valid_fs = | 426 const gchar *valid_fs = |
420 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+="; | 427 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+="; |
421 g_strcanon(hash_fs, valid_fs, '-'); | 428 g_strcanon(hash_fs, valid_fs, '-'); |
422 } | 429 } |
423 | 430 |
424 dir = expand_filename (dir); | 431 dir = expand_filename (dir); |
425 file = g_strdup_printf ("%s/%s.ini", dir, hash_fs); | 432 file = g_strdup_printf ("%s/%s.ini", dir, hash_fs); |
426 g_free(dir); | 433 g_free(dir); |
434 g_free(hash_fs); | |
427 | 435 |
428 caps_filename_return: | 436 caps_filename_return: |
429 g_free(hash_fs); | |
430 return file; | 437 return file; |
431 } | 438 } |
432 | 439 |
440 /* Store capabilities set in GKeyFile. To be used with verified hashes only */ | |
433 void caps_copy_to_persistent(const char* hash, char* xml) | 441 void caps_copy_to_persistent(const char* hash, char* xml) |
434 { | 442 { |
435 gchar *file; | 443 gchar *file; |
436 GList *features, *langs, *forms; | 444 GList *features, *langs, *forms; |
437 GKeyFile *key_file; | 445 GKeyFile *key_file; |
451 fd = open (file, O_WRONLY|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR); | 459 fd = open (file, O_WRONLY|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR); |
452 if (fd == -1) | 460 if (fd == -1) |
453 goto caps_copy_exists; | 461 goto caps_copy_exists; |
454 | 462 |
455 key_file = g_key_file_new (); | 463 key_file = g_key_file_new (); |
464 g_key_file_set_comment (key_file, NULL, NULL, | |
465 "This is autogenerated file. Please do not modify.", | |
466 NULL); | |
456 | 467 |
457 langs = g_hash_table_get_keys (c->identities); | 468 langs = g_hash_table_get_keys (c->identities); |
458 { | 469 { |
459 identity *i; | 470 identity *i; |
460 GList *lang; | 471 GList *lang; |
503 { | 514 { |
504 GList *field; | 515 GList *field; |
505 GList *values; | 516 GList *values; |
506 for (field=fields; field; field=field->next) { | 517 for (field=fields; field; field=field->next) { |
507 values = g_hash_table_lookup (d->fields, field->data); | 518 values = g_hash_table_lookup (d->fields, field->data); |
508 { | 519 { |
509 GList *value; | 520 GList *value; |
510 gchar **string_list; | 521 gchar **string_list; |
511 gint i; | 522 gint i; |
512 i = g_list_length (values); | 523 i = g_list_length (values); |
513 string_list = g_new (gchar*, i + 1); | 524 string_list = g_new (gchar*, i + 1); |
514 i = 0; | 525 i = 0; |
515 for (value=values; value; value=value->next) { | 526 for (value=values; value; value=value->next) { |
516 string_list[i] = g_strdup(value->data); | 527 string_list[i] = g_strdup(value->data); |
517 ++i; | 528 ++i; |
518 } | 529 } |
519 string_list[i] = NULL; | 530 string_list[i] = NULL; |
520 | 531 |
521 g_key_file_set_string_list (key_file, group, field->data, | 532 g_key_file_set_string_list (key_file, group, field->data, |
522 (const gchar**)string_list, i); | 533 (const gchar**)string_list, i); |
523 | 534 |
524 g_strfreev (string_list); | 535 g_strfreev (string_list); |
525 } | 536 } |
526 } | 537 } |
527 } | 538 } |
528 g_list_free(fields); | 539 g_list_free(fields); |
529 g_free (group); | 540 g_free (group); |
530 } | 541 } |
545 g_free(file); | 556 g_free(file); |
546 caps_copy_return: | 557 caps_copy_return: |
547 return; | 558 return; |
548 } | 559 } |
549 | 560 |
561 /* Restore capabilities from GKeyFile. Hash is not verified afterwards */ | |
550 gboolean caps_restore_from_persistent (const char* hash) | 562 gboolean caps_restore_from_persistent (const char* hash) |
551 { | 563 { |
552 gchar *file; | 564 gchar *file; |
553 GKeyFile *key_file; | 565 GKeyFile *key_file; |
554 gchar **groups, **group; | 566 gchar **groups, **group; |
595 | 607 |
596 fields = g_key_file_get_keys(key_file, *group, NULL, NULL); | 608 fields = g_key_file_get_keys(key_file, *group, NULL, NULL); |
597 for (field = fields; *field; ++field) { | 609 for (field = fields; *field; ++field) { |
598 gchar **values, **value; | 610 gchar **values, **value; |
599 values = g_key_file_get_string_list (key_file, *group, *field, | 611 values = g_key_file_get_string_list (key_file, *group, *field, |
600 NULL, NULL); | 612 NULL, NULL); |
601 for (value = values; *value; ++value) { | 613 for (value = values; *value; ++value) { |
602 caps_add_dataform_field (hash, formtype, *field, *value); | 614 caps_add_dataform_field (hash, formtype, *field, *value); |
603 } | 615 } |
604 g_strfreev (values); | 616 g_strfreev (values); |
605 } | 617 } |
606 g_strfreev (fields); | 618 g_strfreev (fields); |
607 } | 619 } |
608 } | 620 } |
609 g_strfreev(groups); | 621 g_strfreev(groups); |