Commit 9a7ba8d0 authored by Adrien Béraud's avatar Adrien Béraud Committed by gerrit2

namedirectory: optional use of old restbed API

Reviewed-by: default avatarAlexandre Viau <alexandre@alexandreviau.net>
Change-Id: I9b95dd1e061717f390e4fd5d5209b2aebe18dc9c
parent 99d138d1
......@@ -393,6 +393,10 @@ AC_DEFINE_UNQUOTED([HAVE_RINGNS], `if test "x$enable_ringns" != "xno"; then echo
# Rest C++ with restbed
AC_ARG_WITH([restcpp],
AS_HELP_STRING([--with-restcpp], [enable rest support with C++]))
AC_ARG_ENABLE([restbed_old_api], AS_HELP_STRING([--enable-restbed-old-api], [Use the old restbed API]))
AS_IF([test "x$enable_restbed_old_api" = "xyes"], [
AC_DEFINE([RESTBED_OLD_API], [], [Defined if you use the old restbed API])
])
AS_IF([test "x$enable_ringns" != "xno" || test "x$with_restcpp" = "xyes"],
AC_CHECK_LIB(restbed, exit,, AC_MSG_ERROR([Missing restbed files])));
......
......@@ -58,6 +58,16 @@ NameDirectory& NameDirectory::instance(const std::string& server)
return it.first->second;
}
size_t getContentLength(restbed::Response& reply)
{
size_t length = 0;
#ifndef RESTBED_OLD_API
length =
#endif
reply.get_header("Content-Length", length);
return length;
}
void NameDirectory::lookupAddress(const std::string& addr, LookupCallback cb)
{
auto cacheRes = nameCache_.find(addr);
......@@ -76,8 +86,7 @@ void NameDirectory::lookupAddress(const std::string& addr, LookupCallback cb)
auto ret = restbed::Http::async(req, [this,cb,addr](const std::shared_ptr<restbed::Request>,
const std::shared_ptr<restbed::Response> reply) {
if (reply->get_status_code() == 200) {
size_t length = 0;
length = reply->get_header("Content-Length", length);
size_t length = getContentLength(*reply);
if (length > MAX_RESPONSE_SIZE) {
cb("", Response::error);
return;
......@@ -139,8 +148,7 @@ void NameDirectory::lookupName(const std::string& name, LookupCallback cb)
if (code != 200)
RING_DBG("Name lookup for %s: got reply code %d", name.c_str(), code);
if (code >= 200 && code < 300) {
size_t length = 0;
length = reply->get_header("Content-Length", length);
size_t length = getContentLength(*reply);
if (length > MAX_RESPONSE_SIZE) {
cb("", Response::error);
return;
......@@ -224,8 +232,7 @@ void NameDirectory::registerName(const std::string& addr, const std::string& nam
auto code = reply->get_status_code();
RING_DBG("Got reply for registration of %s -> %s: code %d", name.c_str(), addr.c_str(), code);
if (code >= 200 && code < 300) {
size_t length = 0;
length = reply->get_header("Content-Length", length);
size_t length = getContentLength(*reply);
if (length > MAX_RESPONSE_SIZE) {
cb(RegistrationResponse::error);
return;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment