From 610ffa5ee147f383ad2f876b6659bb9b92628808 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Thu, 15 Jan 2015 14:23:19 +0100
Subject: [PATCH 1/7] IFP: move interface definitions from ifpsrv.c into
 separate file

Number of IFP interfaces will grown up rapidly in the future. It is
not convenient to keep it inside ifpsrv.c.
---
 Makefile.am                     |   1 +
 src/responder/ifp/ifp_iface.c   | 108 ++++++++++++++++++++++++++++++++++++++++
 src/responder/ifp/ifp_private.h |   2 +
 src/responder/ifp/ifpsrv.c      |  80 ++---------------------------
 4 files changed, 115 insertions(+), 76 deletions(-)
 create mode 100644 src/responder/ifp/ifp_iface.c

diff --git a/Makefile.am b/Makefile.am
index e4c1f453053d0d815aaa277d6f4126326ce2b95d..c4631060efeb9b6035c318c5a724e07d49f573de 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1049,6 +1049,7 @@ sssd_ifp_SOURCES = \
     src/responder/ifp/ifpsrv_cmd.c \
     src/responder/ifp/ifp_iface_generated.c \
     src/responder/ifp/ifp_iface_generated.h \
+    src/responder/ifp/ifp_iface.c \
     src/responder/ifp/ifpsrv_util.c \
     src/responder/ifp/ifp_domains.c \
     src/responder/ifp/ifp_components.c \
diff --git a/src/responder/ifp/ifp_iface.c b/src/responder/ifp/ifp_iface.c
new file mode 100644
index 0000000000000000000000000000000000000000..8209381d72b6601b9c3934f30d5c57131b1d71b7
--- /dev/null
+++ b/src/responder/ifp/ifp_iface.c
@@ -0,0 +1,108 @@
+/*
+    Authors:
+        Pavel Březina <pbrezina@redhat.com>
+
+    Copyright (C) 2015 Red Hat
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    This program 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 General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <dbus/dbus.h>
+
+#include "sbus/sssd_dbus.h"
+#include "monitor/monitor_interfaces.h"
+#include "confdb/confdb.h"
+#include "responder/ifp/ifp_private.h"
+#include "responder/ifp/ifp_domains.h"
+#include "responder/ifp/ifp_components.h"
+#include "responder/common/responder_sbus.h"
+
+struct infopipe_iface ifp_iface = {
+    { &infopipe_iface_meta, 0 },
+    .Ping = ifp_ping,
+
+    /* components */
+    .ListComponents = ifp_list_components,
+    .ListResponders = ifp_list_responders,
+    .ListBackends = ifp_list_backends,
+    .FindMonitor = ifp_find_monitor,
+    .FindResponderByName = ifp_find_responder_by_name,
+    .FindBackendByName = ifp_find_backend_by_name,
+
+    .GetUserAttr = ifp_user_get_attr,
+    .GetUserGroups = ifp_user_get_groups,
+    .ListDomains = ifp_list_domains,
+    .FindDomainByName = ifp_find_domain_by_name,
+};
+
+struct infopipe_component ifp_component = {
+    { &infopipe_component_meta, 0 },
+    .Enable = ifp_component_enable,
+    .Disable = ifp_component_disable,
+    .ChangeDebugLevel = ifp_component_change_debug_level,
+    .ChangeDebugLevelTemporarily = ifp_component_change_debug_level_tmp,
+    .infopipe_component_get_name = ifp_component_get_name,
+    .infopipe_component_get_debug_level = ifp_component_get_debug_level,
+    .infopipe_component_get_enabled = ifp_component_get_enabled,
+    .infopipe_component_get_type = ifp_component_get_type,
+    /* FIXME: This should be part of Components.Backends interface, onece
+     * SSSD supports multiple interfaces per object path. */
+    .infopipe_component_get_providers = ifp_backend_get_providers
+};
+
+struct infopipe_domain ifp_domain = {
+    { &infopipe_domain_meta, 0 },
+    .infopipe_domain_get_name = ifp_dom_get_name,
+    .infopipe_domain_get_provider = ifp_dom_get_provider,
+    .infopipe_domain_get_primary_servers = ifp_dom_get_primary_servers,
+    .infopipe_domain_get_backup_servers = ifp_dom_get_backup_servers,
+    .infopipe_domain_get_min_id = ifp_dom_get_min_id,
+    .infopipe_domain_get_max_id = ifp_dom_get_max_id,
+    .infopipe_domain_get_realm = ifp_dom_get_realm,
+    .infopipe_domain_get_forest = ifp_dom_get_forest,
+    .infopipe_domain_get_login_format = ifp_dom_get_login_format,
+    .infopipe_domain_get_fully_qualified_name_format = ifp_dom_get_fqdn_format,
+    .infopipe_domain_get_enumerable = ifp_dom_get_enumerable,
+    .infopipe_domain_get_use_fully_qualified_names = ifp_dom_get_use_fqdn,
+    .infopipe_domain_get_subdomain = ifp_dom_get_subdomain,
+    .infopipe_domain_get_parent_domain = ifp_dom_get_parent_domain
+};
+
+struct iface_map {
+    const char *path;
+    struct sbus_vtable *vtable;
+};
+
+static struct iface_map iface_map[] = {
+    { INFOPIPE_PATH, &ifp_iface.vtable },
+    { INFOPIPE_DOMAIN_PATH, &ifp_domain.vtable },
+    { INFOPIPE_COMPONENT_PATH, &ifp_component.vtable },
+    { NULL, NULL },
+};
+
+errno_t ifp_register_sbus_interface(struct sbus_connection *conn, void *pvt)
+{
+    errno_t ret;
+    int i;
+
+    for (i = 0; iface_map[i].path != NULL; i++) {
+        ret = sbus_conn_register_iface(conn, iface_map[i].vtable,
+                                       iface_map[i].path, pvt);
+        if (ret != EOK) {
+            return ret;
+        }
+    }
+
+    return EOK;
+}
diff --git a/src/responder/ifp/ifp_private.h b/src/responder/ifp/ifp_private.h
index 676544fadfab136707f01b752c9526d64ee6fa3f..8583754b3122fa015f069d88d9f4f8d101ac5734 100644
--- a/src/responder/ifp/ifp_private.h
+++ b/src/responder/ifp/ifp_private.h
@@ -46,6 +46,8 @@ struct ifp_ctx {
     const char **user_whitelist;
 };
 
