[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 | { |
---|
| 231 | struct xt_node *xt = xt_from_string( payload ); |
---|
| 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 | |
---|
[bc090f0] | 476 | /* oim_send: Sending offline messages */ |
---|
| 477 | |
---|
| 478 | struct msn_soap_oim_send_data |
---|
| 479 | { |
---|
| 480 | char *to; |
---|
| 481 | char *msg; |
---|
| 482 | int number; |
---|
[27053b5] | 483 | msn_soap_result_t need_retry; |
---|
[bc090f0] | 484 | }; |
---|
| 485 | |
---|
[e5a8118] | 486 | static int msn_soap_oim_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 487 | { |
---|
| 488 | struct msn_soap_oim_send_data *oim = soap_req->data; |
---|
| 489 | struct im_connection *ic = soap_req->ic; |
---|
| 490 | struct msn_data *md = ic->proto_data; |
---|
| 491 | char *display_name_b64; |
---|
| 492 | |
---|
[91d6e91] | 493 | display_name_b64 = tobase64( set_getstr( &ic->acc->set, "display_name" ) ); |
---|
[e5a8118] | 494 | |
---|
| 495 | soap_req->url = g_strdup( SOAP_OIM_SEND_URL ); |
---|
[7db65b7] | 496 | soap_req->action = g_strdup( SOAP_OIM_SEND_ACTION ); |
---|
[e5a8118] | 497 | soap_req->payload = g_markup_printf_escaped( SOAP_OIM_SEND_PAYLOAD, |
---|
[91d6e91] | 498 | ic->acc->user, display_name_b64, MSNP_VER, MSNP_BUILD, |
---|
| 499 | oim->to, md->tokens[2], |
---|
[5fecede] | 500 | MSNP11_PROD_ID, md->lock_key ? md->lock_key : "", |
---|
| 501 | oim->number, oim->number, oim->msg ); |
---|
[e5a8118] | 502 | |
---|
| 503 | g_free( display_name_b64 ); |
---|
[27053b5] | 504 | oim->need_retry = MSN_SOAP_OK; |
---|
[e5a8118] | 505 | |
---|
[523fb23] | 506 | return MSN_SOAP_OK; |
---|
[e5a8118] | 507 | } |
---|
| 508 | |
---|
[27053b5] | 509 | static xt_status msn_soap_oim_reauth( struct xt_node *node, gpointer data ) |
---|
[e5a8118] | 510 | { |
---|
| 511 | struct msn_soap_req_data *soap_req = data; |
---|
| 512 | struct msn_soap_oim_send_data *oim = soap_req->data; |
---|
| 513 | struct im_connection *ic = soap_req->ic; |
---|
| 514 | struct msn_data *md = ic->proto_data; |
---|
[27053b5] | 515 | struct xt_node *c; |
---|
[e5a8118] | 516 | |
---|
[27053b5] | 517 | if( ( c = xt_find_node( node->children, "LockKeyChallenge" ) ) && c->text_len > 0 ) |
---|
| 518 | { |
---|
| 519 | g_free( md->lock_key ); |
---|
| 520 | md->lock_key = msn_p11_challenge( c->text ); |
---|
| 521 | oim->need_retry = MSN_SOAP_RETRY; |
---|
| 522 | } |
---|
| 523 | if( xt_find_node( node->children, "RequiredAuthPolicy" ) ) |
---|
| 524 | { |
---|
| 525 | oim->need_retry = MSN_SOAP_REAUTH; |
---|
| 526 | } |
---|
[e5a8118] | 527 | |
---|
| 528 | return XT_HANDLED; |
---|
| 529 | } |
---|
| 530 | |
---|
| 531 | static const struct xt_handler_entry msn_soap_oim_send_parser[] = { |
---|
[27053b5] | 532 | { "detail", "soap:Fault", msn_soap_oim_reauth }, |
---|
| 533 | { NULL, NULL, NULL } |
---|
[e5a8118] | 534 | }; |
---|
| 535 | |
---|
| 536 | static int msn_soap_oim_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 537 | { |
---|
| 538 | struct msn_soap_oim_send_data *oim = soap_req->data; |
---|
| 539 | |
---|
[bc090f0] | 540 | if( soap_req->http_req->status_code == 500 && oim->need_retry && soap_req->ttl > 0 ) |
---|
[e5a8118] | 541 | { |
---|
[27053b5] | 542 | return oim->need_retry; |
---|
[e5a8118] | 543 | } |
---|
| 544 | else if( soap_req->http_req->status_code == 200 ) |
---|
[bc090f0] | 545 | { |
---|
[8a35d4b] | 546 | /* Noise.. |
---|
[bc090f0] | 547 | imcb_log( soap_req->ic, "Offline message successfully delivered to %s", oim->to ); |
---|
[8a35d4b] | 548 | */ |
---|
[e5a8118] | 549 | return MSN_SOAP_OK; |
---|
[bc090f0] | 550 | } |
---|
[e5a8118] | 551 | else |
---|
[bc090f0] | 552 | { |
---|
[8a35d4b] | 553 | char *dec = frombase64( oim->msg ); |
---|
| 554 | imcb_log( soap_req->ic, "Failed to deliver offline message to %s:\n%s", oim->to, dec ); |
---|
| 555 | g_free( dec ); |
---|
[e5a8118] | 556 | return MSN_SOAP_ABORT; |
---|
[bc090f0] | 557 | } |
---|
[e5a8118] | 558 | } |
---|
| 559 | |
---|
| 560 | static int msn_soap_oim_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 561 | { |
---|
| 562 | struct msn_soap_oim_send_data *oim = soap_req->data; |
---|
| 563 | |
---|
| 564 | g_free( oim->to ); |
---|
| 565 | g_free( oim->msg ); |
---|
| 566 | g_free( oim ); |
---|
| 567 | |
---|
[523fb23] | 568 | return MSN_SOAP_OK; |
---|
[e5a8118] | 569 | } |
---|
| 570 | |
---|
| 571 | int msn_soap_oim_send( struct im_connection *ic, const char *to, const char *msg ) |
---|
| 572 | { |
---|
| 573 | struct msn_soap_oim_send_data *data; |
---|
| 574 | |
---|
[8eec79d] | 575 | /* Don't send any of the special messages since they creep people out. :-) */ |
---|
| 576 | if( strncmp( msg, "\r\r", 2 ) == 0 ) |
---|
| 577 | return 0; |
---|
| 578 | |
---|
[e5a8118] | 579 | data = g_new0( struct msn_soap_oim_send_data, 1 ); |
---|
| 580 | data->to = g_strdup( to ); |
---|
| 581 | data->msg = tobase64( msg ); |
---|
| 582 | data->number = 1; |
---|
| 583 | |
---|
| 584 | return msn_soap_start( ic, data, msn_soap_oim_build_request, |
---|
| 585 | msn_soap_oim_send_parser, |
---|
| 586 | msn_soap_oim_handle_response, |
---|
| 587 | msn_soap_oim_free_data ); |
---|
| 588 | } |
---|
[bc090f0] | 589 | |
---|
| 590 | int msn_soap_oim_send_queue( struct im_connection *ic, GSList **msgq ) |
---|
| 591 | { |
---|
| 592 | GSList *l; |
---|
| 593 | char *n = NULL; |
---|
| 594 | |
---|
| 595 | for( l = *msgq; l; l = l->next ) |
---|
| 596 | { |
---|
| 597 | struct msn_message *m = l->data; |
---|
| 598 | |
---|
| 599 | if( n == NULL ) |
---|
| 600 | n = m->who; |
---|
| 601 | if( strcmp( n, m->who ) == 0 ) |
---|
| 602 | msn_soap_oim_send( ic, m->who, m->text ); |
---|
| 603 | } |
---|
| 604 | |
---|
| 605 | while( *msgq != NULL ) |
---|
| 606 | { |
---|
| 607 | struct msn_message *m = (*msgq)->data; |
---|
| 608 | |
---|
| 609 | g_free( m->who ); |
---|
| 610 | g_free( m->text ); |
---|
| 611 | g_free( m ); |
---|
| 612 | |
---|
| 613 | *msgq = g_slist_remove( *msgq, m ); |
---|
| 614 | } |
---|
[523fb23] | 615 | |
---|
| 616 | return 1; |
---|
[bc090f0] | 617 | } |
---|
[7db65b7] | 618 | |
---|
| 619 | |
---|
| 620 | /* memlist: Fetching the membership list (NOT address book) */ |
---|
| 621 | |
---|
| 622 | static int msn_soap_memlist_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 623 | { |
---|
[7f34ce2] | 624 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 625 | |
---|
[7db65b7] | 626 | soap_req->url = g_strdup( SOAP_MEMLIST_URL ); |
---|
| 627 | soap_req->action = g_strdup( SOAP_MEMLIST_ACTION ); |
---|
[6ddb223] | 628 | soap_req->payload = msn_soap_abservice_build( SOAP_MEMLIST_PAYLOAD, "Initial", md->tokens[1] ); |
---|
[7db65b7] | 629 | |
---|
| 630 | return 1; |
---|
| 631 | } |
---|
| 632 | |
---|
[7f34ce2] | 633 | static xt_status msn_soap_memlist_member( struct xt_node *node, gpointer data ) |
---|
| 634 | { |
---|
| 635 | bee_user_t *bu; |
---|
| 636 | struct msn_buddy_data *bd; |
---|
| 637 | struct xt_node *p; |
---|
| 638 | char *role = NULL, *handle = NULL; |
---|
| 639 | struct msn_soap_req_data *soap_req = data; |
---|
| 640 | struct im_connection *ic = soap_req->ic; |
---|
| 641 | |
---|
[d97f51b] | 642 | if( ( p = xt_find_path( node, "../../MemberRole" ) ) ) |
---|
[7f34ce2] | 643 | role = p->text; |
---|
| 644 | |
---|
| 645 | if( ( p = xt_find_node( node->children, "PassportName" ) ) ) |
---|
| 646 | handle = p->text; |
---|
| 647 | |
---|
| 648 | if( !role || !handle || |
---|
| 649 | !( ( bu = bee_user_by_handle( ic->bee, ic, handle ) ) || |
---|
| 650 | ( bu = bee_user_new( ic->bee, ic, handle, 0 ) ) ) ) |
---|
| 651 | return XT_HANDLED; |
---|
| 652 | |
---|
| 653 | bd = bu->data; |
---|
| 654 | if( strcmp( role, "Allow" ) == 0 ) |
---|
[04cd284] | 655 | { |
---|
[7f34ce2] | 656 | bd->flags |= MSN_BUDDY_AL; |
---|
[04cd284] | 657 | ic->permit = g_slist_prepend( ic->permit, g_strdup( handle ) ); |
---|
| 658 | } |
---|
[7f34ce2] | 659 | else if( strcmp( role, "Block" ) == 0 ) |
---|
[04cd284] | 660 | { |
---|
[7f34ce2] | 661 | bd->flags |= MSN_BUDDY_BL; |
---|
[04cd284] | 662 | ic->deny = g_slist_prepend( ic->deny, g_strdup( handle ) ); |
---|
| 663 | } |
---|
[7f34ce2] | 664 | else if( strcmp( role, "Reverse" ) == 0 ) |
---|
| 665 | bd->flags |= MSN_BUDDY_RL; |
---|
| 666 | else if( strcmp( role, "Pending" ) == 0 ) |
---|
| 667 | bd->flags |= MSN_BUDDY_PL; |
---|
[e5854a8] | 668 | |
---|
[ed86165] | 669 | if( getenv( "BITLBEE_DEBUG" ) ) |
---|
[ca974d7] | 670 | fprintf( stderr, "%p %s %d\n", bu, handle, bd->flags ); |
---|
[7f34ce2] | 671 | |
---|
| 672 | return XT_HANDLED; |
---|
| 673 | } |
---|
| 674 | |
---|
[7db65b7] | 675 | static const struct xt_handler_entry msn_soap_memlist_parser[] = { |
---|
[7f34ce2] | 676 | { "Member", "Members", msn_soap_memlist_member }, |
---|
[7db65b7] | 677 | { NULL, NULL, NULL } |
---|
| 678 | }; |
---|
| 679 | |
---|
| 680 | static int msn_soap_memlist_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 681 | { |
---|
[7f34ce2] | 682 | msn_soap_addressbook_request( soap_req->ic ); |
---|
| 683 | |
---|
| 684 | return MSN_SOAP_OK; |
---|
[7db65b7] | 685 | } |
---|
| 686 | |
---|
| 687 | static int msn_soap_memlist_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 688 | { |
---|
| 689 | return 0; |
---|
| 690 | } |
---|
| 691 | |
---|
| 692 | int msn_soap_memlist_request( struct im_connection *ic ) |
---|
| 693 | { |
---|
| 694 | return msn_soap_start( ic, NULL, msn_soap_memlist_build_request, |
---|
| 695 | msn_soap_memlist_parser, |
---|
| 696 | msn_soap_memlist_handle_response, |
---|
| 697 | msn_soap_memlist_free_data ); |
---|
| 698 | } |
---|
[7f34ce2] | 699 | |
---|
[193dc74] | 700 | /* Variant: Adding/Removing people */ |
---|
| 701 | struct msn_soap_memlist_edit_data |
---|
| 702 | { |
---|
| 703 | char *handle; |
---|
| 704 | gboolean add; |
---|
| 705 | msn_buddy_flags_t list; |
---|
| 706 | }; |
---|
| 707 | |
---|
| 708 | static int msn_soap_memlist_edit_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 709 | { |
---|
| 710 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 711 | struct msn_soap_memlist_edit_data *med = soap_req->data; |
---|
| 712 | char *add, *scenario, *list; |
---|
| 713 | |
---|
| 714 | soap_req->url = g_strdup( SOAP_MEMLIST_URL ); |
---|
| 715 | if( med->add ) |
---|
| 716 | { |
---|
| 717 | soap_req->action = g_strdup( SOAP_MEMLIST_ADD_ACTION ); |
---|
| 718 | add = "Add"; |
---|
| 719 | } |
---|
| 720 | else |
---|
| 721 | { |
---|
| 722 | soap_req->action = g_strdup( SOAP_MEMLIST_DEL_ACTION ); |
---|
| 723 | add = "Delete"; |
---|
| 724 | } |
---|
| 725 | switch( med->list ) |
---|
| 726 | { |
---|
| 727 | case MSN_BUDDY_AL: |
---|
| 728 | scenario = "BlockUnblock"; |
---|
| 729 | list = "Allow"; |
---|
| 730 | break; |
---|
| 731 | case MSN_BUDDY_BL: |
---|
| 732 | scenario = "BlockUnblock"; |
---|
| 733 | list = "Block"; |
---|
| 734 | break; |
---|
| 735 | case MSN_BUDDY_RL: |
---|
| 736 | scenario = "Timer"; |
---|
| 737 | list = "Reverse"; |
---|
| 738 | break; |
---|
| 739 | case MSN_BUDDY_PL: |
---|
| 740 | default: |
---|
| 741 | scenario = "Timer"; |
---|
| 742 | list = "Pending"; |
---|
| 743 | break; |
---|
| 744 | } |
---|
[6ddb223] | 745 | soap_req->payload = msn_soap_abservice_build( SOAP_MEMLIST_EDIT_PAYLOAD, |
---|
[193dc74] | 746 | scenario, md->tokens[1], add, list, med->handle, add ); |
---|
| 747 | |
---|
| 748 | return 1; |
---|
| 749 | } |
---|
| 750 | |
---|
| 751 | static int msn_soap_memlist_edit_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 752 | { |
---|
| 753 | return MSN_SOAP_OK; |
---|
| 754 | } |
---|
| 755 | |
---|
| 756 | static int msn_soap_memlist_edit_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 757 | { |
---|
| 758 | struct msn_soap_memlist_edit_data *med = soap_req->data; |
---|
| 759 | |
---|
| 760 | g_free( med->handle ); |
---|
| 761 | g_free( med ); |
---|
| 762 | |
---|
| 763 | return 0; |
---|
| 764 | } |
---|
| 765 | |
---|
| 766 | int msn_soap_memlist_edit( struct im_connection *ic, const char *handle, gboolean add, int list ) |
---|
| 767 | { |
---|
| 768 | struct msn_soap_memlist_edit_data *med; |
---|
| 769 | |
---|
| 770 | med = g_new0( struct msn_soap_memlist_edit_data, 1 ); |
---|
| 771 | med->handle = g_strdup( handle ); |
---|
| 772 | med->add = add; |
---|
| 773 | med->list = list; |
---|
| 774 | |
---|
| 775 | return msn_soap_start( ic, med, msn_soap_memlist_edit_build_request, |
---|
| 776 | NULL, |
---|
| 777 | msn_soap_memlist_edit_handle_response, |
---|
| 778 | msn_soap_memlist_edit_free_data ); |
---|
| 779 | } |
---|
| 780 | |
---|
[7f34ce2] | 781 | |
---|
| 782 | /* addressbook: Fetching the membership list (NOT address book) */ |
---|
| 783 | |
---|
| 784 | static int msn_soap_addressbook_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 785 | { |
---|
| 786 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 787 | |
---|
| 788 | soap_req->url = g_strdup( SOAP_ADDRESSBOOK_URL ); |
---|
| 789 | soap_req->action = g_strdup( SOAP_ADDRESSBOOK_ACTION ); |
---|
[6ddb223] | 790 | soap_req->payload = msn_soap_abservice_build( SOAP_ADDRESSBOOK_PAYLOAD, "Initial", md->tokens[1] ); |
---|
[7f34ce2] | 791 | |
---|
| 792 | return 1; |
---|
| 793 | } |
---|
| 794 | |
---|
| 795 | static xt_status msn_soap_addressbook_group( struct xt_node *node, gpointer data ) |
---|
| 796 | { |
---|
| 797 | struct xt_node *p; |
---|
| 798 | char *id = NULL, *name = NULL; |
---|
| 799 | struct msn_soap_req_data *soap_req = data; |
---|
[ff27648] | 800 | struct msn_data *md = soap_req->ic->proto_data; |
---|
[7f34ce2] | 801 | |
---|
[d97f51b] | 802 | if( ( p = xt_find_path( node, "../groupId" ) ) ) |
---|
[7f34ce2] | 803 | id = p->text; |
---|
| 804 | |
---|
| 805 | if( ( p = xt_find_node( node->children, "name" ) ) ) |
---|
| 806 | name = p->text; |
---|
| 807 | |
---|
[ff27648] | 808 | if( id && name ) |
---|
| 809 | { |
---|
| 810 | struct msn_group *mg = g_new0( struct msn_group, 1 ); |
---|
| 811 | mg->id = g_strdup( id ); |
---|
| 812 | mg->name = g_strdup( name ); |
---|
| 813 | md->groups = g_slist_prepend( md->groups, mg ); |
---|
| 814 | } |
---|
| 815 | |
---|
[ed86165] | 816 | if( getenv( "BITLBEE_DEBUG" ) ) |
---|
[ca974d7] | 817 | fprintf( stderr, "%s %s\n", id, name ); |
---|
[7f34ce2] | 818 | |
---|
| 819 | return XT_HANDLED; |
---|
| 820 | } |
---|
| 821 | |
---|
| 822 | static xt_status msn_soap_addressbook_contact( struct xt_node *node, gpointer data ) |
---|
| 823 | { |
---|
| 824 | bee_user_t *bu; |
---|
| 825 | struct msn_buddy_data *bd; |
---|
| 826 | struct xt_node *p; |
---|
[9b01339] | 827 | char *id = NULL, *type = NULL, *handle = NULL, *is_msgr = "false", |
---|
[ff27648] | 828 | *display_name = NULL, *group_id = NULL; |
---|
[7f34ce2] | 829 | struct msn_soap_req_data *soap_req = data; |
---|
| 830 | struct im_connection *ic = soap_req->ic; |
---|
[ff27648] | 831 | struct msn_group *group; |
---|
[7f34ce2] | 832 | |
---|
[d97f51b] | 833 | if( ( p = xt_find_path( node, "../contactId" ) ) ) |
---|
[7f34ce2] | 834 | id = p->text; |
---|
| 835 | if( ( p = xt_find_node( node->children, "contactType" ) ) ) |
---|
| 836 | type = p->text; |
---|
| 837 | if( ( p = xt_find_node( node->children, "passportName" ) ) ) |
---|
| 838 | handle = p->text; |
---|
| 839 | if( ( p = xt_find_node( node->children, "displayName" ) ) ) |
---|
| 840 | display_name = p->text; |
---|
[9b01339] | 841 | if( ( p = xt_find_node( node->children, "isMessengerUser" ) ) ) |
---|
| 842 | is_msgr = p->text; |
---|
[ff27648] | 843 | if( ( p = xt_find_path( node, "groupIds/guid" ) ) ) |
---|
| 844 | group_id = p->text; |
---|
[7f34ce2] | 845 | |
---|
| 846 | if( type && g_strcasecmp( type, "me" ) == 0 ) |
---|
| 847 | { |
---|
| 848 | set_t *set = set_find( &ic->acc->set, "display_name" ); |
---|
| 849 | g_free( set->value ); |
---|
| 850 | set->value = g_strdup( display_name ); |
---|
| 851 | |
---|
[80175a1] | 852 | /* Try to fetch the profile; if the user has one, that's where |
---|
| 853 | we can find the persistent display_name. */ |
---|
| 854 | if( ( p = xt_find_node( node->children, "CID" ) ) && p->text ) |
---|
| 855 | msn_soap_profile_get( ic, p->text ); |
---|
| 856 | |
---|
[7f34ce2] | 857 | return XT_HANDLED; |
---|
| 858 | } |
---|
| 859 | |
---|
[9b01339] | 860 | if( !bool2int( is_msgr ) || handle == NULL ) |
---|
[d97f51b] | 861 | return XT_HANDLED; |
---|
| 862 | |
---|
[7f34ce2] | 863 | if( !( bu = bee_user_by_handle( ic->bee, ic, handle ) ) && |
---|
| 864 | !( bu = bee_user_new( ic->bee, ic, handle, 0 ) ) ) |
---|
| 865 | return XT_HANDLED; |
---|
| 866 | |
---|
| 867 | bd = bu->data; |
---|
| 868 | bd->flags |= MSN_BUDDY_FL; |
---|
| 869 | g_free( bd->cid ); |
---|
| 870 | bd->cid = g_strdup( id ); |
---|
| 871 | |
---|
| 872 | imcb_rename_buddy( ic, handle, display_name ); |
---|
| 873 | |
---|
[ff27648] | 874 | if( group_id && ( group = msn_group_by_id( ic, group_id ) ) ) |
---|
| 875 | imcb_add_buddy( ic, handle, group->name ); |
---|
| 876 | |
---|
[ed86165] | 877 | if( getenv( "BITLBEE_DEBUG" ) ) |
---|
[ca974d7] | 878 | fprintf( stderr, "%s %s %s %s\n", id, type, handle, display_name ); |
---|
[7f34ce2] | 879 | |
---|
| 880 | return XT_HANDLED; |
---|
| 881 | } |
---|
| 882 | |
---|
| 883 | static const struct xt_handler_entry msn_soap_addressbook_parser[] = { |
---|
| 884 | { "contactInfo", "Contact", msn_soap_addressbook_contact }, |
---|
| 885 | { "groupInfo", "Group", msn_soap_addressbook_group }, |
---|
| 886 | { NULL, NULL, NULL } |
---|
| 887 | }; |
---|
| 888 | |
---|
| 889 | static int msn_soap_addressbook_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 890 | { |
---|
[327af51] | 891 | GSList *l; |
---|
[4eb75b2] | 892 | int wtf = 0; |
---|
[327af51] | 893 | |
---|
| 894 | for( l = soap_req->ic->bee->users; l; l = l->next ) |
---|
| 895 | { |
---|
| 896 | struct bee_user *bu = l->data; |
---|
[4eb75b2] | 897 | struct msn_buddy_data *bd = bu->data; |
---|
[327af51] | 898 | |
---|
[d68365c] | 899 | if( bu->ic == soap_req->ic && bd ) |
---|
[4eb75b2] | 900 | { |
---|
[d68365c] | 901 | msn_buddy_ask( bu ); |
---|
| 902 | |
---|
| 903 | if( ( bd->flags & ( MSN_BUDDY_AL | MSN_BUDDY_BL ) ) == |
---|
| 904 | ( MSN_BUDDY_AL | MSN_BUDDY_BL ) ) |
---|
| 905 | { |
---|
| 906 | bd->flags &= ~MSN_BUDDY_BL; |
---|
| 907 | wtf++; |
---|
| 908 | } |
---|
[4eb75b2] | 909 | } |
---|
[327af51] | 910 | } |
---|
| 911 | |
---|
[4eb75b2] | 912 | if( wtf ) |
---|
| 913 | imcb_log( soap_req->ic, "Warning: %d contacts were in both your " |
---|
| 914 | "block and your allow list. Assuming they're all " |
---|
| 915 | "allowed. Use the official WLM client once to fix " |
---|
| 916 | "this.", wtf ); |
---|
| 917 | |
---|
[ca7de3a] | 918 | msn_auth_got_contact_list( soap_req->ic ); |
---|
[327af51] | 919 | |
---|
[7f34ce2] | 920 | return MSN_SOAP_OK; |
---|
| 921 | } |
---|
| 922 | |
---|
| 923 | static int msn_soap_addressbook_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 924 | { |
---|
| 925 | return 0; |
---|
| 926 | } |
---|
| 927 | |
---|
| 928 | int msn_soap_addressbook_request( struct im_connection *ic ) |
---|
| 929 | { |
---|
| 930 | return msn_soap_start( ic, NULL, msn_soap_addressbook_build_request, |
---|
| 931 | msn_soap_addressbook_parser, |
---|
| 932 | msn_soap_addressbook_handle_response, |
---|
| 933 | msn_soap_addressbook_free_data ); |
---|
| 934 | } |
---|
[4452e69] | 935 | |
---|
| 936 | /* Variant: Change our display name. */ |
---|
| 937 | static int msn_soap_ab_namechange_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 938 | { |
---|
| 939 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 940 | |
---|
| 941 | soap_req->url = g_strdup( SOAP_ADDRESSBOOK_URL ); |
---|
| 942 | soap_req->action = g_strdup( SOAP_AB_NAMECHANGE_ACTION ); |
---|
[6ddb223] | 943 | soap_req->payload = msn_soap_abservice_build( SOAP_AB_NAMECHANGE_PAYLOAD, |
---|
[e0e1546] | 944 | "Timer", md->tokens[1], (char *) soap_req->data ); |
---|
[4452e69] | 945 | |
---|
| 946 | return 1; |
---|
| 947 | } |
---|
| 948 | |
---|
| 949 | static int msn_soap_ab_namechange_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 950 | { |
---|
| 951 | /* TODO: Ack the change? Not sure what the NAKs look like.. */ |
---|
| 952 | return MSN_SOAP_OK; |
---|
| 953 | } |
---|
| 954 | |
---|
| 955 | static int msn_soap_ab_namechange_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 956 | { |
---|
| 957 | g_free( soap_req->data ); |
---|
| 958 | return 0; |
---|
| 959 | } |
---|
| 960 | |
---|
| 961 | int msn_soap_addressbook_set_display_name( struct im_connection *ic, const char *new ) |
---|
| 962 | { |
---|
| 963 | return msn_soap_start( ic, g_strdup( new ), |
---|
| 964 | msn_soap_ab_namechange_build_request, |
---|
| 965 | NULL, |
---|
| 966 | msn_soap_ab_namechange_handle_response, |
---|
| 967 | msn_soap_ab_namechange_free_data ); |
---|
| 968 | } |
---|
[4fc95c5] | 969 | |
---|
| 970 | /* Add a contact. */ |
---|
| 971 | static int msn_soap_ab_contact_add_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 972 | { |
---|
| 973 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 974 | bee_user_t *bu = soap_req->data; |
---|
| 975 | |
---|
| 976 | soap_req->url = g_strdup( SOAP_ADDRESSBOOK_URL ); |
---|
| 977 | soap_req->action = g_strdup( SOAP_AB_CONTACT_ADD_ACTION ); |
---|
| 978 | soap_req->payload = msn_soap_abservice_build( SOAP_AB_CONTACT_ADD_PAYLOAD, |
---|
| 979 | "ContactSave", md->tokens[1], bu->handle, bu->fullname ? bu->fullname : bu->handle ); |
---|
| 980 | |
---|
| 981 | return 1; |
---|
| 982 | } |
---|
| 983 | |
---|
| 984 | static xt_status msn_soap_ab_contact_add_cid( struct xt_node *node, gpointer data ) |
---|
| 985 | { |
---|
| 986 | struct msn_soap_req_data *soap_req = data; |
---|
| 987 | bee_user_t *bu = soap_req->data; |
---|
| 988 | struct msn_buddy_data *bd = bu->data; |
---|
| 989 | |
---|
| 990 | g_free( bd->cid ); |
---|
| 991 | bd->cid = g_strdup( node->text ); |
---|
| 992 | |
---|
| 993 | return XT_HANDLED; |
---|
| 994 | } |
---|
| 995 | |
---|
| 996 | static const struct xt_handler_entry msn_soap_ab_contact_add_parser[] = { |
---|
| 997 | { "guid", "ABContactAddResult", msn_soap_ab_contact_add_cid }, |
---|
| 998 | { NULL, NULL, NULL } |
---|
| 999 | }; |
---|
| 1000 | |
---|
| 1001 | static int msn_soap_ab_contact_add_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 1002 | { |
---|
| 1003 | /* TODO: Ack the change? Not sure what the NAKs look like.. */ |
---|
| 1004 | return MSN_SOAP_OK; |
---|
| 1005 | } |
---|
| 1006 | |
---|
| 1007 | static int msn_soap_ab_contact_add_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 1008 | { |
---|
| 1009 | return 0; |
---|
| 1010 | } |
---|
| 1011 | |
---|
| 1012 | int msn_soap_ab_contact_add( struct im_connection *ic, bee_user_t *bu ) |
---|
| 1013 | { |
---|
| 1014 | return msn_soap_start( ic, bu, |
---|
| 1015 | msn_soap_ab_contact_add_build_request, |
---|
| 1016 | msn_soap_ab_contact_add_parser, |
---|
| 1017 | msn_soap_ab_contact_add_handle_response, |
---|
| 1018 | msn_soap_ab_contact_add_free_data ); |
---|
| 1019 | } |
---|
| 1020 | |
---|
| 1021 | /* Remove a contact. */ |
---|
| 1022 | static int msn_soap_ab_contact_del_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 1023 | { |
---|
| 1024 | struct msn_data *md = soap_req->ic->proto_data; |
---|
[52f5e90] | 1025 | const char *cid = soap_req->data; |
---|
[4fc95c5] | 1026 | |
---|
| 1027 | soap_req->url = g_strdup( SOAP_ADDRESSBOOK_URL ); |
---|
| 1028 | soap_req->action = g_strdup( SOAP_AB_CONTACT_DEL_ACTION ); |
---|
| 1029 | soap_req->payload = msn_soap_abservice_build( SOAP_AB_CONTACT_DEL_PAYLOAD, |
---|
[52f5e90] | 1030 | "Timer", md->tokens[1], cid ); |
---|
[4fc95c5] | 1031 | |
---|
| 1032 | return 1; |
---|
| 1033 | } |
---|
| 1034 | |
---|
| 1035 | static int msn_soap_ab_contact_del_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 1036 | { |
---|
| 1037 | /* TODO: Ack the change? Not sure what the NAKs look like.. */ |
---|
| 1038 | return MSN_SOAP_OK; |
---|
| 1039 | } |
---|
| 1040 | |
---|
| 1041 | static int msn_soap_ab_contact_del_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 1042 | { |
---|
[52f5e90] | 1043 | g_free( soap_req->data ); |
---|
[4fc95c5] | 1044 | return 0; |
---|
| 1045 | } |
---|
| 1046 | |
---|
| 1047 | int msn_soap_ab_contact_del( struct im_connection *ic, bee_user_t *bu ) |
---|
| 1048 | { |
---|
[52f5e90] | 1049 | struct msn_buddy_data *bd = bu->data; |
---|
| 1050 | |
---|
| 1051 | return msn_soap_start( ic, g_strdup( bd->cid ), |
---|
[4fc95c5] | 1052 | msn_soap_ab_contact_del_build_request, |
---|
| 1053 | NULL, |
---|
| 1054 | msn_soap_ab_contact_del_handle_response, |
---|
| 1055 | msn_soap_ab_contact_del_free_data ); |
---|
| 1056 | } |
---|
[80175a1] | 1057 | |
---|
| 1058 | |
---|
| 1059 | |
---|
| 1060 | /* Storage stuff: Fetch profile. */ |
---|
| 1061 | static int msn_soap_profile_get_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 1062 | { |
---|
| 1063 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 1064 | |
---|
| 1065 | soap_req->url = g_strdup( SOAP_STORAGE_URL ); |
---|
| 1066 | soap_req->action = g_strdup( SOAP_PROFILE_GET_ACTION ); |
---|
| 1067 | soap_req->payload = g_markup_printf_escaped( SOAP_PROFILE_GET_PAYLOAD, |
---|
| 1068 | md->tokens[3], (char*) soap_req->data ); |
---|
| 1069 | |
---|
| 1070 | return 1; |
---|
| 1071 | } |
---|
| 1072 | |
---|
| 1073 | static xt_status msn_soap_profile_get_result( struct xt_node *node, gpointer data ) |
---|
| 1074 | { |
---|
| 1075 | struct msn_soap_req_data *soap_req = data; |
---|
| 1076 | struct im_connection *ic = soap_req->ic; |
---|
| 1077 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 1078 | struct xt_node *dn; |
---|
| 1079 | |
---|
| 1080 | if( ( dn = xt_find_node( node->children, "DisplayName" ) ) && dn->text ) |
---|
| 1081 | { |
---|
| 1082 | set_t *set = set_find( &ic->acc->set, "display_name" ); |
---|
| 1083 | g_free( set->value ); |
---|
| 1084 | set->value = g_strdup( dn->text ); |
---|
| 1085 | |
---|
| 1086 | md->flags |= MSN_GOT_PROFILE_DN; |
---|
| 1087 | } |
---|
| 1088 | |
---|
| 1089 | return XT_HANDLED; |
---|
| 1090 | } |
---|
| 1091 | |
---|
[76c89dc7] | 1092 | static xt_status msn_soap_profile_get_rid( struct xt_node *node, gpointer data ) |
---|
| 1093 | { |
---|
| 1094 | struct msn_soap_req_data *soap_req = data; |
---|
| 1095 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 1096 | |
---|
| 1097 | g_free( md->profile_rid ); |
---|
| 1098 | md->profile_rid = g_strdup( node->text ); |
---|
| 1099 | |
---|
| 1100 | return XT_HANDLED; |
---|
| 1101 | } |
---|
| 1102 | |
---|
[80175a1] | 1103 | static const struct xt_handler_entry msn_soap_profile_get_parser[] = { |
---|
| 1104 | { "ExpressionProfile", "GetProfileResult", msn_soap_profile_get_result }, |
---|
[76c89dc7] | 1105 | { "ResourceID", "GetProfileResult", msn_soap_profile_get_rid }, |
---|
[80175a1] | 1106 | { NULL, NULL, NULL } |
---|
| 1107 | }; |
---|
| 1108 | |
---|
| 1109 | static int msn_soap_profile_get_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 1110 | { |
---|
| 1111 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 1112 | |
---|
| 1113 | md->flags |= MSN_GOT_PROFILE; |
---|
| 1114 | msn_ns_finish_login( soap_req->ic ); |
---|
| 1115 | |
---|
| 1116 | return MSN_SOAP_OK; |
---|
| 1117 | } |
---|
| 1118 | |
---|
| 1119 | static int msn_soap_profile_get_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 1120 | { |
---|
| 1121 | g_free( soap_req->data ); |
---|
| 1122 | return 0; |
---|
| 1123 | } |
---|
| 1124 | |
---|
| 1125 | int msn_soap_profile_get( struct im_connection *ic, const char *cid ) |
---|
| 1126 | { |
---|
| 1127 | return msn_soap_start( ic, g_strdup( cid ), |
---|
| 1128 | msn_soap_profile_get_build_request, |
---|
| 1129 | msn_soap_profile_get_parser, |
---|
| 1130 | msn_soap_profile_get_handle_response, |
---|
| 1131 | msn_soap_profile_get_free_data ); |
---|
| 1132 | } |
---|
[76c89dc7] | 1133 | |
---|
| 1134 | /* Update profile (display name). */ |
---|
| 1135 | static int msn_soap_profile_set_dn_build_request( struct msn_soap_req_data *soap_req ) |
---|
| 1136 | { |
---|
| 1137 | struct msn_data *md = soap_req->ic->proto_data; |
---|
| 1138 | |
---|
| 1139 | soap_req->url = g_strdup( SOAP_STORAGE_URL ); |
---|
| 1140 | soap_req->action = g_strdup( SOAP_PROFILE_SET_DN_ACTION ); |
---|
| 1141 | soap_req->payload = g_markup_printf_escaped( SOAP_PROFILE_SET_DN_PAYLOAD, |
---|
| 1142 | md->tokens[3], md->profile_rid, (char*) soap_req->data ); |
---|
| 1143 | |
---|
| 1144 | return 1; |
---|
| 1145 | } |
---|
| 1146 | |
---|
| 1147 | static const struct xt_handler_entry msn_soap_profile_set_dn_parser[] = { |
---|
| 1148 | { NULL, NULL, NULL } |
---|
| 1149 | }; |
---|
| 1150 | |
---|
| 1151 | static int msn_soap_profile_set_dn_handle_response( struct msn_soap_req_data *soap_req ) |
---|
| 1152 | { |
---|
| 1153 | return MSN_SOAP_OK; |
---|
| 1154 | } |
---|
| 1155 | |
---|
| 1156 | static int msn_soap_profile_set_dn_free_data( struct msn_soap_req_data *soap_req ) |
---|
| 1157 | { |
---|
| 1158 | g_free( soap_req->data ); |
---|
| 1159 | return 0; |
---|
| 1160 | } |
---|
| 1161 | |
---|
| 1162 | int msn_soap_profile_set_dn( struct im_connection *ic, const char *dn ) |
---|
| 1163 | { |
---|
| 1164 | return msn_soap_start( ic, g_strdup( dn ), |
---|
| 1165 | msn_soap_profile_set_dn_build_request, |
---|
| 1166 | msn_soap_profile_set_dn_parser, |
---|
| 1167 | msn_soap_profile_set_dn_handle_response, |
---|
| 1168 | msn_soap_profile_set_dn_free_data ); |
---|
| 1169 | } |
---|