Path: blob/main/crypto/krb5/src/lib/rpc/unit-test/rpc_test_svc.c
39565 views
#include "rpc_test.h"1#include <stdio.h>2#include <string.h>3#include <stdlib.h> /* getenv, exit */4#include <sys/types.h>5#include <syslog.h>67/* States a server can be in wrt request */89#define _IDLE 010#define _SERVED 11112static int _rpcsvcstate = _IDLE; /* Set when a request is serviced */13static int _rpcsvccount = 0; /* Number of requests being serviced */1415void16rpc_test_prog_1_svc(struct svc_req *rqstp, SVCXPRT *transp)17{18union {19char *rpc_test_echo_1_arg;20} argument;21char *result;22xdrproc_t xdr_argument, xdr_result;23char *(*local)(char *, struct svc_req *);2425_rpcsvccount++;26switch (rqstp->rq_proc) {27case NULLPROC:28(void) svc_sendreply(transp, xdr_void,29(char *)NULL);30_rpcsvccount--;31_rpcsvcstate = _SERVED;32return;3334case RPC_TEST_ECHO:35xdr_argument = (xdrproc_t)xdr_wrapstring;36xdr_result = (xdrproc_t)xdr_wrapstring;37local = (char *(*)(char *, struct svc_req *)) rpc_test_echo_1_svc;38break;3940default:41svcerr_noproc(transp);42_rpcsvccount--;43_rpcsvcstate = _SERVED;44return;45}46(void) memset(&argument, 0, sizeof (argument));47if (!svc_getargs(transp, xdr_argument, &argument)) {48svcerr_decode(transp);49_rpcsvccount--;50_rpcsvcstate = _SERVED;51return;52}53result = (*local)((char *)&argument, rqstp);54if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {55svcerr_systemerr(transp);56}57if (!svc_freeargs(transp, xdr_argument, &argument)) {58syslog(LOG_ERR, "unable to free arguments");59exit(1);60}61_rpcsvccount--;62_rpcsvcstate = _SERVED;63return;64}656667