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

Go to the source code of this file.

Functions

int __big_delete (HTAB *hashp, BUFHEAD *bufp)
 
int __big_insert (HTAB *hashp, BUFHEAD *bufp, const DBT *key, const DBT *val)
 
int __big_keydata (HTAB *hashp, BUFHEAD *bufp, DBT *key, DBT *val, int set)
 
int __big_return (HTAB *hashp, BUFHEAD *bufp, int ndx, DBT *val, int set_current)
 
int __big_split (HTAB *hashp, BUFHEAD *op, BUFHEAD *np, BUFHEAD *big_keyp, int addr, u_int32_t obucket, SPLIT_RETURN *ret)
 
int __find_bigpair (HTAB *hashp, BUFHEAD *bufp, int ndx, char *key, int size)
 
u_int16_t __find_last_page (HTAB *hashp, BUFHEAD **bpp)
 
static int collect_key __P ((HTAB *, BUFHEAD *, int, DBT *, int))
 
static int collect_data __P ((HTAB *, BUFHEAD *, int, int))
 
static int collect_data (HTAB *hashp, BUFHEAD *bufp, int len, int set)
 
static int collect_key (HTAB *hashp, BUFHEAD *bufp, int len, DBT *val, int set)
 

Function Documentation

◆ __big_delete()

int __big_delete ( HTAB hashp,
BUFHEAD bufp 
)

Definition at line 188 of file hash_bigkey.c.

References __free_ovflpage(), __get_buf(), BUF_MOD, _bufhead::flags, FREESPACE, FULL_KEY, FULL_KEY_DATA, if(), NULL, OFFSET, _bufhead::ovfl, OVFLPAGE, _bufhead::page, PAGE_META, and while().

Referenced by __delpair().

191 {
192  register BUFHEAD *last_bfp, *rbufp;
193  u_int16_t *bp, pageno;
194  int key_done, n;
195 
196  rbufp = bufp;
197  last_bfp = NULL;
198  bp = (u_int16_t *)bufp->page;
199  pageno = 0;
200  key_done = 0;
201 
202  while (!key_done || (bp[2] != FULL_KEY_DATA)) {
203  if (bp[2] == FULL_KEY || bp[2] == FULL_KEY_DATA)
204  key_done = 1;
205 
206  /*
207  * If there is freespace left on a FULL_KEY_DATA page, then
208  * the data is short and fits entirely on this page, and this
209  * is the last page.
210  */
211  if (bp[2] == FULL_KEY_DATA && FREESPACE(bp))
212  break;
213  pageno = bp[bp[0] - 1];
214  rbufp->flags |= BUF_MOD;
215  rbufp = __get_buf(hashp, pageno, rbufp, 0);
216  if (last_bfp)
217  __free_ovflpage(hashp, last_bfp);
218  last_bfp = rbufp;
219  if (!rbufp)
220  return (-1); /* Error. */
221  bp = (u_int16_t *)rbufp->page;
222  }
223 
224  /*
225  * If we get here then rbufp points to the last page of the big
226  * key/data pair. Bufp points to the first one -- it should now be
227  * empty pointing to the next page after this pair. Can't free it
228  * because we don't have the page pointing to it.
229  */
230 
231  /* This is information from the last page of the pair. */
232  n = bp[0];
233  pageno = bp[n - 1];
234 
235  /* Now, bp is the first page of the pair. */
236  bp = (u_int16_t *)bufp->page;
237  if (n > 2) {
238  /* There is an overflow page. */
239  bp[1] = pageno;
240  bp[2] = OVFLPAGE;
241  bufp->ovfl = rbufp->ovfl;
242  } else
243  /* This is the last page. */
244  bufp->ovfl = NULL;
245  n -= 2;
246  bp[0] = n;
247  FREESPACE(bp) = hashp->BSIZE - PAGE_META(n);
248  OFFSET(bp) = hashp->BSIZE - 1;
249 
250  bufp->flags |= BUF_MOD;
251  if (rbufp)
252  __free_ovflpage(hashp, rbufp);
253  if (last_bfp && last_bfp != rbufp)
254  __free_ovflpage(hashp, last_bfp);
255 
256  hashp->NKEYS--;
257  return (0);
258 }
#define FREESPACE(P)
Definition: page.h:80
BUFHEAD * ovfl
Definition: hash.h:50
if(!yyg->yy_init)
Definition: ast_expr2f.c:868
#define NULL
Definition: resample.c:96
#define PAGE_META(N)
Definition: page.h:85
#define FULL_KEY
Definition: hash.h:269
char * page
Definition: hash.h:52
#define BUF_MOD
Definition: hash.h:54
while(1)
Definition: ast_expr2f.c:894
Definition: hash.h:47
#define OFFSET(P)
Definition: page.h:81
unsigned short u_int16_t
char flags
Definition: hash.h:53
#define OVFLPAGE
Definition: hash.h:267
#define FULL_KEY_DATA
Definition: hash.h:270
BUFHEAD * __get_buf(HTAB *hashp, u_int32_t addr, BUFHEAD *prev_bp, int newpage)
Definition: hash_buf.c:105
void __free_ovflpage(HTAB *hashp, BUFHEAD *obufp)
Definition: hash_page.c:815

