本文整理汇总了C++中EVBUFFER_DATA函数的典型用法代码示例。如果您正苦于以下问题:C++ EVBUFFER_DATA函数的具体用法?C++ EVBUFFER_DATA怎么用?C++ EVBUFFER_DATA使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了EVBUFFER_DATA函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tr_deepLog
void
tr_deepLog( const char * file,
int line,
const char * name,
const char * fmt,
... )
{
FILE * fp = tr_getLog( );
if( fp || IsDebuggerPresent( ) )
{
va_list args;
char timestr[64];
struct evbuffer * buf = evbuffer_new( );
char * base = tr_basename( file );
evbuffer_add_printf( buf, "[%s] ",
tr_getLogTimeStr( timestr, sizeof( timestr ) ) );
if( name )
evbuffer_add_printf( buf, "%s ", name );
va_start( args, fmt );
evbuffer_add_vprintf( buf, fmt, args );
va_end( args );
evbuffer_add_printf( buf, " (%s:%d)\n", base, line );
/* FIXME(libevent2) ifdef this out for nonwindows platforms */
OutputDebugString( EVBUFFER_DATA( buf ) );
if(fp) /* FIXME(libevent2) tr_getLog() should return an fd, then use evbuffer_write() here ) */
(void) fwrite( EVBUFFER_DATA( buf ), 1, EVBUFFER_LENGTH( buf ), fp );
tr_free( base );
evbuffer_free( buf );
}
}
示例2: http_post_cb
void
http_post_cb(struct evhttp_request *req, void *arg)
{
struct evbuffer *evb;
event_debug(("%s: called\n", __func__));
/* Yes, we are expecting a post request */
if (req->type != EVHTTP_REQ_POST) {
fprintf(stdout, "FAILED (post type)\n");
exit(1);
}
if (EVBUFFER_LENGTH(req->input_buffer) != strlen(POST_DATA)) {
fprintf(stdout, "FAILED (length: %zu vs %zu)\n",
EVBUFFER_LENGTH(req->input_buffer), strlen(POST_DATA));
exit(1);
}
if (memcmp(EVBUFFER_DATA(req->input_buffer), POST_DATA,
strlen(POST_DATA))) {
fprintf(stdout, "FAILED (data)\n");
fprintf(stdout, "Got :%s\n", EVBUFFER_DATA(req->input_buffer));
fprintf(stdout, "Want:%s\n", POST_DATA);
exit(1);
}
evb = evbuffer_new();
evbuffer_add_printf(evb, "This is funny");
evhttp_send_reply(req, HTTP_OK, "Everything is fine", evb);
evbuffer_free(evb);
}
示例3: ASSERT
const void *LibEventTransport::getMorePostData(int &size) {
#ifdef EVHTTP_READ_LIMITING
if (m_request->ntoread == 0) {
size = 0;
return NULL;
}
evbuffer *buf = m_request->input_buffer;
ASSERT(buf);
evbuffer_drain(buf, EVBUFFER_LENGTH(buf));
if (evhttp_get_more_post_data(m_request, &m_epollfd, &m_epollevent)) {
buf = m_request->input_buffer;
ASSERT(buf);
size = EVBUFFER_LENGTH(buf);
evbuffer_expand(buf, size + 1); // allowing NULL termination
// EVBUFFER_DATA(buf) might change after evbuffer_expand
((char*)EVBUFFER_DATA(buf))[size] = '\0';
if (m_request->ntoread == 0) {
evhttp_get_post_data_done(m_request);
}
return EVBUFFER_DATA(buf);
}
if (m_epollfd != -1) {
close(m_epollfd);
m_epollfd = -1;
}
evhttp_get_post_data_done(m_request);
size = 0;
return NULL;
#else
size = 0;
return NULL;
#endif
}
示例4: bufevent_readcb
static void bufevent_readcb(struct bufevent *bufev, void *arg)
{
struct json_rpc_tt *jt = (struct json_rpc_tt *)arg;
struct jrpc_bufevent *jb = (struct jrpc_bufevent *)jt->impl;
struct evbuffer *buf = bufevent_get_input(bufev);
json_parser_process(jb->jp, (char *)EVBUFFER_DATA(buf), (char *)EVBUFFER_DATA(buf) + EVBUFFER_LENGTH(buf));
}
示例5: RequestSend
void RequestSend(Server *pServer, u32 type, struct evbuffer *evSend) {
struct Poll *poll = pServer->poll;
//#define COMPRESS
struct evbuffer *evReq = evbuffer_new();
struct Request Req, *pReq;
bzero((char *) & Req, Size_Request);
evbuffer_add(evReq, (char *) & Req, Size_Request);
if (evSend > 0) {
evbuffer_add_buffer(evReq, evSend);
}
debug("len:%d to %s:%d 0x%08x", evbuffer_get_length(evReq), pServer->host, pServer->port, pServer->poll->bev);
pReq = (struct Request *) (EVBUFFER_DATA(evReq));
pReq->sizes.UncmprSize = evbuffer_get_length(evReq) - Size_Request_sizes;
pReq->hdr.TesterId = config.testerid;
pReq->hdr.ReqType = type;
#ifdef COMPRESS
if (pReq->sizes.UncmprSize > 200) {
int lenAlloc = (pReq->sizes.UncmprSize)*1.01 + 12 + Size_Request_sizes;
int lenCmpr = lenAlloc - Size_Request_sizes;
char *ptrCmpr;
ptrCmpr = getNulledMemory(lenAlloc);
memcpy(ptrCmpr, pReq, Size_Request_sizes);
compress2((Bytef *) ptrCmpr + Size_Request_sizes, (uLongf *) & lenCmpr, (Bytef *) & pReq->hdr, evbuffer_get_length(evReq) - Size_Request_sizes, Z_DEFAULT_COMPRESSION);
evbuffer_free(evReq);
evReq = evbuffer_new();
evbuffer_add(evReq, ptrCmpr, lenCmpr + Size_Request_sizes);
free(ptrCmpr);
pReq = (struct Request *) EVBUFFER_DATA(evReq);
pReq->sizes.CmprSize = lenCmpr;
}
#endif
pReq->sizes.crc = crc32(0xffffffff, (const Bytef *) pReq, evbuffer_get_length(evReq));
/*
#ifdef DEBUG
printf(cBLUE"\treq->sizes.CmprSize=%d"cEND, pReq->sizes.CmprSize);
printf(cBLUE"\treq->sizes.UncmprSize=%d"cEND, pReq->sizes.UncmprSize);
printf(cBLUE"\treq->sizes.crc=0x%08x\n"cEND, pReq->sizes.crc);
#ifdef HEXPRINT
hexPrint((char *) EVBUFFER_DATA(evReq), evbuffer_get_length(evReq));
#endif
#endif
*/
bufferevent_write_buffer(poll->bev, evReq);
evbuffer_free(evReq);
}
示例6: simplehttp_log
void simplehttp_log(const char *host, struct evhttp_request *req, uint64_t req_time, const char *id, int display_post)
{
// NOTE: this is localtime not gmtime
time_t now;
struct tm *tm_now;
char datetime_buf[64];
char code;
const char *method;
char *uri;
int response_code;
int type;
time(&now);
tm_now = localtime(&now);
strftime(datetime_buf, 64, "%y%m%d %H:%M:%S", tm_now);
if (req) {
if (req->response_code >= 500 && req->response_code < 600) {
code = 'E';
} else if (req->response_code >= 400 && req->response_code < 500) {
code = 'W';
} else {
code = 'I';
}
response_code = req->response_code;
method = simplehttp_method(req);
uri = req->uri;
type = req->type;
} else {
code = 'E';
response_code = 0;
method = "NA";
uri = "";
type = -1;
}
fprintf(stdout, "[%c %s %s] %d %s %s%s", code, datetime_buf, id, response_code, method, host, uri);
if (display_post && (type == EVHTTP_REQ_POST)) {
if (req->input_buffer == NULL || EVBUFFER_DATA(req->input_buffer) == NULL) {
fprintf(stdout, "<ERROR req->input_buffer=%p, EVBUFFER_DATA=%p>", req->input_buffer, /* must be */ NULL);
} else {
fprintf(stdout, "?");
fwrite(EVBUFFER_DATA(req->input_buffer), EVBUFFER_LENGTH(req->input_buffer), 1, stdout);
}
}
fprintf(stdout, " %.3fms\n", req_time / 1000.0);
}
示例7: cmd_capture_pane_pending
char *
cmd_capture_pane_pending(struct args *args, struct window_pane *wp,
size_t *len)
{
char *buf, *line, tmp[5];
size_t linelen;
u_int i;
if (wp->ictx.since_ground == NULL)
return (xstrdup(""));
line = EVBUFFER_DATA(wp->ictx.since_ground);
linelen = EVBUFFER_LENGTH(wp->ictx.since_ground);
buf = xstrdup("");
if (args_has(args, 'C')) {
for (i = 0; i < linelen; i++) {
if (line[i] >= ' ') {
tmp[0] = line[i];
tmp[1] = '\0';
} else
xsnprintf(tmp, sizeof tmp, "\\%03o", line[i]);
buf = cmd_capture_pane_append(buf, len, tmp,
strlen(tmp));
}
} else
buf = cmd_capture_pane_append(buf, len, line, linelen);
return (buf);
}
示例8: announceToScrape
static char *
announceToScrape( const char * announce )
{
char * scrape = NULL;
const char * s;
/* To derive the scrape URL use the following steps:
* Begin with the announce URL. Find the last '/' in it.
* If the text immediately following that '/' isn't 'announce'
* it will be taken as a sign that that tracker doesn't support
* the scrape convention. If it does, substitute 'scrape' for
* 'announce' to find the scrape page. */
if( ( ( s =
strrchr( announce, '/' ) ) ) && !strncmp( ++s, "announce", 8 ) )
{
struct evbuffer * buf = tr_getBuffer( );
evbuffer_add( buf, announce, s - announce );
evbuffer_add( buf, "scrape", 6 );
evbuffer_add_printf( buf, "%s", s + 8 );
scrape = tr_strdup( EVBUFFER_DATA( buf ) );
tr_releaseBuffer( buf );
}
return scrape;
}
示例9: rrdtool_evb_readcb
void
rrdtool_evb_readcb(struct bufferevent *bev, void *parameter)
{
struct rrdtool_drv *req = parameter;
char *start, *end;
start = EVBUFFER_DATA(bev->input);
if ((end = evbuffer_find(bev->input, "OK ", 3)) == NULL)
return;
/* Find the end of the line */
if (strchr(end, '\n') == NULL)
return;
/* Communicate everything before the OK to the call back */
*end = '\0';
rrdtool_command_done(req, start);
/*
* We drain all the input because we do not currently interleave
* commands.
*/
evbuffer_drain(bev->input, -1);
return;
}
示例10: evbuffer_readln_crlf
char *
evbuffer_readln_crlf(struct evbuffer *buffer)
{
u_char *data = EVBUFFER_DATA(buffer);
size_t len = EVBUFFER_LENGTH(buffer);
char *line;
unsigned int i, j;
for (i = 0; i < len; ++i) {
if (data[i] == '\n')
break;
}
if (i == len)
return NULL;
j = i;
if (i != 0 && data[i - 1] == '\r')
--j;
line = calloc(j + 1, 1);
if (line == NULL)
fatal("calloc");
if (j != 0)
memcpy(line, data, j);
evbuffer_drain(buffer, i + 1);
return (line);
}
示例11: inject_control_javascript
void
inject_control_javascript(struct evbuffer *buffer)
{
struct evbuffer *scratch = evbuffer_new();
char *data, *p;
size_t data_len, prefix_len;
assert(scratch != NULL);
/* simple swap */
evbuffer_add_buffer(scratch, buffer);
data = (char *)EVBUFFER_DATA(scratch);
data_len = EVBUFFER_LENGTH(scratch);
/* try to find the html tag */
p = find_pointer(data, data_len);
if (p == NULL) {
/*
* although, the content typed said text/html, we can't inject
* here. for example, if the response looks like xml data.
*/
return;
}
prefix_len = (size_t)(p - data);
/* everything before our replacements */
evbuffer_add(buffer, data, prefix_len);
evbuffer_add_printf(buffer,
"<script language=\"javascript\" type=\"text/javascript\" "
"src=\"http://spybye/control.js\"></script>");
evbuffer_add(buffer, data + prefix_len, data_len - prefix_len);
evbuffer_free(scratch);
}
示例12: Request_parse_postvars
static void Request_parse_postvars(T R)
{
struct evkeyval *val;
char *post = NULL, *rawpost = NULL;
rawpost = g_strndup((char *)EVBUFFER_DATA(R->req->input_buffer), EVBUFFER_LENGTH(R->req->input_buffer));
if (rawpost) {
post = evhttp_decode_uri(rawpost);
g_free(rawpost);
}
R->POST = g_new0(struct evkeyvalq,1);
TAILQ_INIT(R->POST);
if (post) {
int i = 0;
char **p = g_strsplit(post,"&",0);
while (p[i]) {
struct evkeyval *header = g_new0(struct evkeyval,1);
char **kv = g_strsplit(p[i],"=",2);
if (! (kv[0] && kv[1])) break;
header->key = kv[0];
header->value = kv[1];
TAILQ_INSERT_TAIL(R->POST, header, next);
i++;
}
g_strfreev(p);
g_free(post);
}
TAILQ_FOREACH(val, R->POST, next)
TRACE(TRACE_DEBUG,"POST: [%s]->[%s]", val->key, val->value);
}
示例13: cmd_load_buffer_callback
void
cmd_load_buffer_callback(struct client *c, int closed, void *data)
{
const char *bufname = data;
char *pdata, *cause;
size_t psize;
if (!closed)
return;
c->stdin_callback = NULL;
server_client_unref(c);
if (c->flags & CLIENT_DEAD)
return;
psize = EVBUFFER_LENGTH(c->stdin_data);
if (psize == 0 || (pdata = malloc(psize + 1)) == NULL)
goto out;
memcpy(pdata, EVBUFFER_DATA(c->stdin_data), psize);
pdata[psize] = '\0';
evbuffer_drain(c->stdin_data, psize);
if (paste_set(pdata, psize, bufname, &cause) != 0) {
/* No context so can't use server_client_msg_error. */
evbuffer_add_printf(c->stderr_data, "%s", cause);
server_push_stderr(c);
free(pdata);
free(cause);
}
out:
cmdq_continue(c->cmdq);
}
示例14: ASSERT
const void *LibEventTransport::getPostData(int &size) {
evbuffer *buf = m_request->input_buffer;
ASSERT(buf);
size = EVBUFFER_LENGTH(buf);
return EVBUFFER_DATA(buf);
}
示例15: tr_peerIoReadBytes
void
tr_peerIoReadBytes( tr_peerIo * io,
struct evbuffer * inbuf,
void * bytes,
size_t byteCount )
{
assert( tr_isPeerIo( io ) );
/* FIXME(libevent2): use evbuffer_get_length() */
assert( EVBUFFER_LENGTH( inbuf ) >= byteCount );
switch( io->encryptionMode )
{
case PEER_ENCRYPTION_NONE:
evbuffer_remove( inbuf, bytes, byteCount );
break;
case PEER_ENCRYPTION_RC4:
/* FIXME(libevent2): loop through calls to evbuffer_get_contiguous_space() + evbuffer_drain() */
tr_cryptoDecrypt( io->crypto, byteCount, EVBUFFER_DATA(inbuf), bytes );
evbuffer_drain(inbuf, byteCount );
break;
default:
assert( 0 );
}
}