return sockinfo;
}
-gint sock_printf(SockInfo *sock, const gchar *format, ...)
-{
- va_list args;
- gchar buf[BUFFSIZE];
-
- va_start(args, format);
- g_vsnprintf(buf, sizeof(buf), format, args);
- va_end(args);
-
- return sock_write_all(sock, buf, strlen(buf));
-}
-
static gint fd_read(gint fd, gchar *buf, gint len)
{
if (fd_check_io(fd, G_IO_IN) < 0)
}
#if USE_OPENSSL
-gint ssl_read(SSL *ssl, gchar *buf, gint len)
+static gint ssl_read(SSL *ssl, gchar *buf, gint len)
{
gint err, ret;
}
#if USE_OPENSSL
-gint ssl_write(SSL *ssl, const gchar *buf, gint len)
+static gint ssl_write(SSL *ssl, const gchar *buf, gint len)
{
gint ret;
}
#if USE_OPENSSL
-gint ssl_write_all(SSL *ssl, const gchar *buf, gint len)
+static gint ssl_write_all(SSL *ssl, const gchar *buf, gint len)
{
gint n, wrlen = 0;
}
#if USE_OPENSSL
-gint ssl_gets(SSL *ssl, gchar *buf, gint len)
+static gint ssl_peek (SSL *ssl, gchar *buf, gint len);
+
+static gint ssl_gets(SSL *ssl, gchar *buf, gint len)
{
gchar *newline, *bp = buf;
gint n;
return ret;
}
-static gint fd_getline(gint fd, gchar **str)
-{
- gchar buf[BUFFSIZE];
- gint len;
- gulong size = 1;
-
- while ((len = fd_gets(fd, buf, sizeof(buf))) > 0) {
- size += len;
- if (!*str)
- *str = g_strdup(buf);
- else {
- *str = g_realloc(*str, size);
- strcat(*str, buf);
- }
- if (buf[len - 1] == '\n'
-#ifdef G_OS_WIN32 /* FIXME This does not seem to be correct. */
- || buf[len - 1] == '\r'
-#endif
- )
- break;
- }
- if (len == -1 && *str)
- g_free(*str);
-
- return len;
-}
-
-#if USE_OPENSSL
-gint ssl_getline(SSL *ssl, gchar **str)
-{
- gchar buf[BUFFSIZE];
- gint len;
- gulong size = 1;
-
- while ((len = ssl_gets(ssl, buf, sizeof(buf))) > 0) {
- size += len;
- if (!*str)
- *str = g_strdup(buf);
- else {
- *str = g_realloc(*str, size);
- strcat(*str, buf);
- }
- if (buf[len - 1] == '\n')
- break;
- }
- if (len == -1 && *str)
- g_free(*str);
-
- return len;
-}
-#endif
-
-gchar *sock_getline(SockInfo *sock)
-{
- gint ret;
- gchar *str = NULL;
-
- g_return_val_if_fail(sock != NULL, NULL);
-
-#if USE_OPENSSL
- if (sock->ssl)
- ret = ssl_getline(sock->ssl, &str);
- else
-#endif
- ret = fd_getline(sock->sock, &str);
-
- if (ret < 0)
- sock->state = CONN_DISCONNECTED;
- return str;
-}
-
-gint sock_puts(SockInfo *sock, const gchar *buf)
-{
- gint ret;
-
- if ((ret = sock_write_all(sock, buf, strlen(buf))) < 0)
- return ret;
- return sock_write_all(sock, "\r\n", 2);
-}
-
/* peek at the socket data without actually reading it */
#if USE_OPENSSL
-gint ssl_peek(SSL *ssl, gchar *buf, gint len)
+static gint ssl_peek(SSL *ssl, gchar *buf, gint len)
{
gint err, ret;
}
#endif
-gint sock_peek(SockInfo *sock, gchar *buf, gint len)
-{
- g_return_val_if_fail(sock != NULL, -1);
-
-#if USE_OPENSSL
- if (sock->ssl)
- return ssl_peek(sock->ssl, buf, len);
-#endif
- return fd_recv(sock->sock, buf, len, MSG_PEEK);
-}
-
gint sock_close(SockInfo *sock)
{
gint ret;
gint sock_connect_async_cancel (gint id);
/* Basic I/O functions */
-gint sock_printf (SockInfo *sock, const gchar *format, ...)
- G_GNUC_PRINTF(2, 3);
gint sock_read (SockInfo *sock, gchar *buf, gint len);
gint sock_write (SockInfo *sock, const gchar *buf, gint len);
gint sock_write_all (SockInfo *sock, const gchar *buf, gint len);
gint sock_gets (SockInfo *sock, gchar *buf, gint len);
-gchar *sock_getline (SockInfo *sock);
-gint sock_puts (SockInfo *sock, const gchar *buf);
-gint sock_peek (SockInfo *sock, gchar *buf, gint len);
gint sock_close (SockInfo *sock);
/* Functions to directly work on FD. They are needed for pipes */
gint fd_gets (gint sock, gchar *buf, gint len);
gint fd_close (gint sock);
-/* Functions for SSL */
-#if USE_OPENSSL
-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 **str);
-gint ssl_peek (SSL *ssl, gchar *buf, gint len);
-#endif
-
#endif /* __SOCKET_H__ */