Mercurial > hg
comparison mcabber/src/settings.c @ 1065:230dca34dbea
Extand pgp_data structure
Extand pgp_data structure so that we can disbale PGP per contact and compare
the signature key with a reference key id.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sat, 02 Dec 2006 11:13:40 +0100 |
parents | b57a01ffeed6 |
children | 6646d2ed7f74 |
comparison
equal
deleted
inserted
replaced
1064:516b5f7d1023 | 1065:230dca34dbea |
---|---|
30 | 30 |
31 static GSList *option; | 31 static GSList *option; |
32 static GSList *alias; | 32 static GSList *alias; |
33 static GSList *binding; | 33 static GSList *binding; |
34 | 34 |
35 | |
36 typedef struct { | 35 typedef struct { |
37 gchar *name; | 36 gchar *name; |
38 gchar *value; | 37 gchar *value; |
39 } T_setting; | 38 } T_setting; |
40 | 39 |
40 #ifdef HAVE_GPGME /* PGP settings */ | |
41 static GHashTable *pgpopt; | |
42 | |
43 typedef struct { | |
44 gchar *pgp_keyid; /* KeyId the contact is supposed to use */ | |
45 guint pgp_disabled; /* If TRUE, PGP is disabled for outgoing messages */ | |
46 } T_pgpopt; | |
47 #endif | |
48 | |
41 static inline GSList **get_list_ptr(guint type) | 49 static inline GSList **get_list_ptr(guint type) |
42 { | 50 { |
43 if (type == SETTINGS_TYPE_OPTION) return &option; | 51 if (type == SETTINGS_TYPE_OPTION) return &option; |
44 else if (type == SETTINGS_TYPE_ALIAS) return &alias; | 52 else if (type == SETTINGS_TYPE_ALIAS) return &alias; |
45 else if (type == SETTINGS_TYPE_BINDING) return &binding; | 53 else if (type == SETTINGS_TYPE_BINDING) return &binding; |
59 | 67 |
60 return ptr; | 68 return ptr; |
61 } | 69 } |
62 | 70 |
63 /* -- */ | 71 /* -- */ |
72 | |
73 void settings_init(void) | |
74 { | |
75 #ifdef HAVE_GPGME | |
76 pgpopt = g_hash_table_new(&g_str_hash, &g_str_equal); | |
77 #endif | |
78 } | |
64 | 79 |
65 // cfg_read_file(filename) | 80 // cfg_read_file(filename) |
66 // Read and parse config file "filename". If filename is NULL, | 81 // Read and parse config file "filename". If filename is NULL, |
67 // try to open the configuration file at the default locations. | 82 // try to open the configuration file at the default locations. |
68 // | 83 // |
365 *p = 0; | 380 *p = 0; |
366 } | 381 } |
367 return nick; | 382 return nick; |
368 } | 383 } |
369 | 384 |
385 | |
386 /* PGP settings */ | |
387 | |
388 // settings_pgp_setdisabled(jid, value) | |
389 // Enable/disable PGP encryption for jid. | |
390 // (Set value to TRUE to disable encryption) | |
391 void settings_pgp_setdisabled(const char *bjid, guint value) | |
392 { | |
393 #ifdef HAVE_GPGME | |
394 T_pgpopt *pgpdata; | |
395 pgpdata = g_hash_table_lookup(pgpopt, bjid); | |
396 if (!pgpdata) { | |
397 // If value is 0, we do not need to create a structure (that's | |
398 // the default value). | |
399 if (value) { | |
400 pgpdata = g_new0(T_pgpopt, 1); | |
401 pgpdata->pgp_disabled = value; | |
402 g_hash_table_insert(pgpopt, g_strdup(bjid), pgpdata); | |
403 } | |
404 } else { | |
405 pgpdata->pgp_disabled = value; | |
406 // We could remove the key/value if pgp_disabled is 0 and | |
407 // pgp_keyid is NULL, actually. | |
408 } | |
409 #endif | |
410 } | |
411 | |
412 // settings_pgp_getdisabled(jid) | |
413 // Return TRUE if PGP encryption should be disabled for jid. | |
414 guint settings_pgp_getdisabled(const char *bjid) | |
415 { | |
416 #ifdef HAVE_GPGME | |
417 T_pgpopt *pgpdata; | |
418 pgpdata = g_hash_table_lookup(pgpopt, bjid); | |
419 if (pgpdata) | |
420 return pgpdata->pgp_disabled; | |
421 else | |
422 return FALSE; // default: not disabled | |
423 #else | |
424 return TRUE; // No PGP support, let's say it's disabled. | |
425 #endif | |
426 } | |
427 | |
428 // settings_pgp_setkeyid(jid, keyid) | |
429 // Set the PGP KeyId for user jid. | |
430 // Use keyid = NULL to erase the previous KeyId. | |
431 void settings_pgp_setkeyid(const char *bjid, const char *keyid) | |
432 { | |
433 #ifdef HAVE_GPGME | |
434 T_pgpopt *pgpdata; | |
435 pgpdata = g_hash_table_lookup(pgpopt, bjid); | |
436 if (!pgpdata) { | |
437 // If keyid is NULL, we do not need to create a structure (that's | |
438 // the default value). | |
439 if (keyid) { | |
440 pgpdata = g_new0(T_pgpopt, 1); | |
441 pgpdata->pgp_keyid = g_strdup(keyid); | |
442 g_hash_table_insert(pgpopt, g_strdup(bjid), pgpdata); | |
443 } | |
444 } else { | |
445 g_free(pgpdata->pgp_keyid); | |
446 if (keyid) | |
447 pgpdata->pgp_keyid = g_strdup(keyid); | |
448 else | |
449 pgpdata->pgp_keyid = NULL; | |
450 // We could remove the key/value if pgp_disabled is 0 and | |
451 // pgp_keyid is NULL, actually. | |
452 } | |
453 #endif | |
454 } | |
455 | |
456 // settings_pgp_getkeyid(jid) | |
457 // Get the PGP KeyId for user jid. | |
458 const char *settings_pgp_getkeyid(const char *bjid) | |
459 { | |
460 #ifdef HAVE_GPGME | |
461 T_pgpopt *pgpdata; | |
462 pgpdata = g_hash_table_lookup(pgpopt, bjid); | |
463 if (pgpdata) | |
464 return pgpdata->pgp_keyid; | |
465 #endif | |
466 return NULL; | |
467 } | |
468 | |
370 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ | 469 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |