Mercurial > pidgin.yaz
changeset 20671:4dd60add6a7c
Further cleanup of the msn prpl including preventing the authorization request callback from crashing if triggered after the account is disconnected. Also removal of some extraneous debuggery, there is more that needs to be removed.
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Fri, 28 Sep 2007 01:57:55 +0000 |
parents | 6b9e964f0572 |
children | c8d4fe2cd0d7 70c2ecd55dd8 |
files | libpurple/protocols/msn/contact.c libpurple/protocols/msn/notification.c libpurple/protocols/msn/userlist.c |
diffstat | 3 files changed, 89 insertions(+), 83 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/msn/contact.c Fri Sep 28 01:54:07 2007 +0000 +++ b/libpurple/protocols/msn/contact.c Fri Sep 28 01:57:55 2007 +0000 @@ -474,10 +474,10 @@ gchar *type, *membershipId = NULL; const char *member_type = xmlnode_get_attrib(member, "type"); - purple_debug_info("MSNCL","Member type: %s\n", member_type ? member_type : "(null)"); - - if (!member_type) + if (!member_type) { + purple_debug_error("msn", "No Member Type specified for Member.\n"); continue; + } if(!g_strcasecmp(member_type, "PassportMember") ) { passport = type = NULL; @@ -504,6 +504,7 @@ msn_got_lst_user(session, user, list_op, NULL); } else if (!g_strcasecmp(member_type, "PhoneMember")) { + purple_debug_info("msn", "Recieved Phone Member; ignoring.\n"); } else if (!g_strcasecmp(member_type, "EmailMember")) { xmlnode *emailNode; @@ -526,6 +527,8 @@ } msn_got_lst_user(session, user, list_op, NULL); + } else { + purple_debug_info("msn", "Unknown Member type: %s\n", member_type); } } } @@ -594,8 +597,8 @@ msn_get_contact_list(MsnContact * contact, const MsnSoapPartnerScenario partner_scenario, const char *update_time) { MsnSoapReq *soap_request; - gchar *body = NULL; - gchar * update_str; + gchar *body; + gchar *update_str = NULL; const gchar *partner_scenario_str = MsnSoapPartnerScenarioText[partner_scenario]; purple_debug_misc("MSNCL","Getting Contact List.\n"); @@ -603,11 +606,9 @@ if ( update_time != NULL ) { purple_debug_info("MSNCL","Last update time: %s\n",update_time); update_str = g_strdup_printf(MSN_GET_CONTACT_UPDATE_XML,update_time); - } else { - update_str = g_strdup(""); } - body = g_strdup_printf(MSN_GET_CONTACT_TEMPLATE, partner_scenario_str, update_str); + body = g_strdup_printf(MSN_GET_CONTACT_TEMPLATE, partner_scenario_str, update_str ? update_str : ""); g_free(update_str); soap_request = msn_soap_request_new(MSN_CONTACT_SERVER, @@ -633,13 +634,12 @@ for(group = xmlnode_get_child(node, "Group"); group; group = xmlnode_get_next_twin(group)){ xmlnode *groupId, *groupInfo, *groupname; - char *group_id, *group_name; + char *group_id = NULL, *group_name = NULL; - groupId = xmlnode_get_child(group,"groupId"); - group_id = xmlnode_get_data(groupId); - groupInfo = xmlnode_get_child(group,"groupInfo"); - groupname = xmlnode_get_child(groupInfo,"name"); - group_name = xmlnode_get_data(groupname); + if ((groupId = xmlnode_get_child(group, "groupId"))) + group_id = xmlnode_get_data(groupId); + if ((groupInfo = xmlnode_get_child(group, "groupInfo")) && (groupname = xmlnode_get_child(groupInfo, "name"))) + group_name = xmlnode_get_data(groupname); msn_group_new(session->userlist, group_id, group_name); @@ -649,7 +649,7 @@ continue; } - purple_debug_info("MsnAB","group_id: %s, name: %s\n",group_id,group_name); + purple_debug_info("MsnAB","group_id: %s, name: %s\n", group_id, group_name ? group_name : "(null)"); if ((purple_find_group(group_name)) == NULL){ PurpleGroup *g = purple_group_new(group_name); purple_blist_add_group(g, NULL); @@ -756,7 +756,6 @@ msn_user_set_uid(user, uid); msn_user_set_type(user, usertype); - purple_debug_misc("MsnAB","parse guid...\n"); groupIds = xmlnode_get_child(contactInfo, "groupIds"); if (groupIds) { for (guid = xmlnode_get_child(groupIds, "guid"); guid; @@ -767,6 +766,7 @@ g_free(group_id); } } else { + purple_debug_info("msn", "User not in any groups, adding to default group.\n"); /*not in any group,Then set default group*/ msn_user_add_group_id(user, MSN_INDIVIDUALS_GROUP_ID); } @@ -783,17 +783,15 @@ static gboolean msn_parse_addressbook(MsnContact * contact) { - MsnSession * session; + MsnSession *session; xmlnode * node,*body,*response,*result; xmlnode *groups; - xmlnode *contacts; + xmlnode *contacts; xmlnode *abNode; xmlnode *fault, *faultstringnode, *faultdetail, *errorcode; session = contact->session; - - node = xmlnode_from_str(contact->soapconn->body, contact->soapconn->body_len); if ( node == NULL ) { purple_debug_error("MSN AddressBook","Error parsing Address Book with size %d\n", contact->soapconn->body_len); @@ -802,8 +800,11 @@ purple_debug_misc("MSN AddressBook", "Parsing Address Book with size %d\n", contact->soapconn->body_len); - purple_debug_misc("MSN AddressBook","node{%p},name:%s,child:%s,last:%s\n",node,node->name,node->child->name,node->lastchild->name); - + purple_debug_misc("MSN AddressBook","node{%p},name:%s,child:%s,last:%s\n", node, + node->name ? node->name : "(null)", + (node->child && node->child->name) ? node->child->name : "(null)", + (node->lastchild && node->lastchild->name) ? node->lastchild->name : "(null)"); + body = xmlnode_get_child(node,"Body"); purple_debug_misc("MSN AddressBook","body{%p},name:%s\n",body,body->name); @@ -1401,14 +1402,17 @@ msn_update_contact(MsnContact *contact, const char* nickname) { MsnSoapReq *soap_request; - gchar *body = NULL, *escaped_nickname; + gchar *body, *escaped_nickname; + + /* I'm not sure this is right, but if it isn't, the rest of this function will need to be fixed */ + g_return_if_fail(nickname != NULL); purple_debug_info("MSN CL","Update contact information with new friendly name: %s\n", nickname); - + escaped_nickname = g_markup_escape_text(nickname, -1); body = g_strdup_printf(MSN_CONTACT_UPDATE_TEMPLATE, escaped_nickname); - + g_free(escaped_nickname); /*build SOAP and POST it*/ soap_request = msn_soap_request_new(MSN_CONTACT_SERVER,
--- a/libpurple/protocols/msn/notification.c Fri Sep 28 01:54:07 2007 +0000 +++ b/libpurple/protocols/msn/notification.c Fri Sep 28 01:57:55 2007 +0000 @@ -101,7 +101,8 @@ MsnCmdProc *cmdproc; MsnSession *session; PurpleAccount *account; - char **a, **c, *vers; + GString *vers; + const char *ver_str; int i; g_return_if_fail(servconn != NULL); @@ -110,31 +111,24 @@ session = servconn->session; account = session->account; - /* Allocate an array for CVR0, NULL, and all the versions */ -// a = c = g_new0(char *, session->protocol_ver - WLM_MIN_PROTOCOL + 3); - a = c = g_new0(char *, WLM_MAX_PROTOCOL - WLM_MIN_PROTOCOL + 3); + vers = g_string_new(""); -// for (i = session->protocol_ver; i >= WLM_MIN_PROTOCOL; i--) +/* for (i = session->protocol_ver; i >= WLM_MIN_PROTOCOL; i--) */ for (i = WLM_MAX_PROTOCOL; i >= WLM_MIN_PROTOCOL; i--) - *c++ = g_strdup_printf("MSNP%d", i); + g_string_append_printf(vers, " MSNP%d", i); - *c++ = g_strdup("CVR0"); - - vers = g_strjoinv(" ", a); + g_string_append(vers, " CVR0"); if (session->login_step == MSN_LOGIN_STEP_START) - { msn_session_set_login_step(session, MSN_LOGIN_STEP_HANDSHAKE); - } else - { msn_session_set_login_step(session, MSN_LOGIN_STEP_HANDSHAKE2); - } - msn_cmdproc_send(cmdproc, "VER", "%s", vers); + /* Skip the initial space */ + ver_str = (vers->str + 1); + msn_cmdproc_send(cmdproc, "VER", "%s", ver_str); - g_strfreev(a); - g_free(vers); + g_string_free(vers, TRUE); } gboolean @@ -189,7 +183,7 @@ const char *group_name; group_name = msn_userlist_find_group_name(session->userlist,group_id); reason = g_strdup_printf(_("%s is not a valid group."), - group_name); + group_name ? group_name : ""); } } else @@ -590,57 +584,59 @@ { xmlnode *d_node,*c_node; char **tokens; - char *email,*domain; - char *list_op_str,*type_str; + const char *email,*domain; + char fmt_str[3]; + + g_return_if_fail(passport != NULL); purple_debug_info("MSNP14","Passport: %s, type: %d\n", passport, type); tokens = g_strsplit(passport, "@", 2); email = tokens[0]; domain = tokens[1]; + if (email == NULL || domain == NULL) { + purple_debug_error("msn", "Invalid passport (%s) specified to add to contact xml.\n", passport); + g_strfreev(tokens); + g_return_if_reached(); + } + /*find a domain Node*/ for(d_node = xmlnode_get_child(mlNode,"d"); d_node; d_node = xmlnode_get_next_twin(d_node)) { - const char * attr = NULL; - purple_debug_info("MSNP14","d_node: %s\n",d_node->name); - attr = xmlnode_get_attrib(d_node,"n"); - if(attr == NULL){ + const char *attr = xmlnode_get_attrib(d_node,"n"); + if (attr == NULL) continue; - } - if(!strcmp(attr,domain)){ + if (!strcmp(attr,domain)) break; - } } + if(d_node == NULL) { /*domain not found, create a new domain Node*/ - purple_debug_info("MSNP14","get No d_node\n"); + purple_debug_info("msn", "Didn't find existing domain node, adding one.\n"); d_node = xmlnode_new("d"); - xmlnode_set_attrib(d_node,"n",domain); - xmlnode_insert_child(mlNode,d_node); + xmlnode_set_attrib(d_node, "n", domain); + xmlnode_insert_child(mlNode, d_node); } /*create contact node*/ c_node = xmlnode_new("c"); - xmlnode_set_attrib(c_node,"n",email); + xmlnode_set_attrib(c_node, "n", email); - list_op_str = g_strdup_printf("%d",list_op); - purple_debug_info("MSNP14","list_op: %d\n",list_op); - xmlnode_set_attrib(c_node,"l",list_op_str); - g_free(list_op_str); + purple_debug_info("MSNP14", "list_op: %d\n", list_op); + g_snprintf(fmt_str, sizeof(fmt_str), "%d", list_op); + xmlnode_set_attrib(c_node, "l", fmt_str); - if (type != MSN_USER_TYPE_UNKNOWN) { - type_str = g_strdup_printf("%d", type); - } else { - if (msn_user_is_yahoo(session->account, passport)) - type_str = g_strdup_printf("%d", MSN_USER_TYPE_YAHOO); - else - type_str = g_strdup_printf("%d", MSN_USER_TYPE_PASSPORT); - } + if (type != MSN_USER_TYPE_UNKNOWN) + g_snprintf(fmt_str, sizeof(fmt_str), "%d", type); + else if (msn_user_is_yahoo(session->account, passport)) + g_snprintf(fmt_str, sizeof(fmt_str), "%d", MSN_USER_TYPE_YAHOO); + else + g_snprintf(fmt_str, sizeof(fmt_str), "%d", MSN_USER_TYPE_PASSPORT); + /*mobile*/ //type_str = g_strdup_printf("4"); - xmlnode_set_attrib(c_node,"t",type_str); - g_free(type_str); + xmlnode_set_attrib(c_node, "t", fmt_str); xmlnode_insert_child(d_node, c_node);
--- a/libpurple/protocols/msn/userlist.c Fri Sep 28 01:54:07 2007 +0000 +++ b/libpurple/protocols/msn/userlist.c Fri Sep 28 01:57:55 2007 +0000 @@ -41,16 +41,20 @@ msn_accept_add_cb(gpointer data) { MsnPermitAdd *pa = data; - MsnSession *session = pa->gc->proto_data; - MsnUserList *userlist = session->userlist; - MsnUser *user = msn_userlist_find_add_user(userlist, pa->who, pa->who); - + purple_debug_misc("MSN Userlist", "Accepted the new buddy: %s\n", pa->who); - msn_userlist_add_buddy_to_list(userlist, pa->who, MSN_LIST_AL); + if (PURPLE_CONNECTION_IS_VALID(pa->gc)) + { + MsnSession *session = pa->gc->proto_data; + MsnUserList *userlist = session->userlist; + MsnUser *user = msn_userlist_find_add_user(userlist, pa->who, pa->who); - if (msn_userlist_user_is_in_list(user, MSN_LIST_FL)) { - msn_del_contact_from_list(session->contact, NULL, pa->who, MSN_LIST_PL); + + msn_userlist_add_buddy_to_list(userlist, pa->who, MSN_LIST_AL); + + if (msn_userlist_user_is_in_list(user, MSN_LIST_FL)) + msn_del_contact_from_list(session->contact, NULL, pa->who, MSN_LIST_PL); } g_free(pa->who); @@ -63,14 +67,14 @@ { MsnPermitAdd *pa = data; - purple_debug_misc("MSN Userlist", "Deniedthe new buddy: %s\n", pa->who); + purple_debug_misc("MSN Userlist", "Denied the new buddy: %s\n", pa->who); - if (g_list_find(purple_connections_get_all(), pa->gc) != NULL) + if (PURPLE_CONNECTION_IS_VALID(pa->gc)) { MsnSession *session = pa->gc->proto_data; MsnUserList *userlist = session->userlist; MsnCallbackState *state = msn_callback_state_new(); - + msn_callback_state_set_action(state, MSN_DENIED_BUDDY); msn_userlist_add_buddy_to_list(userlist, pa->who, MSN_LIST_BL); @@ -85,16 +89,18 @@ static void got_new_entry(PurpleConnection *gc, const char *passport, const char *friendly) { + PurpleAccount *acct; MsnPermitAdd *pa; pa = g_new0(MsnPermitAdd, 1); pa->who = g_strdup(passport); pa->friendly = g_strdup(friendly); pa->gc = gc; - - purple_account_request_authorization(purple_connection_get_account(gc), passport, NULL, friendly, NULL, - purple_find_buddy(purple_connection_get_account(gc), passport) != NULL, - msn_accept_add_cb, msn_cancel_add_cb, pa); + + acct = purple_connection_get_account(gc); + purple_account_request_authorization(acct, passport, NULL, friendly, NULL, + purple_find_buddy(acct, passport) != NULL, + msn_accept_add_cb, msn_cancel_add_cb, pa); }