move repository from m6w6 to awesomized
[awesomized/libmemcached] / src / libmemcachedprotocol / binary_handler.c
index ada4c42599cc999fe62c50d796fbe175b2cebdae..84151cfed4f23fa02f686ba483507fe8a66407c6 100644 (file)
@@ -9,11 +9,12 @@
     | the terms online at: https://opensource.org/licenses/BSD-3-Clause  |
     +--------------------------------------------------------------------+
     | Copyright (c) 2006-2014 Brian Aker   https://datadifferential.com/ |
-    | Copyright (c) 2020 Michael Wallner   <mike@php.net>                |
+    | Copyright (c) 2020-2021 Michael Wallner        https://awesome.co/ |
     +--------------------------------------------------------------------+
 */
 
 #include "libmemcachedprotocol/common.h"
+#include "p9y/socket.hpp"
 
 #include <stdlib.h>
 #include <sys/types.h>
@@ -43,7 +44,7 @@ binary_raw_response_handler(const void *cookie, protocol_binary_request_header *
                             protocol_binary_response_header *response) {
   memcached_protocol_client_st *client = (void *) cookie;
 
-  if (client->root->pedantic
+  if (response && client->root->pedantic
       && !memcached_binary_protocol_pedantic_check_response(request, response)) {
     return PROTOCOL_BINARY_RESPONSE_EINVAL;
   }
@@ -52,6 +53,10 @@ binary_raw_response_handler(const void *cookie, protocol_binary_request_header *
     return PROTOCOL_BINARY_RESPONSE_EINTERNAL;
   }
 
+  if (!response) {
+    return PROTOCOL_BINARY_RESPONSE_SUCCESS;
+  }
+
   size_t len = sizeof(protocol_binary_response_header) + htonl(response->response.bodylen);
   size_t offset = 0;
   char *ptr = (void *) response;
@@ -916,6 +921,20 @@ stat_command_handler(const void *cookie, protocol_binary_request_header *header,
 
     rval = client->root->callback->interface.v1.stat(cookie, (void *) (header + 1), keylen,
                                                      stat_response_handler);
+    if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS) {
+      /* END message */
+      protocol_binary_response_no_extras response = {
+          .message = {
+              .header.response =
+                  {
+                      .magic = PROTOCOL_BINARY_RES,
+                      .opcode = PROTOCOL_BINARY_CMD_STAT,
+                      .status = htons(PROTOCOL_BINARY_RESPONSE_SUCCESS),
+                      .opaque = header->request.opaque,
+                  },
+          }};
+      rval = response_handler(cookie, header, &response);
+    }
   } else {
     rval = PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND;
   }
@@ -940,6 +959,9 @@ version_command_handler(const void *cookie, protocol_binary_request_header *head
   memcached_protocol_client_st *client = (void *) cookie;
   if (client->root->callback->interface.v1.version) {
     rval = client->root->callback->interface.v1.version(cookie, version_response_handler);
+    if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS) {
+      rval = response_handler(cookie, header, NULL);
+    }
   } else {
     rval = PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND;
   }