# Database Browser C APIs

This article is deprecated. Please see the following article instead.

> As explained in the Database Browser page, the eXtremeDB SDK includes an HTML-based database browser / editor (HTTP Viewer) that can be used to examine any eXtremeDB database.

> The browser is implemented via a special library `mcohv`, which is a layer between the UDA API and the generic C APIs of the eXtremeDB database, and the HTTP server library `mcoews`. Simply linking with these libraries enables HTML browser access to examine or change the database contents. Library `mcohv` has an extended version `mcohv_sql` which allows executing SQL queries to browse the database. (The additional library `mcosql` must be linked for SQL access). Conversely, not linking the application with the `mcohv` and `mcoews` libraries effectively disables http access to the eXtremeDB database.

> ## Database Browser Functions

> The following structure allows changing the default HTTP server bindings from `http://localhost:8082/` to a user defined address and port when starting the HTTP server:

>         typedef struct tag_mcohv_interface_def
>         {
>             char* interface_addr;
>             unsigned short port;
>         } mcohv_interface_def_t;

> The database browser can simultaneously serve up to five custom interfaces specified by argument `n_intf` of function mcohv_start().

> The application will define the following data structure pointer (as a void pointer) to hold `mcohv` library internal information between the starting and stopping of the Database Browser HTTP Server:

> `typedef void* mcohv_p;`

> ## Database Browser Initialize/Shutdown Functions

> To initialize the `mcohv` library before starting the Database Browser Server and to shut it down gracefully, call the following functions:

>         int mcohv_initialize();
>         int mcohv_shutdown();

> The HTTP server library `mcoews` needs no additional initialization. All of the necessary functionality performed by this library are encapsulated in the `mcohv` library.

> ## Database Browser Start/Stop Server Functions

> Then `mcohv` library is initialized and the database or databases opened as usual by the application using generic API functions `mco_db_open_dev()` or `mco_db_load()` or by using the UDA function `mco_uda_db_open()`. The application starts the Database Browser server. Note that, due to the fact that UDA functions are used by the `mcohv` library, to gather database information, the UDA metadictionary must first be created and initialized.

>         int mcohv_start(mcohv_p* hv, mco_metadict_header_t *db,
>                 mcohv_interface_def_t* intf,
>                 unsigned int n_intf);

>         int mcohv_stop(mcohv_p hv);

> The following code snippets (from samples "samples/core/02-open/convhv" and "samples/core/22-httpview") show some of the details and steps for using the HttpViewer in an application:

>         #define DATABASE_SEGMENT_SIZE 10*1024*1024
>         mco_device_t dev;
>         mco_metadict_header_t *metadict;
>         mcohv_p hv;
>         unsigned int size;
>         char *db_name = "my_db"

>         mco_runtime_start();

>         mco_metadict_size(1, &size);
>         metadict = (mco_metadict_header_t *) (malloc(size));
>         mco_metadict_register(metadict, db_name, my_db get_dictionary(), NULL);
>         mco_db_params_init ( &db_params );

>         dev.type       = MCO_MEMORY_CONV;
>         dev.assignment = MCO_MEMORY_ASSIGN_DATABASE;
>         dev.size       = DATABASE_SEGMENT_SIZE;
>         dev.dev.conv.ptr = (void*)malloc( DATABASE_SEGMENT_SIZE );

>         mco_db_open_dev(db_name, my_db_get_dictionary(), &dev, 1, &db_params );

>         mcohv_start(&hv, metadict, 0, 0);

>         /* Wait until some event to stop http server */
>         mcohv_stop(hv);
>         mco_db_close(db_name);
>         mco_runtime_stop();
>         free(dev.dev.conv.ptr);