本文整理汇总了C++中SafeBuf::getBuf方法的典型用法代码示例。如果您正苦于以下问题:C++ SafeBuf::getBuf方法的具体用法?C++ SafeBuf::getBuf怎么用?C++ SafeBuf::getBuf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SafeBuf
的用法示例。
在下文中一共展示了SafeBuf::getBuf方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getCurrentUrl
// . the url being reuqested
// . removes &code= facebook cruft
bool HttpRequest::getCurrentUrl ( SafeBuf &cu ) {
// makre sure we got enough room
if ( ! cu.reserve ( m_hostLen + 64 + m_plen + 1 + 1 ) ) return false;
// need a "Host: "
char *host = m_host;
if ( ! host ) host = APPSUBDOMAIN;
cu.safePrintf("http");
if ( m_isSSL ) cu.pushChar('s');
cu.safePrintf("://%s",host);
char *path = m_path;
long plen = m_plen;
if ( ! path ) {
path = "/";
plen = 1;
}
// . scan path and change \0 back to = or &
// . similar logic in HttpServer.cpp for logging!
char *dst = cu.getBuf();
char *src = path;
char *srcEnd = path + plen;
char dd = '=';
for ( ; src < srcEnd ; src++ , dst++ ) {
*dst = *src;
if ( *src ) continue;
*dst = dd;
if ( dd == '=' ) dd = '&';
else dd = '=';
}
*dst = '\0';
// cut it off at facebook's &code=
char *buf = cu.getBufStart();
char *code = strstr( buf,"&code=");
// fix for eventguru.com/blog.html?code=
if ( ! code ) code = strstr(buf,"?code=");
// hack that off if there
if ( code ) {
*code = '\0';
dst = code;
}
// update length
cu.setLength( dst - cu.getBufStart() );
return true;
}
示例2: getCurrentUrlPath
bool HttpRequest::getCurrentUrlPath ( SafeBuf &cup ) {
// makre sure we got enough room
if ( ! cup.reserve ( m_plen + 1 + 1 ) ) return false;
char *path = m_path;
long plen = m_plen;
if ( ! path ) {
path = "/";
plen = 1;
}
// . scan path and change \0 back to = or &
// . similar logic in HttpServer.cpp for logging!
char *dst = cup.getBuf();
char *start = dst;
char *src = path;
char *srcEnd = path + plen;
// stop if we hit '?'
for ( ; src < srcEnd && *src != '?' ; src++ , dst++ ) {
*dst = *src;
}
cup.incrementLength(dst - start);
*dst = '\0';
return true;
}
示例3: importLoop
//.........这里部分代码省略.........
mcast = getAvailMulticast();
// if none, must have to wait for some to come back to us
if ( ! mcast ) {
// restore file offset
//m_fileOffset = saved;
// no, must have been a oom or something
log("import: import no mcast available");
return true;//false;
}
// this is for holding a compressed titlerec
//sbuf = &mcast->m_sbuf;//&gr->m_sbuf;
// point to start of buf
sbuf->reset();
// ensure we have enough room
sbuf->reserve ( need );
// collnum first 4 bytes
sbuf->pushLong( (long)m_collnum );
// store title key
sbuf->safeMemcpy ( &tkey , sizeof(key_t) );
// then datasize if any. neg rec will have -1 datasize
if ( dataSize >= 0 )
sbuf->pushLong ( dataSize );
// then read data rec itself into it, compressed titlerec part
if ( dataSize > 0 ) {
// read in the titlerec after the key/datasize
status = m_bf.read ( sbuf->getBuf() ,
dataSize ,
m_fileOffset );
if ( g_errno ) { // n != dataSize ) {
log("main: failed to read in title rec "
"file. %s. Skipping file %s",
mstrerror(g_errno),m_bf.getFilename());
// essentially free up this msg7 now
//msg7->m_inUse = false;
//msg7->reset();
goto nextFile;
}
// advance
m_fileOffset += dataSize;
// it's good, count it
sbuf->m_length += dataSize;
}
// set xmldoc from the title rec
//xd->set ( sbuf.getBufStart() );
//xd->m_masterState = NULL;
//xd->m_masterCallback ( titledbInjectLoop );
// we use this so we know where the doc we are injecting
// was in the foregien titledb file. so we can update our bookmark
// code.
mcast->m_hackFileOff = saved;//m_fileOffset;
mcast->m_hackFileId = m_bfFileId;
//
// inject a title rec buf this time, we are doing an import
// FROM A TITLEDB FILE!!!
//
示例4: sendPageThesaurus
bool sendPageThesaurus( TcpSocket *s, HttpRequest *r ) {
SafeBuf p;
char getBuf[64]; // holds extra values for GET method
char formBuf[256]; // holds extra values for forms
snprintf(getBuf, 64, "c=%s",
r->getString("c", 0, ""));
snprintf(formBuf, 256,
"<input type=hidden name=\"c\" value=\"%s\">",
//"<input type=hidden name=\"pwd\" value=\"%s\">",
r->getString("c", 0, ""));
g_pages.printAdminTop( &p, s, r);
if (r->getLong("cancel", 0) != 0) {
g_thesaurus.cancelRebuild();
p.safePrintf("<br><br>\n");
p.safePrintf(
"<center><b><font color=#ff0000>"
"rebuild canceled"
"</font></b></center>");
}
if (r->getLong("rebuild", 0) != 0) {
bool full = r->getLong("full", 0);
p.safePrintf("<br><br>\n");
if (g_thesaurus.rebuild(0, full)) {
p.safePrintf(
"<center><b><font color=#ff0000>"
"error starting rebuild, check log for details"
"</font></b></center>");
} else {
p.safePrintf(
"<center><b><font color=#ff0000>"
"rebuild started"
"</font></b></center>");
}
}
if (r->getLong("rebuildaff", 0) != 0) {
bool full = r->getLong("full", 0);
p.safePrintf("<br><br>\n");
if (g_thesaurus.rebuildAffinity(0, full)) {
p.safePrintf(
"<center><b><font color=#ff0000>"
"error starting rebuild, check log for details"
"</font></b></center>");
} else {
p.safePrintf(
"<center><b><font color=#ff0000>"
"rebuild started"
"</font></b></center>");
}
}
if (r->getLong("distribute", 0) != 0) {
char cmd[1024];
p.safePrintf("<br><br>\n");
if (g_thesaurus.m_affinityState) {
p.safePrintf(
"<center><b><font color=#ff0000>"
"cannot distribute during rebuild"
"</font></b></center>");
} else {
for ( long i = 0; i < g_hostdb.getNumHosts() ; i++ ) {
Host *h = g_hostdb.getHost(i);
snprintf(cmd, 512,
"rcp -r "
"./dict/thesaurus.* "
"%s:%s/dict/ &",
iptoa(h->m_ip),
h->m_dir);
log(LOG_INFO, "admin: %s", cmd);
system( cmd );
}
p.safePrintf(
"<center><b><font color=#ff0000>"
"data distributed"
"</font></b></center>");
}
}
if (r->getLong("reload", 0) != 0) {
p.safePrintf("<br><br>\n");
if (r->getLong("cast", 0) != 0) {
p.safePrintf(
"<center><b><font color=#ff0000>"
"reload command broadcast"
"</font></b></center>");
} else if (g_thesaurus.init()) {
p.safePrintf(
"<center><b><font color=#ff0000>"
"thesaurus data reloaded"
"</font></b></center>");
} else {
p.safePrintf(
"<center><b><font color=#ff0000>"
"error reloading thesaurus data"
"</font></b></center>");
}
}
//.........这里部分代码省略.........