Browse Source

src: lint c++ code

v0.11.5-release
Fedor Indutny 12 years ago
parent
commit
8e29ce9f13
  1. 41
      src/cares_wrap.cc
  2. 18
      src/fs_event_wrap.cc
  3. 16
      src/handle_wrap.h
  4. 115
      src/node.cc
  5. 4
      src/node.h
  6. 2
      src/node_buffer.cc
  7. 8
      src/node_buffer.h
  8. 332
      src/node_constants.cc
  9. 6
      src/node_constants.h
  10. 5
      src/node_counters.cc
  11. 8
      src/node_counters.h
  12. 271
      src/node_crypto.cc
  13. 25
      src/node_crypto.h
  14. 88
      src/node_crypto_bio.cc
  15. 7
      src/node_crypto_bio.h
  16. 25
      src/node_crypto_groups.h
  17. 2
      src/node_dtrace.cc
  18. 39
      src/node_dtrace.h
  19. 10
      src/node_extensions.cc
  20. 57
      src/node_extensions.h
  21. 20
      src/node_file.cc
  22. 7
      src/node_file.h
  23. 19
      src/node_http_parser.cc
  24. 8
      src/node_http_parser.h
  25. 42
      src/node_internals.h
  26. 12
      src/node_javascript.cc
  27. 5
      src/node_javascript.h
  28. 14
      src/node_object_wrap.h
  29. 28
      src/node_os.cc
  30. 11
      src/node_os.h
  31. 5
      src/node_script.cc
  32. 10
      src/node_script.h
  33. 8
      src/node_stat_watcher.cc
  34. 6
      src/node_stat_watcher.h
  35. 9
      src/node_version.h
  36. 5
      src/node_watchdog.cc
  37. 2
      src/node_watchdog.h
  38. 28
      src/node_win32_etw_provider-inl.h
  39. 2
      src/node_win32_etw_provider.cc
  40. 15
      src/node_win32_etw_provider.h
  41. 36
      src/node_win32_perfctr_provider.cc
  42. 9
      src/node_win32_perfctr_provider.h
  43. 8
      src/node_wrap.h
  44. 35
      src/node_zlib.cc
  45. 18
      src/pipe_wrap.cc
  46. 6
      src/pipe_wrap.h
  47. 8
      src/process_wrap.cc
  48. 6
      src/queue.h
  49. 10
      src/req_wrap.h
  50. 2
      src/signal_wrap.cc
  51. 7
      src/smalloc.h
  52. 12
      src/stream_wrap.cc
  53. 10
      src/stream_wrap.h
  54. 4
      src/string_bytes.cc
  55. 16
      src/tcp_wrap.cc
  56. 8
      src/tcp_wrap.h
  57. 2
      src/timer_wrap.cc
  58. 228
      src/tls_wrap.cc
  59. 4
      src/tty_wrap.cc
  60. 8
      src/tty_wrap.h
  61. 6
      src/udp_wrap.cc
  62. 31
      src/udp_wrap.h
  63. 28
      src/v8abbr.h

41
src/cares_wrap.cc

