(net_http.c) Get rid of strlen
This commit is contained in:
parent
2c4010818e
commit
d9c196154c
|
@ -389,16 +389,15 @@ void net_http_urlencode(char **dest, const char *source)
|
||||||
void net_http_urlencode_full(char *dest,
|
void net_http_urlencode_full(char *dest,
|
||||||
const char *source, size_t size)
|
const char *source, size_t size)
|
||||||
{
|
{
|
||||||
|
size_t buf_pos;
|
||||||
size_t tmp_len;
|
size_t tmp_len;
|
||||||
size_t url_domain_len;
|
|
||||||
char url_domain[256];
|
char url_domain[256];
|
||||||
char url_path[PATH_MAX_LENGTH];
|
char url_path[PATH_MAX_LENGTH];
|
||||||
size_t buf_pos = 0;
|
|
||||||
char *tmp = NULL;
|
char *tmp = NULL;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
strlcpy(url_path, source, sizeof(url_path));
|
strlcpy(url_path, source, sizeof(url_path));
|
||||||
tmp = url_path;
|
tmp = url_path;
|
||||||
|
|
||||||
while (count < 3 && tmp[0] != '\0')
|
while (count < 3 && tmp[0] != '\0')
|
||||||
{
|
{
|
||||||
|
@ -408,20 +407,19 @@ void net_http_urlencode_full(char *dest,
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp_len = strlen(tmp);
|
tmp_len = strlen(tmp);
|
||||||
url_domain_len = ((strlcpy(url_domain, source, tmp - url_path)) - tmp_len) - 1;
|
buf_pos = ((strlcpy(url_domain, source, tmp - url_path)) - tmp_len) - 1;
|
||||||
strlcpy(url_path,
|
strlcpy(url_path,
|
||||||
source + url_domain_len + 1,
|
source + buf_pos + 1,
|
||||||
tmp_len + 1
|
tmp_len + 1
|
||||||
);
|
);
|
||||||
|
|
||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
net_http_urlencode(&tmp, url_path);
|
net_http_urlencode(&tmp, url_path);
|
||||||
buf_pos = strlcpy(dest, url_domain, size);
|
buf_pos = strlcpy(dest, url_domain, size);
|
||||||
dest[buf_pos] = '/';
|
dest[ buf_pos] = '/';
|
||||||
dest[buf_pos+1] = '\0';
|
dest[++buf_pos] = '\0';
|
||||||
buf_pos += 1;
|
|
||||||
strlcpy(dest + buf_pos, tmp, size - buf_pos);
|
strlcpy(dest + buf_pos, tmp, size - buf_pos);
|
||||||
free (tmp);
|
free(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int net_http_new_socket(struct http_connection_t *conn)
|
static int net_http_new_socket(struct http_connection_t *conn)
|
||||||
|
@ -756,12 +754,12 @@ struct http_t *net_http_new(struct http_connection_t *conn)
|
||||||
if (conn->port)
|
if (conn->port)
|
||||||
{
|
{
|
||||||
char portstr[16];
|
char portstr[16];
|
||||||
|
size_t _len = 0;
|
||||||
portstr[0] = '\0';
|
portstr[ _len] = ':';
|
||||||
|
portstr[++_len] = '\0';
|
||||||
snprintf(portstr, sizeof(portstr), ":%i", conn->port);
|
_len += snprintf(portstr + _len, sizeof(portstr) - _len,
|
||||||
net_http_send_str(&conn->sock_state, &error, portstr,
|
"%i", conn->port);
|
||||||
strlen(portstr));
|
net_http_send_str(&conn->sock_state, &error, portstr, _len);
|
||||||
}
|
}
|
||||||
|
|
||||||
net_http_send_str(&conn->sock_state, &error, "\r\n",
|
net_http_send_str(&conn->sock_state, &error, "\r\n",
|
||||||
|
|
Loading…
Reference in New Issue