From cee285517b2811898aa85dc2f5c6e137158ec4cf Mon Sep 17 00:00:00 2001
From: Roman Tsisyk <roman@tarantool.org>
Date: Thu, 27 Jul 2017 15:44:43 +0300
Subject: [PATCH] xrow: move call_request/auth_request to xrow.cc

No semantic changes.

Follow up #2619 and #2507
---
 src/box/authentication.cc |  67 ------------------
 src/box/authentication.h  |  32 ---------
 src/box/call.cc           |  80 ---------------------
 src/box/call.h            |  34 ---------
 src/box/iproto.cc         |   1 -
 src/box/xrow.c            | 144 ++++++++++++++++++++++++++++++++++++++
 src/box/xrow.h            |  48 +++++++++++++
 7 files changed, 192 insertions(+), 214 deletions(-)

diff --git a/src/box/authentication.cc b/src/box/authentication.cc
index c078e55c74..802d1a64cb 100644
--- a/src/box/authentication.cc
+++ b/src/box/authentication.cc
@@ -31,76 +31,9 @@
 #include "authentication.h"
 #include "user.h"
 #include "session.h"
-#include "iproto_constants.h"
-#include "xrow.h"
 
 static char zero_hash[SCRAMBLE_SIZE];
 
-int
-xrow_decode_auth(const struct xrow_header *row, struct auth_request *request)
-{
-	if (row->bodycnt == 0) {
-		diag_set(ClientError, ER_INVALID_MSGPACK,
-			 "missing request body");
-		return 1;
-	}
-
-	assert(row->bodycnt == 1);
-	const char *data = (const char *) row->body[0].iov_base;
-	const char *end = data + row->body[0].iov_len;
-	assert((end - data) > 0);
-
-	if (mp_typeof(*data) != MP_MAP || mp_check_map(data, end) > 0) {
-error:
-		diag_set(ClientError, ER_INVALID_MSGPACK, "packet body");
-		return 1;
-	}
-
-	memset(request, 0, sizeof(*request));
-	request->header = row;
-
-	uint32_t map_size = mp_decode_map(&data);
-	for (uint32_t i = 0; i < map_size; ++i) {
-		if ((end - data) < 1 || mp_typeof(*data) != MP_UINT)
-			goto error;
-
-		uint64_t key = mp_decode_uint(&data);
-		const char *value = data;
-		if (mp_check(&data, end) != 0)
-			goto error;
-
-		switch (key) {
-		case IPROTO_USER_NAME:
-			if (mp_typeof(*value) != MP_STR)
-				goto error;
-			request->user_name = value;
-			break;
-		case IPROTO_TUPLE:
-			if (mp_typeof(*value) != MP_ARRAY)
-				goto error;
-			request->scramble = value;
-			break;
-		default:
-			continue; /* unknown key */
-		}
-	}
-	if (data != end) {
-		diag_set(ClientError, ER_INVALID_MSGPACK, "packet end");
-		return 1;
-	}
-	if (request->user_name == NULL) {
-		diag_set(ClientError, ER_MISSING_REQUEST_FIELD,
-			  iproto_key_name(IPROTO_USER_NAME));
-		return 1;
-	}
-	if (request->scramble == NULL) {
-		diag_set(ClientError, ER_MISSING_REQUEST_FIELD,
-			 iproto_key_name(IPROTO_TUPLE));
-		return 1;
-	}
-	return 0;
-}
-
 void
 authenticate(const char *user_name, uint32_t len,
 	     const char *tuple)
diff --git a/src/box/authentication.h b/src/box/authentication.h
index 1cf9d6d873..f719d1c507 100644
--- a/src/box/authentication.h
+++ b/src/box/authentication.h
@@ -33,38 +33,6 @@
 
 #include <stdint.h>
 
