/* * Pipes all outgoing private messages through OTR */ static void sig_server_sendmsg(SERVER_REC *server, const char *target, const char *msg, void *target_type_p) { int ret; char *otrmsg = NULL; key_gen_check(); if (GPOINTER_TO_INT(target_type_p) != SEND_TARGET_NICK) { goto end; } /* Critical section. On error, message MUST NOT be sent */ ret = otr_send(server, msg, target, &otrmsg); if (ret) { signal_stop(); goto end; } if (!otrmsg) { /* Send original message */ signal_continue(4, server, target, msg, target_type_p); } else { /* Send encrypted message */ signal_continue(4, server, target, otrmsg, target_type_p); } end: otrl_message_free(otrmsg); return; }
/* * Handle the "/otr" command. */ static void cmd_otr(const char *data, void *server, WI_ITEM_REC *item) { char *cmd = NULL; QUERY_REC *query; query = QUERY(item); /* Check key generation state. */ key_gen_check(); if (*data == '\0') { IRSSI_INFO(NULL, NULL, "Alive!"); goto end; } utils_extract_command(data, &cmd); if (!cmd) { /* ENOMEM and cmd is untouched. */ goto end; } if (query && query->server && query->server->connrec) { cmd_generic(user_state_global, query->server, query->name, cmd, data); } else { cmd_generic(user_state_global, NULL, NULL, cmd, data); } statusbar_items_redraw("otr"); free(cmd); end: return; }
/* * Pipes all incoming private messages through OTR */ void sig_message_private(SERVER_REC *server, const char *msg, const char *nick, const char *address) { int ret; char *new_msg = NULL; key_gen_check(); ret = otr_receive(server, msg, nick, &new_msg); if (ret) { signal_stop(); goto end; } if (!new_msg) { /* This message was not OTR */ signal_continue(4, server, msg, nick, address); } else { /* OTR received message */ signal_continue(4, server, new_msg, nick, address); } end: otrl_message_free(new_msg); return; }
/* * Handle /me IRC command. */ static void cmd_me(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item) { int ret; const char *target; char *msg, *otrmsg = NULL; QUERY_REC *query; query = QUERY(item); key_gen_check(); if (!query || !query->server) { goto end; } CMD_IRC_SERVER(server); if (!IS_IRC_QUERY(query)) { goto end; } if (!server || !server->connected) { cmd_return_error(CMDERR_NOT_CONNECTED); } target = window_item_get_target(item); ret = asprintf(&msg, OTR_IRC_MARKER_ME "%s", data); if (ret < 0) { goto end; } /* Critical section. On error, message MUST NOT be sent */ ret = otr_send(query->server, msg, target, &otrmsg); free(msg); if (!otrmsg) { goto end; } signal_stop(); if (otrmsg) { /* Send encrypted message */ irssi_send_message(SERVER(server), target, otrmsg); otrl_message_free(otrmsg); } signal_emit("message irc own_action", 3, server, data, item->visible_name); end: return; }
/* * Pipes all incoming private messages through OTR */ void sig_message_private(SERVER_REC *server, const char *msg, const char *nick, const char *address) { int ret; char *new_msg = NULL; key_gen_check(); ret = otr_receive(server, msg, nick, &new_msg); if (ret) { signal_stop(); goto end; } if (!new_msg) { /* This message was not OTR */ signal_continue(4, server, msg, nick, address); } else { /* * Check for /me IRC marker and if so, handle it so the user does not * receive a message beginning with /me but rather let irssi handle it * as a IRC action. */ if (!strncmp(new_msg, OTR_IRC_MARKER_ME, OTR_IRC_MARKER_ME_LEN)) { signal_stop(); signal_emit("message irc action", 5, server, new_msg + OTR_IRC_MARKER_ME_LEN, nick, address, nick); } else { /* OTR received message */ signal_continue(4, server, new_msg, nick, address); } } end: otrl_message_free(new_msg); return; }