summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a884382)
raw | patch | inline | side by side (parent: a884382)
author | Sebastian Harl <sh@tokkee.org> | |
Sun, 5 Oct 2014 14:25:36 +0000 (16:25 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sun, 5 Oct 2014 14:25:36 +0000 (16:25 +0200) |
The respective commands only support hosts at the moment but this change
prepares the wire-format to support other types as well.
prepares the wire-format to support other types as well.
index dd4bcced2b4c99fa63c781654218c1f68ff761d7..85f278c74dd374d56c24011f06bb6a568f32cd26 100644 (file)
typedef struct {
sdb_conn_node_t super;
+ int type;
char *name;
conn_matcher_t *filter;
} conn_fetch_t;
typedef struct {
sdb_conn_node_t super;
+ int type;
conn_matcher_t *matcher;
conn_matcher_t *filter;
} conn_lookup_t;
diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y
index 129b4613009c9d5fc12aa71d2a470c0b02feed31..f13bbad7c011c8f07ecc53a1c9c8e16a39e9d61c 100644 (file)
--- a/src/frontend/grammar.y
+++ b/src/frontend/grammar.y
$$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL,
conn_fetch_t, conn_fetch_destroy));
+ CONN_FETCH($$)->type = SDB_HOST;
CONN_FETCH($$)->name = $3;
CONN_FETCH($$)->filter = CONN_MATCHER($4);
$$->cmd = CONNECTION_FETCH;
$$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL,
conn_lookup_t, conn_lookup_destroy));
+ CONN_LOOKUP($$)->type = SDB_HOST;
CONN_LOOKUP($$)->matcher = CONN_MATCHER($3);
CONN_LOOKUP($$)->filter = CONN_MATCHER($4);
$$->cmd = CONNECTION_LOOKUP;
diff --git a/src/frontend/query.c b/src/frontend/query.c
index 1751ba57e7a9a241b148cbc4f4dc391787cf0c44..39b5d53004da6774ad6395ade472e22cc33971b7 100644 (file)
--- a/src/frontend/query.c
+++ b/src/frontend/query.c
int
sdb_fe_fetch(sdb_conn_t *conn)
{
- char hostname[conn->cmd_len + 1];
+ char name[conn->cmd_len + 1];
+ int type;
+
if ((! conn) || (conn->cmd != CONNECTION_FETCH))
return -1;
- strncpy(hostname, sdb_strbuf_string(conn->buf), conn->cmd_len);
- hostname[sizeof(hostname) - 1] = '\0';
- return sdb_fe_exec_fetch(conn, hostname, /* filter = */ NULL);
+
+ if (conn->cmd_len < sizeof(type)) {
+ sdb_log(SDB_LOG_ERR, "frontend: Invalid command length %d for "
+ "FETCH command", conn->cmd_len);
+ sdb_strbuf_sprintf(conn->errbuf, "FETCH: Invalid command length %d",
+ conn->cmd_len);
+ return -1;
+ }
+
+ type = sdb_proto_get_int(conn->buf, 0);
+ strncpy(name, sdb_strbuf_string(conn->buf) + sizeof(type),
+ conn->cmd_len - sizeof(type));
+ name[sizeof(name) - 1] = '\0';
+ return sdb_fe_exec_fetch(conn, type, name, /* filter = */ NULL);
} /* sdb_fe_fetch */
int
sdb_fe_lookup(sdb_conn_t *conn)
{
sdb_store_matcher_t *m;
+ const char *matcher;
+ size_t matcher_len;
+
+ uint32_t type;
int status;
if ((! conn) || (conn->cmd != CONNECTION_LOOKUP))
return -1;
- m = sdb_fe_parse_matcher(sdb_strbuf_string(conn->buf),
- (int)conn->cmd_len);
+ if (conn->cmd_len < sizeof(type)) {
+ sdb_log(SDB_LOG_ERR, "frontend: Invalid command length %d for "
+ "LOOKUP command", conn->cmd_len);
+ sdb_strbuf_sprintf(conn->errbuf, "LOOKUP: Invalid command length %d",
+ conn->cmd_len);
+ return -1;
+ }
+ type = sdb_proto_get_int(conn->buf, 0);
+
+ matcher = sdb_strbuf_string(conn->buf) + sizeof(type);
+ matcher_len = conn->cmd_len - sizeof(type);
+ m = sdb_fe_parse_matcher(matcher, (int)matcher_len);
if (! m) {
- char expr[conn->cmd_len + 1];
- strncpy(expr, sdb_strbuf_string(conn->buf), conn->cmd_len);
+ char expr[matcher_len + 1];
+ strncpy(expr, matcher, sizeof(expr));
expr[sizeof(expr) - 1] = '\0';
sdb_log(SDB_LOG_ERR, "frontend: Failed to parse "
"lookup condition '%s'", expr);
return -1;
}
- status = sdb_fe_exec_lookup(conn, m, /* filter = */ NULL);
+ status = sdb_fe_exec_lookup(conn, type, m, /* filter = */ NULL);
sdb_object_deref(SDB_OBJ(m));
return status;
} /* sdb_fe_lookup */
case CONNECTION_FETCH:
if (CONN_FETCH(node)->filter)
filter = CONN_FETCH(node)->filter->matcher;
- return sdb_fe_exec_fetch(conn, CONN_FETCH(node)->name, filter);
+ return sdb_fe_exec_fetch(conn, CONN_FETCH(node)->type,
+ CONN_FETCH(node)->name, filter);
case CONNECTION_LIST:
if (CONN_LIST(node)->filter)
filter = CONN_LIST(node)->filter->matcher;
m = CONN_LOOKUP(node)->matcher->matcher;
if (CONN_LOOKUP(node)->filter)
filter = CONN_LOOKUP(node)->filter->matcher;
- return sdb_fe_exec_lookup(conn, m, filter);
+ return sdb_fe_exec_lookup(conn,
+ CONN_LOOKUP(node)->type, m, filter);
case CONNECTION_TIMESERIES:
return sdb_fe_exec_timeseries(conn,
CONN_TS(node)->hostname, CONN_TS(node)->metric,
} /* sdb_fe_exec */
int
-sdb_fe_exec_fetch(sdb_conn_t *conn, const char *name,
+sdb_fe_exec_fetch(sdb_conn_t *conn, int type, const char *name,
sdb_store_matcher_t *filter)
{
sdb_strbuf_t *buf;
sdb_store_obj_t *host;
uint32_t res_type = htonl(CONNECTION_FETCH);
+ /* XXX: support other types */
+ if (type != SDB_HOST) {
+ sdb_log(SDB_LOG_ERR, "frontend: Invalid object type %d "
+ "in FETCH command", type);
+ sdb_strbuf_sprintf(conn->errbuf,
+ "FETCH: Invalid object type %d", type);
+ return -1;
+ }
+
host = sdb_store_get_host(name);
if (! host) {
sdb_log(SDB_LOG_DEBUG, "frontend: Failed to fetch host '%s': "
} /* sdb_fe_exec_list */
int
-sdb_fe_exec_lookup(sdb_conn_t *conn, sdb_store_matcher_t *m,
- sdb_store_matcher_t *filter)
+sdb_fe_exec_lookup(sdb_conn_t *conn, int type,
+ sdb_store_matcher_t *m, sdb_store_matcher_t *filter)
{
tojson_data_t data = { NULL, filter, 0 };
uint32_t res_type = htonl(CONNECTION_LOOKUP);
+ /* XXX: support other types */
+ if (type != SDB_HOST) {
+ sdb_log(SDB_LOG_ERR, "frontend: Invalid object type %d "
+ "in LOOKUP command", type);
+ sdb_strbuf_sprintf(conn->errbuf,
+ "LOOKUP: Invalid object type %d", type);
+ return -1;
+ }
+
data.buf = sdb_strbuf_create(1024);
if (! data.buf) {
char errbuf[1024];
index 8189470d4347721dab0aebeeb526e0e32ec90e07..a890bd0ffae75d16fa1e39909c12fb5c0621d86b 100644 (file)
/*
* sdb_fe_exec_fetch:
- * Execute the 'FETCH' command. Send the named host, serialized as JSON, to
- * the client. If specified, only objects matching the filter will be
- * included. See sdb_store_tojson for details.
+ * Execute the 'FETCH' command. Send the named object of the specified type,
+ * serialized as JSON, to the client. If specified, only objects matching the
+ * filter will be included. See sdb_store_tojson for details.
*
* Returns:
* - 0 on success
* - a negative value else
*/
int
-sdb_fe_exec_fetch(sdb_conn_t *conn, const char *name,
+sdb_fe_exec_fetch(sdb_conn_t *conn, int type, const char *name,
sdb_store_matcher_t *filter);
/*
/*
* sdb_fe_exec_lookup:
- * Execute the 'LOOKUP' command. Send a list of hosts matching 'm', serialized
- * as JSON, to the client. If specified, only objects matching the filter will
- * be included. See sdb_store_tojson for details.
+ * Execute the 'LOOKUP' command. Send a list of objects of the specified type
+ * matching 'm', serialized as JSON, to the client. If specified, only objects
+ * matching the filter will be included. See sdb_store_tojson for details.
*
* Returns:
* - 0 on success
* - a negative value else
*/
int
-sdb_fe_exec_lookup(sdb_conn_t *conn, sdb_store_matcher_t *m,
- sdb_store_matcher_t *filter);
+sdb_fe_exec_lookup(sdb_conn_t *conn, int type,
+ sdb_store_matcher_t *m, sdb_store_matcher_t *filter);
/*
* sdb_fe_exec_timeseries:
index de45f736b02b310e69b6aac0e45cb4c530eb19fb..e9001cbb413003b01e8a3ab745827e228eaab3fa 100644 (file)
/*
* CONNECTION_FETCH:
* Execute the 'FETCH' command in the server. The message body shall
- * include the hostname of the host to be retrieved.
+ * include the type and the identifier of the object to be retrieved.
+ * Hosts are identified by their name. Other types are not supported yet.
+ * The type is encoded as a 32bit integer in network byte-order.
*/
CONNECTION_FETCH,
/*
* CONNECTION_LIST:
* Execute the 'LIST' command in the server. The message body may include
- * the type of the objects to be included in addition to all hosts,
- * encoded as a 32bit integer in network byte-order.
+ * 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
+ * child objects. By default, all hosts are listed.
*/
CONNECTION_LIST,
/*
* CONNECTION_LOOKUP:
* Execute the 'LOOKUP' command in the server. The message body shall
- * include the conditional expression of the 'MATCHING' clause.
+ * include the type of the objects to look up and a string representing
+ * the conditional expression of the 'MATCHING' clause. The type is
+ * encoded as a 32bit integer in network byte-order.
*/
CONNECTION_LOOKUP,