#include <afsconfig.h>
#include <afs/param.h>
+#include <roken.h>
-#include <stdlib.h>
-#include <stdio.h>
#include <ctype.h>
-#include <string.h>
+
#include "rpc_scan.h"
#include "rpc_parse.h"
#include "rpc_util.h"
list *proc_defined[MAX_PACKAGES], *special_defined, *typedef_defined,
- *uniondef_defined;
+ *uniondef_defined, *complex_defined;
char *SplitStart = NULL;
char *SplitEnd = NULL;
char *MasterPrefix = NULL;
static void ucs_ProcTail_setup(definition * defp, int split_flag);
static void ss_Proc_CodeGeneration(definition * defp);
static void ss_ProcName_setup(definition * defp);
-static void ss_ProcParams_setup(definition * defp, int *somefrees);
-static void ss_ProcSpecial_setup(definition * defp, int *somefrees);
+static void ss_ProcParams_setup(definition * defp);
+static void ss_ProcSpecial_setup(definition * defp);
static void ss_ProcUnmarshallInParams_setup(definition * defp);
static void ss_ProcCallRealProc_setup(definition * defp);
static void ss_ProcMarshallOutParams_setup(definition * defp);
-static void ss_ProcTail_setup(definition * defp, int somefrees);
+static void ss_ProcTail_setup(definition * defp);
static int opcode_holes_exist(void);
static void er_ProcDeclExterns_setup(void);
static void er_ProcProcsArray_setup(void);
break;
case TOK_EOF:
return (NULL);
- break;
case TOK_PACKAGE:
def_package(defp);
break;
declaration dec;
decl_list *decls;
decl_list **tailp;
+ int special = 0;
defp->def_kind = DEF_STRUCT;
tailp = &defp->def.st.decls;
do {
get_declaration(&dec, DEF_STRUCT);
+ /* If a structure contains an array, then we're going
+ * to need to be clever about freeing it */
+ if (dec.rel == REL_ARRAY) {
+ special = 1;
+ }
decls = ALLOC(decl_list);
decls->decl = dec;
*tailp = decls;
} while (tok.kind != TOK_RBRACE);
get_token(&tok);
*tailp = NULL;
+
+ if (special)
+ STOREVAL(&complex_defined, defp);
}
static void
if (Sflag || cflag)
ss_Proc_CodeGeneration(defp);
}
- if (Sflag)
+ if (Sflag || (cflag && xflag && !proc_split_flag))
STOREVAL(&proc_defined[PackageIndex], defp);
}
if (!cflag) {
for (plist = defp->pc.plists; plist; plist = plist->next) {
if (plist->component_kind == DEF_PARAM) {
+ f_print(fout, ",");
if (ansic_flag) {
+ if (plist->pl.param_kind == DEF_INPARAM &&
+ strcmp(plist->pl.param_type, "char *") == 0) {
+ f_print(fout, "const ");
+ }
if (plist->pl.param_flag & OUT_STRING) {
- f_print(fout, ",%s *%s", plist->pl.param_type,
+ f_print(fout, "%s *%s", plist->pl.param_type,
plist->pl.param_name);
} else {
- f_print(fout, ",%s %s", plist->pl.param_type,
+ f_print(fout, "%s %s", plist->pl.param_type,
plist->pl.param_name);
}
} else {
- f_print(fout, ", %s", plist->pl.param_name);
+ f_print(fout, " %s", plist->pl.param_name);
plist->pl.param_flag &= ~PROCESSED_PARAM;
}
}
if (!(split_flag > 1) || (noofallparams != 0)) {
f_print(fout, "\tXDR z_xdrs;\n");
}
- /*
- * Print out client side stat gathering call
- */
- if (xflag && split_flag != 1) {
- f_print(fout, "\tstruct clock __QUEUE, __EXEC;\n");
- }
if ((!split_flag) || (split_flag == 1)) {
f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_ENCODE);\n");
}
if (xflag && split_flag != 1) {
f_print(fout, "\tif (rx_enable_stats) {\n");
- f_print(fout, "\t clock_GetTime(&__EXEC);\n");
- f_print(fout, "\t clock_Sub(&__EXEC, &z_call->startTime);\n");
- f_print(fout, "\t __QUEUE = z_call->startTime;\n");
- f_print(fout, "\t clock_Sub(&__QUEUE, &z_call->queueTime);\n");
if (PackageStatIndex[PackageIndex]) {
- if (!split_flag) {
- f_print(fout,
- "\t rx_IncrementTimeAndCount(z_conn->peer, %s,\n",
- PackageStatIndex[PackageIndex]);
- } else {
- f_print(fout,
- "\t rx_IncrementTimeAndCount(z_call->conn->peer, %s,\n",
- PackageStatIndex[PackageIndex]);
- }
+ f_print(fout,
+ "\t rx_RecordCallStatistics(z_call, %s,\n",
+ PackageStatIndex[PackageIndex]);
} else {
- if (!split_flag) {
- f_print(fout,
- "\t rx_IncrementTimeAndCount(z_conn->peer,\n"
- "\t\t(((afs_uint32)(ntohs(z_conn->serviceId) << 16)) \n"
- "\t\t| ((afs_uint32)ntohs(z_conn->peer->port))),\n");
- } else {
- f_print(fout,
- "\t rx_IncrementTimeAndCount(z_call->conn->peer,\n"
- "\t\t(((afs_uint32)(ntohs(z_call->conn->serviceId) << 16)) |\n"
- "\t\t((afs_uint32)ntohs(z_call->conn->peer->port))),\n");
- }
- }
- if (xflag) {
- f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, &__QUEUE, &__EXEC,\n",
- no_of_stat_funcs, PackagePrefix[PackageIndex]);
f_print(fout,
- "\t\t&z_call->bytesSent, &z_call->bytesRcvd, 1);\n");
+ "\t rx_RecordCallStatistics(z_call, \n"
+ "\t\t(((afs_uint32)(ntohs(rx_ServiceIdOf(rx_ConnectionOf(z_call))) << 16)) |\n"
+ "\t\t((afs_uint32)ntohs(rx_PortOf(rx_PeerOf(rx_ConnectionOf(z_call)))))),\n");
}
+ f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, 1);\n",
+ no_of_stat_funcs, PackagePrefix[PackageIndex]);
f_print(fout, "\t}\n\n");
}
f_print(fout, "\treturn z_result;\n}\n\n");
static void
ss_Proc_CodeGeneration(definition * defp)
{
- int somefrees = 0;
-
defp->can_fail = 0;
ss_ProcName_setup(defp);
if (!cflag) {
- ss_ProcParams_setup(defp, &somefrees);
- ss_ProcSpecial_setup(defp, &somefrees);
+ ss_ProcParams_setup(defp);
+ ss_ProcSpecial_setup(defp);
ss_ProcUnmarshallInParams_setup(defp);
ss_ProcCallRealProc_setup(defp);
ss_ProcMarshallOutParams_setup(defp);
- ss_ProcTail_setup(defp, somefrees);
+ ss_ProcTail_setup(defp);
}
}
PackagePrefix[PackageIndex], defp->pc.proc_name);
f_print(fout, "struct rx_call *z_call, XDR *z_xdrs)\n{\n");
f_print(fout, "\t" "afs_int32 z_result;\n");
- if (xflag) {
- f_print(fout, "\tstruct clock __QUEUE, __EXEC;\n");
- }
for (plist = defp->pc.plists; plist; plist = plist->next)
if (plist->component_kind == DEF_PARAM) {
static void
-ss_ProcParams_setup(definition * defp, int *somefrees)
+ss_ProcParams_setup(definition * defp)
{
proc1_list *plist, *plist1;
list *listp;
plist->pl.param_name);
} else {
plist->pl.param_flag |= FREETHIS_PARAM;
- *somefrees = 1;
f_print(fout, "\t%s %s=(%s)0", plist->pl.param_type,
plist->pl.param_name, plist->pl.param_type);
}
f_print(fout, ", %s", plist1->pl.param_name);
} else {
plist1->pl.param_flag |= FREETHIS_PARAM;
- *somefrees = 1;
f_print(fout, ", *%s=(%s)0", plist1->pl.param_name,
plist1->pl.param_type);
}
static void
-ss_ProcSpecial_setup(definition * defp, int *somefrees)
+ss_ProcSpecial_setup(definition * defp)
{
proc1_list *plist;
definition *defp1;
for (listp = special_defined; listp != NULL; listp = listp->next) {
defp1 = (definition *) listp->val;
+
for (plist = defp->pc.plists; plist; plist = plist->next) {
if (plist->component_kind == DEF_PARAM
&& (plist->pl.param_kind == DEF_INPARAM
if (streq(string, structname(plist->pl.param_type))) {
plist->pl.string_name = spec->sdef.string_name;
plist->pl.param_flag |= FREETHIS_PARAM;
- *somefrees = 1;
fprintf(fout, "\n\t%s.%s = 0;", plist->pl.param_name,
spec->sdef.string_name);
}
}
}
}
- if (!*somefrees)
- fprintf(fout, "\n");
for (listp = typedef_defined; listp != NULL; listp = listp->next) {
defp1 = (definition *) listp->val;
for (plist = defp->pc.plists; plist; plist = plist->next) {
if (plist->component_kind == DEF_PARAM) {
if (streq(defp1->def_name, structname(plist->pl.param_type))) {
plist->pl.param_flag |= FREETHIS_PARAM;
- *somefrees = 1;
switch (defp1->pc.rel) {
case REL_ARRAY:
- f_print(fout, "\n\t%s.%s_val = 0;",
- plist->pl.param_name, defp1->def_name);
- f_print(fout, "\n\t%s.%s_len = 0;",
- plist->pl.param_name, defp1->def_name);
plist->pl.string_name = alloc(40);
- s_print(plist->pl.string_name, "%s_val",
- defp1->def_name);
+ if (brief_flag) {
+ f_print(fout, "\n\t%s.val = 0;",
+ plist->pl.param_name);
+ f_print(fout, "\n\t%s.len = 0;",
+ plist->pl.param_name);
+ s_print(plist->pl.string_name, "val");
+ } else {
+ f_print(fout, "\n\t%s.%s_val = 0;",
+ plist->pl.param_name, defp1->def_name);
+ f_print(fout, "\n\t%s.%s_len = 0;",
+ plist->pl.param_name, defp1->def_name);
+ s_print(plist->pl.string_name, "%s_val",
+ defp1->def_name);
+ }
break;
case REL_POINTER:
f_print(fout, "\n\t%s = 0;", plist->pl.param_name);
}
}
}
+ for (listp = complex_defined; listp != NULL; listp = listp->next) {
+ defp1 = (definition *) listp->val;
+ for (plist = defp->pc.plists; plist; plist = plist->next) {
+ if (plist->component_kind == DEF_PARAM) {
+ if (streq(defp1->def_name, structname(plist->pl.param_type))) {
+ plist->pl.param_flag |= FREETHIS_PARAM;
+ fprintf(fout, "\n\tmemset(&%s, 0, sizeof(%s));",
+ plist->pl.param_name, defp1->def_name);
+ }
+ }
+ }
+ }
+
f_print(fout, "\n");
}
}
}
+static void
+ss_ProcTail_frees(char *xdrfunc, int *somefrees) {
+ if (!*somefrees) {
+ f_print(fout, "\tz_xdrs->x_op = XDR_FREE;\n");
+ f_print(fout, "\tif ((!%s)", xdrfunc);
+ *somefrees = 1;
+ } else {
+ f_print(fout, "\n\t || (!%s)", xdrfunc);
+ }
+}
+
static void
-ss_ProcTail_setup(definition * defp, int somefrees)
+ss_ProcTail_setup(definition * defp)
{
proc1_list *plist;
definition *defp1;
list *listp;
- int firsttime = 0;
+ int somefrees = 0;
if (defp->can_fail) {
f_print(fout, "fail:\n");
}
+
for (plist = defp->pc.plists; plist; plist = plist->next) {
if (plist->component_kind == DEF_PARAM
- && (plist->pl.param_flag & FREETHIS_PARAM))
- somefrees = 1;
- }
- if (somefrees)
- f_print(fout, "\tz_xdrs->x_op = XDR_FREE;\n");
- for (plist = defp->pc.plists; plist; plist = plist->next) {
- if (plist->component_kind == DEF_PARAM
- && (plist->pl.param_flag & FREETHIS_PARAM)) {
- char *dot = "", *extens = "";
- if (plist->pl.string_name) {
- dot = ".";
- extens = plist->pl.string_name;
- }
- f_print(fout, "\tif (!%s) goto fail1;\n", plist->scode);
- }
+ && (plist->pl.param_flag & FREETHIS_PARAM))
+ ss_ProcTail_frees(plist->scode, &somefrees);
}
+
for (listp = typedef_defined; listp != NULL; listp = listp->next) {
defp1 = (definition *) listp->val;
for (plist = defp->pc.plists; plist; plist = plist->next) {
switch (defp1->pc.rel) {
case REL_ARRAY:
case REL_POINTER:
- if (!somefrees && !firsttime) {
- firsttime = 1;
- f_print(fout, "\tz_xdrs->x_op = XDR_FREE;\n");
- }
- somefrees = 1;
- f_print(fout, "\tif (!%s) goto fail1;\n",
- plist->scode);
+ ss_ProcTail_frees(plist->scode, &somefrees);
break;
default:
break;
}
}
}
+
for (listp = uniondef_defined; listp != NULL; listp = listp->next) {
defp1 = (definition *) listp->val;
for (plist = defp->pc.plists; plist; plist = plist->next) {
&& !(plist->pl.param_flag & FREETHIS_PARAM)) {
if (streq(defp1->def_name, structname(plist->pl.param_type))) {
if (plist->pl.param_flag & INDIRECT_PARAM) {
- if (!somefrees && !firsttime) {
- firsttime = 1;
- f_print(fout, "\tz_xdrs->x_op = XDR_FREE;\n");
- }
- somefrees = 1;
- f_print(fout, "\tif (!%s) goto fail1;\n",
- plist->scode);
+ ss_ProcTail_frees(plist->scode, &somefrees);
}
}
}
}
}
+ if (somefrees) {
+ f_print(fout, ")\n");
+ f_print(fout, "\t\tz_result = RXGEN_SS_XDRFREE;\n\n");
+ }
+
if (xflag) {
f_print(fout, "\tif (rx_enable_stats) {\n");
- f_print(fout, "\t clock_GetTime(&__EXEC);\n");
- f_print(fout, "\t clock_Sub(&__EXEC, &z_call->startTime);\n");
- f_print(fout, "\t __QUEUE = z_call->startTime;\n");
- f_print(fout, "\t clock_Sub(&__QUEUE, &z_call->queueTime);\n");
- f_print(fout, "\t rx_IncrementTimeAndCount(z_call->conn->peer,");
+ f_print(fout, "\t rx_RecordCallStatistics(z_call,");
if (PackageStatIndex[PackageIndex]) {
f_print(fout, " %s,\n", PackageStatIndex[PackageIndex]);
} else {
f_print(fout,
- "\n\t\t(((afs_uint32)(ntohs(z_call->conn->serviceId) << 16)) |\n"
- "\t\t((afs_uint32)ntohs(z_call->conn->service->servicePort))),\n");
+ "\n\t\t(((afs_uint32)(ntohs(rx_ServiceIdOf(rx_ConnectionOf(z_call))) << 16)) |\n"
+ "\t\t((afs_uint32)ntohs(rx_ServiceOf(rx_ConnectionOf(z_call))->servicePort))),\n");
}
- f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, &__QUEUE, &__EXEC,\n",
+ f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, 0);\n",
no_of_stat_funcs, PackagePrefix[PackageIndex]);
- f_print(fout, "\t\t&z_call->bytesSent, &z_call->bytesRcvd, 0);\n");
f_print(fout, "\t}\n\n");
}
f_print(fout, "\treturn z_result;\n");
- if (somefrees) {
- f_print(fout, "fail1:\n");
-
- if (xflag) {
- f_print(fout, "\tif (rx_enable_stats) {\n");
- f_print(fout, "\t clock_GetTime(&__EXEC);\n");
- f_print(fout, "\t clock_Sub(&__EXEC, &z_call->startTime);\n");
- f_print(fout, "\t __QUEUE = z_call->startTime;\n");
- f_print(fout, "\t clock_Sub(&__QUEUE, &z_call->queueTime);\n");
- f_print(fout,
- "\t rx_IncrementTimeAndCount(z_call->conn->peer,");
- if (PackageStatIndex[PackageIndex]) {
- f_print(fout, " %s,\n", PackageStatIndex[PackageIndex]);
- } else {
- f_print(fout,
- "\n\t\t(((afs_uint32)(ntohs(z_call->conn->serviceId) << 16)) |\n"
- "\t\t((afs_uint32)ntohs(z_call->conn->service->servicePort))),\n");
- }
- f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, &__QUEUE, &__EXEC,\n",
- no_of_stat_funcs, PackagePrefix[PackageIndex]);
- f_print(fout,
- "\t\t&z_call->bytesSent, &z_call->bytesRcvd, 0);\n");
- f_print(fout, "\t}\n\n");
- }
-
- f_print(fout, "\treturn RXGEN_SS_XDRFREE;\n}\n\n");
- } else {
- f_print(fout, "}\n\n");
- }
+ f_print(fout, "}\n\n");
}
if (!cflag) {
for (plist = defp->pc.plists; plist; plist = plist->next) {
if (plist->component_kind == DEF_PARAM) {
+ f_print(fout, ",");
if (ansic_flag) {
+ if (plist->pl.param_kind == DEF_INPARAM &&
+ strcmp(plist->pl.param_type, "char *") == 0) {
+ f_print(fout, "const ");
+ }
if (plist->pl.param_flag & OUT_STRING) {
- f_print(fout, ",%s *%s", plist->pl.param_type,
+ f_print(fout, "%s *%s", plist->pl.param_type,
plist->pl.param_name);
} else {
- f_print(fout, ",%s %s", plist->pl.param_type,
+ f_print(fout, "%s %s", plist->pl.param_type,
plist->pl.param_name);
}
} else {
plist->pl.param_flag &= ~PROCESSED_PARAM;
- f_print(fout, ", %s", plist->pl.param_name);
+ f_print(fout, " %s", plist->pl.param_name);
}
}
}
list *listp;
definition *defp;
+ if ( !Sflag )
+ return;
+
f_print(fout, "\n");
for (listp = proc_defined[PackageIndex]; listp != NULL;
listp = listp->next) {
if ((listp = proc_defined[PackageIndex])) {
defp = (definition *) listp->val;
- if (defp->pc.proc_serverstub) {
- f_print(fout, "\nstatic afs_int32 (*StubProcsArray%d[])() = {%s",
- PackageIndex, defp->pc.proc_serverstub);
- } else {
- f_print(fout,
- "\nstatic afs_int32 (*StubProcsArray%d[])(struct rx_call *z_call, XDR *z_xdrs) = {_%s%s%s",
- PackageIndex, prefix, defp->pc.proc_prefix,
- ((definition *) listp->val)->pc.proc_name);
- defp = (definition *) listp->val;
+ if ( cflag ) {
+ f_print(fout, "\nstatic char *opnames%d[] = {\"%s%s\"",
+ PackageIndex, defp->pc.proc_prefix, defp->pc.proc_name);
+ }
+ else {
+ if (defp->pc.proc_serverstub) {
+ f_print(fout, "\nstatic afs_int32 (*StubProcsArray%d[])() = {%s",
+ PackageIndex, defp->pc.proc_serverstub);
+ } else {
+ f_print(fout,
+ "\nstatic afs_int32 (*StubProcsArray%d[])(struct rx_call *z_call, XDR *z_xdrs) = {_%s%s%s",
+ PackageIndex, prefix, defp->pc.proc_prefix,
+ ((definition *) listp->val)->pc.proc_name);
+ defp = (definition *) listp->val;
+ }
}
listp = listp->next;
}
for (; listp != NULL; listp = listp->next) {
defp = (definition *) listp->val;
- if (defp->pc.proc_serverstub) {
- f_print(fout, ",%s", defp->pc.proc_serverstub);
- } else {
- f_print(fout, ", _%s%s%s", prefix, defp->pc.proc_prefix,
- defp->pc.proc_name);
+ if ( cflag ) {
+ f_print(fout, ", \"%s%s\"",defp->pc.proc_prefix,defp->pc.proc_name);
+ }
+ else {
+ if (defp->pc.proc_serverstub) {
+ f_print(fout, ",%s", defp->pc.proc_serverstub);
+ } else {
+ f_print(fout, ", _%s%s%s", prefix, defp->pc.proc_prefix,
+ defp->pc.proc_name);
+ }
}
}
f_print(fout, "};\n\n");
static void
er_ProcMainBody_setup(void)
{
+ if ( cflag ) {
+ f_print(fout, "char *%sTranslateOpCode(int op)\n{\n",
+ PackagePrefix[PackageIndex]);
+ f_print(fout, "\tif (op < %sLOWEST_OPCODE || op > %sHIGHEST_OPCODE)\n\t\treturn NULL;\n",
+ PackagePrefix[PackageIndex], PackagePrefix[PackageIndex]);
+ f_print(fout, "\treturn opnames%d[op - %sLOWEST_OPCODE];\n}\n",
+ PackageIndex, PackagePrefix[PackageIndex]);
+ return;
+ }
f_print(fout, "int %s%sExecuteRequest(struct rx_call *z_call)\n",
prefix, PackagePrefix[PackageIndex]);
f_print(fout, "{\n\tint op;\n");
static void
er_HeadofOldStyleProc_setup(void)
{
- f_print(fout,
- "\nint %s%sExecuteRequest (struct rx_call *z_call)\n",
- prefix,
+ if ( cflag ) {
+ f_print(fout, "char *%sTranslateOpCode(int op)\n{\n",
(combinepackages ? MasterPrefix : PackagePrefix[PackageIndex]));
- f_print(fout, "{\n");
- f_print(fout, "\tint op;\n");
- f_print(fout, "\tXDR z_xdrs;\n");
- f_print(fout, "\t" "afs_int32 z_result;\n\n");
- f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
- f_print(fout, "\tz_result = RXGEN_DECODE;\n");
- f_print(fout, "\tif (!xdr_int(&z_xdrs, &op)) goto fail;\n");
+ }
+ else {
+ f_print(fout,
+ "\nint %s%sExecuteRequest (struct rx_call *z_call)\n",
+ prefix,
+ (combinepackages ? MasterPrefix : PackagePrefix[PackageIndex]));
+ f_print(fout, "{\n");
+ f_print(fout, "\tint op;\n");
+ f_print(fout, "\tXDR z_xdrs;\n");
+ f_print(fout, "\t" "afs_int32 z_result;\n\n");
+ f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
+ f_print(fout, "\tz_result = RXGEN_DECODE;\n");
+ f_print(fout, "\tif (!xdr_int(&z_xdrs, &op)) goto fail;\n");
+ }
f_print(fout, "\tswitch (op) {\n");
}
static void
proc_er_case(definition * defp)
{
+ if ( cflag ) {
+ f_print(fout, "\t\tcase %d:", defp->pc.proc_opcodenum);
+ f_print(fout, "\treturn \"%s%s\";\n",
+ defp->pc.proc_prefix, defp->pc.proc_name);
+ return;
+ }
if (opcodesnotallowed[PackageIndex]) {
f_print(fout, "\t\tcase %d:\n", defp->pc.proc_opcodenum);
} else {
er_TailofOldStyleProc_setup(void)
{
f_print(fout, "\t\tdefault:\n");
+ if ( cflag ) {
+ f_print(fout, "\t\t\treturn NULL;\n\t}\n}\n");
+ return;
+ }
f_print(fout, "\t\t\tz_result = RXGEN_OPCODE;\n");
f_print(fout, "\t\t\tbreak;\n\t}\n");
f_print(fout, "fail:\n");