comparison mcabber/src/otr.c @ 1320:cb400799db8f

Configurable OTR directory
author franky@veqlargh.fs
date Wed, 03 Oct 2007 21:27:46 +0200
parents b17754d9221b
children ab1b7f7a682e
comparison
equal deleted inserted replaced
1319:dc83548be698 1320:cb400799db8f
107 static void otr_message_disconnect(ConnContext *ctx); 107 static void otr_message_disconnect(ConnContext *ctx);
108 static ConnContext * otr_get_context(const char *buddy); 108 static ConnContext * otr_get_context(const char *buddy);
109 static void otr_startstop(const char * buddy, int start); 109 static void otr_startstop(const char * buddy, int start);
110 static void otr_handle_smp_tlvs(OtrlTLV * tlvs, ConnContext * ctx); 110 static void otr_handle_smp_tlvs(OtrlTLV * tlvs, ConnContext * ctx);
111 111
112 static char * otr_get_dir(void);
112 113
113 void otr_init(const char *jid) 114 void otr_init(const char *jid)
114 { 115 {
115 char * root = expand_filename("~/.mcabber/otr/"); 116 char * root = otr_get_dir();
116 account = jidtodisp(jid); 117 account = jidtodisp(jid);
117 keyfile = g_strdup_printf("%s%s.key", root, account); 118 keyfile = g_strdup_printf("%s%s.key", root, account);
118 fprfile = g_strdup_printf("%s%s.fpr", root, account); 119 fprfile = g_strdup_printf("%s%s.fpr", root, account);
119 g_free(root); 120 g_free(root);
120 121
133 134
134 void otr_terminate(void) 135 void otr_terminate(void)
135 { 136 {
136 ConnContext * ctx; 137 ConnContext * ctx;
137 138
138 for(ctx = userstate->context_root; ctx; ctx = ctx->next) 139 for (ctx = userstate->context_root; ctx; ctx = ctx->next)
139 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) 140 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED)
140 otr_message_disconnect(ctx); 141 otr_message_disconnect(ctx);
141 142
142 g_free(account); 143 g_free(account);
143 account = NULL; 144 account = NULL;
154 otrl_userstate_free(userstate); 155 otrl_userstate_free(userstate);
155 156
156 userstate = NULL; 157 userstate = NULL;
157 g_free(keyfile); 158 g_free(keyfile);
158 keyfile = NULL; 159 keyfile = NULL;
160 }
161
162 static char * otr_get_dir(void)
163 {
164 char * configured_dir = (char *)settings_opt_get("otr_dir");
165
166 if (configured_dir)
167 return expand_filename(configured_dir);
168 else
169 return expand_filename("~/.mcabber/otr/");
159 } 170 }
160 171
161 static ConnContext * otr_get_context(const char *buddy) 172 static ConnContext * otr_get_context(const char *buddy)
162 { 173 {
163 int null = 0; 174 int null = 0;
546 * desired. */ 557 * desired. */
547 static void cb_create_privkey(void *opdata, const char *accountname, 558 static void cb_create_privkey(void *opdata, const char *accountname,
548 const char *protocol) 559 const char *protocol)
549 { 560 {
550 gcry_error_t e; 561 gcry_error_t e;
562 char * root;
551 563
552 scr_LogPrint(LPRINT_LOGNORM, 564 scr_LogPrint(LPRINT_LOGNORM,
553 "Generating new OTR key for %s. This may take a while...", 565 "Generating new OTR key for %s. This may take a while...",
554 accountname); 566 accountname);
555 scr_DoUpdate(); 567 scr_DoUpdate();
556 568
557 e = otrl_privkey_generate(userstate, keyfile, accountname, protocol); 569 e = otrl_privkey_generate(userstate, keyfile, accountname, protocol);
558 570
559 if (e) 571 if (e) {
560 scr_LogPrint(LPRINT_LOGNORM, "OTR key generation failed!" 572 root = otr_get_dir();
561 " Please mkdir ~/.mcabber/otr/ and restart mcabber."); 573 scr_LogPrint(LPRINT_LOGNORM, "OTR key generation failed! Please mkdir "
574 "%s if you want to use otr encryption.", root);
575 g_free(root);
576 }
562 else 577 else
563 scr_LogPrint(LPRINT_LOGNORM, "OTR key generated."); 578 scr_LogPrint(LPRINT_LOGNORM, "OTR key generated.");
564 } 579 }
565 580
566 /* Report whether you think the given user is online. Return 1 if 581 /* Report whether you think the given user is online. Return 1 if