◆ __big_insert()

int __big_insert ( HTAB hashp,
BUFHEAD bufp,
const DBT key,
const DBT val 
)

Definition at line 88 of file hash_bigkey.c.

References __add_ovflpage(), BIGOVERHEAD, BUF_MOD, DBT::data, _bufhead::flags, FREESPACE, FULL_KEY, FULL_KEY_DATA, MIN, OFFSET, _bufhead::page, PAGE_META, PARTIAL_KEY, and DBT::size.

Referenced by __addel().

92 {
93  register u_int16_t *p;
94  int key_size, n, val_size;
95  u_int16_t space, move_bytes, off;
96  char *cp, *key_data, *val_data;
97 
98  cp = bufp->page; /* Character pointer of p. */
99  p = (u_int16_t *)cp;
100 
101  key_data = (char *)key->data;
102  key_size = key->size;
103  val_data = (char *)val->data;
104  val_size = val->size;
105 
106  /* First move the Key */
107  for (space = FREESPACE(p) - BIGOVERHEAD; key_size;
108  space = FREESPACE(p) - BIGOVERHEAD) {
109  move_bytes = MIN(space, key_size);
110  off = OFFSET(p) - move_bytes;
111  memmove(cp + off, key_data, move_bytes);
112  key_size -= move_bytes;
113  key_data += move_bytes;
114  n = p[0];
115  p[++n] = off;
116  p[0] = ++n;
117  FREESPACE(p) = off - PAGE_META(n);
118  OFFSET(p) = off;
119  p[n] = PARTIAL_KEY;
120  bufp = __add_ovflpage(hashp, bufp);
121  if (!bufp)
122  return (-1);
123  n = p[0];
124  if (!key_size) {
125  if (FREESPACE(p)) {
126  move_bytes = MIN(FREESPACE(p), val_size);
127  off = OFFSET(p) - move_bytes;
128  p[n] = off;
129  memmove(cp + off, val_data, move_bytes);
130  val_data += move_bytes;
131  val_size -= move_bytes;
132  p[n - 2] = FULL_KEY_DATA;
133  FREESPACE(p) = FREESPACE(p) - move_bytes;
134  OFFSET(p) = off;
135  } else
136  p[n - 2] = FULL_KEY;
137  }
138  p = (u_int16_t *)bufp->page;
139  cp = bufp->page;
140  bufp->flags |= BUF_MOD;
141  }
142 
143  /* Now move the data */
144  for (space = FREESPACE(p) - BIGOVERHEAD; val_size;
145  space = FREESPACE(p) - BIGOVERHEAD) {
146  move_bytes = MIN(space, val_size);
147  /*
148  * Here's the hack to make sure that if the data ends on the
149  * same page as the key ends, FREESPACE is at least one.
150  */
151  if ((int) space == val_size && (size_t) val_size == val->size)
152  move_bytes--;
153  off = OFFSET(p) - move_bytes;
154  memmove(cp + off, val_data, move_bytes);
155  val_size -= move_bytes;
156  val_data += move_bytes;
157  n = p[0];
158  p[++n] = off;
159  p[0] = ++n;
160  FREESPACE(p) = off - PAGE_META(n);
161  OFFSET(p) = off;
162  if (val_size) {
163  p[n] = FULL_KEY;
164  bufp = __add_ovflpage(hashp, bufp);
165  if (!bufp)
166  return (-1);
167  cp = bufp->page;
168  p = (u_int16_t *)cp;
169  } else
170  p[n] = FULL_KEY_DATA;
171  bufp->flags |= BUF_MOD;
172  }
173  return (0);
174 }
void * data
Definition: db.h:86
#define FREESPACE(P)
Definition: page.h:80
BUFHEAD * __add_ovflpage(HTAB *hashp, BUFHEAD *bufp)
Definition: hash_page.c:465
size_t size
Definition: db.h:87
#define BIGOVERHEAD
Definition: page.h:77
#define PAGE_META(N)
Definition: page.h:85
#define FULL_KEY
Definition: hash.h:269
char * page
Definition: hash.h:52
#define MIN(a, b)
Definition: utils.h:226
#define BUF_MOD
Definition: hash.h:54
#define PARTIAL_KEY
Definition: hash.h:268
#define OFFSET(P)
Definition: page.h:81
unsigned short u_int16_t
char flags
Definition: hash.h:53
#define FULL_KEY_DATA
Definition: hash.h:270

