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