aboutsummaryrefslogtreecommitdiffstats
path: root/protocols
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2016-12-26 16:04:14 +0100
committerMarius Halden <marius.h@lden.org>2016-12-26 16:04:14 +0100
commit184c46d3507a0ff9fc68a4409f690add96cd183d (patch)
tree6fc6a92212d7e8f68107e418db50073ed8c0f88c /protocols
parent979082a36fe648b81711373c62311bcd7d9d3b54 (diff)
parent59ccef5cc9f1ed67112248c20649ce8005188173 (diff)
Merge branch 'master' into patched-master
Diffstat (limited to 'protocols')
-rw-r--r--protocols/msn/msn_util.c2
-rw-r--r--protocols/msn/soap.c4
-rw-r--r--protocols/nogaim.c90
-rw-r--r--protocols/purple/bpurple.h4
-rw-r--r--protocols/purple/purple.c75
5 files changed, 129 insertions, 46 deletions
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 5035a156..fad6976f 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;
- struct plugin_info *info;
+ 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();
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 edd1e9c3..2515f07e 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);
@@ -379,6 +402,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")) {
@@ -916,17 +943,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) {
@@ -1400,16 +1432,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);
@@ -1418,7 +1464,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);
}
@@ -1640,6 +1686,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 +1790,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 +1825,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 "