Check for valid limitmap
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 7 Nov 2011 11:23:32 +0000 (12:23 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 7 Nov 2011 11:23:32 +0000 (12:23 +0100)
src/client.c
src/session.c

index c9ac78f..0ae3641 100644 (file)
@@ -988,10 +988,11 @@ static char *make_solrquery(struct client *cl)
     return r;
 }
 
-static void apply_limit(struct session_database *sdb,
-                        facet_limits_t facet_limits,
-                        WRBUF w_pqf, WRBUF w_ccl)
+static int apply_limit(struct session_database *sdb,
+                       facet_limits_t facet_limits,
+                       WRBUF w_pqf, WRBUF w_ccl)
 {
+    int ret = 0;
     int i = 0;
     const char *name;
     const char *value;
@@ -1043,6 +1044,14 @@ static void apply_limit(struct session_database *sdb,
                     wrbuf_puts(w_ccl, ")");
 
                 }
+                else if (!strncmp(s->value, "local:", 6))
+                    ;
+                else
+                {
+                    yaz_log(YLOG_WARN, "Target %s: Bad limitmap '%s'",
+                            sdb->database->id, s->value);
+                    ret = -1; /* bad limitmap */
+                }
                 break;
             }
         }
@@ -1054,6 +1063,7 @@ static void apply_limit(struct session_database *sdb,
         }
     }
     nmem_destroy(nmem_tmp);
+    return ret;
 }
                         
 // Parse the query given the settings specific to this client
@@ -1099,7 +1109,8 @@ int client_parse_query(struct client *cl, const char *query,
         wrbuf_puts(w_pqf, " ");
     }
 
-    apply_limit(sdb, facet_limits, w_pqf, w_ccl);
+    if (apply_limit(sdb, facet_limits, w_pqf, w_ccl))
+        return -2;
 
     yaz_log(YLOG_LOG, "CCL query: %s", wrbuf_cstr(w_ccl));
     cn = ccl_find_str(ccl_map, wrbuf_cstr(w_ccl), &cerror, &cpos);
index a48f69b..ac41b36 100644 (file)
@@ -689,7 +689,8 @@ enum pazpar2_error_code session_search(struct session *se,
 {
     int live_channels = 0;
     int no_working = 0;
-    int no_failed = 0;
+    int no_failed_query = 0;
+    int no_failed_limit = 0;
     struct client_list *l, *l0;
     struct timeval tval;
     facet_limits_t facet_limits;
@@ -753,8 +754,10 @@ enum pazpar2_error_code session_search(struct session *se,
 
         parse_ret = client_parse_query(cl, query, facet_limits, startrecs,
             maxrecs);
-        if (parse_ret < 0)
-            no_failed++;
+        if (parse_ret == -1)
+            no_failed_query++;
+        else if (parse_ret == -2)
+            no_failed_limit++;
         else if (parse_ret == 0)
         {
             session_log(se, YLOG_LOG, "client NEW %s", client_get_id(cl));
@@ -783,11 +786,16 @@ enum pazpar2_error_code session_search(struct session *se,
 
     if (no_working == 0)
     {
-        if (no_failed > 0)
+        if (no_failed_query > 0)
         {
             *addinfo = "query";
             return PAZPAR2_MALFORMED_PARAMETER_VALUE;
         }
+        else if (no_failed_limit > 0)
+        {
+            *addinfo = "limit";
+            return PAZPAR2_MALFORMED_PARAMETER_VALUE;
+        }
         else
             return PAZPAR2_NO_TARGETS;
     }