2 * Copyright (C) 2011-2012 Red Hat Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef WRAPPI_INTERNAL_H_
20 #define WRAPPI_INTERNAL_H_
24 #include <rpc/types.h>
27 #define STREQ(a,b) (strcmp((a),(b)) == 0)
28 #define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0)
29 #define STRNEQ(a,b) (strcmp((a),(b)) != 0)
30 #define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0)
31 #define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0)
32 #define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0)
33 #define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0)
34 #define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0)
35 #define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0)
37 struct wrap_internal_h {
38 char *error; /* Last error on this handle, NULL is none. */
39 int errnum; /* errno, or 0 if there was no errno set. */
40 const char *error_func; /* Function where the error occurred, if known. */
44 /* The "internal" part of the handle must always appear at the
45 * beginning of the handle structure. For the remote case, this
46 * contains a cut-down handle which is what non-local entry points
47 * are permitted to touch. For the local case, the full handle is
48 * cast to (struct wrap_internal_h *).
50 struct wrap_internal_h internal;
52 /* Fields that follow the 'internal' structure only exist
53 * on the local side of a connection.
56 uint32_t serial; /* Serial number used in protocol. */
58 FILE *rfp, *wfp; /* Connection to remote. */
59 pid_t pid; /* Child process if using remote, eg ssh */
61 /* Connection URL. If scheme == LOCAL, it means we're using the
64 wrap_scheme_enum scheme;
68 /* Declare an error, setting the error field in the handle. */
69 #define set_error(fs...) \
70 wrap_int_set_error ((struct wrap_internal_h *)w, __func__, fs)
71 #define set_error_errno(fs...) \
72 wrap_int_set_error_errno ((struct wrap_internal_h *)w, (errno), __func__, fs)
74 extern void wrap_int_connect_ssh (wrap_h *w);
75 extern void wrap_int_make_request (wrap_h *w, int proc_nr, const void *args, void *ret);
76 extern void wrap_int_make_request_xdr (wrap_h *w, int proc_nr, const void *args, void *ret);
77 extern void wrap_int_set_error (struct wrap_internal_h *w, const char *func, const char *fs, ...);
78 extern void wrap_int_set_error_errno (struct wrap_internal_h *w, int errnum, const char *func, const char *fs, ...);
80 /* See lib/internal-procs.c for the static contents of this table.
81 * The table is indexed by wrap_int_<name>_num. These are defined in
82 * lib/internal-procs.h.
85 const char *name; /* The name of this entry point. */
87 /* XDR encode/decode functions for serializing the args and ret. */
92 extern const struct proc_table wrap_int_proc_table[];
94 #include "internal-procs.h"
96 #endif /* WRAPPI_INTERNAL_H_ */