[PATCH/RFC V2 08/26] Move vpninfo default settings into library
Kevin Cernekee
cernekee at gmail.com
Sun Aug 11 21:49:09 EDT 2013
This allows main.c to call openconnect_vpninfo_new() to create the
library instance.
Signed-off-by: Kevin Cernekee <cernekee at gmail.com>
---
library.c | 12 +++++++++---
main.c | 34 +++++++---------------------------
openconnect-internal.h | 2 +-
3 files changed, 17 insertions(+), 31 deletions(-)
diff --git a/library.c b/library.c
index 95afe9c..c0ec763 100644
--- a/library.c
+++ b/library.c
@@ -50,16 +50,21 @@ 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->cancel_fd = vpninfo->cancel_fd_write = -1;
vpninfo->cert_expire_warning = 60 * 86400;
+ vpninfo->deflate = 1;
+ vpninfo->dtls_attempt_period = 60;
+ vpninfo->max_qlen = 10;
+ vpninfo->reconnect_interval = RECONNECT_INTERVAL_MIN;
+ vpninfo->reconnect_timeout = 300;
+ 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->cancel_fd = -1;
- vpninfo->cancel_fd_write = -1;
vpninfo->xmlpost = 1;
openconnect_set_reported_os(vpninfo, NULL);
@@ -153,6 +158,7 @@ void openconnect_vpninfo_free(struct openconnect_info *vpninfo)
#endif
vpninfo->peer_cert = NULL;
}
+ free(vpninfo->localname);
free(vpninfo->useragent);
#ifdef HAVE_LIBSTOKEN
if (vpninfo->stoken_pin)
diff --git a/main.c b/main.c
index 9253b71..faf0448 100644
--- a/main.c
+++ b/main.c
@@ -509,38 +509,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, 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->reconnect_interval = RECONNECT_INTERVAL_MIN;
- vpninfo->reconnect_timeout = 300;
- 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;
+
vpninfo->cbdata = vpninfo;
- vpninfo->cert_expire_warning = 60 * 86400;
- vpninfo->cancel_fd = -1;
- vpninfo->xmlpost = 1;
-
- if (!uname(&utsbuf))
- vpninfo->localname = utsbuf.nodename;
- else
- vpninfo->localname = "localhost";
+ if (!uname(&utsbuf)) {
+ free(vpninfo->localname);
+ vpninfo->localname = xstrdup(utsbuf.nodename);
+ }
while ((opt = next_option(argc, argv, &config_arg))) {
diff --git a/openconnect-internal.h b/openconnect-internal.h
index ebb7aa5..226cd72 100644
--- a/openconnect-internal.h
+++ b/openconnect-internal.h
@@ -157,7 +157,7 @@ struct openconnect_info {
char *proxy;
int proxy_port;
- const char *localname;
+ char *localname;
char *hostname;
char *unique_hostname;
int port;
--
1.7.9.5
More information about the openconnect-devel
mailing list