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