Ejemplo n.º 1
0
box_param_t * gene_boxbyType( int fd, Byte8_t offset, Byte8_t length, char TBox[])
{
  Byte8_t pos;
  Byte_t *data;
  Byte8_t boxlen, headlen;
  char *boxtype;
  box_param_t *foundbox;

  
  if( length==0){ /* set the max length*/
    if( (length = get_filesize( fd) - offset) <= 0)
      return NULL;
  }

  pos = offset;
  while( pos < offset+length-7){ /* LBox+TBox-1=7*/
    
    /* read LBox and TBox*/
    if((data = fetch_bytes( fd, pos, 8))){
      headlen = 8;
      boxlen = (Byte8_t)big4(data);
      boxtype = (char *)(data+4);

      if( boxlen == 1){
	Byte_t *data2;
	headlen = 16;
	/* read XLBox*/
	if((data2 = fetch_bytes( fd, pos+8, 8))){
	  boxlen = big8(data2);
	  free(data2);
	}
	else{
	  fprintf( FCGI_stderr, "Error: error in gene_boxbyType( %d, %lld, %lld, %s)\n", fd, offset, length, TBox);
	  return NULL;
	}
      }
      if( strncmp ( boxtype, TBox, 4) == 0){
	foundbox = (box_param_t *)malloc( sizeof( box_param_t));
	foundbox->fd = fd;
	foundbox->offset = pos;
	foundbox->headlen = headlen;
	foundbox->length = boxlen;
	strncpy( foundbox->type, TBox, 4);
	foundbox->next = NULL;
	free( data);
	return foundbox;
      }
      free( data);
    }
    else{
      fprintf( FCGI_stderr, "Error: error in gene_boxbyType( %d, %lld, %lld, %s)\n", fd, offset, length, TBox);
      return NULL;
    }
    pos+= boxlen;
  }
  fprintf( FCGI_stderr, "Error: Box %s not found\n", TBox);

  return NULL;
}
Ejemplo n.º 2
0
box_param_t * gene_boxbyOffset( int fd, OPJ_OFF_T offset)
{
  Byte_t *data;
  Byte8_t boxlen;
  Byte_t headlen;
  char *boxtype;
  box_param_t *box;

  /* read LBox and TBox*/
  if(!(data = fetch_bytes( fd, offset, 8))){
    fprintf( FCGI_stderr, "Error: error in gene_boxbyOffset( %d, %" PRId64 ")\n", fd, offset);
    return NULL;
  }
  
  headlen = 8;
  boxlen = (Byte8_t)big4(data);
  boxtype = (char *)(data+4);  

  /* box type constraint*/
  if( !isalpha(boxtype[0]) || !isalpha(boxtype[1]) ||
      (!isalnum(boxtype[2])&&!isspace(boxtype[2])) ||
      (!isalpha(boxtype[3])&&!isspace(boxtype[3]))){
    free( data);
    return NULL;
  }
  
  if( boxlen == 1){
    Byte_t *data2;
    headlen = 16;
    /* read XLBox*/
    if((data2 = fetch_bytes( fd, offset+8, 8))){
      boxlen = big8(data2);
      free(data2);
    }
    else{
      fprintf( FCGI_stderr, "Error: error in gene_boxbyOffset( %d, %" PRId64 ")\n", fd, offset);
      free( data);
      return NULL;
    }
  }
  box = (box_param_t *)malloc( sizeof( box_param_t));
  box->fd = fd;
  box->offset = offset;
  box->headlen = headlen;
  box->length = boxlen;
  strncpy( box->type, boxtype, 4);
  box->next = NULL;
  free( data);
  return box;
}
Ejemplo n.º 3
0
boxheader_param_t * gene_boxheader( int fd, OPJ_OFF_T offset)
{
  Byte8_t boxlen;
  Byte_t headlen;
  char *boxtype;
  boxheader_param_t *boxheader;

  boxlen = fetch_4bytebigendian( fd, offset);
  boxtype = (char *)fetch_bytes( fd, offset+4, 4);
  headlen = 8;
    
  if( boxlen == 1){ /* read XLBox */
    boxlen = fetch_8bytebigendian( fd, offset+8);
    headlen = 16;
  }

  boxheader = (boxheader_param_t *)malloc( sizeof( boxheader_param_t));
  boxheader->headlen = headlen;
  boxheader->length = boxlen;
  strncpy( boxheader->type, boxtype, 4);
  boxheader->next = NULL;
  
  free( boxtype);
  return boxheader;
}
Ejemplo n.º 4
0
Byte2_t fetch_2bytebigendian( int fd, OPJ_OFF_T offset)
{
  Byte_t *data;
  Byte2_t code;

  if(!(data = fetch_bytes( fd, offset, 2))){
    fprintf( FCGI_stderr, "Error: error in fetch_2bytebigendian( %d, %ld)\n", fd, offset);
    return 0;
  }
  code = big2(data);
  free( data);

  return code;
}
Ejemplo n.º 5
0
Byte8_t fetch_8bytebigendian( int fd, long offset)
{
  Byte_t *data;
  Byte8_t code;

  if(!(data = fetch_bytes( fd, offset, 8))){
    fprintf( FCGI_stderr, "Error: error in fetch_8bytebigendian( %d, %ld)\n", fd, offset);
    return 0;
  }
  code = big8(data);
  free( data);

  return code;
}
Ejemplo n.º 6
0
void send_responsedata( server_record_t *rec, QR_t *qr)
{
  int fd;
  const char tmpfname[] = "tmpjpipstream.jpp";
  Byte_t *jpipstream;
  Byte8_t len_of_jpipstream;

  if( (fd = open( tmpfname, O_RDWR|O_CREAT|O_EXCL, S_IRWXU)) == -1){
    fprintf( FCGI_stderr, "file open error %s", tmpfname);
    fprintf( FCGI_stdout, "Status: 503\r\n");
    fprintf( FCGI_stdout, "Reason: Implementation failed\r\n");
    return;
  }
  
  recons_stream_from_msgqueue( qr->msgqueue, fd);
  
  add_EORmsg( fd, qr); /* needed at least for tcp and udp */
  
  len_of_jpipstream = (Byte8_t)get_filesize( fd);
  jpipstream = fetch_bytes( fd, 0, len_of_jpipstream);
  
  close( fd);
  remove( tmpfname);

  fprintf( FCGI_stdout, "\r\n");

  if( len_of_jpipstream){
    
    if( qr->channel)
      if( qr->channel->aux == tcp || qr->channel->aux == udp){
	send_responsedata_on_aux( qr->channel->aux==tcp, rec->auxtrans, qr->channel->cid, jpipstream, len_of_jpipstream, 1000); /* 1KB per frame*/
	return;
      }
    
    if( fwrite( jpipstream, len_of_jpipstream, 1, FCGI_stdout) != 1)
      fprintf( FCGI_stderr, "Error: failed to write jpipstream\n");
  }

  opj_free( jpipstream);

  return;
}
Ejemplo n.º 7
0
Byte_t * fetch_DBoxbytes( box_param_t *box, OPJ_OFF_T offset, OPJ_SIZE_T size)
{
  return fetch_bytes( box->fd, get_DBoxoff( box)+offset, size);
}
Ejemplo n.º 8
0
Byte_t * fetch_headbytes( box_param_t *box)
{
  return fetch_bytes( box->fd, box->offset, box->headlen);
}
Ejemplo n.º 9
0
box_param_t * gene_boxbyType( int fd, OPJ_OFF_T offset, OPJ_SIZE_T length, const char TBox[])
{
  OPJ_OFF_T pos;
  Byte_t *data;
  Byte8_t boxlen;
  Byte_t headlen;
  char *boxtype;
  box_param_t *foundbox;

  
  if( length==0){ /* set the max length*/
    if( get_filesize( fd) <= offset )
      return NULL;
    assert( get_filesize( fd) > offset );
    assert( offset >= 0 );
    length = (OPJ_SIZE_T)(get_filesize( fd) - offset);
  }

  pos = offset;
  assert( pos >= 0 );
  assert( (OPJ_OFF_T)length >= 0 );
  while( pos < offset+(OPJ_OFF_T)length-7){ /* LBox+TBox-1=7*/
    
    /* read LBox and TBox*/
    if((data = fetch_bytes( fd, pos, 8))){
      headlen = 8;
      boxlen = (Byte8_t)big4(data);
      boxtype = (char *)(data+4);

      if( boxlen == 1){
	Byte_t *data2;
	headlen = 16;
	/* read XLBox*/
	if((data2 = fetch_bytes( fd, pos+8, 8))){
	  boxlen = big8(data2);
	  free(data2);
	}
	else{
	  fprintf( FCGI_stderr, "Error: error in gene_boxbyType( %d, %" PRId64 ", %" PRId64 ", %s)\n", fd, offset, length, TBox);
	  return NULL;
	}
      }
      if( strncmp ( boxtype, TBox, 4) == 0){
	foundbox = (box_param_t *)malloc( sizeof( box_param_t));
	foundbox->fd = fd;
	foundbox->offset = pos;
	foundbox->headlen = headlen;
	foundbox->length = boxlen;
	strncpy( foundbox->type, TBox, 4);
	foundbox->next = NULL;
	free( data);
	return foundbox;
      }
      free( data);
    }
    else{
      fprintf( FCGI_stderr, "Error: error in gene_boxbyType( %d, %" PRId64 ", %" PRId64 ", %s)\n", fd, offset, length, TBox);
      return NULL;
    }
    assert( ((Byte8_t)pos+boxlen)>=(Byte8_t)pos);
    pos+= (OPJ_OFF_T)boxlen;
  }
  fprintf( FCGI_stderr, "Error: Box %s not found\n", TBox);

  return NULL;
}
Byte_t * fetch_codestreambytes( codestream_param_t *cs, long offset, int size)
{
  return fetch_bytes( cs->fd, cs->offset+offset, size);
}
Ejemplo n.º 11
0
Byte_t * fetch_codestreambytes( codestream_param_t *cs, OPJ_OFF_T offset, OPJ_SIZE_T size)
{
  return fetch_bytes( cs->fd, cs->offset+offset, size);
}
Ejemplo n.º 12
0
Byte_t * fetch_DBoxbytes( box_param_t *box, long offset, int size)
{
  return fetch_bytes( box->fd, get_DBoxoff( box)+offset, size);
}
Ejemplo n.º 13
0
box_param_t * gene_boxbyType( int fd, Byte8_t offset, Byte8_t length, char TBox[])
{
  Byte8_t pos;
  Byte_t *data;
  Byte8_t boxlen, headlen;
  char *boxtype;
  box_param_t *foundbox;

  
  if( length==0){ // set the max length
    struct stat sb;
    if( fstat( fd, &sb) == -1){
      fprintf( FCGI_stdout, "Reason: Target broken (fstat error)\r\n");
      return NULL;
    }
    length = (Byte8_t)sb.st_size - offset;
  }

  pos = offset;
  while( pos < offset+length-7){ // LBox+TBox-1=7
    
    // read LBox and TBox
    if((data = fetch_bytes( fd, pos, 8))){
      headlen = 8;
      boxlen = (Byte8_t)big4(data);
      boxtype = (char *)(data+4);

      if( boxlen == 1){
	Byte_t *data2;
	headlen = 16;
	// read XLBox
	if((data2 = fetch_bytes( fd, pos+8, 8))){
	  boxlen = big8(data2);
	  free(data2);
	}
	else{
	  fprintf( FCGI_stderr, "Error: error in gene_boxbyType( %d, %lld, %lld, %s)\n", fd, offset, length, TBox);
	  return NULL;
	}
      }
      if( strncmp ( boxtype, TBox, 4) == 0){
	foundbox = (box_param_t *)malloc( sizeof( box_param_t));
	foundbox->fd = fd;
	foundbox->offset = pos;
	foundbox->headlen = headlen;
	foundbox->length = boxlen;
	strncpy( foundbox->type, TBox, 4);
	foundbox->next = NULL;
	free( data);
	return foundbox;
      }
      free( data);
    }
    else{
      fprintf( FCGI_stderr, "Error: error in gene_boxbyType( %d, %lld, %lld, %s)\n", fd, offset, length, TBox);
      return NULL;
    }
    pos+= boxlen;
  }
  fprintf( FCGI_stderr, "Error: Box %s not found\n", TBox);

  return NULL;
}