コード例 #1
0
ファイル: module.c プロジェクト: ahf/irssi-otr
/*
 * 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;
}
コード例 #2
0
ファイル: FiSH.c プロジェクト: kelek-/FiSH-irssi
void encrypt_msg(SERVER_REC * server, char *target, char *msg,
		 char *orig_target)
{
	char bf_dest[800] = "", *plainMsg;
	char contactName[CONTACT_SIZE] = "";

	if (IsNULLorEmpty(msg) || IsNULLorEmpty(target))
		return;

	if (getIniSectionForContact(server, target, contactName) == FALSE)
		return;

	if (getContactKey(contactName, NULL) == FALSE)
		return;

	plainMsg = isPlainPrefix(msg);
	if (plainMsg) {
		signal_continue(4, server, target, plainMsg, orig_target);
		return;
	}
	// generally cut a message to a size of 512 byte, as everything above will never arrive complete anyway
	if (strlen(msg) > 512)
		msg[512] = '\0';

	if (FiSH_encrypt(server, msg, target, bf_dest) == 1) {	// message was encrypted
		bf_dest[512] = '\0';
		signal_continue(4, server, target, bf_dest, orig_target);
	}
}
コード例 #3
0
ファイル: module.c プロジェクト: DrWhax/irssi-otr
/*
 * 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;
}
コード例 #4
0
ファイル: FiSH.c プロジェクト: kelek-/FiSH-irssi
/*
 * format outgoing (encrypted) messages (add crypt-mark or remove plain-prefix)
 */
void format_msg(SERVER_REC * server, char *msg, char *target, char *orig_target)
{
	char contactName[CONTACT_SIZE] = "", myMark[20] =
	    "", formattedMsg[800] = "";
	int i, markPos;
	char *plainMsg;

	if (IsNULLorEmpty(msg) || IsNULLorEmpty(target))
		return;

	if (settings_get_bool("process_outgoing") == 0)
		return;

	if (getIniSectionForContact(server, target, contactName) == FALSE)
		return;

	if (getContactKey(contactName, NULL) == FALSE)
		return;

	plainMsg = isPlainPrefix(msg);
	if (plainMsg) {
		signal_continue(4, server, plainMsg, target, orig_target);
		return;
	}
	// generally cut a message to a size of 512 byte, as everything above will never arrive complete anyway
	if (strlen(msg) > 512)
		msg[512] = '\0';

	// append crypt-mark?
	strncpy(myMark, settings_get_str("mark_encrypted"), sizeof(myMark));
	if (*myMark != '\0') {
		strcpy(formattedMsg, msg);
		markPos = settings_get_int("mark_position");
		if (markPos == 0)
			strcat(formattedMsg, myMark);	//append mark at the end
		else {		// prefix mark
			i = strlen(myMark);
			memmove(formattedMsg + i, formattedMsg,
				strlen(formattedMsg) + 1);
			strncpy(formattedMsg, myMark, i);
		}

		signal_continue(4, server, formattedMsg, target, orig_target);

		ZeroMemory(formattedMsg, sizeof(formattedMsg));
	}

	return;
}
コード例 #5
0
ファイル: FiSH.c プロジェクト: hugopeixoto/FiSH-irssi
/*
 * format outgoing (encrypted) messages (add crypt-mark or remove plain-prefix)
 */
