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