Asterisk - The Open Source Telephony Project  18.5.0
Functions
ndbm.c File Reference
#include <sys/param.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ndbm.h>
#include "hash.h"
Include dependency graph for ndbm.c:

Go to the source code of this file.

Functions

int dbm_clearerr (DBM *db)
 
void dbm_close (DBM *db)
 
int dbm_delete (DBM *db, datum key)
 
int dbm_dirfno (DBM *db)
 
int dbm_error (DBM *db)
 
datum dbm_fetch (DBM *db, datum key)
 
datum dbm_firstkey (DBM *db)
 
datum dbm_nextkey (DBM *db)
 
DBMdbm_open (char *file, int flags, int mode) const
 
int dbm_store (DBM *db, datum key, datum data, int flags)
 

Function Documentation

◆ dbm_clearerr()

int dbm_clearerr ( DBM db)

Definition at line 219 of file ndbm.c.

References htab::errnum, hp, and __db::internal.

221 {
222  HTAB *hp;
223 
224  hp = (HTAB *)db->internal;
225  hp->errnum = 0;
226  return (0);
227 }
int errnum
Definition: hash.h:106
void * internal
Definition: db.h:137
Definition: hash.h:92
static struct hostent * hp
Definition: chan_skinny.c:1236

◆ dbm_close()

void dbm_close ( DBM db)

Definition at line 91 of file ndbm.c.

References db.

93 {
94  (void)(db->close)(db);
95 }
static sqlite3 * db

◆ dbm_delete()

int dbm_delete ( DBM db,
datum  key 
)

Definition at line 170 of file ndbm.c.

References DBT::data, datum::dptr, datum::dsize, DBT::size, and status.

173 {
174  int status;
175  DBT dbtkey;
176 
177  dbtkey.data = key.dptr;
178  dbtkey.size = key.dsize;
179  status = (db->del)(db, &dbtkey, 0);
180  if (status)
181  return (-1);
182  else
183  return (0);
184 }
void * data
Definition: db.h:86
size_t size
Definition: db.h:87
Definition: db.h:85
char * dptr
Definition: ndbm.h:58
int dsize
Definition: ndbm.h:59
jack_status_t status
Definition: app_jack.c:146

◆ dbm_dirfno()

int dbm_dirfno ( DBM db)

Definition at line 230 of file ndbm.c.

References __db::internal.

232 {
233  return(((HTAB *)db->internal)->fp);
234 }
void * internal
Definition: db.h:137
Definition: hash.h:92

◆ dbm_error()

int dbm_error ( DBM db)

Definition at line 209 of file ndbm.c.

References htab::errnum, hp, and __db::internal.

211 {
212  HTAB *hp;
213 
214  hp = (HTAB *)db->internal;
215  return (hp->errnum);
216 }
int errnum
Definition: hash.h:106
void * internal
Definition: db.h:137
Definition: hash.h:92
static struct hostent * hp
Definition: chan_skinny.c:1236

◆ dbm_fetch()

datum dbm_fetch ( DBM db,
datum  key 
)

Definition at line 103 of file ndbm.c.

References DBT::data, datum::dptr, datum::dsize, NULL, DBT::size, and status.

106 {
107  datum retdata;
108  int status;
109  DBT dbtkey, dbtretdata;
110 
111  dbtkey.data = key.dptr;
112  dbtkey.size = key.dsize;
113  status = (db->get)(db, &dbtkey, &dbtretdata, 0);
114  if (status) {
115  dbtretdata.data = NULL;
116  dbtretdata.size = 0;
117  }
118  retdata.dptr = dbtretdata.data;
119  retdata.dsize = dbtretdata.size;
120  return (retdata);
121 }
void * data
Definition: db.h:86
size_t size
Definition: db.h:87
Definition: db.h:85
char * dptr
Definition: ndbm.h:58
#define NULL
Definition: resample.c:96
Definition: ndbm.h:57
int dsize
Definition: ndbm.h:59
jack_status_t status
Definition: app_jack.c:146

◆ dbm_firstkey()

datum dbm_firstkey ( DBM db)

Definition at line 129 of file ndbm.c.

References DBT::data, datum::dptr, datum::dsize, NULL, R_FIRST, DBT::size, and status.