◆ __big_keydata()

int __big_keydata ( HTAB hashp,
BUFHEAD bufp,
DBT key,
DBT val,
int  set 
)

Definition at line 507 of file hash_bigkey.c.

References collect_key(), DBT::data, DBT::size, and htab::tmp_key.

Referenced by __big_split(), and hash_seq().

512 {
513  key->size = collect_key(hashp, bufp, 0, val, set);
514  if (key->size == (size_t) -1)
515  return (-1);
516  key->data = (u_char *)hashp->tmp_key;
517  return (0);
518 }
void * data
Definition: db.h:86
size_t size
Definition: db.h:87
char * tmp_key
Definition: hash.h:102
static int collect_key(HTAB *hashp, BUFHEAD *bufp, int len, DBT *val, int set)
Definition: hash_bigkey.c:525

◆ __big_return()

int __big_return ( HTAB hashp,
BUFHEAD bufp,
int  ndx,
DBT val,
int  set_current 
)

Definition at line 360 of file hash_bigkey.c.

References __get_buf(), _bufhead::addr, htab::cbucket, htab::cndx, collect_data(), htab::cpage, DBT::data, errno, FREESPACE, FULL_KEY, len(), NULL, _bufhead::page, PARTIAL_KEY, DBT::size, htab::tmp_buf, and while().

Referenced by collect_key(), and hash_access().

