Skip to content
Merged
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
31 changes: 0 additions & 31 deletions include/tscore/ink_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ can_safely_shift_left(T value, int num_places)

@see ats_scoped_fd
@see ats_scoped_mem
@see ats_scoped_obj

For example, if you open a file descriptor and have to do other checks which result in having to call
@c close in each @c if clause.
Expand Down Expand Up @@ -585,36 +584,6 @@ class ats_scoped_mem : public ats_scoped_resource<detail::SCOPED_MALLOC_TRAITS<T
}
};

/** Specialization of @c ats_scoped_resource for objects.
This handles a pointer to an object created by @c new and destroyed by @c delete.
*/

template <typename T /// Underlying (not pointer) type.
>
class ats_scoped_obj : public ats_scoped_resource<detail::SCOPED_OBJECT_TRAITS<T>>
{
public:
typedef ats_scoped_resource<detail::SCOPED_OBJECT_TRAITS<T>> super; ///< Super type.
typedef ats_scoped_obj self; ///< Self reference.

/// Default constructor - an empty container.
ats_scoped_obj() : super() {}
/// Construct with contained resource.
explicit ats_scoped_obj(T *obj) : super(obj) {}
self &
operator=(T *obj)
{
super::operator=(obj);
return *this;
}

T *
operator->() const
{
return *this;
}
};

/** Combine two strings as file paths.
Trailing and leading separators for @a lhs and @a rhs respectively
are handled to yield exactly one separator.
Expand Down
5 changes: 3 additions & 2 deletions iocore/net/SSLSessionCache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "SSLStats.h"

#include <cstring>
#include <memory>

#define SSLSESSIONCACHE_STRINGIFY0(x) #x
#define SSLSESSIONCACHE_STRINGIFY(x) SSLSESSIONCACHE_STRINGIFY0(x)
Expand Down Expand Up @@ -160,7 +161,7 @@ SSLSessionBucket::insertSession(const SSLSessionID &id, SSL_SESSION *sess, SSL *
// This could be moved to a function in charge of populating exdata
exdata->curve = (ssl == nullptr) ? 0 : SSLGetCurveNID(ssl);

ats_scoped_obj<SSLSession> ssl_session(new SSLSession(id, buf, len, buf_exdata));
std::unique_ptr<SSLSession> ssl_session(new SSLSession(id, buf, len, buf_exdata));

std::unique_lock w_lock(mutex, std::try_to_lock);
if (!w_lock.owns_lock()) {
Expand Down Expand Up @@ -351,7 +352,7 @@ SSLOriginSessionCache::insert_session(const std::string &lookup_key, SSL_SESSION
// Create the shared pointer to the session, with the custom deleter
std::shared_ptr<SSL_SESSION> shared_sess(sess_ptr, SSLSessDeleter);
ssl_curve_id curve = (ssl == nullptr) ? 0 : SSLGetCurveNID(ssl);
ats_scoped_obj<SSLOriginSession> ssl_orig_session(new SSLOriginSession(lookup_key, curve, shared_sess));
std::unique_ptr<SSLOriginSession> ssl_orig_session(new SSLOriginSession(lookup_key, curve, shared_sess));
auto new_node = ssl_orig_session.release();

std::unique_lock lock(mutex);
Expand Down
2 changes: 1 addition & 1 deletion plugins/experimental/sslheaders/sslheaders.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ SslHdrParseOptions(int argc, const char **argv)
{nullptr, 0, nullptr, 0},
};

ats_scoped_obj<SslHdrInstance> hdr(new SslHdrInstance());
std::unique_ptr<SslHdrInstance> hdr(new SslHdrInstance());

for (;;) {
int opt;
Expand Down
34 changes: 20 additions & 14 deletions proxy/http2/unit_tests/test_HpackIndexingTable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
limitations under the License.
*/

#include <memory>

#include "catch.hpp"

#include "HPACK.h"
Expand Down Expand Up @@ -69,7 +71,7 @@ TEST_CASE("HPACK low level APIs", "[hpack]")
HpackIndexingTable indexing_table(4096);

