comparison libpurple/protocols/myspace/myspace.c @ 17966:f1827c3dc65a

Add msim_process_server_info() to save the server information dictionary received before logging in, in session->server_info. Not used for much now, but may be useful in the future.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Sun, 22 Jul 2007 05:37:48 +0000
parents e3687194f2b2
children c9acdf96e74e
comparison
equal deleted inserted replaced
17965:e3687194f2b2 17966:f1827c3dc65a
2415 g_hash_table_destroy(body); 2415 g_hash_table_destroy(body);
2416 2416
2417 return TRUE; 2417 return TRUE;
2418 } 2418 }
2419 2419
2420 /** Process the initial server information from the server. */
2421 gboolean
2422 msim_process_server_info(MsimSession *session, MsimMessage *msg)
2423 {
2424 gchar *body_str;
2425 GHashTable *body;
2426
2427 body_str = msim_msg_get_string(msg, "body");
2428 g_return_val_if_fail(body_str != NULL, FALSE);
2429 body = msim_parse_body(body_str);
2430 g_free(body_str);
2431 g_return_val_if_fail(body != NULL, FALSE);
2432
2433 /* Example body:
2434 AdUnitRefreshInterval=10.
2435 AlertPollInterval=360.
2436 AllowChatRoomEmoticonSharing=False.
2437 ChatRoomUserIDs=78744676;163733130;1300326231;123521495;142663391.
2438 CurClientVersion=673.
2439 EnableIMBrowse=True.
2440 EnableIMStuffAvatars=False.
2441 EnableIMStuffZaps=False.
2442 MaxAddAllFriends=100.
2443 MaxContacts=1000.
2444 MinClientVersion=594.
2445 MySpaceIM_ENGLISH=78744676.
2446 MySpaceNowTimer=720.
2447 PersistenceDataTimeout=900.
2448 UseWebChallenge=1.
2449 WebTicketGoHome=False
2450
2451 Anything useful? TODO: use what is useful, and use it.
2452 */
2453 purple_debug_info("msim_process_server_info",
2454 "maximum contacts: %s\n", g_hash_table_lookup(body, "MaxContacts"));
2455
2456 session->server_info = body;
2457 /* session->server_info freed in msim_session_destroy */
2458
2459 return TRUE;
2460 }
2461
2420 /** 2462 /**
2421 * Process a persistance message reply from the server. 2463 * Process a persistance message reply from the server.
2422 * 2464 *
2423 * @param session 2465 * @param session
2424 * @param msg Message reply from server. 2466 * @param msg Message reply from server.
2425 * 2467 *
2426 * @return TRUE if successful. 2468 * @return TRUE if successful.
2469 *
2470 * msim_lookup_user sets callback for here
2427 */ 2471 */
2428 gboolean 2472 gboolean
2429 msim_process_reply(MsimSession *session, MsimMessage *msg) 2473 msim_process_reply(MsimSession *session, MsimMessage *msg)
2430 { 2474 {
2475 MSIM_USER_LOOKUP_CB cb;
2476 gpointer data;
2477 guint rid, cmd, dsn, lid;
2478
2431 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); 2479 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
2432 g_return_val_if_fail(msg != NULL, FALSE); 2480 g_return_val_if_fail(msg != NULL, FALSE);
2433 2481
2434 if (msim_msg_get(msg, "rid")) /* msim_lookup_user sets callback for here */ 2482 msim_store_buddy_info(session, msg);
2435 { 2483
2436 MSIM_USER_LOOKUP_CB cb; 2484 rid = msim_msg_get_integer(msg, "rid");
2437 gpointer data; 2485 cmd = msim_msg_get_integer(msg, "cmd");
2438 guint rid; 2486 dsn = msim_msg_get_integer(msg, "dsn");
2439 2487 lid = msim_msg_get_integer(msg, "lid");
2440 msim_store_buddy_info(session, msg); 2488
2441 2489 if (cmd == (MSIM_CMD_BIT_REPLY | MSIM_CMD_GET) &&
2442 rid = msim_msg_get_integer(msg, "rid"); 2490 dsn == MG_SERVER_INFO_DSN &&
2443 2491 lid == MG_SERVER_INFO_LID)
2444 /* If a callback is registered for this userid lookup, call it. */ 2492 {
2445 cb = g_hash_table_lookup(session->user_lookup_cb, GUINT_TO_POINTER(rid)); 2493 return msim_process_server_info(session, msg);
2446 data = g_hash_table_lookup(session->user_lookup_cb_data, GUINT_TO_POINTER(rid)); 2494 }
2447 2495
2448 if (cb) 2496 /* If a callback is registered for this userid lookup, call it. */
2449 { 2497 cb = g_hash_table_lookup(session->user_lookup_cb, GUINT_TO_POINTER(rid));
2450 purple_debug_info("msim", 2498 data = g_hash_table_lookup(session->user_lookup_cb_data, GUINT_TO_POINTER(rid));
2451 "msim_process_body: calling callback now\n"); 2499
2452 /* Clone message, so that the callback 'cb' can use it (needs to free it also). */ 2500 if (cb)
2453 cb(session, msim_msg_clone(msg), data); 2501 {
2454 g_hash_table_remove(session->user_lookup_cb, GUINT_TO_POINTER(rid)); 2502 purple_debug_info("msim",
2455 g_hash_table_remove(session->user_lookup_cb_data, GUINT_TO_POINTER(rid)); 2503 "msim_process_body: calling callback now\n");
2456 } else { 2504 /* Clone message, so that the callback 'cb' can use it (needs to free it also). */
2457 purple_debug_info("msim", 2505 cb(session, msim_msg_clone(msg), data);
2458 "msim_process_body: no callback for rid %d\n", rid); 2506 g_hash_table_remove(session->user_lookup_cb, GUINT_TO_POINTER(rid));
2459 } 2507 g_hash_table_remove(session->user_lookup_cb_data, GUINT_TO_POINTER(rid));
2508 } else {
2509 purple_debug_info("msim",
2510 "msim_process_body: no callback for rid %d\n", rid);
2460 } 2511 }
2461 2512
2462 return TRUE; 2513 return TRUE;
2463 } 2514 }
2464 2515
3165 session->user_lookup_cb_data = g_hash_table_new_full(g_direct_hash, 3216 session->user_lookup_cb_data = g_hash_table_new_full(g_direct_hash,
3166 g_direct_equal, NULL, NULL);/* TODO: we don't know what the values are, 3217 g_direct_equal, NULL, NULL);/* TODO: we don't know what the values are,
3167 they could be integers inside gpointers 3218 they could be integers inside gpointers
3168 or strings, so I don't freed them. 3219 or strings, so I don't freed them.
3169 Figure this out, once free cache. */ 3220 Figure this out, once free cache. */
3221
3222 /* Created in msim_process_server_info() */
3223 session->server_info = NULL;
3224
3170 session->rxoff = 0; 3225 session->rxoff = 0;
3171 session->rxbuf = g_new0(gchar, MSIM_READ_BUF_SIZE); 3226 session->rxbuf = g_new0(gchar, MSIM_READ_BUF_SIZE);
3172 session->next_rid = 1; 3227 session->next_rid = 1;
3173 session->last_comm = time(NULL); 3228 session->last_comm = time(NULL);
3174 session->inbox_status = 0; 3229 session->inbox_status = 0;
3192 g_free(session->username); 3247 g_free(session->username);
3193 3248
3194 /* TODO: Remove. */ 3249 /* TODO: Remove. */
3195 g_hash_table_destroy(session->user_lookup_cb); 3250 g_hash_table_destroy(session->user_lookup_cb);
3196 g_hash_table_destroy(session->user_lookup_cb_data); 3251 g_hash_table_destroy(session->user_lookup_cb_data);
3252
3253 if (session->server_info)
3254 g_hash_table_destroy(session->server_info);
3197 3255
3198 g_free(session); 3256 g_free(session);
3199 } 3257 }
3200 3258
3201 /** 3259 /**