diff --git a/libmobile_zte.c b/libmobile_zte.c index 826cdf5a6557f9c3ff8c103e68543393d9a5f507..982e5b3153f105afe7eaebcde666179cdb9ed1df 100644 --- a/libmobile_zte.c +++ b/libmobile_zte.c @@ -18,7 +18,7 @@ static char *lexer(const char **input, char *delimiter); static char *get_query_wrapper(char *ip_addr, char *vars); static CURLcode perform_post_request(char *ip_addr, CURL *curl, char *query, struct string *str); static CURLcode perform_get_request(char *ip_addr, CURL *curl, char *query, struct string *str); -static struct json_object *prepare_request(char *ip_addr, char *query, int option); +static struct json_object *perform_request(char *ip_addr, char *query, int option); static struct json_object *parse_apn_profiles(struct json_object *apn_profiles); /** @@ -275,7 +275,7 @@ static CURLcode perform_get_request(char *ip_addr, CURL *curl, char *query, stru * A pointer to a json_object containing the JSON response from the server. * NULL on failure. */ -static struct json_object *prepare_request(char *ip_addr, char *query, int option) +static struct json_object *perform_request(char *ip_addr, char *query, int option) { CURL *curl; CURLcode rv; @@ -385,12 +385,12 @@ static struct json_object *parse_apn_profiles(struct json_object *apn_profiles) struct json_object *mobile_connect_network_zte(char *ip_addr) { - return prepare_request(ip_addr, "isTest=false¬Callback=true&goformId=CONNECT_NETWORK", POST); + return perform_request(ip_addr, "isTest=false¬Callback=true&goformId=CONNECT_NETWORK", POST); } struct json_object *mobile_disconnect_network_zte(char *ip_addr) { - return prepare_request(ip_addr, "isTest=false¬Callback=true&goformId=DISCONNECT_NETWORK", POST); + return perform_request(ip_addr, "isTest=false¬Callback=true&goformId=DISCONNECT_NETWORK", POST); } struct json_object *mobile_delete_apn_profile_zte(char *ip_addr, char *name) @@ -411,7 +411,7 @@ struct json_object *mobile_delete_apn_profile_zte(char *ip_addr, char *name) snprintf(query, 1023, "isTest=false&apn_action=delete&apn_mode=manual&index=%d&goformId=APN_PROC_EX", idx); json_object_put(apn_profiles); - return prepare_request(ip_addr, query, POST); + return perform_request(ip_addr, query, POST); fail_idx: json_object_put(apn_profiles); @@ -421,17 +421,17 @@ fail: struct json_object *mobile_enable_roaming_zte(char *ip_addr) { - return prepare_request(ip_addr, "isTest=false&goformId=SET_CONNECTION_MODE&roam_setting_option=on", POST); + return perform_request(ip_addr, "isTest=false&goformId=SET_CONNECTION_MODE&roam_setting_option=on", POST); } struct json_object *mobile_disable_roaming_zte(char *ip_addr) { - return prepare_request(ip_addr, "isTest=false&goformId=SET_CONNECTION_MODE&roam_setting_option=off", POST); + return perform_request(ip_addr, "isTest=false&goformId=SET_CONNECTION_MODE&roam_setting_option=off", POST); } struct json_object *mobile_get_roam_status_zte(char *ip_addr) { - return prepare_request(ip_addr, "roam_setting_option", GET); + return perform_request(ip_addr, "roam_setting_option", GET); } struct json_object *mobile_get_current_apn_zte(char *ip_addr) @@ -439,7 +439,7 @@ struct json_object *mobile_get_current_apn_zte(char *ip_addr) struct json_object *current_idx, *idx_json, *apn_profiles, *current_profile; int idx, counter = 0, rv; - idx_json = prepare_request(ip_addr, "Current_index", GET); + idx_json = perform_request(ip_addr, "Current_index", GET); if (!idx_json) { //debug_print("couldn't find index\n"); goto fail; @@ -475,27 +475,27 @@ fail: struct json_object *mobile_get_remaining_tries_zte(char *ip_addr) { - return prepare_request(ip_addr, "pinnumber", GET); + return perform_request(ip_addr, "pinnumber", GET); } struct json_object *mobile_get_pin_status_zte(char *ip_addr) { - return prepare_request(ip_addr, "pin_status", GET); + return perform_request(ip_addr, "pin_status", GET); } struct json_object *mobile_get_rssi_zte(char *ip_addr) { - return prepare_request(ip_addr, "lte_rssi", GET); + return perform_request(ip_addr, "lte_rssi", GET); } struct json_object *mobile_get_modem_state_zte(char *ip_addr) { - return prepare_request(ip_addr, "&sms_received_flag_flag=0&sts_received_flag_flag=0&cmd=modem_main_state%2Cpin_status%2Cloginfo%2Cnew_version_state%2Ccurrent_upgrade_state%2Cis_mandatory%2Csms_received_flag%2Csts_received_flag%2Csignalbar%2Cnetwork_type%2Cnetwork_provider%2Cppp_status%2CEX_SSID1%2Cex_wifi_status%2CEX_wifi_profile%2Cm_ssid_enable%2Csms_unread_num%2CRadioOff%2Csimcard_roam%2Clan_ipaddr%2Cstation_mac%2Cbattery_charging%2Cbattery_vol_percent%2Cbattery_pers%2Cspn_display_flag%2Cplmn_display_flag%2Cspn_name_data%2Cspn_b1_flag%2Cspn_b2_flag%2Crealtime_tx_bytes%2Crealtime_rx_bytes%2Crealtime_time%2Crealtime_tx_thrpt%2Crealtime_rx_thrpt%2Cmonthly_rx_bytes%2Cmonthly_tx_bytes%2Cmonthly_time%2Cdate_month%2Cdata_volume_limit_switch%2Cdata_volume_limit_size%2Cdata_volume_alert_percent%2Cdata_volume_limit_unit%2Croam_setting_option%2Cupg_roam_switch%2Chplmn", GET); + return perform_request(ip_addr, "&sms_received_flag_flag=0&sts_received_flag_flag=0&cmd=modem_main_state%2Cpin_status%2Cloginfo%2Cnew_version_state%2Ccurrent_upgrade_state%2Cis_mandatory%2Csms_received_flag%2Csts_received_flag%2Csignalbar%2Cnetwork_type%2Cnetwork_provider%2Cppp_status%2CEX_SSID1%2Cex_wifi_status%2CEX_wifi_profile%2Cm_ssid_enable%2Csms_unread_num%2CRadioOff%2Csimcard_roam%2Clan_ipaddr%2Cstation_mac%2Cbattery_charging%2Cbattery_vol_percent%2Cbattery_pers%2Cspn_display_flag%2Cplmn_display_flag%2Cspn_name_data%2Cspn_b1_flag%2Cspn_b2_flag%2Crealtime_tx_bytes%2Crealtime_rx_bytes%2Crealtime_time%2Crealtime_tx_thrpt%2Crealtime_rx_thrpt%2Cmonthly_rx_bytes%2Cmonthly_tx_bytes%2Cmonthly_time%2Cdate_month%2Cdata_volume_limit_switch%2Cdata_volume_limit_size%2Cdata_volume_alert_percent%2Cdata_volume_limit_unit%2Croam_setting_option%2Cupg_roam_switch%2Chplmn", GET); } struct json_object *mobile_get_apn_profiles_zte(char *ip_addr) { - struct json_object *apn_profiles = prepare_request(ip_addr, "APN_config0,APN_config1,APN_config2,APN_config3,APN_config4,APN_config5,APN_config6,APN_config7,APN_config8,APN_config9,APN_config10,APN_config11,APN_config12,APN_config13,APN_config14,APN_config15,APN_config16,APN_config17,APN_config18,APN_config19", GET); + struct json_object *apn_profiles = perform_request(ip_addr, "APN_config0,APN_config1,APN_config2,APN_config3,APN_config4,APN_config5,APN_config6,APN_config7,APN_config8,APN_config9,APN_config10,APN_config11,APN_config12,APN_config13,APN_config14,APN_config15,APN_config16,APN_config17,APN_config18,APN_config19", GET); if (!apn_profiles) { //debug_print("Error getting profiles!\n"); @@ -512,7 +512,7 @@ struct json_object *mobile_create_apn_profile_zte(char *ip_addr, char *profile_n 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(ip_addr), wan_apn); - return prepare_request(ip_addr, query, POST); + return perform_request(ip_addr, query, POST); } struct json_object *mobile_set_apn_profile_zte(char *ip_addr, char *name) @@ -534,7 +534,7 @@ struct json_object *mobile_set_apn_profile_zte(char *ip_addr, char *name) snprintf(query, 1023, "isTest=false&goformId=APN_PROC_EX&apn_mode=manual&apn_action=set_default&set_default_flag=1&pdp_type=IP&index=%d", idx); json_object_put(apn_profiles); - return prepare_request(ip_addr, query, POST); + return perform_request(ip_addr, query, POST); free_idx: json_object_put(apn_profiles); fail: @@ -547,7 +547,7 @@ struct json_object *mobile_enable_pin_zte(char *ip_addr, char *pin) snprintf(query, 1023, "isTest=false&goformId=ENABLE_PIN&OldPinNumber=%s&pin_save_flag=0&isTest=false", pin); - return prepare_request(ip_addr, query, POST); + return perform_request(ip_addr, query, POST); } struct json_object *mobile_verify_pin_zte(char *ip_addr, char *pin) @@ -561,7 +561,7 @@ struct json_object *mobile_set_pin_zte(char *ip_addr, char *current_pin, char *n snprintf(query, 1023, "isTest=false&goformId=ENABLE_PIN&OldPinNumber=%s&NewPinNumber=%s&pin_save_flag=0&isTest=false", current_pin, new_pin); - return prepare_request(ip_addr, query, POST); + return perform_request(ip_addr, query, POST); } struct json_object *mobile_disable_pin_zte(char *ip_addr, char *pin) @@ -570,7 +570,7 @@ struct json_object *mobile_disable_pin_zte(char *ip_addr, char *pin) snprintf(query, 1023, "isTest=false&goformId=DISABLE_PIN&OldPinNumber=%s&pin_save_flag=0&isTest=false", pin); - return prepare_request(ip_addr, query, POST); + return perform_request(ip_addr, query, POST); } struct json_object *mobile_unlock_sim_zte(char *ip_addr, char *pin, char *puk) @@ -578,6 +578,6 @@ struct json_object *mobile_unlock_sim_zte(char *ip_addr, char *pin, char *puk) char query[1024] = {0}; snprintf(query, 1023, "isTest=false&goformId=ENTER_PUK&PUKNumber=%s&PinNumber=%s&pin_save_flag=0", puk, pin); - printf("query %s\n", query); - return prepare_request(ip_addr, query, POST); + + return perform_request(ip_addr, query, POST); }