X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Futil.cpp;h=4a533b1e6be8fce4494f5ef918538580292cf712;hb=ccb3175f21446689741af2e783d5024a2355242b;hp=fc304cab46691ec10536e9ddce14943106b8a9a3;hpb=df8db6d8a539fa6d793aeb541f7c64d625c91d42;p=metaproxy-moved-to-github.git diff --git a/src/util.cpp b/src/util.cpp index fc304ca..4a533b1 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,4 +1,4 @@ -/* $Id: util.cpp,v 1.4 2006-01-13 15:09:35 adam Exp $ +/* $Id: util.cpp,v 1.6 2006-01-17 13:34:51 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -8,8 +8,10 @@ #include #include +#include #include "util.hpp" + bool yp2::util::pqf(ODR odr, Z_APDU *apdu, const std::string &q) { YAZ_PQF_Parser pqf_parser = yaz_pqf_create(); @@ -28,6 +30,76 @@ bool yp2::util::pqf(ODR odr, Z_APDU *apdu, const std::string &q) { return true; } +int yp2::util::get_vhost_otherinfo(Z_OtherInformation **otherInformation, + bool remove_flag, + std::list &vhosts) +{ + int cat; + for (cat = 1; ; cat++) + { + // check virtual host + const char *vhost = + yaz_oi_get_string_oidval(otherInformation, + VAL_PROXY, + cat /* categoryValue */, + remove_flag /* delete flag */); + if (!vhost) + break; + vhosts.push_back(std::string(vhost)); + } + --cat; + return cat; +} + +void yp2::util::split_zurl(std::string zurl, std::string &host, + std::list &db) +{ + const char *zurl_cstr = zurl.c_str(); + const char *sep = strchr(zurl_cstr, '/'); + + if (sep) + { + host = std::string(zurl_cstr, sep - zurl_cstr); + + const char *cp1 = sep+1; + while(1) + { + const char *cp2 = strchr(cp1, '+'); + if (cp2) + db.push_back(std::string(cp1, cp2 - cp1)); + else + { + db.push_back(std::string(cp1)); + break; + } + cp1 = cp2+1; + } + } + else + { + host = zurl; + } +} + +bool yp2::util::set_databases_from_zurl(ODR odr, std::string zurl, + int *db_num, char ***db_strings) +{ + std::string host; + std::list dblist; + + split_zurl(zurl, host, dblist); + + if (dblist.size() == 0) + return false; + *db_num = dblist.size(); + *db_strings = (char **) odr_malloc(odr, sizeof(char*) * (*db_num)); + + std::list::const_iterator it = dblist.begin(); + for (int i = 0; it != dblist.end(); it++, i++) + (*db_strings)[i] = odr_strdup(odr, it->c_str()); + return true; +} + yp2::odr::odr(int type) { m_odr = odr_createmem(type);