• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ buffer_string_length函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中buffer_string_length函数的典型用法代码示例。如果您正苦于以下问题:C++ buffer_string_length函数的具体用法?C++ buffer_string_length怎么用?C++ buffer_string_length使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了buffer_string_length函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:AndreLouisCaron,项目名称:lighttpd,代码行数:28,代码来源:mod_cml.c


示例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);
	}
}
开发者ID:jonahglover,项目名称:lighttpd1.4,代码行数:59,代码来源:mod_accesslog.c


示例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;
}
开发者ID:AndreLouisCaron,项目名称:lighttpd,代码行数:59,代码来源:network_writev.c


示例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);
}
开发者ID:Shield-Firewall,项目名称:lighttpd1.4,代码行数:59,代码来源:chunk.c


示例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;
}
开发者ID:glensc,项目名称:lighttpd,代码行数:10,代码来源:request.c


示例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;
    }
}
开发者ID:ChunHungLiu,项目名称:lighttpd1.4,代码行数:54,代码来源:http-header-glue.c


示例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;
}
开发者ID:gstrauss,项目名称:lighttpd1.4,代码行数:31,代码来源:mod_flv_streaming.c


示例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;
}
开发者ID:automatical,项目名称:lighttpd1.4,代码行数:58,代码来源:mod_proxy.c


示例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;
}
开发者ID:jonahglover,项目名称:lighttpd1.4,代码行数:58,代码来源:mod_evhost.c


示例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);
	}
}
开发者ID:loganaden,项目名称:lighttpd1.4,代码行数:56,代码来源:chunk.c


示例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;
}
开发者ID:automatical,项目名称:lighttpd1.4,代码行数:42,代码来源:mod_simple_vhost.c


示例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;
}
开发者ID:glensc,项目名称:lighttpd,代码行数:40,代码来源:log.c


示例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;
}
开发者ID:automatical,项目名称:lighttpd1.4,代码行数:14,代码来源:stat_cache.c


示例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;
}
开发者ID:AndreLouisCaron,项目名称:lighttpd,代码行数:48,代码来源:mod_flv_streaming.c


示例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;
}
开发者ID:Shield-Firewall,项目名称:lighttpd1.4,代码行数:16,代码来源:chunk.c


示例16: test_buffer_string_space

static void test_buffer_string_space(void) {
	buffer *b = buffer_init();
	size_t space;

	space = buffer_string_space(b);
	assert(0 == space);
	buffer_copy_string_len(b, CONST_STR_LEN(""));
	space = buffer_string_space(b);
	assert(space > 0);
	assert(space + buffer_string_length(b) == b->size - 1);
	buffer_commit(b, b->size - 1);
	assert(b->used == b->size);
	space = buffer_string_space(b);
	assert(0 == space);

	buffer_free(b);
}
开发者ID:gstrauss,项目名称:lighttpd1.4,代码行数:17,代码来源:test_buffer.c


示例17: data_string_print

static void data_string_print(const data_unset *d, int depth) {
	data_string *ds = (data_string *)d;
	size_t i, len;
	UNUSED(depth);

	/* empty and uninitialized strings */
	if (buffer_string_is_empty(ds->value)) {
		fputs("\"\"", stdout);
		return;
	}

	/* print out the string as is, except prepend " with backslash */
	putc('"', stdout);
	len = buffer_string_length(ds->value);
	for (i = 0; i < len; i++) {
		unsigned char c = ds->value->ptr[i];
		if (c == '"') {
			fputs("\\\"", stdout);
		} else {
			putc(c, stdout);
		}
	}
	putc('"', stdout);
}
开发者ID:carriercomm,项目名称:lighttpd_ported,代码行数:24,代码来源:data_string.c


示例18: mod_redirect_uri_handler

