From: Ralph Boehme Date: Tue, 5 Aug 2014 11:14:21 +0000 (+0200) Subject: Spotlight: use async Tracker SPARQL API X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netatalk.git;a=commitdiff_plain;h=071887b8a84c7111477d9e1fcc8be9ea2b0c47e5 Spotlight: use async Tracker SPARQL API Signed-off-by: Ralph Boehme --- diff --git a/NEWS b/NEWS index aeae4c16..f332611f 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,7 @@ Changes in 3.1.4 "fce ignore names" and "fce notify script" * UPD: afpd: check for modified included config file, FR #95. * UPD: libatalk: logger: remove flood protection and allocate messages +* UPD: Spotlight: use async Tracker SPARQL API Changes in 3.1.3 ================ diff --git a/etc/Makefile.am b/etc/Makefile.am index 6877a761..959b864d 100644 --- a/etc/Makefile.am +++ b/etc/Makefile.am @@ -1,3 +1,3 @@ # Makefile.am for etc/ -SUBDIRS = afpd cnid_dbd netatalk spotlight uams +SUBDIRS = spotlight afpd cnid_dbd netatalk uams diff --git a/etc/afpd/Makefile.am b/etc/afpd/Makefile.am index 77ed9d64..724cb52f 100644 --- a/etc/afpd/Makefile.am +++ b/etc/afpd/Makefile.am @@ -7,7 +7,6 @@ CLEANFILES = DISTCLEANFILES = sbin_PROGRAMS = afpd -noinst_PROGRAMS = hash spot afpd_SOURCES = \ afp_avahi.c \ @@ -39,7 +38,6 @@ afpd_SOURCES = \ nfsquota.c \ ofork.c \ quota.c \ - spotlight.c \ spotlight_marshalling.c \ status.c \ switch.c \ @@ -64,6 +62,12 @@ afpd_CFLAGS = \ -D_PATH_CONFDIR=\"$(pkgconfdir)/\" \ -D_PATH_STATEDIR='"$(localstatedir)/netatalk/"' +if HAVE_TRACKER +afpd_SOURCES += spotlight.c +afpd_LDADD += $(top_builddir)/etc/spotlight/libspotlight.la +afpd_CFLAGS += @TRACKER_CFLAGS@ +endif + if HAVE_ACLS afpd_SOURCES += acls.c endif @@ -98,10 +102,3 @@ noinst_HEADERS = auth.h afp_config.h desktop.h directory.h fce_api_internal.h fi filedir.h fork.h icon.h mangle.h misc.h status.h switch.h \ uam_auth.h uid.h unix.h volume.h hash.h acls.h acl_mappings.h extattrs.h \ dircache.h afp_zeroconf.h afp_avahi.h afp_mdns.h afpstats.h afpstats_obj.h - -hash_SOURCES = hash.c -hash_CFLAGS = -DKAZLIB_TEST_MAIN -I$(top_srcdir)/include - -spot_SOURCES = spotlight.c spotlight_marshalling.c -spot_CFLAGS = -DSPOT_TEST_MAIN -spot_LDADD = $(top_builddir)/libatalk/libatalk.la diff --git a/etc/afpd/afp_dsi.c b/etc/afpd/afp_dsi.c index 124db47a..98404ce2 100644 --- a/etc/afpd/afp_dsi.c +++ b/etc/afpd/afp_dsi.c @@ -493,9 +493,12 @@ void afp_over_dsi(AFPObj *obj) int flag = 1; setsockopt(dsi->socket, SOL_TCP, TCP_NODELAY, &flag, sizeof(flag)); +#ifdef HAVE_TRACKER /* Initialize Spotlight */ - if ((obj->options.flags & OPTION_SPOTLIGHT) && (obj->options.slmod_path)) - sl_mod_load(obj); + if (obj->options.flags & OPTION_SPOTLIGHT) { + spotlight_init(obj); + } +#endif ipc_child_state(obj, DSI_RUNNING); diff --git a/etc/afpd/auth.c b/etc/afpd/auth.c index 7a7c41e5..dc4dd8bc 100644 --- a/etc/afpd/auth.c +++ b/etc/afpd/auth.c @@ -187,7 +187,9 @@ static int set_auth_switch(const AFPObj *obj, int expired) case 31: uam_afpserver_action(AFP_SYNCDIR, UAM_AFPSERVER_POSTAUTH, afp_syncdir, NULL); uam_afpserver_action(AFP_SYNCFORK, UAM_AFPSERVER_POSTAUTH, afp_syncfork, NULL); +#ifdef HAVE_TRACKER uam_afpserver_action(AFP_SPOTLIGHT_PRIVATE, UAM_AFPSERVER_POSTAUTH, afp_spotlight_rpc, NULL); +#endif uam_afpserver_action(AFP_ENUMERATE_EXT2, UAM_AFPSERVER_POSTAUTH, afp_enumerate_ext2, NULL); case 30: diff --git a/etc/afpd/file.c b/etc/afpd/file.c index 881640da..6d5cb4fc 100644 --- a/etc/afpd/file.c +++ b/etc/afpd/file.c @@ -765,7 +765,6 @@ createfile_iderr: ad_flush(&ad); ad_close(&ad, ADFLAGS_DF|ADFLAGS_HF ); fce_register(obj, FCE_FILE_CREATE, fullpathname(upath), NULL); - sl_index_file(path); curdir->d_offcnt++; setvoltime(obj, vol ); diff --git a/etc/afpd/spotlight.c b/etc/afpd/spotlight.c index 56546244..621ef383 100644 --- a/etc/afpd/spotlight.c +++ b/etc/afpd/spotlight.c @@ -1,5 +1,5 @@ /* - Copyright (c) 2012 Frank Lahm + Copyright (c) 2012-2014 Ralph Boehme This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -40,152 +40,659 @@ #include #include "directory.h" +#include "etc/spotlight/sparql_parser.h" -static TALLOC_CTX *sl_ctx; -static void *sl_module; -static struct sl_module_export *sl_module_export; - -/* Helper functions and stuff */ -static const char *neststrings[] = { - "", - "\t", - "\t\t", - "\t\t\t", - "\t\t\t\t", - "\t\t\t\t\t", - "\t\t\t\t\t\t", -}; - -static int dd_dump(DALLOC_CTX *dd, int nestinglevel) +#define MAX_SL_RESULTS 20 + +static char *tracker_to_unix_path(TALLOC_CTX *mem_ctx, const char *uri); +static int cnid_comp_fn(const void *p1, const void *p2); +static bool create_result_handle(slq_t *slq); +static bool add_filemeta(sl_array_t *reqinfo, + sl_array_t *fm_array, + const char *path, + const struct stat *sp); + +/************************************************ + * Misc utility functions + ************************************************/ + +static char *tab_level(TALLOC_CTX *mem_ctx, int level) { - const char *type; + int i; + char *string = talloc_array(mem_ctx, char, level + 1); + + for (i = 0; i < level; i++) { + string[i] = '\t'; + } - LOG(log_debug, logtype_sl, "%s%s(#%d): {", - neststrings[nestinglevel], talloc_get_name(dd), talloc_array_length(dd->dd_talloc_array)); + string[i] = '\0'; + return string; +} - for (int n = 0; n < talloc_array_length(dd->dd_talloc_array); n++) { +static char *dd_dump(DALLOC_CTX *dd, int nestinglevel) +{ + const char *type; + int n; + uint64_t i; + sl_bool_t bl; + sl_time_t t; + struct tm *tm; + char datestring[256]; + sl_cnids_t cnids; + char *logstring, *nested_logstring; + char *tab_string1, *tab_string2; + + tab_string1 = tab_level(dd, nestinglevel); + tab_string2 = tab_level(dd, nestinglevel + 1); + if (tab_string1 == NULL || tab_string2 == NULL) { + return NULL; + } - type = talloc_get_name(dd->dd_talloc_array[n]); + logstring = talloc_asprintf(dd, + "%s%s(#%lu): {\n", + tab_string1, + talloc_get_name(dd), + talloc_array_length(dd->dd_talloc_array)); - if (STRCMP(type, ==, "DALLOC_CTX") - || STRCMP(type, ==, "sl_array_t") - || STRCMP(type, ==, "sl_filemeta_t") - || STRCMP(type, ==, "sl_dict_t")) { - dd_dump(dd->dd_talloc_array[n], nestinglevel + 1); - } else if (STRCMP(type, ==, "uint64_t")) { - uint64_t i; + for (n = 0; n < talloc_array_length(dd->dd_talloc_array); n++) { + type = talloc_get_name(dd->dd_talloc_array[n]); + if (strequal(type, "DALLOC_CTX") + || strequal(type, "sl_array_t") + || strequal(type, "sl_filemeta_t") + || strequal(type, "sl_dict_t")) { + nested_logstring = dd_dump(dd->dd_talloc_array[n], + nestinglevel + 1); + if (!nested_logstring) { + return NULL; + } + logstring = talloc_strdup_append(logstring, + nested_logstring); + if (!logstring) { + return NULL; + } + } else if (strequal(type, "uint64_t")) { memcpy(&i, dd->dd_talloc_array[n], sizeof(uint64_t)); - LOG(log_debug, logtype_sl, "%suint64_t: 0x%04x", neststrings[nestinglevel + 1], i); - } else if (STRCMP(type, ==, "char *")) { - LOG(log_debug, logtype_sl, "%sstring: %s", neststrings[nestinglevel + 1], (char *)dd->dd_talloc_array[n]); - } else if (STRCMP(type, ==, "sl_bool_t")) { - sl_bool_t bl; + logstring = talloc_asprintf_append( + logstring, + "%suint64_t: 0x%04" PRIx64 "\n", + tab_string2, i); + if (!logstring) { + return NULL; + } + } else if (strequal(type, "char *")) { + logstring = talloc_asprintf_append( + logstring, + "%sstring: %s\n", + tab_string2, + (char *)dd->dd_talloc_array[n]); + if (!logstring) { + return NULL; + } + } else if (strequal(type, "smb_ucs2_t *")) { + logstring = talloc_asprintf_append( + logstring, + "%sUTF16-string: %s\n", + tab_string2, + (char *)dd->dd_talloc_array[n]); + if (!logstring) { + return NULL; + } + } else if (strequal(type, "sl_bool_t")) { memcpy(&bl, dd->dd_talloc_array[n], sizeof(sl_bool_t)); - LOG(log_debug, logtype_sl, "%sbool: %s", neststrings[nestinglevel + 1], bl ? "true" : "false"); - } else if (STRCMP(type, ==, "sl_nil_t")) { - LOG(log_debug, logtype_sl, "%snil", neststrings[nestinglevel + 1]); - } else if (STRCMP(type, ==, "sl_time_t")) { - sl_time_t t; - struct tm *tm; - char datestring[256]; + logstring = talloc_asprintf_append( + logstring, + "%sbool: %s\n", + tab_string2, + bl ? "true" : "false"); + if (!logstring) { + return NULL; + } + } else if (strequal(type, "sl_nil_t")) { + logstring = talloc_asprintf_append( + logstring, + "%snil\n", + tab_string2); + if (!logstring) { + return NULL; + } + } else if (strequal(type, "sl_time_t")) { memcpy(&t, dd->dd_talloc_array[n], sizeof(sl_time_t)); tm = localtime(&t.tv_sec); - strftime(datestring, sizeof(datestring), "%Y-%m-%d %H:%M:%S", tm); - LOG(log_debug, logtype_sl, "%ssl_time_t: %s.%06d", neststrings[nestinglevel + 1], datestring, t.tv_usec); - } else if (STRCMP(type, ==, "sl_cnids_t")) { - sl_cnids_t cnids; + strftime(datestring, + sizeof(datestring), + "%Y-%m-%d %H:%M:%S", tm); + logstring = talloc_asprintf_append( + logstring, + "%ssl_time_t: %s.%06lu\n", + tab_string2, + datestring, + (unsigned long)t.tv_usec); + if (!logstring) { + return NULL; + } + } else if (strequal(type, "sl_cnids_t")) { memcpy(&cnids, dd->dd_talloc_array[n], sizeof(sl_cnids_t)); - LOG(log_debug, logtype_sl, "%sCNIDs: unkn1: 0x%" PRIx16 ", unkn2: 0x%" PRIx32, - neststrings[nestinglevel + 1], cnids.ca_unkn1, cnids.ca_context); - if (cnids.ca_cnids) - dd_dump(cnids.ca_cnids, nestinglevel + 2); + logstring = talloc_asprintf_append( + logstring, + "%sCNIDs: unkn1: 0x%" PRIx16 ", unkn2: 0x%" PRIx32 "\n", + tab_string2, + cnids.ca_unkn1, + cnids.ca_context); + if (!logstring) { + return NULL; + } + if (cnids.ca_cnids) { + nested_logstring = dd_dump( + cnids.ca_cnids, + nestinglevel + 2); + if (!nested_logstring) { + return NULL; + } + logstring = talloc_strdup_append(logstring, + nested_logstring); + if (!logstring) { + return NULL; + } + } + } else { + logstring = talloc_asprintf_append( + logstring, + "%stype: %s\n", + tab_string2, + type); + if (!logstring) { + return NULL; + } + } + } + logstring = talloc_asprintf_append(logstring, + "%s}\n", + tab_string1); + if (!logstring) { + return NULL; + } + return logstring; +} + +static int cnid_comp_fn(const void *p1, const void *p2) +{ + const uint64_t *cnid1 = p1, *cnid2 = p2; + if (*cnid1 == *cnid2) { + return 0; + } + if (*cnid1 < *cnid2) { + return -1; + } + return 1; +} + +static int sl_createCNIDArray(slq_t *slq, const DALLOC_CTX *p) +{ + EC_INIT; + uint64_t *cnids = NULL; + + EC_NULL( cnids = talloc_array(slq, uint64_t, talloc_array_length(p)) ); + + for (int i = 0; i < talloc_array_length(p); i++) { + memcpy(&cnids[i], p->dd_talloc_array[i], sizeof(uint64_t)); + } + qsort(cnids, talloc_array_length(p), sizeof(uint64_t), cnid_comp_fn); + + slq->slq_cnids = cnids; + slq->slq_cnids_num = talloc_array_length(p); + +EC_CLEANUP: + if (ret != 0) { + if (cnids) + talloc_free(cnids); + } + EC_EXIT; +} + +static char *tracker_to_unix_path(TALLOC_CTX *mem_ctx, const char *uri) +{ + GFile *f; + char *path; + char *talloc_path = NULL; + + f = g_file_new_for_uri(uri); + if (!f) { + return NULL; + } + + path = g_file_get_path(f); + g_object_unref(f); + + if (!path) { + return NULL; + } + + talloc_path = talloc_strdup(mem_ctx, path); + g_free(path); + + return talloc_path; +} + +/** + * Add requested metadata for a query result element + * + * This could be rewritten to something more sophisticated like + * querying metadata from Tracker. + * + * If path or sp is NULL, simply add nil values for all attributes. + **/ +static bool add_filemeta(sl_array_t *reqinfo, + sl_array_t *fm_array, + const char *path, + const struct stat *sp) +{ + sl_array_t *meta; + sl_nil_t nil; + int i, metacount; + uint64_t uint64var; + sl_time_t sl_time; + char *p, *name; + + metacount = talloc_array_length(reqinfo->dd_talloc_array); + if (metacount == 0 || path == NULL || sp == NULL) { + dalloc_add_copy(fm_array, &nil, sl_nil_t); + return true; + } + + meta = talloc_zero(fm_array, sl_array_t); + + for (i = 0; i < metacount; i++) { + if (strequal(reqinfo->dd_talloc_array[i], "kMDItemDisplayName") + || strequal(reqinfo->dd_talloc_array[i], "kMDItemFSName")) { + if ((p = strrchr(path, '/'))) { + name = dalloc_strdup(meta, p + 1); + dalloc_add(meta, name, "char *"); + } + } else if (strequal(reqinfo->dd_talloc_array[i], + "kMDItemPath")) { + name = dalloc_strdup(meta, path); + dalloc_add(meta, name, "char *"); + } else if (strequal(reqinfo->dd_talloc_array[i], + "kMDItemFSSize")) { + uint64var = sp->st_size; + dalloc_add_copy(meta, &uint64var, uint64_t); + } else if (strequal(reqinfo->dd_talloc_array[i], + "kMDItemFSOwnerUserID")) { + uint64var = sp->st_uid; + dalloc_add_copy(meta, &uint64var, uint64_t); + } else if (strequal(reqinfo->dd_talloc_array[i], + "kMDItemFSOwnerGroupID")) { + uint64var = sp->st_gid; + dalloc_add_copy(meta, &uint64var, uint64_t); + } else if (strequal(reqinfo->dd_talloc_array[i], + "kMDItemFSContentChangeDate")) { + sl_time.tv_sec = sp->st_mtime; + dalloc_add_copy(meta, &sl_time, sl_time_t); } else { - LOG(log_debug, logtype_sl, "%stype: %s", neststrings[nestinglevel + 1], type); + dalloc_add_copy(meta, &nil, sl_nil_t); } } - LOG(log_debug, logtype_sl, "%s}", neststrings[nestinglevel]); + + dalloc_add(fm_array, meta, sl_array_t); + return true; +} + +/** + * Allocate result handle used in the async Tracker cursor result + * handler for storing results + **/ +static bool create_result_handle(slq_t *slq) +{ + sl_nil_t nil = 0; + struct sl_rslts *query_results; + + if (slq->query_results) { + LOG(log_error, logtype_sl,"unexpected existing result handle"); + return false; + } + + query_results = talloc_zero(slq, struct sl_rslts); + + /* CNIDs */ + query_results->cnids = talloc_zero(query_results, sl_cnids_t); + if (query_results->cnids == NULL) { + return false; + } + query_results->cnids->ca_cnids = talloc_zero(query_results->cnids, + DALLOC_CTX); + if (query_results->cnids->ca_cnids == NULL) { + return false; + } + + query_results->cnids->ca_unkn1 = 0xadd; + query_results->cnids->ca_context = slq->slq_ctx2; + + /* FileMeta */ + query_results->fm_array = talloc_zero(query_results, sl_array_t); + if (query_results->fm_array == NULL) { + return false; + } + + /* For some reason the list of results always starts with a nil entry */ + dalloc_add_copy(query_results->fm_array, &nil, sl_nil_t); + + slq->query_results = query_results; + return true; +} + +static bool add_results(sl_array_t *array, slq_t *slq) +{ + sl_filemeta_t *fm; + uint64_t status = 0; + + /* FileMeta */ + fm = talloc_zero(array, sl_filemeta_t); + if (!fm) { + return false; + } + + dalloc_add_copy(array, &status, uint64_t); + dalloc_add(array, slq->query_results->cnids, sl_cnids_t); + if (slq->query_results->num_results > 0) { + dalloc_add(fm, slq->query_results->fm_array, sl_array_t); + } + dalloc_add(array, fm, sl_filemeta_t); + + /* This ensure the results get clean up after been sent to the client */ + talloc_steal(array, slq->query_results); + slq->query_results = NULL; + + if (!create_result_handle(slq)) { + LOG(log_error, logtype_sl, "couldn't add result handle"); + slq->slq_state = SLQ_STATE_ERROR; + return false; + } + + return true; } -#ifndef SPOT_TEST_MAIN -/************************************************************************************************** +/****************************************************************************** * Spotlight queries - **************************************************************************************************/ + ******************************************************************************/ static ATALK_LIST_HEAD(sl_queries); +static ATALK_LIST_HEAD(sl_cancelled_queries); -/*! +/** * Add a query to the list of active queries - */ -static int slq_add(slq_t *slq) + **/ +static void slq_add(slq_t *slq) { list_add(&(slq->slq_list), &sl_queries); - return 0; } -static int slq_remove(slq_t *slq) +/** + * Add a query to the list of active queries + **/ +static void slq_cancelled_add(slq_t *slq) +{ + list_add(&(slq->slq_list), &sl_cancelled_queries); +} + +/** + * Remove a query from the active list + **/ +static void slq_remove(slq_t *slq) { - EC_INIT; struct list_head *p; slq_t *q = NULL; list_for_each(p, &sl_queries) { q = list_entry(p, slq_t, slq_list); - if ((q->slq_ctx1 == slq->slq_ctx1) && (q->slq_ctx2 == slq->slq_ctx2)) { + if ((q->slq_ctx1 == slq->slq_ctx1) && (q->slq_ctx2 == slq->slq_ctx2)) { list_del(p); break; } - q = NULL; - } - - if (q == NULL) { - /* The SL query 'slq' was not found in the list, this is not supposed to happen! */ - LOG(log_warning, logtype_sl, "slq_remove: slq not in active query list"); } -EC_CLEANUP: - EC_EXIT; + return; } static slq_t *slq_for_ctx(uint64_t ctx1, uint64_t ctx2) { - EC_INIT; slq_t *q = NULL; struct list_head *p; list_for_each(p, &sl_queries) { q = list_entry(p, slq_t, slq_list); - - LOG(log_debug, logtype_sl, "slq_for_ctx(ctx1: 0x%" PRIx64 ", ctx2: 0x%" PRIx64 - "): active: ctx1: 0x%" PRIx64 ", ctx2: 0x%" PRIx64, - ctx1, ctx2, q->slq_ctx1, q->slq_ctx2); - - if ((q->slq_ctx1 == ctx1) && (q->slq_ctx2 == ctx2)) { + if ((q->slq_ctx1 == ctx1) && (q->slq_ctx2 == ctx2)) { break; } q = NULL; } -EC_CLEANUP: - if (ret != 0) - q = NULL; return q; } -/* Error handling for queries */ -static void slq_error(slq_t *slq) +/** + * Remove a query from the active queue and free it + **/ +static void slq_destroy(slq_t *slq) { - if (!slq) + if (slq == NULL) { return; - sl_module_export->sl_mod_error(slq); + } slq_remove(slq); talloc_free(slq); } -/************************************************************************************************** +/** + * Cancel a query + **/ +static void slq_cancel(slq_t *slq) +{ + g_cancellable_cancel(slq->cancellable); + slq->slq_state = SLQ_STATE_CANCEL_PENDING; + slq_remove(slq); + slq_cancelled_add(slq); +} + +/** + * talloc destructor cb + **/ +static int slq_free_cb(slq_t *slq) +{ + if (slq->tracker_cursor) { + g_object_unref(slq->tracker_cursor); + } + if (slq->cancellable) { + g_object_unref(slq->cancellable); + } + return 0; +} + +/** + * Free all cancelled queries + **/ +static void slq_cancelled_cleanup(void) +{ + struct list_head *p; + slq_t *q = NULL; + + list_for_each(p, &sl_cancelled_queries) { + q = list_entry(p, slq_t, slq_list); + list_del(p); + if (q->slq_state != SLQ_STATE_CANCELLED) { + LOG(log_error, logtype_sl, "unexpected state: %d", q->slq_state); + } + talloc_free(q); + } + + return; +} + +/************************************************ + * Tracker async callbacks + ************************************************/ + +static void tracker_con_cb(GObject *object, + GAsyncResult *res, + gpointer user_data) +{ + struct sl_ctx *sl_ctx = user_data; + GError *error = NULL; + + sl_ctx->tracker_con = tracker_sparql_connection_get_finish(res, + &error); + if (error) { + LOG(log_error, logtype_sl, "Could not connect to Tracker: %s", + error->message); + sl_ctx->tracker_con = NULL; + g_error_free(error); + return; + } + + LOG(log_info, logtype_sl, "connected to Tracker"); +} + +static void tracker_cursor_cb(GObject *object, + GAsyncResult *res, + gpointer user_data) +{ + GError *error = NULL; + slq_t *slq = user_data; + gboolean more_results; + const gchar *uri; + char *path; + int result; + struct stat sb; + uint64_t uint64var; + bool ok; + cnid_t did, id; + + if (g_cancellable_is_cancelled(slq->cancellable)) { + slq->slq_state = SLQ_STATE_CANCELLED; + return; + } + + more_results = tracker_sparql_cursor_next_finish(slq->tracker_cursor, + res, + &error); + + if (error) { + LOG(log_error, logtype_sl, "Tracker cursor: %s", error->message); + g_error_free(error); + slq->slq_state = SLQ_STATE_ERROR; + return; + } + + if (!more_results) { + slq->slq_state = SLQ_STATE_DONE; + return; + } + + uri = tracker_sparql_cursor_get_string(slq->tracker_cursor, 0, NULL); + if (uri == NULL) { + /* + * Not sure how this could happen if + * tracker_sparql_cursor_next_finish() returns true, but I've + * seen it. + */ + LOG(log_debug, logtype_sl, "no URI for result"); + goto exit; + } + + path = tracker_to_unix_path(slq->query_results, uri); + if (path == NULL) { + LOG(log_error, logtype_sl, "error converting Tracker URI: %s", uri); + slq->slq_state = SLQ_STATE_ERROR; + return; + } + + result = access(path, R_OK); + if (result != 0) { + goto exit; + } + + id = cnid_for_path(slq->slq_vol->v_cdb, slq->slq_vol->v_path, path, &did); + if (id == CNID_INVALID) { + LOG(log_error, logtype_sl, "cnid_for_path error: %s", path); + goto exit; + } + uint64var = ntohl(id); + + if (slq->slq_cnids) { + ok = bsearch(&uint64var, slq->slq_cnids, slq->slq_cnids_num, + sizeof(uint64_t), cnid_comp_fn); + if (!ok) { + goto exit; + } + } + + dalloc_add_copy(slq->query_results->cnids->ca_cnids, + &uint64var, uint64_t); + ok = add_filemeta(slq->slq_reqinfo, slq->query_results->fm_array, + path, &sb); + if (!ok) { + LOG(log_error, logtype_sl, "add_filemeta error"); + slq->slq_state = SLQ_STATE_ERROR; + return; + } + + slq->query_results->num_results++; + +exit: + if (slq->query_results->num_results < MAX_SL_RESULTS) { + tracker_sparql_cursor_next_async(slq->tracker_cursor, + slq->cancellable, + tracker_cursor_cb, + slq); + } +} + +static void tracker_query_cb(GObject *object, + GAsyncResult *res, + gpointer user_data) +{ + bool ok; + GError *error = NULL; + slq_t *slq = user_data; + + if (g_cancellable_is_cancelled(slq->cancellable)) { + slq->slq_state = SLQ_STATE_CANCELLED; + return; + } + + slq->tracker_cursor = tracker_sparql_connection_query_finish( + TRACKER_SPARQL_CONNECTION(object), + res, + &error); + + if (error) { + slq->slq_state = SLQ_STATE_ERROR; + LOG(log_error, logtype_sl, "Tracker query error: %s", error->message); + g_error_free(error); + return; + } + + slq->slq_state = SLQ_STATE_RESULTS; + + ok = create_result_handle(slq); + if (!ok) { + LOG(log_error, logtype_sl, "create_result_handle error"); + slq->slq_state = SLQ_STATE_ERROR; + return; + } + + tracker_sparql_cursor_next_async(slq->tracker_cursor, + slq->slq_obj->sl_ctx->cancellable, + tracker_cursor_cb, + slq); +} + +/******************************************************************************* * Spotlight RPC functions - **************************************************************************************************/ + ******************************************************************************/ -static int sl_rpc_fetchPropertiesForContext(const AFPObj *obj, const DALLOC_CTX *query, DALLOC_CTX *reply, const struct vol *v) +static int sl_rpc_fetchPropertiesForContext(const AFPObj *obj, + const DALLOC_CTX *query, + DALLOC_CTX *reply, + const struct vol *v) { EC_INIT; @@ -194,9 +701,9 @@ static int sl_rpc_fetchPropertiesForContext(const AFPObj *obj, const DALLOC_CTX sl_array_t *array; sl_uuid_t uuid; - if (!v->v_uuid) - EC_FAIL_LOG("sl_rpc_fetchPropertiesForContext: missing UUID for volume: %s", v->v_localname); - + if (!v->v_uuid) { + EC_FAIL_LOG("missing UUID for volume: %s", v->v_localname); + } dict = talloc_zero(reply, sl_dict_t); /* key/val 1 */ @@ -236,39 +743,10 @@ EC_CLEANUP: EC_EXIT; } -static int cnid_comp_fn(const void *p1, const void *p2) -{ - const uint64_t *cnid1 = p1, *cnid2 = p2; - if (*cnid1 == *cnid2) - return 0; - if (*cnid1 < *cnid2) - return -1; - else - return 1; -} - -static int sl_createCNIDArray(slq_t *slq, const DALLOC_CTX *p) -{ - EC_INIT; - uint64_t *cnids = NULL; - - EC_NULL( cnids = talloc_array(slq, uint64_t, talloc_array_length(p)) ); - for (int i = 0; i < talloc_array_length(p); i++) - memcpy(&cnids[i], p->dd_talloc_array[i], sizeof(uint64_t)); - qsort(cnids, talloc_array_length(p), sizeof(uint64_t), cnid_comp_fn); - - slq->slq_cnids = cnids; - slq->slq_cnids_num = talloc_array_length(p); - -EC_CLEANUP: - if (ret != 0) { - if (cnids) - talloc_free(cnids); - } - EC_EXIT; -} - -static int sl_rpc_openQuery(AFPObj *obj, const DALLOC_CTX *query, DALLOC_CTX *reply, struct vol *v) +static int sl_rpc_openQuery(AFPObj *obj, + const DALLOC_CTX *query, + DALLOC_CTX *reply, + struct vol *v) { EC_INIT; char *sl_query; @@ -276,96 +754,187 @@ static int sl_rpc_openQuery(AFPObj *obj, const DALLOC_CTX *query, DALLOC_CTX *re DALLOC_CTX *reqinfo; sl_array_t *array; sl_cnids_t *cnids; - slq_t *slq = NULL; + slq_t *slq; + char slq_host[MAXPATHLEN + 1]; + uint16_t convflags = v->v_mtou_flags; + uint64_t result; + gchar *sparql_query; + GError *error = NULL; + + array = talloc_zero(reply, sl_array_t); + + if (obj->sl_ctx->tracker_con == NULL) { + EC_FAIL; + } /* Allocate and initialize query object */ - slq = talloc_zero(sl_ctx, slq_t); + slq = talloc_zero(obj->sl_ctx, slq_t); slq->slq_state = SLQ_STATE_NEW; slq->slq_obj = obj; slq->slq_vol = v; slq->slq_allow_expr = obj->options.flags & OPTION_SPOTLIGHT_EXPR ? true : false; slq->slq_result_limit = obj->options.sparql_limit; + slq->cancellable = g_cancellable_new(); + talloc_set_destructor(slq, slq_free_cb); - LOG(log_info, logtype_sl, "sl_rpc_openQuery: expr: %s, limit: %" PRIu64, + LOG(log_debug, logtype_sl, "Spotlight: expr: %s, limit: %" PRIu64, slq->slq_allow_expr ? "yes" : "no", slq->slq_result_limit); /* convert spotlight query charset to host charset */ - EC_NULL_LOG( sl_query = dalloc_value_for_key(query, "DALLOC_CTX", 0, "DALLOC_CTX", 1, "kMDQueryString") ); - char slq_host[MAXPATHLEN + 1]; - uint16_t convflags = v->v_mtou_flags; - size_t slq_maclen; - if (convert_charset(CH_UTF8_MAC, v->v_volcharset, v->v_maccharset, sl_query, strlen(sl_query), slq_host, MAXPATHLEN, &convflags) == -1) { - LOG(log_error, logtype_afpd, "sl_rpc_openQuery(\"%s\"): charset conversion failed", sl_query); + sl_query = dalloc_value_for_key(query, "DALLOC_CTX", 0, + "DALLOC_CTX", 1, + "kMDQueryString"); + if (sl_query == NULL) { + EC_FAIL; + } + ret = convert_charset(CH_UTF8_MAC, v->v_volcharset, v->v_maccharset, + sl_query, strlen(sl_query), slq_host, MAXPATHLEN, + &convflags); + if (ret == -1) { + LOG(log_error, logtype_sl, "charset conversion failed"); EC_FAIL; } slq->slq_qstring = talloc_strdup(slq, slq_host); - LOG(log_debug, logtype_sl, "sl_rpc_openQuery: %s", slq->slq_qstring); + LOG(log_debug, logtype_sl, "Spotlight query: \"%s\"", slq->slq_qstring); slq->slq_time = time(NULL); - EC_NULL_LOG( uint64 = dalloc_get(query, "DALLOC_CTX", 0, "DALLOC_CTX", 0, "uint64_t", 1) ); + uint64 = dalloc_get(query, "DALLOC_CTX", 0, "DALLOC_CTX", 0, "uint64_t", 1); + if (uint64 == NULL) { + EC_FAIL; + } slq->slq_ctx1 = *uint64; - EC_NULL_LOG( uint64 = dalloc_get(query, "DALLOC_CTX", 0, "DALLOC_CTX", 0, "uint64_t", 2) ); + + uint64 = dalloc_get(query, "DALLOC_CTX", 0, "DALLOC_CTX", 0, "uint64_t", 2); + if (uint64 == NULL) { + EC_FAIL; + } slq->slq_ctx2 = *uint64; - EC_NULL_LOG( reqinfo = dalloc_value_for_key(query, "DALLOC_CTX", 0, "DALLOC_CTX", 1, "kMDAttributeArray") ); + + reqinfo = dalloc_value_for_key(query, "DALLOC_CTX", 0, "DALLOC_CTX", 1, + "kMDAttributeArray"); + if (reqinfo == NULL) { + EC_FAIL; + } slq->slq_reqinfo = talloc_steal(slq, reqinfo); - if ((cnids = dalloc_value_for_key(query, "DALLOC_CTX", 0, "DALLOC_CTX", 1, "kMDQueryItemArray"))) { + + cnids = dalloc_value_for_key(query, "DALLOC_CTX", 0, "DALLOC_CTX", 1, + "kMDQueryItemArray"); + if (cnids) { EC_ZERO_LOG( sl_createCNIDArray(slq, cnids->ca_cnids) ); } - - LOG(log_maxdebug, logtype_sl, "sl_rpc_openQuery: requested attributes:"); - dd_dump(slq->slq_reqinfo, 0); - (void)slq_add(slq); - - /* Run the query */ - EC_ZERO( sl_module_export->sl_mod_start_search(slq) ); + ret = map_spotlight_to_sparql_query(slq, &sparql_query); + if (ret != 0) { + LOG(log_debug, logtype_sl, "mapping retured non-zero"); + EC_FAIL; + } + LOG(log_debug, logtype_sl, "SPARQL query: \"%s\"", sparql_query); + + tracker_sparql_connection_query_async(obj->sl_ctx->tracker_con, + sparql_query, + slq->cancellable, + tracker_query_cb, + slq); + if (error) { + LOG(log_error, logtype_sl, "Couldn't query the Tracker Store: '%s'", + error->message); + g_clear_error(&error); + EC_FAIL; + } - array = talloc_zero(reply, sl_array_t); - uint64_t sl_res = ret == 0 ? 0 : UINT64_MAX; - dalloc_add_copy(array, &sl_res, uint64_t); - dalloc_add(reply, array, sl_array_t); + slq->slq_state = SLQ_STATE_RUNNING; + slq_add(slq); EC_CLEANUP: if (ret != 0) { - slq_error(slq); + slq_destroy(slq); + result = UINT64_MAX; + ret = 0; + } else { + result = 0; } + + dalloc_add_copy(array, &result, uint64_t); + dalloc_add(reply, array, sl_array_t); EC_EXIT; } -static int sl_rpc_fetchQueryResultsForContext(const AFPObj *obj, const DALLOC_CTX *query, DALLOC_CTX *reply, const struct vol *v) +static int sl_rpc_fetchQueryResultsForContext(const AFPObj *obj, + const DALLOC_CTX *query, + DALLOC_CTX *reply, + const struct vol *v) { EC_INIT; slq_t *slq = NULL; - uint64_t *uint64, ctx1, ctx2; + uint64_t *uint64, ctx1, ctx2, status; + sl_array_t *array; + bool ok; + + array = talloc_zero(reply, sl_array_t); + if (array == NULL) { + return false; + } /* Context */ - EC_NULL_LOG (uint64 = dalloc_get(query, "DALLOC_CTX", 0, "DALLOC_CTX", 0, "uint64_t", 1) ); + uint64 = dalloc_get(query, "DALLOC_CTX", 0, "DALLOC_CTX", 0, "uint64_t", 1); + if (uint64 == NULL) { + EC_FAIL; + } ctx1 = *uint64; - EC_NULL_LOG (uint64 = dalloc_get(query, "DALLOC_CTX", 0, "DALLOC_CTX", 0, "uint64_t", 2) ); + uint64 = dalloc_get(query, "DALLOC_CTX", 0, "DALLOC_CTX", 0, "uint64_t", 2); + if (uint64 == NULL) { + EC_FAIL; + } ctx2 = *uint64; /* Get query for context */ - EC_NULL_LOG( slq = slq_for_ctx(ctx1, ctx2) ); - if (slq->slq_state != SLQ_STATE_RUNNING && slq->slq_state != SLQ_STATE_DONE) { - EC_FAIL_LOG("Spotlight: attempt to fetch results for query that isn't active"); + slq = slq_for_ctx(ctx1, ctx2); + if (slq == NULL) { + EC_FAIL; } - /* Create and pass reply handle */ - EC_NULL( slq->slq_reply = talloc_zero(reply, sl_array_t) ); + switch (slq->slq_state) { + case SLQ_STATE_RUNNING: + case SLQ_STATE_RESULTS: + case SLQ_STATE_DONE: + ok = add_results(array, slq); + if (!ok) { + LOG(log_error, logtype_sl, "error adding results"); + EC_FAIL; + } + if (slq->slq_state == SLQ_STATE_RESULTS) { + tracker_sparql_cursor_next_async( + slq->tracker_cursor, + slq->cancellable, + tracker_cursor_cb, + slq); + } + break; - /* Fetch Tracker results*/ - EC_ZERO_LOG( sl_module_export->sl_mod_fetch_result(slq) ); + case SLQ_STATE_ERROR: + LOG(log_error, logtype_sl, "query in error state"); + EC_FAIL; - dalloc_add(reply, slq->slq_reply, sl_array_t); + default: + LOG(log_error, logtype_sl, "unexpected query state %d", slq->slq_state); + EC_FAIL; + } + + dalloc_add(reply, array, sl_array_t); + EC_EXIT; EC_CLEANUP: - if (ret != 0) { - slq_error(slq); - } + slq_destroy(slq); + status = UINT64_MAX; + dalloc_add_copy(array, &status, uint64_t); + dalloc_add(reply, array, sl_array_t); EC_EXIT; } -static int sl_rpc_storeAttributesForOIDArray(const AFPObj *obj, const DALLOC_CTX *query, DALLOC_CTX *reply, const struct vol *vol) +static int sl_rpc_storeAttributesForOIDArray(const AFPObj *obj, + const DALLOC_CTX *query, + DALLOC_CTX *reply, + const struct vol *vol) { EC_INIT; uint64_t uint64; @@ -375,11 +944,11 @@ static int sl_rpc_storeAttributesForOIDArray(const AFPObj *obj, const DALLOC_CTX cnid_t id; char *path; struct dir *dir; - + EC_NULL_LOG( cnids = dalloc_get(query, "DALLOC_CTX", 0, "sl_cnids_t", 2) ); memcpy(&uint64, cnids->ca_cnids->dd_talloc_array[0], sizeof(uint64_t)); id = (cnid_t)uint64; - LOG(log_debug, logtype_sl, "sl_rpc_storeAttributesForOIDArray: CNID: %" PRIu32, id); + LOG(log_debug, logtype_sl, "CNID: %" PRIu32, id); if (htonl(id) == DIRDID_ROOT) { path = vol->v_path; @@ -422,11 +991,10 @@ static int sl_rpc_fetchAttributeNamesForOIDArray(const AFPObj *obj, const DALLOC EC_INIT; uint64_t uint64; sl_cnids_t *cnids; - sl_time_t *sl_time; cnid_t id; char *path; struct dir *dir; - + EC_NULL_LOG( cnids = dalloc_get(query, "DALLOC_CTX", 0, "sl_cnids_t", 1) ); memcpy(&uint64, cnids->ca_cnids->dd_talloc_array[0], sizeof(uint64_t)); id = (cnid_t)uint64; @@ -488,155 +1056,206 @@ EC_CLEANUP: static int sl_rpc_fetchAttributesForOIDArray(AFPObj *obj, const DALLOC_CTX *query, DALLOC_CTX *reply, const struct vol *vol) { EC_INIT; - slq_t *slq = NULL; uint64_t uint64; - sl_cnids_t *cnids; - sl_time_t *sl_time; - cnid_t id; + sl_cnids_t *cnids, *replycnids; + cnid_t id, did; struct dir *dir; - sl_array_t *reqinfo; + sl_array_t *array, *reqinfo, *fm_array; + char buffer[12 + MAXPATHLEN + 1]; + char *name, *path; + sl_filemeta_t *fm; + sl_nil_t nil; + uint64_t sl_res; + struct stat sb; + array = talloc_zero(reply, sl_array_t); + replycnids = talloc_zero(reply, sl_cnids_t); + replycnids->ca_cnids = talloc_zero(replycnids, DALLOC_CTX); + fm = talloc_zero(array, sl_filemeta_t); + fm_array = talloc_zero(fm, sl_array_t); + if (array == NULL || replycnids == NULL || replycnids->ca_cnids == NULL + || fm == NULL || fm_array == NULL) { + EC_FAIL; + } + + reqinfo = dalloc_get(query, "DALLOC_CTX", 0, "sl_array_t", 1); + if (reqinfo == NULL) { + EC_FAIL; + } + cnids = dalloc_get(query, "DALLOC_CTX", 0, "sl_cnids_t", 2); + if (cnids == NULL) { + EC_FAIL; + } - /* Allocate and initialize query object */ - slq = talloc_zero(reply, slq_t); - slq->slq_state = SLQ_STATE_ATTRS; - slq->slq_obj = obj; - slq->slq_vol = vol; - EC_NULL( slq->slq_reply = talloc_zero(reply, sl_array_t) ); - EC_NULL( reqinfo = dalloc_get(query, "DALLOC_CTX", 0, "sl_array_t", 1) ); - slq->slq_reqinfo = talloc_steal(slq, reqinfo); - - EC_NULL_LOG( cnids = dalloc_get(query, "DALLOC_CTX", 0, "sl_cnids_t", 2) ); memcpy(&uint64, cnids->ca_cnids->dd_talloc_array[0], sizeof(uint64_t)); id = (cnid_t)uint64; if (htonl(id) == DIRDID_ROOT) { - slq->slq_path = talloc_strdup(slq, vol->v_path); + path = talloc_strdup(reply, vol->v_path); } else if (id < CNID_START) { EC_FAIL; } else { - cnid_t did; - char buffer[12 + MAXPATHLEN + 1]; - char *name; did = htonl(id); EC_NULL( name = cnid_resolve(vol->v_cdb, &did, buffer, sizeof(buffer)) ); EC_NULL( dir = dirlookup(vol, did) ); - EC_NULL( slq->slq_path = talloc_asprintf(slq, "%s/%s", bdata(dir->d_fullpath), name) ); + EC_NULL( path = talloc_asprintf(reply, "%s/%s", bdata(dir->d_fullpath), name) ); } - /* Return result value 0 */ - uint64_t sl_res = 0; - dalloc_add_copy(slq->slq_reply, &sl_res, uint64_t); + EC_ZERO( stat(path, &sb) ); + + sl_res = 0; + dalloc_add_copy(array, &sl_res, uint64_t); - /* Return CNID array */ - sl_cnids_t *replycnids = talloc_zero(reply, sl_cnids_t); - replycnids->ca_cnids = talloc_zero(cnids, DALLOC_CTX); replycnids->ca_unkn1 = 0xfec; replycnids->ca_context = cnids->ca_context; uint64 = (uint64_t)id; dalloc_add_copy(replycnids->ca_cnids, &uint64, uint64_t); - dalloc_add(slq->slq_reply, replycnids, sl_cnids_t); - - /* Fetch attributes from module */ - EC_ZERO_LOG( sl_module_export->sl_mod_fetch_attrs(slq) ); + dalloc_add(array, replycnids, sl_cnids_t); + dalloc_add(fm, fm_array, fm_array_t); + dalloc_add_copy(fm_array, &nil, sl_nil_t); + add_filemeta(reqinfo, fm_array, path, &sb); - dalloc_add(reply, slq->slq_reply, sl_array_t); + /* Now add result */ + dalloc_add(array, fm, sl_filemeta_t); + dalloc_add(reply, array, sl_array_t); + EC_EXIT; EC_CLEANUP: + sl_res = UINT64_MAX; + dalloc_add_copy(array, &sl_res, uint64_t); + dalloc_add(array, fm, sl_filemeta_t); + dalloc_add(reply, array, sl_array_t); EC_EXIT; } -static int sl_rpc_closeQueryForContext(const AFPObj *obj, const DALLOC_CTX *query, DALLOC_CTX *reply, const struct vol *v) +static int sl_rpc_closeQueryForContext(const AFPObj *obj, + const DALLOC_CTX *query, + DALLOC_CTX *reply, + const struct vol *v) { EC_INIT; slq_t *slq = NULL; uint64_t *uint64, ctx1, ctx2; sl_array_t *array; - + uint64_t sl_result; + + array = talloc_zero(reply, sl_array_t); + /* Context */ - EC_NULL_LOG (uint64 = dalloc_get(query, "DALLOC_CTX", 0, "DALLOC_CTX", 0, "uint64_t", 1) ); + uint64 = dalloc_get(query, "DALLOC_CTX", 0, "DALLOC_CTX", 0, "uint64_t", 1); + if (uint64 == NULL) { + EC_FAIL; + } ctx1 = *uint64; - EC_NULL_LOG (uint64 = dalloc_get(query, "DALLOC_CTX", 0, "DALLOC_CTX", 0, "uint64_t", 2) ); + uint64 = dalloc_get(query, "DALLOC_CTX", 0, "DALLOC_CTX", 0, "uint64_t", 2); + if (uint64 == NULL) { + EC_FAIL; + } ctx2 = *uint64; /* Get query for context and free it */ - EC_NULL_LOG( slq = slq_for_ctx(ctx1, ctx2) ); - if (slq->slq_state != SLQ_STATE_DONE) - LOG(log_warning, logtype_sl, "Closing active query"); - sl_module_export->sl_mod_end_search(slq); - slq_remove(slq); - talloc_free(slq); - slq = NULL; + slq = slq_for_ctx(ctx1, ctx2); + if (slq == NULL) { + EC_FAIL; + } - array = talloc_zero(reply, sl_array_t); - uint64_t sl_res = 0; - dalloc_add_copy(array, &sl_res, uint64_t); - dalloc_add(reply, array, sl_array_t); + switch (slq->slq_state) { + case SLQ_STATE_DONE: + case SLQ_STATE_ERROR: + slq_destroy(slq); + break; + + case SLQ_STATE_RUNNING: + case SLQ_STATE_RESULTS: + slq_cancel(slq); + break; + + default: + LOG(log_error, logtype_sl, "Unexpected state %d", slq->slq_state); + EC_FAIL; + } + + sl_result = 0; EC_CLEANUP: if (ret != 0) { - slq_error(slq); + sl_result = UINT64_MAX; } + dalloc_add_copy(array, &sl_result, uint64_t); + dalloc_add(reply, array, sl_array_t); EC_EXIT; } -/************************************************************************************************** - * Spotlight module functions - **************************************************************************************************/ +/****************************************************************************** + * Spotlight functions + ******************************************************************************/ -int sl_mod_load(AFPObj *obj) +int spotlight_init(AFPObj *obj) { - EC_INIT; + const char *attributes; + struct sl_ctx *sl_ctx; - sl_ctx = talloc_new(NULL); + LOG(log_info, logtype_sl, "Initializing Spotlight"); - if ((sl_module = mod_open(obj->options.slmod_path)) == NULL) { - LOG(log_error, logtype_sl, "Failed to load module \'%s\': %s", obj->options.slmod_path, mod_error()); - EC_FAIL; - } + sl_ctx = talloc_zero(NULL, struct sl_ctx); + obj->sl_ctx = sl_ctx; - if ((sl_module_export = mod_symbol(sl_module, "sl_mod")) == NULL) { - LOG(log_error, logtype_sl, "sl_mod_load(%s): mod_symbol error for symbol sl_mod", obj->options.slmod_path); - EC_FAIL; + attributes = atalk_iniparser_getstring(obj->iniconfig, INISEC_GLOBAL, + "spotlight attributes", NULL); + if (attributes) { + configure_spotlight_attributes(attributes); } - sl_module_export->sl_mod_init(obj); - -EC_CLEANUP: - EC_EXIT; -} + /* + * Tracker uses glibs event dispatching, so we need a mainloop + */ + sl_ctx->mainloop = g_main_loop_new(NULL, false); + sl_ctx->cancellable = g_cancellable_new(); -/** - * Index a file - **/ -void sl_index_file(const char *path) -{ - if (sl_module_export && sl_module_export->sl_mod_index_file) - sl_module_export->sl_mod_index_file(path); + setenv("DBUS_SESSION_BUS_ADDRESS", "unix:path=" _PATH_STATEDIR "spotlight.ipc", 1); + setenv("XDG_DATA_HOME", _PATH_STATEDIR, 0); + setenv("XDG_CACHE_HOME", _PATH_STATEDIR, 0); + setenv("TRACKER_USE_LOG_FILES", "1", 0); + + tracker_sparql_connection_get_async(sl_ctx->cancellable, + tracker_con_cb, sl_ctx); + + return 0; } -/************************************************************************************************** +/****************************************************************************** * AFP functions - **************************************************************************************************/ + ******************************************************************************/ -int afp_spotlight_rpc(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen) +int afp_spotlight_rpc(AFPObj *obj, char *ibuf, size_t ibuflen, + char *rbuf, size_t *rbuflen) { EC_INIT; TALLOC_CTX *tmp_ctx = talloc_new(NULL); uint16_t vid; int cmd; - int endianess = SL_ENC_LITTLE_ENDIAN; struct vol *vol; DALLOC_CTX *query; DALLOC_CTX *reply; char *rpccmd; int len; + bool event; *rbuflen = 0; - if (sl_module == NULL) + if (!(obj->options.flags & OPTION_SPOTLIGHT)) { return AFPERR_NOOP; + } + + /* + * Process finished glib events + */ + event = true; + while (event) { + event = g_main_context_iteration(NULL, false); + } + slq_cancelled_cleanup(); ibuf += 2; ibuflen -= 2; @@ -678,8 +1297,8 @@ int afp_spotlight_rpc(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_ EC_NULL( reply = talloc_zero(tmp_ctx, DALLOC_CTX) ); EC_NEG1_LOG( sl_unpack(query, ibuf + 22) ); - LOG(log_debug, logtype_sl, "afp_spotlight_rpc: Request dump:"); - dd_dump(query, 0); + LOG(log_debug, logtype_sl, "Spotlight RPC request:\n%s", + dd_dump(query, 0)); EC_NULL_LOG( rpccmd = dalloc_get(query, "DALLOC_CTX", 0, "DALLOC_CTX", 0, "char *", 0) ); @@ -701,8 +1320,8 @@ int afp_spotlight_rpc(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_ LOG(log_error, logtype_sl, "afp_spotlight_rpc: unknown Spotlight RPC: %s", rpccmd); } - LOG(log_debug, logtype_sl, "afp_spotlight_rpc: Reply dump:"); - dd_dump(reply, 0); + LOG(log_debug, logtype_sl, "Spotlight RPC reply dump:\n%s", + dd_dump(reply, 0)); memset(rbuf, 0, 4); *rbuflen += 4; @@ -720,97 +1339,3 @@ EC_CLEANUP: } EC_EXIT; } -#endif - -/************************************************************************************************** - * Testing - **************************************************************************************************/ - -#ifdef SPOT_TEST_MAIN - -int main(int argc, char **argv) -{ - EC_INIT; - TALLOC_CTX *mem_ctx = talloc_new(NULL); - DALLOC_CTX *dd = talloc_zero(mem_ctx, DALLOC_CTX); - uint64_t i; - - set_processname("spot"); - setuplog("default:info,spotlight:debug", "/dev/tty"); - - LOG(log_info, logtype_sl, "Start"); - - i = 1; - dalloc_add_copy(dd, &i, uint64_t); - char *str = dalloc_strdup(dd, "hello world"); - dalloc_add(dd, str, char *); - sl_bool_t b = true; - dalloc_add_copy(dd, &b, sl_bool_t); - - /* add a nested array */ - DALLOC_CTX *nested = talloc_zero(dd, DALLOC_CTX); - i = 3; - dalloc_add_copy(nested, &i, uint64_t); - dalloc_add(dd, nested, DALLOC_CTX); - - /* test an allocated CNID array */ - uint64_t id = 16; - sl_cnids_t *cnids = talloc_zero(dd, sl_cnids_t); - cnids->ca_cnids = talloc_zero(cnids, DALLOC_CTX); - cnids->ca_unkn1 = 1; - dalloc_add_copy(cnids->ca_cnids, &id, uint64_t); - dalloc_add(dd, cnids, sl_cnids_t); - - /* Now the Spotlight types */ - sl_array_t *sl_array = talloc_zero(dd, sl_array_t); - i = 0x1234; - dalloc_add_copy(sl_array, &i, uint64_t); - - sl_dict_t *sl_dict = talloc_zero(dd, sl_dict_t); - i = 0xffff; - dalloc_add_copy(sl_dict, &i, uint64_t); - dalloc_add(sl_array, sl_dict, sl_dict_t); - - dalloc_add(dd, sl_array, sl_array_t); - - dd_dump(dd, 0); - - /* now parse a real spotlight packet */ - if (argc > 1) { - char ibuf[8192]; - char rbuf[8192]; - int fd; - size_t len; - DALLOC_CTX *query; - - EC_NULL( query = talloc_zero(mem_ctx, DALLOC_CTX) ); - - EC_NEG1_LOG( fd = open(argv[1], O_RDONLY) ); - EC_NEG1_LOG( len = read(fd, ibuf, 8192) ); - close(fd); - EC_NEG1_LOG( sl_unpack(query, ibuf + 24) ); - - /* Now dump the whole thing */ - dd_dump(query, 0); - } - -#if 0 - /* packing */ - int qlen; - char buf[MAX_SLQ_DAT]; - EC_NEG1_LOG( qlen = sl_pack(query, buf) ); - - EC_NEG1_LOG( fd = open("test.bin", O_RDWR) ); - lseek(fd, 24, SEEK_SET); - write(fd, buf, qlen); - close(fd); -#endif - -EC_CLEANUP: - if (mem_ctx) { - talloc_free(mem_ctx); - mem_ctx = NULL; - } - EC_EXIT; -} -#endif diff --git a/etc/afpd/spotlight_marshalling.c b/etc/afpd/spotlight_marshalling.c index 69733f49..9329dde2 100644 --- a/etc/afpd/spotlight_marshalling.c +++ b/etc/afpd/spotlight_marshalling.c @@ -216,7 +216,7 @@ EC_CLEANUP: static int sl_pack_CNID(sl_cnids_t *cnids, char *buf, int offset, char *toc_buf, int *toc_idx) { EC_INIT; - int off = 0, len; + int len; int cnid_count = talloc_array_length(cnids->ca_cnids->dd_talloc_array); uint64_t id; @@ -472,7 +472,6 @@ static int sl_unpack_floats(DALLOC_CTX *query, const char *buf, int offset, uint { int count, i; uint64_t query_data64; - double fval; union { double d; uint32_t w[2]; @@ -786,8 +785,8 @@ EC_CLEANUP: int sl_unpack(DALLOC_CTX *query, const char *buf) { EC_INIT; - int encoding, i, toc_entries; - uint64_t toc_offset, tquerylen, toc_entry; + int encoding, toc_entries; + uint64_t toc_offset; if (strncmp(buf, "md031234", 8) == 0) encoding = SL_ENC_BIG_ENDIAN; diff --git a/etc/netatalk/netatalk.c b/etc/netatalk/netatalk.c index 1ce7befc..b8987b7e 100644 --- a/etc/netatalk/netatalk.c +++ b/etc/netatalk/netatalk.c @@ -173,7 +173,7 @@ static void sigterm_cb(evutil_socket_t fd, short what, void *arg) event_del(sigquit_ev); event_del(timer_ev); -#ifdef HAVE_TRACKER_SPARQL +#ifdef HAVE_TRACKER system("tracker-control -t"); #endif kill_childs(SIGTERM, &afpd_pid, &cnid_metad_pid, &dbus_pid, NULL); @@ -183,7 +183,7 @@ static void sigterm_cb(evutil_socket_t fd, short what, void *arg) static void sigquit_cb(evutil_socket_t fd, short what, void *arg) { LOG(log_note, logtype_afpd, "Exiting on SIGQUIT"); -#ifdef HAVE_TRACKER_SPARQL +#ifdef HAVE_TRACKER system("tracker-control -t"); #endif kill_childs(SIGQUIT, &afpd_pid, &cnid_metad_pid, &dbus_pid, NULL); @@ -420,7 +420,7 @@ int main(int argc, char **argv) if (atalk_iniparser_getboolean(obj.iniconfig, INISEC_GLOBAL, "start dbus", 1)) { dbus_path = atalk_iniparser_getstring(obj.iniconfig, INISEC_GLOBAL, "dbus daemon", DBUS_DAEMON_PATH); - LOG(log_debug, logtype_default, "DBUS: '%s'", dbus_path); + LOG(log_note, logtype_default, "Starting dbus: %s", dbus_path); if ((dbus_pid = run_process(dbus_path, "--config-file=" _PATH_CONFDIR "dbus-session.conf", NULL)) == NETATALK_SRV_ERROR) { LOG(log_error, logtype_default, "Error starting '%s'", dbus_path); netatalk_exit(EXITERR_CONF); @@ -433,6 +433,7 @@ int main(int argc, char **argv) set_sl_volumes(); if (atalk_iniparser_getboolean(obj.iniconfig, INISEC_GLOBAL, "start tracker", 1)) { + LOG(log_note, logtype_default, "Starting Tracker"); system(TRACKER_PREFIX "/bin/tracker-control -s"); } } diff --git a/etc/spotlight/Makefile.am b/etc/spotlight/Makefile.am index 60e0c25b..95f1ba48 100644 --- a/etc/spotlight/Makefile.am +++ b/etc/spotlight/Makefile.am @@ -1,36 +1,33 @@ # Makefile.am for etc/spotlight/ pkgconfdir = @PKGCONFDIR@ -moduledir = @UAMS_PATH@ -module_LTLIBRARIES = +noinst_LTLIBRARIES = noinst_PROGRAMS = -noinst_HEADERS = slmod_sparql_map.h +noinst_HEADERS = sparql_map.h BUILT_SOURCES = AM_YFLAGS = -d -if HAVE_TRACKER_SPARQL -BUILT_SOURCES += slmod_sparql_parser.h +if HAVE_TRACKER +BUILT_SOURCES += sparql_parser.h noinst_PROGRAMS += srp -module_LTLIBRARIES += slmod_sparql.la +noinst_LTLIBRARIES += libspotlight.la -slmod_sparql_la_SOURCES = \ - slmod_sparql.c \ - slmod_sparql_map.c \ - slmod_sparql_parser.y \ +libspotlight_la_SOURCES = \ + sparql_map.c \ + sparql_parser.y \ spotlight_rawquery_lexer.l -slmod_sparql_la_CFLAGS = \ +libspotlight_la_CFLAGS = \ -DDBUS_API_SUBJECT_TO_CHANGE \ @TRACKER_CFLAGS@ \ - @TRACKER_MINER_CFLAGS@ \ -D_PATH_STATEDIR='"$(localstatedir)/netatalk"' -slmod_sparql_la_LDFLAGS = -module -avoid-version @TRACKER_LIBS@ @TRACKER_MINER_LIBS@ +libspotlight_la_LDFLAGS = @TRACKER_LIBS@ @TRACKER_MINER_LIBS@ srp_SOURCES = \ - slmod_sparql_map.c \ - slmod_sparql_parser.y \ + sparql_map.c \ + sparql_parser.y \ spotlight_rawquery_lexer.l srp_CFLAGS = -DMAIN -I$(top_srcdir)/include @TRACKER_CFLAGS@ diff --git a/etc/spotlight/slmod_sparql.c b/etc/spotlight/slmod_sparql.c index 21e8d382..e58d7df6 100644 --- a/etc/spotlight/slmod_sparql.c +++ b/etc/spotlight/slmod_sparql.c @@ -1,5 +1,5 @@ /* - Copyright (c) 2012 Frank Lahm + Copyright (C) Ralph Boehme 2012-2014 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -34,9 +34,6 @@ #define MAX_SL_RESULTS 20 static TrackerSparqlConnection *connection; -#if 0 -static TrackerMinerManager *manager; -#endif static char *tracker_to_unix_path(const char *uri) { @@ -398,37 +395,6 @@ static int sl_mod_index_file(const void *p) * impose limits on the maximum number of watched directories. */ return 0; - -#if 0 -#ifdef HAVE_TRACKER_MINER - EC_INIT; - const char *f = p; - - if (!f) - goto EC_CLEANUP; - - GError *error = NULL; - GFile *file = NULL; - - file = g_file_new_for_commandline_arg(f); - - become_root(); - tracker_miner_manager_index_file(manager, file, &error); - unbecome_root(); - - if (error) - LOG(log_error, logtype_sl, "sl_mod_index_file(\"%s\"): indexing failed", f); - else - LOG(log_debug, logtype_sl, "sl_mod_index_file(\"%s\"): indexing file was successful", f); - -EC_CLEANUP: - if (file) - g_object_unref(file); - EC_EXIT; -#else - return 0; -#endif /* HAVE_TRACKER_MINER */ -#endif /* 0 */ } struct sl_module_export sl_mod = { diff --git a/etc/spotlight/slmod_sparql_map.c b/etc/spotlight/slmod_sparql_map.c deleted file mode 100644 index 7ac4963c..00000000 --- a/etc/spotlight/slmod_sparql_map.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - Copyright (c) 2012 Frank Lahm - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. -*/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif /* HAVE_CONFIG_H */ - -#include -#include -#include - -#include - -#include "slmod_sparql_map.h" - -#define NOTSUPPORTED NULL -#define SPECIAL NULL - -struct spotlight_sparql_map spotlight_sparql_map[] = { - /* ssm_spotlight_attr ssm_enabled, ssm_type, ssm_sparql_attr */ - {"*", true, ssmt_fts, "fts:match"}, - - /* Filesystem metadata */ - {"kMDItemFSLabel", true, ssmt_num, NOTSUPPORTED}, - {"kMDItemDisplayName", true, ssmt_str, "nfo:fileName"}, - {"kMDItemFSName", true, ssmt_str, "nfo:fileName"}, - {"kMDItemFSContentChangeDate", true, ssmt_date, "nfo:fileLastModified"}, - - /* Common metadata */ - {"kMDItemTextContent", true, ssmt_fts, "fts:match"}, - {"kMDItemContentCreationDate", true, ssmt_date, "nie:contentCreated"}, - {"kMDItemContentModificationDate", true, ssmt_date, "nfo:fileLastModified"}, - {"kMDItemAttributeChangeDate", true, ssmt_date, "nfo:fileLastModified"}, - {"kMDItemLastUsedDate", true, ssmt_date, "nfo:fileLastAccessed"}, - {"kMDItemAuthors", true, ssmt_str, "dc:creator"}, - {"kMDItemCopyright", true, ssmt_str, "nie:copyright"}, - {"kMDItemCountry", true, ssmt_str, "nco:country"}, - {"kMDItemCreator", true, ssmt_str, "dc:creator"}, - {"kMDItemDurationSeconds", true, ssmt_num, "nfo:duration"}, - {"kMDItemNumberOfPages", true, ssmt_num, "nfo:pageCount"}, - {"kMDItemTitle", true, ssmt_str, "nie:title"}, - {"_kMDItemGroupId", true, ssmt_type, SPECIAL}, - {"kMDItemContentTypeTree", true, ssmt_type, SPECIAL}, - - /* Image metadata */ - {"kMDItemPixelWidth", true, ssmt_num, "nfo:width"}, - {"kMDItemPixelHeight", true, ssmt_num, "nfo:height"}, - {"kMDItemColorSpace", true, ssmt_str, "nexif:colorSpace"}, - {"kMDItemBitsPerSample", true, ssmt_num, "nfo:colorDepth"}, - {"kMDItemFocalLength", true, ssmt_num, "nmm:focalLength"}, - {"kMDItemISOSpeed", true, ssmt_num, "nmm:isoSpeed"}, - {"kMDItemOrientation", true, ssmt_bool, "nfo:orientation"}, - {"kMDItemResolutionWidthDPI", true, ssmt_num, "nfo:horizontalResolution"}, - {"kMDItemResolutionHeightDPI", true, ssmt_num, "nfo:verticalResolution"}, - {"kMDItemExposureTimeSeconds", true, ssmt_num, "nmm:exposureTime"}, - - /* Audio metadata */ - {"kMDItemComposer", true, ssmt_str, "nmm:composer"}, - {"kMDItemMusicalGenre", true, ssmt_str, "nfo:genre"}, - - {NULL, false, ssmt_str, NULL} -}; - -struct MDTypeMap MDTypeMap[] = { - {"1", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nmo#Email"}, - {"2", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nco#Contact"}, - {"3", kMDTypeMapNotSup, NULL}, /* PrefPane */ - {"4", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Font"}, - {"5", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Bookmark"}, - {"6", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nco#Contact"}, - {"7", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Video"}, - {"8", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Executable"}, - {"9", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Folder"}, - {"10", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Audio"}, - {"11", kMDTypeMapMime, "application/pdf"}, - {"12", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Presentation"}, - {"13", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Image"}, - {"public.jpeg", kMDTypeMapMime, "image/jpeg"}, - {"public.tiff", kMDTypeMapMime, "image/tiff"}, - {"com.compuserve.gif", kMDTypeMapMime, "image/gif"}, - {"public.png", kMDTypeMapMime, "image/png"}, - {"com.microsoft.bmp", kMDTypeMapMime, "image/bmp"}, - {"public.content", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Document"}, - {"public.mp3", kMDTypeMapMime, "audio/mpeg"}, - {"public.mpeg-4-audio", kMDTypeMapMime, "audio/x-aac"}, - {"com.apple.application", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Software"}, - {"public.text", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#TextDocument"}, - {"public.plain-text", kMDTypeMapMime, "text/plain"}, - {"public.rtf", kMDTypeMapMime, "text/rtf"}, - {"public.html", kMDTypeMapMime, "text/html"}, - {"public.xml", kMDTypeMapMime, "text/xml"}, - {"public.source-code", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#SourceCode"}, - {NULL, kMDTypeMapNotSup, NULL} -}; - -void configure_spotlight_attributes(const char *attributes_in) -{ - char *attr, *attributes; - int i; - - for (i = 0; spotlight_sparql_map[i].ssm_spotlight_attr != NULL; i++) - spotlight_sparql_map[i].ssm_enabled = false; - - /* - * Go through the attribute map and for every element scan - * attributes_in with strtok(). If it's contained, keep it - * enabled, otherwise disable it. - */ - - attributes = strdup(attributes_in); - - for (attr = strtok(attributes, ","); attr; attr = strtok(NULL, ",")) { - - for (i = 0; spotlight_sparql_map[i].ssm_spotlight_attr != NULL; i++) - - if (strcmp(attr, spotlight_sparql_map[i].ssm_spotlight_attr) == 0) { - LOG(log_info, logtype_sl, "Enabling Spotlight attribute: %s", - spotlight_sparql_map[i].ssm_spotlight_attr); - spotlight_sparql_map[i].ssm_enabled = true; - break; - } - } - - free(attributes); -} diff --git a/etc/spotlight/slmod_sparql_map.h b/etc/spotlight/slmod_sparql_map.h deleted file mode 100644 index 3b924740..00000000 --- a/etc/spotlight/slmod_sparql_map.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - Copyright (c) 2012 Frank Lahm - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. -*/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif /* HAVE_CONFIG_H */ - -#ifndef SPOTLIGHT_SPARQL_MAP_H -#define SPOTLIGHT_SPARQL_MAP_H - -enum ssm_type { - ssmt_bool, /* a boolean value that doesn't requires a SPARQL FILTER */ - ssmt_num, /* a numeric value that requires a SPARQL FILTER */ - ssmt_str, /* a string value that requieres a SPARQL FILTER */ - ssmt_fts, /* a string value that will be queried with SPARQL 'fts:match' */ - ssmt_date, /* date values are handled in a special map function map_daterange() */ - ssmt_type /* kMDItemContentType, requires special mapping */ -}; - -enum kMDTypeMap { - kMDTypeMapNotSup, /* not supported */ - kMDTypeMapRDF, /* query with rdf:type */ - kMDTypeMapMime /* query with nie:mimeType */ -}; - -struct spotlight_sparql_map { - const char *ssm_spotlight_attr; - bool ssm_enabled; - enum ssm_type ssm_type; - const char *ssm_sparql_attr; -}; - -struct MDTypeMap { - const char *mdtm_value; /* MD query value of attributes '_kMDItemGroupId' and 'kMDItemContentTypeTree' */ - enum kMDTypeMap mdtm_type; /* whether SPARQL query must search attribute rdf:type or nie:mime_Type */ - const char *mdtm_sparql; /* the SPARQL query match string */ -}; - -extern struct spotlight_sparql_map spotlight_sparql_map[]; -extern struct spotlight_sparql_map spotlight_sparql_date_map[]; -extern struct MDTypeMap MDTypeMap[]; -#endif diff --git a/etc/spotlight/slmod_sparql_parser.c b/etc/spotlight/slmod_sparql_parser.c deleted file mode 100644 index 3d32af62..00000000 --- a/etc/spotlight/slmod_sparql_parser.c +++ /dev/null @@ -1,2055 +0,0 @@ -/* A Bison parser, made by GNU Bison 2.7. */ - -/* Bison implementation for Yacc-like parsers in C - - Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -/* As a special exception, you may create a larger work that contains - part or all of the Bison parser skeleton and distribute that work - under terms of your choice, so long as that work isn't itself a - parser generator using the skeleton or a modified version thereof - as a parser skeleton. Alternatively, if you modify or redistribute - the parser skeleton itself, you may (at your option) remove this - special exception, which will cause the skeleton and the resulting - Bison output files to be licensed under the GNU General Public - License without this special exception. - - This special exception was added by the Free Software Foundation in - version 2.2 of Bison. */ - -/* C LALR(1) parser skeleton written by Richard Stallman, by - simplifying the original so-called "semantic" parser. */ - -/* All symbols defined below should begin with yy or YY, to avoid - infringing on user name space. This should be done even for local - variables, as they might otherwise be expanded by user macros. - There are some unavoidable exceptions within include files to - define necessary library symbols; they are noted "INFRINGES ON - USER NAME SPACE" below. */ - -/* Identify Bison output. */ -#define YYBISON 1 - -/* Bison version. */ -#define YYBISON_VERSION "2.7" - -/* Skeleton name. */ -#define YYSKELETON_NAME "yacc.c" - -/* Pure parsers. */ -#define YYPURE 0 - -/* Push parsers. */ -#define YYPUSH 0 - -/* Pull parsers. */ -#define YYPULL 1 - - - - -/* Copy the first part of user declarations. */ -/* Line 371 of yacc.c */ -#line 1 "slmod_sparql_parser.y" - - #include - - #include - #include - #include - #include - - #include - - #include - #include - #include - #include - - #include "slmod_sparql_map.h" - - struct yy_buffer_state; - typedef struct yy_buffer_state *YY_BUFFER_STATE; - extern int yylex (void); - extern void yyerror (char const *); - extern void *yyterminate(void); - extern YY_BUFFER_STATE yy_scan_string( const char *str); - extern void yy_delete_buffer ( YY_BUFFER_STATE buffer ); - - /* forward declarations */ - static const char *map_expr(const char *attr, char op, const char *val); - static const char *map_daterange(const char *dateattr, time_t date1, time_t date2); - static time_t isodate2unix(const char *s); - - /* global vars, eg needed by the lexer */ - slq_t *ssp_slq; - - /* local vars */ - static gchar *ssp_result; - static char sparqlvar; - static char *result_limit; - -/* Line 371 of yacc.c */ -#line 107 "slmod_sparql_parser.c" - -# ifndef YY_NULL -# if defined __cplusplus && 201103L <= __cplusplus -# define YY_NULL nullptr -# else -# define YY_NULL 0 -# endif -# endif - -/* Enabling verbose error messages. */ -#ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 -#else -# define YYERROR_VERBOSE 1 -#endif - -/* In a future release of Bison, this section will be replaced - by #include "y.tab.h". */ -#ifndef YY_YY_SLMOD_SPARQL_PARSER_H_INCLUDED -# define YY_YY_SLMOD_SPARQL_PARSER_H_INCLUDED -/* Enabling traces. */ -#ifndef YYDEBUG -# define YYDEBUG 0 -#endif -#if YYDEBUG -extern int yydebug; -#endif - -/* Tokens. */ -#ifndef YYTOKENTYPE -# define YYTOKENTYPE - /* Put the tokens into the symbol table, so that GDB and other debuggers - know about them. */ - enum yytokentype { - WORD = 258, - BOOL = 259, - FUNC_INRANGE = 260, - DATE_ISO = 261, - OBRACE = 262, - CBRACE = 263, - EQUAL = 264, - UNEQUAL = 265, - GT = 266, - LT = 267, - COMMA = 268, - QUOTE = 269, - AND = 270, - OR = 271 - }; -#endif -/* Tokens. */ -#define WORD 258 -#define BOOL 259 -#define FUNC_INRANGE 260 -#define DATE_ISO 261 -#define OBRACE 262 -#define CBRACE 263 -#define EQUAL 264 -#define UNEQUAL 265 -#define GT 266 -#define LT 267 -#define COMMA 268 -#define QUOTE 269 -#define AND 270 -#define OR 271 - - - -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED -typedef union YYSTYPE -{ -/* Line 387 of yacc.c */ -#line 46 "slmod_sparql_parser.y" - - int ival; - const char *sval; - bool bval; - time_t tval; - - -/* Line 387 of yacc.c */ -#line 190 "slmod_sparql_parser.c" -} YYSTYPE; -# define YYSTYPE_IS_TRIVIAL 1 -# define yystype YYSTYPE /* obsolescent; will be withdrawn */ -# define YYSTYPE_IS_DECLARED 1 -#endif - -extern YYSTYPE yylval; - -#ifdef YYPARSE_PARAM -#if defined __STDC__ || defined __cplusplus -int yyparse (void *YYPARSE_PARAM); -#else -int yyparse (); -#endif -#else /* ! YYPARSE_PARAM */ -#if defined __STDC__ || defined __cplusplus -int yyparse (void); -#else -int yyparse (); -#endif -#endif /* ! YYPARSE_PARAM */ -/* "%code provides" blocks. */ -/* Line 387 of yacc.c */ -#line 40 "slmod_sparql_parser.y" - - #define SPRAW_TIME_OFFSET 978307200 - extern int map_spotlight_to_sparql_query(slq_t *slq, gchar **sparql_result); - extern slq_t *ssp_slq; - - -/* Line 387 of yacc.c */ -#line 222 "slmod_sparql_parser.c" - -#endif /* !YY_YY_SLMOD_SPARQL_PARSER_H_INCLUDED */ - -/* Copy the second part of user declarations. */ - -/* Line 390 of yacc.c */ -#line 229 "slmod_sparql_parser.c" - -#ifdef short -# undef short -#endif - -#ifdef YYTYPE_UINT8 -typedef YYTYPE_UINT8 yytype_uint8; -#else -typedef unsigned char yytype_uint8; -#endif - -#ifdef YYTYPE_INT8 -typedef YYTYPE_INT8 yytype_int8; -#elif (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -typedef signed char yytype_int8; -#else -typedef short int yytype_int8; -#endif - -#ifdef YYTYPE_UINT16 -typedef YYTYPE_UINT16 yytype_uint16; -#else -typedef unsigned short int yytype_uint16; -#endif - -#ifdef YYTYPE_INT16 -typedef YYTYPE_INT16 yytype_int16; -#else -typedef short int yytype_int16; -#endif - -#ifndef YYSIZE_T -# ifdef __SIZE_TYPE__ -# define YYSIZE_T __SIZE_TYPE__ -# elif defined size_t -# define YYSIZE_T size_t -# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -# include /* INFRINGES ON USER NAME SPACE */ -# define YYSIZE_T size_t -# else -# define YYSIZE_T unsigned int -# endif -#endif - -#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) - -#ifndef YY_ -# if defined YYENABLE_NLS && YYENABLE_NLS -# if ENABLE_NLS -# include /* INFRINGES ON USER NAME SPACE */ -# define YY_(Msgid) dgettext ("bison-runtime", Msgid) -# endif -# endif -# ifndef YY_ -# define YY_(Msgid) Msgid -# endif -#endif - -/* Suppress unused-variable warnings by "using" E. */ -#if ! defined lint || defined __GNUC__ -# define YYUSE(E) ((void) (E)) -#else -# define YYUSE(E) /* empty */ -#endif - -/* Identity function, used to suppress warnings about constant conditions. */ -#ifndef lint -# define YYID(N) (N) -#else -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static int -YYID (int yyi) -#else -static int -YYID (yyi) - int yyi; -#endif -{ - return yyi; -} -#endif - -#if ! defined yyoverflow || YYERROR_VERBOSE - -/* The parser invokes alloca or malloc; define the necessary symbols. */ - -# ifdef YYSTACK_USE_ALLOCA -# if YYSTACK_USE_ALLOCA -# ifdef __GNUC__ -# define YYSTACK_ALLOC __builtin_alloca -# elif defined __BUILTIN_VA_ARG_INCR -# include /* INFRINGES ON USER NAME SPACE */ -# elif defined _AIX -# define YYSTACK_ALLOC __alloca -# elif defined _MSC_VER -# include /* INFRINGES ON USER NAME SPACE */ -# define alloca _alloca -# else -# define YYSTACK_ALLOC alloca -# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -# include /* INFRINGES ON USER NAME SPACE */ - /* Use EXIT_SUCCESS as a witness for stdlib.h. */ -# ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -# endif -# endif -# endif -# endif -# endif - -# ifdef YYSTACK_ALLOC - /* Pacify GCC's `empty if-body' warning. */ -# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) -# ifndef YYSTACK_ALLOC_MAXIMUM - /* The OS might guarantee only one guard page at the bottom of the stack, - and a page size can be as small as 4096 bytes. So we cannot safely - invoke alloca (N) if N exceeds 4096. Use a slightly smaller number - to allow for a few compiler-allocated temporary stack slots. */ -# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ -# endif -# else -# define YYSTACK_ALLOC YYMALLOC -# define YYSTACK_FREE YYFREE -# ifndef YYSTACK_ALLOC_MAXIMUM -# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM -# endif -# if (defined __cplusplus && ! defined EXIT_SUCCESS \ - && ! ((defined YYMALLOC || defined malloc) \ - && (defined YYFREE || defined free))) -# include /* INFRINGES ON USER NAME SPACE */ -# ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -# endif -# endif -# ifndef YYMALLOC -# define YYMALLOC malloc -# if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ -# endif -# endif -# ifndef YYFREE -# define YYFREE free -# if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -void free (void *); /* INFRINGES ON USER NAME SPACE */ -# endif -# endif -# endif -#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ - - -#if (! defined yyoverflow \ - && (! defined __cplusplus \ - || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) - -/* A type that is properly aligned for any stack member. */ -union yyalloc -{ - yytype_int16 yyss_alloc; - YYSTYPE yyvs_alloc; -}; - -/* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) - -/* The size of an array large to enough to hold all stacks, each with - N elements. */ -# define YYSTACK_BYTES(N) \ - ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ - + YYSTACK_GAP_MAXIMUM) - -# define YYCOPY_NEEDED 1 - -/* Relocate STACK from its old location to the new one. The - local variables YYSIZE and YYSTACKSIZE give the old and new number of - elements in the stack, and YYPTR gives the new location of the - stack. Advance YYPTR to a properly aligned location for the next - stack. */ -# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ - do \ - { \ - YYSIZE_T yynewbytes; \ - YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ - Stack = &yyptr->Stack_alloc; \ - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / sizeof (*yyptr); \ - } \ - while (YYID (0)) - -#endif - -#if defined YYCOPY_NEEDED && YYCOPY_NEEDED -/* Copy COUNT objects from SRC to DST. The source and destination do - not overlap. */ -# ifndef YYCOPY -# if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(Dst, Src, Count) \ - __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) -# else -# define YYCOPY(Dst, Src, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (Dst)[yyi] = (Src)[yyi]; \ - } \ - while (YYID (0)) -# endif -# endif -#endif /* !YYCOPY_NEEDED */ - -/* YYFINAL -- State number of the termination state. */ -#define YYFINAL 2 -/* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 52 - -/* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 17 -/* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 7 -/* YYNRULES -- Number of rules. */ -#define YYNRULES 22 -/* YYNRULES -- Number of states. */ -#define YYNSTATES 51 - -/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ -#define YYUNDEFTOK 2 -#define YYMAXUTOK 271 - -#define YYTRANSLATE(YYX) \ - ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) - -/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ -static const yytype_uint8 yytranslate[] = -{ - 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, - 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16 -}; - -#if YYDEBUG -/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in - YYRHS. */ -static const yytype_uint8 yyprhs[] = -{ - 0, 0, 3, 4, 7, 9, 11, 15, 17, 19, - 23, 27, 31, 37, 43, 49, 55, 62, 69, 76, - 83, 92, 97 -}; - -/* YYRHS -- A `-1'-separated list of the rules' RHS. */ -static const yytype_int8 yyrhs[] = -{ - 18, 0, -1, -1, 18, 19, -1, 20, -1, 4, - -1, 21, 16, 21, -1, 21, -1, 22, -1, 7, - 20, 8, -1, 20, 15, 20, -1, 20, 16, 20, - -1, 3, 9, 14, 3, 14, -1, 3, 10, 14, - 3, 14, -1, 3, 12, 14, 3, 14, -1, 3, - 11, 14, 3, 14, -1, 3, 9, 14, 3, 14, - 3, -1, 3, 10, 14, 3, 14, 3, -1, 3, - 12, 14, 3, 14, 3, -1, 3, 11, 14, 3, - 14, 3, -1, 5, 7, 3, 13, 23, 13, 23, - 8, -1, 6, 7, 3, 8, -1, 3, -1 -}; - -/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ -static const yytype_uint8 yyrline[] = -{ - 0, 68, 68, 70, 74, 88, 94, 102, 103, 104, - 105, 112, 125, 126, 127, 128, 129, 130, 131, 132, - 136, 140, 141 -}; -#endif - -#if YYDEBUG || YYERROR_VERBOSE || 1 -/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. - First, the terminals, then, starting at YYNTOKENS, nonterminals. */ -static const char *const yytname[] = -{ - "$end", "error", "$undefined", "WORD", "BOOL", "FUNC_INRANGE", - "DATE_ISO", "OBRACE", "CBRACE", "EQUAL", "UNEQUAL", "GT", "LT", "COMMA", - "QUOTE", "AND", "OR", "$accept", "input", "line", "expr", "match", - "function", "date", YY_NULL -}; -#endif - -# ifdef YYPRINT -/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to - token YYLEX-NUM. */ -static const yytype_uint16 yytoknum[] = -{ - 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, 269, 270, 271 -}; -# endif - -/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_uint8 yyr1[] = -{ - 0, 17, 18, 18, 19, 20, 20, 20, 20, 20, - 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, - 22, 23, 23 -}; - -/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ -static const yytype_uint8 yyr2[] = -{ - 0, 2, 0, 2, 1, 1, 3, 1, 1, 3, - 3, 3, 5, 5, 5, 5, 6, 6, 6, 6, - 8, 4, 1 -}; - -/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM. - Performed when YYTABLE doesn't specify something else to do. Zero - means the default is an error. */ -static const yytype_uint8 yydefact[] = -{ - 2, 0, 1, 0, 5, 0, 0, 3, 4, 7, - 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 9, 10, 11, 6, 0, - 0, 0, 0, 0, 12, 13, 15, 14, 22, 0, - 0, 16, 17, 19, 18, 0, 0, 0, 0, 21, - 20 -}; - -/* YYDEFGOTO[NTERM-NUM]. */ -static const yytype_int8 yydefgoto[] = -{ - -1, 1, 7, 8, 9, 10, 40 -}; - -/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - STATE-NUM. */ -#define YYPACT_NINF -10 -static const yytype_int8 yypact[] = -{ - -10, 10, -10, 9, -10, -2, -1, -10, 8, -9, - -10, 2, 12, 13, 14, 26, -7, -1, -1, 27, - 28, 29, 30, 31, 22, -10, 20, -10, -10, 23, - 24, 25, 32, 19, 37, 38, 39, 40, -10, 41, - 34, -10, -10, -10, -10, 42, 19, 36, 43, -10, - -10 -}; - -/* YYPGOTO[NTERM-NUM]. */ -static const yytype_int8 yypgoto[] = -{ - -10, -10, -10, -6, 33, -10, 3 -}; - -/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If - positive, shift that token. If negative, reduce the rule which - number is the opposite. If YYTABLE_NINF, syntax error. */ -#define YYTABLE_NINF -1 -static const yytype_uint8 yytable[] = -{ - 16, 25, 3, 4, 5, 15, 6, 19, 17, 18, - 2, 26, 27, 3, 4, 5, 20, 6, 11, 12, - 13, 14, 38, 17, 18, 39, 21, 22, 23, 24, - 3, 29, 30, 31, 32, 33, 18, 34, 35, 36, - 41, 42, 43, 44, 49, 47, 37, 46, 45, 48, - 0, 50, 28 -}; - -#define yypact_value_is_default(Yystate) \ - (!!((Yystate) == (-10))) - -#define yytable_value_is_error(Yytable_value) \ - YYID (0) - -static const yytype_int8 yycheck[] = -{ - 6, 8, 3, 4, 5, 7, 7, 16, 15, 16, - 0, 17, 18, 3, 4, 5, 14, 7, 9, 10, - 11, 12, 3, 15, 16, 6, 14, 14, 14, 3, - 3, 3, 3, 3, 3, 13, 16, 14, 14, 14, - 3, 3, 3, 3, 8, 3, 14, 13, 7, 46, - -1, 8, 19 -}; - -/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ -static const yytype_uint8 yystos[] = -{ - 0, 18, 0, 3, 4, 5, 7, 19, 20, 21, - 22, 9, 10, 11, 12, 7, 20, 15, 16, 16, - 14, 14, 14, 14, 3, 8, 20, 20, 21, 3, - 3, 3, 3, 13, 14, 14, 14, 14, 3, 6, - 23, 3, 3, 3, 3, 7, 13, 3, 23, 8, - 8 -}; - -#define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY (-2) -#define YYEOF 0 - -#define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab -#define YYERROR goto yyerrorlab - - -/* Like YYERROR except do call yyerror. This remains here temporarily - to ease the transition to the new meaning of YYERROR, for GCC. - Once GCC version 2 has supplanted version 1, this can go. However, - YYFAIL appears to be in use. Nevertheless, it is formally deprecated - in Bison 2.4.2's NEWS entry, where a plan to phase it out is - discussed. */ - -#define YYFAIL goto yyerrlab -#if defined YYFAIL - /* This is here to suppress warnings from the GCC cpp's - -Wunused-macros. Normally we don't worry about that warning, but - some users do, and we want to make it easy for users to remove - YYFAIL uses, which will produce warnings from Bison 2.5. */ -#endif - -#define YYRECOVERING() (!!yyerrstatus) - -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - YYPOPSTACK (yylen); \ - yystate = *yyssp; \ - goto yybackup; \ - } \ - else \ - { \ - yyerror (YY_("syntax error: cannot back up")); \ - YYERROR; \ - } \ -while (YYID (0)) - -/* Error token number */ -#define YYTERROR 1 -#define YYERRCODE 256 - - -/* This macro is provided for backward compatibility. */ -#ifndef YY_LOCATION_PRINT -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) -#endif - - -/* YYLEX -- calling `yylex' with the right arguments. */ -#ifdef YYLEX_PARAM -# define YYLEX yylex (YYLEX_PARAM) -#else -# define YYLEX yylex () -#endif - -/* Enable debugging if requested. */ -#if YYDEBUG - -# ifndef YYFPRINTF -# include /* INFRINGES ON USER NAME SPACE */ -# define YYFPRINTF fprintf -# endif - -# define YYDPRINTF(Args) \ -do { \ - if (yydebug) \ - YYFPRINTF Args; \ -} while (YYID (0)) - -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ -do { \ - if (yydebug) \ - { \ - YYFPRINTF (stderr, "%s ", Title); \ - yy_symbol_print (stderr, \ - Type, Value); \ - YYFPRINTF (stderr, "\n"); \ - } \ -} while (YYID (0)) - - -/*--------------------------------. -| Print this symbol on YYOUTPUT. | -`--------------------------------*/ - -/*ARGSUSED*/ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) -#else -static void -yy_symbol_value_print (yyoutput, yytype, yyvaluep) - FILE *yyoutput; - int yytype; - YYSTYPE const * const yyvaluep; -#endif -{ - FILE *yyo = yyoutput; - YYUSE (yyo); - if (!yyvaluep) - return; -# ifdef YYPRINT - if (yytype < YYNTOKENS) - YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); -# else - YYUSE (yyoutput); -# endif - switch (yytype) - { - default: - break; - } -} - - -/*--------------------------------. -| Print this symbol on YYOUTPUT. | -`--------------------------------*/ - -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) -#else -static void -yy_symbol_print (yyoutput, yytype, yyvaluep) - FILE *yyoutput; - int yytype; - YYSTYPE const * const yyvaluep; -#endif -{ - if (yytype < YYNTOKENS) - YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); - else - YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); - - yy_symbol_value_print (yyoutput, yytype, yyvaluep); - YYFPRINTF (yyoutput, ")"); -} - -/*------------------------------------------------------------------. -| yy_stack_print -- Print the state stack from its BOTTOM up to its | -| TOP (included). | -`------------------------------------------------------------------*/ - -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static void -yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) -#else -static void -yy_stack_print (yybottom, yytop) - yytype_int16 *yybottom; - yytype_int16 *yytop; -#endif -{ - YYFPRINTF (stderr, "Stack now"); - for (; yybottom <= yytop; yybottom++) - { - int yybot = *yybottom; - YYFPRINTF (stderr, " %d", yybot); - } - YYFPRINTF (stderr, "\n"); -} - -# define YY_STACK_PRINT(Bottom, Top) \ -do { \ - if (yydebug) \ - yy_stack_print ((Bottom), (Top)); \ -} while (YYID (0)) - - -/*------------------------------------------------. -| Report that the YYRULE is going to be reduced. | -`------------------------------------------------*/ - -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static void -yy_reduce_print (YYSTYPE *yyvsp, int yyrule) -#else -static void -yy_reduce_print (yyvsp, yyrule) - YYSTYPE *yyvsp; - int yyrule; -#endif -{ - int yynrhs = yyr2[yyrule]; - int yyi; - unsigned long int yylno = yyrline[yyrule]; - YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", - yyrule - 1, yylno); - /* The symbols being reduced. */ - for (yyi = 0; yyi < yynrhs; yyi++) - { - YYFPRINTF (stderr, " $%d = ", yyi + 1); - yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], - &(yyvsp[(yyi + 1) - (yynrhs)]) - ); - YYFPRINTF (stderr, "\n"); - } -} - -# define YY_REDUCE_PRINT(Rule) \ -do { \ - if (yydebug) \ - yy_reduce_print (yyvsp, Rule); \ -} while (YYID (0)) - -/* Nonzero means print parse trace. It is left uninitialized so that - multiple parsers can coexist. */ -int yydebug; -#else /* !YYDEBUG */ -# define YYDPRINTF(Args) -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) -# define YY_STACK_PRINT(Bottom, Top) -# define YY_REDUCE_PRINT(Rule) -#endif /* !YYDEBUG */ - - -/* YYINITDEPTH -- initial size of the parser's stacks. */ -#ifndef YYINITDEPTH -# define YYINITDEPTH 200 -#endif - -/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only - if the built-in stack extension method is used). - - Do not make this value too large; the results are undefined if - YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) - evaluated with infinite-precision integer arithmetic. */ - -#ifndef YYMAXDEPTH -# define YYMAXDEPTH 10000 -#endif - - -#if YYERROR_VERBOSE - -# ifndef yystrlen -# if defined __GLIBC__ && defined _STRING_H -# define yystrlen strlen -# else -/* Return the length of YYSTR. */ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static YYSIZE_T -yystrlen (const char *yystr) -#else -static YYSIZE_T -yystrlen (yystr) - const char *yystr; -#endif -{ - YYSIZE_T yylen; - for (yylen = 0; yystr[yylen]; yylen++) - continue; - return yylen; -} -# endif -# endif - -# ifndef yystpcpy -# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE -# define yystpcpy stpcpy -# else -/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in - YYDEST. */ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static char * -yystpcpy (char *yydest, const char *yysrc) -#else -static char * -yystpcpy (yydest, yysrc) - char *yydest; - const char *yysrc; -#endif -{ - char *yyd = yydest; - const char *yys = yysrc; - - while ((*yyd++ = *yys++) != '\0') - continue; - - return yyd - 1; -} -# endif -# endif - -# ifndef yytnamerr -/* Copy to YYRES the contents of YYSTR after stripping away unnecessary - quotes and backslashes, so that it's suitable for yyerror. The - heuristic is that double-quoting is unnecessary unless the string - contains an apostrophe, a comma, or backslash (other than - backslash-backslash). YYSTR is taken from yytname. If YYRES is - null, do not copy; instead, return the length of what the result - would have been. */ -static YYSIZE_T -yytnamerr (char *yyres, const char *yystr) -{ - if (*yystr == '"') - { - YYSIZE_T yyn = 0; - char const *yyp = yystr; - - for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - /* Fall through. */ - default: - if (yyres) - yyres[yyn] = *yyp; - yyn++; - break; - - case '"': - if (yyres) - yyres[yyn] = '\0'; - return yyn; - } - do_not_strip_quotes: ; - } - - if (! yyres) - return yystrlen (yystr); - - return yystpcpy (yyres, yystr) - yyres; -} -# endif - -/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message - about the unexpected token YYTOKEN for the state stack whose top is - YYSSP. - - Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is - not large enough to hold the message. In that case, also set - *YYMSG_ALLOC to the required number of bytes. Return 2 if the - required number of bytes is too large to store. */ -static int -yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, - yytype_int16 *yyssp, int yytoken) -{ - YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]); - YYSIZE_T yysize = yysize0; - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - /* Internationalized format string. */ - const char *yyformat = YY_NULL; - /* Arguments of yyformat. */ - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - /* Number of reported tokens (one for the "unexpected", one per - "expected"). */ - int yycount = 0; - - /* There are many possibilities here to consider: - - Assume YYFAIL is not used. It's too flawed to consider. See - - for details. YYERROR is fine as it does not invoke this - function. - - If this state is a consistent state with a default action, then - the only way this function was invoked is if the default action - is an error action. In that case, don't check for expected - tokens because there are none. - - The only way there can be no lookahead present (in yychar) is if - this state is a consistent state with a default action. Thus, - detecting the absence of a lookahead is sufficient to determine - that there is no unexpected or expected token to report. In that - case, just report a simple "syntax error". - - Don't assume there isn't a lookahead just because this state is a - consistent state with a default action. There might have been a - previous inconsistent state, consistent state with a non-default - action, or user semantic action that manipulated yychar. - - Of course, the expected token list depends on states to have - correct lookahead information, and it depends on the parser not - to perform extra reductions after fetching a lookahead from the - scanner and before detecting a syntax error. Thus, state merging - (from LALR or IELR) and default reductions corrupt the expected - token list. However, the list is correct for canonical LR with - one exception: it will still contain any token that will not be - accepted due to an error action in a later state. - */ - if (yytoken != YYEMPTY) - { - int yyn = yypact[*yyssp]; - yyarg[yycount++] = yytname[yytoken]; - if (!yypact_value_is_default (yyn)) - { - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yyx; - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR - && !yytable_value_is_error (yytable[yyx + yyn])) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - break; - } - yyarg[yycount++] = yytname[yyx]; - { - YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]); - if (! (yysize <= yysize1 - && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; - } - } - } - } - - switch (yycount) - { -# define YYCASE_(N, S) \ - case N: \ - yyformat = S; \ - break - YYCASE_(0, YY_("syntax error")); - YYCASE_(1, YY_("syntax error, unexpected %s")); - YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); - YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); - YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); - YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); -# undef YYCASE_ - } - - { - YYSIZE_T yysize1 = yysize + yystrlen (yyformat); - if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; - } - - if (*yymsg_alloc < yysize) - { - *yymsg_alloc = 2 * yysize; - if (! (yysize <= *yymsg_alloc - && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) - *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; - return 1; - } - - /* Avoid sprintf, as that infringes on the user's name space. - Don't have undefined behavior even if the translation - produced a string with the wrong number of "%s"s. */ - { - char *yyp = *yymsg; - int yyi = 0; - while ((*yyp = *yyformat) != '\0') - if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyformat += 2; - } - else - { - yyp++; - yyformat++; - } - } - return 0; -} -#endif /* YYERROR_VERBOSE */ - -/*-----------------------------------------------. -| Release the memory associated to this symbol. | -`-----------------------------------------------*/ - -/*ARGSUSED*/ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) -#else -static void -yydestruct (yymsg, yytype, yyvaluep) - const char *yymsg; - int yytype; - YYSTYPE *yyvaluep; -#endif -{ - YYUSE (yyvaluep); - - if (!yymsg) - yymsg = "Deleting"; - YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); - - switch (yytype) - { - - default: - break; - } -} - - - - -/* The lookahead symbol. */ -int yychar; - - -#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_END -#endif -#ifndef YY_INITIAL_VALUE -# define YY_INITIAL_VALUE(Value) /* Nothing. */ -#endif - -/* The semantic value of the lookahead symbol. */ -YYSTYPE yylval YY_INITIAL_VALUE(yyval_default); - -/* Number of syntax errors so far. */ -int yynerrs; - - -/*----------. -| yyparse. | -`----------*/ - -#ifdef YYPARSE_PARAM -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -int -yyparse (void *YYPARSE_PARAM) -#else -int -yyparse (YYPARSE_PARAM) - void *YYPARSE_PARAM; -#endif -#else /* ! YYPARSE_PARAM */ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -int -yyparse (void) -#else -int -yyparse () - -#endif -#endif -{ - int yystate; - /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus; - - /* The stacks and their tools: - `yyss': related to states. - `yyvs': related to semantic values. - - Refer to the stacks through separate pointers, to allow yyoverflow - to reallocate them elsewhere. */ - - /* The state stack. */ - yytype_int16 yyssa[YYINITDEPTH]; - yytype_int16 *yyss; - yytype_int16 *yyssp; - - /* The semantic value stack. */ - YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs; - YYSTYPE *yyvsp; - - YYSIZE_T yystacksize; - - int yyn; - int yyresult; - /* Lookahead token as an internal (translated) token number. */ - int yytoken = 0; - /* The variables used to return semantic value and location from the - action routines. */ - YYSTYPE yyval; - -#if YYERROR_VERBOSE - /* Buffer for error messages, and its allocated size. */ - char yymsgbuf[128]; - char *yymsg = yymsgbuf; - YYSIZE_T yymsg_alloc = sizeof yymsgbuf; -#endif - -#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) - - /* The number of symbols on the RHS of the reduced rule. - Keep to zero when no symbol should be popped. */ - int yylen = 0; - - yyssp = yyss = yyssa; - yyvsp = yyvs = yyvsa; - yystacksize = YYINITDEPTH; - - YYDPRINTF ((stderr, "Starting parse\n")); - - yystate = 0; - yyerrstatus = 0; - yynerrs = 0; - yychar = YYEMPTY; /* Cause a token to be read. */ - goto yysetstate; - -/*------------------------------------------------------------. -| yynewstate -- Push a new state, which is found in yystate. | -`------------------------------------------------------------*/ - yynewstate: - /* In all cases, when you get here, the value and location stacks - have just been pushed. So pushing a state here evens the stacks. */ - yyssp++; - - yysetstate: - *yyssp = yystate; - - if (yyss + yystacksize - 1 <= yyssp) - { - /* Get the current used size of the three stacks, in elements. */ - YYSIZE_T yysize = yyssp - yyss + 1; - -#ifdef yyoverflow - { - /* Give user a chance to reallocate the stack. Use copies of - these so that the &'s don't force the real ones into - memory. */ - YYSTYPE *yyvs1 = yyvs; - yytype_int16 *yyss1 = yyss; - - /* Each stack pointer address is followed by the size of the - data in use in that stack, in bytes. This used to be a - conditional around just the two extra args, but that might - be undefined if yyoverflow is a macro. */ - yyoverflow (YY_("memory exhausted"), - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp), - &yystacksize); - - yyss = yyss1; - yyvs = yyvs1; - } -#else /* no yyoverflow */ -# ifndef YYSTACK_RELOCATE - goto yyexhaustedlab; -# else - /* Extend the stack our own way. */ - if (YYMAXDEPTH <= yystacksize) - goto yyexhaustedlab; - yystacksize *= 2; - if (YYMAXDEPTH < yystacksize) - yystacksize = YYMAXDEPTH; - - { - yytype_int16 *yyss1 = yyss; - union yyalloc *yyptr = - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); - if (! yyptr) - goto yyexhaustedlab; - YYSTACK_RELOCATE (yyss_alloc, yyss); - YYSTACK_RELOCATE (yyvs_alloc, yyvs); -# undef YYSTACK_RELOCATE - if (yyss1 != yyssa) - YYSTACK_FREE (yyss1); - } -# endif -#endif /* no yyoverflow */ - - yyssp = yyss + yysize - 1; - yyvsp = yyvs + yysize - 1; - - YYDPRINTF ((stderr, "Stack size increased to %lu\n", - (unsigned long int) yystacksize)); - - if (yyss + yystacksize - 1 <= yyssp) - YYABORT; - } - - YYDPRINTF ((stderr, "Entering state %d\n", yystate)); - - if (yystate == YYFINAL) - YYACCEPT; - - goto yybackup; - -/*-----------. -| yybackup. | -`-----------*/ -yybackup: - - /* Do appropriate processing given the current state. Read a - lookahead token if we need one and don't already have one. */ - - /* First try to decide what to do without reference to lookahead token. */ - yyn = yypact[yystate]; - if (yypact_value_is_default (yyn)) - goto yydefault; - - /* Not known => get a lookahead token if don't already have one. */ - - /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ - if (yychar == YYEMPTY) - { - YYDPRINTF ((stderr, "Reading a token: ")); - yychar = YYLEX; - } - - if (yychar <= YYEOF) - { - yychar = yytoken = YYEOF; - YYDPRINTF ((stderr, "Now at end of input.\n")); - } - else - { - yytoken = YYTRANSLATE (yychar); - YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); - } - - /* If the proper action on seeing token YYTOKEN is to reduce or to - detect an error, take that action. */ - yyn += yytoken; - if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) - goto yydefault; - yyn = yytable[yyn]; - if (yyn <= 0) - { - if (yytable_value_is_error (yyn)) - goto yyerrlab; - yyn = -yyn; - goto yyreduce; - } - - /* Count tokens shifted since error; after three, turn off error - status. */ - if (yyerrstatus) - yyerrstatus--; - - /* Shift the lookahead token. */ - YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); - - /* Discard the shifted token. */ - yychar = YYEMPTY; - - yystate = yyn; - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - *++yyvsp = yylval; - YY_IGNORE_MAYBE_UNINITIALIZED_END - - goto yynewstate; - - -/*-----------------------------------------------------------. -| yydefault -- do the default action for the current state. | -`-----------------------------------------------------------*/ -yydefault: - yyn = yydefact[yystate]; - if (yyn == 0) - goto yyerrlab; - goto yyreduce; - - -/*-----------------------------. -| yyreduce -- Do a reduction. | -`-----------------------------*/ -yyreduce: - /* yyn is the number of a rule to reduce with. */ - yylen = yyr2[yyn]; - - /* If YYLEN is nonzero, implement the default value of the action: - `$$ = $1'. - - Otherwise, the following line sets YYVAL to garbage. - This behavior is undocumented and Bison - users should not rely upon it. Assigning to YYVAL - unconditionally makes the parser a bit smaller, and it avoids a - GCC warning that YYVAL may be used uninitialized. */ - yyval = yyvsp[1-yylen]; - - - YY_REDUCE_PRINT (yyn); - switch (yyn) - { - case 4: -/* Line 1792 of yacc.c */ -#line 74 "slmod_sparql_parser.y" - { - if (ssp_slq->slq_result_limit) - result_limit = talloc_asprintf(ssp_slq, "LIMIT %ld", ssp_slq->slq_result_limit); - else - result_limit = ""; - ssp_result = talloc_asprintf(ssp_slq, - "SELECT ?url WHERE " - "{ %s . ?obj nie:url ?url . FILTER(tracker:uri-is-descendant('file://%s/', ?url)) } %s", - (yyvsp[(1) - (1)].sval), ssp_slq->slq_vol->v_path, result_limit); - (yyval.sval) = ssp_result; -} - break; - - case 5: -/* Line 1792 of yacc.c */ -#line 88 "slmod_sparql_parser.y" - { - if ((yyvsp[(1) - (1)].bval) == false) - YYACCEPT; - else - YYABORT; -} - break; - - case 6: -/* Line 1792 of yacc.c */ -#line 94 "slmod_sparql_parser.y" - { - if ((yyvsp[(1) - (3)].sval) == NULL || (yyvsp[(3) - (3)].sval) == NULL) - YYABORT; - if (strcmp((yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval)) != 0) - (yyval.sval) = talloc_asprintf(ssp_slq, "{ %s } UNION { %s }", (yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval)); - else - (yyval.sval) = talloc_asprintf(ssp_slq, "%s", (yyvsp[(1) - (3)].sval)); -} - break; - - case 7: -/* Line 1792 of yacc.c */ -#line 102 "slmod_sparql_parser.y" - {(yyval.sval) = (yyvsp[(1) - (1)].sval); if ((yyval.sval) == NULL) YYABORT;} - break; - - case 8: -/* Line 1792 of yacc.c */ -#line 103 "slmod_sparql_parser.y" - {(yyval.sval) = (yyvsp[(1) - (1)].sval);} - break; - - case 9: -/* Line 1792 of yacc.c */ -#line 104 "slmod_sparql_parser.y" - {(yyval.sval) = talloc_asprintf(ssp_slq, "%s", (yyvsp[(2) - (3)].sval));} - break; - - case 10: -/* Line 1792 of yacc.c */ -#line 105 "slmod_sparql_parser.y" - { - if (!ssp_slq->slq_allow_expr) { - yyerror("Spotlight queries with logic expressions are disabled"); - YYABORT; - } - (yyval.sval) = talloc_asprintf(ssp_slq, "%s . %s", (yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval)); -} - break; - - case 11: -/* Line 1792 of yacc.c */ -#line 112 "slmod_sparql_parser.y" - { - if (!ssp_slq->slq_allow_expr) { - yyerror("Spotlight queries with logic expressions are disabled"); - YYABORT; - } - if (strcmp((yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval)) != 0) - (yyval.sval) = talloc_asprintf(ssp_slq, "{ %s } UNION { %s }", (yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval)); - else - (yyval.sval) = talloc_asprintf(ssp_slq, "%s", (yyvsp[(1) - (3)].sval)); -} - break; - - case 12: -/* Line 1792 of yacc.c */ -#line 125 "slmod_sparql_parser.y" - {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '=', (yyvsp[(4) - (5)].sval));} - break; - - case 13: -/* Line 1792 of yacc.c */ -#line 126 "slmod_sparql_parser.y" - {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '!', (yyvsp[(4) - (5)].sval));} - break; - - case 14: -/* Line 1792 of yacc.c */ -#line 127 "slmod_sparql_parser.y" - {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '<', (yyvsp[(4) - (5)].sval));} - break; - - case 15: -/* Line 1792 of yacc.c */ -#line 128 "slmod_sparql_parser.y" - {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '>', (yyvsp[(4) - (5)].sval));} - break; - - case 16: -/* Line 1792 of yacc.c */ -#line 129 "slmod_sparql_parser.y" - {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '=', (yyvsp[(4) - (6)].sval));} - break; - - case 17: -/* Line 1792 of yacc.c */ -#line 130 "slmod_sparql_parser.y" - {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '!', (yyvsp[(4) - (6)].sval));} - break; - - case 18: -/* Line 1792 of yacc.c */ -#line 131 "slmod_sparql_parser.y" - {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '<', (yyvsp[(4) - (6)].sval));} - break; - - case 19: -/* Line 1792 of yacc.c */ -#line 132 "slmod_sparql_parser.y" - {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '>', (yyvsp[(4) - (6)].sval));} - break; - - case 20: -/* Line 1792 of yacc.c */ -#line 136 "slmod_sparql_parser.y" - {(yyval.sval) = map_daterange((yyvsp[(3) - (8)].sval), (yyvsp[(5) - (8)].tval), (yyvsp[(7) - (8)].tval));} - break; - - case 21: -/* Line 1792 of yacc.c */ -#line 140 "slmod_sparql_parser.y" - {(yyval.tval) = isodate2unix((yyvsp[(3) - (4)].sval));} - break; - - case 22: -/* Line 1792 of yacc.c */ -#line 141 "slmod_sparql_parser.y" - {(yyval.tval) = atoi((yyvsp[(1) - (1)].sval)) + SPRAW_TIME_OFFSET;} - break; - - -/* Line 1792 of yacc.c */ -#line 1602 "slmod_sparql_parser.c" - default: break; - } - /* User semantic actions sometimes alter yychar, and that requires - that yytoken be updated with the new translation. We take the - approach of translating immediately before every use of yytoken. - One alternative is translating here after every semantic action, - but that translation would be missed if the semantic action invokes - YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or - if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an - incorrect destructor might then be invoked immediately. In the - case of YYERROR or YYBACKUP, subsequent parser actions might lead - to an incorrect destructor call or verbose syntax error message - before the lookahead is translated. */ - YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); - - YYPOPSTACK (yylen); - yylen = 0; - YY_STACK_PRINT (yyss, yyssp); - - *++yyvsp = yyval; - - /* Now `shift' the result of the reduction. Determine what state - that goes to, based on the state we popped back to and the rule - number reduced by. */ - - yyn = yyr1[yyn]; - - yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; - if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) - yystate = yytable[yystate]; - else - yystate = yydefgoto[yyn - YYNTOKENS]; - - goto yynewstate; - - -/*------------------------------------. -| yyerrlab -- here on detecting error | -`------------------------------------*/ -yyerrlab: - /* Make sure we have latest lookahead translation. See comments at - user semantic actions for why this is necessary. */ - yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); - - /* If not already recovering from an error, report this error. */ - if (!yyerrstatus) - { - ++yynerrs; -#if ! YYERROR_VERBOSE - yyerror (YY_("syntax error")); -#else -# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ - yyssp, yytoken) - { - char const *yymsgp = YY_("syntax error"); - int yysyntax_error_status; - yysyntax_error_status = YYSYNTAX_ERROR; - if (yysyntax_error_status == 0) - yymsgp = yymsg; - else if (yysyntax_error_status == 1) - { - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); - if (!yymsg) - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - yysyntax_error_status = 2; - } - else - { - yysyntax_error_status = YYSYNTAX_ERROR; - yymsgp = yymsg; - } - } - yyerror (yymsgp); - if (yysyntax_error_status == 2) - goto yyexhaustedlab; - } -# undef YYSYNTAX_ERROR -#endif - } - - - - if (yyerrstatus == 3) - { - /* If just tried and failed to reuse lookahead token after an - error, discard it. */ - - if (yychar <= YYEOF) - { - /* Return failure if at end of input. */ - if (yychar == YYEOF) - YYABORT; - } - else - { - yydestruct ("Error: discarding", - yytoken, &yylval); - yychar = YYEMPTY; - } - } - - /* Else will try to reuse lookahead token after shifting the error - token. */ - goto yyerrlab1; - - -/*---------------------------------------------------. -| yyerrorlab -- error raised explicitly by YYERROR. | -`---------------------------------------------------*/ -yyerrorlab: - - /* Pacify compilers like GCC when the user code never invokes - YYERROR and the label yyerrorlab therefore never appears in user - code. */ - if (/*CONSTCOND*/ 0) - goto yyerrorlab; - - /* Do not reclaim the symbols of the rule which action triggered - this YYERROR. */ - YYPOPSTACK (yylen); - yylen = 0; - YY_STACK_PRINT (yyss, yyssp); - yystate = *yyssp; - goto yyerrlab1; - - -/*-------------------------------------------------------------. -| yyerrlab1 -- common code for both syntax error and YYERROR. | -`-------------------------------------------------------------*/ -yyerrlab1: - yyerrstatus = 3; /* Each real token shifted decrements this. */ - - for (;;) - { - yyn = yypact[yystate]; - if (!yypact_value_is_default (yyn)) - { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) - { - yyn = yytable[yyn]; - if (0 < yyn) - break; - } - } - - /* Pop the current state because it cannot handle the error token. */ - if (yyssp == yyss) - YYABORT; - - - yydestruct ("Error: popping", - yystos[yystate], yyvsp); - YYPOPSTACK (1); - yystate = *yyssp; - YY_STACK_PRINT (yyss, yyssp); - } - - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - *++yyvsp = yylval; - YY_IGNORE_MAYBE_UNINITIALIZED_END - - - /* Shift the error token. */ - YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); - - yystate = yyn; - goto yynewstate; - - -/*-------------------------------------. -| yyacceptlab -- YYACCEPT comes here. | -`-------------------------------------*/ -yyacceptlab: - yyresult = 0; - goto yyreturn; - -/*-----------------------------------. -| yyabortlab -- YYABORT comes here. | -`-----------------------------------*/ -yyabortlab: - yyresult = 1; - goto yyreturn; - -#if !defined yyoverflow || YYERROR_VERBOSE -/*-------------------------------------------------. -| yyexhaustedlab -- memory exhaustion comes here. | -`-------------------------------------------------*/ -yyexhaustedlab: - yyerror (YY_("memory exhausted")); - yyresult = 2; - /* Fall through. */ -#endif - -yyreturn: - if (yychar != YYEMPTY) - { - /* Make sure we have latest lookahead translation. See comments at - user semantic actions for why this is necessary. */ - yytoken = YYTRANSLATE (yychar); - yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval); - } - /* Do not reclaim the symbols of the rule which action triggered - this YYABORT or YYACCEPT. */ - YYPOPSTACK (yylen); - YY_STACK_PRINT (yyss, yyssp); - while (yyssp != yyss) - { - yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp); - YYPOPSTACK (1); - } -#ifndef yyoverflow - if (yyss != yyssa) - YYSTACK_FREE (yyss); -#endif -#if YYERROR_VERBOSE - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); -#endif - /* Make sure YYID is used. */ - return YYID (yyresult); -} - - -/* Line 2055 of yacc.c */ -#line 144 "slmod_sparql_parser.y" - - -static time_t isodate2unix(const char *s) -{ - struct tm tm; - - if (strptime(s, "%Y-%m-%dT%H:%M:%SZ", &tm) == NULL) - return (time_t)-1; - return mktime(&tm); -} - -static const char *map_daterange(const char *dateattr, time_t date1, time_t date2) -{ - EC_INIT; - char *result = NULL; - struct spotlight_sparql_map *p; - struct tm *tmp; - char buf1[64], buf2[64]; - - EC_NULL_LOG( tmp = localtime(&date1) ); - strftime(buf1, sizeof(buf1), "%Y-%m-%dT%H:%M:%SZ", tmp); - EC_NULL_LOG( tmp = localtime(&date2) ); - strftime(buf2, sizeof(buf2), "%Y-%m-%dT%H:%M:%SZ", tmp); - - for (p = spotlight_sparql_map; p->ssm_spotlight_attr; p++) { - if (strcmp(dateattr, p->ssm_spotlight_attr) == 0) { - result = talloc_asprintf(ssp_slq, - "?obj %s ?%c FILTER (?%c > '%s' && ?%c < '%s')", - p->ssm_sparql_attr, - sparqlvar, - sparqlvar, - buf1, - sparqlvar, - buf2); - sparqlvar++; - break; - } - } - -EC_CLEANUP: - if (ret != 0) - return NULL; - return result; -} - -static char *map_type_search(const char *attr, char op, const char *val) -{ - char *result = NULL; - const char *sparqlAttr; - - for (struct MDTypeMap *p = MDTypeMap; p->mdtm_value; p++) { - if (strcmp(p->mdtm_value, val) == 0) { - switch (p->mdtm_type) { - case kMDTypeMapRDF: - sparqlAttr = "rdf:type"; - break; - case kMDTypeMapMime: - sparqlAttr = "nie:mimeType"; - break; - default: - return NULL; - } - result = talloc_asprintf(ssp_slq, "?obj %s '%s'", - sparqlAttr, - p->mdtm_sparql); - break; - } - } - return result; -} - -static const char *map_expr(const char *attr, char op, const char *val) -{ - EC_INIT; - char *result = NULL; - struct spotlight_sparql_map *p; - time_t t; - struct tm *tmp; - char buf1[64]; - bstring q = NULL, search = NULL, replace = NULL; - - for (p = spotlight_sparql_map; p->ssm_spotlight_attr; p++) { - if (p->ssm_enabled && (strcmp(p->ssm_spotlight_attr, attr) == 0)) { - if (p->ssm_type != ssmt_type && p->ssm_sparql_attr == NULL) { - yyerror("unsupported Spotlight attribute"); - EC_FAIL; - } - switch (p->ssm_type) { - case ssmt_bool: - result = talloc_asprintf(ssp_slq, "?obj %s '%s'", p->ssm_sparql_attr, val); - break; - case ssmt_num: - result = talloc_asprintf(ssp_slq, "?obj %s ?%c FILTER(?%c %c%c '%s')", - p->ssm_sparql_attr, - sparqlvar, - sparqlvar, - op, - op == '!' ? '=' : ' ', /* append '=' to '!' */ - val); - sparqlvar++; - break; - case ssmt_str: - q = bformat("^%s$", val); - search = bfromcstr("*"); - replace = bfromcstr(".*"); - bfindreplace(q, search, replace, 0); - result = talloc_asprintf(ssp_slq, "?obj %s ?%c FILTER(regex(?%c, '%s'))", - p->ssm_sparql_attr, - sparqlvar, - sparqlvar, - bdata(q)); - sparqlvar++; - break; - case ssmt_fts: - result = talloc_asprintf(ssp_slq, "?obj %s '%s'", p->ssm_sparql_attr, val); - break; - case ssmt_date: - t = atoi(val) + SPRAW_TIME_OFFSET; - EC_NULL( tmp = localtime(&t) ); - strftime(buf1, sizeof(buf1), "%Y-%m-%dT%H:%M:%SZ", tmp); - result = talloc_asprintf(ssp_slq, "?obj %s ?%c FILTER(?%c %c '%s')", - p->ssm_sparql_attr, - sparqlvar, - sparqlvar, - op, - buf1); - sparqlvar++; - break; - case ssmt_type: - result = map_type_search(attr, op, val); - break; - default: - EC_FAIL; - } - break; - } - } - -EC_CLEANUP: - if (q) - bdestroy(q); - if (search) - bdestroy(search); - if (replace) - bdestroy(replace); - return result; -} - -void yyerror(const char *str) -{ -#ifdef MAIN - printf("yyerror: %s\n", str); -#else - LOG(log_error, logtype_sl, "yyerror: %s", str); -#endif -} - -int yywrap() -{ - return 1; -} - -/** - * Map a Spotlight RAW query string to a SPARQL query string - * - * @param[in] slq Spotlight query handle - * @param[out] sparql_result Mapped SPARQL query, string is allocated in - * talloc context of slq - * @return 0 on success, -1 on error - **/ -int map_spotlight_to_sparql_query(slq_t *slq, gchar **sparql_result) -{ - EC_INIT; - YY_BUFFER_STATE s = NULL; - ssp_result = NULL; - - ssp_slq = slq; - s = yy_scan_string(slq->slq_qstring); - sparqlvar = 'a'; - - EC_ZERO( yyparse() ); - -EC_CLEANUP: - if (s) - yy_delete_buffer(s); - if (ret == 0) - *sparql_result = ssp_result; - else - *sparql_result = NULL; - EC_EXIT; -} - -#ifdef MAIN -int main(int argc, char **argv) -{ - int ret; - YY_BUFFER_STATE s; - - if (argc != 2) { - printf("usage: %s QUERY\n", argv[0]); - return 1; - } - - ssp_slq = talloc_zero(NULL, slq_t); - struct vol *vol = talloc_zero(ssp_slq, struct vol); - vol->v_path = "/Volumes/test"; - ssp_slq->slq_vol = vol; - ssp_slq->slq_allow_expr = true; - sparqlvar = 'a'; - - s = yy_scan_string(argv[1]); - - ret = yyparse(); - - yy_delete_buffer(s); - - if (ret == 0) - printf("SPARQL: %s\n", ssp_result ? ssp_result : "(empty)"); - - return 0; -} -#endif diff --git a/etc/spotlight/slmod_sparql_parser.h b/etc/spotlight/slmod_sparql_parser.h deleted file mode 100644 index 9eb22b37..00000000 --- a/etc/spotlight/slmod_sparql_parser.h +++ /dev/null @@ -1,130 +0,0 @@ -/* A Bison parser, made by GNU Bison 2.7. */ - -/* Bison interface for Yacc-like parsers in C - - Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -/* As a special exception, you may create a larger work that contains - part or all of the Bison parser skeleton and distribute that work - under terms of your choice, so long as that work isn't itself a - parser generator using the skeleton or a modified version thereof - as a parser skeleton. Alternatively, if you modify or redistribute - the parser skeleton itself, you may (at your option) remove this - special exception, which will cause the skeleton and the resulting - Bison output files to be licensed under the GNU General Public - License without this special exception. - - This special exception was added by the Free Software Foundation in - version 2.2 of Bison. */ - -#ifndef YY_YY_SLMOD_SPARQL_PARSER_H_INCLUDED -# define YY_YY_SLMOD_SPARQL_PARSER_H_INCLUDED -/* Enabling traces. */ -#ifndef YYDEBUG -# define YYDEBUG 0 -#endif -#if YYDEBUG -extern int yydebug; -#endif - -/* Tokens. */ -#ifndef YYTOKENTYPE -# define YYTOKENTYPE - /* Put the tokens into the symbol table, so that GDB and other debuggers - know about them. */ - enum yytokentype { - WORD = 258, - BOOL = 259, - FUNC_INRANGE = 260, - DATE_ISO = 261, - OBRACE = 262, - CBRACE = 263, - EQUAL = 264, - UNEQUAL = 265, - GT = 266, - LT = 267, - COMMA = 268, - QUOTE = 269, - AND = 270, - OR = 271 - }; -#endif -/* Tokens. */ -#define WORD 258 -#define BOOL 259 -#define FUNC_INRANGE 260 -#define DATE_ISO 261 -#define OBRACE 262 -#define CBRACE 263 -#define EQUAL 264 -#define UNEQUAL 265 -#define GT 266 -#define LT 267 -#define COMMA 268 -#define QUOTE 269 -#define AND 270 -#define OR 271 - - - -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED -typedef union YYSTYPE -{ -/* Line 2058 of yacc.c */ -#line 46 "slmod_sparql_parser.y" - - int ival; - const char *sval; - bool bval; - time_t tval; - - -/* Line 2058 of yacc.c */ -#line 97 "slmod_sparql_parser.h" -} YYSTYPE; -# define YYSTYPE_IS_TRIVIAL 1 -# define yystype YYSTYPE /* obsolescent; will be withdrawn */ -# define YYSTYPE_IS_DECLARED 1 -#endif - -extern YYSTYPE yylval; - -#ifdef YYPARSE_PARAM -#if defined __STDC__ || defined __cplusplus -int yyparse (void *YYPARSE_PARAM); -#else -int yyparse (); -#endif -#else /* ! YYPARSE_PARAM */ -#if defined __STDC__ || defined __cplusplus -int yyparse (void); -#else -int yyparse (); -#endif -#endif /* ! YYPARSE_PARAM */ -/* "%code provides" blocks. */ -/* Line 2058 of yacc.c */ -#line 40 "slmod_sparql_parser.y" - - #define SPRAW_TIME_OFFSET 978307200 - extern int map_spotlight_to_sparql_query(slq_t *slq, gchar **sparql_result); - extern slq_t *ssp_slq; - - -/* Line 2058 of yacc.c */ -#line 129 "slmod_sparql_parser.h" - -#endif /* !YY_YY_SLMOD_SPARQL_PARSER_H_INCLUDED */ diff --git a/etc/spotlight/slmod_sparql_parser.y b/etc/spotlight/slmod_sparql_parser.y deleted file mode 100644 index 76d8b5a7..00000000 --- a/etc/spotlight/slmod_sparql_parser.y +++ /dev/null @@ -1,365 +0,0 @@ -%{ - #include - - #include - #include - #include - #include - - #include - - #include - #include - #include - #include - - #include "slmod_sparql_map.h" - - struct yy_buffer_state; - typedef struct yy_buffer_state *YY_BUFFER_STATE; - extern int yylex (void); - extern void yyerror (char const *); - extern void *yyterminate(void); - extern YY_BUFFER_STATE yy_scan_string( const char *str); - extern void yy_delete_buffer ( YY_BUFFER_STATE buffer ); - - /* forward declarations */ - static const char *map_expr(const char *attr, char op, const char *val); - static const char *map_daterange(const char *dateattr, time_t date1, time_t date2); - static time_t isodate2unix(const char *s); - - /* global vars, eg needed by the lexer */ - slq_t *ssp_slq; - - /* local vars */ - static gchar *ssp_result; - static char sparqlvar; - static char *result_limit; -%} - -%code provides { - #define SPRAW_TIME_OFFSET 978307200 - extern int map_spotlight_to_sparql_query(slq_t *slq, gchar **sparql_result); - extern slq_t *ssp_slq; -} - -%union { - int ival; - const char *sval; - bool bval; - time_t tval; -} - -%expect 5 -%error-verbose - -%type match expr line function -%type date - -%token WORD -%token BOOL -%token FUNC_INRANGE -%token DATE_ISO -%token OBRACE CBRACE EQUAL UNEQUAL GT LT COMMA QUOTE -%left AND -%left OR -%% - -input: -/* empty */ -| input line -; - -line: -expr { - if (ssp_slq->slq_result_limit) - result_limit = talloc_asprintf(ssp_slq, "LIMIT %ld", ssp_slq->slq_result_limit); - else - result_limit = ""; - ssp_result = talloc_asprintf(ssp_slq, - "SELECT ?url WHERE " - "{ %s . ?obj nie:url ?url . FILTER(tracker:uri-is-descendant('file://%s/', ?url)) } %s", - $1, ssp_slq->slq_vol->v_path, result_limit); - $$ = ssp_result; -} -; - -expr: -BOOL { - if ($1 == false) - YYACCEPT; - else - YYABORT; -} -| match OR match { - if ($1 == NULL || $3 == NULL) - YYABORT; - if (strcmp($1, $3) != 0) - $$ = talloc_asprintf(ssp_slq, "{ %s } UNION { %s }", $1, $3); - else - $$ = talloc_asprintf(ssp_slq, "%s", $1); -} -| match {$$ = $1; if ($$ == NULL) YYABORT;} -| function {$$ = $1;} -| OBRACE expr CBRACE {$$ = talloc_asprintf(ssp_slq, "%s", $2);} -| expr AND expr { - if (!ssp_slq->slq_allow_expr) { - yyerror("Spotlight queries with logic expressions are disabled"); - YYABORT; - } - $$ = talloc_asprintf(ssp_slq, "%s . %s", $1, $3); -} -| expr OR expr { - if (!ssp_slq->slq_allow_expr) { - yyerror("Spotlight queries with logic expressions are disabled"); - YYABORT; - } - if (strcmp($1, $3) != 0) - $$ = talloc_asprintf(ssp_slq, "{ %s } UNION { %s }", $1, $3); - else - $$ = talloc_asprintf(ssp_slq, "%s", $1); -} -; - -match: -WORD EQUAL QUOTE WORD QUOTE {$$ = map_expr($1, '=', $4);} -| WORD UNEQUAL QUOTE WORD QUOTE {$$ = map_expr($1, '!', $4);} -| WORD LT QUOTE WORD QUOTE {$$ = map_expr($1, '<', $4);} -| WORD GT QUOTE WORD QUOTE {$$ = map_expr($1, '>', $4);} -| WORD EQUAL QUOTE WORD QUOTE WORD {$$ = map_expr($1, '=', $4);} -| WORD UNEQUAL QUOTE WORD QUOTE WORD {$$ = map_expr($1, '!', $4);} -| WORD LT QUOTE WORD QUOTE WORD {$$ = map_expr($1, '<', $4);} -| WORD GT QUOTE WORD QUOTE WORD {$$ = map_expr($1, '>', $4);} -; - -function: -FUNC_INRANGE OBRACE WORD COMMA date COMMA date CBRACE {$$ = map_daterange($3, $5, $7);} -; - -date: -DATE_ISO OBRACE WORD CBRACE {$$ = isodate2unix($3);} -| WORD {$$ = atoi($1) + SPRAW_TIME_OFFSET;} -; - -%% - -static time_t isodate2unix(const char *s) -{ - struct tm tm; - - if (strptime(s, "%Y-%m-%dT%H:%M:%SZ", &tm) == NULL) - return (time_t)-1; - return mktime(&tm); -} - -static const char *map_daterange(const char *dateattr, time_t date1, time_t date2) -{ - EC_INIT; - char *result = NULL; - struct spotlight_sparql_map *p; - struct tm *tmp; - char buf1[64], buf2[64]; - - EC_NULL_LOG( tmp = localtime(&date1) ); - strftime(buf1, sizeof(buf1), "%Y-%m-%dT%H:%M:%SZ", tmp); - EC_NULL_LOG( tmp = localtime(&date2) ); - strftime(buf2, sizeof(buf2), "%Y-%m-%dT%H:%M:%SZ", tmp); - - for (p = spotlight_sparql_map; p->ssm_spotlight_attr; p++) { - if (strcmp(dateattr, p->ssm_spotlight_attr) == 0) { - result = talloc_asprintf(ssp_slq, - "?obj %s ?%c FILTER (?%c > '%s' && ?%c < '%s')", - p->ssm_sparql_attr, - sparqlvar, - sparqlvar, - buf1, - sparqlvar, - buf2); - sparqlvar++; - break; - } - } - -EC_CLEANUP: - if (ret != 0) - return NULL; - return result; -} - -static char *map_type_search(const char *attr, char op, const char *val) -{ - char *result = NULL; - const char *sparqlAttr; - - for (struct MDTypeMap *p = MDTypeMap; p->mdtm_value; p++) { - if (strcmp(p->mdtm_value, val) == 0) { - switch (p->mdtm_type) { - case kMDTypeMapRDF: - sparqlAttr = "rdf:type"; - break; - case kMDTypeMapMime: - sparqlAttr = "nie:mimeType"; - break; - default: - return NULL; - } - result = talloc_asprintf(ssp_slq, "?obj %s '%s'", - sparqlAttr, - p->mdtm_sparql); - break; - } - } - return result; -} - -static const char *map_expr(const char *attr, char op, const char *val) -{ - EC_INIT; - char *result = NULL; - struct spotlight_sparql_map *p; - time_t t; - struct tm *tmp; - char buf1[64]; - bstring q = NULL, search = NULL, replace = NULL; - - for (p = spotlight_sparql_map; p->ssm_spotlight_attr; p++) { - if (p->ssm_enabled && (strcmp(p->ssm_spotlight_attr, attr) == 0)) { - if (p->ssm_type != ssmt_type && p->ssm_sparql_attr == NULL) { - yyerror("unsupported Spotlight attribute"); - EC_FAIL; - } - switch (p->ssm_type) { - case ssmt_bool: - result = talloc_asprintf(ssp_slq, "?obj %s '%s'", p->ssm_sparql_attr, val); - break; - case ssmt_num: - result = talloc_asprintf(ssp_slq, "?obj %s ?%c FILTER(?%c %c%c '%s')", - p->ssm_sparql_attr, - sparqlvar, - sparqlvar, - op, - op == '!' ? '=' : ' ', /* append '=' to '!' */ - val); - sparqlvar++; - break; - case ssmt_str: - q = bformat("^%s$", val); - search = bfromcstr("*"); - replace = bfromcstr(".*"); - bfindreplace(q, search, replace, 0); - result = talloc_asprintf(ssp_slq, "?obj %s ?%c FILTER(regex(?%c, '%s'))", - p->ssm_sparql_attr, - sparqlvar, - sparqlvar, - bdata(q)); - sparqlvar++; - break; - case ssmt_fts: - result = talloc_asprintf(ssp_slq, "?obj %s '%s'", p->ssm_sparql_attr, val); - break; - case ssmt_date: - t = atoi(val) + SPRAW_TIME_OFFSET; - EC_NULL( tmp = localtime(&t) ); - strftime(buf1, sizeof(buf1), "%Y-%m-%dT%H:%M:%SZ", tmp); - result = talloc_asprintf(ssp_slq, "?obj %s ?%c FILTER(?%c %c '%s')", - p->ssm_sparql_attr, - sparqlvar, - sparqlvar, - op, - buf1); - sparqlvar++; - break; - case ssmt_type: - result = map_type_search(attr, op, val); - break; - default: - EC_FAIL; - } - break; - } - } - -EC_CLEANUP: - if (q) - bdestroy(q); - if (search) - bdestroy(search); - if (replace) - bdestroy(replace); - return result; -} - -void yyerror(const char *str) -{ -#ifdef MAIN - printf("yyerror: %s\n", str); -#else - LOG(log_error, logtype_sl, "yyerror: %s", str); -#endif -} - -int yywrap() -{ - return 1; -} - -/** - * Map a Spotlight RAW query string to a SPARQL query string - * - * @param[in] slq Spotlight query handle - * @param[out] sparql_result Mapped SPARQL query, string is allocated in - * talloc context of slq - * @return 0 on success, -1 on error - **/ -int map_spotlight_to_sparql_query(slq_t *slq, gchar **sparql_result) -{ - EC_INIT; - YY_BUFFER_STATE s = NULL; - ssp_result = NULL; - - ssp_slq = slq; - s = yy_scan_string(slq->slq_qstring); - sparqlvar = 'a'; - - EC_ZERO( yyparse() ); - -EC_CLEANUP: - if (s) - yy_delete_buffer(s); - if (ret == 0) - *sparql_result = ssp_result; - else - *sparql_result = NULL; - EC_EXIT; -} - -#ifdef MAIN -int main(int argc, char **argv) -{ - int ret; - YY_BUFFER_STATE s; - - if (argc != 2) { - printf("usage: %s QUERY\n", argv[0]); - return 1; - } - - ssp_slq = talloc_zero(NULL, slq_t); - struct vol *vol = talloc_zero(ssp_slq, struct vol); - vol->v_path = "/Volumes/test"; - ssp_slq->slq_vol = vol; - ssp_slq->slq_allow_expr = true; - sparqlvar = 'a'; - - s = yy_scan_string(argv[1]); - - ret = yyparse(); - - yy_delete_buffer(s); - - if (ret == 0) - printf("SPARQL: %s\n", ssp_result ? ssp_result : "(empty)"); - - return 0; -} -#endif diff --git a/etc/spotlight/sparql_map.c b/etc/spotlight/sparql_map.c new file mode 100644 index 00000000..3a0e4691 --- /dev/null +++ b/etc/spotlight/sparql_map.c @@ -0,0 +1,136 @@ +/* + Copyright (c) 2012 Frank Lahm + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include + +#include + +#include "sparql_map.h" + +#define NOTSUPPORTED NULL +#define SPECIAL NULL + +struct spotlight_sparql_map spotlight_sparql_map[] = { + /* ssm_spotlight_attr ssm_enabled, ssm_type, ssm_sparql_attr */ + {"*", true, ssmt_fts, "fts:match"}, + + /* Filesystem metadata */ + {"kMDItemFSLabel", true, ssmt_num, NOTSUPPORTED}, + {"kMDItemDisplayName", true, ssmt_str, "nfo:fileName"}, + {"kMDItemFSName", true, ssmt_str, "nfo:fileName"}, + {"kMDItemFSContentChangeDate", true, ssmt_date, "nfo:fileLastModified"}, + + /* Common metadata */ + {"kMDItemTextContent", true, ssmt_fts, "fts:match"}, + {"kMDItemContentCreationDate", true, ssmt_date, "nie:contentCreated"}, + {"kMDItemContentModificationDate", true, ssmt_date, "nfo:fileLastModified"}, + {"kMDItemAttributeChangeDate", true, ssmt_date, "nfo:fileLastModified"}, + {"kMDItemLastUsedDate", true, ssmt_date, "nfo:fileLastAccessed"}, + {"kMDItemAuthors", true, ssmt_str, "dc:creator"}, + {"kMDItemCopyright", true, ssmt_str, "nie:copyright"}, + {"kMDItemCountry", true, ssmt_str, "nco:country"}, + {"kMDItemCreator", true, ssmt_str, "dc:creator"}, + {"kMDItemDurationSeconds", true, ssmt_num, "nfo:duration"}, + {"kMDItemNumberOfPages", true, ssmt_num, "nfo:pageCount"}, + {"kMDItemTitle", true, ssmt_str, "nie:title"}, + {"_kMDItemGroupId", true, ssmt_type, SPECIAL}, + {"kMDItemContentTypeTree", true, ssmt_type, SPECIAL}, + + /* Image metadata */ + {"kMDItemPixelWidth", true, ssmt_num, "nfo:width"}, + {"kMDItemPixelHeight", true, ssmt_num, "nfo:height"}, + {"kMDItemColorSpace", true, ssmt_str, "nexif:colorSpace"}, + {"kMDItemBitsPerSample", true, ssmt_num, "nfo:colorDepth"}, + {"kMDItemFocalLength", true, ssmt_num, "nmm:focalLength"}, + {"kMDItemISOSpeed", true, ssmt_num, "nmm:isoSpeed"}, + {"kMDItemOrientation", true, ssmt_bool, "nfo:orientation"}, + {"kMDItemResolutionWidthDPI", true, ssmt_num, "nfo:horizontalResolution"}, + {"kMDItemResolutionHeightDPI", true, ssmt_num, "nfo:verticalResolution"}, + {"kMDItemExposureTimeSeconds", true, ssmt_num, "nmm:exposureTime"}, + + /* Audio metadata */ + {"kMDItemComposer", true, ssmt_str, "nmm:composer"}, + {"kMDItemMusicalGenre", true, ssmt_str, "nfo:genre"}, + + {NULL, false, ssmt_str, NULL} +}; + +struct MDTypeMap MDTypeMap[] = { + {"1", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nmo#Email"}, + {"2", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nco#Contact"}, + {"3", kMDTypeMapNotSup, NULL}, /* PrefPane */ + {"4", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Font"}, + {"5", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Bookmark"}, + {"6", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nco#Contact"}, + {"7", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Video"}, + {"8", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Executable"}, + {"9", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Folder"}, + {"10", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Audio"}, + {"11", kMDTypeMapMime, "application/pdf"}, + {"12", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Presentation"}, + {"13", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Image"}, + {"public.jpeg", kMDTypeMapMime, "image/jpeg"}, + {"public.tiff", kMDTypeMapMime, "image/tiff"}, + {"com.compuserve.gif", kMDTypeMapMime, "image/gif"}, + {"public.png", kMDTypeMapMime, "image/png"}, + {"com.microsoft.bmp", kMDTypeMapMime, "image/bmp"}, + {"public.content", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Document"}, + {"public.mp3", kMDTypeMapMime, "audio/mpeg"}, + {"public.mpeg-4-audio", kMDTypeMapMime, "audio/x-aac"}, + {"com.apple.application", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Software"}, + {"public.text", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#TextDocument"}, + {"public.plain-text", kMDTypeMapMime, "text/plain"}, + {"public.rtf", kMDTypeMapMime, "text/rtf"}, + {"public.html", kMDTypeMapMime, "text/html"}, + {"public.xml", kMDTypeMapMime, "text/xml"}, + {"public.source-code", kMDTypeMapRDF, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#SourceCode"}, + {NULL, kMDTypeMapNotSup, NULL} +}; + +void configure_spotlight_attributes(const char *attributes_in) +{ + char *attr, *attributes; + int i; + + for (i = 0; spotlight_sparql_map[i].ssm_spotlight_attr != NULL; i++) + spotlight_sparql_map[i].ssm_enabled = false; + + /* + * Go through the attribute map and for every element scan + * attributes_in with strtok(). If it's contained, keep it + * enabled, otherwise disable it. + */ + + attributes = strdup(attributes_in); + + for (attr = strtok(attributes, ","); attr; attr = strtok(NULL, ",")) { + + for (i = 0; spotlight_sparql_map[i].ssm_spotlight_attr != NULL; i++) + + if (strcmp(attr, spotlight_sparql_map[i].ssm_spotlight_attr) == 0) { + LOG(log_info, logtype_sl, "Enabling Spotlight attribute: %s", + spotlight_sparql_map[i].ssm_spotlight_attr); + spotlight_sparql_map[i].ssm_enabled = true; + break; + } + } + + free(attributes); +} diff --git a/etc/spotlight/sparql_map.h b/etc/spotlight/sparql_map.h new file mode 100644 index 00000000..3b924740 --- /dev/null +++ b/etc/spotlight/sparql_map.h @@ -0,0 +1,53 @@ +/* + Copyright (c) 2012 Frank Lahm + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#ifndef SPOTLIGHT_SPARQL_MAP_H +#define SPOTLIGHT_SPARQL_MAP_H + +enum ssm_type { + ssmt_bool, /* a boolean value that doesn't requires a SPARQL FILTER */ + ssmt_num, /* a numeric value that requires a SPARQL FILTER */ + ssmt_str, /* a string value that requieres a SPARQL FILTER */ + ssmt_fts, /* a string value that will be queried with SPARQL 'fts:match' */ + ssmt_date, /* date values are handled in a special map function map_daterange() */ + ssmt_type /* kMDItemContentType, requires special mapping */ +}; + +enum kMDTypeMap { + kMDTypeMapNotSup, /* not supported */ + kMDTypeMapRDF, /* query with rdf:type */ + kMDTypeMapMime /* query with nie:mimeType */ +}; + +struct spotlight_sparql_map { + const char *ssm_spotlight_attr; + bool ssm_enabled; + enum ssm_type ssm_type; + const char *ssm_sparql_attr; +}; + +struct MDTypeMap { + const char *mdtm_value; /* MD query value of attributes '_kMDItemGroupId' and 'kMDItemContentTypeTree' */ + enum kMDTypeMap mdtm_type; /* whether SPARQL query must search attribute rdf:type or nie:mime_Type */ + const char *mdtm_sparql; /* the SPARQL query match string */ +}; + +extern struct spotlight_sparql_map spotlight_sparql_map[]; +extern struct spotlight_sparql_map spotlight_sparql_date_map[]; +extern struct MDTypeMap MDTypeMap[]; +#endif diff --git a/etc/spotlight/sparql_parser.c b/etc/spotlight/sparql_parser.c new file mode 100644 index 00000000..77fa9e50 --- /dev/null +++ b/etc/spotlight/sparql_parser.c @@ -0,0 +1,2062 @@ +/* A Bison parser, made by GNU Bison 2.7. */ + +/* Bison implementation for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* C LALR(1) parser skeleton written by Richard Stallman, by + simplifying the original so-called "semantic" parser. */ + +/* All symbols defined below should begin with yy or YY, to avoid + infringing on user name space. This should be done even for local + variables, as they might otherwise be expanded by user macros. + There are some unavoidable exceptions within include files to + define necessary library symbols; they are noted "INFRINGES ON + USER NAME SPACE" below. */ + +/* Identify Bison output. */ +#define YYBISON 1 + +/* Bison version. */ +#define YYBISON_VERSION "2.7" + +/* Skeleton name. */ +#define YYSKELETON_NAME "yacc.c" + +/* Pure parsers. */ +#define YYPURE 0 + +/* Push parsers. */ +#define YYPUSH 0 + +/* Pull parsers. */ +#define YYPULL 1 + + + + +/* Copy the first part of user declarations. */ +/* Line 371 of yacc.c */ +#line 1 "sparql_parser.y" + + #include + + #include + #include + #include + #include + + #include + + #include + #include + #include + #include + + #include "sparql_map.h" + + struct yy_buffer_state; + typedef struct yy_buffer_state *YY_BUFFER_STATE; + extern int yylex (void); + extern void yyerror (char const *); + extern void *yyterminate(void); + extern YY_BUFFER_STATE yy_scan_string( const char *str); + extern void yy_delete_buffer ( YY_BUFFER_STATE buffer ); + + /* forward declarations */ + static const char *map_expr(const char *attr, char op, const char *val); + static const char *map_daterange(const char *dateattr, time_t date1, time_t date2); + static time_t isodate2unix(const char *s); + + /* global vars, eg needed by the lexer */ + slq_t *ssp_slq; + + /* local vars */ + static gchar *ssp_result; + static char sparqlvar; + static char *result_limit; + +/* Line 371 of yacc.c */ +#line 107 "sparql_parser.c" + +# ifndef YY_NULL +# if defined __cplusplus && 201103L <= __cplusplus +# define YY_NULL nullptr +# else +# define YY_NULL 0 +# endif +# endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE 1 +#endif + +/* In a future release of Bison, this section will be replaced + by #include "y.tab.h". */ +#ifndef YY_YY_SPARQL_PARSER_H_INCLUDED +# define YY_YY_SPARQL_PARSER_H_INCLUDED +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int yydebug; +#endif + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + WORD = 258, + BOOL = 259, + FUNC_INRANGE = 260, + DATE_ISO = 261, + OBRACE = 262, + CBRACE = 263, + EQUAL = 264, + UNEQUAL = 265, + GT = 266, + LT = 267, + COMMA = 268, + QUOTE = 269, + AND = 270, + OR = 271 + }; +#endif +/* Tokens. */ +#define WORD 258 +#define BOOL 259 +#define FUNC_INRANGE 260 +#define DATE_ISO 261 +#define OBRACE 262 +#define CBRACE 263 +#define EQUAL 264 +#define UNEQUAL 265 +#define GT 266 +#define LT 267 +#define COMMA 268 +#define QUOTE 269 +#define AND 270 +#define OR 271 + + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +{ +/* Line 387 of yacc.c */ +#line 46 "sparql_parser.y" + + int ival; + const char *sval; + bool bval; + time_t tval; + + +/* Line 387 of yacc.c */ +#line 190 "sparql_parser.c" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + +extern YYSTYPE yylval; + +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int yyparse (void *YYPARSE_PARAM); +#else +int yyparse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int yyparse (void); +#else +int yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ +/* "%code provides" blocks. */ +/* Line 387 of yacc.c */ +#line 40 "sparql_parser.y" + + #define SPRAW_TIME_OFFSET 978307200 + extern int map_spotlight_to_sparql_query(slq_t *slq, gchar **sparql_result); + extern slq_t *ssp_slq; + + +/* Line 387 of yacc.c */ +#line 222 "sparql_parser.c" + +#endif /* !YY_YY_SPARQL_PARSER_H_INCLUDED */ + +/* Copy the second part of user declarations. */ + +/* Line 390 of yacc.c */ +#line 229 "sparql_parser.c" + +#ifdef short +# undef short +#endif + +#ifdef YYTYPE_UINT8 +typedef YYTYPE_UINT8 yytype_uint8; +#else +typedef unsigned char yytype_uint8; +#endif + +#ifdef YYTYPE_INT8 +typedef YYTYPE_INT8 yytype_int8; +#elif (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +typedef signed char yytype_int8; +#else +typedef short int yytype_int8; +#endif + +#ifdef YYTYPE_UINT16 +typedef YYTYPE_UINT16 yytype_uint16; +#else +typedef unsigned short int yytype_uint16; +#endif + +#ifdef YYTYPE_INT16 +typedef YYTYPE_INT16 yytype_int16; +#else +typedef short int yytype_int16; +#endif + +#ifndef YYSIZE_T +# ifdef __SIZE_TYPE__ +# define YYSIZE_T __SIZE_TYPE__ +# elif defined size_t +# define YYSIZE_T size_t +# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# else +# define YYSIZE_T unsigned int +# endif +#endif + +#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) + +#ifndef YY_ +# if defined YYENABLE_NLS && YYENABLE_NLS +# if ENABLE_NLS +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_(Msgid) dgettext ("bison-runtime", Msgid) +# endif +# endif +# ifndef YY_ +# define YY_(Msgid) Msgid +# endif +#endif + +/* Suppress unused-variable warnings by "using" E. */ +#if ! defined lint || defined __GNUC__ +# define YYUSE(E) ((void) (E)) +#else +# define YYUSE(E) /* empty */ +#endif + +/* Identity function, used to suppress warnings about constant conditions. */ +#ifndef lint +# define YYID(N) (N) +#else +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static int +YYID (int yyi) +#else +static int +YYID (yyi) + int yyi; +#endif +{ + return yyi; +} +#endif + +#if ! defined yyoverflow || YYERROR_VERBOSE + +/* The parser invokes alloca or malloc; define the necessary symbols. */ + +# ifdef YYSTACK_USE_ALLOCA +# if YYSTACK_USE_ALLOCA +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca +# elif defined __BUILTIN_VA_ARG_INCR +# include /* INFRINGES ON USER NAME SPACE */ +# elif defined _AIX +# define YYSTACK_ALLOC __alloca +# elif defined _MSC_VER +# include /* INFRINGES ON USER NAME SPACE */ +# define alloca _alloca +# else +# define YYSTACK_ALLOC alloca +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +# include /* INFRINGES ON USER NAME SPACE */ + /* Use EXIT_SUCCESS as a witness for stdlib.h. */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +# endif +# endif +# endif +# endif +# endif + +# ifdef YYSTACK_ALLOC + /* Pacify GCC's `empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) +# ifndef YYSTACK_ALLOC_MAXIMUM + /* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ +# endif +# else +# define YYSTACK_ALLOC YYMALLOC +# define YYSTACK_FREE YYFREE +# ifndef YYSTACK_ALLOC_MAXIMUM +# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM +# endif +# if (defined __cplusplus && ! defined EXIT_SUCCESS \ + && ! ((defined YYMALLOC || defined malloc) \ + && (defined YYFREE || defined free))) +# include /* INFRINGES ON USER NAME SPACE */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +# endif +# endif +# ifndef YYMALLOC +# define YYMALLOC malloc +# if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# ifndef YYFREE +# define YYFREE free +# if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +void free (void *); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# endif +#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ + + +#if (! defined yyoverflow \ + && (! defined __cplusplus \ + || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + +/* A type that is properly aligned for any stack member. */ +union yyalloc +{ + yytype_int16 yyss_alloc; + YYSTYPE yyvs_alloc; +}; + +/* The size of the maximum gap between one aligned stack and the next. */ +# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) + +/* The size of an array large to enough to hold all stacks, each with + N elements. */ +# define YYSTACK_BYTES(N) \ + ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ + + YYSTACK_GAP_MAXIMUM) + +# define YYCOPY_NEEDED 1 + +/* Relocate STACK from its old location to the new one. The + local variables YYSIZE and YYSTACKSIZE give the old and new number of + elements in the stack, and YYPTR gives the new location of the + stack. Advance YYPTR to a properly aligned location for the next + stack. */ +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYSIZE_T yynewbytes; \ + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof (*yyptr); \ + } \ + while (YYID (0)) + +#endif + +#if defined YYCOPY_NEEDED && YYCOPY_NEEDED +/* Copy COUNT objects from SRC to DST. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(Dst, Src, Count) \ + __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) +# else +# define YYCOPY(Dst, Src, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (Dst)[yyi] = (Src)[yyi]; \ + } \ + while (YYID (0)) +# endif +# endif +#endif /* !YYCOPY_NEEDED */ + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL 2 +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST 52 + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS 17 +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS 7 +/* YYNRULES -- Number of rules. */ +#define YYNRULES 22 +/* YYNRULES -- Number of states. */ +#define YYNSTATES 51 + +/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ +#define YYUNDEFTOK 2 +#define YYMAXUTOK 271 + +#define YYTRANSLATE(YYX) \ + ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) + +/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ +static const yytype_uint8 yytranslate[] = +{ + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16 +}; + +#if YYDEBUG +/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in + YYRHS. */ +static const yytype_uint8 yyprhs[] = +{ + 0, 0, 3, 4, 7, 9, 11, 15, 17, 19, + 23, 27, 31, 37, 43, 49, 55, 62, 69, 76, + 83, 92, 97 +}; + +/* YYRHS -- A `-1'-separated list of the rules' RHS. */ +static const yytype_int8 yyrhs[] = +{ + 18, 0, -1, -1, 18, 19, -1, 20, -1, 4, + -1, 21, 16, 21, -1, 21, -1, 22, -1, 7, + 20, 8, -1, 20, 15, 20, -1, 20, 16, 20, + -1, 3, 9, 14, 3, 14, -1, 3, 10, 14, + 3, 14, -1, 3, 12, 14, 3, 14, -1, 3, + 11, 14, 3, 14, -1, 3, 9, 14, 3, 14, + 3, -1, 3, 10, 14, 3, 14, 3, -1, 3, + 12, 14, 3, 14, 3, -1, 3, 11, 14, 3, + 14, 3, -1, 5, 7, 3, 13, 23, 13, 23, + 8, -1, 6, 7, 3, 8, -1, 3, -1 +}; + +/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ +static const yytype_uint8 yyrline[] = +{ + 0, 68, 68, 70, 74, 88, 99, 107, 108, 109, + 110, 117, 130, 131, 132, 133, 134, 135, 136, 137, + 141, 145, 146 +}; +#endif + +#if YYDEBUG || YYERROR_VERBOSE || 1 +/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + "$end", "error", "$undefined", "WORD", "BOOL", "FUNC_INRANGE", + "DATE_ISO", "OBRACE", "CBRACE", "EQUAL", "UNEQUAL", "GT", "LT", "COMMA", + "QUOTE", "AND", "OR", "$accept", "input", "line", "expr", "match", + "function", "date", YY_NULL +}; +#endif + +# ifdef YYPRINT +/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to + token YYLEX-NUM. */ +static const yytype_uint16 yytoknum[] = +{ + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 271 +}; +# endif + +/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const yytype_uint8 yyr1[] = +{ + 0, 17, 18, 18, 19, 20, 20, 20, 20, 20, + 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, + 22, 23, 23 +}; + +/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ +static const yytype_uint8 yyr2[] = +{ + 0, 2, 0, 2, 1, 1, 3, 1, 1, 3, + 3, 3, 5, 5, 5, 5, 6, 6, 6, 6, + 8, 4, 1 +}; + +/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE doesn't specify something else to do. Zero + means the default is an error. */ +static const yytype_uint8 yydefact[] = +{ + 2, 0, 1, 0, 5, 0, 0, 3, 4, 7, + 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 9, 10, 11, 6, 0, + 0, 0, 0, 0, 12, 13, 15, 14, 22, 0, + 0, 16, 17, 19, 18, 0, 0, 0, 0, 21, + 20 +}; + +/* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int8 yydefgoto[] = +{ + -1, 1, 7, 8, 9, 10, 40 +}; + +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +#define YYPACT_NINF -10 +static const yytype_int8 yypact[] = +{ + -10, 10, -10, 9, -10, -2, -1, -10, 8, -9, + -10, 2, 12, 13, 14, 26, -7, -1, -1, 27, + 28, 29, 30, 31, 22, -10, 20, -10, -10, 23, + 24, 25, 32, 19, 37, 38, 39, 40, -10, 41, + 34, -10, -10, -10, -10, 42, 19, 36, 43, -10, + -10 +}; + +/* YYPGOTO[NTERM-NUM]. */ +static const yytype_int8 yypgoto[] = +{ + -10, -10, -10, -6, 33, -10, 3 +}; + +/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule which + number is the opposite. If YYTABLE_NINF, syntax error. */ +#define YYTABLE_NINF -1 +static const yytype_uint8 yytable[] = +{ + 16, 25, 3, 4, 5, 15, 6, 19, 17, 18, + 2, 26, 27, 3, 4, 5, 20, 6, 11, 12, + 13, 14, 38, 17, 18, 39, 21, 22, 23, 24, + 3, 29, 30, 31, 32, 33, 18, 34, 35, 36, + 41, 42, 43, 44, 49, 47, 37, 46, 45, 48, + 0, 50, 28 +}; + +#define yypact_value_is_default(Yystate) \ + (!!((Yystate) == (-10))) + +#define yytable_value_is_error(Yytable_value) \ + YYID (0) + +static const yytype_int8 yycheck[] = +{ + 6, 8, 3, 4, 5, 7, 7, 16, 15, 16, + 0, 17, 18, 3, 4, 5, 14, 7, 9, 10, + 11, 12, 3, 15, 16, 6, 14, 14, 14, 3, + 3, 3, 3, 3, 3, 13, 16, 14, 14, 14, + 3, 3, 3, 3, 8, 3, 14, 13, 7, 46, + -1, 8, 19 +}; + +/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const yytype_uint8 yystos[] = +{ + 0, 18, 0, 3, 4, 5, 7, 19, 20, 21, + 22, 9, 10, 11, 12, 7, 20, 15, 16, 16, + 14, 14, 14, 14, 3, 8, 20, 20, 21, 3, + 3, 3, 3, 13, 14, 14, 14, 14, 3, 6, + 23, 3, 3, 3, 3, 7, 13, 3, 23, 8, + 8 +}; + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab + + +/* Like YYERROR except do call yyerror. This remains here temporarily + to ease the transition to the new meaning of YYERROR, for GCC. + Once GCC version 2 has supplanted version 1, this can go. However, + YYFAIL appears to be in use. Nevertheless, it is formally deprecated + in Bison 2.4.2's NEWS entry, where a plan to phase it out is + discussed. */ + +#define YYFAIL goto yyerrlab +#if defined YYFAIL + /* This is here to suppress warnings from the GCC cpp's + -Wunused-macros. Normally we don't worry about that warning, but + some users do, and we want to make it easy for users to remove + YYFAIL uses, which will produce warnings from Bison 2.5. */ +#endif + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK (yylen); \ + yystate = *yyssp; \ + goto yybackup; \ + } \ + else \ + { \ + yyerror (YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ +while (YYID (0)) + +/* Error token number */ +#define YYTERROR 1 +#define YYERRCODE 256 + + +/* This macro is provided for backward compatibility. */ +#ifndef YY_LOCATION_PRINT +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +#endif + + +/* YYLEX -- calling `yylex' with the right arguments. */ +#ifdef YYLEX_PARAM +# define YYLEX yylex (YYLEX_PARAM) +#else +# define YYLEX yylex () +#endif + +/* Enable debugging if requested. */ +#if YYDEBUG + +# ifndef YYFPRINTF +# include /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (YYID (0)) + +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, \ + Type, Value); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (YYID (0)) + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +/*ARGSUSED*/ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) +#else +static void +yy_symbol_value_print (yyoutput, yytype, yyvaluep) + FILE *yyoutput; + int yytype; + YYSTYPE const * const yyvaluep; +#endif +{ + FILE *yyo = yyoutput; + YYUSE (yyo); + if (!yyvaluep) + return; +# ifdef YYPRINT + if (yytype < YYNTOKENS) + YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); +# else + YYUSE (yyoutput); +# endif + switch (yytype) + { + default: + break; + } +} + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) +#else +static void +yy_symbol_print (yyoutput, yytype, yyvaluep) + FILE *yyoutput; + int yytype; + YYSTYPE const * const yyvaluep; +#endif +{ + if (yytype < YYNTOKENS) + YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); + else + YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); + + yy_symbol_value_print (yyoutput, yytype, yyvaluep); + YYFPRINTF (yyoutput, ")"); +} + +/*------------------------------------------------------------------. +| yy_stack_print -- Print the state stack from its BOTTOM up to its | +| TOP (included). | +`------------------------------------------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) +#else +static void +yy_stack_print (yybottom, yytop) + yytype_int16 *yybottom; + yytype_int16 *yytop; +#endif +{ + YYFPRINTF (stderr, "Stack now"); + for (; yybottom <= yytop; yybottom++) + { + int yybot = *yybottom; + YYFPRINTF (stderr, " %d", yybot); + } + YYFPRINTF (stderr, "\n"); +} + +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (YYID (0)) + + +/*------------------------------------------------. +| Report that the YYRULE is going to be reduced. | +`------------------------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_reduce_print (YYSTYPE *yyvsp, int yyrule) +#else +static void +yy_reduce_print (yyvsp, yyrule) + YYSTYPE *yyvsp; + int yyrule; +#endif +{ + int yynrhs = yyr2[yyrule]; + int yyi; + unsigned long int yylno = yyrline[yyrule]; + YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", + yyrule - 1, yylno); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) + { + YYFPRINTF (stderr, " $%d = ", yyi + 1); + yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], + &(yyvsp[(yyi + 1) - (yynrhs)]) + ); + YYFPRINTF (stderr, "\n"); + } +} + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (yyvsp, Rule); \ +} while (YYID (0)) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; +#else /* !YYDEBUG */ +# define YYDPRINTF(Args) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YY_STACK_PRINT(Bottom, Top) +# define YY_REDUCE_PRINT(Rule) +#endif /* !YYDEBUG */ + + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) + evaluated with infinite-precision integer arithmetic. */ + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH 10000 +#endif + + +#if YYERROR_VERBOSE + +# ifndef yystrlen +# if defined __GLIBC__ && defined _STRING_H +# define yystrlen strlen +# else +/* Return the length of YYSTR. */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static YYSIZE_T +yystrlen (const char *yystr) +#else +static YYSIZE_T +yystrlen (yystr) + const char *yystr; +#endif +{ + YYSIZE_T yylen; + for (yylen = 0; yystr[yylen]; yylen++) + continue; + return yylen; +} +# endif +# endif + +# ifndef yystpcpy +# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +# define yystpcpy stpcpy +# else +/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in + YYDEST. */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static char * +yystpcpy (char *yydest, const char *yysrc) +#else +static char * +yystpcpy (yydest, yysrc) + char *yydest; + const char *yysrc; +#endif +{ + char *yyd = yydest; + const char *yys = yysrc; + + while ((*yyd++ = *yys++) != '\0') + continue; + + return yyd - 1; +} +# endif +# endif + +# ifndef yytnamerr +/* Copy to YYRES the contents of YYSTR after stripping away unnecessary + quotes and backslashes, so that it's suitable for yyerror. The + heuristic is that double-quoting is unnecessary unless the string + contains an apostrophe, a comma, or backslash (other than + backslash-backslash). YYSTR is taken from yytname. If YYRES is + null, do not copy; instead, return the length of what the result + would have been. */ +static YYSIZE_T +yytnamerr (char *yyres, const char *yystr) +{ + if (*yystr == '"') + { + YYSIZE_T yyn = 0; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes: ; + } + + if (! yyres) + return yystrlen (yystr); + + return yystpcpy (yyres, yystr) - yyres; +} +# endif + +/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message + about the unexpected token YYTOKEN for the state stack whose top is + YYSSP. + + Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is + not large enough to hold the message. In that case, also set + *YYMSG_ALLOC to the required number of bytes. Return 2 if the + required number of bytes is too large to store. */ +static int +yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, + yytype_int16 *yyssp, int yytoken) +{ + YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]); + YYSIZE_T yysize = yysize0; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + /* Internationalized format string. */ + const char *yyformat = YY_NULL; + /* Arguments of yyformat. */ + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + /* Number of reported tokens (one for the "unexpected", one per + "expected"). */ + int yycount = 0; + + /* There are many possibilities here to consider: + - Assume YYFAIL is not used. It's too flawed to consider. See + + for details. YYERROR is fine as it does not invoke this + function. + - If this state is a consistent state with a default action, then + the only way this function was invoked is if the default action + is an error action. In that case, don't check for expected + tokens because there are none. + - The only way there can be no lookahead present (in yychar) is if + this state is a consistent state with a default action. Thus, + detecting the absence of a lookahead is sufficient to determine + that there is no unexpected or expected token to report. In that + case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this state is a + consistent state with a default action. There might have been a + previous inconsistent state, consistent state with a non-default + action, or user semantic action that manipulated yychar. + - Of course, the expected token list depends on states to have + correct lookahead information, and it depends on the parser not + to perform extra reductions after fetching a lookahead from the + scanner and before detecting a syntax error. Thus, state merging + (from LALR or IELR) and default reductions corrupt the expected + token list. However, the list is correct for canonical LR with + one exception: it will still contain any token that will not be + accepted due to an error action in a later state. + */ + if (yytoken != YYEMPTY) + { + int yyn = yypact[*yyssp]; + yyarg[yycount++] = yytname[yytoken]; + if (!yypact_value_is_default (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + break; + } + yyarg[yycount++] = yytname[yyx]; + { + YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]); + if (! (yysize <= yysize1 + && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } + } + } + } + + switch (yycount) + { +# define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +# undef YYCASE_ + } + + { + YYSIZE_T yysize1 = yysize + yystrlen (yyformat); + if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } + + if (*yymsg_alloc < yysize) + { + *yymsg_alloc = 2 * yysize; + if (! (yysize <= *yymsg_alloc + && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) + *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; + return 1; + } + + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + { + char *yyp = *yymsg; + int yyi = 0; + while ((*yyp = *yyformat) != '\0') + if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyformat += 2; + } + else + { + yyp++; + yyformat++; + } + } + return 0; +} +#endif /* YYERROR_VERBOSE */ + +/*-----------------------------------------------. +| Release the memory associated to this symbol. | +`-----------------------------------------------*/ + +/*ARGSUSED*/ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) +#else +static void +yydestruct (yymsg, yytype, yyvaluep) + const char *yymsg; + int yytype; + YYSTYPE *yyvaluep; +#endif +{ + YYUSE (yyvaluep); + + if (!yymsg) + yymsg = "Deleting"; + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + + switch (yytype) + { + + default: + break; + } +} + + + + +/* The lookahead symbol. */ +int yychar; + + +#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_END +#endif +#ifndef YY_INITIAL_VALUE +# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#endif + +/* The semantic value of the lookahead symbol. */ +YYSTYPE yylval YY_INITIAL_VALUE(yyval_default); + +/* Number of syntax errors so far. */ +int yynerrs; + + +/*----------. +| yyparse. | +`----------*/ + +#ifdef YYPARSE_PARAM +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +int +yyparse (void *YYPARSE_PARAM) +#else +int +yyparse (YYPARSE_PARAM) + void *YYPARSE_PARAM; +#endif +#else /* ! YYPARSE_PARAM */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +int +yyparse (void) +#else +int +yyparse () + +#endif +#endif +{ + int yystate; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; + + /* The stacks and their tools: + `yyss': related to states. + `yyvs': related to semantic values. + + Refer to the stacks through separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* The state stack. */ + yytype_int16 yyssa[YYINITDEPTH]; + yytype_int16 *yyss; + yytype_int16 *yyssp; + + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs; + YYSTYPE *yyvsp; + + YYSIZE_T yystacksize; + + int yyn; + int yyresult; + /* Lookahead token as an internal (translated) token number. */ + int yytoken = 0; + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; + +#if YYERROR_VERBOSE + /* Buffer for error messages, and its allocated size. */ + char yymsgbuf[128]; + char *yymsg = yymsgbuf; + YYSIZE_T yymsg_alloc = sizeof yymsgbuf; +#endif + +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) + + /* The number of symbols on the RHS of the reduced rule. + Keep to zero when no symbol should be popped. */ + int yylen = 0; + + yyssp = yyss = yyssa; + yyvsp = yyvs = yyvsa; + yystacksize = YYINITDEPTH; + + YYDPRINTF ((stderr, "Starting parse\n")); + + yystate = 0; + yyerrstatus = 0; + yynerrs = 0; + yychar = YYEMPTY; /* Cause a token to be read. */ + goto yysetstate; + +/*------------------------------------------------------------. +| yynewstate -- Push a new state, which is found in yystate. | +`------------------------------------------------------------*/ + yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. So pushing a state here evens the stacks. */ + yyssp++; + + yysetstate: + *yyssp = yystate; + + if (yyss + yystacksize - 1 <= yyssp) + { + /* Get the current used size of the three stacks, in elements. */ + YYSIZE_T yysize = yyssp - yyss + 1; + +#ifdef yyoverflow + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + yytype_int16 *yyss1 = yyss; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * sizeof (*yyssp), + &yyvs1, yysize * sizeof (*yyvsp), + &yystacksize); + + yyss = yyss1; + yyvs = yyvs1; + } +#else /* no yyoverflow */ +# ifndef YYSTACK_RELOCATE + goto yyexhaustedlab; +# else + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) + goto yyexhaustedlab; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; + + { + yytype_int16 *yyss1 = yyss; + union yyalloc *yyptr = + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + if (! yyptr) + goto yyexhaustedlab; + YYSTACK_RELOCATE (yyss_alloc, yyss); + YYSTACK_RELOCATE (yyvs_alloc, yyvs); +# undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); + } +# endif +#endif /* no yyoverflow */ + + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; + + YYDPRINTF ((stderr, "Stack size increased to %lu\n", + (unsigned long int) yystacksize)); + + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; + } + + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + + if (yystate == YYFINAL) + YYACCEPT; + + goto yybackup; + +/*-----------. +| yybackup. | +`-----------*/ +yybackup: + + /* Do appropriate processing given the current state. Read a + lookahead token if we need one and don't already have one. */ + + /* First try to decide what to do without reference to lookahead token. */ + yyn = yypact[yystate]; + if (yypact_value_is_default (yyn)) + goto yydefault; + + /* Not known => get a lookahead token if don't already have one. */ + + /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ + if (yychar == YYEMPTY) + { + YYDPRINTF ((stderr, "Reading a token: ")); + yychar = YYLEX; + } + + if (yychar <= YYEOF) + { + yychar = yytoken = YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else + { + yytoken = YYTRANSLATE (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) + goto yydefault; + yyn = yytable[yyn]; + if (yyn <= 0) + { + if (yytable_value_is_error (yyn)) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; + + /* Shift the lookahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + + /* Discard the shifted token. */ + yychar = YYEMPTY; + + yystate = yyn; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END + + goto yynewstate; + + +/*-----------------------------------------------------------. +| yydefault -- do the default action for the current state. | +`-----------------------------------------------------------*/ +yydefault: + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + +/*-----------------------------. +| yyreduce -- Do a reduction. | +`-----------------------------*/ +yyreduce: + /* yyn is the number of a rule to reduce with. */ + yylen = yyr2[yyn]; + + /* If YYLEN is nonzero, implement the default value of the action: + `$$ = $1'. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1-yylen]; + + + YY_REDUCE_PRINT (yyn); + switch (yyn) + { + case 4: +/* Line 1792 of yacc.c */ +#line 74 "sparql_parser.y" + { + if (ssp_slq->slq_result_limit) + result_limit = talloc_asprintf(ssp_slq, "LIMIT %ld", ssp_slq->slq_result_limit); + else + result_limit = ""; + ssp_result = talloc_asprintf(ssp_slq, + "SELECT ?url WHERE " + "{ %s . ?obj nie:url ?url . FILTER(tracker:uri-is-descendant('file://%s/', ?url)) } %s", + (yyvsp[(1) - (1)].sval), ssp_slq->slq_vol->v_path, result_limit); + (yyval.sval) = ssp_result; +} + break; + + case 5: +/* Line 1792 of yacc.c */ +#line 88 "sparql_parser.y" + { + /* + * We can't properly handle these in expressions, fortunately this + * is probably only ever used by OS X as sole element in an + * expression ie "False" (when Finder window selected our share + * but no search string entered yet). Packet traces showed that OS + * X Spotlight server then returns a failure (ie -1) which is what + * we do here too by calling YYABORT. + */ + YYABORT; +} + break; + + case 6: +/* Line 1792 of yacc.c */ +#line 99 "sparql_parser.y" + { + if ((yyvsp[(1) - (3)].sval) == NULL || (yyvsp[(3) - (3)].sval) == NULL) + YYABORT; + if (strcmp((yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval)) != 0) + (yyval.sval) = talloc_asprintf(ssp_slq, "{ %s } UNION { %s }", (yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval)); + else + (yyval.sval) = talloc_asprintf(ssp_slq, "%s", (yyvsp[(1) - (3)].sval)); +} + break; + + case 7: +/* Line 1792 of yacc.c */ +#line 107 "sparql_parser.y" + {(yyval.sval) = (yyvsp[(1) - (1)].sval); if ((yyval.sval) == NULL) YYABORT;} + break; + + case 8: +/* Line 1792 of yacc.c */ +#line 108 "sparql_parser.y" + {(yyval.sval) = (yyvsp[(1) - (1)].sval);} + break; + + case 9: +/* Line 1792 of yacc.c */ +#line 109 "sparql_parser.y" + {(yyval.sval) = talloc_asprintf(ssp_slq, "%s", (yyvsp[(2) - (3)].sval));} + break; + + case 10: +/* Line 1792 of yacc.c */ +#line 110 "sparql_parser.y" + { + if (!ssp_slq->slq_allow_expr) { + yyerror("Spotlight queries with logic expressions are disabled"); + YYABORT; + } + (yyval.sval) = talloc_asprintf(ssp_slq, "%s . %s", (yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval)); +} + break; + + case 11: +/* Line 1792 of yacc.c */ +#line 117 "sparql_parser.y" + { + if (!ssp_slq->slq_allow_expr) { + yyerror("Spotlight queries with logic expressions are disabled"); + YYABORT; + } + if (strcmp((yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval)) != 0) + (yyval.sval) = talloc_asprintf(ssp_slq, "{ %s } UNION { %s }", (yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval)); + else + (yyval.sval) = talloc_asprintf(ssp_slq, "%s", (yyvsp[(1) - (3)].sval)); +} + break; + + case 12: +/* Line 1792 of yacc.c */ +#line 130 "sparql_parser.y" + {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '=', (yyvsp[(4) - (5)].sval));} + break; + + case 13: +/* Line 1792 of yacc.c */ +#line 131 "sparql_parser.y" + {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '!', (yyvsp[(4) - (5)].sval));} + break; + + case 14: +/* Line 1792 of yacc.c */ +#line 132 "sparql_parser.y" + {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '<', (yyvsp[(4) - (5)].sval));} + break; + + case 15: +/* Line 1792 of yacc.c */ +#line 133 "sparql_parser.y" + {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '>', (yyvsp[(4) - (5)].sval));} + break; + + case 16: +/* Line 1792 of yacc.c */ +#line 134 "sparql_parser.y" + {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '=', (yyvsp[(4) - (6)].sval));} + break; + + case 17: +/* Line 1792 of yacc.c */ +#line 135 "sparql_parser.y" + {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '!', (yyvsp[(4) - (6)].sval));} + break; + + case 18: +/* Line 1792 of yacc.c */ +#line 136 "sparql_parser.y" + {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '<', (yyvsp[(4) - (6)].sval));} + break; + + case 19: +/* Line 1792 of yacc.c */ +#line 137 "sparql_parser.y" + {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '>', (yyvsp[(4) - (6)].sval));} + break; + + case 20: +/* Line 1792 of yacc.c */ +#line 141 "sparql_parser.y" + {(yyval.sval) = map_daterange((yyvsp[(3) - (8)].sval), (yyvsp[(5) - (8)].tval), (yyvsp[(7) - (8)].tval));} + break; + + case 21: +/* Line 1792 of yacc.c */ +#line 145 "sparql_parser.y" + {(yyval.tval) = isodate2unix((yyvsp[(3) - (4)].sval));} + break; + + case 22: +/* Line 1792 of yacc.c */ +#line 146 "sparql_parser.y" + {(yyval.tval) = atoi((yyvsp[(1) - (1)].sval)) + SPRAW_TIME_OFFSET;} + break; + + +/* Line 1792 of yacc.c */ +#line 1607 "sparql_parser.c" + default: break; + } + /* User semantic actions sometimes alter yychar, and that requires + that yytoken be updated with the new translation. We take the + approach of translating immediately before every use of yytoken. + One alternative is translating here after every semantic action, + but that translation would be missed if the semantic action invokes + YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or + if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an + incorrect destructor might then be invoked immediately. In the + case of YYERROR or YYBACKUP, subsequent parser actions might lead + to an incorrect destructor call or verbose syntax error message + before the lookahead is translated. */ + YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + + *++yyvsp = yyval; + + /* Now `shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ + + yyn = yyr1[yyn]; + + yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; + if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yytable[yystate]; + else + yystate = yydefgoto[yyn - YYNTOKENS]; + + goto yynewstate; + + +/*------------------------------------. +| yyerrlab -- here on detecting error | +`------------------------------------*/ +yyerrlab: + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); + + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) + { + ++yynerrs; +#if ! YYERROR_VERBOSE + yyerror (YY_("syntax error")); +#else +# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ + yyssp, yytoken) + { + char const *yymsgp = YY_("syntax error"); + int yysyntax_error_status; + yysyntax_error_status = YYSYNTAX_ERROR; + if (yysyntax_error_status == 0) + yymsgp = yymsg; + else if (yysyntax_error_status == 1) + { + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); + if (!yymsg) + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = 2; + } + else + { + yysyntax_error_status = YYSYNTAX_ERROR; + yymsgp = yymsg; + } + } + yyerror (yymsgp); + if (yysyntax_error_status == 2) + goto yyexhaustedlab; + } +# undef YYSYNTAX_ERROR +#endif + } + + + + if (yyerrstatus == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + if (yychar <= YYEOF) + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } + else + { + yydestruct ("Error: discarding", + yytoken, &yylval); + yychar = YYEMPTY; + } + } + + /* Else will try to reuse lookahead token after shifting the error + token. */ + goto yyerrlab1; + + +/*---------------------------------------------------. +| yyerrorlab -- error raised explicitly by YYERROR. | +`---------------------------------------------------*/ +yyerrorlab: + + /* Pacify compilers like GCC when the user code never invokes + YYERROR and the label yyerrorlab therefore never appears in user + code. */ + if (/*CONSTCOND*/ 0) + goto yyerrorlab; + + /* Do not reclaim the symbols of the rule which action triggered + this YYERROR. */ + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + yystate = *yyssp; + goto yyerrlab1; + + +/*-------------------------------------------------------------. +| yyerrlab1 -- common code for both syntax error and YYERROR. | +`-------------------------------------------------------------*/ +yyerrlab1: + yyerrstatus = 3; /* Each real token shifted decrements this. */ + + for (;;) + { + yyn = yypact[yystate]; + if (!yypact_value_is_default (yyn)) + { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; + + + yydestruct ("Error: popping", + yystos[yystate], yyvsp); + YYPOPSTACK (1); + yystate = *yyssp; + YY_STACK_PRINT (yyss, yyssp); + } + + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END + + + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + + yystate = yyn; + goto yynewstate; + + +/*-------------------------------------. +| yyacceptlab -- YYACCEPT comes here. | +`-------------------------------------*/ +yyacceptlab: + yyresult = 0; + goto yyreturn; + +/*-----------------------------------. +| yyabortlab -- YYABORT comes here. | +`-----------------------------------*/ +yyabortlab: + yyresult = 1; + goto yyreturn; + +#if !defined yyoverflow || YYERROR_VERBOSE +/*-------------------------------------------------. +| yyexhaustedlab -- memory exhaustion comes here. | +`-------------------------------------------------*/ +yyexhaustedlab: + yyerror (YY_("memory exhausted")); + yyresult = 2; + /* Fall through. */ +#endif + +yyreturn: + if (yychar != YYEMPTY) + { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE (yychar); + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval); + } + /* Do not reclaim the symbols of the rule which action triggered + this YYABORT or YYACCEPT. */ + YYPOPSTACK (yylen); + YY_STACK_PRINT (yyss, yyssp); + while (yyssp != yyss) + { + yydestruct ("Cleanup: popping", + yystos[*yyssp], yyvsp); + YYPOPSTACK (1); + } +#ifndef yyoverflow + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif +#if YYERROR_VERBOSE + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); +#endif + /* Make sure YYID is used. */ + return YYID (yyresult); +} + + +/* Line 2055 of yacc.c */ +#line 149 "sparql_parser.y" + + +static time_t isodate2unix(const char *s) +{ + struct tm tm; + + if (strptime(s, "%Y-%m-%dT%H:%M:%SZ", &tm) == NULL) + return (time_t)-1; + return mktime(&tm); +} + +static const char *map_daterange(const char *dateattr, time_t date1, time_t date2) +{ + EC_INIT; + char *result = NULL; + struct spotlight_sparql_map *p; + struct tm *tmp; + char buf1[64], buf2[64]; + + EC_NULL_LOG( tmp = localtime(&date1) ); + strftime(buf1, sizeof(buf1), "%Y-%m-%dT%H:%M:%SZ", tmp); + EC_NULL_LOG( tmp = localtime(&date2) ); + strftime(buf2, sizeof(buf2), "%Y-%m-%dT%H:%M:%SZ", tmp); + + for (p = spotlight_sparql_map; p->ssm_spotlight_attr; p++) { + if (strcmp(dateattr, p->ssm_spotlight_attr) == 0) { + result = talloc_asprintf(ssp_slq, + "?obj %s ?%c FILTER (?%c > '%s' && ?%c < '%s')", + p->ssm_sparql_attr, + sparqlvar, + sparqlvar, + buf1, + sparqlvar, + buf2); + sparqlvar++; + break; + } + } + +EC_CLEANUP: + if (ret != 0) + return NULL; + return result; +} + +static char *map_type_search(const char *attr, char op, const char *val) +{ + char *result = NULL; + const char *sparqlAttr; + + for (struct MDTypeMap *p = MDTypeMap; p->mdtm_value; p++) { + if (strcmp(p->mdtm_value, val) == 0) { + switch (p->mdtm_type) { + case kMDTypeMapRDF: + sparqlAttr = "rdf:type"; + break; + case kMDTypeMapMime: + sparqlAttr = "nie:mimeType"; + break; + default: + return NULL; + } + result = talloc_asprintf(ssp_slq, "?obj %s '%s'", + sparqlAttr, + p->mdtm_sparql); + break; + } + } + return result; +} + +static const char *map_expr(const char *attr, char op, const char *val) +{ + EC_INIT; + char *result = NULL; + struct spotlight_sparql_map *p; + time_t t; + struct tm *tmp; + char buf1[64]; + bstring q = NULL, search = NULL, replace = NULL; + + for (p = spotlight_sparql_map; p->ssm_spotlight_attr; p++) { + if (p->ssm_enabled && (strcmp(p->ssm_spotlight_attr, attr) == 0)) { + if (p->ssm_type != ssmt_type && p->ssm_sparql_attr == NULL) { + yyerror("unsupported Spotlight attribute"); + EC_FAIL; + } + switch (p->ssm_type) { + case ssmt_bool: + result = talloc_asprintf(ssp_slq, "?obj %s '%s'", p->ssm_sparql_attr, val); + break; + case ssmt_num: + result = talloc_asprintf(ssp_slq, "?obj %s ?%c FILTER(?%c %c%c '%s')", + p->ssm_sparql_attr, + sparqlvar, + sparqlvar, + op, + op == '!' ? '=' : ' ', /* append '=' to '!' */ + val); + sparqlvar++; + break; + case ssmt_str: + q = bformat("^%s$", val); + search = bfromcstr("*"); + replace = bfromcstr(".*"); + bfindreplace(q, search, replace, 0); + result = talloc_asprintf(ssp_slq, "?obj %s ?%c FILTER(regex(?%c, '%s'))", + p->ssm_sparql_attr, + sparqlvar, + sparqlvar, + bdata(q)); + sparqlvar++; + break; + case ssmt_fts: + result = talloc_asprintf(ssp_slq, "?obj %s '%s'", p->ssm_sparql_attr, val); + break; + case ssmt_date: + t = atoi(val) + SPRAW_TIME_OFFSET; + EC_NULL( tmp = localtime(&t) ); + strftime(buf1, sizeof(buf1), "%Y-%m-%dT%H:%M:%SZ", tmp); + result = talloc_asprintf(ssp_slq, "?obj %s ?%c FILTER(?%c %c '%s')", + p->ssm_sparql_attr, + sparqlvar, + sparqlvar, + op, + buf1); + sparqlvar++; + break; + case ssmt_type: + result = map_type_search(attr, op, val); + break; + default: + EC_FAIL; + } + break; + } + } + +EC_CLEANUP: + if (ret != 0) + result = NULL; + if (q) + bdestroy(q); + if (search) + bdestroy(search); + if (replace) + bdestroy(replace); + return result; +} + +void yyerror(const char *str) +{ +#ifdef MAIN + printf("yyerror: %s\n", str); +#else + LOG(log_error, logtype_sl, "yyerror: %s", str); +#endif +} + +int yywrap() +{ + return 1; +} + +/** + * Map a Spotlight RAW query string to a SPARQL query string + * + * @param[in] slq Spotlight query handle + * @param[out] sparql_result Mapped SPARQL query, string is allocated in + * talloc context of slq + * @return 0 on success, -1 on error + **/ +int map_spotlight_to_sparql_query(slq_t *slq, gchar **sparql_result) +{ + EC_INIT; + YY_BUFFER_STATE s = NULL; + ssp_result = NULL; + + ssp_slq = slq; + s = yy_scan_string(slq->slq_qstring); + sparqlvar = 'a'; + + EC_ZERO( yyparse() ); + +EC_CLEANUP: + if (s) + yy_delete_buffer(s); + if (ret == 0) + *sparql_result = ssp_result; + else + *sparql_result = NULL; + EC_EXIT; +} + +#ifdef MAIN +int main(int argc, char **argv) +{ + int ret; + YY_BUFFER_STATE s; + + if (argc != 2) { + printf("usage: %s QUERY\n", argv[0]); + return 1; + } + + ssp_slq = talloc_zero(NULL, slq_t); + struct vol *vol = talloc_zero(ssp_slq, struct vol); + vol->v_path = "/Volumes/test"; + ssp_slq->slq_vol = vol; + ssp_slq->slq_allow_expr = true; + sparqlvar = 'a'; + + s = yy_scan_string(argv[1]); + + ret = yyparse(); + + yy_delete_buffer(s); + + if (ret == 0) + printf("SPARQL: %s\n", ssp_result ? ssp_result : "(empty)"); + + return 0; +} +#endif diff --git a/etc/spotlight/sparql_parser.h b/etc/spotlight/sparql_parser.h new file mode 100644 index 00000000..6c5267dc --- /dev/null +++ b/etc/spotlight/sparql_parser.h @@ -0,0 +1,130 @@ +/* A Bison parser, made by GNU Bison 2.7. */ + +/* Bison interface for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +#ifndef YY_YY_SPARQL_PARSER_H_INCLUDED +# define YY_YY_SPARQL_PARSER_H_INCLUDED +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int yydebug; +#endif + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + WORD = 258, + BOOL = 259, + FUNC_INRANGE = 260, + DATE_ISO = 261, + OBRACE = 262, + CBRACE = 263, + EQUAL = 264, + UNEQUAL = 265, + GT = 266, + LT = 267, + COMMA = 268, + QUOTE = 269, + AND = 270, + OR = 271 + }; +#endif +/* Tokens. */ +#define WORD 258 +#define BOOL 259 +#define FUNC_INRANGE 260 +#define DATE_ISO 261 +#define OBRACE 262 +#define CBRACE 263 +#define EQUAL 264 +#define UNEQUAL 265 +#define GT 266 +#define LT 267 +#define COMMA 268 +#define QUOTE 269 +#define AND 270 +#define OR 271 + + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +{ +/* Line 2058 of yacc.c */ +#line 46 "sparql_parser.y" + + int ival; + const char *sval; + bool bval; + time_t tval; + + +/* Line 2058 of yacc.c */ +#line 97 "sparql_parser.h" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + +extern YYSTYPE yylval; + +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int yyparse (void *YYPARSE_PARAM); +#else +int yyparse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int yyparse (void); +#else +int yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ +/* "%code provides" blocks. */ +/* Line 2058 of yacc.c */ +#line 40 "sparql_parser.y" + + #define SPRAW_TIME_OFFSET 978307200 + extern int map_spotlight_to_sparql_query(slq_t *slq, gchar **sparql_result); + extern slq_t *ssp_slq; + + +/* Line 2058 of yacc.c */ +#line 129 "sparql_parser.h" + +#endif /* !YY_YY_SPARQL_PARSER_H_INCLUDED */ diff --git a/etc/spotlight/sparql_parser.y b/etc/spotlight/sparql_parser.y new file mode 100644 index 00000000..ede21872 --- /dev/null +++ b/etc/spotlight/sparql_parser.y @@ -0,0 +1,372 @@ +%{ + #include + + #include + #include + #include + #include + + #include + + #include + #include + #include + #include + + #include "sparql_map.h" + + struct yy_buffer_state; + typedef struct yy_buffer_state *YY_BUFFER_STATE; + extern int yylex (void); + extern void yyerror (char const *); + extern void *yyterminate(void); + extern YY_BUFFER_STATE yy_scan_string( const char *str); + extern void yy_delete_buffer ( YY_BUFFER_STATE buffer ); + + /* forward declarations */ + static const char *map_expr(const char *attr, char op, const char *val); + static const char *map_daterange(const char *dateattr, time_t date1, time_t date2); + static time_t isodate2unix(const char *s); + + /* global vars, eg needed by the lexer */ + slq_t *ssp_slq; + + /* local vars */ + static gchar *ssp_result; + static char sparqlvar; + static char *result_limit; +%} + +%code provides { + #define SPRAW_TIME_OFFSET 978307200 + extern int map_spotlight_to_sparql_query(slq_t *slq, gchar **sparql_result); + extern slq_t *ssp_slq; +} + +%union { + int ival; + const char *sval; + bool bval; + time_t tval; +} + +%expect 5 +%error-verbose + +%type match expr line function +%type date + +%token WORD +%token BOOL +%token FUNC_INRANGE +%token DATE_ISO +%token OBRACE CBRACE EQUAL UNEQUAL GT LT COMMA QUOTE +%left AND +%left OR +%% + +input: +/* empty */ +| input line +; + +line: +expr { + if (ssp_slq->slq_result_limit) + result_limit = talloc_asprintf(ssp_slq, "LIMIT %ld", ssp_slq->slq_result_limit); + else + result_limit = ""; + ssp_result = talloc_asprintf(ssp_slq, + "SELECT ?url WHERE " + "{ %s . ?obj nie:url ?url . FILTER(tracker:uri-is-descendant('file://%s/', ?url)) } %s", + $1, ssp_slq->slq_vol->v_path, result_limit); + $$ = ssp_result; +} +; + +expr: +BOOL { + /* + * We can't properly handle these in expressions, fortunately this + * is probably only ever used by OS X as sole element in an + * expression ie "False" (when Finder window selected our share + * but no search string entered yet). Packet traces showed that OS + * X Spotlight server then returns a failure (ie -1) which is what + * we do here too by calling YYABORT. + */ + YYABORT; +} +| match OR match { + if ($1 == NULL || $3 == NULL) + YYABORT; + if (strcmp($1, $3) != 0) + $$ = talloc_asprintf(ssp_slq, "{ %s } UNION { %s }", $1, $3); + else + $$ = talloc_asprintf(ssp_slq, "%s", $1); +} +| match {$$ = $1; if ($$ == NULL) YYABORT;} +| function {$$ = $1;} +| OBRACE expr CBRACE {$$ = talloc_asprintf(ssp_slq, "%s", $2);} +| expr AND expr { + if (!ssp_slq->slq_allow_expr) { + yyerror("Spotlight queries with logic expressions are disabled"); + YYABORT; + } + $$ = talloc_asprintf(ssp_slq, "%s . %s", $1, $3); +} +| expr OR expr { + if (!ssp_slq->slq_allow_expr) { + yyerror("Spotlight queries with logic expressions are disabled"); + YYABORT; + } + if (strcmp($1, $3) != 0) + $$ = talloc_asprintf(ssp_slq, "{ %s } UNION { %s }", $1, $3); + else + $$ = talloc_asprintf(ssp_slq, "%s", $1); +} +; + +match: +WORD EQUAL QUOTE WORD QUOTE {$$ = map_expr($1, '=', $4);} +| WORD UNEQUAL QUOTE WORD QUOTE {$$ = map_expr($1, '!', $4);} +| WORD LT QUOTE WORD QUOTE {$$ = map_expr($1, '<', $4);} +| WORD GT QUOTE WORD QUOTE {$$ = map_expr($1, '>', $4);} +| WORD EQUAL QUOTE WORD QUOTE WORD {$$ = map_expr($1, '=', $4);} +| WORD UNEQUAL QUOTE WORD QUOTE WORD {$$ = map_expr($1, '!', $4);} +| WORD LT QUOTE WORD QUOTE WORD {$$ = map_expr($1, '<', $4);} +| WORD GT QUOTE WORD QUOTE WORD {$$ = map_expr($1, '>', $4);} +; + +function: +FUNC_INRANGE OBRACE WORD COMMA date COMMA date CBRACE {$$ = map_daterange($3, $5, $7);} +; + +date: +DATE_ISO OBRACE WORD CBRACE {$$ = isodate2unix($3);} +| WORD {$$ = atoi($1) + SPRAW_TIME_OFFSET;} +; + +%% + +static time_t isodate2unix(const char *s) +{ + struct tm tm; + + if (strptime(s, "%Y-%m-%dT%H:%M:%SZ", &tm) == NULL) + return (time_t)-1; + return mktime(&tm); +} + +static const char *map_daterange(const char *dateattr, time_t date1, time_t date2) +{ + EC_INIT; + char *result = NULL; + struct spotlight_sparql_map *p; + struct tm *tmp; + char buf1[64], buf2[64]; + + EC_NULL_LOG( tmp = localtime(&date1) ); + strftime(buf1, sizeof(buf1), "%Y-%m-%dT%H:%M:%SZ", tmp); + EC_NULL_LOG( tmp = localtime(&date2) ); + strftime(buf2, sizeof(buf2), "%Y-%m-%dT%H:%M:%SZ", tmp); + + for (p = spotlight_sparql_map; p->ssm_spotlight_attr; p++) { + if (strcmp(dateattr, p->ssm_spotlight_attr) == 0) { + result = talloc_asprintf(ssp_slq, + "?obj %s ?%c FILTER (?%c > '%s' && ?%c < '%s')", + p->ssm_sparql_attr, + sparqlvar, + sparqlvar, + buf1, + sparqlvar, + buf2); + sparqlvar++; + break; + } + } + +EC_CLEANUP: + if (ret != 0) + return NULL; + return result; +} + +static char *map_type_search(const char *attr, char op, const char *val) +{ + char *result = NULL; + const char *sparqlAttr; + + for (struct MDTypeMap *p = MDTypeMap; p->mdtm_value; p++) { + if (strcmp(p->mdtm_value, val) == 0) { + switch (p->mdtm_type) { + case kMDTypeMapRDF: + sparqlAttr = "rdf:type"; + break; + case kMDTypeMapMime: + sparqlAttr = "nie:mimeType"; + break; + default: + return NULL; + } + result = talloc_asprintf(ssp_slq, "?obj %s '%s'", + sparqlAttr, + p->mdtm_sparql); + break; + } + } + return result; +} + +static const char *map_expr(const char *attr, char op, const char *val) +{ + EC_INIT; + char *result = NULL; + struct spotlight_sparql_map *p; + time_t t; + struct tm *tmp; + char buf1[64]; + bstring q = NULL, search = NULL, replace = NULL; + + for (p = spotlight_sparql_map; p->ssm_spotlight_attr; p++) { + if (p->ssm_enabled && (strcmp(p->ssm_spotlight_attr, attr) == 0)) { + if (p->ssm_type != ssmt_type && p->ssm_sparql_attr == NULL) { + yyerror("unsupported Spotlight attribute"); + EC_FAIL; + } + switch (p->ssm_type) { + case ssmt_bool: + result = talloc_asprintf(ssp_slq, "?obj %s '%s'", p->ssm_sparql_attr, val); + break; + case ssmt_num: + result = talloc_asprintf(ssp_slq, "?obj %s ?%c FILTER(?%c %c%c '%s')", + p->ssm_sparql_attr, + sparqlvar, + sparqlvar, + op, + op == '!' ? '=' : ' ', /* append '=' to '!' */ + val); + sparqlvar++; + break; + case ssmt_str: + q = bformat("^%s$", val); + search = bfromcstr("*"); + replace = bfromcstr(".*"); + bfindreplace(q, search, replace, 0); + result = talloc_asprintf(ssp_slq, "?obj %s ?%c FILTER(regex(?%c, '%s'))", + p->ssm_sparql_attr, + sparqlvar, + sparqlvar, + bdata(q)); + sparqlvar++; + break; + case ssmt_fts: + result = talloc_asprintf(ssp_slq, "?obj %s '%s'", p->ssm_sparql_attr, val); + break; + case ssmt_date: + t = atoi(val) + SPRAW_TIME_OFFSET; + EC_NULL( tmp = localtime(&t) ); + strftime(buf1, sizeof(buf1), "%Y-%m-%dT%H:%M:%SZ", tmp); + result = talloc_asprintf(ssp_slq, "?obj %s ?%c FILTER(?%c %c '%s')", + p->ssm_sparql_attr, + sparqlvar, + sparqlvar, + op, + buf1); + sparqlvar++; + break; + case ssmt_type: + result = map_type_search(attr, op, val); + break; + default: + EC_FAIL; + } + break; + } + } + +EC_CLEANUP: + if (ret != 0) + result = NULL; + if (q) + bdestroy(q); + if (search) + bdestroy(search); + if (replace) + bdestroy(replace); + return result; +} + +void yyerror(const char *str) +{ +#ifdef MAIN + printf("yyerror: %s\n", str); +#else + LOG(log_error, logtype_sl, "yyerror: %s", str); +#endif +} + +int yywrap() +{ + return 1; +} + +/** + * Map a Spotlight RAW query string to a SPARQL query string + * + * @param[in] slq Spotlight query handle + * @param[out] sparql_result Mapped SPARQL query, string is allocated in + * talloc context of slq + * @return 0 on success, -1 on error + **/ +int map_spotlight_to_sparql_query(slq_t *slq, gchar **sparql_result) +{ + EC_INIT; + YY_BUFFER_STATE s = NULL; + ssp_result = NULL; + + ssp_slq = slq; + s = yy_scan_string(slq->slq_qstring); + sparqlvar = 'a'; + + EC_ZERO( yyparse() ); + +EC_CLEANUP: + if (s) + yy_delete_buffer(s); + if (ret == 0) + *sparql_result = ssp_result; + else + *sparql_result = NULL; + EC_EXIT; +} + +#ifdef MAIN +int main(int argc, char **argv) +{ + int ret; + YY_BUFFER_STATE s; + + if (argc != 2) { + printf("usage: %s QUERY\n", argv[0]); + return 1; + } + + ssp_slq = talloc_zero(NULL, slq_t); + struct vol *vol = talloc_zero(ssp_slq, struct vol); + vol->v_path = "/Volumes/test"; + ssp_slq->slq_vol = vol; + ssp_slq->slq_allow_expr = true; + sparqlvar = 'a'; + + s = yy_scan_string(argv[1]); + + ret = yyparse(); + + yy_delete_buffer(s); + + if (ret == 0) + printf("SPARQL: %s\n", ssp_result ? ssp_result : "(empty)"); + + return 0; +} +#endif diff --git a/etc/spotlight/spotlight_rawquery_lexer.c b/etc/spotlight/spotlight_rawquery_lexer.c index 38b7a73f..b13b721b 100644 --- a/etc/spotlight/spotlight_rawquery_lexer.c +++ b/etc/spotlight/spotlight_rawquery_lexer.c @@ -14,7 +14,7 @@ #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 #define YY_FLEX_MINOR_VERSION 5 -#define YY_FLEX_SUBMINOR_VERSION 35 +#define YY_FLEX_SUBMINOR_VERSION 37 #if YY_FLEX_SUBMINOR_VERSION > 0 #define FLEX_BETA #endif @@ -59,7 +59,6 @@ typedef int flex_int32_t; typedef unsigned char flex_uint8_t; typedef unsigned short int flex_uint16_t; typedef unsigned int flex_uint32_t; -#endif /* ! C99 */ /* Limits of integral types. */ #ifndef INT8_MIN @@ -90,6 +89,8 @@ typedef unsigned int flex_uint32_t; #define UINT32_MAX (4294967295U) #endif +#endif /* ! C99 */ + #endif /* ! FLEXINT_H */ #ifdef __cplusplus @@ -158,7 +159,12 @@ typedef unsigned int flex_uint32_t; typedef struct yy_buffer_state *YY_BUFFER_STATE; #endif -extern int yyleng; +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +extern yy_size_t yyleng; extern FILE *yyin, *yyout; @@ -184,11 +190,6 @@ extern FILE *yyin, *yyout; #define unput(c) yyunput( c, (yytext_ptr) ) -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - #ifndef YY_STRUCT_YY_BUFFER_STATE #define YY_STRUCT_YY_BUFFER_STATE struct yy_buffer_state @@ -206,7 +207,7 @@ struct yy_buffer_state /* Number of characters read into yy_ch_buf, not including EOB * characters. */ - int yy_n_chars; + yy_size_t yy_n_chars; /* Whether we "own" the buffer - i.e., we know we created it, * and can realloc() it to grow it, and should free() it to @@ -276,8 +277,8 @@ static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ /* yy_hold_char holds the character lost when yytext is formed. */ static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ -int yyleng; +static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */ +yy_size_t yyleng; /* Points to current character in buffer. */ static char *yy_c_buf_p = (char *) 0; @@ -305,7 +306,7 @@ static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ); +YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len ); void *yyalloc (yy_size_t ); void *yyrealloc (void *,yy_size_t ); @@ -501,11 +502,11 @@ char *yytext; #include #include #include -#ifdef HAVE_TRACKER_SPARQL -#include "slmod_sparql_parser.h" +#ifdef HAVE_TRACKER +#include "sparql_parser.h" #define SLQ_VAR ssp_slq #endif -#line 509 "spotlight_rawquery_lexer.c" +#line 510 "spotlight_rawquery_lexer.c" #define INITIAL 0 @@ -544,7 +545,7 @@ FILE *yyget_out (void ); void yyset_out (FILE * out_str ); -int yyget_leng (void ); +yy_size_t yyget_leng (void ); char *yyget_text (void ); @@ -594,7 +595,7 @@ static int input (void ); /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO fwrite( yytext, yyleng, 1, yyout ) +#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, @@ -605,7 +606,7 @@ static int input (void ); if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ { \ int c = '*'; \ - int n; \ + size_t n; \ for ( n = 0; n < max_size && \ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \ @@ -689,7 +690,7 @@ YY_DECL #line 27 "spotlight_rawquery_lexer.l" -#line 693 "spotlight_rawquery_lexer.c" +#line 694 "spotlight_rawquery_lexer.c" if ( !(yy_init) ) { @@ -858,7 +859,7 @@ YY_RULE_SETUP #line 44 "spotlight_rawquery_lexer.l" ECHO; YY_BREAK -#line 862 "spotlight_rawquery_lexer.c" +#line 863 "spotlight_rawquery_lexer.c" case YY_STATE_EOF(INITIAL): yyterminate(); @@ -1044,21 +1045,21 @@ static int yy_get_next_buffer (void) else { - int num_to_read = + yy_size_t num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; while ( num_to_read <= 0 ) { /* Not enough room in the buffer - grow it. */ /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER; + YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; int yy_c_buf_p_offset = (int) ((yy_c_buf_p) - b->yy_ch_buf); if ( b->yy_is_our_buffer ) { - int new_size = b->yy_buf_size * 2; + yy_size_t new_size = b->yy_buf_size * 2; if ( new_size <= 0 ) b->yy_buf_size += b->yy_buf_size / 8; @@ -1089,7 +1090,7 @@ static int yy_get_next_buffer (void) /* Read in more data. */ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), (size_t) num_to_read ); + (yy_n_chars), num_to_read ); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); } @@ -1184,7 +1185,7 @@ static int yy_get_next_buffer (void) yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_is_jam = (yy_current_state == 56); - return yy_is_jam ? 0 : yy_current_state; + return yy_is_jam ? 0 : yy_current_state; } static void yyunput (int c, register char * yy_bp ) @@ -1199,7 +1200,7 @@ static int yy_get_next_buffer (void) if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) { /* need to shift things up to make room */ /* +2 for EOB chars. */ - register int number_to_move = (yy_n_chars) + 2; + register yy_size_t number_to_move = (yy_n_chars) + 2; register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; register char *source = @@ -1248,7 +1249,7 @@ static int yy_get_next_buffer (void) else { /* need more input */ - int offset = (yy_c_buf_p) - (yytext_ptr); + yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); ++(yy_c_buf_p); switch ( yy_get_next_buffer( ) ) @@ -1408,10 +1409,6 @@ static void yy_load_buffer_state (void) yyfree((void *) b ); } -#ifndef __cplusplus -extern int isatty (int ); -#endif /* __cplusplus */ - /* Initializes or reinitializes a buffer. * This function is sometimes called more than once on the same buffer, * such as during a yyrestart() or at EOF. @@ -1524,7 +1521,7 @@ void yypop_buffer_state (void) */ static void yyensure_buffer_stack (void) { - int num_to_alloc; + yy_size_t num_to_alloc; if (!(yy_buffer_stack)) { @@ -1616,17 +1613,17 @@ YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) /** Setup the input buffer state to scan the given bytes. The next call to yylex() will * scan from a @e copy of @a bytes. - * @param bytes the byte buffer to scan - * @param len the number of bytes in the buffer pointed to by @a bytes. + * @param yybytes the byte buffer to scan + * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. * * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len ) +YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len ) { YY_BUFFER_STATE b; char *buf; yy_size_t n; - int i; + yy_size_t i; /* Get memory for full buffer, including space for trailing EOB's. */ n = _yybytes_len + 2; @@ -1708,7 +1705,7 @@ FILE *yyget_out (void) /** Get the length of the current token. * */ -int yyget_leng (void) +yy_size_t yyget_leng (void) { return yyleng; } diff --git a/etc/spotlight/spotlight_rawquery_lexer.l b/etc/spotlight/spotlight_rawquery_lexer.l index aa1e25f9..db7f40cd 100644 --- a/etc/spotlight/spotlight_rawquery_lexer.l +++ b/etc/spotlight/spotlight_rawquery_lexer.l @@ -9,8 +9,8 @@ #include #include #include -#ifdef HAVE_TRACKER_SPARQL -#include "slmod_sparql_parser.h" +#ifdef HAVE_TRACKER +#include "sparql_parser.h" #define SLQ_VAR ssp_slq #endif %} diff --git a/include/atalk/globals.h b/include/atalk/globals.h index dfb356a8..fb2848f3 100644 --- a/include/atalk/globals.h +++ b/include/atalk/globals.h @@ -124,7 +124,6 @@ struct afp_options { char *mimicmodel; char *adminauthuser; char *ignored_attr; - char *slmod_path; int splice_size; char *cnid_mysql_host; char *cnid_mysql_user; @@ -161,6 +160,7 @@ typedef struct AFPObj { int fce_version; char *fce_ign_names; char *fce_notify_script; + struct sl_ctx *sl_ctx; } AFPObj; /* typedef for AFP functions handlers */ diff --git a/include/atalk/spotlight.h b/include/atalk/spotlight.h index bafa52f5..69121380 100644 --- a/include/atalk/spotlight.h +++ b/include/atalk/spotlight.h @@ -26,29 +26,15 @@ #include #include -/************************************************************************************************** - * Spotlight module stuff - **************************************************************************************************/ - -#define SL_MODULE_VERSION 1 - -struct sl_module_export { - int sl_mod_version; - int (*sl_mod_init) (void *); - int (*sl_mod_start_search)(void *); - int (*sl_mod_fetch_result)(void *); - int (*sl_mod_end_search) (void *); - int (*sl_mod_fetch_attrs) (void *); - int (*sl_mod_error) (void *); - int (*sl_mod_index_file) (const void *); -}; - -extern int sl_mod_load(AFPObj *obj); -extern void sl_index_file(const char *path); +#ifdef HAVE_TRACKER +#include +#include +#include +#endif -/************************************************************************************************** +/****************************************************************************** * Spotlight RPC and marshalling stuff - **************************************************************************************************/ + ******************************************************************************/ /* FPSpotlightRPC subcommand codes */ #define SPOTLIGHT_CMD_OPEN 1 @@ -61,59 +47,81 @@ extern void sl_index_file(const char *path); #define SL_ENC_BIG_ENDIAN 2 #define SL_ENC_UTF_16 4 -typedef DALLOC_CTX sl_array_t; /* an array of elements */ -typedef DALLOC_CTX sl_dict_t; /* an array of key/value elements */ -typedef DALLOC_CTX sl_filemeta_t; /* contains one sl_array_t */ -typedef int sl_nil_t; /* a nil element */ -typedef bool sl_bool_t; /* a boolean, we avoid bool_t as it's a define for something else */ -typedef struct timeval sl_time_t; /* a boolean, we avoid bool_t as it's a define for something else */ +typedef DALLOC_CTX sl_array_t; /* an array of elements */ +typedef DALLOC_CTX sl_dict_t; /* an array of key/value elements */ +typedef DALLOC_CTX sl_filemeta_t; /* contains one sl_array_t */ +typedef int sl_nil_t; /* a nil element */ +typedef bool sl_bool_t; /* a boolean, we avoid bool_t */ +typedef struct timeval sl_time_t; typedef struct { char sl_uuid[16]; -} sl_uuid_t; /* a UUID */ +} sl_uuid_t; /* a UUID */ typedef struct { uint16_t ca_unkn1; uint32_t ca_context; DALLOC_CTX *ca_cnids; -} sl_cnids_t; /* an array of CNIDs */ +} sl_cnids_t; /* an array of CNIDs */ -/************************************************************************************************** +/****************************************************************************** * Some helper stuff dealing with queries - **************************************************************************************************/ + ******************************************************************************/ -/* Internal query state */ +/* query state */ typedef enum { - SLQ_STATE_NEW = 1, /* Query received from client */ - SLQ_STATE_RUNNING = 2, /* Query dispatched to Tracker */ - SLQ_STATE_DONE = 3, /* Tracker finished */ - SLQ_STATE_END = 4, /* Query results returned to client */ - SLQ_STATE_ATTRS = 5 /* Fetch metadata for an object */ + SLQ_STATE_NEW, /* Query received from client */ + SLQ_STATE_RUNNING, /* Query dispatched to Tracker */ + SLQ_STATE_RESULTS, /* Async Tracker query read */ + SLQ_STATE_DONE, /* Got all results from Tracker */ + SLQ_STATE_CANCEL_PENDING, /* a cancel op for the query is pending */ + SLQ_STATE_CANCELLED, /* the query has been cancelled */ + SLQ_STATE_ERROR /* an error happended somewhere */ } slq_state_t; +/* Handle for query results */ +struct sl_rslts { + int num_results; + sl_cnids_t *cnids; + sl_array_t *fm_array; +}; + /* Internal query data structure */ typedef struct _slq_t { - struct list_head slq_list; /* queries are stored in a list */ - slq_state_t slq_state; /* State */ - AFPObj *slq_obj; /* global AFPObj handle */ - const struct vol *slq_vol; /* volume handle */ - DALLOC_CTX *slq_reply; /* reply handle */ - time_t slq_time; /* timestamp where we received this query */ - uint64_t slq_ctx1; /* client context 1 */ - uint64_t slq_ctx2; /* client context 2 */ - sl_array_t *slq_reqinfo; /* array with requested metadata */ - const char *slq_qstring; /* the Spotlight query string */ - uint64_t *slq_cnids; /* Pointer to array with CNIDs to which a query applies */ - size_t slq_cnids_num; /* Size of slq_cnids array */ - const char *slq_path; /* Path to file or dir, used in fetchAttributes */ - void *slq_tracker_cursor; /* Tracker SPARQL query result cursor */ - bool slq_allow_expr; /* Whether to allow logic expressions */ - uint64_t slq_result_limit; /* Whether to LIMIT SPARQL results, default of 0 means no limit */ + struct list_head slq_list; /* queries are stored in a list */ + slq_state_t slq_state; /* State */ + AFPObj *slq_obj; /* global AFPObj handle */ + const struct vol *slq_vol; /* volume handle */ + time_t slq_time; /* timestamp received query */ + uint64_t slq_ctx1; /* client context 1 */ + uint64_t slq_ctx2; /* client context 2 */ + sl_array_t *slq_reqinfo; /* array with requested metadata */ + const char *slq_qstring; /* the Spotlight query string */ + uint64_t *slq_cnids; /* Pointer to array with CNIDs */ + size_t slq_cnids_num; /* Size of slq_cnids array */ + void *tracker_cursor; /* Tracker SPARQL cursor */ + bool slq_allow_expr; /* Whether to allow expressions */ + uint64_t slq_result_limit; /* Whether to LIMIT SPARQL results */ + struct sl_rslts *query_results; /* query results */ +#ifdef HAVE_TRACKER + GCancellable *cancellable; +#endif } slq_t; -/************************************************************************************************** +struct sl_ctx { +#ifdef HAVE_TRACKER + TrackerSparqlConnection *tracker_con; + GCancellable *cancellable; + GMainLoop *mainloop; +#endif + slq_t *query_list; /* list of active queries */ +}; + +/****************************************************************************** * Function declarations - **************************************************************************************************/ + ******************************************************************************/ -extern int afp_spotlight_rpc(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen); +extern int spotlight_init(AFPObj *obj); +extern int afp_spotlight_rpc(AFPObj *obj, char *ibuf, size_t ibuflen _U_, + char *rbuf, size_t *rbuflen); extern int sl_pack(DALLOC_CTX *query, char *buf); extern int sl_unpack(DALLOC_CTX *query, const char *buf); extern void configure_spotlight_attributes(const char *attributes); diff --git a/include/atalk/util.h b/include/atalk/util.h index 6d92e15d..94aab1af 100644 --- a/include/atalk/util.h +++ b/include/atalk/util.h @@ -131,6 +131,10 @@ extern void *mod_symbol (void *, const char *); #define mod_close(a) dlclose(a) #endif /* ! HAVE_DLFCN_H */ +#ifndef strequal +#define strequal(a,b) (strcmp((a),(b)) == 0) +#endif + /****************************************************************** * locking.c ******************************************************************/ diff --git a/libatalk/util/netatalk_conf.c b/libatalk/util/netatalk_conf.c index b5652608..16ade10c 100644 --- a/libatalk/util/netatalk_conf.c +++ b/libatalk/util/netatalk_conf.c @@ -1861,9 +1861,6 @@ int afp_config_parse(AFPObj *AFPObj, char *processname) options->configfile = AFPObj->cmdlineconfigfile ? strdup(AFPObj->cmdlineconfigfile) : strdup(_PATH_CONFDIR "afp.conf"); options->sigconffile = strdup(_PATH_STATEDIR "afp_signature.conf"); options->uuidconf = strdup(_PATH_STATEDIR "afp_voluuid.conf"); -#ifdef HAVE_TRACKER_SPARQL - options->slmod_path = strdup(_PATH_AFPDUAMPATH "slmod_sparql.so"); -#endif options->flags = OPTION_UUID | AFPObj->cmdlineflags; if ((config = atalk_iniparser_load(AFPObj->options.configfile)) == NULL) @@ -2153,9 +2150,6 @@ void afp_config_free(AFPObj *obj) CONFIG_ARG_FREE(obj->options.fqdn); if (obj->options.ignored_attr) CONFIG_ARG_FREE(obj->options.ignored_attr); - if (obj->options.slmod_path) - CONFIG_ARG_FREE(obj->options.slmod_path); - if (obj->options.unixcodepage) CONFIG_ARG_FREE(obj->options.unixcodepage); if (obj->options.maccodepage) diff --git a/macros/netatalk.m4 b/macros/netatalk.m4 index 060e4679..ddbd3498 100644 --- a/macros/netatalk.m4 +++ b/macros/netatalk.m4 @@ -169,8 +169,6 @@ AC_DEFUN([AC_NETATALK_SPOTLIGHT], [ fi else AC_DEFINE(HAVE_TRACKER, 1, [Define if Tracker is available]) - AC_DEFINE(HAVE_TRACKER_SPARQL, 1, [Define if Tracker SPARQL is available]) - AC_DEFINE(HAVE_TRACKER_MINER, 1, [Define if Tracker miner library is available]) AC_DEFINE_UNQUOTED(TRACKER_PREFIX, ["$ac_cv_tracker_prefix"], [Path to Tracker]) AC_DEFINE([DBUS_DAEMON_PATH], ["/bin/dbus-daemon"], [Path to dbus-daemon]) fi @@ -183,7 +181,7 @@ AC_DEFUN([AC_NETATALK_SPOTLIGHT], [ AC_SUBST(TRACKER_LIBS) AC_SUBST(TRACKER_MINER_CFLAGS) AC_SUBST(TRACKER_MINER_LIBS) - AM_CONDITIONAL(HAVE_TRACKER_SPARQL, [test x"$ac_cv_have_tracker_sparql" = x"yes"]) + AM_CONDITIONAL(HAVE_TRACKER, [test x"$ac_cv_have_tracker_sparql" = x"yes"]) ]) dnl Whether to disable bundled libevent