2 +--------------------------------------------------------------------+
3 | libmemcached - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020 Michael Wallner <mike@php.net> |
13 +--------------------------------------------------------------------+
16 #include "libmemcached/csl/common.h"
17 #include "libmemcached/csl/context.h"
19 void Context::abort(const char *error_arg
, config_tokentype last_token
,
20 const char *last_token_str
) {
21 rc
= MEMCACHED_PARSE_ERROR
;
25 memcached_set_parser_error(*memc
, MEMCACHED_AT
, "%s", error_arg
);
30 memcached_set_parser_error(*memc
, MEMCACHED_AT
, "%s", last_token_str
);
34 memcached_set_parser_error(*memc
, MEMCACHED_AT
, "unknown parsing error");
37 void Context::error(const char *error_arg
, config_tokentype last_token
,
38 const char *last_token_str
) {
39 rc
= MEMCACHED_PARSE_ERROR
;
41 memcached_set_parser_error(*memc
, MEMCACHED_AT
, "Unknown error occured during parsing (%s)",
42 last_token_str
? last_token_str
: " ");
46 if (strcmp(error_arg
, "memory exhausted") == 0) {
47 (void) memcached_set_error(*memc
, MEMCACHED_MEMORY_ALLOCATION_FAILURE
, MEMCACHED_AT
,
48 memcached_string_make_from_cstr(error_arg
));
52 // We now test if it is something other then a syntax error, if it we
53 // return a generic message
54 if (strcmp(error_arg
, "syntax error")) {
55 memcached_set_parser_error(*memc
, MEMCACHED_AT
,
56 "Error occured during parsing (%s): last_token=%s(%d)", error_arg
,
57 last_token_str
, last_token
);
61 if (last_token
== UNKNOWN_OPTION
and begin
) {
62 memcached_set_parser_error(*memc
, MEMCACHED_AT
, "Unknown option: %s", begin
);
63 } else if (last_token
== UNKNOWN
) {
64 memcached_set_parser_error(*memc
, MEMCACHED_AT
,
65 "Error occured durring parsing, an unknown token was found.");
67 memcached_set_parser_error(*memc
, MEMCACHED_AT
, "Error occured while parsing (%s)",
68 last_token_str
? last_token_str
: " ");
72 void Context::hostname(const char *str
, size_t size
, server_t
&server_
) {
73 size_t copy_length
= size_t(NI_MAXHOST
) > size
? size
: size_t(NI_MAXHOST
);
74 memcpy(_hostname
, str
, copy_length
);
75 _hostname
[copy_length
] = 0;
77 server_
.port
= MEMCACHED_DEFAULT_PORT
;
79 server_
.c_str
= _hostname
;
83 bool Context::string_buffer(const char *str
, size_t size
, memcached_string_t
&string_
) {
84 if (memcached_string_set(_string_buffer
, str
, size
)) {
85 string_
.c_str
= memcached_string_value(_string_buffer
);
86 string_
.size
= memcached_string_length(_string_buffer
);
94 bool Context::set_hash(memcached_hash_t hash
) {
99 if ((memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, hash
)) != MEMCACHED_SUCCESS
) {
103 return _has_hash
= true;