* src/modest-protocol-mgr.[ch], src/modest-pair.[ch]:
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Sun, 29 Oct 2006 09:15:22 +0000 (09:15 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Sun, 29 Oct 2006 09:15:22 +0000 (09:15 +0000)
  - adding missing files

pmo-trunk-r477

src/modest-pair.c [new file with mode: 0644]
src/modest-pair.h [new file with mode: 0644]
src/modest-protocol-mgr.c [new file with mode: 0644]
src/modest-protocol-mgr.h [new file with mode: 0644]

diff --git a/src/modest-pair.c b/src/modest-pair.c
new file mode 100644 (file)
index 0000000..4d5adca
--- /dev/null
@@ -0,0 +1,73 @@
+/* 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 "modest-pair.h"
+
+ModestPair*
+modest_pair_new     (gpointer first, gpointer second, gboolean own)
+{
+       ModestPair *pair;
+
+       pair = g_new (ModestPair, 1);
+
+       pair->first = first;
+       pair->second = second;
+       pair->own = own;
+       
+       return pair;
+}
+
+
+void
+modest_pair_destroy (ModestPair *pair)
+{
+       if (!pair)
+               return;
+
+       if (pair->own) {
+               g_free (pair->first);
+               g_free (pair->second);
+       }
+       g_free (pair);
+}
+
+
+
+
+GSList*
+modest_pair_gslist_destroy (GSList *pairs)
+{
+       GSList *cursor = pairs;
+       while (cursor) {
+               modest_pair_destroy ((ModestPair*)cursor->data);
+               cursor = cursor->next;
+       }
+       g_slist_free (pairs);
+       return NULL;
+}
diff --git a/src/modest-pair.h b/src/modest-pair.h
new file mode 100644 (file)
index 0000000..d59cd0c
--- /dev/null
@@ -0,0 +1,61 @@
+/* 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_PAIR_H__
+#define __MODEST_PAIR_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+struct _ModestPair {
+       gpointer *first;
+       gpointer *second;
+       gboolean own;
+};
+typedef struct _ModestPair ModestPair;
+
+
+/**
+ * modest_pait_new
+ *
+ * create a new ModestPair instance
+ *
+ * Returns: a newly allocated ModestPair instance
+ */
+ModestPair* modest_pair_new           (gpointer first, gpointer second, gboolean own);
+void        modest_pair_destroy       (ModestPair *pair);
+
+
+GSList    *modest_pair_gslist_destroy (GSList *pairs);
+
+
+G_END_DECLS
+
+#endif /* __MODEST_PAIR_H__ */
diff --git a/src/modest-protocol-mgr.c b/src/modest-protocol-mgr.c
new file mode 100644 (file)
index 0000000..dd566d3
--- /dev/null
@@ -0,0 +1,281 @@
+/* modest-protocol-mgr.c */
+
+/* insert (c)/licensing information) */
+
+#include "modest-protocol-mgr.h"
+#include <string.h> /* strcmp */
+#include <modest-pair.h>
+
+/* 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
new file mode 100644 (file)
index 0000000..72d606e
--- /dev/null
@@ -0,0 +1,108 @@
+/* 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 <glib-object.h>
+#include <glib/gi18n.h>
+#include <modest-pair.h>
+
+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"
+
+
+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
+};
+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__ */
+