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>
16 These functions provide data and function callback support
19 memcached_return_t
memcached_callback_set(memcached_st
*ptr
,
20 const memcached_callback_t flag
,
25 case MEMCACHED_CALLBACK_PREFIX_KEY
:
27 char *key
= (char *)data
;
31 size_t key_length
= strlen(key
);
33 if (memcached_key_test((const char **)&key
, &key_length
, 1) == MEMCACHED_BAD_KEY_PROVIDED
)
35 return MEMCACHED_BAD_KEY_PROVIDED
;
38 if ((key_length
> MEMCACHED_PREFIX_KEY_MAX_SIZE
-1)
39 || (strncpy(ptr
->prefix_key
, key
, MEMCACHED_PREFIX_KEY_MAX_SIZE
) == NULL
))
41 ptr
->prefix_key_length
= 0;
42 return MEMCACHED_BAD_KEY_PROVIDED
;
46 ptr
->prefix_key_length
= key_length
;
51 ptr
->prefix_key
[0]= 0;
52 ptr
->prefix_key_length
= 0;
57 case MEMCACHED_CALLBACK_USER_DATA
:
62 case MEMCACHED_CALLBACK_CLEANUP_FUNCTION
:
64 memcached_cleanup_fn func
= *(memcached_cleanup_fn
*)&data
;
65 ptr
->on_cleanup
= func
;
68 case MEMCACHED_CALLBACK_CLONE_FUNCTION
:
70 memcached_clone_fn func
= *(memcached_clone_fn
*)&data
;
74 #ifdef MEMCACHED_ENABLE_DEPRECATED
75 case MEMCACHED_CALLBACK_MALLOC_FUNCTION
:
77 memcached_malloc_function func
= *(memcached_malloc_fn
*)&data
;
78 ptr
->call_malloc
= func
;
81 case MEMCACHED_CALLBACK_REALLOC_FUNCTION
:
83 memcached_realloc_function func
= *(memcached_realloc_fn
*)&data
;
84 ptr
->call_realloc
= func
;
87 case MEMCACHED_CALLBACK_FREE_FUNCTION
:
89 memcached_free_function func
= *(memcached_free_fn
*)&data
;
94 case MEMCACHED_CALLBACK_GET_FAILURE
:
96 memcached_trigger_key_fn func
= *(memcached_trigger_key_fn
*)&data
;
97 ptr
->get_key_failure
= func
;
100 case MEMCACHED_CALLBACK_DELETE_TRIGGER
:
102 memcached_trigger_delete_key_fn func
= *(memcached_trigger_delete_key_fn
*)&data
;
103 ptr
->delete_trigger
= func
;
106 case MEMCACHED_CALLBACK_MAX
:
108 return MEMCACHED_FAILURE
;
111 return MEMCACHED_SUCCESS
;
114 void *memcached_callback_get(memcached_st
*ptr
,
115 const memcached_callback_t flag
,
116 memcached_return_t
*error
)
118 memcached_return_t local_error
;
121 error
= &local_error
;
125 case MEMCACHED_CALLBACK_PREFIX_KEY
:
127 if (ptr
->prefix_key_length
)
129 *error
= MEMCACHED_SUCCESS
;
130 return (void *)ptr
->prefix_key
;
134 *error
= MEMCACHED_FAILURE
;
138 case MEMCACHED_CALLBACK_USER_DATA
:
140 *error
= ptr
->user_data
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
141 return (void *)ptr
->user_data
;
143 case MEMCACHED_CALLBACK_CLEANUP_FUNCTION
:
145 *error
= ptr
->on_cleanup
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
146 return *(void **)&ptr
->on_cleanup
;
148 case MEMCACHED_CALLBACK_CLONE_FUNCTION
:
150 *error
= ptr
->on_clone
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
151 return *(void **)&ptr
->on_clone
;
153 #ifdef MEMCACHED_ENABLE_DEPRECATED
154 case MEMCACHED_CALLBACK_MALLOC_FUNCTION
:
156 *error
= ptr
->call_malloc
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
157 return *(void **)&ptr
->call_malloc
;
159 case MEMCACHED_CALLBACK_REALLOC_FUNCTION
:
161 *error
= ptr
->call_realloc
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
162 return *(void **)&ptr
->call_realloc
;
164 case MEMCACHED_CALLBACK_FREE_FUNCTION
:
166 *error
= ptr
->call_free
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
167 return *(void **)&ptr
->call_free
;
170 case MEMCACHED_CALLBACK_GET_FAILURE
:
172 *error
= ptr
->get_key_failure
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
173 return *(void **)&ptr
->get_key_failure
;
175 case MEMCACHED_CALLBACK_DELETE_TRIGGER
:
177 *error
= ptr
->delete_trigger
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
178 return *(void **)&ptr
->delete_trigger
;
180 case MEMCACHED_CALLBACK_MAX
:
182 WATCHPOINT_ASSERT(0);
183 *error
= MEMCACHED_FAILURE
;