Code

frontend: Let sdb_fe_parse() return a list of parsed node objects.
[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_accpet:
57  * Accept a new connection on the specified file-descriptor 'fd' and return a
58  * newly allocated connection object.
59  *
60  * Returns:
61  *  - 0 on success
62  *  - a negative value else
63  */
64 sdb_conn_t *
65 sdb_connection_accept(int fd);
67 /*
68  * sdb_connection_close:
69  * Close a open connection and deallocate any memory. The connection object is
70  * no longer valid after calling this function.
71  */
72 void
73 sdb_connection_close(sdb_conn_t *conn);
75 /*
76  * sdb_connection_read:
77  * Read from an open connection until reading would block.
78  *
79  * Returns:
80  *  - the number of bytes read (0 on EOF)
81  *  - a negative value on error
82  */
83 ssize_t
84 sdb_connection_read(sdb_conn_t *conn);
86 /*
87  * sdb_connection_send:
88  * Send to an open connection.
89  *
90  * Returns:
91  *  - the number of bytes written
92  *  - a negative value on error
93  */
94 ssize_t
95 sdb_connection_send(sdb_conn_t *conn, uint32_t code,
96                 uint32_t msg_len, const char *msg);
98 /*
99  * sdb_connection_ping:
100  * Send back a backend status indicator to the connected client.
101  *
102  * Returns:
103  *  - 0 on success
104  *  - a negative value else
105  */
106 int
107 sdb_connection_ping(sdb_conn_t *conn);
109 /*
110  * sdb_fe_parse:
111  * Parse the query text specified in 'query' and return a list of parse trees
112  * (for each command) to be executed by sdb_fe_exec. The list has to be freed
113  * by the caller.
114  *
115  * Returns:
116  *  - an sdb_llist_t object of sdb_conn_node_t on success
117  *  - NULL in case of an error
118  */
119 sdb_llist_t *
120 sdb_fe_parse(const char *query);
122 /*
123  * sdb_fe_exec:
124  * Execute the command identified by 'node'.
125  *
126  * Returns:
127  *  - 0 on success
128  *  - a negative value else
129  */
130 int
131 sdb_fe_exec(sdb_conn_node_t *node);
133 /*
134  * session handling
135  */
137 /*
138  * sdb_fe_session_start:
139  * Start a new user session on the specified connection.
140  *
141  * Returns:
142  *  - 0 on success
143  *  - a negative value else
144  */
145 int
146 sdb_fe_session_start(sdb_conn_t *conn);
148 /*
149  * store access
150  */
152 /*
153  * sdb_fe_list:
154  * Send a complete listing of the store, serialized as JSON, to the client.
155  *
156  * Returns:
157  *  - 0 on success
158  *  - a negative value else
159  */
160 int
161 sdb_fe_list(sdb_conn_t *conn);
163 #ifdef __cplusplus
164 } /* extern "C" */
165 #endif
167 #endif /* ! SDB_FRONTEND_CONNECTION_H */
169 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */