]> andersk Git - moira.git/blame - clients/moira/misc.c
Command line printer manipulation client, and build goo.
[moira.git] / clients / moira / misc.c
CommitLineData
c441a31a 1/* $Id$
7ac48069 2 *
3 * This is the file misc.c for the Moira Client, which allows a naieve
59ec8dae 4 * to quickly and easily maintain most parts of the Moira database.
5eaef520 5 * It Contains:
7310363b 6 * TableStats
7 * ShowClients
8 * ShowValue
9 *
10 * Created: 5 October 1988
11 * By: Mark A. Rosenstein
12 *
7ac48069 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>.
7310363b 16 */
17
7ac48069 18#include <mit-copyright.h>
8defc06b 19#include <moira.h>
20#include <moira_site.h>
7ac48069 21#include "defs.h"
22#include "f_defs.h"
23#include "globals.h"
24
7310363b 25#include <sys/types.h>
533bacb3 26#ifndef _WIN32
7310363b 27#include <sys/socket.h>
28#include <netinet/in.h>
7ac48069 29#include <arpa/inet.h>
30#include <netdb.h>
533bacb3 31#endif /* _WIN32 */
7310363b 32
7ac48069 33#include <stdio.h>
34#include <stdlib.h>
35#include <string.h>
36
37RCSID("$Header$");
7310363b 38
7ac48069 39void PrintStats(char **info);
40void PrintClients(char **info);
41void PrintValue(char **info);
42void PrintAlias(char **info);
7310363b 43
44/* Function Name: PrintStats
45 * Description: print statistics from argv
46 * Arguments: info: statistics tuple
47 * Returns: DM_NORMAL
48 */
49
7ac48069 50void PrintStats(char **info)
7310363b 51{
5eaef520 52 char buf[BUFSIZ];
7310363b 53
9d4e1174 54 sprintf(buf, "Table: %-30s Modified: %s", info[0], info[4]);
5eaef520 55 Put_message(buf);
56 sprintf(buf, " %s appends, %s updates, %s deletes",
9d4e1174 57 info[1], info[2], info[3]);
5eaef520 58 Put_message(buf);
7310363b 59}
60
61
62/* Function Name: TableStats
59ec8dae 63 * Description: display the Moira table statistics
7310363b 64 * Arguments: NONE
65 * Returns: DM_NORMAL
66 */
67
7ac48069 68int TableStats(int argc, char **argv)
7310363b 69{
5eaef520 70 int status;
600b459e 71 struct mqelem *elem = NULL;
5eaef520 72
7ac48069 73 if ((status = do_mr_query("get_all_table_stats", 0, NULL, StoreInfo, &elem)))
5eaef520 74 {
75 com_err(program_name, status, " in TableStats");
76 return DM_NORMAL;
7310363b 77 }
5eaef520 78 Loop(QueueTop(elem), PrintStats);
79 FreeQueue(elem);
80 return DM_NORMAL;
7310363b 81}
82
83
84/* Function Name: PrintClients
85 * Description: print info from client tuple
86 * Arguments: argv
87 */
88
7ac48069 89void PrintClients(char **info)
7310363b 90{
5eaef520 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]);
7ac48069 102 info[1] = strdup(host_entry->h_name);
7310363b 103 }
104 }
5eaef520 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);
7310363b 109}
110
111
112/* Function Name: ShowClients
8defc06b 113 * Description: show clients actively using MR
7310363b 114 * Arguments: NONE
115 * Returns: DM_NORMAL
116 */
117
7ac48069 118int ShowClients(int argc, char **argv)
7310363b 119{
5eaef520 120 int status;
600b459e 121 struct mqelem *elem = NULL;
5eaef520 122
7ac48069 123 if ((status = do_mr_query("_list_users", 0, NULL, StoreInfo, &elem)))
5eaef520 124 {
125 com_err(program_name, status, " in ShowClients");
126 return DM_NORMAL;
7310363b 127 }
5eaef520 128 Loop(QueueTop(elem), PrintClients);
129 FreeQueue(elem);
130 return DM_NORMAL;
7310363b 131}
132
133
134/* Function Name: PrintValue
135 * Description: displays variable values
136 * Arguments: argv
137 */
138
7ac48069 139void PrintValue(char **info)
7310363b 140{
5eaef520 141 char buf[BUFSIZ];
7310363b 142
5eaef520 143 sprintf(buf, "Value: %s", info[0]);
144 Put_message(buf);
7310363b 145}
146
147
148/* Function Name: ShowValue
8defc06b 149 * Description: get a variable value from MR
7310363b 150 * Arguments: variable name
151 * Returns: DM_NORMAL
152 */
153
5eaef520 154int ShowValue(int argc, char **argv)
7310363b 155{
5eaef520 156 int status;
600b459e 157 struct mqelem *elem = NULL;
5eaef520 158
7ac48069 159 if ((status = do_mr_query("get_value", 1, &argv[1], StoreInfo, &elem)))
5eaef520 160 {
161 com_err(program_name, status, " in ShowValue");
162 return DM_NORMAL;
7310363b 163 }
5eaef520 164 Loop(elem, PrintValue);
165 FreeQueue(elem);
166 return DM_NORMAL;
7310363b 167}
168
169
170/* Function Name: PrintAlias
171 * Description: print an alias relation
172 * Arguments: argv
173 */
174
7ac48069 175void PrintAlias(char **info)
7310363b 176{
5eaef520 177 char buf[BUFSIZ];
7310363b 178
5eaef520 179 sprintf(buf, "Name: %-20s Type: %-12s Value: %s",
180 info[0], info[1], info[2]);
181 Put_message(buf);
7310363b 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
5eaef520 191int ShowAlias(int argc, char **argv)
7310363b 192{
5eaef520 193 int status;
194 char *info[4];
600b459e 195 struct mqelem *elem = NULL;
5eaef520 196
197 info[0] = argv[1];
198 info[1] = argv[2];
199 info[2] = "*";
7ac48069 200 if ((status = do_mr_query("get_alias", 3, info, StoreInfo, &elem)))
5eaef520 201 {
202 com_err(program_name, status, " in ShowAlias");
203 return DM_NORMAL;
7310363b 204 }
5eaef520 205 Loop(QueueTop(elem), PrintAlias);
206 FreeQueue(elem);
207 return DM_NORMAL;
7310363b 208}
This page took 0.340579 seconds and 6 git commands to generate.