]> arthur.barton.de Git - netatalk.git/blob - include/atalk/spotlight.h
Spotlight: use async Tracker SPARQL API
[netatalk.git] / include / atalk / spotlight.h
1 /*
2   Copyright (c) 2012 Frank Lahm <franklahm@gmail.com>
3
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.
8
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.
13 */
14
15 #ifdef HAVE_CONFIG_H
16 #include "config.h"
17 #endif /* HAVE_CONFIG_H */
18
19 #ifndef SPOTLIGHT_H
20 #define SPOTLIGHT_H
21
22 #include <stdint.h>
23 #include <stdbool.h>
24
25 #include <atalk/dalloc.h>
26 #include <atalk/globals.h>
27 #include <atalk/volume.h>
28
29 #ifdef HAVE_TRACKER
30 #include <gio/gio.h>
31 #include <tracker-sparql.h>
32 #include <libtracker-miner/tracker-miner.h>
33 #endif
34
35 /******************************************************************************
36  * Spotlight RPC and marshalling stuff
37  ******************************************************************************/
38
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
44
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
49
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;
56 typedef struct {
57     char sl_uuid[16];
58 }  sl_uuid_t;                         /* a UUID                               */
59 typedef struct {
60     uint16_t   ca_unkn1;
61     uint32_t   ca_context;
62     DALLOC_CTX *ca_cnids;
63 }  sl_cnids_t;                        /* an array of CNIDs                    */
64
65 /******************************************************************************
66  * Some helper stuff dealing with queries
67  ******************************************************************************/
68
69 /* query state */
70 typedef enum {
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         */
78 } slq_state_t;
79
80 /* Handle for query results */
81 struct sl_rslts {
82     int         num_results;
83     sl_cnids_t *cnids;
84     sl_array_t *fm_array;
85 };
86
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                    */
104 #ifdef HAVE_TRACKER
105     GCancellable     *cancellable;
106 #endif
107 } slq_t;
108
109 struct sl_ctx {
110 #ifdef HAVE_TRACKER
111     TrackerSparqlConnection *tracker_con;
112     GCancellable *cancellable;
113     GMainLoop *mainloop;
114 #endif
115     slq_t *query_list; /* list of active queries */
116 };
117
118 /******************************************************************************
119  * Function declarations
120  ******************************************************************************/
121
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);
128
129 #endif /* SPOTLIGHT_H */