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