X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=src%2Finclude%2Futils%2Fproto.h;h=56715630524594a71e524932def3f1a01a9f7670;hp=6f0907feee2c2e5243e61e2c37ce47419a7539b2;hb=5637e2d8b66c64cb4ce2e205c0f6912cd8f9eb54;hpb=90064393a1c5c27ef0ae05652e6672814772fdce diff --git a/src/include/utils/proto.h b/src/include/utils/proto.h index 6f0907f..5671563 100644 --- a/src/include/utils/proto.h +++ b/src/include/utils/proto.h @@ -28,7 +28,7 @@ #ifndef SDB_UTILS_PROTO_H #define SDB_UTILS_PROTO_H 1 -#include "utils/strbuf.h" +#include "core/data.h" #include #include @@ -37,6 +37,43 @@ extern "C" { #endif +/* + * sdb_proto_host, sdb_proto_service, sdb_proto_metric: + * Protocol-specific representations of the basic information of stored + * objects. + */ +typedef struct { + sdb_time_t last_update; + const char *name; +} sdb_proto_host_t; +#define SDB_PROTO_HOST_INIT { 0, NULL } + +typedef struct { + sdb_time_t last_update; + const char *hostname; + const char *name; +} sdb_proto_service_t; +#define SDB_PROTO_SERVICE_INIT { 0, NULL, NULL } + +typedef struct { + sdb_time_t last_update; + const char *hostname; + const char *name; + const char *store_type; /* optional */ + const char *store_id; /* optional */ +} sdb_proto_metric_t; +#define SDB_PROTO_METRIC_INIT { 0, NULL, NULL, NULL, NULL } + +typedef struct { + sdb_time_t last_update; + int parent_type; + const char *hostname; /* optional */ + const char *parent; + const char *key; + sdb_data_t value; +} sdb_proto_attribute_t; +#define SDB_PROTO_ATTRIBUTE_INIT { 0, 0, NULL, NULL, NULL, SDB_DATA_INIT } + /* * sdb_proto_marshal: * Encode the message into the wire format by adding an appropriate header. @@ -44,28 +81,129 @@ extern "C" { * the header (64 bits) and the entire message. * * Returns: - * - the number of bytes of the full encoded message on success (even if less - * than that fit into and was written to the buffer) + * - The number of bytes of the full encoded message on success. The function + * does not write more than 'buf_len' bytes. If the output was truncated + * then the return value is the number of bytes which would have been + * written if enough space had been available. * - a negative value on error */ ssize_t sdb_proto_marshal(char *buf, size_t buf_len, uint32_t code, uint32_t msg_len, const char *msg); +/* + * sdb_proto_marshal_int32: + * Encode the 32-bit integer into the wire format and write it to buf. + * + * Returns: + * - The number of bytes of the encoded value on success. The function does + * not write more than 'buf_len' bytes. If the output was truncated then + * the return value is the number of bytes which would have been written if + * enough space had been available. + * - a negative value else + */ +ssize_t +sdb_proto_marshal_int32(char *buf, size_t buf_len, uint32_t v); + +/* + * sdb_proto_marshal_data: + * Encode a datum into the wire format and write it to buf. + * + * Returns: + * - The number of bytes of the full encoded datum on success. The function + * does not write more than 'buf_len' bytes. If the output was truncated + * then the return value is the number of bytes which would have been + * written if enough space had been available. + * - a negative value else + */ +ssize_t +sdb_proto_marshal_data(char *buf, size_t buf_len, const sdb_data_t *datum); + +/* + * sdb_proto_marshal_host, sdb_proto_marshal_service, + * sdb_proto_marshal_metric, sdb_proto_marshal_attribute: + * Encode the basic information of a stored object into the wire format and + * write it to buf. These functions are similar to the sdb_store_ + * functions. See their documentation for details about the arguments. + * + * Returns: + * - The number of bytes of the full encoded datum on success. The function + * does not write more than 'buf_len' bytes. If the output was truncated + * then the return value is the number of bytes which would have been + * written if enough space had been available. + * - a negative value else + */ +ssize_t +sdb_proto_marshal_host(char *buf, size_t buf_len, + const sdb_proto_host_t *host); +ssize_t +sdb_proto_marshal_service(char *buf, size_t buf_len, + const sdb_proto_service_t *svc); +ssize_t +sdb_proto_marshal_metric(char *buf, size_t buf_len, + const sdb_proto_metric_t *metric); +ssize_t +sdb_proto_marshal_attribute(char *buf, size_t buf_len, + const sdb_proto_attribute_t *attr); + /* * sdb_proto_unmarshal_header: - * Read and decode a message header from the specified string buffer. + * Read and decode a message header from the specified string. * * Returns: - * - 0 on success + * - the number of bytes read on success * - a negative value else */ -int -sdb_proto_unmarshal_header(sdb_strbuf_t *buf, +ssize_t +sdb_proto_unmarshal_header(const char *buf, size_t buf_len, uint32_t *code, uint32_t *msg_len); -uint32_t -sdb_proto_get_int(sdb_strbuf_t *buf, size_t offset); +/* + * sdb_proto_unmarshal_int32: + * Read and decode a 32-bit integer from the specified string. + * + * Returns: + * - the number of bytes read on success + * - a negative value else + */ +ssize_t +sdb_proto_unmarshal_int32(const char *buf, size_t buf_len, uint32_t *v); + +/* + * sdb_proto_unmarshal_data: + * Read and decode a datum from the specified string. The datum's data will be + * allocated dynamically if necessary and will have to be free'd using + * sdb_data_free_datum. + * + * Returns: + * - the number of bytes read on success + * - a negative value else + */ +ssize_t +sdb_proto_unmarshal_data(const char *buf, size_t len, sdb_data_t *datum); + +/* + * sdb_proto_unmarshal_host, sdb_proto_unmarshal_service, + * sdb_proto_unmarshal_metric, sdb_proto_unmarshal_attribute: + * Read and decode a host, service, metric, or attribute object from the + * specified string. + * + * Returns: + * - the number of bytes read on success + * - a negative value else + */ +ssize_t +sdb_proto_unmarshal_host(const char *buf, size_t len, + sdb_proto_host_t *host); +ssize_t +sdb_proto_unmarshal_service(const char *buf, size_t len, + sdb_proto_service_t *svc); +ssize_t +sdb_proto_unmarshal_metric(const char *buf, size_t len, + sdb_proto_metric_t *metric); +ssize_t +sdb_proto_unmarshal_attribute(const char *buf, size_t len, + sdb_proto_attribute_t *attr); #ifdef __cplusplus } /* extern "C" */