/*
+--------------------------------------------------------------------+
- | libmemcached - C/C++ Client Library for memcached |
+ | libmemcached-awesome - C/C++ Client Library for memcached |
+--------------------------------------------------------------------+
| Redistribution and use in source and binary forms, with or without |
| modification, are permitted under the terms of the BSD license. |
| 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>
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;
}
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;
protocol_binary_response_status rval;
memcached_protocol_client_st *client = (void *) cookie;
- if (client->root->callback->interface.v1.add != NULL) {
+ if (client->root->callback->interface.v1.add) {
uint16_t keylen = ntohs(header->request.keylen);
uint32_t datalen = ntohl(header->request.bodylen) - keylen - 8;
protocol_binary_request_add *request = (void *) header;
protocol_binary_response_status rval;
memcached_protocol_client_st *client = (void *) cookie;
- if (client->root->callback->interface.v1.decrement != NULL) {
+ if (client->root->callback->interface.v1.decrement) {
uint16_t keylen = ntohs(header->request.keylen);
protocol_binary_request_decr *request = (void *) header;
uint64_t init = memcached_ntohll(request->message.body.initial);
protocol_binary_response_status rval;
memcached_protocol_client_st *client = (void *) cookie;
- if (client->root->callback->interface.v1.delete_object != NULL) {
+ if (client->root->callback->interface.v1.delete_object) {
uint16_t keylen = ntohs(header->request.keylen);
void *key = (header + 1);
uint64_t cas = memcached_ntohll(header->request.cas);
protocol_binary_response_status rval;
memcached_protocol_client_st *client = (void *) cookie;
- if (client->root->callback->interface.v1.flush_object != NULL) {
+ if (client->root->callback->interface.v1.flush_object) {
protocol_binary_request_flush *flush_object = (void *) header;
uint32_t timeout = 0;
if (htonl(header->request.bodylen) == 4) {
protocol_binary_response_status rval;
memcached_protocol_client_st *client = (void *) cookie;
- if (client->root->callback->interface.v1.get != NULL) {
+ if (client->root->callback->interface.v1.get) {
uint16_t keylen = ntohs(header->request.keylen);
void *key = (header + 1);
rval = client->root->callback->interface.v1.get(cookie, key, keylen, get_response_handler);
protocol_binary_response_status rval;
memcached_protocol_client_st *client = (void *) cookie;
- if (client->root->callback->interface.v1.increment != NULL) {
+ if (client->root->callback->interface.v1.increment) {
uint16_t keylen = ntohs(header->request.keylen);
protocol_binary_request_incr *request = (void *) header;
uint64_t init = memcached_ntohll(request->message.body.initial);
noop_command_handler(const void *cookie, protocol_binary_request_header *header,
memcached_binary_protocol_raw_response_handler response_handler) {
memcached_protocol_client_st *client = (void *) cookie;
- if (client->root->callback->interface.v1.noop != NULL) {
+ if (client->root->callback->interface.v1.noop) {
client->root->callback->interface.v1.noop(cookie);
}
protocol_binary_response_status rval;
memcached_protocol_client_st *client = (void *) cookie;
- if (client->root->callback->interface.v1.append != NULL) {
+ if (client->root->callback->interface.v1.append) {
uint16_t keylen = ntohs(header->request.keylen);
uint32_t datalen = ntohl(header->request.bodylen) - keylen;
char *key = (void *) (header + 1);
protocol_binary_response_status rval;
memcached_protocol_client_st *client = (void *) cookie;
- if (client->root->callback->interface.v1.prepend != NULL) {
+ if (client->root->callback->interface.v1.prepend) {
uint16_t keylen = ntohs(header->request.keylen);
uint32_t datalen = ntohl(header->request.bodylen) - keylen;
char *key = (char *) (header + 1);
quit_command_handler(const void *cookie, protocol_binary_request_header *header,
memcached_binary_protocol_raw_response_handler response_handler) {
memcached_protocol_client_st *client = (void *) cookie;
- if (client->root->callback->interface.v1.quit != NULL) {
+ if (client->root->callback->interface.v1.quit) {
client->root->callback->interface.v1.quit(cookie);
}
protocol_binary_response_status rval;
memcached_protocol_client_st *client = (void *) cookie;
- if (client->root->callback->interface.v1.replace != NULL) {
+ if (client->root->callback->interface.v1.replace) {
uint16_t keylen = ntohs(header->request.keylen);
uint32_t datalen = ntohl(header->request.bodylen) - keylen - 8;
protocol_binary_request_replace *request = (void *) header;
protocol_binary_response_status rval;
memcached_protocol_client_st *client = (void *) cookie;
- if (client->root->callback->interface.v1.set != NULL) {
+ if (client->root->callback->interface.v1.set) {
uint16_t keylen = ntohs(header->request.keylen);
uint32_t datalen = ntohl(header->request.bodylen) - keylen - 8;
protocol_binary_request_replace *request = (void *) header;
protocol_binary_response_status rval;
memcached_protocol_client_st *client = (void *) cookie;
- if (client->root->callback->interface.v1.stat != NULL) {
+ if (client->root->callback->interface.v1.stat) {
uint16_t keylen = ntohs(header->request.keylen);
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, (void *) &response);
+ }
} else {
rval = PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND;
}
protocol_binary_response_status rval;
memcached_protocol_client_st *client = (void *) cookie;
- if (client->root->callback->interface.v1.version != NULL) {
+ 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;
}
}
/* we got all data available, execute the callback! */
- if (client->root->callback->pre_execute != NULL) {
+ if (client->root->callback->pre_execute) {
client->root->callback->pre_execute(client, header);
}
switch (client->root->callback->interface_version) {
case 0:
- if (client->root->callback->interface.v0.comcode[cc] != NULL) {
+ if (client->root->callback->interface.v0.comcode[cc]) {
rval = client->root->callback->interface.v0.comcode[cc](client, header,
binary_raw_response_handler);
}
break;
case 1:
- if (comcode_v0_v1_remap[cc] != NULL) {
+ if (comcode_v0_v1_remap[cc]) {
rval = comcode_v0_v1_remap[cc](client, header, binary_raw_response_handler);
}
break;
abort();
}
- if (rval == PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND && client->root->callback->unknown != NULL) {
+ if (rval == PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND && client->root->callback->unknown) {
rval = client->root->callback->unknown(client, header, binary_raw_response_handler);
}
rval = binary_raw_response_handler(client, header, (void *) &response);
}
- if (client->root->callback->post_execute != NULL) {
+ if (client->root->callback->post_execute) {
client->root->callback->post_execute(client, header);
}