X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=lib%2Finternal.h;h=1c98ca47653631816fa3608064b902a36f08844d;hb=cf654cde5cfc9337e254934b23274e4a7b3432ba;hp=2213d7bec809c09d3ebf853a3256dfaa2d12ff55;hpb=9bc1d63c273099058929cce160bea0a871eb001a;p=wrappi.git diff --git a/lib/internal.h b/lib/internal.h index 2213d7b..1c98ca4 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -19,8 +19,91 @@ #ifndef WRAPPI_INTERNAL_H_ #define WRAPPI_INTERNAL_H_ +#include +#include +#include +#include + +#define STREQ(a,b) (strcmp((a),(b)) == 0) +#define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0) +#define STRNEQ(a,b) (strcmp((a),(b)) != 0) +#define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0) +#define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0) +#define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0) +#define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0) +#define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0) +#define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0) + +struct wrap_internal_h { + char *error; /* Last error on this handle, NULL is none. */ + int errnum; /* errno, or 0 if there was no errno set. */ + const char *error_func; /* Function where the error occurred, if known. */ +}; + struct wrap_h { - int error_flag; + /* The "internal" part of the handle must always appear at the + * beginning of the handle structure. For the remote case, this + * contains a cut-down handle which is what non-local entry points + * are permitted to touch. For the local case, the full handle is + * cast to (struct wrap_internal_h *). + */ + struct wrap_internal_h internal; + + /* Fields that follow the 'internal' structure only exist + * on the local side of a connection. + */ + + uint32_t serial; /* Serial number used in protocol. */ + + FILE *rfp, *wfp; /* Connection to remote. */ + pid_t pid; /* Child process if using remote, eg ssh */ + + /* Connection URL. If scheme == LOCAL, it means we're using the + * local code. + */ + wrap_scheme_enum scheme; + char *hostname; + char *wrappid_path; }; +/* Declare an error, setting the error field in the handle. */ +#define set_error(fs...) \ + wrap_int_set_error ((struct wrap_internal_h *)w, __func__, fs) +#define set_error_errno(fs...) \ + wrap_int_set_error_errno ((struct wrap_internal_h *)w, (errno), __func__, fs) + +extern void wrap_int_connect_ssh (wrap_h *w); +extern int wrap_int_lookup_proc_entry (const char *name); +extern void wrap_int_make_request (wrap_h *w, int proc_nr, const void *args, void *ret); +extern void wrap_int_make_request_xdr (wrap_h *w, int proc_nr, const void *args, void *ret); +extern void wrap_int_set_error (struct wrap_internal_h *w, const char *func, const char *fs, ...); +extern void wrap_int_set_error_errno (struct wrap_internal_h *w, int errnum, const char *func, const char *fs, ...); + +/* See lib/internal-procs.c for the static contents of this table. + * The table is indexed by wrap_int__num. These are defined in + * lib/internal-procs.h. + */ +struct proc_table { + const char *name; /* The name of this entry point. */ + + /* Size of the args and ret structs. */ + size_t args_struct_size; + size_t ret_struct_size; + + /* Call this procedure. */ + void (*call) (wrap_h *w, const void *args, void *ret); + + /* XDR encode/decode functions for serializing the args and ret. */ + xdrproc_t args_xdrproc; + xdrproc_t ret_xdrproc; +}; + +extern const struct proc_table wrap_int_proc_table[]; + +#include "internal-procs.h" + +/* Defined and used by lib/internal-procs-lookup.gperf */ +struct proc_entry { char *name; int proc_nr; }; +extern const struct proc_entry *wrap_int_gperf_lookup_proc_entry (register const char *str, register unsigned int len); + #endif /* WRAPPI_INTERNAL_H_ */