]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/spotlight.h
da7aaf65fd3dcbc43803cf6468335557b7fbe6d1
[netatalk.git] / etc / afpd / 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 /**************************************************************************************************
30  * Spotlight module stuff
31  **************************************************************************************************/
32
33 #define SL_MODULE_VERSION 1
34
35 struct sl_module_export {
36     int sl_mod_version;
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 };
42
43 extern int sl_mod_load(const char *path);
44
45
46 /**************************************************************************************************
47  * Spotlight RPC and marshalling stuff
48  **************************************************************************************************/
49
50 /* FPSpotlightRPC subcommand codes */
51 #define SPOTLIGHT_CMD_OPEN    1
52 #define SPOTLIGHT_CMD_FLAGS   2
53 #define SPOTLIGHT_CMD_RPC     3
54 #define SPOTLIGHT_CMD_OPEN2   4
55
56 /* Can be ored and used as flags */
57 #define SL_ENC_LITTLE_ENDIAN 1
58 #define SL_ENC_BIG_ENDIAN    2
59 #define SL_ENC_UTF_16        4
60
61 typedef DALLOC_CTX     sl_array_t;    /* an array of elements                                           */
62 typedef DALLOC_CTX     sl_dict_t;     /* an array of key/value elements                                 */
63 typedef DALLOC_CTX     sl_filemeta_t; /* contains one sl_array_t                                        */
64 typedef int            sl_nil_t;      /* a nil element                                                  */
65 typedef bool           sl_bool_t;     /* a boolean, we avoid bool_t as it's a define for something else */
66 typedef struct timeval sl_time_t;     /* a boolean, we avoid bool_t as it's a define for something else */
67 typedef struct {
68     char sl_uuid[16];
69 }  sl_uuid_t;                         /* a UUID                                                         */
70 typedef struct {
71     uint16_t   ca_unkn1;
72     uint32_t   ca_context;
73     DALLOC_CTX *ca_cnids;
74 }  sl_cnids_t;                        /* an array of CNIDs                                              */
75
76 /**************************************************************************************************
77  * Some helper stuff dealing with queries
78  **************************************************************************************************/
79
80 /* Internal query state */
81 typedef enum {
82     SLQ_STATE_NEW      = 1,           /* Query received from client                                     */
83     SLQ_STATE_RUNNING  = 2,           /* Query dispatched to Tracker                                    */
84     SLQ_STATE_DONE     = 3,           /* Tracker finished                                               */
85     SLQ_STATE_END      = 4            /* Query results returned to client                               */
86 } slq_state_t;
87
88 /* Internal query data structure */
89 typedef struct {
90     slq_state_t    slq_state;         /* State                                                          */
91     AFPObj         *slq_obj;          /* global AFPObj handle                                           */
92     const struct vol *slq_vol;        /* volume handle                                                  */
93     DALLOC_CTX     *slq_reply;        /* reply handle                                                   */
94     time_t         slq_time;          /* timestamp where we received this query                         */
95     uint64_t       slq_ctx1;          /* client context 1                                               */
96     uint64_t       slq_ctx2;          /* client context 2                                               */
97     const char     *slq_qstring;      /* the Spotlight query string                                     */
98     DALLOC_CTX     *slq_reqinfo;      /* array with requested metadata                                  */
99     int            slq_metacount;     /* number of requested metadata attributes in slq_reqinfo         */
100     void           *slq_tracker_cursor; /* Tracker query result cursor                                  */
101 } slq_t;
102
103 /**************************************************************************************************
104  * Function declarations
105  **************************************************************************************************/
106
107 extern int afp_spotlight_rpc(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen);
108 extern int sl_pack(DALLOC_CTX *query, char *buf);
109 extern int sl_unpack(DALLOC_CTX *query, const char *buf);
110
111 #endif /* SPOTLIGHT_H */