Skip to content
Snippets Groups Projects
Commit 5091d65b authored by Jakob Olsson's avatar Jakob Olsson
Browse files

cppcheck and checkpatch

parent 8aaeba0d
No related branches found
No related tags found
No related merge requests found
...@@ -24,7 +24,7 @@ int signal_strength(struct ubus_context *ctx, struct ubus_object *obj, ...@@ -24,7 +24,7 @@ int signal_strength(struct ubus_context *ctx, struct ubus_object *obj,
{ {
struct blob_buf bb; struct blob_buf bb;
char * response = get_request("rssi"); char *response = get_request("rssi");
struct json_object *parsed_response = json_tokener_parse(response); struct json_object *parsed_response = json_tokener_parse(response);
memset(&bb, 0, sizeof(struct blob_buf)); memset(&bb, 0, sizeof(struct blob_buf));
......
...@@ -53,7 +53,7 @@ int print_response(struct json_object *parsed_response, struct ubus_context *ctx ...@@ -53,7 +53,7 @@ int print_response(struct json_object *parsed_response, struct ubus_context *ctx
int isdigits(const char *pin) int isdigits(const char *pin)
{ {
while (*pin){ while (*pin) {
if (isdigit(*pin++) == 0) if (isdigit(*pin++) == 0)
return false; return false;
} }
...@@ -65,7 +65,7 @@ int validate_pin_format(char *pin) ...@@ -65,7 +65,7 @@ int validate_pin_format(char *pin)
if (!isdigits(pin)) { if (!isdigits(pin)) {
printf("Please enter digits only!\n"); printf("Please enter digits only!\n");
goto fail; goto fail;
} else if (strlen(pin) > 8 && strlen(pin) < 4 ) { } else if (strlen(pin) > 8 || strlen(pin) < 4) {
printf("Please enter between 4 to 8 digits!\n"); printf("Please enter between 4 to 8 digits!\n");
goto fail; goto fail;
} else if (atoi(pin) == 0) { } else if (atoi(pin) == 0) {
...@@ -227,11 +227,10 @@ int verify_pin(struct ubus_context *ctx, struct ubus_object *obj, ...@@ -227,11 +227,10 @@ int verify_pin(struct ubus_context *ctx, struct ubus_object *obj,
struct json_object *rv; struct json_object *rv;
json_object_object_get_ex(parsed_response, "pin_status", &rv); json_object_object_get_ex(parsed_response, "pin_status", &rv);
if (json_object_get_string(rv)) { if (json_object_get_string(rv))
response = _enable_pin(pin); response = _enable_pin(pin);
} else { else
response = _disable_pin(pin); response = _disable_pin(pin);
}
json_object_put(parsed_response); json_object_put(parsed_response);
parsed_response = json_tokener_parse(response); parsed_response = json_tokener_parse(response);
...@@ -247,6 +246,7 @@ int remaining_tries(struct ubus_context *ctx, struct ubus_object *obj, ...@@ -247,6 +246,7 @@ int remaining_tries(struct ubus_context *ctx, struct ubus_object *obj,
{ {
char *response = get_request("pinnumber"); char *response = get_request("pinnumber");
struct json_object *parsed_response = json_tokener_parse(response); struct json_object *parsed_response = json_tokener_parse(response);
print_response(parsed_response, ctx, req); print_response(parsed_response, ctx, req);
return 0; return 0;
} }
......
...@@ -187,8 +187,7 @@ char *post_request(char *query) ...@@ -187,8 +187,7 @@ char *post_request(char *query)
str.len = 0; str.len = 0;
curl = curl_easy_init(); curl = curl_easy_init();
if (curl) if (curl) {
{
curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.0.1/goform/goform_set_cmd_process"); curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.0.1/goform/goform_set_cmd_process");
curl_easy_setopt(curl, CURLOPT_REFERER, "http://192.168.0.1/index.html"); curl_easy_setopt(curl, CURLOPT_REFERER, "http://192.168.0.1/index.html");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, query); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, query);
...@@ -196,12 +195,13 @@ char *post_request(char *query) ...@@ -196,12 +195,13 @@ char *post_request(char *query)
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_func); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_func);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &str); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &str);
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
if (res) if (res) {
{
printf("errored when performing curl, %s\n", curl_easy_strerror(res)); printf("errored when performing curl, %s\n", curl_easy_strerror(res));
goto fail; goto fail;
} }
} }
curl_cleaner(curl);
return str.ptr; return str.ptr;
fail: fail:
return NULL; return NULL;
...@@ -221,19 +221,19 @@ char *get_request(char *vars) ...@@ -221,19 +221,19 @@ char *get_request(char *vars)
str.ptr = calloc(1, 1); str.ptr = calloc(1, 1);
str.len = 0; str.len = 0;
curl = curl_easy_init(); curl = curl_easy_init();
if (curl) if (curl) {
{
curl_easy_setopt(curl, CURLOPT_URL, query); curl_easy_setopt(curl, CURLOPT_URL, query);
curl_easy_setopt(curl, CURLOPT_REFERER, "http://192.168.0.1/index.html"); curl_easy_setopt(curl, CURLOPT_REFERER, "http://192.168.0.1/index.html");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_func); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_func);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &str); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &str);
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
if (res) if (res) {
{
printf("errored when performing curl, %s\n", curl_easy_strerror(res)); printf("errored when performing curl, %s\n", curl_easy_strerror(res));
goto fail; goto fail;
} }
} }
curl_cleaner(curl);
return str.ptr; return str.ptr;
fail: fail:
return NULL; return NULL;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment