Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate name_get() and value_get() function returns const char * (#10153) #12027

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
40 changes: 18 additions & 22 deletions include/proxy/hdrs/MIME.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ struct MIMEField {
}

/// @return The name of @a this field.
std::string_view name_get() const;
const char *name_get(int *length) const;
std::string_view name_get() const;
[[deprecated("Use name_get() returns std::string_view")]] const char *name_get(int *length) const;

/** Find the index of the value in the multi-value field.

Expand All @@ -160,8 +160,8 @@ struct MIMEField {
int value_get_index(const char *value, int length) const;

/// @return The value of @a this field.
std::string_view value_get() const;
const char *value_get(int *length) const;
std::string_view value_get() const;
[[deprecated("Use value_get() returns std::string_view")]] const char *value_get(int *length) const;

int32_t value_get_int() const;
uint32_t value_get_uint() const;
Expand Down Expand Up @@ -974,11 +974,9 @@ MIMEField::name_set(HdrHeap *heap, MIMEHdrImpl *mh, const char *name, int length
inline bool
MIMEField::name_is_valid(uint32_t invalid_char_bits) const
{
const char *name;
int length;

for (name = name_get(&length); length > 0; length--) {
if (ParseRules::is_type(name[length - 1], invalid_char_bits)) {
auto name{name_get()};
for (char c : name) {
if (ParseRules::is_type(c, invalid_char_bits)) {
return false;
}
}
Expand All @@ -992,7 +990,7 @@ inline const char *
MIMEField::value_get(int *length) const
{
auto value{this->value_get()};
*length = int(value.size());
*length = static_cast<int>(value.length());
return value.data();
}

Expand Down Expand Up @@ -1083,11 +1081,9 @@ MIMEField::value_append(HdrHeap *heap, MIMEHdrImpl *mh, const char *value, int l
inline bool
MIMEField::value_is_valid(uint32_t invalid_char_bits) const
{
const char *value;
int length;

for (value = value_get(&length); length > 0; length--) {
if (ParseRules::is_type(value[length - 1], invalid_char_bits)) {
auto value{value_get()};
for (char c : value) {
if (ParseRules::is_type(c, invalid_char_bits)) {
return false;
}
}
Expand Down Expand Up @@ -1449,7 +1445,9 @@ MIMEHdr::value_get(const char *name, int name_length, int *value_length_return)
const MIMEField *field = field_find(name, name_length);

if (field) {
return field->value_get(value_length_return);
auto value{field->value_get()};
*value_length_return = static_cast<int>(value.length());
return value.data();
}
return nullptr;
}
Expand Down Expand Up @@ -1581,12 +1579,10 @@ MIMEHdr::field_combine_dups(MIMEField *field, bool prepend_comma, const char sep
MIMEField *current = field->m_next_dup;

while (current) {
int value_len = 0;
const char *value_str = current->value_get(&value_len);

if (value_len > 0) {
HdrHeap::HeapGuard guard(m_heap, value_str); // reference count the source string so it doesn't get moved
field->value_append(m_heap, m_mime, value_str, value_len, prepend_comma, separator);
auto value{current->value_get()};
if (value.length() > 0) {
HdrHeap::HeapGuard guard(m_heap, value.data()); // reference count the source string so it doesn't get moved
field->value_append(m_heap, m_mime, value.data(), value.length(), prepend_comma, separator);
}
field_delete(current, false); // don't delete duplicates
current = field->m_next_dup;
Expand Down
8 changes: 6 additions & 2 deletions include/proxy/http2/HPACK.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,17 @@ class MIMEFieldWrapper
const char *
name_get(int *length) const
{
return _field->name_get(length);
auto name{_field->name_get()};
*length = static_cast<int>(name.length());
return name.data();
}

const char *
value_get(int *length) const
{
return _field->value_get(length);
auto value{_field->value_get()};
*length = static_cast<int>(value.length());
return value.data();
}

const MIMEField *
Expand Down
8 changes: 6 additions & 2 deletions src/api/InkAPI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,9 @@ TSMimeFieldValueGet(TSMBuffer /* bufp ATS_UNUSED */, TSMLoc field_obj, int idx,
if (idx >= 0) {
return mime_field_value_get_comma_val(handle->field_ptr, value_len_ptr, idx);
} else {
return handle->field_ptr->value_get(value_len_ptr);
auto value{handle->field_ptr->value_get()};
*value_len_ptr = static_cast<int>(value.length());
return value.data();
}
}

