void TR_svtImp::loadDataset(const string &path) { train.push_back(vector< Ptr<Object> >()); test.push_back(vector< Ptr<Object> >()); validation.push_back(vector< Ptr<Object> >()); string trainXml(path + "train.xml"); string testXml(path + "test.xml"); // loading train images description xmlParse(trainXml, train.back()); // loading test images description xmlParse(testXml, test.back()); }
int Parse(const pchar src) { int l=strlen(src); pPool=xmemNewPool(32+l*4); pNode=xmlNew(pPool); return xmlParse(pPool,pNode,src,0); }
void terminate3 () { connect(&messageCallback, &resultCallback, &fmuStateCallback); xmlParse(FMU_FOLDER); //TypeDefDataModel * typeDefs = getTypeDefDataModel(); return; }
void terminate2 () { connect(&messageCallback, &resultCallback, &fmuStateCallback); xmlParse(FMU_FOLDER); forceCleanup(); return; }
/* **************************************************************************** * * xmlParse - * * This function is called once (actually it is not that simple) for each node in * the tree that the XML parser has built for us. * * * In the node '<contextValue>', isCompoundValuePath returns TRUE. * Under "<contextValue>", we have either a simple string or a Compound Value Tree. * In the case of a "simple string" the value of the current node is NON EMPTY, * and as the node is treated already in the previous call to 'treat()', no further action is needed. * * If a node is NOT TREATED and it is NOT a compound, a parse error is issued */ void xmlParse ( ConnectionInfo* ciP, xml_node<>* father, xml_node<>* node, const std::string& indentation, const std::string& fatherPath, XmlNode* parseVector, ParseData* parseDataP ) { std::string value = wsStrip(node->value()); std::string name = wsStrip(node->name()); std::string path = fatherPath + "/" + name; bool treated = treat(node, path, parseVector, parseDataP); if (isCompoundValuePath(path.c_str()) && (value == "") && (node->first_node() != NULL)) { // // Count children (to avoid false compounds because of just en empty sttribute value) // xml_node<>* child = node->first_node(); int children = 0; while (child != NULL) { if (child->name()[0] != 0) ++children; child = child->next_sibling(); } if (children == 0) // NOT a compound value return; eatCompound(ciP, NULL, node, ""); compoundValueEnd(ciP, parseDataP); return; } else if (treated == false) { ciP->httpStatusCode = SccBadRequest; if (ciP->answer == "") ciP->answer = std::string("Unknown XML field: '") + name.c_str() + "'"; LM_W(("ERROR: '%s', PATH: '%s' ", ciP->answer.c_str(), fatherPath.c_str())); return; } // Recursive calls for all children of this node xml_node<>* child = node->first_node(); while (child != NULL) { if ((child != NULL) && (child->name() != NULL) && (onlyWs(child->name()) == false)) xmlParse(ciP, node, child, indentation + " ", path, parseVector, parseDataP); child = child->next_sibling(); } }
void terminate4 () { connect(&messageCallback, &resultCallback, &fmuStateCallback); xmlParse(FMU_FOLDER); ScalarVariablesAllStruct * ss = getAllScalarVariables(); requestStateChange(simStateNative_3_init_requested); requestStateChange(simStateNative_5_step_requested); forceCleanup(); return; }
/* **************************************************************************** * * xmlParse - */ void xmlParse(xml_node<>* father, xml_node<>* node, std::string indentation, std::string fatherPath, XmlNode* parseVector, ParseData* reqDataP) { if (node == NULL) return; if (node->name() == NULL) return; if (node->name()[0] == 0) return; std::string path = fatherPath + "/" + node->name(); // // Lookup node in the node vector // bool treated = false; for (unsigned int ix = 0; parseVector[ix].path != "LAST"; ++ix) { if (path == parseVector[ix].path) { int r; if ((r = parseVector[ix].treat(node, reqDataP)) != 0) { fprintf(stderr, "parse vector treat function error: %d\n", r); LM_E(("parse vector treat function error: %d", r)); } treated = true; break; } } if (treated == false) LM_W(("Warning: node '%s' not treated (%s)", path.c_str(), node->name())); xml_node<>* child = node->first_node(); while (child != NULL) { xmlParse(node, child, indentation + " ", path, parseVector, reqDataP); child = child->next_sibling(); } }
int ParseFile(const char* filename) { FILE *f=fopen(filename,"rt"); if(!f)return 0; fseek(f,0,SEEK_END); int size=ftell(f); fseek(f,0,SEEK_SET); char *buf=new char[size+1]; fread(buf,size,1,f); buf[size]=0; fclose(f); pPool=xmemNewPool(32+size*4); pNode=xmlNew(pPool); int res=xmlParse(pPool,pNode,buf,0); delete [] buf; return res; }
int main() { Tree *tree = new Tree(); XMLParser xmlParse("decisions.xml", tree); Randomizer r; std::string input; std::string searchType = "depthFirstSearch"; bool running = true; while (running == true) { std::cout << "Press 1 to print out XML tree of ""decisions.xml""\n"; std::cout << "Press 2 to change search type: *depthFirstSearch or breadthFirstSearch\n"; std::cout << "Press 3 to receive a response based on input\n"; std::cout << "Press q to Exit \n"; std::getline(std::cin, input); if (input == "1") { tree->printTree(tree->getRoot()); } if (input == "2") { std::cout << "Enter type: depthFirstSearch or breadthFirstSearch: "; std::getline(std::cin, searchType); } if (input == "3") { std::cout << "Press q to Escape Sequence \n"; bool getResponses = true; std::string behaviorInput; while (getResponses) { std::cout << "Enter a Behavior: "; std::getline(std::cin, behaviorInput); std::string response = r.getResponse(tree, behaviorInput, searchType); std::cout << "Response: " << response << '\n'; if (behaviorInput == "q") { getResponses = false; } } } if (input == "q") { running = false; return 0; } } }
void cText2SkinLoader::Load(const char *Skin) { cText2SkinI18n *translations = new cText2SkinI18n(Skin); cText2SkinTheme *theme = new cText2SkinTheme(Skin); std::string themefile = SkinPath() + "/" + Skin + "/" + Skin + ".colors"; theme->Load(themefile); std::string skinfile = SkinPath() + "/" + Skin + "/" + Skin + ".skin"; if (access(skinfile.c_str(), F_OK) == 0) { isyslog("parsing %s", skinfile.c_str()); cxSkin *skin = xmlParse(Skin, skinfile, translations, theme); if (skin) { if (skin->Version() <= cText2SkinPlugin::SkinVersion()) { new cText2SkinLoader(skin, translations, theme, Skin, skin->Title()); return; } else esyslog("ERROR: text2skin: Skin is version %i,%i, expecting <= %s", skin->Version().Major(), skin->Version().Minor(), cText2SkinPlugin::SkinVersion()); } else esyslog("ERROR: error in skin file"); delete skin; } }
/* **************************************************************************** * * xmlTreat - */ std::string xmlTreat ( const char* content, ConnectionInfo* ciP, ParseData* parseDataP, RequestType request, std::string payloadWord, XmlRequest** reqPP, std::string* errorMsgP ) { xml_document<> doc; char* xmlPayload = (char*) content; // // If the payload is empty, the XML parsing library does an assert // and the broker dies. // Therefore, this check here is important, to avoid death. // // 'OK' is returned as there is no error to send a request without payload. // if ((content == NULL) || (*content == 0)) { return "OK"; } try { doc.parse<0>(xmlPayload); } catch (parse_error& e) { std::string errorReply = restErrorReplyGet(ciP, ciP->outFormat, "", "unknown", SccBadRequest, "XML Parse Error"); LM_W(("Bad Input ('%s', '%s')", content, e.what())); if (errorMsgP) { *errorMsgP = std::string("XML parse error exception: ") + e.what(); } return errorReply; } catch (...) { std::string errorReply = restErrorReplyGet(ciP, ciP->outFormat, "", "unknown", SccBadRequest, "XML Parse Error"); LM_W(("Bad Input (%s)", content)); if (errorMsgP) { *errorMsgP = std::string("XML parse generic exception"); } return errorReply; } xml_node<>* father = doc.first_node(); XmlRequest* reqP = xmlRequestGet(request, ciP->method); ciP->parseDataP = parseDataP; if (father == NULL) { std::string errorReply = restErrorReplyGet(ciP, ciP->outFormat, "", "unknown", SccBadRequest, "XML Parse Error"); LM_W(("Bad Input (XML parse error)")); if (errorMsgP) { *errorMsgP = std::string("XML parse error: invalid XML input"); } return errorReply; } if (reqP == NULL) { std::string errorReply = restErrorReplyGet( ciP, ciP->outFormat, "", requestType(request), SccBadRequest, std::string("Sorry, no request treating object found for RequestType /") + requestType(request) + "/, method /" + ciP->method + "/"); LM_W(("Bad Input (no request treating object found for RequestType %d (%s), method %s)", request, requestType(request), ciP->method.c_str())); LM_W(("Bad Input (no request treating object found for RequestType %d (%s), method %s)", request, requestType(request), ciP->method.c_str())); if (errorMsgP) { *errorMsgP = std::string("Unable to treat ") + requestType(request) + " requests"; } return errorReply; } if (reqPP != NULL) { *reqPP = reqP; } // // Checking that the payload matches the URL // if (((ciP->verb == POST) || (ciP->verb == PUT)) && (payloadWord.length() != 0)) { std::string errorReply; char* payloadStart = (char*) content; // Skip '<?xml version="1.0" encoding="UTF-8"?> ' ? if (strncmp(payloadStart, "<?xml", 5) == 0) { ++payloadStart; payloadStart = strstr(payloadStart, "<"); } // Skip '<' if (*payloadStart == '<') { ++payloadStart; } if (strncasecmp(payloadWord.c_str(), payloadStart, payloadWord.length()) != 0) { errorReply = restErrorReplyGet(ciP, ciP->outFormat, "", reqP->keyword, SccBadRequest, std::string("Expected /") + payloadWord + "/ payload, got /" + payloadStart + "/"); LM_W(("Bad Input (invalid payload: wanted: '%s', got '%s')", payloadWord.c_str(), payloadStart)); if (errorMsgP) { *errorMsgP = std::string("Bad Input (invalid payload, expecting '") + payloadWord + "', got '" + payloadStart + "')"; } return errorReply; } } if (reqP->init == NULL) // No payload treating function { return "OK"; } reqP->init(parseDataP); ciP->httpStatusCode = SccOk; xmlParse(ciP, NULL, father, "", "", reqP->parseVector, parseDataP, errorMsgP); if (ciP->httpStatusCode != SccOk) { LM_W(("Bad Input (XML parse error)")); return restErrorReplyGet(ciP, ciP->outFormat, "", payloadWord, ciP->httpStatusCode, ciP->answer); } LM_T(LmtParseCheck, ("Calling check for XML parsed tree (%s)", ciP->payloadWord)); std::string check = reqP->check(parseDataP, ciP); if (check != "OK") { LM_W(("Bad Input (%s: %s)", reqP->keyword.c_str(), check.c_str())); if (errorMsgP) { *errorMsgP = std::string("Bad Input: ") + check; } } reqP->present(parseDataP); if (check != "OK") { if (errorMsgP) { *errorMsgP = std::string("Bad Input: ") + check; } } return check; }
UINT32 http_snd_req(HTTPParameters ClientParams, HTTP_VERB verb, CHAR* pSndData, u8 parseXmlJson) { INT32 nRetCode; UINT32 nSize,nTotal = 0; CHAR* Buffer = NULL; HTTP_SESSION_HANDLE pHTTP; UINT32 nSndDataLen ; #if DEMO_HTTP_XML_PARSE XML_Parser parser; #elif DEMO_HTTP_SXML_PARSE CHAR * buf_cache = NULL; UINT32 cur_pos = 0; #endif #if DEMO_HTTP_JSON_PARSE json_parser jsonParser; json_printer printer; #endif do { #if !DEMO_HTTP_XML_PARSE && DEMO_HTTP_SXML_PARSE buf_cache = (CHAR*)tls_mem_alloc(HTTP_CLIENT_BUFFER_SIZE); if(buf_cache == NULL) return HTTP_CLIENT_ERROR_NO_MEMORY; memset(buf_cache , 0, HTTP_CLIENT_BUFFER_SIZE); #endif Buffer = (CHAR*)tls_mem_alloc(HTTP_CLIENT_BUFFER_SIZE); if(Buffer == NULL) { #if !DEMO_HTTP_XML_PARSE && DEMO_HTTP_SXML_PARSE tls_mem_free(buf_cache); #endif return HTTP_CLIENT_ERROR_NO_MEMORY; } memset(Buffer, 0, HTTP_CLIENT_BUFFER_SIZE); printf("\nHTTP Client v1.0\n\n"); nSndDataLen = (pSndData==NULL ? 0 : strlen(pSndData)); // Open the HTTP request handle pHTTP = HTTPClientOpenRequest(0); if(!pHTTP) { nRetCode = HTTP_CLIENT_ERROR_INVALID_HANDLE; break; } // Set the Verb nRetCode = HTTPClientSetVerb(pHTTP,verb); if(nRetCode != HTTP_CLIENT_SUCCESS) { break; } #if TLS_CONFIG_HTTP_CLIENT_AUTH // Set authentication if(ClientParams.AuthType != AuthSchemaNone) { if((nRetCode = HTTPClientSetAuth(pHTTP,ClientParams.AuthType,NULL)) != HTTP_CLIENT_SUCCESS) { break; } // Set authentication if((nRetCode = HTTPClientSetCredentials(pHTTP,ClientParams.UserName,ClientParams.Password)) != HTTP_CLIENT_SUCCESS) { break; } } #endif //TLS_CONFIG_HTTP_CLIENT_AUTH #if TLS_CONFIG_HTTP_CLIENT_PROXY // Use Proxy server if(ClientParams.UseProxy == TRUE) { if((nRetCode = HTTPClientSetProxy(pHTTP,ClientParams.ProxyHost,ClientParams.ProxyPort,NULL,NULL)) != HTTP_CLIENT_SUCCESS) { break; } } #endif //TLS_CONFIG_HTTP_CLIENT_PROXY if((nRetCode = HTTPClientSendRequest(pHTTP,ClientParams.Uri,pSndData,nSndDataLen,verb==VerbPost || verb==VerbPut,0,0)) != HTTP_CLIENT_SUCCESS) { break; } // Retrieve the the headers and analyze them if((nRetCode = HTTPClientRecvResponse(pHTTP,30)) != HTTP_CLIENT_SUCCESS) { break; } printf("Start to receive data from remote server...\n"); #if DEMO_HTTP_XML_PARSE if(parseXmlJson == 1) xmlParseInit(&parser); #endif #if DEMO_HTTP_JSON_PARSE if(parseXmlJson == 2) jsonParseInit(&jsonParser, &printer); #endif // Get the data until we get an error or end of stream code while(nRetCode == HTTP_CLIENT_SUCCESS || nRetCode != HTTP_CLIENT_EOS) { // Set the size of our buffer nSize = HTTP_CLIENT_BUFFER_SIZE; // Get the data nRetCode = HTTPClientReadData(pHTTP,Buffer,nSize,300,&nSize); if(nRetCode != HTTP_CLIENT_SUCCESS && nRetCode != HTTP_CLIENT_EOS) break; printf("%s", Buffer); #if DEMO_HTTP_XML_PARSE if(parseXmlJson == 1) xmlParse(parser, Buffer, nSize, nRetCode == HTTP_CLIENT_EOS); #elif DEMO_HTTP_SXML_PARSE if(parseXmlJson == 1) { if(cur_pos + nSize < HTTP_CLIENT_BUFFER_SIZE-1) { memcpy(buf_cache+cur_pos, Buffer, nSize); cur_pos += nSize; if(nRetCode == HTTP_CLIENT_EOS) sxml_parse_all(buf_cache); } } #endif #if DEMO_HTTP_JSON_PARSE if(parseXmlJson == 2) jsonParse(&jsonParser, &printer, Buffer, nSize, nRetCode == HTTP_CLIENT_EOS); #endif nTotal += nSize; } } while(0); // Run only once tls_mem_free(Buffer); #if !DEMO_HTTP_XML_PARSE && DEMO_HTTP_SXML_PARSE tls_mem_free(buf_cache); #endif if(pHTTP) HTTPClientCloseRequest(&pHTTP); if(ClientParams.Verbose == TRUE) { printf("\n\nHTTP Client terminated %d (got %d kb)\n\n",nRetCode,(nTotal/ 1024)); } return nRetCode; }