[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; |
---|
[2af3e23] | 272 | char pass[MAX_PASSPORT_PWLEN+1]; |
---|
[523fb23] | 273 | |
---|
[2c6b0f4] | 274 | if( sd->redirect ) |
---|
| 275 | { |
---|
| 276 | soap_req->url = sd->redirect; |
---|
| 277 | sd->redirect = NULL; |
---|
| 278 | } |
---|
| 279 | else if( g_str_has_suffix( ic->acc->user, "@msn.com" ) ) |
---|
[73efe3a] | 280 | soap_req->url = g_strdup( SOAP_PASSPORT_SSO_URL_MSN ); |
---|
| 281 | else |
---|
| 282 | soap_req->url = g_strdup( SOAP_PASSPORT_SSO_URL ); |
---|
| 283 | |
---|
[2af3e23] | 284 | strncpy( pass, ic->acc->pass, MAX_PASSPORT_PWLEN ); |
---|
[385fbc4] | 285 | pass[MAX_PASSPORT_PWLEN] = '\0'; |
---|
[523fb23] | 286 | soap_req->payload = g_markup_printf_escaped( SOAP_PASSPORT_SSO_PAYLOAD, |
---|
[2af3e23] | 287 | ic->acc->user, pass, md->pp_policy ); |
---|
[523fb23] | 288 | |
---|
| 289 | return MSN_SOAP_OK; |
---|
| 290 | } |
---|
| 291 | |
---|
| 292 | static xt_status msn_soap_passport_sso_token( struct xt_node *node, gpointer data ) |
---|
| 293 | { |
---|
| 294 | struct msn_soap_req_data *soap_req = data; |
---|
| 295 | struct msn_soap_passport_sso_data *sd = soap_req->data; |
---|
| 296 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 297 | struct xt_node *p; |
---|
| 298 | char *id; |
---|
| 299 | |
---|
| 300 | if( ( id = xt_find_attr( node, "Id" ) ) == NULL ) |
---|
| 301 | return XT_HANDLED; |
---|
| 302 | id += strlen( id ) - 1; |
---|
| 303 | if( *id == '1' && |
---|
[d97f51b] | 304 | ( p = xt_find_path( node, "../../wst:RequestedProofToken/wst:BinarySecret" ) ) && |
---|
[523fb23] | 305 | p->text ) |
---|
| 306 | sd->secret = g_strdup( p->text ); |
---|
| 307 | |
---|
[91d6e91] | 308 | *id -= '1'; |
---|
[80175a1] | 309 | if( *id >= 0 && *id < sizeof( md->tokens ) / sizeof( md->tokens[0] ) ) |
---|
[91d6e91] | 310 | { |
---|
| 311 | g_free( md->tokens[(int)*id] ); |
---|
| 312 | md->tokens[(int)*id] = g_strdup( node->text ); |
---|
| 313 | } |
---|
[523fb23] | 314 | |
---|
| 315 | return XT_HANDLED; |
---|
| 316 | } |
---|
| 317 | |
---|
[660cb00] | 318 | static xt_status msn_soap_passport_failure( struct xt_node *node, gpointer data ) |
---|
| 319 | { |
---|
| 320 | struct msn_soap_req_data *soap_req = data; |
---|
| 321 | struct msn_soap_passport_sso_data *sd = soap_req->data; |
---|
| 322 | struct xt_node *code = xt_find_node( node->children, "faultcode" ); |
---|
| 323 | struct xt_node *string = xt_find_node( node->children, "faultstring" ); |
---|
[2c6b0f4] | 324 | struct xt_node *url; |
---|
[660cb00] | 325 | |
---|
| 326 | if( code == NULL || code->text_len == 0 ) |
---|
| 327 | sd->error = g_strdup( "Unknown error" ); |
---|
[2c6b0f4] | 328 | else if( strcmp( code->text, "psf:Redirect" ) == 0 && |
---|
| 329 | ( url = xt_find_node( node->children, "psf:redirectUrl" ) ) && |
---|
| 330 | url->text_len > 0 ) |
---|
| 331 | sd->redirect = g_strdup( url->text ); |
---|
[660cb00] | 332 | else |
---|
| 333 | sd->error = g_strdup_printf( "%s (%s)", code->text, string && string->text_len ? |
---|
| 334 | string->text : "no description available" ); |
---|
| 335 | |
---|
| 336 | return XT_HANDLED; |
---|
| 337 | } |
---|
| 338 | |
---|
[523fb23] | 339 | static const struct xt_handler_entry msn_soap_passport_sso_parser[] = { |
---|
| 340 | { "wsse:BinarySecurityToken", "wst:RequestedSecurityToken", msn_soap_passport_sso_token }, |
---|
[660cb00] | 341 | { "S:Fault", "S:Envelope", msn_soap_passport_failure }, |
---|
[523fb23] | 342 | { NULL, NULL, NULL } |
---|
| 343 | }; |
---|
| 344 | |
---|
| 345 | static char *msn_key_fuckery( char *key, int key_len, char *type ) |
---|
| 346 | { |
---|
| 347 | unsigned char hash1[20+strlen(type)+1]; |
---|
| 348 | unsigned char hash2[20]; |
---|
| 349 | char *ret; |
---|
| 350 | |
---|
| 351 | sha1_hmac( key, key_len, type, 0, hash1 ); |
---|
| 352 | strcpy( (char*) hash1 + 20, type ); |
---|
| 353 | sha1_hmac( key, key_len, (char*) hash1, sizeof( hash1 ) - 1, hash2 ); |
---|
| 354 | |
---|
| 355 | /* This is okay as hash1 is read completely before it's overwritten. */ |
---|
| 356 | sha1_hmac( key, key_len, (char*) hash1, 20, hash1 ); |
---|
| 357 | sha1_hmac( key, key_len, (char*) hash1, sizeof( hash1 ) - 1, hash1 ); |
---|
| 358 | |
---|
| 359 | ret = g_malloc( 24 ); |
---|
| 360 | memcpy( ret, hash2, 20 ); |
---|
| 361 | memcpy( ret + 20, hash1, 4 ); |
---|
| 362 | return ret; |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | static int msn_soap_passport_sso_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 366 | { |
---|
| 367 | struct msn_soap_passport_sso_data *sd = soap_req->data; |
---|
| 368 | struct im_connection *ic = soap_req->ic; |
---|
[4aa8a04] | 369 | struct msn_data *md = ic->proto_data; |
---|
[523fb23] | 370 | char *key1, *key2, *key3, *blurb64; |
---|
| 371 | int key1_len; |
---|
| 372 | unsigned char *padnonce, *des3res; |
---|
| 373 | struct |
---|
| 374 | { |
---|
| 375 | unsigned int uStructHeaderSize; // 28. Does not count data |
---|
| 376 | unsigned int uCryptMode; // CRYPT_MODE_CBC (1) |
---|
| 377 | unsigned int uCipherType; // TripleDES (0x6603) |
---|
| 378 | unsigned int uHashType; // SHA1 (0x8004) |
---|
| 379 | unsigned int uIVLen; // 8 |
---|
| 380 | unsigned int uHashLen; // 20 |
---|
| 381 | unsigned int uCipherLen; // 72 |
---|
| 382 | unsigned char iv[8]; |
---|
| 383 | unsigned char hash[20]; |
---|
| 384 | unsigned char cipherbytes[72]; |
---|
| 385 | } blurb = { |
---|
| 386 | GUINT32_TO_LE( 28 ), |
---|
| 387 | GUINT32_TO_LE( 1 ), |
---|
| 388 | GUINT32_TO_LE( 0x6603 ), |
---|
| 389 | GUINT32_TO_LE( 0x8004 ), |
---|
| 390 | GUINT32_TO_LE( 8 ), |
---|
| 391 | GUINT32_TO_LE( 20 ), |
---|
| 392 | GUINT32_TO_LE( 72 ), |
---|
| 393 | }; |
---|
[660cb00] | 394 | |
---|
[2c6b0f4] | 395 | if( sd->redirect ) |
---|
| 396 | return MSN_SOAP_RETRY; |
---|
| 397 | |
---|
[4aa8a04] | 398 | if( md->soapq ) |
---|
[4e1be76] | 399 | return msn_soapq_flush( ic, TRUE ); |
---|
[4aa8a04] | 400 | |
---|
[660cb00] | 401 | if( sd->secret == NULL ) |
---|
| 402 | { |
---|
| 403 | msn_auth_got_passport_token( ic, NULL, sd->error ); |
---|
| 404 | return MSN_SOAP_OK; |
---|
| 405 | } |
---|
[523fb23] | 406 | |
---|
| 407 | key1_len = base64_decode( sd->secret, (unsigned char**) &key1 ); |
---|
| 408 | |
---|
| 409 | key2 = msn_key_fuckery( key1, key1_len, "WS-SecureConversationSESSION KEY HASH" ); |
---|
| 410 | key3 = msn_key_fuckery( key1, key1_len, "WS-SecureConversationSESSION KEY ENCRYPTION" ); |
---|
| 411 | |
---|
| 412 | sha1_hmac( key2, 24, sd->nonce, 0, blurb.hash ); |
---|
| 413 | padnonce = g_malloc( strlen( sd->nonce ) + 8 ); |
---|
| 414 | strcpy( (char*) padnonce, sd->nonce ); |
---|
| 415 | memset( padnonce + strlen( sd->nonce ), 8, 8 ); |
---|
| 416 | |
---|
| 417 | random_bytes( blurb.iv, 8 ); |
---|
| 418 | |
---|
| 419 | ssl_des3_encrypt( (unsigned char*) key3, 24, padnonce, strlen( sd->nonce ) + 8, blurb.iv, &des3res ); |
---|
| 420 | memcpy( blurb.cipherbytes, des3res, 72 ); |
---|
| 421 | |
---|
| 422 | blurb64 = base64_encode( (unsigned char*) &blurb, sizeof( blurb ) ); |
---|
[660cb00] | 423 | msn_auth_got_passport_token( ic, blurb64, NULL ); |
---|
[523fb23] | 424 | |
---|
| 425 | g_free( padnonce ); |
---|
| 426 | g_free( blurb64 ); |
---|
| 427 | g_free( des3res ); |
---|
| 428 | g_free( key1 ); |
---|
| 429 | g_free( key2 ); |
---|
| 430 | g_free( key3 ); |
---|
| 431 | |
---|
| 432 | return MSN_SOAP_OK; |
---|
| 433 | } |
---|
| 434 | |
---|
| 435 | static int msn_soap_passport_sso_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 436 | { |
---|
| 437 | struct msn_soap_passport_sso_data *sd = soap_req->data; |
---|
| 438 | |
---|
| 439 | g_free( sd->nonce ); |
---|
| 440 | g_free( sd->secret ); |
---|
[660cb00] | 441 | g_free( sd->error ); |
---|
[2c6b0f4] | 442 | g_free( sd->redirect ); |
---|
[c1d40e7] | 443 | g_free( sd ); |
---|
[523fb23] | 444 | |
---|
| 445 | return MSN_SOAP_OK; |
---|
| 446 | } |
---|
| 447 | |
---|
[4aa8a04] | 448 | int msn_soap_passport_sso_request( struct im_connection *ic, const char *nonce ) |
---|
[523fb23] | 449 | { |
---|
| 450 | struct msn_soap_passport_sso_data *sd = g_new0( struct msn_soap_passport_sso_data, 1 ); |
---|
| 451 | |
---|
| 452 | sd->nonce = g_strdup( nonce ); |
---|
| 453 | |
---|
| 454 | return msn_soap_start( ic, sd, msn_soap_passport_sso_build_request, |
---|
| 455 | msn_soap_passport_sso_parser, |
---|
| 456 | msn_soap_passport_sso_handle_response, |
---|
| 457 | msn_soap_passport_sso_free_data ); |
---|
| 458 | } |
---|
| 459 | |
---|
| 460 | |
---|
[bc090f0] | 461 | /* oim_send: Sending offline messages */ |
---|
| 462 | |
---|
| 463 | struct msn_soap_oim_send_data |
---|
| 464 | { |
---|
| 465 | char *to; |
---|
| 466 | char *msg; |
---|
| 467 | int number; |
---|
[27053b5] | 468 | msn_soap_result_t need_retry; |
---|
[bc090f0] | 469 | }; |
---|
| 470 | |
---|
[e5a8118] | 471 | static int msn_soap_oim_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 472 | { |
---|
| 473 | struct msn_soap_oim_send_data *oim = soap_req->data; |
---|
| 474 | struct im_connection *ic = soap_req->ic; |
---|
| 475 | struct msn_data *md = ic->proto_data; |
---|
| 476 | char *display_name_b64; |
---|
| 477 | |
---|
[91d6e91] | 478 | display_name_b64 = tobase64( set_getstr( &ic->acc->set, "display_name" ) ); |
---|
[e5a8118] | 479 | |
---|
| 480 | soap_req->url = g_strdup( SOAP_OIM_SEND_URL ); |
---|
[7db65b7] | 481 | soap_req->action = g_strdup( SOAP_OIM_SEND_ACTION ); |
---|
[e5a8118] | 482 | soap_req->payload = g_markup_printf_escaped( SOAP_OIM_SEND_PAYLOAD, |
---|
[91d6e91] | 483 | ic->acc->user, display_name_b64, MSNP_VER, MSNP_BUILD, |
---|
| 484 | oim->to, md->tokens[2], |
---|
[5fecede] | 485 | MSNP11_PROD_ID, md->lock_key ? md->lock_key : "", |
---|
| 486 | oim->number, oim->number, oim->msg ); |
---|
[e5a8118] | 487 | |
---|
| 488 | g_free( display_name_b64 ); |
---|
[27053b5] | 489 | oim->need_retry = MSN_SOAP_OK; |
---|
[e5a8118] | 490 | |
---|
[523fb23] | 491 | return MSN_SOAP_OK; |
---|
[e5a8118] | 492 | } |
---|
| 493 | |
---|
[27053b5] | 494 | static xt_status msn_soap_oim_reauth( struct xt_node *node, gpointer data ) |
---|
[e5a8118] | 495 | { |
---|
| 496 | struct msn_soap_req_data *soap_req = data; |
---|
| 497 | struct msn_soap_oim_send_data *oim = soap_req->data; |
---|
| 498 | struct im_connection *ic = soap_req->ic; |
---|
| 499 | struct msn_data *md = ic->proto_data; |
---|
[27053b5] | 500 | struct xt_node *c; |
---|
[e5a8118] | 501 | |
---|
[27053b5] | 502 | if( ( c = xt_find_node( node->children, "LockKeyChallenge" ) ) && c->text_len > 0 ) |
---|
| 503 | { |
---|
| 504 | g_free( md->lock_key ); |
---|
| 505 | md->lock_key = msn_p11_challenge( c->text ); |
---|
| 506 | oim->need_retry = MSN_SOAP_RETRY; |
---|
| 507 | } |
---|
| 508 | if( xt_find_node( node->children, "RequiredAuthPolicy" ) ) |
---|
| 509 | { |
---|
| 510 | oim->need_retry = MSN_SOAP_REAUTH; |
---|
| 511 | } |
---|
[e5a8118] | 512 | |
---|
| 513 | return XT_HANDLED; |
---|
| 514 | } |
---|
| 515 | |
---|
| 516 | static const struct xt_handler_entry msn_soap_oim_send_parser[] = { |
---|
[27053b5] | 517 | { "detail", "soap:Fault", msn_soap_oim_reauth }, |
---|
| 518 | { NULL, NULL, NULL } |
---|
[e5a8118] | 519 | }; |
---|
| 520 | |
---|
| 521 | static int msn_soap_oim_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 522 | { |
---|
| 523 | struct msn_soap_oim_send_data *oim = soap_req->data; |
---|
| 524 | |
---|
[bc090f0] | 525 | if( soap_req->http_req->status_code == 500 && oim->need_retry && soap_req->ttl > 0 ) |
---|
[e5a8118] | 526 | { |
---|
[27053b5] | 527 | return oim->need_retry; |
---|
[e5a8118] | 528 | } |
---|
| 529 | else if( soap_req->http_req->status_code == 200 ) |
---|
[bc090f0] | 530 | { |
---|
| 531 | imcb_log( soap_req->ic, "Offline message successfully delivered to %s", oim->to ); |
---|
[e5a8118] | 532 | return MSN_SOAP_OK; |
---|
[bc090f0] | 533 | } |
---|
[e5a8118] | 534 | else |
---|
[bc090f0] | 535 | { |
---|
| 536 | imcb_log( soap_req->ic, "Failed to deliver offline message to %s:\n%s", oim->to, oim->msg ); |
---|
[e5a8118] | 537 | return MSN_SOAP_ABORT; |
---|
[bc090f0] | 538 | } |
---|
[e5a8118] | 539 | } |
---|
| 540 | |
---|
| 541 | static int msn_soap_oim_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 542 | { |
---|
| 543 | struct msn_soap_oim_send_data *oim = soap_req->data; |
---|
| 544 | |
---|
| 545 | g_free( oim->to ); |
---|
| 546 | g_free( oim->msg ); |
---|
| 547 | g_free( oim ); |
---|
| 548 | |
---|
[523fb23] | 549 | return MSN_SOAP_OK; |
---|
[e5a8118] | 550 | } |
---|
| 551 | |
---|
| 552 | int msn_soap_oim_send( struct im_connection *ic, const char *to, const char *msg ) |
---|
| 553 | { |
---|
| 554 | struct msn_soap_oim_send_data *data; |
---|
| 555 | |
---|
| 556 | data = g_new0( struct msn_soap_oim_send_data, 1 ); |
---|
| 557 | data->to = g_strdup( to ); |
---|
| 558 | data->msg = tobase64( msg ); |
---|
| 559 | data->number = 1; |
---|
| 560 | |
---|
| 561 | return msn_soap_start( ic, data, msn_soap_oim_build_request, |
---|
| 562 | msn_soap_oim_send_parser, |
---|
| 563 | msn_soap_oim_handle_response, |
---|
| 564 | msn_soap_oim_free_data ); |
---|
| 565 | } |
---|
[bc090f0] | 566 | |
---|
| 567 | int msn_soap_oim_send_queue( struct im_connection *ic, GSList **msgq ) |
---|
| 568 | { |
---|
| 569 | GSList *l; |
---|
| 570 | char *n = NULL; |
---|
| 571 | |
---|
| 572 | for( l = *msgq; l; l = l->next ) |
---|
| 573 | { |
---|
| 574 | struct msn_message *m = l->data; |
---|
| 575 | |
---|
| 576 | if( n == NULL ) |
---|
| 577 | n = m->who; |
---|
| 578 | if( strcmp( n, m->who ) == 0 ) |
---|
| 579 | msn_soap_oim_send( ic, m->who, m->text ); |
---|
| 580 | } |
---|
| 581 | |
---|
| 582 | while( *msgq != NULL ) |
---|
| 583 | { |
---|
| 584 | struct msn_message *m = (*msgq)->data; |
---|
| 585 | |
---|
| 586 | g_free( m->who ); |
---|
| 587 | g_free( m->text ); |
---|
| 588 | g_free( m ); |
---|
| 589 | |
---|
| 590 | *msgq = g_slist_remove( *msgq, m ); |
---|
| 591 | } |
---|
[523fb23] | 592 | |
---|
| 593 | return 1; |
---|
[bc090f0] | 594 | } |
---|
[7db65b7] | 595 | |
---|
| 596 | |
---|
| 597 | /* memlist: Fetching the membership list (NOT address book) */ |
---|
| 598 | |
---|
| 599 | static int msn_soap_memlist_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 600 | { |
---|
[7f34ce2] | 601 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 602 | |
---|
[7db65b7] | 603 | soap_req->url = g_strdup( SOAP_MEMLIST_URL ); |
---|
| 604 | soap_req->action = g_strdup( SOAP_MEMLIST_ACTION ); |
---|
[6ddb223] | 605 | soap_req->payload = msn_soap_abservice_build( SOAP_MEMLIST_PAYLOAD, "Initial", md->tokens[1] ); |
---|
[7db65b7] | 606 | |
---|
| 607 | return 1; |
---|
| 608 | } |
---|
| 609 | |
---|
[7f34ce2] | 610 | static xt_status msn_soap_memlist_member( struct xt_node *node, gpointer data ) |
---|
| 611 | { |
---|
| 612 | bee_user_t *bu; |
---|
| 613 | struct msn_buddy_data *bd; |
---|
| 614 | struct xt_node *p; |
---|
| 615 | char *role = NULL, *handle = NULL; |
---|
| 616 | struct msn_soap_req_data *soap_req = data; |
---|
| 617 | struct im_connection *ic = soap_req->ic; |
---|
| 618 | |
---|
[d97f51b] | 619 | if( ( p = xt_find_path( node, "../../MemberRole" ) ) ) |
---|
[7f34ce2] | 620 | role = p->text; |
---|
| 621 | |
---|
| 622 | if( ( p = xt_find_node( node->children, "PassportName" ) ) ) |
---|
| 623 | handle = p->text; |
---|
| 624 | |
---|
| 625 | if( !role || !handle || |
---|
| 626 | !( ( bu = bee_user_by_handle( ic->bee, ic, handle ) ) || |
---|
| 627 | ( bu = bee_user_new( ic->bee, ic, handle, 0 ) ) ) ) |
---|
| 628 | return XT_HANDLED; |
---|
| 629 | |
---|
| 630 | bd = bu->data; |
---|
| 631 | if( strcmp( role, "Allow" ) == 0 ) |
---|
[04cd284] | 632 | { |
---|
[7f34ce2] | 633 | bd->flags |= MSN_BUDDY_AL; |
---|
[04cd284] | 634 | ic->permit = g_slist_prepend( ic->permit, g_strdup( handle ) ); |
---|
| 635 | } |
---|
[7f34ce2] | 636 | else if( strcmp( role, "Block" ) == 0 ) |
---|
[04cd284] | 637 | { |
---|
[7f34ce2] | 638 | bd->flags |= MSN_BUDDY_BL; |
---|
[04cd284] | 639 | ic->deny = g_slist_prepend( ic->deny, g_strdup( handle ) ); |
---|
| 640 | } |
---|
[7f34ce2] | 641 | else if( strcmp( role, "Reverse" ) == 0 ) |
---|
| 642 | bd->flags |= MSN_BUDDY_RL; |
---|
| 643 | else if( strcmp( role, "Pending" ) == 0 ) |
---|
| 644 | bd->flags |= MSN_BUDDY_PL; |
---|
[e5854a8] | 645 | |
---|
[ed86165] | 646 | if( getenv( "BITLBEE_DEBUG" ) ) |
---|
| 647 | printf( "%p %s %d\n", bu, handle, bd->flags ); |
---|
[7f34ce2] | 648 | |
---|
| 649 | return XT_HANDLED; |
---|
| 650 | } |
---|
| 651 | |
---|
[7db65b7] | 652 | static const struct xt_handler_entry msn_soap_memlist_parser[] = { |
---|
[7f34ce2] | 653 | { "Member", "Members", msn_soap_memlist_member }, |
---|
[7db65b7] | 654 | { NULL, NULL, NULL } |
---|
| 655 | }; |
---|
| 656 | |
---|
| 657 | static int msn_soap_memlist_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 658 | { |
---|
[7f34ce2] | 659 | msn_soap_addressbook_request( soap_req->ic ); |
---|
| 660 | |
---|
| 661 | return MSN_SOAP_OK; |
---|
[7db65b7] | 662 | } |
---|
| 663 | |
---|
| 664 | static int msn_soap_memlist_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 665 | { |
---|
| 666 | return 0; |
---|
| 667 | } |
---|
| 668 | |
---|
| 669 | int msn_soap_memlist_request( struct im_connection *ic ) |
---|
| 670 | { |
---|
| 671 | return msn_soap_start( ic, NULL, msn_soap_memlist_build_request, |
---|
| 672 | msn_soap_memlist_parser, |
---|
| 673 | msn_soap_memlist_handle_response, |
---|
| 674 | msn_soap_memlist_free_data ); |
---|
| 675 | } |
---|
[7f34ce2] | 676 | |
---|
[193dc74] | 677 | /* Variant: Adding/Removing people */ |
---|
| 678 | struct msn_soap_memlist_edit_data |
---|
| 679 | { |
---|
| 680 | char *handle; |
---|
| 681 | gboolean add; |
---|
| 682 | msn_buddy_flags_t list; |
---|
| 683 | }; |
---|
| 684 | |
---|
| 685 | static int msn_soap_memlist_edit_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 686 | { |
---|
| 687 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 688 | struct msn_soap_memlist_edit_data *med = soap_req->data; |
---|
| 689 | char *add, *scenario, *list; |
---|
| 690 | |
---|
| 691 | soap_req->url = g_strdup( SOAP_MEMLIST_URL ); |
---|
| 692 | if( med->add ) |
---|
| 693 | { |
---|
| 694 | soap_req->action = g_strdup( SOAP_MEMLIST_ADD_ACTION ); |
---|
| 695 | add = "Add"; |
---|
| 696 | } |
---|
| 697 | else |
---|
| 698 | { |
---|
| 699 | soap_req->action = g_strdup( SOAP_MEMLIST_DEL_ACTION ); |
---|
| 700 | add = "Delete"; |
---|
| 701 | } |
---|
| 702 | switch( med->list ) |
---|
| 703 | { |
---|
| 704 | case MSN_BUDDY_AL: |
---|
| 705 | scenario = "BlockUnblock"; |
---|
| 706 | list = "Allow"; |
---|
| 707 | break; |
---|
| 708 | case MSN_BUDDY_BL: |
---|
| 709 | scenario = "BlockUnblock"; |
---|
| 710 | list = "Block"; |
---|
| 711 | break; |
---|
| 712 | case MSN_BUDDY_RL: |
---|
| 713 | scenario = "Timer"; |
---|
| 714 | list = "Reverse"; |
---|
| 715 | break; |
---|
| 716 | case MSN_BUDDY_PL: |
---|
| 717 | default: |
---|
| 718 | scenario = "Timer"; |
---|
| 719 | list = "Pending"; |
---|
| 720 | break; |
---|
| 721 | } |
---|
[6ddb223] | 722 | soap_req->payload = msn_soap_abservice_build( SOAP_MEMLIST_EDIT_PAYLOAD, |
---|
[193dc74] | 723 | scenario, md->tokens[1], add, list, med->handle, add ); |
---|
| 724 | |
---|
| 725 | return 1; |
---|
| 726 | } |
---|
| 727 | |
---|
| 728 | static int msn_soap_memlist_edit_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 729 | { |
---|
| 730 | return MSN_SOAP_OK; |
---|
| 731 | } |
---|
| 732 | |
---|
| 733 | static int msn_soap_memlist_edit_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 734 | { |
---|
| 735 | struct msn_soap_memlist_edit_data *med = soap_req->data; |
---|
| 736 | |
---|
| 737 | g_free( med->handle ); |
---|
| 738 | g_free( med ); |
---|
| 739 | |
---|
| 740 | return 0; |
---|
| 741 | } |
---|
| 742 | |
---|
| 743 | int msn_soap_memlist_edit( struct im_connection *ic, const char *handle, gboolean add, int list ) |
---|
| 744 | { |
---|
| 745 | struct msn_soap_memlist_edit_data *med; |
---|
| 746 | |
---|
| 747 | med = g_new0( struct msn_soap_memlist_edit_data, 1 ); |
---|
| 748 | med->handle = g_strdup( handle ); |
---|
| 749 | med->add = add; |
---|
| 750 | med->list = list; |
---|
| 751 | |
---|
| 752 | return msn_soap_start( ic, med, msn_soap_memlist_edit_build_request, |
---|
| 753 | NULL, |
---|
| 754 | msn_soap_memlist_edit_handle_response, |
---|
| 755 | msn_soap_memlist_edit_free_data ); |
---|
| 756 | } |
---|
| 757 | |
---|
[7f34ce2] | 758 | |
---|
| 759 | /* addressbook: Fetching the membership list (NOT address book) */ |
---|
| 760 | |
---|
| 761 | static int msn_soap_addressbook_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 762 | { |
---|
| 763 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 764 | |
---|
| 765 | soap_req->url = g_strdup( SOAP_ADDRESSBOOK_URL ); |
---|
| 766 | soap_req->action = g_strdup( SOAP_ADDRESSBOOK_ACTION ); |
---|
[6ddb223] | 767 | soap_req->payload = msn_soap_abservice_build( SOAP_ADDRESSBOOK_PAYLOAD, "Initial", md->tokens[1] ); |
---|
[7f34ce2] | 768 | |
---|
| 769 | return 1; |
---|
| 770 | } |
---|
| 771 | |
---|
| 772 | static xt_status msn_soap_addressbook_group( struct xt_node *node, gpointer data ) |
---|
| 773 | { |
---|
| 774 | struct xt_node *p; |
---|
| 775 | char *id = NULL, *name = NULL; |
---|
| 776 | struct msn_soap_req_data *soap_req = data; |
---|
[ff27648] | 777 | struct msn_data *md = soap_req->ic->proto_data; |
---|
[7f34ce2] | 778 | |
---|
[d97f51b] | 779 | if( ( p = xt_find_path( node, "../groupId" ) ) ) |
---|
[7f34ce2] | 780 | id = p->text; |
---|
| 781 | |
---|
| 782 | if( ( p = xt_find_node( node->children, "name" ) ) ) |
---|
| 783 | name = p->text; |
---|
| 784 | |
---|
[ff27648] | 785 | if( id && name ) |
---|
| 786 | { |
---|
| 787 | struct msn_group *mg = g_new0( struct msn_group, 1 ); |
---|
| 788 | mg->id = g_strdup( id ); |
---|
| 789 | mg->name = g_strdup( name ); |
---|
| 790 | md->groups = g_slist_prepend( md->groups, mg ); |
---|
| 791 | } |
---|
| 792 | |
---|
[ed86165] | 793 | if( getenv( "BITLBEE_DEBUG" ) ) |
---|
| 794 | printf( "%s %s\n", id, name ); |
---|
[7f34ce2] | 795 | |
---|
| 796 | return XT_HANDLED; |
---|
| 797 | } |
---|
| 798 | |
---|
| 799 | static xt_status msn_soap_addressbook_contact( struct xt_node *node, gpointer data ) |
---|
| 800 | { |
---|
| 801 | bee_user_t *bu; |
---|
| 802 | struct msn_buddy_data *bd; |
---|
| 803 | struct xt_node *p; |
---|
[9b01339] | 804 | char *id = NULL, *type = NULL, *handle = NULL, *is_msgr = "false", |
---|
[ff27648] | 805 | *display_name = NULL, *group_id = NULL; |
---|
[7f34ce2] | 806 | struct msn_soap_req_data *soap_req = data; |
---|
| 807 | struct im_connection *ic = soap_req->ic; |
---|
[ff27648] | 808 | struct msn_group *group; |
---|
[7f34ce2] | 809 | |
---|
[d97f51b] | 810 | if( ( p = xt_find_path( node, "../contactId" ) ) ) |
---|
[7f34ce2] | 811 | id = p->text; |
---|
| 812 | if( ( p = xt_find_node( node->children, "contactType" ) ) ) |
---|
| 813 | type = p->text; |
---|
| 814 | if( ( p = xt_find_node( node->children, "passportName" ) ) ) |
---|
| 815 | handle = p->text; |
---|
| 816 | if( ( p = xt_find_node( node->children, "displayName" ) ) ) |
---|
| 817 | display_name = p->text; |
---|
[9b01339] | 818 | if( ( p = xt_find_node( node->children, "isMessengerUser" ) ) ) |
---|
| 819 | is_msgr = p->text; |
---|
[ff27648] | 820 | if( ( p = xt_find_path( node, "groupIds/guid" ) ) ) |
---|
| 821 | group_id = p->text; |
---|
[7f34ce2] | 822 | |
---|
| 823 | if( type && g_strcasecmp( type, "me" ) == 0 ) |
---|
| 824 | { |
---|
| 825 | set_t *set = set_find( &ic->acc->set, "display_name" ); |
---|
| 826 | g_free( set->value ); |
---|
| 827 | set->value = g_strdup( display_name ); |
---|
| 828 | |
---|
[80175a1] | 829 | /* Try to fetch the profile; if the user has one, that's where |
---|
| 830 | we can find the persistent display_name. */ |
---|
| 831 | if( ( p = xt_find_node( node->children, "CID" ) ) && p->text ) |
---|
| 832 | msn_soap_profile_get( ic, p->text ); |
---|
| 833 | |
---|
[7f34ce2] | 834 | return XT_HANDLED; |
---|
| 835 | } |
---|
| 836 | |
---|
[9b01339] | 837 | if( !bool2int( is_msgr ) || handle == NULL ) |
---|
[d97f51b] | 838 | return XT_HANDLED; |
---|
| 839 | |
---|
[7f34ce2] | 840 | if( !( bu = bee_user_by_handle( ic->bee, ic, handle ) ) && |
---|
| 841 | !( bu = bee_user_new( ic->bee, ic, handle, 0 ) ) ) |
---|
| 842 | return XT_HANDLED; |
---|
| 843 | |
---|
| 844 | bd = bu->data; |
---|
| 845 | bd->flags |= MSN_BUDDY_FL; |
---|
| 846 | g_free( bd->cid ); |
---|
| 847 | bd->cid = g_strdup( id ); |
---|
| 848 | |
---|
| 849 | imcb_rename_buddy( ic, handle, display_name ); |
---|
| 850 | |
---|
[ff27648] | 851 | if( group_id && ( group = msn_group_by_id( ic, group_id ) ) ) |
---|
| 852 | imcb_add_buddy( ic, handle, group->name ); |
---|
| 853 | |
---|
[ed86165] | 854 | if( getenv( "BITLBEE_DEBUG" ) ) |
---|
| 855 | printf( "%s %s %s %s\n", id, type, handle, display_name ); |
---|
[7f34ce2] | 856 | |
---|
| 857 | return XT_HANDLED; |
---|
| 858 | } |
---|
| 859 | |
---|
| 860 | static const struct xt_handler_entry msn_soap_addressbook_parser[] = { |
---|
| 861 | { "contactInfo", "Contact", msn_soap_addressbook_contact }, |
---|
| 862 | { "groupInfo", "Group", msn_soap_addressbook_group }, |
---|
| 863 | { NULL, NULL, NULL } |
---|
| 864 | }; |
---|
| 865 | |
---|
| 866 | static int msn_soap_addressbook_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 867 | { |
---|
[327af51] | 868 | GSList *l; |
---|
| 869 | |
---|
| 870 | for( l = soap_req->ic->bee->users; l; l = l->next ) |
---|
| 871 | { |
---|
| 872 | struct bee_user *bu = l->data; |
---|
| 873 | |
---|
| 874 | if( bu->ic == soap_req->ic ) |
---|
| 875 | msn_buddy_ask( bu ); |
---|
| 876 | } |
---|
| 877 | |
---|
[ca7de3a] | 878 | msn_auth_got_contact_list( soap_req->ic ); |
---|
[327af51] | 879 | |
---|
[7f34ce2] | 880 | return MSN_SOAP_OK; |
---|
| 881 | } |
---|
| 882 | |
---|
| 883 | static int msn_soap_addressbook_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 884 | { |
---|
| 885 | return 0; |
---|
| 886 | } |
---|
| 887 | |
---|
| 888 | int msn_soap_addressbook_request( struct im_connection *ic ) |
---|
| 889 | { |
---|
| 890 | return msn_soap_start( ic, NULL, msn_soap_addressbook_build_request, |
---|
| 891 | msn_soap_addressbook_parser, |
---|
| 892 | msn_soap_addressbook_handle_response, |
---|
| 893 | msn_soap_addressbook_free_data ); |
---|
| 894 | } |
---|
[4452e69] | 895 | |
---|
| 896 | /* Variant: Change our display name. */ |
---|
| 897 | static int msn_soap_ab_namechange_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 898 | { |
---|
| 899 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 900 | |
---|
| 901 | soap_req->url = g_strdup( SOAP_ADDRESSBOOK_URL ); |
---|
| 902 | soap_req->action = g_strdup( SOAP_AB_NAMECHANGE_ACTION ); |
---|
[6ddb223] | 903 | soap_req->payload = msn_soap_abservice_build( SOAP_AB_NAMECHANGE_PAYLOAD, |
---|
[e0e1546] | 904 | "Timer", md->tokens[1], (char *) soap_req->data ); |
---|
[4452e69] | 905 | |
---|
| 906 | return 1; |
---|
| 907 | } |
---|
| 908 | |
---|
| 909 | static int msn_soap_ab_namechange_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 910 | { |
---|
| 911 | /* TODO: Ack the change? Not sure what the NAKs look like.. */ |
---|
| 912 | return MSN_SOAP_OK; |
---|
| 913 | } |
---|
| 914 | |
---|
| 915 | static int msn_soap_ab_namechange_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 916 | { |
---|
| 917 | g_free( soap_req->data ); |
---|
| 918 | return 0; |
---|
| 919 | } |
---|
| 920 | |
---|
| 921 | int msn_soap_addressbook_set_display_name( struct im_connection *ic, const char *new ) |
---|
| 922 | { |
---|
| 923 | return msn_soap_start( ic, g_strdup( new ), |
---|
| 924 | msn_soap_ab_namechange_build_request, |
---|
| 925 | NULL, |
---|
| 926 | msn_soap_ab_namechange_handle_response, |
---|
| 927 | msn_soap_ab_namechange_free_data ); |
---|
| 928 | } |
---|
[4fc95c5] | 929 | |
---|
| 930 | /* Add a contact. */ |
---|
| 931 | static int msn_soap_ab_contact_add_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 932 | { |
---|
| 933 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 934 | bee_user_t *bu = soap_req->data; |
---|
| 935 | |
---|
| 936 | soap_req->url = g_strdup( SOAP_ADDRESSBOOK_URL ); |
---|
| 937 | soap_req->action = g_strdup( SOAP_AB_CONTACT_ADD_ACTION ); |
---|
| 938 | soap_req->payload = msn_soap_abservice_build( SOAP_AB_CONTACT_ADD_PAYLOAD, |
---|
| 939 | "ContactSave", md->tokens[1], bu->handle, bu->fullname ? bu->fullname : bu->handle ); |
---|
| 940 | |
---|
| 941 | return 1; |
---|
| 942 | } |
---|
| 943 | |
---|
| 944 | static xt_status msn_soap_ab_contact_add_cid( struct xt_node *node, gpointer data ) |
---|
| 945 | { |
---|
| 946 | struct msn_soap_req_data *soap_req = data; |
---|
| 947 | bee_user_t *bu = soap_req->data; |
---|
| 948 | struct msn_buddy_data *bd = bu->data; |
---|
| 949 | |
---|
| 950 | g_free( bd->cid ); |
---|
| 951 | bd->cid = g_strdup( node->text ); |
---|
| 952 | |
---|
| 953 | return XT_HANDLED; |
---|
| 954 | } |
---|
| 955 | |
---|
| 956 | static const struct xt_handler_entry msn_soap_ab_contact_add_parser[] = { |
---|
| 957 | { "guid", "ABContactAddResult", msn_soap_ab_contact_add_cid }, |
---|
| 958 | { NULL, NULL, NULL } |
---|
| 959 | }; |
---|
| 960 | |
---|
| 961 | static int msn_soap_ab_contact_add_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 962 | { |
---|
| 963 | /* TODO: Ack the change? Not sure what the NAKs look like.. */ |
---|
| 964 | return MSN_SOAP_OK; |
---|
| 965 | } |
---|
| 966 | |
---|
| 967 | static int msn_soap_ab_contact_add_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 968 | { |
---|
| 969 | return 0; |
---|
| 970 | } |
---|
| 971 | |
---|
| 972 | int msn_soap_ab_contact_add( struct im_connection *ic, bee_user_t *bu ) |
---|
| 973 | { |
---|
| 974 | return msn_soap_start( ic, bu, |
---|
| 975 | msn_soap_ab_contact_add_build_request, |
---|
| 976 | msn_soap_ab_contact_add_parser, |
---|
| 977 | msn_soap_ab_contact_add_handle_response, |
---|
| 978 | msn_soap_ab_contact_add_free_data ); |
---|
| 979 | } |
---|
| 980 | |
---|
| 981 | /* Remove a contact. */ |
---|
| 982 | static int msn_soap_ab_contact_del_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 983 | { |
---|
| 984 | struct msn_data *md = soap_req->ic->proto_data; |
---|
[52f5e90] | 985 | const char *cid = soap_req->data; |
---|
[4fc95c5] | 986 | |
---|
| 987 | soap_req->url = g_strdup( SOAP_ADDRESSBOOK_URL ); |
---|
| 988 | soap_req->action = g_strdup( SOAP_AB_CONTACT_DEL_ACTION ); |
---|
| 989 | soap_req->payload = msn_soap_abservice_build( SOAP_AB_CONTACT_DEL_PAYLOAD, |
---|
[52f5e90] | 990 | "Timer", md->tokens[1], cid ); |
---|
[4fc95c5] | 991 | |
---|
| 992 | return 1; |
---|
| 993 | } |
---|
| 994 | |
---|
| 995 | static int msn_soap_ab_contact_del_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 996 | { |
---|
| 997 | /* TODO: Ack the change? Not sure what the NAKs look like.. */ |
---|
| 998 | return MSN_SOAP_OK; |
---|
| 999 | } |
---|
| 1000 | |
---|
| 1001 | static int msn_soap_ab_contact_del_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 1002 | { |
---|
[52f5e90] | 1003 | g_free( soap_req->data ); |
---|
[4fc95c5] | 1004 | return 0; |
---|
| 1005 | } |
---|
| 1006 | |
---|
| 1007 | int msn_soap_ab_contact_del( struct im_connection *ic, bee_user_t *bu ) |
---|
| 1008 | { |
---|
[52f5e90] | 1009 | struct msn_buddy_data *bd = bu->data; |
---|
| 1010 | |
---|
| 1011 | return msn_soap_start( ic, g_strdup( bd->cid ), |
---|
[4fc95c5] | 1012 | msn_soap_ab_contact_del_build_request, |
---|
| 1013 | NULL, |
---|
| 1014 | msn_soap_ab_contact_del_handle_response, |
---|
| 1015 | msn_soap_ab_contact_del_free_data ); |
---|
| 1016 | } |
---|
[80175a1] | 1017 | |
---|
| 1018 | |
---|
| 1019 | |
---|
| 1020 | /* Storage stuff: Fetch profile. */ |
---|
| 1021 | static int msn_soap_profile_get_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 1022 | { |
---|
| 1023 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 1024 | |
---|
| 1025 | soap_req->url = g_strdup( SOAP_STORAGE_URL ); |
---|
| 1026 | soap_req->action = g_strdup( SOAP_PROFILE_GET_ACTION ); |
---|
| 1027 | soap_req->payload = g_markup_printf_escaped( SOAP_PROFILE_GET_PAYLOAD, |
---|
| 1028 | md->tokens[3], (char*) soap_req->data ); |
---|
| 1029 | |
---|
| 1030 | return 1; |
---|
| 1031 | } |
---|
| 1032 | |
---|
| 1033 | static xt_status msn_soap_profile_get_result( struct xt_node *node, gpointer data ) |
---|
| 1034 | { |
---|
| 1035 | struct msn_soap_req_data *soap_req = data; |
---|
| 1036 | struct im_connection *ic = soap_req->ic; |
---|
| 1037 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 1038 | struct xt_node *dn; |
---|
| 1039 | |
---|
| 1040 | if( ( dn = xt_find_node( node->children, "DisplayName" ) ) && dn->text ) |
---|
| 1041 | { |
---|
| 1042 | set_t *set = set_find( &ic->acc->set, "display_name" ); |
---|
| 1043 | g_free( set->value ); |
---|
| 1044 | set->value = g_strdup( dn->text ); |
---|
| 1045 | |
---|
| 1046 | md->flags |= MSN_GOT_PROFILE_DN; |
---|
| 1047 | } |
---|
| 1048 | |
---|
| 1049 | return XT_HANDLED; |
---|
| 1050 | } |
---|
| 1051 | |
---|
| 1052 | static const struct xt_handler_entry msn_soap_profile_get_parser[] = { |
---|
| 1053 | { "ExpressionProfile", "GetProfileResult", msn_soap_profile_get_result }, |
---|
| 1054 | { NULL, NULL, NULL } |
---|
| 1055 | }; |
---|
| 1056 | |
---|
| 1057 | static int msn_soap_profile_get_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 1058 | { |
---|
| 1059 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 1060 | |
---|
| 1061 | md->flags |= MSN_GOT_PROFILE; |
---|
| 1062 | msn_ns_finish_login( soap_req->ic ); |
---|
| 1063 | |
---|
| 1064 | return MSN_SOAP_OK; |
---|
| 1065 | } |
---|
| 1066 | |
---|
| 1067 | static int msn_soap_profile_get_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 1068 | { |
---|
| 1069 | g_free( soap_req->data ); |
---|
| 1070 | return 0; |
---|
| 1071 | } |
---|
| 1072 | |
---|
| 1073 | int msn_soap_profile_get( struct im_connection *ic, const char *cid ) |
---|
| 1074 | { |
---|
| 1075 | return msn_soap_start( ic, g_strdup( cid ), |
---|
| 1076 | msn_soap_profile_get_build_request, |
---|
| 1077 | msn_soap_profile_get_parser, |
---|
| 1078 | msn_soap_profile_get_handle_response, |
---|
| 1079 | msn_soap_profile_get_free_data ); |
---|
| 1080 | } |
---|