Expand Down Expand Up @@ -2030,7 +2032,9 @@ TSMimeHdrFieldNameGet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int *length)
sdk_assert(sdk_sanity_check_null_ptr((void *)length) == TS_SUCCESS);

MIMEFieldSDKHandle *handle = reinterpret_cast<MIMEFieldSDKHandle *>(field);
return handle->field_ptr->name_get(length);
auto name{handle->field_ptr->name_get()};
*length = static_cast<int>(name.length());
return name.data();
}

TSReturnCode
Expand Down
12 changes: 6 additions & 6 deletions src/iocore/cache/unit_tests/test_Alternate_L_to_S.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ bool reuse_existing_cache = false;

#include "main.h"

using namespace std::literals;

class CacheAltReadAgain : public CacheTestHandler
{
public:
Expand Down Expand Up @@ -76,9 +78,8 @@ class CacheAltReadAgain : public CacheTestHandler
REQUIRE(rt);
MIMEField *field = rt->read_http_info->m_alt->m_response_hdr.field_find(MIME_FIELD_CONTENT_TYPE, MIME_LEN_CONTENT_TYPE);
REQUIRE(field);
int len;
const char *value = field->value_get(&len);
REQUIRE(memcmp(value, "text/html;charset=utf-8", len) == 0);
auto value{field->value_get()};
REQUIRE(value == "text/html;charset=utf-8"sv);
}
};

Expand Down Expand Up @@ -156,9 +157,8 @@ class CacheAltTest_L_to_S : public CacheTestHandler
REQUIRE(rt);
MIMEField *field = rt->read_http_info->m_alt->m_response_hdr.field_find(MIME_FIELD_CONTENT_TYPE, MIME_LEN_CONTENT_TYPE);
REQUIRE(field);
int len;
const char *value = field->value_get(&len);
REQUIRE(memcmp(value, "application/x-javascript", len) == 0);
auto value{field->value_get()};
REQUIRE(value == "application/x-javascript"sv);
}
};

Expand Down
17 changes: 8 additions & 9 deletions src/iocore/cache/unit_tests/test_Alternate_L_to_S_remove_L.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#include "main.h"

using namespace std::literals;

int cache_vols = 1;
bool reuse_existing_cache = false;

Expand Down Expand Up @@ -87,9 +89,8 @@ class CacheAltReadAgain2 : public CacheTestHandler
REQUIRE(rt);
MIMEField *field = rt->read_http_info->m_alt->m_response_hdr.field_find(MIME_FIELD_CONTENT_TYPE, MIME_LEN_CONTENT_TYPE);
REQUIRE(field);
int len;
const char *value = field->value_get(&len);
REQUIRE(memcmp(value, "application/x-javascript", len) == 0);
auto value{field->value_get()};
REQUIRE(value == "application/x-javascript"sv);
}
};

Expand Down Expand Up @@ -133,9 +134,8 @@ class CacheAltReadAgain : public CacheTestHandler
REQUIRE(rt);
MIMEField *field = rt->read_http_info->m_alt->m_response_hdr.field_find(MIME_FIELD_CONTENT_TYPE, MIME_LEN_CONTENT_TYPE);
REQUIRE(field);
int len;
const char *value = field->value_get(&len);
REQUIRE(memcmp(value, "text/html;charset=utf-8", len) == 0);
auto value{field->value_get()};
REQUIRE(value == "text/html;charset=utf-8"sv);
}
};

Expand Down Expand Up @@ -213,9 +213,8 @@ class CacheAltTest_L_to_S_remove_L : public CacheTestHandler
REQUIRE(rt);
MIMEField *field = rt->read_http_info->m_alt->m_response_hdr.field_find(MIME_FIELD_CONTENT_TYPE, MIME_LEN_CONTENT_TYPE);
REQUIRE(field);
int len;
const char *value = field->value_get(&len);
REQUIRE(memcmp(value, "application/x-javascript", len) == 0);
auto value{field->value_get()};
REQUIRE(value == "application/x-javascript"sv);
}

