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