Deleted Added
full compact
rpc_svcout.c (149733) rpc_svcout.c (152398)
1/*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
8 *

--- 21 unchanged lines hidden (view full) ---

30#if 0
31#ifndef lint
32#ident "@(#)rpc_svcout.c 1.4 90/04/13 SMI"
33static char sccsid[] = "@(#)rpc_svcout.c 1.29 89/03/30 (C) 1987 SMI";
34#endif
35#endif
36
37#include <sys/cdefs.h>
1/*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
8 *

--- 21 unchanged lines hidden (view full) ---

30#if 0
31#ifndef lint
32#ident "@(#)rpc_svcout.c 1.4 90/04/13 SMI"
33static char sccsid[] = "@(#)rpc_svcout.c 1.29 89/03/30 (C) 1987 SMI";
34#endif
35#endif
36
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD: head/usr.bin/rpcgen/rpc_svcout.c 149733 2005-09-02 19:33:50Z stefanf $");
38__FBSDID("$FreeBSD: head/usr.bin/rpcgen/rpc_svcout.c 152398 2005-11-13 21:17:24Z dwmalone $");
39
40/*
41 * rpc_svcout.c, Server-skeleton outputter for the RPC protocol compiler
42 * Copyright (C) 1987, Sun Microsystems, Inc.
43 */
44#include <stdio.h>
45#include <string.h>
46#include "rpc_parse.h"
47#include "rpc_scan.h"
48#include "rpc_util.h"
49
39
40/*
41 * rpc_svcout.c, Server-skeleton outputter for the RPC protocol compiler
42 * Copyright (C) 1987, Sun Microsystems, Inc.
43 */
44#include <stdio.h>
45#include <string.h>
46#include "rpc_parse.h"
47#include "rpc_scan.h"
48#include "rpc_util.h"
49
50extern int tirpc_socket;
51
52static char RQSTP[] = "rqstp";
53static char TRANSP[] = "transp";
54static char ARG[] = "argument";
55static char RESULT[] = "result";
56static char ROUTINE[] = "local";
57static char RETVAL[] = "retval";
58
59char _errbuf[256]; /* For all messages */
60
61void internal_proctype( proc_list * );
62static void write_real_program( definition * );
50static char RQSTP[] = "rqstp";
51static char TRANSP[] = "transp";
52static char ARG[] = "argument";
53static char RESULT[] = "result";
54static char ROUTINE[] = "local";
55static char RETVAL[] = "retval";
56
57char _errbuf[256]; /* For all messages */
58
59void internal_proctype( proc_list * );
60static void write_real_program( definition * );
63static void write_program( definition *, char * );
64static void printerr( char *, char * );
65static void printif( char *, char *, char *, char * );
66static void write_inetmost( char * );
67static void print_return( char * );
68static void print_pmapunset( char * );
69static void print_err_message( char * );
61static void write_program(definition *, const char *);
62static void printerr(const char *, const char *);
63static void printif(const char *, const char *, const char *, const char *);
64static void write_inetmost(const char *);
65static void print_return(const char *);
66static void print_pmapunset(const char *);
67static void print_err_message(const char *);
70static void write_timeout_func( void );
68static void write_timeout_func( void );
71static void write_pm_most( char *, int );
72static void write_rpc_svc_fg( char *, char * );
73static void open_log_file( char *, char * );
69static void write_pm_most(const char *, int);
70static void write_rpc_svc_fg(const char *, const char *);
71static void open_log_file(const char *, const char *);
74static void write_msg_out( void );
72static void write_msg_out( void );
75int nullproc( proc_list * );
76
77
78static void
73
74
75static void
79p_xdrfunc(rname, typename)
80char* rname;
81char* typename;
76p_xdrfunc(const char *rname, const char *typename)
82{
83 f_print(fout, "\t\txdr_%s = (xdrproc_t) xdr_%s;\n",
84 rname, stringfix(typename));
85}
86
87void
77{
78 f_print(fout, "\t\txdr_%s = (xdrproc_t) xdr_%s;\n",
79 rname, stringfix(typename));
80}
81
82void
88internal_proctype(plist)
89 proc_list *plist;
83internal_proctype(proc_list *plist)
90{
91 f_print(fout, "static ");
92 ptype(plist->res_prefix, plist->res_type, 1);
93 f_print(fout, "*");
94}
95
96
97/*
98 * write most of the service, that is, everything but the registrations.
99 */
100void
84{
85 f_print(fout, "static ");
86 ptype(plist->res_prefix, plist->res_type, 1);
87 f_print(fout, "*");
88}
89
90
91/*
92 * write most of the service, that is, everything but the registrations.
93 */
94void
101write_most(infile, netflag, nomain)
102 char *infile; /* our name */
103 int netflag;
104 int nomain;
95write_most(const char *infile, int netflag, int nomain)
105{
106 if (inetdflag || pmflag) {
96{
97 if (inetdflag || pmflag) {
107 char* var_type;
98 const char *var_type;
108 var_type = (nomain? "extern" : "static");
109 f_print(fout, "%s int _rpcpmstart;", var_type);
110 f_print(fout, "\t\t/* Started by a port monitor ? */\n");
111 if (!tirpcflag || tirpc_socket) {
112 f_print(fout, "%s int _rpcfdtype;", var_type);
113 f_print(fout, "\n\t\t /* Whether Stream or \
114Datagram ? */\n");
115 }

--- 74 unchanged lines hidden (view full) ---

190 open_log_file(infile, "\t");
191 }
192}
193
194/*
195 * write a registration for the given transport
196 */
197void
99 var_type = (nomain? "extern" : "static");
100 f_print(fout, "%s int _rpcpmstart;", var_type);
101 f_print(fout, "\t\t/* Started by a port monitor ? */\n");
102 if (!tirpcflag || tirpc_socket) {
103 f_print(fout, "%s int _rpcfdtype;", var_type);
104 f_print(fout, "\n\t\t /* Whether Stream or \
105Datagram ? */\n");
106 }

--- 74 unchanged lines hidden (view full) ---

181 open_log_file(infile, "\t");
182 }
183}
184
185/*
186 * write a registration for the given transport
187 */
188void
198write_netid_register(transp)
199 char *transp;
189write_netid_register(const char *transp)
200{
201 list *l;
202 definition *def;
203 version_list *vp;
190{
191 list *l;
192 definition *def;
193 version_list *vp;
204 char *sp;
194 const char *sp;
205 char tmpbuf[32];
206
207 sp = "";
208 f_print(fout, "\n");
209 f_print(fout, "%s\tnconf = getnetconfigent(\"%s\");\n", sp, transp);
210 f_print(fout, "%s\tif (nconf == NULL) {\n", sp);
211 (void) sprintf(_errbuf, "cannot find %s netid.", transp);
212 sprintf(tmpbuf, "%s\t\t", sp);

--- 39 unchanged lines hidden (view full) ---

252 }
253 f_print(fout, "%s\tfreenetconfigent(nconf);\n", sp);
254}
255
256/*
257 * write a registration for the given transport for TLI
258 */
259void
195 char tmpbuf[32];
196
197 sp = "";
198 f_print(fout, "\n");
199 f_print(fout, "%s\tnconf = getnetconfigent(\"%s\");\n", sp, transp);
200 f_print(fout, "%s\tif (nconf == NULL) {\n", sp);
201 (void) sprintf(_errbuf, "cannot find %s netid.", transp);
202 sprintf(tmpbuf, "%s\t\t", sp);

