Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
  if( argc<3){
    fprintf( stderr, "USAGE: ./addXMLinJP2 modifing.jp2 adding.xml\n");
    return -1;
  }
  
  FILE *fp;
  char *xmldata, type[]="xml ";
  long fsize, boxsize;

  fp = open_jp2file( argv[1]);
  if( !fp)
    return -1;
  
  xmldata = read_xmlfile( argv[2], &fsize);
  boxsize = fsize + 8;

  fputc( (boxsize>>24)&0xff, fp);
  fputc( (boxsize>>16)&0xff, fp);
  fputc( (boxsize>>8)&0xff, fp);
  fputc( boxsize&0xff, fp);
  fwrite( type, 4, 1, fp);
  fwrite( xmldata, fsize, 1, fp);
  
  free( xmldata);
  fclose(fp);
  
  return 0;
}
Ejemplo n.º 2
0
target_param_t * gene_target( targetlist_param_t *targetlist, char *targetpath)
{
  target_param_t *target;
  int fd;
  index_param_t *jp2idx;
  char tmpfname[MAX_LENOFTID];
  static int last_csn = 0;
  
  if( targetpath[0]=='\0'){
    fprintf( FCGI_stderr, "Error: exception, no targetpath in gene_target()\n");
    return NULL;
  }

  if((fd = open_jp2file( targetpath, tmpfname)) == -1){
    fprintf( FCGI_stdout, "Status: 404\r\n"); 
    return NULL;
  }
  
  if( !(jp2idx = parse_jp2file( fd))){
    fprintf( FCGI_stdout, "Status: 501\r\n");
    return NULL;
  }

  target = (target_param_t *)opj_malloc( sizeof(target_param_t));
  snprintf( target->tid, MAX_LENOFTID, "%x-%x", (unsigned int)time(NULL), (unsigned int)rand());
  target->targetname = strdup( targetpath); 
  target->fd = fd;
#ifdef SERVER
  if( tmpfname[0])
    target->tmpfname = strdup( tmpfname);
  else
    target->tmpfname = NULL;
#endif
  target->csn = last_csn++;
  target->codeidx = jp2idx;
  target->num_of_use = 0; 
  target->jppstream = OPJ_TRUE;
  target->jptstream = isJPTfeasible( *jp2idx);
  target->next=NULL;

  if( targetlist->first) /* there are one or more entries*/
    targetlist->last->next = target;
  else                   /* first entry*/
    targetlist->first = target;
  targetlist->last = target;

#ifndef SERVER
  fprintf( logstream, "local log: target %s generated\n", targetpath);
#endif
  
  return target;
}