switch_memory_pool_t *pool = NULL;
char *name = (char *) switch_xml_attr_soft(cfg, "name");
+
if (zstr(name)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "missing name in profile\n");
+
return SWITCH_STATUS_GENERR;
}
if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error allocation pool for new profile : %s\n", name);
+
return SWITCH_STATUS_GENERR;
}
fetch_section = switch_xml_parse_section_string(name);
if ((params = switch_xml_child(cfg, "params")) != NULL) {
+
for (param = switch_xml_child(params, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
}
if (fetch_section == SWITCH_XML_SECTION_RESULT) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Fetch Profile[%s] invalid fetch-section: %s\n", name, switch_xml_toxml(cfg, SWITCH_FALSE));
+ char *tmp = switch_xml_toxml(cfg, SWITCH_FALSE);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Fetch Profile[%s] invalid fetch-section: %s\n", name, tmp);
+ free(tmp);
goto err;
}
}
}
- if(ptr)
+ if (ptr) {
*ptr = profile;
+ }
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "fetch handler profile %s successfully configured\n", name);
+
return SWITCH_STATUS_SUCCESS;
err:
/* Cleanup */
- if(pool) {
- switch_core_destroy_memory_pool(&pool);
- }
+ if(pool) {
+ switch_core_destroy_memory_pool(&pool);
+ }
+
return SWITCH_STATUS_GENERR;
}
} else if((header = switch_event_get_header_ptr(src, field->name)) != NULL) {
if (header->idx) {
item = cJSON_CreateArray();
+
for(i = 0; i < header->idx; i++) {
cJSON_AddItemToArray(item, kazoo_event_json_value(field->out_type, header->array[i]));
}
+
kazoo_cJSON_AddItemToObject(dst, field->as ? field->as : field->name, item);
} else if (field->out_type_as_array) {
item = cJSON_CreateArray();
expanded = kz_event_expand_headers(src, field->value);
if(expanded != NULL && !zstr(expanded)) {
item = kazoo_event_add_json_value(dst, field, field->as ? field->as : field->name, expanded);
- if(expanded != field->value) {
- free(expanded);
- }
}
+
+ if (expanded != field->value) {
+ switch_safe_free(expanded);
+ }
+
break;
case FIELD_FIRST_OF:
+
for(n = 0; n < field->list.size; n++) {
if(*field->list.value[n] == '#') {
item = kazoo_event_add_json_value(dst, field, field->as ? field->as : field->name, ++field->list.value[n]);
if(header) {
if (header->idx) {
item = cJSON_CreateArray();
+
for(i = 0; i < header->idx; i++) {
cJSON_AddItemToArray(item, kazoo_event_json_value(field->out_type, header->array[i]));
}
+
kazoo_cJSON_AddItemToObject(dst, field->as ? field->as : field->name, item);
} else {
item = kazoo_event_add_json_value(dst, field, field->as ? field->as : field->name, header->value);
}
+
break;
}
}
}
+
break;
case FIELD_PREFIX:
+
for (header = src->headers; header; header = header->next) {
if(!strncmp(header->name, field->name, strlen(field->name))) {
if (header->idx) {
cJSON *array = cJSON_CreateArray();
+
for(i = 0; i < header->idx; i++) {
cJSON_AddItemToArray(array, kazoo_event_json_value(field->out_type, header->array[i]));
}
+
kazoo_cJSON_AddItemToObject(dst, field->exclude_prefix ? header->name+strlen(field->name) : header->name, array);
} else {
kazoo_event_add_json_value(dst, field, field->exclude_prefix ? header->name+strlen(field->name) : header->name, header->value);
}
}
}
+
break;
case FIELD_STATIC:
break;
}
- return item;
+ return item;
}
static switch_status_t kazoo_event_add_fields_to_json(kazoo_logging_ptr logging, cJSON *dst, switch_event_t *src, kazoo_field_ptr field) {
if (ei_decode_atom_safe(buf->buff, &buf->index, section_str)
|| !(section = switch_xml_parse_section_string(section_str))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Ignoring a fetch reply without a configuration section\n");
+
return erlang_response_badarg(rbuf);
}
if (ei_decode_string_or_binary_limited(buf->buff, &buf->index, sizeof(uuid_str), uuid_str)
|| zstr_buf(uuid_str)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Ignoring a fetch reply without request UUID\n");
+
return erlang_response_badarg(rbuf);
}
if (ei_decode_string_or_binary(buf->buff, &buf->index, &xml_str)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Ignoring a fetch reply without XML : %s \n", uuid_str);
+
return erlang_response_badarg(rbuf);
}
if (zstr(xml_str)) {
switch_safe_free(xml_str);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Ignoring an empty fetch reply : %s\n", uuid_str);
+
return erlang_response_badarg(rbuf);
}
break;
default:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received fetch reply %s for an unknown configuration section: %s : %s\n", uuid_str, section_str, xml_str);
+ switch_safe_free(xml_str);
+
return erlang_response_badarg(rbuf);
}
if (result == SWITCH_STATUS_SUCCESS) {
+ switch_safe_free(xml_str);
+
return erlang_response_ok(rbuf);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received fetch reply %s is unknown or has expired : %s\n", uuid_str, xml_str);
+ switch_safe_free(xml_str);
+
return erlang_response_baduuid(rbuf);
}
}