SSH is in but not working properly.
This commit is contained in:
parent
0c9b9c1487
commit
a5a5c70625
5 changed files with 61 additions and 24 deletions
|
@ -89,9 +89,14 @@ add_definitions(
|
|||
${GTK3_CFLAGS}
|
||||
-Wall
|
||||
-Wno-unknown-pragmas
|
||||
-O2
|
||||
)
|
||||
|
||||
if(DEBUG_MODE)
|
||||
add_definitions(-O0)
|
||||
else()
|
||||
add_definitions(-O2)
|
||||
endif()
|
||||
|
||||
|
||||
target_link_directories(${CMAKE_PROJECT_NAME} PUBLIC
|
||||
${GTK3_LIBRARY_DIRS}
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
#define SSH_H
|
||||
|
||||
|
||||
#include "libssh2.h"
|
||||
#include "libssh2_sftp.h"
|
||||
|
||||
#include "common.h"
|
||||
|
||||
|
||||
|
|
|
@ -20,18 +20,23 @@
|
|||
*/
|
||||
|
||||
|
||||
#include "stddclmr.h"
|
||||
#include "common.h"
|
||||
#include "scintillaHeaders.h"
|
||||
#include "joeydev.h"
|
||||
#include "stddclmr.h"
|
||||
#include "ssh.h"
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
gtk_init(&argc, &argv);
|
||||
sshStartup();
|
||||
|
||||
winJoeyDevCreate();
|
||||
gtk_main();
|
||||
|
||||
scintilla_release_resources();
|
||||
sshShutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "common.h"
|
||||
#include "project.h"
|
||||
#include "utils.h"
|
||||
#include "ssh.h"
|
||||
|
||||
|
||||
enum ProjectColumnsE {
|
||||
|
@ -415,8 +416,10 @@ EVENT void menuProjectBuildSettings(GtkWidget *object, gpointer userData) {
|
|||
&txtUser,
|
||||
&txtPassword
|
||||
};
|
||||
int result = 0;
|
||||
char temp[6];
|
||||
int result = 0;
|
||||
SSHT *ssh = NULL;
|
||||
char *output = NULL;
|
||||
|
||||
(void)object;
|
||||
|
||||
|
@ -442,9 +445,27 @@ EVENT void menuProjectBuildSettings(GtkWidget *object, gpointer userData) {
|
|||
|
||||
if (result == BUILD_SETTINGS_RESPONSE_TEST) {
|
||||
// Run server connection test.
|
||||
ssh = sshConnect(self->buildHost, self->buildPort, self->buildUser, self->buildPassword);
|
||||
if (ssh) {
|
||||
debug("Connected!\n");
|
||||
result = sshExecute(ssh, "echo ${JOEYLIB_SDKS}", &output);
|
||||
debug("----------\n");
|
||||
if ((result == 0) && (strlen(output) > 0)) {
|
||||
debug("%s\n", output);
|
||||
} else {
|
||||
debug("No output!\n");
|
||||
}
|
||||
debug("----------\n");
|
||||
DEL(output);
|
||||
sshDisconnect(&ssh);
|
||||
} else {
|
||||
debug("Failed to connect.\n");
|
||||
}
|
||||
} else {
|
||||
// Close dialog on OKAY but not TEST.
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
43
src/ssh.c
43
src/ssh.c
|
@ -24,9 +24,6 @@
|
|||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "libssh2.h"
|
||||
#include "libssh2_sftp.h"
|
||||
|
||||
#include "ssh.h"
|
||||
#include "utils.h"
|
||||
#include "array.h"
|
||||
|
@ -41,6 +38,10 @@ closesocket(data->sock);
|
|||
|
||||
|
||||
static SSHT **_activeSSHs = NULL;
|
||||
static char *_output = NULL;
|
||||
static int _outputLen = 0;
|
||||
static char *_buffer = NULL;
|
||||
static int _bufferLen = 0;
|
||||
|
||||
|
||||
gboolean sshUpdate(gpointer userData); // Not static
|
||||
|
@ -63,7 +64,7 @@ SSHT *sshConnect(char *hostname, uint16_t port, char *user, char *password) {
|
|||
sin.sin_port = htons(port);
|
||||
sin.sin_addr.s_addr = hostaddr;
|
||||
if (connect(data->sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)) != 0) {
|
||||
debug("Failed to connect!\n");
|
||||
debug("Failed to connect: %d\n", errno);
|
||||
DEL(data);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -80,7 +81,7 @@ SSHT *sshConnect(char *hostname, uint16_t port, char *user, char *password) {
|
|||
while ((rc = libssh2_session_handshake(data->session, data->sock)) == LIBSSH2_ERROR_EAGAIN)
|
||||
;
|
||||
if (rc) {
|
||||
printf("Failure establishing SSH session: %d\n", rc);
|
||||
debug("Failure establishing SSH session: %d\n", rc);
|
||||
libssh2_session_free(data->session);
|
||||
socketclose(data->sock);
|
||||
DEL(data);
|
||||
|
@ -200,9 +201,12 @@ void sshShutdown(void) {
|
|||
//curl_multi_cleanup(_curlMulti);
|
||||
//curl_global_cleanup();
|
||||
|
||||
libssh2_exit();
|
||||
|
||||
g_idle_remove_by_data(sshUpdate);
|
||||
|
||||
DEL(_output);
|
||||
DEL(_buffer);
|
||||
|
||||
libssh2_exit();
|
||||
}
|
||||
|
||||
|
||||
|
@ -224,33 +228,32 @@ void sshStartup(void) {
|
|||
printf("libssh2 initialization failed: %d\n", err);
|
||||
}
|
||||
|
||||
utilEnsureBufferSize((unsigned char **)&_output, &_outputLen, 1024);
|
||||
utilEnsureBufferSize((unsigned char **)&_buffer, &_bufferLen, 0x4000);
|
||||
|
||||
g_idle_add(sshUpdate, sshUpdate);
|
||||
}
|
||||
|
||||
|
||||
gboolean sshUpdate(gpointer userData) {
|
||||
int rc;
|
||||
char buffer[0x4000];
|
||||
int exitcode = 127;
|
||||
char *exitsignal = (char *)"none";
|
||||
char *output = NULL;
|
||||
int outputLen = 0;
|
||||
SSHT *s;
|
||||
int i;
|
||||
|
||||
(void)userData;
|
||||
|
||||
utilEnsureBufferSize((unsigned char **)&output, &outputLen, 1024);
|
||||
output[0] = 0;
|
||||
_output[0] = 0;
|
||||
|
||||
for (i=0; i<arrlen(_activeSSHs); i++) {
|
||||
s = _activeSSHs[i];
|
||||
if (!s->finished) {
|
||||
rc = libssh2_channel_read(s->channel, buffer, sizeof(buffer));
|
||||
rc = libssh2_channel_read(s->channel, _buffer, sizeof(_buffer));
|
||||
if (rc > 0) {
|
||||
utilEnsureBufferSize((unsigned char **)&output, &outputLen, rc + 1);
|
||||
output[0] = 0;
|
||||
strncat(output, (char *)buffer, rc);
|
||||
utilEnsureBufferSize((unsigned char **)&_output, &_outputLen, rc + 1);
|
||||
_output[0] = 0;
|
||||
strncat(_output, (char *)_buffer, rc);
|
||||
//***TODO*** Display in status dialog
|
||||
//s->status->AddOutput(output);
|
||||
} else {
|
||||
|
@ -260,14 +263,14 @@ gboolean sshUpdate(gpointer userData) {
|
|||
while ((rc = libssh2_channel_close(s->channel)) == LIBSSH2_ERROR_EAGAIN) {
|
||||
sshWaitSocket(s->sock, s->session);
|
||||
}
|
||||
DEL(output);
|
||||
output = strdup("\n\nUH OH! Something wrong happened. Check the output for errors.");
|
||||
DEL(_output);
|
||||
_output = strdup("\n\nUH OH! Something wrong happened. Check the output for errors.");
|
||||
if (rc == 0) {
|
||||
exitcode = libssh2_channel_get_exit_status(s->channel);
|
||||
libssh2_channel_get_exit_signal(s->channel, &exitsignal, NULL, NULL, NULL, NULL, NULL);
|
||||
if (exitcode == 0) {
|
||||
DEL(output);
|
||||
output = strdup("\n\nFINISHED! You can close this window anytime.");
|
||||
DEL(_output);
|
||||
_output = strdup("\n\nFINISHED! You can close this window anytime.");
|
||||
}
|
||||
}
|
||||
//***TODO*** Display in status dialog
|
||||
|
|
Loading…
Add table
Reference in a new issue