366 {
367  BUFHEAD *save_p;
368  u_int16_t *bp, len, off, save_addr;
369  char *tp;
370 
371  bp = (u_int16_t *)bufp->page;
372  while (bp[ndx + 1] == PARTIAL_KEY) {
373  bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
374  if (!bufp)
375  return (-1);
376  bp = (u_int16_t *)bufp->page;
377  ndx = 1;
378  }
379 
380  if (bp[ndx + 1] == FULL_KEY) {
381  bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
382  if (!bufp)
383  return (-1);
384  bp = (u_int16_t *)bufp->page;
385  save_p = bufp;
386  save_addr = save_p->addr;
387  off = bp[1];
388  len = 0;
389  } else
390  if (!FREESPACE(bp)) {
391  /*
392  * This is a hack. We can't distinguish between
393  * FULL_KEY_DATA that contains complete data or
394  * incomplete data, so we require that if the data
395  * is complete, there is at least 1 byte of free
396  * space left.
397  */
398  off = bp[bp[0]];
399  len = bp[1] - off;
400  save_p = bufp;
401  save_addr = bufp->addr;
402  bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
403  if (!bufp)
404  return (-1);
405  bp = (u_int16_t *)bufp->page;
406  } else {
407  /* The data is all on one page. */
408  tp = (char *)bp;
409  off = bp[bp[0]];
410  val->data = (u_char *)tp + off;
411  val->size = bp[1] - off;
412  if (set_current) {
413  if (bp[0] == 2) { /* No more buckets in
414  * chain */
415  hashp->cpage = NULL;
416  hashp->cbucket++;
417  hashp->cndx = 1;
418  } else {
419  hashp->cpage = __get_buf(hashp,
420  bp[bp[0] - 1], bufp, 0);
421  if (!hashp->cpage)
422  return (-1);
423  hashp->cndx = 1;
424  if (!((u_int16_t *)
425  hashp->cpage->page)[0]) {
426  hashp->cbucket++;
427  hashp->cpage = NULL;
428  }
429  }
430  }
431  return (0);
432  }
433 
434  val->size = collect_data(hashp, bufp, (int)len, set_current);
435  if (val->size == (size_t) -1)
436  return (-1);
437  if (save_p->addr != save_addr) {
438  /* We are pretty short on buffers. */
439  errno = EINVAL; /* OUT OF BUFFERS */
440  return (-1);
441  }
442  memmove(hashp->tmp_buf, (save_p->page) + off, len);
443  val->data = (u_char *)hashp->tmp_buf;
444  return (0);
445 }
void * data
Definition: db.h:86
#define FREESPACE(P)
Definition: page.h:80
u_int32_t addr
Definition: hash.h:51
size_t size
Definition: db.h:87
#define NULL
Definition: resample.c:96
#define FULL_KEY
Definition: hash.h:269
char * page
Definition: hash.h:52
static int collect_data(HTAB *hashp, BUFHEAD *bufp, int len, int set)
Definition: hash_bigkey.c:451
while(1)
Definition: ast_expr2f.c:894
#define PARTIAL_KEY
Definition: hash.h:268
Definition: hash.h:47
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int errno
BUFHEAD * cpage
Definition: hash.h:103
unsigned short u_int16_t
char * tmp_buf
Definition: hash.h:101
BUFHEAD * __get_buf(HTAB *hashp, u_int32_t addr, BUFHEAD *prev_bp, int newpage)
Definition: hash_buf.c:105
int cndx
Definition: hash.h:105
int cbucket
Definition: hash.h:104

◆ __big_split()

int __big_split ( HTAB hashp,
BUFHEAD op,
BUFHEAD np,
BUFHEAD big_keyp,
int  addr,
u_int32_t  obucket,
SPLIT_RETURN ret 
)

Definition at line 570 of file hash_bigkey.c.

References __add_ovflpage(), __big_keydata(), __call_hash(), __find_last_page(), __get_buf(), _bufhead::addr, BUF_MOD, DBT::data, DEBUG, _bufhead::flags, FREESPACE, if(), SPLIT_RETURN::newp, SPLIT_RETURN::next_addr, SPLIT_RETURN::nextp, NULL, OFFSET, SPLIT_RETURN::oldp, _bufhead::ovfl, OVFLPAGE, OVFLSIZE, _bufhead::page, and DBT::size.

Referenced by ugly_split().

