Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions include/proxy/hdrs/MIME.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ enum class MimeParseState {
#define MIME_FIELD_SLOTNUM_MAX (MIME_FIELD_SLOTNUM_MASK - 1)
#define MIME_FIELD_SLOTNUM_UNKNOWN MIME_FIELD_SLOTNUM_MAX

#define MIME_FIELD_FREE_SLOT_NONE -1
#define MIME_FIELD_FREE_SLOT_UNINITIALIZED -2

/***********************************************************************
* *
* MIMEField & MIMEFieldBlockImpl *
Expand All @@ -99,16 +102,19 @@ enum class MimeParseState {
struct MIMEHdrImpl;

struct MIMEField {
const char *m_ptr_name; // 4
const char *m_ptr_value; // 4
MIMEField *m_next_dup; // 4
int16_t m_wks_idx; // 2
uint16_t m_len_name; // 2
uint32_t m_len_value : 24; // 3
uint8_t m_n_v_raw_printable : 1; // 1/8
uint8_t m_n_v_raw_printable_pad : 3; // 3/8
uint8_t m_readiness : 2; // 2/8
uint8_t m_flags : 2; // 2/8
const char *m_ptr_name; // 4
const char *m_ptr_value; // 4
union {
MIMEField *m_next_dup; // 4
int32_t m_free_next; ///< Slot number of the next deleted field.
};
int16_t m_wks_idx; // 2
uint16_t m_len_name; // 2
uint32_t m_len_value : 24; // 3
uint8_t m_n_v_raw_printable : 1; // 1/8
uint8_t m_n_v_raw_printable_pad : 3; // 3/8
uint8_t m_readiness : 2; // 2/8
uint8_t m_flags : 2; // 2/8

bool
is_dup_head() const
Expand Down Expand Up @@ -304,7 +310,8 @@ struct MIMEHdrImpl : public HdrHeapObjImpl {
friend struct MIMEHdrImpl;
};

// HdrHeapObjImpl is 4 bytes, so this will result in 4 bytes padding
// HdrHeapObjImpl is 4 bytes, so this uses the 4 bytes that would otherwise be padding.
int32_t m_free_slot; ///< Slot number at the head of the deleted field free list.
uint64_t m_presence_bits;
uint32_t m_slot_accelerators[4];

Expand Down Expand Up @@ -749,6 +756,7 @@ int mime_hdr_fields_count(MIMEHdrImpl *mh);

void mime_field_init(MIMEField *field);
MIMEField *mime_field_create(HdrHeap *heap, MIMEHdrImpl *mh);
MIMEField *mime_field_create_for_name(HdrHeap *heap, MIMEHdrImpl *mh, std::string_view name);
MIMEField *mime_field_create_named(HdrHeap *heap, MIMEHdrImpl *mh, std::string_view name);

void mime_hdr_field_attach(MIMEHdrImpl *mh, MIMEField *field, int check_for_dups, MIMEField *prev_dup);
Expand Down Expand Up @@ -1184,7 +1192,7 @@ MIMEHdr::fields_count() const
inline MIMEField *
MIMEHdr::field_create(std::string_view name)
{
MIMEField *field = mime_field_create(m_heap, m_mime);
MIMEField *field = name.empty() ? mime_field_create(m_heap, m_mime) : mime_field_create_for_name(m_heap, m_mime, name);

if (!name.empty()) {
auto length{static_cast<int>(name.length())};
Expand Down
16 changes: 14 additions & 2 deletions include/proxy/http2/HPACK.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,16 @@ class MIMEFieldWrapper
{
public:
MIMEFieldWrapper(MIMEField *f, HdrHeap *hh, MIMEHdrImpl *impl) : _field(f), _heap(hh), _mh(impl) {}
MIMEFieldWrapper(HdrHeap *hh, MIMEHdrImpl *impl) : _heap(hh), _mh(impl) {}
bool
name_set(const char *name, int name_len)
{
return _field->name_set(_heap, _mh, std::string_view{name, static_cast<std::string_view::size_type>(name_len)});
std::string_view name_view{name, static_cast<std::string_view::size_type>(name_len)};

if (_field == nullptr) {
_field = mime_field_create_for_name(_heap, _mh, name_view);
}
return _field->name_set(_heap, _mh, name_view);
}

bool
Expand All @@ -101,8 +107,14 @@ class MIMEFieldWrapper
return _field;
}

MIMEField *
field_get()
{
return _field;
}

private:
MIMEField *_field;
MIMEField *_field = nullptr;
HdrHeap *_heap;
MIMEHdrImpl *_mh;
};
Expand Down
2 changes: 1 addition & 1 deletion src/api/InkAPI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1770,7 +1770,7 @@ TSMimeHdrFieldAppend(TSMBuffer bufp, TSMLoc mh_mloc, TSMLoc field_mloc)
HdrHeap *heap = ((reinterpret_cast<HdrHeapSDKHandle *>(bufp))->m_heap);

// allocate a new hdr field and copy any pre-set info
mh_field = mime_field_create(heap, mh);
mh_field = mime_field_create_for_name(heap, mh, field_handle->field_ptr->name_get());

// FIX: is it safe to copy everything over?
memcpy(mh_field, field_handle->field_ptr, sizeof(MIMEField));
Expand Down
Loading