void
Expand Down
17 changes: 8 additions & 9 deletions src/iocore/cache/unit_tests/test_Alternate_L_to_S_remove_S.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#include "main.h"

using namespace std::literals;

int cache_vols = 1;
bool reuse_existing_cache = false;

Expand Down Expand Up @@ -80,9 +82,8 @@ class CacheAltReadAgain2 : public CacheTestHandler
REQUIRE(rt);
MIMEField *field = rt->read_http_info->m_alt->m_response_hdr.field_find(MIME_FIELD_CONTENT_TYPE, MIME_LEN_CONTENT_TYPE);
REQUIRE(field);
int len;
const char *value = field->value_get(&len);
REQUIRE(memcmp(value, "text/html;charset=utf-8", len) == 0);
auto value{field->value_get()};
REQUIRE(value == "text/html;charset=utf-8"sv);
}
};

Expand Down Expand Up @@ -134,9 +135,8 @@ class CacheAltReadAgain : public CacheTestHandler
REQUIRE(rt);
MIMEField *field = rt->read_http_info->m_alt->m_response_hdr.field_find(MIME_FIELD_CONTENT_TYPE, MIME_LEN_CONTENT_TYPE);
REQUIRE(field);
int len;
const char *value = field->value_get(&len);
REQUIRE(memcmp(value, "text/html;charset=utf-8", len) == 0);
auto value{field->value_get()};
REQUIRE(value == "text/html;charset=utf-8"sv);
}
};

Expand Down Expand Up @@ -214,9 +214,8 @@ class CacheAltTest_L_to_S_remove_S : public CacheTestHandler
REQUIRE(rt);
MIMEField *field = rt->read_http_info->m_alt->m_response_hdr.field_find(MIME_FIELD_CONTENT_TYPE, MIME_LEN_CONTENT_TYPE);
REQUIRE(field);
int len;
const char *value = field->value_get(&len);
REQUIRE(memcmp(value, "application/x-javascript", len) == 0);
auto value{field->value_get()};
REQUIRE(value == "application/x-javascript"sv);
}

void
Expand Down
12 changes: 6 additions & 6 deletions src/iocore/cache/unit_tests/test_Alternate_S_to_L.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#include "main.h"

using namespace std::literals;

int cache_vols = 1;
bool reuse_existing_cache = false;

Expand Down Expand Up @@ -76,9 +78,8 @@ class CacheAltReadAgain : public CacheTestHandler
REQUIRE(rt);
MIMEField *field = rt->read_http_info->m_alt->m_response_hdr.field_find(MIME_FIELD_CONTENT_TYPE, MIME_LEN_CONTENT_TYPE);
REQUIRE(field);
int len;
const char *value = field->value_get(&len);
REQUIRE(memcmp(value, "text/html;charset=utf-8", len) == 0);
auto value{field->value_get()};
REQUIRE(value == "text/html;charset=utf-8"sv);
}
};

Expand Down Expand Up @@ -158,9 +159,8 @@ class CacheAltTest_L_to_S : public CacheTestHandler
REQUIRE(rt);
MIMEField *field = rt->read_http_info->m_alt->m_response_hdr.field_find(MIME_FIELD_CONTENT_TYPE, MIME_LEN_CONTENT_TYPE);
REQUIRE(field);
int len;
const char *value = field->value_get(&len);
REQUIRE(memcmp(value, "application/x-javascript", len) == 0);
auto value{field->value_get()};
REQUIRE(value == "application/x-javascript"sv);
}
};

Expand Down
17 changes: 8 additions & 9 deletions src/iocore/cache/unit_tests/test_Alternate_S_to_L_remove_L.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "main.h"
#include "../P_CacheInternal.h"

using namespace std::literals;

int cache_vols = 1;
bool reuse_existing_cache = false;

Expand Down Expand Up @@ -81,9 +83,8 @@ class CacheAltReadAgain2 : public CacheTestHandler
REQUIRE(rt);
MIMEField *field = rt->read_http_info->m_alt->m_response_hdr.field_find(MIME_FIELD_CONTENT_TYPE, MIME_LEN_CONTENT_TYPE);
REQUIRE(field);
int len;
const char *value = field->value_get(&len);
REQUIRE(memcmp(value, "text/html;charset=utf-8", len) == 0);
auto value{field->value_get()};
REQUIRE(value == "text/html;charset=utf-8"sv);
}
};

