6db2db82d3dbe1e86329f33157ecdca339370bb6
[awesomized/libmemcached] / libmemcached / 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 case MEMCACHED_CALLBACK_GET_FAILURE:
52 {
53 memcached_trigger_key func= (memcached_trigger_key)data;
54 ptr->get_key_failure= func;
55 break;
56 }
57 case MEMCACHED_CALLBACK_DELETE_TRIGGER:
58 {
59 memcached_trigger_delete_key func= (memcached_trigger_delete_key)data;
60 ptr->delete_trigger= func;
61 break;
62 }
63 default:
64 return MEMCACHED_FAILURE;
65 }
66
67 return MEMCACHED_SUCCESS;
68 }
69
70 void *memcached_callback_get(memcached_st *ptr,
71 memcached_callback flag,
72 memcached_return *error)
73 {
74 memcached_return local_error;
75 if (!error)
76 error = &local_error;
77
78 switch (flag)
79 {
80 case MEMCACHED_CALLBACK_USER_DATA:
81 {
82 *error= ptr->user_data ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
83 return (void *)ptr->user_data;
84 }
85 case MEMCACHED_CALLBACK_CLEANUP_FUNCTION:
86 {
87 *error= ptr->on_cleanup ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
88 return (void *)ptr->on_cleanup;
89 }
90 case MEMCACHED_CALLBACK_CLONE_FUNCTION:
91 {
92 *error= ptr->on_clone ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
93 return (void *)ptr->on_clone;
94 }
95 case MEMCACHED_CALLBACK_MALLOC_FUNCTION:
96 {
97 *error= ptr->call_malloc ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
98 return (void *)ptr->call_malloc;
99 }
100 case MEMCACHED_CALLBACK_REALLOC_FUNCTION:
101 {
102 *error= ptr->call_realloc ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
103 return (void *)ptr->call_realloc;
104 }
105 case MEMCACHED_CALLBACK_FREE_FUNCTION:
106 {
107 *error= ptr->call_free ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
108 return (void *)ptr->call_free;
109 }
110 case MEMCACHED_CALLBACK_GET_FAILURE:
111 {
112 *error= ptr->get_key_failure ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
113 return (void *)ptr->get_key_failure;
114 }
115 case MEMCACHED_CALLBACK_DELETE_TRIGGER:
116 {
117 *error= ptr->delete_trigger ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
118 return (void *)ptr->delete_trigger;
119 }
120 default:
121 WATCHPOINT_ASSERT(0);
122 *error= MEMCACHED_FAILURE;
123 return NULL;
124 }
125 }