Move all sources to subdirs
This commit is contained in:
+1690
File diff suppressed because it is too large
Load Diff
+1380
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* Please do not edit this file.
|
||||
* It was generated using rpcgen.
|
||||
*/
|
||||
|
||||
#ifndef _PORTMAP_H_RPCGEN
|
||||
#define _PORTMAP_H_RPCGEN
|
||||
|
||||
#include "xdr_impl.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define PMAP_PORT 111
|
||||
|
||||
struct pmap2_mapping {
|
||||
u_int prog;
|
||||
u_int vers;
|
||||
u_int prot;
|
||||
u_int port;
|
||||
};
|
||||
typedef struct pmap2_mapping pmap2_mapping;
|
||||
|
||||
struct pmap2_call_args {
|
||||
u_int prog;
|
||||
u_int vers;
|
||||
u_int proc;
|
||||
xdr_string_t args;
|
||||
};
|
||||
typedef struct pmap2_call_args pmap2_call_args;
|
||||
|
||||
struct pmap2_call_result {
|
||||
u_int port;
|
||||
xdr_string_t res;
|
||||
};
|
||||
typedef struct pmap2_call_result pmap2_call_result;
|
||||
|
||||
struct pmap2_mapping_list {
|
||||
pmap2_mapping map;
|
||||
struct pmap2_mapping_list *next;
|
||||
};
|
||||
typedef struct pmap2_mapping_list pmap2_mapping_list;
|
||||
|
||||
struct pmap2_dump_result {
|
||||
struct pmap2_mapping_list *list;
|
||||
};
|
||||
typedef struct pmap2_dump_result pmap2_dump_result;
|
||||
|
||||
struct pmap3_string_result {
|
||||
xdr_string_t addr;
|
||||
};
|
||||
typedef struct pmap3_string_result pmap3_string_result;
|
||||
|
||||
struct pmap3_mapping {
|
||||
u_int prog;
|
||||
u_int vers;
|
||||
xdr_string_t netid;
|
||||
xdr_string_t addr;
|
||||
xdr_string_t owner;
|
||||
};
|
||||
typedef struct pmap3_mapping pmap3_mapping;
|
||||
|
||||
struct pmap3_mapping_list {
|
||||
pmap3_mapping map;
|
||||
struct pmap3_mapping_list *next;
|
||||
};
|
||||
typedef struct pmap3_mapping_list pmap3_mapping_list;
|
||||
|
||||
struct pmap3_dump_result {
|
||||
struct pmap3_mapping_list *list;
|
||||
};
|
||||
typedef struct pmap3_dump_result pmap3_dump_result;
|
||||
|
||||
struct pmap3_call_args {
|
||||
u_int prog;
|
||||
u_int vers;
|
||||
u_int proc;
|
||||
xdr_string_t args;
|
||||
};
|
||||
typedef struct pmap3_call_args pmap3_call_args;
|
||||
|
||||
struct pmap3_call_result {
|
||||
u_int port;
|
||||
xdr_string_t res;
|
||||
};
|
||||
typedef struct pmap3_call_result pmap3_call_result;
|
||||
|
||||
struct pmap3_netbuf {
|
||||
u_int maxlen;
|
||||
xdr_string_t buf;
|
||||
};
|
||||
typedef struct pmap3_netbuf pmap3_netbuf;
|
||||
|
||||
typedef pmap2_mapping PMAP2SETargs;
|
||||
|
||||
typedef pmap2_mapping PMAP2UNSETargs;
|
||||
|
||||
typedef pmap2_mapping PMAP2GETPORTargs;
|
||||
|
||||
typedef pmap2_call_args PMAP2CALLITargs;
|
||||
|
||||
typedef pmap2_call_result PMAP2CALLITres;
|
||||
|
||||
typedef pmap2_dump_result PMAP2DUMPres;
|
||||
|
||||
typedef pmap3_mapping PMAP3SETargs;
|
||||
|
||||
typedef pmap3_mapping PMAP3UNSETargs;
|
||||
|
||||
typedef pmap3_mapping PMAP3GETADDRargs;
|
||||
|
||||
typedef pmap3_string_result PMAP3GETADDRres;
|
||||
|
||||
typedef pmap3_dump_result PMAP3DUMPres;
|
||||
|
||||
typedef pmap3_call_result PMAP3CALLITargs;
|
||||
|
||||
typedef pmap3_call_result PMAP3CALLITres;
|
||||
|
||||
typedef pmap3_netbuf PMAP3UADDR2TADDRres;
|
||||
|
||||
typedef pmap3_netbuf PMAP3TADDR2UADDRargs;
|
||||
|
||||
typedef pmap3_string_result PMAP3TADDR2UADDRres;
|
||||
|
||||
#define PMAP_PROGRAM 100000
|
||||
#define PMAP_V2 2
|
||||
|
||||
|
||||
#define PMAP2_NULL 0
|
||||
#define PMAP2_SET 1
|
||||
#define PMAP2_UNSET 2
|
||||
#define PMAP2_GETPORT 3
|
||||
#define PMAP2_DUMP 4
|
||||
#define PMAP2_CALLIT 5
|
||||
|
||||
#define PMAP_V3 3
|
||||
|
||||
|
||||
#define PMAP3_NULL 0
|
||||
#define PMAP3_SET 1
|
||||
#define PMAP3_UNSET 2
|
||||
#define PMAP3_GETADDR 3
|
||||
#define PMAP3_DUMP 4
|
||||
#define PMAP3_CALLIT 5
|
||||
#define PMAP3_GETTIME 6
|
||||
#define PMAP3_UADDR2TADDR 7
|
||||
#define PMAP3_TADDR2UADDR 8
|
||||
|
||||
|
||||
/* the xdr functions */
|
||||
|
||||
|
||||
extern bool_t xdr_pmap2_mapping (XDR *, pmap2_mapping*);
|
||||
extern bool_t xdr_pmap2_call_args (XDR *, pmap2_call_args*);
|
||||
extern bool_t xdr_pmap2_call_result (XDR *, pmap2_call_result*);
|
||||
extern bool_t xdr_pmap2_mapping_list (XDR *, pmap2_mapping_list*);
|
||||
extern bool_t xdr_pmap2_dump_result (XDR *, pmap2_dump_result*);
|
||||
extern bool_t xdr_pmap3_string_result (XDR *, pmap3_string_result*);
|
||||
extern bool_t xdr_pmap3_mapping (XDR *, pmap3_mapping*);
|
||||
extern bool_t xdr_pmap3_mapping_list (XDR *, pmap3_mapping_list*);
|
||||
extern bool_t xdr_pmap3_dump_result (XDR *, pmap3_dump_result*);
|
||||
extern bool_t xdr_pmap3_call_args (XDR *, pmap3_call_args*);
|
||||
extern bool_t xdr_pmap3_call_result (XDR *, pmap3_call_result*);
|
||||
extern bool_t xdr_pmap3_netbuf (XDR *, pmap3_netbuf*);
|
||||
extern bool_t xdr_PMAP2SETargs (XDR *, PMAP2SETargs*);
|
||||
extern bool_t xdr_PMAP2UNSETargs (XDR *, PMAP2UNSETargs*);
|
||||
extern bool_t xdr_PMAP2GETPORTargs (XDR *, PMAP2GETPORTargs*);
|
||||
extern bool_t xdr_PMAP2CALLITargs (XDR *, PMAP2CALLITargs*);
|
||||
extern bool_t xdr_PMAP2CALLITres (XDR *, PMAP2CALLITres*);
|
||||
extern bool_t xdr_PMAP2DUMPres (XDR *, PMAP2DUMPres*);
|
||||
extern bool_t xdr_PMAP3SETargs (XDR *, PMAP3SETargs*);
|
||||
extern bool_t xdr_PMAP3UNSETargs (XDR *, PMAP3UNSETargs*);
|
||||
extern bool_t xdr_PMAP3GETADDRargs (XDR *, PMAP3GETADDRargs*);
|
||||
extern bool_t xdr_PMAP3GETADDRres (XDR *, PMAP3GETADDRres*);
|
||||
extern bool_t xdr_PMAP3DUMPres (XDR *, PMAP3DUMPres*);
|
||||
extern bool_t xdr_PMAP3CALLITargs (XDR *, PMAP3CALLITargs*);
|
||||
extern bool_t xdr_PMAP3CALLITres (XDR *, PMAP3CALLITres*);
|
||||
extern bool_t xdr_PMAP3UADDR2TADDRres (XDR *, PMAP3UADDR2TADDRres*);
|
||||
extern bool_t xdr_PMAP3TADDR2UADDRargs (XDR *, PMAP3TADDR2UADDRargs*);
|
||||
extern bool_t xdr_PMAP3TADDR2UADDRres (XDR *, PMAP3TADDR2UADDRres*);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_PORTMAP_H_RPCGEN */
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
Copyright (c) 2014, Ronnie Sahlberg
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
const PMAP_PORT = 111; /* portmapper port number */
|
||||
|
||||
struct pmap2_mapping {
|
||||
unsigned int prog;
|
||||
unsigned int vers;
|
||||
unsigned int prot;
|
||||
unsigned int port;
|
||||
};
|
||||
|
||||
struct pmap2_call_args {
|
||||
unsigned int prog;
|
||||
unsigned int vers;
|
||||
unsigned int proc;
|
||||
opaque args<>;
|
||||
};
|
||||
|
||||
struct pmap2_call_result {
|
||||
unsigned int port;
|
||||
opaque res<>;
|
||||
};
|
||||
|
||||
struct pmap2_mapping_list {
|
||||
pmap2_mapping map;
|
||||
pmap2_mapping_list *next;
|
||||
};
|
||||
|
||||
struct pmap2_dump_result {
|
||||
struct pmap2_mapping_list *list;
|
||||
};
|
||||
|
||||
struct pmap3_string_result {
|
||||
string addr<>;
|
||||
};
|
||||
|
||||
struct pmap3_mapping {
|
||||
unsigned int prog;
|
||||
unsigned int vers;
|
||||
string netid<>;
|
||||
string addr<>;
|
||||
string owner<>;
|
||||
};
|
||||
|
||||
struct pmap3_mapping_list {
|
||||
pmap3_mapping map;
|
||||
pmap3_mapping_list *next;
|
||||
};
|
||||
|
||||
struct pmap3_dump_result {
|
||||
struct pmap3_mapping_list *list;
|
||||
};
|
||||
|
||||
struct pmap3_call_args {
|
||||
unsigned int prog;
|
||||
unsigned int vers;
|
||||
unsigned int proc;
|
||||
opaque args<>;
|
||||
};
|
||||
|
||||
struct pmap3_call_result {
|
||||
unsigned int port;
|
||||
opaque res<>;
|
||||
};
|
||||
|
||||
struct pmap3_netbuf {
|
||||
unsigned int maxlen;
|
||||
/* This pretty much contains a sockaddr_storage.
|
||||
* Beware differences in endianess for ss_family
|
||||
* and whether or not ss_len exists.
|
||||
*/
|
||||
opaque buf<>;
|
||||
};
|
||||
|
||||
typedef pmap2_mapping PMAP2SETargs;
|
||||
typedef pmap2_mapping PMAP2UNSETargs;
|
||||
typedef pmap2_mapping PMAP2GETPORTargs;
|
||||
typedef pmap2_call_args PMAP2CALLITargs;
|
||||
typedef pmap2_call_result PMAP2CALLITres;
|
||||
typedef pmap2_dump_result PMAP2DUMPres;
|
||||
|
||||
typedef pmap3_mapping PMAP3SETargs;
|
||||
typedef pmap3_mapping PMAP3UNSETargs;
|
||||
typedef pmap3_mapping PMAP3GETADDRargs;
|
||||
typedef pmap3_string_result PMAP3GETADDRres;
|
||||
typedef pmap3_dump_result PMAP3DUMPres;
|
||||
typedef pmap3_call_result PMAP3CALLITargs;
|
||||
typedef pmap3_call_result PMAP3CALLITres;
|
||||
typedef pmap3_netbuf PMAP3UADDR2TADDRres;
|
||||
typedef pmap3_netbuf PMAP3TADDR2UADDRargs;
|
||||
typedef pmap3_string_result PMAP3TADDR2UADDRres;
|
||||
|
||||
program PMAP_PROGRAM {
|
||||
version PMAP_V2 {
|
||||
void
|
||||
PMAP2_NULL(void) = 0;
|
||||
|
||||
uint32_t
|
||||
PMAP2_SET(PMAP2SETargs) = 1;
|
||||
|
||||
uint32_t
|
||||
PMAP2_UNSET(PMAP2UNSETargs) = 2;
|
||||
|
||||
uint32_t
|
||||
PMAP2_GETPORT(PMAP2GETPORTargs) = 3;
|
||||
|
||||
PMAP2DUMPres
|
||||
PMAP2_DUMP(void) = 4;
|
||||
|
||||
PMAP2CALLITres
|
||||
PMAP2_CALLIT(PMAP2CALLITargs) = 5;
|
||||
} = 2;
|
||||
version PMAP_V3 {
|
||||
void
|
||||
PMAP3_NULL(void) = 0;
|
||||
|
||||
uint32_t
|
||||
PMAP3_SET(PMAP3SETargs) = 1;
|
||||
|
||||
uint32_t
|
||||
PMAP3_UNSET(PMAP3UNSETargs) = 2;
|
||||
|
||||
PMAP3GETADDRres
|
||||
PMAP3_GETADDR(PMAP3GETADDRargs) = 3;
|
||||
|
||||
PMAP3DUMPres
|
||||
PMAP3_DUMP(void) = 4;
|
||||
|
||||
PMAP3CALLITres
|
||||
PMAP3_CALLIT(PMAP3CALLITargs) = 5;
|
||||
|
||||
uint32_t
|
||||
PMAP3_GETTIME(void) = 6;
|
||||
|
||||
PMAP3UADDR2TADDRres
|
||||
PMAP3_UADDR2TADDR(string) = 7;
|
||||
|
||||
PMAP3TADDR2UADDRres
|
||||
PMAP3_TADDR2UADDR(PMAP3TADDR2UADDRargs) = 8;
|
||||
} = 3;
|
||||
} = 100000;
|
||||
@@ -0,0 +1,406 @@
|
||||
/*
|
||||
* Please do not edit this file.
|
||||
* It was generated using rpcgen.
|
||||
*/
|
||||
|
||||
#include "portmap.h"
|
||||
#include "xdr_impl_inline.h"
|
||||
|
||||
bool_t
|
||||
xdr_pmap2_mapping (XDR *xdrs, pmap2_mapping *objp)
|
||||
{
|
||||
|
||||
|
||||
if (xdrs->x_op == XDR_ENCODE) {
|
||||
if (1) {
|
||||
if (!xdr_u_int (xdrs, &objp->prog))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->vers))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->prot))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->port))
|
||||
return FALSE;
|
||||
} else {
|
||||
IXDR_PUT_U_LONG(buf, objp->prog);
|
||||
IXDR_PUT_U_LONG(buf, objp->vers);
|
||||
IXDR_PUT_U_LONG(buf, objp->prot);
|
||||
IXDR_PUT_U_LONG(buf, objp->port);
|
||||
}
|
||||
return TRUE;
|
||||
} else if (xdrs->x_op == XDR_DECODE) {
|
||||
if (1) {
|
||||
if (!xdr_u_int (xdrs, &objp->prog))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->vers))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->prot))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->port))
|
||||
return FALSE;
|
||||
} else {
|
||||
objp->prog = IXDR_GET_U_LONG(buf);
|
||||
objp->vers = IXDR_GET_U_LONG(buf);
|
||||
objp->prot = IXDR_GET_U_LONG(buf);
|
||||
objp->port = IXDR_GET_U_LONG(buf);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (!xdr_u_int (xdrs, &objp->prog))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->vers))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->prot))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->port))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_pmap2_call_args (XDR *xdrs, pmap2_call_args *objp)
|
||||
{
|
||||
|
||||
|
||||
if (xdrs->x_op == XDR_ENCODE) {
|
||||
if (1) {
|
||||
if (!xdr_u_int (xdrs, &objp->prog))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->vers))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->proc))
|
||||
return FALSE;
|
||||
|
||||
} else {
|
||||
IXDR_PUT_U_LONG(buf, objp->prog);
|
||||
IXDR_PUT_U_LONG(buf, objp->vers);
|
||||
IXDR_PUT_U_LONG(buf, objp->proc);
|
||||
}
|
||||
if (!xdr_bytes(xdrs, &objp->args, ~0))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
} else if (xdrs->x_op == XDR_DECODE) {
|
||||
if (1) {
|
||||
if (!xdr_u_int (xdrs, &objp->prog))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->vers))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->proc))
|
||||
return FALSE;
|
||||
|
||||
} else {
|
||||
objp->prog = IXDR_GET_U_LONG(buf);
|
||||
objp->vers = IXDR_GET_U_LONG(buf);
|
||||
objp->proc = IXDR_GET_U_LONG(buf);
|
||||
}
|
||||
if (!xdr_bytes(xdrs, &objp->args, ~0))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (!xdr_u_int (xdrs, &objp->prog))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->vers))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->proc))
|
||||
return FALSE;
|
||||
if (!xdr_bytes(xdrs, &objp->args, ~0))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_pmap2_call_result (XDR *xdrs, pmap2_call_result *objp)
|
||||
{
|
||||
|
||||
if (!xdr_u_int (xdrs, &objp->port))
|
||||
return FALSE;
|
||||
if (!xdr_bytes(xdrs, &objp->res, ~0))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_pmap2_mapping_list (XDR *xdrs, pmap2_mapping_list *objp)
|
||||
{
|
||||
|
||||
if (!xdr_pmap2_mapping (xdrs, &objp->map))
|
||||
return FALSE;
|
||||
if (!xdr_pointer (xdrs, (char **)&objp->next, sizeof (pmap2_mapping_list), (xdrproc_t) xdr_pmap2_mapping_list))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_pmap2_dump_result (XDR *xdrs, pmap2_dump_result *objp)
|
||||
{
|
||||
|
||||
if (!xdr_pointer (xdrs, (char **)&objp->list, sizeof (pmap2_mapping_list), (xdrproc_t) xdr_pmap2_mapping_list))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_pmap3_string_result (XDR *xdrs, pmap3_string_result *objp)
|
||||
{
|
||||
|
||||
if (!xdr_string (xdrs, &objp->addr, ~0))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_pmap3_mapping (XDR *xdrs, pmap3_mapping *objp)
|
||||
{
|
||||
|
||||
if (!xdr_u_int (xdrs, &objp->prog))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->vers))
|
||||
return FALSE;
|
||||
if (!xdr_string (xdrs, &objp->netid, ~0))
|
||||
return FALSE;
|
||||
if (!xdr_string (xdrs, &objp->addr, ~0))
|
||||
return FALSE;
|
||||
if (!xdr_string (xdrs, &objp->owner, ~0))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_pmap3_mapping_list (XDR *xdrs, pmap3_mapping_list *objp)
|
||||
{
|
||||
|
||||
if (!xdr_pmap3_mapping (xdrs, &objp->map))
|
||||
return FALSE;
|
||||
if (!xdr_pointer (xdrs, (char **)&objp->next, sizeof (pmap3_mapping_list), (xdrproc_t) xdr_pmap3_mapping_list))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_pmap3_dump_result (XDR *xdrs, pmap3_dump_result *objp)
|
||||
{
|
||||
|
||||
if (!xdr_pointer (xdrs, (char **)&objp->list, sizeof (pmap3_mapping_list), (xdrproc_t) xdr_pmap3_mapping_list))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_pmap3_call_args (XDR *xdrs, pmap3_call_args *objp)
|
||||
{
|
||||
|
||||
|
||||
if (xdrs->x_op == XDR_ENCODE) {
|
||||
if (1) {
|
||||
if (!xdr_u_int (xdrs, &objp->prog))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->vers))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->proc))
|
||||
return FALSE;
|
||||
|
||||
} else {
|
||||
IXDR_PUT_U_LONG(buf, objp->prog);
|
||||
IXDR_PUT_U_LONG(buf, objp->vers);
|
||||
IXDR_PUT_U_LONG(buf, objp->proc);
|
||||
}
|
||||
if (!xdr_bytes(xdrs, &objp->args, ~0))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
} else if (xdrs->x_op == XDR_DECODE) {
|
||||
if (1) {
|
||||
if (!xdr_u_int (xdrs, &objp->prog))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->vers))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->proc))
|
||||
return FALSE;
|
||||
|
||||
} else {
|
||||
objp->prog = IXDR_GET_U_LONG(buf);
|
||||
objp->vers = IXDR_GET_U_LONG(buf);
|
||||
objp->proc = IXDR_GET_U_LONG(buf);
|
||||
}
|
||||
if (!xdr_bytes(xdrs, &objp->args, ~0))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (!xdr_u_int (xdrs, &objp->prog))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->vers))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->proc))
|
||||
return FALSE;
|
||||
if (!xdr_bytes(xdrs, &objp->args, ~0))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_pmap3_call_result (XDR *xdrs, pmap3_call_result *objp)
|
||||
{
|
||||
|
||||
if (!xdr_u_int (xdrs, &objp->port))
|
||||
return FALSE;
|
||||
if (!xdr_bytes(xdrs, &objp->res, ~0))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_pmap3_netbuf (XDR *xdrs, pmap3_netbuf *objp)
|
||||
{
|
||||
|
||||
if (!xdr_u_int (xdrs, &objp->maxlen))
|
||||
return FALSE;
|
||||
if (!xdr_bytes(xdrs, &objp->buf, ~0))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_PMAP2SETargs (XDR *xdrs, PMAP2SETargs *objp)
|
||||
{
|
||||
|
||||
if (!xdr_pmap2_mapping (xdrs, objp))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_PMAP2UNSETargs (XDR *xdrs, PMAP2UNSETargs *objp)
|
||||
{
|
||||
|
||||
if (!xdr_pmap2_mapping (xdrs, objp))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_PMAP2GETPORTargs (XDR *xdrs, PMAP2GETPORTargs *objp)
|
||||
{
|
||||
|
||||
if (!xdr_pmap2_mapping (xdrs, objp))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_PMAP2CALLITargs (XDR *xdrs, PMAP2CALLITargs *objp)
|
||||
{
|
||||
|
||||
if (!xdr_pmap2_call_args (xdrs, objp))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_PMAP2CALLITres (XDR *xdrs, PMAP2CALLITres *objp)
|
||||
{
|
||||
|
||||
if (!xdr_pmap2_call_result (xdrs, objp))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_PMAP2DUMPres (XDR *xdrs, PMAP2DUMPres *objp)
|
||||
{
|
||||
|
||||
if (!xdr_pmap2_dump_result (xdrs, objp))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_PMAP3SETargs (XDR *xdrs, PMAP3SETargs *objp)
|
||||
{
|
||||
|
||||
if (!xdr_pmap3_mapping (xdrs, objp))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_PMAP3UNSETargs (XDR *xdrs, PMAP3UNSETargs *objp)
|
||||
{
|
||||
|
||||
if (!xdr_pmap3_mapping (xdrs, objp))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_PMAP3GETADDRargs (XDR *xdrs, PMAP3GETADDRargs *objp)
|
||||
{
|
||||
|
||||
if (!xdr_pmap3_mapping (xdrs, objp))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_PMAP3GETADDRres (XDR *xdrs, PMAP3GETADDRres *objp)
|
||||
{
|
||||
|
||||
if (!xdr_pmap3_string_result (xdrs, objp))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_PMAP3DUMPres (XDR *xdrs, PMAP3DUMPres *objp)
|
||||
{
|
||||
|
||||
if (!xdr_pmap3_dump_result (xdrs, objp))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_PMAP3CALLITargs (XDR *xdrs, PMAP3CALLITargs *objp)
|
||||
{
|
||||
|
||||
if (!xdr_pmap3_call_result (xdrs, objp))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_PMAP3CALLITres (XDR *xdrs, PMAP3CALLITres *objp)
|
||||
{
|
||||
|
||||
if (!xdr_pmap3_call_result (xdrs, objp))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_PMAP3UADDR2TADDRres (XDR *xdrs, PMAP3UADDR2TADDRres *objp)
|
||||
{
|
||||
|
||||
if (!xdr_pmap3_netbuf (xdrs, objp))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_PMAP3TADDR2UADDRargs (XDR *xdrs, PMAP3TADDR2UADDRargs *objp)
|
||||
{
|
||||
|
||||
if (!xdr_pmap3_netbuf (xdrs, objp))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_PMAP3TADDR2UADDRres (XDR *xdrs, PMAP3TADDR2UADDRres *objp)
|
||||
{
|
||||
|
||||
if (!xdr_pmap3_string_result (xdrs, objp))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Please do not edit this file.
|
||||
* It was generated using rpcgen.
|
||||
*/
|
||||
|
||||
#ifndef _RPC_H_RPCGEN
|
||||
#define _RPC_H_RPCGEN
|
||||
|
||||
#include "xdr_impl.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define RPC_MSG_VERSION 2
|
||||
|
||||
enum rpc_auth_flavor {
|
||||
RPC_AUTH_NONE = 0,
|
||||
RPC_AUTH_SYS = 1,
|
||||
RPC_AUTH_SHORT = 2,
|
||||
RPC_AUTH_DH = 3,
|
||||
RPC_RPCSEC_GSS = 6,
|
||||
};
|
||||
typedef enum rpc_auth_flavor rpc_auth_flavor;
|
||||
|
||||
enum rpc_msg_type {
|
||||
RPC_CALL = 0,
|
||||
RPC_REPLY = 1,
|
||||
};
|
||||
typedef enum rpc_msg_type rpc_msg_type;
|
||||
|
||||
enum rpc_reply_stat {
|
||||
RPC_MSG_ACCEPTED = 0,
|
||||
RPC_MSG_DENIED = 1,
|
||||
};
|
||||
typedef enum rpc_reply_stat rpc_reply_stat;
|
||||
|
||||
enum rpc_accept_stat {
|
||||
RPC_SUCCESS = 0,
|
||||
RPC_PROG_UNAVAIL = 1,
|
||||
RPC_PROG_MISMATCH = 2,
|
||||
RPC_PROC_UNAVAIL = 3,
|
||||
RPC_GARBAGE_ARGS = 4,
|
||||
RPC_SYSTEM_ERR = 5,
|
||||
};
|
||||
typedef enum rpc_accept_stat rpc_accept_stat;
|
||||
|
||||
enum rpc_reject_stat {
|
||||
RPC_MISMATCH = 0,
|
||||
RPC_AUTH_ERROR = 1,
|
||||
};
|
||||
typedef enum rpc_reject_stat rpc_reject_stat;
|
||||
|
||||
enum rpc_auth_stat {
|
||||
RPC_AUTH_OK = 0,
|
||||
RPC_AUTH_BADCRED = 1,
|
||||
RPC_AUTH_REJECTEDCRED = 2,
|
||||
RPC_AUTH_BADVERF = 3,
|
||||
RPC_AUTH_REJECTEDVERF = 4,
|
||||
RPC_AUTH_TOOWEAK = 5,
|
||||
RPC_AUTH_INVALIDRESP = 6,
|
||||
RPC_AUTH_FAILED = 7,
|
||||
};
|
||||
typedef enum rpc_auth_stat rpc_auth_stat;
|
||||
|
||||
struct rpc_opaque_auth {
|
||||
rpc_auth_flavor flavor;
|
||||
xdr_string_t body;
|
||||
};
|
||||
typedef struct rpc_opaque_auth rpc_opaque_auth;
|
||||
|
||||
struct rpc_call_body {
|
||||
u_int rpcvers;
|
||||
u_int prog;
|
||||
u_int vers;
|
||||
u_int proc;
|
||||
rpc_opaque_auth cred;
|
||||
rpc_opaque_auth verf;
|
||||
};
|
||||
typedef struct rpc_call_body rpc_call_body;
|
||||
|
||||
struct rpc_mismatch_info {
|
||||
u_int min_version;
|
||||
u_int max_version;
|
||||
};
|
||||
typedef struct rpc_mismatch_info rpc_mismatch_info;
|
||||
|
||||
struct rpc_accepted_reply_body {
|
||||
rpc_accept_stat stat;
|
||||
union {
|
||||
rpc_mismatch_info mismatch_info;
|
||||
};
|
||||
};
|
||||
typedef struct rpc_accepted_reply_body rpc_accepted_reply_body;
|
||||
|
||||
struct rpc_accepted_reply {
|
||||
rpc_opaque_auth verf;
|
||||
rpc_accepted_reply_body reply_data;
|
||||
};
|
||||
typedef struct rpc_accepted_reply rpc_accepted_reply;
|
||||
|
||||
struct rpc_rejected_reply {
|
||||
rpc_reject_stat stat;
|
||||
union {
|
||||
rpc_mismatch_info mismatch_info;
|
||||
rpc_auth_stat auth_stat;
|
||||
};
|
||||
};
|
||||
typedef struct rpc_rejected_reply rpc_rejected_reply;
|
||||
|
||||
struct rpc_reply_body {
|
||||
rpc_reply_stat stat;
|
||||
union {
|
||||
rpc_accepted_reply areply;
|
||||
rpc_rejected_reply rreply;
|
||||
};
|
||||
};
|
||||
typedef struct rpc_reply_body rpc_reply_body;
|
||||
|
||||
struct rpc_msg_body {
|
||||
rpc_msg_type dir;
|
||||
union {
|
||||
rpc_call_body cbody;
|
||||
rpc_reply_body rbody;
|
||||
};
|
||||
};
|
||||
typedef struct rpc_msg_body rpc_msg_body;
|
||||
|
||||
struct rpc_msg {
|
||||
u_int xid;
|
||||
rpc_msg_body body;
|
||||
};
|
||||
typedef struct rpc_msg rpc_msg;
|
||||
|
||||
/* the xdr functions */
|
||||
|
||||
|
||||
extern bool_t xdr_rpc_auth_flavor (XDR *, rpc_auth_flavor*);
|
||||
extern bool_t xdr_rpc_msg_type (XDR *, rpc_msg_type*);
|
||||
extern bool_t xdr_rpc_reply_stat (XDR *, rpc_reply_stat*);
|
||||
extern bool_t xdr_rpc_accept_stat (XDR *, rpc_accept_stat*);
|
||||
extern bool_t xdr_rpc_reject_stat (XDR *, rpc_reject_stat*);
|
||||
extern bool_t xdr_rpc_auth_stat (XDR *, rpc_auth_stat*);
|
||||
extern bool_t xdr_rpc_opaque_auth (XDR *, rpc_opaque_auth*);
|
||||
extern bool_t xdr_rpc_call_body (XDR *, rpc_call_body*);
|
||||
extern bool_t xdr_rpc_mismatch_info (XDR *, rpc_mismatch_info*);
|
||||
extern bool_t xdr_rpc_accepted_reply_body (XDR *, rpc_accepted_reply_body*);
|
||||
extern bool_t xdr_rpc_accepted_reply (XDR *, rpc_accepted_reply*);
|
||||
extern bool_t xdr_rpc_rejected_reply (XDR *, rpc_rejected_reply*);
|
||||
extern bool_t xdr_rpc_reply_body (XDR *, rpc_reply_body*);
|
||||
extern bool_t xdr_rpc_msg_body (XDR *, rpc_msg_body*);
|
||||
extern bool_t xdr_rpc_msg (XDR *, rpc_msg*);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_RPC_H_RPCGEN */
|
||||
@@ -0,0 +1,113 @@
|
||||
/* Based on RFC 5531 - RPC: Remote Procedure Call Protocol Specification Version 2 */
|
||||
|
||||
const RPC_MSG_VERSION = 2;
|
||||
|
||||
enum rpc_auth_flavor {
|
||||
RPC_AUTH_NONE = 0,
|
||||
RPC_AUTH_SYS = 1,
|
||||
RPC_AUTH_SHORT = 2,
|
||||
RPC_AUTH_DH = 3,
|
||||
RPC_RPCSEC_GSS = 6
|
||||
};
|
||||
|
||||
enum rpc_msg_type {
|
||||
RPC_CALL = 0,
|
||||
RPC_REPLY = 1
|
||||
};
|
||||
|
||||
enum rpc_reply_stat {
|
||||
RPC_MSG_ACCEPTED = 0,
|
||||
RPC_MSG_DENIED = 1
|
||||
};
|
||||
|
||||
enum rpc_accept_stat {
|
||||
RPC_SUCCESS = 0,
|
||||
RPC_PROG_UNAVAIL = 1,
|
||||
RPC_PROG_MISMATCH = 2,
|
||||
RPC_PROC_UNAVAIL = 3,
|
||||
RPC_GARBAGE_ARGS = 4,
|
||||
RPC_SYSTEM_ERR = 5
|
||||
};
|
||||
|
||||
enum rpc_reject_stat {
|
||||
RPC_MISMATCH = 0,
|
||||
RPC_AUTH_ERROR = 1
|
||||
};
|
||||
|
||||
enum rpc_auth_stat {
|
||||
RPC_AUTH_OK = 0,
|
||||
/*
|
||||
* failed at remote end
|
||||
*/
|
||||
RPC_AUTH_BADCRED = 1, /* bogus credentials (seal broken) */
|
||||
RPC_AUTH_REJECTEDCRED = 2, /* client should begin new session */
|
||||
RPC_AUTH_BADVERF = 3, /* bogus verifier (seal broken) */
|
||||
RPC_AUTH_REJECTEDVERF = 4, /* verifier expired or was replayed */
|
||||
RPC_AUTH_TOOWEAK = 5, /* rejected due to security reasons */
|
||||
/*
|
||||
* failed locally
|
||||
*/
|
||||
RPC_AUTH_INVALIDRESP = 6, /* bogus response verifier */
|
||||
RPC_AUTH_FAILED = 7 /* some unknown reason */
|
||||
};
|
||||
|
||||
struct rpc_opaque_auth {
|
||||
rpc_auth_flavor flavor;
|
||||
opaque body<400>;
|
||||
};
|
||||
|
||||
struct rpc_call_body {
|
||||
u_int rpcvers;
|
||||
u_int prog;
|
||||
u_int vers;
|
||||
u_int proc;
|
||||
rpc_opaque_auth cred;
|
||||
rpc_opaque_auth verf;
|
||||
/* procedure-specific parameters start here */
|
||||
};
|
||||
|
||||
struct rpc_mismatch_info {
|
||||
unsigned int min_version;
|
||||
unsigned int max_version;
|
||||
};
|
||||
|
||||
union rpc_accepted_reply_body switch (rpc_accept_stat stat) {
|
||||
case RPC_SUCCESS:
|
||||
void;
|
||||
/* procedure-specific results start here */
|
||||
case RPC_PROG_MISMATCH:
|
||||
rpc_mismatch_info mismatch_info;
|
||||
default:
|
||||
void;
|
||||
};
|
||||
|
||||
struct rpc_accepted_reply {
|
||||
rpc_opaque_auth verf;
|
||||
rpc_accepted_reply_body reply_data;
|
||||
};
|
||||
|
||||
union rpc_rejected_reply switch (rpc_reject_stat stat) {
|
||||
case RPC_MISMATCH:
|
||||
rpc_mismatch_info mismatch_info;
|
||||
case RPC_AUTH_ERROR:
|
||||
rpc_auth_stat auth_stat;
|
||||
};
|
||||
|
||||
union rpc_reply_body switch (rpc_reply_stat stat) {
|
||||
case RPC_MSG_ACCEPTED:
|
||||
rpc_accepted_reply areply;
|
||||
case RPC_MSG_DENIED:
|
||||
rpc_rejected_reply rreply;
|
||||
};
|
||||
|
||||
union rpc_msg_body switch (rpc_msg_type dir) {
|
||||
case RPC_CALL:
|
||||
rpc_call_body cbody;
|
||||
case RPC_REPLY:
|
||||
rpc_reply_body rbody;
|
||||
};
|
||||
|
||||
struct rpc_msg {
|
||||
u_int xid;
|
||||
rpc_msg_body body;
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include "rpc.h"
|
||||
|
||||
struct rpc_op_t;
|
||||
|
||||
// Handler should return 1 if the request is processed asynchronously
|
||||
// and requires the incoming message to not be freed until processing ends,
|
||||
// 0 otherwise.
|
||||
typedef int (*rpc_handler_t)(void *opaque, rpc_op_t *rop);
|
||||
|
||||
struct rpc_service_proc_t
|
||||
{
|
||||
uint32_t prog;
|
||||
uint32_t vers;
|
||||
uint32_t proc;
|
||||
rpc_handler_t handler_fn;
|
||||
xdrproc_t req_fn;
|
||||
uint32_t req_size;
|
||||
xdrproc_t resp_fn;
|
||||
uint32_t resp_size;
|
||||
void *opaque;
|
||||
};
|
||||
|
||||
inline bool operator < (const rpc_service_proc_t & a, const rpc_service_proc_t & b)
|
||||
{
|
||||
return a.prog < b.prog || a.prog == b.prog && (a.vers < b.vers || a.vers == b.vers && a.proc < b.proc);
|
||||
}
|
||||
|
||||
struct rpc_op_t
|
||||
{
|
||||
void *client;
|
||||
uint8_t *buffer;
|
||||
XDR *xdrs;
|
||||
rpc_msg in_msg, out_msg;
|
||||
void *request;
|
||||
void *reply;
|
||||
xdrproc_t reply_fn;
|
||||
uint32_t reply_marker;
|
||||
bool referenced;
|
||||
};
|
||||
|
||||
void rpc_queue_reply(rpc_op_t *rop);
|
||||
@@ -0,0 +1,253 @@
|
||||
/*
|
||||
* Please do not edit this file.
|
||||
* It was generated using rpcgen.
|
||||
*/
|
||||
|
||||
#include "rpc.h"
|
||||
#include "xdr_impl_inline.h"
|
||||
|
||||
bool_t
|
||||
xdr_rpc_auth_flavor (XDR *xdrs, rpc_auth_flavor *objp)
|
||||
{
|
||||
|
||||
if (!xdr_enum (xdrs, (enum_t *) objp))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_rpc_msg_type (XDR *xdrs, rpc_msg_type *objp)
|
||||
{
|
||||
|
||||
if (!xdr_enum (xdrs, (enum_t *) objp))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_rpc_reply_stat (XDR *xdrs, rpc_reply_stat *objp)
|
||||
{
|
||||
|
||||
if (!xdr_enum (xdrs, (enum_t *) objp))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_rpc_accept_stat (XDR *xdrs, rpc_accept_stat *objp)
|
||||
{
|
||||
|
||||
if (!xdr_enum (xdrs, (enum_t *) objp))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_rpc_reject_stat (XDR *xdrs, rpc_reject_stat *objp)
|
||||
{
|
||||
|
||||
if (!xdr_enum (xdrs, (enum_t *) objp))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_rpc_auth_stat (XDR *xdrs, rpc_auth_stat *objp)
|
||||
{
|
||||
|
||||
if (!xdr_enum (xdrs, (enum_t *) objp))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_rpc_opaque_auth (XDR *xdrs, rpc_opaque_auth *objp)
|
||||
{
|
||||
|
||||
if (!xdr_rpc_auth_flavor (xdrs, &objp->flavor))
|
||||
return FALSE;
|
||||
if (!xdr_bytes(xdrs, &objp->body, 400))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_rpc_call_body (XDR *xdrs, rpc_call_body *objp)
|
||||
{
|
||||
|
||||
|
||||
if (xdrs->x_op == XDR_ENCODE) {
|
||||
if (1) {
|
||||
if (!xdr_u_int (xdrs, &objp->rpcvers))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->prog))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->vers))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->proc))
|
||||
return FALSE;
|
||||
|
||||
} else {
|
||||
IXDR_PUT_U_LONG(buf, objp->rpcvers);
|
||||
IXDR_PUT_U_LONG(buf, objp->prog);
|
||||
IXDR_PUT_U_LONG(buf, objp->vers);
|
||||
IXDR_PUT_U_LONG(buf, objp->proc);
|
||||
}
|
||||
if (!xdr_rpc_opaque_auth (xdrs, &objp->cred))
|
||||
return FALSE;
|
||||
if (!xdr_rpc_opaque_auth (xdrs, &objp->verf))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
} else if (xdrs->x_op == XDR_DECODE) {
|
||||
if (1) {
|
||||
if (!xdr_u_int (xdrs, &objp->rpcvers))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->prog))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->vers))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->proc))
|
||||
return FALSE;
|
||||
|
||||
} else {
|
||||
objp->rpcvers = IXDR_GET_U_LONG(buf);
|
||||
objp->prog = IXDR_GET_U_LONG(buf);
|
||||
objp->vers = IXDR_GET_U_LONG(buf);
|
||||
objp->proc = IXDR_GET_U_LONG(buf);
|
||||
}
|
||||
if (!xdr_rpc_opaque_auth (xdrs, &objp->cred))
|
||||
return FALSE;
|
||||
if (!xdr_rpc_opaque_auth (xdrs, &objp->verf))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (!xdr_u_int (xdrs, &objp->rpcvers))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->prog))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->vers))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->proc))
|
||||
return FALSE;
|
||||
if (!xdr_rpc_opaque_auth (xdrs, &objp->cred))
|
||||
return FALSE;
|
||||
if (!xdr_rpc_opaque_auth (xdrs, &objp->verf))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_rpc_mismatch_info (XDR *xdrs, rpc_mismatch_info *objp)
|
||||
{
|
||||
|
||||
if (!xdr_u_int (xdrs, &objp->min_version))
|
||||
return FALSE;
|
||||
if (!xdr_u_int (xdrs, &objp->max_version))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_rpc_accepted_reply_body (XDR *xdrs, rpc_accepted_reply_body *objp)
|
||||
{
|
||||
|
||||
if (!xdr_rpc_accept_stat (xdrs, &objp->stat))
|
||||
return FALSE;
|
||||
switch (objp->stat) {
|
||||
case RPC_SUCCESS:
|
||||
break;
|
||||
case RPC_PROG_MISMATCH:
|
||||
if (!xdr_rpc_mismatch_info (xdrs, &objp->mismatch_info))
|
||||
return FALSE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_rpc_accepted_reply (XDR *xdrs, rpc_accepted_reply *objp)
|
||||
{
|
||||
|
||||
if (!xdr_rpc_opaque_auth (xdrs, &objp->verf))
|
||||
return FALSE;
|
||||
if (!xdr_rpc_accepted_reply_body (xdrs, &objp->reply_data))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_rpc_rejected_reply (XDR *xdrs, rpc_rejected_reply *objp)
|
||||
{
|
||||
|
||||
if (!xdr_rpc_reject_stat (xdrs, &objp->stat))
|
||||
return FALSE;
|
||||
switch (objp->stat) {
|
||||
case RPC_MISMATCH:
|
||||
if (!xdr_rpc_mismatch_info (xdrs, &objp->mismatch_info))
|
||||
return FALSE;
|
||||
break;
|
||||
case RPC_AUTH_ERROR:
|
||||
if (!xdr_rpc_auth_stat (xdrs, &objp->auth_stat))
|
||||
return FALSE;
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_rpc_reply_body (XDR *xdrs, rpc_reply_body *objp)
|
||||
{
|
||||
|
||||
if (!xdr_rpc_reply_stat (xdrs, &objp->stat))
|
||||
return FALSE;
|
||||
switch (objp->stat) {
|
||||
case RPC_MSG_ACCEPTED:
|
||||
if (!xdr_rpc_accepted_reply (xdrs, &objp->areply))
|
||||
return FALSE;
|
||||
break;
|
||||
case RPC_MSG_DENIED:
|
||||
if (!xdr_rpc_rejected_reply (xdrs, &objp->rreply))
|
||||
return FALSE;
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_rpc_msg_body (XDR *xdrs, rpc_msg_body *objp)
|
||||
{
|
||||
|
||||
if (!xdr_rpc_msg_type (xdrs, &objp->dir))
|
||||
return FALSE;
|
||||
switch (objp->dir) {
|
||||
case RPC_CALL:
|
||||
if (!xdr_rpc_call_body (xdrs, &objp->cbody))
|
||||
return FALSE;
|
||||
break;
|
||||
case RPC_REPLY:
|
||||
if (!xdr_rpc_reply_body (xdrs, &objp->rbody))
|
||||
return FALSE;
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_rpc_msg (XDR *xdrs, rpc_msg *objp)
|
||||
{
|
||||
|
||||
if (!xdr_u_int (xdrs, &objp->xid))
|
||||
return FALSE;
|
||||
if (!xdr_rpc_msg_body (xdrs, &objp->body))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# 1) remove all extern non-xdr functions (service, client)
|
||||
# 2) use xdr_string_t for strings instead of char*
|
||||
# 3) remove K&R #ifdefs
|
||||
# 4) remove register int32_t* buf
|
||||
# 5) remove union names
|
||||
# 6) use xdr_string_t for opaques instead of u_int + char*
|
||||
# 7) TODO: generate normal procedure stubs
|
||||
run_rpcgen() {
|
||||
rpcgen -h $1.x | \
|
||||
perl -e '
|
||||
{ local $/ = undef; $_ = <>; }
|
||||
s/^extern(?!.*"C"|.*bool_t xdr.*XDR).*\n//gm;
|
||||
s/#include <rpc\/rpc.h>/#include "xdr_impl.h"/;
|
||||
s/^typedef char \*/typedef xdr_string_t /gm;
|
||||
s/^(\s*)char \*(?!.*_val)/$1xdr_string_t /gm;
|
||||
# remove union names
|
||||
s/ \w+_u;/;/gs;
|
||||
# use xdr_string_t for opaques
|
||||
s/struct\s*\{\s*u_int\s+\w+_len;\s*char\s+\*\w+_val;\s*\}\s*/xdr_string_t /gs;
|
||||
# remove stdc/k&r
|
||||
s/^#if.*__STDC__.*//gm;
|
||||
s/\n#else[^\n]*K&R.*?\n#endif[^\n]*K&R[^\n]*//gs;
|
||||
print;' > $1.h
|
||||
rpcgen -c $1.x | \
|
||||
perl -pe '
|
||||
s/register int32_t \*buf;\s*//g;
|
||||
s/\bbuf\s*=[^;]+;\s*//g;
|
||||
s/\bbuf\s*==\s*NULL/1/g;
|
||||
# remove union names
|
||||
s/(\.|->)\w+_u\./$1/g;
|
||||
# use xdr_string_t for opaques
|
||||
# xdr_bytes(xdrs, (char**)&objp->data.data_val, (char**)&objp->data.data_len, 400)
|
||||
# -> xdr_bytes(xdrs, &objp->data, 400)
|
||||
# xdr_bytes(xdrs, (char**)&objp->data_val, (char**)&objp->data_len, 400)
|
||||
# -> xdr_bytes(xdrs, objp, 400)
|
||||
s/xdr_bytes\s*\(\s*xdrs,\s*\(\s*char\s*\*\*\s*\)\s*([^()]+?)\.\w+_val\s*,\s*\(\s*u_int\s*\*\s*\)\s*\1\.\w+_len,/xdr_bytes(xdrs, $1,/gs;
|
||||
s/xdr_bytes\s*\(\s*xdrs,\s*\(\s*char\s*\*\*\s*\)\s*&\s*([^()]+?)->\w+_val\s*,\s*\(\s*u_int\s*\*\s*\)\s*&\s*\1->\w+_len,/xdr_bytes(xdrs, $1,/gs;
|
||||
# add include
|
||||
if (/#include/) { $_ .= "#include \"xdr_impl_inline.h\"\n"; }' > ${1}_xdr.cpp
|
||||
}
|
||||
|
||||
run_rpcgen nfs
|
||||
run_rpcgen rpc
|
||||
run_rpcgen portmap
|
||||
@@ -0,0 +1,107 @@
|
||||
// Copyright (c) Vitaliy Filippov, 2019+
|
||||
// License: VNPL-1.1 (see README.md for details)
|
||||
//
|
||||
// Efficient XDR implementation almost compatible with rpcgen (see run-rpcgen.sh)
|
||||
|
||||
#include "xdr_impl_inline.h"
|
||||
|
||||
XDR* xdr_create()
|
||||
{
|
||||
return new XDR;
|
||||
}
|
||||
|
||||
void xdr_destroy(XDR* xdrs)
|
||||
{
|
||||
xdr_reset(xdrs);
|
||||
delete xdrs;
|
||||
}
|
||||
|
||||
void xdr_reset(XDR *xdrs)
|
||||
{
|
||||
for (auto buf: xdrs->allocs)
|
||||
{
|
||||
free(buf);
|
||||
}
|
||||
xdrs->buf = NULL;
|
||||
xdrs->avail = 0;
|
||||
xdrs->allocs.resize(0);
|
||||
xdrs->in_linked_list.resize(0);
|
||||
xdrs->cur_out.resize(0);
|
||||
xdrs->last_end = 0;
|
||||
xdrs->buf_list.resize(0);
|
||||
}
|
||||
|
||||
int xdr_decode(XDR *xdrs, void *buf, unsigned size, xdrproc_t fn, void *data)
|
||||
{
|
||||
xdrs->x_op = XDR_DECODE;
|
||||
xdrs->buf = (uint8_t*)buf;
|
||||
xdrs->avail = size;
|
||||
return fn(xdrs, data);
|
||||
}
|
||||
|
||||
int xdr_encode(XDR *xdrs, xdrproc_t fn, void *data)
|
||||
{
|
||||
xdrs->x_op = XDR_ENCODE;
|
||||
return fn(xdrs, data);
|
||||
}
|
||||
|
||||
void xdr_encode_finish(XDR *xdrs, iovec **iov_list, unsigned *iov_count)
|
||||
{
|
||||
if (xdrs->last_end < xdrs->cur_out.size())
|
||||
{
|
||||
xdrs->buf_list.push_back((iovec){
|
||||
.iov_base = 0,
|
||||
.iov_len = xdrs->cur_out.size() - xdrs->last_end,
|
||||
});
|
||||
xdrs->last_end = xdrs->cur_out.size();
|
||||
}
|
||||
uint8_t *cur_buf = xdrs->cur_out.data();
|
||||
for (auto & buf: xdrs->buf_list)
|
||||
{
|
||||
if (!buf.iov_base)
|
||||
{
|
||||
buf.iov_base = cur_buf;
|
||||
cur_buf += buf.iov_len;
|
||||
}
|
||||
}
|
||||
*iov_list = xdrs->buf_list.data();
|
||||
*iov_count = xdrs->buf_list.size();
|
||||
}
|
||||
|
||||
void xdr_dump_encoded(XDR *xdrs)
|
||||
{
|
||||
for (auto & buf: xdrs->buf_list)
|
||||
{
|
||||
for (int i = 0; i < buf.iov_len; i++)
|
||||
printf("%02x", ((uint8_t*)buf.iov_base)[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void xdr_add_malloc(XDR *xdrs, void *buf)
|
||||
{
|
||||
xdrs->allocs.push_back(buf);
|
||||
}
|
||||
|
||||
xdr_string_t xdr_copy_string(XDR *xdrs, const std::string & str)
|
||||
{
|
||||
char *cp = (char*)malloc_or_die(str.size()+1);
|
||||
memcpy(cp, str.data(), str.size());
|
||||
cp[str.size()] = 0;
|
||||
xdr_add_malloc(xdrs, cp);
|
||||
return (xdr_string_t){ str.size(), cp };
|
||||
}
|
||||
|
||||
xdr_string_t xdr_copy_string(XDR *xdrs, const char *str)
|
||||
{
|
||||
return xdr_copy_string(xdrs, str, strlen(str));
|
||||
}
|
||||
|
||||
xdr_string_t xdr_copy_string(XDR *xdrs, const char *str, size_t len)
|
||||
{
|
||||
char *cp = (char*)malloc_or_die(len+1);
|
||||
memcpy(cp, str, len);
|
||||
cp[len] = 0;
|
||||
xdr_add_malloc(xdrs, cp);
|
||||
return (xdr_string_t){ len, cp };
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
// Copyright (c) Vitaliy Filippov, 2019+
|
||||
// License: VNPL-1.1 (see README.md for details)
|
||||
//
|
||||
// Efficient XDR implementation almost compatible with rpcgen (see run-rpcgen.sh)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sys/uio.h>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
#define XDR_COPY_LENGTH 128
|
||||
|
||||
struct xdr_string_t
|
||||
{
|
||||
size_t size;
|
||||
char *data;
|
||||
|
||||
operator std::string()
|
||||
{
|
||||
return std::string(data, size);
|
||||
}
|
||||
|
||||
bool operator == (const char *str)
|
||||
{
|
||||
if (!str)
|
||||
return false;
|
||||
int i;
|
||||
for (i = 0; i < size; i++)
|
||||
if (!str[i] || str[i] != data[i])
|
||||
return false;
|
||||
if (str[i])
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator != (const char *str)
|
||||
{
|
||||
return !(*this == str);
|
||||
}
|
||||
};
|
||||
|
||||
typedef uint32_t u_int;
|
||||
typedef uint32_t enum_t;
|
||||
typedef uint32_t bool_t;
|
||||
struct XDR;
|
||||
typedef int (*xdrproc_t)(XDR *xdrs, void *data);
|
||||
|
||||
// Create an empty XDR object
|
||||
XDR* xdr_create();
|
||||
|
||||
// Destroy the XDR object
|
||||
void xdr_destroy(XDR* xdrs);
|
||||
|
||||
// Free resources from any previous xdr_decode/xdr_encode calls
|
||||
void xdr_reset(XDR *xdrs);
|
||||
|
||||
// Try to decode <size> bytes from buffer <buf> using <fn>
|
||||
// Result may contain memory allocations that will be valid until the next call to xdr_{reset,destroy,decode,encode}
|
||||
int xdr_decode(XDR *xdrs, void *buf, unsigned size, xdrproc_t fn, void *data);
|
||||
|
||||
// Try to encode <data> using <fn>
|
||||
// May be mixed with xdr_decode
|
||||
// May be called multiple times to encode multiple parts of the same message
|
||||
int xdr_encode(XDR *xdrs, xdrproc_t fn, void *data);
|
||||
|
||||
// Get the result of previous xdr_encodes as a list of <struct iovec>'s
|
||||
// in <iov_list> (start) and <iov_count> (count).
|
||||
// The resulting iov_list is valid until the next call to xdr_{reset,destroy}.
|
||||
// It may contain references to the original data, so original data must not
|
||||
// be freed until the result is fully processed (sent).
|
||||
void xdr_encode_finish(XDR *xdrs, iovec **iov_list, unsigned *iov_count);
|
||||
|
||||
// Remember an allocated buffer to free it later on xdr_reset() or xdr_destroy()
|
||||
void xdr_add_malloc(XDR *xdrs, void *buf);
|
||||
|
||||
xdr_string_t xdr_copy_string(XDR *xdrs, const std::string & str);
|
||||
|
||||
xdr_string_t xdr_copy_string(XDR *xdrs, const char *str);
|
||||
|
||||
xdr_string_t xdr_copy_string(XDR *xdrs, const char *str, size_t len);
|
||||
|
||||
void xdr_dump_encoded(XDR *xdrs);
|
||||
@@ -0,0 +1,309 @@
|
||||
// Copyright (c) Vitaliy Filippov, 2019+
|
||||
// License: VNPL-1.1 (see README.md for details)
|
||||
//
|
||||
// Efficient XDR implementation almost compatible with rpcgen (see run-rpcgen.sh)
|
||||
|
||||
// XDR in a nutshell:
|
||||
//
|
||||
// int: big endian 32bit
|
||||
// unsigned: BE 32bit
|
||||
// enum: BE 32bit
|
||||
// bool: BE 32bit 0/1
|
||||
// hyper: BE 64bit
|
||||
// unsigned hyper: BE 64bit
|
||||
// float: BE float
|
||||
// double: BE double
|
||||
// quadruple: BE long double
|
||||
// opaque[n] (fixed-length): bytes, padded to !(n%4)
|
||||
// opaque (variable-length): BE 32bit length, then n bytes, padded to !(n%4)
|
||||
// string: same as opaque
|
||||
// array<T>[n] (fixed-length): n items of type T
|
||||
// vector<T> (variable-length): BE 32bit length, then n items of type T
|
||||
// struct: components in the same order as specified
|
||||
// union: BE 32bit variant id, then variant of the union
|
||||
// void: nothing (empty, 0 byte data)
|
||||
// optional (XDR T*): BE 32bit 1/0, then T or nothing
|
||||
// linked list: sequence of optional entries
|
||||
//
|
||||
// RPC over TCP:
|
||||
//
|
||||
// BE 32bit length, then rpc_msg, then the procedure message itself
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "xdr_impl.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <endian.h>
|
||||
#include <vector>
|
||||
|
||||
#include "malloc_or_die.h"
|
||||
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
#define XDR_ENCODE 0
|
||||
#define XDR_DECODE 1
|
||||
#define BYTES_PER_XDR_UNIT 4
|
||||
#define IXDR_PUT_U_LONG(a, b)
|
||||
#define IXDR_GET_U_LONG(a) 0
|
||||
#define IXDR_PUT_BOOL(a, b)
|
||||
#define IXDR_GET_BOOL(a) 0
|
||||
#define XDR_INLINE(xdrs, len) NULL
|
||||
|
||||
struct xdr_linked_list_t
|
||||
{
|
||||
xdrproc_t fn;
|
||||
unsigned entry_size, size, cap;
|
||||
void *base;
|
||||
unsigned has_next, link_offset;
|
||||
};
|
||||
|
||||
struct XDR
|
||||
{
|
||||
int x_op;
|
||||
|
||||
// For decoding:
|
||||
uint8_t *buf = NULL;
|
||||
unsigned avail = 0;
|
||||
std::vector<void*> allocs;
|
||||
std::vector<xdr_linked_list_t> in_linked_list;
|
||||
|
||||
// For encoding:
|
||||
std::vector<uint8_t> cur_out;
|
||||
unsigned last_end = 0;
|
||||
std::vector<iovec> buf_list;
|
||||
};
|
||||
|
||||
uint32_t inline len_pad4(uint32_t len)
|
||||
{
|
||||
return ((len+3)/4) * 4;
|
||||
}
|
||||
|
||||
inline int xdr_opaque(XDR *xdrs, void *data, uint32_t len)
|
||||
{
|
||||
if (len <= 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (xdrs->x_op == XDR_DECODE)
|
||||
{
|
||||
uint32_t padded = len_pad4(len);
|
||||
if (xdrs->avail < padded)
|
||||
return 0;
|
||||
memcpy(data, xdrs->buf, len);
|
||||
xdrs->buf += padded;
|
||||
xdrs->avail -= padded;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned old = xdrs->cur_out.size();
|
||||
uint32_t pad = (len & 3) ? (4 - (len & 3)) : 0;
|
||||
xdrs->cur_out.resize(old + len + pad);
|
||||
memcpy(xdrs->cur_out.data()+old, data, len);
|
||||
for (uint32_t i = 0; i < pad; i++)
|
||||
xdrs->cur_out[old+i] = 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int xdr_bytes(XDR *xdrs, xdr_string_t *data, uint32_t maxlen)
|
||||
{
|
||||
if (xdrs->x_op == XDR_DECODE)
|
||||
{
|
||||
if (xdrs->avail < 4)
|
||||
return 0;
|
||||
uint32_t len = be32toh(*((uint32_t*)xdrs->buf));
|
||||
uint32_t padded = len_pad4(len);
|
||||
if (xdrs->avail < 4+padded)
|
||||
return 0;
|
||||
data->size = len;
|
||||
data->data = (char*)(xdrs->buf+4);
|
||||
xdrs->buf += 4+padded;
|
||||
xdrs->avail -= 4+padded;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (data->size < XDR_COPY_LENGTH)
|
||||
{
|
||||
unsigned old = xdrs->cur_out.size();
|
||||
xdrs->cur_out.resize(old + 4+data->size);
|
||||
*(uint32_t*)(xdrs->cur_out.data() + old) = htobe32(data->size);
|
||||
memcpy(xdrs->cur_out.data()+old+4, data->data, data->size);
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned old = xdrs->cur_out.size();
|
||||
xdrs->cur_out.resize(old + 4);
|
||||
*(uint32_t*)(xdrs->cur_out.data() + old) = htobe32(data->size);
|
||||
xdrs->buf_list.push_back((iovec){
|
||||
.iov_base = 0,
|
||||
.iov_len = xdrs->cur_out.size() - xdrs->last_end,
|
||||
});
|
||||
xdrs->last_end = xdrs->cur_out.size();
|
||||
xdrs->buf_list.push_back((iovec)
|
||||
{
|
||||
.iov_base = (void*)data->data,
|
||||
.iov_len = data->size,
|
||||
});
|
||||
}
|
||||
if (data->size & 3)
|
||||
{
|
||||
int pad = 4-(data->size & 3);
|
||||
unsigned old = xdrs->cur_out.size();
|
||||
xdrs->cur_out.resize(old+pad);
|
||||
for (int i = 0; i < pad; i++)
|
||||
xdrs->cur_out[old+i] = 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int xdr_string(XDR *xdrs, xdr_string_t *data, uint32_t maxlen)
|
||||
{
|
||||
return xdr_bytes(xdrs, data, maxlen);
|
||||
}
|
||||
|
||||
inline int xdr_u_int(XDR *xdrs, void *data)
|
||||
{
|
||||
if (xdrs->x_op == XDR_DECODE)
|
||||
{
|
||||
if (xdrs->avail < 4)
|
||||
return 0;
|
||||
*((uint32_t*)data) = be32toh(*((uint32_t*)xdrs->buf));
|
||||
xdrs->buf += 4;
|
||||
xdrs->avail -= 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned old = xdrs->cur_out.size();
|
||||
xdrs->cur_out.resize(old + 4);
|
||||
*(uint32_t*)(xdrs->cur_out.data() + old) = htobe32(*(uint32_t*)data);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int xdr_enum(XDR *xdrs, void *data)
|
||||
{
|
||||
return xdr_u_int(xdrs, data);
|
||||
}
|
||||
|
||||
inline int xdr_bool(XDR *xdrs, void *data)
|
||||
{
|
||||
return xdr_u_int(xdrs, data);
|
||||
}
|
||||
|
||||
inline int xdr_uint64_t(XDR *xdrs, void *data)
|
||||
{
|
||||
if (xdrs->x_op == XDR_DECODE)
|
||||
{
|
||||
if (xdrs->avail < 8)
|
||||
return 0;
|
||||
*((uint64_t*)data) = be64toh(*((uint64_t*)xdrs->buf));
|
||||
xdrs->buf += 8;
|
||||
xdrs->avail -= 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned old = xdrs->cur_out.size();
|
||||
xdrs->cur_out.resize(old + 8);
|
||||
*(uint64_t*)(xdrs->cur_out.data() + old) = htobe64(*(uint64_t*)data);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Parse inconvenient shitty linked lists as arrays
|
||||
inline int xdr_pointer(XDR *xdrs, char **data, unsigned entry_size, xdrproc_t entry_fn)
|
||||
{
|
||||
if (xdrs->x_op == XDR_DECODE)
|
||||
{
|
||||
if (xdrs->avail < 4)
|
||||
return 0;
|
||||
uint32_t has_next = be32toh(*((uint32_t*)xdrs->buf));
|
||||
xdrs->buf += 4;
|
||||
xdrs->avail -= 4;
|
||||
*data = NULL;
|
||||
if (!xdrs->in_linked_list.size() ||
|
||||
xdrs->in_linked_list.back().fn != entry_fn)
|
||||
{
|
||||
if (has_next)
|
||||
{
|
||||
unsigned cap = 2;
|
||||
void *base = malloc_or_die(entry_size * cap);
|
||||
xdrs->in_linked_list.push_back((xdr_linked_list_t){
|
||||
.fn = entry_fn,
|
||||
.entry_size = entry_size,
|
||||
.size = 1,
|
||||
.cap = cap,
|
||||
.base = base,
|
||||
.has_next = 0,
|
||||
.link_offset = 0,
|
||||
});
|
||||
*data = (char*)base;
|
||||
if (!entry_fn(xdrs, base))
|
||||
return 0;
|
||||
auto & ll = xdrs->in_linked_list.back();
|
||||
while (ll.has_next)
|
||||
{
|
||||
ll.has_next = 0;
|
||||
if (ll.size >= ll.cap)
|
||||
{
|
||||
ll.cap *= 2;
|
||||
ll.base = realloc_or_die(ll.base, ll.entry_size * ll.cap);
|
||||
}
|
||||
if (!entry_fn(xdrs, (uint8_t*)ll.base + ll.entry_size*ll.size))
|
||||
return 0;
|
||||
ll.size++;
|
||||
}
|
||||
for (unsigned i = 0; i < ll.size-1; i++)
|
||||
{
|
||||
*(void**)((uint8_t*)ll.base + i*ll.entry_size + ll.link_offset) =
|
||||
(uint8_t*)ll.base + (i+1)*ll.entry_size;
|
||||
}
|
||||
xdrs->allocs.push_back(ll.base);
|
||||
xdrs->in_linked_list.pop_back();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto & ll = xdrs->in_linked_list.back();
|
||||
xdrs->in_linked_list.back().has_next = has_next;
|
||||
xdrs->in_linked_list.back().link_offset = (uint8_t*)data - (uint8_t*)ll.base - ll.entry_size*ll.size;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned old = xdrs->cur_out.size();
|
||||
xdrs->cur_out.resize(old + 4);
|
||||
*(uint32_t*)(xdrs->cur_out.data() + old) = htobe32(*data ? 1 : 0);
|
||||
if (*data)
|
||||
entry_fn(xdrs, *data);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int xdr_array(XDR *xdrs, char **data, uint32_t* len, uint32_t maxlen, uint32_t entry_size, xdrproc_t fn)
|
||||
{
|
||||
if (xdrs->x_op == XDR_DECODE)
|
||||
{
|
||||
if (xdrs->avail < 4)
|
||||
return 0;
|
||||
*len = be32toh(*((uint32_t*)xdrs->buf));
|
||||
if (*len > maxlen)
|
||||
return 0;
|
||||
xdrs->buf += 4;
|
||||
xdrs->avail -= 4;
|
||||
*data = (char*)malloc_or_die(entry_size * (*len));
|
||||
for (uint32_t i = 0; i < *len; i++)
|
||||
fn(xdrs, *data + entry_size*i);
|
||||
xdrs->allocs.push_back(*data);
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned old = xdrs->cur_out.size();
|
||||
xdrs->cur_out.resize(old + 4);
|
||||
*(uint32_t*)(xdrs->cur_out.data() + old) = htobe32(*len);
|
||||
for (uint32_t i = 0; i < *len; i++)
|
||||
fn(xdrs, *data + entry_size*i);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user