1/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2#ifndef MEMCACHED_SERVER_API_H
3#define MEMCACHED_SERVER_API_H
4#include <inttypes.h>
5
6#include <memcached/types.h>
7#include <memcached/config_parser.h>
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13    typedef struct {
14        /**
15         * The current time.
16         */
17        rel_time_t (*get_current_time)(void);
18
19        /**
20         * Get the relative time for the given time_t value.
21         */
22        rel_time_t (*realtime)(const time_t exptime);
23
24        /**
25         * Get the absolute time for the given rel_time_t value.
26         */
27        time_t (*abstime)(const rel_time_t exptime);
28
29        /**
30         * Get the server's version number.
31         *
32         * @return the server's version number
33         */
34        const char* (*server_version)(void);
35
36        /**
37         * Generate a simple hash value of a piece of data.
38         *
39         * @param data pointer to data to hash
40         * @param size size of the data to generate the hash value of
41         * @param seed an extra seed value for the hash function
42         * @return hash value of the data.
43         */
44        uint32_t (*hash)(const void *data, size_t size, uint32_t seed);
45
46        /**
47         * parser config options
48         */
49        int (*parse_config)(const char *str, struct config_item items[], FILE *error);
50
51        /**
52         * Request the server to start a shutdown sequence.
53         */
54        void (*shutdown)(void);
55
56        /**
57         * Get the current configuration from the core..
58         * See "stats settings" for a list of legal keywords
59         */
60        bool (*get_config)(struct config_item items[]);
61
62    } SERVER_CORE_API;
63
64    typedef struct {
65        /**
66         * Allocate and deallocate thread-specific stats arrays for
67         * engine-maintained separate stats.
68         */
69        void *(*new_stats)(void);
70        void (*release_stats)(void*);
71
72        /**
73         * Tell the server we've evicted an item.
74         */
75        void (*evicting)(const void *cookie,
76                         const void *key,
77                         int nkey);
78    } SERVER_STAT_API;
79
80    /**
81     * Commands to operate on a specific cookie.
82     */
83    typedef struct {
84        /**
85         * Retrieve socket file descriptor of the session for the given cookie.
86         *
87         * @param cookie The cookie provided by the frontend
88         *
89         * @return the socket file descriptor of the session for the given cookie.
90         */
91#ifdef WIN32
92        SOCKET (*get_socket_fd)(const void *cookie);
93#else
94        int (*get_socket_fd)(const void *cookie);
95#endif
96
97        /**
98         * Get the auth data for the connection associated with the
99         * given cookie.
100         *
101         * @param cookie The cookie provided by the frontend
102         * @param data Pointer to auth_data_t structure for returning the values
103         *
104         */
105        void (*get_auth_data)(const void *cookie, auth_data_t *data);
106
107        /**
108         * Store engine-specific session data on the given cookie.
109         *
110         * The engine interface allows for a single item to be
111         * attached to the connection that it can use to track
112         * connection-specific data throughout duration of the
113         * connection.
114         *
115         * @param cookie The cookie provided by the frontend
116         * @param engine_data pointer to opaque data
117         */
118        void (*store_engine_specific)(const void *cookie, void *engine_data);
119
120        /**
121         * Retrieve engine-specific session data for the given cookie.
122         *
123         * @param cookie The cookie provided by the frontend
124         *
125         * @return the data provied by store_engine_specific or NULL
126         *         if none was provided
127         */
128        void *(*get_engine_specific)(const void *cookie);
129
130        /**
131         * Check if datatype for supported by the connection.
132         *
133         * @param cookie The cookie provided by the frontend
134         *
135         * @return true if supported or else false.
136         */
137        bool (*is_datatype_supported)(const void *cookie);
138
139        /**
140         * Retrieve the opcode of the connection, if
141         * ewouldblock flag is set. Please note that the ewouldblock
142         * flag for a connection is cleared before calling into
143         * the engine interface, so this method only works in the
144         * notify hooks.
145         *
146         * @param cookie The cookie provided by the frontend
147         *
148         * @return the opcode from the binary_header saved in the
149         * connection.
150         */
151        uint8_t (*get_opcode_if_ewouldblock_set)(const void *cookie);
152
153        /**
154         * Validate given ns_server's session cas token against
155         * saved token in memached, and if so incrment the session
156         * counter.
157         *
158         * @param cas The cas token from the request
159         *
160         * @return true if session cas matches the one saved in
161         * memcached
162         */
163        bool (*validate_session_cas)(const uint64_t cas);
164
165        /**
166         * Decrement session_cas's counter everytime a control
167         * command completes execution.
168         */
169        void (*decrement_session_ctr)(void);
170
171        /**
172         * Let a connection know that IO has completed.
173         * @param cookie cookie representing the connection
174         * @param status the status for the io operation
175         */
176        void (*notify_io_complete)(const void *cookie,
177                                   ENGINE_ERROR_CODE status);
178
179        /**
180         * Notify the core that we're holding on to this cookie for
181         * future use. (The core guarantees it will not invalidate the
182         * memory until the cookie is invalidated by calling release())
183         */
184        ENGINE_ERROR_CODE (*reserve)(const void *cookie);
185
186        /**
187         * Notify the core that we're releasing the reference to the
188         * The engine is not allowed to use the cookie (the core may invalidate
189         * the memory)
190         */
191        ENGINE_ERROR_CODE (*release)(const void *cookie);
192
193        /**
194         * Set admin access for this connection
195         */
196        void (*set_admin)(const void *cookie);
197
198        /**
199         * See if this connection have admin access or not
200         */
201        bool (*is_admin)(const void *cookie);
202
203        /**
204         * Set the priority for this connection
205         */
206        void (*set_priority)(const void *cookie, CONN_PRIORITY priority);
207    } SERVER_COOKIE_API;
208
209#ifdef WIN32
210#undef interface
211#endif
212
213    typedef SERVER_HANDLE_V1* (*GET_SERVER_API)(void);
214
215#ifdef __cplusplus
216}
217#endif
218
219#endif
220