1334cfbbfSTrond Norbye/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2334cfbbfSTrond Norbye#ifndef MEMCACHED_SERVER_API_H
3334cfbbfSTrond Norbye#define MEMCACHED_SERVER_API_H
4334cfbbfSTrond Norbye#include <inttypes.h>
58f89d2eaSDustin Sallings
68f89d2eaSDustin Sallings#include <memcached/types.h>
78f89d2eaSDustin Sallings#include <memcached/config_parser.h>
88f89d2eaSDustin Sallings
9334cfbbfSTrond Norbye#ifdef __cplusplus
10334cfbbfSTrond Norbyeextern "C" {
11334cfbbfSTrond Norbye#endif
12334cfbbfSTrond Norbye
138f89d2eaSDustin Sallings    typedef struct {
148f89d2eaSDustin Sallings        /**
158f89d2eaSDustin Sallings         * The current time.
168f89d2eaSDustin Sallings         */
178f89d2eaSDustin Sallings        rel_time_t (*get_current_time)(void);
188f89d2eaSDustin Sallings
198f89d2eaSDustin Sallings        /**
208f89d2eaSDustin Sallings         * Get the relative time for the given time_t value.
218f89d2eaSDustin Sallings         */
228f89d2eaSDustin Sallings        rel_time_t (*realtime)(const time_t exptime);
238f89d2eaSDustin Sallings
24aaa1d1c4STrond Norbye        /**
25aaa1d1c4STrond Norbye         * Get the absolute time for the given rel_time_t value.
26aaa1d1c4STrond Norbye         */
27aaa1d1c4STrond Norbye        time_t (*abstime)(const rel_time_t exptime);
288f89d2eaSDustin Sallings
298f89d2eaSDustin Sallings        /**
308f89d2eaSDustin Sallings         * Get the server's version number.
318f89d2eaSDustin Sallings         *
328f89d2eaSDustin Sallings         * @return the server's version number
338f89d2eaSDustin Sallings         */
348f89d2eaSDustin Sallings        const char* (*server_version)(void);
358f89d2eaSDustin Sallings
368f89d2eaSDustin Sallings        /**
378f89d2eaSDustin Sallings         * Generate a simple hash value of a piece of data.
388f89d2eaSDustin Sallings         *
398f89d2eaSDustin Sallings         * @param data pointer to data to hash
408f89d2eaSDustin Sallings         * @param size size of the data to generate the hash value of
418f89d2eaSDustin Sallings         * @param seed an extra seed value for the hash function
428f89d2eaSDustin Sallings         * @return hash value of the data.
438f89d2eaSDustin Sallings         */
448f89d2eaSDustin Sallings        uint32_t (*hash)(const void *data, size_t size, uint32_t seed);
458f89d2eaSDustin Sallings
468f89d2eaSDustin Sallings        /**
478f89d2eaSDustin Sallings         * parser config options
488f89d2eaSDustin Sallings         */
498f89d2eaSDustin Sallings        int (*parse_config)(const char *str, struct config_item items[], FILE *error);
508f89d2eaSDustin Sallings
516c5ff8d7STrond Norbye        /**
526c5ff8d7STrond Norbye         * Request the server to start a shutdown sequence.
536c5ff8d7STrond Norbye         */
546c5ff8d7STrond Norbye        void (*shutdown)(void);
556c5ff8d7STrond Norbye
567b3cfe46STrond Norbye        /**
577b3cfe46STrond Norbye         * Get the current configuration from the core..
587b3cfe46STrond Norbye         * See "stats settings" for a list of legal keywords
597b3cfe46STrond Norbye         */
607b3cfe46STrond Norbye        bool (*get_config)(struct config_item items[]);
617b3cfe46STrond Norbye
626c5ff8d7STrond Norbye    } SERVER_CORE_API;
636c5ff8d7STrond Norbye
646c5ff8d7STrond Norbye    typedef struct {
656c5ff8d7STrond Norbye        /**
666c5ff8d7STrond Norbye         * Allocate and deallocate thread-specific stats arrays for
676c5ff8d7STrond Norbye         * engine-maintained separate stats.
686c5ff8d7STrond Norbye         */
696c5ff8d7STrond Norbye        void *(*new_stats)(void);
706c5ff8d7STrond Norbye        void (*release_stats)(void*);
716c5ff8d7STrond Norbye
726c5ff8d7STrond Norbye        /**
736c5ff8d7STrond Norbye         * Tell the server we've evicted an item.
746c5ff8d7STrond Norbye         */
756c5ff8d7STrond Norbye        void (*evicting)(const void *cookie,
766c5ff8d7STrond Norbye                         const void *key,
776c5ff8d7STrond Norbye                         int nkey);
786c5ff8d7STrond Norbye    } SERVER_STAT_API;
796c5ff8d7STrond Norbye
806c5ff8d7STrond Norbye    /**
816c5ff8d7STrond Norbye     * Commands to operate on a specific cookie.
826c5ff8d7STrond Norbye     */
836c5ff8d7STrond Norbye    typedef struct {
846c5ff8d7STrond Norbye        /**
856c5ff8d7STrond Norbye         * Retrieve socket file descriptor of the session for the given cookie.
866c5ff8d7STrond Norbye         *
876c5ff8d7STrond Norbye         * @param cookie The cookie provided by the frontend
886c5ff8d7STrond Norbye         *
896c5ff8d7STrond Norbye         * @return the socket file descriptor of the session for the given cookie.
906c5ff8d7STrond Norbye         */
91ce9a18d0STrond Norbye#ifdef WIN32
92ce9a18d0STrond Norbye        SOCKET (*get_socket_fd)(const void *cookie);
93ce9a18d0STrond Norbye#else
946c5ff8d7STrond Norbye        int (*get_socket_fd)(const void *cookie);
95ce9a18d0STrond Norbye#endif
966c5ff8d7STrond Norbye
978f89d2eaSDustin Sallings        /**
988f89d2eaSDustin Sallings         * Get the auth data for the connection associated with the
998f89d2eaSDustin Sallings         * given cookie.
1008f89d2eaSDustin Sallings         *
1018f89d2eaSDustin Sallings         * @param cookie The cookie provided by the frontend
1028f89d2eaSDustin Sallings         * @param data Pointer to auth_data_t structure for returning the values
1038f89d2eaSDustin Sallings         *
1048f89d2eaSDustin Sallings         */
1058f89d2eaSDustin Sallings        void (*get_auth_data)(const void *cookie, auth_data_t *data);
1068f89d2eaSDustin Sallings
1078f89d2eaSDustin Sallings        /**
1088f89d2eaSDustin Sallings         * Store engine-specific session data on the given cookie.
1098f89d2eaSDustin Sallings         *
1108f89d2eaSDustin Sallings         * The engine interface allows for a single item to be
1118f89d2eaSDustin Sallings         * attached to the connection that it can use to track
1128f89d2eaSDustin Sallings         * connection-specific data throughout duration of the
1138f89d2eaSDustin Sallings         * connection.
1148f89d2eaSDustin Sallings         *
1158f89d2eaSDustin Sallings         * @param cookie The cookie provided by the frontend
1168f89d2eaSDustin Sallings         * @param engine_data pointer to opaque data
1178f89d2eaSDustin Sallings         */
1188f89d2eaSDustin Sallings        void (*store_engine_specific)(const void *cookie, void *engine_data);
1198f89d2eaSDustin Sallings
1208f89d2eaSDustin Sallings        /**
1218f89d2eaSDustin Sallings         * Retrieve engine-specific session data for the given cookie.
1228f89d2eaSDustin Sallings         *
1238f89d2eaSDustin Sallings         * @param cookie The cookie provided by the frontend
1248f89d2eaSDustin Sallings         *
1258f89d2eaSDustin Sallings         * @return the data provied by store_engine_specific or NULL
1268f89d2eaSDustin Sallings         *         if none was provided
1278f89d2eaSDustin Sallings         */
1288f89d2eaSDustin Sallings        void *(*get_engine_specific)(const void *cookie);
130bd0ecd24Sabhinavdangeti        /**
131bd0ecd24Sabhinavdangeti         * Check if datatype for supported by the connection.
132bd0ecd24Sabhinavdangeti         *
1334f426e26Sabhinavdangeti         * @param cookie The cookie provided by the frontend
1344f426e26Sabhinavdangeti         *
135bd0ecd24Sabhinavdangeti         * @return true if supported or else false.
136bd0ecd24Sabhinavdangeti         */
137bd0ecd24Sabhinavdangeti        bool (*is_datatype_supported)(const void *cookie);
1392c217587Sabhinavdangeti        /**
1404f426e26Sabhinavdangeti         * Retrieve the opcode of the connection, if
1414f426e26Sabhinavdangeti         * ewouldblock flag is set. Please note that the ewouldblock
1424f426e26Sabhinavdangeti         * flag for a connection is cleared before calling into
1434f426e26Sabhinavdangeti         * the engine interface, so this method only works in the
1444f426e26Sabhinavdangeti         * notify hooks.
1454f426e26Sabhinavdangeti         *
1464f426e26Sabhinavdangeti         * @param cookie The cookie provided by the frontend
1474f426e26Sabhinavdangeti         *
1484f426e26Sabhinavdangeti         * @return the opcode from the binary_header saved in the
1494f426e26Sabhinavdangeti         * connection.
1504f426e26Sabhinavdangeti         */
1514f426e26Sabhinavdangeti        uint8_t (*get_opcode_if_ewouldblock_set)(const void *cookie);
1534f426e26Sabhinavdangeti        /**
1544f426e26Sabhinavdangeti         * Validate given ns_server's session cas token against
1554f426e26Sabhinavdangeti         * saved token in memached, and if so incrment the session
1564f426e26Sabhinavdangeti         * counter.
1572c217587Sabhinavdangeti         *
1582c217587Sabhinavdangeti         * @param cas The cas token from the request
1592c217587Sabhinavdangeti         *
1602c217587Sabhinavdangeti         * @return true if session cas matches the one saved in
1612c217587Sabhinavdangeti         * memcached
1622c217587Sabhinavdangeti         */
1632c217587Sabhinavdangeti        bool (*validate_session_cas)(const uint64_t cas);
1654f426e26Sabhinavdangeti        /**
1664f426e26Sabhinavdangeti         * Decrement session_cas's counter everytime a control
1674f426e26Sabhinavdangeti         * command completes execution.
1684f426e26Sabhinavdangeti         */
1694f426e26Sabhinavdangeti        void (*decrement_session_ctr)(void);
1708f89d2eaSDustin Sallings
1718f89d2eaSDustin Sallings        /**
1728f89d2eaSDustin Sallings         * Let a connection know that IO has completed.
1738f89d2eaSDustin Sallings         * @param cookie cookie representing the connection
1748f89d2eaSDustin Sallings         * @param status the status for the io operation
1758f89d2eaSDustin Sallings         */
1768f89d2eaSDustin Sallings        void (*notify_io_complete)(const void *cookie,
1778f89d2eaSDustin Sallings                                   ENGINE_ERROR_CODE status);
1788f89d2eaSDustin Sallings
17983835a25STrond Norbye        /**
18083835a25STrond Norbye         * Notify the core that we're holding on to this cookie for
18183835a25STrond Norbye         * future use. (The core guarantees it will not invalidate the
18283835a25STrond Norbye         * memory until the cookie is invalidated by calling release())
18383835a25STrond Norbye         */
18455627b40STrond Norbye        ENGINE_ERROR_CODE (*reserve)(const void *cookie);
18583835a25STrond Norbye
18683835a25STrond Norbye        /**
18783835a25STrond Norbye         * Notify the core that we're releasing the reference to the
18883835a25STrond Norbye         * The engine is not allowed to use the cookie (the core may invalidate
18983835a25STrond Norbye         * the memory)
19083835a25STrond Norbye         */
19155627b40STrond Norbye        ENGINE_ERROR_CODE (*release)(const void *cookie);
19283835a25STrond Norbye
1938667210cSTrond Norbye        /**
1948667210cSTrond Norbye         * Set admin access for this connection
1958667210cSTrond Norbye         */
1968667210cSTrond Norbye        void (*set_admin)(const void *cookie);
1978667210cSTrond Norbye
1988667210cSTrond Norbye        /**
1998667210cSTrond Norbye         * See if this connection have admin access or not
2008667210cSTrond Norbye         */
2018667210cSTrond Norbye        bool (*is_admin)(const void *cookie);
20283835a25STrond Norbye
20328e825f7STrond Norbye        /**
20428e825f7STrond Norbye         * Set the priority for this connection
20528e825f7STrond Norbye         */
20628e825f7STrond Norbye        void (*set_priority)(const void *cookie, CONN_PRIORITY priority);
2076c5ff8d7STrond Norbye    } SERVER_COOKIE_API;
208334cfbbfSTrond Norbye
209f603fdb6STrond Norbye#ifdef WIN32
210334cfbbfSTrond Norbye#undef interface
211334cfbbfSTrond Norbye#endif
212334cfbbfSTrond Norbye
2138f89d2eaSDustin Sallings    typedef SERVER_HANDLE_V1* (*GET_SERVER_API)(void);
214334cfbbfSTrond Norbye
215334cfbbfSTrond Norbye#ifdef __cplusplus
216334cfbbfSTrond Norbye}
217334cfbbfSTrond Norbye#endif
218334cfbbfSTrond Norbye
219334cfbbfSTrond Norbye#endif