#include "portable.h"
#include <stdio.h>
#include <ac/unistd.h>
#include <ac/socket.h>
#include <ac/string.h>
#include <lutil.h>
#include "slap.h"
#include "back-netinfo.h"
static u_int32_t cursor = NOID;
int netinfo_tool_entry_open(BackendDB *be, int mode)
{
struct dsinfo *di = ((struct dsinfo *)be->be_private);
assert(slapMode & SLAP_TOOL_MODE);
assert(di != NULL);
if (di->engine == NULL)
return 1;
return 0;
}
int netinfo_tool_entry_close(BackendDB *be)
{
cursor = NOID;
return 0;
}
ID netinfo_tool_entry_next(BackendDB *be)
{
struct dsinfo *di = ((struct dsinfo *)be->be_private);
dsstore *store;
u_int32_t max;
assert(slapMode & SLAP_TOOL_MODE);
assert(di != NULL);
assert(di->engine != NULL);
store = di->engine->store;
max = dsstore_max_id(store);
do
{
cursor++;
if (dsstore_record_version(store, cursor) != IndexNull)
return (ID)cursor;
}
while (cursor < max);
return NOID;
}
Entry *netinfo_tool_entry_get(BackendDB *be, ID id)
{
struct dsinfo *di = (struct dsinfo *)be->be_private;
dsrecord *rec;
Entry *ent = NULL;
assert(slapMode & SLAP_TOOL_MODE);
assert(di != NULL);
assert(di->engine != NULL);
if (dsengine_fetch(di->engine, (u_int32_t)id, &rec) != DSStatusOK)
return NULL;
if (dsrecord_to_entry(be, rec, &ent) != DSStatusOK)
ent = NULL;
dsrecord_release(rec);
return ent;
}
ID netinfo_tool_entry_put(BackendDB *be, Entry *e, struct berval *text)
{
struct dsinfo *di = (struct dsinfo *)be->be_private;
dsrecord *rec;
dsstatus status;
u_int32_t dsid;
struct berval parentNDN;
assert(slapMode & SLAP_TOOL_MODE);
assert(di != NULL);
assert(di->engine != NULL);
assert(text);
assert(text->bv_val);
assert(text->bv_val[0] == '\0');
dnParent(&e->e_nname, &parentNDN);
status = netinfo_back_dn_pathcreate(be, &parentNDN, &dsid);
if (status != DSStatusOK)
{
snprintf(text->bv_val, text->bv_len, "unable to get parent: %s",
dsstatus_message(status));
return NOID;
}
status = entry_to_dsrecord(be, dsid, e, &rec);
if (status != DSStatusOK)
{
snprintf(text->bv_val, text->bv_len, "unable to parse entry: %s",
dsstatus_message(status));
return NOID;
}
status = dsengine_create(di->engine, rec, dsid);
if (status != DSStatusOK)
{
snprintf(text->bv_val, text->bv_len, "unable to create entry: %s",
dsstatus_message(status));
dsrecord_release(rec);
return NOID;
}
dsid = rec->dsid;
dsrecord_release(rec);
return (ID)dsid;
}
int netinfo_tool_entry_reindex(BackendDB *be, ID id)
{
struct dsinfo *di = (struct dsinfo *)be->be_private;
assert(slapMode & SLAP_TOOL_MODE);
assert(di != NULL);
assert(di->engine != NULL);
return 0;
}
int netinfo_tool_sync(BackendDB *be)
{
struct dsinfo *di = (struct dsinfo *)be->be_private;
assert(slapMode & SLAP_TOOL_MODE);
assert(di != NULL);
assert(di->engine != NULL);
dsstore_flush_cache(di->engine->store);
return 0;
}