Skip to content
Closed
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
3 changes: 3 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ DISTCLEANFILES = redhat/SOURCES/* redhat/SPEC/* redhat/RPMS/* redhat/SRPMS/* red
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libhttpserver.pc

cmakemoduledir = $(datadir)/cmake/Modules
cmakemodule_DATA = cmakemodule/FindLibHttpServer.cmake

include $(top_srcdir)/aminclude.am

# Update libtool, if needed.
Expand Down
1 change: 1 addition & 0 deletions ebuild/net-libs/libhttpserver/Manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EBUILD libhttpserver-9999.ebuild 801 SHA256 339a46d12470a896c3068cee951e62bba0ddd6205629af7c81092766ba02e081 SHA512 2395d7c34eb0553ac78871dc0d18c9e83929d0a301c9e46227bc90961e324ee80afadb151cf8936f8cff157a271d7b0bd503e3129e8012d7ca784d5f5ab19678 WHIRLPOOL cce855b6906df88c6923bdc5f291a418ca96d95d4e3595b26b34fb0f2ca09ac9bd6da5b7b1822d6fa69c79694ee89ee261b2bb33d4c1096ac424c42e428eb733
39 changes: 39 additions & 0 deletions ebuild/net-libs/libhttpserver/libhttpserver-9999.ebuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI="4"

inherit git-r3

FORK="vozhyk-" # use "etr" for original version

DESCRIPTION="C++ library for creating an embedded Rest HTTP server (and more)"
HOMEPAGE="http://github.com/${FORK}/${PN}"
EGIT_REPO_URI="git://github.com/${FORK}/${PN}.git"

LICENSE="LGPL-2.1"
SLOT="0"
KEYWORDS="~amd64"
IUSE="debug"

RDEPEND=">=net-libs/libmicrohttpd-0.9.37"
DEPEND="${RDEPEND}"

src_configure() {
./bootstrap

mkdir build
cd build && ECONF_SOURCE=.. econf \
$(use_enable debug) \
--disable-doxygen-doc # no useflag for now
# TODO configure checks for TLS
}

src_compile() {
cd build && emake
}

src_install() {
cd build && emake DESTDIR="${D}" install
}
11 changes: 8 additions & 3 deletions src/http_response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ http_response::http_response(const http_response_builder& builder):
ca(0x0),
closure_data(0x0),
ce(builder._ce),
cycle_callback(builder._cycle_callback),
data_callback(builder._data_callback),
get_raw_response(this, builder._get_raw_response),
decorate_response(this, builder._decorate_response),
enqueue_response(this, builder._enqueue_response),
Expand Down Expand Up @@ -207,12 +207,17 @@ namespace details

ssize_t cb(void* cls, uint64_t pos, char* buf, size_t max)
{
ssize_t val = static_cast<http_response*>(cls)->cycle_callback(buf, max);
ssize_t val = (*static_cast<http_response*>(cls)->data_callback)(buf, max);
if(val == -1)
static_cast<http_response*>(cls)->completed = true;
return val;
}

void free_cb(void* cls)
{
delete static_cast<http_response*>(cls)->data_callback;
}

}

void http_response::get_raw_response_deferred(
Expand All @@ -226,7 +231,7 @@ void http_response::get_raw_response_deferred(
1024,
&details::cb,
this,
NULL
&details::free_cb
);
else
static_cast<http_response*>(this)->get_raw_response(response, ws);
Expand Down
24 changes: 21 additions & 3 deletions src/httpserver/http_response.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace details
{
struct http_response_ptr;
ssize_t cb(void*, uint64_t, char*, size_t);
void free_cb(void*);
struct cache_entry;
};

Expand All @@ -62,7 +63,23 @@ class bad_caching_attempt: public std::exception
}
};

typedef ssize_t(*cycle_callback_ptr)(char*, size_t);
/**
* Callback called to obtain data from a deferred_response
**/
class data_callback
{
public:
/**
* @param buf Buffer to copy data to
* @param max Maximum number of bytes allowed to be copied
* @return number of bytes copied, or
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be improved by mirroring MHD documentation

* -1 for end of stream, or
* -2 for end with error
**/
virtual ssize_t operator() (char* buf, size_t max) = 0;

virtual ~data_callback() {}
};

/**
* Class representing an abstraction for an Http Response. It is used from classes using these apis to send information through http protocol.
Expand Down Expand Up @@ -97,7 +114,7 @@ class http_response
ca(0x0),
closure_data(0x0),
ce(b.ce),
cycle_callback(b.cycle_callback),
data_callback(b.data_callback),
get_raw_response(b.get_raw_response),
decorate_response(b.decorate_response),
enqueue_response(b.enqueue_response),
Expand Down Expand Up @@ -259,7 +276,7 @@ class http_response
void(*ca)(void*);
void* closure_data;
details::cache_entry* ce;
cycle_callback_ptr cycle_callback;
class data_callback* data_callback;

const get_raw_response_t get_raw_response;
const decorate_response_t decorate_response;
Expand Down Expand Up @@ -298,6 +315,7 @@ class http_response
friend class http_response_builder;
friend void clone_response(const http_response& hr, http_response** dhr);
friend ssize_t details::cb(void* cls, uint64_t pos, char* buf, size_t max);
friend void details::free_cb(void* cls);
friend std::ostream &operator<< (std::ostream &os, const http_response &r);
private:
http_response& operator=(const http_response& b);
Expand Down
12 changes: 9 additions & 3 deletions src/httpserver/http_response_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class http_response_builder
_keepalive_secs(-1),
_keepalive_msg(""),
_send_topic(""),
_data_callback(NULL),
_ce(0x0),
_get_raw_response(&http_response::get_raw_response_str),
_decorate_response(&http_response::decorate_response_str),
Expand Down Expand Up @@ -120,6 +121,7 @@ class http_response_builder
_keepalive_secs(-1),
_keepalive_msg(""),
_send_topic(""),
_data_callback(NULL),
_ce(0x0),
_get_raw_response(&http_response::get_raw_response_str),
_decorate_response(&http_response::decorate_response_str),
Expand All @@ -142,6 +144,9 @@ class http_response_builder
_keepalive_secs(b._keepalive_secs),
_keepalive_msg(b._keepalive_msg),
_send_topic(b._send_topic),
// Is copying the pointer a good idea?
// (since it is deleted in details::free_cb)
_data_callback(b._data_callback),
_ce(b._ce),
_get_raw_response(b._get_raw_response),
_decorate_response(b._decorate_response),
Expand All @@ -164,6 +169,7 @@ class http_response_builder
_keepalive_secs = b._keepalive_secs;
_keepalive_msg = b._keepalive_msg;
_send_topic = b._send_topic;
_data_callback = b._data_callback;
_ce = b._ce;
_get_raw_response = b._get_raw_response;
_decorate_response = b._decorate_response;
Expand Down Expand Up @@ -233,9 +239,9 @@ class http_response_builder
return *this;
}

http_response_builder& deferred_response(cycle_callback_ptr cycle_callback)
http_response_builder& deferred_response(data_callback* data_callback)
{
_cycle_callback = cycle_callback;
_data_callback = data_callback;
_get_raw_response = &http_response::get_raw_response_deferred;
_decorate_response = &http_response::decorate_response_deferred;
return *this;
Expand Down Expand Up @@ -276,7 +282,7 @@ class http_response_builder
int _keepalive_secs;
std::string _keepalive_msg;
std::string _send_topic;
cycle_callback_ptr _cycle_callback;
data_callback* _data_callback;
details::cache_entry* _ce;

void (http_response::*_get_raw_response)(MHD_Response**, webserver*);
Expand Down