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