From 87872c712535013cbba81653021a41091a9ed7f2 Mon Sep 17 00:00:00 2001 From: dequis Date: Mon, 28 Nov 2016 02:52:22 -0300 Subject: purple: Use roomlist_room_serialize, fixes joining jabber chats The room names in 'chat list' were missing the server part. Jabber is the only prpl which implements this method as far as I can see, and it's needed to get the full name. --- protocols/purple/purple.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'protocols') diff --git a/protocols/purple/purple.c b/protocols/purple/purple.c index c7123798..8b3b8c7c 100644 --- a/protocols/purple/purple.c +++ b/protocols/purple/purple.c @@ -1386,16 +1386,30 @@ static void prplcb_roomlist_set_fields(PurpleRoomlist *list, GList *fields) } } +static char *prplcb_roomlist_get_room_name(PurpleRoomlist *list, PurpleRoomlistRoom *room) +{ + struct im_connection *ic = purple_ic_by_pa(list->account); + struct purple_data *pd = ic->proto_data; + PurplePlugin *prpl = purple_plugins_find_with_id(pd->account->protocol_id); + PurplePluginProtocolInfo *pi = prpl->info->extra_info; + + if (pi && pi->roomlist_room_serialize) { + return pi->roomlist_room_serialize(room); + } else { + return g_strdup(purple_roomlist_room_get_name(room)); + } +} + static void prplcb_roomlist_add_room(PurpleRoomlist *list, PurpleRoomlistRoom *room) { bee_chat_info_t *ci; - const char *title; + char *title; const char *topic; GList *fields; struct purple_roomlist_data *rld = list->ui_data; fields = purple_roomlist_room_get_fields(room); - title = purple_roomlist_room_get_name(room); + title = prplcb_roomlist_get_room_name(list, room); if (rld->topic >= 0) { topic = g_list_nth_data(fields, rld->topic); @@ -1404,7 +1418,7 @@ static void prplcb_roomlist_add_room(PurpleRoomlist *list, PurpleRoomlistRoom *r } ci = g_new(bee_chat_info_t, 1); - ci->title = g_strdup(title); + ci->title = title; ci->topic = g_strdup(topic); rld->chats = g_slist_prepend(rld->chats, ci); } -- cgit v1.2.3 From 0483e1e6e3954787058aff78223cb758f0074f2d Mon Sep 17 00:00:00 2001 From: dequis Date: Mon, 28 Nov 2016 16:26:16 -0300 Subject: Fix some compiler warnings warn_unused_result on write() is particularly annoying. You can't just add (void) to ignore it due to gcc bug 66425. I replaced some of those with fwrite() and used a variable marked with the G_GNUC_UNUSED attribute for the writes from signal handlers. --- protocols/msn/msn_util.c | 2 +- protocols/msn/soap.c | 4 ++-- protocols/nogaim.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'protocols') diff --git a/protocols/msn/msn_util.c b/protocols/msn/msn_util.c index 763b2768..af00e461 100644 --- a/protocols/msn/msn_util.c +++ b/protocols/msn/msn_util.c @@ -179,7 +179,7 @@ void msn_queue_feed(struct msn_data *h, char *bytes, int st) if (getenv("BITLBEE_DEBUG")) { fprintf(stderr, "\n\x1b[92m<<< "); - write(2, bytes , st); + fwrite(bytes, st, 1, stderr); fprintf(stderr, "\x1b[97m"); } } diff --git a/protocols/msn/soap.c b/protocols/msn/soap.c index 1fa22d13..14aaed11 100644 --- a/protocols/msn/soap.c +++ b/protocols/msn/soap.c @@ -212,9 +212,9 @@ static void msn_soap_debug_print(const char *headers, const char *payload) if (headers) { if ((s = strstr(headers, "\r\n\r\n"))) { - write(2, headers, s - headers + 4); + fwrite(headers, s - headers + 4, 1, stderr); } else { - write(2, headers, strlen(headers)); + fwrite(headers, strlen(headers), 1, stderr); } } diff --git a/protocols/nogaim.c b/protocols/nogaim.c index 2f6b3783..e4db7024 100644 --- a/protocols/nogaim.c +++ b/protocols/nogaim.c @@ -53,7 +53,7 @@ gboolean load_plugin(char *path) { GList *l; struct plugin_info *i; - struct plugin_info *info; + struct plugin_info *info = NULL; struct plugin_info * (*info_function) (void) = NULL; void (*init_function) (void); -- cgit v1.2.3 From 7486853ca817c0e6d0a5b3d1b702d6bd8e96bf4e Mon Sep 17 00:00:00 2001 From: dequis Date: Sun, 25 Dec 2016 20:10:58 -0300 Subject: Refactor: Split plugin info stuff from load_plugin() into two functions --- protocols/nogaim.c | 88 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 35 deletions(-) (limited to 'protocols') diff --git a/protocols/nogaim.c b/protocols/nogaim.c index e4db7024..3fed2728 100644 --- a/protocols/nogaim.c +++ b/protocols/nogaim.c @@ -49,16 +49,64 @@ static gint pluginscmp(gconstpointer a, gconstpointer b, gpointer data) return g_strcasecmp(ia->name, ib->name); } -gboolean load_plugin(char *path) +/* semi-private */ +gboolean plugin_info_validate(struct plugin_info *info, const char *path) { GList *l; - struct plugin_info *i; + gboolean loaded = FALSE; + + if (!path) { + path = "(null)"; + } + + if (info->abiver != BITLBEE_ABI_VERSION_CODE) { + log_message(LOGLVL_ERROR, + "`%s' uses ABI %u but %u is required\n", + path, info->abiver, + BITLBEE_ABI_VERSION_CODE); + return FALSE; + } + + if (!info->name || !info->version) { + log_message(LOGLVL_ERROR, + "Name or version missing from the " + "plugin info in `%s'\n", path); + return FALSE; + } + + for (l = plugins; l; l = l->next) { + struct plugin_info *i = l->data; + + if (g_strcasecmp(i->name, info->name) == 0) { + loaded = TRUE; + break; + } + } + + if (loaded) { + log_message(LOGLVL_WARNING, + "%s plugin already loaded\n", + info->name); + return FALSE; + } + + return TRUE; +} + +/* semi-private */ +gboolean plugin_info_add(struct plugin_info *info) +{ + plugins = g_list_insert_sorted_with_data(plugins, info, pluginscmp, NULL); + return TRUE; +} + +gboolean load_plugin(char *path) +{ struct plugin_info *info = NULL; struct plugin_info * (*info_function) (void) = NULL; void (*init_function) (void); GModule *mod = g_module_open(path, G_MODULE_BIND_LAZY); - gboolean loaded = FALSE; if (!mod) { log_message(LOGLVL_ERROR, "Error loading plugin `%s': %s\n", path, g_module_error()); @@ -68,36 +116,7 @@ gboolean load_plugin(char *path) if (g_module_symbol(mod, "init_plugin_info", (gpointer *) &info_function)) { info = info_function(); - if (info->abiver != BITLBEE_ABI_VERSION_CODE) { - log_message(LOGLVL_ERROR, - "`%s' uses ABI %u but %u is required\n", - path, info->abiver, - BITLBEE_ABI_VERSION_CODE); - g_module_close(mod); - return FALSE; - } - - if (!info->name || !info->version) { - log_message(LOGLVL_ERROR, - "Name or version missing from the " - "plugin info in `%s'\n", path); - g_module_close(mod); - return FALSE; - } - - for (l = plugins; l; l = l->next) { - i = l->data; - - if (g_strcasecmp(i->name, info->name) == 0) { - loaded = TRUE; - break; - } - } - - if (loaded) { - log_message(LOGLVL_WARNING, - "%s plugin already loaded\n", - info->name); + if (!plugin_info_validate(info, path)) { g_module_close(mod); return FALSE; } @@ -112,8 +131,7 @@ gboolean load_plugin(char *path) } if (info_function) { - plugins = g_list_insert_sorted_with_data(plugins, info, - pluginscmp, NULL); + plugin_info_add(info); } init_function(); -- cgit v1.2.3 From 6d212f401cf7eeb3eabe315e610578f5aac74607 Mon Sep 17 00:00:00 2001 From: dequis Date: Sun, 25 Dec 2016 20:41:13 -0300 Subject: purple: include purple plugins in the 'plugins' command list --- protocols/purple/purple.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'protocols') diff --git a/protocols/purple/purple.c b/protocols/purple/purple.c index 8b3b8c7c..49c1ee7c 100644 --- a/protocols/purple/purple.c +++ b/protocols/purple/purple.c @@ -1640,6 +1640,10 @@ static void purple_ui_init() } } +/* borrowing this semi-private function + * TODO: figure out a better interface later (famous last words) */ +gboolean plugin_info_add(struct plugin_info *info); + void purple_initmodule() { struct prpl funcs; @@ -1740,6 +1744,7 @@ void purple_initmodule() PurplePlugin *prot = prots->data; PurplePluginProtocolInfo *pi = prot->info->extra_info; struct prpl *ret; + struct plugin_info *info; /* If we already have this one (as a native module), don't add a libpurple duplicate. */ @@ -1774,6 +1779,16 @@ void purple_initmodule() ret->data = NULL; register_protocol(ret); } + + info = g_new0(struct plugin_info, 1); + info->abiver = BITLBEE_ABI_VERSION_CODE; + info->name = ret->name; + info->version = prot->info->version; + info->description = prot->info->description; + info->author = prot->info->author; + info->url = prot->info->homepage; + + plugin_info_add(info); } g_string_append(help, "\n\nFor used protocols, more information about available " -- cgit v1.2.3 From 59ccef5cc9f1ed67112248c20649ce8005188173 Mon Sep 17 00:00:00 2001 From: dequis Date: Sun, 25 Dec 2016 21:13:57 -0300 Subject: purple: Call imcb_buddy_nick_change() on a few whitelisted plugins The whitelist includes hangouts, funyahoo and icq. These plugins tend to have numeric or meaningless usernames. With this change, users don't have to do 'ac whatever set nick_format %full_name' anymore. Just sugar. --- protocols/purple/bpurple.h | 4 ++++ protocols/purple/purple.c | 40 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) (limited to 'protocols') diff --git a/protocols/purple/bpurple.h b/protocols/purple/bpurple.h index 81be2575..9b34cdff 100644 --- a/protocols/purple/bpurple.h +++ b/protocols/purple/bpurple.h @@ -6,6 +6,8 @@ #define PURPLE_REQUEST_HANDLE "purple_request" +#define PURPLE_OPT_SHOULD_SET_NICK 1 + struct purple_data { PurpleAccount *account; @@ -14,6 +16,8 @@ struct purple_data guint next_request_id; char *chat_list_server; GSList *filetransfers; + + int flags; }; #endif /* !BPURPLE_H */ diff --git a/protocols/purple/purple.c b/protocols/purple/purple.c index 49c1ee7c..9e0dc57e 100644 --- a/protocols/purple/purple.c +++ b/protocols/purple/purple.c @@ -113,6 +113,29 @@ static char *purple_get_account_prpl_id(account_t *acc) return acc->prpl->data; } +static gboolean purple_account_should_set_nick(account_t *acc) +{ + /* whitelist of protocols that tend to have numeric or meaningless usernames, and should + * always offer the 'alias' as a nick. this is just so that users don't have to do + * 'account whatever set nick_format %full_name' + */ + char *whitelist[] = { + "prpl-hangouts", + "prpl-eionrobb-funyahoo-plusplus", + "prpl-icq", + NULL, + }; + char **p; + + for (p = whitelist; *p; p++) { + if (g_strcmp0(acc->prpl->data, *p) == 0) { + return TRUE; + } + } + + return FALSE; +} + static void purple_init(account_t *acc) { char *prpl_id = purple_get_account_prpl_id(acc); @@ -367,6 +390,10 @@ static void purple_login(account_t *acc) purple_account_set_password(pd->account, acc->pass); purple_sync_settings(acc, pd->account); + if (purple_account_should_set_nick(acc)) { + pd->flags = PURPLE_OPT_SHOULD_SET_NICK; + } + purple_account_set_enabled(pd->account, "BitlBee", TRUE); if (set_getbool(&acc->set, "mail_notifications") && set_getstr(&acc->set, "mail_notifications_handle")) { @@ -902,17 +929,22 @@ static void prplcb_blist_update(PurpleBuddyList *list, PurpleBlistNode *node) PurpleBuddy *bud = (PurpleBuddy *) node; PurpleGroup *group = purple_buddy_get_group(bud); struct im_connection *ic = purple_ic_by_pa(bud->account); + struct purple_data *pd = ic->proto_data; PurpleStatus *as; int flags = 0; + char *alias = NULL; if (ic == NULL) { return; } - if (bud->server_alias) { - imcb_rename_buddy(ic, bud->name, bud->server_alias); - } else if (bud->alias) { - imcb_rename_buddy(ic, bud->name, bud->alias); + alias = bud->server_alias ? : bud->alias; + + if (alias) { + imcb_rename_buddy(ic, bud->name, alias); + if (pd->flags & PURPLE_OPT_SHOULD_SET_NICK) { + imcb_buddy_nick_change(ic, bud->name, alias); + } } if (group) { -- cgit v1.2.3