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