Skip to content
Browse files

Add Tables implementation

  • Loading branch information...
1 parent 04b3b87 commit 6232fb474e0fd90f1c8769da4b085821d0f0e0a5 @aredridel committed Oct 11, 2011
Showing with 94 additions and 5 deletions.
  1. +23 −3 ApacheRequest.cc
  2. +17 −0 ApacheRequest.h
  3. +33 −0 ApacheTable.cc
  4. +19 −0 ApacheTable.h
  5. +1 −1 Makefile
  6. +1 −1 wscript
View
26 ApacheRequest.cc
@@ -1,4 +1,5 @@
#include "ApacheRequest.h"
+#include "ApacheTable.h"
using namespace v8;
@@ -11,7 +12,10 @@ namespace mod_node {
if(req_function_template.IsEmpty()) {
req_function_template = Persistent<FunctionTemplate>(FunctionTemplate::New());
req_function_template->SetClassName(String::NewSymbol("ApacheRequest"));
- req_function_template->InstanceTemplate()->SetInternalFieldCount(1);
+ Handle <ObjectTemplate> itemplate = req_function_template->InstanceTemplate();
+ itemplate->SetInternalFieldCount(1);
+ itemplate->SetAccessor(String::New("headers_in"), GetHeadersIn);
+ itemplate->SetAccessor(String::New("headers_out"), GetHeadersOut);
NODE_SET_PROTOTYPE_METHOD(req_function_template, "write", Write);
NODE_SET_PROTOTYPE_METHOD(req_function_template, "end", End);
}
@@ -20,6 +24,16 @@ namespace mod_node {
target->Set(String::New("ApacheRequest"), req_function);
}
+ Handle<Value> ApacheRequest::GetHeadersIn(Local<String> property, const AccessorInfo& info) {
+ ApacheRequest *req = ObjectWrap::Unwrap<ApacheRequest>(info.Holder());
+ return req->HeadersIn;
+ }
+
+ Handle<Value> ApacheRequest::GetHeadersOut(Local<String> property, const AccessorInfo& info) {
+ ApacheRequest *req = ObjectWrap::Unwrap<ApacheRequest>(info.Holder());
+ return req->HeadersOut;
+ }
+
Handle<Object> ApacheRequest::New(request_ext *rex) {
Handle<Object> req = req_function->NewInstance();
ApacheRequest *s = new ApacheRequest(rex);
@@ -54,8 +68,14 @@ namespace mod_node {
return Undefined();
}
- ApacheRequest::ApacheRequest(request_ext *rex): rex(rex)
- {
+ ApacheRequest::ApacheRequest(request_ext *rex): rex(rex) {
+ HeadersIn = Persistent<Value>::New(ApacheTable::New(rex->req->headers_in));
+ HeadersOut = Persistent<Value>::New(ApacheTable::New(rex->req->headers_out));
+ }
+
+ ApacheRequest::~ApacheRequest() {
+ HeadersIn.Dispose();
+ HeadersOut.Dispose();
}
void ApacheRequest::rputs(char *str) {
View
17 ApacheRequest.h
@@ -30,10 +30,27 @@ namespace mod_node {
*/
static v8::Handle<v8::Value> End(const v8::Arguments &args);
+ /** Get the headers table object for this request
+ *
+ * @returns the headers table object
+ */
+ static v8::Handle<v8::Value> GetHeadersOut(v8::Local<v8::String> property, const v8::AccessorInfo& info);
+ static v8::Handle<v8::Value> GetHeadersIn(v8::Local<v8::String> property, const v8::AccessorInfo& info);
+
ApacheRequest(request_ext *rex);
+ ~ApacheRequest();
+
void rputs(char *str);
void end();
+ v8::Persistent<v8::Value> HeadersIn;
+ v8::Persistent<v8::Value> HeadersOut;
+
+ /** Copy constructor is not supported */
+ ApacheRequest(const ApacheRequest&);
+
+ /** assignment operator is not supported */
+ ApacheRequest& operator=(const ApacheRequest&);
};
};
View
33 ApacheTable.cc
@@ -0,0 +1,33 @@
+#include "ApacheTable.h"
+
+using namespace v8;
+
+
+namespace mod_node {
+ static Persistent<FunctionTemplate> table_function_template;
+ static Persistent<Function> table_function;
+
+ void ApacheTable::Initialize(Handle<Object> target) {
+ HandleScope scope;
+ if(table_function_template.IsEmpty()) {
+ table_function_template = Persistent<FunctionTemplate>(FunctionTemplate::New());
+ table_function_template->SetClassName(String::NewSymbol("ApacheTable"));
+ Handle <ObjectTemplate> itemplate = table_function_template->InstanceTemplate();
+ itemplate->SetInternalFieldCount(1);
+ }
+
+ table_function = Persistent<Function>::New(table_function_template->GetFunction());
+ target->Set(String::New("ApacheTable"), table_function);
+ };
+
+ Handle<Object> ApacheTable::New(apr_table_t *tab) {
+ Handle<Object> table = table_function->NewInstance();
+ ApacheTable *s = new ApacheTable(tab);
+ s->Wrap(table);
+ return table;
+ }
+
+ ApacheTable::ApacheTable(apr_table_t *table) : table(table) {
+ }
+
+};
View
19 ApacheTable.h
@@ -0,0 +1,19 @@
+#ifndef __ApacheTable_h__
+#define __ApacheTable_h__
+
+#include "mod_node.h"
+
+namespace mod_node {
+
+ class ApacheTable : public node::ObjectWrap {
+ public:
+ apr_table_t *table;
+
+ static void Initialize(v8::Handle<v8::Object> target);
+ static v8::Handle<v8::Object> New(apr_table_t *tab);
+
+ ApacheTable(apr_table_t *table);
+ };
+};
+
+#endif
View
2 Makefile
@@ -2,7 +2,7 @@ WAF=node-waf
all: mod_node
-mod_node: mod_node.cc mod_node.h ApacheProcess.cc ApacheProcess.h ApacheRequest.cc ApacheRequest.h ApacheServer.cc ApacheServer.h build/c4che/build.config.py
+mod_node: mod_node.cc mod_node.h ApacheProcess.cc ApacheProcess.h ApacheRequest.cc ApacheRequest.h ApacheServer.cc ApacheServer.h ApacheTable.cc ApacheTable.h build/c4che/build.config.py
${WAF} build
build/c4che/build.config.py:
View
2 wscript
@@ -38,7 +38,7 @@ def build(bld):
linkflags = ['-Wl,-undefined', '-Wl,dynamic_lookup'] if bld.env.USE_UNDEFINED_DYNAMIC else [],
cxxflags = ['-Wall'])
bld.new_task_gen(
- source = 'mod_node.cc ApacheProcess.cc ApacheRequest.cc ApacheServer.cc',
+ source = 'mod_node.cc ApacheProcess.cc ApacheRequest.cc ApacheServer.cc ApacheTable.cc',
target = 'mod_node',
features = ['cxx', 'cshlib'],
uselib = ['HTTPD', 'APU', 'APR', 'NODE'],

0 comments on commit 6232fb4

Please sign in to comment.
Something went wrong with that request. Please try again.