Code

frontend: Send connection-related log messages to the client.
[sysdb.git] / src / include / frontend / connection.h
1 /*
2  * SysDB - src/include/frontend/connection.h
3  * Copyright (C) 2013 Sebastian 'tokkee' Harl <sh@tokkee.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
28 #ifndef SDB_FRONTEND_CONNECTION_H
29 #define SDB_FRONTEND_CONNECTION_H 1
31 #include "frontend/proto.h"
32 #include "utils/llist.h"
33 #include "utils/strbuf.h"
35 #include <inttypes.h>
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
41 typedef struct sdb_conn sdb_conn_t;
43 /*
44  * sdb_conn_node_t represents an interface for the result of parsing a command
45  * string. The first field of an actual implementation of the interface is a
46  * sdb_conn_state_t in order to fascilitate casting to and from the interface
47  * type to the implementation type.
48  */
49 typedef struct {
50         sdb_object_t super;
51         sdb_conn_state_t cmd;
52 } sdb_conn_node_t;
53 #define SDB_CONN_NODE(obj) ((sdb_conn_node_t *)(obj))
55 /*
56  * sdb_connection_enable_logging:
57  * Enable logging of connection-related messages to the current client
58  * connection. After this function has been called all log messages
59  * originating from the thread handling the current client connection will
60  * also be sent to the client.
61  *
62  * Returns:
63  *  - 0 on success
64  *  - a negative value else
65  */
66 int
67 sdb_connection_enable_logging(void);
69 /*
70  * sdb_connection_accpet:
71  * Accept a new connection on the specified file-descriptor 'fd' and return a
72  * newly allocated connection object.
73  *
74  * Returns:
75  *  - 0 on success
76  *  - a negative value else
77  */
78 sdb_conn_t *
79 sdb_connection_accept(int fd);
81 /*
82  * sdb_connection_close:
83  * Close a open connection and deallocate any memory. The connection object is
84  * no longer valid after calling this function.
85  */
86 void
87 sdb_connection_close(sdb_conn_t *conn);
89 /*
90  * sdb_connection_read:
91  * Read from an open connection until reading would block.
92  *
93  * Returns:
94  *  - the number of bytes read (0 on EOF)
95  *  - a negative value on error
96  */
97 ssize_t
98 sdb_connection_read(sdb_conn_t *conn);
100 /*
101  * sdb_connection_send:
102  * Send to an open connection.
103  *
104  * Returns:
105  *  - the number of bytes written
106  *  - a negative value on error
107  */
108 ssize_t
109 sdb_connection_send(sdb_conn_t *conn, uint32_t code,
110                 uint32_t msg_len, const char *msg);
112 /*
113  * sdb_connection_ping:
114  * Send back a backend status indicator to the connected client.
115  *
116  * Returns:
117  *  - 0 on success
118  *  - a negative value else
119  */
120 int
121 sdb_connection_ping(sdb_conn_t *conn);
123 /*
124  * sdb_fe_parse:
125  * Parse the query text specified in 'query' of length 'len' and return a list
126  * of parse trees (for each command) to be executed by sdb_fe_exec. The list
127  * has to be freed by the caller. If 'len' is less than zero, parse the whole
128  * (nul-terminated) string.
129  *
130  * Returns:
131  *  - an sdb_llist_t object of sdb_conn_node_t on success
132  *  - NULL in case of an error
133  */
134 sdb_llist_t *
135 sdb_fe_parse(const char *query, int len);
137 /*
138  * sdb_fe_exec:
139  * Execute the command identified by 'node' on the specified connection.
140  *
141  * Returns:
142  *  - 0 on success
143  *  - a negative value else
144  */
145 int
146 sdb_fe_exec(sdb_conn_t *conn, sdb_conn_node_t *node);
148 /*
149  * session handling
150  */
152 /*
153  * sdb_fe_session_start:
154  * Start a new user session on the specified connection.
155  *
156  * Returns:
157  *  - 0 on success
158  *  - a negative value else
159  */
160 int
161 sdb_fe_session_start(sdb_conn_t *conn);
163 /*
164  * store access
165  */
167 /*
168  * sdb_fe_list:
169  * Send a complete listing of the store, serialized as JSON, to the client.
170  *
171  * Returns:
172  *  - 0 on success
173  *  - a negative value else
174  */
175 int
176 sdb_fe_list(sdb_conn_t *conn);
178 #ifdef __cplusplus
179 } /* extern "C" */
180 #endif
182 #endif /* ! SDB_FRONTEND_CONNECTION_H */
184 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */