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>
49 %output "libmemcached/csl/parser.cc"
50 %defines "libmemcached/csl/parser.h"
51 %lex-param { yyscan_t *scanner }
52 %name-prefix="config_"
53 %parse-param { class Context *context }
54 %parse-param { yyscan_t *scanner }
62 #include <libmemcached/options.hpp>
64 #include <libmemcached/csl/context.h>
65 #include <libmemcached/csl/symbol.h>
66 #include <libmemcached/csl/scanner.h>
68 #ifndef __INTEL_COMPILER
69 # pragma GCC diagnostic ignored "-Wold-style-cast"
72 #ifndef __INTEL_COMPILER
74 # pragma GCC diagnostic ignored "-Wlogical-op"
75 # pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations"
79 int conf_lex(YYSTYPE* lvalp, void* scanner);
81 #define select_yychar(__context) yychar == UNKNOWN ? ( (__context)->previous_token == END ? UNKNOWN : (__context)->previous_token ) : yychar
83 #define stryytname(__yytokentype) ((__yytokentype) < YYNTOKENS ) ? yytname[(__yytokentype)] : ""
85 #define parser_abort(__context, __error_message) do { (__context)->abort((__error_message), yytokentype(select_yychar(__context)), stryytname(YYTRANSLATE(select_yychar(__context)))); YYABORT; } while (0)
87 // This is bison calling error.
88 inline void __config_error(Context *context, yyscan_t *scanner, const char *error, int last_token, const char *last_token_str)
90 if (not context->end())
92 context->error(error, yytokentype(last_token), last_token_str);
96 context->error(error, yytokentype(last_token), last_token_str);
100 #define config_error(__context, __scanner, __error_msg) do { __config_error((__context), (__scanner), (__error_msg), select_yychar(__context), stryytname(YYTRANSLATE(select_yychar(__context)))); } while (0)
111 %token CONFIGURE_FILE
116 %token SERVERS_OPTION
117 %token UNKNOWN_OPTION
120 /* All behavior options */
121 %token BINARY_PROTOCOL
122 %token BUFFER_REQUESTS
123 %token CONNECT_TIMEOUT
126 %token HASH_WITH_NAMESPACE
127 %token IO_BYTES_WATERMARK
128 %token IO_KEY_PREFETCH
129 %token IO_MSG_WATERMARK
131 %token KETAMA_WEIGHTED
133 %token NUMBER_OF_REPLICAS
135 %token RANDOMIZE_REPLICA_READ
137 %token REMOVE_FAILED_SERVERS
140 %token SOCKET_RECV_SIZE
141 %token SOCKET_SEND_SIZE
147 %token _TCP_KEEPALIVE
176 %token <boolean> CSL_TRUE
177 %token <boolean> CSL_FALSE
182 %token <number> CSL_FLOAT
183 %token <number> NUMBER
185 %token <number> WEIGHT_START
186 %token <server> IPADDRESS
187 %token <server> HOSTNAME
188 %token <string> STRING
189 %token <string> QUOTED_STRING
190 %token <string> FILE_PATH
192 %type <behavior> behavior_boolean
193 %type <behavior> behavior_number
194 %type <distribution> distribution
196 %type <number> optional_port
197 %type <number> optional_weight
198 %type <string> string
204 | begin ' ' statement
221 context->rc= MEMCACHED_PARSE_USER_ERROR;
222 parser_abort(context, "ERROR called directly");
226 memcached_reset(context->memc);
234 if ((context->rc= memcached_parse_configure_file(*context->memc, $3.c_str, $3.size)) != MEMCACHED_SUCCESS)
236 parser_abort(context, "Failed to parse configuration file");
243 SERVER HOSTNAME optional_port optional_weight
245 if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, uint32_t($4))))
248 snprintf(buffer, sizeof(buffer), "Failed to add server: %s:%u", $2.c_str, uint32_t($3));
249 parser_abort(context, buffer);
251 context->unset_server();
253 | SERVER IPADDRESS optional_port optional_weight
255 if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, uint32_t($4))))
258 snprintf(buffer, sizeof(buffer), "Failed to add server: %s:%u", $2.c_str, uint32_t($3));
259 parser_abort(context, buffer);
261 context->unset_server();
263 | CSL_SOCKET string optional_weight
265 if (memcached_failed(context->rc= memcached_server_add_unix_socket_with_weight(context->memc, $2.c_str, uint32_t($3))))
268 snprintf(buffer, sizeof(buffer), "Failed to add socket: %s", $2.c_str);
269 parser_abort(context, buffer);
272 | CONFIGURE_FILE string
274 memcached_set_configuration_file(context->memc, $2.c_str, $2.size);
278 context->memc->configure.initial_pool_size= uint32_t($2);
282 context->memc->configure.max_pool_size= uint32_t($2);
290 if (memcached_callback_get(context->memc, MEMCACHED_CALLBACK_PREFIX_KEY, NULL))
292 parser_abort(context, "--NAMESPACE can only be called once");
295 if ((context->rc= memcached_set_namespace(*context->memc, $2.c_str, $2.size)) != MEMCACHED_SUCCESS)
297 parser_abort(context, memcached_last_error_message(context->memc));
302 memcached_flag(*context->memc, MEMCACHED_FLAG_IS_FETCHING_VERSION, true);
304 | DISTRIBUTION distribution
306 // Check to see if DISTRIBUTION has already been set
307 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
309 parser_abort(context, "--DISTRIBUTION can only be called once");
312 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
314 parser_abort(context, memcached_last_error_message(context->memc));;
317 | DISTRIBUTION distribution ',' hash
319 // Check to see if DISTRIBUTION has already been set
320 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
322 parser_abort(context, "--DISTRIBUTION can only be called once");
325 if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, $4)) != MEMCACHED_SUCCESS)
327 parser_abort(context, "Unable to set the hash for the DISTRIBUTION requested");
332 if (context->set_hash($2) == false)
334 parser_abort(context, "--HASH can only be set once");
337 | behavior_number NUMBER
339 if ((context->rc= memcached_behavior_set(context->memc, $1, $2)) != MEMCACHED_SUCCESS)
341 parser_abort(context, "Unable to set behavior");
346 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
349 snprintf(buffer, sizeof(buffer), "Could not set: %s", libmemcached_string_behavior($1));
350 parser_abort(context, buffer);
359 REMOVE_FAILED_SERVERS
361 $$= MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS;
365 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
369 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
373 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
377 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
381 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
385 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
389 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
393 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
397 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
401 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
405 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
412 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
416 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
418 | HASH_WITH_NAMESPACE
420 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
424 $$= MEMCACHED_BEHAVIOR_NOREPLY;
426 | RANDOMIZE_REPLICA_READ
428 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
432 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
436 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
440 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
444 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
448 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
452 $$= MEMCACHED_BEHAVIOR_USE_UDP;
456 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
461 { $$= MEMCACHED_DEFAULT_PORT;}
475 $$= MEMCACHED_HASH_MD5;
479 $$= MEMCACHED_HASH_CRC;
483 $$= MEMCACHED_HASH_FNV1_64;
487 $$= MEMCACHED_HASH_FNV1A_64;
491 $$= MEMCACHED_HASH_FNV1_32;
495 $$= MEMCACHED_HASH_FNV1A_32;
499 $$= MEMCACHED_HASH_HSIEH;
503 $$= MEMCACHED_HASH_MURMUR;
507 $$= MEMCACHED_HASH_JENKINS;
525 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
529 $$= MEMCACHED_DISTRIBUTION_MODULA;
533 $$= MEMCACHED_DISTRIBUTION_RANDOM;
539 void Context::start()
541 config_parse(this, (void **)scanner);