#define strcasestr local_strcasestr
#endif
-int parse_url(char *url, char **res_proto, char **res_host, int *res_port, char **res_path)
+int parse_url(char *url, char **res_proto, char **res_host, int *res_port,
+ char **res_path, int default_port)
{
char *proto = url;
char *host, *path, *port_str;
int port;
host = strstr(url, "://");
- if (!host)
- return -EINVAL;
- *host = 0;
- host += 3;
-
- if (!strcasecmp(proto, "https"))
- port = 443;
- else if (!strcasecmp(proto, "http"))
- port = 80;
- else if (!strcasecmp(proto, "socks") ||
- !strcasecmp(proto, "socks4") ||
- !strcasecmp(proto, "socks5"))
- port = 1080;
- else
- return -EPROTONOSUPPORT;
+ if (host) {
+ *host = 0;
+ host += 3;
+
+ if (!strcasecmp(proto, "https"))
+ port = 443;
+ else if (!strcasecmp(proto, "http"))
+ port = 80;
+ else if (!strcasecmp(proto, "socks") ||
+ !strcasecmp(proto, "socks4") ||
+ !strcasecmp(proto, "socks5"))
+ port = 1080;
+ else
+ return -EPROTONOSUPPORT;
+ } else {
+ if (default_port) {
+ proto = NULL;
+ port = default_port;
+ host = url;
+ } else
+ return -EINVAL;
+ }
path = strchr(host, '/');
if (path) {
port = new_port;
}
}
- /* Check for IPv6 literal (RFC2732) */
- if (host[0] == '[' && host[strlen(host)-1] == ']') {
- host[strlen(host)-1] = 0;
- host++;
- }
if (res_proto)
- *res_proto = strdup(proto);
+ *res_proto = proto ? strdup(proto) : NULL;
if (res_host)
*res_host = strdup(host);
if (res_port)
free(vpninfo->urlpath);
vpninfo->urlpath = NULL;
- ret = parse_url(vpninfo->redirect_url, NULL, &host, &port, &vpninfo->urlpath);
+ ret = parse_url(vpninfo->redirect_url, NULL, &host, &port, &vpninfo->urlpath, 0);
if (ret) {
vpninfo->progress(vpninfo, PRG_ERR, "Failed to parse redirected URL '%s': %s\n",
vpninfo->redirect_url, strerror(-ret));
case 'P': {
char *url = strdup(optarg);
char *scheme;
- parse_url(url, &scheme, &vpninfo->proxy, &vpninfo->proxy_port, NULL);
+ parse_url(url, &scheme, &vpninfo->proxy, &vpninfo->proxy_port, NULL, 80);
if (scheme && strcmp(scheme, "http")) {
fprintf(stderr, "Non-http proxy not supported\n");
exit(1);
if (config_lookup_host(vpninfo, argv[optind]))
exit(1);
- if (!vpninfo->hostname)
- vpninfo->hostname = strdup(argv[optind]);
+ if (!vpninfo->hostname) {
+ char *url = strdup(argv[optind]);
+ char *scheme;
+ char *group;
+
+ if (parse_url(url, &scheme, &vpninfo->hostname, &vpninfo->port,
+ &group, 443)) {
+ fprintf(stderr, "Failed to parse server URL '%s'\n",
+ url);
+ exit(1);
+ }
+ if (scheme && strcmp(scheme, "https")) {
+ fprintf(stderr, "Only https:// permitted for server URL\n");
+ exit(1);
+ }
+ if (group) {
+ free(vpninfo->urlpath);
+ vpninfo->urlpath = group;
+ }
+ free(scheme);
+ }
#ifdef SSL_UI
set_openssl_ui();
.B --useragent
.I STRING
]
-\fIserver\fR
+[https://]\fIserver\fR[:\fIport\fR][/\fIgroup\fR]
.SH DESCRIPTION
The program
int openconnect_obtain_cookie(struct openconnect_info *vpninfo);
char *openconnect_create_useragent(char *base);
int process_http_proxy(struct openconnect_info *vpninfo, int ssl_sock);
-int parse_url(char *url, char **res_proto, char **res_host, int *res_port, char **res_path);
+int parse_url(char *url, char **res_proto, char **res_host, int *res_port,
+ char **res_path, int default_port);
/* ssl_ui.c */
int set_openssl_ui(void);
<UL>
<LI><B>OpenConnect HEAD</B><BR>
<UL>
+ <LI>Allow server to be specified with <TT>https://</TT> URL, including port and pathname (which Cisco calls 'UserGroup')</LI>
<LI>Support connection through HTTP proxy.</LI>
<LI>Handle HTTP redirection with port numbers.</LI>
<LI>Handle HTTP redirection with IPv6 literal addresses.</LI>
<hr>
<address>David Woodhouse <<A HREF="mailto:dwmw2@infradead.org">dwmw2@infradead.org</A>></address>
<!-- hhmts start -->
-Last modified: Fri Jan 1 22:08:53 GMT 2010
+Last modified: Fri Jan 1 22:50:54 GMT 2010
<!-- hhmts end -->
</body> </html>
snprintf(port, 5, "%d", vpninfo->port);
}
+ if (hostname[0] == '[' && hostname[strlen(hostname)-1] == ']') {
+ hostname = strndup(hostname + 1, strlen(hostname) - 2);
+ if (!hostname)
+ return -ENOMEM;
+ hints.ai_flags |= AI_NUMERICHOST;
+ }
+
err = getaddrinfo(hostname, port, &hints, &result);
+ if (hints.ai_flags & AI_NUMERICHOST)
+ free(hostname);
+
if (err) {
vpninfo->progress(vpninfo, PRG_ERR, "getaddrinfo failed: %s\n",
gai_strerror(err));
freeaddrinfo(result);
if (ssl_sock < 0) {
- vpninfo->progress(vpninfo, PRG_ERR, "Failed to connect to host %s\n", hostname);
+ vpninfo->progress(vpninfo, PRG_ERR, "Failed to connect to host %s\n",
+ vpninfo->proxy?:vpninfo->hostname);
return -EINVAL;
}
}