Example #1
0
/* array functions */
amf0_data * amf0_array_new(void) {
    amf0_data * data = amf0_data_new(AMF0_TYPE_STRICT_ARRAY);
    if (data != NULL) {
        amf0_list_init(&data->list_data);
    }
    return data;
}
Example #2
0
/* associative array functions */
amf0_data * amf0_associative_array_new(void) {
    amf0_data * data = amf0_data_new(AMF0_TYPE_ECMA_ARRAY);
    if (data != NULL) {
        amf0_list_init(&data->list_data);
    }
    return data;
}
Example #3
0
/* clone AMF data */
amf0_data * amf0_data_clone(amf0_data * data) {
    /* we copy data recursively */
    if (data != NULL) {
        switch (data->type) {
            case AMF0_TYPE_NUMBER: return amf0_number_new(amf0_number_get_value(data));
            case AMF0_TYPE_BOOLEAN: return amf0_boolean_new(amf0_boolean_get_value(data));
            case AMF0_TYPE_STRING:
                if (data->string_data.mbstr != NULL) {
                    return amf0_string_new((uint8_t *)strdup((char *)amf0_string_get_uint8_ts(data)), amf0_string_get_size(data));
                }
                else {
                    return amf0_str(NULL);
                }
            case AMF0_TYPE_NULL: return NULL;
            case AMF0_TYPE_UNDEFINED: return NULL;
            /*case AMF0_TYPE_REFERENCE:*/
            case AMF0_TYPE_OBJECT:
            case AMF0_TYPE_ECMA_ARRAY:
            case AMF0_TYPE_STRICT_ARRAY:
                {
                    amf0_data * d = amf0_data_new(data->type);
                    if (d != NULL) {
                        amf0_list_init(&d->list_data);
                        amf0_list_clone(&data->list_data, &d->list_data);
                    }
                    return d;
                }
            case AMF0_TYPE_DATE: return amf0_date_new(amf0_date_get_milliseconds(data), amf0_date_get_timezone(data));
            /*case AMF0_TYPE_SIMPLEOBJECT:*/
            case AMF0_TYPE_XML_DOCUMENT: return NULL;
            case AMF0_TYPE_TYPED_OBJECT: return NULL;
        }
    }
    return NULL;
}
Example #4
0
/* object functions */
amf0_data * amf0_object_new(void) {
    amf0_data * data = amf0_data_new(AMF0_TYPE_OBJECT);
    if (data != NULL) {
        amf0_list_init(&data->list_data);
    }
    return data;
}
Example #5
0
/* clone AMF data */
amf0_data * amf0_data_clone(const amf0_data *data) {
    /* we copy data recursively */
    if (data != NULL) {
        switch (data->type) {
            case AMF0_TYPE_NUMBER: return amf0_number_new(amf0_number_get_value(data));
            case AMF0_TYPE_BOOLEAN: return amf0_boolean_new(amf0_boolean_get_value(data));
            case AMF0_TYPE_STRING:
                if (data->string_data.mbstr != NULL) {
                    return amf0_string_new((uint8_t *)strdup((char *)amf0_string_get_bytes(data)), amf0_string_get_size(data));
                }
                else {
                    return amf0_str(NULL);
                }
            case AMF0_TYPE_MOVIECLIP: /* not supported */
            case AMF0_TYPE_NULL:
            case AMF0_TYPE_UNDEFINED:
            case AMF0_TYPE_REFERENCE: /* TODO */
            case AMF0_TYPE_OBJECT_END:
                return NULL;

            case AMF0_TYPE_OBJECT:
            case AMF0_TYPE_ECMA_ARRAY:
            case AMF0_TYPE_STRICT_ARRAY:
                {
                    amf0_data * d = amf0_data_new(data->type);
                    if (d != NULL) {
                        amf0_list_init(&d->list_data);
                        amf0_list_clone(&data->list_data, &d->list_data);
                    }
                    return d;
                }

            case AMF0_TYPE_DATE: return amf0_date_new(amf0_date_get_milliseconds(data), amf0_date_get_timezone(data));
            case AMF0_TYPE_LONG_STRING: /* TODO */
            case AMF0_TYPE_UNSUPPORTED: /* TODO */
            case AMF0_TYPE_RECORDSET: /* not supported */
            case AMF0_TYPE_XML_DOCUMENT: /* TODO */
            case AMF0_TYPE_TYPED_OBJECT: /* TODO */
            default:
                return NULL;
        }
    }
    return NULL;
}