/RIC-E2-TERMINATION/3rdparty/cgreen_1.2.0_amd64.deb
/testConfigFile
/config/config.conf
+/logTest
+/b64Test
add_executable(testConfigFile
RIC-E2-TERMINATION/ReadConfigFile.h
RIC-E2-TERMINATION/TEST/ConfigurationFileTest/testConfigFile.cpp)
+
+add_executable(b64Test
+ RIC-E2-TERMINATION/base64.cpp
+ RIC-E2-TERMINATION/base64.h
+ RIC-E2-TERMINATION/TEST/base64/testBase64.cpp)
+
+#find_package(RapidJSON)
+
+#add_executable(logTest
+# RIC-E2-TERMINATION/TEST/ASN_LOG/LogTest.h
+# RIC-E2-TERMINATION/TEST/ASN_LOG/LogTest.cpp)
# && find / -type f -name "libopentracing.a" -exec cp {} libopentracing.a \; && cd /opt/e2/RIC-E2-TERMINATION && ls nlohmann \
FROM ubuntu:16.04
-RUN apt-get update && apt-get install -y net-tools iputils-ping curl tcpdump && mkdir /opt/e2/config
+RUN apt-get update && apt-get install -y net-tools iputils-ping curl tcpdump && mkdir -p /opt/e2/config
COPY --from=ubuntu /opt/e2/e2 /opt/e2/e2
COPY --from=ubuntu /opt/e2/RIC-E2-TERMINATION/dockerRouter.txt /opt/e2/dockerRouter.txt
COPY --from=ubuntu /usr/local/lib/libnng.so.1 /usr/local/lib/libnng.so.1
COPY --from=ubuntu /usr/local/lib/libmdclog.so.0 /usr/local/lib/libmdclog.so.0
-COPY --from=ubuntu /usr/local/lib/libcgreen.so.1.2.0 /usr/local/lib/libcgreen.so.1.2.0
-COPY --from=ubuntu /usr/local/lib/libcgreen.so.1 /usr/local/lib/libcgreen.so.1
-COPY --from=ubuntu /usr/local/lib/libcgreen.so /usr/local/lib/libcgreen.so
-
COPY --from=ubuntu /usr/lib/libboost_log_setup.so /usr/lib/libboost_log_setup.so
COPY --from=ubuntu /usr/lib/libboost_log_setup.so.1.69.0 /usr/lib/libboost_log_setup.so.1.69.0
#include "LogTest.h"
+string LogTest::getLine() {
+ std::string line;
+
+ if (std::getline(file, line)) {
+ return line;
+ }
+ return "";
+}
+
+void LogTest::getJsonDoc(string json) {
+ if (json.length() != 0) {
+ document.Parse(json.c_str());
+ }
+}
+
+string LogTest::getBase64(Document &document) {
+ if (document.HasMember("asnBase64")) {
+ return document["asnBase64"].GetString();
+ }
+ return "";
+}
#include <shared_mutex>
#include <iterator>
#include <map>
+#include <fstream>
+
+#include "rapidjson/document.h"
+#include "rapidjson/writer.h"
+#include "rapidjson/stringbuffer.h"
using namespace std;
+using namespace rapidjson;
class LogTest {
public:
LogTest() = default;
- openFile(string const& configFile);
+ int openFile(string const& configFile) {
+ file.open(configFile.c_str());
+ if (!file) {
+ return -1;
+ }
+ return 0;
+ }
+
+ string getLine();
+ void getJsonDoc(string json);
+
+ string getBase64(Document &document);
+private:
+ std::ifstream file;
+ Document document;
};
Ensure(Cgreen, goodparams) {
ReadConfigFile conf {};
assert_that(conf.openConfigFile("config") == 0);
- assert_that(conf.getIntValue("nano") == 38002);
+ assert_that(conf.getIntValue("nano") == 38000);
assert_that(conf.getStringValue("loglevel") == "info");
assert_that(conf.getStringValue("volume") == ".");
Ensure(Cgreen, badParams) {
ReadConfigFile conf {};
assert_that(conf.openConfigFile("config") == 0);
- assert_that(conf.getIntValue("nano") != 38000);
+ assert_that(conf.getIntValue("nano") != 38002);
assert_that(conf.getStringValue("loglevel") != "");
assert_that(conf.getStringValue("volume") != "bob");
assert_that(conf.getStringValue("volum") != "bob");
--- /dev/null
+/*
+ * Copyright 2019 AT&T Intellectual Property
+ * Copyright 2019 Nokia
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//
+// Created by adi ENZEL on 11/27/19.
+//
+
+#include "base64.h"
+#include <mdclog/mdclog.h>
+#include <cgreen/cgreen.h>
+#include <cstdio>
+#include <cerrno>
+#include <cstdlib>
+#include <cstring>
+
+using namespace std;
+
+Describe(base64);
+BeforeEach(base64) {}
+AfterEach(base64) {}
+
+using namespace cgreen;
+
+void init_log() {
+ mdclog_attr_t *attr;
+ mdclog_attr_init(&attr);
+ mdclog_attr_set_ident(attr, "TestConfiguration");
+ mdclog_init(attr);
+ mdclog_attr_destroy(attr);
+}
+
+const char *data = "ABC123Test Lets Try this' input and see What \"happens\"";
+
+Ensure(base64, encDec) {
+ string str = "ABC123Test Lets Try this' input and see What \"happens\"";
+ auto *buf = (unsigned char *)malloc(str.length() * 2);
+ auto length = (long)(str.length() * 2);
+ base64::encode((unsigned char *)str.c_str(), str.length(), buf, length);
+ auto *backBackBuff = (unsigned char *)malloc(length);
+ auto length2 = length;
+ assert_that(base64::decode(buf, length, backBackBuff, length2) == 0);
+ std::string str1( backBackBuff, backBackBuff + sizeof backBackBuff / sizeof backBackBuff[0]);
+
+ assert_that(str.length() == (ulong)length2)
+ //auto val = str.compare((const char *)backBackBuff);
+ assert_that(str.compare((const char *)backBackBuff) == 0)
+ free(backBackBuff);
+ free(buf);
+}
+
+Ensure(base64, errorsHandling) {
+ string str = "ABC123Test Lets Try this' input and see What \"happens\"";
+ auto *buf = (unsigned char *)malloc(str.length() * 2);
+ auto length = (long)(str.length());
+ assert_that(base64::encode((unsigned char *)str.c_str(), str.length(), buf, length) == -1);
+ length = (long)(str.length() * 2);
+ assert_that(base64::encode((unsigned char *)str.c_str(), str.length(), buf, length) == 0);
+ auto *backBackBuff = (unsigned char *)malloc(length);
+ auto length2 = length >> 2;
+ assert_that(base64::decode(buf, length, backBackBuff, length2) == -1);
+ //std::string str1( backBackBuff, backBackBuff + sizeof backBackBuff / sizeof backBackBuff[0]);
+ auto length1 = 0l;
+ assert_that(base64::encode((unsigned char *)str.c_str(), str.length(), nullptr , length) == -1);
+// assert_that(base64::encode((unsigned char *)str.c_str(), str.length(), nullptr , length) == -1);
+ assert_that(base64::encode(nullptr, str.length(), backBackBuff , length) == -1);
+ assert_that(base64::encode((unsigned char *)str.c_str(), length1, backBackBuff , length) == -1);
+ assert_that(base64::encode(nullptr, str.length(), backBackBuff , length1) == -1);
+ length1 = -1;
+ assert_that(base64::encode((unsigned char *)str.c_str(), length1, backBackBuff , length) == -1);
+ assert_that(base64::encode(nullptr, str.length(), backBackBuff , length1) == -1);
+
+}
+
+
+int main(const int argc, char **argv) {
+ mdclog_severity_t loglevel = MDCLOG_INFO;
+ init_log();
+ mdclog_level_set(loglevel);
+
+ //TestSuite *suite = create_test_suite();
+ TestSuite *suite = create_named_test_suite_(__FUNCTION__, __FILE__, __LINE__);
+
+ add_test_with_context(suite, base64, encDec);
+ add_test_with_context(suite, base64, errorsHandling);
+
+ return cgreen::run_test_suite(suite, create_text_reporter());
+
+}
\ No newline at end of file
#include "base64.h"
-void base64::encode(const unsigned char *src, const int srcLen, char unsigned *dst, int &dstLen) {
+int base64::encode(const unsigned char *src, int srcLen, char unsigned *dst, long &dstLen) {
unsigned char *pos;
const unsigned char *end, *in;
- if (dstLen < srcLen) {
- mdclog_write(MDCLOG_ERR, "Destination size %d must be at least 140 percent from source size %d",
+
+ if (dstLen <= 0 || srcLen <= 0) {
+ mdclog_write(MDCLOG_ERR, "source or destination length are 0. dst =%ld source = %d",
+ dstLen, srcLen);
+ return -1;
+ }
+ if (dstLen < (srcLen * 4 / 3)) {
+ mdclog_write(MDCLOG_ERR, "Destination size %ld must be at least 140 percent from source size %d",
dstLen, srcLen);
- return;
+ return -1;
}
if (dst == nullptr) {
mdclog_write(MDCLOG_ERR, "Destination must be allocated and freed by caller the function not allocate the memory");
- return;
+ return -1;
+ }
+ if (src == nullptr) {
+ mdclog_write(MDCLOG_ERR, "source is null pointer");
+ return -1;
}
end = src + srcLen;
}
*pos = '\0';
- dstLen = pos - dst;
+ dstLen = pos - dst;return 0;
}
+int base64::decode(const unsigned char *src, int srcLen, char unsigned *dst, long &dstLen) {
+ unsigned char inv_table[INVERSE_TABLE_SIZE];
+ memset(inv_table, 0x80, INVERSE_TABLE_SIZE);
+ for (ulong i = 0; i < sizeof(base64_table) - 1; i++) {
+ inv_table[base64_table[i]] = (unsigned char) i;
+ }
+ inv_table['='] = 0;
+
+
+ if (dstLen == 0 || dstLen < (int)(srcLen / 4 * 3)) {
+ mdclog_write(MDCLOG_ERR, "Destination size %ld can be up to 40 smaller then source size %d",
+ dstLen, srcLen);
+ return -1;
+ }
+ if (dst == nullptr) {
+ mdclog_write(MDCLOG_ERR, "Destination must be allocated and freed by caller the function not allocate the memory");
+ return -1;
+ }
+
+ unsigned char *pos, block[4], tmp;
+ long i;
+ int pad = 0;
+
+ size_t count = 0;
+
+ for (i = 0; i < srcLen; i++) {
+ if (inv_table[src[i]] != 0x80) {
+ count++;
+ }
+ }
+
+ if (count == 0 || count % 4)
+ return -1;
+
+ pos = dst;
+ count = 0;
+ for (i = 0; i < srcLen; i++) {
+ tmp = inv_table[src[i]];
+ if (tmp == 0x80) {
+ continue;
+ }
+ block[count] = tmp;
+
+ if (src[i] == '=') {
+ pad++;
+ }
+
+ count++;
+ if (count == 4) {
+ *pos++ = (block[0] << 2) | ((unsigned char)block[1] >> (unsigned int)4);
+ *pos++ = (block[1] << 4) | ((unsigned char)block[2] >> (unsigned int)2);
+ *pos++ = (block[2] << 6) | block[3];
+ count = 0;
+ if (pad) {
+ if (pad == 1) {
+ pos--;
+ }
+ else if (pad == 2) {
+ pos -= 2;
+ }
+ else {
+ return -1;
+ }
+ break;
+ }
+ }
+ }
+
+ dstLen = pos - dst;
+ return 0;
+}
#define E2_BASE64_H
#include <mdclog/mdclog.h>
+#include <cstring>
+#include <zconf.h>
static const unsigned char base64_table[65] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+#define INVERSE_TABLE_SIZE 256
+
class base64 {
public:
- static void encode(const unsigned char *src, const int srcLen, char unsigned *dst, int &dstLen);
+ /**
+ *
+ * @param src
+ * @param srcLen
+ * @param dst
+ * @param dstLen
+ * @return 0 = OK -1 fault
+ */
+ static int encode(const unsigned char *src, int srcLen, char unsigned *dst, long &dstLen);
+ /**
+ *
+ * @param src
+ * @param srcLen
+ * @param dst
+ * @param dstLen
+ * @return 0 = OK -1 fault
+ */
+ static int decode(const unsigned char *src, int srcLen, char unsigned *dst, long &dstLen);
+
};
typedef struct ReportingMessages {
FormatedMessage_t message;
- int outLen;
+ long outLen;
unsigned char base64Data[RECEIVE_SCTP_BUFFER_SIZE * 2];
char buffer[RECEIVE_SCTP_BUFFER_SIZE * 8];
size_t bufferLen;