summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2019-05-20 09:15:37 +0000
committerGerrit Code Review <gerrit@fd.io>2019-05-20 09:15:37 +0000
commit7d93a4e00022cc2a46b4580c8befaa629aae4bfc (patch)
tree683ce5941be6e26f455d6ab1661e07bc6e533c13
parent250e5f768a75a62b001c16932e06055fa64a1a27 (diff)
parent90256e9929e11ef720d9e9c6afc4342acacae654 (diff)
Merge "[HICN-200] Minor issue Android"
-rw-r--r--apps/http-server/http-server.cc30
-rw-r--r--libtransport/src/hicn/transport/core/content_object.cc6
-rw-r--r--libtransport/src/hicn/transport/core/interest.cc5
-rw-r--r--libtransport/src/hicn/transport/core/packet.cc5
4 files changed, 43 insertions, 3 deletions
diff --git a/apps/http-server/http-server.cc b/apps/http-server/http-server.cc
index 9d3eac5b8..f5fabf56f 100644
--- a/apps/http-server/http-server.cc
+++ b/apps/http-server/http-server.cc
@@ -287,12 +287,40 @@ int main(int argc, char **argv) {
response->setResponseLifetime(response_lifetime);
- if (_isDirectory(path.c_str())) {
+ if (!_isDirectory(path.c_str())) {
// Check if path is within web_root_path
if (distance(web_root_path.begin(), web_root_path.end()) <=
distance(path.begin(), path.end()) &&
equal(web_root_path.begin(), web_root_path.end(), path.begin())) {
+ if (_isRegularFile(path.c_str())) {
+ auto ifs = make_shared<ifstream>();
+ ifs->open(path, ifstream::in | ios::binary);
+
+ if (*ifs) {
+ // read and send 15 MB at a time
+ streamsize buffer_size = 15 * 1024 * 1024;
+ auto buffer = make_shared<vector<char>>(buffer_size);
+
+ ifs->seekg(0, ios::end);
+ auto length = ifs->tellg();
+ ifs->seekg(0, ios::beg);
+
+ response->setResponseLength(length);
+ *response << "HTTP/1.0 200 OK\r\nContent-Length: " << length
+ << "\r\n\r\n";
+
+ default_resource_send(server, response, ifs, buffer, length);
+
+ return;
+ }
+ }
+ }
+ } else {
+ if (distance(web_root_path.begin(), web_root_path.end()) <=
+ distance(path.begin(), path.end()) &&
+ equal(web_root_path.begin(), web_root_path.end(), path.begin())) {
path += "index.html";
+ std::cout << "path: "<< path <<endl;
if (_isRegularFile(path.c_str())) {
auto ifs = make_shared<ifstream>();
ifs->open(path, ifstream::in | ios::binary);
diff --git a/libtransport/src/hicn/transport/core/content_object.cc b/libtransport/src/hicn/transport/core/content_object.cc
index 107ab8567..764d753cd 100644
--- a/libtransport/src/hicn/transport/core/content_object.cc
+++ b/libtransport/src/hicn/transport/core/content_object.cc
@@ -33,6 +33,7 @@ namespace core {
ContentObject::ContentObject(const Name &name, Packet::Format format)
: Packet(format) {
+
if (TRANSPORT_EXPECT_FALSE(
hicn_data_set_name(format, packet_start_, name.getStructReference()) <
0)) {
@@ -46,8 +47,13 @@ ContentObject::ContentObject(const Name &name, Packet::Format format)
}
}
+#ifdef __ANDROID__
+ContentObject::ContentObject(hicn_format_t format)
+ : ContentObject(Name("0::0|0"), format) {}
+#else
ContentObject::ContentObject(hicn_format_t format)
: ContentObject(Packet::base_name, format) {}
+#endif
ContentObject::ContentObject(const Name &name, hicn_format_t format,
const uint8_t *payload, std::size_t size)
diff --git a/libtransport/src/hicn/transport/core/interest.cc b/libtransport/src/hicn/transport/core/interest.cc
index bd7b57422..e7d47d565 100644
--- a/libtransport/src/hicn/transport/core/interest.cc
+++ b/libtransport/src/hicn/transport/core/interest.cc
@@ -44,7 +44,12 @@ Interest::Interest(const Name &interest_name, Packet::Format format)
}
}
+
+#ifdef __ANDROID__
+Interest::Interest(hicn_format_t format) : Interest(Name("0::0|0"), format) {}
+#else
Interest::Interest(hicn_format_t format) : Interest(base_name, format) {}
+#endif
Interest::Interest(const uint8_t *buffer, std::size_t size)
: Packet(buffer, size) {
diff --git a/libtransport/src/hicn/transport/core/packet.cc b/libtransport/src/hicn/transport/core/packet.cc
index 954266664..04ec74660 100644
--- a/libtransport/src/hicn/transport/core/packet.cc
+++ b/libtransport/src/hicn/transport/core/packet.cc
@@ -29,7 +29,7 @@ namespace transport {
namespace core {
-const core::Name Packet::base_name("0::0|0");
+ const core::Name Packet::base_name("0::0|0");
Packet::Packet(Format format)
: packet_(utils::MemBuf::create(getHeaderSizeFromFormat(format, 256))
@@ -37,7 +37,8 @@ Packet::Packet(Format format)
packet_start_(reinterpret_cast<hicn_header_t *>(packet_->writableData())),
header_head_(packet_.get()),
payload_head_(nullptr),
- format_(format) {
+ format_(format){
+
if (hicn_packet_init_header(format, packet_start_) < 0) {
throw errors::RuntimeException("Unexpected error initializing the packet.");
}