sync with 0.9.2cvs11
authorPaul Mangan <paul@claws-mail.org>
Wed, 2 Jul 2003 11:20:00 +0000 (11:20 +0000)
committerPaul Mangan <paul@claws-mail.org>
Wed, 2 Jul 2003 11:20:00 +0000 (11:20 +0000)
ChangeLog
ChangeLog.claws
ChangeLog.jp
configure.ac
src/common/session.c
src/common/session.h
src/common/socket.c
src/common/socket.h

index 605999e..224d8b7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2003-07-02
+
+       * src/socket.[ch]: sock_add_watch(): new. It monitors SSL by original
+         watch functions (otherwise uses g_io_add_watch()).
+       * src/session.[ch]: removed previous workarounds, and replaced
+         g_io_add_watch() with sock_add_watch().
+
 2003-07-01
 
        * src/socket.[ch]: added sock_has_pending_data() which returns TRUE
index 580fbff..c1f05ae 100644 (file)
@@ -1,3 +1,8 @@
+2003-07-02 [paul]      0.9.0claws73
+
+       * sync with 0.9.2cvs11
+               see ChangeLog 2003-07-02
+
 2003-07-02 [paul]      0.9.0claws72
 
        * src/procmsg.c
index 6ac7742..2bfaaea 100644 (file)
@@ -1,3 +1,10 @@
+2003-07-02
+
+       * src/socket.[ch]: sock_add_watch(): ¿·µ¬¡£ SSL ¤ò¥ª¥ê¥¸¥Ê¥ë¤Î watch
+         ´Ø¿ô¤Ç´Æ»ë¤¹¤ë(SSL ¤Ç¤Ê¤¤¾ì¹ç¤Ï g_io_add_watch() ¤ò»ÈÍÑ)¡£
+       * src/session.[ch]: °ÊÁ°¤ÎÂнè¤òºï½ü¤·¡¢ g_io_add_watch() ¤ò
+         sock_add_watch() ¤ÇÃÖ¤­´¹¤¨¤¿¡£
+
 2003-07-01
 
        * src/socket.[ch]: ¥½¥±¥Ã¥È¤Ë̤½èÍý¤Î¥Ç¡¼¥¿¤¬Â¸ºß¤¹¤ë¾ì¹ç TRUE ¤ò
index 7eeaabd..fd59cc3 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws72
+EXTRA_VERSION=claws73
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index 9b4a638..1c2f92c 100644 (file)
@@ -42,19 +42,16 @@ static gint session_connect_cb              (SockInfo       *sock,
                                         gpointer        data);
 static gint session_close              (Session        *session);
 
