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