Get rid of an unused variable.
authorJeffrey Stedfast <fejj@ximian.com>
Wed, 17 Apr 2002 01:25:28 +0000 (01:25 +0000)
committerJeffrey Stedfast <fejj@src.gnome.org>
Wed, 17 Apr 2002 01:25:28 +0000 (01:25 +0000)
2002-04-16  Jeffrey Stedfast  <fejj@ximian.com>

* camel-filter-driver.c (camel_filter_driver_filter_folder): Get
rid of an unused variable.

* providers/smtp/camel-smtp-transport.c (smtp_helo): Use
camel_gethostbyaddr since gethostbyaddr is not reentrant.

* camel-http-stream.c (http_connect): Updated after the rename of
camel_get_host_byname.

* camel-service.c (camel_gethostbyname): Renamed.
(camel_gethostbyaddr): New cancellable/reentrant version of
gethostbyaddr.

camel/ChangeLog
camel/camel-filter-driver.c
camel/camel-http-stream.c
camel/camel-service.c
camel/camel-service.h
camel/camel-tcp-stream-raw.c
camel/camel-tcp-stream.h
camel/providers/smtp/camel-smtp-transport.c

index 0356045..a3cc3d5 100644 (file)
@@ -1,3 +1,18 @@
+2002-04-16  Jeffrey Stedfast  <fejj@ximian.com>
+
+       * camel-filter-driver.c (camel_filter_driver_filter_folder): Get
+       rid of an unused variable.
+
+       * providers/smtp/camel-smtp-transport.c (smtp_helo): Use
+       camel_gethostbyaddr since gethostbyaddr is not reentrant.
+
+       * camel-http-stream.c (http_connect): Updated after the rename of
+       camel_get_host_byname.
+
+       * camel-service.c (camel_gethostbyname): Renamed.
+       (camel_gethostbyaddr): New cancellable/reentrant version of
+       gethostbyaddr.
+
 2002-04-14  Jeffrey Stedfast  <fejj@ximian.com>
 
        * providers/local/camel-spoold-store.c: Added #include
index f5dd167..f4e7820 100644 (file)
@@ -983,7 +983,6 @@ camel_filter_driver_filter_folder (CamelFilterDriver *driver, CamelFolder *folde
        char *source_url, *service_url;
        const char *folder_name;
        int status = 0;
-       int need_sep = 0;
        CamelURL *url;
        int i;
        
index bc9aa33..44c7601 100644 (file)
@@ -188,7 +188,7 @@ http_connect (CamelService *service, CamelURL *url)
                return NULL;
        }
        
-       host = camel_get_host_byname (url->host, NULL);
+       host = camel_gethostbyname (url->host, NULL);
        if (!host) {
                errno = EHOSTUNREACH;
                return NULL;
index 9c32256..502da90 100644 (file)
@@ -554,7 +554,7 @@ camel_service_gethost (CamelService *service, CamelException *ex)
        else
                hostname = "localhost";
        
-       return camel_get_host_byname(hostname, ex);
+       return camel_gethostbyname (hostname, ex);
 }
 
 #ifdef offsetof
@@ -568,6 +568,8 @@ struct _lookup_msg {
        EMsg msg;
 #endif
        const char *name;
+       int len;
+       int type;
        int result;
        int herr;
        struct hostent hostbuf;
@@ -576,7 +578,7 @@ struct _lookup_msg {
 };
 
 static void *
-get_host(void *data)
+get_hostbyname(void *data)
 {
        struct _lookup_msg *info = data;
 
@@ -597,7 +599,8 @@ get_host(void *data)
        return NULL;
 }
 
-struct hostent *camel_get_host_byname(const char *name, CamelException *ex)
+struct hostent *
+camel_gethostbyname(const char *name, CamelException *ex)
 {
 #ifdef ENABLE_THREADS
        int fdmax, fd, cancel_fd;
@@ -622,7 +625,7 @@ struct hostent *camel_get_host_byname(const char *name, CamelException *ex)
        cancel_fd = camel_operation_cancel_fd(NULL);
        if (cancel_fd == -1) {
 #endif
-               get_host(msg);
+               get_hostbyname(msg);
 #ifdef ENABLE_THREADS
        } else {
                EMsgPort *reply_port;
@@ -631,7 +634,7 @@ struct hostent *camel_get_host_byname(const char *name, CamelException *ex)
 
                reply_port = msg->msg.reply_port = e_msgport_new();
                fd = e_msgport_fd(msg->msg.reply_port);
-               if (pthread_create(&id, NULL, get_host, msg) == 0) {
+               if (pthread_create(&id, NULL, get_hostbyname, msg) == 0) {
                        FD_ZERO(&rdset);
                        FD_SET(cancel_fd, &rdset);
                        FD_SET(fd, &rdset);
@@ -675,6 +678,118 @@ struct hostent *camel_get_host_byname(const char *name, CamelException *ex)
        }
 }
 
+
+static void *
+get_hostbyaddr (void *data)
+{
+       struct _lookup_msg *info = data;
+
+       while ((info->result = e_gethostbyaddr_r (info->name, info->len, info->type, &info->hostbuf,
+                                                 info->hostbufmem, info->hostbuflen, &info->herr)) == ERANGE) {
+               d(printf ("gethostbyaddr fialed?\n"));
+#ifdef ENABLE_THREADS
+               pthread_testcancel ();
+#endif
+                info->hostbuflen *= 2;
+                info->hostbufmem = g_realloc (info->hostbufmem, info->hostbuflen);
+       }
+       
+       d(printf ("gethostbyaddr ok?\n"));
+       
+#ifdef ENABLE_THREADS
+       e_msgport_reply ((EMsg *) info);
+#endif
+       return NULL;
+}
+
+
+struct hostent *
+camel_gethostbyaddr (const char *addr, int len, int type, CamelException *ex)
+{
+#ifdef ENABLE_THREADS
+       int fdmax, fd, cancel_fd;
+#endif
+       struct _lookup_msg *msg;
+       
+       g_return_val_if_fail (addr != NULL, NULL);
+       
+       if (camel_operation_cancel_check (NULL)) {
+               camel_exception_setv (ex, CAMEL_EXCEPTION_USER_CANCEL, _("Cancelled"));
+               return NULL;
+       }
+       
+       camel_operation_start_transient (NULL, _("Resolving address"));
+       
+       msg = g_malloc0 (sizeof (struct _lookup_msg));
+       msg->hostbuflen = 1024;
+       msg->hostbufmem = g_malloc (msg->hostbuflen);
+       msg->name = addr;
+       msg->len = len;
+       msg->type = type;
+       
+#ifdef ENABLE_THREADS
+       cancel_fd = camel_operation_cancel_fd (NULL);
+       if (cancel_fd == -1) {
+#endif
+               get_hostbyaddr (msg);
+#ifdef ENABLE_THREADS
+       } else {
+               EMsgPort *reply_port;
+               pthread_t id;
+               fd_set rdset;
+               
+               reply_port = msg->msg.reply_port = e_msgport_new ();
+               fd = e_msgport_fd (msg->msg.reply_port);
+               if (pthread_create (&id, NULL, get_hostbyaddr, msg) == 0) {
+                       FD_ZERO(&rdset);
+                       FD_SET(cancel_fd, &rdset);
+                       FD_SET(fd, &rdset);
+                       fdmax = MAX(fd, cancel_fd) + 1;
+                       d(printf("waiting for name return/cancellation in main process\n"));
+                       if (select (fdmax, &rdset, NULL, 0, NULL) == -1) {
+                               camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+                                                     _("Failure in name lookup: %s"), g_strerror (errno));
+                               d(printf ("Cancelling lookup thread\n"));
+                               pthread_cancel (id);
+                       } else if (FD_ISSET(cancel_fd, &rdset)) {
+                               d(printf ("Cancelling lookup thread\n"));
+                               camel_exception_setv (ex, CAMEL_EXCEPTION_USER_CANCEL, _("Cancelled"));
+                               pthread_cancel (id);
+                       } else {
+                               struct _lookup_msg *reply = (struct _lookup_msg *) e_msgport_get (reply_port);
+                               
+                               g_assert (reply == msg);
+                       }
+                       
+                       d(printf ("waiting for child to exit\n"));
+                       pthread_join (id, NULL);
+                       d(printf ("child done\n"));
+               }
+               
+               e_msgport_destroy (reply_port);
+       }
+#endif
+       
+       camel_operation_end (NULL);
+       
+       if (msg->herr) {
+               if (!camel_exception_is_set (ex)) {
+                       if (msg->herr == HOST_NOT_FOUND || msg->herr == NO_DATA)
+                               camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
+                                                    _("Host lookup failed: host not found"));
+                       else
+                               camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
+                                                    _("Host lookup failed: unknown reason"));
+               }
+               
+               g_free (msg->hostbufmem);
+               g_free (msg);
+               return NULL;
+       } else {
+               return &msg->hostbuf;
+       }
+}
+
 void camel_free_host(struct hostent *h)
 {
        struct _lookup_msg *msg;
index 98d3de4..cb8b89e 100644 (file)
@@ -126,7 +126,8 @@ struct hostent *    camel_service_gethost            (CamelService *service,
                                                      CamelException *ex);
 
 /* cancellable dns lookup */
-struct hostent *    camel_get_host_byname           (const char *name, CamelException *ex);
+struct hostent *    camel_gethostbyname              (const char *name, CamelException *ex);
+struct hostent *    camel_gethostbyaddr              (const char *addr, int len, int type, CamelException *ex);
 void               camel_free_host                  (struct hostent *h);
 
 /* Standard Camel function */
index cd3a74d..d8aef35 100644 (file)
@@ -572,11 +572,11 @@ stream_get_local_address (CamelTcpStream *stream)
 {
        struct sockaddr_in sin;
        socklen_t len;
-
+       
        if (getsockname (CAMEL_TCP_STREAM_RAW (stream)->sockfd,
-                        (struct sockaddr *)&sin, &len) == -1)
+                        (struct sockaddr *) &sin, &len) == -1)
                return NULL;
