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