Browse files

abstracted out constants, still crashes

  • Loading branch information...
1 parent 075cc89 commit 54afe8ec547b81e7ccf4332eb5e8cfe9131ff89a @substack committed Mar 24, 2011
Showing with 176 additions and 170 deletions.
  1. +154 −0 src/constants.cc
  2. +1 −151 src/constants.h
  3. +12 −18 src/sshd.cc
  4. +8 −0 src/sshd.h
  5. +1 −1 wscript
View
154 src/constants.cc
@@ -0,0 +1,154 @@
+#include "constants.h"
+
+#define SET(x) target->Set(String::NewSymbol(#x), Integer::New(x));
+
+Persistent<Object> Constants() {
+ Persistent<Object> target = Persistent<Object>::New(Object::New());
+
+ // kex types
+ SET(SSH_KEX);
+ SET(SSH_HOSTKEYS);
+ SET(SSH_CRYPT_C_S);
+ SET(SSH_CRYPT_S_C);
+ SET(SSH_MAC_C_S);
+ SET(SSH_MAC_S_C);
+ SET(SSH_COMP_C_S);
+ SET(SSH_COMP_S_C);
+ SET(SSH_LANG_C_S);
+ SET(SSH_LANG_S_C);
+
+ SET(SSH_CRYPT);
+ SET(SSH_MAC);
+ SET(SSH_COMP);
+ SET(SSH_LANG);
+
+ // auth
+ SET(SSH_AUTH_SUCCESS);
+ SET(SSH_AUTH_DENIED);
+ SET(SSH_AUTH_PARTIAL);
+ SET(SSH_AUTH_INFO);
+ SET(SSH_AUTH_AGAIN);
+ SET(SSH_AUTH_ERROR);
+
+ // auth flags
+ SET(SSH_AUTH_METHOD_UNKNOWN);
+ SET(SSH_AUTH_METHOD_NONE);
+ SET(SSH_AUTH_METHOD_PASSWORD);
+ SET(SSH_AUTH_METHOD_PUBLICKEY);
+ SET(SSH_AUTH_METHOD_HOSTBASED);
+ SET(SSH_AUTH_METHOD_INTERACTIVE);
+
+ // message requests
+ SET(SSH_REQUEST_AUTH);
+ SET(SSH_REQUEST_CHANNEL_OPEN);
+ SET(SSH_REQUEST_CHANNEL);
+ SET(SSH_REQUEST_SERVICE);
+ SET(SSH_REQUEST_GLOBAL);
+
+ // channel type
+ SET(SSH_CHANNEL_UNKNOWN);
+ SET(SSH_CHANNEL_SESSION);
+ SET(SSH_CHANNEL_DIRECT_TCPIP);
+ SET(SSH_CHANNEL_FORWARDED_TCPIP);
+ Integer::New(SSH_CHANNEL_X11);
+
+ // channel requests
+ SET(SSH_CHANNEL_REQUEST_UNKNOWN);
+ SET(SSH_CHANNEL_REQUEST_PTY);
+ SET(SSH_CHANNEL_REQUEST_EXEC);
+ SET(SSH_CHANNEL_REQUEST_SHELL);
+ SET(SSH_CHANNEL_REQUEST_ENV);
+ SET(SSH_CHANNEL_REQUEST_SUBSYSTEM);
+ SET(SSH_CHANNEL_REQUEST_WINDOW_CHANGE);
+
+ // global request
+ SET(SSH_GLOBAL_REQUEST_UNKNOWN);
+ SET(SSH_GLOBAL_REQUEST_TCPIP_FORWARD);
+ SET(SSH_GLOBAL_REQUEST_CANCEL_TCPIP_FORWARD);
+
+ // publickey state
+ SET(SSH_PUBLICKEY_STATE_ERROR);
+ SET(SSH_PUBLICKEY_STATE_NONE);
+ SET(SSH_PUBLICKEY_STATE_VALID);
+ SET(SSH_PUBLICKEY_STATE_WRONG);
+
+ // status flags
+ SET(SSH_CLOSED);
+ SET(SSH_READ_PENDING);
+ SET(SSH_CLOSED_ERROR);
+
+ // server known messages
+ SET(SSH_SERVER_ERROR);
+ SET(SSH_SERVER_NOT_KNOWN);
+ SET(SSH_SERVER_KNOWN_OK);
+ SET(SSH_SERVER_KNOWN_CHANGED);
+ SET(SSH_SERVER_FOUND_OTHER);
+ SET(SSH_SERVER_FILE_NOT_FOUND);
+
+ // error types
+ SET(SSH_NO_ERROR);
+ SET(SSH_REQUEST_DENIED);
+ SET(SSH_FATAL);
+ SET(SSH_EINTR);
+
+ // key types
+ SET(SSH_KEYTYPE_UNKNOWN);
+ SET(SSH_KEYTYPE_DSS);
+ SET(SSH_KEYTYPE_RSA);
+ SET(SSH_KEYTYPE_RSA1);
+
+ // error return codes
+ SET(SSH_OK);
+ SET(SSH_ERROR);
+ SET(SSH_AGAIN);
+ SET(SSH_EOF);
+
+ // logging codes
+ SET(SSH_LOG_NOLOG);
+ SET(SSH_LOG_RARE);
+ SET(SSH_LOG_PROTOCOL);
+ SET(SSH_LOG_PACKET);
+ SET(SSH_LOG_FUNCTIONS);
+
+ // options why not
+ SET(SSH_OPTIONS_HOST);
+ SET(SSH_OPTIONS_PORT);
+ SET(SSH_OPTIONS_PORT_STR);
+ SET(SSH_OPTIONS_FD);
+ SET(SSH_OPTIONS_USER);
+ SET(SSH_OPTIONS_SSH_DIR);
+ SET(SSH_OPTIONS_IDENTITY);
+ SET(SSH_OPTIONS_ADD_IDENTITY);
+ SET(SSH_OPTIONS_KNOWNHOSTS);
+ SET(SSH_OPTIONS_TIMEOUT);
+ SET(SSH_OPTIONS_TIMEOUT_USEC);
+ SET(SSH_OPTIONS_SSH1);
+ SET(SSH_OPTIONS_SSH2);
+ SET(SSH_OPTIONS_LOG_VERBOSITY);
+ SET(SSH_OPTIONS_LOG_VERBOSITY_STR);
+ SET(SSH_OPTIONS_CIPHERS_C_S);
+ SET(SSH_OPTIONS_CIPHERS_S_C);
+ SET(SSH_OPTIONS_COMPRESSION_C_S);
+ SET(SSH_OPTIONS_COMPRESSION_S_C);
+ SET(SSH_OPTIONS_PROXYCOMMAND);
+ SET(SSH_OPTIONS_BINDADDR);
+ SET(SSH_OPTIONS_STRICTHOSTKEYCHECK);
+ SET(SSH_OPTIONS_COMPRESSION);
+ SET(SSH_OPTIONS_COMPRESSION_LEVEL);
+
+ // scp constants
+ SET(SSH_SCP_WRITE);
+ SET(SSH_SCP_READ);
+ SET(SSH_SCP_RECURSIVE);
+
+ // request types
+ SET(SSH_SCP_REQUEST_NEWDIR);
+ SET(SSH_SCP_REQUEST_NEWFILE);
+ SET(SSH_SCP_REQUEST_EOF);
+ SET(SSH_SCP_REQUEST_ENDDIR);
+ SET(SSH_SCP_REQUEST_WARNING);
+
+ return target;
+}
+
+#undef SET
View
152 src/constants.h
@@ -8,156 +8,6 @@
using namespace v8;
using namespace node;
-#define SET(x) target->Set(String::NewSymbol(#x), Integer::New(x));
+Persistent<Object> Constants();
-Persistent<Object> Constants() {
- Persistent<Object> target = Persistent<Object>::New(Object::New());
-
- // kex types
- SET(SSH_KEX);
- SET(SSH_HOSTKEYS);
- SET(SSH_CRYPT_C_S);
- SET(SSH_CRYPT_S_C);
- SET(SSH_MAC_C_S);
- SET(SSH_MAC_S_C);
- SET(SSH_COMP_C_S);
- SET(SSH_COMP_S_C);
- SET(SSH_LANG_C_S);
- SET(SSH_LANG_S_C);
-
- SET(SSH_CRYPT);
- SET(SSH_MAC);
- SET(SSH_COMP);
- SET(SSH_LANG);
-
- // auth
- SET(SSH_AUTH_SUCCESS);
- SET(SSH_AUTH_DENIED);
- SET(SSH_AUTH_PARTIAL);
- SET(SSH_AUTH_INFO);
- SET(SSH_AUTH_AGAIN);
- SET(SSH_AUTH_ERROR);
-
- // auth flags
- SET(SSH_AUTH_METHOD_UNKNOWN);
- SET(SSH_AUTH_METHOD_NONE);
- SET(SSH_AUTH_METHOD_PASSWORD);
- SET(SSH_AUTH_METHOD_PUBLICKEY);
- SET(SSH_AUTH_METHOD_HOSTBASED);
- SET(SSH_AUTH_METHOD_INTERACTIVE);
-
- // message requests
- SET(SSH_REQUEST_AUTH);
- SET(SSH_REQUEST_CHANNEL_OPEN);
- SET(SSH_REQUEST_CHANNEL);
- SET(SSH_REQUEST_SERVICE);
- SET(SSH_REQUEST_GLOBAL);
-
- // channel type
- SET(SSH_CHANNEL_UNKNOWN);
- SET(SSH_CHANNEL_SESSION);
- SET(SSH_CHANNEL_DIRECT_TCPIP);
- SET(SSH_CHANNEL_FORWARDED_TCPIP);
- Integer::New(SSH_CHANNEL_X11);
-
- // channel requests
- SET(SSH_CHANNEL_REQUEST_UNKNOWN);
- SET(SSH_CHANNEL_REQUEST_PTY);
- SET(SSH_CHANNEL_REQUEST_EXEC);
- SET(SSH_CHANNEL_REQUEST_SHELL);
- SET(SSH_CHANNEL_REQUEST_ENV);
- SET(SSH_CHANNEL_REQUEST_SUBSYSTEM);
- SET(SSH_CHANNEL_REQUEST_WINDOW_CHANGE);
-
- // global request
- SET(SSH_GLOBAL_REQUEST_UNKNOWN);
- SET(SSH_GLOBAL_REQUEST_TCPIP_FORWARD);
- SET(SSH_GLOBAL_REQUEST_CANCEL_TCPIP_FORWARD);
-
- // publickey state
- SET(SSH_PUBLICKEY_STATE_ERROR);
- SET(SSH_PUBLICKEY_STATE_NONE);
- SET(SSH_PUBLICKEY_STATE_VALID);
- SET(SSH_PUBLICKEY_STATE_WRONG);
-
- // status flags
- SET(SSH_CLOSED);
- SET(SSH_READ_PENDING);
- SET(SSH_CLOSED_ERROR);
-
- // server known messages
- SET(SSH_SERVER_ERROR);
- SET(SSH_SERVER_NOT_KNOWN);
- SET(SSH_SERVER_KNOWN_OK);
- SET(SSH_SERVER_KNOWN_CHANGED);
- SET(SSH_SERVER_FOUND_OTHER);
- SET(SSH_SERVER_FILE_NOT_FOUND);
-
- // error types
- SET(SSH_NO_ERROR);
- SET(SSH_REQUEST_DENIED);
- SET(SSH_FATAL);
- SET(SSH_EINTR);
-
- // key types
- SET(SSH_KEYTYPE_UNKNOWN);
- SET(SSH_KEYTYPE_DSS);
- SET(SSH_KEYTYPE_RSA);
- SET(SSH_KEYTYPE_RSA1);
-
- // error return codes
- SET(SSH_OK);
- SET(SSH_ERROR);
- SET(SSH_AGAIN);
- SET(SSH_EOF);
-
- // logging codes
- SET(SSH_LOG_NOLOG);
- SET(SSH_LOG_RARE);
- SET(SSH_LOG_PROTOCOL);
- SET(SSH_LOG_PACKET);
- SET(SSH_LOG_FUNCTIONS);
-
- // options why not
- SET(SSH_OPTIONS_HOST);
- SET(SSH_OPTIONS_PORT);
- SET(SSH_OPTIONS_PORT_STR);
- SET(SSH_OPTIONS_FD);
- SET(SSH_OPTIONS_USER);
- SET(SSH_OPTIONS_SSH_DIR);
- SET(SSH_OPTIONS_IDENTITY);
- SET(SSH_OPTIONS_ADD_IDENTITY);
- SET(SSH_OPTIONS_KNOWNHOSTS);
- SET(SSH_OPTIONS_TIMEOUT);
- SET(SSH_OPTIONS_TIMEOUT_USEC);
- SET(SSH_OPTIONS_SSH1);
- SET(SSH_OPTIONS_SSH2);
- SET(SSH_OPTIONS_LOG_VERBOSITY);
- SET(SSH_OPTIONS_LOG_VERBOSITY_STR);
- SET(SSH_OPTIONS_CIPHERS_C_S);
- SET(SSH_OPTIONS_CIPHERS_S_C);
- SET(SSH_OPTIONS_COMPRESSION_C_S);
- SET(SSH_OPTIONS_COMPRESSION_S_C);
- SET(SSH_OPTIONS_PROXYCOMMAND);
- SET(SSH_OPTIONS_BINDADDR);
- SET(SSH_OPTIONS_STRICTHOSTKEYCHECK);
- SET(SSH_OPTIONS_COMPRESSION);
- SET(SSH_OPTIONS_COMPRESSION_LEVEL);
-
- // scp constants
- SET(SSH_SCP_WRITE);
- SET(SSH_SCP_READ);
- SET(SSH_SCP_RECURSIVE);
-
- // request types
- SET(SSH_SCP_REQUEST_NEWDIR);
- SET(SSH_SCP_REQUEST_NEWFILE);
- SET(SSH_SCP_REQUEST_EOF);
- SET(SSH_SCP_REQUEST_ENDDIR);
- SET(SSH_SCP_REQUEST_WARNING);
-
- return target;
-}
-
-#undef SET
#endif
View
30 src/sshd.cc
@@ -1,14 +1,8 @@
#include "sshd.h"
-#include "client.h"
-#include "constants.h"
Persistent<FunctionTemplate> SSHD::constructor_template;
Persistent<String> SSHD::sessionSymbol;
-
-struct ClientServerPair {
- SSHD *server;
- Client *client;
-};
+ClientServerPair *makePair(SSHD *);
void SSHD::setPort(Local<Value> port) {
if (port->IsNumber()) {
@@ -144,12 +138,7 @@ Handle<Value> SSHD::Listen(const Arguments &args) {
);
}
- ClientServerPair *pair = new ClientServerPair;
-
- pair->server = sshd;
- pair->client = new Client;
-
- eio_custom(Accept, EIO_PRI_DEFAULT, AcceptAfter, pair);
+ eio_custom(Accept, EIO_PRI_DEFAULT, AcceptAfter, makePair(sshd));
ev_ref(EV_DEFAULT_UC);
return args.This();
@@ -192,6 +181,7 @@ printf("4\n"); fflush(stdout);
Handle<Value> argv[1];
argv[0] = client->handle_;
printf("5\n"); fflush(stdout);
+ client->Ref();
printf("6\n"); fflush(stdout);
server->Emit(String::NewSymbol("session"), 1, argv);
printf("7\n"); fflush(stdout);
@@ -207,12 +197,9 @@ printf("8\n"); fflush(stdout);
if (!server->closed) {
printf("9\n"); fflush(stdout);
- pair->client = new Client;
-printf("10\n"); fflush(stdout);
-
- eio_custom(Accept, EIO_PRI_DEFAULT, AcceptAfter, pair);
+ eio_custom(Accept, EIO_PRI_DEFAULT, AcceptAfter, makePair(server));
ev_ref(EV_DEFAULT_UC);
-printf("11\n"); fflush(stdout);
+printf("10\n"); fflush(stdout);
}
return 0;
@@ -224,3 +211,10 @@ Handle<Value> SSHD::Close(const Arguments &args) {
sshd->closed = true;
return args.This();
}
+
+ClientServerPair *makePair(SSHD *sshd) {
+ ClientServerPair *p = new ClientServerPair;
+ p->server = sshd;
+ p->client = new Client;
+ return p;
+}
View
8 src/sshd.h
@@ -16,6 +16,9 @@
using namespace v8;
using namespace node;
+#include "client.h"
+#include "constants.h"
+
class SSHD : EventEmitter {
private:
static Persistent<FunctionTemplate> constructor_template;
@@ -40,4 +43,9 @@ class SSHD : EventEmitter {
static Persistent<String> sessionSymbol;
};
+struct ClientServerPair {
+ SSHD *server;
+ Client *client;
+};
+
#endif
View
2 wscript
@@ -28,7 +28,7 @@ def build(bld):
sshd.target = 'sshd'
sshd.source = [
'src/init.cc', 'src/sshd.cc', 'src/client.cc',
- 'src/msg.cc', 'src/chan.cc'
+ 'src/msg.cc', 'src/chan.cc', 'src/constants.cc'
]
sshd.cxxflags = [ '-D_FILE_OFFSET_BITS=64', '-D_LARGEFILE_SOURCE' ]
sshd.cxxflags.append(

0 comments on commit 54afe8e

Please sign in to comment.