/*
 * Please do not edit this file.
 * It was generated using rpcgen.
 */

#ifndef _DTN_TYPES_H_RPCGEN
#define _DTN_TYPES_H_RPCGEN

#include <rpc/rpc.h>


#ifdef __cplusplus
extern "C" {
#endif

/*
 * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
 * By downloading, copying, installing or using the software you agree
 * to this license. If you do not agree to this license, do not
 * download, install, copy or use the software.
 * 
 * Intel Open Source License 
 * 
 * Copyright (c) 2004 Intel Corporation. All rights reserved. 
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 
 *   Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 * 
 *   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.
 * 
 *   Neither the name of the Intel Corporation nor the names of its
 *   contributors may be used to endorse or promote products derived
 *   from * this software without specific prior written permission.
 *  
 * 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
 * INTEL OR ITS 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.
 */

/**********************************
 * This file defines the types used in the DTN client API. The structures are
 * autogenerated using rpcgen, as are the marshalling and unmarshalling
 * XDR routines.
 */

#include <limits.h>
#ifndef ARG_MAX
#define ARG_MAX _POSIX_ARG_MAX
#endif

#include <rpc/rpc.h>


/**********************************
 * Constants.
 * (Note that we use #defines to get the comments as well)
 */
#define DTN_MAX_ENDPOINT_ID 256 /* max endpoint_id size (bytes) */
#define DTN_MAX_PATH_LEN PATH_MAX /* max path length */
#define DTN_MAX_EXEC_LEN ARG_MAX /* length of string passed to exec() */
#define DTN_MAX_AUTHDATA 1024 /* length of auth/security data*/
#define DTN_MAX_REGION_LEN 64 /* 64 chars "should" be long enough */
#define DTN_MAX_BUNDLE_MEM 50000 /* biggest in-memory bundle is ~50K*/

/**
 * Specification of a dtn endpoint id, i.e. a URI, implemented as a
 * fixed-length char buffer. Note that for efficiency reasons, this
 * fixed length is relatively small (256 bytes). 
 * 
 * The alternative is to use the opaque XDR type but then all endpoint
 * ids would require malloc / free which is more prone to leaks / bugs.
 */

struct dtn_endpoint_id_t {
	char uri[DTN_MAX_ENDPOINT_ID];
};
typedef struct dtn_endpoint_id_t dtn_endpoint_id_t;

/**
 * A registration cookie.
 */

typedef u_int dtn_reg_id_t;

/**
 * DTN timeouts are specified in seconds.
 */

typedef u_int dtn_timeval_t;

/**
 * Specification of a service tag used in building a local endpoint
 * identifier.
 * 
 * Note that the application cannot (in general) expect to be able to
 * use the full DTN_MAX_ENDPOINT_ID, as there is a chance of overflow
 * when the daemon concats the tag with its own local endpoint id.
 */

struct dtn_service_tag_t {
	char tag[DTN_MAX_ENDPOINT_ID];
};
typedef struct dtn_service_tag_t dtn_service_tag_t;

/**
 * Value for an unspecified registration cookie (i.e. indication that
 * the daemon should allocate a new unique id).
 */
#define DTN_REGID_NONE 0

/**
 * Registration delivery failure actions
 *     DTN_REG_DROP   - drop bundle if registration not active
 *     DTN_REG_DEFER  - spool bundle for later retrieval
 *     DTN_REG_EXEC   - exec program on bundle arrival
 */

enum dtn_reg_failure_action_t {
	DTN_REG_DROP = 1,
	DTN_REG_DEFER = 2,
	DTN_REG_EXEC = 3,
};
typedef enum dtn_reg_failure_action_t dtn_reg_failure_action_t;

/**
 * Registration state.
 */

struct dtn_reg_info_t {
	dtn_endpoint_id_t endpoint;
	dtn_reg_id_t regid;
	dtn_reg_failure_action_t failure_action;
	dtn_timeval_t expiration;
	struct {
		u_int script_len;
		char *script_val;
	} script;
};
typedef struct dtn_reg_info_t dtn_reg_info_t;

/**
 * Bundle priority specifier.
 *     COS_BULK      - lowest priority
 *     COS_NORMAL    - regular priority
 *     COS_EXPEDITED - important
 *     COS_RESERVED  - TBD
 */

enum dtn_bundle_priority_t {
	COS_BULK = 0,
	COS_NORMAL = 1,
	COS_EXPEDITED = 2,
	COS_RESERVED = 3,
};
typedef enum dtn_bundle_priority_t dtn_bundle_priority_t;

/**
 * Bundle delivery option flags. Note that multiple options
 * may be selected for a given bundle.
 *     
 *     DOPTS_NONE           - no custody, etc
 *     DOPTS_CUSTODY        - custody xfer
 *     DOPTS_DELIVERY_RCPT  - end to end delivery (i.e. return receipt)
 *     DOPTS_RECEIVE_RCPT   - per hop arrival receipt
 *     DOPTS_FORWARD_RCPT   - per hop departure receipt
 *     DOPTS_CUSTODY_RCPT   - per custodian receipt
 *     DOPTS_DELETE_RCPT    - request deletion receipt
 */

enum dtn_bundle_delivery_opts_t {
	DOPTS_NONE = 0,
	DOPTS_CUSTODY = 1,
	DOPTS_DELIVERY_RCPT = 2,
	DOPTS_RECEIVE_RCPT = 4,
	DOPTS_FORWARD_RCPT = 8,
	DOPTS_CUSTODY_RCPT = 16,
	DOPTS_DELETE_RCPT = 32,
};
typedef enum dtn_bundle_delivery_opts_t dtn_bundle_delivery_opts_t;

/**
 * Bundle metadata.
 */

struct dtn_bundle_spec_t {
	dtn_endpoint_id_t source;
	dtn_endpoint_id_t dest;
	dtn_endpoint_id_t replyto;
	dtn_bundle_priority_t priority;
	int dopts;
	dtn_timeval_t expiration;
};
typedef struct dtn_bundle_spec_t dtn_bundle_spec_t;

/**
 * The payload of a bundle can be sent or received either in a file,
 * in which case the payload structure contains the filename, or in
 * memory where the struct has the actual data.
 *
 * Note that there is a limit (DTN_PAYLOAD_MEM) on the maximum size
 * bundle payload that can be sent or received in memory.
 */

enum dtn_bundle_payload_location_t {
	DTN_PAYLOAD_FILE = 0,
	DTN_PAYLOAD_MEM = 1,
};
typedef enum dtn_bundle_payload_location_t dtn_bundle_payload_location_t;

struct dtn_bundle_payload_t {
	dtn_bundle_payload_location_t location;
	union {
		struct {
			u_int filename_len;
			char *filename_val;
		} filename;
		struct {
			u_int buf_len;
			char *buf_val;
		} buf;
	} dtn_bundle_payload_t_u;
};
typedef struct dtn_bundle_payload_t dtn_bundle_payload_t;

/**
 * Bundle authentication data. TBD
 */

struct dtn_bundle_auth_t {
	struct {
		u_int blob_len;
		char *blob_val;
	} blob;
};
typedef struct dtn_bundle_auth_t dtn_bundle_auth_t;

/* the xdr functions */

#if defined(__STDC__) || defined(__cplusplus)
extern  bool_t xdr_dtn_endpoint_id_t (XDR *, dtn_endpoint_id_t*);
extern  bool_t xdr_dtn_reg_id_t (XDR *, dtn_reg_id_t*);
extern  bool_t xdr_dtn_timeval_t (XDR *, dtn_timeval_t*);
extern  bool_t xdr_dtn_service_tag_t (XDR *, dtn_service_tag_t*);
extern  bool_t xdr_dtn_reg_failure_action_t (XDR *, dtn_reg_failure_action_t*);
extern  bool_t xdr_dtn_reg_info_t (XDR *, dtn_reg_info_t*);
extern  bool_t xdr_dtn_bundle_priority_t (XDR *, dtn_bundle_priority_t*);
extern  bool_t xdr_dtn_bundle_delivery_opts_t (XDR *, dtn_bundle_delivery_opts_t*);
extern  bool_t xdr_dtn_bundle_spec_t (XDR *, dtn_bundle_spec_t*);
extern  bool_t xdr_dtn_bundle_payload_location_t (XDR *, dtn_bundle_payload_location_t*);
extern  bool_t xdr_dtn_bundle_payload_t (XDR *, dtn_bundle_payload_t*);
extern  bool_t xdr_dtn_bundle_auth_t (XDR *, dtn_bundle_auth_t*);

#else /* K&R C */
extern bool_t xdr_dtn_endpoint_id_t ();
extern bool_t xdr_dtn_reg_id_t ();
extern bool_t xdr_dtn_timeval_t ();
extern bool_t xdr_dtn_service_tag_t ();
extern bool_t xdr_dtn_reg_failure_action_t ();
extern bool_t xdr_dtn_reg_info_t ();
extern bool_t xdr_dtn_bundle_priority_t ();
extern bool_t xdr_dtn_bundle_delivery_opts_t ();
extern bool_t xdr_dtn_bundle_spec_t ();
extern bool_t xdr_dtn_bundle_payload_location_t ();
extern bool_t xdr_dtn_bundle_payload_t ();
extern bool_t xdr_dtn_bundle_auth_t ();

#endif /* K&R C */

#ifdef __cplusplus
}
#endif

#endif /* !_DTN_TYPES_H_RPCGEN */

