Skip to content
Snippets Groups Projects
Commit d09a5e06 authored by Ionuț-Alex Oprea's avatar Ionuț-Alex Oprea
Browse files

some suggestions

parent 414061fa
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ CC = gcc ...@@ -2,7 +2,7 @@ CC = gcc
CFLAGS = -g -Wall CFLAGS = -g -Wall
LIBS = -ljson-c -lubox -lubus -luci -lcurl -lmobile LIBS = -ljson-c -lubox -lubus -luci -lcurl -lmobile
all: libmobile1 libmobile2# common dongle_apn dongle_pin dongle_network all: libmobile1 libmobile2 common dongle_apn dongle_pin dongle_network
#gcc -shared -o libhello.so -fPIC hello.c #gcc -shared -o libhello.so -fPIC hello.c
...@@ -34,7 +34,7 @@ libmobile2: ${MOBJS} ...@@ -34,7 +34,7 @@ libmobile2: ${MOBJS}
#DPOBJS = dongle_pin.o #DPOBJS = dongle_pin.o
#DPSRCS = dongle_pin.c #DPSRCS = dongle_pin.c
#dongle_pin: ${DPOBJS} #dongle_pin: ${DPOBJS}
# ${CC} ${CFLAGS} ${DPOBJS} ${COBJS} -o dongle_pin ${LIBS} # ${CC} ${CFLAGS} ${DPOBJS} ${COBJS} -o dongle_pin -L . ${LIBS}
# #
#DNOBJS = dongle_network.o #DNOBJS = dongle_network.o
#DNSRCS = dongle_network.c #DNSRCS = dongle_network.c
......
...@@ -18,6 +18,7 @@ static int apn_profile_idx(struct json_object *apn_profiles, char *name); ...@@ -18,6 +18,7 @@ static int apn_profile_idx(struct json_object *apn_profiles, char *name);
static int get_apn_profiles_len(void); static int get_apn_profiles_len(void);
static char *lexer(char **input, char *delimiter); static char *lexer(char **input, char *delimiter);
static char *get_query_wrapper(char *vars); static char *get_query_wrapper(char *vars);
static char *mobile_post_request(char *query);
/** /**
* Function: curl_cleaner * Function: curl_cleaner
...@@ -50,18 +51,21 @@ static void curl_cleaner(CURLcode *curl) ...@@ -50,18 +51,21 @@ static void curl_cleaner(CURLcode *curl)
static size_t write_func(void *buffer, size_t size, size_t nmemb, void *userp) static size_t write_func(void *buffer, size_t size, size_t nmemb, void *userp)
{ {
struct string *str = (struct string *)userp; struct string *str = (struct string *)userp;
size_t new_len = str->len + (size * nmemb); size_t len = size * nmemb;
size_t new_len = str->len + len;
str->ptr = realloc(str->ptr, new_len + 1); ptr = realloc(str->ptr, new_len + 1);
if (str->ptr == NULL) { if (ptr == NULL) {
free(str->ptr);
printf("not enough ptr (realloc returned NULL)\n"); printf("not enough ptr (realloc returned NULL)\n");
return 0; return 0;
} } else //realloc succeeded
memcpy(str->ptr + str->len, buffer, size * nmemb); str->ptr = ptr;
memcpy(str->ptr + str->len, buffer, len);
str->ptr[new_len] = '\0'; str->ptr[new_len] = '\0';
str->len = new_len; str->len = new_len;
return size * nmemb; return len;
} }
/** /**
...@@ -438,7 +442,7 @@ char *mobile_disable_pin(char *pin) ...@@ -438,7 +442,7 @@ char *mobile_disable_pin(char *pin)
return mobile_post_request(query); return mobile_post_request(query);
} }
char *mobile_post_request(char *query) static char *mobile_post_request(char *query)
{ {
CURL *curl; CURL *curl;
CURLcode res; CURLcode res;
...@@ -478,6 +482,7 @@ char *mobile_get_request(char *vars) ...@@ -478,6 +482,7 @@ char *mobile_get_request(char *vars)
if (!query) if (!query)
goto fail; goto fail;
// flow, calloc return code, gotos and frees
str.ptr = calloc(1, 1); str.ptr = calloc(1, 1);
str.len = 0; str.len = 0;
curl = curl_easy_init(); curl = curl_easy_init();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment