From fc281a966c29421c896746d784a6f1393fe37f3f Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Wed, 17 Apr 2002 01:25:28 +0000 Subject: Get rid of an unused variable. 2002-04-16 Jeffrey Stedfast * 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. svn path=/trunk/; revision=16484 --- camel/ChangeLog | 15 ++++ camel/camel-filter-driver.c | 1 - camel/camel-http-stream.c | 2 +- camel/camel-service.c | 125 ++++++++++++++++++++++++++-- camel/camel-service.h | 3 +- camel/camel-tcp-stream-raw.c | 12 +-- camel/camel-tcp-stream.h | 6 +- camel/providers/smtp/camel-smtp-transport.c | 18 ++-- 8 files changed, 159 insertions(+), 23 deletions(-) diff --git a/camel/ChangeLog b/camel/ChangeLog index 0356045cc9..a3cc3d5422 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,18 @@ +2002-04-16 Jeffrey Stedfast + + * 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 * providers/local/camel-spoold-store.c: Added #include diff --git a/camel/camel-filter-driver.c b/camel/camel-filter-driver.c index f5dd16756c..f4e78204ec 100644 --- a/camel/camel-filter-driver.c +++ b/camel/camel-filter-driver.c @@ -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; diff --git a/camel/camel-http-stream.c b/camel/camel-http-stream.c index bc9aa33508..44c7601e82 100644 --- a/camel/camel-http-stream.c +++ b/camel/camel-http-stream.c @@ -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; diff --git a/camel/camel-service.c b/camel/camel-service.c index 9c32256fe0..502da90c5a 100644 --- a/camel/camel-service.c +++ b/camel/camel-service.c @@ -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; diff --git a/camel/camel-service.h b/camel/camel-service.h index 98d3de41f3..cb8b89eae9 100644 --- a/camel/camel-service.h +++ b/camel/camel-service.h @@ -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 */ diff --git a/camel/camel-tcp-stream-raw.c b/camel/camel-tcp-stream-raw.c index cd3a74d6f2..d8aef35079 100644 --- a/camel/camel-tcp-stream-raw.c +++ b/camel/camel-tcp-stream-raw.c @@ -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); } diff --git a/camel/camel-tcp-stream.h b/camel/camel-tcp-stream.h index e6651e6ccd..2c4d022168 100644 --- a/camel/camel-tcp-stream.h +++ b/camel/camel-tcp-stream.h @@ -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; }; diff --git a/camel/providers/smtp/camel-smtp-transport.c b/camel/providers/smtp/camel-smtp-transport.c index f71f8b4050..2a5640d7ab 100644 --- a/camel/providers/smtp/camel-smtp-transport.c +++ b/camel/providers/smtp/camel-smtp-transport.c @@ -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); -- cgit v1.2.3