Add xmlrpc client command sender
authorNeutron Soutmun <neo.neutron@gmail.com>
Tue, 2 Sep 2008 12:42:51 +0000 (19:42 +0700)
committerNeutron Soutmun <neo.neutron@gmail.com>
Sun, 2 Nov 2008 19:43:11 +0000 (02:43 +0700)
2008-09-02  Neutron Soutmun <neo.neutron@gmail.com>

* +src/rh-xmlrpc-cmd.{h,c}: Add new xmlrpc client command sender.
* src/rahunasd.c: Move the send_xmlrpc_stopacct() code to rh-xmlrpc-cmd.
* src/Makefile.am: Update accordingly to new change.

ChangeLog
src/Makefile.am
src/rahunasd.c
src/rh-xmlrpc-cmd.c [new file with mode: 0644]
src/rh-xmlrpc-cmd.h [new file with mode: 0644]

index 903b569..51d7b1a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-09-02  Neutron Soutmun <neo.neutron@gmail.com>
+
+       * +src/rh-xmlrpc-cmd.{h,c}: Add new xmlrpc client command sender.
+       * src/rahunasd.c: Move the send_xmlrpc_stopacct() code to rh-xmlrpc-cmd.
+       * src/Makefile.am: Update accordingly to new change.
+
 2008-09-01  Neutron Soutmun <neo.neutron@gmail.com>
 
        * src/rahunasd.c: Remove unnecessary functions.
index 147144b..faecf59 100644 (file)
@@ -7,6 +7,7 @@ AM_CFLAGS = $(LIBGNET_CFLAGS) -I$(top_builddir)/src/include/ \
 
 rahunasd_SOURCES = rahunasd.c \
        rh-xmlrpc-server.c \
+       rh-xmlrpc-cmd.c \
   rh-ipset.c \
        rh-utils.c
 
index f5d698a..77ef8bf 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "rahunasd.h"
 #include "rh-xmlrpc-server.h"
+#include "rh-xmlrpc-cmd.h"
 #include "rh-ipset.h"
 #include "rh-utils.h"
 
@@ -32,7 +33,6 @@ int ipset_flush();
 struct rahunas_map* rh_init_map();
 int rh_init_members(struct rahunas_map *map);
 
-int send_xmlrpc_stopacct(struct rahunas_map *map, uint32_t id);
 
 /* Declaration */
 struct rahunas_map *map = NULL;
@@ -227,55 +227,6 @@ int getline(int fd, char *buf, size_t size)
        return (current - buf);
 }
 
-int send_xmlrpc_stopacct(struct rahunas_map *map, uint32_t id) {
-  struct rahunas_member *members = NULL;
-  GNetXmlRpcClient *client = NULL;
-  gchar *reply  = NULL;
-       gchar *params = NULL;
-
-       if (!map)
-         return (-1);
-
-  if (!map->members)
-    return (-1);
-
-  if (id < 0 || id > (map->size - 1))
-    return (-1);
-       
-       members = map->members;
-
-  client = gnet_xmlrpc_client_new(XMLSERVICE_HOST, XMLSERVICE_URL, 
-                                       XMLSERVICE_PORT);
-
-  if (!client) {
-    logmsg(RH_LOG_ERROR, "Could not connect to XML-RPC service");
-    return (-1);
-  }
-       
-       params = g_strdup_printf("%s|%s|%s|%d|%s", 
-                           idtoip(map, id),
-                                members[id].username,
-                                                                                                        members[id].session_id,
-                                                                                                        members[id].session_start,
-                           mac_tostring(members[id].mac_address));
-
-  if (params == NULL)
-    return (-1);
-  
-  if (gnet_xmlrpc_client_call(client, "stopacct", params, &reply) == 0)
-    {
-      DP("stopacct reply = %s", reply);
-      g_free(reply);
-    }
-  else
-    DP("%s", "Failed executing stopacct!");
-       
-       g_free(params);
-
-  return 0;
-}
-
-
 struct rahunas_map* rh_init_map() {
   struct rahunas_map *map = NULL;
 
diff --git a/src/rh-xmlrpc-cmd.c b/src/rh-xmlrpc-cmd.c
new file mode 100644 (file)
index 0000000..d39fbd7
--- /dev/null
@@ -0,0 +1,57 @@
+/**
+ * XML-RPC client command sender
+ * Author: Neutron Soutmun <neo.neutron@gmail.com>
+ * Date:   2008-09-02
+ */
+
+#include "../xmlrpc/xmlrpc.h"
+#include "rahunasd.h"
+#include "rh-xmlrpc-cmd.h"
+
+int send_xmlrpc_stopacct(struct rahunas_map *map, uint32_t id) {
+  struct rahunas_member *members = NULL;
+  GNetXmlRpcClient *client = NULL;
+  gchar *reply  = NULL;
+       gchar *params = NULL;
+
+       if (!map)
+         return (-1);
+
+  if (!map->members)
+    return (-1);
+
+  if (id < 0 || id > (map->size - 1))
+    return (-1);
+       
+       members = map->members;
+
+  client = gnet_xmlrpc_client_new(XMLSERVICE_HOST, XMLSERVICE_URL, 
+                                       XMLSERVICE_PORT);
+
+  if (!client) {
+    logmsg(RH_LOG_ERROR, "Could not connect to XML-RPC service");
+    return (-1);
+  }
+       
+       params = g_strdup_printf("%s|%s|%s|%d|%s", 
+                           idtoip(map, id),
+                                members[id].username,
+                                                                                                        members[id].session_id,
+                                                                                                        members[id].session_start,
+                           mac_tostring(members[id].mac_address));
+
+  if (params == NULL)
+    return (-1);
+  
+  if (gnet_xmlrpc_client_call(client, "stopacct", params, &reply) == 0)
+    {
+      DP("stopacct reply = %s", reply);
+      g_free(reply);
+    }
+  else
+    DP("%s", "Failed executing stopacct!");
+       
+       g_free(params);
+
+  return 0;
+}
diff --git a/src/rh-xmlrpc-cmd.h b/src/rh-xmlrpc-cmd.h
new file mode 100644 (file)
index 0000000..9a1c392
--- /dev/null
@@ -0,0 +1,11 @@
+/**
+ * XML-RPC client command sender header
+ * Author: Neutron Soutmun <neo.neutron@gmail.com>
+ * Date:   2008-09-02
+ */
+#ifndef __RH_XMLRPC_CMD
+#define __RH_XMLRPC_CMD
+
+int send_xmlrpc_stopacct(struct rahunas_map *map, uint32_t id);
+
+#endif // __RH_XMLRPC_CMD