diff --git a/account.c b/account.c index b0a14d8..39bb552 100644 --- a/account.c +++ b/account.c @@ -93,9 +93,6 @@ void account__log_emit_weechat(void *const userdata, const xmpp_log_level_t leve static const char *log_level_name[4] = {"debug", "info", "warn", "error"}; - time_t date = time(NULL); - const char *timestamp = weechat_util_get_time_string(&date); - char *xml; if ((level == XMPP_LEVEL_DEBUG) && ((xml = strchr(msg, '<')) != NULL)) { @@ -112,7 +109,7 @@ void account__log_emit_weechat(void *const userdata, const xmpp_log_level_t leve return; } xmlNodePtr root = xmlDocGetRootElement(doc); - const char *tag = root ? root->name : ""; + const char *tag = root ? (const char*)root->name : ""; const char *colour = weechat_color("blue"); if (weechat_strcasecmp(tag, "message")) { @@ -143,8 +140,10 @@ void account__log_emit_weechat(void *const userdata, const xmpp_log_level_t leve fclose(nullfd); return; } - const char **lines = weechat_string_split(buf, "\r\n", NULL, - 0, 0, &size); + char **lines = weechat_string_split((char*)buf, "\r\n", NULL, + 0, 0, &size); + if (lines[size-1][0] == 0) + lines[--size] = 0; weechat_printf( account ? account->buffer : NULL, _("%s%s (%s): %s"), @@ -155,6 +154,7 @@ void account__log_emit_weechat(void *const userdata, const xmpp_log_level_t leve account ? account->buffer : NULL, _("%s%s"), colour, lines[i]); + weechat_string_free_split(lines); fclose(nullfd); } else @@ -257,7 +257,7 @@ struct t_account *account__alloc(const char *name) void account__free_data(struct t_account *account) { - int i; + //int i; if (!account) return; @@ -535,4 +535,6 @@ int account__timer_cb(const void *pointer, void *data, int remaining_calls) || xmpp_conn_is_connected(ptr_account->connection))) connection__process(ptr_account->context, ptr_account->connection, 10); } + + return WEECHAT_RC_OK; } diff --git a/account.h b/account.h index 2f56de8..8fff73c 100644 --- a/account.h +++ b/account.h @@ -56,7 +56,7 @@ enum t_account_option struct t_account { - const char *name; + char *name; struct t_config_option *options[ACCOUNT_NUM_OPTIONS]; int reloading_from_config; @@ -65,8 +65,8 @@ struct t_account int disconnected; xmpp_log_t logger; - struct xmpp_ctx_t *context; - struct xmpp_conn_t *connection; + xmpp_ctx_t *context; + xmpp_conn_t *connection; struct t_gui_buffer *buffer; char *buffer_as_string; diff --git a/channel.c b/channel.c index 7c2f9b3..0379285 100644 --- a/channel.c +++ b/channel.c @@ -607,23 +607,23 @@ struct t_channel_member *channel__add_member(struct t_account *account, void channel__send_message(struct t_account *account, struct t_channel *channel, const char *to, const char *body) { - struct xmpp_stanza_t *message = xmpp_message_new(account->context, - channel->type == CHANNEL_TYPE_MUC - ? "groupchat" : "chat", - to, NULL); + xmpp_stanza_t *message = xmpp_message_new(account->context, + channel->type == CHANNEL_TYPE_MUC + ? "groupchat" : "chat", + to, NULL); xmpp_message_set_body(message, body); char *url = strstr(body, "http"); if (url) { - struct xmpp_stanza_t *message__x = xmpp_stanza_new(account->context); + xmpp_stanza_t *message__x = xmpp_stanza_new(account->context); xmpp_stanza_set_name(message__x, "x"); xmpp_stanza_set_ns(message__x, "jabber:x:oob"); - struct xmpp_stanza_t *message__x__url = xmpp_stanza_new(account->context); + xmpp_stanza_t *message__x__url = xmpp_stanza_new(account->context); xmpp_stanza_set_name(message__x__url, "url"); - struct xmpp_stanza_t *message__x__url__text = xmpp_stanza_new(account->context); + xmpp_stanza_t *message__x__url__text = xmpp_stanza_new(account->context); xmpp_stanza_set_text(message__x__url__text, url); xmpp_stanza_add_child(message__x__url, message__x__url__text); xmpp_stanza_release(message__x__url__text); diff --git a/command.c b/command.c index e409df3..899eeab 100644 --- a/command.c +++ b/command.c @@ -168,8 +168,10 @@ void command__account_add(int argc, char **argv) { case 5: password = argv[4]; + // fall through case 4: jid = argv[3]; + // fall through case 3: name = argv[2]; command__add_account(name, jid, password); @@ -332,7 +334,7 @@ int command__enter(const void *pointer, void *data, { struct t_account *ptr_account = NULL; struct t_channel *ptr_channel = NULL; - struct xmpp_stanza_t *pres; + xmpp_stanza_t *pres; char *jid, *pres_jid, *text; (void) pointer; @@ -354,43 +356,49 @@ int command__enter(const void *pointer, void *data, if (argc > 1) { - jid = argv[1]; - pres_jid = argv[1]; - - if(!xmpp_jid_resource(ptr_account->context, pres_jid)) - pres_jid = xmpp_jid_new( - ptr_account->context, - xmpp_jid_node(ptr_account->context, jid), - xmpp_jid_domain(ptr_account->context, jid), - account_nickname(ptr_account) - && strlen(account_nickname(ptr_account)) - ? account_nickname(ptr_account) - : xmpp_jid_node(ptr_account->context, - account_jid(ptr_account))); - - ptr_channel = channel__search(ptr_account, jid); - if (!ptr_channel) - ptr_channel = channel__new(ptr_account, CHANNEL_TYPE_MUC, jid, jid); - - pres = xmpp_presence_new(ptr_account->context); - xmpp_stanza_set_to(pres, pres_jid); - xmpp_stanza_set_from(pres, account_jid(ptr_account)); - - struct xmpp_stanza_t *pres__x = xmpp_stanza_new(ptr_account->context); - xmpp_stanza_set_name(pres__x, "x"); - xmpp_stanza_set_ns(pres__x, "http://jabber.org/protocol/muc"); - xmpp_stanza_add_child(pres, pres__x); - xmpp_stanza_release(pres__x); - - xmpp_send(ptr_account->connection, pres); - xmpp_stanza_release(pres); - - if (argc > 2) + int n_jid = 0; + char **jids = weechat_string_split(argv[1], ",", NULL, 0, 0, &n_jid); + for (int i = 0; i < n_jid; i++) { - text = argv_eol[2]; + jid = xmpp_jid_bare(ptr_account->context, jids[i]); + pres_jid = jids[i]; + + if(!xmpp_jid_resource(ptr_account->context, pres_jid)) + pres_jid = xmpp_jid_new( + ptr_account->context, + xmpp_jid_node(ptr_account->context, jid), + xmpp_jid_domain(ptr_account->context, jid), + account_nickname(ptr_account) + && strlen(account_nickname(ptr_account)) + ? account_nickname(ptr_account) + : xmpp_jid_node(ptr_account->context, + account_jid(ptr_account))); + + ptr_channel = channel__search(ptr_account, jid); + if (!ptr_channel) + ptr_channel = channel__new(ptr_account, CHANNEL_TYPE_MUC, jid, jid); + + pres = xmpp_presence_new(ptr_account->context); + xmpp_stanza_set_to(pres, pres_jid); + xmpp_stanza_set_from(pres, account_jid(ptr_account)); + + xmpp_stanza_t *pres__x = xmpp_stanza_new(ptr_account->context); + xmpp_stanza_set_name(pres__x, "x"); + xmpp_stanza_set_ns(pres__x, "http://jabber.org/protocol/muc"); + xmpp_stanza_add_child(pres, pres__x); + xmpp_stanza_release(pres__x); + + xmpp_send(ptr_account->connection, pres); + xmpp_stanza_release(pres); + + if (argc > 2) + { + text = argv_eol[2]; - channel__send_message(ptr_account, ptr_channel, jid, text); + channel__send_message(ptr_account, ptr_channel, jid, text); + } } + weechat_string_free_split(jids); } return WEECHAT_RC_OK; @@ -402,7 +410,7 @@ int command__open(const void *pointer, void *data, { struct t_account *ptr_account = NULL; struct t_channel *ptr_channel = NULL; - struct xmpp_stanza_t *pres; + xmpp_stanza_t *pres; char *jid, *text; (void) pointer; @@ -424,7 +432,7 @@ int command__open(const void *pointer, void *data, if (argc > 1) { - jid = argv[1]; + jid = xmpp_jid_bare(ptr_account->context, argv[1]); pres = xmpp_presence_new(ptr_account->context); xmpp_stanza_set_to(pres, jid); @@ -453,7 +461,7 @@ int command__me(const void *pointer, void *data, { struct t_account *ptr_account = NULL; struct t_channel *ptr_channel = NULL; - struct xmpp_stanza_t *message; + xmpp_stanza_t *message; char *text; (void) pointer; diff --git a/config.c b/config.c index 09fa0c6..8718d03 100644 --- a/config.c +++ b/config.c @@ -190,7 +190,7 @@ config__account_new_option (struct t_config_file *config_file, new_option = weechat_config_new_option ( config_file, section, option_name, "string", - N_("XMPP Channel Autojoin"), + N_("XMPP MUC Autojoins"), NULL, 0, 0, default_value, value, null_value_allowed, diff --git a/connection.c b/connection.c index 899c36b..62190d1 100644 --- a/connection.c +++ b/connection.c @@ -53,11 +53,11 @@ int version_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata) version = xmpp_stanza_new(account->context); xmpp_stanza_set_name(version, "version"); - xmpp_stanza_add_child(query, weechat_version); + xmpp_stanza_add_child(query, version); xmpp_stanza_release(version); text = xmpp_stanza_new(account->context); - xmpp_stanza_set_text(text, version); + xmpp_stanza_set_text(text, weechat_version); xmpp_stanza_add_child(version, text); xmpp_stanza_release(text); @@ -74,16 +74,17 @@ int version_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata) int presence_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata) { + (void) conn; + struct t_account *account = (struct t_account *)userdata; struct t_user *user; struct t_channel *channel; - const char *to, *from, *from_bare; + const char *from, *from_bare; from = xmpp_stanza_get_from(stanza); if (from == NULL) return 1; from_bare = xmpp_jid_bare(account->context, from); - to = xmpp_stanza_get_to(stanza); user = user__search(account, from); if (!user) @@ -103,11 +104,13 @@ int presence_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata) int message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata) { + (void) conn; + struct t_account *account = (struct t_account *)userdata; struct t_channel *channel; - xmpp_stanza_t *body, *reply, *delay, *topic; + xmpp_stanza_t *body, *delay, *topic; const char *type, *from, *from_bare, *to, *timestamp = 0; - char *intext, *replytext; + char *intext; struct tm time = {0}; time_t date = 0; @@ -164,7 +167,7 @@ int message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata) if (strcmp(to, channel->id) == 0) weechat_printf_date_tags(channel->buffer, date, NULL, "%s[to %s]: %s", - user__as_prefix_raw(account->context, from), + user__as_prefix_raw(account, from), to, intext ? intext : ""); else if (weechat_string_match(intext, "/me *", 0)) weechat_printf_date_tags(channel->buffer, date, NULL, "%s%s %s", @@ -172,7 +175,7 @@ int message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata) intext ? intext+4 : ""); else weechat_printf_date_tags(channel->buffer, date, NULL, "%s%s", - user__as_prefix_raw(account->context, from), + user__as_prefix_raw(account, from), intext ? intext : ""); if (intext) @@ -207,7 +210,7 @@ void connection__handler(xmpp_conn_t *conn, xmpp_conn_event_t status, xmpp_stanza_set_ns(pres__c, "http://jabber.org/protocol/caps"); xmpp_stanza_set_attribute(pres__c, "hash", "sha-1"); xmpp_stanza_set_attribute(pres__c, "node", "http://weechat.org"); - snprintf(cap_hash, sizeof(cap_hash), "%027d=", time(NULL)); + snprintf(cap_hash, sizeof(cap_hash), "%027ld=", time(NULL)); xmpp_stanza_set_attribute(pres__c, "ver", cap_hash); xmpp_stanza_add_child(pres, pres__c); xmpp_stanza_release(pres__c); @@ -226,17 +229,18 @@ void connection__handler(xmpp_conn_t *conn, xmpp_conn_event_t status, xmpp_send(conn, pres); xmpp_stanza_release(pres); - command__enter(NULL, NULL, account->buffer, 2, argv, argv_eol); - - xmpp_send(conn, pres); - xmpp_stanza_release(pres); + char **command = weechat_string_dyn_alloc(256); + weechat_string_dyn_concat(command, "/enter ", -1); + weechat_string_dyn_concat(command, account_autojoin(account), -1); + weechat_command(account->buffer, *command); + weechat_string_dyn_free(command, 1); } else { //weechat_printf(account->buffer, "DEBUG: disconnected"); //xmpp_stop(account->context); } } -char *const rand_string(int length) +char* rand_string(int length) { char *string = malloc(length); srand(time(NULL)); @@ -255,7 +259,7 @@ int connection__connect(struct t_account *account, xmpp_conn_t **connection, const char* jid, const char* password, int tls) { *connection = xmpp_conn_new(account->context); - char *resource = account_resource(account); + const char *resource = account_resource(account); if (!(resource && strlen(resource))) { char *const rand = rand_string(8); @@ -273,7 +277,7 @@ int connection__connect(struct t_account *account, xmpp_conn_t **connection, resource)); xmpp_conn_set_pass(*connection, password); - auto flags = xmpp_conn_get_flags(*connection); + int flags = xmpp_conn_get_flags(*connection); switch (tls) { case 0: diff --git a/plugin.c b/plugin.c index 0479cee..3905393 100644 --- a/plugin.c +++ b/plugin.c @@ -10,9 +10,9 @@ #include "plugin.h" #include "config.h" +#include "account.h" #include "connection.h" #include "command.h" -#include "account.h" #include "buffer.h" //#include "xmpp-completion.h"