From ed9d76c711bc39aaf6a23545baac808cbdb21cc1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Fri, 10 Apr 2015 14:55:18 -0400
Subject: [PATCH] android: fix build

- bump contrib pcre to 8.36
- add missing C++ std functions
- add missing inclusions

Refs #70084

Change-Id: Idd0f94d07d53b0b89dfb03b97c5b467a83b3ff83
Signed-off-by: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
---
 contrib/src/pcre/SHA512SUMS    |  2 +-
 contrib/src/pcre/rules.mak     |  4 ++--
 src/media/audio/sound/tone.cpp |  1 +
 src/media/media_codec.cpp      | 34 ++++++++++++++++++----------------
 src/media/video/video_base.cpp |  2 +-
 src/ringdht/ringaccount.h      |  1 +
 src/string_utils.cpp           |  3 ++-
 src/string_utils.h             | 28 +++++++++++++++++++++++++---
 src/upnp/upnp_context.cpp      |  4 ++--
 src/upnp/upnp_igd.h            |  5 +++--
 10 files changed, 56 insertions(+), 28 deletions(-)

diff --git a/contrib/src/pcre/SHA512SUMS b/contrib/src/pcre/SHA512SUMS
index 5c2c2935b0..066d00148c 100644
--- a/contrib/src/pcre/SHA512SUMS
+++ b/contrib/src/pcre/SHA512SUMS
@@ -1 +1 @@
-e94c652b40de60b391e28afbddc67b5a034650f6f62027e52f2d7aef53caf5f0da9f2d4f6872d1558f965dd9d4d696e5e23d2a50f20a4fbc9f0a707fb6f55fae  pcre-8.35.tar.bz2
+acd2bc6911be7b518ad4aca3c3ccbe98bdbeabf0e77d6b04009838c7825b563a001377f8c3a6a8a0583ec32ee9fefe05e3c1a69f272fe5084469a6b6c2148fbf  pcre-8.36.tar.bz2
diff --git a/contrib/src/pcre/rules.mak b/contrib/src/pcre/rules.mak
index d30cee780d..e6de6149d5 100644
--- a/contrib/src/pcre/rules.mak
+++ b/contrib/src/pcre/rules.mak
@@ -1,6 +1,6 @@
 # Perl Compatible Regular Expression
 
-PCRE_VERSION := 8.35
+PCRE_VERSION := 8.36
 PCRE_URL := ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-$(PCRE_VERSION).tar.bz2
 
 PKGS += pcre
@@ -22,6 +22,6 @@ pcre: pcre-$(PCRE_VERSION).tar.bz2 .sum-pcre
 	$(MOVE)
 
 .pcre: pcre
-	cd $< && $(HOSTVARS) ./configure $(HOSTCONF)
+	cd $< && $(HOSTVARS) ./configure --disable-cpp $(HOSTCONF)
 	cd $< && $(MAKE) install
 	touch $@
diff --git a/src/media/audio/sound/tone.cpp b/src/media/audio/sound/tone.cpp
index e3a919e3e2..434bd33750 100644
--- a/src/media/audio/sound/tone.cpp
+++ b/src/media/audio/sound/tone.cpp
@@ -38,6 +38,7 @@
 
 #include <vector>
 #include <cmath>
+#include <cstdlib>
 
 namespace ring {
 
diff --git a/src/media/media_codec.cpp b/src/media/media_codec.cpp
index a5a0790a0d..5c0155ef6d 100644
--- a/src/media/media_codec.cpp
+++ b/src/media/media_codec.cpp
@@ -33,7 +33,9 @@
 #include "media_codec.h"
 #include "account_const.h"
 
-#include <string.h>
+#include "string_utils.h"
+
+#include <string>
 #include <sstream>
 
 namespace ring {
@@ -103,9 +105,9 @@ SystemAudioCodecInfo::getCodecSpecifications()
     return {
         {DRing::Account::ConfProperties::CodecInfo::NAME, name},
         {DRing::Account::ConfProperties::CodecInfo::TYPE, (mediaType & MEDIA_AUDIO ? "AUDIO" : "VIDEO")},
-        {DRing::Account::ConfProperties::CodecInfo::BITRATE, std::to_string(bitrate)},
-        {DRing::Account::ConfProperties::CodecInfo::SAMPLE_RATE, std::to_string(audioformat.sample_rate)},
-        {DRing::Account::ConfProperties::CodecInfo::CHANNEL_NUMBER, std::to_string(audioformat.nb_channels)}
+        {DRing::Account::ConfProperties::CodecInfo::BITRATE, ring::to_string(bitrate)},
+        {DRing::Account::ConfProperties::CodecInfo::SAMPLE_RATE, ring::to_string(audioformat.sample_rate)},
+        {DRing::Account::ConfProperties::CodecInfo::CHANNEL_NUMBER, ring::to_string(audioformat.nb_channels)}
         };
 }
 
@@ -134,8 +136,8 @@ SystemVideoCodecInfo::getCodecSpecifications()
     return {
         {DRing::Account::ConfProperties::CodecInfo::NAME, name},
         {DRing::Account::ConfProperties::CodecInfo::TYPE, (mediaType & MEDIA_AUDIO ? "AUDIO" : "VIDEO")},
-        {DRing::Account::ConfProperties::CodecInfo::BITRATE, std::to_string(bitrate)},
-        {DRing::Account::ConfProperties::CodecInfo::FRAME_RATE, std::to_string(frameRate)}
+        {DRing::Account::ConfProperties::CodecInfo::BITRATE, ring::to_string(bitrate)},
+        {DRing::Account::ConfProperties::CodecInfo::FRAME_RATE, ring::to_string(frameRate)}
         };
 }
 