579 {
580  register BUFHEAD *tmpp;
581  register u_int16_t *tp;
582  BUFHEAD *bp;
583  DBT key, val;
584  u_int32_t change;
585  u_int16_t free_space, n, off;
586 
587  bp = big_keyp;
588 
589  /* Now figure out where the big key/data goes */
590  if (__big_keydata(hashp, big_keyp, &key, &val, 0))
591  return (-1);
592  change = (__call_hash(hashp, key.data, key.size) != obucket);
593 
594  if ((ret->next_addr = __find_last_page(hashp, &big_keyp))) {
595  if (!(ret->nextp =
596  __get_buf(hashp, ret->next_addr, big_keyp, 0)))
597  return (-1);;
598  } else
599  ret->nextp = NULL;
600 
601  /* Now make one of np/op point to the big key/data pair */
602 #ifdef DEBUG
603  assert(np->ovfl == NULL);
604 #endif
605  if (change)
606  tmpp = np;
607  else
608  tmpp = op;
609 
610  tmpp->flags |= BUF_MOD;
611 #ifdef DEBUG1
612  (void)fprintf(stderr,
613  "BIG_SPLIT: %d->ovfl was %d is now %d\n", tmpp->addr,
614  (tmpp->ovfl ? tmpp->ovfl->addr : 0), (bp ? bp->addr : 0));
615 #endif
616  tmpp->ovfl = bp; /* one of op/np point to big_keyp */
617  tp = (u_int16_t *)tmpp->page;
618 #ifdef DEBUG
619  assert(FREESPACE(tp) >= OVFLSIZE);
620 #endif
621  n = tp[0];
622  off = OFFSET(tp);
623  free_space = FREESPACE(tp);
624  tp[++n] = (u_int16_t)addr;
625  tp[++n] = OVFLPAGE;
626  tp[0] = n;
627  OFFSET(tp) = off;
628  FREESPACE(tp) = free_space - OVFLSIZE;
629 
630  /*
631  * Finally, set the new and old return values. BIG_KEYP contains a
632  * pointer to the last page of the big key_data pair. Make sure that
633  * big_keyp has no following page (2 elements) or create an empty
634  * following page.
635  */
636 
637  ret->newp = np;
638  ret->oldp = op;
639 
640  tp = (u_int16_t *)big_keyp->page;
641  big_keyp->flags |= BUF_MOD;
642  if (tp[0] > 2) {
643  /*
644  * There may be either one or two offsets on this page. If
645  * there is one, then the overflow page is linked on normally
646  * and tp[4] is OVFLPAGE. If there are two, tp[4] contains
647  * the second offset and needs to get stuffed in after the
648  * next overflow page is added.
649  */
650  n = tp[4];
651  free_space = FREESPACE(tp);
652  off = OFFSET(tp);
653  tp[0] -= 2;
654  FREESPACE(tp) = free_space + OVFLSIZE;
655  OFFSET(tp) = off;
656  tmpp = __add_ovflpage(hashp, big_keyp);
657  if (!tmpp)
658  return (-1);
659  tp[4] = n;
660  } else
661  tmpp = big_keyp;
662 
663  if (change)
664  ret->newp = tmpp;
665  else
666  ret->oldp = tmpp;
667  return (0);
668 }
int __big_keydata(HTAB *hashp, BUFHEAD *bufp, DBT *key, DBT *val, int set)
Definition: hash_bigkey.c:507
void * data
Definition: db.h:86
#define FREESPACE(P)
Definition: page.h:80
BUFHEAD * __add_ovflpage(HTAB *hashp, BUFHEAD *bufp)
Definition: hash_page.c:465
u_int32_t addr
Definition: hash.h:51
size_t size
Definition: db.h:87
Definition: ast_expr2.c:325
BUFHEAD * nextp
Definition: page.h:90
BUFHEAD * ovfl
Definition: hash.h:50
if(!yyg->yy_init)
Definition: ast_expr2f.c:868
Definition: db.h:85
#define NULL
Definition: resample.c:96
char * page
Definition: hash.h:52
u_int16_t next_addr
Definition: page.h:91
#define OVFLSIZE
Definition: page.h:79
#define DEBUG
Definition: chan_alsa.c:81
#define BUF_MOD
Definition: hash.h:54
u_int16_t __find_last_page(HTAB *hashp, BUFHEAD **bpp)
Definition: hash_bigkey.c:319
u_int32_t __call_hash(HTAB *hashp, char *k, int len)
Definition: hash.c:886
Definition: hash.h:47
#define OFFSET(P)
Definition: page.h:81
unsigned short u_int16_t
BUFHEAD * newp
Definition: page.h:88
BUFHEAD * oldp
Definition: page.h:89
char flags
Definition: hash.h:53
unsigned int u_int32_t
#define OVFLPAGE
Definition: hash.h:267
BUFHEAD * __get_buf(HTAB *hashp, u_int32_t addr, BUFHEAD *prev_bp, int newpage)
Definition: hash_buf.c:105

◆ __find_bigpair()

int __find_bigpair ( HTAB hashp,
BUFHEAD bufp,
int  ndx,
char *  key,
int  size 
)

Definition at line 267 of file hash_bigkey.c.

References __get_buf(), _bufhead::page, and PARTIAL_KEY.

Referenced by hash_access().

