From: Adam Dickmeiss Date: Mon, 6 Oct 2003 08:08:49 +0000 (+0000) Subject: Allow ranges for query attributes X-Git-Tag: YAZPP.0.7.pre1~7 X-Git-Url: http://git.indexdata.com/?p=yazpp-moved-to-github.git;a=commitdiff_plain;h=c33e210d2827f71ab8bf61c36662425809f7d933 Allow ranges for query attributes --- diff --git a/include/yaz++/proxy.h b/include/yaz++/proxy.h index c40a13d..ca44ea0 100644 --- a/include/yaz++/proxy.h +++ b/include/yaz++/proxy.h @@ -2,7 +2,7 @@ * Copyright (c) 1998-2003, Index Data. * See the file LICENSE for details. * - * $Id: proxy.h,v 1.9 2003-10-03 13:01:42 adam Exp $ + * $Id: proxy.h,v 1.10 2003-10-06 08:08:49 adam Exp $ */ #include @@ -49,6 +49,9 @@ private: char **addinfo); #endif int m_copy; + int match_list(int v, const char *m); + int atoi_l(const char **cp); + }; class YAZ_EXPORT Yaz_RecordCache { diff --git a/src/config.xml b/src/config.xml index af63747..19d0b06 100644 --- a/src/config.xml +++ b/src/config.xml @@ -22,7 +22,7 @@ 11 10 - + diff --git a/src/yaz-proxy-config.cpp b/src/yaz-proxy-config.cpp index 6132ed7..d1ba17c 100644 --- a/src/yaz-proxy-config.cpp +++ b/src/yaz-proxy-config.cpp @@ -2,9 +2,10 @@ * Copyright (c) 1998-2003, Index Data. * See the file LICENSE for details. * - * $Id: yaz-proxy-config.cpp,v 1.3 2003-10-04 06:44:16 adam Exp $ + * $Id: yaz-proxy-config.cpp,v 1.4 2003-10-06 08:08:49 adam Exp $ */ +#include #include #include @@ -173,6 +174,40 @@ void Yaz_ProxyConfig::return_target_info(xmlNodePtr ptr, } #endif +int Yaz_ProxyConfig::atoi_l(const char **cp) +{ + int v = 0; + while (**cp && isdigit(**cp)) + { + v = v*10 + (**cp - '0'); + (*cp)++; + } + return v; +} + +int Yaz_ProxyConfig::match_list(int v, const char *m) +{ + while(m && *m) + { + while(*m && isspace(*m)) + m++; + if (*m == '*') + return 1; + int l = atoi_l(&m); + int h = l; + if (*m == '-') + { + ++m; + h = atoi_l(&m); + } + if (v >= l && v <= h) + return 1; + if (*m == ',') + m++; + } + return 0; +} + #if HAVE_XML2 int Yaz_ProxyConfig::check_type_1_attributes(ODR odr, xmlNodePtr ptr, Z_AttributeList *attrs, @@ -213,19 +248,14 @@ int Yaz_ProxyConfig::check_type_1_attributes(ODR odr, xmlNodePtr ptr, continue; int type = *el->attributeType; - if (strcmp(match_type, "*")) { - if (type != atoi(match_type)) - continue; // no match on type - } + if (!match_list(type, match_type)) + continue; if (el->which == Z_AttributeValue_numeric && el->value.numeric) { - int value = *el->value.numeric; - if (strcmp(match_value, "*")) { - if (value != atoi(match_value)) - continue; // no match on value - } - sprintf(value_str, "%d", value); + if (!match_list(*el->value.numeric, match_value)) + continue; + sprintf (value_str, "%d", *el->value.numeric); } else continue;