Changeset 090c9b7
- Timestamp:
- 2013-08-01T20:39:49Z (11 years ago)
- Branches:
- master
- Children:
- b939cff
- Parents:
- 352a6b0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
otr.c
r352a6b0 r090c9b7 60 60 const char *recipient, const char *message); 61 61 62 int op_display_otr_message(void *opdata, const char *accountname, const char *protocol,63 const char *username, const char *msg);64 65 62 void op_new_fingerprint(void *opdata, OtrlUserState us, const char *accountname, 66 63 const char *protocol, const char *username, unsigned char fingerprint[20]); … … 86 83 void op_handle_smp_event(void *opdata, OtrlSMPEvent ev, ConnContext *ctx, 87 84 unsigned short percent, char *question); 85 86 void op_handle_msg_event(void *opdata, OtrlMessageEvent ev, ConnContext *ctx, 87 const char *message, gcry_error_t err); 88 88 89 89 /** otr sub-command handlers: **/ … … 162 162 irc_user_t *peeruser(irc_t *irc, const char *handle, const char *protocol); 163 163 164 /* show an otr-related message to the user */ 165 void display_otr_message(void *opdata, ConnContext *ctx, const char *fmt, ...); 166 167 /* write an otr-related message to the system log */ 168 void log_otr_message(void *opdata, const char *fmt, ...); 169 164 170 /* combined handler for the 'otr smp' and 'otr smpq' commands */ 165 171 void otr_smp_or_smpq(irc_t *irc, const char *nick, const char *question, … … 211 217 otr_ops.is_logged_in = &op_is_logged_in; 212 218 otr_ops.inject_message = &op_inject_message; 213 //XXX otr_ops.display_otr_message = &op_display_otr_message;214 219 otr_ops.update_context_list = NULL; 215 220 otr_ops.new_fingerprint = &op_new_fingerprint; … … 218 223 otr_ops.gone_insecure = &op_gone_insecure; 219 224 otr_ops.still_secure = &op_still_secure; 220 //XXX otr_ops.log_message = &op_log_message;221 225 otr_ops.max_message_size = &op_max_message_size; 222 226 otr_ops.account_name = &op_account_name; … … 230 234 otr_ops.resent_msg_prefix_free = NULL; 231 235 otr_ops.handle_smp_event = &op_handle_smp_event; 232 otr_ops.handle_msg_event = NULL; // XXX236 otr_ops.handle_msg_event = &op_handle_msg_event; 233 237 otr_ops.create_instag = NULL; // XXX 234 238 otr_ops.convert_msg = &op_convert_msg; … … 560 564 } 561 565 562 int op_display_otr_message(void *opdata, const char *accountname,563 const char *protocol, const char *username, const char *message)564 {565 struct im_connection *ic = check_imc(opdata, accountname, protocol);566 char *msg = g_strdup(message);567 irc_t *irc = ic->bee->ui_data;568 irc_user_t *u = peeruser(irc, username, protocol);569 570 strip_html(msg);571 if(u) {572 /* display as a notice from this particular user */573 irc_usernotice(u, "%s", msg);574 } else {575 irc_rootmsg(irc, "[otr] %s", msg);576 }577 578 g_free(msg);579 return 0;580 }581 582 566 void op_new_fingerprint(void *opdata, OtrlUserState us, 583 567 const char *accountname, const char *protocol, … … 670 654 } 671 655 672 void op_log_message(void *opdata, const char *message)673 {674 char *msg = g_strdup(message);675 676 strip_html(msg);677 log_message(LOGLVL_INFO, "otr: %s", msg);678 g_free(msg);679 }680 681 656 int op_max_message_size(void *opdata, ConnContext *context) 682 657 { … … 821 796 otrl_message_abort_smp(us, &otr_ops, u->bu->ic, ctx); 822 797 otrl_sm_state_free(ctx->smstate); 798 break; 799 } 800 } 801 802 void op_handle_msg_event(void *opdata, OtrlMessageEvent ev, ConnContext *ctx, 803 const char *message, gcry_error_t err) 804 { 805 switch(ev) { 806 case OTRL_MSGEVENT_ENCRYPTION_REQUIRED: 807 display_otr_message(opdata, ctx, 808 "policy requires encryption - message not sent"); 809 break; 810 case OTRL_MSGEVENT_ENCRYPTION_ERROR: 811 display_otr_message(opdata, ctx, 812 "error during encryption - message not sent"); 813 break; 814 case OTRL_MSGEVENT_CONNECTION_ENDED: 815 display_otr_message(opdata, ctx, 816 "other end has disconnected OTR - " 817 "close connection or reconnect!"); 818 break; 819 case OTRL_MSGEVENT_SETUP_ERROR: 820 display_otr_message(opdata, ctx, 821 "OTR connection failed: %s", gcry_strerror(err)); 822 break; 823 case OTRL_MSGEVENT_MSG_REFLECTED: 824 display_otr_message(opdata, ctx, 825 "received our own OTR message (!?)"); 826 break; 827 case OTRL_MSGEVENT_MSG_RESENT: 828 display_otr_message(opdata, ctx, 829 "the previous message was resent"); 830 break; 831 case OTRL_MSGEVENT_RCVDMSG_NOT_IN_PRIVATE: 832 display_otr_message(opdata, ctx, 833 "unexpected encrypted message received"); 834 break; 835 case OTRL_MSGEVENT_RCVDMSG_UNREADABLE: 836 display_otr_message(opdata, ctx, 837 "unreadable encrypted message received"); 838 break; 839 case OTRL_MSGEVENT_RCVDMSG_MALFORMED: 840 display_otr_message(opdata, ctx, 841 "malformed OTR message received"); 842 break; 843 case OTRL_MSGEVENT_RCVDMSG_GENERAL_ERR: 844 display_otr_message(opdata, ctx, 845 "OTR error message received: %s", message); 846 break; 847 case OTRL_MSGEVENT_RCVDMSG_UNENCRYPTED: 848 display_otr_message(opdata, ctx, 849 "unencrypted message received: %s", message); 850 break; 851 case OTRL_MSGEVENT_RCVDMSG_UNRECOGNIZED: 852 display_otr_message(opdata, ctx, 853 "unrecognized OTR message received"); 854 break; 855 default: 856 /* ignore XXX log? */ 823 857 break; 824 858 } … … 1195 1229 /*** local helpers / subroutines: ***/ 1196 1230 1231 void log_otr_message(void *opdata, const char *fmt, ...) 1232 { 1233 va_list va; 1234 1235 va_start(va, fmt); 1236 char *msg = g_strdup_vprintf(fmt, va); 1237 va_end(va); 1238 1239 log_message(LOGLVL_INFO, "otr: %s", msg); 1240 } 1241 1242 void display_otr_message(void *opdata, ConnContext *ctx, const char *fmt, ...) 1243 { 1244 struct im_connection *ic = 1245 check_imc(opdata, ctx->accountname, ctx->protocol); 1246 irc_t *irc = ic->bee->ui_data; 1247 irc_user_t *u = peeruser(irc, ctx->username, ctx->protocol); 1248 va_list va; 1249 1250 va_start(va, fmt); 1251 char *msg = g_strdup_vprintf(fmt, va); 1252 va_end(va); 1253 1254 if(u) { 1255 /* display as a notice from this particular user */ 1256 irc_usernotice(u, "%s", msg); 1257 } else { 1258 irc_rootmsg(irc, "[otr] %s", msg); 1259 } 1260 1261 g_free(msg); 1262 } 1263 1197 1264 /* combined handler for the 'otr smp' and 'otr smpq' commands */ 1198 1265 void otr_smp_or_smpq(irc_t *irc, const char *nick, const char *question,
Note: See TracChangeset
for help on using the changeset viewer.