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