diff --git a/cdr.c b/cdr.c index 93ebfc6..b07da03 100644 --- a/cdr.c +++ b/cdr.c @@ -42,6 +42,21 @@ static const char* cdr_map_status(const char *sip_status) static void free_cdrs(cdr_entry_t **cdrs, uint64_t cdr_count) { + if (!*cdrs) + return; + + for (uint64_t i = 0; i < cdr_count; i++) { + cdr_entry_t *cdr = &(*cdrs)[i]; + +#define F(f, l) g_string_free(cdr->f, TRUE); +#define FA(f, a, l) for (unsigned int j = 0; j < a; j++) g_string_free(cdr->f[j], TRUE); + +#include "cdr_field_names.inc" + +#undef F +#undef FA + } + g_free(*cdrs); *cdrs = NULL; } @@ -224,19 +239,18 @@ static inline int hexval(unsigned char c) { } /* un-uri-escape string in place */ -static void uri_unescape(char *str) { - unsigned char *s, *d; +static void uri_unescape(GString *str) { + unsigned char *s; unsigned int c; int cv; + GString *dup = g_string_new(""); - s = (unsigned char *) str; - d = (unsigned char *) str; + s = (unsigned char *) str->str; while (*s) { if (*s != '%') { copy: - *d = *s; - d++; + g_string_append_c(dup, *s); s++; continue; } @@ -252,11 +266,12 @@ copy: if (!c) /* disallow null bytes */ goto copy; - *d = c; + g_string_append_c(dup, c); s += 3; - d++; } - *d = 0; + g_string_truncate(str, 0); + g_string_append_len(str, dup->str, dup->len); + g_string_free(dup, TRUE); } static int cdr_parse_json_get_uint8(json_object *obj, const char *key, uint8_t *outp) { @@ -329,98 +344,96 @@ static int cdr_parse_json_get_double_clamped(json_object *obj, const char *key, return 1; } -#define cdr_parse_json_get_strbuf(obj, key, outp) cdr_parse_json_get_string(obj, key, outp, sizeof(outp)) - -static int cdr_parse_json_get_string(json_object *obj, const char *key, char *outp, size_t len) { +static int cdr_parse_json_get_g_string(json_object *obj, const char *key, GString *outp) { json_object *str_obj; if (!json_object_object_get_ex(obj, key, &str_obj)) return 0; if (!json_object_is_type(str_obj, json_type_string)) return 0; // TODO: if string equals to , null or NULL set it to an empty string '\0' - g_strlcpy(outp, json_object_get_string(str_obj), len); + g_string_assign(outp, json_object_get_string(str_obj)); return 1; } static int cdr_parse_srcleg_json(json_object *json, cdr_entry_t *cdr) { // source_user_id - if (!cdr_parse_json_get_strbuf(json, "uuid", cdr->source_user_id)) { - L_ERROR("Call-Id '%s' does not contain 'uuid' key (source user id), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "uuid", cdr->source_user_id)) { + L_ERROR("Call-Id '%s' does not contain 'uuid' key (source user id), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // source_user - if (!cdr_parse_json_get_strbuf(json, "u", cdr->source_user)) { - L_ERROR("Call-Id '%s' does not contain 'u' key (source user), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "u", cdr->source_user)) { + L_ERROR("Call-Id '%s' does not contain 'u' key (source user), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // source_domain - if (!cdr_parse_json_get_strbuf(json, "d", cdr->source_domain)) { - L_ERROR("Call-Id '%s' does not contain 'd' key (source domain), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "d", cdr->source_domain)) { + L_ERROR("Call-Id '%s' does not contain 'd' key (source domain), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // source_cli - if (!cdr_parse_json_get_strbuf(json, "cli", cdr->source_cli)) { - L_ERROR("Call-Id '%s' does not contain 'cli' key (source cli), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "cli", cdr->source_cli)) { + L_ERROR("Call-Id '%s' does not contain 'cli' key (source cli), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // source_ext_subscriber_id - if (!cdr_parse_json_get_strbuf(json, "s_id", cdr->source_ext_subscriber_id)) { - L_ERROR("Call-Id '%s' does not contain 's_id' key (source external subscriber id), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "s_id", cdr->source_ext_subscriber_id)) { + L_ERROR("Call-Id '%s' does not contain 's_id' key (source external subscriber id), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } uri_unescape(cdr->source_ext_subscriber_id); // source_ext_contract_id - if (!cdr_parse_json_get_strbuf(json, "c_id", cdr->source_ext_contract_id)) { - L_ERROR("Call-Id '%s' does not contain 'c_id' key (source external contract id), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "c_id", cdr->source_ext_contract_id)) { + L_ERROR("Call-Id '%s' does not contain 'c_id' key (source external contract id), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } uri_unescape(cdr->source_ext_contract_id); // source_account_id if (!cdr_parse_json_get_uint64(json, "a_id", &cdr->source_account_id)) { - L_ERROR("Call-Id '%s' does not contain 'a_id' key (source account id), '%s'", cdr->call_id, json_object_get_string(json)); + L_ERROR("Call-Id '%s' does not contain 'a_id' key (source account id), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // peer_auth_user - if (!cdr_parse_json_get_strbuf(json, "pau", cdr->peer_auth_user)) { - L_ERROR("Call-Id '%s' does not contain 'pau' key (peer auth user), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "pau", cdr->peer_auth_user)) { + L_ERROR("Call-Id '%s' does not contain 'pau' key (peer auth user), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // peer_auth_realm - if (!cdr_parse_json_get_strbuf(json, "par", cdr->peer_auth_realm)) { - L_ERROR("Call-Id '%s' does not contain 'par' key (peer auth realm), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "par", cdr->peer_auth_realm)) { + L_ERROR("Call-Id '%s' does not contain 'par' key (peer auth realm), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // source_clir if (!cdr_parse_json_get_uint8_clamped(json, "clir", &cdr->source_clir, 0, 1)) { - L_ERROR("Call-Id '%s' does not contain 'clir' key (source account id), '%s'", cdr->call_id, json_object_get_string(json)); + L_ERROR("Call-Id '%s' does not contain 'clir' key (source account id), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // call_type - if (!cdr_parse_json_get_strbuf(json, "s", cdr->call_type)) { - L_ERROR("Call-Id '%s' does not contain 's' key (call type), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "s", cdr->call_type)) { + L_ERROR("Call-Id '%s' does not contain 's' key (call type), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // source_ip - if (!cdr_parse_json_get_strbuf(json, "ip", cdr->source_ip)) { - L_ERROR("Call-Id '%s' does not contain 'ip' key (source ip), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "ip", cdr->source_ip)) { + L_ERROR("Call-Id '%s' does not contain 'ip' key (source ip), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // init_time if (!cdr_parse_json_get_double(json, "t", &cdr->init_time)) { - L_ERROR("Call-Id '%s' does not contain 't' key (source init time), '%s'", cdr->call_id, json_object_get_string(json)); + L_ERROR("Call-Id '%s' does not contain 't' key (source init time), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } @@ -428,87 +441,87 @@ static int cdr_parse_srcleg_json(json_object *json, cdr_entry_t *cdr) // source_gpp if(!json_object_object_get_ex(json, "gpp", &temp_value)) { - L_ERROR("Call-Id '%s' does not contain 'gpp' key (source gpp list), '%s'", cdr->call_id, json_object_get_string(json)); + L_ERROR("Call-Id '%s' does not contain 'gpp' key (source gpp list), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } if (!json_object_is_type(temp_value, json_type_array)) { - L_ERROR("Call-Id '%s' key 'gpp' doesn't contain an array, '%s'", cdr->call_id, json_object_get_string(json)); + L_ERROR("Call-Id '%s' key 'gpp' doesn't contain an array, '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } if(json_object_array_length(temp_value) != 10) { - L_ERROR("Call-Id '%s' has only '%zu' source gpp fields, they should be 10, '%s'", cdr->call_id, json_object_array_length(temp_value), json_object_get_string(json)); + L_ERROR("Call-Id '%s' has only '%zu' source gpp fields, they should be 10, '%s'", cdr->call_id->str, json_object_array_length(temp_value), json_object_get_string(json)); goto err; } int i; for(i = 0; i < 10; ++i) { - g_strlcpy(cdr->source_gpp[i], json_object_get_string(json_object_array_get_idx(temp_value, i)) ? : "", sizeof(cdr->source_gpp[i])); + g_string_assign(cdr->source_gpp[i], json_object_get_string(json_object_array_get_idx(temp_value, i)) ? : ""); } // source_lnp_prefix if(!json_object_object_get_ex(json, "lnp_p", &temp_value)) { if (strict_leg_tokens) { // TODO: "Strict acc fields (move to trash otherwise)" What is the meaning of this param??? is it still necessary - L_ERROR("Call-Id '%s' does not contain 'lnp_p' key (source lnp prefix), '%s'", cdr->call_id, json_object_get_string(json)); + L_ERROR("Call-Id '%s' does not contain 'lnp_p' key (source lnp prefix), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } else { - cdr->source_lnp_prefix[0] = '\0'; - cdr->source_user_out[0] = '\0'; - L_WARNING("Call-Id '%s' does not contain 'lnp_p' key, using empty source lnp prefix and source user out '%s'", cdr->call_id, json_object_get_string(json)); + g_string_truncate(cdr->source_lnp_prefix, 0); + g_string_truncate(cdr->source_user_out, 0); + L_WARNING("Call-Id '%s' does not contain 'lnp_p' key, using empty source lnp prefix and source user out '%s'", cdr->call_id->str, json_object_get_string(json)); goto ret; } } - g_strlcpy(cdr->source_lnp_prefix, json_object_get_string(temp_value), sizeof(cdr->source_lnp_prefix)); + g_string_assign(cdr->source_lnp_prefix, json_object_get_string(temp_value)); // source_user_out if(!json_object_object_get_ex(json, "cli_out", &temp_value)) { if (strict_leg_tokens) { // TODO: "Strict acc fields (move to trash otherwise)" What is the meaning of this param??? is it still necessary - L_ERROR("Call-Id '%s' does not contain 'cli_out' key (source user out), '%s'", cdr->call_id, json_object_get_string(json)); + L_ERROR("Call-Id '%s' does not contain 'cli_out' key (source user out), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } else { - cdr->source_user_out[0] = '\0'; - L_WARNING("Call-Id '%s' does not contain 'cli_out' key, using empty source user out '%s'", cdr->call_id, json_object_get_string(json)); + g_string_truncate(cdr->source_user_out, 0); + L_WARNING("Call-Id '%s' does not contain 'cli_out' key, using empty source user out '%s'", cdr->call_id->str, json_object_get_string(json)); goto ret; } } - g_strlcpy(cdr->source_user_out, json_object_get_string(temp_value), sizeof(cdr->source_user_out)); + g_string_assign(cdr->source_user_out, json_object_get_string(temp_value)); uri_unescape(cdr->source_user_out); // source_lnp_type - if (!cdr_parse_json_get_strbuf(json, "lnp_t", cdr->source_lnp_type)) { - L_ERROR("Call-Id '%s' does not contain 'lnp_t' key (source lnp type), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "lnp_t", cdr->source_lnp_type)) { + L_ERROR("Call-Id '%s' does not contain 'lnp_t' key (source lnp type), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // header_pai - if (!cdr_parse_json_get_strbuf(json, "pai", cdr->header_pai)) { - L_ERROR("Call-Id '%s' does not contain 'pai' key (P-Asserted-Identity header), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "pai", cdr->header_pai)) { + L_ERROR("Call-Id '%s' does not contain 'pai' key (P-Asserted-Identity header), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // header_diversion - if (!cdr_parse_json_get_strbuf(json, "div", cdr->header_diversion)) { - L_ERROR("Call-Id '%s' does not contain 'div' key (Diversion header), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "div", cdr->header_diversion)) { + L_ERROR("Call-Id '%s' does not contain 'div' key (Diversion header), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // group - if (!cdr_parse_json_get_strbuf(json, "cid", cdr->group)) { - L_ERROR("Call-Id '%s' does not contain 'cid' key (group info), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "cid", cdr->group)) { + L_ERROR("Call-Id '%s' does not contain 'cid' key (group info), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // header_u2u - if (!cdr_parse_json_get_strbuf(json, "u2u", cdr->header_u2u)) { - L_ERROR("Call-Id '%s' does not contain 'u2u' key (User-to-User header), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "u2u", cdr->header_u2u)) { + L_ERROR("Call-Id '%s' does not contain 'u2u' key (User-to-User header), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // source_lcr_id if (!cdr_parse_json_get_uint64(json, "lcr", &cdr->source_lcr_id)) { - L_DEBUG("Call-Id '%s' does not contain 'lcr' key (source lcr id), '%s'", cdr->call_id, json_object_get_string(json)); + L_DEBUG("Call-Id '%s' does not contain 'lcr' key (source lcr id), '%s'", cdr->call_id->str, json_object_get_string(json)); /// Simply return 0 in order to avoid issues with ACC records in the OLD format during an upgrade /// Added in mr8.1, it should be changed to -1 in mr9.+ /// goto err; @@ -516,32 +529,32 @@ static int cdr_parse_srcleg_json(json_object *json, cdr_entry_t *cdr) } // source_concurrent_calls_quota - if (!cdr_parse_json_get_strbuf(json, "cc_quota", cdr->source_concurrent_calls_quota)) { - L_DEBUG("Call-Id '%s' does not contain 'cc_quota' key (source concurrent calls quota), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "cc_quota", cdr->source_concurrent_calls_quota)) { + L_DEBUG("Call-Id '%s' does not contain 'cc_quota' key (source concurrent calls quota), '%s'", cdr->call_id->str, json_object_get_string(json)); /// Added in mr8.3, it should be changed to -1 in mr9.+ /// goto err; goto ret; } // source_concurrent_calls_count - if (!cdr_parse_json_get_strbuf(json, "cc_sub", cdr->source_concurrent_calls_count)) { - L_DEBUG("Call-Id '%s' does not contain 'cc_sub' key (source concurrent calls count), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "cc_sub", cdr->source_concurrent_calls_count)) { + L_DEBUG("Call-Id '%s' does not contain 'cc_sub' key (source concurrent calls count), '%s'", cdr->call_id->str, json_object_get_string(json)); /// Added in mr8.3, it should be changed to -1 in mr9.+ /// goto err; goto ret; } // source_concurrent_calls_count_customer - if (!cdr_parse_json_get_strbuf(json, "cc_cust", cdr->source_concurrent_calls_count_customer)) { - L_DEBUG("Call-Id '%s' does not contain 'cc_cust' key (source concurrent calls count customer), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "cc_cust", cdr->source_concurrent_calls_count_customer)) { + L_DEBUG("Call-Id '%s' does not contain 'cc_cust' key (source concurrent calls count customer), '%s'", cdr->call_id->str, json_object_get_string(json)); /// Added in mr8.3, it should be changed to -1 in mr9.+ /// goto err; goto ret; } // source_last_hih - if (!cdr_parse_json_get_strbuf(json, "last_hih", cdr->source_last_hih)) { - L_DEBUG("Call-Id '%s' does not contain 'last_hih' key (source last hih), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "last_hih", cdr->source_last_hih)) { + L_DEBUG("Call-Id '%s' does not contain 'last_hih' key (source last hih), '%s'", cdr->call_id->str, json_object_get_string(json)); /// Added in mr9.4, it should be changed to -1 in mr10.+ /// goto err; goto ret; @@ -560,69 +573,69 @@ static int cdr_parse_dstleg_json(json_object *json, cdr_entry_t *cdr) { // split if (!cdr_parse_json_get_uint8(json, "plu", &cdr->split)) { - L_ERROR("Call-Id '%s' does not contain 'plu' key (split flag), '%s'", cdr->call_id, json_object_get_string(json)); + L_ERROR("Call-Id '%s' does not contain 'plu' key (split flag), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // destination_ext_subscriber_id - if (!cdr_parse_json_get_strbuf(json, "s_id", cdr->destination_ext_subscriber_id)) { - L_ERROR("Call-Id '%s' does not contain 's_id' key (destination external subscriber id), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "s_id", cdr->destination_ext_subscriber_id)) { + L_ERROR("Call-Id '%s' does not contain 's_id' key (destination external subscriber id), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } uri_unescape(cdr->destination_ext_subscriber_id); // destination_ext_contract_id - if (!cdr_parse_json_get_strbuf(json, "c_id", cdr->destination_ext_contract_id)) { - L_ERROR("Call-Id '%s' does not contain 'c_id' key (destination external contract id), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "c_id", cdr->destination_ext_contract_id)) { + L_ERROR("Call-Id '%s' does not contain 'c_id' key (destination external contract id), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } uri_unescape(cdr->destination_ext_contract_id); // destination_account_id if (!cdr_parse_json_get_uint64(json, "a_id", &cdr->destination_account_id)) { - L_ERROR("Call-Id '%s' does not contain 'a_id' key (destination account id), '%s'", cdr->call_id, json_object_get_string(json)); + L_ERROR("Call-Id '%s' does not contain 'a_id' key (destination account id), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // destination_dialed - if (!cdr_parse_json_get_strbuf(json, "dialed", cdr->destination_dialed)) { - L_ERROR("Call-Id '%s' does not contain 'dialed' key (dialed digit), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "dialed", cdr->destination_dialed)) { + L_ERROR("Call-Id '%s' does not contain 'dialed' key (dialed digit), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // destination_user_id - if (!cdr_parse_json_get_strbuf(json, "uuid", cdr->destination_user_id)) { - L_ERROR("Call-Id '%s' does not contain 'uuid' key (destination user id), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "uuid", cdr->destination_user_id)) { + L_ERROR("Call-Id '%s' does not contain 'uuid' key (destination user id), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // destination_user - if (!cdr_parse_json_get_strbuf(json, "u", cdr->destination_user)) { - L_ERROR("Call-Id '%s' does not contain 'u' key (destination user), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "u", cdr->destination_user)) { + L_ERROR("Call-Id '%s' does not contain 'u' key (destination user), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // destination_domain - if (!cdr_parse_json_get_strbuf(json, "d", cdr->destination_domain)) { - L_ERROR("Call-Id '%s' does not contain 'd' key (destination domain), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "d", cdr->destination_domain)) { + L_ERROR("Call-Id '%s' does not contain 'd' key (destination domain), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // destination_user_in - if (!cdr_parse_json_get_strbuf(json, "u_in", cdr->destination_user_in)) { - L_ERROR("Call-Id '%s' does not contain 'u_in' key (incoming destination user), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "u_in", cdr->destination_user_in)) { + L_ERROR("Call-Id '%s' does not contain 'u_in' key (incoming destination user), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // destination_domain_in - if (!cdr_parse_json_get_strbuf(json, "d_in", cdr->destination_domain_in)) { - L_ERROR("Call-Id '%s' does not contain 'd_in' key (incoming destination domain), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "d_in", cdr->destination_domain_in)) { + L_ERROR("Call-Id '%s' does not contain 'd_in' key (incoming destination domain), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // destination_lcr_id if (!cdr_parse_json_get_uint64(json, "lcr", &cdr->destination_lcr_id)) { - L_ERROR("Call-Id '%s' does not contain 'lcr' key (lcr id), '%s'", cdr->call_id, json_object_get_string(json)); + L_ERROR("Call-Id '%s' does not contain 'lcr' key (lcr id), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } @@ -630,85 +643,85 @@ static int cdr_parse_dstleg_json(json_object *json, cdr_entry_t *cdr) // destination_gpp if(!json_object_object_get_ex(json, "gpp", &temp_value)) { - L_ERROR("Call-Id '%s' does not contain 'gpp' key (source gpp list), '%s'", cdr->call_id, json_object_get_string(json)); + L_ERROR("Call-Id '%s' does not contain 'gpp' key (source gpp list), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } if (!json_object_is_type(temp_value, json_type_array)) { - L_ERROR("Call-Id '%s' key 'gpp' doesn't contain an array, '%s'", cdr->call_id, json_object_get_string(json)); + L_ERROR("Call-Id '%s' key 'gpp' doesn't contain an array, '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } if(json_object_array_length(temp_value) != 10) { - L_ERROR("Call-Id '%s' has only '%zu' destination gpp fields, they should be 10, '%s'", cdr->call_id, json_object_array_length(temp_value), json_object_get_string(json)); + L_ERROR("Call-Id '%s' has only '%zu' destination gpp fields, they should be 10, '%s'", cdr->call_id->str, json_object_array_length(temp_value), json_object_get_string(json)); goto err; } int i; for(i = 0; i < 10; ++i) { - g_strlcpy(cdr->destination_gpp[i], json_object_get_string(json_object_array_get_idx(temp_value, i)) ? : "", sizeof(cdr->destination_gpp[i])); + g_string_assign(cdr->destination_gpp[i], json_object_get_string(json_object_array_get_idx(temp_value, i)) ? : ""); } // destination_lnp_prefix if(!json_object_object_get_ex(json, "lnp_p", &temp_value)) { if (strict_leg_tokens) { // TODO: "Strict acc fields (move to trash otherwise)" What is the meaning of this param??? is it still necessary - L_ERROR("Call-Id '%s' does not contain 'lnp_p' key (destination lnp prefix), '%s'", cdr->call_id, json_object_get_string(json)); + L_ERROR("Call-Id '%s' does not contain 'lnp_p' key (destination lnp prefix), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } else { - cdr->destination_lnp_prefix[0] = '\0'; - cdr->destination_user_out[0] = '\0'; - L_WARNING("Call-Id '%s' does not contain 'lnp_p' key, using empty destination lnp prefix and destination user out '%s'", cdr->call_id, json_object_get_string(json)); + g_string_truncate(cdr->destination_lnp_prefix, 0); + g_string_truncate(cdr->destination_user_out, 0); + L_WARNING("Call-Id '%s' does not contain 'lnp_p' key, using empty destination lnp prefix and destination user out '%s'", cdr->call_id->str, json_object_get_string(json)); goto ret; } } - g_strlcpy(cdr->destination_lnp_prefix, json_object_get_string(temp_value), sizeof(cdr->destination_lnp_prefix)); + g_string_assign(cdr->destination_lnp_prefix, json_object_get_string(temp_value)); // destination_user_out if(!json_object_object_get_ex(json, "u_out", &temp_value)) { if (strict_leg_tokens) { // TODO: "Strict acc fields (move to trash otherwise)" What is the meaning of this param??? is it still necessary - L_ERROR("Call-Id '%s' does not contain 'cli_out' key (source user out), '%s'", cdr->call_id, json_object_get_string(json)); + L_ERROR("Call-Id '%s' does not contain 'cli_out' key (source user out), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } else { - cdr->destination_user_out[0] = '\0'; - L_WARNING("Call-Id '%s' does not contain 'cli_out' key, using empty destination user out '%s'", cdr->call_id, json_object_get_string(json)); + g_string_truncate(cdr->destination_user_out, 0); + L_WARNING("Call-Id '%s' does not contain 'cli_out' key, using empty destination user out '%s'", cdr->call_id->str, json_object_get_string(json)); goto ret; } } - g_strlcpy(cdr->destination_user_out, json_object_get_string(temp_value), sizeof(cdr->destination_user_out)); + g_string_assign(cdr->destination_user_out, json_object_get_string(temp_value)); uri_unescape(cdr->destination_user_out); // destination_lnp_type - if (!cdr_parse_json_get_strbuf(json, "lnp_t", cdr->destination_lnp_type)) { - L_ERROR("Call-Id '%s' does not contain 'lnp_t' key (destination lnp type), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "lnp_t", cdr->destination_lnp_type)) { + L_ERROR("Call-Id '%s' does not contain 'lnp_t' key (destination lnp type), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // furnished_charging_info - if (!cdr_parse_json_get_strbuf(json, "fci", cdr->furnished_charging_info)) { - L_ERROR("Call-Id '%s' does not contain 'fci' key (furnished charging info), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "fci", cdr->furnished_charging_info)) { + L_ERROR("Call-Id '%s' does not contain 'fci' key (furnished charging info), '%s'", cdr->call_id->str, json_object_get_string(json)); goto err; } // destination_concurrent_calls_quota - if (!cdr_parse_json_get_strbuf(json, "cc_quota", cdr->destination_concurrent_calls_quota)) { - L_DEBUG("Call-Id '%s' does not contain 'cc_quota' key (destination concurrent calls quota), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "cc_quota", cdr->destination_concurrent_calls_quota)) { + L_DEBUG("Call-Id '%s' does not contain 'cc_quota' key (destination concurrent calls quota), '%s'", cdr->call_id->str, json_object_get_string(json)); /// Added in mr8.3, it should be changed to -1 in mr9.+ /// goto err; goto ret; } // destination_concurrent_calls_count - if (!cdr_parse_json_get_strbuf(json, "cc_sub", cdr->destination_concurrent_calls_count)) { - L_DEBUG("Call-Id '%s' does not contain 'cc_sub' key (destination concurrent calls count), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "cc_sub", cdr->destination_concurrent_calls_count)) { + L_DEBUG("Call-Id '%s' does not contain 'cc_sub' key (destination concurrent calls count), '%s'", cdr->call_id->str, json_object_get_string(json)); /// Added in mr8.3, it should be changed to -1 in mr9.+ /// goto err; goto ret; } // destination_concurrent_calls_count_customer - if (!cdr_parse_json_get_strbuf(json, "cc_cust", cdr->destination_concurrent_calls_count_customer)) { - L_DEBUG("Call-Id '%s' does not contain 'cc_cust' key (destination concurrent calls count customer), '%s'", cdr->call_id, json_object_get_string(json)); + if (!cdr_parse_json_get_g_string(json, "cc_cust", cdr->destination_concurrent_calls_count_customer)) { + L_DEBUG("Call-Id '%s' does not contain 'cc_cust' key (destination concurrent calls count customer), '%s'", cdr->call_id->str, json_object_get_string(json)); /// Added in mr8.3, it should be changed to -1 in mr9.+ /// goto err; goto ret; @@ -732,22 +745,22 @@ static int cdr_parse_srcleg_list(char *srcleg, cdr_entry_t *cdr) tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated source user id, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated source user id, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->source_user_id, tmp2, sizeof(cdr->source_user_id)); + g_string_assign(cdr->source_user_id, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated source user, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated source user, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->source_user, tmp2, sizeof(cdr->source_user)); + g_string_assign(cdr->source_user, tmp2); uri_unescape(cdr->source_user); *tmp1 = MED_SEP; tmp2 = ++tmp1; @@ -755,11 +768,11 @@ static int cdr_parse_srcleg_list(char *srcleg, cdr_entry_t *cdr) tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated source domain, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated source domain, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->source_domain, tmp2, sizeof(cdr->source_domain)); + g_string_assign(cdr->source_domain, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; @@ -767,11 +780,11 @@ static int cdr_parse_srcleg_list(char *srcleg, cdr_entry_t *cdr) tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated source cli, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated source cli, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->source_cli, tmp2, sizeof(cdr->source_cli)); + g_string_assign(cdr->source_cli, tmp2); uri_unescape(cdr->source_cli); *tmp1 = MED_SEP; tmp2 = ++tmp1; @@ -779,11 +792,11 @@ static int cdr_parse_srcleg_list(char *srcleg, cdr_entry_t *cdr) tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated source external subscriber id, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated source external subscriber id, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->source_ext_subscriber_id, tmp2, sizeof(cdr->source_ext_subscriber_id)); + g_string_assign(cdr->source_ext_subscriber_id, tmp2); uri_unescape(cdr->source_ext_subscriber_id); *tmp1 = MED_SEP; tmp2 = ++tmp1; @@ -791,11 +804,11 @@ static int cdr_parse_srcleg_list(char *srcleg, cdr_entry_t *cdr) tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated source external contract id, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated source external contract id, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->source_ext_contract_id, tmp2, sizeof(cdr->source_ext_contract_id)); + g_string_assign(cdr->source_ext_contract_id, tmp2); uri_unescape(cdr->source_ext_contract_id); *tmp1 = MED_SEP; tmp2 = ++tmp1; @@ -803,7 +816,7 @@ static int cdr_parse_srcleg_list(char *srcleg, cdr_entry_t *cdr) tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated source account id, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated source account id, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; @@ -814,29 +827,29 @@ static int cdr_parse_srcleg_list(char *srcleg, cdr_entry_t *cdr) tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated peer auth user, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated peer auth user, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->peer_auth_user, tmp2, sizeof(cdr->peer_auth_user)); + g_string_assign(cdr->peer_auth_user, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated peer auth realm, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated peer auth realm, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->peer_auth_realm, tmp2, sizeof(cdr->peer_auth_realm)); + g_string_assign(cdr->peer_auth_realm, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated source clir status, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated source clir status, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; @@ -847,29 +860,29 @@ static int cdr_parse_srcleg_list(char *srcleg, cdr_entry_t *cdr) tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated call type, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated call type, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->call_type, tmp2, sizeof(cdr->call_type)); + g_string_assign(cdr->call_type, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated source ip, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated source ip, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->source_ip, tmp2, sizeof(cdr->source_ip)); + g_string_assign(cdr->source_ip, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated source init time, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated source init time, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; @@ -883,11 +896,11 @@ static int cdr_parse_srcleg_list(char *srcleg, cdr_entry_t *cdr) tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated source gpp %d, '%s'", cdr->call_id, i, tmp2); + L_ERROR("Call-Id '%s' has no separated source gpp %d, '%s'", cdr->call_id->str, i, tmp2); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->source_gpp[i], tmp2, sizeof(cdr->source_gpp[i])); + g_string_assign(cdr->source_gpp[i], tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; } @@ -896,17 +909,17 @@ static int cdr_parse_srcleg_list(char *srcleg, cdr_entry_t *cdr) if(tmp1 == NULL) { if (strict_leg_tokens) { - L_ERROR("Call-Id '%s' has no separated source lnp prefix, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated source lnp prefix, '%s'", cdr->call_id->str, tmp2); return -1; } else { - cdr->source_lnp_prefix[0] = '\0'; - cdr->source_user_out[0] = '\0'; - L_WARNING("Call-Id '%s' src leg has missing tokens (using empty lnp prefix, user out) '%s'", cdr->call_id, tmp2); + g_string_truncate(cdr->source_lnp_prefix, 0); + g_string_truncate(cdr->source_user_out, 0); + L_WARNING("Call-Id '%s' src leg has missing tokens (using empty lnp prefix, user out) '%s'", cdr->call_id->str, tmp2); return 0; } } *tmp1 = '\0'; - g_strlcpy(cdr->source_lnp_prefix, tmp2, sizeof(cdr->source_lnp_prefix)); + g_string_assign(cdr->source_lnp_prefix, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; @@ -914,16 +927,16 @@ static int cdr_parse_srcleg_list(char *srcleg, cdr_entry_t *cdr) if(tmp1 == NULL) { if (strict_leg_tokens) { - L_ERROR("Call-Id '%s' has no separated source user out, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated source user out, '%s'", cdr->call_id->str, tmp2); return -1; } else { - cdr->source_user_out[0] = '\0'; - L_WARNING("Call-Id '%s' src leg has missing tokens (using empty user out) '%s'", cdr->call_id, tmp2); + g_string_truncate(cdr->source_user_out, 0); + L_WARNING("Call-Id '%s' src leg has missing tokens (using empty user out) '%s'", cdr->call_id->str, tmp2); return 0; } } *tmp1 = '\0'; - g_strlcpy(cdr->source_user_out, tmp2, sizeof(cdr->source_user_out)); + g_string_assign(cdr->source_user_out, tmp2); uri_unescape(cdr->source_user_out); *tmp1 = MED_SEP; tmp2 = ++tmp1; @@ -931,62 +944,62 @@ static int cdr_parse_srcleg_list(char *srcleg, cdr_entry_t *cdr) tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated source lnp type, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated source lnp type, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->source_lnp_type, tmp2, sizeof(cdr->source_lnp_type)); + g_string_assign(cdr->source_lnp_type, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated P-Asserted-Identity header, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated P-Asserted-Identity header, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->header_pai, tmp2, sizeof(cdr->header_pai)); + g_string_assign(cdr->header_pai, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated Diversion header, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated Diversion header, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->header_diversion, tmp2, sizeof(cdr->header_diversion)); + g_string_assign(cdr->header_diversion, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated group info, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated group info, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->group, tmp2, sizeof(cdr->group)); + g_string_assign(cdr->group, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated User-to-User header, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated User-to-User header, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->header_u2u, tmp2, sizeof(cdr->header_u2u)); + g_string_assign(cdr->header_u2u, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_DEBUG("Call-Id '%s' has no separated source lcr id, '%s'", cdr->call_id, tmp2); + L_DEBUG("Call-Id '%s' has no separated source lcr id, '%s'", cdr->call_id->str, tmp2); /// Simply return 0 in order to avoid issues with ACC records in the OLD format during an upgrade /// Added in mr8.1, it should be changed to -1 in mr9.+ return 0; @@ -999,36 +1012,36 @@ static int cdr_parse_srcleg_list(char *srcleg, cdr_entry_t *cdr) tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_DEBUG("Call-Id '%s' has no separated source concurrent calls quota, '%s'", cdr->call_id, tmp2); + L_DEBUG("Call-Id '%s' has no separated source concurrent calls quota, '%s'", cdr->call_id->str, tmp2); /// Added in mr8.3, it should be changed to -1 in mr9.+ return 0; } *tmp1 = '\0'; - g_strlcpy(cdr->source_concurrent_calls_quota, tmp2, sizeof(cdr->source_concurrent_calls_quota)); + g_string_assign(cdr->source_concurrent_calls_quota, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_DEBUG("Call-Id '%s' has no separated source concurrent calls count, '%s'", cdr->call_id, tmp2); + L_DEBUG("Call-Id '%s' has no separated source concurrent calls count, '%s'", cdr->call_id->str, tmp2); /// Added in mr8.3, it should be changed to -1 in mr9.+ return 0; } *tmp1 = '\0'; - g_strlcpy(cdr->source_concurrent_calls_count, tmp2, sizeof(cdr->source_concurrent_calls_count)); + g_string_assign(cdr->source_concurrent_calls_count, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_DEBUG("Call-Id '%s' has no separated source concurrent calls customer count, '%s'", cdr->call_id, tmp2); + L_DEBUG("Call-Id '%s' has no separated source concurrent calls customer count, '%s'", cdr->call_id->str, tmp2); /// Added in mr8.3, it should be changed to -1 in mr9.+ return 0; } *tmp1 = '\0'; - g_strlcpy(cdr->source_concurrent_calls_count_customer, tmp2, sizeof(cdr->source_concurrent_calls_count_customer)); + g_string_assign(cdr->source_concurrent_calls_count_customer, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; @@ -1044,7 +1057,7 @@ static int cdr_parse_dstleg_list(char *dstleg, cdr_entry_t *cdr) tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated split flag, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated split flag, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; @@ -1055,11 +1068,11 @@ static int cdr_parse_dstleg_list(char *dstleg, cdr_entry_t *cdr) tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated destination external subscriber id, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated destination external subscriber id, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->destination_ext_subscriber_id, tmp2, sizeof(cdr->destination_ext_subscriber_id)); + g_string_assign(cdr->destination_ext_subscriber_id, tmp2); uri_unescape(cdr->destination_ext_subscriber_id); *tmp1 = MED_SEP; tmp2 = ++tmp1; @@ -1067,11 +1080,11 @@ static int cdr_parse_dstleg_list(char *dstleg, cdr_entry_t *cdr) tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated destination external contract id, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated destination external contract id, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->destination_ext_contract_id, tmp2, sizeof(cdr->destination_ext_contract_id)); + g_string_assign(cdr->destination_ext_contract_id, tmp2); uri_unescape(cdr->destination_ext_contract_id); *tmp1 = MED_SEP; tmp2 = ++tmp1; @@ -1079,7 +1092,7 @@ static int cdr_parse_dstleg_list(char *dstleg, cdr_entry_t *cdr) tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated destination account id, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated destination account id, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; @@ -1090,73 +1103,73 @@ static int cdr_parse_dstleg_list(char *dstleg, cdr_entry_t *cdr) tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated dialed digits", cdr->call_id); + L_ERROR("Call-Id '%s' has no separated dialed digits", cdr->call_id->str); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->destination_dialed, tmp2, sizeof(cdr->destination_dialed)); + g_string_assign(cdr->destination_dialed, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated destination user id", cdr->call_id); + L_ERROR("Call-Id '%s' has no separated destination user id", cdr->call_id->str); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->destination_user_id, tmp2, sizeof(cdr->destination_user_id)); + g_string_assign(cdr->destination_user_id, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated destination user", cdr->call_id); + L_ERROR("Call-Id '%s' has no separated destination user", cdr->call_id->str); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->destination_user, tmp2, sizeof(cdr->destination_user)); + g_string_assign(cdr->destination_user, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated destination domain", cdr->call_id); + L_ERROR("Call-Id '%s' has no separated destination domain", cdr->call_id->str); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->destination_domain, tmp2, sizeof(cdr->destination_domain)); + g_string_assign(cdr->destination_domain, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated incoming destination user", cdr->call_id); + L_ERROR("Call-Id '%s' has no separated incoming destination user", cdr->call_id->str); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->destination_user_in, tmp2, sizeof(cdr->destination_user_in)); + g_string_assign(cdr->destination_user_in, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated incoming destination domain", cdr->call_id); + L_ERROR("Call-Id '%s' has no separated incoming destination domain", cdr->call_id->str); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->destination_domain_in, tmp2, sizeof(cdr->destination_domain_in)); + g_string_assign(cdr->destination_domain_in, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated destination lcr id, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated destination lcr id, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; @@ -1170,11 +1183,11 @@ static int cdr_parse_dstleg_list(char *dstleg, cdr_entry_t *cdr) tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated destination gpp %d, '%s'", cdr->call_id, i, tmp2); + L_ERROR("Call-Id '%s' has no separated destination gpp %d, '%s'", cdr->call_id->str, i, tmp2); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->destination_gpp[i], tmp2, sizeof(cdr->destination_gpp[i])); + g_string_assign(cdr->destination_gpp[i], tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; } @@ -1183,17 +1196,17 @@ static int cdr_parse_dstleg_list(char *dstleg, cdr_entry_t *cdr) if(tmp1 == NULL) { if (strict_leg_tokens) { - L_ERROR("Call-Id '%s' has no separated destination lnp prefix, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated destination lnp prefix, '%s'", cdr->call_id->str, tmp2); return -1; } else { - cdr->destination_lnp_prefix[0] = '\0'; - cdr->destination_user_out[0] = '\0'; - L_WARNING("Call-Id '%s' dst leg has missing tokens (using empty lnp prefix, user out) '%s'", cdr->call_id, tmp2); + g_string_truncate(cdr->destination_lnp_prefix, 0); + g_string_truncate(cdr->destination_user_out, 0); + L_WARNING("Call-Id '%s' dst leg has missing tokens (using empty lnp prefix, user out) '%s'", cdr->call_id->str, tmp2); return 0; } } *tmp1 = '\0'; - g_strlcpy(cdr->destination_lnp_prefix, tmp2, sizeof(cdr->destination_lnp_prefix)); + g_string_assign(cdr->destination_lnp_prefix, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; @@ -1201,74 +1214,74 @@ static int cdr_parse_dstleg_list(char *dstleg, cdr_entry_t *cdr) if(tmp1 == NULL) { if (strict_leg_tokens) { - L_ERROR("Call-Id '%s' has no separated destination user out, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated destination user out, '%s'", cdr->call_id->str, tmp2); return -1; } else { - cdr->destination_user_out[0] = '\0'; - L_WARNING("Call-Id '%s' dst leg has missing tokens (using empty user out) '%s'", cdr->call_id, tmp2); + g_string_truncate(cdr->destination_user_out, 0); + L_WARNING("Call-Id '%s' dst leg has missing tokens (using empty user out) '%s'", cdr->call_id->str, tmp2); return 0; } } *tmp1 = '\0'; - g_strlcpy(cdr->destination_user_out, tmp2, sizeof(cdr->destination_user_out)); + g_string_assign(cdr->destination_user_out, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated destination lnp type, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated destination lnp type, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->destination_lnp_type, tmp2, sizeof(cdr->destination_lnp_type)); + g_string_assign(cdr->destination_lnp_type, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_ERROR("Call-Id '%s' has no separated furnished charging info, '%s'", cdr->call_id, tmp2); + L_ERROR("Call-Id '%s' has no separated furnished charging info, '%s'", cdr->call_id->str, tmp2); return -1; } *tmp1 = '\0'; - g_strlcpy(cdr->furnished_charging_info, tmp2, sizeof(cdr->furnished_charging_info)); + g_string_assign(cdr->furnished_charging_info, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_DEBUG("Call-Id '%s' has no separated destination concurrent calls quota, '%s'", cdr->call_id, tmp2); + L_DEBUG("Call-Id '%s' has no separated destination concurrent calls quota, '%s'", cdr->call_id->str, tmp2); /// Added in mr8.3, it should be changed to -1 in mr9.+ return 0; } *tmp1 = '\0'; - g_strlcpy(cdr->destination_concurrent_calls_quota, tmp2, sizeof(cdr->destination_concurrent_calls_quota)); + g_string_assign(cdr->destination_concurrent_calls_quota, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_DEBUG("Call-Id '%s' has no separated destination concurrent calls count, '%s'", cdr->call_id, tmp2); + L_DEBUG("Call-Id '%s' has no separated destination concurrent calls count, '%s'", cdr->call_id->str, tmp2); /// Added in mr8.3, it should be changed to -1 in mr9.+ return 0; } *tmp1 = '\0'; - g_strlcpy(cdr->destination_concurrent_calls_count, tmp2, sizeof(cdr->destination_concurrent_calls_count)); + g_string_assign(cdr->destination_concurrent_calls_count, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; tmp1 = strchr(tmp2, MED_SEP); if(tmp1 == NULL) { - L_DEBUG("Call-Id '%s' has no separated destination concurrent calls customer count, '%s'", cdr->call_id, tmp2); + L_DEBUG("Call-Id '%s' has no separated destination concurrent calls customer count, '%s'", cdr->call_id->str, tmp2); /// Added in mr8.3, it should be changed to -1 in mr9.+ return 0; } *tmp1 = '\0'; - g_strlcpy(cdr->destination_concurrent_calls_count_customer, tmp2, sizeof(cdr->destination_concurrent_calls_count_customer)); + g_string_assign(cdr->destination_concurrent_calls_count_customer, tmp2); *tmp1 = MED_SEP; tmp2 = ++tmp1; @@ -1358,6 +1371,18 @@ static cdr_entry_t *alloc_cdrs(uint64_t cdr_count) { if (!cdrs) return NULL; + for (uint64_t i = 0; i < cdr_count; i++) { + cdr_entry_t *cdr = &cdrs[i]; + +#define F(f, l) cdr->f = g_string_new(""); +#define FA(f, a, l) for (unsigned int j = 0; j < a; j++) cdr->f[j] = g_string_new(""); + +#include "cdr_field_names.inc" + +#undef F +#undef FA + } + return cdrs; } @@ -1463,12 +1488,11 @@ static int cdr_create_cdrs(med_entry_t *records, uint64_t count, } } - g_strlcpy(cdr->call_id, e->callid, sizeof(cdr->call_id)); - /* g_strlcpy(cdr->start_time, e->timestamp, sizeof(cdr->start_time)); */ + g_string_assign(cdr->call_id, e->callid); cdr->start_time = e->unix_timestamp; cdr->duration = (tmp_unix_endtime >= e->unix_timestamp) ? tmp_unix_endtime - e->unix_timestamp : 0; - g_strlcpy(cdr->call_status, call_status, sizeof(cdr->call_status)); - g_strlcpy(cdr->call_code, e->sip_code, sizeof(cdr->call_code)); + g_string_assign(cdr->call_status, call_status); + g_string_assign(cdr->call_code, e->sip_code); cdr->source_carrier_cost = 0; @@ -1496,7 +1520,7 @@ static int cdr_create_cdrs(med_entry_t *records, uint64_t count, } cdr->mos = mos_data; - g_strlcpy(cdr->acc_ref, e->acc_ref, sizeof(cdr->acc_ref)); + g_string_assign(cdr->acc_ref, e->acc_ref); L_DEBUG("Created CDR index %lu\n", cdr_index); } @@ -1530,63 +1554,63 @@ void cdr_set_provider(cdr_entry_t *cdr) { char *val; - if(strncmp("0", cdr->source_user_id, sizeof(cdr->source_user_id)) != 0) + if(strcmp("0", cdr->source_user_id->str) != 0) { if((val = g_hash_table_lookup(med_uuid_table, cdr->source_user_id)) != NULL) { - g_strlcpy(cdr->source_provider_id, val, sizeof(cdr->source_provider_id)); + g_string_assign(cdr->source_provider_id, val); } else { - g_strlcpy(cdr->source_provider_id, "0", sizeof(cdr->source_provider_id)); + g_string_assign(cdr->source_provider_id, "0"); } } else if (cdr->source_lcr_id) { - snprintf(cdr->source_provider_id, sizeof(cdr->source_provider_id), + g_string_printf(cdr->source_provider_id, "%llu", (unsigned long long) cdr->source_lcr_id); val = g_hash_table_lookup(med_peer_id_table, cdr->source_provider_id); - g_strlcpy(cdr->source_provider_id, val ? : "0", sizeof(cdr->source_provider_id)); + g_string_assign(cdr->source_provider_id, val ? : "0"); } else if((val = g_hash_table_lookup(med_peer_ip_table, cdr->source_domain)) != NULL) { - g_strlcpy(cdr->source_provider_id, val, sizeof(cdr->source_provider_id)); + g_string_assign(cdr->source_provider_id, val); } else if((val = g_hash_table_lookup(med_peer_host_table, cdr->source_domain)) != NULL) { - g_strlcpy(cdr->source_provider_id, val, sizeof(cdr->source_provider_id)); + g_string_assign(cdr->source_provider_id, val); } else { - g_strlcpy(cdr->source_provider_id, "0", sizeof(cdr->source_provider_id)); + g_string_assign(cdr->source_provider_id, "0"); } - if(strncmp("0", cdr->destination_user_id, sizeof(cdr->destination_user_id)) != 0) + if(strcmp("0", cdr->destination_user_id->str) != 0) { if((val = g_hash_table_lookup(med_uuid_table, cdr->destination_user_id)) != NULL) { - g_strlcpy(cdr->destination_provider_id, val, sizeof(cdr->destination_provider_id)); + g_string_assign(cdr->destination_provider_id, val); } else { - g_strlcpy(cdr->destination_provider_id, "0", sizeof(cdr->destination_provider_id)); + g_string_assign(cdr->destination_provider_id, "0"); } } else if (cdr->destination_lcr_id) { - snprintf(cdr->destination_provider_id, sizeof(cdr->destination_provider_id), + g_string_printf(cdr->destination_provider_id, "%llu", (unsigned long long) cdr->destination_lcr_id); val = g_hash_table_lookup(med_peer_id_table, cdr->destination_provider_id); - g_strlcpy(cdr->destination_provider_id, val ? : "0", sizeof(cdr->destination_provider_id)); + g_string_assign(cdr->destination_provider_id, val ? : "0"); } else if((val = g_hash_table_lookup(med_peer_ip_table, cdr->destination_domain)) != NULL) { - g_strlcpy(cdr->destination_provider_id, val, sizeof(cdr->destination_provider_id)); + g_string_assign(cdr->destination_provider_id, val); } else if((val = g_hash_table_lookup(med_peer_host_table, cdr->destination_domain)) != NULL) { - g_strlcpy(cdr->destination_provider_id, val, sizeof(cdr->destination_provider_id)); + g_string_assign(cdr->destination_provider_id, val); } else { - g_strlcpy(cdr->destination_provider_id, "0", sizeof(cdr->destination_provider_id)); + g_string_assign(cdr->destination_provider_id, "0"); } } diff --git a/cdr.h b/cdr.h index 30eebaf..2c954a9 100644 --- a/cdr.h +++ b/cdr.h @@ -25,8 +25,8 @@ typedef struct { int avg_rtt; } mos_data_t; -#define F(f, l) char f[l]; -#define FA(f, a, l) char f[a][l]; +#define F(f, l) GString *f; +#define FA(f, a, l) GString *f[a]; typedef struct { #include "cdr_field_names.inc" diff --git a/medmysql.c b/medmysql.c index befd027..4d142c7 100644 --- a/medmysql.c +++ b/medmysql.c @@ -523,10 +523,10 @@ void medmysql_cleanup() medmysql_handler_close(&stats_handler); } -static void medmysql_buf_escape(MYSQL *m, size_t *buflen, const char *str, char *orig_dest, +static void medmysql_buf_escape(MYSQL *m, size_t *buflen, const char *str, const size_t str_len, + char *orig_dest, size_t sql_buffer_size) { - size_t str_len = strlen(str); char *dest = orig_dest; // verify buffer space requirements: string itself * 2, quotes '', optional "_latin1", null @@ -549,9 +549,14 @@ static void medmysql_buf_escape(MYSQL *m, size_t *buflen, const char *str, char *buflen += dest - orig_dest; } +static inline void medmysql_buf_escape_c(MYSQL *m, size_t *buflen, const char *str, char *orig_dest, + size_t sql_buffer_size) +{ + medmysql_buf_escape(m, buflen, str, strlen(str), orig_dest, sql_buffer_size); +} #define BUFPRINT(x...) buflen += sprintf(sql_buffer + buflen, x); if (buflen >= sql_buffer_size) abort() -#define BUFESCAPE(x) medmysql_buf_escape(med_handler->m, &buflen, x, sql_buffer + buflen, sql_buffer_size) +#define BUFESCAPE(x) medmysql_buf_escape_c(med_handler->m, &buflen, x, sql_buffer + buflen, sql_buffer_size) /**********************************************************************/ int medmysql_insert_records(med_entry_t *records, uint64_t count, const char *table) @@ -846,15 +851,16 @@ int medmysql_delete_entries(const char *callid, struct medmysql_batches *batches } #define CDRPRINT(x) batch->cdrs.len += sprintf(batch->cdrs.str + batch->cdrs.len, x) -#define CDRESCAPE(x) medmysql_buf_escape(med_handler->m, &batch->cdrs.len, x, batch->cdrs.str + batch->cdrs.len, PACKET_SIZE) +#define CDRESCAPE(x) medmysql_buf_escape(med_handler->m, &batch->cdrs.len, x->str, x->len, batch->cdrs.str + batch->cdrs.len, PACKET_SIZE) +#define CDRESCAPE_C(x) medmysql_buf_escape_c(med_handler->m, &batch->cdrs.len, x, batch->cdrs.str + batch->cdrs.len, PACKET_SIZE) /**********************************************************************/ static int medmysql_tag_record(GQueue *q, unsigned long cdr_id, unsigned long provider_id, - unsigned long direction_id, const char *value, double start_time, unsigned long tag_id) + unsigned long direction_id, const GString *value, double start_time, unsigned long tag_id) { - char esc_value[strlen(value)*2+1]; + char esc_value[value->len*2+1]; - mysql_real_escape_string(med_handler->m, esc_value, value, strlen(value)); + mysql_real_escape_string(med_handler->m, esc_value, value->str, value->len); cdr_tag_record *record = malloc(sizeof(*record)); record->cdr_id = cdr_id; @@ -884,11 +890,11 @@ static int medmysql_mos_record(GQueue *q, unsigned long cdr_id, double avg_score return 0; } -static int medmysql_group_record(MYSQL *m, GQueue *q, unsigned long cdr_id, const char *group, double start_time) +static int medmysql_group_record(MYSQL *m, GQueue *q, unsigned long cdr_id, const GString *group, double start_time) { - char esc_group[strlen(group)*2+1]; + char esc_group[group->len*2+1]; - mysql_real_escape_string(m, esc_group, group, strlen(group)); + mysql_real_escape_string(m, esc_group, group->str, group->len); cdr_tag_record *record = malloc(sizeof(*record)); record->cdr_id = cdr_id; @@ -903,17 +909,17 @@ static int medmysql_group_record(MYSQL *m, GQueue *q, unsigned long cdr_id, cons static int medmysql_tag_cdr(struct medmysql_cdr_batch *batch, unsigned long provider_id, - unsigned long direction_id, const char *tag_name, const char *tag_value, + unsigned long direction_id, const char *tag_name, const GString *tag_value, const cdr_entry_t *e) { gpointer tag_id; - if (!strlen(tag_value)) + if (!tag_value->len) return 0; if ((tag_id = g_hash_table_lookup(med_cdr_tag_table, tag_name)) == NULL) { L_WARNING("Call-Id '%s' has no cdr tag type '%s', '%s'", - e->call_id, tag_name, tag_value); + e->call_id->str, tag_name, tag_value->str); return -1; } if (medmysql_tag_record(&batch->cdr_tags, batch->num_cdrs, provider_id, @@ -980,7 +986,7 @@ int medmysql_insert_cdrs(cdr_entry_t *entries, uint64_t count, struct medmysql_b CDRPRINT(","); CDRESCAPE(e->source_ext_contract_id); CDRPRINT(","); - CDRESCAPE(str_source_accid); + CDRESCAPE_C(str_source_accid); CDRPRINT(","); CDRESCAPE(e->source_user); @@ -989,7 +995,7 @@ int medmysql_insert_cdrs(cdr_entry_t *entries, uint64_t count, struct medmysql_b CDRPRINT(","); CDRESCAPE(e->source_cli); CDRPRINT(","); - CDRESCAPE(str_source_clir); + CDRESCAPE_C(str_source_clir); CDRPRINT(","); CDRESCAPE(e->source_ip); CDRPRINT(","); @@ -1001,7 +1007,7 @@ int medmysql_insert_cdrs(cdr_entry_t *entries, uint64_t count, struct medmysql_b CDRPRINT(","); CDRESCAPE(e->destination_ext_contract_id); CDRPRINT(","); - CDRESCAPE(str_dest_accid); + CDRESCAPE_C(str_dest_accid); CDRPRINT(","); CDRESCAPE(e->destination_user); CDRPRINT(","); @@ -1023,30 +1029,30 @@ int medmysql_insert_cdrs(cdr_entry_t *entries, uint64_t count, struct medmysql_b CDRPRINT(","); CDRESCAPE(e->call_code); CDRPRINT(","); - CDRESCAPE(str_init_time); + CDRESCAPE_C(str_init_time); CDRPRINT(","); - CDRESCAPE(str_start_time); + CDRESCAPE_C(str_start_time); CDRPRINT(","); - CDRESCAPE(str_duration); + CDRESCAPE_C(str_duration); CDRPRINT(","); CDRESCAPE(e->call_id); CDRPRINT(","); - CDRESCAPE(str_source_carrier_cost); + CDRESCAPE_C(str_source_carrier_cost); CDRPRINT(","); - CDRESCAPE(str_source_reseller_cost); + CDRESCAPE_C(str_source_reseller_cost); CDRPRINT(","); - CDRESCAPE(str_source_customer_cost); + CDRESCAPE_C(str_source_customer_cost); CDRPRINT(","); - CDRESCAPE(str_dest_carrier_cost); + CDRESCAPE_C(str_dest_carrier_cost); CDRPRINT(","); - CDRESCAPE(str_dest_reseller_cost); + CDRESCAPE_C(str_dest_reseller_cost); CDRPRINT(","); - CDRESCAPE(str_dest_customer_cost); + CDRESCAPE_C(str_dest_customer_cost); CDRPRINT(","); - CDRESCAPE(str_split); + CDRESCAPE_C(str_split); for(gpp = 0; gpp < 10; ++gpp) { - if(strnlen(e->source_gpp[gpp], sizeof(e->source_gpp[gpp])) > 0) + if(e->source_gpp[gpp]->len > 0) { CDRPRINT(","); CDRESCAPE(e->source_gpp[gpp]); @@ -1058,7 +1064,7 @@ int medmysql_insert_cdrs(cdr_entry_t *entries, uint64_t count, struct medmysql_b } for(gpp = 0; gpp < 10; ++gpp) { - if(strnlen(e->destination_gpp[gpp], sizeof(e->destination_gpp[gpp])) > 0) + if(e->destination_gpp[gpp]->len > 0) { CDRPRINT(","); CDRESCAPE(e->destination_gpp[gpp]); @@ -1078,7 +1084,7 @@ int medmysql_insert_cdrs(cdr_entry_t *entries, uint64_t count, struct medmysql_b CDRPRINT(","); CDRESCAPE(e->destination_user_out); - if(strnlen(e->source_lnp_type, sizeof(e->source_lnp_type)) > 0) + if(e->source_lnp_type->len > 0) { CDRPRINT(","); CDRESCAPE(e->source_lnp_type); @@ -1088,7 +1094,7 @@ int medmysql_insert_cdrs(cdr_entry_t *entries, uint64_t count, struct medmysql_b CDRPRINT(",NULL"); } - if(strnlen(e->destination_lnp_type, sizeof(e->destination_lnp_type)) > 0) + if(e->destination_lnp_type->len > 0) { CDRPRINT(","); CDRESCAPE(e->destination_lnp_type); @@ -1155,7 +1161,7 @@ int medmysql_insert_cdrs(cdr_entry_t *entries, uint64_t count, struct medmysql_b batch->num_cdrs++; // no check for return codes here we should keep on nevertheless - medmysql_update_call_stat_info(e->call_code, e->start_time); + medmysql_update_call_stat_info(e->call_code->str, e->start_time); if (check_shutdown()) return -1; @@ -1174,10 +1180,9 @@ int medmysql_delete_intermediate(cdr_entry_t *entries, uint64_t count, struct me for(i = 0; i < count; ++i) { cdr_entry_t *e = &(entries[i]); - char *callid = e->call_id; - char esc_callid[strlen(callid)*2+1]; + char esc_callid[e->call_id->len*2+1]; - mysql_real_escape_string(int_cdr_handler->m, esc_callid, callid, strlen(callid)); + mysql_real_escape_string(int_cdr_handler->m, esc_callid, e->call_id->str, e->call_id->len); if (medmysql_batch_prepare(&batches->int_cdr_delete)) return -1; @@ -1221,7 +1226,7 @@ int medmysql_update_call_stat_info(const char *call_code, const double start_tim return -1; } - sprintf(period_key, "%s-%s", period, call_code); + snprintf(period_key, sizeof(period_key), "%s-%s", period, call_code); if ((period_t = g_hash_table_lookup(med_call_stat_info_table, &period_key)) == NULL) { period_t = malloc(sizeof(struct medmysql_call_stat_info_t));