Changes to libtrans interface

This commit is contained in:
matt335672 2021-09-17 11:29:02 +01:00
parent 5862a6123f
commit 30a92cb095
6 changed files with 63 additions and 36 deletions

View File

@ -30,17 +30,54 @@
#include "libscp_connection.h"
#include "string_calls.h"
#include "trans.h"
/*****************************************************************************/
struct trans *
scp_trans_create(int sck)
scp_connect(const char *host, const char *port,
tis_term term_func,
ttrans_data_in data_in_func,
void *callback_data)
{
struct trans *result = trans_create(TRANS_MODE_TCP, 8192, 8192);
if (result != NULL)
struct trans *t = trans_create(TRANS_MODE_TCP, 8192, 8192);
int index;
if (host == NULL)
{
result->sck = sck;
host = "localhost";
}
return result;
if (port == NULL)
{
port = "3350";
}
t->is_term = term_func;
t->trans_data_in = data_in_func;
t->header_size = 8;
t->no_stream_init_on_data_in = 1;
t->callback_data = callback_data;
/* try to connect up to 4 times
*
* term_func can be NULL, so check before calling it */
index = 4;
while (trans_connect(t, host, port, 3000) != 0 &&
!(term_func && term_func()) &&
--index > 0)
{
g_sleep(1000);
LOG_DEVEL(LOG_LEVEL_DEBUG, "Connect failed. Trying again...");
}
if (t->status != TRANS_STATUS_UP)
{
trans_delete(t);
t = NULL;
}
return t;
}
/*****************************************************************************/

View File

@ -31,11 +31,12 @@
/**
*
* @brief creates a new SCP transport object
* @param sck the connection socket
*
* This is a convenience function which calls trans_create() with the
* correct parameters.
* @brief creates a new SCP connection
* @param host Hostname to connect to (NULL for default)
* @param port Port to connect to (NULL for default)
* @param term_func Transport termination function (or NULL)
* @param data_in_func Transport 'data in' function
* @param callback_data Closure data for data in function
*
* Returned object can be freed with trans_delete()
*
@ -43,7 +44,10 @@
*
*/
struct trans *
scp_trans_create(int sck);
scp_connect(const char *host, const char *port,
tis_term term_func,
ttrans_data_in data_in_func,
void *callback_data);
/**
* @brief Maps SCP_CLIENT_TYPES_E to a string

View File

@ -410,10 +410,9 @@ scp_v0s_accept(struct trans *atrans, struct SCP_SESSION *session)
in_uint16_be(in_s, height);
scp_session_set_height(session, height);
in_uint16_be(in_s, bpp);
if (session_type == SCP_SESSION_TYPE_XORG && bpp != 24)
if (session_type == SCP_SESSION_TYPE_XORG)
{
LOG(LOG_LEVEL_WARNING,
"Setting bpp to 24 from %d for Xorg session", bpp);
/* Client value is ignored */
bpp = 24;
}
if (0 != scp_session_set_bpp(session, (tui8)bpp))

View File

@ -60,6 +60,9 @@ scp_v0c_gateway_request(struct trans *atrans,
const char *username,
const char *password);
/*
* Note client bpp is ignored by the sesman for Xorg sessions
*/
enum SCP_CLIENT_STATES_E
scp_v0c_create_session_request(struct trans *atrans,
const char *username,

View File

@ -53,7 +53,6 @@ int main(int argc, char **argv)
//int end;
int idx;
//int sel;
int sock;
char *pwd;
struct log_config *logging;
@ -128,21 +127,14 @@ int main(int argc, char **argv)
scp_init();
sock = g_tcp_socket();
if (sock < 0)
{
LOG_DEVEL(LOG_LEVEL_DEBUG, "Socket open error, g_tcp_socket() failed");
return 1;
}
s = scp_session_create();
t = scp_trans_create(sock);
LOG_DEVEL(LOG_LEVEL_DEBUG, "Connecting to %s:%s)", serv, port);
t = scp_connect(serv, port, NULL, NULL, NULL);
LOG_DEVEL(LOG_LEVEL_DEBUG, "Connecting to %s:%s with user %s (%s)", serv, port, user, pass);
if (0 != trans_connect(t, serv, port, 3000))
if (t == NULL)
{
LOG(LOG_LEVEL_ERROR, "trans_connect() error");
LOG(LOG_LEVEL_ERROR, "scp_connect() error");
return 1;
}

View File

@ -46,7 +46,6 @@ int main(int argc, char **argv)
int scnt;
int idx;
int sel;
int sock;
logging = log_config_init_for_console(LOG_LEVEL_INFO, NULL);
log_start_from_param(logging);
@ -54,16 +53,9 @@ int main(int argc, char **argv)
scp_init();
sock = g_tcp_socket();
if (sock < 0)
{
return 1;
}
s = scp_session_create();
t = scp_trans_create(sock);
if (0 != trans_connect(t, "localhost", "3350", 3000))
t = scp_connect("localhost", "3350", NULL, NULL, NULL);
if (t == NULL)
{
g_printf("error connecting");
return 1;