Don't forget the Port variable when creating an invitation URL.

This commit is contained in:
Guus Sliepen 2013-07-25 17:17:33 +02:00
parent d1e01bc880
commit d6a67266c8

View file

@ -42,6 +42,8 @@ int addressfamily = AF_UNSPEC;
char *get_my_hostname() { char *get_my_hostname() {
char *hostname = NULL; char *hostname = NULL;
char *port = NULL;
char *hostport = NULL;
char *name = get_my_name(false); char *name = get_my_name(false);
char *filename = NULL; char *filename = NULL;
@ -61,20 +63,21 @@ char *get_my_hostname() {
if(*q == '=') if(*q == '=')
q += 1 + strspn(q + 1, "\t "); q += 1 + strspn(q + 1, "\t ");
*p = 0; *p = 0;
if(strcasecmp(line, "Address"))
continue;
p = q + strcspn(q, "\t "); p = q + strcspn(q, "\t ");
if(*p) if(*p)
*p++ = 0; *p++ = 0;
p += strspn(p, "\t "); p += strspn(p, "\t ");
p[strcspn(p, "\t ")] = 0; p[strcspn(p, "\t ")] = 0;
if(!port && !strcasecmp(line, "Port")) {
port = xstrdup(q);
continue;
}
if(strcasecmp(line, "Address"))
continue;
hostname = xstrdup(q);
if(*p) { if(*p) {
if(strchr(q, ':')) free(port);
xasprintf(&hostname, "[%s]:%s", q, p); port = xstrdup(p);
else
xasprintf(&hostname, "%s:%s", q, p);
} else {
hostname = xstrdup(q);
} }
break; break;
} }
@ -82,10 +85,8 @@ char *get_my_hostname() {
} }
} }
if(hostname) { if(hostname)
free(filename); goto done;
return hostname;
}
// If that doesn't work, guess externally visible hostname // If that doesn't work, guess externally visible hostname
fprintf(stderr, "Trying to discover externally visible hostname...\n"); fprintf(stderr, "Trying to discover externally visible hostname...\n");
@ -142,7 +143,7 @@ again:
if(!rstrip(line)) { if(!rstrip(line)) {
if(hostname) if(hostname)
goto done; goto save;
else else
goto again; goto again;
} }
@ -157,7 +158,7 @@ again:
free(hostname); free(hostname);
hostname = xstrdup(line); hostname = xstrdup(line);
done: save:
if(filename) { if(filename) {
FILE *f = fopen(filename, "a"); FILE *f = fopen(filename, "a");
if(f) { if(f) {
@ -166,10 +167,23 @@ done:
} else { } else {
fprintf(stderr, "Could not append Address to %s: %s\n", filename, strerror(errno)); fprintf(stderr, "Could not append Address to %s: %s\n", filename, strerror(errno));
} }
free(filename);
} }
return hostname; done:
if(port) {
if(strchr(hostname, ':'))
xasprintf(&hostport, "[%s]:%s", hostname, port);
else
xasprintf(&hostport, "%s:%s", hostname, port);
} else {
hostport = hostname;
hostname = NULL;
}
free(hostname);
free(port);
free(filename);
return hostport;
} }
static bool fcopy(FILE *out, const char *filename) { static bool fcopy(FILE *out, const char *filename) {