-
+       
        return camel_tcp_address_new (CAMEL_TCP_ADDRESS_IPV4, sin.sin_port,
                                      4, &sin.sin_addr);
 }
@@ -586,11 +586,11 @@ stream_get_remote_address (CamelTcpStream *stream)
 {
        struct sockaddr_in sin;
        socklen_t len;
-
+       
        if (getpeername (CAMEL_TCP_STREAM_RAW (stream)->sockfd,
-                        (struct sockaddr *)&sin, &len) == -1)
+                        (struct sockaddr *) &sin, &len) == -1)
                return NULL;
-
+       
        return camel_tcp_address_new (CAMEL_TCP_ADDRESS_IPV4, sin.sin_port,
                                      4, &sin.sin_addr);
 }
index e6651e6..2c4d022 100644 (file)
@@ -89,7 +89,8 @@ typedef struct _CamelSockOptData {
 } CamelSockOptData;
 
 typedef enum {
-       CAMEL_TCP_ADDRESS_IPV4
+       CAMEL_TCP_ADDRESS_IPV4,
+       CAMEL_TCP_ADDRESS_IPV6
 } CamelTcpAddressFamily;
 
 typedef struct {
@@ -99,8 +100,7 @@ typedef struct {
 } CamelTcpAddress;
 
 
-struct _CamelTcpStream
-{
+struct _CamelTcpStream {
        CamelStream parent_object;
        
 };
index f71f8b4..2a5640d 100644 (file)
@@ -831,24 +831,30 @@ smtp_helo (CamelSmtpTransport *transport, CamelException *ex)
 {
        /* say hello to the server */
        char *name, *cmdbuf, *respbuf = NULL;
-       const char *token;
        struct hostent *host;
+       CamelException err;
+       const char *token;
        
        camel_operation_start_transient (NULL, _("SMTP Greeting"));
        
        /* get the local host name */
-       host = gethostbyaddr ((char *)&transport->localaddr->address,
-                             transport->localaddr->length, AF_INET);
-       if (host && host->h_name)
+       camel_exception_init (&err);
+       host = camel_gethostbyaddr ((char *) &transport->localaddr->address,
+                                   transport->localaddr->length, AF_INET, &err);
+       camel_exception_clear (&err);
+       
+       if (host && host->h_name) {
                name = g_strdup (host->h_name);
-       else {
+       else {
                name = g_strdup_printf ("[%d.%d.%d.%d]",
                                        transport->localaddr->address[0],
                                        transport->localaddr->address[1],
                                        transport->localaddr->address[2],
                                        transport->localaddr->address[3]);
        }
-
+       
+       camel_free_host (host);
+       
        /* hiya server! how are you today? */
        if (transport->flags & CAMEL_SMTP_TRANSPORT_IS_ESMTP)
                cmdbuf = g_strdup_printf ("EHLO %s\r\n", name);