Changeset 4452e69 for protocols


Ignore:
Timestamp:
2010-08-14T13:06:11Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
5848675
Parents:
d93c0eb9
Message:

Allow changing the display_name, now permanently!

Location:
protocols
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • protocols/msn/msn.c

    rd93c0eb9 r4452e69  
    2525
    2626#include "nogaim.h"
     27#include "soap.h"
    2728#include "msn.h"
    2829
     
    3536static void msn_init( account_t *acc )
    3637{
    37         set_add( &acc->set, "display_name", NULL, set_eval_display_name, acc );
    38         set_add( &acc->set, "local_display_name", "false", set_eval_bool, acc );
     38        set_t *s;
     39       
     40        s = set_add( &acc->set, "display_name", NULL, set_eval_display_name, acc );
     41        s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY;
     42       
    3943        set_add( &acc->set, "mail_notifications", "false", set_eval_bool, acc );
    4044        set_add( &acc->set, "switchboard_keepalives", "false", set_eval_bool, acc );
     
    203207}
    204208
    205 static void msn_set_my_name( struct im_connection *ic, char *info )
    206 {
    207         msn_set_display_name( ic, info );
    208 }
    209 
    210209static void msn_get_info(struct im_connection *ic, char *who)
    211210{
     
    332331        account_t *acc = set->data;
    333332        struct im_connection *ic = acc->ic;
    334        
    335         /* Allow any name if we're offline. */
    336         if( ic == NULL )
    337                 return value;
     333        struct msn_data *md = ic->proto_data;
     334        char buf[512];
     335        char *fn;
    338336       
    339337        if( strlen( value ) > 129 )
     
    343341        }
    344342       
    345         /* Returning NULL would be better, because the server still has to
    346            confirm the name change. However, it looks a bit confusing to the
    347            user. */
    348         return msn_set_display_name( ic, value ) ? value : NULL;
     343        msn_soap_addressbook_set_display_name( ic, value );
     344
     345        fn = g_malloc( strlen( value ) * 3 + 1 );
     346        strcpy( fn, value );
     347        http_encode( fn );
     348        g_snprintf( buf, sizeof( buf ), "PRP %d MFN %s\r\n",
     349                    ++md->trId, fn );
     350        g_free( fn );
     351       
     352        /* Note: We don't actually know if the server accepted the new name,
     353           and won't give proper feedback yet if it doesn't. */
     354        return msn_write( ic, buf, strlen( buf ) ) ? value : NULL;
    349355}
    350356
     
    375381        ret->set_away = msn_set_away;
    376382        ret->get_info = msn_get_info;
    377         ret->set_my_name = msn_set_my_name;
    378383        ret->add_buddy = msn_add_buddy;
    379384        ret->remove_buddy = msn_remove_buddy;
  • protocols/msn/msn.h

    rd93c0eb9 r4452e69  
    207207char **msn_linesplit( char *line );
    208208int msn_handler( struct msn_handler_data *h );
    209 char *msn_http_encode( const char *input );
    210209void msn_msgq_purge( struct im_connection *ic, GSList **list );
    211210gboolean msn_set_display_name( struct im_connection *ic, const char *rawname );
  • protocols/msn/msn_util.c

    rd93c0eb9 r4452e69  
    6161{
    6262        struct msn_data *md = ic->proto_data;
    63         char buf[1024], *realname, groupid[8];
     63        char buf[1024], realname[strlen(realname_)*3+1], groupid[8];
    6464       
    6565        *groupid = '\0';
     
    9494                        if( l == NULL )
    9595                        {
    96                                 char *groupname = msn_http_encode( group );
     96                                char groupname[strlen(group)+1];
     97                                strcpy( groupname, group );
     98                                http_encode( groupname );
    9799                                g_snprintf( buf, sizeof( buf ), "ADG %d %s %d\r\n", ++md->trId, groupname, 0 );
    98                                 g_free( groupname );
    99100                                return msn_write( ic, buf, strlen( buf ) );
    100101                        }
     
    109110        }
    110111       
    111         realname = msn_http_encode( realname_ );
     112        strcpy( realname, realname_ );
     113        http_encode( realname );
    112114        g_snprintf( buf, sizeof( buf ), "ADD %d %s %s %s%s\r\n", ++md->trId, list, who, realname, groupid );
    113         g_free( realname );
    114115       
    115116        return msn_write( ic, buf, strlen( buf ) );
     
    380381}
    381382
    382 /* The difference between this function and the normal http_encode() function
    383    is that this one escapes every 7-bit ASCII character because this is said
    384    to avoid some lame server-side checks when setting a real-name. Also,
    385    non-ASCII characters are not escaped because MSN servers don't seem to
    386    appreciate that! */
    387 char *msn_http_encode( const char *input )
    388 {
    389         char *ret, *s;
    390         int i;
    391        
    392         ret = s = g_new0( char, strlen( input ) * 3 + 1 );
    393         for( i = 0; input[i]; i ++ )
    394                 if( input[i] & 128 )
    395                 {
    396                         *s = input[i];
    397                         s ++;
    398                 }
    399                 else
    400                 {
    401                         g_snprintf( s, 4, "%%%02X", input[i] );
    402                         s += 3;
    403                 }
    404        
    405         return ret;
    406 }
    407 
    408383void msn_msgq_purge( struct im_connection *ic, GSList **list )
    409384{
     
    444419                imcb_log( ic, "%s", ret->str );
    445420        g_string_free( ret, TRUE );
    446 }
    447 
    448 gboolean msn_set_display_name( struct im_connection *ic, const char *rawname )
    449 {
    450         char *fn = msn_http_encode( rawname );
    451         struct msn_data *md = ic->proto_data;
    452         char buf[1024];
    453        
    454         g_snprintf( buf, sizeof( buf ), "REA %d %s %s\r\n", ++md->trId, ic->acc->user, fn );
    455         g_free( fn );
    456        
    457         return msn_write( ic, buf, strlen( buf ) ) != 0;
    458421}
    459422
  • protocols/msn/ns.c

    rd93c0eb9 r4452e69  
    3535static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts );
    3636
    37 static gboolean msn_ns_got_display_name( struct im_connection *ic, char *name );
    3837static void msn_ns_send_adl( struct im_connection *ic );
    3938
     
    474473                return( 0 );
    475474        }
    476 #if 0
    477         /* Discard this one completely for now since I don't care about the ack
    478            and since MSN servers can apparently screw up the formatting. */
    479         else if( strcmp( cmd[0], "REA" ) == 0 )
    480         {
    481                 if( num_parts < 5 )
    482                 {
    483                         imcb_error( ic, "Syntax error" );
    484                         imc_logout( ic, TRUE );
    485                         return( 0 );
    486                 }
    487                
    488                 if( g_strcasecmp( cmd[3], ic->acc->user ) == 0 )
    489                 {
    490                         set_t *s;
    491                        
    492                         http_decode( cmd[4] );
    493                         strncpy( ic->displayname, cmd[4], sizeof( ic->displayname ) );
    494                         ic->displayname[sizeof(ic->displayname)-1] = 0;
    495                        
    496                         if( ( s = set_find( &ic->acc->set, "display_name" ) ) )
    497                         {
    498                                 g_free( s->value );
    499                                 s->value = g_strdup( cmd[4] );
    500                         }
    501                 }
    502                 else
    503                 {
    504                         /* This is not supposed to happen, but let's handle it anyway... */
    505                         http_decode( cmd[4] );
    506                         imcb_rename_buddy( ic, cmd[3], cmd[4] );
    507                 }
    508         }
    509 #endif
    510475        else if( strcmp( cmd[0], "IPG" ) == 0 )
    511476        {
     
    801766        xt_free_node( adl );
    802767}
    803 
    804 static gboolean msn_ns_got_display_name( struct im_connection *ic, char *name )
    805 {
    806         set_t *s;
    807        
    808         if( ( s = set_find( &ic->acc->set, "display_name" ) ) == NULL )
    809                 return FALSE; /* Shouldn't happen.. */
    810        
    811         http_decode( name );
    812        
    813         if( s->value && strcmp( s->value, name ) == 0 )
    814         {
    815                 return TRUE;
    816                 /* The names match, nothing to worry about. */
    817         }
    818         else if( s->value != NULL &&
    819                  ( strcmp( name, ic->acc->user ) == 0 ||
    820                    set_getbool( &ic->acc->set, "local_display_name" ) ) )
    821         {
    822                 /* The server thinks our display name is our e-mail address
    823                    which is probably wrong, or the user *wants* us to do this:
    824                    Always use the locally set display_name. */
    825                 return msn_set_display_name( ic, s->value );
    826         }
    827         else
    828         {
    829                 if( s->value && *s->value )
    830                         imcb_log( ic, "BitlBee thinks your display name is `%s' but "
    831                                       "the MSN server says it's `%s'. Using the MSN "
    832                                       "server's name. Set local_display_name to true "
    833                                       "to use the local name.", s->value, name );
    834                
    835                 if( g_utf8_validate( name, -1, NULL ) )
    836                 {
    837                         g_free( s->value );
    838                         s->value = g_strdup( name );
    839                 }
    840                 else
    841                 {
    842                         imcb_log( ic, "Warning: Friendly name in server response was corrupted" );
    843                 }
    844                
    845                 return TRUE;
    846         }
    847 }
  • protocols/msn/soap.c

    rd93c0eb9 r4452e69  
    609609                                         msn_soap_addressbook_free_data );
    610610}
     611
     612/* Variant: Change our display name. */
     613static int msn_soap_ab_namechange_build_request( struct msn_soap_req_data *soap_req )
     614{
     615        struct msn_data *md = soap_req->ic->proto_data;
     616       
     617        soap_req->url = g_strdup( SOAP_ADDRESSBOOK_URL );
     618        soap_req->action = g_strdup( SOAP_AB_NAMECHANGE_ACTION );
     619        soap_req->payload = g_markup_printf_escaped( SOAP_AB_NAMECHANGE_PAYLOAD,
     620                md->tokens[1], (char *) soap_req->data );
     621       
     622        return 1;
     623}
     624
     625static int msn_soap_ab_namechange_handle_response( struct msn_soap_req_data *soap_req )
     626{
     627        /* TODO: Ack the change? Not sure what the NAKs look like.. */
     628        return MSN_SOAP_OK;
     629}
     630
     631static int msn_soap_ab_namechange_free_data( struct msn_soap_req_data *soap_req )
     632{
     633        g_free( soap_req->data );
     634        return 0;
     635}
     636
     637int msn_soap_addressbook_set_display_name( struct im_connection *ic, const char *new )
     638{
     639        return msn_soap_start( ic, g_strdup( new ),
     640                               msn_soap_ab_namechange_build_request,
     641                               NULL,
     642                               msn_soap_ab_namechange_handle_response,
     643                               msn_soap_ab_namechange_free_data );
     644}
  • protocols/msn/soap.h

    rd93c0eb9 r4452e69  
    220220"</soap:Envelope>"
    221221
     222#define SOAP_AB_NAMECHANGE_ACTION "http://www.msn.com/webservices/AddressBook/ABContactUpdate"
     223
     224#define SOAP_AB_NAMECHANGE_PAYLOAD \
     225"<?xml version=\"1.0\" encoding=\"utf-8\"?>" \
     226"<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/\">" \
     227  "<soap:Header>" \
     228    "<ABApplicationHeader xmlns=\"http://www.msn.com/webservices/AddressBook\">" \
     229      "<ApplicationId>CFE80F9D-180F-4399-82AB-413F33A1FA11</ApplicationId>" \
     230      "<IsMigration>false</IsMigration>" \
     231      "<PartnerScenario>Initial</PartnerScenario>" \
     232    "</ABApplicationHeader>" \
     233    "<ABAuthHeader xmlns=\"http://www.msn.com/webservices/AddressBook\">" \
     234      "<ManagedGroupRequest>false</ManagedGroupRequest>" \
     235      "<TicketToken>%s</TicketToken>" \
     236    "</ABAuthHeader>" \
     237  "</soap:Header>" \
     238    "<soap:Body>" \
     239        "<ABContactUpdate xmlns=\"http://www.msn.com/webservices/AddressBook\">" \
     240            "<abId>00000000-0000-0000-0000-000000000000</abId>" \
     241            "<contacts>" \
     242                "<Contact xmlns=\"http://www.msn.com/webservices/AddressBook\">" \
     243                    "<contactInfo>" \
     244                        "<contactType>Me</contactType>" \
     245                        "<displayName>%s</displayName>" \
     246                    "</contactInfo>" \
     247                    "<propertiesChanged>DisplayName</propertiesChanged>" \
     248                "</Contact>" \
     249            "</contacts>" \
     250        "</ABContactUpdate>" \
     251    "</soap:Body>" \
     252"</soap:Envelope>"
     253
    222254int msn_soap_addressbook_request( struct im_connection *ic );
     255int msn_soap_addressbook_set_display_name( struct im_connection *ic, const char *new );
    223256
    224257
  • protocols/nogaim.h

    rd93c0eb9 r4452e69  
    194194           this info via imcb_log(). Implementing these are optional. */
    195195        void (* get_info)       (struct im_connection *, char *who);
     196        /* set_my_name is *DEPRECATED*, not used by the UI anymore. Use the
     197           display_name setting instead. */
    196198        void (* set_my_name)    (struct im_connection *, char *name);
    197199        void (* set_name)       (struct im_connection *, char *who, char *name);
Note: See TracChangeset for help on using the changeset viewer.