Skip to content

Commit

Permalink
Add new helper functions to support cmd_fd feature
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
  • Loading branch information
cernekee committed Jan 15, 2014
1 parent 5e4048b commit 60d4e18
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
3 changes: 3 additions & 0 deletions openconnect-internal.h
Expand Up @@ -298,6 +298,7 @@ struct openconnect_info {

int cmd_fd;
int cmd_fd_write;
int got_cancel_cmd;

struct pkt *incoming_queue;
struct pkt *outgoing_queue;
Expand Down Expand Up @@ -403,7 +404,9 @@ const char *keystore_strerror(int err);
int keystore_fetch(const char *key, unsigned char **result);
#endif
void cmd_fd_set(struct openconnect_info *vpninfo, fd_set *fds, int *maxfd);
void check_cmd_fd(struct openconnect_info *vpninfo, fd_set *fds);
int is_cancel_pending(struct openconnect_info *vpninfo, fd_set *fds);
void poll_cmd_fd(struct openconnect_info *vpninfo, int timeout);

/* ${SSL_LIBRARY}.c */
int openconnect_SSL_gets(struct openconnect_info *vpninfo, char *buf, size_t len);
Expand Down
3 changes: 3 additions & 0 deletions openconnect.h
Expand Up @@ -167,6 +167,9 @@ struct oc_auth_form {
#define PRG_DEBUG 2
#define PRG_TRACE 3

/* byte commands to write into the cmd_fd */
#define OC_CMD_CANCEL 'x'

struct openconnect_info;

#define OPENCONNECT_X509 void
Expand Down
37 changes: 36 additions & 1 deletion ssl.c
Expand Up @@ -530,7 +530,42 @@ void cmd_fd_set(struct openconnect_info *vpninfo, fd_set *fds, int *maxfd)
}
}

void check_cmd_fd(struct openconnect_info *vpninfo, fd_set *fds)
{
char cmd;

if (vpninfo->cmd_fd == -1 || !FD_ISSET(vpninfo->cmd_fd, fds))
return;
if (vpninfo->cmd_fd_write == -1) {
/* legacy openconnect_set_cancel_fd() users */
vpninfo->got_cancel_cmd = 1;
return;
}

if (read(vpninfo->cmd_fd, &cmd, 1) != 1)
return;

switch (cmd) {
case OC_CMD_CANCEL:
vpninfo->got_cancel_cmd = 1;
break;
}
}

int is_cancel_pending(struct openconnect_info *vpninfo, fd_set *fds)
{
return vpninfo->cmd_fd != -1 && FD_ISSET(vpninfo->cmd_fd, fds);
check_cmd_fd(vpninfo, fds);
return vpninfo->got_cancel_cmd;
}

void poll_cmd_fd(struct openconnect_info *vpninfo, int timeout)
{
fd_set rd_set;
int maxfd = 0;
struct timeval tv = { timeout, 0 };

FD_ZERO(&rd_set);
cmd_fd_set(vpninfo, &rd_set, &maxfd);
select(maxfd + 1, &rd_set, NULL, NULL, &tv);
check_cmd_fd(vpninfo, &rd_set);
}

0 comments on commit 60d4e18

Please sign in to comment.