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