svnno****@sourc*****
svnno****@sourc*****
2011年 2月 3日 (木) 23:06:39 JST
Revision: 360 http://sourceforge.jp/projects/swfed/svn/view?view=rev&revision=360 Author: yoya Date: 2011-02-03 23:06:39 +0900 (Thu, 03 Feb 2011) Log Message: ----------- - (get|replace)ShapeData の実装 - (get|replace)TagContentsByCID の修正 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 16:12:34 UTC (rev 359) +++ trunk/src/php_swfed.c 2011-02-03 14:06:39 UTC (rev 360) @@ -63,8 +63,8 @@ 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) @@ -503,7 +503,6 @@ 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) { @@ -515,13 +514,7 @@ 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) { @@ -542,8 +535,7 @@ } 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; } @@ -556,23 +548,16 @@ 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"); + fprintf(stderr, "getTagContentsByCID: Can't get_tagcontents_bycid\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); + RETURN_STRINGL(data_ref, data_len, 1); } PHP_METHOD(swfed, replaceTagContentsByCID) { @@ -594,13 +579,58 @@ 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; + } + 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 16:12:34 UTC (rev 359) +++ trunk/src/php_swfed.h 2011-02-03 14:06:39 UTC (rev 360) @@ -58,6 +58,8 @@ PHP_METHOD(swfed, getTagContentsByCID); PHP_METHOD(swfed, replaceTagContentsByCID); // +PHP_METHOD(swfed, getShapeData); +PHP_METHOD(swfed, replaceShapeData); PHP_METHOD(swfed, setShapeAdjustMode); PHP_METHOD(swfed, getShapeIdListByBitmapRef); PHP_METHOD(swfed, getBitmapSize); Modified: trunk/src/swf_object.c =================================================================== --- trunk/src/swf_object.c 2011-02-02 16:12:34 UTC (rev 359) +++ trunk/src/swf_object.c 2011-02-03 14:06:39 UTC (rev 360) @@ -210,19 +210,21 @@ 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; } @@ -257,26 +259,30 @@ 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; } @@ -287,25 +293,97 @@ 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 } /* --- */ Modified: trunk/src/swf_object.h =================================================================== --- trunk/src/swf_object.h 2011-02-02 16:12:34 UTC (rev 359) +++ trunk/src/swf_object.h 2011-02-03 14:06:39 UTC (rev 360) @@ -51,6 +51,12 @@ /* --- */ +extern unsigned char *swf_object_get_shapedata(swf_object_t *swf, + int shape_id, + unsigned long *length); +extern int swf_object_replace_shapedata(swf_object_t *swf, int shape_id, + unsigned char *data, + unsigned long length); extern int swf_object_set_shape_adjust_mode(swf_object_t *swf, unsigned mode); extern int swf_object_adjust_shapebitmap(swf_object_t *swf, int bitmap_id, int old_width, int old_height,