]> arthur.barton.de Git - netatalk.git/blobdiff - etc/spotlight/slmod_sparql_parser.y
Spotlight: new options for controlling query behaviour
[netatalk.git] / etc / spotlight / slmod_sparql_parser.y
index 0763b39c913a08e89131440c0f7c486ab213a0bf..e4069bbe381892be8a67f2d877f9400f4ecd6796 100644 (file)
@@ -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 ?url WHERE "
-                                 "{ %s . ?obj nie:url ?url . FILTER(tracker:uri-is-descendant('file://%s/', ?url)) } LIMIT 100",
-                                 $1, ssp_slq->slq_vol->v_path);
+                                 "{ %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,10 @@ BOOL                             {
         YYABORT;
 }
 | match OR match                 {
+    if (!ssp_slq->slq_allow_expr)
+        YYABORT;
+    if ($1 == NULL || $3 == NULL)
+        YYABORT;
     if (strcmp($1, $3) != 0)
         $$ = talloc_asprintf(ssp_slq, "{ %s } UNION { %s }", $1, $3);
     else
@@ -95,7 +104,11 @@ 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)
+        YYABORT;
+    $$ = talloc_asprintf(ssp_slq, "%s . %s", $1, $3);
+}
 | expr OR expr                 {
     if (strcmp($1, $3) != 0)
         $$ = talloc_asprintf(ssp_slq, "{ %s } UNION { %s }", $1, $3);
@@ -206,7 +219,7 @@ 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 (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;
@@ -331,6 +344,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]);