| 1702 | } |
| 1703 | |
| 1704 | TSReturnCode |
| 1705 | TSMimeHdrFieldAppend(TSMBuffer bufp, TSMLoc mh_mloc, TSMLoc field_mloc) |
| 1706 | { |
| 1707 | // Allow to modify the buffer only |
| 1708 | // if bufp is modifiable. If bufp is not modifiable return |
| 1709 | // TS_ERROR. If allowed, return TS_SUCCESS. Changed the |
| 1710 | // return value of function from void to TSReturnCode. |
| 1711 | sdk_assert(sdk_sanity_check_mbuffer(bufp) == TS_SUCCESS); |
| 1712 | sdk_assert((sdk_sanity_check_mime_hdr_handle(mh_mloc) == TS_SUCCESS) || |
| 1713 | (sdk_sanity_check_http_hdr_handle(mh_mloc) == TS_SUCCESS)); |
| 1714 | sdk_assert(sdk_sanity_check_field_handle(field_mloc) == TS_SUCCESS); |
| 1715 | |
| 1716 | if (!isWriteable(bufp)) { |
| 1717 | return TS_ERROR; |
| 1718 | } |
| 1719 | |
| 1720 | MIMEField *mh_field; |
| 1721 | MIMEHdrImpl *mh = _hdr_mloc_to_mime_hdr_impl(mh_mloc); |
| 1722 | MIMEFieldSDKHandle *field_handle = reinterpret_cast<MIMEFieldSDKHandle *>(field_mloc); |
| 1723 | |
| 1724 | ////////////////////////////////////////////////////////////////////// |
| 1725 | // The field passed in field_mloc might have been allocated from // |
| 1726 | // inside a MIME header (the correct way), or it might have been // |
| 1727 | // created in isolation as a "standalone field" (the old way). // |
| 1728 | // // |
| 1729 | // If it's a standalone field (the associated mime header is null), // |
| 1730 | // then we need to now allocate a real field inside the header, // |
| 1731 | // copy over the data, and convert the standalone field into a // |
| 1732 | // forwarding pointer to the real field, in case it's used again // |
| 1733 | ////////////////////////////////////////////////////////////////////// |
| 1734 | if (field_handle->mh == nullptr) { |
| 1735 | HdrHeap *heap = ((reinterpret_cast<HdrHeapSDKHandle *>(bufp))->m_heap); |
| 1736 | |
| 1737 | // allocate a new hdr field and copy any pre-set info |
| 1738 | mh_field = mime_field_create(heap, mh); |
| 1739 | |
| 1740 | // FIX: is it safe to copy everything over? |
| 1741 | memcpy(mh_field, field_handle->field_ptr, sizeof(MIMEField)); |
| 1742 | |
| 1743 | // now set up the forwarding ptr from standalone field to hdr field |
| 1744 | field_handle->mh = mh; |
| 1745 | field_handle->field_ptr = mh_field; |
| 1746 | } |
| 1747 | |
| 1748 | ink_assert(field_handle->mh == mh); |
| 1749 | ink_assert(field_handle->field_ptr->m_ptr_name); |
| 1750 | |
| 1751 | mime_hdr_field_attach(mh, field_handle->field_ptr, 1, nullptr); |
| 1752 | return TS_SUCCESS; |
| 1753 | } |
| 1754 | |
| 1755 | TSReturnCode |
| 1756 | TSMimeHdrFieldRemove(TSMBuffer bufp, TSMLoc mh_mloc, TSMLoc field_mloc) |