[libgovirt] Add ovirt_get_option_group() API
- From: Christophe Fergeau <teuf src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgovirt] Add ovirt_get_option_group() API
- Date: Tue, 8 Oct 2013 17:06:27 +0000 (UTC)
commit e0f0126d89f263a5bd66c453223765003513c171
Author: Christophe Fergeau <cfergeau redhat com>
Date: Mon Sep 16 14:38:51 2013 +0200
Add ovirt_get_option_group() API
This allows applications to easily add support for command line
options libgovirt knows about. For now, it's only --ovirt-ca-file
which specifies the root CA certificate libgovirt should trust during
https REST sessions. If it's not specified, the system CA cert store
will be used.
govirt/Makefile.am | 2 +
govirt/govirt.h | 1 +
govirt/govirt.sym | 3 ++
govirt/ovirt-options.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++
govirt/ovirt-options.h | 31 ++++++++++++++++++++
5 files changed, 110 insertions(+), 0 deletions(-)
---
diff --git a/govirt/Makefile.am b/govirt/Makefile.am
index 0c694ca..d9e70a5 100644
--- a/govirt/Makefile.am
+++ b/govirt/Makefile.am
@@ -19,6 +19,7 @@ libgovirt_la_HEADERS = \
ovirt-cdrom.h \
ovirt-collection.h \
ovirt-error.h \
+ ovirt-options.h \
ovirt-proxy.h \
ovirt-resource.h \
ovirt-rest-call-error.h \
@@ -50,6 +51,7 @@ libgovirt_la_SOURCES = \
ovirt-cdrom.c \
ovirt-collection.c \
ovirt-error.c \
+ ovirt-options.c \
ovirt-proxy.c \
ovirt-proxy-deprecated.c \
ovirt-resource.c \
diff --git a/govirt/govirt.h b/govirt/govirt.h
index a1a7513..69f878b 100644
--- a/govirt/govirt.h
+++ b/govirt/govirt.h
@@ -27,6 +27,7 @@
#include <govirt/ovirt-cdrom.h>
#include <govirt/ovirt-collection.h>
#include <govirt/ovirt-error.h>
+#include <govirt/ovirt-options.h>
#include <govirt/ovirt-proxy.h>
#include <govirt/ovirt-resource.h>
#include <govirt/ovirt-rest-call-error.h>
diff --git a/govirt/govirt.sym b/govirt/govirt.sym
index a61e72c..bc53901 100644
--- a/govirt/govirt.sym
+++ b/govirt/govirt.sym
@@ -50,6 +50,9 @@ GOVIRT_0.2.0 {
};
GOVIRT_0.2.1 {
+ ovirt_get_option_group;
+ ovirt_set_proxy_options;
+
ovirt_api_get_type;
ovirt_api_new;
ovirt_api_get_vms;
diff --git a/govirt/ovirt-options.c b/govirt/ovirt-options.c
new file mode 100644
index 0000000..2a9f8f0
--- /dev/null
+++ b/govirt/ovirt-options.c
@@ -0,0 +1,73 @@
+/*
+ Copyright (C) 2010, 2013 Red Hat, Inc.
+
+ This library 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.
+
+ This library 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 this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <glib-object.h>
+
+#include "ovirt-options.h"
+
+static char *ca_file = NULL;
+
+G_GNUC_NORETURN
+static void option_version(void)
+{
+ g_print(PACKAGE_STRING "\n");
+ exit(0);
+}
+
+/**
+ * ovirt_get_option_group: (skip)
+ *
+ * Returns: (transfer full): a #GOptionGroup for the commandline
+ * arguments specific to libgovirt. You have to call
+ * ovirt_set_proxy_options() after to set the options on a
+ * #OvirtProxy.
+ **/
+GOptionGroup* ovirt_get_option_group(void)
+{
+ const GOptionEntry entries[] = {
+ { "ovirt-ca-file", '\0', 0, G_OPTION_ARG_FILENAME, &ca_file,
+ "Root CA certificate file for secure SSL connections", "<file>" },
+ { "ovirt-version", '\0', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_version,
+ "Display libgovirt version information", NULL },
+ { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
+ };
+ GOptionGroup *grp;
+
+ grp = g_option_group_new("ovirt", "oVirt Options:", "Show oVirt Options", NULL, NULL);
+ g_option_group_add_entries(grp, entries);
+
+ return grp;
+}
+
+/**
+ * ovirt_set_proxy_options:
+ * @proxy: a #OvirtProxy to set options upon
+ *
+ * Set various properties on @proxy, according to the commandline
+ * arguments given to ovirt_get_option_group() option group.
+ **/
+void ovirt_set_proxy_options(OvirtProxy *proxy)
+{
+ g_return_if_fail(OVIRT_IS_PROXY(proxy));
+
+ if (ca_file)
+ g_object_set(G_OBJECT(proxy), "ssl-ca-file", ca_file, NULL);
+}
diff --git a/govirt/ovirt-options.h b/govirt/ovirt-options.h
new file mode 100644
index 0000000..043c566
--- /dev/null
+++ b/govirt/ovirt-options.h
@@ -0,0 +1,31 @@
+/*
+ Copyright (C) 2010, 2013 Red Hat, Inc.
+
+ This library 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.
+
+ This library 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 this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef OVIRT_OPTION_H
+#define OVIRT_OPTION_H
+
+#include <glib.h>
+
+#include "ovirt-proxy.h"
+
+G_BEGIN_DECLS
+
+GOptionGroup* ovirt_get_option_group(void);
+void ovirt_set_proxy_options(OvirtProxy *proxy);
+
+G_END_DECLS
+
+#endif /* OVIRT_OPTION_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]