#line 1 "http_parser.rl"
/* Copyright (c) 2008, 2009 Ryan Dahl (ry@tinyclouds.org)
* Based on Zed Shaw's Mongrel, copyright (c) Zed A. Shaw
*
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "http_parser.h"
#include <limits.h>
#include <assert.h>
static int unhex[] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1
,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1
,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1
,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
};
#define TRUE 1
#define FALSE 0
#define MIN(a,b) (a < b ? a : b)
#define NULL (void*)(0)
#define MAX_FIELD_SIZE 80*1024
#define REMAINING (pe - p)
#define CALLBACK(FOR) \
do { \
if (parser->FOR##_mark) { \
parser->FOR##_size += p - parser->FOR##_mark; \
if (parser->FOR##_size > MAX_FIELD_SIZE) { \
parser->error = TRUE; \
return 0; \
} \
if (parser->on_##FOR) { \
callback_return_value = parser->on_##FOR(parser, \
parser->FOR##_mark, \
p - parser->FOR##_mark); \
} \
} \
} while(0)
#define RESET_PARSER(parser) \
parser->chunk_size = 0; \
parser->eating = 0; \
parser->header_field_mark = NULL; \
parser->header_value_mark = NULL; \
parser->query_string_mark = NULL; \
parser->path_mark = NULL; \
parser->uri_mark = NULL; \
parser->fragment_mark = NULL; \
parser->status_code = 0; \
parser->method = 0; \
parser->transfer_encoding = HTTP_IDENTITY; \
parser->version_major = 0; \
parser->version_minor = 0; \
parser->keep_alive = -1; \
parser->content_length = 0; \
parser->body_read = 0;
#define END_REQUEST \
do { \
if (parser->on_message_complete) { \
callback_return_value = \
parser->on_message_complete(parser); \
} \
RESET_PARSER(parser); \
} while (0)
#define SKIP_BODY(nskip) \
do { \
tmp = (nskip); \
if (parser->on_body && tmp > 0) { \
callback_return_value = parser->on_body(parser, p, tmp); \
} \
if (callback_return_value == 0) { \
p += tmp; \
parser->body_read += tmp; \
parser->chunk_size -= tmp; \
if (0 == parser->chunk_size) { \
parser->eating = FALSE; \
if (parser->transfer_encoding == HTTP_IDENTITY) { \
END_REQUEST; \
} \
} else { \
parser->eating = TRUE; \
} \
} \
} while (0)
#line 413 "http_parser.rl"
#line 116 "http_parser.c"
static const int http_parser_start = 1;
static const int http_parser_first_final = 267;
static const int http_parser_error = 0;
static const int http_parser_en_ChunkedBody = 2;
static const int http_parser_en_ChunkedBody_chunk_chunk_end = 12;
static const int http_parser_en_Requests = 269;
static const int http_parser_en_Responses = 270;
static const int http_parser_en_main = 1;
#line 416 "http_parser.rl"
void
http_parser_init (http_parser *parser, enum http_parser_type type)
{
int cs = 0;
#line 134 "http_parser.c"
{
cs = http_parser_start;
}
#line 422 "http_parser.rl"
parser->cs = cs;
parser->type = type;
parser->error = 0;
parser->on_message_begin = NULL;
parser->on_path = NULL;
parser->on_query_string = NULL;
parser->on_uri = NULL;
parser->on_header_field = NULL;
parser->on_header_value = NULL;
parser->on_headers_complete = NULL;
parser->on_body = NULL;
parser->on_message_complete = NULL;
RESET_PARSER(parser);
}
/** exec **/
size_t
http_parser_execute (http_parser *parser, const char *buffer, size_t len)
{
size_t tmp; // REMOVE ME this is extremely hacky
int callback_return_value = 0;
const char *p, *pe;
int cs = parser->cs;
p = buffer;
pe = buffer+len;
if (0 < parser->chunk_size && parser->eating) {
/* eat body */
SKIP_BODY(MIN(len, parser->chunk_size));
if (callback_return_value != 0) {
parser->error = TRUE;
return 0;
}
}
if (parser->header_field_mark) parser->header_field_mark = buffer;
if (parser->header_value_mark) parser->header_value_mark = buffer;
if (parser->fragment_mark) parser->fragment_mark = buffer;
if (parser->query_string_mark) parser->query_string_mark = buffer;
if (parser->path_mark) parser->path_mark = buffer;
if (parser->uri_mark) parser->uri_m
没有合适的资源?快使用搜索试试~ 我知道了~
node-0.0.5.tar.gz
0 下载量 201 浏览量
2024-05-18
23:33:14
上传
评论
收藏 2.79MB GZ 举报
温馨提示
共1075个文件
js:431个
py:198个
cc:170个
Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。
资源推荐
资源详情
资源评论
收起资源包目录
node-0.0.5.tar.gz (1075个子文件)
ev.3 182KB
eio.3 154KB
configure.ac 331B
configure.ac 271B
Makefile.am 402B
Makefile.am 273B
AUTHORS 590B
windows-tick-processor.bat 236B
http_parser.c 120KB
ev.c 68KB
dtoa.c 68KB
eio.c 36KB
oi_socket.c 23KB
test.c 21KB
event.c 9KB
ev_select.c 8KB
ev_epoll.c 7KB
ev_kqueue.c 6KB
ev_win32.c 5KB
ev_port.c 5KB
demo.c 5KB
ev_poll.c 4KB
dtoa-config.c 3KB
ping_pong.c 3KB
connection_interruption.c 3KB
common.c 2KB
echo.c 2KB
codegen-ia32.cc 260KB
objects.cc 247KB
runtime.cc 242KB
test-api.cc 218KB
codegen-arm.cc 186KB
test-debug.cc 174KB
jsregexp.cc 153KB
unicode.cc 150KB
parser.cc 145KB
api.cc 108KB
heap.cc 107KB
spaces.cc 82KB
debug.cc 80KB
mark-compact.cc 63KB
bootstrapper.cc 60KB
platform-win32.cc 55KB
assembler-ia32.cc 50KB
simulator-arm.cc 50KB
test-regexp.cc 49KB
serialize.cc 47KB
regexp-macro-assembler-ia32.cc 46KB
assembler-arm.cc 45KB
ic.cc 42KB
stub-cache-ia32.cc 42KB
stub-cache-arm.cc 38KB
assembler-x64.cc 37KB
virtual-frame-ia32.cc 37KB
macro-assembler-ia32.cc 35KB
stub-cache.cc 35KB
macro-assembler-arm.cc 34KB
disasm-ia32.cc 34KB
log.cc 34KB
ic-ia32.cc 32KB
scopes.cc 32KB
factory.cc 31KB
top.cc 30KB
objects-debug.cc 29KB
prettyprinter.cc 27KB
ic-arm.cc 26KB
builtins-ia32.cc 26KB
handles.cc 26KB
disasm-arm.cc 24KB
scanner.cc 24KB
builtins.cc 24KB
test-heap.cc 24KB
codegen-x64.cc 23KB
frames.cc 23KB
d8.cc 22KB
builtins-arm.cc 22KB
macro-assembler-x64.cc 22KB
conversions.cc 22KB
codegen.cc 22KB
d8-posix.cc 21KB
test-log.cc 21KB
rewriter.cc 21KB
process.cc 20KB
execution.cc 20KB
interpreter-irregexp.cc 20KB
assembler.cc 19KB
net.cc 19KB
platform-linux.cc 19KB
scopeinfo.cc 17KB
accessors.cc 17KB
test-decls.cc 17KB
string-stream.cc 17KB
platform-freebsd.cc 16KB
test-strings.cc 16KB
flags.cc 16KB
compiler.cc 15KB
jump-target.cc 15KB
platform-macos.cc 15KB
ast.cc 15KB
log-utils.cc 14KB
共 1075 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11
资源评论
程序员Chino的日记
- 粉丝: 3029
- 资源: 4万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功