Commit e44495fb authored by Kevin Cernekee's avatar Kevin Cernekee

Move vpninfo default settings into library

This allows main.c to call openconnect_vpninfo_new() to create the
library instance.
Signed-off-by: default avatarKevin Cernekee <cernekee@gmail.com>
parent fc34c007
......@@ -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);
......@@ -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
......
......@@ -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))) {
......
......@@ -159,7 +159,7 @@ struct openconnect_info {
char *proxy;
int proxy_port;
const char *localname;
char *localname;
char *hostname;
char *unique_hostname;
int port;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment