Permalink
Browse files

initial import

  • Loading branch information...
mnaamani committed Aug 11, 2012
0 parents commit 9354b2d49343ec2ea8798383a5b72c949ec17537
@@ -0,0 +1,7 @@
+Copyright (C) 2012 Mokhtar Naamani (mokhtar.naamani@gmail.com)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,23 @@
+NODE_PREFIX = /usr/local
+CXX = g++
+CFLAGS =
+NODE_CFLAGS := -g -O2 -fPIC -DPIC -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -DEV_MULTIPLICITY=0 -I$(NODE_PREFIX)/include/node
+CCLD = $(CXX)
+LDFLAGS =
+NODE_LDFLAGS =
+LIBS = -lotr
+
+module:
+ node-waf configure build
+ mkdir -p node_modules
+ rm -rf node_modules/otr
+ mkdir -p node_modules/otr/lib
+ cp package.json node_modules/otr
+ cp otr.js node_modules/otr/lib
+ cp build/Release/otrnat.node node_modules/otr/lib
+
+install:
+ cp -r node_modules/otr ~/.node_libraries/
+clean:
+ node-waf distclean
+ rm -fR node_modules/
7 README
@@ -0,0 +1,7 @@
+use apt-get to install the below dependancies:
+
+nodejs
+nodejs-dev
+libotr2
+libotr2-dev
+
@@ -0,0 +1,127 @@
+#include "otr.hpp"
+#include "cvv8/convert.hpp"
+
+extern "C"{
+ #include <libotr/privkey.h>
+}
+
+using namespace v8;
+
+namespace otr {
+v8::Persistent<v8::FunctionTemplate> ConnectionCtx::constructor;
+
+ConnectionCtx::ConnectionCtx(ConnContext* context) : ObjectWrap(),
+ context_(context) {};
+
+ConnectionCtx::~ConnectionCtx() {};
+
+void ConnectionCtx::Init(Handle<Object> target) {
+ HandleScope scope;
+
+ // Prepare constructor template
+ Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
+ Local<String> name = String::NewSymbol("ConnContext");
+
+ constructor = Persistent<FunctionTemplate>::New(tpl);
+ // ObjectWrap uses the first internal field to store the wrapped pointer.
+ constructor->InstanceTemplate()->SetInternalFieldCount(1);
+ constructor->SetClassName(name);
+
+ // Prototype
+ NODE_SET_PROTOTYPE_ACCESSOR(constructor, "protocol", ctxGetter,ctxSetter);
+ NODE_SET_PROTOTYPE_ACCESSOR(constructor, "username", ctxGetter,ctxSetter);
+ NODE_SET_PROTOTYPE_ACCESSOR(constructor, "accountname", ctxGetter,ctxSetter);
+ NODE_SET_PROTOTYPE_ACCESSOR(constructor, "msgstate", ctxGetter,ctxSetter);
+ NODE_SET_PROTOTYPE_ACCESSOR(constructor, "fingerprint", ctxGetter,ctxSetter);
+ NODE_SET_PROTOTYPE_ACCESSOR(constructor, "protocol_version", ctxGetter,ctxSetter);
+ NODE_SET_PROTOTYPE_ACCESSOR(constructor, "smstate", ctxGetter,ctxSetter);
+ NODE_SET_PROTOTYPE_ACCESSOR(constructor, "trust", ctxGetter,ctxSetter);
+
+ target->Set(name, constructor->GetFunction());
+}
+
+Handle<Value> ConnectionCtx::New(const Arguments& args) {
+ HandleScope scope;
+ ConnContext *context=NULL;
+ if(args.Length()==0){
+
+ }else{
+ if(!args[0]->IsObject()){
+ return scope.Close(V8EXCEPTION("Invalid arguments. First argument 'userstate' (UserState) excpected."));
+ }
+ if(!args.Length() > 1 || !args[1]->IsString()){
+ return scope.Close(V8EXCEPTION("Invalid arguments. Second argument 'accountname' (string) excpected."));
+ }
+ if(!args.Length() > 2 || !args[2]->IsString()){
+ return scope.Close(V8EXCEPTION("Invalid arguments. Third argument 'protocol' (string) excpected."));
+ }
+ if(!args.Length() > 3 || !args[3]->IsString()){
+ return scope.Close(V8EXCEPTION("Invalid arguments. Fourth argument 'recipient' (string) excpected."));
+ }
+
+ int addedp;
+ UserState* us = node::ObjectWrap::Unwrap<UserState>(args[0]->ToObject());
+ String::Utf8Value accountname(args[1]->ToString());
+ String::Utf8Value protocol(args[2]->ToString());
+ String::Utf8Value user(args[3]->ToString());
+ context = otrl_context_find(us->userstate_, *user,*accountname, *protocol, 1, &addedp, NULL,NULL);
+ }
+ ConnectionCtx* obj = new ConnectionCtx(context);
+ obj->Wrap(args.This());
+
+ return scope.Close(args.This());
+}
+v8::Handle<v8::Value> ConnectionCtx::WrapConnectionCtx(ConnContext *context){
+ v8::Local<v8::Object> o = constructor->InstanceTemplate()->NewInstance();
+ ConnectionCtx *obj = node::ObjectWrap::Unwrap<ConnectionCtx>(o);
+ obj->context_ = context;
+ return o;
+}
+
+void ConnectionCtx::ctxSetter(Local<String> property, Local<Value> value, const AccessorInfo& info) {
+}
+
+Handle<Value> ConnectionCtx::ctxGetter(Local<String> property, const AccessorInfo& info) {
+ HandleScope scope;
+ ConnectionCtx* obj = node::ObjectWrap::Unwrap<ConnectionCtx>(info.This());
+ ConnContext *ctx = obj->context_;
+
+ if(!ctx) return scope.Close(Undefined());
+
+ std::string prop = cvv8::CastFromJS<std::string>(property);
+
+ IfStrEqual(prop,"protocol"){
+ return scope.Close(String::New(ctx->protocol));
+ }
+ IfStrEqual(prop,"username"){
+ return scope.Close(String::New(ctx->username));
+ }
+ IfStrEqual(prop,"accountname"){
+ return scope.Close(String::New(ctx->accountname));
+ }
+ IfStrEqual(prop,"msgstate"){
+ return scope.Close(Int32::New((unsigned int)ctx->msgstate));
+ }
+ IfStrEqual(prop,"protocol_version"){
+ return scope.Close(Int32::New((unsigned int)ctx->protocol_version));
+ }
+ IfStrEqual(prop,"smstate"){
+ return scope.Close(Int32::New((unsigned int)ctx->smstate->sm_prog_state));
+ }
+ IfStrEqual(prop,"fingerprint"){
+ if(ctx->active_fingerprint==NULL) return scope.Close(Undefined());
+ char human[45];
+ otrl_privkey_hash_to_human(human, ctx->active_fingerprint->fingerprint);
+ return scope.Close(String::New(human));
+ }
+ IfStrEqual(prop,"trust"){
+ if(ctx->active_fingerprint==NULL) return scope.Close(Undefined());
+ if(ctx->active_fingerprint->trust == NULL) return scope.Close(Undefined());
+ return scope.Close(String::New(ctx->active_fingerprint->trust));
+ }
+
+ return scope.Close(Undefined());
+
+}
+
+}
@@ -0,0 +1,33 @@
+#ifndef __NODE_OTR_CONNCONTEXT_H__
+#define __NODE_OTR_CONNCONTEXT_H__
+
+#include "otr.hpp"
+
+extern "C" {
+ #include <libotr/context.h>
+}
+
+namespace otr {
+
+class ConnectionCtx : public node::ObjectWrap {
+ public:
+ static void Init(v8::Handle<v8::Object> target);
+ static v8::Persistent<v8::FunctionTemplate> constructor;
+
+ protected:
+ friend class MessageAppOps;
+ ConnContext* context_;
+
+ ConnectionCtx(ConnContext* context);
+ ~ConnectionCtx();
+
+ static v8::Handle<v8::Value> New(const v8::Arguments& args);
+ static v8::Handle<v8::Value> WrapConnectionCtx(ConnContext *context);
+ static v8::Handle<v8::Value> ctxGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info);
+ static void ctxSetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info);
+
+
+};
+
+}
+#endif
Oops, something went wrong.

0 comments on commit 9354b2d

Please sign in to comment.