]> andersk Git - moira.git/blob - clients/moira/misc.c
second code style cleanup: void/void * usage, proper #includes. try to
[moira.git] / clients / moira / misc.c
1 /* $Id $
2  *
3  *      This is the file misc.c for the Moira Client, which allows a naieve
4  *      to quickly and easily maintain most parts of the Moira database.
5  *      It Contains:
6  *              TableStats
7  *              ShowClients
8  *              ShowValue
9  *
10  *      Created:        5 October 1988
11  *      By:             Mark A. Rosenstein
12  *
13  * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
14  * For copying and distribution information, please see the file
15  * <mit-copyright.h>.
16  */
17
18 #include <mit-copyright.h>
19 #include <moira.h>
20 #include <moira_site.h>
21 #include "defs.h"
22 #include "f_defs.h"
23 #include "globals.h"
24
25 #include <sys/types.h>
26 #include <sys/socket.h>
27 #include <netinet/in.h>
28 #include <arpa/inet.h>
29 #include <netdb.h>
30
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34
35 RCSID("$Header$");
36
37 void PrintStats(char **info);
38 void PrintClients(char **info);
39 void PrintValue(char **info);
40 void PrintAlias(char **info);
41
42 /*      Function Name: PrintStats
43  *      Description: print statistics from argv
44  *      Arguments: info: statistics tuple
45  *      Returns: DM_NORMAL
46  */
47
48 void PrintStats(char **info)
49 {
50   char buf[BUFSIZ];
51
52   sprintf(buf, "Table: %-30s Modified: %s", info[0], info[5]);
53   Put_message(buf);
54   sprintf(buf, "    %s appends, %s updates, %s deletes",
55           info[2], info[3], info[4]);
56   Put_message(buf);
57 }
58
59
60 /*      Function Name: TableStats
61  *      Description: display the Moira table statistics
62  *      Arguments: NONE
63  *      Returns: DM_NORMAL
64  */
65
66 int TableStats(int argc, char **argv)
67 {
68   int status;
69   struct qelem *elem = NULL;
70
71   if ((status = do_mr_query("get_all_table_stats", 0, NULL, StoreInfo, &elem)))
72     {
73       com_err(program_name, status, " in TableStats");
74       return DM_NORMAL;
75     }
76   Loop(QueueTop(elem), PrintStats);
77   FreeQueue(elem);
78   return DM_NORMAL;
79 }
80
81
82 /*      Function Name: PrintClients
83  *      Description: print info from client tuple
84  *      Arguments: argv
85  */
86
87 void PrintClients(char **info)
88 {
89   char buf[BUFSIZ];
90   unsigned long host_address;
91   struct hostent *host_entry;
92
93   host_address = inet_addr(info[1]);
94   if (host_address)
95     {
96       host_entry = gethostbyaddr((char *) &host_address, 4, AF_INET);
97       if (host_entry)
98         {
99           free(info[1]);
100           info[1] = strdup(host_entry->h_name);
101         }
102     }
103   sprintf(buf, "Principal %s on %s (%s)", info[0], info[1], info[2]);
104   Put_message(buf);
105   sprintf(buf, "    Connected at %s, client %s", info[3], info[4]);
106   Put_message(buf);
107 }
108
109
110 /*      Function Name: ShowClients
111  *      Description: show clients actively using MR
112  *      Arguments: NONE
113  *      Returns: DM_NORMAL
114  */
115
116 int ShowClients(int argc, char **argv)
117 {
118   int status;
119   struct qelem *elem = NULL;
120
121   if ((status = do_mr_query("_list_users", 0, NULL, StoreInfo, &elem)))
122     {
123       com_err(program_name, status, " in ShowClients");
124       return DM_NORMAL;
125     }
126   Loop(QueueTop(elem), PrintClients);
127   FreeQueue(elem);
128   return DM_NORMAL;
129 }
130
131
132 /*      Function Name: PrintValue
133  *      Description: displays variable values
134  *      Arguments: argv
135  */
136
137 void PrintValue(char **info)
138 {
139   char buf[BUFSIZ];
140
141   sprintf(buf, "Value: %s", info[0]);
142   Put_message(buf);
143 }
144
145
146 /*      Function Name: ShowValue
147  *      Description: get a variable value from MR
148  *      Arguments: variable name
149  *      Returns: DM_NORMAL
150  */
151
152 int ShowValue(int argc, char **argv)
153 {
154   int status;
155   struct qelem *elem = NULL;
156
157   if ((status = do_mr_query("get_value", 1, &argv[1], StoreInfo, &elem)))
158     {
159       com_err(program_name, status, " in ShowValue");
160       return DM_NORMAL;
161     }
162   Loop(elem, PrintValue);
163   FreeQueue(elem);
164   return DM_NORMAL;
165 }
166
167
168 /*      Function Name: PrintAlias
169  *      Description: print an alias relation
170  *      Arguments: argv
171  */
172
173 void PrintAlias(char **info)
174 {
175   char buf[BUFSIZ];
176
177   sprintf(buf, "Name: %-20s Type: %-12s Value: %s",
178           info[0], info[1], info[2]);
179   Put_message(buf);
180 }
181
182
183 /*      Function Name: ShowAlias
184  *      Description: display an alias relation
185  *      Arguments: name & type of alias
186  *      Returns: DM_NORMAL
187  */
188
189 int ShowAlias(int argc, char **argv)
190 {
191   int status;
192   char *info[4];
193   struct qelem *elem = NULL;
194
195   info[0] = argv[1];
196   info[1] = argv[2];
197   info[2] = "*";
198   if ((status = do_mr_query("get_alias", 3, info, StoreInfo, &elem)))
199     {
200       com_err(program_name, status, " in ShowAlias");
201       return DM_NORMAL;
202     }
203   Loop(QueueTop(elem), PrintAlias);
204   FreeQueue(elem);
205   return DM_NORMAL;
206 }
This page took 0.049538 seconds and 5 git commands to generate.