static int raw_on_metadata_tag(flv_tag * tag, amf_data * name, amf_data * data, flv_parser * parser) { printf("* Metadata event name: %s\n", amf_string_get_bytes(name)); printf("* Metadata contents: "); amf_data_dump(stdout, data, 0); printf("\n"); return OK; }
/* dump AMF data into a stream as text */ void amf_data_dump(FILE * stream, const amf_data * data, int indent_level) { if (data != NULL) { amf_node * node; time_t time; struct tm * t; char datestr[128]; switch (data->type) { case AMF_TYPE_NUMBER: fprintf(stream, "%.12g", data->number_data); break; case AMF_TYPE_BOOLEAN: fprintf(stream, "%s", (data->boolean_data) ? "true" : "false"); break; case AMF_TYPE_STRING: fprintf(stream, "\'%.*s\'", data->string_data.size, data->string_data.mbstr); break; case AMF_TYPE_OBJECT: node = amf_object_first(data); fprintf(stream, "{\n"); while (node != NULL) { fprintf(stream, "%*s", (indent_level+1)*4, ""); amf_data_dump(stream, amf_object_get_name(node), indent_level+1); fprintf(stream, ": "); amf_data_dump(stream, amf_object_get_data(node), indent_level+1); node = amf_object_next(node); fprintf(stream, "\n"); } fprintf(stream, "%*s", indent_level*4 + 1, "}"); break; case AMF_TYPE_NULL: fprintf(stream, "null"); break; case AMF_TYPE_UNDEFINED: fprintf(stream, "undefined"); break; /*case AMF_TYPE_REFERENCE:*/ case AMF_TYPE_ASSOCIATIVE_ARRAY: node = amf_associative_array_first(data); fprintf(stream, "{\n"); while (node != NULL) { fprintf(stream, "%*s", (indent_level+1)*4, ""); amf_data_dump(stream, amf_associative_array_get_name(node), indent_level+1); fprintf(stream, " => "); amf_data_dump(stream, amf_associative_array_get_data(node), indent_level+1); node = amf_associative_array_next(node); fprintf(stream, "\n"); } fprintf(stream, "%*s", indent_level*4 + 1, "}"); break; case AMF_TYPE_ARRAY: node = amf_array_first(data); fprintf(stream, "[\n"); while (node != NULL) { fprintf(stream, "%*s", (indent_level+1)*4, ""); amf_data_dump(stream, node->data, indent_level+1); node = amf_array_next(node); fprintf(stream, "\n"); } fprintf(stream, "%*s", indent_level*4 + 1, "]"); break; case AMF_TYPE_DATE: time = amf_date_to_time_t(data); tzset(); t = localtime(&time); strftime(datestr, sizeof(datestr), "%a, %d %b %Y %H:%M:%S %z", t); fprintf(stream, "%s", datestr); break; /*case AMF_TYPE_SIMPLEOBJECT:*/ case AMF_TYPE_XML: break; case AMF_TYPE_CLASS: break; default: break; } } }
int dump_raw_amf_data(const amf_data * data) { amf_data_dump(stdout, data, 0); printf("\n"); return OK; }