[libgit2-glib] Add a common type for credential classes.



commit b944a55038c20f75e49f533dc3f428212af870f2
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Wed Mar 20 15:24:57 2013 +0100

    Add a common type for credential classes.

 libgit2-glib/Makefile.am           |    2 +
 libgit2-glib/ggit-cred-plaintext.c |    2 +-
 libgit2-glib/ggit-cred-plaintext.h |    7 ++--
 libgit2-glib/ggit-cred.c           |   47 +++++++++++++++++++++++++++++
 libgit2-glib/ggit-cred.h           |   58 ++++++++++++++++++++++++++++++++++++
 libgit2-glib/ggit-types.h          |   31 +++++++++++++++++++
 6 files changed, 142 insertions(+), 5 deletions(-)
---
diff --git a/libgit2-glib/Makefile.am b/libgit2-glib/Makefile.am
index ea3888a..4e610f5 100644
--- a/libgit2-glib/Makefile.am
+++ b/libgit2-glib/Makefile.am
@@ -20,6 +20,7 @@ INST_H_FILES =                                \
        ggit-commit.h                   \
        ggit-config.h                   \
        ggit-config-entry.h             \
+       ggit-cred.h                     \
        ggit-cred-plaintext.h           \
        ggit-diff.h                     \
        ggit-diff-delta.h               \
@@ -63,6 +64,7 @@ C_FILES =                             \
        ggit-config.c                   \
        ggit-config-entry.c             \
        ggit-convert.c                  \
+       ggit-cred.c                     \
        ggit-cred-plaintext.c           \
        ggit-diff.c                     \
        ggit-diff-delta.c               \
diff --git a/libgit2-glib/ggit-cred-plaintext.c b/libgit2-glib/ggit-cred-plaintext.c
index d2b2412..f49ee8b 100644
--- a/libgit2-glib/ggit-cred-plaintext.c
+++ b/libgit2-glib/ggit-cred-plaintext.c
@@ -41,7 +41,7 @@ enum
 
 static void ggit_cred_plaintext_initable_iface_init (GInitableIface  *iface);
 
-G_DEFINE_TYPE_EXTENDED (GgitCredPlaintext, ggit_cred_plaintext, GGIT_TYPE_NATIVE,
+G_DEFINE_TYPE_EXTENDED (GgitCredPlaintext, ggit_cred_plaintext, GGIT_TYPE_CRED,
                         0,
                         G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
                                                ggit_cred_plaintext_initable_iface_init))
diff --git a/libgit2-glib/ggit-cred-plaintext.h b/libgit2-glib/ggit-cred-plaintext.h
index 6a8c297..6a9b61b 100644
--- a/libgit2-glib/ggit-cred-plaintext.h
+++ b/libgit2-glib/ggit-cred-plaintext.h
@@ -23,7 +23,7 @@
 #define __GGIT_CRED_PLAINTEXT_H__
 
 #include <glib-object.h>
-#include <libgit2-glib/ggit-native.h>
+#include <libgit2-glib/ggit-cred.h>
 
 G_BEGIN_DECLS
 
@@ -35,20 +35,19 @@ G_BEGIN_DECLS
 #define GGIT_IS_CRED_PLAINTEXT_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE ((klass), GGIT_TYPE_CRED_PLAINTEXT))
 #define GGIT_CRED_PLAINTEXT_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS ((obj), GGIT_TYPE_CRED_PLAINTEXT, 
GgitCredPlaintextClass))
 
-typedef struct _GgitCredPlaintext              GgitCredPlaintext;
 typedef struct _GgitCredPlaintextClass         GgitCredPlaintextClass;
 typedef struct _GgitCredPlaintextPrivate       GgitCredPlaintextPrivate;
 
 struct _GgitCredPlaintext
 {
-       GgitNative parent;
+       GgitCred parent;
 
        GgitCredPlaintextPrivate *priv;
 };
 
 struct _GgitCredPlaintextClass
 {
-       GgitNativeClass parent_class;
+       GgitCredClass parent_class;
 };
 
 GType                ggit_cred_plaintext_get_type      (void) G_GNUC_CONST;
