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

untested apn parser

parent 26ff735c
Branches
No related tags found
No related merge requests found
...@@ -18,6 +18,7 @@ void curl_cleaner(CURLcode *curl); ...@@ -18,6 +18,7 @@ void curl_cleaner(CURLcode *curl);
size_t write_func(void *buffer, size_t size, size_t nmemb, void *userp); 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); int apn_profile_idx(struct json_object *apn_profiles, char *name);
int get_apn_profiles_len(void); int get_apn_profiles_len(void);
struct json_object *parse_apn_profiles(char *apn_profiles);
/** /**
* Function: curl_cleaner * Function: curl_cleaner
...@@ -138,6 +139,18 @@ success: ...@@ -138,6 +139,18 @@ success:
return len; return len;
} }
/**
* Function: parse_apn_profiles
*
* Takes a string of APN profile configurations provided by zte-mf823 (which is in an awkward, difficult to read format)
* and transforms them into a more easily read and worked with JSON format.
*
* Parameters:
* apn_profiles - A character string containing the APN profiles.
* Returns:
* The newly generated JSON on success.
* NULL on failure.
*/
struct json_object *parse_apn_profiles(char *apn_profiles) struct json_object *parse_apn_profiles(char *apn_profiles)
{ {
if (strlen(apn_profiles) <= 0) { if (strlen(apn_profiles) <= 0) {
...@@ -151,43 +164,57 @@ struct json_object *parse_apn_profiles(char *apn_profiles) ...@@ -151,43 +164,57 @@ struct json_object *parse_apn_profiles(char *apn_profiles)
goto fail; goto fail;
} }
struct json_object *parsed_profiles = json_object_new_object(); struct json_object *parsed_profiles = json_object_new_object();
int apn_counter = 0;
char field_names[13] = {"profile_name", "apn_name", "mode", "dunno", "authentication", "username?", "password?", "IPdunno", "ddnunno?", "dno", "DNS_mode", "IPv_username", "IPv_password"};
int rv;
json_object_object_foreach(apn_profiles_json, key, val) { json_object_object_foreach(apn_profiles_json, key, val) {
char *apn = json_object_get_string(val); char *apn_string = json_object_get_string(val);
if (strlen(apn) <= 0) if (strlen(apn_string) <= 0)
goto finished; goto finished;
int i;
struct json_object *apn_profile = json_object_new_object();
char fields[13] = {"profile_name", "apn_name", "mode", "dunno", "authentication", "username?", "password?", "IPdunno", "ddnunno?", "dno", "DNS_mode", "IPv_username", "IPv_password"}; for (i = 0; i < 13; i++) {
int field_counter = 0; char *field_val = strtok(apn_string, "($)");
json_object_object_add(apn_profile, field_names[i], field_val);
}
rv = json_object_object_add(parsed_profiles, sprintf("%d", apn_counter), apn_profile); //be careful here, do we need json_object_get(apn_profile)?
json_object_put(apn_profile);
if (!rv) {
DEBUG("Error adding object!\n");
goto free_objects;
}
apn_counter++;
//json_put what??
printf("FREE THEM CORRECTLY HERE!\n");
//best guess, free: apn_profile
} }
goto finished;
free_object: free_objects:
json_object_put(apn_profiles); json_object_put(apn_profiles);
json_object_put(parsed_profiles); json_object_put(parsed_profiles);
fail: fail:
return NULL; return NULL;
finished: finished:
printf("probably need to free apn_profiles_json!\n");
//best guess, free: apn_profiles_json
json_object_put(apn_profiles);
json_object_put(parsed_profiles);
return parsed_profiles; return parsed_profiles;
} }
char *mobile_connect_network(void) char *mobile_connect_network(void)
{ {
char query[1024] = {0}; return mobile_post_request("isTest=false&goformId=CONNECT_NETWORK");
strncpy(query, "isTest=false&goformId=CONNECT_NETWORK", 1023);
return mobile_post_request(query);
} }
char *mobile_disconnect_network(void) char *mobile_disconnect_network(void)
{ {
char query[1024] = {0}; return mobile_post_request("isTest=false&goformId=DISCONNECT_NETWORK");
// removed notcallback, why have it?
strncpy(query, "isTest=false&goformId=DISCONNECT_NETWORK", 1023);
return mobile_post_request(query);
} }
char *mobile_delete_apn(char *name) char *mobile_delete_apn(char *name)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment