Eric Salama | 8a9c6c2 | 2017-11-10 11:02:23 +0100 | [diff] [blame^] | 1 | #ifndef _MINI_SAMPLE_H |
| 2 | #define _MINI_SAMPLE_H |
| 3 | |
| 4 | #include <sys/socket.h> |
| 5 | #include <netinet/in.h> |
| 6 | #include <netinet/ip.h> |
| 7 | |
| 8 | /* input and output sample types */ |
| 9 | enum { |
| 10 | SMP_T_ANY = 0, /* any type */ |
| 11 | SMP_T_BOOL, /* boolean */ |
| 12 | SMP_T_SINT, /* signed 64bits integer type */ |
| 13 | SMP_T_ADDR, /* ipv4 or ipv6, only used for input type compatibility */ |
| 14 | SMP_T_IPV4, /* ipv4 type */ |
| 15 | SMP_T_IPV6, /* ipv6 type */ |
| 16 | SMP_T_STR, /* char string type */ |
| 17 | SMP_T_BIN, /* buffer type */ |
| 18 | SMP_T_METH, /* contain method */ |
| 19 | SMP_TYPES /* number of types, must always be last */ |
| 20 | }; |
| 21 | |
| 22 | /* describes a chunk of string */ |
| 23 | struct chunk { |
| 24 | char *str; /* beginning of the string itself. Might not be 0-terminated */ |
| 25 | int size; /* total size of the buffer, 0 if the *str is read-only */ |
| 26 | int len; /* current size of the string from first to last char. <0 = uninit. */ |
| 27 | }; |
| 28 | |
| 29 | union sample_value { |
| 30 | long long int sint; /* used for signed 64bits integers */ |
| 31 | struct in_addr ipv4; /* used for ipv4 addresses */ |
| 32 | struct in6_addr ipv6; /* used for ipv6 addresses */ |
| 33 | struct chunk str; /* used for char strings or buffers */ |
| 34 | //struct meth meth; /* used for http method */ |
| 35 | }; |
| 36 | |
| 37 | /* Used to store sample constant */ |
| 38 | struct sample_data { |
| 39 | int type; /* SMP_T_* */ |
| 40 | union sample_value u; /* sample data */ |
| 41 | }; |
| 42 | |
| 43 | /* a sample is a typed data extracted from a stream. It has a type, contents, |
| 44 | * validity constraints, a context for use in iterative calls. |
| 45 | */ |
| 46 | struct sample { |
| 47 | struct sample_data data; |
| 48 | }; |
| 49 | #endif |
| 50 | |