mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-09 17:48:19 +00:00
Merge pull request #8105 from Robyt3/Base-net_addr_from_url-Refactor
Minor refactoring of `net_addr_from_url`
This commit is contained in:
commit
bcfc61b82a
|
@ -1290,19 +1290,15 @@ static int parse_uint16(unsigned short *out, const char **str)
|
||||||
|
|
||||||
int net_addr_from_url(NETADDR *addr, const char *string, char *host_buf, size_t host_buf_size)
|
int net_addr_from_url(NETADDR *addr, const char *string, char *host_buf, size_t host_buf_size)
|
||||||
{
|
{
|
||||||
char host[128];
|
|
||||||
int length;
|
|
||||||
int start = 0;
|
|
||||||
int end;
|
|
||||||
int failure;
|
|
||||||
const char *str = str_startswith(string, "tw-0.6+udp://");
|
const char *str = str_startswith(string, "tw-0.6+udp://");
|
||||||
if(!str)
|
if(!str)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
mem_zero(addr, sizeof(*addr));
|
mem_zero(addr, sizeof(*addr));
|
||||||
|
|
||||||
length = str_length(str);
|
int length = str_length(str);
|
||||||
end = length;
|
int start = 0;
|
||||||
|
int end = length;
|
||||||
for(int i = 0; i < length; i++)
|
for(int i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
if(str[i] == '@')
|
if(str[i] == '@')
|
||||||
|
@ -1320,14 +1316,13 @@ int net_addr_from_url(NETADDR *addr, const char *string, char *host_buf, size_t
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char host[128];
|
||||||
str_truncate(host, sizeof(host), str + start, end - start);
|
str_truncate(host, sizeof(host), str + start, end - start);
|
||||||
if(host_buf)
|
if(host_buf)
|
||||||
str_copy(host_buf, host, host_buf_size);
|
str_copy(host_buf, host, host_buf_size);
|
||||||
|
|
||||||
if((failure = net_addr_from_str(addr, host)))
|
return net_addr_from_str(addr, host);
|
||||||
return failure;
|
|
||||||
|
|
||||||
return failure;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int net_addr_from_str(NETADDR *addr, const char *string)
|
int net_addr_from_str(NETADDR *addr, const char *string)
|
||||||
|
|
Loading…
Reference in a new issue