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_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; \
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 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 */
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 */
101 sl_array_t
*fm_array
;
104 struct sl_inode_path_map
{
105 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
;
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 ******************************************************************************/
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
,
159 const char *sharename
,
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 */