static void write_program(definition *def) { version_list *vp; proc_list *proc; for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { for (proc = vp->procs; proc != NULL; proc = proc->next) { f_print(fout, "\n"); if (mtflag == 0) { ptype(proc->res_prefix, proc->res_type, 1); f_print(fout, "*\n"); pvname(proc->proc_name, vp->vers_num); printarglist(proc, RESULT, "clnt", "CLIENT *"); } else { f_print(fout, "enum clnt_stat \n"); pvname(proc->proc_name, vp->vers_num); printarglist(proc, RESULT, "clnt", "CLIENT *"); } f_print(fout, "{\n"); printbody(proc); f_print(fout, "}\n"); } } }
static void pfreeprocdef(const char * name, const char *vers) { f_print(fout, "extern int "); pvname(name, vers); f_print(fout, "_freeresult(SVCXPRT *, xdrproc_t, caddr_t);\n"); }
void pprocdef(proc_list *proc, version_list *vp, const char *addargtype, int server_p, int mode) { ptype( proc->res_prefix, proc->res_type, 1 ); f_print( fout, "* " ); if( server_p ) pvname_svc(proc->proc_name, vp->vers_num); else pvname(proc->proc_name, vp->vers_num); /* * mode 0 == cplusplus, mode 1 = ANSI-C, mode 2 = old style C */ if(mode == 0 || mode ==1) parglist(proc, addargtype); else f_print(fout, "();\n"); }
void pprocdef (proc_list * proc, version_list * vp, const char *addargtype, int server_p, int mode) { if (mtflag) {/* Print MT style stubs */ if (server_p) f_print (fout, "bool_t "); else f_print (fout, "enum clnt_stat "); } else { ptype (proc->res_prefix, proc->res_type, 1); f_print (fout, "* "); } if (server_p) pvname_svc (proc->proc_name, vp->vers_num); else pvname (proc->proc_name, vp->vers_num); /* * mode 1 = ANSI-C, mode 2 = K&R C */ if (mode == 1) parglist (proc, addargtype); else f_print (fout, "();\n"); }
void write_sample_clnt_main(void) { list *l; definition *def; version_list *vp; f_print(fout, "\n\n"); f_print(fout, "int\n"); f_print(fout, "main(int argc, char *argv[])\n{\n"); f_print(fout, "\tchar *host;"); f_print(fout, "\n\n\tif (argc < 2) {"); f_print(fout, "\n\t\tprintf(\"usage: %%s server_host\\n\", argv[0]);\n"); f_print(fout, "\t\texit(1);\n\t}"); f_print(fout, "\n\thost = argv[1];\n"); for (l = defined; l != NULL; l = l->next) { def = l->val; if (def->def_kind != DEF_PROGRAM) { continue; } for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { f_print(fout, "\t"); pvname(def->def_name, vp->vers_num); f_print(fout, "(host);\n"); } } f_print(fout, "}\n"); }
/* * write most of the service, that is, everything but the registrations. */ void write_most(void) { list *l; definition *def; version_list *vp; 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, "();"); } } } f_print(fout, "\n\n"); f_print(fout, "main()\n"); f_print(fout, "{\n"); f_print(fout, "\tSVCXPRT *%s;\n", TRANSP); f_print(fout, "\n"); for (l = defined; l != NULL; l = l->next) { def = (definition *) l->val; if (def->def_kind != DEF_PROGRAM) { continue; } for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { f_print(fout, "\tpmap_unset(%s, %s);\n", def->def_name, vp->vers_name); } } }
static void pdispatch(const char * name, const char *vers) { f_print(fout, "void "); pvname(name, vers); f_print(fout, "(struct svc_req *rqstp, SVCXPRT *transp);\n"); }
static void pfreeprocdef (const char *name, const char *vers, int mode) { f_print (fout, "extern int "); pvname (name, vers); if (mode == 1) f_print (fout,"_freeresult (SVCXPRT *, xdrproc_t, caddr_t);\n"); else f_print (fout,"_freeresult ();\n"); }
static void write_sample_server(definition *def) { version_list *vp; proc_list *proc; for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { for (proc = vp->procs; proc != NULL; proc = proc->next) { f_print(fout, "\n"); if (!mtflag) { return_type(proc); f_print(fout, "*\n"); } else f_print(fout, "bool_t\n"); pvname_svc(proc->proc_name, vp->vers_num); printarglist(proc, "result", RQSTP, "struct svc_req *"); f_print(fout, "{\n"); if (!mtflag) { f_print(fout, "\tstatic "); if(!streq(proc->res_type, "void")) return_type(proc); else f_print(fout, "char *"); /* cannot have void type */ f_print(fout, " result;\n"); } else f_print(fout, "\tbool_t retval;\n"); f_print(fout, "\n\t/*\n\t * insert server code here\n\t */\n\n"); if (!mtflag) if(!streq(proc->res_type, "void")) f_print(fout, "\treturn (&result);\n}\n"); else /* cast back to void * */ f_print(fout, "\treturn((void *) &result);\n}\n"); else f_print(fout, "\treturn (retval);\n}\n"); } /* put in sample freeing routine */ if (mtflag) { f_print(fout, "\nint\n"); pvname(def->def_name, vp->vers_num); f_print(fout,"_freeresult(SVCXPRT *transp, xdrproc_t xdr_result, caddr_t result)\n"); f_print(fout, "{\n"); f_print(fout, "\t(void) xdr_free(xdr_result, result);\n"); f_print(fout, "\n\t/*\n\t * Insert additional freeing code here, if needed\n\t */\n"); f_print(fout, "\n}\n"); } } }
void pprocdef(proc_list *proc, version_list *vp, const char *addargtype, int server_p) { decl_list *dl; if (Mflag) { if (server_p) f_print(fout, "bool_t "); else f_print(fout, "enum clnt_stat "); } else { ptype(proc->res_prefix, proc->res_type, 1); f_print(fout, "*"); } if (server_p) pvname_svc(proc->proc_name, vp->vers_num); else pvname(proc->proc_name, vp->vers_num); f_print(fout, "("); if (proc->arg_num < 2 && newstyle && streq(proc->args.decls->decl.type, "void")) { /* 0 argument in new style: do nothing */ } else { for (dl = proc->args.decls; dl != NULL; dl = dl->next) { ptype(dl->decl.prefix, dl->decl.type, 1); if (!newstyle) f_print(fout, "*"); f_print(fout, ", "); } } if (Mflag) { if (streq(proc->res_type, "void")) f_print(fout, "char"); else ptype(proc->res_prefix, proc->res_type, 0); if (!isvectordef(proc->res_type, REL_ALIAS)) f_print(fout, "*"); f_print(fout, ", "); } f_print(fout, "%s);\n", addargtype); }
static void write_sample_server(definition * def) { version_list *vp; proc_list *proc; for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { for (proc = vp->procs; proc != NULL; proc = proc->next) { f_print(fout, "\n"); /* if( Cflag ) f_print( fout, "extern \"C\"{\n"); */ return_type(proc); f_print(fout, "* \n"); if (Cflag) pvname_svc(proc->proc_name, vp->vers_num); else pvname(proc->proc_name, vp->vers_num); printarglist(proc, RQSTP, "struct svc_req *"); f_print(fout, "{\n"); f_print(fout, "\n\tstatic "); if (!streq(proc->res_type, "void")) return_type(proc); else f_print(fout, "char*"); /* cannot have void type */ /* f_print(fout, " result;\n", proc->res_type); */ f_print(fout, " result;\n"); f_print(fout, "\n\t/*\n\t * insert server code here\n\t */\n\n"); if (!streq(proc->res_type, "void")) f_print(fout, "\treturn(&result);\n}\n"); else /* cast back to void * */ f_print(fout, "\treturn((void*) &result);\n}\n"); /* if( Cflag) f_print( fout, "};\n"); */ } } }
void pprocdef(proc_list * proc, version_list * vp) { f_print(fout, "extern "); if (proc->res_prefix) { if (streq(proc->res_prefix, "enum")) { f_print(fout, "enum "); } else { f_print(fout, "struct "); } } if (streq(proc->res_type, "bool")) { f_print(fout, "bool_t *"); } else if (streq(proc->res_type, "string")) { f_print(fout, "char **"); } else { f_print(fout, "%s *", fixtype(proc->res_type)); } pvname(proc->proc_name, vp->vers_num); f_print(fout, "();\n"); }
/* * write a registration for the given transport */ void write_register(char *transp) { list *l; definition *def; version_list *vp; f_print(fout, "\n"); f_print(fout, "\t%s = svc%s_create(RPC_ANYSOCK", TRANSP, transp); if (streq(transp, "tcp")) { f_print(fout, ", 0, 0"); } f_print(fout, ");\n"); f_print(fout, "\tif (%s == NULL) {\n", TRANSP); f_print(fout, "\t\tfprintf(stderr, \"cannot create %s service.\\n\");\n", transp); f_print(fout, "\t\texit(1);\n"); f_print(fout, "\t}\n"); for (l = defined; l != NULL; l = l->next) { def = (definition *) l->val; if (def->def_kind != DEF_PROGRAM) { continue; } for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { f_print(fout, "\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"); f_print(fout, "\t\tfprintf(stderr, \"unable to register (%s, %s, %s).\\n\");\n", def->def_name, vp->vers_name, transp); f_print(fout, "\t\texit(1);\n"); f_print(fout, "\t}\n"); } } }
static void write_program(definition * def) { version_list *vp; proc_list *proc; for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { for (proc = vp->procs; proc != NULL; proc = proc->next) { f_print(fout, "\n"); ptype(proc->res_prefix, proc->res_type, 1); f_print(fout, "*\n"); pvname(proc->proc_name, vp->vers_num); f_print(fout, "(argp, clnt)\n"); f_print(fout, "\t"); ptype(proc->arg_prefix, proc->arg_type, 1); f_print(fout, "*argp;\n"); f_print(fout, "\tCLIENT *clnt;\n"); f_print(fout, "{\n"); printbody(proc); f_print(fout, "}\n\n"); } } }
static void write_sample_client(const char *program_name, version_list *vp) { proc_list *proc; int i; decl_list *l; f_print(fout, "\n\nvoid\n"); pvname(program_name, vp->vers_num); f_print(fout, "(char *host)\n{\n"); f_print(fout, "\tCLIENT *clnt;\n"); i = 0; for (proc = vp->procs; proc != NULL; proc = proc->next) { f_print(fout, "\t"); if (mtflag) { f_print(fout, "enum clnt_stat retval_%d;\n\t", ++i); ptype(proc->res_prefix, proc->res_type, 1); f_print(fout, "result_%d;\n", i); } else { ptype(proc->res_prefix, proc->res_type, 1); f_print(fout, " *result_%d;\n",++i); } /* print out declarations for arguments */ if(proc->arg_num < 2 && !newstyle) { f_print(fout, "\t"); if(!streq(proc->args.decls->decl.type, "void")) ptype(proc->args.decls->decl.prefix, proc->args.decls->decl.type, 1); else f_print(fout, "char * "); /* cannot have "void" type */ f_print(fout, " "); pvname(proc->proc_name, vp->vers_num); f_print(fout, "_arg;\n"); } else if (!streq(proc->args.decls->decl.type, "void")) { for (l = proc->args.decls; l != NULL; l = l->next) { f_print(fout, "\t"); ptype(l->decl.prefix, l->decl.type, 1); if (strcmp(l->decl.type,"string") == 1) f_print(fout, " "); pvname(proc->proc_name, vp->vers_num); f_print(fout, "_%s;\n", l->decl.name); } } } /* generate creation of client handle */ f_print(fout, "\n#ifndef\tDEBUG\n"); f_print(fout, "\tclnt = clnt_create(host, %s, %s, \"%s\");\n", program_name, vp->vers_name, tirpcflag? "netpath" : "udp"); f_print(fout, "\tif (clnt == (CLIENT *) NULL) {\n"); f_print(fout, "\t\tclnt_pcreateerror(host);\n"); f_print(fout, "\t\texit(1);\n\t}\n"); f_print(fout, "#endif\t/* DEBUG */\n\n"); /* generate calls to procedures */ i = 0; for (proc = vp->procs; proc != NULL; proc = proc->next) { if (mtflag) f_print(fout, "\tretval_%d = ",++i); else f_print(fout, "\tresult_%d = ",++i); pvname(proc->proc_name, vp->vers_num); if (proc->arg_num < 2 && !newstyle) { f_print(fout, "("); if(streq(proc->args.decls->decl.type, "void")) /* cast to void * */ f_print(fout, "(void *)"); f_print(fout, "&"); pvname(proc->proc_name, vp->vers_num); if (mtflag) f_print(fout, "_arg, &result_%d, clnt);\n", i); else f_print(fout, "_arg, clnt);\n"); } else if (streq(proc->args.decls->decl.type, "void")) { if (mtflag) f_print(fout, "(&result_%d, clnt);\n", i); else f_print(fout, "(clnt);\n"); } else { f_print(fout, "("); for (l = proc->args.decls; l != NULL; l = l->next) { pvname(proc->proc_name, vp->vers_num); f_print(fout, "_%s, ", l->decl.name); } if (mtflag) f_print(fout, "&result_%d, ", i); f_print(fout, "clnt);\n"); } if (mtflag) { f_print(fout, "\tif (retval_%d != RPC_SUCCESS) {\n", i); } else { f_print(fout, "\tif (result_%d == (", i); ptype(proc->res_prefix, proc->res_type, 1); f_print(fout, "*) NULL) {\n"); } f_print(fout, "\t\tclnt_perror(clnt, \"call failed\");\n"); f_print(fout, "\t}\n"); } f_print(fout, "#ifndef\tDEBUG\n"); f_print(fout, "\tclnt_destroy(clnt);\n"); f_print(fout, "#endif\t /* DEBUG */\n"); f_print(fout, "}\n"); }
static void write_sample_client(char *program_name, version_list *vp) { proc_list *proc; int i; decl_list *l; f_print(fout, "\n\nvoid\n"); pvname(program_name, vp->vers_num); if (Cflag) f_print(fout, "( char* host )\n{\n"); else f_print(fout, "(host)\nchar *host;\n{\n"); f_print(fout, "\tCLIENT *clnt;\n"); i = 0; for (proc = vp->procs; proc != NULL; proc = proc->next) { f_print(fout, "\t"); ptype(proc->res_prefix, proc->res_type, 1); f_print(fout, " *result_%d;\n", ++i); /* print out declarations for arguments */ if (proc->arg_num < 2 && !newstyle) { f_print(fout, "\t"); if (!streq(proc->args.decls->decl.type, "void")) ptype(proc->args.decls->decl.prefix, proc->args.decls->decl.type, 1); else f_print(fout, "char* "); /* cannot have "void" type */ f_print(fout, " "); pvname(proc->proc_name, vp->vers_num); f_print(fout, "_arg;\n"); } else if (!streq(proc->args.decls->decl.type, "void")) { for (l = proc->args.decls; l != NULL; l = l->next) { f_print(fout, "\t"); ptype(l->decl.prefix, l->decl.type, 1); f_print(fout, " "); pvname(proc->proc_name, vp->vers_num); f_print(fout, "_%s;\n", l->decl.name); /* pdeclaration(proc->args.argname, &l->decl, 1, ";\n" );*/ } } } /* generate creation of client handle */ f_print(fout, "\tclnt = clnt_create(host, %s, %s, \"%s\");\n", program_name, vp->vers_name, tirpcflag ? "netpath" : "udp"); f_print(fout, "\tif (clnt == NULL) {\n"); f_print(fout, "\t\tclnt_pcreateerror(host);\n"); f_print(fout, "\t\texit(1);\n\t}\n"); /* generate calls to procedures */ i = 0; for (proc = vp->procs; proc != NULL; proc = proc->next) { f_print(fout, "\tresult_%d = ", ++i); pvname(proc->proc_name, vp->vers_num); if (proc->arg_num < 2 && !newstyle) { f_print(fout, "("); if (streq(proc->args.decls->decl.type, "void")) /* cast to void* */ f_print(fout, "(void*)"); f_print(fout, "&"); pvname(proc->proc_name, vp->vers_num); f_print(fout, "_arg, clnt);\n"); } else if (streq(proc->args.decls->decl.type, "void")) { f_print(fout, "(clnt);\n"); } else { f_print(fout, "("); for (l = proc->args.decls; l != NULL; l = l->next) { pvname(proc->proc_name, vp->vers_num); f_print(fout, "_%s, ", l->decl.name); } f_print(fout, "clnt);\n"); } f_print(fout, "\tif (result_%d == NULL) {\n", i); f_print(fout, "\t\tclnt_perror(clnt, \"call failed:\");\n"); f_print(fout, "\t}\n"); } f_print(fout, "\tclnt_destroy( clnt );\n"); f_print(fout, "}\n"); }
static void write_table (definition * def) { version_list *vp; proc_list *proc; int current; int expected; char progvers[100]; int warning; for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { warning = 0; s_print (progvers, "%s_%s", locase (def->def_name), vp->vers_num); /* print the table header */ f_print (fout, tbl_hdr, progvers); if (nullproc (vp->procs)) { expected = 0; } else { expected = 1; f_print (fout, "%s", null_entry); } for (proc = vp->procs; proc != NULL; proc = proc->next) { current = atoi (proc->proc_num); if (current != expected++) { f_print (fout, "\n/*\n * WARNING: table out of order\n */\n"); if (warning == 0) { f_print (stderr, "WARNING %s table is out of order\n", progvers); warning = 1; nonfatalerrors = 1; } expected = current + 1; } f_print (fout, " {\n\t(char *(*)())RPCGEN_ACTION("); /* routine to invoke */ if (!newstyle) pvname_svc (proc->proc_name, vp->vers_num); else { if (newstyle) f_print (fout, "_"); /* calls internal func */ pvname (proc->proc_name, vp->vers_num); } f_print (fout, "),\n"); /* argument info */ if (proc->arg_num > 1) printit ((char *) NULL, proc->args.argname); else /* do we have to do something special for newstyle */ printit (proc->args.decls->decl.prefix, proc->args.decls->decl.type); /* result info */ printit (proc->res_prefix, proc->res_type); f_print (fout, " },\n"); } /* print the table trailer */ f_print (fout, "%s", tbl_end); f_print (fout, tbl_nproc, progvers, progvers, progvers); f_print (fout, "const struct rpc_program_tc %s = {\n" "\t%s, %s, %s_table,\n" "\tsizeof (%s_table) / sizeof (%s_table[0])\n" "};\n\n", progvers, def->def_name, vp->vers_num, progvers, progvers, progvers); } }
static void write_program(definition * def, char *storage) { version_list *vp; proc_list *proc; int filled; for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { f_print(fout, "\n"); if (storage != NULL) { f_print(fout, "%s ", storage); } f_print(fout, "void\n"); 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, "{\n"); filled = 0; f_print(fout, "\tunion {\n"); for (proc = vp->procs; proc != NULL; proc = proc->next) { if (streq(proc->arg_type, "void")) { continue; } filled = 1; f_print(fout, "\t\t"); ptype(proc->arg_prefix, proc->arg_type, 0); pvname(proc->proc_name, vp->vers_num); f_print(fout, "_arg;\n"); } if (!filled) { 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, "\n"); f_print(fout, "\tswitch (%s->rq_proc) {\n", RQSTP); if (!nullproc(vp->procs)) { f_print(fout, "\tcase NULLPROC:\n"); f_print(fout, "\t\tsvc_sendreply(%s, xdr_void, 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, ";\n"); f_print(fout, "\t\tbreak;\n\n"); } f_print(fout, "\tdefault:\n"); printerr("noproc", TRANSP); f_print(fout, "\t\treturn;\n"); f_print(fout, "\t}\n"); f_print(fout, "\tmemset(&%s, 0, sizeof(%s));\n", ARG, ARG); printif("getargs", TRANSP, "&", ARG); printerr("decode", TRANSP); f_print(fout, "\t\treturn;\n"); f_print(fout, "\t}\n"); f_print(fout, "\t%s = (*%s)(&%s, %s);\n", RESULT, ROUTINE, ARG, RQSTP); f_print(fout, "\tif (%s != NULL && !svc_sendreply(%s, xdr_%s, %s)) {\n", RESULT, TRANSP, RESULT, RESULT); printerr("systemerr", TRANSP); f_print(fout, "\t}\n"); printif("freeargs", TRANSP, "&", ARG); f_print(fout, "\t\tfprintf(stderr, \"unable to free arguments\\n\");\n"); f_print(fout, "\t\texit(1);\n"); f_print(fout, "\t}\n"); f_print(fout, "}\n\n"); } }