Lines Matching refs:tbl

78 #define TBLSIZE(tbl) ((tbl)->size + (tbl)->n * VHT_ENTRY_SIZE)  argument
81 #define TBLENTRIES(tbl) ENTRIES((tbl)->buf, (tbl)->bufsize, (tbl)->n) argument
82 #define TBLENTRY(tbl, i) (&TBLENTRIES(tbl)[(i)]) argument
90 vht_newentry(struct vht_table *tbl) in vht_newentry() argument
94 assert(tbl->maxsize - TBLSIZE(tbl) >= VHT_ENTRY_SIZE); in vht_newentry()
95 tbl->n++; in vht_newentry()
96 e = TBLENTRY(tbl, 0); in vht_newentry()
98 e->offset = tbl->size; in vht_newentry()
103 vht_trim(struct vht_table *tbl, ssize_t max) in vht_trim() argument
109 CHECK_OBJ_NOTNULL(tbl, VHT_TABLE_MAGIC); in vht_trim()
113 if (TBLSIZE(tbl) <= max) in vht_trim()
117 for (i = tbl->n - 1; i >= 0; i--) { in vht_trim()
118 e = TBLENTRY(tbl, i); in vht_trim()
120 if (TBLSIZE(tbl) - (u + v * VHT_ENTRY_SIZE) > max) { in vht_trim()
132 assert(v <= tbl->n); in vht_trim()
134 memmove(tbl->buf, tbl->buf + u, tbl->size - u); in vht_trim()
135 memmove(TBLENTRY(tbl, v), TBLENTRY(tbl, 0), (tbl->n - v) * sizeof *e); in vht_trim()
136 tbl->n -= v; in vht_trim()
137 tbl->size -= u; in vht_trim()
142 vht_appendname(struct vht_table *tbl, const char *buf, size_t len) in vht_appendname() argument
146 CHECK_OBJ_NOTNULL(tbl, VHT_TABLE_MAGIC); in vht_appendname()
147 e = TBLENTRY(tbl, 0); in vht_appendname()
150 assert(TBLSIZE(tbl) + len <= tbl->maxsize); in vht_appendname()
151 assert(e->offset + e->namelen == tbl->size); in vht_appendname()
152 memcpy(tbl->buf + tbl->size, buf, len); in vht_appendname()
154 tbl->size += len; in vht_appendname()
159 vht_appendvalue(struct vht_table *tbl, const char *buf, size_t len) in vht_appendvalue() argument
163 CHECK_OBJ_NOTNULL(tbl, VHT_TABLE_MAGIC); in vht_appendvalue()
164 e = TBLENTRY(tbl, 0); in vht_appendvalue()
166 assert(TBLSIZE(tbl) + len <= tbl->maxsize); in vht_appendvalue()
167 assert(e->offset + e->namelen + e->valuelen == tbl->size); in vht_appendvalue()
168 memcpy(tbl->buf + tbl->size, buf, len); in vht_appendvalue()
170 tbl->size += len; in vht_appendvalue()
177 VHT_NewEntry(struct vht_table *tbl) in VHT_NewEntry() argument
180 CHECK_OBJ_NOTNULL(tbl, VHT_TABLE_MAGIC); in VHT_NewEntry()
181 assert(tbl->maxsize <= tbl->protomax); in VHT_NewEntry()
182 vht_trim(tbl, tbl->maxsize - VHT_ENTRY_SIZE); in VHT_NewEntry()
183 if (tbl->maxsize - TBLSIZE(tbl) < VHT_ENTRY_SIZE) { in VHT_NewEntry()
185 assert(tbl->maxsize < VHT_ENTRY_SIZE); in VHT_NewEntry()
188 vht_newentry(tbl); in VHT_NewEntry()
192 VHT_NewEntry_Indexed(struct vht_table *tbl, unsigned idx) in VHT_NewEntry_Indexed() argument
204 CHECK_OBJ_NOTNULL(tbl, VHT_TABLE_MAGIC); in VHT_NewEntry_Indexed()
205 assert(tbl->maxsize <= tbl->protomax); in VHT_NewEntry_Indexed()
212 VHT_NewEntry(tbl); in VHT_NewEntry_Indexed()
213 VHT_AppendName(tbl, static_table[idx - 1].name, in VHT_NewEntry_Indexed()
219 if (idx >= tbl->n) in VHT_NewEntry_Indexed()
221 assert(tbl->maxsize >= VHT_ENTRY_SIZE); in VHT_NewEntry_Indexed()
223 e = TBLENTRY(tbl, idx); in VHT_NewEntry_Indexed()
230 while (tbl->n - 1 - u > idx && in VHT_NewEntry_Indexed()
231 tbl->maxsize - TBLSIZE(tbl) + l < VHT_ENTRY_SIZE + e->namelen) { in VHT_NewEntry_Indexed()
232 e2 = TBLENTRY(tbl, tbl->n - 1 - u); in VHT_NewEntry_Indexed()
237 vht_trim(tbl, TBLSIZE(tbl) - l); in VHT_NewEntry_Indexed()
239 assert(e == TBLENTRY(tbl, idx)); in VHT_NewEntry_Indexed()
241 if (tbl->maxsize - TBLSIZE(tbl) >= VHT_ENTRY_SIZE + e->namelen) { in VHT_NewEntry_Indexed()
243 vht_newentry(tbl); in VHT_NewEntry_Indexed()
245 assert(e == TBLENTRY(tbl, idx)); in VHT_NewEntry_Indexed()
247 vht_appendname(tbl, tbl->buf + e->offset, e->namelen); in VHT_NewEntry_Indexed()
256 assert(idx == tbl->n - 1); in VHT_NewEntry_Indexed()
261 memmove(TBLENTRY(tbl, 1), TBLENTRY(tbl, 0), (tbl->n - 1) * sizeof *e); in VHT_NewEntry_Indexed()
262 tbl->n--; in VHT_NewEntry_Indexed()
270 memcpy(tmp, tbl->buf, l2); in VHT_NewEntry_Indexed()
271 memmove(tbl->buf, tbl->buf + l2, tbl->size - l2); in VHT_NewEntry_Indexed()
272 memcpy(tbl->buf + tbl->size - l2, tmp, l2); in VHT_NewEntry_Indexed()
276 tbl->size -= lentry; in VHT_NewEntry_Indexed()
279 for (u = 0; u < tbl->n; u++) { in VHT_NewEntry_Indexed()
280 e = TBLENTRY(tbl, u); in VHT_NewEntry_Indexed()
284 assert(e->offset + ENTRYLEN(e) <= tbl->size); in VHT_NewEntry_Indexed()
289 assert(tbl->maxsize - TBLSIZE(tbl) >= VHT_ENTRY_SIZE + lname); in VHT_NewEntry_Indexed()
290 tbl->n++; in VHT_NewEntry_Indexed()
291 e = TBLENTRY(tbl, 0); in VHT_NewEntry_Indexed()
293 e->offset = tbl->size; in VHT_NewEntry_Indexed()
295 tbl->size += lname; in VHT_NewEntry_Indexed()
301 VHT_AppendName(struct vht_table *tbl, const char *buf, ssize_t len) in VHT_AppendName() argument
304 CHECK_OBJ_NOTNULL(tbl, VHT_TABLE_MAGIC); in VHT_AppendName()
305 assert(tbl->maxsize <= tbl->protomax); in VHT_AppendName()
311 vht_trim(tbl, tbl->maxsize - len); in VHT_AppendName()
312 if (tbl->n == 0) in VHT_AppendName()
315 vht_appendname(tbl, buf, len); in VHT_AppendName()
319 VHT_AppendValue(struct vht_table *tbl, const char *buf, ssize_t len) in VHT_AppendValue() argument
322 CHECK_OBJ_NOTNULL(tbl, VHT_TABLE_MAGIC); in VHT_AppendValue()
323 assert(tbl->maxsize <= tbl->protomax); in VHT_AppendValue()
329 vht_trim(tbl, tbl->maxsize - len); in VHT_AppendValue()
330 if (tbl->n == 0) in VHT_AppendValue()
333 vht_appendvalue(tbl, buf, len); in VHT_AppendValue()
337 VHT_SetMaxTableSize(struct vht_table *tbl, size_t maxsize) in VHT_SetMaxTableSize() argument
340 CHECK_OBJ_NOTNULL(tbl, VHT_TABLE_MAGIC); in VHT_SetMaxTableSize()
341 assert(tbl->maxsize <= tbl->protomax); in VHT_SetMaxTableSize()
342 if (maxsize > tbl->protomax) in VHT_SetMaxTableSize()
344 vht_trim(tbl, maxsize); in VHT_SetMaxTableSize()
345 assert(TBLSIZE(tbl) <= maxsize); in VHT_SetMaxTableSize()
346 tbl->maxsize = maxsize; in VHT_SetMaxTableSize()
351 VHT_SetProtoMax(struct vht_table *tbl, size_t protomax) in VHT_SetProtoMax() argument
356 CHECK_OBJ_NOTNULL(tbl, VHT_TABLE_MAGIC); in VHT_SetProtoMax()
358 assert(tbl->maxsize <= tbl->protomax); in VHT_SetProtoMax()
360 if (protomax == tbl->protomax) in VHT_SetProtoMax()
363 if (tbl->maxsize > protomax) in VHT_SetProtoMax()
364 tbl->maxsize = protomax; in VHT_SetProtoMax()
365 vht_trim(tbl, tbl->maxsize); in VHT_SetProtoMax()
366 assert(TBLSIZE(tbl) <= tbl->maxsize); in VHT_SetProtoMax()
369 if (bufsize == tbl->bufsize) { in VHT_SetProtoMax()
370 tbl->protomax = protomax; in VHT_SetProtoMax()
378 if (tbl->buf != NULL) { in VHT_SetProtoMax()
379 memcpy(buf, tbl->buf, tbl->size); in VHT_SetProtoMax()
380 memcpy(ENTRIES(buf, bufsize, tbl->n), TBLENTRIES(tbl), in VHT_SetProtoMax()
381 sizeof (struct vht_entry) * tbl->n); in VHT_SetProtoMax()
382 free(tbl->buf); in VHT_SetProtoMax()
384 tbl->buf = buf; in VHT_SetProtoMax()
385 tbl->bufsize = bufsize; in VHT_SetProtoMax()
386 tbl->protomax = protomax; in VHT_SetProtoMax()
391 VHT_LookupName(const struct vht_table *tbl, unsigned idx, size_t *plen) in VHT_LookupName() argument
406 if (tbl == NULL) in VHT_LookupName()
408 CHECK_OBJ_NOTNULL(tbl, VHT_TABLE_MAGIC); in VHT_LookupName()
411 if (idx >= tbl->n) in VHT_LookupName()
414 e = TBLENTRY(tbl, idx); in VHT_LookupName()
416 assert(e->offset + e->namelen <= tbl->size); in VHT_LookupName()
418 return (tbl->buf + e->offset); in VHT_LookupName()
422 VHT_LookupValue(const struct vht_table *tbl, unsigned idx, size_t *plen) in VHT_LookupValue() argument
437 if (tbl == NULL) in VHT_LookupValue()
439 CHECK_OBJ_NOTNULL(tbl, VHT_TABLE_MAGIC); in VHT_LookupValue()
442 if (idx >= tbl->n) in VHT_LookupValue()
445 e = TBLENTRY(tbl, idx); in VHT_LookupValue()
447 assert(e->offset + e->namelen + e->valuelen <= tbl->size); in VHT_LookupValue()
449 return (tbl->buf + e->offset + e->namelen); in VHT_LookupValue()
453 VHT_Init(struct vht_table *tbl, size_t protomax) in VHT_Init() argument
459 AN(tbl); in VHT_Init()
462 INIT_OBJ(tbl, VHT_TABLE_MAGIC); in VHT_Init()
463 r = VHT_SetProtoMax(tbl, protomax); in VHT_Init()
465 tbl->magic = 0; in VHT_Init()
468 tbl->maxsize = tbl->protomax; in VHT_Init()
473 VHT_Fini(struct vht_table *tbl) in VHT_Fini() argument
476 CHECK_OBJ_NOTNULL(tbl, VHT_TABLE_MAGIC); in VHT_Fini()
477 free(tbl->buf); in VHT_Fini()
478 memset(tbl, 0, sizeof *tbl); in VHT_Fini()
491 vht_matchtable(struct vht_table *tbl, ...) in vht_matchtable() argument
499 CHECK_OBJ_NOTNULL(tbl, VHT_TABLE_MAGIC); in vht_matchtable()
501 va_start(ap, tbl); in vht_matchtable()
503 for (u = 0; u < tbl->n; u++) { in vht_matchtable()
517 e = TBLENTRY(tbl, u); in vht_matchtable()
523 strncmp(a, tbl->buf + e->offset, e->namelen)) in vht_matchtable()
526 strncmp(b, tbl->buf + e->offset + e->namelen, in vht_matchtable()
533 u, e->offset, (int)e->namelen, tbl->buf + e->offset, in vht_matchtable()
534 (int)e->valuelen, tbl->buf + e->offset +e->namelen); in vht_matchtable()
555 tbl->n, tbl->size, TBLSIZE(tbl), tbl->maxsize, in vht_matchtable()
556 tbl->protomax, tbl->bufsize); in vht_matchtable()
609 struct vht_table tbl[1]; in test_2() local
614 AZ(VHT_Init(tbl, VHT_ENTRY_SIZE + 10)); in test_2()
616 VHT_NewEntry(tbl); in test_2()
617 VHT_AppendName(tbl, "12345", -1); in test_2()
618 VHT_AppendValue(tbl, "abcde", -1); in test_2()
619 assert(TBLSIZE(tbl) == VHT_ENTRY_SIZE + 10); in test_2()
621 AZ(vht_matchtable(tbl, "12345", "abcde", NULL)); in test_2()
623 VHT_AppendValue(tbl, "f", -1); in test_2()
624 AZ(vht_matchtable(tbl, NULL)); in test_2()
626 VHT_NewEntry(tbl); in test_2()
627 AZ(vht_matchtable(tbl, "", "", NULL)); in test_2()
629 VHT_Fini(tbl); in test_2()
630 AZ(tbl->buf); in test_2()
642 struct vht_table tbl[1]; in test_3() local
647 AZ(VHT_Init(tbl, 4096)); in test_3()
649 VHT_NewEntry(tbl); in test_3()
650 VHT_AppendName(tbl, "a", -1); in test_3()
651 VHT_AppendValue(tbl, "12345", -1); in test_3()
652 VHT_NewEntry(tbl); in test_3()
653 VHT_AppendName(tbl, "b", -1); in test_3()
654 VHT_AppendValue(tbl, "67890", -1); in test_3()
655 VHT_NewEntry(tbl); in test_3()
656 VHT_AppendName(tbl, "c", -1); in test_3()
657 VHT_AppendValue(tbl, "abcde", -1); in test_3()
658 AZ(vht_matchtable(tbl, "c", "abcde", "b", "67890", "a", "12345", NULL)); in test_3()
661 AZ(VHT_SetProtoMax(tbl, VHT_ENTRY_SIZE * 2 + 6 * 2)); in test_3()
662 AZ(vht_matchtable(tbl, "c", "abcde", "b", "67890", NULL)); in test_3()
665 assert(VHT_SetMaxTableSize(tbl, VHT_ENTRY_SIZE * 2 + 6 * 2 + 1) == -1); in test_3()
668 AZ(VHT_SetMaxTableSize(tbl, VHT_ENTRY_SIZE * 2 + 6 * 2 - 1)); in test_3()
669 AZ(vht_matchtable(tbl, "c", "abcde", NULL)); in test_3()
672 AZ(VHT_SetMaxTableSize(tbl, VHT_ENTRY_SIZE * 2 + 6 * 2)); in test_3()
673 AZ(vht_matchtable(tbl, "c", "abcde", NULL)); in test_3()
676 VHT_NewEntry(tbl); in test_3()
677 VHT_AppendName(tbl, "d", -1); in test_3()
678 VHT_AppendValue(tbl, "ABCDE", -1); in test_3()
679 AZ(vht_matchtable(tbl, "d", "ABCDE", "c", "abcde", NULL)); in test_3()
682 AZ(VHT_SetMaxTableSize(tbl, 0)); in test_3()
683 AZ(vht_matchtable(tbl, NULL)); in test_3()
684 VHT_NewEntry(tbl); in test_3()
685 AZ(vht_matchtable(tbl, NULL)); in test_3()
688 AZ(VHT_SetProtoMax(tbl, 0)); in test_3()
689 AZ(vht_matchtable(tbl, NULL)); in test_3()
690 VHT_NewEntry(tbl); in test_3()
691 AZ(vht_matchtable(tbl, NULL)); in test_3()
693 VHT_Fini(tbl); in test_3()
705 struct vht_table tbl[1]; in test_4() local
717 AZ(VHT_Init(tbl, VHT_ENTRY_SIZE * 2 + 10 * 2)); /* 84 bytes */ in test_4()
720 AZ(VHT_NewEntry_Indexed(tbl, 4)); in test_4()
721 VHT_AppendValue(tbl, "12345", -1); in test_4()
722 AZ(vht_matchtable(tbl, ":path", "12345", NULL)); in test_4()
725 AZ(VHT_NewEntry_Indexed(tbl, VHT_DYNAMIC + 0)); in test_4()
726 VHT_AppendValue(tbl, "abcde", -1); in test_4()
727 AZ(vht_matchtable(tbl, ":path", "abcde", ":path", "12345", NULL)); in test_4()
728 AZ(tbl->maxsize - TBLSIZE(tbl)); /* No space left */ in test_4()
731 AZ(VHT_NewEntry_Indexed(tbl, VHT_DYNAMIC + 0)); in test_4()
732 VHT_AppendValue(tbl, "ABCDE", -1); in test_4()
733 AZ(vht_matchtable(tbl, ":path", "ABCDE", ":path", "abcde", NULL)); in test_4()
736 AZ(VHT_NewEntry_Indexed(tbl, VHT_DYNAMIC + 1)); in test_4()
737 AZ(vht_matchtable(tbl, ":path", "", ":path", "ABCDE", NULL)); in test_4()
741 VHT_NewEntry(tbl); in test_4()
742 VHT_AppendName(tbl, longname, strlen(longname)); in test_4()
743 AZ(vht_matchtable(tbl, longname, "", NULL)); in test_4()
744 AZ(VHT_NewEntry_Indexed(tbl, VHT_DYNAMIC + 0)); in test_4()
745 VHT_AppendValue(tbl, "2", -1); in test_4()
746 AZ(vht_matchtable(tbl, longname, "2", NULL)); in test_4()
748 VHT_Fini(tbl); in test_4()
757 struct vht_table tbl[1]; in test_5() local
775 AZ(VHT_Init(tbl, in test_5()
778 VHT_NewEntry(tbl); in test_5()
779 VHT_AppendName(tbl, buf_a, sizeof buf_a - 1); in test_5()
780 VHT_AppendValue(tbl, buf_b, sizeof buf_b - 1); in test_5()
781 AZ(vht_matchtable(tbl, buf_a, buf_b, NULL)); in test_5()
783 VHT_NewEntry(tbl); in test_5()
784 VHT_AppendName(tbl, buf_a, sizeof buf_a - 1); in test_5()
785 VHT_AppendValue(tbl, buf_b, sizeof buf_b - 1); in test_5()
786 AZ(vht_matchtable(tbl, buf_a, buf_b, buf_a, buf_b, NULL)); in test_5()
788 VHT_NewEntry(tbl); in test_5()
789 VHT_AppendName(tbl, buf_a, sizeof buf_a - 1); in test_5()
790 VHT_AppendValue(tbl, buf_b, sizeof buf_b - 1); in test_5()
791 AZ(vht_matchtable(tbl, buf_a, buf_b, buf_a, buf_b, buf_a, buf_b, NULL)); in test_5()
793 AZ(VHT_NewEntry_Indexed(tbl, VHT_DYNAMIC + 2)); in test_5()
794 VHT_AppendValue(tbl, buf_b, sizeof buf_b - 1); in test_5()
795 AZ(vht_matchtable(tbl, buf_a, buf_b, buf_a, buf_b, buf_a, buf_b, NULL)); in test_5()
797 VHT_Fini(tbl); in test_5()