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

internal calls static, add wrapper to prepare query

parent 2bf9c877
Branches
No related tags found
No related merge requests found
...@@ -3,10 +3,8 @@ ...@@ -3,10 +3,8 @@
* 1. Add parsing for displaying APN profiles available to make sense of them * 1. Add parsing for displaying APN profiles available to make sense of them
* 2. Add more input options when creating APN profile * 2. Add more input options when creating APN profile
* 3. Seperate "set default" and "apply" APN profiles (what is the difference anyway?) * 3. Seperate "set default" and "apply" APN profiles (what is the difference anyway?)
* 4. Make the APN parsed fields more dynamic * 4. Change way to seperate profile configurations? (i.e. currently 0: .., 1: .., n: ...)
*/ */
#include "libmobile.h" #include "libmobile.h"
struct string { struct string {
...@@ -14,11 +12,12 @@ struct string { ...@@ -14,11 +12,12 @@ struct string {
size_t len; size_t len;
}; };
void curl_cleaner(CURLcode *curl); static void curl_cleaner(CURLcode *curl);
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);
int apn_profile_idx(struct json_object *apn_profiles, char *name); static int apn_profile_idx(struct json_object *apn_profiles, char *name);
int get_apn_profiles_len(void); static int get_apn_profiles_len(void);
char *lexer(char **input, char *delimiter); static char *lexer(char **input, char *delimiter);
static char *get_query_wrapper(char *vars);
/** /**
* Function: curl_cleaner * Function: curl_cleaner
...@@ -28,7 +27,7 @@ char *lexer(char **input, char *delimiter); ...@@ -28,7 +27,7 @@ char *lexer(char **input, char *delimiter);
* Parameters: * Parameters:
* curl - The curl easy handle variable. * curl - The curl easy handle variable.
*/ */
void curl_cleaner(CURLcode *curl) static void curl_cleaner(CURLcode *curl)
{ {
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
curl_global_cleanup(); curl_global_cleanup();
...@@ -48,7 +47,7 @@ void curl_cleaner(CURLcode *curl) ...@@ -48,7 +47,7 @@ void curl_cleaner(CURLcode *curl)
* Returns: * Returns:
* Number of bytes managed (size*nmemb). * Number of bytes managed (size*nmemb).
*/ */
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 new_len = str->len + (size * nmemb);
...@@ -78,7 +77,7 @@ size_t write_func(void *buffer, size_t size, size_t nmemb, void *userp) ...@@ -78,7 +77,7 @@ size_t write_func(void *buffer, size_t size, size_t nmemb, void *userp)
* Index of the APN on success. * Index of the APN on success.
* -1 on failure. * -1 on failure.
*/ */
int apn_profile_idx(struct json_object *apn_profiles, char *name) static int apn_profile_idx(struct json_object *apn_profiles, char *name)
{ {
int idx = 0; int idx = 0;
json_object_object_foreach(apn_profiles, key, val) { json_object_object_foreach(apn_profiles, key, val) {
...@@ -105,7 +104,7 @@ int apn_profile_idx(struct json_object *apn_profiles, char *name) ...@@ -105,7 +104,7 @@ int apn_profile_idx(struct json_object *apn_profiles, char *name)
* Number of APN profiles available on success. * Number of APN profiles available on success.
* -1 on failure. * -1 on failure.
*/ */
int get_apn_profiles_len(void) static int get_apn_profiles_len(void)
{ {
char *response = mobile_get_apn_profiles(); char *response = mobile_get_apn_profiles();
...@@ -157,7 +156,7 @@ success: ...@@ -157,7 +156,7 @@ success:
* Will alter the input string and allocate memory for the return value! * Will alter the input string and allocate memory for the return value!
* The caller is responsible for freeing the return value. * The caller is responsible for freeing the return value.
*/ */
char *lexer(char **input, char *delimiter) { static char *lexer(char **input, char *delimiter) {
if(strlen(*input) == 0) { if(strlen(*input) == 0) {
printf("empty input!\n"); printf("empty input!\n");
return NULL; return NULL;
...@@ -440,17 +439,43 @@ fail: ...@@ -440,17 +439,43 @@ fail:
return NULL; return NULL;
} }
char *mobile_get_request(char *vars) /**
* Function: get_query_wrapper
* Wraps the input comma-separated values to the appropriate address format for a GET request.
*
* Parameters:
* vars - Char pointer pointing to comma-separated values to retreive.
*
* Returns:
* The entire query on success.
* NULL on failure.
*/
char *get_query_wrapper(char *vars)
{ {
CURL *curl; if (strlen(vars) == 0) {
CURLcode res; printf("No GET input provided!\n");
struct string str; return NULL;
}
char query[1024] = {0}; char query[1024] = {0};
strncpy(query, "http://192.168.0.1/goform/goform_get_cmd_process?isTest=false&cmd=", 1023); strncpy(query, "http://192.168.0.1/goform/goform_get_cmd_process?isTest=false&cmd=", 1023);
strncat(query + strlen(query), vars, 1023); strncat(query + strlen(query), vars, 1023);
strncat(query + strlen(query), "&multi_data=1", 1023); strncat(query + strlen(query), "&multi_data=1", 1023);
return strdup(query);
}
char *mobile_get_request(char *vars)
{
CURL *curl;
CURLcode res;
struct string str;
char *query = get_query_wrapper(vars);
if (!query)
goto fail;
str.ptr = calloc(1, 1); str.ptr = calloc(1, 1);
str.len = 0; str.len = 0;
curl = curl_easy_init(); curl = curl_easy_init();
...@@ -466,6 +491,7 @@ char *mobile_get_request(char *vars) ...@@ -466,6 +491,7 @@ char *mobile_get_request(char *vars)
} }
} }
free(query);
curl_cleaner(curl); curl_cleaner(curl);
return str.ptr; return str.ptr;
fail: fail:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment