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