summaryrefslogtreecommitdiff
path: root/xmpp.c
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2022-11-27 18:53:12 +0100
committerxengineering <me@xengineering.eu>2022-11-27 19:07:49 +0100
commit2efc9022bf064136bb7cd25bd59971f2b419ff48 (patch)
tree87ea72030a3bb28f1ddba1675482a9346c5df814 /xmpp.c
parent8b9ce1d7848bd8ad417a3834d11e1b00c028f8eb (diff)
downloadlimox-2efc9022bf064136bb7cd25bd59971f2b419ff48.tar
limox-2efc9022bf064136bb7cd25bd59971f2b419ff48.tar.zst
limox-2efc9022bf064136bb7cd25bd59971f2b419ff48.zip
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)
Diffstat (limited to 'xmpp.c')
-rw-r--r--xmpp.c48
1 files changed, 41 insertions, 7 deletions
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);
}