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