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