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