>From c05df71ea0ad5f6ac19a167aeeabcecaaf704ff7 Mon Sep 17 00:00:00 2001
From: Stef Walter <stefw@redhat.com>
Date: Fri, 10 Jan 2014 11:23:33 +0100
Subject: [PATCH 6/6] sbus: Use constants to make dbus calls

This allows us to remove duplicated information, and have the
compiler check that when an method name is changed or removed
the callers are updated.
---
 src/monitor/monitor.c                        | 18 +++++++++---------
 src/monitor/monitor_interfaces.h             | 17 -----------------
 src/monitor/monitor_sbus.c                   |  4 ++--
 src/providers/data_provider.h                | 17 -----------------
 src/providers/data_provider_be.c             |  4 ++--
 src/providers/data_provider_iface.xml        |  6 ++++++
 src/providers/dp_auth_util.c                 |  4 ++--
 src/providers/proxy/proxy_auth.c             |  4 ++--
 src/providers/proxy/proxy_child.c            |  4 ++--
 src/responder/autofs/autofssrv_dp.c          |  4 ++--
 src/responder/common/responder_dp.c          |  4 ++--
 src/responder/common/responder_get_domains.c |  4 ++--
 src/responder/pam/pamsrv_dp.c                |  4 ++--
 src/responder/ssh/sshsrv_dp.c                |  4 ++--
 src/responder/sudo/sudosrv_dp.c              |  4 ++--
 15 files changed, 37 insertions(+), 65 deletions(-)

diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
index ddbaece..a756fc4 100644
--- a/src/monitor/monitor.c
+++ b/src/monitor/monitor.c
@@ -739,7 +739,7 @@ static int service_signal(struct mt_svc *svc, const char *svc_signal)
 
     msg = dbus_message_new_method_call(NULL,
                                        MONITOR_PATH,
-                                       MONITOR_INTERFACE,
+                                       MON_CLI_IFACE,
                                        svc_signal);
     if (msg == NULL) {
         DEBUG(SSSDBG_FATAL_FAILURE,
@@ -759,27 +759,27 @@ static int service_signal(struct mt_svc *svc, const char *svc_signal)
 
 static int service_signal_dns_reload(struct mt_svc *svc)
 {
-    return service_signal(svc, MON_CLI_METHOD_RES_INIT);
+    return service_signal(svc, MON_CLI_IFACE_RESINIT);
 }
 static int service_signal_offline(struct mt_svc *svc)
 {
-    return service_signal(svc, MON_CLI_METHOD_OFFLINE);
+    return service_signal(svc, MON_CLI_IFACE_GOOFFLINE);
 }
 static int service_signal_reset_offline(struct mt_svc *svc)
 {
-    return service_signal(svc, MON_CLI_METHOD_RESET_OFFLINE);
+    return service_signal(svc, MON_CLI_IFACE_RESETOFFLINE);
 }
 static int service_signal_rotate(struct mt_svc *svc)
 {
-    return service_signal(svc, MON_CLI_METHOD_ROTATE);
+    return service_signal(svc, MON_CLI_IFACE_ROTATELOGS);
 }
 static int service_signal_clear_memcache(struct mt_svc *svc)
 {
-    return service_signal(svc, MON_CLI_METHOD_CLEAR_MEMCACHE);
+    return service_signal(svc, MON_CLI_IFACE_CLEARMEMCACHE);
 }
 static int service_signal_clear_enum_cache(struct mt_svc *svc)
 {
-    return service_signal(svc, MON_CLI_METHOD_CLEAR_ENUM_CACHE);
+    return service_signal(svc, MON_CLI_IFACE_CLEARENUMCACHE);
 }
 
 static int check_domain_ranges(struct sss_domain_info *domains)
@@ -2362,8 +2362,8 @@ static int service_send_ping(struct mt_svc *svc)
      */
     msg = dbus_message_new_method_call(NULL,
                                        MONITOR_PATH,
-                                       MONITOR_INTERFACE,
-                                       MON_CLI_METHOD_PING);
+                                       MON_CLI_IFACE,
+                                       MON_CLI_IFACE_PING);
     if (!msg) {
         DEBUG(0,("Out of memory?!\n"));
         talloc_zfree(svc->conn);
diff --git a/src/monitor/monitor_interfaces.h b/src/monitor/monitor_interfaces.h
index 308642f..ef4254a 100644
--- a/src/monitor/monitor_interfaces.h
+++ b/src/monitor/monitor_interfaces.h
@@ -29,26 +29,9 @@
 
 /*** Monitor SRV Interface ***/
 #define MON_SRV_PATH "/org/freedesktop/sssd/monitor"
-#define MON_SRV_INTERFACE "org.freedesktop.sssd.monitor"
-
-/* Monitor SRV Methods */
-#define MON_SRV_METHOD_VERSION "getVersion"
-#define MON_SRV_METHOD_REGISTER "RegisterService"
 
 /*** Monitor CLI Interface ***/
 #define MONITOR_PATH "/org/freedesktop/sssd/service"
-#define MONITOR_INTERFACE "org.freedesktop.sssd.service"
-
-/* Monitor CLI Methods */
-#define MON_CLI_METHOD_IDENTITY "getIdentity"
-#define MON_CLI_METHOD_PING "ping"
-#define MON_CLI_METHOD_SHUTDOWN "shutDown"
-#define MON_CLI_METHOD_RES_INIT "resInit"
-#define MON_CLI_METHOD_OFFLINE "goOffline" /* Applicable only to providers */
-#define MON_CLI_METHOD_RESET_OFFLINE "resetOffline" /* Applicable only to providers */
-#define MON_CLI_METHOD_ROTATE "rotateLogs"
-#define MON_CLI_METHOD_CLEAR_MEMCACHE "clearMemcache"
-#define MON_CLI_METHOD_CLEAR_ENUM_CACHE "clearEnumCache"
 
 #define SSSD_SERVICE_PIPE "private/sbus-monitor"
 
diff --git a/src/monitor/monitor_sbus.c b/src/monitor/monitor_sbus.c
index 66270a7..d01cf3c 100644
--- a/src/monitor/monitor_sbus.c
+++ b/src/monitor/monitor_sbus.c
@@ -117,8 +117,8 @@ int monitor_common_send_id(struct sbus_connection *conn,
     /* create the message */
     msg = dbus_message_new_method_call(NULL,
                                        MON_SRV_PATH,
-                                       MON_SRV_INTERFACE,
-                                       MON_SRV_METHOD_REGISTER);
+                                       MON_SRV_IFACE,
+                                       MON_SRV_IFACE_REGISTERSERVICE);
     if (msg == NULL) {
         DEBUG(0, ("Out of memory?!\n"));
         return ENOMEM;
diff --git a/src/providers/data_provider.h b/src/providers/data_provider.h
index 70dbdeb..ee851ba 100644
--- a/src/providers/data_provider.h
+++ b/src/providers/data_provider.h
@@ -48,23 +48,8 @@
 #define DATA_PROVIDER_VERSION 0x0001
 #define DATA_PROVIDER_PIPE "private/sbus-dp"
 
-#define DP_INTERFACE "org.freedesktop.sssd.dataprovider"
 #define DP_PATH "/org/freedesktop/sssd/dataprovider"
 
-#define DP_METHOD_REGISTER "RegisterService"
-#define DP_METHOD_GETACCTINFO "getAccountInfo"
-#define DP_METHOD_SUDOHANDLER "sudoHandler"
-#define DP_METHOD_AUTOFSHANDLER "autofsHandler"
-#define DP_METHOD_HOSTHANDLER "hostHandler"
-#define DP_METHOD_GETDOMAINS "getDomains"
-
-/* this is a reverse method sent from providers to
- * the nss responder to tell it to update the mmap
- * cache */
-#define DP_REV_INTERFACE "org.freedesktop.sssd.dataprovider_rev"
-#define DP_REV_METHOD_UPDATE_CACHE "updateCache"
-#define DP_REV_METHOD_INITGR_CHECK "initgrCheck"
-
 /**
  * @defgroup pamHandler PAM DBUS request
  * @ingroup sss_pam
@@ -125,8 +110,6 @@
  */
 
 
-#define DP_METHOD_PAMHANDLER "pamHandler"
-
 /**
  * @}
  */ /* end of group pamHandler */
diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
index d56ec52..7b30548 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -855,8 +855,8 @@ static void acctinfo_initgroups_callback(struct be_req *be_req,
     /* Set up null request */
     msg = dbus_message_new_method_call(NULL,
                                        DP_PATH,
-                                       DP_REV_INTERFACE,
-                                       DP_REV_METHOD_INITGR_CHECK);
+                                       DATA_PROVIDER_REV_IFACE,
+                                       DATA_PROVIDER_REV_IFACE_INITGRCHECK);
     if (!msg) {
         DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory?!\n"));
         ret = ENOMEM;
diff --git a/src/providers/data_provider_iface.xml b/src/providers/data_provider_iface.xml
index 1f34964..90397f1 100644
--- a/src/providers/data_provider_iface.xml
+++ b/src/providers/data_provider_iface.xml
@@ -26,6 +26,12 @@
         </method>
     </interface>
 
+    <!--
+      this is a reverse method sent from providers to
+      the nss responder to tell it to update the mmap
+      cache
+    -->
+
     <interface name="org.freedesktop.sssd.dataprovider_rev">
         <annotation value="data_provider_rev_iface" name="org.freedesktop.DBus.GLib.CSymbol"/>
         <method name="updateCache">
diff --git a/src/providers/dp_auth_util.c b/src/providers/dp_auth_util.c
index 0bf10a7..2ce5872 100644
--- a/src/providers/dp_auth_util.c
+++ b/src/providers/dp_auth_util.c
@@ -359,8 +359,8 @@ int dp_common_send_id(struct sbus_connection *conn, uint16_t version,
     /* create the message */
     msg = dbus_message_new_method_call(NULL,
                                        DP_PATH,
-                                       DP_INTERFACE,
-                                       DP_METHOD_REGISTER);
+                                       DATA_PROVIDER_IFACE,
+                                       DATA_PROVIDER_IFACE_REGISTERSERVICE);
     if (msg == NULL) {
         DEBUG(0, ("Out of memory?!\n"));
         return ENOMEM;
diff --git a/src/providers/proxy/proxy_auth.c b/src/providers/proxy/proxy_auth.c
index fa766dc..848890e 100644
--- a/src/providers/proxy/proxy_auth.c
+++ b/src/providers/proxy/proxy_auth.c
@@ -580,8 +580,8 @@ static struct tevent_req *proxy_pam_conv_send(TALLOC_CTX *mem_ctx,
 
     msg = dbus_message_new_method_call(NULL,
                                        DP_PATH,
-                                       DP_INTERFACE,
-                                       DP_METHOD_PAMHANDLER);
+                                       DATA_PROVIDER_IFACE,
+                                       DATA_PROVIDER_IFACE_PAMHANDLER);
     if (msg == NULL) {
         DEBUG(1, ("dbus_message_new_method_call failed.\n"));
         talloc_zfree(req);
diff --git a/src/providers/proxy/proxy_child.c b/src/providers/proxy/proxy_child.c
index b59546d..42d6dcb 100644
--- a/src/providers/proxy/proxy_child.c
+++ b/src/providers/proxy/proxy_child.c
@@ -427,8 +427,8 @@ int proxy_child_send_id(struct sbus_connection *conn,
     /* create the message */
     msg = dbus_message_new_method_call(NULL,
                                        DP_PATH,
-                                       DP_INTERFACE,
-                                       DP_METHOD_REGISTER);
+                                       DATA_PROVIDER_IFACE,
+                                       DATA_PROVIDER_IFACE_REGISTERSERVICE);
     if (msg == NULL) {
         DEBUG(0, ("Out of memory?!\n"));
         return ENOMEM;
diff --git a/src/responder/autofs/autofssrv_dp.c b/src/responder/autofs/autofssrv_dp.c
index 7f51b61..39fb42f 100644
--- a/src/responder/autofs/autofssrv_dp.c
+++ b/src/responder/autofs/autofssrv_dp.c
@@ -118,8 +118,8 @@ sss_dp_get_autofs_msg(void *pvt)
 
     msg = dbus_message_new_method_call(NULL,
                                        DP_PATH,
-                                       DP_INTERFACE,
-                                       DP_METHOD_AUTOFSHANDLER);
+                                       DATA_PROVIDER_IFACE,
+                                       DATA_PROVIDER_IFACE_AUTOFSHANDLER);
     if (msg == NULL) {
         DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory?!\n"));
         return NULL;
diff --git a/src/responder/common/responder_dp.c b/src/responder/common/responder_dp.c
index e73e1e6..6616ded 100644
--- a/src/responder/common/responder_dp.c
+++ b/src/responder/common/responder_dp.c
@@ -587,8 +587,8 @@ sss_dp_get_account_msg(void *pvt)
 
     msg = dbus_message_new_method_call(NULL,
                                        DP_PATH,
-                                       DP_INTERFACE,
-                                       DP_METHOD_GETACCTINFO);
+                                       DATA_PROVIDER_IFACE,
+                                       DATA_PROVIDER_IFACE_GETACCOUNTINFO);
     if (msg == NULL) {
         talloc_free(filter);
         DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory?!\n"));
diff --git a/src/responder/common/responder_get_domains.c b/src/responder/common/responder_get_domains.c
index a976d27..0e198ff 100644
--- a/src/responder/common/responder_get_domains.c
+++ b/src/responder/common/responder_get_domains.c
@@ -94,8 +94,8 @@ sss_dp_get_domains_msg(void *pvt)
 
     msg = dbus_message_new_method_call(NULL,
                                        DP_PATH,
-                                       DP_INTERFACE,
-                                       DP_METHOD_GETDOMAINS);
+                                       DATA_PROVIDER_IFACE,
+                                       DATA_PROVIDER_IFACE_GETDOMAINS);
     if (msg == NULL) {
         DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory?!\n"));
         return NULL;
diff --git a/src/responder/pam/pamsrv_dp.c b/src/responder/pam/pamsrv_dp.c
index d5a5244..747fd23 100644
--- a/src/responder/pam/pamsrv_dp.c
+++ b/src/responder/pam/pamsrv_dp.c
@@ -126,8 +126,8 @@ int pam_dp_send_req(struct pam_auth_req *preq, int timeout)
 
     msg = dbus_message_new_method_call(NULL,
                                        DP_PATH,
-                                       DP_INTERFACE,
-                                       DP_METHOD_PAMHANDLER);
+                                       DATA_PROVIDER_IFACE,
+                                       DATA_PROVIDER_IFACE_PAMHANDLER);
     if (msg == NULL) {
         DEBUG(0,("Out of memory?!\n"));
         return ENOMEM;
diff --git a/src/responder/ssh/sshsrv_dp.c b/src/responder/ssh/sshsrv_dp.c
index 812e0c7..080be33 100644
--- a/src/responder/ssh/sshsrv_dp.c
+++ b/src/responder/ssh/sshsrv_dp.c
@@ -126,8 +126,8 @@ sss_dp_get_ssh_host_msg(void *pvt)
 
     msg = dbus_message_new_method_call(NULL,
                                        DP_PATH,
-                                       DP_INTERFACE,
-                                       DP_METHOD_HOSTHANDLER);
+                                       DATA_PROVIDER_IFACE,
+                                       DATA_PROVIDER_IFACE_HOSTHANDLER);
     if (msg == NULL) {
         DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory?!\n"));
         talloc_free(filter);
diff --git a/src/responder/sudo/sudosrv_dp.c b/src/responder/sudo/sudosrv_dp.c
index 3cd8fe8..c3bb570 100644
--- a/src/responder/sudo/sudosrv_dp.c
+++ b/src/responder/sudo/sudosrv_dp.c
@@ -141,8 +141,8 @@ sss_dp_get_sudoers_msg(void *pvt)
 
     msg = dbus_message_new_method_call(NULL,
                                        DP_PATH,
-                                       DP_INTERFACE,
-                                       DP_METHOD_SUDOHANDLER);
+                                       DATA_PROVIDER_IFACE,
+                                       DATA_PROVIDER_IFACE_SUDOHANDLER);
     if (msg == NULL) {
         DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory?!\n"));
         return NULL;
-- 
1.8.4.2

