Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/otr.c @ 1577:e1a642472f4e
Use otr context where possible, saves one mc_strtolower() per received message
author | franky |
---|---|
date | Sun, 12 Apr 2009 20:20:56 +0200 |
parents | 24ff212a1c54 |
children | c8be6c2243d6 |
comparison
equal
deleted
inserted
replaced
1576:72fef01d9061 | 1577:e1a642472f4e |
---|---|
32 #include "utils.h" | 32 #include "utils.h" |
33 #include "screen.h" | 33 #include "screen.h" |
34 #include "settings.h" | 34 #include "settings.h" |
35 #include "nohtml.h" | 35 #include "nohtml.h" |
36 | 36 |
37 #define OTR_PROTOCOL_NAME "jabber" | |
37 | 38 |
38 static OtrlUserState userstate = NULL; | 39 static OtrlUserState userstate = NULL; |
39 static char * account = NULL; | 40 static char * account = NULL; |
40 static char * keyfile = NULL; | 41 static char * keyfile = NULL; |
41 static char * fprfile = NULL; | 42 static char * fprfile = NULL; |
126 if (!otr_is_enabled) | 127 if (!otr_is_enabled) |
127 return; | 128 return; |
128 | 129 |
129 OTRL_INIT; | 130 OTRL_INIT; |
130 | 131 |
131 userstate = otrl_userstate_create (); | 132 userstate = otrl_userstate_create(); |
132 | 133 |
133 root = otr_get_dir(); | 134 root = otr_get_dir(); |
134 account = jidtodisp(fjid); | 135 account = jidtodisp(fjid); |
135 keyfile = g_strdup_printf("%s%s.key", root, account); | 136 keyfile = g_strdup_printf("%s%s.key", root, account); |
136 fprfile = g_strdup_printf("%s%s.fpr", root, account); | 137 fprfile = g_strdup_printf("%s%s.fpr", root, account); |
137 g_free(root); | 138 g_free(root); |
138 | 139 |
139 if (otrl_privkey_read(userstate, keyfile)){ | 140 if (otrl_privkey_read(userstate, keyfile)){ |
140 scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR key from %s", keyfile); | 141 scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR key from %s", keyfile); |
141 cb_create_privkey(NULL, account, "jabber"); | 142 cb_create_privkey(NULL, account, OTR_PROTOCOL_NAME); |
142 } | 143 } |
143 if (otrl_privkey_read_fingerprints(userstate, fprfile, NULL, NULL)){ | 144 if (otrl_privkey_read_fingerprints(userstate, fprfile, NULL, NULL)){ |
144 scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR fingerprints from %s", | 145 scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR fingerprints from %s", |
145 fprfile); | 146 fprfile); |
146 } | 147 } |
202 int null = 0; | 203 int null = 0; |
203 ConnContext * ctx; | 204 ConnContext * ctx; |
204 char * lowcasebuddy = g_strdup(buddy); | 205 char * lowcasebuddy = g_strdup(buddy); |
205 | 206 |
206 mc_strtolower(lowcasebuddy); | 207 mc_strtolower(lowcasebuddy); |
207 ctx = otrl_context_find(userstate, lowcasebuddy, account, "jabber", 1, &null, | 208 ctx = otrl_context_find(userstate, lowcasebuddy, account, OTR_PROTOCOL_NAME, |
208 NULL, NULL); | 209 1, &null, NULL, NULL); |
209 g_free(lowcasebuddy); | 210 g_free(lowcasebuddy); |
210 return ctx; | 211 return ctx; |
211 } | 212 } |
212 | 213 |
213 static void otr_message_disconnect(ConnContext *ctx) | 214 static void otr_message_disconnect(ConnContext *ctx) |
363 char *newmessage = NULL; | 364 char *newmessage = NULL; |
364 OtrlTLV *tlvs = NULL; | 365 OtrlTLV *tlvs = NULL; |
365 OtrlTLV *tlv = NULL; | 366 OtrlTLV *tlv = NULL; |
366 ConnContext * ctx; | 367 ConnContext * ctx; |
367 | 368 |
369 ctx = otr_get_context(buddy); | |
368 *free_msg = 0; | 370 *free_msg = 0; |
369 ignore_message = otrl_message_receiving(userstate, &ops, NULL, account, | 371 ignore_message = otrl_message_receiving(userstate, &ops, NULL, |
370 "jabber", buddy, *otr_data, &newmessage, &tlvs, NULL, NULL); | 372 ctx->accountname, ctx->protocol, |
371 | 373 ctx->username, *otr_data, |
372 ctx = otr_get_context(buddy); | 374 &newmessage, &tlvs,NULL, NULL); |
375 | |
373 | 376 |
374 tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED); | 377 tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED); |
375 if (tlv) { | 378 if (tlv) { |
376 /* Notify the user that the other side disconnected. */ | 379 /* Notify the user that the other side disconnected. */ |
377 if (ctx) { | 380 if (ctx) { |
378 cb_gone_insecure(NULL, ctx); | 381 cb_gone_insecure(NULL, ctx); |
379 otr_disconnect(buddy); | 382 otr_disconnect(ctx->username); |
380 } | 383 } |
381 } | 384 } |
382 | 385 |
383 otr_handle_smp_tlvs(tlvs, ctx); | 386 otr_handle_smp_tlvs(tlvs, ctx); |
384 | 387 |
405 char *htmlmsg; | 408 char *htmlmsg; |
406 ConnContext * ctx = otr_get_context(buddy); | 409 ConnContext * ctx = otr_get_context(buddy); |
407 | 410 |
408 htmlmsg = html_escape(*msg); | 411 htmlmsg = html_escape(*msg); |
409 | 412 |
410 err = otrl_message_sending(userstate, &ops, NULL, account, "jabber", buddy, | 413 err = otrl_message_sending(userstate, &ops, NULL, ctx->accountname, |
411 htmlmsg, NULL, &newmessage, NULL, NULL); | 414 ctx->protocol, ctx->username, htmlmsg, NULL, |
415 &newmessage, NULL, NULL); | |
412 | 416 |
413 g_free(htmlmsg); | 417 g_free(htmlmsg); |
414 | 418 |
415 if (err) | 419 if (err) |
416 *msg = NULL; /*something went wrong, don't send the plain-message! */ | 420 *msg = NULL; /*something went wrong, don't send the plain-message! */ |
428 /* Prints OTR connection state */ | 432 /* Prints OTR connection state */ |
429 void otr_print_info(const char * buddy) | 433 void otr_print_info(const char * buddy) |
430 { | 434 { |
431 const char *state, *auth, *policy; | 435 const char *state, *auth, *policy; |
432 ConnContext * ctx = otr_get_context(buddy); | 436 ConnContext * ctx = otr_get_context(buddy); |
433 OtrlPolicy p = cb_policy (ctx->app_data, ctx); | 437 OtrlPolicy p = cb_policy(ctx->app_data, ctx); |
434 | 438 |
435 if (!userstate || !ctx) | 439 if (!userstate || !ctx) |
436 return; | 440 return; |
437 | 441 |
438 switch (ctx->msgstate) { | 442 switch (ctx->msgstate) { |