Mercurial > pidgin
comparison libpurple/protocols/myspace/myspace.c @ 17326:f057837085b0
Change to use const gchar * where appropriate.
author | Jeffrey Connelly <jaconnel@calpoly.edu> |
---|---|
date | Thu, 14 Jun 2007 08:18:59 +0000 |
parents | 1a26b36889dc |
children | 4205f33b658f |
comparison
equal
deleted
inserted
replaced
17325:1a26b36889dc | 17326:f057837085b0 |
---|---|
105 * | 105 * |
106 * @return The base icon name string. | 106 * @return The base icon name string. |
107 */ | 107 */ |
108 const gchar *msim_list_icon(PurpleAccount *acct, PurpleBuddy *buddy) | 108 const gchar *msim_list_icon(PurpleAccount *acct, PurpleBuddy *buddy) |
109 { | 109 { |
110 /* Use a MySpace icon submitted by hbons submitted one at | 110 /* Use a MySpace icon submitted by hbons at |
111 * http://developer.pidgin.im/wiki/MySpaceIM. */ | 111 * http://developer.pidgin.im/wiki/MySpaceIM. */ |
112 return "myspace"; | 112 return "myspace"; |
113 } | 113 } |
114 | 114 |
115 /** | 115 /** |
159 * http://mail.gnome.org/archives/gtk-app-devel-list/2000-July/msg00201.html | 159 * http://mail.gnome.org/archives/gtk-app-devel-list/2000-July/msg00201.html |
160 * | 160 * |
161 */ | 161 */ |
162 gchar *str_replace(const gchar *str, const gchar *old, const gchar *new) | 162 gchar *str_replace(const gchar *str, const gchar *old, const gchar *new) |
163 { | 163 { |
164 char **items; | 164 gchar **items; |
165 char *ret; | 165 gchar *ret; |
166 | 166 |
167 items = g_strsplit(str, old, -1); | 167 items = g_strsplit(str, old, -1); |
168 ret = g_strjoinv(new, items); | 168 ret = g_strjoinv(new, items); |
169 g_free(items); | 169 g_free(items); |
170 return ret; | 170 return ret; |
174 | 174 |
175 | 175 |
176 #ifdef MSIM_DEBUG_MSG | 176 #ifdef MSIM_DEBUG_MSG |
177 void print_hash_item(gpointer key, gpointer value, gpointer user_data) | 177 void print_hash_item(gpointer key, gpointer value, gpointer user_data) |
178 { | 178 { |
179 purple_debug_info("msim", "%s=%s\n", (char *)key, (char *)value); | 179 purple_debug_info("msim", "%s=%s\n", (gchar *)key, (gchar *)value); |
180 } | 180 } |
181 #endif | 181 #endif |
182 | 182 |
183 /** | 183 /** |
184 * Send raw data to the server. | 184 * Send raw data to the server. |
227 * @param acct Account information to use to login. | 227 * @param acct Account information to use to login. |
228 */ | 228 */ |
229 void msim_login(PurpleAccount *acct) | 229 void msim_login(PurpleAccount *acct) |
230 { | 230 { |
231 PurpleConnection *gc; | 231 PurpleConnection *gc; |
232 const char *host; | 232 const gchar *host; |
233 int port; | 233 int port; |
234 | 234 |
235 g_return_if_fail(acct != NULL); | 235 g_return_if_fail(acct != NULL); |
236 | 236 |
237 purple_debug_info("myspace", "logging in %s\n", acct->username); | 237 purple_debug_info("myspace", "logging in %s\n", acct->username); |
270 * @return TRUE if successful, FALSE if not | 270 * @return TRUE if successful, FALSE if not |
271 */ | 271 */ |
272 gboolean msim_login_challenge(MsimSession *session, MsimMessage *msg) | 272 gboolean msim_login_challenge(MsimSession *session, MsimMessage *msg) |
273 { | 273 { |
274 PurpleAccount *account; | 274 PurpleAccount *account; |
275 gchar *response; | 275 const gchar *response; |
276 guint response_len; | 276 guint response_len; |
277 gchar *nc; | 277 gchar *nc; |
278 gsize nc_len; | 278 gsize nc_len; |
279 | 279 |
280 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); | 280 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); |
358 Taken from Samba source code. Modified to allow us to maintain state | 358 Taken from Samba source code. Modified to allow us to maintain state |
359 between calls to crypt_rc4. | 359 between calls to crypt_rc4. |
360 */ | 360 */ |
361 | 361 |
362 void crypt_rc4_init(rc4_state_struct *rc4_state, | 362 void crypt_rc4_init(rc4_state_struct *rc4_state, |
363 const unsigned char *key, int key_len) | 363 const guchar *key, int key_len) |
364 { | 364 { |
365 int ind; | 365 int ind; |
366 unsigned char j = 0; | 366 unsigned gchar j = 0; |
367 unsigned char *s_box; | 367 unsigned gchar *s_box; |
368 | 368 |
369 memset(rc4_state, 0, sizeof(rc4_state_struct)); | 369 memset(rc4_state, 0, sizeof(rc4_state_struct)); |
370 s_box = rc4_state->s_box; | 370 s_box = rc4_state->s_box; |
371 | 371 |
372 for (ind = 0; ind < 256; ind++) | 372 for (ind = 0; ind < 256; ind++) |
373 { | 373 { |
374 s_box[ind] = (unsigned char)ind; | 374 s_box[ind] = (guchar)ind; |
375 } | 375 } |
376 | 376 |
377 for( ind = 0; ind < 256; ind++) | 377 for( ind = 0; ind < 256; ind++) |
378 { | 378 { |
379 unsigned char tc; | 379 guchar tc; |
380 | 380 |
381 j += (s_box[ind] + key[ind%key_len]); | 381 j += (s_box[ind] + key[ind%key_len]); |
382 | 382 |
383 tc = s_box[ind]; | 383 tc = s_box[ind]; |
384 s_box[ind] = s_box[j]; | 384 s_box[ind] = s_box[j]; |
385 s_box[j] = tc; | 385 s_box[j] = tc; |
386 } | 386 } |
387 | 387 |
388 } | 388 } |
389 | 389 |
390 void crypt_rc4(rc4_state_struct *rc4_state, unsigned char *data, int data_len) | 390 void crypt_rc4(rc4_state_struct *rc4_state, guchar *data, int data_len) |
391 { | 391 { |
392 unsigned char *s_box; | 392 guchar *s_box; |
393 unsigned char index_i; | 393 guchar index_i; |
394 unsigned char index_j; | 394 guchar index_j; |
395 int ind; | 395 int ind; |
396 | 396 |
397 /* retrieve current state from the state struct (so we can resume where | 397 /* retrieve current state from the state struct (so we can resume where |
398 we left off) */ | 398 we left off) */ |
399 index_i = rc4_state->index_i; | 399 index_i = rc4_state->index_i; |
400 index_j = rc4_state->index_j; | 400 index_j = rc4_state->index_j; |
401 s_box = rc4_state->s_box; | 401 s_box = rc4_state->s_box; |
402 | 402 |
403 for( ind = 0; ind < data_len; ind++) | 403 for( ind = 0; ind < data_len; ind++) |
404 { | 404 { |
405 unsigned char tc; | 405 guchar tc; |
406 unsigned char t; | 406 guchar t; |
407 | 407 |
408 index_i++; | 408 index_i++; |
409 index_j += s_box[index_i]; | 409 index_j += s_box[index_i]; |
410 | 410 |
411 tc = s_box[index_i]; | 411 tc = s_box[index_i]; |
433 * @param response_len Will be written with response length. | 433 * @param response_len Will be written with response length. |
434 * | 434 * |
435 * @return Binary login challenge response, ready to send to the server. Must be g_free()'d | 435 * @return Binary login challenge response, ready to send to the server. Must be g_free()'d |
436 * when finished. | 436 * when finished. |
437 */ | 437 */ |
438 gchar *msim_compute_login_response(gchar nonce[2 * NONCE_SIZE], | 438 const gchar *msim_compute_login_response(const gchar nonce[2 * NONCE_SIZE], |
439 gchar *email, gchar *password, guint *response_len) | 439 const gchar *email, const gchar *password, guint *response_len) |
440 { | 440 { |
441 PurpleCipherContext *key_context; | 441 PurpleCipherContext *key_context; |
442 PurpleCipher *sha1; | 442 PurpleCipher *sha1; |
443 #ifdef MSIM_USE_PURPLE_RC4 | 443 #ifdef MSIM_USE_PURPLE_RC4 |
444 PurpleCipherContext *rc4; | 444 PurpleCipherContext *rc4; |
549 purple_debug_info("msim", "response=<%s>\n", data_out); | 549 purple_debug_info("msim", "response=<%s>\n", data_out); |
550 #endif | 550 #endif |
551 | 551 |
552 *response_len = data_out_len; | 552 *response_len = data_out_len; |
553 | 553 |
554 return (gchar *)data_out; | 554 return (const gchar *)data_out; |
555 } | 555 } |
556 | 556 |
557 /** | 557 /** |
558 * Schedule an IM to be sent once the user ID is looked up. | 558 * Schedule an IM to be sent once the user ID is looked up. |
559 * | 559 * |
566 * | 566 * |
567 * Allows sending to a user by username, email address, or userid. If | 567 * Allows sending to a user by username, email address, or userid. If |
568 * a username or email address is given, the userid must be looked up. | 568 * a username or email address is given, the userid must be looked up. |
569 * This function does that by calling msim_postprocess_outgoing(). | 569 * This function does that by calling msim_postprocess_outgoing(). |
570 */ | 570 */ |
571 int msim_send_im(PurpleConnection *gc, const char *who, | 571 int msim_send_im(PurpleConnection *gc, const gchar *who, |
572 const char *message, PurpleMessageFlags flags) | 572 const gchar *message, PurpleMessageFlags flags) |
573 { | 573 { |
574 MsimSession *session; | 574 MsimSession *session; |
575 | 575 |
576 g_return_val_if_fail(gc != NULL, 0); | 576 g_return_val_if_fail(gc != NULL, 0); |
577 g_return_val_if_fail(who != NULL, 0); | 577 g_return_val_if_fail(who != NULL, 0); |
579 | 579 |
580 /* 'flags' has many options, not used here. */ | 580 /* 'flags' has many options, not used here. */ |
581 | 581 |
582 session = gc->proto_data; | 582 session = gc->proto_data; |
583 | 583 |
584 /* TODO: const-correctness */ | 584 if (msim_send_bm(session, who, message, MSIM_BM_INSTANT)) |
585 if (msim_send_bm(session, (char *)who, (char *)message, MSIM_BM_INSTANT)) | |
586 { | 585 { |
587 /* Return 1 to have Purple show this IM as being sent, 0 to not. I always | 586 /* Return 1 to have Purple show this IM as being sent, 0 to not. I always |
588 * return 1 even if the message could not be sent, since I don't know if | 587 * return 1 even if the message could not be sent, since I don't know if |
589 * it has failed yet--because the IM is only sent after the userid is | 588 * it has failed yet--because the IM is only sent after the userid is |
590 * retrieved from the server (which happens after this function returns). | 589 * retrieved from the server (which happens after this function returns). |
614 * @param text Message text to send. Not freed; will be copied. | 613 * @param text Message text to send. Not freed; will be copied. |
615 * @param type A MSIM_BM_* constant. | 614 * @param type A MSIM_BM_* constant. |
616 * | 615 * |
617 * Buddy messages ('bm') include instant messages, action messages, status messages, etc. | 616 * Buddy messages ('bm') include instant messages, action messages, status messages, etc. |
618 */ | 617 */ |
619 gboolean msim_send_bm(MsimSession *session, gchar *who, gchar *text, int type) | 618 gboolean msim_send_bm(MsimSession *session, const gchar *who, const gchar *text, int type) |
620 { | 619 { |
621 gboolean rc; | 620 gboolean rc; |
622 MsimMessage *msg; | 621 MsimMessage *msg; |
623 const char *from_username = session->account->username; | 622 const gchar *from_username; |
623 | |
624 from_username = session->account->username; | |
624 | 625 |
625 purple_debug_info("msim", "sending %d message from %s to %s: %s\n", | 626 purple_debug_info("msim", "sending %d message from %s to %s: %s\n", |
626 type, from_username, who, text); | 627 type, from_username, who, text); |
627 | 628 |
628 msg = msim_msg_new(TRUE, | 629 msg = msim_msg_new(TRUE, |
631 /* 't' will be inserted here */ | 632 /* 't' will be inserted here */ |
632 "cv", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(MSIM_CLIENT_VERSION), | 633 "cv", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(MSIM_CLIENT_VERSION), |
633 "msg", MSIM_TYPE_STRING, g_strdup(text), | 634 "msg", MSIM_TYPE_STRING, g_strdup(text), |
634 NULL); | 635 NULL); |
635 | 636 |
636 rc = msim_postprocess_outgoing(session, msg, (char *)who, "t", "cv"); | 637 rc = msim_postprocess_outgoing(session, msg, who, "t", "cv"); |
637 | 638 |
638 msim_msg_free(msg); | 639 msim_msg_free(msg); |
639 | 640 |
640 return rc; | 641 return rc; |
641 } | 642 } |
712 * @param gc | 713 * @param gc |
713 * @param name The buddy name to which our user is typing to | 714 * @param name The buddy name to which our user is typing to |
714 * @param state PURPLE_TYPING, PURPLE_TYPED, PURPLE_NOT_TYPING | 715 * @param state PURPLE_TYPING, PURPLE_TYPED, PURPLE_NOT_TYPING |
715 * | 716 * |
716 */ | 717 */ |
717 unsigned int msim_send_typing(PurpleConnection *gc, const char *name, PurpleTypingState state) | 718 unsigned int msim_send_typing(PurpleConnection *gc, const gchar *name, PurpleTypingState state) |
718 { | 719 { |
719 char *typing_str; | 720 const gchar *typing_str; |
720 MsimSession *session; | 721 MsimSession *session; |
721 | 722 |
722 session = (MsimSession *)gc->proto_data; | 723 session = (MsimSession *)gc->proto_data; |
723 | 724 |
724 switch (state) | 725 switch (state) |
733 typing_str = "%stoptyping%"; | 734 typing_str = "%stoptyping%"; |
734 break; | 735 break; |
735 } | 736 } |
736 | 737 |
737 purple_debug_info("msim", "msim_send_typing(%s): %d (%s)\n", name, state, typing_str); | 738 purple_debug_info("msim", "msim_send_typing(%s): %d (%s)\n", name, state, typing_str); |
738 msim_send_bm(session, (gchar *)name, typing_str, MSIM_BM_ACTION); | 739 msim_send_bm(session, name, typing_str, MSIM_BM_ACTION); |
739 return 0; | 740 return 0; |
740 } | 741 } |
741 | 742 |
742 /** Retrieve a user's profile. */ | 743 /** Retrieve a user's profile. */ |
743 void msim_get_info(PurpleConnection *gc, const char *name) | 744 void msim_get_info(PurpleConnection *gc, const gchar *name) |
744 { | 745 { |
745 PurpleNotifyUserInfo *user_info; | 746 PurpleNotifyUserInfo *user_info; |
746 PurpleBuddy *buddy; | 747 PurpleBuddy *buddy; |
747 MsimSession *session; | 748 MsimSession *session; |
748 | 749 |
1381 * If the field named by uid_field_name does not exist, it will be added before the | 1382 * If the field named by uid_field_name does not exist, it will be added before the |
1382 * field named by uid_before, as an integer, with the userid. | 1383 * field named by uid_before, as an integer, with the userid. |
1383 * | 1384 * |
1384 * Does not handle sending, or scheduling userid lookup. For that, see msim_postprocess_outgoing(). | 1385 * Does not handle sending, or scheduling userid lookup. For that, see msim_postprocess_outgoing(). |
1385 */ | 1386 */ |
1386 MsimMessage *msim_do_postprocessing(MsimMessage *msg, gchar *uid_before, gchar *uid_field_name, guint uid) | 1387 MsimMessage *msim_do_postprocessing(MsimMessage *msg, const gchar *uid_before, const gchar *uid_field_name, guint uid) |
1387 { | 1388 { |
1388 purple_debug_info("msim", "msim_do_postprocessing called with ufn=%s, ub=%s, uid=%d\n", | 1389 purple_debug_info("msim", "msim_do_postprocessing called with ufn=%s, ub=%s, uid=%d\n", |
1389 uid_field_name, uid_before, uid); | 1390 uid_field_name, uid_before, uid); |
1390 msim_msg_dump("msim_do_postprocessing msg: %s\n", msg); | 1391 msim_msg_dump("msim_do_postprocessing msg: %s\n", msg); |
1391 | 1392 |
1483 * @param uid_field_name Name of new field to add, containing uid of username. Static string. | 1484 * @param uid_field_name Name of new field to add, containing uid of username. Static string. |
1484 * @param uid_before Name of existing field to insert username field before. Static string. | 1485 * @param uid_before Name of existing field to insert username field before. Static string. |
1485 * | 1486 * |
1486 * @return Postprocessed message. | 1487 * @return Postprocessed message. |
1487 */ | 1488 */ |
1488 gboolean msim_postprocess_outgoing(MsimSession *session, MsimMessage *msg, gchar *username, | 1489 gboolean msim_postprocess_outgoing(MsimSession *session, MsimMessage *msg, const gchar *username, |
1489 gchar *uid_field_name, gchar *uid_before) | 1490 const gchar *uid_field_name, const gchar *uid_before) |
1490 { | 1491 { |
1491 PurpleBuddy *buddy; | 1492 PurpleBuddy *buddy; |
1492 guint uid; | 1493 guint uid; |
1493 gboolean rc; | 1494 gboolean rc; |
1494 | 1495 |
1982 /** | 1983 /** |
1983 * Obtain the status text for a buddy. | 1984 * Obtain the status text for a buddy. |
1984 * | 1985 * |
1985 * @param buddy The buddy to obtain status text for. | 1986 * @param buddy The buddy to obtain status text for. |
1986 * | 1987 * |
1987 * @return Status text, or NULL if error. | 1988 * @return Status text, or NULL if error. Caller g_free()'s. |
1988 * | 1989 * |
1989 */ | 1990 */ |
1990 char *msim_status_text(PurpleBuddy *buddy) | 1991 char *msim_status_text(PurpleBuddy *buddy) |
1991 { | 1992 { |
1992 MsimSession *session; | 1993 MsimSession *session; |
1993 gchar *display_name; | 1994 const gchar *display_name; |
1994 | 1995 |
1995 g_return_val_if_fail(buddy != NULL, NULL); | 1996 g_return_val_if_fail(buddy != NULL, NULL); |
1996 | 1997 |
1997 session = (MsimSession *)buddy->account->gc->proto_data; | 1998 session = (MsimSession *)buddy->account->gc->proto_data; |
1998 g_return_val_if_fail(MSIM_SESSION_VALID(session), NULL); | 1999 g_return_val_if_fail(MSIM_SESSION_VALID(session), NULL); |
1999 | 2000 |
2000 /* TODO: const correctness */ | 2001 /* TODO: const correctness */ |
2001 /* TODO: show Headline, or DisplayName, or selectable, or both? */ | 2002 /* TODO: show Headline, or DisplayName, or selectable, or both? */ |
2002 display_name = (gchar *)purple_blist_node_get_string(&buddy->node, "DisplayName"); | 2003 display_name = purple_blist_node_get_string(&buddy->node, "DisplayName"); |
2003 | 2004 |
2004 if (display_name) | 2005 if (display_name) |
2005 { | 2006 { |
2006 return g_strdup(display_name); | 2007 return g_strdup(display_name); |
2007 } else { | 2008 } else { |