|
@ -1,14 +1,17 @@ |
|
|
#include <v8.h> |
|
|
|
|
|
|
|
|
|
|
|
extern "C" { |
|
|
extern "C" { |
|
|
#include <oi.h> |
|
|
#include <oi.h> |
|
|
#include <ebb_request_parser.h> |
|
|
#include <ebb_request_parser.h> |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#include "http_request.h" |
|
|
|
|
|
#include "js_http_request_processor.h" |
|
|
|
|
|
|
|
|
#include <assert.h> |
|
|
#include <assert.h> |
|
|
#include <string> |
|
|
#include <string> |
|
|
#include <map> |
|
|
#include <map> |
|
|
|
|
|
|
|
|
|
|
|
#include <v8.h> |
|
|
|
|
|
|
|
|
using namespace v8; |
|
|
using namespace v8; |
|
|
using namespace std; |
|
|
using namespace std; |
|
|
|
|
|
|
|
@ -17,37 +20,7 @@ using namespace std; |
|
|
|
|
|
|
|
|
static oi_server server; |
|
|
static oi_server server; |
|
|
static struct ev_loop *loop; |
|
|
static struct ev_loop *loop; |
|
|
|
|
|
static JsHttpRequestProcessor *processor; |
|
|
class Connection { |
|
|
|
|
|
public: |
|
|
|
|
|
Connection(void); |
|
|
|
|
|
ebb_request_parser parser; |
|
|
|
|
|
oi_socket socket; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class Request { |
|
|
|
|
|
public: |
|
|
|
|
|
Request(Connection &); |
|
|
|
|
|
string path; |
|
|
|
|
|
Connection &connection_; |
|
|
|
|
|
ebb_request parser_info; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
Request::Request |
|
|
|
|
|
( Connection &connection |
|
|
|
|
|
) |
|
|
|
|
|
: connection_(connection) |
|
|
|
|
|
{ |
|
|
|
|
|
ebb_request_init(&parser_info); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Connection::Connection |
|
|
|
|
|
( void |
|
|
|
|
|
) |
|
|
|
|
|
{ |
|
|
|
|
|
oi_socket_init (&socket, 30.0); |
|
|
|
|
|
ebb_request_parser_init (&parser); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void on_path |
|
|
void on_path |
|
|
( ebb_request *req |
|
|
( ebb_request *req |
|
@ -55,17 +28,23 @@ void on_path |
|
|
, size_t len |
|
|
, size_t len |
|
|
) |
|
|
) |
|
|
{ |
|
|
{ |
|
|
Request *request = static_cast<Request*> (req->data); |
|
|
HttpRequest *request = static_cast<HttpRequest*> (req->data); |
|
|
request->path.append(buf, len); |
|
|
request->path.append(buf, len); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void on_request_complete |
|
|
void on_headers_complete |
|
|
( ebb_request *req |
|
|
( ebb_request *req |
|
|
) |
|
|
) |
|
|
{ |
|
|
{ |
|
|
Request *request = static_cast<Request*> (req->data); |
|
|
HttpRequest *request = static_cast<HttpRequest*> (req->data); |
|
|
|
|
|
|
|
|
|
|
|
processor->Process(request); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// dispatch to javascript
|
|
|
void on_request_complete |
|
|
|
|
|
( ebb_request *req |
|
|
|
|
|
) |
|
|
|
|
|
{ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ebb_request * on_request |
|
|
ebb_request * on_request |
|
@ -74,7 +53,7 @@ ebb_request * on_request |
|
|
{ |
|
|
{ |
|
|
Connection *connection = static_cast<Connection*> (data); |
|
|
Connection *connection = static_cast<Connection*> (data); |
|
|
|
|
|
|
|
|
Request *request = new Request(*connection); |
|
|
HttpRequest *request = new HttpRequest(*connection); |
|
|
|
|
|
|
|
|
request->parser_info.on_path = on_path; |
|
|
request->parser_info.on_path = on_path; |
|
|
request->parser_info.on_query_string = NULL; |
|
|
request->parser_info.on_query_string = NULL; |
|
@ -82,7 +61,7 @@ ebb_request * on_request |
|
|
request->parser_info.on_fragment = NULL; |
|
|
request->parser_info.on_fragment = NULL; |
|
|
request->parser_info.on_header_field = NULL; |
|
|
request->parser_info.on_header_field = NULL; |
|
|
request->parser_info.on_header_value = NULL; |
|
|
request->parser_info.on_header_value = NULL; |
|
|
request->parser_info.on_headers_complete = NULL; |
|
|
request->parser_info.on_headers_complete = on_headers_complete; |
|
|
request->parser_info.on_body = NULL; |
|
|
request->parser_info.on_body = NULL; |
|
|
request->parser_info.on_complete = on_request_complete; |
|
|
request->parser_info.on_complete = on_request_complete; |
|
|
request->parser_info.data = request; |
|
|
request->parser_info.data = request; |
|
@ -128,9 +107,6 @@ static oi_socket* new_connection |
|
|
) |
|
|
) |
|
|
{ |
|
|
{ |
|
|
Connection *connection = new Connection(); |
|
|
Connection *connection = new Connection(); |
|
|
|
|
|
|
|
|
/* initialize the components of Connection */ |
|
|
|
|
|
oi_socket_init(&connection->socket, 30.0); |
|
|
|
|
|
connection->socket.on_read = on_read; |
|
|
connection->socket.on_read = on_read; |
|
|
connection->socket.on_error = NULL; |
|
|
connection->socket.on_error = NULL; |
|
|
connection->socket.on_close = on_close; |
|
|
connection->socket.on_close = on_close; |
|
@ -138,10 +114,10 @@ static oi_socket* new_connection |
|
|
connection->socket.on_drain = on_drain; |
|
|
connection->socket.on_drain = on_drain; |
|
|
connection->socket.data = connection; |
|
|
connection->socket.data = connection; |
|
|
|
|
|
|
|
|
ebb_request_parser_init(&connection->parser); |
|
|
|
|
|
connection->parser.new_request = on_request; |
|
|
connection->parser.new_request = on_request; |
|
|
connection->parser.data = connection; |
|
|
connection->parser.data = connection; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return &connection->socket; |
|
|
return &connection->socket; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -208,14 +184,14 @@ int main |
|
|
fprintf(stderr, "Error reading '%s'.\n", file.c_str()); |
|
|
fprintf(stderr, "Error reading '%s'.\n", file.c_str()); |
|
|
return 1; |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
/*
|
|
|
|
|
|
HttpRequestProcessor processor(source); |
|
|
processor = new JsHttpRequestProcessor(source); |
|
|
map<string, string> output; |
|
|
map<string, string> output; |
|
|
if (!processor.Initialize(&options, &output)) { |
|
|
if (!processor->Initialize(&options, &output)) { |
|
|
fprintf(stderr, "Error initializing processor.\n"); |
|
|
fprintf(stderr, "Error initializing processor.\n"); |
|
|
return 1; |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////
|
|
|
/////////////////////////////////////
|
|
|
|
|
|
|
|
|