pax_global_header00006660000000000000000000000064120122735340014511gustar00rootroot0000000000000052 comment=de9a2cf2eff3bc500f5bb9516aad6261568e2f28 node-stringprep-0.1.5/000077500000000000000000000000001201227353400146345ustar00rootroot00000000000000node-stringprep-0.1.5/.gitignore000066400000000000000000000000721201227353400166230ustar00rootroot00000000000000.lock-wscript .DS_Store node_modules build *~ *.log .idea node-stringprep-0.1.5/LICENSE000066400000000000000000000020411201227353400156360ustar00rootroot00000000000000Copyright (c) 2010 Stephan Maka 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. node-stringprep-0.1.5/README.markdown000066400000000000000000000016231201227353400173370ustar00rootroot00000000000000# node-stringprep # [Flattr this!](https://flattr.com/thing/44598/node-stringprep) ## Purpose ## Exposes predefined Unicode normalization functions that are required by many protocols. This is just a binding to [ICU](http://icu-project.org/), which is [said to be fast.](http://ayena.de/node/74) ## Installation ## # Debian apt-get install libicu-dev # Gentoo emerge icu # OSX using MacPorts port install icu +devel # OSX using Homebrew brew install icu4c ln -s /usr/local/Cellar/icu4c//bin/icu-config /usr/local/bin/icu-config npm install node-stringprep ## Usage ## var StringPrep = require('node-stringprep').StringPrep; var prep = new StringPrep('nameprep'); prep.prepare('Äffchen') // => 'äffchen' For a list of supported profiles, see [node-stringprep.cc](http://github.com/astro/node-stringprep/blob/master/node-stringprep.cc#L160) node-stringprep-0.1.5/binding.gyp000066400000000000000000000007731201227353400167760ustar00rootroot00000000000000{ 'targets': [ { 'target_name': 'node-stringprep', 'sources': [ 'node-stringprep.cc' ], 'cflags!': [ '-fno-exceptions', '`icu-config --cppflags`' ], 'cflags_cc!': [ '-fno-exceptions' ], 'libraries': [ '`icu-config --ldflags`' ], 'conditions': [ ['OS=="mac"', { 'include_dirs': [ '/opt/local/include' ], 'xcode_settings': { 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES' } }] ] } ] }node-stringprep-0.1.5/install.sh000077500000000000000000000003741201227353400166450ustar00rootroot00000000000000#!/bin/sh which icu-config > /dev/null 2> /dev/null if [ $? -ne 0 ] then echo 'Cannot find `icu-config` in $PATH,' echo 'please install it from http://site.icu-project.org/' exit 1 fi node-waf configure || exit 1 node-waf build || exit 1 node-stringprep-0.1.5/leakcheck.js000066400000000000000000000004371201227353400171100ustar00rootroot00000000000000var SP = require('./build/default/node-stringprep'); function run() { var p = new SP.StringPrep('nameprep'); var r = p.prepare('A\u0308ffin'); if (r !== 'äffin') throw r; process.nextTick(run); } try { run(); } catch (e) { console.log(JSON.stringify(e)); } node-stringprep-0.1.5/node-stringprep.cc000066400000000000000000000144611201227353400202710ustar00rootroot00000000000000#include #include #include #include #include #include #include using namespace v8; using namespace node; /*** Utility ***/ static Handle throwTypeError(const char *msg) { return ThrowException(Exception::TypeError(String::New(msg))); } /* supports return of just enum */ class UnknownProfileException : public std::exception { }; class StringPrep : public ObjectWrap { public: static void Initialize(Handle target) { HandleScope scope; Local t = FunctionTemplate::New(New); t->InstanceTemplate()->SetInternalFieldCount(1); NODE_SET_PROTOTYPE_METHOD(t, "prepare", Prepare); target->Set(String::NewSymbol("StringPrep"), t->GetFunction()); } bool good() const { return U_SUCCESS(error); } const char *errorName() const { return u_errorName(error); } Handle makeException() const { return Exception::Error(String::New(errorName())); } protected: /*** Constructor ***/ static Handle New(const Arguments& args) { HandleScope scope; if (args.Length() >= 1 && args[0]->IsString()) { String::Utf8Value arg0(args[0]->ToString()); UStringPrepProfileType profileType; try { profileType = parseProfileType(arg0); } catch (UnknownProfileException &) { return throwTypeError("Unknown StringPrep profile"); } StringPrep *self = new StringPrep(profileType); if (self->good()) { self->Wrap(args.This()); return args.This(); } else { Handle exception = self->makeException(); delete self; return ThrowException(exception); } } else return throwTypeError("Bad argument."); } StringPrep(const UStringPrepProfileType profileType) : error(U_ZERO_ERROR) { profile = usprep_openByType(profileType, &error); } /*** Destructor ***/ ~StringPrep() { if (profile) usprep_close(profile); } /*** Prepare ***/ static Handle Prepare(const Arguments& args) { HandleScope scope; if (args.Length() >= 1 && args[0]->IsString()) { StringPrep *self = ObjectWrap::Unwrap(args.This()); String::Value arg0(args[0]->ToString()); return scope.Close(self->prepare(arg0)); } else return throwTypeError("Bad argument."); } Handle prepare(String::Value &str) { size_t destLen = str.length() + 1; UChar *dest = NULL; while(!dest) { dest = new UChar[destLen]; size_t w = usprep_prepare(profile, *str, str.length(), dest, destLen, USPREP_DEFAULT, NULL, &error); if (error == U_BUFFER_OVERFLOW_ERROR) { // retry with a dest buffer twice as large destLen *= 2; delete[] dest; dest = NULL; } else if (!good()) { // other error, just bail out delete[] dest; return ThrowException(makeException()); } else destLen = w; } Local result = String::New(dest, destLen); delete[] dest; return result; } private: UStringPrepProfile *profile; UErrorCode error; static enum UStringPrepProfileType parseProfileType(String::Utf8Value &profile) throw(UnknownProfileException) { if (strcasecmp(*profile, "nameprep") == 0) return USPREP_RFC3491_NAMEPREP; if (strcasecmp(*profile, "nfs4_cs_prep") == 0) return USPREP_RFC3530_NFS4_CS_PREP; if (strcasecmp(*profile, "nfs4_cs_prep") == 0) return USPREP_RFC3530_NFS4_CS_PREP_CI; if (strcasecmp(*profile, "nfs4_cis_prep") == 0) return USPREP_RFC3530_NFS4_CIS_PREP; if (strcasecmp(*profile, "nfs4_mixed_prep prefix") == 0) return USPREP_RFC3530_NFS4_MIXED_PREP_PREFIX; if (strcasecmp(*profile, "nfs4_mixed_prep suffix") == 0) return USPREP_RFC3530_NFS4_MIXED_PREP_SUFFIX; if (strcasecmp(*profile, "iscsi") == 0) return USPREP_RFC3722_ISCSI; if (strcasecmp(*profile, "nodeprep") == 0) return USPREP_RFC3920_NODEPREP; if (strcasecmp(*profile, "resourceprep") == 0) return USPREP_RFC3920_RESOURCEPREP; if (strcasecmp(*profile, "mib") == 0) return USPREP_RFC4011_MIB; if (strcasecmp(*profile, "saslprep") == 0) return USPREP_RFC4013_SASLPREP; if (strcasecmp(*profile, "trace") == 0) return USPREP_RFC4505_TRACE; if (strcasecmp(*profile, "ldap") == 0) return USPREP_RFC4518_LDAP; if (strcasecmp(*profile, "ldapci") == 0) return USPREP_RFC4518_LDAP_CI; throw UnknownProfileException(); } }; /*** IDN support ***/ Handle ToUnicode(const Arguments& args) { HandleScope scope; if (args.Length() >= 1 && args[0]->IsString()) { String::Value str(args[0]->ToString()); // ASCII encoding (xn--*--*) should be longer than Unicode size_t destLen = str.length() + 1; UChar *dest = NULL; while(!dest) { dest = new UChar[destLen]; UErrorCode error = U_ZERO_ERROR; size_t w = uidna_toUnicode(*str, str.length(), dest, destLen, UIDNA_DEFAULT, NULL, &error); if (error == U_BUFFER_OVERFLOW_ERROR) { // retry with a dest buffer twice as large destLen *= 2; delete[] dest; dest = NULL; } else if (U_FAILURE(error)) { // other error, just bail out delete[] dest; Handle exception = Exception::Error(String::New(u_errorName(error))); return scope.Close(ThrowException(exception)); } else destLen = w; } Local result = String::New(dest, destLen); delete[] dest; return scope.Close(result); } else return throwTypeError("Bad argument."); } /*** Initialization ***/ extern "C" void init(Handle target) { HandleScope scope; StringPrep::Initialize(target); NODE_SET_METHOD(target, "toUnicode", ToUnicode); } node-stringprep-0.1.5/package.json000066400000000000000000000012051201227353400171200ustar00rootroot00000000000000{ "name": "node-stringprep", "version": "0.1.5", "main": "./build/Release/node-stringprep.node", "description": "ICU StringPrep profiles", "keywords": ["unicode", "stringprep", "icu"], "dependencies": {}, "devDependencies": {}, "repository": { "type": "git", "path": "git://github.com/astro/node-stringprep.git" }, "homepage": "http://github.com/astro/node-stringprep", "bugs": "http://github.com/astro/node-stringprep/issues", "author": { "name": "Astro", "email": "astro@spaceboyz.net", "web": "http://spaceboyz.net/~astro/" }, "licenses": [{ "type": "MIT" }], "engines": { "node": ">=0.4" } } node-stringprep-0.1.5/wscript000066400000000000000000000013271201227353400162550ustar00rootroot00000000000000import os def backtick(cmd): return os.popen(cmd).read().strip() srcdir = '.' blddir = 'build' VERSION = '0.0.2' def set_options(opt): opt.tool_options('compiler_cxx') def configure(conf): conf.check_tool('compiler_cxx') conf.check_tool('node_addon') if backtick('icu-config --version')[0] != '4': conf.fatal('Missing library icu 4.x.x') conf.env['CXXFLAGS_ICU'] = backtick('icu-config --cppflags').replace('-pedantic', '').split(' ') conf.env['LINKFLAGS_ICU'] = backtick('icu-config --ldflags').split(' ') conf.env.set_variant("default") def build(bld): obj = bld.new_task_gen('cxx', 'shlib', 'node_addon') obj.target = 'node-stringprep' obj.source = 'node-stringprep.cc' obj.uselib = 'ICU'