diff --git a/libgit2-glib/ggit-cred.c b/libgit2-glib/ggit-cred.c
new file mode 100644
index 0000000..2a2a703
--- /dev/null
+++ b/libgit2-glib/ggit-cred.c
@@ -0,0 +1,47 @@
+/*
+ * ggit-cred.c
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2013 - Ignacio Casal Quinteiro
+ *
+ * libgit2-glib is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * libgit2-glib is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with libgit2-glib. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "ggit-cred.h"
+
+// NOTE: this is a simple wrap around GgitNative to have a common point for git_cred types
+
+G_DEFINE_TYPE (GgitCred, ggit_cred, GGIT_TYPE_NATIVE)
+
+static void
+ggit_cred_finalize (GObject *object)
+{
+       G_OBJECT_CLASS (ggit_cred_parent_class)->finalize (object);
+}
+
+static void
+ggit_cred_class_init (GgitCredClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       object_class->finalize = ggit_cred_finalize;
+}
+
+static void
+ggit_cred_init (GgitCred *cred)
+{
+}
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-cred.h b/libgit2-glib/ggit-cred.h
new file mode 100644
index 0000000..de6ec4c
--- /dev/null
+++ b/libgit2-glib/ggit-cred.h
@@ -0,0 +1,58 @@
+/*
+ * ggit-cred.h
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2013 - Ignacio Casal Quinteiro
+ *
+ * libgit2-glib is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * libgit2-glib is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with libgit2-glib. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __GGIT_CRED_H__
+#define __GGIT_CRED_H__
+
+#include <glib-object.h>
+#include <libgit2-glib/ggit-native.h>
+
+G_BEGIN_DECLS
+
+#define GGIT_TYPE_CRED                 (ggit_cred_get_type ())
+#define GGIT_CRED(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GGIT_TYPE_CRED, GgitCred))
+#define GGIT_CRED_CONST(obj)           (G_TYPE_CHECK_INSTANCE_CAST ((obj), GGIT_TYPE_CRED, GgitCred const))
+#define GGIT_CRED_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), GGIT_TYPE_CRED, GgitCredClass))
+#define GGIT_IS_CRED(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GGIT_TYPE_CRED))
+#define GGIT_IS_CRED_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), GGIT_TYPE_CRED))
+#define GGIT_CRED_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), GGIT_TYPE_CRED, GgitCredClass))
+
+typedef struct _GgitCredClass  GgitCredClass;
+
+struct _GgitCred
+{
+       GgitNative parent;
+
+       gpointer *priv;
+};
+
+struct _GgitCredClass
+{
+       GgitNativeClass parent_class;
+};
+
+GType               ggit_cred_get_type           (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* __GGIT_CRED_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-types.h b/libgit2-glib/ggit-types.h
index 9ddb8d9..a335771 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -61,6 +61,20 @@ typedef struct _GgitConfig GgitConfig;
 typedef struct _GgitConfigEntry GgitConfigEntry;
 
 /**
+ * GgitCred:
+ *
+ * Represents a git credential.
+ */
+typedef struct _GgitCred GgitCred;
+
+/**
+ * GgitCredPlaintext:
+ *
+ * Represents a plain text credential.
+ */
+typedef struct _GgitCredPlaintext GgitCredPlaintext;
+
+/**
  * GgitDiff:
  *
  * Represents a diff.
@@ -682,6 +696,23 @@ typedef gint (* GgitConfigMatchCallback) (GMatchInfo  *match_info,
                                           gpointer     user_data);
 
 /**
+ * GgitCredAcquireCallback:
+ * @url: the resource for which we are demanding a credential.
+ * @username_from_url: (allow-none): The username that was embedded in a "user host"
+ *                                   remote url, or NULL if not included.
+ * @allowed_types: a bitmask stating which cred types are OK to return.
+ * @cred: (transfer full): newly created credential object.
+ * @user_data: (closure): user-supplied data.
+ *
+ * Signature of a function which acquires a credential object.
+ */
+typedef gint (* GgitCredAcquireCallback) (const gchar *url,
+                                          const gchar *username_from_url,
+                                          guint        allowed_types,
+                                          GgitCred   **cred,
+                                          gpointer     user_data);
+
+/**
  * GgitDiffFileCallback:
  * @delta: a #GgitDiffDelta.
  * @progress: the progress.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]