comparison mcabber/src/settings.c @ 1197:6f602d3270a4

Add /pgp [-]force With this command it becomes possible to enforce PGP encryption without checking if the remote client has PGP support. It can be used to send encrypted offline messages too.
author Mikael Berthe <mikael@lilotux.net>
date Fri, 27 Apr 2007 00:37:57 +0200
parents 7b8765c10abb
children c96fef31ff96
comparison
equal deleted inserted replaced
1196:d657a13fd71a 1197:6f602d3270a4
36 static GHashTable *pgpopt; 36 static GHashTable *pgpopt;
37 37
38 typedef struct { 38 typedef struct {
39 gchar *pgp_keyid; /* KeyId the contact is supposed to use */ 39 gchar *pgp_keyid; /* KeyId the contact is supposed to use */
40 guint pgp_disabled; /* If TRUE, PGP is disabled for outgoing messages */ 40 guint pgp_disabled; /* If TRUE, PGP is disabled for outgoing messages */
41 guint pgp_force; /* If TRUE, PGP is used w/o negotiation */
41 } T_pgpopt; 42 } T_pgpopt;
42 #endif 43 #endif
43 44
44 static inline GHashTable *get_hash(guint type) 45 static inline GHashTable *get_hash(guint type)
45 { 46 {
401 T_pgpopt *pgpdata; 402 T_pgpopt *pgpdata;
402 pgpdata = g_hash_table_lookup(pgpopt, bjid); 403 pgpdata = g_hash_table_lookup(pgpopt, bjid);
403 if (pgpdata) 404 if (pgpdata)
404 return pgpdata->pgp_disabled; 405 return pgpdata->pgp_disabled;
405 else 406 else
406 return FALSE; // default: not disabled 407 return FALSE; // Default: not disabled
407 #else 408 #else
408 return TRUE; // No PGP support, let's say it's disabled. 409 return TRUE; // No PGP support, let's say it's disabled.
410 #endif
411 }
412
413 // settings_pgp_setforce(jid, value)
414 // Force (or not) PGP encryption for jid.
415 // When value is TRUE, PGP support will be assumed for the remote client.
416 void settings_pgp_setforce(const char *bjid, guint value)
417 {
418 #ifdef HAVE_GPGME
419 T_pgpopt *pgpdata;
420 pgpdata = g_hash_table_lookup(pgpopt, bjid);
421 if (!pgpdata) {
422 // If value is 0, we do not need to create a structure (that's
423 // the default value).
424 if (value) {
425 pgpdata = g_new0(T_pgpopt, 1);
426 pgpdata->pgp_force = value;
427 g_hash_table_insert(pgpopt, g_strdup(bjid), pgpdata);
428 }
429 } else {
430 pgpdata->pgp_force = value;
431 }
432 if (!pgpdata->pgp_keyid)
433 scr_LogPrint(LPRINT_NORMAL, "Warning: the Key Id is not set!");
434 #endif
435 }
436
437 // settings_pgp_getforce(jid)
438 // Return TRUE if PGP enforcement is set for jid.
439 guint settings_pgp_getforce(const char *bjid)
440 {
441 #ifdef HAVE_GPGME
442 T_pgpopt *pgpdata;
443 pgpdata = g_hash_table_lookup(pgpopt, bjid);
444 if (pgpdata)
445 return pgpdata->pgp_force;
446 else
447 return FALSE; // Default
448 #else
449 return FALSE; // No PGP support
409 #endif 450 #endif
410 } 451 }
411 452
412 // settings_pgp_setkeyid(jid, keyid) 453 // settings_pgp_setkeyid(jid, keyid)
413 // Set the PGP KeyId for user jid. 454 // Set the PGP KeyId for user jid.