Asterisk - The Open Source Telephony Project GIT-master-f36a736
Functions
rec_get.c File Reference
#include <sys/types.h>
#include <errno.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "../include/db.h"
#include "recno.h"
Include dependency graph for rec_get.c:

Go to the source code of this file.

Functions

int __rec_fmap (BTREE *t, recno_t top)
 
int __rec_fpipe (BTREE *t, recno_t top)
 
int __rec_get (DB *dbp, const DBT *key, DBT *data, u_int flags) const
 
int __rec_vmap (BTREE *t, recno_t top)
 
int __rec_vpipe (BTREE *t, recno_t top)
 

Function Documentation

◆ __rec_fmap()

int __rec_fmap ( BTREE t,
recno_t  top 
)

Definition at line 235 of file rec_get.c.

238{
239 DBT data;
240 recno_t nrec;
241 u_char *sp, *ep, *p;
242 size_t len;
243
244 if (t->bt_rdata.size < t->bt_reclen) {
245 t->bt_rdata.data = t->bt_rdata.data == NULL ?
246 malloc(t->bt_reclen) :
247 realloc(t->bt_rdata.data, t->bt_reclen);
248 if (t->bt_rdata.data == NULL)
249 return (RET_ERROR);
250 t->bt_rdata.size = t->bt_reclen;
251 }
252 data.data = t->bt_rdata.data;
253 data.size = t->bt_reclen;
254
255 sp = (u_char *)t->bt_cmap;
256 ep = (u_char *)t->bt_emap;
257 for (nrec = t->bt_nrecs; nrec < top; ++nrec) {
258 if (sp >= ep) {
259 F_SET(t, R_EOF);
260 return (RET_SPECIAL);
261 }
262 len = t->bt_reclen;
263 for (p = t->bt_rdata.data;
264 sp < ep && len > 0; *p++ = *sp++, --len);
265 if (len != 0)
266 memset(p, t->bt_bval, len);
267 if (__rec_iput(t, nrec, &data, 0) != RET_SUCCESS)
268 return (RET_ERROR);
269 }
270 t->bt_cmap = (caddr_t)sp;
271 return (RET_SUCCESS);
272}
#define realloc(a, b)
Definition: astmm.h:161
#define F_SET(p, f)
Definition: btree.h:40
#define R_EOF
Definition: btree.h:378
#define RET_SUCCESS
Definition: db.h:52
u_int32_t recno_t
Definition: db.h:82
#define RET_ERROR
Definition: db.h:51
#define RET_SPECIAL
Definition: db.h:53
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
char * malloc()
int __rec_iput(BTREE *t, recno_t nrec, const DBT *data, u_int flags)
Definition: rec_put.c:190
#define NULL
Definition: resample.c:96
Definition: db.h:85
void * data
Definition: db.h:86
size_t size
Definition: db.h:87
caddr_t bt_cmap
Definition: btree.h:355
caddr_t bt_emap
Definition: btree.h:357
u_char bt_bval
Definition: btree.h:362
size_t bt_reclen
Definition: btree.h:361
recno_t bt_nrecs
Definition: btree.h:360
DBT bt_rdata
Definition: btree.h:333

References __rec_iput(), _btree::bt_bval, _btree::bt_cmap, _btree::bt_emap, _btree::bt_nrecs, _btree::bt_rdata, _btree::bt_reclen, DBT::data, F_SET, len(), malloc(), NULL, R_EOF, realloc, RET_ERROR, RET_SPECIAL, RET_SUCCESS, and DBT::size.

Referenced by __rec_open().

◆ __rec_fpipe()

int __rec_fpipe ( BTREE t,
recno_t  top 
)

Definition at line 122 of file rec_get.c.

