summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 78afb86)
raw | patch | inline | side by side (parent: 78afb86)
author | Sebastian Harl <sh@tokkee.org> | |
Tue, 11 Nov 2014 17:49:49 +0000 (18:49 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Tue, 11 Nov 2014 17:49:49 +0000 (18:49 +0100) |
All public symbols should use the "sdb" prefix.
13 files changed:
diff --git a/src/client/sock.c b/src/client/sock.c
index 82a48a62534a6e0d0b00dee704e58cf821dc998c..8602532da9eea9d4575d85d52fdc82cc34976c91 100644 (file)
--- a/src/client/sock.c
+++ b/src/client/sock.c
if (! username)
username = "";
- status = sdb_client_send(client, CONNECTION_STARTUP,
+ status = sdb_client_send(client, SDB_CONNECTION_STARTUP,
(uint32_t)strlen(username), username);
if (status < 0) {
char errbuf[1024];
buf = sdb_strbuf_create(64);
rstatus = 0;
status = sdb_client_recv(client, &rstatus, buf);
- if ((status > 0) && (rstatus == CONNECTION_OK)) {
+ if ((status > 0) && (rstatus == SDB_CONNECTION_OK)) {
sdb_strbuf_destroy(buf);
return 0;
}
sdb_log(SDB_LOG_ERR, "Encountered end-of-file while waiting "
"for server response");
- if (rstatus == CONNECTION_ERROR) {
+ if (rstatus == SDB_CONNECTION_ERROR) {
sdb_log(SDB_LOG_ERR, "Access denied for user '%s'", username);
status = -((int)rstatus);
}
- else if (rstatus != CONNECTION_OK) {
+ else if (rstatus != SDB_CONNECTION_OK) {
sdb_log(SDB_LOG_ERR, "Received unsupported authentication request "
"(status %d) during startup", (int)rstatus);
status = -((int)rstatus);
index c1b9d01ef19494188dddd2d3dd916601715e924a..6a50736be23752fe6ea96c2beaccda8815ea9c8d 100644 (file)
--- a/src/frontend/analyzer.c
+++ b/src/frontend/analyzer.c
/* For now, this function checks basic matcher attributes only;
* later, this may be turned into one of multiple AST visitors. */
- if (node->cmd == CONNECTION_FETCH) {
+ if (node->cmd == SDB_CONNECTION_FETCH) {
conn_fetch_t *fetch = CONN_FETCH(node);
if ((fetch->type == SDB_HOST) && fetch->name) {
sdb_strbuf_sprintf(errbuf, "Unexpected STRING '%s'", fetch->name);
filter = fetch->filter->matcher;
context = fetch->type;
}
- else if (node->cmd == CONNECTION_LIST) {
+ else if (node->cmd == SDB_CONNECTION_LIST) {
if (CONN_LIST(node)->filter)
filter = CONN_LIST(node)->filter->matcher;
context = CONN_LIST(node)->type;
}
- else if (node->cmd == CONNECTION_LOOKUP) {
+ else if (node->cmd == SDB_CONNECTION_LOOKUP) {
if (CONN_LOOKUP(node)->matcher)
m = CONN_LOOKUP(node)->matcher->matcher;
if (CONN_LOOKUP(node)->filter)
filter = CONN_LOOKUP(node)->filter->matcher;
context = CONN_LOOKUP(node)->type;
}
- else if (node->cmd == CONNECTION_TIMESERIES)
+ else if (node->cmd == SDB_CONNECTION_TIMESERIES)
return 0;
else
return -1;
index bb0f494f2d432c849e4c60be174b3cfec3f786ab..1d8b8b34d2c9ff06eeca3f0aff9584443528540c 100644 (file)
sdb_log(SDB_LOG_DEBUG, "frontend: Accepted connection on fd=%i",
conn->fd);
- conn->cmd = CONNECTION_IDLE;
+ conn->cmd = SDB_CONNECTION_IDLE;
conn->cmd_len = 0;
conn->skip_len = 0;
memcpy(tmp, &p, sizeof(p));
strcpy(tmp + sizeof(p), msg);
- if (sdb_connection_send(conn, CONNECTION_LOG, len, tmp) < 0)
+ if (sdb_connection_send(conn, SDB_CONNECTION_LOG, len, tmp) < 0)
return -1;
return 0;
} /* connection_log */
{
int status = -1;
- assert(conn && (conn->cmd != CONNECTION_IDLE));
+ assert(conn && (conn->cmd != SDB_CONNECTION_IDLE));
assert(! conn->skip_len);
sdb_log(SDB_LOG_DEBUG, "frontend: Handling command %u (len: %u)",
conn->cmd, conn->cmd_len);
- if (conn->cmd == CONNECTION_PING)
+ if (conn->cmd == SDB_CONNECTION_PING)
status = sdb_connection_ping(conn);
- else if (conn->cmd == CONNECTION_STARTUP)
+ else if (conn->cmd == SDB_CONNECTION_STARTUP)
status = sdb_fe_session_start(conn);
- else if (conn->cmd == CONNECTION_QUERY)
+ else if (conn->cmd == SDB_CONNECTION_QUERY)
status = sdb_fe_query(conn);
- else if (conn->cmd == CONNECTION_FETCH)
+ else if (conn->cmd == SDB_CONNECTION_FETCH)
status = sdb_fe_fetch(conn);
- else if (conn->cmd == CONNECTION_LIST)
+ else if (conn->cmd == SDB_CONNECTION_LIST)
status = sdb_fe_list(conn);
- else if (conn->cmd == CONNECTION_LOOKUP)
+ else if (conn->cmd == SDB_CONNECTION_LOOKUP)
status = sdb_fe_lookup(conn);
else {
sdb_log(SDB_LOG_WARNING, "frontend: Ignoring invalid command %#x",
if (status) {
if (! sdb_strbuf_len(conn->errbuf))
sdb_strbuf_sprintf(conn->errbuf, "Failed to execute command");
- sdb_connection_send(conn, CONNECTION_ERROR,
+ sdb_connection_send(conn, SDB_CONNECTION_ERROR,
(uint32_t)sdb_strbuf_len(conn->errbuf),
sdb_strbuf_string(conn->errbuf));
}
{
const char *errmsg = NULL;
- assert(conn && (conn->cmd == CONNECTION_IDLE) && (! conn->cmd_len));
+ assert(conn && (conn->cmd == SDB_CONNECTION_IDLE) && (! conn->cmd_len));
if (conn->skip_len)
return -1;
sdb_strbuf_skip(conn->buf, 0, 2 * sizeof(uint32_t));
- if ((! conn->ready) && (conn->cmd != CONNECTION_STARTUP))
+ if ((! conn->ready) && (conn->cmd != SDB_CONNECTION_STARTUP))
errmsg = "Authentication required";
- else if (conn->cmd == CONNECTION_IDLE)
+ else if (conn->cmd == SDB_CONNECTION_IDLE)
errmsg = "Invalid command 0";
if (errmsg) {
size_t len = sdb_strbuf_len(conn->buf);
sdb_strbuf_sprintf(conn->errbuf, "%s", errmsg);
- sdb_connection_send(conn, CONNECTION_ERROR,
+ sdb_connection_send(conn, SDB_CONNECTION_ERROR,
(uint32_t)strlen(errmsg), errmsg);
conn->skip_len += conn->cmd_len;
- conn->cmd = CONNECTION_IDLE;
+ conn->cmd = SDB_CONNECTION_IDLE;
conn->cmd_len = 0;
if (len > conn->skip_len)
while (42) {
ssize_t status = connection_read(conn);
- if ((conn->cmd == CONNECTION_IDLE) && (! conn->cmd_len)
+ if ((conn->cmd == SDB_CONNECTION_IDLE) && (! conn->cmd_len)
&& (sdb_strbuf_len(conn->buf) >= 2 * sizeof(int32_t)))
command_init(conn);
- if ((conn->cmd != CONNECTION_IDLE)
+ if ((conn->cmd != SDB_CONNECTION_IDLE)
&& (sdb_strbuf_len(conn->buf) >= conn->cmd_len)) {
command_handle(conn);
/* remove the command from the buffer */
if (conn->cmd_len)
sdb_strbuf_skip(conn->buf, 0, conn->cmd_len);
- conn->cmd = CONNECTION_IDLE;
+ conn->cmd = SDB_CONNECTION_IDLE;
conn->cmd_len = 0;
}
int
sdb_connection_ping(sdb_conn_t *conn)
{
- if ((! conn) || (conn->cmd != CONNECTION_PING))
+ if ((! conn) || (conn->cmd != SDB_CONNECTION_PING))
return -1;
/* we're alive */
- sdb_connection_send(conn, CONNECTION_OK, 0, NULL);
+ sdb_connection_send(conn, SDB_CONNECTION_OK, 0, NULL);
return 0;
} /* sdb_connection_ping */
diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y
index 80fb249684e0120be85cd421905fec666d277bc4..3180167fe2d98256637078338be98baf1e5368f8 100644 (file)
--- a/src/frontend/grammar.y
+++ b/src/frontend/grammar.y
sdb_conn_node_t *n;
n = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL,
conn_expr_t, conn_expr_destroy));
- n->cmd = CONNECTION_EXPR;
+ n->cmd = SDB_CONNECTION_EXPR;
CONN_EXPR(n)->expr = $1;
sdb_llist_append(pt, SDB_OBJ(n));
CONN_FETCH($$)->host = $3;
CONN_FETCH($$)->name = NULL;
CONN_FETCH($$)->filter = CONN_MATCHER($4);
- $$->cmd = CONNECTION_FETCH;
+ $$->cmd = SDB_CONNECTION_FETCH;
}
|
FETCH object_type STRING '.' STRING filter_clause
CONN_FETCH($$)->host = $3;
CONN_FETCH($$)->name = $5;
CONN_FETCH($$)->filter = CONN_MATCHER($6);
- $$->cmd = CONNECTION_FETCH;
+ $$->cmd = SDB_CONNECTION_FETCH;
}
;
conn_list_t, conn_list_destroy));
CONN_LIST($$)->type = $2;
CONN_LIST($$)->filter = CONN_MATCHER($3);
- $$->cmd = CONNECTION_LIST;
+ $$->cmd = SDB_CONNECTION_LIST;
}
;
CONN_LOOKUP($$)->type = $2;
CONN_LOOKUP($$)->matcher = CONN_MATCHER($3);
CONN_LOOKUP($$)->filter = CONN_MATCHER($4);
- $$->cmd = CONNECTION_LOOKUP;
+ $$->cmd = SDB_CONNECTION_LOOKUP;
}
;
CONN_TS($$)->metric = $4;
CONN_TS($$)->opts.start = $5;
CONN_TS($$)->opts.end = $6;
- $$->cmd = CONNECTION_TIMESERIES;
+ $$->cmd = SDB_CONNECTION_TIMESERIES;
}
;
$$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL,
conn_matcher_t, conn_matcher_destroy));
- $$->cmd = CONNECTION_MATCHER;
+ $$->cmd = SDB_CONNECTION_MATCHER;
CONN_MATCHER($$)->matcher = $1;
}
;
diff --git a/src/frontend/parser.c b/src/frontend/parser.c
index c38799dd5ddd53161ac37f981a1e418f410a5dfb..c82a514a00e7ddb4831805dafbbed8c9c618888e 100644 (file)
--- a/src/frontend/parser.c
+++ b/src/frontend/parser.c
return NULL;
}
- assert(node->cmd == CONNECTION_MATCHER);
+ assert(node->cmd == SDB_CONNECTION_MATCHER);
m = CONN_MATCHER(node)->matcher;
CONN_MATCHER(node)->matcher = NULL;
return NULL;
}
- assert(node->cmd == CONNECTION_EXPR);
+ assert(node->cmd == SDB_CONNECTION_EXPR);
e = CONN_EXPR(node)->expr;
CONN_EXPR(node)->expr = NULL;
diff --git a/src/frontend/query.c b/src/frontend/query.c
index 6e94f646f2f9d1c20dc2f12dbd30236283dda21a..35ff1026d1d84686d10468b9fe5046d5a14d7a41 100644 (file)
--- a/src/frontend/query.c
+++ b/src/frontend/query.c
sdb_conn_node_t *node = NULL;
int status = 0;
- if ((! conn) || (conn->cmd != CONNECTION_QUERY))
+ if ((! conn) || (conn->cmd != SDB_CONNECTION_QUERY))
return -1;
parsetree = sdb_fe_parse(sdb_strbuf_string(conn->buf),
switch (sdb_llist_len(parsetree)) {
case 0:
/* skipping empty command; send back an empty reply */
- sdb_connection_send(conn, CONNECTION_DATA, 0, NULL);
+ sdb_connection_send(conn, SDB_CONNECTION_DATA, 0, NULL);
break;
case 1:
node = SDB_CONN_NODE(sdb_llist_get(parsetree, 0));
char name[conn->cmd_len + 1];
int type;
- if ((! conn) || (conn->cmd != CONNECTION_FETCH))
+ if ((! conn) || (conn->cmd != SDB_CONNECTION_FETCH))
return -1;
if (conn->cmd_len < sizeof(uint32_t)) {
{
int type = SDB_HOST;
- if ((! conn) || (conn->cmd != CONNECTION_LIST))
+ if ((! conn) || (conn->cmd != SDB_CONNECTION_LIST))
return -1;
if (conn->cmd_len == sizeof(uint32_t))
int status;
conn_matcher_t m_node = {
- { SDB_OBJECT_INIT, CONNECTION_MATCHER }, NULL
+ { SDB_OBJECT_INIT, SDB_CONNECTION_MATCHER }, NULL
};
conn_lookup_t node = {
- { SDB_OBJECT_INIT, CONNECTION_LOOKUP },
+ { SDB_OBJECT_INIT, SDB_CONNECTION_LOOKUP },
-1, &m_node, NULL
};
- if ((! conn) || (conn->cmd != CONNECTION_LOOKUP))
+ if ((! conn) || (conn->cmd != SDB_CONNECTION_LOOKUP))
return -1;
if (conn->cmd_len < sizeof(uint32_t)) {
return -1;
switch (node->cmd) {
- case CONNECTION_FETCH:
+ case SDB_CONNECTION_FETCH:
if (CONN_FETCH(node)->filter)
filter = CONN_FETCH(node)->filter->matcher;
return sdb_fe_exec_fetch(conn, CONN_FETCH(node)->type,
CONN_FETCH(node)->host, CONN_FETCH(node)->name, filter);
- case CONNECTION_LIST:
+ case SDB_CONNECTION_LIST:
if (CONN_LIST(node)->filter)
filter = CONN_LIST(node)->filter->matcher;
return sdb_fe_exec_list(conn, CONN_LIST(node)->type, filter);
- case CONNECTION_LOOKUP:
+ case SDB_CONNECTION_LOOKUP:
if (CONN_LOOKUP(node)->matcher)
m = CONN_LOOKUP(node)->matcher->matcher;
if (CONN_LOOKUP(node)->filter)
filter = CONN_LOOKUP(node)->filter->matcher;
return sdb_fe_exec_lookup(conn,
CONN_LOOKUP(node)->type, m, filter);
- case CONNECTION_TIMESERIES:
+ case SDB_CONNECTION_TIMESERIES:
return sdb_fe_exec_timeseries(conn,
CONN_TS(node)->hostname, CONN_TS(node)->metric,
&CONN_TS(node)->opts);
sdb_fe_exec_fetch(sdb_conn_t *conn, int type,
const char *hostname, const char *name, sdb_store_matcher_t *filter)
{
- uint32_t res_type = htonl(CONNECTION_FETCH);
+ uint32_t res_type = htonl(SDB_CONNECTION_FETCH);
sdb_store_obj_t *host;
sdb_store_obj_t *obj;
}
sdb_store_json_finish(f);
- sdb_connection_send(conn, CONNECTION_DATA,
+ sdb_connection_send(conn, SDB_CONNECTION_DATA,
(uint32_t)sdb_strbuf_len(buf), sdb_strbuf_string(buf));
sdb_strbuf_destroy(buf);
free(f);
int
sdb_fe_exec_list(sdb_conn_t *conn, int type, sdb_store_matcher_t *filter)
{
- uint32_t res_type = htonl(CONNECTION_LIST);
+ uint32_t res_type = htonl(SDB_CONNECTION_LIST);
sdb_store_json_formatter_t *f;
sdb_strbuf_t *buf;
}
sdb_store_json_finish(f);
- sdb_connection_send(conn, CONNECTION_DATA,
+ sdb_connection_send(conn, SDB_CONNECTION_DATA,
(uint32_t)sdb_strbuf_len(buf), sdb_strbuf_string(buf));
sdb_strbuf_destroy(buf);
free(f);
sdb_fe_exec_lookup(sdb_conn_t *conn, int type,
sdb_store_matcher_t *m, sdb_store_matcher_t *filter)
{
- uint32_t res_type = htonl(CONNECTION_LOOKUP);
+ uint32_t res_type = htonl(SDB_CONNECTION_LOOKUP);
sdb_store_json_formatter_t *f;
sdb_strbuf_t *buf;
}
sdb_store_json_finish(f);
- sdb_connection_send(conn, CONNECTION_DATA,
+ sdb_connection_send(conn, SDB_CONNECTION_DATA,
(uint32_t)sdb_strbuf_len(buf), sdb_strbuf_string(buf));
sdb_strbuf_destroy(buf);
free(f);
sdb_timeseries_opts_t *opts)
{
sdb_strbuf_t *buf;
- uint32_t res_type = htonl(CONNECTION_TIMESERIES);
+ uint32_t res_type = htonl(SDB_CONNECTION_TIMESERIES);
buf = sdb_strbuf_create(1024);
if (! buf) {
return -1;
}
- sdb_connection_send(conn, CONNECTION_DATA,
+ sdb_connection_send(conn, SDB_CONNECTION_DATA,
(uint32_t)sdb_strbuf_len(buf), sdb_strbuf_string(buf));
sdb_strbuf_destroy(buf);
return 0;
diff --git a/src/frontend/session.c b/src/frontend/session.c
index 0587c50a5f2a405ea03f801c481d197ce488db02..b0fc7803e2a0e23ab53a05cc6a1c694c4251b824 100644 (file)
--- a/src/frontend/session.c
+++ b/src/frontend/session.c
if ((! conn) || (conn->username))
return -1;
- if (conn->cmd != CONNECTION_STARTUP)
+ if (conn->cmd != SDB_CONNECTION_STARTUP)
return -1;
username = sdb_strbuf_string(conn->buf);
sdb_strbuf_sprintf(conn->errbuf, "Authentication failed");
return -1;
}
- sdb_connection_send(conn, CONNECTION_OK, 0, NULL);
+ sdb_connection_send(conn, SDB_CONNECTION_OK, 0, NULL);
conn->ready = 1;
return 0;
} /* sdb_fe_session_start */
index b329fa1ec9d8b3c003207b0c197085aeed6c29d6..5dc2b1a8c5ce35105f7b57b972b3dd924bca3ab8 100644 (file)
/*
* sdb_fe_query, sdb_fe_fetch, sdb_fe_list, sdb_fe_lookup:
- * Handle the CONNECTION_QUERY, CONNECTION_FETCH, CONNECTION_LIST, and
- * CONNECTION_LOOKUP commands respectively. It is expected that the current
- * command has been initialized already.
+ * Handle the SDB_CONNECTION_QUERY, SDB_CONNECTION_FETCH, SDB_CONNECTION_LIST,
+ * and SDB_CONNECTION_LOOKUP commands respectively. It is expected that the
+ * current command has been initialized already.
*
* Returns:
* - 0 on success
index 3819e3f07ce953309c73265a8f81c82a9fd5e924..7aae68dde622a0ebe7835c796a46c216838b7de8 100644 (file)
*/
/*
- * CONNECTION_OK:
+ * SDB_CONNECTION_OK:
* Indicates that a command was successful. The message body will usually
* be empty but may contain a string providing unformatted information
* providing more details.
* +---------------+---------------+
* | optional status message ... |
*/
- CONNECTION_OK = 0,
+ SDB_CONNECTION_OK = 0,
/*
- * CONNECTION_ERROR:
+ * SDB_CONNECTION_ERROR:
* Indicates that a command has failed. The message body will contain a
* string describing the error.
*
* +---------------+---------------+
* | error message ... |
*/
- CONNECTION_ERROR,
+ SDB_CONNECTION_ERROR,
/*
- * CONNECTION_LOG:
+ * SDB_CONNECTION_LOG:
* Indicates an asynchronous log message. The message body will contain
* the log priority (see utils/error.h) and message. Log messages may be
* sent to the client any time.
* +---------------+ |
* | ... |
*/
- CONNECTION_LOG,
+ SDB_CONNECTION_LOG,
/*
* Query-result specific messages.
*/
/*
- * CONNECTION_DATA:
+ * SDB_CONNECTION_DATA:
* Indicates that a data query was successful. The message body will
* contain the type of the data and the result encoded as a JSON string.
* The type is the same as the command code of the respective command (see
* +---------------+ |
* | ... |
*/
- CONNECTION_DATA = 100,
+ SDB_CONNECTION_DATA = 100,
} sdb_conn_status_t;
/* accepted commands / state of the connection */
typedef enum {
/*
- * CONNECTION_IDLE:
+ * SDB_CONNECTION_IDLE:
* This is an internal state used for idle connections.
*/
- CONNECTION_IDLE = 0,
+ SDB_CONNECTION_IDLE = 0,
/*
- * CONNECTION_PING:
+ * SDB_CONNECTION_PING:
* Check if the current connection is still alive. The server will reply
- * with CONNECTION_OK and an empty message body if it was able to handle
- * the command.
+ * with SDB_CONNECTION_OK and an empty message body if it was able to
+ * handle the command.
*
* 0 32 64
* +---------------+---------------+
* | PING | 0 |
* +---------------+---------------+
*/
- CONNECTION_PING,
+ SDB_CONNECTION_PING,
/*
- * CONNECTION_STARTUP:
+ * SDB_CONNECTION_STARTUP:
* Setup of a client connection. The message body shall include the
* username of the user contacting the server. The server may then send
* further requests to the client for authentication (not implemented
* yet). Once the setup and authentication was successful, the server
- * replies with CONNECTION_OK. Further information may be requested from
- * the server using special messages specific to the authentication
+ * replies with SDB_CONNECTION_OK. Further information may be requested
+ * from the server using special messages specific to the authentication
* method. The server does not send any asynchronous messages before
* startup is complete.
*
* +---------------+---------------+
* | username ... |
*/
- CONNECTION_STARTUP,
+ SDB_CONNECTION_STARTUP,
/*
* Querying the server. On success, the server replies with
- * CONNECTION_DATA.
+ * SDB_CONNECTION_DATA.
*
* The command codes listed here are used, both, for sending a query to
* the server and to indicate the response type from a query in a DATA
*/
/*
- * CONNECTION_QUERY:
+ * SDB_CONNECTION_QUERY:
* Execute a query in the server. The message body shall include a single
* query command as a text string. Multiple commands are ignored by the
* server entirely to protect against injection attacks.
* +---------------+---------------+
* | query string ... |
*/
- CONNECTION_QUERY,
+ SDB_CONNECTION_QUERY,
/*
- * CONNECTION_FETCH:
+ * SDB_CONNECTION_FETCH:
* Execute the 'FETCH' command in the server. The message body shall
* include the type and the identifier of the object to be retrieved.
* Hosts are identified by their name. Other types are not supported yet.
* +---------------+ |
* | ... |
*/
- CONNECTION_FETCH,
+ SDB_CONNECTION_FETCH,
/*
- * CONNECTION_LIST:
+ * SDB_CONNECTION_LIST:
* Execute the 'LIST' command in the server. The message body may include
* the type of the objects to be listed, encoded as a 32bit integer in
* network byte-order. The response includes all hosts and the respective
* | [object type] |
* +---------------+
*/
- CONNECTION_LIST,
+ SDB_CONNECTION_LIST,
/*
- * CONNECTION_LOOKUP:
+ * SDB_CONNECTION_LOOKUP:
* Execute the 'LOOKUP' command in the server. The message body shall
* include the type of the objects to look up and a string representing
* the conditional expression of the 'MATCHING' clause. The type is
* +---------------+ |
* | clause ... |
*/
- CONNECTION_LOOKUP,
+ SDB_CONNECTION_LOOKUP,
/*
- * CONNECTION_TIMESERIES:
+ * SDB_CONNECTION_TIMESERIES:
* Execute the 'TIMESERIES' command in the server. This command is not yet
- * supported on the wire. Use CONNECTION_QUERY instead.
+ * supported on the wire. Use SDB_CONNECTION_QUERY instead.
*/
- CONNECTION_TIMESERIES,
+ SDB_CONNECTION_TIMESERIES,
/*
* Command subcomponents.
*/
/*
- * CONNECTION_MATCHER:
+ * SDB_CONNECTION_MATCHER:
* A parsed matcher. Only used internally.
*/
- CONNECTION_MATCHER = 100,
+ SDB_CONNECTION_MATCHER = 100,
/*
- * CONNECTION_EXPR:
+ * SDB_CONNECTION_EXPR:
* A parsed expression. Only used internally.
*/
- CONNECTION_EXPR,
+ SDB_CONNECTION_EXPR,
} sdb_conn_state_t;
#ifdef __cplusplus
index 81f679233d969ccb203f5f938c07e6d5f98fd693..143661868d49204c9436bdd2e370a1346881df71 100644 (file)
int status;
void (*printer)(sdb_strbuf_t *);
} response_printers[] = {
- { CONNECTION_LOG, log_printer },
- { CONNECTION_DATA, data_printer },
+ { SDB_CONNECTION_LOG, log_printer },
+ { SDB_CONNECTION_DATA, data_printer },
};
/*
data = strndup(query, query_len);
/* ignore errors; we'll only hide the command from the caller */
- sdb_client_send(input->client, CONNECTION_QUERY, query_len, query);
+ sdb_client_send(input->client, SDB_CONNECTION_QUERY, query_len, query);
/* The server will send back *something*, either error/log messages
* and/or the reply to the query. Here, we don't care about what it
diff --git a/src/tools/sysdb/main.c b/src/tools/sysdb/main.c
index 331cfa25e640912ac79ac6b37c44d3a91f374323..6e75ef9b6c7687484848739fda8eeeaf3c85a233 100644 (file)
--- a/src/tools/sysdb/main.c
+++ b/src/tools/sysdb/main.c
while (sdb_llist_iter_has_next(iter)) {
sdb_object_t *obj = sdb_llist_iter_get_next(iter);
- if (sdb_client_send(client, CONNECTION_QUERY,
+ if (sdb_client_send(client, SDB_CONNECTION_QUERY,
(uint32_t)strlen(obj->name), obj->name) <= 0) {
sdb_log(SDB_LOG_ERR, "Failed to send command '%s' to server",
obj->name);
break;
}
- if ((status == CONNECTION_DATA) || (status == CONNECTION_ERROR))
+ if ((status == SDB_CONNECTION_DATA)
+ || (status == SDB_CONNECTION_ERROR))
break;
- if (status == CONNECTION_OK) {
+ if (status == SDB_CONNECTION_OK) {
/* pre 0.4 versions used OK instead of DATA */
sdb_log(SDB_LOG_WARNING, "Received unexpected OK status from "
"server in response to a QUERY (expected DATA); "
}
}
- if ((status != CONNECTION_OK) && (status != CONNECTION_DATA))
+ if ((status != SDB_CONNECTION_OK) && (status != SDB_CONNECTION_DATA))
break; /* error */
}
int status = execute_commands(input.client, commands);
sdb_llist_destroy(commands);
sdb_client_destroy(input.client);
- if ((status != CONNECTION_OK) && (status != CONNECTION_DATA))
+ if ((status != SDB_CONNECTION_OK) && (status != SDB_CONNECTION_DATA))
exit(1);
exit(0);
}
index ea933233d2f8bf9e21611a761b0ecc4a7f20e35f..77828e6a8c4220d482a1eaaf69c6ec03b142fca0 100644 (file)
unlink(tmp_file);
- conn->cmd = CONNECTION_IDLE;
+ conn->cmd = SDB_CONNECTION_IDLE;
conn->cmd_len = 0;
return conn;
} /* mock_conn_create */
ssize_t check, expected;
expected = 2 * sizeof(uint32_t) + strlen("fakeuser");
- check = sdb_connection_send(conn, CONNECTION_STARTUP,
+ check = sdb_connection_send(conn, SDB_CONNECTION_STARTUP,
(uint32_t)strlen("fakeuser"), "fakeuser");
fail_unless(check == expected,
"sdb_connection_send(STARTUP, fakeuser) = %zi; expected: %zi",
const char *err;
} golden_data[] = {
/* code == UINT32_MAX => no data will be sent */
- { UINT32_MAX, NULL, NULL },
- { CONNECTION_IDLE, "fakedata", "Authentication required" },
- { CONNECTION_PING, NULL, "Authentication required" },
- { CONNECTION_STARTUP, "fakeuser", NULL },
- { CONNECTION_PING, NULL, NULL },
- { CONNECTION_IDLE, NULL, "Invalid command 0" },
- { CONNECTION_PING, "fakedata", NULL },
- { CONNECTION_IDLE, NULL, "Invalid command 0" },
+ { UINT32_MAX, NULL, NULL },
+ { SDB_CONNECTION_IDLE, "fakedata", "Authentication required" },
+ { SDB_CONNECTION_PING, NULL, "Authentication required" },
+ { SDB_CONNECTION_STARTUP, "fakeuser", NULL },
+ { SDB_CONNECTION_PING, NULL, NULL },
+ { SDB_CONNECTION_IDLE, NULL, "Invalid command 0" },
+ { SDB_CONNECTION_PING, "fakedata", NULL },
+ { SDB_CONNECTION_IDLE, NULL, "Invalid command 0" },
};
size_t i;
const char *err;
} golden_data[] = {
/* code == UINT32_MAX => this is a follow-up package */
- { CONNECTION_PING, 20, "9876543210", 0, "Authentication required" },
- { UINT32_MAX, -1, "9876543210", 0, "Authentication required" },
- { CONNECTION_PING, 10, "9876543210", 0, "Authentication required" },
- { CONNECTION_IDLE, 10, "9876543210", 0, "Authentication required" },
- { CONNECTION_IDLE, 20, "9876543210", 0, "Authentication required" },
- { UINT32_MAX, -1, "9876543210", 0, "Authentication required" },
- { CONNECTION_STARTUP, -1, NULL, 0, NULL },
- { CONNECTION_PING, 20, "9876543210", 10, NULL },
- { UINT32_MAX, -1, "9876543210", 0, NULL },
- { CONNECTION_IDLE, 20, "9876543210", 0, "Invalid command 0" },
- { UINT32_MAX, -1, "9876543210", 0, "Invalid command 0" },
- { CONNECTION_IDLE, 20, "9876543210", 0, "Invalid command 0" },
- { UINT32_MAX, -1, "9876543210", 0, "Invalid command 0" },
- { CONNECTION_PING, 10, "9876543210", 0, NULL },
- { CONNECTION_PING, 20, "9876543210", 10, NULL },
- { UINT32_MAX, -1, "9876543210", 0, NULL },
+ { SDB_CONNECTION_PING, 20, "9876543210", 0, "Authentication required" },
+ { UINT32_MAX, -1, "9876543210", 0, "Authentication required" },
+ { SDB_CONNECTION_PING, 10, "9876543210", 0, "Authentication required" },
+ { SDB_CONNECTION_IDLE, 10, "9876543210", 0, "Authentication required" },
+ { SDB_CONNECTION_IDLE, 20, "9876543210", 0, "Authentication required" },
+ { UINT32_MAX, -1, "9876543210", 0, "Authentication required" },
+ { SDB_CONNECTION_STARTUP, -1, NULL, 0, NULL },
+ { SDB_CONNECTION_PING, 20, "9876543210", 10, NULL },
+ { UINT32_MAX, -1, "9876543210", 0, NULL },
+ { SDB_CONNECTION_IDLE, 20, "9876543210", 0, "Invalid command 0" },
+ { UINT32_MAX, -1, "9876543210", 0, "Invalid command 0" },
+ { SDB_CONNECTION_IDLE, 20, "9876543210", 0, "Invalid command 0" },
+ { UINT32_MAX, -1, "9876543210", 0, "Invalid command 0" },
+ { SDB_CONNECTION_PING, 10, "9876543210", 0, NULL },
+ { SDB_CONNECTION_PING, 20, "9876543210", 10, NULL },
+ { UINT32_MAX, -1, "9876543210", 0, NULL },
};
size_t i;
mock_conn_truncate(conn);
- if (golden_data[i].code == CONNECTION_STARTUP) {
+ if (golden_data[i].code == SDB_CONNECTION_STARTUP) {
connection_startup(conn);
continue;
}
golden_data[i].buf_len);
}
else {
- fail_unless(conn->cmd == CONNECTION_IDLE,
+ fail_unless(conn->cmd == SDB_CONNECTION_IDLE,
"sdb_connection_read() did not reset command; "
- "got %u; expected: %u", conn->cmd, CONNECTION_IDLE);
+ "got %u; expected: %u", conn->cmd, SDB_CONNECTION_IDLE);
fail_unless(conn->cmd_len == 0,
"sdb_connection_read() did not reset command length; "
"got %u; expected: 0", conn->cmd_len);
index 17c1032bcd0168c94fb9a9ae5873d111c6eb3926..2368bcc4d3efe821a5342aa25ee07316ff69e7e1 100644 (file)
{ ";;", -1, 0, 0 },
/* valid commands */
- { "FETCH host 'host'", -1, 1, CONNECTION_FETCH },
+ { "FETCH host 'host'", -1, 1, SDB_CONNECTION_FETCH },
{ "FETCH host 'host' FILTER "
- "age > 60s", -1, 1, CONNECTION_FETCH },
+ "age > 60s", -1, 1, SDB_CONNECTION_FETCH },
{ "FETCH service "
- "'host'.'service'", -1, 1, CONNECTION_FETCH },
+ "'host'.'service'", -1, 1, SDB_CONNECTION_FETCH },
{ "FETCH metric "
- "'host'.'metric'", -1, 1, CONNECTION_FETCH },
+ "'host'.'metric'", -1, 1, SDB_CONNECTION_FETCH },
- { "LIST hosts", -1, 1, CONNECTION_LIST },
- { "LIST hosts -- foo", -1, 1, CONNECTION_LIST },
- { "LIST hosts;", -1, 1, CONNECTION_LIST },
- { "LIST hosts; INVALID", 11, 1, CONNECTION_LIST },
+ { "LIST hosts", -1, 1, SDB_CONNECTION_LIST },
+ { "LIST hosts -- foo", -1, 1, SDB_CONNECTION_LIST },
+ { "LIST hosts;", -1, 1, SDB_CONNECTION_LIST },
+ { "LIST hosts; INVALID", 11, 1, SDB_CONNECTION_LIST },
{ "LIST hosts FILTER "
- "age > 60s", -1, 1, CONNECTION_LIST },
- { "LIST services", -1, 1, CONNECTION_LIST },
+ "age > 60s", -1, 1, SDB_CONNECTION_LIST },
+ { "LIST services", -1, 1, SDB_CONNECTION_LIST },
{ "LIST services FILTER "
- "age > 60s", -1, 1, CONNECTION_LIST },
- { "LIST metrics", -1, 1, CONNECTION_LIST },
+ "age > 60s", -1, 1, SDB_CONNECTION_LIST },
+ { "LIST metrics", -1, 1, SDB_CONNECTION_LIST },
{ "LIST metrics FILTER "
- "age > 60s", -1, 1, CONNECTION_LIST },
+ "age > 60s", -1, 1, SDB_CONNECTION_LIST },
- { "LOOKUP hosts", -1, 1, CONNECTION_LOOKUP },
+ { "LOOKUP hosts", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
- "name = 'host'", -1, 1, CONNECTION_LOOKUP },
+ "name = 'host'", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING NOT "
- "name = 'host'", -1, 1, CONNECTION_LOOKUP },
+ "name = 'host'", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
"name =~ 'p' AND "
- "ANY service =~ 'p'", -1, 1, CONNECTION_LOOKUP },
+ "ANY service =~ 'p'", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING NOT "
"name =~ 'p' AND "
- "ANY service =~ 'p'", -1, 1, CONNECTION_LOOKUP },
+ "ANY service =~ 'p'", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
"name =~ 'p' AND "
"ANY service =~ 'p' OR "
- "ANY service =~ 'r'", -1, 1, CONNECTION_LOOKUP },
+ "ANY service =~ 'r'", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING NOT "
"name =~ 'p' AND "
"ANY service =~ 'p' OR "
- "ANY service =~ 'r'", -1, 1, CONNECTION_LOOKUP },
+ "ANY service =~ 'r'", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
"name =~ 'p' "
- "FILTER age > 1D", -1, 1, CONNECTION_LOOKUP },
+ "FILTER age > 1D", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
"name =~ 'p' "
"FILTER age > 1D AND "
- "interval < 240s" , -1, 1, CONNECTION_LOOKUP },
+ "interval < 240s" , -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
"name =~ 'p' "
- "FILTER NOT age>1D", -1, 1, CONNECTION_LOOKUP },
+ "FILTER NOT age>1D", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
"name =~ 'p' "
"FILTER age>"
- "interval", -1, 1, CONNECTION_LOOKUP },
- { "LOOKUP services", -1, 1, CONNECTION_LOOKUP },
+ "interval", -1, 1, SDB_CONNECTION_LOOKUP },
+ { "LOOKUP services", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP services MATCHING ANY "
- "attribute =~ 'a'", -1, 1, CONNECTION_LOOKUP },
- { "LOOKUP metrics", -1, 1, CONNECTION_LOOKUP },
+ "attribute =~ 'a'", -1, 1, SDB_CONNECTION_LOOKUP },
+ { "LOOKUP metrics", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP metrics MATCHING ANY "
- "attribute =~ 'a'", -1, 1, CONNECTION_LOOKUP },
+ "attribute =~ 'a'", -1, 1, SDB_CONNECTION_LOOKUP },
{ "TIMESERIES 'host'.'metric' "
"START 2014-01-01 "
"END 2014-12-31 "
- "23:59:59", -1, 1, CONNECTION_TIMESERIES },
+ "23:59:59", -1, 1, SDB_CONNECTION_TIMESERIES },
{ "TIMESERIES 'host'.'metric' "
"START 2014-02-02 "
- "14:02", -1, 1, CONNECTION_TIMESERIES },
+ "14:02", -1, 1, SDB_CONNECTION_TIMESERIES },
{ "TIMESERIES 'host'.'metric' "
- "END 2014-02-02", -1, 1, CONNECTION_TIMESERIES },
+ "END 2014-02-02", -1, 1, SDB_CONNECTION_TIMESERIES },
{ "TIMESERIES "
- "'host'.'metric'", -1, 1, CONNECTION_TIMESERIES },
+ "'host'.'metric'", -1, 1, SDB_CONNECTION_TIMESERIES },
/* string constants */
{ "LOOKUP hosts MATCHING "
- "name = ''''", -1, 1, CONNECTION_LOOKUP },
+ "name = ''''", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
- "name = '''foo'", -1, 1, CONNECTION_LOOKUP },
+ "name = '''foo'", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
- "name = 'f''oo'", -1, 1, CONNECTION_LOOKUP },
+ "name = 'f''oo'", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
- "name = 'foo'''", -1, 1, CONNECTION_LOOKUP },
+ "name = 'foo'''", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
"name = '''", -1, -1, 0 },
/* numeric constants */
{ "LOOKUP hosts MATCHING "
"attribute['foo'] = "
- "1234", -1, 1, CONNECTION_LOOKUP },
+ "1234", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
"attribute['foo'] != "
- "+234", -1, 1, CONNECTION_LOOKUP },
+ "+234", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
"attribute['foo'] < "
- "-234", -1, 1, CONNECTION_LOOKUP },
+ "-234", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
"attribute['foo'] > "
- "12.4", -1, 1, CONNECTION_LOOKUP },
+ "12.4", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
"attribute['foo'] <= "
- "12. + .3", -1, 1, CONNECTION_LOOKUP },
+ "12. + .3", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
"attribute['foo'] <= "
- "'f' || 'oo'", -1, 1, CONNECTION_LOOKUP },
+ "'f' || 'oo'", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
"attribute['foo'] >= "
- ".4", -1, 1, CONNECTION_LOOKUP },
+ ".4", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
"attribute['foo'] = "
- "+12e3", -1, 1, CONNECTION_LOOKUP },
+ "+12e3", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
"attribute['foo'] = "
- "+12e-3", -1, 1, CONNECTION_LOOKUP },
+ "+12e-3", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
"attribute['foo'] = "
- "-12e+3", -1, 1, CONNECTION_LOOKUP },
+ "-12e+3", -1, 1, SDB_CONNECTION_LOOKUP },
/* date, time, interval constants */
{ "LOOKUP hosts MATCHING "
"attribute['foo'] = "
- "1 Y 42D", -1, 1, CONNECTION_LOOKUP },
+ "1 Y 42D", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
"attribute['foo'] = "
- "1s 42D", -1, 1, CONNECTION_LOOKUP },
+ "1s 42D", -1, 1, SDB_CONNECTION_LOOKUP },
/*
* TODO: Something like 1Y42D should work as well but it doesn't since
* the scanner will tokenize it into {digit}{identifier} :-/
*
{ "LOOKUP hosts MATCHING "
"attribute['foo'] = "
- "1Y42D", -1, 1, CONNECTION_LOOKUP },
+ "1Y42D", -1, 1, SDB_CONNECTION_LOOKUP },
*/
/* NULL */
{ "LOOKUP hosts MATCHING "
"attribute['foo'] "
- "IS NULL", -1, 1, CONNECTION_LOOKUP },
+ "IS NULL", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
"attribute['foo'] "
- "IS NOT NULL", -1, 1, CONNECTION_LOOKUP },
+ "IS NOT NULL", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
"NOT attribute['foo'] "
- "IS NULL", -1, 1, CONNECTION_LOOKUP },
+ "IS NULL", -1, 1, SDB_CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
"ANY service IS NULL", -1, -1, 0 },