From 020c61af845fbd3eea93143f83ac50587f9d33b2 Mon Sep 17 00:00:00 2001 From: Tony Olagbaiye Date: Wed, 30 Jun 2021 09:54:59 +0100 Subject: [PATCH] channels for pm --- account.c | 39 +++++----------- account.h | 4 +- channel.c | 112 +++++++++++++++------------------------------- channel.h | 83 ++++++++++++----------------------- command.c | 23 +++++----- config.c | 26 ++++++++++- connection.c | 122 +++++++++++++++++++-------------------------------- connection.h | 8 +--- plugin.c | 3 -- 9 files changed, 158 insertions(+), 262 deletions(-) diff --git a/account.c b/account.c index e70c2cc..e490634 100644 --- a/account.c +++ b/account.c @@ -28,6 +28,7 @@ char *account_options[ACCOUNT_NUM_OPTIONS][2] = { "password", "" }, { "tls", "normal" }, { "nickname", "" }, + { "autoconnect", "" }, }; struct t_account *account__search(const char *name) @@ -83,8 +84,8 @@ int account__search_option(const char *option_name) return -1; } -void log_emit_weechat(void *const userdata, const xmpp_log_level_t level, - const char *const area, const char *const msg) +void account__log_emit_weechat(void *const userdata, const xmpp_log_level_t level, + const char *const area, const char *const msg) { struct t_account *account = (struct t_account*)userdata; @@ -131,18 +132,13 @@ struct t_account *account__alloc(const char *name) /* set name */ new_account->name = strdup(name); - /* set properties */ - new_account->jid = NULL; - new_account->password = NULL; - new_account->tls = 1; - /* internal vars */ new_account->reloading_from_config = 0; new_account->is_connected = 0; new_account->disconnected = 0; - new_account->logger.handler = &log_emit_weechat; + new_account->logger.handler = &account__log_emit_weechat; new_account->logger.userdata = new_account; new_account->context = xmpp_ctx_new(NULL, &new_account->logger); new_account->connection = NULL; @@ -236,19 +232,12 @@ void account__free_data(struct t_account *account) if (account->name) free(account->name); - if (account->jid) - free(account->jid); - if (account->password) - free(account->password); - - if (account->nickname) - free(account->nickname); if (account->buffer_as_string) free(account->buffer_as_string); - channel__free_all(account); - user__free_all(account); + //channel__free_all(account); + //user__free_all(account); } void account__free(struct t_account *account) @@ -459,19 +448,11 @@ int account__connect(struct t_account *account) account__close_connection(account); - account->jid = !account->options[ACCOUNT_OPTION_JID] ? NULL : - weechat_config_string(account->options[ACCOUNT_OPTION_JID]); - account->password = !account->options[ACCOUNT_OPTION_PASSWORD] ? NULL : - weechat_config_string(account->options[ACCOUNT_OPTION_PASSWORD]); - account->tls = !account->options[ACCOUNT_OPTION_TLS] ? NULL : - weechat_config_integer(account->options[ACCOUNT_OPTION_TLS]); - account->nickname = !account->options[ACCOUNT_OPTION_NICKNAME] ? NULL : - weechat_config_string(account->options[ACCOUNT_OPTION_NICKNAME]); - account->is_connected = - connection__connect(account->context, &account->connection, - &account->logger, account->jid, - account->password, account->tls); + connection__connect(account, &account->connection, + weechat_config_string(account->options[ACCOUNT_OPTION_JID]), + weechat_config_string(account->options[ACCOUNT_OPTION_PASSWORD]), + weechat_config_string(account->options[ACCOUNT_OPTION_TLS])); return account->is_connected; } diff --git a/account.h b/account.h index c963bde..4720016 100644 --- a/account.h +++ b/account.h @@ -14,15 +14,13 @@ enum t_account_option ACCOUNT_OPTION_PASSWORD, ACCOUNT_OPTION_TLS, ACCOUNT_OPTION_NICKNAME, + ACCOUNT_OPTION_AUTOCONNECT, ACCOUNT_NUM_OPTIONS, }; struct t_account { const char *name; - const char *jid; - const char *password; - int tls; struct t_config_option *options[ACCOUNT_NUM_OPTIONS]; int reloading_from_config; diff --git a/channel.c b/channel.c index a2dd60c..546ec9c 100644 --- a/channel.c +++ b/channel.c @@ -17,7 +17,7 @@ #include "buffer.h" struct t_channel *channel__search(struct t_account *account, - const char *id) + const char *id) { struct t_channel *ptr_channel; @@ -35,8 +35,8 @@ struct t_channel *channel__search(struct t_account *account, } struct t_gui_buffer *channel__search_buffer(struct t_account *account, - enum t_channel_type type, - const char *name) + enum t_channel_type type, + const char *name) { struct t_hdata *hdata_buffer; struct t_gui_buffer *ptr_buffer; @@ -57,11 +57,9 @@ struct t_gui_buffer *channel__search_buffer(struct t_account *account, if (ptr_type && ptr_type[0] && ptr_account_name && ptr_account_name[0] && ptr_channel_name && ptr_channel_name[0] - && ( (( (type == CHANNEL_TYPE_CHANNEL) - || (type == CHANNEL_TYPE_GROUP)) + && ( (( (type == CHANNEL_TYPE_MUC)) && (strcmp(ptr_type, "channel") == 0)) - || (( (type == CHANNEL_TYPE_MPIM) - || (type == CHANNEL_TYPE_IM)) + || (( (type == CHANNEL_TYPE_PM)) && (strcmp(ptr_type, "private") == 0))) && (strcmp(ptr_account_name, account->name) == 0) && (weechat_strcasecmp(ptr_channel_name, name) == 0)) @@ -76,8 +74,8 @@ struct t_gui_buffer *channel__search_buffer(struct t_account *account, } struct t_gui_buffer *channel__create_buffer(struct t_account *account, - enum t_channel_type type, - const char *name) + enum t_channel_type type, + const char *name) { struct t_gui_buffer *ptr_buffer; int buffer_created; @@ -125,8 +123,7 @@ struct t_gui_buffer *channel__create_buffer(struct t_account *account, weechat_buffer_set(ptr_buffer, "name", buffer_name); weechat_buffer_set(ptr_buffer, "localvar_set_type", - (type == CHANNEL_TYPE_IM || - type == CHANNEL_TYPE_MPIM) ? "private" : "channel"); + (type == CHANNEL_TYPE_PM) ? "private" : "channel"); weechat_buffer_set(ptr_buffer, "localvar_set_nick", account->nickname); weechat_buffer_set(ptr_buffer, "localvar_set_server", account->name); weechat_buffer_set(ptr_buffer, "localvar_set_channel", name); @@ -137,7 +134,7 @@ struct t_gui_buffer *channel__create_buffer(struct t_account *account, WEECHAT_HOOK_SIGNAL_POINTER, ptr_buffer); weechat_buffer_set(ptr_buffer, "input_get_unknown_commands", "1"); - if (type != CHANNEL_TYPE_IM) + if (type != CHANNEL_TYPE_PM) { weechat_buffer_set(ptr_buffer, "nicklist", "1"); weechat_buffer_set(ptr_buffer, "nicklist_display_groups", "0"); @@ -157,14 +154,12 @@ struct t_gui_buffer *channel__create_buffer(struct t_account *account, } void channel__add_nicklist_groups(struct t_account *account, - struct t_channel *channel) + struct t_channel *channel) { struct t_gui_buffer *ptr_buffer; char str_group[32]; - if (channel && channel->type == CHANNEL_TYPE_MPIM) - return; - if (channel && channel->type == CHANNEL_TYPE_IM) + if (channel && channel->type == CHANNEL_TYPE_PM) return; ptr_buffer = channel ? channel->buffer : account->buffer; @@ -180,13 +175,13 @@ void channel__add_nicklist_groups(struct t_account *account, } struct t_channel *channel__new(struct t_account *account, - enum t_channel_type type, - const char *id, const char *name) + enum t_channel_type type, + const char *id, const char *name) { struct t_channel *new_channel, *ptr_channel; struct t_gui_buffer *ptr_buffer; struct t_hook *typing_timer; - char buffer_name[CHANNEL_NAME_MAX_LEN + 2]; + char buffer_name[128]; if (!account || !id || !name || !name[0]) return NULL; @@ -198,7 +193,7 @@ struct t_channel *channel__new(struct t_account *account, } buffer_name[0] = '#'; - strncpy(&buffer_name[1], name, CHANNEL_NAME_MAX_LEN + 1); + strncpy(&buffer_name[1], name, sizeof(buffer_name)); ptr_buffer = channel__create_buffer(account, type, buffer_name); if (!ptr_buffer) @@ -214,29 +209,16 @@ struct t_channel *channel__new(struct t_account *account, new_channel->type = type; new_channel->id = strdup(id); new_channel->name = strdup(name); - new_channel->created = 0; - - new_channel->is_general = 0; - new_channel->name_normalized = NULL; - new_channel->is_shared = 0; - new_channel->is_org_shared = 0; - new_channel->is_member = 0; new_channel->topic.value = NULL; new_channel->topic.creator = NULL; new_channel->topic.last_set = 0; - new_channel->purpose.value = NULL; - new_channel->purpose.creator = NULL; - new_channel->purpose.last_set = 0; - new_channel->is_archived = 0; new_channel->creator = NULL; new_channel->last_read = 0.0; new_channel->unread_count = 0; new_channel->unread_count_display = 0; - new_channel->is_user_deleted = 0; - new_channel->typing_hook_timer = typing_timer; new_channel->members_speaking[0] = NULL; new_channel->members_speaking[1] = NULL; @@ -259,8 +241,8 @@ struct t_channel *channel__new(struct t_account *account, } void channel__member_speaking_add_to_list(struct t_channel *channel, - const char *nick, - int highlight) + const char *nick, + int highlight) { int size, to_remove, i; struct t_weelist_item *ptr_item; @@ -293,7 +275,7 @@ void channel__member_speaking_add_to_list(struct t_channel *channel, } void channel__member_speaking_add(struct t_channel *channel, - const char *nick, int highlight) + const char *nick, int highlight) { if (highlight < 0) highlight = 0; @@ -306,8 +288,8 @@ void channel__member_speaking_add(struct t_channel *channel, } void channel__member_speaking_rename(struct t_channel *channel, - const char *old_nick, - const char *new_nick) + const char *old_nick, + const char *new_nick) { struct t_weelist_item *ptr_item; int i; @@ -324,8 +306,8 @@ void channel__member_speaking_rename(struct t_channel *channel, } void channel__member_speaking_rename_if_present(struct t_account *account, - struct t_channel *channel, - const char *nick) + struct t_channel *channel, + const char *nick) { struct t_weelist_item *ptr_item; int i, j, list_size; @@ -348,7 +330,7 @@ void channel__member_speaking_rename_if_present(struct t_account *account, } void channel__typing_free(struct t_channel *channel, - struct t_channel_typing *typing) + struct t_channel_typing *typing) { struct t_channel_typing *new_typings; @@ -387,8 +369,8 @@ void channel__typing_free_all(struct t_channel *channel) } int channel__typing_cb(const void *pointer, - void *data, - int remaining_calls) + void *data, + int remaining_calls) { struct t_channel_typing *ptr_typing, *next_typing; struct t_channel *channel; @@ -437,9 +419,8 @@ int channel__typing_cb(const void *pointer, return WEECHAT_RC_OK; } -struct t_channel_typing *channel__typing_search( - struct t_channel *channel, - const char *id) +struct t_channel_typing *channel__typing_search(struct t_channel *channel, + const char *id) { struct t_channel_typing *ptr_typing; @@ -457,7 +438,7 @@ struct t_channel_typing *channel__typing_search( } void channel__add_typing(struct t_channel *channel, - struct t_user *user) + struct t_user *user) { struct t_channel_typing *new_typing; @@ -482,7 +463,7 @@ void channel__add_typing(struct t_channel *channel, } void channel__member_free(struct t_channel *channel, - struct t_channel_member *member) + struct t_channel_member *member) { struct t_channel_member *new_members; @@ -519,7 +500,7 @@ void channel__member_free_all(struct t_channel *channel) } void channel__free(struct t_account *account, - struct t_channel *channel) + struct t_channel *channel) { struct t_channel *new_channels; @@ -553,16 +534,10 @@ void channel__free(struct t_account *account, free(channel->id); if (channel->name) free(channel->name); - if (channel->name_normalized) - free(channel->name_normalized); if (channel->topic.value) free(channel->topic.value); if (channel->topic.creator) free(channel->topic.creator); - if (channel->purpose.value) - free(channel->purpose.value); - if (channel->purpose.creator) - free(channel->purpose.creator); if (channel->creator) free(channel->creator); if (channel->members_speaking[0]) @@ -584,9 +559,9 @@ void channel__free_all(struct t_account *account) } void channel__update_topic(struct t_channel *channel, - const char* topic, - const char* creator, - int last_set) + const char* topic, + const char* creator, + int last_set) { if (channel->topic.value) free(channel->topic.value); @@ -602,24 +577,9 @@ void channel__update_topic(struct t_channel *channel, weechat_buffer_set(channel->buffer, "title", ""); } -void channel__update_purpose(struct t_channel *channel, - const char* purpose, - const char* creator, - int last_set) -{ - if (channel->purpose.value) - free(channel->purpose.value); - if (channel->purpose.creator) - free(channel->purpose.creator); - channel->purpose.value = (purpose) ? strdup(purpose) : NULL; - channel->purpose.creator = (creator) ? strdup(creator) : NULL; - channel->purpose.last_set = last_set; -} - -struct t_channel_member *channel__add_member( - struct t_account *account, - struct t_channel *channel, - const char *id) +struct t_channel_member *channel__add_member(struct t_account *account, + struct t_channel *channel, + const char *id) { struct t_channel_member *member; struct t_user *user; diff --git a/channel.h b/channel.h index 5b79c79..3498c47 100644 --- a/channel.h +++ b/channel.h @@ -7,14 +7,10 @@ #define CHANNEL_MEMBERS_SPEAKING_LIMIT 128 -#define CHANNEL_NAME_MAX_LEN 22 - enum t_channel_type { - CHANNEL_TYPE_CHANNEL, - CHANNEL_TYPE_GROUP, - CHANNEL_TYPE_MPIM, - CHANNEL_TYPE_IM, + CHANNEL_TYPE_MUC, + CHANNEL_TYPE_PM, }; struct t_channel_typing @@ -42,31 +38,13 @@ struct t_channel_topic time_t last_set; }; -struct t_channel_purpose -{ - char *value; - char *creator; - time_t last_set; -}; - struct t_channel { - enum t_channel_type type; + enum t_channel_type type; char *id; char *name; - time_t created; - - /* channel */ - int is_general; - char *name_normalized; - int is_shared; - int is_org_shared; - int is_member; - /* group */ struct t_channel_topic topic; - struct t_channel_purpose purpose; - int is_archived; /* mpim */ char *creator; @@ -74,9 +52,6 @@ struct t_channel int unread_count; int unread_count_display; - /* im */ - int is_user_deleted; - struct t_hook *typing_hook_timer; struct t_weelist *members_speaking[2]; struct t_channel_typing *typings; @@ -91,57 +66,55 @@ struct t_channel }; struct t_channel *channel__search(struct t_account *account, - const char *id); + const char *id); void channel__add_nicklist_groups(struct t_account *account, - struct t_channel *channel); + struct t_channel *channel); struct t_channel *channel__new(struct t_account *account, - enum t_channel_type type, - const char *id, const char *name); + enum t_channel_type type, + const char *id, const char *name); void channel__member_speaking_add(struct t_channel *channel, - const char *nick, int highlight); + const char *nick, int highlight); void channel__member_speaking_rename(struct t_channel *channel, - const char *old_nick, - const char *new_nick); + const char *old_nick, + const char *new_nick); void channel__member_speaking_rename_if_present(struct t_account *account, - struct t_channel *channel, - const char *nick); + struct t_channel *channel, + const char *nick); void channel__typing_free(struct t_channel *channel, - struct t_channel_typing *typing); + struct t_channel_typing *typing); void channel__typing_free_all(struct t_channel *channel); int channel__typing_cb(const void *pointer, - void *data, - int remaining_calls); + void *data, + int remaining_calls); -struct t_channel_typing *channel__typing_search( - struct t_channel *channel, - const char *id); +struct t_channel_typing *channel__typing_search(struct t_channel *channel, + const char *id); void channel__add_typing(struct t_channel *channel, - struct t_user *user); + struct t_user *user); void channel__free_all(struct t_account *account); void channel__update_topic(struct t_channel *channel, - const char* title, - const char* creator, - int last_set); + const char* title, + const char* creator, + int last_set); void channel__update_purpose(struct t_channel *channel, - const char* purpose, - const char* creator, - int last_set); - -struct t_channel_member *channel__add_member( - struct t_account *account, - struct t_channel *channel, - const char *id); + const char* purpose, + const char* creator, + int last_set); + +struct t_channel_member *channel__add_member(struct t_account *account, + struct t_channel *channel, + const char *id); #endif /*WEECHAT_XMPP_CHANNEL_H*/ diff --git a/command.c b/command.c index fe39db0..6ed8acd 100644 --- a/command.c +++ b/command.c @@ -33,7 +33,7 @@ void command__display_account(struct t_account *account) weechat_color("reset"), weechat_color("chat_delimiters"), weechat_color("chat_server"), - (account->jid) ? account->jid : "???", + weechat_config_string(account->options[ACCOUNT_OPTION_JID]), weechat_color("chat_delimiters"), weechat_color("reset"), (account->is_connected) ? _("connected") : _("not connected"), @@ -53,7 +53,7 @@ void command__display_account(struct t_account *account) weechat_color("reset"), weechat_color("chat_delimiters"), weechat_color("chat_server"), - (account->jid) ? account->jid : "???", + weechat_config_string(account->options[ACCOUNT_OPTION_JID]), weechat_color("chat_delimiters"), weechat_color("reset")); } @@ -138,17 +138,14 @@ void command__add_account(const char *name, const char *jid, const char *passwor account->name = strdup(name); if (jid) - account->jid = strdup(jid); + weechat_config_option_set(account->options[ACCOUNT_OPTION_JID], + strdup(jid), 1); if (password) - account->password = strdup(password); - weechat_config_option_set(account->options[ACCOUNT_OPTION_JID], - account->jid, 1); - weechat_config_option_set(account->options[ACCOUNT_OPTION_PASSWORD], - account->password, 1); - weechat_config_option_set(account->options[ACCOUNT_OPTION_NICKNAME], - account->jid ? xmpp_jid_node(account->context, - account->jid) - : NULL, 1); + weechat_config_option_set(account->options[ACCOUNT_OPTION_PASSWORD], + strdup(password), 1); + if (jid) + weechat_config_option_set(account->options[ACCOUNT_OPTION_NICKNAME], + strdup(xmpp_jid_node(account->context, jid)), 1); weechat_printf ( NULL, @@ -159,7 +156,7 @@ void command__add_account(const char *name, const char *jid, const char *passwor weechat_color("reset"), weechat_color("chat_delimiters"), weechat_color("chat_server"), - account->jid ? account->jid : "???", + jid ? jid : "???", weechat_color("chat_delimiters"), weechat_color("reset")); } diff --git a/config.c b/config.c index dcc1c2c..b2cf31f 100644 --- a/config.c +++ b/config.c @@ -126,7 +126,23 @@ config__account_new_option (struct t_config_file *config_file, new_option = weechat_config_new_option ( config_file, section, option_name, "string", - N_("XMPP Server JID"), + N_("XMPP Account Nickname"), + NULL, 0, 0, + default_value, value, + null_value_allowed, + callback_check_value, + callback_check_value_pointer, + callback_check_value_data, + callback_change, + callback_change_pointer, + callback_change_data, + NULL, NULL, NULL); + break; + case ACCOUNT_OPTION_AUTOCONNECT: + new_option = weechat_config_new_option ( + config_file, section, + option_name, "boolean", + N_("Autoconnect XMPP Account"), NULL, 0, 0, default_value, value, null_value_allowed, @@ -216,6 +232,14 @@ int config__account_read_cb (const void *pointer, void *data, ACCOUNT_NUM_OPTIONS; rc = weechat_config_option_set( ptr_account->options[index_option], value, 1); + if (!ptr_account->reloading_from_config) + { + const char *ac_global = weechat_info_get("auto_connect", NULL); + int ac_local = weechat_config_boolean( + ptr_account->options[ACCOUNT_OPTION_AUTOCONNECT]); + if (ac_local && (strcmp(ac_global, "1") == 0)) + account__connect(ptr_account); + } } else { diff --git a/connection.c b/connection.c index 0f0b93e..07e919b 100644 --- a/connection.c +++ b/connection.c @@ -9,13 +9,9 @@ #include "plugin.h" #include "config.h" +#include "account.h" +#include "channel.h" #include "connection.h" -//#include "api/xmpp-api-hello.h" -//#include "api/xmpp-api-error.h" -//#include "api/xmpp-api-message.h" -//#include "api/xmpp-api-user-typing.h" - -xmpp_conn_t *connection; void connection__init() { @@ -26,37 +22,39 @@ int version_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata) { xmpp_stanza_t *reply, *query, *name, *version, *text; const char *ns; - xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata; + struct t_account *account = (struct t_account *)userdata; + const char *weechat_name = "weechat"; + const char *weechat_version = weechat_info_get("version", NULL); weechat_printf(NULL, "Received version request from %s", xmpp_stanza_get_from(stanza)); reply = xmpp_stanza_reply(stanza); xmpp_stanza_set_type(reply, "result"); - query = xmpp_stanza_new(ctx); + query = xmpp_stanza_new(account->context); xmpp_stanza_set_name(query, "query"); ns = xmpp_stanza_get_ns(xmpp_stanza_get_children(stanza)); if (ns) { xmpp_stanza_set_ns(query, ns); } - name = xmpp_stanza_new(ctx); + name = xmpp_stanza_new(account->context); xmpp_stanza_set_name(name, "name"); xmpp_stanza_add_child(query, name); xmpp_stanza_release(name); - text = xmpp_stanza_new(ctx); - xmpp_stanza_set_text(text, "libstrophe example bot"); + text = xmpp_stanza_new(account->context); + xmpp_stanza_set_text(text, weechat_name); xmpp_stanza_add_child(name, text); xmpp_stanza_release(text); - version = xmpp_stanza_new(ctx); + version = xmpp_stanza_new(account->context); xmpp_stanza_set_name(version, "version"); - xmpp_stanza_add_child(query, version); + xmpp_stanza_add_child(query, weechat_version); xmpp_stanza_release(version); - text = xmpp_stanza_new(ctx); - xmpp_stanza_set_text(text, "1.0"); + text = xmpp_stanza_new(account->context); + xmpp_stanza_set_text(text, version); xmpp_stanza_add_child(version, text); xmpp_stanza_release(text); @@ -65,14 +63,17 @@ int version_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata) xmpp_send(conn, reply); xmpp_stanza_release(reply); + if (version) + free (version); + return 1; } int message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata) { - xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata; + struct t_account *account = (struct t_account *)userdata; xmpp_stanza_t *body, *reply; - const char *type; + const char *type, *from, *from_jid; char *intext, *replytext; int quit = 0; @@ -82,68 +83,68 @@ int message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata) type = xmpp_stanza_get_type(stanza); if (type != NULL && strcmp(type, "error") == 0) return 1; + from = xmpp_stanza_get_from(stanza); + from_jid = xmpp_jid_bare(account->context, from); intext = xmpp_stanza_get_text(body); - weechat_printf(NULL, "Incoming message from %s: %s", xmpp_stanza_get_from(stanza), - intext); + struct t_channel *channel = channel__search(account, from_jid); + if (!channel) + channel = channel__new(account, CHANNEL_TYPE_PM, from_jid, from_jid); + + weechat_printf(channel->buffer, "%s: %s", from_jid, intext); reply = xmpp_stanza_reply(stanza); if (xmpp_stanza_get_type(reply) == NULL) xmpp_stanza_set_type(reply, "chat"); - if (strcmp(intext, "quit") == 0) { - replytext = strdup("bye!"); - quit = 1; - } else { - replytext = (char *)malloc(strlen(" to you too!") + strlen(intext) + 1); - strcpy(replytext, intext); - strcat(replytext, " to you too!"); - } - xmpp_free(ctx, intext); + replytext = (char *)malloc(strlen(" received!") + strlen(intext) + 1); + strcpy(replytext, intext); + strcat(replytext, " received!"); + + xmpp_free(account->context, intext); xmpp_message_set_body(reply, replytext); xmpp_send(conn, reply); xmpp_stanza_release(reply); + weechat_printf(channel->buffer, "%s: %s", + weechat_config_string(account->options[ACCOUNT_OPTION_JID]), + replytext); free(replytext); - if (quit) - xmpp_disconnect(conn); - return 1; } void connection__handler(xmpp_conn_t *conn, xmpp_conn_event_t status, - int error, xmpp_stream_error_t *stream_error, - void *userdata) + int error, xmpp_stream_error_t *stream_error, + void *userdata) { - xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata; + struct t_account *account = (struct t_account *)userdata; (void)error; (void)stream_error; if (status == XMPP_CONN_CONNECT) { xmpp_stanza_t *pres; - weechat_printf(NULL, "DEBUG: connected"); + weechat_printf(account->buffer, "DEBUG: connected"); xmpp_handler_add(conn, version_handler, "jabber:iq:version", "iq", NULL, - ctx); - xmpp_handler_add(conn, message_handler, NULL, "message", NULL, ctx); + account); + xmpp_handler_add(conn, message_handler, NULL, "message", NULL, account); /* Send initial so that we appear online to contacts */ - pres = xmpp_presence_new(ctx); + pres = xmpp_presence_new(account->context); xmpp_send(conn, pres); xmpp_stanza_release(pres); } else { - weechat_printf(NULL, "DEBUG: disconnected"); - xmpp_stop(ctx); + weechat_printf(account->buffer, "DEBUG: disconnected"); + //xmpp_stop(account->context); } } -int connection__connect(xmpp_ctx_t *context, xmpp_conn_t **connection, - xmpp_log_t *logger, const char* jid, - const char* password, int tls) +int connection__connect(struct t_account *account, xmpp_conn_t **connection, + const char* jid, const char* password, int tls) { - *connection = xmpp_conn_new(context); + *connection = xmpp_conn_new(account->context); xmpp_conn_set_jid(*connection, jid); xmpp_conn_set_pass(*connection, password); @@ -163,7 +164,7 @@ int connection__connect(xmpp_ctx_t *context, xmpp_conn_t **connection, } xmpp_conn_set_flags(*connection, flags); - if (xmpp_connect_client(*connection, NULL, 0, &connection__handler, context) + if (xmpp_connect_client(*connection, NULL, 0, &connection__handler, account) != XMPP_EOK) { weechat_printf( @@ -174,11 +175,6 @@ int connection__connect(xmpp_ctx_t *context, xmpp_conn_t **connection, return 0; } - weechat_printf( - NULL, - _("%s%s: c'necting to %s"), - weechat_prefix("error"), WEECHAT_XMPP_PLUGIN_NAME, - jid); return 1; } @@ -191,29 +187,3 @@ void connection__process(xmpp_ctx_t *context, xmpp_conn_t *connection, timeout); } } - -int connection__route_message(xmpp_conn_t *workspace, - const char *type, void *message) -{ - //struct stringcase key; - //key.string = type; - - //size_t case_count = sizeof(cases) / sizeof(cases[0]); - //void *entry_ptr = bsearch(&key, cases, case_count, - // sizeof(struct stringcase), stringcase_cmp); - - //if (entry_ptr) - //{ - // struct stringcase *entry = (struct stringcase *)entry_ptr; - // return (*entry->func)(workspace, message); - //} - //else - //{ - // weechat_printf( - // workspace->buffer, - // _("%s%s: got unhandled message of type: %s"), - // weechat_prefix("error"), XMPP_PLUGIN_NAME, - // type); - return 1; - //} -} diff --git a/connection.h b/connection.h index 1b049ea..54eb1dc 100644 --- a/connection.h +++ b/connection.h @@ -7,14 +7,10 @@ void connection__init(); -int connection__connect(xmpp_ctx_t *context, xmpp_conn_t **connection, - xmpp_log_t *logger, const char* jid, - const char* password, int tls); +int connection__connect(struct t_account *account, xmpp_conn_t **connection, + const char* jid, const char* password, int tls); void connection__process(xmpp_ctx_t *context, xmpp_conn_t *connection, const unsigned long timeout); -int connection__route_message(xmpp_conn_t *connection, - const char *type, void *message); - #endif /*WEECHAT_XMPP_CONNECTION_H*/ diff --git a/plugin.c b/plugin.c index fc0c9f2..02fa0a5 100644 --- a/plugin.c +++ b/plugin.c @@ -26,7 +26,6 @@ WEECHAT_PLUGIN_PRIORITY(5500); struct t_weechat_plugin *weechat_xmpp_plugin = NULL; -struct t_hook *weechat_xmpp_autoconnect_timer = NULL; struct t_hook *weechat_xmpp_process_timer = NULL; struct t_gui_bar_item *weechat_xmpp_typing_bar_item = NULL; @@ -76,8 +75,6 @@ int weechat_plugin_end(struct t_weechat_plugin *plugin) if (weechat_xmpp_typing_bar_item) weechat_bar_item_remove(weechat_xmpp_typing_bar_item); - if (weechat_xmpp_autoconnect_timer) - weechat_unhook(weechat_xmpp_autoconnect_timer); if (weechat_xmpp_process_timer) weechat_unhook(weechat_xmpp_process_timer);