Merge branch 'master' into github-master

This commit is contained in:
斟酌 鵬兄 2016-06-16 16:03:42 +08:00
commit 0a45c7f391
13 changed files with 10 additions and 176 deletions

3
.gitmodules vendored
View File

@ -1,3 +1,6 @@
[submodule "botanss"]
path = botanss
url = git@github.com:tgckpg/BotanSS.git
[submodule "ext/utils"]
path = ext/utils
url = git@github.com:tgckpg/botansx-utils.git

@ -1 +1 @@
Subproject commit dcdd941f3b4cdfebc54d452688aa59a68498efac
Subproject commit cd2cce7e985a00c685f9f0ad776af6a9f394d765

1
ext/utils Submodule

@ -0,0 +1 @@
Subproject commit 4a76826516dda30eee5f96f5057afaba6baa7e41

View File

@ -56,7 +56,7 @@ else
// Define AppNS
cl.rootNS( "notifyterm", "./notify-term" );
cl.rootNS( "notifysrv", "./notifysrv" );
cl.rootNS( "botansx", "./ext/" );
var App = cl.load( "notifyterm.app" );

View File

@ -4,7 +4,7 @@ var cl = global.botanLoader;
var Dragonfly = global.Dragonfly;
var HttpRequest = cl.load( "botanss.net.HttpRequest" );
var ustr = cl.load( "notifysrv.utils.string" );
var ustr = cl.load( "botansx.utils.string" );
class Notis
{

View File

@ -6,7 +6,8 @@ var Dragonfly = global.Dragonfly;
var EventEmitter = require( "events" ).EventEmitter;
var HttpRequest = cl.load( "botanss.net.HttpRequest" );
var Rand = cl.load( "notifysrv.utils.random" );
var Rand = cl.load( "botansx.utils.random" );
var Notis = cl.load( "notifyterm.Notis" );
var Model = cl.load( "notifyterm.schema" );

View File

@ -4,7 +4,7 @@ var cl = global.botanLoader;
var Dragonfly = global.Dragonfly;
var HttpRequest = cl.load( "botanss.net.HttpRequest" );
var Base = cl.load( "notifysrv.postframe" );
var Base = cl.load( "botanss.net.PostFrame" );
var WNSAuth = cl.load( "notifyterm.WNSAuth" );
var Model = cl.load( "notifyterm.schema" );

View File

@ -1,15 +0,0 @@
"use strict";
var cl = global.botanLoader;
var Dragonfly = global.Dragonfly;
var qstr = cl.load( "notifysrv.utils.querystr" );
class EventArgs
{
constructor()
{
this.Handled = false;
}
}
module.exports = EventArgs;

View File

@ -1,23 +0,0 @@
"use strict";
var cl = global.botanLoader;
var Dragonfly = global.Dragonfly;
var qstr = cl.load( "notifysrv.utils.querystr" );
var EventArgs = cl.load( "notifysrv.eventargs.eventargs" );
class PostRequestEventArgs extends EventArgs
{
constructor( QueryString )
{
super();
this.Raw = QueryString;
}
get Data()
{
return qstr.queryStr( this.Raw );
}
}
module.exports = PostRequestEventArgs;

View File

@ -1,91 +0,0 @@
"use strict";
var cl = global.botanLoader;
var Dragonfly = global.Dragonfly;
var PostRequestEventArgs = cl.load( "notifysrv.eventargs.postrequest" );
var EventEmitter = require( "events" ).EventEmitter;
class PostFrame extends EventEmitter
{
constructor( Http )
{
super();
this.HTTP = Http;
this.result = "Error: PostFrame is unhandled";
this.planted = false;
}
run()
{
var _self = this;
var requestStr = "";
if( this.HTTP.request.isPost )
{
var Req = this.HTTP.request.raw;
var ReceiveData = function( data )
{
requestStr += data + "";
if( 51200 < requestStr.length )
{
_self.result = "The size of request is too big ( 500KB < )";
Req.removeListener( "data", ReceiveData );
Req.removeListener( "end", ReceiveEnd );
_self.plantResult();
}
};
var ReceiveEnd = function()
{
var EventArgs = new PostRequestEventArgs( requestStr );
_self.emit( "PostRequest", this, EventArgs );
if( !EventArgs.Handled )
{
_self.result = "Error: Unhandled Request";
_self.plantResult();
}
};
Req.addListener( "data", ReceiveData );
Req.addListener( "end", ReceiveEnd );
return;
}
else
{
Dragonfly.Info(
"GET: " + encodeURI( this.HTTP.request.raw.url )
+ " - " + this.HTTP.request.raw.headers["user-agent"]
, Dragonfly.Visibility.VISIBLE
);
}
this.plantResult();
}
plantResult()
{
if( !this.planted )
{
this.planted = true;
if( this.HTTP )
{
if( !( this.result instanceof Buffer ) )
{
this.result = String( this.result );
}
this.HTTP.response.headers["Content-Type"] = "text/plain";
this.HTTP.response.headers["Content-Length"] = this.result.length;
this.HTTP.response.write( this.result );
this.HTTP.response.end();
}
}
}
}
module.exports = PostFrame;

View File

@ -1,14 +0,0 @@
module.exports = {
queryStr: function( qstr )
{
var qObj = {};
qstr.split( "&" ).forEach( function( val )
{
val = val.split( "=" );
qObj[ val[0] ] = val[1] ? decodeURIComponent( val[1].replace( /\+/g, " " ) ) : true;
} );
return qObj;
}
};

View File

@ -1,15 +0,0 @@
var lut = []; for ( var i=0; i<256; i++ ) { lut[i] = (i<16?'0':'')+(i).toString(16); }
module.exports = {
uuid: function()
{
var d0 = Math.random()*0xffffffff|0;
var d1 = Math.random()*0xffffffff|0;
var d2 = Math.random()*0xffffffff|0;
var d3 = Math.random()*0xffffffff|0;
return lut[d0&0xff]+lut[d0>>8&0xff]+lut[d0>>16&0xff]+lut[d0>>24&0xff]+'-'+
lut[d1&0xff]+lut[d1>>8&0xff]+'-'+lut[d1>>16&0x0f|0x40]+lut[d1>>24&0xff]+'-'+
lut[d2&0x3f|0x80]+lut[d2>>8&0xff]+'-'+lut[d2>>16&0xff]+lut[d2>>24&0xff]+
lut[d3&0xff]+lut[d3>>8&0xff]+lut[d3>>16&0xff]+lut[d3>>24&0xff];
}
};

View File

@ -1,13 +0,0 @@
module.exports = {
encodeHtml: function ( str, br )
{
str = ( str + "" ).replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&apos;")
;
if( br ) str = str.replace( /\n/g, "<br/>" );
return str;
}
}