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