本文整理汇总了C++中XmlDoc类的典型用法代码示例。如果您正苦于以下问题:C++ XmlDoc类的具体用法?C++ XmlDoc怎么用?C++ XmlDoc使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XmlDoc类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WarningMessage
//////////////////////////////////////////////////////////////////////////
//check whether user that request to log in from client side is in the repository
//if so return Login type message
//else return warning.
Message MessageHandler::LoginMessage()
{
strVal path = _repositoryPath+"Users.xml";
XmlDoc doc;
if (!doc.LoadXmlFile(path))
return WarningMessage("Users file broken, please contact administrator.");
strVal name = GetMessageName();
strVal tag = "User";
strVal content;
xmlRep rep;
vector<XmlDoc> users = doc.Children(tag);
for (size_t i=0; i<users.size(); ++i)
{
strVal userName = users[i].Children("Name")[0].InnerText();
if (userName == name)
{
_loginUsers[_curIP] = name;
return _msg;
}
}
return WarningMessage("User is not in the repository.");
}
示例2: handleRequest7
void handleRequest7 ( UdpSlot *slot , long netnice ) {
//m_state = state;
//m_callback = callback;
// shortcut
XmlDoc *xd;
try { xd = new (XmlDoc); }
catch ( ... ) {
g_errno = ENOMEM;
log("PageInject: import failed: new(%i): %s",
(int)sizeof(XmlDoc),mstrerror(g_errno));
sendReply(slot);
return;
}
mnew ( xd, sizeof(XmlDoc) , "PageInject" );
//xd->reset();
char *titleRec = slot->m_readBuf;
long titleRecSize = slot->m_readBufSize;
long collnum = *(long *)titleRec;
titleRec += 4;
titleRecSize -= 4;
CollectionRec *cr = g_collectiondb.m_recs[collnum];
if ( ! cr ) {
sendReply(slot);
return;
}
// if injecting a titlerec from an import operation use set2()
//if ( m_sbuf.length() > 0 ) {
xd->set2 ( titleRec,//m_sbuf.getBufStart() ,
titleRecSize,//m_sbuf.length() ,
cr->m_coll ,
NULL, // pbuf
MAX_NICENESS ,
NULL ); // sreq
// log it i guess
log("inject: importing %s",xd->m_firstUrl.getUrl());
// call this when done indexing
//xd->m_masterState = this;
//xd->m_masterLoop = doneInjectingWrapper9;
xd->m_state = xd;//this;
xd->m_callback1 = doneInjectingWrapper10;
xd->m_isImporting = true;
xd->m_isImportingValid = true;
// hack this
xd->m_slot = slot;
// then index it
if ( ! xd->indexDoc() )
// return if would block
return;
// all done?
//return true;
sendReply ( slot );
}
示例3: gotReplyWrapperxd
bool gotReplyWrapperxd ( void *state ) {
// grab it
XmlDoc *xd = (XmlDoc *)state;
// get it
UdpSlot *slot = (UdpSlot *)xd->m_slot;
// parse the request
Msg20Request *req = (Msg20Request *)slot->m_readBuf;
// print time
long long took = gettimeofdayInMilliseconds() - xd->m_setTime;
// if there is a baclkog of msg20 summary generation requests this
// is really not the cpu it took to make the smmary, but how long it
// took to get the reply. this request might have had to wait for the
// other summaries to finish computing before it got its turn,
// meanwhile its clock was ticking. TODO: make this better?
// only do for niceness 0 otherwise it gets interrupted by quickpoll
// and can take a long time.
if ( (req->m_isDebug || took > 100) && req->m_niceness == 0 )
log("query: Took %lli ms to compute summary for d=%lli u=%s "
"niceness=%li",
took,
xd->m_docId,xd->m_firstUrl.m_url,
xd->m_niceness );
// error?
if ( g_errno ) { xd->m_reply.sendReply ( xd ); return true; }
// this should not block now
Msg20Reply *reply = xd->getMsg20Reply ( );
// sanity check, should not block here now
if ( reply == (void *)-1 ) { char *xx=NULL;*xx=0; }
// NULL means error, -1 means blocked. on error g_errno should be set
if ( ! reply && ! g_errno ) { char *xx=NULL;*xx=0;}
// send it off. will send an error reply if g_errno is set
return reply->sendReply ( xd );
}
示例4: TEST_F
TEST_F(XmlDocTest, PosdbGetMetaListNewDoc) {
const char *url = "http://www.example.test/index.html";
char contentNew[] = "<html><head><title>my title</title></head><body>new document</body></html>";
XmlDoc xmlDocNew;
initializeDocForPosdb(&xmlDocNew, url, contentNew);
xmlDocNew.getMetaList(false);
auto metaListKeys = parseMetaList(xmlDocNew.m_metaList, xmlDocNew.m_metaListSize);
// make sure positive special key is there (to clear out existing negative special key)
EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, POSDB_DELETEDOC_TERMID, false));
EXPECT_FALSE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, POSDB_DELETEDOC_TERMID, true));
// make sure title & body text is indexed
// title
EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("title", "my"), false));
EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("title", "title"), false));
EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("title", "mytitle"), false));
EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("my"), false));
EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("title"), false));
EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("mytitle"), false));
// body
EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("new"), false));
EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("document"), false));
EXPECT_TRUE(posdbFindRecord(metaListKeys, xmlDocNew.m_docId, hashWord("newdocument"), false));
/// @todo ALC add other terms
}
示例5: GetMessageName
//////////////////////////////////////////////////////////////////////////
//Extract InnerText of Name tag in message
strVal MessageHandler::GetMessageName()
{
strVal tag = "Name";
XmlDoc doc = _msg.Doc();
vector<XmlDoc> names = doc.Children(tag);
if (names.size() <=0)return "";
strVal name = names[0].InnerText();
return names[0].InnerText();
}
示例6: inFile
void CClientInfo::Config(const string& fileName)
{
ifstream inFile(fileName.c_str(), ifstream::in);
string inXml, inLine;
while (getline(inFile, inLine))
inXml += inLine;
XmlVec confData(inXml.begin(), inXml.end());
confData.push_back('\0');
XmlDoc xmlDoc;
try {
xmlDoc.parse<0>(&confData[0]);
} catch (...) {
LOG("ERROR: failed to load the server config file.");
return;
}
XmlNodePtr pNode = NULL;
if ((pNode = xmlDoc.first_node("server_list"))) {
XmlNodePtr pItem = pNode->first_node("server");
while (pItem) {
int pId = HAS_ATTR(pItem, "id") ? atoi(ATTR_VALUE(pItem, "id")) : -1;
string ipStr = HAS_ATTR(pItem, "ip") ? ATTR_VALUE(pItem, "ip") : "127.0.0.1";
int port = HAS_ATTR(pItem, "port") ? atoi(ATTR_VALUE(pItem, "port")) : 12345;
m_svrMap[pId] = pair<string, int>(ipStr, port);
pItem = pItem->next_sibling("server");
}
}
if ((pNode = xmlDoc.first_node("parameters"))) {
m_connNum = HAS_NODE(pNode, "conn_num") ? atoi(NODE_VALUE(pNode, "conn_num")) : 1;
m_fixRate = HAS_NODE(pNode, "fix_rate") ? atoi(NODE_VALUE(pNode, "fix_rate")) : 0;
m_initTimeout = HAS_NODE(pNode, "init_timeout") ? atoi(NODE_VALUE(pNode, "init_timeout")) : 20;
m_videoLen = HAS_NODE(pNode, "video_len") ? atoi(NODE_VALUE(pNode, "video_len")) : 278;
m_initBufferSize = HAS_NODE(pNode, "init_buffer_size") ? atoi(NODE_VALUE(pNode, "init_buffer_size")) : 10;
}
LOG("--------------------------------------------------");
svrMap_t::const_iterator cIt = m_svrMap.begin();
for (; cIt != m_svrMap.end(); ++cIt) {
LOG("|server: id=%d, %s:%d.", (*cIt).first, (*cIt).second.first.c_str(), (*cIt).second.second);
}
LOG("|number of connections: %d.", m_connNum);
LOG("|video length: %d.", m_videoLen);
LOG("|fix rate: %d.", m_fixRate);
LOG("|init buffer timeout: %d.", m_initTimeout);
LOG("|init buffer size: %d.", m_initBufferSize);
LOG("--------------------------------------------------");
xmlDoc.clear();
m_rateVec.push_back(350);
m_rateVec.push_back(470);
m_rateVec.push_back(630);
m_rateVec.push_back(845);
m_rateVec.push_back(1130);
m_rateVec.push_back(1520);
m_rateVec.push_back(2040);
}
示例7: sendPageTitledb
// . returns false if blocked, true otherwise
// . sets g_errno on error
// . make a web page displaying the titleRec of "docId" given via cgi
// . call g_httpServer.sendDynamicPage() to send it
bool sendPageTitledb ( TcpSocket *s , HttpRequest *r ) {
// get the docId from the cgi vars
long long docId = r->getLongLong ("d", 0LL );
// set up a msg22 to get the next titleRec
State4 *st ;
try { st = new (State4); }
catch ( ... ) {
g_errno = ENOMEM;
log("PageTitledb: new(%i): %s",
(int)sizeof(State4),mstrerror(g_errno));
return g_httpServer.sendErrorReply(s,500,mstrerror(g_errno));}
mnew ( st , sizeof(State4) , "PageTitledb");
// save the socket
st->m_socket = s;
// copy it
st->m_r.copy ( r );
// remember if http request is internal/local or not
st->m_isRootAdmin = g_conf.isCollAdmin ( s , r );
st->m_isLocal = r->isLocal();
st->m_docId = docId;
// password, too
st->m_pwd = r->getString ( "pwd" );
// get the collection
long collLen = 0;
char *coll = st->m_r.getString("c",&collLen);
if ( ! coll || ! coll[0] ) {
//coll = g_conf.m_defaultColl;
coll = g_conf.getDefaultColl( r->getHost(), r->getHostLen() );
collLen = gbstrlen(coll);
}
st->m_coll = coll;
st->m_collLen = collLen;
// just print page if no docid provided
if ( ! docId ) return gotTitleRec ( st );
// get the handy XmlDoc
XmlDoc *xd = &st->m_xd;
// use 0 for niceness
xd->set3 ( docId , coll , 0 );
// callback
xd->setCallback ( st , gotTitleRec );
// . and tell it to load from old title rec
// . this sets all the member vars from it and also sets
// m_titleRecBuf to contain the actual compressed title rec
if ( ! xd->loadFromOldTitleRec ( ) ) return false;
// we got it without blocking. cached?
return gotTitleRec ( st );
}
示例8: doneInjectingWrapper9
// when XmlDoc::inject() complets it calls this
void doneInjectingWrapper9 ( void *state ) {
Msg7 *msg7 = (Msg7 *)state;
msg7->m_inUse = false;
// shortcut
XmlDoc *xd = &msg7->m_xd;
GigablastRequest *gr = &msg7->m_gr;
if ( gr->m_getSections && ! gr->m_gotSections ) {
// do not re-call
gr->m_gotSections = true;
// new callback now, same state
xd->m_callback1 = doneInjectingWrapper9;
// and if it blocks internally, it will call
// getInlineSectionVotingBuf until it completes then it will
// call xd->m_callback
xd->m_masterLoop = NULL;
// get sections
SafeBuf *buf = xd->getInlineSectionVotingBuf();
// if it returns -1 wait for it to call wrapper10 when done
if ( buf == (void *)-1 ) return;
// error?
if ( ! buf ) log("inject: error getting sections: %s",
mstrerror(g_errno));
}
loop:
// if we were injecting delimterized documents...
char *delim = gr->m_contentDelim;
if ( delim && ! delim[0] ) delim = NULL;
if ( delim && msg7->m_start ) {
// do another injection. returns false if it blocks
if ( ! msg7->inject ( msg7->m_state , msg7->m_callback ) )
return;
}
if ( msg7->m_start && delim )
goto loop;
// and we call the original caller
msg7->m_callback ( msg7->m_state );
}
示例9: getXmlTypeNoThrow
XmlType getXmlTypeNoThrow(const XmlDoc& doc) //throw()
{
if (doc.root().getNameAs<std::string>() == "FreeFileSync")
{
std::string type;
if (doc.root().getAttribute("XmlType", type))
{
if (type == "GUI")
return XML_TYPE_GUI;
else if (type == "BATCH")
return XML_TYPE_BATCH;
else if (type == "GLOBAL")
return XML_TYPE_GLOBAL;
}
}
return XML_TYPE_OTHER;
}
示例10: GetKeyName
//////////////////////////////////////////////////////////////////////////
//check whether uploaded file is not in repository
//or user own the file
bool MessageHandler::OKtoCheckin(strVal fileName)
{
fileName = GetKeyName(fileName)+".xml";
XmlDoc doc;
//package not in the repository, ok to check in
if (!doc.LoadXmlFile(_repositoryPath+_metaFolder+fileName))
if (!doc.LoadXmlFile(_repositoryPath+_checkinFoler+fileName))
return true;
vector<XmlDoc> elems = doc.Children("owner");
if (elems.size()<=0)return false;
//check in depend on whether user is package owner
strVal owner = elems[0].InnerText();
return owner == _curUser;
}
示例11: setXmlType
void setXmlType(XmlDoc& doc, XmlType type) //throw()
{
switch (type)
{
case XML_TYPE_GUI:
doc.root().setAttribute("XmlType", "GUI");
break;
case XML_TYPE_BATCH:
doc.root().setAttribute("XmlType", "BATCH");
break;
case XML_TYPE_GLOBAL:
doc.root().setAttribute("XmlType", "GLOBAL");
break;
case XML_TYPE_OTHER:
assert(false);
break;
}
}
示例12: processLoop
// returns false if blocked, true otherwise
bool processLoop ( void *state ) {
// get it
State60 *st = (State60 *)state;
// get the tcp socket from the state
TcpSocket *s = st->m_socket;
// get it
XmlDoc *xd = &st->m_xd;
if ( ! xd->m_loaded ) {
// setting just the docid. niceness is 0.
xd->set3 ( st->m_docId , st->m_coll , 0 );
// callback
xd->setCallback ( state , processLoop );
// . and tell it to load from the old title rec
// . if it returns false it blocked and will call our callback
// processLoop() when it completes
if ( ! xd->loadFromOldTitleRec ( ) ) return false;
}
if ( g_errno ) return sendErrorReply ( st , g_errno );
// get the utf8 content
char **utf8 = xd->getUtf8Content();
//int32_t len = xd->size_utf8Content - 1;
// wait if blocked???
if ( utf8 == (void *)-1 ) return false;
// strange
if ( xd->size_utf8Content<=0) return sendErrorReply(st,EBADENGINEER );
// alloc error?
if ( ! utf8 ) return sendErrorReply ( st , g_errno );
// get this host
Host *h = g_hostdb.getHost ( g_hostdb.m_hostId );
if ( ! h ) return sendErrorReply ( st , EBADENGINEER );
// make it into an editable page now for the turk guy
sendTurkPageReply ( st );
}
示例13: sign
void XmlSignature::sign(XmlDoc &xml, const Sec::Key &key)
{
try
{
XmlElementPtr rootNode{ xml.root() };
XmlElementPtr sigNode{ std::make_shared<XmlElement>(
*_signature->createBlankSignature(xml, CANON_C14N_COM, SIGNATURE_RSA, HASH_SHA1)) };
rootNode->add(*sigNode);
DSIGReference * ref = _signature->createReference(MAKE_UNICODE_STRING(""));
ref->appendEnvelopedSignatureTransform();
_signature->setSigningKey(key);
_signature->sign();
_signed = true;
}
catch (XSECException &ex)
{
rethrowWithMessage(ex, "An error occured while signing xml");
}
}
示例14: sendPageGet
//.........这里部分代码省略.........
// . we need to match summary here so we need to know this
//bool seq = r->getLong ( "seq" , false );
// restrict to root file?
bool rtq = r->getLong ( "rtq" , false );
// . get the titleRec
// . TODO: redirect client to a better http server to save bandwidth
State2 *st ;
try { st = new (State2); }
catch (... ) {
g_errno = ENOMEM;
log("PageGet: new(%i): %s",
(int)sizeof(State2),mstrerror(g_errno));
return g_httpServer.sendErrorReply(s,500,mstrerror(g_errno));}
mnew ( st , sizeof(State2) , "PageGet1" );
// save the socket and if Host: is local in the Http request Mime
st->m_socket = s;
st->m_isAdmin = g_conf.isCollAdmin ( s , r );
st->m_isLocal = r->isLocal();
st->m_docId = docId;
st->m_printed = false;
// include header ... "this page cached by Gigablast on..."
st->m_includeHeader = r->getLong ("ih" , true );
st->m_includeBaseHref = r->getLong ("ibh" , false );
st->m_queryHighlighting = r->getLong ("qh" , true );
st->m_strip = r->getLong ("strip" , 0 );
st->m_clickAndScroll = r->getLong ("cas" , true );
st->m_cnsPage = r->getLong ("cnsp" , true );
char *langAbbr = r->getString("qlang",NULL);
st->m_langId = langUnknown;
if ( langAbbr ) {
uint8_t langId = getLangIdFromAbbr ( langAbbr );
st->m_langId = langId;
}
strncpy ( st->m_coll , coll , MAX_COLL_LEN+1 );
// store query for query highlighting
st->m_netTestResults = r->getLong ("rnettest", false );
//if( st->m_netTestResults ) {
// mdelete ( st , sizeof(State2) , "PageGet1" );
// delete ( st );
// return sendPageNetResult( s );
//}
if ( q && qlen > 0 ) strcpy ( st->m_q , q );
else st->m_q[0] = '\0';
st->m_qlen = qlen;
//st->m_seq = seq;
st->m_rtq = rtq;
st->m_boolFlag = r->getLong ("bq", 2 /*default is 2*/ );
st->m_isBanned = false;
st->m_noArchive = false;
st->m_socket = s;
st->m_format = r->getReplyFormat();
// default to 0 niceness
st->m_niceness = 0;
st->m_r.copy ( r );
//st->m_cr = cr;
st->m_printDisclaimer = true;
if ( st->m_cnsPage )
st->m_printDisclaimer = false;
if ( st->m_strip ) // ! st->m_evbits.isEmpty() )
st->m_printDisclaimer = false;
// should we cache it?
char useCache = r->getLong ( "usecache" , 1 );
char rcache = r->getLong ( "rcache" , 1 );
char wcache = r->getLong ( "wcache" , 1 );
long cacheAge = r->getLong ( "cacheAge" , 60*60 ); // default one hour
if ( useCache == 0 ) { cacheAge = 0; wcache = 0; }
if ( rcache == 0 ) cacheAge = 0;
// . fetch the TitleRec
// . a max cache age of 0 means not to read from the cache
XmlDoc *xd = &st->m_xd;
// url based?
if ( url ) {
SpiderRequest sreq;
sreq.reset();
strcpy(sreq.m_url, url );
sreq.setDataSize();
// this returns false if "coll" is invalid
if ( ! xd->set4 ( &sreq , NULL , coll , NULL , st->m_niceness ) )
goto hadSetError;
}
// . when getTitleRec() is called it will load the old one
// since XmlDoc::m_setFromTitleRec will be true
// . niceness is 0
// . use st->m_coll since XmlDoc just points to it!
// . this returns false if "coll" is invalid
else if ( ! xd->set3 ( docId , st->m_coll , 0 ) ) {
hadSetError:
mdelete ( st , sizeof(State2) , "PageGet1" );
delete ( st );
g_errno = ENOMEM;
log("PageGet: set3: %s", mstrerror(g_errno));
return g_httpServer.sendErrorReply(s,500,mstrerror(g_errno));
}
// if it blocks while it loads title rec, it will re-call this routine
xd->setCallback ( st , processLoopWrapper );
// good to go!
return processLoop ( st );
}
示例15: processLoop
// returns false if blocked, true otherwise
bool processLoop ( void *state ) {
// get it
State2 *st = (State2 *)state;
// get the tcp socket from the state
TcpSocket *s = st->m_socket;
// get it
XmlDoc *xd = &st->m_xd;
if ( ! xd->m_loaded ) {
// setting just the docid. niceness is 0.
//xd->set3 ( st->m_docId , st->m_coll , 0 );
// callback
xd->setCallback ( state , processLoop );
// . and tell it to load from the old title rec
// . this sets xd->m_oldTitleRec/m_oldTitleRecSize
// . this sets xd->ptr_* and all other member vars from
// the old title rec if found in titledb.
if ( ! xd->loadFromOldTitleRec ( ) ) return false;
}
if ( g_errno ) return sendErrorReply ( st , g_errno );
// now force it to load old title rec
//char **tr = xd->getTitleRec();
SafeBuf *tr = xd->getTitleRecBuf();
// blocked? return false if so. it will call processLoop() when it rets
if ( tr == (void *)-1 ) return false;
// we did not block. check for error? this will free "st" too.
if ( ! tr ) return sendErrorReply ( st , g_errno );
// if title rec was empty, that is a problem
if ( xd->m_titleRecBuf.length() == 0 )
return sendErrorReply ( st , ENOTFOUND);
// set callback
char *na = xd->getIsNoArchive();
// wait if blocked
if ( na == (void *)-1 ) return false;
// error?
if ( ! na ) return sendErrorReply ( st , g_errno );
// forbidden? allow turkeys through though...
if ( ! st->m_isAdmin && *na )
return sendErrorReply ( st , ENOCACHE );
SafeBuf *sb = &st->m_sb;
// &page=4 will print rainbow sections
if ( ! st->m_printed && st->m_r.getLong("page",0) ) {
// do not repeat this call
st->m_printed = true;
// this will call us again since we called
// xd->setCallback() above to us
if ( ! xd->printDocForProCog ( sb , &st->m_r ) )
return false;
}
char *contentType = "text/html";
char format = st->m_format;
if ( format == FORMAT_XML ) contentType = "text/xml";
if ( format == FORMAT_JSON ) contentType = "application/json";
// if we printed a special page (like rainbow sections) then return now
if ( st->m_printed ) {
bool status = g_httpServer.sendDynamicPage (s,
//buf,bufLen,
sb->getBufStart(),
sb->getLength(),
-1,false,
//"text/html",
contentType,
-1, NULL, "utf8" );
// nuke state2
mdelete ( st , sizeof(State2) , "PageGet1" );
delete (st);
return status;
}
/*
// this was calling XmlDoc and setting sections, etc. to
// get the SpiderReply junk... no no no
// is it banned or filtered? this ignores the TagRec in the titleRec
// and uses msg8a to get it fresh instead
char *vi = xd->getIsFiltered();//Visible( );
// wait if blocked
if ( vi == (void *)-1 ) return false;
// error?
if ( ! vi ) return sendErrorReply ( st , g_errno );
// banned?
if ( ! st->m_isAdmin && ! *vi ) return sendErrorReply (st,EDOCBANNED);
*/
// get the utf8 content
char **utf8 = xd->getUtf8Content();
//long len = xd->size_utf8Content - 1;
// wait if blocked???
if ( utf8 == (void *)-1 ) return false;
// strange
if ( xd->size_utf8Content<=0) {
log("pageget: utf8 content <= 0");
return sendErrorReply(st,EBADENGINEER );
//.........这里部分代码省略.........