Pointer parameter could be declared as pointing to const (callback)

This commit is contained in:
Francois Perrad 2017-08-19 22:39:53 +02:00
parent 89e64c631e
commit 598056d168
12 changed files with 30 additions and 30 deletions

View File

@ -84,7 +84,7 @@ struct Channel {
int flushing; int flushing;
/* Used by client chansession to handle ~ escaping, NULL ignored otherwise */ /* Used by client chansession to handle ~ escaping, NULL ignored otherwise */
void (*read_mangler)(struct Channel*, unsigned char* bytes, int *len); void (*read_mangler)(const struct Channel*, const unsigned char* bytes, int *len);
const struct ChanType* type; const struct ChanType* type;
@ -98,7 +98,7 @@ struct ChanType {
int (*inithandler)(struct Channel*); int (*inithandler)(struct Channel*);
int (*check_close)(struct Channel*); int (*check_close)(struct Channel*);
void (*reqhandler)(struct Channel*); void (*reqhandler)(struct Channel*);
void (*closehandler)(struct Channel*); void (*closehandler)(const struct Channel*);
}; };
/* Callback for connect_remote */ /* Callback for connect_remote */

View File

@ -35,12 +35,12 @@
#include "chansession.h" #include "chansession.h"
#include "agentfwd.h" #include "agentfwd.h"
static void cli_closechansess(struct Channel *channel); static void cli_closechansess(const struct Channel *channel);
static int cli_initchansess(struct Channel *channel); static int cli_initchansess(struct Channel *channel);
static void cli_chansessreq(struct Channel *channel); static void cli_chansessreq(struct Channel *channel);
static void send_chansess_pty_req(const struct Channel *channel); static void send_chansess_pty_req(const struct Channel *channel);
static void send_chansess_shell_req(const struct Channel *channel); static void send_chansess_shell_req(const struct Channel *channel);
static void cli_escape_handler(struct Channel *channel, unsigned char* buf, int *len); static void cli_escape_handler(const struct Channel *channel, const unsigned char* buf, int *len);
static int cli_init_netcat(struct Channel *channel); static int cli_init_netcat(struct Channel *channel);
static void cli_tty_setup(void); static void cli_tty_setup(void);
@ -83,7 +83,7 @@ out:
/* If the main session goes, we close it up */ /* If the main session goes, we close it up */
static void cli_closechansess(struct Channel *UNUSED(channel)) { static void cli_closechansess(const struct Channel *UNUSED(channel)) {
cli_tty_cleanup(); /* Restore tty modes etc */ cli_tty_cleanup(); /* Restore tty modes etc */
/* This channel hasn't gone yet, so we have > 1 */ /* This channel hasn't gone yet, so we have > 1 */
@ -452,7 +452,7 @@ do_escape(unsigned char c) {
} }
static static
void cli_escape_handler(struct Channel* UNUSED(channel), unsigned char* buf, int *len) { void cli_escape_handler(const struct Channel* UNUSED(channel), const unsigned char* buf, int *len) {
char c; char c;
int skip_char = 0; int skip_char = 0;

View File

@ -142,7 +142,7 @@ static void cli_dropbear_log(int priority,
fflush(stderr); fflush(stderr);
} }
static void exec_proxy_cmd(void *user_data_cmd) { static void exec_proxy_cmd(const void *user_data_cmd) {
const char *cmd = user_data_cmd; const char *cmd = user_data_cmd;
char *usershell; char *usershell;

View File

@ -241,7 +241,7 @@ int connect_unix(const char* path) {
* it will be run after the child has fork()ed, and is passed exec_data. * it will be run after the child has fork()ed, and is passed exec_data.
* If ret_errfd == NULL then stderr will not be captured. * If ret_errfd == NULL then stderr will not be captured.
* ret_pid can be passed as NULL to discard the pid. */ * ret_pid can be passed as NULL to discard the pid. */
int spawn_command(void(*exec_fn)(void *user_data), void *exec_data, int spawn_command(void(*exec_fn)(const void *user_data), const void *exec_data,
int *ret_writefd, int *ret_readfd, int *ret_errfd, pid_t *ret_pid) { int *ret_writefd, int *ret_readfd, int *ret_errfd, pid_t *ret_pid) {
int infds[2]; int infds[2];
int outfds[2]; int outfds[2];

View File

@ -56,7 +56,7 @@ extern int debug_trace;
char * stripcontrol(const char * text); char * stripcontrol(const char * text);
int spawn_command(void(*exec_fn)(void *user_data), void *exec_data, int spawn_command(void(*exec_fn)(const void *user_data), const void *exec_data,
int *writefd, int *readfd, int *errfd, pid_t *pid); int *writefd, int *readfd, int *errfd, pid_t *pid);
void run_shell_command(const char* cmd, unsigned int maxfd, char* usershell); void run_shell_command(const char* cmd, unsigned int maxfd, char* usershell);
#ifdef ENABLE_CONNECT_UNIX #ifdef ENABLE_CONNECT_UNIX

View File

@ -78,8 +78,8 @@ void handle_listeners(const fd_set * readfds) {
* cleanup(void* typedata) happens when cleaning up */ * cleanup(void* typedata) happens when cleaning up */
struct Listener* new_listener(const int socks[], unsigned int nsocks, struct Listener* new_listener(const int socks[], unsigned int nsocks,
int type, void* typedata, int type, void* typedata,
void (*acceptor)(struct Listener* listener, int sock), void (*acceptor)(const struct Listener* listener, int sock),
void (*cleanup)(struct Listener*)) { void (*cleanup)(const struct Listener*)) {
unsigned int i, j; unsigned int i, j;
struct Listener *newlisten = NULL; struct Listener *newlisten = NULL;
@ -132,8 +132,8 @@ struct Listener* new_listener(const int socks[], unsigned int nsocks,
/* Return the first listener which matches the type-specific comparison /* Return the first listener which matches the type-specific comparison
* function. Particularly needed for global requests, like tcp */ * function. Particularly needed for global requests, like tcp */
struct Listener * get_listener(int type, void* typedata, struct Listener * get_listener(int type, const void* typedata,
int (*match)(void*, void*)) { int (*match)(const void*, const void*)) {
unsigned int i; unsigned int i;
struct Listener* listener; struct Listener* listener;

View File

@ -35,8 +35,8 @@ struct Listener {
int index; /* index in the array of listeners */ int index; /* index in the array of listeners */
void (*acceptor)(struct Listener*, int sock); void (*acceptor)(const struct Listener*, int sock);
void (*cleanup)(struct Listener*); void (*cleanup)(const struct Listener*);
int type; /* CHANNEL_ID_X11, CHANNEL_ID_AGENT, int type; /* CHANNEL_ID_X11, CHANNEL_ID_AGENT,
CHANNEL_ID_TCPDIRECT (for clients), CHANNEL_ID_TCPDIRECT (for clients),
@ -52,11 +52,11 @@ void set_listener_fds(fd_set * readfds);
struct Listener* new_listener(const int socks[], unsigned int nsocks, struct Listener* new_listener(const int socks[], unsigned int nsocks,
int type, void* typedata, int type, void* typedata,
void (*acceptor)(struct Listener* listener, int sock), void (*acceptor)(const struct Listener* listener, int sock),
void (*cleanup)(struct Listener*)); void (*cleanup)(const struct Listener*));
struct Listener * get_listener(int type, void* typedata, struct Listener * get_listener(int type, const void* typedata,
int (*match)(void*, void*)); int (*match)(const void*, const void*));
void remove_listener(struct Listener* listener); void remove_listener(struct Listener* listener);

View File

@ -45,7 +45,7 @@
static int send_msg_channel_open_agent(int fd); static int send_msg_channel_open_agent(int fd);
static int bindagent(int fd, struct ChanSess * chansess); static int bindagent(int fd, struct ChanSess * chansess);
static void agentaccept(struct Listener * listener, int sock); static void agentaccept(const struct Listener * listener, int sock);
/* Handles client requests to start agent forwarding, sets up listening socket. /* Handles client requests to start agent forwarding, sets up listening socket.
* Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
@ -100,7 +100,7 @@ fail:
/* accepts a connection on the forwarded socket and opens a new channel for it /* accepts a connection on the forwarded socket and opens a new channel for it
* back to the client */ * back to the client */
/* returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ /* returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
static void agentaccept(struct Listener *UNUSED(listener), int sock) { static void agentaccept(const struct Listener *UNUSED(listener), int sock) {
int fd; int fd;

View File

@ -47,10 +47,10 @@ static int sessionsignal(const struct ChanSess *chansess);
static int noptycommand(struct Channel *channel, struct ChanSess *chansess); static int noptycommand(struct Channel *channel, struct ChanSess *chansess);
static int ptycommand(struct Channel *channel, struct ChanSess *chansess); static int ptycommand(struct Channel *channel, struct ChanSess *chansess);
static int sessionwinchange(const struct ChanSess *chansess); static int sessionwinchange(const struct ChanSess *chansess);
static void execchild(void *user_data_chansess); static void execchild(const void *user_data_chansess);
static void addchildpid(struct ChanSess *chansess, pid_t pid); static void addchildpid(struct ChanSess *chansess, pid_t pid);
static void sesssigchild_handler(int val); static void sesssigchild_handler(int val);
static void closechansess(struct Channel *channel); static void closechansess(const struct Channel *channel);
static int newchansess(struct Channel *channel); static int newchansess(struct Channel *channel);
static void chansessionrequest(struct Channel *channel); static void chansessionrequest(struct Channel *channel);
static int sesscheckclose(const struct Channel *channel); static int sesscheckclose(const struct Channel *channel);
@ -281,7 +281,7 @@ chansess_login_alloc(const struct ChanSess *chansess) {
} }
/* clean a session channel */ /* clean a session channel */
static void closechansess(struct Channel *channel) { static void closechansess(const struct Channel *channel) {
struct ChanSess *chansess; struct ChanSess *chansess;
unsigned int i; unsigned int i;
@ -898,7 +898,7 @@ static void addchildpid(struct ChanSess *chansess, pid_t pid) {
/* Clean up, drop to user privileges, set up the environment and execute /* Clean up, drop to user privileges, set up the environment and execute
* the command/shell. This function does not return. */ * the command/shell. This function does not return. */
static void execchild(void *user_data) { static void execchild(const void *user_data) {
struct ChanSess *chansess = user_data; struct ChanSess *chansess = user_data;
char *usershell = NULL; char *usershell = NULL;

View File

@ -107,7 +107,7 @@ out:
TRACE(("leave recv_msg_global_request")) TRACE(("leave recv_msg_global_request"))
} }
static int matchtcp(void* typedata1, void* typedata2) { static int matchtcp(const void* typedata1, const void* typedata2) {
const struct TCPListener *info1 = (struct TCPListener*)typedata1; const struct TCPListener *info1 = (struct TCPListener*)typedata1;
const struct TCPListener *info2 = (struct TCPListener*)typedata2; const struct TCPListener *info2 = (struct TCPListener*)typedata2;

View File

@ -38,7 +38,7 @@
#define X11BASEPORT 6000 #define X11BASEPORT 6000
#define X11BINDBASE 6010 #define X11BINDBASE 6010
static void x11accept(struct Listener* listener, int sock); static void x11accept(const struct Listener* listener, int sock);
static int bindport(int fd); static int bindport(int fd);
static int send_msg_channel_open_x11(int fd, const struct sockaddr_in* addr); static int send_msg_channel_open_x11(int fd, const struct sockaddr_in* addr);
@ -126,7 +126,7 @@ fail:
/* accepts a new X11 socket */ /* accepts a new X11 socket */
/* returns DROPBEAR_FAILURE or DROPBEAR_SUCCESS */ /* returns DROPBEAR_FAILURE or DROPBEAR_SUCCESS */
static void x11accept(struct Listener* listener, int sock) { static void x11accept(const struct Listener* listener, int sock) {
int fd; int fd;
struct sockaddr_in addr; struct sockaddr_in addr;

View File

@ -35,7 +35,7 @@
#if DROPBEAR_TCP_ACCEPT #if DROPBEAR_TCP_ACCEPT
static void cleanup_tcp(struct Listener *listener) { static void cleanup_tcp(const struct Listener *listener) {
struct TCPListener *tcpinfo = (struct TCPListener*)(listener->typedata); struct TCPListener *tcpinfo = (struct TCPListener*)(listener->typedata);
@ -52,7 +52,7 @@ int tcp_prio_inithandler(struct Channel* channel)
return 0; return 0;
} }
static void tcp_acceptor(struct Listener *listener, int sock) { static void tcp_acceptor(const struct Listener *listener, int sock) {
int fd; int fd;
struct sockaddr_storage sa; struct sockaddr_storage sa;