]> andersk Git - moira.git/blob - server/qsubs.c
Allow hostname to start with a digit in hostname_check, but disallow it
[moira.git] / server / qsubs.c
1 /* $Id$
2  *
3  * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology
4  * For copying and distribution information, please see the file
5  * <mit-copyright.h>.
6  */
7
8 #include <mit-copyright.h>
9 #include "mr_server.h"
10 #include "query.h"
11
12 #include <stdlib.h>
13
14 RCSID("$Header$");
15
16 extern struct query Queries2[];
17 extern int QueryCount2;
18
19 int qcmp(const void *q1, const void *q2);
20
21 struct query *get_query_by_name(char *name)
22 {
23   struct query *q;
24   int i;
25
26   q = Queries2;
27   i = QueryCount2;
28
29   if (strlen(name) == 4)
30     {
31       while (--i >= 0)
32         {
33           if (!strcmp(q->shortname, name))
34             return q;
35           q++;
36         }
37     }
38   else
39     {
40       while (--i >= 0)
41         {
42           if (!strcmp(q->name, name))
43             return q;
44           q++;
45         }
46     }
47
48   return NULL;
49 }
50
51 void list_queries(int (*action)(int, char *[], void *), void *actarg)
52 {
53   struct query *q;
54   int i;
55   static struct query **squeries2 = NULL;
56   struct query **sq;
57   char qnames[80];
58   char *qnp;
59   int count;
60
61   count = QueryCount2;
62   if (!squeries2)
63     {
64       sq = xmalloc(count * sizeof(struct query *));
65       squeries2 = sq;
66       q = Queries2;
67       for (i = count; --i >= 0; )
68         *sq++ = q++;
69       qsort(squeries2, count, sizeof(struct query *), qcmp);
70     }
71   sq = squeries2;
72
73   qnp = qnames;
74   for (i = count; --i >= 0; sq++)
75     {
76       sprintf(qnames, "%s (%s)", (*sq)->name, (*sq)->shortname);
77       (*action)(1, &qnp, actarg);
78     }
79   strcpy(qnames, "_help");
80   (*action)(1, &qnp, actarg);
81   strcpy(qnames, "_list_queries");
82   (*action)(1, &qnp, actarg);
83   strcpy(qnames, "_list_users");
84   (*action)(1, &qnp, actarg);
85 }
86
87 void help_query(struct query *q, int (*action)(int, char *[], void *),
88                 void *actarg)
89 {
90   int argcount;
91   int i;
92   char argn[32];
93   char qname[512];
94   char argr[512];
95   char *argv[32];
96
97   argcount = q->argc;
98   if (q->type == UPDATE || q->type == APPEND)
99     argcount += q->vcnt;
100
101   switch (argcount)
102     {
103     case 0:
104       sprintf(qname, "   %s, %s ()", q->name, q->shortname);
105       argv[0] = qname;
106       argcount = 1;
107       break;
108
109     case 1:
110       sprintf(qname, "   %s, %s (%s)", q->name, q->shortname, q->fields[0]);
111       argv[0] = qname;
112       argcount = 1;
113       break;
114
115     case 2:
116       sprintf(qname, "   %s, %s (%s, %s)", q->name, q->shortname,
117               q->fields[0], q->fields[1]);
118       argv[0] = qname;
119       argcount = 1;
120       break;
121
122     default:
123       sprintf(qname, "   %s, %s (%s", q->name, q->shortname, q->fields[0]);
124       argv[0] = qname;
125       argcount--;
126       for (i = 1; i < argcount; i++)
127         argv[i] = q->fields[i];
128       sprintf(argn, "%s)", q->fields[argcount]);
129       argv[argcount++] = argn;
130       break;
131     }
132
133   if (q->type == RETRIEVE)
134     {
135       sprintf(argr, "%s => %s", argv[--argcount], q->fields[q->argc]);
136       argv[argcount++] = argr;
137       if (q->vcnt > 1)
138         {
139           for (i = q->argc + 1; i < q->vcnt + q->argc; i++)
140             argv[argcount++] = q->fields[i];
141         }
142     }
143   (*action)(argcount, argv, actarg);
144 }
145
146 int qcmp(const void *q1, const void *q2)
147 {
148   return strcmp((*(struct query **)q1)->name, (*(struct query **)q2)->name);
149 }
This page took 0.045866 seconds and 5 git commands to generate.