wificfg: quieten some compile type warnings.

This commit is contained in:
Our Air Quality 2017-12-11 14:29:57 +11:00
parent 61f23d0cf4
commit 876f24556d
2 changed files with 31 additions and 34 deletions

View file

@ -76,7 +76,7 @@ static int read_crlf_line(int s, char *buf, size_t len)
do {
char c;
int r = read(s, &c, 1);
ssize_t r = read(s, &c, 1);
/* Expecting a known terminator so fail on EOF. */
if (r <= 0)
@ -101,7 +101,7 @@ static int read_crlf_line(int s, char *buf, size_t len)
return num;
}
int wificfg_form_name_value(int s, bool *valp, size_t *rem, char *buf, size_t len)
ssize_t wificfg_form_name_value(int s, bool *valp, size_t *rem, char *buf, size_t len)
{
size_t num = 0;
@ -110,7 +110,7 @@ int wificfg_form_name_value(int s, bool *valp, size_t *rem, char *buf, size_t le
break;
char c;
int r = read(s, &c, 1);
ssize_t r = read(s, &c, 1);
/* Expecting a known number of characters so fail on EOF. */
if (r <= 0) return -1;
@ -243,7 +243,7 @@ static const struct {
static wificfg_method intern_http_method(char *str)
{
int i;
size_t i;
for (i = 0; i < sizeof(method_table) / sizeof(method_table[0]); i++) {
if (!strcmp(str, method_table[i].str))
return method_table[i].method;
@ -274,7 +274,7 @@ static const struct {
static http_header intern_http_header(char *str)
{
int i;
size_t i;
for (i = 0; i < sizeof(http_header_table) / sizeof(http_header_table[0]); i++) {
if (!strcmp(str, http_header_table[i].str))
return http_header_table[i].name;
@ -292,7 +292,7 @@ static const struct {
static wificfg_content_type intern_http_content_type(char *str)
{
int i;
size_t i;
for (i = 0; i < sizeof(content_type_table) / sizeof(content_type_table[0]); i++) {
if (!strcmp(str, content_type_table[i].str))
return content_type_table[i].type;
@ -318,13 +318,13 @@ static char *skip_to_whitespace(char *string)
return string;
}
int wificfg_write_string(int s, const char *str)
ssize_t wificfg_write_string(int s, const char *str)
{
int res = write(s, str, strlen(str));
ssize_t res = write(s, str, strlen(str));
return res;
}
int wificfg_write_string_chunk(int s, const char *str, char *buf, size_t len)
ssize_t wificfg_write_string_chunk(int s, const char *str, char *buf, size_t len)
{
size_t str_len = strlen(str);
@ -366,7 +366,7 @@ int wificfg_write_string_chunk(int s, const char *str, char *buf, size_t len)
/* Else too big for the buffer. */
char size_buf[8];
size_t size_len = snprintf(size_buf, sizeof(size_buf), "%x\r\n", str_len);
int res = write(s, size_buf, size_len);
ssize_t res = write(s, size_buf, size_len);
if (res != size_len) {
return res;
}
@ -377,7 +377,7 @@ int wificfg_write_string_chunk(int s, const char *str, char *buf, size_t len)
return write(s, size_buf + size_len - 2, 2);
}
int wificfg_write_chunk_end(int s)
ssize_t wificfg_write_chunk_end(int s)
{
return wificfg_write_string(s, "0\r\n\r\n");
}
@ -448,12 +448,12 @@ static const struct {
static form_name intern_form_name(char *str)
{
int i;
for (i = 0; i < sizeof(form_name_table) / sizeof(form_name_table[0]); i++) {
if (!strcmp(str, form_name_table[i].str))
return form_name_table[i].name;
}
return FORM_NAME_NONE;
size_t i;
for (i = 0; i < sizeof(form_name_table) / sizeof(form_name_table[0]); i++) {
if (!strcmp(str, form_name_table[i].str))
return form_name_table[i].name;
}
return FORM_NAME_NONE;
}
@ -838,7 +838,7 @@ static int handle_wificfg_index_post(int s, wificfg_method method,
bool valp = false;
while (rem > 0) {
int r = wificfg_form_name_value(s, &valp, &rem, buf, len);
ssize_t r = wificfg_form_name_value(s, &valp, &rem, buf, len);
if (r < 0) {
break;
@ -849,7 +849,7 @@ static int handle_wificfg_index_post(int s, wificfg_method method,
form_name name = intern_form_name(buf);
if (valp) {
int r = wificfg_form_name_value(s, NULL, &rem, buf, len);
ssize_t r = wificfg_form_name_value(s, NULL, &rem, buf, len);
if (r < 0) {
break;
}
@ -1230,7 +1230,7 @@ static int handle_wifi_ap_post(int s, wificfg_method method,
uint8_t dns_enable = 0;
while (rem > 0) {
int r = wificfg_form_name_value(s, &valp, &rem, buf, len);
ssize_t r = wificfg_form_name_value(s, &valp, &rem, buf, len);
if (r < 0) {
break;
@ -1241,7 +1241,7 @@ static int handle_wifi_ap_post(int s, wificfg_method method,
form_name name = intern_form_name(buf);
if (valp) {
int r = wificfg_form_name_value(s, NULL, &rem, buf, len);
ssize_t r = wificfg_form_name_value(s, NULL, &rem, buf, len);
if (r < 0) {
break;
}
@ -1281,19 +1281,19 @@ static int handle_wifi_ap_post(int s, wificfg_method method,
}
case FORM_NAME_AP_AUTHMODE: {
uint32_t mode = strtoul(buf, NULL, 10);
if (mode >= 0 && mode <= 5)
if (mode <= 5)
sysparam_set_int8("wifi_ap_authmode", mode);
break;
}
case FORM_NAME_AP_MAX_CONN: {
uint32_t max_conn = strtoul(buf, NULL, 10);
if (max_conn >= 0 && max_conn <= 8)
if (max_conn <= 8)
sysparam_set_int8("wifi_ap_max_conn", max_conn);
break;
}
case FORM_NAME_AP_BEACON_INTERVAL: {
uint32_t interval = strtoul(buf, NULL, 10);
if (interval >= 0 && interval <= 10000)
if (interval <= 10000)
sysparam_set_int32("wifi_ap_beacon_interval", interval);
break;
}
@ -1305,7 +1305,7 @@ static int handle_wifi_ap_post(int s, wificfg_method method,
break;
case FORM_NAME_AP_DHCP_LEASES: {
uint32_t leases = strtoul(buf, NULL, 10);
if (leases >= 0 && leases <= 16)
if (leases <= 16)
sysparam_set_int8("wifi_ap_dhcp_leases", leases);
break;
}
@ -1851,7 +1851,7 @@ static void server_task(void *pvParameters)
size_t len;
for (len = 0; len < 4096; len++) {
char c;
int res = read(s, &c, 1);
ssize_t res = read(s, &c, 1);
if (res != 1) break;
}
@ -1912,7 +1912,7 @@ static void dns_task(void *pvParameters)
char buffer[96];
struct sockaddr_storage src_addr;
socklen_t src_addr_len = sizeof(src_addr);
size_t count = recvfrom(fd, buffer, sizeof(buffer), 0, (struct sockaddr*)&src_addr, &src_addr_len);
ssize_t count = recvfrom(fd, buffer, sizeof(buffer), 0, (struct sockaddr*)&src_addr, &src_addr_len);
/* Drop messages that are too large to send a response in the buffer */
if (count > 0 && count <= sizeof(buffer) - 16) {

View file

@ -97,7 +97,7 @@ void wificfg_init(uint32_t port, const wificfg_dispatch *dispatch);
* is truncated to the buffer length. The number of characters read is limited
* to the remainder which is updated. The 'valp' flag is set if a value follows.
*/
int wificfg_form_name_value(int s, bool *valp, size_t *rem, char *buf, size_t len);
ssize_t wificfg_form_name_value(int s, bool *valp, size_t *rem, char *buf, size_t len);
/* Support for form url-encoding decoder. */
void wificfg_form_url_decode(char *string);
@ -106,20 +106,17 @@ void wificfg_form_url_decode(char *string);
void wificfg_html_escape(char *string, char *buf, size_t len);
/* Support for writing a string in a response. */
int wificfg_write_string(int s, const char *str);
ssize_t wificfg_write_string(int s, const char *str);
/* Support for writing a string in a response, with chunk transfer encoding.
* An optional buffer may be supplied to use to construct a chunk with the
* header and trailer, reducing the number of write() calls, and the str may be
* at the start of this buffer.
*/
int wificfg_write_string_chunk(int s, const char *str, char *buf, size_t len);
ssize_t wificfg_write_string_chunk(int s, const char *str, char *buf, size_t len);
/* Write a chunk transfer encoding end marker. */
int wificfg_write_chunk_end(int s);
/* Write a chunk offset 4 bytes into the buffer. */
int wificfg_write_buffer_chunk(int s, char *buf);
ssize_t wificfg_write_chunk_end(int s);
/* Write a html title meta data, using the hostname or AP SSI. */
int wificfg_write_html_title(int s, char *buf, size_t len, const char *str);