static handler_t mod_redirect_uri_handler(server *srv, connection *con, void *p_data) {
#ifdef HAVE_PCRE_H
	plugin_data *p = p_data;
	size_t i;

	/*
	 * REWRITE URL
	 *
	 * e.g. redirect /base/ to /index.php?section=base
	 *
	 */

	mod_redirect_patch_connection(srv, con, p);

	buffer_copy_buffer(p->match_buf, con->request.uri);

	for (i = 0; i < p->conf.redirect->used; i++) {
		pcre *match;
		pcre_extra *extra;
		const char *pattern;
		size_t pattern_len;
		int n;
		pcre_keyvalue *kv = p->conf.redirect->kv[i];
# define N 10
		int ovec[N * 3];

		match       = kv->key;
		extra       = kv->key_extra;
		pattern     = kv->value->ptr;
		pattern_len = buffer_string_length(kv->value);

		if ((n = pcre_exec(match, extra, CONST_BUF_LEN(p->match_buf), 0, 0, ovec, 3 * N)) < 0) {
			if (n != PCRE_ERROR_NOMATCH) {
				log_error_write(srv, __FILE__, __LINE__, "sd",
						"execution error while matching: ", n);
				return HANDLER_ERROR;
			}
		} else {
			const char **list;
			size_t start;
			size_t k;

			/* it matched */
			pcre_get_substring_list(p->match_buf->ptr, ovec, n, &list);

			/* search for $[0-9] */

			buffer_reset(p->location);

			start = 0;
			for (k = 0; k + 1 < pattern_len; k++) {
				if (pattern[k] == '$' || pattern[k] == '%') {
					/* got one */

					size_t num = pattern[k + 1] - '0';

					buffer_append_string_len(p->location, pattern + start, k - start);

					if (!isdigit((unsigned char)pattern[k + 1])) {
						/* enable escape: "%%" => "%", "%a" => "%a", "$$" => "$" */
						buffer_append_string_len(p->location, pattern+k, pattern[k] == pattern[k+1] ? 1 : 2);
					} else if (pattern[k] == '$') {
						/* n is always > 0 */
						if (num < (size_t)n) {
							buffer_append_string(p->location, list[num]);
						}
					} else if (p->conf.context == NULL) {
						/* we have no context, we are global */
						log_error_write(srv, __FILE__, __LINE__, "sb",
								"used a rewrite containing a %[0-9]+ in the global scope, ignored:",
								kv->value);
					} else {
						config_append_cond_match_buffer(con, p->conf.context, p->location, num);
					}

					k++;
					start = k + 1;
				}
			}

			buffer_append_string_len(p->location, pattern + start, pattern_len - start);

			pcre_free(list);

			response_header_insert(srv, con, CONST_STR_LEN("Location"), CONST_BUF_LEN(p->location));

			con->http_status = p->conf.redirect_code > 99 && p->conf.redirect_code < 1000 ? p->conf.redirect_code : 301;
			con->mode = DIRECT;
			con->file_finished = 1;

			return HANDLER_FINISHED;
		}
	}
#undef N

#else
	UNUSED(srv);
	UNUSED(con);
	UNUSED(p_data);
#endif
//.........这里部分代码省略.........
开发者ID:lilohuang,项目名称:lighttpd1.4,代码行数:101,代码来源:mod_redirect.c


示例19: stat_cache_get_entry


//.........这里部分代码省略.........
		if (sc->dirs && (sc->dirs->key == dir_ndx)) {
			dir_node = sc->dirs;
		}

		if (dir_node && file_node) {
			/* we found a file */

			sce = file_node->data;
			fam_dir = dir_node->data;

			if (fam_dir->version == sce->dir_version) {
				/* the stat()-cache entry is still ok */

				*ret_sce = sce;
				return HANDLER_GO_ON;
			}
		}
	}
