556eaddd924b177ee036b0c2bc4f5601cb025c8f
[rahunas] / src / rh-xmlrpc-cmd.c
1 /**
2  * XML-RPC client command sender
3  * Author: Neutron Soutmun <neo.neutron@gmail.com>
4  * Date:   2008-09-02
5  */
6
7 #include "../xmlrpc/xmlrpc.h"
8 #include "rahunasd.h"
9 #include "rh-xmlrpc-cmd.h"
10
11 int send_xmlrpc_stopacct(struct rahunas_map *map, uint32_t id, int cause) {
12   struct rahunas_member *members = NULL;
13   GNetXmlRpcClient *client = NULL;
14   gchar *reply  = NULL;
15         gchar *params = NULL;
16
17         if (!map)
18           return (-1);
19
20   if (!map->members)
21     return (-1);
22
23   if (id < 0 || id > (map->size - 1))
24     return (-1);
25         
26         members = map->members;
27
28         params = g_strdup_printf("%s|%s|%s|%d|%s|%d", 
29                            idtoip(map, id),
30                                  members[id].username,
31                                                                                                          members[id].session_id,
32                                                                                                          members[id].session_start,
33                            mac_tostring(members[id].mac_address),
34                            cause);
35
36   if (params == NULL)
37     return (-1);
38
39   client = gnet_xmlrpc_client_new(rh_config.xml_serv_host, 
40                                   rh_config.xml_serv_url, 
41                                         rh_config.xml_serv_port);
42
43   if (!client) {
44     logmsg(RH_LOG_ERROR, "Could not connect to XML-RPC service");
45     return (-1);
46   }
47         
48   if (gnet_xmlrpc_client_call(client, "stopacct", params, &reply) == 0)
49     {
50       DP("stopacct reply = %s", reply);
51       g_free(reply);
52     }
53   else
54     {
55       DP("%s", "Failed executing stopacct!");
56       return (-1);
57     }
58
59   gnet_xmlrpc_client_delete(client);    
60
61         g_free(params);
62
63   return 0;
64 }