Esempio n. 1
0
/* Open the store indicated by NAME, which should consist of a store type
   name followed by a ':' and any type-specific name, returning the new store
   in STORE.  If NAME doesn't contain a `:', then it will be interpreted as
   either a class name, if such a class occurs in CLASSES, or a filename,
   which is opened by calling store_open on NAME; a `:' at the end or the
   beginning of NAME unambiguously causes the remainder to be treated as a
   class-name or a filename, respectively.  CLASSES is used to select classes
   specified by the type name; if it is 0, STORE_STD_CLASSES is used.  */
error_t
store_typed_open (const char *name, int flags,
		  const struct store_class *const *classes,
		  struct store **store)
{
  const struct store_class *cl;
  const char *clname_end = strchrnul (name, ':');

  if (clname_end == name && *clname_end)
    /* Open NAME with store_open.  */
    return store_open (name + 1, flags, classes, store);

  /* Try to find an existing class by the given name.  */
  cl = store_find_class (name, clname_end, classes);
  if (cl != 0)
    {
      if (! cl->open)
	/* CL cannot be opened.  */
	return EOPNOTSUPP;

      if (*clname_end)
	/* Skip the ':' separating the class-name from the device name.  */
	clname_end++;

      if (! *clname_end)
	/* The class-specific portion of the name is empty, so make it *really*
	   empty.  */
	clname_end = 0;

      return (*cl->open) (clname_end, flags, classes, store);
    }

  /* Try to open a store by loading a module to define the class, if we
     have the module-loading support linked in.  We don't just use
     store_module_find_class, because store_module_open will unload the new
     module if the open doesn't succeed and we have no other way to unload
     it.  We always leave modules loaded once a store from the module has
     been successfully opened and so can leave unbounded numbers of old
     modules loaded after closing all the stores using them.  But at least
     we can avoid having modules loaded for stores we never even opened.  */
# pragma weak store_module_open
  if (store_module_open)
    {
      error_t err = store_module_open (name, flags, classes, store);
      if (err != ENOENT)
	return err;
    }

  /* No class with the given name found.  */
  if (*clname_end)
    /* NAME really should be a class name, which doesn't exist.  */
    return EINVAL;
  else
    /* Try opening NAME by querying it as a file instead.  */
    return store_open (name, flags, classes, store);
}
Esempio n. 2
0
char *test_open()
{
	s = store_open("btree.test", STORE_O_CREAT);
	store_resize(s, 1024 * 1024 * 256);
	mu_assert(s != NULL, "File should not be NULL");

	return NULL;
}
Esempio n. 3
0
int main()
{
    Store *s, *d, *sprite_s, *pool_s, *elem_s;
    char *c;
    Scalar r;

    s = store_open();
    {
        if (store_child_save(&sprite_s, "sprite", s))
        {
            c = "hello, world";
            string_save(&c, "prop1", sprite_s);

            c = "hello, world ... again";
            string_save(&c, "prop2", sprite_s);

            r = SCALAR_INFINITY;
            scalar_save(&r, "prop6", sprite_s);

            if (store_child_save(&pool_s, "pool", sprite_s))
            {
                store_child_save(&elem_s, "elem1", pool_s);
                store_child_save(&elem_s, "elem2", pool_s);
            }
        }
    }
    store_write_file(s, "test.sav");
    store_close(s);

    /* ---- */

    d = store_open_file("test.sav");
    {
        if (store_child_load(&sprite_s, "sprite", d))
        {
            printf("%s\n", sprite_s->name);

            string_load(&c, "prop1", "hai", sprite_s);
            printf("    prop1: %s\n", c);

            string_load(&c, "prop3", "hai", sprite_s);
            printf("    prop3: %s\n", c);

            string_load(&c, "prop2", "hai", sprite_s);
            printf("    prop2: %s\n", c);

            scalar_load(&r, "prop6", 4.2, sprite_s);
            printf("    prop6: %f\n", r);

            if (store_child_load(&pool_s, "pool", sprite_s))
                while (store_child_load(&elem_s, NULL, pool_s))
                    printf("        %s\n", elem_s->name);
        }
    }
    store_close(d);

    return 0;
}
Esempio n. 4
0
int main(int argc, char **argv) {
	int cli;
	int sock = BindSocket(12345);
	struct config conf;
	conf.store = store_open("tracker.db");
	conf.max_peer_return=50;
	conf.min_interval=300;
	conf.max_peer_return=48;
	struct event_base *base = event_init();
	struct evhttp *httpd;
	httpd = evhttp_new(base);
	cli = evhttp_accept_socket(httpd, sock);
	evhttp_set_gencb(httpd, tracker, (void *)&conf);
	event_base_dispatch(base);

	return 0;
}