MEMCACHED_BAD_KEY_PROVIDED has been added as an error type. When libmemcached
[m6w6/libmemcached] / lib / memcached_callback.c
1 #include "common.h"
2 #include <sys/types.h>
3 #include <sys/socket.h>
4 #include <netinet/tcp.h>
5
6 /*
7 These functions provide data and function callback support
8 */
9
10 memcached_return memcached_callback_set(memcached_st *ptr,
11 memcached_callback flag,
12 void *data)
13 {
14 switch (flag)
15 {
16 case MEMCACHED_CALLBACK_USER_DATA:
17 {
18 ptr->user_data= data;
19 break;
20 }
21 case MEMCACHED_CALLBACK_CLEANUP_FUNCTION:
22 {
23 memcached_cleanup_func func= (memcached_cleanup_func)data;
24 ptr->on_cleanup= func;
25 break;
26 }
27 case MEMCACHED_CALLBACK_CLONE_FUNCTION:
28 {
29 memcached_clone_func func= (memcached_clone_func)data;
30 ptr->on_clone= func;
31 break;
32 }
33 case MEMCACHED_CALLBACK_MALLOC_FUNCTION:
34 {
35 memcached_malloc_function func= (memcached_malloc_function)data;
36 ptr->call_malloc= func;
37 break;
38 }
39 case MEMCACHED_CALLBACK_REALLOC_FUNCTION:
40 {
41 memcached_realloc_function func= (memcached_realloc_function)data;
42 ptr->call_realloc= func;
43 break;
44 }
45 case MEMCACHED_CALLBACK_FREE_FUNCTION:
46 {
47 memcached_free_function func= (memcached_free_function)data;
48 ptr->call_free= func;
49 break;
50 }
51 default:
52 return MEMCACHED_FAILURE;
53 }
54
55 return MEMCACHED_SUCCESS;
56 }
57
58 void *memcached_callback_get(memcached_st *ptr,
59 memcached_callback flag,
60 memcached_return *error)
61 {
62 memcached_return local_error;
63 if (!error)
64 error = &local_error;
65
66 switch (flag)
67 {
68 case MEMCACHED_CALLBACK_USER_DATA:
69 {
70 *error= ptr->user_data ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
71 return (void *)ptr->user_data;
72 }
73 case MEMCACHED_CALLBACK_CLEANUP_FUNCTION:
74 {
75 *error= ptr->on_cleanup ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
76 return (void *)ptr->on_cleanup;
77 }
78 case MEMCACHED_CALLBACK_CLONE_FUNCTION:
79 {
80 *error= ptr->on_clone ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
81 return (void *)ptr->on_clone;
82 }
83 case MEMCACHED_CALLBACK_MALLOC_FUNCTION:
84 {
85 *error= ptr->call_malloc ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
86 return (void *)ptr->call_malloc;
87 }
88 case MEMCACHED_CALLBACK_REALLOC_FUNCTION:
89 {
90 *error= ptr->call_realloc ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
91 return (void *)ptr->call_realloc;
92 }
93 case MEMCACHED_CALLBACK_FREE_FUNCTION:
94 {
95 *error= ptr->call_free ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
96 return (void *)ptr->call_free;
97 }
98 default:
99 WATCHPOINT_ASSERT(0);
100 *error= MEMCACHED_FAILURE;
101 return NULL;
102 }
103 }