]> andersk Git - moira.git/blob - server/mr_scall.c
Added a working query request handler.
[moira.git] / server / mr_scall.c
1 /*
2  *      $Source$
3  *      $Author$
4  *      $Header$
5  *
6  *      Copyright (C) 1987 by the Massachusetts Institute of Technology
7  *
8  *      $Log$
9  *      Revision 1.3  1987-06-04 01:35:01  wesommer
10  *      Added a working query request handler.
11  *
12  * Revision 1.2  87/06/03  16:07:50  wesommer
13  * Fixes for lint.
14  * 
15  * Revision 1.1  87/06/02  20:07:10  wesommer
16  * Initial revision
17  * 
18  */
19
20 #ifndef lint
21 static char *rcsid_sms_scall_c = "$Header$";
22 #endif lint
23
24 #include <krb.h>
25 #include <errno.h>
26 #include "sms_private.h"
27 #include "sms_server.h"
28 extern char buf1[];
29 extern int nclients;
30 extern char *whoami;
31
32 extern void clist_delete(), do_auth(), do_shutdown();
33 void do_call();
34
35 /*
36  * Welcome to the (finite state) machine (highest level).
37  */
38 void
39 do_client(cp)
40         client *cp;
41 {
42         if (OP_STATUS(cp->pending_op) == OP_CANCELLED) {
43                 (void) sprintf(buf1, "Closed connection (now %d client%s)",
44                                nclients-1,
45                                nclients!=2?"s":"");
46                 com_err(whoami, 0, buf1);
47                 clist_delete(cp);
48                 return;
49         }
50         switch (cp->action) {
51         case CL_ACCEPT:
52         case CL_SEND:
53                 /* Start recieving next request */
54                 initialize_operation(cp->pending_op, sms_start_recv,
55                                      (char *)&cp->args, (int (*)())NULL);
56                 queue_operation(cp->con, CON_INPUT, cp->pending_op);
57                 cp->action = CL_RECEIVE;
58                 break;
59         case CL_RECEIVE:
60                 /* Data is here. Process it & start it heading back */
61                 do_call(cp); /* This may block for a while. */
62                 initialize_operation(cp->pending_op, sms_start_send,
63                                      (char *)&cp->reply, (int (*)())NULL);
64                 queue_operation(cp->con, CON_OUTPUT, cp->pending_op);
65                 cp->action = CL_SEND;
66                 break;
67         }
68 }               
69
70 #ifdef notdef
71 char *procnames[] = {
72          "noop",
73          "auth",
74          "shutdown",
75          "query",
76          };
77 #endif notdef
78
79 void
80 do_call(cl)
81         client *cl;
82 {
83         int pn;
84         cl->reply.sms_argc = 0;
85         cl->reply.sms_status = 0;
86         if (((pn = cl->args->sms_procno) < 0) ||
87             (pn > SMS_MAX_PROC)) {
88                 com_err(whoami, 0, "procno out of range");
89                 cl->reply.sms_status = SMS_UNKNOWN_PROC;
90                 return;
91         }
92 #ifdef SMS_DBG
93         fprintf(stderr, "[#%d] %s(", cl->id, procnames[pn]);
94         for (i=0; i < cl->args->sms_argc; i++) {
95                 if (i) fputc(',', stderr);
96                 frequote(stderr,cl->args->sms_argv[i]);
97         }
98         fprintf(stderr, ")\n");
99 #endif SMS_DBG
100
101         switch(pn) {
102         case SMS_NOOP:
103                 cl->reply.sms_status = 0;
104                 com_err(whoami, 0, "noop");
105                 return;
106         case SMS_AUTH:
107                 do_auth(cl);
108                 return;
109
110         case SMS_QUERY:
111                 do_retr(cl);
112                 return;
113
114         case SMS_SHUTDOWN:
115                 do_shutdown(cl);
116                 return;
117         }
118 }
119
120 retr_callback(argc, argv, p_cp)
121         int argc;
122         char **argv;
123         char *p_cp;
124 {
125         register client *cp = (client *)p_cp;
126         /* XXX MEM when are these freed?? */
127         /*
128          * This takes too much advantage of the fact that
129          * serialization of the data happens during the queue operation.
130          */
131         sms_params *arg_tmp = (sms_params *)db_alloc(sizeof(sms_params));
132         OPERATION op_tmp = create_operation();
133         
134
135 #ifdef notdef                   /* We really don't want this logged */
136         com_err(whoami, 0, "Returning next data:");
137         log_args(argc, argv);
138 #endif notdef
139         
140         arg_tmp->sms_status = SMS_MORE_DATA;
141         arg_tmp->sms_argc = argc;
142         arg_tmp->sms_argv = argv;
143         arg_tmp->sms_flattened = (char *)NULL;
144         arg_tmp->sms_argl = (int *)NULL;
145         reset_operation(op_tmp);
146         initialize_operation(op_tmp, sms_start_send, (char *)arg_tmp,
147                              (int (*)())NULL);
148         queue_operation(cp->con, CON_OUTPUT, op_tmp);
149 }
150
151
152 do_retr(cl)
153         client *cl;
154 {
155         cl->reply.sms_argc = 0;
156         cl->reply.sms_status = 0;
157
158         if (!cl->clname) {
159                 com_err(whoami, 0, "Unauthenticated query rejected");
160                 cl->reply.sms_status = EACCES;
161                 return;
162         }
163         com_err(whoami, 0, "Processing query: ");
164         log_args(cl->args->sms_argc, cl->args->sms_argv);
165         
166         sms_process_query(cl->args->sms_argv[0],
167                           cl->args->sms_argc-1,
168                           cl->args->sms_argv+1,
169                           retr_callback,
170                           (char *)cl);
171
172         com_err(whoami, 0, "Query complete.");
173 }
174
This page took 0.046691 seconds and 5 git commands to generate.