[1.5][JPIP] backport r1037 to branch 1.5

This commit is contained in:
Antonin Descampe 2011-11-06 22:03:12 +00:00
parent 238b767917
commit 09f2926cd5
13 changed files with 127 additions and 88 deletions

View File

@ -5,6 +5,10 @@ What's New for OpenJPIP
! : changed ! : changed
+ : added + : added
November 3, 2011
* [kaori] solved memory leak of opj_server
! [kaori] removed redundant defines
November 2, 2011 November 2, 2011
* [antonin] additional patches for autotools and cmake * [antonin] additional patches for autotools and cmake

View File

@ -59,6 +59,7 @@ boxheader_param_t * gene_boxheader( int fd, Byte8_t offset)
boxlen = fetch_8bytebigendian( fd, offset+8); boxlen = fetch_8bytebigendian( fd, offset+8);
headlen = 16; headlen = 16;
} }
boxheader = (boxheader_param_t *)malloc( sizeof( boxheader_param_t)); boxheader = (boxheader_param_t *)malloc( sizeof( boxheader_param_t));
boxheader->headlen = headlen; boxheader->headlen = headlen;
boxheader->length = boxlen; boxheader->length = boxlen;

View File

@ -33,9 +33,6 @@
#include <string.h> #include <string.h>
#include "cache_manager.h" #include "cache_manager.h"
//! maximum length of channel identifier
#define MAX_LENOFCID 30
cachelist_param_t * gene_cachelist() cachelist_param_t * gene_cachelist()
{ {
cachelist_param_t *cachelist; cachelist_param_t *cachelist;
@ -66,12 +63,11 @@ cache_param_t * gene_cache( char *targetname, int csn, char *tid, char *cid)
cache_param_t *cache; cache_param_t *cache;
cache = (cache_param_t *)malloc( sizeof(cache_param_t)); cache = (cache_param_t *)malloc( sizeof(cache_param_t));
strcpy( cache->filename, targetname); cache->filename = strdup( targetname);
strcpy( cache->tid, tid); cache->tid = strdup( tid);
cache->csn = csn; cache->csn = csn;
cache->cid = (char **)malloc( sizeof(char *)); cache->cid = (char **)malloc( sizeof(char *));
*cache->cid = (char *)malloc( MAX_LENOFCID); *cache->cid = strdup( cid);
strcpy( *cache->cid, cid);
cache->numOfcid = 1; cache->numOfcid = 1;
#if 1 #if 1
cache->metadatalist = NULL; cache->metadatalist = NULL;
@ -88,6 +84,9 @@ void delete_cache( cache_param_t **cache)
{ {
int i; int i;
free( (*cache)->filename);
free( (*cache)->tid);
delete_metadatalist( &(*cache)->metadatalist); delete_metadatalist( &(*cache)->metadatalist);
if((*cache)->ihdrbox) if((*cache)->ihdrbox)
@ -111,6 +110,9 @@ cache_param_t * search_cache( char targetname[], cachelist_param_t *cachelist)
{ {
cache_param_t *foundcache; cache_param_t *foundcache;
if( !targetname)
return NULL;
foundcache = cachelist->first; foundcache = cachelist->first;
while( foundcache != NULL){ while( foundcache != NULL){
@ -143,6 +145,9 @@ cache_param_t * search_cacheBycid( char cid[], cachelist_param_t *cachelist)
cache_param_t *foundcache; cache_param_t *foundcache;
int i; int i;
if( !cid)
return NULL;
foundcache = cachelist->first; foundcache = cachelist->first;
while( foundcache != NULL){ while( foundcache != NULL){
@ -158,6 +163,9 @@ cache_param_t * search_cacheBytid( char tid[], cachelist_param_t *cachelist)
{ {
cache_param_t *foundcache; cache_param_t *foundcache;
if( !tid)
return NULL;
foundcache = cachelist->first; foundcache = cachelist->first;
while( foundcache != NULL){ while( foundcache != NULL){
@ -170,31 +178,28 @@ cache_param_t * search_cacheBytid( char tid[], cachelist_param_t *cachelist)
void add_cachecid( char *cid, cache_param_t *cache) void add_cachecid( char *cid, cache_param_t *cache)
{ {
char **tmp; if( !cid)
int i; return;
tmp = cache->cid; if( realloc( cache->cid, (cache->numOfcid+1)*sizeof(char *)) == NULL){
fprintf( stderr, "failed to add new cid to cache table in add_cachecid()\n");
cache->cid = (char **)malloc( (cache->numOfcid+1)*sizeof(char *)); return;
for( i=0; i<cache->numOfcid; i++){
cache->cid[i] = (char *)malloc( MAX_LENOFCID);
strcpy( cache->cid[i], tmp[i]);
free( tmp[i]);
} }
free( tmp);
cache->cid[ cache->numOfcid] = (char *)malloc( MAX_LENOFCID); cache->cid[ cache->numOfcid] = strdup( cid);
strcpy( cache->cid[ cache->numOfcid], cid);
cache->numOfcid ++; cache->numOfcid ++;
} }
void update_cachetid( char *tid, cache_param_t *cache) void update_cachetid( char *tid, cache_param_t *cache)
{ {
if( !tid)
return;
if( tid[0] != '0' && strcmp( tid, cache->tid) !=0){ if( tid[0] != '0' && strcmp( tid, cache->tid) !=0){
fprintf( stderr, "tid is updated to %s for %s\n", tid, cache->filename); fprintf( stderr, "tid is updated to %s for %s\n", tid, cache->filename);
strcpy( cache->tid, tid); free( cache->tid);
cache->tid = strdup( tid);
} }
} }
@ -231,8 +236,7 @@ void remove_cidInCache( char *cid, cache_param_t *cache)
for( i=0, j=0; i<cache->numOfcid; i++){ for( i=0, j=0; i<cache->numOfcid; i++){
if( i != idx){ if( i != idx){
cache->cid[j] = (char *)malloc( MAX_LENOFCID); cache->cid[j] = strdup( tmp[i]);
strcpy( cache->cid[j], tmp[i]);
j++; j++;
} }
free( tmp[i]); free( tmp[i]);

View File

@ -34,16 +34,10 @@
#include "metadata_manager.h" #include "metadata_manager.h"
#include "ihdrbox_manager.h" #include "ihdrbox_manager.h"
//! maximum length of target name
#define MAX_LENOFTARGET 128
//! maximum length of target identifier
#define MAX_LENOFTID 30
//! cache parameters //! cache parameters
typedef struct cache_param{ typedef struct cache_param{
char filename[MAX_LENOFTARGET]; //!< file name char *filename; //!< file name
char tid[MAX_LENOFTID]; //!< taregt identifier char *tid; //!< taregt identifier
int csn; //!< codestream number int csn; //!< codestream number
char **cid; //!< dynamic array of channel identifiers char **cid; //!< dynamic array of channel identifiers
int numOfcid; //!< number of cids int numOfcid; //!< number of cids

View File

@ -184,7 +184,6 @@ void delete_cachemodel( cachemodel_param_t **cachemodel)
free( (*cachemodel)->tp_model); free( (*cachemodel)->tp_model);
free( (*cachemodel)->th_model); free( (*cachemodel)->th_model);
if( (*cachemodel)->target->codeidx->SIZ.Csiz > 1)
for( i=0; i<(*cachemodel)->target->codeidx->SIZ.Csiz; i++) for( i=0; i<(*cachemodel)->target->codeidx->SIZ.Csiz; i++)
free( (*cachemodel)->pp_model[i]); free( (*cachemodel)->pp_model[i]);
free( (*cachemodel)->pp_model); free( (*cachemodel)->pp_model);

View File

@ -37,20 +37,16 @@
#include "jpipstream_manager.h" #include "jpipstream_manager.h"
#include "jp2k_encoder.h" #include "jp2k_encoder.h"
//! maximum length of channel identifier
#define MAX_LENOFCID 30
void handle_JPIPstreamMSG( SOCKET connected_socket, cachelist_param_t *cachelist, void handle_JPIPstreamMSG( SOCKET connected_socket, cachelist_param_t *cachelist,
Byte_t **jpipstream, int *streamlen, msgqueue_param_t *msgqueue) Byte_t **jpipstream, int *streamlen, msgqueue_param_t *msgqueue)
{ {
Byte_t *newjpipstream; Byte_t *newjpipstream;
int newstreamlen = 0; int newstreamlen = 0;
cache_param_t *cache; cache_param_t *cache;
char target[MAX_LENOFTARGET], tid[MAX_LENOFTID], cid[MAX_LENOFCID]; char *target, *tid, *cid;
metadatalist_param_t *metadatalist; metadatalist_param_t *metadatalist;
newjpipstream = receive_JPIPstream( connected_socket, target, tid, cid, &newstreamlen); newjpipstream = receive_JPIPstream( connected_socket, &target, &tid, &cid, &newstreamlen);
parse_JPIPstream( newjpipstream, newstreamlen, *streamlen, msgqueue); parse_JPIPstream( newjpipstream, newstreamlen, *streamlen, msgqueue);
@ -61,11 +57,11 @@ void handle_JPIPstreamMSG( SOCKET connected_socket, cachelist_param_t *cachelist
parse_metamsg( msgqueue, *jpipstream, *streamlen, metadatalist); parse_metamsg( msgqueue, *jpipstream, *streamlen, metadatalist);
// cid registration // cid registration
if( target[0] != 0){ if( target != NULL){
if((cache = search_cache( target, cachelist))){ if((cache = search_cache( target, cachelist))){
if( tid[0] != 0) if( tid != NULL)
update_cachetid( tid, cache); update_cachetid( tid, cache);
if( cid[0] != 0) if( cid != NULL)
add_cachecid( cid, cache); add_cachecid( cid, cache);
} }
else{ else{
@ -80,6 +76,10 @@ void handle_JPIPstreamMSG( SOCKET connected_socket, cachelist_param_t *cachelist
delete_metadatalist( &cache->metadatalist); delete_metadatalist( &cache->metadatalist);
cache->metadatalist = metadatalist; cache->metadatalist = metadatalist;
if( target) free( target);
if( tid) free( tid);
if( cid) free( cid);
response_signal( connected_socket, true); response_signal( connected_socket, true);
} }
@ -87,14 +87,19 @@ void handle_PNMreqMSG( SOCKET connected_socket, Byte_t *jpipstream, msgqueue_par
{ {
Byte_t *pnmstream; Byte_t *pnmstream;
ihdrbox_param_t *ihdrbox; ihdrbox_param_t *ihdrbox;
char cid[MAX_LENOFCID], tmp[10]; char *CIDorTID, tmp[10];
cache_param_t *cache; cache_param_t *cache;
int fw, fh; int fw, fh;
receive_line( connected_socket, cid); CIDorTID = receive_string( connected_socket);
if(!(cache = search_cacheBycid( cid, cachelist)))
if(!(cache = search_cacheBytid( cid, cachelist))) if(!(cache = search_cacheBycid( CIDorTID, cachelist)))
if(!(cache = search_cacheBytid( CIDorTID, cachelist))){
free( CIDorTID);
return; return;
}
free( CIDorTID);
receive_line( connected_socket, tmp); receive_line( connected_socket, tmp);
fw = atoi( tmp); fw = atoi( tmp);
@ -112,12 +117,17 @@ void handle_PNMreqMSG( SOCKET connected_socket, Byte_t *jpipstream, msgqueue_par
void handle_XMLreqMSG( SOCKET connected_socket, Byte_t *jpipstream, cachelist_param_t *cachelist) void handle_XMLreqMSG( SOCKET connected_socket, Byte_t *jpipstream, cachelist_param_t *cachelist)
{ {
char cid[MAX_LENOFCID]; char *cid;
cache_param_t *cache; cache_param_t *cache;
receive_line( connected_socket, cid); cid = receive_string( connected_socket);
if(!(cache = search_cacheBycid( cid, cachelist)))
if(!(cache = search_cacheBycid( cid, cachelist))){
free( cid);
return; return;
}
free( cid);
boxcontents_param_t *boxcontents = cache->metadatalist->last->boxcontents; boxcontents_param_t *boxcontents = cache->metadatalist->last->boxcontents;
Byte_t *xmlstream = (Byte_t *)malloc( boxcontents->length); Byte_t *xmlstream = (Byte_t *)malloc( boxcontents->length);
@ -128,13 +138,15 @@ void handle_XMLreqMSG( SOCKET connected_socket, Byte_t *jpipstream, cachelist_pa
void handle_TIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist) void handle_TIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
{ {
char target[MAX_LENOFTARGET], *tid = NULL; char *target, *tid = NULL;
cache_param_t *cache; cache_param_t *cache;
int tidlen = 0; int tidlen = 0;
receive_line( connected_socket, target); target = receive_string( connected_socket);
cache = search_cache( target, cachelist); cache = search_cache( target, cachelist);
free( target);
if( cache){ if( cache){
tid = cache->tid; tid = cache->tid;
tidlen = strlen(tid); tidlen = strlen(tid);
@ -144,13 +156,15 @@ void handle_TIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
void handle_CIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist) void handle_CIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
{ {
char target[MAX_LENOFTARGET], *cid = NULL; char *target, *cid = NULL;
cache_param_t *cache; cache_param_t *cache;
int cidlen = 0; int cidlen = 0;
receive_line( connected_socket, target); target = receive_string( connected_socket);
cache = search_cache( target, cachelist); cache = search_cache( target, cachelist);
free( target);
if( cache){ if( cache){
if( cache->numOfcid > 0){ if( cache->numOfcid > 0){
cid = cache->cid[ cache->numOfcid-1]; cid = cache->cid[ cache->numOfcid-1];
@ -162,23 +176,29 @@ void handle_CIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
void handle_dstCIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist) void handle_dstCIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
{ {
char cid[MAX_LENOFCID]; char *cid;
receive_line( connected_socket, cid); cid = receive_string( connected_socket);
remove_cachecid( cid, cachelist); remove_cachecid( cid, cachelist);
response_signal( connected_socket, true); response_signal( connected_socket, true);
free( cid);
} }
void handle_JP2saveMSG( SOCKET connected_socket, cachelist_param_t *cachelist, msgqueue_param_t *msgqueue, Byte_t *jpipstream) void handle_JP2saveMSG( SOCKET connected_socket, cachelist_param_t *cachelist, msgqueue_param_t *msgqueue, Byte_t *jpipstream)
{ {
char cid[MAX_LENOFCID]; char *cid;
cache_param_t *cache; cache_param_t *cache;
Byte_t *jp2stream; Byte_t *jp2stream;
Byte8_t jp2len; Byte8_t jp2len;
receive_line( connected_socket, cid); cid = receive_string( connected_socket);
if(!(cache = search_cacheBycid( cid, cachelist))) if(!(cache = search_cacheBycid( cid, cachelist))){
free( cid);
return; return;
}
free( cid);
jp2stream = recons_jp2( msgqueue, jpipstream, cache->csn, &jp2len); jp2stream = recons_jp2( msgqueue, jpipstream, cache->csn, &jp2len);

View File

@ -123,15 +123,13 @@ msgtype_t identify_clientmsg( SOCKET connected_socket)
return MSGERROR; return MSGERROR;
} }
Byte_t * receive_JPIPstream( SOCKET connected_socket, char *target, char *tid, char *cid, int *streamlen) Byte_t * receive_JPIPstream( SOCKET connected_socket, char **target, char **tid, char **cid, int *streamlen)
{ {
Byte_t *jpipstream=NULL, *ptr; Byte_t *jpipstream=NULL, *ptr;
char buf[BUF_LEN], versionstring[] = "version 1.2"; char buf[BUF_LEN], versionstring[] = "version 1.2";
int linelen, redlen, remlen; int linelen, redlen, remlen;
target[0] = 0; *target = *cid = *tid = NULL;
cid[0] = 0;
tid[0] = 0;
if((linelen = receive_line( connected_socket, buf)) == 0) if((linelen = receive_line( connected_socket, buf)) == 0)
return NULL; return NULL;
@ -145,17 +143,17 @@ Byte_t * receive_JPIPstream( SOCKET connected_socket, char *target, char *tid, c
if( strstr( buf, "jp2")){ if( strstr( buf, "jp2")){
// register cid option // register cid option
strcpy( target, buf); *target = strdup( buf);
if((linelen = receive_line( connected_socket, buf)) == 0) if((linelen = receive_line( connected_socket, buf)) == 0)
return NULL; return NULL;
if( strcmp( buf, "0") != 0) if( strcmp( buf, "0") != 0)
strcpy( tid, buf); *tid = strdup( buf);
if((linelen = receive_line( connected_socket, buf)) == 0) if((linelen = receive_line( connected_socket, buf)) == 0)
return NULL; return NULL;
if( strcmp( buf, "0") != 0) if( strcmp( buf, "0") != 0)
strcpy( cid, buf); *cid = strdup( buf);
if((linelen = receive_line( connected_socket, buf)) == 0) if((linelen = receive_line( connected_socket, buf)) == 0)
return NULL; return NULL;
@ -281,6 +279,15 @@ int receive_line(SOCKET connected_socket, char *p)
return len; return len;
} }
char * receive_string( SOCKET connected_socket)
{
char buf[BUF_LEN];
receive_line( connected_socket, buf);
return strdup(buf);
}
void response_signal( SOCKET connected_socket, bool succeed) void response_signal( SOCKET connected_socket, bool succeed)
{ {
Byte_t code; Byte_t code;

View File

@ -71,13 +71,13 @@ msgtype_t identify_clientmsg( SOCKET connected_socket);
* receive a JPT- JPP- stream from client * receive a JPT- JPP- stream from client
* *
* @param [in] connected_socket file descriptor of the connected socket * @param [in] connected_socket file descriptor of the connected socket
* @param [out] target received target file name (if not received, null string) * @param [out] target address of received target file name string pointer ( malloced, if not received, NULL)
* @param [out] tid received target identifier (if not received, null string) * @param [out] tid address of received target identifier string pointer ( malloced, if not received, null string)
* @param [out] cid received channel identifier (if not received, null string) * @param [out] cid address of received channel identifier string pointer ( malloced, if not received, null string)
* @param [out] streamlen length of the received codestream * @param [out] streamlen length of the received codestream
* @return JPT- JPP- codestream * @return JPT- JPP- codestream
*/ */
Byte_t * receive_JPIPstream( SOCKET connected_socket, char *target, char *tid, char *cid, int *streamlen); Byte_t * receive_JPIPstream( SOCKET connected_socket, char **target, char **tid, char **cid, int *streamlen);
/** /**
* send PGM/PPM image stream to the client * send PGM/PPM image stream to the client
@ -135,6 +135,14 @@ void response_signal( SOCKET connected_socket, bool succeed);
*/ */
int receive_line(SOCKET connected_socket, char *buf); int receive_line(SOCKET connected_socket, char *buf);
/**
* receive a string line (ending with '\n') from client, return malloc string
*
* @param [in] connected_socket file descriptor of the connected socket
* @return pointer to the string (memory allocated)
*/
char * receive_string( SOCKET connected_socket);
/** /**
* close socket * close socket
* *

View File

@ -564,7 +564,7 @@ bool set_ppixdata( box_param_t *cidx_box, index_param_t *jp2idx)
free( faix_box); free( faix_box);
} }
free(manf); delete_manfbox( &manf);
return true; return true;
} }

View File

@ -69,19 +69,19 @@ targetlist_param_t * gene_targetlist()
*/ */
int open_jp2file( char filename[]); int open_jp2file( char filename[]);
target_param_t * gene_target( targetlist_param_t *targetlist, char *targetname) target_param_t * gene_target( targetlist_param_t *targetlist, char *targetpath)
{ {
target_param_t *target; target_param_t *target;
int fd; int fd;
index_param_t *jp2idx; index_param_t *jp2idx;
static int last_csn = 0; static int last_csn = 0;
if( targetname[0]=='\0'){ if( targetpath[0]=='\0'){
fprintf( FCGI_stderr, "Error: exception, no targetname in gene_target()\n"); fprintf( FCGI_stderr, "Error: exception, no targetpath in gene_target()\n");
return NULL; return NULL;
} }
if((fd = open_jp2file( targetname)) == -1){ if((fd = open_jp2file( targetpath)) == -1){
fprintf( FCGI_stdout, "Status: 404\r\n"); fprintf( FCGI_stdout, "Status: 404\r\n");
return NULL; return NULL;
} }
@ -93,7 +93,7 @@ target_param_t * gene_target( targetlist_param_t *targetlist, char *targetname)
target = (target_param_t *)malloc( sizeof(target_param_t)); target = (target_param_t *)malloc( sizeof(target_param_t));
snprintf( target->tid, MAX_LENOFTID, "%x-%x", (unsigned int)time(NULL), (unsigned int)rand()); snprintf( target->tid, MAX_LENOFTID, "%x-%x", (unsigned int)time(NULL), (unsigned int)rand());
strcpy( target->filename, targetname); target->filename = strdup( targetpath);
target->fd = fd; target->fd = fd;
target->csn = last_csn++; target->csn = last_csn++;
target->codeidx = jp2idx; target->codeidx = jp2idx;
@ -109,7 +109,7 @@ target_param_t * gene_target( targetlist_param_t *targetlist, char *targetname)
targetlist->last = target; targetlist->last = target;
#ifndef SERVER #ifndef SERVER
fprintf( logstream, "local log: target %s generated\n", targetname); fprintf( logstream, "local log: target %s generated\n", targetpath);
#endif #endif
return target; return target;
@ -129,11 +129,16 @@ void unrefer_target( target_param_t *target)
void delete_target( target_param_t **target) void delete_target( target_param_t **target)
{ {
close( (*target)->fd); close( (*target)->fd);
if( (*target)->codeidx)
delete_index ( &(*target)->codeidx); delete_index ( &(*target)->codeidx);
#ifndef SERVER #ifndef SERVER
fprintf( logstream, "local log: target: %s deleted\n", (*target)->filename); fprintf( logstream, "local log: target: %s deleted\n", (*target)->filename);
#endif #endif
free( (*target)->filename);
free(*target); free(*target);
} }

View File

@ -37,13 +37,10 @@
//! maximum length of target identifier //! maximum length of target identifier
#define MAX_LENOFTID 30 #define MAX_LENOFTID 30
//! maximum length of target name
#define MAX_LENOFTARGET 128
//! target parameters //! target parameters
typedef struct target_param{ typedef struct target_param{
char tid[MAX_LENOFTID]; //!< taregt identifier char tid[MAX_LENOFTID]; //!< taregt identifier
char filename[MAX_LENOFTARGET]; //!< file name char *filename; //!< file name
int fd; //!< file descriptor int fd; //!< file descriptor
int csn; //!< codestream number int csn; //!< codestream number
index_param_t *codeidx; //!< index information of codestream index_param_t *codeidx; //!< index information of codestream
@ -74,10 +71,10 @@ targetlist_param_t * gene_targetlist();
* generate a target * generate a target
* *
* @param[in] targetlist target list to insert the generated target * @param[in] targetlist target list to insert the generated target
* @param[in] targetname target file name * @param[in] targetpath file path or URL of the target
* @return pointer to the generated target * @return pointer to the generated target
*/ */
target_param_t * gene_target( targetlist_param_t *targetlist, char *targetname); target_param_t * gene_target( targetlist_param_t *targetlist, char *targetpath);
/** /**

View File

@ -64,7 +64,7 @@ int main(int argc,char *argv[])
if(!( fwrite_jp2k( argv[2], dec))) if(!( fwrite_jp2k( argv[2], dec)))
return -1; return -1;
output_log( true, false, false, dec); // output_log( true, false, false, dec);
destroy_jpipdecoder( &dec); destroy_jpipdecoder( &dec);