-static gboolean session_read_msg_idle_cb       (gpointer        data);
-static gboolean session_read_data_idle_cb      (gpointer        data);
-
-static gboolean session_read_msg_cb    (GIOChannel     *source,
+static gboolean session_read_msg_cb    (SockInfo       *source,
                                         GIOCondition    condition,
                                         gpointer        data);
-static gboolean session_read_data_cb   (GIOChannel     *source,
+static gboolean session_read_data_cb   (SockInfo       *source,
                                         GIOCondition    condition,
                                         gpointer        data);
-static gboolean session_write_msg_cb   (GIOChannel     *source,
+static gboolean session_write_msg_cb   (SockInfo       *source,
                                         GIOCondition    condition,
                                         gpointer        data);
-static gboolean session_write_data_cb  (GIOChannel     *source,
+static gboolean session_write_data_cb  (SockInfo       *source,
                                         GIOCondition    condition,
                                         gpointer        data);
 
@@ -75,7 +72,6 @@ void session_init(Session *session)
 
        session->conn_id = 0;
 
-       session->sock_ch = NULL;
        session->io_tag = 0;
 
        session->read_buf = g_string_sized_new(1024);
@@ -139,13 +135,12 @@ static gint session_connect_cb(SockInfo *sock, gpointer data)
        }
 #endif
 
-       debug_print("session: child: connected\n");
+       sock_set_nonblocking_mode(sock, TRUE);
 
        debug_print("session: connected\n");
 
        session->state = SESSION_RECV;
-       session->sock_ch = g_io_channel_unix_new(sock->sock);
-       session->io_tag = g_io_add_watch(session->sock_ch, G_IO_IN,
+       session->io_tag = sock_add_watch(session->sock, G_IO_IN,
                                         session_read_msg_cb,
                                         session);
 
@@ -248,11 +243,6 @@ static gint session_close(Session *session)
                session->io_tag = 0;
        }
 
-       if (session->sock_ch) {
-               g_io_channel_unref(session->sock_ch);
-               session->sock_ch = NULL;
-       }
-
        if (session->sock) {
                sock_close(session->sock);
                session->sock = NULL;
@@ -299,10 +289,10 @@ gint session_send_msg(Session *session, SessionMsgType type, const gchar *msg)
        session->write_buf_p = session->write_buf;
        session->write_buf_len = strlen(msg) + 2;
 
-       ret = session_write_msg_cb(session->sock_ch, G_IO_OUT, session);
+       ret = session_write_msg_cb(session->sock, G_IO_OUT, session);
 
        if (ret == TRUE)
-               session->io_tag = g_io_add_watch(session->sock_ch, G_IO_OUT,
+               session->io_tag = sock_add_watch(session->sock, G_IO_OUT,
                                                 session_write_msg_cb, session);
        else if (session->state == SESSION_ERROR)
                return -1;
@@ -316,29 +306,12 @@ gint session_recv_msg(Session *session)
 
        session->state = SESSION_RECV;
 
-       if (sock_has_pending_data(session->sock))
-               g_idle_add(session_read_msg_idle_cb, session);
-       else
-               session->io_tag = g_io_add_watch(session->sock_ch, G_IO_IN,
-                                                session_read_msg_cb, session);
+       session->io_tag = sock_add_watch(session->sock, G_IO_IN,
+                                        session_read_msg_cb, session);
 
        return 0;
 }
 
-static gboolean session_read_msg_idle_cb(gpointer data)
-{
-       Session *session = SESSION(data);
-       gboolean ret;
-
-       ret = session_read_msg_cb(session->sock_ch, G_IO_IN, data);
-
-       if (ret == TRUE)
-               session->io_tag = g_io_add_watch(session->sock_ch, G_IO_IN,
-                                                session_read_msg_cb, session);
-
-       return FALSE;
-}
-
 /*!
  *\brief       parent (child?): send data to other process
  *
@@ -365,10 +338,10 @@ gint session_send_data(Session *session, const guchar *data, guint size)
        session->write_buf_len = size;
        gettimeofday(&session->tv_prev, NULL);
 
-       ret = session_write_data_cb(session->sock_ch, G_IO_OUT, session);
+       ret = session_write_data_cb(session->sock, G_IO_OUT, session);
 
        if (ret == TRUE)
-               session->io_tag = g_io_add_watch(session->sock_ch, G_IO_OUT,
+               session->io_tag = sock_add_watch(session->sock, G_IO_OUT,
                                                 session_write_data_cb,
                                                 session);
        else if (session->state == SESSION_ERROR)
@@ -387,30 +360,13 @@ gint session_recv_data(Session *session, guint size, const gchar *terminator)
        session->read_data_terminator = g_strdup(terminator);
        gettimeofday(&session->tv_prev, NULL);
 
-       if (sock_has_pending_data(session->sock))
-               g_idle_add(session_read_data_idle_cb, session);
-       else
-               session->io_tag = g_io_add_watch(session->sock_ch, G_IO_IN,
-                                                session_read_data_cb, session);
+       session->io_tag = sock_add_watch(session->sock, G_IO_IN,
+                                        session_read_data_cb, session);
 
        return 0;
 }
 
-static gboolean session_read_data_idle_cb(gpointer data)
-{
-       Session *session = SESSION(data);
-       gboolean ret;
-
-       ret = session_read_data_cb(session->sock_ch, G_IO_IN, data);
-
-       if (ret == TRUE)
-               session->io_tag = g_io_add_watch(session->sock_ch, G_IO_IN,
-                                                session_read_data_cb, session);
-
-       return FALSE;
-}
-
-static gboolean session_read_msg_cb(GIOChannel *source, GIOCondition condition,
+static gboolean session_read_msg_cb(SockInfo *source, GIOCondition condition,
                                    gpointer data)
 {
        Session *session = SESSION(data);
@@ -487,7 +443,7 @@ static gboolean session_read_msg_cb(GIOChannel *source, GIOCondition condition,
        return FALSE;
 }
 
-static gboolean session_read_data_cb(GIOChannel        *source, GIOCondition condition,
+static gboolean session_read_data_cb(SockInfo *source, GIOCondition condition,
                                     gpointer data)
 {
        Session *session = SESSION(data);
@@ -515,8 +471,6 @@ static gboolean session_read_data_cb(GIOChannel     *source, GIOCondition condition,
                }
        }
 
-       g_print("session_read_data_cb(): read %d bytes\n", read_len);
-
        data_buf = session->read_data_buf;
 
        g_byte_array_append(data_buf, buf, read_len);
@@ -619,7 +573,7 @@ static gint session_write_buf(Session *session)
        return 0;
 }
 
-static gboolean session_write_msg_cb(GIOChannel *source, GIOCondition condition,
+static gboolean session_write_msg_cb(SockInfo *source, GIOCondition condition,
                                     gpointer data)
 {
        Session *session = SESSION(data);
@@ -648,7 +602,7 @@ static gboolean session_write_msg_cb(GIOChannel *source, GIOCondition condition,
        return FALSE;
 }
 
-static gboolean session_write_data_cb(GIOChannel *source,
+static gboolean session_write_data_cb(SockInfo *source,
                                      GIOCondition condition, gpointer data)
 {
        Session *session = SESSION(data);
index 3f4a0e1..d28bc8d 100644 (file)
@@ -102,8 +102,6 @@ struct _Session
 
        gint conn_id;
 
-       /* I/O channel for socket */
-       GIOChannel *sock_ch;
        gint io_tag;
 
        GString *read_buf;
index 4367470..581c683 100644 (file)
@@ -96,6 +96,24 @@ static guint io_timeout = 60;
 
 static GList *sock_connect_data_list = NULL;
 
+static gboolean sock_prepare           (gpointer        source_data,
+                                        GTimeVal       *current_time,
+                                        gint           *timeout,
+                                        gpointer        data);
+static gboolean sock_check             (gpointer        source_data,
+                                        GTimeVal       *current_time,
+                                        gpointer        user_data);
+static gboolean sock_dispatch          (gpointer        source_data,
+                                        GTimeVal       *current_time,
+                                        gpointer        user_data);
+
+GSourceFuncs sock_watch_funcs = {
+       sock_prepare,
+       sock_check,
+       sock_dispatch,
+       NULL
+};
+
 static gint sock_connect_with_timeout  (gint                    sock,
                                         const struct sockaddr  *serv_addr,
                                         gint                    addrlen,
@@ -230,7 +248,6 @@ gint sock_set_nonblocking_mode(SockInfo *sock, gboolean nonblock)
        return set_nonblocking_mode(sock->sock, nonblock);
 }
 
-
 static gboolean is_nonblocking_mode(gint fd)
 {
        gint flags;
@@ -251,6 +268,75 @@ gboolean sock_is_nonblocking_mode(SockInfo *sock)
        return is_nonblocking_mode(sock->sock);
 }
 
+
+static gboolean sock_prepare(gpointer source_data, GTimeVal *current_time,
+                            gint *timeout, gpointer data)
+{
+       *timeout = 1;
+       return FALSE;
+}
+
+static gboolean sock_check(gpointer source_data, GTimeVal *current_time,
+                          gpointer user_data)
+{
+       SockInfo *sock = (SockInfo *)source_data;
+       struct timeval timeout = {0, 0};
+       fd_set fds;
+
+#if USE_OPENSSL
+       if (sock->ssl) {
+               if (sock->condition & G_IO_IN) {
+                       if (SSL_pending(sock->ssl) > 0) {
+                               g_print("SSL has pending data\n");
+                               return TRUE;
+                       }
+               }
+       }
+#endif
+
+       FD_ZERO(&fds);
+       FD_SET(sock->sock, &fds);
+
+       select(sock->sock + 1,
+              (sock->condition & G_IO_IN)  ? &fds : NULL,
+              (sock->condition & G_IO_OUT) ? &fds : NULL,
+              NULL, &timeout);
+
+       return FD_ISSET(sock->sock, &fds) != 0;
+}
+
+static gboolean sock_dispatch(gpointer source_data, GTimeVal *current_time,
+                             gpointer user_data)
+{
+       SockInfo *sock = (SockInfo *)source_data;
+
+       return sock->callback(sock, sock->condition, user_data);
+}
+
+static gboolean sock_watch_cb(GIOChannel *source, GIOCondition condition,
+                             gpointer data)
+{
+       SockInfo *sock = (SockInfo *)data;
+
+       return sock->callback(sock, condition, sock->data);
+}
+
+guint sock_add_watch(SockInfo *sock, GIOCondition condition, SockFunc func,
+                    gpointer data)
+{
+       sock->callback = func;
+       sock->condition = condition;
+       sock->data = data;
+
+#if USE_OPENSSL
+       if (sock->ssl)
+               return g_source_add(G_PRIORITY_DEFAULT, FALSE,
+                                   &sock_watch_funcs, sock, data, NULL);
+#endif
+
+       return g_io_add_watch(sock->sock_ch, condition, sock_watch_cb, sock);
+}
+
 gboolean sock_has_pending_data(SockInfo *sock)
 {
        struct timeval timeout = {0, 0};
@@ -562,6 +648,7 @@ static gboolean sock_connect_async_cb(GIOChannel *source,
 
        sockinfo = g_new0(SockInfo, 1);
        sockinfo->sock = fd;
+       sockinfo->sock_ch = g_io_channel_unix_new(fd);
        sockinfo->hostname = g_strdup(conn_data->hostname);
        sockinfo->port = conn_data->port;
        sockinfo->state = CONN_ESTABLISHED;
@@ -918,6 +1005,7 @@ static SockInfo *sockinfo_from_fd(const gchar *hostname,
 
        sockinfo = g_new0(SockInfo, 1);
        sockinfo->sock = sock;
+       sockinfo->sock_ch = g_io_channel_unix_new(sock);
        sockinfo->hostname = g_strdup(hostname);
        sockinfo->port = port;
        sockinfo->state = CONN_ESTABLISHED;
@@ -1287,6 +1375,9 @@ gint sock_close(SockInfo *sock)
        if (!sock)
                return 0;
 
+       if (sock->sock_ch)
+               g_io_channel_unref(sock->sock_ch);
+
 #if USE_OPENSSL
        if (sock->ssl)
                ssl_done_socket(sock);
index 735a7b7..20b996c 100644 (file)
@@ -45,23 +45,25 @@ typedef enum
 
 typedef gint (*SockConnectFunc)                (SockInfo       *sock,
                                         gpointer        data);
+typedef gboolean (*SockFunc)           (SockInfo       *sock,
+                                        GIOCondition    condition,
+                                        gpointer        data);
 
 struct _SockInfo
 {
-#if USE_GIO
-       GIOChannel *channel;
-       gchar *buf;
-       gint buflen;
-#else
        gint sock;
+#if USE_OPENSSL
+       SSL *ssl;
 #endif
+       GIOChannel *sock_ch;
+
        gchar *hostname;
        gushort port;
        ConnectionState state;
        gpointer data;
-#if USE_OPENSSL
-       SSL *ssl;
-#endif
+
+       SockFunc callback;
+       GIOCondition condition;
 };
 
 gint sock_set_io_timeout               (guint sec);
@@ -69,6 +71,9 @@ gint sock_set_io_timeout              (guint sec);
 gint sock_set_nonblocking_mode         (SockInfo *sock, gboolean nonblock);
 gboolean sock_is_nonblocking_mode      (SockInfo *sock);
 
+guint sock_add_watch                   (SockInfo *sock, GIOCondition condition,
+                                        SockFunc func, gpointer data);
+
 gboolean sock_has_pending_data         (SockInfo *sock);
 
 struct hostent *my_gethostbyname       (const gchar *hostname);
@@ -79,6 +84,7 @@ gint sock_connect_async                       (const gchar *hostname, gushort port,
                                         SockConnectFunc func, gpointer data);
 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);