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