Code

Merged branch 'master' of git://git.tokkee.org/sysdb.
[sysdb.git] / src / include / frontend / connection.h
index a5ea092c425d65f570af2b838f2febbdf9e64611..a2163bce9841d479557ad5f8c4f93bdf69ba4af5 100644 (file)
@@ -28,6 +28,7 @@
 #ifndef SDB_FRONTEND_CONNECTION_H
 #define SDB_FRONTEND_CONNECTION_H 1
 
+#include "frontend/proto.h"
 #include "utils/strbuf.h"
 
 #include <inttypes.h>
 extern "C" {
 #endif
 
-/* status codes returned to a client */
-typedef enum {
-       CONNECTION_OK = 0,
-       CONNECTION_ERROR
-} sdb_conn_status_t;
-
-/* accepted commands / state of the connection */
-typedef enum {
-       CONNECTION_IDLE = 0,
-       CONNECTION_PING,
-       CONNECTION_STARTUP,
-} sdb_conn_state_t;
-
-/* a generic connection object */
-typedef struct {
-       /* file-descriptor of the open connection */
-       int fd;
-
-       /* read buffer */
-       sdb_strbuf_t *buf;
-
-       /* connection / protocol state information */
-       uint32_t cmd;
-       uint32_t cmd_len;
-
-       /* user information */
-       char *username; /* NULL if the user has not been authenticated */
-} sdb_conn_t;
+typedef struct sdb_conn sdb_conn_t;
 
 /*
- * sdb_connection_init:
- * Initialize an (already allocated) connection. This function allocates and
- * initialized any attributes. It's an error to call init on an already
- * initialized object.
+ * sdb_connection_accpet:
+ * Accept a new connection on the specified file-descriptor 'fd' and return a
+ * newly allocated connection object.
  *
  * Returns:
  *  - 0 on success
  *  - a negative value else
  */
-int
-sdb_connection_init(sdb_conn_t *conn);
+sdb_conn_t *
+sdb_connection_accept(int fd);
 
 /*
  * sdb_connection_close:
- * Close a open connection and deallocate any memory used by its attributes.
+ * Close a open connection and deallocate any memory. The connection object is
+ * no longer valid after calling this function.
  */
 void
 sdb_connection_close(sdb_conn_t *conn);
@@ -106,7 +80,7 @@ sdb_connection_read(sdb_conn_t *conn);
  */
 ssize_t
 sdb_connection_send(sdb_conn_t *conn, uint32_t code,
-               uint32_t msg_len, char *msg);
+               uint32_t msg_len, const char *msg);
 
 /*
  * sdb_connection_ping:
@@ -124,7 +98,7 @@ sdb_connection_ping(sdb_conn_t *conn);
  */
 
 /*
- * sdb_session_start:
+ * sdb_fe_session_start:
  * Start a new user session on the specified connection.
  *
  * Returns:
@@ -132,7 +106,22 @@ sdb_connection_ping(sdb_conn_t *conn);
  *  - a negative value else
  */
 int
-sdb_session_start(sdb_conn_t *conn);
+sdb_fe_session_start(sdb_conn_t *conn);
+
+/*
+ * store access
+ */
+
+/*
+ * sdb_fe_list:
+ * Send a complete listing of the store, serialized as JSON, to the client.
+ *
+ * Returns:
+ *  - 0 on success
+ *  - a negative value else
+ */
+int
+sdb_fe_list(sdb_conn_t *conn);
 
 #ifdef __cplusplus
 } /* extern "C" */