+errno_t ifp_register_sbus_interface(struct sbus_connection *conn, void *pvt);
+
 /* This is a throwaway method to ease the review of the patch.
  * It will be removed later */
 int ifp_ping(struct sbus_request *dbus_req, void *data);
diff --git a/src/responder/ifp/ifpsrv.c b/src/responder/ifp/ifpsrv.c
index 5b7f26ca1135f9ee47e45d50e44516bf58cdcccd..476008174948083e5a2c55876ad9b8395de1c233 100644
--- a/src/responder/ifp/ifpsrv.c
+++ b/src/responder/ifp/ifpsrv.c
@@ -68,69 +68,6 @@ static struct data_provider_iface ifp_dp_methods = {
     .getAccountInfo = NULL,
 };
 
-struct infopipe_iface ifp_iface = {
-    { &infopipe_iface_meta, 0 },
-    .Ping = ifp_ping,
-
-    /* components */
-    .ListComponents = ifp_list_components,
-    .ListResponders = ifp_list_responders,
-    .ListBackends = ifp_list_backends,
-    .FindMonitor = ifp_find_monitor,
-    .FindResponderByName = ifp_find_responder_by_name,
-    .FindBackendByName = ifp_find_backend_by_name,
-
-    .GetUserAttr = ifp_user_get_attr,
-    .GetUserGroups = ifp_user_get_groups,
-    .ListDomains = ifp_list_domains,
-    .FindDomainByName = ifp_find_domain_by_name,
-};
-
-struct infopipe_component ifp_component = {
-    { &infopipe_component_meta, 0 },
-    .Enable = ifp_component_enable,
-    .Disable = ifp_component_disable,
-    .ChangeDebugLevel = ifp_component_change_debug_level,
-    .ChangeDebugLevelTemporarily = ifp_component_change_debug_level_tmp,
-    .infopipe_component_get_name = ifp_component_get_name,
-    .infopipe_component_get_debug_level = ifp_component_get_debug_level,
-    .infopipe_component_get_enabled = ifp_component_get_enabled,
-    .infopipe_component_get_type = ifp_component_get_type,
-    /* FIXME: This should be part of Components.Backends interface, onece
-     * SSSD supports multiple interfaces per object path. */
-    .infopipe_component_get_providers = ifp_backend_get_providers
-};
-
-struct infopipe_domain ifp_domain = {
-    { &infopipe_domain_meta, 0 },
-    .infopipe_domain_get_name = ifp_dom_get_name,
-    .infopipe_domain_get_provider = ifp_dom_get_provider,
-    .infopipe_domain_get_primary_servers = ifp_dom_get_primary_servers,
-    .infopipe_domain_get_backup_servers = ifp_dom_get_backup_servers,
-    .infopipe_domain_get_min_id = ifp_dom_get_min_id,
-    .infopipe_domain_get_max_id = ifp_dom_get_max_id,
-    .infopipe_domain_get_realm = ifp_dom_get_realm,
-    .infopipe_domain_get_forest = ifp_dom_get_forest,
-    .infopipe_domain_get_login_format = ifp_dom_get_login_format,
-    .infopipe_domain_get_fully_qualified_name_format = ifp_dom_get_fqdn_format,
-    .infopipe_domain_get_enumerable = ifp_dom_get_enumerable,
-    .infopipe_domain_get_use_fully_qualified_names = ifp_dom_get_use_fqdn,
-    .infopipe_domain_get_subdomain = ifp_dom_get_subdomain,
-    .infopipe_domain_get_parent_domain = ifp_dom_get_parent_domain
-};
-
-struct sysbus_iface {
-    const char *path;
-    struct sbus_vtable *iface_vtable;
-};
-
-static struct sysbus_iface ifp_ifaces[] = {
-    { INFOPIPE_PATH, &ifp_iface.vtable },
-    { INFOPIPE_DOMAIN_PATH, &ifp_domain.vtable },
-    { INFOPIPE_COMPONENT_PATH, &ifp_component.vtable },
-    { NULL, NULL },
-};
-
 struct sss_cmd_table *get_ifp_cmds(void)
 {
     static struct sss_cmd_table ifp_cmds[] = {
@@ -171,14 +108,12 @@ static errno_t
 sysbus_init(TALLOC_CTX *mem_ctx,
             struct tevent_context *ev,
             const char *dbus_name,
-            struct sysbus_iface *sysbus_ifaces,
             void *pvt,
             struct sysbus_ctx **sysbus)
 {
     DBusError dbus_error;
     DBusConnection *conn = NULL;
     struct sysbus_ctx *system_bus = NULL;
-    int i;
     errno_t ret;
 
     system_bus = talloc_zero(mem_ctx, struct sysbus_ctx);
@@ -224,15 +159,10 @@ sysbus_init(TALLOC_CTX *mem_ctx,
         goto fail;
     }
 
-    for (i = 0; sysbus_ifaces[i].path != NULL; i++) {
-        ret = sbus_conn_register_iface(system_bus->conn,
-                                       sysbus_ifaces[i].iface_vtable,
-                                       sysbus_ifaces[i].path, pvt);
-        if (ret != EOK) {
-            DEBUG(SSSDBG_CRIT_FAILURE,
-                  "Could not add the interface\n");
-            goto fail;
-        }
+    ret = ifp_register_sbus_interface(system_bus->conn, pvt);
+    if (ret != EOK) {
+        DEBUG(SSSDBG_CRIT_FAILURE, "Could not register interfaces\n");
+        goto fail;
     }
 
     *sysbus = system_bus;
@@ -267,7 +197,6 @@ static int ifp_sysbus_reconnect(struct sbus_request *dbus_req, void *data)
     /* Connect to the D-BUS system bus and set up methods */
     ret = sysbus_init(ifp_ctx, ifp_ctx->rctx->ev,
                       INFOPIPE_IFACE,
-                      ifp_ifaces,
                       ifp_ctx, &ifp_ctx->sysbus);
     if (ret == ERR_NO_SYSBUS) {
         DEBUG(SSSDBG_MINOR_FAILURE,
@@ -398,7 +327,6 @@ int ifp_process_init(TALLOC_CTX *mem_ctx,
     /* Connect to the D-BUS system bus and set up methods */
     ret = sysbus_init(ifp_ctx, ifp_ctx->rctx->ev,
                       INFOPIPE_IFACE,
-                      ifp_ifaces,
                       ifp_ctx, &ifp_ctx->sysbus);
     if (ret == ERR_NO_SYSBUS) {
         DEBUG(SSSDBG_MINOR_FAILURE,
-- 
1.7.11.7

