From 1a90351c2c8ad1c704da1d673fbed13e4ca6bbf3 Mon Sep 17 00:00:00 2001 From: Eion Robb Date: Tue, 9 Dec 2014 06:04:24 +0000 Subject: SkypeWeb : Add in a uri-handler for skype: uri's --- skypeweb/libskypeweb.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++- skypeweb/skypeweb_util.c | 30 +++++++++++++- skypeweb/skypeweb_util.h | 4 +- 3 files changed, 136 insertions(+), 3 deletions(-) diff --git a/skypeweb/libskypeweb.c b/skypeweb/libskypeweb.c index 11d36f7..4fbe9f6 100644 --- a/skypeweb/libskypeweb.c +++ b/skypeweb/libskypeweb.c @@ -323,6 +323,80 @@ skypeweb_close(PurpleConnection *pc) /* Plugin functions */ /******************************************************************************/ +static gboolean +skypeweb_uri_handler(const char *proto, const char *cmd, GHashTable *params) +{ + PurpleAccount *account; + PurpleConnection *pc; + + if (!g_str_equal(proto, "skype")) + return FALSE; + + /*skype uri's: + + skype: //does nothing + skype:{buddyname} //open im with {buddyname} + skype:{buddynames}?chat //open multi-user chat with {buddynames} + skype:?chat&blob={blob id} //open public multi-user chat with the blob id of {blob id} + skype:?chat&id={chat id} //open multi-user chat with the id of {chat id} + skype:{buddyname}?add //add user to buddy list + skype:{buddyname}?userinfo //get buddy's info + + skype:{buddynames}?call //call {buddynames} + skype:{buddyname}?voicemail //send a voice mail message + skype:{buddyname}?sendfile //send a file + */ + + account = find_acct(SKYPEWEB_PLUGIN_ID, g_hash_table_lookup(params, "account")); + pc = purple_account_get_connection(account); + + if (g_hash_table_lookup(params, "chat")) { + if (cmd && *cmd) { + //there'll be a bunch of usernames, seperated by semi-colon + if (strchr(cmd, ';')) { + gchar **users = g_strsplit_set(cmd, ";", -1); + skypeweb_initiate_chat(pc->proto_data, users[0]); + //TODO the other users + g_strfreev(users); + } else { + PurpleConversation *conv; + conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, cmd, account); + if (!conv) { + conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, cmd); + } + purple_conversation_present(conv); + } + } else { + //probably a public multi-user chat? + GHashTable *chatinfo; + if (g_hash_table_lookup(params, "id")) + chatinfo = skypeweb_chat_info_defaults(pc, g_hash_table_lookup(params, "id")); + else if (g_hash_table_lookup(params, "blob")) + chatinfo = skypeweb_chat_info_defaults(pc, g_hash_table_lookup(params, "blob")); + + skypeweb_join_chat(pc, chatinfo); + g_hash_table_destroy(chatinfo); + } + } else if (g_hash_table_lookup(params, "add")) { + purple_blist_request_add_buddy(account, cmd, "Skype", g_hash_table_lookup(params, "displayname")); + return TRUE; + } else if (g_hash_table_lookup(params, "call")) { + + } else if (g_hash_table_lookup(params, "userinfo")) { + skypeweb_get_info(pc, cmd); + return TRUE; + } else if (g_hash_table_lookup(params, "voicemail")) { + + } else if (g_hash_table_lookup(params, "sendfile")) { + + } else if (strlen(cmd)) { + //supposed to be the same as call? + } + + //we don't know how to handle this + return FALSE; +} + static gboolean plugin_load(PurplePlugin *plugin) { @@ -360,7 +434,36 @@ plugin_init(PurplePlugin *plugin) "always_use_https", FALSE); prpl_info->protocol_options = g_list_append( prpl_info->protocol_options, option);*/ - + + + /* + //leave + purple_cmd_register("leave", "", PURPLE_CMD_P_PRPL, PURPLE_CMD_FLAG_CHAT | + PURPLE_CMD_FLAG_PRPL_ONLY | PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, + plugin->info->id, skypeweb_cmd_leave, + _("leave [room]: Leave the chat"), NULL); + //topic + purple_cmd_register("topic", "s", PURPLE_CMD_P_PRPL, PURPLE_CMD_FLAG_CHAT | + PURPLE_CMD_FLAG_PRPL_ONLY | PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, + plugin->info->id, skypeweb_cmd_topic, + _("topic [<new topic>]: View or change the topic"), + NULL); + //call, as in call person + //kick + purple_cmd_register("kick", "s", PURPLE_CMD_P_PRPL, PURPLE_CMD_FLAG_CHAT | + PURPLE_CMD_FLAG_PRPL_ONLY, + plugin->info->id, skypeweb_cmd_kick, + _("kick <user> [room]: Kick a user from the room."), + NULL); + //kickban + purple_cmd_register("kickban", "s", PURPLE_CMD_P_PRPL, PURPLE_CMD_FLAG_CHAT | + PURPLE_CMD_FLAG_PRPL_ONLY, + plugin->info->id, skypeweb_cmd_kickban, + _("kickban <user> [room]: Kick and ban a user from the room."), + NULL); + */ + + purple_signal_connect(purple_get_core(), "uri-handler", plugin, PURPLE_CALLBACK(skypeweb_uri_handler), NULL); } static PurplePluginProtocolInfo prpl_info = { diff --git a/skypeweb/skypeweb_util.c b/skypeweb/skypeweb_util.c index b635471..0cff64f 100644 --- a/skypeweb/skypeweb_util.c +++ b/skypeweb/skypeweb_util.c @@ -67,7 +67,9 @@ skypeweb_contact_url_to_name(const gchar *url) return tempname; } - return start; + g_free(tempname); + tempname = g_strdup(start); + return tempname; } /** turn https://bay-client-s.gateway.messenger.live.com/v1/users/ME/conversations/19:blah@thread.skype @@ -200,3 +202,29 @@ skypeweb_get_js_time() return (val.tv_sec * 1000) + (val.tv_usec / 1000); } + +/* copied from oscar.c to be libpurple 2.1 compatible */ +PurpleAccount * +find_acct(const char *prpl, const char *acct_id) +{ + PurpleAccount *acct = NULL; + + /* If we have a specific acct, use it */ + if (acct_id && *acct_id) { + acct = purple_accounts_find(acct_id, prpl); + if (acct && !purple_account_is_connected(acct)) + acct = NULL; + } else { /* Otherwise find an active account for the protocol */ + GList *l = purple_accounts_get_all(); + while (l) { + if (!strcmp(prpl, purple_account_get_protocol_id(l->data)) + && purple_account_is_connected(l->data)) { + acct = l->data; + break; + } + l = l->next; + } + } + + return acct; +} diff --git a/skypeweb/skypeweb_util.h b/skypeweb/skypeweb_util.h index 2c36d35..0d97bb7 100644 --- a/skypeweb/skypeweb_util.h +++ b/skypeweb/skypeweb_util.h @@ -9,4 +9,6 @@ const gchar *skypeweb_thread_url_to_name(const gchar *url); gchar *skypeweb_hmac_sha256(gchar *input); -gint64 skypeweb_get_js_time(); \ No newline at end of file +gint64 skypeweb_get_js_time(); + +PurpleAccount *find_acct(const char *prpl, const char *acct_id); \ No newline at end of file -- cgit v1.2.3