From f9d911e867544260ca862478d5b13f0f89377acb Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 28 Jul 2014 19:30:25 +0200 Subject: doc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/mds-echo.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/mds-echo.c b/src/mds-echo.c index 82acc34..4867e90 100644 --- a/src/mds-echo.c +++ b/src/mds-echo.c @@ -267,6 +267,8 @@ int echo_message(void) const char* recv_length = NULL; size_t i, n; + /* Fetch headers. */ + #define __get_header(storage, header, skip) \ (startswith(received.headers[i], header)) \ storage = received.headers[i] + skip * strlen(header) @@ -278,6 +280,8 @@ int echo_message(void) else if __get_header(recv_length, "Length: ", 0); else continue; + + /* Stop fetch headers if we have found everything we want. */ if (recv_client_id && recv_message_id && recv_length) break; } @@ -285,6 +289,7 @@ int echo_message(void) #undef __get_header + /* Validate headers. */ if ((recv_client_id == NULL) || (strequals(recv_client_id, "0:0"))) { eprint("received message from anonymous sender, ignoring."); @@ -296,6 +301,8 @@ int echo_message(void) return 0; } + /* Construct echo message headers. */ + n = 1 + strlen("To: \nIn response to: \nMessage ID: \n\n"); n += strlen(recv_client_id) + strlen(recv_message_id) + 3 * sizeof(int32_t); if (recv_length != NULL) @@ -316,8 +323,10 @@ int echo_message(void) recv_length == NULL ? "" : recv_length, recv_length == NULL ? "" : "\n"); + /* Increase message ID */ message_id = message_id == INT32_MAX ? 0 : (message_id + 1); + /* Send echo. */ if (full_send(echo_buffer, strlen(echo_buffer))) return 1; return full_send(received.payload, received.payload_size); -- cgit v1.2.3-70-g09d2