コード例 #1
0
ファイル: dbtest.cpp プロジェクト: teloon/simpleDDD
/*#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
*/
int main(int argc, char **argv){

TCHDB *hdb;
char *key, *value; 

/* create the object */
hdb = tchdbnew();

/* open the database */
if(!tchdbopen(hdb, "teloon.hdb", HDBOWRITER|HDBOTRUNC)){
	fprintf(stderr, "open error\n");
}

/* store records */
if(!tchdbput2(hdb, "foo", "hop") ||
!tchdbput2(hdb, "barz", "step") ||
!tchdbput2(hdb, "ssss", "jump")){
fprintf(stderr, "put error\n");
}

/* retrieve records */
value = tchdbget2(hdb, "foo");
if(value){
printf("%s\n", value);
free(value);
} else {
fprintf(stderr, "get error\n");
}

/* traverse records */
tchdbiterinit(hdb);
while((key = tchdbiternext2(hdb)) != NULL){
value = tchdbget2(hdb, key);
if(value){
printf("%s:%s\n", key, value);
free(value);
}
free(key);
}
tchdbiterinit(hdb);
while((key = tchdbiternext2(hdb)) != NULL){
value = tchdbget2(hdb, key);
if(value){
printf("%s:%s\n", key, value);
free(value);
}
free(key);
}

/* close the database */
if(!tchdbclose(hdb)){
fprintf(stderr, "close error\n");
}

/* delete the object */
tchdbdel(hdb);

return 0;
} 
コード例 #2
0
ファイル: lessfsck.c プロジェクト: crass/lessfs
void purge_dbb_beyond(INOBNO *inobno)
{
    char *asc_hash = NULL;
    char *key, *value;
    int size;
    int vsize;
    INOBNO inobnocur;

    printf("purge_dbb_beyond : purge fileblock metadata after blocknr %llu\n",inobno->blocknr);
    /* traverse records */
    tchdbiterinit(dbb);
    while ((key = tchdbiternext(dbb, &size)) != NULL) {
        value = tchdbget(dbb, key, size, &vsize);
        memcpy(&inobnocur.inode, key, sizeof(unsigned long long));
        memcpy(&inobnocur.blocknr, key + sizeof(unsigned long long),
               sizeof(unsigned long long));
        if ( inobno->inode == inobnocur.inode ) {
           if ( inobnocur.blocknr > inobno->blocknr ) {
              printf("delete reference %llu-%llu\n",inobnocur.inode,inobnocur.blocknr);
              tchdbout(dbb,&inobnocur,sizeof(INOBNO));
// Verify dbu in this case.
           }
        }
        free(asc_hash);
        free(value);
        free(key);
    }
}
コード例 #3
0
ファイル: tchmgr.c プロジェクト: kadoma/fms
/* perform list command */
static int proclist(const char *path, int omode, bool pv, bool px){
  TCHDB *hdb = tchdbnew();
  if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
  if(!tchdbopen(hdb, path, HDBOREADER | omode)){
    printerr(hdb);
    tchdbdel(hdb);
    return 1;
  }
  bool err = false;
  if(!tchdbiterinit(hdb)){
    printerr(hdb);
    err = true;
  }
  TCXSTR *key = tcxstrnew();
  TCXSTR *val = tcxstrnew();
  while(tchdbiternext3(hdb, key, val)){
    printdata(tcxstrptr(key), tcxstrsize(key), px);
    if(pv){
      putchar('\t');
      printdata(tcxstrptr(val), tcxstrsize(val), px);
    }
    putchar('\n');
  }
  tcxstrdel(val);
  tcxstrdel(key);
  if(!tchdbclose(hdb)){
    if(!err) printerr(hdb);
    err = true;
  }
  tchdbdel(hdb);
  return err ? 1 : 0;
}
コード例 #4
0
ファイル: tcfiler.c プロジェクト: wix/tcfiler
int unpack_files(char *root_dir, bool verbose, bool test) {

    char *key;
    void *value;
    int fd, count, key_size, val_size;


    /* traverse records */
    count = 0;
    tchdbiterinit(hdb);
    while ((key = tchdbiternext2(hdb)) != NULL) {
        key_size = (int) strlen(key);

        if (verbose || test) fprintf(stdout, "Extracting file: %s\n", key);

        value = tchdbget(hdb, key, key_size, &val_size);
        if (value && !test) {
            if (-1 == (fd = open(key, O_WRONLY | O_CREAT | O_TRUNC, 0644))) {
                fprintf(stdout, "***Failed open file %s\n", key);
                return 1;
            }

            write(fd, value, val_size);
            close(fd);
            free(value);
        }
        free(key);
        count++;
    }

    return count;
}
コード例 #5
0
ファイル: lessfsck.c プロジェクト: crass/lessfs
void check_inodes()
{
    char *key, *value;
    int size;
    int ksize;
    DDSTAT *ddstat;
    DBT *data;
    unsigned long long inode;
    char *nfi = "NFI";
    CRYPTO *crypto;
    struct stat stbuf;
    char *blockdatadir;

    if (NULL == config->blockdatabs) {
        blockdatadir = s_dirname(config->blockdata);
        stat(blockdatadir, &stbuf);
        free(blockdatadir);
    } else {
        stat(config->blockdata, &stbuf);
    }
    /* traverse records */
    tchdbiterinit(dbp);
    while ((key = tchdbiternext(dbp, &ksize)) != NULL) {
        show_progress();
        if (0 == memcmp(key, nfi, 3)) {
            value = tchdbget(dbp, key, strlen(key), &size);
            memcpy(&inode, value, sizeof(unsigned long long));
            free(value);
        } else {
            memcpy(&inode, key, sizeof(unsigned long long));
            data = search_dbdata(dbp, &inode, sizeof(unsigned long long));
            if (inode == 0) {
                crypto = (CRYPTO *) data->data;
            } else {
                ddstat = value_to_ddstat(data);
                if ( 0 == check_inode_orphaned(ddstat)) {
                   if (S_ISREG(ddstat->stbuf.st_mode)) {
                      if ( NULL != config->blockdatabs ) { 
                        check_inode_structure(ddstat);   
                      } else {
                        file_check_inode_structure(ddstat);   
                      }    
                   }
                } else {
                   printf("Deleting corrupted inode %llu\n",(unsigned long long)ddstat->stbuf.st_ino);
                   search_and_delete_dbdirent(ddstat);
                   delete_key(dbp, key, ksize);
                }
                ddstatfree(ddstat);
            }
            DBTfree(data);
        }
        free(key);
    }

}
コード例 #6
0
ファイル: tchmgr.c プロジェクト: Fleurer/nanodb
/* perform list command */
static int proclist(const char *path, int omode, int max, bool pv, bool px, const char *fmstr){
  TCHDB *hdb = tchdbnew();
  if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
  if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(hdb);
  if(!tchdbopen(hdb, path, HDBOREADER | omode)){
    printerr(hdb);
    tchdbdel(hdb);
    return 1;
  }
  bool err = false;
  if(fmstr){
    TCLIST *keys = tchdbfwmkeys2(hdb, fmstr, max);
    for(int i = 0; i < tclistnum(keys); i++){
      int ksiz;
      const char *kbuf = tclistval(keys, i, &ksiz);
      printdata(kbuf, ksiz, px);
      if(pv){
        int vsiz;
        char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
        if(vbuf){
          putchar('\t');
          printdata(vbuf, vsiz, px);
          tcfree(vbuf);
        }
      }
      putchar('\n');
    }
    tclistdel(keys);
  } else {
    if(!tchdbiterinit(hdb)){
      printerr(hdb);
      err = true;
    }
    TCXSTR *key = tcxstrnew();
    TCXSTR *val = tcxstrnew();
    int cnt = 0;
    while(tchdbiternext3(hdb, key, val)){
      printdata(tcxstrptr(key), tcxstrsize(key), px);
      if(pv){
        putchar('\t');
        printdata(tcxstrptr(val), tcxstrsize(val), px);
      }
      putchar('\n');
      if(max >= 0 && ++cnt >= max) break;
    }
    tcxstrdel(val);
    tcxstrdel(key);
  }
  if(!tchdbclose(hdb)){
    if(!err) printerr(hdb);
    err = true;
  }
  tchdbdel(hdb);
  return err ? 1 : 0;
}
コード例 #7
0
ファイル: kvds_tch_linux.hpp プロジェクト: 1901/libmoost
      bool beg()
      {
         assert_data_store_open();
         bool bOk = tchdbiterinit(pdb_);

         if(bOk)
         {
            set_next_itr();
         }

         return bOk;
      }
