Dillo v3.1.1-98-g318d1f14
Loading...
Searching...
No Matches
dpip.h
Go to the documentation of this file.
1/*
2 * Library for dealing with dpip tags (dillo plugin protocol tags).
3 */
4
5#ifndef __DPIP_H__
6#define __DPIP_H__
7
8#ifdef __cplusplus
9extern "C" {
10#endif /* __cplusplus */
11
12#include "../dlib/dlib.h"
13
14/*
15 * Communication mode flags
16 */
17#define DPIP_TAG 1
18#define DPIP_LAST_TAG 2
19#define DPIP_RAW 4
20#define DPIP_NONBLOCK 8
27
31typedef struct {
32 int fd_in;
33 int fd_out;
34 /* FILE *in; --Unused. The stream functions block when reading. */
35 FILE *out;
36
41 int mode;
42 int status;
43} Dsh;
44
45
52char *a_Dpip_build_cmd(const char *format, ...);
53
59char *a_Dpip_get_attr(const char *tag, const char *attrname);
60char *a_Dpip_get_attr_l(const char *tag, size_t tagsize, const char *attrname);
61
62int a_Dpip_check_auth(const char *auth);
63
64/*
65 * Dpip socket API
66 */
67Dsh *a_Dpip_dsh_new(int fd_in, int fd_out, int flush_sz);
68int a_Dpip_dsh_write(Dsh *dsh, int flush, const char *Data, int DataSize);
69int a_Dpip_dsh_write_str(Dsh *dsh, int flush, const char *str);
70int a_Dpip_dsh_tryflush(Dsh *dsh);
71int a_Dpip_dsh_trywrite(Dsh *dsh, const char *Data, int DataSize);
72char *a_Dpip_dsh_read_token(Dsh *dsh, int blocking);
73char *a_Dpip_dsh_read_token2(Dsh *dsh, int blocking, int *DataSize);
74void a_Dpip_dsh_close(Dsh *dsh);
75void a_Dpip_dsh_free(Dsh *dsh);
76
77#define a_Dpip_dsh_printf(sh, flush, ...) \
78 D_STMT_START { \
79 Dstr *dstr = dStr_sized_new(128); \
80 dStr_sprintf(dstr, __VA_ARGS__); \
81 a_Dpip_dsh_write(sh, flush, dstr->str, dstr->len); \
82 dStr_free(dstr, 1); \
83 } D_STMT_END
84
85#ifdef __cplusplus
86}
87#endif /* __cplusplus */
88
89#endif /* __DPIP_H__ */
90
int a_Dpip_dsh_trywrite(Dsh *dsh, const char *Data, int DataSize)
Definition dpip.c:359
char * a_Dpip_dsh_read_token2(Dsh *dsh, int blocking, int *DataSize)
Return a newlly allocated string with the next dpip token in the socket.
Definition dpip.c:438
void a_Dpip_dsh_free(Dsh *dsh)
Free the SockHandler structure.
Definition dpip.c:525
char * a_Dpip_build_cmd(const char *format,...)
Printf like function for building dpip commands.
Definition dpip.c:83
int a_Dpip_dsh_write_str(Dsh *dsh, int flush, const char *str)
Convenience function.
Definition dpip.c:374
char * a_Dpip_get_attr(const char *tag, const char *attrname)
Task: given a tag and an attribute name, return its value.
Definition dpip.c:192
DpipDshStatus
Definition dpip.h:22
@ DPIP_ERROR
Definition dpip.h:24
@ DPIP_EOF
Definition dpip.h:25
@ DPIP_EAGAIN
Definition dpip.h:23
char * a_Dpip_dsh_read_token(Dsh *dsh, int blocking)
Return a newlly allocated string with the next dpip token in the socket.
Definition dpip.c:493
void a_Dpip_dsh_close(Dsh *dsh)
Close this socket for reading and writing.
Definition dpip.c:504
char * a_Dpip_get_attr_l(const char *tag, size_t tagsize, const char *attrname)
Task: given a tag, its size and an attribute name, return the attribute value (stuffing of ' is remov...
Definition dpip.c:134
int a_Dpip_check_auth(const char *auth)
Check whether the given 'auth' string equals what dpid saved.
Definition dpip.c:201
int a_Dpip_dsh_write(Dsh *dsh, int flush, const char *Data, int DataSize)
Streamed write to socket.
Definition dpip.c:317
int a_Dpip_dsh_tryflush(Dsh *dsh)
Definition dpip.c:340
Dsh * a_Dpip_dsh_new(int fd_in, int fd_out, int flush_sz)
Create and initialize a dpip socket handler.
Definition dpip.c:247
Dpip socket handler type.
Definition dpip.h:31
Dstr * rdbuf
read buffer
Definition dpip.h:38
int mode
mode flags: DPIP_TAG | DPIP_LAST_TAG | DPIP_RAW
Definition dpip.h:41
int status
status code: DPIP_EAGAIN | DPIP_ERROR | DPIP_EOF
Definition dpip.h:42
Dstr * wrbuf
write buffer
Definition dpip.h:37
int fd_in
Definition dpip.h:32
int fd_out
Definition dpip.h:33
int flush_sz
max size before flush
Definition dpip.h:39
FILE * out
Definition dpip.h:35
Definition dlib.h:102