Пример #1
0
int db_get_dbvalue(void *vhandle, const dbv_t *token, /*@out@*/ dbv_t *val)
{
    char *data;
    int dsiz;

    dbh_t *handle = vhandle;
    VILLA *dbp = handle->dbp;

    data = vlget(dbp, token->data, token->leng, &dsiz);

    if (data == NULL)
	return DS_NOTFOUND;

    if (val->leng < (unsigned)dsiz) {
	print_error(__FILE__, __LINE__,
		    "(qdbm) db_get_dbvalue( '%.*s' ), size error %lu: %lu",
		    CLAMP_INT_MAX(token->leng),
		    (char *)token->data, (unsigned long)val->leng,
		    (unsigned long)dsiz);
	exit(EX_ERROR);
    }

    val->leng = dsiz;		/* read count */
    memcpy(val->data, data, dsiz);

    free(data); /* not xfree() as allocated by vlget() */

    return 0;
}
Пример #2
0
void *
mutt_hcache_fetch_raw (header_cache_t *h, const char *filename,
                       size_t(*keylen) (const char *fn))
{
#ifndef HAVE_DB4
  char path[_POSIX_PATH_MAX];
  int ksize;
#endif
#ifdef HAVE_QDBM
  char *data = NULL;
#elif HAVE_TC
  void *data;
  int sp;
#elif HAVE_GDBM
  datum key;
  datum data;
#elif HAVE_DB4
  DBT key;
  DBT data;
#endif
  
  if (!h)
    return NULL;
  
#ifdef HAVE_DB4
  if (filename[0] == '/')
    filename++;

  mutt_hcache_dbt_init(&key, (void *) filename, keylen(filename));
  mutt_hcache_dbt_empty_init(&data);
  data.flags = DB_DBT_MALLOC;
  
  h->db->get(h->db, NULL, &key, &data, 0);
  
  return data.data;
#else
  strncpy(path, h->folder, sizeof (path));
  safe_strcat(path, sizeof (path), filename);

  ksize = strlen (h->folder) + keylen (path + strlen (h->folder));  
#endif
#ifdef HAVE_QDBM
  data = vlget(h->db, path, ksize, NULL);
  
  return data;
#elif HAVE_TC
  data = tcbdbget(h->db, path, ksize, &sp);

  return data;
#elif HAVE_GDBM
  key.dptr = path;
  key.dsize = ksize;
  
  data = gdbm_fetch(h->db, key);
  
  return data.dptr;
#endif
}
Пример #3
0
ValuePointer JsonDb::Transaction::Retrieve(ValueKey key)
{
	if(key == null_key)
		return null_element;

	// std::cout << "Retrieve: key=" << key << std::endl;

	// Then retrieve the actual data
	int value_size;
	CharPtr val = CharPtr(vlget(db.get(), (char const *)&key, sizeof(ValueKey), &value_size));

	if(val.get() == NULL)
		return ValuePointer();

	if(value_size <= 0)
		throw std::runtime_error((boost::format("Element has an invalid size: %d") % key).str().c_str());

	std::string val_str(val.get(), value_size);
	std::istringstream input(val_str);
	ValuePointer result = Value::Unserialize(key, input);	

	return result;
}
Пример #4
0
Файл: test.c Проект: ADTSH/io
int main(void)
{
	VILLA *villa;
	int size;
	char *s;
	
	printf("compareFunc(\"a\", \"b\") = %i\n", compareFunc("a", 1, "b", 1));
	printf("compareFunc(\"b\", \"a\") = %i\n", compareFunc("b", 1, "a", 1));
	printf("compareFunc(\"a\", \"a\") = %i\n", compareFunc("a", 1, "a", 1));
	printf("compareFunc(\"b\", \"b\") = %i\n", compareFunc("b", 1, "b", 1));
	
	remove("test.qdbm");
	
	if(!(villa = vlopen("test.qdbm", VL_OWRITER | VL_OCREAT, compareFunc)))
	{
		printf("vlopen failed %s\n", dperrmsg(dpecode));
		return 1;
	}

	if(!vltranbegin(villa))
	{
		printf("vltranbegin failed %s\n", dperrmsg(dpecode));
		return 1;	
	}
		
	if(!vlput(villa, "a", 1, "1", 1, DP_DOVER))
	{
		printf("vlput failed %s\n", dperrmsg(dpecode));
		return 1;
	}
	
	if(!vlput(villa, "b", 1, "2", 1, DP_DOVER))
	{
		printf("vlput failed %s\n", dperrmsg(dpecode));
		return 1;
	}
	
	if(!vltrancommit(villa))
	{
		printf("vltrancommit failed %s\n", dperrmsg(dpecode));
		return 1;	
	}
	
	if(!vlclose(villa))
	{
		printf("vlclose failed %s\n", dperrmsg(dpecode));
		return 1;
	}
	
	if(!(villa = vlopen("test.qdbm", VL_OWRITER | VL_OCREAT, compareFunc)))
	{
		printf("vlopen failed %s\n", dperrmsg(dpecode));
		return 1;
	}
	
	s = vlget(villa, "a", 1, &size);
	printf("a = '%s'\n", s ? s : "NULL");

	s = vlget(villa, "b", 1, &size);
	printf("b = '%s'\n", s ? s : "NULL");

	if(!vlclose(villa))
	{
		printf("vlclose failed %s\n", dperrmsg(dpecode));
		return 1;
	}
		
	return 0;
}