Example #1
0
int add_cdb_key (struct cdb_make *cdb, char *key, char *data){
  uint32 h;
  char *tmpptr;
  if (cdb_make_addbegin(cdb,strlen(key),strlen(data)) == -1) {
    printf("error on cdb_make_addbegin)\n");
    return(-1);
  } 
  h = CDB_HASHSTART;
  
  for(tmpptr=key;*tmpptr!=0;++tmpptr) {
    if (buffer_PUTC(&cdb->b,*tmpptr) == -1) {
      printf("error in buffer_PUTC\n");
      return(-1);
    }
    h = cdb_hashadd(h,*tmpptr);
  }

  for(tmpptr=data;*tmpptr!=0;++tmpptr) {
    if (buffer_PUTC(&cdb->b,*tmpptr) == -1) {
      printf("error in buffer_PUTC\n");
      return(-1);
    }
  }
  if (cdb_make_addend(cdb,strlen(key),strlen(data),h) == -1) {
    printf("error in cdb_make_addend\n");
    return(-1);
  }
  return(0);
}
Example #2
0
uint32 cdb_hash(const unsigned char *buf,unsigned long int len) {
  uint32 h;

  h = CDB_HASHSTART;
  while (len) {
    h = cdb_hashadd(h,*buf);
    ++buf;
    --len;
  }
  return h;
}
Example #3
0
int make_cdb()
{
 FILE *fs;
 int fdout;
 char *key;
 char *data;
 char *tmpptr;
 static char input[MAX_LINE];
 uint32 h;


  if ( (fs = fopen(ClearFile,"r")) == NULL) {
    printf("Not building simcontrol.cdb file. No %s/simcontrol text file\n",
      CONTROLDIR);
    return(-1);
  }
 
  if ( (fdout = open(CdbTmpFile, O_CREAT | O_TRUNC | O_WRONLY)) < 0) {
     printf("error on open tmp file\n");
    return(-1);
  }

  if (cdb_make_start(&c,fdout) == -1) {
    printf("error on cdb_make_start\n");
    return(-1);
  } 

  while(fgets(input,sizeof(input), fs)!=NULL) { 

    if ( input[0] == ':' ) {
      key = "";
      data = strtok(&input[1],"\r\n");
    } else {
      key = strtok(input,TOKENS);
      if ( key == NULL ) continue;
      data = strtok(NULL,"\r\n");
    }

    if ( data == NULL ) data="";

    /*snprintf(key,sizeof(key),"%s", data);*/

    if (cdb_make_addbegin(&c,strlen(key),strlen(data)) == -1) {
      printf("error on cdb_make_addbegin)\n");
      return(-1);
    } 
    h = CDB_HASHSTART;
    
    for(tmpptr=key;*tmpptr!=0;++tmpptr) {
      if (buffer_PUTC(&c.b,*tmpptr) == -1) {
        printf("error in buffer_PUTC\n");
        return(-1);
      }
      h = cdb_hashadd(h,*tmpptr);
    }

    for(tmpptr=data;*tmpptr!=0;++tmpptr) {
      if (buffer_PUTC(&c.b,*tmpptr) == -1) {
        printf("error in buffer_PUTC\n");
        return(-1);
      }
    }
    if (cdb_make_addend(&c,strlen(key),strlen(data),h) == -1) {
      printf("error in cdb_make_addend\n");
      return(-1);
    }
  }
  if (cdb_make_finish(&c) == -1) {
    printf("error in cdb_make_finish\n"); 
    return(-1);
  }

  /*fprintf(fsout"\n");*/
  fclose(fs);
  close(fdout);

  if (rename(CdbTmpFile, CdbFile)==-1) {
    printf("error: could not rename %s to %s\n", CdbTmpFile, CdbFile);
    return(-1);
  }
  chmod(CdbFile, 0644);
  printf("simscan cdb file built. %s/simcontrol.cdb\n", CONTROLDIR);
  return(0);
}
Example #4
0
uint32 cdb_hash (char const *buf, unsigned int len)
{
  uint32 h = CDB_HASHSTART ;
  while (len--) h = cdb_hashadd(h, *buf++) ;
  return h ;
}
Example #5
0
ut32 cdb_hash(const char *buf, ut32 len) {
	ut32 h = CDB_HASHSTART;
	while (len--)
		h = cdb_hashadd (h, *buf++);
	return h;
}