SSH is in but not working properly.

This commit is contained in:
Scott Duensing 2022-12-22 18:27:19 -06:00
parent 0c9b9c1487
commit a5a5c70625
5 changed files with 61 additions and 24 deletions

View file

@ -89,9 +89,14 @@ add_definitions(
${GTK3_CFLAGS} ${GTK3_CFLAGS}
-Wall -Wall
-Wno-unknown-pragmas -Wno-unknown-pragmas
-O2
) )
if(DEBUG_MODE)
add_definitions(-O0)
else()
add_definitions(-O2)
endif()
target_link_directories(${CMAKE_PROJECT_NAME} PUBLIC target_link_directories(${CMAKE_PROJECT_NAME} PUBLIC
${GTK3_LIBRARY_DIRS} ${GTK3_LIBRARY_DIRS}

View file

@ -24,6 +24,9 @@
#define SSH_H #define SSH_H
#include "libssh2.h"
#include "libssh2_sftp.h"
#include "common.h" #include "common.h"

View file

@ -20,18 +20,23 @@
*/ */
#include "stddclmr.h"
#include "common.h" #include "common.h"
#include "scintillaHeaders.h" #include "scintillaHeaders.h"
#include "joeydev.h" #include "joeydev.h"
#include "stddclmr.h" #include "ssh.h"
int main(int argc, char **argv) { int main(int argc, char **argv) {
gtk_init(&argc, &argv); gtk_init(&argc, &argv);
sshStartup();
winJoeyDevCreate(); winJoeyDevCreate();
gtk_main(); gtk_main();
scintilla_release_resources(); scintilla_release_resources();
sshShutdown();
return 0; return 0;
} }

View file

@ -27,6 +27,7 @@
#include "common.h" #include "common.h"
#include "project.h" #include "project.h"
#include "utils.h" #include "utils.h"
#include "ssh.h"
enum ProjectColumnsE { enum ProjectColumnsE {
@ -415,8 +416,10 @@ EVENT void menuProjectBuildSettings(GtkWidget *object, gpointer userData) {
&txtUser, &txtUser,
&txtPassword &txtPassword
}; };
int result = 0;
char temp[6]; char temp[6];
int result = 0;
SSHT *ssh = NULL;
char *output = NULL;
(void)object; (void)object;
@ -442,9 +445,27 @@ EVENT void menuProjectBuildSettings(GtkWidget *object, gpointer userData) {
if (result == BUILD_SETTINGS_RESPONSE_TEST) { if (result == BUILD_SETTINGS_RESPONSE_TEST) {
// Run server connection 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;
} }
} }

View file

@ -24,9 +24,6 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include "libssh2.h"
#include "libssh2_sftp.h"
#include "ssh.h" #include "ssh.h"
#include "utils.h" #include "utils.h"
#include "array.h" #include "array.h"
@ -41,6 +38,10 @@ closesocket(data->sock);
static SSHT **_activeSSHs = NULL; 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 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_port = htons(port);
sin.sin_addr.s_addr = hostaddr; sin.sin_addr.s_addr = hostaddr;
if (connect(data->sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)) != 0) { 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); DEL(data);
return NULL; 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) while ((rc = libssh2_session_handshake(data->session, data->sock)) == LIBSSH2_ERROR_EAGAIN)
; ;
if (rc) { if (rc) {
printf("Failure establishing SSH session: %d\n", rc); debug("Failure establishing SSH session: %d\n", rc);
libssh2_session_free(data->session); libssh2_session_free(data->session);
socketclose(data->sock); socketclose(data->sock);
DEL(data); DEL(data);
@ -200,9 +201,12 @@ void sshShutdown(void) {
//curl_multi_cleanup(_curlMulti); //curl_multi_cleanup(_curlMulti);
//curl_global_cleanup(); //curl_global_cleanup();
libssh2_exit();
g_idle_remove_by_data(sshUpdate); 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); printf("libssh2 initialization failed: %d\n", err);
} }
utilEnsureBufferSize((unsigned char **)&_output, &_outputLen, 1024);
utilEnsureBufferSize((unsigned char **)&_buffer, &_bufferLen, 0x4000);
g_idle_add(sshUpdate, sshUpdate); g_idle_add(sshUpdate, sshUpdate);
} }
gboolean sshUpdate(gpointer userData) { gboolean sshUpdate(gpointer userData) {
int rc; int rc;
char buffer[0x4000];
int exitcode = 127; int exitcode = 127;
char *exitsignal = (char *)"none"; char *exitsignal = (char *)"none";
char *output = NULL;
int outputLen = 0;
SSHT *s; SSHT *s;
int i; int i;
(void)userData; (void)userData;
utilEnsureBufferSize((unsigned char **)&output, &outputLen, 1024); _output[0] = 0;
output[0] = 0;
for (i=0; i<arrlen(_activeSSHs); i++) { for (i=0; i<arrlen(_activeSSHs); i++) {
s = _activeSSHs[i]; s = _activeSSHs[i];
if (!s->finished) { if (!s->finished) {
rc = libssh2_channel_read(s->channel, buffer, sizeof(buffer)); rc = libssh2_channel_read(s->channel, _buffer, sizeof(_buffer));
if (rc > 0) { if (rc > 0) {
utilEnsureBufferSize((unsigned char **)&output, &outputLen, rc + 1); utilEnsureBufferSize((unsigned char **)&_output, &_outputLen, rc + 1);
output[0] = 0; _output[0] = 0;
strncat(output, (char *)buffer, rc); strncat(_output, (char *)_buffer, rc);
//***TODO*** Display in status dialog //***TODO*** Display in status dialog
//s->status->AddOutput(output); //s->status->AddOutput(output);
} else { } else {
@ -260,14 +263,14 @@ gboolean sshUpdate(gpointer userData) {
while ((rc = libssh2_channel_close(s->channel)) == LIBSSH2_ERROR_EAGAIN) { while ((rc = libssh2_channel_close(s->channel)) == LIBSSH2_ERROR_EAGAIN) {
sshWaitSocket(s->sock, s->session); sshWaitSocket(s->sock, s->session);
} }
DEL(output); DEL(_output);
output = strdup("\n\nUH OH! Something wrong happened. Check the output for errors."); _output = strdup("\n\nUH OH! Something wrong happened. Check the output for errors.");
if (rc == 0) { if (rc == 0) {
exitcode = libssh2_channel_get_exit_status(s->channel); exitcode = libssh2_channel_get_exit_status(s->channel);
libssh2_channel_get_exit_signal(s->channel, &exitsignal, NULL, NULL, NULL, NULL, NULL); libssh2_channel_get_exit_signal(s->channel, &exitsignal, NULL, NULL, NULL, NULL, NULL);
if (exitcode == 0) { if (exitcode == 0) {
DEL(output); DEL(_output);
output = strdup("\n\nFINISHED! You can close this window anytime."); _output = strdup("\n\nFINISHED! You can close this window anytime.");
} }
} }
//***TODO*** Display in status dialog //***TODO*** Display in status dialog