2 +--------------------------------------------------------------------+
3 | libmemcached-awesome - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020-2021 Michael Wallner https://awesome.co/ |
13 +--------------------------------------------------------------------+
16 #include "libmemcached/common.h"
17 #include <sys/types.h>
20 These functions provide data and function callback support
23 memcached_return_t
memcached_callback_set(memcached_st
*shell
, const memcached_callback_t flag
,
25 Memcached
*ptr
= memcached2Memcached(shell
);
28 case MEMCACHED_CALLBACK_PREFIX_KEY
: {
29 return memcached_set_namespace(*ptr
, (char *) data
, data
? strlen((char *) data
) : 0);
32 case MEMCACHED_CALLBACK_USER_DATA
: {
33 ptr
->user_data
= const_cast<void *>(data
);
37 case MEMCACHED_CALLBACK_CLEANUP_FUNCTION
: {
38 memcached_cleanup_fn func
= *(memcached_cleanup_fn
*) &data
;
39 ptr
->on_cleanup
= func
;
43 case MEMCACHED_CALLBACK_CLONE_FUNCTION
: {
44 memcached_clone_fn func
= *(memcached_clone_fn
*) &data
;
49 case MEMCACHED_CALLBACK_GET_FAILURE
: {
50 memcached_trigger_key_fn func
= *(memcached_trigger_key_fn
*) &data
;
51 ptr
->get_key_failure
= func
;
55 case MEMCACHED_CALLBACK_DELETE_TRIGGER
: {
56 if (data
) // NULL would mean we are disabling.
58 if (memcached_behavior_get(ptr
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
)) {
59 return memcached_set_error(
60 *ptr
, MEMCACHED_INVALID_ARGUMENTS
, MEMCACHED_AT
,
61 memcached_literal_param("Delete triggers cannot be used if buffering is enabled"));
64 if (memcached_behavior_get(ptr
, MEMCACHED_BEHAVIOR_NOREPLY
)) {
65 return memcached_set_error(
66 *ptr
, MEMCACHED_INVALID_ARGUMENTS
, MEMCACHED_AT
,
67 memcached_literal_param(
68 "Delete triggers cannot be used if MEMCACHED_BEHAVIOR_NOREPLY is set"));
72 memcached_trigger_delete_key_fn func
= *(memcached_trigger_delete_key_fn
*) &data
;
73 ptr
->delete_trigger
= func
;
77 case MEMCACHED_CALLBACK_MAX
:
78 return memcached_set_error(*ptr
, MEMCACHED_INVALID_ARGUMENTS
, MEMCACHED_AT
,
79 memcached_literal_param("Invalid callback supplied"));
82 return MEMCACHED_SUCCESS
;
85 return MEMCACHED_INVALID_ARGUMENTS
;
88 void *memcached_callback_get(memcached_st
*shell
, const memcached_callback_t flag
,
89 memcached_return_t
*error
) {
90 Memcached
*ptr
= memcached2Memcached(shell
);
91 memcached_return_t local_error
;
97 *error
= MEMCACHED_INVALID_ARGUMENTS
;
102 case MEMCACHED_CALLBACK_PREFIX_KEY
: {
103 *error
= MEMCACHED_SUCCESS
;
104 if (ptr
->_namespace
) {
105 return (void *) memcached_array_string(ptr
->_namespace
);
110 case MEMCACHED_CALLBACK_USER_DATA
: {
111 *error
= ptr
->user_data
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
112 return (void *) ptr
->user_data
;
115 case MEMCACHED_CALLBACK_CLEANUP_FUNCTION
: {
116 *error
= ptr
->on_cleanup
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
117 return *(void **) &ptr
->on_cleanup
;
120 case MEMCACHED_CALLBACK_CLONE_FUNCTION
: {
121 *error
= ptr
->on_clone
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
122 return *(void **) &ptr
->on_clone
;
125 case MEMCACHED_CALLBACK_GET_FAILURE
: {
126 *error
= ptr
->get_key_failure
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
127 return *(void **) &ptr
->get_key_failure
;
130 case MEMCACHED_CALLBACK_DELETE_TRIGGER
: {
131 *error
= ptr
->delete_trigger
? MEMCACHED_SUCCESS
: MEMCACHED_FAILURE
;
132 return *(void **) &ptr
->delete_trigger
;
135 case MEMCACHED_CALLBACK_MAX
:
139 assert_msg(0, "Invalid callback passed to memcached_callback_get()");
140 *error
= MEMCACHED_FAILURE
;