3 #include <sys/socket.h>
4 #include <netinet/tcp.h>
7 These functions provide data and function callback support
10 memcached_return
memcached_callback_set(memcached_st
*ptr
,
11 memcached_callback flag
,
16 case MEMCACHED_CALLBACK_PREFIX_KEY
:
18 char *key
= (char *)data
;
22 size_t key_length
= strlen(key
);
24 if (memcached_key_test((const char **)&key
, &key_length
, 1) == MEMCACHED_BAD_KEY_PROVIDED
)
26 return MEMCACHED_BAD_KEY_PROVIDED
;
29 if ((key_length
> MEMCACHED_PREFIX_KEY_MAX_SIZE
-1)
30 || (strcpy(ptr
->prefix_key
, key
) == NULL
))
32 ptr
->prefix_key_length
= 0;
33 return MEMCACHED_BAD_KEY_PROVIDED
;
37 ptr
->prefix_key_length
= key_length
;
42 memset(ptr
->prefix_key
, 0, MEMCACHED_PREFIX_KEY_MAX_SIZE
);
43 ptr
->prefix_key_length
= 0;
48 case MEMCACHED_CALLBACK_USER_DATA
:
53 case MEMCACHED_CALLBACK_CLEANUP_FUNCTION
:
55 memcached_cleanup_func func
= *(memcached_cleanup_func
*)&data
;
56 ptr
->on_cleanup
= func
;
59 case MEMCACHED_CALLBACK_CLONE_FUNCTION
:
61 memcached_clone_func func
= *(memcached_clone_func
*)&data
;
65 #ifdef MEMCACHED_ENABLE_DEPRECATED
66 case MEMCACHED_CALLBACK_MALLOC_FUNCTION
:
68 memcached_malloc_function func
= *(memcached_malloc_function
*)&data
;
69 ptr
->call_malloc
= func
;
72 case MEMCACHED_CALLBACK_REALLOC_FUNCTION
:
74 memcached_realloc_function func
= *(memcached_realloc_function
*)&data
;
75 ptr
->call_realloc
= func
;
78 case MEMCACHED_CALLBACK_FREE_FUNCTION
:
80 memcached_free_function func
= *(memcached_free_function
*)&data
;
85 case MEMCACHED_CALLBACK_GET_FAILURE
:
87 memcached_trigger_key func
= *(memcached_trigger_key
*)&data
;
88 ptr
->get_key_failure
= func
;
91 case MEMCACHED_CALLBACK_DELETE_TRIGGER
:
93 memcached_trigger_delete_key func
= *(memcached_trigger_delete_key
*)&data
;
94 ptr
->delete_trigger
= func
;
98 return MEMCACHED_FAILURE
;
101 return MEMCACHED_SUCCESS
;
104 void *memcached_callback_get(memcached_st
*ptr
,
105 memcached_callback flag
,
106 memcached_return
*error
)
108 memcached_return local_error
;
111 error
= &local_error
;
115 case MEMCACHED_CALLBACK_PREFIX_KEY
:
117 if (ptr
->prefix_key
[0] == 0)
119 *error
= MEMCACHED_FAILURE
;
124 *error
= MEMCACHED_SUCCESS
;
125 return (void *)ptr
->prefix_key
;
128 case MEMCACHED_CALLBACK_USER_DATA
:
130 *error
= ptr
->user_data
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
131 return (void *)ptr
->user_data
;
133 case MEMCACHED_CALLBACK_CLEANUP_FUNCTION
:
135 *error
= ptr
->on_cleanup
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
136 return *(void **)&ptr
->on_cleanup
;
138 case MEMCACHED_CALLBACK_CLONE_FUNCTION
:
140 *error
= ptr
->on_clone
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
141 return *(void **)&ptr
->on_clone
;
143 #ifdef MEMCACHED_ENABLE_DEPRECATED
144 case MEMCACHED_CALLBACK_MALLOC_FUNCTION
:
146 *error
= ptr
->call_malloc
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
147 return *(void **)&ptr
->call_malloc
;
149 case MEMCACHED_CALLBACK_REALLOC_FUNCTION
:
151 *error
= ptr
->call_realloc
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
152 return *(void **)&ptr
->call_realloc
;
154 case MEMCACHED_CALLBACK_FREE_FUNCTION
:
156 *error
= ptr
->call_free
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
157 return *(void **)&ptr
->call_free
;
160 case MEMCACHED_CALLBACK_GET_FAILURE
:
162 *error
= ptr
->get_key_failure
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
163 return *(void **)&ptr
->get_key_failure
;
165 case MEMCACHED_CALLBACK_DELETE_TRIGGER
:
167 *error
= ptr
->delete_trigger
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
168 return *(void **)&ptr
->delete_trigger
;
171 WATCHPOINT_ASSERT(0);
172 *error
= MEMCACHED_FAILURE
;