comparison mcabber/src/otr.c @ 1347:07816313073b

Add an option 'otr' to enable OTR support in the configuration file
author Mikael Berthe <mikael@lilotux.net>
date Fri, 09 Nov 2007 23:14:03 +0100
parents e36b21e11760
children 08f641e91f94
comparison
equal deleted inserted replaced
1346:e36b21e11760 1347:07816313073b
36 static OtrlUserState userstate = NULL; 36 static OtrlUserState userstate = NULL;
37 static char * account = NULL; 37 static char * account = NULL;
38 static char * keyfile = NULL; 38 static char * keyfile = NULL;
39 static char * fprfile = NULL; 39 static char * fprfile = NULL;
40 40
41 static int otr_is_enabled = FALSE;
41 42
42 static OtrlPolicy cb_policy (void *opdata, ConnContext *ctx); 43 static OtrlPolicy cb_policy (void *opdata, ConnContext *ctx);
43 static void cb_create_privkey (void *opdata, 44 static void cb_create_privkey (void *opdata,
44 const char *accountname, 45 const char *accountname,
45 const char *protocol); 46 const char *protocol);
111 112
112 static char * otr_get_dir(void); 113 static char * otr_get_dir(void);
113 114
114 void otr_init(const char *jid) 115 void otr_init(const char *jid)
115 { 116 {
116 char * root = otr_get_dir(); 117 char *root;
118
119 otr_is_enabled = !!settings_opt_get_int("otr");
120
121 if (!otr_is_enabled)
122 return;
123
124 OTRL_INIT;
125
126 userstate = otrl_userstate_create ();
127
128 root = otr_get_dir();
117 account = jidtodisp(jid); 129 account = jidtodisp(jid);
118 keyfile = g_strdup_printf("%s%s.key", root, account); 130 keyfile = g_strdup_printf("%s%s.key", root, account);
119 fprfile = g_strdup_printf("%s%s.fpr", root, account); 131 fprfile = g_strdup_printf("%s%s.fpr", root, account);
120 g_free(root); 132 g_free(root);
121 133
122 OTRL_INIT;
123
124 userstate = otrl_userstate_create ();
125 if (otrl_privkey_read(userstate, keyfile)){ 134 if (otrl_privkey_read(userstate, keyfile)){
126 scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR key from %s", keyfile); 135 scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR key from %s", keyfile);
127 cb_create_privkey(NULL, account, "jabber"); 136 cb_create_privkey(NULL, account, "jabber");
128 } 137 }
129 if (otrl_privkey_read_fingerprints(userstate, fprfile, NULL, NULL)){ 138 if (otrl_privkey_read_fingerprints(userstate, fprfile, NULL, NULL)){
133 } 142 }
134 143
135 void otr_terminate(void) 144 void otr_terminate(void)
136 { 145 {
137 ConnContext * ctx; 146 ConnContext * ctx;
147
148 if (!otr_is_enabled)
149 return;
138 150
139 for (ctx = userstate->context_root; ctx; ctx = ctx->next) 151 for (ctx = userstate->context_root; ctx; ctx = ctx->next)
140 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) 152 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
141 otr_message_disconnect(ctx); 153 otr_message_disconnect(ctx);
142 154
721 static int cb_max_message_size(void *opdata, ConnContext *context) 733 static int cb_max_message_size(void *opdata, ConnContext *context)
722 { 734 {
723 return 8192; 735 return 8192;
724 } 736 }
725 737
738 int otr_enabled(void)
739 {
740 return otr_is_enabled;
741 }
742
743 #else /* !HAVE_LIBOTR */
744
745 int otr_enabled(void)
746 {
747 return FALSE;
748 }
749
726 #endif /* HAVE_LIBOTR */ 750 #endif /* HAVE_LIBOTR */
727 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ 751 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */