-
Notifications
You must be signed in to change notification settings - Fork 1
/
endpoint.c
46 lines (39 loc) · 910 Bytes
/
endpoint.c
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
// Copyright 2016 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#include <stdlib.h>
#include <strings.h>
#include "miniv.h"
// Find the host:port in a Vanadium endpoint like this;
// @6@[email protected]:64994@@85b4dbc6d23fa02d98b74c9008c3f1b0@[email protected]:u:[email protected]:bridge@@
err_t nameParse(char *name, char **host, char **port) {
if (name == NULL) {
return ERR_PARAM;
}
char *p = name;
int ct = 0;
while (*p) {
if (ct == 3) {
// Found hostname, terminate it.
*host = p;
p = index(p, ':');
if (p == NULL) {
break;
}
*p = 0;
p++;
*port = p;
p = index(p, '@');
if (p == NULL) {
break;
}
*p = 0;
return ERR_OK;
}
if (*p == '@') {
ct++;
}
p++;
}
return ERR_ENDPOINT;
}