1 /* @(#)rpc_svcout.c 1.2 87/11/24 3.9 RPCSRC */
3 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
4 * unrestricted use provided that this legend is included on all tape
5 * media and as a part of the software program in whole or part. Users
6 * may copy or modify Sun RPC without charge, but are not authorized
7 * to license or distribute it to anyone else except as part of a product or
8 * program developed by the user.
10 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
11 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
12 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14 * Sun RPC is provided with no support and without any obligation on the
15 * part of Sun Microsystems, Inc. to assist in its use, correction,
16 * modification or enhancement.
18 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
19 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
20 * OR ANY PART THEREOF.
22 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
23 * or profits or other special, indirect and consequential damages, even if
24 * Sun has been advised of the possibility of such damages.
26 * Sun Microsystems, Inc.
28 * Mountain View, California 94043
32 * rpc_svcout.c, Server-skeleton outputter for the RPC protocol compiler
33 * Copyright (C) 1987, Sun Microsytsems, Inc.
35 #include <afsconfig.h>
36 #include <afs/param.h>
44 #include "rpc_parse.h"
47 static char RQSTP[] = "rqstp";
48 static char TRANSP[] = "transp";
49 static char ARG[] = "argument";
50 static char RESULT[] = "result";
51 static char ROUTINE[] = "local";
53 /* static prototypes */
54 static void write_program(definition * def, char *storage);
55 static void printerr(char *err, char *transp);
56 static void printif(char *proc, char *transp, char *prefix, char *arg);
60 * write most of the service, that is, everything but the registrations.
69 for (l = defined; l != NULL; l = l->next) {
70 def = (definition *) l->val;
71 if (def->def_kind == DEF_PROGRAM) {
72 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
73 f_print(fout, "\nstatic void ");
74 pvname(def->def_name, vp->vers_num);
79 f_print(fout, "\n\n");
80 f_print(fout, "main()\n");
82 f_print(fout, "\tSVCXPRT *%s;\n", TRANSP);
84 for (l = defined; l != NULL; l = l->next) {
85 def = (definition *) l->val;
86 if (def->def_kind != DEF_PROGRAM) {
89 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
90 f_print(fout, "\tpmap_unset(%s, %s);\n", def->def_name,
98 * write a registration for the given transport
101 write_register(char *transp)
108 f_print(fout, "\t%s = svc%s_create(RPC_ANYSOCK", TRANSP, transp);
109 if (streq(transp, "tcp")) {
110 f_print(fout, ", 0, 0");
112 f_print(fout, ");\n");
113 f_print(fout, "\tif (%s == NULL) {\n", TRANSP);
114 f_print(fout, "\t\tfprintf(stderr, \"cannot create %s service.\\n\");\n",
116 f_print(fout, "\t\texit(1);\n");
117 f_print(fout, "\t}\n");
119 for (l = defined; l != NULL; l = l->next) {
120 def = (definition *) l->val;
121 if (def->def_kind != DEF_PROGRAM) {
124 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
125 f_print(fout, "\tif (!svc_register(%s, %s, %s, ", TRANSP,
126 def->def_name, vp->vers_name);
127 pvname(def->def_name, vp->vers_num);
128 f_print(fout, ", IPPROTO_%s)) {\n",
129 streq(transp, "udp") ? "UDP" : "TCP");
131 "\t\tfprintf(stderr, \"unable to register (%s, %s, %s).\\n\");\n",
132 def->def_name, vp->vers_name, transp);
133 f_print(fout, "\t\texit(1);\n");
134 f_print(fout, "\t}\n");
141 * write the rest of the service
146 f_print(fout, "\tsvc_run();\n");
147 f_print(fout, "\tfprintf(stderr, \"svc_run returned\\n\");\n");
148 f_print(fout, "\texit(1);\n");
149 f_print(fout, "}\n");
153 write_programs(char *storage)
158 for (l = defined; l != NULL; l = l->next) {
159 def = (definition *) l->val;
160 if (def->def_kind == DEF_PROGRAM) {
161 write_program(def, storage);
168 write_program(definition * def, char *storage)
174 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
176 if (storage != NULL) {
177 f_print(fout, "%s ", storage);
179 f_print(fout, "void\n");
180 pvname(def->def_name, vp->vers_num);
181 f_print(fout, "(%s, %s)\n", RQSTP, TRANSP);
182 f_print(fout, " struct svc_req *%s;\n", RQSTP);
183 f_print(fout, " SVCXPRT *%s;\n", TRANSP);
184 f_print(fout, "{\n");
187 f_print(fout, "\tunion {\n");
188 for (proc = vp->procs; proc != NULL; proc = proc->next) {
189 if (streq(proc->arg_type, "void")) {
193 f_print(fout, "\t\t");
194 ptype(proc->arg_prefix, proc->arg_type, 0);
195 pvname(proc->proc_name, vp->vers_num);
196 f_print(fout, "_arg;\n");
199 f_print(fout, "\t\tint fill;\n");
201 f_print(fout, "\t} %s;\n", ARG);
202 f_print(fout, "\tchar *%s;\n", RESULT);
203 f_print(fout, "\tbool_t (*xdr_%s)(), (*xdr_%s)();\n", ARG, RESULT);
204 f_print(fout, "\tchar *(*%s)();\n", ROUTINE);
206 f_print(fout, "\tswitch (%s->rq_proc) {\n", RQSTP);
208 if (!nullproc(vp->procs)) {
209 f_print(fout, "\tcase NULLPROC:\n");
210 f_print(fout, "\t\tsvc_sendreply(%s, xdr_void, NULL);\n", TRANSP);
211 f_print(fout, "\t\treturn;\n\n");
213 for (proc = vp->procs; proc != NULL; proc = proc->next) {
214 f_print(fout, "\tcase %s:\n", proc->proc_name);
215 f_print(fout, "\t\txdr_%s = xdr_%s;\n", ARG,
216 stringfix(proc->arg_type));
217 f_print(fout, "\t\txdr_%s = xdr_%s;\n", RESULT,
218 stringfix(proc->res_type));
219 f_print(fout, "\t\t%s = (char *(*)()) ", ROUTINE);
220 pvname(proc->proc_name, vp->vers_num);
221 f_print(fout, ";\n");
222 f_print(fout, "\t\tbreak;\n\n");
224 f_print(fout, "\tdefault:\n");
225 printerr("noproc", TRANSP);
226 f_print(fout, "\t\treturn;\n");
227 f_print(fout, "\t}\n");
229 f_print(fout, "\tmemset(&%s, 0, sizeof(%s));\n", ARG, ARG);
230 printif("getargs", TRANSP, "&", ARG);
231 printerr("decode", TRANSP);
232 f_print(fout, "\t\treturn;\n");
233 f_print(fout, "\t}\n");
235 f_print(fout, "\t%s = (*%s)(&%s, %s);\n", RESULT, ROUTINE, ARG,
238 "\tif (%s != NULL && !svc_sendreply(%s, xdr_%s, %s)) {\n",
239 RESULT, TRANSP, RESULT, RESULT);
240 printerr("systemerr", TRANSP);
241 f_print(fout, "\t}\n");
243 printif("freeargs", TRANSP, "&", ARG);
245 "\t\tfprintf(stderr, \"unable to free arguments\\n\");\n");
246 f_print(fout, "\t\texit(1);\n");
247 f_print(fout, "\t}\n");
249 f_print(fout, "}\n\n");
254 printerr(char *err, char *transp)
256 f_print(fout, "\t\tsvcerr_%s(%s);\n", err, transp);
260 printif(char *proc, char *transp, char *prefix, char *arg)
262 f_print(fout, "\tif (!svc_%s(%s, xdr_%s, %s%s)) {\n", proc, transp, arg,
268 nullproc(proc_list * proc)
270 for (; proc != NULL; proc = proc->next) {
271 if (streq(proc->proc_num, "0")) {