[b7d3cc34] | 1 | /********************************************************************\ |
---|
| 2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
| 3 | * * |
---|
[79bb7e4] | 4 | * Copyright 2002-2012 Wilmer van der Gaast and others * |
---|
[b7d3cc34] | 5 | \********************************************************************/ |
---|
| 6 | |
---|
| 7 | /* MSN module - Miscellaneous utilities */ |
---|
| 8 | |
---|
| 9 | /* |
---|
| 10 | This program is free software; you can redistribute it and/or modify |
---|
| 11 | it under the terms of the GNU General Public License as published by |
---|
| 12 | the Free Software Foundation; either version 2 of the License, or |
---|
| 13 | (at your option) any later version. |
---|
| 14 | |
---|
| 15 | This program is distributed in the hope that it will be useful, |
---|
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 18 | GNU General Public License for more details. |
---|
| 19 | |
---|
| 20 | You should have received a copy of the GNU General Public License with |
---|
| 21 | the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; |
---|
| 22 | if not, write to the Free Software Foundation, Inc., 59 Temple Place, |
---|
| 23 | Suite 330, Boston, MA 02111-1307 USA |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include "nogaim.h" |
---|
| 27 | #include "msn.h" |
---|
[21029d0] | 28 | #include "md5.h" |
---|
[193dc74] | 29 | #include "soap.h" |
---|
[b7d3cc34] | 30 | #include <ctype.h> |
---|
| 31 | |
---|
[193dc74] | 32 | static char *adlrml_entry( const char *handle_, msn_buddy_flags_t list ) |
---|
| 33 | { |
---|
| 34 | char *domain, handle[strlen(handle_)+1]; |
---|
| 35 | |
---|
| 36 | strcpy( handle, handle_ ); |
---|
| 37 | if( ( domain = strchr( handle, '@' ) ) ) |
---|
[d97f51b] | 38 | *(domain++) = '\0'; |
---|
[193dc74] | 39 | else |
---|
| 40 | return NULL; |
---|
| 41 | |
---|
| 42 | return g_markup_printf_escaped( "<ml><d n=\"%s\"><c n=\"%s\" l=\"%d\" t=\"1\"/></d></ml>", |
---|
| 43 | domain, handle, list ); |
---|
| 44 | } |
---|
| 45 | |
---|
[4fc95c5] | 46 | int msn_buddy_list_add( struct im_connection *ic, msn_buddy_flags_t list, const char *who, const char *realname, const char *group ) |
---|
[b7d3cc34] | 47 | { |
---|
[0da65d5] | 48 | struct msn_data *md = ic->proto_data; |
---|
[64768d4] | 49 | char groupid[8]; |
---|
[193dc74] | 50 | bee_user_t *bu; |
---|
| 51 | struct msn_buddy_data *bd; |
---|
| 52 | char *adl; |
---|
[b7d3cc34] | 53 | |
---|
[6acc033] | 54 | *groupid = '\0'; |
---|
[193dc74] | 55 | #if 0 |
---|
[6acc033] | 56 | if( group ) |
---|
| 57 | { |
---|
| 58 | int i; |
---|
| 59 | for( i = 0; i < md->groupcount; i ++ ) |
---|
| 60 | if( g_strcasecmp( md->grouplist[i], group ) == 0 ) |
---|
| 61 | { |
---|
| 62 | g_snprintf( groupid, sizeof( groupid ), " %d", i ); |
---|
| 63 | break; |
---|
| 64 | } |
---|
[b7d3cc34] | 65 | |
---|
[70ac477] | 66 | if( *groupid == '\0' ) |
---|
| 67 | { |
---|
| 68 | /* Have to create this group, it doesn't exist yet. */ |
---|
| 69 | struct msn_groupadd *ga; |
---|
| 70 | GSList *l; |
---|
| 71 | |
---|
| 72 | for( l = md->grpq; l; l = l->next ) |
---|
| 73 | { |
---|
| 74 | ga = l->data; |
---|
| 75 | if( g_strcasecmp( ga->group, group ) == 0 ) |
---|
| 76 | break; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | ga = g_new0( struct msn_groupadd, 1 ); |
---|
| 80 | ga->who = g_strdup( who ); |
---|
| 81 | ga->group = g_strdup( group ); |
---|
| 82 | md->grpq = g_slist_prepend( md->grpq, ga ); |
---|
| 83 | |
---|
| 84 | if( l == NULL ) |
---|
| 85 | { |
---|
[4452e69] | 86 | char groupname[strlen(group)+1]; |
---|
| 87 | strcpy( groupname, group ); |
---|
| 88 | http_encode( groupname ); |
---|
[70ac477] | 89 | g_snprintf( buf, sizeof( buf ), "ADG %d %s %d\r\n", ++md->trId, groupname, 0 ); |
---|
| 90 | return msn_write( ic, buf, strlen( buf ) ); |
---|
| 91 | } |
---|
| 92 | else |
---|
| 93 | { |
---|
| 94 | /* This can happen if the user's doing lots of adds to a |
---|
| 95 | new group at once; we're still waiting for the server |
---|
| 96 | to confirm group creation. */ |
---|
| 97 | return 1; |
---|
| 98 | } |
---|
| 99 | } |
---|
[b7d3cc34] | 100 | } |
---|
[193dc74] | 101 | #endif |
---|
| 102 | |
---|
[4fc95c5] | 103 | if( !( ( bu = bee_user_by_handle( ic->bee, ic, who ) ) || |
---|
| 104 | ( bu = bee_user_new( ic->bee, ic, who, 0 ) ) ) || |
---|
[193dc74] | 105 | !( bd = bu->data ) || bd->flags & list ) |
---|
| 106 | return 1; |
---|
[b7d3cc34] | 107 | |
---|
[193dc74] | 108 | bd->flags |= list; |
---|
[b7d3cc34] | 109 | |
---|
[4fc95c5] | 110 | if( list == MSN_BUDDY_FL ) |
---|
| 111 | msn_soap_ab_contact_add( ic, bu ); |
---|
| 112 | else |
---|
| 113 | msn_soap_memlist_edit( ic, who, TRUE, list ); |
---|
[193dc74] | 114 | |
---|
| 115 | if( ( adl = adlrml_entry( who, list ) ) ) |
---|
| 116 | { |
---|
[64768d4] | 117 | int st = msn_ns_write( ic, -1, "ADL %d %zd\r\n%s", |
---|
| 118 | ++md->trId, strlen( adl ), adl ); |
---|
[193dc74] | 119 | g_free( adl ); |
---|
| 120 | |
---|
[64768d4] | 121 | return st; |
---|
[193dc74] | 122 | } |
---|
[6ddb223] | 123 | |
---|
| 124 | return 1; |
---|
[b7d3cc34] | 125 | } |
---|
| 126 | |
---|
[193dc74] | 127 | int msn_buddy_list_remove( struct im_connection *ic, msn_buddy_flags_t list, const char *who, const char *group ) |
---|
[b7d3cc34] | 128 | { |
---|
[0da65d5] | 129 | struct msn_data *md = ic->proto_data; |
---|
[64768d4] | 130 | char groupid[8]; |
---|
[193dc74] | 131 | bee_user_t *bu; |
---|
| 132 | struct msn_buddy_data *bd; |
---|
| 133 | char *adl; |
---|
[b7d3cc34] | 134 | |
---|
[8b01217] | 135 | *groupid = '\0'; |
---|
[193dc74] | 136 | #if 0 |
---|
[8b01217] | 137 | if( group ) |
---|
| 138 | { |
---|
| 139 | int i; |
---|
| 140 | for( i = 0; i < md->groupcount; i ++ ) |
---|
| 141 | if( g_strcasecmp( md->grouplist[i], group ) == 0 ) |
---|
| 142 | { |
---|
| 143 | g_snprintf( groupid, sizeof( groupid ), " %d", i ); |
---|
| 144 | break; |
---|
| 145 | } |
---|
| 146 | } |
---|
[193dc74] | 147 | #endif |
---|
| 148 | |
---|
| 149 | if( !( bu = bee_user_by_handle( ic->bee, ic, who ) ) || |
---|
| 150 | !( bd = bu->data ) || !( bd->flags & list ) ) |
---|
| 151 | return 1; |
---|
| 152 | |
---|
| 153 | bd->flags &= ~list; |
---|
[8b01217] | 154 | |
---|
[4fc95c5] | 155 | if( list == MSN_BUDDY_FL ) |
---|
| 156 | msn_soap_ab_contact_del( ic, bu ); |
---|
| 157 | else |
---|
| 158 | msn_soap_memlist_edit( ic, who, FALSE, list ); |
---|
[193dc74] | 159 | |
---|
| 160 | if( ( adl = adlrml_entry( who, list ) ) ) |
---|
| 161 | { |
---|
[64768d4] | 162 | int st = msn_ns_write( ic, -1, "RML %d %zd\r\n%s", |
---|
| 163 | ++md->trId, strlen( adl ), adl ); |
---|
[193dc74] | 164 | g_free( adl ); |
---|
| 165 | |
---|
[64768d4] | 166 | return st; |
---|
[193dc74] | 167 | } |
---|
[b7d3cc34] | 168 | |
---|
[6ddb223] | 169 | return 1; |
---|
[b7d3cc34] | 170 | } |
---|
| 171 | |
---|
| 172 | struct msn_buddy_ask_data |
---|
| 173 | { |
---|
[0da65d5] | 174 | struct im_connection *ic; |
---|
[b7d3cc34] | 175 | char *handle; |
---|
| 176 | char *realname; |
---|
| 177 | }; |
---|
| 178 | |
---|
[9143aeb] | 179 | static void msn_buddy_ask_yes( void *data ) |
---|
[b7d3cc34] | 180 | { |
---|
[9143aeb] | 181 | struct msn_buddy_ask_data *bla = data; |
---|
| 182 | |
---|
[193dc74] | 183 | msn_buddy_list_add( bla->ic, MSN_BUDDY_AL, bla->handle, bla->realname, NULL ); |
---|
[b7d3cc34] | 184 | |
---|
[17a6ee9] | 185 | imcb_ask_add( bla->ic, bla->handle, NULL ); |
---|
[e6d6047] | 186 | |
---|
[b7d3cc34] | 187 | g_free( bla->handle ); |
---|
| 188 | g_free( bla->realname ); |
---|
| 189 | g_free( bla ); |
---|
| 190 | } |
---|
| 191 | |
---|
[9143aeb] | 192 | static void msn_buddy_ask_no( void *data ) |
---|
[b7d3cc34] | 193 | { |
---|
[9143aeb] | 194 | struct msn_buddy_ask_data *bla = data; |
---|
| 195 | |
---|
[193dc74] | 196 | msn_buddy_list_add( bla->ic, MSN_BUDDY_BL, bla->handle, bla->realname, NULL ); |
---|
[b7d3cc34] | 197 | |
---|
| 198 | g_free( bla->handle ); |
---|
| 199 | g_free( bla->realname ); |
---|
| 200 | g_free( bla ); |
---|
| 201 | } |
---|
| 202 | |
---|
[e5854a8] | 203 | void msn_buddy_ask( bee_user_t *bu ) |
---|
[b7d3cc34] | 204 | { |
---|
[e5854a8] | 205 | struct msn_buddy_ask_data *bla; |
---|
| 206 | struct msn_buddy_data *bd = bu->data; |
---|
[b7d3cc34] | 207 | char buf[1024]; |
---|
| 208 | |
---|
[3325df7] | 209 | if( !( bd->flags & MSN_BUDDY_PL ) ) |
---|
[e5854a8] | 210 | return; |
---|
| 211 | |
---|
| 212 | bla = g_new0( struct msn_buddy_ask_data, 1 ); |
---|
| 213 | bla->ic = bu->ic; |
---|
| 214 | bla->handle = g_strdup( bu->handle ); |
---|
| 215 | bla->realname = g_strdup( bu->fullname ); |
---|
[b7d3cc34] | 216 | |
---|
| 217 | g_snprintf( buf, sizeof( buf ), |
---|
[5c09a59] | 218 | "The user %s (%s) wants to add you to his/her buddy list.", |
---|
[e5854a8] | 219 | bu->handle, bu->fullname ); |
---|
| 220 | imcb_ask( bu->ic, buf, bla, msn_buddy_ask_yes, msn_buddy_ask_no ); |
---|
[b7d3cc34] | 221 | } |
---|
| 222 | |
---|
| 223 | /* *NOT* thread-safe, but that's not a problem for now... */ |
---|
| 224 | char **msn_linesplit( char *line ) |
---|
| 225 | { |
---|
| 226 | static char **ret = NULL; |
---|
| 227 | static int size = 3; |
---|
| 228 | int i, n = 0; |
---|
| 229 | |
---|
| 230 | if( ret == NULL ) |
---|
| 231 | ret = g_new0( char*, size ); |
---|
| 232 | |
---|
| 233 | for( i = 0; line[i] && line[i] == ' '; i ++ ); |
---|
| 234 | if( line[i] ) |
---|
| 235 | { |
---|
| 236 | ret[n++] = line + i; |
---|
| 237 | for( i ++; line[i]; i ++ ) |
---|
| 238 | { |
---|
| 239 | if( line[i] == ' ' ) |
---|
| 240 | line[i] = 0; |
---|
| 241 | else if( line[i] != ' ' && !line[i-1] ) |
---|
| 242 | ret[n++] = line + i; |
---|
| 243 | |
---|
| 244 | if( n >= size ) |
---|
| 245 | ret = g_renew( char*, ret, size += 2 ); |
---|
| 246 | } |
---|
| 247 | } |
---|
| 248 | ret[n] = NULL; |
---|
| 249 | |
---|
| 250 | return( ret ); |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | /* This one handles input from a MSN Messenger server. Both the NS and SB servers usually give |
---|
| 254 | commands, but sometimes they give additional data (payload). This function tries to handle |
---|
| 255 | this all in a nice way and send all data to the right places. */ |
---|
| 256 | |
---|
| 257 | /* Return values: -1: Read error, abort connection. |
---|
| 258 | 0: Command reported error; Abort *immediately*. (The connection does not exist anymore) |
---|
| 259 | 1: OK */ |
---|
| 260 | |
---|
| 261 | int msn_handler( struct msn_handler_data *h ) |
---|
| 262 | { |
---|
| 263 | int st; |
---|
| 264 | |
---|
| 265 | h->rxq = g_renew( char, h->rxq, h->rxlen + 1024 ); |
---|
| 266 | st = read( h->fd, h->rxq + h->rxlen, 1024 ); |
---|
| 267 | h->rxlen += st; |
---|
| 268 | |
---|
| 269 | if( st <= 0 ) |
---|
| 270 | return( -1 ); |
---|
| 271 | |
---|
[523fb23] | 272 | if( getenv( "BITLBEE_DEBUG" ) ) |
---|
| 273 | { |
---|
| 274 | write( 2, "->C:", 4 ); |
---|
| 275 | write( 2, h->rxq + h->rxlen - st, st ); |
---|
| 276 | } |
---|
| 277 | |
---|
[b7d3cc34] | 278 | while( st ) |
---|
| 279 | { |
---|
| 280 | int i; |
---|
| 281 | |
---|
| 282 | if( h->msglen == 0 ) |
---|
| 283 | { |
---|
| 284 | for( i = 0; i < h->rxlen; i ++ ) |
---|
| 285 | { |
---|
| 286 | if( h->rxq[i] == '\r' || h->rxq[i] == '\n' ) |
---|
| 287 | { |
---|
| 288 | char *cmd_text, **cmd; |
---|
| 289 | int count; |
---|
| 290 | |
---|
| 291 | cmd_text = g_strndup( h->rxq, i ); |
---|
| 292 | cmd = msn_linesplit( cmd_text ); |
---|
| 293 | for( count = 0; cmd[count]; count ++ ); |
---|
[bae0617] | 294 | st = h->exec_command( h, cmd, count ); |
---|
[b7d3cc34] | 295 | g_free( cmd_text ); |
---|
| 296 | |
---|
| 297 | /* If the connection broke, don't continue. We don't even exist anymore. */ |
---|
| 298 | if( !st ) |
---|
| 299 | return( 0 ); |
---|
| 300 | |
---|
| 301 | if( h->msglen ) |
---|
| 302 | h->cmd_text = g_strndup( h->rxq, i ); |
---|
| 303 | |
---|
| 304 | /* Skip to the next non-emptyline */ |
---|
| 305 | while( i < h->rxlen && ( h->rxq[i] == '\r' || h->rxq[i] == '\n' ) ) i ++; |
---|
| 306 | |
---|
| 307 | break; |
---|
| 308 | } |
---|
| 309 | } |
---|
| 310 | |
---|
| 311 | /* If we reached the end of the buffer, there's still an incomplete command there. |
---|
| 312 | Return and wait for more data. */ |
---|
| 313 | if( i == h->rxlen && h->rxq[i-1] != '\r' && h->rxq[i-1] != '\n' ) |
---|
| 314 | break; |
---|
| 315 | } |
---|
| 316 | else |
---|
| 317 | { |
---|
| 318 | char *msg, **cmd; |
---|
| 319 | int count; |
---|
| 320 | |
---|
| 321 | /* Do we have the complete message already? */ |
---|
| 322 | if( h->msglen > h->rxlen ) |
---|
| 323 | break; |
---|
| 324 | |
---|
| 325 | msg = g_strndup( h->rxq, h->msglen ); |
---|
| 326 | cmd = msn_linesplit( h->cmd_text ); |
---|
| 327 | for( count = 0; cmd[count]; count ++ ); |
---|
| 328 | |
---|
[bae0617] | 329 | st = h->exec_message( h, msg, h->msglen, cmd, count ); |
---|
[b7d3cc34] | 330 | g_free( msg ); |
---|
| 331 | g_free( h->cmd_text ); |
---|
| 332 | h->cmd_text = NULL; |
---|
| 333 | |
---|
| 334 | if( !st ) |
---|
| 335 | return( 0 ); |
---|
| 336 | |
---|
| 337 | i = h->msglen; |
---|
| 338 | h->msglen = 0; |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | /* More data after this block? */ |
---|
| 342 | if( i < h->rxlen ) |
---|
| 343 | { |
---|
| 344 | char *tmp; |
---|
| 345 | |
---|
| 346 | tmp = g_memdup( h->rxq + i, h->rxlen - i ); |
---|
| 347 | g_free( h->rxq ); |
---|
| 348 | h->rxq = tmp; |
---|
| 349 | h->rxlen -= i; |
---|
| 350 | i = 0; |
---|
| 351 | } |
---|
| 352 | else |
---|
| 353 | /* If not, reset the rx queue and get lost. */ |
---|
| 354 | { |
---|
| 355 | g_free( h->rxq ); |
---|
| 356 | h->rxq = g_new0( char, 1 ); |
---|
| 357 | h->rxlen = 0; |
---|
| 358 | return( 1 ); |
---|
| 359 | } |
---|
| 360 | } |
---|
| 361 | |
---|
| 362 | return( 1 ); |
---|
| 363 | } |
---|
[54794b8] | 364 | |
---|
[46dca11] | 365 | void msn_msgq_purge( struct im_connection *ic, GSList **list ) |
---|
| 366 | { |
---|
| 367 | struct msn_message *m; |
---|
| 368 | GString *ret; |
---|
| 369 | GSList *l; |
---|
[4255320] | 370 | int n = 0; |
---|
[46dca11] | 371 | |
---|
| 372 | l = *list; |
---|
| 373 | if( l == NULL ) |
---|
| 374 | return; |
---|
| 375 | |
---|
| 376 | m = l->data; |
---|
| 377 | ret = g_string_sized_new( 1024 ); |
---|
[43462708] | 378 | g_string_printf( ret, "Warning: Cleaning up MSN (switchboard) connection with unsent " |
---|
[46dca11] | 379 | "messages to %s:", m->who ? m->who : "unknown recipient" ); |
---|
| 380 | |
---|
| 381 | while( l ) |
---|
| 382 | { |
---|
| 383 | m = l->data; |
---|
| 384 | |
---|
[4255320] | 385 | if( strncmp( m->text, "\r\r\r", 3 ) != 0 ) |
---|
| 386 | { |
---|
| 387 | g_string_append_printf( ret, "\n%s", m->text ); |
---|
| 388 | n ++; |
---|
| 389 | } |
---|
[46dca11] | 390 | |
---|
| 391 | g_free( m->who ); |
---|
| 392 | g_free( m->text ); |
---|
| 393 | g_free( m ); |
---|
| 394 | |
---|
| 395 | l = l->next; |
---|
| 396 | } |
---|
| 397 | g_slist_free( *list ); |
---|
| 398 | *list = NULL; |
---|
| 399 | |
---|
[4255320] | 400 | if( n > 0 ) |
---|
| 401 | imcb_log( ic, "%s", ret->str ); |
---|
[46dca11] | 402 | g_string_free( ret, TRUE ); |
---|
| 403 | } |
---|
[e3413cc] | 404 | |
---|
[21029d0] | 405 | /* Copied and heavily modified from http://tmsnc.sourceforge.net/chl.c */ |
---|
| 406 | char *msn_p11_challenge( char *challenge ) |
---|
| 407 | { |
---|
| 408 | char *output, buf[256]; |
---|
| 409 | md5_state_t md5c; |
---|
| 410 | unsigned char md5Hash[16], *newHash; |
---|
| 411 | unsigned int *md5Parts, *chlStringParts, newHashParts[5]; |
---|
| 412 | long long nHigh = 0, nLow = 0; |
---|
| 413 | int i, n; |
---|
| 414 | |
---|
| 415 | /* Create the MD5 hash */ |
---|
| 416 | md5_init(&md5c); |
---|
| 417 | md5_append(&md5c, (unsigned char*) challenge, strlen(challenge)); |
---|
| 418 | md5_append(&md5c, (unsigned char*) MSNP11_PROD_KEY, strlen(MSNP11_PROD_KEY)); |
---|
| 419 | md5_finish(&md5c, md5Hash); |
---|
| 420 | |
---|
| 421 | /* Split it into four integers */ |
---|
| 422 | md5Parts = (unsigned int *)md5Hash; |
---|
| 423 | for (i = 0; i < 4; i ++) |
---|
| 424 | { |
---|
[523fb23] | 425 | md5Parts[i] = GUINT32_TO_LE(md5Parts[i]); |
---|
[21029d0] | 426 | |
---|
| 427 | /* & each integer with 0x7FFFFFFF */ |
---|
| 428 | /* and save one unmodified array for later */ |
---|
| 429 | newHashParts[i] = md5Parts[i]; |
---|
| 430 | md5Parts[i] &= 0x7FFFFFFF; |
---|
| 431 | } |
---|
| 432 | |
---|
| 433 | /* make a new string and pad with '0' */ |
---|
| 434 | n = g_snprintf(buf, sizeof(buf)-5, "%s%s00000000", challenge, MSNP11_PROD_ID); |
---|
| 435 | /* truncate at an 8-byte boundary */ |
---|
| 436 | buf[n&=~7] = '\0'; |
---|
| 437 | |
---|
| 438 | /* split into integers */ |
---|
| 439 | chlStringParts = (unsigned int *)buf; |
---|
| 440 | |
---|
| 441 | /* this is magic */ |
---|
| 442 | for (i = 0; i < (n / 4) - 1; i += 2) |
---|
| 443 | { |
---|
| 444 | long long temp; |
---|
| 445 | |
---|
[523fb23] | 446 | chlStringParts[i] = GUINT32_TO_LE(chlStringParts[i]); |
---|
| 447 | chlStringParts[i+1] = GUINT32_TO_LE(chlStringParts[i+1]); |
---|
[21029d0] | 448 | |
---|
| 449 | temp = (md5Parts[0] * (((0x0E79A9C1 * (long long)chlStringParts[i]) % 0x7FFFFFFF)+nHigh) + md5Parts[1])%0x7FFFFFFF; |
---|
| 450 | nHigh = (md5Parts[2] * (((long long)chlStringParts[i+1]+temp) % 0x7FFFFFFF) + md5Parts[3]) % 0x7FFFFFFF; |
---|
| 451 | nLow = nLow + nHigh + temp; |
---|
| 452 | } |
---|
| 453 | nHigh = (nHigh+md5Parts[1]) % 0x7FFFFFFF; |
---|
| 454 | nLow = (nLow+md5Parts[3]) % 0x7FFFFFFF; |
---|
| 455 | |
---|
| 456 | newHashParts[0] ^= nHigh; |
---|
| 457 | newHashParts[1] ^= nLow; |
---|
| 458 | newHashParts[2] ^= nHigh; |
---|
| 459 | newHashParts[3] ^= nLow; |
---|
| 460 | |
---|
| 461 | /* swap more bytes if big endian */ |
---|
| 462 | for (i = 0; i < 4; i ++) |
---|
[523fb23] | 463 | newHashParts[i] = GUINT32_TO_LE(newHashParts[i]); |
---|
[21029d0] | 464 | |
---|
| 465 | /* make a string of the parts */ |
---|
| 466 | newHash = (unsigned char *)newHashParts; |
---|
| 467 | |
---|
| 468 | /* convert to hexadecimal */ |
---|
| 469 | output = g_new(char, 33); |
---|
| 470 | for (i = 0; i < 16; i ++) |
---|
| 471 | sprintf(output + i * 2, "%02x", newHash[i]); |
---|
| 472 | |
---|
| 473 | return output; |
---|
| 474 | } |
---|
[ca7de3a] | 475 | |
---|
| 476 | gint msn_domaintree_cmp( gconstpointer a_, gconstpointer b_ ) |
---|
| 477 | { |
---|
| 478 | const char *a = a_, *b = b_; |
---|
| 479 | gint ret; |
---|
| 480 | |
---|
| 481 | if( !( a = strchr( a, '@' ) ) || !( b = strchr( b, '@' ) ) || |
---|
| 482 | ( ret = strcmp( a, b ) ) == 0 ) |
---|
| 483 | ret = strcmp( a_, b_ ); |
---|
| 484 | |
---|
| 485 | return ret; |
---|
| 486 | } |
---|
[ff27648] | 487 | |
---|
| 488 | struct msn_group *msn_group_by_name( struct im_connection *ic, const char *name ) |
---|
| 489 | { |
---|
| 490 | struct msn_data *md = ic->proto_data; |
---|
| 491 | GSList *l; |
---|
| 492 | |
---|
| 493 | for( l = md->groups; l; l = l->next ) |
---|
| 494 | { |
---|
| 495 | struct msn_group *mg = l->data; |
---|
| 496 | |
---|
| 497 | if( g_strcasecmp( mg->name, name ) == 0 ) |
---|
| 498 | return mg; |
---|
| 499 | } |
---|
| 500 | |
---|
| 501 | return NULL; |
---|
| 502 | } |
---|
| 503 | |
---|
| 504 | struct msn_group *msn_group_by_id( struct im_connection *ic, const char *id ) |
---|
| 505 | { |
---|
| 506 | struct msn_data *md = ic->proto_data; |
---|
| 507 | GSList *l; |
---|
| 508 | |
---|
| 509 | for( l = md->groups; l; l = l->next ) |
---|
| 510 | { |
---|
| 511 | struct msn_group *mg = l->data; |
---|
| 512 | |
---|
| 513 | if( g_strcasecmp( mg->id, id ) == 0 ) |
---|
| 514 | return mg; |
---|
| 515 | } |
---|
| 516 | |
---|
| 517 | return NULL; |
---|
| 518 | } |
---|
[e0e1546] | 519 | |
---|
| 520 | int msn_ns_set_display_name( struct im_connection *ic, const char *value ) |
---|
| 521 | { |
---|
| 522 | struct msn_data *md = ic->proto_data; |
---|
| 523 | char fn[strlen(value)*3+1]; |
---|
| 524 | |
---|
| 525 | strcpy( fn, value ); |
---|
| 526 | http_encode( fn ); |
---|
| 527 | |
---|
| 528 | /* Note: We don't actually know if the server accepted the new name, |
---|
| 529 | and won't give proper feedback yet if it doesn't. */ |
---|
[64768d4] | 530 | return msn_ns_write( ic, -1, "PRP %d MFN %s\r\n", ++md->trId, fn ); |
---|
[e0e1546] | 531 | } |
---|
[79bb7e4] | 532 | |
---|
| 533 | const char *msn_normalize_handle( const char *handle ) |
---|
| 534 | { |
---|
| 535 | if( strncmp( handle, "1:", 2 ) == 0 ) |
---|
| 536 | return handle + 2; |
---|
| 537 | else |
---|
| 538 | return handle; |
---|
| 539 | } |
---|