-#if defined(__cplusplus)
-extern "C" {
-#endif /* defined(__cplusplus) */
-
-struct xrow_header;
-
-/**
- * AUTH request
- */
-struct auth_request {
-	/** Request header */
-	const struct xrow_header *header;
-	/** MessagePack encoded name of the user to authenticate. */
-	const char *user_name;
-	/** Auth scramble. @sa scramble.h */
-	const char *scramble;
-};
-
-/**
- * Decode AUTH request from MessagePack.
- * @param row request header.
- * @param[out] request Request to decode.
- * @retval  0 on success
- * @retval -1 on error
- */
-int
-xrow_decode_auth(const struct xrow_header *row, struct auth_request *request);
-
-#if defined(__cplusplus)
-} /* extern "C" */
-#endif /* defined(__cplusplus) */
-
 void
 authenticate(const char *user_name, uint32_t len, const char *tuple);
 
diff --git a/src/box/call.cc b/src/box/call.cc
index 59b0d66f56..3e07ac7dad 100644
--- a/src/box/call.cc
+++ b/src/box/call.cc
@@ -43,86 +43,6 @@
 #include "rmean.h"
 #include "small/obuf.h"
 
-static const char empty_args[] = { (char)0x90 };
-
-int
-xrow_decode_call(const struct xrow_header *row, struct call_request *request)
-{
-	if (row->bodycnt == 0) {
-		diag_set(ClientError, ER_INVALID_MSGPACK,
-			 "missing request body");
-		return 1;
-	}
-
-	assert(row->bodycnt == 1);
-	const char *data = (const char *) row->body[0].iov_base;
-	const char *end = data + row->body[0].iov_len;
-	assert((end - data) > 0);
-
-	if (mp_typeof(*data) != MP_MAP || mp_check_map(data, end) > 0) {
-error:
-		diag_set(ClientError, ER_INVALID_MSGPACK, "packet body");
-		return 1;
-	}
-
-	memset(request, 0, sizeof(*request));
-	request->header = row;
-
-	uint32_t map_size = mp_decode_map(&data);
-	for (uint32_t i = 0; i < map_size; ++i) {
-		if ((end - data) < 1 || mp_typeof(*data) != MP_UINT)
-			goto error;
-
-		uint64_t key = mp_decode_uint(&data);
-		const char *value = data;
-		if (mp_check(&data, end) != 0)
-			goto error;
-
-		switch (key) {
-		case IPROTO_FUNCTION_NAME:
-			if (mp_typeof(*value) != MP_STR)
-				goto error;
-			request->name = value;
-			break;
-		case IPROTO_EXPR:
-			if (mp_typeof(*value) != MP_STR)
-				goto error;
-			request->expr = value;
-			break;
-		case IPROTO_TUPLE:
-			if (mp_typeof(*value) != MP_ARRAY)
-				goto error;
-			request->args = value;
-			request->args_end = data;
-			break;
-		default:
-			continue; /* unknown key */
-		}
-	}
-	if (data != end) {
-		diag_set(ClientError, ER_INVALID_MSGPACK, "packet end");
-		return 1;
-	}
-	if (row->type == IPROTO_EVAL) {
-		if (request->expr == NULL) {
-			diag_set(ClientError, ER_MISSING_REQUEST_FIELD,
-				 iproto_key_name(IPROTO_EXPR));
-			return 1;
-		}
-	} else if (request->name == NULL) {
-		assert(row->type == IPROTO_CALL_16 ||
-		       row->type == IPROTO_CALL);
-		diag_set(ClientError, ER_MISSING_REQUEST_FIELD,
-			 iproto_key_name(IPROTO_FUNCTION_NAME));
-		return 1;
-	}
-	if (request->args == NULL) {
-		request->args = empty_args;
-		request->args_end = empty_args + sizeof(empty_args);
-	}
-	return 0;
-}
-
 static inline struct func *
 access_check_func(const char *name, uint32_t name_len)
 {
diff --git a/src/box/call.h b/src/box/call.h
index fd0e4ca285..826ca4d5fe 100644
--- a/src/box/call.h
+++ b/src/box/call.h
@@ -33,40 +33,6 @@
 
 #include <stdint.h>
 
-#if defined(__cplusplus)
-extern "C" {
-#endif /* defined(__cplusplus) */
-
-/**
- * CALL/EVAL request.
- */
-struct call_request {
-	/** Request header */
-	const struct xrow_header *header;
-	/** Function name for CALL request. MessagePack String. */
-	const char *name;
-	/** Expression for EVAL request. MessagePack String. */
-	const char *expr;
-	/** CALL/EVAL parameters. MessagePack Array. */
-	const char *args;
-	const char *args_end;
-};
-
-/**
- * Decode CALL/EVAL request from a given MessagePack map.
- * @param[out] call_request Request to decode to.
- * @param type Request type - either CALL or CALL_16 or EVAL.
- * @param sync Request sync.
- * @param data Request MessagePack encoded body.
- * @param len @data length.
- */
-int
-xrow_decode_call(const struct xrow_header *row, struct call_request *request);
-
-#if defined(__cplusplus)
-} /* extern "C" */
-#endif /* defined(__cplusplus) */
-
 struct obuf;
 
 struct box_function_ctx {
diff --git a/src/box/iproto.cc b/src/box/iproto.cc
index 7f14fc648d..33addaf426 100644
--- a/src/box/iproto.cc
+++ b/src/box/iproto.cc
@@ -51,7 +51,6 @@
 #include "iobuf.h"
 #include "box.h"
 #include "call.h"
-#include "authentication.h"
 #include "tuple.h"
 #include "session.h"
 #include "xrow.h"
diff --git a/src/box/xrow.c b/src/box/xrow.c
index cb4b38e561..20d4088584 100644
--- a/src/box/xrow.c
+++ b/src/box/xrow.c
@@ -522,6 +522,150 @@ xrow_to_iovec(const struct xrow_header *row, struct iovec *out)
 	return iovcnt;
 }
 
+int
+xrow_decode_call(const struct xrow_header *row, struct call_request *request)
+{
+	if (row->bodycnt == 0) {
+		diag_set(ClientError, ER_INVALID_MSGPACK,
+			 "missing request body");
+		return 1;
+	}
+
+	assert(row->bodycnt == 1);
+	const char *data = (const char *) row->body[0].iov_base;
+	const char *end = data + row->body[0].iov_len;
+	assert((end - data) > 0);
+
+	if (mp_typeof(*data) != MP_MAP || mp_check_map(data, end) > 0) {
+error:
+		diag_set(ClientError, ER_INVALID_MSGPACK, "packet body");
+		return 1;
+	}
+
+	memset(request, 0, sizeof(*request));
+	request->header = row;
+
+	uint32_t map_size = mp_decode_map(&data);
+	for (uint32_t i = 0; i < map_size; ++i) {
+		if ((end - data) < 1 || mp_typeof(*data) != MP_UINT)
+			goto error;
+
+		uint64_t key = mp_decode_uint(&data);
+		const char *value = data;
+		if (mp_check(&data, end) != 0)
+			goto error;
+
+		switch (key) {
+		case IPROTO_FUNCTION_NAME:
+			if (mp_typeof(*value) != MP_STR)
+				goto error;
+			request->name = value;
+			break;
+		case IPROTO_EXPR:
+			if (mp_typeof(*value) != MP_STR)
+				goto error;
+			request->expr = value;
+			break;
+		case IPROTO_TUPLE:
+			if (mp_typeof(*value) != MP_ARRAY)
+				goto error;
+			request->args = value;
+			request->args_end = data;
+			break;
+		default:
+			continue; /* unknown key */
+		}
+	}
+	if (data != end) {
+		diag_set(ClientError, ER_INVALID_MSGPACK, "packet end");
+		return 1;
+	}
+	if (row->type == IPROTO_EVAL) {
+		if (request->expr == NULL) {
+			diag_set(ClientError, ER_MISSING_REQUEST_FIELD,
+				 iproto_key_name(IPROTO_EXPR));
+			return 1;
+		}
+	} else if (request->name == NULL) {
+		assert(row->type == IPROTO_CALL_16 ||
+		       row->type == IPROTO_CALL);
+		diag_set(ClientError, ER_MISSING_REQUEST_FIELD,
+			 iproto_key_name(IPROTO_FUNCTION_NAME));
+		return 1;
+	}
+	if (request->args == NULL) {
+		static const char empty_args[] = { (char)0x90 };
+		request->args = empty_args;
+		request->args_end = empty_args + sizeof(empty_args);
+	}
+	return 0;
+}
+
+int
+xrow_decode_auth(const struct xrow_header *row, struct auth_request *request)
+{
+	if (row->bodycnt == 0) {
+		diag_set(ClientError, ER_INVALID_MSGPACK,
+			 "missing request body");
+		return 1;
+	}
+
+	assert(row->bodycnt == 1);
+	const char *data = (const char *) row->body[0].iov_base;
+	const char *end = data + row->body[0].iov_len;
+	assert((end - data) > 0);
+
+	if (mp_typeof(*data) != MP_MAP || mp_check_map(data, end) > 0) {
+error:
+		diag_set(ClientError, ER_INVALID_MSGPACK, "packet body");
+		return 1;
+	}
+
+	memset(request, 0, sizeof(*request));
+	request->header = row;
+
+	uint32_t map_size = mp_decode_map(&data);
+	for (uint32_t i = 0; i < map_size; ++i) {
+		if ((end - data) < 1 || mp_typeof(*data) != MP_UINT)
+			goto error;
+
+		uint64_t key = mp_decode_uint(&data);
+		const char *value = data;
+		if (mp_check(&data, end) != 0)
+			goto error;
+
+		switch (key) {
+		case IPROTO_USER_NAME:
+			if (mp_typeof(*value) != MP_STR)
+				goto error;
+			request->user_name = value;
+			break;
+		case IPROTO_TUPLE:
+			if (mp_typeof(*value) != MP_ARRAY)
+				goto error;
+			request->scramble = value;
+			break;
+		default:
+			continue; /* unknown key */
+		}
+	}
+	if (data != end) {
+		diag_set(ClientError, ER_INVALID_MSGPACK, "packet end");
+		return 1;
+	}
+	if (request->user_name == NULL) {
+		diag_set(ClientError, ER_MISSING_REQUEST_FIELD,
+			  iproto_key_name(IPROTO_USER_NAME));
+		return 1;
+	}
+	if (request->scramble == NULL) {
+		diag_set(ClientError, ER_MISSING_REQUEST_FIELD,
+			 iproto_key_name(IPROTO_TUPLE));
+		return 1;
+	}
+	return 0;
+}
+
 int
 xrow_encode_auth(struct xrow_header *packet, const char *salt, size_t salt_len,
 		 const char *login, size_t login_len,
diff --git a/src/box/xrow.h b/src/box/xrow.h
index 072bd41b69..2eb0c4e86e 100644
--- a/src/box/xrow.h
+++ b/src/box/xrow.h
@@ -106,6 +106,54 @@ xrow_header_decode(struct xrow_header *header,
 struct request *
 xrow_decode_request(struct xrow_header *row);
 
+/**
+ * CALL/EVAL request.
+ */
+struct call_request {
+	/** Request header */
+	const struct xrow_header *header;
+	/** Function name for CALL request. MessagePack String. */
+	const char *name;
+	/** Expression for EVAL request. MessagePack String. */
+	const char *expr;
+	/** CALL/EVAL parameters. MessagePack Array. */
+	const char *args;
+	const char *args_end;
+};
+
+/**
+ * Decode CALL/EVAL request from a given MessagePack map.
+ * @param[out] call_request Request to decode to.
+ * @param type Request type - either CALL or CALL_16 or EVAL.
+ * @param sync Request sync.
+ * @param data Request MessagePack encoded body.
+ * @param len @data length.
+ */
+int
+xrow_decode_call(const struct xrow_header *row, struct call_request *request);
+
+/**
+ * AUTH request
+ */
+struct auth_request {
+	/** Request header */
+	const struct xrow_header *header;
+	/** MessagePack encoded name of the user to authenticate. */
+	const char *user_name;
+	/** Auth scramble. @sa scramble.h */
+	const char *scramble;
+};
+
+/**
+ * Decode AUTH request from MessagePack.
+ * @param row request header.
+ * @param[out] request Request to decode.
+ * @retval  0 on success
+ * @retval -1 on error
+ */
+int
+xrow_decode_auth(const struct xrow_header *row, struct auth_request *request);
+
 /**
  * Encode AUTH command.
  * @param[out] Row.
-- 
GitLab