示例#1
0
static void
_update_dynamic_handles(NVTable *self, NVRegistry *logmsg_nv_registry,
                        NVHandle *handles_to_update,
                        guint8 num_handles_to_update)
{
  guint16 i;
  NVHandle *updated_handles = g_new0(NVHandle, num_handles_to_update);
  NVDynValue* dyn_entries = nv_table_get_dyn_entries(self);

  for (i = 0; i < self->num_dyn_entries; i++)
    {
      NVHandle new_handle;
      NVDynValue *dyn_entry = &dyn_entries[i];
      const gchar *name = _get_entry_name(self, dyn_entry);

      if (!name)
        continue;

      new_handle = nv_registry_alloc_handle(logmsg_nv_registry, name);

      _set_updated_handle(dyn_entry, new_handle, handles_to_update, updated_handles, num_handles_to_update);
    }

  _copy_handles(handles_to_update, updated_handles, num_handles_to_update);

  qsort(dyn_entries, self->num_dyn_entries, sizeof(NVDynValue), _dyn_entry_cmp);
  g_free(updated_handles);
}
示例#2
0
static void
_update_indirect_entry(NVTable *self, NVRegistry *logmsg_nv_registry,
                       NVEntry* entry)
{
  NVHandle oh = entry->vindirect.handle;
  const gchar *name = nv_entry_get_name(entry);

  if (oh > self->num_static_entries)
    {
      _update_indirect_dynamic_entry(self, oh, name, entry, logmsg_nv_registry);
    }
  nv_registry_alloc_handle(logmsg_nv_registry, name);
}
示例#3
0
NVRegistry *
nv_registry_new(const gchar **static_names)
{
  NVRegistry *self = g_new0(NVRegistry, 1);
  gint i;

  self->name_map = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
  self->names = g_array_new(FALSE, FALSE, sizeof(NVHandleDesc));
  for (i = 0; static_names[i]; i++)
    {
      nv_registry_alloc_handle(self, static_names[i]);
    }
  return self;
}
示例#4
0
void
_update_indirect_dynamic_entry(NVTable* self, NVHandle oh, const gchar* name, NVEntry* entry, NVRegistry *logmsg_nv_registry)
{
  NVDynValue* dyn_slot;
  NVEntry* oe = nv_table_get_entry(self, oh, &dyn_slot);
  const gchar* oname = nv_entry_get_name(oe);
  if (G_UNLIKELY(oname[0] == '\0'))
    {
      msg_debug("nvtable: the name of the nventry referred by entry->indirect has zero length",
                evt_tag_str("entry.name", name));
    }
  else
    {
      oh = nv_registry_alloc_handle(logmsg_nv_registry, oname);
      if (oh != 0)
        entry->vindirect.handle = oh;
    }
}
示例#5
0
static void
test_nv_registry()
{
  NVRegistry *reg;
  gint i, j;
  NVHandle handle, prev_handle;
  const gchar *name;
  gssize len;
  const gchar *builtins[] = { "BUILTIN1", "BUILTIN2", "BUILTIN3", NULL };

  reg = nv_registry_new(builtins);

  for (i = 0; builtins[i]; i++)
    {
      handle = nv_registry_alloc_handle(reg, builtins[i]);
      TEST_ASSERT(handle == (i+1));
      name = nv_registry_get_handle_name(reg, handle, &len);
      TEST_ASSERT(strcmp(name, builtins[i]) == 0);
      TEST_ASSERT(strlen(name) == len);
    }

  for (i = 4; i < 65536; i++)
    {
      gchar dyn_name[16];

      g_snprintf(dyn_name, sizeof(dyn_name), "DYN%05d", i);

      /* try to look up the same name multiple times */
      prev_handle = 0;
      for (j = 0; j < 4; j++)
        {
          handle = nv_registry_alloc_handle(reg, dyn_name);
          TEST_ASSERT(prev_handle == 0 || (handle == prev_handle));
          prev_handle = handle;
        }
      name = nv_registry_get_handle_name(reg, handle, &len);
      TEST_ASSERT(strcmp(name, dyn_name) == 0);
      TEST_ASSERT(strlen(name) == len);

      g_snprintf(dyn_name, sizeof(dyn_name), "ALIAS%05d", i);
      nv_registry_add_alias(reg, handle, dyn_name);
      handle = nv_registry_alloc_handle(reg, dyn_name);
      TEST_ASSERT(handle == prev_handle);
    }

  for (i = 65534; i >= 4; i--)
    {
      gchar dyn_name[16];

      g_snprintf(dyn_name, sizeof(dyn_name), "DYN%05d", i);

      /* try to look up the same name multiple times */
      prev_handle = 0;
      for (j = 0; j < 4; j++)
        {
          handle = nv_registry_alloc_handle(reg, dyn_name);
          TEST_ASSERT(prev_handle == 0 || (handle == prev_handle));
          prev_handle = handle;
        }
      name = nv_registry_get_handle_name(reg, handle, &len);
      TEST_ASSERT(strcmp(name, dyn_name) == 0);
      TEST_ASSERT(strlen(name) == len);
    }

  fprintf(stderr, "One error message about too many values is to be expected\n");
  handle = nv_registry_alloc_handle(reg, "too-many-values");
  TEST_ASSERT(handle == 0);

  nv_registry_free(reg);
}