summaryrefslogtreecommitdiff
path: root/datastore-leveldb/src
diff options
context:
space:
mode:
Diffstat (limited to 'datastore-leveldb/src')
-rw-r--r--datastore-leveldb/src/web.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/datastore-leveldb/src/web.cpp b/datastore-leveldb/src/web.cpp
index 125a4ad..d938a66 100644
--- a/datastore-leveldb/src/web.cpp
+++ b/datastore-leveldb/src/web.cpp
@@ -11,10 +11,18 @@ static inline uint64_t now() {
std::chrono::high_resolution_clock::now().time_since_epoch()).count();
}
+inline void strToL(unsigned long int *l, std::string s) {
+ *l = std::stoul(s);
+}
+inline void strToL(unsigned long long int *l, std::string s) {
+ *l = std::stoull(s);
+}
+
+
static inline bool parse_key(leveldb::Slice &&key, uint64_t *value) {
if (key.size() != 20+3)
return false;
- *value = std::stoul(key.data()+3);
+ strToL(value, key.data()+3);
return true;
}
@@ -38,7 +46,7 @@ const boost::regex web_handle_api_value_timestamp_R(
"/api/value/([a-zA-Z0-9\\.]+)/([0-9]+)");
void web_handle_api_value_timestamp(const boost::cmatch &match, struct mg_connection *conn) {
std::string sensor(match[1].str());
- uint64_t timestamp = std::stoul(match[2].str());
+ uint64_t timestamp; strToL(&timestamp, match[2].str());
char buf[1024];
int bytesRead = mg_read(conn, buf, 1024);
std::string value(buf, bytesRead);
@@ -80,8 +88,8 @@ const boost::regex web_handle_api_range_R(
"/api/range/([a-zA-Z0-9\\.]+)/([0-9]+)/([0-9]+)");
void web_handle_api_range(const boost::cmatch &match, struct mg_connection *conn) {
std::string sensor(match[1].str());
- uint64_t start = std::stoul(match[2].str());
- uint64_t end = std::stoul(match[3].str());
+ uint64_t start; strToL(&start, match[2].str());
+ uint64_t end; strToL(&end, match[3].str());
std::string key_start(std::move(make_key(start)));
std::string key_end(std::move(make_key(end)));
@@ -122,9 +130,9 @@ const boost::regex web_handle_api_range_size_R(
"/api/range/([a-zA-Z0-9\\.]+)/([0-9]+)/([0-9]+)/([0-9]+)");
void web_handle_api_range_size(const boost::cmatch &match, struct mg_connection *conn) {
std::string sensor(match[1].str());
- uint64_t start = std::stoul(match[2].str());
- uint64_t end = std::stoul(match[3].str());
- uint64_t size = std::stoul(match[4].str());
+ uint64_t start; strToL(&start, match[2].str());
+ uint64_t end; strToL(&end, match[3].str());
+ uint64_t size; strToL(&size, match[4].str());
leveldb::DB *db = getDB(sensor);
if (db == nullptr) {
@@ -152,7 +160,7 @@ void web_handle_api_range_size(const boost::cmatch &match, struct mg_connection
uint64_t actual_size = 0;
std::ostringstream outbuf;
leveldb::Iterator* it = db->NewIterator(leveldb::ReadOptions());
- for (uint64_t key = start; key <= end; key += step) {
+ for (uint64_t key = start; key < end; key += step) {
it->Seek(make_key(key));
if (!it->Valid()) continue;