diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2010-08-12 00:03:33 +0100 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2010-08-12 00:03:33 +0100 |
commit | 7f34ce254c1a1587e5560456dd11acb29345206d (patch) | |
tree | 94df95bac535a5a395980ea8eef815ddad2f2c69 | |
parent | 523fb2324a351e9607ad2a803c6e866c5175aa16 (diff) |
Get contact list/address book info. Next step: We have to send it back.
Seriously. Wish I were joking.
-rw-r--r-- | protocols/msn/msn.c | 13 | ||||
-rw-r--r-- | protocols/msn/msn.h | 15 | ||||
-rw-r--r-- | protocols/msn/soap.c | 154 | ||||
-rw-r--r-- | protocols/msn/soap.h | 33 |
4 files changed, 202 insertions, 13 deletions
diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index 10c27a1d..0b9cffc2 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -333,6 +333,16 @@ static char *set_eval_display_name( set_t *set, char *value ) return msn_set_display_name( ic, value ) ? value : NULL; } +static void msn_buddy_data_add( bee_user_t *bu ) +{ + bu->data = g_new0( struct msn_buddy_data, 1 ); +} + +static void msn_buddy_data_free( bee_user_t *bu ) +{ + g_free( bu->data ); +} + void msn_initmodule() { struct prpl *ret = g_new0(struct prpl, 1); @@ -359,6 +369,9 @@ void msn_initmodule() ret->rem_deny = msn_rem_deny; ret->send_typing = msn_send_typing; ret->handle_cmp = g_strcasecmp; + ret->buddy_data_add = msn_buddy_data_add; + ret->buddy_data_free = msn_buddy_data_free; + //ret->transfer_request = msn_ftp_transfer_request; register_protocol(ret); diff --git a/protocols/msn/msn.h b/protocols/msn/msn.h index d4f3442e..757359fe 100644 --- a/protocols/msn/msn.h +++ b/protocols/msn/msn.h @@ -150,6 +150,21 @@ struct msn_handler_data int (*exec_message) ( gpointer data, char *msg, int msglen, char **cmd, int count ); }; +typedef enum +{ + MSN_BUDDY_FL = 1, + MSN_BUDDY_AL = 2, + MSN_BUDDY_BL = 4, + MSN_BUDDY_RL = 8, + MSN_BUDDY_PL = 16, +} msn_buddy_flags_t; + +struct msn_buddy_data +{ + char *cid; + msn_buddy_flags_t flags; +}; + /* Bitfield values for msn_status_code.flags */ #define STATUS_FATAL 1 #define STATUS_SB_FATAL 2 diff --git a/protocols/msn/soap.c b/protocols/msn/soap.c index e837986e..62d58200 100644 --- a/protocols/msn/soap.c +++ b/protocols/msn/soap.c @@ -422,32 +422,61 @@ int msn_soap_oim_send_queue( struct im_connection *ic, GSList **msgq ) /* memlist: Fetching the membership list (NOT address book) */ -#if 0 -struct msn_soap_oim_send_data -{ - char *to; - char *msg; - int number; - int need_retry; -}; -#endif - static int msn_soap_memlist_build_request( struct msn_soap_req_data *soap_req ) { + struct msn_data *md = soap_req->ic->proto_data; + soap_req->url = g_strdup( SOAP_MEMLIST_URL ); soap_req->action = g_strdup( SOAP_MEMLIST_ACTION ); - soap_req->payload = g_strdup( SOAP_MEMLIST_PAYLOAD ); + soap_req->payload = g_markup_printf_escaped( SOAP_MEMLIST_PAYLOAD, md->tokens[1] ); return 1; } +static xt_status msn_soap_memlist_member( struct xt_node *node, gpointer data ) +{ + bee_user_t *bu; + struct msn_buddy_data *bd; + struct xt_node *p; + char *role = NULL, *handle = NULL; + struct msn_soap_req_data *soap_req = data; + struct im_connection *ic = soap_req->ic; + + if( ( p = node->parent ) && ( p = p->parent ) && + ( p = xt_find_node( p->children, "MemberRole" ) ) ) + role = p->text; + + if( ( p = xt_find_node( node->children, "PassportName" ) ) ) + handle = p->text; + + if( !role || !handle || + !( ( bu = bee_user_by_handle( ic->bee, ic, handle ) ) || + ( bu = bee_user_new( ic->bee, ic, handle, 0 ) ) ) ) + return XT_HANDLED; + + bd = bu->data; + if( strcmp( role, "Allow" ) == 0 ) + bd->flags |= MSN_BUDDY_AL; + else if( strcmp( role, "Block" ) == 0 ) + bd->flags |= MSN_BUDDY_BL; + else if( strcmp( role, "Reverse" ) == 0 ) + bd->flags |= MSN_BUDDY_RL; + else if( strcmp( role, "Pending" ) == 0 ) + bd->flags |= MSN_BUDDY_PL; + + return XT_HANDLED; +} + static const struct xt_handler_entry msn_soap_memlist_parser[] = { + { "Member", "Members", msn_soap_memlist_member }, { NULL, NULL, NULL } }; static int msn_soap_memlist_handle_response( struct msn_soap_req_data *soap_req ) { - return 0; + msn_soap_addressbook_request( soap_req->ic ); + + return MSN_SOAP_OK; } static int msn_soap_memlist_free_data( struct msn_soap_req_data *soap_req ) @@ -462,3 +491,104 @@ int msn_soap_memlist_request( struct im_connection *ic ) msn_soap_memlist_handle_response, msn_soap_memlist_free_data ); } + + +/* addressbook: Fetching the membership list (NOT address book) */ + +static int msn_soap_addressbook_build_request( struct msn_soap_req_data *soap_req ) +{ + struct msn_data *md = soap_req->ic->proto_data; + + soap_req->url = g_strdup( SOAP_ADDRESSBOOK_URL ); + soap_req->action = g_strdup( SOAP_ADDRESSBOOK_ACTION ); + soap_req->payload = g_markup_printf_escaped( SOAP_ADDRESSBOOK_PAYLOAD, md->tokens[1] ); + + return 1; +} + +static xt_status msn_soap_addressbook_group( struct xt_node *node, gpointer data ) +{ + struct xt_node *p; + char *id = NULL, *name = NULL; + struct msn_soap_req_data *soap_req = data; + struct im_connection *ic = soap_req->ic; + + if( ( p = node->parent ) && + ( p = xt_find_node( p->children, "groupId" ) ) ) + id = p->text; + + if( ( p = xt_find_node( node->children, "name" ) ) ) + name = p->text; + + printf( "%s %s\n", id, name ); + + return XT_HANDLED; +} + +static xt_status msn_soap_addressbook_contact( struct xt_node *node, gpointer data ) +{ + bee_user_t *bu; + struct msn_buddy_data *bd; + struct xt_node *p; + char *id = NULL, *type = NULL, *handle = NULL, *display_name = NULL; + struct msn_soap_req_data *soap_req = data; + struct im_connection *ic = soap_req->ic; + + if( ( p = node->parent ) && + ( p = xt_find_node( p->children, "contactId" ) ) ) + id = p->text; + if( ( p = xt_find_node( node->children, "contactType" ) ) ) + type = p->text; + if( ( p = xt_find_node( node->children, "passportName" ) ) ) + handle = p->text; + if( ( p = xt_find_node( node->children, "displayName" ) ) ) + display_name = p->text; + + if( type && g_strcasecmp( type, "me" ) == 0 ) + { + set_t *set = set_find( &ic->acc->set, "display_name" ); + g_free( set->value ); + set->value = g_strdup( display_name ); + + return XT_HANDLED; + } + + if( !( bu = bee_user_by_handle( ic->bee, ic, handle ) ) && + !( bu = bee_user_new( ic->bee, ic, handle, 0 ) ) ) + return XT_HANDLED; + + bd = bu->data; + bd->flags |= MSN_BUDDY_FL; + g_free( bd->cid ); + bd->cid = g_strdup( id ); + + imcb_rename_buddy( ic, handle, display_name ); + + printf( "%s %s %s %s\n", id, type, handle, display_name ); + + return XT_HANDLED; +} + +static const struct xt_handler_entry msn_soap_addressbook_parser[] = { + { "contactInfo", "Contact", msn_soap_addressbook_contact }, + { "groupInfo", "Group", msn_soap_addressbook_group }, + { NULL, NULL, NULL } +}; + +static int msn_soap_addressbook_handle_response( struct msn_soap_req_data *soap_req ) +{ + return MSN_SOAP_OK; +} + +static int msn_soap_addressbook_free_data( struct msn_soap_req_data *soap_req ) +{ + return 0; +} + +int msn_soap_addressbook_request( struct im_connection *ic ) +{ + return msn_soap_start( ic, NULL, msn_soap_addressbook_build_request, + msn_soap_addressbook_parser, + msn_soap_addressbook_handle_response, + msn_soap_addressbook_free_data ); +} diff --git a/protocols/msn/soap.h b/protocols/msn/soap.h index 5fbac3c4..9eb1caef 100644 --- a/protocols/msn/soap.h +++ b/protocols/msn/soap.h @@ -151,7 +151,7 @@ int msn_soap_oim_send( struct im_connection *ic, const char *to, const char *msg int msn_soap_oim_send_queue( struct im_connection *ic, GSList **msgq ); -#define SOAP_MEMLIST_URL "https://byrdr.omega.contacts.msn.com/abservice/SharingService.asmx" +#define SOAP_MEMLIST_URL "http://contacts.msn.com/abservice/SharingService.asmx" #define SOAP_MEMLIST_ACTION "http://www.msn.com/webservices/AddressBook/FindMembership" #define SOAP_MEMLIST_PAYLOAD \ @@ -165,6 +165,7 @@ int msn_soap_oim_send_queue( struct im_connection *ic, GSList **msgq ); "</ABApplicationHeader>" \ "<ABAuthHeader xmlns=\"http://www.msn.com/webservices/AddressBook\">" \ "<ManagedGroupRequest xmlns=\"http://www.msn.com/webservices/AddressBook\">false</ManagedGroupRequest>" \ + "<TicketToken>%s</TicketToken>" \ "</ABAuthHeader>" \ "</soap:Header>" \ "<soap:Body xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" \ @@ -176,4 +177,34 @@ int msn_soap_oim_send_queue( struct im_connection *ic, GSList **msgq ); int msn_soap_memlist_request( struct im_connection *ic ); +#define SOAP_ADDRESSBOOK_URL "http://contacts.msn.com/abservice/abservice.asmx" +#define SOAP_ADDRESSBOOK_ACTION "http://www.msn.com/webservices/AddressBook/ABFindAll" + +#define SOAP_ADDRESSBOOK_PAYLOAD \ +"<?xml version=\"1.0\" encoding=\"utf-8\"?>" \ +"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">" \ + "<soap:Header>" \ + "<ABApplicationHeader xmlns=\"http://www.msn.com/webservices/AddressBook\">" \ + "<ApplicationId>CFE80F9D-180F-4399-82AB-413F33A1FA11</ApplicationId>" \ + "<IsMigration>false</IsMigration>" \ + "<PartnerScenario>Initial</PartnerScenario>" \ + "</ABApplicationHeader>" \ + "<ABAuthHeader xmlns=\"http://www.msn.com/webservices/AddressBook\">" \ + "<ManagedGroupRequest>false</ManagedGroupRequest>" \ + "<TicketToken>%s</TicketToken>" \ + "</ABAuthHeader>" \ + "</soap:Header>" \ + "<soap:Body>" \ + "<ABFindAll xmlns=\"http://www.msn.com/webservices/AddressBook\">" \ + "<abId>00000000-0000-0000-0000-000000000000</abId>" \ + "<abView>Full</abView>" \ + "<deltasOnly>false</deltasOnly>" \ + "<lastChange>0001-01-01T00:00:00.0000000-08:00</lastChange>" \ + "</ABFindAll>" \ + "</soap:Body>" \ +"</soap:Envelope>" + +int msn_soap_addressbook_request( struct im_connection *ic ); + + #endif /* __SOAP_H__ */ |