/* perform import command */ int doimport(const char *name, int bnum, int bin){ DEPOT *depot; char *buf, *kbuf, *vbuf, *ktmp, *vtmp; int i, err, ktsiz, vtsiz; /* open a database */ if(!(depot = dpopen(name, DP_OWRITER | DP_OCREAT, bnum))){ pdperror(name); return 1; } /* loop for each line */ err = FALSE; for(i = 1; (buf = getl()) != NULL; i++){ kbuf = buf; if((vbuf = strchr(buf, '\t')) != NULL){ *vbuf = '\0'; vbuf++; /* store a record */ if(bin){ ktmp = cbbasedecode(kbuf, &ktsiz); vtmp = cbbasedecode(vbuf, &vtsiz); if(!dpput(depot, ktmp, ktsiz, vtmp, vtsiz, DP_DOVER)){ pdperror(name); err = TRUE; } free(vtmp); free(ktmp); } else { if(!dpput(depot, kbuf, -1, vbuf, -1, DP_DOVER)){ pdperror(name); err = TRUE; } } } else { fprintf(stderr, "%s: %s: invalid format in line %d\n", progname, name, i); } free(buf); if(err) break; } /* close the database */ if(!dpclose(depot)){ pdperror(name); return 1; } return err ? 1 : 0; }
static VALUE minidb_set(VALUE self, VALUE key, VALUE val) { DEPOT *db; Data_Get_Struct(self, DEPOT, db); StringValue(key); StringValue(val); if (!dpput(db, RSTRING_PTR(key), RSTRING_LEN(key), RSTRING_PTR(val), RSTRING_LEN(val), DP_DOVER)) { rb_raise(rb_eRuntimeError, "dpput failed"); } return val; }
bool DBPrivWrite(DBPriv *db, const void *key, int key_size, const void *value, int value_size) { if (!Lock(db)) { return false; } if (!dpput(db->depot, key, key_size, value, value_size, DP_DOVER)) { char *db_name = dpname(db->depot); Log(LOG_LEVEL_ERR, "Could not write key to DB '%s'. (dpput: %s)", db_name, dperrmsg(dpecode)); free(db_name); Unlock(db); return false; } Unlock(db); return true; }
/* Store a record. */ int gdbm_store(GDBM_FILE dbf, datum key, datum content, int flag){ int dmode; assert(dbf); if(!key.dptr || key.dsize < 0 || !content.dptr || content.dsize < 0){ gdbm_errno = GDBM_ILLEGAL_DATA; return -1; } if(dbf->depot){ if(!dpwritable(dbf->depot)){ gdbm_errno = GDBM_READER_CANT_STORE; return -1; } dmode = (flag == GDBM_INSERT) ? DP_DKEEP : DP_DOVER; if(!dpput(dbf->depot, key.dptr, key.dsize, content.dptr, content.dsize, dmode)){ gdbm_errno = gdbm_geterrno(dpecode); if(dpecode == DP_EKEEP) return 1; return -1; } if(dbf->syncmode && !dpsync(dbf->depot)){ gdbm_errno = gdbm_geterrno(dpecode); return -1; } } else { if(!crwritable(dbf->curia)){ gdbm_errno = GDBM_READER_CANT_STORE; return -1; } dmode = (flag == GDBM_INSERT) ? CR_DKEEP : CR_DOVER; if(!crput(dbf->curia, key.dptr, key.dsize, content.dptr, content.dsize, dmode)){ gdbm_errno = gdbm_geterrno(dpecode); if(dpecode == DP_EKEEP) return 1; return -1; } if(dbf->syncmode && !crsync(dbf->curia)){ gdbm_errno = gdbm_geterrno(dpecode); return -1; } } return 0; }
/* Initialize the root directory. */ int master_init(const char *rootdir){ DEPOT *depot; FILE *ofp; char path[URIBUFSIZ]; int err; assert(rootdir); if(est_mkdir(rootdir) == -1 && errno != EEXIST) return FALSE; err = FALSE; sprintf(path, "%s%c%s", rootdir, ESTPATHCHR, METAFILE); if((depot = dpopen(path, DP_OWRITER | DP_OCREAT | DP_OTRUNC, MINIBNUM))){ if(!dpput(depot, MMKMAGIC, -1, MMKMAGVAL, -1, DP_DKEEP)) err = TRUE; if(!dpclose(depot)) err = TRUE; } else { err = TRUE; } sprintf(path, "%s%c%s", rootdir, ESTPATHCHR, CONFFILE); if((ofp = fopen(path, "wb")) != NULL){ fprintf(ofp, "# binding address of TCP (0.0.0.0 means every address)\n"); fprintf(ofp, "bindaddr: 0.0.0.0\n"); fprintf(ofp, "\n"); fprintf(ofp, "# port number of TCP\n"); fprintf(ofp, "portnum: 1978\n"); fprintf(ofp, "\n"); fprintf(ofp, "# public URL (absolute URL)\n"); fprintf(ofp, "publicurl:\n"); fprintf(ofp, "\n"); fprintf(ofp, "# running mode (1:normal, 2:readonly)\n"); fprintf(ofp, "runmode: 1\n"); fprintf(ofp, "\n"); fprintf(ofp, "# authorization mode (1:none, 2:admin, 3:all)\n"); fprintf(ofp, "authmode: 2\n"); fprintf(ofp, "\n"); fprintf(ofp, "# maximum length of data to receive (in kilobytes)\n"); fprintf(ofp, "recvmax: 1024\n"); fprintf(ofp, "\n"); fprintf(ofp, "# maximum number of connections at the same time\n"); fprintf(ofp, "maxconn: 30\n"); fprintf(ofp, "\n"); fprintf(ofp, "# idle time to start flushing (in seconds)\n"); fprintf(ofp, "idleflush: 20\n"); fprintf(ofp, "\n"); fprintf(ofp, "# idle time to start synchronizing (in seconds)\n"); fprintf(ofp, "idlesync: 300\n"); fprintf(ofp, "\n"); fprintf(ofp, "# timeout of a session (in seconds)\n"); fprintf(ofp, "sessiontimeout: 600\n"); fprintf(ofp, "\n"); fprintf(ofp, "# timeout of search (in seconds)\n"); fprintf(ofp, "searchtimeout: 15\n"); fprintf(ofp, "\n"); fprintf(ofp, "# maximum number of documents to send\n"); fprintf(ofp, "searchmax: 1000\n"); fprintf(ofp, "\n"); fprintf(ofp, "# maximum depth of meta search\n"); fprintf(ofp, "searchdepth: 5\n"); fprintf(ofp, "\n"); fprintf(ofp, "# whether to rate URI for scoring (0:no, 1:yes)\n"); fprintf(ofp, "rateuri: 1\n"); fprintf(ofp, "\n"); fprintf(ofp, "# merge method of meta search (1:score, 2:score and rank, 3:rank)\n"); fprintf(ofp, "mergemethod: 2\n"); fprintf(ofp, "\n"); fprintf(ofp, "# host name of the proxy\n"); fprintf(ofp, "proxyhost:\n"); fprintf(ofp, "\n"); fprintf(ofp, "# port number of the proxy\n"); fprintf(ofp, "proxyport:\n"); fprintf(ofp, "\n"); fprintf(ofp, "# path of the log file (relative path or absolute path)\n"); fprintf(ofp, "logfile: %s\n", LOGFILE); fprintf(ofp, "\n"); fprintf(ofp, "# logging level (1:debug, 2:information, 3:warning, 4:error, 5:none)\n"); fprintf(ofp, "loglevel: 2\n"); fprintf(ofp, "\n"); fprintf(ofp, "# command for backup (absolute path of a command)\n"); fprintf(ofp, "backupcmd:\n"); fprintf(ofp, "\n"); fprintf(ofp, "# scale prediction (1:small, 2:medium, 3:large, 4:huge)\n"); fprintf(ofp, "scalepred: 2\n"); fprintf(ofp, "\n"); fprintf(ofp, "# score expression (1:void, 2:char, 3:int, 4:asis)\n"); fprintf(ofp, "scoreexpr: 2\n"); fprintf(ofp, "\n"); fprintf(ofp, "# attribute indexes (attribute name and data type)\n"); fprintf(ofp, "attrindex: @mdate{{!}}seq\n"); fprintf(ofp, "attrindex: @title{{!}}str\n"); fprintf(ofp, "\n"); fprintf(ofp, "# document root directory (absolute path of a directory to be public)\n"); fprintf(ofp, "docroot:\n"); fprintf(ofp, "\n"); fprintf(ofp, "# index file (name of directory index files)\n"); fprintf(ofp, "indexfile:\n"); fprintf(ofp, "\n"); fprintf(ofp, "# decimal IP addresses of trusted nodes\n"); fprintf(ofp, "trustednode:\n"); fprintf(ofp, "\n"); fprintf(ofp, "# whether to deny all nodes except for trusted nodes (0:no, 1:yes)\n"); fprintf(ofp, "denyuntrusted: 0\n"); fprintf(ofp, "\n"); fprintf(ofp, "# maximum size of the index cache (in megabytes)\n"); fprintf(ofp, "cachesize: 64\n"); fprintf(ofp, "\n"); fprintf(ofp, "# maximum number of cached records for document attributes\n"); fprintf(ofp, "cacheanum: 8192\n"); fprintf(ofp, "\n"); fprintf(ofp, "# maximum number of cached records for document texts\n"); fprintf(ofp, "cachetnum: 1024\n"); fprintf(ofp, "\n"); fprintf(ofp, "# maximum number of cached records for occurrence results\n"); fprintf(ofp, "cachernum: 256\n"); fprintf(ofp, "\n"); fprintf(ofp, "# name of the attribute of the special cache\n"); fprintf(ofp, "specialcache:\n"); fprintf(ofp, "\n"); fprintf(ofp, "# lower limit of cache usage to use the helper\n"); fprintf(ofp, "helpershift: 0.9\n"); fprintf(ofp, "\n"); fprintf(ofp, "# maximum number of expansion of wild cards\n"); fprintf(ofp, "wildmax: 256\n"); fprintf(ofp, "\n"); fprintf(ofp, "# text size limitation of indexing documents (in kilobytes)\n"); fprintf(ofp, "limittextsize: 128\n"); fprintf(ofp, "\n"); fprintf(ofp, "# whole width of the snippet of each shown document\n"); fprintf(ofp, "snipwwidth: 480\n"); fprintf(ofp, "\n"); fprintf(ofp, "# width of strings picked up from the beginning of the text\n"); fprintf(ofp, "sniphwidth: 96\n"); fprintf(ofp, "\n"); fprintf(ofp, "# width of strings picked up around each highlighted word\n"); fprintf(ofp, "snipawidth: 96\n"); fprintf(ofp, "\n"); fprintf(ofp, "# whether to check documents by scanning (0:no, 1:yes)\n"); fprintf(ofp, "scancheck: 1\n"); fprintf(ofp, "\n"); fprintf(ofp, "# number of keywords for similarity search (0 means disabled)\n"); fprintf(ofp, "smlrvnum: 32\n"); fprintf(ofp, "\n"); fprintf(ofp, "# number of documents for delay of keyword extraction\n"); fprintf(ofp, "extdelay: 4096\n"); fprintf(ofp, "\n"); fprintf(ofp, "# e-mail address of the administrator\n"); fprintf(ofp, "adminemail: [email protected]\n"); fprintf(ofp, "\n"); fprintf(ofp, "# expressions to replace the URI of each document\n"); fprintf(ofp, "uireplace: ^file:///home/mikio/public_html/{{!}}http://localhost/\n"); fprintf(ofp, "uireplace: /index\\.html?${{!}}/\n"); fprintf(ofp, "\n"); fprintf(ofp, "# extra attributes to be shown\n"); fprintf(ofp, "uiextattr: @author|Author\n"); fprintf(ofp, "uiextattr: @mdate|Modification Date\n"); fprintf(ofp, "\n"); fprintf(ofp, "# mode of phrase form" " (1:usual, 2:simplified, 3:rough, 4:union: 5:intersection)\n"); fprintf(ofp, "uiphraseform: 2\n"); fprintf(ofp, "\n"); fprintf(ofp, "# tuning parameters for similarity search\n"); fprintf(ofp, "uismlrtune: 16 1024 4096\n"); fprintf(ofp, "\n"); if(fclose(ofp) == EOF) err = TRUE; } else { err = TRUE; } sprintf(path, "%s%c%s", rootdir, ESTPATHCHR, PIDFILE); unlink(path); sprintf(path, "%s%c%s", rootdir, ESTPATHCHR, STOPFILE); unlink(path); sprintf(path, "%s%c%s", rootdir, ESTPATHCHR, USERFILE); if((ofp = fopen(path, "wb")) != NULL){ if(fclose(ofp) == EOF) err = TRUE; } else { err = TRUE; } sprintf(path, "%s%c%s", rootdir, ESTPATHCHR, LOGFILE); if((ofp = fopen(path, "wb")) != NULL){ if(fclose(ofp) == EOF) err = TRUE; } else { err = TRUE; } sprintf(path, "%s%c%s", rootdir, ESTPATHCHR, NODEDIR); est_rmdir_rec(path); if(est_mkdir(path) == -1) err = TRUE; sprintf(path, "%s%c%s", rootdir, ESTPATHCHR, SESSDIR); est_rmdir_rec(path); if(est_mkdir(path) == -1) err = TRUE; return err ? FALSE : TRUE; }
int main(int argc, char *argv[]) { DEPOT *dbmap = NULL; char *str_prefix = "dbbm_key_prefix_"; char *key, keystr[24]; unsigned long i; int rc = 0; PDUMMY_DATA datap; if (argc < 3) { fprintf(stderr, "Usage : <prog> <dbpath> <datasize>\n"); exit(1); } dbmap = dpopen(argv[1], DP_OWRITER|DP_OCREAT|DP_OSPARSE|DP_ONOLCK, -1); if (!dbmap) { fprintf(stderr, "Unable to open the dbbm file \n"); exit(1); } datap = (PDUMMY_DATA) malloc(sizeof(DUMMY_DATA)); if (!datap) { fprintf(stderr, "Malloc error %s\n", strerror(errno)); exit(1); } unsigned long datasize = strtoul(argv[2], NULL, 10); // push data for (i = 0; i < datasize; i++) { asprintf(keystr, "%s%lu", str_prefix, i); datap->x = i; datap->y = i+1; datap->z = i+2; if (!dpput(dbmap, keystr, strlen(keystr), (char *) datap, sizeof(DUMMY_DATA), DP_DOVER)) { fprintf(stderr, "Unable to insert to qdbm\n"); }; } if(!dpclose(dbmap)){ fprintf(stderr, "dpclose: %s\n", dperrmsg(dpecode)); return 1; } //read data dbmap = dpopen(argv[1], DP_OREADER, -1); if (!dbmap) { fprintf(stderr, "Unable to open the dbbm file \n"); exit(1); } fprintf(stdout, "Starting read of the database sequentially\n"); if(!dpiterinit(dbmap)){ fprintf(stderr, "dpiterinit: %s\n", dperrmsg(dpecode)); } /* scan with the iterator */ while ((key = dpiternext(dbmap, NULL)) != NULL) { if (!(datap = (PDUMMY_DATA) dpget(dbmap, key, -1, 0, sizeof(DUMMY_DATA), NULL))) { fprintf(stderr, "Value is not found for key %s\n", key); fprintf(stderr, "dpget: %s\n", dperrmsg(dpecode)); free(key); break; } /* fprintf(stdout, "Data read for dbm : x=%lu y=%lu z=%lu\n", datap->x, datap->y, datap->z);*/ free(datap); } fprintf(stdout, "End of the database reached\n"); if(!dpclose(dbmap)){ fprintf(stderr, "dpclose: %s\n", dperrmsg(dpecode)); return 1; } return 0; }