1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5 * Copyright (C) 2012 Data Differential, http://datadifferential.com/
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with the
19 * * The names of its contributors may not be used to endorse or
20 * promote products derived from this software without specific prior
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include <libmemcached/csl/common.h>
45 %define parse.error verbose
46 %define api.prefix {config_}
51 %lex-param { yyscan_t *scanner }
52 %parse-param { class Context *context }
53 %parse-param { yyscan_t *scanner }
60 #include <libmemcached/options.hpp>
62 #include <libmemcached/csl/context.h>
63 #include <libmemcached/csl/symbol.h>
64 #include <libmemcached/csl/scanner.h>
66 #ifndef __INTEL_COMPILER
67 # pragma GCC diagnostic ignored "-Wold-style-cast"
70 #ifndef __INTEL_COMPILER
72 # pragma GCC diagnostic ignored "-Wlogical-op"
73 # pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations"
77 int conf_lex(YYSTYPE* lvalp, void* scanner);
79 #define select_yychar(__context) yychar == UNKNOWN ? ( (__context)->previous_token == END ? UNKNOWN : (__context)->previous_token ) : yychar
81 #define stryytname(__yytokentype) ((__yytokentype) < YYNTOKENS ) ? yytname[(__yytokentype)] : ""
83 #define parser_abort(__context, __error_message) do { (__context)->abort((__error_message), config_tokentype(select_yychar(__context)), stryytname(YYTRANSLATE(select_yychar(__context)))); YYABORT; } while (0)
85 // This is bison calling error.
86 inline void __config_error(Context *context, yyscan_t *scanner, const char *error, int last_token, const char *last_token_str)
88 if (not context->end())
90 context->error(error, config_tokentype(last_token), last_token_str);
94 context->error(error, config_tokentype(last_token), last_token_str);
98 #define config_error(__context, __scanner, __error_msg) do { __config_error((__context), (__scanner), (__error_msg), select_yychar(__context), stryytname(YYTRANSLATE(select_yychar(__context)))); } while (0)
109 %token CONFIGURE_FILE
114 %token SERVERS_OPTION
115 %token UNKNOWN_OPTION
118 /* All behavior options */
119 %token BINARY_PROTOCOL
120 %token BUFFER_REQUESTS
121 %token CONNECT_TIMEOUT
124 %token HASH_WITH_NAMESPACE
125 %token IO_BYTES_WATERMARK
126 %token IO_KEY_PREFETCH
127 %token IO_MSG_WATERMARK
129 %token KETAMA_WEIGHTED
131 %token NUMBER_OF_REPLICAS
133 %token RANDOMIZE_REPLICA_READ
135 %token REMOVE_FAILED_SERVERS
138 %token SOCKET_RECV_SIZE
139 %token SOCKET_SEND_SIZE
145 %token _TCP_KEEPALIVE
174 %token <boolean> CSL_TRUE
175 %token <boolean> CSL_FALSE
180 %token <number> CSL_FLOAT
181 %token <number> NUMBER
183 %token <number> WEIGHT_START
184 %token <server> IPADDRESS
185 %token <server> HOSTNAME
186 %token <string> STRING
187 %token <string> QUOTED_STRING
188 %token <string> FILE_PATH
190 %type <behavior> behavior_boolean
191 %type <behavior> behavior_number
192 %type <distribution> distribution
194 %type <number> optional_port
195 %type <number> optional_weight
196 %type <string> string
202 | begin ' ' statement
219 context->rc= MEMCACHED_PARSE_USER_ERROR;
220 parser_abort(context, "ERROR called directly");
224 memcached_reset(context->memc);
232 if ((context->rc= memcached_parse_configure_file(*context->memc, $3.c_str, $3.size)) != MEMCACHED_SUCCESS)
234 parser_abort(context, "Failed to parse configuration file");
241 SERVER HOSTNAME optional_port optional_weight
243 if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, uint32_t($4))))
246 snprintf(buffer, sizeof(buffer), "Failed to add server: %s:%u", $2.c_str, uint32_t($3));
247 parser_abort(context, buffer);
249 context->unset_server();
251 | SERVER IPADDRESS optional_port optional_weight
253 if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, uint32_t($4))))
256 snprintf(buffer, sizeof(buffer), "Failed to add server: %s:%u", $2.c_str, uint32_t($3));
257 parser_abort(context, buffer);
259 context->unset_server();
261 | CSL_SOCKET string optional_weight
263 if (memcached_failed(context->rc= memcached_server_add_unix_socket_with_weight(context->memc, $2.c_str, uint32_t($3))))
266 snprintf(buffer, sizeof(buffer), "Failed to add socket: %s", $2.c_str);
267 parser_abort(context, buffer);
270 | CONFIGURE_FILE string
272 memcached_set_configuration_file(context->memc, $2.c_str, $2.size);
276 context->memc->configure.initial_pool_size= uint32_t($2);
280 context->memc->configure.max_pool_size= uint32_t($2);
288 if (memcached_callback_get(context->memc, MEMCACHED_CALLBACK_PREFIX_KEY, NULL))
290 parser_abort(context, "--NAMESPACE can only be called once");
293 if ((context->rc= memcached_set_namespace(*context->memc, $2.c_str, $2.size)) != MEMCACHED_SUCCESS)
295 parser_abort(context, memcached_last_error_message(context->memc));
300 memcached_flag(*context->memc, MEMCACHED_FLAG_IS_FETCHING_VERSION, true);
302 | DISTRIBUTION distribution
304 // Check to see if DISTRIBUTION has already been set
305 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
307 parser_abort(context, "--DISTRIBUTION can only be called once");
310 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
312 parser_abort(context, memcached_last_error_message(context->memc));;
315 | DISTRIBUTION distribution ',' hash
317 // Check to see if DISTRIBUTION has already been set
318 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
320 parser_abort(context, "--DISTRIBUTION can only be called once");
323 if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, $4)) != MEMCACHED_SUCCESS)
325 parser_abort(context, "Unable to set the hash for the DISTRIBUTION requested");
330 if (context->set_hash($2) == false)
332 parser_abort(context, "--HASH can only be set once");
335 | behavior_number NUMBER
337 if ((context->rc= memcached_behavior_set(context->memc, $1, $2)) != MEMCACHED_SUCCESS)
339 parser_abort(context, "Unable to set behavior");
344 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
347 snprintf(buffer, sizeof(buffer), "Could not set: %s", libmemcached_string_behavior($1));
348 parser_abort(context, buffer);
357 REMOVE_FAILED_SERVERS
359 $$= MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS;
363 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
367 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
371 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
375 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
379 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
383 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
387 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
391 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
395 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
399 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
403 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
410 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
414 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
416 | HASH_WITH_NAMESPACE
418 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
422 $$= MEMCACHED_BEHAVIOR_NOREPLY;
424 | RANDOMIZE_REPLICA_READ
426 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
430 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
434 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
438 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
442 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
446 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
450 $$= MEMCACHED_BEHAVIOR_USE_UDP;
454 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
459 { $$= MEMCACHED_DEFAULT_PORT;}
473 $$= MEMCACHED_HASH_MD5;
477 $$= MEMCACHED_HASH_CRC;
481 $$= MEMCACHED_HASH_FNV1_64;
485 $$= MEMCACHED_HASH_FNV1A_64;
489 $$= MEMCACHED_HASH_FNV1_32;
493 $$= MEMCACHED_HASH_FNV1A_32;
497 $$= MEMCACHED_HASH_HSIEH;
501 $$= MEMCACHED_HASH_MURMUR;
505 $$= MEMCACHED_HASH_JENKINS;
523 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
527 $$= MEMCACHED_DISTRIBUTION_MODULA;
531 $$= MEMCACHED_DISTRIBUTION_RANDOM;
537 void Context::start()
539 config_parse(this, (void **)scanner);