Skip to content

Commit

Permalink
Merge remote-tracking branch 'tronic/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
dgoulet committed Mar 25, 2016
2 parents 4ad3b7b + 565e760 commit bd0e3bf
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/module.c
Expand Up @@ -26,6 +26,7 @@
#include <glib/gstdio.h>
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>

#include "cmd.h"
#include "key.h"
Expand Down
3 changes: 3 additions & 0 deletions src/otr.c
Expand Up @@ -363,6 +363,9 @@ int otr_send(SERVER_REC *irssi, const char *msg, const char *to, char **otr_msg)
IRSSI_NOTICE(irssi, to, "Send failed.");
goto error;
}

/* Modify some libotr messages (OTR init in particular) to work better with IRC. */
if (*otr_msg) utils_escape_message(*otr_msg);

IRSSI_DEBUG("Message sent...");

Expand Down
4 changes: 4 additions & 0 deletions src/otr.h
Expand Up @@ -54,6 +54,10 @@
#define OTR_MSG_BEGIN_TAG "?OTR:"
#define OTR_MSG_END_TAG '.'

#define OTR_MSG_HELP " This is a request for an Off-the-Record private conversation. "\
"However, you do not have a plugin to support that. If you are using Irssi, "\
"please install irssi-otr (irssi-plugin-otr).";

/* IRC /me command marker and len. */
#define OTR_IRC_MARKER_ME "/me "
#define OTR_IRC_MARKER_ME_LEN sizeof(OTR_IRC_MARKER_ME) - 1
Expand Down
19 changes: 19 additions & 0 deletions src/utils.c
Expand Up @@ -73,6 +73,25 @@ char *utils_trim_string(char *s)
return rtrim(ltrim(s));
}

/*
* Convert invalid characters (newlines from libotr) into spaces.
* Also change the init help string because IRC does not support HTML.
*/
char *utils_escape_message(char *s) {
char const* helpmsg = OTR_MSG_HELP;
size_t i;
if (strncmp(s, "?OTR", 4) == 0 && strstr(s, "</b> has requested an <a href")) {
i = strcspn(s, "\n");
if (i + strlen(helpmsg) <= strlen(s)) {
strcpy(s + i, helpmsg);
}
}
for (i = 0; s[i]; ++i) {
if (s[i] == '\n' || s[i] == '\r') s[i] = ' ';
}
return s;
}

/*
* Extract question and secret for an SMP authentication.
*
Expand Down
1 change: 1 addition & 0 deletions src/utils.h
Expand Up @@ -29,5 +29,6 @@ void utils_string_to_upper(char *string);
int utils_auth_extract_secret(const char *_data, char **secret);
void utils_hash_parts_to_readable_hash(const char **parts, char *dst);
char *utils_trim_string(char *s);
char *utils_escape_message(char *s);

#endif /* IRSSI_OTR_UTILS_H */

0 comments on commit bd0e3bf

Please sign in to comment.