2 * Copyright (C) 2006-2009 Brian Aker
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
8 * Summary: Change any of the possible callbacks.
13 #include <sys/types.h>
14 #include <sys/socket.h>
15 #include <netinet/tcp.h>
18 These functions provide data and function callback support
21 memcached_return_t
memcached_callback_set(memcached_st
*ptr
,
22 const memcached_callback_t flag
,
27 case MEMCACHED_CALLBACK_PREFIX_KEY
:
29 char *key
= (char *)data
;
33 size_t key_length
= strlen(key
);
35 if (memcached_key_test((const char **)&key
, &key_length
, 1) == MEMCACHED_BAD_KEY_PROVIDED
)
37 return MEMCACHED_BAD_KEY_PROVIDED
;
40 if ((key_length
> MEMCACHED_PREFIX_KEY_MAX_SIZE
-1)
41 || (strncpy(ptr
->prefix_key
, key
, MEMCACHED_PREFIX_KEY_MAX_SIZE
) == NULL
))
43 ptr
->prefix_key_length
= 0;
44 return MEMCACHED_BAD_KEY_PROVIDED
;
48 ptr
->prefix_key_length
= key_length
;
53 ptr
->prefix_key
[0]= 0;
54 ptr
->prefix_key_length
= 0;
59 case MEMCACHED_CALLBACK_USER_DATA
:
64 case MEMCACHED_CALLBACK_CLEANUP_FUNCTION
:
66 memcached_cleanup_fn func
= *(memcached_cleanup_fn
*)&data
;
67 ptr
->on_cleanup
= func
;
70 case MEMCACHED_CALLBACK_CLONE_FUNCTION
:
72 memcached_clone_fn func
= *(memcached_clone_fn
*)&data
;
76 #ifdef MEMCACHED_ENABLE_DEPRECATED
77 case MEMCACHED_CALLBACK_MALLOC_FUNCTION
:
79 memcached_malloc_function func
= *(memcached_malloc_fn
*)&data
;
80 ptr
->call_malloc
= func
;
83 case MEMCACHED_CALLBACK_REALLOC_FUNCTION
:
85 memcached_realloc_function func
= *(memcached_realloc_fn
*)&data
;
86 ptr
->call_realloc
= func
;
89 case MEMCACHED_CALLBACK_FREE_FUNCTION
:
91 memcached_free_function func
= *(memcached_free_fn
*)&data
;
96 case MEMCACHED_CALLBACK_GET_FAILURE
:
98 memcached_trigger_key_fn func
= *(memcached_trigger_key_fn
*)&data
;
99 ptr
->get_key_failure
= func
;
102 case MEMCACHED_CALLBACK_DELETE_TRIGGER
:
104 memcached_trigger_delete_key_fn func
= *(memcached_trigger_delete_key_fn
*)&data
;
105 ptr
->delete_trigger
= func
;
108 case MEMCACHED_CALLBACK_MAX
:
110 return MEMCACHED_FAILURE
;
113 return MEMCACHED_SUCCESS
;
116 void *memcached_callback_get(memcached_st
*ptr
,
117 const memcached_callback_t flag
,
118 memcached_return_t
*error
)
120 memcached_return_t local_error
;
123 error
= &local_error
;
127 case MEMCACHED_CALLBACK_PREFIX_KEY
:
129 if (ptr
->prefix_key_length
)
131 *error
= MEMCACHED_SUCCESS
;
132 return (void *)ptr
->prefix_key
;
136 *error
= MEMCACHED_FAILURE
;
140 case MEMCACHED_CALLBACK_USER_DATA
:
142 *error
= ptr
->user_data
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
143 return (void *)ptr
->user_data
;
145 case MEMCACHED_CALLBACK_CLEANUP_FUNCTION
:
147 *error
= ptr
->on_cleanup
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
148 return *(void **)&ptr
->on_cleanup
;
150 case MEMCACHED_CALLBACK_CLONE_FUNCTION
:
152 *error
= ptr
->on_clone
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
153 return *(void **)&ptr
->on_clone
;
155 #ifdef MEMCACHED_ENABLE_DEPRECATED
156 case MEMCACHED_CALLBACK_MALLOC_FUNCTION
:
158 *error
= ptr
->call_malloc
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
159 return *(void **)&ptr
->call_malloc
;
161 case MEMCACHED_CALLBACK_REALLOC_FUNCTION
:
163 *error
= ptr
->call_realloc
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
164 return *(void **)&ptr
->call_realloc
;
166 case MEMCACHED_CALLBACK_FREE_FUNCTION
:
168 *error
= ptr
->call_free
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
169 return *(void **)&ptr
->call_free
;
172 case MEMCACHED_CALLBACK_GET_FAILURE
:
174 *error
= ptr
->get_key_failure
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
175 return *(void **)&ptr
->get_key_failure
;
177 case MEMCACHED_CALLBACK_DELETE_TRIGGER
:
179 *error
= ptr
->delete_trigger
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
180 return *(void **)&ptr
->delete_trigger
;
182 case MEMCACHED_CALLBACK_MAX
:
184 WATCHPOINT_ASSERT(0);
185 *error
= MEMCACHED_FAILURE
;