Exemplo n.º 1
0
static int json_on_header(flv_header * header, flv_parser * parser) {
    json_emitter * je;
    je = (json_emitter*)parser->user_data;

    json_emit_object_start(je);
    json_emit_object_key_z(je, "magic");
    json_emit_string(je, (char*)header->signature, 3);
    json_emit_object_key_z(je, "hasVideo");
    json_emit_boolean(je, flv_header_has_video(*header));
    json_emit_object_key_z(je, "hasAudio");
    json_emit_boolean(je, flv_header_has_audio(*header));
    json_emit_object_key_z(je, "version");
    json_emit_integer(je, header->version);
    json_emit_object_key_z(je, "tags");
    json_emit_array_start(je);

    return OK;
}
Exemplo n.º 2
0
/* JSON metadata dumping */
static void json_amf_data_dump(const amf_data * data, json_emitter * je) {
    if (data != NULL) {
        amf_node * node;
        char str[128];

        switch (data->type) {
            case AMF_TYPE_NUMBER:
                json_emit_number(je, data->number_data);
                break;
            case AMF_TYPE_BOOLEAN:
                json_emit_boolean(je, data->boolean_data);
                break;
            case AMF_TYPE_STRING:
                json_emit_string(je, (char *)amf_string_get_bytes(data), amf_string_get_size(data));
                break;
            case AMF_TYPE_OBJECT:
                json_emit_object_start(je);
                node = amf_object_first(data);
                while (node != NULL) {
                    json_emit_object_key(je,
                        (char *)amf_string_get_bytes(amf_object_get_name(node)),
                        amf_string_get_size(amf_object_get_name(node))
                    );
                    json_amf_data_dump(amf_object_get_data(node), je);
                    node = amf_object_next(node);
                }
                json_emit_object_end(je);
                break;
            case AMF_TYPE_NULL:
            case AMF_TYPE_UNDEFINED:
                json_emit_null(je);
                break;
            case AMF_TYPE_ASSOCIATIVE_ARRAY:
                json_emit_object_start(je);
                node = amf_associative_array_first(data);
                while (node != NULL) {
                    json_emit_object_key(je,
                        (char *)amf_string_get_bytes(amf_associative_array_get_name(node)),
                        amf_string_get_size(amf_associative_array_get_name(node))
                    );
                    json_amf_data_dump(amf_object_get_data(node), je);
                    node = amf_associative_array_next(node);
                }
                json_emit_object_end(je);
                break;
            case AMF_TYPE_ARRAY:
                json_emit_array_start(je);
                node = amf_array_first(data);
                while (node != NULL) {
                    json_amf_data_dump(amf_array_get(node), je);
                    node = amf_array_next(node);
                }
                json_emit_array_end(je);
                break;
            case AMF_TYPE_DATE:
                amf_date_to_iso8601(data, str, sizeof(str));
                json_emit_string(je, str, strlen(str));
                break;
            case AMF_TYPE_XML: break;
            case AMF_TYPE_CLASS: break;
            default: break;
        }
    }
}
Exemplo n.º 3
0
int
getprop_main(const struct cmd_getprop_info* info)
{
    const char* format = info->getprop.format;
    const char* format_not_found = info->getprop.format_not_found;
    bool null = info->getprop.null;
    if (null && format == NULL && format_not_found == NULL)
        usage_error("must supply --format or "
                    "--format-not-found or both if using -0");

    find_symbol_in_libc("__system_property_foreach",
                        &property_foreach);
    if (property_foreach == NULL)
        property_foreach = compat_property_foreach;

    dbg("using %s for property enumeration",
        property_foreach == compat_property_foreach
        ? "compat_property_foreach"
        : "__system_property_foreach");

    int exit_status = 0;

    struct json_writer* writer = NULL;
    if (format == NULL && format_not_found == NULL) {
        writer = json_writer_create(xstdout);
        json_begin_object(writer);
    }

    const char** properties = ARGV_CONCAT(info->properties);
    bool first = true;
    char sep = null ? '\0' : '\n';
    if (*properties == NULL) {
        struct property_vector* pv = find_all_properties();
        char prev_name[PROP_NAME_MAX];
        for (size_t i = 0; i < pv->size; ++i) {
            char name[PROP_NAME_MAX];
            char value[PROP_VALUE_MAX];
            (void) __system_property_read(pv->props[i], name, value);
            if (i > 0 && strcmp(name, prev_name) == 0)
                continue;
            if (writer != NULL) {
                json_begin_field(writer, name);
                json_emit_string(writer, value);
            } else {
                output_property(&first, sep, format, name, value);
            }
            strcpy(prev_name, name);
        }
    } else {
        size_t nproperties = argv_count(properties);
        qsort(properties,
              nproperties,
              sizeof (properties[0]),
              property_argv_compare);
        const char* property;
        const char* prev_property = NULL;
        while ((property = *properties++)) {
            if (prev_property != NULL && !strcmp(prev_property, property))
                continue;
            if (writer != NULL)
                json_begin_field(writer, property);
            const prop_info* pi = __system_property_find(property);
            if (pi) {
                char value[PROP_VALUE_MAX];
                __system_property_read(pi, NULL, value);
                if (writer != NULL)
                    json_emit_string(writer, value);
                else if (format != NULL)
                    output_property(&first, sep, format, property, value);
            } else {
                if (writer != NULL)
                    json_emit_null(writer);
                else if (format_not_found != NULL)
                    output_property(&first, sep,
                                    format_not_found,
                                    property, NULL);
                exit_status = 4;
            }
            prev_property = property;
        }
    }

    if (writer == NULL && !first && !null)
        xputc(sep, xstdout);

    if (writer != NULL)
        json_end_object(writer);

    xflush(xstdout);
    return exit_status;
}