1 #include "rpc_test.h"
2 #include <stdio.h>
3 #include <string.h>
4 #include <stdlib.h> /* getenv, exit */
5 #include <sys/types.h>
6 #include <syslog.h>
7 
8 /* States a server can be in wrt request */
9 
10 #define	_IDLE 0
11 #define	_SERVED 1
12 
13 static int _rpcsvcstate = _IDLE;	/* Set when a request is serviced */
14 static int _rpcsvccount = 0;		/* Number of requests being serviced */
15 
16 void
rpc_test_prog_1_svc(rqstp,transp)17 rpc_test_prog_1_svc(rqstp, transp)
18 	struct svc_req *rqstp;
19 	SVCXPRT *transp;
20 {
21 	union {
22 		char *rpc_test_echo_1_arg;
23 	} argument;
24 	char *result;
25 	bool_t (*xdr_argument)(), (*xdr_result)();
26 	char *(*local)();
27 
28 	_rpcsvccount++;
29 	switch (rqstp->rq_proc) {
30 	case NULLPROC:
31 		(void) svc_sendreply(transp, xdr_void,
32 			(char *)NULL);
33 		_rpcsvccount--;
34 		_rpcsvcstate = _SERVED;
35 		return;
36 
37 	case RPC_TEST_ECHO:
38 		xdr_argument = xdr_wrapstring;
39 		xdr_result = xdr_wrapstring;
40 		local = (char *(*)()) rpc_test_echo_1_svc;
41 		break;
42 
43 	default:
44 		svcerr_noproc(transp);
45 		_rpcsvccount--;
46 		_rpcsvcstate = _SERVED;
47 		return;
48 	}
49 	(void) memset(&argument, 0, sizeof (argument));
50 	if (!svc_getargs(transp, xdr_argument, &argument)) {
51 		svcerr_decode(transp);
52 		_rpcsvccount--;
53 		_rpcsvcstate = _SERVED;
54 		return;
55 	}
56 	result = (*local)(&argument, rqstp);
57 	if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
58 		svcerr_systemerr(transp);
59 	}
60 	if (!svc_freeargs(transp, xdr_argument, &argument)) {
61 		syslog(LOG_ERR, "unable to free arguments");
62 		exit(1);
63 	}
64 	_rpcsvccount--;
65 	_rpcsvcstate = _SERVED;
66 	return;
67 }
68