converted listeners to the linked list functions
This commit is contained in:
@@ -92,7 +92,7 @@ LIBSSH2_CHANNEL *
|
|||||||
_libssh2_channel_locate(LIBSSH2_SESSION *session, unsigned long channel_id)
|
_libssh2_channel_locate(LIBSSH2_SESSION *session, unsigned long channel_id)
|
||||||
{
|
{
|
||||||
LIBSSH2_CHANNEL *channel;
|
LIBSSH2_CHANNEL *channel;
|
||||||
LIBSSH2_LISTENER *listener;
|
LIBSSH2_LISTENER *l;
|
||||||
|
|
||||||
for(channel = session->channels.head; channel; channel = channel->next) {
|
for(channel = session->channels.head; channel; channel = channel->next) {
|
||||||
if (channel->local.id == channel_id)
|
if (channel->local.id == channel_id)
|
||||||
@@ -101,8 +101,9 @@ _libssh2_channel_locate(LIBSSH2_SESSION *session, unsigned long channel_id)
|
|||||||
|
|
||||||
/* We didn't find the channel in the session, let's then check its
|
/* We didn't find the channel in the session, let's then check its
|
||||||
listeners... */
|
listeners... */
|
||||||
for(listener = session->listeners; listener; listener = listener->next) {
|
for(l = _libssh2_list_first(&session->listeners); l;
|
||||||
for(channel = listener->queue; channel; channel = channel->next) {
|
l = _libssh2_list_next(&l->node)) {
|
||||||
|
for(channel = l->queue; channel; channel = channel->next) {
|
||||||
if (channel->local.id == channel_id)
|
if (channel->local.id == channel_id)
|
||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
@@ -585,12 +586,8 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
|
|||||||
listener->queue_size = 0;
|
listener->queue_size = 0;
|
||||||
listener->queue_maxsize = queue_maxsize;
|
listener->queue_maxsize = queue_maxsize;
|
||||||
|
|
||||||
listener->next = session->listeners;
|
/* append this to the parent's list of listeners */
|
||||||
listener->prev = NULL;
|
_libssh2_list_add(&session->listeners, &listener->node);
|
||||||
if (session->listeners) {
|
|
||||||
session->listeners->prev = listener;
|
|
||||||
}
|
|
||||||
session->listeners = listener;
|
|
||||||
|
|
||||||
if (bound_port) {
|
if (bound_port) {
|
||||||
*bound_port = listener->port;
|
*bound_port = listener->port;
|
||||||
@@ -713,14 +710,8 @@ static int channel_forward_cancel(LIBSSH2_LISTENER *listener)
|
|||||||
}
|
}
|
||||||
LIBSSH2_FREE(session, listener->host);
|
LIBSSH2_FREE(session, listener->host);
|
||||||
|
|
||||||
if (listener->next) {
|
/* remove this entry from the parent's list of listeners */
|
||||||
listener->next->prev = listener->prev;
|
_libssh2_list_remove(&listener->node);
|
||||||
}
|
|
||||||
if (listener->prev) {
|
|
||||||
listener->prev->next = listener->next;
|
|
||||||
} else {
|
|
||||||
session->listeners = listener->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
LIBSSH2_FREE(session, listener);
|
LIBSSH2_FREE(session, listener);
|
||||||
|
|
||||||
|
|||||||
@@ -437,6 +437,8 @@ struct _LIBSSH2_CHANNEL_BRIGADE
|
|||||||
|
|
||||||
struct _LIBSSH2_LISTENER
|
struct _LIBSSH2_LISTENER
|
||||||
{
|
{
|
||||||
|
struct list_node node; /* linked list header */
|
||||||
|
|
||||||
LIBSSH2_SESSION *session;
|
LIBSSH2_SESSION *session;
|
||||||
|
|
||||||
char *host;
|
char *host;
|
||||||
@@ -446,8 +448,6 @@ struct _LIBSSH2_LISTENER
|
|||||||
int queue_size;
|
int queue_size;
|
||||||
int queue_maxsize;
|
int queue_maxsize;
|
||||||
|
|
||||||
LIBSSH2_LISTENER *prev, *next;
|
|
||||||
|
|
||||||
/* State variables used in libssh2_channel_forward_cancel() */
|
/* State variables used in libssh2_channel_forward_cancel() */
|
||||||
libssh2_nonblocking_states chanFwdCncl_state;
|
libssh2_nonblocking_states chanFwdCncl_state;
|
||||||
unsigned char *chanFwdCncl_data;
|
unsigned char *chanFwdCncl_data;
|
||||||
@@ -724,7 +724,7 @@ struct _LIBSSH2_SESSION
|
|||||||
LIBSSH2_CHANNEL_BRIGADE channels;
|
LIBSSH2_CHANNEL_BRIGADE channels;
|
||||||
unsigned long next_channel;
|
unsigned long next_channel;
|
||||||
|
|
||||||
LIBSSH2_LISTENER *listeners;
|
struct list_head listeners; /* list of LIBSSH2_LISTENER structs */
|
||||||
|
|
||||||
/* Actual I/O socket */
|
/* Actual I/O socket */
|
||||||
int socket_fd;
|
int socket_fd;
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
|
|||||||
/* 17 = packet_type(1) + channel(4) + reason(4) + descr(4) + lang(4) */
|
/* 17 = packet_type(1) + channel(4) + reason(4) + descr(4) + lang(4) */
|
||||||
unsigned long packet_len = 17 + (sizeof(FwdNotReq) - 1);
|
unsigned long packet_len = 17 + (sizeof(FwdNotReq) - 1);
|
||||||
unsigned char *p;
|
unsigned char *p;
|
||||||
LIBSSH2_LISTENER *listen = session->listeners;
|
LIBSSH2_LISTENER *listen = _libssh2_list_first(&session->listeners);
|
||||||
char failure_code = 1; /* SSH_OPEN_ADMINISTRATIVELY_PROHIBITED */
|
char failure_code = 1; /* SSH_OPEN_ADMINISTRATIVELY_PROHIBITED */
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
@@ -238,7 +238,7 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
listen = listen->next;
|
listen = _libssh2_list_next(&listen->node);
|
||||||
}
|
}
|
||||||
|
|
||||||
listen_state->state = libssh2_NB_state_sent;
|
listen_state->state = libssh2_NB_state_sent;
|
||||||
|
|||||||
@@ -734,12 +734,12 @@ session_free(LIBSSH2_SESSION *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (session->state == libssh2_NB_state_sent) {
|
if (session->state == libssh2_NB_state_sent) {
|
||||||
while (session->listeners) {
|
LIBSSH2_LISTENER *l;
|
||||||
rc = libssh2_channel_forward_cancel(session->listeners);
|
while (l = _libssh2_list_first(&session->listeners)) {
|
||||||
if (rc == PACKET_EAGAIN) {
|
rc = libssh2_channel_forward_cancel(l);
|
||||||
|
if (rc == PACKET_EAGAIN)
|
||||||
return PACKET_EAGAIN;
|
return PACKET_EAGAIN;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
session->state = libssh2_NB_state_sent1;
|
session->state = libssh2_NB_state_sent1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user