@@ -161,9 +163,9 @@ AccountAudioCodecInfo::getCodecSpecifications()
     return {
         {DRing::Account::ConfProperties::CodecInfo::NAME, systemCodecInfo.name},
         {DRing::Account::ConfProperties::CodecInfo::TYPE, (systemCodecInfo.mediaType & MEDIA_AUDIO ? "AUDIO" : "VIDEO")},
-        {DRing::Account::ConfProperties::CodecInfo::BITRATE, std::to_string(bitrate)},
-        {DRing::Account::ConfProperties::CodecInfo::SAMPLE_RATE, std::to_string(audioformat.sample_rate)},
-        {DRing::Account::ConfProperties::CodecInfo::CHANNEL_NUMBER, std::to_string(audioformat.nb_channels)}
+        {DRing::Account::ConfProperties::CodecInfo::BITRATE, ring::to_string(bitrate)},
+        {DRing::Account::ConfProperties::CodecInfo::SAMPLE_RATE, ring::to_string(audioformat.sample_rate)},
+        {DRing::Account::ConfProperties::CodecInfo::CHANNEL_NUMBER, ring::to_string(audioformat.nb_channels)}
         };
 }
 
@@ -172,15 +174,15 @@ AccountAudioCodecInfo::setCodecSpecifications(const std::map<std::string, std::s
 {
     auto it = details.find(DRing::Account::ConfProperties::CodecInfo::BITRATE);
     if (it != details.end())
-        bitrate = std::stoi(it->second);
+        bitrate = ring::stoi(it->second);
 
     it = details.find(DRing::Account::ConfProperties::CodecInfo::SAMPLE_RATE);
     if (it != details.end())
-        audioformat.sample_rate = std::stoi(it->second);
+        audioformat.sample_rate = ring::stoi(it->second);
 
     it = details.find(DRing::Account::ConfProperties::CodecInfo::CHANNEL_NUMBER);
     if (it != details.end())
-        audioformat.nb_channels = std::stoi(it->second);
+        audioformat.nb_channels = ring::stoi(it->second);
 }
 
 bool
@@ -205,8 +207,8 @@ AccountVideoCodecInfo::getCodecSpecifications()
     return {
         {DRing::Account::ConfProperties::CodecInfo::NAME, systemCodecInfo.name},
         {DRing::Account::ConfProperties::CodecInfo::TYPE, (systemCodecInfo.mediaType & MEDIA_AUDIO ? "AUDIO" : "VIDEO")},
-        {DRing::Account::ConfProperties::CodecInfo::BITRATE, std::to_string(bitrate)},
-        {DRing::Account::ConfProperties::CodecInfo::FRAME_RATE, std::to_string(frameRate)}
+        {DRing::Account::ConfProperties::CodecInfo::BITRATE, ring::to_string(bitrate)},
+        {DRing::Account::ConfProperties::CodecInfo::FRAME_RATE, ring::to_string(frameRate)}
         };
 }
 
