comparison libpurple/protocols/myspace/myspace.c @ 17953:bde17299004b

Support unofficial bm code 200, also used by Miranda IM plugin, to report third-party client version. "Get Info" now shows unofficial client information, if available, and buddies coming online are sent this information so they can view it too. Official client version is not currently supported in the same manner.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Wed, 18 Jul 2007 06:09:32 +0000
parents 4001661344e4
children 016f9b2d6ee0
comparison
equal deleted inserted replaced
17952:4001661344e4 17953:bde17299004b
1088 g_free(enclosed_raw); 1088 g_free(enclosed_raw);
1089 1089
1090 return markup; 1090 return markup;
1091 } 1091 }
1092 1092
1093 /** Handle an incoming buddy message. */
1094 gboolean
1095 msim_incoming_bm(MsimSession *session, MsimMessage *msg)
1096 {
1097 guint bm;
1098
1099 bm = msim_msg_get_integer(msg, "bm");
1100
1101 switch (bm)
1102 {
1103 case MSIM_BM_STATUS:
1104 return msim_incoming_status(session, msg);
1105 case MSIM_BM_INSTANT:
1106 return msim_incoming_im(session, msg);
1107 case MSIM_BM_ACTION:
1108 return msim_incoming_action(session, msg);
1109 case MSIM_BM_MEDIA:
1110 return msim_incoming_media(session, msg);
1111 case MSIM_BM_UNOFFICIAL_CLIENT:
1112 return msim_incoming_unofficial_client(session, msg);
1113 default:
1114 /* Not really an IM, but show it for informational
1115 * purposes during development. */
1116 return msim_incoming_im(session, msg);
1117 }
1118 }
1119
1093 /** 1120 /**
1094 * Handle an incoming instant message. 1121 * Handle an incoming instant message.
1095 * 1122 *
1096 * @param session The session 1123 * @param session The session
1097 * @param msg Message from the server, containing 'f' (userid from) and 'msg'. 1124 * @param msg Message from the server, containing 'f' (userid from) and 'msg'.
1206 g_free(username); 1233 g_free(username);
1207 1234
1208 return rc; 1235 return rc;
1209 } 1236 }
1210 1237
1238 /* Process an incoming media (buddy icon) message. */
1239 gboolean
1240 msim_incoming_media(MsimSession *session, MsimMessage *msg)
1241 {
1242 gchar *username, *text;
1243
1244 username = msim_msg_get_string(msg, "_username");
1245 text = msim_msg_get_string(msg, "msg");
1246
1247 g_return_val_if_fail(username != NULL, FALSE);
1248 g_return_val_if_fail(text != NULL, FALSE);
1249
1250 purple_debug_info("msim", "msim_incoming_media: from %s, got msg=%s\n", username, text);
1251
1252 /* Media messages are sent when the user opens a window to someone.
1253 * Tell libpurple they started typing and stopped typing, to inform the Psychic
1254 * Mode plugin so it too can open a window to the user. */
1255 serv_got_typing(session->gc, username, 0, PURPLE_TYPING);
1256 serv_got_typing_stopped(session->gc, username);
1257
1258 g_free(username);
1259
1260 return TRUE;
1261 }
1262
1263 /* Process an incoming "unofficial client" message. The plugin for
1264 * Miranda IM sends this message with the plugin information. */
1265 gboolean
1266 msim_incoming_unofficial_client(MsimSession *session, MsimMessage *msg)
1267 {
1268 PurpleBuddy *buddy;
1269 gchar *username, *client_info;
1270
1271 username = msim_msg_get_string(msg, "_username");
1272 client_info = msim_msg_get_string(msg, "msg");
1273
1274 g_return_val_if_fail(username != NULL, FALSE);
1275 g_return_val_if_fail(client_info != NULL, FALSE);
1276
1277 purple_debug_info("msim", "msim_incoming_unofficial_client: %s is using client %s\n",
1278 username, client_info);
1279
1280 buddy = purple_find_buddy(session->account, username);
1281
1282 g_return_val_if_fail(buddy != NULL, FALSE);
1283
1284 purple_blist_node_set_string(&buddy->node, "client", client_info);
1285
1286
1287 g_free(username);
1288 /* Do not free client_info - the blist now owns it. */
1289
1290 return TRUE;
1291 }
1292
1293
1294 /** Send our client version to another unofficial client that understands it. */
1295 gboolean
1296 msim_send_unofficial_client(MsimSession *session, gchar *username)
1297 {
1298 gchar *our_info;
1299 gboolean ret;
1300
1301 our_info = g_strdup_printf("Libpurple %d.%d.%d - msimprpl %s",
1302 PURPLE_MAJOR_VERSION,
1303 PURPLE_MINOR_VERSION,
1304 PURPLE_MICRO_VERSION,
1305 MSIM_PRPL_VERSION_STRING);
1306
1307 ret = msim_send_bm(session, username, our_info, MSIM_BM_UNOFFICIAL_CLIENT);
1308
1309 g_free(our_info);
1310
1311 return ret;
1312 }
1313
1211 /** 1314 /**
1212 * Handle when our user starts or stops typing to another user. 1315 * Handle when our user starts or stops typing to another user.
1213 * 1316 *
1214 * @param gc 1317 * @param gc
1215 * @param name The buddy name to which our user is typing to 1318 * @param name The buddy name to which our user is typing to
1312 purple_notify_user_info_add_pair(user_info, _("Location"), 1415 purple_notify_user_info_add_pair(user_info, _("Location"),
1313 g_strdup(str)); 1416 g_strdup(str));
1314 1417
1315 /* Other information */ 1418 /* Other information */
1316 1419
1317 /* Headline comes from buddy status messages */
1318 if (buddy) 1420 if (buddy)
1319 { 1421 {
1422 /* Headline comes from buddy status messages */
1320 str = purple_blist_node_get_string(&buddy->node, "Headline"); 1423 str = purple_blist_node_get_string(&buddy->node, "Headline");
1321 if (str) 1424 if (str)
1322 purple_notify_user_info_add_pair(user_info, "Headline", str); 1425 purple_notify_user_info_add_pair(user_info, "Headline", str);
1323 } 1426 }
1324 1427
1337 /* Total friends only available if looked up by uid, not username. */ 1440 /* Total friends only available if looked up by uid, not username. */
1338 str = g_hash_table_lookup(body, "TotalFriends"); 1441 str = g_hash_table_lookup(body, "TotalFriends");
1339 if (str) 1442 if (str)
1340 purple_notify_user_info_add_pair(user_info, _("Total Friends"), 1443 purple_notify_user_info_add_pair(user_info, _("Total Friends"),
1341 g_strdup(str)); 1444 g_strdup(str));
1445
1446 if (buddy)
1447 {
1448 str = purple_blist_node_get_string(&buddy->node, "client");
1449 if (str)
1450 purple_notify_user_info_add_pair(user_info, _("Client Version"),
1451 g_strdup(str));
1452 }
1342 1453
1343 purple_notify_userinfo(session->gc, user, user_info, NULL, NULL); 1454 purple_notify_userinfo(session->gc, user, user_info, NULL, NULL);
1344 purple_debug_info("msim", "msim_get_info_cb: username=%s\n", user); 1455 purple_debug_info("msim", "msim_get_info_cb: username=%s\n", user);
1345 //purple_notify_user_info_destroy(user_info); 1456 //purple_notify_user_info_destroy(user_info);
1346 /* Do not free username, since it will be used by user_info. */ 1457 /* Do not free username, since it will be used by user_info. */
1942 { 2053 {
1943 return msim_login_challenge(session, msg); 2054 return msim_login_challenge(session, msg);
1944 } else if (msim_msg_get(msg, "sesskey")) { 2055 } else if (msim_msg_get(msg, "sesskey")) {
1945 return msim_we_are_logged_on(session, msg); 2056 return msim_we_are_logged_on(session, msg);
1946 } else if (msim_msg_get(msg, "bm")) { 2057 } else if (msim_msg_get(msg, "bm")) {
1947 guint bm; 2058 return msim_incoming_bm(session, msg);
1948
1949 bm = msim_msg_get_integer(msg, "bm");
1950 switch (bm)
1951 {
1952 case MSIM_BM_STATUS:
1953 return msim_status(session, msg);
1954 case MSIM_BM_INSTANT:
1955 return msim_incoming_im(session, msg);
1956 case MSIM_BM_ACTION:
1957 return msim_incoming_action(session, msg);
1958 default:
1959 /* Not really an IM, but show it for informational
1960 * purposes during development. */
1961 return msim_incoming_im(session, msg);
1962 }
1963 } else if (msim_msg_get(msg, "rid")) { 2059 } else if (msim_msg_get(msg, "rid")) {
1964 return msim_process_reply(session, msg); 2060 return msim_process_reply(session, msg);
1965 } else if (msim_msg_get(msg, "error")) { 2061 } else if (msim_msg_get(msg, "error")) {
1966 return msim_error(session, msg); 2062 return msim_error(session, msg);
1967 } else if (msim_msg_get(msg, "ka")) { 2063 } else if (msim_msg_get(msg, "ka")) {
2146 * @param msg Status update message. Caller frees. 2242 * @param msg Status update message. Caller frees.
2147 * 2243 *
2148 * @return TRUE if successful. 2244 * @return TRUE if successful.
2149 */ 2245 */
2150 gboolean 2246 gboolean
2151 msim_status(MsimSession *session, MsimMessage *msg) 2247 msim_incoming_status(MsimSession *session, MsimMessage *msg)
2152 { 2248 {
2153 PurpleBuddyList *blist; 2249 PurpleBuddyList *blist;
2154 PurpleBuddy *buddy; 2250 PurpleBuddy *buddy;
2155 //PurpleStatus *status; 2251 //PurpleStatus *status;
2156 gchar **status_array; 2252 gchar **status_array;
2261 purple_debug_info("msim", "msim_status: got idle: %s\n", username); 2357 purple_debug_info("msim", "msim_status: got idle: %s\n", username);
2262 purple_prpl_got_user_idle(session->account, username, TRUE, time(NULL)); 2358 purple_prpl_got_user_idle(session->account, username, TRUE, time(NULL));
2263 } else { 2359 } else {
2264 /* All other statuses indicate going back to non-idle. */ 2360 /* All other statuses indicate going back to non-idle. */
2265 purple_prpl_got_user_idle(session->account, username, FALSE, time(NULL)); 2361 purple_prpl_got_user_idle(session->account, username, FALSE, time(NULL));
2362 }
2363
2364 if (status_code == MSIM_STATUS_CODE_ONLINE)
2365 {
2366 /* Secretly whisper to unofficial clients our own version as they come online */
2367 msim_send_unofficial_client(session, username);
2266 } 2368 }
2267 2369
2268 g_strfreev(status_array); 2370 g_strfreev(status_array);
2269 g_free(status_str); 2371 g_free(status_str);
2270 g_free(username); 2372 g_free(username);
2649 purple_connection_error(gc, _("Server has disconnected")); 2751 purple_connection_error(gc, _("Server has disconnected"));
2650 return; 2752 return;
2651 } 2753 }
2652 2754
2653 /* Null terminate */ 2755 /* Null terminate */
2756 purple_debug_info("msim", "msim_input_cb: going to null terminate "
2757 "at n=%d\n", n);
2654 session->rxbuf[session->rxoff + n] = 0; 2758 session->rxbuf[session->rxoff + n] = 0;
2655 2759
2656 #ifdef MSIM_CHECK_EMBEDDED_NULLS 2760 #ifdef MSIM_CHECK_EMBEDDED_NULLS
2657 /* Check for embedded NULs. I don't handle them, and they shouldn't occur. */ 2761 /* Check for embedded NULs. I don't handle them, and they shouldn't occur. */
2658 if (strlen(session->rxbuf + session->rxoff) != n) 2762 if (strlen(session->rxbuf + session->rxoff) != n)
2683 #endif 2787 #endif
2684 *end = 0; 2788 *end = 0;
2685 msg = msim_parse(g_strdup(session->rxbuf)); 2789 msg = msim_parse(g_strdup(session->rxbuf));
2686 if (!msg) 2790 if (!msg)
2687 { 2791 {
2688 purple_debug_info("msim", "msim_input_cb: couldn't parse <%s>\n", 2792 purple_debug_info("msim", "msim_input_cb: couldn't parse rxbuf\n");
2689 session->rxbuf);
2690 purple_connection_error(gc, _("Unparseable message")); 2793 purple_connection_error(gc, _("Unparseable message"));
2691 } 2794 }
2692 else 2795 else
2693 { 2796 {
2694 /* Process message and then free it (processing function should 2797 /* Process message and then free it (processing function should
3170 NULL, /**< dependencies */ 3273 NULL, /**< dependencies */
3171 PURPLE_PRIORITY_DEFAULT, /**< priority */ 3274 PURPLE_PRIORITY_DEFAULT, /**< priority */
3172 3275
3173 "prpl-myspace", /**< id */ 3276 "prpl-myspace", /**< id */
3174 "MySpaceIM", /**< name */ 3277 "MySpaceIM", /**< name */
3175 "0.12", /**< version */ 3278 MSIM_PRPL_VERSION_STRING, /**< version */
3176 /** summary */ 3279 /** summary */
3177 "MySpaceIM Protocol Plugin", 3280 "MySpaceIM Protocol Plugin",
3178 /** description */ 3281 /** description */
3179 "MySpaceIM Protocol Plugin", 3282 "MySpaceIM Protocol Plugin",
3180 "Jeff Connelly <jeff2@soc.pidgin.im>", /**< author */ 3283 "Jeff Connelly <jeff2@soc.pidgin.im>", /**< author */