125{
126 DBT data;
127 recno_t nrec;
128 size_t len;
129 int ch;
130 u_char *p;
131
132 if (t->bt_rdata.size < t->bt_reclen) {
133 t->bt_rdata.data = t->bt_rdata.data == NULL ?
134 malloc(t->bt_reclen) :
135 realloc(t->bt_rdata.data, t->bt_reclen);
136 if (t->bt_rdata.data == NULL)
137 return (RET_ERROR);
138 t->bt_rdata.size = t->bt_reclen;
139 }
140 data.data = t->bt_rdata.data;
141 data.size = t->bt_reclen;
142
143 for (nrec = t->bt_nrecs; nrec < top;) {
144 len = t->bt_reclen;
145 for (p = t->bt_rdata.data;; *p++ = ch)
146 if ((ch = getc(t->bt_rfp)) == EOF || !--len) {
147 if (ch != EOF)
148 *p = ch;
149 if (len != 0)
150 memset(p, t->bt_bval, len);
151 if (__rec_iput(t,
152 nrec, &data, 0) != RET_SUCCESS)
153 return (RET_ERROR);
154 ++nrec;
155 break;
156 }
157 if (ch == EOF)
158 break;
159 }
160 if (nrec < top) {
161 F_SET(t, R_EOF);
162 return (RET_SPECIAL);
163 }
164 return (RET_SUCCESS);
165}
FILE * bt_rfp
Definition: btree.h:352

References __rec_iput(), _btree::bt_bval, _btree::bt_nrecs, _btree::bt_rdata, _btree::bt_reclen, _btree::bt_rfp, DBT::data, F_SET, len(), malloc(), NULL, R_EOF, realloc, RET_ERROR, RET_SPECIAL, RET_SUCCESS, and DBT::size.

Referenced by __rec_open().

◆ __rec_get()

int __rec_get ( DB dbp,
const DBT key,
DBT data,
u_int  flags 
) const

Definition at line 63 of file rec_get.c.

68{
69 BTREE *t;
70 EPG *e;
71 recno_t nrec;
72 int status;
73
74 t = dbp->internal;
75
76 /* Toss any page pinned across calls. */
77 if (t->bt_pinned != NULL) {
78 mpool_put(t->bt_mp, t->bt_pinned, 0);
79 t->bt_pinned = NULL;
80 }
81
82 /* Get currently doesn't take any flags, and keys of 0 are illegal. */
83 if (flags || (nrec = *(recno_t *)key->data) == 0) {
84 errno = EINVAL;
85 return (RET_ERROR);
86 }
87
88 /*
89 * If we haven't seen this record yet, try to find it in the
90 * original file.
91 */
92 if (nrec > t->bt_nrecs) {
93 if (F_ISSET(t, R_EOF | R_INMEM))
94 return (RET_SPECIAL);
95 if ((status = t->bt_irec(t, nrec)) != RET_SUCCESS)
96 return (status);
97 }
98
99 --nrec;
100 if ((e = __rec_search(t, nrec, SEARCH)) == NULL)
101 return (RET_ERROR);
102
103 status = __rec_ret(t, e, 0, NULL, data);
104 if (F_ISSET(t, B_DB_LOCK))
105 mpool_put(t->bt_mp, e->page, 0);
106 else
107 t->bt_pinned = e->page;
108 return (status);
109}
jack_status_t status
Definition: app_jack.c:146
#define F_ISSET(p, f)
Definition: btree.h:42
#define R_INMEM
Definition: btree.h:381
#define B_DB_LOCK
Definition: btree.h:385
static DB * dbp
Definition: hsearch.c:49
int errno
int mpool_put(MPOOL *mp, void *page, u_int flags)
Definition: mpool.c:251
EPG * __rec_search(BTREE *t, recno_t recno, enum SRCHOP op)
Definition: rec_search.c:64
int __rec_ret(BTREE *t, EPG *e, recno_t nrec, DBT *key, DBT *data)
Definition: rec_utils.c:62
@ SEARCH
Definition: recno.h:36
void * internal
Definition: db.h:137
Definition: btree.h:312
MPOOL * bt_mp
Definition: btree.h:313
PAGE * bt_pinned
Definition: btree.h:318
Definition: btree.h:254
PAGE * page
Definition: btree.h:255

