[7daec06] | 1 | /* |
---|
| 2 | * skype.c - Skype plugin for BitlBee |
---|
| 3 | * |
---|
[680920f] | 4 | * Copyright (c) 2007, 2008 by Miklos Vajna <vmiklos@frugalware.org> |
---|
[f06e3ac] | 5 | * |
---|
[7daec06] | 6 | * Several ideas are used from the BitlBee Jabber plugin, which is |
---|
| 7 | * |
---|
| 8 | * Copyright (c) 2006 by Wilmer van der Gaast <wilmer@gaast.net> |
---|
| 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 |
---|
| 21 | * along with this program; if not, write to the Free Software |
---|
| 22 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
---|
| 23 | * USA. |
---|
[f06e3ac] | 24 | */ |
---|
[7daec06] | 25 | |
---|
[f9c3e7b] | 26 | #define _XOPEN_SOURCE |
---|
[f06e3ac] | 27 | #include <stdio.h> |
---|
[ed2e37f] | 28 | #include <poll.h> |
---|
[f06e3ac] | 29 | #include <bitlbee.h> |
---|
[c7304b2] | 30 | #include <bitlbee/ssl_client.h> |
---|
[72aa7f0] | 31 | #include <glib.h> |
---|
[f06e3ac] | 32 | |
---|
[f5aedd91] | 33 | #define SKYPE_DEFAULT_SERVER "localhost" |
---|
[4bbd9db] | 34 | #define SKYPE_DEFAULT_PORT "2727" |
---|
[f06e3ac] | 35 | |
---|
[bbba374] | 36 | /* |
---|
| 37 | * Enumerations |
---|
| 38 | */ |
---|
| 39 | |
---|
| 40 | typedef enum |
---|
| 41 | { |
---|
[df9255d] | 42 | SKYPE_CALL_RINGING = 1, |
---|
[9db0234] | 43 | SKYPE_CALL_MISSED, |
---|
| 44 | SKYPE_CALL_UNPLACED, |
---|
[2eb4b1f] | 45 | SKYPE_CALL_CANCELLED, |
---|
[acd9478] | 46 | SKYPE_CALL_FINISHED, |
---|
[a92fb07] | 47 | SKYPE_CALL_REFUSED, |
---|
[9db0234] | 48 | /* This means we are ringing somebody, not somebody rings us. */ |
---|
| 49 | SKYPE_CALL_RINGING_OUT |
---|
[bbba374] | 50 | } skype_call_status; |
---|
| 51 | |
---|
[df9255d] | 52 | typedef enum |
---|
| 53 | { |
---|
| 54 | SKYPE_FILETRANSFER_NEW = 1, |
---|
| 55 | SKYPE_FILETRANSFER_FAILED |
---|
| 56 | } skype_filetransfer_status; |
---|
| 57 | |
---|
[7daec06] | 58 | /* |
---|
| 59 | * Structures |
---|
| 60 | */ |
---|
| 61 | |
---|
[f06e3ac] | 62 | struct skype_data |
---|
| 63 | { |
---|
| 64 | struct im_connection *ic; |
---|
[a3d6427] | 65 | char *username; |
---|
[368861e] | 66 | /* The effective file descriptor. We store it here so any function can |
---|
| 67 | * write() to it. */ |
---|
[f06e3ac] | 68 | int fd; |
---|
[368861e] | 69 | /* File descriptor returned by bitlbee. we store it so we know when |
---|
| 70 | * we're connected and when we aren't. */ |
---|
| 71 | int bfd; |
---|
[c7304b2] | 72 | /* ssl_getfd() uses this to get the file desciptor. */ |
---|
| 73 | void *ssl; |
---|
[2a0f99c] | 74 | /* When we receive a new message id, we query the properties, finally |
---|
| 75 | * the chatname. Store the properties here so that we can use |
---|
[c81d0ef] | 76 | * imcb_buddy_msg() when we got the chatname. */ |
---|
[77c1abe] | 77 | char *handle; |
---|
[a7af5f0] | 78 | /* List, because of multiline messages. */ |
---|
| 79 | GList *body; |
---|
[2a0f99c] | 80 | char *type; |
---|
[bbba374] | 81 | /* This is necessary because we send a notification when we get the |
---|
| 82 | * handle. So we store the state here and then we can send a |
---|
| 83 | * notification about the handle is in a given status. */ |
---|
| 84 | skype_call_status call_status; |
---|
[2eb4b1f] | 85 | char *call_id; |
---|
[48181f0] | 86 | char *call_duration; |
---|
[df9255d] | 87 | /* Same for file transfers. */ |
---|
| 88 | skype_filetransfer_status filetransfer_status; |
---|
[86278cd] | 89 | /* Using /j #nick we want to have a groupchat with two people. Usually |
---|
| 90 | * not (default). */ |
---|
| 91 | char* groupchat_with; |
---|
[f8674db] | 92 | /* The user who invited us to the chat. */ |
---|
| 93 | char* adder; |
---|
[a5f76a2] | 94 | /* If we are waiting for a confirmation about we changed the topic. */ |
---|
| 95 | int topic_wait; |
---|
[67454bd] | 96 | /* These are used by the info command. */ |
---|
| 97 | char *info_fullname; |
---|
| 98 | char *info_phonehome; |
---|
| 99 | char *info_phoneoffice; |
---|
| 100 | char *info_phonemobile; |
---|
| 101 | char *info_nrbuddies; |
---|
| 102 | char *info_tz; |
---|
| 103 | char *info_seen; |
---|
| 104 | char *info_birthday; |
---|
| 105 | char *info_sex; |
---|
| 106 | char *info_language; |
---|
| 107 | char *info_country; |
---|
| 108 | char *info_province; |
---|
| 109 | char *info_city; |
---|
| 110 | char *info_homepage; |
---|
| 111 | char *info_about; |
---|
[f06e3ac] | 112 | }; |
---|
| 113 | |
---|
[adce2de] | 114 | struct skype_away_state |
---|
| 115 | { |
---|
| 116 | char *code; |
---|
| 117 | char *full_name; |
---|
| 118 | }; |
---|
| 119 | |
---|
[7daec06] | 120 | struct skype_buddy_ask_data |
---|
| 121 | { |
---|
| 122 | struct im_connection *ic; |
---|
| 123 | char *handle; |
---|
| 124 | }; |
---|
| 125 | |
---|
| 126 | /* |
---|
| 127 | * Tables |
---|
| 128 | */ |
---|
| 129 | |
---|
[adce2de] | 130 | const struct skype_away_state skype_away_state_list[] = |
---|
| 131 | { |
---|
| 132 | { "ONLINE", "Online" }, |
---|
| 133 | { "SKYPEME", "Skype Me" }, |
---|
| 134 | { "AWAY", "Away" }, |
---|
| 135 | { "NA", "Not available" }, |
---|
| 136 | { "DND", "Do Not Disturb" }, |
---|
| 137 | { "INVISIBLE", "Invisible" }, |
---|
[23411c6] | 138 | { "OFFLINE", "Offline" }, |
---|
| 139 | { NULL, NULL} |
---|
[adce2de] | 140 | }; |
---|
| 141 | |
---|
[7daec06] | 142 | /* |
---|
| 143 | * Functions |
---|
| 144 | */ |
---|
[d3cbd17] | 145 | |
---|
[f06e3ac] | 146 | int skype_write( struct im_connection *ic, char *buf, int len ) |
---|
| 147 | { |
---|
| 148 | struct skype_data *sd = ic->proto_data; |
---|
[1fb89e3] | 149 | struct pollfd pfd[1]; |
---|
| 150 | |
---|
| 151 | pfd[0].fd = sd->fd; |
---|
| 152 | pfd[0].events = POLLOUT; |
---|
[f06e3ac] | 153 | |
---|
[7daec06] | 154 | /* This poll is necessary or we'll get a SIGPIPE when we write() to |
---|
| 155 | * sd->fd. */ |
---|
[1fb89e3] | 156 | poll(pfd, 1, 1000); |
---|
| 157 | if(pfd[0].revents & POLLHUP) |
---|
| 158 | { |
---|
| 159 | imc_logout( ic, TRUE ); |
---|
| 160 | return FALSE; |
---|
| 161 | } |
---|
[c7304b2] | 162 | ssl_write( sd->ssl, buf, len ); |
---|
[f06e3ac] | 163 | |
---|
[9fd4241] | 164 | return TRUE; |
---|
[f06e3ac] | 165 | } |
---|
| 166 | |
---|
[d3cbd17] | 167 | static void skype_buddy_ask_yes( gpointer w, struct skype_buddy_ask_data *bla ) |
---|
| 168 | { |
---|
| 169 | char *buf = g_strdup_printf("SET USER %s ISAUTHORIZED TRUE", bla->handle); |
---|
| 170 | skype_write( bla->ic, buf, strlen( buf ) ); |
---|
| 171 | g_free(buf); |
---|
| 172 | g_free(bla->handle); |
---|
| 173 | g_free(bla); |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | static void skype_buddy_ask_no( gpointer w, struct skype_buddy_ask_data *bla ) |
---|
| 177 | { |
---|
| 178 | char *buf = g_strdup_printf("SET USER %s ISAUTHORIZED FALSE", bla->handle); |
---|
| 179 | skype_write( bla->ic, buf, strlen( buf ) ); |
---|
| 180 | g_free(buf); |
---|
| 181 | g_free(bla->handle); |
---|
| 182 | g_free(bla); |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | void skype_buddy_ask( struct im_connection *ic, char *handle, char *message) |
---|
| 186 | { |
---|
| 187 | struct skype_buddy_ask_data *bla = g_new0( struct skype_buddy_ask_data, 1 ); |
---|
| 188 | char *buf; |
---|
| 189 | |
---|
| 190 | bla->ic = ic; |
---|
| 191 | bla->handle = g_strdup(handle); |
---|
| 192 | |
---|
| 193 | buf = g_strdup_printf( "The user %s wants to add you to his/her buddy list, saying: '%s'.", handle, message); |
---|
| 194 | imcb_ask( ic, buf, bla, skype_buddy_ask_yes, skype_buddy_ask_no ); |
---|
| 195 | g_free( buf ); |
---|
| 196 | } |
---|
| 197 | |
---|
[72aa7f0] | 198 | struct groupchat *skype_chat_by_name( struct im_connection *ic, char *name ) |
---|
| 199 | { |
---|
| 200 | struct groupchat *ret; |
---|
| 201 | |
---|
[de2f05e] | 202 | for( ret = ic->groupchats; ret; ret = ret->next ) |
---|
[72aa7f0] | 203 | { |
---|
| 204 | if(strcmp(name, ret->title ) == 0 ) |
---|
| 205 | break; |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | return ret; |
---|
| 209 | } |
---|
| 210 | |
---|
[1323e36] | 211 | static gboolean skype_read_callback( gpointer data, gint fd, b_input_condition cond ) |
---|
| 212 | { |
---|
| 213 | struct im_connection *ic = data; |
---|
| 214 | struct skype_data *sd = ic->proto_data; |
---|
| 215 | char buf[1024]; |
---|
| 216 | int st; |
---|
[9fd4241] | 217 | char **lines, **lineptr, *line, *ptr; |
---|
[1323e36] | 218 | |
---|
[98bca36] | 219 | if( !sd || sd->fd == -1 ) |
---|
[1323e36] | 220 | return FALSE; |
---|
[7daec06] | 221 | /* Read the whole data. */ |
---|
[c7304b2] | 222 | st = ssl_read( sd->ssl, buf, sizeof( buf ) ); |
---|
[1323e36] | 223 | if( st > 0 ) |
---|
| 224 | { |
---|
| 225 | buf[st] = '\0'; |
---|
[7daec06] | 226 | /* Then split it up to lines. */ |
---|
[9fd4241] | 227 | lines = g_strsplit(buf, "\n", 0); |
---|
| 228 | lineptr = lines; |
---|
| 229 | while((line = *lineptr)) |
---|
| 230 | { |
---|
| 231 | if(!strlen(line)) |
---|
| 232 | break; |
---|
| 233 | if(!strncmp(line, "USERS ", 6)) |
---|
| 234 | { |
---|
| 235 | char **i; |
---|
| 236 | char **nicks; |
---|
| 237 | |
---|
| 238 | nicks = g_strsplit(line + 6, ", ", 0); |
---|
| 239 | i = nicks; |
---|
| 240 | while(*i) |
---|
| 241 | { |
---|
| 242 | g_snprintf(buf, 1024, "GET USER %s ONLINESTATUS\n", *i); |
---|
| 243 | skype_write( ic, buf, strlen( buf ) ); |
---|
| 244 | i++; |
---|
| 245 | } |
---|
| 246 | g_strfreev(nicks); |
---|
| 247 | } |
---|
| 248 | else if(!strncmp(line, "USER ", 5)) |
---|
| 249 | { |
---|
[adce2de] | 250 | int flags = 0; |
---|
[be975f8] | 251 | char *status = strrchr(line, ' '); |
---|
| 252 | char *user = strchr(line, ' '); |
---|
[adce2de] | 253 | status++; |
---|
[be975f8] | 254 | ptr = strchr(++user, ' '); |
---|
| 255 | *ptr = '\0'; |
---|
[6627d92] | 256 | ptr++; |
---|
[7daec06] | 257 | if(!strncmp(ptr, "ONLINESTATUS ", 13) && |
---|
| 258 | strcmp(user, sd->username) != 0 |
---|
| 259 | && strcmp(user, "echo123") != 0) |
---|
[a3d6427] | 260 | { |
---|
| 261 | ptr = g_strdup_printf("%s@skype.com", user); |
---|
| 262 | imcb_add_buddy(ic, ptr, NULL); |
---|
| 263 | if(strcmp(status, "OFFLINE") != 0) |
---|
| 264 | flags |= OPT_LOGGED_IN; |
---|
| 265 | if(strcmp(status, "ONLINE") != 0 && strcmp(status, "SKYPEME") != 0) |
---|
| 266 | flags |= OPT_AWAY; |
---|
| 267 | imcb_buddy_status(ic, ptr, flags, NULL, NULL); |
---|
| 268 | g_free(ptr); |
---|
| 269 | } |
---|
[d3cbd17] | 270 | else if(!strncmp(ptr, "RECEIVEDAUTHREQUEST ", 20)) |
---|
| 271 | { |
---|
| 272 | char *message = ptr + 20; |
---|
| 273 | if(strlen(message)) |
---|
| 274 | skype_buddy_ask(ic, user, message); |
---|
| 275 | } |
---|
| 276 | else if(!strncmp(ptr, "BUDDYSTATUS ", 12)) |
---|
| 277 | { |
---|
| 278 | char *st = ptr + 12; |
---|
| 279 | if(!strcmp(st, "3")) |
---|
| 280 | { |
---|
| 281 | char *buf = g_strdup_printf("%s@skype.com", user); |
---|
| 282 | imcb_add_buddy(ic, buf, NULL); |
---|
| 283 | g_free(buf); |
---|
| 284 | } |
---|
| 285 | } |
---|
[67454bd] | 286 | else if(!strncmp(ptr, "FULLNAME ", 9)) |
---|
| 287 | sd->info_fullname = g_strdup_printf("%s", ptr + 9); |
---|
[93052e1] | 288 | else if(!strncmp(ptr, "PHONE_HOME ", 11)) |
---|
| 289 | sd->info_phonehome = g_strdup_printf("%s", ptr + 11); |
---|
| 290 | else if(!strncmp(ptr, "PHONE_OFFICE ", 13)) |
---|
| 291 | sd->info_phoneoffice = g_strdup_printf("%s", ptr + 13); |
---|
| 292 | else if(!strncmp(ptr, "PHONE_MOBILE ", 13)) |
---|
| 293 | sd->info_phonemobile = g_strdup_printf("%s", ptr + 13); |
---|
| 294 | else if(!strncmp(ptr, "NROF_AUTHED_BUDDIES ", 20)) |
---|
| 295 | sd->info_nrbuddies = g_strdup_printf("%s", ptr + 20); |
---|
| 296 | else if(!strncmp(ptr, "TIMEZONE ", 9)) |
---|
| 297 | sd->info_tz = g_strdup_printf("%s", ptr + 9); |
---|
| 298 | else if(!strncmp(ptr, "LASTONLINETIMESTAMP ", 20)) |
---|
| 299 | sd->info_seen = g_strdup_printf("%s", ptr + 20); |
---|
| 300 | else if(!strncmp(ptr, "BIRTHDAY ", 9)) |
---|
| 301 | sd->info_birthday = g_strdup_printf("%s", ptr + 9); |
---|
| 302 | else if(!strncmp(ptr, "SEX ", 4)) |
---|
| 303 | sd->info_sex = g_strdup_printf("%s", ptr + 4); |
---|
| 304 | else if(!strncmp(ptr, "LANGUAGE ", 9)) |
---|
| 305 | sd->info_language = g_strdup_printf("%s", ptr + 9); |
---|
| 306 | else if(!strncmp(ptr, "COUNTRY ", 8)) |
---|
| 307 | sd->info_country = g_strdup_printf("%s", ptr + 8); |
---|
| 308 | else if(!strncmp(ptr, "PROVINCE ", 9)) |
---|
| 309 | sd->info_province = g_strdup_printf("%s", ptr + 9); |
---|
| 310 | else if(!strncmp(ptr, "CITY ", 5)) |
---|
| 311 | sd->info_city = g_strdup_printf("%s", ptr + 5); |
---|
| 312 | else if(!strncmp(ptr, "HOMEPAGE ", 9)) |
---|
| 313 | sd->info_homepage = g_strdup_printf("%s", ptr + 9); |
---|
[67454bd] | 314 | else if(!strncmp(ptr, "ABOUT ", 6)) |
---|
| 315 | { |
---|
| 316 | sd->info_about = g_strdup_printf("%s", ptr + 6); |
---|
| 317 | |
---|
[93052e1] | 318 | GString *st = g_string_new("Contact Information\n"); |
---|
[67454bd] | 319 | g_string_append_printf(st, "Skype Name: %s\n", user); |
---|
| 320 | if(sd->info_fullname) |
---|
| 321 | { |
---|
[93052e1] | 322 | if(strlen(sd->info_fullname)) |
---|
| 323 | g_string_append_printf(st, "Full Name: %s\n", sd->info_fullname); |
---|
[67454bd] | 324 | g_free(sd->info_fullname); |
---|
| 325 | } |
---|
[93052e1] | 326 | if(sd->info_phonehome) |
---|
| 327 | { |
---|
| 328 | if(strlen(sd->info_phonehome)) |
---|
| 329 | g_string_append_printf(st, "Home Phone: %s\n", sd->info_phonehome); |
---|
| 330 | g_free(sd->info_phonehome); |
---|
| 331 | } |
---|
| 332 | if(sd->info_phoneoffice) |
---|
| 333 | { |
---|
| 334 | if(strlen(sd->info_phoneoffice)) |
---|
| 335 | g_string_append_printf(st, "Office Phone: %s\n", sd->info_phoneoffice); |
---|
| 336 | g_free(sd->info_phoneoffice); |
---|
| 337 | } |
---|
| 338 | if(sd->info_phonemobile) |
---|
| 339 | { |
---|
| 340 | if(strlen(sd->info_phonemobile)) |
---|
| 341 | g_string_append_printf(st, "Mobile Phone: %s\n", sd->info_phonemobile); |
---|
| 342 | g_free(sd->info_phonemobile); |
---|
| 343 | } |
---|
| 344 | g_string_append_printf(st, "Personal Information\n"); |
---|
| 345 | if(sd->info_nrbuddies) |
---|
| 346 | { |
---|
| 347 | if(strlen(sd->info_nrbuddies)) |
---|
| 348 | g_string_append_printf(st, "Contacts: %s\n", sd->info_nrbuddies); |
---|
| 349 | g_free(sd->info_nrbuddies); |
---|
| 350 | } |
---|
| 351 | if(sd->info_tz) |
---|
| 352 | { |
---|
| 353 | if(strlen(sd->info_tz)) |
---|
[885efac6] | 354 | { |
---|
[33cac97] | 355 | char ib[256]; |
---|
| 356 | time_t t = time(NULL); |
---|
| 357 | t += atoi(sd->info_tz)-(60*60*24); |
---|
| 358 | struct tm *gt = gmtime(&t); |
---|
| 359 | strftime(ib, 256, "%H:%M:%S", gt); |
---|
| 360 | g_string_append_printf(st, "Local Time: %s\n", ib); |
---|
[885efac6] | 361 | } |
---|
[93052e1] | 362 | g_free(sd->info_tz); |
---|
| 363 | } |
---|
| 364 | if(sd->info_seen) |
---|
| 365 | { |
---|
| 366 | if(strlen(sd->info_seen)) |
---|
[885efac6] | 367 | { |
---|
[3c5aded] | 368 | char ib[256]; |
---|
| 369 | time_t it = atoi(sd->info_seen); |
---|
| 370 | struct tm *tm = localtime(&it); |
---|
| 371 | strftime(ib, 256, ("%Y. %m. %d. %H:%M"), tm); |
---|
| 372 | g_string_append_printf(st, "Last Seen: %s\n", ib); |
---|
[885efac6] | 373 | } |
---|
[93052e1] | 374 | g_free(sd->info_seen); |
---|
| 375 | } |
---|
| 376 | if(sd->info_birthday) |
---|
| 377 | { |
---|
[969f643] | 378 | if(strlen(sd->info_birthday) && strcmp(sd->info_birthday, "0")) |
---|
[885efac6] | 379 | { |
---|
[f9c3e7b] | 380 | char ib[256]; |
---|
| 381 | struct tm tm; |
---|
| 382 | strptime(sd->info_birthday, "%Y%m%d", &tm); |
---|
| 383 | strftime(ib, 256, "%B %d, %Y", &tm); |
---|
| 384 | g_string_append_printf(st, "Birthday: %s\n", ib); |
---|
[5b9847d] | 385 | |
---|
| 386 | strftime(ib, 256, "%Y", &tm); |
---|
| 387 | int year = atoi(ib); |
---|
| 388 | time_t t = time(NULL); |
---|
| 389 | struct tm *lt = localtime(&t); |
---|
| 390 | g_string_append_printf(st, "Age: %d\n", lt->tm_year+1900-year); |
---|
[885efac6] | 391 | } |
---|
[93052e1] | 392 | g_free(sd->info_birthday); |
---|
| 393 | } |
---|
| 394 | if(sd->info_sex) |
---|
| 395 | { |
---|
| 396 | if(strlen(sd->info_sex)) |
---|
[885efac6] | 397 | { |
---|
[6b43dd4] | 398 | char *iptr = sd->info_sex; |
---|
| 399 | while(*iptr++) |
---|
| 400 | *iptr = tolower(*iptr); |
---|
[93052e1] | 401 | g_string_append_printf(st, "Gender: %s\n", sd->info_sex); |
---|
[885efac6] | 402 | } |
---|
[93052e1] | 403 | g_free(sd->info_sex); |
---|
| 404 | } |
---|
| 405 | if(sd->info_language) |
---|
| 406 | { |
---|
| 407 | if(strlen(sd->info_language)) |
---|
[885efac6] | 408 | { |
---|
| 409 | char *iptr = strchr(sd->info_language, ' '); |
---|
| 410 | if(iptr) |
---|
| 411 | iptr++; |
---|
| 412 | else |
---|
| 413 | iptr = sd->info_language; |
---|
| 414 | g_string_append_printf(st, "Language: %s\n", iptr); |
---|
| 415 | } |
---|
[93052e1] | 416 | g_free(sd->info_language); |
---|
| 417 | } |
---|
| 418 | if(sd->info_country) |
---|
| 419 | { |
---|
| 420 | if(strlen(sd->info_country)) |
---|
[885efac6] | 421 | { |
---|
| 422 | char *iptr = strchr(sd->info_country, ' '); |
---|
| 423 | if(iptr) |
---|
| 424 | iptr++; |
---|
| 425 | else |
---|
| 426 | iptr = sd->info_country; |
---|
[191470d] | 427 | g_string_append_printf(st, "Country: %s\n", iptr); |
---|
[885efac6] | 428 | } |
---|
[93052e1] | 429 | g_free(sd->info_country); |
---|
| 430 | } |
---|
| 431 | if(sd->info_province) |
---|
| 432 | { |
---|
| 433 | if(strlen(sd->info_province)) |
---|
| 434 | g_string_append_printf(st, "Region: %s\n", sd->info_province); |
---|
| 435 | g_free(sd->info_province); |
---|
| 436 | } |
---|
| 437 | if(sd->info_city) |
---|
| 438 | { |
---|
| 439 | if(strlen(sd->info_city)) |
---|
| 440 | g_string_append_printf(st, "City: %s\n", sd->info_city); |
---|
| 441 | g_free(sd->info_city); |
---|
| 442 | } |
---|
| 443 | if(sd->info_homepage) |
---|
| 444 | { |
---|
| 445 | if(strlen(sd->info_homepage)) |
---|
| 446 | g_string_append_printf(st, "Homepage: %s\n", sd->info_homepage); |
---|
| 447 | g_free(sd->info_homepage); |
---|
| 448 | } |
---|
| 449 | if(sd->info_about) |
---|
| 450 | { |
---|
| 451 | if(strlen(sd->info_about)) |
---|
| 452 | g_string_append_printf(st, "%s\n", sd->info_about); |
---|
| 453 | g_free(sd->info_about); |
---|
| 454 | } |
---|
[67454bd] | 455 | imcb_log(ic, "%s", st->str); |
---|
| 456 | g_string_free(st, TRUE); |
---|
| 457 | } |
---|
[9fd4241] | 458 | } |
---|
[77c1abe] | 459 | else if(!strncmp(line, "CHATMESSAGE ", 12)) |
---|
| 460 | { |
---|
| 461 | char *id = strchr(line, ' '); |
---|
| 462 | if(++id) |
---|
| 463 | { |
---|
| 464 | char *info = strchr(id, ' '); |
---|
| 465 | *info = '\0'; |
---|
| 466 | info++; |
---|
| 467 | if(!strcmp(info, "STATUS RECEIVED")) |
---|
| 468 | { |
---|
[7daec06] | 469 | /* New message ID: |
---|
| 470 | * (1) Request its from field |
---|
| 471 | * (2) Request its body |
---|
[2a0f99c] | 472 | * (3) Request its type |
---|
| 473 | * (4) Query chatname |
---|
[7daec06] | 474 | */ |
---|
[77c1abe] | 475 | g_snprintf(buf, 1024, "GET CHATMESSAGE %s FROM_HANDLE\n", id); |
---|
| 476 | skype_write( ic, buf, strlen( buf ) ); |
---|
| 477 | g_snprintf(buf, 1024, "GET CHATMESSAGE %s BODY\n", id); |
---|
| 478 | skype_write( ic, buf, strlen( buf ) ); |
---|
[2a0f99c] | 479 | g_snprintf(buf, 1024, "GET CHATMESSAGE %s TYPE\n", id); |
---|
| 480 | skype_write( ic, buf, strlen( buf ) ); |
---|
[c81d0ef] | 481 | g_snprintf(buf, 1024, "GET CHATMESSAGE %s CHATNAME\n", id); |
---|
| 482 | skype_write( ic, buf, strlen( buf ) ); |
---|
[77c1abe] | 483 | } |
---|
| 484 | else if(!strncmp(info, "FROM_HANDLE ", 12)) |
---|
| 485 | { |
---|
| 486 | info += 12; |
---|
[7daec06] | 487 | /* New from field value. Store |
---|
| 488 | * it, then we can later use it |
---|
| 489 | * when we got the message's |
---|
| 490 | * body. */ |
---|
[7613670] | 491 | g_free(sd->handle); |
---|
[77c1abe] | 492 | sd->handle = g_strdup_printf("%s@skype.com", info); |
---|
[5d1b0774] | 493 | } |
---|
| 494 | else if(!strncmp(info, "EDITED_BY ", 10)) |
---|
| 495 | { |
---|
| 496 | info += 10; |
---|
| 497 | /* This is the same as |
---|
| 498 | * FROM_HANDLE, except that we |
---|
| 499 | * never request these lines |
---|
| 500 | * from Skype, we just get |
---|
| 501 | * them. */ |
---|
| 502 | g_free(sd->handle); |
---|
| 503 | sd->handle = g_strdup_printf("%s@skype.com", info); |
---|
[77c1abe] | 504 | } |
---|
| 505 | else if(!strncmp(info, "BODY ", 5)) |
---|
| 506 | { |
---|
| 507 | info += 5; |
---|
[a7af5f0] | 508 | sd->body = g_list_append(sd->body, g_strdup(info)); |
---|
[c81d0ef] | 509 | } |
---|
[2a0f99c] | 510 | else if(!strncmp(info, "TYPE ", 5)) |
---|
| 511 | { |
---|
| 512 | info += 5; |
---|
| 513 | g_free(sd->type); |
---|
| 514 | sd->type = g_strdup(info); |
---|
| 515 | } |
---|
[c81d0ef] | 516 | else if(!strncmp(info, "CHATNAME ", 9)) |
---|
| 517 | { |
---|
| 518 | info += 9; |
---|
[2a0f99c] | 519 | if(sd->handle && sd->body && sd->type) |
---|
[7daec06] | 520 | { |
---|
[31870ae] | 521 | struct groupchat *gc = skype_chat_by_name(ic, info); |
---|
[a7af5f0] | 522 | int i; |
---|
| 523 | for(i=0;i<g_list_length(sd->body);i++) |
---|
[2a0f99c] | 524 | { |
---|
[a7af5f0] | 525 | char *body = g_list_nth_data(sd->body, i); |
---|
[54e6207] | 526 | if(!strcmp(sd->type, "SAID") || !strcmp(sd->type, "EMOTED")) |
---|
[a7af5f0] | 527 | { |
---|
[54e6207] | 528 | char *st; |
---|
| 529 | if(!strcmp(sd->type, "SAID")) |
---|
| 530 | st = g_strdup(body); |
---|
| 531 | else |
---|
| 532 | { |
---|
| 533 | st = g_strdup_printf("/me %s", body); |
---|
| 534 | } |
---|
[a7af5f0] | 535 | if(!gc) |
---|
| 536 | /* Private message */ |
---|
[54e6207] | 537 | imcb_buddy_msg(ic, sd->handle, st, 0, 0); |
---|
[a7af5f0] | 538 | else |
---|
| 539 | /* Groupchat message */ |
---|
[54e6207] | 540 | imcb_chat_msg(gc, sd->handle, st, 0, 0); |
---|
| 541 | g_free(st); |
---|
[a7af5f0] | 542 | } |
---|
| 543 | else if(!strcmp(sd->type, "SETTOPIC")) |
---|
| 544 | { |
---|
| 545 | if(gc) |
---|
[de2f05e] | 546 | imcb_chat_topic(gc, sd->handle, body, 0); |
---|
[a7af5f0] | 547 | } |
---|
| 548 | else if(!strcmp(sd->type, "LEFT")) |
---|
| 549 | { |
---|
| 550 | if(gc) |
---|
| 551 | imcb_chat_remove_buddy(gc, sd->handle, NULL); |
---|
| 552 | } |
---|
[2a0f99c] | 553 | } |
---|
[a7af5f0] | 554 | g_list_free(sd->body); |
---|
| 555 | sd->body = NULL; |
---|
[7daec06] | 556 | } |
---|
[77c1abe] | 557 | } |
---|
| 558 | } |
---|
| 559 | } |
---|
[ecfbc5d] | 560 | else if(!strncmp(line, "CALL ", 5)) |
---|
| 561 | { |
---|
| 562 | char *id = strchr(line, ' '); |
---|
| 563 | if(++id) |
---|
| 564 | { |
---|
| 565 | char *info = strchr(id, ' '); |
---|
| 566 | *info = '\0'; |
---|
| 567 | info++; |
---|
| 568 | if(!strcmp(info, "STATUS RINGING")) |
---|
| 569 | { |
---|
| 570 | g_snprintf(buf, 1024, "GET CALL %s PARTNER_HANDLE\n", id); |
---|
| 571 | skype_write( ic, buf, strlen( buf ) ); |
---|
[9db0234] | 572 | if(sd->call_status != SKYPE_CALL_UNPLACED) |
---|
| 573 | sd->call_status = SKYPE_CALL_RINGING; |
---|
| 574 | else |
---|
| 575 | sd->call_status = SKYPE_CALL_RINGING_OUT; |
---|
[bbba374] | 576 | } |
---|
| 577 | else if(!strcmp(info, "STATUS MISSED")) |
---|
| 578 | { |
---|
| 579 | g_snprintf(buf, 1024, "GET CALL %s PARTNER_HANDLE\n", id); |
---|
| 580 | skype_write( ic, buf, strlen( buf ) ); |
---|
| 581 | sd->call_status = SKYPE_CALL_MISSED; |
---|
[ecfbc5d] | 582 | } |
---|
[2eb4b1f] | 583 | else if(!strcmp(info, "STATUS CANCELLED")) |
---|
| 584 | { |
---|
| 585 | g_snprintf(buf, 1024, "GET CALL %s PARTNER_HANDLE\n", id); |
---|
| 586 | skype_write( ic, buf, strlen( buf ) ); |
---|
| 587 | sd->call_status = SKYPE_CALL_CANCELLED; |
---|
| 588 | } |
---|
[acd9478] | 589 | else if(!strcmp(info, "STATUS FINISHED")) |
---|
| 590 | { |
---|
| 591 | g_snprintf(buf, 1024, "GET CALL %s PARTNER_HANDLE\n", id); |
---|
| 592 | skype_write( ic, buf, strlen( buf ) ); |
---|
| 593 | sd->call_status = SKYPE_CALL_FINISHED; |
---|
| 594 | } |
---|
[a92fb07] | 595 | else if(!strcmp(info, "STATUS REFUSED")) |
---|
| 596 | { |
---|
| 597 | g_snprintf(buf, 1024, "GET CALL %s PARTNER_HANDLE\n", id); |
---|
| 598 | skype_write( ic, buf, strlen( buf ) ); |
---|
| 599 | sd->call_status = SKYPE_CALL_REFUSED; |
---|
| 600 | } |
---|
[9db0234] | 601 | else if(!strcmp(info, "STATUS UNPLACED")) |
---|
[2eb4b1f] | 602 | { |
---|
| 603 | if(sd->call_id) |
---|
| 604 | g_free(sd->call_id); |
---|
| 605 | /* Save the ID for later usage (Cancel/Finish). */ |
---|
| 606 | sd->call_id = g_strdup(id); |
---|
[9db0234] | 607 | sd->call_status = SKYPE_CALL_UNPLACED; |
---|
[2eb4b1f] | 608 | } |
---|
[48181f0] | 609 | else if(!strncmp(info, "DURATION ", 9)) |
---|
| 610 | { |
---|
| 611 | if(sd->call_duration) |
---|
| 612 | g_free(sd->call_duration); |
---|
| 613 | sd->call_duration = g_strdup(info+9); |
---|
| 614 | } |
---|
[ecfbc5d] | 615 | else if(!strncmp(info, "PARTNER_HANDLE ", 15)) |
---|
| 616 | { |
---|
| 617 | info += 15; |
---|
[df9255d] | 618 | if(sd->call_status) { |
---|
| 619 | switch(sd->call_status) |
---|
| 620 | { |
---|
| 621 | case SKYPE_CALL_RINGING: |
---|
| 622 | imcb_log(ic, "The user %s is currently ringing you.", info); |
---|
| 623 | break; |
---|
| 624 | case SKYPE_CALL_MISSED: |
---|
| 625 | imcb_log(ic, "You have missed a call from user %s.", info); |
---|
| 626 | break; |
---|
[9db0234] | 627 | case SKYPE_CALL_RINGING_OUT: |
---|
| 628 | imcb_log(ic, "You are currently ringing the user %s.", info); |
---|
| 629 | break; |
---|
[2eb4b1f] | 630 | case SKYPE_CALL_CANCELLED: |
---|
| 631 | imcb_log(ic, "You cancelled the call to the user %s.", info); |
---|
[acd9478] | 632 | break; |
---|
[a92fb07] | 633 | case SKYPE_CALL_REFUSED: |
---|
| 634 | imcb_log(ic, "The user %s refused the call.", info); |
---|
| 635 | break; |
---|
[acd9478] | 636 | case SKYPE_CALL_FINISHED: |
---|
[48181f0] | 637 | if(sd->call_duration) |
---|
| 638 | { |
---|
| 639 | imcb_log(ic, "You finished the call to the user %s (duration: %s seconds).", info, sd->call_duration); |
---|
| 640 | } |
---|
| 641 | else |
---|
| 642 | { |
---|
| 643 | imcb_log(ic, "You finished the call to the user %s.", info); |
---|
| 644 | } |
---|
[2eb4b1f] | 645 | break; |
---|
[9db0234] | 646 | default: |
---|
| 647 | /* Don't be noisy, ignore other statuses for now. */ |
---|
| 648 | break; |
---|
[df9255d] | 649 | } |
---|
| 650 | sd->call_status = 0; |
---|
| 651 | } |
---|
| 652 | } |
---|
| 653 | } |
---|
| 654 | } |
---|
| 655 | else if(!strncmp(line, "FILETRANSFER ", 13)) |
---|
| 656 | { |
---|
| 657 | char *id = strchr(line, ' '); |
---|
| 658 | if(++id) |
---|
| 659 | { |
---|
| 660 | char *info = strchr(id, ' '); |
---|
| 661 | *info = '\0'; |
---|
| 662 | info++; |
---|
| 663 | if(!strcmp(info, "STATUS NEW")) |
---|
| 664 | { |
---|
| 665 | g_snprintf(buf, 1024, "GET FILETRANSFER %s PARTNER_HANDLE\n", id); |
---|
| 666 | skype_write( ic, buf, strlen( buf ) ); |
---|
| 667 | sd->filetransfer_status = SKYPE_FILETRANSFER_NEW; |
---|
| 668 | } |
---|
| 669 | else if(!strcmp(info, "STATUS FAILED")) |
---|
| 670 | { |
---|
| 671 | g_snprintf(buf, 1024, "GET FILETRANSFER %s PARTNER_HANDLE\n", id); |
---|
| 672 | skype_write( ic, buf, strlen( buf ) ); |
---|
| 673 | sd->filetransfer_status = SKYPE_FILETRANSFER_FAILED; |
---|
| 674 | } |
---|
| 675 | else if(!strncmp(info, "PARTNER_HANDLE ", 15)) |
---|
| 676 | { |
---|
| 677 | info += 15; |
---|
| 678 | if(sd->filetransfer_status) { |
---|
| 679 | switch(sd->filetransfer_status) |
---|
| 680 | { |
---|
| 681 | case SKYPE_FILETRANSFER_NEW: |
---|
| 682 | imcb_log(ic, "The user %s offered a new file for you.", info); |
---|
| 683 | break; |
---|
| 684 | case SKYPE_FILETRANSFER_FAILED: |
---|
| 685 | imcb_log(ic, "Failed to transfer file from user %s.", info); |
---|
| 686 | break; |
---|
| 687 | } |
---|
| 688 | sd->filetransfer_status = 0; |
---|
[bbba374] | 689 | } |
---|
[ecfbc5d] | 690 | } |
---|
| 691 | } |
---|
| 692 | } |
---|
[2d07803] | 693 | else if(!strncmp(line, "CHAT ", 5)) |
---|
| 694 | { |
---|
| 695 | char *id = strchr(line, ' '); |
---|
| 696 | if(++id) |
---|
| 697 | { |
---|
| 698 | char *info = strchr(id, ' '); |
---|
[86f2683] | 699 | if(info) |
---|
| 700 | *info = '\0'; |
---|
[2d07803] | 701 | info++; |
---|
[5652d43] | 702 | /* Remove fake chat if we created one in skype_chat_with() */ |
---|
| 703 | struct groupchat *gc = skype_chat_by_name(ic, ""); |
---|
| 704 | if(gc) |
---|
| 705 | imcb_chat_free(gc); |
---|
[5a61e43f] | 706 | if(!strcmp(info, "STATUS MULTI_SUBSCRIBED")) |
---|
[72aa7f0] | 707 | { |
---|
[86278cd] | 708 | imcb_chat_new( ic, id ); |
---|
[f8674db] | 709 | g_snprintf(buf, 1024, "GET CHAT %s ADDER\n", id); |
---|
| 710 | skype_write(ic, buf, strlen(buf)); |
---|
| 711 | g_snprintf(buf, 1024, "GET CHAT %s TOPIC\n", id); |
---|
| 712 | skype_write(ic, buf, strlen(buf)); |
---|
[86278cd] | 713 | } |
---|
| 714 | else if(!strcmp(info, "STATUS DIALOG") && sd->groupchat_with) |
---|
| 715 | { |
---|
[5652d43] | 716 | gc = imcb_chat_new( ic, id ); |
---|
[86278cd] | 717 | /* According to the docs this |
---|
| 718 | * is necessary. However it |
---|
| 719 | * does not seem the situation |
---|
| 720 | * and it would open an extra |
---|
| 721 | * window on our client, so |
---|
| 722 | * just leave it out. */ |
---|
| 723 | /*g_snprintf(buf, 1024, "OPEN CHAT %s\n", id); |
---|
| 724 | skype_write(ic, buf, strlen(buf));*/ |
---|
| 725 | g_snprintf(buf, 1024, "%s@skype.com", sd->groupchat_with); |
---|
| 726 | imcb_chat_add_buddy(gc, buf); |
---|
| 727 | imcb_chat_add_buddy(gc, sd->username); |
---|
| 728 | g_free(sd->groupchat_with); |
---|
| 729 | sd->groupchat_with = NULL; |
---|
[f8674db] | 730 | g_snprintf(buf, 1024, "GET CHAT %s ADDER\n", id); |
---|
| 731 | skype_write(ic, buf, strlen(buf)); |
---|
| 732 | g_snprintf(buf, 1024, "GET CHAT %s TOPIC\n", id); |
---|
| 733 | skype_write(ic, buf, strlen(buf)); |
---|
[72aa7f0] | 734 | } |
---|
[ec159f1] | 735 | else if(!strcmp(info, "STATUS UNSUBSCRIBED")) |
---|
| 736 | { |
---|
[5652d43] | 737 | gc = skype_chat_by_name(ic, id); |
---|
[ec159f1] | 738 | if(gc) |
---|
| 739 | gc->data = (void*)FALSE; |
---|
| 740 | } |
---|
[f8674db] | 741 | else if(!strncmp(info, "ADDER ", 6)) |
---|
| 742 | { |
---|
| 743 | info += 6; |
---|
| 744 | g_free(sd->adder); |
---|
| 745 | sd->adder = g_strdup_printf("%s@skype.com", info); |
---|
| 746 | } |
---|
[d601f9b] | 747 | else if(!strncmp(info, "TOPIC ", 6)) |
---|
| 748 | { |
---|
| 749 | info += 6; |
---|
[5652d43] | 750 | gc = skype_chat_by_name(ic, id); |
---|
[a5f76a2] | 751 | if(gc && (sd->adder || sd->topic_wait)) |
---|
[f8674db] | 752 | { |
---|
[a5f76a2] | 753 | if(sd->topic_wait) |
---|
| 754 | { |
---|
| 755 | sd->adder = g_strdup(sd->username); |
---|
| 756 | sd->topic_wait = 0; |
---|
| 757 | } |
---|
| 758 | imcb_chat_topic(gc, sd->adder, info, 0); |
---|
[f8674db] | 759 | g_free(sd->adder); |
---|
| 760 | sd->adder = NULL; |
---|
| 761 | } |
---|
[d601f9b] | 762 | } |
---|
[72aa7f0] | 763 | else if(!strncmp(info, "ACTIVEMEMBERS ", 14)) |
---|
| 764 | { |
---|
| 765 | info += 14; |
---|
[5652d43] | 766 | gc = skype_chat_by_name(ic, id); |
---|
[ec159f1] | 767 | /* Hack! We set ->data to TRUE |
---|
| 768 | * while we're on the channel |
---|
| 769 | * so that we won't rejoin |
---|
| 770 | * after a /part. */ |
---|
| 771 | if(gc && !gc->data) |
---|
[72aa7f0] | 772 | { |
---|
[349ee4a] | 773 | char **members = g_strsplit(info, " ", 0); |
---|
| 774 | int i; |
---|
| 775 | for(i=0;members[i];i++) |
---|
| 776 | { |
---|
| 777 | if(!strcmp(members[i], sd->username)) |
---|
| 778 | continue; |
---|
| 779 | g_snprintf(buf, 1024, "%s@skype.com", members[i]); |
---|
[c09d327] | 780 | if(!g_list_find_custom(gc->in_room, buf, (GCompareFunc)strcmp)) |
---|
| 781 | imcb_chat_add_buddy(gc, buf); |
---|
[349ee4a] | 782 | } |
---|
| 783 | imcb_chat_add_buddy(gc, sd->username); |
---|
| 784 | g_strfreev(members); |
---|
[72aa7f0] | 785 | } |
---|
| 786 | } |
---|
[2d07803] | 787 | } |
---|
| 788 | } |
---|
[c7304b2] | 789 | else if(!strncmp(line, "PASSWORD ", 9)) |
---|
| 790 | { |
---|
| 791 | if(!strncmp(line+9, "OK", 2)) |
---|
| 792 | imcb_connected(ic); |
---|
| 793 | else |
---|
| 794 | { |
---|
| 795 | imcb_error(ic, "Authentication Failed"); |
---|
| 796 | imc_logout( ic, TRUE ); |
---|
| 797 | } |
---|
| 798 | } |
---|
[9fd4241] | 799 | lineptr++; |
---|
| 800 | } |
---|
| 801 | g_strfreev(lines); |
---|
[1323e36] | 802 | } |
---|
| 803 | else if( st == 0 || ( st < 0 && !sockerr_again() ) ) |
---|
| 804 | { |
---|
| 805 | closesocket( sd->fd ); |
---|
| 806 | sd->fd = -1; |
---|
| 807 | |
---|
| 808 | imcb_error( ic, "Error while reading from server" ); |
---|
| 809 | imc_logout( ic, TRUE ); |
---|
| 810 | return FALSE; |
---|
| 811 | } |
---|
| 812 | return TRUE; |
---|
| 813 | } |
---|
| 814 | |
---|
[f06e3ac] | 815 | gboolean skype_start_stream( struct im_connection *ic ) |
---|
| 816 | { |
---|
[1323e36] | 817 | struct skype_data *sd = ic->proto_data; |
---|
[f06e3ac] | 818 | char *buf; |
---|
| 819 | int st; |
---|
| 820 | |
---|
[1fb89e3] | 821 | if(!sd) |
---|
| 822 | return FALSE; |
---|
| 823 | |
---|
[368861e] | 824 | if( sd->bfd <= 0 ) |
---|
| 825 | sd->bfd = b_input_add( sd->fd, GAIM_INPUT_READ, skype_read_callback, ic ); |
---|
[1323e36] | 826 | |
---|
[a0b206b] | 827 | /* Log in */ |
---|
| 828 | buf = g_strdup_printf("USERNAME %s\n", ic->acc->user); |
---|
| 829 | st = skype_write( ic, buf, strlen( buf ) ); |
---|
| 830 | g_free(buf); |
---|
| 831 | buf = g_strdup_printf("PASSWORD %s\n", ic->acc->pass); |
---|
| 832 | st = skype_write( ic, buf, strlen( buf ) ); |
---|
| 833 | g_free(buf); |
---|
| 834 | |
---|
[7daec06] | 835 | /* This will download all buddies. */ |
---|
[9fd4241] | 836 | buf = g_strdup_printf("SEARCH FRIENDS\n"); |
---|
[f06e3ac] | 837 | st = skype_write( ic, buf, strlen( buf ) ); |
---|
| 838 | g_free(buf); |
---|
[348a3a2] | 839 | buf = g_strdup_printf("SET USERSTATUS ONLINE\n"); |
---|
| 840 | skype_write( ic, buf, strlen( buf ) ); |
---|
| 841 | g_free(buf); |
---|
[f06e3ac] | 842 | return st; |
---|
| 843 | } |
---|
| 844 | |
---|
[c7304b2] | 845 | gboolean skype_connected( gpointer data, void *source, b_input_condition cond ) |
---|
[f06e3ac] | 846 | { |
---|
| 847 | struct im_connection *ic = data; |
---|
[c7304b2] | 848 | struct skype_data *sd = ic->proto_data; |
---|
| 849 | if(!source) |
---|
| 850 | { |
---|
| 851 | sd->ssl = NULL; |
---|
| 852 | imcb_error( ic, "Could not connect to server" ); |
---|
| 853 | imc_logout( ic, TRUE ); |
---|
| 854 | return FALSE; |
---|
| 855 | } |
---|
| 856 | imcb_log( ic, "Connected to server, logging in" ); |
---|
[f06e3ac] | 857 | return skype_start_stream(ic); |
---|
| 858 | } |
---|
| 859 | |
---|
| 860 | static void skype_login( account_t *acc ) |
---|
| 861 | { |
---|
| 862 | struct im_connection *ic = imcb_new( acc ); |
---|
| 863 | struct skype_data *sd = g_new0( struct skype_data, 1 ); |
---|
| 864 | |
---|
| 865 | ic->proto_data = sd; |
---|
| 866 | |
---|
| 867 | imcb_log( ic, "Connecting" ); |
---|
[c7304b2] | 868 | sd->ssl = ssl_connect(set_getstr( &acc->set, "server" ), set_getint( &acc->set, "port" ), skype_connected, ic ); |
---|
| 869 | sd->fd = sd->ssl ? ssl_getfd( sd->ssl ) : -1; |
---|
[a3d6427] | 870 | sd->username = g_strdup( acc->user ); |
---|
[f06e3ac] | 871 | |
---|
| 872 | sd->ic = ic; |
---|
| 873 | } |
---|
| 874 | |
---|
| 875 | static void skype_logout( struct im_connection *ic ) |
---|
| 876 | { |
---|
| 877 | struct skype_data *sd = ic->proto_data; |
---|
[98bca36] | 878 | char *buf; |
---|
| 879 | |
---|
| 880 | buf = g_strdup_printf("SET USERSTATUS OFFLINE\n"); |
---|
| 881 | skype_write( ic, buf, strlen( buf ) ); |
---|
| 882 | g_free(buf); |
---|
| 883 | |
---|
[a3d6427] | 884 | g_free(sd->username); |
---|
[7613670] | 885 | g_free(sd->handle); |
---|
[f06e3ac] | 886 | g_free(sd); |
---|
[98bca36] | 887 | ic->proto_data = NULL; |
---|
[f06e3ac] | 888 | } |
---|
| 889 | |
---|
[93ece66] | 890 | static int skype_buddy_msg( struct im_connection *ic, char *who, char *message, int flags ) |
---|
| 891 | { |
---|
[77c1abe] | 892 | char *buf, *ptr, *nick; |
---|
[93ece66] | 893 | int st; |
---|
| 894 | |
---|
[cbec0d6] | 895 | nick = g_strdup(who); |
---|
[77c1abe] | 896 | ptr = strchr(nick, '@'); |
---|
[0bb1b7f] | 897 | if(ptr) |
---|
| 898 | *ptr = '\0'; |
---|
[93ece66] | 899 | |
---|
[77c1abe] | 900 | buf = g_strdup_printf("MESSAGE %s %s\n", nick, message); |
---|
| 901 | g_free(nick); |
---|
[93ece66] | 902 | st = skype_write( ic, buf, strlen( buf ) ); |
---|
| 903 | g_free(buf); |
---|
| 904 | |
---|
| 905 | return st; |
---|
| 906 | } |
---|
| 907 | |
---|
[23411c6] | 908 | const struct skype_away_state *skype_away_state_by_name( char *name ) |
---|
| 909 | { |
---|
| 910 | int i; |
---|
| 911 | |
---|
| 912 | for( i = 0; skype_away_state_list[i].full_name; i ++ ) |
---|
| 913 | if( g_strcasecmp( skype_away_state_list[i].full_name, name ) == 0 ) |
---|
| 914 | return( skype_away_state_list + i ); |
---|
| 915 | |
---|
| 916 | return NULL; |
---|
| 917 | } |
---|
| 918 | |
---|
[f06e3ac] | 919 | static void skype_set_away( struct im_connection *ic, char *state_txt, char *message ) |
---|
| 920 | { |
---|
[23411c6] | 921 | const struct skype_away_state *state; |
---|
| 922 | char *buf; |
---|
| 923 | |
---|
| 924 | if( strcmp( state_txt, GAIM_AWAY_CUSTOM ) == 0 ) |
---|
| 925 | state = skype_away_state_by_name( "Away" ); |
---|
| 926 | else |
---|
| 927 | state = skype_away_state_by_name( state_txt ); |
---|
| 928 | buf = g_strdup_printf("SET USERSTATUS %s\n", state->code); |
---|
| 929 | skype_write( ic, buf, strlen( buf ) ); |
---|
| 930 | g_free(buf); |
---|
[f06e3ac] | 931 | } |
---|
| 932 | |
---|
| 933 | static GList *skype_away_states( struct im_connection *ic ) |
---|
| 934 | { |
---|
[de2f05e] | 935 | static GList *l = NULL; |
---|
[adce2de] | 936 | int i; |
---|
| 937 | |
---|
[de2f05e] | 938 | if( l == NULL ) |
---|
| 939 | for( i = 0; skype_away_state_list[i].full_name; i ++ ) |
---|
| 940 | l = g_list_append( l, (void*) skype_away_state_list[i].full_name ); |
---|
[adce2de] | 941 | |
---|
[f06e3ac] | 942 | return l; |
---|
| 943 | } |
---|
| 944 | |
---|
[93dffea] | 945 | static char *skype_set_display_name( set_t *set, char *value ) |
---|
| 946 | { |
---|
| 947 | account_t *acc = set->data; |
---|
| 948 | struct im_connection *ic = acc->ic; |
---|
| 949 | char *buf; |
---|
| 950 | |
---|
[fcef6e6] | 951 | buf = g_strdup_printf("SET PROFILE FULLNAME %s", value); |
---|
[93dffea] | 952 | skype_write( ic, buf, strlen( buf ) ); |
---|
| 953 | g_free(buf); |
---|
| 954 | return(value); |
---|
| 955 | } |
---|
| 956 | |
---|
[b68b023] | 957 | static char *skype_set_call( set_t *set, char *value ) |
---|
| 958 | { |
---|
| 959 | account_t *acc = set->data; |
---|
| 960 | struct im_connection *ic = acc->ic; |
---|
[2eb4b1f] | 961 | struct skype_data *sd = ic->proto_data; |
---|
[b68b023] | 962 | char *nick, *ptr, *buf; |
---|
| 963 | |
---|
[2eb4b1f] | 964 | if(value) |
---|
[b68b023] | 965 | { |
---|
[2eb4b1f] | 966 | user_t *u = user_find(acc->irc, value); |
---|
| 967 | /* We are starting a call */ |
---|
| 968 | if(!u) |
---|
| 969 | { |
---|
| 970 | imcb_error(ic, "%s - no such nick", value); |
---|
| 971 | return(value); |
---|
| 972 | } |
---|
| 973 | nick = g_strdup(u->handle); |
---|
| 974 | ptr = strchr(nick, '@'); |
---|
| 975 | if(ptr) |
---|
| 976 | *ptr = '\0'; |
---|
| 977 | |
---|
| 978 | buf = g_strdup_printf("CALL %s", nick); |
---|
| 979 | skype_write( ic, buf, strlen( buf ) ); |
---|
| 980 | g_free(buf); |
---|
| 981 | g_free(nick); |
---|
| 982 | } |
---|
| 983 | else |
---|
| 984 | { |
---|
| 985 | /* We are ending a call */ |
---|
| 986 | if(sd->call_id) |
---|
| 987 | { |
---|
| 988 | buf = g_strdup_printf("SET CALL %s STATUS FINISHED", sd->call_id); |
---|
| 989 | skype_write( ic, buf, strlen( buf ) ); |
---|
| 990 | g_free(buf); |
---|
[9fd7202] | 991 | g_free(sd->call_id); |
---|
| 992 | sd->call_id = NULL; |
---|
[2eb4b1f] | 993 | } |
---|
| 994 | else |
---|
| 995 | { |
---|
| 996 | imcb_error(ic, "There are no active calls currently."); |
---|
| 997 | } |
---|
[b68b023] | 998 | } |
---|
| 999 | return(value); |
---|
| 1000 | } |
---|
| 1001 | |
---|
[f06e3ac] | 1002 | static void skype_add_buddy( struct im_connection *ic, char *who, char *group ) |
---|
| 1003 | { |
---|
[6627d92] | 1004 | char *buf, *nick, *ptr; |
---|
| 1005 | |
---|
[cbec0d6] | 1006 | nick = g_strdup(who); |
---|
[6627d92] | 1007 | ptr = strchr(nick, '@'); |
---|
| 1008 | if(ptr) |
---|
| 1009 | *ptr = '\0'; |
---|
| 1010 | buf = g_strdup_printf("SET USER %s BUDDYSTATUS 2 Please authorize me\n", nick); |
---|
| 1011 | skype_write( ic, buf, strlen( buf ) ); |
---|
| 1012 | g_free(nick); |
---|
[f06e3ac] | 1013 | } |
---|
| 1014 | |
---|
| 1015 | static void skype_remove_buddy( struct im_connection *ic, char *who, char *group ) |
---|
| 1016 | { |
---|
[6627d92] | 1017 | char *buf, *nick, *ptr; |
---|
| 1018 | |
---|
[cbec0d6] | 1019 | nick = g_strdup(who); |
---|
[6627d92] | 1020 | ptr = strchr(nick, '@'); |
---|
| 1021 | if(ptr) |
---|
| 1022 | *ptr = '\0'; |
---|
| 1023 | buf = g_strdup_printf("SET USER %s BUDDYSTATUS 1\n", nick); |
---|
| 1024 | skype_write( ic, buf, strlen( buf ) ); |
---|
| 1025 | g_free(nick); |
---|
[f06e3ac] | 1026 | } |
---|
| 1027 | |
---|
[79e20f9] | 1028 | void skype_chat_msg( struct groupchat *gc, char *message, int flags ) |
---|
[66c9558] | 1029 | { |
---|
[79e20f9] | 1030 | struct im_connection *ic = gc->ic; |
---|
| 1031 | char *buf; |
---|
| 1032 | buf = g_strdup_printf("CHATMESSAGE %s %s\n", gc->title, message); |
---|
| 1033 | skype_write( ic, buf, strlen( buf ) ); |
---|
| 1034 | g_free(buf); |
---|
[66c9558] | 1035 | } |
---|
| 1036 | |
---|
[b01dc6c] | 1037 | void skype_chat_leave( struct groupchat *gc ) |
---|
| 1038 | { |
---|
| 1039 | struct im_connection *ic = gc->ic; |
---|
| 1040 | char *buf; |
---|
| 1041 | buf = g_strdup_printf("ALTER CHAT %s LEAVE\n", gc->title); |
---|
| 1042 | skype_write( ic, buf, strlen( buf ) ); |
---|
| 1043 | g_free(buf); |
---|
[760319d] | 1044 | gc->data = (void*)TRUE; |
---|
| 1045 | } |
---|
| 1046 | |
---|
| 1047 | void skype_chat_invite(struct groupchat *gc, char *who, char *message) |
---|
| 1048 | { |
---|
| 1049 | struct im_connection *ic = gc->ic; |
---|
| 1050 | char *buf, *ptr, *nick; |
---|
| 1051 | nick = g_strdup(message); |
---|
| 1052 | ptr = strchr(nick, '@'); |
---|
| 1053 | if(ptr) |
---|
| 1054 | *ptr = '\0'; |
---|
| 1055 | buf = g_strdup_printf("ALTER CHAT %s ADDMEMBERS %s\n", gc->title, nick); |
---|
| 1056 | skype_write( ic, buf, strlen( buf ) ); |
---|
| 1057 | g_free(buf); |
---|
| 1058 | g_free(nick); |
---|
[b01dc6c] | 1059 | } |
---|
| 1060 | |
---|
[09e2a69] | 1061 | void skype_chat_topic(struct groupchat *gc, char *message) |
---|
| 1062 | { |
---|
| 1063 | struct im_connection *ic = gc->ic; |
---|
[a5f76a2] | 1064 | struct skype_data *sd = ic->proto_data; |
---|
[09e2a69] | 1065 | char *buf; |
---|
| 1066 | buf = g_strdup_printf("ALTER CHAT %s SETTOPIC %s\n", gc->title, message); |
---|
| 1067 | skype_write( ic, buf, strlen( buf ) ); |
---|
| 1068 | g_free(buf); |
---|
[a5f76a2] | 1069 | sd->topic_wait = 1; |
---|
[09e2a69] | 1070 | } |
---|
| 1071 | |
---|
[86278cd] | 1072 | struct groupchat *skype_chat_with(struct im_connection *ic, char *who) |
---|
| 1073 | { |
---|
| 1074 | struct skype_data *sd = ic->proto_data; |
---|
| 1075 | char *ptr, *nick, *buf; |
---|
| 1076 | nick = g_strdup(who); |
---|
| 1077 | ptr = strchr(nick, '@'); |
---|
| 1078 | if(ptr) |
---|
| 1079 | *ptr = '\0'; |
---|
| 1080 | buf = g_strdup_printf("CHAT CREATE %s\n", nick); |
---|
| 1081 | skype_write(ic, buf, strlen(buf)); |
---|
| 1082 | g_free(buf); |
---|
| 1083 | sd->groupchat_with = g_strdup(nick); |
---|
| 1084 | g_free(nick); |
---|
[5652d43] | 1085 | /* We create a fake chat for now. We will replace it with a real one in |
---|
| 1086 | * the real callback. */ |
---|
| 1087 | return(imcb_chat_new( ic, "" )); |
---|
[86278cd] | 1088 | } |
---|
| 1089 | |
---|
[67454bd] | 1090 | static void skype_get_info(struct im_connection *ic, char *who) |
---|
| 1091 | { |
---|
| 1092 | char *ptr, *nick, *buf; |
---|
| 1093 | nick = g_strdup(who); |
---|
| 1094 | ptr = strchr(nick, '@'); |
---|
| 1095 | if(ptr) |
---|
| 1096 | *ptr = '\0'; |
---|
| 1097 | buf = g_strdup_printf("GET USER %s FULLNAME\n", nick); |
---|
| 1098 | skype_write(ic, buf, strlen(buf)); |
---|
| 1099 | g_free(buf); |
---|
| 1100 | buf = g_strdup_printf("GET USER %s PHONE_HOME\n", nick); |
---|
| 1101 | skype_write(ic, buf, strlen(buf)); |
---|
| 1102 | g_free(buf); |
---|
| 1103 | buf = g_strdup_printf("GET USER %s PHONE_OFFICE\n", nick); |
---|
| 1104 | skype_write(ic, buf, strlen(buf)); |
---|
| 1105 | g_free(buf); |
---|
| 1106 | buf = g_strdup_printf("GET USER %s PHONE_MOBILE\n", nick); |
---|
| 1107 | skype_write(ic, buf, strlen(buf)); |
---|
| 1108 | g_free(buf); |
---|
| 1109 | buf = g_strdup_printf("GET USER %s NROF_AUTHED_BUDDIES\n", nick); |
---|
| 1110 | skype_write(ic, buf, strlen(buf)); |
---|
| 1111 | g_free(buf); |
---|
| 1112 | buf = g_strdup_printf("GET USER %s TIMEZONE\n", nick); |
---|
| 1113 | skype_write(ic, buf, strlen(buf)); |
---|
| 1114 | g_free(buf); |
---|
| 1115 | buf = g_strdup_printf("GET USER %s LASTONLINETIMESTAMP\n", nick); |
---|
| 1116 | skype_write(ic, buf, strlen(buf)); |
---|
| 1117 | g_free(buf); |
---|
| 1118 | buf = g_strdup_printf("GET USER %s BIRTHDAY\n", nick); |
---|
| 1119 | skype_write(ic, buf, strlen(buf)); |
---|
| 1120 | g_free(buf); |
---|
| 1121 | buf = g_strdup_printf("GET USER %s SEX\n", nick); |
---|
| 1122 | skype_write(ic, buf, strlen(buf)); |
---|
| 1123 | g_free(buf); |
---|
| 1124 | buf = g_strdup_printf("GET USER %s LANGUAGE\n", nick); |
---|
| 1125 | skype_write(ic, buf, strlen(buf)); |
---|
| 1126 | g_free(buf); |
---|
| 1127 | buf = g_strdup_printf("GET USER %s COUNTRY\n", nick); |
---|
| 1128 | skype_write(ic, buf, strlen(buf)); |
---|
| 1129 | g_free(buf); |
---|
| 1130 | buf = g_strdup_printf("GET USER %s PROVINCE\n", nick); |
---|
| 1131 | skype_write(ic, buf, strlen(buf)); |
---|
| 1132 | g_free(buf); |
---|
| 1133 | buf = g_strdup_printf("GET USER %s CITY\n", nick); |
---|
| 1134 | skype_write(ic, buf, strlen(buf)); |
---|
| 1135 | g_free(buf); |
---|
| 1136 | buf = g_strdup_printf("GET USER %s HOMEPAGE\n", nick); |
---|
| 1137 | skype_write(ic, buf, strlen(buf)); |
---|
| 1138 | g_free(buf); |
---|
| 1139 | buf = g_strdup_printf("GET USER %s ABOUT\n", nick); |
---|
| 1140 | skype_write(ic, buf, strlen(buf)); |
---|
| 1141 | g_free(buf); |
---|
| 1142 | } |
---|
| 1143 | |
---|
[93dffea] | 1144 | static void skype_set_my_name( struct im_connection *ic, char *info ) |
---|
| 1145 | { |
---|
| 1146 | skype_set_display_name( set_find( &ic->acc->set, "display_name" ), info ); |
---|
| 1147 | } |
---|
| 1148 | |
---|
| 1149 | static void skype_init( account_t *acc ) |
---|
| 1150 | { |
---|
| 1151 | set_t *s; |
---|
| 1152 | |
---|
| 1153 | s = set_add( &acc->set, "server", SKYPE_DEFAULT_SERVER, set_eval_account, acc ); |
---|
| 1154 | s->flags |= ACC_SET_OFFLINE_ONLY; |
---|
| 1155 | |
---|
| 1156 | s = set_add( &acc->set, "port", SKYPE_DEFAULT_PORT, set_eval_int, acc ); |
---|
| 1157 | s->flags |= ACC_SET_OFFLINE_ONLY; |
---|
| 1158 | |
---|
| 1159 | s = set_add( &acc->set, "display_name", NULL, skype_set_display_name, acc ); |
---|
| 1160 | s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY; |
---|
[b68b023] | 1161 | |
---|
| 1162 | s = set_add( &acc->set, "call", NULL, skype_set_call, acc ); |
---|
| 1163 | s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY; |
---|
[93dffea] | 1164 | } |
---|
| 1165 | |
---|
[f06e3ac] | 1166 | void init_plugin(void) |
---|
| 1167 | { |
---|
| 1168 | struct prpl *ret = g_new0( struct prpl, 1 ); |
---|
| 1169 | |
---|
| 1170 | ret->name = "skype"; |
---|
| 1171 | ret->login = skype_login; |
---|
| 1172 | ret->init = skype_init; |
---|
| 1173 | ret->logout = skype_logout; |
---|
[93ece66] | 1174 | ret->buddy_msg = skype_buddy_msg; |
---|
[67454bd] | 1175 | ret->get_info = skype_get_info; |
---|
[93dffea] | 1176 | ret->set_my_name = skype_set_my_name; |
---|
[f06e3ac] | 1177 | ret->away_states = skype_away_states; |
---|
[7daec06] | 1178 | ret->set_away = skype_set_away; |
---|
[f06e3ac] | 1179 | ret->add_buddy = skype_add_buddy; |
---|
| 1180 | ret->remove_buddy = skype_remove_buddy; |
---|
[66c9558] | 1181 | ret->chat_msg = skype_chat_msg; |
---|
[b01dc6c] | 1182 | ret->chat_leave = skype_chat_leave; |
---|
[760319d] | 1183 | ret->chat_invite = skype_chat_invite; |
---|
[86278cd] | 1184 | ret->chat_with = skype_chat_with; |
---|
[f06e3ac] | 1185 | ret->handle_cmp = g_strcasecmp; |
---|
[09e2a69] | 1186 | ret->chat_topic = skype_chat_topic; |
---|
[f06e3ac] | 1187 | register_protocol( ret ); |
---|
| 1188 | } |
---|
[6172871] | 1189 | |
---|
| 1190 | /* vim: set ts=2 sw=2 noet: */ |
---|