diff --git a/client/cookie.html b/client/cookie.html deleted file mode 100644 index 65cddd0..0000000 --- a/client/cookie.html +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - -cookie set - - diff --git a/server/app.js b/server/app.js index f2deba2..4bad472 100755 --- a/server/app.js +++ b/server/app.js @@ -7,51 +7,6 @@ var sys = require('sys'), o_.merge(global, require('./settings')); try { o_.merge(global, require('./settings.local')); } catch(e) {} -try { - var daemon = require('./libs/daemon/daemon'), - start = function() { - daemon.init({ - lock: PID_FILE, - stdin: '/dev/null', - stdout: LOG_FILE, - stderr: LOG_FILE, - umask: 0, - chroot: null, - chdir: '.' - }); - }, - stop = function() { - process.kill(parseInt(require('fs').readFileSync(PID_FILE))); - }; - - switch(process.argv[2]) { - case 'stop': - stop(); - process.exit(0); - break; - - case 'start': - if(process.argv[3]) - process.env.EXPRESS_ENV = process.argv[3]; - start(); - break; - - case 'restart': - stop(); - start(); - process.exit(0); - break; - - case 'help': - sys.puts('Usage: node app.js [start|stop|restart]'); - process.exit(0); - break; - } -} catch(e) { - sys.puts('Daemon library not found! Please compile ' + - './libs/daemon/daemon.node if you would like to use it.'); -} - var app = express(); //app.set('env', 'development'); app.use(require('method-override')()); @@ -125,3 +80,5 @@ app.use('/app/signoff', function(req, res) { res.signOff(); res.send(new packages.Success('goodbye')); }); + +console.log('Ajax IM server started...'); diff --git a/server/dev/app.js b/server/dev/app.js index ed4443c..5259093 100644 --- a/server/dev/app.js +++ b/server/dev/app.js @@ -5,18 +5,4 @@ module.exports = function(route, app) { res.render('chat', { }); }); - - app.get(route+'/cookie', function(req, res) { - var uid = function(n) { - var chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', nn=''; - for(var c=0; c < n; c++){ - nn += chars.substr(0|Math.random() * chars.length, 1); - } - return nn; - }; - res.setHeader('Set-Cookie', - cookie.serialize('sessionid', uid(40), {path: '/'}) - ); - res.send('cookie set'); - }); }; \ No newline at end of file diff --git a/server/libs/daemon/daemon.cc b/server/libs/daemon/daemon.cc deleted file mode 100644 index b9868ff..0000000 --- a/server/libs/daemon/daemon.cc +++ /dev/null @@ -1,301 +0,0 @@ -/* -* Daemon.node -*** A node.JS addon that allows creating Unix/Linux Daemons in pure Javascript. -*** Copyright 2010 (c) -* Under MIT License. See LICENSE file. -*/ - -#include -#include -#include -#include -#include -#include -#include - -#define PID_MAXLEN 10 - -using namespace v8; - -// Go through special routines to become a daemon. -// if successful, returns daemon's PID -Handle Start(const Arguments& args) { - pid_t pid; - - pid = fork(); - if(pid > 0) exit(0); - if(pid < 0) exit(1); - - // Can be changed after with process.umaks - umask(0); - - setsid(); - - // Can be changed with process.chdir - chdir("/"); - - return Integer::New(getpid()); -} - -// Close Standard IN/OUT/ERR Streams -Handle CloseIO(const Arguments& args) { - close(STDIN_FILENO); - close(STDOUT_FILENO); - close(STDERR_FILENO); -} - -// File-lock to make sure that only one instance of daemon is running.. also for storing PID -/* lock ( filename ) -*** filename: a path to a lock-file. -*** Note: if filename doesn't exist, it will be created when function is called. -*/ -Handle LockD(const Arguments& args) { - if(!args[0]->IsString()) - return Boolean::New(false); - - String::Utf8Value data(args[0]->ToString()); - char pid_str[PID_MAXLEN+1]; - - int lfp = open(*data, O_RDWR | O_CREAT, 0640); - if(lfp < 0) exit(1); - if(lockf(lfp, F_TLOCK, 0) < 0) exit(0); - - int len = snprintf(pid_str, PID_MAXLEN, "%d", getpid()); - write(lfp, pid_str, len); - - return Boolean::New(true); -} - -class StreamPtr : public node::ObjectWrap -{ -public: - explicit StreamPtr(FILE** fpp, const char *pmode); - ~StreamPtr(); - - static Handle Open(const Arguments& args); - static Handle Close(const Arguments& args); - static Handle Redirect(const Arguments& args); - - static void Initialize(Handle target); - static Handle New(const Arguments& args); - - FILE** stream; - const char *mode; -private: - static Persistent constructor_template; -}; - -Persistent StreamPtr::constructor_template; - -StreamPtr::StreamPtr(FILE** fpp, const char *pmode) - : stream(fpp) - , mode( pmode ) -{ -} - -StreamPtr::~StreamPtr() -{ - fclose(*stream); -} - -Handle StreamPtr::Open(const Arguments& args) -{ - HandleScope scope; - - StreamPtr *fp = ObjectWrap::Unwrap(args.This()); - char *new_file = *String::Utf8Value(args[0]->ToString()); - *fp->stream = fopen(new_file, fp->mode); - - // return if the creation of the new FILE* was successful; - return Boolean::New( *fp->stream != NULL ); -} - -Handle StreamPtr::Close(const Arguments& args) -{ - HandleScope handle_scope; - - StreamPtr *fp = ObjectWrap::Unwrap(args.This()); - assert( fp && "object had no InternalField" ); - int ret = fclose(*fp->stream); - - return Boolean::New(ret == 0); -} - -Handle StreamPtr::Redirect(const Arguments& args) -{ - HandleScope scope; - if (Close(args)->ToBoolean()->Value()) - { - return Open(args); - } else { - return Boolean::New(false); - } -} - -Persistent stdin_obj; -Persistent stdout_obj; -Persistent stderr_obj; - -void StreamPtr::Initialize(Handle target) -{ - HandleScope scope; - - Local file_pointer = FunctionTemplate::New(StreamPtr::New); - constructor_template = Persistent::New(file_pointer); - constructor_template->InstanceTemplate()->SetInternalFieldCount(1); - - NODE_SET_PROTOTYPE_METHOD(constructor_template, "open", StreamPtr::Open); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "close", StreamPtr::Close); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "sendTo", StreamPtr::Redirect); - - // Although we could expose the prototype directly, I see no reason to, as it's not - // very useful for anything other than the intended purpose. - //target->Set(String::NewSymbol("StreamPtr"), constructor_template->GetFunction()); - - stdin_obj = Persistent::New( constructor_template->GetFunction()->NewInstance() ); - Handle stdin_ptr = External::New( new StreamPtr( &stdin, "r" ) ); - stdin_obj->SetInternalField(0, stdin_ptr); - target->Set(String::NewSymbol("stdin"), stdin_obj); - - stdout_obj = Persistent::New( constructor_template->GetFunction()->NewInstance() ); - Handle stdout_ptr = External::New( new StreamPtr( &stdout, "w" ) ); - stdout_obj->SetInternalField(0, stdout_ptr); - target->Set(String::NewSymbol("stdout"), stdout_obj); - - stderr_obj = Persistent::New( constructor_template->GetFunction()->NewInstance() ); - Handle stderr_ptr = External::New( new StreamPtr( &stderr, "w" ) ); - stderr_obj->SetInternalField(0, stderr_ptr); - target->Set(String::NewSymbol("stderr"), stderr_obj); -} - -Handle StreamPtr::New(const Arguments& args) -{ - HandleScope scope; - return scope.Close(args.This()); -} - -/* The default object: - * { - * "fork": true, - * "lock": "daemon.pid" - * "stdout": null, - * "stderr": null, - * "stdin": null, - * "umask": 0, - * "chroot": null, - * "chdir": ".", - * } - */ - -#define SET_DEFAULT(obj, name, value) \ -do { \ -Local str_##name = String::New(#name); \ -if( !obj->Has( str_##name ) ) \ - obj->Set( str_##name, (value) ); \ -} while (0) - -static inline void setDefaults(Handle &arg) -{ - HandleScope scope; - - SET_DEFAULT( arg, fork, Boolean::New(true) ); - SET_DEFAULT( arg, lock, String::New("daemon.pid") ); - SET_DEFAULT( arg, stdin, Null() ); - SET_DEFAULT( arg, stdout, Null() ); - SET_DEFAULT( arg, stderr, Null() ); - SET_DEFAULT( arg, umask, Integer::New(0) ); - SET_DEFAULT( arg, chroot, Null() ); - SET_DEFAULT( arg, chdir, String::New(".") ); - //SET_DEFAULT( arg, close_fds, Boolean::New(false) ); - //SET_DEFAULT( arg, catch_signals, Boolean::New(false) ); -} - -#undef SET_DEFAULT - -Handle Init(const Arguments& args) -{ - HandleScope scope; - - Local arg = args[0]->ToObject(); - setDefaults( arg ); - - pid_t pid = 0; - if( arg->Get( String::New("fork") )->IsTrue() ) - { - pid = fork(); - if(pid > 0) exit(0); - if(pid < 0) exit(1); - } - - if( !arg->Get( String::New("lock") )->IsNull() ) - { - Local file = arg->Get( String::New( "lock" ) )->ToString(); - String::Utf8Value data(file); - char pid_str[PID_MAXLEN+1]; - - int lfp = open(*data, O_RDWR | O_CREAT, 0640); - if(lfp < 0) exit(1); - if(lockf(lfp, F_TLOCK, 0) < 0) exit(0); - - int len = snprintf(pid_str, PID_MAXLEN, "%d", getpid()); - write(lfp, pid_str, len); - } - - if( arg->Get( String::New("stdin") )->IsNull() ) - { - Local close = Function::Cast( *stdin_obj->Get( String::New("close") ) ); - close->Call( stdin_obj, 0, NULL ); - } else { - Local send_to = Function::Cast( *stdin_obj->Get( String::New("sendTo") ) ); - Local string_arg = arg->Get( String::New("stdin") ); - send_to->Call( stdin_obj, 1, &string_arg ); - } - - if( arg->Get( String::New("stdout") )->IsNull() ) - { - Local close = Function::Cast( *stdout_obj->Get( String::New("close") ) ); - close->Call( stdout_obj, 0, NULL ); - } else { - Local send_to = Function::Cast( *stdout_obj->Get( String::New("sendTo") ) ); - Local string_arg = arg->Get( String::New("stdout") ); - send_to->Call( stdout_obj, 1, &string_arg ); - } - - if( arg->Get( String::New("stderr") )->IsNull() ) - { - Local close = Function::Cast( *stderr_obj->Get( String::New("close") ) ); - close->Call( stderr_obj, 0, NULL ); - } else { - Local send_to = Function::Cast( *stderr_obj->Get( String::New("sendTo") ) ); - Local string_arg = arg->Get( String::New("stderr") ); - send_to->Call( stderr_obj, 1, &string_arg ); - } - - Local umask_arg = arg->Get( String::New("umask") )->ToInteger(); - umask( umask_arg->Value() ); - - if( !arg->Get( String::New("chroot") )->IsNull() ) - { - char* dir = *String::AsciiValue( arg->Get( String::New("chroot") ) ); - chroot( dir ); - } - - if( !arg->Get( String::New("chdir") )->IsNull() ) - { - char* dir = *String::AsciiValue( arg->Get( String::New("chdir") ) ); - chdir( dir ); - } - - return Integer::New(pid); -} - -extern "C" void init(Handle target) { - HandleScope scope; - - target->Set(String::New("start"), FunctionTemplate::New(Start)->GetFunction()); - target->Set(String::New("lock"), FunctionTemplate::New(LockD)->GetFunction()); - target->Set(String::New("closeIO"), FunctionTemplate::New(CloseIO)->GetFunction()); - target->Set(String::New("init"), FunctionTemplate::New(Init)->GetFunction()); - - StreamPtr::Initialize(target); -} diff --git a/server/libs/daemon/wscript b/server/libs/daemon/wscript deleted file mode 100644 index 0dc837c..0000000 --- a/server/libs/daemon/wscript +++ /dev/null @@ -1,15 +0,0 @@ -srcdir = "." -blddir = "build" -VERSION = "0.0.1" - -def set_options(opt): - opt.tool_options("compiler_cxx") - -def configure(conf): - conf.check_tool("compiler_cxx") - conf.check_tool("node_addon") - -def build(bld): - obj = bld.new_task_gen("cxx", "shlib", "node_addon") - obj.target = "daemon" - obj.source = "daemon.cc" \ No newline at end of file