Browse Source

...

v0.7.4-release
Ryan 16 years ago
parent
commit
6ded7fec5f
  1. 41
      http_request.h
  2. 13
      js_http_request_processor.h
  3. 84
      server.cc

41
http_request.h

@ -0,0 +1,41 @@
#ifndef http_request_h
#define http_request_h
extern "C" {
#include <oi_socket.h>
#include <ebb_request_parser.h>
}
#include <string>
using namespace std;
class Connection {
public:
Connection ( void)
{
oi_socket_init (&socket, 30.0);
ebb_request_parser_init (&parser);
}
ebb_request_parser parser;
oi_socket socket;
};
class HttpRequest {
public:
HttpRequest (Connection &c) : connection_(c) { ebb_request_init(&parser_info); }
~HttpRequest() { }
const string& Path () { return path; }
const string& Referrer () { return referrer; }
const string& Host () { return host; }
const string& UserAgent () { return user_agent; }
string path;
string referrer;
string host;
string user_agent;
Connection &connection_;
ebb_request parser_info;
};
#endif // http_request_h

13
js_http_request_processor.h

@ -5,6 +5,8 @@
#include <string> #include <string>
#include <map> #include <map>
#include "http_request.h"
using namespace std; using namespace std;
using namespace v8; using namespace v8;
@ -13,17 +15,6 @@ using namespace v8;
// and then add scripting capabilities that allow you to interact with // and then add scripting capabilities that allow you to interact with
// the objects through JavaScript. // the objects through JavaScript.
/**
* A simplified http request.
*/
class HttpRequest {
public:
virtual ~HttpRequest() { }
virtual const string& Path() = 0;
virtual const string& Referrer() = 0;
virtual const string& Host() = 0;
virtual const string& UserAgent() = 0;
};
/** /**
* The abstract superclass of http request processors. * The abstract superclass of http request processors.

84
server.cc

@ -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);
// dispatch to javascript processor->Process(request);
}
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,19 +107,16 @@ static oi_socket* new_connection
) )
{ {
Connection *connection = new Connection(); Connection *connection = new Connection();
connection->socket.on_read = on_read;
connection->socket.on_error = NULL;
connection->socket.on_close = on_close;
connection->socket.on_timeout = NULL;
connection->socket.on_drain = on_drain;
connection->socket.data = connection;
/* initialize the components of Connection */ connection->parser.new_request = on_request;
oi_socket_init(&connection->socket, 30.0); connection->parser.data = connection;
connection->socket.on_read = on_read;
connection->socket.on_error = NULL;
connection->socket.on_close = on_close;
connection->socket.on_timeout = NULL;
connection->socket.on_drain = on_drain;
connection->socket.data = connection;
ebb_request_parser_init(&connection->parser);
connection->parser.new_request = on_request;
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;
} }
*/
///////////////////////////////////// /////////////////////////////////////

Loading…
Cancel
Save