本文整理汇总了C++中buffer_string_length函数的典型用法代码示例。如果您正苦于以下问题:C++ buffer_string_length函数的具体用法?C++ buffer_string_length怎么用?C++ buffer_string_length使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了buffer_string_length函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cache_call_lua
static int cache_call_lua(server *srv, connection *con, plugin_data *p, buffer *cml_file) {
buffer *b;
char *c;
/* cleanup basedir */
b = p->baseurl;
buffer_copy_buffer(b, con->uri.path);
for (c = b->ptr + buffer_string_length(b); c > b->ptr && *c != '/'; c--);
if (*c == '/') {
buffer_string_set_length(b, c - b->ptr + 1);
}
b = p->basedir;
buffer_copy_buffer(b, con->physical.path);
for (c = b->ptr + buffer_string_length(b); c > b->ptr && *c != '/'; c--);
if (*c == '/') {
buffer_string_set_length(b, c - b->ptr + 1);
}
/* prepare variables
* - cookie-based
* - get-param-based
*/
return cache_parse_lua(srv, con, p, cml_file);
}
示例2: accesslog_append_escaped
static void accesslog_append_escaped(buffer *dest, buffer *str) {
char *ptr, *start, *end;
/* replaces non-printable chars with \xHH where HH is the hex representation of the byte */
/* exceptions: " => \", \ => \\, whitespace chars => \n \t etc. */
if (buffer_string_is_empty(str)) return;
buffer_string_prepare_append(dest, buffer_string_length(str));
for (ptr = start = str->ptr, end = str->ptr + buffer_string_length(str); ptr < end; ptr++) {
unsigned char const c = (unsigned char) *ptr;
if (c >= ' ' && c <= '~' && c != '"' && c != '\\') {
/* nothing to change, add later as one block */
} else {
/* copy previous part */
if (start < ptr) {
buffer_append_string_len(dest, start, ptr - start);
}
start = ptr + 1;
switch (c) {
case '"':
BUFFER_APPEND_STRING_CONST(dest, "\\\"");
break;
case '\\':
BUFFER_APPEND_STRING_CONST(dest, "\\\\");
break;
case '\b':
BUFFER_APPEND_STRING_CONST(dest, "\\b");
break;
case '\n':
BUFFER_APPEND_STRING_CONST(dest, "\\n");
break;
case '\r':
BUFFER_APPEND_STRING_CONST(dest, "\\r");
break;
case '\t':
BUFFER_APPEND_STRING_CONST(dest, "\\t");
break;
case '\v':
BUFFER_APPEND_STRING_CONST(dest, "\\v");
break;
default: {
/* non printable char => \xHH */
char hh[5] = {'\\','x',0,0,0};
char h = c / 16;
hh[2] = (h > 9) ? (h - 10 + 'A') : (h + '0');
h = c % 16;
hh[3] = (h > 9) ? (h - 10 + 'A') : (h + '0');
buffer_append_string_len(dest, &hh[0], 4);
}
break;
}
}
}
if (start < end) {
buffer_append_string_len(dest, start, end - start);
}
}
示例3: network_writev_mem_chunks
int network_writev_mem_chunks(server *srv, connection *con, int fd, chunkqueue *cq, off_t *p_max_bytes) {
struct iovec chunks[MAX_CHUNKS];
size_t num_chunks;
off_t max_bytes = *p_max_bytes;
off_t toSend;
ssize_t r;
UNUSED(con);
force_assert(NULL != cq->first);
force_assert(MEM_CHUNK == cq->first->type);
{
chunk const *c;
toSend = 0;
num_chunks = 0;
for (c = cq->first; NULL != c && MEM_CHUNK == c->type && num_chunks < MAX_CHUNKS && toSend < max_bytes; c = c->next) {
size_t c_len;
force_assert(c->offset >= 0 && c->offset <= (off_t)buffer_string_length(c->mem));
c_len = buffer_string_length(c->mem) - c->offset;
if (c_len > 0) {
toSend += c_len;
chunks[num_chunks].iov_base = c->mem->ptr + c->offset;
chunks[num_chunks].iov_len = c_len;
++num_chunks;
}
}
}
if (0 == num_chunks) {
chunkqueue_remove_finished_chunks(cq);
return 0;
}
r = writev(fd, chunks, num_chunks);
if (r < 0) switch (errno) {
case EAGAIN:
case EINTR:
break;
case EPIPE:
case ECONNRESET:
return -2;
default:
log_error_write(srv, __FILE__, __LINE__, "ssd",
"writev failed:", strerror(errno), fd);
return -1;
}
if (r >= 0) {
*p_max_bytes -= r;
chunkqueue_mark_written(cq, r);
}
return (r > 0 && r == toSend) ? 0 : -3;
}
示例4: chunkqueue_get_memory
void chunkqueue_get_memory(chunkqueue *cq, char **mem, size_t *len, size_t min_size, size_t alloc_size) {
static const size_t REALLOC_MAX_SIZE = 256;
chunk *c;
buffer *b;
char *dummy_mem;
size_t dummy_len;
force_assert(NULL != cq);
if (NULL == mem) mem = &dummy_mem;
if (NULL == len) len = &dummy_len;
/* default values: */
if (0 == min_size) min_size = 1024;
if (0 == alloc_size) alloc_size = 4096;
if (alloc_size < min_size) alloc_size = min_size;
if (NULL != cq->last && MEM_CHUNK == cq->last->type) {
size_t have;
b = cq->last->mem;
have = buffer_string_space(b);
/* unused buffer: allocate space */
if (buffer_string_is_empty(b)) {
buffer_string_prepare_copy(b, alloc_size);
have = buffer_string_space(b);
}
/* if buffer is really small just make it bigger */
else if (have < min_size && b->size <= REALLOC_MAX_SIZE) {
size_t cur_len = buffer_string_length(b);
size_t new_size = cur_len + min_size, append;
if (new_size < alloc_size) new_size = alloc_size;
append = new_size - cur_len;
if (append >= min_size) {
buffer_string_prepare_append(b, append);
have = buffer_string_space(b);
}
}
/* return pointer into existing buffer if large enough */
if (have >= min_size) {
*mem = b->ptr + buffer_string_length(b);
*len = have;
return;
}
}
/* allocate new chunk */
c = chunkqueue_get_unused_chunk(cq);
c->type = MEM_CHUNK;
chunkqueue_append_chunk(cq, c);
b = c->mem;
buffer_string_prepare_append(b, alloc_size);
*mem = b->ptr + buffer_string_length(b);
*len = buffer_string_space(b);
}
示例5: http_request_header_finished
int http_request_header_finished(server *srv, connection *con) {
UNUSED(srv);
if (buffer_string_length(con->request.request) < 4) return 0;
if (0 == memcmp(con->request.request->ptr + buffer_string_length(con->request.request) - 4, CONST_STR_LEN("\r\n\r\n"))) return 1;
if (NULL != strstr(con->request.request->ptr, "\r\n\r\n")) return 1;
return 0;
}
示例6: http_response_xsendfile
void http_response_xsendfile (server *srv, connection *con, buffer *path, const array *xdocroot) {
const int status = con->http_status;
int valid = 1;
/* reset Content-Length, if set by backend
* Content-Length might later be set to size of X-Sendfile static file,
* determined by open(), fstat() to reduces race conditions if the file
* is modified between stat() (stat_cache_get_entry()) and open(). */
if (con->parsed_response & HTTP_CONTENT_LENGTH) {
data_string *ds = (data_string *) array_get_element(con->response.headers, "Content-Length");
if (ds) buffer_reset(ds->value);
con->parsed_response &= ~HTTP_CONTENT_LENGTH;
con->response.content_length = -1;
}
buffer_urldecode_path(path);
buffer_path_simplify(path, path);
if (con->conf.force_lowercase_filenames) {
buffer_to_lower(path);
}
/* check that path is under xdocroot(s)
* - xdocroot should have trailing slash appended at config time
* - con->conf.force_lowercase_filenames is not a server-wide setting,
* and so can not be definitively applied to xdocroot at config time*/
if (xdocroot->used) {
size_t i, xlen = buffer_string_length(path);
for (i = 0; i < xdocroot->used; ++i) {
data_string *ds = (data_string *)xdocroot->data[i];
size_t dlen = buffer_string_length(ds->value);
if (dlen <= xlen
&& (!con->conf.force_lowercase_filenames
? 0 == memcmp(path->ptr, ds->value->ptr, dlen)
: 0 == strncasecmp(path->ptr, ds->value->ptr, dlen))) {
break;
}
}
if (i == xdocroot->used) {
log_error_write(srv, __FILE__, __LINE__, "SBs",
"X-Sendfile (", path,
") not under configured x-sendfile-docroot(s)");
con->http_status = 403;
valid = 0;
}
}
if (valid) http_response_send_file(srv, con, path);
if (con->http_status >= 400 && status < 300) {
con->mode = DIRECT;
} else if (0 != status && 200 != status) {
con->http_status = status;
}
}
示例7: split_get_params
static int split_get_params(array *get_params, buffer *qrystr) {
size_t is_key = 1, klen = 0;
char *key = qrystr->ptr, *val = NULL;
if (buffer_string_is_empty(qrystr)) return 0;
for (size_t i = 0, len = buffer_string_length(qrystr); i <= len; ++i) {
switch(qrystr->ptr[i]) {
case '=':
if (is_key) {
val = qrystr->ptr + i + 1;
klen = (size_t)(qrystr->ptr + i - key);
is_key = 0;
}
break;
case '&':
case '\0': /* fin symbol */
if (!is_key) {
/* we need at least a = since the last & */
array_insert_key_value(get_params, key, klen, val, qrystr->ptr + i - val);
}
key = qrystr->ptr + i + 1;
val = NULL;
is_key = 1;
break;
}
}
return 0;
}
示例8: 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;
}
示例9: mod_evhost_parse_host
static int mod_evhost_parse_host(connection *con,array *host) {
register char *ptr = con->uri.authority->ptr + buffer_string_length(con->uri.authority);
char *colon = ptr; /* needed to filter out the colon (if exists) */
int first = 1;
data_string *ds;
int i;
/* first, find the domain + tld */
for(; ptr > con->uri.authority->ptr; ptr--) {
if(*ptr == '.') {
if(first) first = 0;
else break;
} else if(*ptr == ':') {
colon = ptr;
first = 1;
}
}
ds = data_string_init();
buffer_copy_string_len(ds->key,CONST_STR_LEN("%0"));
/* if we stopped at a dot, skip the dot */
if (*ptr == '.') ptr++;
buffer_copy_string_len(ds->value, ptr, colon-ptr);
array_insert_unique(host,(data_unset *)ds);
/* if the : is not the start of the authority, go on parsing the hostname */
if (colon != con->uri.authority->ptr) {
for(ptr = colon - 1, i = 1; ptr > con->uri.authority->ptr; ptr--) {
if(*ptr == '.') {
if (ptr != colon - 1) {
/* is something between the dots */
ds = data_string_init();
buffer_copy_string_len(ds->key,CONST_STR_LEN("%"));
buffer_append_int(ds->key, i++);
buffer_copy_string_len(ds->value,ptr+1,colon-ptr-1);
array_insert_unique(host,(data_unset *)ds);
}
colon = ptr;
}
}
/* if the . is not the first charactor of the hostname */
if (colon != ptr) {
ds = data_string_init();
buffer_copy_string_len(ds->key,CONST_STR_LEN("%"));
buffer_append_int(ds->key, i /* ++ */);
buffer_copy_string_len(ds->value,ptr,colon-ptr);
array_insert_unique(host,(data_unset *)ds);
}
}
return 0;
}
示例10: chunkqueue_steal
void chunkqueue_steal(chunkqueue *dest, chunkqueue *src, off_t len) {
while (len > 0) {
chunk *c = src->first;
off_t clen = 0, use;
if (NULL == c) break;
switch (c->type) {
case MEM_CHUNK:
clen = buffer_string_length(c->mem);
break;
case FILE_CHUNK:
clen = c->file.length;
break;
}
force_assert(clen >= c->offset);
clen -= c->offset;
use = len >= clen ? clen : len;
src->bytes_out += use;
dest->bytes_in += use;
len -= use;
if (0 == clen) {
/* drop empty chunk */
src->first = c->next;
if (c == src->last) src->last = NULL;
chunkqueue_push_unused_chunk(src, c);
continue;
}
if (use == clen) {
/* move complete chunk */
src->first = c->next;
if (c == src->last) src->last = NULL;
chunkqueue_append_chunk(dest, c);
continue;
}
/* partial chunk with length "use" */
switch (c->type) {
case MEM_CHUNK:
chunkqueue_append_mem(dest, c->mem->ptr + c->offset, use);
break;
case FILE_CHUNK:
/* tempfile flag is in "last" chunk after the split */
chunkqueue_append_file(dest, c->file.name, c->file.start + c->offset, use);
break;
}
c->offset += use;
force_assert(0 == len);
}
}
示例11: build_doc_root
static int build_doc_root(server *srv, connection *con, plugin_data *p, buffer *out, buffer *host) {
stat_cache_entry *sce = NULL;
force_assert(!buffer_string_is_empty(p->conf.server_root));
buffer_string_prepare_copy(out, 127);
buffer_copy_buffer(out, p->conf.server_root);
if (!buffer_string_is_empty(host)) {
/* 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 (buffer_string_length(p->conf.document_root) > 1 && p->conf.document_root->ptr[0] == '/') {
buffer_append_string_len(out, p->conf.document_root->ptr + 1, buffer_string_length(p->conf.document_root) - 1);
} else {
buffer_append_string_buffer(out, p->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;
}
示例12: log_error_write_multiline_buffer
int log_error_write_multiline_buffer(server *srv, const char *filename, unsigned int line, buffer *multiline, const char *fmt, ...) {
va_list ap;
size_t prefix_len;
buffer *b = srv->errorlog_buf;
char *pos, *end, *current_line;
if (buffer_string_is_empty(multiline)) return 0;
if (-1 == log_buffer_prepare(b, srv, filename, line)) return 0;
va_start(ap, fmt);
log_buffer_append_printf(b, fmt, ap);
va_end(ap);
prefix_len = buffer_string_length(b);
current_line = pos = multiline->ptr;
end = multiline->ptr + buffer_string_length(multiline);
for ( ; pos <= end ; ++pos) {
switch (*pos) {
case '\n':
case '\r':
case '\0': /* handles end of string */
if (current_line < pos) {
/* truncate to prefix */
buffer_string_set_length(b, prefix_len);
buffer_append_string_len(b, current_line, pos - current_line);
log_write(srv, b);
}
current_line = pos + 1;
break;
default:
break;
}
}
return 0;
}
示例13: buffer_copy_dirname
static int buffer_copy_dirname(buffer *dst, buffer *file) {
size_t i;
if (buffer_string_is_empty(file)) return -1;
for (i = buffer_string_length(file); i > 0; i--) {
if (file->ptr[i] == '/') {
buffer_copy_string_len(dst, file->ptr, i);
return 0;
}
}
return -1;
}
示例14: split_get_params
static int split_get_params(array *get_params, buffer *qrystr) {
size_t is_key = 1;
size_t i, len;
char *key = NULL, *val = NULL;
key = qrystr->ptr;
/* we need the \0 */
len = buffer_string_length(qrystr);
for (i = 0; i <= len; i++) {
switch(qrystr->ptr[i]) {
case '=':
if (is_key) {
val = qrystr->ptr + i + 1;
qrystr->ptr[i] = '\0';
is_key = 0;
}
break;
case '&':
case '\0': /* fin symbol */
if (!is_key) {
data_string *ds;
/* we need at least a = since the last & */
/* terminate the value */
qrystr->ptr[i] = '\0';
if (NULL == (ds = (data_string *)array_get_unused_element(get_params, TYPE_STRING))) {
ds = data_string_init();
}
buffer_copy_string_len(ds->key, key, strlen(key));
buffer_copy_string_len(ds->value, val, strlen(val));
array_insert_unique(get_params, (data_unset *)ds);
}
key = qrystr->ptr + i + 1;
val = NULL;
is_key = 1;
break;
}
}
return 0;
}
示例15: chunk_remaining_length
static off_t chunk_remaining_length(const chunk *c) {
off_t len = 0;
switch (c->type) {
case MEM_CHUNK:
len = buffer_string_length(c->mem);
break;
case FILE_CHUNK:
len = c->file.length;
break;
default:
force_assert(c->type == MEM_CHUNK || c->type == FILE_CHUNK);
break;
}
force_assert(c->offset <= len);
return len - c->offset;
}