]>
Commit | Line | Data |
---|---|---|
a3cf6921 | 1 | /* |
2 | * $Source$ | |
3 | * $Author$ | |
4 | * $Header$ | |
5 | * | |
6 | * Copyright (C) 1987 by the Massachusetts Institute of Technology | |
7 | * | |
8 | * $Log$ | |
28222705 | 9 | * Revision 1.8 1987-07-16 15:43:19 wesommer |
10 | * Fixed bug where the argv was not copied to private storage | |
11 | * (it got changed out from under us before it got sent..). | |
a3cf6921 | 12 | * |
28222705 | 13 | * Revision 1.7 87/07/14 00:39:01 wesommer |
14 | * Rearranged loggin. | |
15 | * | |
630e8323 | 16 | * Revision 1.6 87/06/30 20:04:43 wesommer |
17 | * Free returned tuples when possible. | |
18 | * | |
ed31e0d1 | 19 | * Revision 1.5 87/06/26 10:55:53 wesommer |
20 | * Added sms_access, now paiys attention to return code from | |
21 | * sms_process_query, sms_check_access. | |
22 | * | |
3630192b | 23 | * Revision 1.4 87/06/21 16:42:00 wesommer |
24 | * Performance work, rearrangement of include files. | |
25 | * | |
c27b3454 | 26 | * Revision 1.3 87/06/04 01:35:01 wesommer |
27 | * Added a working query request handler. | |
28 | * | |
78849033 | 29 | * Revision 1.2 87/06/03 16:07:50 wesommer |
30 | * Fixes for lint. | |
31 | * | |
5dbd09a0 | 32 | * Revision 1.1 87/06/02 20:07:10 wesommer |
33 | * Initial revision | |
34 | * | |
a3cf6921 | 35 | */ |
36 | ||
37 | #ifndef lint | |
38 | static char *rcsid_sms_scall_c = "$Header$"; | |
39 | #endif lint | |
40 | ||
41 | #include <krb.h> | |
78849033 | 42 | #include <errno.h> |
a3cf6921 | 43 | #include "sms_server.h" |
44 | extern char buf1[]; | |
45 | extern int nclients; | |
46 | extern char *whoami; | |
28222705 | 47 | extern char *malloc(); |
a3cf6921 | 48 | |
49 | extern void clist_delete(), do_auth(), do_shutdown(); | |
50 | void do_call(); | |
51 | ||
52 | /* | |
53 | * Welcome to the (finite state) machine (highest level). | |
54 | */ | |
55 | void | |
56 | do_client(cp) | |
57 | client *cp; | |
58 | { | |
ed31e0d1 | 59 | free_rtn_tuples(cp); |
a3cf6921 | 60 | if (OP_STATUS(cp->pending_op) == OP_CANCELLED) { |
61 | (void) sprintf(buf1, "Closed connection (now %d client%s)", | |
62 | nclients-1, | |
63 | nclients!=2?"s":""); | |
64 | com_err(whoami, 0, buf1); | |
65 | clist_delete(cp); | |
66 | return; | |
67 | } | |
68 | switch (cp->action) { | |
69 | case CL_ACCEPT: | |
70 | case CL_SEND: | |
71 | /* Start recieving next request */ | |
72 | initialize_operation(cp->pending_op, sms_start_recv, | |
5dbd09a0 | 73 | (char *)&cp->args, (int (*)())NULL); |
a3cf6921 | 74 | queue_operation(cp->con, CON_INPUT, cp->pending_op); |
75 | cp->action = CL_RECEIVE; | |
76 | break; | |
77 | case CL_RECEIVE: | |
78 | /* Data is here. Process it & start it heading back */ | |
79 | do_call(cp); /* This may block for a while. */ | |
80 | initialize_operation(cp->pending_op, sms_start_send, | |
5dbd09a0 | 81 | (char *)&cp->reply, (int (*)())NULL); |
a3cf6921 | 82 | queue_operation(cp->con, CON_OUTPUT, cp->pending_op); |
83 | cp->action = CL_SEND; | |
84 | break; | |
85 | } | |
86 | } | |
87 | ||
a3cf6921 | 88 | char *procnames[] = { |
89 | "noop", | |
90 | "auth", | |
91 | "shutdown", | |
78849033 | 92 | "query", |
630e8323 | 93 | "access", |
94 | }; | |
95 | ||
a3cf6921 | 96 | |
97 | void | |
98 | do_call(cl) | |
99 | client *cl; | |
100 | { | |
101 | int pn; | |
102 | cl->reply.sms_argc = 0; | |
103 | cl->reply.sms_status = 0; | |
104 | if (((pn = cl->args->sms_procno) < 0) || | |
105 | (pn > SMS_MAX_PROC)) { | |
106 | com_err(whoami, 0, "procno out of range"); | |
107 | cl->reply.sms_status = SMS_UNKNOWN_PROC; | |
108 | return; | |
109 | } | |
630e8323 | 110 | if (log_flags & LOG_ARGS) |
111 | log_args(procnames[pn], cl->args->sms_argc, | |
112 | cl->args->sms_argv); | |
113 | else if (log_flags & LOG_REQUESTS) | |
114 | com_err(whoami, 0, procnames[pn]); | |
a3cf6921 | 115 | |
116 | switch(pn) { | |
117 | case SMS_NOOP: | |
118 | cl->reply.sms_status = 0; | |
a3cf6921 | 119 | return; |
3630192b | 120 | |
a3cf6921 | 121 | case SMS_AUTH: |
122 | do_auth(cl); | |
123 | return; | |
78849033 | 124 | |
125 | case SMS_QUERY: | |
a3cf6921 | 126 | do_retr(cl); |
127 | return; | |
a3cf6921 | 128 | |
3630192b | 129 | case SMS_ACCESS: |
130 | do_access(cl); | |
131 | return; | |
132 | ||
a3cf6921 | 133 | case SMS_SHUTDOWN: |
134 | do_shutdown(cl); | |
135 | return; | |
136 | } | |
137 | } | |
138 | ||
ed31e0d1 | 139 | free_rtn_tuples(cp) |
140 | client *cp; | |
141 | { | |
142 | register returned_tuples *temp; | |
143 | for (temp=cp->first; temp && OP_DONE(temp->op); ) { | |
144 | register returned_tuples *t1=temp; | |
145 | temp = t1->next; | |
146 | if (t1 == cp->last) cp->last = NULL; | |
28222705 | 147 | |
ed31e0d1 | 148 | sms_destroy_reply(t1->retval); |
28222705 | 149 | #ifdef notdef |
ed31e0d1 | 150 | if (t1->retval) { |
151 | register sms_params *p = t1->retval; | |
152 | if (p->sms_flattened) | |
153 | free(p->sms_flattened); | |
154 | if (p->sms_argl) | |
155 | free(p->sms_argl); | |
156 | free(p); | |
157 | } | |
28222705 | 158 | #endif notdef |
ed31e0d1 | 159 | delete_operation(t1->op); |
160 | free(t1); | |
161 | } | |
162 | cp->first = temp; | |
163 | } | |
164 | ||
78849033 | 165 | retr_callback(argc, argv, p_cp) |
28222705 | 166 | register int argc; |
167 | register char **argv; | |
78849033 | 168 | char *p_cp; |
169 | { | |
170 | register client *cp = (client *)p_cp; | |
78849033 | 171 | /* |
172 | * This takes too much advantage of the fact that | |
173 | * serialization of the data happens during the queue operation. | |
174 | */ | |
175 | sms_params *arg_tmp = (sms_params *)db_alloc(sizeof(sms_params)); | |
ed31e0d1 | 176 | returned_tuples *tp = (returned_tuples *) |
177 | db_alloc(sizeof(returned_tuples)); | |
28222705 | 178 | register char **nargv = (char **)malloc(argc * sizeof(char *)); |
179 | register int i; | |
ed31e0d1 | 180 | |
78849033 | 181 | OPERATION op_tmp = create_operation(); |
78849033 | 182 | |
630e8323 | 183 | if (log_flags & LOG_RESP) |
184 | log_args("return: ", argc, argv); | |
185 | ||
ed31e0d1 | 186 | tp->op = op_tmp; |
187 | tp->retval = arg_tmp; | |
188 | tp->next = NULL; | |
78849033 | 189 | |
190 | arg_tmp->sms_status = SMS_MORE_DATA; | |
191 | arg_tmp->sms_argc = argc; | |
28222705 | 192 | arg_tmp->sms_argv = nargv; |
193 | for (i = 0; i < argc; i++) { | |
194 | register int len = strlen(argv[i]) + 1; | |
195 | nargv[i] = malloc(len); | |
196 | bcopy(argv[i], nargv[i], len); | |
197 | } | |
78849033 | 198 | arg_tmp->sms_flattened = (char *)NULL; |
199 | arg_tmp->sms_argl = (int *)NULL; | |
ed31e0d1 | 200 | |
201 | if (cp->last) { | |
202 | cp->last->next = tp; | |
203 | cp->last = tp; | |
204 | } else { | |
205 | cp->last = cp->first = tp; | |
206 | } | |
207 | ||
78849033 | 208 | reset_operation(op_tmp); |
209 | initialize_operation(op_tmp, sms_start_send, (char *)arg_tmp, | |
210 | (int (*)())NULL); | |
211 | queue_operation(cp->con, CON_OUTPUT, op_tmp); | |
212 | } | |
213 | ||
214 | ||
a3cf6921 | 215 | do_retr(cl) |
216 | client *cl; | |
217 | { | |
78849033 | 218 | cl->reply.sms_argc = 0; |
219 | cl->reply.sms_status = 0; | |
630e8323 | 220 | |
3630192b | 221 | cl->reply.sms_status = |
222 | sms_process_query(cl, | |
223 | cl->args->sms_argv[0], | |
224 | cl->args->sms_argc-1, | |
225 | cl->args->sms_argv+1, | |
226 | retr_callback, | |
227 | (char *)cl); | |
630e8323 | 228 | if (log_flags & LOG_RES) |
229 | com_err(whoami, 0, "Query complete."); | |
a3cf6921 | 230 | } |
78849033 | 231 | |
3630192b | 232 | do_access(cl) |
233 | client *cl; | |
234 | { | |
235 | cl->reply.sms_argc = 0; | |
630e8323 | 236 | |
3630192b | 237 | cl->reply.sms_status = |
238 | sms_check_access(cl, | |
239 | cl->args->sms_argv[0], | |
240 | cl->args->sms_argc-1, | |
241 | cl->args->sms_argv+1); | |
242 | ||
243 | com_err(whoami, 0, "Access check complete."); | |
244 | } |