Exemple #1
0
/* read an associative array */
static amf0_data * amf0_associative_array_read(read_proc_t read_proc, void * user_data) {
    amf0_data * name;
    amf0_data * element;
    uint32_t size;
    uint8_t error_code;
    amf0_data * data;

    data = amf0_associative_array_new();
    if (data == NULL) {
        return NULL;
    }

    /* we ignore the 32 bits array size marker */
    if (read_proc(&size, sizeof(uint32_t), user_data) < sizeof(uint32_t)) {
        amf0_data_free(data);
        return amf0_data_error(AMF0_ERROR_EOF);
    }

    while(1) {
        name = amf0_string_read(read_proc, user_data);
        error_code = amf0_data_get_error(name);
        if (error_code != AMF0_ERROR_OK) {
            /* invalid name: error */
            amf0_data_free(name);
            amf0_data_free(data);
            return amf0_data_error(error_code);
        }

        element = amf0_data_read(read_proc, user_data);
        error_code = amf0_data_get_error(element);

        if (amf0_string_get_size(name) == 0 || error_code == AMF0_ERROR_END_TAG || error_code == AMF0_ERROR_UNKNOWN_TYPE) {
            /* end tag or unknown element: end of data, exit loop */
            amf0_data_free(name);
            amf0_data_free(element);
            break;
        }
        else if (error_code != AMF0_ERROR_OK) {
            amf0_data_free(name);
            amf0_data_free(data);
            amf0_data_free(element);
            return amf0_data_error(error_code);
        }

        if (amf0_associative_array_add(data, (char *)amf0_string_get_bytes(name), element) == NULL) {
            amf0_data_free(name);
            amf0_data_free(element);
            amf0_data_free(data);
            return NULL;
        }
        else {
            amf0_data_free(name);
        }
    }

    return data;
}
Exemple #2
0
/* read an associative array */
static amf0_data * amf0_associative_array_read(read_proc_t read_proc, void * user_data) {
    amf0_data * data = amf0_associative_array_new();
    if (data != NULL) {
        amf0_data * name;
        amf0_data * element;
        uint32_t size;
        if (read_proc(&size, sizeof(uint32_t), user_data) == sizeof(uint32_t)) {
            /* we ignore the 32 bits array size marker */
            while(1) {
                name = amf0_string_read(read_proc, user_data);
                if (name != NULL) {
                    element = amf0_data_read(read_proc, user_data);
                    if (element != NULL) {
                        if (amf0_associative_array_add(data, (char *)amf0_string_get_uint8_ts(name), element) == NULL) {
                            amf0_data_free(name);
                            amf0_data_free(element);
                            amf0_data_free(data);
                            return NULL;
                        }
                    }
                    else {
                        amf0_data_free(name);
                        break;
                    }
                }
                else {
                    /* invalid name: error */
                    amf0_data_free(data);
                    return NULL;
                }
            }
        }
        else {
            amf0_data_free(data);
            return NULL;
        }
    }
    return data;
}