aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2000-03-29 04:51:58 +0800
committerDan Winship <danw@src.gnome.org>2000-03-29 04:51:58 +0800
commit207652677441264ca1e51d06898b37ea4164c8e2 (patch)
treeded681c259297bf4b25a83fb9cd1bccc57fe4baf /camel
parentc3b6d117ee155a571d8c4da01b81b6855e26e6f6 (diff)
downloadgsoc2013-evolution-207652677441264ca1e51d06898b37ea4164c8e2.tar.gz
gsoc2013-evolution-207652677441264ca1e51d06898b37ea4164c8e2.tar.zst
gsoc2013-evolution-207652677441264ca1e51d06898b37ea4164c8e2.zip
convenience functions to canonicalize the host and port values of a
* camel-service.c (camel_service_gethost, camel_service_getport): convenience functions to canonicalize the host and port values of a service's URL. * providers/pop3/camel-pop3-store.c: use them svn path=/trunk/; revision=2216
Diffstat (limited to 'camel')
-rw-r--r--camel/ChangeLog5
-rw-r--r--camel/camel-service.c88
-rw-r--r--camel/camel-service.h10
-rw-r--r--camel/providers/pop3/camel-pop3-store.c31
4 files changed, 113 insertions, 21 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index b94ab8d079..c8cebe07d1 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,5 +1,10 @@
2000-03-28 Dan Winship <danw@helixcode.com>
+ * camel-service.c (camel_service_gethost,
+ camel_service_getport): convenience functions to canonicalize
+ the host and port values of a service's URL.
+ * providers/pop3/camel-pop3-store.c: use them
+
* providers/mbox/camel-mbox-folder.c
(_check_get_or_maybe_generate_summary_file): Make this work when
the inbox file doesn't yet exist.
diff --git a/camel/camel-service.c b/camel/camel-service.c
index 394a163ae0..01b72e1a70 100644
--- a/camel/camel-service.c
+++ b/camel/camel-service.c
@@ -28,6 +28,9 @@
#include "camel-log.h"
#include "camel-exception.h"
+#include <ctype.h>
+#include <stdlib.h>
+
static GtkObjectClass *parent_class=NULL;
/* Returns the class for a CamelService */
@@ -418,3 +421,88 @@ camel_service_free_auth_types (CamelService *service, GList *authtypes)
{
CSERV_CLASS (service)->free_auth_types (service, authtypes);
}
+
+
+
+/* URL utility routines */
+
+/**
+ * camel_service_gethost: get a hostent for a CamelService's host
+ * @service: a CamelService
+ * @ex: a CamelException
+ *
+ * This is a convenience function to do a gethostbyname on the host
+ * for the service's URL.
+ *
+ * Return value: a (statically-allocated) hostent.
+ **/
+struct hostent *
+camel_service_gethost (CamelService *service, CamelException *ex)
+{
+ struct hostent *h;
+ char *hostname;
+
+ if (service->url->host)
+ hostname = service->url->host;
+ else
+ hostname = "localhost";
+ h = gethostbyname (hostname);
+ if (!h) {
+ extern int h_errno;
+
+ if (h_errno == HOST_NOT_FOUND || h_errno == NO_DATA) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_URL_INVALID,
+ "No such host %s.", hostname);
+ } else {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
+ "Temporarily unable to look up "
+ "hostname %s.", hostname);
+ }
+ return NULL;
+ }
+
+ return h;
+}
+
+/**
+ * camel_service_getport: get the port number for a service's URL
+ * @service: a CamelService
+ * @default_name: the default service name if none is provided by the URL
+ * @default_number: the default port number if the @default_name lookup fails
+ * @proto: the protocol (eg, "tcp") to be used
+ * @ex: a CamelExcption
+ *
+ * This is a convenience function to get the port number for a service
+ * based on the service's URL (which may contain either a numeric
+ * or symbolic port name) and the provided defaults.
+ *
+ * Return value: a port number, or -1 if the user specified a port name
+ * that could not be resolved.
+ **/
+int
+camel_service_getport (CamelService *service, char *default_port,
+ int default_number, char *proto, CamelException *ex)
+{
+ struct servent *s;
+ char *port;
+
+ if (service->url->port)
+ port = service->url->port;
+ else
+ port = default_port;
+
+ if (isdigit (*port))
+ return htons (atoi (port));
+
+ s = getservbyname (port, proto);
+ if (s)
+ return s->s_port;
+
+
+ if (port == service->url->port) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_URL_INVALID,
+ "Unknown port `%s'", port);
+ return -1;
+ } else
+ return default_number;
+}
diff --git a/camel/camel-service.h b/camel/camel-service.h
index 521db58104..2da9c57f69 100644
--- a/camel/camel-service.h
+++ b/camel/camel-service.h
@@ -35,6 +35,7 @@ extern "C" {
#endif /* __cplusplus }*/
#include <gtk/gtk.h>
+#include <netdb.h>
#include "camel-types.h"
#include "url-util.h"
@@ -114,6 +115,15 @@ GList * camel_service_query_auth_types (CamelService *service);
void camel_service_free_auth_types (CamelService *service,
GList *authtypes);
+/* convenience functions */
+struct hostent * camel_service_gethost (CamelService *service,
+ CamelException *ex);
+int camel_service_getport (CamelService *service,
+ char *default_name,
+ int default_number,
+ char *proto,
+ CamelException *ex);
+
/* Standard Gtk function */
GtkType camel_service_get_type (void);
diff --git a/camel/providers/pop3/camel-pop3-store.c b/camel/providers/pop3/camel-pop3-store.c
index 8b9ff03fac..543a6ce532 100644
--- a/camel/providers/pop3/camel-pop3-store.c
+++ b/camel/providers/pop3/camel-pop3-store.c
@@ -29,7 +29,6 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <errno.h>
-#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -44,6 +43,9 @@
#include "md5-utils.h"
#include "url-util.h"
+/* Specified in RFC 1939 */
+#define POP3_PORT 110
+
static CamelServiceClass *service_class = NULL;
static void finalize (GtkObject *object);
@@ -203,28 +205,19 @@ pop3_connect (CamelService *service, CamelException *ex)
{
struct hostent *h;
struct sockaddr_in sin;
- int fd, status, apoplen;
+ int port, fd, status, apoplen;
char *buf, *apoptime, *pass;
CamelPop3Store *store = CAMEL_POP3_STORE (service);
if (!service_class->connect (service, ex))
return FALSE;
- h = gethostbyname (service->url->host);
- if (!h) {
- extern int h_errno;
- if (h_errno == HOST_NOT_FOUND || h_errno == NO_DATA) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_URL_INVALID,
- "No such host %s.",
- service->url->host);
- } else {
- camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
- "Temporarily unable to look up "
- "hostname %s.",
- service->url->host);
- }
+ h = camel_service_gethost (service, ex);
+ if (!h)
+ return FALSE;
+ port = camel_service_getport (service, "pop3", POP3_PORT, "tcp", ex);
+ if (port == -1)
return FALSE;
- }
pass = g_strdup (service->url->passwd);
if (!pass) {
@@ -240,11 +233,7 @@ pop3_connect (CamelService *service, CamelException *ex)
}
sin.sin_family = h->h_addrtype;
- /* XXX this is all bad */
- if (service->url->port && *service->url->port)
- sin.sin_port = htons (atoi (service->url->port));
- else
- sin.sin_port = htons (110);
+ sin.sin_port = port;
memcpy (&sin.sin_addr, h->h_addr, sizeof (sin.sin_addr));
fd = socket (h->h_addrtype, SOCK_STREAM, 0);
letions'>-7/+82 * - update to jpeg-8dinoex2010-02-051-0/+1 * - Update to 2.1miwi2009-12-223-85/+149 * Reset maintainer at his request due to current lack of time.linimon2009-08-281-1/+1 * - Chase audio/libgpod shlib bumpmiwi2009-08-081-2/+2 * - bump all port that indirectly depends on libjpeg and have not yet been bump...dinoex2009-07-311-0/+1 * - Update to 0.15.0miwi2009-03-143-5/+12 * - USE_PYTHONDISTUTILS is nothing, removepav2009-01-091-1/+0 * - Update to 0.14.0wxs2008-12-173-4/+8 * Update to 0.13.1wxs2008-11-032-4/+4 * - Update to 0.13.0miwi2008-10-112-4/+4 * - Update to 0.12.2miwi2008-08-092-6/+5 * Add dependency on pysqlite2.wxs2008-07-221-3/+5 * - Update to 0.12.0pav2008-07-163-4/+6 * - Update to 0.11.3pav2008-06-122-6/+6 * Bump portrevision due to upgrade of devel/gettext.edwin2008-06-061-0/+1 * - Update to 0.11.2miwi2008-05-022-5/+5 * - Update to 0.11.1miwi2008-03-303-5/+6 * - Fix vim related typo and unbreak INDEX.tmclaugh2008-03-071-1/+1 * - Add missing RUN_DEPENDS on devel/xdg-utilstmclaugh2008-03-071-1/+3 * Update to 0.11.0ehaupt2008-02-273-6/+8 * - Update to 0.10.4miwi2008-02-013-5/+5 * Bump PORTREVISION for ports affected by libgpod library version bump.danfe2008-01-071-0/+1 * Chase libgpod version bump.danfe2008-01-071-1/+1 * - Update to 0.10.3pav2007-12-163-7/+12