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