void format_msg(SERVER_REC *server, char *msg, char *target, char *orig_target)
{
    char contactName[CONTACT_SIZE]="", myMark[20]="", markPos[20]="", formattedMsg[800]="";
    int i;
    char *plainMsg;


    if (IsNULLorEmpty(msg) || IsNULLorEmpty(target)) return;
    if (GetBlowIniSwitch("FiSH", "process_outgoing", "1") == 0) return;

    if (GetIniSectionForContact(server, target, contactName)==FALSE) return;

    if (LoadKeyForContact(contactName, NULL)==FALSE) return;


    plainMsg = IsPlainPrefix(msg);
    if (plainMsg) {
        signal_continue(4, server, plainMsg, target, orig_target);
        return;
    }


    // generally cut a message to a size of 512 byte, as everything above will never arrive complete anyway
    if (strlen(msg) > 512) msg[512]='\0';


    // append crypt-mark?
    if (GetBlowIniSwitch(contactName, "mark_encrypted", "1") != 0) {
        GetPrivateProfileString("FiSH", "mark_encrypted", "", myMark, sizeof(myMark), iniPath);	// global setting
        if (*myMark != '\0') {
            strcpy(formattedMsg, msg);

            GetPrivateProfileString("FiSH", "mark_position", "0", markPos, sizeof(markPos), iniPath);
            if (*markPos=='0') strcat(formattedMsg, myMark);		//append mark at the end
            else {	// prefix mark
                i=strlen(myMark);
                memmove(formattedMsg+i, formattedMsg, strlen(formattedMsg)+1);
                strncpy(formattedMsg, myMark, i);
            }

            signal_continue(4, server, formattedMsg, target, orig_target);

            ZeroMemory(formattedMsg, sizeof(formattedMsg));
        }
    }

    return;
}
コード例 #6
0
ファイル: FiSH.c プロジェクト: kelek-/FiSH-irssi
/*
 * Decrypt NOTICE messages (and forward DH1080 key-exchange)
 */
