From 62d506c24aaf543f84c82e2850a05b1387e4990d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 9 Jan 2021 13:58:38 +0000 Subject: Clang format --- service/apiImpl.cpp | 70 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 30 deletions(-) (limited to 'service/apiImpl.cpp') diff --git a/service/apiImpl.cpp b/service/apiImpl.cpp index 5a1e7a6..01f06c7 100644 --- a/service/apiImpl.cpp +++ b/service/apiImpl.cpp @@ -1,51 +1,53 @@ #include "apiImpl.h" #include "uptr.h" -#include #include #include +#include -#include -#include +#include #include #include -#include +#include +#include #define CESSO(curl, opt, expr) \ BOOST_VERIFY_MSG(CURLE_OK == curl_easy_setopt(curl.get(), opt, expr), "Failed setting option " #opt); namespace MirrorSearch { SearchImpl::SearchImpl(const DB::ConnectionPoolPtr & db) : - IceTray::AbstractDatabaseClient(db), - log(LOGMANAGER()->getLogger()) + IceTray::AbstractDatabaseClient(db), log(LOGMANAGER()->getLogger()) { } - SearchServices SearchImpl::getServices(const ::Ice::Current&) + SearchServices + SearchImpl::getServices(const ::Ice::Current &) { return fetch(sql::getServices); } - template + template void - libxmlErrorHandler(const std::string & fn, const P & ... p) + libxmlErrorHandler(const std::string & fn, const P &... p) { throw XmlError(Fmt::get(fn, xmlGetLastError()->message, p...)); } - template - auto lEHB(const P & ... p) + template + auto + lEHB(const P &... p) { return std::bind(&libxmlErrorHandler, std::placeholders::_1, p...); } - template + template void - curlErrorHandler(const std::string & fn, const char * errbuf, const P & ... p) + curlErrorHandler(const std::string & fn, const char * errbuf, const P &... p) { throw CurlError(Fmt::get(fn, errbuf, p...)); } - template - auto cEHB(const char * errbuf, const P & ... p) + template + auto + cEHB(const char * errbuf, const P &... p) { return std::bind(&curlErrorHandler, std::placeholders::_1, errbuf, p...); } @@ -57,18 +59,21 @@ namespace MirrorSearch { typedef std::function CurlWriteCallback; - static size_t write_callback(char * ptr, size_t size, size_t nmemb, void * userdata) + static size_t + write_callback(char * ptr, size_t size, size_t nmemb, void * userdata) { return (*(MirrorSearch::CurlWriteCallback *)(userdata))(ptr, size * nmemb); } AdHocFormatter(Read, "Failed to read in %? (%?) [%?]"); - UPtr getDoc(const SearchServicePtr & ss, const std::string & fn) { + UPtr + getDoc(const SearchServicePtr & ss, const std::string & fn) + { auto fmt = AdHoc::Buffer::getFormat(ss->baseurl); auto url = (fmt % fn).str(); char errbuf[CURL_ERROR_SIZE] = ""; - xmlParserCtxtSPtr ctx { nullptr, nullptr }; + xmlParserCtxtSPtr ctx {nullptr, nullptr}; auto curl = make_unique(curl_easy_init, curl_easy_cleanup, cEHB(errbuf, url)); BOOST_ASSERT(curl); @@ -76,8 +81,8 @@ namespace MirrorSearch { CESSO(curl, CURLOPT_WRITEFUNCTION, write_callback); CurlWriteCallback cb = [&ctx, &url, &ss](auto data, auto size) { if (!ctx) { - ctx = make_unique(htmlCreatePushParserCtxt, htmlFreeParserCtxt, lEHB(url), - (xmlSAXHandlerPtr)NULL, (void*)NULL, data, size, url.c_str(), XML_CHAR_ENCODING_NONE); + ctx = make_unique(htmlCreatePushParserCtxt, htmlFreeParserCtxt, lEHB(url), (xmlSAXHandlerPtr)NULL, + (void *)NULL, data, size, url.c_str(), XML_CHAR_ENCODING_NONE); htmlCtxtUseOptions(ctx.get(), ss->parserflags); } else { @@ -99,7 +104,7 @@ namespace MirrorSearch { CESSO(curl, CURLOPT_TCP_FASTOPEN, 1L); CESSO(curl, CURLOPT_FAILONERROR, 1L); if (curl_easy_perform(curl.get()) != CURLE_OK) { - curlErrorHandler(failingFunction((void*)&curl_easy_perform), errbuf, url); + curlErrorHandler(failingFunction((void *)&curl_easy_perform), errbuf, url); } if (!ctx) { throw CurlError("Did not retrieve any data."); @@ -109,27 +114,31 @@ namespace MirrorSearch { throw XmlError("Could not construct a document."); } - UPtr doc = { ctx->myDoc, xmlFreeDoc }; + UPtr doc = {ctx->myDoc, xmlFreeDoc}; return doc; } AdHocFormatter(XPathCtx, "Failed to create xpath context in %? (%?)"); - static auto getXPathCxt(const xmlDocSPtr & doc) + static auto + getXPathCxt(const xmlDocSPtr & doc) { return make_unique(xmlXPathNewContext, xmlXPathFreeContext, lEHB(), doc.get()); } AdHocFormatter(XPathEval, "Failed to evaluate xpath in %? (%?) [%?]"); - static auto getXPathObj(const ::std::string & xpath, const xmlXPathContextSPtr & ctx, xmlXPathObjectType type) + static auto + getXPathObj(const ::std::string & xpath, const xmlXPathContextSPtr & ctx, xmlXPathObjectType type) { - auto xpathObj = make_unique(xmlXPathEvalExpression, xmlXPathFreeObject, lEHB(xpath), BAD_CAST xpath.c_str(), ctx.get()); + auto xpathObj = make_unique( + xmlXPathEvalExpression, xmlXPathFreeObject, lEHB(xpath), BAD_CAST xpath.c_str(), ctx.get()); if (xpathObj->type != type) { throw XmlError("Xpath evaluates to wrong type " + xpath); } return xpathObj; } - void SearchImpl::callService(const ::std::string & fn, const SearchServicePtr & s, SearchHits & sh) const + void + SearchImpl::callService(const ::std::string & fn, const SearchServicePtr & s, SearchHits & sh) const { auto doc = getDoc(s, fn); auto xpathCtx = getXPathCxt(doc); @@ -142,12 +151,13 @@ namespace MirrorSearch { xpathCtx->node = xpathObj->nodesetval->nodeTab[row]; auto xpathObjI = getXPathObj(s->urlxpath, xpathCtx, xmlXPathObjectType::XPATH_STRING); if (xpathObjI->stringval && *xpathObjI->stringval) { - sh.push_back(std::make_shared(0, s->id, (const char *) xpathObjI->stringval)); + sh.push_back(std::make_shared(0, s->id, (const char *)xpathObjI->stringval)); } } } - SearchHits SearchImpl::getMatches(const ::std::string fn, const ::Ice::Current & c) + SearchHits + SearchImpl::getMatches(const ::std::string fn, const ::Ice::Current & c) { SearchHits sh; for (const auto & s : getServices(c)) { @@ -156,7 +166,8 @@ namespace MirrorSearch { return sh; } - ::IceUtil::Optional<::std::string> SearchImpl::feelingLucky(const ::std::string fn, const ::Ice::Current & c) + ::IceUtil::Optional<::std::string> + SearchImpl::feelingLucky(const ::std::string fn, const ::Ice::Current & c) { const auto ms = getMatches(fn, c); if (ms.empty()) @@ -164,4 +175,3 @@ namespace MirrorSearch { return ms.front()->url; } } - -- cgit v1.2.3