]> andersk Git - moira.git/blob - clients/moira/misc.c
Win32 portability mods for Pismere.
[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 #ifndef _WIN32
27 #include <sys/socket.h>
28 #include <netinet/in.h>
29 #include <arpa/inet.h>
30 #include <netdb.h>
31 #endif /* _WIN32 */
32
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36
37 RCSID("$Header$");
38
39 void PrintStats(char **info);
40 void PrintClients(char **info);
41 void PrintValue(char **info);
42 void PrintAlias(char **info);
43
44 /*      Function Name: PrintStats
45  *      Description: print statistics from argv
46  *      Arguments: info: statistics tuple
47  *      Returns: DM_NORMAL
48  */
49
50 void PrintStats(char **info)
51 {
52   char buf[BUFSIZ];
53
54   sprintf(buf, "Table: %-30s Modified: %s", info[0], info[4]);
55   Put_message(buf);
56   sprintf(buf, "    %s appends, %s updates, %s deletes",
57           info[1], info[2], info[3]);
58   Put_message(buf);
59 }
60
61
62 /*      Function Name: TableStats
63  *      Description: display the Moira table statistics
64  *      Arguments: NONE
65  *      Returns: DM_NORMAL
66  */
67
68 int TableStats(int argc, char **argv)
69 {
70   int status;
71   struct mqelem *elem = NULL;
72
73   if ((status = do_mr_query("get_all_table_stats", 0, NULL, StoreInfo, &elem)))
74     {
75       com_err(program_name, status, " in TableStats");
76       return DM_NORMAL;
77     }
78   Loop(QueueTop(elem), PrintStats);
79   FreeQueue(elem);
80   return DM_NORMAL;
81 }
82
83
84 /*      Function Name: PrintClients
85  *      Description: print info from client tuple
86  *      Arguments: argv
87  */
88
89 void PrintClients(char **info)
90 {
91   char buf[BUFSIZ];
92   unsigned long host_address;
93   struct hostent *host_entry;
94
95   host_address = inet_addr(info[1]);
96   if (host_address)
97     {
98       host_entry = gethostbyaddr((char *) &host_address, 4, AF_INET);
99       if (host_entry)
100         {
101           free(info[1]);
102           info[1] = strdup(host_entry->h_name);
103         }
104     }
105   sprintf(buf, "Principal %s on %s (%s)", info[0], info[1], info[2]);
106   Put_message(buf);
107   sprintf(buf, "    Connected at %s, client %s", info[3], info[4]);
108   Put_message(buf);
109 }
110
111
112 /*      Function Name: ShowClients
113  *      Description: show clients actively using MR
114  *      Arguments: NONE
115  *      Returns: DM_NORMAL
116  */
117
118 int ShowClients(int argc, char **argv)
119 {
120   int status;
121   struct mqelem *elem = NULL;
122
123   if ((status = do_mr_query("_list_users", 0, NULL, StoreInfo, &elem)))
124     {
125       com_err(program_name, status, " in ShowClients");
126       return DM_NORMAL;
127     }
128   Loop(QueueTop(elem), PrintClients);
129   FreeQueue(elem);
130   return DM_NORMAL;
131 }
132
133
134 /*      Function Name: PrintValue
135  *      Description: displays variable values
136  *      Arguments: argv
137  */
138
139 void PrintValue(char **info)
140 {
141   char buf[BUFSIZ];
142
143   sprintf(buf, "Value: %s", info[0]);
144   Put_message(buf);
145 }
146
147
148 /*      Function Name: ShowValue
149  *      Description: get a variable value from MR
150  *      Arguments: variable name
151  *      Returns: DM_NORMAL
152  */
153
154 int ShowValue(int argc, char **argv)
155 {
156   int status;
157   struct mqelem *elem = NULL;
158
159   if ((status = do_mr_query("get_value", 1, &argv[1], StoreInfo, &elem)))
160     {
161       com_err(program_name, status, " in ShowValue");
162       return DM_NORMAL;
163     }
164   Loop(elem, PrintValue);
165   FreeQueue(elem);
166   return DM_NORMAL;
167 }
168
169
170 /*      Function Name: PrintAlias
171  *      Description: print an alias relation
172  *      Arguments: argv
173  */
174
175 void PrintAlias(char **info)
176 {
177   char buf[BUFSIZ];
178
179   sprintf(buf, "Name: %-20s Type: %-12s Value: %s",
180           info[0], info[1], info[2]);
181   Put_message(buf);
182 }
183
184
185 /*      Function Name: ShowAlias
186  *      Description: display an alias relation
187  *      Arguments: name & type of alias
188  *      Returns: DM_NORMAL
189  */
190
191 int ShowAlias(int argc, char **argv)
192 {
193   int status;
194   char *info[4];
195   struct mqelem *elem = NULL;
196
197   info[0] = argv[1];
198   info[1] = argv[2];
199   info[2] = "*";
200   if ((status = do_mr_query("get_alias", 3, info, StoreInfo, &elem)))
201     {
202       com_err(program_name, status, " in ShowAlias");
203       return DM_NORMAL;
204     }
205   Loop(QueueTop(elem), PrintAlias);
206   FreeQueue(elem);
207   return DM_NORMAL;
208 }
This page took 0.054343 seconds and 5 git commands to generate.