From 2efc9022bf064136bb7cd25bd59971f2b419ff48 Mon Sep 17 00:00:00 2001 From: xengineering Date: Sun, 27 Nov 2022 18:53:12 +0100 Subject: Switch completely to SDL2 version The now legacy version of LimoX with GTK4 and libstrophe is now not part of the main branch anymore. There might be a legacy branch keeping this version at the time of reading. This cut of implemented functionality is motivated by these reasons: - Implementing XMPP is fun, educative and gives full control. - Low level graphics with SDL2 is portable, fast, educative an mature. - I do not have to use GLib and a crazy event loop anymore (run and hide) --- xmpp.c | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) (limited to 'xmpp.c') diff --git a/xmpp.c b/xmpp.c index 865b235..e1ab985 100644 --- a/xmpp.c +++ b/xmpp.c @@ -30,14 +30,51 @@ char *domainpart(char *jid) } } - char* retval = (char *)malloc((stop-start+1) * sizeof(char)); - memcpy(retval, jid+start, (stop-start)*sizeof(char)); + char *retval = (char *)malloc((stop-start+1) * sizeof(char)); + memcpy(retval, jid+start, (stop-start) * sizeof(char)); retval[stop] = '\0'; return retval; } -void net_init(void) +/* + * Return the preferred struct addrinfo * or NULL + * + * This handles DNS resolution. It returns the first valid addrinfo which is + * returned by getaddrinfo. Mind that the addrinfo could use IPv6 instead of + * IPv4. + */ +struct addrinfo *get_addrinfo(char *domain) +{ + struct addrinfo hints; + struct addrinfo *servinfo; + memset(&hints, 0, sizeof hints); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + if (getaddrinfo(domain, "xmpp-client", &hints, &servinfo) != 0) { + printf("Failed to resolve hostname '%s'.\n", domain); + return NULL; + } + struct addrinfo *p; + for(p=servinfo; p!=NULL; p=p->ai_next) { + if (p->ai_family == AF_INET) { + printf("an IPv4!\n"); // TODO + + } else if (p->ai_family == AF_INET6) { + printf("an IPv6!\n"); // TODO + } else { + printf("Unknown addrinfo address type.\n"); + } + } + return NULL; +} + +/* + * Initialize the network connection to the XMPP server + * + * TODO: Error handling is missing. + */ +void xmpp_connect(void) { printf("net_init()\n"); @@ -46,9 +83,6 @@ void net_init(void) char *domain = domainpart(user_str); printf("Trying to connect as '%s' with '%s'.\n", user_str, pwd_str); printf("Domainpart is '%s'.\n", domain); -} -void net_quit(void) -{ - printf("net_quit()\n"); + get_addrinfo(domain); } -- cgit v1.2.3-70-g09d2