PHP_ME(swfed, replaceTagData, NULL, 0)
PHP_ME(swfed, getTagContentsByCID, NULL, 0)
PHP_ME(swfed, replaceTagContentsByCID, NULL, 0)
- PHP_MALIAS(swfed, getShapeData, getTagContentsByCID, NULL, 0)
- PHP_MALIAS(swfed, replaceShapeData, replaceTagContentsByCID, NULL, 0)
+ PHP_ME(swfed, getShapeData, NULL, 0)
+ PHP_ME(swfed, replaceShapeData, NULL, 0)
PHP_ME(swfed, setShapeAdjustMode, NULL, 0)
PHP_ME(swfed, getShapeIdListByBitmapRef, NULL, 0)
long tag_seqno = 0;
swf_object_t *swf = NULL;
unsigned char *data_ref = NULL;
- char *new_buff = NULL;
unsigned long data_len = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &tag_seqno) == FAILURE) {
fprintf(stderr, "getTagData: Can't get_tagdata\n");
RETURN_FALSE;
}
- new_buff = emalloc(data_len);
- if (new_buff == NULL) {
- fprintf(stderr, "getTagData: Can't emalloc new_buff\n");
- RETURN_FALSE;
- }
- memcpy(new_buff, data_ref, data_len);
- RETURN_STRINGL(new_buff, data_len, 0);
+ RETURN_STRINGL(data_ref, data_len, 1);
}
PHP_METHOD(swfed, replaceTagData) {
}
swf = get_swf_object(getThis() TSRMLS_CC);
result = swf_object_replace_tagdata(swf, tag_seqno,
- (unsigned char *)data,
- & data_len);
+ (unsigned char *)data, data_len);
if (result) {
RETURN_FALSE;
}
unsigned char *data_ref = NULL;
char *new_buff = NULL;
unsigned long data_len = 0;
-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &cid) == FAILURE) {
RETURN_FALSE;
}
swf = get_swf_object(getThis() TSRMLS_CC);
data_ref = swf_object_get_tagcontents_bycid(swf, cid, &data_len);
if (data_ref == NULL) {
- fprintf(stderr, "getTagContentsByCID: Can't get_tagdata\n");
- RETURN_FALSE;
- }
- new_buff = emalloc(data_len);
- if (new_buff == NULL) {
- fprintf(stderr, "getTagContentsByCID: Can't emalloc new_buff\n");
+ fprintf(stderr, "getTagContentsByCID: Can't get_tagcontents_bycid\n");
RETURN_FALSE;
}
- memcpy(new_buff, data_ref, data_len);
- RETURN_STRINGL(new_buff, data_len, 0);
+ RETURN_STRINGL(data_ref, data_len, 1);
}
PHP_METHOD(swfed, replaceTagContentsByCID) {
swf = get_swf_object(getThis() TSRMLS_CC);
result = swf_object_replace_tagcontents_bycid(swf, cid,
(unsigned char *)data,
- & data_len);
+ data_len);
+ if (result) {
+ RETURN_FALSE;
+ }
+ RETURN_TRUE;
+}
+
+
+PHP_METHOD(swfed, getShapeData) {
+ long cid = 0;
+ swf_object_t *swf = NULL;
+ unsigned char *data_ref = NULL;
+ char *new_buff = NULL;
+ unsigned long data_len = 0;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &cid) == FAILURE) {
+ RETURN_FALSE;
+ }
+ swf = get_swf_object(getThis() TSRMLS_CC);
+ data_ref = swf_object_get_shapedata(swf, cid, &data_len);
+ if (data_ref == NULL) {
+ fprintf(stderr, "getShapeData: Can't get_tagcontents_bycid\n");
+ RETURN_FALSE;
+ }
+ RETURN_STRINGL(data_ref, data_len, 1);
+}
+
+PHP_METHOD(swfed, replaceShapeData) {
+ char *data = NULL;
+ unsigned long data_len = 0;
+ long cid = 0;
+ swf_object_t *swf = NULL;
+ int result = 0;
+ switch (ZEND_NUM_ARGS()) {
+ default:
+ WRONG_PARAM_COUNT;
+ RETURN_FALSE; /* XXX */
+ case 2:
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &cid, &data, &data_len) == FAILURE) {
+ RETURN_FALSE;
+ }
+ break;
+ }
+ swf = get_swf_object(getThis() TSRMLS_CC);
+ result = swf_object_replace_shapedata(swf, cid,
+ (unsigned char *)data,
+ data_len);
if (result) {
RETURN_FALSE;
}
tag = tag->next;
}
if (tag) {
- if (tag->data) {
- *length = tag->length;
- return tag->data;
- }
if (tag->detail) {
bitstream_t *bs;
- unsigned char *data;
+ if (tag->data) {
+ free(tag->data);
+ tag->data = NULL;
+ }
bs = bitstream_open();
swf_tag_build(bs, tag, swf);
- data = bitstream_steal(bs, length);
+ tag->data = bitstream_steal(bs, &(tag->length));
bitstream_close(bs);
- return data;
+ }
+ if (tag->data) {
+ *length = tag->length;
+ return tag->data;
}
}
return NULL;
swf_tag_t *tag;
tag = swf->tag;
while (tag) {
- if (swf_tag_identity(tag, cid)) {
- break;
+ if (swf_tag_identity(tag, cid) == 0) {
+ break; // match
}
+ tag = tag->next;
}
if (tag) {
- if (tag->data) {
- *length = tag->length - 2;
- return tag->data + 2;
- }
if (tag->detail) {
bitstream_t *bs;
- unsigned char *data;
+ if (tag->data) {
+ free(tag->data);
+ tag->data = NULL;
+ }
bs = bitstream_open();
swf_tag_build(bs, tag, swf);
- data = bitstream_steal(bs, length);
+ tag->data = bitstream_steal(bs, &(tag->length));
bitstream_close(bs);
- *length -= 2;
- return data + 2;
+ }
+ if (tag->data) {
+ unsigned char *data;
+ *length = tag->length - 2;
+ return tag->data + 2;
}
}
+ *length = 0;
return NULL;
}
swf_tag_t *tag;
tag = swf->tag;
while (tag) {
- if (swf_tag_identity(tag, cid)) {
- break;
+ if (swf_tag_identity(tag, cid) == 0) {
+ break; // match
}
+ tag = tag->next;
}
if (tag) {
+ if (tag->detail) {
+ swf_tag_destroy(tag);
+ }
if (tag->data) {
free(tag->data);
+ tag->data = NULL;
}
- if (tag->detail) { // FIXME
+ tag->length = length + 2;
+ tag->data = malloc(length + 2);
+ tag->data[0] = cid & 0xff;
+ tag->data[1] = cid >> 8;
+ memcpy(tag->data + 2, data, length);
+ return 0; // success
+ }
+ return 1; // failure
+}
+
+
+unsigned char *
+swf_object_get_shapedata(swf_object_t *swf, int cid, unsigned long *length) {
+ swf_tag_t *tag;
+ tag = swf->tag;
+ while (tag) {
+ if (swf_tag_identity(tag, cid) == 0) {
+ break; // match
+ }
+ tag = tag->next;
+ }
+ if (tag) {
+ if (! isShapeTag(tag->tag)) {
+ fprintf(stderr, "");
+ return NULL;
+ }
+ if (tag->detail) {
+ bitstream_t *bs;
+ if (tag->data) {
+ free(tag->data);
+ tag->data = NULL;
+ }
+ bs = bitstream_open();
+ swf_tag_build(bs, tag, swf);
+ tag->data = bitstream_steal(bs, &(tag->length));
+ bitstream_close(bs);
+ }
+ if (tag->data) {
+ unsigned char *data;
+ *length = tag->length - 2;
+ return tag->data + 2;
+ }
+ }
+ *length = 0;
+ return NULL;
+}
+
+int
+swf_object_replace_shapedata(swf_object_t *swf, int cid,
+ unsigned char *data,
+ unsigned long length) {
+ swf_tag_t *tag;
+ tag = swf->tag;
+ while (tag) {
+ if (swf_tag_identity(tag, cid) == 0) {
+ break; // match
+ }
+ tag = tag->next;
+ }
+ if (tag) {
+ if (! isShapeTag(tag->tag)) {
+ return 1; // failure
+ }
+ if (tag->detail) {
swf_tag_destroy(tag);
}
+ if (tag->data) {
+ free(tag->data);
+ tag->data = NULL;
+ }
tag->length = length + 2;
tag->data = malloc(length + 2);
tag->data[0] = cid & 0xff;
tag->data[1] = cid >> 8;
- memcpy(tag->data, data + 2, length);
- return 0;
+ memcpy(tag->data + 2, data, length);
+ return 0; // success
}
- return 1;
+ return 1; // failure
}
/* --- */