Asterisk - The Open Source Telephony Project  18.5.0
Functions | Variables
hsearch.c File Reference
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
#include "../include/db.h"
#include "search.h"
Include dependency graph for hsearch.c:

Go to the source code of this file.

Functions

int hcreate (u_int nel)
 
void hdestroy ()
 
ENTRYhsearch (ENTRY item, ACTION action)
 

Variables

static DBdbp = NULL
 
static ENTRY retval
 

Function Documentation

◆ hcreate()

int hcreate ( u_int  nel)

Definition at line 53 of file hsearch.c.

References __hash_open(), HASHINFO::bsize, HASHINFO::cachesize, dbp, HASHINFO::ffactor, sip_to_pjsip::info(), HASHINFO::lorder, HASHINFO::nelem, and NULL.

55 {
56  HASHINFO info;
57 
58  info.nelem = nel;
59  info.bsize = 256;
60  info.ffactor = 8;
61  info.cachesize = 0;
62  info.hash = NULL;
63  info.lorder = 0;
64  dbp = (DB *)__hash_open(NULL, O_CREAT | O_RDWR, 0600, &info, 0);
65  return ((int)dbp);
66 }
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
#define NULL
Definition: resample.c:96
Definition: db.h:163
static DB * dbp
Definition: hsearch.c:49
def info(msg)
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

◆ hdestroy()

void hdestroy ( )

Definition at line 101 of file hsearch.c.

References dbp, and NULL.

102 {
103  if (dbp) {
104  (void)(dbp->close)(dbp);
105  dbp = NULL;
106  }
107 }
#define NULL
Definition: resample.c:96
static DB * dbp
Definition: hsearch.c:49

◆ hsearch()

ENTRY* hsearch ( ENTRY  item,
ACTION  action 
)

Definition at line 69 of file hsearch.c.

References entry::data, DBT::data, ENTER, entry::key, NULL, R_NOOVERWRITE, DBT::size, and status.

72 {
73  DBT key, val;
74  int status;
75 
76  if (!dbp)
77  return (NULL);
78  key.data = (u_char *)item.key;
79  key.size = strlen(item.key) + 1;
80 
81  if (action == ENTER) {
82  val.data = (u_char *)item.data;
83  val.size = strlen(item.data) + 1;
84  status = (dbp->put)(dbp, &key, &val, R_NOOVERWRITE);
85  if (status)
86  return (NULL);
87  } else {
88  /* FIND */
89  status = (dbp->get)(dbp, &key, &val, 0);
90  if (status)
91  return (NULL);
92  else
93  item.data = (char *)val.data;
94  }
95  retval.key = item.key;
96  retval.data = item.data;
97  return (&retval);
98 }
void * data
Definition: db.h:86
size_t size
Definition: db.h:87
Definition: ast_expr2.c:325
Definition: db.h:85
#define NULL
Definition: resample.c:96
static DB * dbp
Definition: hsearch.c:49
char * key
Definition: search.h:41
#define R_NOOVERWRITE
Definition: db.h:98
static ENTRY retval
Definition: hsearch.c:50
char * data
Definition: search.h:42
jack_status_t status
Definition: app_jack.c:146

Variable Documentation

◆ dbp

DB* dbp = NULL
static

Definition at line 49 of file hsearch.c.

Referenced by __bt_open(), __hash_open(), __rec_open(), hcreate(), and hdestroy().

◆ retval

ENTRY retval
static