From 308a283f82cf42a1078ad9432cfda8a92a13a5ae Mon Sep 17 00:00:00 2001 From: Guru Chandru Date: Fri, 22 Oct 2021 19:27:55 +0530 Subject: [PATCH 01/35] Adding rbus dependency --- meson.build | 68 +++++++++++++++++++++++++++++++++++++- src/common.c | 17 ++++++++-- subprojects/cjson.wrap | 11 ++++++ subprojects/rbus-core.wrap | 8 +++++ subprojects/rbus.wrap | 8 +++++ subprojects/rtMessage.wrap | 8 +++++ subprojects/wdmp.wrap | 8 +++++ 7 files changed, 124 insertions(+), 4 deletions(-) create mode 100644 subprojects/cjson.wrap create mode 100644 subprojects/rbus-core.wrap create mode 100644 subprojects/rbus.wrap create mode 100644 subprojects/rtMessage.wrap create mode 100644 subprojects/wdmp.wrap diff --git a/meson.build b/meson.build index 3b74dda..aa03593 100644 --- a/meson.build +++ b/meson.build @@ -15,11 +15,69 @@ if not meson.is_subproject() werror = true endif +prefix = get_option('prefix') + +################################################################################ +# Dependencies +################################################################################ + +#rtMessage +rtMessagecmake = import('cmake') + +rtMessage_proj = rtMessagecmake.subproject('rtMessage') + +librtMessage_dep = rtMessage_proj.dependency('rtMessage') + +#rbus-core +rbuscorecmake = import('cmake') + +rbuscore_opts = rbuscorecmake.subproject_options() + +rbuscore_opts.add_cmake_defines({'BUILD_FOR_DESKTOP': true, 'CMAKE_INSTALL_PREFIX': prefix+'/include'}) + +rbuscore_proj = rbuscorecmake.subproject('rbus-core', options: rbuscore_opts) + +librbuscore_dep = rbuscore_proj.dependency('rbus-core') + +message(prefix+'/include') + +#rbus + + +#rbuscmake = import('cmake') + +#rbus_opts = rbuscmake.subproject_options() + +#rbus_opts.add_cmake_defines({'BUILD_FOR_DESKTOP': true, 'CMAKE_INSTALL_PREFIX': prefix+'/include'}) + +#rbus_proj = rbuscmake.subproject('rbus', options: rbus_opts) + +#librbus_dep = rbus_proj.dependency('rbus') + +all_dep = [librtMessage_dep, librbuscore_dep]#, librbus_dep] + +#wdmp-c dependencies + +#wdmpcmake = import('cmake') + +#wdmp_opts = wdmpcmake.subproject_options() + +#wdmp_opts.add_cmake_defines({'CMAKE_POSITION_INDEPENDENT_CODE': true}) + +#wdmp_proj = wdmpcmake.subproject('wdmp', options: wdmp_opts) + +#libwdmp_dep = wdmp_proj.dependency('wdmp-c') + +#cjson dependencies +#libcjson_dep = dependency('libcjson', version: '>=1.7.14', fallback: ['cjson']) + +#all_dep = [libcjson_dep, libwdmp_dep] + ################################################################################ # Common variable definitions ################################################################################ -inc_base = 'include/'+meson.project_name() +inc_base = ['include/'+meson.project_name()] ################################################################################ # Generate the version header file @@ -35,6 +93,7 @@ install_headers([headers, ver_h], subdir: meson.project_name()) inc = include_directories(inc_base) +src_args = ['-lcjson'] sources = ['src/common.c'] libcpeabs = library(meson.project_name(), @@ -42,6 +101,13 @@ libcpeabs = library(meson.project_name(), include_directories: inc, install: true) +executable(meson.project_name(), + sources, + include_directories: inc, + dependencies: all_dep, + install: true, + link_args: src_args) + ################################################################################ # Define the tests ################################################################################ diff --git a/src/common.c b/src/common.c index c571421..16d49c5 100644 --- a/src/common.c +++ b/src/common.c @@ -3,8 +3,11 @@ #include #include +#include #include - +#include +//#include "../../subprojects/wdmp/src/wdmp-c.h" +#include /*----------------------------------------------------------------------------*/ /* Macros */ /*----------------------------------------------------------------------------*/ @@ -23,8 +26,7 @@ /*----------------------------------------------------------------------------*/ /* Function Prototypes */ /*----------------------------------------------------------------------------*/ -/* none */ - +void do_something(); /*----------------------------------------------------------------------------*/ /* Internal functions */ /*----------------------------------------------------------------------------*/ @@ -33,6 +35,15 @@ /*----------------------------------------------------------------------------*/ /* External Functions */ /*----------------------------------------------------------------------------*/ +int main() +{ + /* req_struct *req = NULL; + req = (req_struct *) malloc (sizeof(req_struct)); + do_something();*/ + //wdmp_parse_generic_request("Hi", WDMP_TR181, &req); + return 0; +} + void do_something() { printf("I do something well.\n"); diff --git a/subprojects/cjson.wrap b/subprojects/cjson.wrap new file mode 100644 index 0000000..26a0097 --- /dev/null +++ b/subprojects/cjson.wrap @@ -0,0 +1,11 @@ +[wrap-file] +directory = cJSON-1.7.14 +source_url = https://github.com/DaveGamble/cJSON/archive/refs/tags/v1.7.14.tar.gz +source_filename = v1.7.14.tar.gz +source_hash = fb50a663eefdc76bafa80c82bc045af13b1363e8f45cec8b442007aef6a41343 +patch_filename = cjson_1.7.14-1_patch.zip +patch_url = https://wrapdb.mesonbuild.com/v2/cjson_1.7.14-1/get_patch +patch_hash = 82d7a029637bdd6696a89075907581768e7088c20b1c69f400cb6e15e716d803 + +[provide] +libcjson = libcjson_dep diff --git a/subprojects/rbus-core.wrap b/subprojects/rbus-core.wrap new file mode 100644 index 0000000..d0ad384 --- /dev/null +++ b/subprojects/rbus-core.wrap @@ -0,0 +1,8 @@ +[wrap-git] +directory = rbus-core + +url = https://github.com/rdkcmf/rbuscore +revision = rdk-next + +[provide] +librbus-core = librbus-core_dep diff --git a/subprojects/rbus.wrap b/subprojects/rbus.wrap new file mode 100644 index 0000000..3a58c8c --- /dev/null +++ b/subprojects/rbus.wrap @@ -0,0 +1,8 @@ +[wrap-git] +directory = rbus + +url = https://github.com/rdkcmf/rbus.git +revision = rdk-next + +[provide] +librbus = librbus_dep diff --git a/subprojects/rtMessage.wrap b/subprojects/rtMessage.wrap new file mode 100644 index 0000000..02b9b1d --- /dev/null +++ b/subprojects/rtMessage.wrap @@ -0,0 +1,8 @@ +[wrap-git] +directory = rtMessage + +url = https://github.com/rdkcmf/rdk-rtmessage.git +revision = rdk-next + +[provide] +librtMessage = librtMessage_dep diff --git a/subprojects/wdmp.wrap b/subprojects/wdmp.wrap new file mode 100644 index 0000000..12b28c9 --- /dev/null +++ b/subprojects/wdmp.wrap @@ -0,0 +1,8 @@ +[wrap-git] +directory = wdmp + +url = https://github.com/xmidt-org/wdmp-c.git +revision = dd95994163333dc997a2620ee482ed99c35d1d3c + +[provide] +libwdmp = libwdmp_dep From bea448a2f2fab255a34c453ba9f7f53bf9422d8f Mon Sep 17 00:00:00 2001 From: Guru Chandru Date: Mon, 25 Oct 2021 19:06:47 +0530 Subject: [PATCH 02/35] New changes to incorporate main rbus code --- include/cpeabs/cpeabs.h | 2 ++ meson.build | 55 ++++++++++++++++++++++++++++------------- src/common.c | 1 + 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/include/cpeabs/cpeabs.h b/include/cpeabs/cpeabs.h index 2bc5f73..868444b 100644 --- a/include/cpeabs/cpeabs.h +++ b/include/cpeabs/cpeabs.h @@ -7,4 +7,6 @@ #include #include +#include + #endif diff --git a/meson.build b/meson.build index aa03593..ff004db 100644 --- a/meson.build +++ b/meson.build @@ -20,12 +20,22 @@ prefix = get_option('prefix') ################################################################################ # Dependencies ################################################################################ +#cjson +libcjson_dep = dependency('libcjson', version: '>=1.7.14', fallback: ['cjson']) #rtMessage rtMessagecmake = import('cmake') -rtMessage_proj = rtMessagecmake.subproject('rtMessage') +rtMessage_opts = rtMessagecmake.subproject_options() +rtMessage_opts.add_cmake_defines({ #'BUILD_FOR_DESKTOP': true, + 'CMAKE_C_FLAGS': '-std=c99 -D_GNU_SOURCE=1', + 'CMAKE_CXX_FLAGS': '-std=c99 -D_GNU_SOURCE=1', + 'BUILD_RTMESSAGE_SAMPLE_APP': true, + 'BUILD_RTMESSAGE_LIB': true, + 'BUILD_DATAPROVIDER_LIB': false, + }) +rtMessage_proj = rtMessagecmake.subproject('rtMessage', options: rtMessage_opts) librtMessage_dep = rtMessage_proj.dependency('rtMessage') #rbus-core @@ -33,7 +43,11 @@ rbuscorecmake = import('cmake') rbuscore_opts = rbuscorecmake.subproject_options() -rbuscore_opts.add_cmake_defines({'BUILD_FOR_DESKTOP': true, 'CMAKE_INSTALL_PREFIX': prefix+'/include'}) +rbuscore_opts.add_cmake_defines({ #'BUILD_FOR_DESKTOP': true, + #'CMAKE_INSTALL_PREFIX': prefix+'/include', + 'RTMESSAGE_INCLUDE_DIRS': 'subprojects/rtMessage', + 'RTMESSAGE_LIBRARIES': 'subprojects/rtMessage', + }) rbuscore_proj = rbuscorecmake.subproject('rbus-core', options: rbuscore_opts) @@ -44,17 +58,22 @@ message(prefix+'/include') #rbus -#rbuscmake = import('cmake') +rbuscmake = import('cmake') -#rbus_opts = rbuscmake.subproject_options() +rbus_opts = rbuscmake.subproject_options() -#rbus_opts.add_cmake_defines({'BUILD_FOR_DESKTOP': true, 'CMAKE_INSTALL_PREFIX': prefix+'/include'}) +rbus_opts.add_cmake_defines({'BUILD_FOR_DESKTOP': true, + 'RTMESSAGE_INCLUDE_DIRS': 'subprojects/rtMessage', + 'RTMESSAGE_LIBRARIES': 'subprojects/rtMessage', + 'RBUSCORE_INCLUDE_DIRS': 'subprojects/rbus-core', + 'RBUSCORE_LIBRARIES':'subprojects/rbus-core' + }) -#rbus_proj = rbuscmake.subproject('rbus', options: rbus_opts) +rbus_proj = rbuscmake.subproject('rbus', options: rbus_opts) -#librbus_dep = rbus_proj.dependency('rbus') +librbus_dep = rbus_proj.dependency('rbus') -all_dep = [librtMessage_dep, librbuscore_dep]#, librbus_dep] +all_dep = [libcjson_dep, librtMessage_dep, librbuscore_dep, librbus_dep] #wdmp-c dependencies @@ -77,7 +96,7 @@ all_dep = [librtMessage_dep, librbuscore_dep]#, librbus_dep] # Common variable definitions ################################################################################ -inc_base = ['include/'+meson.project_name()] +inc_base = ['include/'+meson.project_name()]#, 'subprojects/rtMessage', 'subprojects/rbus-core', 'subprojects/rbus'] ################################################################################ # Generate the version header file @@ -85,29 +104,31 @@ inc_base = ['include/'+meson.project_name()] subdir('include/'+meson.project_name()) -install_headers([headers, ver_h], subdir: meson.project_name()) +install_headers(['include/'+meson.project_name()+'/cpeabs.h', ver_h], subdir: meson.project_name()) ################################################################################ # Define the libraries ################################################################################ -inc = include_directories(inc_base) +inc = include_directories([inc_base]) -src_args = ['-lcjson'] +src_args = ['-lcjson', '-lpthread'] sources = ['src/common.c'] libcpeabs = library(meson.project_name(), - sources, - include_directories: inc, - install: true) - -executable(meson.project_name(), sources, include_directories: inc, dependencies: all_dep, install: true, link_args: src_args) +#executable(meson.project_name(), + # sources, + # include_directories: inc, + # dependencies: all_dep, + # install: true, + # link_args: src_args) + ################################################################################ # Define the tests ################################################################################ diff --git a/src/common.c b/src/common.c index 16d49c5..b0ad4ef 100644 --- a/src/common.c +++ b/src/common.c @@ -8,6 +8,7 @@ #include //#include "../../subprojects/wdmp/src/wdmp-c.h" #include +#include /*----------------------------------------------------------------------------*/ /* Macros */ /*----------------------------------------------------------------------------*/ From f62b377dbac0a545a99b33a4639f53166bd5f684 Mon Sep 17 00:00:00 2001 From: Weston Schmidt Date: Mon, 25 Oct 2021 20:56:50 -0700 Subject: [PATCH 03/35] This should more or less get rtMessage building. --- meson.build | 56 +------------------ .../rtmessage/meson.build | 9 +++ subprojects/rtMessage/meson.build | 52 +++++++++++++++++ 3 files changed, 62 insertions(+), 55 deletions(-) create mode 100644 subprojects/rtMessage/include-workaround-meson/rtmessage/meson.build create mode 100644 subprojects/rtMessage/meson.build diff --git a/meson.build b/meson.build index ff004db..e059b29 100644 --- a/meson.build +++ b/meson.build @@ -22,56 +22,7 @@ prefix = get_option('prefix') ################################################################################ #cjson libcjson_dep = dependency('libcjson', version: '>=1.7.14', fallback: ['cjson']) - -#rtMessage -rtMessagecmake = import('cmake') - -rtMessage_opts = rtMessagecmake.subproject_options() -rtMessage_opts.add_cmake_defines({ #'BUILD_FOR_DESKTOP': true, - 'CMAKE_C_FLAGS': '-std=c99 -D_GNU_SOURCE=1', - 'CMAKE_CXX_FLAGS': '-std=c99 -D_GNU_SOURCE=1', - 'BUILD_RTMESSAGE_SAMPLE_APP': true, - 'BUILD_RTMESSAGE_LIB': true, - 'BUILD_DATAPROVIDER_LIB': false, - }) - -rtMessage_proj = rtMessagecmake.subproject('rtMessage', options: rtMessage_opts) -librtMessage_dep = rtMessage_proj.dependency('rtMessage') - -#rbus-core -rbuscorecmake = import('cmake') - -rbuscore_opts = rbuscorecmake.subproject_options() - -rbuscore_opts.add_cmake_defines({ #'BUILD_FOR_DESKTOP': true, - #'CMAKE_INSTALL_PREFIX': prefix+'/include', - 'RTMESSAGE_INCLUDE_DIRS': 'subprojects/rtMessage', - 'RTMESSAGE_LIBRARIES': 'subprojects/rtMessage', - }) - -rbuscore_proj = rbuscorecmake.subproject('rbus-core', options: rbuscore_opts) - -librbuscore_dep = rbuscore_proj.dependency('rbus-core') - -message(prefix+'/include') - -#rbus - - -rbuscmake = import('cmake') - -rbus_opts = rbuscmake.subproject_options() - -rbus_opts.add_cmake_defines({'BUILD_FOR_DESKTOP': true, - 'RTMESSAGE_INCLUDE_DIRS': 'subprojects/rtMessage', - 'RTMESSAGE_LIBRARIES': 'subprojects/rtMessage', - 'RBUSCORE_INCLUDE_DIRS': 'subprojects/rbus-core', - 'RBUSCORE_LIBRARIES':'subprojects/rbus-core' - }) - -rbus_proj = rbuscmake.subproject('rbus', options: rbus_opts) - -librbus_dep = rbus_proj.dependency('rbus') +librtMessage_dep = dependency('librtMessage') all_dep = [libcjson_dep, librtMessage_dep, librbuscore_dep, librbus_dep] @@ -87,11 +38,6 @@ all_dep = [libcjson_dep, librtMessage_dep, librbuscore_dep, librbus_dep] #libwdmp_dep = wdmp_proj.dependency('wdmp-c') -#cjson dependencies -#libcjson_dep = dependency('libcjson', version: '>=1.7.14', fallback: ['cjson']) - -#all_dep = [libcjson_dep, libwdmp_dep] - ################################################################################ # Common variable definitions ################################################################################ diff --git a/subprojects/rtMessage/include-workaround-meson/rtmessage/meson.build b/subprojects/rtMessage/include-workaround-meson/rtmessage/meson.build new file mode 100644 index 0000000..ae17948 --- /dev/null +++ b/subprojects/rtMessage/include-workaround-meson/rtmessage/meson.build @@ -0,0 +1,9 @@ +# This is a workaround for creating a rtmessage/ folder with the headers in it in +# the builddir space. +# +# See https://github.com/mesonbuild/meson/issues/2546 for where the technique comes from +foreach h: headers + configure_file(copy: true, + input: h, + output: '@PLAINNAME@') +endforeach diff --git a/subprojects/rtMessage/meson.build b/subprojects/rtMessage/meson.build new file mode 100644 index 0000000..7df1545 --- /dev/null +++ b/subprojects/rtMessage/meson.build @@ -0,0 +1,52 @@ +project('rtMessage', 'c', + version: '0.0.1', + meson_version: '>=0.54.0', + license: ['Apache-2.0'], + default_options: ['c_std=c18']) + + +libcjson_dep = dependency('libcjson', version: '>=1.7.14', fallback: ['cjson']) +thread_dep = dependency('threads') + +headers = files('rtMessage.h', + 'rtMessageHeader.h', + 'rtError.h', + 'rtConnection.h', + 'rtVector.h', + 'rtRetainable.h', + 'rtLog.h', + 'rtList.h', + 'rtTime.h', + 'rtAtomic.h', + 'rtm_discovery_api.h', + 'rtAdvisory.h') + +subdir('include-workaround-meson/rtmessage') + +librtMessage = library('rtMessage', + ['rtConnection.c', + 'rtCipher.c', + 'rtLog.c', + 'rtError.c', + 'rtMessageHeader.c', + 'rtEncoder.c', + 'rtMessage.c', + 'rtSocket.c', + 'rtVector.c', + 'rtList.c', + 'rtTime.c', + 'rtSemaphore.c', + 'rtRetainable.c', + 'rtBase64.c', + 'local_benchmarking.c'], + c_args: ['-D_GNU_SOURCE', '-D_POSIX_C_SOURCE=199309L'], + cpp_args: ['-D_GNU_SOURCE', '-D_POSIX_C_SOURCE=199309L'], + dependencies: [ libcjson_dep ], + install: true) + +librtMessage_dep = declare_dependency(include_directories: ['include-workaround-meson'], + link_with: librtMessage) + +if meson.version().version_compare('>=0.54.0') + meson.override_dependency('librtMessage', librtMessage_dep) +endif From 57d8cb41b291275e5f9d6b8b6b89b57736e3a98b Mon Sep 17 00:00:00 2001 From: Weston Schmidt Date: Mon, 25 Oct 2021 21:20:14 -0700 Subject: [PATCH 04/35] Work around the need to have the wrapper code in the wrapdb. --- subprojects/rtMessage.wrap | 1 + workaround.sh | 8 ++++++++ .../include-workaround-meson/rtmessage/meson.build | 0 {subprojects => wrapdb}/rtMessage/meson.build | 0 4 files changed, 9 insertions(+) create mode 100755 workaround.sh rename {subprojects => wrapdb}/rtMessage/include-workaround-meson/rtmessage/meson.build (100%) rename {subprojects => wrapdb}/rtMessage/meson.build (100%) diff --git a/subprojects/rtMessage.wrap b/subprojects/rtMessage.wrap index 02b9b1d..69ecd62 100644 --- a/subprojects/rtMessage.wrap +++ b/subprojects/rtMessage.wrap @@ -3,6 +3,7 @@ directory = rtMessage url = https://github.com/rdkcmf/rdk-rtmessage.git revision = rdk-next +patch_filename = rtMessage.tar.gz [provide] librtMessage = librtMessage_dep diff --git a/workaround.sh b/workaround.sh new file mode 100755 index 0000000..2d3a64e --- /dev/null +++ b/workaround.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +mkdir -p subprojects/packagefiles + +pushd wrapdb +tar -czf rtMessage.tar.gz rtMessage +mv rtMessage.tar.gz ../subprojects/packagefiles/. +popd diff --git a/subprojects/rtMessage/include-workaround-meson/rtmessage/meson.build b/wrapdb/rtMessage/include-workaround-meson/rtmessage/meson.build similarity index 100% rename from subprojects/rtMessage/include-workaround-meson/rtmessage/meson.build rename to wrapdb/rtMessage/include-workaround-meson/rtmessage/meson.build diff --git a/subprojects/rtMessage/meson.build b/wrapdb/rtMessage/meson.build similarity index 100% rename from subprojects/rtMessage/meson.build rename to wrapdb/rtMessage/meson.build From 373423eb367ed5a78580cc68b13b62a0c9b02c76 Mon Sep 17 00:00:00 2001 From: Weston Schmidt Date: Mon, 25 Oct 2021 22:04:35 -0700 Subject: [PATCH 05/35] Graft enough meson build scripts onto the rbus libraries so we can build cpeabs. --- .gitignore | 4 ++++ README.md | 4 ++++ include/cpeabs/cpeabs.h | 3 ++- meson.build | 6 ++++-- subprojects/rbus-core.wrap | 8 -------- subprojects/rbus.wrap | 1 + subprojects/rbuscore.wrap | 9 +++++++++ workaround.sh | 10 +++++++++- wrapdb/rbus/include-workaround-meson/rbus/meson.build | 9 +++++++++ wrapdb/rbus/include/meson.build | 6 ++++++ wrapdb/rbus/meson.build | 11 +++++++++++ wrapdb/rbuscore/meson.build | 8 ++++++++ wrapdb/rtMessage/meson.build | 5 +++-- 13 files changed, 70 insertions(+), 14 deletions(-) delete mode 100644 subprojects/rbus-core.wrap create mode 100644 subprojects/rbuscore.wrap create mode 100644 wrapdb/rbus/include-workaround-meson/rbus/meson.build create mode 100644 wrapdb/rbus/include/meson.build create mode 100644 wrapdb/rbus/meson.build create mode 100644 wrapdb/rbuscore/meson.build diff --git a/.gitignore b/.gitignore index 5f6bec7..7f2071a 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,7 @@ _testmain.go *.test *.prof *.xml + +subprojects/rbus* +subprojects/rtMessage +subprojects/cJSON* diff --git a/README.md b/README.md index 87ca294..d93e2b2 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,12 @@ An abstraction layer for consumer preference equipment systems. # Building and Testing Instructions ``` +./workaround.sh meson build cd build ninja all test coverage firefox meson-logs/coveragereport/index.html ``` + +The `workaround.sh` script makes it so we don't need to add the rbus stuff to the +upstream wrapdb. diff --git a/include/cpeabs/cpeabs.h b/include/cpeabs/cpeabs.h index 868444b..fb6a0ae 100644 --- a/include/cpeabs/cpeabs.h +++ b/include/cpeabs/cpeabs.h @@ -7,6 +7,7 @@ #include #include -#include +/* Don't do this ... you loose the portability you are after. */ +#include #endif diff --git a/meson.build b/meson.build index e059b29..6718900 100644 --- a/meson.build +++ b/meson.build @@ -21,8 +21,10 @@ prefix = get_option('prefix') # Dependencies ################################################################################ #cjson -libcjson_dep = dependency('libcjson', version: '>=1.7.14', fallback: ['cjson']) -librtMessage_dep = dependency('librtMessage') +libcjson_dep = dependency('libcjson', version: '>=1.7.14', fallback: ['cjson']) +librtMessage_dep = dependency('librtMessage') +librbuscore_dep = dependency('librbuscore') +librbus_dep = dependency('librbus') all_dep = [libcjson_dep, librtMessage_dep, librbuscore_dep, librbus_dep] diff --git a/subprojects/rbus-core.wrap b/subprojects/rbus-core.wrap deleted file mode 100644 index d0ad384..0000000 --- a/subprojects/rbus-core.wrap +++ /dev/null @@ -1,8 +0,0 @@ -[wrap-git] -directory = rbus-core - -url = https://github.com/rdkcmf/rbuscore -revision = rdk-next - -[provide] -librbus-core = librbus-core_dep diff --git a/subprojects/rbus.wrap b/subprojects/rbus.wrap index 3a58c8c..6f20ff1 100644 --- a/subprojects/rbus.wrap +++ b/subprojects/rbus.wrap @@ -3,6 +3,7 @@ directory = rbus url = https://github.com/rdkcmf/rbus.git revision = rdk-next +patch_filename = rbus.tar.gz [provide] librbus = librbus_dep diff --git a/subprojects/rbuscore.wrap b/subprojects/rbuscore.wrap new file mode 100644 index 0000000..b182fb5 --- /dev/null +++ b/subprojects/rbuscore.wrap @@ -0,0 +1,9 @@ +[wrap-git] +directory = rbuscore + +url = https://github.com/rdkcmf/rbuscore +revision = rdk-next +patch_filename = rbuscore.tar.gz + +[provide] +librbuscore = librbuscore_dep diff --git a/workaround.sh b/workaround.sh index 2d3a64e..2c490ca 100755 --- a/workaround.sh +++ b/workaround.sh @@ -3,6 +3,14 @@ mkdir -p subprojects/packagefiles pushd wrapdb + tar -czf rtMessage.tar.gz rtMessage -mv rtMessage.tar.gz ../subprojects/packagefiles/. +mv -f rtMessage.tar.gz ../subprojects/packagefiles/. + +tar -czf rbuscore.tar.gz rbuscore +mv -f rbuscore.tar.gz ../subprojects/packagefiles/. + +tar -czf rbus.tar.gz rbus +mv -f rbus.tar.gz ../subprojects/packagefiles/. + popd diff --git a/wrapdb/rbus/include-workaround-meson/rbus/meson.build b/wrapdb/rbus/include-workaround-meson/rbus/meson.build new file mode 100644 index 0000000..c9ecfcc --- /dev/null +++ b/wrapdb/rbus/include-workaround-meson/rbus/meson.build @@ -0,0 +1,9 @@ +# This is a workaround for creating a rbus/ folder with the headers in it in +# the builddir space. +# +# See https://github.com/mesonbuild/meson/issues/2546 for where the technique comes from +foreach h: headers + configure_file(copy: true, + input: h, + output: '@PLAINNAME@') +endforeach diff --git a/wrapdb/rbus/include/meson.build b/wrapdb/rbus/include/meson.build new file mode 100644 index 0000000..1a58d74 --- /dev/null +++ b/wrapdb/rbus/include/meson.build @@ -0,0 +1,6 @@ +headers = files('rbus_filter.h', + 'rbus.h', + 'rbus_message.h', + 'rbus_object.h', + 'rbus_property.h', + 'rbus_value.h') diff --git a/wrapdb/rbus/meson.build b/wrapdb/rbus/meson.build new file mode 100644 index 0000000..0e66081 --- /dev/null +++ b/wrapdb/rbus/meson.build @@ -0,0 +1,11 @@ +project('rbus', 'c', + version: '0.0.1', + meson_version: '>=0.54.0', + license: ['Apache-2.0'], + default_options: ['c_std=c18']) + +subdir('include') +subdir('include-workaround-meson/rbus') + +librbus_dep = declare_dependency(include_directories: ['include-workaround-meson', + 'include-workaround-meson/rbus']) diff --git a/wrapdb/rbuscore/meson.build b/wrapdb/rbuscore/meson.build new file mode 100644 index 0000000..ccba7c7 --- /dev/null +++ b/wrapdb/rbuscore/meson.build @@ -0,0 +1,8 @@ +project('rbuscore', 'c', + version: '0.0.1', + meson_version: '>=0.54.0', + license: ['Apache-2.0'], + default_options: ['c_std=c18']) + + +librbuscore_dep = declare_dependency(include_directories: ['rbus-core/include']) diff --git a/wrapdb/rtMessage/meson.build b/wrapdb/rtMessage/meson.build index 7df1545..e6aa7aa 100644 --- a/wrapdb/rtMessage/meson.build +++ b/wrapdb/rtMessage/meson.build @@ -41,10 +41,11 @@ librtMessage = library('rtMessage', 'local_benchmarking.c'], c_args: ['-D_GNU_SOURCE', '-D_POSIX_C_SOURCE=199309L'], cpp_args: ['-D_GNU_SOURCE', '-D_POSIX_C_SOURCE=199309L'], - dependencies: [ libcjson_dep ], + dependencies: [ libcjson_dep, thread_dep ], install: true) -librtMessage_dep = declare_dependency(include_directories: ['include-workaround-meson'], +librtMessage_dep = declare_dependency(include_directories: ['include-workaround-meson', + 'include-workaround-meson/rtmessage'], link_with: librtMessage) if meson.version().version_compare('>=0.54.0') From 59ba959f7d72270c2ec1b0c22ec243c878310388 Mon Sep 17 00:00:00 2001 From: Guru Chandru Date: Tue, 26 Oct 2021 14:51:06 +0530 Subject: [PATCH 06/35] cJSON build issue fix --- subprojects/rtMessage.wrap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subprojects/rtMessage.wrap b/subprojects/rtMessage.wrap index 69ecd62..68eab43 100644 --- a/subprojects/rtMessage.wrap +++ b/subprojects/rtMessage.wrap @@ -1,7 +1,7 @@ [wrap-git] directory = rtMessage -url = https://github.com/rdkcmf/rdk-rtmessage.git +url = https://github.com/guruchandru/rdk-rtmessage.git revision = rdk-next patch_filename = rtMessage.tar.gz From 8572fb7f52b00c9222403dff909d40bbbf5f53fe Mon Sep 17 00:00:00 2001 From: Guru Chandru Date: Tue, 26 Oct 2021 18:01:02 +0530 Subject: [PATCH 07/35] Script and executable change --- meson.build | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/meson.build b/meson.build index 6718900..661b81f 100644 --- a/meson.build +++ b/meson.build @@ -15,6 +15,16 @@ if not meson.is_subproject() werror = true endif +script = join_paths(meson.source_root(), 'workaround.sh') + +r = run_command('/bin/sh', script) +if r.returncode() != 0 + message('script failed') +endif + +output = r.stdout().strip() +errortxt = r.stderr().strip() + prefix = get_option('prefix') ################################################################################ @@ -70,12 +80,12 @@ libcpeabs = library(meson.project_name(), install: true, link_args: src_args) -#executable(meson.project_name(), - # sources, - # include_directories: inc, - # dependencies: all_dep, - # install: true, - # link_args: src_args) +executable(meson.project_name(), + sources, + include_directories: inc, + dependencies: all_dep, + install: true, + link_args: src_args) ################################################################################ # Define the tests From a7c4c2b0296a165bde90ed9850ab5ad98f83f6d6 Mon Sep 17 00:00:00 2001 From: Guru Chandru Date: Tue, 26 Oct 2021 20:41:46 +0530 Subject: [PATCH 08/35] Test changes --- src/common.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/common.c b/src/common.c index b0ad4ef..d641530 100644 --- a/src/common.c +++ b/src/common.c @@ -8,6 +8,7 @@ #include //#include "../../subprojects/wdmp/src/wdmp-c.h" #include +#include #include /*----------------------------------------------------------------------------*/ /* Macros */ @@ -42,6 +43,12 @@ int main() req = (req_struct *) malloc (sizeof(req_struct)); do_something();*/ //wdmp_parse_generic_request("Hi", WDMP_TR181, &req); + rtMessageHeader* testrt = NULL; + testrt = (rtMessageHeader*)malloc(sizeof(rtMessageHeader)); + + rtMessageHeader_Init(testrt); + + do_something(); return 0; } From d93d6c6746f81fb5a26bad734fd83f5aa4b104ef Mon Sep 17 00:00:00 2001 From: Weston Schmidt Date: Tue, 26 Oct 2021 11:27:14 -0700 Subject: [PATCH 09/35] Work around the old version of meson in RDK Yocto today (0.53). --- meson.build | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 6718900..2e6dd66 100644 --- a/meson.build +++ b/meson.build @@ -5,6 +5,7 @@ project('cpeabs', 'c', version: '0.0.0', + meson_version: '>=0.53', license: ['Apache-2.0'], default_options: ['c_std=c99', 'b_coverage=true']) @@ -20,11 +21,22 @@ prefix = get_option('prefix') ################################################################################ # Dependencies ################################################################################ -#cjson + +if meson.version().version_compare('>=0.54.0') libcjson_dep = dependency('libcjson', version: '>=1.7.14', fallback: ['cjson']) librtMessage_dep = dependency('librtMessage') librbuscore_dep = dependency('librbuscore') librbus_dep = dependency('librbus') +else +warning('You are running an older version of meson.') +warning('In order for dependency management to be supported you need a newer version of meson (0.54+)') +# For older versions of meson, you need to have the upstream dependencies installed +# in the correct locations. +libcjson_dep = dependency('libcjson') +librtMessage_dep = dependency('librtMessage') +librbuscore_dep = dependency('librbuscore') +librbus_dep = dependency('librbus') +endif all_dep = [libcjson_dep, librtMessage_dep, librbuscore_dep, librbus_dep] From 998d824578e89c58ec8af9e3411933ec7eab9ff0 Mon Sep 17 00:00:00 2001 From: Guru Chandru Date: Wed, 27 Oct 2021 12:19:40 +0530 Subject: [PATCH 10/35] Fix for rbus related yocto dependency --- include/cpeabs/cpeabs.h | 1 - meson.build | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/include/cpeabs/cpeabs.h b/include/cpeabs/cpeabs.h index fb6a0ae..f58218d 100644 --- a/include/cpeabs/cpeabs.h +++ b/include/cpeabs/cpeabs.h @@ -8,6 +8,5 @@ #include /* Don't do this ... you loose the portability you are after. */ -#include #endif diff --git a/meson.build b/meson.build index 1d16ef0..cd9e4f5 100644 --- a/meson.build +++ b/meson.build @@ -43,12 +43,12 @@ warning('In order for dependency management to be supported you need a newer ver # For older versions of meson, you need to have the upstream dependencies installed # in the correct locations. libcjson_dep = dependency('libcjson') -librtMessage_dep = dependency('librtMessage') -librbuscore_dep = dependency('librbuscore') -librbus_dep = dependency('librbus') +#librtMessage_dep = dependency('rtMessage') +#librbuscore_dep = dependency('rbus-core') +#librbus_dep = dependency('rbus') endif -all_dep = [libcjson_dep, librtMessage_dep, librbuscore_dep, librbus_dep] +all_dep = [libcjson_dep]#, librbuscore_dep, librbus_dep] #wdmp-c dependencies @@ -106,7 +106,7 @@ executable(meson.project_name(), if not meson.is_subproject() test_args = ['-fprofile-arcs', '-ftest-coverage', '-O0'] - cunit_dep = dependency('cunit') + # cunit_dep = dependency('cunit') tests = [ ['test common', 'test_common'], @@ -116,7 +116,7 @@ if not meson.is_subproject() test(test[0], executable(test[1], ['tests/'+test[1]+'.c'], include_directories: inc, - dependencies: cunit_dep, + # dependencies: cunit_dep, install: false, link_args: test_args, link_with: libcpeabs)) From c5ca0fe6a1c719123ed52b90020c652c1b1e4194 Mon Sep 17 00:00:00 2001 From: Guru Chandru Date: Thu, 28 Oct 2021 17:46:01 +0530 Subject: [PATCH 11/35] Cmake change for cpeabs --- CMakeLists.txt | 140 ++++++++++++++++ README.md | 8 +- include/cpeabs/meson.build | 27 ---- include/cpeabs/ver.h.in | 27 ---- meson.build | 150 ------------------ src/CMakeLists.txt | 29 ++++ src/common.c | 7 +- include/cpeabs/cpeabs.h => src/common.h | 3 - subprojects/cjson.wrap | 11 -- subprojects/rbus.wrap | 9 -- subprojects/rbuscore.wrap | 9 -- subprojects/rtMessage.wrap | 9 -- subprojects/wdmp.wrap | 8 - tests/CMakeLists.txt | 50 ++++++ tests/test_common.c | 19 ++- workaround.sh | 16 -- .../include-workaround-meson/rbus/meson.build | 9 -- wrapdb/rbus/include/meson.build | 6 - wrapdb/rbus/meson.build | 11 -- wrapdb/rbuscore/meson.build | 8 - .../rtmessage/meson.build | 9 -- wrapdb/rtMessage/meson.build | 53 ------- 22 files changed, 240 insertions(+), 378 deletions(-) create mode 100644 CMakeLists.txt delete mode 100644 include/cpeabs/meson.build delete mode 100644 include/cpeabs/ver.h.in delete mode 100644 meson.build create mode 100644 src/CMakeLists.txt rename include/cpeabs/cpeabs.h => src/common.h (56%) delete mode 100644 subprojects/cjson.wrap delete mode 100644 subprojects/rbus.wrap delete mode 100644 subprojects/rbuscore.wrap delete mode 100644 subprojects/rtMessage.wrap delete mode 100644 subprojects/wdmp.wrap create mode 100644 tests/CMakeLists.txt delete mode 100755 workaround.sh delete mode 100644 wrapdb/rbus/include-workaround-meson/rbus/meson.build delete mode 100644 wrapdb/rbus/include/meson.build delete mode 100644 wrapdb/rbus/meson.build delete mode 100644 wrapdb/rbuscore/meson.build delete mode 100644 wrapdb/rtMessage/include-workaround-meson/rtmessage/meson.build delete mode 100644 wrapdb/rtMessage/meson.build diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..fd7bfe7 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,140 @@ +# Copyright 2020 +# +# 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. + +cmake_minimum_required(VERSION 2.8.7) + +project(cpeabs) + +include(ExternalProject) +include(CTest) + +add_definitions(-std=c99) +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -g -Werror -Wall -D_GNU_SOURCE=1") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c99 -g -Werror -Wall -D_GNU_SOURCE=1") + +if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") +set(CMAKE_MACOSX_RPATH 1) +set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup") +endif() + +set(INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/_install) +set(PREFIX_DIR ${CMAKE_CURRENT_BINARY_DIR}/_prefix) +set(INCLUDE_DIR ${INSTALL_DIR}/include) +set(LIBRARY_DIR ${INSTALL_DIR}/lib) +set(LIBRARY_DIR64 ${INSTALL_DIR}/lib64) +set(COMMON_LIBRARY_DIR ${INSTALL_DIR}/lib/${CMAKE_LIBRARY_ARCHITECTURE}) +set(TEST_RESULTS_DIR ${CMAKE_CURRENT_BINARY_DIR}/test_results) +file(MAKE_DIRECTORY ${TEST_RESULTS_DIR}) + +include_directories(${INCLUDE_DIR} + ${INCLUDE_DIR}/cjson + ${INCLUDE_DIR}/msgpack + ${INCLUDE_DIR}/rbus + ${INCLUDE_DIR}/rbus-core + ${INCLUDE_DIR}/rtmessage + #${INCLUDE_DIR}/trower-base64 + #${INCLUDE_DIR}/wdmp-c + #${INCLUDE_DIR}/cimplog + #${INCLUDE_DIR}/wrp-c +# ${INCLUDE_DIR}/curl + ) +#if (FEATURE_SUPPORT_AKER) +#include_directories(${INCLUDE_DIR}/nanomsg +# ${INCLUDE_DIR}/libparodus +#) +#endif (FEATURE_SUPPORT_AKER) + +#if (WEBCONFIG_BIN_SUPPORT) +#include_directories(${INCLUDE_DIR}/rbus +# ${INCLUDE_DIR}/rbus-core +# ${INCLUDE_DIR}/rtmessage +#) +#endif (WEBCONFIG_BIN_SUPPORT) + +if (NOT BUILD_YOCTO) + +# msgpack-c external dependency +#------------------------------------------------------------------------------- +ExternalProject_Add(msgpack + PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/msgpack + GIT_REPOSITORY https://github.com/msgpack/msgpack-c.git + GIT_TAG "7a98138f27f27290e680bf8fbf1f8d1b089bf138" + CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} + -DMSGPACK_ENABLE_CXX=OFF + -DMSGPACK_BUILD_EXAMPLES=OFF + -DBUILD_TESTING=OFF +) +add_library(libmsgpack STATIC SHARED IMPORTED) +add_dependencies(libmsgpack msgpack) + +# cJSON external dependency +#------------------------------------------------------------------------------- +ExternalProject_Add(cJSON + PREFIX ${PREFIX_DIR}/cJSON + GIT_REPOSITORY https://github.com/DaveGamble/cJSON.git + GIT_TAG "aafb64a1c549b7b927e339df6d35b1d5059dc235" + CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} +) +add_library(libcJSON STATIC IMPORTED) +add_dependencies(libcJSON cJSON) + +# rtMessage external dependency +#------------------------------------------------------------------------------- +ExternalProject_Add(rtMessage + PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/rtMessage + GIT_REPOSITORY https://github.com/rdkcmf/rdk-rtmessage.git + GIT_TAG rdk-next + CMAKE_ARGS += -DBUILD_RTMESSAGE_LIB=ON + -DBUILD_RTMESSAGE_SAMPLE_APP=ON + -DBUILD_FOR_DESKTOP=ON + -DBUILD_DATAPROVIDER_LIB=ON + -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTING=OFF +) +add_library(librtMessage STATIC SHARED IMPORTED) +add_dependencies(librtMessage rtMessage) + +# rbus-core external dependency +#------------------------------------------------------------------------------- +ExternalProject_Add(rbus-core + DEPENDS rtMessage + PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/rbus-core + GIT_REPOSITORY https://github.com/rdkcmf/rbuscore.git + GIT_TAG rdk-next + CMAKE_ARGS += DBUILD_FOR_DESKTOP=ON -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} + -DBUILD_TESTING=OFF +) +add_library(librbus-core STATIC SHARED IMPORTED) +add_dependencies(librbus-core rbus-core) + +# rbus external dependency +#------------------------------------------------------------------------------- +ExternalProject_Add(rbus + DEPENDS rtMessage rbus-core + PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/rbus + GIT_REPOSITORY https://github.com/rdkcmf/rbus.git + GIT_TAG rdk-next + CMAKE_ARGS += -DBUILD_FOR_DESKTOP=ON -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTING=OFF +) + +add_library(librbus STATIC SHARED IMPORTED) +add_dependencies(librbus rbus) + +endif () +link_directories ( ${LIBRARY_DIR} ${COMMON_LIBRARY_DIR} ${LIBRARY_DIR64} ) + +add_subdirectory(src) + +if (BUILD_TESTING) + add_subdirectory(tests) +endif (BUILD_TESTING) diff --git a/README.md b/README.md index d93e2b2..4481262 100644 --- a/README.md +++ b/README.md @@ -18,11 +18,11 @@ An abstraction layer for consumer preference equipment systems. # Building and Testing Instructions ``` -./workaround.sh -meson build +mkdir build cd build -ninja all test coverage -firefox meson-logs/coveragereport/index.html +cmake .. +make +make test ``` The `workaround.sh` script makes it so we don't need to add the rbus stuff to the diff --git a/include/cpeabs/meson.build b/include/cpeabs/meson.build deleted file mode 100644 index e7fa3b0..0000000 --- a/include/cpeabs/meson.build +++ /dev/null @@ -1,27 +0,0 @@ -# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC -# SPDX-License-Identifier: Apache-2.0 - -version = meson.project_version() -version_arr = version.split('.') -major = version_arr[0].to_int() -minor = version_arr[1].to_int() -patch = version_arr[2].to_int() - -hex = '0123456789abcdef' -ver = '0x@0@@1@@2@@3@@4@@5@' -bitwise = ver.format(hex[major / 16], hex[major % 16], - hex[minor / 16], hex[minor % 16], - hex[patch / 16], hex[patch % 16]) - -cfg = configuration_data() -cfg.set( meson.project_name()+'_VERSION', version) -cfg.set( meson.project_name()+'_VERSION_MAJOR', major) -cfg.set( meson.project_name()+'_VERSION_MINOR', minor) -cfg.set( meson.project_name()+'_VERSION_PATCH', patch) -cfg.set( meson.project_name()+'_BITWISE_VERSION', bitwise) - -ver_h = configure_file(input: 'ver.h.in', - output: 'ver.h', - configuration: cfg) - -headers = files(['cpeabs.h']) diff --git a/include/cpeabs/ver.h.in b/include/cpeabs/ver.h.in deleted file mode 100644 index d7e72f1..0000000 --- a/include/cpeabs/ver.h.in +++ /dev/null @@ -1,27 +0,0 @@ -/* SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC */ -/* SPDX-License-Identifier: Apache-2.0 */ - -#ifndef __CPEABS_VERSION_H__ -#define __CPEABS_VERSION_H__ 1 - -#define CPEABS_VERSION "@cpeabs_VERSION@" - -#define CPEABS_VERSION_MAJOR @cpeabs_VERSION_MAJOR @ -#define CPEABS_VERSION_MINOR @cpeabs_VERSION_MINOR @ -#define CPEABS_VERSION_PATCH @cpeabs_VERSION_PATCH @ - -/* This is the numeric version of the cpeabs version number, meant for easier - * parsing and comparisons by programs. The CPEABS_VERSION_NUM define - * will always follow this syntax: - * - * 0xAABBCC - * - * Where AA, BB, and CC are each major version, minor version, patch in hex - * using 8 bits each. - * - * It should be safe to compare two different versions with the greater number - * being the newer version. - */ -#define CPEABS_VERSION_NUM @cpeabs_BITWISE_VERSION @ - -#endif diff --git a/meson.build b/meson.build deleted file mode 100644 index cd9e4f5..0000000 --- a/meson.build +++ /dev/null @@ -1,150 +0,0 @@ -# Meson build file -# -# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC -# SPDX-License-Identifier: Apache-2.0 - -project('cpeabs', 'c', - version: '0.0.0', - meson_version: '>=0.53', - license: ['Apache-2.0'], - default_options: ['c_std=c99', - 'b_coverage=true']) - -if not meson.is_subproject() - # We want strict flags - warning_level = 3 # -Wall - werror = true -endif - -script = join_paths(meson.source_root(), 'workaround.sh') - -r = run_command('/bin/sh', script) -if r.returncode() != 0 - message('script failed') -endif - -output = r.stdout().strip() -errortxt = r.stderr().strip() - -prefix = get_option('prefix') - -################################################################################ -# Dependencies -################################################################################ - -if meson.version().version_compare('>=0.54.0') -libcjson_dep = dependency('libcjson', version: '>=1.7.14', fallback: ['cjson']) -librtMessage_dep = dependency('librtMessage') -librbuscore_dep = dependency('librbuscore') -librbus_dep = dependency('librbus') -else -warning('You are running an older version of meson.') -warning('In order for dependency management to be supported you need a newer version of meson (0.54+)') -# For older versions of meson, you need to have the upstream dependencies installed -# in the correct locations. -libcjson_dep = dependency('libcjson') -#librtMessage_dep = dependency('rtMessage') -#librbuscore_dep = dependency('rbus-core') -#librbus_dep = dependency('rbus') -endif - -all_dep = [libcjson_dep]#, librbuscore_dep, librbus_dep] - -#wdmp-c dependencies - -#wdmpcmake = import('cmake') - -#wdmp_opts = wdmpcmake.subproject_options() - -#wdmp_opts.add_cmake_defines({'CMAKE_POSITION_INDEPENDENT_CODE': true}) - -#wdmp_proj = wdmpcmake.subproject('wdmp', options: wdmp_opts) - -#libwdmp_dep = wdmp_proj.dependency('wdmp-c') - -################################################################################ -# Common variable definitions -################################################################################ - -inc_base = ['include/'+meson.project_name()]#, 'subprojects/rtMessage', 'subprojects/rbus-core', 'subprojects/rbus'] - -################################################################################ -# Generate the version header file -################################################################################ - -subdir('include/'+meson.project_name()) - -install_headers(['include/'+meson.project_name()+'/cpeabs.h', ver_h], subdir: meson.project_name()) - -################################################################################ -# Define the libraries -################################################################################ - -inc = include_directories([inc_base]) - -src_args = ['-lcjson', '-lpthread'] -sources = ['src/common.c'] - -libcpeabs = library(meson.project_name(), - sources, - include_directories: inc, - dependencies: all_dep, - install: true, - link_args: src_args) - -executable(meson.project_name(), - sources, - include_directories: inc, - dependencies: all_dep, - install: true, - link_args: src_args) - -################################################################################ -# Define the tests -################################################################################ - -if not meson.is_subproject() - test_args = ['-fprofile-arcs', '-ftest-coverage', '-O0'] - - # cunit_dep = dependency('cunit') - - tests = [ - ['test common', 'test_common'], - ] - - foreach test : tests - test(test[0], - executable(test[1], ['tests/'+test[1]+'.c'], - include_directories: inc, - # dependencies: cunit_dep, - install: false, - link_args: test_args, - link_with: libcpeabs)) - endforeach - - add_test_setup('valgrind', - is_default: true, - exe_wrapper: [ 'valgrind', - '--leak-check=full', - '--error-exitcode=1' ], - timeout_multiplier: 2) -endif - -################################################################################ -# Add the license check target -################################################################################ - -reuse_bin = find_program('reuse', required: false) -if reuse_bin.found() - custom_target('license', - command: [reuse_bin, 'lint'], - build_always_stale: true, - output: ['license']) -endif - -libcpeabs_dep = declare_dependency(include_directories: ['include'], - link_with: libcpeabs) - -if meson.version().version_compare('>=0.54.0') - meson.override_dependency(meson.project_name(), libcpeabs_dep) -endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..f70cd55 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,29 @@ +# Copyright 2021 Comcast Cable Communications Management, LLC +# +# 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. + +set(PROJ_CPEABS cpeabs) +set(HEADERS common.h) +set(SOURCES common.c) + +#Support webcfg lib for backward compatibility +add_library(${PROJ_CPEABS} STATIC ${HEADERS} ${SOURCES}) +add_library(${PROJ_CPEABS}.shared SHARED ${HEADERS} ${SOURCES}) +set_target_properties(${PROJ_CPEABS}.shared PROPERTIES OUTPUT_NAME ${PROJ_CPEABS}) +set_property(TARGET ${PROJ_CPEABS} PROPERTY C_STANDARD 99) +set_property(TARGET ${PROJ_CPEABS}.shared PROPERTY C_STANDARD 99) + +install (TARGETS ${PROJ_CPEABS} DESTINATION lib${LIB_SUFFIX}) +install (TARGETS ${PROJ_CPEABS}.shared DESTINATION lib${LIB_SUFFIX}) +install (FILES ${HEADERS} DESTINATION include/${PROJ_CPEABS}) + diff --git a/src/common.c b/src/common.c index d641530..1d26bcb 100644 --- a/src/common.c +++ b/src/common.c @@ -1,12 +1,7 @@ -/* SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC */ -/* SPDX-License-Identifier: Apache-2.0 */ - #include #include #include #include -#include -//#include "../../subprojects/wdmp/src/wdmp-c.h" #include #include #include @@ -37,7 +32,7 @@ void do_something(); /*----------------------------------------------------------------------------*/ /* External Functions */ /*----------------------------------------------------------------------------*/ -int main() +int cpeabs() { /* req_struct *req = NULL; req = (req_struct *) malloc (sizeof(req_struct)); diff --git a/include/cpeabs/cpeabs.h b/src/common.h similarity index 56% rename from include/cpeabs/cpeabs.h rename to src/common.h index f58218d..ea6eedf 100644 --- a/include/cpeabs/cpeabs.h +++ b/src/common.h @@ -1,6 +1,3 @@ -/* SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC */ -/* SPDX-License-Identifier: Apache-2.0 */ - #ifndef __CPEABS_H__ #define __CPEABS_H__ diff --git a/subprojects/cjson.wrap b/subprojects/cjson.wrap deleted file mode 100644 index 26a0097..0000000 --- a/subprojects/cjson.wrap +++ /dev/null @@ -1,11 +0,0 @@ -[wrap-file] -directory = cJSON-1.7.14 -source_url = https://github.com/DaveGamble/cJSON/archive/refs/tags/v1.7.14.tar.gz -source_filename = v1.7.14.tar.gz -source_hash = fb50a663eefdc76bafa80c82bc045af13b1363e8f45cec8b442007aef6a41343 -patch_filename = cjson_1.7.14-1_patch.zip -patch_url = https://wrapdb.mesonbuild.com/v2/cjson_1.7.14-1/get_patch -patch_hash = 82d7a029637bdd6696a89075907581768e7088c20b1c69f400cb6e15e716d803 - -[provide] -libcjson = libcjson_dep diff --git a/subprojects/rbus.wrap b/subprojects/rbus.wrap deleted file mode 100644 index 6f20ff1..0000000 --- a/subprojects/rbus.wrap +++ /dev/null @@ -1,9 +0,0 @@ -[wrap-git] -directory = rbus - -url = https://github.com/rdkcmf/rbus.git -revision = rdk-next -patch_filename = rbus.tar.gz - -[provide] -librbus = librbus_dep diff --git a/subprojects/rbuscore.wrap b/subprojects/rbuscore.wrap deleted file mode 100644 index b182fb5..0000000 --- a/subprojects/rbuscore.wrap +++ /dev/null @@ -1,9 +0,0 @@ -[wrap-git] -directory = rbuscore - -url = https://github.com/rdkcmf/rbuscore -revision = rdk-next -patch_filename = rbuscore.tar.gz - -[provide] -librbuscore = librbuscore_dep diff --git a/subprojects/rtMessage.wrap b/subprojects/rtMessage.wrap deleted file mode 100644 index 68eab43..0000000 --- a/subprojects/rtMessage.wrap +++ /dev/null @@ -1,9 +0,0 @@ -[wrap-git] -directory = rtMessage - -url = https://github.com/guruchandru/rdk-rtmessage.git -revision = rdk-next -patch_filename = rtMessage.tar.gz - -[provide] -librtMessage = librtMessage_dep diff --git a/subprojects/wdmp.wrap b/subprojects/wdmp.wrap deleted file mode 100644 index 12b28c9..0000000 --- a/subprojects/wdmp.wrap +++ /dev/null @@ -1,8 +0,0 @@ -[wrap-git] -directory = wdmp - -url = https://github.com/xmidt-org/wdmp-c.git -revision = dd95994163333dc997a2620ee482ed99c35d1d3c - -[provide] -libwdmp = libwdmp_dep diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..d7da11c --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,50 @@ +# Copyright 2021 Comcast Cable Communications Management, LLC +# +# 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. + +set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -W -g -fprofile-arcs -ftest-coverage -O0") +set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST ") +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W -g -fprofile-arcs -ftest-coverage -O0") +set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -O0") + +if(NOT DISABLE_VALGRIND) +set (MEMORY_CHECK valgrind --leak-check=full --show-reachable=yes --track-origins=yes -v) +endif () + +link_directories ( ${LIBRARY_DIR} ) +#------------------------------------------------------------------------------- +# test_common +#------------------------------------------------------------------------------- +add_test(NAME test_common COMMAND ${MEMORY_CHECK} ./test_common) + +set(SOURCES test_common.c ../src/common.c ) + +add_executable(test_common ${SOURCES}) + +target_link_libraries (test_common -lcunit -lmsgpackc -lpthread -lrbus -lrbus-core -lrtMessage) + +target_link_libraries (test_common gcov -Wl,--no-as-needed ) + + +# Code coverage + +add_custom_target(coverage +COMMAND lcov -q --capture --directory +${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_common.dir/__/src --output-file test_common.info + +COMMAND lcov +-a test_common.info +--output-file coverage.info + +COMMAND genhtml coverage.info +WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) diff --git a/tests/test_common.c b/tests/test_common.c index b621357..e0cc801 100644 --- a/tests/test_common.c +++ b/tests/test_common.c @@ -1,6 +1,19 @@ -/* SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC */ -/* SPDX-License-Identifier: Apache-2.0 */ - + /** + * Copyright 2019 Comcast Cable Communications Management, LLC + * + * 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. + * + */ #include #include #include diff --git a/workaround.sh b/workaround.sh deleted file mode 100755 index 2c490ca..0000000 --- a/workaround.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -mkdir -p subprojects/packagefiles - -pushd wrapdb - -tar -czf rtMessage.tar.gz rtMessage -mv -f rtMessage.tar.gz ../subprojects/packagefiles/. - -tar -czf rbuscore.tar.gz rbuscore -mv -f rbuscore.tar.gz ../subprojects/packagefiles/. - -tar -czf rbus.tar.gz rbus -mv -f rbus.tar.gz ../subprojects/packagefiles/. - -popd diff --git a/wrapdb/rbus/include-workaround-meson/rbus/meson.build b/wrapdb/rbus/include-workaround-meson/rbus/meson.build deleted file mode 100644 index c9ecfcc..0000000 --- a/wrapdb/rbus/include-workaround-meson/rbus/meson.build +++ /dev/null @@ -1,9 +0,0 @@ -# This is a workaround for creating a rbus/ folder with the headers in it in -# the builddir space. -# -# See https://github.com/mesonbuild/meson/issues/2546 for where the technique comes from -foreach h: headers - configure_file(copy: true, - input: h, - output: '@PLAINNAME@') -endforeach diff --git a/wrapdb/rbus/include/meson.build b/wrapdb/rbus/include/meson.build deleted file mode 100644 index 1a58d74..0000000 --- a/wrapdb/rbus/include/meson.build +++ /dev/null @@ -1,6 +0,0 @@ -headers = files('rbus_filter.h', - 'rbus.h', - 'rbus_message.h', - 'rbus_object.h', - 'rbus_property.h', - 'rbus_value.h') diff --git a/wrapdb/rbus/meson.build b/wrapdb/rbus/meson.build deleted file mode 100644 index 0e66081..0000000 --- a/wrapdb/rbus/meson.build +++ /dev/null @@ -1,11 +0,0 @@ -project('rbus', 'c', - version: '0.0.1', - meson_version: '>=0.54.0', - license: ['Apache-2.0'], - default_options: ['c_std=c18']) - -subdir('include') -subdir('include-workaround-meson/rbus') - -librbus_dep = declare_dependency(include_directories: ['include-workaround-meson', - 'include-workaround-meson/rbus']) diff --git a/wrapdb/rbuscore/meson.build b/wrapdb/rbuscore/meson.build deleted file mode 100644 index ccba7c7..0000000 --- a/wrapdb/rbuscore/meson.build +++ /dev/null @@ -1,8 +0,0 @@ -project('rbuscore', 'c', - version: '0.0.1', - meson_version: '>=0.54.0', - license: ['Apache-2.0'], - default_options: ['c_std=c18']) - - -librbuscore_dep = declare_dependency(include_directories: ['rbus-core/include']) diff --git a/wrapdb/rtMessage/include-workaround-meson/rtmessage/meson.build b/wrapdb/rtMessage/include-workaround-meson/rtmessage/meson.build deleted file mode 100644 index ae17948..0000000 --- a/wrapdb/rtMessage/include-workaround-meson/rtmessage/meson.build +++ /dev/null @@ -1,9 +0,0 @@ -# This is a workaround for creating a rtmessage/ folder with the headers in it in -# the builddir space. -# -# See https://github.com/mesonbuild/meson/issues/2546 for where the technique comes from -foreach h: headers - configure_file(copy: true, - input: h, - output: '@PLAINNAME@') -endforeach diff --git a/wrapdb/rtMessage/meson.build b/wrapdb/rtMessage/meson.build deleted file mode 100644 index e6aa7aa..0000000 --- a/wrapdb/rtMessage/meson.build +++ /dev/null @@ -1,53 +0,0 @@ -project('rtMessage', 'c', - version: '0.0.1', - meson_version: '>=0.54.0', - license: ['Apache-2.0'], - default_options: ['c_std=c18']) - - -libcjson_dep = dependency('libcjson', version: '>=1.7.14', fallback: ['cjson']) -thread_dep = dependency('threads') - -headers = files('rtMessage.h', - 'rtMessageHeader.h', - 'rtError.h', - 'rtConnection.h', - 'rtVector.h', - 'rtRetainable.h', - 'rtLog.h', - 'rtList.h', - 'rtTime.h', - 'rtAtomic.h', - 'rtm_discovery_api.h', - 'rtAdvisory.h') - -subdir('include-workaround-meson/rtmessage') - -librtMessage = library('rtMessage', - ['rtConnection.c', - 'rtCipher.c', - 'rtLog.c', - 'rtError.c', - 'rtMessageHeader.c', - 'rtEncoder.c', - 'rtMessage.c', - 'rtSocket.c', - 'rtVector.c', - 'rtList.c', - 'rtTime.c', - 'rtSemaphore.c', - 'rtRetainable.c', - 'rtBase64.c', - 'local_benchmarking.c'], - c_args: ['-D_GNU_SOURCE', '-D_POSIX_C_SOURCE=199309L'], - cpp_args: ['-D_GNU_SOURCE', '-D_POSIX_C_SOURCE=199309L'], - dependencies: [ libcjson_dep, thread_dep ], - install: true) - -librtMessage_dep = declare_dependency(include_directories: ['include-workaround-meson', - 'include-workaround-meson/rtmessage'], - link_with: librtMessage) - -if meson.version().version_compare('>=0.54.0') - meson.override_dependency('librtMessage', librtMessage_dep) -endif From 45e2935bb7107dfe2f263409ccbcccabc656ade5 Mon Sep 17 00:00:00 2001 From: Guru Chandru Date: Thu, 28 Oct 2021 19:06:49 +0530 Subject: [PATCH 12/35] Code changes for utility lib --- CMakeLists.txt | 42 +- src/CMakeLists.txt | 4 +- src/common.c | 53 -- src/common.h | 9 - src/webcfg_util.c | 538 +++++++++++++++++++++ src/webcfg_util.h | 72 +++ tests/CMakeLists.txt | 10 +- tests/{test_common.c => test_webcfgutil.c} | 6 +- 8 files changed, 646 insertions(+), 88 deletions(-) delete mode 100644 src/common.c delete mode 100644 src/common.h create mode 100644 src/webcfg_util.c create mode 100644 src/webcfg_util.h rename tests/{test_common.c => test_webcfgutil.c} (96%) diff --git a/CMakeLists.txt b/CMakeLists.txt index fd7bfe7..a9db680 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,24 +43,9 @@ include_directories(${INCLUDE_DIR} ${INCLUDE_DIR}/rbus ${INCLUDE_DIR}/rbus-core ${INCLUDE_DIR}/rtmessage - #${INCLUDE_DIR}/trower-base64 - #${INCLUDE_DIR}/wdmp-c - #${INCLUDE_DIR}/cimplog - #${INCLUDE_DIR}/wrp-c -# ${INCLUDE_DIR}/curl + ${INCLUDE_DIR}/wdmp-c + ${INCLUDE_DIR}/cimplog ) -#if (FEATURE_SUPPORT_AKER) -#include_directories(${INCLUDE_DIR}/nanomsg -# ${INCLUDE_DIR}/libparodus -#) -#endif (FEATURE_SUPPORT_AKER) - -#if (WEBCONFIG_BIN_SUPPORT) -#include_directories(${INCLUDE_DIR}/rbus -# ${INCLUDE_DIR}/rbus-core -# ${INCLUDE_DIR}/rtmessage -#) -#endif (WEBCONFIG_BIN_SUPPORT) if (NOT BUILD_YOCTO) @@ -78,6 +63,17 @@ ExternalProject_Add(msgpack add_library(libmsgpack STATIC SHARED IMPORTED) add_dependencies(libmsgpack msgpack) +# cimplog external dependency +#------------------------------------------------------------------------------- +ExternalProject_Add(cimplog + PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/cimplog + GIT_REPOSITORY https://github.com/Comcast/cimplog.git + GIT_TAG "1.0.2" + CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} +) +add_library(libcimplog STATIC SHARED IMPORTED) +add_dependencies(libcimplog cimplog) + # cJSON external dependency #------------------------------------------------------------------------------- ExternalProject_Add(cJSON @@ -89,6 +85,18 @@ ExternalProject_Add(cJSON add_library(libcJSON STATIC IMPORTED) add_dependencies(libcJSON cJSON) +# wdmp-c external dependency +#------------------------------------------------------------------------------- +ExternalProject_Add(wdmp-c + PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/wdmp-c + GIT_REPOSITORY https://github.com/Comcast/wdmp-c.git + GIT_TAG "796dddbcfa7686ec63536d950775e79b52ee5c3f" + CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} + -DBUILD_TESTING=OFF +) +add_library(libwdmp-c STATIC SHARED IMPORTED) +add_dependencies(libwdmp-c wdmp-c) + # rtMessage external dependency #------------------------------------------------------------------------------- ExternalProject_Add(rtMessage diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f70cd55..fa2450d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,8 +13,8 @@ # limitations under the License. set(PROJ_CPEABS cpeabs) -set(HEADERS common.h) -set(SOURCES common.c) +set(HEADERS webcfg_util.h) +set(SOURCES webcfg_util.c) #Support webcfg lib for backward compatibility add_library(${PROJ_CPEABS} STATIC ${HEADERS} ${SOURCES}) diff --git a/src/common.c b/src/common.c deleted file mode 100644 index 1d26bcb..0000000 --- a/src/common.c +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -/*----------------------------------------------------------------------------*/ -/* Macros */ -/*----------------------------------------------------------------------------*/ -/* none */ - -/*----------------------------------------------------------------------------*/ -/* Data Structures */ -/*----------------------------------------------------------------------------*/ -/* none */ - -/*----------------------------------------------------------------------------*/ -/* File Scoped Variables */ -/*----------------------------------------------------------------------------*/ -/* none */ - -/*----------------------------------------------------------------------------*/ -/* Function Prototypes */ -/*----------------------------------------------------------------------------*/ -void do_something(); -/*----------------------------------------------------------------------------*/ -/* Internal functions */ -/*----------------------------------------------------------------------------*/ -/* none */ - -/*----------------------------------------------------------------------------*/ -/* External Functions */ -/*----------------------------------------------------------------------------*/ -int cpeabs() -{ - /* req_struct *req = NULL; - req = (req_struct *) malloc (sizeof(req_struct)); - do_something();*/ - //wdmp_parse_generic_request("Hi", WDMP_TR181, &req); - rtMessageHeader* testrt = NULL; - testrt = (rtMessageHeader*)malloc(sizeof(rtMessageHeader)); - - rtMessageHeader_Init(testrt); - - do_something(); - return 0; -} - -void do_something() -{ - printf("I do something well.\n"); -} diff --git a/src/common.h b/src/common.h deleted file mode 100644 index ea6eedf..0000000 --- a/src/common.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef __CPEABS_H__ -#define __CPEABS_H__ - -#include -#include - -/* Don't do this ... you loose the portability you are after. */ - -#endif diff --git a/src/webcfg_util.c b/src/webcfg_util.c new file mode 100644 index 0000000..28b448a --- /dev/null +++ b/src/webcfg_util.c @@ -0,0 +1,538 @@ +/* + * Copyright 2021 Comcast Cable Communications Management, LLC + * + * 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. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "webcfg_util.h" +/*----------------------------------------------------------------------------*/ +/* Macros */ +/*----------------------------------------------------------------------------*/ +#define SERIAL_NUMBER "Device.DeviceInfo.SerialNumber" +#define FIRMWARE_VERSION "Device.DeviceInfo.X_CISCO_COM_FirmwareName" +#define DEVICE_BOOT_TIME "Device.DeviceInfo.X_RDKCENTRAL-COM_BootTime" +#define MODEL_NAME "Device.DeviceInfo.ModelName" +#define PRODUCT_CLASS "Device.DeviceInfo.ProductClass" +#define CONN_CLIENT_PARAM "Device.NotifyComponent.X_RDKCENTRAL-COM_Connected-Client" +#define LAST_REBOOT_REASON "Device.DeviceInfo.X_RDKCENTRAL-COM_LastRebootReason" +#define PARTNER_ID "Device.DeviceInfo.X_RDKCENTRAL-COM_Syndication.PartnerId" +#define ACCOUNT_ID "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.AccountInfo.AccountID" +#define FIRMW_START_TIME "Device.DeviceInfo.X_RDKCENTRAL-COM_MaintenanceWindow.FirmwareUpgradeStartTime" +#define FIRMW_END_TIME "Device.DeviceInfo.X_RDKCENTRAL-COM_MaintenanceWindow.FirmwareUpgradeEndTime" + +#if defined(_COSA_BCM_MIPS_) +#define DEVICE_MAC "Device.DPoE.Mac_address" +#elif defined(PLATFORM_RASPBERRYPI) +#define DEVICE_MAC "Device.Ethernet.Interface.5.MACAddress" +#elif defined(RDKB_EMU) +#define DEVICE_MAC "Device.DeviceInfo.X_COMCAST-COM_WAN_MAC" +#else +#define DEVICE_MAC "Device.X_CISCO_COM_CableModem.MACAddress" +#endif + +#define WEBCFG_URL_PARAM "Device.X_RDK_WebConfig.URL" +#define WEBCFG_PARAM_SUPPLEMENTARY_SERVICE "Device.X_RDK_WebConfig.SupplementaryServiceUrls." + +/*----------------------------------------------------------------------------*/ +/* Data Structures */ +/*----------------------------------------------------------------------------*/ +typedef struct +{ + char *paramName; + char *paramValue; + rbusValueType_t type; +} rbusParamVal_t; +/*----------------------------------------------------------------------------*/ +/* File Scoped Variables */ +/*----------------------------------------------------------------------------*/ +static bool isRbus = false ; +char deviceMAC[32]={'\0'}; +/*----------------------------------------------------------------------------*/ +/* Function Prototypes */ +/*----------------------------------------------------------------------------*/ +void __attribute__((weak)) getValues_rbus(const char *paramName[], const unsigned int paramCount, int index, money_trace_spans *timeSpan, param_t ***paramArr, int *retValCount, WDMP_STATUS *retStatus); +static bool isRbusEnabled(); +void macIDToLower(char macValue[],char macConverted[]); +void webStrncpy(char *destStr, const char *srcStr, size_t destSize); +/*----------------------------------------------------------------------------*/ +/* External Functions */ +/*----------------------------------------------------------------------------*/ +void webStrncpy(char *destStr, const char *srcStr, size_t destSize) +{ + strncpy(destStr, srcStr, destSize-1); + destStr[destSize-1] = '\0'; +} + +void macIDToLower(char macValue[],char macConverted[]) +{ + int i = 0; + int j; + char *token[32]; + char tmp[32]; + webStrncpy(tmp, macValue,sizeof(tmp)); + token[i] = strtok(tmp, ":"); + if(token[i]!=NULL) + { + strncpy(macConverted, token[i],31); + macConverted[31]='\0'; + i++; + } + while ((token[i] = strtok(NULL, ":")) != NULL) + { + strncat(macConverted, token[i],31); + macConverted[31]='\0'; + i++; + } + macConverted[31]='\0'; + for(j = 0; macConverted[j]; j++) + { + macConverted[j] = tolower(macConverted[j]); + } +} + +char* get_deviceMAC() +{ + if(strlen(deviceMAC) != 0) + { + WebcfgDebug("deviceMAC returned %s\n", deviceMAC); + return deviceMAC; + } + + char *macID = NULL; + char deviceMACValue[32] = { '\0' }; + macID = getParamValue(DEVICE_MAC); + if (macID != NULL) + { + strncpy(deviceMACValue, macID, strlen(macID)+1); + macIDToLower(deviceMACValue, deviceMAC); + WebcfgDebug("deviceMAC: %s\n",deviceMAC); + WEB_FREE(macID); + } + WebcfgDebug("deviceMAC returned from lib is %s\n", deviceMAC); + return deviceMAC; +} + +char * getSerialNumber() +{ + char *serialNum = NULL; + serialNum = getParamValue(SERIAL_NUMBER); + WebcfgDebug("serialNum returned from lib is %s\n", serialNum); + return serialNum; +} + +char * getDeviceBootTime() +{ + char *bootTime = NULL; + bootTime = getParamValue(DEVICE_BOOT_TIME); + WebcfgDebug("bootTime returned from lib is %s\n", bootTime); + return bootTime; +} + +char * getProductClass() +{ + char *productClass = NULL; + productClass = getParamValue(PRODUCT_CLASS); + WebcfgDebug("productClass returned from lib is %s\n", productClass); + return productClass; +} + +char * getModelName() +{ + char *modelName = NULL; + modelName = getParamValue(MODEL_NAME); + WebcfgDebug("modelName returned from lib is %s\n", modelName); + return modelName; +} + +char * getFirmwareVersion() +{ + char *firmware = NULL; + firmware = getParamValue(FIRMWARE_VERSION); + WebcfgDebug("firmware returned from lib is %s\n", firmware); + return firmware; +} + +char * getConnClientParamName() +{ + return CONN_CLIENT_PARAM; +} + +char * getRebootReason() +{ + char *reboot_reason = NULL; + reboot_reason = getParamValue(LAST_REBOOT_REASON); + WebcfgDebug("reboot_reason returned from lib is %s\n", reboot_reason); + return reboot_reason; +} + +char * getPartnerID() +{ + char *partnerId = NULL; + partnerId = getParamValue(PARTNER_ID); + WebcfgDebug("partnerId returned from lib is %s\n", partnerId); + return partnerId; +} + +char * getAccountID() +{ + char *accountId = NULL; + accountId = getParamValue(ACCOUNT_ID); + WebcfgDebug("accountId returned from lib is %s\n", accountId); + return accountId; +} + +char * getFirmwareUpgradeStartTime() +{ + char *FirmwareUpgradeStartTime = NULL; + FirmwareUpgradeStartTime = getParamValue(FIRMW_START_TIME); + WebcfgDebug("FirmwareUpgradeStartTime returned from lib is %s\n", FirmwareUpgradeStartTime); + return FirmwareUpgradeStartTime; +} + +char * getFirmwareUpgradeEndTime() +{ + char *FirmwareUpgradeEndTime = NULL; + FirmwareUpgradeEndTime = getParamValue(FIRMW_END_TIME); + WebcfgDebug("FirmwareUpgradeEndTime returned from lib is %s\n", FirmwareUpgradeEndTime); + return FirmwareUpgradeEndTime; +} + +bool isRbusEnabled() +{ + if(RBUS_ENABLED == rbus_checkStatus()) + { + isRbus = true; + } + else + { + isRbus = false; + } + WebcfgDebug("Webconfig util RBUS mode active status = %s\n", isRbus ? "true":"false"); + return isRbus; +} + +int Get_Webconfig_URL( char *pString) +{ + char *tempUrl = NULL; + int retPsmGet = 0; + if(isRbusEnabled()) + { + retPsmGet = rbus_GetValueFromDB( WEBCFG_URL_PARAM, &tempUrl); + WebcfgDebug("Get_Webconfig_URL. retPsmGet %d tempUrl %s\n", retPsmGet, tempUrl); + if (retPsmGet == RBUS_ERROR_SUCCESS) + { + if(tempUrl !=NULL) + { + strcpy(pString , tempUrl); + } + WebcfgDebug("Get_Webconfig_URL. pString %s\n", pString); + } + else + { + WebcfgError("psm_get failed ret %d for parameter %s\n", retPsmGet, WEBCFG_URL_PARAM); + } + } + WebcfgDebug("Get_Webconfig_URL strong fn from lib\n"); + return retPsmGet; +} + +int Set_Webconfig_URL( char *pString) +{ + int retPsmSet = 0; + if(isRbusEnabled()) + { + retPsmSet = rbus_StoreValueIntoDB( WEBCFG_URL_PARAM, pString ); + WebcfgDebug("Set_Webconfig_URL. retPsmSet %d pString %s\n", retPsmSet, pString); + + if (retPsmSet != RBUS_ERROR_SUCCESS) + { + WebcfgError("psm_set failed ret %d for parameter %s and value %s\n", retPsmSet, WEBCFG_URL_PARAM, pString); + return 0; + } + else + { + WebcfgDebug("psm_set success ret %d for parameter %s and value %s\n", retPsmSet, WEBCFG_URL_PARAM, pString); + } + } + return retPsmSet; +} + +int Get_Supplementary_URL( char *name, char *pString) +{ + char *tempUrl = NULL; + int retPsmGet = 0; + if(isRbusEnabled()) + { + char *tempParam = (char *) malloc (sizeof(char)*MAX_BUFF_SIZE); + if(tempParam !=NULL) + { + snprintf(tempParam, MAX_BUFF_SIZE, "%s%s", WEBCFG_PARAM_SUPPLEMENTARY_SERVICE, name); + WebcfgDebug("tempParam is %s\n", tempParam); + retPsmGet = rbus_GetValueFromDB( tempParam, &tempUrl); + if (retPsmGet == RBUS_ERROR_SUCCESS) + { + WebcfgDebug("Get_Supplementary_URL. retPsmGet %d tempUrl %s\n", retPsmGet, tempUrl); + if(tempUrl !=NULL) + { + strcpy(pString , tempUrl); + } + WebcfgDebug("Get_Supplementary_URL. pString %s\n", pString); + WEB_FREE(tempParam); + } + else + { + WebcfgError("psm_get failed ret %d for parameter %s\n", retPsmGet, tempParam); + WEB_FREE(tempParam); + } + } + } + return retPsmGet; +} + +int Set_Supplementary_URL( char *name, char *pString) +{ + int retPsmSet = 0; + if(isRbusEnabled()) + { + char *tempParam = (char *) malloc (sizeof(char)*MAX_BUFF_SIZE); + if(tempParam !=NULL) + { + if ((name != NULL) && (strncmp(name, "Telemetry",strlen(name)+1)) == 0) + { + snprintf(tempParam, MAX_BUFF_SIZE, "%s%s", WEBCFG_PARAM_SUPPLEMENTARY_SERVICE, name); + WebcfgDebug("tempParam is %s\n", tempParam); + retPsmSet = rbus_StoreValueIntoDB( tempParam, pString ); + if (retPsmSet != RBUS_ERROR_SUCCESS) + { + WebcfgError("psm_set failed ret %d for parameter %s%s and value %s\n", retPsmSet, WEBCFG_PARAM_SUPPLEMENTARY_SERVICE, name, pString); + WEB_FREE(tempParam); + return 0; + } + else + { + WebcfgDebug("psm_set success ret %d for parameter %s%s and value %s\n",retPsmSet, WEBCFG_PARAM_SUPPLEMENTARY_SERVICE, name, pString); + } + } + else + { + WebcfgError("Invalid supplementary doc name\n"); + } + WEB_FREE(tempParam); + } + } + return retPsmSet; +} + +char * getParamValue(char *paramName) +{ + if(isRbusEnabled()) + { + int paramCount=0; + WDMP_STATUS ret = WDMP_FAILURE; + int count=0; + const char *getParamList[1]; + getParamList[0] = paramName; + + char *paramValue = (char *) malloc(sizeof(char)*64); + paramCount = sizeof(getParamList)/sizeof(getParamList[0]); + param_t **parametervalArr = (param_t **) malloc(sizeof(param_t *) * paramCount); + + WebcfgDebug("paramName : %s paramCount %d\n",getParamList[0], paramCount); + getValues_rbus(getParamList, paramCount, 0, NULL, ¶metervalArr, &count, &ret); + + if (ret == WDMP_SUCCESS ) + { + strncpy(paramValue, parametervalArr[0]->value,64); + WEB_FREE(parametervalArr[0]->name); + WEB_FREE(parametervalArr[0]->value); + WEB_FREE(parametervalArr[0]); + } + else + { + WebcfgError("Failed to GetValue for %s\n", getParamList[0]); + WEB_FREE(paramValue); + } + WEB_FREE(parametervalArr); + WebcfgDebug("getParamValue : paramValue is %s\n", paramValue); + return paramValue; + } + WebcfgError("getParamValue : returns NULL\n"); + return NULL; +} + +/** + * To persist TR181 parameter values in PSM DB. + */ +int rbus_StoreValueIntoDB(char *paramName, char *value) +{ + char recordName[ 256] = {'\0'}; + char psmName[256] = {'\0'}; + rbusParamVal_t val[1]; + bool commit = 1; + rbusError_t errorcode = RBUS_ERROR_INVALID_INPUT; + rbus_error_t err = RTMESSAGE_BUS_SUCCESS; + + strcpy(recordName, paramName); + WebcfgDebug("rbus_StoreValueIntoDB recordName is %s\n", recordName); + + val[0].paramName = recordName; + val[0].paramValue = value; + val[0].type = 0; + + sprintf(psmName, "%s%s", "eRT.", DEST_COMP_ID_PSM); + WebcfgDebug("rbus_StoreValueIntoDB psmName is %s\n", psmName); + + rbusMessage request, response; + + rbusMessage_Init(&request); + rbusMessage_SetInt32(request, 0); //sessionId + rbusMessage_SetString(request, "webconfig"); //component name that invokes the set + rbusMessage_SetInt32(request, (int32_t)1); //size of params + + rbusMessage_SetString(request, val[0].paramName); //param details + rbusMessage_SetInt32(request, val[0].type); + rbusMessage_SetString(request, val[0].paramValue); + rbusMessage_SetString(request, commit ? "1" : "0"); + + + if((err = rbus_invokeRemoteMethod(psmName, METHOD_SETPARAMETERVALUES, request, 6000, &response)) != RTMESSAGE_BUS_SUCCESS) + { + WebcfgError("rbus_invokeRemoteMethod failed with err %d", err); + errorcode = RBUS_ERROR_BUS_ERROR; + } + else + { + int ret = -1; + char const* pErrorReason = NULL; + rbusMessage_GetInt32(response, &ret); + + WebcfgDebug("Response from the remote method is [%d]!", ret); + errorcode = (rbusError_t) ret; + + if((errorcode == RBUS_ERROR_SUCCESS) || (errorcode == 100)) //legacy error codes returned from component PSM. + { + errorcode = RBUS_ERROR_SUCCESS; + WebcfgDebug("Successfully Set the Value"); + } + else + { + rbusMessage_GetString(response, &pErrorReason); + WebcfgError("Failed to Set the Value for %s", pErrorReason); + } + + rbusMessage_Release(response); + } + + return errorcode; +} + +/** + * To fetch TR181 parameter values from PSM DB. + */ +int rbus_GetValueFromDB( char* paramName, char** paramValue) +{ + char recordName[ 256] = {'\0'}; + char psmName[256] = {'\0'}; + char * parameterNames[1] = {NULL}; + int32_t type = 0; + rbusError_t errorcode = RBUS_ERROR_INVALID_INPUT; + rbus_error_t err = RTMESSAGE_BUS_SUCCESS; + *paramValue = NULL; + + strcpy(recordName, paramName); + WebcfgDebug("rbus_GetValueFromDB recordName is %s\n", recordName); + + parameterNames[0] = (char*)recordName; + + sprintf(psmName, "%s%s", "eRT.", DEST_COMP_ID_PSM); + WebcfgDebug("rbus_GetValueFromDB psmName is %s\n", psmName); + + rbusMessage request, response; + + rbusMessage_Init(&request); + rbusMessage_SetString(request, psmName); //component name that invokes the get + rbusMessage_SetInt32(request, (int32_t)1); //size of params + + rbusMessage_SetString(request, parameterNames[0]); //param details + + if((err = rbus_invokeRemoteMethod(psmName, METHOD_GETPARAMETERVALUES, request, 6000, &response)) != RTMESSAGE_BUS_SUCCESS) + { + WebcfgError("rbus_invokeRemoteMethod GET failed with err %d\n", err); + errorcode = RBUS_ERROR_BUS_ERROR; + } + else + { + int valSize=0; + int ret = -1; + rbusMessage_GetInt32(response, &ret); + WebcfgDebug("Response from the remote method is [%d]!\n",ret); + errorcode = (rbusError_t) ret; + + if((errorcode == RBUS_ERROR_SUCCESS) || (errorcode == 100)) //legacy error code from component. + { + WebcfgDebug("Successfully Get the Value\n"); + errorcode = RBUS_ERROR_SUCCESS; + rbusMessage_GetInt32(response, &valSize); + if(1/*valSize*/) + { + char const *buff = NULL; + rbusMessage_GetString(response, &buff); + WebcfgDebug("Requested param buff [%s]\n", buff); + if(buff && (strcmp(recordName, buff) == 0)) + { + rbusMessage_GetInt32(response, &type); + WebcfgDebug("Requested param type [%d]\n", type); + buff = NULL; + rbusMessage_GetString(response, &buff); + *paramValue = strdup(buff); //free buff + WebcfgDebug("Requested param DB value [%s]\n", *paramValue); + } + else + { + WebcfgError("Rbus error. Requested param: [%s], Received Param: [%s]\n", recordName, buff); + errorcode = RBUS_ERROR_BUS_ERROR; + } + } + } + else + { + WebcfgError("Response from remote Get method failed!!\n"); + errorcode = RBUS_ERROR_BUS_ERROR; + } + + rbusMessage_Release(response); + } + return errorcode; +} + +void getValues_rbus(const char *paramName[], const unsigned int paramCount, int index, money_trace_spans *timeSpan, param_t ***paramArr, int *retValCount, WDMP_STATUS *retStatus) +{ + UNUSED(paramName); + UNUSED(paramCount); + UNUSED(index); + UNUSED(timeSpan); + UNUSED(paramArr); + UNUSED(retValCount); + UNUSED(retStatus); + return; +} + diff --git a/src/webcfg_util.h b/src/webcfg_util.h new file mode 100644 index 0000000..0a0d0b2 --- /dev/null +++ b/src/webcfg_util.h @@ -0,0 +1,72 @@ +/* + * Copyright 2021 Comcast Cable Communications Management, LLC + * + * 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. + */ +#ifndef __WEBCFGUTIL_H__ +#define __WEBCFGUTIL_H__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +/*----------------------------------------------------------------------------*/ +/* Macros */ +/*----------------------------------------------------------------------------*/ +#define DEST_COMP_ID_PSM "com.cisco.spvtg.ccsp.psm" +#define WEB_FREE(__x__) if(__x__ != NULL) { free((void*)(__x__)); __x__ = NULL;} else {printf("Trying to free null pointer\n");} +#define UNUSED(x) (void )(x) +#define MAX_BUFF_SIZE 256 + +/** + * @brief Enables or disables debug logs. + */ +#ifdef WEBCONFIG_BIN_SUPPORT + +#define WEBCFG_LOG_MODULE "WEBCONFIG" +#define WEBCFG_RDK_LOG_MODULE "LOG.RDK.WEBCONFIG" + +#define WebConfigLog(...) __cimplog_rdk_generic(WEBCFG_RDK_LOG_MODULE, WEBCFG_LOG_MODULE, LEVEL_INFO, __VA_ARGS__) + +#define WebcfgError(...) __cimplog_rdk_generic(WEBCFG_RDK_LOG_MODULE, WEBCFG_LOG_MODULE, LEVEL_ERROR, __VA_ARGS__) +#define WebcfgInfo(...) __cimplog_rdk_generic(WEBCFG_RDK_LOG_MODULE, WEBCFG_LOG_MODULE, LEVEL_INFO, __VA_ARGS__) +#define WebcfgDebug(...) __cimplog_rdk_generic(WEBCFG_RDK_LOG_MODULE, WEBCFG_LOG_MODULE, LEVEL_DEBUG, __VA_ARGS__) +#else +#define WebConfigLog(...) printf(__VA_ARGS__) + +#define WebcfgError(...) printf(__VA_ARGS__) +#define WebcfgInfo(...) printf(__VA_ARGS__) +#define WebcfgDebug(...) printf(__VA_ARGS__) + +#endif +/*----------------------------------------------------------------------------*/ +/* Data Structures */ +/*----------------------------------------------------------------------------*/ + + +/*----------------------------------------------------------------------------*/ +/* External Functions */ +/*----------------------------------------------------------------------------*/ + +char * getParamValue(char *paramName); +void getValues_rbus(const char *paramName[], const unsigned int paramCount, int index, money_trace_spans *timeSpan, param_t ***paramArr, int *retValCount, WDMP_STATUS *retStatus); +int rbus_GetValueFromDB( char* paramName, char** paramValue); +int rbus_StoreValueIntoDB(char *paramName, char *value); + +#endif + diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d7da11c..3e3bcb7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -25,15 +25,15 @@ link_directories ( ${LIBRARY_DIR} ) #------------------------------------------------------------------------------- # test_common #------------------------------------------------------------------------------- -add_test(NAME test_common COMMAND ${MEMORY_CHECK} ./test_common) +add_test(NAME test_webcfgutil COMMAND ${MEMORY_CHECK} ./test_webcfgutil) -set(SOURCES test_common.c ../src/common.c ) +set(SOURCES test_webcfgutil.c ../src/webcfg_util.c ) -add_executable(test_common ${SOURCES}) +add_executable(test_webcfgutil ${SOURCES}) -target_link_libraries (test_common -lcunit -lmsgpackc -lpthread -lrbus -lrbus-core -lrtMessage) +target_link_libraries (test_webcfgutil -lcjson -lcunit -lmsgpackc -lwdmp-c -lcimplog -lpthread -lrbus -lrbus-core) -target_link_libraries (test_common gcov -Wl,--no-as-needed ) +target_link_libraries (test_webcfgutil gcov -Wl,--no-as-needed ) # Code coverage diff --git a/tests/test_common.c b/tests/test_webcfgutil.c similarity index 96% rename from tests/test_common.c rename to tests/test_webcfgutil.c index e0cc801..6a2da27 100644 --- a/tests/test_common.c +++ b/tests/test_webcfgutil.c @@ -18,6 +18,7 @@ #include #include #include +#include "../src/webcfg_util.h" /*----------------------------------------------------------------------------*/ /* Macros */ @@ -37,14 +38,15 @@ /*----------------------------------------------------------------------------*/ /* Function Prototypes */ /*----------------------------------------------------------------------------*/ -extern void do_something(); +/* none */ /*----------------------------------------------------------------------------*/ /* Tests */ /*----------------------------------------------------------------------------*/ void test_do_something() { - do_something(); + char * name = getParamValue("test"); + printf("Name is %s\n", name); } From baf1c8e4cf1c4c1febaba550b79881abf64ab45b Mon Sep 17 00:00:00 2001 From: Guru Chandru Date: Tue, 2 Nov 2021 12:20:33 +0530 Subject: [PATCH 13/35] Debug logs --- src/webcfg_util.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/webcfg_util.c b/src/webcfg_util.c index 28b448a..cd5f129 100644 --- a/src/webcfg_util.c +++ b/src/webcfg_util.c @@ -127,6 +127,7 @@ char* get_deviceMAC() WebcfgDebug("deviceMAC: %s\n",deviceMAC); WEB_FREE(macID); } + WebcfgInfo("Inside cpeabs lib file\n"); WebcfgDebug("deviceMAC returned from lib is %s\n", deviceMAC); return deviceMAC; } @@ -244,6 +245,7 @@ int Get_Webconfig_URL( char *pString) { strcpy(pString , tempUrl); } + WebcfgInfo("Inside cpeabs lib file\n"); WebcfgDebug("Get_Webconfig_URL. pString %s\n", pString); } else @@ -270,6 +272,7 @@ int Set_Webconfig_URL( char *pString) } else { + WebcfgInfo("Inside cpeabs lib file\n"); WebcfgDebug("psm_set success ret %d for parameter %s and value %s\n", retPsmSet, WEBCFG_URL_PARAM, pString); } } @@ -290,6 +293,7 @@ int Get_Supplementary_URL( char *name, char *pString) retPsmGet = rbus_GetValueFromDB( tempParam, &tempUrl); if (retPsmGet == RBUS_ERROR_SUCCESS) { + WebcfgInfo("Inside cpeabs lib file\n"); WebcfgDebug("Get_Supplementary_URL. retPsmGet %d tempUrl %s\n", retPsmGet, tempUrl); if(tempUrl !=NULL) { @@ -329,6 +333,7 @@ int Set_Supplementary_URL( char *name, char *pString) } else { + WebcfgInfo("Inside cpeabs lib file\n"); WebcfgDebug("psm_set success ret %d for parameter %s%s and value %s\n",retPsmSet, WEBCFG_PARAM_SUPPLEMENTARY_SERVICE, name, pString); } } From 779a573a2d6f9808a6bd59eed3380ccf129e9c55 Mon Sep 17 00:00:00 2001 From: Guru Chandru Date: Tue, 2 Nov 2021 19:21:23 +0530 Subject: [PATCH 14/35] Refactored code --- CMakeLists.txt | 5 ++ src/webcfg_util.h => include/cpeabs.h | 20 +++++- src/CMakeLists.txt | 18 ++++- src/pods/impl.c | 45 +++++++++++++ src/{webcfg_util.c => rdkb/impl.c} | 2 +- tests/CMakeLists.txt | 38 +++++++++-- tests/test_pods.c | 86 ++++++++++++++++++++++++ tests/{test_webcfgutil.c => test_rdkb.c} | 2 +- 8 files changed, 203 insertions(+), 13 deletions(-) rename src/webcfg_util.h => include/cpeabs.h (93%) create mode 100644 src/pods/impl.c rename src/{webcfg_util.c => rdkb/impl.c} (99%) create mode 100644 tests/test_pods.c rename tests/{test_webcfgutil.c => test_rdkb.c} (98%) diff --git a/CMakeLists.txt b/CMakeLists.txt index a9db680..f487ea3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,8 @@ set(COMMON_LIBRARY_DIR ${INSTALL_DIR}/lib/${CMAKE_LIBRARY_ARCHITECTURE}) set(TEST_RESULTS_DIR ${CMAKE_CURRENT_BINARY_DIR}/test_results) file(MAKE_DIRECTORY ${TEST_RESULTS_DIR}) +if (WEBCONFIG_BIN_SUPPORT) + include_directories(${INCLUDE_DIR} ${INCLUDE_DIR}/cjson ${INCLUDE_DIR}/msgpack @@ -139,6 +141,9 @@ add_library(librbus STATIC SHARED IMPORTED) add_dependencies(librbus rbus) endif () + +endif (WEBCONFIG_BIN_SUPPORT) + link_directories ( ${LIBRARY_DIR} ${COMMON_LIBRARY_DIR} ${LIBRARY_DIR64} ) add_subdirectory(src) diff --git a/src/webcfg_util.h b/include/cpeabs.h similarity index 93% rename from src/webcfg_util.h rename to include/cpeabs.h index 0a0d0b2..8617bf0 100644 --- a/src/webcfg_util.h +++ b/include/cpeabs.h @@ -13,10 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __WEBCFGUTIL_H__ -#define __WEBCFGUTIL_H__ +#ifndef __CPEABS_H__ +#define __CPEABS_H__ #include + +#ifdef WEBCONFIG_BIN_SUPPORT + #include #include #include @@ -25,18 +28,25 @@ #include #include #include + +#endif /*----------------------------------------------------------------------------*/ /* Macros */ /*----------------------------------------------------------------------------*/ + +#ifdef WEBCONFIG_BIN_SUPPORT + #define DEST_COMP_ID_PSM "com.cisco.spvtg.ccsp.psm" #define WEB_FREE(__x__) if(__x__ != NULL) { free((void*)(__x__)); __x__ = NULL;} else {printf("Trying to free null pointer\n");} #define UNUSED(x) (void )(x) #define MAX_BUFF_SIZE 256 +#endif + /** * @brief Enables or disables debug logs. */ -#ifdef WEBCONFIG_BIN_SUPPORT +#if defined WEBCONFIG_BIN_SUPPORT && defined BUILD_YOCTO #define WEBCFG_LOG_MODULE "WEBCONFIG" #define WEBCFG_RDK_LOG_MODULE "LOG.RDK.WEBCONFIG" @@ -63,10 +73,14 @@ /* External Functions */ /*----------------------------------------------------------------------------*/ +#ifdef WEBCONFIG_BIN_SUPPORT char * getParamValue(char *paramName); void getValues_rbus(const char *paramName[], const unsigned int paramCount, int index, money_trace_spans *timeSpan, param_t ***paramArr, int *retValCount, WDMP_STATUS *retStatus); int rbus_GetValueFromDB( char* paramName, char** paramValue); int rbus_StoreValueIntoDB(char *paramName, char *value); +#else +void do_something(); +#endif #endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fa2450d..503cf3e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,8 +13,22 @@ # limitations under the License. set(PROJ_CPEABS cpeabs) -set(HEADERS webcfg_util.h) -set(SOURCES webcfg_util.c) + +if (BUILD_YOCTO) +add_definitions(-DBUILD_YOCTO) +endif (BUILD_YOCTO) + +if (WEBCONFIG_BIN_SUPPORT) +add_definitions(-DWEBCONFIG_BIN_SUPPORT) +endif (WEBCONFIG_BIN_SUPPORT) + +set(HEADERS ../include/cpeabs.h) + +if (WEBCONFIG_BIN_SUPPORT) +set(SOURCES rdkb/impl.c) +else() +set(SOURCES pods/impl.c) +endif (WEBCONFIG_BIN_SUPPORT) #Support webcfg lib for backward compatibility add_library(${PROJ_CPEABS} STATIC ${HEADERS} ${SOURCES}) diff --git a/src/pods/impl.c b/src/pods/impl.c new file mode 100644 index 0000000..721fbaf --- /dev/null +++ b/src/pods/impl.c @@ -0,0 +1,45 @@ +/* + * Copyright 2021 Comcast Cable Communications Management, LLC + * + * 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. + */ +#include +#include +#include +#include +#include +#include "../../include/cpeabs.h" +/*----------------------------------------------------------------------------*/ +/* Macros */ +/*----------------------------------------------------------------------------*/ +/*none*/ +/*----------------------------------------------------------------------------*/ +/* Data Structures */ +/*----------------------------------------------------------------------------*/ +/*none*/ +/*----------------------------------------------------------------------------*/ +/* File Scoped Variables */ +/*----------------------------------------------------------------------------*/ +/*none*/ +/*----------------------------------------------------------------------------*/ +/* Function Prototypes */ +/*----------------------------------------------------------------------------*/ +/*none*/ +/*----------------------------------------------------------------------------*/ +/* External Functions */ +/*----------------------------------------------------------------------------*/ +void do_something() +{ + printf("It did something"); +} + diff --git a/src/webcfg_util.c b/src/rdkb/impl.c similarity index 99% rename from src/webcfg_util.c rename to src/rdkb/impl.c index cd5f129..592c0d8 100644 --- a/src/webcfg_util.c +++ b/src/rdkb/impl.c @@ -23,7 +23,7 @@ #include #include #include -#include "webcfg_util.h" +#include "../../include/cpeabs.h" /*----------------------------------------------------------------------------*/ /* Macros */ /*----------------------------------------------------------------------------*/ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3e3bcb7..f331a9e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -22,19 +22,45 @@ set (MEMORY_CHECK valgrind --leak-check=full --show-reachable=yes --track-origin endif () link_directories ( ${LIBRARY_DIR} ) + +if (BUILD_YOCTO) +add_definitions(-DBUILD_YOCTO) +endif (BUILD_YOCTO) + +if (WEBCONFIG_BIN_SUPPORT) +add_definitions(-DWEBCONFIG_BIN_SUPPORT) +endif (WEBCONFIG_BIN_SUPPORT) + +if(WEBCONFIG_BIN_SUPPORT) +#------------------------------------------------------------------------------- +# test_rdkb +#------------------------------------------------------------------------------- +add_test(NAME test_rdkb COMMAND ${MEMORY_CHECK} ./test_rdkb) + +set(SOURCES test_rdkb.c ../src/rdkb/impl.c ) + +add_executable(test_rdkb ${SOURCES}) + +target_link_libraries (test_rdkb -lcjson -lcunit -lmsgpackc -lwdmp-c -lcimplog -lpthread -lrbus -lrbus-core) + +target_link_libraries (test_rdkb gcov -Wl,--no-as-needed ) + +else() + #------------------------------------------------------------------------------- -# test_common +# test_pods #------------------------------------------------------------------------------- -add_test(NAME test_webcfgutil COMMAND ${MEMORY_CHECK} ./test_webcfgutil) +add_test(NAME test_pods COMMAND ${MEMORY_CHECK} ./test_pods) -set(SOURCES test_webcfgutil.c ../src/webcfg_util.c ) +set(SOURCES test_pods.c ../src/pods/impl.c ) -add_executable(test_webcfgutil ${SOURCES}) +add_executable(test_pods ${SOURCES}) -target_link_libraries (test_webcfgutil -lcjson -lcunit -lmsgpackc -lwdmp-c -lcimplog -lpthread -lrbus -lrbus-core) +target_link_libraries (test_pods -lcunit) -target_link_libraries (test_webcfgutil gcov -Wl,--no-as-needed ) +target_link_libraries (test_pods gcov -Wl,--no-as-needed ) +endif(WEBCONFIG_BIN_SUPPORT) # Code coverage diff --git a/tests/test_pods.c b/tests/test_pods.c new file mode 100644 index 0000000..d289dea --- /dev/null +++ b/tests/test_pods.c @@ -0,0 +1,86 @@ + /** + * Copyright 2019 Comcast Cable Communications Management, LLC + * + * 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. + * + */ +#include +#include +#include +#include +#include "../include/cpeabs.h" + +/*----------------------------------------------------------------------------*/ +/* Macros */ +/*----------------------------------------------------------------------------*/ +/* none */ + +/*----------------------------------------------------------------------------*/ +/* Data Structures */ +/*----------------------------------------------------------------------------*/ +/* none */ + +/*----------------------------------------------------------------------------*/ +/* File Scoped Variables */ +/*----------------------------------------------------------------------------*/ +/* none */ + +/*----------------------------------------------------------------------------*/ +/* Function Prototypes */ +/*----------------------------------------------------------------------------*/ +/* none */ + +/*----------------------------------------------------------------------------*/ +/* Tests */ +/*----------------------------------------------------------------------------*/ +void test_do_something() +{ + do_something(); +} + + +/*----------------------------------------------------------------------------*/ +/* Testing Framework */ +/*----------------------------------------------------------------------------*/ + +void add_suites(CU_pSuite *suite) +{ + *suite = CU_add_suite("common encoding tests", NULL, NULL); + CU_add_test(*suite, "Test do_something", test_do_something); +} + +int main(void) +{ + unsigned rv = 1; + CU_pSuite suite = NULL; + + if (CUE_SUCCESS == CU_initialize_registry()) { + add_suites(&suite); + + if (NULL != suite) { + CU_basic_set_mode(CU_BRM_VERBOSE); + CU_basic_run_tests(); + printf("\n"); + CU_basic_show_failures(CU_get_failure_list()); + printf("\n\n"); + rv = CU_get_number_of_tests_failed(); + } + + CU_cleanup_registry(); + } + + if (0 != rv) { + return 1; + } + return 0; +} diff --git a/tests/test_webcfgutil.c b/tests/test_rdkb.c similarity index 98% rename from tests/test_webcfgutil.c rename to tests/test_rdkb.c index 6a2da27..3158f4d 100644 --- a/tests/test_webcfgutil.c +++ b/tests/test_rdkb.c @@ -18,7 +18,7 @@ #include #include #include -#include "../src/webcfg_util.h" +#include "../include/cpeabs.h" /*----------------------------------------------------------------------------*/ /* Macros */ From 39e30dd420194589ddc6f7c541c5158fe6dac3f0 Mon Sep 17 00:00:00 2001 From: Guru Chandru Date: Tue, 9 Nov 2021 13:03:35 +0530 Subject: [PATCH 15/35] Review comment changes with debug logs --- CMakeLists.txt | 10 ++--- include/cpeabs.h | 21 ++--------- src/CMakeLists.txt | 20 ++++++---- src/pc/impl.c | 83 ++++++++++++++++++++++++++++++++++++++++++ src/pods/impl.c | 54 +++++++++++++++++++++++---- src/rdkb/impl.c | 29 ++++++++------- tests/CMakeLists.txt | 31 +++++++++++++--- tests/test_pc.c | 87 ++++++++++++++++++++++++++++++++++++++++++++ tests/test_pods.c | 7 ++-- tests/test_rdkb.c | 4 +- 10 files changed, 283 insertions(+), 63 deletions(-) create mode 100644 src/pc/impl.c create mode 100644 tests/test_pc.c diff --git a/CMakeLists.txt b/CMakeLists.txt index f487ea3..7367005 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright 2020 +# Copyright 2021 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -37,8 +37,6 @@ set(COMMON_LIBRARY_DIR ${INSTALL_DIR}/lib/${CMAKE_LIBRARY_ARCHITECTURE}) set(TEST_RESULTS_DIR ${CMAKE_CURRENT_BINARY_DIR}/test_results) file(MAKE_DIRECTORY ${TEST_RESULTS_DIR}) -if (WEBCONFIG_BIN_SUPPORT) - include_directories(${INCLUDE_DIR} ${INCLUDE_DIR}/cjson ${INCLUDE_DIR}/msgpack @@ -49,6 +47,10 @@ include_directories(${INCLUDE_DIR} ${INCLUDE_DIR}/cimplog ) +include_directories( + include/ + ) + if (NOT BUILD_YOCTO) # msgpack-c external dependency @@ -142,8 +144,6 @@ add_dependencies(librbus rbus) endif () -endif (WEBCONFIG_BIN_SUPPORT) - link_directories ( ${LIBRARY_DIR} ${COMMON_LIBRARY_DIR} ${LIBRARY_DIR64} ) add_subdirectory(src) diff --git a/include/cpeabs.h b/include/cpeabs.h index 8617bf0..850011b 100644 --- a/include/cpeabs.h +++ b/include/cpeabs.h @@ -17,9 +17,6 @@ #define __CPEABS_H__ #include - -#ifdef WEBCONFIG_BIN_SUPPORT - #include #include #include @@ -29,24 +26,17 @@ #include #include -#endif /*----------------------------------------------------------------------------*/ /* Macros */ /*----------------------------------------------------------------------------*/ - -#ifdef WEBCONFIG_BIN_SUPPORT - -#define DEST_COMP_ID_PSM "com.cisco.spvtg.ccsp.psm" -#define WEB_FREE(__x__) if(__x__ != NULL) { free((void*)(__x__)); __x__ = NULL;} else {printf("Trying to free null pointer\n");} +#define CPEABS_FREE(__x__) if(__x__ != NULL) { free((void*)(__x__)); __x__ = NULL;} else {printf("Trying to free null pointer\n");} #define UNUSED(x) (void )(x) #define MAX_BUFF_SIZE 256 -#endif - /** * @brief Enables or disables debug logs. */ -#if defined WEBCONFIG_BIN_SUPPORT && defined BUILD_YOCTO +#if defined DEVICE_GATEWAY && defined BUILD_YOCTO #define WEBCFG_LOG_MODULE "WEBCONFIG" #define WEBCFG_RDK_LOG_MODULE "LOG.RDK.WEBCONFIG" @@ -67,20 +57,15 @@ /*----------------------------------------------------------------------------*/ /* Data Structures */ /*----------------------------------------------------------------------------*/ - - +/* none */ /*----------------------------------------------------------------------------*/ /* External Functions */ /*----------------------------------------------------------------------------*/ -#ifdef WEBCONFIG_BIN_SUPPORT char * getParamValue(char *paramName); void getValues_rbus(const char *paramName[], const unsigned int paramCount, int index, money_trace_spans *timeSpan, param_t ***paramArr, int *retValCount, WDMP_STATUS *retStatus); int rbus_GetValueFromDB( char* paramName, char** paramValue); int rbus_StoreValueIntoDB(char *paramName, char *value); -#else -void do_something(); -#endif #endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 503cf3e..03a4ace 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,19 +18,25 @@ if (BUILD_YOCTO) add_definitions(-DBUILD_YOCTO) endif (BUILD_YOCTO) -if (WEBCONFIG_BIN_SUPPORT) -add_definitions(-DWEBCONFIG_BIN_SUPPORT) -endif (WEBCONFIG_BIN_SUPPORT) +#if (PLATFORM STREQUAL "DEVICE_GATEWAY") +if (DEVICE_GATEWAY) +add_definitions(-DDEVICE_GATEWAY) +#elseif (PLATFORM STREQUAL "DEVICE_EXTENDER") +elseif (DEVICE_EXTENDER) +add_definitions(-DDEVICE_EXTENDER) +endif () set(HEADERS ../include/cpeabs.h) -if (WEBCONFIG_BIN_SUPPORT) +if (DEVICE_GATEWAY) set(SOURCES rdkb/impl.c) -else() +elseif (DEVICE_EXTENDER) set(SOURCES pods/impl.c) -endif (WEBCONFIG_BIN_SUPPORT) +else () +set(SOURCES pc/impl.c) +endif () -#Support webcfg lib for backward compatibility +#Support cpeabs lib for backward compatibility add_library(${PROJ_CPEABS} STATIC ${HEADERS} ${SOURCES}) add_library(${PROJ_CPEABS}.shared SHARED ${HEADERS} ${SOURCES}) set_target_properties(${PROJ_CPEABS}.shared PROPERTIES OUTPUT_NAME ${PROJ_CPEABS}) diff --git a/src/pc/impl.c b/src/pc/impl.c new file mode 100644 index 0000000..13ea633 --- /dev/null +++ b/src/pc/impl.c @@ -0,0 +1,83 @@ +/* + * Copyright 2021 Comcast Cable Communications Management, LLC + * + * 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. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "cpeabs.h" +/*----------------------------------------------------------------------------*/ +/* Macros */ +/*----------------------------------------------------------------------------*/ +/* none */ +/*----------------------------------------------------------------------------*/ +/* Data Structures */ +/*----------------------------------------------------------------------------*/ +/* none */ +/*----------------------------------------------------------------------------*/ +/* File Scoped Variables */ +/*----------------------------------------------------------------------------*/ +/* none */ +/*----------------------------------------------------------------------------*/ +/* Function Prototypes */ +/*----------------------------------------------------------------------------*/ +/* none */ +/*----------------------------------------------------------------------------*/ +/* External Functions */ +/*----------------------------------------------------------------------------*/ +char * getParamValue(char *paramName) +{ + UNUSED(paramName); + return "NULL"; +} + +/** + * To persist TR181 parameter values in DB. + */ +int rbus_StoreValueIntoDB(char *paramName, char *value) +{ + UNUSED(paramName); + UNUSED(value); + return 1; +} + +/** + * To fetch TR181 parameter values from DB. + */ +int rbus_GetValueFromDB( char* paramName, char** paramValue) +{ + UNUSED(paramName); + UNUSED(paramValue); + return 1; +} + +void getValues_rbus(const char *paramName[], const unsigned int paramCount, int index, money_trace_spans *timeSpan, param_t ***paramArr, int *retValCount, WDMP_STATUS *retStatus) +{ + UNUSED(paramName); + UNUSED(paramCount); + UNUSED(index); + UNUSED(timeSpan); + UNUSED(paramArr); + UNUSED(retValCount); + UNUSED(retStatus); + return; +} + diff --git a/src/pods/impl.c b/src/pods/impl.c index 721fbaf..13ea633 100644 --- a/src/pods/impl.c +++ b/src/pods/impl.c @@ -14,32 +14,70 @@ * limitations under the License. */ #include -#include #include #include #include -#include "../../include/cpeabs.h" +#include +#include +#include +#include +#include +#include +#include "cpeabs.h" /*----------------------------------------------------------------------------*/ /* Macros */ /*----------------------------------------------------------------------------*/ -/*none*/ +/* none */ /*----------------------------------------------------------------------------*/ /* Data Structures */ /*----------------------------------------------------------------------------*/ -/*none*/ +/* none */ /*----------------------------------------------------------------------------*/ /* File Scoped Variables */ /*----------------------------------------------------------------------------*/ -/*none*/ +/* none */ /*----------------------------------------------------------------------------*/ /* Function Prototypes */ /*----------------------------------------------------------------------------*/ -/*none*/ +/* none */ /*----------------------------------------------------------------------------*/ /* External Functions */ /*----------------------------------------------------------------------------*/ -void do_something() +char * getParamValue(char *paramName) { - printf("It did something"); + UNUSED(paramName); + return "NULL"; +} + +/** + * To persist TR181 parameter values in DB. + */ +int rbus_StoreValueIntoDB(char *paramName, char *value) +{ + UNUSED(paramName); + UNUSED(value); + return 1; +} + +/** + * To fetch TR181 parameter values from DB. + */ +int rbus_GetValueFromDB( char* paramName, char** paramValue) +{ + UNUSED(paramName); + UNUSED(paramValue); + return 1; +} + +void getValues_rbus(const char *paramName[], const unsigned int paramCount, int index, money_trace_spans *timeSpan, param_t ***paramArr, int *retValCount, WDMP_STATUS *retStatus) +{ + UNUSED(paramName); + UNUSED(paramCount); + UNUSED(index); + UNUSED(timeSpan); + UNUSED(paramArr); + UNUSED(retValCount); + UNUSED(retStatus); + return; } diff --git a/src/rdkb/impl.c b/src/rdkb/impl.c index 592c0d8..934a418 100644 --- a/src/rdkb/impl.c +++ b/src/rdkb/impl.c @@ -23,10 +23,11 @@ #include #include #include -#include "../../include/cpeabs.h" +#include "cpeabs.h" /*----------------------------------------------------------------------------*/ /* Macros */ /*----------------------------------------------------------------------------*/ +#define DEST_COMP_ID_PSM "com.cisco.spvtg.ccsp.psm" #define SERIAL_NUMBER "Device.DeviceInfo.SerialNumber" #define FIRMWARE_VERSION "Device.DeviceInfo.X_CISCO_COM_FirmwareName" #define DEVICE_BOOT_TIME "Device.DeviceInfo.X_RDKCENTRAL-COM_BootTime" @@ -72,11 +73,11 @@ char deviceMAC[32]={'\0'}; void __attribute__((weak)) getValues_rbus(const char *paramName[], const unsigned int paramCount, int index, money_trace_spans *timeSpan, param_t ***paramArr, int *retValCount, WDMP_STATUS *retStatus); static bool isRbusEnabled(); void macIDToLower(char macValue[],char macConverted[]); -void webStrncpy(char *destStr, const char *srcStr, size_t destSize); +void cpeabStrncpy(char *destStr, const char *srcStr, size_t destSize); /*----------------------------------------------------------------------------*/ /* External Functions */ /*----------------------------------------------------------------------------*/ -void webStrncpy(char *destStr, const char *srcStr, size_t destSize) +void cpeabStrncpy(char *destStr, const char *srcStr, size_t destSize) { strncpy(destStr, srcStr, destSize-1); destStr[destSize-1] = '\0'; @@ -88,7 +89,7 @@ void macIDToLower(char macValue[],char macConverted[]) int j; char *token[32]; char tmp[32]; - webStrncpy(tmp, macValue,sizeof(tmp)); + cpeabStrncpy(tmp, macValue,sizeof(tmp)); token[i] = strtok(tmp, ":"); if(token[i]!=NULL) { @@ -125,7 +126,7 @@ char* get_deviceMAC() strncpy(deviceMACValue, macID, strlen(macID)+1); macIDToLower(deviceMACValue, deviceMAC); WebcfgDebug("deviceMAC: %s\n",deviceMAC); - WEB_FREE(macID); + CPEABS_FREE(macID); } WebcfgInfo("Inside cpeabs lib file\n"); WebcfgDebug("deviceMAC returned from lib is %s\n", deviceMAC); @@ -300,12 +301,12 @@ int Get_Supplementary_URL( char *name, char *pString) strcpy(pString , tempUrl); } WebcfgDebug("Get_Supplementary_URL. pString %s\n", pString); - WEB_FREE(tempParam); + CPEABS_FREE(tempParam); } else { WebcfgError("psm_get failed ret %d for parameter %s\n", retPsmGet, tempParam); - WEB_FREE(tempParam); + CPEABS_FREE(tempParam); } } } @@ -328,7 +329,7 @@ int Set_Supplementary_URL( char *name, char *pString) if (retPsmSet != RBUS_ERROR_SUCCESS) { WebcfgError("psm_set failed ret %d for parameter %s%s and value %s\n", retPsmSet, WEBCFG_PARAM_SUPPLEMENTARY_SERVICE, name, pString); - WEB_FREE(tempParam); + CPEABS_FREE(tempParam); return 0; } else @@ -341,7 +342,7 @@ int Set_Supplementary_URL( char *name, char *pString) { WebcfgError("Invalid supplementary doc name\n"); } - WEB_FREE(tempParam); + CPEABS_FREE(tempParam); } } return retPsmSet; @@ -367,16 +368,16 @@ char * getParamValue(char *paramName) if (ret == WDMP_SUCCESS ) { strncpy(paramValue, parametervalArr[0]->value,64); - WEB_FREE(parametervalArr[0]->name); - WEB_FREE(parametervalArr[0]->value); - WEB_FREE(parametervalArr[0]); + CPEABS_FREE(parametervalArr[0]->name); + CPEABS_FREE(parametervalArr[0]->value); + CPEABS_FREE(parametervalArr[0]); } else { WebcfgError("Failed to GetValue for %s\n", getParamList[0]); - WEB_FREE(paramValue); + CPEABS_FREE(paramValue); } - WEB_FREE(parametervalArr); + CPEABS_FREE(parametervalArr); WebcfgDebug("getParamValue : paramValue is %s\n", paramValue); return paramValue; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f331a9e..be99558 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -27,11 +27,14 @@ if (BUILD_YOCTO) add_definitions(-DBUILD_YOCTO) endif (BUILD_YOCTO) -if (WEBCONFIG_BIN_SUPPORT) -add_definitions(-DWEBCONFIG_BIN_SUPPORT) -endif (WEBCONFIG_BIN_SUPPORT) +if (DEVICE_GATEWAY) +add_definitions(-DDEVICE_GATEWAY) +elseif (DEVICE_EXTENDER) +add_definitions(-DDEVICE_EXTENDER) +endif () + +if (PLATFORM STREQUAL "DEVICE_GATEWAY") -if(WEBCONFIG_BIN_SUPPORT) #------------------------------------------------------------------------------- # test_rdkb #------------------------------------------------------------------------------- @@ -45,7 +48,8 @@ target_link_libraries (test_rdkb -lcjson -lcunit -lmsgpackc -lwdmp-c -lcimplog - target_link_libraries (test_rdkb gcov -Wl,--no-as-needed ) -else() + +elseif (PLATFORM STREQUAL "DEVICE_EXTENDER") #------------------------------------------------------------------------------- # test_pods @@ -60,7 +64,22 @@ target_link_libraries (test_pods -lcunit) target_link_libraries (test_pods gcov -Wl,--no-as-needed ) -endif(WEBCONFIG_BIN_SUPPORT) +else() + +#------------------------------------------------------------------------------- +# test_pc +#------------------------------------------------------------------------------- +add_test(NAME test_pc COMMAND ${MEMORY_CHECK} ./test_pc) + +set(SOURCES test_pc.c ../src/pc/impl.c ) + +add_executable(test_pc ${SOURCES}) + +target_link_libraries (test_pc -lcunit) + +target_link_libraries (test_pc gcov -Wl,--no-as-needed ) + +endif() # Code coverage diff --git a/tests/test_pc.c b/tests/test_pc.c new file mode 100644 index 0000000..c255df5 --- /dev/null +++ b/tests/test_pc.c @@ -0,0 +1,87 @@ + /** + * Copyright 2021 Comcast Cable Communications Management, LLC + * + * 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. + * + */ +#include +#include +#include +#include +#include "cpeabs.h" + +/*----------------------------------------------------------------------------*/ +/* Macros */ +/*----------------------------------------------------------------------------*/ +/* none */ + +/*----------------------------------------------------------------------------*/ +/* Data Structures */ +/*----------------------------------------------------------------------------*/ +/* none */ + +/*----------------------------------------------------------------------------*/ +/* File Scoped Variables */ +/*----------------------------------------------------------------------------*/ +/* none */ + +/*----------------------------------------------------------------------------*/ +/* Function Prototypes */ +/*----------------------------------------------------------------------------*/ +/* none */ + +/*----------------------------------------------------------------------------*/ +/* Tests */ +/*----------------------------------------------------------------------------*/ +void test_do_something() +{ + char * testget = getParamValue("test"); + printf("%s\n", testget); +} + + +/*----------------------------------------------------------------------------*/ +/* Testing Framework */ +/*----------------------------------------------------------------------------*/ + +void add_suites(CU_pSuite *suite) +{ + *suite = CU_add_suite("common encoding tests", NULL, NULL); + CU_add_test(*suite, "Test do_something in test_pc", test_do_something); +} + +int main(void) +{ + unsigned rv = 1; + CU_pSuite suite = NULL; + + if (CUE_SUCCESS == CU_initialize_registry()) { + add_suites(&suite); + + if (NULL != suite) { + CU_basic_set_mode(CU_BRM_VERBOSE); + CU_basic_run_tests(); + printf("\n"); + CU_basic_show_failures(CU_get_failure_list()); + printf("\n\n"); + rv = CU_get_number_of_tests_failed(); + } + + CU_cleanup_registry(); + } + + if (0 != rv) { + return 1; + } + return 0; +} diff --git a/tests/test_pods.c b/tests/test_pods.c index d289dea..7daba06 100644 --- a/tests/test_pods.c +++ b/tests/test_pods.c @@ -1,5 +1,5 @@ /** - * Copyright 2019 Comcast Cable Communications Management, LLC + * Copyright 2021 Comcast Cable Communications Management, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ #include #include #include -#include "../include/cpeabs.h" +#include "cpeabs.h" /*----------------------------------------------------------------------------*/ /* Macros */ @@ -45,7 +45,8 @@ /*----------------------------------------------------------------------------*/ void test_do_something() { - do_something(); + char * testget = getParamValue("test"); + printf("%s\n", testget); } diff --git a/tests/test_rdkb.c b/tests/test_rdkb.c index 3158f4d..f13df78 100644 --- a/tests/test_rdkb.c +++ b/tests/test_rdkb.c @@ -1,5 +1,5 @@ /** - * Copyright 2019 Comcast Cable Communications Management, LLC + * Copyright 2021 Comcast Cable Communications Management, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ #include #include #include -#include "../include/cpeabs.h" +#include "cpeabs.h" /*----------------------------------------------------------------------------*/ /* Macros */ From 70af7813bca5e3ea4041742686b51a7c6aec3bc3 Mon Sep 17 00:00:00 2001 From: Guru Chandru Date: Tue, 9 Nov 2021 16:23:46 +0530 Subject: [PATCH 16/35] Cflag changes --- src/CMakeLists.txt | 10 ++++------ tests/CMakeLists.txt | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 03a4ace..3c9dc00 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,19 +18,17 @@ if (BUILD_YOCTO) add_definitions(-DBUILD_YOCTO) endif (BUILD_YOCTO) -#if (PLATFORM STREQUAL "DEVICE_GATEWAY") -if (DEVICE_GATEWAY) +if (PLATFORM STREQUAL "DEVICE_GATEWAY") add_definitions(-DDEVICE_GATEWAY) -#elseif (PLATFORM STREQUAL "DEVICE_EXTENDER") -elseif (DEVICE_EXTENDER) +elseif (PLATFORM STREQUAL "DEVICE_EXTENDER") add_definitions(-DDEVICE_EXTENDER) endif () set(HEADERS ../include/cpeabs.h) -if (DEVICE_GATEWAY) +if (PLATFORM STREQUAL "DEVICE_GATEWAY") set(SOURCES rdkb/impl.c) -elseif (DEVICE_EXTENDER) +elseif (PLATFORM STREQUAL "DEVICE_EXTENDER") set(SOURCES pods/impl.c) else () set(SOURCES pc/impl.c) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index be99558..8cf3bc3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -27,9 +27,9 @@ if (BUILD_YOCTO) add_definitions(-DBUILD_YOCTO) endif (BUILD_YOCTO) -if (DEVICE_GATEWAY) +if (PLATFORM STREQUAL "DEVICE_GATEWAY") add_definitions(-DDEVICE_GATEWAY) -elseif (DEVICE_EXTENDER) +elseif (PLATFORM STREQUAL "DEVICE_EXTENDER") add_definitions(-DDEVICE_EXTENDER) endif () From 82d2b7e1aeb73ef366987aef4c851c9e36ae0e5d Mon Sep 17 00:00:00 2001 From: Guru Chandru Date: Tue, 9 Nov 2021 18:45:11 +0530 Subject: [PATCH 17/35] Guardrail Security Fix --- src/pc/impl.c | 2 +- src/pods/impl.c | 2 +- src/rdkb/impl.c | 25 ++++++++++++------------- tests/test_pc.c | 2 +- tests/test_pods.c | 2 +- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/pc/impl.c b/src/pc/impl.c index 13ea633..9d37923 100644 --- a/src/pc/impl.c +++ b/src/pc/impl.c @@ -46,7 +46,7 @@ char * getParamValue(char *paramName) { UNUSED(paramName); - return "NULL"; + return NULL; } /** diff --git a/src/pods/impl.c b/src/pods/impl.c index 13ea633..9d37923 100644 --- a/src/pods/impl.c +++ b/src/pods/impl.c @@ -46,7 +46,7 @@ char * getParamValue(char *paramName) { UNUSED(paramName); - return "NULL"; + return NULL; } /** diff --git a/src/rdkb/impl.c b/src/rdkb/impl.c index 934a418..44b4924 100644 --- a/src/rdkb/impl.c +++ b/src/rdkb/impl.c @@ -89,18 +89,17 @@ void macIDToLower(char macValue[],char macConverted[]) int j; char *token[32]; char tmp[32]; - cpeabStrncpy(tmp, macValue,sizeof(tmp)); + cpeabStrncpy(tmp, macValue, sizeof(tmp)); token[i] = strtok(tmp, ":"); if(token[i]!=NULL) { - strncpy(macConverted, token[i],31); - macConverted[31]='\0'; + cpeabStrncpy(macConverted, token[i], 32); i++; } while ((token[i] = strtok(NULL, ":")) != NULL) { - strncat(macConverted, token[i],31); - macConverted[31]='\0'; + strncat(macConverted, token[i], 31); + macConverted[31]='\0'; i++; } macConverted[31]='\0'; @@ -123,7 +122,7 @@ char* get_deviceMAC() macID = getParamValue(DEVICE_MAC); if (macID != NULL) { - strncpy(deviceMACValue, macID, strlen(macID)+1); + cpeabStrncpy(deviceMACValue, macID, strlen(macID)+1); macIDToLower(deviceMACValue, deviceMAC); WebcfgDebug("deviceMAC: %s\n",deviceMAC); CPEABS_FREE(macID); @@ -244,7 +243,7 @@ int Get_Webconfig_URL( char *pString) { if(tempUrl !=NULL) { - strcpy(pString , tempUrl); + cpeabStrncpy(pString, tempUrl, strlen(tempUrl)+1); } WebcfgInfo("Inside cpeabs lib file\n"); WebcfgDebug("Get_Webconfig_URL. pString %s\n", pString); @@ -298,7 +297,7 @@ int Get_Supplementary_URL( char *name, char *pString) WebcfgDebug("Get_Supplementary_URL. retPsmGet %d tempUrl %s\n", retPsmGet, tempUrl); if(tempUrl !=NULL) { - strcpy(pString , tempUrl); + cpeabStrncpy(pString, tempUrl, strlen(tempUrl)+1); } WebcfgDebug("Get_Supplementary_URL. pString %s\n", pString); CPEABS_FREE(tempParam); @@ -367,7 +366,7 @@ char * getParamValue(char *paramName) if (ret == WDMP_SUCCESS ) { - strncpy(paramValue, parametervalArr[0]->value,64); + cpeabStrncpy(paramValue, parametervalArr[0]->value,64); CPEABS_FREE(parametervalArr[0]->name); CPEABS_FREE(parametervalArr[0]->value); CPEABS_FREE(parametervalArr[0]); @@ -397,14 +396,14 @@ int rbus_StoreValueIntoDB(char *paramName, char *value) rbusError_t errorcode = RBUS_ERROR_INVALID_INPUT; rbus_error_t err = RTMESSAGE_BUS_SUCCESS; - strcpy(recordName, paramName); + cpeabStrncpy(recordName, paramName, strlen(paramName)+1); WebcfgDebug("rbus_StoreValueIntoDB recordName is %s\n", recordName); val[0].paramName = recordName; val[0].paramValue = value; val[0].type = 0; - sprintf(psmName, "%s%s", "eRT.", DEST_COMP_ID_PSM); + snprintf(psmName, MAX_BUFF_SIZE, "%s%s", "eRT.", DEST_COMP_ID_PSM); WebcfgDebug("rbus_StoreValueIntoDB psmName is %s\n", psmName); rbusMessage request, response; @@ -464,12 +463,12 @@ int rbus_GetValueFromDB( char* paramName, char** paramValue) rbus_error_t err = RTMESSAGE_BUS_SUCCESS; *paramValue = NULL; - strcpy(recordName, paramName); + cpeabStrncpy(recordName, paramName, strlen(paramName)+1); WebcfgDebug("rbus_GetValueFromDB recordName is %s\n", recordName); parameterNames[0] = (char*)recordName; - sprintf(psmName, "%s%s", "eRT.", DEST_COMP_ID_PSM); + snprintf(psmName, MAX_BUFF_SIZE, "%s%s", "eRT.", DEST_COMP_ID_PSM); WebcfgDebug("rbus_GetValueFromDB psmName is %s\n", psmName); rbusMessage request, response; diff --git a/tests/test_pc.c b/tests/test_pc.c index c255df5..bc9052d 100644 --- a/tests/test_pc.c +++ b/tests/test_pc.c @@ -46,7 +46,7 @@ void test_do_something() { char * testget = getParamValue("test"); - printf("%s\n", testget); + printf("testget is %s\n", testget); } diff --git a/tests/test_pods.c b/tests/test_pods.c index 7daba06..b4989e3 100644 --- a/tests/test_pods.c +++ b/tests/test_pods.c @@ -46,7 +46,7 @@ void test_do_something() { char * testget = getParamValue("test"); - printf("%s\n", testget); + printf("testget is %s\n", testget); } From 66dc4d9c16115866eebd8f952e44c80c796f3c4f Mon Sep 17 00:00:00 2001 From: Guru Chandru Date: Tue, 9 Nov 2021 19:55:05 +0530 Subject: [PATCH 18/35] Removed debug logs --- src/rdkb/impl.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/rdkb/impl.c b/src/rdkb/impl.c index 44b4924..ac0b025 100644 --- a/src/rdkb/impl.c +++ b/src/rdkb/impl.c @@ -127,7 +127,6 @@ char* get_deviceMAC() WebcfgDebug("deviceMAC: %s\n",deviceMAC); CPEABS_FREE(macID); } - WebcfgInfo("Inside cpeabs lib file\n"); WebcfgDebug("deviceMAC returned from lib is %s\n", deviceMAC); return deviceMAC; } @@ -245,7 +244,6 @@ int Get_Webconfig_URL( char *pString) { cpeabStrncpy(pString, tempUrl, strlen(tempUrl)+1); } - WebcfgInfo("Inside cpeabs lib file\n"); WebcfgDebug("Get_Webconfig_URL. pString %s\n", pString); } else @@ -272,7 +270,6 @@ int Set_Webconfig_URL( char *pString) } else { - WebcfgInfo("Inside cpeabs lib file\n"); WebcfgDebug("psm_set success ret %d for parameter %s and value %s\n", retPsmSet, WEBCFG_URL_PARAM, pString); } } @@ -293,7 +290,6 @@ int Get_Supplementary_URL( char *name, char *pString) retPsmGet = rbus_GetValueFromDB( tempParam, &tempUrl); if (retPsmGet == RBUS_ERROR_SUCCESS) { - WebcfgInfo("Inside cpeabs lib file\n"); WebcfgDebug("Get_Supplementary_URL. retPsmGet %d tempUrl %s\n", retPsmGet, tempUrl); if(tempUrl !=NULL) { @@ -333,7 +329,6 @@ int Set_Supplementary_URL( char *name, char *pString) } else { - WebcfgInfo("Inside cpeabs lib file\n"); WebcfgDebug("psm_set success ret %d for parameter %s%s and value %s\n",retPsmSet, WEBCFG_PARAM_SUPPLEMENTARY_SERVICE, name, pString); } } From dcd5fd5ab9006d61a5f365142c7c8d9777ae6ffb Mon Sep 17 00:00:00 2001 From: Guru Chandru Date: Wed, 10 Nov 2021 12:23:37 +0530 Subject: [PATCH 19/35] Rbus Code changes and Review comment changes --- CMakeLists.txt | 2 +- src/CMakeLists.txt | 2 +- src/rdkb/impl.c | 210 ++++++++++++++++++------------------------- tests/CMakeLists.txt | 6 +- 4 files changed, 91 insertions(+), 129 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7367005..5874cbf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,7 @@ include_directories(${INCLUDE_DIR} ) include_directories( - include/ + ${PROJECT_SOURCE_DIR}/include/ ) if (NOT BUILD_YOCTO) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3c9dc00..4663626 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,7 +24,7 @@ elseif (PLATFORM STREQUAL "DEVICE_EXTENDER") add_definitions(-DDEVICE_EXTENDER) endif () -set(HEADERS ../include/cpeabs.h) +set(HEADERS ${PROJECT_SOURCE_DIR}/include/cpeabs.h) if (PLATFORM STREQUAL "DEVICE_GATEWAY") set(SOURCES rdkb/impl.c) diff --git a/src/rdkb/impl.c b/src/rdkb/impl.c index ac0b025..520900f 100644 --- a/src/rdkb/impl.c +++ b/src/rdkb/impl.c @@ -27,7 +27,6 @@ /*----------------------------------------------------------------------------*/ /* Macros */ /*----------------------------------------------------------------------------*/ -#define DEST_COMP_ID_PSM "com.cisco.spvtg.ccsp.psm" #define SERIAL_NUMBER "Device.DeviceInfo.SerialNumber" #define FIRMWARE_VERSION "Device.DeviceInfo.X_CISCO_COM_FirmwareName" #define DEVICE_BOOT_TIME "Device.DeviceInfo.X_RDKCENTRAL-COM_BootTime" @@ -74,6 +73,7 @@ void __attribute__((weak)) getValues_rbus(const char *paramName[], const unsigne static bool isRbusEnabled(); void macIDToLower(char macValue[],char macConverted[]); void cpeabStrncpy(char *destStr, const char *srcStr, size_t destSize); +rbusHandle_t __attribute__((weak)) get_global_rbus_handle(void); /*----------------------------------------------------------------------------*/ /* External Functions */ /*----------------------------------------------------------------------------*/ @@ -384,65 +384,38 @@ char * getParamValue(char *paramName) */ int rbus_StoreValueIntoDB(char *paramName, char *value) { - char recordName[ 256] = {'\0'}; - char psmName[256] = {'\0'}; - rbusParamVal_t val[1]; - bool commit = 1; - rbusError_t errorcode = RBUS_ERROR_INVALID_INPUT; - rbus_error_t err = RTMESSAGE_BUS_SUCCESS; - - cpeabStrncpy(recordName, paramName, strlen(paramName)+1); - WebcfgDebug("rbus_StoreValueIntoDB recordName is %s\n", recordName); - - val[0].paramName = recordName; - val[0].paramValue = value; - val[0].type = 0; - - snprintf(psmName, MAX_BUFF_SIZE, "%s%s", "eRT.", DEST_COMP_ID_PSM); - WebcfgDebug("rbus_StoreValueIntoDB psmName is %s\n", psmName); - - rbusMessage request, response; - - rbusMessage_Init(&request); - rbusMessage_SetInt32(request, 0); //sessionId - rbusMessage_SetString(request, "webconfig"); //component name that invokes the set - rbusMessage_SetInt32(request, (int32_t)1); //size of params - - rbusMessage_SetString(request, val[0].paramName); //param details - rbusMessage_SetInt32(request, val[0].type); - rbusMessage_SetString(request, val[0].paramValue); - rbusMessage_SetString(request, commit ? "1" : "0"); + rbusHandle_t rbus_handle; + rbusObject_t inParams; + rbusObject_t outParams; + rbusValue_t setvalue; + int rc = RBUS_ERROR_SUCCESS; + + rbus_handle = get_global_rbus_handle(); + if(!rbus_handle) + { + WebcfgError("rbus_StoreValueIntoDB failed as rbus_handle is empty\n"); + return 1; + } + rbusObject_Init(&inParams, NULL); + rbusValue_Init(&setvalue); + rbusValue_SetString(setvalue, value); + rbusObject_SetValue(inParams, paramName, setvalue); + rbusValue_Release(setvalue); - if((err = rbus_invokeRemoteMethod(psmName, METHOD_SETPARAMETERVALUES, request, 6000, &response)) != RTMESSAGE_BUS_SUCCESS) - { - WebcfgError("rbus_invokeRemoteMethod failed with err %d", err); - errorcode = RBUS_ERROR_BUS_ERROR; - } - else - { - int ret = -1; - char const* pErrorReason = NULL; - rbusMessage_GetInt32(response, &ret); - - WebcfgDebug("Response from the remote method is [%d]!", ret); - errorcode = (rbusError_t) ret; - - if((errorcode == RBUS_ERROR_SUCCESS) || (errorcode == 100)) //legacy error codes returned from component PSM. - { - errorcode = RBUS_ERROR_SUCCESS; - WebcfgDebug("Successfully Set the Value"); - } - else - { - rbusMessage_GetString(response, &pErrorReason); - WebcfgError("Failed to Set the Value for %s", pErrorReason); - } - - rbusMessage_Release(response); - } - - return errorcode; + rc = rbusMethod_Invoke(rbus_handle, "SetPSMRecordValue()", inParams, &outParams); + rbusObject_Release(inParams); + if(rc != RBUS_ERROR_SUCCESS) + { + WebcfgError("SetPSMRecordValue failed with err %d: %s\n", rc, rbusError_ToString(rc)); + } + else + { + WebcfgDebug("SetPSMRecordValue is success\n"); + rbusObject_Release(outParams); + return 0; + } + return 1; } /** @@ -450,78 +423,62 @@ int rbus_StoreValueIntoDB(char *paramName, char *value) */ int rbus_GetValueFromDB( char* paramName, char** paramValue) { - char recordName[ 256] = {'\0'}; - char psmName[256] = {'\0'}; - char * parameterNames[1] = {NULL}; - int32_t type = 0; - rbusError_t errorcode = RBUS_ERROR_INVALID_INPUT; - rbus_error_t err = RTMESSAGE_BUS_SUCCESS; - *paramValue = NULL; - - cpeabStrncpy(recordName, paramName, strlen(paramName)+1); - WebcfgDebug("rbus_GetValueFromDB recordName is %s\n", recordName); - - parameterNames[0] = (char*)recordName; - - snprintf(psmName, MAX_BUFF_SIZE, "%s%s", "eRT.", DEST_COMP_ID_PSM); - WebcfgDebug("rbus_GetValueFromDB psmName is %s\n", psmName); - - rbusMessage request, response; - - rbusMessage_Init(&request); - rbusMessage_SetString(request, psmName); //component name that invokes the get - rbusMessage_SetInt32(request, (int32_t)1); //size of params + rbusHandle_t rbus_handle; + rbusObject_t inParams; + rbusObject_t outParams; + rbusValue_t setvalue; + int rc = RBUS_ERROR_SUCCESS; + + rbus_handle = get_global_rbus_handle(); + if(!rbus_handle) + { + WebcfgError("rbus_GetValueFromDB failed as rbus_handle is empty\n"); + return 1; + } - rbusMessage_SetString(request, parameterNames[0]); //param details + rbusObject_Init(&inParams, NULL); + rbusValue_Init(&setvalue); + rbusValue_SetString(setvalue, "value"); + rbusObject_SetValue(inParams, paramName, setvalue); + rbusValue_Release(setvalue); - if((err = rbus_invokeRemoteMethod(psmName, METHOD_GETPARAMETERVALUES, request, 6000, &response)) != RTMESSAGE_BUS_SUCCESS) - { - WebcfgError("rbus_invokeRemoteMethod GET failed with err %d\n", err); - errorcode = RBUS_ERROR_BUS_ERROR; - } - else - { - int valSize=0; - int ret = -1; - rbusMessage_GetInt32(response, &ret); - WebcfgDebug("Response from the remote method is [%d]!\n",ret); - errorcode = (rbusError_t) ret; - - if((errorcode == RBUS_ERROR_SUCCESS) || (errorcode == 100)) //legacy error code from component. - { - WebcfgDebug("Successfully Get the Value\n"); - errorcode = RBUS_ERROR_SUCCESS; - rbusMessage_GetInt32(response, &valSize); - if(1/*valSize*/) + rc = rbusMethod_Invoke(rbus_handle, "GetPSMRecordValue()", inParams, &outParams); + rbusObject_Release(inParams); + if(rc != RBUS_ERROR_SUCCESS) + { + WebcfgError("GetPSMRecordValue failed with err %d: %s\n", rc, rbusError_ToString(rc)); + } + else + { + WebcfgDebug("GetPSMRecordValue is success\n"); + rbusProperty_t prop = NULL; + rbusValue_t value = NULL; + char *str_value = NULL; + prop = rbusObject_GetProperties(outParams); + while(prop) { - char const *buff = NULL; - rbusMessage_GetString(response, &buff); - WebcfgDebug("Requested param buff [%s]\n", buff); - if(buff && (strcmp(recordName, buff) == 0)) + value = rbusProperty_GetValue(prop); + if(value) { - rbusMessage_GetInt32(response, &type); - WebcfgDebug("Requested param type [%d]\n", type); - buff = NULL; - rbusMessage_GetString(response, &buff); - *paramValue = strdup(buff); //free buff - WebcfgDebug("Requested param DB value [%s]\n", *paramValue); - } - else - { - WebcfgError("Rbus error. Requested param: [%s], Received Param: [%s]\n", recordName, buff); - errorcode = RBUS_ERROR_BUS_ERROR; + str_value = rbusValue_ToString(value,NULL,0); + if(str_value) + { + WebcfgDebug("Parameter Name : %s\n", rbusProperty_GetName(prop)); + WebcfgDebug("Parameter Value fetched: %s\n", str_value); + } } + prop = rbusProperty_GetNext(prop); } - } - else - { - WebcfgError("Response from remote Get method failed!!\n"); - errorcode = RBUS_ERROR_BUS_ERROR; - } - - rbusMessage_Release(response); - } - return errorcode; + if(str_value !=NULL) + { + *paramValue = strdup(str_value); + CPEABS_FREE(str_value); + WebcfgDebug("Requested param DB value [%s]\n", *paramValue); + } + rbusObject_Release(outParams); + return 0; + } + return 1; } void getValues_rbus(const char *paramName[], const unsigned int paramCount, int index, money_trace_spans *timeSpan, param_t ***paramArr, int *retValCount, WDMP_STATUS *retStatus) @@ -536,3 +493,8 @@ void getValues_rbus(const char *paramName[], const unsigned int paramCount, int return; } +rbusHandle_t get_global_rbus_handle(void) +{ + return 0; +} + diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8cf3bc3..6d56449 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -40,7 +40,7 @@ if (PLATFORM STREQUAL "DEVICE_GATEWAY") #------------------------------------------------------------------------------- add_test(NAME test_rdkb COMMAND ${MEMORY_CHECK} ./test_rdkb) -set(SOURCES test_rdkb.c ../src/rdkb/impl.c ) +set(SOURCES test_rdkb.c ${PROJECT_SOURCE_DIR}/src/rdkb/impl.c ) add_executable(test_rdkb ${SOURCES}) @@ -56,7 +56,7 @@ elseif (PLATFORM STREQUAL "DEVICE_EXTENDER") #------------------------------------------------------------------------------- add_test(NAME test_pods COMMAND ${MEMORY_CHECK} ./test_pods) -set(SOURCES test_pods.c ../src/pods/impl.c ) +set(SOURCES test_pods.c ${PROJECT_SOURCE_DIR}/src/pods/impl.c ) add_executable(test_pods ${SOURCES}) @@ -71,7 +71,7 @@ else() #------------------------------------------------------------------------------- add_test(NAME test_pc COMMAND ${MEMORY_CHECK} ./test_pc) -set(SOURCES test_pc.c ../src/pc/impl.c ) +set(SOURCES test_pc.c ${PROJECT_SOURCE_DIR}/src/pc/impl.c ) add_executable(test_pc ${SOURCES}) From 281ac9f331c29218abd1c7bbb192b54c65bf40b0 Mon Sep 17 00:00:00 2001 From: Guru Chandru Date: Wed, 10 Nov 2021 14:52:32 +0530 Subject: [PATCH 20/35] Updated README.md file --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4481262..9e581c2 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,9 @@ An abstraction layer for consumer preference equipment systems. # Building and Testing Instructions ``` +Use CFLAG -DPLATFORM=DEVICE_GATEWAY to build for RDKB platform +Use CFLAG -DPLATFORM=DEVICE_EXTENDER to build for POD platform + mkdir build cd build cmake .. @@ -25,5 +28,3 @@ make make test ``` -The `workaround.sh` script makes it so we don't need to add the rbus stuff to the -upstream wrapdb. From fe80eaf0e842315220105cf426ef640c2284d09e Mon Sep 17 00:00:00 2001 From: Debasya Sahoo Date: Thu, 11 Nov 2021 07:36:01 +0000 Subject: [PATCH 21/35] Adding cimplog fix for extender support --- include/cpeabs.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/cpeabs.h b/include/cpeabs.h index 850011b..9b5c804 100644 --- a/include/cpeabs.h +++ b/include/cpeabs.h @@ -18,7 +18,11 @@ #include #include + +#if ! defined(DEVICE_EXTENDER) #include +#endif + #include #include #include From 5574067c0b036f9f1c88ba18a99e799b05cd212d Mon Sep 17 00:00:00 2001 From: Sadhyama Vengilat Date: Thu, 11 Nov 2021 16:02:49 +0530 Subject: [PATCH 22/35] Check CR systemready using rbus --- include/cpeabs.h | 2 +- src/rdkb/impl.c | 187 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 187 insertions(+), 2 deletions(-) diff --git a/include/cpeabs.h b/include/cpeabs.h index 9b5c804..91b8602 100644 --- a/include/cpeabs.h +++ b/include/cpeabs.h @@ -70,6 +70,6 @@ char * getParamValue(char *paramName); void getValues_rbus(const char *paramName[], const unsigned int paramCount, int index, money_trace_spans *timeSpan, param_t ***paramArr, int *retValCount, WDMP_STATUS *retStatus); int rbus_GetValueFromDB( char* paramName, char** paramValue); int rbus_StoreValueIntoDB(char *paramName, char *value); - +int rbus_waitUntilSystemReady(); #endif diff --git a/src/rdkb/impl.c b/src/rdkb/impl.c index 520900f..ffeb14a 100644 --- a/src/rdkb/impl.c +++ b/src/rdkb/impl.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -51,7 +52,7 @@ #define WEBCFG_URL_PARAM "Device.X_RDK_WebConfig.URL" #define WEBCFG_PARAM_SUPPLEMENTARY_SERVICE "Device.X_RDK_WebConfig.SupplementaryServiceUrls." - +#define SYSTEM_READY_PARM "Device.CR.SystemReady" /*----------------------------------------------------------------------------*/ /* Data Structures */ /*----------------------------------------------------------------------------*/ @@ -74,6 +75,10 @@ static bool isRbusEnabled(); void macIDToLower(char macValue[],char macConverted[]); void cpeabStrncpy(char *destStr, const char *srcStr, size_t destSize); rbusHandle_t __attribute__((weak)) get_global_rbus_handle(void); +static void systemReadyEventHandler(rbusHandle_t handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription); +static void subscribeSystemReadyEvent(); +static int rbus_checkIfSystemReady(); +static int webcfgRbusRegisterWithCR(); /*----------------------------------------------------------------------------*/ /* External Functions */ /*----------------------------------------------------------------------------*/ @@ -498,3 +503,183 @@ rbusHandle_t get_global_rbus_handle(void) return 0; } +int rbus_waitUntilSystemReady() +{ + int ret = 0; + if(rbus_checkIfSystemReady()) + { + WebcfgInfo("Checked CR - System is ready, proceed with webconfig startup\n"); + system("touch /var/tmp/webcfgcacheready"); + } + else + { + webcfgRbusRegisterWithCR(); + subscribeSystemReadyEvent(); + + FILE *file; + int wait_time = 0; + int total_wait_time = 0; + + //Wait till Call back touches the indicator to proceed further + while((file = fopen("/var/tmp/webcfgcacheready", "r")) == NULL) + { + WebcfgInfo("Waiting for system ready signal\n"); + //After waiting for 24 * 5 = 120s (2mins) send message to CR to query for system ready + if(wait_time == 24) + { + wait_time = 0; + if(rbus_checkIfSystemReady()) + { + WebcfgInfo("Checked CR - System is ready\n"); + system("touch /var/tmp/webcfgcacheready"); + break; + } + else + { + WebcfgInfo("Queried CR for system ready after waiting for 2 mins, it is still not ready\n"); + if(total_wait_time >= 84) + { + WebcfgInfo("Queried CR for system ready after waiting for 7 mins, it is still not ready. Proceeding ...\n"); + ret = 1; + break; + } + } + } + sleep(5); + wait_time++; + total_wait_time++; + }; + // In case of WebConfig restart, we should be having cacheready already touched. + if(file != NULL) + { + WebcfgInfo("/var/tmp/webcfgcacheready file exists, proceed with webconfig start up\n"); + fclose(file); + } + } + return ret; +} + +static void subscribeSystemReadyEvent() +{ + int rc = RBUS_ERROR_SUCCESS; + rbusHandle_t rbus_handle; + + rbus_handle = get_global_rbus_handle(); + if(!rbus_handle) + { + WebcfgError("subscribeSystemReadyEvent failed as rbus_handle is empty\n"); + return; + } + + rc = rbusEvent_Subscribe(rbus_handle,SYSTEM_READY_PARM,systemReadyEventHandler,"webconfig",0); + if(rc != RBUS_ERROR_SUCCESS) + WebcfgError("systemready rbusEvent_Subscribe failed: %d, %s\n", rc, rbusError_ToString(rc)); + else + WebcfgInfo("systemready rbusEvent_Subscribe was successful\n"); +} + +static void systemReadyEventHandler(rbusHandle_t handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription) +{ + (void)handle; + (void)subscription; + int eventValue = 0; + rbusValue_t value = NULL; + + value = rbusObject_GetValue(event->data, "value"); + eventValue = (int) rbusValue_GetBoolean(value); + WebcfgDebug("eventValue is %d\n", eventValue); + if(eventValue) + { + system("touch /var/tmp/webcfgcacheready"); + WebcfgInfo("Received system ready signal, created /var/tmp/webcfgcacheready file\n"); + } +} + +/** + * rbus_checkIfSystemReady Function to query CR and check if system is ready. + * This is just in case webconfig registers for the systemReadySignal event late. + * If SystemReadySignal is already sent then this will return 1 indicating system is ready. + */ +static int rbus_checkIfSystemReady() +{ + int rc = -1; + rbusHandle_t rbus_handle; + int sysVal = 0; + + rbus_handle = get_global_rbus_handle(); + if(!rbus_handle) + { + WebcfgError("rbus_checkIfSystemReady failed as rbus_handle is empty\n"); + return rc; + } + + rbusValue_t value; + rc = rbus_get(rbus_handle, SYSTEM_READY_PARM, &value); + if(rc != RBUS_ERROR_SUCCESS) + { + WebcfgError("rbus_checkIfSystemReady failed with err %d: %s\n", rc, rbusError_ToString(rc)); + return rc; + } + else + { + WebcfgDebug("rbus_checkIfSystemReady returns %d\n", rbusValue_GetBoolean(value)); + sysVal = (int) rbusValue_GetBoolean(value); + WebcfgDebug("sysVal is %d\n", sysVal); + } + rbusValue_Release(value); + if(sysVal) + { + WebcfgDebug("SystemReady returns 1\n"); + return 1; + } + else + { + WebcfgDebug("SystemReady returns 0\n"); + } + return rc; +} + +/** + * To register webconfig component with component Registery CR. + */ +static int webcfgRbusRegisterWithCR() +{ + rbusHandle_t rbus_handle; + rbusObject_t inParams; + rbusObject_t outParams; + rbusValue_t value; + int rc = RBUS_ERROR_SUCCESS; + + rbus_handle = get_global_rbus_handle(); + if(!rbus_handle) + { + WebcfgError("webcfgRbusRegisterWithCR failed as rbus_handle is empty\n"); + return 1; + } + + rbusObject_Init(&inParams, NULL); + + rbusValue_Init(&value); + rbusValue_SetString(value, "webconfig"); + rbusObject_SetValue(inParams, "name", value); + rbusValue_Release(value); + + rbusValue_Init(&value); + rbusValue_SetInt32(value, 1); + rbusObject_SetValue(inParams, "version", value); + rbusValue_Release(value); + + rc = rbusMethod_Invoke(rbus_handle, "Device.CR.RegisterComponent()", inParams, &outParams); + rbusObject_Release(inParams); + if(rc != RBUS_ERROR_SUCCESS) + { + WebcfgError("Device.CR.RegisterComponent failed with err %d: %s\n", rc, rbusError_ToString(rc)); + } + else + { + WebcfgInfo("Device.CR.RegisterComponent is success\n"); + rbusObject_Release(outParams); + return 0; + } + return 1; +} From 5a236e45b92fb79e624011e42fb66cd98f0497ca Mon Sep 17 00:00:00 2001 From: Sadhyama Vengilat Date: Mon, 15 Nov 2021 21:35:11 +0530 Subject: [PATCH 23/35] To use file creat functions instead of system commands --- src/rdkb/impl.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/rdkb/impl.c b/src/rdkb/impl.c index ffeb14a..ca4e3d4 100644 --- a/src/rdkb/impl.c +++ b/src/rdkb/impl.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include #include #include @@ -506,10 +508,19 @@ rbusHandle_t get_global_rbus_handle(void) int rbus_waitUntilSystemReady() { int ret = 0; + int fd; + if(rbus_checkIfSystemReady()) { WebcfgInfo("Checked CR - System is ready, proceed with webconfig startup\n"); - system("touch /var/tmp/webcfgcacheready"); + if((fd = creat("/var/tmp/webcfgcacheready", S_IRUSR | S_IWUSR)) == -1) + { + WebcfgError("/var/tmp/webcfgcacheready file creation failed with error:%d\n", errno); + } + else + { + close(fd); + } } else { @@ -531,7 +542,14 @@ int rbus_waitUntilSystemReady() if(rbus_checkIfSystemReady()) { WebcfgInfo("Checked CR - System is ready\n"); - system("touch /var/tmp/webcfgcacheready"); + if((fd = creat("/var/tmp/webcfgcacheready", S_IRUSR | S_IWUSR)) == -1) + { + WebcfgError("/var/tmp/webcfgcacheready file creation failed, error:%d\n", errno); + } + else + { + close(fd); + } break; } else @@ -584,13 +602,21 @@ static void systemReadyEventHandler(rbusHandle_t handle, rbusEvent_t const* even (void)subscription; int eventValue = 0; rbusValue_t value = NULL; + int fd; value = rbusObject_GetValue(event->data, "value"); eventValue = (int) rbusValue_GetBoolean(value); WebcfgDebug("eventValue is %d\n", eventValue); if(eventValue) { - system("touch /var/tmp/webcfgcacheready"); + if((fd = creat("/var/tmp/webcfgcacheready", S_IRUSR | S_IWUSR)) == -1) + { + WebcfgError("Failed to create /var/tmp/webcfgcacheready file, error:%d\n", errno); + } + else + { + close(fd); + } WebcfgInfo("Received system ready signal, created /var/tmp/webcfgcacheready file\n"); } } From 3448ecbdaf354d3180392ef5f045ae6af8ab0c64 Mon Sep 17 00:00:00 2001 From: Sreedevi V Date: Tue, 23 Nov 2021 16:24:28 +0530 Subject: [PATCH 24/35] Move connected client notification business logic from webconfig to webpa. --- src/rdkb/impl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rdkb/impl.c b/src/rdkb/impl.c index ca4e3d4..e6a63fb 100644 --- a/src/rdkb/impl.c +++ b/src/rdkb/impl.c @@ -35,7 +35,7 @@ #define DEVICE_BOOT_TIME "Device.DeviceInfo.X_RDKCENTRAL-COM_BootTime" #define MODEL_NAME "Device.DeviceInfo.ModelName" #define PRODUCT_CLASS "Device.DeviceInfo.ProductClass" -#define CONN_CLIENT_PARAM "Device.NotifyComponent.X_RDKCENTRAL-COM_Connected-Client" +#define CONN_CLIENT_PARAM "Device.X_RDK_Webpa.ConnectedClientNotify" #define LAST_REBOOT_REASON "Device.DeviceInfo.X_RDKCENTRAL-COM_LastRebootReason" #define PARTNER_ID "Device.DeviceInfo.X_RDKCENTRAL-COM_Syndication.PartnerId" #define ACCOUNT_ID "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.AccountInfo.AccountID" From ab7e95335f0411b4141b06b9d1a67c1ce8ebda66 Mon Sep 17 00:00:00 2001 From: Debasya Sahoo Date: Fri, 10 Dec 2021 13:14:03 +0000 Subject: [PATCH 25/35] Adding utils and database functionalities Change-Id: I3e37c85106f4326d4f7a3757b750d2136eff1a1a --- include/cpeabs.h | 3 +- include/cpeabs_ovsdb_utils.h | 26 ++ src/CMakeLists.txt | 7 +- src/pods/cpeabs_ovsdb_utils.c | 637 ++++++++++++++++++++++++++++++ src/pods/impl.c | 703 ++++++++++++++++++++++++++++++++-- 5 files changed, 1330 insertions(+), 46 deletions(-) create mode 100644 include/cpeabs_ovsdb_utils.h create mode 100644 src/pods/cpeabs_ovsdb_utils.c diff --git a/include/cpeabs.h b/include/cpeabs.h index 91b8602..c3d8c4a 100644 --- a/include/cpeabs.h +++ b/include/cpeabs.h @@ -21,14 +21,13 @@ #if ! defined(DEVICE_EXTENDER) #include -#endif - #include #include #include #include #include #include +#endif /*----------------------------------------------------------------------------*/ /* Macros */ diff --git a/include/cpeabs_ovsdb_utils.h b/include/cpeabs_ovsdb_utils.h new file mode 100644 index 0000000..0552975 --- /dev/null +++ b/include/cpeabs_ovsdb_utils.h @@ -0,0 +1,26 @@ +/* + * Copyright 2021 Comcast Cable Communications Management, LLC + * + * 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. + */ + +#include + +#define OVSDB_COL_NUM 256 +#define OVSDB_COL_STR 1024 +#define UUID_STR_LEN 36 +#define OVSDB_SOCK_PATH "/var/run/db.sock" + +bool ovsdb_string_value_get(char *table,json_t *where, int coln, char * colv[],char *result_str, unsigned int len ); +bool ovsdb_parse_where(json_t *where, char *_str, bool is_parent_where); +void cpeabStrncpy(char *destStr, const char *srcStr, size_t destSize); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4663626..4cfeb38 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,12 +24,13 @@ elseif (PLATFORM STREQUAL "DEVICE_EXTENDER") add_definitions(-DDEVICE_EXTENDER) endif () -set(HEADERS ${PROJECT_SOURCE_DIR}/include/cpeabs.h) - if (PLATFORM STREQUAL "DEVICE_GATEWAY") set(SOURCES rdkb/impl.c) +set(HEADERS ${PROJECT_SOURCE_DIR}/include/cpeabs.h) elseif (PLATFORM STREQUAL "DEVICE_EXTENDER") -set(SOURCES pods/impl.c) +set(SOURCES pods/impl.c pods/cpeabs_ovsdb_utils.c) +set(HEADERS ${PROJECT_SOURCE_DIR}/include/cpeabs_ovsdb_utils.h ${PROJECT_SOURCE_DIR}/include/cpeabs.h) +add_definitions(-DPS_FILE_PATH=${PS_FILE_PATH}) else () set(SOURCES pc/impl.c) endif () diff --git a/src/pods/cpeabs_ovsdb_utils.c b/src/pods/cpeabs_ovsdb_utils.c new file mode 100644 index 0000000..c744f57 --- /dev/null +++ b/src/pods/cpeabs_ovsdb_utils.c @@ -0,0 +1,637 @@ +/* + * Copyright 2021 Comcast Cable Communications Management, LLC + * + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "cpeabs_ovsdb_utils.h" +#include "cpeabs.h" + +static int g_ovsdb_handle = -1; +static char ovsdb_opt_db[32] = "Open_vSwitch"; +static int ovsdb_where_num = 0; +static char **ovsdb_where_expr = NULL; + +int ovsdb_connect(void); +void ovsdb_close(int fd); +static json_t *ovsdb_json_exec(char *method, json_t *params); +static bool ovsdb_json_error(json_t *jres); +static bool ovsdb_parse_columns(json_t *columns, int colc, char *colv[]); +json_t *json_value(char *str); + +/* + * Initialize Ovsdb connection and return handle. + */ +int ovsdb_util_init() +{ + int db = -1; + + db = ovsdb_connect(); + if (db < 0) { + WebcfgError("%s : Failed to connect to ovsdb. \n",__func__); + } + else + { + WebcfgError("%s : Successfully connected to ovsdb \n",__func__); + g_ovsdb_handle = db; + } + return db; +} + +bool ovsdb_util_fini() +{ + if (g_ovsdb_handle > 0) + { + ovsdb_close(g_ovsdb_handle); + g_ovsdb_handle = -1; + } + return true; +} + +int ovsdb_handle_get() +{ + return g_ovsdb_handle; +} + +/* + * =========================================================================== + * OVSDB communication functions + * =========================================================================== + */ + +/* + * Connect to a OVSDB database + */ +int ovsdb_connect(void) +{ + struct sockaddr_un addr; + + int fd = -1; + + fd = socket(AF_UNIX, SOCK_STREAM, 0); + if (fd < 0) + { + WebcfgError("Unable to open OVSDB socket: %s\n", strerror(errno)); + goto error; + } + + memset(&addr, 0, sizeof(addr)); + addr.sun_family = AF_UNIX; + + char *sock_path = OVSDB_SOCK_PATH; + + if (strlen(sock_path) >= sizeof(addr.sun_path)) + { + WebcfgError("Connect path too long!\n"); + goto error; + } + cpeabStrncpy(addr.sun_path, sock_path, sizeof(addr.sun_path)); + + if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) != 0) + { + WebcfgError("Unable to connect to OVSDB: %s\n", strerror(errno)); + goto error; + } + + return fd; + +error: + if (fd >= 0) close(fd); + + return -1; +} + +void ovsdb_close(int fd) +{ + close(fd); +} + +/* + * OVSDB Select method + */ +bool ovsdb_select(char *table, json_t *where, int coln, char *colv[], + json_t **jresult, json_t **acolumns) +{ + *jresult = NULL; + json_t *columns = json_array(); + *acolumns = columns; + + json_t *jparam = json_pack("[ s, { s:s, s:s, s:o } ]", + ovsdb_opt_db, + "op", "select", + "table", table, + "where", where); + if (jparam == NULL) + { + WebcfgError("Error creating JSON-RPC parameters (SELECT).\n"); + return false; + } + if (coln > 0) + { + /* Parse columns */ + if (!ovsdb_parse_columns(columns, coln, colv)) + { + WebcfgError("Error parsing columns. \n"); + } + + if (json_object_set_new(json_array_get(jparam, 1), "columns", columns) != 0) + { + WebcfgError("Error appending columns.\n"); + return false; + } + } + json_t *jres = ovsdb_json_exec("transact", jparam); + if (!ovsdb_json_error(jres)) + { + return false; + } + *jresult = jres; + return true; +} + +/* + * This functions splits a string into a left value, an operator and a right value. It can be used to + * parse structures as a=b, or a!=b etc. + * + * This function modifies the string expr + * Param op is taken from the "delim" array + */ +static bool str_parse_expr(char *expr, char *delim[], char **lval, char **op, char **rval) +{ + char *pop; + char **pdelim; + + for (pdelim = delim; *pdelim != NULL; pdelim++) + { + /* Find the delimiter string */ + pop = strstr(expr, *pdelim); + if (pop == NULL) continue; + + *op = *pdelim; + + *lval = expr; + *rval = pop + strlen(*pdelim); + *pop = '\0'; + + return true; + } + + /* Error parsing */ + return false; +} + + +/* + * Check if an error was reported from OVSDB, if so, display it and return false. Return true otherwise. + */ +bool ovsdb_json_error(json_t *jobj) +{ + json_t *jres = json_object_get(jobj, "result"); + if (jres == NULL) + { + WebcfgError("Error: No \"result\" object is present.\n"); + return false; + } + + /* Use the first object in the array */ + jres = json_array_get(jres, 0); + + json_t *jerror = json_object_get(jres, "error"); + if (jerror == NULL) + { + /* No error, return */ + return true; + } + WebcfgError("Error: %s\n", json_string_value(jerror)); + + json_t *jdetails = json_object_get(jres, "details"); + if (jdetails != NULL) + { + WebcfgError("Details: %s\n", json_string_value(jdetails)); + } + + json_t *jsyntax = json_object_get(jres, "syntax"); + if (jsyntax != NULL) + { + WebcfgError("Syntax: %s\n", json_string_value(jsyntax)); + } + + return false; +} + +/* + * Return true if string is encased in quotation marks, either ' or " + */ +bool str_is_quoted(char *str) +{ + size_t len = strlen(str); + + if ((str[0] == '"' && str[len - 1] == '"') || + (str[0] == '\'' && str[len - 1] == '\'')) + { + return true; + } + + return false; +} + +/* + * Guess the type of "str" and return a JSON object of the corresponding type. + * + * If str is: + * "\"...\"" -> Everything that starts with a quote and ends in a quote is assumed to be a string. + * The resulting object is the value without quotes + * "true" -> bool, value set to true + * "false" -> bool, value set to false + * "XXXX" -> where X are digits only -> integer + * ["map", -> object + * ["set", -> object + * ["uuid", -> object + * + * Everything else is assumed to be a string. + */ +json_t *json_value(char *str) +{ + if (str[0] == '\0') return json_string(""); + + /* + * Check for quoted string first + */ + if (str_is_quoted(str)) + { + return json_stringn(str + 1, strlen(str) - 2); + } + + if (strcmp(str, "true") == 0) + { + return json_true(); + } + else if (strcmp(str, "false") == 0) + { + return json_false(); + } + + /* + * Try to convert it to an integer + */ + char *pend; + json_int_t lval = strtoll(str, &pend, 0); + + /* All character were consumed during conversion -- it's an int */ + if (*pend == '\0') + { + return json_integer(lval); + } + // check if object + char *str_map = "[\"map\","; + char *str_set = "[\"set\","; + char *str_uuid = "[\"uuid\","; + if (!strncmp(str, str_map, strlen(str_map)) + || !strncmp(str, str_set, strlen(str_set)) + || !strncmp(str, str_uuid, strlen(str_uuid))) + { + // Try to parse rval as a json object + json_t *jobj = json_loads(str, 0, NULL); + if (jobj) { + return jobj; + } + WebcfgError("Error decoding as object value: %s\n", str); + // fallthrough, treat as string for backward compatibility, eventually treat as error + } + + /* Everything else is a string */ + return json_string(str); +} + +/* + * Parse a list of columns, generate an array object out of it + */ +static bool ovsdb_parse_columns(json_t *columns, int colc, char *colv[]) +{ + int ii; + + json_t *jrval = NULL; + + for (ii = 0; ii < colc; ii++) + { + char col[OVSDB_COL_STR]; + + /* + * Use only the "left" value of an expression + */ + char *lval, *op, *rval; + + static char *delim[] = + { + ":=", + "::", + "~=", + NULL + }; + + if (strlen(colv[ii]) + 1 > sizeof(col)) + { + WebcfgError("Column too big: %s\n", colv[ii]); + return false; + } + cpeabStrncpy(col, colv[ii], OVSDB_COL_STR); + if (!str_parse_expr(col, delim, &lval, &op, &rval)) + { + /*Not an expression, use whole line as left value */ + lval = colv[ii]; + rval = NULL; + } + else + { + /* Depending on the operator, do different things with rval */ + if (strcmp(op, ":=") == 0) + { + /* := standard right value processing */ + jrval = json_value(rval); + } + else if (strcmp(op, "::") == 0) + { + /* Try to parse rval as a json object */ + jrval = json_loads(rval, 0, NULL); + if (jrval == NULL) + { + WebcfgError("Error decoding column right value: %s\n", rval); + return false; + } + } + else if (strcmp(op, "~=") == 0) + { + /* Force right value to string */ + jrval = json_string(rval); + } + else + { + WebcfgError("Error decoding column operator: %s\n", op); + return false; + } + } + + if (json_is_array(columns)) + { + /* Append left value only */ + if (json_array_append_new(columns, json_string(lval)) != 0) + { + goto error; + } + } + else if (json_is_object(columns) && rval != NULL) + { + if (json_object_set_new(columns, lval, jrval) != 0) + { + goto error; + } + } + else + { + WebcfgError("Parameter is not an object or array.\n"); + goto error; + } + + jrval = NULL; + } + return true; + +error: + if (jrval != NULL) json_decref(jrval); + return false; +} + +bool ovsdb_json_get_result_rows(json_t *jobj, json_t **jrows) +{ + *jrows = NULL; + + json_t *jres = json_object_get(jobj, "result"); + if (jres == NULL) + { + WebcfgError("Error: No \"result\" object is present.\n"); + return false; + } + + /* Use the first object in the array */ + jres = json_array_get(jres, 0); + if (jres == NULL) + { + WebcfgError("Unexpected JSON result: Got empty array.\n"); + return false; + } + + *jrows = json_object_get(jres, "rows"); + if (*jrows == NULL) + { + WebcfgError("Error: Expected \"rows\" object in response.\n"); + return false; + } + return true; +} + +/* + * Execute a JSON RPC command, close the connection and return + */ +json_t *ovsdb_json_exec(char *method, json_t *params) +{ + char buf[2048]; + + char *str = NULL; + json_t *jres = NULL; + int db = -1; + + json_t *jexec = json_pack("{ s:s, s:o, s:i }", "method", method, "params", params, "id", getpid()); + + str = json_dumps(jexec, 0); + WebcfgDebug(">>>>>>> %s\n", str); + db = g_ovsdb_handle; + + ssize_t len = strlen(str); + if (write(db, str, len) < len) + { + WebcfgError("Error writing to OVSDB: %s\n", strerror(errno)); + goto error; + } + + ssize_t nrd; + nrd = read(db, buf, sizeof(buf)); + if (nrd < 0) + { + goto error; + } + + buf[nrd] = '\0'; + + WebcfgDebug("<<<<<<< %s\n", buf); + + jres = json_loads(buf, JSON_PRESERVE_ORDER, NULL); + +error: + if (str != NULL) free(str); + if (db > 0) ovsdb_close(db); + + return jres; +} + +bool ovsdb_parse_where(json_t *where, char *_str, bool is_parent_where) +{ + bool retval = false; + char str[OVSDB_COL_STR]; + + if (strlen(_str) + 1 > sizeof(str)) + { + /* String too long */ + return false; + } + + cpeabStrncpy(str, _str, sizeof(str)); + + static char *where_delims[] = + { + "==", + "!=", + ":inc:", + ":exc:", + NULL, + }; + + char *lval, *op, *rval; + if (!str_parse_expr(str, where_delims, &lval, &op, &rval)) + { + WebcfgError("Error parsing expression: %s\n", _str); + return false; + } + + /* Convert ovsh opt o ovsdb op */ + if (strcmp(op, ":inc:") == 0) + { + op = "includes"; + } + else if (strcmp(op, ":exc:") == 0) + { + op = "excludes"; + } + else + { + /* Other ovsh operators (where_delims) match 1:1 to ovsdb operators */ + } + + /* + * Create a JSON array from values + */ + json_t *jop = json_array(); + if (jop == NULL) + { + WebcfgError("Unable to create JSON array\n"); + return false; + } + + if (json_array_append_new(jop, json_string(lval)) != 0) + { + WebcfgError("Unable to append JSON array (lval)\n"); + goto error; + } + + if (json_array_append_new(jop, json_string(op)) != 0) + { + WebcfgError("Unable to append JSON array (op)\n"); + goto error; + } + + if (json_array_append_new(jop, json_value(rval)) != 0) + { + WebcfgError("Unable to append JSON array (rval)\n"); + goto error; + } + + if (json_array_append(where, jop) != 0) + { + WebcfgError("Unable to append JSON array (where)\n"); + goto error; + } + + retval = true; + + /* Append to global where expr table, but only if this is a regular where + * statement (not part of a --parent argument) */ + if (!is_parent_where) + { + ovsdb_where_num++; + ovsdb_where_expr = (char**)realloc(ovsdb_where_expr, sizeof(char**) * ovsdb_where_num); + ovsdb_where_expr[ovsdb_where_num-1] = strdup(_str); + } + +error: + if (jop != NULL) json_decref(jop); + + return retval; +} + +bool ovsdb_string_value_get(char *table,json_t *where, int coln, char * colv[],char *result_str, unsigned int len ) + +{ + int handle = -1; + bool ret = false; + json_t *jres = NULL; + json_t *columns = NULL; + json_t *jrows = NULL; + json_t *result = NULL; + + handle = ovsdb_util_init(); + if (handle < 0) { + goto exit; + } + if (!ovsdb_select(table, where, coln, colv, &jres, &columns)) { + WebcfgError("ovsdb_select failed.\n"); + goto exit; + } + if (!ovsdb_json_get_result_rows(jres, &jrows)) { + WebcfgError("ovsdb_json_get_result_rows failed.\n"); + goto exit; + } + + if (jrows != NULL || (json_array_size(jrows) > 0)) { + result = json_object_get(json_array_get(jrows,0),colv[0]); + if (result) + { + if (json_is_string(result)) { + cpeabStrncpy(result_str,json_string_value(result),len); + ret = true; + } else if (json_is_integer(result)) { + snprintf(result_str,len, "%lld",json_integer_value(result)); + ret = true; + } else { + WebcfgError(" Un supported value type.\n"); + } + } + else { + WebcfgError("JROWS is null or Json Array size is less than 0\n"); + } + } +exit : + ovsdb_util_fini(); + return ret; +} diff --git a/src/pods/impl.c b/src/pods/impl.c index 9d37923..2c1e8ab 100644 --- a/src/pods/impl.c +++ b/src/pods/impl.c @@ -16,68 +16,689 @@ #include #include #include +#include #include -#include -#include -#include -#include -#include -#include +#include #include "cpeabs.h" +#include "cpeabs_ovsdb_utils.h" + +#define BFR_SIZE_16 16 +#define BFR_SIZE_32 32 +#define BFR_SIZE_64 64 +#define BFR_SIZE_128 128 +#define BFR_SIZE_256 256 + +#define ACCOUNT_FILE "account" +#define WEBCFG_CFG_FILE "webcfg.json" + +#define MAKE_STR(x) _MAKE_STR(x) +#define _MAKE_STR(x) #x + +#define OSP_PSTORE_ACCOUNT MAKE_STR(PS_FILE_PATH) ACCOUNT_FILE +#define WEBCONFIG_CONFIG_PS_FILE MAKE_STR(PS_FILE_PATH) WEBCFG_CFG_FILE + +#define OSP_PSTORE_REBOOT "/var/run/osp_reboot_reason" +#define WEBCFG_RFC_PARAM "Device.X_RDK_WebConfig.RfcEnable" +#define PARAM_RFC_ENABLE "eRT.com.cisco.spvtg.ccsp.webpa.WebConfigRfcEnable" +#define WEBCFG_URL_PARAM "Device.X_RDK_WebConfig.URL" +#define WEBCFG_SUPPLEMENTARY_TELEMETRY_PARAM "Device.X_RDK_WebConfig.SupplementaryServiceUrls.Telemetry" + +#define WEBCFG_MAX_PARAM_LEN 128 +#define RETURN_OK 0 +#define RETURN_ERR -1 + /*----------------------------------------------------------------------------*/ -/* Macros */ -/*----------------------------------------------------------------------------*/ -/* none */ -/*----------------------------------------------------------------------------*/ -/* Data Structures */ -/*----------------------------------------------------------------------------*/ -/* none */ -/*----------------------------------------------------------------------------*/ -/* File Scoped Variables */ -/*----------------------------------------------------------------------------*/ -/* none */ +char deviceMAC[BFR_SIZE_64] = {'\0'}; /*----------------------------------------------------------------------------*/ /* Function Prototypes */ /*----------------------------------------------------------------------------*/ -/* none */ +void macIDToLower(char macValue[],char macConverted[]); /*----------------------------------------------------------------------------*/ -/* External Functions */ +/* Macros */ /*----------------------------------------------------------------------------*/ -char * getParamValue(char *paramName) +void cpeabStrncpy(char *destStr, const char *srcStr, size_t destSize) +{ + strncpy(destStr, srcStr, destSize-1); + destStr[destSize-1] = '\0'; +} + +bool json_string_value_get(char *key, char* value_str, size_t len) +{ + json_t *json; + json_error_t error; + json_t *value; + bool ret = false; + + json = json_load_file(WEBCONFIG_CONFIG_PS_FILE, 0, &error); + if(!json) + { + WebcfgError("Failed to load %s",WEBCONFIG_CONFIG_PS_FILE); + return ret; + } + + value = json_object_get(json, key); + if (value) + { + cpeabStrncpy(value_str,json_string_value(value),len); + WebcfgInfo("%s : Fetched [%s] = [%s]. \n",__func__,key,value_str); + ret = true; + } + else + { + WebcfgError("Json value is Null.\n"); + } + json_decref(json); + return ret; +} + +bool json_string_value_set(char *key, char* value_str) +{ + json_t *json; + json_error_t error; + json_t *value_json; + bool ret = false; + + json = json_load_file(WEBCONFIG_CONFIG_PS_FILE, 0, &error); + if(!json) + { + WebcfgError("Failed to load %s",WEBCONFIG_CONFIG_PS_FILE); + return ret; + } + + value_json = json_string(value_str); + + if (json_object_set(json, key, value_json) == RETURN_OK) + { + WebcfgInfo("%s : Successfully set : [%s] = [%s] \n",__func__,key,value_str); + if (json_dump_file(json,WEBCONFIG_CONFIG_PS_FILE,0) == RETURN_OK ) + { + WebcfgInfo("Successfully Written to file. \n"); + ret = true; + } + } + else + { + WebcfgError("Json value is Null.\n"); + } + json_decref(value_json); + json_decref(json); + return ret; +} + +void macIDToLower(char macValue[],char macConverted[]) +{ + int i = 0; + int j; + char *token[BFR_SIZE_64]; + char tmp[BFR_SIZE_64]; + + cpeabStrncpy(tmp, macValue,sizeof(tmp)); + token[i] = strtok(tmp, ":"); + if(token[i]!=NULL) + { + cpeabStrncpy(macConverted, token[i],BFR_SIZE_64); + i++; + } + while ((token[i] = strtok(NULL, ":")) != NULL) + { + strncat(macConverted, token[i], 63); + macConverted[63]='\0'; + i++; + } + macConverted[63]='\0'; + for(j = 0; macConverted[j]; j++) + { + macConverted[j] = tolower(macConverted[j]); + } +} + +char* get_deviceMAC() +{ + if(strlen(deviceMAC) != 0) + { + WebcfgDebug("deviceMAC returned %s\n", deviceMAC); + return deviceMAC; + } + + json_t *where = json_array(); + char *table = "Wifi_Inet_State"; + char *colv[] = {"hwaddr"}; + char buff[BFR_SIZE_64]; + char *where_str = "if_name==eth0"; + + if (!ovsdb_parse_where(where,where_str, false)) + { + WebcfgError("Error parsing WHERE statement: %s",where_str); + } + // memset(deviceMAC,0,sizeof(deviceMAC)); + memset(buff,0,sizeof(buff)); + WebcfgDebug("Reaching after memset of buff inside get devicemac\n"); + if (ovsdb_string_value_get(table,where,1,colv,buff,sizeof(buff))) + { + WebcfgDebug("Reaching after ovsdb_string_value_get success inside get devicemac\n"); + macIDToLower(buff, deviceMAC); + WebcfgDebug("deviceMAC returned from lib in converted format is: %s\n",deviceMAC); + return deviceMAC; + } + else + { + WebcfgError("Failed to GetValue for deviceMAC\n"); + return NULL; + } +} + +char * getSerialNumber() +{ + json_t *where = json_array(); + char *table = "AWLAN_Node"; + char *colv[] = {"serial_number"}; + char buff[BFR_SIZE_64]; + char *serialNum = NULL; + + serialNum = malloc(BFR_SIZE_64*sizeof(char)); + if (!serialNum) + { + WebcfgError("%s : serialNum couldnt be assigned with memory\n",__func__); + return NULL; + } + + memset(buff,0,sizeof(buff)); + + if (ovsdb_string_value_get(table,where,1,colv,buff,sizeof(buff))) + { + WebcfgDebug("serialNum returned from lib is %s\n", buff); + cpeabStrncpy(serialNum,buff,BFR_SIZE_64*sizeof(char)); + return serialNum; + } + else + { + WebcfgError("Failed to GetValue for serialNum\n"); + return NULL; + } +} + +char * getDeviceBootTime() +{ + json_t *where = json_array(); + char *table = "AWLAN_Node"; + char *colv[] = {"boot_time"}; + char buff[BFR_SIZE_64]; + char *bootTime = NULL; + + bootTime = malloc(BFR_SIZE_64*sizeof(char)); + if (!bootTime) + { + WebcfgError("%s : bootTime couldnt be assigned with memory\n",__func__); + return NULL; + } + + memset(buff,0,sizeof(buff)); + + if (ovsdb_string_value_get(table,where,1,colv,buff,sizeof(buff))) + { + WebcfgDebug("bootTime returned from lib is %s\n", buff); + cpeabStrncpy(bootTime,buff,BFR_SIZE_64*sizeof(char)); + return bootTime; + } + else + { + WebcfgError("Failed to GetValue for bootTime\n"); + return NULL; + } +} + +char * getProductClass() +{ + char *productClass = NULL; + productClass = malloc(BFR_SIZE_16*sizeof(char)); + if (!productClass) + { + WebcfgError("%s : productClass couldnt be assigned with memory\n",__func__); + return NULL; + } + cpeabStrncpy(productClass,"XE2",BFR_SIZE_16*sizeof(char)); + return productClass; +} + +char * getModelName() +{ + json_t *where = json_array(); + char *table = "AWLAN_Node"; + char *colv[] = {"model"}; + char buff[BFR_SIZE_64]; + char *modelName = NULL; + + modelName = malloc(BFR_SIZE_64*sizeof(char)); + if (!modelName) + { + WebcfgError("%s : modelName couldnt be assigned with memory\n",__func__); + return NULL; + } + + memset(buff,0,sizeof(buff)); + + if (ovsdb_string_value_get(table,where,1,colv,buff,sizeof(buff))) + { + WebcfgDebug("modelName returned from lib is %s\n", buff); + cpeabStrncpy(modelName,buff,BFR_SIZE_64*sizeof(char)); + return modelName; + } + else + { + WebcfgError("Failed to GetValue for modelName\n"); + return NULL; + } +} + +char * getFirmwareVersion() +{ + json_t *where = json_array(); + char *table = "AWLAN_Node"; + char *colv[] = {"firmware_version"}; + char buff[BFR_SIZE_64]; + char *firmware_version = NULL; + + firmware_version = malloc(BFR_SIZE_64*sizeof(char)); + if (!firmware_version) + { + WebcfgError("%s : firmware_version couldnt be assigned with memory\n",__func__); + return NULL; + } + + memset(buff,0,sizeof(buff)); + + if (ovsdb_string_value_get(table,where,1,colv,buff,sizeof(buff))) + { + WebcfgDebug("firmwareVersion returned from lib is %s\n", buff); + cpeabStrncpy(firmware_version,buff,BFR_SIZE_64*sizeof(char)); + return firmware_version; + } + else + { + WebcfgError("Failed to GetValue for firmwareVersion\n"); + return NULL; + } +} + +char * getConnClientParamName() +{ + return NULL; +} + +char * getRebootReason() +{ + FILE *rebptr = NULL; + char reboot_type[BFR_SIZE_64]; + char reboot_str[BFR_SIZE_32]; + char reboot_osprsn[BFR_SIZE_128]; + char reboot_fileresp[BFR_SIZE_256]; + char * reboot_reason = NULL; + + reboot_reason = malloc(BFR_SIZE_64*sizeof(char)); + if (!reboot_reason) + { + WebcfgError("%s : reboot_reason couldnt be assigned with memory\n",__func__); + return NULL; + } + + memset(reboot_type,0,sizeof(reboot_type)); + memset(reboot_str,0,sizeof(reboot_str)); + memset(reboot_fileresp, 0, sizeof(reboot_fileresp)); + memset(reboot_osprsn, 0, sizeof(reboot_osprsn)); + if ((rebptr = fopen(OSP_PSTORE_REBOOT, "r")) == NULL) + { + WebcfgError("Error! File %s cannot be opened.\n", OSP_PSTORE_REBOOT); + return NULL; + } + if( fgets(reboot_fileresp, sizeof(reboot_fileresp), rebptr) != NULL ) + { + sscanf(reboot_fileresp, "%31s %63s %127[^\n]", reboot_str, reboot_type, reboot_osprsn); + } + else + { + WebcfgError("Error! Output from file %s couldnt be parsed.", OSP_PSTORE_REBOOT); + return NULL; + } + cpeabStrncpy(reboot_reason,reboot_type,BFR_SIZE_64*sizeof(char)); + if (strlen(reboot_reason) > 0) + { + WebcfgDebug("Reboot reason returned from lib is %s\n", reboot_reason); + return reboot_reason; + } + else + { + WebcfgError("Failed to GetValue for reboot_reason\n"); + return NULL; + } +} + +char * cutting_delimiters(char *pstore_content, char * PATTERN1, char *PATTERN2) +{ + char *start, *end; + char *target = NULL; + if((start = strstr(pstore_content, PATTERN1))) + { + start += strlen(PATTERN1); + if ((end = strstr(start, PATTERN2))) + { + target = (char *)malloc(end-start+1); + memcpy(target,start,end-start); + target[end-start] = '\0'; + } + } + return target; +} + +int get_id_pstore(int id_chk, char *id_type) { - UNUSED(paramName); - return NULL; + char pstore_content[BFR_SIZE_256]; + char acc_id[BFR_SIZE_64]; + char partner_id[BFR_SIZE_64]; + char *acc_id_ret = NULL; + char *partner_id_ret = NULL; + int ret = RETURN_ERR; + + FILE *fptr = NULL; + if ((fptr = fopen(OSP_PSTORE_ACCOUNT, "r")) == NULL) + { + WebcfgError("Error! File %s cannot be opened.",OSP_PSTORE_ACCOUNT); + return ret; + } + memset(pstore_content,0,sizeof(pstore_content)); + fscanf(fptr, "%[^\n]", pstore_content); + WebcfgDebug("Data from the file:\n%s\n", pstore_content); + fclose(fptr); + + memset(acc_id,0,sizeof(acc_id)); + memset(partner_id,0,sizeof(partner_id)); + + if((strchr(pstore_content, ',') != NULL) && (strlen(pstore_content) > 0)) + { + sscanf(pstore_content, "%*[^:]%*c%[^,]%*[^:]%*c%[^}]", acc_id, partner_id); + acc_id_ret = cutting_delimiters(acc_id, "\"", "\""); + partner_id_ret = cutting_delimiters(partner_id, "\"", "\""); + } + else if(strlen(pstore_content) > 0) + { + sscanf(pstore_content, "%*[^:]%*c%[^}]", acc_id); + acc_id_ret = cutting_delimiters(acc_id, "\"", "\""); + } + else + { + WebcfgError("Error!The file is present but is empty!\n"); + return ret; + } + if ((id_chk == 1) && (strlen(partner_id) > 0)) + { + cpeabStrncpy(id_type,partner_id_ret,BFR_SIZE_64*sizeof(char)); + ret = RETURN_OK; + return ret; + } + else + { + WebcfgError("Partner ID couldnt be parsed\n"); + return ret; + } + + if ((id_chk == 0) && (strlen(acc_id) > 0)) + { + cpeabStrncpy(id_type,acc_id_ret,BFR_SIZE_64*sizeof(char)); + ret = RETURN_OK; + return ret; + } + else + { + WebcfgError("Account ID couldnt be parsed\n"); + return ret; + } + +} +char * getPartnerID() +{ + int partner_id_chk = 1; + char *partner_id = NULL; + int ret_val; + + partner_id = malloc(BFR_SIZE_64*sizeof(char)); + if (!partner_id) + { + WebcfgError("%s : partner_id couldnt be assigned with memory\n",__func__); + return NULL; + } + ret_val = get_id_pstore(partner_id_chk,partner_id); + if (ret_val != RETURN_ERR) + { + WebcfgDebug("PartnerID returned from lib is %s\n", partner_id); + return partner_id; + } + else + { + WebcfgError("Failed to GetValue for PartnerID\n"); + return NULL; + } +} + +char * getAccountID() +{ + int acc_id_chk = 0; + char *account_id = NULL; + int ret_val; + + account_id = malloc(BFR_SIZE_64*sizeof(char)); + if (!account_id) + { + WebcfgError("%s : account_id couldnt be assigned with memory\n",__func__); + return NULL; + } + ret_val = get_id_pstore(acc_id_chk,account_id); + if (ret_val != RETURN_ERR) + { + WebcfgDebug("AccountID returned from lib is %s\n", account_id); + return account_id; + } + else + { + WebcfgError("Failed to GetValue for AccountID\n"); + return NULL; + } +} + +char * getFirmwareUpgradeStartTime() +{ + char * start_time = NULL; + + start_time = malloc(BFR_SIZE_32*sizeof(char)); + if (!start_time) + { + WebcfgError("%s : start_time couldnt be assigned with memory\n",__func__); + return NULL; + } + + cpeabStrncpy(start_time,"7200",strlen("7200")+1); + return start_time; +} + +char * getFirmwareUpgradeEndTime() +{ + char * end_time = NULL; + + end_time = malloc(BFR_SIZE_32*sizeof(char)); + if (!end_time) + { + WebcfgError("%s : end_time couldnt be assigned with memory\n",__func__); + return NULL; + } + + cpeabStrncpy(end_time,"14400",strlen("14400")+1); + return end_time; +} + +int Get_Webconfig_URL( char *pString) +{ + char url[128]; + int ret = RETURN_ERR; + + memset(url,0,sizeof(url)); + + if (json_string_value_get(WEBCFG_URL_PARAM,url, sizeof(url))) + { + cpeabStrncpy(pString,url,sizeof(url)); + WebcfgDebug("Successfully fetched Webconfig URL : [%s]. \n", url); + ret = RETURN_OK; + } + else{ + WebcfgError("Error! Failed to fetch Webconfig URL\n"); + } + return ret; +} + +int Set_Webconfig_URL( char *pString) +{ + int ret = RETURN_ERR; + + if (json_string_value_set(WEBCFG_URL_PARAM, pString) == true) + { + WebcfgDebug("Successfully set Webconfig URL \n"); + ret = RETURN_OK; + } + else{ + WebcfgError("Error! Failed to set Webconfig URL\n"); + } + return ret; +} + +int Get_Supplementary_URL( char *name, char *pString) +{ + char url[128]; + int ret = RETURN_ERR; + + memset(url,0,sizeof(url)); + + if (json_string_value_get(WEBCFG_SUPPLEMENTARY_TELEMETRY_PARAM,url, sizeof(url))) + { + WebcfgDebug("Successfully fetched Webconfig Supp URL : [%s] \n", url); + cpeabStrncpy(pString,url,sizeof(url)); + ret = RETURN_OK; + } + else{ + WebcfgError("Error! Failed to fetch Webconfig Supp URL\n"); + } + return ret; +} + +int Set_Supplementary_URL( char *name, char *pString) +{ + int ret = RETURN_ERR; + + if (json_string_value_set(WEBCFG_SUPPLEMENTARY_TELEMETRY_PARAM, pString) == true) + { + WebcfgDebug("Successfully set Webconfig URL \n"); + ret = RETURN_OK; + } + else{ + WebcfgError("Error! Failed to set Webconfig Supp URL\n"); + } + return ret; } /** - * To persist TR181 parameter values in DB. + * To persist TR181 parameter values in PSM DB. */ int rbus_StoreValueIntoDB(char *paramName, char *value) { - UNUSED(paramName); - UNUSED(value); - return 1; -} + int ret = RETURN_ERR; + if (strncmp(paramName,WEBCFG_RFC_PARAM,WEBCFG_MAX_PARAM_LEN) == 0) + { + if (json_string_value_set(WEBCFG_RFC_PARAM,value) == RETURN_OK) + { + WebcfgDebug("%s : Successfully stored [%s] = [%s]. \n",__func__,WEBCFG_RFC_PARAM,value); + ret = RETURN_OK; + } + } + else if (strncmp(paramName,PARAM_RFC_ENABLE,WEBCFG_MAX_PARAM_LEN) == 0) + { + if (json_string_value_set(PARAM_RFC_ENABLE,value) == RETURN_OK) + { + WebcfgDebug("%s : Successfully stored [%s] = [%s]. \n",__func__,PARAM_RFC_ENABLE,value); + ret = RETURN_OK; + } + } + else if (strncmp(paramName,WEBCFG_URL_PARAM,WEBCFG_MAX_PARAM_LEN) == 0) + { + if (Set_Webconfig_URL(value) == RETURN_OK) + { + WebcfgDebug("%s : Successfully stored [%s] = [%s]. \n",__func__,WEBCFG_URL_PARAM,value); + ret = RETURN_OK; + } + } + else if (strncmp(paramName,WEBCFG_SUPPLEMENTARY_TELEMETRY_PARAM,WEBCFG_MAX_PARAM_LEN) == 0) + { + if (Set_Supplementary_URL(NULL,value) == RETURN_OK) + { + WebcfgDebug("%s : Successfully stored [%s] = [%s]. \n",__func__,WEBCFG_SUPPLEMENTARY_TELEMETRY_PARAM,value); + ret = RETURN_OK; + } + } + else { + WebcfgError("Invalid Param Name \n"); + } + return ret; +} /** - * To fetch TR181 parameter values from DB. + * To fetch TR181 parameter values from PSM DB. */ int rbus_GetValueFromDB( char* paramName, char** paramValue) { - UNUSED(paramName); - UNUSED(paramValue); - return 1; + char value_str[256]; + int ret = RETURN_ERR; + + memset(value_str,0,sizeof(value_str)); + + if (strncmp(paramName,WEBCFG_RFC_PARAM,WEBCFG_MAX_PARAM_LEN) == 0) + { + if (json_string_value_get(WEBCFG_RFC_PARAM,value_str, sizeof(value_str))) + { + *paramValue = strdup(value_str); + WebcfgDebug("%s : Successfully fetched [%s] = [%s]. \n",__func__,WEBCFG_RFC_PARAM,*paramValue); + ret = RETURN_OK; + } + } + else if (strncmp(paramName,PARAM_RFC_ENABLE,WEBCFG_MAX_PARAM_LEN) == 0) + { + if (json_string_value_get(PARAM_RFC_ENABLE,value_str, sizeof(value_str))) + { + *paramValue = strdup(value_str); + WebcfgDebug("%s : Successfully fetched [%s] = [%s]. \n",__func__,PARAM_RFC_ENABLE,*paramValue); + ret = RETURN_OK; + } + } + else if (strncmp(paramName,WEBCFG_URL_PARAM,WEBCFG_MAX_PARAM_LEN) == 0) + { + if (Get_Webconfig_URL(value_str) == RETURN_OK) + { + *paramValue = strdup(value_str); + WebcfgDebug("%s : Successfully fetched [%s] = [%s]. \n",__func__,WEBCFG_URL_PARAM,*paramValue); + ret = RETURN_OK; + } + } + else if (strncmp(paramName,WEBCFG_SUPPLEMENTARY_TELEMETRY_PARAM,WEBCFG_MAX_PARAM_LEN) == 0) + { + if (Get_Supplementary_URL(NULL,value_str) == RETURN_OK) + { + *paramValue = strdup(value_str); + WebcfgDebug("%s : Successfully fetched [%s] = [%s]. \n",__func__,WEBCFG_SUPPLEMENTARY_TELEMETRY_PARAM,*paramValue); + ret = RETURN_OK; + } + } + else + { + WebcfgError("Invalid Param Name \n"); + } + return ret; } -void getValues_rbus(const char *paramName[], const unsigned int paramCount, int index, money_trace_spans *timeSpan, param_t ***paramArr, int *retValCount, WDMP_STATUS *retStatus) +int rbus_waitUntilSystemReady() { - UNUSED(paramName); - UNUSED(paramCount); - UNUSED(index); - UNUSED(timeSpan); - UNUSED(paramArr); - UNUSED(retValCount); - UNUSED(retStatus); - return; + return RETURN_OK; } - From e5cea2d1f68701705c07e97b6675433476104d92 Mon Sep 17 00:00:00 2001 From: debasya Date: Fri, 10 Dec 2021 18:55:03 +0530 Subject: [PATCH 26/35] Update impl.c --- src/pods/impl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pods/impl.c b/src/pods/impl.c index 2c1e8ab..908fdc7 100644 --- a/src/pods/impl.c +++ b/src/pods/impl.c @@ -48,7 +48,7 @@ #define RETURN_ERR -1 /*----------------------------------------------------------------------------*/ -char deviceMAC[BFR_SIZE_64] = {'\0'}; +char deviceMAC[BFR_SIZE_64]; /*----------------------------------------------------------------------------*/ /* Function Prototypes */ /*----------------------------------------------------------------------------*/ @@ -170,7 +170,7 @@ char* get_deviceMAC() { WebcfgError("Error parsing WHERE statement: %s",where_str); } - // memset(deviceMAC,0,sizeof(deviceMAC)); + memset(deviceMAC,0,sizeof(deviceMAC)); memset(buff,0,sizeof(buff)); WebcfgDebug("Reaching after memset of buff inside get devicemac\n"); if (ovsdb_string_value_get(table,where,1,colv,buff,sizeof(buff))) From 508895c418e6608400c3b11e6e2834e6037dc2cc Mon Sep 17 00:00:00 2001 From: Guru Chandru Date: Thu, 16 Dec 2021 19:19:18 +0530 Subject: [PATCH 27/35] Cmake and meson integration --- include/cpeabs/cpeabs.h | 10 ++++ include/cpeabs/meson.build | 27 +++++++++++ include/cpeabs/ver.h.in | 27 +++++++++++ meson.build | 93 ++++++++++++++++++++++++++++++++++++++ src/common.c | 39 ++++++++++++++++ tests/test_common.c | 72 +++++++++++++++++++++++++++++ 6 files changed, 268 insertions(+) create mode 100644 include/cpeabs/cpeabs.h create mode 100644 include/cpeabs/meson.build create mode 100644 include/cpeabs/ver.h.in create mode 100644 meson.build create mode 100644 src/common.c create mode 100644 tests/test_common.c diff --git a/include/cpeabs/cpeabs.h b/include/cpeabs/cpeabs.h new file mode 100644 index 0000000..2bc5f73 --- /dev/null +++ b/include/cpeabs/cpeabs.h @@ -0,0 +1,10 @@ +/* SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC */ +/* SPDX-License-Identifier: Apache-2.0 */ + +#ifndef __CPEABS_H__ +#define __CPEABS_H__ + +#include +#include + +#endif diff --git a/include/cpeabs/meson.build b/include/cpeabs/meson.build new file mode 100644 index 0000000..e7fa3b0 --- /dev/null +++ b/include/cpeabs/meson.build @@ -0,0 +1,27 @@ +# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC +# SPDX-License-Identifier: Apache-2.0 + +version = meson.project_version() +version_arr = version.split('.') +major = version_arr[0].to_int() +minor = version_arr[1].to_int() +patch = version_arr[2].to_int() + +hex = '0123456789abcdef' +ver = '0x@0@@1@@2@@3@@4@@5@' +bitwise = ver.format(hex[major / 16], hex[major % 16], + hex[minor / 16], hex[minor % 16], + hex[patch / 16], hex[patch % 16]) + +cfg = configuration_data() +cfg.set( meson.project_name()+'_VERSION', version) +cfg.set( meson.project_name()+'_VERSION_MAJOR', major) +cfg.set( meson.project_name()+'_VERSION_MINOR', minor) +cfg.set( meson.project_name()+'_VERSION_PATCH', patch) +cfg.set( meson.project_name()+'_BITWISE_VERSION', bitwise) + +ver_h = configure_file(input: 'ver.h.in', + output: 'ver.h', + configuration: cfg) + +headers = files(['cpeabs.h']) diff --git a/include/cpeabs/ver.h.in b/include/cpeabs/ver.h.in new file mode 100644 index 0000000..d7e72f1 --- /dev/null +++ b/include/cpeabs/ver.h.in @@ -0,0 +1,27 @@ +/* SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC */ +/* SPDX-License-Identifier: Apache-2.0 */ + +#ifndef __CPEABS_VERSION_H__ +#define __CPEABS_VERSION_H__ 1 + +#define CPEABS_VERSION "@cpeabs_VERSION@" + +#define CPEABS_VERSION_MAJOR @cpeabs_VERSION_MAJOR @ +#define CPEABS_VERSION_MINOR @cpeabs_VERSION_MINOR @ +#define CPEABS_VERSION_PATCH @cpeabs_VERSION_PATCH @ + +/* This is the numeric version of the cpeabs version number, meant for easier + * parsing and comparisons by programs. The CPEABS_VERSION_NUM define + * will always follow this syntax: + * + * 0xAABBCC + * + * Where AA, BB, and CC are each major version, minor version, patch in hex + * using 8 bits each. + * + * It should be safe to compare two different versions with the greater number + * being the newer version. + */ +#define CPEABS_VERSION_NUM @cpeabs_BITWISE_VERSION @ + +#endif diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..3b74dda --- /dev/null +++ b/meson.build @@ -0,0 +1,93 @@ +# Meson build file +# +# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC +# SPDX-License-Identifier: Apache-2.0 + +project('cpeabs', 'c', + version: '0.0.0', + license: ['Apache-2.0'], + default_options: ['c_std=c99', + 'b_coverage=true']) + +if not meson.is_subproject() + # We want strict flags + warning_level = 3 # -Wall + werror = true +endif + +################################################################################ +# Common variable definitions +################################################################################ + +inc_base = 'include/'+meson.project_name() + +################################################################################ +# Generate the version header file +################################################################################ + +subdir('include/'+meson.project_name()) + +install_headers([headers, ver_h], subdir: meson.project_name()) + +################################################################################ +# Define the libraries +################################################################################ + +inc = include_directories(inc_base) + +sources = ['src/common.c'] + +libcpeabs = library(meson.project_name(), + sources, + include_directories: inc, + install: true) + +################################################################################ +# Define the tests +################################################################################ + +if not meson.is_subproject() + test_args = ['-fprofile-arcs', '-ftest-coverage', '-O0'] + + cunit_dep = dependency('cunit') + + tests = [ + ['test common', 'test_common'], + ] + + foreach test : tests + test(test[0], + executable(test[1], ['tests/'+test[1]+'.c'], + include_directories: inc, + dependencies: cunit_dep, + install: false, + link_args: test_args, + link_with: libcpeabs)) + endforeach + + add_test_setup('valgrind', + is_default: true, + exe_wrapper: [ 'valgrind', + '--leak-check=full', + '--error-exitcode=1' ], + timeout_multiplier: 2) +endif + +################################################################################ +# Add the license check target +################################################################################ + +reuse_bin = find_program('reuse', required: false) +if reuse_bin.found() + custom_target('license', + command: [reuse_bin, 'lint'], + build_always_stale: true, + output: ['license']) +endif + +libcpeabs_dep = declare_dependency(include_directories: ['include'], + link_with: libcpeabs) + +if meson.version().version_compare('>=0.54.0') + meson.override_dependency(meson.project_name(), libcpeabs_dep) +endif diff --git a/src/common.c b/src/common.c new file mode 100644 index 0000000..c571421 --- /dev/null +++ b/src/common.c @@ -0,0 +1,39 @@ +/* SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC */ +/* SPDX-License-Identifier: Apache-2.0 */ + +#include +#include +#include + +/*----------------------------------------------------------------------------*/ +/* Macros */ +/*----------------------------------------------------------------------------*/ +/* none */ + +/*----------------------------------------------------------------------------*/ +/* Data Structures */ +/*----------------------------------------------------------------------------*/ +/* none */ + +/*----------------------------------------------------------------------------*/ +/* File Scoped Variables */ +/*----------------------------------------------------------------------------*/ +/* none */ + +/*----------------------------------------------------------------------------*/ +/* Function Prototypes */ +/*----------------------------------------------------------------------------*/ +/* none */ + +/*----------------------------------------------------------------------------*/ +/* Internal functions */ +/*----------------------------------------------------------------------------*/ +/* none */ + +/*----------------------------------------------------------------------------*/ +/* External Functions */ +/*----------------------------------------------------------------------------*/ +void do_something() +{ + printf("I do something well.\n"); +} diff --git a/tests/test_common.c b/tests/test_common.c new file mode 100644 index 0000000..b621357 --- /dev/null +++ b/tests/test_common.c @@ -0,0 +1,72 @@ +/* SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC */ +/* SPDX-License-Identifier: Apache-2.0 */ + +#include +#include +#include +#include + +/*----------------------------------------------------------------------------*/ +/* Macros */ +/*----------------------------------------------------------------------------*/ +/* none */ + +/*----------------------------------------------------------------------------*/ +/* Data Structures */ +/*----------------------------------------------------------------------------*/ +/* none */ + +/*----------------------------------------------------------------------------*/ +/* File Scoped Variables */ +/*----------------------------------------------------------------------------*/ +/* none */ + +/*----------------------------------------------------------------------------*/ +/* Function Prototypes */ +/*----------------------------------------------------------------------------*/ +extern void do_something(); + +/*----------------------------------------------------------------------------*/ +/* Tests */ +/*----------------------------------------------------------------------------*/ +void test_do_something() +{ + do_something(); +} + + +/*----------------------------------------------------------------------------*/ +/* Testing Framework */ +/*----------------------------------------------------------------------------*/ + +void add_suites(CU_pSuite *suite) +{ + *suite = CU_add_suite("common encoding tests", NULL, NULL); + CU_add_test(*suite, "Test do_something", test_do_something); +} + +int main(void) +{ + unsigned rv = 1; + CU_pSuite suite = NULL; + + if (CUE_SUCCESS == CU_initialize_registry()) { + add_suites(&suite); + + if (NULL != suite) { + CU_basic_set_mode(CU_BRM_VERBOSE); + CU_basic_run_tests(); + printf("\n"); + CU_basic_show_failures(CU_get_failure_list()); + printf("\n\n"); + rv = CU_get_number_of_tests_failed(); + } + + CU_cleanup_registry(); + } + + if (0 != rv) { + return 1; + } + return 0; +} From ac273c64ee854299cea7cfe5f204e5285e0b80e1 Mon Sep 17 00:00:00 2001 From: retheesh-sasidharan <96306517+retheesh-sasidharan@users.noreply.github.com> Date: Fri, 17 Dec 2021 17:14:52 +0000 Subject: [PATCH 28/35] Sky Specific mac address change Added sky specific code for accessing device mac address --- src/rdkb/impl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rdkb/impl.c b/src/rdkb/impl.c index e6a63fb..081432d 100644 --- a/src/rdkb/impl.c +++ b/src/rdkb/impl.c @@ -48,6 +48,8 @@ #define DEVICE_MAC "Device.Ethernet.Interface.5.MACAddress" #elif defined(RDKB_EMU) #define DEVICE_MAC "Device.DeviceInfo.X_COMCAST-COM_WAN_MAC" +#elif defined(_HUB4_PRODUCT_REQ_) +#define DEVICE_MAC "Device.DeviceInfo.X_COMCAST-COM_WAN_MAC" #else #define DEVICE_MAC "Device.X_CISCO_COM_CableModem.MACAddress" #endif From 038902eefd9215afcf63cdc26ffffdac022b64ce Mon Sep 17 00:00:00 2001 From: Guru Chandru Date: Fri, 17 Dec 2021 12:14:34 +0530 Subject: [PATCH 29/35] wrapdb integration --- README.md | 8 +++ include/cpeabs.h | 18 +----- include/cpeabs/cpeabs.h | 5 ++ include/cpeabs_ovsdb_utils.h | 17 +----- meson.build | 57 +++++++++++++++++-- src/CMakeLists.txt | 4 +- src/common.c | 25 +++++++- subprojects/cimplog.wrap | 9 +++ subprojects/cjson.wrap | 11 ++++ subprojects/rtMessage.wrap | 9 +++ subprojects/wdmp.wrap | 9 +++ workaround.sh | 22 +++++++ wrapdb/cimplog/meson.build | 7 +++ .../include-workaround-meson/rbus/meson.build | 9 +++ wrapdb/rbus/include/meson.build | 6 ++ wrapdb/rbus/meson.build | 11 ++++ wrapdb/rbuscore/meson.build | 8 +++ .../rtmessage/meson.build | 9 +++ wrapdb/rtMessage/meson.build | 53 +++++++++++++++++ wrapdb/wdmp/meson.build | 7 +++ 20 files changed, 265 insertions(+), 39 deletions(-) create mode 100644 subprojects/cimplog.wrap create mode 100644 subprojects/cjson.wrap create mode 100644 subprojects/rtMessage.wrap create mode 100644 subprojects/wdmp.wrap create mode 100755 workaround.sh create mode 100644 wrapdb/cimplog/meson.build create mode 100644 wrapdb/rbus/include-workaround-meson/rbus/meson.build create mode 100644 wrapdb/rbus/include/meson.build create mode 100644 wrapdb/rbus/meson.build create mode 100644 wrapdb/rbuscore/meson.build create mode 100644 wrapdb/rtMessage/include-workaround-meson/rtmessage/meson.build create mode 100644 wrapdb/rtMessage/meson.build create mode 100644 wrapdb/wdmp/meson.build diff --git a/README.md b/README.md index 9e581c2..335f4cc 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,12 @@ An abstraction layer for consumer preference equipment systems. # Building and Testing Instructions ``` +./workaround.sh +meson build +cd build +ninja all test coverage +firefox meson-logs/coveragereport/index.html + Use CFLAG -DPLATFORM=DEVICE_GATEWAY to build for RDKB platform Use CFLAG -DPLATFORM=DEVICE_EXTENDER to build for POD platform @@ -28,3 +34,5 @@ make make test ``` +The `workaround.sh` script makes it so we don't need to add the rbus stuff to the +upstream wrapdb. diff --git a/include/cpeabs.h b/include/cpeabs.h index c3d8c4a..c076960 100644 --- a/include/cpeabs.h +++ b/include/cpeabs.h @@ -1,18 +1,6 @@ -/* - * Copyright 2021 Comcast Cable Communications Management, LLC - * - * 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. - */ +/* SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC */ +/* SPDX-License-Identifier: Apache-2.0 */ + #ifndef __CPEABS_H__ #define __CPEABS_H__ diff --git a/include/cpeabs/cpeabs.h b/include/cpeabs/cpeabs.h index 2bc5f73..7a3eb28 100644 --- a/include/cpeabs/cpeabs.h +++ b/include/cpeabs/cpeabs.h @@ -6,5 +6,10 @@ #include #include +#include +#include +#include +#include +#include #endif diff --git a/include/cpeabs_ovsdb_utils.h b/include/cpeabs_ovsdb_utils.h index 0552975..6b8e7ce 100644 --- a/include/cpeabs_ovsdb_utils.h +++ b/include/cpeabs_ovsdb_utils.h @@ -1,18 +1,5 @@ -/* - * Copyright 2021 Comcast Cable Communications Management, LLC - * - * 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. - */ +/* SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC */ +/* SPDX-License-Identifier: Apache-2.0 */ #include diff --git a/meson.build b/meson.build index 3b74dda..e167eb7 100644 --- a/meson.build +++ b/meson.build @@ -5,6 +5,7 @@ project('cpeabs', 'c', version: '0.0.0', + meson_version: '>=0.53', license: ['Apache-2.0'], default_options: ['c_std=c99', 'b_coverage=true']) @@ -15,11 +16,49 @@ if not meson.is_subproject() werror = true endif +script = join_paths(meson.source_root(), 'workaround.sh') + +r = run_command('/bin/sh', script) +if r.returncode() != 0 + message('script failed') +endif + +output = r.stdout().strip() +errortxt = r.stderr().strip() + +prefix = get_option('prefix') + +################################################################################ +# Dependencies +################################################################################ + +if meson.version().version_compare('>=0.54.0') +libcjson_dep = dependency('libcjson', version: '>=1.7.14', fallback: ['cjson']) +libcimplog_dep = dependency('libcimplog') +libwdmp_dep = dependency('libwdmp') +librtMessage_dep = dependency('librtMessage') +librbuscore_dep = dependency('librbuscore') +librbus_dep = dependency('librbus') +else +warning('You are running an older version of meson.') +warning('In order for dependency management to be supported you need a newer version of meson (0.54+)') +# For older versions of meson, you need to have the upstream dependencies installed +# in the correct locations. +libcjson_dep = dependency('libcjson') +libcimplog_dep = dependency('libcimplog') +libwdmp_dep = dependency('libwdmp') +librtMessage_dep = dependency('librtMessage') +librbuscore_dep = dependency('librbuscore') +librbus_dep = dependency('librbus') +endif + +all_dep = [libcjson_dep, librtMessage_dep, librbuscore_dep, librbus_dep, libcimplog_dep, libwdmp_dep] + ################################################################################ # Common variable definitions ################################################################################ -inc_base = 'include/'+meson.project_name() +inc_base = ['include/'+meson.project_name()] ################################################################################ # Generate the version header file @@ -27,20 +66,30 @@ inc_base = 'include/'+meson.project_name() subdir('include/'+meson.project_name()) -install_headers([headers, ver_h], subdir: meson.project_name()) +install_headers(['include/'+meson.project_name()+'/cpeabs.h', ver_h], subdir: meson.project_name()) ################################################################################ # Define the libraries ################################################################################ -inc = include_directories(inc_base) +inc = include_directories([inc_base]) +src_args = ['-lcjson', '-lpthread'] sources = ['src/common.c'] libcpeabs = library(meson.project_name(), sources, include_directories: inc, - install: true) + dependencies: all_dep, + install: true, + link_args: src_args) + +executable(meson.project_name(), + sources, + include_directories: inc, + dependencies: all_dep, + install: true, + link_args: src_args) ################################################################################ # Define the tests diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4cfeb38..44c75fa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,10 +26,10 @@ endif () if (PLATFORM STREQUAL "DEVICE_GATEWAY") set(SOURCES rdkb/impl.c) -set(HEADERS ${PROJECT_SOURCE_DIR}/include/cpeabs.h) +set(HEADERS ${PROJECT_SOURCE_DIR}/include/cpeabs/cpeabs.h) elseif (PLATFORM STREQUAL "DEVICE_EXTENDER") set(SOURCES pods/impl.c pods/cpeabs_ovsdb_utils.c) -set(HEADERS ${PROJECT_SOURCE_DIR}/include/cpeabs_ovsdb_utils.h ${PROJECT_SOURCE_DIR}/include/cpeabs.h) +set(HEADERS ${PROJECT_SOURCE_DIR}/include/cpeabs_ovsdb_utils.h ${PROJECT_SOURCE_DIR}/include/cpeabs/cpeabs.h) add_definitions(-DPS_FILE_PATH=${PS_FILE_PATH}) else () set(SOURCES pc/impl.c) diff --git a/src/common.c b/src/common.c index c571421..d641530 100644 --- a/src/common.c +++ b/src/common.c @@ -3,8 +3,13 @@ #include #include +#include #include - +#include +//#include "../../subprojects/wdmp/src/wdmp-c.h" +#include +#include +#include /*----------------------------------------------------------------------------*/ /* Macros */ /*----------------------------------------------------------------------------*/ @@ -23,8 +28,7 @@ /*----------------------------------------------------------------------------*/ /* Function Prototypes */ /*----------------------------------------------------------------------------*/ -/* none */ - +void do_something(); /*----------------------------------------------------------------------------*/ /* Internal functions */ /*----------------------------------------------------------------------------*/ @@ -33,6 +37,21 @@ /*----------------------------------------------------------------------------*/ /* External Functions */ /*----------------------------------------------------------------------------*/ +int main() +{ + /* req_struct *req = NULL; + req = (req_struct *) malloc (sizeof(req_struct)); + do_something();*/ + //wdmp_parse_generic_request("Hi", WDMP_TR181, &req); + rtMessageHeader* testrt = NULL; + testrt = (rtMessageHeader*)malloc(sizeof(rtMessageHeader)); + + rtMessageHeader_Init(testrt); + + do_something(); + return 0; +} + void do_something() { printf("I do something well.\n"); diff --git a/subprojects/cimplog.wrap b/subprojects/cimplog.wrap new file mode 100644 index 0000000..ad71f48 --- /dev/null +++ b/subprojects/cimplog.wrap @@ -0,0 +1,9 @@ +[wrap-git] +directory = cimplog + +url = https://github.com/Comcast/cimplog.git +revision = 8a5fb3c2f182241d17f5342bea5b7688c28cd1fd +patch_filename = cimplog.tar.gz + +[provide] +libcimplog = libcimplog_dep diff --git a/subprojects/cjson.wrap b/subprojects/cjson.wrap new file mode 100644 index 0000000..26a0097 --- /dev/null +++ b/subprojects/cjson.wrap @@ -0,0 +1,11 @@ +[wrap-file] +directory = cJSON-1.7.14 +source_url = https://github.com/DaveGamble/cJSON/archive/refs/tags/v1.7.14.tar.gz +source_filename = v1.7.14.tar.gz +source_hash = fb50a663eefdc76bafa80c82bc045af13b1363e8f45cec8b442007aef6a41343 +patch_filename = cjson_1.7.14-1_patch.zip +patch_url = https://wrapdb.mesonbuild.com/v2/cjson_1.7.14-1/get_patch +patch_hash = 82d7a029637bdd6696a89075907581768e7088c20b1c69f400cb6e15e716d803 + +[provide] +libcjson = libcjson_dep diff --git a/subprojects/rtMessage.wrap b/subprojects/rtMessage.wrap new file mode 100644 index 0000000..68eab43 --- /dev/null +++ b/subprojects/rtMessage.wrap @@ -0,0 +1,9 @@ +[wrap-git] +directory = rtMessage + +url = https://github.com/guruchandru/rdk-rtmessage.git +revision = rdk-next +patch_filename = rtMessage.tar.gz + +[provide] +librtMessage = librtMessage_dep diff --git a/subprojects/wdmp.wrap b/subprojects/wdmp.wrap new file mode 100644 index 0000000..2e9c073 --- /dev/null +++ b/subprojects/wdmp.wrap @@ -0,0 +1,9 @@ +[wrap-git] +directory = wdmp + +url = https://github.com/Comcast/wdmp-c.git +revision = 796dddbcfa7686ec63536d950775e79b52ee5c3f +patch_filename = wdmp.tar.gz + +[provide] +libwdmp = libwdmp_dep diff --git a/workaround.sh b/workaround.sh new file mode 100755 index 0000000..fc3ee33 --- /dev/null +++ b/workaround.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +mkdir -p subprojects/packagefiles + +pushd wrapdb + +tar -czf rtMessage.tar.gz rtMessage +mv -f rtMessage.tar.gz ../subprojects/packagefiles/. + +tar -czf rbuscore.tar.gz rbuscore +mv -f rbuscore.tar.gz ../subprojects/packagefiles/. + +tar -czf rbus.tar.gz rbus +mv -f rbus.tar.gz ../subprojects/packagefiles/. + +tar -czf cimplog.tar.gz cimplog +mv -f cimplog.tar.gz ../subprojects/packagefiles/. + +tar -czf wdmp.tar.gz wdmp +mv -f wdmp.tar.gz ../subprojects/packagefiles/. + +popd diff --git a/wrapdb/cimplog/meson.build b/wrapdb/cimplog/meson.build new file mode 100644 index 0000000..d17e197 --- /dev/null +++ b/wrapdb/cimplog/meson.build @@ -0,0 +1,7 @@ +project('cimplog', 'c', + version: '0.0.1', + meson_version: '>=0.54.0', + license: ['Apache-2.0'], + default_options: ['c_std=c18']) + +libcimplog_dep = declare_dependency(include_directories: ['src/']) diff --git a/wrapdb/rbus/include-workaround-meson/rbus/meson.build b/wrapdb/rbus/include-workaround-meson/rbus/meson.build new file mode 100644 index 0000000..c9ecfcc --- /dev/null +++ b/wrapdb/rbus/include-workaround-meson/rbus/meson.build @@ -0,0 +1,9 @@ +# This is a workaround for creating a rbus/ folder with the headers in it in +# the builddir space. +# +# See https://github.com/mesonbuild/meson/issues/2546 for where the technique comes from +foreach h: headers + configure_file(copy: true, + input: h, + output: '@PLAINNAME@') +endforeach diff --git a/wrapdb/rbus/include/meson.build b/wrapdb/rbus/include/meson.build new file mode 100644 index 0000000..1a58d74 --- /dev/null +++ b/wrapdb/rbus/include/meson.build @@ -0,0 +1,6 @@ +headers = files('rbus_filter.h', + 'rbus.h', + 'rbus_message.h', + 'rbus_object.h', + 'rbus_property.h', + 'rbus_value.h') diff --git a/wrapdb/rbus/meson.build b/wrapdb/rbus/meson.build new file mode 100644 index 0000000..0e66081 --- /dev/null +++ b/wrapdb/rbus/meson.build @@ -0,0 +1,11 @@ +project('rbus', 'c', + version: '0.0.1', + meson_version: '>=0.54.0', + license: ['Apache-2.0'], + default_options: ['c_std=c18']) + +subdir('include') +subdir('include-workaround-meson/rbus') + +librbus_dep = declare_dependency(include_directories: ['include-workaround-meson', + 'include-workaround-meson/rbus']) diff --git a/wrapdb/rbuscore/meson.build b/wrapdb/rbuscore/meson.build new file mode 100644 index 0000000..ccba7c7 --- /dev/null +++ b/wrapdb/rbuscore/meson.build @@ -0,0 +1,8 @@ +project('rbuscore', 'c', + version: '0.0.1', + meson_version: '>=0.54.0', + license: ['Apache-2.0'], + default_options: ['c_std=c18']) + + +librbuscore_dep = declare_dependency(include_directories: ['rbus-core/include']) diff --git a/wrapdb/rtMessage/include-workaround-meson/rtmessage/meson.build b/wrapdb/rtMessage/include-workaround-meson/rtmessage/meson.build new file mode 100644 index 0000000..ae17948 --- /dev/null +++ b/wrapdb/rtMessage/include-workaround-meson/rtmessage/meson.build @@ -0,0 +1,9 @@ +# This is a workaround for creating a rtmessage/ folder with the headers in it in +# the builddir space. +# +# See https://github.com/mesonbuild/meson/issues/2546 for where the technique comes from +foreach h: headers + configure_file(copy: true, + input: h, + output: '@PLAINNAME@') +endforeach diff --git a/wrapdb/rtMessage/meson.build b/wrapdb/rtMessage/meson.build new file mode 100644 index 0000000..e6aa7aa --- /dev/null +++ b/wrapdb/rtMessage/meson.build @@ -0,0 +1,53 @@ +project('rtMessage', 'c', + version: '0.0.1', + meson_version: '>=0.54.0', + license: ['Apache-2.0'], + default_options: ['c_std=c18']) + + +libcjson_dep = dependency('libcjson', version: '>=1.7.14', fallback: ['cjson']) +thread_dep = dependency('threads') + +headers = files('rtMessage.h', + 'rtMessageHeader.h', + 'rtError.h', + 'rtConnection.h', + 'rtVector.h', + 'rtRetainable.h', + 'rtLog.h', + 'rtList.h', + 'rtTime.h', + 'rtAtomic.h', + 'rtm_discovery_api.h', + 'rtAdvisory.h') + +subdir('include-workaround-meson/rtmessage') + +librtMessage = library('rtMessage', + ['rtConnection.c', + 'rtCipher.c', + 'rtLog.c', + 'rtError.c', + 'rtMessageHeader.c', + 'rtEncoder.c', + 'rtMessage.c', + 'rtSocket.c', + 'rtVector.c', + 'rtList.c', + 'rtTime.c', + 'rtSemaphore.c', + 'rtRetainable.c', + 'rtBase64.c', + 'local_benchmarking.c'], + c_args: ['-D_GNU_SOURCE', '-D_POSIX_C_SOURCE=199309L'], + cpp_args: ['-D_GNU_SOURCE', '-D_POSIX_C_SOURCE=199309L'], + dependencies: [ libcjson_dep, thread_dep ], + install: true) + +librtMessage_dep = declare_dependency(include_directories: ['include-workaround-meson', + 'include-workaround-meson/rtmessage'], + link_with: librtMessage) + +if meson.version().version_compare('>=0.54.0') + meson.override_dependency('librtMessage', librtMessage_dep) +endif diff --git a/wrapdb/wdmp/meson.build b/wrapdb/wdmp/meson.build new file mode 100644 index 0000000..dee013c --- /dev/null +++ b/wrapdb/wdmp/meson.build @@ -0,0 +1,7 @@ +project('wdmp', 'c', + version: '0.0.1', + meson_version: '>=0.54.0', + license: ['Apache-2.0'], + default_options: ['c_std=c18']) + +libwdmp_dep = declare_dependency(include_directories: ['src/']) From 83e6a3bbe6ac26d1e6660b0d24d944030e79d195 Mon Sep 17 00:00:00 2001 From: Guru Chandru Date: Wed, 22 Dec 2021 11:16:59 +0530 Subject: [PATCH 30/35] Refactoring Folders --- CMakeLists.txt | 8 ++- include/cpeabs.h | 62 ------------------- include/cpeabs/cpeabs.h | 53 ++++++++++++++-- src/CMakeLists.txt | 2 +- src/common.c | 1 - .../pods/include}/cpeabs_ovsdb_utils.h | 0 tests/CMakeLists.txt | 2 +- 7 files changed, 56 insertions(+), 72 deletions(-) delete mode 100644 include/cpeabs.h rename {include => src/pods/include}/cpeabs_ovsdb_utils.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5874cbf..d6e3e5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,9 +48,15 @@ include_directories(${INCLUDE_DIR} ) include_directories( - ${PROJECT_SOURCE_DIR}/include/ + ${PROJECT_SOURCE_DIR}/include/cpeabs/ ) +if (PLATFORM STREQUAL "DEVICE_EXTENDER") +include_directories( + ${PROJECT_SOURCE_DIR}/src/pods/include/ + ) +endif () + if (NOT BUILD_YOCTO) # msgpack-c external dependency diff --git a/include/cpeabs.h b/include/cpeabs.h deleted file mode 100644 index c076960..0000000 --- a/include/cpeabs.h +++ /dev/null @@ -1,62 +0,0 @@ -/* SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC */ -/* SPDX-License-Identifier: Apache-2.0 */ - -#ifndef __CPEABS_H__ -#define __CPEABS_H__ - -#include -#include - -#if ! defined(DEVICE_EXTENDER) -#include -#include -#include -#include -#include -#include -#include -#endif - -/*----------------------------------------------------------------------------*/ -/* Macros */ -/*----------------------------------------------------------------------------*/ -#define CPEABS_FREE(__x__) if(__x__ != NULL) { free((void*)(__x__)); __x__ = NULL;} else {printf("Trying to free null pointer\n");} -#define UNUSED(x) (void )(x) -#define MAX_BUFF_SIZE 256 - -/** - * @brief Enables or disables debug logs. - */ -#if defined DEVICE_GATEWAY && defined BUILD_YOCTO - -#define WEBCFG_LOG_MODULE "WEBCONFIG" -#define WEBCFG_RDK_LOG_MODULE "LOG.RDK.WEBCONFIG" - -#define WebConfigLog(...) __cimplog_rdk_generic(WEBCFG_RDK_LOG_MODULE, WEBCFG_LOG_MODULE, LEVEL_INFO, __VA_ARGS__) - -#define WebcfgError(...) __cimplog_rdk_generic(WEBCFG_RDK_LOG_MODULE, WEBCFG_LOG_MODULE, LEVEL_ERROR, __VA_ARGS__) -#define WebcfgInfo(...) __cimplog_rdk_generic(WEBCFG_RDK_LOG_MODULE, WEBCFG_LOG_MODULE, LEVEL_INFO, __VA_ARGS__) -#define WebcfgDebug(...) __cimplog_rdk_generic(WEBCFG_RDK_LOG_MODULE, WEBCFG_LOG_MODULE, LEVEL_DEBUG, __VA_ARGS__) -#else -#define WebConfigLog(...) printf(__VA_ARGS__) - -#define WebcfgError(...) printf(__VA_ARGS__) -#define WebcfgInfo(...) printf(__VA_ARGS__) -#define WebcfgDebug(...) printf(__VA_ARGS__) - -#endif -/*----------------------------------------------------------------------------*/ -/* Data Structures */ -/*----------------------------------------------------------------------------*/ -/* none */ -/*----------------------------------------------------------------------------*/ -/* External Functions */ -/*----------------------------------------------------------------------------*/ - -char * getParamValue(char *paramName); -void getValues_rbus(const char *paramName[], const unsigned int paramCount, int index, money_trace_spans *timeSpan, param_t ***paramArr, int *retValCount, WDMP_STATUS *retStatus); -int rbus_GetValueFromDB( char* paramName, char** paramValue); -int rbus_StoreValueIntoDB(char *paramName, char *value); -int rbus_waitUntilSystemReady(); -#endif - diff --git a/include/cpeabs/cpeabs.h b/include/cpeabs/cpeabs.h index 7a3eb28..3de35a0 100644 --- a/include/cpeabs/cpeabs.h +++ b/include/cpeabs/cpeabs.h @@ -4,12 +4,53 @@ #ifndef __CPEABS_H__ #define __CPEABS_H__ -#include #include -#include -#include -#include -#include -#include +#include +#if ! defined(DEVICE_EXTENDER) +#include #endif + +/*----------------------------------------------------------------------------*/ +/* Macros */ +/*----------------------------------------------------------------------------*/ +#define CPEABS_FREE(__x__) if(__x__ != NULL) { free((void*)(__x__)); __x__ = NULL;} else {printf("Trying to free null pointer\n");} +#define UNUSED(x) (void )(x) +#define MAX_BUFF_SIZE 256 + +/** + * @brief Enables or disables debug logs. + */ +#if defined DEVICE_GATEWAY && defined BUILD_YOCTO + +#define WEBCFG_LOG_MODULE "WEBCONFIG" +#define WEBCFG_RDK_LOG_MODULE "LOG.RDK.WEBCONFIG" + +#define WebConfigLog(...) __cimplog_rdk_generic(WEBCFG_RDK_LOG_MODULE, WEBCFG_LOG_MODULE, LEVEL_INFO, __VA_ARGS__) + +#define WebcfgError(...) __cimplog_rdk_generic(WEBCFG_RDK_LOG_MODULE, WEBCFG_LOG_MODULE, LEVEL_ERROR, __VA_ARGS__) +#define WebcfgInfo(...) __cimplog_rdk_generic(WEBCFG_RDK_LOG_MODULE, WEBCFG_LOG_MODULE, LEVEL_INFO, __VA_ARGS__) +#define WebcfgDebug(...) __cimplog_rdk_generic(WEBCFG_RDK_LOG_MODULE, WEBCFG_LOG_MODULE, LEVEL_DEBUG, __VA_ARGS__) +#else +#define WebConfigLog(...) printf(__VA_ARGS__) + +#define WebcfgError(...) printf(__VA_ARGS__) +#define WebcfgInfo(...) printf(__VA_ARGS__) +#define WebcfgDebug(...) printf(__VA_ARGS__) + +#endif +/*----------------------------------------------------------------------------*/ +/* Data Structures */ +/*----------------------------------------------------------------------------*/ +/* none */ +/*----------------------------------------------------------------------------*/ +/* External Functions */ +/*----------------------------------------------------------------------------*/ + +char * getParamValue(char *paramName); +void getValues_rbus(const char *paramName[], const unsigned int paramCount, int index, money_trace_spans *timeSpan, param_t ***paramArr, int *retValCount, WDMP_STATUS *retStatus); +int rbus_GetValueFromDB( char* paramName, char** paramValue); +int rbus_StoreValueIntoDB(char *paramName, char *value); +int rbus_waitUntilSystemReady(); +#endif + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 44c75fa..bfb55a1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -29,7 +29,7 @@ set(SOURCES rdkb/impl.c) set(HEADERS ${PROJECT_SOURCE_DIR}/include/cpeabs/cpeabs.h) elseif (PLATFORM STREQUAL "DEVICE_EXTENDER") set(SOURCES pods/impl.c pods/cpeabs_ovsdb_utils.c) -set(HEADERS ${PROJECT_SOURCE_DIR}/include/cpeabs_ovsdb_utils.h ${PROJECT_SOURCE_DIR}/include/cpeabs/cpeabs.h) +set(HEADERS ${PROJECT_SOURCE_DIR}/include/cpeabs/cpeabs.h ${PROJECT_SOURCE_DIR}/src/pods/include/cpeabs_ovsdb_utils.h) add_definitions(-DPS_FILE_PATH=${PS_FILE_PATH}) else () set(SOURCES pc/impl.c) diff --git a/src/common.c b/src/common.c index d641530..9130c01 100644 --- a/src/common.c +++ b/src/common.c @@ -6,7 +6,6 @@ #include #include #include -//#include "../../subprojects/wdmp/src/wdmp-c.h" #include #include #include diff --git a/include/cpeabs_ovsdb_utils.h b/src/pods/include/cpeabs_ovsdb_utils.h similarity index 100% rename from include/cpeabs_ovsdb_utils.h rename to src/pods/include/cpeabs_ovsdb_utils.h diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6d56449..44169ef 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -44,7 +44,7 @@ set(SOURCES test_rdkb.c ${PROJECT_SOURCE_DIR}/src/rdkb/impl.c ) add_executable(test_rdkb ${SOURCES}) -target_link_libraries (test_rdkb -lcjson -lcunit -lmsgpackc -lwdmp-c -lcimplog -lpthread -lrbus -lrbus-core) +target_link_libraries (test_rdkb -lcjson -lcunit -lmsgpackc -lwdmp-c -lcimplog -lpthread -lrbus ) target_link_libraries (test_rdkb gcov -Wl,--no-as-needed ) From 3bd97c4ea09ce728c4975e82f940f3a0eb9a9af7 Mon Sep 17 00:00:00 2001 From: Guru Chandru Date: Wed, 22 Dec 2021 13:38:44 +0530 Subject: [PATCH 31/35] Pod refactoring and jansson local build config changes --- CMakeLists.txt | 15 +++++++++++++++ meson.build | 4 +++- src/pods/impl.c | 8 ++++---- subprojects/jansson.wrap | 9 +++++++++ tests/CMakeLists.txt | 4 ++-- tests/test_pods.c | 5 ++--- workaround.sh | 3 +++ wrapdb/jansson/meson.build | 7 +++++++ 8 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 subprojects/jansson.wrap create mode 100644 wrapdb/jansson/meson.build diff --git a/CMakeLists.txt b/CMakeLists.txt index d6e3e5e..0a68123 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -148,6 +148,21 @@ ExternalProject_Add(rbus add_library(librbus STATIC SHARED IMPORTED) add_dependencies(librbus rbus) +if (PLATFORM STREQUAL "DEVICE_EXTENDER") + +# jansson external dependency +#------------------------------------------------------------------------------- +ExternalProject_Add(jansson + PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/rbus + GIT_REPOSITORY https://github.com/akheron/jansson.git + GIT_TAG master + CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} +) + +add_library(libjansson STATIC SHARED IMPORTED) +add_dependencies(libjansson jansson) +endif () + endif () link_directories ( ${LIBRARY_DIR} ${COMMON_LIBRARY_DIR} ${LIBRARY_DIR64} ) diff --git a/meson.build b/meson.build index e167eb7..e545b28 100644 --- a/meson.build +++ b/meson.build @@ -39,6 +39,7 @@ libwdmp_dep = dependency('libwdmp') librtMessage_dep = dependency('librtMessage') librbuscore_dep = dependency('librbuscore') librbus_dep = dependency('librbus') +libjansson_dep = dependency('libjansson') else warning('You are running an older version of meson.') warning('In order for dependency management to be supported you need a newer version of meson (0.54+)') @@ -50,9 +51,10 @@ libwdmp_dep = dependency('libwdmp') librtMessage_dep = dependency('librtMessage') librbuscore_dep = dependency('librbuscore') librbus_dep = dependency('librbus') +libjansson_dep = dependency('libjansson') endif -all_dep = [libcjson_dep, librtMessage_dep, librbuscore_dep, librbus_dep, libcimplog_dep, libwdmp_dep] +all_dep = [libcjson_dep, librtMessage_dep, librbuscore_dep, librbus_dep, libcimplog_dep, libwdmp_dep, libjansson_dep] ################################################################################ # Common variable definitions diff --git a/src/pods/impl.c b/src/pods/impl.c index 908fdc7..c47f344 100644 --- a/src/pods/impl.c +++ b/src/pods/impl.c @@ -567,7 +567,7 @@ int Set_Webconfig_URL( char *pString) return ret; } -int Get_Supplementary_URL( char *name, char *pString) +int Get_Supplementary_URL(char *pString) { char url[128]; int ret = RETURN_ERR; @@ -586,7 +586,7 @@ int Get_Supplementary_URL( char *name, char *pString) return ret; } -int Set_Supplementary_URL( char *name, char *pString) +int Set_Supplementary_URL(char *pString) { int ret = RETURN_ERR; @@ -634,7 +634,7 @@ int rbus_StoreValueIntoDB(char *paramName, char *value) } else if (strncmp(paramName,WEBCFG_SUPPLEMENTARY_TELEMETRY_PARAM,WEBCFG_MAX_PARAM_LEN) == 0) { - if (Set_Supplementary_URL(NULL,value) == RETURN_OK) + if (Set_Supplementary_URL(value) == RETURN_OK) { WebcfgDebug("%s : Successfully stored [%s] = [%s]. \n",__func__,WEBCFG_SUPPLEMENTARY_TELEMETRY_PARAM,value); ret = RETURN_OK; @@ -684,7 +684,7 @@ int rbus_GetValueFromDB( char* paramName, char** paramValue) } else if (strncmp(paramName,WEBCFG_SUPPLEMENTARY_TELEMETRY_PARAM,WEBCFG_MAX_PARAM_LEN) == 0) { - if (Get_Supplementary_URL(NULL,value_str) == RETURN_OK) + if (Get_Supplementary_URL(value_str) == RETURN_OK) { *paramValue = strdup(value_str); WebcfgDebug("%s : Successfully fetched [%s] = [%s]. \n",__func__,WEBCFG_SUPPLEMENTARY_TELEMETRY_PARAM,*paramValue); diff --git a/subprojects/jansson.wrap b/subprojects/jansson.wrap new file mode 100644 index 0000000..49703c6 --- /dev/null +++ b/subprojects/jansson.wrap @@ -0,0 +1,9 @@ +[wrap-git] +directory = jansson + +url = https://github.com/akheron/jansson.git +revision = addeeef408cf9e4711a234e04fc2c4bd7357561b +patch_filename = jansson.tar.gz + +[provide] +libjansson = libjansson_dep diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 44169ef..192f473 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -56,11 +56,11 @@ elseif (PLATFORM STREQUAL "DEVICE_EXTENDER") #------------------------------------------------------------------------------- add_test(NAME test_pods COMMAND ${MEMORY_CHECK} ./test_pods) -set(SOURCES test_pods.c ${PROJECT_SOURCE_DIR}/src/pods/impl.c ) +set(SOURCES test_pods.c ${PROJECT_SOURCE_DIR}/src/pods/impl.c ${PROJECT_SOURCE_DIR}/src/pods/cpeabs_ovsdb_utils.c ) add_executable(test_pods ${SOURCES}) -target_link_libraries (test_pods -lcunit) +target_link_libraries (test_pods -lcunit -ljansson) target_link_libraries (test_pods gcov -Wl,--no-as-needed ) diff --git a/tests/test_pods.c b/tests/test_pods.c index b4989e3..df66bec 100644 --- a/tests/test_pods.c +++ b/tests/test_pods.c @@ -19,7 +19,7 @@ #include #include #include "cpeabs.h" - +#include "cpeabs_ovsdb_utils.h" /*----------------------------------------------------------------------------*/ /* Macros */ /*----------------------------------------------------------------------------*/ @@ -45,8 +45,7 @@ /*----------------------------------------------------------------------------*/ void test_do_something() { - char * testget = getParamValue("test"); - printf("testget is %s\n", testget); + printf("SUCCESS\n"); } diff --git a/workaround.sh b/workaround.sh index fc3ee33..f1a12a0 100755 --- a/workaround.sh +++ b/workaround.sh @@ -19,4 +19,7 @@ mv -f cimplog.tar.gz ../subprojects/packagefiles/. tar -czf wdmp.tar.gz wdmp mv -f wdmp.tar.gz ../subprojects/packagefiles/. +tar -czf jansson.tar.gz jansson +mv -f jansson.tar.gz ../subprojects/packagefiles/. + popd diff --git a/wrapdb/jansson/meson.build b/wrapdb/jansson/meson.build new file mode 100644 index 0000000..2000578 --- /dev/null +++ b/wrapdb/jansson/meson.build @@ -0,0 +1,7 @@ +project('jansson', 'c', + version: '0.0.1', + meson_version: '>=0.54.0', + license: ['Apache-2.0'], + default_options: ['c_std=c18']) + +libjansson_dep = declare_dependency(include_directories: ['src/']) From 90a397f914a361f6ec78d66e7800d836f2a09622 Mon Sep 17 00:00:00 2001 From: Guru Chandru Date: Wed, 22 Dec 2021 13:54:04 +0530 Subject: [PATCH 32/35] Added Steps to build in README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 335f4cc..a4e7aea 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ An abstraction layer for consumer preference equipment systems. # Building and Testing Instructions +Use the below commands to build using meson ``` ./workaround.sh meson build @@ -24,6 +25,9 @@ cd build ninja all test coverage firefox meson-logs/coveragereport/index.html +``` +Use the below commands to build using cmake +``` Use CFLAG -DPLATFORM=DEVICE_GATEWAY to build for RDKB platform Use CFLAG -DPLATFORM=DEVICE_EXTENDER to build for POD platform From a2d6122dab3742cd0bb97d8c5033be645605f6c1 Mon Sep 17 00:00:00 2001 From: Guru Chandru Date: Wed, 22 Dec 2021 15:34:03 +0530 Subject: [PATCH 33/35] Fix for REUSE Compliance Check Failure --- CMakeLists.txt | 15 ++------------- src/CMakeLists.txt | 15 ++------------- src/pc/impl.c | 18 +++--------------- src/pods/cpeabs_ovsdb_utils.c | 17 ++--------------- src/pods/impl.c | 18 +++--------------- src/rdkb/impl.c | 18 +++--------------- subprojects/cimplog.wrap | 3 +++ subprojects/cjson.wrap | 3 +++ subprojects/jansson.wrap | 3 +++ subprojects/rtMessage.wrap | 3 +++ subprojects/wdmp.wrap | 3 +++ tests/CMakeLists.txt | 15 ++------------- tests/test_pc.c | 19 +++---------------- tests/test_pods.c | 19 +++---------------- tests/test_rdkb.c | 19 +++---------------- workaround.sh | 3 +++ wrapdb/cimplog/meson.build | 3 +++ wrapdb/jansson/meson.build | 3 +++ .../include-workaround-meson/rbus/meson.build | 4 ++++ wrapdb/rbus/include/meson.build | 3 +++ wrapdb/rbus/meson.build | 3 +++ wrapdb/rbuscore/meson.build | 3 +++ .../rtmessage/meson.build | 4 ++++ wrapdb/rtMessage/meson.build | 3 +++ wrapdb/wdmp/meson.build | 3 +++ 25 files changed, 73 insertions(+), 147 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a68123..6062b0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,16 +1,5 @@ -# Copyright 2021 -# -# 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. +# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC +# SPDX-License-Identifier: Apache-2.0 cmake_minimum_required(VERSION 2.8.7) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bfb55a1..99b94db 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,16 +1,5 @@ -# Copyright 2021 Comcast Cable Communications Management, LLC -# -# 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. +# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC +# SPDX-License-Identifier: Apache-2.0 set(PROJ_CPEABS cpeabs) diff --git a/src/pc/impl.c b/src/pc/impl.c index 9d37923..19fde7d 100644 --- a/src/pc/impl.c +++ b/src/pc/impl.c @@ -1,18 +1,6 @@ -/* - * Copyright 2021 Comcast Cable Communications Management, LLC - * - * 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. - */ +/* SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC */ +/* SPDX-License-Identifier: Apache-2.0 */ + #include #include #include diff --git a/src/pods/cpeabs_ovsdb_utils.c b/src/pods/cpeabs_ovsdb_utils.c index c744f57..10783ec 100644 --- a/src/pods/cpeabs_ovsdb_utils.c +++ b/src/pods/cpeabs_ovsdb_utils.c @@ -1,18 +1,5 @@ -/* - * Copyright 2021 Comcast Cable Communications Management, LLC - * - * 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. - */ +/* SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC */ +/* SPDX-License-Identifier: Apache-2.0 */ #include #include diff --git a/src/pods/impl.c b/src/pods/impl.c index c47f344..1ae8f44 100644 --- a/src/pods/impl.c +++ b/src/pods/impl.c @@ -1,18 +1,6 @@ -/* - * Copyright 2021 Comcast Cable Communications Management, LLC - * - * 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. - */ +/* SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC */ +/* SPDX-License-Identifier: Apache-2.0 */ + #include #include #include diff --git a/src/rdkb/impl.c b/src/rdkb/impl.c index e6a63fb..bbb6be2 100644 --- a/src/rdkb/impl.c +++ b/src/rdkb/impl.c @@ -1,18 +1,6 @@ -/* - * Copyright 2021 Comcast Cable Communications Management, LLC - * - * 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. - */ +/* SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC */ +/* SPDX-License-Identifier: Apache-2.0 */ + #include #include #include diff --git a/subprojects/cimplog.wrap b/subprojects/cimplog.wrap index ad71f48..456bd9c 100644 --- a/subprojects/cimplog.wrap +++ b/subprojects/cimplog.wrap @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC +# SPDX-License-Identifier: Apache-2.0 + [wrap-git] directory = cimplog diff --git a/subprojects/cjson.wrap b/subprojects/cjson.wrap index 26a0097..f65f72f 100644 --- a/subprojects/cjson.wrap +++ b/subprojects/cjson.wrap @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC +# SPDX-License-Identifier: Apache-2.0 + [wrap-file] directory = cJSON-1.7.14 source_url = https://github.com/DaveGamble/cJSON/archive/refs/tags/v1.7.14.tar.gz diff --git a/subprojects/jansson.wrap b/subprojects/jansson.wrap index 49703c6..c6dcf30 100644 --- a/subprojects/jansson.wrap +++ b/subprojects/jansson.wrap @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC +# SPDX-License-Identifier: Apache-2.0 + [wrap-git] directory = jansson diff --git a/subprojects/rtMessage.wrap b/subprojects/rtMessage.wrap index 68eab43..0d5bd3d 100644 --- a/subprojects/rtMessage.wrap +++ b/subprojects/rtMessage.wrap @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC +# SPDX-License-Identifier: Apache-2.0 + [wrap-git] directory = rtMessage diff --git a/subprojects/wdmp.wrap b/subprojects/wdmp.wrap index 2e9c073..db970b8 100644 --- a/subprojects/wdmp.wrap +++ b/subprojects/wdmp.wrap @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC +# SPDX-License-Identifier: Apache-2.0 + [wrap-git] directory = wdmp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 192f473..d2f986f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,16 +1,5 @@ -# Copyright 2021 Comcast Cable Communications Management, LLC -# -# 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. +# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC +# SPDX-License-Identifier: Apache-2.0 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -W -g -fprofile-arcs -ftest-coverage -O0") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST ") diff --git a/tests/test_pc.c b/tests/test_pc.c index bc9052d..21ac1e7 100644 --- a/tests/test_pc.c +++ b/tests/test_pc.c @@ -1,19 +1,6 @@ - /** - * Copyright 2021 Comcast Cable Communications Management, LLC - * - * 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. - * - */ +/* SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC */ +/* SPDX-License-Identifier: Apache-2.0 */ + #include #include #include diff --git a/tests/test_pods.c b/tests/test_pods.c index df66bec..e80311f 100644 --- a/tests/test_pods.c +++ b/tests/test_pods.c @@ -1,19 +1,6 @@ - /** - * Copyright 2021 Comcast Cable Communications Management, LLC - * - * 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. - * - */ +/* SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC */ +/* SPDX-License-Identifier: Apache-2.0 */ + #include #include #include diff --git a/tests/test_rdkb.c b/tests/test_rdkb.c index f13df78..c9ab790 100644 --- a/tests/test_rdkb.c +++ b/tests/test_rdkb.c @@ -1,19 +1,6 @@ - /** - * Copyright 2021 Comcast Cable Communications Management, LLC - * - * 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. - * - */ +/* SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC */ +/* SPDX-License-Identifier: Apache-2.0 */ + #include #include #include diff --git a/workaround.sh b/workaround.sh index f1a12a0..781e043 100755 --- a/workaround.sh +++ b/workaround.sh @@ -1,5 +1,8 @@ #!/bin/bash +# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC +# SPDX-License-Identifier: Apache-2.0 + mkdir -p subprojects/packagefiles pushd wrapdb diff --git a/wrapdb/cimplog/meson.build b/wrapdb/cimplog/meson.build index d17e197..d206bab 100644 --- a/wrapdb/cimplog/meson.build +++ b/wrapdb/cimplog/meson.build @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC +# SPDX-License-Identifier: Apache-2.0 + project('cimplog', 'c', version: '0.0.1', meson_version: '>=0.54.0', diff --git a/wrapdb/jansson/meson.build b/wrapdb/jansson/meson.build index 2000578..444bf66 100644 --- a/wrapdb/jansson/meson.build +++ b/wrapdb/jansson/meson.build @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC +# SPDX-License-Identifier: Apache-2.0 + project('jansson', 'c', version: '0.0.1', meson_version: '>=0.54.0', diff --git a/wrapdb/rbus/include-workaround-meson/rbus/meson.build b/wrapdb/rbus/include-workaround-meson/rbus/meson.build index c9ecfcc..4e14b07 100644 --- a/wrapdb/rbus/include-workaround-meson/rbus/meson.build +++ b/wrapdb/rbus/include-workaround-meson/rbus/meson.build @@ -2,6 +2,10 @@ # the builddir space. # # See https://github.com/mesonbuild/meson/issues/2546 for where the technique comes from +# +# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC +# SPDX-License-Identifier: Apache-2.0 + foreach h: headers configure_file(copy: true, input: h, diff --git a/wrapdb/rbus/include/meson.build b/wrapdb/rbus/include/meson.build index 1a58d74..1603b34 100644 --- a/wrapdb/rbus/include/meson.build +++ b/wrapdb/rbus/include/meson.build @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC +# SPDX-License-Identifier: Apache-2.0 + headers = files('rbus_filter.h', 'rbus.h', 'rbus_message.h', diff --git a/wrapdb/rbus/meson.build b/wrapdb/rbus/meson.build index 0e66081..8cc2108 100644 --- a/wrapdb/rbus/meson.build +++ b/wrapdb/rbus/meson.build @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC +# SPDX-License-Identifier: Apache-2.0 + project('rbus', 'c', version: '0.0.1', meson_version: '>=0.54.0', diff --git a/wrapdb/rbuscore/meson.build b/wrapdb/rbuscore/meson.build index ccba7c7..c4b8af0 100644 --- a/wrapdb/rbuscore/meson.build +++ b/wrapdb/rbuscore/meson.build @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC +# SPDX-License-Identifier: Apache-2.0 + project('rbuscore', 'c', version: '0.0.1', meson_version: '>=0.54.0', diff --git a/wrapdb/rtMessage/include-workaround-meson/rtmessage/meson.build b/wrapdb/rtMessage/include-workaround-meson/rtmessage/meson.build index ae17948..958aaed 100644 --- a/wrapdb/rtMessage/include-workaround-meson/rtmessage/meson.build +++ b/wrapdb/rtMessage/include-workaround-meson/rtmessage/meson.build @@ -2,6 +2,10 @@ # the builddir space. # # See https://github.com/mesonbuild/meson/issues/2546 for where the technique comes from +# +# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC +# SPDX-License-Identifier: Apache-2.0 + foreach h: headers configure_file(copy: true, input: h, diff --git a/wrapdb/rtMessage/meson.build b/wrapdb/rtMessage/meson.build index e6aa7aa..36e1e2a 100644 --- a/wrapdb/rtMessage/meson.build +++ b/wrapdb/rtMessage/meson.build @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC +# SPDX-License-Identifier: Apache-2.0 + project('rtMessage', 'c', version: '0.0.1', meson_version: '>=0.54.0', diff --git a/wrapdb/wdmp/meson.build b/wrapdb/wdmp/meson.build index dee013c..5ee5aa3 100644 --- a/wrapdb/wdmp/meson.build +++ b/wrapdb/wdmp/meson.build @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC +# SPDX-License-Identifier: Apache-2.0 + project('wdmp', 'c', version: '0.0.1', meson_version: '>=0.54.0', From 5709e6e205aa5ac828a41072337f8f5bb9728fe0 Mon Sep 17 00:00:00 2001 From: Guru Chandru Date: Thu, 30 Dec 2021 14:49:45 +0530 Subject: [PATCH 34/35] Refactored Macros, platform independent header files --- CMakeLists.txt | 6 ++++- include/cpeabs/cpeabs.h | 29 +------------------- src/CMakeLists.txt | 10 +++---- src/common.c | 35 +++++++++++++------------ src/pc/impl.c | 2 +- src/pods/cpeabs_ovsdb_utils.c | 1 + src/pods/impl.c | 1 + src/pods/include/cpeabs_pod.h | 33 +++++++++++++++++++++++ src/rdkb/impl.c | 27 +++++++++++-------- src/rdkb/include/cpeabs_rdkb.h | 48 ++++++++++++++++++++++++++++++++++ tests/CMakeLists.txt | 4 +-- 11 files changed, 132 insertions(+), 64 deletions(-) create mode 100644 src/pods/include/cpeabs_pod.h create mode 100644 src/rdkb/include/cpeabs_rdkb.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6062b0a..b38fdbf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,11 @@ include_directories( ${PROJECT_SOURCE_DIR}/include/cpeabs/ ) -if (PLATFORM STREQUAL "DEVICE_EXTENDER") +if (PLATFORM STREQUAL "DEVICE_GATEWAY") +include_directories( + ${PROJECT_SOURCE_DIR}/src/rdkb/include/ + ) +elseif (PLATFORM STREQUAL "DEVICE_EXTENDER") include_directories( ${PROJECT_SOURCE_DIR}/src/pods/include/ ) diff --git a/include/cpeabs/cpeabs.h b/include/cpeabs/cpeabs.h index 3de35a0..f7e2f56 100644 --- a/include/cpeabs/cpeabs.h +++ b/include/cpeabs/cpeabs.h @@ -7,38 +7,10 @@ #include #include -#if ! defined(DEVICE_EXTENDER) -#include -#endif - /*----------------------------------------------------------------------------*/ /* Macros */ /*----------------------------------------------------------------------------*/ -#define CPEABS_FREE(__x__) if(__x__ != NULL) { free((void*)(__x__)); __x__ = NULL;} else {printf("Trying to free null pointer\n");} -#define UNUSED(x) (void )(x) -#define MAX_BUFF_SIZE 256 - -/** - * @brief Enables or disables debug logs. - */ -#if defined DEVICE_GATEWAY && defined BUILD_YOCTO - -#define WEBCFG_LOG_MODULE "WEBCONFIG" -#define WEBCFG_RDK_LOG_MODULE "LOG.RDK.WEBCONFIG" -#define WebConfigLog(...) __cimplog_rdk_generic(WEBCFG_RDK_LOG_MODULE, WEBCFG_LOG_MODULE, LEVEL_INFO, __VA_ARGS__) - -#define WebcfgError(...) __cimplog_rdk_generic(WEBCFG_RDK_LOG_MODULE, WEBCFG_LOG_MODULE, LEVEL_ERROR, __VA_ARGS__) -#define WebcfgInfo(...) __cimplog_rdk_generic(WEBCFG_RDK_LOG_MODULE, WEBCFG_LOG_MODULE, LEVEL_INFO, __VA_ARGS__) -#define WebcfgDebug(...) __cimplog_rdk_generic(WEBCFG_RDK_LOG_MODULE, WEBCFG_LOG_MODULE, LEVEL_DEBUG, __VA_ARGS__) -#else -#define WebConfigLog(...) printf(__VA_ARGS__) - -#define WebcfgError(...) printf(__VA_ARGS__) -#define WebcfgInfo(...) printf(__VA_ARGS__) -#define WebcfgDebug(...) printf(__VA_ARGS__) - -#endif /*----------------------------------------------------------------------------*/ /* Data Structures */ /*----------------------------------------------------------------------------*/ @@ -52,5 +24,6 @@ void getValues_rbus(const char *paramName[], const unsigned int paramCount, int int rbus_GetValueFromDB( char* paramName, char** paramValue); int rbus_StoreValueIntoDB(char *paramName, char *value); int rbus_waitUntilSystemReady(); +void cpeabs_free(void *ptr); #endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 99b94db..dcdc7bc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,14 +14,14 @@ add_definitions(-DDEVICE_EXTENDER) endif () if (PLATFORM STREQUAL "DEVICE_GATEWAY") -set(SOURCES rdkb/impl.c) -set(HEADERS ${PROJECT_SOURCE_DIR}/include/cpeabs/cpeabs.h) +set(SOURCES rdkb/impl.c common.c) +set(HEADERS ${PROJECT_SOURCE_DIR}/include/cpeabs/cpeabs.h ${PROJECT_SOURCE_DIR}/src/rdkb/include/cpeabs_rdkb.h) elseif (PLATFORM STREQUAL "DEVICE_EXTENDER") -set(SOURCES pods/impl.c pods/cpeabs_ovsdb_utils.c) -set(HEADERS ${PROJECT_SOURCE_DIR}/include/cpeabs/cpeabs.h ${PROJECT_SOURCE_DIR}/src/pods/include/cpeabs_ovsdb_utils.h) +set(SOURCES pods/impl.c pods/cpeabs_ovsdb_utils.c common.c) +set(HEADERS ${PROJECT_SOURCE_DIR}/include/cpeabs/cpeabs.h ${PROJECT_SOURCE_DIR}/src/pods/include/cpeabs_ovsdb_utils.h ${PROJECT_SOURCE_DIR}/src/pods/include/cpeabs_pod.h) add_definitions(-DPS_FILE_PATH=${PS_FILE_PATH}) else () -set(SOURCES pc/impl.c) +set(SOURCES pc/impl.c common.c) endif () #Support cpeabs lib for backward compatibility diff --git a/src/common.c b/src/common.c index 9130c01..59132ca 100644 --- a/src/common.c +++ b/src/common.c @@ -6,9 +6,6 @@ #include #include #include -#include -#include -#include /*----------------------------------------------------------------------------*/ /* Macros */ /*----------------------------------------------------------------------------*/ @@ -36,22 +33,28 @@ void do_something(); /*----------------------------------------------------------------------------*/ /* External Functions */ /*----------------------------------------------------------------------------*/ +//For test purpose +void do_something() +{ + printf("I do something well.\n"); +} + +//For meson build stub function int main() { - /* req_struct *req = NULL; - req = (req_struct *) malloc (sizeof(req_struct)); - do_something();*/ - //wdmp_parse_generic_request("Hi", WDMP_TR181, &req); - rtMessageHeader* testrt = NULL; - testrt = (rtMessageHeader*)malloc(sizeof(rtMessageHeader)); - - rtMessageHeader_Init(testrt); - - do_something(); - return 0; + return 0; } -void do_something() +//User-defined function to free pointer +void cpeabs_free(void *ptr) { - printf("I do something well.\n"); + if(ptr != NULL) + { + free((void*)(ptr)); + ptr = NULL; + } + else + { + printf("Trying to free null pointer\n"); + } } diff --git a/src/pc/impl.c b/src/pc/impl.c index 19fde7d..aa2162c 100644 --- a/src/pc/impl.c +++ b/src/pc/impl.c @@ -15,7 +15,7 @@ /*----------------------------------------------------------------------------*/ /* Macros */ /*----------------------------------------------------------------------------*/ -/* none */ +#define UNUSED(x) (void )(x) /*----------------------------------------------------------------------------*/ /* Data Structures */ /*----------------------------------------------------------------------------*/ diff --git a/src/pods/cpeabs_ovsdb_utils.c b/src/pods/cpeabs_ovsdb_utils.c index 10783ec..f9c1c52 100644 --- a/src/pods/cpeabs_ovsdb_utils.c +++ b/src/pods/cpeabs_ovsdb_utils.c @@ -16,6 +16,7 @@ #include "cpeabs_ovsdb_utils.h" #include "cpeabs.h" +#include "cpeabs_pod.h" static int g_ovsdb_handle = -1; static char ovsdb_opt_db[32] = "Open_vSwitch"; diff --git a/src/pods/impl.c b/src/pods/impl.c index 1ae8f44..9e22cff 100644 --- a/src/pods/impl.c +++ b/src/pods/impl.c @@ -9,6 +9,7 @@ #include #include "cpeabs.h" #include "cpeabs_ovsdb_utils.h" +#include "cpeabs_pod.h" #define BFR_SIZE_16 16 #define BFR_SIZE_32 32 diff --git a/src/pods/include/cpeabs_pod.h b/src/pods/include/cpeabs_pod.h new file mode 100644 index 0000000..ee562b0 --- /dev/null +++ b/src/pods/include/cpeabs_pod.h @@ -0,0 +1,33 @@ +/* SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC */ +/* SPDX-License-Identifier: Apache-2.0 */ + +#ifndef __CPEABS_POD_H__ +#define __CPEABS_POD_H__ + +#include +/*----------------------------------------------------------------------------*/ +/* Macros */ +/*----------------------------------------------------------------------------*/ +#define UNUSED(x) (void )(x) +#define MAX_BUFF_SIZE 256 + +/** + * @brief Enables or disables debug logs. + */ + +#define WebConfigLog(...) printf(__VA_ARGS__) + +#define WebcfgError(...) printf(__VA_ARGS__) +#define WebcfgInfo(...) printf(__VA_ARGS__) +#define WebcfgDebug(...) printf(__VA_ARGS__) + +/*----------------------------------------------------------------------------*/ +/* Data Structures */ +/*----------------------------------------------------------------------------*/ +/* none */ +/*----------------------------------------------------------------------------*/ +/* External Functions */ +/*----------------------------------------------------------------------------*/ +/* none */ +#endif + diff --git a/src/rdkb/impl.c b/src/rdkb/impl.c index bbb6be2..c2d2787 100644 --- a/src/rdkb/impl.c +++ b/src/rdkb/impl.c @@ -15,6 +15,7 @@ #include #include #include "cpeabs.h" +#include "cpeabs_rdkb.h" /*----------------------------------------------------------------------------*/ /* Macros */ /*----------------------------------------------------------------------------*/ @@ -43,6 +44,9 @@ #define WEBCFG_URL_PARAM "Device.X_RDK_WebConfig.URL" #define WEBCFG_PARAM_SUPPLEMENTARY_SERVICE "Device.X_RDK_WebConfig.SupplementaryServiceUrls." #define SYSTEM_READY_PARM "Device.CR.SystemReady" + +#define UNUSED(x) (void )(x) +#define MAX_BUFF_SIZE 256 /*----------------------------------------------------------------------------*/ /* Data Structures */ /*----------------------------------------------------------------------------*/ @@ -72,6 +76,7 @@ static int webcfgRbusRegisterWithCR(); /*----------------------------------------------------------------------------*/ /* External Functions */ /*----------------------------------------------------------------------------*/ + void cpeabStrncpy(char *destStr, const char *srcStr, size_t destSize) { strncpy(destStr, srcStr, destSize-1); @@ -120,7 +125,7 @@ char* get_deviceMAC() cpeabStrncpy(deviceMACValue, macID, strlen(macID)+1); macIDToLower(deviceMACValue, deviceMAC); WebcfgDebug("deviceMAC: %s\n",deviceMAC); - CPEABS_FREE(macID); + cpeabs_free(macID); } WebcfgDebug("deviceMAC returned from lib is %s\n", deviceMAC); return deviceMAC; @@ -291,12 +296,12 @@ int Get_Supplementary_URL( char *name, char *pString) cpeabStrncpy(pString, tempUrl, strlen(tempUrl)+1); } WebcfgDebug("Get_Supplementary_URL. pString %s\n", pString); - CPEABS_FREE(tempParam); + cpeabs_free(tempParam); } else { WebcfgError("psm_get failed ret %d for parameter %s\n", retPsmGet, tempParam); - CPEABS_FREE(tempParam); + cpeabs_free(tempParam); } } } @@ -319,7 +324,7 @@ int Set_Supplementary_URL( char *name, char *pString) if (retPsmSet != RBUS_ERROR_SUCCESS) { WebcfgError("psm_set failed ret %d for parameter %s%s and value %s\n", retPsmSet, WEBCFG_PARAM_SUPPLEMENTARY_SERVICE, name, pString); - CPEABS_FREE(tempParam); + cpeabs_free(tempParam); return 0; } else @@ -331,7 +336,7 @@ int Set_Supplementary_URL( char *name, char *pString) { WebcfgError("Invalid supplementary doc name\n"); } - CPEABS_FREE(tempParam); + cpeabs_free(tempParam); } } return retPsmSet; @@ -357,16 +362,16 @@ char * getParamValue(char *paramName) if (ret == WDMP_SUCCESS ) { cpeabStrncpy(paramValue, parametervalArr[0]->value,64); - CPEABS_FREE(parametervalArr[0]->name); - CPEABS_FREE(parametervalArr[0]->value); - CPEABS_FREE(parametervalArr[0]); + cpeabs_free(parametervalArr[0]->name); + cpeabs_free(parametervalArr[0]->value); + cpeabs_free(parametervalArr[0]); } else { WebcfgError("Failed to GetValue for %s\n", getParamList[0]); - CPEABS_FREE(paramValue); + cpeabs_free(paramValue); } - CPEABS_FREE(parametervalArr); + cpeabs_free(parametervalArr); WebcfgDebug("getParamValue : paramValue is %s\n", paramValue); return paramValue; } @@ -467,7 +472,7 @@ int rbus_GetValueFromDB( char* paramName, char** paramValue) if(str_value !=NULL) { *paramValue = strdup(str_value); - CPEABS_FREE(str_value); + cpeabs_free(str_value); WebcfgDebug("Requested param DB value [%s]\n", *paramValue); } rbusObject_Release(outParams); diff --git a/src/rdkb/include/cpeabs_rdkb.h b/src/rdkb/include/cpeabs_rdkb.h new file mode 100644 index 0000000..2a8eab1 --- /dev/null +++ b/src/rdkb/include/cpeabs_rdkb.h @@ -0,0 +1,48 @@ +/* SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC */ +/* SPDX-License-Identifier: Apache-2.0 */ + +#ifndef __CPEABS_RDKB_H__ +#define __CPEABS_RDKB_H__ + +#include +#include +#include + +/*----------------------------------------------------------------------------*/ +/* Macros */ +/*----------------------------------------------------------------------------*/ +#define UNUSED(x) (void )(x) +#define MAX_BUFF_SIZE 256 + +/** + * @brief Enables or disables debug logs. + */ +#if defined BUILD_YOCTO + +#define WEBCFG_LOG_MODULE "WEBCONFIG" +#define WEBCFG_RDK_LOG_MODULE "LOG.RDK.WEBCONFIG" + +#define WebConfigLog(...) __cimplog_rdk_generic(WEBCFG_RDK_LOG_MODULE, WEBCFG_LOG_MODULE, LEVEL_INFO, __VA_ARGS__) + +#define WebcfgError(...) __cimplog_rdk_generic(WEBCFG_RDK_LOG_MODULE, WEBCFG_LOG_MODULE, LEVEL_ERROR, __VA_ARGS__) +#define WebcfgInfo(...) __cimplog_rdk_generic(WEBCFG_RDK_LOG_MODULE, WEBCFG_LOG_MODULE, LEVEL_INFO, __VA_ARGS__) +#define WebcfgDebug(...) __cimplog_rdk_generic(WEBCFG_RDK_LOG_MODULE, WEBCFG_LOG_MODULE, LEVEL_DEBUG, __VA_ARGS__) +#else +#define WebConfigLog(...) printf(__VA_ARGS__) + +#define WebcfgError(...) printf(__VA_ARGS__) +#define WebcfgInfo(...) printf(__VA_ARGS__) +#define WebcfgDebug(...) printf(__VA_ARGS__) + +#endif + +/*----------------------------------------------------------------------------*/ +/* Data Structures */ +/*----------------------------------------------------------------------------*/ +/* none */ +/*----------------------------------------------------------------------------*/ +/* External Functions */ +/*----------------------------------------------------------------------------*/ +/* none */ +#endif + diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d2f986f..187929e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -29,7 +29,7 @@ if (PLATFORM STREQUAL "DEVICE_GATEWAY") #------------------------------------------------------------------------------- add_test(NAME test_rdkb COMMAND ${MEMORY_CHECK} ./test_rdkb) -set(SOURCES test_rdkb.c ${PROJECT_SOURCE_DIR}/src/rdkb/impl.c ) +set(SOURCES test_rdkb.c ${PROJECT_SOURCE_DIR}/src/rdkb/impl.c ${PROJECT_SOURCE_DIR}/src/common.c) add_executable(test_rdkb ${SOURCES}) @@ -45,7 +45,7 @@ elseif (PLATFORM STREQUAL "DEVICE_EXTENDER") #------------------------------------------------------------------------------- add_test(NAME test_pods COMMAND ${MEMORY_CHECK} ./test_pods) -set(SOURCES test_pods.c ${PROJECT_SOURCE_DIR}/src/pods/impl.c ${PROJECT_SOURCE_DIR}/src/pods/cpeabs_ovsdb_utils.c ) +set(SOURCES test_pods.c ${PROJECT_SOURCE_DIR}/src/pods/impl.c ${PROJECT_SOURCE_DIR}/src/pods/cpeabs_ovsdb_utils.c ${PROJECT_SOURCE_DIR}/src/common.c) add_executable(test_pods ${SOURCES}) From b7831eaf55ee8ab581bce022aaca34f0c664397d Mon Sep 17 00:00:00 2001 From: Debasya Sahoo Date: Tue, 4 Jan 2022 11:16:46 +0000 Subject: [PATCH 35/35] Adding mods according to review --- src/pods/impl.c | 86 +++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 46 deletions(-) diff --git a/src/pods/impl.c b/src/pods/impl.c index 9e22cff..b9a0505 100644 --- a/src/pods/impl.c +++ b/src/pods/impl.c @@ -202,6 +202,7 @@ char * getSerialNumber() else { WebcfgError("Failed to GetValue for serialNum\n"); + cpeabs_free(serialNum); return NULL; } } @@ -232,6 +233,7 @@ char * getDeviceBootTime() else { WebcfgError("Failed to GetValue for bootTime\n"); + cpeabs_free(bootTime); return NULL; } } @@ -275,7 +277,8 @@ char * getModelName() else { WebcfgError("Failed to GetValue for modelName\n"); - return NULL; + cpeabs_free(modelName); + return NULL; } } @@ -305,7 +308,8 @@ char * getFirmwareVersion() else { WebcfgError("Failed to GetValue for firmwareVersion\n"); - return NULL; + cpeabs_free(firmware_version); + return NULL; } } @@ -337,6 +341,7 @@ char * getRebootReason() if ((rebptr = fopen(OSP_PSTORE_REBOOT, "r")) == NULL) { WebcfgError("Error! File %s cannot be opened.\n", OSP_PSTORE_REBOOT); + cpeabs_free(reboot_reason); return NULL; } if( fgets(reboot_fileresp, sizeof(reboot_fileresp), rebptr) != NULL ) @@ -346,7 +351,8 @@ char * getRebootReason() else { WebcfgError("Error! Output from file %s couldnt be parsed.", OSP_PSTORE_REBOOT); - return NULL; + cpeabs_free(reboot_reason); + return NULL; } cpeabStrncpy(reboot_reason,reboot_type,BFR_SIZE_64*sizeof(char)); if (strlen(reboot_reason) > 0) @@ -357,7 +363,8 @@ char * getRebootReason() else { WebcfgError("Failed to GetValue for reboot_reason\n"); - return NULL; + cpeabs_free(reboot_reason); + return NULL; } } @@ -378,20 +385,27 @@ char * cutting_delimiters(char *pstore_content, char * PATTERN1, char *PATTERN2) return target; } -int get_id_pstore(int id_chk, char *id_type) +char * get_id_pstore(int id_chk, char *id_type) { char pstore_content[BFR_SIZE_256]; char acc_id[BFR_SIZE_64]; char partner_id[BFR_SIZE_64]; char *acc_id_ret = NULL; char *partner_id_ret = NULL; - int ret = RETURN_ERR; - FILE *fptr = NULL; - if ((fptr = fopen(OSP_PSTORE_ACCOUNT, "r")) == NULL) + + id_type = malloc(BFR_SIZE_64*sizeof(char)); + + if (!id_type) + { + WebcfgError("%s : id_type couldnt be assigned with memory\n",__func__); + return NULL; + } + if ((fptr = fopen(OSP_PSTORE_ACCOUNT, "r")) == NULL) { WebcfgError("Error! File %s cannot be opened.",OSP_PSTORE_ACCOUNT); - return ret; + cpeabs_free(id_type); + return NULL; } memset(pstore_content,0,sizeof(pstore_content)); fscanf(fptr, "%[^\n]", pstore_content); @@ -415,50 +429,36 @@ int get_id_pstore(int id_chk, char *id_type) else { WebcfgError("Error!The file is present but is empty!\n"); - return ret; + cpeabs_free(id_type); + return NULL; } if ((id_chk == 1) && (strlen(partner_id) > 0)) { cpeabStrncpy(id_type,partner_id_ret,BFR_SIZE_64*sizeof(char)); - ret = RETURN_OK; - return ret; - } - else - { - WebcfgError("Partner ID couldnt be parsed\n"); - return ret; + return id_type; } if ((id_chk == 0) && (strlen(acc_id) > 0)) { cpeabStrncpy(id_type,acc_id_ret,BFR_SIZE_64*sizeof(char)); - ret = RETURN_OK; - return ret; - } - else - { - WebcfgError("Account ID couldnt be parsed\n"); - return ret; + return id_type; } + WebcfgError("Error! Partnerid or/and Accountid couldnt be parsed"); + cpeabs_free(id_type); + return NULL; } char * getPartnerID() { int partner_id_chk = 1; char *partner_id = NULL; - int ret_val; + char *ret_partner_id = NULL; - partner_id = malloc(BFR_SIZE_64*sizeof(char)); - if (!partner_id) - { - WebcfgError("%s : partner_id couldnt be assigned with memory\n",__func__); - return NULL; - } - ret_val = get_id_pstore(partner_id_chk,partner_id); - if (ret_val != RETURN_ERR) + ret_partner_id = get_id_pstore(partner_id_chk,partner_id); + if (ret_partner_id != NULL) { - WebcfgDebug("PartnerID returned from lib is %s\n", partner_id); - return partner_id; + WebcfgDebug("PartnerID returned from lib is %s\n", ret_partner_id); + return ret_partner_id; } else { @@ -471,19 +471,13 @@ char * getAccountID() { int acc_id_chk = 0; char *account_id = NULL; - int ret_val; + char *ret_account_id = NULL; - account_id = malloc(BFR_SIZE_64*sizeof(char)); - if (!account_id) - { - WebcfgError("%s : account_id couldnt be assigned with memory\n",__func__); - return NULL; - } - ret_val = get_id_pstore(acc_id_chk,account_id); - if (ret_val != RETURN_ERR) + ret_account_id = get_id_pstore(acc_id_chk,account_id); + if (ret_account_id != NULL) { - WebcfgDebug("AccountID returned from lib is %s\n", account_id); - return account_id; + WebcfgDebug("AccountID returned from lib is %s\n", ret_account_id); + return ret_account_id; } else {