Back to index

courier  0.68.2
Classes | Defines | Functions
gdbmobj.h File Reference
#include "config.h"
#include <gdbm.h>
#include <stdlib.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  gdbmobj

Defines

#define gdbmobj_isopen(p)   (!!(p)->has_dbf)

Functions

void gdbmobj_init (struct gdbmobj *)
int gdbmobj_open (struct gdbmobj *, const char *, const char *)
void gdbmobj_close (struct gdbmobj *)
char * gdbmobj_fetch (struct gdbmobj *, const char *, size_t, size_t *, const char *)
int gdbmobj_exists (struct gdbmobj *, const char *, size_t)
int gdbmobj_delete (struct gdbmobj *, const char *, size_t)
int gdbmobj_store (struct gdbmobj *, const char *, size_t, const char *, size_t, const char *)
char * gdbmobj_firstkey (struct gdbmobj *, size_t *, char **, size_t *)
char * gdbmobj_nextkey (struct gdbmobj *, size_t *, char **, size_t *)

Class Documentation

struct gdbmobj

Definition at line 19 of file gdbmobj.h.

Class Members
GDBM_FILE dbf
int has_dbf
char * prev_key
size_t prev_key_len

Define Documentation

#define gdbmobj_isopen (   p)    (!!(p)->has_dbf)

Definition at line 31 of file gdbmobj.h.


Function Documentation

void gdbmobj_close ( struct gdbmobj )

Definition at line 27 of file gdbmobj.c.

{
       if (obj->has_dbf)
       {
              obj->has_dbf=0;
              gdbm_close(obj->dbf);
       }
       if (obj->prev_key)
       {
              free(obj->prev_key);
              obj->prev_key=0;
       }
}

Here is the caller graph for this function:

int gdbmobj_delete ( struct gdbmobj ,
const char *  ,
size_t   
)

Definition at line 8 of file gdbmobj3.c.

{
datum  dkey;

       if (!obj->has_dbf)   return (0);

       dkey.dptr=(char *)key;
       dkey.dsize=keylen;

       if (gdbm_delete(obj->dbf, dkey))   return (-1);
       return (0);
}
int gdbmobj_exists ( struct gdbmobj ,
const char *  ,
size_t   
)

Definition at line 100 of file gdbmobj.c.

{
datum  dkey;

       if (!obj->has_dbf)   return (0);

       dkey.dptr=(char *)key;
       dkey.dsize=keylen;

       if (gdbm_exists(obj->dbf, dkey))   return (1);
       return (0);
}
char* gdbmobj_fetch ( struct gdbmobj ,
const char *  ,
size_t  ,
size_t *  ,
const char *   
)

Definition at line 115 of file gdbmobj.c.

{
char   *p;

       for (;;)
       {
              if ((p=gdbm_dofetch(obj, key, keylen, datalen)) != 0)
                     return (p);
              if (!options) break;
              if (*options == 'I')
              {
                     while (keylen && key[--keylen] != '.')
                            ;
                     if (!keylen)  break;
                     continue;
              }
              if (*options == 'D')
              {
              size_t i;

                     for (i=0; i<keylen; i++)
                            if (key[i] == '@') { ++i; break; }
                     if (i < keylen)
                     {
                            if ((p=gdbm_dofetch(obj, key, i, datalen)) != 0)
                                   return (p);
                            key += i;
                            keylen -= i;
                            continue;
                     }

                     for (i=0; i<keylen; i++)
                            if (key[i] == '.') { ++i; break; }
                     if (i < keylen)
                     {
                            key += i;
                            keylen -= i;
                            continue;
                     }
                     break;
              }
              break;
       }
       return (0);
}

Here is the call graph for this function:

char* gdbmobj_firstkey ( struct gdbmobj ,
size_t *  ,
char **  ,
size_t *   
)

Definition at line 11 of file gdbmobj2.c.

{
datum  key;

       if (!obj->has_dbf)   return (0);

       if (obj->prev_key)   free(obj->prev_key);
       obj->prev_key=0;

       key=gdbm_firstkey(obj->dbf);

       if (!key.dptr)       return (0);

       obj->prev_key=key.dptr;
       obj->prev_key_len=key.dsize;
       return (fetchkeyval(obj, keylen, val, vallen));
}

Here is the call graph for this function:

void gdbmobj_init ( struct gdbmobj )

Definition at line 20 of file gdbmobj.c.

{
       obj->has_dbf=0;
       obj->prev_key=0;
       obj->prev_key_len=0;
}
char* gdbmobj_nextkey ( struct gdbmobj ,
size_t *  ,
char **  ,
size_t *   
)

Definition at line 40 of file gdbmobj2.c.

{
datum  dkey, key;

       if (!obj->has_dbf || !obj->prev_key)      return (0);

       dkey.dptr=(char *)obj->prev_key;
       dkey.dsize=obj->prev_key_len;

       key=gdbm_nextkey(obj->dbf, dkey);

       free(obj->prev_key);
       obj->prev_key=key.dptr;
       obj->prev_key_len=key.dsize;
       return (fetchkeyval(obj, keylen, val, vallen));
}

Here is the call graph for this function:

int gdbmobj_open ( struct gdbmobj ,
const char *  ,
const char *   
)

Definition at line 41 of file gdbmobj.c.

{
int    mode=GDBM_READER;

       for ( ; *modestr; modestr++)
              switch (*modestr)    {
              case 'c':
              case 'C':
                     mode=GDBM_WRCREAT;
                     break;
              case 'w':
              case 'W':
                     mode=GDBM_WRITER;
                     break;
              case 'n':
              case 'N':
                     mode=GDBM_NEWDB;
                     break;
       }

       gdbmobj_close(obj);
       if ((obj->dbf=gdbm_open((char *)filename, 0, mode, 0664, 0)) != 0)
       {
              /* Where possible, set the close-on-exec bit */

#if    HAVE_GDBM_FDESC
#ifdef  FD_CLOEXEC

       int    fd=gdbm_fdesc(obj->dbf);

              if (fd >= 0)  fcntl(fd, F_SETFD, FD_CLOEXEC);
#endif
#endif

              obj->has_dbf=1;
              return (0);
       }
       return (-1);
}

Here is the call graph for this function:

int gdbmobj_store ( struct gdbmobj ,
const char *  ,
size_t  ,
const char *  ,
size_t  ,
const char *   
)

Definition at line 81 of file gdbmobj.c.

{
datum dkey;
datum dval;

       dkey.dptr=(char *)key;
       dkey.dsize=keylen;

       dval.dptr=(char *)data;
       dval.dsize=datalen;

       return (obj->has_dbf ? gdbm_store(obj->dbf, dkey, dval, (
                     *mode == 'i' || *mode == 'I' ?
                            GDBM_INSERT:GDBM_REPLACE)):-1);
}