]> andersk Git - moira.git/blob - clients/moira/misc.c
3c9c4d1f837c577cac8f96eb4cca552b43d7f02a
[moira.git] / clients / moira / misc.c
1 /*      This is the file misc.c for the SMS Client, which allows a naieve
2  *      user to quickly and easily maintain most parts of the SMS 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 <strings.h>
23 #include <sms.h>
24 #include <sms_app.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 PrintStats(info)
44 char **info;
45 {
46     char buf[BUFSIZ];
47
48     sprintf(buf, "Table: %-30s Modified: %s", info[0], info[5]);
49     Put_message(buf);
50     sprintf(buf, "    %s appends, %s updates, %s deletes",
51             info[2], info[3], info[4]);
52     Put_message(buf);
53 }
54
55
56 /*      Function Name: TableStats
57  *      Description: display the SMS table statistics
58  *      Arguments: NONE
59  *      Returns: DM_NORMAL
60  */
61
62 int TableStats()
63 {
64     int status;
65     struct qelem *elem = NULL;
66
67     if (status = do_sms_query("get_all_table_stats", 0, NULL,
68                               StoreInfo, (char *)&elem)) {
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 PrintClients(info)
84 char **info;
85 {
86     char buf[BUFSIZ];
87     unsigned long host_address;
88     struct hostent *host_entry;
89
90     host_address = inet_addr(info[1]);
91     if (host_address != NULL) {
92         host_entry = gethostbyaddr((char *) &host_address, 4, AF_INET);
93         if (host_entry != NULL) {
94             free(info[1]);
95             info[1] = Strsave(host_entry->h_name);
96         }
97     }
98     sprintf(buf, "Principal %s on %s (%s)", info[0], info[1], info[2]);
99     Put_message(buf);
100     sprintf(buf, "    Connected at %s, client %s", info[3], info[4]);
101     Put_message(buf);
102 }
103
104
105 /*      Function Name: ShowClients
106  *      Description: show clients actively using SMS
107  *      Arguments: NONE
108  *      Returns: DM_NORMAL
109  */
110
111 int ShowClients()
112 {
113     int status;
114     struct qelem *elem = NULL;
115
116     if (status = do_sms_query("_list_users", 0, NULL,
117                               StoreInfo, (char *) &elem)) {
118         com_err(program_name, status, " in ShowClients");
119         return(DM_NORMAL);
120     }
121     Loop(QueueTop(elem), PrintClients);
122     FreeQueue(elem);
123     return(DM_NORMAL);
124 }
125
126
127 /*      Function Name: PrintValue
128  *      Description: displays variable values
129  *      Arguments: argv
130  */
131
132 PrintValue(info)
133 char **info;
134 {
135     char buf[BUFSIZ];
136
137     sprintf(buf, "Value: %s", info[0]);
138     Put_message(buf);
139 }
140
141
142 /*      Function Name: ShowValue
143  *      Description: get a variable value from SMS
144  *      Arguments: variable name
145  *      Returns: DM_NORMAL
146  */
147
148 int ShowValue(argc, argv)
149 int argc;
150 char **argv;
151 {
152     int status;
153     struct qelem *elem = NULL;
154
155     if (status = do_sms_query("get_value", 1, &argv[1],
156                               StoreInfo, (char *) &elem)) {
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 PrintAlias(info)
172 char **info;
173 {
174     char buf[BUFSIZ];
175
176     sprintf(buf, "Name: %-20s Type: %-12s Value: %s",
177             info[0], info[1], info[2]);
178     Put_message(buf);
179 }
180
181
182 /*      Function Name: ShowAlias
183  *      Description: display an alias relation
184  *      Arguments: name & type of alias
185  *      Returns: DM_NORMAL
186  */
187
188 int ShowAlias(argc, argv)
189 int argc;
190 char **argv;
191 {
192     int status;
193     char *info[4];
194     struct qelem *elem = NULL;
195
196     info[0] = argv[1];
197     info[1] = argv[2];
198     info[2] = "*";
199     if (status = do_sms_query("get_alias", 3, info,
200                               StoreInfo, (char *) &elem)) {
201         com_err(program_name, status, " in ShowAlias");
202         return(DM_NORMAL);
203     }
204     Loop(QueueTop(elem), PrintAlias);
205     FreeQueue(elem);
206     return(DM_NORMAL);
207 }
This page took 0.039408 seconds and 3 git commands to generate.