From: Dirk-Jan C. Binnema Date: Mon, 15 Jan 2007 10:30:39 +0000 (+0000) Subject: * modest-proto*: X-Git-Tag: git_migration_finished~4260 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=ad5b9c325eeefcabb682ad025ddd47f25801acd9 * modest-proto*: replace modest-proto and modest-protocol-mgr with modest-protocol-info. changes to other code in next commits. pmo-trunk-r619 --- diff --git a/src/modest-proto.c b/src/modest-proto.c deleted file mode 100644 index f64aeb0..0000000 --- a/src/modest-proto.c +++ /dev/null @@ -1,121 +0,0 @@ -/* Copyright (c) 2006, Nokia Corporation - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the Nokia Corporation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -#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 -}; - - -static const gchar* security_protos[] = { - MODEST_SECURITY_PROTO_NONE, - MODEST_SECURITY_PROTO_SSL, - MODEST_SECURITY_PROTO_TLS, - NULL -}; - -static const gchar* auth_protos[] = { - MODEST_AUTH_PROTO_PASSWORD, - NULL -}; - - -gboolean -modest_proto_is_valid (const gchar *proto, gboolean store_proto) -{ - int i; - - g_return_val_if_fail (proto, FALSE); - - 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; -} - - -ModestProtoType -modest_proto_type (const gchar *proto) -{ - 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; -} - -const gchar** -modest_proto_security_protos (void) -{ - return (const gchar**) security_protos; -} - -const gchar** -modest_proto_auth_protos (void) -{ - return (const gchar**) auth_protos; -} - diff --git a/src/modest-proto.h b/src/modest-proto.h deleted file mode 100644 index 63bcddc..0000000 --- a/src/modest-proto.h +++ /dev/null @@ -1,126 +0,0 @@ -/* Copyright (c) 2006, Nokia Corporation - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the Nokia Corporation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -/* modest-proto.h */ - -#ifndef __MODEST_PROTO_H__ -#define __MODEST_PROTO_H__ - -#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" - - -#define MODEST_SECURITY_PROTO_NONE "none" -#define MODEST_SECURITY_PROTO_SSL "ssl" -#define MODEST_SECURITY_PROTO_TLS "tls" - - -#define MODEST_AUTH_PROTO_PASSWORD "password" - - - -enum { - MODEST_PROTO_TYPE_ANY = 0, - MODEST_PROTO_TYPE_TRANSPORT = 1, - MODEST_PROTO_TYPE_STORE = 2, -}; -typedef gint ModestProtoType; - -/** - * modest_proto_is_valid: - * @proto: a string describing the 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 store_proto); - -/** - * modest_proto_type: - * @proto: a string describing the protocol - * - * converts the string proto into a ModestProtoType - * - * Returns: a valid ModestProtoType corresponding to proto - */ -ModestProtoType modest_proto_type (const gchar *proto); - -/** - * modest_proto_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_proto_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); - - -/** - * modest_proto_security_protos: - * - * return a list of all available security (connection) protocols - * - * Returns: a newly allocated, NULL-terminated list of of store protocols - */ -const gchar** modest_proto_security_protos (void); - - -/** - * modest_proto_auth_protos: - * - * return a list of all available authentication protocols - * - * Returns: a newly allocated, NULL-terminated list of of store protocols - */ -const gchar** modest_proto_auth_protos (void); - -#endif /*__MODEST_SERVER_PROTO_H__*/ - diff --git a/src/modest-protocol-info.c b/src/modest-protocol-info.c new file mode 100644 index 0000000..0508daf --- /dev/null +++ b/src/modest-protocol-info.c @@ -0,0 +1,188 @@ +/* Copyright (c) 2006, Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Nokia Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include /* strcmp */ +#include +#include + + +typedef struct { + ModestProtocol proto; + const gchar* name; + const gchar* display_name; +} ProtocolInfo; + +static const ProtocolInfo ProtocolMap[] = { + { MODEST_PROTOCOL_TRANSPORT_SENDMAIL, "sendmail", N_("Sendmail") }, + { MODEST_PROTOCOL_TRANSPORT_SMTP, "smtp", N_("SMTP Server") }, + + { MODEST_PROTOCOL_STORE_POP, "pop", N_("POP3") }, + { MODEST_PROTOCOL_STORE_IMAP, "imap", N_("IMAPv4") }, + { MODEST_PROTOCOL_STORE_MAILDIR, "maildir", N_("Maildir") }, + { MODEST_PROTOCOL_STORE_MBOX, "mbox", N_("MBox") }, + + { MODEST_PROTOCOL_SECURITY_SSL, "ssl", N_("SSL") }, + { MODEST_PROTOCOL_SECURITY_TLS, "tls", N_("TLS") }, + + { MODEST_PROTOCOL_AUTH_NONE, "none", N_("none") }, + { MODEST_PROTOCOL_AUTH_PASSWORD, "password", N_("Password") } +}; +const guint PROTOCOL_MAP_SIZE = sizeof(ProtocolMap)/sizeof(ProtocolInfo); + + +GSList* +modest_protocol_info_get_protocol_list (ModestProtocolType type) +{ + GSList *proto_list; + int i; + + g_return_val_if_fail (type > MODEST_PROTOCOL_TYPE_UNKNOWN && + type < MODEST_PROTOCOL_TYPE_NUM, + NULL); + + for (i = 0; i != PROTOCOL_MAP_SIZE; ++i) { + ProtocolInfo info = (ProtocolInfo)ProtocolMap[i]; + if (modest_protocol_info_get_protocol_type(info.proto) == type) + proto_list = g_slist_append (proto_list, GINT_TO_POINTER(info.proto)); + } + return proto_list; +} + + + +ModestPairList* +modest_protocol_info_get_protocol_pair_list (ModestProtocolType type) +{ + ModestPairList *proto_list; + int i; + + g_return_val_if_fail (type > MODEST_PROTOCOL_TYPE_UNKNOWN && type < MODEST_PROTOCOL_TYPE_NUM, + NULL); + + for (i = 0; i != PROTOCOL_MAP_SIZE; ++i) { + ProtocolInfo info = (ProtocolInfo)ProtocolMap[i]; + if (modest_protocol_info_get_protocol_type(info.proto) == type) + proto_list = g_slist_append (proto_list, + (gpointer)modest_pair_new( + (gpointer)info.name, + (gpointer)info.display_name, + FALSE)); + } + return proto_list; +} + + +ModestProtocolType +modest_protocol_info_get_protocol_type (ModestProtocol proto) +{ + switch (proto) { + case MODEST_PROTOCOL_TRANSPORT_SENDMAIL: + case MODEST_PROTOCOL_TRANSPORT_SMTP: + return MODEST_PROTOCOL_TYPE_TRANSPORT; + + case MODEST_PROTOCOL_STORE_POP: + case MODEST_PROTOCOL_STORE_IMAP: + case MODEST_PROTOCOL_STORE_MAILDIR: + case MODEST_PROTOCOL_STORE_MBOX: + return MODEST_PROTOCOL_TYPE_STORE; + + case MODEST_PROTOCOL_SECURITY_SSL: + case MODEST_PROTOCOL_SECURITY_TLS: + return MODEST_PROTOCOL_TYPE_SECURITY; + + case MODEST_PROTOCOL_AUTH_NONE: + case MODEST_PROTOCOL_AUTH_PASSWORD: + return MODEST_PROTOCOL_TYPE_AUTH; + + default: + g_return_val_if_reached (MODEST_PROTOCOL_TYPE_UNKNOWN); + } +} + + +ModestProtocol +modest_protocol_info_get_protocol (const gchar* name) +{ + int i; + g_return_val_if_fail (name, MODEST_PROTOCOL_UNKNOWN); + + for (i = 0; i != PROTOCOL_MAP_SIZE; ++i) { + ProtocolInfo info = (ProtocolInfo)ProtocolMap[i]; + if (strcmp(name, info.name) == 0) + return info.proto; + } + + return MODEST_PROTOCOL_UNKNOWN; +} + + + + +/* get either the name or the display_name for the protocol */ +static const gchar* +get_protocol_string (ModestProtocol proto, gboolean get_name) +{ + int i; + g_return_val_if_fail (modest_protocol_info_get_protocol_type(proto) != + MODEST_PROTOCOL_TYPE_UNKNOWN, NULL); + + for (i = 0; i != PROTOCOL_MAP_SIZE; ++i) { + ProtocolInfo info = (ProtocolInfo)ProtocolMap[i]; + if (info.proto == proto) + return get_name ? info.name : info.display_name; + } + g_return_val_if_reached (NULL); +} + +const gchar* +modest_protocol_info_get_protocol_name (ModestProtocol proto) +{ + return get_protocol_string (proto, TRUE); +} + + +const gchar* +modest_protocol_info_get_protocol_display_name (ModestProtocol proto) +{ + return get_protocol_string (proto, FALSE); +} + + +gboolean +modest_protocol_info_protocol_is_local_store (ModestProtocol proto) +{ + g_return_val_if_fail (modest_protocol_info_get_protocol_type (proto) != + MODEST_PROTOCOL_TYPE_UNKNOWN, FALSE); + + /* may add MH later */ + return proto == MODEST_PROTOCOL_STORE_MBOX || proto == MODEST_PROTOCOL_STORE_MAILDIR; +} + + diff --git a/src/modest-protocol-info.h b/src/modest-protocol-info.h new file mode 100644 index 0000000..d4b2a85 --- /dev/null +++ b/src/modest-protocol-info.h @@ -0,0 +1,160 @@ +/* Copyright (c) 2006, Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Nokia Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __MODEST_PROTOCOL_INFO_H__ +#define __MODEST_PROTOCOL_INFO_H__ + +#include + +G_BEGIN_DECLS + +/* NOTE: be careful to check modest-protocol-info.c + * if you make any changes here */ +typedef enum { + MODEST_PROTOCOL_UNKNOWN, + + MODEST_PROTOCOL_TRANSPORT_SENDMAIL, + MODEST_PROTOCOL_TRANSPORT_SMTP, + + MODEST_PROTOCOL_STORE_POP, + MODEST_PROTOCOL_STORE_IMAP, + MODEST_PROTOCOL_STORE_MAILDIR, + MODEST_PROTOCOL_STORE_MBOX, + + MODEST_PROTOCOL_SECURITY_SSL, + MODEST_PROTOCOL_SECURITY_TLS, + + MODEST_PROTOCOL_AUTH_NONE, + MODEST_PROTOCOL_AUTH_PASSWORD, + + MODEST_PROTOCOL_NUM +} ModestProtocol; + + +typedef enum { + MODEST_PROTOCOL_TYPE_UNKNOWN, + MODEST_PROTOCOL_TYPE_TRANSPORT, + MODEST_PROTOCOL_TYPE_STORE, + MODEST_PROTOCOL_TYPE_SECURITY, + MODEST_PROTOCOL_TYPE_AUTH, + + MODEST_PROTOCOL_TYPE_NUM +} ModestProtocolType; + + +/** + * modest_protocol_info_get_list: + * @type: the type of list you want, it should NOT be MODEST_PROTOCOL_TYPE_UNKNOWN + * + * return the list of protocols of the given @type. + * the elements of the returned list are ModestProtocols (use GPOINTER_TO_INT to get it) + * + * Returns: a list of protocols of the given @type; after use, it should be freed + * with g_slist_free. The elements should not be freed, as there is no memory allocated + * for them. + */ +GSList* modest_protocol_info_get_protocol_list (ModestProtocolType type); + + +/** + * modest_protocol_info_get_list: + * @type: the type of list you want, it should NOT be MODEST_PROTOCOL_TYPE_UNKNOWN + * + * return the list of -tupels of the given @type. + * the elements of the returned list are ModestPairs + * this is a convenience function for use with ModestComboBox + * + * Returns: a list of protocols of the given @type; after use, it should be freed + * with modest_pair_list_free + */ +ModestPairList* modest_protocol_info_get_protocol_pair_list (ModestProtocolType type); + + +/** + * modest_protocol_info_get_protocol_type: + * @proto: the ModestProtocol you'd like to query for its type + * + * return ModestProtocolType for the protocol + * + * Returns: the protocol type or MODEST_PROTOCOL_TYPE_UNKNOWN + */ +ModestProtocolType modest_protocol_info_get_protocol_type (ModestProtocol proto); + + +/** + * modest_protocol_info_get_protocol_type: + * @name: the name of the ModestProtocol + * + * return the id of the protocol with the given name + * + * Returns: the id of the protocol or MODEST_PROTOCOL_UNKNOWN + */ +ModestProtocol modest_protocol_info_get_protocol (const gchar* name); + + +/** + * modest_protocol_info_get_protocol_name: + * @proto: the protocol you are looking for + * + * return the string id of the proto (such as "imap", or "tls") + * + * Returns: string id of the proto as a constant string, that should NOT be modified or freed + */ +const gchar* modest_protocol_info_get_protocol_name (ModestProtocol proto); + +/** + * modest_protocol_info_get_protocol_display_name: + * @proto: the protocol you are looking for + * + * return the string id of the proto (such as "imap", or "tls") + * + * Returns: string id of the proto as a constant string, that should NOT be modified or freed + * + */ +const gchar* modest_protocol_info_get_protocol_display_name (ModestProtocol proto); + + + +/** + * modest_protocol_info_protocol_is_local_store: + * @proto: the protocol + * + * is this protocol a local store protocol? + * + * Returns: TRUE if it is a local store, FALSE otherwise + * + */ +gboolean modest_protocol_info_protocol_is_local_store (ModestProtocol proto); + + + + +G_END_DECLS +#endif /* __MODEST_PROTOCOL_INFO_H__ */ + diff --git a/src/modest-protocol-mgr.c b/src/modest-protocol-mgr.c deleted file mode 100644 index 8fab57a..0000000 --- a/src/modest-protocol-mgr.c +++ /dev/null @@ -1,307 +0,0 @@ -/* Copyright (c) 2006, Nokia Corporation - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the Nokia Corporation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include /* strcmp */ -#include "modest-protocol-mgr.h" -#include - -/* include other impl specific header files */ - -/* 'private'/'protected' functions */ -static void modest_protocol_mgr_class_init (ModestProtocolMgrClass *klass); -static void modest_protocol_mgr_init (ModestProtocolMgr *obj); -static void modest_protocol_mgr_finalize (GObject *obj); -/* list my signals */ -enum { - /* MY_SIGNAL_1, */ - /* MY_SIGNAL_2, */ - LAST_SIGNAL -}; - -typedef struct _ModestProtocolMgrPrivate ModestProtocolMgrPrivate; -struct _ModestProtocolMgrPrivate { - GSList *transport_protos; - GSList *store_protos; - GSList *security_protos; - GSList *auth_protos; -}; -#define MODEST_PROTOCOL_MGR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ - MODEST_TYPE_PROTOCOL_MGR, \ - ModestProtocolMgrPrivate)) -/* globals */ -static GObjectClass *parent_class = NULL; - -/* uncomment the following if you have defined any signals */ -/* static guint signals[LAST_SIGNAL] = {0}; */ - -GType -modest_protocol_mgr_get_type (void) -{ - static GType my_type = 0; - if (!my_type) { - static const GTypeInfo my_info = { - sizeof(ModestProtocolMgrClass), - NULL, /* base init */ - NULL, /* base finalize */ - (GClassInitFunc) modest_protocol_mgr_class_init, - NULL, /* class finalize */ - NULL, /* class data */ - sizeof(ModestProtocolMgr), - 1, /* n_preallocs */ - (GInstanceInitFunc) modest_protocol_mgr_init, - NULL - }; - my_type = g_type_register_static (G_TYPE_OBJECT, - "ModestProtocolMgr", - &my_info, 0); - } - return my_type; -} - -static void -modest_protocol_mgr_class_init (ModestProtocolMgrClass *klass) -{ - GObjectClass *gobject_class; - gobject_class = (GObjectClass*) klass; - - parent_class = g_type_class_peek_parent (klass); - gobject_class->finalize = modest_protocol_mgr_finalize; - - g_type_class_add_private (gobject_class, sizeof(ModestProtocolMgrPrivate)); - - /* signal definitions go here, e.g.: */ -/* signals[MY_SIGNAL_1] = */ -/* g_signal_new ("my_signal_1",....); */ -/* signals[MY_SIGNAL_2] = */ -/* g_signal_new ("my_signal_2",....); */ -/* etc. */ -} - -static void -modest_protocol_mgr_init (ModestProtocolMgr *obj) -{ - ModestProtocolMgrPrivate *priv; - priv = MODEST_PROTOCOL_MGR_GET_PRIVATE (obj); - - priv->transport_protos = NULL; - priv->store_protos = NULL; - priv->security_protos = NULL; - priv->auth_protos = NULL; -} - - - - -static void -modest_protocol_mgr_finalize (GObject *obj) -{ - ModestProtocolMgrPrivate *priv; - priv = MODEST_PROTOCOL_MGR_GET_PRIVATE (obj); - - priv->transport_protos = - modest_pair_gslist_destroy (priv->transport_protos); - priv->store_protos = - modest_pair_gslist_destroy (priv->store_protos); - priv->security_protos = - modest_pair_gslist_destroy (priv->security_protos); - priv->auth_protos = - modest_pair_gslist_destroy (priv->auth_protos); - - G_OBJECT_CLASS(parent_class)->finalize (obj); -} - -ModestProtocolMgr* -modest_protocol_mgr_new (void) -{ - return MODEST_PROTOCOL_MGR(g_object_new(MODEST_TYPE_PROTOCOL_MGR, NULL)); -} - - - -const GSList* -modest_protocol_mgr_get_transport_protocols (ModestProtocolMgr* self) -{ - ModestProtocolMgrPrivate *priv; - - g_return_val_if_fail (self, NULL); - - priv = MODEST_PROTOCOL_MGR_GET_PRIVATE (self); - - if (!priv->transport_protos) { - priv->transport_protos = - g_slist_append (priv->transport_protos, - (gpointer)modest_pair_new( - (gpointer)MODEST_PROTOCOL_TRANSPORT_SENDMAIL, - (gpointer)_("Sendmail"), FALSE)); - priv->transport_protos = - g_slist_append (priv->transport_protos, - (gpointer)modest_pair_new( - (gpointer)MODEST_PROTOCOL_TRANSPORT_SMTP, - (gpointer)_("SMTP-server"), FALSE)); - } - return priv->transport_protos; -} - - -const GSList* -modest_protocol_mgr_get_store_protocols (ModestProtocolMgr* self) -{ - ModestProtocolMgrPrivate *priv; - - g_return_val_if_fail (self, NULL); - - priv = MODEST_PROTOCOL_MGR_GET_PRIVATE (self); - - if (!priv->store_protos) { - priv->store_protos = - g_slist_append (priv->store_protos, - (gpointer)modest_pair_new( - (gpointer)MODEST_PROTOCOL_STORE_POP, - (gpointer)_("POP3"), FALSE)); - priv->store_protos = - g_slist_append (priv->store_protos, - (gpointer)modest_pair_new( - (gpointer)MODEST_PROTOCOL_STORE_IMAP, - (gpointer)_("IMAP v4"), FALSE)); - priv->store_protos = - g_slist_append (priv->store_protos, - (gpointer)modest_pair_new( - (gpointer)MODEST_PROTOCOL_STORE_MBOX, - (gpointer)_("Mbox"), FALSE)); - priv->store_protos = - g_slist_append (priv->store_protos, - (gpointer)modest_pair_new( - (gpointer)MODEST_PROTOCOL_STORE_MAILDIR, - (gpointer)_("Maildir"), FALSE)); - } - return priv->store_protos; -} - -const GSList* -modest_protocol_mgr_get_security_protocols (ModestProtocolMgr* self) -{ - ModestProtocolMgrPrivate *priv; - - g_return_val_if_fail (self, NULL); - - priv = MODEST_PROTOCOL_MGR_GET_PRIVATE (self); - - if (!priv->security_protos) { - priv->security_protos = - g_slist_append (priv->security_protos, - (gpointer)modest_pair_new( - (gpointer)MODEST_PROTOCOL_SECURITY_NONE, - (gpointer)_("None"), FALSE)); - priv->security_protos = - g_slist_append (priv->security_protos, - (gpointer)modest_pair_new( - (gpointer)MODEST_PROTOCOL_SECURITY_TLS, - (gpointer)_("TLS"), FALSE)); - priv->security_protos = - g_slist_append (priv->security_protos, - (gpointer)modest_pair_new( - (gpointer)MODEST_PROTOCOL_SECURITY_SSL, - (gpointer)_("SSL"), FALSE)); - } - return priv->security_protos; -} - - - -const GSList* -modest_protocol_mgr_get_auth_protocols (ModestProtocolMgr* self) -{ - ModestProtocolMgrPrivate *priv; - - g_return_val_if_fail (self, NULL); - - priv = MODEST_PROTOCOL_MGR_GET_PRIVATE (self); - - if (!priv->auth_protos) { - priv->auth_protos = - g_slist_append (priv->auth_protos, - (gpointer)modest_pair_new( - (gpointer)MODEST_PROTOCOL_AUTH_NONE, - (gpointer)_("None"), FALSE)); - priv->auth_protos = - g_slist_append (priv->auth_protos, - (gpointer)modest_pair_new( - (gpointer)MODEST_PROTOCOL_AUTH_PASSWORD, - (gpointer)_("Password"), FALSE)); - } - return priv->auth_protos; -} - - - - -gboolean -modest_protocol_mgr_protocol_is_valid (ModestProtocolMgr* self, const gchar* proto, - ModestProtocolType type) -{ - gboolean found = FALSE; - - switch (type) { - case MODEST_PROTOCOL_TYPE_ANY: - - case MODEST_PROTOCOL_TYPE_TRANSPORT: - found = found - || strcmp(proto, MODEST_PROTOCOL_TRANSPORT_SENDMAIL) == 0 - || strcmp(proto, MODEST_PROTOCOL_TRANSPORT_SMTP) == 0; - if (found || type != MODEST_PROTOCOL_TYPE_ANY) - break; - case MODEST_PROTOCOL_TYPE_STORE: - found = found - || strcmp(proto, MODEST_PROTOCOL_STORE_POP) == 0 - || strcmp(proto, MODEST_PROTOCOL_STORE_IMAP) == 0 - || strcmp(proto, MODEST_PROTOCOL_STORE_MAILDIR) == 0 - || strcmp(proto, MODEST_PROTOCOL_STORE_MBOX) == 0; - if (found || type != MODEST_PROTOCOL_TYPE_ANY) - break; - - case MODEST_PROTOCOL_TYPE_SECURITY: - found = found - || strcmp(proto, MODEST_PROTOCOL_SECURITY_NONE) == 0 - || strcmp(proto, MODEST_PROTOCOL_SECURITY_SSL) == 0 - || strcmp(proto, MODEST_PROTOCOL_SECURITY_TLS) == 0; - if (found || type != MODEST_PROTOCOL_TYPE_ANY) - break; - - case MODEST_PROTOCOL_TYPE_AUTH: - found = found - || strcmp(proto, MODEST_PROTOCOL_AUTH_NONE) == 0 - || strcmp(proto, MODEST_PROTOCOL_AUTH_PASSWORD) == 0; - break; - default: - g_warning ("invalid protocol type %d", type); - } - - return found; -} diff --git a/src/modest-protocol-mgr.h b/src/modest-protocol-mgr.h deleted file mode 100644 index 96a2352..0000000 --- a/src/modest-protocol-mgr.h +++ /dev/null @@ -1,105 +0,0 @@ -/* Copyright (c) 2006, Nokia Corporation - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the Nokia Corporation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __MODEST_PROTOCOL_MGR_H__ -#define __MODEST_PROTOCOL_MGR_H__ - -#include -#include - -G_BEGIN_DECLS - -/* convenience macros */ -#define MODEST_TYPE_PROTOCOL_MGR (modest_protocol_mgr_get_type()) -#define MODEST_PROTOCOL_MGR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_PROTOCOL_MGR,ModestProtocolMgr)) -#define MODEST_PROTOCOL_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_PROTOCOL_MGR,GObject)) -#define MODEST_IS_PROTOCOL_MGR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_PROTOCOL_MGR)) -#define MODEST_IS_PROTOCOL_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_PROTOCOL_MGR)) -#define MODEST_PROTOCOL_MGR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_PROTOCOL_MGR,ModestProtocolMgrClass)) - -typedef struct _ModestProtocolMgr ModestProtocolMgr; -typedef struct _ModestProtocolMgrClass ModestProtocolMgrClass; - -struct _ModestProtocolMgr { - GObject parent; - /* insert public members, if any */ -}; - -struct _ModestProtocolMgrClass { - GObjectClass parent_class; - /* insert signal callback declarations, eg. */ - /* void (* my_event) (ModestProtocolMgr* obj); */ -}; - -/* transport */ -#define MODEST_PROTOCOL_TRANSPORT_SENDMAIL "sendmail" -#define MODEST_PROTOCOL_TRANSPORT_SMTP "smtp" - -/* store */ -#define MODEST_PROTOCOL_STORE_NONE "none" -#define MODEST_PROTOCOL_STORE_POP "pop" -#define MODEST_PROTOCOL_STORE_IMAP "imap" -#define MODEST_PROTOCOL_STORE_MAILDIR "maildir" -#define MODEST_PROTOCOL_STORE_MBOX "mbox" - -/* security */ -#define MODEST_PROTOCOL_SECURITY_NONE "none" -#define MODEST_PROTOCOL_SECURITY_SSL "ssl" -#define MODEST_PROTOCOL_SECURITY_TLS "tls" - -/* authentication */ -#define MODEST_PROTOCOL_AUTH_NONE "none" -#define MODEST_PROTOCOL_AUTH_PASSWORD "password" - -typedef enum _ModestProtocolType { - MODEST_PROTOCOL_TYPE_TRANSPORT, - MODEST_PROTOCOL_TYPE_STORE, - MODEST_PROTOCOL_TYPE_SECURITY, - MODEST_PROTOCOL_TYPE_AUTH, - MODEST_PROTOCOL_TYPE_ANY, - MODEST_PROTOCOL_TYPE_NUM -} ModestProtocolType; -/* typedef enum _ModestProtocolType ModestProtocolType; */ - -/* member functions */ -GType modest_protocol_mgr_get_type (void) G_GNUC_CONST; - -ModestProtocolMgr* modest_protocol_mgr_new (void); - -const GSList* modest_protocol_mgr_get_transport_protocols (ModestProtocolMgr *self); -const GSList* modest_protocol_mgr_get_store_protocols (ModestProtocolMgr *self); -const GSList* modest_protocol_mgr_get_security_protocols (ModestProtocolMgr *self); -const GSList* modest_protocol_mgr_get_auth_protocols (ModestProtocolMgr *self); - -gboolean modest_protocol_mgr_protocol_is_valid (ModestProtocolMgr *self, const gchar* proto, - ModestProtocolType type); - -G_END_DECLS -#endif /* __MODEST_PROTOCOL_MGR_H__ */ -