/*
* LimoX - The Linux on mobile XMPP chat client
* Copyright (C) 2022 xengineering
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include
#include
#include
#include
#include
#include
#include
/*
* Get the domainpart of the Jabber ID (JID)
*
* See https://datatracker.ietf.org/doc/html/rfc7622#section-3.2 for details.
*/
char *get_domainpart(char *jid)
{
int start = 0; // inclusive
int stop = strlen(jid); // exclusive
for(int i=0; iai_next) {
if (p->ai_family == AF_INET) {
struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
addr = &(ipv4->sin_addr);
inet_ntop(p->ai_family, addr, ipstr, sizeof ipstr);
printf("Got compatible IPv4 address %s from DNS.\n", ipstr);
return p;
} else if (p->ai_family == AF_INET6) {
printf("Ignored IPv6 DNS entry which is not supported.\n");
} else {
printf("Ignored unknown addrinfo address type.\n");
}
}
printf("No suitable IP address found via DNS!\n");
return NULL;
}
/*
* Initialize the network connection to the XMPP server
*
* TODO: Error handling is missing.
*/
void xmpp_connect(void)
{
printf("net_init()\n");
char *jid = getenv("LIMOX_USER");
char *pwd = getenv("LIMOX_PWD");
printf("Trying to connect as '%s' with '%s'.\n", jid, pwd);
char *domain = get_domainpart(jid);
printf("Domainpart is '%s'.\n", domain);
struct addrinfo *addr = get_addrinfo(domain);
int sock = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
if (sock == -1) {
printf("Failed to get socket from OS!.");
return;
} else {
printf("Got socket number %d from OS.\n", sock);
}
}