[4e4af1b] | 1 | /********************************************************************\ |
---|
| 2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
| 3 | * * |
---|
| 4 | * Copyright 2002-2010 Wilmer van der Gaast and others * |
---|
| 5 | \********************************************************************/ |
---|
| 6 | |
---|
| 7 | /* MSN module - All the SOAPy XML stuff. |
---|
| 8 | Some manager at Microsoft apparently thought MSNP wasn't XMLy enough so |
---|
| 9 | someone stepped up and changed that. This is the result. Kilobytes and |
---|
| 10 | more kilobytes of XML vomit to transfer tiny bits of informaiton. */ |
---|
| 11 | |
---|
| 12 | /* |
---|
| 13 | This program is free software; you can redistribute it and/or modify |
---|
| 14 | it under the terms of the GNU General Public License as published by |
---|
| 15 | the Free Software Foundation; either version 2 of the License, or |
---|
| 16 | (at your option) any later version. |
---|
| 17 | |
---|
| 18 | This program is distributed in the hope that it will be useful, |
---|
| 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 21 | GNU General Public License for more details. |
---|
| 22 | |
---|
| 23 | You should have received a copy of the GNU General Public License with |
---|
| 24 | the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; |
---|
| 25 | if not, write to the Free Software Foundation, Inc., 59 Temple Place, |
---|
| 26 | Suite 330, Boston, MA 02111-1307 USA |
---|
| 27 | */ |
---|
[e5a8118] | 28 | |
---|
| 29 | #include "http_client.h" |
---|
| 30 | #include "soap.h" |
---|
| 31 | #include "msn.h" |
---|
| 32 | #include "bitlbee.h" |
---|
| 33 | #include "url.h" |
---|
| 34 | #include "misc.h" |
---|
[523fb23] | 35 | #include "sha1.h" |
---|
[e5a8118] | 36 | #include "base64.h" |
---|
| 37 | #include "xmltree.h" |
---|
| 38 | #include <ctype.h> |
---|
| 39 | #include <errno.h> |
---|
| 40 | |
---|
[4e4af1b] | 41 | /* This file tries to make SOAP stuff pretty simple to do by letting you just |
---|
| 42 | provide a function to build a request, a few functions to parse various |
---|
| 43 | parts of the response, and a function to run when the full response was |
---|
| 44 | received and parsed. See the various examples below. */ |
---|
| 45 | |
---|
[e5a8118] | 46 | typedef enum |
---|
| 47 | { |
---|
| 48 | MSN_SOAP_OK, |
---|
| 49 | MSN_SOAP_RETRY, |
---|
[27053b5] | 50 | MSN_SOAP_REAUTH, |
---|
[e5a8118] | 51 | MSN_SOAP_ABORT, |
---|
| 52 | } msn_soap_result_t; |
---|
| 53 | |
---|
[12767e3] | 54 | struct msn_soap_req_data; |
---|
| 55 | typedef int (*msn_soap_func) ( struct msn_soap_req_data * ); |
---|
| 56 | |
---|
[e5a8118] | 57 | struct msn_soap_req_data |
---|
| 58 | { |
---|
| 59 | void *data; |
---|
| 60 | struct im_connection *ic; |
---|
| 61 | int ttl; |
---|
| 62 | |
---|
| 63 | char *url, *action, *payload; |
---|
| 64 | struct http_request *http_req; |
---|
| 65 | |
---|
| 66 | const struct xt_handler_entry *xml_parser; |
---|
| 67 | msn_soap_func build_request, handle_response, free_data; |
---|
| 68 | }; |
---|
| 69 | |
---|
| 70 | static int msn_soap_send_request( struct msn_soap_req_data *req ); |
---|
[4e1be76] | 71 | static void msn_soap_free( struct msn_soap_req_data *soap_req ); |
---|
[f2520b5] | 72 | static void msn_soap_debug_print( const char *headers, const char *payload ); |
---|
[e5a8118] | 73 | |
---|
| 74 | static int msn_soap_start( struct im_connection *ic, |
---|
| 75 | void *data, |
---|
| 76 | msn_soap_func build_request, |
---|
| 77 | const struct xt_handler_entry *xml_parser, |
---|
| 78 | msn_soap_func handle_response, |
---|
| 79 | msn_soap_func free_data ) |
---|
| 80 | { |
---|
| 81 | struct msn_soap_req_data *req = g_new0( struct msn_soap_req_data, 1 ); |
---|
| 82 | |
---|
| 83 | req->ic = ic; |
---|
| 84 | req->data = data; |
---|
| 85 | req->xml_parser = xml_parser; |
---|
| 86 | req->build_request = build_request; |
---|
| 87 | req->handle_response = handle_response; |
---|
| 88 | req->free_data = free_data; |
---|
| 89 | req->ttl = 3; |
---|
| 90 | |
---|
| 91 | return msn_soap_send_request( req ); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | static void msn_soap_handle_response( struct http_request *http_req ); |
---|
| 95 | |
---|
| 96 | static int msn_soap_send_request( struct msn_soap_req_data *soap_req ) |
---|
| 97 | { |
---|
| 98 | char *http_req; |
---|
[523fb23] | 99 | char *soap_action = NULL; |
---|
[e5a8118] | 100 | url_t url; |
---|
| 101 | |
---|
| 102 | soap_req->build_request( soap_req ); |
---|
| 103 | |
---|
[523fb23] | 104 | if( soap_req->action ) |
---|
| 105 | soap_action = g_strdup_printf( "SOAPAction: \"%s\"\r\n", soap_req->action ); |
---|
[7db65b7] | 106 | |
---|
[e5a8118] | 107 | url_set( &url, soap_req->url ); |
---|
| 108 | http_req = g_strdup_printf( SOAP_HTTP_REQUEST, url.file, url.host, |
---|
[523fb23] | 109 | soap_action ? soap_action : "", |
---|
[7db65b7] | 110 | strlen( soap_req->payload ), soap_req->payload ); |
---|
[e5a8118] | 111 | |
---|
[f2520b5] | 112 | msn_soap_debug_print( http_req, soap_req->payload ); |
---|
| 113 | |
---|
[e5a8118] | 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 | |
---|
[ffb6dea] | 117 | g_free( http_req ); |
---|
[523fb23] | 118 | g_free( soap_action ); |
---|
[ffb6dea] | 119 | |
---|
[e5a8118] | 120 | return soap_req->http_req != NULL; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | static void msn_soap_handle_response( struct http_request *http_req ) |
---|
| 124 | { |
---|
| 125 | struct msn_soap_req_data *soap_req = http_req->data; |
---|
| 126 | int st; |
---|
| 127 | |
---|
[801b90b] | 128 | if( g_slist_find( msn_connections, soap_req->ic ) == NULL ) |
---|
| 129 | { |
---|
[4e1be76] | 130 | msn_soap_free( soap_req ); |
---|
[801b90b] | 131 | return; |
---|
| 132 | } |
---|
| 133 | |
---|
[27053b5] | 134 | msn_soap_debug_print( http_req->reply_headers, http_req->reply_body ); |
---|
| 135 | |
---|
[e5a8118] | 136 | if( http_req->body_size > 0 ) |
---|
| 137 | { |
---|
| 138 | struct xt_parser *parser; |
---|
[4aa8a04] | 139 | struct xt_node *err; |
---|
[e5a8118] | 140 | |
---|
| 141 | parser = xt_new( soap_req->xml_parser, soap_req ); |
---|
| 142 | xt_feed( parser, http_req->reply_body, http_req->body_size ); |
---|
[4aa8a04] | 143 | if( http_req->status_code == 500 && |
---|
| 144 | ( err = xt_find_path( parser->root, "soap:Body/soap:Fault/detail/errorcode" ) ) && |
---|
[27053b5] | 145 | err->text_len > 0 ) |
---|
[4aa8a04] | 146 | { |
---|
[27053b5] | 147 | if( strcmp( err->text, "PassportAuthFail" ) == 0 ) |
---|
| 148 | { |
---|
| 149 | xt_free( parser ); |
---|
| 150 | st = MSN_SOAP_REAUTH; |
---|
| 151 | goto fail; |
---|
| 152 | } |
---|
| 153 | /* TODO: Handle/report other errors. */ |
---|
[4aa8a04] | 154 | } |
---|
| 155 | |
---|
[e5a8118] | 156 | xt_handle( parser, NULL, -1 ); |
---|
| 157 | xt_free( parser ); |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | st = soap_req->handle_response( soap_req ); |
---|
[27053b5] | 161 | |
---|
| 162 | fail: |
---|
[ffb6dea] | 163 | g_free( soap_req->url ); |
---|
| 164 | g_free( soap_req->action ); |
---|
| 165 | g_free( soap_req->payload ); |
---|
| 166 | soap_req->url = soap_req->action = soap_req->payload = NULL; |
---|
| 167 | |
---|
[e5a8118] | 168 | if( st == MSN_SOAP_RETRY && --soap_req->ttl ) |
---|
[27053b5] | 169 | { |
---|
[e5a8118] | 170 | msn_soap_send_request( soap_req ); |
---|
[27053b5] | 171 | } |
---|
| 172 | else if( st == MSN_SOAP_REAUTH ) |
---|
| 173 | { |
---|
| 174 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 175 | |
---|
| 176 | if( !( md->flags & MSN_REAUTHING ) ) |
---|
| 177 | { |
---|
| 178 | /* Nonce shouldn't actually be touched for re-auths. */ |
---|
| 179 | msn_soap_passport_sso_request( soap_req->ic, "blaataap" ); |
---|
| 180 | md->flags |= MSN_REAUTHING; |
---|
| 181 | } |
---|
| 182 | md->soapq = g_slist_append( md->soapq, soap_req ); |
---|
| 183 | } |
---|
[e5a8118] | 184 | else |
---|
| 185 | { |
---|
| 186 | soap_req->free_data( soap_req ); |
---|
| 187 | g_free( soap_req ); |
---|
| 188 | } |
---|
| 189 | } |
---|
| 190 | |
---|
[6ddb223] | 191 | static char *msn_soap_abservice_build( const char *body_fmt, const char *scenario, const char *ticket, ... ) |
---|
| 192 | { |
---|
| 193 | va_list params; |
---|
| 194 | char *ret, *format, *body; |
---|
| 195 | |
---|
| 196 | format = g_markup_printf_escaped( SOAP_ABSERVICE_PAYLOAD, scenario, ticket ); |
---|
| 197 | |
---|
| 198 | va_start( params, ticket ); |
---|
| 199 | body = g_strdup_vprintf( body_fmt, params ); |
---|
| 200 | va_end( params ); |
---|
| 201 | |
---|
| 202 | ret = g_strdup_printf( format, body ); |
---|
| 203 | g_free( body ); |
---|
| 204 | g_free( format ); |
---|
| 205 | |
---|
| 206 | return ret; |
---|
| 207 | } |
---|
| 208 | |
---|
[f2520b5] | 209 | static void msn_soap_debug_print( const char *headers, const char *payload ) |
---|
| 210 | { |
---|
| 211 | char *s; |
---|
| 212 | |
---|
| 213 | if( !getenv( "BITLBEE_DEBUG" ) ) |
---|
| 214 | return; |
---|
| 215 | |
---|
| 216 | if( ( s = strstr( headers, "\r\n\r\n" ) ) ) |
---|
| 217 | write( 1, s, s - headers + 4 ); |
---|
| 218 | else |
---|
| 219 | write( 1, headers, strlen( headers ) ); |
---|
| 220 | |
---|
| 221 | #ifdef DEBUG |
---|
| 222 | { |
---|
| 223 | struct xt_node *xt = xt_from_string( payload ); |
---|
| 224 | if( xt ) |
---|
| 225 | xt_print( xt ); |
---|
| 226 | xt_free_node( xt ); |
---|
| 227 | } |
---|
| 228 | #endif |
---|
| 229 | } |
---|
| 230 | |
---|
[4e1be76] | 231 | int msn_soapq_flush( struct im_connection *ic, gboolean resend ) |
---|
[4aa8a04] | 232 | { |
---|
| 233 | struct msn_data *md = ic->proto_data; |
---|
| 234 | |
---|
| 235 | while( md->soapq ) |
---|
| 236 | { |
---|
[4e1be76] | 237 | if( resend ) |
---|
| 238 | msn_soap_send_request( (struct msn_soap_req_data*) md->soapq->data ); |
---|
| 239 | else |
---|
| 240 | msn_soap_free( (struct msn_soap_req_data*) md->soapq->data ); |
---|
[4aa8a04] | 241 | md->soapq = g_slist_remove( md->soapq, md->soapq->data ); |
---|
| 242 | } |
---|
| 243 | |
---|
| 244 | return MSN_SOAP_OK; |
---|
| 245 | } |
---|
| 246 | |
---|
[4e1be76] | 247 | static void msn_soap_free( struct msn_soap_req_data *soap_req ) |
---|
| 248 | { |
---|
| 249 | soap_req->free_data( soap_req ); |
---|
| 250 | g_free( soap_req->url ); |
---|
| 251 | g_free( soap_req->action ); |
---|
| 252 | g_free( soap_req->payload ); |
---|
| 253 | g_free( soap_req ); |
---|
| 254 | } |
---|
| 255 | |
---|
[bc090f0] | 256 | |
---|
[523fb23] | 257 | /* passport_sso: Authentication MSNP15+ */ |
---|
| 258 | |
---|
| 259 | struct msn_soap_passport_sso_data |
---|
| 260 | { |
---|
| 261 | char *nonce; |
---|
| 262 | char *secret; |
---|
[660cb00] | 263 | char *error; |
---|
[2c6b0f4] | 264 | char *redirect; |
---|
[523fb23] | 265 | }; |
---|
| 266 | |
---|
| 267 | static int msn_soap_passport_sso_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 268 | { |
---|
[2c6b0f4] | 269 | struct msn_soap_passport_sso_data *sd = soap_req->data; |
---|
[523fb23] | 270 | struct im_connection *ic = soap_req->ic; |
---|
[4aa8a04] | 271 | struct msn_data *md = ic->proto_data; |
---|
[523fb23] | 272 | |
---|
[2c6b0f4] | 273 | if( sd->redirect ) |
---|
| 274 | { |
---|
| 275 | soap_req->url = sd->redirect; |
---|
| 276 | sd->redirect = NULL; |
---|
| 277 | } |
---|
| 278 | else if( g_str_has_suffix( ic->acc->user, "@msn.com" ) ) |
---|
[73efe3a] | 279 | soap_req->url = g_strdup( SOAP_PASSPORT_SSO_URL_MSN ); |
---|
| 280 | else |
---|
| 281 | soap_req->url = g_strdup( SOAP_PASSPORT_SSO_URL ); |
---|
| 282 | |
---|
[523fb23] | 283 | soap_req->payload = g_markup_printf_escaped( SOAP_PASSPORT_SSO_PAYLOAD, |
---|
[4aa8a04] | 284 | ic->acc->user, ic->acc->pass, md->pp_policy ); |
---|
[523fb23] | 285 | |
---|
| 286 | return MSN_SOAP_OK; |
---|
| 287 | } |
---|
| 288 | |
---|
| 289 | static xt_status msn_soap_passport_sso_token( struct xt_node *node, gpointer data ) |
---|
| 290 | { |
---|
| 291 | struct msn_soap_req_data *soap_req = data; |
---|
| 292 | struct msn_soap_passport_sso_data *sd = soap_req->data; |
---|
| 293 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 294 | struct xt_node *p; |
---|
| 295 | char *id; |
---|
| 296 | |
---|
| 297 | if( ( id = xt_find_attr( node, "Id" ) ) == NULL ) |
---|
| 298 | return XT_HANDLED; |
---|
| 299 | id += strlen( id ) - 1; |
---|
| 300 | if( *id == '1' && |
---|
[d97f51b] | 301 | ( p = xt_find_path( node, "../../wst:RequestedProofToken/wst:BinarySecret" ) ) && |
---|
[523fb23] | 302 | p->text ) |
---|
| 303 | sd->secret = g_strdup( p->text ); |
---|
| 304 | |
---|
[91d6e91] | 305 | *id -= '1'; |
---|
[80175a1] | 306 | if( *id >= 0 && *id < sizeof( md->tokens ) / sizeof( md->tokens[0] ) ) |
---|
[91d6e91] | 307 | { |
---|
| 308 | g_free( md->tokens[(int)*id] ); |
---|
| 309 | md->tokens[(int)*id] = g_strdup( node->text ); |
---|
| 310 | } |
---|
[523fb23] | 311 | |
---|
| 312 | return XT_HANDLED; |
---|
| 313 | } |
---|
| 314 | |
---|
[660cb00] | 315 | static xt_status msn_soap_passport_failure( struct xt_node *node, gpointer data ) |
---|
| 316 | { |
---|
| 317 | struct msn_soap_req_data *soap_req = data; |
---|
| 318 | struct msn_soap_passport_sso_data *sd = soap_req->data; |
---|
| 319 | struct xt_node *code = xt_find_node( node->children, "faultcode" ); |
---|
| 320 | struct xt_node *string = xt_find_node( node->children, "faultstring" ); |
---|
[2c6b0f4] | 321 | struct xt_node *url; |
---|
[660cb00] | 322 | |
---|
| 323 | if( code == NULL || code->text_len == 0 ) |
---|
| 324 | sd->error = g_strdup( "Unknown error" ); |
---|
[2c6b0f4] | 325 | else if( strcmp( code->text, "psf:Redirect" ) == 0 && |
---|
| 326 | ( url = xt_find_node( node->children, "psf:redirectUrl" ) ) && |
---|
| 327 | url->text_len > 0 ) |
---|
| 328 | sd->redirect = g_strdup( url->text ); |
---|
[660cb00] | 329 | else |
---|
| 330 | sd->error = g_strdup_printf( "%s (%s)", code->text, string && string->text_len ? |
---|
| 331 | string->text : "no description available" ); |
---|
| 332 | |
---|
| 333 | return XT_HANDLED; |
---|
| 334 | } |
---|
| 335 | |
---|
[523fb23] | 336 | static const struct xt_handler_entry msn_soap_passport_sso_parser[] = { |
---|
| 337 | { "wsse:BinarySecurityToken", "wst:RequestedSecurityToken", msn_soap_passport_sso_token }, |
---|
[660cb00] | 338 | { "S:Fault", "S:Envelope", msn_soap_passport_failure }, |
---|
[523fb23] | 339 | { NULL, NULL, NULL } |
---|
| 340 | }; |
---|
| 341 | |
---|
| 342 | static char *msn_key_fuckery( char *key, int key_len, char *type ) |
---|
| 343 | { |
---|
| 344 | unsigned char hash1[20+strlen(type)+1]; |
---|
| 345 | unsigned char hash2[20]; |
---|
| 346 | char *ret; |
---|
| 347 | |
---|
| 348 | sha1_hmac( key, key_len, type, 0, hash1 ); |
---|
| 349 | strcpy( (char*) hash1 + 20, type ); |
---|
| 350 | sha1_hmac( key, key_len, (char*) hash1, sizeof( hash1 ) - 1, hash2 ); |
---|
| 351 | |
---|
| 352 | /* This is okay as hash1 is read completely before it's overwritten. */ |
---|
| 353 | sha1_hmac( key, key_len, (char*) hash1, 20, hash1 ); |
---|
| 354 | sha1_hmac( key, key_len, (char*) hash1, sizeof( hash1 ) - 1, hash1 ); |
---|
| 355 | |
---|
| 356 | ret = g_malloc( 24 ); |
---|
| 357 | memcpy( ret, hash2, 20 ); |
---|
| 358 | memcpy( ret + 20, hash1, 4 ); |
---|
| 359 | return ret; |
---|
| 360 | } |
---|
| 361 | |
---|
| 362 | static int msn_soap_passport_sso_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 363 | { |
---|
| 364 | struct msn_soap_passport_sso_data *sd = soap_req->data; |
---|
| 365 | struct im_connection *ic = soap_req->ic; |
---|
[4aa8a04] | 366 | struct msn_data *md = ic->proto_data; |
---|
[523fb23] | 367 | char *key1, *key2, *key3, *blurb64; |
---|
| 368 | int key1_len; |
---|
| 369 | unsigned char *padnonce, *des3res; |
---|
| 370 | struct |
---|
| 371 | { |
---|
| 372 | unsigned int uStructHeaderSize; // 28. Does not count data |
---|
| 373 | unsigned int uCryptMode; // CRYPT_MODE_CBC (1) |
---|
| 374 | unsigned int uCipherType; // TripleDES (0x6603) |
---|
| 375 | unsigned int uHashType; // SHA1 (0x8004) |
---|
| 376 | unsigned int uIVLen; // 8 |
---|
| 377 | unsigned int uHashLen; // 20 |
---|
| 378 | unsigned int uCipherLen; // 72 |
---|
| 379 | unsigned char iv[8]; |
---|
| 380 | unsigned char hash[20]; |
---|
| 381 | unsigned char cipherbytes[72]; |
---|
| 382 | } blurb = { |
---|
| 383 | GUINT32_TO_LE( 28 ), |
---|
| 384 | GUINT32_TO_LE( 1 ), |
---|
| 385 | GUINT32_TO_LE( 0x6603 ), |
---|
| 386 | GUINT32_TO_LE( 0x8004 ), |
---|
| 387 | GUINT32_TO_LE( 8 ), |
---|
| 388 | GUINT32_TO_LE( 20 ), |
---|
| 389 | GUINT32_TO_LE( 72 ), |
---|
| 390 | }; |
---|
[660cb00] | 391 | |
---|
[2c6b0f4] | 392 | if( sd->redirect ) |
---|
| 393 | return MSN_SOAP_RETRY; |
---|
| 394 | |
---|
[4aa8a04] | 395 | if( md->soapq ) |
---|
[4e1be76] | 396 | return msn_soapq_flush( ic, TRUE ); |
---|
[4aa8a04] | 397 | |
---|
[660cb00] | 398 | if( sd->secret == NULL ) |
---|
| 399 | { |
---|
| 400 | msn_auth_got_passport_token( ic, NULL, sd->error ); |
---|
| 401 | return MSN_SOAP_OK; |
---|
| 402 | } |
---|
[523fb23] | 403 | |
---|
| 404 | key1_len = base64_decode( sd->secret, (unsigned char**) &key1 ); |
---|
| 405 | |
---|
| 406 | key2 = msn_key_fuckery( key1, key1_len, "WS-SecureConversationSESSION KEY HASH" ); |
---|
| 407 | key3 = msn_key_fuckery( key1, key1_len, "WS-SecureConversationSESSION KEY ENCRYPTION" ); |
---|
| 408 | |
---|
| 409 | sha1_hmac( key2, 24, sd->nonce, 0, blurb.hash ); |
---|
| 410 | padnonce = g_malloc( strlen( sd->nonce ) + 8 ); |
---|
| 411 | strcpy( (char*) padnonce, sd->nonce ); |
---|
| 412 | memset( padnonce + strlen( sd->nonce ), 8, 8 ); |
---|
| 413 | |
---|
| 414 | random_bytes( blurb.iv, 8 ); |
---|
| 415 | |
---|
| 416 | ssl_des3_encrypt( (unsigned char*) key3, 24, padnonce, strlen( sd->nonce ) + 8, blurb.iv, &des3res ); |
---|
| 417 | memcpy( blurb.cipherbytes, des3res, 72 ); |
---|
| 418 | |
---|
| 419 | blurb64 = base64_encode( (unsigned char*) &blurb, sizeof( blurb ) ); |
---|
[660cb00] | 420 | msn_auth_got_passport_token( ic, blurb64, NULL ); |
---|
[523fb23] | 421 | |
---|
| 422 | g_free( padnonce ); |
---|
| 423 | g_free( blurb64 ); |
---|
| 424 | g_free( des3res ); |
---|
| 425 | g_free( key1 ); |
---|
| 426 | g_free( key2 ); |
---|
| 427 | g_free( key3 ); |
---|
| 428 | |
---|
| 429 | return MSN_SOAP_OK; |
---|
| 430 | } |
---|
| 431 | |
---|
| 432 | static int msn_soap_passport_sso_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 433 | { |
---|
| 434 | struct msn_soap_passport_sso_data *sd = soap_req->data; |
---|
| 435 | |
---|
| 436 | g_free( sd->nonce ); |
---|
| 437 | g_free( sd->secret ); |
---|
[660cb00] | 438 | g_free( sd->error ); |
---|
[2c6b0f4] | 439 | g_free( sd->redirect ); |
---|
[523fb23] | 440 | |
---|
| 441 | return MSN_SOAP_OK; |
---|
| 442 | } |
---|
| 443 | |
---|
[4aa8a04] | 444 | int msn_soap_passport_sso_request( struct im_connection *ic, const char *nonce ) |
---|
[523fb23] | 445 | { |
---|
| 446 | struct msn_soap_passport_sso_data *sd = g_new0( struct msn_soap_passport_sso_data, 1 ); |
---|
| 447 | |
---|
| 448 | sd->nonce = g_strdup( nonce ); |
---|
| 449 | |
---|
| 450 | return msn_soap_start( ic, sd, msn_soap_passport_sso_build_request, |
---|
| 451 | msn_soap_passport_sso_parser, |
---|
| 452 | msn_soap_passport_sso_handle_response, |
---|
| 453 | msn_soap_passport_sso_free_data ); |
---|
| 454 | } |
---|
| 455 | |
---|
| 456 | |
---|
[bc090f0] | 457 | /* oim_send: Sending offline messages */ |
---|
| 458 | |
---|
| 459 | struct msn_soap_oim_send_data |
---|
| 460 | { |
---|
| 461 | char *to; |
---|
| 462 | char *msg; |
---|
| 463 | int number; |
---|
[27053b5] | 464 | msn_soap_result_t need_retry; |
---|
[bc090f0] | 465 | }; |
---|
| 466 | |
---|
[e5a8118] | 467 | static int msn_soap_oim_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 468 | { |
---|
| 469 | struct msn_soap_oim_send_data *oim = soap_req->data; |
---|
| 470 | struct im_connection *ic = soap_req->ic; |
---|
| 471 | struct msn_data *md = ic->proto_data; |
---|
| 472 | char *display_name_b64; |
---|
| 473 | |
---|
[91d6e91] | 474 | display_name_b64 = tobase64( set_getstr( &ic->acc->set, "display_name" ) ); |
---|
[e5a8118] | 475 | |
---|
| 476 | soap_req->url = g_strdup( SOAP_OIM_SEND_URL ); |
---|
[7db65b7] | 477 | soap_req->action = g_strdup( SOAP_OIM_SEND_ACTION ); |
---|
[e5a8118] | 478 | soap_req->payload = g_markup_printf_escaped( SOAP_OIM_SEND_PAYLOAD, |
---|
[91d6e91] | 479 | ic->acc->user, display_name_b64, MSNP_VER, MSNP_BUILD, |
---|
| 480 | oim->to, md->tokens[2], |
---|
[5fecede] | 481 | MSNP11_PROD_ID, md->lock_key ? md->lock_key : "", |
---|
| 482 | oim->number, oim->number, oim->msg ); |
---|
[e5a8118] | 483 | |
---|
| 484 | g_free( display_name_b64 ); |
---|
[27053b5] | 485 | oim->need_retry = MSN_SOAP_OK; |
---|
[e5a8118] | 486 | |
---|
[523fb23] | 487 | return MSN_SOAP_OK; |
---|
[e5a8118] | 488 | } |
---|
| 489 | |
---|
[27053b5] | 490 | static xt_status msn_soap_oim_reauth( struct xt_node *node, gpointer data ) |
---|
[e5a8118] | 491 | { |
---|
| 492 | struct msn_soap_req_data *soap_req = data; |
---|
| 493 | struct msn_soap_oim_send_data *oim = soap_req->data; |
---|
| 494 | struct im_connection *ic = soap_req->ic; |
---|
| 495 | struct msn_data *md = ic->proto_data; |
---|
[27053b5] | 496 | struct xt_node *c; |
---|
[e5a8118] | 497 | |
---|
[27053b5] | 498 | if( ( c = xt_find_node( node->children, "LockKeyChallenge" ) ) && c->text_len > 0 ) |
---|
| 499 | { |
---|
| 500 | g_free( md->lock_key ); |
---|
| 501 | md->lock_key = msn_p11_challenge( c->text ); |
---|
| 502 | oim->need_retry = MSN_SOAP_RETRY; |
---|
| 503 | } |
---|
| 504 | if( xt_find_node( node->children, "RequiredAuthPolicy" ) ) |
---|
| 505 | { |
---|
| 506 | oim->need_retry = MSN_SOAP_REAUTH; |
---|
| 507 | } |
---|
[e5a8118] | 508 | |
---|
| 509 | return XT_HANDLED; |
---|
| 510 | } |
---|
| 511 | |
---|
| 512 | static const struct xt_handler_entry msn_soap_oim_send_parser[] = { |
---|
[27053b5] | 513 | { "detail", "soap:Fault", msn_soap_oim_reauth }, |
---|
| 514 | { NULL, NULL, NULL } |
---|
[e5a8118] | 515 | }; |
---|
| 516 | |
---|
| 517 | static int msn_soap_oim_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 518 | { |
---|
| 519 | struct msn_soap_oim_send_data *oim = soap_req->data; |
---|
| 520 | |
---|
[bc090f0] | 521 | if( soap_req->http_req->status_code == 500 && oim->need_retry && soap_req->ttl > 0 ) |
---|
[e5a8118] | 522 | { |
---|
[27053b5] | 523 | return oim->need_retry; |
---|
[e5a8118] | 524 | } |
---|
| 525 | else if( soap_req->http_req->status_code == 200 ) |
---|
[bc090f0] | 526 | { |
---|
| 527 | imcb_log( soap_req->ic, "Offline message successfully delivered to %s", oim->to ); |
---|
[e5a8118] | 528 | return MSN_SOAP_OK; |
---|
[bc090f0] | 529 | } |
---|
[e5a8118] | 530 | else |
---|
[bc090f0] | 531 | { |
---|
| 532 | imcb_log( soap_req->ic, "Failed to deliver offline message to %s:\n%s", oim->to, oim->msg ); |
---|
[e5a8118] | 533 | return MSN_SOAP_ABORT; |
---|
[bc090f0] | 534 | } |
---|
[e5a8118] | 535 | } |
---|
| 536 | |
---|
| 537 | static int msn_soap_oim_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 538 | { |
---|
| 539 | struct msn_soap_oim_send_data *oim = soap_req->data; |
---|
| 540 | |
---|
| 541 | g_free( oim->to ); |
---|
| 542 | g_free( oim->msg ); |
---|
| 543 | g_free( oim ); |
---|
| 544 | |
---|
[523fb23] | 545 | return MSN_SOAP_OK; |
---|
[e5a8118] | 546 | } |
---|
| 547 | |
---|
| 548 | int msn_soap_oim_send( struct im_connection *ic, const char *to, const char *msg ) |
---|
| 549 | { |
---|
| 550 | struct msn_soap_oim_send_data *data; |
---|
| 551 | |
---|
| 552 | data = g_new0( struct msn_soap_oim_send_data, 1 ); |
---|
| 553 | data->to = g_strdup( to ); |
---|
| 554 | data->msg = tobase64( msg ); |
---|
| 555 | data->number = 1; |
---|
| 556 | |
---|
| 557 | return msn_soap_start( ic, data, msn_soap_oim_build_request, |
---|
| 558 | msn_soap_oim_send_parser, |
---|
| 559 | msn_soap_oim_handle_response, |
---|
| 560 | msn_soap_oim_free_data ); |
---|
| 561 | } |
---|
[bc090f0] | 562 | |
---|
| 563 | int msn_soap_oim_send_queue( struct im_connection *ic, GSList **msgq ) |
---|
| 564 | { |
---|
| 565 | GSList *l; |
---|
| 566 | char *n = NULL; |
---|
| 567 | |
---|
| 568 | for( l = *msgq; l; l = l->next ) |
---|
| 569 | { |
---|
| 570 | struct msn_message *m = l->data; |
---|
| 571 | |
---|
| 572 | if( n == NULL ) |
---|
| 573 | n = m->who; |
---|
| 574 | if( strcmp( n, m->who ) == 0 ) |
---|
| 575 | msn_soap_oim_send( ic, m->who, m->text ); |
---|
| 576 | } |
---|
| 577 | |
---|
| 578 | while( *msgq != NULL ) |
---|
| 579 | { |
---|
| 580 | struct msn_message *m = (*msgq)->data; |
---|
| 581 | |
---|
| 582 | g_free( m->who ); |
---|
| 583 | g_free( m->text ); |
---|
| 584 | g_free( m ); |
---|
| 585 | |
---|
| 586 | *msgq = g_slist_remove( *msgq, m ); |
---|
| 587 | } |
---|
[523fb23] | 588 | |
---|
| 589 | return 1; |
---|
[bc090f0] | 590 | } |
---|
[7db65b7] | 591 | |
---|
| 592 | |
---|
| 593 | /* memlist: Fetching the membership list (NOT address book) */ |
---|
| 594 | |
---|
| 595 | static int msn_soap_memlist_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 596 | { |
---|
[7f34ce2] | 597 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 598 | |
---|
[7db65b7] | 599 | soap_req->url = g_strdup( SOAP_MEMLIST_URL ); |
---|
| 600 | soap_req->action = g_strdup( SOAP_MEMLIST_ACTION ); |
---|
[6ddb223] | 601 | soap_req->payload = msn_soap_abservice_build( SOAP_MEMLIST_PAYLOAD, "Initial", md->tokens[1] ); |
---|
[7db65b7] | 602 | |
---|
| 603 | return 1; |
---|
| 604 | } |
---|
| 605 | |
---|
[7f34ce2] | 606 | static xt_status msn_soap_memlist_member( struct xt_node *node, gpointer data ) |
---|
| 607 | { |
---|
| 608 | bee_user_t *bu; |
---|
| 609 | struct msn_buddy_data *bd; |
---|
| 610 | struct xt_node *p; |
---|
| 611 | char *role = NULL, *handle = NULL; |
---|
| 612 | struct msn_soap_req_data *soap_req = data; |
---|
| 613 | struct im_connection *ic = soap_req->ic; |
---|
| 614 | |
---|
[d97f51b] | 615 | if( ( p = xt_find_path( node, "../../MemberRole" ) ) ) |
---|
[7f34ce2] | 616 | role = p->text; |
---|
| 617 | |
---|
| 618 | if( ( p = xt_find_node( node->children, "PassportName" ) ) ) |
---|
| 619 | handle = p->text; |
---|
| 620 | |
---|
| 621 | if( !role || !handle || |
---|
| 622 | !( ( bu = bee_user_by_handle( ic->bee, ic, handle ) ) || |
---|
| 623 | ( bu = bee_user_new( ic->bee, ic, handle, 0 ) ) ) ) |
---|
| 624 | return XT_HANDLED; |
---|
| 625 | |
---|
| 626 | bd = bu->data; |
---|
| 627 | if( strcmp( role, "Allow" ) == 0 ) |
---|
| 628 | bd->flags |= MSN_BUDDY_AL; |
---|
| 629 | else if( strcmp( role, "Block" ) == 0 ) |
---|
| 630 | bd->flags |= MSN_BUDDY_BL; |
---|
| 631 | else if( strcmp( role, "Reverse" ) == 0 ) |
---|
| 632 | bd->flags |= MSN_BUDDY_RL; |
---|
| 633 | else if( strcmp( role, "Pending" ) == 0 ) |
---|
| 634 | bd->flags |= MSN_BUDDY_PL; |
---|
[e5854a8] | 635 | |
---|
[ed86165] | 636 | if( getenv( "BITLBEE_DEBUG" ) ) |
---|
| 637 | printf( "%p %s %d\n", bu, handle, bd->flags ); |
---|
[7f34ce2] | 638 | |
---|
| 639 | return XT_HANDLED; |
---|
| 640 | } |
---|
| 641 | |
---|
[7db65b7] | 642 | static const struct xt_handler_entry msn_soap_memlist_parser[] = { |
---|
[7f34ce2] | 643 | { "Member", "Members", msn_soap_memlist_member }, |
---|
[7db65b7] | 644 | { NULL, NULL, NULL } |
---|
| 645 | }; |
---|
| 646 | |
---|
| 647 | static int msn_soap_memlist_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 648 | { |
---|
[7f34ce2] | 649 | msn_soap_addressbook_request( soap_req->ic ); |
---|
| 650 | |
---|
| 651 | return MSN_SOAP_OK; |
---|
[7db65b7] | 652 | } |
---|
| 653 | |
---|
| 654 | static int msn_soap_memlist_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 655 | { |
---|
| 656 | return 0; |
---|
| 657 | } |
---|
| 658 | |
---|
| 659 | int msn_soap_memlist_request( struct im_connection *ic ) |
---|
| 660 | { |
---|
| 661 | return msn_soap_start( ic, NULL, msn_soap_memlist_build_request, |
---|
| 662 | msn_soap_memlist_parser, |
---|
| 663 | msn_soap_memlist_handle_response, |
---|
| 664 | msn_soap_memlist_free_data ); |
---|
| 665 | } |
---|
[7f34ce2] | 666 | |
---|
[193dc74] | 667 | /* Variant: Adding/Removing people */ |
---|
| 668 | struct msn_soap_memlist_edit_data |
---|
| 669 | { |
---|
| 670 | char *handle; |
---|
| 671 | gboolean add; |
---|
| 672 | msn_buddy_flags_t list; |
---|
| 673 | }; |
---|
| 674 | |
---|
| 675 | static int msn_soap_memlist_edit_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 676 | { |
---|
| 677 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 678 | struct msn_soap_memlist_edit_data *med = soap_req->data; |
---|
| 679 | char *add, *scenario, *list; |
---|
| 680 | |
---|
| 681 | soap_req->url = g_strdup( SOAP_MEMLIST_URL ); |
---|
| 682 | if( med->add ) |
---|
| 683 | { |
---|
| 684 | soap_req->action = g_strdup( SOAP_MEMLIST_ADD_ACTION ); |
---|
| 685 | add = "Add"; |
---|
| 686 | } |
---|
| 687 | else |
---|
| 688 | { |
---|
| 689 | soap_req->action = g_strdup( SOAP_MEMLIST_DEL_ACTION ); |
---|
| 690 | add = "Delete"; |
---|
| 691 | } |
---|
| 692 | switch( med->list ) |
---|
| 693 | { |
---|
| 694 | case MSN_BUDDY_AL: |
---|
| 695 | scenario = "BlockUnblock"; |
---|
| 696 | list = "Allow"; |
---|
| 697 | break; |
---|
| 698 | case MSN_BUDDY_BL: |
---|
| 699 | scenario = "BlockUnblock"; |
---|
| 700 | list = "Block"; |
---|
| 701 | break; |
---|
| 702 | case MSN_BUDDY_RL: |
---|
| 703 | scenario = "Timer"; |
---|
| 704 | list = "Reverse"; |
---|
| 705 | break; |
---|
| 706 | case MSN_BUDDY_PL: |
---|
| 707 | default: |
---|
| 708 | scenario = "Timer"; |
---|
| 709 | list = "Pending"; |
---|
| 710 | break; |
---|
| 711 | } |
---|
[6ddb223] | 712 | soap_req->payload = msn_soap_abservice_build( SOAP_MEMLIST_EDIT_PAYLOAD, |
---|
[193dc74] | 713 | scenario, md->tokens[1], add, list, med->handle, add ); |
---|
| 714 | |
---|
| 715 | return 1; |
---|
| 716 | } |
---|
| 717 | |
---|
| 718 | static int msn_soap_memlist_edit_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 719 | { |
---|
| 720 | return MSN_SOAP_OK; |
---|
| 721 | } |
---|
| 722 | |
---|
| 723 | static int msn_soap_memlist_edit_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 724 | { |
---|
| 725 | struct msn_soap_memlist_edit_data *med = soap_req->data; |
---|
| 726 | |
---|
| 727 | g_free( med->handle ); |
---|
| 728 | g_free( med ); |
---|
| 729 | |
---|
| 730 | return 0; |
---|
| 731 | } |
---|
| 732 | |
---|
| 733 | int msn_soap_memlist_edit( struct im_connection *ic, const char *handle, gboolean add, int list ) |
---|
| 734 | { |
---|
| 735 | struct msn_soap_memlist_edit_data *med; |
---|
| 736 | |
---|
| 737 | med = g_new0( struct msn_soap_memlist_edit_data, 1 ); |
---|
| 738 | med->handle = g_strdup( handle ); |
---|
| 739 | med->add = add; |
---|
| 740 | med->list = list; |
---|
| 741 | |
---|
| 742 | return msn_soap_start( ic, med, msn_soap_memlist_edit_build_request, |
---|
| 743 | NULL, |
---|
| 744 | msn_soap_memlist_edit_handle_response, |
---|
| 745 | msn_soap_memlist_edit_free_data ); |
---|
| 746 | } |
---|
| 747 | |
---|
[7f34ce2] | 748 | |
---|
| 749 | /* addressbook: Fetching the membership list (NOT address book) */ |
---|
| 750 | |
---|
| 751 | static int msn_soap_addressbook_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 752 | { |
---|
| 753 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 754 | |
---|
| 755 | soap_req->url = g_strdup( SOAP_ADDRESSBOOK_URL ); |
---|
| 756 | soap_req->action = g_strdup( SOAP_ADDRESSBOOK_ACTION ); |
---|
[6ddb223] | 757 | soap_req->payload = msn_soap_abservice_build( SOAP_ADDRESSBOOK_PAYLOAD, "Initial", md->tokens[1] ); |
---|
[7f34ce2] | 758 | |
---|
| 759 | return 1; |
---|
| 760 | } |
---|
| 761 | |
---|
| 762 | static xt_status msn_soap_addressbook_group( struct xt_node *node, gpointer data ) |
---|
| 763 | { |
---|
| 764 | struct xt_node *p; |
---|
| 765 | char *id = NULL, *name = NULL; |
---|
| 766 | struct msn_soap_req_data *soap_req = data; |
---|
[ff27648] | 767 | struct msn_data *md = soap_req->ic->proto_data; |
---|
[7f34ce2] | 768 | |
---|
[d97f51b] | 769 | if( ( p = xt_find_path( node, "../groupId" ) ) ) |
---|
[7f34ce2] | 770 | id = p->text; |
---|
| 771 | |
---|
| 772 | if( ( p = xt_find_node( node->children, "name" ) ) ) |
---|
| 773 | name = p->text; |
---|
| 774 | |
---|
[ff27648] | 775 | if( id && name ) |
---|
| 776 | { |
---|
| 777 | struct msn_group *mg = g_new0( struct msn_group, 1 ); |
---|
| 778 | mg->id = g_strdup( id ); |
---|
| 779 | mg->name = g_strdup( name ); |
---|
| 780 | md->groups = g_slist_prepend( md->groups, mg ); |
---|
| 781 | } |
---|
| 782 | |
---|
[ed86165] | 783 | if( getenv( "BITLBEE_DEBUG" ) ) |
---|
| 784 | printf( "%s %s\n", id, name ); |
---|
[7f34ce2] | 785 | |
---|
| 786 | return XT_HANDLED; |
---|
| 787 | } |
---|
| 788 | |
---|
| 789 | static xt_status msn_soap_addressbook_contact( struct xt_node *node, gpointer data ) |
---|
| 790 | { |
---|
| 791 | bee_user_t *bu; |
---|
| 792 | struct msn_buddy_data *bd; |
---|
| 793 | struct xt_node *p; |
---|
[9b01339] | 794 | char *id = NULL, *type = NULL, *handle = NULL, *is_msgr = "false", |
---|
[ff27648] | 795 | *display_name = NULL, *group_id = NULL; |
---|
[7f34ce2] | 796 | struct msn_soap_req_data *soap_req = data; |
---|
| 797 | struct im_connection *ic = soap_req->ic; |
---|
[ff27648] | 798 | struct msn_group *group; |
---|
[7f34ce2] | 799 | |
---|
[d97f51b] | 800 | if( ( p = xt_find_path( node, "../contactId" ) ) ) |
---|
[7f34ce2] | 801 | id = p->text; |
---|
| 802 | if( ( p = xt_find_node( node->children, "contactType" ) ) ) |
---|
| 803 | type = p->text; |
---|
| 804 | if( ( p = xt_find_node( node->children, "passportName" ) ) ) |
---|
| 805 | handle = p->text; |
---|
| 806 | if( ( p = xt_find_node( node->children, "displayName" ) ) ) |
---|
| 807 | display_name = p->text; |
---|
[9b01339] | 808 | if( ( p = xt_find_node( node->children, "isMessengerUser" ) ) ) |
---|
| 809 | is_msgr = p->text; |
---|
[ff27648] | 810 | if( ( p = xt_find_path( node, "groupIds/guid" ) ) ) |
---|
| 811 | group_id = p->text; |
---|
[7f34ce2] | 812 | |
---|
| 813 | if( type && g_strcasecmp( type, "me" ) == 0 ) |
---|
| 814 | { |
---|
| 815 | set_t *set = set_find( &ic->acc->set, "display_name" ); |
---|
| 816 | g_free( set->value ); |
---|
| 817 | set->value = g_strdup( display_name ); |
---|
| 818 | |
---|
[80175a1] | 819 | /* Try to fetch the profile; if the user has one, that's where |
---|
| 820 | we can find the persistent display_name. */ |
---|
| 821 | if( ( p = xt_find_node( node->children, "CID" ) ) && p->text ) |
---|
| 822 | msn_soap_profile_get( ic, p->text ); |
---|
| 823 | |
---|
[7f34ce2] | 824 | return XT_HANDLED; |
---|
| 825 | } |
---|
| 826 | |
---|
[9b01339] | 827 | if( !bool2int( is_msgr ) || handle == NULL ) |
---|
[d97f51b] | 828 | return XT_HANDLED; |
---|
| 829 | |
---|
[7f34ce2] | 830 | if( !( bu = bee_user_by_handle( ic->bee, ic, handle ) ) && |
---|
| 831 | !( bu = bee_user_new( ic->bee, ic, handle, 0 ) ) ) |
---|
| 832 | return XT_HANDLED; |
---|
| 833 | |
---|
| 834 | bd = bu->data; |
---|
| 835 | bd->flags |= MSN_BUDDY_FL; |
---|
| 836 | g_free( bd->cid ); |
---|
| 837 | bd->cid = g_strdup( id ); |
---|
| 838 | |
---|
| 839 | imcb_rename_buddy( ic, handle, display_name ); |
---|
| 840 | |
---|
[ff27648] | 841 | if( group_id && ( group = msn_group_by_id( ic, group_id ) ) ) |
---|
| 842 | imcb_add_buddy( ic, handle, group->name ); |
---|
| 843 | |
---|
[ed86165] | 844 | if( getenv( "BITLBEE_DEBUG" ) ) |
---|
| 845 | printf( "%s %s %s %s\n", id, type, handle, display_name ); |
---|
[7f34ce2] | 846 | |
---|
| 847 | return XT_HANDLED; |
---|
| 848 | } |
---|
| 849 | |
---|
| 850 | static const struct xt_handler_entry msn_soap_addressbook_parser[] = { |
---|
| 851 | { "contactInfo", "Contact", msn_soap_addressbook_contact }, |
---|
| 852 | { "groupInfo", "Group", msn_soap_addressbook_group }, |
---|
| 853 | { NULL, NULL, NULL } |
---|
| 854 | }; |
---|
| 855 | |
---|
| 856 | static int msn_soap_addressbook_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 857 | { |
---|
[327af51] | 858 | GSList *l; |
---|
| 859 | |
---|
| 860 | for( l = soap_req->ic->bee->users; l; l = l->next ) |
---|
| 861 | { |
---|
| 862 | struct bee_user *bu = l->data; |
---|
| 863 | |
---|
| 864 | if( bu->ic == soap_req->ic ) |
---|
| 865 | msn_buddy_ask( bu ); |
---|
| 866 | } |
---|
| 867 | |
---|
[ca7de3a] | 868 | msn_auth_got_contact_list( soap_req->ic ); |
---|
[327af51] | 869 | |
---|
[7f34ce2] | 870 | return MSN_SOAP_OK; |
---|
| 871 | } |
---|
| 872 | |
---|
| 873 | static int msn_soap_addressbook_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 874 | { |
---|
| 875 | return 0; |
---|
| 876 | } |
---|
| 877 | |
---|
| 878 | int msn_soap_addressbook_request( struct im_connection *ic ) |
---|
| 879 | { |
---|
| 880 | return msn_soap_start( ic, NULL, msn_soap_addressbook_build_request, |
---|
| 881 | msn_soap_addressbook_parser, |
---|
| 882 | msn_soap_addressbook_handle_response, |
---|
| 883 | msn_soap_addressbook_free_data ); |
---|
| 884 | } |
---|
[4452e69] | 885 | |
---|
| 886 | /* Variant: Change our display name. */ |
---|
| 887 | static int msn_soap_ab_namechange_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 888 | { |
---|
| 889 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 890 | |
---|
| 891 | soap_req->url = g_strdup( SOAP_ADDRESSBOOK_URL ); |
---|
| 892 | soap_req->action = g_strdup( SOAP_AB_NAMECHANGE_ACTION ); |
---|
[6ddb223] | 893 | soap_req->payload = msn_soap_abservice_build( SOAP_AB_NAMECHANGE_PAYLOAD, |
---|
[e0e1546] | 894 | "Timer", md->tokens[1], (char *) soap_req->data ); |
---|
[4452e69] | 895 | |
---|
| 896 | return 1; |
---|
| 897 | } |
---|
| 898 | |
---|
| 899 | static int msn_soap_ab_namechange_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 900 | { |
---|
| 901 | /* TODO: Ack the change? Not sure what the NAKs look like.. */ |
---|
| 902 | return MSN_SOAP_OK; |
---|
| 903 | } |
---|
| 904 | |
---|
| 905 | static int msn_soap_ab_namechange_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 906 | { |
---|
| 907 | g_free( soap_req->data ); |
---|
| 908 | return 0; |
---|
| 909 | } |
---|
| 910 | |
---|
| 911 | int msn_soap_addressbook_set_display_name( struct im_connection *ic, const char *new ) |
---|
| 912 | { |
---|
| 913 | return msn_soap_start( ic, g_strdup( new ), |
---|
| 914 | msn_soap_ab_namechange_build_request, |
---|
| 915 | NULL, |
---|
| 916 | msn_soap_ab_namechange_handle_response, |
---|
| 917 | msn_soap_ab_namechange_free_data ); |
---|
| 918 | } |
---|
[4fc95c5] | 919 | |
---|
| 920 | /* Add a contact. */ |
---|
| 921 | static int msn_soap_ab_contact_add_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 922 | { |
---|
| 923 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 924 | bee_user_t *bu = soap_req->data; |
---|
| 925 | |
---|
| 926 | soap_req->url = g_strdup( SOAP_ADDRESSBOOK_URL ); |
---|
| 927 | soap_req->action = g_strdup( SOAP_AB_CONTACT_ADD_ACTION ); |
---|
| 928 | soap_req->payload = msn_soap_abservice_build( SOAP_AB_CONTACT_ADD_PAYLOAD, |
---|
| 929 | "ContactSave", md->tokens[1], bu->handle, bu->fullname ? bu->fullname : bu->handle ); |
---|
| 930 | |
---|
| 931 | return 1; |
---|
| 932 | } |
---|
| 933 | |
---|
| 934 | static xt_status msn_soap_ab_contact_add_cid( struct xt_node *node, gpointer data ) |
---|
| 935 | { |
---|
| 936 | struct msn_soap_req_data *soap_req = data; |
---|
| 937 | bee_user_t *bu = soap_req->data; |
---|
| 938 | struct msn_buddy_data *bd = bu->data; |
---|
| 939 | |
---|
| 940 | g_free( bd->cid ); |
---|
| 941 | bd->cid = g_strdup( node->text ); |
---|
| 942 | |
---|
| 943 | return XT_HANDLED; |
---|
| 944 | } |
---|
| 945 | |
---|
| 946 | static const struct xt_handler_entry msn_soap_ab_contact_add_parser[] = { |
---|
| 947 | { "guid", "ABContactAddResult", msn_soap_ab_contact_add_cid }, |
---|
| 948 | { NULL, NULL, NULL } |
---|
| 949 | }; |
---|
| 950 | |
---|
| 951 | static int msn_soap_ab_contact_add_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 952 | { |
---|
| 953 | /* TODO: Ack the change? Not sure what the NAKs look like.. */ |
---|
| 954 | return MSN_SOAP_OK; |
---|
| 955 | } |
---|
| 956 | |
---|
| 957 | static int msn_soap_ab_contact_add_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 958 | { |
---|
| 959 | return 0; |
---|
| 960 | } |
---|
| 961 | |
---|
| 962 | int msn_soap_ab_contact_add( struct im_connection *ic, bee_user_t *bu ) |
---|
| 963 | { |
---|
| 964 | return msn_soap_start( ic, bu, |
---|
| 965 | msn_soap_ab_contact_add_build_request, |
---|
| 966 | msn_soap_ab_contact_add_parser, |
---|
| 967 | msn_soap_ab_contact_add_handle_response, |
---|
| 968 | msn_soap_ab_contact_add_free_data ); |
---|
| 969 | } |
---|
| 970 | |
---|
| 971 | /* Remove a contact. */ |
---|
| 972 | static int msn_soap_ab_contact_del_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 973 | { |
---|
| 974 | struct msn_data *md = soap_req->ic->proto_data; |
---|
[52f5e90] | 975 | const char *cid = soap_req->data; |
---|
[4fc95c5] | 976 | |
---|
| 977 | soap_req->url = g_strdup( SOAP_ADDRESSBOOK_URL ); |
---|
| 978 | soap_req->action = g_strdup( SOAP_AB_CONTACT_DEL_ACTION ); |
---|
| 979 | soap_req->payload = msn_soap_abservice_build( SOAP_AB_CONTACT_DEL_PAYLOAD, |
---|
[52f5e90] | 980 | "Timer", md->tokens[1], cid ); |
---|
[4fc95c5] | 981 | |
---|
| 982 | return 1; |
---|
| 983 | } |
---|
| 984 | |
---|
| 985 | static int msn_soap_ab_contact_del_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 986 | { |
---|
| 987 | /* TODO: Ack the change? Not sure what the NAKs look like.. */ |
---|
| 988 | return MSN_SOAP_OK; |
---|
| 989 | } |
---|
| 990 | |
---|
| 991 | static int msn_soap_ab_contact_del_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 992 | { |
---|
[52f5e90] | 993 | g_free( soap_req->data ); |
---|
[4fc95c5] | 994 | return 0; |
---|
| 995 | } |
---|
| 996 | |
---|
| 997 | int msn_soap_ab_contact_del( struct im_connection *ic, bee_user_t *bu ) |
---|
| 998 | { |
---|
[52f5e90] | 999 | struct msn_buddy_data *bd = bu->data; |
---|
| 1000 | |
---|
| 1001 | return msn_soap_start( ic, g_strdup( bd->cid ), |
---|
[4fc95c5] | 1002 | msn_soap_ab_contact_del_build_request, |
---|
| 1003 | NULL, |
---|
| 1004 | msn_soap_ab_contact_del_handle_response, |
---|
| 1005 | msn_soap_ab_contact_del_free_data ); |
---|
| 1006 | } |
---|
[80175a1] | 1007 | |
---|
| 1008 | |
---|
| 1009 | |
---|
| 1010 | /* Storage stuff: Fetch profile. */ |
---|
| 1011 | static int msn_soap_profile_get_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 1012 | { |
---|
| 1013 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 1014 | |
---|
| 1015 | soap_req->url = g_strdup( SOAP_STORAGE_URL ); |
---|
| 1016 | soap_req->action = g_strdup( SOAP_PROFILE_GET_ACTION ); |
---|
| 1017 | soap_req->payload = g_markup_printf_escaped( SOAP_PROFILE_GET_PAYLOAD, |
---|
| 1018 | md->tokens[3], (char*) soap_req->data ); |
---|
| 1019 | |
---|
| 1020 | return 1; |
---|
| 1021 | } |
---|
| 1022 | |
---|
| 1023 | static xt_status msn_soap_profile_get_result( struct xt_node *node, gpointer data ) |
---|
| 1024 | { |
---|
| 1025 | struct msn_soap_req_data *soap_req = data; |
---|
| 1026 | struct im_connection *ic = soap_req->ic; |
---|
| 1027 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 1028 | struct xt_node *dn; |
---|
| 1029 | |
---|
| 1030 | if( ( dn = xt_find_node( node->children, "DisplayName" ) ) && dn->text ) |
---|
| 1031 | { |
---|
| 1032 | set_t *set = set_find( &ic->acc->set, "display_name" ); |
---|
| 1033 | g_free( set->value ); |
---|
| 1034 | set->value = g_strdup( dn->text ); |
---|
| 1035 | |
---|
| 1036 | md->flags |= MSN_GOT_PROFILE_DN; |
---|
| 1037 | } |
---|
| 1038 | |
---|
| 1039 | return XT_HANDLED; |
---|
| 1040 | } |
---|
| 1041 | |
---|
| 1042 | static const struct xt_handler_entry msn_soap_profile_get_parser[] = { |
---|
| 1043 | { "ExpressionProfile", "GetProfileResult", msn_soap_profile_get_result }, |
---|
| 1044 | { NULL, NULL, NULL } |
---|
| 1045 | }; |
---|
| 1046 | |
---|
| 1047 | static int msn_soap_profile_get_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 1048 | { |
---|
| 1049 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 1050 | |
---|
| 1051 | md->flags |= MSN_GOT_PROFILE; |
---|
| 1052 | msn_ns_finish_login( soap_req->ic ); |
---|
| 1053 | |
---|
| 1054 | return MSN_SOAP_OK; |
---|
| 1055 | } |
---|
| 1056 | |
---|
| 1057 | static int msn_soap_profile_get_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 1058 | { |
---|
| 1059 | g_free( soap_req->data ); |
---|
| 1060 | return 0; |
---|
| 1061 | } |
---|
| 1062 | |
---|
| 1063 | int msn_soap_profile_get( struct im_connection *ic, const char *cid ) |
---|
| 1064 | { |
---|
| 1065 | return msn_soap_start( ic, g_strdup( cid ), |
---|
| 1066 | msn_soap_profile_get_build_request, |
---|
| 1067 | msn_soap_profile_get_parser, |
---|
| 1068 | msn_soap_profile_get_handle_response, |
---|
| 1069 | msn_soap_profile_get_free_data ); |
---|
| 1070 | } |
---|