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