#endif

	/*
	 * *lol*
	 * - open() + fstat() on a named-pipe results in a (intended) hang.
	 * - stat() if regular file + open() to see if we can read from it is better
	 *
	 * */
	if (-1 == stat(name->ptr, &st)) {
		return HANDLER_ERROR;
	}


	if (S_ISREG(st.st_mode)) {
		/* fix broken stat/open for symlinks to reg files with appended slash on freebsd,osx */
		if (name->ptr[buffer_string_length(name) - 1] == '/') {
			errno = ENOTDIR;
			return HANDLER_ERROR;
		}

		/* try to open the file to check if we can read it */
		if (-1 == (fd = open(name->ptr, O_RDONLY))) {
			return HANDLER_ERROR;
		}
		close(fd);
	}

	if (NULL == sce) {
#ifdef DEBUG_STAT_CACHE
		int osize = splaytree_size(sc->files);
#endif

		sce = stat_cache_entry_init();
		buffer_copy_buffer(sce->name, name);

		sc->files = splaytree_insert(sc->files, file_ndx, sce);
#ifdef DEBUG_STAT_CACHE
		if (ctrl.size == 0) {
			ctrl.size = 16;
			ctrl.used = 0;
			ctrl.ptr = malloc(ctrl.size * sizeof(*ctrl.ptr));
		} else if (ctrl.size == ctrl.used) {
			ctrl.size += 16;
			ctrl.ptr = realloc(ctrl.ptr, ctrl.size * sizeof(*ctrl.ptr));
		}

		ctrl.ptr[ctrl.used++] = file_ndx;
开发者ID:automatical,项目名称:lighttpd1.4,代码行数:66,代码来源:stat_cache.c


示例20: deflate_compress_response

static handler_t deflate_compress_response(server *srv, connection *con, handler_ctx *hctx) {
	off_t len, max;
	int close_stream;

	/* move all chunk from write_queue into our in_queue, then adjust
	 * counters since con->write_queue is reused for compressed output */
	len = chunkqueue_length(con->write_queue);
	chunkqueue_remove_finished_chunks(con->write_queue);
	chunkqueue_append_chunkqueue(hctx->in_queue, con->write_queue);
	con->write_queue->bytes_in  -= len;
	con->write_queue->bytes_out -= len;

	max = chunkqueue_length(hctx->in_queue);
      #if 0
	/* calculate max bytes to compress for this call */
	if (p->conf.sync_flush && max > (len = p->conf.work_block_size << 10)) {
		max = len;
	}
      #endif

	/* Compress chunks from in_queue into chunks for write_queue */
	while (max) {
		chunk *c = hctx->in_queue->first;

		switch(c->type) {
		case MEM_CHUNK:
			len = buffer_string_length(c->mem) - c->offset;
			if (len > max) len = max;
			if (mod_deflate_compress(srv, con, hctx, (unsigned char *)c->mem->ptr+c->offset, len) < 0) {
				log_error_write(srv, __FILE__, __LINE__, "s",
						"compress failed.");
				return HANDLER_ERROR;
			}
			break;
		case FILE_CHUNK:
			len = c->file.length - c->offset;
			if (len > max) len = max;
			if ((len = mod_deflate_file_chunk(srv, con, hctx, c, len)) < 0) {
				log_error_write(srv, __FILE__, __LINE__, "s",
						"compress file chunk failed.");
				return HANDLER_ERROR;
			}
			break;
		default:
			log_error_write(srv, __FILE__, __LINE__, "ds", c, "type not known");
			return HANDLER_ERROR;
		}

		max -= len;
		chunkqueue_mark_written(hctx->in_queue, len);
	}

	/*(currently should always be true)*/
	/*(current implementation requires response be complete)*/
	close_stream = (con->file_finished && chunkqueue_is_empty(hctx->in_queue));
	if (mod_deflate_stream_flush(srv, con, hctx, close_stream) < 0) {
		log_error_write(srv, __FILE__, __LINE__, "s", "flush error");
		return HANDLER_ERROR;
	}

	return close_stream ? HANDLER_FINISHED : HANDLER_GO_ON;
}
开发者ID:ikayzo,项目名称:lighttpd1.4,代码行数:62,代码来源:mod_deflate.c



注:本文中的buffer_string_length函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ buffer_uptodate函数代码示例发布时间:2022-05-30
下一篇:
C++ buffer_string_is_empty函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap