- Timestamp:
- 2006-07-19T16:52:38Z (18 years ago)
- Branches:
- master
- Children:
- d3a672c
- Parents:
- 04026d4
- Location:
- lib
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/events.h
r04026d4 r0aaca60 20 20 */ 21 21 22 /* 23 * Split off the event handling things from proxy.[ch] (and adding timer 24 * stuff. This to allow BitlBee to use other libs than GLib for event 25 * handling. 26 */ 22 /* This stuff used to be in proxy.c too, but I split it off so BitlBee can 23 use other libraries (like libevent) to handle events. proxy.c is one very 24 nice piece of work from Gaim. It connects to a TCP server in the back- 25 ground and calls a callback function once the connection is ready to use. 26 This function (proxy_connect()) can be found in proxy.c. (It also 27 transparently handles HTTP/SOCKS proxies, when necessary.) 28 29 This file offers some extra event handling toys, which will be handled 30 by GLib or libevent. The advantage of using libevent is that it can use 31 more advanced I/O polling functions like epoll() in recent Linux 32 kernels. This should improve BitlBee's scalability. */ 27 33 28 34 … … 39 45 #include <gmodule.h> 40 46 47 /* The conditions you can pass to gaim_input_add()/that will be passed to 48 the given callback function. */ 41 49 typedef enum { 42 50 GAIM_INPUT_READ = 1 << 1, … … 45 53 typedef gboolean (*b_event_handler)(gpointer data, gint fd, b_input_condition cond); 46 54 55 /* For internal use. */ 47 56 #define GAIM_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR) 48 57 #define GAIM_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL) … … 52 61 #define event_debug( x... ) 53 62 63 /* Call this once when the program starts. It'll initialize the event handler 64 library (if necessary) and then return immediately. */ 54 65 G_MODULE_EXPORT void b_main_init(); 66 67 /* This one enters the event loop. It shouldn't return until one of the event 68 handlers calls b_main_quit(). */ 55 69 G_MODULE_EXPORT void b_main_run(); 56 70 G_MODULE_EXPORT void b_main_quit(); 57 71 72 73 /* Add event handlers (for I/O or a timeout). The event handler will be called 74 every time the event "happens", until your event handler returns FALSE (or 75 until you remove it using b_event_remove(). As usual, the data argument 76 can be used to pass your own data to the event handler. */ 58 77 G_MODULE_EXPORT gint b_input_add(int fd, b_input_condition cond, b_event_handler func, gpointer data); 59 78 G_MODULE_EXPORT gint b_timeout_add(gint timeout, b_event_handler func, gpointer data); 60 79 G_MODULE_EXPORT void b_event_remove(gint id); 61 80 81 /* For now, closesocket() is only a function when using libevent. With GLib 82 it's a preprocessor macro. */ 62 83 #ifdef EVENTS_LIBEVENT 63 84 G_MODULE_EXPORT void closesocket(int fd); -
lib/http_client.h
r04026d4 r0aaca60 24 24 */ 25 25 26 /* http_client allows you to talk (asynchronously, again) to HTTP servers. 27 In the "background" it will send the whole query and wait for a complete 28 response to come back. Right now it's only used by the MSN Passport 29 authentication code, but it might be useful for other things too (for 30 example the AIM usericon patch uses this so icons can be stored on 31 webservers instead of the local filesystem). 32 33 Didn't test this too much, but it seems to work well. Just don't look 34 at the code that handles HTTP 30x redirects. ;-) The function is 35 probably not very useful for downloading lots of data since it keeps 36 everything in a memory buffer until the download is completed (and 37 can't pass any data or whatever before then). It's very useful for 38 doing quick requests without blocking the whole program, though. */ 39 26 40 #include <glib.h> 27 28 41 #include "ssl_client.h" 29 42 30 43 struct http_request; 31 44 45 /* Your callback function should look like this: */ 32 46 typedef void (*http_input_function)( struct http_request * ); 33 47 48 /* This structure will be filled in by the http_dorequest* functions, and 49 it will be passed to the callback function. Use the data field to add 50 your own data. */ 34 51 struct http_request 35 52 { 36 char *request; 37 int request_length; 38 int status_code; 39 char *status_string; 53 char *request; /* The request to send to the server. */ 54 int request_length; /* Its size. */ 55 int status_code; /* The numeric HTTP status code. (Or -1 56 if something really went wrong) */ 57 char *status_string; /* The error text. */ 40 58 char *reply_headers; 41 59 char *reply_body; 42 int body_size; 43 int finished; 60 int body_size; /* The number of bytes in reply_body. */ 61 int finished; /* Set to non-0 if the request was completed 62 successfully. */ 63 64 http_input_function func; 65 gpointer data; 66 67 /* Please don't touch the things down here, you shouldn't need them. */ 44 68 45 69 void *ssl; … … 49 73 int bytes_written; 50 74 int bytes_read; 51 52 http_input_function func;53 gpointer data;54 75 }; 55 76 77 /* The _url variant is probably more useful than the raw version. The raw 78 version is probably only useful if you want to do POST requests or if 79 you want to add some extra headers. As you can see, HTTPS connections 80 are also supported (using ssl_client). */ 56 81 void *http_dorequest( char *host, int port, int ssl, char *request, http_input_function func, gpointer data ); 57 82 void *http_dorequest_url( char *url_string, http_input_function func, gpointer data ); -
lib/rc4.h
r04026d4 r0aaca60 23 23 24 24 25 /* See rc4.c for more information. */ 26 25 27 struct rc4_state 26 28 { -
lib/ssl_client.h
r04026d4 r0aaca60 24 24 */ 25 25 26 /* ssl_client makes it easier to open SSL connections to servers. (It 27 doesn't offer SSL server functionality yet, but it could be useful 28 to add it later.) Different ssl_client modules are available, and 29 ssl_client tries to make them all behave the same. It's very simple 30 and basic, it just imitates the proxy_connect() function from the 31 Gaim libs and passes the socket to the program once the handshake 32 is completed. */ 33 26 34 #include <glib.h> 27 35 #include "proxy.h" 28 36 37 /* Some generic error codes. Especially SSL_AGAIN is important if you 38 want to do asynchronous I/O. */ 29 39 #define SSL_OK 0 30 40 #define SSL_NOHANDSHAKE 1 … … 33 43 extern int ssl_errno; 34 44 45 /* This is what your callback function should look like. */ 35 46 typedef gboolean (*ssl_input_function)(gpointer, void*, b_input_condition); 36 47 48 49 /* Connect to host:port, call the given function when the connection is 50 ready to be used for SSL traffic. This is all done asynchronously, no 51 blocking I/O! (Except for the DNS lookups, for now...) */ 37 52 G_MODULE_EXPORT void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data ); 53 54 /* Obviously you need special read/write functions to read data. */ 38 55 G_MODULE_EXPORT int ssl_read( void *conn, char *buf, int len ); 39 56 G_MODULE_EXPORT int ssl_write( void *conn, const char *buf, int len ); 57 58 /* Abort the SSL connection and disconnect the socket. Do not use close() 59 directly, both the SSL library and the peer will be unhappy! */ 40 60 G_MODULE_EXPORT void ssl_disconnect( void *conn_ ); 61 62 /* Get the fd for this connection, you will usually need it for event 63 handling. */ 41 64 G_MODULE_EXPORT int ssl_getfd( void *conn ); 65 66 /* This function returns GAIM_INPUT_READ/WRITE. With SSL connections it's 67 possible that something has to be read while actually were trying to 68 write something (think about key exchange/refresh/etc). So when an 69 SSL operation returned SSL_AGAIN, *always* use this function when 70 adding an event handler to the queue. (And it should perform exactly 71 the same action as the handler that just received the SSL_AGAIN.) */ 42 72 G_MODULE_EXPORT b_input_condition ssl_getdirection( void *conn );
Note: See TracChangeset
for help on using the changeset viewer.