void decrypt_notice(SERVER_REC * server, char *msg, char *nick, char *address,
		    char *target)
{
	GString *decrypted;
	char *DH1024warn;

	if (strncmp(msg, "DH1024_", 7) == 0) {
		DH1024warn =
		    "\002FiSH:\002 Received \002old DH1024\002 public key from you! Please update to latest version: https://github.com/falsovsky/FiSH-irssi";
		signal_stop();
		irc_send_cmdv((IRC_SERVER_REC *) server, "NOTICE %s :%s\n",
			      nick, DH1024warn);
		signal_emit("message irc own_notice", 3, server, DH1024warn,
			    nick);
		return;
	}

	if (strncmp(msg, "DH1080_", 7) == 0) {
		DH1080_received(server, msg, nick, address, target);
		return;
	}
#ifdef FiSH_DECRYPT_ZNC_LOGS
	if (IsZNCtimestamp(msg))
		msg += 11;
#endif

	decrypted = g_string_new("");
	if (FiSH_decrypt(server, msg, ischannel(*target) ? target : nick, decrypted)) {
		signal_continue(5, server, decrypted->str, nick, address, target);
		ZeroMemory(decrypted->str, decrypted->len);
	}
	g_string_free(decrypted, TRUE);
}
コード例 #7
0
ファイル: fe-server.c プロジェクト: easeip/osx-irssi
static void server_command(const char *data, SERVER_REC *server,
			   WI_ITEM_REC *item)
{
	if (server == NULL) {
		/* this command accepts non-connected server too */
		server = active_win->connect_server;
	}

	signal_continue(3, data, server, item);
}
コード例 #8
0
ファイル: FiSH.c プロジェクト: kelek-/FiSH-irssi
void decrypt_topic(SERVER_REC * server, char *channel, char *topic, char *nick,
		   char *address)
{
	GString *decrypted;

	decrypted = g_string_new("");
	if (FiSH_decrypt(server, topic, channel, decrypted)) {
		signal_continue(5, server, channel, decrypted->str, nick, address);
		ZeroMemory(decrypted->str, decrypted->len);
	}
	g_string_free(decrypted, TRUE);
}
コード例 #9
0
ファイル: FiSH.c プロジェクト: kelek-/FiSH-irssi
void decrypt_changed_topic(CHANNEL_REC * chan_rec)
{
	GString *decrypted;

	decrypted = g_string_new("");
	if (FiSH_decrypt(chan_rec->server, chan_rec->topic,
		     chan_rec->name, decrypted)) {
		g_free_not_null(chan_rec->topic);
		chan_rec->topic = g_strdup(decrypted->str);
		signal_continue(1, chan_rec);
		ZeroMemory(decrypted->str, decrypted->len);
	}
	g_string_free(decrypted, TRUE);
}
コード例 #10
0
ファイル: FiSH.c プロジェクト: kelek-/FiSH-irssi
void decrypt_action(SERVER_REC * server, char *msg, char *nick, char *address,
		    char *target)
{
	GString *decrypted;
	if (target == NULL)
		return;

	decrypted = g_string_new("");
	if (FiSH_decrypt(server, msg, ischannel(*target) ? target : nick, decrypted)) {
		signal_continue(5, server, decrypted->str, nick, address, target);
		ZeroMemory(decrypted->str, decrypted->len);
	}
	g_string_free(decrypted, TRUE);
}
コード例 #11
0
ファイル: module.c プロジェクト: ahf/irssi-otr
/*
 * 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;
}
コード例 #12
0
ファイル: FiSH.c プロジェクト: kelek-/FiSH-irssi
void raw_handler(SERVER_REC * server, char *data)
{
	GString *decrypted;
	char channel[CONTACT_SIZE], *ptr, *ptr_bak;
	int len;

	if (IsNULLorEmpty(data))
		return;

	ptr = strchr(data, ' ');	// point to command
	if (ptr == NULL)
		return;
	ptr++;

	if (strncmp(ptr, "332 ", 4) != 0)
		return;		// 332 = TOPIC

	ptr_bak = ptr;
	ptr = strchr(ptr, '#');	// point to #channel
	if (ptr == NULL) {
		ptr = strchr(ptr_bak, '&');	// point to &channel
		if (ptr == NULL) {
			ptr = strchr(ptr_bak, '!');	// point to !channel
			if (ptr == NULL)
				return;
		}
	}

	len = strchr(ptr, ' ') - ptr;
	if (len >= CONTACT_SIZE - 2)
		return;		// channel string too long, something went wrong
	strncpy(channel, ptr, len);
	channel[len] = '\0';

	ptr = strchr(ptr, ':');	// point to topic msg start
	if (ptr == NULL)
		return;
	ptr++;

	decrypted = g_string_new("");
	if (FiSH_decrypt(server, ptr, channel, decrypted)) {
		g_string_prepend_len(decrypted, data, strlen(data) - strlen(ptr));
		signal_continue(2, server, decrypted->str);
		ZeroMemory(decrypted->str, decrypted->len);
	}
	g_string_free(decrypted, TRUE);
}
コード例 #13
0
ファイル: FiSH.c プロジェクト: kelek-/FiSH-irssi
void decrypt_msg(SERVER_REC * server, char *msg, const char *nick,
		 const char *address, const char *target)
{
	GString *decrypted;
	const char *contactPtr, *msg_bak = msg;
	char contactName[CONTACT_SIZE] = "";

	if (msg == NULL || target == NULL || nick == NULL)
		return;

#ifdef FiSH_DECRYPT_ZNC_LOGS
	if (IsZNCtimestamp(msg))
		msg += 11;
#endif

	//channel?
	if (ischannel(*target))
		contactPtr = target;
	else if (strcmp(nick, "-psyBNC") == 0) {	// psyBNC log message found             // <-psyBNC> Nw~Thu Mar 29 15:02:45 :([email protected]) +OK e3454451hbadA0

		msg = strstr(msg, " :(") + 3;	// points to nick!ident@host in psybnc log
		if (msg == (char *)3)
			return;
		ExtractRnick(contactName, msg);
		msg = strchr(msg, ' ') + 1;
		if (msg == (char *)1)
			return;
		contactPtr = contactName;
	} else if (strcmp(nick, "-sBNC") == 0) {	// sBNC log message found (PRIVMSG)             // <-sBNC> Sun Sep  1 13:37:00 2007 someone ([email protected]): +OK Mp1p8.qYxFN1

		if ((msg = strstr(msg, " (")) == NULL)
			return;
		else
			msg--;	// points to the last char of the nick

		while (*msg != '\0' && *msg != ' ' && msg > msg_bak)
			msg--;

		if (*msg == ' ')
			msg++;	// now points to the first char of the nick
		else
			return;

		ExtractRnick(contactName, msg);

		if ((msg = strstr(msg, "): ")) == NULL)
			return;	// find metadata end
		msg += 3;	// now points to encrypted message

		contactPtr = contactName;
	} else
		contactPtr = nick;

	decrypted = g_string_new("");
	if (FiSH_decrypt(server, msg, contactPtr, decrypted)) {
		if (strncmp(decrypted->str, "\001ACTION ", 8) == 0) {
			// ACTION message found
			signal_stop();
			signal_emit("message irc action", 5, server,
					decrypted->str + 8, nick, address, target);
		}
		else {
			signal_continue(5, server, decrypted->str, nick, address, target);
		}
		ZeroMemory(decrypted->str, decrypted->len);
	}
	g_string_free(decrypted, TRUE);
}