static void event_handler(switch_event_t *event) { char *buf; switch_xml_t xml; char *xmlstr = "N/A"; uint8_t dofree = 0; switch (event->event_id) { case SWITCH_EVENT_LOG: return; default: switch_event_serialize(event, &buf, SWITCH_TRUE); if ((xml = switch_event_xmlize(event, SWITCH_VA_NONE))) { xmlstr = switch_xml_toxml(xml, SWITCH_FALSE); dofree++; } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\nEVENT (text version)\n--------------------------------\n%s", buf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\nEVENT (xml version)\n--------------------------------\n%s\n", xmlstr); break; } switch_safe_free(buf); if (dofree) { if (xml) { switch_xml_free(xml); } if (xmlstr) { free(xmlstr); } } }
SWITCH_DECLARE(const char *)Event::serialize(const char *format) { this_check(""); switch_safe_free(serialized_string); if (!event) { return ""; } if (format && !strcasecmp(format, "xml")) { switch_xml_t xml; if ((xml = switch_event_xmlize(event, SWITCH_VA_NONE))) { serialized_string = switch_xml_toxml(xml, SWITCH_FALSE); switch_xml_free(xml); return serialized_string; } else { return ""; } } else if (format && !strcasecmp(format, "json")) { switch_event_serialize_json(event, &serialized_string); return serialized_string; } else { if (switch_event_serialize(event, &serialized_string, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) { char *new_serialized_string = switch_mprintf("'%s'", serialized_string); free(serialized_string); serialized_string = new_serialized_string; return serialized_string; } } return ""; }