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>
31 #include <tracker-sparql.h>
32 #include <libtracker-miner/tracker-miner.h>
35 /******************************************************************************
36 * Spotlight RPC and marshalling stuff
37 ******************************************************************************/
39 /* FPSpotlightRPC subcommand codes */
40 #define SPOTLIGHT_CMD_OPEN 1
41 #define SPOTLIGHT_CMD_FLAGS 2
42 #define SPOTLIGHT_CMD_RPC 3
43 #define SPOTLIGHT_CMD_OPEN2 4
45 /* Can be ored and used as flags */
46 #define SL_ENC_LITTLE_ENDIAN 1
47 #define SL_ENC_BIG_ENDIAN 2
48 #define SL_ENC_UTF_16 4
50 typedef DALLOC_CTX sl_array_t; /* an array of elements */
51 typedef DALLOC_CTX sl_dict_t; /* an array of key/value elements */
52 typedef DALLOC_CTX sl_filemeta_t; /* contains one sl_array_t */
53 typedef int sl_nil_t; /* a nil element */
54 typedef bool sl_bool_t; /* a boolean, we avoid bool_t */
55 typedef struct timeval sl_time_t;
58 } sl_uuid_t; /* a UUID */
63 } sl_cnids_t; /* an array of CNIDs */
65 /******************************************************************************
66 * Some helper stuff dealing with queries
67 ******************************************************************************/
71 SLQ_STATE_NEW, /* Query received from client */
72 SLQ_STATE_RUNNING, /* Query dispatched to Tracker */
73 SLQ_STATE_RESULTS, /* Async Tracker query read */
74 SLQ_STATE_DONE, /* Got all results from Tracker */
75 SLQ_STATE_CANCEL_PENDING, /* a cancel op for the query is pending */
76 SLQ_STATE_CANCELLED, /* the query has been cancelled */
77 SLQ_STATE_ERROR /* an error happended somewhere */
80 /* Handle for query results */
87 /* Internal query data structure */
88 typedef struct _slq_t {
89 struct list_head slq_list; /* queries are stored in a list */
90 slq_state_t slq_state; /* State */
91 AFPObj *slq_obj; /* global AFPObj handle */
92 const struct vol *slq_vol; /* volume handle */
93 time_t slq_time; /* timestamp received query */
94 uint64_t slq_ctx1; /* client context 1 */
95 uint64_t slq_ctx2; /* client context 2 */
96 sl_array_t *slq_reqinfo; /* array with requested metadata */
97 const char *slq_qstring; /* the Spotlight query string */
98 uint64_t *slq_cnids; /* Pointer to array with CNIDs */
99 size_t slq_cnids_num; /* Size of slq_cnids array */
100 void *tracker_cursor; /* Tracker SPARQL cursor */
101 bool slq_allow_expr; /* Whether to allow expressions */
102 uint64_t slq_result_limit; /* Whether to LIMIT SPARQL results */
103 struct sl_rslts *query_results; /* query results */
105 GCancellable *cancellable;
111 TrackerSparqlConnection *tracker_con;
112 GCancellable *cancellable;
115 slq_t *query_list; /* list of active queries */
118 /******************************************************************************
119 * Function declarations
120 ******************************************************************************/
122 extern int spotlight_init(AFPObj *obj);
123 extern int afp_spotlight_rpc(AFPObj *obj, char *ibuf, size_t ibuflen _U_,
124 char *rbuf, size_t *rbuflen);
125 extern int sl_pack(DALLOC_CTX *query, char *buf);
126 extern int sl_unpack(DALLOC_CTX *query, const char *buf);
127 extern void configure_spotlight_attributes(const char *attributes);
129 #endif /* SPOTLIGHT_H */