aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libssh/agent.h2
-rw-r--r--include/libssh/poll.h2
-rw-r--r--include/libssh/priv.h4
-rw-r--r--include/libssh/session.h2
-rw-r--r--include/libssh/socket.h58
-rw-r--r--libssh/agent.c2
-rw-r--r--libssh/packet.c10
-rw-r--r--libssh/poll.c2
-rw-r--r--libssh/socket.c70
-rw-r--r--tests/test_socket.c2
10 files changed, 78 insertions, 76 deletions
diff --git a/include/libssh/agent.h b/include/libssh/agent.h
index fca577d1..b620b332 100644
--- a/include/libssh/agent.h
+++ b/include/libssh/agent.h
@@ -48,7 +48,7 @@
#define SSH_AGENT_OLD_SIGNATURE 0x01
struct ssh_agent_struct {
- struct socket *sock;
+ struct ssh_socket_struct *sock;
ssh_buffer ident;
unsigned int count;
};
diff --git a/include/libssh/poll.h b/include/libssh/poll.h
index ca5ec181..5d8bd3cc 100644
--- a/include/libssh/poll.h
+++ b/include/libssh/poll.h
@@ -95,7 +95,7 @@ void ssh_poll_set_callback(ssh_poll_handle p, ssh_poll_callback cb, void *userda
ssh_poll_ctx ssh_poll_ctx_new(size_t chunk_size);
void ssh_poll_ctx_free(ssh_poll_ctx ctx);
int ssh_poll_ctx_add(ssh_poll_ctx ctx, ssh_poll_handle p);
-int ssh_poll_ctx_add_socket (ssh_poll_ctx ctx, struct socket *s);
+int ssh_poll_ctx_add_socket (ssh_poll_ctx ctx, struct ssh_socket_struct *s);
void ssh_poll_ctx_remove(ssh_poll_ctx ctx, ssh_poll_handle p);
int ssh_poll_ctx_dopoll(ssh_poll_ctx ctx, int timeout);
diff --git a/include/libssh/priv.h b/include/libssh/priv.h
index c251140a..8413a22a 100644
--- a/include/libssh/priv.h
+++ b/include/libssh/priv.h
@@ -136,10 +136,10 @@ unsigned char *packet_encrypt(ssh_session session,void *packet,unsigned int len)
/* it returns the hmac buffer if exists*/
int packet_hmac_verify(ssh_session session,ssh_buffer buffer,unsigned char *mac);
-struct socket;
+struct ssh_socket_struct;
int ssh_packet_socket_callback(const void *data, size_t len, void *user);
-void ssh_packet_register_socket_callback(ssh_session session, struct socket *s);
+void ssh_packet_register_socket_callback(ssh_session session, struct ssh_socket_struct *s);
void ssh_packet_set_callbacks(ssh_session session, ssh_packet_callbacks callbacks);
void ssh_packet_set_default_callbacks(ssh_session session);
void ssh_packet_process(ssh_session session, uint8_t type);
diff --git a/include/libssh/session.h b/include/libssh/session.h
index cea2f739..09ed655d 100644
--- a/include/libssh/session.h
+++ b/include/libssh/session.h
@@ -41,7 +41,7 @@ enum ssh_session_state_e {
struct ssh_session_struct {
struct error_struct error;
- struct socket *socket;
+ struct ssh_socket_struct *socket;
char *serverbanner;
char *clientbanner;
int protoversion;
diff --git a/include/libssh/socket.h b/include/libssh/socket.h
index 0c2a6c9e..c0bc7d52 100644
--- a/include/libssh/socket.h
+++ b/include/libssh/socket.h
@@ -26,38 +26,40 @@
struct ssh_poll_handle_struct;
/* socket.c */
-struct socket;
+struct ssh_socket_struct;
+typedef struct ssh_socket_struct* ssh_socket;
+
int ssh_socket_init(void);
-struct socket *ssh_socket_new(ssh_session session);
-void ssh_socket_free(struct socket *s);
-void ssh_socket_set_fd(struct socket *s, socket_t fd);
-socket_t ssh_socket_get_fd(struct socket *s);
+ssh_socket ssh_socket_new(ssh_session session);
+void ssh_socket_free(ssh_socket s);
+void ssh_socket_set_fd(ssh_socket s, socket_t fd);
+socket_t ssh_socket_get_fd(ssh_socket s);
#ifndef _WIN32
-int ssh_socket_unix(struct socket *s, const char *path);
+int ssh_socket_unix(ssh_socket s, const char *path);
#endif
-void ssh_socket_close(struct socket *s);
-int ssh_socket_read(struct socket *s, void *buffer, int len);
-int ssh_socket_write(struct socket *s,const void *buffer, int len);
-int ssh_socket_is_open(struct socket *s);
-int ssh_socket_fd_isset(struct socket *s, fd_set *set);
-void ssh_socket_fd_set(struct socket *s, fd_set *set, int *fd_max);
-int ssh_socket_completeread(struct socket *s, void *buffer, uint32_t len);
-int ssh_socket_completewrite(struct socket *s, const void *buffer, uint32_t len);
-int ssh_socket_wait_for_data(struct socket *s, ssh_session session, uint32_t len);
-int ssh_socket_nonblocking_flush(struct socket *s);
-int ssh_socket_blocking_flush(struct socket *s);
-int ssh_socket_poll(struct socket *s, int *writeable, int *except);
-void ssh_socket_set_towrite(struct socket *s);
-void ssh_socket_set_toread(struct socket *s);
-void ssh_socket_set_except(struct socket *s);
-int ssh_socket_get_status(struct socket *s);
-int ssh_socket_data_available(struct socket *s);
-int ssh_socket_data_writable(struct socket *s);
+void ssh_socket_close(ssh_socket s);
+int ssh_socket_read(ssh_socket s, void *buffer, int len);
+int ssh_socket_write(ssh_socket s,const void *buffer, int len);
+int ssh_socket_is_open(ssh_socket s);
+int ssh_socket_fd_isset(ssh_socket s, fd_set *set);
+void ssh_socket_fd_set(ssh_socket s, fd_set *set, int *fd_max);
+int ssh_socket_completeread(ssh_socket s, void *buffer, uint32_t len);
+int ssh_socket_completewrite(ssh_socket s, const void *buffer, uint32_t len);
+int ssh_socket_wait_for_data(ssh_socket s, ssh_session session, uint32_t len);
+int ssh_socket_nonblocking_flush(ssh_socket s);
+int ssh_socket_blocking_flush(ssh_socket s);
+int ssh_socket_poll(ssh_socket s, int *writeable, int *except);
+void ssh_socket_set_towrite(ssh_socket s);
+void ssh_socket_set_toread(ssh_socket s);
+void ssh_socket_set_except(ssh_socket s);
+int ssh_socket_get_status(ssh_socket s);
+int ssh_socket_data_available(ssh_socket s);
+int ssh_socket_data_writable(ssh_socket s);
-void ssh_socket_set_callbacks(struct socket *s, ssh_socket_callbacks callbacks);
+void ssh_socket_set_callbacks(ssh_socket s, ssh_socket_callbacks callbacks);
int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, int fd, int revents, void *s);
-void ssh_socket_register_pollcallback(struct socket *s, struct ssh_poll_handle_struct *p);
-struct ssh_poll_handle_struct * ssh_socket_get_poll_handle(struct socket *s);
-int ssh_socket_connect(struct socket *s, const char *host, int port, const char *bind_addr);
+void ssh_socket_register_pollcallback(ssh_socket s, struct ssh_poll_handle_struct *p);
+struct ssh_poll_handle_struct * ssh_socket_get_poll_handle(ssh_socket s);
+int ssh_socket_connect(ssh_socket s, const char *host, int port, const char *bind_addr);
#endif /* SOCKET_H_ */
diff --git a/libssh/agent.c b/libssh/agent.c
index bada814c..a918664a 100644
--- a/libssh/agent.c
+++ b/libssh/agent.c
@@ -81,7 +81,7 @@ static void agent_put_u32(void *vp, uint32_t v) {
p[3] = (uint8_t)v & 0xff;
}
-static size_t atomicio(struct socket *s, void *buf, size_t n, int do_read) {
+static size_t atomicio(ssh_socket s, void *buf, size_t n, int do_read) {
char *b = buf;
size_t pos = 0;
ssize_t res;
diff --git a/libssh/packet.c b/libssh/packet.c
index caa47058..ef406bcc 100644
--- a/libssh/packet.c
+++ b/libssh/packet.c
@@ -275,7 +275,7 @@ error:
return processed;
}
-void ssh_packet_register_socket_callback(ssh_session session, struct socket *s){
+void ssh_packet_register_socket_callback(ssh_session session, ssh_socket s){
session->socket_callbacks.data=ssh_packet_socket_callback;
session->socket_callbacks.connected=NULL;
session->socket_callbacks.controlflow=NULL;
@@ -555,7 +555,7 @@ static int packet_read1(ssh_session session) {
}
}
- rc = ssh_socket_read(session->socket, &len, sizeof(uint32_t));
+ rc = ssh_socket_read(session->ssh_socket_struct, &len, sizeof(uint32_t));
if (rc != SSH_OK) {
goto error;
}
@@ -587,7 +587,7 @@ static int packet_read1(ssh_session session) {
goto error;
}
- rc = ssh_socket_read(session->socket, packet, to_be_read);
+ rc = ssh_socket_read(session->ssh_socket_struct, packet, to_be_read);
if(rc != SSH_OK) {
SAFE_FREE(packet);
goto error;
@@ -880,7 +880,7 @@ static int packet_send1(ssh_session session) {
ssh_print_hexa("encrypted packet",buffer_get(session->out_buffer),
buffer_get_len(session->out_buffer));
#endif
- if (ssh_socket_write(session->socket, buffer_get(session->out_buffer),
+ if (ssh_socket_write(session->ssh_socket_struct, buffer_get(session->out_buffer),
buffer_get_len(session->out_buffer)) == SSH_ERROR) {
goto error;
}
@@ -918,7 +918,7 @@ void packet_parse(ssh_session session) {
ssh_log(session, SSH_LOG_PACKET, "Received SSH_MSG_DISCONNECT");
ssh_set_error(session, SSH_FATAL, "Received SSH_MSG_DISCONNECT");
- ssh_socket_close(session->socket);
+ ssh_socket_close(session->ssh_socket_struct);
session->alive = 0;
return;
case SSH_SMSG_STDOUT_DATA:
diff --git a/libssh/poll.c b/libssh/poll.c
index 7d9e3e5a..42da4aab 100644
--- a/libssh/poll.c
+++ b/libssh/poll.c
@@ -498,7 +498,7 @@ int ssh_poll_ctx_add(ssh_poll_ctx ctx, ssh_poll_handle p) {
*
* @return 0 on success, < 0 on error
*/
-int ssh_poll_ctx_add_socket (ssh_poll_ctx ctx, struct socket *s) {
+int ssh_poll_ctx_add_socket (ssh_poll_ctx ctx, ssh_socket s) {
ssh_poll_handle p=ssh_socket_get_poll_handle(s);
if(p==NULL)
return -1;
diff --git a/libssh/socket.c b/libssh/socket.c
index 9c04ff96..a1a0e2cd 100644
--- a/libssh/socket.c
+++ b/libssh/socket.c
@@ -53,7 +53,7 @@ enum ssh_socket_states_e {
SSH_SOCKET_CLOSED
};
-struct socket {
+struct ssh_socket_struct {
socket_t fd;
int last_errno;
int data_to_read; /* reading now on socket will
@@ -68,8 +68,8 @@ struct socket {
ssh_poll_handle poll;
};
-static int ssh_socket_unbuffered_read(struct socket *s, void *buffer, uint32_t len);
-static int ssh_socket_unbuffered_write(struct socket *s, const void *buffer,
+static int ssh_socket_unbuffered_read(ssh_socket s, void *buffer, uint32_t len);
+static int ssh_socket_unbuffered_write(ssh_socket s, const void *buffer,
uint32_t len);
/*
@@ -91,10 +91,10 @@ int ssh_socket_init(void) {
* \internal
* \brief creates a new Socket object
*/
-struct socket *ssh_socket_new(ssh_session session) {
- struct socket *s;
+ssh_socket ssh_socket_new(ssh_session session) {
+ ssh_socket s;
- s = malloc(sizeof(struct socket));
+ s = malloc(sizeof(struct ssh_socket_struct));
if (s == NULL) {
return NULL;
}
@@ -127,12 +127,12 @@ struct socket *ssh_socket_new(ssh_session session) {
* @param callbacks a ssh_socket_callback object reference
*/
-void ssh_socket_set_callbacks(struct socket *s, ssh_socket_callbacks callbacks){
+void ssh_socket_set_callbacks(ssh_socket s, ssh_socket_callbacks callbacks){
s->callbacks=callbacks;
}
int ssh_socket_pollcallback(ssh_poll_handle p, int fd, int revents, void *v_s){
- struct socket *s=(struct socket *)v_s;
+ ssh_socket s=(ssh_socket )v_s;
char buffer[4096];
int r,w;
int err=0;
@@ -215,7 +215,7 @@ int ssh_socket_pollcallback(ssh_poll_handle p, int fd, int revents, void *v_s){
return 0;
}
-void ssh_socket_register_pollcallback(struct socket *s, ssh_poll_handle p){
+void ssh_socket_register_pollcallback(ssh_socket s, ssh_poll_handle p){
ssh_poll_set_callback(p,ssh_socket_pollcallback,s);
s->poll=p;
}
@@ -225,7 +225,7 @@ void ssh_socket_register_pollcallback(struct socket *s, ssh_poll_handle p){
* creates it if it does not exist.
* @returns allocated and initialized ssh_poll_handle object
*/
-ssh_poll_handle ssh_socket_get_poll_handle(struct socket *s){
+ssh_poll_handle ssh_socket_get_poll_handle(ssh_socket s){
if(s->poll)
return s->poll;
s->poll=ssh_poll_new(s->fd,0,ssh_socket_pollcallback,s);
@@ -235,7 +235,7 @@ ssh_poll_handle ssh_socket_get_poll_handle(struct socket *s){
/** \internal
* \brief Deletes a socket object
*/
-void ssh_socket_free(struct socket *s){
+void ssh_socket_free(ssh_socket s){
if (s == NULL) {
return;
}
@@ -248,7 +248,7 @@ void ssh_socket_free(struct socket *s){
}
#ifndef _WIN32
-int ssh_socket_unix(struct socket *s, const char *path) {
+int ssh_socket_unix(ssh_socket s, const char *path) {
struct sockaddr_un sunaddr;
sunaddr.sun_family = AF_UNIX;
@@ -279,7 +279,7 @@ int ssh_socket_unix(struct socket *s, const char *path) {
/* \internal
* \brief closes a socket
*/
-void ssh_socket_close(struct socket *s){
+void ssh_socket_close(ssh_socket s){
if (ssh_socket_is_open(s)) {
#ifdef _WIN32
closesocket(s->fd);
@@ -295,7 +295,7 @@ void ssh_socket_close(struct socket *s){
/* \internal
* \brief sets the file descriptor of the socket
*/
-void ssh_socket_set_fd(struct socket *s, socket_t fd) {
+void ssh_socket_set_fd(ssh_socket s, socket_t fd) {
s->fd = fd;
if(s->poll)
ssh_poll_set_fd(s->poll,fd);
@@ -304,21 +304,21 @@ void ssh_socket_set_fd(struct socket *s, socket_t fd) {
/* \internal
* \brief returns the file descriptor of the socket
*/
-socket_t ssh_socket_get_fd(struct socket *s) {
+socket_t ssh_socket_get_fd(ssh_socket s) {
return s->fd;
}
/* \internal
* \brief returns nonzero if the socket is open
*/
-int ssh_socket_is_open(struct socket *s) {
+int ssh_socket_is_open(ssh_socket s) {
return s->fd != -1;
}
/* \internal
* \brief read len bytes from socket into buffer
*/
-static int ssh_socket_unbuffered_read(struct socket *s, void *buffer, uint32_t len) {
+static int ssh_socket_unbuffered_read(ssh_socket s, void *buffer, uint32_t len) {
int rc = -1;
if (s->data_except) {
@@ -343,7 +343,7 @@ static int ssh_socket_unbuffered_read(struct socket *s, void *buffer, uint32_t l
/* \internal
* \brief writes len bytes from buffer to socket
*/
-static int ssh_socket_unbuffered_write(struct socket *s, const void *buffer,
+static int ssh_socket_unbuffered_write(ssh_socket s, const void *buffer,
uint32_t len) {
int w = -1;
@@ -372,7 +372,7 @@ static int ssh_socket_unbuffered_write(struct socket *s, const void *buffer,
/* \internal
* \brief returns nonzero if the current socket is in the fd_set
*/
-int ssh_socket_fd_isset(struct socket *s, fd_set *set) {
+int ssh_socket_fd_isset(ssh_socket s, fd_set *set) {
if(s->fd == -1) {
return 0;
}
@@ -383,7 +383,7 @@ int ssh_socket_fd_isset(struct socket *s, fd_set *set) {
* \brief sets the current fd in a fd_set and updates the fd_max
*/
-void ssh_socket_fd_set(struct socket *s, fd_set *set, int *fd_max) {
+void ssh_socket_fd_set(ssh_socket s, fd_set *set, int *fd_max) {
if (s->fd == -1)
return;
FD_SET(s->fd,set);
@@ -395,7 +395,7 @@ void ssh_socket_fd_set(struct socket *s, fd_set *set, int *fd_max) {
/** \internal
* \brief reads blocking until len bytes have been read
*/
-int ssh_socket_completeread(struct socket *s, void *buffer, uint32_t len) {
+int ssh_socket_completeread(ssh_socket s, void *buffer, uint32_t len) {
int r = -1;
uint32_t total = 0;
uint32_t toread = len;
@@ -424,7 +424,7 @@ int ssh_socket_completeread(struct socket *s, void *buffer, uint32_t len) {
/** \internal
* \brief Blocking write of len bytes
*/
-int ssh_socket_completewrite(struct socket *s, const void *buffer, uint32_t len) {
+int ssh_socket_completewrite(ssh_socket s, const void *buffer, uint32_t len) {
ssh_session session = s->session;
int written = -1;
@@ -454,7 +454,7 @@ int ssh_socket_completewrite(struct socket *s, const void *buffer, uint32_t len)
* \returns SSH_OK or SSH_ERROR.
* \returns SSH_AGAIN in nonblocking mode
*/
-int ssh_socket_read(struct socket *s, void *buffer, int len){
+int ssh_socket_read(ssh_socket s, void *buffer, int len){
ssh_session session = s->session;
int rc = SSH_ERROR;
@@ -478,7 +478,7 @@ int ssh_socket_read(struct socket *s, void *buffer, int len){
* \returns SSH_OK, or SSH_ERROR
* \warning has no effect on socket before a flush
*/
-int ssh_socket_write(struct socket *s, const void *buffer, int len) {
+int ssh_socket_write(ssh_socket s, const void *buffer, int len) {
ssh_session session = s->session;
enter_function();
if (buffer_add_data(s->out_buffer, buffer, len) < 0) {
@@ -498,7 +498,7 @@ int ssh_socket_write(struct socket *s, const void *buffer, int len) {
* \returns SSH_AGAIN need to call later for data
* \returns SSH_ERROR error happened
*/
-int ssh_socket_wait_for_data(struct socket *s, ssh_session session, uint32_t len) {
+int ssh_socket_wait_for_data(ssh_socket s, ssh_session session, uint32_t len) {
char buffer[4096] = {0};
char *buf = NULL;
int except;
@@ -585,7 +585,7 @@ int ssh_socket_wait_for_data(struct socket *s, ssh_session session, uint32_t len
}
/* ssh_socket_poll */
-int ssh_socket_poll(struct socket *s, int *writeable, int *except) {
+int ssh_socket_poll(ssh_socket s, int *writeable, int *except) {
ssh_session session = s->session;
ssh_pollfd_t fd[1];
int rc = -1;
@@ -637,7 +637,7 @@ int ssh_socket_poll(struct socket *s, int *writeable, int *except) {
* \brief starts a nonblocking flush of the output buffer
*
*/
-int ssh_socket_nonblocking_flush(struct socket *s) {
+int ssh_socket_nonblocking_flush(ssh_socket s) {
ssh_session session = s->session;
int w;
@@ -688,7 +688,7 @@ int ssh_socket_nonblocking_flush(struct socket *s) {
/** \internal
* \brief locking flush of the output packet buffer
*/
-int ssh_socket_blocking_flush(struct socket *s) {
+int ssh_socket_blocking_flush(ssh_socket s) {
ssh_session session = s->session;
enter_function();
@@ -732,27 +732,27 @@ int ssh_socket_blocking_flush(struct socket *s) {
return SSH_OK; // no data pending
}
-void ssh_socket_set_towrite(struct socket *s) {
+void ssh_socket_set_towrite(ssh_socket s) {
s->data_to_write = 1;
}
-void ssh_socket_set_toread(struct socket *s) {
+void ssh_socket_set_toread(ssh_socket s) {
s->data_to_read = 1;
}
-void ssh_socket_set_except(struct socket *s) {
+void ssh_socket_set_except(ssh_socket s) {
s->data_except = 1;
}
-int ssh_socket_data_available(struct socket *s) {
+int ssh_socket_data_available(ssh_socket s) {
return s->data_to_read;
}
-int ssh_socket_data_writable(struct socket *s) {
+int ssh_socket_data_writable(ssh_socket s) {
return s->data_to_write;
}
-int ssh_socket_get_status(struct socket *s) {
+int ssh_socket_get_status(ssh_socket s) {
int r = 0;
if (s->data_to_read) {
@@ -780,7 +780,7 @@ int ssh_socket_get_status(struct socket *s) {
* which is problematic for hosts having DNS fail-over
*/
-int ssh_socket_connect(struct socket *s, const char *host, int port, const char *bind_addr){
+int ssh_socket_connect(ssh_socket s, const char *host, int port, const char *bind_addr){
socket_t fd;
ssh_session session=s->session;
ssh_poll_ctx ctx;
diff --git a/tests/test_socket.c b/tests/test_socket.c
index 118287a0..84f7b35e 100644
--- a/tests/test_socket.c
+++ b/tests/test_socket.c
@@ -31,7 +31,7 @@
#include <libssh/poll.h>
int stop=0;
-struct socket *s;
+ssh_socket s;
static int data_rcv(const void *data, size_t len, void *user){
printf("Received data: '");