diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2010-08-20 23:24:19 +0200 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2010-08-20 23:24:19 +0200 |
commit | f5c598b518d1f906148534d015f50075d3e8242d (patch) | |
tree | 21dd70add5b366c3dd80641b77f6b18e0baa009e /dpip/dpip.h | |
parent | e98d02a01ffeb18ede86af025e51ae1ec011c75a (diff) | |
parent | 5f0fc0e48b8cbee7e1795935da0abff6627fd498 (diff) |
merge
Diffstat (limited to 'dpip/dpip.h')
-rw-r--r-- | dpip/dpip.h | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/dpip/dpip.h b/dpip/dpip.h index 29bb5fcf..083732ff 100644 --- a/dpip/dpip.h +++ b/dpip/dpip.h @@ -9,6 +9,40 @@ extern "C" { #endif /* __cplusplus */ +#include "../dlib/dlib.h" + +/* + * Communication mode flags + */ +#define DPIP_TAG 1 /* Dpip tags in the socket */ +#define DPIP_LAST_TAG 2 /* Dpip mode-switching tag */ +#define DPIP_RAW 4 /* Raw data in the socket */ +#define DPIP_NONBLOCK 8 /* Nonblocking IO */ + +typedef enum { + DPIP_EAGAIN, + DPIP_ERROR, + DPIP_EOF +} DpipDshStatus; + +/* + * Dpip socket handler type. + */ +typedef struct _DpipSocketHandler Dsh; +struct _DpipSocketHandler { + int fd_in; + int fd_out; + /* FILE *in; --Unused. The stream functions block when reading. */ + FILE *out; + + Dstr *wrbuf; /* write buffer */ + Dstr *rdbuf; /* read buffer */ + int flush_sz; /* max size before flush */ + + int mode; /* mode flags: DPIP_TAG | DPIP_LAST_TAG | DPIP_RAW */ + int status; /* status code: DPIP_EAGAIN | DPIP_ERROR | DPIP_EOF */ +}; + /* * Printf like function for building dpip commands. @@ -23,8 +57,30 @@ char *a_Dpip_build_cmd(const char *format, ...); * (dpip character escaping is removed here) * Return value: the attribute value, or NULL if not present or malformed. */ -char *a_Dpip_get_attr(char *tag, size_t tagsize, const char *attrname); +char *a_Dpip_get_attr(const char *tag, const char *attrname); +char *a_Dpip_get_attr_l(const char *tag, size_t tagsize, const char *attrname); + +int a_Dpip_check_auth(const char *auth); + +/* + * Dpip socket API + */ +Dsh *a_Dpip_dsh_new(int fd_in, int fd_out, int flush_sz); +int a_Dpip_dsh_write(Dsh *dsh, int flush, const char *Data, int DataSize); +int a_Dpip_dsh_write_str(Dsh *dsh, int flush, const char *str); +int a_Dpip_dsh_tryflush(Dsh *dsh); +int a_Dpip_dsh_trywrite(Dsh *dsh, const char *Data, int DataSize); +char *a_Dpip_dsh_read_token(Dsh *dsh, int blocking); +void a_Dpip_dsh_close(Dsh *dsh); +void a_Dpip_dsh_free(Dsh *dsh); +#define a_Dpip_dsh_printf(sh, flush, ...) \ + D_STMT_START { \ + Dstr *dstr = dStr_sized_new(128); \ + dStr_sprintf(dstr, __VA_ARGS__); \ + a_Dpip_dsh_write(sh, flush, dstr->str, dstr->len); \ + dStr_free(dstr, 1); \ + } D_STMT_END #ifdef __cplusplus } |