Changeset 7c0a497
- Timestamp:
- 2005-12-17T20:56:50Z (19 years ago)
- Branches:
- master
- Children:
- a03a9f3
- Parents:
- b5a22e3 (diff), ad8b8a3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Files:
-
- 2 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/Makefile
rb5a22e3 r7c0a497 10 10 11 11 # [SH] Program variables 12 objects = md5.o nogaim.o proxy.o sha.o util.o $(SSL_CLIENT)12 objects = http_client.o md5.o nogaim.o proxy.o sha.o $(SSL_CLIENT) util.o 13 13 14 14 # [SH] The next two lines should contain the directory name (in $(subdirs)) -
protocols/msn/ns.c
rb5a22e3 r7c0a497 208 208 { 209 209 /* Time for some Passport black magic... */ 210 if( !passport_get_id( gc, gc->username, gc->password, cmd[4], msn_auth_got_passport_id) )210 if( !passport_get_id( msn_auth_got_passport_id, gc, gc->username, gc->password, cmd[4] ) ) 211 211 { 212 212 hide_login_progress_error( gc, "Error while contacting Passport server" ); -
protocols/msn/passport.c
rb5a22e3 r7c0a497 20 20 */ 21 21 22 #include " ssl_client.h"22 #include "http_client.h" 23 23 #include "passport.h" 24 24 #include "msn.h" … … 31 31 static char *prd_cached = NULL; 32 32 33 static char *passport_create_header( char *reply, char *email, char *pwd ); 33 static int passport_get_id_real( gpointer func, gpointer data, char *header ); 34 static void passport_get_id_ready( struct http_request *req ); 35 34 36 static int passport_retrieve_dalogin( gpointer data, gpointer func, char *header ); 35 static void passport_retrieve_dalogin_ connected( gpointer data, void *ssl, GaimInputCondition cond);36 static int passport_get_id_from( gpointer data, gpointer func, char *header_i, char *url ); 37 static void passport_get_id_connected( gpointer data, void *ssl, GaimInputCondition cond );37 static void passport_retrieve_dalogin_ready( struct http_request *req ); 38 39 static char *passport_create_header( char *cookie, char *email, char *pwd ); 38 40 static void destroy_reply( struct passport_reply *rep ); 39 41 40 41 int passport_get_id( gpointer data, char *username, char *password, char *cookie, gpointer func ) 42 int passport_get_id( gpointer func, gpointer data, char *username, char *password, char *cookie ) 42 43 { 43 44 char *header = passport_create_header( cookie, username, password ); 44 45 45 if( prd_cached ) 46 { 47 int st; 48 49 st = passport_get_id_from( data, func, header, prd_cached ); 50 g_free( header ); 51 return( st ); 52 } 46 if( prd_cached == NULL ) 47 return passport_retrieve_dalogin( func, data, header ); 53 48 else 54 { 55 return( passport_retrieve_dalogin( data, func, header ) ); 56 } 57 } 58 59 60 static char *passport_create_header( char *reply, char *email, char *pwd ) 61 { 62 char *buffer = g_new0( char, 2048 ); 63 char *currenttoken; 64 char *email_enc, *pwd_enc; 65 66 email_enc = g_new0( char, strlen( email ) * 3 + 1 ); 67 strcpy( email_enc, email ); 68 http_encode( email_enc ); 69 70 pwd_enc = g_new0( char, strlen( pwd ) * 3 + 1 ); 71 strcpy( pwd_enc, pwd ); 72 http_encode( pwd_enc ); 73 74 currenttoken = strstr( reply, "lc=" ); 75 if( currenttoken == NULL ) 76 return( NULL ); 77 78 g_snprintf( buffer, 2048, 79 "Authorization: Passport1.4 OrgVerb=GET," 80 "OrgURL=http%%3A%%2F%%2Fmessenger%%2Emsn%%2Ecom," 81 "sign-in=%s,pwd=%s,%s", email_enc, pwd_enc, 82 currenttoken ); 83 84 g_free( email_enc ); 85 g_free( pwd_enc ); 86 87 return( buffer ); 88 } 89 90 91 static int passport_retrieve_dalogin( gpointer data, gpointer func, char *header ) 92 { 93 struct passport_reply *rep = g_new0( struct passport_reply, 1 ); 94 void *ssl; 95 49 return passport_get_id_real( func, data, header ); 50 } 51 52 static int passport_get_id_real( gpointer func, gpointer data, char *header ) 53 { 54 struct passport_reply *rep; 55 char *server, *dummy, *reqs; 56 struct http_request *req; 57 58 rep = g_new0( struct passport_reply, 1 ); 96 59 rep->data = data; 97 60 rep->func = func; 98 rep->header = header; 99 100 ssl = ssl_connect( "nexus.passport.com", 443, passport_retrieve_dalogin_connected, rep ); 101 102 if( !ssl ) 103 destroy_reply( rep ); 104 105 return( ssl != NULL ); 106 } 107 108 #define PPR_BUFFERSIZE 2048 109 #define PPR_REQUEST "GET /rdr/pprdr.asp HTTP/1.0\r\n\r\n" 110 static void passport_retrieve_dalogin_connected( gpointer data, void *ssl, GaimInputCondition cond ) 111 { 112 int ret; 113 char buffer[PPR_BUFFERSIZE+1]; 114 struct passport_reply *rep = data; 61 62 server = g_strdup( prd_cached ); 63 dummy = strchr( server, '/' ); 64 65 if( dummy == NULL ) 66 { 67 destroy_reply( rep ); 68 return( 0 ); 69 } 70 71 reqs = g_malloc( strlen( header ) + strlen( dummy ) + 128 ); 72 sprintf( reqs, "GET %s HTTP/1.0\r\n%s\r\n\r\n", dummy, header ); 73 74 *dummy = 0; 75 req = http_dorequest( server, 443, 1, reqs, passport_get_id_ready, rep ); 76 77 g_free( server ); 78 g_free( reqs ); 79 80 if( req == NULL ) 81 destroy_reply( rep ); 82 83 return( req != NULL ); 84 } 85 86 static void passport_get_id_ready( struct http_request *req ) 87 { 88 struct passport_reply *rep = req->data; 115 89 116 90 if( !g_slist_find( msn_connections, rep->data ) ) 117 91 { 118 if( ssl ) ssl_disconnect( ssl );119 92 destroy_reply( rep ); 120 93 return; 121 94 } 122 95 123 if( !ssl ) 124 { 125 rep->func( rep ); 126 destroy_reply( rep ); 127 return; 128 } 129 130 ssl_write( ssl, PPR_REQUEST, strlen( PPR_REQUEST ) ); 131 132 if( ( ret = ssl_read( ssl, buffer, PPR_BUFFERSIZE ) ) <= 0 ) 133 { 134 goto failure; 135 } 136 137 { 138 char *dalogin = strstr( buffer, "DALogin=" ); 139 char *urlend; 96 if( req->status_code == 200 ) 97 { 98 char *dummy; 140 99 141 if( !dalogin ) 142 goto failure; 143 144 dalogin += strlen( "DALogin=" ); 145 urlend = strchr( dalogin, ',' ); 146 if( urlend ) 147 *urlend = 0; 148 149 /* strip the http(s):// part from the url */ 150 urlend = strstr( urlend, "://" ); 151 if( urlend ) 152 dalogin = urlend + strlen( "://" ); 153 154 if( prd_cached == NULL ) 155 prd_cached = g_strdup( dalogin ); 156 } 157 158 if( passport_get_id_from( rep->data, rep->func, rep->header, prd_cached ) ) 159 { 160 ssl_disconnect( ssl ); 161 destroy_reply( rep ); 162 return; 163 } 164 165 failure: 166 ssl_disconnect( ssl ); 167 rep->func( rep ); 168 destroy_reply( rep ); 169 } 170 171 172 static int passport_get_id_from( gpointer data, gpointer func, char *header_i, char *url ) 173 { 174 struct passport_reply *rep = g_new0( struct passport_reply, 1 ); 175 char server[512], *dummy; 176 void *ssl; 177 178 rep->data = data; 179 rep->func = func; 180 rep->redirects = 4; 181 182 strncpy( server, url, 512 ); 183 dummy = strchr( server, '/' ); 184 if( dummy ) 185 *dummy = 0; 186 187 ssl = ssl_connect( server, 443, passport_get_id_connected, rep ); 188 189 if( ssl ) 190 { 191 rep->header = g_strdup( header_i ); 192 rep->url = g_strdup( url ); 193 } 194 else 195 { 196 destroy_reply( rep ); 197 } 198 199 return( ssl != NULL ); 200 } 201 202 #define PPG_BUFFERSIZE 4096 203 static void passport_get_id_connected( gpointer data, void *ssl, GaimInputCondition cond ) 204 { 205 struct passport_reply *rep = data; 206 char server[512], buffer[PPG_BUFFERSIZE+1], *dummy; 207 int ret; 208 209 if( !g_slist_find( msn_connections, rep->data ) ) 210 { 211 if( ssl ) ssl_disconnect( ssl ); 212 destroy_reply( rep ); 213 return; 214 } 215 216 if( !ssl ) 217 { 218 rep->func( rep ); 219 destroy_reply( rep ); 220 return; 221 } 222 223 memset( buffer, 0, PPG_BUFFERSIZE + 1 ); 224 225 strncpy( server, rep->url, 512 ); 226 dummy = strchr( server, '/' ); 227 if( dummy == NULL ) 228 goto end; 229 230 g_snprintf( buffer, PPG_BUFFERSIZE - 1, "GET %s HTTP/1.0\r\n" 231 "%s\r\n\r\n", dummy, rep->header ); 232 233 ssl_write( ssl, buffer, strlen( buffer ) ); 234 memset( buffer, 0, PPG_BUFFERSIZE + 1 ); 235 236 { 237 char *buffer2 = buffer; 238 239 while( ( ( ret = ssl_read( ssl, buffer2, 512 ) ) > 0 ) && 240 ( buffer + PPG_BUFFERSIZE - buffer2 - ret - 512 >= 0 ) ) 241 { 242 buffer2 += ret; 243 } 244 } 245 246 if( *buffer == 0 ) 247 goto end; 248 249 if( ( dummy = strstr( buffer, "Location:" ) ) ) 250 { 251 char *urlend; 252 253 rep->redirects --; 254 if( rep->redirects == 0 ) 255 goto end; 256 257 dummy += strlen( "Location:" ); 258 while( isspace( *dummy ) ) dummy ++; 259 urlend = dummy; 260 while( !isspace( *urlend ) ) urlend ++; 261 *urlend = 0; 262 if( ( urlend = strstr( dummy, "://" ) ) ) 263 dummy = urlend + strlen( "://" ); 264 265 g_free( rep->url ); 266 rep->url = g_strdup( dummy ); 267 268 strncpy( server, dummy, sizeof( server ) - 1 ); 269 dummy = strchr( server, '/' ); 270 if( dummy ) *dummy = 0; 271 272 ssl_disconnect( ssl ); 273 274 if( ssl_connect( server, 443, passport_get_id_connected, rep ) ) 275 { 276 return; 277 } 278 else 279 { 280 rep->func( rep ); 281 destroy_reply( rep ); 282 return; 283 } 284 } 285 else if( strstr( buffer, "200 OK" ) ) 286 { 287 if( ( dummy = strstr( buffer, "from-PP='" ) ) ) 100 if( ( dummy = strstr( req->reply_headers, "from-PP='" ) ) ) 288 101 { 289 102 char *responseend; … … 298 111 } 299 112 300 end:301 ssl_disconnect( ssl );302 113 rep->func( rep ); 303 114 destroy_reply( rep ); 304 115 } 305 116 117 static char *passport_create_header( char *cookie, char *email, char *pwd ) 118 { 119 char *buffer = g_new0( char, 2048 ); 120 char *currenttoken; 121 char *email_enc, *pwd_enc; 122 123 email_enc = g_new0( char, strlen( email ) * 3 + 1 ); 124 strcpy( email_enc, email ); 125 http_encode( email_enc ); 126 127 pwd_enc = g_new0( char, strlen( pwd ) * 3 + 1 ); 128 strcpy( pwd_enc, pwd ); 129 http_encode( pwd_enc ); 130 131 currenttoken = strstr( cookie, "lc=" ); 132 if( currenttoken == NULL ) 133 return( NULL ); 134 135 g_snprintf( buffer, 2048, 136 "Authorization: Passport1.4 OrgVerb=GET," 137 "OrgURL=http%%3A%%2F%%2Fmessenger%%2Emsn%%2Ecom," 138 "sign-in=%s,pwd=%s,%s", email_enc, pwd_enc, 139 currenttoken ); 140 141 g_free( email_enc ); 142 g_free( pwd_enc ); 143 144 return( buffer ); 145 } 146 147 #define PPR_REQUEST "GET /rdr/pprdr.asp HTTP/1.0\r\n\r\n" 148 static int passport_retrieve_dalogin( gpointer func, gpointer data, char *header ) 149 { 150 struct passport_reply *rep = g_new0( struct passport_reply, 1 ); 151 struct http_request *req; 152 153 rep->data = data; 154 rep->func = func; 155 rep->header = header; 156 157 req = http_dorequest( "nexus.passport.com", 443, 1, PPR_REQUEST, passport_retrieve_dalogin_ready, rep ); 158 159 if( !req ) 160 destroy_reply( rep ); 161 162 return( req != NULL ); 163 } 164 165 static void passport_retrieve_dalogin_ready( struct http_request *req ) 166 { 167 struct passport_reply *rep = req->data; 168 char *dalogin; 169 char *urlend; 170 171 if( !g_slist_find( msn_connections, rep->data ) ) 172 { 173 destroy_reply( rep ); 174 return; 175 } 176 177 dalogin = strstr( req->reply_headers, "DALogin=" ); 178 179 if( !dalogin ) 180 goto failure; 181 182 dalogin += strlen( "DALogin=" ); 183 urlend = strchr( dalogin, ',' ); 184 if( urlend ) 185 *urlend = 0; 186 187 /* strip the http(s):// part from the url */ 188 urlend = strstr( urlend, "://" ); 189 if( urlend ) 190 dalogin = urlend + strlen( "://" ); 191 192 if( prd_cached == NULL ) 193 prd_cached = g_strdup( dalogin ); 194 195 if( passport_get_id_real( rep->func, rep->data, rep->header ) ) 196 { 197 destroy_reply( rep ); 198 return; 199 } 200 201 failure: 202 rep->func( rep ); 203 destroy_reply( rep ); 204 } 306 205 307 206 static void destroy_reply( struct passport_reply *rep ) 308 207 { 309 if( rep->result ) g_free( rep->result ); 310 if( rep->url ) g_free( rep->url ); 311 if( rep->header ) g_free( rep->header ); 312 if( rep ) g_free( rep ); 313 } 208 g_free( rep->result ); 209 g_free( rep->header ); 210 g_free( rep ); 211 } -
protocols/msn/passport.h
rb5a22e3 r7c0a497 35 35 struct passport_reply 36 36 { 37 void (*func)( struct passport_reply * ); 37 38 void *data; 38 39 char *result; 39 void (*func)( struct passport_reply * );40 char *url;41 40 char *header; 42 int redirects;43 41 }; 44 42 45 int passport_get_id( gpointer data, char *username, char *password, char *cookie, gpointer func);43 int passport_get_id( gpointer func, gpointer data, char *username, char *password, char *cookie ); 46 44 47 45 #endif /* __PASSPORT_H__ */ -
protocols/proxy.c
rb5a22e3 r7c0a497 106 106 if (condition & GAIM_WRITE_COND) 107 107 gaim_cond |= GAIM_INPUT_WRITE; 108 // if (condition & GAIM_ERR_COND)109 // fprintf( stderr, "ERROR! fd=%d\n", g_io_channel_unix_get_fd( source ) );110 108 111 109 closure->function(closure->data, g_io_channel_unix_get_fd(source), gaim_cond); -
protocols/ssl_bogus.c
rb5a22e3 r7c0a497 28 28 int ssl_errno; 29 29 30 void *ssl_connect( char *host, int port, SslInputFunction func, gpointer data )30 void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data ) 31 31 { 32 32 return( NULL ); -
protocols/ssl_client.h
rb5a22e3 r7c0a497 33 33 extern int ssl_errno; 34 34 35 typedef void (* SslInputFunction)(gpointer, void*, GaimInputCondition);35 typedef void (*ssl_input_function)(gpointer, void*, GaimInputCondition); 36 36 37 G_MODULE_EXPORT void *ssl_connect( char *host, int port, SslInputFunction func, gpointer data );37 G_MODULE_EXPORT void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data ); 38 38 G_MODULE_EXPORT int ssl_read( void *conn, char *buf, int len ); 39 39 G_MODULE_EXPORT int ssl_write( void *conn, const char *buf, int len ); 40 40 G_MODULE_EXPORT void ssl_disconnect( void *conn_ ); 41 41 G_MODULE_EXPORT int ssl_getfd( void *conn ); 42 G_MODULE_EXPORT GaimInputCondition ssl_getdirection( void *conn ); -
protocols/ssl_gnutls.c
rb5a22e3 r7c0a497 38 38 struct scd 39 39 { 40 SslInputFunction func;40 ssl_input_function func; 41 41 gpointer data; 42 42 int fd; … … 51 51 52 52 53 void *ssl_connect( char *host, int port, SslInputFunction func, gpointer data )53 void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data ) 54 54 { 55 55 struct scd *conn = g_new0( struct scd, 1 ); … … 117 117 if( st == GNUTLS_E_AGAIN || st == GNUTLS_E_INTERRUPTED ) 118 118 { 119 conn->inpa = gaim_input_add( conn->fd, 120 gnutls_record_get_direction( conn->session ) ? 121 GAIM_INPUT_WRITE : GAIM_INPUT_READ, 119 conn->inpa = gaim_input_add( conn->fd, ssl_getdirection( conn ), 122 120 ssl_handshake, data ); 123 121 } … … 145 143 int ssl_read( void *conn, char *buf, int len ) 146 144 { 145 int st; 146 147 147 if( !((struct scd*)conn)->established ) 148 148 { … … 151 151 } 152 152 153 return( gnutls_record_recv( ((struct scd*)conn)->session, buf, len ) ); 154 153 st = gnutls_record_recv( ((struct scd*)conn)->session, buf, len ); 154 155 ssl_errno = SSL_OK; 156 if( st == GNUTLS_E_AGAIN || st == GNUTLS_E_INTERRUPTED ) 157 ssl_errno = SSL_AGAIN; 158 159 return st; 155 160 } 156 161 157 162 int ssl_write( void *conn, const char *buf, int len ) 158 163 { 164 int st; 165 159 166 if( !((struct scd*)conn)->established ) 160 167 { … … 163 170 } 164 171 165 return( gnutls_record_send( ((struct scd*)conn)->session, buf, len ) ); 172 st = gnutls_record_send( ((struct scd*)conn)->session, buf, len ); 173 174 ssl_errno = SSL_OK; 175 if( st == GNUTLS_E_AGAIN || st == GNUTLS_E_INTERRUPTED ) 176 ssl_errno = SSL_AGAIN; 177 178 return st; 166 179 } 167 180 … … 184 197 return( ((struct scd*)conn)->fd ); 185 198 } 199 200 GaimInputCondition ssl_getdirection( void *conn ) 201 { 202 return( gnutls_record_get_direction( ((struct scd*)conn)->session ) ? 203 GAIM_INPUT_WRITE : GAIM_INPUT_READ ); 204 } -
protocols/ssl_nss.c
rb5a22e3 r7c0a497 45 45 struct scd 46 46 { 47 SslInputFunction func;47 ssl_input_function func; 48 48 gpointer data; 49 49 int fd; … … 91 91 92 92 93 void *ssl_connect( char *host, int port, SslInputFunction func, gpointer data )93 void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data ) 94 94 { 95 95 struct scd *conn = g_new0( struct scd, 1 ); -
protocols/ssl_openssl.c
rb5a22e3 r7c0a497 41 41 struct scd 42 42 { 43 SslInputFunction func;43 ssl_input_function func; 44 44 gpointer data; 45 45 int fd; … … 54 54 55 55 56 void *ssl_connect( char *host, int port, SslInputFunction func, gpointer data )56 void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data ) 57 57 { 58 58 struct scd *conn = g_new0( struct scd, 1 ); -
sock.h
rb5a22e3 r7c0a497 1 #include <errno.h> 2 #include <fcntl.h> 3 1 4 #ifndef _WIN32 2 5 #include <unistd.h> -
url.c
rb5a22e3 r7c0a497 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * 4 * Copyright 2001-200 4Wilmer van der Gaast and others *4 * Copyright 2001-2005 Wilmer van der Gaast and others * 5 5 \********************************************************************/ 6 6 … … 30 30 { 31 31 char s[MAX_STRING]; 32 char *i , *j;32 char *i; 33 33 34 34 /* protocol:// */ … … 40 40 else 41 41 { 42 if( g_strncasecmp( set_url, "http", i - set_url ) == 0 ) 42 if( g_strncasecmp( set_url, "https", i - set_url ) == 0 ) 43 url->proto = PROTO_HTTPS; 44 else if( g_strncasecmp( set_url, "http", i - set_url ) == 0 ) 43 45 url->proto = PROTO_HTTP; 44 46 else if( g_strncasecmp( set_url, "socks4", i - set_url ) == 0 ) … … 56 58 if( ( i = strchr( s, '/' ) ) == NULL ) 57 59 { 58 strcpy( url-> dir, "/" );60 strcpy( url->file, "/" ); 59 61 } 60 62 else 61 63 { 64 strncpy( url->file, i, MAX_STRING ); 62 65 *i = 0; 63 g_snprintf( url->dir, MAX_STRING, "/%s", i + 1 );64 if( url->proto == PROTO_HTTP )65 http_encode( url->dir );66 66 } 67 67 strncpy( url->host, s, MAX_STRING ); 68 j = strchr( url->dir, '?' );69 if( j != NULL )70 *j = 0;71 i = strrchr( url->dir, '/' );72 *i = 0;73 if( j != NULL )74 *j = '?';75 if( i == NULL )76 {77 strcpy( url->file, url->dir );78 strcpy( url->dir, "/" );79 }80 else81 {82 strcpy( url->file, i + 1 );83 strcat( url->dir, "/" );84 }85 68 86 69 /* Check for username in host field */ … … 96 79 else 97 80 { 98 if( url->proto == PROTO_FTP ) 99 { 100 strcpy( url->user, "anonymous" ); 101 strcpy( url->pass, "-p.artmaps@lintux.cx" ); 102 } 103 else 104 { 105 *url->user = *url->pass = 0; 106 } 81 *url->user = *url->pass = 0; 107 82 } 108 83 … … 117 92 { 118 93 *i = 0; 119 sscanf( i + 1, "% i", &url->port );94 sscanf( i + 1, "%d", &url->port ); 120 95 } 121 /* Take default port numbers from /etc/services */122 96 else 123 97 { 124 98 if( url->proto == PROTO_HTTP ) 125 url->port = 8080; 99 url->port = 80; 100 else if( url->proto == PROTO_HTTPS ) 101 url->port = 443; 126 102 else if( url->proto == PROTO_SOCKS4 || url->proto == PROTO_SOCKS4 ) 127 103 url->port = 1080; -
url.h
rb5a22e3 r7c0a497 26 26 #include "bitlbee.h" 27 27 28 #define PROTO_FTP 129 28 #define PROTO_HTTP 2 29 #define PROTO_HTTPS 5 30 30 #define PROTO_SOCKS4 3 31 31 #define PROTO_SOCKS5 4 … … 37 37 int port; 38 38 char host[MAX_STRING]; 39 char dir[MAX_STRING];40 39 char file[MAX_STRING]; 41 40 char user[MAX_STRING];
Note: See TracChangeset
for help on using the changeset viewer.