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/>.
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
37 #define MAX_SL_FRAGMENT_SIZE 0xFFFFF
38 #define MAX_SL_RESULTS 100
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; \
46 struct timeval_buf last_used_buf; \
47 const char *last_used; \
48 struct timeval_buf expire_buf; \
50 start = timeval_str_buf(&__slq->start_time, false, \
52 last_used = timeval_str_buf(&__slq->last_used, false, \
53 true, &last_used_buf); \
54 expire = timeval_str_buf(&__slq->expire_time, false, \
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)); \
62 /******************************************************************************
63 * Some helper stuff dealing with queries
64 ******************************************************************************/
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 beed 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 happended somewhere */
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 int snum; /* share snum */
88 uint64_t ctx1; /* client context 1 */
89 uint64_t ctx2; /* client context 2 */
90 sl_array_t *reqinfo; /* array with requested metadata */
91 char *query_string; /* the Spotlight query string */
92 uint64_t *cnids; /* restrict query to these CNIDs */
93 size_t cnids_num; /* Size of slq_cnids array */
94 const char *path_scope; /* path to directory to search */
95 struct sl_rslts *query_results; /* query results */
96 TALLOC_CTX *entries_ctx; /* talloc parent of the search results */
102 sl_array_t *fm_array;
105 struct sl_inode_path_map {
106 struct mds_ctx *mds_ctx;
111 /* Per process state */
113 struct tevent_context *ev_ctx;
114 void *backend_private;
117 /* Per tree connect state */
119 struct mdssvc_backend *backend;
120 struct mdssvc_ctx *mdssvc_ctx;
121 void *backend_private;
122 struct auth_session_info *pipe_session_info;
125 smb_iconv_t ic_nfc_to_nfd;
126 smb_iconv_t ic_nfd_to_nfc;
128 const char *sharename;
130 struct sl_query *query_list; /* list of active queries */
131 struct db_context *ino_path_map; /* dbwrap rbt for storing inode->path mappings */
134 struct mdssvc_backend {
135 bool (*init)(struct mdssvc_ctx *mdssvc_ctx);
136 bool (*connect)(struct mds_ctx *mds_ctx);
137 bool (*search_map)(struct sl_query *slq);
138 bool (*search_start)(struct sl_query *slq);
139 bool (*search_cont)(struct sl_query *slq);
140 bool (*shutdown)(struct mdssvc_ctx *mdssvc_ctx);
143 /******************************************************************************
144 * Function declarations
145 ******************************************************************************/
150 extern bool mds_init(struct messaging_context *msg_ctx);
151 extern bool mds_shutdown(void);
152 struct mds_ctx *mds_init_ctx(TALLOC_CTX *mem_ctx,
153 struct tevent_context *ev,
154 struct auth_session_info *session_info,
156 const char *sharename,
158 extern bool mds_dispatch(struct mds_ctx *query_ctx,
159 struct mdssvc_blob *request_blob,
160 struct mdssvc_blob *response_blob);
161 bool mds_add_result(struct sl_query *slq, const char *path);
163 #endif /* _MDSSVC_H */