X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=etc%2Fspotlight%2Fslmod_sparql_parser.y;h=76d8b5a768d5b668c72f093b1adf1ebfb3f8dda9;hb=0612081546981aae6caa7fde0f60fee10d9b688a;hp=301129696dfa1fb77fd2ecfd0b4f88b2518ceb44;hpb=2543f8977bd9392f695a75704ad300958f49ec47;p=netatalk.git diff --git a/etc/spotlight/slmod_sparql_parser.y b/etc/spotlight/slmod_sparql_parser.y index 30112969..76d8b5a7 100644 --- a/etc/spotlight/slmod_sparql_parser.y +++ b/etc/spotlight/slmod_sparql_parser.y @@ -34,6 +34,7 @@ /* local vars */ static gchar *ssp_result; static char sparqlvar; + static char *result_limit; %} %code provides { @@ -71,10 +72,14 @@ input: 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 DISTINCT ?url WHERE " - "{ ?obj nie:url ?url FILTER(regex(?url, '^file://%s/')) . %s}", - ssp_slq->slq_vol->v_path, $1); + "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; } ; @@ -87,6 +92,8 @@ BOOL { 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 @@ -95,8 +102,18 @@ BOOL { | match {$$ = $1; if ($$ == NULL) YYABORT;} | function {$$ = $1;} | OBRACE expr CBRACE {$$ = talloc_asprintf(ssp_slq, "%s", $2);} -| expr AND expr {$$ = talloc_asprintf(ssp_slq, "%s . %s", $1, $3);} +| 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 @@ -206,7 +223,11 @@ static const char *map_expr(const char *attr, char op, const char *val) bstring q = NULL, search = NULL, replace = NULL; for (p = spotlight_sparql_map; p->ssm_spotlight_attr; p++) { - if (p->ssm_sparql_attr && strcmp(p->ssm_spotlight_attr, attr) == 0) { + 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); @@ -252,7 +273,6 @@ static const char *map_expr(const char *attr, char op, const char *val) result = map_type_search(attr, op, val); break; default: - yyerror("unknown Spotlight attribute type"); EC_FAIL; } break; @@ -328,6 +348,7 @@ int main(int argc, char **argv) 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]);