Drop OpenSSL support from socket code

This commit is contained in:
Christian Dywan 2012-02-19 20:21:37 +01:00
parent c6b15ff4dc
commit d2fe0791e1
4 changed files with 1 additions and 246 deletions

View file

@ -54,9 +54,6 @@
#endif #endif
#include "socket.h" #include "socket.h"
#if USE_SSL
# include <openssl/ssl.h>
#endif
#ifdef G_ENABLE_DEBUG #ifdef G_ENABLE_DEBUG
# define debug_print g_debug # define debug_print g_debug
@ -562,10 +559,6 @@ gboolean sock_has_read_data(SockInfo *sock)
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
gulong val; gulong val;
#if USE_SSL
if (sock->ssl)
return TRUE;
#endif
if (ioctlsocket(sock->sock, FIONREAD, &val) < 0) { if (ioctlsocket(sock->sock, FIONREAD, &val) < 0) {
g_warning("sock_has_read_data(): ioctlsocket() failed: %d\n", g_warning("sock_has_read_data(): ioctlsocket() failed: %d\n",
WSAGetLastError()); WSAGetLastError());
@ -595,22 +588,6 @@ static gboolean sock_check(GSource *source)
fd_set fds; fd_set fds;
GIOCondition condition = sock->condition; GIOCondition condition = sock->condition;
#if USE_SSL
if (sock->ssl) {
if (condition & G_IO_IN) {
if (SSL_pending(sock->ssl) > 0)
return TRUE;
if (SSL_want_write(sock->ssl))
condition |= G_IO_OUT;
}
if (condition & G_IO_OUT) {
if (SSL_want_read(sock->ssl))
condition |= G_IO_IN;
}
}
#endif
FD_ZERO(&fds); FD_ZERO(&fds);
FD_SET(sock->sock, &fds); FD_SET(sock->sock, &fds);
@ -647,19 +624,6 @@ guint sock_add_watch(SockInfo *sock, GIOCondition condition, SockFunc func,
sock->callback = func; sock->callback = func;
sock->condition = condition; sock->condition = condition;
sock->data = data; sock->data = data;
#if USE_SSL
if (sock->ssl) {
GSource *source;
source = g_source_new(&sock_watch_funcs, sizeof(SockSource));
((SockSource *)source)->sock = sock;
g_source_set_priority(source, G_PRIORITY_DEFAULT);
g_source_set_can_recurse(source, FALSE);
return g_source_attach(source, NULL);
}
#endif
return g_io_add_watch(sock->sock_ch, condition, sock_watch_cb, sock); return g_io_add_watch(sock->sock_ch, condition, sock_watch_cb, sock);
} }
@ -1375,10 +1339,6 @@ gint sock_read(SockInfo *sock, gchar *buf, gint len)
{ {
g_return_val_if_fail(sock != NULL, -1); g_return_val_if_fail(sock != NULL, -1);
#if USE_SSL
if (sock->ssl)
return ssl_read(sock->ssl, buf, len);
#endif
return fd_read(sock->sock, buf, len); return fd_read(sock->sock, buf, len);
} }
@ -1394,44 +1354,10 @@ gint fd_read(gint fd, gchar *buf, gint len)
#endif #endif
} }
#if USE_SSL
gint ssl_read(SSL *ssl, gchar *buf, gint len)
{
gint err, ret;
if (SSL_pending(ssl) == 0) {
if (fd_check_io(SSL_get_rfd(ssl), G_IO_IN) < 0)
return -1;
}
ret = SSL_read(ssl, buf, len);
switch ((err = SSL_get_error(ssl, ret))) {
case SSL_ERROR_NONE:
return ret;
case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_WRITE:
errno = EAGAIN;
return -1;
case SSL_ERROR_ZERO_RETURN:
return 0;
default:
g_warning("SSL_read() returned error %d, ret = %d\n", err, ret);
if (ret == 0)
return 0;
return -1;
}
}
#endif
gint sock_write(SockInfo *sock, const gchar *buf, gint len) gint sock_write(SockInfo *sock, const gchar *buf, gint len)
{ {
g_return_val_if_fail(sock != NULL, -1); g_return_val_if_fail(sock != NULL, -1);
#if USE_SSL
if (sock->ssl)
return ssl_write(sock->ssl, buf, len);
#endif
return fd_write(sock->sock, buf, len); return fd_write(sock->sock, buf, len);
} }
@ -1459,34 +1385,10 @@ gint fd_write(gint fd, const gchar *buf, gint len)
#endif #endif
} }
#if USE_SSL
gint ssl_write(SSL *ssl, const gchar *buf, gint len)
{
gint ret;
ret = SSL_write(ssl, buf, len);
switch (SSL_get_error(ssl, ret)) {
case SSL_ERROR_NONE:
return ret;
case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_WRITE:
errno = EAGAIN;
return -1;
default:
return -1;
}
}
#endif
gint sock_write_all(SockInfo *sock, const gchar *buf, gint len) gint sock_write_all(SockInfo *sock, const gchar *buf, gint len)
{ {
g_return_val_if_fail(sock != NULL, -1); g_return_val_if_fail(sock != NULL, -1);
#if USE_SSL
if (sock->ssl)
return ssl_write_all(sock->ssl, buf, len);
#endif
return fd_write_all(sock->sock, buf, len); return fd_write_all(sock->sock, buf, len);
} }
@ -1506,24 +1408,6 @@ gint fd_write_all(gint fd, const gchar *buf, gint len)
return wrlen; return wrlen;
} }
#if USE_SSL
gint ssl_write_all(SSL *ssl, const gchar *buf, gint len)
{
gint n, wrlen = 0;
while (len) {
n = ssl_write(ssl, buf, len);
if (n <= 0)
return -1;
len -= n;
wrlen += n;
buf += n;
}
return wrlen;
}
#endif
gint fd_recv(gint fd, gchar *buf, gint len, gint flags) gint fd_recv(gint fd, gchar *buf, gint len, gint flags)
{ {
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
@ -1570,38 +1454,10 @@ gint fd_gets(gint fd, gchar *buf, gint len)
return bp - buf; return bp - buf;
} }
#if USE_SSL
gint ssl_gets(SSL *ssl, gchar *buf, gint len)
{
gchar *newline, *bp = buf;
gint n;
if (--len < 1)
return -1;
do {
if ((n = ssl_peek(ssl, bp, len)) <= 0)
return -1;
if ((newline = memchr(bp, '\n', n)) != NULL)
n = newline - bp + 1;
if ((n = ssl_read(ssl, bp, n)) < 0)
return -1;
bp += n;
len -= n;
} while (!newline && len);
*bp = '\0';
return bp - buf;
}
#endif
gint sock_gets(SockInfo *sock, gchar *buf, gint len) gint sock_gets(SockInfo *sock, gchar *buf, gint len)
{ {
g_return_val_if_fail(sock != NULL, -1); g_return_val_if_fail(sock != NULL, -1);
#if USE_SSL
if (sock->ssl)
return ssl_gets(sock->ssl, buf, len);
#endif
return fd_gets(sock->sock, buf, len); return fd_gets(sock->sock, buf, len);
} }
@ -1630,42 +1486,11 @@ gint fd_getline(gint fd, gchar **line)
return (gint)size; return (gint)size;
} }
#if USE_SSL
gint ssl_getline(SSL *ssl, gchar **line)
{
gchar buf[BUFFSIZE];
gchar *str = NULL;
gint len;
gulong size = 0;
gulong cur_offset = 0;
while ((len = ssl_gets(ssl, buf, sizeof(buf))) > 0) {
size += len;
str = g_realloc(str, size + 1);
memcpy(str + cur_offset, buf, len + 1);
cur_offset += len;
if (buf[len - 1] == '\n')
break;
}
*line = str;
if (!str)
return -1;
else
return (gint)size;
}
#endif
gint sock_getline(SockInfo *sock, gchar **line) gint sock_getline(SockInfo *sock, gchar **line)
{ {
g_return_val_if_fail(sock != NULL, -1); g_return_val_if_fail(sock != NULL, -1);
g_return_val_if_fail(line != NULL, -1); g_return_val_if_fail(line != NULL, -1);
#if USE_SSL
if (sock->ssl)
return ssl_getline(sock->ssl, line);
#endif
return fd_getline(sock->sock, line); return fd_getline(sock->sock, line);
} }
@ -1679,44 +1504,10 @@ gint sock_puts(SockInfo *sock, const gchar *buf)
} }
/* peek at the socket data without actually reading it */ /* peek at the socket data without actually reading it */
#if USE_SSL
gint ssl_peek(SSL *ssl, gchar *buf, gint len)
{
gint err, ret;
if (SSL_pending(ssl) == 0) {
if (fd_check_io(SSL_get_rfd(ssl), G_IO_IN) < 0)
return -1;
}
ret = SSL_peek(ssl, buf, len);
switch ((err = SSL_get_error(ssl, ret))) {
case SSL_ERROR_NONE:
return ret;
case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_WRITE:
errno = EAGAIN;
return -1;
case SSL_ERROR_ZERO_RETURN:
return 0;
default:
g_warning("SSL_peek() returned error %d, ret = %d\n", err, ret);
if (ret == 0)
return 0;
return -1;
}
}
#endif
gint sock_peek(SockInfo *sock, gchar *buf, gint len) gint sock_peek(SockInfo *sock, gchar *buf, gint len)
{ {
g_return_val_if_fail(sock != NULL, -1); g_return_val_if_fail(sock != NULL, -1);
#if USE_SSL
if (sock->ssl)
return ssl_peek(sock->ssl, buf, len);
#endif
return fd_recv(sock->sock, buf, len, MSG_PEEK); return fd_recv(sock->sock, buf, len, MSG_PEEK);
} }
@ -1727,11 +1518,6 @@ gint sock_close(SockInfo *sock)
if (!sock) if (!sock)
return 0; return 0;
#if USE_SSL
if (sock->ssl)
ssl_done_socket(sock);
#endif
if (sock->sock_ch) { if (sock->sock_ch) {
g_io_channel_shutdown(sock->sock_ch, FALSE, NULL); g_io_channel_shutdown(sock->sock_ch, FALSE, NULL);
g_io_channel_unref(sock->sock_ch); g_io_channel_unref(sock->sock_ch);
@ -1759,13 +1545,4 @@ gint fd_close(gint fd)
#endif #endif
} }
#if USE_SSL
void ssl_done_socket(SockInfo *sockinfo)
{
if (sockinfo->ssl) {
SSL_free(sockinfo->ssl);
}
}
#endif
#endif #endif

