Esempio n. 1
0
int
ht_insert_uniqmap (TCADB * adb, char *uniq_key)
{
  void *value_ptr;
  int nkey = 0, size = 0;

  if ((adb == NULL) || (uniq_key == NULL))
    return (EINVAL);

  if ((value_ptr = tcadbget2 (adb, uniq_key)) != NULL) {
    free (value_ptr);
    return 0;
  }

  size = get_ht_size (adb);
  /* the auto increment value starts at SIZE (hash table) + 1 */
  nkey = size > 0 ? size + 1 : 1;

  if (!tcadbput (adb, uniq_key, strlen (uniq_key), &nkey, sizeof (int)))
    LOG_DEBUG (("Unable to tcadbput\n"));

  free (uniq_key);

  return nkey;
}
Esempio n. 2
0
char *
get_hostname (const char *host)
{
  void *value_ptr;

  value_ptr = tcadbget2 (ht_hostnames, host);
  if (value_ptr)
    return value_ptr;
  return NULL;
}
Esempio n. 3
0
static PyObject *
get(PyObject *self,PyObject *args){
    char *value;
    const char *dbname;
    const char *key;
    if (!PyArg_ParseTuple(args, "ss", &dbname, &key))
        return NULL;
    TCADB *adb = openadb(dbname);
    if (adb->omode==ADBOTDB)
        value = tctdbget3(adb->tdb,key);
    else
        value = tcadbget2(adb, key);
    closeadb(adb);
    return Py_BuildValue("s",value);
}
Esempio n. 4
0
int
ht_insert_keymap (TCADB * adb, const char *value)
{
  void *value_ptr;
  int nkey = 0, size = 0, ret = 0;

  if ((adb == NULL) || (value == NULL))
    return (EINVAL);

  if ((value_ptr = tcadbget2 (adb, value)) != NULL) {
    ret = (*(int *) value_ptr);
    free (value_ptr);
    return ret;
  }

  size = get_ht_size (adb);
  /* the auto increment value starts at SIZE (hash table) + 1 */
  nkey = size > 0 ? size + 1 : 1;

  tcadbput (adb, value, strlen (value), &nkey, sizeof (int));

  return nkey;
}