Mercurial > ~mikael > mcabber > hg
comparison mcabber/mcabber/otr.c @ 2076:9fb1ccf291cc
Switch to libotr v4 API
Patch merged from isbear's mcabber-patches repository (Mikael)
author | Myhailo Danylenko <isbear@ukrpost.net> |
---|---|
date | Wed, 15 May 2013 13:32:42 +0300 |
parents | e6d355e50d7a |
children | 0c78d31c753d |
comparison
equal
deleted
inserted
replaced
2075:f52b47f29ca0 | 2076:9fb1ccf291cc |
---|---|
54 static void cb_inject_message (void *opdata, | 54 static void cb_inject_message (void *opdata, |
55 const char *accountname, | 55 const char *accountname, |
56 const char *protocol, | 56 const char *protocol, |
57 const char *recipient, | 57 const char *recipient, |
58 const char *message); | 58 const char *message); |
59 static void cb_update_context_list(void *opdata); | |
60 static void cb_new_fingerprint (void *opdata, OtrlUserState us, | |
61 const char *accountname, | |
62 const char *protocol, | |
63 const char *username, | |
64 unsigned char fingerprint[20]); | |
65 static void cb_write_fingerprints (void *opdata); | |
66 static void cb_gone_secure (void *opdata, ConnContext *context); | |
67 static void cb_gone_insecure (void *opdata, ConnContext *context); | |
68 static void cb_still_secure (void *opdata, ConnContext *context, | |
69 int is_reply); | |
70 static int cb_max_message_size (void *opdata, ConnContext *context); | |
71 | |
72 #ifdef HAVE_LIBOTR3 | |
59 static void cb_notify (void *opdata, | 73 static void cb_notify (void *opdata, |
60 OtrlNotifyLevel level, | 74 OtrlNotifyLevel level, |
61 const char *accountname, | 75 const char *accountname, |
62 const char *protocol, | 76 const char *protocol, |
63 const char *username, | 77 const char *username, |
67 static int cb_display_otr_message(void *opdata, | 81 static int cb_display_otr_message(void *opdata, |
68 const char *accountname, | 82 const char *accountname, |
69 const char *protocol, | 83 const char *protocol, |
70 const char *username, | 84 const char *username, |
71 const char *msg); | 85 const char *msg); |
72 static void cb_update_context_list(void *opdata); | |
73 static const char *cb_protocol_name (void *opdata, const char *protocol); | 86 static const char *cb_protocol_name (void *opdata, const char *protocol); |
74 static void cb_protocol_name_free (void *opdata, | 87 static void cb_protocol_name_free (void *opdata, |
75 const char *protocol_name); | 88 const char *protocol_name); |
76 static void cb_new_fingerprint (void *opdata, OtrlUserState us, | |
77 const char *accountname, | |
78 const char *protocol, | |
79 const char *username, | |
80 unsigned char fingerprint[20]); | |
81 static void cb_write_fingerprints (void *opdata); | |
82 static void cb_gone_secure (void *opdata, ConnContext *context); | |
83 static void cb_gone_insecure (void *opdata, ConnContext *context); | |
84 static void cb_still_secure (void *opdata, ConnContext *context, | |
85 int is_reply); | |
86 static void cb_log_message (void *opdata, const char *message); | 89 static void cb_log_message (void *opdata, const char *message); |
87 static int cb_max_message_size (void *opdata, ConnContext *context); | 90 |
91 static void otr_handle_smp_tlvs (OtrlTLV *tlvs, ConnContext *ctx); | |
92 #else /* HAVE_LIBOTR3 */ | |
93 static char *tagfile = NULL; | |
94 static guint otr_timer_source = 0; | |
95 | |
96 static void cb_handle_smp_event (void *opdata, OtrlSMPEvent event, | |
97 ConnContext *context, unsigned short percent, | |
98 char *question); | |
99 static void cb_handle_msg_event (void *opdata, OtrlMessageEvent event, | |
100 ConnContext *context, const char *message, | |
101 gcry_error_t err); | |
102 static void cb_create_instag (void *opdata, const char *accountname, | |
103 const char *protocol); | |
104 static void cb_timer_control (void *opdata, unsigned int interval); | |
105 #endif /* HAVE_LIBOTR3 */ | |
88 | 106 |
89 static OtrlMessageAppOps ops = | 107 static OtrlMessageAppOps ops = |
90 { | 108 { |
91 cb_policy, | 109 cb_policy, |
92 cb_create_privkey, | 110 cb_create_privkey, |
93 cb_is_logged_in, | 111 cb_is_logged_in, |
94 cb_inject_message, | 112 cb_inject_message, |
113 #ifdef HAVE_LIBOTR3 | |
95 cb_notify, | 114 cb_notify, |
96 cb_display_otr_message, | 115 cb_display_otr_message, |
116 #endif | |
97 cb_update_context_list, | 117 cb_update_context_list, |
118 #ifdef HAVE_LIBOTR3 | |
98 cb_protocol_name, | 119 cb_protocol_name, |
99 cb_protocol_name_free, | 120 cb_protocol_name_free, |
121 #endif | |
100 cb_new_fingerprint, | 122 cb_new_fingerprint, |
101 cb_write_fingerprints, | 123 cb_write_fingerprints, |
102 cb_gone_secure, | 124 cb_gone_secure, |
103 cb_gone_insecure, | 125 cb_gone_insecure, |
104 cb_still_secure, | 126 cb_still_secure, |
127 #ifdef HAVE_LIBOTR3 | |
105 cb_log_message, | 128 cb_log_message, |
129 #endif | |
106 cb_max_message_size, | 130 cb_max_message_size, |
107 NULL, /*account_name*/ | 131 NULL, /* account_name */ |
108 NULL /*account_name_free*/ | 132 NULL, /* account_name_free */ |
133 #ifndef HAVE_LIBOTR3 | |
134 NULL, /* received_symkey */ | |
135 NULL, /* otr_error_message */ | |
136 NULL, /* otr_error_message_free */ | |
137 NULL, /* resent_msg_prefix */ | |
138 NULL, /* resent_msg_prefix_free */ | |
139 cb_handle_smp_event, | |
140 cb_handle_msg_event, | |
141 cb_create_instag, | |
142 NULL, /* convert_msg */ | |
143 NULL, /* convert_free */ | |
144 cb_timer_control, | |
145 #endif | |
109 }; | 146 }; |
110 | 147 |
111 static void otr_message_disconnect(ConnContext *ctx); | 148 static void otr_message_disconnect(ConnContext *ctx); |
112 static ConnContext *otr_get_context(const char *buddy); | 149 static ConnContext *otr_get_context(const char *buddy); |
113 static void otr_startstop(const char *buddy, int start); | 150 static void otr_startstop(const char *buddy, int start); |
114 static void otr_handle_smp_tlvs(OtrlTLV *tlvs, ConnContext *ctx); | |
115 | 151 |
116 static char *otr_get_dir(void); | 152 static char *otr_get_dir(void); |
117 | 153 |
118 void otr_init(const char *fjid) | 154 void otr_init(const char *fjid) |
119 { | 155 { |
133 | 169 |
134 root = otr_get_dir(); | 170 root = otr_get_dir(); |
135 account = jidtodisp(fjid); | 171 account = jidtodisp(fjid); |
136 keyfile = g_strdup_printf("%s%s.key", root, account); | 172 keyfile = g_strdup_printf("%s%s.key", root, account); |
137 fprfile = g_strdup_printf("%s%s.fpr", root, account); | 173 fprfile = g_strdup_printf("%s%s.fpr", root, account); |
138 g_free(root); | |
139 | 174 |
140 if (otrl_privkey_read(userstate, keyfile)){ | 175 if (otrl_privkey_read(userstate, keyfile)){ |
141 scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR key from %s", keyfile); | 176 scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR key from %s", keyfile); |
142 cb_create_privkey(NULL, account, OTR_PROTOCOL_NAME); | 177 cb_create_privkey(NULL, account, OTR_PROTOCOL_NAME); |
143 } | 178 } |
144 if (otrl_privkey_read_fingerprints(userstate, fprfile, NULL, NULL)){ | 179 if (otrl_privkey_read_fingerprints(userstate, fprfile, NULL, NULL)){ |
145 scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR fingerprints from %s", | 180 scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR fingerprints from %s", |
146 fprfile); | 181 fprfile); |
147 } | 182 } |
183 #ifndef HAVE_LIBOTR3 | |
184 tagfile = g_strdup_printf("%s%s.tag", root, account); | |
185 if (otrl_instag_read(userstate, tagfile)) { | |
186 scr_LogPrint(LPRINT_LOGNORM, "Could not read OTR instance tag from %s", tagfile); | |
187 cb_create_instag(NULL, account, OTR_PROTOCOL_NAME); | |
188 } | |
189 #endif | |
190 g_free(root); | |
148 } | 191 } |
149 | 192 |
150 void otr_terminate(void) | 193 void otr_terminate(void) |
151 { | 194 { |
152 ConnContext *ctx; | 195 ConnContext *ctx; |
153 | 196 |
154 if (!otr_is_enabled) | 197 if (!otr_is_enabled) |
155 return; | 198 return; |
199 | |
200 #ifndef HAVE_LIBOTR3 | |
201 if (otr_timer_source > 0) { | |
202 g_source_remove (otr_timer_source); | |
203 otr_timer_source = 0; | |
204 } | |
205 #endif | |
156 | 206 |
157 for (ctx = userstate->context_root; ctx; ctx = ctx->next) | 207 for (ctx = userstate->context_root; ctx; ctx = ctx->next) |
158 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) | 208 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) |
159 otr_message_disconnect(ctx); | 209 otr_message_disconnect(ctx); |
160 | 210 |
173 otrl_userstate_free(userstate); | 223 otrl_userstate_free(userstate); |
174 | 224 |
175 userstate = NULL; | 225 userstate = NULL; |
176 g_free(keyfile); | 226 g_free(keyfile); |
177 keyfile = NULL; | 227 keyfile = NULL; |
228 g_free(fprfile); | |
229 fprfile = NULL; | |
230 #ifndef HAVE_LIBOTR3 | |
231 g_free(tagfile); | |
232 tagfile = NULL; | |
233 #endif | |
178 } | 234 } |
179 | 235 |
180 static char *otr_get_dir(void) | 236 static char *otr_get_dir(void) |
181 { | 237 { |
182 const char *configured_dir = settings_opt_get("otr_dir"); | 238 const char *configured_dir = settings_opt_get("otr_dir"); |
204 ConnContext *ctx; | 260 ConnContext *ctx; |
205 char *lowcasebuddy = g_strdup(buddy); | 261 char *lowcasebuddy = g_strdup(buddy); |
206 | 262 |
207 mc_strtolower(lowcasebuddy); | 263 mc_strtolower(lowcasebuddy); |
208 ctx = otrl_context_find(userstate, lowcasebuddy, account, OTR_PROTOCOL_NAME, | 264 ctx = otrl_context_find(userstate, lowcasebuddy, account, OTR_PROTOCOL_NAME, |
265 #ifdef HAVE_LIBOTR3 | |
209 1, &null, NULL, NULL); | 266 1, &null, NULL, NULL); |
267 #else | |
268 // INSTAG XXX | |
269 OTRL_INSTAG_BEST, 1, &null, NULL, NULL); | |
270 #endif | |
210 g_free(lowcasebuddy); | 271 g_free(lowcasebuddy); |
211 return ctx; | 272 return ctx; |
212 } | 273 } |
213 | 274 |
214 static void otr_message_disconnect(ConnContext *ctx) | 275 static void otr_message_disconnect(ConnContext *ctx) |
215 { | 276 { |
216 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) | 277 if (ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) |
217 cb_gone_insecure(NULL, ctx); | 278 cb_gone_insecure(NULL, ctx); |
218 otrl_message_disconnect(userstate, &ops, NULL, ctx->accountname, | 279 otrl_message_disconnect(userstate, &ops, NULL, ctx->accountname, |
280 #ifdef HAVE_LIBOTR3 | |
219 ctx->protocol, ctx->username); | 281 ctx->protocol, ctx->username); |
282 #else | |
283 // INSTAG XXX | |
284 ctx->protocol, ctx->username, OTRL_INSTAG_BEST); | |
285 #endif | |
220 } | 286 } |
221 | 287 |
222 static void otr_startstop(const char *buddy, int start) | 288 static void otr_startstop(const char *buddy, int start) |
223 { | 289 { |
224 char *msg = NULL; | 290 char *msg = NULL; |
280 tr = ctx->active_fingerprint->trust; | 346 tr = ctx->active_fingerprint->trust; |
281 scr_LogPrint(LPRINT_LOGNORM, "%s [%44s]: %s", ctx->username, fpr, | 347 scr_LogPrint(LPRINT_LOGNORM, "%s [%44s]: %s", ctx->username, fpr, |
282 tr && *tr ? "trusted" : "untrusted"); | 348 tr && *tr ? "trusted" : "untrusted"); |
283 cb_write_fingerprints(NULL); | 349 cb_write_fingerprints(NULL); |
284 } | 350 } |
351 | |
352 #ifdef HAVE_LIBOTR3 | |
285 | 353 |
286 static void otr_handle_smp_tlvs(OtrlTLV *tlvs, ConnContext *ctx) | 354 static void otr_handle_smp_tlvs(OtrlTLV *tlvs, ConnContext *ctx) |
287 { | 355 { |
288 OtrlTLV *tlv = NULL; | 356 OtrlTLV *tlv = NULL; |
289 char *sbuf = NULL; | 357 char *sbuf = NULL; |
352 scr_WriteIncomingMessage(ctx->username, sbuf, 0, HBB_PREFIX_INFO, 0); | 420 scr_WriteIncomingMessage(ctx->username, sbuf, 0, HBB_PREFIX_INFO, 0); |
353 g_free(sbuf); | 421 g_free(sbuf); |
354 } | 422 } |
355 } | 423 } |
356 | 424 |
425 #else /* HAVE_LIBOTR3 */ | |
426 | |
427 static void cb_handle_smp_event(void *opdata, OtrlSMPEvent event, | |
428 ConnContext *context, unsigned short percent, | |
429 char *question) | |
430 { | |
431 const char *msg = NULL; | |
432 char *freeme = NULL; | |
433 switch (event) { | |
434 case OTRL_SMPEVENT_ASK_FOR_SECRET: | |
435 msg = freeme = g_strdup_printf("OTR: Socialist Millionaires' Protocol: " | |
436 "Received SMP Initiation.\n" | |
437 "Answer with /otr smpr %s $secret", | |
438 context->username); | |
439 break; | |
440 case OTRL_SMPEVENT_ASK_FOR_ANSWER: | |
441 msg = freeme = g_strdup_printf("OTR: Socialist Millionaires' Protocol: " | |
442 "Received SMP Initiation.\n" | |
443 "Answer with /otr smpr %s $secret\n" | |
444 "Question: %s", context->username, | |
445 question); | |
446 break; | |
447 case OTRL_SMPEVENT_CHEATED: | |
448 msg = "OTR: Socialist Millionaires' Protocol: Correspondent cancelled negotiation!"; | |
449 otrl_message_abort_smp(userstate, &ops, opdata, context); | |
450 break; | |
451 case OTRL_SMPEVENT_IN_PROGRESS: | |
452 scr_log_print(LPRINT_DEBUG, "OTR: Socialist Millionaires' Protocol: " | |
453 "Negotiation is in pogress..."); | |
454 break; | |
455 case OTRL_SMPEVENT_SUCCESS: | |
456 msg = "OTR: Socialist Millionaires' Protocol: Success!"; | |
457 break; | |
458 case OTRL_SMPEVENT_FAILURE: | |
459 msg = "OTR: Socialist Millionaires' Protocol: Failure."; | |
460 break; | |
461 case OTRL_SMPEVENT_ABORT: | |
462 msg = "OTR: Socialist Millionaires' Protocol: Aborted."; | |
463 break; | |
464 case OTRL_SMPEVENT_ERROR: | |
465 msg = "OTR: Socialist Millionaires' Protocol: Error occured, aborting negotiations!"; | |
466 otrl_message_abort_smp(userstate, &ops, opdata, context); | |
467 break; | |
468 default: | |
469 break; | |
470 } | |
471 | |
472 if (msg) { | |
473 scr_WriteIncomingMessage(context->username, msg, 0, HBB_PREFIX_INFO, 0); | |
474 g_free(freeme); | |
475 } | |
476 } | |
477 | |
478 static void cb_handle_msg_event(void *opdata, OtrlMessageEvent event, | |
479 ConnContext *context, const char *message, | |
480 gcry_error_t err) | |
481 { | |
482 const char *msg = NULL; | |
483 char *freeme = NULL; | |
484 switch (event) { | |
485 case OTRL_MSGEVENT_ENCRYPTION_REQUIRED: | |
486 msg = "OTR: Policy requires encryption on message!"; | |
487 break; | |
488 case OTRL_MSGEVENT_ENCRYPTION_ERROR: | |
489 msg = "OTR: Encryption error! Message not sent."; | |
490 break; | |
491 case OTRL_MSGEVENT_CONNECTION_ENDED: | |
492 msg = "OTR: Connection closed by remote end, message lost. " | |
493 "Close or refresh connection."; | |
494 break; | |
495 case OTRL_MSGEVENT_SETUP_ERROR: | |
496 // FIXME | |
497 msg = freeme = g_strdup_printf("OTR: Error setting up private conversation: %u", | |
498 err); | |
499 break; | |
500 case OTRL_MSGEVENT_MSG_REFLECTED: | |
501 msg = "OTR: Received own OTR message!"; | |
502 break; | |
503 case OTRL_MSGEVENT_MSG_RESENT: | |
504 msg = "OTR: Previous message was resent."; | |
505 break; | |
506 case OTRL_MSGEVENT_RCVDMSG_NOT_IN_PRIVATE: | |
507 msg = "OTR: Received encrypted message, but connection is not established " \ | |
508 "yet! Message lost."; | |
509 break; | |
510 case OTRL_MSGEVENT_RCVDMSG_UNREADABLE: | |
511 msg = "OTR: Unable to read incoming message!"; | |
512 break; | |
513 case OTRL_MSGEVENT_RCVDMSG_MALFORMED: | |
514 msg = "OTR: Malformed incoming message!"; | |
515 break; | |
516 case OTRL_MSGEVENT_LOG_HEARTBEAT_RCVD: | |
517 scr_log_print(LPRINT_DEBUG, "OTR: Received heartbeat."); | |
518 break; | |
519 case OTRL_MSGEVENT_LOG_HEARTBEAT_SENT: | |
520 scr_log_print(LPRINT_DEBUG, "OTR: Sent heartbeat."); | |
521 break; | |
522 case OTRL_MSGEVENT_RCVDMSG_GENERAL_ERR: | |
523 msg = freeme = g_strdup_printf("OTR: Received general otr error: %s", | |
524 message); | |
525 break; | |
526 case OTRL_MSGEVENT_RCVDMSG_UNENCRYPTED: | |
527 msg = freeme = g_strdup_printf("OTR: Received unencrypted message: %s", | |
528 message); | |
529 break; | |
530 case OTRL_MSGEVENT_RCVDMSG_UNRECOGNIZED: | |
531 msg = "OTR: Unable to determine type of received OTR message!"; | |
532 break; | |
533 case OTRL_MSGEVENT_RCVDMSG_FOR_OTHER_INSTANCE: | |
534 // XXX | |
535 scr_log_print(LPRINT_DEBUG, "OTR: Received message for other instance."); | |
536 break; | |
537 default: | |
538 break; | |
539 } | |
540 | |
541 if (msg) { | |
542 scr_WriteIncomingMessage(context->username, msg, 0, HBB_PREFIX_INFO, 0); | |
543 g_free(freeme); | |
544 } | |
545 } | |
546 | |
547 #endif /* HAVE_LIBOTR3 */ | |
548 | |
357 /* | 549 /* |
358 * returns whether a otr_message was received | 550 * returns whether a otr_message was received |
359 * sets *otr_data to NULL, when it was an internal otr message | 551 * sets *otr_data to NULL, when it was an internal otr message |
360 */ | 552 */ |
361 int otr_receive(char **otr_data, const char *buddy, int *free_msg) | 553 int otr_receive(char **otr_data, const char *buddy, int *free_msg) |
362 { | 554 { |
363 int ignore_message; | 555 int ignore_message; |
364 char *newmessage = NULL; | 556 char *newmessage = NULL; |
557 #ifdef HAVE_LIBOTR3 | |
365 OtrlTLV *tlvs = NULL; | 558 OtrlTLV *tlvs = NULL; |
366 OtrlTLV *tlv = NULL; | 559 OtrlTLV *tlv = NULL; |
560 #endif | |
367 ConnContext *ctx; | 561 ConnContext *ctx; |
368 | 562 |
369 ctx = otr_get_context(buddy); | 563 ctx = otr_get_context(buddy); |
370 *free_msg = 0; | 564 *free_msg = 0; |
371 ignore_message = otrl_message_receiving(userstate, &ops, NULL, | 565 ignore_message = otrl_message_receiving(userstate, &ops, NULL, |
372 ctx->accountname, ctx->protocol, | 566 ctx->accountname, ctx->protocol, |
373 ctx->username, *otr_data, | 567 ctx->username, *otr_data, |
374 &newmessage, &tlvs,NULL, NULL); | 568 #ifdef HAVE_LIBOTR3 |
375 | 569 &newmessage, &tlvs, NULL, NULL); |
376 | 570 |
377 tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED); | 571 tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED); |
378 if (tlv) { | 572 if (tlv) { |
379 /* Notify the user that the other side disconnected. */ | 573 /* Notify the user that the other side disconnected. */ |
380 if (ctx) { | 574 if (ctx) { |
385 | 579 |
386 otr_handle_smp_tlvs(tlvs, ctx); | 580 otr_handle_smp_tlvs(tlvs, ctx); |
387 | 581 |
388 if (tlvs != NULL) | 582 if (tlvs != NULL) |
389 otrl_tlv_free(tlvs); | 583 otrl_tlv_free(tlvs); |
584 #else | |
585 &newmessage, NULL, NULL, NULL, NULL); | |
586 #endif | |
390 | 587 |
391 if (ignore_message) | 588 if (ignore_message) |
392 *otr_data = NULL; | 589 *otr_data = NULL; |
393 | 590 |
394 if (!ignore_message && newmessage) { | 591 if (!ignore_message && newmessage) { |
408 char *htmlmsg; | 605 char *htmlmsg; |
409 ConnContext *ctx = otr_get_context(buddy); | 606 ConnContext *ctx = otr_get_context(buddy); |
410 | 607 |
411 if (ctx->msgstate == OTRL_MSGSTATE_PLAINTEXT) | 608 if (ctx->msgstate == OTRL_MSGSTATE_PLAINTEXT) |
412 err = otrl_message_sending(userstate, &ops, NULL, ctx->accountname, | 609 err = otrl_message_sending(userstate, &ops, NULL, ctx->accountname, |
610 #ifdef HAVE_LIBOTR3 | |
413 ctx->protocol, ctx->username, *msg, NULL, | 611 ctx->protocol, ctx->username, *msg, NULL, |
414 &newmessage, NULL, NULL); | 612 &newmessage, NULL, NULL); |
613 #else | |
614 // INSTAG XXX | |
615 ctx->protocol, ctx->username, OTRL_INSTAG_BEST, | |
616 *msg, NULL, &newmessage, OTRL_FRAGMENT_SEND_SKIP, | |
617 NULL, NULL, NULL); | |
618 #endif | |
415 else { | 619 else { |
416 htmlmsg = html_escape(*msg); | 620 htmlmsg = html_escape(*msg); |
417 err = otrl_message_sending(userstate, &ops, NULL, ctx->accountname, | 621 err = otrl_message_sending(userstate, &ops, NULL, ctx->accountname, |
622 #ifdef HAVE_LIBOTR3 | |
418 ctx->protocol, ctx->username, htmlmsg, NULL, | 623 ctx->protocol, ctx->username, htmlmsg, NULL, |
419 &newmessage, NULL, NULL); | 624 &newmessage, NULL, NULL); |
625 #else | |
626 // INSTAG XXX | |
627 ctx->protocol, ctx->username, OTRL_INSTAG_BEST, | |
628 htmlmsg, NULL, &newmessage, OTRL_FRAGMENT_SEND_SKIP, | |
629 NULL, NULL, NULL); | |
630 #endif | |
420 g_free(htmlmsg); | 631 g_free(htmlmsg); |
421 } | 632 } |
422 | 633 |
423 if (err) | 634 if (err) |
424 *msg = NULL; /*something went wrong, don't send the plain-message! */ | 635 *msg = NULL; /*something went wrong, don't send the plain-message! */ |
646 if (roster_gettype(recipient) == ROSTER_TYPE_USER) | 857 if (roster_gettype(recipient) == ROSTER_TYPE_USER) |
647 xmpp_send_msg(recipient, message, ROSTER_TYPE_USER, "", TRUE, NULL, | 858 xmpp_send_msg(recipient, message, ROSTER_TYPE_USER, "", TRUE, NULL, |
648 LM_MESSAGE_SUB_TYPE_NOT_SET, NULL); | 859 LM_MESSAGE_SUB_TYPE_NOT_SET, NULL); |
649 } | 860 } |
650 | 861 |
862 /* When the list of ConnContexts changes (including a change in | |
863 * state), this is called so the UI can be updated. */ | |
864 static void cb_update_context_list(void *opdata) | |
865 { | |
866 /*maybe introduce new status characters for mcabber, | |
867 * then use this function (?!)*/ | |
868 } | |
869 | |
870 /* A new fingerprint for the given user has been received. */ | |
871 static void cb_new_fingerprint(void *opdata, OtrlUserState us, | |
872 const char *accountname, const char *protocol, | |
873 const char *username, | |
874 unsigned char fingerprint[20]) | |
875 { | |
876 char *sbuf = NULL; | |
877 char readable[45]; | |
878 | |
879 otrl_privkey_hash_to_human(readable, fingerprint); | |
880 sbuf = g_strdup_printf("OTR: new fingerprint: %s", readable); | |
881 scr_WriteIncomingMessage(username, sbuf, 0, HBB_PREFIX_INFO, 0); | |
882 g_free(sbuf); | |
883 } | |
884 | |
885 /* The list of known fingerprints has changed. Write them to disk. */ | |
886 static void cb_write_fingerprints(void *opdata) | |
887 { | |
888 otrl_privkey_write_fingerprints(userstate, fprfile); | |
889 } | |
890 | |
891 /* A ConnContext has entered a secure state. */ | |
892 static void cb_gone_secure(void *opdata, ConnContext *context) | |
893 { | |
894 scr_WriteIncomingMessage(context->username, "OTR: channel established", 0, | |
895 HBB_PREFIX_INFO, 0); | |
896 } | |
897 | |
898 /* A ConnContext has left a secure state. */ | |
899 static void cb_gone_insecure(void *opdata, ConnContext *context) | |
900 { | |
901 scr_WriteIncomingMessage(context->username, "OTR: channel closed", 0, | |
902 HBB_PREFIX_INFO, 0); | |
903 } | |
904 | |
905 /* We have completed an authentication, using the D-H keys we | |
906 * already knew. is_reply indicates whether we initiated the AKE. */ | |
907 static void cb_still_secure(void *opdata, ConnContext *context, int is_reply) | |
908 { | |
909 scr_WriteIncomingMessage(context->username, "OTR: channel reestablished", 0, | |
910 HBB_PREFIX_INFO, 0); | |
911 } | |
912 | |
913 #ifdef HAVE_LIBOTR3 | |
914 | |
651 /* Display a notification message for a particular | 915 /* Display a notification message for a particular |
652 * accountname / protocol / username conversation. */ | 916 * accountname / protocol / username conversation. */ |
653 static void cb_notify(void *opdata, OtrlNotifyLevel level, | 917 static void cb_notify(void *opdata, OtrlNotifyLevel level, |
654 const char *accountname, const char *protocol, | 918 const char *accountname, const char *protocol, |
655 const char *username, const char *title, | 919 const char *username, const char *title, |
682 scr_WriteIncomingMessage(username, strippedmsg, 0, HBB_PREFIX_INFO, 0); | 946 scr_WriteIncomingMessage(username, strippedmsg, 0, HBB_PREFIX_INFO, 0); |
683 g_free(strippedmsg); | 947 g_free(strippedmsg); |
684 return 0; | 948 return 0; |
685 } | 949 } |
686 | 950 |
687 /* When the list of ConnContexts changes (including a change in | |
688 * state), this is called so the UI can be updated. */ | |
689 static void cb_update_context_list(void *opdata) | |
690 { | |
691 /*maybe introduce new status characters for mcabber, | |
692 * then use this function (?!)*/ | |
693 } | |
694 | |
695 /* Return a newly allocated string containing a human-friendly name | 951 /* Return a newly allocated string containing a human-friendly name |
696 * for the given protocol id */ | 952 * for the given protocol id */ |
697 static const char *cb_protocol_name(void *opdata, const char *protocol) | 953 static const char *cb_protocol_name(void *opdata, const char *protocol) |
698 { | 954 { |
699 return protocol; | 955 return protocol; |
703 static void cb_protocol_name_free (void *opdata, const char *protocol_name) | 959 static void cb_protocol_name_free (void *opdata, const char *protocol_name) |
704 { | 960 { |
705 /* We didn't allocated memory, so we don't have to free anything :p */ | 961 /* We didn't allocated memory, so we don't have to free anything :p */ |
706 } | 962 } |
707 | 963 |
708 /* A new fingerprint for the given user has been received. */ | |
709 static void cb_new_fingerprint(void *opdata, OtrlUserState us, | |
710 const char *accountname, const char *protocol, | |
711 const char *username, | |
712 unsigned char fingerprint[20]) | |
713 { | |
714 char *sbuf = NULL; | |
715 char readable[45]; | |
716 | |
717 otrl_privkey_hash_to_human(readable, fingerprint); | |
718 sbuf = g_strdup_printf("OTR: new fingerprint: %s", readable); | |
719 scr_WriteIncomingMessage(username, sbuf, 0, HBB_PREFIX_INFO, 0); | |
720 g_free(sbuf); | |
721 } | |
722 | |
723 /* The list of known fingerprints has changed. Write them to disk. */ | |
724 static void cb_write_fingerprints(void *opdata) | |
725 { | |
726 otrl_privkey_write_fingerprints(userstate, fprfile); | |
727 } | |
728 | |
729 /* A ConnContext has entered a secure state. */ | |
730 static void cb_gone_secure(void *opdata, ConnContext *context) | |
731 { | |
732 scr_WriteIncomingMessage(context->username, "OTR: channel established", 0, | |
733 HBB_PREFIX_INFO, 0); | |
734 } | |
735 | |
736 /* A ConnContext has left a secure state. */ | |
737 static void cb_gone_insecure(void *opdata, ConnContext *context) | |
738 { | |
739 scr_WriteIncomingMessage(context->username, "OTR: channel closed", 0, | |
740 HBB_PREFIX_INFO, 0); | |
741 } | |
742 | |
743 /* We have completed an authentication, using the D-H keys we | |
744 * already knew. is_reply indicates whether we initiated the AKE. */ | |
745 static void cb_still_secure(void *opdata, ConnContext *context, int is_reply) | |
746 { | |
747 scr_WriteIncomingMessage(context->username, "OTR: channel reestablished", 0, | |
748 HBB_PREFIX_INFO, 0); | |
749 } | |
750 | |
751 /* Log a message. The passed message will end in "\n". */ | 964 /* Log a message. The passed message will end in "\n". */ |
752 static void cb_log_message(void *opdata, const char *message) | 965 static void cb_log_message(void *opdata, const char *message) |
753 { | 966 { |
754 scr_LogPrint(LPRINT_DEBUG, "OTR: %s", message); | 967 scr_LogPrint(LPRINT_DEBUG, "OTR: %s", message); |
755 } | 968 } |
756 | 969 |
970 #else /* HAVE_LIBOTR3 */ | |
971 | |
972 /* Generate unique instance tag for account. */ | |
973 static void cb_create_instag(void *opdata, const char *accountname, | |
974 const char *protocol) | |
975 { | |
976 if (otrl_instag_generate(userstate, tagfile, accountname, protocol)) { | |
977 scr_LogPrint(LPRINT_LOGNORM, "OTR instance tag generation failed!"); | |
978 } | |
979 } | |
980 | |
981 static gboolean otr_timer_cb(gpointer userdata) | |
982 { | |
983 otrl_message_poll(userstate, &ops, userdata); | |
984 return TRUE; | |
985 } | |
986 | |
987 static void cb_timer_control(void *opdata, unsigned int interval) | |
988 { | |
989 if (otr_timer_source > 0) { | |
990 g_source_remove(otr_timer_source); | |
991 otr_timer_source = 0; | |
992 } | |
993 if (interval > 0) | |
994 otr_timer_source = g_timeout_add_seconds(interval, otr_timer_cb, opdata); | |
995 } | |
996 | |
997 #endif /* HAVE_LIBOTR3 */ | |
998 | |
757 /* Find the maximum message size supported by this protocol. */ | 999 /* Find the maximum message size supported by this protocol. */ |
758 static int cb_max_message_size(void *opdata, ConnContext *context) | 1000 static int cb_max_message_size(void *opdata, ConnContext *context) |
759 { | 1001 { |
760 return 8192; | 1002 return 8192; |
761 } | 1003 } |