]> andersk Git - moira.git/blame - clients/moira/misc.c
Diane Delgado's changes for a fixed table-locking order
[moira.git] / clients / moira / misc.c
CommitLineData
8defc06b 1/* This is the file misc.c for the MOIRA Client, which allows a naieve
2 * user to quickly and easily maintain most parts of the MOIRA database.
7310363b 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>
24419c79 22#include <string.h>
8defc06b 23#include <moira.h>
24#include <moira_site.h>
7310363b 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"
7310363b 35
36
37/* Function Name: PrintStats
38 * Description: print statistics from argv
39 * Arguments: info: statistics tuple
40 * Returns: DM_NORMAL
41 */
42
43PrintStats(info)
44char **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
8defc06b 57 * Description: display the MOIRA table statistics
7310363b 58 * Arguments: NONE
59 * Returns: DM_NORMAL
60 */
61
62int TableStats()
63{
64 int status;
65 struct qelem *elem = NULL;
66
8defc06b 67 if (status = do_mr_query("get_all_table_stats", 0, NULL,
7310363b 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
83PrintClients(info)
84char **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
8defc06b 106 * Description: show clients actively using MR
7310363b 107 * Arguments: NONE
108 * Returns: DM_NORMAL
109 */
110
111int ShowClients()
112{
113 int status;
114 struct qelem *elem = NULL;
115
8defc06b 116 if (status = do_mr_query("_list_users", 0, NULL,
7310363b 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
132PrintValue(info)
133char **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
8defc06b 143 * Description: get a variable value from MR
7310363b 144 * Arguments: variable name
145 * Returns: DM_NORMAL
146 */
147
148int ShowValue(argc, argv)
149int argc;
150char **argv;
151{
152 int status;
153 struct qelem *elem = NULL;
154
8defc06b 155 if (status = do_mr_query("get_value", 1, &argv[1],
7310363b 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
171PrintAlias(info)
172char **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
188int ShowAlias(argc, argv)
189int argc;
190char **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] = "*";
8defc06b 199 if (status = do_mr_query("get_alias", 3, info,
7310363b 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.101811 seconds and 5 git commands to generate.