d57be5156c13f1230e1b5e5d8ada61e3cc5027db
2 +--------------------------------------------------------------------+
3 | libmemcached - 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 Michael Wallner <mike@php.net> |
13 +--------------------------------------------------------------------+
16 #include "libmemcached/common.h"
18 static inline void _result_init(memcached_result_st
*self
, Memcached
*memc
) {
20 self
->item_expiration
= 0;
24 self
->numeric_value
= UINT64_MAX
;
26 self
->item_key
[0] = 0;
29 memcached_result_st
*memcached_result_create(const memcached_st
*shell
, memcached_result_st
*ptr
) {
30 const Memcached
*memc
= memcached2Memcached(shell
);
32 /* Saving malloc calls :) */
34 ptr
->options
.is_allocated
= false;
36 ptr
= libmemcached_xmalloc(memc
, memcached_result_st
);
42 ptr
->options
.is_allocated
= true;
45 ptr
->options
.is_initialized
= true;
47 _result_init(ptr
, (memcached_st
*) memc
);
49 WATCHPOINT_SET(ptr
->value
.options
.is_initialized
= false);
50 memcached_string_create((memcached_st
*) memc
, &ptr
->value
, 0);
51 WATCHPOINT_ASSERT_INITIALIZED(&ptr
->value
);
52 WATCHPOINT_ASSERT(ptr
->value
.string
== NULL
);
57 void memcached_result_reset(memcached_result_st
*ptr
) {
59 memcached_string_reset(&ptr
->value
);
62 ptr
->item_expiration
= 0;
63 ptr
->numeric_value
= UINT64_MAX
;
66 void memcached_result_free(memcached_result_st
*ptr
) {
71 memcached_string_free(&ptr
->value
);
72 ptr
->numeric_value
= UINT64_MAX
;
74 if (memcached_is_allocated(ptr
)) {
76 ptr
->root
); // Without a root, that means that result was not properly initialized.
77 libmemcached_free(ptr
->root
, ptr
);
80 ptr
->options
.is_initialized
= false;
84 void memcached_result_reset_value(memcached_result_st
*ptr
) {
85 memcached_string_reset(&ptr
->value
);
88 memcached_return_t
memcached_result_set_value(memcached_result_st
*ptr
, const char *value
,
90 if (memcached_failed(memcached_string_append(&ptr
->value
, value
, length
))) {
91 return memcached_set_errno(*ptr
->root
, errno
, MEMCACHED_AT
);
94 return MEMCACHED_SUCCESS
;
97 const char *memcached_result_key_value(const memcached_result_st
*self
) {
98 return self
->key_length
? self
->item_key
: NULL
;
101 size_t memcached_result_key_length(const memcached_result_st
*self
) {
102 return self
->key_length
;
105 const char *memcached_result_value(const memcached_result_st
*self
) {
106 const memcached_string_st
*sptr
= &self
->value
;
107 return memcached_string_value(sptr
);
110 size_t memcached_result_length(const memcached_result_st
*self
) {
111 const memcached_string_st
*sptr
= &self
->value
;
112 return memcached_string_length(sptr
);
115 char *memcached_result_take_value(memcached_result_st
*self
) {
116 memcached_string_st
*sptr
= &self
->value
;
117 return memcached_string_take_value(sptr
);
120 uint32_t memcached_result_flags(const memcached_result_st
*self
) {
121 return self
->item_flags
;
124 uint64_t memcached_result_cas(const memcached_result_st
*self
) {
125 return self
->item_cas
;
128 void memcached_result_set_flags(memcached_result_st
*self
, uint32_t flags
) {
129 self
->item_flags
= flags
;
132 void memcached_result_set_expiration(memcached_result_st
*self
, time_t expiration
) {
133 self
->item_expiration
= expiration
;