--- 39 unchanged lines hidden (view full) ---

242 }
243 f_print(fout, "%s\tfreenetconfigent(nconf);\n", sp);
244}
245
246/*
247 * write a registration for the given transport for TLI
248 */
249void
260write_nettype_register(transp)
261 char *transp;
250write_nettype_register(const char *transp)
262{
263 list *l;
264 definition *def;
265 version_list *vp;
266
267 for (l = defined; l != NULL; l = l->next) {
268 def = (definition *) l->val;
269 if (def->def_kind != DEF_PROGRAM) {

--- 17 unchanged lines hidden (view full) ---

287 }
288 }
289}
290
291/*
292 * write the rest of the service
293 */
294void
251{
252 list *l;
253 definition *def;
254 version_list *vp;
255
256 for (l = defined; l != NULL; l = l->next) {
257 def = (definition *) l->val;
258 if (def->def_kind != DEF_PROGRAM) {

--- 17 unchanged lines hidden (view full) ---

276 }
277 }
278}
279
280/*
281 * write the rest of the service
282 */
283void
295write_rest()
284write_rest(void)
296{
297 f_print(fout, "\n");
298 if (inetdflag) {
299 f_print(fout, "\tif (%s == (SVCXPRT *)NULL) {\n", TRANSP);
300 (void) sprintf(_errbuf, "could not create a handle");
301 print_err_message("\t\t");
302 f_print(fout, "\t\texit(1);\n");
303 f_print(fout, "\t}\n");

--- 10 unchanged lines hidden (view full) ---

314 (void) sprintf(_errbuf, "svc_run returned");
315 print_err_message("\t");
316 f_print(fout, "\texit(1);\n");
317 f_print(fout, "\t/* NOTREACHED */\n");
318 f_print(fout, "}\n");
319}
320
321void
285{
286 f_print(fout, "\n");
287 if (inetdflag) {
288 f_print(fout, "\tif (%s == (SVCXPRT *)NULL) {\n", TRANSP);
289 (void) sprintf(_errbuf, "could not create a handle");
290 print_err_message("\t\t");
291 f_print(fout, "\t\texit(1);\n");
292 f_print(fout, "\t}\n");

--- 10 unchanged lines hidden (view full) ---

303 (void) sprintf(_errbuf, "svc_run returned");
304 print_err_message("\t");
305 f_print(fout, "\texit(1);\n");
306 f_print(fout, "\t/* NOTREACHED */\n");
307 f_print(fout, "}\n");
308}
309
310void
322write_programs(storage)
323 char *storage;
311write_programs(const char *storage)
324{
325 list *l;
326 definition *def;
327
328 /* write out stubs for procedure definitions */
329 for (l = defined; l != NULL; l = l->next) {
330 def = (definition *) l->val;
331 if (def->def_kind == DEF_PROGRAM) {

--- 14 unchanged lines hidden (view full) ---

346
347/*
348 * write out definition of internal function (e.g. _printmsg_1(...))
349 * which calls server's defintion of actual function (e.g. printmsg_1(...)).
350 * Unpacks single user argument of printmsg_1 to call-by-value format
351 * expected by printmsg_1.
352 */
353static void
312{
313 list *l;
314 definition *def;
315
316 /* write out stubs for procedure definitions */
317 for (l = defined; l != NULL; l = l->next) {
318 def = (definition *) l->val;
319 if (def->def_kind == DEF_PROGRAM) {

--- 14 unchanged lines hidden (view full) ---

334
335/*
336 * write out definition of internal function (e.g. _printmsg_1(...))
337 * which calls server's defintion of actual function (e.g. printmsg_1(...)).
338 * Unpacks single user argument of printmsg_1 to call-by-value format
339 * expected by printmsg_1.
340 */
341static void
354write_real_program(def)
355 definition *def;
342write_real_program(definition *def)
356{
357 version_list *vp;
358 proc_list *proc;
359 decl_list *l;
360
361 if (!newstyle) return; /* not needed for old style */
362 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
363 for (proc = vp->procs; proc != NULL; proc = proc->next) {

--- 37 unchanged lines hidden (view full) ---

401 if (mtflag)
402 f_print(fout, "%s, ",RESULT);
403 f_print(fout, "%s));\n}\n", RQSTP);
404 }
405 }
406}
407
408static void
343{
344 version_list *vp;
345 proc_list *proc;
346 decl_list *l;
347
348 if (!newstyle) return; /* not needed for old style */
349 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
350 for (proc = vp->procs; proc != NULL; proc = proc->next) {

--- 37 unchanged lines hidden (view full) ---

388 if (mtflag)
389 f_print(fout, "%s, ",RESULT);
390 f_print(fout, "%s));\n}\n", RQSTP);
391 }
392 }
393}
394
395static void
409write_program(def, storage)
410 definition *def;
411 char *storage;
396write_program(definition *def, const char *storage)
412{
413 version_list *vp;
414 proc_list *proc;
415 int filled;
416
417 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
418 f_print(fout, "\n");
419 if (storage != NULL) {

--- 154 unchanged lines hidden (view full) ---

574 f_print(fout, "\n");
575 };
576 print_return("\t");
577 f_print(fout, "}\n");
578 }
579}
580
581static void
397{
398 version_list *vp;
399 proc_list *proc;
400 int filled;
401
402 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
403 f_print(fout, "\n");
404 if (storage != NULL) {

--- 154 unchanged lines hidden (view full) ---

559 f_print(fout, "\n");
560 };
561 print_return("\t");
562 f_print(fout, "}\n");
563 }
564}
565
566static void
582printerr(err, transp)
583 char *err;
584 char *transp;
567printerr(const char *err, const char *transp)
585{
586 f_print(fout, "\t\tsvcerr_%s(%s);\n", err, transp);
587}
588
589static void
568{
569 f_print(fout, "\t\tsvcerr_%s(%s);\n", err, transp);
570}
571
572static void
590printif(proc, transp, prefix, arg)
591 char *proc;
592 char *transp;
593 char *prefix;
594 char *arg;
573printif(const char *proc, const char *transp, const char *prefix,
574 const char *arg)
595{
596 f_print(fout, "\tif (!svc_%s(%s, xdr_%s, (char *)%s%s)) {\n",
597 proc, transp, arg, prefix, arg);
598}
599
600int
575{
576 f_print(fout, "\tif (!svc_%s(%s, xdr_%s, (char *)%s%s)) {\n",
577 proc, transp, arg, prefix, arg);
578}
579
580int
601nullproc(proc)
602 proc_list *proc;
581nullproc(proc_list *proc)
603{
604 for (; proc != NULL; proc = proc->next) {
605 if (streq(proc->proc_num, "0")) {
606 return (1);
607 }
608 }
609 return (0);
610}
611
612static void
582{
583 for (; proc != NULL; proc = proc->next) {
584 if (streq(proc->proc_num, "0")) {
585 return (1);
586 }
587 }
588 return (0);
589}
590
591static void
613write_inetmost(infile)
614 char *infile;
592write_inetmost(const char *infile)
615{
616 f_print(fout, "\tregister SVCXPRT *%s;\n", TRANSP);
617 f_print(fout, "\tint sock;\n");
618 f_print(fout, "\tint proto;\n");
619 f_print(fout, "\tstruct sockaddr_in saddr;\n");
620 f_print(fout, "\tsocklen_t asize = sizeof (saddr);\n");
621 f_print(fout, "\n");
622 f_print(fout,

--- 11 unchanged lines hidden (view full) ---

634 f_print(fout, "\t} else {\n");
635 write_rpc_svc_fg(infile, "\t\t");
636 f_print(fout, "\t\tsock = RPC_ANYSOCK;\n");
637 print_pmapunset("\t\t");
638 f_print(fout, "\t}\n");
639}
640
641static void
593{
594 f_print(fout, "\tregister SVCXPRT *%s;\n", TRANSP);
595 f_print(fout, "\tint sock;\n");
596 f_print(fout, "\tint proto;\n");
597 f_print(fout, "\tstruct sockaddr_in saddr;\n");
598 f_print(fout, "\tsocklen_t asize = sizeof (saddr);\n");
599 f_print(fout, "\n");
600 f_print(fout,

--- 11 unchanged lines hidden (view full) ---

612 f_print(fout, "\t} else {\n");
613 write_rpc_svc_fg(infile, "\t\t");
614 f_print(fout, "\t\tsock = RPC_ANYSOCK;\n");
615 print_pmapunset("\t\t");
616 f_print(fout, "\t}\n");
617}
618
619static void
642print_return(space)
643 char *space;
620print_return(const char *space)
644{
645 if (exitnow)
646 f_print(fout, "%sexit(0);\n", space);
647 else {
648 if (timerflag) {
649 if (mtflag)
650 f_print(fout, "%smutex_lock(&_svcstate_lock);\n", space);
651 f_print(fout, "%s_rpcsvcstate = _SERVED;\n", space);
652 if (mtflag)
653 f_print(fout, "%smutex_unlock(&_svcstate_lock);\n", space);
654 }
655 f_print(fout, "%sreturn;\n", space);
656 }
657}
658
659static void
621{
622 if (exitnow)
623 f_print(fout, "%sexit(0);\n", space);
624 else {
625 if (timerflag) {
626 if (mtflag)
627 f_print(fout, "%smutex_lock(&_svcstate_lock);\n", space);
628 f_print(fout, "%s_rpcsvcstate = _SERVED;\n", space);
629 if (mtflag)
630 f_print(fout, "%smutex_unlock(&_svcstate_lock);\n", space);
631 }
632 f_print(fout, "%sreturn;\n", space);
633 }
634}
635
636static void
660print_pmapunset(space)
661 char *space;
637print_pmapunset(const char *space)
662{
663 list *l;
664 definition *def;
665 version_list *vp;
666
667 for (l = defined; l != NULL; l = l->next) {
668 def = (definition *) l->val;
669 if (def->def_kind == DEF_PROGRAM) {
670 for (vp = def->def.pr.versions; vp != NULL;
671 vp = vp->next) {
672 f_print(fout, "%s(void) pmap_unset(%s, %s);\n",
673 space, def->def_name, vp->vers_name);
674 }
675 }
676 }
677}
678
679static void
638{
639 list *l;
640 definition *def;
641 version_list *vp;
642
643 for (l = defined; l != NULL; l = l->next) {
644 def = (definition *) l->val;
645 if (def->def_kind == DEF_PROGRAM) {
646 for (vp = def->def.pr.versions; vp != NULL;
647 vp = vp->next) {
648 f_print(fout, "%s(void) pmap_unset(%s, %s);\n",
649 space, def->def_name, vp->vers_name);
650 }
651 }
652 }
653}
654
655static void
680print_err_message(space)
681 char *space;
656print_err_message(const char *space)
682{
683 if (logflag)
684 f_print(fout, "%ssyslog(LOG_ERR, \"%s\");\n", space, _errbuf);
685 else if (inetdflag || pmflag)
686 f_print(fout, "%s_msgout(\"%s\");\n", space, _errbuf);
687 else
688 f_print(fout, "%sfprintf(stderr, \"%s\");\n", space, _errbuf);
689}
690
691/*
692 * Write the server auxiliary function (_msgout, timeout)
693 */
694void
657{
658 if (logflag)
659 f_print(fout, "%ssyslog(LOG_ERR, \"%s\");\n", space, _errbuf);
660 else if (inetdflag || pmflag)
661 f_print(fout, "%s_msgout(\"%s\");\n", space, _errbuf);
662 else
663 f_print(fout, "%sfprintf(stderr, \"%s\");\n", space, _errbuf);
664}
665
666/*
667 * Write the server auxiliary function (_msgout, timeout)
668 */
669void
695write_svc_aux(nomain)
696 int nomain;
670write_svc_aux(int nomain)
697{
698 if (!logflag)
699 write_msg_out();
700 if (!nomain)
701 write_timeout_func();
702}
703
704/*

--- 83 unchanged lines hidden (view full) ---

788 f_print(fout, "}\n");
789
790}
791
792/*
793 * Write the most of port monitor support
794 */
795static void
671{
672 if (!logflag)
673 write_msg_out();
674 if (!nomain)
675 write_timeout_func();
676}
677
678/*

--- 83 unchanged lines hidden (view full) ---

762 f_print(fout, "}\n");
763
764}
765
766/*
767 * Write the most of port monitor support
768 */
769static void
796write_pm_most(infile, netflag)
797 char *infile;
798 int netflag;
770write_pm_most(const char *infile, int netflag)
799{
800 list *l;
801 definition *def;
802 version_list *vp;
803
804 if (tirpc_socket) {
805 f_print(fout,
806 "\tif (getsockname(0, (struct sockaddr *)&saddr, &asize) == 0) {\n");

--- 106 unchanged lines hidden (view full) ---

913 f_print(fout, "\t\t/* NOTREACHED */\n");
914 f_print(fout, "\t}");
915}
916
917/*
918 * Support for backgrounding the server if self started.
919 */
920static void
771{
772 list *l;
773 definition *def;
774 version_list *vp;
775
776 if (tirpc_socket) {
777 f_print(fout,
778 "\tif (getsockname(0, (struct sockaddr *)&saddr, &asize) == 0) {\n");

--- 106 unchanged lines hidden (view full) ---

885 f_print(fout, "\t\t/* NOTREACHED */\n");
886 f_print(fout, "\t}");
887}
888
889/*
890 * Support for backgrounding the server if self started.
891 */
892static void
921write_rpc_svc_fg(infile, sp)
922 char *infile;
923 char *sp;
893write_rpc_svc_fg(const char *infile, const char *sp)
924{
925 f_print(fout, "#ifndef RPC_SVC_FG\n");
926 f_print(fout, "%sint size;\n", sp);
927 if (tirpcflag)
928 f_print(fout, "%sstruct rlimit rl;\n", sp);
929 if (inetdflag)
930 f_print(fout, "%sint pid, i;\n\n", sp);
931 f_print(fout, "%spid = fork();\n", sp);

--- 33 unchanged lines hidden (view full) ---

965 if (!logflag)
966 open_log_file(infile, sp);
967 f_print(fout, "#endif\n");
968 if (logflag)
969 open_log_file(infile, sp);
970}
971
972static void
894{
895 f_print(fout, "#ifndef RPC_SVC_FG\n");
896 f_print(fout, "%sint size;\n", sp);
897 if (tirpcflag)
898 f_print(fout, "%sstruct rlimit rl;\n", sp);
899 if (inetdflag)
900 f_print(fout, "%sint pid, i;\n\n", sp);
901 f_print(fout, "%spid = fork();\n", sp);

--- 33 unchanged lines hidden (view full) ---

935 if (!logflag)
936 open_log_file(infile, sp);
937 f_print(fout, "#endif\n");
938 if (logflag)
939 open_log_file(infile, sp);
940}
941
942static void
973open_log_file(infile, sp)
974 char *infile;
975 char *sp;
943open_log_file(const char *infile, const char *sp)
976{
977 char *s;
978
979 s = strrchr(infile, '.');
980 if (s)
981 *s = '\0';
982 f_print(fout, "%sopenlog(\"%s\", LOG_PID, LOG_DAEMON);\n", sp, infile);
983 if (s)
984 *s = '.';
985}
986
987
988
989
990/*
991 * write a registration for the given transport for Inetd
992 */
993void
944{
945 char *s;
946
947 s = strrchr(infile, '.');
948 if (s)
949 *s = '\0';
950 f_print(fout, "%sopenlog(\"%s\", LOG_PID, LOG_DAEMON);\n", sp, infile);
951 if (s)
952 *s = '.';
953}
954
955
956
957
958/*
959 * write a registration for the given transport for Inetd
960 */
961void
994write_inetd_register(transp)
995 char *transp;
962write_inetd_register(const char *transp)
996{
997 list *l;
998 definition *def;
999 version_list *vp;
963{
964 list *l;
965 definition *def;
966 version_list *vp;
1000 char *sp;
967 const char *sp;
1001 int isudp;
1002 char tmpbuf[32];
1003
1004 if (inetdflag)
1005 sp = "\t";
1006 else
1007 sp = "";
1008 if (streq(transp, "udp"))

--- 53 unchanged lines hidden ---
968 int isudp;
969 char tmpbuf[32];
970
971 if (inetdflag)
972 sp = "\t";
973 else
974 sp = "";
975 if (streq(transp, "udp"))

--- 53 unchanged lines hidden ---