/* @(#)rpc_svcout.c 2.1 88/08/01 4.0 RPCSRC */
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape
* media and as a part of the software program in whole or part. Users
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
* Mountain View, California 94043
static char sccsid
[] = "@(#)rpc_svcout.c 1.6 87/06/24 (C) 1987 SMI";
* rpc_svcout.c, Server-skeleton outputter for the RPC protocol compiler
* Copyright (C) 1987, Sun Microsytsems, Inc.
static char RQSTP
[] = "rqstp";
static char TRANSP
[] = "transp";
static char ARG
[] = "argument";
static char RESULT
[] = "result";
static char ROUTINE
[] = "local";
* write most of the service, that is, everything but the registrations.
for (l
= defined
; l
!= NULL
; l
= l
->next
) {
def
= (definition
*) l
->val
;
if (def
->def_kind
== DEF_PROGRAM
) {
for (vp
= def
->def
.pr
.versions
; vp
!= NULL
; vp
= vp
->next
) {
f_print(fout
, "\nstatic void ");
pvname(def
->def_name
, vp
->vers_num
);
f_print(fout
, "main()\n");
f_print(fout
, "\tSVCXPRT *%s;\n", TRANSP
);
for (l
= defined
; l
!= NULL
; l
= l
->next
) {
def
= (definition
*) l
->val
;
if (def
->def_kind
!= DEF_PROGRAM
) {
for (vp
= def
->def
.pr
.versions
; vp
!= NULL
; vp
= vp
->next
) {
f_print(fout
, "\t(void)pmap_unset(%s, %s);\n", def
->def_name
, vp
->vers_name
);
* write a registration for the given transport
f_print(fout
, "\t%s = svc%s_create(RPC_ANYSOCK", TRANSP
, transp
);
if (streq(transp
, "tcp")) {
f_print(fout
, "\tif (%s == NULL) {\n", TRANSP
);
f_print(fout
, "\t\t(void)fprintf(stderr, \"cannot create %s service.\\n\");\n", transp
);
f_print(fout
, "\t\texit(1);\n");
for (l
= defined
; l
!= NULL
; l
= l
->next
) {
def
= (definition
*) l
->val
;
if (def
->def_kind
!= DEF_PROGRAM
) {
for (vp
= def
->def
.pr
.versions
; vp
!= NULL
; vp
= vp
->next
) {
"\tif (!svc_register(%s, %s, %s, ",
TRANSP
, def
->def_name
, vp
->vers_name
);
pvname(def
->def_name
, vp
->vers_num
);
f_print(fout
, ", IPPROTO_%s)) {\n",
streq(transp
, "udp") ? "UDP" : "TCP");
"\t\t(void)fprintf(stderr, \"unable to register (%s, %s, %s).\\n\");\n",
def
->def_name
, vp
->vers_name
, transp
);
f_print(fout
, "\t\texit(1);\n");
* write the rest of the service
f_print(fout
, "\tsvc_run();\n");
f_print(fout
, "\t(void)fprintf(stderr, \"svc_run returned\\n\");\n");
f_print(fout
, "\texit(1);\n");
for (l
= defined
; l
!= NULL
; l
= l
->next
) {
def
= (definition
*) l
->val
;
if (def
->def_kind
== DEF_PROGRAM
) {
write_program(def
, storage
);
write_program(def
, storage
)
for (vp
= def
->def
.pr
.versions
; vp
!= NULL
; vp
= vp
->next
) {
f_print(fout
, "%s ", storage
);
pvname(def
->def_name
, vp
->vers_num
);
f_print(fout
, "(%s, %s)\n", RQSTP
, TRANSP
);
f_print(fout
, " struct svc_req *%s;\n", RQSTP
);
f_print(fout
, " SVCXPRT *%s;\n", TRANSP
);
f_print(fout
, "\tunion {\n");
for (proc
= vp
->procs
; proc
!= NULL
; proc
= proc
->next
) {
if (streq(proc
->arg_type
, "void")) {
ptype(proc
->arg_prefix
, proc
->arg_type
, 0);
pvname(proc
->proc_name
, vp
->vers_num
);
f_print(fout
, "_arg;\n");
f_print(fout
, "\t\tint fill;\n");
f_print(fout
, "\t} %s;\n", ARG
);
f_print(fout
, "\tchar *%s;\n", RESULT
);
f_print(fout
, "\tbool_t (*xdr_%s)(), (*xdr_%s)();\n", ARG
, RESULT
);
f_print(fout
, "\tchar *(*%s)();\n", ROUTINE
);
f_print(fout
, "\tswitch (%s->rq_proc) {\n", RQSTP
);
if (!nullproc(vp
->procs
)) {
f_print(fout
, "\tcase NULLPROC:\n");
f_print(fout
, "\t\t(void)svc_sendreply(%s, xdr_void, (char *)NULL);\n", TRANSP
);
f_print(fout
, "\t\treturn;\n\n");
for (proc
= vp
->procs
; proc
!= NULL
; proc
= proc
->next
) {
f_print(fout
, "\tcase %s:\n", proc
->proc_name
);
f_print(fout
, "\t\txdr_%s = xdr_%s;\n", ARG
,
stringfix(proc
->arg_type
));
f_print(fout
, "\t\txdr_%s = xdr_%s;\n", RESULT
,
stringfix(proc
->res_type
));
f_print(fout
, "\t\t%s = (char *(*)()) ", ROUTINE
);
pvname(proc
->proc_name
, vp
->vers_num
);
f_print(fout
, "\t\tbreak;\n\n");
f_print(fout
, "\tdefault:\n");
printerr("noproc", TRANSP
);
f_print(fout
, "\t\treturn;\n");
f_print(fout
, "\tbzero((char *)&%s, sizeof(%s));\n", ARG
, ARG
);
printif("getargs", TRANSP
, "&", ARG
);
printerr("decode", TRANSP
);
f_print(fout
, "\t\treturn;\n");
f_print(fout
, "\t%s = (*%s)(&%s, %s);\n", RESULT
, ROUTINE
, ARG
,
"\tif (%s != NULL && !svc_sendreply(%s, xdr_%s, %s)) {\n",
RESULT
, TRANSP
, RESULT
, RESULT
);
printerr("systemerr", TRANSP
);
printif("freeargs", TRANSP
, "&", ARG
);
f_print(fout
, "\t\t(void)fprintf(stderr, \"unable to free arguments\\n\");\n");
f_print(fout
, "\t\texit(1);\n");
f_print(fout
, "\t\tsvcerr_%s(%s);\n", err
, transp
);
printif(proc
, transp
, prefix
, arg
)
f_print(fout
, "\tif (!svc_%s(%s, xdr_%s, %s%s)) {\n",
proc
, transp
, arg
, prefix
, arg
);
for (; proc
!= NULL
; proc
= proc
->next
) {
if (streq(proc
->proc_num
, "0")) {