MCPcopy Create free account
hub / github.com/apache/trafficserver / hdrtoken_init

Function hdrtoken_init

src/proxy/hdrs/HdrToken.cc:362–460  ·  view source on GitHub ↗

*/

Source from the content-addressed store, hash-verified

360/**
361 */
362void
363hdrtoken_init()
364{
365 static int inited = 0;
366
367 int i;
368
369 if (!inited) {
370 inited = 1;
371
372 hdrtoken_strs_dfa = new DFA;
373 hdrtoken_strs_dfa->compile(_hdrtoken_strs, SIZEOF(_hdrtoken_strs), (RE_CASE_INSENSITIVE));
374
375 // all the tokenized hdrtoken strings are placed in a special heap,
376 // and each string is prepended with a HdrTokenHeapPrefix ---
377 // this makes it easy to tell that a string is a tokenized
378 // string (because its address is within the heap), and
379 // makes it easy to find the length, index, flags, mask, and
380 // other info from the prefix.
381
382 int heap_size = 0;
383 for (i = 0; i < static_cast<int> SIZEOF(_hdrtoken_strs); i++) {
384 hdrtoken_str_lengths[i] = static_cast<int>(strlen(_hdrtoken_strs[i]));
385 int sstr_len = snap_up_to_multiple(hdrtoken_str_lengths[i] + 1, sizeof(HdrTokenHeapPrefix));
386 int packed_prefix_str_len = sizeof(HdrTokenHeapPrefix) + sstr_len;
387 heap_size += packed_prefix_str_len;
388 }
389
390 _hdrtoken_strs_heap_f = static_cast<const char *>(ats_malloc(heap_size));
391 _hdrtoken_strs_heap_l = _hdrtoken_strs_heap_f + heap_size - 1;
392
393 char *heap_ptr = const_cast<char *>(_hdrtoken_strs_heap_f);
394
395 for (i = 0; i < static_cast<int> SIZEOF(_hdrtoken_strs); i++) {
396 HdrTokenHeapPrefix prefix;
397
398 memset(&prefix, 0, sizeof(HdrTokenHeapPrefix));
399
400 prefix.wks_idx = i;
401 prefix.wks_length = hdrtoken_str_lengths[i];
402 prefix.wks_token_type = HDRTOKEN_TYPE_OTHER; // default, can override later
403 prefix.wks_info.name = nullptr; // default, can override later
404 prefix.wks_info.slotid = MIME_SLOTID_NONE; // default, can override later
405 prefix.wks_info.mask = TOK_64_CONST(0); // default, can override later
406 prefix.wks_info.flags = HTIF_MULTVALS; // default, can override later
407
408 int sstr_len = snap_up_to_multiple(hdrtoken_str_lengths[i] + 1, sizeof(HdrTokenHeapPrefix));
409
410 *reinterpret_cast<HdrTokenHeapPrefix *>(heap_ptr) = prefix; // set string prefix
411 heap_ptr += sizeof(HdrTokenHeapPrefix); // advance heap ptr past index
412 hdrtoken_strs[i] = heap_ptr; // record string pointer
413 // coverity[secure_coding]
414 ink_strlcpy(const_cast<char *>(hdrtoken_strs[i]), _hdrtoken_strs[i],
415 heap_size - sizeof(HdrTokenHeapPrefix)); // copy string into heap
416 heap_ptr += sstr_len; // advance heap ptr past string
417 heap_size -= sstr_len;
418 }
419

Callers 4

mainFunction · 0.85
url_initFunction · 0.85
mime_initFunction · 0.85
test_Hdrs.ccFile · 0.85

Calls 8

snap_up_to_multipleFunction · 0.85
ats_mallocFunction · 0.85
memsetFunction · 0.85
ink_strlcpyFunction · 0.85
hdrtoken_tokenize_dfaFunction · 0.85
hdrtoken_index_to_prefixFunction · 0.85
hdrtoken_hash_initFunction · 0.85
compileMethod · 0.45

Tested by 1

mainFunction · 0.68