netatalk: spotlight.h Source File

netatalk 4.5.0
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
spotlight.h
Go to the documentation of this file.
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 <stdbool.h>
23#include <stddef.h>
24#include <stdint.h>
25
26#include <atalk/globals.h>
27#include <atalk/volume.h>
28#include <atalk/dalloc.h>
29
30/******************************************************************************
31 * Spotlight RPC and marshalling stuff
32 ******************************************************************************/
33
34/* FPSpotlightRPC subcommand codes */
35#define SPOTLIGHT_CMD_OPEN 1
36#define SPOTLIGHT_CMD_FLAGS 2
37#define SPOTLIGHT_CMD_RPC 3
38#define SPOTLIGHT_CMD_OPEN2 4
39
40/* Can be ored and used as flags */
41#define SL_ENC_LITTLE_ENDIAN 1
42#define SL_ENC_BIG_ENDIAN 2
43#define SL_ENC_UTF_16 4
44
45 typedef DALLOC_CTX sl_array_t;
46 typedef DALLOC_CTX sl_dict_t;
47 typedef DALLOC_CTX sl_filemeta_t;
48 typedef int sl_nil_t;
49 typedef bool sl_bool_t;
50 typedef struct timeval sl_time_t;
51 typedef struct {
52 char sl_uuid[16];
53} sl_uuid_t;
54 typedef struct {
55 uint16_t ca_unkn1;
56 uint32_t ca_context;
57 DALLOC_CTX *ca_cnids;
58} sl_cnids_t;
59
60/******************************************************************************
61 * Some helper stuff dealing with queries
62 ******************************************************************************/
63
65 typedef enum {
66 SLQ_STATE_NEW,
67 SLQ_STATE_RUNNING,
68 SLQ_STATE_RESULTS,
69 SLQ_STATE_FULL,
70 SLQ_STATE_DONE,
71 SLQ_STATE_CANCEL_PENDING,
72 SLQ_STATE_CANCELLED,
73 SLQ_STATE_ERROR
74} slq_state_t;
75
77 typedef enum {
78 SL_INDEX_FILE_MODIFY,
79 SL_INDEX_FILE_DELETE,
80 SL_INDEX_DIR_DELETE,
81 SL_INDEX_FILE_CREATE,
82 SL_INDEX_DIR_CREATE,
83 SL_INDEX_FILE_MOVE,
84 SL_INDEX_DIR_MOVE
85} sl_index_event_t;
86
88 struct sl_rslts {
89 int num_results;
90 sl_cnids_t *cnids;
91 sl_array_t *fm_array;
92};
93
95 typedef struct _slq_t {
96 struct list_head slq_list;
97 slq_state_t slq_state;
98 AFPObj *slq_obj;
99 const struct vol *slq_vol;
100 char *slq_scope;
101 time_t slq_time;
102 uint64_t slq_ctx1;
103 uint64_t slq_ctx2;
104 sl_array_t *slq_reqinfo;
105 const char *slq_qstring;
106 uint64_t *slq_cnids;
107 size_t slq_cnids_num;
108 void *slq_backend_private;
109 bool slq_allow_expr;
110 uint64_t slq_result_limit;
111 struct sl_rslts *query_results;
112} slq_t;
113
114/******************************************************************************
115 * Pluggable search backend vtable
116 ******************************************************************************/
117
118 typedef struct sl_backend_ops {
119 const char *sbo_name;
120
121 /* Called once globally when the first volume using this backend is opened. */
122 int (*sbo_init)(AFPObj *obj);
123
124 /* Called on afpd shutdown. */
125 void (*sbo_close)(AFPObj *obj);
126
127 /* Translate slq->slq_qstring into results.
128 * May be async (localsearch) or synchronous (cnid).
129 * On return slq_state must be SLQ_STATE_RUNNING or SLQ_STATE_DONE. */
130 int (*sbo_open_query)(slq_t *slq);
131
132 /* Fetch the next batch of results into slq->query_results.
133 * For async backends: pumps the event loop.
134 * For sync backends: no-op after sbo_open_query() already set SLQ_STATE_DONE. */
135 int (*sbo_fetch_results)(slq_t *slq);
136
137 /* Cancel and clean up query state. */
138 void (*sbo_close_query)(slq_t *slq);
139
140 /* Optional incremental index update hook. */
141 int (*sbo_index_event)(const AFPObj *obj,
142 const struct vol *vol,
143 sl_index_event_t event,
144 const char *path,
145 const char *oldpath);
146} sl_backend_ops;
147
148/******************************************************************************
149 * Function declarations
150 ******************************************************************************/
151
152extern int afp_spotlight_rpc(AFPObj *obj, char *ibuf, size_t ibuflen _U_,
153 char *rbuf, size_t *rbuflen);
154extern int sl_index_event(const AFPObj *obj,
155 const struct vol *vol,
156 sl_index_event_t event,
157 const char *path,
158 const char *oldpath);
159extern int sl_pack(DALLOC_CTX *query, char *buf);
160extern int sl_unpack(DALLOC_CTX *query, const char *buf);
161extern int sl_unpack_len(DALLOC_CTX *query, const char *buf, size_t buf_len);
162extern void configure_spotlight_attributes(const char *attributes);
163
164#endif /* SPOTLIGHT_H */
rbuflen
static size_t rbuflen
Definition afpfunc_helpers.c:45
rbuf
static char rbuf[rbufsize]
Definition afpfunc_helpers.c:44
buf
static char buf[MAXPATHLEN+1]
Definition afppasswd.c:113
config.h
dalloc.h
globals.h
volume.h
obj
static AFPObj obj
Definition netatalk.c:69
configure_spotlight_attributes
void configure_spotlight_attributes(const char *attributes)
Definition sparql_map.c:109
sl_bool_t
bool sl_bool_t
Definition spotlight.h:49
sl_unpack_len
int sl_unpack_len(DALLOC_CTX *query, const char *buf, size_t buf_len)
Definition spotlight_marshalling.c:1195
sl_pack
int sl_pack(DALLOC_CTX *query, char *buf)
Definition spotlight_marshalling.c:1091
sl_array_t
DALLOC_CTX sl_array_t
Definition spotlight.h:45
sl_nil_t
int sl_nil_t
Definition spotlight.h:48
sl_time_t
struct timeval sl_time_t
Definition spotlight.h:50
sl_dict_t
DALLOC_CTX sl_dict_t
Definition spotlight.h:46
sl_index_event
int sl_index_event(const AFPObj *obj, const struct vol *vol, sl_index_event_t event, const char *path, const char *oldpath)
Definition spotlight.c:92
slq_t
struct _slq_t slq_t
sl_unpack
int sl_unpack(DALLOC_CTX *query, const char *buf)
Definition spotlight_marshalling.c:1190
sl_index_event_t
sl_index_event_t
Definition spotlight.h:77
SL_INDEX_DIR_MOVE
@ SL_INDEX_DIR_MOVE
Definition spotlight.h:84
SL_INDEX_FILE_MOVE
@ SL_INDEX_FILE_MOVE
Definition spotlight.h:83
SL_INDEX_FILE_CREATE
@ SL_INDEX_FILE_CREATE
Definition spotlight.h:81
SL_INDEX_FILE_DELETE
@ SL_INDEX_FILE_DELETE
Definition spotlight.h:79
SL_INDEX_DIR_CREATE
@ SL_INDEX_DIR_CREATE
Definition spotlight.h:82
SL_INDEX_DIR_DELETE
@ SL_INDEX_DIR_DELETE
Definition spotlight.h:80
SL_INDEX_FILE_MODIFY
@ SL_INDEX_FILE_MODIFY
Definition spotlight.h:78
sl_filemeta_t
DALLOC_CTX sl_filemeta_t
Definition spotlight.h:47
afp_spotlight_rpc
int afp_spotlight_rpc(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
Definition spotlight.c:1330
slq_state_t
slq_state_t
Definition spotlight.h:65
SLQ_STATE_NEW
@ SLQ_STATE_NEW
Definition spotlight.h:66
SLQ_STATE_RUNNING
@ SLQ_STATE_RUNNING
Definition spotlight.h:67
SLQ_STATE_CANCELLED
@ SLQ_STATE_CANCELLED
Definition spotlight.h:72
SLQ_STATE_DONE
@ SLQ_STATE_DONE
Definition spotlight.h:70
SLQ_STATE_CANCEL_PENDING
@ SLQ_STATE_CANCEL_PENDING
Definition spotlight.h:71
SLQ_STATE_RESULTS
@ SLQ_STATE_RESULTS
Definition spotlight.h:68
SLQ_STATE_FULL
@ SLQ_STATE_FULL
Definition spotlight.h:69
SLQ_STATE_ERROR
@ SLQ_STATE_ERROR
Definition spotlight.h:73
AFPObj
Definition globals.h:166
DALLOC_CTX
Definition dalloc.h:25
_slq_t
Definition spotlight.h:95
_slq_t::slq_ctx1
uint64_t slq_ctx1
Definition spotlight.h:102
_slq_t::slq_obj
AFPObj * slq_obj
Definition spotlight.h:98
_slq_t::slq_reqinfo
sl_array_t * slq_reqinfo
Definition spotlight.h:104
_slq_t::slq_allow_expr
bool slq_allow_expr
Definition spotlight.h:109
_slq_t::slq_cnids
uint64_t * slq_cnids
Definition spotlight.h:106
_slq_t::slq_vol
const struct vol * slq_vol
Definition spotlight.h:99
_slq_t::slq_scope
char * slq_scope
Definition spotlight.h:100
_slq_t::query_results
struct sl_rslts * query_results
Definition spotlight.h:111
_slq_t::slq_state
slq_state_t slq_state
Definition spotlight.h:97
_slq_t::slq_time
time_t slq_time
Definition spotlight.h:101
_slq_t::slq_ctx2
uint64_t slq_ctx2
Definition spotlight.h:103
_slq_t::slq_backend_private
void * slq_backend_private
Definition spotlight.h:108
_slq_t::slq_qstring
const char * slq_qstring
Definition spotlight.h:105
_slq_t::slq_cnids_num
size_t slq_cnids_num
Definition spotlight.h:107
_slq_t::slq_list
struct list_head slq_list
Definition spotlight.h:96
_slq_t::slq_result_limit
uint64_t slq_result_limit
Definition spotlight.h:110
list_head
Definition include/atalk/list.h:18
path
Definition include/atalk/directory.h:123
sl_backend_ops
Definition spotlight.h:118
sl_backend_ops::sbo_open_query
int(* sbo_open_query)(slq_t *slq)
Definition spotlight.h:130
sl_backend_ops::sbo_close_query
void(* sbo_close_query)(slq_t *slq)
Definition spotlight.h:138
sl_backend_ops::sbo_close
void(* sbo_close)(AFPObj *obj)
Definition spotlight.h:125
sl_backend_ops::sbo_fetch_results
int(* sbo_fetch_results)(slq_t *slq)
Definition spotlight.h:135
sl_backend_ops::sbo_name
const char * sbo_name
Definition spotlight.h:119
sl_backend_ops::sbo_index_event
int(* sbo_index_event)(const AFPObj *obj, const struct vol *vol, sl_index_event_t event, const char *path, const char *oldpath)
Definition spotlight.h:141
sl_backend_ops::sbo_init
int(* sbo_init)(AFPObj *obj)
Definition spotlight.h:122
sl_cnids_t
Definition spotlight.h:54
sl_cnids_t::ca_cnids
DALLOC_CTX * ca_cnids
Definition spotlight.h:57
sl_cnids_t::ca_context
uint32_t ca_context
Definition spotlight.h:56
sl_cnids_t::ca_unkn1
uint16_t ca_unkn1
Definition spotlight.h:55
sl_rslts
Definition spotlight.h:88
sl_rslts::num_results
int num_results
Definition spotlight.h:89
sl_rslts::cnids
sl_cnids_t * cnids
Definition spotlight.h:90
sl_rslts::fm_array
sl_array_t * fm_array
Definition spotlight.h:91
sl_uuid_t
Definition spotlight.h:51
sl_uuid_t::sl_uuid
char sl_uuid[16]
Definition spotlight.h:52
vol
Definition include/atalk/volume.h:33