s3: ldap: Ensure the ADS_STRUCT pointer doesn't get freed on error, we don't own...
[Samba.git] / ctdb / common / reqid.h
blob736e5b3890176a2eb4b219e6bafaa16d86089ce4
1 /*
2 Request id database
4 Copyright (C) Amitay Isaacs 2015
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #ifndef __CTDB_REQID_H__
21 #define __CTDB_REQID_H__
23 #include <talloc.h>
25 /**
26 * @file reqid.h
28 * @brief Request id database
30 * CTDB tracks messsages using request id. CTDB stores client state for each
31 * request id to process the replies correctly.
34 /**
35 * @brief Abstract struct to store request id database
37 struct reqid_context;
39 #define REQID_INVALID 0xffffffff
41 /**
42 * @brief Initialize request id database
44 * This returns a new request id context. Freeing this context will free
45 * all the memory associated with request id database.
47 * @param[in] mem_ctx Talloc memory context
48 * @param[in] start_id The initial id
49 * @param[out] result The new talloc_context structure
50 * @return 0 on success, errno on failure
52 int reqid_init(TALLOC_CTX *mem_ctx, int start_id,
53 struct reqid_context **result);
55 /**
56 * @brief Generate new request id and associate given data with the request id
58 * @param[in] reqid_ctx The request id context
59 * @param[in] private_data The state to associate with new request id
60 * @return new request id, REQID_INVALID on failure
62 uint32_t reqid_new(struct reqid_context *reqid_ctx, void *private_data);
64 #ifdef DOXYGEN
65 /**
66 * @brief Fetch the data associated with the request id
68 * @param[in] reqid_ctx The request id context
69 * @param[in] reqid The request id
70 * @param[in] type The data type of the stored data
71 * @return the data stored for the reqid, NULL on failure
73 type *reqid_find(struct reqid_context *reqid_ctx, uint32_t reqid, #type);
74 #else
75 void *_reqid_find(struct reqid_context *reqid_ctx, uint32_t reqid);
76 #define reqid_find(ctx, reqid, type) \
77 (type *)talloc_check_name(_reqid_find(ctx, reqid), #type)
78 #endif
80 /**
81 * @brief Remove the data associated with the request id
83 * @param[in] reqid_ctx The request id context
84 * @param[in] reqid The request id
85 * @return 0 on success, errno on failure
87 int reqid_remove(struct reqid_context *reqid_ctx, uint32_t reqid);
89 #endif /* __CTDB_REQID_H__ */