smbd: Simplify an if-condition
[Samba.git] / source3 / rpc_server / mdssvc / mdssvc.h
blob6d4e684ae8d862baad50a3138074fc62164b28b7
1 /*
2 Unix SMB/CIFS implementation.
3 Main metadata server / Spotlight routines
5 Copyright (C) Ralph Boehme 2012-2014
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef _MDSSVC_H
22 #define _MDSSVC_H
24 #include "dalloc.h"
25 #include "marshalling.h"
26 #include "lib/util/dlinklist.h"
27 #include "librpc/gen_ndr/mdssvc.h"
30 * glib uses TRUE and FALSE which was redefined by "includes.h" to be
31 * unusable, undefine so glib can establish its own working
32 * replacement.
34 #undef TRUE
35 #undef FALSE
37 #define MAX_SL_RESULTS 100
38 #define SL_PAGESIZE 50
39 #define MAX_SL_RUNTIME 30
40 #define MDS_TRACKER_ASYNC_TIMEOUT_MS 250
42 #define SLQ_DEBUG(lvl, _slq, state) do { if (CHECK_DEBUGLVL(lvl)) { \
43 const struct sl_query *__slq = _slq; \
44 struct timeval_buf start_buf; \
45 const char *start; \
46 struct timeval_buf last_used_buf; \
47 const char *last_used; \
48 struct timeval_buf expire_buf; \
49 const char *expire; \
50 start = timeval_str_buf(&__slq->start_time, false, \
51 true, &start_buf); \
52 last_used = timeval_str_buf(&__slq->last_used, false, \
53 true, &last_used_buf); \
54 expire = timeval_str_buf(&__slq->expire_time, false, \
55 true, &expire_buf); \
56 DEBUG(lvl,("%s slq[0x%jx,0x%jx], start: %s, last_used: %s, " \
57 "expires: %s, query: '%s'\n", state, \
58 (uintmax_t)__slq->ctx1, (uintmax_t)__slq->ctx2, \
59 start, last_used, expire, __slq->query_string)); \
60 }} while(0)
62 /******************************************************************************
63 * Some helper stuff dealing with queries
64 ******************************************************************************/
66 /* query state */
67 typedef enum {
68 SLQ_STATE_NEW, /* Query received from client */
69 SLQ_STATE_RUNNING, /* Query dispatched to Tracker */
70 SLQ_STATE_RESULTS, /* Async Tracker query read */
71 SLQ_STATE_FULL, /* the max amount of result has been queued */
72 SLQ_STATE_DONE, /* Got all results from Tracker */
73 SLQ_STATE_END, /* Query results returned to client */
74 SLQ_STATE_ERROR /* an error happened somewhere */
75 } slq_state_t;
77 /* query structure */
78 struct sl_query {
79 struct sl_query *prev, *next; /* list pointers */
80 struct mds_ctx *mds_ctx; /* context handle */
81 void *backend_private; /* search backend private data */
82 slq_state_t state; /* query state */
83 struct timeval start_time; /* Query start time */
84 struct timeval last_used; /* Time of last result fetch */
85 struct timeval expire_time; /* Query expiration time */
86 struct tevent_timer *te; /* query timeout */
87 uint64_t ctx1; /* client context 1 */
88 uint64_t ctx2; /* client context 2 */
89 sl_array_t *reqinfo; /* array with requested metadata */
90 char *query_string; /* the Spotlight query string */
91 uint64_t *cnids; /* restrict query to these CNIDs */
92 size_t cnids_num; /* Size of slq_cnids array */
93 const char *path_scope; /* path to directory to search */
94 struct sl_rslts *query_results; /* query results */
95 TALLOC_CTX *entries_ctx; /* talloc parent of the search results */
98 struct sl_rslts {
99 int num_results;
100 sl_cnids_t *cnids;
101 sl_array_t *fm_array;
104 struct sl_inode_path_map {
105 struct mds_ctx *mds_ctx;
106 uint64_t ino;
107 char *path;
108 struct stat_ex st;
111 /* Per process state */
112 struct mdssvc_ctx {
113 struct tevent_context *ev_ctx;
114 void *backend_private;
117 /* Per tree connect state */
118 struct mds_ctx {
119 struct mdssvc_backend *backend;
120 struct mdssvc_ctx *mdssvc_ctx;
121 void *backend_private;
122 struct auth_session_info *pipe_session_info;
123 struct dom_sid sid;
124 uid_t uid;
125 smb_iconv_t ic_nfc_to_nfd;
126 smb_iconv_t ic_nfd_to_nfc;
127 int snum;
128 const char *sharename;
129 const char *spath;
130 size_t spath_len;
131 struct connection_struct *conn;
132 struct sl_query *query_list; /* list of active queries */
133 struct db_context *ino_path_map; /* dbwrap rbt for storing inode->path mappings */
136 struct mdssvc_backend {
137 bool (*init)(struct mdssvc_ctx *mdssvc_ctx);
138 bool (*connect)(struct mds_ctx *mds_ctx);
139 bool (*search_map)(struct sl_query *slq);
140 bool (*search_start)(struct sl_query *slq);
141 bool (*search_cont)(struct sl_query *slq);
142 bool (*shutdown)(struct mdssvc_ctx *mdssvc_ctx);
145 /******************************************************************************
146 * Function declarations
147 ******************************************************************************/
150 * mdssvc.c
152 extern bool mds_init(struct messaging_context *msg_ctx);
153 extern bool mds_shutdown(void);
154 NTSTATUS mds_init_ctx(TALLOC_CTX *mem_ctx,
155 struct tevent_context *ev,
156 struct messaging_context *msg_ctx,
157 struct auth_session_info *session_info,
158 int snum,
159 const char *sharename,
160 const char *path,
161 struct mds_ctx **_mds_ctx);
162 extern bool mds_dispatch(struct mds_ctx *mds_ctx,
163 struct mdssvc_blob *request_blob,
164 struct mdssvc_blob *response_blob,
165 size_t max_fragment_size);
166 bool mds_add_result(struct sl_query *slq, const char *path);
168 #endif /* _MDSSVC_H */