From: Siddhesh P. <sid...@us...> - 2009-09-06 13:11:19
|
Update of /cvsroot/ayttm/ayttm/modules/msn2/libmsn2 In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv16545/modules/msn2/libmsn2 Modified Files: msn-commands.c msn-contacts.c msn-message.h Log Message: * MSN: Dynamically add and remove buddies * MSN: Free message payload in the end * MSN: Fixed double adding of buddy when someone else adds us Index: msn-commands.c =================================================================== RCS file: /cvsroot/ayttm/ayttm/modules/msn2/libmsn2/msn-commands.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- msn-commands.c 30 Aug 2009 14:55:58 -0000 1.6 +++ msn-commands.c 6 Sep 2009 13:11:04 -0000 1.7 @@ -127,7 +127,7 @@ { "QRY", MSN_COMMAND_QRY, 3, 3, msn_command_got_QRY, msn_command_parse_payload_QRY }, { "SBS", MSN_COMMAND_SBS, 2, 0, msn_command_got_SBS, NULL }, { "REA", MSN_COMMAND_REA, 0, 0, msn_command_got_REA, NULL }, - { "RML", MSN_COMMAND_RML, 0, 0, msn_command_got_RML, NULL }, + { "RML", MSN_COMMAND_RML, 2, 2, msn_command_got_RML, NULL }, { "RMG", MSN_COMMAND_RMG, 0, 0, msn_command_got_RMG, NULL }, { "UBX", MSN_COMMAND_UBX, 3, 3, msn_command_got_UBX, msn_command_parse_payload_UBX }, { "SDC", MSN_COMMAND_SDC, 0, 0, msn_command_got_SDC, NULL }, @@ -168,41 +168,88 @@ static void msn_command_parse_payload_FQY (MsnMessage *msg) { - if(!msg->payload_info) { - msg->payload_info = m_new0(MsnMessagePayload, 1); - } + } static void msn_command_parse_payload_ADL (MsnMessage *msg) { - if(!msg->payload_info) { - msg->payload_info = m_new0(MsnMessagePayload, 1); + char *start = NULL; + LList *newbuds = NULL; + start = strstr(msg->payload, "<d n="); + + while(start) { + char *users = NULL, *user = NULL; + char *domain = start+6; + char *end = strchr(domain, '>'); + + *(end-1) = '\0'; + users = end+1; + end = strstr(end, "</d>"); + *end = '\0'; + + while((user = strstr(users, "<c "))) { + char buddy_buf[255]; + char *buddy_name; + char *attr = NULL, *attr_end = NULL; + int type = 0; + int list = 0; + char *uend = strstr(user, "/>"); + + MsnBuddy *bud = m_new0(MsnBuddy, 1); + + user += 3; + *uend = '\0'; + + attr = strstr(user, "n=\""); + attr += 3; + attr_end = strchr(attr, '\"'); + + *attr_end = '\0'; + buddy_name = strdup(attr); + *attr_end = '\"'; + + if((attr = strstr(user, "t=\""))) + type = attr[3] - '0'; + + if((attr = strstr(user, "l=\""))) + list = attr[3] - '0'; + + snprintf(buddy_buf, sizeof(buddy_buf), "%s@%s", buddy_name, domain); + + bud->passport = strdup(buddy_buf); + bud->type = (type == 1)?MSN_BUDDY_PASSPORT:MSN_BUDDY_EMAIL; + bud->list = list; + + newbuds = l_list_append(newbuds, bud); + + free(buddy_name); + + users = uend+1; + } + + start = strstr(end+1, "<d n="); } + + msg->payload_info = newbuds; } static void msn_command_parse_payload_GCF (MsnMessage *msg) { - if(!msg->payload_info) { - msg->payload_info = m_new0(MsnMessagePayload, 1); - } + } static void msn_command_parse_payload_UBX (MsnMessage *msg) { - if(!msg->payload_info) { - msg->payload_info = m_new0(MsnMessagePayload, 1); - } + } static void msn_command_parse_payload_QRY (MsnMessage *msg) { - if(!msg->payload_info) { - msg->payload_info = m_new0(MsnMessagePayload, 1); - } + } @@ -360,7 +407,7 @@ bud = buds->data; if(!strcmp(bud->passport, msg->argv[3])) { - if(strcmp(bud->friendlyname, msg->argv[5])) { + if(!bud->friendlyname || strcmp(bud->friendlyname, msg->argv[5])) { free(bud->friendlyname); bud->friendlyname = msn_urldecode(msg->argv[5]); } @@ -515,16 +562,51 @@ ext_got_unknown_IM(mc, im, nick); } + free(payload_info); free(im->body); free(im->color); free(im->font); free(im); + + mc->current_message->payload_info = NULL; } static void msn_command_got_ADL (MsnConnection *mc) { + LList *l1, *l2; + LList *newbuds = mc->current_message->payload_info; + MsnAccount *ma = mc->account; + + for(l1 = newbuds; l1; l1 = l_list_next(l1)) { + int exists = 0; + MsnBuddy *newbud = l1->data; + + /* See if this buddy exists */ + for(l2 = ma->buddies; l2; l2 = l_list_next(l2)) { + MsnBuddy *bud = l2->data; + if(!strcmp(newbud->passport, bud->passport)) { + /* Don't want to mess up the allow and block lists accidentally */ + if(!(bud->list & MSN_BUDDY_ALLOW || bud->list & MSN_BUDDY_BLOCK)) + bud->list = newbud->list; + + msn_buddy_free(newbud); + exists = 1; + break; + } + } + + if(exists) + continue; + + if(ext_buddy_request(ma, newbud)) + msn_buddy_allow(ma, newbud); + + ma->buddies = l_list_append(ma->buddies, newbud); + } + l_list_free(newbuds); + mc->current_message->payload_info = NULL; } Index: msn-contacts.c =================================================================== RCS file: /cvsroot/ayttm/ayttm/modules/msn2/libmsn2/msn-contacts.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- msn-contacts.c 31 Aug 2009 11:10:02 -0000 1.8 +++ msn-contacts.c 6 Sep 2009 13:11:04 -0000 1.9 @@ -84,7 +84,14 @@ } -void msn_got_initial_fqy_response(MsnConnection *mc, void *data) +void msn_got_adl_response(MsnConnection *mc, void *data) +{ + /* Do nothing for now */ +} + + +/* Saved for FQY parsing +void msn_buddies_send_adl(MsnConnection *ma, LList *buddies) { MsnMessage *msg = mc->current_message; char out[MAX_ADL_SIZE], bufsize[5]; @@ -145,14 +152,14 @@ msn_connection_push_callback(mc, msn_got_initial_adl_response, NULL); } +*/ /* This has become a convoluted piece of crap. Need to rework */ -static void _send_adl(MsnAccount *ma) +void msn_buddies_send_adl(MsnAccount *ma, LList *in, int initial, int add) { char buf[MAX_ADL_SIZE]; char bufsize[5]; - LList *in = ma->buddies; LList *l = NULL; int count = 0; int init = 0; @@ -209,9 +216,10 @@ } if( (count < MAX_ADL_CONTACTS - 1 && !strcmp(cur_domain, a->domain)) ) { - if(cur_type == MSN_BUDDY_PASSPORT) + if(!initial || cur_type == MSN_BUDDY_PASSPORT) snprintf(buf + offset, sizeof(buf) - offset, - "<c n=\"%s\" l=\"%u\" t=\"1\"/>", a->name, a->mask); + "<c n=\"%s\" l=\"%u\" t=\"%d\"/>", a->name, a->mask, + (cur_type==MSN_BUDDY_PASSPORT)?1:4); else snprintf(buf + offset, sizeof(buf) - offset, "<c n=\"%s\"/>", a->name); @@ -221,7 +229,7 @@ snprintf(bufsize, sizeof(bufsize), "%d", (int)strlen(buf)); - if(cur_type == MSN_BUDDY_PASSPORT) + if(!initial || cur_type == MSN_BUDDY_PASSPORT) msn_message_send(ma->ns_connection, buf, MSN_COMMAND_ADL, bufsize); else msn_message_send(ma->ns_connection, buf, MSN_COMMAND_FQY, bufsize); @@ -231,14 +239,29 @@ offset = 0; count = 0; - snprintf(buf, sizeof(buf), "<ml><d n=\"%s\"><c n=\"%s\"/>", a->domain, a->name); + offset = snprintf(buf, sizeof(buf), "<ml><d n=\"%s\">", a->domain); cur_domain = a->domain; cur_type = a->type; + + if(!initial || cur_type == MSN_BUDDY_PASSPORT) + snprintf(buf + offset, sizeof(buf) - offset, + "<c n=\"%s\" l=\"%u\" t=\"%d\"/>", a->name, a->mask, + (cur_type==MSN_BUDDY_PASSPORT)?1:4); + else + snprintf(buf + offset, sizeof(buf) - offset, + "<c n=\"%s\"/>", a->name); } else { - snprintf(buf+offset, sizeof(buf)-offset, "</d><d n=\"%s\"><c n=\"%s\" l=\"%u\" t=\"1\"/>", - a->domain, a->name, a->mask); + offset += snprintf(buf+offset, sizeof(buf)-offset, "</d><d n=\"%s\">", a->domain); + + if(!initial || cur_type == MSN_BUDDY_PASSPORT) + snprintf(buf + offset, sizeof(buf) - offset, + "<c n=\"%s\" l=\"%u\" t=\"%d\"/>", a->name, a->mask, + (cur_type==MSN_BUDDY_PASSPORT)?1:4); + else + snprintf(buf + offset, sizeof(buf) - offset, + "<c n=\"%s\"/>", a->name); cur_domain = a->domain; } @@ -254,7 +277,7 @@ if(count) { snprintf(buf+offset, sizeof(buf)-offset, "</d></ml>"); snprintf(bufsize, sizeof(bufsize), "%d", (int)strlen(buf)); - if(cur_type == MSN_BUDDY_PASSPORT) + if(!initial || cur_type == MSN_BUDDY_PASSPORT) msn_message_send(ma->ns_connection, buf, MSN_COMMAND_ADL, bufsize); else msn_message_send(ma->ns_connection, buf, MSN_COMMAND_FQY, bufsize); @@ -262,11 +285,14 @@ sent = 1; } - if(sent) - msn_connection_push_callback(ma->ns_connection, msn_got_initial_adl_response, NULL); - else - ext_msn_contacts_synced(ma); - + if(initial) { + if(sent) + msn_connection_push_callback(ma->ns_connection, msn_got_initial_adl_response, NULL); + else + ext_msn_contacts_synced(ma); + } + else if(add) + msn_connection_push_callback(ma->ns_connection, msn_got_adl_response, in); } @@ -419,7 +445,7 @@ } ret: - _send_adl(ma); + msn_buddies_send_adl(ma, ma->buddies, 1, 0); /* Send your friendly name */ msn_message_send(ma->ns_connection, NULL, MSN_COMMAND_PRP, "MFN", ma->friendlyname); @@ -1011,6 +1037,8 @@ start += 6; offset = strstr(start, "</guid>"); if(offset) { + LList *l = NULL; + *offset = '\0'; bud->contact_id = strdup(start); @@ -1021,7 +1049,15 @@ bud->list &= ~MSN_BUDDY_PENDING; bud->list |= MSN_BUDDY_ALLOW; bud->list |= MSN_BUDDY_FORWARD; + + l = l_list_append(l, bud); + + ma->buddies = l_list_append(ma->buddies, bud); + ext_buddy_added(ma, bud); + msn_buddies_send_adl(ma, l, 0, 1); + + l_list_free(l); } } } @@ -1058,7 +1094,13 @@ void msn_buddy_allow(MsnAccount *ma, MsnBuddy *bud) { - MsnMembershipData *mmbr = m_new0(MsnMembershipData, 1); + MsnMembershipData *mmbr; + + /* Why allow again? */ + if(bud->list & MSN_BUDDY_ALLOW) + return; + + mmbr = m_new0(MsnMembershipData, 1); mmbr->add = 1; mmbr->scenario = "ContactMsgrAPI"; @@ -1117,12 +1159,31 @@ /* Remove buddy */ +static void msn_buddy_rml(MsnAccount *ma, MsnBuddy *bud) +{ + char buf[255]; + int size = 0; + char bufsize[4]; + char *sep = strchr(bud->passport, '@'); + + *sep = '\0'; + size = snprintf(buf, sizeof(buf), "<ml><d n=\"%s\"><c n=\"%s\" t=\"%d\" l=\"%d\"/></d></ml>", + sep+1, bud->passport, 1, + (bud->list & (MSN_BUDDY_ALLOW | MSN_BUDDY_FORWARD | MSN_BUDDY_BLOCK))); + + sprintf(bufsize, "%d", size); + + msn_message_send(ma->ns_connection, buf, MSN_COMMAND_RML, bufsize); +} + + static void msn_contact_remove_response(MsnAccount *ma, char *data, int len, void *cbdata) { MsnBuddy *bud = cbdata; char *offset; if((offset = strstr(data, "<ABContactDeleteResponse"))) { + msn_buddy_rml(ma, bud); ext_buddy_removed(ma, bud->passport); ma->buddies = l_list_remove(ma->buddies, bud); Index: msn-message.h =================================================================== RCS file: /cvsroot/ayttm/ayttm/modules/msn2/libmsn2/msn-message.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- msn-message.h 30 Aug 2009 14:55:58 -0000 1.6 +++ msn-message.h 6 Sep 2009 13:11:04 -0000 1.7 @@ -83,8 +83,8 @@ char *payload; /* Payload Data */ int payload_offset; /* Current size of the payload */ int state; /* State of the message. 0 when complete. */ - void *payload_info; /* Payload parsed into message-specific information. - For now it only houses objects of MsnMessagePayload */ + void *payload_info; /* Payload parsed into message-specific information. */ + int capacity; /* Capacity of the payload */ }; |