131 {
132  int status;
133  datum retkey;
134  DBT dbtretkey, dbtretdata;
135 
136  status = (db->seq)(db, &dbtretkey, &dbtretdata, R_FIRST);
137  if (status)
138  dbtretkey.data = NULL;
139  retkey.dptr = dbtretkey.data;
140  retkey.dsize = dbtretkey.size;
141  return (retkey);
142 }
void * data
Definition: db.h:86
size_t size
Definition: db.h:87
Definition: db.h:85
char * dptr
Definition: ndbm.h:58
#define NULL
Definition: resample.c:96
Definition: ndbm.h:57
int dsize
Definition: ndbm.h:59
#define R_FIRST
Definition: db.h:93
jack_status_t status
Definition: app_jack.c:146

◆ dbm_nextkey()

datum dbm_nextkey ( DBM db)

Definition at line 150 of file ndbm.c.

References DBT::data, datum::dptr, datum::dsize, NULL, R_NEXT, DBT::size, and status.

152 {
153  int status;
154  datum retkey;
155  DBT dbtretkey, dbtretdata;
156 
157  status = (db->seq)(db, &dbtretkey, &dbtretdata, R_NEXT);
158  if (status)
159  dbtretkey.data = NULL;
160  retkey.dptr = dbtretkey.data;
161  retkey.dsize = dbtretkey.size;
162  return (retkey);
163 }
void * data
Definition: db.h:86
size_t size
Definition: db.h:87
Definition: db.h:85
char * dptr
Definition: ndbm.h:58
#define NULL
Definition: resample.c:96
Definition: ndbm.h:57
int dsize
Definition: ndbm.h:59
#define R_NEXT
Definition: db.h:97
jack_status_t status
Definition: app_jack.c:146

◆ dbm_open()

DBM* dbm_open ( char *  file,
int  flags,
int  mode 
) const

Definition at line 61 of file ndbm.c.

References __hash_open(), HASHINFO::bsize, HASHINFO::cachesize, db, DBM_SUFFIX, HASHINFO::ffactor, make_ari_stubs::file, free(), sip_to_pjsip::info(), len(), HASHINFO::lorder, malloc(), HASHINFO::nelem, and NULL.

64 {
65  DBM *db;
66  HASHINFO info;
67  const size_t len = strlen(file) + sizeof (DBM_SUFFIX);
68 #ifdef __GNUC__
69  char path[len];
70 #else
71  char *path = malloc(len);
72  if (path == NULL)
73  return NULL;
74 #endif
75 
76  info.bsize = 4096;
77  info.ffactor = 40;
78  info.nelem = 1;
79  info.cachesize = 0;
80  info.hash = NULL;
81  info.lorder = 0;
82  snprintf(path, len, "%s%s", file, DBM_SUFFIX);
83  db = (DBM *)__hash_open(path, flags, mode, &info, 0);
84 #ifndef __GNUC__
85  free(path);
86 #endif
87  return db;
88 }
int lorder
Definition: db.h:170
u_int cachesize
Definition: db.h:167
DB * __hash_open(char *file, int flags, int mode, const HASHINFO *info, int dflags) const
Definition: hash.c:96
static sqlite3 * db
#define NULL
Definition: resample.c:96
Definition: db.h:163
char * malloc()
void free()
#define DBM_SUFFIX
Definition: ndbm.h:55
def info(msg)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
u_int nelem
Definition: db.h:166
Definition: db.h:129
u_int ffactor
Definition: db.h:165
u_int bsize
Definition: db.h:164

◆ dbm_store()

int dbm_store ( DBM db,
datum  key,
datum  data,
int  flags 
)

Definition at line 193 of file ndbm.c.

References DBT::data, DBM_INSERT, datum::dptr, datum::dsize, R_NOOVERWRITE, and DBT::size.

197 {
198  DBT dbtkey, dbtdata;
199 
200  dbtkey.data = key.dptr;
201  dbtkey.size = key.dsize;
202  dbtdata.data = data.dptr;
203  dbtdata.size = data.dsize;
204  return ((db->put)(db, &dbtkey, &dbtdata,
205  (flags == DBM_INSERT) ? R_NOOVERWRITE : 0));
206 }
void * data
Definition: db.h:86
size_t size
Definition: db.h:87
#define DBM_INSERT
Definition: ndbm.h:48
Definition: db.h:85
char * dptr
Definition: ndbm.h:58
int dsize
Definition: ndbm.h:59
#define R_NOOVERWRITE
Definition: db.h:98