2 Copyright (c) 2012 Frank Lahm <franklahm@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
17 #endif /* HAVE_CONFIG_H */
25 #include <atalk/dalloc.h>
26 #include <atalk/globals.h>
27 #include <atalk/volume.h>
29 /**************************************************************************************************
30 * Spotlight module stuff
31 **************************************************************************************************/
33 #define SL_MODULE_VERSION 1
35 struct sl_module_export {
37 int (*sl_mod_init) (void *);
38 int (*sl_mod_start_search)(void *);
39 int (*sl_mod_fetch_result)(void *);
40 int (*sl_mod_end_search) (void *);
41 int (*sl_mod_fetch_attrs) (void *);
42 int (*sl_mod_error) (void *);
43 int (*sl_mod_index_file) (const void *);
46 extern int sl_mod_load(AFPObj *obj);
47 extern void sl_index_file(const char *path);
49 /**************************************************************************************************
50 * Spotlight RPC and marshalling stuff
51 **************************************************************************************************/
53 /* FPSpotlightRPC subcommand codes */
54 #define SPOTLIGHT_CMD_OPEN 1
55 #define SPOTLIGHT_CMD_FLAGS 2
56 #define SPOTLIGHT_CMD_RPC 3
57 #define SPOTLIGHT_CMD_OPEN2 4
59 /* Can be ored and used as flags */
60 #define SL_ENC_LITTLE_ENDIAN 1
61 #define SL_ENC_BIG_ENDIAN 2
62 #define SL_ENC_UTF_16 4
64 typedef DALLOC_CTX sl_array_t; /* an array of elements */
65 typedef DALLOC_CTX sl_dict_t; /* an array of key/value elements */
66 typedef DALLOC_CTX sl_filemeta_t; /* contains one sl_array_t */
67 typedef int sl_nil_t; /* a nil element */
68 typedef bool sl_bool_t; /* a boolean, we avoid bool_t as it's a define for something else */
69 typedef struct timeval sl_time_t; /* a boolean, we avoid bool_t as it's a define for something else */
72 } sl_uuid_t; /* a UUID */
77 } sl_cnids_t; /* an array of CNIDs */
79 /**************************************************************************************************
80 * Some helper stuff dealing with queries
81 **************************************************************************************************/
83 /* Internal query state */
85 SLQ_STATE_NEW = 1, /* Query received from client */
86 SLQ_STATE_RUNNING = 2, /* Query dispatched to Tracker */
87 SLQ_STATE_DONE = 3, /* Tracker finished */
88 SLQ_STATE_END = 4, /* Query results returned to client */
89 SLQ_STATE_ATTRS = 5 /* Fetch metadata for an object */
92 /* Internal query data structure */
93 typedef struct _slq_t {
94 struct list_head slq_list; /* queries are stored in a list */
95 slq_state_t slq_state; /* State */
96 AFPObj *slq_obj; /* global AFPObj handle */
97 const struct vol *slq_vol; /* volume handle */
98 DALLOC_CTX *slq_reply; /* reply handle */
99 time_t slq_time; /* timestamp where we received this query */
100 uint64_t slq_ctx1; /* client context 1 */
101 uint64_t slq_ctx2; /* client context 2 */
102 sl_array_t *slq_reqinfo; /* array with requested metadata */
103 const char *slq_qstring; /* the Spotlight query string */
104 uint64_t *slq_cnids; /* Pointer to array with CNIDs to which a query applies */
105 size_t slq_cnids_num; /* Size of slq_cnids array */
106 const char *slq_path; /* Path to file or dir, used in fetchAttributes */
107 void *slq_tracker_cursor; /* Tracker SPARQL query result cursor */
108 bool slq_allow_expr; /* Whether to allow logic expressions */
109 uint64_t slq_result_limit; /* Whether to LIMIT SPARQL results, default of 0 means no limit */
112 /**************************************************************************************************
113 * Function declarations
114 **************************************************************************************************/
116 extern int afp_spotlight_rpc(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen);
117 extern int sl_pack(DALLOC_CTX *query, char *buf);
118 extern int sl_unpack(DALLOC_CTX *query, const char *buf);
119 extern void configure_spotlight_attributes(const char *attributes);
121 #endif /* SPOTLIGHT_H */