Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move vpninfo default settings into library
This allows main.c to call openconnect_vpninfo_new() to create the
library instance.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
  • Loading branch information
cernekee committed Jan 15, 2014
1 parent fc34c00 commit e44495f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 29 deletions.
10 changes: 7 additions & 3 deletions library.c
Expand Up @@ -50,16 +50,19 @@ struct openconnect_info *openconnect_vpninfo_new(char *useragent,
{
struct openconnect_info *vpninfo = calloc(sizeof(*vpninfo), 1);

vpninfo->ssl_fd = -1;
vpninfo->tun_fd = vpninfo->ssl_fd = vpninfo->dtls_fd = vpninfo->new_dtls_fd = -1;
vpninfo->cmd_fd = vpninfo->cmd_fd_write = -1;
vpninfo->cert_expire_warning = 60 * 86400;
vpninfo->deflate = 1;
vpninfo->dtls_attempt_period = 60;
vpninfo->max_qlen = 10;
vpninfo->localname = strdup("localhost");
vpninfo->useragent = openconnect_create_useragent(useragent);
vpninfo->validate_peer_cert = validate_peer_cert;
vpninfo->write_new_config = write_new_config;
vpninfo->process_auth_form = process_auth_form;
vpninfo->progress = progress;
vpninfo->cbdata = privdata ? : vpninfo;
vpninfo->cmd_fd = -1;
vpninfo->cmd_fd_write = -1;
vpninfo->xmlpost = 1;
openconnect_set_reported_os(vpninfo, NULL);

Expand Down Expand Up @@ -154,6 +157,7 @@ void openconnect_vpninfo_free(struct openconnect_info *vpninfo)
#endif
vpninfo->peer_cert = NULL;
}
free(vpninfo->localname);
free(vpninfo->useragent);
free(vpninfo->authgroup);
#ifdef HAVE_LIBSTOKEN
Expand Down
32 changes: 7 additions & 25 deletions main.c
Expand Up @@ -533,36 +533,18 @@ int main(int argc, char **argv)

openconnect_init_ssl();

vpninfo = malloc(sizeof(*vpninfo));
vpninfo = openconnect_vpninfo_new((char *)"Open AnyConnect VPN Agent",
validate_peer_cert, NULL, process_auth_form_cb, write_progress, NULL);
if (!vpninfo) {
fprintf(stderr, _("Failed to allocate vpninfo structure\n"));
exit(1);
}
memset(vpninfo, 0, sizeof(*vpninfo));

/* Set up some defaults */
vpninfo->tun_fd = vpninfo->ssl_fd = vpninfo->dtls_fd = vpninfo->new_dtls_fd = -1;
vpninfo->useragent = openconnect_create_useragent("Open AnyConnect VPN Agent");
vpninfo->reqmtu = 0;
vpninfo->deflate = 1;
vpninfo->dtls_attempt_period = 60;
vpninfo->max_qlen = 10;
vpninfo->uid_csd = 0;
/* We could let them override this on the command line some day, perhaps */
openconnect_set_reported_os(vpninfo, NULL);
vpninfo->uid_csd = 0;
vpninfo->uid_csd_given = 0;
vpninfo->validate_peer_cert = validate_peer_cert;
vpninfo->process_auth_form = process_auth_form_cb;
vpninfo->cbdata = vpninfo;
vpninfo->cert_expire_warning = 60 * 86400;
vpninfo->cmd_fd = -1;
vpninfo->xmlpost = 1;

if (!uname(&utsbuf))
vpninfo->localname = utsbuf.nodename;
else
vpninfo->localname = "localhost";
vpninfo->cbdata = vpninfo;
if (!uname(&utsbuf)) {
free(vpninfo->localname);
vpninfo->localname = xstrdup(utsbuf.nodename);
}

while ((opt = next_option(argc, argv, &config_arg))) {

Expand Down
2 changes: 1 addition & 1 deletion openconnect-internal.h
Expand Up @@ -159,7 +159,7 @@ struct openconnect_info {
char *proxy;
int proxy_port;

const char *localname;
char *localname;
char *hostname;
char *unique_hostname;
int port;
Expand Down

0 comments on commit e44495f

Please sign in to comment.