libpurple/protocols/myspace/myspace.c

branch
soc.2013.gobjectification.plugins
changeset 36526
44cfe9e574d8
parent 34868
faa5b053f310
child 36536
07f8c9889257
equal deleted inserted replaced
36525:ea477f05a2ea 36526:44cfe9e574d8
30 * You should have received a copy of the GNU General Public License 30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software 31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 32 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
33 */ 33 */
34 34
35 #define PURPLE_PLUGIN 35 #include "plugins.h"
36
37 #include "myspace.h" 36 #include "myspace.h"
38 37
39 static void msim_set_status(PurpleAccount *account, PurpleStatus *status); 38 static void msim_set_status(PurpleAccount *account, PurpleStatus *status);
40 static void msim_set_idle(PurpleConnection *gc, int time); 39 static void msim_set_idle(PurpleConnection *gc, int time);
41 40
3000 2999
3001 return table; 3000 return table;
3002 } 3001 }
3003 3002
3004 /** 3003 /**
3004 * Called when friends have been imported to buddy list on server.
3005 */
3006 static void
3007 msim_import_friends_cb(MsimSession *session, const MsimMessage *reply, gpointer user_data)
3008 {
3009 MsimMessage *body;
3010 gchar *completed;
3011
3012 /* Check if the friends were imported successfully. */
3013 body = msim_msg_get_dictionary(reply, "body");
3014 g_return_if_fail(body != NULL);
3015 completed = msim_msg_get_string(body, "Completed");
3016 msim_msg_free(body);
3017 g_return_if_fail(completed != NULL);
3018 if (!g_str_equal(completed, "True"))
3019 {
3020 purple_debug_info("msim_import_friends_cb",
3021 "failed to import friends: %s", completed);
3022 purple_notify_error(session->account, _("Add friends from MySpace.com"),
3023 _("Importing friends failed"), NULL);
3024 g_free(completed);
3025 return;
3026 }
3027 g_free(completed);
3028
3029 purple_debug_info("msim_import_friends_cb",
3030 "added friends to server-side buddy list, requesting new contacts from server");
3031
3032 msim_get_contact_list(session, MSIM_CONTACT_LIST_IMPORT_ALL_FRIENDS);
3033
3034 /* TODO: show, X friends have been added */
3035 }
3036
3037 /**
3038 * Import friends from myspace.com.
3039 */
3040 static void msim_import_friends(PurpleProtocolAction *action)
3041 {
3042 PurpleConnection *gc;
3043 MsimSession *session;
3044 gchar *group_name;
3045
3046 gc = action->connection;
3047 session = purple_connection_get_protocol_data(gc);
3048
3049 group_name = "MySpace Friends";
3050
3051 g_return_if_fail(msim_send(session,
3052 "persist", MSIM_TYPE_INTEGER, 1,
3053 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
3054 "cmd", MSIM_TYPE_INTEGER, MSIM_CMD_PUT,
3055 "dsn", MSIM_TYPE_INTEGER, MC_IMPORT_ALL_FRIENDS_DSN,
3056 "lid", MSIM_TYPE_INTEGER, MC_IMPORT_ALL_FRIENDS_LID,
3057 "uid", MSIM_TYPE_INTEGER, session->userid,
3058 "rid", MSIM_TYPE_INTEGER,
3059 msim_new_reply_callback(session, msim_import_friends_cb, NULL),
3060 "body", MSIM_TYPE_STRING,
3061 g_strdup_printf("GroupName=%s", group_name),
3062 NULL));
3063 }
3064
3065 /**
3066 * Actions menu for account.
3067 */
3068 static GList *
3069 msim_get_actions(PurpleConnection *gc)
3070 {
3071 GList *menu;
3072 PurpleProtocolAction *act;
3073
3074 menu = NULL;
3075
3076 #if 0
3077 /* TODO: find out how */
3078 act = purple_protocol_action_new(_("Find people..."), msim_);
3079 menu = g_list_append(menu, act);
3080
3081 act = purple_protocol_action_new(_("Change IM name..."), NULL);
3082 menu = g_list_append(menu, act);
3083 #endif
3084
3085 act = purple_protocol_action_new(_("Add friends from MySpace.com"), msim_import_friends);
3086 menu = g_list_append(menu, act);
3087
3088 return menu;
3089 }
3090
3091 /**
3005 * Callbacks called by Purple, to access this plugin. 3092 * Callbacks called by Purple, to access this plugin.
3006 */ 3093 */
3007 static PurplePluginProtocolInfo prpl_info = { 3094 static PurplePluginProtocolInfo prpl_info = {
3095 "prpl-myspace", /* id */
3096 "MySpaceIM", /* name */
3008 sizeof(PurplePluginProtocolInfo), /* struct_size */ 3097 sizeof(PurplePluginProtocolInfo), /* struct_size */
3009 /* options */ 3098 /* options */
3010 OPT_PROTO_USE_POINTSIZE /* specify font size in sane point size */ 3099 OPT_PROTO_USE_POINTSIZE /* specify font size in sane point size */
3011 | OPT_PROTO_MAIL_CHECK, 3100 | OPT_PROTO_MAIL_CHECK,
3012 3101
3013 /* | OPT_PROTO_IM_IMAGE - TODO: direct images. */ 3102 /* | OPT_PROTO_IM_IMAGE - TODO: direct images. */
3014 NULL, /* user_splits */ 3103 NULL, /* user_splits */
3015 NULL, /* protocol_options */ 3104 NULL, /* protocol_options */
3016 NO_BUDDY_ICONS, /* icon_spec - TODO: eventually should add this */ 3105 NO_BUDDY_ICONS, /* icon_spec - TODO: eventually should add this */
3106 msim_get_actions, /* get_actions */
3017 msim_list_icon, /* list_icon */ 3107 msim_list_icon, /* list_icon */
3018 NULL, /* list_emblems */ 3108 NULL, /* list_emblems */
3019 msim_status_text, /* status_text */ 3109 msim_status_text, /* status_text */
3020 msim_tooltip_text, /* tooltip_text */ 3110 msim_tooltip_text, /* tooltip_text */
3021 msim_status_types, /* status_types */ 3111 msim_status_types, /* status_types */
3080 NULL, /* get_moods */ 3170 NULL, /* get_moods */
3081 NULL, /* set_public_alias */ 3171 NULL, /* set_public_alias */
3082 NULL /* get_public_alias */ 3172 NULL /* get_public_alias */
3083 }; 3173 };
3084 3174
3085 /**
3086 * Load the plugin.
3087 */
3088 static gboolean
3089 msim_load(PurplePlugin *plugin)
3090 {
3091 return TRUE;
3092 }
3093
3094 /**
3095 * Called when friends have been imported to buddy list on server.
3096 */
3097 static void
3098 msim_import_friends_cb(MsimSession *session, const MsimMessage *reply, gpointer user_data)
3099 {
3100 MsimMessage *body;
3101 gchar *completed;
3102
3103 /* Check if the friends were imported successfully. */
3104 body = msim_msg_get_dictionary(reply, "body");
3105 g_return_if_fail(body != NULL);
3106 completed = msim_msg_get_string(body, "Completed");
3107 msim_msg_free(body);
3108 g_return_if_fail(completed != NULL);
3109 if (!g_str_equal(completed, "True"))
3110 {
3111 purple_debug_info("msim_import_friends_cb",
3112 "failed to import friends: %s", completed);
3113 purple_notify_error(session->account, _("Add friends from MySpace.com"),
3114 _("Importing friends failed"), NULL);
3115 g_free(completed);
3116 return;
3117 }
3118 g_free(completed);
3119
3120 purple_debug_info("msim_import_friends_cb",
3121 "added friends to server-side buddy list, requesting new contacts from server");
3122
3123 msim_get_contact_list(session, MSIM_CONTACT_LIST_IMPORT_ALL_FRIENDS);
3124
3125 /* TODO: show, X friends have been added */
3126 }
3127
3128 /**
3129 * Import friends from myspace.com.
3130 */
3131 static void msim_import_friends(PurplePluginAction *action)
3132 {
3133 PurpleConnection *gc;
3134 MsimSession *session;
3135 gchar *group_name;
3136
3137 gc = (PurpleConnection *)action->context;
3138 session = purple_connection_get_protocol_data(gc);
3139
3140 group_name = "MySpace Friends";
3141
3142 g_return_if_fail(msim_send(session,
3143 "persist", MSIM_TYPE_INTEGER, 1,
3144 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
3145 "cmd", MSIM_TYPE_INTEGER, MSIM_CMD_PUT,
3146 "dsn", MSIM_TYPE_INTEGER, MC_IMPORT_ALL_FRIENDS_DSN,
3147 "lid", MSIM_TYPE_INTEGER, MC_IMPORT_ALL_FRIENDS_LID,
3148 "uid", MSIM_TYPE_INTEGER, session->userid,
3149 "rid", MSIM_TYPE_INTEGER,
3150 msim_new_reply_callback(session, msim_import_friends_cb, NULL),
3151 "body", MSIM_TYPE_STRING,
3152 g_strdup_printf("GroupName=%s", group_name),
3153 NULL));
3154 }
3155
3156 /**
3157 * Actions menu for account.
3158 */
3159 static GList *
3160 msim_actions(PurplePlugin *plugin, gpointer context /* PurpleConnection* */)
3161 {
3162 GList *menu;
3163 PurplePluginAction *act;
3164
3165 menu = NULL;
3166
3167 #if 0
3168 /* TODO: find out how */
3169 act = purple_plugin_action_new(_("Find people..."), msim_);
3170 menu = g_list_append(menu, act);
3171
3172 act = purple_plugin_action_new(_("Change IM name..."), NULL);
3173 menu = g_list_append(menu, act);
3174 #endif
3175
3176 act = purple_plugin_action_new(_("Add friends from MySpace.com"), msim_import_friends);
3177 menu = g_list_append(menu, act);
3178
3179 return menu;
3180 }
3181
3182 /**
3183 * Based on MSN's plugin info comments.
3184 */
3185 static PurplePluginInfo info = {
3186 PURPLE_PLUGIN_MAGIC,
3187 PURPLE_MAJOR_VERSION,
3188 PURPLE_MINOR_VERSION,
3189 PURPLE_PLUGIN_PROTOCOL, /**< type */
3190 NULL, /**< ui_requirement */
3191 0, /**< flags */
3192 NULL, /**< dependencies */
3193 PURPLE_PRIORITY_DEFAULT, /**< priority */
3194
3195 "prpl-myspace", /**< id */
3196 "MySpaceIM", /**< name */
3197 MSIM_PRPL_VERSION_STRING, /**< version */
3198 /** summary */
3199 "MySpaceIM Protocol Plugin",
3200 /** description */
3201 "MySpaceIM Protocol Plugin",
3202 "Jeff Connelly <jeff2@soc.pidgin.im>", /**< author */
3203 "https://developer.pidgin.im/wiki/MySpaceIM/", /**< homepage */
3204
3205 msim_load, /**< load */
3206 NULL, /**< unload */
3207 NULL, /**< destroy */
3208 NULL, /**< ui_info */
3209 &prpl_info, /**< extra_info */
3210 NULL, /**< prefs_info */
3211 msim_actions, /**< msim_actions */
3212 NULL, /**< reserved1 */
3213 NULL, /**< reserved2 */
3214 NULL, /**< reserved3 */
3215 NULL /**< reserved4 */
3216 };
3217
3218 #ifdef MSIM_SELF_TEST 3175 #ifdef MSIM_SELF_TEST
3219 /* 3176 /*
3220 * Test functions. 3177 * Test functions.
3221 * Used to test or try out the internal workings of msimprpl. If you're reading 3178 * Used to test or try out the internal workings of msimprpl. If you're reading
3222 * this code for the first time, these functions can be instructive in learning 3179 * this code for the first time, these functions can be instructive in learning
3502 g_free(cid_str); 3459 g_free(cid_str);
3503 return FALSE; 3460 return FALSE;
3504 } 3461 }
3505 3462
3506 /** 3463 /**
3507 * Initialize plugin. 3464 * Query the plugin
3508 */ 3465 */
3509 static void 3466 static PurplePluginInfo *
3510 init_plugin(PurplePlugin *plugin) 3467 plugin_query(GError **error)
3468 {
3469 return purple_plugin_info_new(
3470 "id", "prpl-myspace",
3471 "name", "MySpaceIM",
3472 "version", MSIM_PRPL_VERSION_STRING,
3473 "category", "Protocol",
3474 "summary", "MySpaceIM Protocol Plugin",
3475 "description", "MySpaceIM Protocol Plugin",
3476 "author", "Jeff Connelly <jeff2@soc.pidgin.im>",
3477 "website", "https://developer.pidgin.im/wiki/MySpaceIM/",
3478 "abi-version", PURPLE_ABI_VERSION,
3479 NULL
3480 );
3481 }
3482
3483 /**
3484 * Load the plugin.
3485 */
3486 static gboolean
3487 plugin_load(PurplePlugin *plugin, GError **error)
3511 { 3488 {
3512 #ifdef MSIM_SELF_TEST 3489 #ifdef MSIM_SELF_TEST
3513 msim_test_all(); 3490 msim_test_all();
3514 exit(0); 3491 exit(0);
3515 #endif /* MSIM_SELF_TEST */ 3492 #endif /* MSIM_SELF_TEST */
3516 3493
3517 PurpleAccountOption *option; 3494 PurpleAccountOption *option;
3518 static gboolean initialized = FALSE;
3519 3495
3520 /* TODO: default to automatically try different ports. Make the user be 3496 /* TODO: default to automatically try different ports. Make the user be
3521 * able to set the first port to try (like LastConnectedPort in Windows client). */ 3497 * able to set the first port to try (like LastConnectedPort in Windows client). */
3522 option = purple_account_option_string_new(_("Connect server"), "server", MSIM_SERVER); 3498 option = purple_account_option_string_new(_("Connect server"), "server", MSIM_SERVER);
3523 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 3499 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
3544 3520
3545 option = purple_account_option_int_new(_("Base font size (points)"), "base_font_size", MSIM_BASE_FONT_POINT_SIZE); 3521 option = purple_account_option_int_new(_("Base font size (points)"), "base_font_size", MSIM_BASE_FONT_POINT_SIZE);
3546 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 3522 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
3547 #endif 3523 #endif
3548 3524
3549 /* Code below only runs once. Based on oscar.c's oscar_init(). */ 3525 purple_signal_connect(purple_get_core(), "uri-handler", &prpl_info,
3550 if (initialized)
3551 return;
3552
3553 initialized = TRUE;
3554
3555 purple_signal_connect(purple_get_core(), "uri-handler", &initialized,
3556 PURPLE_CALLBACK(msim_uri_handler), NULL); 3526 PURPLE_CALLBACK(msim_uri_handler), NULL);
3557 } 3527
3558 3528 purple_protocols_add(&prpl_info);
3559 PURPLE_INIT_PLUGIN(myspace, init_plugin, info); 3529
3530 return TRUE;
3531 }
3532
3533 /**
3534 * Unload the plugin.
3535 */
3536 static gboolean
3537 plugin_unload(PurplePlugin *plugin, GError **error)
3538 {
3539 purple_protocols_remove(&prpl_info);
3540
3541 return TRUE;
3542 }
3543
3544 PURPLE_PLUGIN_INIT(myspace, plugin_query, plugin_load, plugin_unload);

mercurial