- Timestamp:
- 2007-08-21T17:02:11Z (17 years ago)
- Branches:
- master
- Children:
- b8b0bfd
- Parents:
- dd8163e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
skype/skype.c
rdd8163e r7daec06 1 /* 2 * This is the most simple possible BitlBee plugin. To use, compile it as 3 * a shared library and place it in the plugin directory: 1 /* 2 * skype.c - Skype plugin for BitlBee 3 * 4 * Copyright (c) 2007 by Miklos Vajna <vmiklos@frugalware.org> 4 5 * 5 * gcc -o example.so -shared example.c `pkg-config --cflags bitlbee` 6 * cp example.so /usr/local/lib/bitlbee 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. 7 24 */ 25 8 26 #include <stdio.h> 9 27 #include <poll.h> … … 11 29 12 30 #define SKYPE_PORT_DEFAULT "2727" 31 32 /* 33 * Structures 34 */ 13 35 14 36 struct skype_data … … 20 42 int tx_len; 21 43 int r_inpa, w_inpa; 22 / / when we receive a new message id, we query the handle, then the body23 // store the handle here24 // TODO: it would be nicer to use a hashmap for this or something44 /* When we receive a new message id, we query the handle, then the 45 * body. Store the handle here so that we imcb_buddy_msg() when we got 46 * the body. */ 25 47 char *handle; 26 48 }; … … 31 53 char *full_name; 32 54 }; 55 56 struct skype_buddy_ask_data 57 { 58 struct im_connection *ic; 59 char *handle; 60 }; 61 62 /* 63 * Tables 64 */ 33 65 34 66 const struct skype_away_state skype_away_state_list[] = … … 44 76 }; 45 77 46 struct skype_buddy_ask_data 47 { 48 struct im_connection *ic; 49 char *handle; 50 }; 78 /* 79 * Functions 80 */ 51 81 52 82 static void skype_init( account_t *acc ) … … 69 99 pfd[0].events = POLLOUT; 70 100 101 /* This poll is necessary or we'll get a SIGPIPE when we write() to 102 * sd->fd. */ 71 103 poll(pfd, 1, 1000); 72 104 if(pfd[0].revents & POLLHUP) … … 76 108 return FALSE; 77 109 } 78 printf("write(): %s", buf);79 110 write( sd->fd, buf, len ); 80 111 … … 123 154 if( !sd || sd->fd == -1 ) 124 155 return FALSE; 156 /* Read the whole data. */ 125 157 st = read( sd->fd, buf, sizeof( buf ) ); 126 158 if( st > 0 ) 127 159 { 128 160 buf[st] = '\0'; 129 printf("read(): '%s'\n", buf);161 /* Then split it up to lines. */ 130 162 lines = g_strsplit(buf, "\n", 0); 131 163 lineptr = lines; … … 134 166 if(!strlen(line)) 135 167 break; 136 printf("skype_read_callback() new line: '%s'\n", line);137 168 if(!strncmp(line, "USERS ", 6)) 138 169 { … … 159 190 *ptr = '\0'; 160 191 ptr++; 161 if(!strncmp(ptr, "ONLINESTATUS ", 13) && strcmp(user, sd->username) != 0 && strcmp(user, "echo123") != 0) 192 if(!strncmp(ptr, "ONLINESTATUS ", 13) && 193 strcmp(user, sd->username) != 0 194 && strcmp(user, "echo123") != 0) 162 195 { 163 196 ptr = g_strdup_printf("%s@skype.com", user); … … 197 230 if(!strcmp(info, "STATUS RECEIVED")) 198 231 { 199 // new message, request its body 200 printf("new received message #%s\n", id); 232 /* New message ID: 233 * (1) Request its from field 234 * (2) Request its body 235 * (3) Mark it as seen 236 */ 201 237 g_snprintf(buf, 1024, "GET CHATMESSAGE %s FROM_HANDLE\n", id); 202 238 skype_write( ic, buf, strlen( buf ) ); … … 209 245 { 210 246 info += 12; 211 // new handle 247 /* New from field value. Store 248 * it, then we can later use it 249 * when we got the message's 250 * body. */ 212 251 sd->handle = g_strdup_printf("%s@skype.com", info); 213 printf("new handle: '%s'\n", info);214 252 } 215 253 else if(!strncmp(info, "BODY ", 5)) 216 254 { 217 255 info += 5; 218 // new body219 printf("<%s> %s\n", sd->handle, info);220 256 if(sd->handle) 257 { 258 /* New body, we have everything to use imcb_buddy_msg() now! */ 221 259 imcb_buddy_msg(ic, sd->handle, info, 0, 0); 222 g_free(sd->handle); 223 sd->handle = NULL; 260 g_free(sd->handle); 261 sd->handle = NULL; 262 } 224 263 } 225 264 } … … 238 277 return FALSE; 239 278 } 240 241 /* EAGAIN/etc or a successful read. */242 279 return TRUE; 243 280 } … … 255 292 sd->r_inpa = b_input_add( sd->fd, GAIM_INPUT_READ, skype_read_callback, ic ); 256 293 257 / / download buddies294 /* This will download all buddies. */ 258 295 buf = g_strdup_printf("SEARCH FRIENDS\n"); 259 296 st = skype_write( ic, buf, strlen( buf ) ); … … 280 317 281 318 imcb_log( ic, "Connecting" ); 282 printf("%s:%d\n", acc->server, set_getint( &acc->set, "port"));283 319 sd->fd = proxy_connect(acc->server, set_getint( &acc->set, "port" ), skype_connected, ic ); 284 printf("sd->fd: %d\n", sd->fd);285 /*imcb_add_buddy(ic, "test@skype.com", NULL);286 imcb_buddy_status(ic, "test@skype.com", OPT_LOGGED_IN, NULL, NULL);287 imcb_buddy_msg(ic, "test@skype.com", "test from skype plugin", 0, 0);*/288 320 sd->username = g_strdup( acc->user ); 289 321 … … 343 375 else 344 376 state = skype_away_state_by_name( state_txt ); 345 printf("would set to: '%s'\n", state->code);346 377 buf = g_strdup_printf("SET USERSTATUS %s\n", state->code); 347 378 skype_write( ic, buf, strlen( buf ) ); … … 370 401 buf = g_strdup_printf("SET USER %s BUDDYSTATUS 2 Please authorize me\n", nick); 371 402 skype_write( ic, buf, strlen( buf ) ); 372 printf("add '%s'\n", nick);373 403 g_free(nick); 374 404 } … … 384 414 buf = g_strdup_printf("SET USER %s BUDDYSTATUS 1\n", nick); 385 415 skype_write( ic, buf, strlen( buf ) ); 386 printf("remove '%s'\n", nick);387 416 g_free(nick); 388 417 } … … 397 426 ret->logout = skype_logout; 398 427 ret->buddy_msg = skype_buddy_msg; 428 ret->away_states = skype_away_states; 399 429 ret->set_away = skype_set_away; 400 ret->away_states = skype_away_states;401 430 ret->add_buddy = skype_add_buddy; 402 431 ret->remove_buddy = skype_remove_buddy;
Note: See TracChangeset
for help on using the changeset viewer.