Changeset 5adcc65
- Timestamp:
- 2008-12-21T20:51:12Z (16 years ago)
- Branches:
- master
- Children:
- a349932
- Parents:
- a5f4040
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
skype/skype.c
ra5f4040 r5adcc65 1 1 /* 2 2 * skype.c - Skype plugin for BitlBee 3 * 3 * 4 4 * Copyright (c) 2007, 2008 by Miklos Vajna <vmiklos@frugalware.org> 5 5 * … … 7 7 * 8 8 * Copyright (c) 2006 by Wilmer van der Gaast <wilmer@gaast.net> 9 * 9 * 10 10 * This program is free software; you can redistribute it and/or modify 11 11 * it under the terms of the GNU General Public License as published by … … 20 20 * You should have received a copy of the GNU General Public License 21 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 23 23 * USA. 24 24 */ … … 38 38 */ 39 39 40 typedef enum 41 { 40 typedef enum { 42 41 SKYPE_CALL_RINGING = 1, 43 42 SKYPE_CALL_MISSED, … … 47 46 } skype_call_status; 48 47 49 typedef enum 50 { 48 typedef enum { 51 49 SKYPE_FILETRANSFER_NEW = 1, 52 50 SKYPE_FILETRANSFER_FAILED … … 57 55 */ 58 56 59 struct skype_data 60 { 57 struct skype_data { 61 58 struct im_connection *ic; 62 59 char *username; … … 88 85 /* Using /j #nick we want to have a groupchat with two people. Usually 89 86 * not (default). */ 90 char *groupchat_with;87 char *groupchat_with; 91 88 /* The user who invited us to the chat. */ 92 char *adder;89 char *adder; 93 90 /* If we are waiting for a confirmation about we changed the topic. */ 94 91 int topic_wait; … … 114 111 }; 115 112 116 struct skype_away_state 117 { 113 struct skype_away_state { 118 114 char *code; 119 115 char *full_name; 120 116 }; 121 117 122 struct skype_buddy_ask_data 123 { 118 struct skype_buddy_ask_data { 124 119 struct im_connection *ic; 125 120 /* This is also used for call IDs for simplicity */ … … 131 126 */ 132 127 133 const struct skype_away_state skype_away_state_list[] = 134 { 128 const struct skype_away_state skype_away_state_list[] = { 135 129 { "ONLINE", "Online" }, 136 130 { "SKYPEME", "Skype Me" }, … … 147 141 */ 148 142 149 int skype_write( struct im_connection *ic, char *buf)143 int skype_write(struct im_connection *ic, char *buf) 150 144 { 151 145 struct skype_data *sd = ic->proto_data; … … 159 153 * sd->fd. */ 160 154 poll(pfd, 1, 1000); 161 if(pfd[0].revents & POLLHUP) 162 { 163 imc_logout( ic, TRUE ); 155 if (pfd[0].revents & POLLHUP) { 156 imc_logout(ic, TRUE); 164 157 return FALSE; 165 158 } 166 ssl_write( sd->ssl, buf, len);159 ssl_write(sd->ssl, buf, len); 167 160 168 161 return TRUE; 169 162 } 170 163 171 static void skype_buddy_ask_yes( void *data)164 static void skype_buddy_ask_yes(void *data) 172 165 { 173 166 struct skype_buddy_ask_data *bla = data; 174 167 char *buf = g_strdup_printf("SET USER %s ISAUTHORIZED TRUE", bla->handle); 175 skype_write( bla->ic, buf);168 skype_write(bla->ic, buf); 176 169 g_free(buf); 177 170 g_free(bla->handle); … … 179 172 } 180 173 181 static void skype_buddy_ask_no( void *data)174 static void skype_buddy_ask_no(void *data) 182 175 { 183 176 struct skype_buddy_ask_data *bla = data; 184 177 char *buf = g_strdup_printf("SET USER %s ISAUTHORIZED FALSE", bla->handle); 185 skype_write( bla->ic, buf);178 skype_write(bla->ic, buf); 186 179 g_free(buf); 187 180 g_free(bla->handle); … … 189 182 } 190 183 191 void skype_buddy_ask( 192 { 193 struct skype_buddy_ask_data *bla = g_new0( struct skype_buddy_ask_data, 1);184 void skype_buddy_ask(struct im_connection *ic, char *handle, char *message) 185 { 186 struct skype_buddy_ask_data *bla = g_new0(struct skype_buddy_ask_data, 1); 194 187 char *buf; 195 188 … … 197 190 bla->handle = g_strdup(handle); 198 191 199 buf = g_strdup_printf( 200 imcb_ask( ic, buf, bla, skype_buddy_ask_yes, skype_buddy_ask_no);201 g_free( buf);202 } 203 204 static void skype_call_ask_yes( void *data)192 buf = g_strdup_printf("The user %s wants to add you to his/her buddy list, saying: '%s'.", handle, message); 193 imcb_ask(ic, buf, bla, skype_buddy_ask_yes, skype_buddy_ask_no); 194 g_free(buf); 195 } 196 197 static void skype_call_ask_yes(void *data) 205 198 { 206 199 struct skype_buddy_ask_data *bla = data; 207 200 char *buf = g_strdup_printf("SET CALL %s STATUS INPROGRESS", bla->handle); 208 skype_write( bla->ic, buf);201 skype_write(bla->ic, buf); 209 202 g_free(buf); 210 203 g_free(bla->handle); … … 212 205 } 213 206 214 static void skype_call_ask_no( void *data)207 static void skype_call_ask_no(void *data) 215 208 { 216 209 struct skype_buddy_ask_data *bla = data; 217 210 char *buf = g_strdup_printf("SET CALL %s STATUS FINISHED", bla->handle); 218 skype_write( bla->ic, buf);211 skype_write(bla->ic, buf); 219 212 g_free(buf); 220 213 g_free(bla->handle); … … 222 215 } 223 216 224 void skype_call_ask( 225 { 226 struct skype_buddy_ask_data *bla = g_new0( struct skype_buddy_ask_data, 1);217 void skype_call_ask(struct im_connection *ic, char *call_id, char *message) 218 { 219 struct skype_buddy_ask_data *bla = g_new0(struct skype_buddy_ask_data, 1); 227 220 228 221 bla->ic = ic; 229 222 bla->handle = g_strdup(call_id); 230 223 231 imcb_ask( ic, message, bla, skype_call_ask_yes, skype_call_ask_no);232 } 233 struct groupchat *skype_chat_by_name( struct im_connection *ic, char *name)224 imcb_ask(ic, message, bla, skype_call_ask_yes, skype_call_ask_no); 225 } 226 struct groupchat *skype_chat_by_name(struct im_connection *ic, char *name) 234 227 { 235 228 struct groupchat *ret; 236 229 237 for( ret = ic->groupchats; ret; ret = ret->next ) 238 { 239 if(strcmp(name, ret->title ) == 0 ) 230 for (ret = ic->groupchats; ret; ret = ret->next) 231 if (strcmp(name, ret->title) == 0) 240 232 break; 233 234 return ret; 235 } 236 237 static char *skype_call_strerror(int err) 238 { 239 switch (err) { 240 case 1: 241 return "Miscellaneous error"; 242 case 2: 243 return "User or phone number does not exist."; 244 case 3: 245 return "User is offline"; 246 case 4: 247 return "No proxy found"; 248 case 5: 249 return "Session terminated."; 250 case 6: 251 return "No common codec found."; 252 case 7: 253 return "Sound I/O error."; 254 case 8: 255 return "Problem with remote sound device."; 256 case 9: 257 return "Call blocked by recipient."; 258 case 10: 259 return "Recipient not a friend."; 260 case 11: 261 return "Current user not authorized by recipient."; 262 case 12: 263 return "Sound recording error."; 264 default: 265 return "Unknown error"; 241 266 } 242 243 return ret; 244 } 245 246 static char *skype_call_strerror(int err) 247 { 248 switch(err) { 249 case 1: 250 return "Miscellaneous error"; 251 case 2: 252 return "User or phone number does not exist."; 253 case 3: 254 return "User is offline"; 255 case 4: 256 return "No proxy found"; 257 case 5: 258 return "Session terminated."; 259 case 6: 260 return "No common codec found."; 261 case 7: 262 return "Sound I/O error."; 263 case 8: 264 return "Problem with remote sound device."; 265 case 9: 266 return "Call blocked by recipient."; 267 case 10: 268 return "Recipient not a friend."; 269 case 11: 270 return "Current user not authorized by recipient."; 271 case 12: 272 return "Sound recording error."; 273 default: 274 return "Unknown error"; 275 } 276 } 277 278 static gboolean skype_read_callback( gpointer data, gint fd, b_input_condition cond ) 267 } 268 269 static gboolean skype_read_callback(gpointer data, gint fd, b_input_condition cond) 279 270 { 280 271 struct im_connection *ic = data; … … 284 275 char **lines, **lineptr, *line, *ptr; 285 276 286 if ( !sd || sd->fd == -1)277 if (!sd || sd->fd == -1) 287 278 return FALSE; 288 279 /* Read the whole data. */ 289 st = ssl_read( sd->ssl, buf, sizeof( buf ) ); 290 if( st > 0 ) 291 { 280 st = ssl_read(sd->ssl, buf, sizeof(buf)); 281 if (st > 0) { 292 282 buf[st] = '\0'; 293 283 /* Then split it up to lines. */ 294 284 lines = g_strsplit(buf, "\n", 0); 295 285 lineptr = lines; 296 while((line = *lineptr)) 297 { 298 if(!strlen(line)) 286 while ((line = *lineptr)) { 287 if (!strlen(line)) 299 288 break; 300 if(!strncmp(line, "USERS ", 6)) 301 { 289 if (!strncmp(line, "USERS ", 6)) { 302 290 char **i; 303 291 char **nicks; … … 305 293 nicks = g_strsplit(line + 6, ", ", 0); 306 294 i = nicks; 307 while(*i) 308 { 295 while (*i) { 309 296 g_snprintf(buf, 1024, "GET USER %s ONLINESTATUS\n", *i); 310 skype_write( ic, buf);297 skype_write(ic, buf); 311 298 i++; 312 299 } 313 300 g_strfreev(nicks); 314 } 315 else if(!strncmp(line, "USER ", 5)) 316 { 301 } else if (!strncmp(line, "USER ", 5)) { 317 302 int flags = 0; 318 303 char *status = strrchr(line, ' '); … … 322 307 *ptr = '\0'; 323 308 ptr++; 324 if (!strncmp(ptr, "ONLINESTATUS ", 13) &&309 if (!strncmp(ptr, "ONLINESTATUS ", 13) && 325 310 strcmp(user, sd->username) != 0 326 && strcmp(user, "echo123") != 0) 327 { 311 && strcmp(user, "echo123") != 0) { 328 312 ptr = g_strdup_printf("%s@skype.com", user); 329 313 imcb_add_buddy(ic, ptr, NULL); 330 if (strcmp(status, "OFFLINE") && (strcmp(status, "SKYPEOUT") || !set_getbool(&ic->acc->set, "skypeout_offline")))314 if (strcmp(status, "OFFLINE") && (strcmp(status, "SKYPEOUT") || !set_getbool(&ic->acc->set, "skypeout_offline"))) 331 315 flags |= OPT_LOGGED_IN; 332 if (strcmp(status, "ONLINE") != 0 && strcmp(status, "SKYPEME") != 0)316 if (strcmp(status, "ONLINE") != 0 && strcmp(status, "SKYPEME") != 0) 333 317 flags |= OPT_AWAY; 334 318 imcb_buddy_status(ic, ptr, flags, NULL, NULL); 335 319 g_free(ptr); 336 } 337 else if(!strncmp(ptr, "RECEIVEDAUTHREQUEST ", 20)) 338 { 320 } else if (!strncmp(ptr, "RECEIVEDAUTHREQUEST ", 20)) { 339 321 char *message = ptr + 20; 340 if (strlen(message))322 if (strlen(message)) 341 323 skype_buddy_ask(ic, user, message); 342 } 343 else if(!strncmp(ptr, "BUDDYSTATUS ", 12)) 344 { 324 } else if (!strncmp(ptr, "BUDDYSTATUS ", 12)) { 345 325 char *st = ptr + 12; 346 if(!strcmp(st, "3")) 347 { 326 if (!strcmp(st, "3")) { 348 327 char *buf = g_strdup_printf("%s@skype.com", user); 349 328 imcb_add_buddy(ic, buf, NULL); 350 329 g_free(buf); 351 330 } 352 } 353 else if(!strncmp(ptr, "FULLNAME ", 9)) 331 } else if (!strncmp(ptr, "FULLNAME ", 9)) 354 332 sd->info_fullname = g_strdup_printf("%s", ptr + 9); 355 else if (!strncmp(ptr, "PHONE_HOME ", 11))333 else if (!strncmp(ptr, "PHONE_HOME ", 11)) 356 334 sd->info_phonehome = g_strdup_printf("%s", ptr + 11); 357 else if (!strncmp(ptr, "PHONE_OFFICE ", 13))335 else if (!strncmp(ptr, "PHONE_OFFICE ", 13)) 358 336 sd->info_phoneoffice = g_strdup_printf("%s", ptr + 13); 359 else if (!strncmp(ptr, "PHONE_MOBILE ", 13))337 else if (!strncmp(ptr, "PHONE_MOBILE ", 13)) 360 338 sd->info_phonemobile = g_strdup_printf("%s", ptr + 13); 361 else if (!strncmp(ptr, "NROF_AUTHED_BUDDIES ", 20))339 else if (!strncmp(ptr, "NROF_AUTHED_BUDDIES ", 20)) 362 340 sd->info_nrbuddies = g_strdup_printf("%s", ptr + 20); 363 else if (!strncmp(ptr, "TIMEZONE ", 9))341 else if (!strncmp(ptr, "TIMEZONE ", 9)) 364 342 sd->info_tz = g_strdup_printf("%s", ptr + 9); 365 else if (!strncmp(ptr, "LASTONLINETIMESTAMP ", 20))343 else if (!strncmp(ptr, "LASTONLINETIMESTAMP ", 20)) 366 344 sd->info_seen = g_strdup_printf("%s", ptr + 20); 367 else if (!strncmp(ptr, "BIRTHDAY ", 9))345 else if (!strncmp(ptr, "BIRTHDAY ", 9)) 368 346 sd->info_birthday = g_strdup_printf("%s", ptr + 9); 369 else if (!strncmp(ptr, "SEX ", 4))347 else if (!strncmp(ptr, "SEX ", 4)) 370 348 sd->info_sex = g_strdup_printf("%s", ptr + 4); 371 else if (!strncmp(ptr, "LANGUAGE ", 9))349 else if (!strncmp(ptr, "LANGUAGE ", 9)) 372 350 sd->info_language = g_strdup_printf("%s", ptr + 9); 373 else if (!strncmp(ptr, "COUNTRY ", 8))351 else if (!strncmp(ptr, "COUNTRY ", 8)) 374 352 sd->info_country = g_strdup_printf("%s", ptr + 8); 375 else if (!strncmp(ptr, "PROVINCE ", 9))353 else if (!strncmp(ptr, "PROVINCE ", 9)) 376 354 sd->info_province = g_strdup_printf("%s", ptr + 9); 377 else if (!strncmp(ptr, "CITY ", 5))355 else if (!strncmp(ptr, "CITY ", 5)) 378 356 sd->info_city = g_strdup_printf("%s", ptr + 5); 379 else if (!strncmp(ptr, "HOMEPAGE ", 9))357 else if (!strncmp(ptr, "HOMEPAGE ", 9)) 380 358 sd->info_homepage = g_strdup_printf("%s", ptr + 9); 381 else if(!strncmp(ptr, "ABOUT ", 6)) 382 { 359 else if (!strncmp(ptr, "ABOUT ", 6)) { 383 360 sd->info_about = g_strdup_printf("%s", ptr + 6); 384 361 385 362 GString *st = g_string_new("Contact Information\n"); 386 363 g_string_append_printf(st, "Skype Name: %s\n", user); 387 if(sd->info_fullname) 388 { 389 if(strlen(sd->info_fullname)) 364 if (sd->info_fullname) { 365 if (strlen(sd->info_fullname)) 390 366 g_string_append_printf(st, "Full Name: %s\n", sd->info_fullname); 391 367 g_free(sd->info_fullname); 392 368 } 393 if(sd->info_phonehome) 394 { 395 if(strlen(sd->info_phonehome)) 369 if (sd->info_phonehome) { 370 if (strlen(sd->info_phonehome)) 396 371 g_string_append_printf(st, "Home Phone: %s\n", sd->info_phonehome); 397 372 g_free(sd->info_phonehome); 398 373 } 399 if(sd->info_phoneoffice) 400 { 401 if(strlen(sd->info_phoneoffice)) 374 if (sd->info_phoneoffice) { 375 if (strlen(sd->info_phoneoffice)) 402 376 g_string_append_printf(st, "Office Phone: %s\n", sd->info_phoneoffice); 403 377 g_free(sd->info_phoneoffice); 404 378 } 405 if(sd->info_phonemobile) 406 { 407 if(strlen(sd->info_phonemobile)) 379 if (sd->info_phonemobile) { 380 if (strlen(sd->info_phonemobile)) 408 381 g_string_append_printf(st, "Mobile Phone: %s\n", sd->info_phonemobile); 409 382 g_free(sd->info_phonemobile); 410 383 } 411 384 g_string_append_printf(st, "Personal Information\n"); 412 if(sd->info_nrbuddies) 413 { 414 if(strlen(sd->info_nrbuddies)) 385 if (sd->info_nrbuddies) { 386 if (strlen(sd->info_nrbuddies)) 415 387 g_string_append_printf(st, "Contacts: %s\n", sd->info_nrbuddies); 416 388 g_free(sd->info_nrbuddies); 417 389 } 418 if(sd->info_tz) 419 { 420 if(strlen(sd->info_tz)) 421 { 390 if (sd->info_tz) { 391 if (strlen(sd->info_tz)) { 422 392 char ib[256]; 423 393 time_t t = time(NULL); … … 429 399 g_free(sd->info_tz); 430 400 } 431 if(sd->info_seen) 432 { 433 if(strlen(sd->info_seen)) 434 { 401 if (sd->info_seen) { 402 if (strlen(sd->info_seen)) { 435 403 char ib[256]; 436 404 time_t it = atoi(sd->info_seen); … … 441 409 g_free(sd->info_seen); 442 410 } 443 if(sd->info_birthday) 444 { 445 if(strlen(sd->info_birthday) && strcmp(sd->info_birthday, "0")) 446 { 411 if (sd->info_birthday) { 412 if (strlen(sd->info_birthday) && strcmp(sd->info_birthday, "0")) { 447 413 char ib[256]; 448 414 struct tm tm; … … 459 425 g_free(sd->info_birthday); 460 426 } 461 if(sd->info_sex) 462 { 463 if(strlen(sd->info_sex)) 464 { 427 if (sd->info_sex) { 428 if (strlen(sd->info_sex)) { 465 429 char *iptr = sd->info_sex; 466 while (*iptr++)430 while (*iptr++) 467 431 *iptr = tolower(*iptr); 468 432 g_string_append_printf(st, "Gender: %s\n", sd->info_sex); … … 470 434 g_free(sd->info_sex); 471 435 } 472 if(sd->info_language) 473 { 474 if(strlen(sd->info_language)) 475 { 436 if (sd->info_language) { 437 if (strlen(sd->info_language)) { 476 438 char *iptr = strchr(sd->info_language, ' '); 477 if (iptr)439 if (iptr) 478 440 iptr++; 479 441 else … … 483 445 g_free(sd->info_language); 484 446 } 485 if(sd->info_country) 486 { 487 if(strlen(sd->info_country)) 488 { 447 if (sd->info_country) { 448 if (strlen(sd->info_country)) { 489 449 char *iptr = strchr(sd->info_country, ' '); 490 if (iptr)450 if (iptr) 491 451 iptr++; 492 452 else … … 496 456 g_free(sd->info_country); 497 457 } 498 if(sd->info_province) 499 { 500 if(strlen(sd->info_province)) 458 if (sd->info_province) { 459 if (strlen(sd->info_province)) 501 460 g_string_append_printf(st, "Region: %s\n", sd->info_province); 502 461 g_free(sd->info_province); 503 462 } 504 if(sd->info_city) 505 { 506 if(strlen(sd->info_city)) 463 if (sd->info_city) { 464 if (strlen(sd->info_city)) 507 465 g_string_append_printf(st, "City: %s\n", sd->info_city); 508 466 g_free(sd->info_city); 509 467 } 510 if(sd->info_homepage) 511 { 512 if(strlen(sd->info_homepage)) 468 if (sd->info_homepage) { 469 if (strlen(sd->info_homepage)) 513 470 g_string_append_printf(st, "Homepage: %s\n", sd->info_homepage); 514 471 g_free(sd->info_homepage); 515 472 } 516 if(sd->info_about) 517 { 518 if(strlen(sd->info_about)) 473 if (sd->info_about) { 474 if (strlen(sd->info_about)) 519 475 g_string_append_printf(st, "%s\n", sd->info_about); 520 476 g_free(sd->info_about); … … 523 479 g_string_free(st, TRUE); 524 480 } 525 } 526 else if(!strncmp(line, "CHATMESSAGE ", 12)) 527 { 481 } else if (!strncmp(line, "CHATMESSAGE ", 12)) { 528 482 char *id = strchr(line, ' '); 529 if(++id) 530 { 483 if (++id) { 531 484 char *info = strchr(id, ' '); 532 485 *info = '\0'; 533 486 info++; 534 if(!strcmp(info, "STATUS RECEIVED")) 535 { 487 if (!strcmp(info, "STATUS RECEIVED")) { 536 488 /* New message ID: 537 489 * (1) Request its from field … … 541 493 */ 542 494 g_snprintf(buf, 1024, "GET CHATMESSAGE %s FROM_HANDLE\n", id); 543 skype_write( ic, buf);495 skype_write(ic, buf); 544 496 g_snprintf(buf, 1024, "GET CHATMESSAGE %s BODY\n", id); 545 skype_write( ic, buf);497 skype_write(ic, buf); 546 498 g_snprintf(buf, 1024, "GET CHATMESSAGE %s TYPE\n", id); 547 skype_write( ic, buf);499 skype_write(ic, buf); 548 500 g_snprintf(buf, 1024, "GET CHATMESSAGE %s CHATNAME\n", id); 549 skype_write( ic, buf ); 550 } 551 else if(!strncmp(info, "FROM_HANDLE ", 12)) 552 { 501 skype_write(ic, buf); 502 } else if (!strncmp(info, "FROM_HANDLE ", 12)) { 553 503 info += 12; 554 504 /* New from field value. Store … … 558 508 g_free(sd->handle); 559 509 sd->handle = g_strdup_printf("%s@skype.com", info); 560 } 561 else if(!strncmp(info, "EDITED_BY ", 10)) 562 { 510 } else if (!strncmp(info, "EDITED_BY ", 10)) { 563 511 info += 10; 564 512 /* This is the same as … … 569 517 g_free(sd->handle); 570 518 sd->handle = g_strdup_printf("%s@skype.com", info); 571 } 572 else if(!strncmp(info, "BODY ", 5)) 573 { 519 } else if (!strncmp(info, "BODY ", 5)) { 574 520 info += 5; 575 521 sd->body = g_list_append(sd->body, g_strdup(info)); 576 } 577 else if(!strncmp(info, "TYPE ", 5)) 578 { 522 } else if (!strncmp(info, "TYPE ", 5)) { 579 523 info += 5; 580 524 g_free(sd->type); 581 525 sd->type = g_strdup(info); 582 } 583 else if(!strncmp(info, "CHATNAME ", 9)) 584 { 526 } else if (!strncmp(info, "CHATNAME ", 9)) { 585 527 info += 9; 586 if(sd->handle && sd->body && sd->type) 587 { 528 if (sd->handle && sd->body && sd->type) { 588 529 struct groupchat *gc = skype_chat_by_name(ic, info); 589 530 int i; 590 for(i=0;i<g_list_length(sd->body);i++) 591 { 531 for (i = 0; i < g_list_length(sd->body); i++) { 592 532 char *body = g_list_nth_data(sd->body, i); 593 if(!strcmp(sd->type, "SAID") || !strcmp(sd->type, "EMOTED")) 594 { 533 if (!strcmp(sd->type, "SAID") || !strcmp(sd->type, "EMOTED")) { 595 534 char *st; 596 if (!strcmp(sd->type, "SAID"))535 if (!strcmp(sd->type, "SAID")) 597 536 st = g_strdup(body); 598 537 else 599 {600 538 st = g_strdup_printf("/me %s", body); 601 } 602 if(!gc) 539 if (!gc) 603 540 /* Private message */ 604 541 imcb_buddy_msg(ic, sd->handle, st, 0, 0); … … 607 544 imcb_chat_msg(gc, sd->handle, st, 0, 0); 608 545 g_free(st); 609 } 610 else if(!strcmp(sd->type, "SETTOPIC")) 611 { 612 if(gc) 546 } else if (!strcmp(sd->type, "SETTOPIC")) { 547 if (gc) 613 548 imcb_chat_topic(gc, sd->handle, body, 0); 614 } 615 else if(!strcmp(sd->type, "LEFT")) 616 { 617 if(gc) 549 } else if (!strcmp(sd->type, "LEFT")) { 550 if (gc) 618 551 imcb_chat_remove_buddy(gc, sd->handle, NULL); 619 552 } … … 624 557 } 625 558 } 626 } 627 else if(!strncmp(line, "CALL ", 5)) 628 { 559 } else if (!strncmp(line, "CALL ", 5)) { 629 560 char *id = strchr(line, ' '); 630 if(++id) 631 { 561 if (++id) { 632 562 char *info = strchr(id, ' '); 633 563 *info = '\0'; 634 564 info++; 635 if (!strncmp(info, "FAILUREREASON ", 14))565 if (!strncmp(info, "FAILUREREASON ", 14)) 636 566 sd->failurereason = atoi(strchr(info, ' ')); 637 else if(!strcmp(info, "STATUS RINGING")) 638 { 639 if(sd->call_id) 567 else if (!strcmp(info, "STATUS RINGING")) { 568 if (sd->call_id) 640 569 g_free(sd->call_id); 641 570 sd->call_id = g_strdup(id); 642 571 g_snprintf(buf, 1024, "GET CALL %s PARTNER_HANDLE\n", id); 643 skype_write( ic, buf);572 skype_write(ic, buf); 644 573 sd->call_status = SKYPE_CALL_RINGING; 645 } 646 else if(!strcmp(info, "STATUS MISSED")) 647 { 574 } else if (!strcmp(info, "STATUS MISSED")) { 648 575 g_snprintf(buf, 1024, "GET CALL %s PARTNER_HANDLE\n", id); 649 skype_write( ic, buf);576 skype_write(ic, buf); 650 577 sd->call_status = SKYPE_CALL_MISSED; 651 } 652 else if(!strcmp(info, "STATUS CANCELLED")) 653 { 578 } else if (!strcmp(info, "STATUS CANCELLED")) { 654 579 g_snprintf(buf, 1024, "GET CALL %s PARTNER_HANDLE\n", id); 655 skype_write( ic, buf);580 skype_write(ic, buf); 656 581 sd->call_status = SKYPE_CALL_CANCELLED; 657 } 658 else if(!strcmp(info, "STATUS FINISHED")) 659 { 582 } else if (!strcmp(info, "STATUS FINISHED")) { 660 583 g_snprintf(buf, 1024, "GET CALL %s PARTNER_HANDLE\n", id); 661 skype_write( ic, buf);584 skype_write(ic, buf); 662 585 sd->call_status = SKYPE_CALL_FINISHED; 663 } 664 else if(!strcmp(info, "STATUS REFUSED")) 665 { 586 } else if (!strcmp(info, "STATUS REFUSED")) { 666 587 g_snprintf(buf, 1024, "GET CALL %s PARTNER_HANDLE\n", id); 667 skype_write( ic, buf);588 skype_write(ic, buf); 668 589 sd->call_status = SKYPE_CALL_REFUSED; 669 } 670 else if(!strcmp(info, "STATUS UNPLACED")) 671 { 672 if(sd->call_id) 590 } else if (!strcmp(info, "STATUS UNPLACED")) { 591 if (sd->call_id) 673 592 g_free(sd->call_id); 674 593 /* Save the ID for later usage (Cancel/Finish). */ 675 594 sd->call_id = g_strdup(id); 676 595 sd->call_out = TRUE; 677 } 678 else if(!strcmp(info, "STATUS FAILED")) 679 { 596 } else if (!strcmp(info, "STATUS FAILED")) { 680 597 imcb_error(ic, "Call failed: %s", skype_call_strerror(sd->failurereason)); 681 598 sd->call_id = NULL; 682 } 683 else if(!strncmp(info, "DURATION ", 9)) 684 { 685 if(sd->call_duration) 599 } else if (!strncmp(info, "DURATION ", 9)) { 600 if (sd->call_duration) 686 601 g_free(sd->call_duration); 687 602 sd->call_duration = g_strdup(info+9); 688 } 689 else if(!strncmp(info, "PARTNER_HANDLE ", 15)) 690 { 603 } else if (!strncmp(info, "PARTNER_HANDLE ", 15)) { 691 604 info += 15; 692 if(sd->call_status) { 693 switch(sd->call_status) 694 { 695 case SKYPE_CALL_RINGING: 696 if(sd->call_out) 697 imcb_log(ic, "You are currently ringing the user %s.", info); 698 else 699 { 700 g_snprintf(buf, 1024, "The user %s is currently ringing you.", info); 701 skype_call_ask(ic, sd->call_id, buf); 702 } 703 break; 704 case SKYPE_CALL_MISSED: 705 imcb_log(ic, "You have missed a call from user %s.", info); 706 break; 707 case SKYPE_CALL_CANCELLED: 708 imcb_log(ic, "You cancelled the call to the user %s.", info); 709 sd->call_status = 0; 710 sd->call_out = FALSE; 711 break; 712 case SKYPE_CALL_REFUSED: 713 if(sd->call_out) 714 imcb_log(ic, "The user %s refused the call.", info); 715 else 716 imcb_log(ic, "You refused the call from user %s.", info); 717 sd->call_out = FALSE; 718 break; 719 case SKYPE_CALL_FINISHED: 720 if(sd->call_duration) 721 imcb_log(ic, "You finished the call to the user %s (duration: %s seconds).", info, sd->call_duration); 722 else 723 imcb_log(ic, "You finished the call to the user %s.", info); 724 sd->call_out = FALSE; 725 break; 726 default: 727 /* Don't be noisy, ignore other statuses for now. */ 728 break; 605 if (sd->call_status) { 606 switch (sd->call_status) { 607 case SKYPE_CALL_RINGING: 608 if (sd->call_out) 609 imcb_log(ic, "You are currently ringing the user %s.", info); 610 else { 611 g_snprintf(buf, 1024, "The user %s is currently ringing you.", info); 612 skype_call_ask(ic, sd->call_id, buf); 613 } 614 break; 615 case SKYPE_CALL_MISSED: 616 imcb_log(ic, "You have missed a call from user %s.", info); 617 break; 618 case SKYPE_CALL_CANCELLED: 619 imcb_log(ic, "You cancelled the call to the user %s.", info); 620 sd->call_status = 0; 621 sd->call_out = FALSE; 622 break; 623 case SKYPE_CALL_REFUSED: 624 if (sd->call_out) 625 imcb_log(ic, "The user %s refused the call.", info); 626 else 627 imcb_log(ic, "You refused the call from user %s.", info); 628 sd->call_out = FALSE; 629 break; 630 case SKYPE_CALL_FINISHED: 631 if (sd->call_duration) 632 imcb_log(ic, "You finished the call to the user %s (duration: %s seconds).", info, sd->call_duration); 633 else 634 imcb_log(ic, "You finished the call to the user %s.", info); 635 sd->call_out = FALSE; 636 break; 637 default: 638 /* Don't be noisy, ignore other statuses for now. */ 639 break; 729 640 } 730 641 sd->call_status = 0; … … 732 643 } 733 644 } 734 } 735 else if(!strncmp(line, "FILETRANSFER ", 13)) 736 { 645 } else if (!strncmp(line, "FILETRANSFER ", 13)) { 737 646 char *id = strchr(line, ' '); 738 if(++id) 739 { 647 if (++id) { 740 648 char *info = strchr(id, ' '); 741 649 *info = '\0'; 742 650 info++; 743 if(!strcmp(info, "STATUS NEW")) 744 { 651 if (!strcmp(info, "STATUS NEW")) { 745 652 g_snprintf(buf, 1024, "GET FILETRANSFER %s PARTNER_HANDLE\n", id); 746 skype_write( ic, buf);653 skype_write(ic, buf); 747 654 sd->filetransfer_status = SKYPE_FILETRANSFER_NEW; 748 } 749 else if(!strcmp(info, "STATUS FAILED")) 750 { 655 } else if (!strcmp(info, "STATUS FAILED")) { 751 656 g_snprintf(buf, 1024, "GET FILETRANSFER %s PARTNER_HANDLE\n", id); 752 skype_write( ic, buf);657 skype_write(ic, buf); 753 658 sd->filetransfer_status = SKYPE_FILETRANSFER_FAILED; 754 } 755 else if(!strncmp(info, "PARTNER_HANDLE ", 15)) 756 { 659 } else if (!strncmp(info, "PARTNER_HANDLE ", 15)) { 757 660 info += 15; 758 if(sd->filetransfer_status) { 759 switch(sd->filetransfer_status) 760 { 761 case SKYPE_FILETRANSFER_NEW: 762 imcb_log(ic, "The user %s offered a new file for you.", info); 763 break; 764 case SKYPE_FILETRANSFER_FAILED: 765 imcb_log(ic, "Failed to transfer file from user %s.", info); 766 break; 661 if (sd->filetransfer_status) { 662 switch (sd->filetransfer_status) { 663 case SKYPE_FILETRANSFER_NEW: 664 imcb_log(ic, "The user %s offered a new file for you.", info); 665 break; 666 case SKYPE_FILETRANSFER_FAILED: 667 imcb_log(ic, "Failed to transfer file from user %s.", info); 668 break; 767 669 } 768 670 sd->filetransfer_status = 0; … … 770 672 } 771 673 } 772 } 773 else if(!strncmp(line, "CHAT ", 5)) 774 { 674 } else if (!strncmp(line, "CHAT ", 5)) { 775 675 char *id = strchr(line, ' '); 776 if(++id) 777 { 676 if (++id) { 778 677 char *info = strchr(id, ' '); 779 if (info)678 if (info) 780 679 *info = '\0'; 781 680 info++; 782 681 /* Remove fake chat if we created one in skype_chat_with() */ 783 682 struct groupchat *gc = skype_chat_by_name(ic, ""); 784 if (gc)683 if (gc) 785 684 imcb_chat_free(gc); 786 if(!strcmp(info, "STATUS MULTI_SUBSCRIBED")) 787 { 788 imcb_chat_new( ic, id ); 685 if (!strcmp(info, "STATUS MULTI_SUBSCRIBED")) { 686 imcb_chat_new(ic, id); 789 687 g_snprintf(buf, 1024, "GET CHAT %s ADDER\n", id); 790 688 skype_write(ic, buf); 791 689 g_snprintf(buf, 1024, "GET CHAT %s TOPIC\n", id); 792 690 skype_write(ic, buf); 793 } 794 else if(!strcmp(info, "STATUS DIALOG") && sd->groupchat_with) 795 { 796 gc = imcb_chat_new( ic, id ); 691 } else if (!strcmp(info, "STATUS DIALOG") && sd->groupchat_with) { 692 gc = imcb_chat_new(ic, id); 797 693 /* According to the docs this 798 694 * is necessary. However it … … 812 708 g_snprintf(buf, 1024, "GET CHAT %s TOPIC\n", id); 813 709 skype_write(ic, buf); 814 } 815 else if(!strcmp(info, "STATUS UNSUBSCRIBED")) 816 { 710 } else if (!strcmp(info, "STATUS UNSUBSCRIBED")) { 817 711 gc = skype_chat_by_name(ic, id); 818 if(gc) 819 gc->data = (void*)FALSE; 820 } 821 else if(!strncmp(info, "ADDER ", 6)) 822 { 712 if (gc) 713 gc->data = (void *)FALSE; 714 } else if (!strncmp(info, "ADDER ", 6)) { 823 715 info += 6; 824 716 g_free(sd->adder); 825 717 sd->adder = g_strdup_printf("%s@skype.com", info); 826 } 827 else if(!strncmp(info, "TOPIC ", 6)) 828 { 718 } else if (!strncmp(info, "TOPIC ", 6)) { 829 719 info += 6; 830 720 gc = skype_chat_by_name(ic, id); 831 if(gc && (sd->adder || sd->topic_wait)) 832 { 833 if(sd->topic_wait) 834 { 721 if (gc && (sd->adder || sd->topic_wait)) { 722 if (sd->topic_wait) { 835 723 sd->adder = g_strdup(sd->username); 836 724 sd->topic_wait = 0; … … 840 728 sd->adder = NULL; 841 729 } 842 } 843 else if(!strncmp(info, "ACTIVEMEMBERS ", 14)) 844 { 730 } else if (!strncmp(info, "ACTIVEMEMBERS ", 14)) { 845 731 info += 14; 846 732 gc = skype_chat_by_name(ic, id); … … 849 735 * so that we won't rejoin 850 736 * after a /part. */ 851 if(gc && !gc->data) 852 { 737 if (gc && !gc->data) { 853 738 char **members = g_strsplit(info, " ", 0); 854 739 int i; 855 for(i=0;members[i];i++) 856 { 857 if(!strcmp(members[i], sd->username)) 740 for (i = 0; members[i]; i++) { 741 if (!strcmp(members[i], sd->username)) 858 742 continue; 859 743 g_snprintf(buf, 1024, "%s@skype.com", members[i]); 860 if (!g_list_find_custom(gc->in_room, buf, (GCompareFunc)strcmp))744 if (!g_list_find_custom(gc->in_room, buf, (GCompareFunc)strcmp)) 861 745 imcb_chat_add_buddy(gc, buf); 862 746 } … … 866 750 } 867 751 } 868 } 869 else if(!strncmp(line, "PASSWORD ", 9)) 870 { 871 if(!strncmp(line+9, "OK", 2)) 752 } else if (!strncmp(line, "PASSWORD ", 9)) { 753 if (!strncmp(line+9, "OK", 2)) 872 754 imcb_connected(ic); 873 else 874 { 755 else { 875 756 imcb_error(ic, "Authentication Failed"); 876 imc_logout( ic, TRUE);757 imc_logout(ic, TRUE); 877 758 } 878 } 879 else if(!strncmp(line, "PROFILE PSTN_BALANCE ", 21)) 880 { 759 } else if (!strncmp(line, "PROFILE PSTN_BALANCE ", 21)) 881 760 imcb_log(ic, "SkypeOut balance value is '%s'.", line+21); 882 } 883 else if(!strncmp(line, "PING", 4)) 884 { 761 else if (!strncmp(line, "PING", 4)) { 885 762 g_snprintf(buf, 1024, "PONG\n"); 886 763 skype_write(ic, buf); 887 } 888 else if(!strncmp(line, "CHATS ", 6)) 889 { 764 } else if (!strncmp(line, "CHATS ", 6)) { 890 765 char **i; 891 766 char **chats = g_strsplit(line + 6, ", ", 0); 892 767 893 768 i = chats; 894 while (*i) 895 { 769 while (*i) { 896 770 g_snprintf(buf, 1024, "GET CHAT %s STATUS\n", *i); 897 skype_write( ic, buf);771 skype_write(ic, buf); 898 772 g_snprintf(buf, 1024, "GET CHAT %s ACTIVEMEMBERS\n", *i); 899 skype_write( ic, buf);773 skype_write(ic, buf); 900 774 i++; 901 775 } … … 905 779 } 906 780 g_strfreev(lines); 907 } 908 else if( st == 0 || ( st < 0 && !sockerr_again() ) ) 909 { 910 closesocket( sd->fd ); 781 } else if (st == 0 || (st < 0 && !sockerr_again())) { 782 closesocket(sd->fd); 911 783 sd->fd = -1; 912 784 913 imcb_error( ic, "Error while reading from server");914 imc_logout( ic, TRUE);785 imcb_error(ic, "Error while reading from server"); 786 imc_logout(ic, TRUE); 915 787 return FALSE; 916 788 } … … 918 790 } 919 791 920 gboolean skype_start_stream( struct im_connection *ic)792 gboolean skype_start_stream(struct im_connection *ic) 921 793 { 922 794 struct skype_data *sd = ic->proto_data; … … 924 796 int st; 925 797 926 if (!sd)798 if (!sd) 927 799 return FALSE; 928 800 929 if ( sd->bfd <= 0)930 sd->bfd = b_input_add( sd->fd, GAIM_INPUT_READ, skype_read_callback, ic);801 if (sd->bfd <= 0) 802 sd->bfd = b_input_add(sd->fd, GAIM_INPUT_READ, skype_read_callback, ic); 931 803 932 804 /* Log in */ 933 805 buf = g_strdup_printf("USERNAME %s\n", ic->acc->user); 934 st = skype_write( ic, buf);806 st = skype_write(ic, buf); 935 807 g_free(buf); 936 808 buf = g_strdup_printf("PASSWORD %s\n", ic->acc->pass); 937 st = skype_write( ic, buf);809 st = skype_write(ic, buf); 938 810 g_free(buf); 939 811 940 812 /* This will download all buddies. */ 941 813 buf = g_strdup_printf("SEARCH FRIENDS\n"); 942 st = skype_write( ic, buf);814 st = skype_write(ic, buf); 943 815 g_free(buf); 944 816 buf = g_strdup_printf("SET USERSTATUS ONLINE\n"); 945 skype_write( ic, buf);817 skype_write(ic, buf); 946 818 g_free(buf); 947 819 … … 949 821 if (set_getbool(&ic->acc->set, "auto_join")) { 950 822 buf = g_strdup_printf("SEARCH BOOKMARKEDCHATS\n"); 951 skype_write( ic, buf);823 skype_write(ic, buf); 952 824 g_free(buf); 953 825 } … … 955 827 } 956 828 957 gboolean skype_connected( gpointer data, void *source, b_input_condition cond)829 gboolean skype_connected(gpointer data, void *source, b_input_condition cond) 958 830 { 959 831 struct im_connection *ic = data; 960 832 struct skype_data *sd = ic->proto_data; 961 if(!source) 962 { 833 if (!source) { 963 834 sd->ssl = NULL; 964 imcb_error( ic, "Could not connect to server");965 imc_logout( ic, TRUE);835 imcb_error(ic, "Could not connect to server"); 836 imc_logout(ic, TRUE); 966 837 return FALSE; 967 838 } 968 imcb_log( ic, "Connected to server, logging in");839 imcb_log(ic, "Connected to server, logging in"); 969 840 return skype_start_stream(ic); 970 841 } 971 842 972 static void skype_login( account_t *acc)973 { 974 struct im_connection *ic = imcb_new( acc);975 struct skype_data *sd = g_new0( struct skype_data, 1);843 static void skype_login(account_t *acc) 844 { 845 struct im_connection *ic = imcb_new(acc); 846 struct skype_data *sd = g_new0(struct skype_data, 1); 976 847 977 848 ic->proto_data = sd; 978 849 979 imcb_log( ic, "Connecting");980 sd->ssl = ssl_connect(set_getstr( &acc->set, "server" ), set_getint( &acc->set, "port" ), skype_connected, ic);981 sd->fd = sd->ssl ? ssl_getfd( sd->ssl) : -1;982 sd->username = g_strdup( acc->user);850 imcb_log(ic, "Connecting"); 851 sd->ssl = ssl_connect(set_getstr(&acc->set, "server"), set_getint(&acc->set, "port"), skype_connected, ic); 852 sd->fd = sd->ssl ? ssl_getfd(sd->ssl) : -1; 853 sd->username = g_strdup(acc->user); 983 854 984 855 sd->ic = ic; … … 988 859 } 989 860 990 static void skype_logout( struct im_connection *ic)861 static void skype_logout(struct im_connection *ic) 991 862 { 992 863 struct skype_data *sd = ic->proto_data; … … 994 865 995 866 buf = g_strdup_printf("SET USERSTATUS OFFLINE\n"); 996 skype_write( ic, buf);867 skype_write(ic, buf); 997 868 g_free(buf); 998 869 … … 1003 874 } 1004 875 1005 static int skype_buddy_msg( struct im_connection *ic, char *who, char *message, int flags)876 static int skype_buddy_msg(struct im_connection *ic, char *who, char *message, int flags) 1006 877 { 1007 878 char *buf, *ptr, *nick; … … 1010 881 nick = g_strdup(who); 1011 882 ptr = strchr(nick, '@'); 1012 if (ptr)883 if (ptr) 1013 884 *ptr = '\0'; 1014 885 … … 1018 889 buf = g_strdup_printf("MESSAGE %s %s\n", nick, message); 1019 890 g_free(nick); 1020 st = skype_write( ic, buf);891 st = skype_write(ic, buf); 1021 892 g_free(buf); 1022 893 … … 1024 895 } 1025 896 1026 const struct skype_away_state *skype_away_state_by_name( char *name)897 const struct skype_away_state *skype_away_state_by_name(char *name) 1027 898 { 1028 899 int i; 1029 900 1030 for ( i = 0; skype_away_state_list[i].full_name; i ++)1031 if ( g_strcasecmp( skype_away_state_list[i].full_name, name ) == 0)1032 return ( skype_away_state_list + i );901 for (i = 0; skype_away_state_list[i].full_name; i++) 902 if (g_strcasecmp(skype_away_state_list[i].full_name, name) == 0) 903 return skype_away_state_list + i; 1033 904 1034 905 return NULL; 1035 906 } 1036 907 1037 static void skype_set_away( struct im_connection *ic, char *state_txt, char *message)908 static void skype_set_away(struct im_connection *ic, char *state_txt, char *message) 1038 909 { 1039 910 const struct skype_away_state *state; 1040 911 char *buf; 1041 912 1042 if ( strcmp( state_txt, GAIM_AWAY_CUSTOM ) == 0)1043 state = skype_away_state_by_name( "Away");913 if (strcmp(state_txt, GAIM_AWAY_CUSTOM) == 0) 914 state = skype_away_state_by_name("Away"); 1044 915 else 1045 state = skype_away_state_by_name( state_txt);916 state = skype_away_state_by_name(state_txt); 1046 917 buf = g_strdup_printf("SET USERSTATUS %s\n", state->code); 1047 skype_write( ic, buf);1048 g_free(buf); 1049 } 1050 1051 static GList *skype_away_states( struct im_connection *ic)1052 { 1053 static GList *l = NULL;918 skype_write(ic, buf); 919 g_free(buf); 920 } 921 922 static GList *skype_away_states(struct im_connection *ic) 923 { 924 static GList *l; 1054 925 int i; 1055 1056 if ( l == NULL)1057 for ( i = 0; skype_away_state_list[i].full_name; i ++)1058 l = g_list_append( l, (void*) skype_away_state_list[i].full_name);1059 926 927 if (l == NULL) 928 for (i = 0; skype_away_state_list[i].full_name; i++) 929 l = g_list_append(l, (void *)skype_away_state_list[i].full_name); 930 1060 931 return l; 1061 932 } 1062 933 1063 static char *skype_set_display_name( set_t *set, char *value)934 static char *skype_set_display_name(set_t *set, char *value) 1064 935 { 1065 936 account_t *acc = set->data; … … 1068 939 1069 940 buf = g_strdup_printf("SET PROFILE FULLNAME %s", value); 1070 skype_write( ic, buf);1071 g_free(buf); 1072 return (value);1073 } 1074 1075 static char *skype_set_balance( set_t *set, char *value)941 skype_write(ic, buf); 942 g_free(buf); 943 return value; 944 } 945 946 static char *skype_set_balance(set_t *set, char *value) 1076 947 { 1077 948 account_t *acc = set->data; … … 1080 951 1081 952 buf = g_strdup_printf("GET PROFILE PSTN_BALANCE"); 1082 skype_write( ic, buf);1083 g_free(buf); 1084 return (value);1085 } 1086 1087 static char *skype_set_call( set_t *set, char *value)953 skype_write(ic, buf); 954 g_free(buf); 955 return value; 956 } 957 958 static char *skype_set_call(set_t *set, char *value) 1088 959 { 1089 960 account_t *acc = set->data; … … 1092 963 char *nick, *ptr, *buf; 1093 964 1094 if(value) 1095 { 965 if (value) { 1096 966 user_t *u = user_find(acc->irc, value); 1097 967 /* We are starting a call */ 1098 if (!u)968 if (!u) 1099 969 nick = g_strdup(value); 1100 970 else 1101 971 nick = g_strdup(u->handle); 1102 972 ptr = strchr(nick, '@'); 1103 if (ptr)973 if (ptr) 1104 974 *ptr = '\0'; 1105 975 1106 976 buf = g_strdup_printf("CALL %s", nick); 1107 skype_write( ic, buf);977 skype_write(ic, buf); 1108 978 g_free(buf); 1109 979 g_free(nick); 1110 } 1111 else 1112 { 980 } else { 1113 981 /* We are ending a call */ 1114 if(sd->call_id) 1115 { 982 if (sd->call_id) { 1116 983 buf = g_strdup_printf("SET CALL %s STATUS FINISHED", sd->call_id); 1117 skype_write( ic, buf);984 skype_write(ic, buf); 1118 985 g_free(buf); 1119 986 g_free(sd->call_id); 1120 987 sd->call_id = NULL; 1121 } 1122 else 1123 { 988 } else 1124 989 imcb_error(ic, "There are no active calls currently."); 1125 }1126 990 } 1127 return (value);1128 } 1129 1130 static void skype_add_buddy( struct im_connection *ic, char *who, char *group)991 return value; 992 } 993 994 static void skype_add_buddy(struct im_connection *ic, char *who, char *group) 1131 995 { 1132 996 char *buf, *nick, *ptr; … … 1134 998 nick = g_strdup(who); 1135 999 ptr = strchr(nick, '@'); 1136 if (ptr)1000 if (ptr) 1137 1001 *ptr = '\0'; 1138 1002 buf = g_strdup_printf("SET USER %s BUDDYSTATUS 2 Please authorize me\n", nick); 1139 skype_write( ic, buf);1003 skype_write(ic, buf); 1140 1004 g_free(nick); 1141 1005 } 1142 1006 1143 static void skype_remove_buddy( struct im_connection *ic, char *who, char *group)1007 static void skype_remove_buddy(struct im_connection *ic, char *who, char *group) 1144 1008 { 1145 1009 char *buf, *nick, *ptr; … … 1147 1011 nick = g_strdup(who); 1148 1012 ptr = strchr(nick, '@'); 1149 if (ptr)1013 if (ptr) 1150 1014 *ptr = '\0'; 1151 1015 buf = g_strdup_printf("SET USER %s BUDDYSTATUS 1\n", nick); 1152 skype_write( ic, buf);1016 skype_write(ic, buf); 1153 1017 g_free(nick); 1154 1018 } 1155 1019 1156 void skype_chat_msg( struct groupchat *gc, char *message, int flags)1020 void skype_chat_msg(struct groupchat *gc, char *message, int flags) 1157 1021 { 1158 1022 struct im_connection *ic = gc->ic; 1159 1023 char *buf; 1160 1024 buf = g_strdup_printf("CHATMESSAGE %s %s\n", gc->title, message); 1161 skype_write( ic, buf);1162 g_free(buf); 1163 } 1164 1165 void skype_chat_leave( struct groupchat *gc)1025 skype_write(ic, buf); 1026 g_free(buf); 1027 } 1028 1029 void skype_chat_leave(struct groupchat *gc) 1166 1030 { 1167 1031 struct im_connection *ic = gc->ic; 1168 1032 char *buf; 1169 1033 buf = g_strdup_printf("ALTER CHAT %s LEAVE\n", gc->title); 1170 skype_write( ic, buf);1171 g_free(buf); 1172 gc->data = (void *)TRUE;1034 skype_write(ic, buf); 1035 g_free(buf); 1036 gc->data = (void *)TRUE; 1173 1037 } 1174 1038 … … 1179 1043 nick = g_strdup(message); 1180 1044 ptr = strchr(nick, '@'); 1181 if (ptr)1045 if (ptr) 1182 1046 *ptr = '\0'; 1183 1047 buf = g_strdup_printf("ALTER CHAT %s ADDMEMBERS %s\n", gc->title, nick); 1184 skype_write( ic, buf);1048 skype_write(ic, buf); 1185 1049 g_free(buf); 1186 1050 g_free(nick); … … 1193 1057 char *buf; 1194 1058 buf = g_strdup_printf("ALTER CHAT %s SETTOPIC %s\n", gc->title, message); 1195 skype_write( ic, buf);1059 skype_write(ic, buf); 1196 1060 g_free(buf); 1197 1061 sd->topic_wait = 1; … … 1204 1068 nick = g_strdup(who); 1205 1069 ptr = strchr(nick, '@'); 1206 if (ptr)1070 if (ptr) 1207 1071 *ptr = '\0'; 1208 1072 buf = g_strdup_printf("CHAT CREATE %s\n", nick); … … 1213 1077 /* We create a fake chat for now. We will replace it with a real one in 1214 1078 * the real callback. */ 1215 return (imcb_chat_new( ic, "" ));1079 return imcb_chat_new(ic, ""); 1216 1080 } 1217 1081 … … 1221 1085 nick = g_strdup(who); 1222 1086 ptr = strchr(nick, '@'); 1223 if (ptr)1087 if (ptr) 1224 1088 *ptr = '\0'; 1225 1089 buf = g_strdup_printf("GET USER %s FULLNAME\n", nick); … … 1270 1134 } 1271 1135 1272 static void skype_set_my_name( struct im_connection *ic, char *info)1273 { 1274 skype_set_display_name( set_find( &ic->acc->set, "display_name" ), info);1275 } 1276 1277 static void skype_init( account_t *acc)1136 static void skype_set_my_name(struct im_connection *ic, char *info) 1137 { 1138 skype_set_display_name(set_find(&ic->acc->set, "display_name"), info); 1139 } 1140 1141 static void skype_init(account_t *acc) 1278 1142 { 1279 1143 set_t *s; 1280 1144 1281 s = set_add( &acc->set, "server", SKYPE_DEFAULT_SERVER, set_eval_account, acc);1145 s = set_add(&acc->set, "server", SKYPE_DEFAULT_SERVER, set_eval_account, acc); 1282 1146 s->flags |= ACC_SET_OFFLINE_ONLY; 1283 1147 1284 s = set_add( &acc->set, "port", SKYPE_DEFAULT_PORT, set_eval_int, acc);1148 s = set_add(&acc->set, "port", SKYPE_DEFAULT_PORT, set_eval_int, acc); 1285 1149 s->flags |= ACC_SET_OFFLINE_ONLY; 1286 1150 1287 s = set_add( &acc->set, "display_name", NULL, skype_set_display_name, acc);1151 s = set_add(&acc->set, "display_name", NULL, skype_set_display_name, acc); 1288 1152 s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY; 1289 1153 1290 s = set_add( &acc->set, "call", NULL, skype_set_call, acc);1154 s = set_add(&acc->set, "call", NULL, skype_set_call, acc); 1291 1155 s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY; 1292 1156 1293 s = set_add( &acc->set, "balance", NULL, skype_set_balance, acc);1157 s = set_add(&acc->set, "balance", NULL, skype_set_balance, acc); 1294 1158 s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY; 1295 1159 1296 s = set_add( &acc->set, "skypeout_offline", "true", set_eval_bool, acc);1297 1298 s = set_add( &acc->set, "skypeconsole", "false", set_eval_bool, acc);1160 s = set_add(&acc->set, "skypeout_offline", "true", set_eval_bool, acc); 1161 1162 s = set_add(&acc->set, "skypeconsole", "false", set_eval_bool, acc); 1299 1163 s->flags |= ACC_SET_OFFLINE_ONLY; 1300 1164 1301 s = set_add( &acc->set, "auto_join", "false", set_eval_bool, acc);1165 s = set_add(&acc->set, "auto_join", "false", set_eval_bool, acc); 1302 1166 s->flags |= ACC_SET_OFFLINE_ONLY; 1303 1167 } … … 1305 1169 void init_plugin(void) 1306 1170 { 1307 struct prpl *ret = g_new0( struct prpl, 1);1171 struct prpl *ret = g_new0(struct prpl, 1); 1308 1172 1309 1173 ret->name = "skype"; … … 1324 1188 ret->handle_cmp = g_strcasecmp; 1325 1189 ret->chat_topic = skype_chat_topic; 1326 register_protocol( ret);1190 register_protocol(ret); 1327 1191 } 1328 1192
Note: See TracChangeset
for help on using the changeset viewer.