[Pkg-privacy-commits] [irssi-plugin-otr] 82/267: uncrustified.
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 12:41:30 UTC 2015
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch debian
in repository irssi-plugin-otr.
commit 1c1d592902ca6802a480ae012f381d4f187862d1
Author: Uli Meis <a.sporto+bee at gmail.com>
Date: Fri Sep 14 22:07:10 2012 +0200
uncrustified.
This patch also contains the used configuration file for uncrustify.
Maybe I should install this as a pre-commit hook or something.
http://irc-otr.tuxfamily.org/bugs/show_bug.cgi?id=2
---
.uncrustify.cfg | 105 +++++++++++++
io_set.c | 32 ++--
io_util.c | 182 ++++++++++++----------
irssi/irssi_otr.c | 194 +++++++++++------------
irssi/irssi_otr.h | 38 +++--
otr.h | 62 ++++----
otr_key.c | 130 +++++++++-------
otr_ops.c | 161 ++++++++++----------
otr_util.c | 414 ++++++++++++++++++++++++++------------------------
weechat/weechat_otr.c | 225 ++++++++++++++-------------
weechat/weechat_otr.h | 78 +++++-----
xchat/xchat_otr.c | 98 ++++++------
xchat/xchat_otr.h | 34 +++--
13 files changed, 989 insertions(+), 764 deletions(-)
diff --git a/.uncrustify.cfg b/.uncrustify.cfg
new file mode 100644
index 0000000..5591dfa
--- /dev/null
+++ b/.uncrustify.cfg
@@ -0,0 +1,105 @@
+#
+# K&R (sort-of)
+#
+# minor modifications
+#
+
+indent_with_tabs = 2 # 1=indent to level only, 2=indent with tabs
+input_tab_size = 8 # original tab size
+output_tab_size = 8 # new tab size
+indent_columns = output_tab_size
+indent_label = 2 # pos: absolute col, neg: relative column
+#indent_var_def_cont = true
+#indent_continue = 4
+indent_class = true
+
+# indent_align_string = False # align broken strings
+# indent_brace = 0
+
+nl_enum_brace = remove # "enum {" vs "enum \n {"
+nl_union_brace = remove # "union {" vs "union \n {"
+nl_struct_brace = remove # "struct {" vs "struct \n {"
+nl_do_brace = remove # "do {" vs "do \n {"
+nl_if_brace = remove # "if () {" vs "if () \n {"
+nl_for_brace = remove # "for () {" vs "for () \n {"
+nl_else_brace = remove # "else {" vs "else \n {"
+nl_while_brace = remove # "while () {" vs "while () \n {"
+nl_switch_brace = remove # "switch () {" vs "switch () \n {"
+# nl_func_var_def_blk = 1
+# nl_before_case = 1
+nl_fcall_brace = add # "foo() {" vs "foo()\n{"
+nl_fdef_brace = add # "int foo() {" vs "int foo()\n{"
+# nl_after_return = TRUE
+nl_brace_while = remove
+nl_brace_else = remove
+nl_squeeze_ifdef = TRUE
+
+# Don't split one-line braced statements inside a class xx { } body
+nl_class_leave_one_liners = true # false/true
+# Don't split one-line function definitions - 'int foo() { return 0; }'
+nl_func_leave_one_liners = true # false/true
+# Whether to collapse empty blocks between '{' and '}'
+nl_collapse_empty_body = true # false/true
+# ^^
+
+# mod_paren_on_return = add # "return 1;" vs "return (1);"
+# mod_full_brace_if = add # "if (a) a--;" vs "if (a) { a--; }"
+# mod_full_brace_for = add # "for () a--;" vs "for () { a--; }"
+# mod_full_brace_do = add # "do a--; while ();" vs "do { a--; } while ();"
+# mod_full_brace_while = add # "while (a) a--;" vs "while (a) { a--; }"
+
+sp_before_semi = remove
+sp_paren_paren = remove # space between (( and ))
+sp_return_paren = remove # "return (1);" vs "return(1);"
+sp_sizeof_paren = remove # "sizeof (int)" vs "sizeof(int)"
+sp_before_sparen = force # "if (" vs "if("
+sp_after_sparen = force # "if () {" vs "if (){"
+sp_after_cast = remove # "(int) a" vs "(int)a"
+sp_inside_braces = force # "{ 1 }" vs "{1}"
+sp_inside_braces_struct = force # "{ 1 }" vs "{1}"
+sp_inside_braces_enum = force # "{ 1 }" vs "{1}"
+sp_inside_paren = remove # "( 1 )" vs "(1)"
+sp_inside_fparen = remove # "( 1 )" vs "(1)" - functions
+sp_inside_sparen = remove # "( 1 )" vs "(1)" - if/for/etc
+# sp_type_func = ignore
+sp_assign = force
+sp_arith = force
+sp_bool = force
+sp_compare = force
+sp_after_comma = force
+sp_func_def_paren = remove # "int foo (){" vs "int foo(){"
+sp_func_call_paren = remove # "foo (" vs "foo("
+sp_func_proto_paren = remove # "int foo ();" vs "int foo();"
+
+# align_with_tabs = FALSE # use tabs to align
+# align_on_tabstop = FALSE # align on tabstops
+# align_enum_equ_span = 4
+# align_nl_cont = TRUE
+# align_var_def_span = 2
+# align_var_def_inline = TRUE
+# align_var_def_star = TRUE
+# align_var_def_colon = TRUE
+# align_assign_span = 1
+# align_struct_init_span = 3
+# align_var_struct_span = 3
+# align_right_cmt_span = 3
+# align_pp_define_span = 3
+# align_pp_define_gap = 4
+# align_number_left = TRUE
+# align_typedef_span = 5
+# align_typedef_gap = 3
+
+# cmt_star_cont = TRUE
+
+eat_blanks_before_close_brace = TRUE
+eat_blanks_after_open_brace = TRUE
+
+# Try to limit code width to N number of columns
+code_width = 78 # number
+cmt_width = 80 # number
+
+# Whether to fully split long 'for' statements at semi-colons
+ls_for_split_full = false # false/true
+
+# Whether to fully split long function protos/calls at commas
+ls_func_split_full = false # false/true
diff --git a/io_set.c b/io_set.c
index 997e078..93e5413 100644
--- a/io_set.c
+++ b/io_set.c
@@ -28,8 +28,10 @@ char set_policy_known[512] = IO_DEFAULT_POLICY_KNOWN;
char set_ignore[512] = IO_DEFAULT_IGNORE;
int set_finishonunload = TRUE;
-void cmd_set(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
- char *target) {
+void cmd_set(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
+ char *argv_eol[],
+ char *target)
+{
char *setting, *value;
if (argc) {
@@ -38,25 +40,25 @@ void cmd_set(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *
}
if (!argc) {
- otr_logst(MSGLEVEL_CRAP,"policy: %s\n"
+ otr_logst(MSGLEVEL_CRAP, "policy: %s\n"
"policy_known: %s\nignore: %s\n"
"finishonunload: %s\n",
- set_policy,set_policy_known,set_ignore,
+ set_policy, set_policy_known, set_ignore,
set_finishonunload ? "true" : "false");
- } else if (strcmp(setting,"policy")==0) {
- otr_setpolicies(ioustate,value,FALSE);
- strcpy(set_policy,value);
- } else if (strcmp(setting,"policy_known")==0) {
- otr_setpolicies(ioustate,value,TRUE);
- strcpy(set_policy_known,value);
- } else if (strcmp(setting,"ignore")==0) {
+ } else if (strcmp(setting, "policy") == 0) {
+ otr_setpolicies(ioustate, value, FALSE);
+ strcpy(set_policy, value);
+ } else if (strcmp(setting, "policy_known") == 0) {
+ otr_setpolicies(ioustate, value, TRUE);
+ strcpy(set_policy_known, value);
+ } else if (strcmp(setting, "ignore") == 0) {
#ifdef HAVE_GREGEX_H
if (regex_nickignore)
g_regex_unref(regex_nickignore);
- regex_nickignore = g_regex_new(value,0,0,NULL);
- strcpy(set_ignore,value);
+ regex_nickignore = g_regex_new(value, 0, 0, NULL);
+ strcpy(set_ignore, value);
#endif
- } else if (strcmp(setting,"finishonunload")==0) {
- set_finishonunload = (strcasecmp(value,"true")==0);
+ } else if (strcmp(setting, "finishonunload") == 0) {
+ set_finishonunload = (strcasecmp(value, "true") == 0);
}
}
diff --git a/io_util.c b/io_util.c
index ca021f8..4d1c71b 100644
--- a/io_util.c
+++ b/io_util.c
@@ -63,16 +63,16 @@ int extract_nick(char *nick, char *line)
if (*line++ != ':')
return FALSE;
- strcpy(nick,line);
-
- if ((excl = strchr(nick,'!')))
+ strcpy(nick, line);
+
+ if ((excl = strchr(nick, '!')))
*excl = '\0';
return TRUE;
-
}
-int cmd_generic(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
+int cmd_generic(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
+ char *argv_eol[],
char *target)
{
char *cmd;
@@ -88,10 +88,12 @@ int cmd_generic(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], cha
argv++;
argv_eol++;
argc--;
-
+
do {
- if (strcmp(commands->name,cmd)==0) {
- commands->cmdfunc(ioustate,ircctx,argc,argv,argv_eol,target);
+ if (strcmp(commands->name, cmd) == 0) {
+ commands->cmdfunc(ioustate, ircctx, argc, argv,
+ argv_eol,
+ target);
return TRUE;
}
} while ((++commands)->name);
@@ -99,60 +101,73 @@ int cmd_generic(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], cha
return FALSE;
}
-void cmd_debug(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
- char *target) {
+void cmd_debug(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
+ char *argv_eol[],
+ char *target)
+{
debug = !debug;
otr_noticest(debug ? TXT_CMD_DEBUG_ON : TXT_CMD_DEBUG_OFF);
}
-void cmd_version(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
- char *target) {
- otr_noticest(TXT_CMD_VERSION,IRCOTR_VERSION);
+void cmd_version(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
+ char *argv_eol[],
+ char *target)
+{
+ otr_noticest(TXT_CMD_VERSION, IRCOTR_VERSION);
}
-void cmd_help(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
- char *target) {
- otr_log(ircctx,target,MSGLEVEL_CRAP,otr_help);
+void cmd_help(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
+ char *argv_eol[],
+ char *target)
+{
+ otr_log(ircctx, target, MSGLEVEL_CRAP, otr_help);
}
-void cmd_finish(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
- char *target) {
+void cmd_finish(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
+ char *argv_eol[],
+ char *target)
+{
if (argc)
- otr_finish(NULL,NULL,argv[0],TRUE);
- else if (ircctx&&target)
- otr_finish(ircctx,target,NULL,TRUE);
+ otr_finish(NULL, NULL, argv[0], TRUE);
+ else if (ircctx && target)
+ otr_finish(ircctx, target, NULL, TRUE);
else
otr_noticest(TXT_CMD_QNOTFOUND);
-
}
-void cmd_trust(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
- char *target) {
+void cmd_trust(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
+ char *argv_eol[],
+ char *target)
+{
if (argc)
- otr_trust(NULL,NULL,argv[0]);
- else if (ircctx&&target)
- otr_trust(ircctx,target,NULL);
+ otr_trust(NULL, NULL, argv[0]);
+ else if (ircctx && target)
+ otr_trust(ircctx, target, NULL);
else
otr_noticest(TXT_CMD_QNOTFOUND);
}
-void cmd_authabort(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
- char *target) {
+void cmd_authabort(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc,
+ char *argv[], char *argv_eol[],
+ char *target)
+{
if (argc)
- otr_authabort(NULL,NULL,argv[0]);
- else if (ircctx&&target)
- otr_authabort(ircctx,target,NULL);
+ otr_authabort(NULL, NULL, argv[0]);
+ else if (ircctx && target)
+ otr_authabort(ircctx, target, NULL);
else
otr_noticest(TXT_CMD_QNOTFOUND);
}
-void cmd_genkey(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
- char *target) {
+void cmd_genkey(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
+ char *argv_eol[],
+ char *target)
+{
if (argc) {
- if (strcmp(argv[0],"abort")==0)
- keygen_abort(ioustate,FALSE);
- else if (strchr(argv[0],'@'))
- keygen_run(ioustate,argv[0]);
+ if (strcmp(argv[0], "abort") == 0)
+ keygen_abort(ioustate, FALSE);
+ else if (strchr(argv[0], '@'))
+ keygen_run(ioustate, argv[0]);
else
otr_noticest(TXT_KG_NEEDACC);
} else {
@@ -160,72 +175,81 @@ void cmd_genkey(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], cha
}
}
-void _cmd_auth(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
- char *target, int qanda) {
+void _cmd_auth(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
+ char *argv_eol[],
+ char *target,
+ int qanda)
+{
char *accountname = NULL;
char *question = NULL;
char *secret;
/* have args? */
- if (argc<(qanda ? 2 : 1)) {
- otr_notice(ircctx,target,
+ if (argc < (qanda ? 2 : 1)) {
+ otr_notice(ircctx, target,
TXT_CMD_AUTH);
return;
}
/* have buddy? */
- if (!(ircctx&&target)) {
- accountname = strchr(argv[0],'@');
+ if (!(ircctx && target)) {
+ accountname = strchr(argv[0], '@');
if (!accountname) {
otr_noticest(TXT_CMD_QNOTFOUND);
return;
}
ircctx = NULL;
target = NULL;
- argv++;argv_eol++;argc--;
+ argv++; argv_eol++; argc--;
}
/* have question? */
if (qanda) {
question = argv[0];
- argv++;argv_eol++;argc--;
+ argv++; argv_eol++; argc--;
}
- secret = argv_eol[0];
+ secret = argv_eol[0];
- otr_auth(ircctx,target,accountname,question,secret);
+ otr_auth(ircctx, target, accountname, question, secret);
}
-void cmd_authq(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
- char *target) {
- _cmd_auth(ioustate,ircctx,argc,argv,argv_eol,target,TRUE);
+void cmd_authq(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
+ char *argv_eol[],
+ char *target)
+{
+ _cmd_auth(ioustate, ircctx, argc, argv, argv_eol, target, TRUE);
}
-void cmd_auth(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
- char *target) {
- _cmd_auth(ioustate,ircctx,argc,argv,argv_eol,target,FALSE);
+void cmd_auth(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
+ char *argv_eol[],
+ char *target)
+{
+ _cmd_auth(ioustate, ircctx, argc, argv, argv_eol, target, FALSE);
}
/*
* /otr contexts
*/
-void cmd_contexts(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
- char *target) {
- struct ctxlist_ *ctxlist = otr_contexts(ioustate),*ctxnext = ctxlist;
- struct fplist_ *fplist,*fpnext;
+void cmd_contexts(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
+ char *argv_eol[],
+ char *target)
+{
+ struct ctxlist_ *ctxlist = otr_contexts(ioustate), *ctxnext = ctxlist;
+ struct fplist_ *fplist, *fpnext;
if (!ctxlist)
otr_infost(TXT_CTX_NOCTXS);
while (ctxlist) {
- otr_infost(TXT_CTX_CTX_UNENCRYPTED+ctxlist->state,
- ctxlist->username,
- ctxlist->accountname);
+ otr_infost(TXT_CTX_CTX_UNENCRYPTED + ctxlist->state,
+ ctxlist->username,
+ ctxlist->accountname);
fplist = ctxlist->fplist;
while (fplist) {
- otr_infost(TXT_CTX_FPS_NO+fplist->authby,
- fplist->fp);
+ otr_infost(TXT_CTX_FPS_NO + fplist->authby,
+ fplist->fp);
fplist = fplist->next;
}
ctxlist = ctxlist->next;
@@ -256,31 +280,33 @@ struct _cmds cmds[] = {
{ "genkey", cmd_genkey },
{ "contexts", cmd_contexts },
{ NULL, NULL },
- { NULL, NULL }};
+ { NULL, NULL }
+};
-void io_explode_args(const char *args, char ***argvp, char ***argv_eolp, int *argcp)
+void io_explode_args(const char *args, char ***argvp, char ***argv_eolp,
+ int *argcp)
{
char **argv, **argv_eol;
char *s = (char*)args;
- int argc=1,i;
+ int argc = 1, i;
- while ((s = strchr(s+1,' ')))
- argc++;
+ while ((s = strchr(s + 1, ' ')))
+ argc++;
- argv = (char **)malloc(sizeof(char *)*argc);
- argv_eol = (char **)malloc(sizeof(char *)*argc);
+ argv = (char**)malloc(sizeof(char *) * argc);
+ argv_eol = (char**)malloc(sizeof(char *) * argc);
s = (char*)args;
argv_eol[0] = strdup(args);
i = 0;
- while (++i<argc)
- argv_eol[i] = strchr(argv_eol[i-1],' ')+1;
+ while (++i < argc)
+ argv_eol[i] = strchr(argv_eol[i - 1], ' ') + 1;
- argv[0] = strtok(strdup(args)," ");
+ argv[0] = strtok(strdup(args), " ");
i = 1;
- while (i<argc) {
- argv[i++] = strtok(NULL," ");
- otr_logst(MSGLEVEL_CRAP,"arg %d: %s",i,argv[i-1]);
+ while (i < argc) {
+ argv[i++] = strtok(NULL, " ");
+ otr_logst(MSGLEVEL_CRAP, "arg %d: %s", i, argv[i - 1]);
}
*argvp = argv;
@@ -293,9 +319,9 @@ void io_explode_args(const char *args, char ***argvp, char ***argv_eolp, int *ar
*/
int otr_getstatus_format(IRC_CTX *ircctx, const char *nick)
{
- int status = otr_getstatus(ircctx,nick);
+ int status = otr_getstatus(ircctx, nick);
- if (status&(IO_ST_SMP_ONGOING)) {
+ if (status & (IO_ST_SMP_ONGOING)) {
/* we don't care about the trust level in that case */
status = status & IO_ST_SMP_ONGOING;
}
diff --git a/irssi/irssi_otr.c b/irssi/irssi_otr.c
index 4bee5a8..1acc082 100644
--- a/irssi/irssi_otr.c
+++ b/irssi/irssi_otr.c
@@ -22,7 +22,8 @@
int debug = FALSE;
static const char *signal_args_otr_event[] = {
- "iobject", "string", "string", "NULL" };
+ "iobject", "string", "string", "NULL"
+};
#ifdef HAVE_GREGEX_H
GRegex *regex_nickignore = NULL;
@@ -34,9 +35,10 @@ void perl_signal_register(const char *signal, const char **args);
static IOUSTATE *ioustate;
-void irc_send_message(IRC_CTX *ircctx, const char *recipient, char *msg) {
+void irc_send_message(IRC_CTX *ircctx, const char *recipient, char *msg)
+{
ircctx->send_message(
- ircctx,recipient,msg,GPOINTER_TO_INT(SEND_TARGET_NICK));
+ ircctx, recipient, msg, GPOINTER_TO_INT(SEND_TARGET_NICK));
}
/*
@@ -45,16 +47,17 @@ void irc_send_message(IRC_CTX *ircctx, const char *recipient, char *msg) {
static void sig_server_sendmsg(SERVER_REC *server, const char *target,
const char *msg, void *target_type_p)
{
- if (GPOINTER_TO_INT(target_type_p)==SEND_TARGET_NICK) {
+ if (GPOINTER_TO_INT(target_type_p) == SEND_TARGET_NICK) {
char *otrmsg;
#ifdef HAVE_GREGEX_H
- if (g_regex_match(regex_nickignore,target,0,NULL))
+ if (g_regex_match(regex_nickignore, target, 0, NULL))
return;
#endif
- otrmsg = otr_send(server,msg,target);
- if (otrmsg&&(otrmsg!=msg)) {
- signal_continue(4,server,target,otrmsg,target_type_p);
+ otrmsg = otr_send(server, msg, target);
+ if (otrmsg && (otrmsg != msg)) {
+ signal_continue(4, server, target, otrmsg,
+ target_type_p);
otrl_message_free(otrmsg);
} else if (!otrmsg)
signal_stop();
@@ -70,62 +73,62 @@ static void sig_message_private(SERVER_REC *server, const char *msg,
char *newmsg;
#ifdef HAVE_GREGEX_H
- if (g_regex_match(regex_nickignore,nick,0,NULL))
+ if (g_regex_match(regex_nickignore, nick, 0, NULL))
return;
#endif
- newmsg = otr_receive(server,msg,nick);
+ newmsg = otr_receive(server, msg, nick);
- if (newmsg&&(newmsg!=msg)) {
- if (g_str_has_prefix(newmsg,IRCACTIONMARK)) {
+ if (newmsg && (newmsg != msg)) {
+ if (g_str_has_prefix(newmsg, IRCACTIONMARK)) {
signal_stop();
signal_emit("message irc action",
5,
server,
- newmsg+IRCACTIONMARKLEN,
+ newmsg + IRCACTIONMARKLEN,
nick,
address,
nick);
-
} else {
- signal_continue(4,server,newmsg,nick,address);
+ signal_continue(4, server, newmsg, nick, address);
}
otrl_message_free(newmsg);
- } else if (newmsg==NULL)
+ } else if (newmsg == NULL)
signal_stop();
}
-static void cmd_me(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
+static void cmd_me(const char *data, IRC_SERVER_REC *server,
+ WI_ITEM_REC *item)
{
QUERY_REC *query = QUERY(item);
- const char *target;
- char *otrmsg,*msg;
+ const char *target;
+ char *otrmsg, *msg;
int unchanged;
if (!query || !query->server)
return;
- CMD_IRC_SERVER(server);
- if (!IS_IRC_QUERY(item))
- return;
+ CMD_IRC_SERVER(server);
+ if (!IS_IRC_QUERY(item))
+ return;
- if (server == NULL || !server->connected)
- cmd_return_error(CMDERR_NOT_CONNECTED);
+ if (server == NULL || !server->connected)
+ cmd_return_error(CMDERR_NOT_CONNECTED);
- target = window_item_get_target(item);
+ target = window_item_get_target(item);
#ifdef HAVE_GREGEX_H
- if (g_regex_match(regex_nickignore,target,0,NULL))
+ if (g_regex_match(regex_nickignore, target, 0, NULL))
return;
#endif
/* since we can't track the message anymore once it's encrypted,
* mark it as a /me inline.
*/
- msg = g_strconcat(IRCACTIONMARK,data,NULL);
- otrmsg = otr_send(query->server,msg,target);
+ msg = g_strconcat(IRCACTIONMARK, data, NULL);
+ otrmsg = otr_send(query->server, msg, target);
- unchanged = otrmsg==msg;
+ unchanged = otrmsg == msg;
g_free(msg);
if (unchanged)
@@ -138,24 +141,25 @@ static void cmd_me(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
otrl_message_free(otrmsg);
}
- signal_emit("message irc own_action", 3, server, data,
- item->visible_name);
+ signal_emit("message irc own_action", 3, server, data,
+ item->visible_name);
}
/*
* Finish an OTR conversation when its query is closed.
*/
-static void sig_query_destroyed(QUERY_REC *query) {
- if (query&&query->server&&query->server->connrec) {
- otr_finish(query->server,query->name,NULL,FALSE);
+static void sig_query_destroyed(QUERY_REC *query)
+{
+ if (query && query->server && query->server->connrec) {
+ otr_finish(query->server, query->name, NULL, FALSE);
}
}
/*
* /otr
*/
-static void cmd_otr(const char *data,void *server,WI_ITEM_REC *item)
+static void cmd_otr(const char *data, void *server, WI_ITEM_REC *item)
{
char **argv, **argv_eol;
int argc;
@@ -166,12 +170,13 @@ static void cmd_otr(const char *data,void *server,WI_ITEM_REC *item)
return;
}
- io_explode_args(data,&argv,&argv_eol,&argc);
+ io_explode_args(data, &argv, &argv_eol, &argc);
- if (query&&query->server&&query->server->connrec) {
- cmd_generic(ioustate,query->server,argc,argv,argv_eol,query->name);
+ if (query && query->server && query->server->connrec) {
+ cmd_generic(ioustate, query->server, argc, argv, argv_eol,
+ query->name);
} else {
- cmd_generic(ioustate,NULL,argc,argv,argv_eol,NULL);
+ cmd_generic(ioustate, NULL, argc, argv, argv_eol, NULL);
}
statusbar_items_redraw("otr");
@@ -198,21 +203,21 @@ static void otr_statusbar(struct SBAR_ITEM_REC *item, int get_size_only)
{
WI_ITEM_REC *wi = active_win->active;
QUERY_REC *query = QUERY(wi);
- int formatnum=0;
+ int formatnum = 0;
- if (query&&query->server&&query->server->connrec)
- formatnum = otr_getstatus_format(query->server,query->name);
+ if (query && query->server && query->server->connrec)
+ formatnum = otr_getstatus_format(query->server, query->name);
statusbar_item_default_handler(
- item,
- get_size_only,
- formatnum ? formats[formatnum].def : ""," ",FALSE);
+ item,
+ get_size_only,
+ formatnum ? formats[formatnum].def : "", " ", FALSE);
}
void otr_query_create(SERVER_REC *server, const char *nick)
{
- if (!server||!nick||
- !settings_get_bool("otr_createqueries")||
+ if (!server || !nick ||
+ !settings_get_bool("otr_createqueries") ||
query_find(server, nick))
return;
@@ -221,20 +226,20 @@ void otr_query_create(SERVER_REC *server, const char *nick)
static void read_settings(void)
{
- otr_setpolicies(ioustate,settings_get_str("otr_policy"),FALSE);
- otr_setpolicies(ioustate,settings_get_str("otr_policy_known"),TRUE);
+ otr_setpolicies(ioustate, settings_get_str("otr_policy"), FALSE);
+ otr_setpolicies(ioustate, settings_get_str("otr_policy_known"), TRUE);
#ifdef HAVE_GREGEX_H
if (regex_nickignore)
g_regex_unref(regex_nickignore);
- regex_nickignore = g_regex_new(settings_get_str("otr_ignore"),0,0,NULL);
+ regex_nickignore = g_regex_new(settings_get_str(
+ "otr_ignore"), 0, 0, NULL);
#endif
-
}
void otr_status_change(IRC_CTX *ircctx, const char *nick, int event)
{
statusbar_items_redraw("otr");
- signal_emit("otr event",3,ircctx,nick,otr_status_txt[event]);
+ signal_emit("otr event", 3, ircctx, nick, otr_status_txt[event]);
}
/*
@@ -251,28 +256,28 @@ void otr_init(void)
ioustate = otr_init_user("one to rule them all");
- signal_add_first("server sendmsg", (SIGNAL_FUNC) sig_server_sendmsg);
- signal_add_first("message private", (SIGNAL_FUNC) sig_message_private);
- command_bind_irc_first("me", NULL, (SIGNAL_FUNC) cmd_me);
- signal_add("query destroyed", (SIGNAL_FUNC) sig_query_destroyed);
+ signal_add_first("server sendmsg", (SIGNAL_FUNC)sig_server_sendmsg);
+ signal_add_first("message private", (SIGNAL_FUNC)sig_message_private);
+ command_bind_irc_first("me", NULL, (SIGNAL_FUNC)cmd_me);
+ signal_add("query destroyed", (SIGNAL_FUNC)sig_query_destroyed);
- command_bind("otr", NULL, (SIGNAL_FUNC) cmd_otr);
+ command_bind("otr", NULL, (SIGNAL_FUNC)cmd_otr);
- command_bind_first("quit", NULL, (SIGNAL_FUNC) cmd_quit);
+ command_bind_first("quit", NULL, (SIGNAL_FUNC)cmd_quit);
- settings_add_str("otr", "otr_policy",IO_DEFAULT_POLICY);
- settings_add_str("otr", "otr_policy_known",IO_DEFAULT_POLICY_KNOWN);
- settings_add_str("otr", "otr_ignore",IO_DEFAULT_IGNORE);
- settings_add_bool("otr", "otr_finishonunload",TRUE);
- settings_add_bool("otr", "otr_createqueries",TRUE);
+ settings_add_str("otr", "otr_policy", IO_DEFAULT_POLICY);
+ settings_add_str("otr", "otr_policy_known", IO_DEFAULT_POLICY_KNOWN);
+ settings_add_str("otr", "otr_ignore", IO_DEFAULT_IGNORE);
+ settings_add_bool("otr", "otr_finishonunload", TRUE);
+ settings_add_bool("otr", "otr_createqueries", TRUE);
read_settings();
- signal_add("setup changed", (SIGNAL_FUNC) read_settings);
+ signal_add("setup changed", (SIGNAL_FUNC)read_settings);
statusbar_item_register("otr", NULL, otr_statusbar);
statusbar_items_redraw("window");
- perl_signal_register("otr event",signal_args_otr_event);
+ perl_signal_register("otr event", signal_args_otr_event);
}
/*
@@ -284,16 +289,16 @@ void otr_deinit(void)
g_regex_unref(regex_nickignore);
#endif
- signal_remove("server sendmsg", (SIGNAL_FUNC) sig_server_sendmsg);
- signal_remove("message private", (SIGNAL_FUNC) sig_message_private);
- command_unbind("me", (SIGNAL_FUNC) cmd_me);
- signal_remove("query destroyed", (SIGNAL_FUNC) sig_query_destroyed);
+ signal_remove("server sendmsg", (SIGNAL_FUNC)sig_server_sendmsg);
+ signal_remove("message private", (SIGNAL_FUNC)sig_message_private);
+ command_unbind("me", (SIGNAL_FUNC)cmd_me);
+ signal_remove("query destroyed", (SIGNAL_FUNC)sig_query_destroyed);
- command_unbind("otr", (SIGNAL_FUNC) cmd_otr);
+ command_unbind("otr", (SIGNAL_FUNC)cmd_otr);
- command_unbind("quit", (SIGNAL_FUNC) cmd_quit);
+ command_unbind("quit", (SIGNAL_FUNC)cmd_quit);
- signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
+ signal_remove("setup changed", (SIGNAL_FUNC)read_settings);
statusbar_item_unregister("otr");
@@ -309,56 +314,57 @@ void otr_deinit(void)
IRC_CTX *ircctx_by_peername(const char *peername, char *nick)
{
- GSList *tmp;
+ GSList *tmp;
char pname[256];
char *address;
- strcpy(pname,peername);
+ strcpy(pname, peername);
- address = strchr(pname,'@');
+ address = strchr(pname, '@');
if (!address)
return NULL;
*address = '\0';
- strcpy(nick,pname);
+ strcpy(nick, pname);
*address++ = '@';
- for (tmp = servers; tmp != NULL; tmp = tmp->next) {
- SERVER_REC *server = tmp->data;
+ for (tmp = servers; tmp != NULL; tmp = tmp->next) {
+ SERVER_REC *server = tmp->data;
- if (g_strcasecmp(server->connrec->address, address) == 0)
- return server;
- }
+ if (g_strcasecmp(server->connrec->address, address) == 0)
+ return server;
+ }
- return NULL;
+ return NULL;
}
-char *lvlstring[] = {
+char *lvlstring[] = {
"NOTICE",
"DEBUG"
};
-void otr_log(IRC_CTX *server, const char *nick,
- int level, const char *format, ...) {
+void otr_log(IRC_CTX *server, const char *nick,
+ int level, const char *format, ...)
+{
va_list params;
- va_start( params, format );
+ va_start(params, format);
char msg[LOGMAX], *s = msg;
- if ((level==LVL_DEBUG)&&!debug)
+ if ((level == LVL_DEBUG) && !debug)
return;
- s += sprintf(s,"%s","%9OTR%9");
+ s += sprintf(s, "%s", "%9OTR%9");
- if (level!=LVL_NOTICE)
- s += sprintf(s,"(%s)",lvlstring[level]);
+ if (level != LVL_NOTICE)
+ s += sprintf(s, "(%s)", lvlstring[level]);
- s += sprintf(s,": ");
+ s += sprintf(s, ": ");
- if( vsnprintf( s, LOGMAX, format, params ) < 0 )
- sprintf( s, "internal error parsing error string (BUG)" );
- va_end( params );
+ if (vsnprintf(s, LOGMAX, format, params) < 0)
+ sprintf(s, "internal error parsing error string (BUG)");
+ va_end(params);
printtext(server, nick, MSGLEVEL_MSGS, msg);
}
diff --git a/irssi/irssi_otr.h b/irssi/irssi_otr.h
index 024d6ff..a7a6472 100644
--- a/irssi/irssi_otr.h
+++ b/irssi/irssi_otr.h
@@ -42,7 +42,8 @@
static IRC_CTX *IRCCTX_DUP(IRC_CTX *ircctx) __attribute__ ((unused));
-static IRC_CTX *IRCCTX_DUP(IRC_CTX *ircctx) {
+static IRC_CTX *IRCCTX_DUP(IRC_CTX *ircctx)
+{
server_ref(ircctx);
return ircctx;
}
@@ -59,25 +60,30 @@ void otr_query_create(IRC_CTX *ircctx, const char *nick);
#define IRCCTX_ADDR(ircctx) ircctx->connrec->address
#define IRCCTX_NICK(ircctx) ircctx->nick
-#define IRCCTX_ACCNAME(accname,ircctx) sprintf(accname, "%s@%s", ircctx->nick, ircctx->connrec->address)
+#define IRCCTX_ACCNAME(accname, ircctx) sprintf(accname, "%s@%s", \
+ ircctx->nick, \
+ ircctx->connrec->address)
#define IRCCTX_IO_US(ircctx) (&ioustate_uniq)
#define IO_CREATE_US(user) (&ioustate_uniq)
-#define otr_noticest(formatnum,...) \
- printformat(NULL,NULL,MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__)
+#define otr_noticest(formatnum, ...) \
+ printformat(NULL, NULL, MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__)
-#define otr_notice(ircctx,nick,formatnum,...) { \
- otr_query_create(ircctx,nick); \
- printformat(ircctx,nick,MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__);}
+#define otr_notice(ircctx, nick, formatnum, ...) { \
+ otr_query_create(ircctx, nick); \
+ printformat(ircctx, nick, MSGLEVEL_MSGS, formatnum, \
+ ## __VA_ARGS__); }
-#define otr_infost(formatnum,...) \
- printformat(NULL,NULL,MSGLEVEL_CRAP, formatnum, ## __VA_ARGS__)
+#define otr_infost(formatnum, ...) \
+ printformat(NULL, NULL, MSGLEVEL_CRAP, formatnum, ## __VA_ARGS__)
-#define otr_info(server,nick,formatnum,...) { \
- otr_query_create(ircctx,nick); \
- printformat(ircctx,nick,MSGLEVEL_CRAP, formatnum, ## __VA_ARGS__);}
+#define otr_info(server, nick, formatnum, ...) { \
+ otr_query_create(ircctx, nick); \
+ printformat(ircctx, nick, MSGLEVEL_CRAP, formatnum, \
+ ## __VA_ARGS__); }
-#define otr_debug(ircctx,nick,formatnum,...) { \
- if (debug) { \
- otr_query_create(ircctx,nick); \
- printformat(ircctx,nick,MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__); } }
+#define otr_debug(ircctx, nick, formatnum, ...) { \
+ if (debug) { \
+ otr_query_create(ircctx, nick); \
+ printformat(ircctx, nick, MSGLEVEL_MSGS, formatnum, \
+ ## __VA_ARGS__); } }
diff --git a/otr.h b/otr.h
index 58353b9..c52e0ca 100644
--- a/otr.h
+++ b/otr.h
@@ -78,10 +78,10 @@ extern IOUSTATE ioustate_uniq;
#define LVL_NOTICE 0
#define LVL_DEBUG 1
-#define otr_logst(level,format,...) \
- otr_log(NULL,NULL,level,format, ## __VA_ARGS__)
+#define otr_logst(level, format, ...) \
+ otr_log(NULL, NULL, level, format, ## __VA_ARGS__)
-void otr_log(IRC_CTX *server, const char *to,
+void otr_log(IRC_CTX *server, const char *to,
int level, const char *format, ...);
/* own */
@@ -93,7 +93,7 @@ void otr_log(IRC_CTX *server, const char *to,
#include "otr-formats.h"
-/*
+/*
* maybe this should be configurable?
* I believe bitlbee has something >500.
*/
@@ -108,7 +108,8 @@ void otr_log(IRC_CTX *server, const char *to,
#define INSTAGFILE "/otr/otr.instag"
/* some defaults */
-#define IO_DEFAULT_POLICY "*@localhost opportunistic,*bitlbee* opportunistic,*@im.* opportunistic, *serv at irc* never"
+#define IO_DEFAULT_POLICY \
+ "*@localhost opportunistic,*bitlbee* opportunistic,*@im.* opportunistic, *serv at irc* never"
#define IO_DEFAULT_POLICY_KNOWN "* always"
#define IO_DEFAULT_IGNORE "xmlconsole[0-9]*"
@@ -116,41 +117,41 @@ void otr_log(IRC_CTX *server, const char *to,
* This makes it readable and sensible for
* people not on IRC (i.e. in case of a gateway
* like bitlbee)
- */
+ */
#define IRCACTIONMARK "/me "
#define IRCACTIONMARKLEN 4
/* one for each OTR context (=communication pair) */
struct co_info {
- char *msgqueue; /* holds partially reconstructed base64
- messages */
- IRC_CTX *ircctx; /* irssi server object for this peer */
- int received_smp_init; /* received SMP init msg */
- int smp_failed; /* last SMP failed */
- char better_msg_two[256]; /* what the second line of the "better"
- default query msg should like. Eat it
- up when it comes in */
- int finished; /* true after you've /otr finished */
+ char *msgqueue; /* holds partially reconstructed base64
+ messages */
+ IRC_CTX *ircctx; /* irssi server object for this peer */
+ int received_smp_init; /* received SMP init msg */
+ int smp_failed; /* last SMP failed */
+ char better_msg_two[256]; /* what the second line of the "better"
+ default query msg should like. Eat it
+ up when it comes in */
+ int finished; /* true after you've /otr finished */
};
/* these are returned by /otr contexts */
struct fplist_ {
char *fp;
- enum { NOAUTH,AUTHSMP,AUTHMAN } authby;
+ enum { NOAUTH, AUTHSMP, AUTHMAN } authby;
struct fplist_ *next;
};
struct ctxlist_ {
char *username;
char *accountname;
- enum { STUNENCRYPTED,STENCRYPTED,STFINISHED,STUNKNOWN } state;
+ enum { STUNENCRYPTED, STENCRYPTED, STFINISHED, STUNKNOWN } state;
struct fplist_ *fplist;
struct ctxlist_ *next;
};
/* returned by otr_getstatus */
-enum {
+enum {
IO_ST_PLAINTEXT,
IO_ST_FINISHED,
IO_ST_SMP_INCOMING,
@@ -161,7 +162,7 @@ enum {
IO_ST_TRUST_MANUAL=64,
IO_ST_TRUST_SMP=128,
IO_ST_SMP_ONGOING=
- IO_ST_SMP_INCOMING|IO_ST_SMP_OUTGOING|IO_ST_SMP_FINALIZE
+ IO_ST_SMP_INCOMING | IO_ST_SMP_OUTGOING | IO_ST_SMP_FINALIZE
};
/* given to otr_status_change */
@@ -214,15 +215,17 @@ void otr_deinit_user(IOUSTATE *ioustate);
/* basic send/receive/status stuff */
-char *otr_send(IRC_CTX *server,const char *msg,const char *to);
-char *otr_receive(IRC_CTX *server,const char *msg,const char *from);
+char *otr_send(IRC_CTX *server, const char *msg, const char *to);
+char *otr_receive(IRC_CTX *server, const char *msg, const char *from);
int otr_getstatus(IRC_CTX *ircctx, const char *nick);
-ConnContext *otr_getcontext(const char *accname,const char *nick,int create,IRC_CTX *ircctx);
+ConnContext *otr_getcontext(const char *accname, const char *nick, int create,
+ IRC_CTX *ircctx);
/* user interaction */
void otr_trust(IRC_CTX *server, char *nick, const char *peername);
-void otr_finish(IRC_CTX *server, char *nick, const char *peername, int inquery);
+void otr_finish(IRC_CTX *server, char *nick, const char *peername,
+ int inquery);
void otr_auth(IRC_CTX *server, char *nick, const char *peername,
const char *question, const char *secret);
void otr_authabort(IRC_CTX *server, char *nick, const char *peername);
@@ -234,7 +237,7 @@ void otr_finishall(IOUSTATE *ioustate);
/* key/fingerprint stuff */
void keygen_run(IOUSTATE *ioustate, const char *accname);
-void keygen_abort(IOUSTATE *ioustate,int ignoreidle);
+void keygen_abort(IOUSTATE *ioustate, int ignoreidle);
void key_load(IOUSTATE *ioustate);
void fps_load(IOUSTATE *ioustate);
void otr_writefps(IOUSTATE *ioustate);
@@ -249,15 +252,18 @@ int extract_nick(char *nick, char *line);
struct _cmds {
char *name;
- void (*cmdfunc)(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[], char *target);
+ void (*cmdfunc)(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc,
+ char *argv[], char *argv_eol[], char *target);
};
/* see io_util.c */
#define CMDCOUNT 9
extern struct _cmds cmds[];
-int cmd_generic(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
- char *target);
+int cmd_generic(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
+ char *argv_eol[],
+ char *target);
int otr_getstatus_format(IRC_CTX *ircctx, const char *nick);
-void io_explode_args(const char *args, char ***argvp, char ***argv_eolp, int *argcp);
+void io_explode_args(const char *args, char ***argvp, char ***argv_eolp,
+ int *argcp);
diff --git a/otr_key.c b/otr_key.c
index 2646294..1082bc5 100644
--- a/otr_key.c
+++ b/otr_key.c
@@ -39,66 +39,68 @@ struct {
guint cwid;
pid_t pid;
IOUSTATE *ioustate;
-} kg_st = {.status = KEYGEN_NO };
+} kg_st = { .status = KEYGEN_NO };
-void keygen_childwatch(GPid pid,gint status, gpointer data) {
- struct pollfd pfd = {
+void keygen_childwatch(GPid pid, gint status, gpointer data)
+{
+ struct pollfd pfd = {
.fd = g_io_channel_unix_get_fd(kg_st.ch[0]),
- .events = POLLIN };
+ .events = POLLIN
+ };
int ret;
/* nothing to do if keygen_complete has already been called */
- if (data)
+ if (data)
return;
kg_st.pid = 0;
- ret = poll(&pfd,1,0);
+ ret = poll(&pfd, 1, 0);
/* data is there, let's wait for keygen_complete to be called */
if (ret == 1)
return;
/* no data, report error and reset kg_st */
- if (ret==0) {
+ if (ret == 0) {
if (WIFSIGNALED(status)) {
char sigstr[16];
sprintf(sigstr,
#ifndef HAVE_STRSIGNAL
- "%d",WTERMSIG(status));
+ "%d", WTERMSIG(status));
#else
- "%s",strsignal(WTERMSIG(status)));
+ "%s", strsignal(WTERMSIG(status)));
#endif
otr_noticest(TXT_KG_EXITSIG,
kg_st.accountname,
sigstr);
- }
- else
- otr_noticest(TXT_KG_EXITED,kg_st.accountname);
- } else if (ret==-1)
- otr_noticest(TXT_KG_POLLERR,kg_st.accountname,strerror(errno));
+ }else
+ otr_noticest(TXT_KG_EXITED, kg_st.accountname);
+ } else if (ret == -1)
+ otr_noticest(TXT_KG_POLLERR, kg_st.accountname,
+ strerror(errno));
- keygen_abort(kg_st.ioustate,FALSE);
-}
+ keygen_abort(kg_st.ioustate, FALSE);
+}
/*
* Installed as g_io_watch and called when the key generation
* process finishs.
*/
-gboolean keygen_complete(GIOChannel *source, GIOCondition condition,
+gboolean keygen_complete(GIOChannel *source, GIOCondition condition,
gpointer data)
{
gcry_error_t err;
const char *clconfdir = get_client_config_dir();
- char *filename = g_strconcat(clconfdir,KEYFILE,NULL);
- char *tmpfilename = g_strconcat(clconfdir,TMPKEYFILE,NULL);
+ char *filename = g_strconcat(clconfdir, KEYFILE, NULL);
+ char *tmpfilename = g_strconcat(clconfdir, TMPKEYFILE, NULL);
- read(g_io_channel_unix_get_fd(kg_st.ch[0]),&err,sizeof(err));
+ read(g_io_channel_unix_get_fd(kg_st.ch[0]), &err, sizeof(err));
g_source_remove(kg_st.cpid);
- g_io_channel_shutdown(kg_st.ch[0],FALSE,NULL);
- g_io_channel_shutdown(kg_st.ch[1],FALSE,NULL);
+ g_io_channel_shutdown(kg_st.ch[0], FALSE, NULL);
+ g_io_channel_shutdown(kg_st.ch[1], FALSE, NULL);
g_io_channel_unref(kg_st.ch[0]);
g_io_channel_unref(kg_st.ch[1]);
@@ -111,14 +113,14 @@ gboolean keygen_complete(GIOChannel *source, GIOCondition condition,
/* reload keys */
otr_noticest(TXT_KG_COMPLETED,
kg_st.accountname,
- time(NULL)-kg_st.started);
- rename(tmpfilename,filename);
+ time(NULL) - kg_st.started);
+ rename(tmpfilename, filename);
//otrl_privkey_forget_all(otr_state); <-- done by lib
key_load(kg_st.ioustate);
}
g_source_remove(kg_st.cwid);
- kg_st.cwid = g_child_watch_add(kg_st.pid,keygen_childwatch,(void*)1);
+ kg_st.cwid = g_child_watch_add(kg_st.pid, keygen_childwatch, (void*)1);
kg_st.status = KEYGEN_NO;
g_free(kg_st.accountname);
@@ -131,7 +133,7 @@ gboolean keygen_complete(GIOChannel *source, GIOCondition condition,
/*
* Run key generation in a seperate process (takes ages).
- * The other process will rewrite the key file, we shouldn't
+ * The other process will rewrite the key file, we shouldn't
* change anything till it's done and we've reloaded the keys.
*/
void keygen_run(IOUSTATE *ioustate, const char *accname)
@@ -139,31 +141,34 @@ void keygen_run(IOUSTATE *ioustate, const char *accname)
gcry_error_t err;
int ret;
int fds[2];
- char *filename = g_strconcat(get_client_config_dir(),TMPKEYFILE,NULL), *filenamedup = g_strdup(filename);
+ char *filename = g_strconcat(
+ get_client_config_dir(), TMPKEYFILE,
+ NULL), *filenamedup = g_strdup(
+ filename);
char *dir = dirname(filenamedup);
- if (kg_st.status!=KEYGEN_NO) {
- if (strcmp(accname,kg_st.accountname)!=0)
+ if (kg_st.status != KEYGEN_NO) {
+ if (strcmp(accname, kg_st.accountname) != 0)
otr_noticest(TXT_KG_ABORTED_DUP,
- accname,kg_st.accountname);
+ accname, kg_st.accountname);
return;
}
if (!g_file_test(dir, G_FILE_TEST_EXISTS)) {
- if (g_mkdir(dir,S_IRWXU)) {
+ if (g_mkdir(dir, S_IRWXU)) {
otr_noticest(TXT_KG_ABORTED_DIR,
- accname,dir,strerror(errno));
+ accname, dir, strerror(errno));
g_free(dir);
g_free(filename);
return;
} else
- otr_noticest(TXT_KG_MKDIR,dir);
+ otr_noticest(TXT_KG_MKDIR, dir);
}
g_free(filenamedup);
if (pipe(fds) != 0) {
otr_noticest(TXT_KG_PIPE,
- accname,strerror(errno));
+ accname, strerror(errno));
g_free(filename);
return;
}
@@ -178,9 +183,9 @@ void keygen_run(IOUSTATE *ioustate, const char *accname)
if ((ret = fork())) {
g_free(filename);
- if (ret==-1) {
+ if (ret == -1) {
otr_noticest(TXT_KG_FORK,
- accname,strerror(errno));
+ accname, strerror(errno));
return;
}
@@ -190,9 +195,10 @@ void keygen_run(IOUSTATE *ioustate, const char *accname)
otr_noticest(TXT_KG_INITIATED,
accname);
- kg_st.cpid = g_io_add_watch(kg_st.ch[0], G_IO_IN,
- (GIOFunc) keygen_complete, NULL);
- kg_st.cwid = g_child_watch_add(kg_st.pid,keygen_childwatch,NULL);
+ kg_st.cpid = g_io_add_watch(kg_st.ch[0], G_IO_IN,
+ (GIOFunc)keygen_complete, NULL);
+ kg_st.cwid = g_child_watch_add(kg_st.pid, keygen_childwatch,
+ NULL);
kg_st.started = time(NULL);
return;
@@ -200,8 +206,9 @@ void keygen_run(IOUSTATE *ioustate, const char *accname)
/* child */
- err = otrl_privkey_generate(ioustate->otr_state,filename,accname,PROTOCOLID);
- write(fds[1],&err,sizeof(err));
+ err = otrl_privkey_generate(ioustate->otr_state, filename, accname,
+ PROTOCOLID);
+ write(fds[1], &err, sizeof(err));
g_free(filename);
_exit(0);
@@ -210,37 +217,37 @@ void keygen_run(IOUSTATE *ioustate, const char *accname)
/*
* Abort ongoing key generation.
*/
-void keygen_abort(IOUSTATE *ioustate,int ignoreidle)
+void keygen_abort(IOUSTATE *ioustate, int ignoreidle)
{
- if (kg_st.status!=KEYGEN_RUNNING) {
+ if (kg_st.status != KEYGEN_RUNNING) {
if (!ignoreidle)
otr_noticest(TXT_KG_NOABORT);
return;
}
- otr_noticest(TXT_KG_ABORT,kg_st.accountname);
+ otr_noticest(TXT_KG_ABORT, kg_st.accountname);
g_source_remove(kg_st.cpid);
g_source_remove(kg_st.cwid);
g_free(kg_st.accountname);
- if (kg_st.pid!=0) {
- kill(kg_st.pid,SIGTERM);
- g_child_watch_add(kg_st.pid,keygen_childwatch,(void*)1);
+ if (kg_st.pid != 0) {
+ kill(kg_st.pid, SIGTERM);
+ g_child_watch_add(kg_st.pid, keygen_childwatch, (void*)1);
}
kg_st.status = KEYGEN_NO;
}
-/*
+/*
* Write fingerprints to file.
*/
void otr_writefps(IOUSTATE *ioustate)
{
gcry_error_t err;
- char *filename = g_strconcat(get_client_config_dir(),FPSFILE,NULL);
+ char *filename = g_strconcat(get_client_config_dir(), FPSFILE, NULL);
- err = otrl_privkey_write_fingerprints(ioustate->otr_state,filename);
+ err = otrl_privkey_write_fingerprints(ioustate->otr_state, filename);
if (err == GPG_ERR_NO_ERROR) {
otr_noticest(TXT_FP_SAVED);
@@ -253,15 +260,16 @@ void otr_writefps(IOUSTATE *ioustate)
}
#ifndef LIBOTR3
-/*
+/*
* Write instance tags to file.
*/
void otr_writeinstags(IOUSTATE *ioustate)
{
gcry_error_t err;
- char *filename = g_strconcat(get_client_config_dir(),INSTAGFILE,NULL);
+ char *filename = g_strconcat(
+ get_client_config_dir(), INSTAGFILE, NULL);
- err = otrl_instag_write(ioustate->otr_state,filename);
+ err = otrl_instag_write(ioustate->otr_state, filename);
if (err == GPG_ERR_NO_ERROR) {
otr_noticest(TXT_INSTAG_SAVED);
@@ -280,14 +288,14 @@ void otr_writeinstags(IOUSTATE *ioustate)
void key_load(IOUSTATE *ioustate)
{
gcry_error_t err;
- char *filename = g_strconcat(get_client_config_dir(),KEYFILE,NULL);
+ char *filename = g_strconcat(get_client_config_dir(), KEYFILE, NULL);
if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
otr_noticest(TXT_KEY_NOT_FOUND);
return;
}
- err = otrl_privkey_read(ioustate->otr_state, filename);
+ err = otrl_privkey_read(ioustate->otr_state, filename);
if (err == GPG_ERR_NO_ERROR) {
otr_noticest(TXT_KEY_LOADED);
@@ -305,14 +313,17 @@ void key_load(IOUSTATE *ioustate)
void fps_load(IOUSTATE *ioustate)
{
gcry_error_t err;
- char *filename = g_strconcat(get_client_config_dir(),FPSFILE,NULL);
+ char *filename = g_strconcat(get_client_config_dir(), FPSFILE, NULL);
if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
otr_noticest(TXT_FP_NOT_FOUND);
return;
}
- err = otrl_privkey_read_fingerprints(ioustate->otr_state,filename,NULL,NULL);
+ err =
+ otrl_privkey_read_fingerprints(ioustate->otr_state, filename,
+ NULL,
+ NULL);
if (err == GPG_ERR_NO_ERROR) {
otr_noticest(TXT_FP_LOADED);
@@ -331,14 +342,15 @@ void fps_load(IOUSTATE *ioustate)
void instag_load(IOUSTATE *ioustate)
{
gcry_error_t err;
- char *filename = g_strconcat(get_client_config_dir(),INSTAGFILE,NULL);
+ char *filename = g_strconcat(
+ get_client_config_dir(), INSTAGFILE, NULL);
if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
otr_noticest(TXT_INSTAG_NOT_FOUND);
return;
}
- err = otrl_instag_read(ioustate->otr_state,filename);
+ err = otrl_instag_read(ioustate->otr_state, filename);
if (err == GPG_ERR_NO_ERROR) {
otr_noticest(TXT_INSTAG_LOADED);
diff --git a/otr_ops.c b/otr_ops.c
index f095ca2..6b0bdb6 100644
--- a/otr_ops.c
+++ b/otr_ops.c
@@ -22,7 +22,7 @@
OtrlMessageAppOps otr_ops;
OtrlPolicy IO_DEFAULT_OTR_POLICY =
- OTRL_POLICY_MANUAL|OTRL_POLICY_WHITESPACE_START_AKE;
+ OTRL_POLICY_MANUAL | OTRL_POLICY_WHITESPACE_START_AKE;
/*
* Return policy for given context based on the otr_policy /setting
@@ -30,7 +30,7 @@ OtrlPolicy IO_DEFAULT_OTR_POLICY =
OtrlPolicy ops_policy(void *opdata, ConnContext *context)
{
struct co_info *coi = context->app_data;
- char *server = strchr(context->accountname,'@')+1;
+ char *server = strchr(context->accountname, '@') + 1;
OtrlPolicy op = IO_DEFAULT_OTR_POLICY;
GSList *pl;
char fullname[1024];
@@ -45,13 +45,12 @@ OtrlPolicy ops_policy(void *opdata, ConnContext *context)
do {
struct plistentry *ple = pl->data;
- if (g_pattern_match_string(ple->namepat,fullname))
+ if (g_pattern_match_string(ple->namepat, fullname))
op = ple->policy;
-
} while ((pl = g_slist_next(pl)));
}
- if (ioustate->plistknown&&context->fingerprint_root.next) {
+ if (ioustate->plistknown && context->fingerprint_root.next) {
pl = ioustate->plistknown;
/* loop through otr_policy_known */
@@ -59,16 +58,15 @@ OtrlPolicy ops_policy(void *opdata, ConnContext *context)
do {
struct plistentry *ple = pl->data;
- if (g_pattern_match_string(ple->namepat,fullname))
+ if (g_pattern_match_string(ple->namepat, fullname))
op = ple->policy;
-
} while ((pl = g_slist_next(pl)));
}
if (coi && coi->finished &&
(op == OTRL_POLICY_OPPORTUNISTIC ||
op == OTRL_POLICY_ALWAYS))
- op = OTRL_POLICY_MANUAL|OTRL_POLICY_WHITESPACE_START_AKE;
+ op = OTRL_POLICY_MANUAL | OTRL_POLICY_WHITESPACE_START_AKE;
return op;
}
@@ -83,7 +81,7 @@ void ops_create_privkey(void *opdata, const char *accountname,
{
IRC_CTX *ircctx __attribute__((unused)) = opdata;
- keygen_run(IRCCTX_IO_US(ircctx),accountname);
+ keygen_run(IRCCTX_IO_US(ircctx), accountname);
}
/*
@@ -92,24 +90,25 @@ void ops_create_privkey(void *opdata, const char *accountname,
* need to derive the server from accountname.
*/
void ops_inject_msg(void *opdata, const char *accountname,
- const char *protocol, const char *recipient, const char *message)
+ const char *protocol, const char *recipient,
+ const char *message)
{
IRC_CTX *a_serv;
char *msgcopy = g_strdup(message);
- /* OTR sometimes gives us multiple lines
+ /* OTR sometimes gives us multiple lines
* (e.g. the default query (a.k.a. "better") message) */
- g_strdelimit (msgcopy,"\n",' ');
+ g_strdelimit(msgcopy, "\n", ' ');
a_serv = opdata;
if (!a_serv) {
char nick[256];
- a_serv = ircctx_by_peername(accountname,nick);
+ a_serv = ircctx_by_peername(accountname, nick);
}
if (!a_serv) {
- otr_notice(a_serv,recipient,TXT_OPS_INJECT,
- accountname,recipient,message);
+ otr_notice(a_serv, recipient, TXT_OPS_INJECT,
+ accountname, recipient, message);
} else {
- otr_logst(MSGLEVEL_CRAP,"%d: INJECT %s",time(NULL),msgcopy);
+ otr_logst(MSGLEVEL_CRAP, "%d: INJECT %s", time(NULL), msgcopy);
irc_send_message(a_serv, recipient, msgcopy);
}
g_free(msgcopy);
@@ -118,35 +117,36 @@ void ops_inject_msg(void *opdata, const char *accountname,
/*
* OTR notification. Haven't seen one yet.
*/
-void ops_notify(void *opdata, OtrlNotifyLevel level, const char *accountname,
- const char *protocol, const char *username,
- const char *title, const char *primary,
+void ops_notify(void *opdata, OtrlNotifyLevel level, const char *accountname,
+ const char *protocol, const char *username,
+ const char *title, const char *primary,
const char *secondary)
{
- ConnContext *co = otr_getcontext(accountname,username,FALSE,NULL);
+ ConnContext *co = otr_getcontext(accountname, username, FALSE, NULL);
IRC_CTX *server = opdata;
struct co_info *coi;
if (co) {
coi = co->app_data;
server = coi->ircctx;
- } else
- otr_notice(server,username,TXT_OPS_NOTIFY_BUG);
+ } else
+ otr_notice(server, username, TXT_OPS_NOTIFY_BUG);
- otr_notice(server,username,TXT_OPS_NOTIFY,
- title,primary,secondary);
+ otr_notice(server, username, TXT_OPS_NOTIFY,
+ title, primary, secondary);
}
#ifdef HAVE_GREGEX_H
/* This is kind of messy. */
-const char *convert_otr_msg(const char *msg)
+const char *convert_otr_msg(const char *msg)
{
- GRegex *regex_bold = g_regex_new("</?i([ /][^>]*)?>",0,0,NULL);
- GRegex *regex_del = g_regex_new("</?b([ /][^>]*)?>",0,0,NULL);
- gchar *msgnohtml =
- g_regex_replace_literal(regex_del,msg,-1,0,"",0,NULL);
+ GRegex *regex_bold = g_regex_new("</?i([ /][^>]*)?>", 0, 0, NULL);
+ GRegex *regex_del = g_regex_new("</?b([ /][^>]*)?>", 0, 0, NULL);
+ gchar *msgnohtml =
+ g_regex_replace_literal(regex_del, msg, -1, 0, "", 0, NULL);
- msg = g_regex_replace_literal(regex_bold,msgnohtml,-1,0,"*",0,NULL);
+ msg = g_regex_replace_literal(regex_bold, msgnohtml, -1, 0, "*", 0,
+ NULL);
g_free(msgnohtml);
g_regex_unref(regex_del);
@@ -161,58 +161,59 @@ const char *convert_otr_msg(const char *msg)
* OTR message. E.g. "following has been transmitted in clear: ...".
* We're trying to kill the ugly HTML.
*/
-int ops_display_msg(void *opdata, const char *accountname,
- const char *protocol, const char *username,
+int ops_display_msg(void *opdata, const char *accountname,
+ const char *protocol, const char *username,
const char *msg)
{
- ConnContext *co = otr_getcontext(accountname,username,FALSE,opdata);
+ ConnContext *co = otr_getcontext(accountname, username, FALSE, opdata);
IRC_CTX *server = opdata;
struct co_info *coi;
if (co) {
coi = co->app_data;
server = coi->ircctx;
- } else
- otr_notice(server,username,TXT_OPS_DISPLAY_BUG);
+ } else
+ otr_notice(server, username, TXT_OPS_DISPLAY_BUG);
#ifdef HAVE_GREGEX_H
msg = convert_otr_msg(msg);
- otr_notice(server,username,TXT_OPS_DISPLAY,msg);
+ otr_notice(server, username, TXT_OPS_DISPLAY, msg);
g_free((char*)msg);
#else
- otr_notice(server,username,TXT_OPS_DISPLAY,msg);
+ otr_notice(server, username, TXT_OPS_DISPLAY, msg);
#endif
return 0;
}
-/*
+/*
* Gone secure.
*/
void ops_secure(void *opdata, ConnContext *context)
{
struct co_info *coi = context->app_data;
char * trust = context->active_fingerprint->trust ? : "";
- char ownfp[45],peerfp[45];
+ char ownfp[45], peerfp[45];
otr_notice(coi->ircctx,
- context->username,TXT_OPS_SEC);
- otr_status_change(coi->ircctx,context->username,IO_STC_GONE_SECURE);
+ context->username, TXT_OPS_SEC);
+ otr_status_change(coi->ircctx, context->username, IO_STC_GONE_SECURE);
//TODO: pull master context
coi->finished = FALSE;
- if (*trust!='\0')
+ if (*trust != '\0')
return;
- /* not authenticated.
+ /* not authenticated.
* Let's print out the fingerprints for comparison */
otrl_privkey_hash_to_human(peerfp,
context->active_fingerprint->fingerprint);
- otr_notice(coi->ircctx,context->username,TXT_OPS_FPCOMP,
- otrl_privkey_fingerprint(IRCCTX_IO_US(coi->ircctx)->otr_state,
+ otr_notice(coi->ircctx, context->username, TXT_OPS_FPCOMP,
+ otrl_privkey_fingerprint(IRCCTX_IO_US(coi->ircctx)->
+ otr_state,
ownfp,
context->accountname,
PROTOCOLID),
@@ -227,8 +228,9 @@ void ops_insecure(void *opdata, ConnContext *context)
{
struct co_info *coi = context->app_data;
otr_notice(coi->ircctx,
- context->username,TXT_OPS_INSEC);
- otr_status_change(coi->ircctx,context->username,IO_STC_GONE_INSECURE);
+ context->username, TXT_OPS_INSEC);
+ otr_status_change(coi->ircctx, context->username,
+ IO_STC_GONE_INSECURE);
}
/*
@@ -238,7 +240,7 @@ void ops_still_secure(void *opdata, ConnContext *context, int is_reply)
{
struct co_info *coi = context->app_data;
otr_notice(coi->ircctx,
- context->username,is_reply ?
+ context->username, is_reply ?
TXT_OPS_STILL_REPLY :
TXT_OPS_STILL_NO_REPLY);
}
@@ -248,11 +250,11 @@ void ops_still_secure(void *opdata, ConnContext *context, int is_reply)
*/
void ops_log(void *opdata, const char *message)
{
- otr_infost(TXT_OPS_LOG,message);
+ otr_infost(TXT_OPS_LOG, message);
}
/*
- * Really critical with IRC.
+ * Really critical with IRC.
* Unfortunately, we can't tell our peer which size to use.
* (reminds me of MTU determination...)
*/
@@ -263,26 +265,26 @@ int ops_max_msg(void *opdata, ConnContext *context)
#ifndef LIBOTR3
void ops_handle_msg_event(void *opdata, OtrlMessageEvent msg_event,
- ConnContext *context, const char *message,
- gcry_error_t err)
+ ConnContext *context, const char *message,
+ gcry_error_t err)
{
- IRC_CTX *server = opdata;
+ IRC_CTX *server = opdata;
char *username = context->username;
otr_debug(server,
username,
TXT_OPS_HANDLE_MSG,
- otr_msg_event_txt[msg_event],message);
+ otr_msg_event_txt[msg_event], message);
}
#endif
/*
- * A context changed.
+ * A context changed.
* I believe this is not happening for the SMP expects.
*/
void ops_up_ctx_list(void *opdata)
{
- otr_status_change(opdata,NULL,IO_STC_CTX_UPDATE);
+ otr_status_change(opdata, NULL, IO_STC_CTX_UPDATE);
}
/*
@@ -295,8 +297,8 @@ void ops_writefps(void *data)
otr_writefps(IRCCTX_IO_US(ircctx));
}
-int ops_is_logged_in(void *opdata, const char *accountname,
- const char *protocol, const char *recipient)
+int ops_is_logged_in(void *opdata, const char *accountname,
+ const char *protocol, const char *recipient)
{
/*TODO register a handler for event 401 no such nick and set
* a variable offline=TRUE. Reset it to false in otr_receive and
@@ -306,9 +308,11 @@ int ops_is_logged_in(void *opdata, const char *accountname,
#ifndef LIBOTR3
void ops_create_instag(void *opdata, const char *accountname,
- const char *protocol)
+ const char *protocol)
{
- otrl_instag_generate(IRCCTX_IO_US(ircctx)->otr_state,"/dev/null",accountname,protocol);
+ otrl_instag_generate(IRCCTX_IO_US(
+ ircctx)->otr_state, "/dev/null",
+ accountname, protocol);
otr_writeinstags(IRCCTX_IO_US(ircctx));
}
@@ -320,44 +324,44 @@ void ops_smp_event(void *opdata, OtrlSMPEvent smp_event,
char *from = context->username;
struct co_info *coi = context->app_data;
- coi->received_smp_init =
- (smp_event==OTRL_SMPEVENT_ASK_FOR_SECRET)||
- (smp_event==OTRL_SMPEVENT_ASK_FOR_ANSWER);
+ coi->received_smp_init =
+ (smp_event == OTRL_SMPEVENT_ASK_FOR_SECRET) ||
+ (smp_event == OTRL_SMPEVENT_ASK_FOR_ANSWER);
switch (smp_event) {
case OTRL_SMPEVENT_ASK_FOR_SECRET:
- otr_notice(ircctx,from,TXT_AUTH_PEER,
+ otr_notice(ircctx, from, TXT_AUTH_PEER,
from);
- otr_status_change(ircctx,from,IO_STC_SMP_INCOMING);
+ otr_status_change(ircctx, from, IO_STC_SMP_INCOMING);
break;
case OTRL_SMPEVENT_ASK_FOR_ANSWER:
- otr_notice(ircctx,from,TXT_AUTH_PEER_QA,from,question);
- otr_status_change(ircctx,from,IO_STC_SMP_INCOMING);
+ otr_notice(ircctx, from, TXT_AUTH_PEER_QA, from, question);
+ otr_status_change(ircctx, from, IO_STC_SMP_INCOMING);
break;
case OTRL_SMPEVENT_IN_PROGRESS:
- otr_notice(ircctx,from,
+ otr_notice(ircctx, from,
TXT_AUTH_PEER_REPLIED,
from);
- otr_status_change(ircctx,from,IO_STC_SMP_FINALIZE);
+ otr_status_change(ircctx, from, IO_STC_SMP_FINALIZE);
break;
case OTRL_SMPEVENT_SUCCESS:
- otr_notice(ircctx,from,
+ otr_notice(ircctx, from,
TXT_AUTH_SUCCESSFUL);
- otr_status_change(ircctx,from,IO_STC_SMP_SUCCESS);
+ otr_status_change(ircctx, from, IO_STC_SMP_SUCCESS);
break;
case OTRL_SMPEVENT_ABORT:
- otr_abort_auth(context,ircctx,from);
- otr_status_change(ircctx,from,IO_STC_SMP_ABORTED);
+ otr_abort_auth(context, ircctx, from);
+ otr_status_change(ircctx, from, IO_STC_SMP_ABORTED);
break;
case OTRL_SMPEVENT_FAILURE:
case OTRL_SMPEVENT_CHEATED:
case OTRL_SMPEVENT_ERROR:
- otr_notice(ircctx,from,TXT_AUTH_FAILED);
+ otr_notice(ircctx, from, TXT_AUTH_FAILED);
coi->smp_failed = TRUE;
- otr_status_change(ircctx,from,IO_STC_SMP_FAILED);
+ otr_status_change(ircctx, from, IO_STC_SMP_FAILED);
break;
default:
- otr_logst(MSGLEVEL_CRAP,"Received unknown SMP event");
+ otr_logst(MSGLEVEL_CRAP, "Received unknown SMP event");
break;
}
}
@@ -367,8 +371,9 @@ void ops_smp_event(void *opdata, OtrlSMPEvent smp_event,
/*
* Initialize our OtrlMessageAppOps
*/
-void otr_initops() {
- memset(&otr_ops,0,sizeof(otr_ops));
+void otr_initops()
+{
+ memset(&otr_ops, 0, sizeof(otr_ops));
otr_ops.policy = ops_policy;
otr_ops.create_privkey = ops_create_privkey;
diff --git a/otr_util.c b/otr_util.c
index c765e34..987ab6d 100644
--- a/otr_util.c
+++ b/otr_util.c
@@ -27,7 +27,7 @@ static int otrinited = FALSE;
#ifdef TARGET_BITLBEE
GHashTable *ioustates;
#else
-IOUSTATE ioustate_uniq = { 0,0,0 };
+IOUSTATE ioustate_uniq = { 0, 0, 0 };
#endif
#ifdef HAVE_GREGEX_H
@@ -53,15 +53,15 @@ IOUSTATE *otr_init_user(char *user)
void otr_deinit_user(IOUSTATE *ioustate)
{
- keygen_abort(ioustate,TRUE);
+ keygen_abort(ioustate, TRUE);
if (ioustate->otr_state) {
otr_writefps(ioustate);
otrl_userstate_free(ioustate->otr_state);
ioustate->otr_state = NULL;
}
- otr_setpolicies(ioustate,"",FALSE);
- otr_setpolicies(ioustate,"",TRUE);
+ otr_setpolicies(ioustate, "", FALSE);
+ otr_setpolicies(ioustate, "", TRUE);
}
/*
@@ -73,23 +73,25 @@ int otrlib_init()
/* apparently used in pidgin-otr to
* force gcrypt to /dev/urandom */
/*
- gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
- gcry_control(GCRYCTL_ENABLE_QUICK_RANDOM, 0);
- */
+ gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
+ gcry_control(GCRYCTL_ENABLE_QUICK_RANDOM, 0);
+ */
OTRL_INIT;
otrinited = TRUE;
}
#ifdef TARGET_BITLBEE
- ioustates = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,otr_deinit_user);
+ ioustates = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
+ otr_deinit_user);
#endif
otr_initops();
#ifdef HAVE_GREGEX_H
- regex_policies =
- g_regex_new("([^,]+) (never|manual|handlews|opportunistic|always)"
- "(,|$)",0,0,NULL);
+ regex_policies =
+ g_regex_new(
+ "([^,]+) (never|manual|handlews|opportunistic|always)"
+ "(,|$)", 0, 0, NULL);
#endif
return 0;
@@ -127,24 +129,25 @@ void context_free_app_info(void *data)
* Add app data to context.
* See struct co_info for details.
*/
-void context_add_app_info(void *data,ConnContext *co)
+void context_add_app_info(void *data, ConnContext *co)
{
IRC_CTX *ircctx = IRCCTX_DUP(data);
struct co_info *coi = g_malloc(sizeof(struct co_info));
- memset(coi,0,sizeof(struct co_info));
+ memset(coi, 0, sizeof(struct co_info));
co->app_data = coi;
co->app_data_free = context_free_app_info;
coi->ircctx = ircctx;
- sprintf(coi->better_msg_two,formats[TXT_OTR_BETTER_TWO].def,co->accountname);
+ sprintf(coi->better_msg_two, formats[TXT_OTR_BETTER_TWO].def,
+ co->accountname);
}
/*
* Get a context from a pair.
*/
-ConnContext *otr_getcontext(const char *accname,const char *nick,
- int create,IRC_CTX *ircctx)
+ConnContext *otr_getcontext(const char *accname, const char *nick,
+ int create, IRC_CTX *ircctx)
{
ConnContext *co = otrl_context_find(
IRCCTX_IO_US(ircctx)->otr_state,
@@ -160,77 +163,76 @@ ConnContext *otr_getcontext(const char *accname,const char *nick,
ircctx);
/* context came from a fingerprint */
- if (co&&ircctx&&!co->app_data)
- context_add_app_info(ircctx,co);
+ if (co && ircctx && !co->app_data)
+ context_add_app_info(ircctx, co);
return co;
}
/*
* Hand the given message to OTR.
- * Returns NULL if OTR handled the message and
+ * Returns NULL if OTR handled the message and
* the original message otherwise.
*/
-char *otr_send(IRC_CTX *ircctx, const char *msg,const char *to)
+char *otr_send(IRC_CTX *ircctx, const char *msg, const char *to)
{
gcry_error_t err;
char *newmessage = NULL;
ConnContext *co;
char accname[256];
- IRCCTX_ACCNAME(accname,ircctx);
+ IRCCTX_ACCNAME(accname, ircctx);
- otr_logst(MSGLEVEL_CRAP,"%d: send...",time(NULL));
+ otr_logst(MSGLEVEL_CRAP, "%d: send...", time(NULL));
err = otrl_message_sending(
- IRCCTX_IO_US(ircctx)->otr_state,
- &otr_ops,
- ircctx,
+ IRCCTX_IO_US(ircctx)->otr_state,
+ &otr_ops,
+ ircctx,
accname,
- PROTOCOLID,
- to,
+ PROTOCOLID,
+ to,
#ifndef LIBOTR3
OTRL_INSTAG_BEST,
#endif
- msg,
- NULL,
- &newmessage,
+ msg,
+ NULL,
+ &newmessage,
#ifndef LIBOTR3
- OTRL_FRAGMENT_SEND_ALL,
+ OTRL_FRAGMENT_SEND_ALL,
&co,
#endif
- context_add_app_info,
+ context_add_app_info,
ircctx);
- otr_logst(MSGLEVEL_CRAP,"%d: sent",time(NULL));
+ otr_logst(MSGLEVEL_CRAP, "%d: sent", time(NULL));
if (err != 0) {
- otr_notice(ircctx,to,TXT_SEND_FAILED,msg);
+ otr_notice(ircctx, to, TXT_SEND_FAILED, msg);
return NULL;
}
- if (newmessage==NULL)
+ if (newmessage == NULL)
return (char*)msg;
/* OTR message. Need to do fragmentation */
#ifdef LIBOTR3
- if (!(co = otr_getcontext(accname,to,FALSE,ircctx))) {
- otr_notice(ircctx,to,TXT_SEND_CHANGE);
+ if (!(co = otr_getcontext(accname, to, FALSE, ircctx))) {
+ otr_notice(ircctx, to, TXT_SEND_CHANGE);
return NULL;
}
err = otrl_message_fragment_and_send(
- &otr_ops,
- ircctx,
+ &otr_ops,
+ ircctx,
co,
- newmessage,
- OTRL_FRAGMENT_SEND_ALL,
+ newmessage,
+ OTRL_FRAGMENT_SEND_ALL,
NULL);
if (err != 0) {
- otr_notice(ircctx,to,TXT_SEND_FRAGMENT,msg);
+ otr_notice(ircctx, to, TXT_SEND_FRAGMENT, msg);
} else
- otr_debug(ircctx,to,TXT_SEND_CONVERTED,newmessage);
-
+ otr_debug(ircctx, to, TXT_SEND_CONVERTED, newmessage);
#endif
return NULL;
@@ -241,23 +243,26 @@ struct ctxlist_ *otr_contexts(IOUSTATE *ioustate)
ConnContext *context;
Fingerprint *fprint;
struct ctxlist_ *ctxlist = NULL, *ctxhead = NULL;
- struct fplist_ *fplist,*fphead;
+ struct fplist_ *fplist, *fphead;
char fp[41];
char *trust;
int i;
- for(context = ioustate->otr_state->context_root; context;
- context = context->next) {
+ for (context = ioustate->otr_state->context_root; context;
+ context = context->next) {
if (!ctxlist)
ctxhead = ctxlist = g_malloc0(sizeof(struct ctxlist_));
else
ctxlist = ctxlist->next = g_malloc0(sizeof(struct
- ctxlist_));
+ ctxlist_));
switch (context->msgstate) {
- case OTRL_MSGSTATE_PLAINTEXT: ctxlist->state = STUNENCRYPTED;break;
- case OTRL_MSGSTATE_ENCRYPTED: ctxlist->state = STENCRYPTED;break;
- case OTRL_MSGSTATE_FINISHED: ctxlist->state = STFINISHED;break;
- default: ctxlist->state = STUNKNOWN;break;
+ case OTRL_MSGSTATE_PLAINTEXT: ctxlist->state = STUNENCRYPTED;
+ break;
+ case OTRL_MSGSTATE_ENCRYPTED: ctxlist->state = STENCRYPTED;
+ break;
+ case OTRL_MSGSTATE_FINISHED: ctxlist->state = STFINISHED;
+ break;
+ default: ctxlist->state = STUNKNOWN; break;
}
ctxlist->username = context->username;
ctxlist->accountname = context->accountname;
@@ -269,18 +274,19 @@ struct ctxlist_ *otr_contexts(IOUSTATE *ioustate)
fphead = fplist = g_malloc0(sizeof(struct
fplist_));
else
- fplist = fplist->next = g_malloc0(sizeof(struct
- fplist_));
+ fplist = fplist->next =
+ g_malloc0(sizeof(struct
+ fplist_));
trust = fprint->trust ? : "";
- for(i=0;i<20;++i)
- sprintf(fp+i*2, "%02x",
- fprint->fingerprint[i]);
+ for (i = 0; i < 20; ++i)
+ sprintf(fp + i * 2, "%02x",
+ fprint->fingerprint[i]);
fplist->fp = g_strdup(fp);
- if (*trust=='\0')
+ if (*trust == '\0')
fplist->authby = NOAUTH;
- else if (strcmp(trust,"smp")==0)
+ else if (strcmp(trust, "smp") == 0)
fplist->authby = AUTHSMP;
- else
+ else
fplist->authby = AUTHMAN;
}
@@ -298,9 +304,9 @@ int otr_getstatus(IRC_CTX *ircctx, const char *nick)
char accname[128];
struct co_info *coi;
- IRCCTX_ACCNAME(accname,ircctx);
+ IRCCTX_ACCNAME(accname, ircctx);
- if (!(co = otr_getcontext(accname,nick,FALSE,ircctx))) {
+ if (!(co = otr_getcontext(accname, nick, FALSE, ircctx))) {
return IO_ST_PLAINTEXT;
}
@@ -312,7 +318,7 @@ int otr_getstatus(IRC_CTX *ircctx, const char *nick)
case OTRL_MSGSTATE_ENCRYPTED: {
char *trust = co->active_fingerprint->trust;
int ex = co->smstate->nextExpected;
- int code=0;
+ int code = 0;
switch (ex) {
case OTRL_SMP_EXPECT1:
@@ -322,17 +328,19 @@ int otr_getstatus(IRC_CTX *ircctx, const char *nick)
case OTRL_SMP_EXPECT2:
code = IO_ST_SMP_OUTGOING;
break;
- case OTRL_SMP_EXPECT3:
+ case OTRL_SMP_EXPECT3:
case OTRL_SMP_EXPECT4:
code = IO_ST_SMP_FINALIZE;
break;
default:
- otr_logst(MSGLEVEL_CRAP,"Encountered unknown SMP state in libotr, please let maintainers know");
+ otr_logst(
+ MSGLEVEL_CRAP,
+ "Encountered unknown SMP state in libotr, please let maintainers know");
return IO_ST_UNKNOWN;
}
- if (trust&&(*trust!='\0'))
- code |= strcmp(trust,"smp")==0 ? IO_ST_TRUST_SMP :
+ if (trust && (*trust != '\0'))
+ code |= strcmp(trust, "smp") == 0 ? IO_ST_TRUST_SMP :
IO_ST_TRUST_MANUAL;
else
code |= IO_ST_UNTRUSTED;
@@ -342,7 +350,9 @@ int otr_getstatus(IRC_CTX *ircctx, const char *nick)
case OTRL_MSGSTATE_FINISHED:
return IO_ST_FINISHED;
default:
- otr_logst(MSGLEVEL_CRAP,"BUG Found! Please write us a mail and describe how you got here");
+ otr_logst(
+ MSGLEVEL_CRAP,
+ "BUG Found! Please write us a mail and describe how you got here");
return IO_ST_UNKNOWN;
}
}
@@ -350,7 +360,8 @@ int otr_getstatus(IRC_CTX *ircctx, const char *nick)
/*
* Finish the conversation.
*/
-void otr_finish(IRC_CTX *ircctx, char *nick, const char *peername, int inquery)
+void otr_finish(IRC_CTX *ircctx, char *nick, const char *peername,
+ int inquery)
{
ConnContext *co;
char accname[128];
@@ -359,42 +370,43 @@ void otr_finish(IRC_CTX *ircctx, char *nick, const char *peername, int inquery)
if (peername) {
nick = nickbuf;
- ircctx = ircctx_by_peername(peername,nick);
+ ircctx = ircctx_by_peername(peername, nick);
if (!ircctx)
return;
}
- IRCCTX_ACCNAME(accname,ircctx);
+ IRCCTX_ACCNAME(accname, ircctx);
- if (!(co = otr_getcontext(accname,nick,FALSE,ircctx))) {
+ if (!(co = otr_getcontext(accname, nick, FALSE, ircctx))) {
if (inquery)
otr_noticest(TXT_CTX_NOT_FOUND,
- accname,nick);
+ accname, nick);
return;
}
otrl_message_disconnect(IRCCTX_IO_US(ircctx)->otr_state,
- &otr_ops,ircctx,accname,
+ &otr_ops, ircctx, accname,
PROTOCOLID,
#ifdef LIBOTR3
nick);
#else
- nick,co->their_instance);
+ nick, co->their_instance);
#endif
- otr_status_change(ircctx,nick,IO_STC_FINISHED);
+ otr_status_change(ircctx, nick, IO_STC_FINISHED);
if (inquery) {
- otr_info(ircctx,nick,TXT_CMD_FINISH,nick,IRCCTX_ADDR(ircctx));
+ otr_info(ircctx, nick, TXT_CMD_FINISH, nick,
+ IRCCTX_ADDR(ircctx));
} else {
- otr_infost(TXT_CMD_FINISH,nick,IRCCTX_ADDR(ircctx));
+ otr_infost(TXT_CMD_FINISH, nick, IRCCTX_ADDR(ircctx));
}
coi = co->app_data;
/* finish if /otr finish has been issued. Reset if
* we're called cause the query window has been closed. */
- if (coi)
+ if (coi)
coi->finished = inquery;
#ifndef LIBOTR3
@@ -410,35 +422,37 @@ void otr_finish(IRC_CTX *ircctx, char *nick, const char *peername, int inquery)
NULL,
NULL);
coi = co->app_data;
- if (coi)
+ if (coi)
coi->finished = inquery;
#endif
-
}
void otr_finishall(IOUSTATE *ioustate)
{
ConnContext *context;
- int finished=0;
+ int finished = 0;
- for(context = ioustate->otr_state->context_root; context;
- context = context->next) {
+ for (context = ioustate->otr_state->context_root; context;
+ context = context->next) {
struct co_info *coi = context->app_data;
- if (context->msgstate!=OTRL_MSGSTATE_ENCRYPTED)
+ if (context->msgstate != OTRL_MSGSTATE_ENCRYPTED)
continue;
- otrl_message_disconnect(ioustate->otr_state,&otr_ops,coi->ircctx,
+ otrl_message_disconnect(ioustate->otr_state, &otr_ops,
+ coi->ircctx,
context->accountname,
PROTOCOLID,
#ifdef LIBOTR3
context->username);
#else
- context->username,context->their_instance);
+ context->username,
+ context->their_instance);
#endif
- otr_status_change(coi->ircctx,context->username,IO_STC_FINISHED);
+ otr_status_change(coi->ircctx, context->username,
+ IO_STC_FINISHED);
- otr_infost(TXT_CMD_FINISH,context->username,
+ otr_infost(TXT_CMD_FINISH, context->username,
IRCCTX_ADDR(coi->ircctx));
finished++;
}
@@ -459,27 +473,26 @@ void otr_trust(IRC_CTX *ircctx, char *nick, const char *peername)
if (peername) {
nick = nickbuf;
- ircctx = ircctx_by_peername(peername,nick);
+ ircctx = ircctx_by_peername(peername, nick);
if (!ircctx)
return;
}
- IRCCTX_ACCNAME(accname,ircctx);
+ IRCCTX_ACCNAME(accname, ircctx);
- if (!(co = otr_getcontext(accname,nick,FALSE,ircctx))) {
+ if (!(co = otr_getcontext(accname, nick, FALSE, ircctx))) {
otr_noticest(TXT_CTX_NOT_FOUND,
- accname,nick);
+ accname, nick);
return;
}
- otrl_context_set_trust(co->active_fingerprint,"manual");
- otr_status_change(ircctx,nick,IO_STC_TRUST_MANUAL);
+ otrl_context_set_trust(co->active_fingerprint, "manual");
+ otr_status_change(ircctx, nick, IO_STC_TRUST_MANUAL);
coi = co->app_data;
coi->smp_failed = FALSE;
- otr_notice(ircctx,nick,TXT_FP_TRUST,nick);
-
+ otr_notice(ircctx, nick, TXT_FP_TRUST, nick);
}
/*
@@ -493,13 +506,15 @@ void otr_abort_auth(ConnContext *co, IRC_CTX *ircctx, const char *nick)
coi->received_smp_init = FALSE;
- otr_notice(ircctx,nick,
- co->smstate->nextExpected!=OTRL_SMP_EXPECT1 ?
+ otr_notice(ircctx, nick,
+ co->smstate->nextExpected != OTRL_SMP_EXPECT1 ?
TXT_AUTH_ABORTED_ONGOING :
TXT_AUTH_ABORTED);
- otrl_message_abort_smp(IRCCTX_IO_US(ircctx)->otr_state,&otr_ops,ircctx,co);
- otr_status_change(ircctx,nick,IO_STC_SMP_ABORT);
+ otrl_message_abort_smp(IRCCTX_IO_US(
+ ircctx)->otr_state, &otr_ops, ircctx,
+ co);
+ otr_status_change(ircctx, nick, IO_STC_SMP_ABORT);
}
/*
@@ -513,21 +528,20 @@ void otr_authabort(IRC_CTX *ircctx, char *nick, const char *peername)
if (peername) {
nick = nickbuf;
- ircctx = ircctx_by_peername(peername,nick);
+ ircctx = ircctx_by_peername(peername, nick);
if (!ircctx)
return;
}
- IRCCTX_ACCNAME(accname,ircctx);
+ IRCCTX_ACCNAME(accname, ircctx);
- if (!(co = otr_getcontext(accname,nick,FALSE,ircctx))) {
+ if (!(co = otr_getcontext(accname, nick, FALSE, ircctx))) {
otr_noticest(TXT_CTX_NOT_FOUND,
- accname,nick);
+ accname, nick);
return;
}
- otr_abort_auth(co,ircctx,nick);
-
+ otr_abort_auth(co, ircctx, nick);
}
/*
@@ -543,36 +557,36 @@ void otr_auth(IRC_CTX *ircctx, char *nick, const char *peername,
if (peername) {
nick = nickbuf;
- ircctx = ircctx_by_peername(peername,nick);
+ ircctx = ircctx_by_peername(peername, nick);
if (!ircctx)
return;
}
- IRCCTX_ACCNAME(accname,ircctx);
+ IRCCTX_ACCNAME(accname, ircctx);
- if (!(co = otr_getcontext(accname,nick,FALSE,ircctx))) {
+ if (!(co = otr_getcontext(accname, nick, FALSE, ircctx))) {
otr_noticest(TXT_CTX_NOT_FOUND,
- accname,nick);
+ accname, nick);
return;
}
- if (co->msgstate!=OTRL_MSGSTATE_ENCRYPTED) {
- otr_notice(ircctx,nick,TXT_AUTH_NEEDENC);
+ if (co->msgstate != OTRL_MSGSTATE_ENCRYPTED) {
+ otr_notice(ircctx, nick, TXT_AUTH_NEEDENC);
return;
}
coi = co->app_data;
/* Aborting an ongoing auth */
- if (co->smstate->nextExpected!=OTRL_SMP_EXPECT1)
- otr_abort_auth(co,ircctx,nick);
+ if (co->smstate->nextExpected != OTRL_SMP_EXPECT1)
+ otr_abort_auth(co, ircctx, nick);
coi->smp_failed = FALSE;
/* reset trust level */
if (co->active_fingerprint) {
char *trust = co->active_fingerprint->trust;
- if (trust&&(*trust!='\0')) {
+ if (trust && (*trust != '\0')) {
otrl_context_set_trust(co->active_fingerprint, "");
otr_writefps(IRCCTX_IO_US(ircctx));
}
@@ -582,7 +596,7 @@ void otr_auth(IRC_CTX *ircctx, char *nick, const char *peername,
#ifndef LIBOTR3
if (question)
otrl_message_initiate_smp_q(
- IRCCTX_IO_US(ircctx)->otr_state,
+ IRCCTX_IO_US(ircctx)->otr_state,
&otr_ops,
ircctx,
co,
@@ -591,15 +605,15 @@ void otr_auth(IRC_CTX *ircctx, char *nick, const char *peername,
strlen(secret));
else
#endif
- otrl_message_initiate_smp(
- IRCCTX_IO_US(ircctx)->otr_state,
- &otr_ops,
- ircctx,
- co,
- (unsigned char*)secret,
- strlen(secret));
+ otrl_message_initiate_smp(
+ IRCCTX_IO_US(ircctx)->otr_state,
+ &otr_ops,
+ ircctx,
+ co,
+ (unsigned char*)secret,
+ strlen(secret));
- otr_status_change(ircctx,nick,IO_STC_SMP_STARTED);
+ otr_status_change(ircctx, nick, IO_STC_SMP_STARTED);
} else {
otrl_message_respond_smp(
IRCCTX_IO_US(ircctx)->otr_state,
@@ -608,74 +622,75 @@ void otr_auth(IRC_CTX *ircctx, char *nick, const char *peername,
co,
(unsigned char*)secret,
strlen(secret));
- otr_status_change(ircctx,nick,IO_STC_SMP_RESPONDED);
+ otr_status_change(ircctx, nick, IO_STC_SMP_RESPONDED);
}
- otr_notice(ircctx,nick,
+ otr_notice(ircctx, nick,
coi->received_smp_init ?
TXT_AUTH_RESPONDING :
TXT_AUTH_INITIATED);
-
}
-/*
+/*
* Handles incoming TLVs of the SMP authentication type. We're not only updating
* our own state but also giving libotr a leg up so it gets through the auth.
*/
-void otr_handle_tlvs(OtrlTLV *tlvs, ConnContext *co,
- struct co_info *coi,
- IRC_CTX *ircctx, const char *from)
+void otr_handle_tlvs(OtrlTLV *tlvs, ConnContext *co,
+ struct co_info *coi,
+ IRC_CTX *ircctx, const char *from)
{
int abort = FALSE;
OtrlTLV *tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1);
if (tlv) {
if (co->smstate->nextExpected != OTRL_SMP_EXPECT1) {
- otr_notice(ircctx,from,TXT_AUTH_HAVE_OLD,
+ otr_notice(ircctx, from, TXT_AUTH_HAVE_OLD,
from);
abort = TRUE;
} else {
- otr_notice(ircctx,from,TXT_AUTH_PEER,
+ otr_notice(ircctx, from, TXT_AUTH_PEER,
from);
coi->received_smp_init = TRUE;
- otr_status_change(ircctx,from,IO_STC_SMP_INCOMING);
+ otr_status_change(ircctx, from, IO_STC_SMP_INCOMING);
}
}
tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP2);
if (tlv) {
if (co->smstate->nextExpected != OTRL_SMP_EXPECT2) {
- otr_notice(ircctx,from,
+ otr_notice(ircctx, from,
TXT_AUTH_PEER_REPLY_WRONG,
from);
abort = TRUE;
} else {
- otr_notice(ircctx,from,
+ otr_notice(ircctx, from,
TXT_AUTH_PEER_REPLIED,
from);
co->smstate->nextExpected = OTRL_SMP_EXPECT4;
- otr_status_change(ircctx,from,IO_STC_SMP_FINALIZE);
+ otr_status_change(ircctx, from, IO_STC_SMP_FINALIZE);
}
}
tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP3);
if (tlv) {
if (co->smstate->nextExpected != OTRL_SMP_EXPECT3) {
- otr_notice(ircctx,from,
+ otr_notice(ircctx, from,
TXT_AUTH_PEER_WRONG_SMP3,
from);
abort = TRUE;
} else {
char *trust = co->active_fingerprint->trust;
- if (trust&&(*trust!='\0')) {
- otr_notice(ircctx,from,
+ if (trust && (*trust != '\0')) {
+ otr_notice(ircctx, from,
TXT_AUTH_SUCCESSFUL);
- otr_status_change(ircctx,from,IO_STC_SMP_SUCCESS);
+ otr_status_change(ircctx, from,
+ IO_STC_SMP_SUCCESS);
} else {
- otr_notice(ircctx,from,
+ otr_notice(ircctx, from,
TXT_AUTH_FAILED);
coi->smp_failed = TRUE;
- otr_status_change(ircctx,from,IO_STC_SMP_FAILED);
+ otr_status_change(ircctx, from,
+ IO_STC_SMP_FAILED);
}
co->smstate->nextExpected = OTRL_SMP_EXPECT1;
coi->received_smp_init = FALSE;
@@ -685,47 +700,48 @@ void otr_handle_tlvs(OtrlTLV *tlvs, ConnContext *co,
tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP4);
if (tlv) {
if (co->smstate->nextExpected != OTRL_SMP_EXPECT4) {
- otr_notice(ircctx,from,
+ otr_notice(ircctx, from,
TXT_AUTH_PEER_WRONG_SMP4,
from);
abort = TRUE;
} else {
char *trust = co->active_fingerprint->trust;
- if (trust&&(*trust!='\0')) {
- otr_notice(ircctx,from,
+ if (trust && (*trust != '\0')) {
+ otr_notice(ircctx, from,
TXT_AUTH_SUCCESSFUL);
- otr_status_change(ircctx,from,IO_STC_SMP_SUCCESS);
+ otr_status_change(ircctx, from,
+ IO_STC_SMP_SUCCESS);
} else {
/* unreachable since 4 is never sent out on
* error */
- otr_notice(ircctx,from,
+ otr_notice(ircctx, from,
TXT_AUTH_FAILED);
coi->smp_failed = TRUE;
- otr_status_change(ircctx,from,IO_STC_SMP_FAILED);
+ otr_status_change(ircctx, from,
+ IO_STC_SMP_FAILED);
}
co->smstate->nextExpected = OTRL_SMP_EXPECT1;
coi->received_smp_init = FALSE;
}
}
if (abort) {
- otr_abort_auth(co,ircctx,from);
- otr_status_change(ircctx,from,IO_STC_SMP_ABORTED);
+ otr_abort_auth(co, ircctx, from);
+ otr_status_change(ircctx, from, IO_STC_SMP_ABORTED);
}
tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED);
if (tlv) {
- otr_status_change(ircctx,from,IO_STC_PEER_FINISHED);
- otr_notice(ircctx,from,TXT_PEER_FINISHED,from);
+ otr_status_change(ircctx, from, IO_STC_PEER_FINISHED);
+ otr_notice(ircctx, from, TXT_PEER_FINISHED, from);
}
-
}
/*
* Hand the given message to OTR.
- * Returns NULL if its an OTR protocol message and
+ * Returns NULL if its an OTR protocol message and
* the (possibly) decrypted message otherwise.
*/
-char *otr_receive(IRC_CTX *ircctx, const char *msg,const char *from)
+char *otr_receive(IRC_CTX *ircctx, const char *msg, const char *from)
{
int ignore_message;
char *newmessage = NULL;
@@ -735,11 +751,11 @@ char *otr_receive(IRC_CTX *ircctx, const char *msg,const char *from)
struct co_info *coi;
OtrlTLV *tlvs;
- IRCCTX_ACCNAME(accname,ircctx);
+ IRCCTX_ACCNAME(accname, ircctx);
- if (!(co = otr_getcontext(accname,from,TRUE,ircctx))) {
+ if (!(co = otr_getcontext(accname, from, TRUE, ircctx))) {
otr_noticest(TXT_CTX_NOT_CREATE,
- accname,from);
+ accname, from);
return NULL;
}
@@ -748,13 +764,13 @@ char *otr_receive(IRC_CTX *ircctx, const char *msg,const char *from)
/* Really lame but I don't see how you could do this in a generic
* way unless the IRC server would somehow mark continuation messages.
*/
- if ((strcmp(msg,coi->better_msg_two)==0)||
- (strcmp(msg,formats[TXT_OTR_BETTER_THREE].def)==0)) {
- otr_debug(ircctx,from,TXT_RECEIVE_IGNORE_QUERY);
+ if ((strcmp(msg, coi->better_msg_two) == 0) ||
+ (strcmp(msg, formats[TXT_OTR_BETTER_THREE].def) == 0)) {
+ otr_debug(ircctx, from, TXT_RECEIVE_IGNORE_QUERY);
return NULL;
}
- /* The server might have split lines that were too long
+ /* The server might have split lines that were too long
* (bitlbee does that). The heuristic is simple: If we can find ?OTR:
* in the message but it doesn't end with a ".", queue it and wait
* for the rest.
@@ -762,15 +778,15 @@ char *otr_receive(IRC_CTX *ircctx, const char *msg,const char *from)
lastmsg = co->app_data;
if (coi->msgqueue) { /* already something in the queue */
- strcpy(coi->msgqueue+strlen(coi->msgqueue),msg);
+ strcpy(coi->msgqueue + strlen(coi->msgqueue), msg);
/* wait for more? */
- if ((strlen(msg)>OTR_MAX_MSG_SIZE)&&
- (msg[strlen(msg)-1]!='.')&&
- (msg[strlen(msg)-1]!=','))
+ if ((strlen(msg) > OTR_MAX_MSG_SIZE) &&
+ (msg[strlen(msg) - 1] != '.') &&
+ (msg[strlen(msg) - 1] != ','))
return NULL;
- otr_debug(ircctx,from,TXT_RECEIVE_DEQUEUED,
+ otr_debug(ircctx, from, TXT_RECEIVE_DEQUEUED,
strlen(coi->msgqueue));
msg = coi->msgqueue;
@@ -779,26 +795,25 @@ char *otr_receive(IRC_CTX *ircctx, const char *msg,const char *from)
/* this is freed thru our caller by otrl_message_free.
* Currently ok since that just uses free().
*/
-
- } else if (strstr(msg,"?OTR:")&&
- (strlen(msg)>OTR_MAX_MSG_SIZE)&&
- (msg[strlen(msg)-1]!='.')&&
- (msg[strlen(msg)-1]!=',')) {
- coi->msgqueue = malloc(4096*sizeof(char));
- strcpy(coi->msgqueue,msg);
- otr_debug(ircctx,from,TXT_RECEIVE_QUEUED,strlen(msg));
+ } else if (strstr(msg, "?OTR:") &&
+ (strlen(msg) > OTR_MAX_MSG_SIZE) &&
+ (msg[strlen(msg) - 1] != '.') &&
+ (msg[strlen(msg) - 1] != ',')) {
+ coi->msgqueue = malloc(4096 * sizeof(char));
+ strcpy(coi->msgqueue, msg);
+ otr_debug(ircctx, from, TXT_RECEIVE_QUEUED, strlen(msg));
return NULL;
}
- otr_logst(MSGLEVEL_CRAP,"%d: receive...",time(NULL));
+ otr_logst(MSGLEVEL_CRAP, "%d: receive...", time(NULL));
ignore_message = otrl_message_receiving(
IRCCTX_IO_US(ircctx)->otr_state,
&otr_ops,
ircctx,
- accname,
- PROTOCOLID,
- from,
- msg,
+ accname,
+ PROTOCOLID,
+ from,
+ msg,
&newmessage,
&tlvs,
#ifdef LIBOTR3
@@ -809,29 +824,28 @@ char *otr_receive(IRC_CTX *ircctx, const char *msg,const char *from)
context_add_app_info,
ircctx);
#endif
- otr_logst(MSGLEVEL_CRAP,"%d: received",time(NULL));
+ otr_logst(MSGLEVEL_CRAP, "%d: received", time(NULL));
if (tlvs) {
#ifdef LIBOTR3
- otr_handle_tlvs(tlvs,co,coi,ircctx,from);
+ otr_handle_tlvs(tlvs, co, coi, ircctx, from);
#else
-
OtrlTLV *tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED);
if (tlv) {
- otr_status_change(ircctx,from,IO_STC_PEER_FINISHED);
- otr_notice(ircctx,from,TXT_PEER_FINISHED,from);
+ otr_status_change(ircctx, from, IO_STC_PEER_FINISHED);
+ otr_notice(ircctx, from, TXT_PEER_FINISHED, from);
}
#endif
}
-
+
if (ignore_message) {
- otr_debug(ircctx,from,
- TXT_RECEIVE_IGNORE, strlen(msg),accname,from,msg);
+ otr_debug(ircctx, from,
+ TXT_RECEIVE_IGNORE, strlen(msg), accname, from, msg);
return NULL;
}
if (newmessage)
- otr_debug(ircctx,from,TXT_RECEIVE_CONVERTED);
+ otr_debug(ircctx, from, TXT_RECEIVE_CONVERTED);
return newmessage ? : (char*)msg;
}
@@ -854,14 +868,17 @@ void otr_setpolicies(IOUSTATE *ioustate, const char *policies, int known)
plist = NULL;
}
- g_regex_match(regex_policies,policies,0,&match_info);
+ g_regex_match(regex_policies, policies, 0, &match_info);
- while(g_match_info_matches(match_info)) {
- struct plistentry *ple = (struct plistentry *)g_malloc0(sizeof(struct plistentry));
+ while (g_match_info_matches(match_info)) {
+ struct plistentry *ple =
+ (struct plistentry*)g_malloc0(sizeof(struct
+ plistentry));
char *pol = g_match_info_fetch(match_info, 2);
- ple->namepat = g_pattern_spec_new(g_match_info_fetch(match_info, 1));
-
+ ple->namepat =
+ g_pattern_spec_new(g_match_info_fetch(match_info, 1));
+
switch (*pol) {
case 'n':
ple->policy = OTRL_POLICY_NEVER;
@@ -870,7 +887,8 @@ void otr_setpolicies(IOUSTATE *ioustate, const char *policies, int known)
ple->policy = OTRL_POLICY_MANUAL;
break;
case 'h':
- ple->policy = OTRL_POLICY_MANUAL|OTRL_POLICY_WHITESPACE_START_AKE;
+ ple->policy = OTRL_POLICY_MANUAL |
+ OTRL_POLICY_WHITESPACE_START_AKE;
break;
case 'o':
ple->policy = OTRL_POLICY_OPPORTUNISTIC;
@@ -880,7 +898,7 @@ void otr_setpolicies(IOUSTATE *ioustate, const char *policies, int known)
break;
}
- plist = g_slist_append(plist,ple);
+ plist = g_slist_append(plist, ple);
g_free(pol);
diff --git a/weechat/weechat_otr.c b/weechat/weechat_otr.c
index eac529b..32b84fe 100644
--- a/weechat/weechat_otr.c
+++ b/weechat/weechat_otr.c
@@ -37,7 +37,8 @@ GRegex *regex_nickignore = NULL;
static IOUSTATE *ioustate;
-void printformatva(IRC_CTX *ircctx, const char *nick, const char *format, va_list params)
+void printformatva(IRC_CTX *ircctx, const char *nick, const char *format,
+ va_list params)
{
char msg[LOGMAX], *s = msg;
char *server = NULL;
@@ -46,61 +47,69 @@ void printformatva(IRC_CTX *ircctx, const char *nick, const char *format, va_lis
if (ircctx)
server = ircctx->address;
- if (server&&nick) {
+ if (server && nick) {
char s[256];
- sprintf(s,"%s.%s",ircctx->address,nick);
- buffer = weechat_buffer_search("irc",s);
+ sprintf(s, "%s.%s", ircctx->address, nick);
+ buffer = weechat_buffer_search("irc", s);
if (!buffer) {
char cmd[256];
- sprintf(cmd,"/query -server %s %s",ircctx->address,nick);
- weechat_command(NULL,cmd);
- buffer = weechat_buffer_search("irc",s);
+ sprintf(cmd, "/query -server %s %s", ircctx->address,
+ nick);
+ weechat_command(NULL, cmd);
+ buffer = weechat_buffer_search("irc", s);
if (!buffer)
- weechat_printf(NULL,"OTR:\tFailed to create "
- "a buffer for the following "
- "message! server=%s,nick=%s",
- ircctx->address,nick);
+ weechat_printf(
+ NULL, "OTR:\tFailed to create "
+ "a buffer for the following "
+ "message! server=%s,nick=%s",
+ ircctx->address, nick);
}
}
- if( vsnprintf( s, LOGMAX, format, params ) < 0 )
- sprintf( s, "internal error parsing error string (BUG)" );
- va_end( params );
+ if (vsnprintf(s, LOGMAX, format, params) < 0)
+ sprintf(s, "internal error parsing error string (BUG)");
+ va_end(params);
- weechat_printf(buffer,"OTR:\t%s",s);
+ weechat_printf(buffer, "OTR:\t%s", s);
}
void printformat(IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...)
{
va_list params;
- va_start( params, fnum );
+ va_start(params, fnum);
- printformatva(ircctx,nick,formats[fnum].def,params);
+ printformatva(ircctx, nick, formats[fnum].def, params);
}
-void otr_log(IRC_CTX *ircctx, const char *nick, int level, const char *format, ...)
+void otr_log(IRC_CTX *ircctx, const char *nick, int level, const char *format,
+ ...)
{
va_list params;
- va_start( params, format );
+ va_start(params, format);
- printformatva(ircctx,nick,format,params);
+ printformatva(ircctx, nick, format, params);
}
-#define wc_printf(server,nick,format,...) \
- otr_log(server,nick,0,format, ## __VA_ARGS__)
+#define wc_printf(server, nick, format, ...) \
+ otr_log(server, nick, 0, format, ## __VA_ARGS__)
-#define wc_debug(server,nick,format,...) { \
- if (debug) \
- wc_printf(server,nick, \
- format, ## __VA_ARGS__); \
+#define wc_debug(server, nick, format, ...) { \
+ if (debug) \
+ wc_printf(server, nick, \
+ format, ## __VA_ARGS__); \
}
-void irc_send_message(IRC_CTX *ircctx, const char *recipient, char *msg) {
+void irc_send_message(IRC_CTX *ircctx, const char *recipient, char *msg)
+{
char nmsg[512];
-
- wc_debug(ircctx,recipient,"OTR injection %s.%s: %s",ircctx->address,recipient,msg);
- sprintf(nmsg,"/quote -server %s PRIVMSG %s :%s",ircctx->address,recipient,msg);
- weechat_command(NULL,nmsg);
+
+ wc_debug(ircctx, recipient, "OTR injection %s.%s: %s",
+ ircctx->address, recipient,
+ msg);
+ sprintf(nmsg, "/quote -server %s PRIVMSG %s :%s", ircctx->address,
+ recipient,
+ msg);
+ weechat_command(NULL, nmsg);
}
IRC_CTX *ircctx_by_peername(const char *peername, char *nick)
@@ -109,72 +118,74 @@ IRC_CTX *ircctx_by_peername(const char *peername, char *nick)
static IRC_CTX ircctx;
static char pname[256];
- strcpy(pname,peername);
+ strcpy(pname, peername);
- address = strchr(pname,'@');
+ address = strchr(pname, '@');
if (!address)
return NULL;
*address = '\0';
- strcpy(nick,pname);
+ strcpy(nick, pname);
*address++ = '@';
ircctx.address = address;
ircctx.nick = pname;
- return &ircctx;
+ return &ircctx;
}
char *wc_modifier_privmsg_in(void *data, const char *modifier,
- const char *modifier_data, const char *string)
+ const char *modifier_data, const char *string)
{
int argc;
char **argv, **argv_eol;
char nick[256];
- char *newmsg,*msg;
+ char *newmsg, *msg;
IRC_CTX ircctx;
char cmsg[512];
string = strdup(string);
- argv = weechat_string_explode (string, " ", 0, 0, &argc);
- argv_eol = weechat_string_explode (string, " ", 1, 0, NULL);
+ argv = weechat_string_explode(string, " ", 0, 0, &argc);
+ argv_eol = weechat_string_explode(string, " ", 1, 0, NULL);
- if (!extract_nick(nick,argv[0]))
+ if (!extract_nick(nick, argv[0]))
goto done;
- if ((*argv[2]=='&')||(*argv[2]=='#'))
+ if ((*argv[2] == '&') || (*argv[2] == '#'))
goto done;
#ifdef HAVE_GREGEX_H
- if (g_regex_match(regex_nickignore,nick,0,NULL))
+ if (g_regex_match(regex_nickignore, nick, 0, NULL))
goto done;
#endif
ircctx.address = (char*)modifier_data;
ircctx.nick = argv[2];
- msg = argv_eol[3]+1;
- wc_debug(&ircctx,nick,"otr receive own %s, server %s, nick %s, msg %s",
- ircctx.nick,ircctx.address,nick,msg);
- newmsg = otr_receive(&ircctx,msg,nick);
+ msg = argv_eol[3] + 1;
+ wc_debug(&ircctx, nick,
+ "otr receive own %s, server %s, nick %s, msg %s",
+ ircctx.nick, ircctx.address, nick,
+ msg);
+ newmsg = otr_receive(&ircctx, msg, nick);
if (!newmsg) {
string = strdup("");
goto done;
}
- if (newmsg==msg) {
+ if (newmsg == msg) {
goto done;
}
- snprintf(cmsg, 511, "%s %s %s :%s",argv[0],argv[1],argv[2],newmsg);
+ snprintf(cmsg, 511, "%s %s %s :%s", argv[0], argv[1], argv[2], newmsg);
otrl_message_free(newmsg);
string = strdup(cmsg);
-done:
+ done:
weechat_string_free_exploded(argv);
weechat_string_free_exploded(argv_eol);
@@ -182,7 +193,7 @@ done:
}
char *wc_modifier_privmsg_out(void *data, const char *modifier,
- const char *modifier_data, const char *string)
+ const char *modifier_data, const char *string)
{
int argc;
char **argv, **argv_eol;
@@ -192,74 +203,80 @@ char *wc_modifier_privmsg_out(void *data, const char *modifier,
char s[256];
char *msg;
- argv = weechat_string_explode (string, " ", 0, 0, &argc);
- argv_eol = weechat_string_explode (string, " ", 1, 0, NULL);
+ argv = weechat_string_explode(string, " ", 0, 0, &argc);
+ argv_eol = weechat_string_explode(string, " ", 1, 0, NULL);
string = strdup(string);
-
- if ((*argv[1]=='&')||(*argv[1]=='#'))
+
+ if ((*argv[1] == '&') || (*argv[1] == '#'))
goto done;
- msg = argv_eol[2]+1;
+ msg = argv_eol[2] + 1;
#ifdef HAVE_GREGEX_H
- if (g_regex_match(regex_nickignore,argv[1],0,NULL))
+ if (g_regex_match(regex_nickignore, argv[1], 0, NULL))
goto done;
#endif
/* we're unfortunately fed back stuff from irc_send_message above */
- if (strncmp(msg,"?OTR",4)==0)
+ if (strncmp(msg, "?OTR", 4) == 0)
goto done;
ircctx.address = (char*)modifier_data;
- sprintf(s,"%s.%s",ircctx.address,argv[1]);
+ sprintf(s, "%s.%s", ircctx.address, argv[1]);
- ircctx.nick = (char*)weechat_info_get("irc_nick",ircctx.address);
+ ircctx.nick = (char*)weechat_info_get("irc_nick", ircctx.address);
- wc_debug(&ircctx,argv[1],"otr send own %s, server %s, nick %s, msg %s",
- ircctx.nick,ircctx.address,argv[1],msg);
- otrmsg = otr_send(&ircctx,msg,argv[1]);
+ wc_debug(&ircctx, argv[1],
+ "otr send own %s, server %s, nick %s, msg %s",
+ ircctx.nick, ircctx.address, argv[1],
+ msg);
+ otrmsg = otr_send(&ircctx, msg, argv[1]);
- if (otrmsg==msg)
+ if (otrmsg == msg)
goto done;
if (!otrmsg) {
- wc_debug(&ircctx,argv[1],"OTR send NULL");
+ wc_debug(&ircctx, argv[1], "OTR send NULL");
free((char*)string);
string = strdup("");
goto done;
}
- wc_debug(&ircctx,argv[1],"NEWMSG");
+ wc_debug(&ircctx, argv[1], "NEWMSG");
snprintf(newmsg, 511, "PRIVMSG %s :%s", argv[1], otrmsg);
otrl_message_free(otrmsg);
-
+
free((char*)string);
string = newmsg;
-done:
+ done:
weechat_string_free_exploded(argv);
weechat_string_free_exploded(argv_eol);
return (char*)string;
}
-int cmd_otr(void *data, struct t_gui_buffer *buffer, int argc, char **word, char **word_eol)
+int cmd_otr(void *data, struct t_gui_buffer *buffer, int argc, char **word,
+ char **word_eol)
{
- const char *own_nick = weechat_buffer_get_string(buffer,"localvar_nick");
- const char *server = weechat_buffer_get_string(buffer,"localvar_server");
- char *target = (char*)weechat_buffer_get_string(buffer,"short_name");
+ const char *own_nick = weechat_buffer_get_string(buffer,
+ "localvar_nick");
+ const char *server = weechat_buffer_get_string(buffer,
+ "localvar_server");
+ char *target = (char*)weechat_buffer_get_string(buffer, "short_name");
IRC_CTX ircctxs = {
.nick = (char*)own_nick,
- .address = (char*)server },
- *ircctx = &ircctxs;
+ .address = (char*)server
+ },
+ *ircctx = &ircctxs;
word++;
word_eol++;
argc--;
- cmd_generic(ioustate,ircctx,argc,word,word_eol,target);
+ cmd_generic(ioustate, ircctx, argc, word, word_eol, target);
return WEECHAT_RC_OK;
}
@@ -267,27 +284,29 @@ int cmd_otr(void *data, struct t_gui_buffer *buffer, int argc, char **word, char
/*
* otr status bar
*/
-char* otr_statusbar_callback (void *data,
- struct t_gui_bar_item *item,
- struct t_gui_window *window)
+char* otr_statusbar_callback(void *data,
+ struct t_gui_bar_item *item,
+ struct t_gui_window *window)
{
const char *target;
IRC_CTX ircctx;
int formatnum;
- struct t_gui_buffer *buffer =
+ struct t_gui_buffer *buffer =
weechat_window_get_pointer(window, "buffer");
- const char *type = weechat_buffer_get_string (buffer, "localvar_type");
+ const char *type = weechat_buffer_get_string(buffer, "localvar_type");
- if (!type || strcmp(type, "private") != 0)
+ if (!type || strcmp(type, "private") != 0)
return strdup("");
-
- ircctx.nick = (char*)weechat_buffer_get_string(buffer,"localvar_nick");
- ircctx.address = (char*)weechat_buffer_get_string(buffer,"localvar_server");
- target = weechat_buffer_get_string(buffer,"short_name");
+
+ ircctx.nick = (char*)weechat_buffer_get_string(buffer,
+ "localvar_nick");
+ ircctx.address = (char*)weechat_buffer_get_string(buffer,
+ "localvar_server");
+ target = weechat_buffer_get_string(buffer, "short_name");
formatnum = otr_getstatus_format(&ircctx, target);
- return strdup (formats[formatnum].def);
+ return strdup(formats[formatnum].def);
}
@@ -296,8 +315,8 @@ void otr_status_change(IRC_CTX *ircctx, const char *nick, int event)
char signalname[128];
char servernick[256];
- sprintf(signalname,"OTR_%s",otr_status_txt[event]);
- sprintf(servernick,"%s,%s",ircctx->address,nick);
+ sprintf(signalname, "OTR_%s", otr_status_txt[event]);
+ sprintf(servernick, "%s,%s", ircctx->address, nick);
weechat_hook_signal_send(signalname,
WEECHAT_HOOK_SIGNAL_STRING,
@@ -306,45 +325,47 @@ void otr_status_change(IRC_CTX *ircctx, const char *nick, int event)
weechat_bar_item_update("otr");
}
-int weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
+int weechat_plugin_init(struct t_weechat_plugin *plugin, int argc,
+ char *argv[])
{
-
weechat_plugin = plugin;
weechat_hook_modifier("irc_in_privmsg", &wc_modifier_privmsg_in, NULL);
- weechat_hook_modifier("irc_out_privmsg", &wc_modifier_privmsg_out, NULL);
+ weechat_hook_modifier("irc_out_privmsg", &wc_modifier_privmsg_out,
+ NULL);
if (otrlib_init())
return WEECHAT_RC_ERROR;
ioustate = otr_init_user("one to rule them all");
- otr_setpolicies(ioustate,IO_DEFAULT_POLICY,FALSE);
- otr_setpolicies(ioustate,IO_DEFAULT_POLICY_KNOWN,TRUE);
+ otr_setpolicies(ioustate, IO_DEFAULT_POLICY, FALSE);
+ otr_setpolicies(ioustate, IO_DEFAULT_POLICY_KNOWN, TRUE);
#ifdef HAVE_GREGEX_H
if (regex_nickignore)
g_regex_unref(regex_nickignore);
- regex_nickignore = g_regex_new(IO_DEFAULT_IGNORE,0,0,NULL);
+ regex_nickignore = g_regex_new(IO_DEFAULT_IGNORE, 0, 0, NULL);
#endif
- weechat_hook_command ("otr",
- N_("Control the OTR module"),
- N_("[text]"),
- N_("text: write this text"),
- "",
- &cmd_otr, NULL);
+ weechat_hook_command("otr",
+ N_("Control the OTR module"),
+ N_("[text]"),
+ N_("text: write this text"),
+ "",
+ &cmd_otr, NULL);
cmds[CMDCOUNT].name = "set";
cmds[CMDCOUNT].cmdfunc = cmd_set;
- otr_statusbar = weechat_bar_item_new ("otr", &otr_statusbar_callback, NULL);
- weechat_bar_item_update ("otr");
+ otr_statusbar = weechat_bar_item_new("otr", &otr_statusbar_callback,
+ NULL);
+ weechat_bar_item_update("otr");
return WEECHAT_RC_OK;
}
-int weechat_plugin_end (struct t_weechat_plugin *plugin)
+int weechat_plugin_end(struct t_weechat_plugin *plugin)
{
weechat_bar_item_remove(otr_statusbar);
diff --git a/weechat/weechat_otr.h b/weechat/weechat_otr.h
index 9e4574c..c97623e 100644
--- a/weechat/weechat_otr.h
+++ b/weechat/weechat_otr.h
@@ -47,29 +47,30 @@ extern char set_policy[512];
extern char set_policy_known[512];
extern char set_ignore[512];
extern int set_finishonunload;
-void cmd_set(IOUSTATE *ioustate,IRC_CTX *ircctx, int argc, char *argv[], char *argv_eol[],
- char *target);
+void cmd_set(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
+ char *argv_eol[],
+ char *target);
-#define get_client_config_dir() weechat_info_get("weechat_dir",NULL)
+#define get_client_config_dir() weechat_info_get("weechat_dir", NULL)
void printformat(IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...);
-#define otr_noticest(formatnum,...) \
- printformat(NULL,NULL,MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__)
+#define otr_noticest(formatnum, ...) \
+ printformat(NULL, NULL, MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__)
-#define otr_notice(server,nick,formatnum,...) \
- printformat(server,nick,MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__)
+#define otr_notice(server, nick, formatnum, ...) \
+ printformat(server, nick, MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__)
-#define otr_infost(formatnum,...) \
- printformat(NULL,NULL,MSGLEVEL_CRAP, formatnum, ## __VA_ARGS__)
+#define otr_infost(formatnum, ...) \
+ printformat(NULL, NULL, MSGLEVEL_CRAP, formatnum, ## __VA_ARGS__)
-#define otr_info(server,nick,formatnum,...) \
- printformat(server,nick,MSGLEVEL_CRAP, formatnum, ## __VA_ARGS__)
+#define otr_info(server, nick, formatnum, ...) \
+ printformat(server, nick, MSGLEVEL_CRAP, formatnum, ## __VA_ARGS__)
-#define otr_debug(server,nick,formatnum,...) { \
- if (debug) \
- printformat(server,nick, \
- MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__); \
+#define otr_debug(server, nick, formatnum, ...) { \
+ if (debug) \
+ printformat(server, nick, \
+ MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__); \
}
static IRC_CTX *IRCCTX_DUP(IRC_CTX *ircctx) __attribute__ ((unused));
@@ -77,7 +78,7 @@ static void IRCCTX_FREE(IRC_CTX *ircctx) __attribute__ ((unused));
static IRC_CTX *IRCCTX_DUP(IRC_CTX *ircctx)
{
- IRC_CTX *nctx = g_memdup(ircctx,sizeof(IRC_CTX));
+ IRC_CTX *nctx = g_memdup(ircctx, sizeof(IRC_CTX));
nctx->nick = strdup(ircctx->nick);
nctx->address = strdup(ircctx->address);
@@ -94,16 +95,18 @@ static void IRCCTX_FREE(IRC_CTX *ircctx)
free(ircctx);
}
-#define IRCCTX_ACCNAME(accname,ircctx) sprintf(accname, "%s@%s", ircctx->nick, ircctx->address)
+#define IRCCTX_ACCNAME(accname, ircctx) sprintf(accname, "%s@%s", \
+ ircctx->nick, \
+ ircctx->address)
#define IRCCTX_IO_US(ircctx) (&ioustate_uniq)
#define IO_CREATE_US(user) (&ioustate_uniq)
/* Don't look beyond this point. Ugly temporary hack. */
-#define g_io_add_watch(pid,a,func,b) gioaddwatchfake(pid,func)
+#define g_io_add_watch(pid, a, func, b) gioaddwatchfake(pid, func)
-#define g_child_watch_add(pid,func,dunno) gchildwatchaddfake(pid,dunno)
-#define g_io_channel_shutdown(channel,FALSE,NULL) \
+#define g_child_watch_add(pid, func, dunno) gchildwatchaddfake(pid, dunno)
+#define g_io_channel_shutdown(channel, FALSE, NULL) \
close(g_io_channel_unix_get_fd(channel))
#define g_source_remove(a) gsourceremovefake(a)
@@ -112,13 +115,12 @@ static void IRCCTX_FREE(IRC_CTX *ircctx)
#include <sys/types.h>
#include <sys/wait.h>
-static void *gchildwatchaddfake(int pid,void *doit) __attribute__ ((unused));
-static void *gchildwatchaddfake(int pid,void *doit)
+static void *gchildwatchaddfake(int pid, void *doit) __attribute__ ((unused));
+static void *gchildwatchaddfake(int pid, void *doit)
{
if (doit)
- waitpid(pid,NULL,0);
+ waitpid(pid, NULL, 0);
return NULL;
-
}
static void gsourceremovefake(struct t_hook *hook) __attribute__ ((unused));
@@ -126,25 +128,31 @@ static void gsourceremovefake(struct t_hook *hook)
{
if (hook)
weechat_unhook(hook);
-
}
-gboolean keygen_complete(GIOChannel *source, GIOCondition condition,
+gboolean keygen_complete(GIOChannel *source, GIOCondition condition,
gpointer data);
static int cb(void *data)
{
- keygen_complete(NULL,0,NULL);
+ keygen_complete(NULL, 0, NULL);
return TRUE;
}
-static struct t_hook *gioaddwatchfake(GIOChannel *source, int (*func)(GIOChannel *source,
- GIOCondition condition,
- gpointer data))
- __attribute__ ((unused));
-
-static struct t_hook *gioaddwatchfake(GIOChannel *source, int (*func)(GIOChannel *source,GIOCondition
- condition, gpointer data))
+static struct t_hook *gioaddwatchfake(GIOChannel *source, int (*func)(
+ GIOChannel *source,
+ GIOCondition
+ condition,
+ gpointer
+ data))
+__attribute__ ((unused));
+
+static struct t_hook *gioaddwatchfake(GIOChannel *source, int (*func)(
+ GIOChannel *source,
+ GIOCondition
+ condition,
+ gpointer data))
{
- return weechat_hook_fd(g_io_channel_unix_get_fd(source),TRUE,FALSE,FALSE,cb,NULL);
+ return weechat_hook_fd(g_io_channel_unix_get_fd(
+ source), TRUE, FALSE, FALSE, cb, NULL);
}
diff --git a/xchat/xchat_otr.c b/xchat/xchat_otr.c
index 60661af..91c25fa 100644
--- a/xchat/xchat_otr.c
+++ b/xchat/xchat_otr.c
@@ -29,7 +29,8 @@ static IOUSTATE *ioustate;
xchat_plugin *ph;
-void irc_send_message(IRC_CTX *ircctx, const char *recipient, char *msg) {
+void irc_send_message(IRC_CTX *ircctx, const char *recipient, char *msg)
+{
xchat_commandf(ph, "PRIVMSG %s :%s", recipient, msg);
}
@@ -38,19 +39,20 @@ int cmd_otr(char *word[], char *word_eol[], void *userdata)
const char *own_nick = xchat_get_info(ph, "nick");
char *target = (char*)xchat_get_info(ph, "channel");
const char *server = xchat_get_info(ph, "server");
- IRC_CTX ircctxs = {
- .nick = (char*)own_nick,
- .address = (char*)server },
- *ircctx = &ircctxs;
- int argc=0;
-
- word+=3;
- word_eol+=3;
-
- while (word[argc]&&*word[argc])
+ IRC_CTX ircctxs = {
+ .nick = (char*)own_nick,
+ .address = (char*)server
+ },
+ *ircctx = &ircctxs;
+ int argc = 0;
+
+ word += 3;
+ word_eol += 3;
+
+ while (word[argc] && *word[argc])
argc++;
- cmd_generic(ioustate,ircctx,argc,word,word_eol,target);
+ cmd_generic(ioustate, ircctx, argc, word, word_eol, target);
return XCHAT_EAT_ALL;
}
@@ -62,23 +64,25 @@ int hook_outgoing(char *word[], char *word_eol[], void *userdata)
const char *server = xchat_get_info(ph, "server");
char newmsg[512];
char *otrmsg;
- IRC_CTX ircctx = {
+ IRC_CTX ircctx = {
.nick = (char*)own_nick,
- .address = (char*)server };
+ .address = (char*)server
+ };
- if ((*channel == '&')||(*channel == '#'))
+ if ((*channel == '&') || (*channel == '#'))
return XCHAT_EAT_NONE;
#ifdef HAVE_GREGEX_H
- if (g_regex_match(regex_nickignore,channel,0,NULL))
+ if (g_regex_match(regex_nickignore, channel, 0, NULL))
return XCHAT_EAT_NONE;
#endif
- otrmsg = otr_send(&ircctx,word_eol[1],channel);
+ otrmsg = otr_send(&ircctx, word_eol[1], channel);
- if (otrmsg==word_eol[1])
+ if (otrmsg == word_eol[1])
return XCHAT_EAT_NONE;
- xchat_emit_print(ph, "Your Message", own_nick, word_eol[1], NULL, NULL);
+ xchat_emit_print(ph, "Your Message", own_nick, word_eol[1], NULL,
+ NULL);
if (!otrmsg)
return XCHAT_EAT_ALL;
@@ -97,26 +101,27 @@ int hook_privmsg(char *word[], char *word_eol[], void *userdata)
char *newmsg;
const char *server = xchat_get_info(ph, "server");
const char *own_nick = xchat_get_info(ph, "nick");
- IRC_CTX ircctx = {
+ IRC_CTX ircctx = {
.nick = (char*)own_nick,
- .address = (char*)server };
+ .address = (char*)server
+ };
xchat_context *query_ctx;
- if (!extract_nick(nick,word[1]))
+ if (!extract_nick(nick, word[1]))
return XCHAT_EAT_NONE;
#ifdef HAVE_GREGEX_H
- if (g_regex_match(regex_nickignore,nick,0,NULL))
+ if (g_regex_match(regex_nickignore, nick, 0, NULL))
return XCHAT_EAT_NONE;
#endif
- newmsg = otr_receive(&ircctx,word_eol[2],nick);
+ newmsg = otr_receive(&ircctx, word_eol[2], nick);
if (!newmsg) {
return XCHAT_EAT_ALL;
}
- if (newmsg==word_eol[2]) {
+ if (newmsg == word_eol[2]) {
return XCHAT_EAT_NONE;
}
@@ -132,18 +137,19 @@ int hook_privmsg(char *word[], char *word_eol[], void *userdata)
return XCHAT_EAT_ALL;
}
-void xchat_plugin_get_info(char **name, char **desc, char **version, void **reserved)
+void xchat_plugin_get_info(char **name, char **desc, char **version,
+ void **reserved)
{
- *name = PNAME;
- *desc = PDESC;
- *version = PVERSION;
+ *name = PNAME;
+ *desc = PDESC;
+ *version = PVERSION;
}
int xchat_plugin_init(xchat_plugin *plugin_handle,
- char **plugin_name,
- char **plugin_desc,
- char **plugin_version,
- char *arg)
+ char **plugin_name,
+ char **plugin_desc,
+ char **plugin_version,
+ char *arg)
{
ph = plugin_handle;
@@ -160,13 +166,13 @@ int xchat_plugin_init(xchat_plugin *plugin_handle,
xchat_hook_command(ph, "", XCHAT_PRI_NORM, hook_outgoing, 0, 0);
xchat_hook_command(ph, "otr", XCHAT_PRI_NORM, cmd_otr, 0, 0);
- otr_setpolicies(ioustate,IO_DEFAULT_POLICY,FALSE);
- otr_setpolicies(ioustate,IO_DEFAULT_POLICY_KNOWN,TRUE);
+ otr_setpolicies(ioustate, IO_DEFAULT_POLICY, FALSE);
+ otr_setpolicies(ioustate, IO_DEFAULT_POLICY_KNOWN, TRUE);
#ifdef HAVE_GREGEX_H
if (regex_nickignore)
g_regex_unref(regex_nickignore);
- regex_nickignore = g_regex_new(IO_DEFAULT_IGNORE,0,0,NULL);
+ regex_nickignore = g_regex_new(IO_DEFAULT_IGNORE, 0, 0, NULL);
#endif
xchat_print(ph, "xchat-otr loaded successfully!\n");
@@ -196,7 +202,7 @@ int xchat_plugin_deinit()
void printformat(IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...)
{
va_list params;
- va_start( params, fnum );
+ va_start(params, fnum);
char msg[LOGMAX], *s = msg;
xchat_context *find_query_ctx;
char *server = NULL;
@@ -204,9 +210,9 @@ void printformat(IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...)
if (ircctx)
server = ircctx->address;
- if (server&&nick) {
+ if (server && nick) {
find_query_ctx = xchat_find_context(ph, server, nick);
- if(find_query_ctx==NULL) {
+ if (find_query_ctx == NULL) {
// no query window yet, let's open one
xchat_commandf(ph, "query %s", nick);
find_query_ctx = xchat_find_context(ph, server, nick);
@@ -215,16 +221,18 @@ void printformat(IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...)
find_query_ctx = xchat_find_context(ph,
NULL,
xchat_get_info(ph,
- "network") ?
+ "network")
+ ?
:
- xchat_get_info(ph,"server"));
+ xchat_get_info(ph,
+ "server"));
}
xchat_set_context(ph, find_query_ctx);
- if( vsnprintf( s, LOGMAX, formats[fnum].def, params ) < 0 )
- sprintf( s, "internal error parsing error string (BUG)" );
- va_end( params );
+ if (vsnprintf(s, LOGMAX, formats[fnum].def, params) < 0)
+ sprintf(s, "internal error parsing error string (BUG)");
+ va_end(params);
xchat_printf(ph, "OTR: %s", s);
}
@@ -234,5 +242,5 @@ IRC_CTX *server_find_address(char *address)
ircctx.address = address;
- return &ircctx;
+ return &ircctx;
}
diff --git a/xchat/xchat_otr.h b/xchat/xchat_otr.h
index a8f3db3..d2295a9 100644
--- a/xchat/xchat_otr.h
+++ b/xchat/xchat_otr.h
@@ -51,34 +51,36 @@ extern char set_policy[512];
extern char set_policy_known[512];
extern char set_ignore[512];
extern int set_finishonunload;
-void cmd_set(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc,
+void cmd_set(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc,
char *argv[], char *argv_eol[], char *target);
-#define get_client_config_dir() xchat_get_info(ph,"xchatdir")
+#define get_client_config_dir() xchat_get_info(ph, "xchatdir")
void printformat(IRC_CTX *ircctx, const char *nick, int lvl, int fnum, ...);
-#define otr_noticest(formatnum,...) \
- printformat(NULL,NULL,MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__)
+#define otr_noticest(formatnum, ...) \
+ printformat(NULL, NULL, MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__)
-#define otr_notice(server,nick,formatnum,...) \
- printformat(server,nick,MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__)
+#define otr_notice(server, nick, formatnum, ...) \
+ printformat(server, nick, MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__)
-#define otr_infost(formatnum,...) \
- printformat(NULL,NULL,MSGLEVEL_CRAP, formatnum, ## __VA_ARGS__)
+#define otr_infost(formatnum, ...) \
+ printformat(NULL, NULL, MSGLEVEL_CRAP, formatnum, ## __VA_ARGS__)
-#define otr_info(server,nick,formatnum,...) \
- printformat(server,nick,MSGLEVEL_CRAP, formatnum, ## __VA_ARGS__)
+#define otr_info(server, nick, formatnum, ...) \
+ printformat(server, nick, MSGLEVEL_CRAP, formatnum, ## __VA_ARGS__)
-#define otr_debug(server,nick,formatnum,...) { \
- if (debug) \
- printformat(server,nick, \
- MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__); \
+#define otr_debug(server, nick, formatnum, ...) { \
+ if (debug) \
+ printformat(server, nick, \
+ MSGLEVEL_MSGS, formatnum, ## __VA_ARGS__); \
}
-#define IRCCTX_DUP(ircctx) g_memdup(ircctx,sizeof(IRC_CTX));
+#define IRCCTX_DUP(ircctx) g_memdup(ircctx, sizeof(IRC_CTX));
#define IRCCTX_ADDR(ircctx) ircctx->address
#define IRCCTX_NICK(ircctx) ircctx->nick
#define IRCCTX_FREE(ircctx) g_free(ircctx)
-#define IRCCTX_ACCNAME(accname,ircctx) sprintf(accname, "%s@%s", ircctx->nick, ircctx->address)
+#define IRCCTX_ACCNAME(accname, ircctx) sprintf(accname, "%s@%s", \
+ ircctx->nick, \
+ ircctx->address)
#define IRCCTX_IO_US(ircctx) (&ioustate_uniq)
#define IO_CREATE_US(user) (&ioustate_uniq)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/irssi-plugin-otr.git
More information about the Pkg-privacy-commits
mailing list