[7daec06] | 1 | /* |
---|
| 2 | * skype.c - Skype plugin for BitlBee |
---|
[5adcc65] | 3 | * |
---|
[7cf146f] | 4 | * Copyright (c) 2007, 2008, 2009, 2010 by Miklos Vajna <vmiklos@frugalware.org> |
---|
[f06e3ac] | 5 | * |
---|
[7daec06] | 6 | * This program is free software; you can redistribute it and/or modify |
---|
| 7 | * it under the terms of the GNU General Public License as published by |
---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 9 | * (at your option) any later version. |
---|
| 10 | * |
---|
| 11 | * This program is distributed in the hope that it will be useful, |
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | * GNU General Public License for more details. |
---|
| 15 | * |
---|
| 16 | * You should have received a copy of the GNU General Public License |
---|
| 17 | * along with this program; if not, write to the Free Software |
---|
[5adcc65] | 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
---|
[7daec06] | 19 | * USA. |
---|
[f06e3ac] | 20 | */ |
---|
[7daec06] | 21 | |
---|
[f9c3e7b] | 22 | #define _XOPEN_SOURCE |
---|
[1f4fc80] | 23 | #define _BSD_SOURCE |
---|
[ed2e37f] | 24 | #include <poll.h> |
---|
[f06e3ac] | 25 | #include <bitlbee.h> |
---|
[7f41495] | 26 | #include <ssl_client.h> |
---|
[f06e3ac] | 27 | |
---|
[f5aedd91] | 28 | #define SKYPE_DEFAULT_SERVER "localhost" |
---|
[4bbd9db] | 29 | #define SKYPE_DEFAULT_PORT "2727" |
---|
[c213d6b] | 30 | #define IRC_LINE_SIZE 1024 |
---|
[ff436ba] | 31 | #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) |
---|
[f06e3ac] | 32 | |
---|
[78d22cd0] | 33 | /* |
---|
| 34 | * Compatibility with BitlBee 1.3+ |
---|
| 35 | */ |
---|
[7670b02] | 36 | #if BITLBEE_VERSION_CODE < BITLBEE_VER(1, 3, 0) |
---|
| 37 | #define B_EV_IO_READ GAIM_INPUT_READ |
---|
[78d22cd0] | 38 | #endif |
---|
| 39 | |
---|
[bbba374] | 40 | /* |
---|
| 41 | * Enumerations |
---|
| 42 | */ |
---|
| 43 | |
---|
[359f4d9] | 44 | enum { |
---|
[df9255d] | 45 | SKYPE_CALL_RINGING = 1, |
---|
[9db0234] | 46 | SKYPE_CALL_MISSED, |
---|
[2eb4b1f] | 47 | SKYPE_CALL_CANCELLED, |
---|
[acd9478] | 48 | SKYPE_CALL_FINISHED, |
---|
[d87daf3] | 49 | SKYPE_CALL_REFUSED |
---|
[5365f84] | 50 | }; |
---|
[bbba374] | 51 | |
---|
[359f4d9] | 52 | enum { |
---|
[df9255d] | 53 | SKYPE_FILETRANSFER_NEW = 1, |
---|
| 54 | SKYPE_FILETRANSFER_FAILED |
---|
[5365f84] | 55 | }; |
---|
[df9255d] | 56 | |
---|
[7daec06] | 57 | /* |
---|
| 58 | * Structures |
---|
| 59 | */ |
---|
| 60 | |
---|
[5adcc65] | 61 | struct skype_data { |
---|
[f06e3ac] | 62 | struct im_connection *ic; |
---|
[a3d6427] | 63 | char *username; |
---|
[368861e] | 64 | /* The effective file descriptor. We store it here so any function can |
---|
| 65 | * write() to it. */ |
---|
[f06e3ac] | 66 | int fd; |
---|
[368861e] | 67 | /* File descriptor returned by bitlbee. we store it so we know when |
---|
| 68 | * we're connected and when we aren't. */ |
---|
| 69 | int bfd; |
---|
[c7304b2] | 70 | /* ssl_getfd() uses this to get the file desciptor. */ |
---|
| 71 | void *ssl; |
---|
[2a0f99c] | 72 | /* When we receive a new message id, we query the properties, finally |
---|
| 73 | * the chatname. Store the properties here so that we can use |
---|
[c81d0ef] | 74 | * imcb_buddy_msg() when we got the chatname. */ |
---|
[77c1abe] | 75 | char *handle; |
---|
[a7af5f0] | 76 | /* List, because of multiline messages. */ |
---|
| 77 | GList *body; |
---|
[2a0f99c] | 78 | char *type; |
---|
[bbba374] | 79 | /* This is necessary because we send a notification when we get the |
---|
| 80 | * handle. So we store the state here and then we can send a |
---|
| 81 | * notification about the handle is in a given status. */ |
---|
[359f4d9] | 82 | int call_status; |
---|
[2eb4b1f] | 83 | char *call_id; |
---|
[48181f0] | 84 | char *call_duration; |
---|
[d87daf3] | 85 | /* If the call is outgoing or not */ |
---|
| 86 | int call_out; |
---|
[df9255d] | 87 | /* Same for file transfers. */ |
---|
[359f4d9] | 88 | int filetransfer_status; |
---|
[86278cd] | 89 | /* Using /j #nick we want to have a groupchat with two people. Usually |
---|
| 90 | * not (default). */ |
---|
[5adcc65] | 91 | char *groupchat_with; |
---|
[f8674db] | 92 | /* The user who invited us to the chat. */ |
---|
[5adcc65] | 93 | char *adder; |
---|
[a5f76a2] | 94 | /* If we are waiting for a confirmation about we changed the topic. */ |
---|
| 95 | int topic_wait; |
---|
[67454bd] | 96 | /* These are used by the info command. */ |
---|
| 97 | char *info_fullname; |
---|
| 98 | char *info_phonehome; |
---|
| 99 | char *info_phoneoffice; |
---|
| 100 | char *info_phonemobile; |
---|
| 101 | char *info_nrbuddies; |
---|
| 102 | char *info_tz; |
---|
| 103 | char *info_seen; |
---|
| 104 | char *info_birthday; |
---|
| 105 | char *info_sex; |
---|
| 106 | char *info_language; |
---|
| 107 | char *info_country; |
---|
| 108 | char *info_province; |
---|
| 109 | char *info_city; |
---|
| 110 | char *info_homepage; |
---|
| 111 | char *info_about; |
---|
[b054fad] | 112 | /* When a call fails, we get the reason and later we get the failure |
---|
| 113 | * event, so store the failure code here till then */ |
---|
| 114 | int failurereason; |
---|
[d9ce18c] | 115 | /* If this is just an update of an already received message. */ |
---|
| 116 | int is_edit; |
---|
[f06e3ac] | 117 | }; |
---|
| 118 | |
---|
[5adcc65] | 119 | struct skype_away_state { |
---|
[adce2de] | 120 | char *code; |
---|
| 121 | char *full_name; |
---|
| 122 | }; |
---|
| 123 | |
---|
[5adcc65] | 124 | struct skype_buddy_ask_data { |
---|
[7daec06] | 125 | struct im_connection *ic; |
---|
[e0074cb] | 126 | /* This is also used for call IDs for simplicity */ |
---|
[7daec06] | 127 | char *handle; |
---|
| 128 | }; |
---|
| 129 | |
---|
| 130 | /* |
---|
| 131 | * Tables |
---|
| 132 | */ |
---|
| 133 | |
---|
[5adcc65] | 134 | const struct skype_away_state skype_away_state_list[] = { |
---|
[bc744df] | 135 | { "AWAY", "Away" }, |
---|
| 136 | { "NA", "Not available" }, |
---|
| 137 | { "DND", "Do Not Disturb" }, |
---|
| 138 | { "INVISIBLE", "Invisible" }, |
---|
| 139 | { "OFFLINE", "Offline" }, |
---|
[4b740c2] | 140 | { "SKYPEME", "Skype Me" }, |
---|
| 141 | { "ONLINE", "Online" }, |
---|
[23411c6] | 142 | { NULL, NULL} |
---|
[adce2de] | 143 | }; |
---|
| 144 | |
---|
[7daec06] | 145 | /* |
---|
| 146 | * Functions |
---|
| 147 | */ |
---|
[d3cbd17] | 148 | |
---|
[7c300bb] | 149 | int skype_write(struct im_connection *ic, char *buf, int len) |
---|
[f06e3ac] | 150 | { |
---|
| 151 | struct skype_data *sd = ic->proto_data; |
---|
[1fb89e3] | 152 | struct pollfd pfd[1]; |
---|
| 153 | |
---|
[e8e2892] | 154 | if (!sd->ssl) |
---|
| 155 | return FALSE; |
---|
| 156 | |
---|
[1fb89e3] | 157 | pfd[0].fd = sd->fd; |
---|
| 158 | pfd[0].events = POLLOUT; |
---|
[f06e3ac] | 159 | |
---|
[7daec06] | 160 | /* This poll is necessary or we'll get a SIGPIPE when we write() to |
---|
| 161 | * sd->fd. */ |
---|
[1fb89e3] | 162 | poll(pfd, 1, 1000); |
---|
[5adcc65] | 163 | if (pfd[0].revents & POLLHUP) { |
---|
| 164 | imc_logout(ic, TRUE); |
---|
[1fb89e3] | 165 | return FALSE; |
---|
| 166 | } |
---|
[5adcc65] | 167 | ssl_write(sd->ssl, buf, len); |
---|
[f06e3ac] | 168 | |
---|
[9fd4241] | 169 | return TRUE; |
---|
[f06e3ac] | 170 | } |
---|
| 171 | |
---|
[1f4fc80] | 172 | int skype_printf(struct im_connection *ic, char *fmt, ...) |
---|
| 173 | { |
---|
| 174 | va_list args; |
---|
| 175 | char str[IRC_LINE_SIZE]; |
---|
[5d9db76] | 176 | |
---|
[1f4fc80] | 177 | va_start(args, fmt); |
---|
| 178 | vsnprintf(str, IRC_LINE_SIZE, fmt, args); |
---|
| 179 | va_end(args); |
---|
| 180 | |
---|
[7c300bb] | 181 | return skype_write(ic, str, strlen(str)); |
---|
[1f4fc80] | 182 | } |
---|
| 183 | |
---|
[5adcc65] | 184 | static void skype_buddy_ask_yes(void *data) |
---|
[d3cbd17] | 185 | { |
---|
[039116a] | 186 | struct skype_buddy_ask_data *bla = data; |
---|
[1f4fc80] | 187 | skype_printf(bla->ic, "SET USER %s ISAUTHORIZED TRUE", |
---|
[8c09bb3] | 188 | bla->handle); |
---|
[d3cbd17] | 189 | g_free(bla->handle); |
---|
| 190 | g_free(bla); |
---|
| 191 | } |
---|
| 192 | |
---|
[5adcc65] | 193 | static void skype_buddy_ask_no(void *data) |
---|
[d3cbd17] | 194 | { |
---|
[039116a] | 195 | struct skype_buddy_ask_data *bla = data; |
---|
[1f4fc80] | 196 | skype_printf(bla->ic, "SET USER %s ISAUTHORIZED FALSE", |
---|
[8c09bb3] | 197 | bla->handle); |
---|
[d3cbd17] | 198 | g_free(bla->handle); |
---|
| 199 | g_free(bla); |
---|
| 200 | } |
---|
| 201 | |
---|
[5adcc65] | 202 | void skype_buddy_ask(struct im_connection *ic, char *handle, char *message) |
---|
[d3cbd17] | 203 | { |
---|
[8c09bb3] | 204 | struct skype_buddy_ask_data *bla = g_new0(struct skype_buddy_ask_data, |
---|
| 205 | 1); |
---|
[d3cbd17] | 206 | char *buf; |
---|
| 207 | |
---|
| 208 | bla->ic = ic; |
---|
| 209 | bla->handle = g_strdup(handle); |
---|
| 210 | |
---|
[8c09bb3] | 211 | buf = g_strdup_printf("The user %s wants to add you to " |
---|
| 212 | "his/her buddy list, saying: '%s'.", handle, message); |
---|
[5adcc65] | 213 | imcb_ask(ic, buf, bla, skype_buddy_ask_yes, skype_buddy_ask_no); |
---|
| 214 | g_free(buf); |
---|
[d3cbd17] | 215 | } |
---|
| 216 | |
---|
[5adcc65] | 217 | static void skype_call_ask_yes(void *data) |
---|
[e0074cb] | 218 | { |
---|
[039116a] | 219 | struct skype_buddy_ask_data *bla = data; |
---|
[1f4fc80] | 220 | skype_printf(bla->ic, "SET CALL %s STATUS INPROGRESS", |
---|
[8c09bb3] | 221 | bla->handle); |
---|
[e0074cb] | 222 | g_free(bla->handle); |
---|
| 223 | g_free(bla); |
---|
| 224 | } |
---|
| 225 | |
---|
[5adcc65] | 226 | static void skype_call_ask_no(void *data) |
---|
[e0074cb] | 227 | { |
---|
[039116a] | 228 | struct skype_buddy_ask_data *bla = data; |
---|
[1f4fc80] | 229 | skype_printf(bla->ic, "SET CALL %s STATUS FINISHED", |
---|
[8c09bb3] | 230 | bla->handle); |
---|
[e0074cb] | 231 | g_free(bla->handle); |
---|
| 232 | g_free(bla); |
---|
| 233 | } |
---|
| 234 | |
---|
[5adcc65] | 235 | void skype_call_ask(struct im_connection *ic, char *call_id, char *message) |
---|
[e0074cb] | 236 | { |
---|
[8c09bb3] | 237 | struct skype_buddy_ask_data *bla = g_new0(struct skype_buddy_ask_data, |
---|
| 238 | 1); |
---|
[e0074cb] | 239 | |
---|
| 240 | bla->ic = ic; |
---|
| 241 | bla->handle = g_strdup(call_id); |
---|
| 242 | |
---|
[5adcc65] | 243 | imcb_ask(ic, message, bla, skype_call_ask_yes, skype_call_ask_no); |
---|
[e0074cb] | 244 | } |
---|
[5adcc65] | 245 | struct groupchat *skype_chat_by_name(struct im_connection *ic, char *name) |
---|
[72aa7f0] | 246 | { |
---|
[78d22cd0] | 247 | #if BITLBEE_VERSION_CODE < BITLBEE_VER(1, 3, 0) |
---|
[72aa7f0] | 248 | struct groupchat *ret; |
---|
| 249 | |
---|
[5adcc65] | 250 | for (ret = ic->groupchats; ret; ret = ret->next) |
---|
| 251 | if (strcmp(name, ret->title) == 0) |
---|
[72aa7f0] | 252 | break; |
---|
| 253 | |
---|
| 254 | return ret; |
---|
[78d22cd0] | 255 | #else |
---|
| 256 | return bee_chat_by_title(ic->bee, ic, name); |
---|
| 257 | #endif |
---|
[72aa7f0] | 258 | } |
---|
| 259 | |
---|
[b054fad] | 260 | static char *skype_call_strerror(int err) |
---|
| 261 | { |
---|
[5adcc65] | 262 | switch (err) { |
---|
| 263 | case 1: |
---|
| 264 | return "Miscellaneous error"; |
---|
| 265 | case 2: |
---|
| 266 | return "User or phone number does not exist."; |
---|
| 267 | case 3: |
---|
| 268 | return "User is offline"; |
---|
| 269 | case 4: |
---|
| 270 | return "No proxy found"; |
---|
| 271 | case 5: |
---|
| 272 | return "Session terminated."; |
---|
| 273 | case 6: |
---|
| 274 | return "No common codec found."; |
---|
| 275 | case 7: |
---|
| 276 | return "Sound I/O error."; |
---|
| 277 | case 8: |
---|
| 278 | return "Problem with remote sound device."; |
---|
| 279 | case 9: |
---|
| 280 | return "Call blocked by recipient."; |
---|
| 281 | case 10: |
---|
| 282 | return "Recipient not a friend."; |
---|
| 283 | case 11: |
---|
| 284 | return "Current user not authorized by recipient."; |
---|
| 285 | case 12: |
---|
| 286 | return "Sound recording error."; |
---|
| 287 | default: |
---|
| 288 | return "Unknown error"; |
---|
[b054fad] | 289 | } |
---|
| 290 | } |
---|
| 291 | |
---|
[078b0b9] | 292 | static void skype_parse_users(struct im_connection *ic, char *line) |
---|
| 293 | { |
---|
[1f4fc80] | 294 | char **i, **nicks; |
---|
[078b0b9] | 295 | |
---|
| 296 | nicks = g_strsplit(line + 6, ", ", 0); |
---|
[1f4fc80] | 297 | for (i = nicks; *i; i++) |
---|
| 298 | skype_printf(ic, "GET USER %s ONLINESTATUS\n", *i); |
---|
[078b0b9] | 299 | g_strfreev(nicks); |
---|
| 300 | } |
---|
| 301 | |
---|
[6e14204] | 302 | static void skype_parse_user(struct im_connection *ic, char *line) |
---|
| 303 | { |
---|
| 304 | int flags = 0; |
---|
| 305 | char *ptr; |
---|
| 306 | struct skype_data *sd = ic->proto_data; |
---|
| 307 | char *user = strchr(line, ' '); |
---|
| 308 | char *status = strrchr(line, ' '); |
---|
| 309 | |
---|
| 310 | status++; |
---|
| 311 | ptr = strchr(++user, ' '); |
---|
| 312 | if (!ptr) |
---|
| 313 | return; |
---|
| 314 | *ptr = '\0'; |
---|
| 315 | ptr++; |
---|
[49a3c02] | 316 | if (!strncmp(ptr, "ONLINESTATUS ", 13)) { |
---|
| 317 | if (!strcmp(user, sd->username)) |
---|
| 318 | return; |
---|
| 319 | if (!set_getbool(&ic->acc->set, "test_join") |
---|
| 320 | && !strcmp(user, "echo123")) |
---|
| 321 | return; |
---|
[6e14204] | 322 | ptr = g_strdup_printf("%s@skype.com", user); |
---|
| 323 | imcb_add_buddy(ic, ptr, NULL); |
---|
[62f51ee9] | 324 | if (strcmp(status, "OFFLINE") && (strcmp(status, "SKYPEOUT") || |
---|
| 325 | !set_getbool(&ic->acc->set, "skypeout_offline"))) |
---|
[6e14204] | 326 | flags |= OPT_LOGGED_IN; |
---|
[62f51ee9] | 327 | if (strcmp(status, "ONLINE") && strcmp(status, "SKYPEME")) |
---|
[6e14204] | 328 | flags |= OPT_AWAY; |
---|
| 329 | imcb_buddy_status(ic, ptr, flags, NULL, NULL); |
---|
| 330 | g_free(ptr); |
---|
| 331 | } else if (!strncmp(ptr, "RECEIVEDAUTHREQUEST ", 20)) { |
---|
| 332 | char *message = ptr + 20; |
---|
| 333 | if (strlen(message)) |
---|
| 334 | skype_buddy_ask(ic, user, message); |
---|
| 335 | } else if (!strncmp(ptr, "BUDDYSTATUS ", 12)) { |
---|
| 336 | char *st = ptr + 12; |
---|
| 337 | if (!strcmp(st, "3")) { |
---|
| 338 | char *buf = g_strdup_printf("%s@skype.com", user); |
---|
| 339 | imcb_add_buddy(ic, buf, NULL); |
---|
| 340 | g_free(buf); |
---|
| 341 | } |
---|
[78d22cd0] | 342 | } else if (!strncmp(ptr, "MOOD_TEXT ", 10)) { |
---|
[4c674bb] | 343 | char *buf = g_strdup_printf("%s@skype.com", user); |
---|
[78d22cd0] | 344 | #if BITLBEE_VERSION_CODE < BITLBEE_VER(1, 3, 0) |
---|
[4c674bb] | 345 | user_t *u = user_findhandle(ic, buf); |
---|
| 346 | g_free(buf); |
---|
| 347 | buf = ptr + 10; |
---|
| 348 | if (u) { |
---|
| 349 | if (u->status_msg) |
---|
| 350 | g_free(u->status_msg); |
---|
| 351 | if (strlen(buf)) |
---|
| 352 | u->status_msg = g_strdup(buf); |
---|
| 353 | else |
---|
| 354 | u->status_msg = NULL; |
---|
| 355 | } |
---|
[78d22cd0] | 356 | #else |
---|
| 357 | bee_user_t *bu = bee_user_by_handle(ic->bee, ic, buf); |
---|
| 358 | g_free(buf); |
---|
| 359 | buf = ptr + 10; |
---|
| 360 | if (bu) { |
---|
| 361 | imcb_buddy_status(ic, bu->handle, bu->flags, NULL, |
---|
[4ab7225] | 362 | *buf ? buf : NULL); |
---|
[78d22cd0] | 363 | } |
---|
| 364 | #endif |
---|
| 365 | if (set_getbool(&ic->acc->set, "show_moods")) |
---|
| 366 | imcb_log(ic, "User `%s' changed mood text to `%s'", user, buf); |
---|
[3518933] | 367 | } else if (!strncmp(ptr, "FULLNAME ", 9)) |
---|
[d7938f9] | 368 | sd->info_fullname = g_strdup(ptr + 9); |
---|
[6e14204] | 369 | else if (!strncmp(ptr, "PHONE_HOME ", 11)) |
---|
[d7938f9] | 370 | sd->info_phonehome = g_strdup(ptr + 11); |
---|
[6e14204] | 371 | else if (!strncmp(ptr, "PHONE_OFFICE ", 13)) |
---|
[d7938f9] | 372 | sd->info_phoneoffice = g_strdup(ptr + 13); |
---|
[6e14204] | 373 | else if (!strncmp(ptr, "PHONE_MOBILE ", 13)) |
---|
[d7938f9] | 374 | sd->info_phonemobile = g_strdup(ptr + 13); |
---|
[6e14204] | 375 | else if (!strncmp(ptr, "NROF_AUTHED_BUDDIES ", 20)) |
---|
[d7938f9] | 376 | sd->info_nrbuddies = g_strdup(ptr + 20); |
---|
[6e14204] | 377 | else if (!strncmp(ptr, "TIMEZONE ", 9)) |
---|
[d7938f9] | 378 | sd->info_tz = g_strdup(ptr + 9); |
---|
[6e14204] | 379 | else if (!strncmp(ptr, "LASTONLINETIMESTAMP ", 20)) |
---|
[d7938f9] | 380 | sd->info_seen = g_strdup(ptr + 20); |
---|
[6e14204] | 381 | else if (!strncmp(ptr, "BIRTHDAY ", 9)) |
---|
[d7938f9] | 382 | sd->info_birthday = g_strdup(ptr + 9); |
---|
[6e14204] | 383 | else if (!strncmp(ptr, "SEX ", 4)) |
---|
[d7938f9] | 384 | sd->info_sex = g_strdup(ptr + 4); |
---|
[6e14204] | 385 | else if (!strncmp(ptr, "LANGUAGE ", 9)) |
---|
[d7938f9] | 386 | sd->info_language = g_strdup(ptr + 9); |
---|
[6e14204] | 387 | else if (!strncmp(ptr, "COUNTRY ", 8)) |
---|
[d7938f9] | 388 | sd->info_country = g_strdup(ptr + 8); |
---|
[6e14204] | 389 | else if (!strncmp(ptr, "PROVINCE ", 9)) |
---|
[d7938f9] | 390 | sd->info_province = g_strdup(ptr + 9); |
---|
[6e14204] | 391 | else if (!strncmp(ptr, "CITY ", 5)) |
---|
[d7938f9] | 392 | sd->info_city = g_strdup(ptr + 5); |
---|
[6e14204] | 393 | else if (!strncmp(ptr, "HOMEPAGE ", 9)) |
---|
[d7938f9] | 394 | sd->info_homepage = g_strdup(ptr + 9); |
---|
[6e14204] | 395 | else if (!strncmp(ptr, "ABOUT ", 6)) { |
---|
[d7938f9] | 396 | sd->info_about = g_strdup(ptr + 6); |
---|
[6e14204] | 397 | |
---|
| 398 | GString *st = g_string_new("Contact Information\n"); |
---|
| 399 | g_string_append_printf(st, "Skype Name: %s\n", user); |
---|
| 400 | if (sd->info_fullname) { |
---|
| 401 | if (strlen(sd->info_fullname)) |
---|
[62f51ee9] | 402 | g_string_append_printf(st, "Full Name: %s\n", |
---|
| 403 | sd->info_fullname); |
---|
[6e14204] | 404 | g_free(sd->info_fullname); |
---|
| 405 | } |
---|
| 406 | if (sd->info_phonehome) { |
---|
| 407 | if (strlen(sd->info_phonehome)) |
---|
[62f51ee9] | 408 | g_string_append_printf(st, "Home Phone: %s\n", |
---|
| 409 | sd->info_phonehome); |
---|
[6e14204] | 410 | g_free(sd->info_phonehome); |
---|
| 411 | } |
---|
| 412 | if (sd->info_phoneoffice) { |
---|
| 413 | if (strlen(sd->info_phoneoffice)) |
---|
[62f51ee9] | 414 | g_string_append_printf(st, "Office Phone: %s\n", |
---|
| 415 | sd->info_phoneoffice); |
---|
[6e14204] | 416 | g_free(sd->info_phoneoffice); |
---|
| 417 | } |
---|
| 418 | if (sd->info_phonemobile) { |
---|
| 419 | if (strlen(sd->info_phonemobile)) |
---|
[62f51ee9] | 420 | g_string_append_printf(st, "Mobile Phone: %s\n", |
---|
| 421 | sd->info_phonemobile); |
---|
[6e14204] | 422 | g_free(sd->info_phonemobile); |
---|
| 423 | } |
---|
| 424 | g_string_append_printf(st, "Personal Information\n"); |
---|
| 425 | if (sd->info_nrbuddies) { |
---|
| 426 | if (strlen(sd->info_nrbuddies)) |
---|
[62f51ee9] | 427 | g_string_append_printf(st, |
---|
| 428 | "Contacts: %s\n", sd->info_nrbuddies); |
---|
[6e14204] | 429 | g_free(sd->info_nrbuddies); |
---|
| 430 | } |
---|
| 431 | if (sd->info_tz) { |
---|
| 432 | if (strlen(sd->info_tz)) { |
---|
| 433 | char ib[256]; |
---|
| 434 | time_t t = time(NULL); |
---|
| 435 | t += atoi(sd->info_tz)-(60*60*24); |
---|
| 436 | struct tm *gt = gmtime(&t); |
---|
| 437 | strftime(ib, 256, "%H:%M:%S", gt); |
---|
[62f51ee9] | 438 | g_string_append_printf(st, |
---|
| 439 | "Local Time: %s\n", ib); |
---|
[6e14204] | 440 | } |
---|
| 441 | g_free(sd->info_tz); |
---|
| 442 | } |
---|
| 443 | if (sd->info_seen) { |
---|
| 444 | if (strlen(sd->info_seen)) { |
---|
| 445 | char ib[256]; |
---|
| 446 | time_t it = atoi(sd->info_seen); |
---|
| 447 | struct tm *tm = localtime(&it); |
---|
| 448 | strftime(ib, 256, ("%Y. %m. %d. %H:%M"), tm); |
---|
[62f51ee9] | 449 | g_string_append_printf(st, |
---|
| 450 | "Last Seen: %s\n", ib); |
---|
[6e14204] | 451 | } |
---|
| 452 | g_free(sd->info_seen); |
---|
| 453 | } |
---|
| 454 | if (sd->info_birthday) { |
---|
[62f51ee9] | 455 | if (strlen(sd->info_birthday) && |
---|
| 456 | strcmp(sd->info_birthday, "0")) { |
---|
[6e14204] | 457 | char ib[256]; |
---|
| 458 | struct tm tm; |
---|
| 459 | strptime(sd->info_birthday, "%Y%m%d", &tm); |
---|
| 460 | strftime(ib, 256, "%B %d, %Y", &tm); |
---|
[62f51ee9] | 461 | g_string_append_printf(st, |
---|
| 462 | "Birthday: %s\n", ib); |
---|
[6e14204] | 463 | |
---|
| 464 | strftime(ib, 256, "%Y", &tm); |
---|
| 465 | int year = atoi(ib); |
---|
| 466 | time_t t = time(NULL); |
---|
| 467 | struct tm *lt = localtime(&t); |
---|
[62f51ee9] | 468 | g_string_append_printf(st, |
---|
| 469 | "Age: %d\n", lt->tm_year+1900-year); |
---|
[6e14204] | 470 | } |
---|
| 471 | g_free(sd->info_birthday); |
---|
| 472 | } |
---|
| 473 | if (sd->info_sex) { |
---|
| 474 | if (strlen(sd->info_sex)) { |
---|
| 475 | char *iptr = sd->info_sex; |
---|
| 476 | while (*iptr++) |
---|
| 477 | *iptr = tolower(*iptr); |
---|
[62f51ee9] | 478 | g_string_append_printf(st, |
---|
| 479 | "Gender: %s\n", sd->info_sex); |
---|
[6e14204] | 480 | } |
---|
| 481 | g_free(sd->info_sex); |
---|
| 482 | } |
---|
| 483 | if (sd->info_language) { |
---|
| 484 | if (strlen(sd->info_language)) { |
---|
| 485 | char *iptr = strchr(sd->info_language, ' '); |
---|
| 486 | if (iptr) |
---|
| 487 | iptr++; |
---|
| 488 | else |
---|
| 489 | iptr = sd->info_language; |
---|
[62f51ee9] | 490 | g_string_append_printf(st, |
---|
| 491 | "Language: %s\n", iptr); |
---|
[6e14204] | 492 | } |
---|
| 493 | g_free(sd->info_language); |
---|
| 494 | } |
---|
| 495 | if (sd->info_country) { |
---|
| 496 | if (strlen(sd->info_country)) { |
---|
| 497 | char *iptr = strchr(sd->info_country, ' '); |
---|
| 498 | if (iptr) |
---|
| 499 | iptr++; |
---|
| 500 | else |
---|
| 501 | iptr = sd->info_country; |
---|
[62f51ee9] | 502 | g_string_append_printf(st, |
---|
| 503 | "Country: %s\n", iptr); |
---|
[6e14204] | 504 | } |
---|
| 505 | g_free(sd->info_country); |
---|
| 506 | } |
---|
| 507 | if (sd->info_province) { |
---|
| 508 | if (strlen(sd->info_province)) |
---|
[62f51ee9] | 509 | g_string_append_printf(st, |
---|
| 510 | "Region: %s\n", sd->info_province); |
---|
[6e14204] | 511 | g_free(sd->info_province); |
---|
| 512 | } |
---|
| 513 | if (sd->info_city) { |
---|
| 514 | if (strlen(sd->info_city)) |
---|
[62f51ee9] | 515 | g_string_append_printf(st, |
---|
| 516 | "City: %s\n", sd->info_city); |
---|
[6e14204] | 517 | g_free(sd->info_city); |
---|
| 518 | } |
---|
| 519 | if (sd->info_homepage) { |
---|
| 520 | if (strlen(sd->info_homepage)) |
---|
[62f51ee9] | 521 | g_string_append_printf(st, |
---|
| 522 | "Homepage: %s\n", sd->info_homepage); |
---|
[6e14204] | 523 | g_free(sd->info_homepage); |
---|
| 524 | } |
---|
| 525 | if (sd->info_about) { |
---|
| 526 | if (strlen(sd->info_about)) |
---|
[62f51ee9] | 527 | g_string_append_printf(st, "%s\n", |
---|
| 528 | sd->info_about); |
---|
[6e14204] | 529 | g_free(sd->info_about); |
---|
| 530 | } |
---|
| 531 | imcb_log(ic, "%s", st->str); |
---|
| 532 | g_string_free(st, TRUE); |
---|
| 533 | } |
---|
| 534 | } |
---|
| 535 | |
---|
| 536 | static void skype_parse_chatmessage(struct im_connection *ic, char *line) |
---|
| 537 | { |
---|
| 538 | struct skype_data *sd = ic->proto_data; |
---|
[c213d6b] | 539 | char buf[IRC_LINE_SIZE]; |
---|
[6e14204] | 540 | char *id = strchr(line, ' '); |
---|
| 541 | |
---|
[6b9d22a] | 542 | if (!++id) |
---|
| 543 | return; |
---|
| 544 | char *info = strchr(id, ' '); |
---|
| 545 | |
---|
| 546 | if (!info) |
---|
| 547 | return; |
---|
| 548 | *info = '\0'; |
---|
| 549 | info++; |
---|
[7825f58] | 550 | if (!strcmp(info, "STATUS RECEIVED") || !strncmp(info, "EDITED_TIMESTAMP", 16)) { |
---|
[6b9d22a] | 551 | /* New message ID: |
---|
| 552 | * (1) Request its from field |
---|
| 553 | * (2) Request its body |
---|
| 554 | * (3) Request its type |
---|
| 555 | * (4) Query chatname |
---|
| 556 | */ |
---|
[1f4fc80] | 557 | skype_printf(ic, "GET CHATMESSAGE %s FROM_HANDLE\n", id); |
---|
[d1d5b34] | 558 | if (!strcmp(info, "STATUS RECEIVED")) |
---|
| 559 | skype_printf(ic, "GET CHATMESSAGE %s BODY\n", id); |
---|
[d9ce18c] | 560 | else |
---|
| 561 | sd->is_edit = 1; |
---|
[1f4fc80] | 562 | skype_printf(ic, "GET CHATMESSAGE %s TYPE\n", id); |
---|
| 563 | skype_printf(ic, "GET CHATMESSAGE %s CHATNAME\n", id); |
---|
[6b9d22a] | 564 | } else if (!strncmp(info, "FROM_HANDLE ", 12)) { |
---|
| 565 | info += 12; |
---|
| 566 | /* New from field value. Store |
---|
| 567 | * it, then we can later use it |
---|
| 568 | * when we got the message's |
---|
| 569 | * body. */ |
---|
| 570 | g_free(sd->handle); |
---|
| 571 | sd->handle = g_strdup_printf("%s@skype.com", info); |
---|
| 572 | } else if (!strncmp(info, "EDITED_BY ", 10)) { |
---|
| 573 | info += 10; |
---|
| 574 | /* This is the same as |
---|
| 575 | * FROM_HANDLE, except that we |
---|
| 576 | * never request these lines |
---|
| 577 | * from Skype, we just get |
---|
| 578 | * them. */ |
---|
| 579 | g_free(sd->handle); |
---|
| 580 | sd->handle = g_strdup_printf("%s@skype.com", info); |
---|
| 581 | } else if (!strncmp(info, "BODY ", 5)) { |
---|
| 582 | info += 5; |
---|
| 583 | sd->body = g_list_append(sd->body, g_strdup(info)); |
---|
| 584 | } else if (!strncmp(info, "TYPE ", 5)) { |
---|
| 585 | info += 5; |
---|
| 586 | g_free(sd->type); |
---|
| 587 | sd->type = g_strdup(info); |
---|
[7825f58] | 588 | } else if (!strncmp(info, "CHATNAME ", 9)) { |
---|
| 589 | info += 9; |
---|
| 590 | if (sd->handle && sd->body && sd->type) { |
---|
| 591 | struct groupchat *gc = skype_chat_by_name(ic, info); |
---|
| 592 | int i; |
---|
| 593 | for (i = 0; i < g_list_length(sd->body); i++) { |
---|
| 594 | char *body = g_list_nth_data(sd->body, i); |
---|
| 595 | if (!strcmp(sd->type, "SAID") || |
---|
| 596 | !strcmp(sd->type, "EMOTED")) { |
---|
| 597 | if (!strcmp(sd->type, "SAID")) { |
---|
| 598 | if (!sd->is_edit) |
---|
| 599 | g_snprintf(buf, IRC_LINE_SIZE, "%s", |
---|
| 600 | body); |
---|
| 601 | else { |
---|
| 602 | g_snprintf(buf, IRC_LINE_SIZE, "%s %s", |
---|
| 603 | set_getstr(&ic->acc->set, "edit_prefix"), |
---|
| 604 | body); |
---|
| 605 | sd->is_edit = 0; |
---|
| 606 | } |
---|
| 607 | } else |
---|
| 608 | g_snprintf(buf, IRC_LINE_SIZE, "/me %s", |
---|
| 609 | body); |
---|
| 610 | if (!gc) |
---|
| 611 | /* Private message */ |
---|
| 612 | imcb_buddy_msg(ic, |
---|
| 613 | sd->handle, buf, 0, 0); |
---|
| 614 | else |
---|
| 615 | /* Groupchat message */ |
---|
| 616 | imcb_chat_msg(gc, |
---|
| 617 | sd->handle, buf, 0, 0); |
---|
| 618 | } else if (!strcmp(sd->type, "SETTOPIC") && gc) |
---|
| 619 | imcb_chat_topic(gc, |
---|
| 620 | sd->handle, body, 0); |
---|
| 621 | else if (!strcmp(sd->type, "LEFT") && gc) |
---|
| 622 | imcb_chat_remove_buddy(gc, |
---|
| 623 | sd->handle, NULL); |
---|
[6e14204] | 624 | } |
---|
[7825f58] | 625 | g_list_free(sd->body); |
---|
| 626 | sd->body = NULL; |
---|
| 627 | } |
---|
[6e14204] | 628 | } |
---|
| 629 | } |
---|
| 630 | |
---|
[9f2f25f] | 631 | static void skype_parse_call(struct im_connection *ic, char *line) |
---|
| 632 | { |
---|
| 633 | struct skype_data *sd = ic->proto_data; |
---|
| 634 | char *id = strchr(line, ' '); |
---|
[c213d6b] | 635 | char buf[IRC_LINE_SIZE]; |
---|
[9f2f25f] | 636 | |
---|
[6b9d22a] | 637 | if (!++id) |
---|
| 638 | return; |
---|
| 639 | char *info = strchr(id, ' '); |
---|
| 640 | |
---|
| 641 | if (!info) |
---|
| 642 | return; |
---|
| 643 | *info = '\0'; |
---|
| 644 | info++; |
---|
| 645 | if (!strncmp(info, "FAILUREREASON ", 14)) |
---|
| 646 | sd->failurereason = atoi(strchr(info, ' ')); |
---|
| 647 | else if (!strcmp(info, "STATUS RINGING")) { |
---|
| 648 | if (sd->call_id) |
---|
| 649 | g_free(sd->call_id); |
---|
| 650 | sd->call_id = g_strdup(id); |
---|
[1f4fc80] | 651 | skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id); |
---|
[6b9d22a] | 652 | sd->call_status = SKYPE_CALL_RINGING; |
---|
| 653 | } else if (!strcmp(info, "STATUS MISSED")) { |
---|
[1f4fc80] | 654 | skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id); |
---|
[6b9d22a] | 655 | sd->call_status = SKYPE_CALL_MISSED; |
---|
| 656 | } else if (!strcmp(info, "STATUS CANCELLED")) { |
---|
[1f4fc80] | 657 | skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id); |
---|
[6b9d22a] | 658 | sd->call_status = SKYPE_CALL_CANCELLED; |
---|
| 659 | } else if (!strcmp(info, "STATUS FINISHED")) { |
---|
[1f4fc80] | 660 | skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id); |
---|
[6b9d22a] | 661 | sd->call_status = SKYPE_CALL_FINISHED; |
---|
| 662 | } else if (!strcmp(info, "STATUS REFUSED")) { |
---|
[1f4fc80] | 663 | skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id); |
---|
[6b9d22a] | 664 | sd->call_status = SKYPE_CALL_REFUSED; |
---|
| 665 | } else if (!strcmp(info, "STATUS UNPLACED")) { |
---|
| 666 | if (sd->call_id) |
---|
| 667 | g_free(sd->call_id); |
---|
| 668 | /* Save the ID for later usage (Cancel/Finish). */ |
---|
| 669 | sd->call_id = g_strdup(id); |
---|
| 670 | sd->call_out = TRUE; |
---|
| 671 | } else if (!strcmp(info, "STATUS FAILED")) { |
---|
[62f51ee9] | 672 | imcb_error(ic, "Call failed: %s", |
---|
| 673 | skype_call_strerror(sd->failurereason)); |
---|
[6b9d22a] | 674 | sd->call_id = NULL; |
---|
| 675 | } else if (!strncmp(info, "DURATION ", 9)) { |
---|
| 676 | if (sd->call_duration) |
---|
| 677 | g_free(sd->call_duration); |
---|
| 678 | sd->call_duration = g_strdup(info+9); |
---|
| 679 | } else if (!strncmp(info, "PARTNER_HANDLE ", 15)) { |
---|
| 680 | info += 15; |
---|
[62f51ee9] | 681 | if (!sd->call_status) |
---|
| 682 | return; |
---|
| 683 | switch (sd->call_status) { |
---|
| 684 | case SKYPE_CALL_RINGING: |
---|
| 685 | if (sd->call_out) |
---|
| 686 | imcb_log(ic, "You are currently ringing " |
---|
| 687 | "the user %s.", info); |
---|
| 688 | else { |
---|
[c213d6b] | 689 | g_snprintf(buf, IRC_LINE_SIZE, |
---|
[62f51ee9] | 690 | "The user %s is currently ringing you.", |
---|
| 691 | info); |
---|
| 692 | skype_call_ask(ic, sd->call_id, buf); |
---|
[9f2f25f] | 693 | } |
---|
[62f51ee9] | 694 | break; |
---|
| 695 | case SKYPE_CALL_MISSED: |
---|
| 696 | imcb_log(ic, "You have missed a call from user %s.", |
---|
| 697 | info); |
---|
| 698 | break; |
---|
| 699 | case SKYPE_CALL_CANCELLED: |
---|
| 700 | imcb_log(ic, "You cancelled the call to the user %s.", |
---|
| 701 | info); |
---|
[6b9d22a] | 702 | sd->call_status = 0; |
---|
[62f51ee9] | 703 | sd->call_out = FALSE; |
---|
| 704 | break; |
---|
| 705 | case SKYPE_CALL_REFUSED: |
---|
| 706 | if (sd->call_out) |
---|
| 707 | imcb_log(ic, "The user %s refused the call.", |
---|
| 708 | info); |
---|
| 709 | else |
---|
| 710 | imcb_log(ic, |
---|
| 711 | "You refused the call from user %s.", |
---|
| 712 | info); |
---|
| 713 | sd->call_out = FALSE; |
---|
| 714 | break; |
---|
| 715 | case SKYPE_CALL_FINISHED: |
---|
| 716 | if (sd->call_duration) |
---|
| 717 | imcb_log(ic, |
---|
| 718 | "You finished the call to the user %s " |
---|
| 719 | "(duration: %s seconds).", |
---|
| 720 | info, sd->call_duration); |
---|
| 721 | else |
---|
| 722 | imcb_log(ic, |
---|
| 723 | "You finished the call to the user %s.", |
---|
| 724 | info); |
---|
| 725 | sd->call_out = FALSE; |
---|
| 726 | break; |
---|
| 727 | default: |
---|
| 728 | /* Don't be noisy, ignore other statuses for now. */ |
---|
| 729 | break; |
---|
[9f2f25f] | 730 | } |
---|
[62f51ee9] | 731 | sd->call_status = 0; |
---|
[9f2f25f] | 732 | } |
---|
| 733 | } |
---|
| 734 | |
---|
[e200daf] | 735 | static void skype_parse_filetransfer(struct im_connection *ic, char *line) |
---|
| 736 | { |
---|
| 737 | struct skype_data *sd = ic->proto_data; |
---|
| 738 | char *id = strchr(line, ' '); |
---|
| 739 | |
---|
[6b9d22a] | 740 | if (!++id) |
---|
| 741 | return; |
---|
| 742 | char *info = strchr(id, ' '); |
---|
| 743 | |
---|
| 744 | if (!info) |
---|
| 745 | return; |
---|
| 746 | *info = '\0'; |
---|
| 747 | info++; |
---|
| 748 | if (!strcmp(info, "STATUS NEW")) { |
---|
[1f4fc80] | 749 | skype_printf(ic, "GET FILETRANSFER %s PARTNER_HANDLE\n", |
---|
[62f51ee9] | 750 | id); |
---|
[6b9d22a] | 751 | sd->filetransfer_status = SKYPE_FILETRANSFER_NEW; |
---|
| 752 | } else if (!strcmp(info, "STATUS FAILED")) { |
---|
[1f4fc80] | 753 | skype_printf(ic, "GET FILETRANSFER %s PARTNER_HANDLE\n", |
---|
[62f51ee9] | 754 | id); |
---|
[6b9d22a] | 755 | sd->filetransfer_status = SKYPE_FILETRANSFER_FAILED; |
---|
| 756 | } else if (!strncmp(info, "PARTNER_HANDLE ", 15)) { |
---|
| 757 | info += 15; |
---|
[62f51ee9] | 758 | if (!sd->filetransfer_status) |
---|
| 759 | return; |
---|
| 760 | switch (sd->filetransfer_status) { |
---|
| 761 | case SKYPE_FILETRANSFER_NEW: |
---|
| 762 | imcb_log(ic, "The user %s offered a new file for you.", |
---|
| 763 | info); |
---|
| 764 | break; |
---|
| 765 | case SKYPE_FILETRANSFER_FAILED: |
---|
| 766 | imcb_log(ic, "Failed to transfer file from user %s.", |
---|
| 767 | info); |
---|
| 768 | break; |
---|
[e200daf] | 769 | } |
---|
[62f51ee9] | 770 | sd->filetransfer_status = 0; |
---|
[e200daf] | 771 | } |
---|
| 772 | } |
---|
| 773 | |
---|
[c35bf7a] | 774 | static void skype_parse_chat(struct im_connection *ic, char *line) |
---|
| 775 | { |
---|
| 776 | struct skype_data *sd = ic->proto_data; |
---|
[c213d6b] | 777 | char buf[IRC_LINE_SIZE]; |
---|
[c35bf7a] | 778 | char *id = strchr(line, ' '); |
---|
| 779 | |
---|
[6b9d22a] | 780 | if (!++id) |
---|
| 781 | return; |
---|
| 782 | struct groupchat *gc; |
---|
| 783 | char *info = strchr(id, ' '); |
---|
[c35bf7a] | 784 | |
---|
[6b9d22a] | 785 | if (!info) |
---|
| 786 | return; |
---|
| 787 | *info = '\0'; |
---|
| 788 | info++; |
---|
| 789 | /* Remove fake chat if we created one in skype_chat_with() */ |
---|
| 790 | gc = skype_chat_by_name(ic, ""); |
---|
| 791 | if (gc) |
---|
| 792 | imcb_chat_free(gc); |
---|
| 793 | if (!strcmp(info, "STATUS MULTI_SUBSCRIBED")) { |
---|
[72b60c7e] | 794 | gc = imcb_chat_new(ic, id); |
---|
| 795 | imcb_chat_name_hint(gc, id); |
---|
[1f4fc80] | 796 | skype_printf(ic, "GET CHAT %s ADDER\n", id); |
---|
| 797 | skype_printf(ic, "GET CHAT %s TOPIC\n", id); |
---|
[6b9d22a] | 798 | } else if (!strcmp(info, "STATUS DIALOG") && sd->groupchat_with) { |
---|
| 799 | gc = imcb_chat_new(ic, id); |
---|
[72b60c7e] | 800 | imcb_chat_name_hint(gc, id); |
---|
[6b9d22a] | 801 | /* According to the docs this |
---|
| 802 | * is necessary. However it |
---|
| 803 | * does not seem the situation |
---|
| 804 | * and it would open an extra |
---|
| 805 | * window on our client, so |
---|
| 806 | * just leave it out. */ |
---|
[1f4fc80] | 807 | /*skype_printf(ic, "OPEN CHAT %s\n", id);*/ |
---|
[5d9db76] | 808 | g_snprintf(buf, IRC_LINE_SIZE, "%s@skype.com", |
---|
| 809 | sd->groupchat_with); |
---|
[6b9d22a] | 810 | imcb_chat_add_buddy(gc, buf); |
---|
| 811 | imcb_chat_add_buddy(gc, sd->username); |
---|
| 812 | g_free(sd->groupchat_with); |
---|
| 813 | sd->groupchat_with = NULL; |
---|
[1f4fc80] | 814 | skype_printf(ic, "GET CHAT %s ADDER\n", id); |
---|
| 815 | skype_printf(ic, "GET CHAT %s TOPIC\n", id); |
---|
[6b9d22a] | 816 | } else if (!strcmp(info, "STATUS UNSUBSCRIBED")) { |
---|
| 817 | gc = skype_chat_by_name(ic, id); |
---|
[c35bf7a] | 818 | if (gc) |
---|
[6b9d22a] | 819 | gc->data = (void *)FALSE; |
---|
| 820 | } else if (!strncmp(info, "ADDER ", 6)) { |
---|
| 821 | info += 6; |
---|
| 822 | g_free(sd->adder); |
---|
| 823 | sd->adder = g_strdup_printf("%s@skype.com", info); |
---|
| 824 | } else if (!strncmp(info, "TOPIC ", 6)) { |
---|
| 825 | info += 6; |
---|
| 826 | gc = skype_chat_by_name(ic, id); |
---|
| 827 | if (gc && (sd->adder || sd->topic_wait)) { |
---|
| 828 | if (sd->topic_wait) { |
---|
| 829 | sd->adder = g_strdup(sd->username); |
---|
| 830 | sd->topic_wait = 0; |
---|
[c35bf7a] | 831 | } |
---|
[6b9d22a] | 832 | imcb_chat_topic(gc, sd->adder, info, 0); |
---|
| 833 | g_free(sd->adder); |
---|
| 834 | sd->adder = NULL; |
---|
| 835 | } |
---|
| 836 | } else if (!strncmp(info, "ACTIVEMEMBERS ", 14)) { |
---|
| 837 | info += 14; |
---|
| 838 | gc = skype_chat_by_name(ic, id); |
---|
| 839 | /* Hack! We set ->data to TRUE |
---|
| 840 | * while we're on the channel |
---|
| 841 | * so that we won't rejoin |
---|
| 842 | * after a /part. */ |
---|
[62f51ee9] | 843 | if (!gc || gc->data) |
---|
| 844 | return; |
---|
| 845 | char **members = g_strsplit(info, " ", 0); |
---|
| 846 | int i; |
---|
| 847 | for (i = 0; members[i]; i++) { |
---|
| 848 | if (!strcmp(members[i], sd->username)) |
---|
| 849 | continue; |
---|
[5d9db76] | 850 | g_snprintf(buf, IRC_LINE_SIZE, "%s@skype.com", |
---|
| 851 | members[i]); |
---|
[62f51ee9] | 852 | if (!g_list_find_custom(gc->in_room, buf, |
---|
| 853 | (GCompareFunc)strcmp)) |
---|
| 854 | imcb_chat_add_buddy(gc, buf); |
---|
[c35bf7a] | 855 | } |
---|
[62f51ee9] | 856 | imcb_chat_add_buddy(gc, sd->username); |
---|
| 857 | g_strfreev(members); |
---|
[c35bf7a] | 858 | } |
---|
| 859 | } |
---|
| 860 | |
---|
[2709f4c] | 861 | static void skype_parse_password(struct im_connection *ic, char *line) |
---|
| 862 | { |
---|
| 863 | if (!strncmp(line+9, "OK", 2)) |
---|
| 864 | imcb_connected(ic); |
---|
| 865 | else { |
---|
| 866 | imcb_error(ic, "Authentication Failed"); |
---|
| 867 | imc_logout(ic, TRUE); |
---|
| 868 | } |
---|
| 869 | } |
---|
| 870 | |
---|
[607f5e3] | 871 | static void skype_parse_profile(struct im_connection *ic, char *line) |
---|
| 872 | { |
---|
| 873 | imcb_log(ic, "SkypeOut balance value is '%s'.", line+21); |
---|
| 874 | } |
---|
| 875 | |
---|
| 876 | static void skype_parse_ping(struct im_connection *ic, char *line) |
---|
| 877 | { |
---|
[4ae3ffc] | 878 | /* Unused parameter */ |
---|
| 879 | line = line; |
---|
[1f4fc80] | 880 | skype_printf(ic, "PONG\n"); |
---|
[607f5e3] | 881 | } |
---|
| 882 | |
---|
| 883 | static void skype_parse_chats(struct im_connection *ic, char *line) |
---|
| 884 | { |
---|
| 885 | char **i; |
---|
| 886 | char **chats = g_strsplit(line + 6, ", ", 0); |
---|
| 887 | |
---|
| 888 | i = chats; |
---|
| 889 | while (*i) { |
---|
[1f4fc80] | 890 | skype_printf(ic, "GET CHAT %s STATUS\n", *i); |
---|
| 891 | skype_printf(ic, "GET CHAT %s ACTIVEMEMBERS\n", *i); |
---|
[607f5e3] | 892 | i++; |
---|
| 893 | } |
---|
| 894 | g_strfreev(chats); |
---|
| 895 | } |
---|
| 896 | |
---|
[ff436ba] | 897 | typedef void (*skype_parser)(struct im_connection *ic, char *line); |
---|
| 898 | |
---|
[8c09bb3] | 899 | static gboolean skype_read_callback(gpointer data, gint fd, |
---|
| 900 | b_input_condition cond) |
---|
[1323e36] | 901 | { |
---|
| 902 | struct im_connection *ic = data; |
---|
| 903 | struct skype_data *sd = ic->proto_data; |
---|
[c213d6b] | 904 | char buf[IRC_LINE_SIZE]; |
---|
[ff436ba] | 905 | int st, i; |
---|
[6e14204] | 906 | char **lines, **lineptr, *line; |
---|
[ff436ba] | 907 | static struct parse_map { |
---|
| 908 | char *k; |
---|
| 909 | skype_parser v; |
---|
| 910 | } parsers[] = { |
---|
| 911 | { "USERS ", skype_parse_users }, |
---|
| 912 | { "USER ", skype_parse_user }, |
---|
| 913 | { "CHATMESSAGE ", skype_parse_chatmessage }, |
---|
| 914 | { "CALL ", skype_parse_call }, |
---|
| 915 | { "FILETRANSFER ", skype_parse_filetransfer }, |
---|
| 916 | { "CHAT ", skype_parse_chat }, |
---|
| 917 | { "PASSWORD ", skype_parse_password }, |
---|
| 918 | { "PROFILE PSTN_BALANCE ", skype_parse_profile }, |
---|
| 919 | { "PING", skype_parse_ping }, |
---|
| 920 | { "CHATS ", skype_parse_chats }, |
---|
| 921 | }; |
---|
[1323e36] | 922 | |
---|
[4ae3ffc] | 923 | /* Unused parameters */ |
---|
| 924 | fd = fd; |
---|
| 925 | cond = cond; |
---|
| 926 | |
---|
[5adcc65] | 927 | if (!sd || sd->fd == -1) |
---|
[1323e36] | 928 | return FALSE; |
---|
[7daec06] | 929 | /* Read the whole data. */ |
---|
[5adcc65] | 930 | st = ssl_read(sd->ssl, buf, sizeof(buf)); |
---|
| 931 | if (st > 0) { |
---|
[1323e36] | 932 | buf[st] = '\0'; |
---|
[7daec06] | 933 | /* Then split it up to lines. */ |
---|
[9fd4241] | 934 | lines = g_strsplit(buf, "\n", 0); |
---|
| 935 | lineptr = lines; |
---|
[5adcc65] | 936 | while ((line = *lineptr)) { |
---|
| 937 | if (!strlen(line)) |
---|
[9fd4241] | 938 | break; |
---|
[b820226] | 939 | if (set_getbool(&ic->acc->set, "skypeconsole_receive")) |
---|
| 940 | imcb_buddy_msg(ic, "skypeconsole", line, 0, 0); |
---|
[6b9d22a] | 941 | for (i = 0; i < ARRAY_SIZE(parsers); i++) |
---|
| 942 | if (!strncmp(line, parsers[i].k, |
---|
| 943 | strlen(parsers[i].k))) { |
---|
[ff436ba] | 944 | parsers[i].v(ic, line); |
---|
| 945 | break; |
---|
| 946 | } |
---|
[9fd4241] | 947 | lineptr++; |
---|
| 948 | } |
---|
| 949 | g_strfreev(lines); |
---|
[5adcc65] | 950 | } else if (st == 0 || (st < 0 && !sockerr_again())) { |
---|
| 951 | closesocket(sd->fd); |
---|
[1323e36] | 952 | sd->fd = -1; |
---|
| 953 | |
---|
[5adcc65] | 954 | imcb_error(ic, "Error while reading from server"); |
---|
| 955 | imc_logout(ic, TRUE); |
---|
[1323e36] | 956 | return FALSE; |
---|
| 957 | } |
---|
| 958 | return TRUE; |
---|
| 959 | } |
---|
| 960 | |
---|
[5adcc65] | 961 | gboolean skype_start_stream(struct im_connection *ic) |
---|
[f06e3ac] | 962 | { |
---|
[1323e36] | 963 | struct skype_data *sd = ic->proto_data; |
---|
[f06e3ac] | 964 | int st; |
---|
| 965 | |
---|
[5adcc65] | 966 | if (!sd) |
---|
[1fb89e3] | 967 | return FALSE; |
---|
| 968 | |
---|
[5adcc65] | 969 | if (sd->bfd <= 0) |
---|
[7670b02] | 970 | sd->bfd = b_input_add(sd->fd, B_EV_IO_READ, |
---|
[8c09bb3] | 971 | skype_read_callback, ic); |
---|
[1323e36] | 972 | |
---|
[a0b206b] | 973 | /* Log in */ |
---|
[1f4fc80] | 974 | skype_printf(ic, "USERNAME %s\n", ic->acc->user); |
---|
| 975 | skype_printf(ic, "PASSWORD %s\n", ic->acc->pass); |
---|
[a0b206b] | 976 | |
---|
[7daec06] | 977 | /* This will download all buddies. */ |
---|
[1f4fc80] | 978 | st = skype_printf(ic, "SEARCH FRIENDS\n"); |
---|
| 979 | skype_printf(ic, "SET USERSTATUS ONLINE\n"); |
---|
[5acf9ab] | 980 | |
---|
| 981 | /* Auto join to bookmarked chats if requested.*/ |
---|
[1f4fc80] | 982 | if (set_getbool(&ic->acc->set, "auto_join")) |
---|
| 983 | skype_printf(ic, "SEARCH BOOKMARKEDCHATS\n"); |
---|
[f06e3ac] | 984 | return st; |
---|
| 985 | } |
---|
| 986 | |
---|
[5adcc65] | 987 | gboolean skype_connected(gpointer data, void *source, b_input_condition cond) |
---|
[f06e3ac] | 988 | { |
---|
| 989 | struct im_connection *ic = data; |
---|
[c7304b2] | 990 | struct skype_data *sd = ic->proto_data; |
---|
[4ae3ffc] | 991 | |
---|
| 992 | /* Unused parameter */ |
---|
| 993 | cond = cond; |
---|
| 994 | |
---|
[5adcc65] | 995 | if (!source) { |
---|
[c7304b2] | 996 | sd->ssl = NULL; |
---|
[5adcc65] | 997 | imcb_error(ic, "Could not connect to server"); |
---|
| 998 | imc_logout(ic, TRUE); |
---|
[c7304b2] | 999 | return FALSE; |
---|
| 1000 | } |
---|
[5adcc65] | 1001 | imcb_log(ic, "Connected to server, logging in"); |
---|
[4ae3ffc] | 1002 | |
---|
[f06e3ac] | 1003 | return skype_start_stream(ic); |
---|
| 1004 | } |
---|
| 1005 | |
---|
[5adcc65] | 1006 | static void skype_login(account_t *acc) |
---|
[f06e3ac] | 1007 | { |
---|
[5adcc65] | 1008 | struct im_connection *ic = imcb_new(acc); |
---|
| 1009 | struct skype_data *sd = g_new0(struct skype_data, 1); |
---|
[f06e3ac] | 1010 | |
---|
| 1011 | ic->proto_data = sd; |
---|
| 1012 | |
---|
[5adcc65] | 1013 | imcb_log(ic, "Connecting"); |
---|
[8c09bb3] | 1014 | sd->ssl = ssl_connect(set_getstr(&acc->set, "server"), |
---|
| 1015 | set_getint(&acc->set, "port"), skype_connected, ic); |
---|
[5adcc65] | 1016 | sd->fd = sd->ssl ? ssl_getfd(sd->ssl) : -1; |
---|
| 1017 | sd->username = g_strdup(acc->user); |
---|
[f06e3ac] | 1018 | |
---|
| 1019 | sd->ic = ic; |
---|
[08a355b] | 1020 | |
---|
| 1021 | if (set_getbool(&acc->set, "skypeconsole")) |
---|
| 1022 | imcb_add_buddy(ic, "skypeconsole", NULL); |
---|
[f06e3ac] | 1023 | } |
---|
| 1024 | |
---|
[5adcc65] | 1025 | static void skype_logout(struct im_connection *ic) |
---|
[f06e3ac] | 1026 | { |
---|
| 1027 | struct skype_data *sd = ic->proto_data; |
---|
[98bca36] | 1028 | |
---|
[1f4fc80] | 1029 | skype_printf(ic, "SET USERSTATUS OFFLINE\n"); |
---|
[98bca36] | 1030 | |
---|
[a3d6427] | 1031 | g_free(sd->username); |
---|
[7613670] | 1032 | g_free(sd->handle); |
---|
[f06e3ac] | 1033 | g_free(sd); |
---|
[98bca36] | 1034 | ic->proto_data = NULL; |
---|
[f06e3ac] | 1035 | } |
---|
| 1036 | |
---|
[8c09bb3] | 1037 | static int skype_buddy_msg(struct im_connection *ic, char *who, char *message, |
---|
| 1038 | int flags) |
---|
[93ece66] | 1039 | { |
---|
[1f4fc80] | 1040 | char *ptr, *nick; |
---|
[93ece66] | 1041 | int st; |
---|
| 1042 | |
---|
[4ae3ffc] | 1043 | /* Unused parameter */ |
---|
| 1044 | flags = flags; |
---|
| 1045 | |
---|
[cbec0d6] | 1046 | nick = g_strdup(who); |
---|
[77c1abe] | 1047 | ptr = strchr(nick, '@'); |
---|
[5adcc65] | 1048 | if (ptr) |
---|
[0bb1b7f] | 1049 | *ptr = '\0'; |
---|
[93ece66] | 1050 | |
---|
[08a355b] | 1051 | if (!strncmp(who, "skypeconsole", 12)) |
---|
[1f4fc80] | 1052 | st = skype_printf(ic, "%s\n", message); |
---|
[08a355b] | 1053 | else |
---|
[1f4fc80] | 1054 | st = skype_printf(ic, "MESSAGE %s %s\n", nick, message); |
---|
[77c1abe] | 1055 | g_free(nick); |
---|
[93ece66] | 1056 | |
---|
| 1057 | return st; |
---|
| 1058 | } |
---|
| 1059 | |
---|
[5adcc65] | 1060 | const struct skype_away_state *skype_away_state_by_name(char *name) |
---|
[23411c6] | 1061 | { |
---|
| 1062 | int i; |
---|
| 1063 | |
---|
[5adcc65] | 1064 | for (i = 0; skype_away_state_list[i].full_name; i++) |
---|
| 1065 | if (g_strcasecmp(skype_away_state_list[i].full_name, name) == 0) |
---|
| 1066 | return skype_away_state_list + i; |
---|
[23411c6] | 1067 | |
---|
| 1068 | return NULL; |
---|
| 1069 | } |
---|
| 1070 | |
---|
[8c09bb3] | 1071 | static void skype_set_away(struct im_connection *ic, char *state_txt, |
---|
| 1072 | char *message) |
---|
[f06e3ac] | 1073 | { |
---|
[23411c6] | 1074 | const struct skype_away_state *state; |
---|
| 1075 | |
---|
[4ae3ffc] | 1076 | /* Unused parameter */ |
---|
| 1077 | message = message; |
---|
| 1078 | |
---|
[4b740c2] | 1079 | if (state_txt == NULL) |
---|
| 1080 | state = skype_away_state_by_name("Online"); |
---|
[23411c6] | 1081 | else |
---|
[5adcc65] | 1082 | state = skype_away_state_by_name(state_txt); |
---|
[1f4fc80] | 1083 | skype_printf(ic, "SET USERSTATUS %s\n", state->code); |
---|
[f06e3ac] | 1084 | } |
---|
| 1085 | |
---|
[5adcc65] | 1086 | static GList *skype_away_states(struct im_connection *ic) |
---|
[f06e3ac] | 1087 | { |
---|
[5adcc65] | 1088 | static GList *l; |
---|
[adce2de] | 1089 | int i; |
---|
[5adcc65] | 1090 | |
---|
[4ae3ffc] | 1091 | /* Unused parameter */ |
---|
| 1092 | ic = ic; |
---|
| 1093 | |
---|
[5adcc65] | 1094 | if (l == NULL) |
---|
| 1095 | for (i = 0; skype_away_state_list[i].full_name; i++) |
---|
[8c09bb3] | 1096 | l = g_list_append(l, |
---|
| 1097 | (void *)skype_away_state_list[i].full_name); |
---|
[5adcc65] | 1098 | |
---|
[f06e3ac] | 1099 | return l; |
---|
| 1100 | } |
---|
| 1101 | |
---|
[5adcc65] | 1102 | static char *skype_set_display_name(set_t *set, char *value) |
---|
[93dffea] | 1103 | { |
---|
| 1104 | account_t *acc = set->data; |
---|
| 1105 | struct im_connection *ic = acc->ic; |
---|
| 1106 | |
---|
[1f4fc80] | 1107 | skype_printf(ic, "SET PROFILE FULLNAME %s", value); |
---|
[5adcc65] | 1108 | return value; |
---|
[93dffea] | 1109 | } |
---|
| 1110 | |
---|
[5adcc65] | 1111 | static char *skype_set_balance(set_t *set, char *value) |
---|
[2af671a] | 1112 | { |
---|
| 1113 | account_t *acc = set->data; |
---|
| 1114 | struct im_connection *ic = acc->ic; |
---|
| 1115 | |
---|
[1f4fc80] | 1116 | skype_printf(ic, "GET PROFILE PSTN_BALANCE"); |
---|
[5adcc65] | 1117 | return value; |
---|
[2af671a] | 1118 | } |
---|
| 1119 | |
---|
[5adcc65] | 1120 | static char *skype_set_call(set_t *set, char *value) |
---|
[b68b023] | 1121 | { |
---|
| 1122 | account_t *acc = set->data; |
---|
| 1123 | struct im_connection *ic = acc->ic; |
---|
[2eb4b1f] | 1124 | struct skype_data *sd = ic->proto_data; |
---|
[1f4fc80] | 1125 | char *nick, *ptr; |
---|
[b68b023] | 1126 | |
---|
[5adcc65] | 1127 | if (value) { |
---|
[78d22cd0] | 1128 | #if BITLBEE_VERSION_CODE < BITLBEE_VER(1, 3, 0) |
---|
| 1129 | /* IRC stuff shouldn't be touched from inside IM modules. */ |
---|
[2eb4b1f] | 1130 | user_t *u = user_find(acc->irc, value); |
---|
| 1131 | /* We are starting a call */ |
---|
[78d22cd0] | 1132 | if (u) |
---|
[a317ba6] | 1133 | nick = g_strdup(u->handle); |
---|
[78d22cd0] | 1134 | else |
---|
| 1135 | #endif |
---|
| 1136 | nick = g_strdup(value); |
---|
[2eb4b1f] | 1137 | ptr = strchr(nick, '@'); |
---|
[5adcc65] | 1138 | if (ptr) |
---|
[2eb4b1f] | 1139 | *ptr = '\0'; |
---|
| 1140 | |
---|
[1f4fc80] | 1141 | skype_printf(ic, "CALL %s", nick); |
---|
[2eb4b1f] | 1142 | g_free(nick); |
---|
[5adcc65] | 1143 | } else { |
---|
[2eb4b1f] | 1144 | /* We are ending a call */ |
---|
[5adcc65] | 1145 | if (sd->call_id) { |
---|
[1f4fc80] | 1146 | skype_printf(ic, "SET CALL %s STATUS FINISHED", |
---|
[8c09bb3] | 1147 | sd->call_id); |
---|
[9fd7202] | 1148 | g_free(sd->call_id); |
---|
| 1149 | sd->call_id = NULL; |
---|
[5adcc65] | 1150 | } else |
---|
[2eb4b1f] | 1151 | imcb_error(ic, "There are no active calls currently."); |
---|
[b68b023] | 1152 | } |
---|
[5adcc65] | 1153 | return value; |
---|
[b68b023] | 1154 | } |
---|
| 1155 | |
---|
[5adcc65] | 1156 | static void skype_add_buddy(struct im_connection *ic, char *who, char *group) |
---|
[f06e3ac] | 1157 | { |
---|
[1f4fc80] | 1158 | char *nick, *ptr; |
---|
[6627d92] | 1159 | |
---|
[4ae3ffc] | 1160 | /* Unused parameter */ |
---|
| 1161 | group = group; |
---|
| 1162 | |
---|
[cbec0d6] | 1163 | nick = g_strdup(who); |
---|
[6627d92] | 1164 | ptr = strchr(nick, '@'); |
---|
[5adcc65] | 1165 | if (ptr) |
---|
[6627d92] | 1166 | *ptr = '\0'; |
---|
[1f4fc80] | 1167 | skype_printf(ic, "SET USER %s BUDDYSTATUS 2 Please authorize me\n", |
---|
[8c09bb3] | 1168 | nick); |
---|
[6627d92] | 1169 | g_free(nick); |
---|
[f06e3ac] | 1170 | } |
---|
| 1171 | |
---|
[5adcc65] | 1172 | static void skype_remove_buddy(struct im_connection *ic, char *who, char *group) |
---|
[f06e3ac] | 1173 | { |
---|
[1f4fc80] | 1174 | char *nick, *ptr; |
---|
[6627d92] | 1175 | |
---|
[4ae3ffc] | 1176 | /* Unused parameter */ |
---|
| 1177 | group = group; |
---|
| 1178 | |
---|
[cbec0d6] | 1179 | nick = g_strdup(who); |
---|
[6627d92] | 1180 | ptr = strchr(nick, '@'); |
---|
[5adcc65] | 1181 | if (ptr) |
---|
[6627d92] | 1182 | *ptr = '\0'; |
---|
[1f4fc80] | 1183 | skype_printf(ic, "SET USER %s BUDDYSTATUS 1\n", nick); |
---|
[6627d92] | 1184 | g_free(nick); |
---|
[f06e3ac] | 1185 | } |
---|
| 1186 | |
---|
[5adcc65] | 1187 | void skype_chat_msg(struct groupchat *gc, char *message, int flags) |
---|
[66c9558] | 1188 | { |
---|
[79e20f9] | 1189 | struct im_connection *ic = gc->ic; |
---|
[4ae3ffc] | 1190 | |
---|
| 1191 | /* Unused parameter */ |
---|
| 1192 | flags = flags; |
---|
| 1193 | |
---|
[1f4fc80] | 1194 | skype_printf(ic, "CHATMESSAGE %s %s\n", gc->title, message); |
---|
[66c9558] | 1195 | } |
---|
| 1196 | |
---|
[5adcc65] | 1197 | void skype_chat_leave(struct groupchat *gc) |
---|
[b01dc6c] | 1198 | { |
---|
| 1199 | struct im_connection *ic = gc->ic; |
---|
[1f4fc80] | 1200 | skype_printf(ic, "ALTER CHAT %s LEAVE\n", gc->title); |
---|
[5adcc65] | 1201 | gc->data = (void *)TRUE; |
---|
[760319d] | 1202 | } |
---|
| 1203 | |
---|
| 1204 | void skype_chat_invite(struct groupchat *gc, char *who, char *message) |
---|
| 1205 | { |
---|
| 1206 | struct im_connection *ic = gc->ic; |
---|
[1f4fc80] | 1207 | char *ptr, *nick; |
---|
[4ae3ffc] | 1208 | |
---|
| 1209 | /* Unused parameter */ |
---|
| 1210 | who = who; |
---|
| 1211 | |
---|
[760319d] | 1212 | nick = g_strdup(message); |
---|
| 1213 | ptr = strchr(nick, '@'); |
---|
[5adcc65] | 1214 | if (ptr) |
---|
[760319d] | 1215 | *ptr = '\0'; |
---|
[1f4fc80] | 1216 | skype_printf(ic, "ALTER CHAT %s ADDMEMBERS %s\n", gc->title, nick); |
---|
[760319d] | 1217 | g_free(nick); |
---|
[b01dc6c] | 1218 | } |
---|
| 1219 | |
---|
[09e2a69] | 1220 | void skype_chat_topic(struct groupchat *gc, char *message) |
---|
| 1221 | { |
---|
| 1222 | struct im_connection *ic = gc->ic; |
---|
[a5f76a2] | 1223 | struct skype_data *sd = ic->proto_data; |
---|
[1f4fc80] | 1224 | skype_printf(ic, "ALTER CHAT %s SETTOPIC %s\n", |
---|
[8c09bb3] | 1225 | gc->title, message); |
---|
[a5f76a2] | 1226 | sd->topic_wait = 1; |
---|
[09e2a69] | 1227 | } |
---|
| 1228 | |
---|
[86278cd] | 1229 | struct groupchat *skype_chat_with(struct im_connection *ic, char *who) |
---|
| 1230 | { |
---|
| 1231 | struct skype_data *sd = ic->proto_data; |
---|
[1f4fc80] | 1232 | char *ptr, *nick; |
---|
[86278cd] | 1233 | nick = g_strdup(who); |
---|
| 1234 | ptr = strchr(nick, '@'); |
---|
[5adcc65] | 1235 | if (ptr) |
---|
[86278cd] | 1236 | *ptr = '\0'; |
---|
[1f4fc80] | 1237 | skype_printf(ic, "CHAT CREATE %s\n", nick); |
---|
[86278cd] | 1238 | sd->groupchat_with = g_strdup(nick); |
---|
| 1239 | g_free(nick); |
---|
[5652d43] | 1240 | /* We create a fake chat for now. We will replace it with a real one in |
---|
| 1241 | * the real callback. */ |
---|
[5adcc65] | 1242 | return imcb_chat_new(ic, ""); |
---|
[86278cd] | 1243 | } |
---|
| 1244 | |
---|
[67454bd] | 1245 | static void skype_get_info(struct im_connection *ic, char *who) |
---|
| 1246 | { |
---|
[1f4fc80] | 1247 | char *ptr, *nick; |
---|
[67454bd] | 1248 | nick = g_strdup(who); |
---|
| 1249 | ptr = strchr(nick, '@'); |
---|
[5adcc65] | 1250 | if (ptr) |
---|
[67454bd] | 1251 | *ptr = '\0'; |
---|
[1f4fc80] | 1252 | skype_printf(ic, "GET USER %s FULLNAME\n", nick); |
---|
| 1253 | skype_printf(ic, "GET USER %s PHONE_HOME\n", nick); |
---|
| 1254 | skype_printf(ic, "GET USER %s PHONE_OFFICE\n", nick); |
---|
| 1255 | skype_printf(ic, "GET USER %s PHONE_MOBILE\n", nick); |
---|
| 1256 | skype_printf(ic, "GET USER %s NROF_AUTHED_BUDDIES\n", nick); |
---|
| 1257 | skype_printf(ic, "GET USER %s TIMEZONE\n", nick); |
---|
| 1258 | skype_printf(ic, "GET USER %s LASTONLINETIMESTAMP\n", nick); |
---|
| 1259 | skype_printf(ic, "GET USER %s BIRTHDAY\n", nick); |
---|
| 1260 | skype_printf(ic, "GET USER %s SEX\n", nick); |
---|
| 1261 | skype_printf(ic, "GET USER %s LANGUAGE\n", nick); |
---|
| 1262 | skype_printf(ic, "GET USER %s COUNTRY\n", nick); |
---|
| 1263 | skype_printf(ic, "GET USER %s PROVINCE\n", nick); |
---|
| 1264 | skype_printf(ic, "GET USER %s CITY\n", nick); |
---|
| 1265 | skype_printf(ic, "GET USER %s HOMEPAGE\n", nick); |
---|
| 1266 | skype_printf(ic, "GET USER %s ABOUT\n", nick); |
---|
[67454bd] | 1267 | } |
---|
| 1268 | |
---|
[5adcc65] | 1269 | static void skype_set_my_name(struct im_connection *ic, char *info) |
---|
[93dffea] | 1270 | { |
---|
[5adcc65] | 1271 | skype_set_display_name(set_find(&ic->acc->set, "display_name"), info); |
---|
[93dffea] | 1272 | } |
---|
| 1273 | |
---|
[5adcc65] | 1274 | static void skype_init(account_t *acc) |
---|
[93dffea] | 1275 | { |
---|
| 1276 | set_t *s; |
---|
| 1277 | |
---|
[8c09bb3] | 1278 | s = set_add(&acc->set, "server", SKYPE_DEFAULT_SERVER, set_eval_account, |
---|
| 1279 | acc); |
---|
[93dffea] | 1280 | s->flags |= ACC_SET_OFFLINE_ONLY; |
---|
| 1281 | |
---|
[5adcc65] | 1282 | s = set_add(&acc->set, "port", SKYPE_DEFAULT_PORT, set_eval_int, acc); |
---|
[93dffea] | 1283 | s->flags |= ACC_SET_OFFLINE_ONLY; |
---|
| 1284 | |
---|
[8c09bb3] | 1285 | s = set_add(&acc->set, "display_name", NULL, skype_set_display_name, |
---|
| 1286 | acc); |
---|
[93dffea] | 1287 | s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY; |
---|
[b68b023] | 1288 | |
---|
[5adcc65] | 1289 | s = set_add(&acc->set, "call", NULL, skype_set_call, acc); |
---|
[b68b023] | 1290 | s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY; |
---|
[2af671a] | 1291 | |
---|
[5adcc65] | 1292 | s = set_add(&acc->set, "balance", NULL, skype_set_balance, acc); |
---|
[2af671a] | 1293 | s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY; |
---|
[bd417a1] | 1294 | |
---|
[5adcc65] | 1295 | s = set_add(&acc->set, "skypeout_offline", "true", set_eval_bool, acc); |
---|
[08a355b] | 1296 | |
---|
[5adcc65] | 1297 | s = set_add(&acc->set, "skypeconsole", "false", set_eval_bool, acc); |
---|
[08a355b] | 1298 | s->flags |= ACC_SET_OFFLINE_ONLY; |
---|
[5acf9ab] | 1299 | |
---|
[8c09bb3] | 1300 | s = set_add(&acc->set, "skypeconsole_receive", "false", set_eval_bool, |
---|
| 1301 | acc); |
---|
[b820226] | 1302 | s->flags |= ACC_SET_OFFLINE_ONLY; |
---|
| 1303 | |
---|
[5adcc65] | 1304 | s = set_add(&acc->set, "auto_join", "false", set_eval_bool, acc); |
---|
[5acf9ab] | 1305 | s->flags |= ACC_SET_OFFLINE_ONLY; |
---|
[f4d37c6] | 1306 | |
---|
[49a3c02] | 1307 | s = set_add(&acc->set, "test_join", "false", set_eval_bool, acc); |
---|
| 1308 | s->flags |= ACC_SET_OFFLINE_ONLY; |
---|
| 1309 | |
---|
[304aa33] | 1310 | s = set_add(&acc->set, "show_moods", "false", set_eval_bool, acc); |
---|
| 1311 | |
---|
[f4d37c6] | 1312 | s = set_add(&acc->set, "edit_prefix", "EDIT:", |
---|
[1e3120f] | 1313 | NULL, acc); |
---|
[93dffea] | 1314 | } |
---|
| 1315 | |
---|
[f06e3ac] | 1316 | void init_plugin(void) |
---|
| 1317 | { |
---|
[5adcc65] | 1318 | struct prpl *ret = g_new0(struct prpl, 1); |
---|
[f06e3ac] | 1319 | |
---|
| 1320 | ret->name = "skype"; |
---|
| 1321 | ret->login = skype_login; |
---|
| 1322 | ret->init = skype_init; |
---|
| 1323 | ret->logout = skype_logout; |
---|
[93ece66] | 1324 | ret->buddy_msg = skype_buddy_msg; |
---|
[67454bd] | 1325 | ret->get_info = skype_get_info; |
---|
[93dffea] | 1326 | ret->set_my_name = skype_set_my_name; |
---|
[f06e3ac] | 1327 | ret->away_states = skype_away_states; |
---|
[7daec06] | 1328 | ret->set_away = skype_set_away; |
---|
[f06e3ac] | 1329 | ret->add_buddy = skype_add_buddy; |
---|
| 1330 | ret->remove_buddy = skype_remove_buddy; |
---|
[66c9558] | 1331 | ret->chat_msg = skype_chat_msg; |
---|
[b01dc6c] | 1332 | ret->chat_leave = skype_chat_leave; |
---|
[760319d] | 1333 | ret->chat_invite = skype_chat_invite; |
---|
[86278cd] | 1334 | ret->chat_with = skype_chat_with; |
---|
[f06e3ac] | 1335 | ret->handle_cmp = g_strcasecmp; |
---|
[09e2a69] | 1336 | ret->chat_topic = skype_chat_topic; |
---|
[5adcc65] | 1337 | register_protocol(ret); |
---|
[f06e3ac] | 1338 | } |
---|