From: Sebastian Harl Date: Wed, 24 Dec 2014 11:58:02 +0000 (+0100) Subject: Add a suffix to integer marshal/unmarshal functions specifying the int size. X-Git-Tag: sysdb-0.7.0~97 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=147e814d602f90e411a948613e85e627f5858018;p=sysdb.git Add a suffix to integer marshal/unmarshal functions specifying the int size. --- diff --git a/src/client/sock.c b/src/client/sock.c index 6f231bd..bed6fc0 100644 --- a/src/client/sock.c +++ b/src/client/sock.c @@ -309,8 +309,8 @@ sdb_client_recv(sdb_client_t *client, /* retrieve status and data len */ assert(len >= 2 * sizeof(uint32_t)); - rstatus = sdb_proto_unmarshal_int(str, len); - rlen = sdb_proto_unmarshal_int(str + sizeof(rstatus), + rstatus = sdb_proto_unmarshal_int32(str, len); + rlen = sdb_proto_unmarshal_int32(str + sizeof(rstatus), len - sizeof(rstatus)); if (! rlen) diff --git a/src/frontend/query.c b/src/frontend/query.c index 1c5b1f2..933ca04 100644 --- a/src/frontend/query.c +++ b/src/frontend/query.c @@ -132,7 +132,7 @@ sdb_fe_fetch(sdb_conn_t *conn) return -1; } - type = sdb_proto_unmarshal_int(SDB_STRBUF_STR(conn->buf)); + type = sdb_proto_unmarshal_int32(SDB_STRBUF_STR(conn->buf)); strncpy(name, sdb_strbuf_string(conn->buf) + sizeof(uint32_t), conn->cmd_len - sizeof(uint32_t)); name[sizeof(name) - 1] = '\0'; @@ -149,7 +149,7 @@ sdb_fe_list(sdb_conn_t *conn) return -1; if (conn->cmd_len == sizeof(uint32_t)) - type = sdb_proto_unmarshal_int(SDB_STRBUF_STR(conn->buf)); + type = sdb_proto_unmarshal_int32(SDB_STRBUF_STR(conn->buf)); else if (conn->cmd_len) { sdb_log(SDB_LOG_ERR, "frontend: Invalid command length %d for " "LIST command", conn->cmd_len); @@ -188,7 +188,7 @@ sdb_fe_lookup(sdb_conn_t *conn) conn->cmd_len); return -1; } - type = sdb_proto_unmarshal_int(SDB_STRBUF_STR(conn->buf)); + type = sdb_proto_unmarshal_int32(SDB_STRBUF_STR(conn->buf)); matcher = sdb_strbuf_string(conn->buf) + sizeof(uint32_t); matcher_len = conn->cmd_len - sizeof(uint32_t); diff --git a/src/include/utils/proto.h b/src/include/utils/proto.h index 4968977..ab01cf5 100644 --- a/src/include/utils/proto.h +++ b/src/include/utils/proto.h @@ -81,11 +81,11 @@ sdb_proto_unmarshal_header(const char *buf, size_t buf_len, uint32_t *code, uint32_t *msg_len); /* - * sdb_proto_unmarshal_int: - * Read and decode an integer from the specified string. + * sdb_proto_unmarshal_int32: + * Read and decode a 32-bit integer from the specified string. */ uint32_t -sdb_proto_unmarshal_int(const char *buf, size_t buf_len); +sdb_proto_unmarshal_int32(const char *buf, size_t buf_len); #ifdef __cplusplus } /* extern "C" */ diff --git a/src/tools/sysdb/command.c b/src/tools/sysdb/command.c index 78deb71..2706dd2 100644 --- a/src/tools/sysdb/command.c +++ b/src/tools/sysdb/command.c @@ -49,7 +49,7 @@ static void log_printer(sdb_strbuf_t *buf) { - uint32_t prio = sdb_proto_unmarshal_int(SDB_STRBUF_STR(buf)); + uint32_t prio = sdb_proto_unmarshal_int32(SDB_STRBUF_STR(buf)); if (prio == UINT32_MAX) { sdb_log(SDB_LOG_WARNING, "Received a LOG message with invalid " diff --git a/src/utils/proto.c b/src/utils/proto.c index 51c2ed8..beaa07e 100644 --- a/src/utils/proto.c +++ b/src/utils/proto.c @@ -54,7 +54,7 @@ * been available. */ static ssize_t -marshal_int(char *buf, size_t buf_len, int64_t v) +marshal_int64(char *buf, size_t buf_len, int64_t v) { if (buf_len >= sizeof(v)) { #if __BYTE_ORDER != __BIG_ENDIAN @@ -64,7 +64,7 @@ marshal_int(char *buf, size_t buf_len, int64_t v) memcpy(buf, &v, sizeof(v)); } return sizeof(v); -} /* marshal_int */ +} /* marshal_int64 */ static ssize_t marshal_double(char *buf, size_t buf_len, double v) @@ -84,7 +84,7 @@ marshal_double(char *buf, size_t buf_len, double v) static ssize_t marshal_datetime(char *buf, size_t buf_len, sdb_time_t v) { - return marshal_int(buf, buf_len, (int64_t)v); + return marshal_int64(buf, buf_len, (int64_t)v); } /* marshal_datetime */ static ssize_t @@ -154,7 +154,7 @@ sdb_proto_marshal_data(char *buf, size_t buf_len, sdb_data_t *datum) return len; if (datum->type == SDB_TYPE_INTEGER) - n = marshal_int(buf, buf_len, datum->data.integer); + n = marshal_int64(buf, buf_len, datum->data.integer); else if (datum->type == SDB_TYPE_DECIMAL) n = marshal_double(buf, buf_len, datum->data.decimal); else if (datum->type == SDB_TYPE_STRING) @@ -192,7 +192,7 @@ sdb_proto_marshal_data(char *buf, size_t buf_len, sdb_data_t *datum) for (i = 0; i < datum->data.array.length; ++i) { if (type == SDB_TYPE_INTEGER) { int64_t *v = datum->data.array.values; - n = marshal_int(buf, buf_len, v[i]); + n = marshal_int64(buf, buf_len, v[i]); } else if (type == SDB_TYPE_DECIMAL) { double *v = datum->data.array.values; @@ -247,10 +247,10 @@ sdb_proto_unmarshal_header(const char *buf, size_t buf_len, if (buf_len < 2 * sizeof(uint32_t)) return -1; - tmp = sdb_proto_unmarshal_int(buf, buf_len); + tmp = sdb_proto_unmarshal_int32(buf, buf_len); if (code) *code = tmp; - tmp = sdb_proto_unmarshal_int(buf + sizeof(uint32_t), + tmp = sdb_proto_unmarshal_int32(buf + sizeof(uint32_t), buf_len - sizeof(uint32_t)); if (msg_len) *msg_len = tmp; @@ -258,7 +258,7 @@ sdb_proto_unmarshal_header(const char *buf, size_t buf_len, } /* sdb_proto_unmarshal_header */ uint32_t -sdb_proto_unmarshal_int(const char *buf, size_t buf_len) +sdb_proto_unmarshal_int32(const char *buf, size_t buf_len) { uint32_t n; @@ -268,7 +268,7 @@ sdb_proto_unmarshal_int(const char *buf, size_t buf_len) memcpy(&n, buf, sizeof(n)); return ntohl(n); -} /* sdb_proto_unmarshal_int */ +} /* sdb_proto_unmarshal_int32 */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */