1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (c) 2009, Patrick "CaptTofu" Galbraith, Padraig O'Sullivan
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are met:
10
* * Redistributions of source code must retain the above copyright notice,
11
* this list of conditions and the following disclaimer.
12
* * Redistributions in binary form must reproduce the above copyright notice,
13
* this list of conditions and the following disclaimer in the documentation
14
* and/or other materials provided with the distribution.
15
* * Neither the name of Patrick Galbraith nor the names of its contributors
16
* may be used to endorse or promote products derived from this software
17
* without specific prior written permission.
19
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29
* THE POSSIBILITY OF SUCH DAMAGE.
32
#include <drizzled/server_includes.h>
33
#include <drizzled/item/func.h>
34
#include <drizzled/function/str/strfunc.h>
36
#include "memcached_functions.h"
37
#include "memc_behavior_set.h"
39
#include <libmemcached/memcached.h>
46
void MemcachedBehaviorSet::setFailureString(const char *error)
48
size_t size= strlen(error);
49
failure_buff.realloc(size);
50
failure_buff.length(size);
51
memcpy(failure_buff.ptr(), error, size);
54
String *MemcachedBehaviorSet::val_str(String *str)
57
memcached_behavior mbehavior;
59
map<const string, memcached_behavior>::iterator it_behav;
60
map<const string, uint64_t>::iterator it_hash;
61
map<const string, uint64_t>::iterator it_dist;
66
! (tmp_behavior= args[0]->val_str(str)) ||
67
! (tmp_setting= args[1]->val_str(str)) ||
70
setFailureString("USAGE: memc_behavior_set('<behavior type>','<value>')");
74
string behavior(tmp_behavior->c_ptr());
75
string setting(tmp_setting->c_ptr());
78
* We don't want the user to have to type in all input in upper
79
* case so we transform the input strings to upper case here.
81
std::transform(behavior.begin(), behavior.end(),
82
behavior.begin(), ::toupper);
83
std::transform(setting.begin(), setting.end(),
84
setting.begin(), ::toupper);
86
it_behav= behavior_map.find(behavior);
87
if (it_behav == behavior_map.end())
89
setFailureString("UNKNOWN BEHAVIOR TYPE!");
92
mbehavior= behavior_map[behavior];
96
case MEMCACHED_BEHAVIOR_SUPPORT_CAS:
97
case MEMCACHED_BEHAVIOR_NO_BLOCK:
98
case MEMCACHED_BEHAVIOR_BUFFER_REQUESTS:
99
case MEMCACHED_BEHAVIOR_USER_DATA:
100
case MEMCACHED_BEHAVIOR_SORT_HOSTS:
101
case MEMCACHED_BEHAVIOR_VERIFY_KEY:
102
case MEMCACHED_BEHAVIOR_TCP_NODELAY:
103
case MEMCACHED_BEHAVIOR_KETAMA:
104
case MEMCACHED_BEHAVIOR_CACHE_LOOKUPS:
105
if (setting.compare("1") == 0)
109
else if (setting.compare("0") == 0)
115
setFailureString("INVALID VALUE FOR BEHAVIOR - MUST be 1 OR 0!");
116
return &failure_buff;
119
case MEMCACHED_BEHAVIOR_DISTRIBUTION:
120
it_dist= dist_settings_map.find(setting);
121
if (it_dist == dist_settings_map.end())
123
setFailureString("INVALID VALUE FOR DISTRIBUTION!");
124
return &failure_buff;
126
isetting= dist_settings_map[setting];
128
case MEMCACHED_BEHAVIOR_HASH:
129
it_hash= hash_settings_map.find(setting);
130
if (it_hash == hash_settings_map.end())
132
setFailureString("INVALID VALUE FOR MEMCACHED HASH ALGORITHM!");
133
return &failure_buff;
135
isetting= hash_settings_map[setting];
137
case MEMCACHED_BEHAVIOR_KETAMA_HASH:
138
isetting= ketama_hash_settings_map[setting];
141
setFailureString("INVALID VALUE FOR KETAMA HASH ALGORITHM!");
142
return &failure_buff;
145
case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE:
146
case MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE:
147
case MEMCACHED_BEHAVIOR_POLL_TIMEOUT:
148
case MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT:
149
case MEMCACHED_BEHAVIOR_RETRY_TIMEOUT:
150
case MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK:
151
case MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK:
153
What type of check the values passed to these behaviors?
161
rc= memcached_behavior_set(memc, mbehavior, isetting);
163
if (rc != MEMCACHED_SUCCESS)
165
return &failure_buff;
168
return &success_buff;