Expand Down Expand Up @@ -136,9 +137,8 @@ class CacheAltReadAgain : public CacheTestHandler
REQUIRE(rt);
MIMEField *field = rt->read_http_info->m_alt->m_response_hdr.field_find(MIME_FIELD_CONTENT_TYPE, MIME_LEN_CONTENT_TYPE);
REQUIRE(field);
int len;
const char *value = field->value_get(&len);
REQUIRE(memcmp(value, "text/html;charset=utf-8", len) == 0);
auto value{field->value_get()};
REQUIRE(value == "text/html;charset=utf-8"sv);
}
};

Expand Down Expand Up @@ -218,9 +218,8 @@ class CacheAltTest_S_to_L_remove_L : public CacheTestHandler
REQUIRE(rt);
MIMEField *field = rt->read_http_info->m_alt->m_response_hdr.field_find(MIME_FIELD_CONTENT_TYPE, MIME_LEN_CONTENT_TYPE);
REQUIRE(field);
int len;
const char *value = field->value_get(&len);
REQUIRE(memcmp(value, "application/x-javascript", len) == 0);
auto value{field->value_get()};
REQUIRE(value == "application/x-javascript"sv);
}

void
Expand Down
17 changes: 8 additions & 9 deletions src/iocore/cache/unit_tests/test_Alternate_S_to_L_remove_S.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "main.h"
#include "../P_CacheInternal.h"

using namespace std::literals;

int cache_vols = 1;
bool reuse_existing_cache = false;

Expand Down Expand Up @@ -88,9 +90,8 @@ class CacheAltReadAgain2 : public CacheTestHandler
REQUIRE(rt);
MIMEField *field = rt->read_http_info->m_alt->m_response_hdr.field_find(MIME_FIELD_CONTENT_TYPE, MIME_LEN_CONTENT_TYPE);
REQUIRE(field);
int len;
const char *value = field->value_get(&len);
REQUIRE(memcmp(value, "application/x-javascript", len) == 0);
auto value{field->value_get()};
REQUIRE(value == "application/x-javascript"sv);
}
};

Expand Down Expand Up @@ -134,9 +135,8 @@ class CacheAltReadAgain : public CacheTestHandler
REQUIRE(rt);
MIMEField *field = rt->read_http_info->m_alt->m_response_hdr.field_find(MIME_FIELD_CONTENT_TYPE, MIME_LEN_CONTENT_TYPE);
REQUIRE(field);
int len;
const char *value = field->value_get(&len);
REQUIRE(memcmp(value, "text/html;charset=utf-8", len) == 0);
auto value{field->value_get()};
REQUIRE(value == "text/html;charset=utf-8"sv);
}
};

Expand Down Expand Up @@ -216,9 +216,8 @@ class test_Alternate_S_to_L_remove_S : public CacheTestHandler
REQUIRE(rt);
MIMEField *field = rt->read_http_info->m_alt->m_response_hdr.field_find(MIME_FIELD_CONTENT_TYPE, MIME_LEN_CONTENT_TYPE);
REQUIRE(field);
int len;
const char *value = field->value_get(&len);
REQUIRE(memcmp(value, "application/x-javascript", len) == 0);
auto value{field->value_get()};
REQUIRE(value == "application/x-javascript"sv);
}

void
Expand Down
7 changes: 4 additions & 3 deletions src/iocore/cache/unit_tests/test_Update_header.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#include "main.h"

using namespace std::literals;

int cache_vols = 1;
bool reuse_existing_cache = false;

Expand Down Expand Up @@ -83,9 +85,8 @@ class CacheUpdateReadAgain : public CacheTestHandler
REQUIRE(rt);
MIMEField *field = rt->read_http_info->m_alt->m_response_hdr.field_find(MIME_FIELD_CONTENT_TYPE, MIME_LEN_CONTENT_TYPE);
REQUIRE(field);
int len;
const char *value = field->value_get(&len);
REQUIRE(memcmp(value, "application/x-javascript", len) == 0);
auto value{field->value_get()};
REQUIRE(value == "application/x-javascript"sv);
}

void
Expand Down
Loading