Skip to content

Commit 5f025bd

Browse files
committed
Merge branch 'dev' of github.com:hioa-cs/IncludeOS
2 parents 18b3656 + 12d871c commit 5f025bd

7 files changed

Lines changed: 128 additions & 15 deletions

File tree

api/isotime

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// -*-C++-*-
2+
// This file is a part of the IncludeOS unikernel - www.includeos.org
3+
//
4+
// Copyright 2017 Oslo and Akershus University College of Applied Sciences
5+
// and Alfred Bratterud
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
19+
#pragma once
20+
#ifndef API_ISOTIME_HEADER
21+
#define API_ISOTIME_HEADER
22+
23+
#include "util/isotime.hpp"
24+
25+
#endif

api/util/isotime.hpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// This file is a part of the IncludeOS unikernel - www.includeos.org
2+
//
3+
// Copyright 2017 Oslo and Akershus University College of Applied Sciences
4+
// and Alfred Bratterud
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
#pragma once
19+
#ifndef UTIL_ISOTIME_HPP
20+
#define UTIL_ISOTIME_HPP
21+
22+
#include <ctime>
23+
#include <string>
24+
25+
namespace isotime
26+
{
27+
/**
28+
* @brief Returns a ISO 8601 UTC datetime string.
29+
* Example: 2017-04-10T13:37:00Z
30+
*
31+
* @param[in] ts A timestamp
32+
*
33+
* @return An ISO datetime string, formatted as "YYYY-MM-DDThh:mm:ssZ"
34+
*/
35+
std::string to_datetime_string(time_t ts)
36+
{
37+
char buf[sizeof "2017-04-10T13:37:00Z"];
38+
strftime(buf, sizeof buf, "%FT%TZ", gmtime(&ts));
39+
return buf;
40+
}
41+
42+
/**
43+
* @brief Returns the current time as a datetime according "to_datetime_string"
44+
*
45+
* @return A datetime string representing now
46+
*/
47+
std::string now()
48+
{
49+
return to_datetime_string(time(0));
50+
}
51+
}
52+
53+
#endif
54+
55+
56+

cmake/botan.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
include(ExternalProject)
55
ExternalProject_Add(botan
66
PREFIX botan
7-
URL https://github.com/includeos/botan/releases/download/inc-2.0/botan-includeos.tar.gz
7+
URL https://github.com/includeos/botan/releases/download/inc-2.0/botan-includeos-i686.tar.gz
88
URL_HASH MD5=5ef7f26047f8fe17219f62755938621d
99
CONFIGURE_COMMAND ""
1010
BUILD_COMMAND ""

examples/acorn/service.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,10 @@ Disk_ptr disk;
3939

4040
#include <time.h>
4141

42-
// Get current date/time, format is [YYYY-MM-DD.HH:mm:ss]
43-
const std::string timestamp() {
44-
time_t now = time(0);
45-
struct tm tstruct;
46-
char buf[80];
47-
tstruct = *localtime(&now);
48-
// Visit http://en.cppreference.com/w/cpp/chrono/c/strftime
49-
// for more information about date/time format
50-
strftime(buf, sizeof(buf), "[%Y-%m-%d.%X] ", &tstruct);
51-
52-
return buf;
53-
}
42+
#include <isotime>
43+
// Get current date/time, format is [YYYY-MM-DDTHH:mm:ssZ]
44+
const std::string timestamp()
45+
{ return "[" + isotime::now() + "] "; }
5446

5547
#include <net/inet4>
5648

@@ -153,7 +145,7 @@ void Service::start(const std::string&) {
153145
router.use("/api/dashboard", dashboard_->router());
154146

155147
// Fallback route for angular application - serve index.html if route is not found
156-
router.on_get("/app/.*",
148+
router.on_get("/app/.*",
157149
[&fs](auto, auto res) {
158150
#ifdef VERBOSE_WEBSERVER
159151
printf("[@GET:/app/*] Fallback route - try to serve index.html\n");

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ set(TEST_SOURCES
9393
${TEST}/util/unit/delegate.cpp
9494
${TEST}/util/unit/fixed_queue.cpp
9595
${TEST}/util/unit/fixed_vector.cpp
96+
${TEST}/util/unit/isotime.cpp
9697
${TEST}/util/unit/logger_test.cpp
9798
${TEST}/util/unit/membitmap.cpp
9899
${TEST}/util/unit/path_to_regex_no_options.cpp

test/util/unit/isotime.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// This file is a part of the IncludeOS unikernel - www.includeos.org
2+
//
3+
// Copyright 2017 Oslo and Akershus University College of Applied Sciences
4+
// and Alfred Bratterud
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
#include <common.cxx>
19+
#include <isotime>
20+
21+
CASE("A timestamp can be converted into a ISO UTC datetime string")
22+
{
23+
uint64_t beginning = 0;
24+
auto str = isotime::to_datetime_string(beginning);
25+
26+
EXPECT(str == "1970-01-01T00:00:00Z");
27+
28+
uint64_t one_minute_later = 60;
29+
str = isotime::to_datetime_string(one_minute_later);
30+
31+
EXPECT(str == "1970-01-01T00:01:00Z");
32+
33+
uint64_t five_hours_later = 3600*5;
34+
str = isotime::to_datetime_string(five_hours_later);
35+
36+
EXPECT(str == "1970-01-01T05:00:00Z");
37+
38+
// Not gonna bother more due to leap seconds and calendars etc...
39+
}

vmbuild/vmbuild.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <cassert>
2828

2929
#include "../api/boot/multiboot.h"
30-
#include "elf.h"
30+
#include "../api/util/elf.h"
3131
#include "../api/util/elf_binary.hpp"
3232

3333
#define SECT_SIZE 512

0 commit comments

Comments
 (0)