References __rec_ret(), __rec_search(), B_DB_LOCK, _btree::bt_mp, _btree::bt_nrecs, _btree::bt_pinned, DBT::data, dbp, errno, F_ISSET, __db::internal, mpool_put(), NULL, _epg::page, R_EOF, R_INMEM, RET_ERROR, RET_SPECIAL, RET_SUCCESS, SEARCH, and status.

Referenced by __rec_open().

◆ __rec_vmap()

int __rec_vmap ( BTREE t,
recno_t  top 
)

Definition at line 285 of file rec_get.c.

288{
289 DBT data;
290 u_char *sp, *ep;
291 recno_t nrec;
292 int bval;
293
294 sp = (u_char *)t->bt_cmap;
295 ep = (u_char *)t->bt_emap;
296 bval = t->bt_bval;
297
298 for (nrec = t->bt_nrecs; nrec < top; ++nrec) {
299 if (sp >= ep) {
300 F_SET(t, R_EOF);
301 return (RET_SPECIAL);
302 }
303 for (data.data = sp; sp < ep && *sp != bval; ++sp);
304 data.size = sp - (u_char *)data.data;
305 if (__rec_iput(t, nrec, &data, 0) != RET_SUCCESS)
306 return (RET_ERROR);
307 ++sp;
308 }
309 t->bt_cmap = (caddr_t)sp;
310 return (RET_SUCCESS);
311}
if(!yyg->yy_init)
Definition: ast_expr2f.c:854

References __rec_iput(), _btree::bt_bval, _btree::bt_cmap, _btree::bt_emap, _btree::bt_nrecs, DBT::data, F_SET, if(), R_EOF, RET_ERROR, RET_SPECIAL, RET_SUCCESS, and DBT::size.

Referenced by __rec_open().

◆ __rec_vpipe()

int __rec_vpipe ( BTREE t,
recno_t  top 
)

Definition at line 178 of file rec_get.c.

181{
182 DBT data;
183 recno_t nrec;
184 indx_t len;
185 size_t sz;
186 int bval, ch;
187 u_char *p;
188
189 bval = t->bt_bval;
190 for (nrec = t->bt_nrecs; nrec < top; ++nrec) {
191 for (p = t->bt_rdata.data,
192 sz = t->bt_rdata.size;; *p++ = ch, --sz) {
193 if ((ch = getc(t->bt_rfp)) == EOF || ch == bval) {
194 data.data = t->bt_rdata.data;
195 data.size = p - (u_char *)t->bt_rdata.data;
196 if (ch == EOF && data.size == 0)
197 break;
198 if (__rec_iput(t, nrec, &data, 0)
199 != RET_SUCCESS)
200 return (RET_ERROR);
201 break;
202 }
203 if (sz == 0) {
204 len = p - (u_char *)t->bt_rdata.data;
205 t->bt_rdata.size += (sz = 256);
206 t->bt_rdata.data = t->bt_rdata.data == NULL ?
207 malloc(t->bt_rdata.size) :
208 realloc(t->bt_rdata.data, t->bt_rdata.size);
209 if (t->bt_rdata.data == NULL)
210 return (RET_ERROR);
211 p = (u_char *)t->bt_rdata.data + len;
212 }
213 }
214 if (ch == EOF)
215 break;
216 }
217 if (nrec < top) {
218 F_SET(t, R_EOF);
219 return (RET_SPECIAL);
220 }
221 return (RET_SUCCESS);
222}
u_int16_t indx_t
Definition: db.h:80

References __rec_iput(), _btree::bt_bval, _btree::bt_nrecs, _btree::bt_rdata, _btree::bt_rfp, DBT::data, F_SET, if(), len(), malloc(), NULL, R_EOF, realloc, RET_ERROR, RET_SPECIAL, RET_SUCCESS, and DBT::size.

Referenced by __rec_open().