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 ((ptr
->flags
& MEM_VERIFY_KEY
) && (memcachd_key_test((char **)&key
, &key_length
, 1) == MEMCACHED_BAD_KEY_PROVIDED
))
25 return MEMCACHED_BAD_KEY_PROVIDED
;
27 if ((ptr
->prefix_key_length
> MEMCACHED_PREFIX_KEY_MAX_SIZE
-1)
28 || (strcpy(ptr
->prefix_key
, key
) == NULL
))
30 ptr
->prefix_key_length
= 0;
31 return MEMCACHED_BAD_KEY_PROVIDED
;
36 memset(ptr
->prefix_key
, 0, MEMCACHED_PREFIX_KEY_MAX_SIZE
);
37 ptr
->prefix_key_length
= 0;
42 case MEMCACHED_CALLBACK_USER_DATA
:
47 case MEMCACHED_CALLBACK_CLEANUP_FUNCTION
:
49 memcached_cleanup_func func
= (memcached_cleanup_func
)data
;
50 ptr
->on_cleanup
= func
;
53 case MEMCACHED_CALLBACK_CLONE_FUNCTION
:
55 memcached_clone_func func
= (memcached_clone_func
)data
;
59 case MEMCACHED_CALLBACK_MALLOC_FUNCTION
:
61 memcached_malloc_function func
= (memcached_malloc_function
)data
;
62 ptr
->call_malloc
= func
;
65 case MEMCACHED_CALLBACK_REALLOC_FUNCTION
:
67 memcached_realloc_function func
= (memcached_realloc_function
)data
;
68 ptr
->call_realloc
= func
;
71 case MEMCACHED_CALLBACK_FREE_FUNCTION
:
73 memcached_free_function func
= (memcached_free_function
)data
;
77 case MEMCACHED_CALLBACK_GET_FAILURE
:
79 memcached_trigger_key func
= (memcached_trigger_key
)data
;
80 ptr
->get_key_failure
= func
;
83 case MEMCACHED_CALLBACK_DELETE_TRIGGER
:
85 memcached_trigger_delete_key func
= (memcached_trigger_delete_key
)data
;
86 ptr
->delete_trigger
= func
;
90 return MEMCACHED_FAILURE
;
93 return MEMCACHED_SUCCESS
;
96 void *memcached_callback_get(memcached_st
*ptr
,
97 memcached_callback flag
,
98 memcached_return
*error
)
100 memcached_return local_error
;
102 error
= &local_error
;
106 case MEMCACHED_CALLBACK_PREFIX_KEY
:
108 if (ptr
->prefix_key
[0] == 0)
110 *error
= MEMCACHED_FAILURE
;
115 *error
= MEMCACHED_SUCCESS
;
116 return (void *)ptr
->prefix_key
;
119 case MEMCACHED_CALLBACK_USER_DATA
:
121 *error
= ptr
->user_data
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
122 return (void *)ptr
->user_data
;
124 case MEMCACHED_CALLBACK_CLEANUP_FUNCTION
:
126 *error
= ptr
->on_cleanup
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
127 return (void *)ptr
->on_cleanup
;
129 case MEMCACHED_CALLBACK_CLONE_FUNCTION
:
131 *error
= ptr
->on_clone
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
132 return (void *)ptr
->on_clone
;
134 case MEMCACHED_CALLBACK_MALLOC_FUNCTION
:
136 *error
= ptr
->call_malloc
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
137 return (void *)ptr
->call_malloc
;
139 case MEMCACHED_CALLBACK_REALLOC_FUNCTION
:
141 *error
= ptr
->call_realloc
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
142 return (void *)ptr
->call_realloc
;
144 case MEMCACHED_CALLBACK_FREE_FUNCTION
:
146 *error
= ptr
->call_free
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
147 return (void *)ptr
->call_free
;
149 case MEMCACHED_CALLBACK_GET_FAILURE
:
151 *error
= ptr
->get_key_failure
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
152 return (void *)ptr
->get_key_failure
;
154 case MEMCACHED_CALLBACK_DELETE_TRIGGER
:
156 *error
= ptr
->delete_trigger
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
157 return (void *)ptr
->delete_trigger
;
160 WATCHPOINT_ASSERT(0);
161 *error
= MEMCACHED_FAILURE
;