[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; |
---|
[9f958f7] | 62 | char *error; |
---|
[e5a8118] | 63 | |
---|
| 64 | char *url, *action, *payload; |
---|
| 65 | struct http_request *http_req; |
---|
| 66 | |
---|
| 67 | const struct xt_handler_entry *xml_parser; |
---|
| 68 | msn_soap_func build_request, handle_response, free_data; |
---|
| 69 | }; |
---|
| 70 | |
---|
| 71 | static int msn_soap_send_request( struct msn_soap_req_data *req ); |
---|
[4e1be76] | 72 | static void msn_soap_free( struct msn_soap_req_data *soap_req ); |
---|
[f2520b5] | 73 | static void msn_soap_debug_print( const char *headers, const char *payload ); |
---|
[e5a8118] | 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 | |
---|
| 84 | req->ic = ic; |
---|
| 85 | req->data = data; |
---|
| 86 | req->xml_parser = xml_parser; |
---|
| 87 | req->build_request = build_request; |
---|
| 88 | req->handle_response = handle_response; |
---|
| 89 | req->free_data = free_data; |
---|
| 90 | 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 ) |
---|
| 98 | { |
---|
| 99 | char *http_req; |
---|
[523fb23] | 100 | char *soap_action = NULL; |
---|
[e5a8118] | 101 | url_t url; |
---|
| 102 | |
---|
| 103 | soap_req->build_request( soap_req ); |
---|
| 104 | |
---|
[523fb23] | 105 | if( soap_req->action ) |
---|
| 106 | soap_action = g_strdup_printf( "SOAPAction: \"%s\"\r\n", soap_req->action ); |
---|
[7db65b7] | 107 | |
---|
[e5a8118] | 108 | url_set( &url, soap_req->url ); |
---|
| 109 | http_req = g_strdup_printf( SOAP_HTTP_REQUEST, url.file, url.host, |
---|
[523fb23] | 110 | soap_action ? soap_action : "", |
---|
[7db65b7] | 111 | strlen( soap_req->payload ), soap_req->payload ); |
---|
[e5a8118] | 112 | |
---|
[f2520b5] | 113 | msn_soap_debug_print( http_req, soap_req->payload ); |
---|
| 114 | |
---|
[e5a8118] | 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 | |
---|
[ffb6dea] | 118 | g_free( http_req ); |
---|
[523fb23] | 119 | g_free( soap_action ); |
---|
[ffb6dea] | 120 | |
---|
[e5a8118] | 121 | return soap_req->http_req != NULL; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | static void msn_soap_handle_response( struct http_request *http_req ) |
---|
| 125 | { |
---|
| 126 | struct msn_soap_req_data *soap_req = http_req->data; |
---|
| 127 | int st; |
---|
| 128 | |
---|
[801b90b] | 129 | if( g_slist_find( msn_connections, soap_req->ic ) == NULL ) |
---|
| 130 | { |
---|
[4e1be76] | 131 | msn_soap_free( soap_req ); |
---|
[801b90b] | 132 | return; |
---|
| 133 | } |
---|
| 134 | |
---|
[27053b5] | 135 | msn_soap_debug_print( http_req->reply_headers, http_req->reply_body ); |
---|
| 136 | |
---|
[e5a8118] | 137 | if( http_req->body_size > 0 ) |
---|
| 138 | { |
---|
| 139 | struct xt_parser *parser; |
---|
[4aa8a04] | 140 | struct xt_node *err; |
---|
[e5a8118] | 141 | |
---|
| 142 | parser = xt_new( soap_req->xml_parser, soap_req ); |
---|
| 143 | xt_feed( parser, http_req->reply_body, http_req->body_size ); |
---|
[4aa8a04] | 144 | if( http_req->status_code == 500 && |
---|
| 145 | ( err = xt_find_path( parser->root, "soap:Body/soap:Fault/detail/errorcode" ) ) && |
---|
[27053b5] | 146 | err->text_len > 0 ) |
---|
[4aa8a04] | 147 | { |
---|
[27053b5] | 148 | if( strcmp( err->text, "PassportAuthFail" ) == 0 ) |
---|
| 149 | { |
---|
| 150 | xt_free( parser ); |
---|
| 151 | st = MSN_SOAP_REAUTH; |
---|
| 152 | goto fail; |
---|
| 153 | } |
---|
| 154 | /* TODO: Handle/report other errors. */ |
---|
[4aa8a04] | 155 | } |
---|
| 156 | |
---|
[e5a8118] | 157 | xt_handle( parser, NULL, -1 ); |
---|
| 158 | xt_free( parser ); |
---|
| 159 | } |
---|
| 160 | |
---|
[9f958f7] | 161 | if( http_req->status_code != 200 ) |
---|
| 162 | soap_req->error = g_strdup( http_req->status_string ); |
---|
| 163 | |
---|
[e5a8118] | 164 | st = soap_req->handle_response( soap_req ); |
---|
[27053b5] | 165 | |
---|
| 166 | fail: |
---|
[ffb6dea] | 167 | g_free( soap_req->url ); |
---|
| 168 | g_free( soap_req->action ); |
---|
| 169 | g_free( soap_req->payload ); |
---|
[9f958f7] | 170 | g_free( soap_req->error ); |
---|
| 171 | soap_req->url = soap_req->action = soap_req->payload = soap_req->error = NULL; |
---|
[ffb6dea] | 172 | |
---|
[e5a8118] | 173 | if( st == MSN_SOAP_RETRY && --soap_req->ttl ) |
---|
[27053b5] | 174 | { |
---|
[e5a8118] | 175 | msn_soap_send_request( soap_req ); |
---|
[27053b5] | 176 | } |
---|
| 177 | else if( st == MSN_SOAP_REAUTH ) |
---|
| 178 | { |
---|
| 179 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 180 | |
---|
| 181 | if( !( md->flags & MSN_REAUTHING ) ) |
---|
| 182 | { |
---|
| 183 | /* Nonce shouldn't actually be touched for re-auths. */ |
---|
| 184 | msn_soap_passport_sso_request( soap_req->ic, "blaataap" ); |
---|
| 185 | md->flags |= MSN_REAUTHING; |
---|
| 186 | } |
---|
| 187 | md->soapq = g_slist_append( md->soapq, soap_req ); |
---|
| 188 | } |
---|
[e5a8118] | 189 | else |
---|
| 190 | { |
---|
| 191 | soap_req->free_data( soap_req ); |
---|
| 192 | g_free( soap_req ); |
---|
| 193 | } |
---|
| 194 | } |
---|
| 195 | |
---|
[6ddb223] | 196 | static char *msn_soap_abservice_build( const char *body_fmt, const char *scenario, const char *ticket, ... ) |
---|
| 197 | { |
---|
| 198 | va_list params; |
---|
| 199 | 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 | |
---|
| 211 | return ret; |
---|
| 212 | } |
---|
| 213 | |
---|
[f2520b5] | 214 | static void msn_soap_debug_print( const char *headers, const char *payload ) |
---|
| 215 | { |
---|
| 216 | char *s; |
---|
| 217 | |
---|
| 218 | if( !getenv( "BITLBEE_DEBUG" ) ) |
---|
| 219 | return; |
---|
| 220 | |
---|
[3bd2f17] | 221 | if( headers ) |
---|
| 222 | { |
---|
| 223 | if( ( s = strstr( headers, "\r\n\r\n" ) ) ) |
---|
[5dc7f90] | 224 | write( 2, headers, s - headers + 4 ); |
---|
[3bd2f17] | 225 | else |
---|
[5dc7f90] | 226 | write( 2, headers, strlen( headers ) ); |
---|
[3bd2f17] | 227 | } |
---|
[f2520b5] | 228 | |
---|
[3bd2f17] | 229 | if( payload ) |
---|
[f2520b5] | 230 | { |
---|
[d0752e8] | 231 | struct xt_node *xt = xt_from_string( payload, 0 ); |
---|
[f2520b5] | 232 | if( xt ) |
---|
| 233 | xt_print( xt ); |
---|
| 234 | xt_free_node( xt ); |
---|
| 235 | } |
---|
| 236 | } |
---|
| 237 | |
---|
[4e1be76] | 238 | int msn_soapq_flush( struct im_connection *ic, gboolean resend ) |
---|
[4aa8a04] | 239 | { |
---|
| 240 | struct msn_data *md = ic->proto_data; |
---|
| 241 | |
---|
| 242 | while( md->soapq ) |
---|
| 243 | { |
---|
[4e1be76] | 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 ); |
---|
[4aa8a04] | 248 | md->soapq = g_slist_remove( md->soapq, md->soapq->data ); |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | return MSN_SOAP_OK; |
---|
| 252 | } |
---|
| 253 | |
---|
[4e1be76] | 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 ); |
---|
[9f958f7] | 260 | g_free( soap_req->error ); |
---|
[4e1be76] | 261 | g_free( soap_req ); |
---|
| 262 | } |
---|
| 263 | |
---|
[bc090f0] | 264 | |
---|
[523fb23] | 265 | /* passport_sso: Authentication MSNP15+ */ |
---|
| 266 | |
---|
| 267 | struct msn_soap_passport_sso_data |
---|
| 268 | { |
---|
| 269 | char *nonce; |
---|
| 270 | char *secret; |
---|
[660cb00] | 271 | char *error; |
---|
[2c6b0f4] | 272 | char *redirect; |
---|
[523fb23] | 273 | }; |
---|
| 274 | |
---|
| 275 | static int msn_soap_passport_sso_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 276 | { |
---|
[2c6b0f4] | 277 | struct msn_soap_passport_sso_data *sd = soap_req->data; |
---|
[523fb23] | 278 | struct im_connection *ic = soap_req->ic; |
---|
[4aa8a04] | 279 | struct msn_data *md = ic->proto_data; |
---|
[2af3e23] | 280 | char pass[MAX_PASSPORT_PWLEN+1]; |
---|
[523fb23] | 281 | |
---|
[2c6b0f4] | 282 | if( sd->redirect ) |
---|
| 283 | { |
---|
| 284 | soap_req->url = sd->redirect; |
---|
| 285 | sd->redirect = NULL; |
---|
| 286 | } |
---|
[5282ffd] | 287 | /* MS changed this URL and broke the old MSN-specific one. The generic |
---|
| 288 | one works, forwarding us to a msn.com URL that works. Takes an extra |
---|
| 289 | second, but that's better than not being able to log in at all. :-/ |
---|
[2c6b0f4] | 290 | else if( g_str_has_suffix( ic->acc->user, "@msn.com" ) ) |
---|
[73efe3a] | 291 | soap_req->url = g_strdup( SOAP_PASSPORT_SSO_URL_MSN ); |
---|
[5282ffd] | 292 | */ |
---|
[02e06b5] | 293 | else |
---|
| 294 | soap_req->url = g_strdup( SOAP_PASSPORT_SSO_URL ); |
---|
[73efe3a] | 295 | |
---|
[2af3e23] | 296 | strncpy( pass, ic->acc->pass, MAX_PASSPORT_PWLEN ); |
---|
[385fbc4] | 297 | pass[MAX_PASSPORT_PWLEN] = '\0'; |
---|
[523fb23] | 298 | soap_req->payload = g_markup_printf_escaped( SOAP_PASSPORT_SSO_PAYLOAD, |
---|
[2af3e23] | 299 | ic->acc->user, pass, md->pp_policy ); |
---|
[523fb23] | 300 | |
---|
| 301 | return MSN_SOAP_OK; |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | static xt_status msn_soap_passport_sso_token( struct xt_node *node, gpointer data ) |
---|
| 305 | { |
---|
| 306 | struct msn_soap_req_data *soap_req = data; |
---|
| 307 | struct msn_soap_passport_sso_data *sd = soap_req->data; |
---|
| 308 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 309 | struct xt_node *p; |
---|
| 310 | char *id; |
---|
| 311 | |
---|
| 312 | if( ( id = xt_find_attr( node, "Id" ) ) == NULL ) |
---|
| 313 | return XT_HANDLED; |
---|
| 314 | id += strlen( id ) - 1; |
---|
| 315 | if( *id == '1' && |
---|
[d97f51b] | 316 | ( p = xt_find_path( node, "../../wst:RequestedProofToken/wst:BinarySecret" ) ) && |
---|
[523fb23] | 317 | p->text ) |
---|
| 318 | sd->secret = g_strdup( p->text ); |
---|
| 319 | |
---|
[91d6e91] | 320 | *id -= '1'; |
---|
[80175a1] | 321 | if( *id >= 0 && *id < sizeof( md->tokens ) / sizeof( md->tokens[0] ) ) |
---|
[91d6e91] | 322 | { |
---|
| 323 | g_free( md->tokens[(int)*id] ); |
---|
| 324 | md->tokens[(int)*id] = g_strdup( node->text ); |
---|
| 325 | } |
---|
[523fb23] | 326 | |
---|
| 327 | return XT_HANDLED; |
---|
| 328 | } |
---|
| 329 | |
---|
[660cb00] | 330 | static xt_status msn_soap_passport_failure( struct xt_node *node, gpointer data ) |
---|
| 331 | { |
---|
| 332 | struct msn_soap_req_data *soap_req = data; |
---|
| 333 | 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" ); |
---|
[2c6b0f4] | 336 | struct xt_node *url; |
---|
[660cb00] | 337 | |
---|
| 338 | if( code == NULL || code->text_len == 0 ) |
---|
| 339 | sd->error = g_strdup( "Unknown error" ); |
---|
[2c6b0f4] | 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 ); |
---|
[660cb00] | 344 | else |
---|
| 345 | sd->error = g_strdup_printf( "%s (%s)", code->text, string && string->text_len ? |
---|
| 346 | string->text : "no description available" ); |
---|
| 347 | |
---|
| 348 | return XT_HANDLED; |
---|
| 349 | } |
---|
| 350 | |
---|
[523fb23] | 351 | static const struct xt_handler_entry msn_soap_passport_sso_parser[] = { |
---|
| 352 | { "wsse:BinarySecurityToken", "wst:RequestedSecurityToken", msn_soap_passport_sso_token }, |
---|
[660cb00] | 353 | { "S:Fault", "S:Envelope", msn_soap_passport_failure }, |
---|
[523fb23] | 354 | { NULL, NULL, NULL } |
---|
| 355 | }; |
---|
| 356 | |
---|
| 357 | static char *msn_key_fuckery( char *key, int key_len, char *type ) |
---|
| 358 | { |
---|
| 359 | unsigned char hash1[20+strlen(type)+1]; |
---|
| 360 | unsigned char hash2[20]; |
---|
| 361 | 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 | |
---|
| 367 | /* 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 ); |
---|
| 374 | return ret; |
---|
| 375 | } |
---|
| 376 | |
---|
| 377 | static int msn_soap_passport_sso_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 378 | { |
---|
| 379 | struct msn_soap_passport_sso_data *sd = soap_req->data; |
---|
| 380 | struct im_connection *ic = soap_req->ic; |
---|
[4aa8a04] | 381 | struct msn_data *md = ic->proto_data; |
---|
[523fb23] | 382 | char *key1, *key2, *key3, *blurb64; |
---|
| 383 | int key1_len; |
---|
| 384 | unsigned char *padnonce, *des3res; |
---|
| 385 | struct |
---|
| 386 | { |
---|
| 387 | unsigned int uStructHeaderSize; // 28. Does not count data |
---|
| 388 | unsigned int uCryptMode; // CRYPT_MODE_CBC (1) |
---|
| 389 | unsigned int uCipherType; // TripleDES (0x6603) |
---|
| 390 | unsigned int uHashType; // SHA1 (0x8004) |
---|
| 391 | unsigned int uIVLen; // 8 |
---|
| 392 | unsigned int uHashLen; // 20 |
---|
| 393 | unsigned int uCipherLen; // 72 |
---|
| 394 | unsigned char iv[8]; |
---|
| 395 | unsigned char hash[20]; |
---|
| 396 | unsigned char cipherbytes[72]; |
---|
| 397 | } 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 ), |
---|
| 405 | }; |
---|
[660cb00] | 406 | |
---|
[2c6b0f4] | 407 | if( sd->redirect ) |
---|
| 408 | return MSN_SOAP_RETRY; |
---|
| 409 | |
---|
[4aa8a04] | 410 | if( md->soapq ) |
---|
[76c89dc7] | 411 | { |
---|
| 412 | md->flags &= ~MSN_REAUTHING; |
---|
[4e1be76] | 413 | return msn_soapq_flush( ic, TRUE ); |
---|
[76c89dc7] | 414 | } |
---|
[4aa8a04] | 415 | |
---|
[660cb00] | 416 | if( sd->secret == NULL ) |
---|
| 417 | { |
---|
[9f958f7] | 418 | msn_auth_got_passport_token( ic, NULL, sd->error ? sd->error : soap_req->error ); |
---|
[660cb00] | 419 | return MSN_SOAP_OK; |
---|
| 420 | } |
---|
[523fb23] | 421 | |
---|
| 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 ) ); |
---|
[660cb00] | 438 | msn_auth_got_passport_token( ic, blurb64, NULL ); |
---|
[523fb23] | 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 ) |
---|
| 451 | { |
---|
| 452 | struct msn_soap_passport_sso_data *sd = soap_req->data; |
---|
| 453 | |
---|
| 454 | g_free( sd->nonce ); |
---|
| 455 | g_free( sd->secret ); |
---|
[660cb00] | 456 | g_free( sd->error ); |
---|
[2c6b0f4] | 457 | g_free( sd->redirect ); |
---|
[c1d40e7] | 458 | g_free( sd ); |
---|
[523fb23] | 459 | |
---|
| 460 | return MSN_SOAP_OK; |
---|
| 461 | } |
---|
| 462 | |
---|
[4aa8a04] | 463 | int msn_soap_passport_sso_request( struct im_connection *ic, const char *nonce ) |
---|
[523fb23] | 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 ); |
---|
| 473 | } |
---|
| 474 | |
---|
| 475 | |
---|
[7db65b7] | 476 | /* memlist: Fetching the membership list (NOT address book) */ |
---|
| 477 | |
---|
| 478 | static int msn_soap_memlist_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 479 | { |
---|
[7f34ce2] | 480 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 481 | |
---|
[7db65b7] | 482 | soap_req->url = g_strdup( SOAP_MEMLIST_URL ); |
---|
| 483 | soap_req->action = g_strdup( SOAP_MEMLIST_ACTION ); |
---|
[6ddb223] | 484 | soap_req->payload = msn_soap_abservice_build( SOAP_MEMLIST_PAYLOAD, "Initial", md->tokens[1] ); |
---|
[7db65b7] | 485 | |
---|
| 486 | return 1; |
---|
| 487 | } |
---|
| 488 | |
---|
[7f34ce2] | 489 | static xt_status msn_soap_memlist_member( struct xt_node *node, gpointer data ) |
---|
| 490 | { |
---|
| 491 | bee_user_t *bu; |
---|
| 492 | struct msn_buddy_data *bd; |
---|
| 493 | struct xt_node *p; |
---|
| 494 | char *role = NULL, *handle = NULL; |
---|
| 495 | struct msn_soap_req_data *soap_req = data; |
---|
| 496 | struct im_connection *ic = soap_req->ic; |
---|
| 497 | |
---|
[d97f51b] | 498 | if( ( p = xt_find_path( node, "../../MemberRole" ) ) ) |
---|
[7f34ce2] | 499 | role = p->text; |
---|
| 500 | |
---|
| 501 | if( ( p = xt_find_node( node->children, "PassportName" ) ) ) |
---|
| 502 | 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 ) ) ) ) |
---|
| 507 | return XT_HANDLED; |
---|
| 508 | |
---|
| 509 | bd = bu->data; |
---|
| 510 | if( strcmp( role, "Allow" ) == 0 ) |
---|
[04cd284] | 511 | { |
---|
[7f34ce2] | 512 | bd->flags |= MSN_BUDDY_AL; |
---|
[04cd284] | 513 | ic->permit = g_slist_prepend( ic->permit, g_strdup( handle ) ); |
---|
| 514 | } |
---|
[7f34ce2] | 515 | else if( strcmp( role, "Block" ) == 0 ) |
---|
[04cd284] | 516 | { |
---|
[7f34ce2] | 517 | bd->flags |= MSN_BUDDY_BL; |
---|
[04cd284] | 518 | ic->deny = g_slist_prepend( ic->deny, g_strdup( handle ) ); |
---|
| 519 | } |
---|
[7f34ce2] | 520 | else if( strcmp( role, "Reverse" ) == 0 ) |
---|
| 521 | bd->flags |= MSN_BUDDY_RL; |
---|
| 522 | else if( strcmp( role, "Pending" ) == 0 ) |
---|
| 523 | bd->flags |= MSN_BUDDY_PL; |
---|
[e5854a8] | 524 | |
---|
[ed86165] | 525 | if( getenv( "BITLBEE_DEBUG" ) ) |
---|
[ca974d7] | 526 | fprintf( stderr, "%p %s %d\n", bu, handle, bd->flags ); |
---|
[7f34ce2] | 527 | |
---|
| 528 | return XT_HANDLED; |
---|
| 529 | } |
---|
| 530 | |
---|
[7db65b7] | 531 | static const struct xt_handler_entry msn_soap_memlist_parser[] = { |
---|
[7f34ce2] | 532 | { "Member", "Members", msn_soap_memlist_member }, |
---|
[7db65b7] | 533 | { NULL, NULL, NULL } |
---|
| 534 | }; |
---|
| 535 | |
---|
| 536 | static int msn_soap_memlist_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 537 | { |
---|
[7f34ce2] | 538 | msn_soap_addressbook_request( soap_req->ic ); |
---|
| 539 | |
---|
| 540 | return MSN_SOAP_OK; |
---|
[7db65b7] | 541 | } |
---|
| 542 | |
---|
| 543 | static int msn_soap_memlist_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 544 | { |
---|
| 545 | return 0; |
---|
| 546 | } |
---|
| 547 | |
---|
| 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 ); |
---|
| 554 | } |
---|
[7f34ce2] | 555 | |
---|
[193dc74] | 556 | /* Variant: Adding/Removing people */ |
---|
| 557 | struct msn_soap_memlist_edit_data |
---|
| 558 | { |
---|
| 559 | char *handle; |
---|
| 560 | gboolean add; |
---|
| 561 | msn_buddy_flags_t list; |
---|
| 562 | }; |
---|
| 563 | |
---|
| 564 | static int msn_soap_memlist_edit_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 565 | { |
---|
| 566 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 567 | struct msn_soap_memlist_edit_data *med = soap_req->data; |
---|
| 568 | 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 ); |
---|
| 574 | add = "Add"; |
---|
| 575 | } |
---|
| 576 | else |
---|
| 577 | { |
---|
| 578 | soap_req->action = g_strdup( SOAP_MEMLIST_DEL_ACTION ); |
---|
| 579 | add = "Delete"; |
---|
| 580 | } |
---|
| 581 | switch( med->list ) |
---|
| 582 | { |
---|
| 583 | case MSN_BUDDY_AL: |
---|
| 584 | scenario = "BlockUnblock"; |
---|
| 585 | list = "Allow"; |
---|
| 586 | break; |
---|
| 587 | case MSN_BUDDY_BL: |
---|
| 588 | scenario = "BlockUnblock"; |
---|
| 589 | list = "Block"; |
---|
| 590 | break; |
---|
| 591 | case MSN_BUDDY_RL: |
---|
| 592 | scenario = "Timer"; |
---|
| 593 | list = "Reverse"; |
---|
| 594 | break; |
---|
| 595 | case MSN_BUDDY_PL: |
---|
| 596 | default: |
---|
| 597 | scenario = "Timer"; |
---|
| 598 | list = "Pending"; |
---|
| 599 | break; |
---|
| 600 | } |
---|
[6ddb223] | 601 | soap_req->payload = msn_soap_abservice_build( SOAP_MEMLIST_EDIT_PAYLOAD, |
---|
[193dc74] | 602 | scenario, md->tokens[1], add, list, med->handle, add ); |
---|
| 603 | |
---|
| 604 | return 1; |
---|
| 605 | } |
---|
| 606 | |
---|
| 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 ) |
---|
| 613 | { |
---|
| 614 | struct msn_soap_memlist_edit_data *med = soap_req->data; |
---|
| 615 | |
---|
| 616 | g_free( med->handle ); |
---|
| 617 | g_free( med ); |
---|
| 618 | |
---|
| 619 | return 0; |
---|
| 620 | } |
---|
| 621 | |
---|
| 622 | int msn_soap_memlist_edit( struct im_connection *ic, const char *handle, gboolean add, int list ) |
---|
| 623 | { |
---|
| 624 | 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 ); |
---|
| 628 | med->add = add; |
---|
| 629 | 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 ); |
---|
| 635 | } |
---|
| 636 | |
---|
[7f34ce2] | 637 | |
---|
| 638 | /* addressbook: Fetching the membership list (NOT address book) */ |
---|
| 639 | |
---|
| 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 ); |
---|
[6ddb223] | 646 | soap_req->payload = msn_soap_abservice_build( SOAP_ADDRESSBOOK_PAYLOAD, "Initial", md->tokens[1] ); |
---|
[7f34ce2] | 647 | |
---|
| 648 | return 1; |
---|
| 649 | } |
---|
| 650 | |
---|
| 651 | static xt_status msn_soap_addressbook_group( struct xt_node *node, gpointer data ) |
---|
| 652 | { |
---|
| 653 | struct xt_node *p; |
---|
| 654 | char *id = NULL, *name = NULL; |
---|
| 655 | struct msn_soap_req_data *soap_req = data; |
---|
[ff27648] | 656 | struct msn_data *md = soap_req->ic->proto_data; |
---|
[7f34ce2] | 657 | |
---|
[d97f51b] | 658 | if( ( p = xt_find_path( node, "../groupId" ) ) ) |
---|
[7f34ce2] | 659 | id = p->text; |
---|
| 660 | |
---|
| 661 | if( ( p = xt_find_node( node->children, "name" ) ) ) |
---|
| 662 | name = p->text; |
---|
| 663 | |
---|
[ff27648] | 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 | |
---|
[ed86165] | 672 | if( getenv( "BITLBEE_DEBUG" ) ) |
---|
[ca974d7] | 673 | fprintf( stderr, "%s %s\n", id, name ); |
---|
[7f34ce2] | 674 | |
---|
| 675 | return XT_HANDLED; |
---|
| 676 | } |
---|
| 677 | |
---|
| 678 | static xt_status msn_soap_addressbook_contact( struct xt_node *node, gpointer data ) |
---|
| 679 | { |
---|
| 680 | bee_user_t *bu; |
---|
| 681 | struct msn_buddy_data *bd; |
---|
| 682 | struct xt_node *p; |
---|
[9b01339] | 683 | char *id = NULL, *type = NULL, *handle = NULL, *is_msgr = "false", |
---|
[ff27648] | 684 | *display_name = NULL, *group_id = NULL; |
---|
[7f34ce2] | 685 | struct msn_soap_req_data *soap_req = data; |
---|
| 686 | struct im_connection *ic = soap_req->ic; |
---|
[ff27648] | 687 | struct msn_group *group; |
---|
[7f34ce2] | 688 | |
---|
[d97f51b] | 689 | if( ( p = xt_find_path( node, "../contactId" ) ) ) |
---|
[7f34ce2] | 690 | id = p->text; |
---|
| 691 | if( ( p = xt_find_node( node->children, "contactType" ) ) ) |
---|
| 692 | type = p->text; |
---|
| 693 | if( ( p = xt_find_node( node->children, "passportName" ) ) ) |
---|
| 694 | handle = p->text; |
---|
| 695 | if( ( p = xt_find_node( node->children, "displayName" ) ) ) |
---|
| 696 | display_name = p->text; |
---|
[9b01339] | 697 | if( ( p = xt_find_node( node->children, "isMessengerUser" ) ) ) |
---|
| 698 | is_msgr = p->text; |
---|
[ff27648] | 699 | if( ( p = xt_find_path( node, "groupIds/guid" ) ) ) |
---|
| 700 | group_id = p->text; |
---|
[7f34ce2] | 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 | |
---|
[80175a1] | 708 | /* Try to fetch the profile; if the user has one, that's where |
---|
| 709 | 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 | |
---|
[7f34ce2] | 713 | return XT_HANDLED; |
---|
| 714 | } |
---|
| 715 | |
---|
[9b01339] | 716 | if( !bool2int( is_msgr ) || handle == NULL ) |
---|
[d97f51b] | 717 | return XT_HANDLED; |
---|
| 718 | |
---|
[7f34ce2] | 719 | if( !( bu = bee_user_by_handle( ic->bee, ic, handle ) ) && |
---|
| 720 | !( bu = bee_user_new( ic->bee, ic, handle, 0 ) ) ) |
---|
| 721 | return XT_HANDLED; |
---|
| 722 | |
---|
| 723 | bd = bu->data; |
---|
| 724 | 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 | |
---|
[ff27648] | 730 | if( group_id && ( group = msn_group_by_id( ic, group_id ) ) ) |
---|
| 731 | imcb_add_buddy( ic, handle, group->name ); |
---|
| 732 | |
---|
[ed86165] | 733 | if( getenv( "BITLBEE_DEBUG" ) ) |
---|
[ca974d7] | 734 | fprintf( stderr, "%s %s %s %s\n", id, type, handle, display_name ); |
---|
[7f34ce2] | 735 | |
---|
| 736 | return XT_HANDLED; |
---|
| 737 | } |
---|
| 738 | |
---|
| 739 | static const struct xt_handler_entry msn_soap_addressbook_parser[] = { |
---|
| 740 | { "contactInfo", "Contact", msn_soap_addressbook_contact }, |
---|
| 741 | { "groupInfo", "Group", msn_soap_addressbook_group }, |
---|
| 742 | { NULL, NULL, NULL } |
---|
| 743 | }; |
---|
| 744 | |
---|
| 745 | static int msn_soap_addressbook_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 746 | { |
---|
[327af51] | 747 | GSList *l; |
---|
[4eb75b2] | 748 | int wtf = 0; |
---|
[327af51] | 749 | |
---|
| 750 | for( l = soap_req->ic->bee->users; l; l = l->next ) |
---|
| 751 | { |
---|
| 752 | struct bee_user *bu = l->data; |
---|
[4eb75b2] | 753 | struct msn_buddy_data *bd = bu->data; |
---|
[327af51] | 754 | |
---|
[d68365c] | 755 | if( bu->ic == soap_req->ic && bd ) |
---|
[4eb75b2] | 756 | { |
---|
[d68365c] | 757 | msn_buddy_ask( bu ); |
---|
| 758 | |
---|
| 759 | if( ( bd->flags & ( MSN_BUDDY_AL | MSN_BUDDY_BL ) ) == |
---|
| 760 | ( MSN_BUDDY_AL | MSN_BUDDY_BL ) ) |
---|
| 761 | { |
---|
| 762 | bd->flags &= ~MSN_BUDDY_BL; |
---|
| 763 | wtf++; |
---|
| 764 | } |
---|
[4eb75b2] | 765 | } |
---|
[327af51] | 766 | } |
---|
| 767 | |
---|
[4eb75b2] | 768 | if( wtf ) |
---|
| 769 | imcb_log( soap_req->ic, "Warning: %d contacts were in both your " |
---|
| 770 | "block and your allow list. Assuming they're all " |
---|
| 771 | "allowed. Use the official WLM client once to fix " |
---|
| 772 | "this.", wtf ); |
---|
| 773 | |
---|
[ca7de3a] | 774 | msn_auth_got_contact_list( soap_req->ic ); |
---|
[327af51] | 775 | |
---|
[7f34ce2] | 776 | return MSN_SOAP_OK; |
---|
| 777 | } |
---|
| 778 | |
---|
| 779 | static int msn_soap_addressbook_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 780 | { |
---|
| 781 | return 0; |
---|
| 782 | } |
---|
| 783 | |
---|
| 784 | int msn_soap_addressbook_request( struct im_connection *ic ) |
---|
| 785 | { |
---|
| 786 | return msn_soap_start( ic, NULL, msn_soap_addressbook_build_request, |
---|
| 787 | msn_soap_addressbook_parser, |
---|
| 788 | msn_soap_addressbook_handle_response, |
---|
| 789 | msn_soap_addressbook_free_data ); |
---|
| 790 | } |
---|
[4452e69] | 791 | |
---|
| 792 | /* Variant: Change our display name. */ |
---|
| 793 | static int msn_soap_ab_namechange_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 794 | { |
---|
| 795 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 796 | |
---|
| 797 | soap_req->url = g_strdup( SOAP_ADDRESSBOOK_URL ); |
---|
| 798 | soap_req->action = g_strdup( SOAP_AB_NAMECHANGE_ACTION ); |
---|
[6ddb223] | 799 | soap_req->payload = msn_soap_abservice_build( SOAP_AB_NAMECHANGE_PAYLOAD, |
---|
[e0e1546] | 800 | "Timer", md->tokens[1], (char *) soap_req->data ); |
---|
[4452e69] | 801 | |
---|
| 802 | return 1; |
---|
| 803 | } |
---|
| 804 | |
---|
| 805 | static int msn_soap_ab_namechange_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 806 | { |
---|
| 807 | /* TODO: Ack the change? Not sure what the NAKs look like.. */ |
---|
| 808 | return MSN_SOAP_OK; |
---|
| 809 | } |
---|
| 810 | |
---|
| 811 | static int msn_soap_ab_namechange_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 812 | { |
---|
| 813 | g_free( soap_req->data ); |
---|
| 814 | return 0; |
---|
| 815 | } |
---|
| 816 | |
---|
| 817 | int msn_soap_addressbook_set_display_name( struct im_connection *ic, const char *new ) |
---|
| 818 | { |
---|
| 819 | return msn_soap_start( ic, g_strdup( new ), |
---|
| 820 | msn_soap_ab_namechange_build_request, |
---|
| 821 | NULL, |
---|
| 822 | msn_soap_ab_namechange_handle_response, |
---|
| 823 | msn_soap_ab_namechange_free_data ); |
---|
| 824 | } |
---|
[4fc95c5] | 825 | |
---|
| 826 | /* Add a contact. */ |
---|
| 827 | static int msn_soap_ab_contact_add_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 828 | { |
---|
| 829 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 830 | bee_user_t *bu = soap_req->data; |
---|
| 831 | |
---|
| 832 | soap_req->url = g_strdup( SOAP_ADDRESSBOOK_URL ); |
---|
| 833 | soap_req->action = g_strdup( SOAP_AB_CONTACT_ADD_ACTION ); |
---|
| 834 | soap_req->payload = msn_soap_abservice_build( SOAP_AB_CONTACT_ADD_PAYLOAD, |
---|
| 835 | "ContactSave", md->tokens[1], bu->handle, bu->fullname ? bu->fullname : bu->handle ); |
---|
| 836 | |
---|
| 837 | return 1; |
---|
| 838 | } |
---|
| 839 | |
---|
| 840 | static xt_status msn_soap_ab_contact_add_cid( struct xt_node *node, gpointer data ) |
---|
| 841 | { |
---|
| 842 | struct msn_soap_req_data *soap_req = data; |
---|
| 843 | bee_user_t *bu = soap_req->data; |
---|
| 844 | struct msn_buddy_data *bd = bu->data; |
---|
| 845 | |
---|
| 846 | g_free( bd->cid ); |
---|
| 847 | bd->cid = g_strdup( node->text ); |
---|
| 848 | |
---|
| 849 | return XT_HANDLED; |
---|
| 850 | } |
---|
| 851 | |
---|
| 852 | static const struct xt_handler_entry msn_soap_ab_contact_add_parser[] = { |
---|
| 853 | { "guid", "ABContactAddResult", msn_soap_ab_contact_add_cid }, |
---|
| 854 | { NULL, NULL, NULL } |
---|
| 855 | }; |
---|
| 856 | |
---|
| 857 | static int msn_soap_ab_contact_add_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 858 | { |
---|
| 859 | /* TODO: Ack the change? Not sure what the NAKs look like.. */ |
---|
| 860 | return MSN_SOAP_OK; |
---|
| 861 | } |
---|
| 862 | |
---|
| 863 | static int msn_soap_ab_contact_add_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 864 | { |
---|
| 865 | return 0; |
---|
| 866 | } |
---|
| 867 | |
---|
| 868 | int msn_soap_ab_contact_add( struct im_connection *ic, bee_user_t *bu ) |
---|
| 869 | { |
---|
| 870 | return msn_soap_start( ic, bu, |
---|
| 871 | msn_soap_ab_contact_add_build_request, |
---|
| 872 | msn_soap_ab_contact_add_parser, |
---|
| 873 | msn_soap_ab_contact_add_handle_response, |
---|
| 874 | msn_soap_ab_contact_add_free_data ); |
---|
| 875 | } |
---|
| 876 | |
---|
| 877 | /* Remove a contact. */ |
---|
| 878 | static int msn_soap_ab_contact_del_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 879 | { |
---|
| 880 | struct msn_data *md = soap_req->ic->proto_data; |
---|
[52f5e90] | 881 | const char *cid = soap_req->data; |
---|
[4fc95c5] | 882 | |
---|
| 883 | soap_req->url = g_strdup( SOAP_ADDRESSBOOK_URL ); |
---|
| 884 | soap_req->action = g_strdup( SOAP_AB_CONTACT_DEL_ACTION ); |
---|
| 885 | soap_req->payload = msn_soap_abservice_build( SOAP_AB_CONTACT_DEL_PAYLOAD, |
---|
[52f5e90] | 886 | "Timer", md->tokens[1], cid ); |
---|
[4fc95c5] | 887 | |
---|
| 888 | return 1; |
---|
| 889 | } |
---|
| 890 | |
---|
| 891 | static int msn_soap_ab_contact_del_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 892 | { |
---|
| 893 | /* TODO: Ack the change? Not sure what the NAKs look like.. */ |
---|
| 894 | return MSN_SOAP_OK; |
---|
| 895 | } |
---|
| 896 | |
---|
| 897 | static int msn_soap_ab_contact_del_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 898 | { |
---|
[52f5e90] | 899 | g_free( soap_req->data ); |
---|
[4fc95c5] | 900 | return 0; |
---|
| 901 | } |
---|
| 902 | |
---|
| 903 | int msn_soap_ab_contact_del( struct im_connection *ic, bee_user_t *bu ) |
---|
| 904 | { |
---|
[52f5e90] | 905 | struct msn_buddy_data *bd = bu->data; |
---|
| 906 | |
---|
| 907 | return msn_soap_start( ic, g_strdup( bd->cid ), |
---|
[4fc95c5] | 908 | msn_soap_ab_contact_del_build_request, |
---|
| 909 | NULL, |
---|
| 910 | msn_soap_ab_contact_del_handle_response, |
---|
| 911 | msn_soap_ab_contact_del_free_data ); |
---|
| 912 | } |
---|
[80175a1] | 913 | |
---|
| 914 | |
---|
| 915 | |
---|
| 916 | /* Storage stuff: Fetch profile. */ |
---|
| 917 | static int msn_soap_profile_get_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 918 | { |
---|
| 919 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 920 | |
---|
| 921 | soap_req->url = g_strdup( SOAP_STORAGE_URL ); |
---|
| 922 | soap_req->action = g_strdup( SOAP_PROFILE_GET_ACTION ); |
---|
| 923 | soap_req->payload = g_markup_printf_escaped( SOAP_PROFILE_GET_PAYLOAD, |
---|
| 924 | md->tokens[3], (char*) soap_req->data ); |
---|
| 925 | |
---|
| 926 | return 1; |
---|
| 927 | } |
---|
| 928 | |
---|
| 929 | static xt_status msn_soap_profile_get_result( struct xt_node *node, gpointer data ) |
---|
| 930 | { |
---|
| 931 | struct msn_soap_req_data *soap_req = data; |
---|
| 932 | struct im_connection *ic = soap_req->ic; |
---|
| 933 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 934 | struct xt_node *dn; |
---|
| 935 | |
---|
| 936 | if( ( dn = xt_find_node( node->children, "DisplayName" ) ) && dn->text ) |
---|
| 937 | { |
---|
| 938 | set_t *set = set_find( &ic->acc->set, "display_name" ); |
---|
| 939 | g_free( set->value ); |
---|
| 940 | set->value = g_strdup( dn->text ); |
---|
| 941 | |
---|
| 942 | md->flags |= MSN_GOT_PROFILE_DN; |
---|
| 943 | } |
---|
| 944 | |
---|
| 945 | return XT_HANDLED; |
---|
| 946 | } |
---|
| 947 | |
---|
[76c89dc7] | 948 | static xt_status msn_soap_profile_get_rid( struct xt_node *node, gpointer data ) |
---|
| 949 | { |
---|
| 950 | struct msn_soap_req_data *soap_req = data; |
---|
| 951 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 952 | |
---|
| 953 | g_free( md->profile_rid ); |
---|
| 954 | md->profile_rid = g_strdup( node->text ); |
---|
| 955 | |
---|
| 956 | return XT_HANDLED; |
---|
| 957 | } |
---|
| 958 | |
---|
[80175a1] | 959 | static const struct xt_handler_entry msn_soap_profile_get_parser[] = { |
---|
| 960 | { "ExpressionProfile", "GetProfileResult", msn_soap_profile_get_result }, |
---|
[76c89dc7] | 961 | { "ResourceID", "GetProfileResult", msn_soap_profile_get_rid }, |
---|
[80175a1] | 962 | { NULL, NULL, NULL } |
---|
| 963 | }; |
---|
| 964 | |
---|
| 965 | static int msn_soap_profile_get_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 966 | { |
---|
| 967 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 968 | |
---|
| 969 | md->flags |= MSN_GOT_PROFILE; |
---|
| 970 | msn_ns_finish_login( soap_req->ic ); |
---|
| 971 | |
---|
| 972 | return MSN_SOAP_OK; |
---|
| 973 | } |
---|
| 974 | |
---|
| 975 | static int msn_soap_profile_get_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 976 | { |
---|
| 977 | g_free( soap_req->data ); |
---|
| 978 | return 0; |
---|
| 979 | } |
---|
| 980 | |
---|
| 981 | int msn_soap_profile_get( struct im_connection *ic, const char *cid ) |
---|
| 982 | { |
---|
| 983 | return msn_soap_start( ic, g_strdup( cid ), |
---|
| 984 | msn_soap_profile_get_build_request, |
---|
| 985 | msn_soap_profile_get_parser, |
---|
| 986 | msn_soap_profile_get_handle_response, |
---|
| 987 | msn_soap_profile_get_free_data ); |
---|
| 988 | } |
---|
[76c89dc7] | 989 | |
---|
| 990 | /* Update profile (display name). */ |
---|
| 991 | static int msn_soap_profile_set_dn_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 992 | { |
---|
| 993 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 994 | |
---|
| 995 | soap_req->url = g_strdup( SOAP_STORAGE_URL ); |
---|
| 996 | soap_req->action = g_strdup( SOAP_PROFILE_SET_DN_ACTION ); |
---|
| 997 | soap_req->payload = g_markup_printf_escaped( SOAP_PROFILE_SET_DN_PAYLOAD, |
---|
| 998 | md->tokens[3], md->profile_rid, (char*) soap_req->data ); |
---|
| 999 | |
---|
| 1000 | return 1; |
---|
| 1001 | } |
---|
| 1002 | |
---|
| 1003 | static const struct xt_handler_entry msn_soap_profile_set_dn_parser[] = { |
---|
| 1004 | { NULL, NULL, NULL } |
---|
| 1005 | }; |
---|
| 1006 | |
---|
| 1007 | static int msn_soap_profile_set_dn_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 1008 | { |
---|
| 1009 | return MSN_SOAP_OK; |
---|
| 1010 | } |
---|
| 1011 | |
---|
| 1012 | static int msn_soap_profile_set_dn_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 1013 | { |
---|
| 1014 | g_free( soap_req->data ); |
---|
| 1015 | return 0; |
---|
| 1016 | } |
---|
| 1017 | |
---|
| 1018 | int msn_soap_profile_set_dn( struct im_connection *ic, const char *dn ) |
---|
| 1019 | { |
---|
| 1020 | return msn_soap_start( ic, g_strdup( dn ), |
---|
| 1021 | msn_soap_profile_set_dn_build_request, |
---|
| 1022 | msn_soap_profile_set_dn_parser, |
---|
| 1023 | msn_soap_profile_set_dn_handle_response, |
---|
| 1024 | msn_soap_profile_set_dn_free_data ); |
---|
| 1025 | } |
---|