@@ -215,11 +217,11 @@ AccountVideoCodecInfo::setCodecSpecifications(const std::map<std::string, std::s
 {
     auto it = details.find(DRing::Account::ConfProperties::CodecInfo::BITRATE);
     if (it != details.end())
-        bitrate = stoi(it->second);
+        bitrate = ring::stoi(it->second);
 
     it = details.find(DRing::Account::ConfProperties::CodecInfo::FRAME_RATE);
     if (it != details.end())
-        frameRate = stoi(it->second);
+        frameRate = ring::stoi(it->second);
 }
 
 AccountVideoCodecInfo::~AccountVideoCodecInfo()
diff --git a/src/media/video/video_base.cpp b/src/media/video/video_base.cpp
index 19744d2b52..2d58bf8556 100644
--- a/src/media/video/video_base.cpp
+++ b/src/media/video/video_base.cpp
@@ -99,7 +99,7 @@ static unsigned
 extractInt(const std::map<std::string, std::string>& settings, const std::string& key) {
     auto i = settings.find(key);
     if (i != settings.cend())
-        return std::stoi(i->second);
+        return ring::stoi(i->second);
     return 0;
 }
 
diff --git a/src/ringdht/ringaccount.h b/src/ringdht/ringaccount.h
index 858a37a9ab..4988a04ed5 100644
--- a/src/ringdht/ringaccount.h
+++ b/src/ringdht/ringaccount.h
@@ -50,6 +50,7 @@
 #include <map>
 #include <chrono>
 #include <list>
+#include <future>
 
 /**
  * @file sipaccount.h
diff --git a/src/string_utils.cpp b/src/string_utils.cpp
index 98a9351ad4..b511f6c83a 100644
--- a/src/string_utils.cpp
+++ b/src/string_utils.cpp
@@ -2,6 +2,7 @@
  *  Copyright (C) 2014-2015 Savoir-Faire Linux Inc.
  *
  *  Author: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
+ *  Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -65,7 +66,7 @@ split_string_to_unsigned(const std::string &s, char delim)
 
     while (std::getline(ss, token, delim))
         if (not token.empty())
-            result.emplace_back(std::stoi(token));
+            result.emplace_back(ring::stoi(token));
     return result;
 }
 
diff --git a/src/string_utils.h b/src/string_utils.h
index 14af94bcf0..6e09f64f84 100644
--- a/src/string_utils.h
+++ b/src/string_utils.h
@@ -2,6 +2,7 @@
  *  Copyright (C) 2014-2015 Savoir-Faire Linux Inc.
  *
  *  Author: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
+ *  Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -52,23 +53,44 @@ bool_to_str(bool b) noexcept
 
 #ifdef __ANDROID__
 
+// Rationale:
+// Some strings functions are not available on Android NDK as explained here:
+// http://stackoverflow.com/questions/17950814/how-to-use-stdstoul-and-stdstoull-in-android/18124627#18124627
+// We implement them by ourself as well as possible here.
+
 template <typename T>
-std::string to_string(T &&value)
+std::string
+to_string(T &&value)
 {
     std::ostringstream os;
-
     os << value;
     return os.str();
 }
 
+int
+stoi(const std::string& str)
+{
+    int v;
+    std::istringstream os(str);
+    os >> v;
+    return v;
+}
+
 #else
 
 template <typename T>
-std::string to_string(T &&value)
+inline std::string
+to_string(T &&value)
 {
     return std::to_string(std::forward<T>(value));
 }
 
+static inline int
+stoi(const std::string& str)
+{
+    return std::stoi(str);
+}
+
 #endif
 
 std::string trim(const std::string &s);
diff --git a/src/upnp/upnp_context.cpp b/src/upnp/upnp_context.cpp
index 652453fe35..68c6314442 100644
--- a/src/upnp/upnp_context.cpp
+++ b/src/upnp/upnp_context.cpp
@@ -921,7 +921,7 @@ UPnPContext::removeMappingsByLocalIPAndDescription(const IGD* igd, const std::st
         std::unique_ptr<IXML_Document, decltype(ixmlDocument_free)&> action(nullptr, ixmlDocument_free);
         IXML_Document* action_ptr = nullptr;
         UpnpAddToAction(&action_ptr, "GetGenericPortMappingEntry", igd->getServiceType().c_str(),
-                        "NewPortMappingIndex", std::to_string(entry_idx).c_str());
+                        "NewPortMappingIndex", ring::to_string(entry_idx).c_str());
         action.reset(action_ptr);
 
         std::unique_ptr<IXML_Document, decltype(ixmlDocument_free)&> response(nullptr, ixmlDocument_free);
@@ -1059,7 +1059,7 @@ UPnPContext::addPortMapping(const IGD* igd, const Mapping& mapping, int* error_c
         std::string errorDescription = get_first_doc_item(response.get(), "errorDescription");
         RING_WARN("UPnP: %s returned with error: %s: %s",
                   action_name.c_str(), errorCode.c_str(), errorDescription.c_str());
-        *error_code = std::stoi(errorCode);
+        *error_code = ring::stoi(errorCode);
         return false;
     }
     return true;
diff --git a/src/upnp/upnp_igd.h b/src/upnp/upnp_igd.h
index d27572b660..90ead0df47 100644
--- a/src/upnp/upnp_igd.h
+++ b/src/upnp/upnp_igd.h
@@ -36,6 +36,7 @@
 
 #include "noncopyable.h"
 #include "ip_utils.h"
+#include "string_utils.h"
 
 namespace ring { namespace upnp {
 
@@ -72,9 +73,9 @@ public:
     friend bool operator!= (Mapping &cRedir1, Mapping &cRedir2);
 
     uint16_t      getPortExternal()    const { return port_external_; };
-    std::string   getPortExternalStr() const { return std::to_string(port_external_); };
+    std::string   getPortExternalStr() const { return ring::to_string(port_external_); };
     uint16_t      getPortInternal()    const { return port_internal_; };
-    std::string   getPortInternalStr() const { return std::to_string(port_internal_); };
+    std::string   getPortInternalStr() const { return ring::to_string(port_internal_); };
     PortType      getType()            const { return type_; };
     std::string   getTypeStr()         const { return type_ == PortType::UDP ? "UDP" : "TCP"; }
     std::string   getDescription()     const { return description_; };
-- 
GitLab