273 {
274  register u_int16_t *bp;
275  register char *p;
276  int ksize;
277  u_int16_t bytes;
278  char *kkey;
279 
280  bp = (u_int16_t *)bufp->page;
281  p = bufp->page;
282  ksize = size;
283  kkey = key;
284 
285  for (bytes = hashp->BSIZE - bp[ndx];
286  bytes <= size && bp[ndx + 1] == PARTIAL_KEY;
287  bytes = hashp->BSIZE - bp[ndx]) {
288  if (memcmp(p + bp[ndx], kkey, bytes))
289  return (-2);
290  kkey += bytes;
291  ksize -= bytes;
292  bufp = __get_buf(hashp, bp[ndx + 2], bufp, 0);
293  if (!bufp)
294  return (-3);
295  p = bufp->page;
296  bp = (u_int16_t *)p;
297  ndx = 1;
298  }
299 
300  if (bytes != ksize || memcmp(p + bp[ndx], kkey, bytes)) {
301 #ifdef HASH_STATISTICS
302  ++hash_collisions;
303 #endif
304  return (-2);
305  } else
306  return (ndx);
307 }
char * page
Definition: hash.h:52
#define PARTIAL_KEY
Definition: hash.h:268
unsigned short u_int16_t
BUFHEAD * __get_buf(HTAB *hashp, u_int32_t addr, BUFHEAD *prev_bp, int newpage)
Definition: hash_buf.c:105

◆ __find_last_page()

u_int16_t __find_last_page ( HTAB hashp,
BUFHEAD **  bpp 
)

Definition at line 319 of file hash_bigkey.c.

References __get_buf(), FREESPACE, FULL_KEY_DATA, OVFLPAGE, and _bufhead::page.

Referenced by __big_split(), and hash_access().

322 {
323  BUFHEAD *bufp;
324  u_int16_t *bp, pageno;
325  int n;
326 
327  bufp = *bpp;
328  bp = (u_int16_t *)bufp->page;
329  for (;;) {
330  n = bp[0];
331 
332  /*
333  * This is the last page if: the tag is FULL_KEY_DATA and
334  * either only 2 entries OVFLPAGE marker is explicit there
335  * is freespace on the page.
336  */
337  if (bp[2] == FULL_KEY_DATA &&
338  ((n == 2) || (bp[n] == OVFLPAGE) || (FREESPACE(bp))))
339  break;
340 
341  pageno = bp[n - 1];
342  bufp = __get_buf(hashp, pageno, bufp, 0);
343  if (!bufp)
344  return (0); /* Need to indicate an error! */
345  bp = (u_int16_t *)bufp->page;
346  }
347 
348  *bpp = bufp;
349  if (bp[0] > 2)
350  return (bp[3]);
351  else
352  return (0);
353 }
#define FREESPACE(P)
Definition: page.h:80
char * page
Definition: hash.h:52
Definition: hash.h:47
unsigned short u_int16_t
#define OVFLPAGE
Definition: hash.h:267
#define FULL_KEY_DATA
Definition: hash.h:270
BUFHEAD * __get_buf(HTAB *hashp, u_int32_t addr, BUFHEAD *prev_bp, int newpage)
Definition: hash_buf.c:105

◆ __P() [1/2]

static int collect_key __P ( (HTAB *, BUFHEAD *, int, DBT *, int)  )
static

◆ __P() [2/2]

static int collect_data __P ( (HTAB *, BUFHEAD *, int, int)  )
static

◆ collect_data()

static int collect_data ( HTAB hashp,
BUFHEAD bufp,
int  len,
int  set 
)
static

Definition at line 451 of file hash_bigkey.c.

References __get_buf(), _bufhead::addr, htab::cbucket, htab::cndx, htab::cpage, errno, free(), FULL_KEY_DATA, malloc(), NULL, _bufhead::page, and htab::tmp_buf.

Referenced by __big_return().

