From 3056c2ca76c37ff03b24deb10e8dd538c70600f2 Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Tue, 2 Aug 2011 22:17:16 -0400 Subject: [PATCH 01/16] Add documentation for SecurePair and its 'secure' event. Fixes #1443. --- doc/api/tls.markdown | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/doc/api/tls.markdown b/doc/api/tls.markdown index e4ded41a775..6cfb29b9236 100644 --- a/doc/api/tls.markdown +++ b/doc/api/tls.markdown @@ -61,8 +61,30 @@ piped to the socket, the plaintext stream is what the user interacts with therea [Here is some code that does it.](http://gist.github.com/848444) +### pair = tls.createSecurePair([credentials], [isServer], [requestCert], [rejectUnauthorized]) +Creates a new secure pair object with two streams, one of which reads/writes encrypted data, and one reads/writes cleartext data. +Generally the encrypted one is piped to/from an incoming encrypted data stream, and the cleartext one +is used as a replacement for the initial encrypted stream. + - `credentials`: A credentials object from crypto.createCredentials( ... ) + + - `isServer`: A boolean indicating whether this tls connection should be opened as a server or a client. + + - `requestCert`: A boolean indicating whether a server should request a certificate from + a connecting client. Only applies to server connections. + + - `rejectUnauthorized`: A boolean indicating whether a server should automatically + reject clients with invalid certificates. Only applies to servers with `requestCert` enabled. + +`tls.createSecurePair()` returns a SecurePair object with `cleartext` and `encrypted` stream properties. + +#### Event: 'secure' + +The event is emitted from the SecurePair once the pair has successfully established a secure connection. + +Similarly to the checking for the server 'secureConnection' event, pair.cleartext.authorized should be +checked to confirm whether the certificate used properly authorized. ### tls.Server From b267dc458d78c2fcbad2a9fa8e8942897d77c3d4 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sat, 6 Aug 2011 00:57:31 +0200 Subject: [PATCH 02/16] cmake: Various fixes. * Allow overriding install path with CMAKE_INSTALL_PREFIX. * make sure js2min.py can be found when building out of source. * Replace empty macros with void(0). Expressions like "debug(x) && foo()" fail if debug(x) is an empty macro. * Make sure node-natives.h creation is deterministic. * Fix version string. The copyright header made the node_version.h file larger than the previously set file read limit. --- cmake/configure.cmake | 5 ++++- cmake/node_build.cmake | 14 +++++++++----- cmake/package.cmake | 4 ++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/cmake/configure.cmake b/cmake/configure.cmake index c05575300b8..2ef391cb0d7 100644 --- a/cmake/configure.cmake +++ b/cmake/configure.cmake @@ -33,10 +33,13 @@ if(${node_arch} MATCHES unknown) set(node_arch x86) endif() +set(NODE_INCLUDE_PREFIX ${CMAKE_INSTALL_PREFIX}) + # Copy tools directory for out-of-source build string(COMPARE EQUAL $(PROJECT_BINARY_DIR) ${PROJECT_SOURCE_DIR} in_source_build) -if(NOT ${in_source_build}) +if(NOT in_source_build) execute_process(COMMAND cmake -E copy_directory ${PROJECT_SOURCE_DIR}/tools ${PROJECT_BINARY_DIR}/tools) + configure_file(${PROJECT_SOURCE_DIR}/deps/v8/tools/jsmin.py ${PROJECT_BINARY_DIR}/tools COPYONLY) endif() # Set some compiler/linker flags.. diff --git a/cmake/node_build.cmake b/cmake/node_build.cmake index 9d89432f00b..2ecc6e5546f 100644 --- a/cmake/node_build.cmake +++ b/cmake/node_build.cmake @@ -6,8 +6,8 @@ set(macros_file ${PROJECT_BINARY_DIR}/macros.py) # replace debug(x) and assert(x) with nothing in release build if(${CMAKE_BUILD_TYPE} MATCHES Release) - file(APPEND ${macros_file} "macro debug(x) = ;\n") - file(APPEND ${macros_file} "macro assert(x) = ;\n") + file(APPEND ${macros_file} "macro debug(x) = void(0);\n") + file(APPEND ${macros_file} "macro assert(x) = void(0);\n") endif() if(NOT DTRACE) @@ -21,16 +21,20 @@ if(NOT DTRACE) DTRACE_NET_SOCKET_READ DTRACE_NET_SOCKET_WRITE) foreach(probe ${dtrace_probes}) - file(APPEND ${macros_file} "macro ${probe}(x) = ;\n") + file(APPEND ${macros_file} "macro ${probe}(x) = void(0);\n") endforeach() endif() +# Sort the JS files being built into natives so that the build is +# deterministic +list(SORT js2c_files) + # include macros file in generation set(js2c_files ${js2c_files} ${macros_file}) add_custom_command( OUTPUT ${PROJECT_BINARY_DIR}/src/node_natives.h - COMMAND ${PYTHON_EXECUTABLE} tools/js2c.py ${PROJECT_BINARY_DIR}/src/node_natives.h ${js2c_files} + COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_BINARY_DIR}/tools/js2c.py ${PROJECT_BINARY_DIR}/src/node_natives.h ${js2c_files} DEPENDS ${js2c_files}) set(node_platform_src "src/platform_${node_platform}.cc") @@ -138,5 +142,5 @@ install(FILES src/node_version.h ${PROJECT_BINARY_DIR}/src/node_config.h - DESTINATION include/node + DESTINATION ${NODE_INCLUDE_PREFIX}/include/node ) diff --git a/cmake/package.cmake b/cmake/package.cmake index 720e2dd7557..2f2905a6bd3 100644 --- a/cmake/package.cmake +++ b/cmake/package.cmake @@ -2,6 +2,10 @@ # package # +# Allow absolute paths when installing +# see http://www.cmake.org/pipermail/cmake/2008-July/022958.html +set(CPACK_SET_DESTDIR "ON") + if(${node_platform} MATCHES darwin) set(CPACK_GENERATOR "TGZ;PackageMaker") # CPack requires the files to end in .txt From fc57df283c22f4be664ed72003870a3e813ae4c7 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 8 Aug 2011 00:59:08 +0200 Subject: [PATCH 03/16] docs: rename readline.md to readline.markdown --- doc/api/readline.markdown | 133 ++++++++++++++++++++++++++++++++++++++ doc/api/readline.md | 133 -------------------------------------- 2 files changed, 133 insertions(+), 133 deletions(-) delete mode 100644 doc/api/readline.md diff --git a/doc/api/readline.markdown b/doc/api/readline.markdown index e69de29bb2d..ea2a7f2e4a3 100644 --- a/doc/api/readline.markdown +++ b/doc/api/readline.markdown @@ -0,0 +1,133 @@ +## Readline + +To use this module, do `require('readline')`. Readline allows reading of a +stream (such as STDIN) on a line-by-line basis. + +Note that once you've invoked this module, your node program will not +terminate until you've closed the interface, and the STDIN stream. Here's how +to allow your program to gracefully terminate: + + var rl = require('readline'); + + var i = rl.createInterface(process.sdtin, process.stdout, null); + i.question("What do you think of node.js?", function(answer) { + // TODO: Log the answer in a database + console.log("Thank you for your valuable feedback."); + + // These two lines together allow the program to terminate. Without + // them, it would run forever. + i.close(); + process.stdin.destroy(); + }); + +### rl.createInterface(input, output, completer) + +Takes two streams and creates a readline interface. The `completer` function +is used for autocompletion. When given a substring, it returns `[[substr1, +substr2, ...], originalsubstring]`. + +`createInterface` is commonly used with `process.stdin` and +`process.stdout` in order to accept user input: + + var readline = require('readline'), + rl = readline.createInterface(process.stdin, process.stdout); + +### rl.setPrompt(prompt, length) + +Sets the prompt, for example when you run `node` on the command line, you see +`> `, which is node's prompt. + +### rl.prompt() + +Readies readline for input from the user, putting the current `setPrompt` +options on a new line, giving the user a new spot to write. + + + +### rl.question(query, callback) + +Prepends the prompt with `query` and invokes `callback` with the user's +response. Displays the query to the user, and then invokes `callback` with the +user's response after it has been typed. + +Example usage: + + interface.question('What is your favorite food?', function(answer) { + console.log('Oh, so your favorite food is ' + answer); + }); + +### rl.close() + + Closes tty. + +### rl.pause() + + Pauses tty. + +### rl.resume() + + Resumes tty. + +### rl.write() + + Writes to tty. + +### Event: 'line' + +`function (line) {}` + +Emitted whenever the `in` stream receives a `\n`, usually received when the +user hits enter, or return. This is a good hook to listen for user input. + +Example of listening for `line`: + + rl.on('line', function (cmd) { + console.log('You just typed: '+cmd); + }); + +### Event: 'close' + +`function () {}` + +Emitted whenever the `in` stream receives a `^C` or `^D`, respectively known +as `SIGINT` and `EOT`. This is a good way to know the user is finished using +your program. + +Example of listening for `close`, and exiting the program afterward: + + rl.on('close', function() { + console.log('goodbye!'); + process.exit(0); + }); + +Here's an example of how to use all these together to craft a tiny command +line interface: + + var readline = require('readline'), + rl = readline.createInterface(process.stdin, process.stdout), + prefix = 'OHAI> '; + + rl.on('line', function(line) { + switch(line.trim()) { + case 'hello': + console.log('world!'); + break; + default: + console.log('Say what? I might have heard `' + line.trim() + '`'); + break; + } + rl.setPrompt(prefix, prefix.length); + rl.prompt(); + }).on('close', function() { + console.log('Have a great day!'); + process.exit(0); + }); + console.log(prefix + 'Good to see you. Try typing stuff.'); + rl.setPrompt(prefix, prefix.length); + rl.prompt(); + + +Take a look at this slightly more complicated +[example](https://gist.github.com/901104), and +[http-console](http://github.com/cloudhead/http-console) for a real-life use +case. \ No newline at end of file diff --git a/doc/api/readline.md b/doc/api/readline.md deleted file mode 100644 index ea2a7f2e4a3..00000000000 --- a/doc/api/readline.md +++ /dev/null @@ -1,133 +0,0 @@ -## Readline - -To use this module, do `require('readline')`. Readline allows reading of a -stream (such as STDIN) on a line-by-line basis. - -Note that once you've invoked this module, your node program will not -terminate until you've closed the interface, and the STDIN stream. Here's how -to allow your program to gracefully terminate: - - var rl = require('readline'); - - var i = rl.createInterface(process.sdtin, process.stdout, null); - i.question("What do you think of node.js?", function(answer) { - // TODO: Log the answer in a database - console.log("Thank you for your valuable feedback."); - - // These two lines together allow the program to terminate. Without - // them, it would run forever. - i.close(); - process.stdin.destroy(); - }); - -### rl.createInterface(input, output, completer) - -Takes two streams and creates a readline interface. The `completer` function -is used for autocompletion. When given a substring, it returns `[[substr1, -substr2, ...], originalsubstring]`. - -`createInterface` is commonly used with `process.stdin` and -`process.stdout` in order to accept user input: - - var readline = require('readline'), - rl = readline.createInterface(process.stdin, process.stdout); - -### rl.setPrompt(prompt, length) - -Sets the prompt, for example when you run `node` on the command line, you see -`> `, which is node's prompt. - -### rl.prompt() - -Readies readline for input from the user, putting the current `setPrompt` -options on a new line, giving the user a new spot to write. - - - -### rl.question(query, callback) - -Prepends the prompt with `query` and invokes `callback` with the user's -response. Displays the query to the user, and then invokes `callback` with the -user's response after it has been typed. - -Example usage: - - interface.question('What is your favorite food?', function(answer) { - console.log('Oh, so your favorite food is ' + answer); - }); - -### rl.close() - - Closes tty. - -### rl.pause() - - Pauses tty. - -### rl.resume() - - Resumes tty. - -### rl.write() - - Writes to tty. - -### Event: 'line' - -`function (line) {}` - -Emitted whenever the `in` stream receives a `\n`, usually received when the -user hits enter, or return. This is a good hook to listen for user input. - -Example of listening for `line`: - - rl.on('line', function (cmd) { - console.log('You just typed: '+cmd); - }); - -### Event: 'close' - -`function () {}` - -Emitted whenever the `in` stream receives a `^C` or `^D`, respectively known -as `SIGINT` and `EOT`. This is a good way to know the user is finished using -your program. - -Example of listening for `close`, and exiting the program afterward: - - rl.on('close', function() { - console.log('goodbye!'); - process.exit(0); - }); - -Here's an example of how to use all these together to craft a tiny command -line interface: - - var readline = require('readline'), - rl = readline.createInterface(process.stdin, process.stdout), - prefix = 'OHAI> '; - - rl.on('line', function(line) { - switch(line.trim()) { - case 'hello': - console.log('world!'); - break; - default: - console.log('Say what? I might have heard `' + line.trim() + '`'); - break; - } - rl.setPrompt(prefix, prefix.length); - rl.prompt(); - }).on('close', function() { - console.log('Have a great day!'); - process.exit(0); - }); - console.log(prefix + 'Good to see you. Try typing stuff.'); - rl.setPrompt(prefix, prefix.length); - rl.prompt(); - - -Take a look at this slightly more complicated -[example](https://gist.github.com/901104), and -[http-console](http://github.com/cloudhead/http-console) for a real-life use -case. \ No newline at end of file From 25118b0a26020d7d37ac91f92e575bae0ec947d5 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 5 Aug 2011 13:52:27 -0700 Subject: [PATCH 04/16] net: fix incorrect sizeof() --- src/node_net.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node_net.cc b/src/node_net.cc index a0bda02035c..5f2d0a18902 100644 --- a/src/node_net.cc +++ b/src/node_net.cc @@ -520,7 +520,7 @@ do { \ } else if (addrlen == sizeof(struct sockaddr_un)) { \ /* first byte is '\0' and all remaining bytes are name; * it is not NUL-terminated and may contain embedded NULs */ \ - (info)->Set(address_symbol, String::New(au->sun_path + 1, sizeof(au->sun_path - 1))); \ + (info)->Set(address_symbol, String::New(au->sun_path + 1, sizeof(au->sun_path) - 1)); \ } else { \ (info)->Set(address_symbol, String::New(au->sun_path)); \ } \ From 421b6e89aa58d1cdc3344d6fadb878f7b37eee1c Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 5 Aug 2011 15:22:54 -0700 Subject: [PATCH 05/16] crypto: fix incorrect ssl shutdown check --- src/node_crypto.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 5b1bd34eed6..0f148b4d350 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -993,7 +993,7 @@ Handle Connection::ReceivedShutdown(const Arguments& args) { if (ss->ssl_ == NULL) return False(); int r = SSL_get_shutdown(ss->ssl_); - if (r | SSL_RECEIVED_SHUTDOWN) return True(); + if (r & SSL_RECEIVED_SHUTDOWN) return True(); return False(); } From 0d8d04e585cfbc526ff2eb6606d5ad83068878a2 Mon Sep 17 00:00:00 2001 From: Christopher Wright Date: Thu, 11 Aug 2011 14:09:33 +1000 Subject: [PATCH 06/16] Correct code span Fixes #1489. --- doc/api/fs.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/fs.markdown b/doc/api/fs.markdown index 6cfb43c4316..7fd40a6d34e 100644 --- a/doc/api/fs.markdown +++ b/doc/api/fs.markdown @@ -396,7 +396,7 @@ stat object: These stat objects are instances of `fs.Stat`. If you want to be notified when the file was modified, not just accessed -you need to compare `curr.mtime` and `prev.mtime. +you need to compare `curr.mtime` and `prev.mtime`. ### fs.unwatchFile(filename) From d1a26284991843417ce00da48005a3f8a8ff5399 Mon Sep 17 00:00:00 2001 From: koichik Date: Thu, 11 Aug 2011 17:13:13 +0900 Subject: [PATCH 07/16] Doc improvements related to #1472. --- doc/api/tls.markdown | 99 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 78 insertions(+), 21 deletions(-) diff --git a/doc/api/tls.markdown b/doc/api/tls.markdown index 6cfb29b9236..0bf81db1210 100644 --- a/doc/api/tls.markdown +++ b/doc/api/tls.markdown @@ -42,13 +42,13 @@ defaults to `localhost`.) `options` should be an object which specifies omitted several well known "root" CAs will be used, like VeriSign. These are used to authorize connections. -`tls.connect()` returns a cleartext `CryptoStream` object. +`tls.connect()` returns a [CleartextStream](#tls.CleartextStream) object. After the TLS/SSL handshake the `callback` is called. The `callback` will be called no matter if the server's certificate was authorized or not. It is up -to the user to test `s.authorized` to see if the server certificate was -signed by one of the specified CAs. If `s.authorized === false` then the error -can be found in `s.authorizationError`. +to the user to test `s.authorized` to see if the server certificate was signed +by one of the specified CAs. If `s.authorized === false` then the error can be +found in `s.authorizationError`. ### STARTTLS @@ -56,35 +56,42 @@ can be found in `s.authorizationError`. In the v0.4 branch no function exists for starting a TLS session on an already existing TCP connection. This is possible it just requires a bit of work. The technique is to use `tls.createSecurePair()` which returns two -streams: an encrypted stream and a plaintext stream. The encrypted stream is then -piped to the socket, the plaintext stream is what the user interacts with thereafter. +streams: an encrypted stream and a cleartext stream. The encrypted stream is +then piped to the socket, the cleartext stream is what the user interacts with +thereafter. [Here is some code that does it.](http://gist.github.com/848444) ### pair = tls.createSecurePair([credentials], [isServer], [requestCert], [rejectUnauthorized]) -Creates a new secure pair object with two streams, one of which reads/writes encrypted data, and one reads/writes cleartext data. -Generally the encrypted one is piped to/from an incoming encrypted data stream, and the cleartext one -is used as a replacement for the initial encrypted stream. +Creates a new secure pair object with two streams, one of which reads/writes +encrypted data, and one reads/writes cleartext data. +Generally the encrypted one is piped to/from an incoming encrypted data stream, +and the cleartext one is used as a replacement for the initial encrypted stream. - `credentials`: A credentials object from crypto.createCredentials( ... ) - - `isServer`: A boolean indicating whether this tls connection should be opened as a server or a client. + - `isServer`: A boolean indicating whether this tls connection should be + opened as a server or a client. - - `requestCert`: A boolean indicating whether a server should request a certificate from - a connecting client. Only applies to server connections. + - `requestCert`: A boolean indicating whether a server should request a + certificate from a connecting client. Only applies to server connections. - - `rejectUnauthorized`: A boolean indicating whether a server should automatically - reject clients with invalid certificates. Only applies to servers with `requestCert` enabled. + - `rejectUnauthorized`: A boolean indicating whether a server should + automatically reject clients with invalid certificates. Only applies to + servers with `requestCert` enabled. -`tls.createSecurePair()` returns a SecurePair object with `cleartext` and `encrypted` stream properties. +`tls.createSecurePair()` returns a SecurePair object with +[cleartext](#tls.CleartextStream) and `encrypted` stream properties. #### Event: 'secure' -The event is emitted from the SecurePair once the pair has successfully established a secure connection. +The event is emitted from the SecurePair once the pair has successfully +established a secure connection. -Similarly to the checking for the server 'secureConnection' event, pair.cleartext.authorized should be -checked to confirm whether the certificate used properly authorized. +Similarly to the checking for the server 'secureConnection' event, +pair.cleartext.authorized should be checked to confirm whether the certificate +used properly authorized. ### tls.Server @@ -143,8 +150,9 @@ has these possibilities: `function (cleartextStream) {}` This event is emitted after a new connection has been successfully -handshaked. The argument is a duplex instance of `stream.Stream`. It has all -the common stream methods and events. +handshaked. The argument is a instance of +[CleartextStream](#tls.CleartextStream). It has all the common stream methods +and events. `cleartextStream.authorized` is a boolean value which indicates if the client has verified by one of the supplied certificate authorities for the @@ -175,8 +183,57 @@ event. #### server.maxConnections -Set this property to reject connections when the server's connection count gets high. +Set this property to reject connections when the server's connection count +gets high. #### server.connections The number of concurrent connections on the server. + + +### tls.CleartextStream + +This is a stream on top of the *Encrypted* stream that makes it possible to +read/write an encrypted data as a cleartext data. + +This instance implements a duplex [Stream](streams.html#streams) interfaces. +It has all the common stream methods and events. + +#### cleartextStream.authorized + +A boolean that is `true` if the peer certificate was signed by one of the +specified CAs, otherwise `false` + +#### cleartextStream.authorizationError + +The reason why the peer's certificate has not been verified. This property +becomes available only when `cleartextStream.authorized === false`. + +#### cleartextStream.getPeerCertificate() + +Returns an object representing the peer's certicicate. The returned object has +some properties corresponding to the field of the certificate. + +Example: + + { subject: + { C: 'UK', + ST: 'Acknack Ltd', + L: 'Rhys Jones', + O: 'node.js', + OU: 'Test TLS Certificate', + CN: 'localhost' }, + issuer: + { C: 'UK', + ST: 'Acknack Ltd', + L: 'Rhys Jones', + O: 'node.js', + OU: 'Test TLS Certificate', + CN: 'localhost' }, + valid_from: 'Nov 11 09:52:22 2009 GMT', + valid_to: 'Nov 6 09:52:22 2029 GMT', + fingerprint: '2A:7A:C2:DD:E5:F9:CC:53:72:35:99:7A:02:5A:71:38:52:EC:8A:DF' } + +If the peer does not provide a certificate, it returns `null` or an empty +object. + From 3210809d0acac59df9fbd887d4e45047b2a82507 Mon Sep 17 00:00:00 2001 From: isaacs Date: Thu, 11 Aug 2011 15:30:56 -0700 Subject: [PATCH 08/16] Fix #1497 querystring: Replace 'in' test with 'hasOwnProperty' --- lib/querystring.js | 2 +- test/simple/test-querystring.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/querystring.js b/lib/querystring.js index aa433982a6f..0effe5b1679 100644 --- a/lib/querystring.js +++ b/lib/querystring.js @@ -166,7 +166,7 @@ QueryString.parse = QueryString.decode = function(qs, sep, eq) { var k = QueryString.unescape(x[0], true); var v = QueryString.unescape(x.slice(1).join(eq), true); - if (!(k in obj)) { + if (!obj.hasOwnProperty(k)) { obj[k] = v; } else if (!Array.isArray(obj[k])) { obj[k] = [obj[k], v]; diff --git a/test/simple/test-querystring.js b/test/simple/test-querystring.js index 8e30dae1e5a..18d06422a1e 100644 --- a/test/simple/test-querystring.js +++ b/test/simple/test-querystring.js @@ -48,7 +48,12 @@ var qsTestCases = [ 'undef': ''}], [' foo = bar ', '%20foo%20=%20bar%20', {' foo ': ' bar '}], ['foo=%zx', 'foo=%25zx', {'foo': '%zx'}], - ['foo=%EF%BF%BD', 'foo=%EF%BF%BD', {'foo': '\ufffd' }] + ['foo=%EF%BF%BD', 'foo=%EF%BF%BD', {'foo': '\ufffd' }], + [ 'toString=foo&valueOf=bar&__defineGetter__=baz', + 'toString=foo&valueOf=bar&__defineGetter__=baz', + { toString: 'foo', + valueOf: 'bar', + __defineGetter__: 'baz' } ] ]; // [ wonkyQS, canonicalQS, obj ] From 7ba30a4c2ec5b81f20373f5919510189e15f6f8c Mon Sep 17 00:00:00 2001 From: Arnout Kazemier Date: Fri, 12 Aug 2011 14:05:46 +0300 Subject: [PATCH 09/16] Small changes for fs.watchFile. Fixed broken markdown. Changed variable `f` to a proper filename. Fixes #1507. --- doc/api/fs.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/fs.markdown b/doc/api/fs.markdown index 7fd40a6d34e..3fa9f1aeb70 100644 --- a/doc/api/fs.markdown +++ b/doc/api/fs.markdown @@ -388,7 +388,7 @@ value in milliseconds. The default is `{ persistent: true, interval: 0 }`. The `listener` gets two arguments the current stat object and the previous stat object: - fs.watchFile(f, function (curr, prev) { + fs.watchFile('message.text', function (curr, prev) { console.log('the current mtime is: ' + curr.mtime); console.log('the previous mtime was: ' + prev.mtime); }); From e00c2ec5e35ae631d01e96eb33f61c12dead3076 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 12 Aug 2011 15:32:43 +0200 Subject: [PATCH 10/16] build: remove 1024 char read limit from cmake file --- cmake/package.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/package.cmake b/cmake/package.cmake index 2f2905a6bd3..755b9df9f4f 100644 --- a/cmake/package.cmake +++ b/cmake/package.cmake @@ -28,7 +28,7 @@ set(CPACK_PACKAGE_DESCRIPTION "Evented I/O for V8 JavaScript. presents the event loop as a language construct instead of as a library.") set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION}") set(CPACK_DEBIAN_PACKAGE_SECTION "web") -file(READ ${PROJECT_SOURCE_DIR}/src/node_version.h node_version_h LIMIT 1024 OFFSET 0) +file(READ ${PROJECT_SOURCE_DIR}/src/node_version.h node_version_h OFFSET 0) string(REGEX REPLACE ".*NODE_MAJOR_VERSION[ ]*([0-9]+).*" "\\1" CPACK_PACKAGE_VERSION_MAJOR "${node_version_h}") string(REGEX REPLACE ".*NODE_MINOR_VERSION[ ]*([0-9]+).*" "\\1" CPACK_PACKAGE_VERSION_MINOR "${node_version_h}") string(REGEX REPLACE ".*NODE_PATCH_VERSION[ ]*([0-9]+).*" "\\1" CPACK_PACKAGE_VERSION_PATCH "${node_version_h}") From 4e204f37fd994b3bd11a829c9f6938b5a3ca9774 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 12 Aug 2011 15:42:45 +0200 Subject: [PATCH 11/16] net: defer DNS lookup error events to next tick net.createConnection() creates a net.Socket object and immediately calls net.Socket.connect() on it. There are no event listeners registered yet so defer the error event to the next tick. Fixes #1202. --- lib/net.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/net.js b/lib/net.js index 8d88c69bba8..35eb84d4988 100644 --- a/lib/net.js +++ b/lib/net.js @@ -717,7 +717,13 @@ Socket.prototype.connect = function() { // TCP require('dns').lookup(arguments[1], function(err, ip, addressType) { if (err) { - self.emit('error', err); + // net.createConnection() creates a net.Socket object and + // immediately calls net.Socket.connect() on it (that's us). + // There are no event listeners registered yet so defer the + // error event to the next tick. + process.nextTick(function() { + self.emit('error', err); + }); } else { timers.active(self); self.type = addressType == 4 ? 'tcp4' : 'tcp6'; From 028b33b18ae16c52cb5eda879d92c20bf5b99c13 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 8 Aug 2011 22:56:26 +0200 Subject: [PATCH 12/16] test: add test for #1202, uncatchable exception on bad host name --- test/simple/test-http-dns-error.js | 70 ++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 test/simple/test-http-dns-error.js diff --git a/test/simple/test-http-dns-error.js b/test/simple/test-http-dns-error.js new file mode 100644 index 00000000000..e3c8be76e5a --- /dev/null +++ b/test/simple/test-http-dns-error.js @@ -0,0 +1,70 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// 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. + +var common = require('../common'); +var assert = require('assert'); + +var http = require('http'); +var https = require('https'); + +var expected_bad_requests = 0; +var actual_bad_requests = 0; + +var host = '********'; +host += host; +host += host; +host += host; +host += host; +host += host; + +function do_not_call() { + throw new Error("This function should not have been called."); +} + +function test(mod) { + expected_bad_requests += 2; + + // Bad host name should not throw an uncatchable exception. + // Ensure that there is time to attach an error listener. + var req = mod.get({host:host, port:42}, do_not_call); + req.on('error', function(err) { + assert.equal(err.code, 'EBADNAME'); + actual_bad_requests++; + }); + // http.get() called req.end() for us + + var req = mod.request({method:'GET', host:host, port:42}, do_not_call); + req.on('error', function(err) { + assert.equal(err.code, 'EBADNAME'); + actual_bad_requests++; + }); + req.end(); +} + +// FIXME This doesn't work for https because the tls module won't emit errors +// until a secure channel has been established - and that is never going to +// happen because the host name is invalid. +//test(https); +test(http); + +process.on('exit', function() { + assert.equal(actual_bad_requests, expected_bad_requests); +}); \ No newline at end of file From 4d186f270fa4cea9835ec60b4417d7ca6f83422a Mon Sep 17 00:00:00 2001 From: koichik Date: Sun, 14 Aug 2011 23:10:36 +0900 Subject: [PATCH 13/16] Docs: Not memcpy, but memmove Fixes #1520. --- doc/api/buffers.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/buffers.markdown b/doc/api/buffers.markdown index b8e3e912f99..754e94452bd 100644 --- a/doc/api/buffers.markdown +++ b/doc/api/buffers.markdown @@ -126,7 +126,7 @@ buffer object. It does not change when the contents of the buffer are changed. ### buffer.copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) -Does a memcpy() between buffers. +Does copy between buffers. The source and target regions can be overlapped. Example: build two Buffers, then copy `buf1` from byte 16 through byte 19 into `buf2`, starting at the 8th byte in `buf2`. From e8d268fd5fad5ac1356862a20b84cdd58bcb205c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Delahaye?= Date: Mon, 15 Aug 2011 15:09:03 +0200 Subject: [PATCH 14/16] Fix docs for fs.*chown Fix bad parameters of fs.chown[Sync], fs.fchown[Sync] and fs.lchown[Sync] in documentation. Fixes #1533. --- doc/api/fs.markdown | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/api/fs.markdown b/doc/api/fs.markdown index 3fa9f1aeb70..6d011647df9 100644 --- a/doc/api/fs.markdown +++ b/doc/api/fs.markdown @@ -73,30 +73,30 @@ given to the completion callback. Synchronous ftruncate(2). -### fs.chown(path, mode, [callback]) +### fs.chown(path, uid, gid, [callback]) Asycnronous chown(2). No arguments other than a possible exception are given to the completion callback. -### fs.chownSync(path, mode) +### fs.chownSync(path, uid, gid) Synchronous chown(2). -### fs.fchown(path, mode, [callback]) +### fs.fchown(path, uid, gid, [callback]) Asycnronous fchown(2). No arguments other than a possible exception are given to the completion callback. -### fs.fchownSync(path, mode) +### fs.fchownSync(path, uid, gid) Synchronous fchown(2). -### fs.lchown(path, mode, [callback]) +### fs.lchown(path, uid, gid, [callback]) Asycnronous lchown(2). No arguments other than a possible exception are given to the completion callback. -### fs.lchownSync(path, mode) +### fs.lchownSync(path, uid, gid) Synchronous lchown(2). From 5e37e10e41c269b12ede9126126032e3a1c57973 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sun, 14 Aug 2011 01:25:39 +0200 Subject: [PATCH 15/16] module: fix pointer reference to out-of-scope variable Reported by Tom Hughes. --- src/node.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/node.cc b/src/node.cc index 527d11ca8e6..0ae59e81bef 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1574,6 +1574,7 @@ typedef void (*extInit)(Handle exports); // DLOpen is node.dlopen(). Used to load 'module.node' dynamically shared // objects. Handle DLOpen(const v8::Arguments& args) { + node_module_struct compat_mod; HandleScope scope; if (args.Length() < 2) return Undefined(); @@ -1616,10 +1617,13 @@ Handle DLOpen(const v8::Arguments& args) { // Get the init() function from the dynamically shared object. node_module_struct *mod = static_cast(dlsym(handle, symstr)); free(symstr); + symstr = NULL; + // Error out if not found. if (mod == NULL) { /* Start Compatibility hack: Remove once everyone is using NODE_MODULE macro */ - node_module_struct compat_mod; + memset(&compat_mod, 0, sizeof compat_mod); + mod = &compat_mod; mod->version = NODE_MODULE_VERSION; From 9cd510846eea5ebdd116fb45ef4d5be64acda022 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 17 Aug 2011 13:21:15 -0700 Subject: [PATCH 16/16] Fixes #1546. Remove expensive debug call. --- lib/http.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/http.js b/lib/http.js index d532eddf0cc..ed6c432548f 100644 --- a/lib/http.js +++ b/lib/http.js @@ -609,7 +609,6 @@ OutgoingMessage.prototype.write = function(chunk, encoding) { if (typeof(chunk) === 'string') { len = Buffer.byteLength(chunk, encoding); var chunk = len.toString(16) + CRLF + chunk + CRLF; - debug('string chunk = ' + util.inspect(chunk)); ret = this._send(chunk, encoding); } else { // buffer