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