[7daec06] | 1 | /* |
---|
| 2 | * skype.c - Skype plugin for BitlBee |
---|
[5adcc65] | 3 | * |
---|
[9ec6b36] | 4 | * Copyright (c) 2007-2013 by Miklos Vajna <vmiklos@vmiklos.hu> |
---|
[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 |
---|
[6f10697] | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
---|
[7daec06] | 19 | * USA. |
---|
[f06e3ac] | 20 | */ |
---|
[7daec06] | 21 | |
---|
[f9c3e7b] | 22 | #define _XOPEN_SOURCE |
---|
[ed2e37f] | 23 | #include <poll.h> |
---|
[ff18fc1] | 24 | #include <stdio.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" |
---|
[61d2eabb] | 30 | #define IRC_LINE_SIZE 16384 |
---|
[5ebff60] | 31 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) |
---|
[f06e3ac] | 32 | |
---|
[bbba374] | 33 | /* |
---|
| 34 | * Enumerations |
---|
| 35 | */ |
---|
| 36 | |
---|
[359f4d9] | 37 | enum { |
---|
[df9255d] | 38 | SKYPE_CALL_RINGING = 1, |
---|
[9db0234] | 39 | SKYPE_CALL_MISSED, |
---|
[2eb4b1f] | 40 | SKYPE_CALL_CANCELLED, |
---|
[acd9478] | 41 | SKYPE_CALL_FINISHED, |
---|
[d87daf3] | 42 | SKYPE_CALL_REFUSED |
---|
[5365f84] | 43 | }; |
---|
[bbba374] | 44 | |
---|
[359f4d9] | 45 | enum { |
---|
[df9255d] | 46 | SKYPE_FILETRANSFER_NEW = 1, |
---|
[b2dc873] | 47 | SKYPE_FILETRANSFER_TRANSFERRING, |
---|
| 48 | SKYPE_FILETRANSFER_COMPLETED, |
---|
[df9255d] | 49 | SKYPE_FILETRANSFER_FAILED |
---|
[5365f84] | 50 | }; |
---|
[df9255d] | 51 | |
---|
[7daec06] | 52 | /* |
---|
| 53 | * Structures |
---|
| 54 | */ |
---|
| 55 | |
---|
[5adcc65] | 56 | struct skype_data { |
---|
[f06e3ac] | 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; |
---|
[c7304b2] | 65 | /* ssl_getfd() uses this to get the file desciptor. */ |
---|
| 66 | void *ssl; |
---|
[2a0f99c] | 67 | /* When we receive a new message id, we query the properties, finally |
---|
| 68 | * the chatname. Store the properties here so that we can use |
---|
[c81d0ef] | 69 | * imcb_buddy_msg() when we got the chatname. */ |
---|
[77c1abe] | 70 | char *handle; |
---|
[a7af5f0] | 71 | /* List, because of multiline messages. */ |
---|
| 72 | GList *body; |
---|
[2a0f99c] | 73 | char *type; |
---|
[bbba374] | 74 | /* This is necessary because we send a notification when we get the |
---|
| 75 | * handle. So we store the state here and then we can send a |
---|
| 76 | * notification about the handle is in a given status. */ |
---|
[359f4d9] | 77 | int call_status; |
---|
[2eb4b1f] | 78 | char *call_id; |
---|
[48181f0] | 79 | char *call_duration; |
---|
[d87daf3] | 80 | /* If the call is outgoing or not */ |
---|
| 81 | int call_out; |
---|
[df9255d] | 82 | /* Same for file transfers. */ |
---|
[359f4d9] | 83 | int filetransfer_status; |
---|
[b2dc873] | 84 | /* Path of the file being transferred. */ |
---|
| 85 | char *filetransfer_path; |
---|
[86278cd] | 86 | /* Using /j #nick we want to have a groupchat with two people. Usually |
---|
| 87 | * not (default). */ |
---|
[5adcc65] | 88 | char *groupchat_with; |
---|
[f8674db] | 89 | /* The user who invited us to the chat. */ |
---|
[5adcc65] | 90 | char *adder; |
---|
[a5f76a2] | 91 | /* If we are waiting for a confirmation about we changed the topic. */ |
---|
| 92 | int topic_wait; |
---|
[67454bd] | 93 | /* These are used by the info command. */ |
---|
| 94 | char *info_fullname; |
---|
| 95 | char *info_phonehome; |
---|
| 96 | char *info_phoneoffice; |
---|
| 97 | char *info_phonemobile; |
---|
| 98 | char *info_nrbuddies; |
---|
| 99 | char *info_tz; |
---|
| 100 | char *info_seen; |
---|
| 101 | char *info_birthday; |
---|
| 102 | char *info_sex; |
---|
| 103 | char *info_language; |
---|
| 104 | char *info_country; |
---|
| 105 | char *info_province; |
---|
| 106 | char *info_city; |
---|
| 107 | char *info_homepage; |
---|
| 108 | char *info_about; |
---|
[b054fad] | 109 | /* When a call fails, we get the reason and later we get the failure |
---|
| 110 | * event, so store the failure code here till then */ |
---|
| 111 | int failurereason; |
---|
[d9ce18c] | 112 | /* If this is just an update of an already received message. */ |
---|
| 113 | int is_edit; |
---|
[89d6845] | 114 | /* List of struct skype_group* */ |
---|
| 115 | GList *groups; |
---|
[46641bf] | 116 | /* Pending user which has to be added to the next group which is |
---|
| 117 | * created. */ |
---|
| 118 | char *pending_user; |
---|
[36f6ab3] | 119 | /* If the info command was used, to determine what to do with FULLNAME result. */ |
---|
| 120 | int is_info; |
---|
[f06e3ac] | 121 | }; |
---|
| 122 | |
---|
[5adcc65] | 123 | struct skype_away_state { |
---|
[adce2de] | 124 | char *code; |
---|
| 125 | char *full_name; |
---|
| 126 | }; |
---|
| 127 | |
---|
[5adcc65] | 128 | struct skype_buddy_ask_data { |
---|
[7daec06] | 129 | struct im_connection *ic; |
---|
[e0074cb] | 130 | /* This is also used for call IDs for simplicity */ |
---|
[7daec06] | 131 | char *handle; |
---|
| 132 | }; |
---|
| 133 | |
---|
[89d6845] | 134 | struct skype_group { |
---|
| 135 | int id; |
---|
| 136 | char *name; |
---|
| 137 | GList *users; |
---|
| 138 | }; |
---|
| 139 | |
---|
[7daec06] | 140 | /* |
---|
| 141 | * Tables |
---|
| 142 | */ |
---|
| 143 | |
---|
[5adcc65] | 144 | const struct skype_away_state skype_away_state_list[] = { |
---|
[bc744df] | 145 | { "AWAY", "Away" }, |
---|
| 146 | { "NA", "Not available" }, |
---|
| 147 | { "DND", "Do Not Disturb" }, |
---|
| 148 | { "INVISIBLE", "Invisible" }, |
---|
| 149 | { "OFFLINE", "Offline" }, |
---|
[4b740c2] | 150 | { "SKYPEME", "Skype Me" }, |
---|
| 151 | { "ONLINE", "Online" }, |
---|
[5ebff60] | 152 | { NULL, NULL } |
---|
[adce2de] | 153 | }; |
---|
| 154 | |
---|
[7daec06] | 155 | /* |
---|
| 156 | * Functions |
---|
| 157 | */ |
---|
[d3cbd17] | 158 | |
---|
[7c300bb] | 159 | int skype_write(struct im_connection *ic, char *buf, int len) |
---|
[f06e3ac] | 160 | { |
---|
| 161 | struct skype_data *sd = ic->proto_data; |
---|
[1fb89e3] | 162 | struct pollfd pfd[1]; |
---|
| 163 | |
---|
[5ebff60] | 164 | if (!sd->ssl) { |
---|
[e8e2892] | 165 | return FALSE; |
---|
[5ebff60] | 166 | } |
---|
[e8e2892] | 167 | |
---|
[1fb89e3] | 168 | pfd[0].fd = sd->fd; |
---|
| 169 | pfd[0].events = POLLOUT; |
---|
[f06e3ac] | 170 | |
---|
[7daec06] | 171 | /* This poll is necessary or we'll get a SIGPIPE when we write() to |
---|
| 172 | * sd->fd. */ |
---|
[1fb89e3] | 173 | poll(pfd, 1, 1000); |
---|
[5adcc65] | 174 | if (pfd[0].revents & POLLHUP) { |
---|
| 175 | imc_logout(ic, TRUE); |
---|
[1fb89e3] | 176 | return FALSE; |
---|
| 177 | } |
---|
[5adcc65] | 178 | ssl_write(sd->ssl, buf, len); |
---|
[f06e3ac] | 179 | |
---|
[9fd4241] | 180 | return TRUE; |
---|
[f06e3ac] | 181 | } |
---|
| 182 | |
---|
[1f4fc80] | 183 | int skype_printf(struct im_connection *ic, char *fmt, ...) |
---|
| 184 | { |
---|
| 185 | va_list args; |
---|
| 186 | char str[IRC_LINE_SIZE]; |
---|
[5d9db76] | 187 | |
---|
[1f4fc80] | 188 | va_start(args, fmt); |
---|
[6ea8782] | 189 | g_vsnprintf(str, IRC_LINE_SIZE, fmt, args); |
---|
[1f4fc80] | 190 | va_end(args); |
---|
| 191 | |
---|
[7c300bb] | 192 | return skype_write(ic, str, strlen(str)); |
---|
[1f4fc80] | 193 | } |
---|
| 194 | |
---|
[5adcc65] | 195 | static void skype_buddy_ask_yes(void *data) |
---|
[d3cbd17] | 196 | { |
---|
[039116a] | 197 | struct skype_buddy_ask_data *bla = data; |
---|
[5ebff60] | 198 | |
---|
[5a0ffa2] | 199 | skype_printf(bla->ic, "SET USER %s ISAUTHORIZED TRUE\n", |
---|
[5ebff60] | 200 | bla->handle); |
---|
[d3cbd17] | 201 | g_free(bla->handle); |
---|
| 202 | g_free(bla); |
---|
| 203 | } |
---|
| 204 | |
---|
[5adcc65] | 205 | static void skype_buddy_ask_no(void *data) |
---|
[d3cbd17] | 206 | { |
---|
[039116a] | 207 | struct skype_buddy_ask_data *bla = data; |
---|
[5ebff60] | 208 | |
---|
[5a0ffa2] | 209 | skype_printf(bla->ic, "SET USER %s ISAUTHORIZED FALSE\n", |
---|
[5ebff60] | 210 | bla->handle); |
---|
[d3cbd17] | 211 | g_free(bla->handle); |
---|
| 212 | g_free(bla); |
---|
| 213 | } |
---|
| 214 | |
---|
[5adcc65] | 215 | void skype_buddy_ask(struct im_connection *ic, char *handle, char *message) |
---|
[d3cbd17] | 216 | { |
---|
[8c09bb3] | 217 | struct skype_buddy_ask_data *bla = g_new0(struct skype_buddy_ask_data, |
---|
[5ebff60] | 218 | 1); |
---|
[d3cbd17] | 219 | char *buf; |
---|
| 220 | |
---|
| 221 | bla->ic = ic; |
---|
| 222 | bla->handle = g_strdup(handle); |
---|
| 223 | |
---|
[e1d6b38] | 224 | buf = g_strdup_printf("The user %s wants to add you to his/her buddy list, saying: '%s'.", handle, message); |
---|
[5adcc65] | 225 | imcb_ask(ic, buf, bla, skype_buddy_ask_yes, skype_buddy_ask_no); |
---|
| 226 | g_free(buf); |
---|
[d3cbd17] | 227 | } |
---|
| 228 | |
---|
[5adcc65] | 229 | static void skype_call_ask_yes(void *data) |
---|
[e0074cb] | 230 | { |
---|
[039116a] | 231 | struct skype_buddy_ask_data *bla = data; |
---|
[5ebff60] | 232 | |
---|
[5a0ffa2] | 233 | skype_printf(bla->ic, "SET CALL %s STATUS INPROGRESS\n", |
---|
[5ebff60] | 234 | bla->handle); |
---|
[e0074cb] | 235 | g_free(bla->handle); |
---|
| 236 | g_free(bla); |
---|
| 237 | } |
---|
| 238 | |
---|
[5adcc65] | 239 | static void skype_call_ask_no(void *data) |
---|
[e0074cb] | 240 | { |
---|
[039116a] | 241 | struct skype_buddy_ask_data *bla = data; |
---|
[5ebff60] | 242 | |
---|
[5a0ffa2] | 243 | skype_printf(bla->ic, "SET CALL %s STATUS FINISHED\n", |
---|
[5ebff60] | 244 | bla->handle); |
---|
[e0074cb] | 245 | g_free(bla->handle); |
---|
| 246 | g_free(bla); |
---|
| 247 | } |
---|
| 248 | |
---|
[5adcc65] | 249 | void skype_call_ask(struct im_connection *ic, char *call_id, char *message) |
---|
[e0074cb] | 250 | { |
---|
[8c09bb3] | 251 | struct skype_buddy_ask_data *bla = g_new0(struct skype_buddy_ask_data, |
---|
[5ebff60] | 252 | 1); |
---|
[e0074cb] | 253 | |
---|
| 254 | bla->ic = ic; |
---|
| 255 | bla->handle = g_strdup(call_id); |
---|
| 256 | |
---|
[5adcc65] | 257 | imcb_ask(ic, message, bla, skype_call_ask_yes, skype_call_ask_no); |
---|
[e0074cb] | 258 | } |
---|
[72aa7f0] | 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 | |
---|
[54ca269] | 292 | static char *skype_group_by_username(struct im_connection *ic, char *username) |
---|
| 293 | { |
---|
| 294 | struct skype_data *sd = ic->proto_data; |
---|
| 295 | int i, j; |
---|
| 296 | |
---|
| 297 | /* NEEDSWORK: we just search for the first group of the user, multiple |
---|
| 298 | * groups / user is not yet supported by BitlBee. */ |
---|
| 299 | |
---|
| 300 | for (i = 0; i < g_list_length(sd->groups); i++) { |
---|
| 301 | struct skype_group *sg = g_list_nth_data(sd->groups, i); |
---|
| 302 | for (j = 0; j < g_list_length(sg->users); j++) { |
---|
[5ebff60] | 303 | if (!strcmp(g_list_nth_data(sg->users, j), username)) { |
---|
[54ca269] | 304 | return sg->name; |
---|
[5ebff60] | 305 | } |
---|
[54ca269] | 306 | } |
---|
| 307 | } |
---|
| 308 | return NULL; |
---|
| 309 | } |
---|
| 310 | |
---|
[46e9822] | 311 | static struct skype_group *skype_group_by_name(struct im_connection *ic, char *name) |
---|
| 312 | { |
---|
| 313 | struct skype_data *sd = ic->proto_data; |
---|
| 314 | int i; |
---|
| 315 | |
---|
| 316 | for (i = 0; i < g_list_length(sd->groups); i++) { |
---|
| 317 | struct skype_group *sg = g_list_nth_data(sd->groups, i); |
---|
[5ebff60] | 318 | if (!strcmp(sg->name, name)) { |
---|
[46e9822] | 319 | return sg; |
---|
[5ebff60] | 320 | } |
---|
[46e9822] | 321 | } |
---|
| 322 | return NULL; |
---|
| 323 | } |
---|
| 324 | |
---|
[078b0b9] | 325 | static void skype_parse_users(struct im_connection *ic, char *line) |
---|
| 326 | { |
---|
[1f4fc80] | 327 | char **i, **nicks; |
---|
[078b0b9] | 328 | |
---|
| 329 | nicks = g_strsplit(line + 6, ", ", 0); |
---|
[36f6ab3] | 330 | for (i = nicks; *i; i++) { |
---|
[1f4fc80] | 331 | skype_printf(ic, "GET USER %s ONLINESTATUS\n", *i); |
---|
[36f6ab3] | 332 | skype_printf(ic, "GET USER %s FULLNAME\n", *i); |
---|
| 333 | } |
---|
[078b0b9] | 334 | g_strfreev(nicks); |
---|
| 335 | } |
---|
| 336 | |
---|
[6e14204] | 337 | static void skype_parse_user(struct im_connection *ic, char *line) |
---|
| 338 | { |
---|
| 339 | int flags = 0; |
---|
| 340 | char *ptr; |
---|
| 341 | struct skype_data *sd = ic->proto_data; |
---|
| 342 | char *user = strchr(line, ' '); |
---|
| 343 | char *status = strrchr(line, ' '); |
---|
| 344 | |
---|
| 345 | status++; |
---|
| 346 | ptr = strchr(++user, ' '); |
---|
[5ebff60] | 347 | if (!ptr) { |
---|
[6e14204] | 348 | return; |
---|
[5ebff60] | 349 | } |
---|
[6e14204] | 350 | *ptr = '\0'; |
---|
| 351 | ptr++; |
---|
[49a3c02] | 352 | if (!strncmp(ptr, "ONLINESTATUS ", 13)) { |
---|
[5ebff60] | 353 | if (!strlen(user) || !strcmp(user, sd->username)) { |
---|
[57b534b] | 354 | return; |
---|
[5ebff60] | 355 | } |
---|
[57b534b] | 356 | if (!set_getbool(&ic->acc->set, "test_join") |
---|
[5ebff60] | 357 | && !strcmp(user, "echo123")) { |
---|
[57b534b] | 358 | return; |
---|
[5ebff60] | 359 | } |
---|
[6e14204] | 360 | ptr = g_strdup_printf("%s@skype.com", user); |
---|
[54ca269] | 361 | imcb_add_buddy(ic, ptr, skype_group_by_username(ic, user)); |
---|
[62f51ee9] | 362 | if (strcmp(status, "OFFLINE") && (strcmp(status, "SKYPEOUT") || |
---|
[5ebff60] | 363 | !set_getbool(&ic->acc->set, "skypeout_offline"))) { |
---|
[6e14204] | 364 | flags |= OPT_LOGGED_IN; |
---|
[5ebff60] | 365 | } |
---|
| 366 | if (strcmp(status, "ONLINE") && strcmp(status, "SKYPEME")) { |
---|
[6e14204] | 367 | flags |= OPT_AWAY; |
---|
[5ebff60] | 368 | } |
---|
[6e14204] | 369 | imcb_buddy_status(ic, ptr, flags, NULL, NULL); |
---|
| 370 | g_free(ptr); |
---|
| 371 | } else if (!strncmp(ptr, "RECEIVEDAUTHREQUEST ", 20)) { |
---|
| 372 | char *message = ptr + 20; |
---|
[5ebff60] | 373 | if (strlen(message)) { |
---|
[6e14204] | 374 | skype_buddy_ask(ic, user, message); |
---|
[5ebff60] | 375 | } |
---|
[6e14204] | 376 | } else if (!strncmp(ptr, "BUDDYSTATUS ", 12)) { |
---|
| 377 | char *st = ptr + 12; |
---|
| 378 | if (!strcmp(st, "3")) { |
---|
| 379 | char *buf = g_strdup_printf("%s@skype.com", user); |
---|
[54ca269] | 380 | imcb_add_buddy(ic, buf, skype_group_by_username(ic, user)); |
---|
[6e14204] | 381 | g_free(buf); |
---|
| 382 | } |
---|
[78d22cd0] | 383 | } else if (!strncmp(ptr, "MOOD_TEXT ", 10)) { |
---|
[4c674bb] | 384 | char *buf = g_strdup_printf("%s@skype.com", user); |
---|
[78d22cd0] | 385 | bee_user_t *bu = bee_user_by_handle(ic->bee, ic, buf); |
---|
| 386 | g_free(buf); |
---|
| 387 | buf = ptr + 10; |
---|
[5ebff60] | 388 | if (bu) { |
---|
[78d22cd0] | 389 | imcb_buddy_status(ic, bu->handle, bu->flags, NULL, |
---|
[5ebff60] | 390 | *buf ? buf : NULL); |
---|
| 391 | } |
---|
| 392 | if (set_getbool(&ic->acc->set, "show_moods")) { |
---|
[78d22cd0] | 393 | imcb_log(ic, "User `%s' changed mood text to `%s'", user, buf); |
---|
[5ebff60] | 394 | } |
---|
[36f6ab3] | 395 | } else if (!strncmp(ptr, "FULLNAME ", 9)) { |
---|
| 396 | char *name = ptr + 9; |
---|
| 397 | if (sd->is_info) { |
---|
| 398 | sd->is_info = FALSE; |
---|
| 399 | sd->info_fullname = g_strdup(name); |
---|
| 400 | } else { |
---|
| 401 | char *buf = g_strdup_printf("%s@skype.com", user); |
---|
| 402 | imcb_rename_buddy(ic, buf, name); |
---|
| 403 | g_free(buf); |
---|
| 404 | } |
---|
[5ebff60] | 405 | } else if (!strncmp(ptr, "PHONE_HOME ", 11)) { |
---|
[d7938f9] | 406 | sd->info_phonehome = g_strdup(ptr + 11); |
---|
[5ebff60] | 407 | } else if (!strncmp(ptr, "PHONE_OFFICE ", 13)) { |
---|
[d7938f9] | 408 | sd->info_phoneoffice = g_strdup(ptr + 13); |
---|
[5ebff60] | 409 | } else if (!strncmp(ptr, "PHONE_MOBILE ", 13)) { |
---|
[d7938f9] | 410 | sd->info_phonemobile = g_strdup(ptr + 13); |
---|
[5ebff60] | 411 | } else if (!strncmp(ptr, "NROF_AUTHED_BUDDIES ", 20)) { |
---|
[d7938f9] | 412 | sd->info_nrbuddies = g_strdup(ptr + 20); |
---|
[5ebff60] | 413 | } else if (!strncmp(ptr, "TIMEZONE ", 9)) { |
---|
[d7938f9] | 414 | sd->info_tz = g_strdup(ptr + 9); |
---|
[5ebff60] | 415 | } else if (!strncmp(ptr, "LASTONLINETIMESTAMP ", 20)) { |
---|
[d7938f9] | 416 | sd->info_seen = g_strdup(ptr + 20); |
---|
[5ebff60] | 417 | } else if (!strncmp(ptr, "SEX ", 4)) { |
---|
[d7938f9] | 418 | sd->info_sex = g_strdup(ptr + 4); |
---|
[5ebff60] | 419 | } else if (!strncmp(ptr, "LANGUAGE ", 9)) { |
---|
[d7938f9] | 420 | sd->info_language = g_strdup(ptr + 9); |
---|
[5ebff60] | 421 | } else if (!strncmp(ptr, "COUNTRY ", 8)) { |
---|
[d7938f9] | 422 | sd->info_country = g_strdup(ptr + 8); |
---|
[5ebff60] | 423 | } else if (!strncmp(ptr, "PROVINCE ", 9)) { |
---|
[d7938f9] | 424 | sd->info_province = g_strdup(ptr + 9); |
---|
[5ebff60] | 425 | } else if (!strncmp(ptr, "CITY ", 5)) { |
---|
[d7938f9] | 426 | sd->info_city = g_strdup(ptr + 5); |
---|
[5ebff60] | 427 | } else if (!strncmp(ptr, "HOMEPAGE ", 9)) { |
---|
[d7938f9] | 428 | sd->info_homepage = g_strdup(ptr + 9); |
---|
[5ebff60] | 429 | } else if (!strncmp(ptr, "ABOUT ", 6)) { |
---|
[85341dd] | 430 | /* Support multiple about lines. */ |
---|
[5ebff60] | 431 | if (!sd->info_about) { |
---|
[85341dd] | 432 | sd->info_about = g_strdup(ptr + 6); |
---|
[5ebff60] | 433 | } else { |
---|
[85341dd] | 434 | GString *st = g_string_new(sd->info_about); |
---|
| 435 | g_string_append_printf(st, "\n%s", ptr + 6); |
---|
| 436 | g_free(sd->info_about); |
---|
| 437 | sd->info_about = g_strdup(st->str); |
---|
| 438 | g_string_free(st, TRUE); |
---|
| 439 | } |
---|
[e1d6b38] | 440 | } else if (!strncmp(ptr, "BIRTHDAY ", 9)) { |
---|
[85341dd] | 441 | sd->info_birthday = g_strdup(ptr + 9); |
---|
[6e14204] | 442 | |
---|
| 443 | GString *st = g_string_new("Contact Information\n"); |
---|
| 444 | g_string_append_printf(st, "Skype Name: %s\n", user); |
---|
| 445 | if (sd->info_fullname) { |
---|
[5ebff60] | 446 | if (strlen(sd->info_fullname)) { |
---|
[62f51ee9] | 447 | g_string_append_printf(st, "Full Name: %s\n", |
---|
[5ebff60] | 448 | sd->info_fullname); |
---|
| 449 | } |
---|
[6e14204] | 450 | g_free(sd->info_fullname); |
---|
[7c2daf5f] | 451 | sd->info_fullname = NULL; |
---|
[6e14204] | 452 | } |
---|
| 453 | if (sd->info_phonehome) { |
---|
[5ebff60] | 454 | if (strlen(sd->info_phonehome)) { |
---|
[62f51ee9] | 455 | g_string_append_printf(st, "Home Phone: %s\n", |
---|
[5ebff60] | 456 | sd->info_phonehome); |
---|
| 457 | } |
---|
[6e14204] | 458 | g_free(sd->info_phonehome); |
---|
[7c2daf5f] | 459 | sd->info_phonehome = NULL; |
---|
[6e14204] | 460 | } |
---|
| 461 | if (sd->info_phoneoffice) { |
---|
[5ebff60] | 462 | if (strlen(sd->info_phoneoffice)) { |
---|
[62f51ee9] | 463 | g_string_append_printf(st, "Office Phone: %s\n", |
---|
[5ebff60] | 464 | sd->info_phoneoffice); |
---|
| 465 | } |
---|
[6e14204] | 466 | g_free(sd->info_phoneoffice); |
---|
[7c2daf5f] | 467 | sd->info_phoneoffice = NULL; |
---|
[6e14204] | 468 | } |
---|
| 469 | if (sd->info_phonemobile) { |
---|
[5ebff60] | 470 | if (strlen(sd->info_phonemobile)) { |
---|
[62f51ee9] | 471 | g_string_append_printf(st, "Mobile Phone: %s\n", |
---|
[5ebff60] | 472 | sd->info_phonemobile); |
---|
| 473 | } |
---|
[6e14204] | 474 | g_free(sd->info_phonemobile); |
---|
[7c2daf5f] | 475 | sd->info_phonemobile = NULL; |
---|
[6e14204] | 476 | } |
---|
| 477 | g_string_append_printf(st, "Personal Information\n"); |
---|
| 478 | if (sd->info_nrbuddies) { |
---|
[5ebff60] | 479 | if (strlen(sd->info_nrbuddies)) { |
---|
[62f51ee9] | 480 | g_string_append_printf(st, |
---|
[5ebff60] | 481 | "Contacts: %s\n", sd->info_nrbuddies); |
---|
| 482 | } |
---|
[6e14204] | 483 | g_free(sd->info_nrbuddies); |
---|
[7c2daf5f] | 484 | sd->info_nrbuddies = NULL; |
---|
[6e14204] | 485 | } |
---|
| 486 | if (sd->info_tz) { |
---|
| 487 | if (strlen(sd->info_tz)) { |
---|
| 488 | char ib[256]; |
---|
| 489 | time_t t = time(NULL); |
---|
[5ebff60] | 490 | t += atoi(sd->info_tz) - (60 * 60 * 24); |
---|
[6e14204] | 491 | struct tm *gt = gmtime(&t); |
---|
| 492 | strftime(ib, 256, "%H:%M:%S", gt); |
---|
[62f51ee9] | 493 | g_string_append_printf(st, |
---|
[5ebff60] | 494 | "Local Time: %s\n", ib); |
---|
[6e14204] | 495 | } |
---|
| 496 | g_free(sd->info_tz); |
---|
[7c2daf5f] | 497 | sd->info_tz = NULL; |
---|
[6e14204] | 498 | } |
---|
| 499 | if (sd->info_seen) { |
---|
| 500 | if (strlen(sd->info_seen)) { |
---|
| 501 | char ib[256]; |
---|
| 502 | time_t it = atoi(sd->info_seen); |
---|
| 503 | struct tm *tm = localtime(&it); |
---|
| 504 | strftime(ib, 256, ("%Y. %m. %d. %H:%M"), tm); |
---|
[62f51ee9] | 505 | g_string_append_printf(st, |
---|
[5ebff60] | 506 | "Last Seen: %s\n", ib); |
---|
[6e14204] | 507 | } |
---|
| 508 | g_free(sd->info_seen); |
---|
[7c2daf5f] | 509 | sd->info_seen = NULL; |
---|
[6e14204] | 510 | } |
---|
| 511 | if (sd->info_birthday) { |
---|
[62f51ee9] | 512 | if (strlen(sd->info_birthday) && |
---|
[5ebff60] | 513 | strcmp(sd->info_birthday, "0")) { |
---|
[6e14204] | 514 | char ib[256]; |
---|
| 515 | struct tm tm; |
---|
| 516 | strptime(sd->info_birthday, "%Y%m%d", &tm); |
---|
| 517 | strftime(ib, 256, "%B %d, %Y", &tm); |
---|
[62f51ee9] | 518 | g_string_append_printf(st, |
---|
[5ebff60] | 519 | "Birthday: %s\n", ib); |
---|
[6e14204] | 520 | |
---|
| 521 | strftime(ib, 256, "%Y", &tm); |
---|
| 522 | int year = atoi(ib); |
---|
| 523 | time_t t = time(NULL); |
---|
| 524 | struct tm *lt = localtime(&t); |
---|
[62f51ee9] | 525 | g_string_append_printf(st, |
---|
[5ebff60] | 526 | "Age: %d\n", lt->tm_year + 1900 - year); |
---|
[6e14204] | 527 | } |
---|
| 528 | g_free(sd->info_birthday); |
---|
[7c2daf5f] | 529 | sd->info_birthday = NULL; |
---|
[6e14204] | 530 | } |
---|
| 531 | if (sd->info_sex) { |
---|
| 532 | if (strlen(sd->info_sex)) { |
---|
| 533 | char *iptr = sd->info_sex; |
---|
[5ebff60] | 534 | while (*iptr++) { |
---|
[6b13103] | 535 | *iptr = g_ascii_tolower(*iptr); |
---|
[5ebff60] | 536 | } |
---|
[62f51ee9] | 537 | g_string_append_printf(st, |
---|
[5ebff60] | 538 | "Gender: %s\n", sd->info_sex); |
---|
[6e14204] | 539 | } |
---|
| 540 | g_free(sd->info_sex); |
---|
[7c2daf5f] | 541 | sd->info_sex = NULL; |
---|
[6e14204] | 542 | } |
---|
| 543 | if (sd->info_language) { |
---|
| 544 | if (strlen(sd->info_language)) { |
---|
| 545 | char *iptr = strchr(sd->info_language, ' '); |
---|
[5ebff60] | 546 | if (iptr) { |
---|
[6e14204] | 547 | iptr++; |
---|
[5ebff60] | 548 | } else { |
---|
[6e14204] | 549 | iptr = sd->info_language; |
---|
[5ebff60] | 550 | } |
---|
[62f51ee9] | 551 | g_string_append_printf(st, |
---|
[5ebff60] | 552 | "Language: %s\n", iptr); |
---|
[6e14204] | 553 | } |
---|
| 554 | g_free(sd->info_language); |
---|
[7c2daf5f] | 555 | sd->info_language = NULL; |
---|
[6e14204] | 556 | } |
---|
| 557 | if (sd->info_country) { |
---|
| 558 | if (strlen(sd->info_country)) { |
---|
| 559 | char *iptr = strchr(sd->info_country, ' '); |
---|
[5ebff60] | 560 | if (iptr) { |
---|
[6e14204] | 561 | iptr++; |
---|
[5ebff60] | 562 | } else { |
---|
[6e14204] | 563 | iptr = sd->info_country; |
---|
[5ebff60] | 564 | } |
---|
[62f51ee9] | 565 | g_string_append_printf(st, |
---|
[5ebff60] | 566 | "Country: %s\n", iptr); |
---|
[6e14204] | 567 | } |
---|
| 568 | g_free(sd->info_country); |
---|
[7c2daf5f] | 569 | sd->info_country = NULL; |
---|
[6e14204] | 570 | } |
---|
| 571 | if (sd->info_province) { |
---|
[5ebff60] | 572 | if (strlen(sd->info_province)) { |
---|
[62f51ee9] | 573 | g_string_append_printf(st, |
---|
[5ebff60] | 574 | "Region: %s\n", sd->info_province); |
---|
| 575 | } |
---|
[6e14204] | 576 | g_free(sd->info_province); |
---|
[7c2daf5f] | 577 | sd->info_province = NULL; |
---|
[6e14204] | 578 | } |
---|
| 579 | if (sd->info_city) { |
---|
[5ebff60] | 580 | if (strlen(sd->info_city)) { |
---|
[62f51ee9] | 581 | g_string_append_printf(st, |
---|
[5ebff60] | 582 | "City: %s\n", sd->info_city); |
---|
| 583 | } |
---|
[6e14204] | 584 | g_free(sd->info_city); |
---|
[7c2daf5f] | 585 | sd->info_city = NULL; |
---|
[6e14204] | 586 | } |
---|
| 587 | if (sd->info_homepage) { |
---|
[5ebff60] | 588 | if (strlen(sd->info_homepage)) { |
---|
[62f51ee9] | 589 | g_string_append_printf(st, |
---|
[5ebff60] | 590 | "Homepage: %s\n", sd->info_homepage); |
---|
| 591 | } |
---|
[6e14204] | 592 | g_free(sd->info_homepage); |
---|
[7c2daf5f] | 593 | sd->info_homepage = NULL; |
---|
[6e14204] | 594 | } |
---|
| 595 | if (sd->info_about) { |
---|
[5ebff60] | 596 | if (strlen(sd->info_about)) { |
---|
[62f51ee9] | 597 | g_string_append_printf(st, "%s\n", |
---|
[5ebff60] | 598 | sd->info_about); |
---|
| 599 | } |
---|
[6e14204] | 600 | g_free(sd->info_about); |
---|
[7c2daf5f] | 601 | sd->info_about = NULL; |
---|
[6e14204] | 602 | } |
---|
| 603 | imcb_log(ic, "%s", st->str); |
---|
| 604 | g_string_free(st, TRUE); |
---|
| 605 | } |
---|
| 606 | } |
---|
| 607 | |
---|
[e1d6b38] | 608 | static void skype_parse_chatmessage_said_emoted(struct im_connection *ic, struct groupchat *gc, char *body) |
---|
[6e14204] | 609 | { |
---|
| 610 | struct skype_data *sd = ic->proto_data; |
---|
[c213d6b] | 611 | char buf[IRC_LINE_SIZE]; |
---|
[5ebff60] | 612 | |
---|
[e1d6b38] | 613 | if (!strcmp(sd->type, "SAID")) { |
---|
[5ebff60] | 614 | if (!sd->is_edit) { |
---|
[e1d6b38] | 615 | g_snprintf(buf, IRC_LINE_SIZE, "%s", body); |
---|
[5ebff60] | 616 | } else { |
---|
[e1d6b38] | 617 | g_snprintf(buf, IRC_LINE_SIZE, "%s %s", set_getstr(&ic->acc->set, "edit_prefix"), body); |
---|
| 618 | sd->is_edit = 0; |
---|
| 619 | } |
---|
[5ebff60] | 620 | } else { |
---|
[e1d6b38] | 621 | g_snprintf(buf, IRC_LINE_SIZE, "/me %s", body); |
---|
[5ebff60] | 622 | } |
---|
| 623 | if (!gc) { |
---|
[e1d6b38] | 624 | /* Private message */ |
---|
| 625 | imcb_buddy_msg(ic, sd->handle, buf, 0, 0); |
---|
[5ebff60] | 626 | } else { |
---|
[e1d6b38] | 627 | /* Groupchat message */ |
---|
| 628 | imcb_chat_msg(gc, sd->handle, buf, 0, 0); |
---|
[5ebff60] | 629 | } |
---|
[e1d6b38] | 630 | } |
---|
| 631 | |
---|
| 632 | static void skype_parse_chatmessage(struct im_connection *ic, char *line) |
---|
| 633 | { |
---|
| 634 | struct skype_data *sd = ic->proto_data; |
---|
[6e14204] | 635 | char *id = strchr(line, ' '); |
---|
| 636 | |
---|
[5ebff60] | 637 | if (!++id) { |
---|
[6b9d22a] | 638 | return; |
---|
[5ebff60] | 639 | } |
---|
[6b9d22a] | 640 | char *info = strchr(id, ' '); |
---|
| 641 | |
---|
[5ebff60] | 642 | if (!info) { |
---|
[6b9d22a] | 643 | return; |
---|
[5ebff60] | 644 | } |
---|
[6b9d22a] | 645 | *info = '\0'; |
---|
| 646 | info++; |
---|
[7825f58] | 647 | if (!strcmp(info, "STATUS RECEIVED") || !strncmp(info, "EDITED_TIMESTAMP", 16)) { |
---|
[6b9d22a] | 648 | /* New message ID: |
---|
| 649 | * (1) Request its from field |
---|
| 650 | * (2) Request its body |
---|
| 651 | * (3) Request its type |
---|
| 652 | * (4) Query chatname |
---|
| 653 | */ |
---|
[1f4fc80] | 654 | skype_printf(ic, "GET CHATMESSAGE %s FROM_HANDLE\n", id); |
---|
[5ebff60] | 655 | if (!strcmp(info, "STATUS RECEIVED")) { |
---|
[d1d5b34] | 656 | skype_printf(ic, "GET CHATMESSAGE %s BODY\n", id); |
---|
[5ebff60] | 657 | } else { |
---|
[d9ce18c] | 658 | sd->is_edit = 1; |
---|
[5ebff60] | 659 | } |
---|
[1f4fc80] | 660 | skype_printf(ic, "GET CHATMESSAGE %s TYPE\n", id); |
---|
| 661 | skype_printf(ic, "GET CHATMESSAGE %s CHATNAME\n", id); |
---|
[6b9d22a] | 662 | } else if (!strncmp(info, "FROM_HANDLE ", 12)) { |
---|
| 663 | info += 12; |
---|
| 664 | /* New from field value. Store |
---|
| 665 | * it, then we can later use it |
---|
| 666 | * when we got the message's |
---|
| 667 | * body. */ |
---|
| 668 | g_free(sd->handle); |
---|
| 669 | sd->handle = g_strdup_printf("%s@skype.com", info); |
---|
| 670 | } else if (!strncmp(info, "EDITED_BY ", 10)) { |
---|
| 671 | info += 10; |
---|
| 672 | /* This is the same as |
---|
| 673 | * FROM_HANDLE, except that we |
---|
| 674 | * never request these lines |
---|
| 675 | * from Skype, we just get |
---|
| 676 | * them. */ |
---|
| 677 | g_free(sd->handle); |
---|
| 678 | sd->handle = g_strdup_printf("%s@skype.com", info); |
---|
| 679 | } else if (!strncmp(info, "BODY ", 5)) { |
---|
| 680 | info += 5; |
---|
| 681 | sd->body = g_list_append(sd->body, g_strdup(info)); |
---|
[5ebff60] | 682 | } else if (!strncmp(info, "TYPE ", 5)) { |
---|
[6b9d22a] | 683 | info += 5; |
---|
| 684 | g_free(sd->type); |
---|
| 685 | sd->type = g_strdup(info); |
---|
[7825f58] | 686 | } else if (!strncmp(info, "CHATNAME ", 9)) { |
---|
| 687 | info += 9; |
---|
| 688 | if (sd->handle && sd->body && sd->type) { |
---|
[451f121] | 689 | struct groupchat *gc = bee_chat_by_title(ic->bee, ic, info); |
---|
[7825f58] | 690 | int i; |
---|
| 691 | for (i = 0; i < g_list_length(sd->body); i++) { |
---|
| 692 | char *body = g_list_nth_data(sd->body, i); |
---|
| 693 | if (!strcmp(sd->type, "SAID") || |
---|
[5ebff60] | 694 | !strcmp(sd->type, "EMOTED")) { |
---|
[e1d6b38] | 695 | skype_parse_chatmessage_said_emoted(ic, gc, body); |
---|
[5ebff60] | 696 | } else if (!strcmp(sd->type, "SETTOPIC") && gc) { |
---|
[7825f58] | 697 | imcb_chat_topic(gc, |
---|
[5ebff60] | 698 | sd->handle, body, 0); |
---|
| 699 | } else if (!strcmp(sd->type, "LEFT") && gc) { |
---|
[7825f58] | 700 | imcb_chat_remove_buddy(gc, |
---|
[5ebff60] | 701 | sd->handle, NULL); |
---|
| 702 | } |
---|
[6e14204] | 703 | } |
---|
[7825f58] | 704 | g_list_free(sd->body); |
---|
| 705 | sd->body = NULL; |
---|
| 706 | } |
---|
[6e14204] | 707 | } |
---|
| 708 | } |
---|
| 709 | |
---|
[9f2f25f] | 710 | static void skype_parse_call(struct im_connection *ic, char *line) |
---|
| 711 | { |
---|
| 712 | struct skype_data *sd = ic->proto_data; |
---|
| 713 | char *id = strchr(line, ' '); |
---|
[c213d6b] | 714 | char buf[IRC_LINE_SIZE]; |
---|
[9f2f25f] | 715 | |
---|
[5ebff60] | 716 | if (!++id) { |
---|
[6b9d22a] | 717 | return; |
---|
[5ebff60] | 718 | } |
---|
[6b9d22a] | 719 | char *info = strchr(id, ' '); |
---|
| 720 | |
---|
[5ebff60] | 721 | if (!info) { |
---|
[6b9d22a] | 722 | return; |
---|
[5ebff60] | 723 | } |
---|
[6b9d22a] | 724 | *info = '\0'; |
---|
| 725 | info++; |
---|
[5ebff60] | 726 | if (!strncmp(info, "FAILUREREASON ", 14)) { |
---|
[6b9d22a] | 727 | sd->failurereason = atoi(strchr(info, ' ')); |
---|
[5ebff60] | 728 | } else if (!strcmp(info, "STATUS RINGING")) { |
---|
| 729 | if (sd->call_id) { |
---|
[6b9d22a] | 730 | g_free(sd->call_id); |
---|
[5ebff60] | 731 | } |
---|
[6b9d22a] | 732 | sd->call_id = g_strdup(id); |
---|
[1f4fc80] | 733 | skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id); |
---|
[6b9d22a] | 734 | sd->call_status = SKYPE_CALL_RINGING; |
---|
| 735 | } else if (!strcmp(info, "STATUS MISSED")) { |
---|
[1f4fc80] | 736 | skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id); |
---|
[6b9d22a] | 737 | sd->call_status = SKYPE_CALL_MISSED; |
---|
| 738 | } else if (!strcmp(info, "STATUS CANCELLED")) { |
---|
[1f4fc80] | 739 | skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id); |
---|
[6b9d22a] | 740 | sd->call_status = SKYPE_CALL_CANCELLED; |
---|
| 741 | } else if (!strcmp(info, "STATUS FINISHED")) { |
---|
[1f4fc80] | 742 | skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id); |
---|
[6b9d22a] | 743 | sd->call_status = SKYPE_CALL_FINISHED; |
---|
| 744 | } else if (!strcmp(info, "STATUS REFUSED")) { |
---|
[1f4fc80] | 745 | skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id); |
---|
[6b9d22a] | 746 | sd->call_status = SKYPE_CALL_REFUSED; |
---|
| 747 | } else if (!strcmp(info, "STATUS UNPLACED")) { |
---|
[5ebff60] | 748 | if (sd->call_id) { |
---|
[6b9d22a] | 749 | g_free(sd->call_id); |
---|
[5ebff60] | 750 | } |
---|
[6b9d22a] | 751 | /* Save the ID for later usage (Cancel/Finish). */ |
---|
| 752 | sd->call_id = g_strdup(id); |
---|
| 753 | sd->call_out = TRUE; |
---|
| 754 | } else if (!strcmp(info, "STATUS FAILED")) { |
---|
[62f51ee9] | 755 | imcb_error(ic, "Call failed: %s", |
---|
[5ebff60] | 756 | skype_call_strerror(sd->failurereason)); |
---|
[6b9d22a] | 757 | sd->call_id = NULL; |
---|
| 758 | } else if (!strncmp(info, "DURATION ", 9)) { |
---|
[5ebff60] | 759 | if (sd->call_duration) { |
---|
[6b9d22a] | 760 | g_free(sd->call_duration); |
---|
[5ebff60] | 761 | } |
---|
| 762 | sd->call_duration = g_strdup(info + 9); |
---|
[6b9d22a] | 763 | } else if (!strncmp(info, "PARTNER_HANDLE ", 15)) { |
---|
| 764 | info += 15; |
---|
[5ebff60] | 765 | if (!sd->call_status) { |
---|
[62f51ee9] | 766 | return; |
---|
[5ebff60] | 767 | } |
---|
[62f51ee9] | 768 | switch (sd->call_status) { |
---|
| 769 | case SKYPE_CALL_RINGING: |
---|
[5ebff60] | 770 | if (sd->call_out) { |
---|
[e1d6b38] | 771 | imcb_log(ic, "You are currently ringing the user %s.", info); |
---|
[5ebff60] | 772 | } else { |
---|
[c213d6b] | 773 | g_snprintf(buf, IRC_LINE_SIZE, |
---|
[5ebff60] | 774 | "The user %s is currently ringing you.", |
---|
| 775 | info); |
---|
[62f51ee9] | 776 | skype_call_ask(ic, sd->call_id, buf); |
---|
[9f2f25f] | 777 | } |
---|
[62f51ee9] | 778 | break; |
---|
| 779 | case SKYPE_CALL_MISSED: |
---|
| 780 | imcb_log(ic, "You have missed a call from user %s.", |
---|
[5ebff60] | 781 | info); |
---|
[62f51ee9] | 782 | break; |
---|
| 783 | case SKYPE_CALL_CANCELLED: |
---|
| 784 | imcb_log(ic, "You cancelled the call to the user %s.", |
---|
[5ebff60] | 785 | info); |
---|
[6b9d22a] | 786 | sd->call_status = 0; |
---|
[62f51ee9] | 787 | sd->call_out = FALSE; |
---|
| 788 | break; |
---|
| 789 | case SKYPE_CALL_REFUSED: |
---|
[5ebff60] | 790 | if (sd->call_out) { |
---|
[62f51ee9] | 791 | imcb_log(ic, "The user %s refused the call.", |
---|
[5ebff60] | 792 | info); |
---|
| 793 | } else { |
---|
[62f51ee9] | 794 | imcb_log(ic, |
---|
[5ebff60] | 795 | "You refused the call from user %s.", |
---|
| 796 | info); |
---|
| 797 | } |
---|
[62f51ee9] | 798 | sd->call_out = FALSE; |
---|
| 799 | break; |
---|
| 800 | case SKYPE_CALL_FINISHED: |
---|
[5ebff60] | 801 | if (sd->call_duration) { |
---|
[62f51ee9] | 802 | imcb_log(ic, |
---|
[5ebff60] | 803 | "You finished the call to the user %s " |
---|
| 804 | "(duration: %s seconds).", |
---|
| 805 | info, sd->call_duration); |
---|
| 806 | } else { |
---|
[62f51ee9] | 807 | imcb_log(ic, |
---|
[5ebff60] | 808 | "You finished the call to the user %s.", |
---|
| 809 | info); |
---|
| 810 | } |
---|
[62f51ee9] | 811 | sd->call_out = FALSE; |
---|
| 812 | break; |
---|
| 813 | default: |
---|
| 814 | /* Don't be noisy, ignore other statuses for now. */ |
---|
| 815 | break; |
---|
[9f2f25f] | 816 | } |
---|
[62f51ee9] | 817 | sd->call_status = 0; |
---|
[9f2f25f] | 818 | } |
---|
| 819 | } |
---|
| 820 | |
---|
[e200daf] | 821 | static void skype_parse_filetransfer(struct im_connection *ic, char *line) |
---|
| 822 | { |
---|
| 823 | struct skype_data *sd = ic->proto_data; |
---|
| 824 | char *id = strchr(line, ' '); |
---|
| 825 | |
---|
[5ebff60] | 826 | if (!++id) { |
---|
[6b9d22a] | 827 | return; |
---|
[5ebff60] | 828 | } |
---|
[6b9d22a] | 829 | char *info = strchr(id, ' '); |
---|
| 830 | |
---|
[5ebff60] | 831 | if (!info) { |
---|
[6b9d22a] | 832 | return; |
---|
[5ebff60] | 833 | } |
---|
[6b9d22a] | 834 | *info = '\0'; |
---|
| 835 | info++; |
---|
| 836 | if (!strcmp(info, "STATUS NEW")) { |
---|
[1f4fc80] | 837 | skype_printf(ic, "GET FILETRANSFER %s PARTNER_HANDLE\n", |
---|
[5ebff60] | 838 | id); |
---|
[6b9d22a] | 839 | sd->filetransfer_status = SKYPE_FILETRANSFER_NEW; |
---|
| 840 | } else if (!strcmp(info, "STATUS FAILED")) { |
---|
[1f4fc80] | 841 | skype_printf(ic, "GET FILETRANSFER %s PARTNER_HANDLE\n", |
---|
[5ebff60] | 842 | id); |
---|
[6b9d22a] | 843 | sd->filetransfer_status = SKYPE_FILETRANSFER_FAILED; |
---|
[b2dc873] | 844 | } else if (!strcmp(info, "STATUS COMPLETED")) { |
---|
| 845 | skype_printf(ic, "GET FILETRANSFER %s PARTNER_HANDLE\n", id); |
---|
| 846 | sd->filetransfer_status = SKYPE_FILETRANSFER_COMPLETED; |
---|
| 847 | } else if (!strcmp(info, "STATUS TRANSFERRING")) { |
---|
| 848 | skype_printf(ic, "GET FILETRANSFER %s PARTNER_HANDLE\n", id); |
---|
| 849 | sd->filetransfer_status = SKYPE_FILETRANSFER_TRANSFERRING; |
---|
| 850 | } else if (!strncmp(info, "FILEPATH ", 9)) { |
---|
| 851 | info += 9; |
---|
| 852 | sd->filetransfer_path = g_strdup(info); |
---|
[6b9d22a] | 853 | } else if (!strncmp(info, "PARTNER_HANDLE ", 15)) { |
---|
| 854 | info += 15; |
---|
[5ebff60] | 855 | if (!sd->filetransfer_status) { |
---|
[62f51ee9] | 856 | return; |
---|
[5ebff60] | 857 | } |
---|
[62f51ee9] | 858 | switch (sd->filetransfer_status) { |
---|
| 859 | case SKYPE_FILETRANSFER_NEW: |
---|
| 860 | imcb_log(ic, "The user %s offered a new file for you.", |
---|
[5ebff60] | 861 | info); |
---|
[62f51ee9] | 862 | break; |
---|
| 863 | case SKYPE_FILETRANSFER_FAILED: |
---|
| 864 | imcb_log(ic, "Failed to transfer file from user %s.", |
---|
[5ebff60] | 865 | info); |
---|
[62f51ee9] | 866 | break; |
---|
[b2dc873] | 867 | case SKYPE_FILETRANSFER_COMPLETED: |
---|
| 868 | imcb_log(ic, "File transfer from user %s completed.", info); |
---|
| 869 | break; |
---|
| 870 | case SKYPE_FILETRANSFER_TRANSFERRING: |
---|
| 871 | if (sd->filetransfer_path) { |
---|
[5ebff60] | 872 | imcb_log(ic, "File transfer from user %s started, saving to %s.", info, |
---|
| 873 | sd->filetransfer_path); |
---|
[b2dc873] | 874 | g_free(sd->filetransfer_path); |
---|
| 875 | sd->filetransfer_path = NULL; |
---|
| 876 | } |
---|
| 877 | break; |
---|
[e200daf] | 878 | } |
---|
[62f51ee9] | 879 | sd->filetransfer_status = 0; |
---|
[e200daf] | 880 | } |
---|
| 881 | } |
---|
| 882 | |
---|
[fbb15f2] | 883 | static struct skype_group *skype_group_by_id(struct im_connection *ic, int id) |
---|
| 884 | { |
---|
[89d6845] | 885 | struct skype_data *sd = ic->proto_data; |
---|
| 886 | int i; |
---|
| 887 | |
---|
| 888 | for (i = 0; i < g_list_length(sd->groups); i++) { |
---|
[5ebff60] | 889 | struct skype_group *sg = (struct skype_group *) g_list_nth_data(sd->groups, i); |
---|
[89d6845] | 890 | |
---|
[5ebff60] | 891 | if (sg->id == id) { |
---|
[89d6845] | 892 | return sg; |
---|
[5ebff60] | 893 | } |
---|
[89d6845] | 894 | } |
---|
| 895 | return NULL; |
---|
| 896 | } |
---|
| 897 | |
---|
[fbb15f2] | 898 | static void skype_group_free(struct skype_group *sg, gboolean usersonly) |
---|
| 899 | { |
---|
[89d6845] | 900 | int i; |
---|
[fbb15f2] | 901 | |
---|
[89d6845] | 902 | for (i = 0; i < g_list_length(sg->users); i++) { |
---|
| 903 | char *user = g_list_nth_data(sg->users, i); |
---|
| 904 | g_free(user); |
---|
| 905 | } |
---|
| 906 | sg->users = NULL; |
---|
[5ebff60] | 907 | if (usersonly) { |
---|
[89d6845] | 908 | return; |
---|
[5ebff60] | 909 | } |
---|
[89d6845] | 910 | g_free(sg->name); |
---|
| 911 | g_free(sg); |
---|
| 912 | } |
---|
| 913 | |
---|
[54ca269] | 914 | /* Update the group of each user in this group */ |
---|
[fbb15f2] | 915 | static void skype_group_users(struct im_connection *ic, struct skype_group *sg) |
---|
| 916 | { |
---|
[54ca269] | 917 | int i; |
---|
| 918 | |
---|
| 919 | for (i = 0; i < g_list_length(sg->users); i++) { |
---|
| 920 | char *user = g_list_nth_data(sg->users, i); |
---|
| 921 | char *buf = g_strdup_printf("%s@skype.com", user); |
---|
| 922 | imcb_add_buddy(ic, buf, sg->name); |
---|
| 923 | g_free(buf); |
---|
| 924 | } |
---|
| 925 | } |
---|
| 926 | |
---|
[89d6845] | 927 | static void skype_parse_group(struct im_connection *ic, char *line) |
---|
| 928 | { |
---|
| 929 | struct skype_data *sd = ic->proto_data; |
---|
| 930 | char *id = strchr(line, ' '); |
---|
| 931 | |
---|
[5ebff60] | 932 | if (!++id) { |
---|
[89d6845] | 933 | return; |
---|
[5ebff60] | 934 | } |
---|
[89d6845] | 935 | |
---|
| 936 | char *info = strchr(id, ' '); |
---|
| 937 | |
---|
[5ebff60] | 938 | if (!info) { |
---|
[89d6845] | 939 | return; |
---|
[5ebff60] | 940 | } |
---|
[89d6845] | 941 | *info = '\0'; |
---|
| 942 | info++; |
---|
| 943 | |
---|
| 944 | if (!strncmp(info, "DISPLAYNAME ", 12)) { |
---|
| 945 | info += 12; |
---|
| 946 | |
---|
| 947 | /* Name given for a group ID: try to update it or insert a new |
---|
| 948 | * one if not found */ |
---|
| 949 | struct skype_group *sg = skype_group_by_id(ic, atoi(id)); |
---|
| 950 | if (sg) { |
---|
| 951 | g_free(sg->name); |
---|
| 952 | sg->name = g_strdup(info); |
---|
| 953 | } else { |
---|
| 954 | sg = g_new0(struct skype_group, 1); |
---|
| 955 | sg->id = atoi(id); |
---|
| 956 | sg->name = g_strdup(info); |
---|
| 957 | sd->groups = g_list_append(sd->groups, sg); |
---|
| 958 | } |
---|
| 959 | } else if (!strncmp(info, "USERS ", 6)) { |
---|
| 960 | struct skype_group *sg = skype_group_by_id(ic, atoi(id)); |
---|
| 961 | |
---|
| 962 | if (sg) { |
---|
| 963 | char **i; |
---|
| 964 | char **users = g_strsplit(info + 6, ", ", 0); |
---|
| 965 | |
---|
| 966 | skype_group_free(sg, TRUE); |
---|
| 967 | i = users; |
---|
| 968 | while (*i) { |
---|
| 969 | sg->users = g_list_append(sg->users, g_strdup(*i)); |
---|
| 970 | i++; |
---|
| 971 | } |
---|
| 972 | g_strfreev(users); |
---|
[54ca269] | 973 | skype_group_users(ic, sg); |
---|
[5ebff60] | 974 | } else { |
---|
[fbb15f2] | 975 | log_message(LOGLVL_ERROR, |
---|
[5ebff60] | 976 | "No skype group with id %s. That's probably a bug.", id); |
---|
| 977 | } |
---|
[46641bf] | 978 | } else if (!strncmp(info, "NROFUSERS ", 10)) { |
---|
| 979 | if (!sd->pending_user) { |
---|
| 980 | /* Number of users changed in this group, query its type to see |
---|
| 981 | * if it's a custom one we should care about. */ |
---|
[5a0ffa2] | 982 | skype_printf(ic, "GET GROUP %s TYPE\n", id); |
---|
[46641bf] | 983 | return; |
---|
| 984 | } |
---|
| 985 | |
---|
| 986 | /* This is a newly created group, we have a single user |
---|
| 987 | * to add. */ |
---|
| 988 | struct skype_group *sg = skype_group_by_id(ic, atoi(id)); |
---|
| 989 | |
---|
| 990 | if (sg) { |
---|
[5a0ffa2] | 991 | skype_printf(ic, "ALTER GROUP %d ADDUSER %s\n", sg->id, sd->pending_user); |
---|
[46641bf] | 992 | g_free(sd->pending_user); |
---|
| 993 | sd->pending_user = NULL; |
---|
[5ebff60] | 994 | } else { |
---|
[46641bf] | 995 | log_message(LOGLVL_ERROR, |
---|
[5ebff60] | 996 | "No skype group with id %s. That's probably a bug.", id); |
---|
| 997 | } |
---|
| 998 | } else if (!strcmp(info, "TYPE CUSTOM_GROUP")) { |
---|
[cb6d3c9] | 999 | /* This one is interesting, query its users. */ |
---|
[5a0ffa2] | 1000 | skype_printf(ic, "GET GROUP %s USERS\n", id); |
---|
[5ebff60] | 1001 | } |
---|
[89d6845] | 1002 | } |
---|
| 1003 | |
---|
[c35bf7a] | 1004 | static void skype_parse_chat(struct im_connection *ic, char *line) |
---|
| 1005 | { |
---|
| 1006 | struct skype_data *sd = ic->proto_data; |
---|
[c213d6b] | 1007 | char buf[IRC_LINE_SIZE]; |
---|
[c35bf7a] | 1008 | char *id = strchr(line, ' '); |
---|
| 1009 | |
---|
[5ebff60] | 1010 | if (!++id) { |
---|
[6b9d22a] | 1011 | return; |
---|
[5ebff60] | 1012 | } |
---|
[6b9d22a] | 1013 | struct groupchat *gc; |
---|
| 1014 | char *info = strchr(id, ' '); |
---|
[c35bf7a] | 1015 | |
---|
[5ebff60] | 1016 | if (!info) { |
---|
[6b9d22a] | 1017 | return; |
---|
[5ebff60] | 1018 | } |
---|
[6b9d22a] | 1019 | *info = '\0'; |
---|
| 1020 | info++; |
---|
| 1021 | /* Remove fake chat if we created one in skype_chat_with() */ |
---|
[451f121] | 1022 | gc = bee_chat_by_title(ic->bee, ic, ""); |
---|
[5ebff60] | 1023 | if (gc) { |
---|
[6b9d22a] | 1024 | imcb_chat_free(gc); |
---|
[5ebff60] | 1025 | } |
---|
[6b9d22a] | 1026 | if (!strcmp(info, "STATUS MULTI_SUBSCRIBED")) { |
---|
[c573f1b] | 1027 | gc = bee_chat_by_title(ic->bee, ic, id); |
---|
| 1028 | if (!gc) { |
---|
| 1029 | gc = imcb_chat_new(ic, id); |
---|
| 1030 | imcb_chat_name_hint(gc, id); |
---|
| 1031 | } |
---|
[1f4fc80] | 1032 | skype_printf(ic, "GET CHAT %s ADDER\n", id); |
---|
| 1033 | skype_printf(ic, "GET CHAT %s TOPIC\n", id); |
---|
[6b9d22a] | 1034 | } else if (!strcmp(info, "STATUS DIALOG") && sd->groupchat_with) { |
---|
| 1035 | gc = imcb_chat_new(ic, id); |
---|
[72b60c7e] | 1036 | imcb_chat_name_hint(gc, id); |
---|
[6b9d22a] | 1037 | /* According to the docs this |
---|
| 1038 | * is necessary. However it |
---|
| 1039 | * does not seem the situation |
---|
| 1040 | * and it would open an extra |
---|
| 1041 | * window on our client, so |
---|
| 1042 | * just leave it out. */ |
---|
[1f4fc80] | 1043 | /*skype_printf(ic, "OPEN CHAT %s\n", id);*/ |
---|
[5d9db76] | 1044 | g_snprintf(buf, IRC_LINE_SIZE, "%s@skype.com", |
---|
[5ebff60] | 1045 | sd->groupchat_with); |
---|
[6b9d22a] | 1046 | imcb_chat_add_buddy(gc, buf); |
---|
| 1047 | imcb_chat_add_buddy(gc, sd->username); |
---|
| 1048 | g_free(sd->groupchat_with); |
---|
| 1049 | sd->groupchat_with = NULL; |
---|
[1f4fc80] | 1050 | skype_printf(ic, "GET CHAT %s ADDER\n", id); |
---|
| 1051 | skype_printf(ic, "GET CHAT %s TOPIC\n", id); |
---|
[6b9d22a] | 1052 | } else if (!strcmp(info, "STATUS UNSUBSCRIBED")) { |
---|
[451f121] | 1053 | gc = bee_chat_by_title(ic->bee, ic, id); |
---|
[5ebff60] | 1054 | if (gc) { |
---|
| 1055 | gc->data = (void *) FALSE; |
---|
| 1056 | } |
---|
[6b9d22a] | 1057 | } else if (!strncmp(info, "ADDER ", 6)) { |
---|
| 1058 | info += 6; |
---|
| 1059 | g_free(sd->adder); |
---|
| 1060 | sd->adder = g_strdup_printf("%s@skype.com", info); |
---|
| 1061 | } else if (!strncmp(info, "TOPIC ", 6)) { |
---|
| 1062 | info += 6; |
---|
[451f121] | 1063 | gc = bee_chat_by_title(ic->bee, ic, id); |
---|
[6b9d22a] | 1064 | if (gc && (sd->adder || sd->topic_wait)) { |
---|
| 1065 | if (sd->topic_wait) { |
---|
| 1066 | sd->adder = g_strdup(sd->username); |
---|
| 1067 | sd->topic_wait = 0; |
---|
[c35bf7a] | 1068 | } |
---|
[6b9d22a] | 1069 | imcb_chat_topic(gc, sd->adder, info, 0); |
---|
| 1070 | g_free(sd->adder); |
---|
| 1071 | sd->adder = NULL; |
---|
| 1072 | } |
---|
[5ebff60] | 1073 | } else if (!strncmp(info, "MEMBERS ", 8) || !strncmp(info, "ACTIVEMEMBERS ", 14)) { |
---|
| 1074 | if (!strncmp(info, "MEMBERS ", 8)) { |
---|
[500419b] | 1075 | info += 8; |
---|
[5ebff60] | 1076 | } else { |
---|
[500419b] | 1077 | info += 14; |
---|
[5ebff60] | 1078 | } |
---|
[451f121] | 1079 | gc = bee_chat_by_title(ic->bee, ic, id); |
---|
[6b9d22a] | 1080 | /* Hack! We set ->data to TRUE |
---|
| 1081 | * while we're on the channel |
---|
| 1082 | * so that we won't rejoin |
---|
| 1083 | * after a /part. */ |
---|
[5ebff60] | 1084 | if (!gc || gc->data) { |
---|
[62f51ee9] | 1085 | return; |
---|
[5ebff60] | 1086 | } |
---|
[62f51ee9] | 1087 | char **members = g_strsplit(info, " ", 0); |
---|
| 1088 | int i; |
---|
| 1089 | for (i = 0; members[i]; i++) { |
---|
[5ebff60] | 1090 | if (!strcmp(members[i], sd->username)) { |
---|
[62f51ee9] | 1091 | continue; |
---|
[5ebff60] | 1092 | } |
---|
[5d9db76] | 1093 | g_snprintf(buf, IRC_LINE_SIZE, "%s@skype.com", |
---|
[5ebff60] | 1094 | members[i]); |
---|
[62f51ee9] | 1095 | if (!g_list_find_custom(gc->in_room, buf, |
---|
[5ebff60] | 1096 | (GCompareFunc) strcmp)) { |
---|
[62f51ee9] | 1097 | imcb_chat_add_buddy(gc, buf); |
---|
[5ebff60] | 1098 | } |
---|
[c35bf7a] | 1099 | } |
---|
[62f51ee9] | 1100 | imcb_chat_add_buddy(gc, sd->username); |
---|
| 1101 | g_strfreev(members); |
---|
[c35bf7a] | 1102 | } |
---|
| 1103 | } |
---|
| 1104 | |
---|
[2709f4c] | 1105 | static void skype_parse_password(struct im_connection *ic, char *line) |
---|
| 1106 | { |
---|
[5ebff60] | 1107 | if (!strncmp(line + 9, "OK", 2)) { |
---|
[2709f4c] | 1108 | imcb_connected(ic); |
---|
[5ebff60] | 1109 | } else { |
---|
[2709f4c] | 1110 | imcb_error(ic, "Authentication Failed"); |
---|
| 1111 | imc_logout(ic, TRUE); |
---|
| 1112 | } |
---|
| 1113 | } |
---|
| 1114 | |
---|
[607f5e3] | 1115 | static void skype_parse_profile(struct im_connection *ic, char *line) |
---|
| 1116 | { |
---|
[5ebff60] | 1117 | imcb_log(ic, "SkypeOut balance value is '%s'.", line + 21); |
---|
[607f5e3] | 1118 | } |
---|
| 1119 | |
---|
| 1120 | static void skype_parse_ping(struct im_connection *ic, char *line) |
---|
| 1121 | { |
---|
[4ae3ffc] | 1122 | /* Unused parameter */ |
---|
| 1123 | line = line; |
---|
[1f4fc80] | 1124 | skype_printf(ic, "PONG\n"); |
---|
[607f5e3] | 1125 | } |
---|
| 1126 | |
---|
| 1127 | static void skype_parse_chats(struct im_connection *ic, char *line) |
---|
| 1128 | { |
---|
| 1129 | char **i; |
---|
| 1130 | char **chats = g_strsplit(line + 6, ", ", 0); |
---|
| 1131 | |
---|
| 1132 | i = chats; |
---|
| 1133 | while (*i) { |
---|
[1f4fc80] | 1134 | skype_printf(ic, "GET CHAT %s STATUS\n", *i); |
---|
| 1135 | skype_printf(ic, "GET CHAT %s ACTIVEMEMBERS\n", *i); |
---|
[607f5e3] | 1136 | i++; |
---|
| 1137 | } |
---|
| 1138 | g_strfreev(chats); |
---|
| 1139 | } |
---|
| 1140 | |
---|
[8b8d1bed] | 1141 | static void skype_parse_groups(struct im_connection *ic, char *line) |
---|
| 1142 | { |
---|
[5ebff60] | 1143 | if (!set_getbool(&ic->acc->set, "read_groups")) { |
---|
[3c7af69] | 1144 | return; |
---|
[5ebff60] | 1145 | } |
---|
[3c7af69] | 1146 | |
---|
[8b8d1bed] | 1147 | char **i; |
---|
| 1148 | char **groups = g_strsplit(line + 7, ", ", 0); |
---|
| 1149 | |
---|
| 1150 | i = groups; |
---|
| 1151 | while (*i) { |
---|
| 1152 | skype_printf(ic, "GET GROUP %s DISPLAYNAME\n", *i); |
---|
| 1153 | skype_printf(ic, "GET GROUP %s USERS\n", *i); |
---|
| 1154 | i++; |
---|
| 1155 | } |
---|
| 1156 | g_strfreev(groups); |
---|
| 1157 | } |
---|
| 1158 | |
---|
[46e9822] | 1159 | static void skype_parse_alter_group(struct im_connection *ic, char *line) |
---|
| 1160 | { |
---|
| 1161 | char *id = line + strlen("ALTER GROUP"); |
---|
| 1162 | |
---|
[5ebff60] | 1163 | if (!++id) { |
---|
[46e9822] | 1164 | return; |
---|
[5ebff60] | 1165 | } |
---|
[46e9822] | 1166 | |
---|
| 1167 | char *info = strchr(id, ' '); |
---|
| 1168 | |
---|
[5ebff60] | 1169 | if (!info) { |
---|
[46e9822] | 1170 | return; |
---|
[5ebff60] | 1171 | } |
---|
[46e9822] | 1172 | *info = '\0'; |
---|
| 1173 | info++; |
---|
| 1174 | |
---|
| 1175 | if (!strncmp(info, "ADDUSER ", 8)) { |
---|
| 1176 | struct skype_group *sg = skype_group_by_id(ic, atoi(id)); |
---|
| 1177 | |
---|
| 1178 | info += 8; |
---|
| 1179 | if (sg) { |
---|
| 1180 | char *buf = g_strdup_printf("%s@skype.com", info); |
---|
| 1181 | sg->users = g_list_append(sg->users, g_strdup(info)); |
---|
| 1182 | imcb_add_buddy(ic, buf, sg->name); |
---|
| 1183 | g_free(buf); |
---|
[5ebff60] | 1184 | } else { |
---|
[46e9822] | 1185 | log_message(LOGLVL_ERROR, |
---|
[5ebff60] | 1186 | "No skype group with id %s. That's probably a bug.", id); |
---|
| 1187 | } |
---|
[46e9822] | 1188 | } |
---|
| 1189 | } |
---|
| 1190 | |
---|
[ff436ba] | 1191 | typedef void (*skype_parser)(struct im_connection *ic, char *line); |
---|
| 1192 | |
---|
[8c09bb3] | 1193 | static gboolean skype_read_callback(gpointer data, gint fd, |
---|
[5ebff60] | 1194 | b_input_condition cond) |
---|
[1323e36] | 1195 | { |
---|
| 1196 | struct im_connection *ic = data; |
---|
| 1197 | struct skype_data *sd = ic->proto_data; |
---|
[c213d6b] | 1198 | char buf[IRC_LINE_SIZE]; |
---|
[ff436ba] | 1199 | int st, i; |
---|
[6e14204] | 1200 | char **lines, **lineptr, *line; |
---|
[ff436ba] | 1201 | static struct parse_map { |
---|
| 1202 | char *k; |
---|
| 1203 | skype_parser v; |
---|
| 1204 | } parsers[] = { |
---|
| 1205 | { "USERS ", skype_parse_users }, |
---|
| 1206 | { "USER ", skype_parse_user }, |
---|
| 1207 | { "CHATMESSAGE ", skype_parse_chatmessage }, |
---|
| 1208 | { "CALL ", skype_parse_call }, |
---|
| 1209 | { "FILETRANSFER ", skype_parse_filetransfer }, |
---|
| 1210 | { "CHAT ", skype_parse_chat }, |
---|
[89d6845] | 1211 | { "GROUP ", skype_parse_group }, |
---|
[ff436ba] | 1212 | { "PASSWORD ", skype_parse_password }, |
---|
| 1213 | { "PROFILE PSTN_BALANCE ", skype_parse_profile }, |
---|
| 1214 | { "PING", skype_parse_ping }, |
---|
| 1215 | { "CHATS ", skype_parse_chats }, |
---|
[8b8d1bed] | 1216 | { "GROUPS ", skype_parse_groups }, |
---|
[46e9822] | 1217 | { "ALTER GROUP ", skype_parse_alter_group }, |
---|
[ff436ba] | 1218 | }; |
---|
[1323e36] | 1219 | |
---|
[4ae3ffc] | 1220 | /* Unused parameters */ |
---|
| 1221 | fd = fd; |
---|
| 1222 | cond = cond; |
---|
| 1223 | |
---|
[5ebff60] | 1224 | if (!sd || sd->fd == -1) { |
---|
[1323e36] | 1225 | return FALSE; |
---|
[5ebff60] | 1226 | } |
---|
[7daec06] | 1227 | /* Read the whole data. */ |
---|
[5adcc65] | 1228 | st = ssl_read(sd->ssl, buf, sizeof(buf)); |
---|
[5ebff60] | 1229 | if (st >= IRC_LINE_SIZE - 1) { |
---|
[61d2eabb] | 1230 | /* As we don't buffer incoming data, if IRC_LINE_SIZE amount of bytes |
---|
| 1231 | * were received, there's a good chance last message was truncated |
---|
| 1232 | * and the next recv() will yield garbage. */ |
---|
| 1233 | imcb_error(ic, "Unable to handle incoming data from skyped"); |
---|
| 1234 | st = 0; |
---|
| 1235 | } |
---|
[5adcc65] | 1236 | if (st > 0) { |
---|
[1323e36] | 1237 | buf[st] = '\0'; |
---|
[7daec06] | 1238 | /* Then split it up to lines. */ |
---|
[9fd4241] | 1239 | lines = g_strsplit(buf, "\n", 0); |
---|
| 1240 | lineptr = lines; |
---|
[5adcc65] | 1241 | while ((line = *lineptr)) { |
---|
[5ebff60] | 1242 | if (!strlen(line)) { |
---|
[9fd4241] | 1243 | break; |
---|
[5ebff60] | 1244 | } |
---|
| 1245 | if (set_getbool(&ic->acc->set, "skypeconsole_receive")) { |
---|
[b820226] | 1246 | imcb_buddy_msg(ic, "skypeconsole", line, 0, 0); |
---|
[5ebff60] | 1247 | } |
---|
| 1248 | for (i = 0; i < ARRAY_SIZE(parsers); i++) { |
---|
[6b9d22a] | 1249 | if (!strncmp(line, parsers[i].k, |
---|
[5ebff60] | 1250 | strlen(parsers[i].k))) { |
---|
[ff436ba] | 1251 | parsers[i].v(ic, line); |
---|
| 1252 | break; |
---|
| 1253 | } |
---|
[5ebff60] | 1254 | } |
---|
[9fd4241] | 1255 | lineptr++; |
---|
| 1256 | } |
---|
| 1257 | g_strfreev(lines); |
---|
[b87e5dc] | 1258 | } else if (st == 0 || (st < 0 && !ssl_sockerr_again(sd->ssl))) { |
---|
[58b65b33] | 1259 | ssl_disconnect(sd->ssl); |
---|
[1323e36] | 1260 | sd->fd = -1; |
---|
[58b65b33] | 1261 | sd->ssl = NULL; |
---|
[1323e36] | 1262 | |
---|
[5adcc65] | 1263 | imcb_error(ic, "Error while reading from server"); |
---|
| 1264 | imc_logout(ic, TRUE); |
---|
[1323e36] | 1265 | return FALSE; |
---|
| 1266 | } |
---|
| 1267 | return TRUE; |
---|
| 1268 | } |
---|
| 1269 | |
---|
[5adcc65] | 1270 | gboolean skype_start_stream(struct im_connection *ic) |
---|
[f06e3ac] | 1271 | { |
---|
[1323e36] | 1272 | struct skype_data *sd = ic->proto_data; |
---|
[f06e3ac] | 1273 | int st; |
---|
| 1274 | |
---|
[5ebff60] | 1275 | if (!sd) { |
---|
[1fb89e3] | 1276 | return FALSE; |
---|
[5ebff60] | 1277 | } |
---|
[1fb89e3] | 1278 | |
---|
[5ebff60] | 1279 | if (sd->bfd <= 0) { |
---|
[7670b02] | 1280 | sd->bfd = b_input_add(sd->fd, B_EV_IO_READ, |
---|
[5ebff60] | 1281 | skype_read_callback, ic); |
---|
| 1282 | } |
---|
[1323e36] | 1283 | |
---|
[a0b206b] | 1284 | /* Log in */ |
---|
[1f4fc80] | 1285 | skype_printf(ic, "USERNAME %s\n", ic->acc->user); |
---|
| 1286 | skype_printf(ic, "PASSWORD %s\n", ic->acc->pass); |
---|
[a0b206b] | 1287 | |
---|
[8b8d1bed] | 1288 | /* This will download all buddies and groups. */ |
---|
[54ca269] | 1289 | st = skype_printf(ic, "SEARCH GROUPS CUSTOM\n"); |
---|
| 1290 | skype_printf(ic, "SEARCH FRIENDS\n"); |
---|
[8b8d1bed] | 1291 | |
---|
[1f4fc80] | 1292 | skype_printf(ic, "SET USERSTATUS ONLINE\n"); |
---|
[5acf9ab] | 1293 | |
---|
| 1294 | /* Auto join to bookmarked chats if requested.*/ |
---|
[215e171] | 1295 | if (set_getbool(&ic->acc->set, "auto_join")) { |
---|
[1f4fc80] | 1296 | skype_printf(ic, "SEARCH BOOKMARKEDCHATS\n"); |
---|
[215e171] | 1297 | skype_printf(ic, "SEARCH ACTIVECHATS\n"); |
---|
| 1298 | skype_printf(ic, "SEARCH MISSEDCHATS\n"); |
---|
| 1299 | skype_printf(ic, "SEARCH RECENTCHATS\n"); |
---|
| 1300 | } |
---|
[f06e3ac] | 1301 | return st; |
---|
| 1302 | } |
---|
| 1303 | |
---|
[486ddb5] | 1304 | gboolean skype_connected(gpointer data, int returncode, void *source, b_input_condition cond) |
---|
[f06e3ac] | 1305 | { |
---|
| 1306 | struct im_connection *ic = data; |
---|
[c7304b2] | 1307 | struct skype_data *sd = ic->proto_data; |
---|
[4ae3ffc] | 1308 | |
---|
| 1309 | /* Unused parameter */ |
---|
| 1310 | cond = cond; |
---|
| 1311 | |
---|
[5adcc65] | 1312 | if (!source) { |
---|
[c7304b2] | 1313 | sd->ssl = NULL; |
---|
[5adcc65] | 1314 | imcb_error(ic, "Could not connect to server"); |
---|
| 1315 | imc_logout(ic, TRUE); |
---|
[c7304b2] | 1316 | return FALSE; |
---|
| 1317 | } |
---|
[5adcc65] | 1318 | imcb_log(ic, "Connected to server, logging in"); |
---|
[4ae3ffc] | 1319 | |
---|
[f06e3ac] | 1320 | return skype_start_stream(ic); |
---|
| 1321 | } |
---|
| 1322 | |
---|
[5adcc65] | 1323 | static void skype_login(account_t *acc) |
---|
[f06e3ac] | 1324 | { |
---|
[5adcc65] | 1325 | struct im_connection *ic = imcb_new(acc); |
---|
| 1326 | struct skype_data *sd = g_new0(struct skype_data, 1); |
---|
[f06e3ac] | 1327 | |
---|
| 1328 | ic->proto_data = sd; |
---|
| 1329 | |
---|
[5adcc65] | 1330 | imcb_log(ic, "Connecting"); |
---|
[8c09bb3] | 1331 | sd->ssl = ssl_connect(set_getstr(&acc->set, "server"), |
---|
[5ebff60] | 1332 | set_getint(&acc->set, "port"), FALSE, skype_connected, ic); |
---|
[5adcc65] | 1333 | sd->fd = sd->ssl ? ssl_getfd(sd->ssl) : -1; |
---|
| 1334 | sd->username = g_strdup(acc->user); |
---|
[f06e3ac] | 1335 | |
---|
| 1336 | sd->ic = ic; |
---|
[08a355b] | 1337 | |
---|
[5ebff60] | 1338 | if (set_getbool(&acc->set, "skypeconsole")) { |
---|
[08a355b] | 1339 | imcb_add_buddy(ic, "skypeconsole", NULL); |
---|
[5ebff60] | 1340 | } |
---|
[f06e3ac] | 1341 | } |
---|
| 1342 | |
---|
[5adcc65] | 1343 | static void skype_logout(struct im_connection *ic) |
---|
[f06e3ac] | 1344 | { |
---|
| 1345 | struct skype_data *sd = ic->proto_data; |
---|
[89d6845] | 1346 | int i; |
---|
[98bca36] | 1347 | |
---|
[1f4fc80] | 1348 | skype_printf(ic, "SET USERSTATUS OFFLINE\n"); |
---|
[98bca36] | 1349 | |
---|
[5ebff60] | 1350 | while (ic->groupchats) { |
---|
[bd11422] | 1351 | imcb_chat_free(ic->groupchats->data); |
---|
[5ebff60] | 1352 | } |
---|
[bd11422] | 1353 | |
---|
[89d6845] | 1354 | for (i = 0; i < g_list_length(sd->groups); i++) { |
---|
[5ebff60] | 1355 | struct skype_group *sg = (struct skype_group *) g_list_nth_data(sd->groups, i); |
---|
[89d6845] | 1356 | skype_group_free(sg, FALSE); |
---|
| 1357 | } |
---|
[58b65b33] | 1358 | |
---|
[5ebff60] | 1359 | if (sd->ssl) { |
---|
[58b65b33] | 1360 | ssl_disconnect(sd->ssl); |
---|
[5ebff60] | 1361 | } |
---|
[58b65b33] | 1362 | |
---|
[a3d6427] | 1363 | g_free(sd->username); |
---|
[7613670] | 1364 | g_free(sd->handle); |
---|
[f06e3ac] | 1365 | g_free(sd); |
---|
[98bca36] | 1366 | ic->proto_data = NULL; |
---|
[f06e3ac] | 1367 | } |
---|
| 1368 | |
---|
[8c09bb3] | 1369 | static int skype_buddy_msg(struct im_connection *ic, char *who, char *message, |
---|
[5ebff60] | 1370 | int flags) |
---|
[93ece66] | 1371 | { |
---|
[1f4fc80] | 1372 | char *ptr, *nick; |
---|
[93ece66] | 1373 | int st; |
---|
| 1374 | |
---|
[4ae3ffc] | 1375 | /* Unused parameter */ |
---|
| 1376 | flags = flags; |
---|
| 1377 | |
---|
[cbec0d6] | 1378 | nick = g_strdup(who); |
---|
[77c1abe] | 1379 | ptr = strchr(nick, '@'); |
---|
[5ebff60] | 1380 | if (ptr) { |
---|
[0bb1b7f] | 1381 | *ptr = '\0'; |
---|
[5ebff60] | 1382 | } |
---|
[93ece66] | 1383 | |
---|
[5ebff60] | 1384 | if (!strncmp(who, "skypeconsole", 12)) { |
---|
[1f4fc80] | 1385 | st = skype_printf(ic, "%s\n", message); |
---|
[5ebff60] | 1386 | } else { |
---|
[1f4fc80] | 1387 | st = skype_printf(ic, "MESSAGE %s %s\n", nick, message); |
---|
[5ebff60] | 1388 | } |
---|
[77c1abe] | 1389 | g_free(nick); |
---|
[93ece66] | 1390 | |
---|
| 1391 | return st; |
---|
| 1392 | } |
---|
| 1393 | |
---|
[5adcc65] | 1394 | const struct skype_away_state *skype_away_state_by_name(char *name) |
---|
[23411c6] | 1395 | { |
---|
| 1396 | int i; |
---|
| 1397 | |
---|
[5ebff60] | 1398 | for (i = 0; skype_away_state_list[i].full_name; i++) { |
---|
| 1399 | if (g_strcasecmp(skype_away_state_list[i].full_name, name) == 0) { |
---|
[5adcc65] | 1400 | return skype_away_state_list + i; |
---|
[5ebff60] | 1401 | } |
---|
| 1402 | } |
---|
[23411c6] | 1403 | |
---|
| 1404 | return NULL; |
---|
| 1405 | } |
---|
| 1406 | |
---|
[8c09bb3] | 1407 | static void skype_set_away(struct im_connection *ic, char *state_txt, |
---|
[5ebff60] | 1408 | char *message) |
---|
[f06e3ac] | 1409 | { |
---|
[23411c6] | 1410 | const struct skype_away_state *state; |
---|
| 1411 | |
---|
[4ae3ffc] | 1412 | /* Unused parameter */ |
---|
| 1413 | message = message; |
---|
| 1414 | |
---|
[5ebff60] | 1415 | if (state_txt == NULL) { |
---|
[4b740c2] | 1416 | state = skype_away_state_by_name("Online"); |
---|
[5ebff60] | 1417 | } else { |
---|
[5adcc65] | 1418 | state = skype_away_state_by_name(state_txt); |
---|
[5ebff60] | 1419 | } |
---|
[1f4fc80] | 1420 | skype_printf(ic, "SET USERSTATUS %s\n", state->code); |
---|
[f06e3ac] | 1421 | } |
---|
| 1422 | |
---|
[5adcc65] | 1423 | static GList *skype_away_states(struct im_connection *ic) |
---|
[f06e3ac] | 1424 | { |
---|
[5adcc65] | 1425 | static GList *l; |
---|
[adce2de] | 1426 | int i; |
---|
[5adcc65] | 1427 | |
---|
[4ae3ffc] | 1428 | /* Unused parameter */ |
---|
| 1429 | ic = ic; |
---|
| 1430 | |
---|
[5ebff60] | 1431 | if (l == NULL) { |
---|
| 1432 | for (i = 0; skype_away_state_list[i].full_name; i++) { |
---|
[8c09bb3] | 1433 | l = g_list_append(l, |
---|
[5ebff60] | 1434 | (void *) skype_away_state_list[i].full_name); |
---|
| 1435 | } |
---|
| 1436 | } |
---|
[5adcc65] | 1437 | |
---|
[f06e3ac] | 1438 | return l; |
---|
| 1439 | } |
---|
| 1440 | |
---|
[5adcc65] | 1441 | static char *skype_set_display_name(set_t *set, char *value) |
---|
[93dffea] | 1442 | { |
---|
| 1443 | account_t *acc = set->data; |
---|
| 1444 | struct im_connection *ic = acc->ic; |
---|
| 1445 | |
---|
[5a0ffa2] | 1446 | skype_printf(ic, "SET PROFILE FULLNAME %s\n", value); |
---|
[5adcc65] | 1447 | return value; |
---|
[93dffea] | 1448 | } |
---|
| 1449 | |
---|
[7764fb1] | 1450 | static char *skype_set_mood_text(set_t *set, char *value) |
---|
| 1451 | { |
---|
| 1452 | account_t *acc = set->data; |
---|
| 1453 | struct im_connection *ic = acc->ic; |
---|
| 1454 | |
---|
[5a0ffa2] | 1455 | skype_printf(ic, "SET PROFILE MOOD_TEXT %s\n", value); |
---|
[7764fb1] | 1456 | return value; |
---|
| 1457 | } |
---|
| 1458 | |
---|
[5adcc65] | 1459 | static char *skype_set_balance(set_t *set, char *value) |
---|
[2af671a] | 1460 | { |
---|
| 1461 | account_t *acc = set->data; |
---|
| 1462 | struct im_connection *ic = acc->ic; |
---|
| 1463 | |
---|
[5a0ffa2] | 1464 | skype_printf(ic, "GET PROFILE PSTN_BALANCE\n"); |
---|
[5adcc65] | 1465 | return value; |
---|
[2af671a] | 1466 | } |
---|
| 1467 | |
---|
[fbb15f2] | 1468 | static void skype_call(struct im_connection *ic, char *value) |
---|
| 1469 | { |
---|
[71c4bb6] | 1470 | char *nick = g_strdup(value); |
---|
| 1471 | char *ptr = strchr(nick, '@'); |
---|
| 1472 | |
---|
[5ebff60] | 1473 | if (ptr) { |
---|
[71c4bb6] | 1474 | *ptr = '\0'; |
---|
[5ebff60] | 1475 | } |
---|
[5a0ffa2] | 1476 | skype_printf(ic, "CALL %s\n", nick); |
---|
[71c4bb6] | 1477 | g_free(nick); |
---|
| 1478 | } |
---|
| 1479 | |
---|
| 1480 | static void skype_hangup(struct im_connection *ic) |
---|
| 1481 | { |
---|
| 1482 | struct skype_data *sd = ic->proto_data; |
---|
| 1483 | |
---|
| 1484 | if (sd->call_id) { |
---|
[5a0ffa2] | 1485 | skype_printf(ic, "SET CALL %s STATUS FINISHED\n", |
---|
[5ebff60] | 1486 | sd->call_id); |
---|
[71c4bb6] | 1487 | g_free(sd->call_id); |
---|
| 1488 | sd->call_id = 0; |
---|
[5ebff60] | 1489 | } else { |
---|
[71c4bb6] | 1490 | imcb_error(ic, "There are no active calls currently."); |
---|
[5ebff60] | 1491 | } |
---|
[71c4bb6] | 1492 | } |
---|
| 1493 | |
---|
[5adcc65] | 1494 | static char *skype_set_call(set_t *set, char *value) |
---|
[b68b023] | 1495 | { |
---|
| 1496 | account_t *acc = set->data; |
---|
| 1497 | struct im_connection *ic = acc->ic; |
---|
| 1498 | |
---|
[5ebff60] | 1499 | if (value) { |
---|
[451f121] | 1500 | skype_call(ic, value); |
---|
[5ebff60] | 1501 | } else { |
---|
[71c4bb6] | 1502 | skype_hangup(ic); |
---|
[5ebff60] | 1503 | } |
---|
[5adcc65] | 1504 | return value; |
---|
[b68b023] | 1505 | } |
---|
| 1506 | |
---|
[5adcc65] | 1507 | static void skype_add_buddy(struct im_connection *ic, char *who, char *group) |
---|
[f06e3ac] | 1508 | { |
---|
[46641bf] | 1509 | struct skype_data *sd = ic->proto_data; |
---|
[1f4fc80] | 1510 | char *nick, *ptr; |
---|
[6627d92] | 1511 | |
---|
[cbec0d6] | 1512 | nick = g_strdup(who); |
---|
[6627d92] | 1513 | ptr = strchr(nick, '@'); |
---|
[5ebff60] | 1514 | if (ptr) { |
---|
[6627d92] | 1515 | *ptr = '\0'; |
---|
[5ebff60] | 1516 | } |
---|
[46e9822] | 1517 | |
---|
| 1518 | if (!group) { |
---|
| 1519 | skype_printf(ic, "SET USER %s BUDDYSTATUS 2 Please authorize me\n", |
---|
[5ebff60] | 1520 | nick); |
---|
[46e9822] | 1521 | g_free(nick); |
---|
| 1522 | } else { |
---|
| 1523 | struct skype_group *sg = skype_group_by_name(ic, group); |
---|
| 1524 | |
---|
| 1525 | if (!sg) { |
---|
| 1526 | /* No such group, we need to create it, then have to |
---|
| 1527 | * add the user once it's created. */ |
---|
[5a0ffa2] | 1528 | skype_printf(ic, "CREATE GROUP %s\n", group); |
---|
[46641bf] | 1529 | sd->pending_user = g_strdup(nick); |
---|
[46e9822] | 1530 | } else { |
---|
[5a0ffa2] | 1531 | skype_printf(ic, "ALTER GROUP %d ADDUSER %s\n", sg->id, nick); |
---|
[46e9822] | 1532 | } |
---|
| 1533 | } |
---|
[f06e3ac] | 1534 | } |
---|
| 1535 | |
---|
[5adcc65] | 1536 | static void skype_remove_buddy(struct im_connection *ic, char *who, char *group) |
---|
[f06e3ac] | 1537 | { |
---|
[1f4fc80] | 1538 | char *nick, *ptr; |
---|
[6627d92] | 1539 | |
---|
[4ae3ffc] | 1540 | /* Unused parameter */ |
---|
| 1541 | group = group; |
---|
| 1542 | |
---|
[cbec0d6] | 1543 | nick = g_strdup(who); |
---|
[6627d92] | 1544 | ptr = strchr(nick, '@'); |
---|
[5ebff60] | 1545 | if (ptr) { |
---|
[6627d92] | 1546 | *ptr = '\0'; |
---|
[5ebff60] | 1547 | } |
---|
[1f4fc80] | 1548 | skype_printf(ic, "SET USER %s BUDDYSTATUS 1\n", nick); |
---|
[6627d92] | 1549 | g_free(nick); |
---|
[f06e3ac] | 1550 | } |
---|
| 1551 | |
---|
[5adcc65] | 1552 | void skype_chat_msg(struct groupchat *gc, char *message, int flags) |
---|
[66c9558] | 1553 | { |
---|
[79e20f9] | 1554 | struct im_connection *ic = gc->ic; |
---|
[4ae3ffc] | 1555 | |
---|
| 1556 | /* Unused parameter */ |
---|
| 1557 | flags = flags; |
---|
| 1558 | |
---|
[1f4fc80] | 1559 | skype_printf(ic, "CHATMESSAGE %s %s\n", gc->title, message); |
---|
[66c9558] | 1560 | } |
---|
| 1561 | |
---|
[5adcc65] | 1562 | void skype_chat_leave(struct groupchat *gc) |
---|
[b01dc6c] | 1563 | { |
---|
| 1564 | struct im_connection *ic = gc->ic; |
---|
[5ebff60] | 1565 | |
---|
[1f4fc80] | 1566 | skype_printf(ic, "ALTER CHAT %s LEAVE\n", gc->title); |
---|
[5ebff60] | 1567 | gc->data = (void *) TRUE; |
---|
[760319d] | 1568 | } |
---|
| 1569 | |
---|
| 1570 | void skype_chat_invite(struct groupchat *gc, char *who, char *message) |
---|
| 1571 | { |
---|
| 1572 | struct im_connection *ic = gc->ic; |
---|
[1f4fc80] | 1573 | char *ptr, *nick; |
---|
[4ae3ffc] | 1574 | |
---|
[17dd2ed] | 1575 | nick = g_strdup(who); |
---|
[760319d] | 1576 | ptr = strchr(nick, '@'); |
---|
[5ebff60] | 1577 | if (ptr) { |
---|
[760319d] | 1578 | *ptr = '\0'; |
---|
[5ebff60] | 1579 | } |
---|
[1f4fc80] | 1580 | skype_printf(ic, "ALTER CHAT %s ADDMEMBERS %s\n", gc->title, nick); |
---|
[760319d] | 1581 | g_free(nick); |
---|
[b01dc6c] | 1582 | } |
---|
| 1583 | |
---|
[09e2a69] | 1584 | void skype_chat_topic(struct groupchat *gc, char *message) |
---|
| 1585 | { |
---|
| 1586 | struct im_connection *ic = gc->ic; |
---|
[a5f76a2] | 1587 | struct skype_data *sd = ic->proto_data; |
---|
[5ebff60] | 1588 | |
---|
[1f4fc80] | 1589 | skype_printf(ic, "ALTER CHAT %s SETTOPIC %s\n", |
---|
[5ebff60] | 1590 | gc->title, message); |
---|
[a5f76a2] | 1591 | sd->topic_wait = 1; |
---|
[09e2a69] | 1592 | } |
---|
| 1593 | |
---|
[86278cd] | 1594 | struct groupchat *skype_chat_with(struct im_connection *ic, char *who) |
---|
| 1595 | { |
---|
| 1596 | struct skype_data *sd = ic->proto_data; |
---|
[1f4fc80] | 1597 | char *ptr, *nick; |
---|
[5ebff60] | 1598 | |
---|
[86278cd] | 1599 | nick = g_strdup(who); |
---|
| 1600 | ptr = strchr(nick, '@'); |
---|
[5ebff60] | 1601 | if (ptr) { |
---|
[86278cd] | 1602 | *ptr = '\0'; |
---|
[5ebff60] | 1603 | } |
---|
[1f4fc80] | 1604 | skype_printf(ic, "CHAT CREATE %s\n", nick); |
---|
[86278cd] | 1605 | sd->groupchat_with = g_strdup(nick); |
---|
| 1606 | g_free(nick); |
---|
[5652d43] | 1607 | /* We create a fake chat for now. We will replace it with a real one in |
---|
| 1608 | * the real callback. */ |
---|
[5adcc65] | 1609 | return imcb_chat_new(ic, ""); |
---|
[86278cd] | 1610 | } |
---|
| 1611 | |
---|
[67454bd] | 1612 | static void skype_get_info(struct im_connection *ic, char *who) |
---|
| 1613 | { |
---|
[36f6ab3] | 1614 | struct skype_data *sd = ic->proto_data; |
---|
[1f4fc80] | 1615 | char *ptr, *nick; |
---|
[5ebff60] | 1616 | |
---|
[67454bd] | 1617 | nick = g_strdup(who); |
---|
| 1618 | ptr = strchr(nick, '@'); |
---|
[5ebff60] | 1619 | if (ptr) { |
---|
[67454bd] | 1620 | *ptr = '\0'; |
---|
[5ebff60] | 1621 | } |
---|
[36f6ab3] | 1622 | sd->is_info = TRUE; |
---|
[1f4fc80] | 1623 | skype_printf(ic, "GET USER %s FULLNAME\n", nick); |
---|
| 1624 | skype_printf(ic, "GET USER %s PHONE_HOME\n", nick); |
---|
| 1625 | skype_printf(ic, "GET USER %s PHONE_OFFICE\n", nick); |
---|
| 1626 | skype_printf(ic, "GET USER %s PHONE_MOBILE\n", nick); |
---|
| 1627 | skype_printf(ic, "GET USER %s NROF_AUTHED_BUDDIES\n", nick); |
---|
| 1628 | skype_printf(ic, "GET USER %s TIMEZONE\n", nick); |
---|
| 1629 | skype_printf(ic, "GET USER %s LASTONLINETIMESTAMP\n", nick); |
---|
| 1630 | skype_printf(ic, "GET USER %s SEX\n", nick); |
---|
| 1631 | skype_printf(ic, "GET USER %s LANGUAGE\n", nick); |
---|
| 1632 | skype_printf(ic, "GET USER %s COUNTRY\n", nick); |
---|
| 1633 | skype_printf(ic, "GET USER %s PROVINCE\n", nick); |
---|
| 1634 | skype_printf(ic, "GET USER %s CITY\n", nick); |
---|
| 1635 | skype_printf(ic, "GET USER %s HOMEPAGE\n", nick); |
---|
| 1636 | skype_printf(ic, "GET USER %s ABOUT\n", nick); |
---|
[85341dd] | 1637 | /* |
---|
| 1638 | * Hack: we query the bithday property which is always a single line, |
---|
| 1639 | * so we can send the collected properties to the user when we have |
---|
| 1640 | * this one. |
---|
| 1641 | */ |
---|
| 1642 | skype_printf(ic, "GET USER %s BIRTHDAY\n", nick); |
---|
[67454bd] | 1643 | } |
---|
| 1644 | |
---|
[5adcc65] | 1645 | static void skype_init(account_t *acc) |
---|
[93dffea] | 1646 | { |
---|
| 1647 | set_t *s; |
---|
| 1648 | |
---|
[8c09bb3] | 1649 | s = set_add(&acc->set, "server", SKYPE_DEFAULT_SERVER, set_eval_account, |
---|
[5ebff60] | 1650 | acc); |
---|
[93dffea] | 1651 | s->flags |= ACC_SET_OFFLINE_ONLY; |
---|
| 1652 | |
---|
[5adcc65] | 1653 | s = set_add(&acc->set, "port", SKYPE_DEFAULT_PORT, set_eval_int, acc); |
---|
[93dffea] | 1654 | s->flags |= ACC_SET_OFFLINE_ONLY; |
---|
| 1655 | |
---|
[8c09bb3] | 1656 | s = set_add(&acc->set, "display_name", NULL, skype_set_display_name, |
---|
[5ebff60] | 1657 | acc); |
---|
[bb5ce568] | 1658 | s->flags |= SET_NOSAVE | ACC_SET_ONLINE_ONLY; |
---|
[b68b023] | 1659 | |
---|
[7764fb1] | 1660 | s = set_add(&acc->set, "mood_text", NULL, skype_set_mood_text, acc); |
---|
[c2a863d] | 1661 | s->flags |= SET_NOSAVE | ACC_SET_ONLINE_ONLY; |
---|
[7764fb1] | 1662 | |
---|
[5adcc65] | 1663 | s = set_add(&acc->set, "call", NULL, skype_set_call, acc); |
---|
[bb5ce568] | 1664 | s->flags |= SET_NOSAVE | ACC_SET_ONLINE_ONLY; |
---|
[2af671a] | 1665 | |
---|
[5adcc65] | 1666 | s = set_add(&acc->set, "balance", NULL, skype_set_balance, acc); |
---|
[bb5ce568] | 1667 | s->flags |= SET_NOSAVE | ACC_SET_ONLINE_ONLY; |
---|
[bd417a1] | 1668 | |
---|
[5adcc65] | 1669 | s = set_add(&acc->set, "skypeout_offline", "true", set_eval_bool, acc); |
---|
[08a355b] | 1670 | |
---|
[5adcc65] | 1671 | s = set_add(&acc->set, "skypeconsole", "false", set_eval_bool, acc); |
---|
[08a355b] | 1672 | s->flags |= ACC_SET_OFFLINE_ONLY; |
---|
[5acf9ab] | 1673 | |
---|
[8c09bb3] | 1674 | s = set_add(&acc->set, "skypeconsole_receive", "false", set_eval_bool, |
---|
[5ebff60] | 1675 | acc); |
---|
[b820226] | 1676 | s->flags |= ACC_SET_OFFLINE_ONLY; |
---|
| 1677 | |
---|
[5adcc65] | 1678 | s = set_add(&acc->set, "auto_join", "false", set_eval_bool, acc); |
---|
[5acf9ab] | 1679 | s->flags |= ACC_SET_OFFLINE_ONLY; |
---|
[f4d37c6] | 1680 | |
---|
[49a3c02] | 1681 | s = set_add(&acc->set, "test_join", "false", set_eval_bool, acc); |
---|
| 1682 | s->flags |= ACC_SET_OFFLINE_ONLY; |
---|
| 1683 | |
---|
[304aa33] | 1684 | s = set_add(&acc->set, "show_moods", "false", set_eval_bool, acc); |
---|
| 1685 | |
---|
[f4d37c6] | 1686 | s = set_add(&acc->set, "edit_prefix", "EDIT:", |
---|
[5ebff60] | 1687 | NULL, acc); |
---|
[3c7af69] | 1688 | |
---|
| 1689 | s = set_add(&acc->set, "read_groups", "false", set_eval_bool, acc); |
---|
[93dffea] | 1690 | } |
---|
| 1691 | |
---|
[c6e0218] | 1692 | #if BITLBEE_VERSION_CODE > BITLBEE_VER(3, 0, 1) |
---|
[fbb15f2] | 1693 | GList *skype_buddy_action_list(bee_user_t *bu) |
---|
[71c4bb6] | 1694 | { |
---|
[fbb15f2] | 1695 | static GList *ret; |
---|
[71c4bb6] | 1696 | |
---|
[a5e6aa1] | 1697 | /* Unused parameter */ |
---|
| 1698 | bu = bu; |
---|
| 1699 | |
---|
[fbb15f2] | 1700 | if (ret == NULL) { |
---|
[c7336ba] | 1701 | static const struct buddy_action ba[2] = { |
---|
[5ebff60] | 1702 | { "CALL", "Initiate a call" }, |
---|
| 1703 | { "HANGUP", "Hang up a call" }, |
---|
[71c4bb6] | 1704 | }; |
---|
[c7336ba] | 1705 | int i; |
---|
[71c4bb6] | 1706 | |
---|
[5ebff60] | 1707 | for (i = 0; i < ARRAY_SIZE(ba); i++) { |
---|
| 1708 | ret = g_list_prepend(ret, (void *) (ba + i)); |
---|
| 1709 | } |
---|
[71c4bb6] | 1710 | } |
---|
| 1711 | |
---|
| 1712 | return ret; |
---|
| 1713 | } |
---|
| 1714 | |
---|
[fbb15f2] | 1715 | void *skype_buddy_action(struct bee_user *bu, const char *action, char * const args[], void *data) |
---|
[71c4bb6] | 1716 | { |
---|
[a5e6aa1] | 1717 | /* Unused parameters */ |
---|
| 1718 | args = args; |
---|
| 1719 | data = data; |
---|
| 1720 | |
---|
[5ebff60] | 1721 | if (!g_strcasecmp(action, "CALL")) { |
---|
[71c4bb6] | 1722 | skype_call(bu->ic, bu->handle); |
---|
[5ebff60] | 1723 | } else if (!g_strcasecmp(action, "HANGUP")) { |
---|
[71c4bb6] | 1724 | skype_hangup(bu->ic); |
---|
[5ebff60] | 1725 | } |
---|
[71c4bb6] | 1726 | |
---|
| 1727 | return NULL; |
---|
| 1728 | } |
---|
| 1729 | #endif |
---|
| 1730 | |
---|
[f06e3ac] | 1731 | void init_plugin(void) |
---|
| 1732 | { |
---|
[5adcc65] | 1733 | struct prpl *ret = g_new0(struct prpl, 1); |
---|
[f06e3ac] | 1734 | |
---|
| 1735 | ret->name = "skype"; |
---|
| 1736 | ret->login = skype_login; |
---|
| 1737 | ret->init = skype_init; |
---|
| 1738 | ret->logout = skype_logout; |
---|
[93ece66] | 1739 | ret->buddy_msg = skype_buddy_msg; |
---|
[67454bd] | 1740 | ret->get_info = skype_get_info; |
---|
[f06e3ac] | 1741 | ret->away_states = skype_away_states; |
---|
[7daec06] | 1742 | ret->set_away = skype_set_away; |
---|
[f06e3ac] | 1743 | ret->add_buddy = skype_add_buddy; |
---|
| 1744 | ret->remove_buddy = skype_remove_buddy; |
---|
[66c9558] | 1745 | ret->chat_msg = skype_chat_msg; |
---|
[b01dc6c] | 1746 | ret->chat_leave = skype_chat_leave; |
---|
[760319d] | 1747 | ret->chat_invite = skype_chat_invite; |
---|
[86278cd] | 1748 | ret->chat_with = skype_chat_with; |
---|
[f06e3ac] | 1749 | ret->handle_cmp = g_strcasecmp; |
---|
[09e2a69] | 1750 | ret->chat_topic = skype_chat_topic; |
---|
[c6e0218] | 1751 | #if BITLBEE_VERSION_CODE > BITLBEE_VER(3, 0, 1) |
---|
[71c4bb6] | 1752 | ret->buddy_action_list = skype_buddy_action_list; |
---|
| 1753 | ret->buddy_action = skype_buddy_action; |
---|
| 1754 | #endif |
---|
[5adcc65] | 1755 | register_protocol(ret); |
---|
[f06e3ac] | 1756 | } |
---|