* @brief Get the header value * * @param bufp request's buffer * @param hdrLoc request's header location * @param header header name * @param headerlen header name length * @param value buffer for the value * @param valuelen length of the buffer for the value * @return pointer to the string with the value. */
| 84 | * @return pointer to the string with the value. |
| 85 | */ |
| 86 | char * |
| 87 | getHeader(TSMBuffer bufp, TSMLoc hdrLoc, const char *header, int headerlen, char *value, int *valuelen) |
| 88 | { |
| 89 | TSMLoc fieldLoc = TSMimeHdrFieldFind(bufp, hdrLoc, header, headerlen); |
| 90 | char *dst = value; |
| 91 | while (fieldLoc) { |
| 92 | TSMLoc next = TSMimeHdrFieldNextDup(bufp, hdrLoc, fieldLoc); |
| 93 | |
| 94 | int count = TSMimeHdrFieldValuesCount(bufp, hdrLoc, fieldLoc); |
| 95 | for (int i = 0; i < count; ++i) { |
| 96 | const char *v = nullptr; |
| 97 | int vlen = 0; |
| 98 | v = TSMimeHdrFieldValueStringGet(bufp, hdrLoc, fieldLoc, i, &vlen); |
| 99 | if (v == nullptr || vlen == 0) { |
| 100 | continue; |
| 101 | } |
| 102 | /* append the field content to the output buffer if enough space, plus space for ", " */ |
| 103 | bool first = (dst == value); |
| 104 | int neededSpace = ((dst - value) + vlen + (dst == value ? 0 : 2)); |
| 105 | if (neededSpace < *valuelen) { |
| 106 | if (!first) { |
| 107 | memcpy(dst, ", ", 2); |
| 108 | dst += 2; |
| 109 | } |
| 110 | memcpy(dst, v, vlen); |
| 111 | dst += vlen; |
| 112 | } |
| 113 | } |
| 114 | TSHandleMLocRelease(bufp, hdrLoc, fieldLoc); |
| 115 | fieldLoc = next; |
| 116 | } |
| 117 | |
| 118 | *valuelen = dst - value; |
| 119 | return value; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * @brief Set a header to a specific value. |
nothing calls this directly
no test coverage detected