Mercurial > pidgin.yaz
diff libpurple/protocols/msn/notification.c @ 21100:29d8c86c14cd
propagate from branch 'im.pidgin.pidgin' (head cd2be742f6c45c200000003fc5a6341297bbe857)
to branch 'im.pidgin.cpw.khc.msnp14.soap' (head 1d7d51174ae87c7f03bb1290a8e447bf2a1704a5)
author | Ka-Hing Cheung <khc@hxbc.us> |
---|---|
date | Thu, 04 Oct 2007 06:13:01 +0000 |
parents | c49b886231d5 58ce69a8582d |
children | 741c3b5eac21 |
line wrap: on
line diff
--- a/libpurple/protocols/msn/notification.c Wed Oct 03 05:05:35 2007 +0000 +++ b/libpurple/protocols/msn/notification.c Thu Oct 04 06:13:01 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 @@ -588,57 +582,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); @@ -1205,8 +1201,6 @@ MsnSession *session = cmdproc->session; const char *type, *value, *friendlyname; - purple_debug_info("MSN Notification", "prp_cmd()\n"); - g_return_if_fail(cmd->param_count >= 3); type = cmd->params[2];