From: Brian Aker Date: Wed, 23 Mar 2011 22:46:23 +0000 (-0700) Subject: Merge in additional language plus some of the configure language for X-Git-Tag: 0.51~15^2~75^2~4 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=50521589078b10acb7be711658754120be554852;p=m6w6%2Flibmemcached Merge in additional language plus some of the configure language for END/RESET/etc. --- diff --git a/clients/memparse.cc b/clients/memparse.cc index eb978f2c..2c80fcd5 100644 --- a/clients/memparse.cc +++ b/clients/memparse.cc @@ -58,8 +58,8 @@ int main(int argc, char *argv[]) if (rc != MEMCACHED_SUCCESS) { - std::cerr << "Failed to parse options:" << argv[x] << std::endl; - std::cerr << "\t" << buffer << std::endl; + std::cerr << "Failed to parse argument #" << x << " " << argv[x] << std::endl; + std::cerr << "Error message from parser was:\t" << buffer << std::endl; return EXIT_FAILURE; } } diff --git a/libmemcached/constants.h b/libmemcached/constants.h index 3c9614d1..e01623c8 100644 --- a/libmemcached/constants.h +++ b/libmemcached/constants.h @@ -75,6 +75,7 @@ typedef enum { MEMCACHED_AUTH_FAILURE, MEMCACHED_AUTH_CONTINUE, MEMCACHED_PARSE_ERROR, + MEMCACHED_PARSE_USER_ERROR, MEMCACHED_MAXIMUM_RETURN /* Always add new error code before */ } memcached_return_t; diff --git a/libmemcached/options.cc b/libmemcached/options.cc index 35e8b783..02b885fc 100644 --- a/libmemcached/options.cc +++ b/libmemcached/options.cc @@ -37,10 +37,9 @@ #include "common.h" -#include -#include +#include -int libmemcached_parse(Context*, yyscan_t *); +#include const char *memcached_parse_filename(memcached_st *memc) { @@ -54,9 +53,15 @@ size_t memcached_parse_filename_length(memcached_st *memc) static memcached_return_t _parse_file_options(memcached_st *self, memcached_string_t *filename) { - FILE *fp= fopen(filename->c_str, "r"); + std::string real_name(filename->c_str, filename->size); + FILE *fp= fopen(real_name.c_str(), "r"); if (! fp) - return memcached_set_errno(self, errno, NULL); + { + memcached_string_t tmp; + tmp.c_str= real_name.c_str(); + tmp.size= real_name.size(); + return memcached_set_errno(self, errno, &tmp); + } char buffer[BUFSIZ]; memcached_return_t rc= MEMCACHED_INVALID_ARGUMENTS; @@ -76,7 +81,7 @@ static memcached_return_t _parse_file_options(memcached_st *self, memcached_stri return rc; } -memcached_return_t libmemcached_check_configuration(const char *option_string, size_t length, const char *error_buffer, size_t error_buffer_size) +memcached_return_t libmemcached_check_configuration(const char *option_string, size_t length, char *error_buffer, size_t error_buffer_size) { memcached_st memc, *memc_ptr; @@ -114,7 +119,7 @@ memcached_return_t memcached_parse_configuration(memcached_st *self, char const memcached_return_t rc; Context context(option_string, length, self, rc); - libmemcached_parse(&context, context.scanner); + context.start(); return rc; } diff --git a/libmemcached/options.h b/libmemcached/options.h index f06ae566..0a27be98 100644 --- a/libmemcached/options.h +++ b/libmemcached/options.h @@ -42,7 +42,7 @@ extern "C" { #endif LIBMEMCACHED_API - memcached_return_t libmemcached_check_configuration(const char *option_string, size_t length, const char *error_buffer, size_t error_buffer_size); + memcached_return_t libmemcached_check_configuration(const char *option_string, size_t length, char *error_buffer, size_t error_buffer_size); LIBMEMCACHED_API memcached_return_t memcached_parse_configuration(memcached_st *ptr, const char *option_string, size_t length); diff --git a/libmemcached/options/context.h b/libmemcached/options/context.h index e650b5ee..9e4ecb3a 100644 --- a/libmemcached/options/context.h +++ b/libmemcached/options/context.h @@ -63,6 +63,8 @@ public: return _end; } + void start(); + void set_end() { rc= MEMCACHED_SUCCESS; diff --git a/libmemcached/options/parser.yy b/libmemcached/options/parser.yy index dd19ef8b..14719045 100644 --- a/libmemcached/options/parser.yy +++ b/libmemcached/options/parser.yy @@ -61,6 +61,7 @@ inline void parser_abort_func(Context *context, const char *error) context->rc= MEMCACHED_PARSE_ERROR; std::string error_message; + error_message+= "Error occured while parsing: "; error_message+= context->begin; error_message+= " ("; if (context->rc == MEMCACHED_PARSE_ERROR and error) @@ -82,10 +83,17 @@ inline void libmemcached_error(YYLTYPE *locp, Context *context, yyscan_t *scanne parser_abort_func(context, error); } +int libmemcached_parse(Context*, yyscan_t *); +void Context::start() +{ + libmemcached_parse(this, scanner); +} + %} %token COMMENT %token END +%token ERROR %token RESET %token DEBUG %token INCLUDE @@ -194,30 +202,22 @@ statement: context->set_end(); YYACCEPT; } - | RESET + | ERROR { - memcached_reset(context->memc); + context->rc= MEMCACHED_PARSE_USER_ERROR; + parser_abort(context, NULL); } - | RESET SERVERS + | RESET { - memcached_servers_reset(context->memc); + memcached_reset(context->memc); } | DEBUG { yydebug= 1; } - | DEBUG TRUE - { - yydebug= 1; - } - | DEBUG FALSE - { - yydebug= 0; - } - | INCLUDE FILE_PATH + | INCLUDE ' ' string { - std::cerr << "Got into INCLUDE" << std::endl; - if ((context->rc= memcached_parse_configure_file(context->memc, $2.c_str, $2.length)) != MEMCACHED_SUCCESS) + if ((context->rc= memcached_parse_configure_file(context->memc, $3.c_str, $3.length)) != MEMCACHED_SUCCESS) { parser_abort(context, NULL); } @@ -434,7 +434,7 @@ server: HOSTNAME_WITH_PORT NUMBER { $$.c_str= $1.c_str; - $$.length= $1.length -1; + $$.length= $1.length -1; // -1 to remove : $$.port= $2; } | HOSTNAME @@ -452,7 +452,7 @@ server: | IPADDRESS_WITH_PORT NUMBER { $$.c_str= $1.c_str; - $$.length= $1.length -1; + $$.length= $1.length -1; // -1 to remove : $$.port= $2; } | IPADDRESS @@ -509,8 +509,8 @@ string: } | QUOTED_STRING { - $$.c_str= $1.c_str +1; - $$.length= $1.length -2; + $$.c_str= $1.c_str +1; // +1 to move use passed the initial quote + $$.length= $1.length -1; // -1 removes the end quote } ; diff --git a/libmemcached/options/scanner.l b/libmemcached/options/scanner.l index 124900cf..aadfdc3b 100644 --- a/libmemcached/options/scanner.l +++ b/libmemcached/options/scanner.l @@ -159,11 +159,12 @@ static void get_lex_chars(char* buffer, int& result, int max_size, Context *cont "--PREFIX-KEY" { yyextra->begin= yytext; return PREFIX_KEY; } "--PREFIX_KEY" { yyextra->begin= yytext; return PREFIX_KEY; } -INCLUDE { yyextra->begin= yytext; std::cerr << "Found INCLUDE" << std::endl; return INCLUDE; } +INCLUDE { yyextra->begin= yytext; return INCLUDE; } RESET { yyextra->begin= yytext; return RESET; } DEBUG { yyextra->begin= yytext; return DEBUG; } SERVERS { yyextra->begin= yytext; return SERVERS; } END { yyextra->begin= yytext; return END; } +ERROR { yyextra->begin= yytext; return ERROR; } TRUE { return TRUE; } FALSE { return FALSE; } @@ -241,3 +242,4 @@ void Context::destroy_scanner() { yylex_destroy(scanner); } + diff --git a/libmemcached/strerror.c b/libmemcached/strerror.c index 5fc365c2..773ccd03 100644 --- a/libmemcached/strerror.c +++ b/libmemcached/strerror.c @@ -93,6 +93,8 @@ const char *memcached_strerror(memcached_st *ptr, memcached_return_t rc) return "CONTINUE AUTHENTICATION"; case MEMCACHED_PARSE_ERROR: return "ERROR OCCURED WHILE PARSING"; + case MEMCACHED_PARSE_USER_ERROR: + return "USER INITIATED ERROR OCCURED WHILE PARSING"; case MEMCACHED_MAXIMUM_RETURN: return "Gibberish returned!"; default: diff --git a/tests/mem_functions.c b/tests/mem_functions.c index b823b3f2..9b27a60a 100644 --- a/tests/mem_functions.c +++ b/tests/mem_functions.c @@ -401,10 +401,10 @@ static test_return_t error_test(memcached_st *memc) 2300930706U, 2943759320U, 674306647U, 2400528935U, 54481931U, 4186304426U, 1741088401U, 2979625118U, 4159057246U, 3425930182U, 2593724503U, 1868899624U, - 1769812374U, 2302537950U, 1110330676U, 3365377466U }; + 1769812374U, 2302537950U, 1110330676U, 3365377466U, + 1336171666U, 3365377466U }; // You have updated the memcache_error messages but not updated docs/tests. - test_true(MEMCACHED_MAXIMUM_RETURN == 44); for (rc= MEMCACHED_SUCCESS; rc < MEMCACHED_MAXIMUM_RETURN; rc++) { uint32_t hash_val; @@ -418,6 +418,7 @@ static test_return_t error_test(memcached_st *memc) } test_true(values[rc] == hash_val); } + test_true(MEMCACHED_MAXIMUM_RETURN == 45); return TEST_SUCCESS; } diff --git a/tests/parser.cc b/tests/parser.cc index 968dd0c7..717859b4 100644 --- a/tests/parser.cc +++ b/tests/parser.cc @@ -422,6 +422,50 @@ test_return_t memcached_create_with_options_test(memcached_st *junk) return TEST_SUCCESS; } +test_return_t test_include_keyword(memcached_st *junk) +{ + (void)junk; + char buffer[BUFSIZ]; + memcached_return_t rc; + rc= libmemcached_check_configuration(STRING_WITH_LEN("INCLUDE \"support/example.cnf\""), buffer, sizeof(buffer)); + test_true_got(rc == MEMCACHED_SUCCESS, buffer); + + return TEST_SUCCESS; +} + +test_return_t test_end_keyword(memcached_st *junk) +{ + (void)junk; + char buffer[BUFSIZ]; + memcached_return_t rc; + rc= libmemcached_check_configuration(STRING_WITH_LEN("--server=localhost END bad keywords"), buffer, sizeof(buffer)); + test_true_got(rc == MEMCACHED_SUCCESS, buffer); + + return TEST_SUCCESS; +} + +test_return_t test_reset_keyword(memcached_st *junk) +{ + (void)junk; + char buffer[BUFSIZ]; + memcached_return_t rc; + rc= libmemcached_check_configuration(STRING_WITH_LEN("--server=localhost reset --server=bad.com"), buffer, sizeof(buffer)); + test_true_got(rc == MEMCACHED_SUCCESS, buffer); + + return TEST_SUCCESS; +} + +test_return_t test_error_keyword(memcached_st *junk) +{ + (void)junk; + char buffer[BUFSIZ]; + memcached_return_t rc; + rc= libmemcached_check_configuration(STRING_WITH_LEN("--server=localhost ERROR --server=bad.com"), buffer, sizeof(buffer)); + test_true_got(rc != MEMCACHED_SUCCESS, buffer); + + return TEST_SUCCESS; +} + #define RANDOM_STRINGS 50 test_return_t random_statement_build_test(memcached_st *junk) { diff --git a/tests/parser.h b/tests/parser.h index 0e762b0b..b21cdf70 100644 --- a/tests/parser.h +++ b/tests/parser.h @@ -85,6 +85,18 @@ LIBTEST_INTERNAL_API LIBTEST_INTERNAL_API test_return_t random_statement_build_test(memcached_st *junk); +LIBTEST_INTERNAL_API +test_return_t test_include_keyword(memcached_st *junk); + +LIBTEST_INTERNAL_API +test_return_t test_end_keyword(memcached_st *junk); + +LIBTEST_INTERNAL_API +test_return_t test_reset_keyword(memcached_st *junk); + +LIBTEST_INTERNAL_API +test_return_t test_error_keyword(memcached_st *junk); + #ifdef __cplusplus } #endif