SCP: Add scp_init_trans_from_fd()

This commit is contained in:
matt335672 2023-01-19 14:21:39 +00:00
parent e96d77bac1
commit f79f8bfa70
2 changed files with 48 additions and 1 deletions

View File

@ -195,7 +195,38 @@ scp_init_trans(struct trans *trans)
}
/*****************************************************************************/
struct trans *
scp_init_trans_from_fd(int fd, int trans_type, int (*term_func)(void))
{
struct trans *result;
if ((result = trans_create(TRANS_MODE_UNIX, 128, 128)) == NULL)
{
LOG(LOG_LEVEL_ERROR, "Can't create SCP transport [%s]",
g_get_strerror());
}
else
{
result->sck = fd;
result->type1 = trans_type;
result->status = TRANS_STATUS_UP;
result->is_term = term_func;
// Make sure child processes don't inherit our FD
(void)g_file_set_cloexec(result->sck, 1);
if (scp_init_trans(result) != 0)
{
LOG(LOG_LEVEL_ERROR, "scp_init_trans() call failed");
trans_delete(result);
result = NULL;
}
}
return result;
}
/*****************************************************************************/
int
scp_msg_in_check_available(struct trans *trans, int *available)
{

View File

@ -125,7 +125,7 @@ scp_connect(const char *port,
* Converts a standard trans connected to an SCP endpoint to an SCP transport
*
* If you are running on a client, you may wish to use
* scp_send_set_peername_request() after the commnect to inform the
* scp_send_set_peername_request() after the connect to inform the
* server who you are.
*
* @param trans connected endpoint
@ -134,6 +134,22 @@ scp_connect(const char *port,
int
scp_init_trans(struct trans *trans);
/**
* Creates an SCP transport from a file descriptor
*
* If you are running on a client, you may wish to use
* scp_send_set_peername_request() after the connect to inform the
* server who you are.
*
* @param fd file descriptor
* @param trans_type TRANS_TYPE_SERVER or TRANS_TYPE_CLIENT
* @param term_func Function to poll during connection for program
* termination, or NULL for none.
* @return SCP transport, or NULL
*/
struct trans *
scp_init_trans_from_fd(int fd, int trans_type, int (*term_func)(void));
/**
* Checks an SCP transport to see if a complete message is
* available for parsing