455 {
456  register u_int16_t *bp;
457  register char *p;
458  BUFHEAD *xbp;
459  u_int16_t save_addr;
460  int mylen, totlen;
461 
462  p = bufp->page;
463  bp = (u_int16_t *)p;
464  mylen = hashp->BSIZE - bp[1];
465  save_addr = bufp->addr;
466 
467  if (bp[2] == FULL_KEY_DATA) { /* End of Data */
468  totlen = len + mylen;
469  if (hashp->tmp_buf)
470  free(hashp->tmp_buf);
471  if ((hashp->tmp_buf = (char *)malloc(totlen)) == NULL)
472  return (-1);
473  if (set) {
474  hashp->cndx = 1;
475  if (bp[0] == 2) { /* No more buckets in chain */
476  hashp->cpage = NULL;
477  hashp->cbucket++;
478  } else {
479  hashp->cpage =
480  __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
481  if (!hashp->cpage)
482  return (-1);
483  else if (!((u_int16_t *)hashp->cpage->page)[0]) {
484  hashp->cbucket++;
485  hashp->cpage = NULL;
486  }
487  }
488  }
489  } else {
490  xbp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
491  if (!xbp || ((totlen =
492  collect_data(hashp, xbp, len + mylen, set)) < 1))
493  return (-1);
494  }
495  if (bufp->addr != save_addr) {
496  errno = EINVAL; /* Out of buffers. */
497  return (-1);
498  }
499  memmove(&hashp->tmp_buf[len], (bufp->page) + bp[1], mylen);
500  return (totlen);
501 }
u_int32_t addr
Definition: hash.h:51
#define NULL
Definition: resample.c:96
char * page
Definition: hash.h:52
char * malloc()
void free()
static int collect_data(HTAB *hashp, BUFHEAD *bufp, int len, int set)
Definition: hash_bigkey.c:451
Definition: hash.h:47
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int errno
BUFHEAD * cpage
Definition: hash.h:103
unsigned short u_int16_t
char * tmp_buf
Definition: hash.h:101
#define FULL_KEY_DATA
Definition: hash.h:270
BUFHEAD * __get_buf(HTAB *hashp, u_int32_t addr, BUFHEAD *prev_bp, int newpage)
Definition: hash_buf.c:105
int cndx
Definition: hash.h:105
int cbucket
Definition: hash.h:104

◆ collect_key()

static int collect_key ( HTAB hashp,
BUFHEAD bufp,
int  len,
DBT val,
int  set 
)
static

Definition at line 525 of file hash_bigkey.c.

References __big_return(), __get_buf(), _bufhead::addr, errno, free(), FULL_KEY, FULL_KEY_DATA, malloc(), NULL, _bufhead::page, and htab::tmp_key.

Referenced by __big_keydata().

531 {
532  BUFHEAD *xbp;
533  char *p;
534  int mylen, totlen;
535  u_int16_t *bp, save_addr;
536 
537  p = bufp->page;
538  bp = (u_int16_t *)p;
539  mylen = hashp->BSIZE - bp[1];
540 
541  save_addr = bufp->addr;
542  totlen = len + mylen;
543  if (bp[2] == FULL_KEY || bp[2] == FULL_KEY_DATA) { /* End of Key. */
544  if (hashp->tmp_key != NULL)
545  free(hashp->tmp_key);
546  if ((hashp->tmp_key = (char *)malloc(totlen)) == NULL)
547  return (-1);
548  if (__big_return(hashp, bufp, 1, val, set))
549  return (-1);
550  } else {
551  xbp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
552  if (!xbp || ((totlen =
553  collect_key(hashp, xbp, totlen, val, set)) < 1))
554  return (-1);
555  }
556  if (bufp->addr != save_addr) {
557  errno = EINVAL; /* MIS -- OUT OF BUFFERS */
558  return (-1);
559  }
560  memmove(&hashp->tmp_key[len], (bufp->page) + bp[1], mylen);
561  return (totlen);
562 }
u_int32_t addr
Definition: hash.h:51
char * tmp_key
Definition: hash.h:102
static int collect_key(HTAB *hashp, BUFHEAD *bufp, int len, DBT *val, int set)
Definition: hash_bigkey.c:525
#define NULL
Definition: resample.c:96
#define FULL_KEY
Definition: hash.h:269
char * page
Definition: hash.h:52
char * malloc()
void free()
Definition: hash.h:47
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int errno
unsigned short u_int16_t
#define FULL_KEY_DATA
Definition: hash.h:270
BUFHEAD * __get_buf(HTAB *hashp, u_int32_t addr, BUFHEAD *prev_bp, int newpage)
Definition: hash_buf.c:105
int __big_return(HTAB *hashp, BUFHEAD *bufp, int ndx, DBT *val, int set_current)
Definition: hash_bigkey.c:360