Example #1
0
void Retsu::Column::lookup(const RIDList& keys, vector<double>& results) {
  results.reserve(keys.size());

  double buffer;
  RIDList::const_iterator key;
  for(key = keys.begin(); key != keys.end(); key++) {
    if(tchdbget3(database, &(*key), sizeof(RecordID), &buffer, sizeof(double)) != -1) {
      results.push_back(buffer);
    }
  }  
}
Example #2
0
bool DBPrivRead(DBPriv *db, const void *key, int key_size, void *dest, int dest_size)
{
    if (tchdbget3(db->hdb, key, key_size, dest, dest_size) == -1)
    {
        if (tchdbecode(db->hdb) != TCENOREC)
        {
            Log(LOG_LEVEL_ERR, "Could not read key '%s': (tchdbget3: %s)", (const char *)key, ErrorMessage(db->hdb));
        }
        return false;
    }

    return true;
}
Example #3
0
bool DBPrivRead(DBPriv *db, const void *key, int key_size, void *dest, int dest_size)
{
    if (tchdbget3(db->hdb, key, key_size, dest, dest_size) == -1)
    {
        if (tchdbecode(db->hdb) != TCENOREC)
        {
            CfOut(cf_error, "", "ReadComplexKeyDB(%s): Could not read: %s\n", (const char *)key, ErrorMessage(db->hdb));
        }
        return false;
    }

    return true;
}
Example #4
0
char *get_host_pubkey(char *host) {
	char *key;
	char value[BUFSIZE];
	char *buffer = (char *) malloc(BUFSIZE *sizeof(char));
	char *keyname = NULL;
	char needle[BUFSIZE];
	TCHDB *hdb;
  hdb = tchdbnew();
	int ecode;
	struct addrinfo *result;
	struct addrinfo *res;

	if(tchdbopen(hdb,LASTSEEN_DB,HDBOREADER) != 1){
		printf("%s for database '%s'\n",tchdberrmsg(tchdbecode(hdb)),LASTSEEN_DB);
		return NULL;
	}
	int error = getaddrinfo(host,NULL,NULL,&result);

	for(res = result; res != NULL; res = res->ai_next) {
		inet_ntop(res->ai_family, get_in_addr((struct sockaddr *)res->ai_addr), needle, sizeof(needle));

		tchdbiterinit(hdb);
		while((key = tchdbiternext2(hdb)) != NULL && keyname == NULL){
			if(strspn(key,"k") == 1){
				tchdbget3(hdb, key, strlen(key) + 1, value, BUFSIZE);
				if(strcmp(value,needle) == 0){
					keyname = ++key;
				}
			}
		}
	}
	tchdbclose(hdb);

	if(keyname) {
		sprintf(buffer,"%s/root-%s.pub",PPKEYS,keyname);
		return buffer;
	}else{
		for(res = result; res != NULL; res = res->ai_next) {
			inet_ntop(res->ai_family, get_in_addr((struct sockaddr *)res->ai_addr), needle, sizeof(needle));
			sprintf(buffer,"%s/root-%s.pub",PPKEYS,needle);
			if(file_exist(buffer)){
				return buffer;
			}
		}
	}
	return NULL;
}
Example #5
0
/** 
 * get a record from database 
 */
int GetRecord(tcDatabase hdb, tcKey key, tcValue *pvalue)
{
    int ecode;
    int ret;

    ret = tchdbget3(hdb, &key, sizeof(tcKey), pvalue->str, pvalue->len);
    //printf("%d\n", ret);
    if(ret != -1)
    {
        pvalue->str[ret] = '\0';
        pvalue->len = ret;
        return SUCCESS;
    }	
    ecode = tchdbecode(hdb);
    fprintf(stderr, "get error: %s\n", tchdberrmsg(ecode));
    
    return FAILURE;  
}
Example #6
0
/* perform read command */
int doread(char *name, int rnum){
  TCHDB *hdb;
  int i, err, len;
  char buf[RECBUFSIZ], vbuf[RECBUFSIZ];
  if(showprgr) printf("<Reading Test of Hash>\n  name=%s  rnum=%d\n\n", name, rnum);
  /* open a database */
  hdb = tchdbnew();
  tchdbsetxmsiz(hdb, rnum * 48);
  if(!tchdbopen(hdb, name, HDBOREADER)){
    fprintf(stderr, "tchdbopen failed\n");
    tchdbdel(hdb);
    return 1;
  }
  err = FALSE;
  /* loop for each record */
  for(i = 1; i <= rnum; i++){
    /* store a record */
    len = sprintf(buf, "%08d", i);
    if(tchdbget3(hdb, buf, len, vbuf, RECBUFSIZ) == -1){
      fprintf(stderr, "tchdbget3 failed\n");
      err = TRUE;
      break;
    }
    /* print progression */
    if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
      putchar('.');
      fflush(stdout);
      if(i == rnum || i % (rnum / 10) == 0){
        printf(" (%08d)\n", i);
        fflush(stdout);
      }
    }
  }
  /* close the database */
  if(!tchdbclose(hdb)){
    fprintf(stderr, "tchdbclose failed\n");
    tchdbdel(hdb);
    return 1;
  }
  tchdbdel(hdb);
  if(showprgr && !err) printf("ok\n\n");
  return err ? 1 : 0;
}
Example #7
0
      bool get(
         void const * pkey, size_t const ksize,
         void * pval, size_t & vsize
         )
      {
         assert_data_store_open();

         int const esize = tchdbget3(pdb_, pkey, ksize, pval, boost::numeric_cast<int>(vsize));
         bool found = (esize >= 0);

         if(found)
         {
            vsize = std::min(vsize, (size_t) esize);
         }
         else
         {
            vsize = 0;
         }

         return found;
      }