From 0481ffb62ae390a89a75ac7a37173b4123845ee7 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Mon, 24 Jul 2006 14:36:29 +0000 Subject: [PATCH] * add functions for getting lists of store/transport protocols * some cleanups / improvements pmo-trunk-r414 --- src/modest-proto.c | 58 ++++++++++++++++++++++++++++++++++++---------------- src/modest-proto.h | 33 +++++++++++++++++++++++++++--- 2 files changed, 70 insertions(+), 21 deletions(-) diff --git a/src/modest-proto.c b/src/modest-proto.c index 6e8b329..3796453 100644 --- a/src/modest-proto.c +++ b/src/modest-proto.c @@ -31,26 +31,34 @@ #include #include "modest-proto.h" +static const gchar* transport_protos[] = { + MODEST_PROTO_SENDMAIL, + MODEST_PROTO_SMTP, + NULL +}; + +static const gchar* store_protos[] = { + MODEST_PROTO_NONE, + MODEST_PROTO_POP, + MODEST_PROTO_IMAP, + MODEST_PROTO_MAILDIR, + MODEST_PROTO_MBOX, + NULL +}; gboolean -modest_proto_is_valid (const gchar *proto) +modest_proto_is_valid (const gchar *proto, gboolean store_proto) { int i; - static const gchar* protos[] = { - MODEST_PROTO_SENDMAIL, - MODEST_PROTO_SMTP, - MODEST_PROTO_POP, - MODEST_PROTO_IMAP, - NULL - }; - if (!proto) - return FALSE; + g_return_val_if_fail (proto, FALSE); - for (i = 0; protos[i]; ++i) { + const gchar** protos = (const gchar**) + store_proto ? store_protos : transport_protos; + + for (i = 0; protos[i]; ++i) if (strcmp(protos[i], proto) == 0) return TRUE; - } return FALSE; } @@ -59,14 +67,28 @@ modest_proto_is_valid (const gchar *proto) ModestProtoType modest_proto_type (const gchar *proto) { - if (!modest_proto_is_valid(proto)) { - g_warning ("invalid protocol %s", proto); - return -1; - } - - /* trick */ + g_return_val_if_fail (proto, -1); + g_return_val_if_fail (modest_proto_is_valid (proto, TRUE) || + modest_proto_is_valid (proto, FALSE), + -1); + /* trick */ if (proto[0] == 's') return MODEST_PROTO_TYPE_TRANSPORT; else return MODEST_PROTO_TYPE_STORE; } + + + +const gchar** +modest_proto_store_protos (void) +{ + return (const gchar **) store_protos; +} + + +const gchar** +modest_proto_transport_protos (void) +{ + return (const gchar**) transport_protos; +} diff --git a/src/modest-proto.h b/src/modest-proto.h index 17906b9..ce99bdb 100644 --- a/src/modest-proto.h +++ b/src/modest-proto.h @@ -35,10 +35,15 @@ #include + #define MODEST_PROTO_SENDMAIL "sendmail" #define MODEST_PROTO_SMTP "smtp" + +#define MODEST_PROTO_NONE "none" #define MODEST_PROTO_POP "pop" #define MODEST_PROTO_IMAP "imap" +#define MODEST_PROTO_MAILDIR "maildir" +#define MODEST_PROTO_MBOX "mbox" enum { MODEST_PROTO_TYPE_ANY = 0, @@ -50,12 +55,13 @@ typedef gint ModestProtoType; /** * modest_proto_is_valid: * @proto: a string describing the protocol - * - * checks if proto is a valid protocol + * @store_proto: is this a store proto? + * + * checks if proto is a valid protocol of the given type * * Returns: TRUE if proto is valid, FALSE otherwise */ -gboolean modest_proto_is_valid (const gchar *proto); +gboolean modest_proto_is_valid (const gchar *proto, gboolean store_proto); /** * modest_proto_type: @@ -67,5 +73,26 @@ gboolean modest_proto_is_valid (const gchar *proto); */ ModestProtoType modest_proto_type (const gchar *proto); +/** + * modest_store_protos: + * + * return a list of all available store protos + * + * Returns: a newly allocated, NULL-terminated list of of store protocols + */ +const gchar** modest_proto_store_protos (void); + + +/** + * modest_transport_protos: + * + * return a list of all available store protos + * + * Returns: a newly allocated, NULL-terminated list of of store protocols + */ +const gchar** modest_proto_transport_protos (void); + + + #endif /*__MODEST_SERVER_PROTO_H__*/ -- 1.7.9.5