xcb_open: Improve protocol/host parsing
Support scenarios where host is not set and protocol is. eg: DISPLAY=tcp/:0 as well as the "inet" and "inet6" alias for "tcp" for compatability with Xlib Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com> Reviewed-by: Jamey Sharp <jamey@minilop.net>
This commit is contained in:
parent
e4b746ac13
commit
3f79628bec
|
@ -129,7 +129,7 @@ int xcb_parse_display(const char *name, char **host, int *displayp,
|
||||||
return _xcb_parse_display(name, host, NULL, displayp, screenp);
|
return _xcb_parse_display(name, host, NULL, displayp, screenp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _xcb_open_tcp(char *host, char *protocol, const unsigned short port);
|
static int _xcb_open_tcp(const char *host, char *protocol, const unsigned short port);
|
||||||
static int _xcb_open_unix(char *protocol, const char *file);
|
static int _xcb_open_unix(char *protocol, const char *file);
|
||||||
#ifdef DNETCONN
|
#ifdef DNETCONN
|
||||||
static int _xcb_open_decnet(const char *host, char *protocol, const unsigned short port);
|
static int _xcb_open_decnet(const char *host, char *protocol, const unsigned short port);
|
||||||
|
@ -138,7 +138,7 @@ static int _xcb_open_decnet(const char *host, char *protocol, const unsigned sho
|
||||||
static int _xcb_open_abstract(char *protocol, const char *file, size_t filelen);
|
static int _xcb_open_abstract(char *protocol, const char *file, size_t filelen);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int _xcb_open(char *host, char *protocol, const int display)
|
static int _xcb_open(const char *host, char *protocol, const int display)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
static const char unix_base[] = "/tmp/.X11-unix/X";
|
static const char unix_base[] = "/tmp/.X11-unix/X";
|
||||||
|
@ -147,14 +147,16 @@ static int _xcb_open(char *host, char *protocol, const int display)
|
||||||
char *file = NULL;
|
char *file = NULL;
|
||||||
int actual_filelen;
|
int actual_filelen;
|
||||||
|
|
||||||
if(*host)
|
|
||||||
{
|
|
||||||
#ifdef HAVE_LAUNCHD
|
#ifdef HAVE_LAUNCHD
|
||||||
if(strncmp(host, "/tmp/launch", 11) == 0) {
|
if(strncmp(host, "/tmp/launch", 11) == 0) {
|
||||||
base = host;
|
base = host;
|
||||||
} else {
|
host = "";
|
||||||
|
protocol = NULL;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if(*host || protocol)
|
||||||
|
{
|
||||||
#ifdef DNETCONN
|
#ifdef DNETCONN
|
||||||
/* DECnet displays have two colons, so _xcb_parse_display will have
|
/* DECnet displays have two colons, so _xcb_parse_display will have
|
||||||
left one at the end. However, an IPv6 address can end with *two*
|
left one at the end. However, an IPv6 address can end with *two*
|
||||||
|
@ -175,9 +177,6 @@ static int _xcb_open(char *host, char *protocol, const int display)
|
||||||
unsigned short port = X_TCP_PORT + display;
|
unsigned short port = X_TCP_PORT + display;
|
||||||
return _xcb_open_tcp(host, protocol, port);
|
return _xcb_open_tcp(host, protocol, port);
|
||||||
}
|
}
|
||||||
#ifdef HAVE_LAUNCHD
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
filelen = strlen(base) + 1 + sizeof(display) * 3 + 1;
|
filelen = strlen(base) + 1 + sizeof(display) * 3 + 1;
|
||||||
|
@ -187,7 +186,7 @@ static int _xcb_open(char *host, char *protocol, const int display)
|
||||||
|
|
||||||
/* display specifies Unix socket */
|
/* display specifies Unix socket */
|
||||||
#ifdef HAVE_LAUNCHD
|
#ifdef HAVE_LAUNCHD
|
||||||
if(base == host)
|
if(strncmp(base, "/tmp/launch", 11) == 0)
|
||||||
actual_filelen = snprintf(file, filelen, "%s:%d", base, display);
|
actual_filelen = snprintf(file, filelen, "%s:%d", base, display);
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
@ -270,7 +269,7 @@ static int _xcb_open_decnet(const char *host, const char *protocol, const unsign
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int _xcb_open_tcp(char *host, char *protocol, const unsigned short port)
|
static int _xcb_open_tcp(const char *host, char *protocol, const unsigned short port)
|
||||||
{
|
{
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
|
@ -278,9 +277,16 @@ static int _xcb_open_tcp(char *host, char *protocol, const unsigned short port)
|
||||||
struct addrinfo *results, *addr;
|
struct addrinfo *results, *addr;
|
||||||
char *bracket;
|
char *bracket;
|
||||||
|
|
||||||
if (protocol && strcmp("tcp",protocol))
|
if (protocol && strcmp("tcp",protocol) && strcmp("inet",protocol)
|
||||||
|
#ifdef AF_INET6
|
||||||
|
&& strcmp("inet6",protocol)
|
||||||
|
#endif
|
||||||
|
)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (*host == '\0')
|
||||||
|
host = "localhost";
|
||||||
|
|
||||||
memset(&hints, 0, sizeof(hints));
|
memset(&hints, 0, sizeof(hints));
|
||||||
#ifdef AI_ADDRCONFIG
|
#ifdef AI_ADDRCONFIG
|
||||||
hints.ai_flags |= AI_ADDRCONFIG;
|
hints.ai_flags |= AI_ADDRCONFIG;
|
||||||
|
|
Loading…
Reference in New Issue