string SoapExecution::callServer(shared_ptr<Url> url, string request) { struct MemoryStruct chunk; chunk.memory = (char*)malloc(1); chunk.size = 0; curl_global_init(CURL_GLOBAL_ALL); CURL *curl = curl_easy_init(); if (!curl) { THROW_EXC("curl initialization failed"); } curl_easy_setopt(curl, CURLOPT_URL, getUrl()->getUrl().c_str()); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk); curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0"); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request.c_str()); curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)request.size()); CURLcode res = curl_easy_perform(curl); if(res != CURLE_OK) { THROW_EXC("perform failed:" << curl_easy_strerror(res)); } curl_easy_cleanup(curl); return string(chunk.memory); }
Sink(): used(0) { if (!enif_alloc_binary(0, &bin)) { enif_release_binary(&bin); THROW_EXC("enif_alloc_binary() failed"); } }
Pipeline PipelinePropVisitor::create_pipeline() { if (!check_mandatory()) THROW_EXC(IllegalValue, "Mandatory parameter is missing"); if (d_values["dline"] < 0.0) d_values["e2edline"] = i_values["period"]; Pipeline pipe(i_values["period"], i_values["e2edline"]); pipe.set_name(name); return pipe; }
void GenPropertyVisitor::operator()(const Property &p) { std::string kd = check_keyword(keywords_double, p.name); std::string ki = check_keyword(keywords_int, p.name); std::string ks = check_keyword(keywords_string, p.name); if (kd != "") { if (d_values.find(kd) != d_values.end()) THROW_EXC(ValueAlreadySet, "value already set"); else d_values[kd] = p.get_double(); } if (ki != "") { if (i_values.find(ki) != i_values.end()) THROW_EXC(ValueAlreadySet, "value already set"); else i_values[ki] = p.get_int(); } if (ks != "") { if (s_values.find(ks) != s_values.end()) THROW_EXC(ValueAlreadySet, "value already set"); else s_values[ks] = p.get_value(); } }
Pipeline create_pipeline(const PropertyList &p) { if( p.type != "pipelineprop") THROW_EXC(IncorrectType, "Expecting a pipeline property type"); PipelinePropVisitor vis; vis(p); return vis.create_pipeline(); }
ErlNifBinary& GetBinary() { size_t allocated = bin.size; if (allocated > used) { if (!enif_realloc_binary(&bin, used)) { enif_release_binary(&bin); THROW_EXC("enif_realloc_binary() failed"); } } return bin; }
xmlDocPtr parseDoc(std::string document, std::string baseUri, bool resolveXIncludes) { xmlDocPtr doc = xmlReadMemory(document.c_str(), document.size(), baseUri.c_str(), NULL, 0); if (doc == nullptr) { THROW_EXC("failed to parse xml queries"); } if (resolveXIncludes) { int ret = xmlXIncludeProcess(doc); if (ret < 0) { THROW_EXC("xinclude failed"); } } string schemaUrl; xmlNodePtr tmp = doc->children; while (tmp) { if (tmp->type == XML_ELEMENT_NODE) { xmlAttributePtr attr = ((xmlElementPtr)tmp)->attributes; while (attr) { if (string((char*)attr->name) == "noNamespaceSchemaLocation" && string("http://www.w3.org/2001/XMLSchema-instance") == (char*)((xmlNodePtr)attr)->ns->href ) { schemaUrl = (char*)attr->children->content; } attr = (xmlAttribute*)attr->next; } } tmp = tmp->next; } LOG_INFO("using schema '" << schemaUrl << "' for validating"); char *absUri = (char*)xmlBuildURI((xmlChar*)schemaUrl.c_str(),(xmlChar*)baseUri.c_str()); if (!schemaUrl.empty()) { validateDoc(doc,baseUri, string(absUri)); } return doc; }
char* GetAppendBuffer(size_t len, char*) { size_t allocated = bin.size; if ((used + len) > allocated) { size_t sz = len > ALLOC_SIZE ? len + ALLOC_SIZE - (len % ALLOC_SIZE) : ALLOC_SIZE; if (!enif_realloc_binary(&bin, allocated + sz)) { enif_release_binary(&bin); THROW_EXC("enif_realloc_binary() failed"); } } return reinterpret_cast<char*>(bin.data + used); }
void validateDoc(xmlDocPtr doc, std::string baseUri, std::string schemaFile) { xmlSchemaParserCtxtPtr ctx = xmlSchemaNewParserCtxt(schemaFile.c_str()); if (ctx) { xmlSchemaSetParserErrors(ctx,(xmlSchemaValidityErrorFunc)errorHandler,(xmlSchemaValidityWarningFunc)warningHandler,nullptr); xmlSchemaPtr schema = xmlSchemaParse(ctx); xmlSchemaFreeParserCtxt(ctx); // validate xmlSchemaValidCtxtPtr vctx = xmlSchemaNewValidCtxt(schema); xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc)errorHandler, (xmlSchemaValidityErrorFunc)warningHandler,nullptr); int ret = xmlSchemaValidateDoc(vctx, doc); xmlSchemaFreeValidCtxt(vctx); xmlSchemaFree(schema); if (ret != 0) { THROW_EXC("xml file '" << baseUri << "' is not valid"); } } }
void SoapExecution::prepareQuery() { string xml = "<query xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>"; xml += getSql(); xml += "</query>"; LOG_DEBUG("about to parse"); xmlDocPtr doc = xmlParseDoc((xmlChar*)xml.c_str()); xmlNodePtr queryElement = xmlDocGetRootElement(doc); xmlNodePtr tmp = queryElement->children; xmlNodePtr inputNode = nullptr; xmlNodePtr outputNode = nullptr; while(tmp) { if (tmp->type == XML_ELEMENT_NODE) { if (inputNode == nullptr) { inputNode = tmp; } else { outputNode = tmp; } } tmp = tmp->next; } if (inputNode == nullptr || outputNode == nullptr) { THROW_EXC("input or output node missing."); } LOG_DEBUG("inputNode = " << inputNode->name); LOG_DEBUG("outputNode = " << outputNode->name);; xmlNodePtr inputQuery = xmlDocCopyNode(inputNode,doc,1); xmlNodePtr outputQuery = xmlDocCopyNode(outputNode,doc,1); assert(getInPorts().size() == 1); inputTemplate.setStylesheet(inputQuery); outputTemplate.setStylesheet(outputQuery); }
void check_and_store_values(std::map<std::string, T> &m, const std::string &n, T v) { if (m.find(n) != m.end()) THROW_EXC(ValueAlreadySet, "value already set"); else m[n] = v; }
bool Config::init(int argc, char **argv) { namespace bpo = boost::program_options; bpo::options_description generic("Basic options"); generic.add_options() ("help,h", "produce help message") ("config", bpo::value<std::string>(), "configuration file") ; bpo::options_description advanced("Advanced options"); advanced.add_options() ("bind-addr", bpo::value<std::string>(), "ip:port to bind") ("db-file", bpo::value<std::string>(), "database file") ("access-log-file", bpo::value<std::string>(), "access log file") ("detector", bpo::value<std::string>()->default_value(std::string("SURF")), "image features detector type") ("extractor", bpo::value<std::string>()->default_value(std::string("SURF")), "image features extractor type") ("matcher", bpo::value<std::string>()->default_value(std::string("FlannBased")), "image features matcher type") ("resize", bpo::value<bool>()->zero_tokens()->default_value(false), "resize image before processing") ; bpo::options_description cmdline_options; cmdline_options.add(generic).add(advanced); bpo::options_description config_file_options; config_file_options.add(advanced); try { bpo::store(bpo::parse_command_line(argc, argv, cmdline_options), vm); bpo::notify(vm); } catch (std::exception &e) { THROW_EXC("Parser failed: %s", e.what()); } if (vm.count("help")) { std::cout << cmdline_options << std::endl; return false; } if (!vm.count("config")) { std::cerr << "Config file is not specified. Run " << argv[0] << " --help for options." << std::endl; return false; } std::string filename = vm["config"].as<std::string>(); std::ifstream file(filename.c_str(), std::ios::in|std::ios::binary); if (file.fail()) { THROW_EXC("Can't open file: %s", filename.c_str()); } try { bpo::store(bpo::parse_config_file(file, config_file_options), vm); bpo::notify(vm); } catch (std::exception &e) { THROW_EXC("Parser failed: %s", e.what()); } check_if_param_specified("bind-addr"); check_if_param_specified("db-file"); check_if_param_specified("access-log-file"); return true; }