Ignore:
Timestamp:
2010-08-11T23:03:33Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
ca7de3a
Parents:
523fb23
Message:

Get contact list/address book info. Next step: We have to send it back.
Seriously. Wish I were joking.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/msn/soap.c

    r523fb23 r7f34ce2  
    423423/* memlist: Fetching the membership list (NOT address book) */
    424424
    425 #if 0
    426 struct msn_soap_oim_send_data
    427 {
    428         char *to;
    429         char *msg;
    430         int number;
    431         int need_retry;
    432 };
    433 #endif
    434 
    435425static int msn_soap_memlist_build_request( struct msn_soap_req_data *soap_req )
    436426{
     427        struct msn_data *md = soap_req->ic->proto_data;
     428       
    437429        soap_req->url = g_strdup( SOAP_MEMLIST_URL );
    438430        soap_req->action = g_strdup( SOAP_MEMLIST_ACTION );
    439         soap_req->payload = g_strdup( SOAP_MEMLIST_PAYLOAD );
     431        soap_req->payload = g_markup_printf_escaped( SOAP_MEMLIST_PAYLOAD, md->tokens[1] );
    440432       
    441433        return 1;
    442434}
    443435
     436static xt_status msn_soap_memlist_member( struct xt_node *node, gpointer data )
     437{
     438        bee_user_t *bu;
     439        struct msn_buddy_data *bd;
     440        struct xt_node *p;
     441        char *role = NULL, *handle = NULL;
     442        struct msn_soap_req_data *soap_req = data;
     443        struct im_connection *ic = soap_req->ic;
     444       
     445        if( ( p = node->parent ) && ( p = p->parent ) &&
     446            ( p = xt_find_node( p->children, "MemberRole" ) ) )
     447                role = p->text;
     448       
     449        if( ( p = xt_find_node( node->children, "PassportName" ) ) )
     450                handle = p->text;
     451       
     452        if( !role || !handle ||
     453            !( ( bu = bee_user_by_handle( ic->bee, ic, handle ) ) ||
     454               ( bu = bee_user_new( ic->bee, ic, handle, 0 ) ) ) )
     455                return XT_HANDLED;
     456       
     457        bd = bu->data;
     458        if( strcmp( role, "Allow" ) == 0 )
     459                bd->flags |= MSN_BUDDY_AL;
     460        else if( strcmp( role, "Block" ) == 0 )
     461                bd->flags |= MSN_BUDDY_BL;
     462        else if( strcmp( role, "Reverse" ) == 0 )
     463                bd->flags |= MSN_BUDDY_RL;
     464        else if( strcmp( role, "Pending" ) == 0 )
     465                bd->flags |= MSN_BUDDY_PL;
     466       
     467        return XT_HANDLED;
     468}
     469
    444470static const struct xt_handler_entry msn_soap_memlist_parser[] = {
     471        { "Member", "Members", msn_soap_memlist_member },
    445472        { NULL,               NULL,     NULL                        }
    446473};
     
    448475static int msn_soap_memlist_handle_response( struct msn_soap_req_data *soap_req )
    449476{
    450         return 0;
     477        msn_soap_addressbook_request( soap_req->ic );
     478       
     479        return MSN_SOAP_OK;
    451480}
    452481
     
    463492                                         msn_soap_memlist_free_data );
    464493}
     494
     495
     496/* addressbook: Fetching the membership list (NOT address book) */
     497
     498static int msn_soap_addressbook_build_request( struct msn_soap_req_data *soap_req )
     499{
     500        struct msn_data *md = soap_req->ic->proto_data;
     501       
     502        soap_req->url = g_strdup( SOAP_ADDRESSBOOK_URL );
     503        soap_req->action = g_strdup( SOAP_ADDRESSBOOK_ACTION );
     504        soap_req->payload = g_markup_printf_escaped( SOAP_ADDRESSBOOK_PAYLOAD, md->tokens[1] );
     505       
     506        return 1;
     507}
     508
     509static xt_status msn_soap_addressbook_group( struct xt_node *node, gpointer data )
     510{
     511        struct xt_node *p;
     512        char *id = NULL, *name = NULL;
     513        struct msn_soap_req_data *soap_req = data;
     514        struct im_connection *ic = soap_req->ic;
     515       
     516        if( ( p = node->parent ) &&
     517            ( p = xt_find_node( p->children, "groupId" ) ) )
     518                id = p->text;
     519       
     520        if( ( p = xt_find_node( node->children, "name" ) ) )
     521                name = p->text;
     522       
     523        printf( "%s %s\n", id, name );
     524       
     525        return XT_HANDLED;
     526}
     527
     528static xt_status msn_soap_addressbook_contact( struct xt_node *node, gpointer data )
     529{
     530        bee_user_t *bu;
     531        struct msn_buddy_data *bd;
     532        struct xt_node *p;
     533        char *id = NULL, *type = NULL, *handle = NULL, *display_name = NULL;
     534        struct msn_soap_req_data *soap_req = data;
     535        struct im_connection *ic = soap_req->ic;
     536       
     537        if( ( p = node->parent ) &&
     538            ( p = xt_find_node( p->children, "contactId" ) ) )
     539                id = p->text;
     540        if( ( p = xt_find_node( node->children, "contactType" ) ) )
     541                type = p->text;
     542        if( ( p = xt_find_node( node->children, "passportName" ) ) )
     543                handle = p->text;
     544        if( ( p = xt_find_node( node->children, "displayName" ) ) )
     545                display_name = p->text;
     546       
     547        if( type && g_strcasecmp( type, "me" ) == 0 )
     548        {
     549                set_t *set = set_find( &ic->acc->set, "display_name" );
     550                g_free( set->value );
     551                set->value = g_strdup( display_name );
     552               
     553                return XT_HANDLED;
     554        }
     555       
     556        if( !( bu = bee_user_by_handle( ic->bee, ic, handle ) ) &&
     557            !( bu = bee_user_new( ic->bee, ic, handle, 0 ) ) )
     558                return XT_HANDLED;
     559       
     560        bd = bu->data;
     561        bd->flags |= MSN_BUDDY_FL;
     562        g_free( bd->cid );
     563        bd->cid = g_strdup( id );
     564       
     565        imcb_rename_buddy( ic, handle, display_name );
     566       
     567        printf( "%s %s %s %s\n", id, type, handle, display_name );
     568       
     569        return XT_HANDLED;
     570}
     571
     572static const struct xt_handler_entry msn_soap_addressbook_parser[] = {
     573        { "contactInfo", "Contact", msn_soap_addressbook_contact },
     574        { "groupInfo", "Group", msn_soap_addressbook_group },
     575        { NULL,               NULL,     NULL                        }
     576};
     577
     578static int msn_soap_addressbook_handle_response( struct msn_soap_req_data *soap_req )
     579{
     580        return MSN_SOAP_OK;
     581}
     582
     583static int msn_soap_addressbook_free_data( struct msn_soap_req_data *soap_req )
     584{
     585        return 0;
     586}
     587
     588int msn_soap_addressbook_request( struct im_connection *ic )
     589{
     590        return msn_soap_start( ic, NULL, msn_soap_addressbook_build_request,
     591                                         msn_soap_addressbook_parser,
     592                                         msn_soap_addressbook_handle_response,
     593                                         msn_soap_addressbook_free_data );
     594}
Note: See TracChangeset for help on using the changeset viewer.