View file

@ -20,10 +20,6 @@
typedef struct _SockInfo SockInfo; typedef struct _SockInfo SockInfo;
#if USE_SSL
# include <openssl/ssl.h>
#endif
typedef enum typedef enum
{ {
CONN_READY, CONN_READY,
@ -42,11 +38,6 @@ typedef gboolean (*SockFunc) (SockInfo *sock,
struct _SockInfo struct _SockInfo
{ {
gint sock; gint sock;
#if USE_SSL
SSL *ssl;
#else
gpointer ssl;
#endif
GIOChannel *sock_ch; GIOChannel *sock_ch;
gchar *hostname; gchar *hostname;
@ -111,15 +102,4 @@ gint fd_gets (gint sock, gchar *buf, gint len);
gint fd_getline (gint sock, gchar **line); gint fd_getline (gint sock, gchar **line);
gint fd_close (gint sock); gint fd_close (gint sock);
/* Functions for SSL */
#if USE_SSL
gint ssl_read (SSL *ssl, gchar *buf, gint len);
gint ssl_write (SSL *ssl, const gchar *buf, gint len);
gint ssl_write_all (SSL *ssl, const gchar *buf, gint len);
gint ssl_gets (SSL *ssl, gchar *buf, gint len);
gint ssl_getline (SSL *ssl, gchar **line);
gint ssl_peek (SSL *ssl, gchar *buf, gint len);
void ssl_done_socket (SockInfo *sockinfo);
#endif
#endif /* __SYLPH_SOCKET_H__ */ #endif /* __SYLPH_SOCKET_H__ */

View file

@ -7,7 +7,7 @@ import platform
progressive = True progressive = True
libs = 'M UNIQUE LIBSOUP GMODULE GTHREAD LIBIDN GIO GTK SQLITE ' \ libs = 'M UNIQUE LIBSOUP GMODULE GTHREAD LIBIDN GIO GTK SQLITE ' \
'LIBNOTIFY WEBKIT JAVASCRIPTCOREGTK LIBXML X11 XSS WS2_32 OPENSSL HILDON' \ 'LIBNOTIFY WEBKIT JAVASCRIPTCOREGTK LIBXML X11 XSS WS2_32 HILDON' \
'HILDON_FM' 'HILDON_FM'
if progressive or Options.commands['check']: if progressive or Options.commands['check']:

View file

@ -275,8 +275,6 @@ def configure (conf):
if not conf.env['HAVE_UNIQUE']: if not conf.env['HAVE_UNIQUE']:
if Options.platform == 'win32': if Options.platform == 'win32':
conf.check (lib='ws2_32') conf.check (lib='ws2_32')
check_pkg ('openssl', mandatory=False)
conf.define ('USE_SSL', [0,1][conf.env['HAVE_OPENSSL'] == 1])
conf.define ('HAVE_NETDB_H', [0,1][conf.check (header_name='netdb.h')]) conf.define ('HAVE_NETDB_H', [0,1][conf.check (header_name='netdb.h')])
conf.check (header_name='sys/wait.h') conf.check (header_name='sys/wait.h')
conf.check (header_name='sys/select.h') conf.check (header_name='sys/select.h')