svnno****@sourc*****
svnno****@sourc*****
2011年 2月 3日 (木) 01:12:34 JST
Revision: 359 http://sourceforge.jp/projects/swfed/svn/view?view=rev&revision=359 Author: yoya Date: 2011-02-03 01:12:34 +0900 (Thu, 03 Feb 2011) Log Message: ----------- - getShapeData, replaceShapeData の実装 (まだ全然動かない) - 各々 alias で、本体は getTagContentsByCID, replaceTagContentsByCID - getTagData, replaceTagData のコード修正 (動作確認してない) Modified Paths: -------------- trunk/src/php_swfed.c trunk/src/php_swfed.h trunk/src/swf_object.c trunk/src/swf_object.h -------------- next part -------------- Modified: trunk/src/php_swfed.c =================================================================== --- trunk/src/php_swfed.c 2011-02-02 15:42:36 UTC (rev 358) +++ trunk/src/php_swfed.c 2011-02-02 16:12:34 UTC (rev 359) @@ -61,6 +61,11 @@ PHP_ME(swfed, getTagDetail, NULL, 0) PHP_ME(swfed, getTagData, NULL, 0) 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, setShapeAdjustMode, NULL, 0) PHP_ME(swfed, getShapeIdListByBitmapRef, NULL, 0) PHP_ME(swfed, getBitmapSize, NULL, 0) @@ -522,7 +527,7 @@ PHP_METHOD(swfed, replaceTagData) { char *data = NULL; unsigned long data_len = 0; - int tag_seqno = 0; + long tag_seqno = 0; swf_object_t *swf = NULL; int result = 0; switch (ZEND_NUM_ARGS()) { @@ -545,6 +550,57 @@ RETURN_TRUE; } +PHP_METHOD(swfed, getTagContentsByCID) { + 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_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"); + RETURN_FALSE; + } + memcpy(new_buff, data_ref, data_len); + RETURN_STRINGL(new_buff, data_len, 0); +} + +PHP_METHOD(swfed, replaceTagContentsByCID) { + 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_tagcontents_bycid(swf, cid, + (unsigned char *)data, + & data_len); + if (result) { + RETURN_FALSE; + } + RETURN_TRUE; +} + PHP_METHOD(swfed, setShapeAdjustMode) { swf_object_t *swf = NULL; unsigned long mode = 0; Modified: trunk/src/php_swfed.h =================================================================== --- trunk/src/php_swfed.h 2011-02-02 15:42:36 UTC (rev 358) +++ trunk/src/php_swfed.h 2011-02-02 16:12:34 UTC (rev 359) @@ -55,6 +55,8 @@ PHP_METHOD(swfed, getTagInfo); PHP_METHOD(swfed, getTagData); PHP_METHOD(swfed, replaceTagData); +PHP_METHOD(swfed, getTagContentsByCID); +PHP_METHOD(swfed, replaceTagContentsByCID); // PHP_METHOD(swfed, setShapeAdjustMode); PHP_METHOD(swfed, getShapeIdListByBitmapRef); Modified: trunk/src/swf_object.c =================================================================== --- trunk/src/swf_object.c 2011-02-02 15:42:36 UTC (rev 358) +++ trunk/src/swf_object.c 2011-02-02 16:12:34 UTC (rev 359) @@ -214,7 +214,7 @@ *length = tag->length; return tag->data; } - if (tag->detail == NULL) { + if (tag->detail) { bitstream_t *bs; unsigned char *data; bs = bitstream_open(); @@ -223,18 +223,88 @@ bitstream_close(bs); return data; } + } + return NULL; +} + +int +swf_object_replace_tagdata(swf_object_t *swf, int tag_seqno, + unsigned char *data, unsigned long length) { + int i; + swf_tag_t *tag; + tag = swf->tag; + for (i=0 ; (i < tag_seqno) && tag ; i++) { + tag = tag->next; + } + if (tag) { + if (tag->data) { + free(tag->data); + } + if (tag->detail) { // FIXME + swf_tag_destroy(tag); + } + tag->length = length; + tag->data = malloc(length); + memcpy(tag->data, data, length); + return 0; + } + return 1; +} + +unsigned char * +swf_object_get_tagcontents_bycid(swf_object_t *swf, int cid, + unsigned long *length) { + swf_tag_t *tag; + tag = swf->tag; + while (tag) { + if (swf_tag_identity(tag, cid)) { + break; + } + } + if (tag) { + if (tag->data) { + *length = tag->length - 2; + return tag->data + 2; + } if (tag->detail) { - *length = tag->length; - return tag->data; + bitstream_t *bs; + unsigned char *data; + bs = bitstream_open(); + swf_tag_build(bs, tag, swf); + data = bitstream_steal(bs, length); + bitstream_close(bs); + *length -= 2; + return data + 2; } } return NULL; } int -swf_object_replace_tagdata(swf_object_t *swf, int tag_seqno, - unsigned char *data, unsigned long *length) { - fprintf(stderr, "swf_object_replace_tagdata: not impremented yet.\n"); +swf_object_replace_tagcontents_bycid(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)) { + break; + } + } + if (tag) { + if (tag->data) { + free(tag->data); + } + if (tag->detail) { // FIXME + swf_tag_destroy(tag); + } + 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; + } return 1; } Modified: trunk/src/swf_object.h =================================================================== --- trunk/src/swf_object.h 2011-02-02 15:42:36 UTC (rev 358) +++ trunk/src/swf_object.h 2011-02-02 16:12:34 UTC (rev 359) @@ -36,7 +36,13 @@ unsigned long *length); extern int swf_object_replace_tagdata(swf_object_t *swf, int tag_seqno, unsigned char *data, - unsigned long *length); + unsigned long length); +extern unsigned char *swf_object_get_tagcontents_bycid(swf_object_t *swf, + int cid, + unsigned long *length); +extern int swf_object_replace_tagcontents_bycid(swf_object_t *swf, int cid, + unsigned char *data, + unsigned long length); /* --- */