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