6 #include "protocol_extension.h"
18 static const char *get_name(
const void *cmd_cookie);
19 static bool accept_command(
const void *cmd_cookie,
void *cookie,
20 int argc,
token_t *argv,
size_t *ndata,
22 static ENGINE_ERROR_CODE execute_command(
const void *cmd_cookie,
const void *cookie,
24 ENGINE_ERROR_CODE (*response_handler)(
const void *cookie,
27 static void abort_command(
const void *cmd_cookie,
const void *cookie);
31 .accept = accept_command,
32 .execute = execute_command,
33 .abort = abort_command,
34 .cookie = &noop_descriptor
39 .accept = accept_command,
40 .execute = execute_command,
41 .abort = abort_command,
42 .cookie = &echo_descriptor
45 static const char *get_name(
const void *cmd_cookie) {
46 if (cmd_cookie == &noop_descriptor) {
53 static bool accept_command(
const void *cmd_cookie,
void *cookie,
54 int argc,
token_t *argv,
size_t *ndata,
56 if (cmd_cookie == &noop_descriptor) {
57 return strcmp(argv[0].value,
"noop") == 0;
59 return strcmp(argv[0].value,
"echo") == 0;
63 static ENGINE_ERROR_CODE execute_command(
const void *cmd_cookie,
const void *cookie,
65 ENGINE_ERROR_CODE (*response_handler)(
const void *cookie,
69 if (cmd_cookie == &noop_descriptor) {
70 return response_handler(cookie, 4,
"OK\r\n");
72 if (response_handler(cookie, argv[0].length, argv[0].value) != ENGINE_SUCCESS) {
73 return ENGINE_DISCONNECT;
76 for (
int ii = 1; ii < argc; ++ii) {
77 if (response_handler(cookie, 2,
" [") != ENGINE_SUCCESS ||
78 response_handler(cookie, argv[ii].length, argv[ii].value) != ENGINE_SUCCESS ||
79 response_handler(cookie, 1,
"]") != ENGINE_SUCCESS) {
80 return ENGINE_DISCONNECT;
84 return response_handler(cookie, 2,
"\r\n");
88 static void abort_command(
const void *cmd_cookie,
const void *cookie)
93 #if defined (__SUNPRO_C) && (__SUNPRO_C >= 0x550)
95 #elif defined __GNUC__
96 __attribute__ ((visibility(
"default")))
99 GET_SERVER_API get_server_api) {
101 if (server == NULL) {