aboutsummaryrefslogtreecommitdiffstats
path: root/fbench
diff options
context:
space:
mode:
authorohad serfaty <ohad@verizonemedia.com>2019-11-25 08:50:22 +0200
committerohad serfaty <ohad@verizonemedia.com>2019-11-25 08:50:22 +0200
commit9f94b126358258326f21ff9cbf823e64300a1a67 (patch)
tree2b11738e3ed0665268d628825d6051a64dece492 /fbench
parentbf7ecdac2da5ecb069e3d01c5e3ed0ab65c270b2 (diff)
Using vespa's internal base64 code
Diffstat (limited to 'fbench')
-rw-r--r--fbench/CMakeLists.txt1
-rw-r--r--fbench/src/fbench/client.cpp55
2 files changed, 6 insertions, 50 deletions
diff --git a/fbench/CMakeLists.txt b/fbench/CMakeLists.txt
index bc40e659b99..5cc56786227 100644
--- a/fbench/CMakeLists.txt
+++ b/fbench/CMakeLists.txt
@@ -3,6 +3,7 @@ vespa_define_module(
DEPENDS
fastos
vespalib
+ staging_vespalib
APPS
src/fbench
diff --git a/fbench/src/fbench/client.cpp b/fbench/src/fbench/client.cpp
index 297cf61bdb3..0de6f676807 100644
--- a/fbench/src/fbench/client.cpp
+++ b/fbench/src/fbench/client.cpp
@@ -8,53 +8,9 @@
#include <cassert>
#include <cstring>
#include <iostream>
+#include <vespa/vespalib/encoding/base64.h>
-static const std::string base64_chars =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "abcdefghijklmnopqrstuvwxyz"
- "0123456789+/";
-
-
-static inline bool is_base64(unsigned char c) {
- return (isalnum(c) || (c == '+') || (c == '/'));
-}
-
-std::string base64_decode(std::string const& encoded_string) {
- int in_len = encoded_string.size();
- int i = 0;
- int j = 0;
- int in_ = 0;
- unsigned char char_array_4[4], char_array_3[3];
- std::string ret;
-
- while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
- char_array_4[i++] = encoded_string[in_]; in_++;
- if (i ==4) {
- for (i = 0; i <4; i++)
- char_array_4[i] = base64_chars.find(char_array_4[i]);
-
- char_array_3[0] = ( char_array_4[0] << 2 ) + ((char_array_4[1] & 0x30) >> 4);
- char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
- char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
-
- for (i = 0; (i < 3); i++)
- ret += char_array_3[i];
- i = 0;
- }
- }
-
- if (i) {
- for (j = 0; j < i; j++)
- char_array_4[j] = base64_chars.find(char_array_4[j]);
-
- char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
- char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
-
- for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
- }
-
- return ret;
-}
+using namespace vespalib;
Client::Client(vespalib::CryptoEngine::SP engine, ClientArguments *args)
: _args(args),
@@ -270,10 +226,9 @@ Client::run()
int cLen = _args->_usePostMode ? urlSource.nextContent() : 0;
auto content = urlSource.content();
if (_args->_usePostMode && _args->_base64Decode) {
- auto base64_content = std::string(urlSource.content(), cLen);
- auto decoded = base64_decode(base64_content);
- content = decoded.c_str();
- cLen = decoded.size();
+ auto base64_decoded = Base64::decode(std::string(urlSource.content(), cLen));
+ content = base64_decoded.c_str();
+ cLen = base64_decoded.size();
}
_reqTimer->Start();