for (const auto &i : indexed_test_case) {
ats_scoped_obj<HTTPHdr> headers(new HTTPHdr);
std::unique_ptr<HTTPHdr> headers(new HTTPHdr);
headers->create(HTTP_TYPE_REQUEST);
MIMEField *field = mime_field_create(headers->m_heap, headers->m_http->m_fields_impl);
MIMEFieldWrapper header(field, headers->m_heap, headers->m_http->m_fields_impl);
Expand Down Expand Up @@ -222,7 +224,7 @@ TEST_CASE("HPACK low level APIs", "[hpack]")
HpackIndexingTable indexing_table(4096);

for (const auto &i : literal_test_case) {
ats_scoped_obj<HTTPHdr> headers(new HTTPHdr);
std::unique_ptr<HTTPHdr> headers(new HTTPHdr);
headers->create(HTTP_TYPE_REQUEST);
MIMEField *field = mime_field_create(headers->m_heap, headers->m_http->m_fields_impl);
MIMEFieldWrapper header(field, headers->m_heap, headers->m_http->m_fields_impl);
Expand Down Expand Up @@ -347,7 +349,7 @@ TEST_CASE("HPACK high level APIs", "[hpack]")
indexing_table.update_maximum_size(DYNAMIC_TABLE_SIZE_FOR_REGRESSION_TEST);

for (unsigned int i = 0; i < sizeof(encoded_field_response_test_case) / sizeof(encoded_field_response_test_case[0]); i++) {
ats_scoped_obj<HTTPHdr> headers(new HTTPHdr);
std::unique_ptr<HTTPHdr> headers(new HTTPHdr);
headers->create(HTTP_TYPE_RESPONSE);

for (unsigned int j = 0; j < sizeof(raw_field_response_test_case[i]) / sizeof(raw_field_response_test_case[i][0]); j++) {
Expand All @@ -365,7 +367,7 @@ TEST_CASE("HPACK high level APIs", "[hpack]")

memset(buf, 0, BUFSIZE_FOR_REGRESSION_TEST);
uint64_t buf_len = BUFSIZE_FOR_REGRESSION_TEST;
int64_t len = hpack_encode_header_block(indexing_table, buf, buf_len, headers);
int64_t len = hpack_encode_header_block(indexing_table, buf, buf_len, headers.get());

REQUIRE(len > 0);
REQUIRE(len == encoded_field_response_test_case[i].encoded_field_len);
Expand Down Expand Up @@ -453,10 +455,10 @@ TEST_CASE("HPACK high level APIs", "[hpack]")
HpackIndexingTable indexing_table(4096);

for (unsigned int i = 0; i < sizeof(encoded_field_request_test_case) / sizeof(encoded_field_request_test_case[0]); i++) {
ats_scoped_obj<HTTPHdr> headers(new HTTPHdr);
std::unique_ptr<HTTPHdr> headers(new HTTPHdr);
headers->create(HTTP_TYPE_REQUEST);

hpack_decode_header_block(indexing_table, headers, encoded_field_request_test_case[i].encoded_field,
hpack_decode_header_block(indexing_table, headers.get(), encoded_field_request_test_case[i].encoded_field,
encoded_field_request_test_case[i].encoded_field_len, MAX_REQUEST_HEADER_SIZE, MAX_TABLE_SIZE);

for (unsigned int j = 0; j < sizeof(raw_field_request_test_case[i]) / sizeof(raw_field_request_test_case[i][0]); j++) {
Expand Down Expand Up @@ -486,53 +488,57 @@ TEST_CASE("HPACK high level APIs", "[hpack]")

// add entries in dynamic table
{
ats_scoped_obj<HTTPHdr> headers(new HTTPHdr);
std::unique_ptr<HTTPHdr> headers(new HTTPHdr);
headers->create(HTTP_TYPE_REQUEST);

// C.3.1. First Request
uint8_t data[] = {0x82, 0x86, 0x84, 0x41, 0x0f, 0x77, 0x77, 0x77, 0x2e, 0x65,
0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d};

int64_t len = hpack_decode_header_block(indexing_table, headers, data, sizeof(data), MAX_REQUEST_HEADER_SIZE, MAX_TABLE_SIZE);
int64_t len =
hpack_decode_header_block(indexing_table, headers.get(), data, sizeof(data), MAX_REQUEST_HEADER_SIZE, MAX_TABLE_SIZE);
CHECK(len == sizeof(data));
CHECK(indexing_table.maximum_size() == 4096);
CHECK(indexing_table.size() == 57);
}

// clear all entries by setting a maximum size of 0
{
ats_scoped_obj<HTTPHdr> headers(new HTTPHdr);
std::unique_ptr<HTTPHdr> headers(new HTTPHdr);
headers->create(HTTP_TYPE_REQUEST);

uint8_t data[] = {0x20};

int64_t len = hpack_decode_header_block(indexing_table, headers, data, sizeof(data), MAX_REQUEST_HEADER_SIZE, MAX_TABLE_SIZE);
int64_t len =
hpack_decode_header_block(indexing_table, headers.get(), data, sizeof(data), MAX_REQUEST_HEADER_SIZE, MAX_TABLE_SIZE);
CHECK(len == sizeof(data));
CHECK(indexing_table.maximum_size() == 0);
CHECK(indexing_table.size() == 0);
}

// make the maximum size back to 4096
{
ats_scoped_obj<HTTPHdr> headers(new HTTPHdr);
std::unique_ptr<HTTPHdr> headers(new HTTPHdr);
headers->create(HTTP_TYPE_REQUEST);

uint8_t data[] = {0x3f, 0xe1, 0x1f};

int64_t len = hpack_decode_header_block(indexing_table, headers, data, sizeof(data), MAX_REQUEST_HEADER_SIZE, MAX_TABLE_SIZE);
int64_t len =
hpack_decode_header_block(indexing_table, headers.get(), data, sizeof(data), MAX_REQUEST_HEADER_SIZE, MAX_TABLE_SIZE);
CHECK(len == sizeof(data));
CHECK(indexing_table.maximum_size() == 4096);
CHECK(indexing_table.size() == 0);
}

// error with exceeding the limit (MAX_TABLE_SIZE)
{
ats_scoped_obj<HTTPHdr> headers(new HTTPHdr);
std::unique_ptr<HTTPHdr> headers(new HTTPHdr);
headers->create(HTTP_TYPE_REQUEST);

uint8_t data[] = {0x3f, 0xe2, 0x1f};

int64_t len = hpack_decode_header_block(indexing_table, headers, data, sizeof(data), MAX_REQUEST_HEADER_SIZE, MAX_TABLE_SIZE);
int64_t len =
hpack_decode_header_block(indexing_table, headers.get(), data, sizeof(data), MAX_REQUEST_HEADER_SIZE, MAX_TABLE_SIZE);
CHECK(len == HPACK_ERROR_COMPRESSION_ERROR);
}
}
Expand Down
15 changes: 9 additions & 6 deletions proxy/logging/LogFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@


***************************************************************************/

#include <memory>

#include "tscore/ink_platform.h"

#include "LogUtils.h"
Expand Down Expand Up @@ -69,7 +72,7 @@ LogFilter *
LogFilter::parse(const char *name, Action action, const char *condition)
{
SimpleTokenizer tok(condition);
ats_scoped_obj<LogField> logfield;
std::unique_ptr<LogField> logfield;

ink_release_assert(action != N_ACTIONS);

Expand All @@ -95,7 +98,7 @@ LogFilter::parse(const char *name, Action action, const char *condition)
}

if (LogField *f = Log::global_field_list.find_by_symbol(field_str)) {
logfield = new LogField(*f);
logfield.reset(new LogField(*f));
}

if (!logfield) {
Expand Down Expand Up @@ -127,7 +130,7 @@ LogFilter::parse(const char *name, Action action, const char *condition)
return nullptr;
}

logfield = new LogField(fname, container);
logfield.reset(new LogField(fname, container));
ink_assert(logfield != nullptr);
}
}
Expand Down Expand Up @@ -157,19 +160,19 @@ LogFilter::parse(const char *name, Action action, const char *condition)

switch (field_type) {
case LogField::sINT:
filter = new LogFilterInt(name, logfield, action, oper, val_str);
filter = new LogFilterInt(name, logfield.get(), action, oper, val_str);
break;

case LogField::dINT:
Error("Invalid field type (double int); cannot create filter '%s'", name);
return nullptr;

case LogField::STRING:
filter = new LogFilterString(name, logfield, action, oper, val_str);
filter = new LogFilterString(name, logfield.get(), action, oper, val_str);
break;

case LogField::IP:
filter = new LogFilterIP(name, logfield, action, oper, val_str);
filter = new LogFilterIP(name, logfield.get(), action, oper, val_str);
break;

default:
Expand Down