Ignore:
Timestamp:
2015-02-20T22:50:54Z (9 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
0b9daac, 3d45471, 7733b8c
Parents:
af359b4
git-author:
Indent <please@…> (19-02-15 05:47:20)
git-committer:
dequis <dx@…> (20-02-15 22:50:54)
Message:

Reindent everything to K&R style with tabs

Used uncrustify, with the configuration file in ./doc/uncrustify.cfg

Commit author set to "Indent <please@…>" so that it's easier to
skip while doing git blame.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/msn/soap.c

    raf359b4 r5ebff60  
    1   /********************************************************************\
     1/********************************************************************\
    22  * BitlBee -- An IRC to other IM-networks gateway                     *
    33  *                                                                    *
     
    4444   received and parsed. See the various examples below. */
    4545
    46 typedef enum
    47 {
     46typedef enum {
    4847        MSN_SOAP_OK,
    4948        MSN_SOAP_RETRY,
     
    5352
    5453struct msn_soap_req_data;
    55 typedef int (*msn_soap_func) ( struct msn_soap_req_data * );
    56 
    57 struct msn_soap_req_data
    58 {
     54typedef int (*msn_soap_func) (struct msn_soap_req_data *);
     55
     56struct msn_soap_req_data {
    5957        void *data;
    6058        struct im_connection *ic;
    6159        int ttl;
    6260        char *error;
    63        
     61
    6462        char *url, *action, *payload;
    6563        struct http_request *http_req;
    66        
     64
    6765        const struct xt_handler_entry *xml_parser;
    6866        msn_soap_func build_request, handle_response, free_data;
    6967};
    7068
    71 static int msn_soap_send_request( struct msn_soap_req_data *req );
    72 static void msn_soap_free( struct msn_soap_req_data *soap_req );
    73 static void msn_soap_debug_print( const char *headers, const char *payload );
    74 
    75 static int msn_soap_start( struct im_connection *ic,
    76                     void *data,
    77                     msn_soap_func build_request,
    78                     const struct xt_handler_entry *xml_parser,
    79                     msn_soap_func handle_response,
    80                     msn_soap_func free_data )
    81 {
    82         struct msn_soap_req_data *req = g_new0( struct msn_soap_req_data, 1 );
    83        
     69static int msn_soap_send_request(struct msn_soap_req_data *req);
     70static void msn_soap_free(struct msn_soap_req_data *soap_req);
     71static void msn_soap_debug_print(const char *headers, const char *payload);
     72
     73static int msn_soap_start(struct im_connection *ic,
     74                          void *data,
     75                          msn_soap_func build_request,
     76                          const struct xt_handler_entry *xml_parser,
     77                          msn_soap_func handle_response,
     78                          msn_soap_func free_data)
     79{
     80        struct msn_soap_req_data *req = g_new0(struct msn_soap_req_data, 1);
     81
    8482        req->ic = ic;
    8583        req->data = data;
     
    8987        req->free_data = free_data;
    9088        req->ttl = 3;
    91        
    92         return msn_soap_send_request( req );
    93 }
    94 
    95 static void msn_soap_handle_response( struct http_request *http_req );
    96 
    97 static int msn_soap_send_request( struct msn_soap_req_data *soap_req )
     89
     90        return msn_soap_send_request(req);
     91}
     92
     93static void msn_soap_handle_response(struct http_request *http_req);
     94
     95static int msn_soap_send_request(struct msn_soap_req_data *soap_req)
    9896{
    9997        char *http_req;
    10098        char *soap_action = NULL;
    10199        url_t url;
    102        
    103         soap_req->build_request( soap_req );
    104        
    105         if( soap_req->action )
    106                 soap_action = g_strdup_printf( "SOAPAction: \"%s\"\r\n", soap_req->action );
    107        
    108         url_set( &url, soap_req->url );
    109         http_req = g_strdup_printf( SOAP_HTTP_REQUEST, url.file, url.host,
    110                 soap_action ? soap_action : "",
    111                 strlen( soap_req->payload ), soap_req->payload );
    112        
    113         msn_soap_debug_print( http_req, soap_req->payload );
    114        
    115         soap_req->http_req = http_dorequest( url.host, url.port, url.proto == PROTO_HTTPS,
    116                 http_req, msn_soap_handle_response, soap_req );
    117        
    118         g_free( http_req );
    119         g_free( soap_action );
    120        
     100
     101        soap_req->build_request(soap_req);
     102
     103        if (soap_req->action) {
     104                soap_action = g_strdup_printf("SOAPAction: \"%s\"\r\n", soap_req->action);
     105        }
     106
     107        url_set(&url, soap_req->url);
     108        http_req = g_strdup_printf(SOAP_HTTP_REQUEST, url.file, url.host,
     109                                   soap_action ? soap_action : "",
     110                                   strlen(soap_req->payload), soap_req->payload);
     111
     112        msn_soap_debug_print(http_req, soap_req->payload);
     113
     114        soap_req->http_req = http_dorequest(url.host, url.port, url.proto == PROTO_HTTPS,
     115                                            http_req, msn_soap_handle_response, soap_req);
     116
     117        g_free(http_req);
     118        g_free(soap_action);
     119
    121120        return soap_req->http_req != NULL;
    122121}
    123122
    124 static void msn_soap_handle_response( struct http_request *http_req )
     123static void msn_soap_handle_response(struct http_request *http_req)
    125124{
    126125        struct msn_soap_req_data *soap_req = http_req->data;
    127126        int st;
    128        
    129         if( g_slist_find( msn_connections, soap_req->ic ) == NULL )
    130         {
    131                 msn_soap_free( soap_req );
     127
     128        if (g_slist_find(msn_connections, soap_req->ic) == NULL) {
     129                msn_soap_free(soap_req);
    132130                return;
    133131        }
    134        
    135         msn_soap_debug_print( http_req->reply_headers, http_req->reply_body );
    136        
    137         if( http_req->body_size > 0 )
    138         {
     132
     133        msn_soap_debug_print(http_req->reply_headers, http_req->reply_body);
     134
     135        if (http_req->body_size > 0) {
    139136                struct xt_parser *parser;
    140137                struct xt_node *err;
    141                
    142                 parser = xt_new( soap_req->xml_parser, soap_req );
    143                 xt_feed( parser, http_req->reply_body, http_req->body_size );
    144                 if( http_req->status_code == 500 &&
    145                     ( err = xt_find_path( parser->root, "soap:Body/soap:Fault/detail/errorcode" ) ) &&
    146                     err->text_len > 0 )
    147                 {
    148                         if( strcmp( err->text, "PassportAuthFail" ) == 0 )
    149                         {
    150                                 xt_free( parser );
     138
     139                parser = xt_new(soap_req->xml_parser, soap_req);
     140                xt_feed(parser, http_req->reply_body, http_req->body_size);
     141                if (http_req->status_code == 500 &&
     142                    (err = xt_find_path(parser->root, "soap:Body/soap:Fault/detail/errorcode")) &&
     143                    err->text_len > 0) {
     144                        if (strcmp(err->text, "PassportAuthFail") == 0) {
     145                                xt_free(parser);
    151146                                st = MSN_SOAP_REAUTH;
    152147                                goto fail;
     
    154149                        /* TODO: Handle/report other errors. */
    155150                }
    156                
    157                 xt_handle( parser, NULL, -1 );
    158                 xt_free( parser );
    159         }
    160        
    161         if( http_req->status_code != 200 )
    162                 soap_req->error = g_strdup( http_req->status_string );
    163        
    164         st = soap_req->handle_response( soap_req );
    165 
    166 fail:   
    167         g_free( soap_req->url );
    168         g_free( soap_req->action );
    169         g_free( soap_req->payload );
    170         g_free( soap_req->error );
     151
     152                xt_handle(parser, NULL, -1);
     153                xt_free(parser);
     154        }
     155
     156        if (http_req->status_code != 200) {
     157                soap_req->error = g_strdup(http_req->status_string);
     158        }
     159
     160        st = soap_req->handle_response(soap_req);
     161
     162fail:
     163        g_free(soap_req->url);
     164        g_free(soap_req->action);
     165        g_free(soap_req->payload);
     166        g_free(soap_req->error);
    171167        soap_req->url = soap_req->action = soap_req->payload = soap_req->error = NULL;
    172        
    173         if( st == MSN_SOAP_RETRY && --soap_req->ttl )
    174         {
    175                 msn_soap_send_request( soap_req );
    176         }
    177         else if( st == MSN_SOAP_REAUTH )
    178         {
     168
     169        if (st == MSN_SOAP_RETRY && --soap_req->ttl) {
     170                msn_soap_send_request(soap_req);
     171        } else if (st == MSN_SOAP_REAUTH) {
    179172                struct msn_data *md = soap_req->ic->proto_data;
    180                
    181                 if( !( md->flags & MSN_REAUTHING ) )
    182                 {
     173
     174                if (!(md->flags & MSN_REAUTHING)) {
    183175                        /* Nonce shouldn't actually be touched for re-auths. */
    184                         msn_soap_passport_sso_request( soap_req->ic, "blaataap" );
    185                         md->flags |= MSN_REAUTHING; 
     176                        msn_soap_passport_sso_request(soap_req->ic, "blaataap");
     177                        md->flags |= MSN_REAUTHING;
    186178                }
    187                 md->soapq = g_slist_append( md->soapq, soap_req );
    188         }
    189         else
    190         {
    191                 soap_req->free_data( soap_req );
    192                 g_free( soap_req );
    193         }
    194 }
    195 
    196 static char *msn_soap_abservice_build( const char *body_fmt, const char *scenario, const char *ticket, ... )
     179                md->soapq = g_slist_append(md->soapq, soap_req);
     180        } else {
     181                soap_req->free_data(soap_req);
     182                g_free(soap_req);
     183        }
     184}
     185
     186static char *msn_soap_abservice_build(const char *body_fmt, const char *scenario, const char *ticket, ...)
    197187{
    198188        va_list params;
    199189        char *ret, *format, *body;
    200        
    201         format = g_markup_printf_escaped( SOAP_ABSERVICE_PAYLOAD, scenario, ticket );
    202        
    203         va_start( params, ticket );
    204         body = g_strdup_vprintf( body_fmt, params );
    205         va_end( params );
    206        
    207         ret = g_strdup_printf( format, body );
    208         g_free( body );
    209         g_free( format );
    210        
     190
     191        format = g_markup_printf_escaped(SOAP_ABSERVICE_PAYLOAD, scenario, ticket);
     192
     193        va_start(params, ticket);
     194        body = g_strdup_vprintf(body_fmt, params);
     195        va_end(params);
     196
     197        ret = g_strdup_printf(format, body);
     198        g_free(body);
     199        g_free(format);
     200
    211201        return ret;
    212202}
    213203
    214 static void msn_soap_debug_print( const char *headers, const char *payload )
     204static void msn_soap_debug_print(const char *headers, const char *payload)
    215205{
    216206        char *s;
    217        
    218         if( !getenv( "BITLBEE_DEBUG" ) )
     207
     208        if (!getenv("BITLBEE_DEBUG")) {
    219209                return;
    220        
    221         if( headers )
    222         {
    223                 if( ( s = strstr( headers, "\r\n\r\n" ) ) )
    224                         write( 2, headers, s - headers + 4 );
    225                 else
    226                         write( 2, headers, strlen( headers ) );
    227         }
    228        
    229         if( payload )
    230         {
    231                 struct xt_node *xt = xt_from_string( payload, 0 );
    232                 if( xt )
    233                         xt_print( xt );
    234                 xt_free_node( xt );
    235         }
    236 }
    237 
    238 int msn_soapq_flush( struct im_connection *ic, gboolean resend )
     210        }
     211
     212        if (headers) {
     213                if ((s = strstr(headers, "\r\n\r\n"))) {
     214                        write(2, headers, s - headers + 4);
     215                } else {
     216                        write(2, headers, strlen(headers));
     217                }
     218        }
     219
     220        if (payload) {
     221                struct xt_node *xt = xt_from_string(payload, 0);
     222                if (xt) {
     223                        xt_print(xt);
     224                }
     225                xt_free_node(xt);
     226        }
     227}
     228
     229int msn_soapq_flush(struct im_connection *ic, gboolean resend)
    239230{
    240231        struct msn_data *md = ic->proto_data;
    241        
    242         while( md->soapq )
    243         {
    244                 if( resend )
    245                         msn_soap_send_request( (struct msn_soap_req_data*) md->soapq->data );
    246                 else
    247                         msn_soap_free( (struct msn_soap_req_data*) md->soapq->data );
    248                 md->soapq = g_slist_remove( md->soapq, md->soapq->data );
    249         }
    250        
    251         return MSN_SOAP_OK;
    252 }
    253 
    254 static void msn_soap_free( struct msn_soap_req_data *soap_req )
    255 {
    256         soap_req->free_data( soap_req );
    257         g_free( soap_req->url );
    258         g_free( soap_req->action );
    259         g_free( soap_req->payload );
    260         g_free( soap_req->error );
    261         g_free( soap_req );
     232
     233        while (md->soapq) {
     234                if (resend) {
     235                        msn_soap_send_request((struct msn_soap_req_data*) md->soapq->data);
     236                } else {
     237                        msn_soap_free((struct msn_soap_req_data*) md->soapq->data);
     238                }
     239                md->soapq = g_slist_remove(md->soapq, md->soapq->data);
     240        }
     241
     242        return MSN_SOAP_OK;
     243}
     244
     245static void msn_soap_free(struct msn_soap_req_data *soap_req)
     246{
     247        soap_req->free_data(soap_req);
     248        g_free(soap_req->url);
     249        g_free(soap_req->action);
     250        g_free(soap_req->payload);
     251        g_free(soap_req->error);
     252        g_free(soap_req);
    262253}
    263254
     
    265256/* passport_sso: Authentication MSNP15+ */
    266257
    267 struct msn_soap_passport_sso_data
    268 {
     258struct msn_soap_passport_sso_data {
    269259        char *nonce;
    270260        char *secret;
     
    273263};
    274264
    275 static int msn_soap_passport_sso_build_request( struct msn_soap_req_data *soap_req )
     265static int msn_soap_passport_sso_build_request(struct msn_soap_req_data *soap_req)
    276266{
    277267        struct msn_soap_passport_sso_data *sd = soap_req->data;
    278268        struct im_connection *ic = soap_req->ic;
    279269        struct msn_data *md = ic->proto_data;
    280         char pass[MAX_PASSPORT_PWLEN+1];
    281        
    282         if( sd->redirect )
    283         {
     270        char pass[MAX_PASSPORT_PWLEN + 1];
     271
     272        if (sd->redirect) {
    284273                soap_req->url = sd->redirect;
    285274                sd->redirect = NULL;
     
    289278           second, but that's better than not being able to log in at all. :-/
    290279        else if( g_str_has_suffix( ic->acc->user, "@msn.com" ) )
    291                 soap_req->url = g_strdup( SOAP_PASSPORT_SSO_URL_MSN );
     280                soap_req->url = g_strdup( SOAP_PASSPORT_SSO_URL_MSN );
    292281        */
    293         else
    294                 soap_req->url = g_strdup( SOAP_PASSPORT_SSO_URL );
    295        
    296         strncpy( pass, ic->acc->pass, MAX_PASSPORT_PWLEN );
     282        else {
     283                soap_req->url = g_strdup(SOAP_PASSPORT_SSO_URL);
     284        }
     285
     286        strncpy(pass, ic->acc->pass, MAX_PASSPORT_PWLEN);
    297287        pass[MAX_PASSPORT_PWLEN] = '\0';
    298         soap_req->payload = g_markup_printf_escaped( SOAP_PASSPORT_SSO_PAYLOAD,
    299                 ic->acc->user, pass, md->pp_policy );
    300        
    301         return MSN_SOAP_OK;
    302 }
    303 
    304 static xt_status msn_soap_passport_sso_token( struct xt_node *node, gpointer data )
     288        soap_req->payload = g_markup_printf_escaped(SOAP_PASSPORT_SSO_PAYLOAD,
     289                                                    ic->acc->user, pass, md->pp_policy);
     290
     291        return MSN_SOAP_OK;
     292}
     293
     294static xt_status msn_soap_passport_sso_token(struct xt_node *node, gpointer data)
    305295{
    306296        struct msn_soap_req_data *soap_req = data;
     
    309299        struct xt_node *p;
    310300        char *id;
    311        
    312         if( ( id = xt_find_attr( node, "Id" ) ) == NULL )
     301
     302        if ((id = xt_find_attr(node, "Id")) == NULL) {
    313303                return XT_HANDLED;
    314         id += strlen( id ) - 1;
    315         if( *id == '1' &&
    316             ( p = xt_find_path( node, "../../wst:RequestedProofToken/wst:BinarySecret" ) ) &&
    317             p->text )
    318                 sd->secret = g_strdup( p->text );
    319        
     304        }
     305        id += strlen(id) - 1;
     306        if (*id == '1' &&
     307            (p = xt_find_path(node, "../../wst:RequestedProofToken/wst:BinarySecret")) &&
     308            p->text) {
     309                sd->secret = g_strdup(p->text);
     310        }
     311
    320312        *id -= '1';
    321         if( *id >= 0 && *id < sizeof( md->tokens ) / sizeof( md->tokens[0] ) )
    322         {
    323                 g_free( md->tokens[(int)*id] );
    324                 md->tokens[(int)*id] = g_strdup( node->text );
    325         }
    326        
     313        if (*id >= 0 && *id < sizeof(md->tokens) / sizeof(md->tokens[0])) {
     314                g_free(md->tokens[(int) *id]);
     315                md->tokens[(int) *id] = g_strdup(node->text);
     316        }
     317
    327318        return XT_HANDLED;
    328319}
    329320
    330 static xt_status msn_soap_passport_failure( struct xt_node *node, gpointer data )
     321static xt_status msn_soap_passport_failure(struct xt_node *node, gpointer data)
    331322{
    332323        struct msn_soap_req_data *soap_req = data;
    333324        struct msn_soap_passport_sso_data *sd = soap_req->data;
    334         struct xt_node *code = xt_find_node( node->children, "faultcode" );
    335         struct xt_node *string = xt_find_node( node->children, "faultstring" );
     325        struct xt_node *code = xt_find_node(node->children, "faultcode");
     326        struct xt_node *string = xt_find_node(node->children, "faultstring");
    336327        struct xt_node *url;
    337        
    338         if( code == NULL || code->text_len == 0 )
    339                 sd->error = g_strdup( "Unknown error" );
    340         else if( strcmp( code->text, "psf:Redirect" ) == 0 &&
    341                  ( url = xt_find_node( node->children, "psf:redirectUrl" ) ) &&
    342                  url->text_len > 0 )
    343                 sd->redirect = g_strdup( url->text );
    344         else
    345                 sd->error = g_strdup_printf( "%s (%s)", code->text, string && string->text_len ?
    346                                              string->text : "no description available" );
    347        
     328
     329        if (code == NULL || code->text_len == 0) {
     330                sd->error = g_strdup("Unknown error");
     331        } else if (strcmp(code->text, "psf:Redirect") == 0 &&
     332                   (url = xt_find_node(node->children, "psf:redirectUrl")) &&
     333                   url->text_len > 0) {
     334                sd->redirect = g_strdup(url->text);
     335        } else {
     336                sd->error = g_strdup_printf("%s (%s)", code->text, string && string->text_len ?
     337                                            string->text : "no description available");
     338        }
     339
    348340        return XT_HANDLED;
    349341}
     
    355347};
    356348
    357 static char *msn_key_fuckery( char *key, int key_len, char *type )
    358 {
    359         unsigned char hash1[20+strlen(type)+1];
     349static char *msn_key_fuckery(char *key, int key_len, char *type)
     350{
     351        unsigned char hash1[20 + strlen(type) + 1];
    360352        unsigned char hash2[20];
    361353        char *ret;
    362        
    363         sha1_hmac( key, key_len, type, 0, hash1 );
    364         strcpy( (char*) hash1 + 20, type );
    365         sha1_hmac( key, key_len, (char*) hash1, sizeof( hash1 ) - 1, hash2 );
    366        
     354
     355        sha1_hmac(key, key_len, type, 0, hash1);
     356        strcpy((char *) hash1 + 20, type);
     357        sha1_hmac(key, key_len, (char *) hash1, sizeof(hash1) - 1, hash2);
     358
    367359        /* This is okay as hash1 is read completely before it's overwritten. */
    368         sha1_hmac( key, key_len, (char*) hash1, 20, hash1 );
    369         sha1_hmac( key, key_len, (char*) hash1, sizeof( hash1 ) - 1, hash1 );
    370        
    371         ret = g_malloc( 24 );
    372         memcpy( ret, hash2, 20 );
    373         memcpy( ret + 20, hash1, 4 );
     360        sha1_hmac(key, key_len, (char *) hash1, 20, hash1);
     361        sha1_hmac(key, key_len, (char *) hash1, sizeof(hash1) - 1, hash1);
     362
     363        ret = g_malloc(24);
     364        memcpy(ret, hash2, 20);
     365        memcpy(ret + 20, hash1, 4);
    374366        return ret;
    375367}
    376368
    377 static int msn_soap_passport_sso_handle_response( struct msn_soap_req_data *soap_req )
     369static int msn_soap_passport_sso_handle_response(struct msn_soap_req_data *soap_req)
    378370{
    379371        struct msn_soap_passport_sso_data *sd = soap_req->data;
     
    383375        int key1_len;
    384376        unsigned char *padnonce, *des3res;
    385         struct
    386         {
     377
     378        struct {
    387379                unsigned int uStructHeaderSize; // 28. Does not count data
    388380                unsigned int uCryptMode; // CRYPT_MODE_CBC (1)
     
    396388                unsigned char cipherbytes[72];
    397389        } blurb = {
    398                 GUINT32_TO_LE( 28 ),
    399                 GUINT32_TO_LE( 1 ),
    400                 GUINT32_TO_LE( 0x6603 ),
    401                 GUINT32_TO_LE( 0x8004 ),
    402                 GUINT32_TO_LE( 8 ),
    403                 GUINT32_TO_LE( 20 ),
    404                 GUINT32_TO_LE( 72 ),
     390                GUINT32_TO_LE(28),
     391                GUINT32_TO_LE(1),
     392                GUINT32_TO_LE(0x6603),
     393                GUINT32_TO_LE(0x8004),
     394                GUINT32_TO_LE(8),
     395                GUINT32_TO_LE(20),
     396                GUINT32_TO_LE(72),
    405397        };
    406        
    407         if( sd->redirect )
     398
     399        if (sd->redirect) {
    408400                return MSN_SOAP_RETRY;
    409        
    410         if( md->soapq )
    411         {
    412                 md->flags &= ~MSN_REAUTHING;
    413                 return msn_soapq_flush( ic, TRUE );
    414         }
    415        
    416         if( sd->secret == NULL )
    417         {
    418                 msn_auth_got_passport_token( ic, NULL, sd->error ? sd->error : soap_req->error );
     401        }
     402
     403        if (md->soapq) {
     404                md->flags &= ~MSN_REAUTHING;
     405                return msn_soapq_flush(ic, TRUE);
     406        }
     407
     408        if (sd->secret == NULL) {
     409                msn_auth_got_passport_token(ic, NULL, sd->error ? sd->error : soap_req->error);
    419410                return MSN_SOAP_OK;
    420411        }
    421412
    422         key1_len = base64_decode( sd->secret, (unsigned char**) &key1 );
    423        
    424         key2 = msn_key_fuckery( key1, key1_len, "WS-SecureConversationSESSION KEY HASH" );
    425         key3 = msn_key_fuckery( key1, key1_len, "WS-SecureConversationSESSION KEY ENCRYPTION" );
    426        
    427         sha1_hmac( key2, 24, sd->nonce, 0, blurb.hash );
    428         padnonce = g_malloc( strlen( sd->nonce ) + 8 );
    429         strcpy( (char*) padnonce, sd->nonce );
    430         memset( padnonce + strlen( sd->nonce ), 8, 8 );
    431        
    432         random_bytes( blurb.iv, 8 );
    433        
    434         ssl_des3_encrypt( (unsigned char*) key3, 24, padnonce, strlen( sd->nonce ) + 8, blurb.iv, &des3res );
    435         memcpy( blurb.cipherbytes, des3res, 72 );
    436        
    437         blurb64 = base64_encode( (unsigned char*) &blurb, sizeof( blurb ) );
    438         msn_auth_got_passport_token( ic, blurb64, NULL );
    439        
    440         g_free( padnonce );
    441         g_free( blurb64 );
    442         g_free( des3res );
    443         g_free( key1 );
    444         g_free( key2 );
    445         g_free( key3 );
    446        
    447         return MSN_SOAP_OK;
    448 }
    449 
    450 static int msn_soap_passport_sso_free_data( struct msn_soap_req_data *soap_req )
     413        key1_len = base64_decode(sd->secret, (unsigned char **) &key1);
     414
     415        key2 = msn_key_fuckery(key1, key1_len, "WS-SecureConversationSESSION KEY HASH");
     416        key3 = msn_key_fuckery(key1, key1_len, "WS-SecureConversationSESSION KEY ENCRYPTION");
     417
     418        sha1_hmac(key2, 24, sd->nonce, 0, blurb.hash);
     419        padnonce = g_malloc(strlen(sd->nonce) + 8);
     420        strcpy((char *) padnonce, sd->nonce);
     421        memset(padnonce + strlen(sd->nonce), 8, 8);
     422
     423        random_bytes(blurb.iv, 8);
     424
     425        ssl_des3_encrypt((unsigned char *) key3, 24, padnonce, strlen(sd->nonce) + 8, blurb.iv, &des3res);
     426        memcpy(blurb.cipherbytes, des3res, 72);
     427
     428        blurb64 = base64_encode((unsigned char *) &blurb, sizeof(blurb));
     429        msn_auth_got_passport_token(ic, blurb64, NULL);
     430
     431        g_free(padnonce);
     432        g_free(blurb64);
     433        g_free(des3res);
     434        g_free(key1);
     435        g_free(key2);
     436        g_free(key3);
     437
     438        return MSN_SOAP_OK;
     439}
     440
     441static int msn_soap_passport_sso_free_data(struct msn_soap_req_data *soap_req)
    451442{
    452443        struct msn_soap_passport_sso_data *sd = soap_req->data;
    453        
    454         g_free( sd->nonce );
    455         g_free( sd->secret );
    456         g_free( sd->error );
    457         g_free( sd->redirect );
    458         g_free( sd );
    459        
    460         return MSN_SOAP_OK;
    461 }
    462 
    463 int msn_soap_passport_sso_request( struct im_connection *ic, const char *nonce )
    464 {
    465         struct msn_soap_passport_sso_data *sd = g_new0( struct msn_soap_passport_sso_data, 1 );
    466        
    467         sd->nonce = g_strdup( nonce );
    468        
    469         return msn_soap_start( ic, sd, msn_soap_passport_sso_build_request,
    470                                        msn_soap_passport_sso_parser,
    471                                        msn_soap_passport_sso_handle_response,
    472                                        msn_soap_passport_sso_free_data );
     444
     445        g_free(sd->nonce);
     446        g_free(sd->secret);
     447        g_free(sd->error);
     448        g_free(sd->redirect);
     449        g_free(sd);
     450
     451        return MSN_SOAP_OK;
     452}
     453
     454int msn_soap_passport_sso_request(struct im_connection *ic, const char *nonce)
     455{
     456        struct msn_soap_passport_sso_data *sd = g_new0(struct msn_soap_passport_sso_data, 1);
     457
     458        sd->nonce = g_strdup(nonce);
     459
     460        return msn_soap_start(ic, sd, msn_soap_passport_sso_build_request,
     461                              msn_soap_passport_sso_parser,
     462                              msn_soap_passport_sso_handle_response,
     463                              msn_soap_passport_sso_free_data);
    473464}
    474465
     
    476467/* memlist: Fetching the membership list (NOT address book) */
    477468
    478 static int msn_soap_memlist_build_request( struct msn_soap_req_data *soap_req )
    479 {
    480         struct msn_data *md = soap_req->ic->proto_data;
    481        
    482         soap_req->url = g_strdup( SOAP_MEMLIST_URL );
    483         soap_req->action = g_strdup( SOAP_MEMLIST_ACTION );
    484         soap_req->payload = msn_soap_abservice_build( SOAP_MEMLIST_PAYLOAD, "Initial", md->tokens[1] );
    485        
     469static int msn_soap_memlist_build_request(struct msn_soap_req_data *soap_req)
     470{
     471        struct msn_data *md = soap_req->ic->proto_data;
     472
     473        soap_req->url = g_strdup(SOAP_MEMLIST_URL);
     474        soap_req->action = g_strdup(SOAP_MEMLIST_ACTION);
     475        soap_req->payload = msn_soap_abservice_build(SOAP_MEMLIST_PAYLOAD, "Initial", md->tokens[1]);
     476
    486477        return 1;
    487478}
    488479
    489 static xt_status msn_soap_memlist_member( struct xt_node *node, gpointer data )
     480static xt_status msn_soap_memlist_member(struct xt_node *node, gpointer data)
    490481{
    491482        bee_user_t *bu;
     
    495486        struct msn_soap_req_data *soap_req = data;
    496487        struct im_connection *ic = soap_req->ic;
    497        
    498         if( ( p = xt_find_path( node, "../../MemberRole" ) ) )
     488
     489        if ((p = xt_find_path(node, "../../MemberRole"))) {
    499490                role = p->text;
    500        
    501         if( ( p = xt_find_node( node->children, "PassportName" ) ) )
     491        }
     492
     493        if ((p = xt_find_node(node->children, "PassportName"))) {
    502494                handle = p->text;
    503        
    504         if( !role || !handle ||
    505             !( ( bu = bee_user_by_handle( ic->bee, ic, handle ) ) ||
    506                ( bu = bee_user_new( ic->bee, ic, handle, 0 ) ) ) )
     495        }
     496
     497        if (!role || !handle ||
     498            !((bu = bee_user_by_handle(ic->bee, ic, handle)) ||
     499              (bu = bee_user_new(ic->bee, ic, handle, 0)))) {
    507500                return XT_HANDLED;
    508        
     501        }
     502
    509503        bd = bu->data;
    510         if( strcmp( role, "Allow" ) == 0 )
    511         {
     504        if (strcmp(role, "Allow") == 0) {
    512505                bd->flags |= MSN_BUDDY_AL;
    513                 ic->permit = g_slist_prepend( ic->permit, g_strdup( handle ) );
    514         }
    515         else if( strcmp( role, "Block" ) == 0 )
    516         {
     506                ic->permit = g_slist_prepend(ic->permit, g_strdup(handle));
     507        } else if (strcmp(role, "Block") == 0) {
    517508                bd->flags |= MSN_BUDDY_BL;
    518                 ic->deny = g_slist_prepend( ic->deny, g_strdup( handle ) );
    519         }
    520         else if( strcmp( role, "Reverse" ) == 0 )
     509                ic->deny = g_slist_prepend(ic->deny, g_strdup(handle));
     510        } else if (strcmp(role, "Reverse") == 0) {
    521511                bd->flags |= MSN_BUDDY_RL;
    522         else if( strcmp( role, "Pending" ) == 0 )
     512        } else if (strcmp(role, "Pending") == 0) {
    523513                bd->flags |= MSN_BUDDY_PL;
    524        
    525         if( getenv( "BITLBEE_DEBUG" ) )
    526                 fprintf( stderr, "%p %s %d\n", bu, handle, bd->flags );
    527        
     514        }
     515
     516        if (getenv("BITLBEE_DEBUG")) {
     517                fprintf(stderr, "%p %s %d\n", bu, handle, bd->flags);
     518        }
     519
    528520        return XT_HANDLED;
    529521}
     
    534526};
    535527
    536 static int msn_soap_memlist_handle_response( struct msn_soap_req_data *soap_req )
    537 {
    538         msn_soap_addressbook_request( soap_req->ic );
    539        
    540         return MSN_SOAP_OK;
    541 }
    542 
    543 static int msn_soap_memlist_free_data( struct msn_soap_req_data *soap_req )
     528static int msn_soap_memlist_handle_response(struct msn_soap_req_data *soap_req)
     529{
     530        msn_soap_addressbook_request(soap_req->ic);
     531
     532        return MSN_SOAP_OK;
     533}
     534
     535static int msn_soap_memlist_free_data(struct msn_soap_req_data *soap_req)
    544536{
    545537        return 0;
    546538}
    547539
    548 int msn_soap_memlist_request( struct im_connection *ic )
    549 {
    550         return msn_soap_start( ic, NULL, msn_soap_memlist_build_request,
    551                                          msn_soap_memlist_parser,
    552                                          msn_soap_memlist_handle_response,
    553                                          msn_soap_memlist_free_data );
     540int msn_soap_memlist_request(struct im_connection *ic)
     541{
     542        return msn_soap_start(ic, NULL, msn_soap_memlist_build_request,
     543                              msn_soap_memlist_parser,
     544                              msn_soap_memlist_handle_response,
     545                              msn_soap_memlist_free_data);
    554546}
    555547
    556548/* Variant: Adding/Removing people */
    557 struct msn_soap_memlist_edit_data
    558 {
     549struct msn_soap_memlist_edit_data {
    559550        char *handle;
    560551        gboolean add;
     
    562553};
    563554
    564 static int msn_soap_memlist_edit_build_request( struct msn_soap_req_data *soap_req )
     555static int msn_soap_memlist_edit_build_request(struct msn_soap_req_data *soap_req)
    565556{
    566557        struct msn_data *md = soap_req->ic->proto_data;
    567558        struct msn_soap_memlist_edit_data *med = soap_req->data;
    568559        char *add, *scenario, *list;
    569        
    570         soap_req->url = g_strdup( SOAP_MEMLIST_URL );
    571         if( med->add )
    572         {
    573                 soap_req->action = g_strdup( SOAP_MEMLIST_ADD_ACTION );
     560
     561        soap_req->url = g_strdup(SOAP_MEMLIST_URL);
     562        if (med->add) {
     563                soap_req->action = g_strdup(SOAP_MEMLIST_ADD_ACTION);
    574564                add = "Add";
    575         }
    576         else
    577         {
    578                 soap_req->action = g_strdup( SOAP_MEMLIST_DEL_ACTION );
     565        } else {
     566                soap_req->action = g_strdup(SOAP_MEMLIST_DEL_ACTION);
    579567                add = "Delete";
    580568        }
    581         switch( med->list )
    582         {
     569        switch (med->list) {
    583570        case MSN_BUDDY_AL:
    584571                scenario = "BlockUnblock";
     
    599586                break;
    600587        }
    601         soap_req->payload = msn_soap_abservice_build( SOAP_MEMLIST_EDIT_PAYLOAD,
    602                 scenario, md->tokens[1], add, list, med->handle, add );
    603        
     588        soap_req->payload = msn_soap_abservice_build(SOAP_MEMLIST_EDIT_PAYLOAD,
     589                                                     scenario, md->tokens[1], add, list, med->handle, add);
     590
    604591        return 1;
    605592}
    606593
    607 static int msn_soap_memlist_edit_handle_response( struct msn_soap_req_data *soap_req )
    608 {
    609         return MSN_SOAP_OK;
    610 }
    611 
    612 static int msn_soap_memlist_edit_free_data( struct msn_soap_req_data *soap_req )
     594static int msn_soap_memlist_edit_handle_response(struct msn_soap_req_data *soap_req)
     595{
     596        return MSN_SOAP_OK;
     597}
     598
     599static int msn_soap_memlist_edit_free_data(struct msn_soap_req_data *soap_req)
    613600{
    614601        struct msn_soap_memlist_edit_data *med = soap_req->data;
    615        
    616         g_free( med->handle );
    617         g_free( med );
    618        
     602
     603        g_free(med->handle);
     604        g_free(med);
     605
    619606        return 0;
    620607}
    621608
    622 int msn_soap_memlist_edit( struct im_connection *ic, const char *handle, gboolean add, int list )
     609int msn_soap_memlist_edit(struct im_connection *ic, const char *handle, gboolean add, int list)
    623610{
    624611        struct msn_soap_memlist_edit_data *med;
    625        
    626         med = g_new0( struct msn_soap_memlist_edit_data, 1 );
    627         med->handle = g_strdup( handle );
     612
     613        med = g_new0(struct msn_soap_memlist_edit_data, 1);
     614        med->handle = g_strdup(handle);
    628615        med->add = add;
    629616        med->list = list;
    630        
    631         return msn_soap_start( ic, med, msn_soap_memlist_edit_build_request,
    632                                         NULL,
    633                                         msn_soap_memlist_edit_handle_response,
    634                                         msn_soap_memlist_edit_free_data );
     617
     618        return msn_soap_start(ic, med, msn_soap_memlist_edit_build_request,
     619                              NULL,
     620                              msn_soap_memlist_edit_handle_response,
     621                              msn_soap_memlist_edit_free_data);
    635622}
    636623
     
    638625/* addressbook: Fetching the membership list (NOT address book) */
    639626
    640 static int msn_soap_addressbook_build_request( struct msn_soap_req_data *soap_req )
    641 {
    642         struct msn_data *md = soap_req->ic->proto_data;
    643        
    644         soap_req->url = g_strdup( SOAP_ADDRESSBOOK_URL );
    645         soap_req->action = g_strdup( SOAP_ADDRESSBOOK_ACTION );
    646         soap_req->payload = msn_soap_abservice_build( SOAP_ADDRESSBOOK_PAYLOAD, "Initial", md->tokens[1] );
    647        
     627static int msn_soap_addressbook_build_request(struct msn_soap_req_data *soap_req)
     628{
     629        struct msn_data *md = soap_req->ic->proto_data;
     630
     631        soap_req->url = g_strdup(SOAP_ADDRESSBOOK_URL);
     632        soap_req->action = g_strdup(SOAP_ADDRESSBOOK_ACTION);
     633        soap_req->payload = msn_soap_abservice_build(SOAP_ADDRESSBOOK_PAYLOAD, "Initial", md->tokens[1]);
     634
    648635        return 1;
    649636}
    650637
    651 static xt_status msn_soap_addressbook_group( struct xt_node *node, gpointer data )
     638static xt_status msn_soap_addressbook_group(struct xt_node *node, gpointer data)
    652639{
    653640        struct xt_node *p;
     
    655642        struct msn_soap_req_data *soap_req = data;
    656643        struct msn_data *md = soap_req->ic->proto_data;
    657        
    658         if( ( p = xt_find_path( node, "../groupId" ) ) )
     644
     645        if ((p = xt_find_path(node, "../groupId"))) {
    659646                id = p->text;
    660        
    661         if( ( p = xt_find_node( node->children, "name" ) ) )
     647        }
     648
     649        if ((p = xt_find_node(node->children, "name"))) {
    662650                name = p->text;
    663        
    664         if( id && name )
    665         {
    666                 struct msn_group *mg = g_new0( struct msn_group, 1 );
    667                 mg->id = g_strdup( id );
    668                 mg->name = g_strdup( name );
    669                 md->groups = g_slist_prepend( md->groups, mg );
    670         }
    671        
    672         if( getenv( "BITLBEE_DEBUG" ) )
    673                 fprintf( stderr, "%s %s\n", id, name );
    674        
     651        }
     652
     653        if (id && name) {
     654                struct msn_group *mg = g_new0(struct msn_group, 1);
     655                mg->id = g_strdup(id);
     656                mg->name = g_strdup(name);
     657                md->groups = g_slist_prepend(md->groups, mg);
     658        }
     659
     660        if (getenv("BITLBEE_DEBUG")) {
     661                fprintf(stderr, "%s %s\n", id, name);
     662        }
     663
    675664        return XT_HANDLED;
    676665}
    677666
    678 static xt_status msn_soap_addressbook_contact( struct xt_node *node, gpointer data )
     667static xt_status msn_soap_addressbook_contact(struct xt_node *node, gpointer data)
    679668{
    680669        bee_user_t *bu;
     
    682671        struct xt_node *p;
    683672        char *id = NULL, *type = NULL, *handle = NULL, *is_msgr = "false",
    684              *display_name = NULL, *group_id = NULL;
     673        *display_name = NULL, *group_id = NULL;
    685674        struct msn_soap_req_data *soap_req = data;
    686675        struct im_connection *ic = soap_req->ic;
    687676        struct msn_group *group;
    688        
    689         if( ( p = xt_find_path( node, "../contactId" ) ) )
     677
     678        if ((p = xt_find_path(node, "../contactId"))) {
    690679                id = p->text;
    691         if( ( p = xt_find_node( node->children, "contactType" ) ) )
     680        }
     681        if ((p = xt_find_node(node->children, "contactType"))) {
    692682                type = p->text;
    693         if( ( p = xt_find_node( node->children, "passportName" ) ) )
     683        }
     684        if ((p = xt_find_node(node->children, "passportName"))) {
    694685                handle = p->text;
    695         if( ( p = xt_find_node( node->children, "displayName" ) ) )
     686        }
     687        if ((p = xt_find_node(node->children, "displayName"))) {
    696688                display_name = p->text;
    697         if( ( p = xt_find_node( node->children, "isMessengerUser" ) ) )
     689        }
     690        if ((p = xt_find_node(node->children, "isMessengerUser"))) {
    698691                is_msgr = p->text;
    699         if( ( p = xt_find_path( node, "groupIds/guid" ) ) )
     692        }
     693        if ((p = xt_find_path(node, "groupIds/guid"))) {
    700694                group_id = p->text;
    701        
    702         if( type && g_strcasecmp( type, "me" ) == 0 )
    703         {
    704                 set_t *set = set_find( &ic->acc->set, "display_name" );
    705                 g_free( set->value );
    706                 set->value = g_strdup( display_name );
    707                
     695        }
     696
     697        if (type && g_strcasecmp(type, "me") == 0) {
     698                set_t *set = set_find(&ic->acc->set, "display_name");
     699                g_free(set->value);
     700                set->value = g_strdup(display_name);
     701
    708702                /* Try to fetch the profile; if the user has one, that's where
    709703                   we can find the persistent display_name. */
    710                 if( ( p = xt_find_node( node->children, "CID" ) ) && p->text )
    711                         msn_soap_profile_get( ic, p->text );
    712                
     704                if ((p = xt_find_node(node->children, "CID")) && p->text) {
     705                        msn_soap_profile_get(ic, p->text);
     706                }
     707
    713708                return XT_HANDLED;
    714709        }
    715        
    716         if( !bool2int( is_msgr ) || handle == NULL )
     710
     711        if (!bool2int(is_msgr) || handle == NULL) {
    717712                return XT_HANDLED;
    718        
    719         if( !( bu = bee_user_by_handle( ic->bee, ic, handle ) ) &&
    720             !( bu = bee_user_new( ic->bee, ic, handle, 0 ) ) )
     713        }
     714
     715        if (!(bu = bee_user_by_handle(ic->bee, ic, handle)) &&
     716            !(bu = bee_user_new(ic->bee, ic, handle, 0))) {
    721717                return XT_HANDLED;
    722        
     718        }
     719
    723720        bd = bu->data;
    724721        bd->flags |= MSN_BUDDY_FL;
    725         g_free( bd->cid );
    726         bd->cid = g_strdup( id );
    727        
    728         imcb_rename_buddy( ic, handle, display_name );
    729        
    730         if( group_id && ( group = msn_group_by_id( ic, group_id ) ) )
    731                 imcb_add_buddy( ic, handle, group->name );
    732        
    733         if( getenv( "BITLBEE_DEBUG" ) )
    734                 fprintf( stderr, "%s %s %s %s\n", id, type, handle, display_name );
    735        
     722        g_free(bd->cid);
     723        bd->cid = g_strdup(id);
     724
     725        imcb_rename_buddy(ic, handle, display_name);
     726
     727        if (group_id && (group = msn_group_by_id(ic, group_id))) {
     728                imcb_add_buddy(ic, handle, group->name);
     729        }
     730
     731        if (getenv("BITLBEE_DEBUG")) {
     732                fprintf(stderr, "%s %s %s %s\n", id, type, handle, display_name);
     733        }
     734
    736735        return XT_HANDLED;
    737736}
     
    743742};
    744743
    745 static int msn_soap_addressbook_handle_response( struct msn_soap_req_data *soap_req )
     744static int msn_soap_addressbook_handle_response(struct msn_soap_req_data *soap_req)
    746745{
    747746        GSList *l;
    748747        int wtf = 0;
    749        
    750         for( l = soap_req->ic->bee->users; l; l = l->next )
    751         {
     748
     749        for (l = soap_req->ic->bee->users; l; l = l->next) {
    752750                struct bee_user *bu = l->data;
    753751                struct msn_buddy_data *bd = bu->data;
    754                
    755                 if( bu->ic == soap_req->ic && bd )
    756                 {
    757                         msn_buddy_ask( bu );
    758                        
    759                         if( ( bd->flags & ( MSN_BUDDY_AL | MSN_BUDDY_BL ) ) ==
    760                                           ( MSN_BUDDY_AL | MSN_BUDDY_BL ) )
    761                         {
     752
     753                if (bu->ic == soap_req->ic && bd) {
     754                        msn_buddy_ask(bu);
     755
     756                        if ((bd->flags & (MSN_BUDDY_AL | MSN_BUDDY_BL)) ==
     757                            (MSN_BUDDY_AL | MSN_BUDDY_BL)) {
    762758                                /* both allow and block, delete block, add wtf */
    763759                                bd->flags &= ~MSN_BUDDY_BL;
     
    766762
    767763
    768                         if( ( bd->flags & ( MSN_BUDDY_AL | MSN_BUDDY_BL ) ) == 0 )
    769                         {
     764                        if ((bd->flags & (MSN_BUDDY_AL | MSN_BUDDY_BL)) == 0) {
    770765                                /* neither allow or block, add allow */
    771766                                bd->flags |= MSN_BUDDY_AL;
     
    773768                }
    774769        }
    775        
    776         if( wtf )
    777                 imcb_log( soap_req->ic, "Warning: %d contacts were in both your "
    778                           "block and your allow list. Assuming they're all "
    779                           "allowed. Use the official WLM client once to fix "
    780                           "this.", wtf );
    781        
    782         msn_auth_got_contact_list( soap_req->ic );
    783        
    784         return MSN_SOAP_OK;
    785 }
    786 
    787 static int msn_soap_addressbook_free_data( struct msn_soap_req_data *soap_req )
     770
     771        if (wtf) {
     772                imcb_log(soap_req->ic, "Warning: %d contacts were in both your "
     773                         "block and your allow list. Assuming they're all "
     774                         "allowed. Use the official WLM client once to fix "
     775                         "this.", wtf);
     776        }
     777
     778        msn_auth_got_contact_list(soap_req->ic);
     779
     780        return MSN_SOAP_OK;
     781}
     782
     783static int msn_soap_addressbook_free_data(struct msn_soap_req_data *soap_req)
    788784{
    789785        return 0;
    790786}
    791787
    792 int msn_soap_addressbook_request( struct im_connection *ic )
    793 {
    794         return msn_soap_start( ic, NULL, msn_soap_addressbook_build_request,
    795                                          msn_soap_addressbook_parser,
    796                                          msn_soap_addressbook_handle_response,
    797                                          msn_soap_addressbook_free_data );
     788int msn_soap_addressbook_request(struct im_connection *ic)
     789{
     790        return msn_soap_start(ic, NULL, msn_soap_addressbook_build_request,
     791                              msn_soap_addressbook_parser,
     792                              msn_soap_addressbook_handle_response,
     793                              msn_soap_addressbook_free_data);
    798794}
    799795
    800796/* Variant: Change our display name. */
    801 static int msn_soap_ab_namechange_build_request( struct msn_soap_req_data *soap_req )
    802 {
    803         struct msn_data *md = soap_req->ic->proto_data;
    804        
    805         soap_req->url = g_strdup( SOAP_ADDRESSBOOK_URL );
    806         soap_req->action = g_strdup( SOAP_AB_NAMECHANGE_ACTION );
    807         soap_req->payload = msn_soap_abservice_build( SOAP_AB_NAMECHANGE_PAYLOAD,
    808                 "Timer", md->tokens[1], (char *) soap_req->data );
    809        
     797static int msn_soap_ab_namechange_build_request(struct msn_soap_req_data *soap_req)
     798{
     799        struct msn_data *md = soap_req->ic->proto_data;
     800
     801        soap_req->url = g_strdup(SOAP_ADDRESSBOOK_URL);
     802        soap_req->action = g_strdup(SOAP_AB_NAMECHANGE_ACTION);
     803        soap_req->payload = msn_soap_abservice_build(SOAP_AB_NAMECHANGE_PAYLOAD,
     804                                                     "Timer", md->tokens[1], (char *) soap_req->data);
     805
    810806        return 1;
    811807}
    812808
    813 static int msn_soap_ab_namechange_handle_response( struct msn_soap_req_data *soap_req )
     809static int msn_soap_ab_namechange_handle_response(struct msn_soap_req_data *soap_req)
    814810{
    815811        /* TODO: Ack the change? Not sure what the NAKs look like.. */
     
    817813}
    818814
    819 static int msn_soap_ab_namechange_free_data( struct msn_soap_req_data *soap_req )
    820 {
    821         g_free( soap_req->data );
     815static int msn_soap_ab_namechange_free_data(struct msn_soap_req_data *soap_req)
     816{
     817        g_free(soap_req->data);
    822818        return 0;
    823819}
    824820
    825 int msn_soap_addressbook_set_display_name( struct im_connection *ic, const char *new )
    826 {
    827         return msn_soap_start( ic, g_strdup( new ),
    828                                msn_soap_ab_namechange_build_request,
    829                                NULL,
    830                                msn_soap_ab_namechange_handle_response,
    831                                msn_soap_ab_namechange_free_data );
     821int msn_soap_addressbook_set_display_name(struct im_connection *ic, const char *new)
     822{
     823        return msn_soap_start(ic, g_strdup(new),
     824                              msn_soap_ab_namechange_build_request,
     825                              NULL,
     826                              msn_soap_ab_namechange_handle_response,
     827                              msn_soap_ab_namechange_free_data);
    832828}
    833829
    834830/* Add a contact. */
    835 static int msn_soap_ab_contact_add_build_request( struct msn_soap_req_data *soap_req )
     831static int msn_soap_ab_contact_add_build_request(struct msn_soap_req_data *soap_req)
    836832{
    837833        struct msn_data *md = soap_req->ic->proto_data;
    838834        bee_user_t *bu = soap_req->data;
    839        
    840         soap_req->url = g_strdup( SOAP_ADDRESSBOOK_URL );
    841         soap_req->action = g_strdup( SOAP_AB_CONTACT_ADD_ACTION );
    842         soap_req->payload = msn_soap_abservice_build( SOAP_AB_CONTACT_ADD_PAYLOAD,
    843                 "ContactSave", md->tokens[1], bu->handle, bu->fullname ? bu->fullname : bu->handle );
    844        
     835
     836        soap_req->url = g_strdup(SOAP_ADDRESSBOOK_URL);
     837        soap_req->action = g_strdup(SOAP_AB_CONTACT_ADD_ACTION);
     838        soap_req->payload = msn_soap_abservice_build(SOAP_AB_CONTACT_ADD_PAYLOAD,
     839                                                     "ContactSave", md->tokens[1], bu->handle,
     840                                                     bu->fullname ? bu->fullname : bu->handle);
     841
    845842        return 1;
    846843}
    847844
    848 static xt_status msn_soap_ab_contact_add_cid( struct xt_node *node, gpointer data )
     845static xt_status msn_soap_ab_contact_add_cid(struct xt_node *node, gpointer data)
    849846{
    850847        struct msn_soap_req_data *soap_req = data;
    851848        bee_user_t *bu = soap_req->data;
    852849        struct msn_buddy_data *bd = bu->data;
    853        
    854         g_free( bd->cid );
    855         bd->cid = g_strdup( node->text );
    856        
     850
     851        g_free(bd->cid);
     852        bd->cid = g_strdup(node->text);
     853
    857854        return XT_HANDLED;
    858855}
     
    863860};
    864861
    865 static int msn_soap_ab_contact_add_handle_response( struct msn_soap_req_data *soap_req )
     862static int msn_soap_ab_contact_add_handle_response(struct msn_soap_req_data *soap_req)
    866863{
    867864        /* TODO: Ack the change? Not sure what the NAKs look like.. */
     
    869866}
    870867
    871 static int msn_soap_ab_contact_add_free_data( struct msn_soap_req_data *soap_req )
     868static int msn_soap_ab_contact_add_free_data(struct msn_soap_req_data *soap_req)
    872869{
    873870        return 0;
    874871}
    875872
    876 int msn_soap_ab_contact_add( struct im_connection *ic, bee_user_t *bu )
    877 {
    878         return msn_soap_start( ic, bu,
    879                                msn_soap_ab_contact_add_build_request,
    880                                msn_soap_ab_contact_add_parser,
    881                                msn_soap_ab_contact_add_handle_response,
    882                                msn_soap_ab_contact_add_free_data );
     873int msn_soap_ab_contact_add(struct im_connection *ic, bee_user_t *bu)
     874{
     875        return msn_soap_start(ic, bu,
     876                              msn_soap_ab_contact_add_build_request,
     877                              msn_soap_ab_contact_add_parser,
     878                              msn_soap_ab_contact_add_handle_response,
     879                              msn_soap_ab_contact_add_free_data);
    883880}
    884881
    885882/* Remove a contact. */
    886 static int msn_soap_ab_contact_del_build_request( struct msn_soap_req_data *soap_req )
     883static int msn_soap_ab_contact_del_build_request(struct msn_soap_req_data *soap_req)
    887884{
    888885        struct msn_data *md = soap_req->ic->proto_data;
    889886        const char *cid = soap_req->data;
    890        
    891         soap_req->url = g_strdup( SOAP_ADDRESSBOOK_URL );
    892         soap_req->action = g_strdup( SOAP_AB_CONTACT_DEL_ACTION );
    893         soap_req->payload = msn_soap_abservice_build( SOAP_AB_CONTACT_DEL_PAYLOAD,
    894                 "Timer", md->tokens[1], cid );
    895        
     887
     888        soap_req->url = g_strdup(SOAP_ADDRESSBOOK_URL);
     889        soap_req->action = g_strdup(SOAP_AB_CONTACT_DEL_ACTION);
     890        soap_req->payload = msn_soap_abservice_build(SOAP_AB_CONTACT_DEL_PAYLOAD,
     891                                                     "Timer", md->tokens[1], cid);
     892
    896893        return 1;
    897894}
    898895
    899 static int msn_soap_ab_contact_del_handle_response( struct msn_soap_req_data *soap_req )
     896static int msn_soap_ab_contact_del_handle_response(struct msn_soap_req_data *soap_req)
    900897{
    901898        /* TODO: Ack the change? Not sure what the NAKs look like.. */
     
    903900}
    904901
    905 static int msn_soap_ab_contact_del_free_data( struct msn_soap_req_data *soap_req )
    906 {
    907         g_free( soap_req->data );
     902static int msn_soap_ab_contact_del_free_data(struct msn_soap_req_data *soap_req)
     903{
     904        g_free(soap_req->data);
    908905        return 0;
    909906}
    910907
    911 int msn_soap_ab_contact_del( struct im_connection *ic, bee_user_t *bu )
     908int msn_soap_ab_contact_del(struct im_connection *ic, bee_user_t *bu)
    912909{
    913910        struct msn_buddy_data *bd = bu->data;
    914        
    915         return msn_soap_start( ic, g_strdup( bd->cid ),
    916                                msn_soap_ab_contact_del_build_request,
    917                                NULL,
    918                                msn_soap_ab_contact_del_handle_response,
    919                                msn_soap_ab_contact_del_free_data );
     911
     912        return msn_soap_start(ic, g_strdup(bd->cid),
     913                              msn_soap_ab_contact_del_build_request,
     914                              NULL,
     915                              msn_soap_ab_contact_del_handle_response,
     916                              msn_soap_ab_contact_del_free_data);
    920917}
    921918
     
    923920
    924921/* Storage stuff: Fetch profile. */
    925 static int msn_soap_profile_get_build_request( struct msn_soap_req_data *soap_req )
    926 {
    927         struct msn_data *md = soap_req->ic->proto_data;
    928        
    929         soap_req->url = g_strdup( SOAP_STORAGE_URL );
    930         soap_req->action = g_strdup( SOAP_PROFILE_GET_ACTION );
    931         soap_req->payload = g_markup_printf_escaped( SOAP_PROFILE_GET_PAYLOAD,
    932                 md->tokens[3], (char*) soap_req->data );
    933        
     922static int msn_soap_profile_get_build_request(struct msn_soap_req_data *soap_req)
     923{
     924        struct msn_data *md = soap_req->ic->proto_data;
     925
     926        soap_req->url = g_strdup(SOAP_STORAGE_URL);
     927        soap_req->action = g_strdup(SOAP_PROFILE_GET_ACTION);
     928        soap_req->payload = g_markup_printf_escaped(SOAP_PROFILE_GET_PAYLOAD,
     929                                                    md->tokens[3], (char *) soap_req->data);
     930
    934931        return 1;
    935932}
    936933
    937 static xt_status msn_soap_profile_get_result( struct xt_node *node, gpointer data )
     934static xt_status msn_soap_profile_get_result(struct xt_node *node, gpointer data)
    938935{
    939936        struct msn_soap_req_data *soap_req = data;
     
    941938        struct msn_data *md = soap_req->ic->proto_data;
    942939        struct xt_node *dn;
    943        
    944         if( ( dn = xt_find_node( node->children, "DisplayName" ) ) && dn->text )
    945         {
    946                 set_t *set = set_find( &ic->acc->set, "display_name" );
    947                 g_free( set->value );
    948                 set->value = g_strdup( dn->text );
    949                
     940
     941        if ((dn = xt_find_node(node->children, "DisplayName")) && dn->text) {
     942                set_t *set = set_find(&ic->acc->set, "display_name");
     943                g_free(set->value);
     944                set->value = g_strdup(dn->text);
     945
    950946                md->flags |= MSN_GOT_PROFILE_DN;
    951947        }
    952        
     948
    953949        return XT_HANDLED;
    954950}
    955951
    956 static xt_status msn_soap_profile_get_rid( struct xt_node *node, gpointer data )
     952static xt_status msn_soap_profile_get_rid(struct xt_node *node, gpointer data)
    957953{
    958954        struct msn_soap_req_data *soap_req = data;
    959955        struct msn_data *md = soap_req->ic->proto_data;
    960        
    961         g_free( md->profile_rid );
    962         md->profile_rid = g_strdup( node->text );
    963        
     956
     957        g_free(md->profile_rid);
     958        md->profile_rid = g_strdup(node->text);
     959
    964960        return XT_HANDLED;
    965961}
     
    971967};
    972968
    973 static int msn_soap_profile_get_handle_response( struct msn_soap_req_data *soap_req )
    974 {
    975         struct msn_data *md = soap_req->ic->proto_data;
    976        
     969static int msn_soap_profile_get_handle_response(struct msn_soap_req_data *soap_req)
     970{
     971        struct msn_data *md = soap_req->ic->proto_data;
     972
    977973        md->flags |= MSN_GOT_PROFILE;
    978         msn_ns_finish_login( soap_req->ic );
    979        
    980         return MSN_SOAP_OK;
    981 }
    982 
    983 static int msn_soap_profile_get_free_data( struct msn_soap_req_data *soap_req )
    984 {
    985         g_free( soap_req->data );
     974        msn_ns_finish_login(soap_req->ic);
     975
     976        return MSN_SOAP_OK;
     977}
     978
     979static int msn_soap_profile_get_free_data(struct msn_soap_req_data *soap_req)
     980{
     981        g_free(soap_req->data);
    986982        return 0;
    987983}
    988984
    989 int msn_soap_profile_get( struct im_connection *ic, const char *cid )
    990 {
    991         return msn_soap_start( ic, g_strdup( cid ),
    992                                msn_soap_profile_get_build_request,
    993                                msn_soap_profile_get_parser,
    994                                msn_soap_profile_get_handle_response,
    995                                msn_soap_profile_get_free_data );
     985int msn_soap_profile_get(struct im_connection *ic, const char *cid)
     986{
     987        return msn_soap_start(ic, g_strdup(cid),
     988                              msn_soap_profile_get_build_request,
     989                              msn_soap_profile_get_parser,
     990                              msn_soap_profile_get_handle_response,
     991                              msn_soap_profile_get_free_data);
    996992}
    997993
    998994/* Update profile (display name). */
    999 static int msn_soap_profile_set_dn_build_request( struct msn_soap_req_data *soap_req )
    1000 {
    1001         struct msn_data *md = soap_req->ic->proto_data;
    1002        
    1003         soap_req->url = g_strdup( SOAP_STORAGE_URL );
    1004         soap_req->action = g_strdup( SOAP_PROFILE_SET_DN_ACTION );
    1005         soap_req->payload = g_markup_printf_escaped( SOAP_PROFILE_SET_DN_PAYLOAD,
    1006                 md->tokens[3], md->profile_rid, (char*) soap_req->data );
    1007        
     995static int msn_soap_profile_set_dn_build_request(struct msn_soap_req_data *soap_req)
     996{
     997        struct msn_data *md = soap_req->ic->proto_data;
     998
     999        soap_req->url = g_strdup(SOAP_STORAGE_URL);
     1000        soap_req->action = g_strdup(SOAP_PROFILE_SET_DN_ACTION);
     1001        soap_req->payload = g_markup_printf_escaped(SOAP_PROFILE_SET_DN_PAYLOAD,
     1002                                                    md->tokens[3], md->profile_rid, (char *) soap_req->data);
     1003
    10081004        return 1;
    10091005}
     
    10131009};
    10141010
    1015 static int msn_soap_profile_set_dn_handle_response( struct msn_soap_req_data *soap_req )
    1016 {
    1017         return MSN_SOAP_OK;
    1018 }
    1019 
    1020 static int msn_soap_profile_set_dn_free_data( struct msn_soap_req_data *soap_req )
    1021 {
    1022         g_free( soap_req->data );
     1011static int msn_soap_profile_set_dn_handle_response(struct msn_soap_req_data *soap_req)
     1012{
     1013        return MSN_SOAP_OK;
     1014}
     1015
     1016static int msn_soap_profile_set_dn_free_data(struct msn_soap_req_data *soap_req)
     1017{
     1018        g_free(soap_req->data);
    10231019        return 0;
    10241020}
    10251021
    1026 int msn_soap_profile_set_dn( struct im_connection *ic, const char *dn )
    1027 {
    1028         return msn_soap_start( ic, g_strdup( dn ),
    1029                                msn_soap_profile_set_dn_build_request,
    1030                                msn_soap_profile_set_dn_parser,
    1031                                msn_soap_profile_set_dn_handle_response,
    1032                                msn_soap_profile_set_dn_free_data );
    1033 }
     1022int msn_soap_profile_set_dn(struct im_connection *ic, const char *dn)
     1023{
     1024        return msn_soap_start(ic, g_strdup(dn),
     1025                              msn_soap_profile_set_dn_build_request,
     1026                              msn_soap_profile_set_dn_parser,
     1027                              msn_soap_profile_set_dn_handle_response,
     1028                              msn_soap_profile_set_dn_free_data);
     1029}
Note: See TracChangeset for help on using the changeset viewer.