socket 0.0.1 → 0.14.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/proto.js DELETED
@@ -1,191 +0,0 @@
1
- // (The MIT License)
2
- //
3
- // Copyright (c) 2012 Richard S Allinson <rsa@mountainmansoftware.com>
4
- //
5
- // Permission is hereby granted, free of charge, to any person obtaining
6
- // a copy of this software and associated documentation files (the
7
- // 'Software'), to deal in the Software without restriction, including
8
- // without limitation the rights to use, copy, modify, merge, publish,
9
- // distribute, sublicense, and/or sell copies of the Software, and to
10
- // permit persons to whom the Software is furnished to do so, subject to
11
- // the following conditions:
12
- //
13
- // The above copyright notice and this permission notice shall be
14
- // included in all copies or substantial portions of the Software.
15
- //
16
- // THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
- // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
- // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
- // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
- // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
-
24
- 'use strict';
25
-
26
- var net = require('net');
27
- var utils = require('./utils');
28
-
29
- // prototype
30
-
31
- var app = module.exports = {};
32
-
33
- // environment
34
-
35
- var env = process.env.NODE_ENV || 'development';
36
-
37
- /**
38
- * use
39
- */
40
-
41
- app.use = function (key, fn) {
42
-
43
- if ('string' !== typeof key) {
44
- fn = key;
45
- key = '';
46
- }
47
-
48
- // wrap sub-apps
49
- if ('function' === typeof fn.handle) {
50
- var server = fn;
51
- fn.key = key;
52
- fn = function (req, res, next) {
53
- server.handle(req, res, next);
54
- };
55
- }
56
-
57
- this.stack.push({
58
- key: key,
59
- handle: fn
60
- });
61
-
62
- return this;
63
- };
64
-
65
- /**
66
- * handle
67
- */
68
-
69
- app.handle = function (req, res, out) {
70
- var stack = this.stack, index = 0;
71
-
72
- function next(err) {
73
- var layer,
74
- arity;
75
-
76
- // next callback
77
- layer = stack[index];
78
-
79
- index = index + 1;
80
-
81
- // all done
82
- if (!layer) {
83
- // delegate to parent
84
- if (out) {
85
- out(err);
86
- return;
87
- }
88
-
89
- // unhandled error
90
- if (err) {
91
- res.end(err.toString());
92
- } else {
93
- res.end();
94
- }
95
- return;
96
- }
97
-
98
- try {
99
- // If we have a key and the req is JSON can we match to some middleware?
100
- // 'some.key.path' === use middleware
101
- if (layer.key !== '' && typeof req === 'object' && utils.keyExists(layer.key, req) === false) {
102
- next(err);
103
- return;
104
- }
105
-
106
- arity = layer.handle.length;
107
- if (err) {
108
- if (arity === 4) {
109
- layer.handle(err, req, res, next);
110
- } else {
111
- next(err);
112
- }
113
- } else if (arity < 4) {
114
- layer.handle(req, res, next);
115
- } else {
116
- next();
117
- }
118
- } catch (e) {
119
- next(e);
120
- }
121
- }
122
- next();
123
- };
124
-
125
- /**
126
- * listen
127
- */
128
-
129
- app.listen = function (port, ip) {
130
- var that = this,
131
- server;
132
-
133
- server = net.createServer(function (socket) {
134
- var req = {data: ''},
135
- res = {data: ''},
136
- handle;
137
-
138
- handle = function (data) {
139
- if (typeof data === 'undefined') {
140
- data = '';
141
- }
142
- req.data += data;
143
- if (data.slice(-that.TERM.length) === that.TERM) {
144
- try {
145
- req.data = req.data.slice(0, req.data.length - that.TERM.length);
146
- } catch (e) {
147
- socket.end('bad request' + that.TERM, that.ENCODING);
148
- return;
149
- }
150
- that.handle(req, res);
151
- }
152
- };
153
-
154
- res.end = function (data, encoding) {
155
- socket.end(data, encoding || that.ENCODING);
156
- };
157
-
158
- socket.setEncoding('utf8');
159
- socket.on('data', handle);
160
-
161
- if (!that.TERM) {
162
- socket.on('connect', handle);
163
- }
164
-
165
- });
166
- server.listen(port, ip);
167
- return this;
168
- };
169
-
170
- /**
171
- * dispatch
172
- */
173
-
174
- app.dispatch = function dispatch(req, port, ip, callback) {
175
- var term = this.TERM || '\r\n',
176
- buffer = '',
177
- client;
178
-
179
- client = net.connect(port, ip, function () {
180
- client.write(req + term);
181
- });
182
- client.on('data', function (data) {
183
- buffer += data;
184
- });
185
- client.on('end', function () {
186
- if (buffer.slice(-term.length) === term) {
187
- buffer = buffer.slice(0, buffer.length - term.length);
188
- }
189
- callback(buffer);
190
- });
191
- };
package/lib/utils.js DELETED
@@ -1,75 +0,0 @@
1
- // (The MIT License)
2
- //
3
- // Copyright (c) 2012 Richard S Allinson <rsa@mountainmansoftware.com>
4
- //
5
- // Permission is hereby granted, free of charge, to any person obtaining
6
- // a copy of this software and associated documentation files (the
7
- // 'Software'), to deal in the Software without restriction, including
8
- // without limitation the rights to use, copy, modify, merge, publish,
9
- // distribute, sublicense, and/or sell copies of the Software, and to
10
- // permit persons to whom the Software is furnished to do so, subject to
11
- // the following conditions:
12
- //
13
- // The above copyright notice and this permission notice shall be
14
- // included in all copies or substantial portions of the Software.
15
- //
16
- // THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
- // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
- // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
- // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
- // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
-
24
- 'use strict';
25
-
26
- /**
27
- * Merge object b with object a.
28
- *
29
- * var a = { foo: 'bar' }
30
- * , b = { bar: 'baz' };
31
- *
32
- * utils.merge(a, b);
33
- * // => { foo: 'bar', bar: 'baz' }
34
- *
35
- * @param {Object} a
36
- * @param {Object} b
37
- * @return {Object}
38
- * @api private
39
- */
40
-
41
- exports.merge = function (a, b) {
42
-
43
- var key;
44
-
45
- if (a && b) {
46
- for (key in b) {
47
- if (b.hasOwnProperty(key)) {
48
- a[key] = b[key];
49
- }
50
- }
51
- }
52
-
53
- return a;
54
- };
55
-
56
- /**
57
- *
58
- */
59
-
60
- exports.keyExists = function (key, obj) {
61
-
62
- if ('string' === typeof key) {
63
- key = key.split('.');
64
- }
65
-
66
- if (key.length === 0) {
67
- return true;
68
- }
69
-
70
- if (obj[key[0]]) {
71
- return this.keyExists(key.slice(1), obj);
72
- }
73
-
74
- return false;
75
- };
@@ -1 +0,0 @@
1
- url=http://localhost/socket/
@@ -1,6 +0,0 @@
1
- include.path=${php.global.include.path}
2
- source.encoding=UTF-8
3
- src.dir=.
4
- tags.asp=false
5
- tags.short=true
6
- web.root=.
@@ -1,9 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project xmlns="http://www.netbeans.org/ns/project/1">
3
- <type>org.netbeans.modules.php.project</type>
4
- <configuration>
5
- <data xmlns="http://www.netbeans.org/ns/php-project/1">
6
- <name>socket</name>
7
- </data>
8
- </configuration>
9
- </project>
package/scripts/lint DELETED
@@ -1,3 +0,0 @@
1
- echo Running JSLint
2
- find ./lib -name "*.js" -print0 | xargs -0 jslint
3
- find ./examples -name "*.js" -print0 | xargs -0 jslint