Changeset 9fd4241
- Timestamp:
- 2007-08-19T15:43:14Z (17 years ago)
- Branches:
- master
- Children:
- be975f8
- Parents:
- 1323e36
- Location:
- skype
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
skype/Makefile
r1323e36 r9fd4241 1 CFLAGS += $(shell pkg-config --cflags bitlbee) -g 1 CFLAGS += $(shell pkg-config --cflags bitlbee) -g -Wall 2 LDFLAGS += $(shell pkg-config --libs bitlbee) 2 3 3 4 skype.so: skype.c -
skype/skype.c
r1323e36 r9fd4241 20 20 }; 21 21 22 static gboolean skype_write_callback( gpointer data, gint fd, b_input_condition cond );23 static gboolean skype_write_queue( struct im_connection *ic );24 25 22 static void skype_init( account_t *acc ) 26 23 { … … 37 34 { 38 35 struct skype_data *sd = ic->proto_data; 39 gboolean ret; 40 41 if( sd->tx_len == 0 ) 42 { 43 sd->tx_len = len; 44 sd->txq = g_memdup( buf, len ); 45 if( ( ret = skype_write_queue( ic ) ) && sd->tx_len > 0 ) 46 sd->w_inpa = b_input_add( sd->fd, GAIM_INPUT_WRITE, skype_write_callback, ic ); 47 } 48 else 49 { 50 sd->txq = g_renew( char, sd->txq, sd->tx_len + len ); 51 memcpy( sd->txq + sd->tx_len, buf, len ); 52 sd->tx_len += len; 53 ret = TRUE; 54 } 55 return ret; 56 } 57 58 static gboolean skype_write_callback( gpointer data, gint fd, b_input_condition cond ) 59 { 60 struct skype_data *sd = ((struct im_connection *)data)->proto_data; 61 62 return sd->fd != -1 && 63 skype_write_queue( data ) && 64 sd->tx_len > 0; 36 37 printf("write(): %s", buf); 38 write( sd->fd, buf, len ); 39 40 // TODO: error handling 41 42 return TRUE; 65 43 } 66 44 … … 71 49 char buf[1024]; 72 50 int st; 51 char **lines, **lineptr, *line, *ptr; 73 52 74 53 if( sd->fd == -1 ) … … 79 58 buf[st] = '\0'; 80 59 printf("read(): '%s'\n", buf); 60 lines = g_strsplit(buf, "\n", 0); 61 lineptr = lines; 62 while((line = *lineptr)) 63 { 64 if(!strlen(line)) 65 break; 66 printf("skype_read_callback() new line: '%s'\n", line); 67 if(!strncmp(line, "USERS ", 6)) 68 { 69 char **i; 70 char **nicks; 71 72 nicks = g_strsplit(line + 6, ", ", 0); 73 i = nicks; 74 while(*i) 75 { 76 g_snprintf(buf, 1024, "GET USER %s ONLINESTATUS\n", *i); 77 skype_write( ic, buf, strlen( buf ) ); 78 i++; 79 } 80 g_strfreev(nicks); 81 } 82 else if(!strncmp(line, "USER ", 5)) 83 { 84 // TODO we should add the buddy even if the status is offline 85 if((ptr = strrchr(line, ' ')) && strcmp(++ptr, "OFFLINE") != 0) 86 { 87 char *user = strchr(line, ' '); 88 ptr = strchr(++user, ' '); 89 *ptr = '\0'; 90 ptr = g_strdup_printf("%s@skype.com", user); 91 imcb_add_buddy(ic, ptr, NULL); 92 imcb_buddy_status(ic, ptr, OPT_LOGGED_IN, NULL, NULL); 93 } 94 } 95 lineptr++; 96 } 97 g_strfreev(lines); 81 98 } 82 99 else if( st == 0 || ( st < 0 && !sockerr_again() ) ) … … 94 111 } 95 112 96 static gboolean skype_write_queue( struct im_connection *ic )97 {98 struct skype_data *sd = ic->proto_data;99 int st;100 101 printf("sd->fd: %d\n", sd->fd);102 st = write( sd->fd, sd->txq, sd->tx_len );103 104 if( st == sd->tx_len )105 {106 /* We wrote everything, clear the buffer. */107 g_free( sd->txq );108 sd->txq = NULL;109 sd->tx_len = 0;110 111 return TRUE;112 }113 else if( st == 0 || ( st < 0 && !sockerr_again() ) )114 {115 /* Set fd to -1 to make sure we won't write to it anymore. */116 closesocket( sd->fd ); /* Shouldn't be necessary after errors? */117 sd->fd = -1;118 119 imcb_error( ic, "Short write() to server" );120 imc_logout( ic, TRUE );121 return FALSE;122 }123 else if( st > 0 )124 {125 char *s;126 127 s = g_memdup( sd->txq + st, sd->tx_len - st );128 sd->tx_len -= st;129 g_free( sd->txq );130 sd->txq = s;131 132 return TRUE;133 }134 else135 {136 return TRUE;137 }138 }139 140 113 gboolean skype_start_stream( struct im_connection *ic ) 141 114 { … … 147 120 sd->r_inpa = b_input_add( sd->fd, GAIM_INPUT_READ, skype_read_callback, ic ); 148 121 149 buf = g_strdup_printf("SEARCH FRIENDS"); 122 // download buddies 123 buf = g_strdup_printf("SEARCH FRIENDS\n"); 150 124 st = skype_write( ic, buf, strlen( buf ) ); 151 125 g_free(buf); … … 163 137 imcb_error( ic, "Could not connect to server" ); 164 138 imc_logout( ic, TRUE ); 165 return ;139 return FALSE; 166 140 } 167 //imcb_add_buddy(ic, "vmiklos_dsd@skype.com", NULL);168 //imcb_buddy_status(ic, "vmiklos_dsd@skype.com", OPT_LOGGED_IN, NULL, NULL);169 141 return skype_start_stream(ic); 170 142 } … … 198 170 { 199 171 static GList *l = NULL; 200 int i;201 172 202 173 l = g_list_append( l, (void*)"Online" );
Note: See TracChangeset
for help on using the changeset viewer.