From 7b7ceea4eca78cdbf63a01f3f7c8edcf36241026 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 20 Feb 2009 17:06:07 +0100 Subject: [PATCH] first compile --- Makefile | 9 ++- count-hosts.js | 44 ++++++++++++++ js_http_request_processor.cc | 111 +---------------------------------- 3 files changed, 51 insertions(+), 113 deletions(-) create mode 100644 count-hosts.js diff --git a/Makefile b/Makefile index 11d51d4ab8..700b9502d5 100644 --- a/Makefile +++ b/Makefile @@ -3,18 +3,21 @@ V8INC = $(HOME)/src/v8/include V8LIB = $(HOME)/src/v8/libv8.a CFLAGS = -g -I$(V8INC) -Ideps/oi -DHAVE_GNUTLS=0 -Ideps/ebb -LDFLAGS = -lev #-lefence +LDFLAGS = -lev -pthread #-lefence ifdef EVDIR CFLAGS += -I$(EVDIR)/include LDFLAGS += -L$(EVDIR)/lib endif -server: server.o oi_socket.o ebb_request_parser.o - g++ $(LDFLAGS) $(V8LIB) $^ -o server +server: js_http_request_processor.o server.o oi_socket.o ebb_request_parser.o + g++ -o server $^ $(LDFLAGS) $(V8LIB) server.o: server.cc g++ $(CFLAGS) -c $< + +js_http_request_processor.o: js_http_request_processor.cc + g++ $(CFLAGS) -c $< ebb_request_parser.o: ebb_request_parser.c deps/ebb/ebb_request_parser.h gcc $(CFLAGS) -c $< diff --git a/count-hosts.js b/count-hosts.js new file mode 100644 index 0000000000..e336476c67 --- /dev/null +++ b/count-hosts.js @@ -0,0 +1,44 @@ +// Copyright 2008 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +function Initialize() { } + + +function Process(request) { + print("hello "); + if (options.verbose) { + log("Processing " + request.host + request.path + + " from " + request.referrer + "@" + request.userAgent); + } + if (!output[request.host]) { + output[request.host] = 1; + } else { + output[request.host]++ + } +} + +Initialize(); diff --git a/js_http_request_processor.cc b/js_http_request_processor.cc index 5c76f4b5c5..dd3d832385 100644 --- a/js_http_request_processor.cc +++ b/js_http_request_processor.cc @@ -32,7 +32,7 @@ #include #include -#include +#include "js_http_request_processor.h" using namespace std; using namespace v8; @@ -459,115 +459,6 @@ void HttpRequestProcessor::Log printf("Logged: %s\n", event); } - -/** - * A simplified http request. - */ -class StringHttpRequest : public HttpRequest -{ -public: - StringHttpRequest - ( const string& path - , const string& referrer - , const string& host - , const string& user_agent - ); - virtual const string& Path () { return path_; } - virtual const string& Referrer () { return referrer_; } - virtual const string& Host () { return host_; } - virtual const string& UserAgent () { return user_agent_; } -private: - string path_; - string referrer_; - string host_; - string user_agent_; -}; - - -StringHttpRequest::StringHttpRequest - ( const string& path - , const string& referrer - , const string& host - , const string& user_agent - ) - : path_ (path) - , referrer_ (referrer) - , host_ (host) - , user_agent_ (user_agent) -{ -} - -void ParseOptions - ( int argc - , char* argv[] - , map& options - , string* file - ) -{ - for (int i = 1; i < argc; i++) { - string arg = argv[i]; - int index = arg.find('=', 0); - if (index == string::npos) { - *file = arg; - } else { - string key = arg.substr(0, index); - string value = arg.substr(index+1); - options[key] = value; - } - } -} - - -// Reads a file into a v8 string. -Handle ReadFile - ( const string& name - ) -{ - FILE* file = fopen(name.c_str(), "rb"); - if (file == NULL) return Handle(); - - fseek(file, 0, SEEK_END); - int size = ftell(file); - rewind(file); - - char* chars = new char[size + 1]; - chars[size] = '\0'; - for (int i = 0; i < size;) { - int read = fread(&chars[i], 1, size - i, file); - i += read; - } - fclose(file); - Handle result = String::New(chars, size); - delete[] chars; - return result; -} - - -const int kSampleSize = 6; -StringHttpRequest kSampleRequests[kSampleSize] = - { StringHttpRequest("/process.cc", "localhost", "google.com", "firefox") - , StringHttpRequest("/", "localhost", "google.net", "firefox") - , StringHttpRequest("/", "localhost", "google.org", "safari") - , StringHttpRequest("/", "localhost", "yahoo.com", "ie") - , StringHttpRequest("/", "localhost", "yahoo.com", "safari") - , StringHttpRequest("/", "localhost", "yahoo.com", "firefox") - }; - - -bool ProcessEntries - ( HttpRequestProcessor* processor - , int count - , StringHttpRequest* reqs - ) -{ - for (int i = 0; i < count; i++) { - if (!processor->Process(&reqs[i])) - return false; - } - return true; -} - - void PrintMap ( map* m )