@ -42,7 +42,6 @@
namespace node {
namespace cares_wrap {
using v8::Array;
@ -230,7 +229,7 @@ static Local<Array> HostentToNames(struct hostent* host) {
class QueryWrap {
public:
QueryWrap(Local<Object> req_wrap_obj) {
explicit QueryWrap(Local<Object> req_wrap_obj) {
HandleScope scope(node_isolate);
persistent().Reset(node_isolate, req_wrap_obj);
}
@ -333,7 +332,7 @@ class QueryWrap {
class QueryAWrap: public QueryWrap {
public:
QueryAWrap(Local<Object> req_wrap_obj) : QueryWrap(req_wrap_obj) {
explicit QueryAWrap(Local<Object> req_wrap_obj) : QueryWrap(req_wrap_obj) {
}
int Send(const char* name) {
@ -363,7 +362,7 @@ class QueryAWrap: public QueryWrap {
class QueryAaaaWrap: public QueryWrap {
public:
QueryAaaaWrap(Local<Object> req_wrap_obj) : QueryWrap(req_wrap_obj) {
explicit QueryAaaaWrap(Local<Object> req_wrap_obj) : QueryWrap(req_wrap_obj) {
}
int Send(const char* name) {
@ -398,7 +397,8 @@ class QueryAaaaWrap: public QueryWrap {
class QueryCnameWrap: public QueryWrap {
public:
QueryCnameWrap(Local<Object> req_wrap_obj) : QueryWrap(req_wrap_obj) {
explicit QueryCnameWrap(Local<Object> req_wrap_obj)
: QueryWrap(req_wrap_obj) {
}
int Send(const char* name) {
@ -436,7 +436,7 @@ class QueryCnameWrap: public QueryWrap {
class QueryMxWrap: public QueryWrap {
public:
QueryMxWrap(Local<Object> req_wrap_obj) : QueryWrap(req_wrap_obj) {
explicit QueryMxWrap(Local<Object> req_wrap_obj) : QueryWrap(req_wrap_obj) {
}
int Send(const char* name) {
@ -478,7 +478,7 @@ class QueryMxWrap: public QueryWrap {
class QueryNsWrap: public QueryWrap {
public:
QueryNsWrap(Local<Object> req_wrap_obj) : QueryWrap(req_wrap_obj) {
explicit QueryNsWrap(Local<Object> req_wrap_obj) : QueryWrap(req_wrap_obj) {
}
int Send(const char* name) {
@ -506,7 +506,7 @@ class QueryNsWrap: public QueryWrap {
class QueryTxtWrap: public QueryWrap {
public:
QueryTxtWrap(Local<Object> req_wrap_obj) : QueryWrap(req_wrap_obj) {
explicit QueryTxtWrap(Local<Object> req_wrap_obj) : QueryWrap(req_wrap_obj) {
}
int Send(const char* name) {
@ -541,7 +541,7 @@ class QueryTxtWrap: public QueryWrap {
class QuerySrvWrap: public QueryWrap {
public:
QuerySrvWrap(Local<Object> req_wrap_obj) : QueryWrap(req_wrap_obj) {
explicit QuerySrvWrap(Local<Object> req_wrap_obj) : QueryWrap(req_wrap_obj) {
}
int Send(const char* name) {
@ -593,7 +593,8 @@ class QuerySrvWrap: public QueryWrap {
class QueryNaptrWrap: public QueryWrap {
public:
QueryNaptrWrap(Local<Object> req_wrap_obj) : QueryWrap(req_wrap_obj) {
explicit QueryNaptrWrap(Local<Object> req_wrap_obj)
: QueryWrap(req_wrap_obj) {
}
int Send(const char* name) {
@ -630,7 +631,6 @@ class QueryNaptrWrap: public QueryWrap {
for (ares_naptr_reply* naptr_current = naptr_start;
naptr_current;
naptr_current = naptr_current->next) {
Local<Object> naptr_record = Object::New();
naptr_record->Set(flags_symbol,
@ -658,7 +658,8 @@ class QueryNaptrWrap: public QueryWrap {
class GetHostByAddrWrap: public QueryWrap {
public:
GetHostByAddrWrap(Local<Object> req_wrap_obj) : QueryWrap(req_wrap_obj) {
explicit GetHostByAddrWrap(Local<Object> req_wrap_obj)
: QueryWrap(req_wrap_obj) {
}
int Send(const char* name) {
@ -695,7 +696,8 @@ class GetHostByAddrWrap: public QueryWrap {
class GetHostByNameWrap: public QueryWrap {
public:
GetHostByNameWrap(Local<Object> req_wrap_obj) : QueryWrap(req_wrap_obj) {
explicit GetHostByNameWrap(Local<Object> req_wrap_obj)
: QueryWrap(req_wrap_obj) {
}
int Send(const char* name, int family) {
@ -768,7 +770,8 @@ static void QueryWithFamily(const FunctionCallbackInfo<Value>& args) {
void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
HandleScope scope(node_isolate);
GetAddrInfoReqWrap* req_wrap = (GetAddrInfoReqWrap*) req->data;
GetAddrInfoReqWrap* req_wrap =
reinterpret_cast<GetAddrInfoReqWrap*>(req->data);
Local<Value> argv[] = {
Integer::New(status, node_isolate),
@ -802,7 +805,8 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
// Ignore random ai_family types.
if (address->ai_family == AF_INET) {
// Juggle pointers
addr = (char*) &((struct sockaddr_in*) address->ai_addr)->sin_addr;
addr = reinterpret_cast<char*>(&(reinterpret_cast<struct sockaddr_in*>(
address->ai_addr)->sin_addr));
int err = uv_inet_ntop(address->ai_family,
addr,
ip,
@ -828,7 +832,8 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
// Ignore random ai_family types.
if (address->ai_family == AF_INET6) {
// Juggle pointers
addr = (char*) &((struct sockaddr_in6*) address->ai_addr)->sin6_addr;
addr = reinterpret_cast<char*>(&(reinterpret_cast<struct sockaddr_in6*>(
address->ai_addr)->sin6_addr));
int err = uv_inet_ntop(address->ai_family,
addr,
ip,
@ -1075,9 +1080,7 @@ static void Initialize(Handle<Object> target) {
oncomplete_sym = String::New("oncomplete");
}
} // namespace cares_wrap
} // namespace cares_wrap
} // namespace node
NODE_MODULE(node_cares_wrap, node::cares_wrap::Initialize)

18
src/fs_event_wrap.cc

@ -41,14 +41,14 @@ static Cached<String> onchange_sym;
static Cached<String> rename_sym;
class FSEventWrap: public HandleWrap {
public:
public:
static void Initialize(Handle<Object> target);
static void New(const FunctionCallbackInfo<Value>& args);
static void Start(const FunctionCallbackInfo<Value>& args);
static void Close(const FunctionCallbackInfo<Value>& args);
private:
FSEventWrap(Handle<Object> object);
private:
explicit FSEventWrap(Handle<Object> object);
virtual ~FSEventWrap();
static void OnEvent(uv_fs_event_t* handle, const char* filename, int events,
@ -147,14 +147,11 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
// unreasonable, right? Still, we should revisit this before v1.0.
if (status) {
eventStr = String::Empty(node_isolate);
}
else if (events & UV_RENAME) {
} else if (events & UV_RENAME) {
eventStr = rename_sym;
}
else if (events & UV_CHANGE) {
} else if (events & UV_CHANGE) {
eventStr = change_sym;
}
else {
} else {
assert(0 && "bad fs events flag");
abort();
}
@ -190,7 +187,6 @@ void FSEventWrap::Close(const FunctionCallbackInfo<Value>& args) {
HandleWrap::Close(args);
}
} // namespace node
} // namespace node
NODE_MODULE(node_fs_event_wrap, node::FSEventWrap::Initialize)

16
src/handle_wrap.h

@ -19,8 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef HANDLE_WRAP_H_
#define HANDLE_WRAP_H_
#ifndef SRC_HANDLE_WRAP_H_
#define SRC_HANDLE_WRAP_H_
#include "queue.h"
@ -53,16 +53,16 @@ namespace node {
args.This()->GetAlignedPointerFromInternalField(0));
class HandleWrap {
public:
public:
static void Initialize(v8::Handle<v8::Object> target);
static void Close(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Ref(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Unref(const v8::FunctionCallbackInfo<v8::Value>& args);
inline uv_handle_t* GetHandle() { return handle__; };
inline uv_handle_t* GetHandle() { return handle__; }
protected:
HandleWrap(v8::Handle<v8::Object> object, uv_handle_t* handle);
protected:
explicit HandleWrap(v8::Handle<v8::Object> object, uv_handle_t* handle);
virtual ~HandleWrap();
inline v8::Local<v8::Object> object() {
@ -73,7 +73,7 @@ protected:
return object_;
}
private:
private:
friend void GetActiveHandles(const v8::FunctionCallbackInfo<v8::Value>&);
static void OnClose(uv_handle_t* handle);
v8::Persistent<v8::Object> object_;
@ -91,4 +91,4 @@ private:
} // namespace node
#endif // HANDLE_WRAP_H_
#endif // SRC_HANDLE_WRAP_H_

115
src/node.cc

@ -80,12 +80,12 @@ typedef int mode_t;
#endif
#include "node_script.h"
# ifdef __APPLE__
#ifdef __APPLE__
# include <crt_externs.h>
# define environ (*_NSGetEnviron())
# elif !defined(_MSC_VER)
#elif !defined(_MSC_VER)
extern char **environ;
# endif
#endif
namespace node {
@ -164,7 +164,7 @@ static char *eval_string = NULL;
static int option_end_index = 0;
static bool use_debug_agent = false;
static bool debug_wait_connect = false;
static int debug_port=5858;
static int debug_port = 5858;
static int max_stack_size = 0;
bool using_domains = false;
@ -208,7 +208,7 @@ Isolate* node_isolate = NULL;
class ArrayBufferAllocator : public ArrayBuffer::Allocator {
public:
public:
// Impose an upper limit to avoid out of memory errors that bring down
// the process.
static const size_t kMaxLength = 0x3fffffff;
@ -216,7 +216,7 @@ public:
virtual ~ArrayBufferAllocator() {}
virtual void* Allocate(size_t length);
virtual void Free(void* data);
private:
private:
ArrayBufferAllocator() {}
ArrayBufferAllocator(const ArrayBufferAllocator&);
void operator=(const ArrayBufferAllocator&);
@ -260,7 +260,6 @@ static void IdleImmediateDummy(uv_idle_t* handle, int status) {
static inline const char *errno_string(int errorno) {
#define ERRNO_CASE(e) case e: return #e;
switch (errorno) {
#ifdef EACCES
ERRNO_CASE(EACCES);
#endif
@ -585,7 +584,6 @@ static inline const char *errno_string(int errorno) {
const char *signo_string(int signo) {
#define SIGNO_CASE(e) case e: return #e;
switch (signo) {
#ifdef SIGHUP
SIGNO_CASE(SIGHUP);
#endif
@ -823,7 +821,7 @@ Local<Value> UVException(int errorno,
Local<Object> obj = e->ToObject();
// TODO errno should probably go
// TODO(piscisaureus) errno should probably go
obj->Set(errno_symbol, Integer::New(errorno, node_isolate));
obj->Set(code_symbol, estring);
if (path) obj->Set(errpath_symbol, path_str);
@ -921,7 +919,7 @@ MakeDomainCallback(const Handle<Object> object,
const Handle<Function> callback,
int argc,
Handle<Value> argv[]) {
// TODO Hook for long stack traces to be made here.
// TODO(trevnorris) Hook for long stack traces to be made here.
// lazy load domain specific symbols
if (enter_symbol.IsEmpty()) {
@ -1003,7 +1001,7 @@ MakeCallback(const Handle<Object> object,
const Handle<Function> callback,
int argc,
Handle<Value> argv[]) {
// TODO Hook for long stack traces to be made here.
// TODO(trevnorris) Hook for long stack traces to be made here.
Local<Object> process = PersistentToLocal(process_p);
if (using_domains)
@ -1204,8 +1202,6 @@ void DisplayExceptionLine(Handle<Message> message) {
int start = message->GetStartColumn();
int end = message->GetEndColumn();
// fprintf(stderr, "---\nsourceline:%s\noffset:%d\nstart:%d\nend:%d\n---\n", sourceline_string, start, end);
fprintf(stderr, "%s\n", sourceline_string);
// Print wavy underline (GetUnderline is deprecated).
for (int i = 0; i < start; i++) {
@ -1252,7 +1248,7 @@ static void ReportException(Handle<Value> er, Handle<Message> message) {
}
static void ReportException(TryCatch& try_catch) {
static void ReportException(const TryCatch& try_catch) {
ReportException(try_catch.Exception(), try_catch.Message());
}
@ -1371,13 +1367,11 @@ static void Umask(const FunctionCallbackInfo<Value>& args) {
if (args.Length() < 1 || args[0]->IsUndefined()) {
old = umask(0);
umask(static_cast<mode_t>(old));
} else if(!args[0]->IsInt32() && !args[0]->IsString()) {
} else if (!args[0]->IsInt32() && !args[0]->IsString()) {
return ThrowTypeError("argument must be an integer or octal string.");
} else {
int oct;
if(args[0]->IsInt32()) {
if (args[0]->IsInt32()) {
oct = args[0]->Uint32Value();
} else {
oct = 0;
@ -1664,7 +1658,7 @@ static void InitGroups(const FunctionCallbackInfo<Value>& args) {
}
}
#endif // __POSIX__ && !defined(__ANDROID__)
#endif // __POSIX__ && !defined(__ANDROID__)
void Exit(const FunctionCallbackInfo<Value>& args) {
@ -1773,8 +1767,8 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
return ThrowError("process.dlopen takes exactly 2 arguments.");
}
Local<Object> module = args[0]->ToObject(); // Cast
String::Utf8Value filename(args[1]); // Cast
Local<Object> module = args[0]->ToObject(); // Cast
String::Utf8Value filename(args[1]); // Cast
if (exports_symbol.IsEmpty()) {
exports_symbol = String::New("exports");
@ -1786,7 +1780,7 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
#ifdef _WIN32
// Windows needs to add the filename into the error message
errmsg = String::Concat(errmsg, args[1]->ToString());
#endif
#endif // _WIN32
ThrowException(Exception::Error(errmsg));
return;
}
@ -1800,7 +1794,7 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
if (pos != NULL) {
base = pos + 1;
}
#else // Windows
#else // Windows
for (;;) {
pos = strpbrk(base, "\\/:");
if (pos == NULL) {
@ -1808,7 +1802,7 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
}
base = pos + 1;
}
#endif
#endif // __POSIX__
/* Strip the .node extension. */
pos = strrchr(base, '.');
@ -1913,9 +1907,9 @@ void FatalException(Handle<Value> error, Handle<Message> message) {
}
void FatalException(TryCatch& try_catch) {
void FatalException(const TryCatch& try_catch) {
HandleScope scope(node_isolate);
// TODO do not call FatalException if try_catch is verbose
// TODO(bajtos) do not call FatalException if try_catch is verbose
// (requires V8 API to expose getter for try_catch.is_verbose_)
FatalException(try_catch.Exception(), try_catch.Message());
}
@ -1946,7 +1940,7 @@ static void Binding(const FunctionCallbackInfo<Value>& args) {
// Append a string to process.moduleLoadList
char buf[1024];
snprintf(buf, 1024, "Binding %s", *module_v);
snprintf(buf, sizeof(buf), "Binding %s", *module_v);
Local<Array> modules = PersistentToLocal(module_load_list);
uint32_t l = modules->Length();
@ -1958,19 +1952,15 @@ static void Binding(const FunctionCallbackInfo<Value>& args) {
// only exports.
modp->register_func(exports, Undefined(node_isolate));
cache->Set(module, exports);
} else if (!strcmp(*module_v, "constants")) {
exports = Object::New();
DefineConstants(exports);
cache->Set(module, exports);
} else if (!strcmp(*module_v, "natives")) {
exports = Object::New();
DefineJavaScript(exports);
cache->Set(module, exports);
} else {
return ThrowError("No such module");
}
@ -1992,7 +1982,7 @@ static void ProcessTitleSetter(Local<String> property,
const PropertyCallbackInfo<void>& info) {
HandleScope scope(node_isolate);
String::Utf8Value title(value);
// TODO: protect with a lock
// TODO(piscisaureus): protect with a lock
uv_set_process_title(*title);
}
@ -2008,7 +1998,7 @@ static void EnvGetter(Local<String> property,
}
#else // _WIN32
String::Value key(property);
WCHAR buffer[32767]; // The maximum size allowed for environment variables.
WCHAR buffer[32767]; // The maximum size allowed for environment variables.
DWORD result = GetEnvironmentVariableW(reinterpret_cast<WCHAR*>(*key),
buffer,
ARRAY_SIZE(buffer));
@ -2142,16 +2132,17 @@ static Handle<Object> GetFeatures() {
HandleScope scope(node_isolate);
Local<Object> obj = Object::New();
obj->Set(String::NewSymbol("debug"),
#if defined(DEBUG) && DEBUG
True(node_isolate)
Local<Value> debug = True(node_isolate);
#else
False(node_isolate)
#endif
);
Local<Value> debug = False(node_isolate);
#endif // defined(DEBUG) && DEBUG
obj->Set(String::NewSymbol("debug"), debug);
obj->Set(String::NewSymbol("uv"), True(node_isolate));
obj->Set(String::NewSymbol("ipv6"), True(node_isolate)); // TODO ping libuv
// TODO(bnoordhuis) ping libuv
obj->Set(String::NewSymbol("ipv6"), True(node_isolate));
obj->Set(String::NewSymbol("tls_npn"), Boolean::New(use_npn));
obj->Set(String::NewSymbol("tls_sni"), Boolean::New(use_sni));
obj->Set(String::NewSymbol("tls"),
@ -2375,7 +2366,7 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
NODE_SET_METHOD(process, "getgroups", GetGroups);
NODE_SET_METHOD(process, "setgroups", SetGroups);
NODE_SET_METHOD(process, "initgroups", InitGroups);
#endif // __POSIX__ && !defined(__ANDROID__)
#endif // __POSIX__ && !defined(__ANDROID__)
NODE_SET_METHOD(process, "_kill", Kill);
@ -2488,7 +2479,7 @@ static void ParseDebugOpt(const char* arg) {
debug_port = atoi(p);
} else {
use_debug_agent = true;
if (!strcmp (arg, "--debug-brk")) {
if (!strcmp(arg, "--debug-brk")) {
debug_wait_connect = true;
return;
} else if (!strcmp(arg, "--debug")) {
@ -2546,7 +2537,7 @@ static void PrintHelp() {
static void ParseArgs(int argc, char **argv) {
int i;
// TODO use parse opts
// TODO(bnoordhuis) use parse opts
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
if (strstr(arg, "--debug") == arg) {
@ -2687,7 +2678,7 @@ static void EnableDebugSignalHandler(uv_signal_t* handle, int) {
}
static void RegisterSignalHandler(int signal, void (*handler)(int)) {
static void RegisterSignalHandler(int signal, void (*handler)(int signal)) {
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
@ -2713,7 +2704,7 @@ void DebugProcess(const FunctionCallbackInfo<Value>& args) {
return ThrowErrnoException(errno, "kill");
}
}
#endif // __POSIX__
#endif // __POSIX__
#ifdef _WIN32
@ -2776,7 +2767,7 @@ static int RegisterDebugSignalHandler() {
*handler = EnableDebugThreadProc;
UnmapViewOfFile((void*) handler);
UnmapViewOfFile(static_cast<void*>(handler));
return 0;
}
@ -2851,20 +2842,16 @@ static void DebugProcess(const FunctionCallbackInfo<Value>& args) {
}
out:
if (process != NULL) {
CloseHandle(process);
}
if (thread != NULL) {
if (process != NULL)
CloseHandle(process);
if (thread != NULL)
CloseHandle(thread);
}
if (handler != NULL) {
if (handler != NULL)
UnmapViewOfFile(handler);
}
if (mapping != NULL) {
if (mapping != NULL)
CloseHandle(mapping);
}
}
#endif // _WIN32
#endif // _WIN32
static void DebugPause(const FunctionCallbackInfo<Value>& args) {
@ -2928,7 +2915,7 @@ char** Init(int argc, char *argv[]) {
uint32_t *stack_limit = &stack_var - (max_stack_size / sizeof(uint32_t));
constraints.set_stack_limit(stack_limit);
SetResourceConstraints(&constraints); // Must be done before V8::Initialize
SetResourceConstraints(&constraints); // Must be done before V8::Initialize
}
V8::SetFlagsFromCommandLine(&v8argc, v8argv, false);
@ -2945,7 +2932,7 @@ char** Init(int argc, char *argv[]) {
RegisterSignalHandler(SIGPIPE, SIG_IGN);
RegisterSignalHandler(SIGINT, SignalExit);
RegisterSignalHandler(SIGTERM, SignalExit);
#endif // __POSIX__
#endif // __POSIX__
uv_check_init(uv_default_loop(), &check_immediate_watcher);
uv_unref(reinterpret_cast<uv_handle_t*>(&check_immediate_watcher));
@ -2960,12 +2947,12 @@ char** Init(int argc, char *argv[]) {
} else {
#ifdef _WIN32
RegisterDebugSignalHandler();
#else // Posix
#else // Posix
static uv_signal_t signal_watcher;
uv_signal_init(uv_default_loop(), &signal_watcher);
uv_signal_start(&signal_watcher, EnableDebugSignalHandler, SIGUSR1);
uv_unref(reinterpret_cast<uv_handle_t*>(&signal_watcher));
#endif // __POSIX__
#endif // __POSIX__
}
return argv;
@ -3018,18 +3005,20 @@ static char **copy_argv(int argc, char **argv) {
int i;
strlen_sum = 0;
for(i = 0; i < argc; i++) {
for (i = 0; i < argc; i++) {
strlen_sum += strlen(argv[i]) + 1;
}
argv_copy = (char **) malloc(sizeof(char *) * (argc + 1) + strlen_sum);
argv_copy = static_cast<char**>(
malloc(sizeof(*argv_copy) * (argc + 1) + strlen_sum));
if (!argv_copy) {
return NULL;
}
argv_data = (char *) argv_copy + sizeof(char *) * (argc + 1);
argv_data = reinterpret_cast<char*>(argv_copy) +
sizeof(*argv_copy) * (argc + 1);
for(i = 0; i < argc; i++) {
for (i = 0; i < argc; i++) {
argv_copy[i] = argv_data;
len = strlen(argv[i]) + 1;
memcpy(argv_data, argv[i], len);

4
src/node.h

@ -139,7 +139,7 @@ void EmitExit(v8::Handle<v8::Object> process);
// Used to be a macro, hence the uppercase name.
template <typename TypeName>
inline void NODE_SET_METHOD(TypeName& recv,
inline void NODE_SET_METHOD(const TypeName& recv,
const char* name,
v8::FunctionCallback callback) {
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(callback);
@ -163,7 +163,7 @@ inline void NODE_SET_PROTOTYPE_METHOD(v8::Handle<v8::FunctionTemplate> recv,
enum encoding {ASCII, UTF8, BASE64, UCS2, BINARY, HEX, BUFFER};
enum encoding ParseEncoding(v8::Handle<v8::Value> encoding_v,
enum encoding _default = BINARY);
NODE_EXTERN void FatalException(v8::TryCatch &try_catch);
NODE_EXTERN void FatalException(const v8::TryCatch& try_catch);
void DisplayExceptionLine(v8::Handle<v8::Message> message);
NODE_EXTERN v8::Local<v8::Value> Encode(const void *buf, size_t len,

2
src/node_buffer.cc

@ -53,7 +53,6 @@
size_t length = end - start;
namespace node {
namespace Buffer {
using v8::Function;
@ -610,7 +609,6 @@ void Initialize(Handle<Object> target) {
} // namespace Buffer
} // namespace node
NODE_MODULE(node_buffer, node::Buffer::Initialize)

8
src/node_buffer.h

@ -23,11 +23,10 @@
#include "smalloc.h"
#include "v8.h"
#ifndef NODE_BUFFER_H_
#define NODE_BUFFER_H_
#ifndef SRC_NODE_BUFFER_H_
#define SRC_NODE_BUFFER_H_
namespace node {
namespace Buffer {
static const unsigned int kMaxLength = smalloc::kMaxLength;
@ -58,7 +57,6 @@ NODE_EXTERN v8::Local<v8::Object> New(char* data,
NODE_EXTERN v8::Local<v8::Object> Use(char* data, uint32_t len);
} // namespace Buffer
} // namespace node
#endif // NODE_BUFFER_H_
#endif // SRC_NODE_BUFFER_H_

332
src/node_constants.cc

@ -38,131 +38,10 @@
namespace node {
using namespace v8;
void DefineConstants(Handle<Object> target) {
// file access modes
NODE_DEFINE_CONSTANT(target, O_RDONLY);
NODE_DEFINE_CONSTANT(target, O_WRONLY);
NODE_DEFINE_CONSTANT(target, O_RDWR);
NODE_DEFINE_CONSTANT(target, S_IFMT);
NODE_DEFINE_CONSTANT(target, S_IFREG);
NODE_DEFINE_CONSTANT(target, S_IFDIR);
NODE_DEFINE_CONSTANT(target, S_IFCHR);
#ifdef S_IFBLK
NODE_DEFINE_CONSTANT(target, S_IFBLK);
#endif
#ifdef S_IFIFO
NODE_DEFINE_CONSTANT(target, S_IFIFO);
#endif
#ifdef S_IFLNK
NODE_DEFINE_CONSTANT(target, S_IFLNK);
#endif
#ifdef S_IFSOCK
NODE_DEFINE_CONSTANT(target, S_IFSOCK);
#endif
#ifdef O_CREAT
NODE_DEFINE_CONSTANT(target, O_CREAT);
#endif
#ifdef O_EXCL
NODE_DEFINE_CONSTANT(target, O_EXCL);
#endif
#ifdef O_NOCTTY
NODE_DEFINE_CONSTANT(target, O_NOCTTY);
#endif
#ifdef O_TRUNC
NODE_DEFINE_CONSTANT(target, O_TRUNC);
#endif
#ifdef O_APPEND
NODE_DEFINE_CONSTANT(target, O_APPEND);
#endif
#ifdef O_DIRECTORY
NODE_DEFINE_CONSTANT(target, O_DIRECTORY);
#endif
#ifdef O_EXCL
NODE_DEFINE_CONSTANT(target, O_EXCL);
#endif
#ifdef O_NOFOLLOW
NODE_DEFINE_CONSTANT(target, O_NOFOLLOW);
#endif
#ifdef O_SYNC
NODE_DEFINE_CONSTANT(target, O_SYNC);
#endif
#ifdef O_SYMLINK
NODE_DEFINE_CONSTANT(target, O_SYMLINK);
#endif
#ifdef O_DIRECT
NODE_DEFINE_CONSTANT(target, O_DIRECT);
#endif
#ifdef S_IRWXU
NODE_DEFINE_CONSTANT(target, S_IRWXU);
#endif
#ifdef S_IRUSR
NODE_DEFINE_CONSTANT(target, S_IRUSR);
#endif
#ifdef S_IWUSR
NODE_DEFINE_CONSTANT(target, S_IWUSR);
#endif
#ifdef S_IXUSR
NODE_DEFINE_CONSTANT(target, S_IXUSR);
#endif
#ifdef S_IRWXG
NODE_DEFINE_CONSTANT(target, S_IRWXG);
#endif
#ifdef S_IRGRP
NODE_DEFINE_CONSTANT(target, S_IRGRP);
#endif
#ifdef S_IWGRP
NODE_DEFINE_CONSTANT(target, S_IWGRP);
#endif
#ifdef S_IXGRP
NODE_DEFINE_CONSTANT(target, S_IXGRP);
#endif
#ifdef S_IRWXO
NODE_DEFINE_CONSTANT(target, S_IRWXO);
#endif
#ifdef S_IROTH
NODE_DEFINE_CONSTANT(target, S_IROTH);
#endif
#ifdef S_IWOTH
NODE_DEFINE_CONSTANT(target, S_IWOTH);
#endif
#ifdef S_IXOTH
NODE_DEFINE_CONSTANT(target, S_IXOTH);
#endif
using v8::Handle;
using v8::Object;
void DefineErrnoConstants(Handle<Object> target) {
#ifdef E2BIG
NODE_DEFINE_CONSTANT(target, E2BIG);
#endif
@ -478,7 +357,9 @@ void DefineConstants(Handle<Object> target) {
#ifdef EXDEV
NODE_DEFINE_CONSTANT(target, EXDEV);
#endif
}
void DefineWindowsErrorConstants(Handle<Object> target) {
#ifdef WSAEINTR
NODE_DEFINE_CONSTANT(target, WSAEINTR);
#endif
@ -710,7 +591,9 @@ void DefineConstants(Handle<Object> target) {
#ifdef WSAEREFUSED
NODE_DEFINE_CONSTANT(target, WSAEREFUSED);
#endif
}
void DefineSignalConstants(Handle<Object> target) {
#ifdef SIGHUP
NODE_DEFINE_CONSTANT(target, SIGHUP);
#endif
@ -853,149 +736,276 @@ void DefineConstants(Handle<Object> target) {
#ifdef SIGUNUSED
NODE_DEFINE_CONSTANT(target, SIGUNUSED);
#endif
}
// OpenSSL SSL context options
void DefineOpenSSLConstants(Handle<Object> target) {
#ifdef SSL_OP_ALL
NODE_DEFINE_CONSTANT(target, SSL_OP_ALL);
NODE_DEFINE_CONSTANT(target, SSL_OP_ALL);
#endif
#ifdef SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION
NODE_DEFINE_CONSTANT(target, SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION);
NODE_DEFINE_CONSTANT(target, SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION);
#endif
#ifdef SSL_OP_CIPHER_SERVER_PREFERENCE
NODE_DEFINE_CONSTANT(target, SSL_OP_CIPHER_SERVER_PREFERENCE);
NODE_DEFINE_CONSTANT(target, SSL_OP_CIPHER_SERVER_PREFERENCE);
#endif
#ifdef SSL_OP_CISCO_ANYCONNECT
NODE_DEFINE_CONSTANT(target, SSL_OP_CISCO_ANYCONNECT);
NODE_DEFINE_CONSTANT(target, SSL_OP_CISCO_ANYCONNECT);
#endif
#ifdef SSL_OP_COOKIE_EXCHANGE
NODE_DEFINE_CONSTANT(target, SSL_OP_COOKIE_EXCHANGE);
NODE_DEFINE_CONSTANT(target, SSL_OP_COOKIE_EXCHANGE);
#endif
#ifdef SSL_OP_CRYPTOPRO_TLSEXT_BUG
NODE_DEFINE_CONSTANT(target, SSL_OP_CRYPTOPRO_TLSEXT_BUG);
NODE_DEFINE_CONSTANT(target, SSL_OP_CRYPTOPRO_TLSEXT_BUG);
#endif
#ifdef SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS
NODE_DEFINE_CONSTANT(target, SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS);
NODE_DEFINE_CONSTANT(target, SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS);
#endif
#ifdef SSL_OP_EPHEMERAL_RSA
NODE_DEFINE_CONSTANT(target, SSL_OP_EPHEMERAL_RSA);
NODE_DEFINE_CONSTANT(target, SSL_OP_EPHEMERAL_RSA);
#endif
#ifdef SSL_OP_LEGACY_SERVER_CONNECT
NODE_DEFINE_CONSTANT(target, SSL_OP_LEGACY_SERVER_CONNECT);
NODE_DEFINE_CONSTANT(target, SSL_OP_LEGACY_SERVER_CONNECT);
#endif
#ifdef SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER
NODE_DEFINE_CONSTANT(target, SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER);
NODE_DEFINE_CONSTANT(target, SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER);
#endif
#ifdef SSL_OP_MICROSOFT_SESS_ID_BUG
NODE_DEFINE_CONSTANT(target, SSL_OP_MICROSOFT_SESS_ID_BUG);
NODE_DEFINE_CONSTANT(target, SSL_OP_MICROSOFT_SESS_ID_BUG);
#endif
#ifdef SSL_OP_MSIE_SSLV2_RSA_PADDING
NODE_DEFINE_CONSTANT(target, SSL_OP_MSIE_SSLV2_RSA_PADDING);
NODE_DEFINE_CONSTANT(target, SSL_OP_MSIE_SSLV2_RSA_PADDING);
#endif
#ifdef SSL_OP_NETSCAPE_CA_DN_BUG
NODE_DEFINE_CONSTANT(target, SSL_OP_NETSCAPE_CA_DN_BUG);
NODE_DEFINE_CONSTANT(target, SSL_OP_NETSCAPE_CA_DN_BUG);
#endif
#ifdef SSL_OP_NETSCAPE_CHALLENGE_BUG
NODE_DEFINE_CONSTANT(target, SSL_OP_NETSCAPE_CHALLENGE_BUG);
NODE_DEFINE_CONSTANT(target, SSL_OP_NETSCAPE_CHALLENGE_BUG);
#endif
#ifdef SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG
NODE_DEFINE_CONSTANT(target, SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG);
NODE_DEFINE_CONSTANT(target, SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG);
#endif
#ifdef SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG
NODE_DEFINE_CONSTANT(target, SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG);
NODE_DEFINE_CONSTANT(target, SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG);
#endif
#ifdef SSL_OP_NO_COMPRESSION
NODE_DEFINE_CONSTANT(target, SSL_OP_NO_COMPRESSION);
NODE_DEFINE_CONSTANT(target, SSL_OP_NO_COMPRESSION);
#endif
#ifdef SSL_OP_NO_QUERY_MTU
NODE_DEFINE_CONSTANT(target, SSL_OP_NO_QUERY_MTU);
NODE_DEFINE_CONSTANT(target, SSL_OP_NO_QUERY_MTU);
#endif
#ifdef SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION
NODE_DEFINE_CONSTANT(target, SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION);
NODE_DEFINE_CONSTANT(target, SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION);
#endif
#ifdef SSL_OP_NO_SSLv2
NODE_DEFINE_CONSTANT(target, SSL_OP_NO_SSLv2);
NODE_DEFINE_CONSTANT(target, SSL_OP_NO_SSLv2);
#endif
#ifdef SSL_OP_NO_SSLv3
NODE_DEFINE_CONSTANT(target, SSL_OP_NO_SSLv3);
NODE_DEFINE_CONSTANT(target, SSL_OP_NO_SSLv3);
#endif
#ifdef SSL_OP_NO_TICKET
NODE_DEFINE_CONSTANT(target, SSL_OP_NO_TICKET);
NODE_DEFINE_CONSTANT(target, SSL_OP_NO_TICKET);
#endif
#ifdef SSL_OP_NO_TLSv1
NODE_DEFINE_CONSTANT(target, SSL_OP_NO_TLSv1);
NODE_DEFINE_CONSTANT(target, SSL_OP_NO_TLSv1);
#endif
#ifdef SSL_OP_NO_TLSv1_1
NODE_DEFINE_CONSTANT(target, SSL_OP_NO_TLSv1_1);
NODE_DEFINE_CONSTANT(target, SSL_OP_NO_TLSv1_1);
#endif
#ifdef SSL_OP_NO_TLSv1_2
NODE_DEFINE_CONSTANT(target, SSL_OP_NO_TLSv1_2);
NODE_DEFINE_CONSTANT(target, SSL_OP_NO_TLSv1_2);
#endif
#ifdef SSL_OP_PKCS1_CHECK_1
NODE_DEFINE_CONSTANT(target, SSL_OP_PKCS1_CHECK_1);
NODE_DEFINE_CONSTANT(target, SSL_OP_PKCS1_CHECK_1);
#endif
#ifdef SSL_OP_PKCS1_CHECK_2
NODE_DEFINE_CONSTANT(target, SSL_OP_PKCS1_CHECK_2);
NODE_DEFINE_CONSTANT(target, SSL_OP_PKCS1_CHECK_2);
#endif
#ifdef SSL_OP_SINGLE_DH_USE
NODE_DEFINE_CONSTANT(target, SSL_OP_SINGLE_DH_USE);
NODE_DEFINE_CONSTANT(target, SSL_OP_SINGLE_DH_USE);
#endif
#ifdef SSL_OP_SINGLE_ECDH_USE
NODE_DEFINE_CONSTANT(target, SSL_OP_SINGLE_ECDH_USE);
NODE_DEFINE_CONSTANT(target, SSL_OP_SINGLE_ECDH_USE);
#endif
#ifdef SSL_OP_SSLEAY_080_CLIENT_DH_BUG
NODE_DEFINE_CONSTANT(target, SSL_OP_SSLEAY_080_CLIENT_DH_BUG);
NODE_DEFINE_CONSTANT(target, SSL_OP_SSLEAY_080_CLIENT_DH_BUG);
#endif
#ifdef SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG
NODE_DEFINE_CONSTANT(target, SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG);
NODE_DEFINE_CONSTANT(target, SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG);
#endif
#ifdef SSL_OP_TLS_BLOCK_PADDING_BUG
NODE_DEFINE_CONSTANT(target, SSL_OP_TLS_BLOCK_PADDING_BUG);
NODE_DEFINE_CONSTANT(target, SSL_OP_TLS_BLOCK_PADDING_BUG);
#endif
#ifdef SSL_OP_TLS_D5_BUG
NODE_DEFINE_CONSTANT(target, SSL_OP_TLS_D5_BUG);
NODE_DEFINE_CONSTANT(target, SSL_OP_TLS_D5_BUG);
#endif
#ifdef SSL_OP_TLS_ROLLBACK_BUG
NODE_DEFINE_CONSTANT(target, SSL_OP_TLS_ROLLBACK_BUG);
NODE_DEFINE_CONSTANT(target, SSL_OP_TLS_ROLLBACK_BUG);
#endif
#ifdef OPENSSL_NPN_NEGOTIATED
#define NPN_ENABLED 1
NODE_DEFINE_CONSTANT(target, NPN_ENABLED);
NODE_DEFINE_CONSTANT(target, NPN_ENABLED);
#endif
}
void DefineSystemConstants(Handle<Object> target) {
// file access modes
NODE_DEFINE_CONSTANT(target, O_RDONLY);
NODE_DEFINE_CONSTANT(target, O_WRONLY);
NODE_DEFINE_CONSTANT(target, O_RDWR);
NODE_DEFINE_CONSTANT(target, S_IFMT);
NODE_DEFINE_CONSTANT(target, S_IFREG);
NODE_DEFINE_CONSTANT(target, S_IFDIR);
NODE_DEFINE_CONSTANT(target, S_IFCHR);
#ifdef S_IFBLK
NODE_DEFINE_CONSTANT(target, S_IFBLK);
#endif
#ifdef S_IFIFO
NODE_DEFINE_CONSTANT(target, S_IFIFO);
#endif
#ifdef S_IFLNK
NODE_DEFINE_CONSTANT(target, S_IFLNK);
#endif
#ifdef S_IFSOCK
NODE_DEFINE_CONSTANT(target, S_IFSOCK);
#endif
#ifdef O_CREAT
NODE_DEFINE_CONSTANT(target, O_CREAT);
#endif
#ifdef O_EXCL
NODE_DEFINE_CONSTANT(target, O_EXCL);
#endif
#ifdef O_NOCTTY
NODE_DEFINE_CONSTANT(target, O_NOCTTY);
#endif
#ifdef O_TRUNC
NODE_DEFINE_CONSTANT(target, O_TRUNC);
#endif
#ifdef O_APPEND
NODE_DEFINE_CONSTANT(target, O_APPEND);
#endif
#ifdef O_DIRECTORY
NODE_DEFINE_CONSTANT(target, O_DIRECTORY);
#endif
#ifdef O_EXCL
NODE_DEFINE_CONSTANT(target, O_EXCL);
#endif
#ifdef O_NOFOLLOW
NODE_DEFINE_CONSTANT(target, O_NOFOLLOW);
#endif
#ifdef O_SYNC
NODE_DEFINE_CONSTANT(target, O_SYNC);
#endif
#ifdef O_SYMLINK
NODE_DEFINE_CONSTANT(target, O_SYMLINK);
#endif
#ifdef O_DIRECT
NODE_DEFINE_CONSTANT(target, O_DIRECT);
#endif
#ifdef S_IRWXU
NODE_DEFINE_CONSTANT(target, S_IRWXU);
#endif
#ifdef S_IRUSR
NODE_DEFINE_CONSTANT(target, S_IRUSR);
#endif
#ifdef S_IWUSR
NODE_DEFINE_CONSTANT(target, S_IWUSR);
#endif
#ifdef S_IXUSR
NODE_DEFINE_CONSTANT(target, S_IXUSR);
#endif
#ifdef S_IRWXG
NODE_DEFINE_CONSTANT(target, S_IRWXG);
#endif
#ifdef S_IRGRP
NODE_DEFINE_CONSTANT(target, S_IRGRP);
#endif
#ifdef S_IWGRP
NODE_DEFINE_CONSTANT(target, S_IWGRP);
#endif
#ifdef S_IXGRP
NODE_DEFINE_CONSTANT(target, S_IXGRP);
#endif
#ifdef S_IRWXO
NODE_DEFINE_CONSTANT(target, S_IRWXO);
#endif
#ifdef S_IROTH
NODE_DEFINE_CONSTANT(target, S_IROTH);
#endif
#ifdef S_IWOTH
NODE_DEFINE_CONSTANT(target, S_IWOTH);
#endif
#ifdef S_IXOTH
NODE_DEFINE_CONSTANT(target, S_IXOTH);
#endif
}
void DefineConstants(Handle<Object> target) {
DefineErrnoConstants(target);
DefineWindowsErrorConstants(target);
DefineSignalConstants(target);
DefineOpenSSLConstants(target);
DefineSystemConstants(target);
}
} // namespace node

6
src/node_constants.h

@ -19,8 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef SRC_CONSTANTS_H_
#define SRC_CONSTANTS_H_
#ifndef SRC_NODE_CONSTANTS_H_
#define SRC_NODE_CONSTANTS_H_
#include "node.h"
#include "v8.h"
@ -29,4 +29,4 @@ namespace node {
void DefineConstants(v8::Handle<v8::Object> target);
} // namespace node
#endif // SRC_CONSTANTS_H_
#endif // SRC_NODE_CONSTANTS_H_

5
src/node_counters.cc

@ -86,7 +86,8 @@ static void counter_gc_done(GCType type, GCCallbackFlags flags) {
uint64_t gcperiod = endgc - counter_gc_start_time;
if (totalperiod > 0) {
unsigned int percent = static_cast<unsigned int>((gcperiod * 100) / totalperiod);
unsigned int percent = static_cast<unsigned int>(
(gcperiod * 100) / totalperiod);
NODE_COUNT_GC_PERCENTTIME(percent);
counter_gc_end_time = endgc;
@ -137,4 +138,4 @@ void TermPerfCounters(Handle<Object> target) {
TermPerfCountersWin32();
}
}
} // namespace node

8
src/node_counters.h

@ -19,8 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef NODE_COUNTERS_H_
#define NODE_COUNTERS_H_
#ifndef SRC_NODE_COUNTERS_H_
#define SRC_NODE_COUNTERS_H_
#include "node.h"
#include "v8.h"
@ -30,7 +30,7 @@ namespace node {
void InitPerfCounters(v8::Handle<v8::Object> target);
void TermPerfCounters(v8::Handle<v8::Object> target);
}
} // namespace node
#ifdef HAVE_PERFCTR
#include "node_win32_perfctr_provider.h"
@ -50,4 +50,4 @@ void TermPerfCounters(v8::Handle<v8::Object> target);
#define NODE_COUNT_PIPE_BYTES_RECV(bytes)
#endif
#endif
#endif // SRC_NODE_COUNTERS_H_

271
src/node_crypto.cc

@ -326,7 +326,7 @@ int SecureContext::NewSessionCallback(SSL* s, SSL_SESSION* sess) {
// Takes a string or buffer and loads it into a BIO.
// Caller responsible for BIO_free_all-ing the returned object.
static BIO* LoadBIO (Handle<Value> v) {
static BIO* LoadBIO(Handle<Value> v) {
BIO *bio = BIO_new(NodeBIO::GetMethod());
if (!bio) return NULL;
@ -354,8 +354,8 @@ static BIO* LoadBIO (Handle<Value> v) {
// Takes a string or buffer and loads it into an X509
// Caller responsible for X509_free-ing the returned object.
static X509* LoadX509 (Handle<Value> v) {
HandleScope scope(node_isolate); // necessary?
static X509* LoadX509(Handle<Value> v) {
HandleScope scope(node_isolate);
BIO *bio = LoadBIO(v);
if (!bio) return NULL;
@ -467,7 +467,7 @@ int SSL_CTX_use_certificate_chain(SSL_CTX *ctx, BIO *in) {
}
}
end:
end:
if (x != NULL) X509_free(x);
return ret;
}
@ -648,8 +648,7 @@ void SecureContext::SetSessionIdContext(
bio = BIO_new(BIO_s_mem());
if (bio == NULL) {
message = String::New("SSL_CTX_set_session_id_context error");
}
else {
} else {
ERR_print_errors(bio);
BIO_get_mem_ptr(bio, &mem);
message = String::New(mem->data, mem->length);
@ -681,7 +680,7 @@ void SecureContext::Close(const FunctionCallbackInfo<Value>& args) {
}
//Takes .pfx or .p12 and password in string or buffer format
// Takes .pfx or .p12 and password in string or buffer format
void SecureContext::LoadPKCS12(const FunctionCallbackInfo<Value>& args) {
HandleScope scope(node_isolate);
@ -722,8 +721,7 @@ void SecureContext::LoadPKCS12(const FunctionCallbackInfo<Value>& args) {
if (d2i_PKCS12_bio(in, &p12) &&
PKCS12_parse(p12, pass, &pkey, &cert, &extraCerts) &&
SSL_CTX_use_certificate(sc->ctx_, cert) &&
SSL_CTX_use_PrivateKey(sc->ctx_, pkey))
{
SSL_CTX_use_PrivateKey(sc->ctx_, pkey)) {
// set extra certs
while (X509* x509 = sk_X509_pop(extraCerts)) {
if (!sc->ca_store_) {
@ -817,115 +815,114 @@ size_t ClientHelloParser::Write(const uint8_t* data, size_t len) {
Handle<Value> argv[1];
switch (state_) {
case kWaiting:
// >= 5 bytes for header parsing
if (offset_ < 5) break;
if (data_[0] == kChangeCipherSpec || data_[0] == kAlert ||
data_[0] == kHandshake || data_[0] == kApplicationData) {
frame_len_ = (data_[3] << 8) + data_[4];
state_ = kTLSHeader;
body_offset_ = 5;
} else {
frame_len_ = (data_[0] << 8) + data_[1];
state_ = kSSLHeader;
if (*data_ & 0x40) {
// header with padding
body_offset_ = 3;
case kWaiting:
// >= 5 bytes for header parsing
if (offset_ < 5)
break;
if (data_[0] == kChangeCipherSpec ||
data_[0] == kAlert ||
data_[0] == kHandshake ||
data_[0] == kApplicationData) {
frame_len_ = (data_[3] << 8) + data_[4];
state_ = kTLSHeader;
body_offset_ = 5;
} else {
// without padding
body_offset_ = 2;
frame_len_ = (data_[0] << 8) + data_[1];
state_ = kSSLHeader;
if (*data_ & 0x40) {
// header with padding
body_offset_ = 3;
} else {
// without padding
body_offset_ = 2;
}
}
}
// Sanity check (too big frame, or too small)
if (frame_len_ >= sizeof(data_)) {
// Let OpenSSL handle it
Finish();
return copied;
}
case kTLSHeader:
case kSSLHeader:
// >= 5 + frame size bytes for frame parsing
if (offset_ < body_offset_ + frame_len_) break;
// Skip unsupported frames and gather some data from frame
// TODO: Check protocol version
if (data_[body_offset_] == kClientHello) {
is_clienthello = true;
uint8_t* body;
size_t session_offset;
if (state_ == kTLSHeader) {
// Skip frame header, hello header, protocol version and random data
session_offset = body_offset_ + 4 + 2 + 32;
if (session_offset + 1 < offset_) {
body = data_ + session_offset;
session_size = *body;
session_id = body + 1;
}
} else if (state_ == kSSLHeader) {
// Skip header, version
session_offset = body_offset_ + 3;
// Sanity check (too big frame, or too small)
if (frame_len_ >= sizeof(data_)) {
// Let OpenSSL handle it
Finish();
return copied;
}
case kTLSHeader:
case kSSLHeader:
// >= 5 + frame size bytes for frame parsing
if (offset_ < body_offset_ + frame_len_)
break;
// Skip unsupported frames and gather some data from frame
if (data_[body_offset_] == kClientHello) {
is_clienthello = true;
uint8_t* body;
size_t session_offset;
if (state_ == kTLSHeader) {
// Skip frame header, hello header, protocol version and random data
session_offset = body_offset_ + 4 + 2 + 32;
if (session_offset + 1 < offset_) {
body = data_ + session_offset;
session_size = *body;
session_id = body + 1;
}
} else if (state_ == kSSLHeader) {
// Skip header, version
session_offset = body_offset_ + 3;
if (session_offset + 4 < offset_) {
body = data_ + session_offset;
if (session_offset + 4 < offset_) {
body = data_ + session_offset;
int ciphers_size = (body[0] << 8) + body[1];
int ciphers_size = (body[0] << 8) + body[1];
if (body + 4 + ciphers_size < data_ + offset_) {
session_size = (body[2] << 8) + body[3];
session_id = body + 4 + ciphers_size;
if (body + 4 + ciphers_size < data_ + offset_) {
session_size = (body[2] << 8) + body[3];
session_id = body + 4 + ciphers_size;
}
}
} else {
// Whoa? How did we get here?
abort();
}
// Check if we overflowed (do not reply with any private data)
if (session_id == NULL ||
session_size > 32 ||
session_id + session_size > data_ + offset_) {
Finish();
return copied;
}
} else {
// Whoa? How did we get here?
abort();
}
// Check if we overflowed (do not reply with any private data)
if (session_id == NULL ||
session_size > 32 ||
session_id + session_size > data_ + offset_) {
// Not client hello - let OpenSSL handle it
if (!is_clienthello) {
Finish();
return copied;
}
// TODO: Parse other things?
}
// Not client hello - let OpenSSL handle it
if (!is_clienthello) {
Finish();
return copied;
}
// Parse frame, call javascript handler and
// move parser into the paused state
if (onclienthello_sym.IsEmpty()) {
onclienthello_sym = String::New("onclienthello");
}
if (sessionid_sym.IsEmpty()) {
sessionid_sym = String::New("sessionId");
}
state_ = kPaused;
hello = Object::New();
hello->Set(sessionid_sym,
Buffer::New(reinterpret_cast<char*>(session_id),
session_size));
argv[0] = hello;
MakeCallback(conn_->handle(node_isolate),
onclienthello_sym,
ARRAY_SIZE(argv),
argv);
break;
case kEnded:
default:
break;
// Parse frame, call javascript handler and
// move parser into the paused state
if (onclienthello_sym.IsEmpty())
onclienthello_sym = String::New("onclienthello");
if (sessionid_sym.IsEmpty())
sessionid_sym = String::New("sessionId");
state_ = kPaused;
hello = Object::New();
hello->Set(sessionid_sym,
Buffer::New(reinterpret_cast<char*>(session_id),
session_size));
argv[0] = hello;
MakeCallback(conn_->handle(node_isolate),
onclienthello_sym,
ARRAY_SIZE(argv),
argv);
break;
case kEnded:
default:
break;
}
return copied;
@ -954,10 +951,13 @@ int Connection::HandleBIOError(BIO *bio, const char* func, int rv) {
if (rv >= 0) return rv;
int retry = BIO_should_retry(bio);
(void) retry; // unused if !defined(SSL_PRINT_DEBUG)
(void) retry; // unused if !defined(SSL_PRINT_DEBUG)
if (BIO_should_write(bio)) {
DEBUG_PRINT("[%p] BIO: %s want write. should retry %d\n", ssl_, func, retry);
DEBUG_PRINT("[%p] BIO: %s want write. should retry %d\n",
ssl_,
func,
retry);
return 0;
} else if (BIO_should_read(bio)) {
@ -972,7 +972,11 @@ int Connection::HandleBIOError(BIO *bio, const char* func, int rv) {
Local<Value> e = Exception::Error(String::New(ssl_error_buf));
handle(node_isolate)->Set(String::New("error"), e);
DEBUG_PRINT("[%p] BIO: %s failed: (%d) %s\n", ssl_, func, rv, ssl_error_buf);
DEBUG_PRINT("[%p] BIO: %s failed: (%d) %s\n",
ssl_,
func,
rv,
ssl_error_buf);
return rv;
}
@ -1046,7 +1050,7 @@ void Connection::ClearError() {
// We should clear the error in JS-land
assert(
handle(node_isolate)->Get(String::New("error"))->BooleanValue() == false);
#endif // NDEBUG
#endif // NDEBUG
}
@ -1079,22 +1083,32 @@ void Connection::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "encOut", Connection::EncOut);
NODE_SET_PROTOTYPE_METHOD(t, "clearPending", Connection::ClearPending);
NODE_SET_PROTOTYPE_METHOD(t, "encPending", Connection::EncPending);
NODE_SET_PROTOTYPE_METHOD(t, "getPeerCertificate", Connection::GetPeerCertificate);
NODE_SET_PROTOTYPE_METHOD(t,
"getPeerCertificate",
Connection::GetPeerCertificate);
NODE_SET_PROTOTYPE_METHOD(t, "getSession", Connection::GetSession);
NODE_SET_PROTOTYPE_METHOD(t, "setSession", Connection::SetSession);
NODE_SET_PROTOTYPE_METHOD(t, "loadSession", Connection::LoadSession);
NODE_SET_PROTOTYPE_METHOD(t, "isSessionReused", Connection::IsSessionReused);
NODE_SET_PROTOTYPE_METHOD(t, "isInitFinished", Connection::IsInitFinished);
NODE_SET_PROTOTYPE_METHOD(t, "verifyError", Connection::VerifyError);
NODE_SET_PROTOTYPE_METHOD(t, "getCurrentCipher", Connection::GetCurrentCipher);
NODE_SET_PROTOTYPE_METHOD(t,
"getCurrentCipher",
Connection::GetCurrentCipher);
NODE_SET_PROTOTYPE_METHOD(t, "start", Connection::Start);
NODE_SET_PROTOTYPE_METHOD(t, "shutdown", Connection::Shutdown);
NODE_SET_PROTOTYPE_METHOD(t, "receivedShutdown", Connection::ReceivedShutdown);
NODE_SET_PROTOTYPE_METHOD(t,
"receivedShutdown",
Connection::ReceivedShutdown);
NODE_SET_PROTOTYPE_METHOD(t, "close", Connection::Close);
#ifdef OPENSSL_NPN_NEGOTIATED
NODE_SET_PROTOTYPE_METHOD(t, "getNegotiatedProtocol", Connection::GetNegotiatedProto);
NODE_SET_PROTOTYPE_METHOD(t, "setNPNProtocols", Connection::SetNPNProtocols);
NODE_SET_PROTOTYPE_METHOD(t,
"getNegotiatedProtocol",
Connection::GetNegotiatedProto);
NODE_SET_PROTOTYPE_METHOD(t,
"setNPNProtocols",
Connection::SetNPNProtocols);
#endif
@ -1158,7 +1172,6 @@ int Connection::AdvertiseNextProtoCallback_(SSL *s,
const unsigned char** data,
unsigned int *len,
void *arg) {
Connection *p = static_cast<Connection*>(SSL_get_app_data(s));
if (p->npnProtos_.IsEmpty()) {
@ -1599,8 +1612,8 @@ void Connection::GetPeerCertificate(const FunctionCallbackInfo<Value>& args) {
EVP_PKEY *pkey = NULL;
RSA *rsa = NULL;
if( NULL != (pkey = X509_get_pubkey(peer_cert))
&& NULL != (rsa = EVP_PKEY_get1_RSA(pkey)) ) {
if (NULL != (pkey = X509_get_pubkey(peer_cert)) &&
NULL != (rsa = EVP_PKEY_get1_RSA(pkey))) {
BN_print(bio, rsa->n);
BIO_get_mem_ptr(bio, &mem);
info->Set(modulus_symbol, String::New(mem->data, mem->length) );
@ -1637,7 +1650,7 @@ void Connection::GetPeerCertificate(const FunctionCallbackInfo<Value>& args) {
const char hex[] = "0123456789ABCDEF";
char fingerprint[EVP_MAX_MD_SIZE * 3];
for (i = 0; i<md_size; i++) {
for (i = 0; i < md_size; i++) {
fingerprint[3*i] = hex[(md[i] & 0xf0) >> 4];
fingerprint[(3*i)+1] = hex[(md[i] & 0x0f)];
fingerprint[(3*i)+2] = ':';
@ -1645,8 +1658,7 @@ void Connection::GetPeerCertificate(const FunctionCallbackInfo<Value>& args) {
if (md_size > 0) {
fingerprint[(3*(md_size-1))+2] = '\0';
}
else {
} else {
fingerprint[0] = '\0';
}
@ -1840,7 +1852,6 @@ void Connection::VerifyError(const FunctionCallbackInfo<Value>& args) {
}
X509_free(peer_cert);
long x509_verify_error = SSL_get_verify_result(ss->ssl_);
Local<String> s;
@ -2678,7 +2689,7 @@ void Sign::SignFinal(const FunctionCallbackInfo<Value>& args) {
ssize_t len = Buffer::Length(args[0]);
char* buf = Buffer::Data(args[0]);
md_len = 8192; // Maximum key size is 8192 bits
md_len = 8192; // Maximum key size is 8192 bits
md_value = new unsigned char[md_len];
bool r = sign->SignFinal(&md_value, &md_len, buf, len);
@ -2841,7 +2852,7 @@ bool Verify::VerifyFinal(const char* key_pem,
siglen,
pkey);
exit:
exit:
if (pkey != NULL)
EVP_PKEY_free(pkey);
if (bp != NULL)
@ -3404,7 +3415,7 @@ void PBKDF2(const FunctionCallbackInfo<Value>& args) {
}
return;
err:
err:
delete[] salt;
delete[] pass;
return ThrowTypeError(type_error);
@ -3414,7 +3425,7 @@ err:
struct RandomBytesRequest {
~RandomBytesRequest();
Persistent<Object> obj_;
unsigned long error_; // openssl error code or zero
unsigned long error_; // openssl error code or zero
uv_work_t work_req_;
size_t size_;
char* data_;
@ -3460,8 +3471,7 @@ void RandomBytesCheck(RandomBytesRequest* req, Local<Value> argv[2]) {
argv[0] = Exception::Error(String::New(errmsg));
argv[1] = Null(node_isolate);
}
else {
} else {
argv[0] = Null(node_isolate);
argv[1] = Buffer::Use(req->data_, req->size_);
}
@ -3511,8 +3521,7 @@ void RandomBytes(const FunctionCallbackInfo<Value>& args) {
RandomBytesWork<pseudoRandom>,
RandomBytesAfter);
args.GetReturnValue().Set(obj);
}
else {
} else {
Local<Value> argv[2];
RandomBytesWork<pseudoRandom>(&req->work_req_);
RandomBytesCheck(req, argv);
@ -3596,13 +3605,11 @@ void InitCrypto(Handle<Object> target) {
// Turn off compression. Saves memory - do it in userland.
#if !defined(OPENSSL_NO_COMP)
STACK_OF(SSL_COMP)* comp_methods =
#if OPENSSL_VERSION_NUMBER < 0x00908000L
SSL_COMP_get_compression_method()
STACK_OF(SSL_COMP)* comp_methods = SSL_COMP_get_compression_method();
#else
SSL_COMP_get_compression_methods()
STACK_OF(SSL_COMP)* comp_methods = SSL_COMP_get_compression_methods();
#endif
;
sk_SSL_COMP_zero(comp_methods);
assert(sk_SSL_COMP_num(comp_methods) == 0);
#endif

25
src/node_crypto.h

@ -57,7 +57,7 @@ class SecureContext : ObjectWrap {
static void Initialize(v8::Handle<v8::Object> target);
SSL_CTX *ctx_;
// TODO: ca_store_ should probably be removed, it's not used anywhere.
// TODO(indutny): ca_store_ should probably be removed, it's not used anywhere
X509_STORE *ca_store_;
static const int kMaxSessionSize = 10 * 1024;
@ -139,10 +139,10 @@ class ClientHelloParser {
kEnded
};
ClientHelloParser(Connection* c) : conn_(c),
state_(kWaiting),
offset_(0),
body_offset_(0) {
explicit ClientHelloParser(Connection* c) : conn_(c),
state_(kWaiting),
offset_(0),
body_offset_(0) {
}
size_t Write(const uint8_t* data, size_t len);
@ -316,9 +316,9 @@ class CipherBase : public ObjectWrap {
static void Final(const v8::FunctionCallbackInfo<v8::Value>& args);
static void SetAutoPadding(const v8::FunctionCallbackInfo<v8::Value>& args);
CipherBase(CipherKind kind) : cipher_(NULL),
initialised_(false),
kind_(kind) {
explicit CipherBase(CipherKind kind) : cipher_(NULL),
initialised_(false),
kind_(kind) {
}
~CipherBase() {
@ -335,7 +335,7 @@ class CipherBase : public ObjectWrap {
class Hmac : public ObjectWrap {
public:
static void Initialize (v8::Handle<v8::Object> target);
static void Initialize(v8::Handle<v8::Object> target);
protected:
void HmacInit(const char* hash_type, const char* key, int key_len);
@ -363,7 +363,7 @@ class Hmac : public ObjectWrap {
class Hash : public ObjectWrap {
public:
static void Initialize (v8::Handle<v8::Object> target);
static void Initialize(v8::Handle<v8::Object> target);
bool HashInit(const char* hash_type);
bool HashUpdate(const char* data, int len);
@ -420,7 +420,7 @@ class Sign : public ObjectWrap {
class Verify : public ObjectWrap {
public:
static void Initialize (v8::Handle<v8::Object> target);
static void Initialize(v8::Handle<v8::Object> target);
void VerifyInit(const char* verify_type);
bool VerifyUpdate(const char* data, int len);
@ -430,7 +430,7 @@ class Verify : public ObjectWrap {
int siglen);
protected:
static void New (const v8::FunctionCallbackInfo<v8::Value>& args);
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
static void VerifyInit(const v8::FunctionCallbackInfo<v8::Value>& args);
static void VerifyUpdate(const v8::FunctionCallbackInfo<v8::Value>& args);
static void VerifyFinal(const v8::FunctionCallbackInfo<v8::Value>& args);
@ -447,7 +447,6 @@ class Verify : public ObjectWrap {
EVP_MD_CTX mdctx_; /* coverity[member_decl] */
const EVP_MD* md_; /* coverity[member_decl] */
bool initialised_;
};
class DiffieHellman : public ObjectWrap {

88
src/node_crypto_bio.cc

@ -133,49 +133,49 @@ long NodeBIO::Ctrl(BIO* bio, int cmd, long num, void* ptr) {
ret = 1;
switch (cmd) {
case BIO_CTRL_RESET:
nbio->Reset();
break;
case BIO_CTRL_EOF:
ret = nbio->Length() == 0;
break;
case BIO_C_SET_BUF_MEM_EOF_RETURN:
bio->num = num;
break;
case BIO_CTRL_INFO:
ret = nbio->Length();
if (ptr != NULL)
*reinterpret_cast<void**>(ptr) = NULL;
break;
case BIO_C_SET_BUF_MEM:
assert(0 && "Can't use SET_BUF_MEM_PTR with NodeBIO");
abort();
break;
case BIO_C_GET_BUF_MEM_PTR:
assert(0 && "Can't use GET_BUF_MEM_PTR with NodeBIO");
ret = 0;
break;
case BIO_CTRL_GET_CLOSE:
ret = bio->shutdown;
break;
case BIO_CTRL_SET_CLOSE:
bio->shutdown = num;
break;
case BIO_CTRL_WPENDING:
ret = 0;
break;
case BIO_CTRL_PENDING:
ret = nbio->Length();
break;
case BIO_CTRL_DUP:
case BIO_CTRL_FLUSH:
ret = 1;
break;
case BIO_CTRL_PUSH:
case BIO_CTRL_POP:
default:
ret = 0;
break;
case BIO_CTRL_RESET:
nbio->Reset();
break;
case BIO_CTRL_EOF:
ret = nbio->Length() == 0;
break;
case BIO_C_SET_BUF_MEM_EOF_RETURN:
bio->num = num;
break;
case BIO_CTRL_INFO:
ret = nbio->Length();
if (ptr != NULL)
*reinterpret_cast<void**>(ptr) = NULL;
break;
case BIO_C_SET_BUF_MEM:
assert(0 && "Can't use SET_BUF_MEM_PTR with NodeBIO");
abort();
break;
case BIO_C_GET_BUF_MEM_PTR:
assert(0 && "Can't use GET_BUF_MEM_PTR with NodeBIO");
ret = 0;
break;
case BIO_CTRL_GET_CLOSE:
ret = bio->shutdown;
break;
case BIO_CTRL_SET_CLOSE:
bio->shutdown = num;
break;
case BIO_CTRL_WPENDING:
ret = 0;
break;
case BIO_CTRL_PENDING:
ret = nbio->Length();
break;
case BIO_CTRL_DUP:
case BIO_CTRL_FLUSH:
ret = 1;
break;
case BIO_CTRL_PUSH:
case BIO_CTRL_POP:
default:
ret = 0;
break;
}
return ret;
}
@ -387,4 +387,4 @@ NodeBIO::~NodeBIO() {
write_head_ = NULL;
}
} // namespace node
} // namespace node

7
src/node_crypto_bio.h

@ -19,6 +19,9 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef SRC_NODE_CRYPTO_BIO_H_
#define SRC_NODE_CRYPTO_BIO_H_
#include "openssl/bio.h"
#include <assert.h>
@ -110,4 +113,6 @@ class NodeBIO {
static BIO_METHOD method_;
};
} // namespace node
} // namespace node
#endif // SRC_NODE_CRYPTO_BIO_H_

25
src/node_crypto_groups.h

@ -1,3 +1,26 @@
// 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.
#ifndef SRC_NODE_CRYPTO_GROUPS_H_
#define SRC_NODE_CRYPTO_GROUPS_H_
/*
These modular groups were literally taken from:
@ -385,3 +408,5 @@ static const modp_group modp_groups[] = {
{ "modp18", V(group_modp18), sizeof(group_modp18), V(two_generator), 1 }
#undef V
};
#endif // SRC_NODE_CRYPTO_GROUPS_H_

2
src/node_dtrace.cc

@ -347,4 +347,4 @@ void InitDTrace(Handle<Object> target) {
#endif
}
}
} // namespace node

39
src/node_dtrace.h

@ -19,14 +19,13 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef NODE_DTRACE_H_
#define NODE_DTRACE_H_
#ifndef SRC_NODE_DTRACE_H_
#define SRC_NODE_DTRACE_H_
#include "node.h"
#include "v8.h"
extern "C" {
/*
* The following structures are passed directly to DTrace when probes are fired.
* Translators in node.d translate these structures into the corresponding D
@ -36,15 +35,15 @@ extern "C" {
*/
typedef struct {
int32_t fd;
int32_t port;
char *remote;
int32_t buffered;
int32_t fd;
int32_t port;
char* remote;
int32_t buffered;
} node_dtrace_connection_t;
typedef struct {
char *url;
char *method;
char* url;
char* method;
} node_dtrace_http_client_request_t;
/*
@ -61,22 +60,22 @@ typedef struct {
* a field is present by checking it against NULL.
*/
typedef struct {
union {
uint32_t version;
uintptr_t unused; /* for compat. with old 64-bit struct */
} _un;
char *url;
char *method;
char *forwardedFor;
char *_pad[8];
union {
uint32_t version;
uintptr_t unused; /* for compat. with old 64-bit struct */
} _un;
char* url;
char* method;
char* forwardedFor;
char* _pad[8];
} node_dtrace_http_server_request_t;
}
} // extern "C"
namespace node {
void InitDTrace(v8::Handle<v8::Object> target);
}
} // namespace node
#endif
#endif // SRC_NODE_DTRACE_H_

10
src/node_extensions.cc

@ -22,6 +22,7 @@
#include "node.h"
#include "node_version.h"
#include "node_extensions.h"
#include <string.h>
#include <stdio.h>
@ -33,7 +34,7 @@
#define NODE_EXT_LIST_ITEM NODE_MODULE_DECL
#define NODE_EXT_LIST_END
#include "node_extensions.h"
NODE_EXT_LIST(NODE_EXT_LIST_START, NODE_EXT_LIST_ITEM, NODE_EXT_LIST_END)
#undef NODE_EXT_LIST_START
#undef NODE_EXT_LIST_ITEM
@ -44,12 +45,11 @@
#define NODE_EXT_LIST_ITEM NODE_EXT_STRING
#define NODE_EXT_LIST_END NULL};
#include "node_extensions.h"
NODE_EXT_LIST(NODE_EXT_LIST_START, NODE_EXT_LIST_ITEM, NODE_EXT_LIST_END)
namespace node {
node_module_struct* get_builtin_module(const char *name)
{
node_module_struct* get_builtin_module(const char *name) {
char buf[128];
node_module_struct *cur = NULL;
snprintf(buf, sizeof(buf), "node_%s", name);
@ -65,4 +65,4 @@ node_module_struct* get_builtin_module(const char *name)
return NULL;
}
}; // namespace node
} // namespace node

57
src/node_extensions.h

@ -19,28 +19,39 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
NODE_EXT_LIST_START
NODE_EXT_LIST_ITEM(node_buffer)
#if HAVE_OPENSSL
NODE_EXT_LIST_ITEM(node_crypto)
NODE_EXT_LIST_ITEM(node_tls_wrap)
#endif
NODE_EXT_LIST_ITEM(node_evals)
NODE_EXT_LIST_ITEM(node_fs)
NODE_EXT_LIST_ITEM(node_http_parser)
NODE_EXT_LIST_ITEM(node_os)
NODE_EXT_LIST_ITEM(node_smalloc)
NODE_EXT_LIST_ITEM(node_zlib)
#ifndef SRC_NODE_EXTENSIONS_H_
#define SRC_NODE_EXTENSIONS_H_
NODE_EXT_LIST_ITEM(node_uv)
NODE_EXT_LIST_ITEM(node_timer_wrap)
NODE_EXT_LIST_ITEM(node_tcp_wrap)
NODE_EXT_LIST_ITEM(node_udp_wrap)
NODE_EXT_LIST_ITEM(node_pipe_wrap)
NODE_EXT_LIST_ITEM(node_cares_wrap)
NODE_EXT_LIST_ITEM(node_tty_wrap)
NODE_EXT_LIST_ITEM(node_process_wrap)
NODE_EXT_LIST_ITEM(node_fs_event_wrap)
NODE_EXT_LIST_ITEM(node_signal_wrap)
#ifdef HAVE_OPENSSL
# define NODE_EXT_LIST_SSL(ITEM) \
ITEM(node_crypto) \
ITEM(node_tls_wrap)
#else
# define NODE_EXT_LIST_SSL(ITEM)
#endif // HAVE_OPENSSL
NODE_EXT_LIST_END
#define NODE_EXT_LIST(START, ITEM, END) \
START \
ITEM(node_buffer) \
NODE_EXT_LIST_SSL(ITEM) \
ITEM(node_evals) \
ITEM(node_fs) \
ITEM(node_http_parser) \
ITEM(node_os) \
ITEM(node_smalloc) \
ITEM(node_zlib) \
\
ITEM(node_uv) \
ITEM(node_timer_wrap) \
ITEM(node_tcp_wrap) \
ITEM(node_udp_wrap) \
ITEM(node_pipe_wrap) \
ITEM(node_cares_wrap) \
ITEM(node_tty_wrap) \
ITEM(node_process_wrap) \
ITEM(node_fs_event_wrap) \
ITEM(node_signal_wrap) \
\
END \
#endif // SRC_NODE_EXTENSIONS_H_

20
src/node_file.cc

@ -55,7 +55,7 @@ using v8::Persistent;
using v8::String;
using v8::Value;
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define TYPE_ERROR(msg) ThrowTypeError(msg)
@ -63,13 +63,13 @@ using v8::Value;
class FSReqWrap: public ReqWrap<uv_fs_t> {
public:
FSReqWrap(const char* syscall)
explicit FSReqWrap(const char* syscall)
: must_free_(false),
syscall_(syscall) {
}
const char* syscall() { return syscall_; }
bool must_free_; // request is responsible for free'ing memory oncomplete
bool must_free_; // request is responsible for free'ing memory oncomplete
private:
const char* syscall_;
@ -98,7 +98,7 @@ static inline int IsInt64(double x) {
static void After(uv_fs_t *req) {
HandleScope scope(node_isolate);
FSReqWrap* req_wrap = (FSReqWrap*) req->data;
FSReqWrap* req_wrap = reinterpret_cast<FSReqWrap*>(req->data);
assert(&req_wrap->req_ == req);
// check if data needs to be cleaned
@ -833,13 +833,13 @@ static void Read(const FunctionCallbackInfo<Value>& args) {
static void Chmod(const FunctionCallbackInfo<Value>& args) {
HandleScope scope(node_isolate);
if(args.Length() < 2 || !args[0]->IsString() || !args[1]->IsInt32()) {
if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsInt32()) {
return THROW_BAD_ARGS;
}
String::Utf8Value path(args[0]);
int mode = static_cast<int>(args[1]->Int32Value());
if(args[2]->IsFunction()) {
if (args[2]->IsFunction()) {
ASYNC_CALL(chmod, args[2], *path, mode);
} else {
SYNC_CALL(chmod, *path, *path, mode);
@ -853,13 +853,13 @@ static void Chmod(const FunctionCallbackInfo<Value>& args) {
static void FChmod(const FunctionCallbackInfo<Value>& args) {
HandleScope scope(node_isolate);
if(args.Length() < 2 || !args[0]->IsInt32() || !args[1]->IsInt32()) {
if (args.Length() < 2 || !args[0]->IsInt32() || !args[1]->IsInt32()) {
return THROW_BAD_ARGS;
}
int fd = args[0]->Int32Value();
int mode = static_cast<int>(args[1]->Int32Value());
if(args[2]->IsFunction()) {
if (args[2]->IsFunction()) {
ASYNC_CALL(fchmod, args[2], fd, mode);
} else {
SYNC_CALL(fchmod, 0, fd, mode);
@ -989,11 +989,11 @@ void File::Initialize(Handle<Object> target) {
NODE_SET_METHOD(target, "chmod", Chmod);
NODE_SET_METHOD(target, "fchmod", FChmod);
//NODE_SET_METHOD(target, "lchmod", LChmod);
// NODE_SET_METHOD(target, "lchmod", LChmod);
NODE_SET_METHOD(target, "chown", Chown);
NODE_SET_METHOD(target, "fchown", FChown);
//NODE_SET_METHOD(target, "lchown", LChown);
// NODE_SET_METHOD(target, "lchown", LChown);
NODE_SET_METHOD(target, "utimes", UTimes);
NODE_SET_METHOD(target, "futimes", FUTimes);

7
src/node_file.h

@ -19,8 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef SRC_FILE_H_
#define SRC_FILE_H_
#ifndef SRC_NODE_FILE_H_
#define SRC_NODE_FILE_H_
#include "node.h"
#include "v8.h"
@ -35,4 +35,5 @@ class File {
void InitFs(v8::Handle<v8::Object> target);
} // namespace node
#endif // SRC_FILE_H_
#endif // SRC_NODE_FILE_H_

19
src/node_http_parser.cc

@ -161,7 +161,7 @@ struct StringPtr {
str_ = str;
else if (on_heap_ || str_ + size_ != str) {
// Non-consecutive input, make a copy on the heap.
// TODO Use slab allocation, O(n) allocs is bad.
// TODO(bnoordhuis) Use slab allocation, O(n) allocs is bad.
char* s = new char[size_ + size];
memcpy(s, str_, size_);
memcpy(s + size_, str, size);
@ -192,8 +192,8 @@ struct StringPtr {
class Parser : public ObjectWrap {
public:
Parser(enum http_parser_type type) : ObjectWrap() {
public:
explicit Parser(enum http_parser_type type) : ObjectWrap() {
Init(type);
}
@ -228,7 +228,7 @@ public:
fields_[num_fields_ - 1].Reset();
}
assert(num_fields_ < (int)ARRAY_SIZE(fields_));
assert(num_fields_ < static_cast<int>(ARRAY_SIZE(fields_)));
assert(num_fields_ == num_values_ + 1);
fields_[num_fields_ - 1].Update(at, length);
@ -244,7 +244,7 @@ public:
values_[num_values_ - 1].Reset();
}
assert(num_values_ < (int)ARRAY_SIZE(values_));
assert(num_values_ < static_cast<int>(ARRAY_SIZE(values_)));
assert(num_values_ == num_fields_);
values_[num_values_ - 1].Update(at, length);
@ -265,8 +265,7 @@ public:
if (have_flushed_) {
// Slow case, flush remaining headers.
Flush();
}
else {
} else {
// Fast case, pass headers and URL to JS land.
message_info->Set(headers_sym, CreateHeaders());
if (parser_.type == HTTP_REQUEST)
@ -342,7 +341,7 @@ public:
HandleScope scope(node_isolate);
if (num_fields_)
Flush(); // Flush trailing HTTP headers.
Flush(); // Flush trailing HTTP headers.
Local<Object> obj = handle(node_isolate);
Local<Value> cb = obj->Get(on_message_complete_sym);
@ -430,7 +429,7 @@ public:
Local<Integer> nparsed_obj = Integer::New(nparsed, node_isolate);
// If there was a parse error in one of the callbacks
// TODO What if there is an error on EOF?
// TODO(bnoordhuis) What if there is an error on EOF?
if (!parser->parser_.upgrade && nparsed != buffer_len) {
enum http_errno err = HTTP_PARSER_ERRNO(&parser->parser_);
@ -481,7 +480,7 @@ public:
}
private:
private:
Local<Array> CreateHeaders() {
// num_values_ is either -1 or the entry # of the last header

8
src/node_http_parser.h

@ -19,8 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef NODE_HTTP_PARSER
#define NODE_HTTP_PARSER
#ifndef SRC_NODE_HTTP_PARSER_H_
#define SRC_NODE_HTTP_PARSER_H_
#include "v8.h"
@ -30,6 +30,6 @@ namespace node {
void InitHttpParser(v8::Handle<v8::Object> target);
}
} // namespace node
#endif // NODE_HTTP_PARSER
#endif // SRC_NODE_HTTP_PARSER_H_

42
src/node_internals.h

@ -39,12 +39,12 @@ extern v8::Persistent<v8::Object> process_p;
template <typename TypeName>
class CachedBase {
public:
public:
CachedBase();
operator v8::Handle<TypeName>() const;
void operator=(v8::Handle<TypeName> that); // Can only assign once.
bool IsEmpty() const;
private:
private:
CachedBase(const CachedBase&);
void operator=(const CachedBase&);
v8::Persistent<TypeName> handle_;
@ -52,14 +52,14 @@ private:
template <typename TypeName>
class Cached : public CachedBase<TypeName> {
public:
public:
operator v8::Handle<v8::Value>() const;
void operator=(v8::Handle<TypeName> that);
};
template <>
class Cached<v8::Value> : public CachedBase<v8::Value> {
public:
public:
operator v8::Handle<v8::Value>() const;
void operator=(v8::Handle<v8::Value> that);
};
@ -93,12 +93,14 @@ v8::Handle<v8::Value> MakeCallback(
int argc,
v8::Handle<v8::Value>* argv);
inline bool HasInstance(v8::Persistent<v8::FunctionTemplate>& function_template,
v8::Handle<v8::Value> value);
inline bool HasInstance(
const v8::Persistent<v8::FunctionTemplate>& function_template,
v8::Handle<v8::Value> value);
inline v8::Local<v8::Object> NewInstance(v8::Persistent<v8::Function>& ctor,
int argc = 0,
v8::Handle<v8::Value>* argv = NULL);
inline v8::Local<v8::Object> NewInstance(
const v8::Persistent<v8::Function>& ctor,
int argc = 0,
v8::Handle<v8::Value>* argv = NULL);
// Convert a struct sockaddr to a { address: '1.2.3.4', port: 1234 } JS object.
// Sets address and port properties on the info object and returns it.
@ -131,12 +133,14 @@ inline static int snprintf(char* buf, unsigned int len, const char* fmt, ...) {
// g++ in strict mode complains loudly about the system offsetof() macro
// because it uses NULL as the base address.
# define offset_of(type, member) \
((intptr_t) ((char *) &(((type *) 8)->member) - 8))
(reinterpret_cast<intptr_t>( \
reinterpret_cast<char*>(&(reinterpret_cast<type*>(8)->member)) - 8))
#endif
#ifndef container_of
# define container_of(ptr, type, member) \
((type *) ((char *) (ptr) - offset_of(type, member)))
(reinterpret_cast<type*>(reinterpret_cast<char*>(ptr) - \
offset_of(type, member)))
#endif
#ifndef ARRAY_SIZE
@ -324,20 +328,22 @@ v8::Handle<v8::Value> MakeCallback(
return MakeCallback(recv, handle, argc, argv);
}
inline bool HasInstance(v8::Persistent<v8::FunctionTemplate>& function_template,
v8::Handle<v8::Value> value) {
inline bool HasInstance(
const v8::Persistent<v8::FunctionTemplate>& function_template,
v8::Handle<v8::Value> value) {
v8::Local<v8::FunctionTemplate> function_template_handle =
PersistentToLocal(function_template);
return function_template_handle->HasInstance(value);
}
inline v8::Local<v8::Object> NewInstance(v8::Persistent<v8::Function>& ctor,
int argc,
v8::Handle<v8::Value>* argv) {
inline v8::Local<v8::Object> NewInstance(
const v8::Persistent<v8::Function>& ctor,
int argc,
v8::Handle<v8::Value>* argv) {
v8::Local<v8::Function> constructor_handle = PersistentToLocal(ctor);
return constructor_handle->NewInstance(argc, argv);
}
} // namespace node
} // namespace node
#endif // SRC_NODE_INTERNALS_H_
#endif // SRC_NODE_INTERNALS_H_

12
src/node_javascript.cc

@ -28,22 +28,26 @@
#include <strings.h>
#endif
using namespace v8;
namespace node {
using v8::Handle;
using v8::HandleScope;
using v8::Local;
using v8::Object;
using v8::String;
Handle<String> MainSource() {
return String::New(node_native, sizeof(node_native) - 1);
}
void DefineJavaScript(v8::Handle<v8::Object> target) {
void DefineJavaScript(Handle<Object> target) {
HandleScope scope(node_isolate);
for (int i = 0; natives[i].name; i++) {
if (natives[i].source != node_native) {
Local<String> name = String::New(natives[i].name);
Handle<String> source = String::New(natives[i].source,
natives[i].source_len);
natives[i].source_len);
target->Set(name, source);
}
}

5
src/node_javascript.h

@ -19,6 +19,9 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef SRC_NODE_JAVASCRIPT_H_
#define SRC_NODE_JAVASCRIPT_H_
#include "v8.h"
namespace node {
@ -27,3 +30,5 @@ void DefineJavaScript(v8::Handle<v8::Object> target);
v8::Handle<v8::String> MainSource();
} // namespace node
#endif // SRC_NODE_JAVASCRIPT_H_

14
src/node_object_wrap.h

@ -19,8 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef object_wrap_h
#define object_wrap_h
#ifndef SRC_NODE_OBJECT_WRAP_H_
#define SRC_NODE_OBJECT_WRAP_H_
#include "node.h"
#include "v8.h"
@ -38,7 +38,7 @@
namespace node {
class NODE_EXTERN ObjectWrap {
public:
public:
ObjectWrap() {
refs_ = 0;
}
@ -75,7 +75,7 @@ public:
}
protected:
protected:
inline void Wrap(v8::Handle<v8::Object> handle) {
assert(persistent().IsEmpty());
assert(handle->InternalFieldCount() > 0);
@ -118,7 +118,7 @@ protected:
int refs_; // ro
private:
private:
static void WeakCallback(v8::Isolate* isolate,
v8::Persistent<v8::Object>* pobj,
ObjectWrap* wrap) {
@ -132,6 +132,6 @@ private:
v8::Persistent<v8::Object> handle_;
};
} // namespace node
} // namespace node
#endif // object_wrap_h
#endif // SRC_NODE_OBJECT_WRAP_H_

28
src/node_os.cc

@ -30,19 +30,19 @@
#ifdef __MINGW32__
# include <io.h>
#endif
#endif // __MINGW32__
#ifdef __POSIX__
# include <netdb.h> // MAXHOSTNAMELEN on Solaris.
# include <unistd.h> // gethostname, sysconf
# include <sys/param.h> // MAXHOSTNAMELEN on Linux and the BSDs.
# include <sys/utsname.h>
#endif
#endif // __MINGW32__
// Add Windows fallback.
#ifndef MAXHOSTNAMELEN
# define MAXHOSTNAMELEN 256
#endif
#endif // MAXHOSTNAMELEN
namespace node {
@ -70,9 +70,9 @@ static void GetHostname(const FunctionCallbackInfo<Value>& args) {
if (gethostname(buf, sizeof(buf))) {
#ifdef __POSIX__
int errorno = errno;
#else // __MINGW32__
#else // __MINGW32__
int errorno = WSAGetLastError();
#endif // __MINGW32__
#endif // __POSIX__
return ThrowErrnoException(errorno, "gethostname");
}
buf[sizeof(buf) - 1] = '\0';
@ -91,9 +91,9 @@ static void GetOSType(const FunctionCallbackInfo<Value>& args) {
return ThrowErrnoException(errno, "uname");
}
rval = info.sysname;
#else // __MINGW32__
#else // __MINGW32__
rval ="Windows_NT";
#endif
#endif // __POSIX__
args.GetReturnValue().Set(String::New(rval));
}
@ -109,17 +109,21 @@ static void GetOSRelease(const FunctionCallbackInfo<Value>& args) {
return ThrowErrnoException(errno, "uname");
}
rval = info.release;
#else // __MINGW32__
#else // __MINGW32__
char release[256];
OSVERSIONINFO info;
info.dwOSVersionInfoSize = sizeof(info);
if (GetVersionEx(&info) == 0) return;
sprintf(release, "%d.%d.%d", static_cast<int>(info.dwMajorVersion),
static_cast<int>(info.dwMinorVersion), static_cast<int>(info.dwBuildNumber));
snprintf(release,
sizeof(release),
"%d.%d.%d",
static_cast<int>(info.dwMajorVersion),
static_cast<int>(info.dwMinorVersion),
static_cast<int>(info.dwBuildNumber));
rval = release;
#endif
#endif // __POSIX__
args.GetReturnValue().Set(String::New(rval));
}
@ -225,7 +229,7 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
}
if (interfaces[i].address.address4.sin_family == AF_INET) {
uv_ip4_name(&interfaces[i].address.address4,ip, sizeof(ip));
uv_ip4_name(&interfaces[i].address.address4, ip, sizeof(ip));
uv_ip4_name(&interfaces[i].netmask.netmask4, netmask, sizeof(netmask));
family = String::New("IPv4");
} else if (interfaces[i].address.address4.sin_family == AF_INET6) {

11
src/node_os.h

@ -19,8 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef node_os_h
#define node_os_h
#ifndef SRC_NODE_OS_H_
#define SRC_NODE_OS_H_
#include "node.h"
#include "v8.h"
@ -28,11 +28,10 @@
namespace node {
class OS {
public:
static void Initialize (v8::Handle<v8::Object> target);
public:
static void Initialize(v8::Handle<v8::Object> target);
};
} // namespace node
#endif // node_os_h
#endif // SRC_NODE_OS_H_

5
src/node_script.cc

@ -310,9 +310,8 @@ void WrappedScript::EvalMachine(const FunctionCallbackInfo<Value>& args) {
}
const int sandbox_index = input_flag == compileCode ? 1 : 0;
if (context_flag == userContext
&& !WrappedContext::InstanceOf(args[sandbox_index]))
{
if (context_flag == userContext &&
!WrappedContext::InstanceOf(args[sandbox_index])) {
return ThrowTypeError("needs a 'context' argument.");
}

10
src/node_script.h

@ -19,8 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef node_script_h
#define node_script_h
#ifndef SRC_NODE_SCRIPT_H_
#define SRC_NODE_SCRIPT_H_
#include "node.h"
#include "node_object_wrap.h"
@ -29,8 +29,8 @@
namespace node {
void InitEvals(v8::Handle<v8::Object> target);
} // namespace node
#endif // node_script_h
} // namespace node
#endif // SRC_NODE_SCRIPT_H_

8
src/node_stat_watcher.cc

@ -60,10 +60,8 @@ static void Delete(uv_handle_t* handle) {
}
StatWatcher::StatWatcher()
: ObjectWrap()
, watcher_(new uv_fs_poll_t)
{
StatWatcher::StatWatcher() : ObjectWrap(),
watcher_(new uv_fs_poll_t) {
uv_fs_poll_init(uv_default_loop(), watcher_);
watcher_->data = static_cast<void*>(this);
}
@ -130,7 +128,7 @@ void StatWatcher::Stop(const FunctionCallbackInfo<Value>& args) {
}
void StatWatcher::Stop () {
void StatWatcher::Stop() {
if (!uv_is_active(reinterpret_cast<uv_handle_t*>(watcher_))) return;
uv_fs_poll_stop(watcher_);
Unref();

6
src/node_stat_watcher.h

@ -19,8 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef NODE_STAT_WATCHER_H_
#define NODE_STAT_WATCHER_H_
#ifndef SRC_NODE_STAT_WATCHER_H_
#define SRC_NODE_STAT_WATCHER_H_
#include "node.h"
#include "uv.h"
@ -52,4 +52,4 @@ class StatWatcher : ObjectWrap {
};
} // namespace node
#endif // NODE_STAT_WATCHER_H_
#endif // SRC_NODE_STAT_WATCHER_H_

9
src/node_version.h

@ -19,8 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef NODE_VERSION_H
#define NODE_VERSION_H
#ifndef SRC_NODE_VERSION_H_
#define SRC_NODE_VERSION_H_
#define NODE_MAJOR_VERSION 0
#define NODE_MINOR_VERSION 11
@ -55,7 +55,8 @@
#define NODE_VERSION_AT_LEAST(major, minor, patch) \
(( (major) < NODE_MAJOR_VERSION) \
|| ((major) == NODE_MAJOR_VERSION && (minor) < NODE_MINOR_VERSION) \
|| ((major) == NODE_MAJOR_VERSION && (minor) == NODE_MINOR_VERSION && (patch) <= NODE_PATCH_VERSION))
|| ((major) == NODE_MAJOR_VERSION && \
(minor) == NODE_MINOR_VERSION && (patch) <= NODE_PATCH_VERSION))
/**
* When this version number is changed, node.js will refuse
@ -65,4 +66,4 @@
*/
#define NODE_MODULE_VERSION 0x000C /* v0.12 */
#endif /* NODE_VERSION_H */
#endif /* SRC_NODE_VERSION_H_ */

5
src/node_watchdog.cc

@ -27,10 +27,7 @@ namespace node {
using v8::V8;
Watchdog::Watchdog(uint64_t ms)
: thread_created_(false)
, destroyed_(false) {
Watchdog::Watchdog(uint64_t ms) : thread_created_(false), destroyed_(false) {
loop_ = uv_loop_new();
if (!loop_)
return;

2
src/node_watchdog.h

@ -29,7 +29,7 @@ namespace node {
class Watchdog {
public:
Watchdog(uint64_t ms);
explicit Watchdog(uint64_t ms);
~Watchdog();
void Dispose();

28
src/node_win32_etw_provider-inl.h

@ -19,16 +19,14 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef SRC_ETW_INL_H_
#define SRC_ETW_INL_H_
#ifndef SRC_NODE_WIN32_ETW_PROVIDER_INL_H_
#define SRC_NODE_WIN32_ETW_PROVIDER_INL_H_
#include "node_win32_etw_provider.h"
#include "node_etw_provider.h"
namespace node {
using namespace v8;
// From node_win32_etw_provider.cc
extern REGHANDLE node_provider;
extern EventWriteFunc event_write;
@ -37,7 +35,7 @@ extern int events_enabled;
#define ETW_WRITE_STRING_DATA(data_descriptor, data) \
EventDataDescCreate(data_descriptor, \
data, \
(strlen(data) + 1) * sizeof(char));
(strlen(data) + 1) * sizeof(*data));
#define ETW_WRITE_INT32_DATA(data_descriptor, data) \
EventDataDescCreate(data_descriptor, data, sizeof(int32_t));
@ -106,7 +104,8 @@ extern int events_enabled;
#define ETW_WRITE_EVENT(eventDescriptor, dataDescriptors) \
DWORD status = event_write(node_provider, \
&eventDescriptor, \
sizeof(dataDescriptors)/sizeof(*dataDescriptors),\
sizeof(dataDescriptors) / \
sizeof(*dataDescriptors), \
dataDescriptors); \
assert(status == ERROR_SUCCESS);
@ -163,7 +162,7 @@ void NODE_NET_STREAM_END(node_dtrace_connection_t* conn,
}
void NODE_GC_START(GCType type, GCCallbackFlags flags) {
void NODE_GC_START(v8::GCType type, v8::GCCallbackFlags flags) {
if (events_enabled > 0) {
EVENT_DATA_DESCRIPTOR descriptors[2];
ETW_WRITE_GC(descriptors, type, flags);
@ -172,7 +171,7 @@ void NODE_GC_START(GCType type, GCCallbackFlags flags) {
}
void NODE_GC_DONE(GCType type, GCCallbackFlags flags) {
void NODE_GC_DONE(v8::GCType type, v8::GCCallbackFlags flags) {
if (events_enabled > 0) {
EVENT_DATA_DESCRIPTOR descriptors[2];
ETW_WRITE_GC(descriptors, type, flags);
@ -221,7 +220,12 @@ void NODE_V8SYMBOL_ADD(LPCSTR symbol,
if (symbol == NULL) {
SETSYMBUF(L"NULL");
} else {
symbol_len = MultiByteToWideChar(CP_ACP, 0, symbol, symbol_len, symbuf, 128);
symbol_len = MultiByteToWideChar(CP_ACP,
0,
symbol,
symbol_len,
symbuf,
128);
if (symbol_len == 0) {
SETSYMBUF(L"Invalid");
} else {
@ -267,5 +271,7 @@ bool NODE_NET_STREAM_END_ENABLED() { return events_enabled > 0; }
bool NODE_NET_SOCKET_READ_ENABLED() { return events_enabled > 0; }
bool NODE_NET_SOCKET_WRITE_ENABLED() { return events_enabled > 0; }
bool NODE_V8SYMBOL_ENABLED() { return events_enabled > 0; }
}
#endif // SRC_ETW_INL_H_
} // namespace node
#endif // SRC_NODE_WIN32_ETW_PROVIDER_INL_H_

2
src/node_win32_etw_provider.cc

@ -26,8 +26,6 @@
namespace node {
using namespace v8;
HMODULE advapi;
REGHANDLE node_provider;
EventRegisterFunc event_register;

15
src/node_win32_etw_provider.h

@ -19,16 +19,14 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef SRC_ETW_H_
#define SRC_ETW_H_
#ifndef SRC_NODE_WIN32_ETW_PROVIDER_H_
#define SRC_NODE_WIN32_ETW_PROVIDER_H_
#include <evntprov.h>
#include "node_dtrace.h"
namespace node {
using namespace v8;
#if defined(_MSC_VER)
# define INLINE __forceinline
#else
@ -70,8 +68,8 @@ INLINE void NODE_NET_SERVER_CONNECTION(node_dtrace_connection_t* conn,
const char *remote, int port, int fd);
INLINE void NODE_NET_STREAM_END(node_dtrace_connection_t* conn,
const char *remote, int port, int fd);
INLINE void NODE_GC_START(GCType type, GCCallbackFlags flags);
INLINE void NODE_GC_DONE(GCType type, GCCallbackFlags flags);
INLINE void NODE_GC_START(v8::GCType type, v8::GCCallbackFlags flags);
INLINE void NODE_GC_DONE(v8::GCType type, v8::GCCallbackFlags flags);
INLINE void NODE_V8SYMBOL_REMOVE(const void* addr1, const void* addr2);
INLINE void NODE_V8SYMBOL_MOVE(const void* addr1, const void* addr2);
INLINE void NODE_V8SYMBOL_RESET();
@ -92,5 +90,6 @@ INLINE bool NODE_V8SYMBOL_ENABLED();
#define NODE_NET_SOCKET_READ(arg0, arg1)
#define NODE_NET_SOCKET_WRITE(arg0, arg1)
}
#endif // SRC_ETW_H_
} // namespace node
#endif // SRC_NODE_WIN32_ETW_PROVIDER_H_

36
src/node_win32_perfctr_provider.cc

@ -29,72 +29,61 @@
typedef ULONG (WINAPI *PerfStartProviderExFunc)(
__in LPGUID ProviderGuid,
__in_opt PPERF_PROVIDER_CONTEXT ProviderContext,
__out PHANDLE Provider
);
__out PHANDLE Provider);
typedef ULONG (WINAPI *PerfStopProviderFunc)(
__in HANDLE ProviderHandle
);
__in HANDLE ProviderHandle);
typedef ULONG (WINAPI *PerfSetCounterSetInfoFunc)(
__in HANDLE ProviderHandle,
__inout_bcount(TemplateSize) PPERF_COUNTERSET_INFO Template,
__in ULONG TemplateSize
);
__in ULONG TemplateSize);
typedef PPERF_COUNTERSET_INSTANCE (WINAPI *PerfCreateInstanceFunc)(
__in HANDLE ProviderHandle,
__in LPCGUID CounterSetGuid,
__in PCWSTR Name,
__in ULONG Id
);
__in ULONG Id);
typedef ULONG (WINAPI *PerfDeleteInstanceFunc)(
__in HANDLE Provider,
__in PPERF_COUNTERSET_INSTANCE InstanceBlock
);
__in PPERF_COUNTERSET_INSTANCE InstanceBlock);
typedef ULONG (WINAPI *PerfSetULongCounterValueFunc)(
__in HANDLE Provider,
__inout PPERF_COUNTERSET_INSTANCE Instance,
__in ULONG CounterId,
__in ULONG Value
);
__in ULONG Value);
typedef ULONG (WINAPI *PerfSetULongLongCounterValueFunc)(
__in HANDLE Provider,
__inout PPERF_COUNTERSET_INSTANCE Instance,
__in ULONG CounterId,
__in ULONGLONG Value
);
__in ULONGLONG Value);
typedef ULONG (WINAPI *PerfIncrementULongCounterValueFunc)(
__in HANDLE Provider,
__inout PPERF_COUNTERSET_INSTANCE Instance,
__in ULONG CounterId,
__in ULONG Value
);
__in ULONG Value);
typedef ULONG (WINAPI *PerfIncrementULongLongCounterValueFunc)(
__in HANDLE Provider,
__inout PPERF_COUNTERSET_INSTANCE Instance,
__in ULONG CounterId,
__in ULONGLONG Value
);
__in ULONGLONG Value);
typedef ULONG (WINAPI *PerfDecrementULongCounterValueFunc)(
__in HANDLE Provider,
__inout PPERF_COUNTERSET_INSTANCE Instance,
__in ULONG CounterId,
__in ULONG Value
);
__in ULONG Value);
typedef ULONG (WINAPI *PerfDecrementULongLongCounterValueFunc)(
__in HANDLE Provider,
__inout PPERF_COUNTERSET_INSTANCE Instance,
__in ULONG CounterId,
__in ULONGLONG Value
);
__in ULONGLONG Value);
HMODULE advapimod;
@ -341,5 +330,4 @@ void NODE_COUNT_PIPE_BYTES_RECV(int bytes) {
}
}
}
} // namespace node

9
src/node_win32_perfctr_provider.h

@ -19,8 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef SRC_WINPERFCTRS_H_
#define SRC_WINPERFCTRS_H_
#ifndef SRC_NODE_WIN32_PERFCTR_PROVIDER_H_
#define SRC_NODE_WIN32_PERFCTR_PROVIDER_H_
#if defined(_MSC_VER)
# define INLINE __forceinline
@ -49,7 +49,6 @@ void NODE_COUNT_PIPE_BYTES_RECV(int bytes);
void InitPerfCountersWin32();
void TermPerfCountersWin32();
}
#endif
} // namespace node
#endif // SRC_NODE_WIN32_PERFCTR_PROVIDER_H_

8
src/node_wrap.h

@ -19,8 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef NODE_WRAP_H
#define NODE_WRAP_H
#ifndef SRC_NODE_WRAP_H_
#define SRC_NODE_WRAP_H_
#include "v8.h"
#include "uv.h"
@ -63,6 +63,6 @@ inline uv_stream_t* HandleToStream(v8::Local<v8::Object> obj) {
return NULL;
}
}
} // namespace node
#endif
#endif // SRC_NODE_WRAP_H_

35
src/node_zlib.cc

@ -68,21 +68,19 @@ void InitZlib(v8::Handle<v8::Object> target);
class ZCtx : public ObjectWrap {
public:
ZCtx(node_zlib_mode mode)
: ObjectWrap()
, init_done_(false)
, level_(0)
, windowBits_(0)
, memLevel_(0)
, strategy_(0)
, err_(0)
, dictionary_(NULL)
, dictionary_len_(0)
, flush_(0)
, chunk_size_(0)
, write_in_progress_(false)
, mode_(mode)
{
explicit ZCtx(node_zlib_mode mode) : ObjectWrap(),
init_done_(false),
level_(0),
windowBits_(0),
memLevel_(0),
strategy_(0),
err_(0),
dictionary_(NULL),
dictionary_len_(0),
flush_(0),
chunk_size_(0),
write_in_progress_(false),
mode_(mode) {
}
@ -219,17 +217,14 @@ class ZCtx : public ObjectWrap {
// If data was encoded with dictionary
if (ctx->err_ == Z_NEED_DICT && ctx->dictionary_ != NULL) {
// Load it
ctx->err_ = inflateSetDictionary(&ctx->strm_,
ctx->dictionary_,
ctx->dictionary_len_);
if (ctx->err_ == Z_OK) {
// And try to decode again
ctx->err_ = inflate(&ctx->strm_, ctx->flush_);
} else if (ctx->err_ == Z_DATA_ERROR) {
// Both inflateSetDictionary() and inflate() return Z_DATA_ERROR.
// Make it possible for After() to tell a bad dictionary from bad
// input.
@ -510,8 +505,8 @@ class ZCtx : public ObjectWrap {
}
private:
static const int kDeflateContextSize = 16384; // approximate
static const int kInflateContextSize = 10240; // approximate
static const int kDeflateContextSize = 16384; // approximate
static const int kInflateContextSize = 10240; // approximate
bool init_done_;

18
src/pipe_wrap.cc

@ -49,7 +49,7 @@ static Cached<String> onconnection_sym;
static Cached<String> oncomplete_sym;
// TODO share with TCPWrap?
// TODO(bnoordhuis) share with TCPWrap?
typedef class ReqWrap<uv_connect_t> ConnectWrap;
@ -100,7 +100,9 @@ void PipeWrap::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "shutdown", StreamWrap::Shutdown);
NODE_SET_PROTOTYPE_METHOD(t, "writeBuffer", StreamWrap::WriteBuffer);
NODE_SET_PROTOTYPE_METHOD(t, "writeAsciiString", StreamWrap::WriteAsciiString);
NODE_SET_PROTOTYPE_METHOD(t,
"writeAsciiString",
StreamWrap::WriteAsciiString);
NODE_SET_PROTOTYPE_METHOD(t, "writeUtf8String", StreamWrap::WriteUtf8String);
NODE_SET_PROTOTYPE_METHOD(t, "writeUcs2String", StreamWrap::WriteUcs2String);
@ -134,8 +136,8 @@ void PipeWrap::New(const FunctionCallbackInfo<Value>& args) {
PipeWrap::PipeWrap(Handle<Object> object, bool ipc)
: StreamWrap(object, reinterpret_cast<uv_stream_t*>(&handle_)) {
int r = uv_pipe_init(uv_default_loop(), &handle_, ipc);
assert(r == 0); // How do we proxy this error up to javascript?
// Suggestion: uv_pipe_init() returns void.
assert(r == 0); // How do we proxy this error up to javascript?
// Suggestion: uv_pipe_init() returns void.
UpdateWriteQueueSize();
}
@ -177,7 +179,7 @@ void PipeWrap::Listen(const FunctionCallbackInfo<Value>& args) {
}
// TODO maybe share with TCPWrap?
// TODO(bnoordhuis) maybe share with TCPWrap?
void PipeWrap::OnConnection(uv_stream_t* handle, int status) {
HandleScope scope(node_isolate);
@ -217,10 +219,10 @@ void PipeWrap::OnConnection(uv_stream_t* handle, int status) {
MakeCallback(wrap->object(), onconnection_sym, ARRAY_SIZE(argv), argv);
}
// TODO Maybe share this with TCPWrap?
// TODO(bnoordhuis) Maybe share this with TCPWrap?
void PipeWrap::AfterConnect(uv_connect_t* req, int status) {
ConnectWrap* req_wrap = (ConnectWrap*) req->data;
PipeWrap* wrap = (PipeWrap*) req->handle->data;
ConnectWrap* req_wrap = reinterpret_cast<ConnectWrap*>(req->data);
PipeWrap* wrap = reinterpret_cast<PipeWrap*>(req->handle->data);
HandleScope scope(node_isolate);

6
src/pipe_wrap.h

@ -19,8 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef PIPE_WRAP_H_
#define PIPE_WRAP_H_
#ifndef SRC_PIPE_WRAP_H_
#define SRC_PIPE_WRAP_H_
#include "stream_wrap.h"
namespace node {
@ -57,4 +57,4 @@ class PipeWrap : public StreamWrap {
} // namespace node
#endif // PIPE_WRAP_H_
#endif // SRC_PIPE_WRAP_H_

8
src/process_wrap.cc

@ -75,7 +75,7 @@ class ProcessWrap : public HandleWrap {
new ProcessWrap(args.This());
}
ProcessWrap(Handle<Object> object)
explicit ProcessWrap(Handle<Object> object)
: HandleWrap(object, reinterpret_cast<uv_handle_t*>(&process_)) {
}
@ -158,7 +158,7 @@ class ProcessWrap : public HandleWrap {
return ThrowTypeError("options.gid should be a number");
}
// TODO is this possible to do without mallocing ?
// TODO(bnoordhuis) is this possible to do without mallocing ?
// options.file
Local<Value> file_v = js_options->Get(String::NewSymbol("file"));
@ -195,7 +195,7 @@ class ProcessWrap : public HandleWrap {
if (!env_v.IsEmpty() && env_v->IsArray()) {
Local<Array> env = Local<Array>::Cast(env_v);
int envc = env->Length();
options.env = new char*[envc + 1]; // Heap allocated to detect errors.
options.env = new char*[envc + 1]; // Heap allocated to detect errors.
for (int i = 0; i < envc; i++) {
String::Utf8Value pair(env->Get(i));
options.env[i] = strdup(*pair);
@ -212,7 +212,7 @@ class ProcessWrap : public HandleWrap {
options.flags |= UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS;
}
//options.detached
// options.detached
if (js_options->Get(String::NewSymbol("detached"))->IsTrue()) {
options.flags |= UV_PROCESS_DETACHED;
}

6
src/queue.h

@ -13,8 +13,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef QUEUE_H_
#define QUEUE_H_
#ifndef SRC_QUEUE_H_
#define SRC_QUEUE_H_
typedef void *QUEUE[2];
@ -89,4 +89,4 @@ typedef void *QUEUE[2];
} \
while (0)
#endif /* QUEUE_H_ */
#endif /* SRC_QUEUE_H_ */

10
src/req_wrap.h

@ -19,8 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef REQ_WRAP_H_
#define REQ_WRAP_H_
#ifndef SRC_REQ_WRAP_H_
#define SRC_REQ_WRAP_H_
#include "queue.h"
@ -33,7 +33,7 @@ extern QUEUE req_wrap_queue;
template <typename T>
class ReqWrap {
public:
public:
ReqWrap(v8::Handle<v8::Object> object = v8::Handle<v8::Object>()) {
v8::HandleScope scope(node_isolate);
if (object.IsEmpty()) object = v8::Object::New();
@ -79,11 +79,11 @@ public:
v8::Persistent<v8::Object> object_;
QUEUE req_wrap_queue_;
void* data_;
T req_; // *must* be last, GetActiveRequests() in node.cc depends on it
T req_; // *must* be last, GetActiveRequests() in node.cc depends on it
};
} // namespace node
#endif // REQ_WRAP_H_
#endif // SRC_REQ_WRAP_H_

2
src/signal_wrap.cc

@ -72,7 +72,7 @@ class SignalWrap : public HandleWrap {
new SignalWrap(args.This());
}
SignalWrap(Handle<Object> object)
explicit SignalWrap(Handle<Object> object)
: HandleWrap(object, reinterpret_cast<uv_handle_t*>(&handle_)) {
int r = uv_signal_init(uv_default_loop(), &handle_);
assert(r == 0);

7
src/smalloc.h

@ -19,8 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef NODE_SMALLOC_H_
#define NODE_SMALLOC_H_
#ifndef SRC_SMALLOC_H_
#define SRC_SMALLOC_H_
#include "node.h"
#include "v8.h"
@ -64,7 +64,6 @@ NODE_EXTERN void Alloc(v8::Handle<v8::Object> obj,
NODE_EXTERN void AllocDispose(v8::Handle<v8::Object> obj);
} // namespace smalloc
} // namespace node
#endif // NODE_SMALLOC_H_
#endif // SRC_SMALLOC_H_

12
src/stream_wrap.cc

@ -29,8 +29,8 @@
#include "udp_wrap.h"
#include "node_counters.h"
#include <stdlib.h> // abort()
#include <limits.h> // INT_MAX
#include <stdlib.h> // abort()
#include <limits.h> // INT_MAX
namespace node {
@ -217,7 +217,7 @@ void StreamWrap::WriteBuffer(const FunctionCallbackInfo<Value>& args) {
size_t length = Buffer::Length(buf_obj);
char* storage = new char[sizeof(WriteWrap)];
WriteWrap* req_wrap = new (storage) WriteWrap(req_wrap_obj, wrap);
WriteWrap* req_wrap = new(storage) WriteWrap(req_wrap_obj, wrap);
req_wrap_obj->SetHiddenValue(buffer_sym, buf_obj);
@ -269,7 +269,7 @@ void StreamWrap::WriteStringImpl(const FunctionCallbackInfo<Value>& args) {
}
char* storage = new char[sizeof(WriteWrap) + storage_size + 15];
WriteWrap* req_wrap = new (storage) WriteWrap(req_wrap_obj, wrap);
WriteWrap* req_wrap = new(storage) WriteWrap(req_wrap_obj, wrap);
char* data = reinterpret_cast<char*>(ROUND_UP(
reinterpret_cast<uintptr_t>(storage) + sizeof(WriteWrap), 16));
@ -377,7 +377,7 @@ void StreamWrap::Writev(const FunctionCallbackInfo<Value>& args) {
storage_size += sizeof(WriteWrap);
char* storage = new char[storage_size];
WriteWrap* req_wrap = new (storage) WriteWrap(req_wrap_obj, wrap);
WriteWrap* req_wrap = new(storage) WriteWrap(req_wrap_obj, wrap);
uint32_t bytes = 0;
size_t offset = sizeof(WriteWrap);
@ -616,4 +616,4 @@ Handle<Object> StreamWrapCallbacks::Self() {
return wrap_->object();
}
}
} // namespace node

10
src/stream_wrap.h

@ -19,8 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef STREAM_WRAP_H_
#define STREAM_WRAP_H_
#ifndef SRC_STREAM_WRAP_H_
#define SRC_STREAM_WRAP_H_
#include "v8.h"
#include "node.h"
@ -53,8 +53,8 @@ class WriteWrap: public ReqWrap<uv_write_t> {
protected:
// People should not be using the non-placement new and delete operator on a
// WriteWrap. Ensure this never happens.
void* operator new(size_t size) { assert(0); };
void operator delete(void* ptr) { assert(0); };
void* operator new(size_t size) { assert(0); }
void operator delete(void* ptr) { assert(0); }
};
// Overridable callbacks' types
@ -160,4 +160,4 @@ class StreamWrap : public HandleWrap {
} // namespace node
#endif // STREAM_WRAP_H_
#endif // SRC_STREAM_WRAP_H_

4
src/string_bytes.cc

@ -458,7 +458,7 @@ static bool contains_non_ascii(const char* src, size_t len) {
return contains_non_ascii_slow(src, len);
}
const unsigned bytes_per_word = sizeof(void*);
const unsigned bytes_per_word = sizeof(uintptr_t);
const unsigned align_mask = bytes_per_word - 1;
const unsigned unaligned = reinterpret_cast<uintptr_t>(src) & align_mask;
@ -505,7 +505,7 @@ static void force_ascii(const char* src, char* dst, size_t len) {
return;
}
const unsigned bytes_per_word = sizeof(void*);
const unsigned bytes_per_word = sizeof(uintptr_t);
const unsigned align_mask = bytes_per_word - 1;
const unsigned src_unalign = reinterpret_cast<uintptr_t>(src) & align_mask;
const unsigned dst_unalign = reinterpret_cast<uintptr_t>(dst) & align_mask;

16
src/tcp_wrap.cc

@ -96,7 +96,9 @@ void TCPWrap::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "shutdown", StreamWrap::Shutdown);
NODE_SET_PROTOTYPE_METHOD(t, "writeBuffer", StreamWrap::WriteBuffer);
NODE_SET_PROTOTYPE_METHOD(t, "writeAsciiString", StreamWrap::WriteAsciiString);
NODE_SET_PROTOTYPE_METHOD(t,
"writeAsciiString",
StreamWrap::WriteAsciiString);
NODE_SET_PROTOTYPE_METHOD(t, "writeUtf8String", StreamWrap::WriteUtf8String);
NODE_SET_PROTOTYPE_METHOD(t, "writeUcs2String", StreamWrap::WriteUcs2String);
NODE_SET_PROTOTYPE_METHOD(t, "writev", StreamWrap::Writev);
@ -113,7 +115,9 @@ void TCPWrap::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "setKeepAlive", SetKeepAlive);
#ifdef _WIN32
NODE_SET_PROTOTYPE_METHOD(t, "setSimultaneousAccepts", SetSimultaneousAccepts);
NODE_SET_PROTOTYPE_METHOD(t,
"setSimultaneousAccepts",
SetSimultaneousAccepts);
#endif
onconnection_sym = String::New("onconnection");
@ -151,8 +155,8 @@ void TCPWrap::New(const FunctionCallbackInfo<Value>& args) {
TCPWrap::TCPWrap(Handle<Object> object)
: StreamWrap(object, reinterpret_cast<uv_stream_t*>(&handle_)) {
int r = uv_tcp_init(uv_default_loop(), &handle_);
assert(r == 0); // How do we proxy this error up to javascript?
// Suggestion: uv_tcp_init() returns void.
assert(r == 0); // How do we proxy this error up to javascript?
// Suggestion: uv_tcp_init() returns void.
UpdateWriteQueueSize();
}
@ -331,8 +335,8 @@ void TCPWrap::OnConnection(uv_stream_t* handle, int status) {
void TCPWrap::AfterConnect(uv_connect_t* req, int status) {
ConnectWrap* req_wrap = (ConnectWrap*) req->data;
TCPWrap* wrap = (TCPWrap*) req->handle->data;
ConnectWrap* req_wrap = reinterpret_cast<ConnectWrap*>(req->data);
TCPWrap* wrap = reinterpret_cast<TCPWrap*>(req->handle->data);
HandleScope scope(node_isolate);

8
src/tcp_wrap.h

@ -19,8 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef TCP_WRAP_H_
#define TCP_WRAP_H_
#ifndef SRC_TCP_WRAP_H_
#define SRC_TCP_WRAP_H_
#include "stream_wrap.h"
namespace node {
@ -34,7 +34,7 @@ class TCPWrap : public StreamWrap {
uv_tcp_t* UVHandle();
private:
TCPWrap(v8::Handle<v8::Object> object);
explicit TCPWrap(v8::Handle<v8::Object> object);
~TCPWrap();
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
@ -64,4 +64,4 @@ class TCPWrap : public StreamWrap {
} // namespace node
#endif // TCP_WRAP_H_
#endif // SRC_TCP_WRAP_H_

2
src/timer_wrap.cc

@ -75,7 +75,7 @@ class TimerWrap : public HandleWrap {
new TimerWrap(args.This());
}
TimerWrap(Handle<Object> object)
explicit TimerWrap(Handle<Object> object)
: HandleWrap(object, reinterpret_cast<uv_handle_t*>(&handle_)) {
int r = uv_timer_init(uv_default_loop(), &handle_);
assert(r == 0);

228
src/tls_wrap.cc

@ -442,29 +442,29 @@ Handle<Value> TLSCallbacks::GetSSLError(int status, int* err) {
*err = SSL_get_error(ssl_, status);
switch (*err) {
case SSL_ERROR_NONE:
case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_WRITE:
break;
case SSL_ERROR_ZERO_RETURN:
return scope.Close(String::NewSymbol("ZERO_RETURN"));
break;
default:
{
BUF_MEM* mem;
BIO* bio;
case SSL_ERROR_NONE:
case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_WRITE:
break;
case SSL_ERROR_ZERO_RETURN:
return scope.Close(String::NewSymbol("ZERO_RETURN"));
break;
default:
{
BUF_MEM* mem;
BIO* bio;
assert(*err == SSL_ERROR_SSL || *err == SSL_ERROR_SYSCALL);
assert(*err == SSL_ERROR_SSL || *err == SSL_ERROR_SYSCALL);
bio = BIO_new(BIO_s_mem());
assert(bio != NULL);
ERR_print_errors(bio);
BIO_get_mem_ptr(bio, &mem);
Handle<Value> r = Exception::Error(String::New(mem->data, mem->length));
BIO_free_all(bio);
bio = BIO_new(BIO_s_mem());
assert(bio != NULL);
ERR_print_errors(bio);
BIO_get_mem_ptr(bio, &mem);
Handle<Value> r = Exception::Error(String::New(mem->data, mem->length));
BIO_free_all(bio);
return scope.Close(r);
}
return scope.Close(r);
}
}
return Handle<Value>();
}
@ -686,104 +686,104 @@ void TLSCallbacks::ParseClientHello() {
Handle<Value> argv[1];
switch (hello_.state) {
case kParseWaiting:
// >= 5 bytes for header parsing
if (avail < 5)
break;
if (data[0] == kChangeCipherSpec ||
data[0] == kAlert ||
data[0] == kHandshake ||
data[0] == kApplicationData) {
hello_.frame_len = (data[3] << 8) + data[4];
hello_.state = kParseTLSHeader;
hello_.body_offset = 5;
} else {
hello_.frame_len = (data[0] << 8) + data[1];
hello_.state = kParseSSLHeader;
if (*data & 0x40) {
// header with padding
hello_.body_offset = 3;
case kParseWaiting:
// >= 5 bytes for header parsing
if (avail < 5)
break;
if (data[0] == kChangeCipherSpec ||
data[0] == kAlert ||
data[0] == kHandshake ||
data[0] == kApplicationData) {
hello_.frame_len = (data[3] << 8) + data[4];
hello_.state = kParseTLSHeader;
hello_.body_offset = 5;
} else {
// without padding
hello_.body_offset = 2;
hello_.frame_len = (data[0] << 8) + data[1];
hello_.state = kParseSSLHeader;
if (*data & 0x40) {
// header with padding
hello_.body_offset = 3;
} else {
// without padding
hello_.body_offset = 2;
}
}
}
// Sanity check (too big frame, or too small)
// Let OpenSSL handle it
if (hello_.frame_len >= kMaxTLSFrameLen)
return ParseFinish();
// Fall through
case kParseTLSHeader:
case kParseSSLHeader:
// >= 5 + frame size bytes for frame parsing
if (avail < hello_.body_offset + hello_.frame_len)
break;
// Sanity check (too big frame, or too small)
// Let OpenSSL handle it
if (hello_.frame_len >= kMaxTLSFrameLen)
return ParseFinish();
// Skip unsupported frames and gather some data from frame
// Fall through
case kParseTLSHeader:
case kParseSSLHeader:
// >= 5 + frame size bytes for frame parsing
if (avail < hello_.body_offset + hello_.frame_len)
break;
// Skip unsupported frames and gather some data from frame
// TODO(indutny): Check protocol version
if (data[hello_.body_offset] == kClientHello) {
is_clienthello = true;
uint8_t* body;
size_t session_offset;
if (hello_.state == kParseTLSHeader) {
// Skip frame header, hello header, protocol version and random data
session_offset = hello_.body_offset + 4 + 2 + 32;
if (session_offset + 1 < avail) {
body = data + session_offset;
session_size = *body;
session_id = body + 1;
}
} else if (hello_.state == kParseSSLHeader) {
// Skip header, version
session_offset = hello_.body_offset + 3;
// TODO(indutny): Check protocol version
if (data[hello_.body_offset] == kClientHello) {
is_clienthello = true;
uint8_t* body;
size_t session_offset;
if (session_offset + 4 < avail) {
body = data + session_offset;
if (hello_.state == kParseTLSHeader) {
// Skip frame header, hello header, protocol version and random data
session_offset = hello_.body_offset + 4 + 2 + 32;
int ciphers_size = (body[0] << 8) + body[1];
if (session_offset + 1 < avail) {
body = data + session_offset;
session_size = *body;
session_id = body + 1;
if (body + 4 + ciphers_size < data + avail) {
session_size = (body[2] << 8) + body[3];
session_id = body + 4 + ciphers_size;
}
}
} else {
// Whoa? How did we get here?
abort();
}
} else if (hello_.state == kParseSSLHeader) {
// Skip header, version
session_offset = hello_.body_offset + 3;
if (session_offset + 4 < avail) {
body = data + session_offset;
int ciphers_size = (body[0] << 8) + body[1];
if (body + 4 + ciphers_size < data + avail) {
session_size = (body[2] << 8) + body[3];
session_id = body + 4 + ciphers_size;
}
// Check if we overflowed (do not reply with any private data)
if (session_id == NULL ||
session_size > 32 ||
session_id + session_size > data + avail) {
return ParseFinish();
}
} else {
// Whoa? How did we get here?
abort();
}
// Check if we overflowed (do not reply with any private data)
if (session_id == NULL ||
session_size > 32 ||
session_id + session_size > data + avail) {
return ParseFinish();
// TODO(indutny): Parse other things?
}
// TODO(indutny): Parse other things?
}
// Not client hello - let OpenSSL handle it
if (!is_clienthello)
return ParseFinish();
// Not client hello - let OpenSSL handle it
if (!is_clienthello)
return ParseFinish();
hello_.state = kParsePaused;
hello_obj = Object::New();
hello_obj->Set(sessionid_sym,
Buffer::New(reinterpret_cast<char*>(session_id),
session_size));
hello_.state = kParsePaused;
hello_obj = Object::New();
hello_obj->Set(sessionid_sym,
Buffer::New(reinterpret_cast<char*>(session_id),
session_size));
argv[0] = hello_obj;
MakeCallback(object(), onclienthello_sym, 1, argv);
break;
case kParseEnded:
default:
break;
argv[0] = hello_obj;
MakeCallback(object(), onclienthello_sym, 1, argv);
break;
case kParseEnded:
default:
break;
}
}
@ -1183,17 +1183,17 @@ int TLSCallbacks::SelectNextProtoCallback(SSL* s,
int status = SSL_select_next_proto(out, outlen, in, inlen, npn_protos, len);
Handle<Value> result;
switch (status) {
case OPENSSL_NPN_UNSUPPORTED:
result = Null(node_isolate);
break;
case OPENSSL_NPN_NEGOTIATED:
result = String::New(reinterpret_cast<const char*>(*out), *outlen);
break;
case OPENSSL_NPN_NO_OVERLAP:
result = False(node_isolate);
break;
default:
break;
case OPENSSL_NPN_UNSUPPORTED:
result = Null(node_isolate);
break;
case OPENSSL_NPN_NEGOTIATED:
result = String::New(reinterpret_cast<const char*>(*out), *outlen);
break;
case OPENSSL_NPN_NO_OVERLAP:
result = False(node_isolate);
break;
default:
break;
}
if (!result.IsEmpty())

4
src/tty_wrap.cc

@ -69,7 +69,9 @@ void TTYWrap::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "readStop", StreamWrap::ReadStop);
NODE_SET_PROTOTYPE_METHOD(t, "writeBuffer", StreamWrap::WriteBuffer);
NODE_SET_PROTOTYPE_METHOD(t, "writeAsciiString", StreamWrap::WriteAsciiString);
NODE_SET_PROTOTYPE_METHOD(t,
"writeAsciiString",
StreamWrap::WriteAsciiString);
NODE_SET_PROTOTYPE_METHOD(t, "writeUtf8String", StreamWrap::WriteUtf8String);
NODE_SET_PROTOTYPE_METHOD(t, "writeUcs2String", StreamWrap::WriteUcs2String);

8
src/tty_wrap.h

@ -19,8 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef TTY_WRAP_H_
#define TTY_WRAP_H_
#ifndef SRC_TTY_WRAP_H_
#define SRC_TTY_WRAP_H_
#include "handle_wrap.h"
#include "stream_wrap.h"
@ -46,6 +46,6 @@ class TTYWrap : public StreamWrap {
uv_tty_t handle_;
};
} // namespace node
} // namespace node
#endif // TTY_WRAP_H_
#endif // SRC_TTY_WRAP_H_

6
src/udp_wrap.cc

@ -57,7 +57,7 @@ static Cached<String> onmessage_sym;
UDPWrap::UDPWrap(Handle<Object> object)
: HandleWrap(object, reinterpret_cast<uv_handle_t*>(&handle_)) {
int r = uv_udp_init(uv_default_loop(), &handle_);
assert(r == 0); // can't fail anyway
assert(r == 0); // can't fail anyway
}
@ -328,7 +328,7 @@ void UDPWrap::GetSockName(const FunctionCallbackInfo<Value>& args) {
}
// TODO share with StreamWrap::AfterWrite() in stream_wrap.cc
// TODO(bnoordhuis) share with StreamWrap::AfterWrite() in stream_wrap.cc
void UDPWrap::OnSend(uv_udp_send_t* req, int status) {
HandleScope scope(node_isolate);
@ -413,6 +413,6 @@ uv_udp_t* UDPWrap::UVHandle() {
}
} // namespace node
} // namespace node
NODE_MODULE(node_udp_wrap, node::UDPWrap::Initialize)

31
src/udp_wrap.h

@ -1,5 +1,26 @@
#ifndef UDP_WRAP_H_
#define UDP_WRAP_H_
// 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.
#ifndef SRC_UDP_WRAP_H_
#define SRC_UDP_WRAP_H_
#include "node.h"
#include "req_wrap.h"
@ -33,7 +54,7 @@ class UDPWrap: public HandleWrap {
uv_udp_t* UVHandle();
private:
UDPWrap(v8::Handle<v8::Object> object);
explicit UDPWrap(v8::Handle<v8::Object> object);
virtual ~UDPWrap();
static void DoBind(const v8::FunctionCallbackInfo<v8::Value>& args,
@ -54,6 +75,6 @@ class UDPWrap: public HandleWrap {
uv_udp_t handle_;
};
} // namespace node
} // namespace node
#endif // UDP_WRAP_H_
#endif // SRC_UDP_WRAP_H_

28
src/v8abbr.h

@ -1,10 +1,32 @@
/** 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.
*/
/*
* This header defines short names for V8 constants for use by the ustack
* helper.
*/
#ifndef V8_ABBR_H
#define V8_ABBR_H
#ifndef SRC_V8ABBR_H_
#define SRC_V8ABBR_H_
/* Frame pointer offsets */
#define V8_OFF_FP_FUNC V8DBG_OFF_FP_FUNCTION
@ -83,4 +105,4 @@
#define V8_OFF_MAP_ATTRS \
V8_OFF_HEAP(V8DBG_CLASS_MAP__INSTANCE_ATTRIBUTES__INT)
#endif /* V8_ABBR_H */
#endif /* SRC_V8ABBR_H_ */

Loading…
Cancel
Save