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

update to take two more arguments to create profile, update internal functions

parent 948c7b71
No related branches found
No related tags found
No related merge requests found
/**
* TODO:
* 1. Add parsing for displaying APN profiles available to make sense of them
* 2. Add more input options when creating APN profile
* 3. Seperate "set default" and "apply" APN profiles (what is the difference anyway?)
* 4. Change way to seperate profile configurations? (i.e. currently 0: .., 1: .., n: ...)
* 1. Add more input options when creating APN profile
*/
#include "libmobile.h"
......@@ -94,17 +91,19 @@ static int apn_profile_idx(struct json_object *apn_profiles, char *name)
int idx = 0;
json_object_object_foreach(apn_profiles, key, val) {
char *apn_profile = json_object_get_string(val);
struct json_object *profile_name_json;
if (!apn_profile || strlen(apn_profile) <= 0)
break;
char *apn_name = strtok(apn_profile, "($)");
json_object_object_get_ex(val, "profile_name", &profile_name_json);
if (strncmp(apn_name, name, 1024) == 0)
if (!profile_name_json)
goto fail;
char *profile_name = json_object_get_string(profile_name_json);
if (strncmp(profile_name, name, 1024) == 0)
return idx;
idx++;
}
fail:
return -1;
}
......@@ -134,6 +133,7 @@ static int get_apn_profiles_len(void)
len++;
else
goto success;
}
success:
......@@ -459,16 +459,22 @@ fail:
return NULL;
}
struct json_object *mobile_create_apn_profile(char *name)
struct json_object *mobile_create_apn_profile(char *profile_name, char *wan_apn, char *pdp_type)
{
char query[1024] = {0};
//snprintf(query, 1023, "isTest=false&goformId=APN_PROC_EX&apn_action=save&apn_mode=manual&profile_name=%s&wan_dial=*99%23&apn_select=manual&pdp_type=\
%s&pdp_select=auto&pdp_addr=&index=%d&wan_apn=%s&ppp_auth_mode=none&ppp_username=&ppp_passwd=&dns_mode=auto&prefer_dns_manual=&standby_dns_manual=",\
profile_name, pdp_type, get_apn_profiles_len(), wan_apn);
strncpy(query, "isTest=false&goformId=APN_PROC_EX&apn_action=save&apn_mode=manual&profile_name=", 1023);
strncat(query + strlen(query), name, 1023);
strncat(query + strlen(query), "&wan_dial=*99%23&apn_select=manual&pdp_type=IP&pdp_select=auto&pdp_addr=&index=", 1023);
sprintf(query + strlen(query), "%d", get_apn_profiles_len());
strncat(query + strlen(query), profile_name, 1023);
strncat(query + strlen(query), "&wan_dial=*99%23&apn_select=manual&pdp_type=", 1023);
strncat(query + strlen(query), pdp_type, 1023);
strncat(query + strlen(query), "&pdp_select=auto&pdp_addr=&index=", 1023);
snprintf(query + strlen(query), 255, "%d", get_apn_profiles_len());
strncat(query + strlen(query), "&wan_apn=", 1023);
strncat(query + strlen(query), name, 1023);
strncat(query + strlen(query), wan_apn, 1023);
strncat(query + strlen(query), "&ppp_auth_mode=none&ppp_username=&ppp_passwd=&dns_mode=auto&prefer_dns_manual=&standby_dns_manual=", 1023);
return prepare_request(query, POST);
......@@ -492,7 +498,7 @@ struct json_object *mobile_set_apn_profile(char *name)
strncpy(query, "isTest=false&goformId=APN_PROC_EX&apn_mode=manual&apn_action=set_default&set_default_flag=1&pdp_type=IP&index=", 1023);
sprintf(query + strlen(query), "%d", idx);
printf("query %s\n", query);
json_object_put(apn_profiles);
return prepare_request(query, POST);
free_idx:
......
......@@ -182,13 +182,15 @@ struct json_object *mobile_get_apn_profiles(void);
* Creates a new APN profile.
*
* Parameter:
* name - Name of the APN (and WAN) profile to create.
* name - Name of the APN profile to create.
* wan_apn - Name of the wan.
* pdp_type - The pdp type to use IPv4/IPv6.
*
* Returns:
* A pointer to a json_object containing the JSON response from the server. {"result": "success"/"failure"}
* NULL on failure.
*/
struct json_object *mobile_create_apn_profile(char *name);
struct json_object *mobile_create_apn_profile(char *profile_name, char *wan_apn, char *pdp_type);
/**
* Function: mobile_set_apn_profile
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment