More implementation.
[wrappi.git] / lib / internal.h
1 /* wrappi
2  * Copyright (C) 2011-2012 Red Hat Inc.
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #ifndef WRAPPI_INTERNAL_H_
20 #define WRAPPI_INTERNAL_H_
21
22 #include <string.h>
23 #include <errno.h>
24
25 #define STREQ(a,b) (strcmp((a),(b)) == 0)
26 #define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0)
27 #define STRNEQ(a,b) (strcmp((a),(b)) != 0)
28 #define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0)
29 #define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0)
30 #define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0)
31 #define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0)
32 #define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0)
33 #define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0)
34
35 struct wrap_internal_h {
36   char *error;          /* Last error on this handle, NULL is none. */
37   int errnum;           /* errno, or 0 if there was no errno set. */
38   const char *error_func; /* Function where the error occurred, if known. */
39 };
40
41 struct wrap_h {
42   /* The "internal" part of the handle must always appear at the
43    * beginning of the handle structure.  For the remote case, this
44    * contains a cut-down handle which is what non-local entry points
45    * are permitted to touch.  For the local case, the full handle is
46    * cast to (struct wrap_internal_h *).
47    */
48   struct wrap_internal_h internal;
49
50   /* Fields that follow the 'internal' structure only exist
51    * on the local side of a connection.
52    */
53
54   /* Connection URL.  If scheme = NULL, it means we're using the local
55    * code.
56    */
57   const char *scheme;
58   const char *hostname;
59 };
60
61 /* Declare an error, setting the error field in the handle. */
62 #define set_error(fs...) \
63   wrap_int_set_error ((struct wrap_internal_h *)w, __func__, fs)
64 #define set_error_errno(fs...) \
65   wrap_int_set_error_errno ((struct wrap_internal_h *)w, (errno), __func__, fs)
66
67 extern void wrap_int_set_error (struct wrap_internal_h *w, const char *func, const char *fs, ...);
68 extern void wrap_int_set_error_errno (struct wrap_internal_h *w, int errnum, const char *func, const char *fs, ...);
69
70 #endif /* WRAPPI_INTERNAL_H_ */