diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2010-10-09 11:41:19 -0700 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2010-10-09 11:41:19 -0700 |
commit | 619770237590e4a760346f2e12681d7e2220dda4 (patch) | |
tree | 8d0d391407280ab74e1fc876d6f272110b474897 /lib | |
parent | 23b29c67968f3dd39e7d6970acc5669556f4c8b9 (diff) | |
parent | 27b407fde1844a0e03f1a9d92d2a1c4a40435f9b (diff) |
Merging OTR branch. It's more or less a plugin if you enable it, and
otherwise a no-op. DO NOT INSTALL THIS ON PUBLIC SERVERS.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/events.h | 6 | ||||
-rw-r--r-- | lib/events_glib.c | 5 | ||||
-rw-r--r-- | lib/misc.c | 12 | ||||
-rw-r--r-- | lib/ssl_bogus.c | 9 | ||||
-rw-r--r-- | lib/ssl_client.h | 3 | ||||
-rw-r--r-- | lib/ssl_gnutls.c | 11 | ||||
-rw-r--r-- | lib/ssl_nss.c | 12 | ||||
-rw-r--r-- | lib/ssl_openssl.c | 12 |
8 files changed, 55 insertions, 15 deletions
diff --git a/lib/events.h b/lib/events.h index fa30cf27..66c4c6b4 100644 --- a/lib/events.h +++ b/lib/events.h @@ -80,10 +80,8 @@ G_MODULE_EXPORT gint b_input_add(int fd, b_input_condition cond, b_event_handler G_MODULE_EXPORT gint b_timeout_add(gint timeout, b_event_handler func, gpointer data); G_MODULE_EXPORT void b_event_remove(gint id); -/* For now, closesocket() is only a function when using libevent. With GLib - it's a preprocessor macro. */ -#ifdef EVENTS_LIBEVENT +/* With libevent, this one also cleans up event handlers if that wasn't already + done (the caller is expected to do so but may miss it sometimes). */ G_MODULE_EXPORT void closesocket(int fd); -#endif #endif /* _EVENTS_H_ */ diff --git a/lib/events_glib.c b/lib/events_glib.c index d6ac82cc..3fafc872 100644 --- a/lib/events_glib.c +++ b/lib/events_glib.c @@ -146,3 +146,8 @@ void b_event_remove(gint tag) if (tag > 0) g_source_remove(tag); } + +void closesocket( int fd ) +{ + close( fd ); +} @@ -156,6 +156,7 @@ void strip_html( char *in ) char out[strlen(in)+1]; char *s = out, *cs; int i, matched; + int taglen; memset( out, 0, sizeof( out ) ); @@ -172,9 +173,18 @@ void strip_html( char *in ) while( *in && *in != '>' ) in ++; + taglen = in - cs - 1; /* not <0 because the above loop runs at least once */ if( *in ) { - if( g_strncasecmp( cs+1, "br", 2) == 0 ) + if( g_strncasecmp( cs+1, "b", taglen) == 0 ) + *(s++) = '\x02'; + else if( g_strncasecmp( cs+1, "/b", taglen) == 0 ) + *(s++) = '\x02'; + else if( g_strncasecmp( cs+1, "i", taglen) == 0 ) + *(s++) = '\x1f'; + else if( g_strncasecmp( cs+1, "/i", taglen) == 0 ) + *(s++) = '\x1f'; + else if( g_strncasecmp( cs+1, "br", taglen) == 0 ) *(s++) = '\n'; in ++; } diff --git a/lib/ssl_bogus.c b/lib/ssl_bogus.c index 9c368c66..e7966f57 100644 --- a/lib/ssl_bogus.c +++ b/lib/ssl_bogus.c @@ -27,6 +27,10 @@ int ssl_errno; +void ssl_init( void ) +{ +} + void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data ) { return( NULL ); @@ -65,3 +69,8 @@ int ssl_pending( void *conn ) { return 0; } + +int ssl_pending( void *conn ) +{ + return 0; +} diff --git a/lib/ssl_client.h b/lib/ssl_client.h index 787d528a..d0340840 100644 --- a/lib/ssl_client.h +++ b/lib/ssl_client.h @@ -46,6 +46,9 @@ extern int ssl_errno; typedef gboolean (*ssl_input_function)(gpointer, void*, b_input_condition); +/* Perform any global initialization the SSL library might need. */ +G_MODULE_EXPORT void ssl_init( void ); + /* Connect to host:port, call the given function when the connection is ready to be used for SSL traffic. This is all done asynchronously, no blocking I/O! (Except for the DNS lookups, for now...) */ diff --git a/lib/ssl_gnutls.c b/lib/ssl_gnutls.c index 6e68791d..ee166bd1 100644 --- a/lib/ssl_gnutls.c +++ b/lib/ssl_gnutls.c @@ -60,6 +60,13 @@ static gboolean ssl_starttls_real( gpointer data, gint source, b_input_condition static gboolean ssl_handshake( gpointer data, gint source, b_input_condition cond ); +void ssl_init( void ) +{ + gnutls_global_init(); + initialized = TRUE; + atexit( gnutls_global_deinit ); +} + void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data ) { struct scd *conn = g_new0( struct scd, 1 ); @@ -121,9 +128,7 @@ static gboolean ssl_connected( gpointer data, gint source, b_input_condition con if( !initialized ) { - gnutls_global_init(); - initialized = TRUE; - atexit( gnutls_global_deinit ); + ssl_init(); } gnutls_certificate_allocate_credentials( &conn->xcred ); diff --git a/lib/ssl_nss.c b/lib/ssl_nss.c index de6e7ec6..b0e2f9f9 100644 --- a/lib/ssl_nss.c +++ b/lib/ssl_nss.c @@ -90,6 +90,14 @@ static SECStatus nss_bad_cert (void *arg, PRFileDesc *socket) } +void ssl_init( void ) +{ + PR_Init( PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1); + NSS_NoDB_Init(NULL); + NSS_SetDomesticPolicy(); + initialized = TRUE; +} + void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data ) { struct scd *conn = g_new0( struct scd, 1 ); @@ -106,9 +114,7 @@ void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data if( !initialized ) { - PR_Init( PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1); - NSS_NoDB_Init(NULL); - NSS_SetDomesticPolicy(); + ssl_init(); } diff --git a/lib/ssl_openssl.c b/lib/ssl_openssl.c index e0143791..64bc9257 100644 --- a/lib/ssl_openssl.c +++ b/lib/ssl_openssl.c @@ -56,6 +56,13 @@ static gboolean ssl_starttls_real( gpointer data, gint source, b_input_condition static gboolean ssl_handshake( gpointer data, gint source, b_input_condition cond ); +void ssl_init( void ) +{ + initialized = TRUE; + SSL_library_init(); + // SSLeay_add_ssl_algorithms(); +} + void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data ) { struct scd *conn = g_new0( struct scd, 1 ); @@ -114,10 +121,7 @@ static gboolean ssl_connected( gpointer data, gint source, b_input_condition con if( !initialized ) { - initialized = TRUE; - SSL_library_init(); - //SSLeay_add_ssl_algorithms(); - //OpenSSL_add_all_algorithms(); + ssl_init(); } meth = TLSv1_client_method(); |