1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate * 22*7c478bd9Sstevel@tonic-gate * Copyright 2001 Sun Microsystems, Inc. All rights reserved. 23*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 24*7c478bd9Sstevel@tonic-gate */ 25*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 26*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 27*7c478bd9Sstevel@tonic-gate /* 28*7c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 29*7c478bd9Sstevel@tonic-gate * The Regents of the University of California 30*7c478bd9Sstevel@tonic-gate * All Rights Reserved 31*7c478bd9Sstevel@tonic-gate * 32*7c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 33*7c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 34*7c478bd9Sstevel@tonic-gate * contributors. 35*7c478bd9Sstevel@tonic-gate */ 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate /* 40*7c478bd9Sstevel@tonic-gate * rpc_clntout.c, Client-stub outputter for the RPC protocol compiler 41*7c478bd9Sstevel@tonic-gate */ 42*7c478bd9Sstevel@tonic-gate #include <stdio.h> 43*7c478bd9Sstevel@tonic-gate #include <string.h> 44*7c478bd9Sstevel@tonic-gate #include <rpc/types.h> 45*7c478bd9Sstevel@tonic-gate #include "rpc_parse.h" 46*7c478bd9Sstevel@tonic-gate #include "rpc_util.h" 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate extern pdeclaration(); 49*7c478bd9Sstevel@tonic-gate void printarglist(); 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate static char RESULT[] = "clnt_res"; 53*7c478bd9Sstevel@tonic-gate 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate #define DEFAULT_TIMEOUT 25 /* in seconds */ 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate void 59*7c478bd9Sstevel@tonic-gate write_stubs() 60*7c478bd9Sstevel@tonic-gate { 61*7c478bd9Sstevel@tonic-gate list *l; 62*7c478bd9Sstevel@tonic-gate definition *def; 63*7c478bd9Sstevel@tonic-gate 64*7c478bd9Sstevel@tonic-gate f_print(fout, 65*7c478bd9Sstevel@tonic-gate "\n/* Default timeout can be changed using clnt_control() */\n"); 66*7c478bd9Sstevel@tonic-gate f_print(fout, "static struct timeval TIMEOUT = { %d, 0 };\n", 67*7c478bd9Sstevel@tonic-gate DEFAULT_TIMEOUT); 68*7c478bd9Sstevel@tonic-gate for (l = defined; l != NULL; l = l->next) { 69*7c478bd9Sstevel@tonic-gate def = (definition *) l->val; 70*7c478bd9Sstevel@tonic-gate if (def->def_kind == DEF_PROGRAM) { 71*7c478bd9Sstevel@tonic-gate write_program(def); 72*7c478bd9Sstevel@tonic-gate } 73*7c478bd9Sstevel@tonic-gate } 74*7c478bd9Sstevel@tonic-gate } 75*7c478bd9Sstevel@tonic-gate 76*7c478bd9Sstevel@tonic-gate static 77*7c478bd9Sstevel@tonic-gate write_program(def) 78*7c478bd9Sstevel@tonic-gate definition *def; 79*7c478bd9Sstevel@tonic-gate { 80*7c478bd9Sstevel@tonic-gate version_list *vp; 81*7c478bd9Sstevel@tonic-gate proc_list *proc; 82*7c478bd9Sstevel@tonic-gate 83*7c478bd9Sstevel@tonic-gate for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { 84*7c478bd9Sstevel@tonic-gate for (proc = vp->procs; proc != NULL; proc = proc->next) { 85*7c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 86*7c478bd9Sstevel@tonic-gate if (mtflag == 0) { 87*7c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, proc->res_type, 1); 88*7c478bd9Sstevel@tonic-gate f_print(fout, "*\n"); 89*7c478bd9Sstevel@tonic-gate pvname(proc->proc_name, vp->vers_num); 90*7c478bd9Sstevel@tonic-gate printarglist(proc, RESULT, "clnt", "CLIENT *"); 91*7c478bd9Sstevel@tonic-gate } else { 92*7c478bd9Sstevel@tonic-gate f_print(fout, "enum clnt_stat \n"); 93*7c478bd9Sstevel@tonic-gate pvname(proc->proc_name, vp->vers_num); 94*7c478bd9Sstevel@tonic-gate printarglist(proc, RESULT, "clnt", "CLIENT *"); 95*7c478bd9Sstevel@tonic-gate 96*7c478bd9Sstevel@tonic-gate } 97*7c478bd9Sstevel@tonic-gate f_print(fout, "{\n"); 98*7c478bd9Sstevel@tonic-gate printbody(proc); 99*7c478bd9Sstevel@tonic-gate 100*7c478bd9Sstevel@tonic-gate f_print(fout, "}\n"); 101*7c478bd9Sstevel@tonic-gate } 102*7c478bd9Sstevel@tonic-gate } 103*7c478bd9Sstevel@tonic-gate } 104*7c478bd9Sstevel@tonic-gate 105*7c478bd9Sstevel@tonic-gate /* 106*7c478bd9Sstevel@tonic-gate * Writes out declarations of procedure's argument list. 107*7c478bd9Sstevel@tonic-gate * In either ANSI C style, in one of old rpcgen style (pass by reference), 108*7c478bd9Sstevel@tonic-gate * or new rpcgen style (multiple arguments, pass by value); 109*7c478bd9Sstevel@tonic-gate */ 110*7c478bd9Sstevel@tonic-gate 111*7c478bd9Sstevel@tonic-gate /* sample addargname = "clnt"; sample addargtype = "CLIENT * " */ 112*7c478bd9Sstevel@tonic-gate 113*7c478bd9Sstevel@tonic-gate void printarglist(proc, result, addargname, addargtype) 114*7c478bd9Sstevel@tonic-gate proc_list *proc; 115*7c478bd9Sstevel@tonic-gate char *result; 116*7c478bd9Sstevel@tonic-gate char* addargname, * addargtype; 117*7c478bd9Sstevel@tonic-gate { 118*7c478bd9Sstevel@tonic-gate bool_t oneway = streq(proc->res_type, "oneway"); 119*7c478bd9Sstevel@tonic-gate decl_list *l; 120*7c478bd9Sstevel@tonic-gate 121*7c478bd9Sstevel@tonic-gate if (!newstyle) { 122*7c478bd9Sstevel@tonic-gate /* old style: always pass argument by reference */ 123*7c478bd9Sstevel@tonic-gate if (Cflag) { /* C++ style heading */ 124*7c478bd9Sstevel@tonic-gate f_print(fout, "("); 125*7c478bd9Sstevel@tonic-gate ptype(proc->args.decls->decl.prefix, 126*7c478bd9Sstevel@tonic-gate proc->args.decls->decl.type, 1); 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate if (mtflag) {/* Generate result field */ 129*7c478bd9Sstevel@tonic-gate f_print(fout, "*argp, "); 130*7c478bd9Sstevel@tonic-gate if (!oneway) { 131*7c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, 132*7c478bd9Sstevel@tonic-gate proc->res_type, 1); 133*7c478bd9Sstevel@tonic-gate f_print(fout, "*%s, ", result); 134*7c478bd9Sstevel@tonic-gate } 135*7c478bd9Sstevel@tonic-gate f_print(fout, "%s%s)\n", 136*7c478bd9Sstevel@tonic-gate addargtype, addargname); 137*7c478bd9Sstevel@tonic-gate } else 138*7c478bd9Sstevel@tonic-gate f_print(fout, "*argp, %s%s)\n", addargtype, addargname); 139*7c478bd9Sstevel@tonic-gate } else { 140*7c478bd9Sstevel@tonic-gate if (!mtflag) 141*7c478bd9Sstevel@tonic-gate f_print(fout, "(argp, %s)\n", addargname); 142*7c478bd9Sstevel@tonic-gate else { 143*7c478bd9Sstevel@tonic-gate f_print(fout, "(argp, "); 144*7c478bd9Sstevel@tonic-gate if (!oneway) { 145*7c478bd9Sstevel@tonic-gate f_print(fout, "%s, ", 146*7c478bd9Sstevel@tonic-gate result); 147*7c478bd9Sstevel@tonic-gate } 148*7c478bd9Sstevel@tonic-gate f_print(fout, "%s)\n", 149*7c478bd9Sstevel@tonic-gate addargname); 150*7c478bd9Sstevel@tonic-gate } 151*7c478bd9Sstevel@tonic-gate f_print(fout, "\t"); 152*7c478bd9Sstevel@tonic-gate ptype(proc->args.decls->decl.prefix, 153*7c478bd9Sstevel@tonic-gate proc->args.decls->decl.type, 1); 154*7c478bd9Sstevel@tonic-gate f_print(fout, "*argp;\n"); 155*7c478bd9Sstevel@tonic-gate if (mtflag && !oneway) { 156*7c478bd9Sstevel@tonic-gate f_print(fout, "\t"); 157*7c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, proc->res_type, 1); 158*7c478bd9Sstevel@tonic-gate f_print(fout, "*%s;\n", result); 159*7c478bd9Sstevel@tonic-gate } 160*7c478bd9Sstevel@tonic-gate } 161*7c478bd9Sstevel@tonic-gate } else if (streq(proc->args.decls->decl.type, "void")) { 162*7c478bd9Sstevel@tonic-gate /* newstyle, 0 argument */ 163*7c478bd9Sstevel@tonic-gate if (mtflag) { 164*7c478bd9Sstevel@tonic-gate f_print(fout, "("); 165*7c478bd9Sstevel@tonic-gate 166*7c478bd9Sstevel@tonic-gate if (Cflag) { 167*7c478bd9Sstevel@tonic-gate if (!oneway) { 168*7c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, 169*7c478bd9Sstevel@tonic-gate proc->res_type, 1); 170*7c478bd9Sstevel@tonic-gate f_print(fout, "*%s, ", result); 171*7c478bd9Sstevel@tonic-gate } 172*7c478bd9Sstevel@tonic-gate f_print(fout, "%s%s)\n", 173*7c478bd9Sstevel@tonic-gate addargtype, addargname); 174*7c478bd9Sstevel@tonic-gate } else 175*7c478bd9Sstevel@tonic-gate f_print(fout, "(%s)\n", addargname); 176*7c478bd9Sstevel@tonic-gate 177*7c478bd9Sstevel@tonic-gate } else 178*7c478bd9Sstevel@tonic-gate if (Cflag) 179*7c478bd9Sstevel@tonic-gate f_print(fout, "(%s%s)\n", addargtype, addargname); 180*7c478bd9Sstevel@tonic-gate else 181*7c478bd9Sstevel@tonic-gate f_print(fout, "(%s)\n", addargname); 182*7c478bd9Sstevel@tonic-gate } else { 183*7c478bd9Sstevel@tonic-gate /* new style, 1 or multiple arguments */ 184*7c478bd9Sstevel@tonic-gate if (!Cflag) { 185*7c478bd9Sstevel@tonic-gate f_print(fout, "("); 186*7c478bd9Sstevel@tonic-gate for (l = proc->args.decls; l != NULL; l = l->next) 187*7c478bd9Sstevel@tonic-gate f_print(fout, "%s, ", l->decl.name); 188*7c478bd9Sstevel@tonic-gate if (mtflag && !oneway) 189*7c478bd9Sstevel@tonic-gate f_print(fout, "%s, ", result); 190*7c478bd9Sstevel@tonic-gate 191*7c478bd9Sstevel@tonic-gate f_print(fout, "%s)\n", addargname); 192*7c478bd9Sstevel@tonic-gate for (l = proc->args.decls; l != NULL; l = l->next) { 193*7c478bd9Sstevel@tonic-gate pdeclaration(proc->args.argname, 194*7c478bd9Sstevel@tonic-gate &l->decl, 1, ";\n"); 195*7c478bd9Sstevel@tonic-gate } 196*7c478bd9Sstevel@tonic-gate if (mtflag && !oneway) { 197*7c478bd9Sstevel@tonic-gate f_print(fout, "\t"); 198*7c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, proc->res_type, 1); 199*7c478bd9Sstevel@tonic-gate f_print(fout, "*%s;\n", result); 200*7c478bd9Sstevel@tonic-gate } 201*7c478bd9Sstevel@tonic-gate 202*7c478bd9Sstevel@tonic-gate } else { /* C++ style header */ 203*7c478bd9Sstevel@tonic-gate f_print(fout, "("); 204*7c478bd9Sstevel@tonic-gate for (l = proc->args.decls; l != NULL; l = l->next) { 205*7c478bd9Sstevel@tonic-gate pdeclaration(proc->args.argname, &l->decl, 0, 206*7c478bd9Sstevel@tonic-gate ", "); 207*7c478bd9Sstevel@tonic-gate } 208*7c478bd9Sstevel@tonic-gate if (mtflag && !oneway) { 209*7c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, proc->res_type, 1); 210*7c478bd9Sstevel@tonic-gate f_print(fout, "*%s, ", result); 211*7c478bd9Sstevel@tonic-gate 212*7c478bd9Sstevel@tonic-gate } 213*7c478bd9Sstevel@tonic-gate f_print(fout, "%s%s)\n", addargtype, addargname); 214*7c478bd9Sstevel@tonic-gate } 215*7c478bd9Sstevel@tonic-gate } 216*7c478bd9Sstevel@tonic-gate 217*7c478bd9Sstevel@tonic-gate if (!Cflag) 218*7c478bd9Sstevel@tonic-gate f_print(fout, "\t%s%s;\n", addargtype, addargname); 219*7c478bd9Sstevel@tonic-gate } 220*7c478bd9Sstevel@tonic-gate 221*7c478bd9Sstevel@tonic-gate 222*7c478bd9Sstevel@tonic-gate 223*7c478bd9Sstevel@tonic-gate static char * 224*7c478bd9Sstevel@tonic-gate ampr(type) 225*7c478bd9Sstevel@tonic-gate char *type; 226*7c478bd9Sstevel@tonic-gate { 227*7c478bd9Sstevel@tonic-gate if (isvectordef(type, REL_ALIAS)) { 228*7c478bd9Sstevel@tonic-gate return (""); 229*7c478bd9Sstevel@tonic-gate } else { 230*7c478bd9Sstevel@tonic-gate return ("&"); 231*7c478bd9Sstevel@tonic-gate } 232*7c478bd9Sstevel@tonic-gate } 233*7c478bd9Sstevel@tonic-gate 234*7c478bd9Sstevel@tonic-gate static 235*7c478bd9Sstevel@tonic-gate printbody(proc) 236*7c478bd9Sstevel@tonic-gate proc_list *proc; 237*7c478bd9Sstevel@tonic-gate { 238*7c478bd9Sstevel@tonic-gate decl_list *l; 239*7c478bd9Sstevel@tonic-gate bool_t args2 = (proc->arg_num > 1); 240*7c478bd9Sstevel@tonic-gate int i; 241*7c478bd9Sstevel@tonic-gate bool_t oneway = streq(proc->res_type, "oneway"); 242*7c478bd9Sstevel@tonic-gate 243*7c478bd9Sstevel@tonic-gate /* 244*7c478bd9Sstevel@tonic-gate * For new style with multiple arguments, need a structure in which 245*7c478bd9Sstevel@tonic-gate * to stuff the arguments. 246*7c478bd9Sstevel@tonic-gate */ 247*7c478bd9Sstevel@tonic-gate 248*7c478bd9Sstevel@tonic-gate 249*7c478bd9Sstevel@tonic-gate if (newstyle && args2) { 250*7c478bd9Sstevel@tonic-gate f_print(fout, "\t%s", proc->args.argname); 251*7c478bd9Sstevel@tonic-gate f_print(fout, " arg;\n"); 252*7c478bd9Sstevel@tonic-gate } 253*7c478bd9Sstevel@tonic-gate if (!oneway) { 254*7c478bd9Sstevel@tonic-gate if (!mtflag) { 255*7c478bd9Sstevel@tonic-gate f_print(fout, "\tstatic "); 256*7c478bd9Sstevel@tonic-gate if (streq(proc->res_type, "void")) { 257*7c478bd9Sstevel@tonic-gate f_print(fout, "char "); 258*7c478bd9Sstevel@tonic-gate } else { 259*7c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, proc->res_type, 0); 260*7c478bd9Sstevel@tonic-gate } 261*7c478bd9Sstevel@tonic-gate f_print(fout, "%s;\n", RESULT); 262*7c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 263*7c478bd9Sstevel@tonic-gate f_print(fout, 264*7c478bd9Sstevel@tonic-gate "\tmemset((char *)%s%s, 0, sizeof (%s));\n", 265*7c478bd9Sstevel@tonic-gate ampr(proc->res_type), RESULT, RESULT); 266*7c478bd9Sstevel@tonic-gate 267*7c478bd9Sstevel@tonic-gate } 268*7c478bd9Sstevel@tonic-gate if (newstyle && !args2 && 269*7c478bd9Sstevel@tonic-gate (streq(proc->args.decls->decl.type, "void"))) { 270*7c478bd9Sstevel@tonic-gate /* newstyle, 0 arguments */ 271*7c478bd9Sstevel@tonic-gate 272*7c478bd9Sstevel@tonic-gate if (mtflag) 273*7c478bd9Sstevel@tonic-gate f_print(fout, "\t return "); 274*7c478bd9Sstevel@tonic-gate else 275*7c478bd9Sstevel@tonic-gate f_print(fout, "\t if "); 276*7c478bd9Sstevel@tonic-gate 277*7c478bd9Sstevel@tonic-gate f_print(fout, 278*7c478bd9Sstevel@tonic-gate "(clnt_call(clnt, %s,\n\t\t(xdrproc_t) xdr_void, ", 279*7c478bd9Sstevel@tonic-gate proc->proc_name); 280*7c478bd9Sstevel@tonic-gate f_print(fout, 281*7c478bd9Sstevel@tonic-gate "(caddr_t) NULL,\n\t\t(xdrproc_t) xdr_%s, " 282*7c478bd9Sstevel@tonic-gate "(caddr_t) %s%s,", 283*7c478bd9Sstevel@tonic-gate stringfix(proc->res_type), 284*7c478bd9Sstevel@tonic-gate (mtflag)?"":ampr(proc->res_type), 285*7c478bd9Sstevel@tonic-gate RESULT); 286*7c478bd9Sstevel@tonic-gate 287*7c478bd9Sstevel@tonic-gate if (mtflag) 288*7c478bd9Sstevel@tonic-gate f_print(fout, "\n\t\tTIMEOUT));\n"); 289*7c478bd9Sstevel@tonic-gate else 290*7c478bd9Sstevel@tonic-gate f_print(fout, 291*7c478bd9Sstevel@tonic-gate "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n"); 292*7c478bd9Sstevel@tonic-gate 293*7c478bd9Sstevel@tonic-gate } else if (newstyle && args2) { 294*7c478bd9Sstevel@tonic-gate /* 295*7c478bd9Sstevel@tonic-gate * Newstyle, multiple arguments 296*7c478bd9Sstevel@tonic-gate * stuff arguments into structure 297*7c478bd9Sstevel@tonic-gate */ 298*7c478bd9Sstevel@tonic-gate for (l = proc->args.decls; l != NULL; l = l->next) { 299*7c478bd9Sstevel@tonic-gate f_print(fout, "\targ.%s = %s;\n", 300*7c478bd9Sstevel@tonic-gate l->decl.name, l->decl.name); 301*7c478bd9Sstevel@tonic-gate } 302*7c478bd9Sstevel@tonic-gate if (mtflag) 303*7c478bd9Sstevel@tonic-gate f_print(fout, "\treturn "); 304*7c478bd9Sstevel@tonic-gate else 305*7c478bd9Sstevel@tonic-gate f_print(fout, "\tif "); 306*7c478bd9Sstevel@tonic-gate f_print(fout, 307*7c478bd9Sstevel@tonic-gate "(clnt_call(clnt, %s,\n\t\t(xdrproc_t) xdr_%s", 308*7c478bd9Sstevel@tonic-gate proc->proc_name, proc->args.argname); 309*7c478bd9Sstevel@tonic-gate f_print(fout, 310*7c478bd9Sstevel@tonic-gate ", (caddr_t) &arg,\n\t\t(xdrproc_t) xdr_%s, " 311*7c478bd9Sstevel@tonic-gate "(caddr_t) %s%s,", 312*7c478bd9Sstevel@tonic-gate stringfix(proc->res_type), 313*7c478bd9Sstevel@tonic-gate (mtflag)?"":ampr(proc->res_type), 314*7c478bd9Sstevel@tonic-gate RESULT); 315*7c478bd9Sstevel@tonic-gate if (mtflag) 316*7c478bd9Sstevel@tonic-gate f_print(fout, "\n\t\tTIMEOUT));\n"); 317*7c478bd9Sstevel@tonic-gate else 318*7c478bd9Sstevel@tonic-gate f_print(fout, 319*7c478bd9Sstevel@tonic-gate "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n"); 320*7c478bd9Sstevel@tonic-gate } else { /* single argument, new or old style */ 321*7c478bd9Sstevel@tonic-gate if (!mtflag) 322*7c478bd9Sstevel@tonic-gate f_print(fout, 323*7c478bd9Sstevel@tonic-gate "\tif (clnt_call(clnt, " 324*7c478bd9Sstevel@tonic-gate "%s,\n\t\t(xdrproc_t) xdr_%s, " 325*7c478bd9Sstevel@tonic-gate "(caddr_t) %s%s,\n\t\t(xdrproc_t) xdr_%s, " 326*7c478bd9Sstevel@tonic-gate "(caddr_t) %s%s,\n\t\tTIMEOUT) != " 327*7c478bd9Sstevel@tonic-gate "RPC_SUCCESS) {\n", 328*7c478bd9Sstevel@tonic-gate proc->proc_name, 329*7c478bd9Sstevel@tonic-gate stringfix(proc->args.decls->decl.type), 330*7c478bd9Sstevel@tonic-gate (newstyle ? "&" : ""), 331*7c478bd9Sstevel@tonic-gate (newstyle ? 332*7c478bd9Sstevel@tonic-gate proc->args.decls->decl.name : 333*7c478bd9Sstevel@tonic-gate "argp"), 334*7c478bd9Sstevel@tonic-gate stringfix(proc->res_type), 335*7c478bd9Sstevel@tonic-gate ampr(proc->res_type), 336*7c478bd9Sstevel@tonic-gate RESULT); 337*7c478bd9Sstevel@tonic-gate else 338*7c478bd9Sstevel@tonic-gate f_print(fout, 339*7c478bd9Sstevel@tonic-gate "\treturn (clnt_call(clnt, " 340*7c478bd9Sstevel@tonic-gate "%s,\n\t\t(xdrproc_t) xdr_%s, " 341*7c478bd9Sstevel@tonic-gate "(caddr_t) %s%s,\n\t\t(xdrproc_t) xdr_%s, " 342*7c478bd9Sstevel@tonic-gate "(caddr_t) %s%s,\n\t\tTIMEOUT));\n", 343*7c478bd9Sstevel@tonic-gate proc->proc_name, 344*7c478bd9Sstevel@tonic-gate stringfix(proc->args.decls->decl.type), 345*7c478bd9Sstevel@tonic-gate (newstyle ? "&" : ""), 346*7c478bd9Sstevel@tonic-gate (newstyle ? 347*7c478bd9Sstevel@tonic-gate proc->args.decls->decl.name : 348*7c478bd9Sstevel@tonic-gate "argp"), 349*7c478bd9Sstevel@tonic-gate stringfix(proc->res_type), "", 350*7c478bd9Sstevel@tonic-gate RESULT); 351*7c478bd9Sstevel@tonic-gate } 352*7c478bd9Sstevel@tonic-gate if (!mtflag) { 353*7c478bd9Sstevel@tonic-gate f_print(fout, "\t\treturn (NULL);\n"); 354*7c478bd9Sstevel@tonic-gate f_print(fout, "\t}\n"); 355*7c478bd9Sstevel@tonic-gate 356*7c478bd9Sstevel@tonic-gate if (streq(proc->res_type, "void")) { 357*7c478bd9Sstevel@tonic-gate f_print(fout, "\treturn ((void *)%s%s);\n", 358*7c478bd9Sstevel@tonic-gate ampr(proc->res_type), RESULT); 359*7c478bd9Sstevel@tonic-gate } else { 360*7c478bd9Sstevel@tonic-gate f_print(fout, "\treturn (%s%s);\n", 361*7c478bd9Sstevel@tonic-gate ampr(proc->res_type), RESULT); 362*7c478bd9Sstevel@tonic-gate } 363*7c478bd9Sstevel@tonic-gate } 364*7c478bd9Sstevel@tonic-gate } else { 365*7c478bd9Sstevel@tonic-gate /* oneway call */ 366*7c478bd9Sstevel@tonic-gate if (!mtflag) { 367*7c478bd9Sstevel@tonic-gate f_print(fout, "\tstatic enum clnt_stat "); 368*7c478bd9Sstevel@tonic-gate f_print(fout, "%s;\n", RESULT); 369*7c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 370*7c478bd9Sstevel@tonic-gate f_print(fout, 371*7c478bd9Sstevel@tonic-gate "\tmemset((char *)&%s, 0, sizeof (%s));\n", 372*7c478bd9Sstevel@tonic-gate RESULT, RESULT); 373*7c478bd9Sstevel@tonic-gate 374*7c478bd9Sstevel@tonic-gate } 375*7c478bd9Sstevel@tonic-gate if (newstyle && !args2 && 376*7c478bd9Sstevel@tonic-gate (streq(proc->args.decls->decl.type, "void"))) { 377*7c478bd9Sstevel@tonic-gate /* newstyle, 0 arguments */ 378*7c478bd9Sstevel@tonic-gate 379*7c478bd9Sstevel@tonic-gate if (mtflag) 380*7c478bd9Sstevel@tonic-gate f_print(fout, "\t return ("); 381*7c478bd9Sstevel@tonic-gate else 382*7c478bd9Sstevel@tonic-gate f_print(fout, "\t if ((%s = ", RESULT); 383*7c478bd9Sstevel@tonic-gate 384*7c478bd9Sstevel@tonic-gate f_print(fout, 385*7c478bd9Sstevel@tonic-gate "clnt_send(clnt, %s,\n\t\t(xdrproc_t) xdr_void, ", 386*7c478bd9Sstevel@tonic-gate proc->proc_name); 387*7c478bd9Sstevel@tonic-gate f_print(fout, 388*7c478bd9Sstevel@tonic-gate "(caddr_t) NULL)"); 389*7c478bd9Sstevel@tonic-gate 390*7c478bd9Sstevel@tonic-gate if (mtflag) 391*7c478bd9Sstevel@tonic-gate f_print(fout, ");\n"); 392*7c478bd9Sstevel@tonic-gate else 393*7c478bd9Sstevel@tonic-gate f_print(fout, ") != RPC_SUCCESS) {\n"); 394*7c478bd9Sstevel@tonic-gate 395*7c478bd9Sstevel@tonic-gate } else if (newstyle && args2) { 396*7c478bd9Sstevel@tonic-gate /* 397*7c478bd9Sstevel@tonic-gate * Newstyle, multiple arguments 398*7c478bd9Sstevel@tonic-gate * stuff arguments into structure 399*7c478bd9Sstevel@tonic-gate */ 400*7c478bd9Sstevel@tonic-gate for (l = proc->args.decls; l != NULL; l = l->next) { 401*7c478bd9Sstevel@tonic-gate f_print(fout, "\targ.%s = %s;\n", 402*7c478bd9Sstevel@tonic-gate l->decl.name, l->decl.name); 403*7c478bd9Sstevel@tonic-gate } 404*7c478bd9Sstevel@tonic-gate if (mtflag) 405*7c478bd9Sstevel@tonic-gate f_print(fout, "\treturn ("); 406*7c478bd9Sstevel@tonic-gate else 407*7c478bd9Sstevel@tonic-gate f_print(fout, "\tif ((%s =", RESULT); 408*7c478bd9Sstevel@tonic-gate f_print(fout, 409*7c478bd9Sstevel@tonic-gate "clnt_send(clnt, %s,\n\t\t(xdrproc_t) xdr_%s", 410*7c478bd9Sstevel@tonic-gate proc->proc_name, proc->args.argname); 411*7c478bd9Sstevel@tonic-gate f_print(fout, 412*7c478bd9Sstevel@tonic-gate ", (caddr_t) &arg)"); 413*7c478bd9Sstevel@tonic-gate if (mtflag) 414*7c478bd9Sstevel@tonic-gate f_print(fout, ");\n"); 415*7c478bd9Sstevel@tonic-gate else 416*7c478bd9Sstevel@tonic-gate f_print(fout, ") != RPC_SUCCESS) {\n"); 417*7c478bd9Sstevel@tonic-gate } else { /* single argument, new or old style */ 418*7c478bd9Sstevel@tonic-gate if (!mtflag) 419*7c478bd9Sstevel@tonic-gate f_print(fout, 420*7c478bd9Sstevel@tonic-gate "\tif ((%s = clnt_send(clnt, " 421*7c478bd9Sstevel@tonic-gate "%s,\n\t\t(xdrproc_t) xdr_%s, " 422*7c478bd9Sstevel@tonic-gate "(caddr_t) %s%s)) != RPC_SUCCESS) {\n", 423*7c478bd9Sstevel@tonic-gate RESULT, 424*7c478bd9Sstevel@tonic-gate proc->proc_name, 425*7c478bd9Sstevel@tonic-gate stringfix(proc->args.decls->decl.type), 426*7c478bd9Sstevel@tonic-gate (newstyle ? "&" : ""), 427*7c478bd9Sstevel@tonic-gate (newstyle ? 428*7c478bd9Sstevel@tonic-gate proc->args.decls->decl.name : 429*7c478bd9Sstevel@tonic-gate "argp")); 430*7c478bd9Sstevel@tonic-gate else 431*7c478bd9Sstevel@tonic-gate 432*7c478bd9Sstevel@tonic-gate f_print(fout, 433*7c478bd9Sstevel@tonic-gate "\treturn (clnt_send(clnt, " 434*7c478bd9Sstevel@tonic-gate "%s,\n\t\t(xdrproc_t) xdr_%s, " 435*7c478bd9Sstevel@tonic-gate "(caddr_t) %s%s));\n", 436*7c478bd9Sstevel@tonic-gate proc->proc_name, 437*7c478bd9Sstevel@tonic-gate stringfix(proc->args.decls->decl.type), 438*7c478bd9Sstevel@tonic-gate (newstyle ? "&" : ""), 439*7c478bd9Sstevel@tonic-gate (newstyle ? 440*7c478bd9Sstevel@tonic-gate proc->args.decls->decl.name : 441*7c478bd9Sstevel@tonic-gate "argp")); 442*7c478bd9Sstevel@tonic-gate } 443*7c478bd9Sstevel@tonic-gate if (!mtflag) { 444*7c478bd9Sstevel@tonic-gate f_print(fout, "\t\treturn (NULL);\n"); 445*7c478bd9Sstevel@tonic-gate f_print(fout, "\t}\n"); 446*7c478bd9Sstevel@tonic-gate 447*7c478bd9Sstevel@tonic-gate f_print(fout, "\treturn ((void *)&%s);\n", 448*7c478bd9Sstevel@tonic-gate RESULT); 449*7c478bd9Sstevel@tonic-gate } 450*7c478bd9Sstevel@tonic-gate } 451*7c478bd9Sstevel@tonic-gate } 452