summaryrefslogtreecommitdiff
path: root/xmpp.c
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2022-11-20 14:40:56 +0100
committerxengineering <me@xengineering.eu>2022-11-20 14:40:56 +0100
commitd9c55d41a6c014ef90fe42ffeef5f5b66409b111 (patch)
tree10404e0e1182084313533176ab4b8759b43cee6b /xmpp.c
parenta4c0236316056a6ef3b6c885f523f0f0da8cdc23 (diff)
downloadlimox-d9c55d41a6c014ef90fe42ffeef5f5b66409b111.tar
limox-d9c55d41a6c014ef90fe42ffeef5f5b66409b111.tar.zst
limox-d9c55d41a6c014ef90fe42ffeef5f5b66409b111.zip
Extract domain from JID with parser function
It is mandatory to have an IP address to dial a TCP connection. FOr this purpose the JID which is given by the user has to be converted into a FQDN and then translated to an IP via DNS. The function added with this commit implements this first part. The extraction of the domain (more precisely the FQDN) from the JID.
Diffstat (limited to 'xmpp.c')
-rw-r--r--xmpp.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/xmpp.c b/xmpp.c
index be677fc..865b235 100644
--- a/xmpp.c
+++ b/xmpp.c
@@ -2,16 +2,50 @@
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+/*
+ * Get the domainpart of the Jabber ID (JID).
+ * See https://datatracker.ietf.org/doc/html/rfc7622#section-3.2 for details.
+ */
+char *domainpart(char *jid)
+{
+ int start = 0; // inclusive
+ int stop = strlen(jid); // exclusive
+
+ for(int i=0; i<strlen(jid); i++) {
+ if (jid[i] == '/') {
+ stop = i;
+ break;
+ }
+ }
+
+ for(int i=0; i<strlen(jid); i++) {
+ if (jid[i] == '@') {
+ start = i + 1;
+ break;
+ }
+ }
+
+ 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)
{
printf("net_init()\n");
char* user_str = getenv("LIMOX_USER");
char* pwd_str = getenv("LIMOX_PWD");
-
+ 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)