blob: 865b2351fdcda2a337f1e55cbe20563b4ecc8483 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#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)
{
printf("net_quit()\n");
}
|