本文整理汇总了C++中buffer_append_string_buffer函数的典型用法代码示例。如果您正苦于以下问题:C++ buffer_append_string_buffer函数的具体用法?C++ buffer_append_string_buffer怎么用?C++ buffer_append_string_buffer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了buffer_append_string_buffer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: proxy_create_env
static int proxy_create_env(server *srv, handler_ctx *hctx) {
size_t i;
connection *con = hctx->remote_conn;
buffer *b;
/* build header */
b = buffer_init();
/* request line */
buffer_copy_string(b, get_http_method_name(con->request.http_method));
buffer_append_string_len(b, CONST_STR_LEN(" "));
buffer_append_string_buffer(b, con->request.uri);
buffer_append_string_len(b, CONST_STR_LEN(" HTTP/1.0\r\n"));
proxy_append_header(con, "X-Forwarded-For", (char *)inet_ntop_cache_get_ip(srv, &(con->dst_addr)));
/* http_host is NOT is just a pointer to a buffer
* which is NULL if it is not set */
if (!buffer_string_is_empty(con->request.http_host)) {
proxy_set_header(con, "X-Host", con->request.http_host->ptr);
}
proxy_set_header(con, "X-Forwarded-Proto", con->uri.scheme->ptr);
/* request header */
for (i = 0; i < con->request.headers->used; i++) {
data_string *ds;
ds = (data_string *)con->request.headers->data[i];
if (!buffer_is_empty(ds->value) && !buffer_is_empty(ds->key)) {
if (buffer_is_equal_string(ds->key, CONST_STR_LEN("Connection"))) continue;
if (buffer_is_equal_string(ds->key, CONST_STR_LEN("Proxy-Connection"))) continue;
buffer_append_string_buffer(b, ds->key);
buffer_append_string_len(b, CONST_STR_LEN(": "));
buffer_append_string_buffer(b, ds->value);
buffer_append_string_len(b, CONST_STR_LEN("\r\n"));
}
}
buffer_append_string_len(b, CONST_STR_LEN("\r\n"));
hctx->wb->bytes_in += buffer_string_length(b);
chunkqueue_append_buffer(hctx->wb, b);
buffer_free(b);
/* body */
if (con->request.content_length) {
chunkqueue *req_cq = con->request_content_queue;
chunkqueue_steal(hctx->wb, req_cq, req_cq->bytes_in);
}
return 0;
}
示例2: http_list_directory_footer
static void http_list_directory_footer(server *srv, connection *con, plugin_data *p, buffer *out) {
UNUSED(srv);
buffer_append_string_len(out, CONST_STR_LEN(
"</tbody>\n"
"</table>\n"
"</div>\n"
));
if (!buffer_string_is_empty(p->conf.show_readme)) {
/* if we have a README file, display it in <pre class="readme"></pre> */
buffer *rb = p->conf.show_readme;
if (rb->ptr[0] != '/') {
buffer_copy_buffer(p->tmp_buf, con->physical.path);
buffer_append_path_len(p->tmp_buf, CONST_BUF_LEN(p->conf.show_readme));
rb = p->tmp_buf;
}
http_list_directory_include_file(out, con->conf.follow_symlink, rb, "readme", p->conf.encode_readme);
}
if(p->conf.auto_layout) {
buffer_append_string_len(out, CONST_STR_LEN(
"<div class=\"foot\">"
));
if (!buffer_string_is_empty(p->conf.set_footer)) {
buffer_append_string_buffer(out, p->conf.set_footer);
} else {
buffer_append_string_buffer(out, con->conf.server_tag);
}
buffer_append_string_len(out, CONST_STR_LEN(
"</div>\n"
));
if (!buffer_string_is_empty(p->conf.external_js)) {
buffer_append_string_len(out, CONST_STR_LEN("<script type=\"text/javascript\" src=\""));
buffer_append_string_buffer(out, p->conf.external_js);
buffer_append_string_len(out, CONST_STR_LEN("\"></script>\n"));
} else if (buffer_is_empty(p->conf.external_js)) {
http_dirlist_append_js_table_resort(out, con);
}
buffer_append_string_len(out, CONST_STR_LEN(
"</body>\n"
"</html>\n"
));
}
}
示例3: http_list_directory_footer
static void http_list_directory_footer(server *srv, connection *con, plugin_data *p, buffer *out) {
UNUSED(srv);
buffer_append_string_len(out, CONST_STR_LEN(
"</tbody>\n"
"</table>\n"
"</div>\n"
));
if (p->conf.show_readme) {
stream s;
/* if we have a README file, display it in <pre class="readme"></pre> */
buffer_copy_string_buffer(p->tmp_buf, con->physical.path);
BUFFER_APPEND_SLASH(p->tmp_buf);
buffer_append_string_len(p->tmp_buf, CONST_STR_LEN("README.txt"));
if (-1 != stream_open(&s, p->tmp_buf)) {
if (p->conf.encode_readme) {
buffer_append_string_len(out, CONST_STR_LEN("<pre class=\"readme\">"));
buffer_append_string_encoded(out, s.start, s.size, ENCODING_MINIMAL_XML);
buffer_append_string_len(out, CONST_STR_LEN("</pre>"));
} else {
buffer_append_string_len(out, s.start, s.size);
}
}
stream_close(&s);
}
if(p->conf.auto_layout) {
buffer_append_string_len(out, CONST_STR_LEN(
"<div class=\"foot\">"
));
if (p->conf.set_footer->used > 1) {
buffer_append_string_buffer(out, p->conf.set_footer);
} else if (buffer_is_empty(con->conf.server_tag)) {
buffer_append_string_len(out, CONST_STR_LEN(PACKAGE_DESC));
} else {
buffer_append_string_buffer(out, con->conf.server_tag);
}
buffer_append_string_len(out, CONST_STR_LEN(
"</div>\n"
"</body>\n"
"</html>\n"
));
}
}
示例4: mod_status_handle_server_statistics
static handler_t mod_status_handle_server_statistics(server *srv, connection *con, void *p_d) {
plugin_data *p = p_d;
buffer *b = p->module_list;
size_t i;
array *st = srv->status;
if (0 == st->used) {
/* we have nothing to send */
con->http_status = 204;
con->file_finished = 1;
return HANDLER_FINISHED;
}
b = chunkqueue_get_append_buffer(con->write_queue);
for (i = 0; i < st->used; i++) {
size_t ndx = st->sorted[i];
buffer_append_string_buffer(b, st->data[ndx]->key);
buffer_append_string(b, ": ");
buffer_append_long(b, ((data_integer *)(st->data[ndx]))->value);
buffer_append_string(b, "\n");
}
response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/plain"));
con->http_status = 200;
con->file_finished = 1;
return HANDLER_FINISHED;
}
示例5: mod_status_handle_server_statistics
static handler_t mod_status_handle_server_statistics(server *srv, connection *con, void *p_d) {
buffer *b;
size_t i;
array *st = srv->status;
UNUSED(p_d);
if (0 == st->used) {
/* we have nothing to send */
con->http_status = 204;
con->file_finished = 1;
return HANDLER_FINISHED;
}
b = buffer_init();
for (i = 0; i < st->used; i++) {
size_t ndx = st->sorted[i];
buffer_append_string_buffer(b, st->data[ndx]->key);
buffer_append_string_len(b, CONST_STR_LEN(": "));
buffer_append_int(b, ((data_integer *)(st->data[ndx]))->value);
buffer_append_string_len(b, CONST_STR_LEN("\n"));
}
chunkqueue_append_buffer(con->write_queue, b);
buffer_free(b);
response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/plain"));
con->http_status = 200;
con->file_finished = 1;
return HANDLER_FINISHED;
}
示例6: build_doc_root
static int build_doc_root(server *srv, connection *con, plugin_data *p, buffer *out, buffer *host) {
stat_cache_entry *sce = NULL;
buffer_prepare_copy(out, 128);
if (p->conf.server_root->used) {
buffer_copy_string_buffer(out, p->conf.server_root);
if (host->used) {
/* a hostname has to start with a alpha-numerical character
* and must not contain a slash "/"
*/
char *dp;
BUFFER_APPEND_SLASH(out);
if (NULL == (dp = strchr(host->ptr, ':'))) {
buffer_append_string_buffer(out, host);
} else {
buffer_append_string_len(out, host->ptr, dp - host->ptr);
}
}
BUFFER_APPEND_SLASH(out);
if (p->conf.document_root->used > 2 && p->conf.document_root->ptr[0] == '/') {
buffer_append_string_len(out, p->conf.document_root->ptr + 1, p->conf.document_root->used - 2);
} else {
buffer_append_string_buffer(out, p->conf.document_root);
BUFFER_APPEND_SLASH(out);
}
} else {
buffer_copy_string_buffer(out, con->conf.document_root);
BUFFER_APPEND_SLASH(out);
}
if (HANDLER_ERROR == stat_cache_get_entry(srv, con, out, &sce)) {
if (p->conf.debug) {
log_error_write(srv, __FILE__, __LINE__, "sb",
strerror(errno), out);
}
return -1;
} else if (!S_ISDIR(sce->st.st_mode)) {
return -1;
}
return 0;
}
示例7: data_response_insert_dup
static int data_response_insert_dup(data_unset *dst, data_unset *src) {
data_string *ds_dst = (data_string *)dst;
data_string *ds_src = (data_string *)src;
if (!buffer_is_empty(ds_dst->value)) {
buffer_append_string_len(ds_dst->value, CONST_STR_LEN("\r\n"));
buffer_append_string_buffer(ds_dst->value, ds_dst->key);
buffer_append_string_len(ds_dst->value, CONST_STR_LEN(": "));
buffer_append_string_buffer(ds_dst->value, ds_src->value);
} else {
buffer_copy_buffer(ds_dst->value, ds_src->value);
}
src->free(src);
return 0;
}
示例8: buffer_append_long
/* op1 is to be eat/return by this function if success, op1->key is not cared
op2 is left untouch, unreferenced
*/
data_unset *configparser_merge_data(data_unset *op1, const data_unset *op2) {
/* type mismatch */
if (op1->type != op2->type) {
if (op1->type == TYPE_STRING && op2->type == TYPE_INTEGER) {
data_string *ds = (data_string *)op1;
buffer_append_long(ds->value, ((data_integer*)op2)->value);
return op1;
} else if (op1->type == TYPE_INTEGER && op2->type == TYPE_STRING) {
data_string *ds = data_string_init();
buffer_append_long(ds->value, ((data_integer*)op1)->value);
buffer_append_string_buffer(ds->value, ((data_string*)op2)->value);
op1->free(op1);
return (data_unset *)ds;
} else {
fprintf(stderr, "data type mismatch, cannot be merge\n");
return NULL;
}
}
switch (op1->type) {
case TYPE_STRING:
buffer_append_string_buffer(((data_string *)op1)->value, ((data_string *)op2)->value);
break;
case TYPE_INTEGER:
((data_integer *)op1)->value += ((data_integer *)op2)->value;
break;
case TYPE_ARRAY: {
array *dst = ((data_array *)op1)->value;
array *src = ((data_array *)op2)->value;
data_unset *du;
size_t i;
for (i = 0; i < src->used; i ++) {
du = (data_unset *)src->data[i];
if (du) {
array_insert_unique(dst, du->copy(du));
}
}
break;
default:
assert(0);
break;
}
}
return op1;
}
示例9: http_list_directory_footer
static void http_list_directory_footer(server *srv, connection *con, plugin_data *p, buffer *out) {
UNUSED(srv);
buffer_append_string_len(out, CONST_STR_LEN(
"</tbody>\n"
"</table>\n"
"</div>\n"
));
if (p->conf.show_readme) {
/* if we have a README file, display it in <pre class="readme"></pre> */
buffer_copy_buffer(p->tmp_buf, con->physical.path);
buffer_append_slash(p->tmp_buf);
buffer_append_string_len(p->tmp_buf, CONST_STR_LEN("README.txt"));
http_list_directory_include_file(out, p->tmp_buf, "readme", p->conf.encode_readme);
}
if(p->conf.auto_layout) {
buffer_append_string_len(out, CONST_STR_LEN(
"<div class=\"foot\">"
));
if (!buffer_string_is_empty(p->conf.set_footer)) {
buffer_append_string_buffer(out, p->conf.set_footer);
} else {
buffer_append_string_buffer(out, con->conf.server_tag);
}
buffer_append_string_len(out, CONST_STR_LEN(
"</div>\n"
"</body>\n"
"</html>\n"
));
}
}
示例10: data_string_insert_dup
static int data_string_insert_dup(data_unset *dst, data_unset *src) {
data_string *ds_dst = (data_string *)dst;
data_string *ds_src = (data_string *)src;
if (ds_dst->value->used) {
buffer_append_string_len(ds_dst->value, CONST_STR_LEN(", "));
buffer_append_string_buffer(ds_dst->value, ds_src->value);
} else {
buffer_copy_string_buffer(ds_dst->value, ds_src->value);
}
src->free(src);
return 0;
}
示例11: http_response_finish_header
int http_response_finish_header(server *srv, connection *con)
{
if (NULL == srv || NULL == con || NULL == con -> write_queue)
{
return -1;
}
/*
* 这个header有安全问题。通产默认不添加。
*/
//http_response_insert_header(srv, con, CONST_STR_LEN("Server"), CONST_STR_LEN("Swiftd/0.1 written by hcy"));
buffer *b = chunkqueue_get_prepend_buffer(con -> write_queue);
if (NULL == b)
{
log_error_write(srv, __FILE__, __LINE__, "s", "chunkqueue_get_prepend_buffer failed.");
return -1;
}
buffer_reset(b);
/*
* Status-Line:
* HTTP-Version SP Status-Code SP Reason-Phrase CRLF
*/
buffer_copy_string_len(b, CONST_STR_LEN("HTTP/1.1"));
buffer_append_string_len(b, CONST_STR_LEN(" ")); //SP
buffer_append_long(b, con -> http_status);
buffer_append_string_len(b, CONST_STR_LEN(" ")); //SP
buffer_append_string(b, get_http_status_name(con -> http_status));
buffer_append_string_len(b, CONST_STR_LEN(CRLF)); //CRLF = '\r\n' defined in base.h
if(con -> keep_alive)
{
http_response_insert_header(srv, con, CONST_STR_LEN("Connection")
, CONST_STR_LEN("keep-alive"));
}
else
{
http_response_insert_header(srv, con, CONST_STR_LEN("Connection")
, CONST_STR_LEN("close"));
}
/*
* Headers:
* Key:Value CRLF
*/
size_t i;
data_string *ds;
for (i = 0; i < con -> response.headers -> used; ++i)
{
ds = (data_string *)con -> response.headers -> data[i];
if (NULL == ds)
{
continue;
}
buffer_append_string_buffer(b, ds -> key);
buffer_append_string_len(b, CONST_STR_LEN(": "));
buffer_append_string_buffer(b, ds -> value);
buffer_append_string_len(b, CONST_STR_LEN(CRLF));
}
/*
* header 和 message body之间的CRLF。
*/
buffer_append_string_len(b, CONST_STR_LEN(CRLF));
/*
* 最后一个'\0'不能发送出去!!
*/
-- b -> used;
log_error_write(srv, __FILE__, __LINE__, "sb", "Response Headers:", b);
array_reset(con -> response.headers);
return 0;
}
示例12: cgi_demux_response
static int cgi_demux_response(server *srv, handler_ctx *hctx) {
plugin_data *p = hctx->plugin_data;
connection *con = hctx->remote_conn;
while(1) {
int n;
buffer_prepare_copy(hctx->response, 1024);
if (-1 == (n = read(hctx->fd, hctx->response->ptr, hctx->response->size - 1))) {
if (errno == EAGAIN || errno == EINTR) {
/* would block, wait for signal */
return FDEVENT_HANDLED_NOT_FINISHED;
}
/* error */
log_error_write(srv, __FILE__, __LINE__, "sdd", strerror(errno), con->fd, hctx->fd);
return FDEVENT_HANDLED_ERROR;
}
if (n == 0) {
/* read finished */
con->file_finished = 1;
/* send final chunk */
http_chunk_append_mem(srv, con, NULL, 0);
joblist_append(srv, con);
return FDEVENT_HANDLED_FINISHED;
}
hctx->response->ptr[n] = '\0';
hctx->response->used = n+1;
/* split header from body */
if (con->file_started == 0) {
char *c;
int in_header = 0;
int header_end = 0;
int cp, eol = EOL_UNSET;
size_t used = 0;
buffer_append_string_buffer(hctx->response_header, hctx->response);
/* nph (non-parsed headers) */
if (0 == strncmp(hctx->response_header->ptr, "HTTP/1.", 7)) in_header = 1;
/* search for the \r\n\r\n or \n\n in the string */
for (c = hctx->response_header->ptr, cp = 0, used = hctx->response_header->used - 1; used; c++, cp++, used--) {
if (*c == ':') in_header = 1;
else if (*c == '\n') {
if (in_header == 0) {
/* got a response without a response header */
c = NULL;
header_end = 1;
break;
}
if (eol == EOL_UNSET) eol = EOL_N;
if (*(c+1) == '\n') {
header_end = 1;
break;
}
} else if (used > 1 && *c == '\r' && *(c+1) == '\n') {
if (in_header == 0) {
/* got a response without a response header */
c = NULL;
header_end = 1;
break;
}
if (eol == EOL_UNSET) eol = EOL_RN;
if (used > 3 &&
*(c+2) == '\r' &&
*(c+3) == '\n') {
header_end = 1;
break;
}
/* skip the \n */
c++;
cp++;
used--;
}
}
if (header_end) {
if (c == NULL) {
/* no header, but a body */
if (con->request.http_version == HTTP_VERSION_1_1) {
con->response.transfer_encoding = HTTP_TRANSFER_ENCODING_CHUNKED;
}
http_chunk_append_mem(srv, con, hctx->response_header->ptr, hctx->response_header->used);
//.........这里部分代码省略.........
示例13: config_set_defaults
int config_set_defaults(server *srv) {
size_t i;
specific_config *s = srv->config_storage[0];
struct stat st1, st2;
struct ev_map {
fdevent_handler_t et;
const char *name;
} event_handlers[] =
{
/* - poll is most reliable
* - select works everywhere
* - linux-* are experimental
*/
#ifdef USE_POLL
{ FDEVENT_HANDLER_POLL, "poll" },
#endif
#ifdef USE_SELECT
{ FDEVENT_HANDLER_SELECT, "select" },
#endif
#ifdef USE_LINUX_EPOLL
{ FDEVENT_HANDLER_LINUX_SYSEPOLL, "linux-sysepoll" },
#endif
#ifdef USE_LINUX_SIGIO
{ FDEVENT_HANDLER_LINUX_RTSIG, "linux-rtsig" },
#endif
#ifdef USE_SOLARIS_DEVPOLL
{ FDEVENT_HANDLER_SOLARIS_DEVPOLL,"solaris-devpoll" },
#endif
#ifdef USE_FREEBSD_KQUEUE
{ FDEVENT_HANDLER_FREEBSD_KQUEUE, "freebsd-kqueue" },
{ FDEVENT_HANDLER_FREEBSD_KQUEUE, "kqueue" },
#endif
{ FDEVENT_HANDLER_UNSET, NULL }
};
if (buffer_is_empty(s->document_root)) {
log_error_write(srv, __FILE__, __LINE__, "s",
"a default document-root has to be set");
return -1;
}
if (buffer_is_empty(srv->srvconf.changeroot)) {
if (-1 == stat(s->document_root->ptr, &st1)) {
log_error_write(srv, __FILE__, __LINE__, "sb",
"base-docroot doesn't exist:",
s->document_root);
return -1;
}
} else {
buffer_copy_string_buffer(srv->tmp_buf, srv->srvconf.changeroot);
buffer_append_string_buffer(srv->tmp_buf, s->document_root);
if (-1 == stat(srv->tmp_buf->ptr, &st1)) {
log_error_write(srv, __FILE__, __LINE__, "sb",
"base-docroot doesn't exist:",
srv->tmp_buf);
return -1;
}
}
buffer_copy_string_buffer(srv->tmp_buf, s->document_root);
buffer_to_lower(srv->tmp_buf);
if (0 == stat(srv->tmp_buf->ptr, &st1)) {
int is_lower = 0;
is_lower = buffer_is_equal(srv->tmp_buf, s->document_root);
/* lower-case existed, check upper-case */
buffer_copy_string_buffer(srv->tmp_buf, s->document_root);
buffer_to_upper(srv->tmp_buf);
/* we have to handle the special case that upper and lower-casing results in the same filename
* as in server.document-root = "/" or "/12345/" */
if (is_lower && buffer_is_equal(srv->tmp_buf, s->document_root)) {
/* lower-casing and upper-casing didn't result in
* an other filename, no need to stat(),
* just assume it is case-sensitive. */
s->force_lowercase_filenames = 0;
} else if (0 == stat(srv->tmp_buf->ptr, &st2)) {
/* upper case exists too, doesn't the FS handle this ? */
/* upper and lower have the same inode -> case-insensitve FS */
if (st1.st_ino == st2.st_ino) {
/* upper and lower have the same inode -> case-insensitve FS */
s->force_lowercase_filenames = 1;
}
}
//.........这里部分代码省略.........
示例14: log_error_write
/**
* 输出日志.
* 日志的格式:
* 2009-11-25 22:31:25: (filename.line) information
*
* 参数fmt的说明如下:
* 's':字符串 'b':buffer 'd':int 'o':off_t 'x':int的十六进制
* 上面的几个参数,在输出相应的值后都追加一个空格' '。
* 如果参数为大写,则不追加空格。
*
*/
int log_error_write(server * srv, const char *filename, unsigned int line,
const char *fmt, ...)
{
pthread_mutex_lock(&srv -> log_lock);
va_list ap;
switch (srv->errorlog_mode)
{
case ERRORLOG_FILE:
case ERRORLOG_STDERR:
/*
* 日志文件和标准错误输出要设定日志的时间。
*/
if (srv->cur_ts != srv->last_generated_debug_ts)
{
buffer_prepare_copy(srv->ts_debug_str, 1024);
strftime(srv->ts_debug_str->ptr, srv->ts_debug_str->size - 1,
"%Y-%m-%d %H:%M:%S", localtime(&(srv->cur_ts)));
srv->ts_debug_str->used = strlen(srv->ts_debug_str->ptr) + 1;
srv->last_generated_debug_ts = srv->cur_ts;
}
buffer_copy_string_buffer(srv->errorlog_buf, srv->ts_debug_str);
buffer_append_string_len(srv->errorlog_buf, CONST_STR_LEN(": ("));
break;
case ERRORLOG_SYSLOG:
/*
* syslog自己产生时间
*/
buffer_copy_string_len(srv->errorlog_buf, CONST_STR_LEN("("));
break;
}
buffer_append_string(srv->errorlog_buf, filename);
buffer_append_string_len(srv->errorlog_buf, CONST_STR_LEN("."));
buffer_append_long(srv->errorlog_buf, line);
buffer_append_string_len(srv->errorlog_buf, CONST_STR_LEN(") "));
//根据字符串fmt来遍历可变参数。
for (va_start(ap, fmt); *fmt; fmt++)
{
int d;
char *s;
buffer *b;
off_t o;
switch (*fmt)
{
case 's': /* string */
s = va_arg(ap, char *);
buffer_append_string(srv->errorlog_buf, s);
buffer_append_string_len(srv->errorlog_buf, CONST_STR_LEN(" "));
break;
case 'b': /* buffer */
b = va_arg(ap, buffer *);
buffer_append_string_buffer(srv->errorlog_buf, b);
buffer_append_string_len(srv->errorlog_buf, CONST_STR_LEN(" "));
break;
case 'd': /* int */
d = va_arg(ap, int);
buffer_append_long(srv->errorlog_buf, d);
buffer_append_string_len(srv->errorlog_buf, CONST_STR_LEN(" "));
break;
case 'o': /* off_t */
o = va_arg(ap, off_t);
buffer_append_off_t(srv->errorlog_buf, o);
buffer_append_string_len(srv->errorlog_buf, CONST_STR_LEN(" "));
break;
case 'x': /* int (hex) */
d = va_arg(ap, int);
buffer_append_string_len(srv->errorlog_buf, CONST_STR_LEN("0x"));
buffer_append_long_hex(srv->errorlog_buf, d);
buffer_append_string_len(srv->errorlog_buf, CONST_STR_LEN(" "));
break;
case 'S': /* string */
s = va_arg(ap, char *);
buffer_append_string(srv->errorlog_buf, s);
break;
case 'B': /* buffer */
b = va_arg(ap, buffer *);
buffer_append_string_buffer(srv->errorlog_buf, b);
break;
case 'D': /* int */
d = va_arg(ap, int);
buffer_append_long(srv->errorlog_buf, d);
break;
case 'O': /* off_t */
o = va_arg(ap, off_t);
//.........这里部分代码省略.........
示例15: cgi_demux_response
static int cgi_demux_response(server *srv, handler_ctx *hctx) {
plugin_data *p = hctx->plugin_data;
connection *con = hctx->remote_conn;
while(1) {
int n;
int toread;
#if defined(__WIN32)
buffer_prepare_copy(hctx->response, 4 * 1024);
#else
if (ioctl(con->fd, FIONREAD, &toread) || toread == 0 || toread <= 4*1024) {
buffer_prepare_copy(hctx->response, 4 * 1024);
} else {
if (toread > MAX_READ_LIMIT) toread = MAX_READ_LIMIT;
buffer_prepare_copy(hctx->response, toread + 1);
}
#endif
if (-1 == (n = read(hctx->fd, hctx->response->ptr, hctx->response->size - 1))) {
if (errno == EAGAIN || errno == EINTR) {
/* would block, wait for signal */
return FDEVENT_HANDLED_NOT_FINISHED;
}
/* error */
log_error_write(srv, __FILE__, __LINE__, "sdd", strerror(errno), con->fd, hctx->fd);
return FDEVENT_HANDLED_ERROR;
}
if (n == 0) {
/* read finished */
con->file_finished = 1;
/* send final chunk */
http_chunk_append_mem(srv, con, NULL, 0);
joblist_append(srv, con);
return FDEVENT_HANDLED_FINISHED;
}
hctx->response->ptr[n] = '\0';
hctx->response->used = n+1;
/* split header from body */
if (con->file_started == 0) {
int is_header = 0;
int is_header_end = 0;
size_t last_eol = 0;
size_t i;
buffer_append_string_buffer(hctx->response_header, hctx->response);
/**
* we have to handle a few cases:
*
* nph:
*
* HTTP/1.0 200 Ok\n
* Header: Value\n
* \n
*
* CGI:
* Header: Value\n
* Status: 200\n
* \n
*
* and different mixes of \n and \r\n combinations
*
* Some users also forget about CGI and just send a response and hope
* we handle it. No headers, no header-content seperator
*
*/
/* nph (non-parsed headers) */
if (0 == strncmp(hctx->response_header->ptr, "HTTP/1.", 7)) is_header = 1;
for (i = 0; !is_header_end && i < hctx->response_header->used - 1; i++) {
char c = hctx->response_header->ptr[i];
switch (c) {
case ':':
/* we found a colon
*
* looks like we have a normal header
*/
is_header = 1;
break;
case '\n':
/* EOL */
if (is_header == 0) {
/* we got a EOL but we don't seem to got a HTTP header */
is_header_end = 1;
break;
}
/**
//.........这里部分代码省略.........