diff --git a/libmobile.c b/libmobile.c index 9354f83f14d7f24cf62386624a92288e5656ad3b..5c0df27cbbd7485645762c136f1f5c3e7c254db0 100644 --- a/libmobile.c +++ b/libmobile.c @@ -170,10 +170,9 @@ char *lexer(char **input, char *delimiter) { if (token) *token = '\0'; - else { - printf("delimiter missing!\n"); + else return NULL; - } + char *substr = strdup(*input); *input = token + strlen(delimiter); @@ -181,19 +180,6 @@ char *lexer(char **input, char *delimiter) { return substr; } -/** - * 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) { if (strlen(apn_profiles) <= 0) { @@ -227,7 +213,8 @@ struct json_object *parse_apn_profiles(char *apn_profiles) } char name[1024]; sprintf(name, "%d", apn_counter); - json_object_object_add(parsed_profiles, name, apn_profile); //be careful here, do we need json_object_get(apn_profile)? + json_object_object_add(parsed_profiles, name, json_object_get(apn_profile)); + json_object_put(apn_profile); apn_counter++; } goto finished; diff --git a/libmobile.h b/libmobile.h index a35a92905708d1ae978afd843c8de74667a4a116..2d7e50a94248f5bc086974b861e7813e69de0bcc 100644 --- a/libmobile.h +++ b/libmobile.h @@ -40,7 +40,23 @@ * the caller is then responsible for freeing this memory by calling free(returned_pointer). * ***************************************************/ + +/** + * __TEMPORARILY PLACED IN THIS HEAD__ + * 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); + /** * Function: mobile_connect_network *