Ejemplo n.º 1
0
box_param_t * gene_boxbyOffinStream( Byte_t *stream, OPJ_OFF_T offset)
{
  Byte8_t boxlen;
  Byte_t headlen;
  char *boxtype;
  box_param_t *box;

  /* read LBox and TBox*/
  headlen = 8;
  boxlen = (Byte8_t)big4( stream);
  boxtype = (char *)( stream+4);  

  /* box type constraint*/
  if( !isalpha(boxtype[0]) || !isalpha(boxtype[1]) ||
      (!isalnum(boxtype[2])&&!isspace(boxtype[2])) ||
      (!isalpha(boxtype[3])&&!isspace(boxtype[3]))){
    return NULL;
  }
  
  if( boxlen == 1){
    headlen = 16;
    boxlen = big8( stream+8); /* read XLBox*/
  }
  box = (box_param_t *)malloc( sizeof( box_param_t));
  box->fd = -1;
  box->offset = offset;
  box->headlen = headlen;
  box->length = boxlen;
  strncpy( box->type, boxtype, 4);
  box->next = NULL;

  return box;
}
Ejemplo n.º 2
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.º 3
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.º 4
0
Byte8_t fetch_8bytebigendian( int fd, OPJ_OFF_T 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.º 5
0
box_param_t * gene_boxbyTypeinStream( Byte_t *stream, 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
    fprintf( FCGI_stderr, "func gene_boxbyTypeinStream(), max length must be more than 0\n");
    return NULL;
  }
  
  pos = offset;
  while( pos < offset+length-7){ // LBox+TBox-1=7
    
    // read LBox and TBox
    data = stream + pos;
    headlen = 8;
    boxlen = (Byte8_t)big4(data);
    boxtype = (char *)(data+4);
   
    if( boxlen == 1){
      // read XLBox
      headlen = 16;
      boxlen = big8( data+8);
    }

    if( strncmp ( boxtype, TBox, 4) == 0){
      foundbox = (box_param_t *)malloc( sizeof( box_param_t));
      foundbox->fd = -1;
      foundbox->offset = pos;
      foundbox->headlen = headlen;
      foundbox->length = boxlen;
      strncpy( foundbox->type, TBox, 4);
      foundbox->next = NULL;
      return foundbox;
    }
    pos+= boxlen;
  }
  fprintf( FCGI_stderr, "Error: Box %s not found\n", TBox);
  
  return NULL;
}
Ejemplo n.º 6
0
box_param_t * gene_boxbyTypeinStream( Byte_t *stream, 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;

  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*/
    data = stream + pos;
    headlen = 8;
    boxlen = (Byte8_t)big4(data);
    boxtype = (char *)(data+4);
   
    if( boxlen == 1){
      /* read XLBox*/
      headlen = 16;
      boxlen = big8( data+8);
    }

    if( strncmp ( boxtype, TBox, 4) == 0){
      foundbox = (box_param_t *)malloc( sizeof( box_param_t));
      foundbox->fd = -1;
      foundbox->offset = pos;
      foundbox->headlen = headlen;
      foundbox->length = boxlen;
      strncpy( foundbox->type, TBox, 4);
      foundbox->next = NULL;
      return foundbox;
    }
    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;
}
Ejemplo n.º 7
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;
}
Ejemplo n.º 8
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;
}