コード例 #8
0
ファイル: lessfsck.c プロジェクト: crass/lessfs
void check_orphaned_data_blocks()
{
    char *key;

    /* traverse records */
    tchdbiterinit(dbdta);
    while ((key = tchdbiternext2(dbdta)) != NULL) {
        if ( 0 == check_inuse((unsigned char *)key)) {
           printhash("Deleting orphaned hash",(unsigned char *)key);
           if (!tchdbout(dbdta, key, config->hashlen)) {
              die_syserr();
           }
        }
        free(key);
    }
}
コード例 #9
0
ファイル: cf-keycrypt.c プロジェクト: svamberg/cf-keycrypt
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;
}
コード例 #10
0
ファイル: tokyo.c プロジェクト: aleeehaider825/hachi-roku
static int
_tc_firstkey (mu_dbm_file_t db, struct mu_dbm_datum *ret)
{
  TCHDB *hdb = db->db_descr;
  void *ptr;
  int retsize;

  tchdbiterinit (hdb);
  ptr = tchdbiternext (hdb, &retsize);
  if (ptr)
    {
      mu_dbm_datum_free (ret);
      ret->mu_dptr = ptr;
      ret->mu_dsize = retsize;
      return 0;
    }
  else if ((db->db_errno.n = tchdbecode (hdb)) == TCENOREC)
    return MU_ERR_NOENT;
  return MU_ERR_FAILURE;
}
コード例 #11
0
ファイル: db_obj.cpp プロジェクト: Quix0r/seeks
 bool db_obj_local::dbiterinit()
 {
   return tchdbiterinit(_hdb);
 }
コード例 #12
0
ファイル: hdb.c プロジェクト: alextsui05/tokyocabinet.ndk
/* iterinit */
JNIEXPORT jboolean JNICALL Java_tokyocabinet_HDB_iterinit
(JNIEnv *env, jobject self){
  TCHDB *hdb = (TCHDB *)(intptr_t)(*env)->GetLongField(env, self, hdb_fid_ptr);
  return tchdbiterinit(hdb);
}