! : changed
+ : added
+November 3, 2011
+* [kaori] solved memory leak of opj_server
+! [kaori] removed redundant defines
+
November 2, 2011
* [antonin] additional patches for autotools and cmake
boxlen = fetch_8bytebigendian( fd, offset+8);
headlen = 16;
}
+
boxheader = (boxheader_param_t *)malloc( sizeof( boxheader_param_t));
boxheader->headlen = headlen;
boxheader->length = boxlen;
#include <string.h>
#include "cache_manager.h"
-//! maximum length of channel identifier
-#define MAX_LENOFCID 30
-
cachelist_param_t * gene_cachelist()
{
cachelist_param_t *cachelist;
cache_param_t *cache;
cache = (cache_param_t *)malloc( sizeof(cache_param_t));
- strcpy( cache->filename, targetname);
- strcpy( cache->tid, tid);
+ cache->filename = strdup( targetname);
+ cache->tid = strdup( tid);
cache->csn = csn;
cache->cid = (char **)malloc( sizeof(char *));
- *cache->cid = (char *)malloc( MAX_LENOFCID);
- strcpy( *cache->cid, cid);
+ *cache->cid = strdup( cid);
cache->numOfcid = 1;
#if 1
cache->metadatalist = NULL;
void delete_cache( cache_param_t **cache)
{
int i;
+
+ free( (*cache)->filename);
+ free( (*cache)->tid);
delete_metadatalist( &(*cache)->metadatalist);
{
cache_param_t *foundcache;
+ if( !targetname)
+ return NULL;
+
foundcache = cachelist->first;
while( foundcache != NULL){
cache_param_t *foundcache;
int i;
+ if( !cid)
+ return NULL;
+
foundcache = cachelist->first;
while( foundcache != NULL){
{
cache_param_t *foundcache;
+ if( !tid)
+ return NULL;
+
foundcache = cachelist->first;
while( foundcache != NULL){
void add_cachecid( char *cid, cache_param_t *cache)
{
- char **tmp;
- int i;
+ if( !cid)
+ return;
- tmp = cache->cid;
-
- cache->cid = (char **)malloc( (cache->numOfcid+1)*sizeof(char *));
-
- for( i=0; i<cache->numOfcid; i++){
- cache->cid[i] = (char *)malloc( MAX_LENOFCID);
- strcpy( cache->cid[i], tmp[i]);
- free( tmp[i]);
+ if( realloc( cache->cid, (cache->numOfcid+1)*sizeof(char *)) == NULL){
+ fprintf( stderr, "failed to add new cid to cache table in add_cachecid()\n");
+ return;
}
- free( tmp);
-
- cache->cid[ cache->numOfcid] = (char *)malloc( MAX_LENOFCID);
- strcpy( cache->cid[ cache->numOfcid], cid);
+
+ cache->cid[ cache->numOfcid] = strdup( cid);
cache->numOfcid ++;
}
void update_cachetid( char *tid, cache_param_t *cache)
{
+ if( !tid)
+ return;
+
if( tid[0] != '0' && strcmp( tid, cache->tid) !=0){
fprintf( stderr, "tid is updated to %s for %s\n", tid, cache->filename);
- strcpy( cache->tid, tid);
+ free( cache->tid);
+ cache->tid = strdup( tid);
}
}
for( i=0, j=0; i<cache->numOfcid; i++){
if( i != idx){
- cache->cid[j] = (char *)malloc( MAX_LENOFCID);
- strcpy( cache->cid[j], tmp[i]);
+ cache->cid[j] = strdup( tmp[i]);
j++;
}
free( tmp[i]);
#include "metadata_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
typedef struct cache_param{
- char filename[MAX_LENOFTARGET]; //!< file name
- char tid[MAX_LENOFTID]; //!< taregt identifier
+ char *filename; //!< file name
+ char *tid; //!< taregt identifier
int csn; //!< codestream number
char **cid; //!< dynamic array of channel identifiers
int numOfcid; //!< number of cids
free( (*cachemodel)->tp_model);
free( (*cachemodel)->th_model);
- if( (*cachemodel)->target->codeidx->SIZ.Csiz > 1)
- for( i=0; i<(*cachemodel)->target->codeidx->SIZ.Csiz; i++)
- free( (*cachemodel)->pp_model[i]);
+ for( i=0; i<(*cachemodel)->target->codeidx->SIZ.Csiz; i++)
+ free( (*cachemodel)->pp_model[i]);
free( (*cachemodel)->pp_model);
#ifndef SERVER
#include "jpipstream_manager.h"
#include "jp2k_encoder.h"
-
-//! maximum length of channel identifier
-#define MAX_LENOFCID 30
-
void handle_JPIPstreamMSG( SOCKET connected_socket, cachelist_param_t *cachelist,
Byte_t **jpipstream, int *streamlen, msgqueue_param_t *msgqueue)
{
Byte_t *newjpipstream;
int newstreamlen = 0;
cache_param_t *cache;
- char target[MAX_LENOFTARGET], tid[MAX_LENOFTID], cid[MAX_LENOFCID];
+ char *target, *tid, *cid;
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_metamsg( msgqueue, *jpipstream, *streamlen, metadatalist);
// cid registration
- if( target[0] != 0){
+ if( target != NULL){
if((cache = search_cache( target, cachelist))){
- if( tid[0] != 0)
+ if( tid != NULL)
update_cachetid( tid, cache);
- if( cid[0] != 0)
+ if( cid != NULL)
add_cachecid( cid, cache);
}
else{
delete_metadatalist( &cache->metadatalist);
cache->metadatalist = metadatalist;
+ if( target) free( target);
+ if( tid) free( tid);
+ if( cid) free( cid);
+
response_signal( connected_socket, true);
}
{
Byte_t *pnmstream;
ihdrbox_param_t *ihdrbox;
- char cid[MAX_LENOFCID], tmp[10];
+ char *CIDorTID, tmp[10];
cache_param_t *cache;
int fw, fh;
- receive_line( connected_socket, cid);
- if(!(cache = search_cacheBycid( cid, cachelist)))
- if(!(cache = search_cacheBytid( cid, cachelist)))
+ CIDorTID = receive_string( connected_socket);
+
+ if(!(cache = search_cacheBycid( CIDorTID, cachelist)))
+ if(!(cache = search_cacheBytid( CIDorTID, cachelist))){
+ free( CIDorTID);
return;
+ }
+
+ free( CIDorTID);
receive_line( connected_socket, tmp);
fw = atoi( tmp);
void handle_XMLreqMSG( SOCKET connected_socket, Byte_t *jpipstream, cachelist_param_t *cachelist)
{
- char cid[MAX_LENOFCID];
+ char *cid;
cache_param_t *cache;
- receive_line( connected_socket, cid);
- if(!(cache = search_cacheBycid( cid, cachelist)))
+ cid = receive_string( connected_socket);
+
+ if(!(cache = search_cacheBycid( cid, cachelist))){
+ free( cid);
return;
+ }
+
+ free( cid);
boxcontents_param_t *boxcontents = cache->metadatalist->last->boxcontents;
Byte_t *xmlstream = (Byte_t *)malloc( boxcontents->length);
void handle_TIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
{
- char target[MAX_LENOFTARGET], *tid = NULL;
+ char *target, *tid = NULL;
cache_param_t *cache;
int tidlen = 0;
- receive_line( connected_socket, target);
+ target = receive_string( connected_socket);
cache = search_cache( target, cachelist);
+
+ free( target);
if( cache){
tid = cache->tid;
void handle_CIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
{
- char target[MAX_LENOFTARGET], *cid = NULL;
+ char *target, *cid = NULL;
cache_param_t *cache;
int cidlen = 0;
- receive_line( connected_socket, target);
+ target = receive_string( connected_socket);
cache = search_cache( target, cachelist);
+ free( target);
+
if( cache){
if( cache->numOfcid > 0){
cid = cache->cid[ cache->numOfcid-1];
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);
response_signal( connected_socket, true);
+
+ free( cid);
}
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;
Byte_t *jp2stream;
Byte8_t jp2len;
- receive_line( connected_socket, cid);
- if(!(cache = search_cacheBycid( cid, cachelist)))
+ cid = receive_string( connected_socket);
+ if(!(cache = search_cacheBycid( cid, cachelist))){
+ free( cid);
return;
+ }
+
+ free( cid);
jp2stream = recons_jp2( msgqueue, jpipstream, cache->csn, &jp2len);
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;
char buf[BUF_LEN], versionstring[] = "version 1.2";
int linelen, redlen, remlen;
- target[0] = 0;
- cid[0] = 0;
- tid[0] = 0;
+ *target = *cid = *tid = NULL;
if((linelen = receive_line( connected_socket, buf)) == 0)
return NULL;
if( strstr( buf, "jp2")){
// register cid option
- strcpy( target, buf);
+ *target = strdup( buf);
if((linelen = receive_line( connected_socket, buf)) == 0)
return NULL;
if( strcmp( buf, "0") != 0)
- strcpy( tid, buf);
+ *tid = strdup( buf);
if((linelen = receive_line( connected_socket, buf)) == 0)
return NULL;
if( strcmp( buf, "0") != 0)
- strcpy( cid, buf);
+ *cid = strdup( buf);
if((linelen = receive_line( connected_socket, buf)) == 0)
return NULL;
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)
{
Byte_t code;
* receive a JPT- JPP- stream from client
*
* @param [in] connected_socket file descriptor of the connected socket
- * @param [out] target received target file name (if not received, null string)
- * @param [out] tid received target identifier (if not received, null string)
- * @param [out] cid received channel identifier (if not received, null string)
+ * @param [out] target address of received target file name string pointer ( malloced, if not received, NULL)
+ * @param [out] tid address of received target identifier string pointer ( malloced, 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
* @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
*/
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
*
free( faix_box);
}
- free(manf);
+ delete_manfbox( &manf);
return true;
}
bhPtr = (*manf)->first;
while( bhPtr != NULL){
- bhNext=bhPtr->next;
+ bhNext = bhPtr->next;
#ifndef SERVER
// fprintf( logstream, "local log: boxheader %.4s deleted!\n", bhPtr->type);
#endif
free(bhPtr);
- bhPtr=bhNext;
+ bhPtr = bhNext;
}
free( *manf);
}
*/
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;
int fd;
index_param_t *jp2idx;
static int last_csn = 0;
- if( targetname[0]=='\0'){
- fprintf( FCGI_stderr, "Error: exception, no targetname in gene_target()\n");
+ if( targetpath[0]=='\0'){
+ fprintf( FCGI_stderr, "Error: exception, no targetpath in gene_target()\n");
return NULL;
}
- if((fd = open_jp2file( targetname)) == -1){
+ if((fd = open_jp2file( targetpath)) == -1){
fprintf( FCGI_stdout, "Status: 404\r\n");
return NULL;
}
target = (target_param_t *)malloc( sizeof(target_param_t));
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->csn = last_csn++;
target->codeidx = jp2idx;
targetlist->last = target;
#ifndef SERVER
- fprintf( logstream, "local log: target %s generated\n", targetname);
+ fprintf( logstream, "local log: target %s generated\n", targetpath);
#endif
return target;
void delete_target( target_param_t **target)
{
close( (*target)->fd);
- delete_index ( &(*target)->codeidx);
+
+ if( (*target)->codeidx)
+ delete_index ( &(*target)->codeidx);
#ifndef SERVER
fprintf( logstream, "local log: target: %s deleted\n", (*target)->filename);
#endif
+
+ free( (*target)->filename);
+
free(*target);
}
//! maximum length of target identifier
#define MAX_LENOFTID 30
-//! maximum length of target name
-#define MAX_LENOFTARGET 128
-
//! target parameters
typedef struct target_param{
char tid[MAX_LENOFTID]; //!< taregt identifier
- char filename[MAX_LENOFTARGET]; //!< file name
+ char *filename; //!< file name
int fd; //!< file descriptor
int csn; //!< codestream number
index_param_t *codeidx; //!< index information of codestream
* generate a 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
*/
-target_param_t * gene_target( targetlist_param_t *targetlist, char *targetname);
+target_param_t * gene_target( targetlist_param_t *targetlist, char *targetpath);
/**
if(!( fwrite_jp2k( argv[2], dec)))
return -1;
- output_log( true, false, false, dec);
+ // output_log( true, false, false, dec);
destroy_jpipdecoder( &dec);