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