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