void MCF::dlHeaderFromHttp(const char* url) { gcTrace("Url: {0}", url); if (m_bStopped) return; if (!url) throw gcException(ERR_BADURL); //FIXME: Needs error checking on getweb HttpHandle wc(url); wc->setDownloadRange(0, MCFCore::MCFHeader::getSizeS()); wc->setUserAgent(USERAGENT_UPDATE); wc->getWeb(); if (wc->getDataSize() != MCFCore::MCFHeader::getSizeS()) throw gcException(ERR_BADHEADER); MCFCore::MCFHeader webHeader(wc->getData()); setHeader(&webHeader); if (!webHeader.isValid()) throw gcException(ERR_BADHEADER); wc->cleanUp(); wc->setUserAgent(USERAGENT_UPDATE); wc->setDownloadRange(webHeader.getXmlStart(), webHeader.getXmlSize()); wc->getWeb(); if (wc->getDataSize() == 0 || wc->getDataSize() != webHeader.getXmlSize()) throw gcException(ERR_WEBDL_FAILED, "Failed to download MCF xml from web (size is ether zero or didnt match header size)"); uint32 bz2BuffLen = webHeader.getXmlSize()*25; char* bz2Buff = nullptr; if ( isCompressed() ) { bz2Buff = new char[bz2BuffLen]; AutoDelete<char> ad(bz2Buff); UTIL::STRING::zeroBuffer(bz2Buff, bz2BuffLen); UTIL::BZIP::BZ2DBuff((char*)bz2Buff, &bz2BuffLen, const_cast<char*>(wc->getData()), wc->getDataSize()); parseXml(bz2Buff, bz2BuffLen); } else { parseXml(const_cast<char*>(wc->getData()), wc->getDataSize()); } //we remove the complete flag due to the files not existing in the MCF for (size_t x=0; x< m_pFileList.size(); x++) { m_pFileList[x]->delFlag(MCFCore::MCFFileI::FLAG_COMPLETE); } }
int LoadSave_loadRocketXML(const text_t* path, TrackData* trackData) { FILE* fp = 0; mxml_node_t* tree = 0; #if defined(_WIN32) if (_wfopen_s(&fp, path, L"r") != 0) return false; #else if (!(fp = fopen(path, "r"))) return false; #endif if (!(tree = mxmlLoadFile(NULL, fp, MXML_TEXT_CALLBACK))) { fclose(fp); return false; } parseXml(tree, trackData); fclose(fp); mxmlDelete(tree); return true; }
void answer_status_by_id(struct gss_account account, int id, char *msg) { /* cURL functionality used just to URIencode the msg */ CURL *curl = curl_easy_init(); if(curl) { char *encoded_msg = curl_easy_escape(curl, msg, strlen(msg)); if(encoded_msg) { /* margin to fit the ID is included */ int amount = 68+strlen(encoded_msg); char *send = malloc(amount); snprintf(send, amount, "in_reply_to_status_id=%d&source=GnuSocialShell&status=%s", id, encoded_msg); if (loglevel >= LOG_DEBUG) { // OK? fprintf(stderr, "in_reply_to_status_id=%d&source=GnuSocialShell&status=%s\n", id, encoded_msg); } // send[sizeof(send)-1] = '\0'; // snprintf does that too char *xml_data = send_to_api(account, send, "statuses/update.xml"); int xml_data_size = strlen(xml_data); if (FindXmlError(xml_data, strlen(xml_data)) < 0 && parseXml(xml_data, xml_data_size, "</status>", 9, NULL, 0) > 0) { struct status posted_status; posted_status = makeStatusFromRawSource(xml_data, xml_data_size); print_status(posted_status); } free(xml_data); free(send); curl_free(encoded_msg); } } }
void BlinkParser::onReplyReadyRead() { if (m_reply != nullptr) { m_reader->addData(m_reply->readAll()); parseXml(); } }
void join_group(struct gss_account account, int id) { char url[128]; sprintf(url, "%s://%s/api/statusnet/groups/join.xml", account.protocol, account.server); FILE *xml = fopen("temp/file.xml", "wb"); CURL *curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_USERPWD, account.user); curl_easy_setopt(curl, CURLOPT_PASSWORD, account.password); curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, save_xml); curl_easy_setopt(curl, CURLOPT_WRITEDATA, xml); char buffer[30]; sprintf(buffer, "id=%d", id); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, buffer); curl_easy_perform(curl); curl_easy_cleanup(curl); fclose(xml); xml = fopen("temp/file.xml", "r"); fseek(xml, 0L, SEEK_END); int filesize = ftell(xml); rewind(xml); char *xml_data = (char *)malloc(filesize); fread(xml_data, filesize, filesize, xml); fclose(xml); char *error = (char *)malloc(512); int xml_data_size = strlen(xml_data); if (parseXml(xml_data, xml_data_size, "<error>", 7, error, 512) > 0) { printf("Error: %s\n", error); } free(error); free(xml_data); }
void UMcf::parseUpdateXml(const XML::gcXMLDocument &xmlDocument) { auto uNode = xmlDocument.GetRoot("appupdate"); if (!uNode.IsValid()) return; auto mcfNode = uNode.FirstChildElement("mcf"); if (!mcfNode.IsValid()) return; const std::string appid = mcfNode.GetAtt("appid"); if (!appid.empty()) m_iAppId = Safe::atoi(appid.c_str()); else m_iAppId = 100; const std::string build = mcfNode.GetAtt("build"); if (!build.empty()) m_iAppBuild = Safe::atoi(build.c_str()); else m_iAppBuild = 0; mcfNode.GetChild("url", m_szUrl); parseXml(mcfNode.FirstChildElement("files")); }
void send_status(struct gss_account account, char *msg) { /* cURL functionality used just to URIencode the msg */ CURL *curl = curl_easy_init(); if(curl) { char *encoded_msg = curl_easy_escape(curl, msg, strlen(msg)); if(encoded_msg) { int amount = 31+strlen(encoded_msg); char *send = malloc(amount); snprintf(send, amount, "source=GnuSocialShell&status=%s", encoded_msg); if (loglevel >= LOG_DEBUG) { // OK? fprintf(stderr, "source=GnuSocialShell&status=%s", encoded_msg); } char *xml_data = send_to_api(account, send, "statuses/update.xml"); int xml_data_size = strlen(xml_data); if (FindXmlError(xml_data, strlen(xml_data)) < 0 && parseXml(xml_data, xml_data_size, "</status>", 9, NULL, 0) > 0) { struct status posted_status; posted_status = makeStatusFromRawSource(xml_data, xml_data_size); print_status(posted_status); } free(xml_data); free(send); curl_free(encoded_msg); } } }
void ArchLinuxNewsReader::readData(const QHttpResponseHeader &resp) { if (resp.statusCode() != 200) http->abort(); else { xml.addData(http->readAll()); parseXml(); } }
void RSSListing::readData(const QHttpResponseHeader &resp) { if (resp.statusCode() != 200) http.abort(); else { xml.addData(http.readAll()); parseXml(); } }
//------------------------------------------------------ void xmlNav::setup(string navPath, string resourcePath){ if( resourcePath != "" && resourcePath.length() > 0 ){ if( resourcePath[resourcePath.length()-1] != '/' && resourcePath[resourcePath.length()-1] != '\\' ){ resourcePath += string("/"); } } parseXml(navPath, resourcePath); }
JsonServerGenerator::JsonServerGenerator(std::string ifile, Info & info) { Interface i = parseXml(ifile); std::string stub = generateStub(i, info); { std::ofstream of(info.getServerDst("Json").c_str()); of << stub << std::endl; } }
void RSSListing::readyRead() { int statusCode = currentReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if (statusCode >= 200 && statusCode < 300) { QByteArray data = currentReply->readAll(); xml.addData(data); parseXml(); } }
void UtubeData::readData(const QHttpResponseHeader &resp) { if (resp.statusCode() != 200) { mHttp->abort(); qDebug() << "UTUBE: Error." << endl; } else { mXml.addData(mHttp->readAll()); parseXml(); } }
void MCF::parseMCF() { if (m_bStopped) return; UTIL::FS::FileHandle hFile; getReadHandle(hFile); safe_delete(m_pFileList); MCFCore::MCFHeader tempHeader; tempHeader.readFromFile(hFile); setHeader(&tempHeader); hFile.seek(tempHeader.getXmlStart()); uint32 xmlBuffLen = tempHeader.getXmlSize()+1; UTIL::MISC::Buffer xmlBuff(xmlBuffLen, true); hFile.read(xmlBuff, tempHeader.getXmlSize()); if (getHeader()->getFlags() & MCFCore::MCFHeaderI::FLAG_NOTCOMPRESSED) { parseXml(xmlBuff, xmlBuffLen); } else { UTIL::MISC::BZ2Worker worker(UTIL::MISC::BZ2_DECOMPRESS); worker.write(xmlBuff, xmlBuffLen, true); worker.doWork(); if (worker.getLastStatus() != BZ_STREAM_END) throw gcException(ERR_BZ2, worker.getLastStatus(), "Failed to decompress mcf header xml"); size_t bz2BuffLen = worker.getReadSize(); UTIL::MISC::Buffer bz2Buff(bz2BuffLen); worker.read(bz2Buff, bz2BuffLen); parseXml(bz2Buff, bz2BuffLen); } }
int XmlImporter::load() { int state = loadFile(); if (state!=OK){ return state; } parseXml(); return OK; }
void RssFetcher::fetchingFinished(QNetworkReply *reply) { const bool error = (reply->error() != QNetworkReply::NoError); if (!error) { parseXml(reply); m_items = 0; } if (--m_requestCount == 0) emit finished(error); reply->deleteLater(); }
Encoder::Encoder (char * in, char * out, bool verbose, bool decode, char * charset) { m_root = NULL; s_debug = verbose; if (endsWith (in, "xml") || (strcmp (in, "-") == 0 && decode == false)) { if (!parseXml (in, charset)) { fprintf (stderr, "Error during XML parsing\n"); exit (1); } FILE * fp = NULL; if (strcmp (out, "-") == 0) { // stdout fp = stdout; } else if (endsWith (out, ".bml")) { fp = fopen (out, "w"); } if (fp != NULL) { BmlEncoder e; m_root->visit (&e); // parse a first time to compute ids table e.initDone (); // dump the id table m_root->visit (&e); // parse a second time to encode the content int size; char * buff = e.getBuffer (size); fwrite (buff, 1, size, fp); free (buff); if (fp != stdout) { fclose (fp); } } else { fprintf (stderr, "Cannot open %s for writing", out); } } else if (endsWith (in, "bml") || (strcmp (in, "-") == 0 && decode)) { if (!parseBml (in)) { fprintf (stderr, "Error during BML parsing\n"); exit (1); } FILE * fp = NULL; if (strcmp (out, "-") == 0) { // stdout fp = stdout; } else if (endsWith (out, ".xml")) { fp = fopen (out, "w"); } if (fp != NULL) { XmlPrinter p (fp); m_root->visit (&p); if (fp != stdout) { fclose (fp); } } else { fprintf (stderr, "Cannot open %s for writing", out); } } else { fprintf (stderr, "Input file must be xml OR bml\n"); exit (1); } }
void GameConfigurator::init(const QString& fileName) { parseXml(fileName); //format.setSamples(16); format.setDepthBufferSize(24); QSurfaceFormat::setDefaultFormat(format); }
int verify_account(struct gss_account account) { int ret = 0; char url[100]; sprintf(url, "%s://%s/api/account/verify_credentials.xml", account.protocol, account.server); FILE *xml = fopen("temp/file.xml", "wb"); CURL *curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, save_xml); curl_easy_setopt(curl, CURLOPT_WRITEDATA, xml); curl_easy_setopt(curl, CURLOPT_USERNAME, account.user); curl_easy_setopt(curl, CURLOPT_PASSWORD, account.password); curl_easy_perform(curl); curl_easy_cleanup(curl); fclose(xml); xml = fopen("temp/file.xml", "r"); fseek(xml, 0L, SEEK_END); int filesize = ftell(xml); rewind(xml); char *xml_data = (char *)malloc(filesize); fread(xml_data, filesize, filesize, xml); fclose(xml); int xml_data_size = strlen(xml_data); char *error = (char *)malloc(512); if (parseXml(xml_data, xml_data_size, "<error>", 7, error, 512) > 0) { printf("Error: %s\n", error); ret = -1; } else if (parseXml(xml_data, xml_data_size, "<screen_name>", 13, "", 0) < 0) { printf("Error: Conecting to @%s@%s\n", account.user, account.server); ret = -1; } free(error); free(xml_data); return ret; }
int get_cmd_type(const char *request_xmlstr) { xmlChar *cmd_type; cmd_type=parseXml(request_xmlstr,"cmd_type"); if(NULL ==cmd_type) return -1; if( xmlStrcmp(cmd_type,BAD_CAST"opendoor") ==0) return 0; else if( xmlStrcmp(cmd_type,BAD_CAST"openheat") == 0) return 1; else if( xmlStrcmp(cmd_type,BAD_CAST"closeheat") == 0) return 2; else if( xmlStrcmp(cmd_type,BAD_CAST"checkdoor") == 0) return 3; else return -1; }
// main function to load settings from xml file bool load() { if (FLIPBOOK_ENABLED) { m_loaded = m_settings.load(FLIPBOOK_SETTINGS_FILE); } else { m_loaded = m_settings.load(DEFAULT_SETTINGS_FILE); } if (m_loaded) { parseXml(); } return m_loaded; }
void BlinkParser::fire(QNetworkReply *reply) { // reset the state m_reply = reply; connect(m_reply, &QNetworkReply::finished, this, &BlinkParser::checkResultCode); m_total = m_current = 0; m_atUserInfo = false; m_reader->clear(); m_reader->addData(reply->readAll()); connect(m_reply, &QNetworkReply::readyRead, this, &BlinkParser::onReplyReadyRead); parseXml(); }
int get_box_num(const char *request_xmlstr) { int n; xmlChar *box_num; box_num=parseXml(request_xmlstr,"box_num"); if(NULL ==box_num) return -1; n=atoi( box_num ); xmlFree(box_num); if(n>=1&&n<=20) return n-1; else return -1; }
int get_box_unit(const char *request_xmlstr) { int n; xmlChar *box_unit; box_unit=parseXml(request_xmlstr,"box_unit"); if(NULL ==box_unit) return -1; n=atoi( box_unit ); xmlFree(box_unit); if(n>=1&&n<=16) return n-1; else return -1; }
int parseDTD (char* dtdpath) { FILE* f; int r = -1; ENTER ("parseDTD"); if (f = fopen (dtdpath, "r")) { r = parseXml (f); /* DTDをパースする */ fclose (f); } else warn3 ("Specified DTD file \"", dtdpath, "\" does not exist."); LEAVE ("parseDTD"); return r; }
// short* : Used for systems (Windows) that use wide-chars in filenames NODE* CParseXml::mainXML(const short *szFileName) { int buffLen; if(bufFile) delete bufFile; bufFile =loadFileW(szFileName, buffLen); if (bufFile == NULL) { DEBUG_T(0,"xml file not found"); return NULL; } return parseXml(bufFile, buffLen); }
NODE* CParseXml::mainXML(const char *szFileName) { int buffLen; if (bufFile) delete bufFile; // bufFile is always terminated with 'nul' bytes bufFile = loadFile(szFileName, buffLen); if (bufFile == NULL) { DEBUG_T(0,"xml file not found"); return NULL; } return parseXml(bufFile, buffLen); }
KeePass2XmlReader::KeePass2XmlReader(const QString &xmlFilename) : d_ptr(new KeePass2XmlReaderPrivate) { Q_D(KeePass2XmlReader); d->xmlFile.setFileName(xmlFilename); d->ok = d->xmlFile.open(QIODevice::ReadOnly); d->errorString = d->ok ? QString() : d->xmlFile.errorString(); if (d->ok) { d->ok = d->xml.setContent(&d->xmlFile, &d->xmlErrorString, &d->xmlErrorLine, &d->xmlErrorColumn); if (d->ok) { parseXml(d->xml.documentElement(), 0); } } d->xmlFile.close(); }
InterfaceGenerator::InterfaceGenerator(std::string ifile, Info & info) { Interface i = parseXml(ifile); std::string stub = generateStub(i, info); { std::ofstream of(info.getInterfaceDst().c_str()); of << stub << std::endl; } std::string cppstub = generateCppStub(i, info); { std::ofstream of(info.getInterfaceSourceDst().c_str()); of << cppstub << std::endl; } }
bool MyCsvParse::init() { mDataTypeMap.clear(); mDataTypeMap.insert(std::make_pair("uint32", eUINT32)); mDataTypeMap.insert(std::make_pair("int32", eINT32)); mDataTypeMap.insert(std::make_pair("float", eFLOAT)); mDataTypeMap.insert(std::make_pair("double", eDOUBLE)); mDataTypeMap.insert(std::make_pair("string", eSTRING)); mParseFunc.insert(std::make_pair("111.csv", std::bind(ParseTest111, std::placeholders::_1))); parseXml(); ParseCsvFile(); return true; }