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