mirror of
https://github.com/outbackdingo/parodus.git
synced 2026-01-27 18:20:04 +00:00
Compare commits
109 Commits
1.1.4
...
xmidt_send
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60c37daa18 | ||
|
|
f51b4ef9c2 | ||
|
|
254c9f6763 | ||
|
|
8876fa9239 | ||
|
|
42fc9eb26e | ||
|
|
e8e652b076 | ||
|
|
dc935f9a09 | ||
|
|
d1462de56a | ||
|
|
223e7db81c | ||
|
|
cd763823fc | ||
|
|
8537f27ece | ||
|
|
6381d9c55f | ||
|
|
980b7a88db | ||
|
|
e3c37b6764 | ||
|
|
67d58441ef | ||
|
|
f6ffda05ad | ||
|
|
6aee851944 | ||
|
|
aaa93e137d | ||
|
|
21e8c74f23 | ||
|
|
0248e7b241 | ||
|
|
da019382c6 | ||
|
|
aecbd885d5 | ||
|
|
0443c45924 | ||
|
|
314c840755 | ||
|
|
69f7e3eba0 | ||
|
|
e643f9e2fc | ||
|
|
7d2e9733d0 | ||
|
|
23c18da03e | ||
|
|
2218637f2c | ||
|
|
54f9983eff | ||
|
|
a577854172 | ||
|
|
e054ef580f | ||
|
|
79eb7ba6ef | ||
|
|
a291b047b6 | ||
|
|
656b1b0b58 | ||
|
|
22ecf0ef76 | ||
|
|
c97a3a3a20 | ||
|
|
46273d9766 | ||
|
|
7efed14c20 | ||
|
|
6d39163d47 | ||
|
|
5b0d3e19f3 | ||
|
|
0d8bb960f6 | ||
|
|
5d537fb139 | ||
|
|
47fcd6bdae | ||
|
|
24e1790ccb | ||
|
|
89fdd97d44 | ||
|
|
5ae2325fb6 | ||
|
|
9bad1142ab | ||
|
|
339b93cfd3 | ||
|
|
a34db44c90 | ||
|
|
bdec80dd07 | ||
|
|
1833c30e83 | ||
|
|
5b26fe38f5 | ||
|
|
f3a4daeb74 | ||
|
|
aaeb1f6612 | ||
|
|
0fb6288255 | ||
|
|
0fd3b76f27 | ||
|
|
48722ffa7c | ||
|
|
bf5d555d96 | ||
|
|
c02b141f7c | ||
|
|
9f40b7efe5 | ||
|
|
2a184e24c9 | ||
|
|
233a167cb4 | ||
|
|
5562d7ec48 | ||
|
|
49513df8f8 | ||
|
|
d0e6c5bd75 | ||
|
|
66f1f4d4fb | ||
|
|
19b4f56913 | ||
|
|
c30d5a3362 | ||
|
|
c98e2e2fb8 | ||
|
|
c78625f35a | ||
|
|
aeea6fbb03 | ||
|
|
d2d1590329 | ||
|
|
e693c09ca3 | ||
|
|
0b9f739323 | ||
|
|
d901efd10c | ||
|
|
824bcb81cf | ||
|
|
671fc5be59 | ||
|
|
4bf8683192 | ||
|
|
9300d76a8e | ||
|
|
dee98922a6 | ||
|
|
b9fa918c15 | ||
|
|
a278a7017d | ||
|
|
69cf210a34 | ||
|
|
77b587aa9d | ||
|
|
441ecf702f | ||
|
|
bdc2733d8e | ||
|
|
1f24671c0f | ||
|
|
3de4ec59c1 | ||
|
|
a01ad8f15c | ||
|
|
1d2e51e31e | ||
|
|
9e808acf7d | ||
|
|
19f2fe1419 | ||
|
|
b99c06a67b | ||
|
|
f57ebc1cd7 | ||
|
|
1df770a91b | ||
|
|
a582bb3252 | ||
|
|
42dd20263b | ||
|
|
ac100c0f4e | ||
|
|
290289f2f1 | ||
|
|
8e9b98b697 | ||
|
|
b148d40c53 | ||
|
|
dc6486f200 | ||
|
|
ad2d43b4f6 | ||
|
|
54cfdd9c52 | ||
|
|
19056ddfec | ||
|
|
1d85742497 | ||
|
|
e29dd26d2b | ||
|
|
5aae91763a |
24
.github/scripts/get_sonarcloud.sh
vendored
Executable file
24
.github/scripts/get_sonarcloud.sh
vendored
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
curl -s -L -O https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip
|
||||
unzip -q -o build-wrapper-linux-x86.zip
|
||||
|
||||
|
||||
SONAR_VERSION=`curl -s https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/ |grep -o "sonar-scanner-cli-[0-9.]*-linux.zip"|sort -r|uniq|head -n 1`
|
||||
curl -s -L -O https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/$SONAR_VERSION
|
||||
curl -s -L -O https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/$SONAR_VERSION.sha256
|
||||
echo " $SONAR_VERSION" >> $SONAR_VERSION.sha256
|
||||
sha256sum -c $SONAR_VERSION.sha256
|
||||
if [[ $? -ne 0 ]]
|
||||
then
|
||||
exit 1
|
||||
fi
|
||||
unzip -q $SONAR_VERSION
|
||||
|
||||
output=`ls | grep -o "sonar-scanner-[0-9.]*-linux"`
|
||||
|
||||
echo "Using $output"
|
||||
|
||||
mv $output sonar-scanner
|
||||
50
.github/workflows/codeql-analysis.yml
vendored
Normal file
50
.github/workflows/codeql-analysis.yml
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
name: LGTM Analysis
|
||||
|
||||
on:
|
||||
create:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
schedule:
|
||||
- cron: '12 9 * * 3'
|
||||
|
||||
jobs:
|
||||
codeql:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
# Install the dependent packages
|
||||
- name: Install packages
|
||||
run: |
|
||||
sudo apt update
|
||||
sudo apt-get -y install valgrind libcunit1 libcunit1-doc libcunit1-dev libmsgpack-dev gcovr libtool
|
||||
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
with:
|
||||
languages: cpp
|
||||
queries: security-extended
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
|
||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||
# and modify them (or add more) to build your code if your project
|
||||
# uses a compiled language
|
||||
|
||||
#- run: |
|
||||
# make bootstrap
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
||||
72
.github/workflows/push.yml
vendored
Normal file
72
.github/workflows/push.yml
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
name: CI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
paths-ignore:
|
||||
- 'AUTHORS'
|
||||
- 'LICENSE'
|
||||
- 'NOTICE'
|
||||
- '**.md'
|
||||
- '.gitignore'
|
||||
tags-ignore:
|
||||
- 'v[0-9]+.[0-9]+.[0-9]+'
|
||||
branches:
|
||||
- main
|
||||
- master
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Unit Tests
|
||||
runs-on: [ ubuntu-latest ]
|
||||
steps:
|
||||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
# Install the dependent packages
|
||||
- name: Install packages
|
||||
run: |
|
||||
sudo apt update
|
||||
sudo apt-get -y install valgrind libcunit1 libcunit1-doc libcunit1-dev libmsgpack-dev gcovr libtool
|
||||
pip install codecov
|
||||
|
||||
- name: Make Build Directory
|
||||
run: mkdir build
|
||||
|
||||
- name: Get Sonarcloud Binaries
|
||||
working-directory: build
|
||||
run: |
|
||||
../.github/scripts/get_sonarcloud.sh
|
||||
|
||||
- name: CMake
|
||||
working-directory: build
|
||||
run: |
|
||||
cmake .. -DINTEGRATION_TESTING:BOOL=false -DDISABLE_VALGRIND:BOOL=${DISABLE_VALGRIND} -DENABLE_SESHAT:BOOL=true -DFEATURE_DNS_QUERY:BOOL=true
|
||||
|
||||
|
||||
- name: Build
|
||||
working-directory: build
|
||||
run: |
|
||||
build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output make all test
|
||||
|
||||
- name: Merge GCOV Reports for Sonarcloud
|
||||
working-directory: build
|
||||
run: |
|
||||
gcovr --sonarqube coverage.xml -r ..
|
||||
|
||||
- name: Upload SonarCloud
|
||||
run: |
|
||||
build/sonar-scanner/bin/sonar-scanner -Dsonar.host.url=https://sonarcloud.io -Dproject.settings=.sonar-project.properties -Dsonar.login=${{ secrets.SONAR_TOKEN }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Upload Codecov.io
|
||||
uses: codecov/codecov-action@v1
|
||||
with:
|
||||
directory: .
|
||||
fail_ci_if_error: true
|
||||
49
.github/workflows/release.yml
vendored
Normal file
49
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
name: release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
# Push events to matching v#.#.#*, ex: v1.2.3, v.2.4.6-beta
|
||||
- 'v[0-9]+.[0-9]+.[0-9]+*'
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: [ ubuntu-latest ]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Determine repo name
|
||||
run: |
|
||||
echo "repo_name=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV
|
||||
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
|
||||
echo "release_slug=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')-${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
|
||||
shell: bash
|
||||
- name: Create tarball and sha256
|
||||
run: |
|
||||
git archive --format=tar.gz -o ${release_slug}.tar.gz --prefix=${release_slug}/ ${version}
|
||||
git archive --format=zip -o ${release_slug}.zip --prefix=${release_slug}/ ${version}
|
||||
sha256sum ${release_slug}.tar.gz ${release_slug}.zip > ${release_slug}-sha256sums.txt
|
||||
mkdir artifacts
|
||||
cp ${release_slug}* artifacts/.
|
||||
- name: Prepare Release Body
|
||||
id: prep
|
||||
run: |
|
||||
export version=${GITHUB_REF#refs/tags/}
|
||||
export NOTES=$(cat CHANGELOG.md | perl -0777 -ne 'print "$1\n" if /.*## \[${version}\]\s(.*?)\s+## \[(v\d+.\d+.\d+)\].*/s')
|
||||
export TODAY=`date +'%m/%d/%Y'`
|
||||
echo ::set-output name=rname::$(echo ${version} ${TODAY})
|
||||
echo ::set-output name=body::${NOTES}
|
||||
- name: create release
|
||||
id: create_release
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
name: ${{ steps.prep.outputs.rname }}
|
||||
draft: false
|
||||
prerelease: false
|
||||
bodyFile: ${{ steps.prep.outputs.body }}
|
||||
artifacts: "artifacts/*"
|
||||
token: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
|
||||
33
.github/workflows/tag.yml
vendored
Normal file
33
.github/workflows/tag.yml
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
name: tag
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- "CHANGELOG.md" # only try to tag if the CHANGELOG has been updated.
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: [ ubuntu-latest ]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
token: '${{ secrets.PERSONAL_ACCESS_TOKEN }}'
|
||||
fetch-depth: 0
|
||||
- name: set up bot
|
||||
run: |
|
||||
git config --global user.name "xmidt-bot"
|
||||
git config --global user.email "$BOT_EMAIL"
|
||||
- name: export variables and tag commit
|
||||
run: |
|
||||
export OLD_VERSION=$(git describe --tags `git rev-list --tags --max-count=1` | tail -1)
|
||||
export TAG=$(cat CHANGELOG.md | perl -0777 -ne 'print "$1" if /.*## \[Unreleased\]\s+## \[(v\d+.\d+.\d+)\].*/s')
|
||||
export BINVER=$(cat CMakeLists.txt | perl -0777 -ne 'print "v$1" if /.*project\s*\(.*\s*VERSION\s*(\d+.\d+.\d+).*\s*\)/s')
|
||||
export TODAY=`date +'%m/%d/%Y'`
|
||||
export NOTES=$(cat CHANGELOG.md | perl -0777 -ne 'print "$ENV{TODAY}\n\n$1\n" if /.*## \[$ENV{TAG}\]\s(.*?)\s+## \[(v\d+.\d+.\d+)\].*/s')
|
||||
if [[ "$TAG" != "" && "$TAG" != "$BINVER" ]]; then echo "CHANGELOG.md($TAG) and CMakeLists.txt VERSION($BINVER) do not match"; fi
|
||||
if [[ "$TAG" != "" && "$TAG" != "$OLD_VERSION" && "$TAG" == "$BINVER" ]]; then git tag -a "$TAG" -m "$NOTES"; git push origin --tags; echo $?; fi
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -34,3 +34,5 @@
|
||||
tags
|
||||
|
||||
build/
|
||||
|
||||
tests/jwt_key.tst
|
||||
|
||||
34
.sonar-project.properties
Normal file
34
.sonar-project.properties
Normal file
@@ -0,0 +1,34 @@
|
||||
# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
# Reference:
|
||||
# https://github.com/SonarSource/sonarcloud_example_go-sqscanner-travis/blob/master/sonar-project.properties
|
||||
|
||||
|
||||
# =====================================================
|
||||
# Standard properties
|
||||
# =====================================================
|
||||
|
||||
sonar.organization=xmidt-org
|
||||
sonar.projectKey=xmidt-org_parodus
|
||||
sonar.projectName=parodus
|
||||
|
||||
sonar.sources=src
|
||||
|
||||
# =====================================================
|
||||
# Meta-data for the project
|
||||
# =====================================================
|
||||
|
||||
sonar.links.homepage=https://github.com/xmidt-org/parodus
|
||||
sonar.links.ci=https://github.com/xmidt-org/parodus/actions
|
||||
sonar.links.scm=https://github.com/xmidt-org/parodus
|
||||
sonar.links.issue=https://github.com/xmidt-org/parodus/issues
|
||||
|
||||
# =====================================================
|
||||
# Properties specific to C
|
||||
# =====================================================
|
||||
sonar.cfamily.build-wrapper-output=build/bw-output
|
||||
sonar.cfamily.threads=2
|
||||
sonar.cfamily.cache.enabled=false
|
||||
sonar.coverageReportPaths=build/coverage.xml
|
||||
|
||||
43
.travis.yml
43
.travis.yml
@@ -1,43 +0,0 @@
|
||||
dist: trusty
|
||||
sudo: required
|
||||
|
||||
language: c
|
||||
compiler:
|
||||
- gcc
|
||||
|
||||
addons:
|
||||
coverity_scan:
|
||||
project:
|
||||
name: "Comcast/parodus"
|
||||
description: "C implementation of the WebPA client coordinator"
|
||||
notification_email: weston_schmidt@alumni.purdue.edu
|
||||
build_command_prepend: "mkdir coverity_build && cd coverity_build && cmake .."
|
||||
build_command: "make"
|
||||
branch_pattern: ignore
|
||||
|
||||
before_install:
|
||||
- sudo pip install codecov
|
||||
- echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-
|
||||
|
||||
install:
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -y -qq check libcunit1 libcunit1-dev uuid-dev valgrind
|
||||
|
||||
script:
|
||||
- mkdir build
|
||||
- cd build
|
||||
- cmake .. -DINTEGRATION_TESTING:BOOL=false -DDISABLE_VALGRIND:BOOL=false -DENABLE_SESHAT:BOOL=true -DFEATURE_DNS_QUERY:BOOL=true
|
||||
- make
|
||||
- export ARGS="-V"
|
||||
- make test
|
||||
|
||||
after_success:
|
||||
- codecov
|
||||
|
||||
env:
|
||||
global:
|
||||
- secure: EwQu1WDUgIF5qM5tnKj/+NCPz9t15y289bbqFo0wDhyfTlJGS9buQeJNeVLtNJBEOngpo+AkaPGvh/d9NZ0vLdxu+K/e+HhA6kOTxUrCHD8+4oX9XpVs/XvQmD1COlJYeeqd8bJMKtlFtonGdMJogxpEFQzv4fQjmoARvL2ciV4OB0MBcD5Lsb72L3a0aJT69F6WFuDpgGj2eIQyCDSTPNIi2X7EA8R33lxnntFDn8Vj6qSBbVOI2S5R5S+JUCMp1Q1ZbEqmh6j+wKtszWj8wGqfz8Ol5+GYl511bExb+hwvV5zen0Ol0+2LQmSpYhbQZ7prfI8AclLLwhDUrP+WDOv34vwd4EWQ1OoLqG23HbBygCxPSBIB6ZxPtVkzjVlOK8qqIB5QXqCyq8sPKlrXfntOQ+Ha938cIA+A0ag+26MLbhDGj8k3Os7BdY/oqNTKADZQdxfGKhCiA9qO2clpMyRXoE0q6hv9dYoG/2c4sxH8DKsT8XY/QbGmiBsk0DWHcpxkObCsHUxVKi+gIBGSL/tSjz2IJfQVZkdl2hhcyStGuPKbiwAlW3HydMk0VgRhVmHBIc41Cv7vPdMEVf/XiFhr2utRX468M/LR8vkhhokKl1xkVIiquwCPYPzZVAFARHTlaBMhz9kQVtTAHf2JkHuM9XcLWKW996FiSeswKyI=
|
||||
- secure: LQK36EsQdIJw7eSW1yz+yh3+yJdp8cznynBjE3whOEVI2KHZimr+vtK5hxE6TH0QjYyrb/BFgRql6CtLprpaABSEC9gpqpahu50jiAkjKC8DtfSloAbH5jj+ZllaPjURocerllNLVZxiRM/WCuJAy0nzBpAyx62YmVlEYi+zYD67d3wG6gLwso6l2DWuPPze6t5NmbUmH9hNk52++TZalwMtZFdibQoYm64vCTT5gycujw6ZDa8GD0m+Yryvc20kLlWPOVS9lN1iEGo98/gj8Ops8w0iw6k7SfEkvvFsKEUDr77wAN5Tk4tGq7odVrD/y3W9AsHkkSb1B6RqVWkcW3SjCAQc03jhdaBxXwcoJZcYahY21CB12EP7p0HSjEbvIzNpk0D9MulsGaMPlOudnKdG0/kmD7oIAiXjfC7PiPBBFIc/cVF5VAKNTUInEVfcKvlLpqDatwjB+qgb7pld24dUPuJw+yOgglk7J7xckJYHFTHhk0PWI5oN66dndj3yyJp4dz1v64ViFFTG4PO4YPJydZxRxolg1eGMuG0UIYJK6RWcSQ+ZPBm4p78J8xfHtgUkvWvrHJoXC1qAzqx1XRzbHEeTJgbKgLrWY+B6nbNotw1RDX4lNDirp5EI6GqezoFJToZkqe3MRs8DrqhaFjUbbEzAxznRWmxnWNN3Ujc=
|
||||
# The next declaration is the encrypted COVERITY_SCAN_TOKEN, created
|
||||
# via the "travis encrypt" command using the project repo's public key
|
||||
- secure: "V/W4Z9/3uXpS83CvlZ1XfDAbHPIA2ID5G5s9GPcsUqoOASQdc6Y/DPejUlot+DgtiHOEdTr9n5iWDOuxqjcVnjVd6ag9i2m0PMqDhPj3fnUJM6dAeXIBda/qSuTsJTX4cIwb371R77cLcIUm35IEOSIAQOBCjh7RCf3ivGPUp+wobTonkNzDw6xqO90hx7NLnxwGSCcaNBFKOcLL0e7DXspp18lTWCSSaHELzXOyLlhZnWhC5tiFUIZk1ixm/cO1YEQH9AzgPJ5OYs+On0j8VT8XWMsxHu0zfkZkdZMAEOQbO6u4HBDePIfp+PoF1LwtX/UXfaEkUHZ0kNVXHfsN/KP7NHgTbASe9EXp+R4pcKEy4ZEbx+xpp7FlMQSJYiYiQbJ2FBrjwRPreXiHyCqn8htd0YNOTH4UykvO3NYxlTaMf9aE041lnLjUY18TuXrILz6SzMsGV+nYqfIci/NPuj/57k7nw127a93S4Mr/phXts9ZL8I7kagd8wKv3m5+7rmIfuSfS2kg2pTa0hk5uMqFWLG8AilUQ5t1ChylzPcl/Gdgi9OP0pG2WyUmkqOiSqhwwdg2ZCwptodwuonfbdKMSBuHOS8lLU1bGyCRdWsMoscSv/xn4t3ikzBsSDiKgI8xq2+aqQyHDeVneqAk1BbxiNIwoJeyVXq2EKU6MlgI="
|
||||
12
.whitesource
Normal file
12
.whitesource
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"scanSettings": {
|
||||
"baseBranches": []
|
||||
},
|
||||
"checkRunSettings": {
|
||||
"vulnerableCheckRunConclusionLevel": "failure",
|
||||
"displayMode": "diff"
|
||||
},
|
||||
"issueSettings": {
|
||||
"minSeverityLevel": "LOW"
|
||||
}
|
||||
}
|
||||
61
CHANGELOG.md
61
CHANGELOG.md
@@ -5,18 +5,20 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
- Security: Added support to use auth token during initial connect to cloud
|
||||
- Fix re-registration fails that lose a socket
|
||||
- Fix mutex error in service alive
|
||||
- Security: Mutual Authentication (mTLS or two way TLS)
|
||||
- Rename command line options for MTLS cert and Key
|
||||
- Update to use nanomsg v. 1.1.4
|
||||
- requestNewAuthToken will clear the token if it fails.
|
||||
- request auth token on every retry, not just after 403
|
||||
- update to use nopoll v 1.0.2
|
||||
- Add pause/resume heartBeatTimer
|
||||
- parodus event handler to listen to interface_down and interface_up event
|
||||
- Pause connection retry during interface_down event
|
||||
- Add additional HTTP headers for call to Themis from Convey
|
||||
- Add callback handler for initial cloud connection status change event
|
||||
- Fix Parodus connection stuck on interface up down received together
|
||||
- Update to use nopoll version 1.0.3
|
||||
|
||||
## [1.1.4]
|
||||
- on connect retry, requery jwt only if it failed before
|
||||
- put two timestamps in connection health file; start conn and current
|
||||
- change health file update interval to 240sec
|
||||
- use jitter in backoff delay
|
||||
- sendMessage to check cloud status == ONLINE before sending
|
||||
- when killed with SIGTERM, close will use msg in close reason file.
|
||||
|
||||
## [1.1.3]
|
||||
- Add callback handler for ping status change event
|
||||
- Fixed nopoll_conn_unref crash
|
||||
- Update retry timestamp in connection-health-file
|
||||
@@ -24,12 +26,26 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
- provide signal handlers so we shut down properly when INCLUDE_BREAKPAD active
|
||||
- send status code and reason in websocket close message
|
||||
- dont try to install handler for signal 9
|
||||
- on connect retry, requery jwt only if it failed before
|
||||
- put two timestamps in connection health file; start conn and current
|
||||
- change health file update interval to 240sec
|
||||
- use jitter in backoff delay
|
||||
- sendMessage to check cloud status == ONLINE before sending
|
||||
- when killed with SIGTERM, close will use msg in close reason file.
|
||||
|
||||
## [1.1.2]
|
||||
- Add pause/resume heartBeatTimer
|
||||
- parodus event handler to listen to interface_down and interface_up event
|
||||
- Pause connection retry during interface_down event
|
||||
|
||||
## [1.1.1]
|
||||
- Update to use nanomsg v. 1.1.4
|
||||
- requestNewAuthToken will clear the token if it fails.
|
||||
- request auth token on every retry, not just after 403
|
||||
- update to use nopoll v 1.0.2
|
||||
|
||||
## [1.0.4]
|
||||
- Fix re-registration fails that lose a socket
|
||||
- Fix mutex error in service alive
|
||||
- Security: Mutual Authentication (mTLS or two way TLS)
|
||||
- Rename command line options for MTLS cert and Key
|
||||
|
||||
## [1.0.3]
|
||||
- Security: Added support to use auth token during initial connect to cloud
|
||||
|
||||
## [1.0.2] - 2019-02-08
|
||||
- Refactored connection.c and updated corresponding unit tests
|
||||
@@ -79,6 +95,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
|
||||
### Security
|
||||
- Added command line arguments for secure token read and acquire. Token presented to cloud for authentication verification.
|
||||
- Added support for override functions to support drop root capabilities for parodus process
|
||||
|
||||
## [1.0.0] - 2017-11-17
|
||||
### Added
|
||||
@@ -88,7 +105,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
### Added
|
||||
- Initial creation
|
||||
|
||||
[Unreleased]: https://github.com/Comcast/parodus/compare/1.0.1...HEAD
|
||||
[Unreleased]: https://github.com/Comcast/parodus/compare/1.1.4...HEAD
|
||||
[1.1.4]: https://github.com/Comcast/parodus/compare/1.1.3...1.1.4
|
||||
[1.1.3]: https://github.com/Comcast/parodus/compare/1.1.2...1.1.3
|
||||
[1.1.2]: https://github.com/Comcast/parodus/compare/1.1.1...1.1.2
|
||||
[1.1.1]: https://github.com/Comcast/parodus/compare/1.0.4...1.1.1
|
||||
[1.0.4]: https://github.com/Comcast/parodus/compare/1.0.3...1.0.4
|
||||
[1.0.3]: https://github.com/Comcast/parodus/compare/1.0.2...1.0.3
|
||||
[1.0.2]: https://github.com/Comcast/parodus/compare/1.0.1...1.0.2
|
||||
[1.0.1]: https://github.com/Comcast/parodus/compare/1.0.0...1.0.1
|
||||
[1.0.0]: https://github.com/Comcast/parodus/compare/79fa7438de2b14ae64f869d52f5c127497bf9c3f...1.0.0
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
cmake_minimum_required(VERSION 2.8.7)
|
||||
|
||||
#project(parodus VERSION 1.1.15)
|
||||
project(parodus)
|
||||
|
||||
include(ExternalProject)
|
||||
@@ -42,6 +43,13 @@ include_directories(${INCLUDE_DIR}
|
||||
${INCLUDE_DIR}/cjwt
|
||||
)
|
||||
|
||||
if (ENABLE_WEBCFGBIN)
|
||||
include_directories(${INCLUDE_DIR}/rbus
|
||||
${INCLUDE_DIR}/rbus-core
|
||||
${INCLUDE_DIR}/rtmessage
|
||||
)
|
||||
endif (ENABLE_WEBCFGBIN)
|
||||
|
||||
# Get git commit hash
|
||||
#-------------------------------------------------------------------------------
|
||||
execute_process(
|
||||
@@ -85,7 +93,7 @@ add_dependencies(libtrower-base64 trower-base64)
|
||||
ExternalProject_Add(nopoll
|
||||
PREFIX ${PREFIX_DIR}/nopoll
|
||||
GIT_REPOSITORY https://github.com/Comcast/nopoll.git
|
||||
GIT_TAG "1.0.2"
|
||||
GIT_TAG "1.0.3"
|
||||
CONFIGURE_COMMAND COMMAND <SOURCE_DIR>/autogen.sh --prefix=${PREFIX}
|
||||
--includedir=${INCLUDE_DIR}
|
||||
--libdir=${LIBRARY_DIR}
|
||||
@@ -164,8 +172,8 @@ add_dependencies(libcimplog cimplog)
|
||||
ExternalProject_Add(wrp-c
|
||||
DEPENDS trower-base64 msgpack cimplog
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/wrp-c
|
||||
GIT_REPOSITORY https://github.com/Comcast/wrp-c.git
|
||||
GIT_TAG "1.0.1"
|
||||
GIT_REPOSITORY https://github.com/xmidt-org/wrp-c.git
|
||||
GIT_TAG "71f8a39fe39f98da007ed4cdabbb192be1da1685"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
|
||||
-DMSGPACK_ENABLE_CXX=OFF
|
||||
-DMSGPACK_BUILD_EXAMPLES=OFF
|
||||
@@ -228,6 +236,51 @@ include_directories(${INCLUDE_DIR}
|
||||
|
||||
endif (FEATURE_DNS_QUERY)
|
||||
|
||||
if (ENABLE_WEBCFGBIN)
|
||||
# rtMessage external dependency
|
||||
#-------------------------------------------------------------------------------
|
||||
ExternalProject_Add(rtMessage
|
||||
DEPENDS cJSON
|
||||
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=OFF
|
||||
-DCJSON_BUILD=OFF
|
||||
-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 (ENABLE_WEBCFGBIN)
|
||||
|
||||
if (BUILD_TESTING)
|
||||
# cmocka external dependency
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -252,6 +305,14 @@ if (FEATURE_DNS_QUERY)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFEATURE_DNS_QUERY ")
|
||||
endif (FEATURE_DNS_QUERY)
|
||||
|
||||
if (ENABLE_WEBCFGBIN)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_WEBCFGBIN ")
|
||||
endif (ENABLE_WEBCFGBIN)
|
||||
|
||||
if (WAN_FAILOVER_SUPPORTED)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWAN_FAILOVER_SUPPORTED ")
|
||||
endif (WAN_FAILOVER_SUPPORTED)
|
||||
|
||||
link_directories ( ${LIBRARY_DIR} ${COMMON_LIBRARY_DIR} ${LIBRARY_DIR64} )
|
||||
add_subdirectory(src)
|
||||
if (BUILD_TESTING)
|
||||
|
||||
14
README.md
14
README.md
@@ -1,10 +1,16 @@
|
||||
<!--
|
||||
SPDX-FileCopyrightText: 2016-2021 Comcast Cable Communications Management, LLC
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
# parodus
|
||||
|
||||
[](https://travis-ci.org/xmidt-org/parodus)
|
||||
[](http://codecov.io/github/Comcast/parodus?branch=master)
|
||||
[](https://github.com/xmidt-org/parodus/actions)
|
||||
[](http://codecov.io/github/xmidt-org/parodus?branch=master)
|
||||
[](https://scan.coverity.com/projects/comcast-parodus)
|
||||
[](https://github.com/Comcast/parodus/blob/master/LICENSE)
|
||||
[](CHANGELOG.md)
|
||||
[](https://sonarcloud.io/dashboard?id=xmidt-org_parodus)
|
||||
[](https://lgtm.com/projects/g/xmidt-org/parodus/context:cpp)
|
||||
[](https://github.com/xmidt-org/parodus/blob/master/LICENSE)
|
||||
[](CHANGELOG.md)
|
||||
|
||||
|
||||
C implementation of the XMiDT client coordinator
|
||||
|
||||
@@ -15,7 +15,7 @@ set(SOURCES main.c mutex.c networking.c nopoll_helpers.c heartBeat.c nopoll_hand
|
||||
ParodusInternal.c string_helpers.c time.c config.c conn_interface.c
|
||||
connection.c spin_thread.c client_list.c service_alive.c
|
||||
upstream.c downstream.c thread_tasks.c partners_check.c token.c event_handler.c
|
||||
crud_interface.c crud_tasks.c crud_internal.c close_retry.c auth_token.c)
|
||||
crud_interface.c crud_tasks.c crud_internal.c close_retry.c auth_token.c privilege.c)
|
||||
|
||||
if (ENABLE_SESHAT)
|
||||
set(SOURCES ${SOURCES} seshat_interface.c)
|
||||
@@ -23,6 +23,15 @@ else()
|
||||
set(SOURCES ${SOURCES} seshat_interface_stub.c)
|
||||
endif (ENABLE_SESHAT)
|
||||
|
||||
if (ENABLE_WEBCFGBIN)
|
||||
set(SOURCES ${SOURCES} upstream_rbus.c xmidtsend_rbus.c)
|
||||
endif (ENABLE_WEBCFGBIN)
|
||||
|
||||
if (WAN_FAILOVER_SUPPORTED)
|
||||
message(STATUS "WAN_FAILOVER_SUPPORTED is supported")
|
||||
else()
|
||||
message(STATUS "WAN_FAILOVER_SUPPORTED is not supported")
|
||||
endif (WAN_FAILOVER_SUPPORTED)
|
||||
|
||||
add_executable(parodus ${SOURCES})
|
||||
|
||||
@@ -53,5 +62,7 @@ if (ENABLE_SESHAT)
|
||||
target_link_libraries (parodus -llibseshat)
|
||||
endif (ENABLE_SESHAT)
|
||||
|
||||
|
||||
if (ENABLE_WEBCFGBIN)
|
||||
target_link_libraries (parodus -lrbus -lrbus-core -lrtMessage)
|
||||
endif (ENABLE_WEBCFGBIN)
|
||||
install (TARGETS parodus DESTINATION bin)
|
||||
|
||||
@@ -69,9 +69,9 @@ char* getWebpaConveyHeader()
|
||||
cJSON_AddStringToObject(response, WEBPA_PROTOCOL, get_parodus_cfg()->webpa_protocol);
|
||||
}
|
||||
|
||||
if(strlen(get_parodus_cfg()->webpa_interface_used)!=0)
|
||||
if(strlen(getWebpaInterface())!=0)
|
||||
{
|
||||
cJSON_AddStringToObject(response, WEBPA_INTERFACE, get_parodus_cfg()->webpa_interface_used);
|
||||
cJSON_AddStringToObject(response, WEBPA_INTERFACE, getWebpaInterface());
|
||||
}
|
||||
|
||||
if(strlen(get_parodus_cfg()->hw_last_reboot_reason)!=0)
|
||||
|
||||
@@ -139,7 +139,6 @@ typedef struct {
|
||||
/*----------------------------------------------------------------------------*/
|
||||
extern bool g_shutdown;
|
||||
extern ParodusMsg *ParodusMsgQ;
|
||||
int numLoops;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Function Prototypes */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -162,7 +161,13 @@ int readFromFile(const char *file_name, char **data);
|
||||
void timespec_diff(struct timespec *start, struct timespec *stop,
|
||||
struct timespec *result);
|
||||
|
||||
|
||||
#ifdef ENABLE_WEBCFGBIN
|
||||
void subscribeRBUSevent();
|
||||
int regXmidtSendDataMethod();
|
||||
#endif
|
||||
#ifdef WAN_FAILOVER_SUPPORTED
|
||||
void setWebpaInterface(char *value);
|
||||
#endif
|
||||
/*------------------------------------------------------------------------------*/
|
||||
/* For interface_down_event Flag */
|
||||
/*------------------------------------------------------------------------------*/
|
||||
@@ -179,8 +184,11 @@ void set_interface_down_event();
|
||||
pthread_cond_t *get_interface_down_con();
|
||||
|
||||
pthread_mutex_t *get_interface_down_mut();
|
||||
|
||||
|
||||
pthread_cond_t *get_global_cloud_status_cond(void);
|
||||
|
||||
pthread_mutex_t *get_global_cloud_status_mut(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
110
src/auth_token.c
110
src/auth_token.c
@@ -24,6 +24,7 @@
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include "config.h"
|
||||
#include "connection.h"
|
||||
#include "auth_token.h"
|
||||
#include "ParodusInternal.h"
|
||||
#include <cjwt/cjwt.h>
|
||||
@@ -31,13 +32,14 @@
|
||||
#include <curl/curl.h>
|
||||
#include <uuid/uuid.h>
|
||||
|
||||
#define MAX_BUF_SIZE 128
|
||||
#define MAX_BUF_SIZE 256
|
||||
#define CURL_TIMEOUT_SEC 25L
|
||||
#define MAX_CURL_RETRY_COUNT 3
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void createCurlheader(char *mac_header, char *serial_header, char *uuid_header, char *transaction_uuid, struct curl_slist *list, struct curl_slist **header_list);
|
||||
void createCurlheader(struct curl_slist *list, struct curl_slist **header_list);
|
||||
long g_response_code;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
@@ -62,10 +64,7 @@ int requestNewAuthToken(char *newToken, size_t len, int r_count)
|
||||
struct curl_slist *list = NULL;
|
||||
struct curl_slist *headers_list = NULL;
|
||||
|
||||
char *mac_header = NULL;
|
||||
char *serial_header = NULL;
|
||||
char *uuid_header = NULL;
|
||||
char *transaction_uuid = NULL;
|
||||
char webpa_interface[64]={'\0'};
|
||||
double total;
|
||||
|
||||
struct token_data data;
|
||||
@@ -77,14 +76,15 @@ int requestNewAuthToken(char *newToken, size_t len, int r_count)
|
||||
{
|
||||
data.data[0] = '\0';
|
||||
|
||||
createCurlheader(mac_header, serial_header, uuid_header, transaction_uuid, list, &headers_list);
|
||||
createCurlheader(list, &headers_list);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, get_parodus_cfg()->token_server_url);
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, CURL_TIMEOUT_SEC);
|
||||
|
||||
if(get_parodus_cfg()->webpa_interface_used !=NULL && strlen(get_parodus_cfg()->webpa_interface_used) >0)
|
||||
parStrncpy(webpa_interface, getWebpaInterface(), sizeof(webpa_interface));
|
||||
if(webpa_interface !=NULL && strlen(webpa_interface) >0)
|
||||
{
|
||||
curl_easy_setopt(curl, CURLOPT_INTERFACE, get_parodus_cfg()->webpa_interface_used);
|
||||
curl_easy_setopt(curl, CURLOPT_INTERFACE, webpa_interface);
|
||||
}
|
||||
/* set callback for writing received data */
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback_fn);
|
||||
@@ -263,52 +263,60 @@ char* generate_trans_uuid()
|
||||
}
|
||||
|
||||
/* @brief function to create curl header contains mac, serial number and uuid.
|
||||
* @param[in] mac_header mac address header key value pair
|
||||
* @param[in] serial_header serial number key value pair
|
||||
* @param[in] uuid_header transaction uuid key value pair
|
||||
* @param[in] h the auth headers to populate
|
||||
* @param[in] list temp curl header list
|
||||
* @param[out] header_list output curl header list
|
||||
*/
|
||||
void createCurlheader(char *mac_header, char *serial_header, char *uuid_header, char *transaction_uuid, struct curl_slist *list, struct curl_slist **header_list)
|
||||
void createCurlheader(struct curl_slist *list, struct curl_slist **header_list)
|
||||
{
|
||||
mac_header = (char *) malloc(sizeof(char)*MAX_BUF_SIZE);
|
||||
if(mac_header !=NULL)
|
||||
{
|
||||
snprintf(mac_header, MAX_BUF_SIZE, "X-Midt-Mac-Address: %s", get_parodus_cfg()->hw_mac);
|
||||
ParodusPrint("mac_header formed %s\n", mac_header);
|
||||
list = curl_slist_append(list, mac_header);
|
||||
free(mac_header);
|
||||
mac_header = NULL;
|
||||
}
|
||||
char buf[MAX_BUF_SIZE];
|
||||
char *uuid = NULL;
|
||||
|
||||
serial_header = (char *) malloc(sizeof(char)*MAX_BUF_SIZE);
|
||||
if(serial_header !=NULL)
|
||||
{
|
||||
snprintf(serial_header, MAX_BUF_SIZE, "X-Midt-Serial-Number: %s", get_parodus_cfg()->hw_serial_number);
|
||||
ParodusPrint("serial_header formed %s\n", serial_header);
|
||||
list = curl_slist_append(list, serial_header);
|
||||
free(serial_header);
|
||||
serial_header = NULL;
|
||||
}
|
||||
snprintf(buf, MAX_BUF_SIZE, "X-Midt-Mac-Address: %s", get_parodus_cfg()->hw_mac);
|
||||
ParodusPrint("mac_header formed %s\n", buf);
|
||||
list = curl_slist_append(list, buf);
|
||||
|
||||
transaction_uuid = generate_trans_uuid();
|
||||
if(transaction_uuid !=NULL)
|
||||
{
|
||||
uuid_header = (char *) malloc(sizeof(char)*MAX_BUF_SIZE);
|
||||
if(uuid_header !=NULL)
|
||||
{
|
||||
snprintf(uuid_header, MAX_BUF_SIZE, "X-Midt-Uuid: %s", transaction_uuid);
|
||||
ParodusInfo("uuid_header formed %s\n", uuid_header);
|
||||
list = curl_slist_append(list, uuid_header);
|
||||
free(transaction_uuid);
|
||||
transaction_uuid = NULL;
|
||||
free(uuid_header);
|
||||
uuid_header = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Failed to generate transaction_uuid\n");
|
||||
}
|
||||
*header_list = list;
|
||||
snprintf(buf, MAX_BUF_SIZE, "X-Midt-Serial-Number: %s", get_parodus_cfg()->hw_serial_number);
|
||||
ParodusPrint("serial_header formed %s\n", buf);
|
||||
list = curl_slist_append(list, buf);
|
||||
|
||||
uuid = generate_trans_uuid();
|
||||
if(uuid !=NULL) {
|
||||
snprintf(buf, MAX_BUF_SIZE, "X-Midt-Uuid: %s", uuid);
|
||||
ParodusInfo("uuid_header formed %s\n", buf);
|
||||
list = curl_slist_append(list, buf);
|
||||
free(uuid);
|
||||
} else {
|
||||
ParodusError("Failed to generate transaction_uuid\n");
|
||||
}
|
||||
|
||||
snprintf(buf, MAX_BUF_SIZE, "X-Midt-Partner-Id: %s", get_parodus_cfg()->partner_id);
|
||||
ParodusInfo("partnerid_header formed %s\n", buf);
|
||||
list = curl_slist_append(list, buf);
|
||||
|
||||
snprintf(buf, MAX_BUF_SIZE, "X-Midt-Hardware-Model: %s", get_parodus_cfg()->hw_model);
|
||||
list = curl_slist_append(list, buf);
|
||||
|
||||
snprintf(buf, MAX_BUF_SIZE, "X-Midt-Hardware-Manufacturer: %s", get_parodus_cfg()->hw_manufacturer);
|
||||
list = curl_slist_append(list, buf);
|
||||
|
||||
snprintf(buf, MAX_BUF_SIZE, "X-Midt-Firmware-Name: %s", get_parodus_cfg()->fw_name);
|
||||
list = curl_slist_append(list, buf);
|
||||
|
||||
snprintf(buf, MAX_BUF_SIZE, "X-Midt-Protocol: %s", get_parodus_cfg()->webpa_protocol);
|
||||
list = curl_slist_append(list, buf);
|
||||
|
||||
snprintf(buf, MAX_BUF_SIZE, "X-Midt-Interface-Used: %s", getWebpaInterface());
|
||||
list = curl_slist_append(list, buf);
|
||||
|
||||
snprintf(buf, MAX_BUF_SIZE, "X-Midt-Last-Reboot-Reason: %s", get_parodus_cfg()->hw_last_reboot_reason);
|
||||
list = curl_slist_append(list, buf);
|
||||
|
||||
snprintf(buf, MAX_BUF_SIZE, "X-Midt-Last-Reconnect-Reason: %s", get_global_reconnect_reason());
|
||||
list = curl_slist_append(list, buf);
|
||||
|
||||
snprintf(buf, MAX_BUF_SIZE, "X-Midt-Boot-Retry-Wait: %d", get_parodus_cfg()->boot_retry_wait);
|
||||
list = curl_slist_append(list, buf);
|
||||
|
||||
*header_list = list;
|
||||
}
|
||||
|
||||
@@ -294,3 +294,24 @@ int sendMsgtoRegisteredClients(char *dest,const char **Msg,size_t msgSize)
|
||||
release_global_node ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//To check client registration status with parodus.
|
||||
int checkClientStatus(char *serviceName)
|
||||
{
|
||||
reg_list_item_t *temp = NULL;
|
||||
temp = get_global_node();
|
||||
while (NULL != temp)
|
||||
{
|
||||
ParodusPrint("node is pointing to temp->service_name %s \n",temp->service_name);
|
||||
// Sending message to registered clients
|
||||
if( strcmp(serviceName, temp->service_name) == 0)
|
||||
{
|
||||
release_global_node ();
|
||||
return 1;
|
||||
}
|
||||
ParodusPrint("checking the next item in the list\n");
|
||||
temp= temp->next;
|
||||
}
|
||||
release_global_node ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ int sendMsgtoRegisteredClients(char *dest,const char **Msg,size_t msgSize);
|
||||
|
||||
reg_list_item_t * get_global_node(void);
|
||||
void release_global_node (void);
|
||||
|
||||
int checkClientStatus();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
80
src/config.c
80
src/config.c
@@ -33,13 +33,30 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
pthread_mutex_t config_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
//For sending cond signal when cloud status is ONLINE
|
||||
pthread_mutex_t cloud_status_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t cloud_status_cond=PTHREAD_COND_INITIALIZER;
|
||||
|
||||
char webpa_interface[64]={'\0'};
|
||||
|
||||
char cloud_status[32]={'\0'};
|
||||
static ParodusCfg parodusCfg;
|
||||
static unsigned int rsa_algorithms =
|
||||
(1<<alg_rs256) | (1<<alg_rs384) | (1<<alg_rs512);
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
pthread_cond_t *get_global_cloud_status_cond(void)
|
||||
{
|
||||
return &cloud_status_cond;
|
||||
}
|
||||
|
||||
pthread_mutex_t *get_global_cloud_status_mut(void)
|
||||
{
|
||||
return &cloud_status_mut;
|
||||
}
|
||||
|
||||
ParodusCfg *get_parodus_cfg(void)
|
||||
{
|
||||
@@ -61,6 +78,27 @@ void reset_cloud_disconnect_reason(ParodusCfg *cfg)
|
||||
cfg->cloud_disconnect = NULL;
|
||||
}
|
||||
|
||||
void set_cloud_status(char *status)
|
||||
{
|
||||
if(status != NULL)
|
||||
{
|
||||
pthread_mutex_lock(&config_mut);
|
||||
get_parodus_cfg()->cloud_status = status;
|
||||
if(strcmp (status, CLOUD_STATUS_ONLINE) == 0)
|
||||
{
|
||||
pthread_cond_signal(&cloud_status_cond);
|
||||
}
|
||||
pthread_mutex_unlock(&config_mut);
|
||||
}
|
||||
}
|
||||
|
||||
char *get_cloud_status(void)
|
||||
{
|
||||
pthread_mutex_lock(&config_mut);
|
||||
parStrncpy(cloud_status, get_parodus_cfg()->cloud_status, sizeof(cloud_status));
|
||||
pthread_mutex_unlock(&config_mut);
|
||||
return cloud_status;
|
||||
}
|
||||
|
||||
const char *get_tok (const char *src, int delim, char *result, int resultsize)
|
||||
{
|
||||
@@ -146,9 +184,9 @@ void read_key_from_file (const char *fname, char *buf, size_t buflen)
|
||||
int parse_mac_address (char *target, const char *arg)
|
||||
{
|
||||
int count = 0;
|
||||
int i;
|
||||
int i, j;
|
||||
char c;
|
||||
|
||||
char *mac = target;
|
||||
for (i=0; (c=arg[i]) != 0; i++) {
|
||||
if (c !=':')
|
||||
count++;
|
||||
@@ -160,6 +198,13 @@ int parse_mac_address (char *target, const char *arg)
|
||||
*(target++) = c;
|
||||
}
|
||||
*target = 0; // terminating null
|
||||
|
||||
//convert mac to lowercase
|
||||
for(j = 0; mac[j]; j++)
|
||||
{
|
||||
mac[j] = tolower(mac[j]);
|
||||
}
|
||||
ParodusPrint("mac in lowercase is %s\n", mac);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -214,8 +259,13 @@ int parse_webpa_url__ (const char *full_url,
|
||||
if(openBracket != NULL){
|
||||
//Remove [ from server address
|
||||
char *remove = server_addr;
|
||||
int i;
|
||||
|
||||
// Strings can overlap, so don't use strncpy()
|
||||
remove++;
|
||||
parStrncpy (server_addr, remove, server_addr_buflen);
|
||||
for( i = 0; i < server_addr_buflen; i++ ) {
|
||||
server_addr[i] = remove[i];
|
||||
}
|
||||
closeBracket = strchr(server_addr,']');
|
||||
if(closeBracket != NULL){
|
||||
//Remove ] by making it as null
|
||||
@@ -719,7 +769,7 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg)
|
||||
}
|
||||
if(strlen(config->webpa_interface_used )!=0)
|
||||
{
|
||||
parStrncpy(cfg->webpa_interface_used, config->webpa_interface_used,sizeof(cfg->webpa_interface_used));
|
||||
parStrncpy(getWebpaInterface(), config->webpa_interface_used,sizeof(getWebpaInterface()));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -843,4 +893,26 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WAN_FAILOVER_SUPPORTED
|
||||
void setWebpaInterface(char *value)
|
||||
{
|
||||
pthread_mutex_lock (&config_mut);
|
||||
parStrncpy(get_parodus_cfg()->webpa_interface_used, value, sizeof(get_parodus_cfg()->webpa_interface_used));
|
||||
pthread_mutex_unlock (&config_mut);
|
||||
}
|
||||
#endif
|
||||
|
||||
char *getWebpaInterface(void)
|
||||
{
|
||||
#ifdef WAN_FAILOVER_SUPPORTED
|
||||
ParodusPrint("WAN_FAILOVER_SUPPORTED mode \n");
|
||||
pthread_mutex_lock (&config_mut);
|
||||
parStrncpy(webpa_interface, get_parodus_cfg()->webpa_interface_used, sizeof(webpa_interface));
|
||||
pthread_mutex_unlock (&config_mut);
|
||||
#else
|
||||
parStrncpy(webpa_interface, get_parodus_cfg()->webpa_interface_used, sizeof(webpa_interface));
|
||||
#endif
|
||||
ParodusPrint("webpa_interface:%s\n", webpa_interface);
|
||||
return webpa_interface;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#ifndef _CONFIG_H_
|
||||
#define _CONFIG_H_
|
||||
|
||||
#include <pthread.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -75,7 +76,7 @@ typedef struct
|
||||
char hw_serial_number[64];
|
||||
char hw_manufacturer[64];
|
||||
char hw_mac[64];
|
||||
char hw_last_reboot_reason[64];
|
||||
char hw_last_reboot_reason[128];
|
||||
char fw_name[64];
|
||||
unsigned int boot_time;
|
||||
unsigned int webpa_ping_timeout;
|
||||
@@ -139,6 +140,10 @@ void set_parodus_cfg(ParodusCfg *);
|
||||
char *get_token_application(void) ;
|
||||
void set_cloud_disconnect_reason(ParodusCfg *cfg, char *disconn_reason);
|
||||
void reset_cloud_disconnect_reason(ParodusCfg *cfg);
|
||||
char *getWebpaInterface(void);
|
||||
void set_cloud_status(char *status);
|
||||
char *get_cloud_status(void);
|
||||
|
||||
/**
|
||||
* parse a webpa url. Extract the server address, the port
|
||||
* and return whether it's secure or not
|
||||
|
||||
@@ -77,6 +77,7 @@ void createSocketConnection(void (* initKeypress)())
|
||||
server_list_t server_list;
|
||||
bool seshat_registered = false;
|
||||
int create_conn_rtn = 0;
|
||||
int nopoll_returnvalue = 0;
|
||||
unsigned int webpa_ping_timeout_ms = 1000 * get_parodus_cfg()->webpa_ping_timeout;
|
||||
unsigned int heartBeatTimer = 0;
|
||||
struct timespec start_svc_alive_timer;
|
||||
@@ -112,6 +113,13 @@ void createSocketConnection(void (* initKeypress)())
|
||||
UpStreamMsgQ = NULL;
|
||||
StartThread(handle_upstream, &upstream_tid);
|
||||
StartThread(processUpstreamMessage, &upstream_msg_tid);
|
||||
#ifdef ENABLE_WEBCFGBIN
|
||||
subscribeRBUSevent();
|
||||
regXmidtSendDataMethod();
|
||||
#endif
|
||||
#ifdef WAN_FAILOVER_SUPPORTED
|
||||
subscribeCurrentActiveInterfaceEvent();
|
||||
#endif
|
||||
ParodusMsgQ = NULL;
|
||||
StartThread(messageHandlerTask, &downstream_tid);
|
||||
StartThread(serviceAliveTask, &svc_alive_tid);
|
||||
@@ -131,14 +139,17 @@ void createSocketConnection(void (* initKeypress)())
|
||||
struct timespec start, stop, diff;
|
||||
int time_taken_ms;
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &start);
|
||||
nopoll_loop_wait(ctx, 5000000);
|
||||
clock_gettime(CLOCK_REALTIME, &stop);
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
nopoll_returnvalue = nopoll_loop_wait(ctx, 5000000);
|
||||
clock_gettime(CLOCK_MONOTONIC, &stop);
|
||||
|
||||
timespec_diff(&start, &stop, &diff);
|
||||
time_taken_ms = diff.tv_sec * 1000 + (diff.tv_nsec / 1000000);
|
||||
|
||||
// ParodusInfo("nopoll_loop_wait() time %d msec\n", time_taken_ms);
|
||||
if(time_taken_ms/1000 != 5)
|
||||
{
|
||||
ParodusInfo("nopoll_loop_wait value %d,nopoll_loop_wait() time %d msec\n",nopoll_returnvalue, time_taken_ms);
|
||||
}
|
||||
ParodusPrint("webpa_ping_timeout_ms %d msec\n", webpa_ping_timeout_ms);
|
||||
heartBeatTimer = get_heartBeatTimer();
|
||||
if(heartBeatTimer >= webpa_ping_timeout_ms)
|
||||
{
|
||||
@@ -195,7 +206,8 @@ void createSocketConnection(void (* initKeypress)())
|
||||
}
|
||||
createNopollConnection(ctx, &server_list);
|
||||
}
|
||||
} while(!get_close_retry() && !g_shutdown);
|
||||
//process exit only when g_shutdown is true.
|
||||
} while(FOREVER() && !g_shutdown);
|
||||
|
||||
pthread_mutex_lock (get_global_svc_mut());
|
||||
pthread_cond_signal (get_global_svc_con());
|
||||
|
||||
@@ -62,6 +62,10 @@ enum {
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
parodusOnConnStatusChangeHandler on_conn_status_change;
|
||||
|
||||
parodusOnPingStatusChangeHandler on_ping_status_change;
|
||||
|
||||
pthread_mutex_t backoff_delay_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t backoff_delay_con=PTHREAD_COND_INITIALIZER;
|
||||
|
||||
@@ -695,7 +699,8 @@ int wait_while_interface_down()
|
||||
if (rtn != 0)
|
||||
ParodusError
|
||||
("Error on pthread_cond_wait (%d) in wait_while_interface_down\n", rtn);
|
||||
if ((rtn != 0) || g_shutdown) {
|
||||
if (g_shutdown) {
|
||||
ParodusInfo("Received g_shutdown during interface down wait, returning\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -712,9 +717,9 @@ int createNopollConnection(noPollCtx *ctx, server_list_t *server_list)
|
||||
{
|
||||
create_connection_ctx_t conn_ctx;
|
||||
int max_retry_count;
|
||||
struct timespec connect_time,*connectTimePtr;
|
||||
connectTimePtr = &connect_time;
|
||||
backoff_timer_t backoff_timer;
|
||||
static int init_conn_failure=1;
|
||||
struct sysinfo l_sSysInfo;
|
||||
|
||||
if(ctx == NULL) {
|
||||
return nopoll_false;
|
||||
@@ -750,6 +755,14 @@ int createNopollConnection(noPollCtx *ctx, server_list_t *server_list)
|
||||
}
|
||||
/* if we failed to connect, don't reuse the redirect server */
|
||||
free_server (&conn_ctx.server_list->redirect);
|
||||
|
||||
/* On initial connect failure, invoke conn status change event as "failed" only 1 time*/
|
||||
if((NULL != on_conn_status_change) && init && init_conn_failure)
|
||||
{
|
||||
on_conn_status_change("failed");
|
||||
init_conn_failure=0;
|
||||
}
|
||||
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
/* if we don't already have a valid jwt, look up server information */
|
||||
if (server_is_null (&conn_ctx.server_list->jwt))
|
||||
@@ -771,8 +784,14 @@ int createNopollConnection(noPollCtx *ctx, server_list_t *server_list)
|
||||
OnboardLog("Connected to server\n");
|
||||
}
|
||||
|
||||
get_parodus_cfg()->cloud_status = CLOUD_STATUS_ONLINE;
|
||||
ParodusInfo("cloud_status set as %s after successful connection\n", get_parodus_cfg()->cloud_status);
|
||||
set_cloud_status(CLOUD_STATUS_ONLINE);
|
||||
ParodusInfo("cloud_status set as %s after successful connection\n", get_cloud_status());
|
||||
|
||||
/* On initial connect success, invoke conn status change event as "success" */
|
||||
if((NULL != on_conn_status_change) && init)
|
||||
{
|
||||
on_conn_status_change("success");
|
||||
}
|
||||
|
||||
// Invoke the ping status change event callback as "received" ping
|
||||
if(NULL != on_ping_status_change)
|
||||
@@ -780,9 +799,9 @@ int createNopollConnection(noPollCtx *ctx, server_list_t *server_list)
|
||||
on_ping_status_change("received");
|
||||
}
|
||||
|
||||
if((get_parodus_cfg()->boot_time != 0) && init) {
|
||||
getCurrentTime(connectTimePtr);
|
||||
ParodusInfo("connect_time-diff-boot_time=%d\n", connectTimePtr->tv_sec - get_parodus_cfg()->boot_time);
|
||||
if(init) {
|
||||
sysinfo(&l_sSysInfo);
|
||||
ParodusInfo("connect_time-diff-boot_time=%ld\n", l_sSysInfo.uptime);
|
||||
init = 0; //set init to 0 so that this is logged only during process start up and not during reconnect
|
||||
}
|
||||
|
||||
@@ -842,7 +861,7 @@ static noPollConnOpts * createConnOpts (char * extra_headers, bool secure)
|
||||
nopoll_conn_opts_ssl_peer_verify (opts, nopoll_true);
|
||||
nopoll_conn_opts_set_ssl_protocol (opts, NOPOLL_METHOD_TLSV1_2);
|
||||
}
|
||||
nopoll_conn_opts_set_interface (opts,get_parodus_cfg()->webpa_interface_used);
|
||||
nopoll_conn_opts_set_interface (opts,getWebpaInterface());
|
||||
nopoll_conn_opts_set_extra_headers (opts,extra_headers);
|
||||
return opts;
|
||||
}
|
||||
@@ -882,8 +901,8 @@ void close_and_unref_connection(noPollConn *conn, bool is_shutting_down)
|
||||
{
|
||||
if (conn) {
|
||||
close_conn (conn, is_shutting_down);
|
||||
get_parodus_cfg()->cloud_status = CLOUD_STATUS_OFFLINE;
|
||||
ParodusInfo("cloud_status set as %s after connection close\n", get_parodus_cfg()->cloud_status);
|
||||
set_cloud_status(CLOUD_STATUS_OFFLINE);
|
||||
ParodusInfo("cloud_status set as %s after connection close\n", get_cloud_status());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -932,3 +951,8 @@ void registerParodusOnPingStatusChangeHandler(parodusOnPingStatusChangeHandler c
|
||||
on_ping_status_change = callback_func;
|
||||
}
|
||||
|
||||
void registerParodusOnConnStatusChangeHandler(parodusOnConnStatusChangeHandler callback_func)
|
||||
{
|
||||
on_conn_status_change = callback_func;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,15 @@ extern "C" {
|
||||
#define SHUTDOWN_REASON_SYSTEM_RESTART "system_restarting"
|
||||
#define SHUTDOWN_REASON_SIGTERM "SIGTERM"
|
||||
|
||||
/**
|
||||
* parodusOnConnStatusChangeHandler - Function pointer
|
||||
* Used to define callback function to do additional processing
|
||||
* when websocket cloud connection status change event
|
||||
* i.e. "cloud-conn-status" as "fail" or "success"
|
||||
*/
|
||||
typedef void (*parodusOnConnStatusChangeHandler) (char * status);
|
||||
extern parodusOnConnStatusChangeHandler on_conn_status_change;
|
||||
|
||||
/**
|
||||
* parodusOnPingStatusChangeHandler - Function pointer
|
||||
* Used to define callback function to do additional processing
|
||||
@@ -44,7 +53,7 @@ extern "C" {
|
||||
* i.e. ping_miss or ping receive after miss
|
||||
*/
|
||||
typedef void (*parodusOnPingStatusChangeHandler) (char * status);
|
||||
parodusOnPingStatusChangeHandler on_ping_status_change;
|
||||
extern parodusOnPingStatusChangeHandler on_ping_status_change;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Function Prototypes */
|
||||
@@ -79,6 +88,9 @@ void set_cloud_disconnect_time(int disconnTime);
|
||||
void start_conn_in_progress (unsigned long start_time);
|
||||
void stop_conn_in_progress (void);
|
||||
|
||||
// To Register parodusOnConnStatusChangeHandler Callback function
|
||||
void registerParodusOnConnStatusChangeHandler(parodusOnConnStatusChangeHandler on_conn_status_change);
|
||||
|
||||
// To Register parodusOnPingStatusChangeHandler Callback function
|
||||
void registerParodusOnPingStatusChangeHandler(parodusOnPingStatusChangeHandler on_ping_status_change);
|
||||
|
||||
|
||||
@@ -26,6 +26,9 @@
|
||||
#include "config.h"
|
||||
#include "connection.h"
|
||||
#include "close_retry.h"
|
||||
#include "client_list.h"
|
||||
|
||||
#define SERVICE_STATUS "service-status"
|
||||
|
||||
static void freeObjArray(char *(*obj)[], int size);
|
||||
static int writeIntoCrudJson(cJSON *res_obj, char * object, cJSON *objValue, int freeFlag);
|
||||
@@ -33,6 +36,7 @@ static int parse_dest_elements_to_string(wrp_msg_t *reqMsg, char *(*obj)[]);
|
||||
static char* strdupptr( const char *s, const char *e );
|
||||
static int ConnDisconnectFromCloud(char *reason);
|
||||
static int validateDisconnectString(char *reason);
|
||||
static int getClientStatus(char *service, cJSON **jsonresponse);
|
||||
|
||||
int writeToJSON(char *data)
|
||||
{
|
||||
@@ -533,13 +537,13 @@ int retrieveFromMemory(char *keyName, cJSON **jsonresponse)
|
||||
}
|
||||
else if(strcmp(WEBPA_INTERFACE, keyName)==0)
|
||||
{
|
||||
if((get_parodus_cfg()->webpa_interface_used !=NULL)&& (strlen(get_parodus_cfg()->fw_name)==0))
|
||||
if((getWebpaInterface() !=NULL)&& (strlen(get_parodus_cfg()->fw_name)==0))
|
||||
{
|
||||
ParodusError("retrieveFromMemory: webpa_interface_used value is NULL\n");
|
||||
return -1;
|
||||
}
|
||||
ParodusInfo("retrieveFromMemory: keyName:%s value:%s\n",keyName,get_parodus_cfg()->webpa_interface_used);
|
||||
cJSON_AddItemToObject( *jsonresponse, WEBPA_INTERFACE , cJSON_CreateString(get_parodus_cfg()->webpa_interface_used));
|
||||
ParodusInfo("retrieveFromMemory: keyName:%s value:%s\n",keyName,getWebpaInterface());
|
||||
cJSON_AddItemToObject( *jsonresponse, WEBPA_INTERFACE , cJSON_CreateString(getWebpaInterface()));
|
||||
}
|
||||
else if(strcmp(WEBPA_URL, keyName)==0)
|
||||
{
|
||||
@@ -573,20 +577,20 @@ int retrieveFromMemory(char *keyName, cJSON **jsonresponse)
|
||||
}
|
||||
else if(strcmp(CLOUD_STATUS, keyName)==0)
|
||||
{
|
||||
if(get_parodus_cfg()->cloud_status ==NULL)
|
||||
if(get_cloud_status() ==NULL)
|
||||
{
|
||||
ParodusError("retrieveFromMemory: cloud_status value is NULL\n");
|
||||
return -1;
|
||||
}
|
||||
else if((get_parodus_cfg()->cloud_status !=NULL) && (strlen(get_parodus_cfg()->cloud_status)==0))
|
||||
else if((get_cloud_status() !=NULL) && (strlen(get_cloud_status())==0))
|
||||
{
|
||||
ParodusError("retrieveFromMemory: cloud_status value is empty\n");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusInfo("retrieveFromMemory: keyName:%s value:%s\n", keyName, get_parodus_cfg()->cloud_status);
|
||||
cJSON_AddItemToObject( *jsonresponse, CLOUD_STATUS , cJSON_CreateString(get_parodus_cfg()->cloud_status));
|
||||
ParodusInfo("retrieveFromMemory: keyName:%s value:%s\n", keyName, get_cloud_status());
|
||||
cJSON_AddItemToObject( *jsonresponse, CLOUD_STATUS , cJSON_CreateString(get_cloud_status()));
|
||||
}
|
||||
}
|
||||
else if(strcmp(BOOT_TIME, keyName)==0)
|
||||
@@ -639,10 +643,17 @@ int retrieveObject( wrp_msg_t *reqMsg, wrp_msg_t **response )
|
||||
}
|
||||
|
||||
ParodusInfo( "Number of object level %d\n", objlevel );
|
||||
|
||||
if(objlevel == 3 && ((obj[3] !=NULL) && strstr(obj[3] ,"tags") == NULL))
|
||||
if((objlevel == 3 && ((obj[3] !=NULL) && strstr(obj[3] ,"tags") == NULL)) || (objlevel == 4 && ((obj[3] !=NULL) && strstr(obj[3] ,"service-status") != NULL)))
|
||||
{
|
||||
inMemStatus = retrieveFromMemory(obj[3], &inMemResponse );
|
||||
//To support dest "mac:14xxxxxxxxxx/parodus/service-status/service" to retrieve online/offline status of registered clients.
|
||||
if(strstr(obj[3] ,"service-status") !=NULL)
|
||||
{
|
||||
inMemStatus = getClientStatus(obj[4], &inMemResponse );
|
||||
}
|
||||
else
|
||||
{
|
||||
inMemStatus = retrieveFromMemory(obj[3], &inMemResponse );
|
||||
}
|
||||
|
||||
if(inMemStatus == 0)
|
||||
{
|
||||
@@ -1613,3 +1624,27 @@ static int validateDisconnectString(char *reason)
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
static int getClientStatus(char *service, cJSON **jsonresponse)
|
||||
{
|
||||
char regstatus[16] ={0};
|
||||
*jsonresponse = cJSON_CreateObject();
|
||||
|
||||
if(service == NULL)
|
||||
{
|
||||
ParodusError("service is NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(checkClientStatus(service))
|
||||
{
|
||||
strncpy(regstatus, "online", sizeof(regstatus)-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(regstatus, "offline", sizeof(regstatus)-1);
|
||||
}
|
||||
ParodusPrint("getClientStatus: service:%s value:%s\n", service, regstatus);
|
||||
cJSON_AddItemToObject( *jsonresponse, SERVICE_STATUS , cJSON_CreateString(regstatus));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "breakpad_wrapper.h"
|
||||
#endif
|
||||
#include "signal.h"
|
||||
#include "privilege.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Macros */
|
||||
@@ -41,7 +42,7 @@ typedef void Sigfunc(int);
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* none */
|
||||
int numLoops;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Function Prototypes */
|
||||
@@ -104,6 +105,7 @@ int main( int argc, char **argv)
|
||||
memset(cfg,0,sizeof(ParodusCfg));
|
||||
|
||||
ParodusInfo("********** Starting component: Parodus **********\n ");
|
||||
drop_root_privilege();
|
||||
setDefaultValuesToCfg(cfg);
|
||||
if (0 != parseCommandLine(argc,argv,cfg)) {
|
||||
abort();
|
||||
|
||||
@@ -52,7 +52,7 @@ void setMessageHandlers()
|
||||
|
||||
static int cloud_status_is_online (void)
|
||||
{
|
||||
const char *status = get_parodus_cfg()->cloud_status;
|
||||
const char *status = get_cloud_status();
|
||||
if (NULL == status)
|
||||
return false;
|
||||
return (strcmp (status, CLOUD_STATUS_ONLINE) == 0);
|
||||
@@ -60,14 +60,14 @@ static int cloud_status_is_online (void)
|
||||
|
||||
/** To send upstream msgs to server ***/
|
||||
|
||||
void sendMessage(noPollConn *conn, void *msg, size_t len)
|
||||
int sendMessage(noPollConn *conn, void *msg, size_t len)
|
||||
{
|
||||
int bytesWritten = 0;
|
||||
|
||||
if (!cloud_status_is_online ()) {
|
||||
ParodusError("Failed to send msg upstream as connection is not OK\n");
|
||||
OnboardLog("Failed to send msg upstream as connection is not OK\n");
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
|
||||
ParodusInfo("sendMessage length %zu\n", len);
|
||||
@@ -77,7 +77,9 @@ void sendMessage(noPollConn *conn, void *msg, size_t len)
|
||||
if (bytesWritten != (int) len)
|
||||
{
|
||||
ParodusError("Failed to send bytes %zu, bytes written were=%d (errno=%d, %s)..\n", len, bytesWritten, errno, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sendResponse(noPollConn * conn, void * buffer, size_t length)
|
||||
|
||||
@@ -41,7 +41,7 @@ extern "C" {
|
||||
*/
|
||||
int sendResponse(noPollConn * conn,void *str, size_t bufferSize);
|
||||
void setMessageHandlers();
|
||||
void sendMessage(noPollConn *conn, void *msg, size_t len);
|
||||
int sendMessage(noPollConn *conn, void *msg, size_t len);
|
||||
|
||||
/**
|
||||
* @brief __report_log Nopoll log handler
|
||||
|
||||
6
src/privilege.c
Normal file
6
src/privilege.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "privilege.h"
|
||||
|
||||
void drop_root_privilege()
|
||||
{
|
||||
|
||||
}
|
||||
2
src/privilege.h
Normal file
2
src/privilege.h
Normal file
@@ -0,0 +1,2 @@
|
||||
/* This is a stub function that will be overridden in a patch */
|
||||
void drop_root_privilege();
|
||||
@@ -34,7 +34,7 @@ uint64_t getCurrentTimeInMicroSeconds(struct timespec *timer)
|
||||
ParodusPrint("timer->tv_sec : %lu\n",timer->tv_sec);
|
||||
ParodusPrint("timer->tv_nsec : %lu\n",timer->tv_nsec);
|
||||
systime = (uint64_t)timer->tv_sec * 1000000L + timer->tv_nsec/ 1000;
|
||||
return systime;
|
||||
return systime;
|
||||
}
|
||||
|
||||
long timeValDiff(struct timespec *starttime, struct timespec *finishtime)
|
||||
|
||||
@@ -83,7 +83,6 @@ void packMetaData()
|
||||
//Pack the metadata initially to reuse for every upstream msg sending to server
|
||||
ParodusPrint("-------------- Packing metadata ----------------\n");
|
||||
sprintf(boot_time, "%d", get_parodus_cfg()->boot_time);
|
||||
|
||||
struct data meta_pack[METADATA_COUNT] = {
|
||||
{HW_MODELNAME, get_parodus_cfg()->hw_model},
|
||||
{HW_SERIALNUMBER, get_parodus_cfg()->hw_serial_number},
|
||||
@@ -95,10 +94,9 @@ void packMetaData()
|
||||
{LAST_RECONNECT_REASON, get_global_reconnect_reason()},
|
||||
{WEBPA_PROTOCOL, get_parodus_cfg()->webpa_protocol},
|
||||
{WEBPA_UUID,get_parodus_cfg()->webpa_uuid},
|
||||
{WEBPA_INTERFACE, get_parodus_cfg()->webpa_interface_used},
|
||||
{WEBPA_INTERFACE, getWebpaInterface()},
|
||||
{PARTNER_ID, get_parodus_cfg()->partner_id}
|
||||
};
|
||||
|
||||
const data_t metapack = {METADATA_COUNT, meta_pack};
|
||||
|
||||
metaPackSize = wrp_pack_metadata( &metapack , &metadataPack );
|
||||
@@ -330,6 +328,7 @@ void *processUpstreamMessage()
|
||||
if(ret == 1)
|
||||
{
|
||||
wrp_msg_t *eventMsg = (wrp_msg_t *) malloc(sizeof(wrp_msg_t));
|
||||
memset( eventMsg, 0, sizeof( wrp_msg_t ) );
|
||||
eventMsg->msg_type = msgType;
|
||||
eventMsg->u.event.content_type=msg->u.event.content_type;
|
||||
eventMsg->u.event.source=msg->u.event.source;
|
||||
@@ -339,6 +338,15 @@ void *processUpstreamMessage()
|
||||
eventMsg->u.event.headers=msg->u.event.headers;
|
||||
eventMsg->u.event.metadata=msg->u.event.metadata;
|
||||
eventMsg->u.event.partner_ids = partnersList;
|
||||
if(msg->u.event.transaction_uuid)
|
||||
{
|
||||
ParodusPrint("Inside Trans id in PARODUS\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("Assigning NULL to trans id\n");
|
||||
eventMsg->u.event.transaction_uuid = NULL;
|
||||
}
|
||||
|
||||
int size = wrp_struct_to( eventMsg, WRP_BYTES, &bytes );
|
||||
if(size > 0)
|
||||
@@ -417,12 +425,43 @@ void *processUpstreamMessage()
|
||||
{
|
||||
ParodusError("Failed to get device_id\n");
|
||||
}
|
||||
} else if (WRP_MSG_TYPE__SVC_ALIVE != msgType) {
|
||||
}
|
||||
else if((WRP_MSG_TYPE__UPDATE == msgType) || (WRP_MSG_TYPE__DELETE == msgType))
|
||||
{
|
||||
ParodusPrint("UPDATE/DELETE request\n");
|
||||
ret = getDeviceId(&device_id, &device_id_len);
|
||||
if(ret == 0)
|
||||
{
|
||||
ParodusPrint("device_id %s device_id_len %lu\n", device_id, device_id_len);
|
||||
/* Match dest based on device_id. Check dest start with: "mac:112233445xxx" ? */
|
||||
if( 0 == strncasecmp(device_id, msg->u.crud.dest, device_id_len-1) )
|
||||
{
|
||||
/* For this device. For nanomsg clients.*/
|
||||
getServiceNameAndSendResponse(msg, &message->msg, message->len);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Not for this device. Send upstream */
|
||||
ParodusInfo("sendUpstreamMsgToServer \n");
|
||||
sendUpstreamMsgToServer(&message->msg, message->len);
|
||||
}
|
||||
if(device_id != NULL)
|
||||
{
|
||||
free(device_id);
|
||||
device_id = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Failed to get device_id\n");
|
||||
}
|
||||
}
|
||||
else if (WRP_MSG_TYPE__SVC_ALIVE != msgType) {
|
||||
/* Don't reply to service alive message */
|
||||
sendUpstreamMsgToServer(&message->msg, message->len);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -565,11 +604,12 @@ void getServiceNameAndSendResponse(wrp_msg_t *msg, void **msg_bytes, size_t msg_
|
||||
}
|
||||
}
|
||||
|
||||
void sendUpstreamMsgToServer(void **resp_bytes, size_t resp_size)
|
||||
int sendUpstreamMsgToServer(void **resp_bytes, size_t resp_size)
|
||||
{
|
||||
void *appendData;
|
||||
size_t encodedSize;
|
||||
bool close_retry = false;
|
||||
int sendRetStatus = 1;
|
||||
//appending response with metadata
|
||||
if(metaPackSize > 0)
|
||||
{
|
||||
@@ -584,12 +624,13 @@ void sendUpstreamMsgToServer(void **resp_bytes, size_t resp_size)
|
||||
//TODO: Upstream and downstream messages in queue should be handled and queue should be empty before parodus forcefully disconnect from cloud.
|
||||
if(!close_retry || (get_parodus_cfg()->cloud_disconnect !=NULL))
|
||||
{
|
||||
sendMessage(get_global_conn(),appendData, encodedSize);
|
||||
sendRetStatus = sendMessage(get_global_conn(),appendData, encodedSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusInfo("close_retry is %d, unable to send response as connection retry is in progress\n", close_retry);
|
||||
OnboardLog("close_retry is %d, unable to send response as connection retry is in progress\n", close_retry);
|
||||
sendRetStatus = 1;
|
||||
}
|
||||
free(appendData);
|
||||
appendData =NULL;
|
||||
@@ -597,6 +638,9 @@ void sendUpstreamMsgToServer(void **resp_bytes, size_t resp_size)
|
||||
else
|
||||
{
|
||||
ParodusError("Failed to send upstream as metadata packing is not successful\n");
|
||||
sendRetStatus = 1;
|
||||
}
|
||||
ParodusPrint("sendRetStatus is %d\n", sendRetStatus);
|
||||
|
||||
return sendRetStatus;
|
||||
}
|
||||
|
||||
@@ -47,11 +47,15 @@ typedef struct UpStreamMsg__
|
||||
void packMetaData();
|
||||
void *handle_upstream();
|
||||
void *processUpstreamMessage();
|
||||
void registerRBUSlistener();
|
||||
int getDeviceId(char **device_id, size_t *device_id_len);
|
||||
void sendUpstreamMsgToServer(void **resp_bytes, size_t resp_size);
|
||||
int sendUpstreamMsgToServer(void **resp_bytes, size_t resp_size);
|
||||
void getServiceNameAndSendResponse(wrp_msg_t *msg, void **msg_bytes, size_t msg_size);
|
||||
void createUpstreamRetrieveMsg(wrp_msg_t *message, wrp_msg_t **retrieve_msg);
|
||||
void set_global_UpStreamMsgQ(UpStreamMsg * UpStreamQ);
|
||||
#ifdef WAN_FAILOVER_SUPPORTED
|
||||
int subscribeCurrentActiveInterfaceEvent();
|
||||
#endif
|
||||
UpStreamMsg * get_global_UpStreamMsgQ(void);
|
||||
pthread_cond_t *get_global_nano_con(void);
|
||||
pthread_mutex_t *get_global_nano_mut(void);
|
||||
|
||||
183
src/upstream_rbus.c
Normal file
183
src/upstream_rbus.c
Normal file
@@ -0,0 +1,183 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @file upstream_rbus.c
|
||||
*
|
||||
* @description This is used for parodus-RBUS communication
|
||||
* to send notification events upstream to cloud.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <rbus.h>
|
||||
#include "upstream.h"
|
||||
#include "ParodusInternal.h"
|
||||
#include "partners_check.h"
|
||||
|
||||
#define WEBCFG_UPSTREAM_EVENT "Webconfig.Upstream"
|
||||
#ifdef WAN_FAILOVER_SUPPORTED
|
||||
#define WEBPA_INTERFACE "Device.X_RDK_WanManager.CurrentActiveInterface"
|
||||
#endif
|
||||
|
||||
rbusHandle_t rbus_Handle;
|
||||
rbusError_t err;
|
||||
|
||||
void processWebconfigUpstreamEvent(rbusHandle_t handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription);
|
||||
|
||||
void subscribeAsyncHandler( rbusHandle_t handle, rbusEventSubscription_t* subscription, rbusError_t error);
|
||||
|
||||
rbusHandle_t get_parodus_rbus_Handle(void)
|
||||
{
|
||||
return rbus_Handle;
|
||||
}
|
||||
#ifdef WAN_FAILOVER_SUPPORTED
|
||||
void eventReceiveHandler( rbusHandle_t rbus_Handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription );
|
||||
#endif
|
||||
|
||||
/* API to register RBUS listener to receive messages from webconfig */
|
||||
void subscribeRBUSevent()
|
||||
{
|
||||
int rc = RBUS_ERROR_SUCCESS;
|
||||
err = rbus_open(&rbus_Handle, "parodus");
|
||||
if (err)
|
||||
{
|
||||
ParodusError("rbus_open failed :%s\n", rbusError_ToString(err));
|
||||
return;
|
||||
}
|
||||
rc = rbusEvent_SubscribeAsync(rbus_Handle,WEBCFG_UPSTREAM_EVENT,processWebconfigUpstreamEvent,subscribeAsyncHandler,"parodus",10*60);
|
||||
if(rc != RBUS_ERROR_SUCCESS)
|
||||
ParodusError("rbusEvent_Subscribe failed: %d, %s\n", rc, rbusError_ToString(rc));
|
||||
else
|
||||
ParodusInfo("rbusEvent_Subscribe was successful\n");
|
||||
}
|
||||
|
||||
#ifdef WAN_FAILOVER_SUPPORTED
|
||||
/* API to subscribe Active Interface name on value change event*/
|
||||
int subscribeCurrentActiveInterfaceEvent()
|
||||
{
|
||||
int rc = RBUS_ERROR_SUCCESS;
|
||||
ParodusPrint("Subscribing to Device.X_RDK_WanManager.CurrentActiveInterface Event\n");
|
||||
rc = rbusEvent_SubscribeAsync(rbus_Handle,WEBPA_INTERFACE,eventReceiveHandler,subscribeAsyncHandler,"parodusInterface",10*20);
|
||||
if(rc != RBUS_ERROR_SUCCESS)
|
||||
{
|
||||
ParodusError("%s subscribe failed : %d - %s\n", WEBPA_INTERFACE, rc, rbusError_ToString(rc));
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
||||
void processWebconfigUpstreamEvent(rbusHandle_t handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription)
|
||||
{
|
||||
(void)handle;
|
||||
(void)subscription;
|
||||
|
||||
int rv=-1;
|
||||
wrp_msg_t *event_msg;
|
||||
void *bytes;
|
||||
const uint8_t* bytesVal = NULL;
|
||||
int len;
|
||||
rbusValue_t value = NULL;
|
||||
|
||||
value = rbusObject_GetValue(event->data, "value");
|
||||
bytesVal = rbusValue_GetBytes(value, &len);
|
||||
|
||||
bytes = (void*) bytesVal;
|
||||
rv = wrp_to_struct( bytes, len, WRP_BYTES, &event_msg );
|
||||
if(rv > 0)
|
||||
{
|
||||
ParodusInfo(" Received upstream event data: dest '%s'\n", event_msg->u.event.dest);
|
||||
partners_t *partnersList = NULL;
|
||||
int j = 0;
|
||||
|
||||
int ret = validate_partner_id(event_msg, &partnersList);
|
||||
if(ret == 1)
|
||||
{
|
||||
wrp_msg_t *eventMsg = (wrp_msg_t *) malloc(sizeof(wrp_msg_t));
|
||||
memset( eventMsg, 0, sizeof( wrp_msg_t ) );
|
||||
eventMsg->msg_type = event_msg->msg_type;
|
||||
eventMsg->u.event.content_type=event_msg->u.event.content_type;
|
||||
eventMsg->u.event.source=event_msg->u.event.source;
|
||||
eventMsg->u.event.dest=event_msg->u.event.dest;
|
||||
eventMsg->u.event.payload=event_msg->u.event.payload;
|
||||
eventMsg->u.event.payload_size=event_msg->u.event.payload_size;
|
||||
eventMsg->u.event.headers=event_msg->u.event.headers;
|
||||
eventMsg->u.event.metadata=event_msg->u.event.metadata;
|
||||
eventMsg->u.event.partner_ids = partnersList;
|
||||
if(event_msg->u.event.transaction_uuid)
|
||||
{
|
||||
ParodusPrint("Inside Trans id in PARODUS_rbus\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("Assigning NULL to trans id RBUS\n");
|
||||
eventMsg->u.event.transaction_uuid = NULL;
|
||||
}
|
||||
|
||||
int size = wrp_struct_to( eventMsg, WRP_BYTES, &bytes );
|
||||
if(size > 0)
|
||||
{
|
||||
sendUpstreamMsgToServer(&bytes, size);
|
||||
}
|
||||
free(eventMsg);
|
||||
free(bytes);
|
||||
bytes = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
sendUpstreamMsgToServer((void **)(&bytes), len);
|
||||
}
|
||||
if(partnersList != NULL)
|
||||
{
|
||||
for(j=0; j<(int)partnersList->count; j++)
|
||||
{
|
||||
if(NULL != partnersList->partner_ids[j])
|
||||
{
|
||||
free(partnersList->partner_ids[j]);
|
||||
}
|
||||
}
|
||||
free(partnersList);
|
||||
}
|
||||
partnersList = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void subscribeAsyncHandler( rbusHandle_t handle, rbusEventSubscription_t* subscription, rbusError_t error)
|
||||
{
|
||||
(void)handle;
|
||||
ParodusInfo("subscribeAsyncHandler event %s, error %d - %s\n",subscription->eventName, error, rbusError_ToString(error));
|
||||
}
|
||||
|
||||
#ifdef WAN_FAILOVER_SUPPORTED
|
||||
void eventReceiveHandler( rbusHandle_t rbus_Handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription )
|
||||
{
|
||||
(void)subscription;
|
||||
ParodusPrint("Handling event inside eventReceiveHandler\n");
|
||||
(void)rbus_Handle;
|
||||
char * interface = NULL;
|
||||
rbusValue_t newValue = rbusObject_GetValue(event->data, "value");
|
||||
rbusValue_t oldValue = rbusObject_GetValue(event->data, "oldValue");
|
||||
ParodusInfo("Consumer received ValueChange event for param %s\n", event->name);
|
||||
|
||||
if(newValue) {
|
||||
interface = (char *) rbusValue_GetString(newValue, NULL);
|
||||
setWebpaInterface(interface);
|
||||
}
|
||||
if(newValue !=NULL && oldValue!=NULL && interface!=NULL) {
|
||||
ParodusInfo("New Value: %s Old Value: %s New Interface Value: %s\n", rbusValue_GetString(newValue, NULL), rbusValue_GetString(oldValue, NULL), interface);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
846
src/xmidtsend_rbus.c
Normal file
846
src/xmidtsend_rbus.c
Normal file
@@ -0,0 +1,846 @@
|
||||
/**
|
||||
* Copyright 2022 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @file xmidtsend_rbus.c
|
||||
*
|
||||
* @ To provide Xmidt send RBUS method to send events upstream.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <rbus.h>
|
||||
#include "upstream.h"
|
||||
#include "ParodusInternal.h"
|
||||
#include "partners_check.h"
|
||||
#include "xmidtsend_rbus.h"
|
||||
#include "config.h"
|
||||
|
||||
static pthread_t processThreadId = 0;
|
||||
static int XmidtQsize = 0;
|
||||
|
||||
XmidtMsg *XmidtMsgQ = NULL;
|
||||
|
||||
pthread_mutex_t xmidt_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
pthread_cond_t xmidt_con=PTHREAD_COND_INITIALIZER;
|
||||
|
||||
bool highQosValueCheck(int qos)
|
||||
{
|
||||
if(qos > 24)
|
||||
{
|
||||
ParodusInfo("The qos value is high\n");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("The qos value is low\n");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
* @brief To handle xmidt rbus messages received from various components.
|
||||
*/
|
||||
void addToXmidtUpstreamQ(wrp_msg_t * msg, rbusMethodAsyncHandle_t asyncHandle)
|
||||
{
|
||||
XmidtMsg *message;
|
||||
|
||||
ParodusPrint("XmidtQsize is %d\n" , XmidtQsize);
|
||||
if(XmidtQsize == MAX_QUEUE_SIZE)
|
||||
{
|
||||
char * errorMsg = strdup("Max Queue Size Exceeded");
|
||||
ParodusError("Queue Size Exceeded\n");
|
||||
createOutParamsandSendAck(msg, asyncHandle, errorMsg , QUEUE_SIZE_EXCEEDED);
|
||||
wrp_free_struct(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
ParodusPrint ("Add Xmidt Upstream message to queue\n");
|
||||
message = (XmidtMsg *)malloc(sizeof(XmidtMsg));
|
||||
|
||||
if(message)
|
||||
{
|
||||
message->msg = msg;
|
||||
message->asyncHandle =asyncHandle;
|
||||
//Increment queue size to handle max queue limit
|
||||
XmidtQsize++;
|
||||
message->next=NULL;
|
||||
pthread_mutex_lock (&xmidt_mut);
|
||||
//Producer adds the rbus msg into queue
|
||||
if(XmidtMsgQ == NULL)
|
||||
{
|
||||
XmidtMsgQ = message;
|
||||
|
||||
ParodusPrint("Producer added xmidt message\n");
|
||||
pthread_cond_signal(&xmidt_con);
|
||||
pthread_mutex_unlock (&xmidt_mut);
|
||||
ParodusPrint("mutex unlock in xmidt producer\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
XmidtMsg *temp = XmidtMsgQ;
|
||||
while(temp->next)
|
||||
{
|
||||
temp = temp->next;
|
||||
}
|
||||
temp->next = message;
|
||||
pthread_mutex_unlock (&xmidt_mut);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
char * errorMsg = strdup("Unable to enqueue");
|
||||
ParodusError("failure in allocation for xmidt message\n");
|
||||
createOutParamsandSendAck(msg, asyncHandle, errorMsg , ENQUEUE_FAILURE);
|
||||
wrp_free_struct(msg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//Xmidt consumer thread to process the rbus events.
|
||||
void processXmidtData()
|
||||
{
|
||||
int err = 0;
|
||||
err = pthread_create(&processThreadId, NULL, processXmidtUpstreamMsg, NULL);
|
||||
if (err != 0)
|
||||
{
|
||||
ParodusError("Error creating processXmidtData thread :[%s]\n", strerror(err));
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusInfo("processXmidtData thread created Successfully\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Consumer to Parse and process rbus data.
|
||||
void* processXmidtUpstreamMsg()
|
||||
{
|
||||
int rv = 0;
|
||||
while(FOREVER())
|
||||
{
|
||||
pthread_mutex_lock (&xmidt_mut);
|
||||
ParodusPrint("mutex lock in xmidt consumer thread\n");
|
||||
if(XmidtMsgQ != NULL)
|
||||
{
|
||||
XmidtMsg *Data = XmidtMsgQ;
|
||||
|
||||
pthread_mutex_unlock (&xmidt_mut);
|
||||
ParodusPrint("mutex unlock in xmidt consumer thread\n");
|
||||
rv = processData(Data->msg, Data->asyncHandle);
|
||||
if(!rv)
|
||||
{
|
||||
ParodusPrint("Data->msg wrp free\n");
|
||||
wrp_free_struct(Data->msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
free(Data->msg);
|
||||
}
|
||||
free(Data);
|
||||
Data = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (g_shutdown)
|
||||
{
|
||||
pthread_mutex_unlock (&xmidt_mut);
|
||||
break;
|
||||
}
|
||||
ParodusPrint("Before cond wait in xmidt consumer thread\n");
|
||||
pthread_cond_wait(&xmidt_con, &xmidt_mut);
|
||||
pthread_mutex_unlock (&xmidt_mut);
|
||||
ParodusPrint("mutex unlock in xmidt thread after cond wait\n");
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//To validate and send events upstream
|
||||
int processData(wrp_msg_t * msg, rbusMethodAsyncHandle_t asyncHandle)
|
||||
{
|
||||
int rv = 0;
|
||||
char *errorMsg = "none";
|
||||
int statuscode =0;
|
||||
|
||||
wrp_msg_t * xmidtMsg = msg;
|
||||
if (xmidtMsg == NULL)
|
||||
{
|
||||
ParodusError("xmidtMsg is NULL\n");
|
||||
errorMsg = strdup("Unable to enqueue");
|
||||
createOutParamsandSendAck(xmidtMsg, asyncHandle, errorMsg, ENQUEUE_FAILURE);
|
||||
xmidtQDequeue();
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = validateXmidtData(xmidtMsg, &errorMsg, &statuscode);
|
||||
ParodusPrint("validateXmidtData, errorMsg %s statuscode %d\n", errorMsg, statuscode);
|
||||
if(rv)
|
||||
{
|
||||
ParodusPrint("validation successful, send event to server\n");
|
||||
sendXmidtEventToServer(xmidtMsg, asyncHandle);
|
||||
return rv;
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("validation failed, send failure ack\n");
|
||||
createOutParamsandSendAck(xmidtMsg, asyncHandle, errorMsg , statuscode);
|
||||
xmidtQDequeue();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
//To remove an event from Queue
|
||||
void xmidtQDequeue()
|
||||
{
|
||||
pthread_mutex_lock (&xmidt_mut);
|
||||
if(XmidtMsgQ != NULL)
|
||||
{
|
||||
XmidtMsgQ = XmidtMsgQ->next;
|
||||
XmidtQsize -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("XmidtMsgQ is NULL\n");
|
||||
}
|
||||
pthread_mutex_unlock (&xmidt_mut);
|
||||
}
|
||||
|
||||
int validateXmidtData(wrp_msg_t * eventMsg, char **errorMsg, int *statusCode)
|
||||
{
|
||||
if(eventMsg == NULL)
|
||||
{
|
||||
ParodusError("eventMsg is NULL\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(eventMsg->msg_type != WRP_MSG_TYPE__EVENT)
|
||||
{
|
||||
*errorMsg = strdup("Message format is invalid");
|
||||
*statusCode = INVALID_MSG_TYPE;
|
||||
ParodusError("errorMsg: %s, statusCode: %d\n", *errorMsg, *statusCode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(eventMsg->u.event.source == NULL)
|
||||
{
|
||||
*errorMsg = strdup("Missing source");
|
||||
*statusCode = MISSING_SOURCE;
|
||||
ParodusError("errorMsg: %s, statusCode: %d\n", *errorMsg, *statusCode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(eventMsg->u.event.dest == NULL)
|
||||
{
|
||||
*errorMsg = strdup("Missing dest");
|
||||
*statusCode = MISSING_DEST;
|
||||
ParodusError("errorMsg: %s, statusCode: %d\n", *errorMsg, *statusCode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(eventMsg->u.event.content_type == NULL)
|
||||
{
|
||||
*errorMsg = strdup("Missing content_type");
|
||||
*statusCode = MISSING_CONTENT_TYPE;
|
||||
ParodusError("errorMsg: %s, statusCode: %d\n", *errorMsg, *statusCode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(eventMsg->u.event.payload == NULL)
|
||||
{
|
||||
*errorMsg = strdup("Missing payload");
|
||||
*statusCode = MISSING_PAYLOAD;
|
||||
ParodusError("errorMsg: %s, statusCode: %d\n", *errorMsg, *statusCode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(eventMsg->u.event.payload_size == 0)
|
||||
{
|
||||
*errorMsg = strdup("Missing payloadlen");
|
||||
*statusCode = MISSING_PAYLOADLEN;
|
||||
ParodusError("errorMsg: %s, statusCode: %d\n", *errorMsg, *statusCode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ParodusPrint("validateXmidtData success. errorMsg %s statusCode %d\n", *errorMsg, *statusCode);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void sendXmidtEventToServer(wrp_msg_t * msg, rbusMethodAsyncHandle_t asyncHandle)
|
||||
{
|
||||
wrp_msg_t *notif_wrp_msg = NULL;
|
||||
ssize_t msg_len;
|
||||
void *msg_bytes;
|
||||
int ret = -1;
|
||||
char sourceStr[64] = {'\0'};
|
||||
char *device_id = NULL;
|
||||
size_t device_id_len = 0;
|
||||
int sendRetStatus = 1;
|
||||
char *errorMsg = NULL;
|
||||
int qos = 0;
|
||||
|
||||
notif_wrp_msg = (wrp_msg_t *)malloc(sizeof(wrp_msg_t));
|
||||
if(notif_wrp_msg != NULL)
|
||||
{
|
||||
memset(notif_wrp_msg, 0, sizeof(wrp_msg_t));
|
||||
notif_wrp_msg->msg_type = WRP_MSG_TYPE__EVENT;
|
||||
|
||||
ParodusPrint("msg->u.event.source: %s\n",msg->u.event.source);
|
||||
|
||||
if(msg->u.event.source !=NULL)
|
||||
{
|
||||
//To get device_id in the format "mac:112233445xxx"
|
||||
ret = getDeviceId(&device_id, &device_id_len);
|
||||
if(ret == 0)
|
||||
{
|
||||
ParodusPrint("device_id %s device_id_len %lu\n", device_id, device_id_len);
|
||||
snprintf(sourceStr, sizeof(sourceStr), "%s/%s", device_id, msg->u.event.source);
|
||||
ParodusPrint("sourceStr formed is %s\n" , sourceStr);
|
||||
notif_wrp_msg->u.event.source = strdup(sourceStr);
|
||||
ParodusInfo("source:%s\n", notif_wrp_msg->u.event.source);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Failed to get device_id\n");
|
||||
}
|
||||
if(device_id != NULL)
|
||||
{
|
||||
free(device_id);
|
||||
device_id = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(msg->u.event.dest != NULL)
|
||||
{
|
||||
notif_wrp_msg->u.event.dest = msg->u.event.dest;
|
||||
ParodusInfo("destination: %s\n", notif_wrp_msg->u.event.dest);
|
||||
}
|
||||
|
||||
if(msg->u.event.transaction_uuid != NULL)
|
||||
{
|
||||
notif_wrp_msg->u.event.transaction_uuid = msg->u.event.transaction_uuid;
|
||||
ParodusPrint("Notification transaction_uuid %s\n", notif_wrp_msg->u.event.transaction_uuid);
|
||||
}
|
||||
|
||||
if(msg->u.event.content_type != NULL)
|
||||
{
|
||||
if(strcmp(msg->u.event.content_type , "JSON") == 0)
|
||||
{
|
||||
notif_wrp_msg->u.event.content_type = strdup("application/json");
|
||||
}
|
||||
ParodusPrint("content_type is %s\n",notif_wrp_msg->u.event.content_type);
|
||||
}
|
||||
|
||||
if(msg->u.event.payload != NULL)
|
||||
{
|
||||
ParodusInfo("Notification payload: %s\n",msg->u.event.payload);
|
||||
notif_wrp_msg->u.event.payload = (void *)msg->u.event.payload;
|
||||
notif_wrp_msg->u.event.payload_size = msg->u.event.payload_size;
|
||||
ParodusPrint("payload size %lu\n", notif_wrp_msg->u.event.payload_size);
|
||||
}
|
||||
|
||||
if(msg->u.event.qos != 0)
|
||||
{
|
||||
notif_wrp_msg->u.event.qos = msg->u.event.qos;
|
||||
qos = notif_wrp_msg->u.event.qos;
|
||||
ParodusInfo("Notification qos: %d\n",notif_wrp_msg->u.event.qos);
|
||||
}
|
||||
msg_len = wrp_struct_to (notif_wrp_msg, WRP_BYTES, &msg_bytes);
|
||||
|
||||
ParodusPrint("Encoded xmidt wrp msg, msg_len %lu\n", msg_len);
|
||||
if(msg_len > 0)
|
||||
{
|
||||
ParodusPrint("sendUpstreamMsgToServer\n");
|
||||
sendRetStatus = sendUpstreamMsgToServer(&msg_bytes, msg_len);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("wrp msg_len is zero\n");
|
||||
errorMsg = strdup("Wrp message encoding failed");
|
||||
createOutParamsandSendAck(msg, asyncHandle, errorMsg, WRP_ENCODE_FAILURE);
|
||||
xmidtQDequeue();
|
||||
|
||||
ParodusPrint("wrp_free_struct\n");
|
||||
if(notif_wrp_msg != NULL)
|
||||
{
|
||||
wrp_free_struct(notif_wrp_msg);
|
||||
}
|
||||
|
||||
if(msg_bytes != NULL)
|
||||
{
|
||||
free(msg_bytes);
|
||||
msg_bytes = NULL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
while(sendRetStatus) //If SendMessage is failed condition
|
||||
{
|
||||
ParodusError("sendXmidtEventToServer is Failed\n");
|
||||
if(highQosValueCheck(qos))
|
||||
{
|
||||
ParodusPrint("The event is having high qos retry again\n");
|
||||
ParodusInfo("Wait till connection is Up\n");
|
||||
|
||||
pthread_mutex_lock(get_global_cloud_status_mut());
|
||||
pthread_cond_wait(get_global_cloud_status_cond(), get_global_cloud_status_mut());
|
||||
pthread_mutex_unlock(get_global_cloud_status_mut());
|
||||
ParodusInfo("Received cloud status signal proceed to retry\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
errorMsg = strdup("send failed due to client disconnect");
|
||||
ParodusInfo("The event is having low qos proceed to dequeue\n");
|
||||
createOutParamsandSendAck(msg, asyncHandle, errorMsg, CLIENT_DISCONNECT);
|
||||
xmidtQDequeue();
|
||||
break;
|
||||
}
|
||||
sendRetStatus = sendUpstreamMsgToServer(&msg_bytes, msg_len);
|
||||
}
|
||||
|
||||
if(sendRetStatus == 0)
|
||||
{
|
||||
errorMsg = strdup("send to server success");
|
||||
createOutParamsandSendAck(msg, asyncHandle, errorMsg, DELIVERED_SUCCESS);
|
||||
xmidtQDequeue();
|
||||
}
|
||||
|
||||
ParodusPrint("B4 notif wrp_free_struct\n");
|
||||
if(notif_wrp_msg != NULL)
|
||||
{
|
||||
wrp_free_struct(notif_wrp_msg);
|
||||
}
|
||||
|
||||
if(msg_bytes != NULL)
|
||||
{
|
||||
free(msg_bytes);
|
||||
msg_bytes = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
errorMsg = strdup("Memory allocation failed");
|
||||
ParodusError("Memory allocation failed\n");
|
||||
createOutParamsandSendAck(msg, asyncHandle, errorMsg, MSG_PROCESSING_FAILED);
|
||||
xmidtQDequeue();
|
||||
}
|
||||
|
||||
if(msg->u.event.source !=NULL)
|
||||
{
|
||||
free(msg->u.event.source);
|
||||
msg->u.event.source = NULL;
|
||||
}
|
||||
if(msg->u.event.content_type !=NULL)
|
||||
{
|
||||
free(msg->u.event.content_type);
|
||||
msg->u.event.content_type = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void createOutParamsandSendAck(wrp_msg_t *msg, rbusMethodAsyncHandle_t asyncHandle, char *errorMsg, int statuscode)
|
||||
{
|
||||
rbusObject_t outParams;
|
||||
rbusError_t err;
|
||||
rbusValue_t value;
|
||||
char qosstring[20] = "";
|
||||
|
||||
rbusValue_Init(&value);
|
||||
rbusValue_SetString(value, "event");
|
||||
rbusObject_Init(&outParams, NULL);
|
||||
rbusObject_SetValue(outParams, "msg_type", value);
|
||||
rbusValue_Release(value);
|
||||
|
||||
ParodusPrint("statuscode %d errorMsg %s\n", statuscode, errorMsg);
|
||||
rbusValue_Init(&value);
|
||||
rbusValue_SetInt32(value, statuscode);
|
||||
rbusObject_SetValue(outParams, "status", value);
|
||||
rbusValue_Release(value);
|
||||
|
||||
if(errorMsg !=NULL)
|
||||
{
|
||||
rbusValue_Init(&value);
|
||||
rbusValue_SetString(value, errorMsg);
|
||||
rbusObject_SetValue(outParams, "error_message", value);
|
||||
rbusValue_Release(value);
|
||||
free(errorMsg);
|
||||
}
|
||||
|
||||
if(msg != NULL)
|
||||
{
|
||||
if(msg->u.event.source !=NULL)
|
||||
{
|
||||
ParodusPrint("msg->u.event.source is %s\n", msg->u.event.source);
|
||||
rbusValue_Init(&value);
|
||||
rbusValue_SetString(value, msg->u.event.source);
|
||||
rbusObject_SetValue(outParams, "source", value);
|
||||
rbusValue_Release(value);
|
||||
}
|
||||
|
||||
if(msg->u.event.dest !=NULL)
|
||||
{
|
||||
rbusValue_Init(&value);
|
||||
rbusValue_SetString(value, msg->u.event.dest);
|
||||
rbusObject_SetValue(outParams, "dest", value);
|
||||
rbusValue_Release(value);
|
||||
}
|
||||
|
||||
if(msg->u.event.content_type !=NULL)
|
||||
{
|
||||
rbusValue_Init(&value);
|
||||
rbusValue_SetString(value, msg->u.event.content_type);
|
||||
rbusObject_SetValue(outParams, "content_type", value);
|
||||
rbusValue_Release(value);
|
||||
}
|
||||
|
||||
rbusValue_Init(&value);
|
||||
snprintf(qosstring, sizeof(qosstring), "%d", msg->u.event.qos);
|
||||
ParodusPrint("qosstring is %s\n", qosstring);
|
||||
rbusValue_SetString(value, qosstring);
|
||||
rbusObject_SetValue(outParams, "qos", value);
|
||||
rbusValue_Release(value);
|
||||
|
||||
if(msg->u.event.transaction_uuid !=NULL)
|
||||
{
|
||||
rbusValue_Init(&value);
|
||||
rbusValue_SetString(value, msg->u.event.transaction_uuid);
|
||||
rbusObject_SetValue(outParams, "transaction_uuid", value);
|
||||
rbusValue_Release(value);
|
||||
ParodusPrint("outParams msg->u.event.transaction_uuid %s\n", msg->u.event.transaction_uuid);
|
||||
}
|
||||
}
|
||||
|
||||
if(outParams !=NULL)
|
||||
{
|
||||
//rbusObject_fwrite(outParams, 1, stdout);
|
||||
if(asyncHandle == NULL)
|
||||
{
|
||||
ParodusError("asyncHandle is NULL\n");
|
||||
return;
|
||||
}
|
||||
|
||||
err = rbusMethod_SendAsyncResponse(asyncHandle, RBUS_ERROR_SUCCESS, outParams);
|
||||
//err = rbusMethod_SendAsyncResponse(asyncHandle, RBUS_ERROR_INVALID_RESPONSE_FROM_DESTINATION, outParams); //for negative case
|
||||
|
||||
if(err != RBUS_ERROR_SUCCESS)
|
||||
{
|
||||
ParodusError("rbusMethod_SendAsyncResponse failed err: %d\n", err);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusInfo("rbusMethod_SendAsyncResponse success: %d\n", err);
|
||||
}
|
||||
|
||||
rbusObject_Release(outParams);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Failed to create outParams\n");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief This function handles check method call from t2 before the actual inParams SET and to not proceed with inParams processing.
|
||||
*/
|
||||
int checkInputParameters(rbusObject_t inParams)
|
||||
{
|
||||
rbusValue_t check = rbusObject_GetValue(inParams, "check");
|
||||
if(check)
|
||||
{
|
||||
ParodusPrint("Rbus check method. Not proceeding to process this inparam\n");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
//To generate unique transaction id for xmidt send requests
|
||||
char* generate_transaction_uuid()
|
||||
{
|
||||
char *transID = NULL;
|
||||
uuid_t transaction_Id;
|
||||
char *trans_id = NULL;
|
||||
trans_id = (char *)malloc(37);
|
||||
uuid_generate_random(transaction_Id);
|
||||
uuid_unparse(transaction_Id, trans_id);
|
||||
|
||||
if(trans_id !=NULL)
|
||||
{
|
||||
transID = trans_id;
|
||||
}
|
||||
return transID;
|
||||
}
|
||||
|
||||
void parseRbusInparamsToWrp(rbusObject_t inParams, char *trans_id, wrp_msg_t **eventMsg)
|
||||
{
|
||||
char *msg_typeStr = NULL;
|
||||
char *sourceVal = NULL;
|
||||
char *destStr = NULL, *contenttypeStr = NULL;
|
||||
char *payloadStr = NULL, *qosVal = NULL;
|
||||
unsigned int payloadlength = 0;
|
||||
wrp_msg_t *msg = NULL;
|
||||
|
||||
msg = ( wrp_msg_t * ) malloc( sizeof( wrp_msg_t ) );
|
||||
if(msg == NULL)
|
||||
{
|
||||
ParodusError("Wrp msg allocation failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
memset( msg, 0, sizeof( wrp_msg_t ) );
|
||||
|
||||
rbusValue_t msg_type = rbusObject_GetValue(inParams, "msg_type");
|
||||
if(msg_type)
|
||||
{
|
||||
if(rbusValue_GetType(msg_type) == RBUS_STRING)
|
||||
{
|
||||
msg_typeStr = (char *) rbusValue_GetString(msg_type, NULL);
|
||||
ParodusPrint("msg_type value received is %s\n", msg_typeStr);
|
||||
if(msg_typeStr !=NULL)
|
||||
{
|
||||
if(strcmp(msg_typeStr, "event") ==0)
|
||||
{
|
||||
msg->msg_type = WRP_MSG_TYPE__EVENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("msg_type received is not event : %s\n", msg_typeStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("msg_type is empty\n");
|
||||
}
|
||||
|
||||
rbusValue_t source = rbusObject_GetValue(inParams, "source");
|
||||
if(source)
|
||||
{
|
||||
if(rbusValue_GetType(source) == RBUS_STRING)
|
||||
{
|
||||
sourceVal = (char *)rbusValue_GetString(source, NULL);
|
||||
if(sourceVal !=NULL)
|
||||
{
|
||||
ParodusInfo("source value received is %s\n", sourceVal);
|
||||
msg->u.event.source = strdup(sourceVal);
|
||||
}
|
||||
ParodusPrint("msg->u.event.source is %s\n", msg->u.event.source);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("source is empty\n");
|
||||
}
|
||||
|
||||
rbusValue_t dest = rbusObject_GetValue(inParams, "dest");
|
||||
if(dest)
|
||||
{
|
||||
if(rbusValue_GetType(dest) == RBUS_STRING)
|
||||
{
|
||||
destStr = (char *)rbusValue_GetString(dest, NULL);
|
||||
if(destStr !=NULL)
|
||||
{
|
||||
ParodusPrint("dest value received is %s\n", destStr);
|
||||
msg->u.event.dest = strdup(destStr);
|
||||
ParodusPrint("msg->u.event.dest is %s\n", msg->u.event.dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("dest is empty\n");
|
||||
}
|
||||
|
||||
rbusValue_t contenttype = rbusObject_GetValue(inParams, "content_type");
|
||||
if(contenttype)
|
||||
{
|
||||
if(rbusValue_GetType(contenttype) == RBUS_STRING)
|
||||
{
|
||||
contenttypeStr = (char *)rbusValue_GetString(contenttype, NULL);
|
||||
if(contenttypeStr !=NULL)
|
||||
{
|
||||
ParodusPrint("contenttype value received is %s\n", contenttypeStr);
|
||||
msg->u.event.content_type = strdup(contenttypeStr);
|
||||
ParodusPrint("msg->u.event.content_type is %s\n", msg->u.event.content_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("contenttype is empty\n");
|
||||
}
|
||||
|
||||
rbusValue_t payload = rbusObject_GetValue(inParams, "payload");
|
||||
if(payload)
|
||||
{
|
||||
if((rbusValue_GetType(payload) == RBUS_STRING))
|
||||
{
|
||||
payloadStr = (char *)rbusValue_GetString(payload, NULL);
|
||||
if(payloadStr !=NULL)
|
||||
{
|
||||
ParodusPrint("payload received is %s\n", payloadStr);
|
||||
msg->u.event.payload = strdup(payloadStr);
|
||||
ParodusPrint("msg->u.event.payload is %s\n", msg->u.event.payload);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("payloadStr is empty\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("payload is empty\n");
|
||||
}
|
||||
|
||||
rbusValue_t payloadlen = rbusObject_GetValue(inParams, "payloadlen");
|
||||
if(payloadlen)
|
||||
{
|
||||
if(rbusValue_GetType(payloadlen) == RBUS_INT32)
|
||||
{
|
||||
ParodusPrint("payloadlen type %d RBUS_INT32 %d\n", rbusValue_GetType(payloadlen), RBUS_INT32);
|
||||
payloadlength = rbusValue_GetInt32(payloadlen);
|
||||
ParodusPrint("payloadlen received is %lu\n", payloadlength);
|
||||
msg->u.event.payload_size = (size_t) payloadlength;
|
||||
ParodusPrint("msg->u.event.payload_size is %lu\n", msg->u.event.payload_size);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("payloadlen is empty\n");
|
||||
}
|
||||
|
||||
ParodusPrint("check qos\n");
|
||||
rbusValue_t qos = rbusObject_GetValue(inParams, "qos");
|
||||
if(qos)
|
||||
{
|
||||
if(rbusValue_GetType(qos) == RBUS_STRING)
|
||||
{
|
||||
ParodusPrint("qos type %d RBUS_STRING %d\n", rbusValue_GetType(qos), RBUS_STRING);
|
||||
qosVal = (char *)rbusValue_GetString(qos, NULL);
|
||||
ParodusPrint("qos received is %s\n", qosVal);
|
||||
if(qosVal !=NULL)
|
||||
{
|
||||
msg->u.event.qos = atoi(qosVal);
|
||||
ParodusPrint("msg->u.event.qos is %d\n", msg->u.event.qos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(trans_id !=NULL)
|
||||
{
|
||||
ParodusPrint("Add trans_id %s to wrp message\n", trans_id);
|
||||
msg->u.event.transaction_uuid = strdup(trans_id);
|
||||
free(trans_id);
|
||||
trans_id = NULL;
|
||||
ParodusPrint("msg->u.event.transaction_uuid is %s\n", msg->u.event.transaction_uuid);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("transaction_uuid is empty\n");
|
||||
}
|
||||
|
||||
*eventMsg = msg;
|
||||
ParodusPrint("parseRbusInparamsToWrp End\n");
|
||||
}
|
||||
|
||||
static rbusError_t sendDataHandler(rbusHandle_t handle, char const* methodName, rbusObject_t inParams, rbusObject_t outParams, rbusMethodAsyncHandle_t asyncHandle)
|
||||
{
|
||||
(void) handle;
|
||||
(void) outParams;
|
||||
int inStatus = 0;
|
||||
char *transaction_uuid = NULL;
|
||||
wrp_msg_t *wrpMsg= NULL;
|
||||
ParodusInfo("methodHandler called: %s\n", methodName);
|
||||
//printRBUSParams(inParams, INPARAMS_PATH);
|
||||
|
||||
if((methodName !=NULL) && (strcmp(methodName, XMIDT_SEND_METHOD) == 0))
|
||||
{
|
||||
inStatus = checkInputParameters(inParams);
|
||||
if(inStatus)
|
||||
{
|
||||
//generate transaction id to create outParams and send ack
|
||||
transaction_uuid = generate_transaction_uuid();
|
||||
ParodusInfo("xmidt transaction_uuid generated is %s\n", transaction_uuid);
|
||||
parseRbusInparamsToWrp(inParams, transaction_uuid, &wrpMsg);
|
||||
|
||||
//xmidt send producer
|
||||
addToXmidtUpstreamQ(wrpMsg, asyncHandle);
|
||||
ParodusInfo("sendDataHandler returned %d\n", RBUS_ERROR_ASYNC_RESPONSE);
|
||||
return RBUS_ERROR_ASYNC_RESPONSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("check method call received, ignoring input\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Method %s received is not supported\n", methodName);
|
||||
return RBUS_ERROR_BUS_ERROR;
|
||||
}
|
||||
ParodusPrint("send RBUS_ERROR_SUCCESS\n");
|
||||
return RBUS_ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int regXmidtSendDataMethod()
|
||||
{
|
||||
int rc = RBUS_ERROR_SUCCESS;
|
||||
rbusDataElement_t dataElements[1] = { { XMIDT_SEND_METHOD, RBUS_ELEMENT_TYPE_METHOD, { NULL, NULL, NULL, NULL, NULL, sendDataHandler } } };
|
||||
|
||||
rbusHandle_t rbus_handle = get_parodus_rbus_Handle();
|
||||
|
||||
ParodusPrint("Registering xmidt sendData method %s\n", XMIDT_SEND_METHOD);
|
||||
if(!rbus_handle)
|
||||
{
|
||||
ParodusError("regXmidtSendDataMethod failed as rbus_handle is empty\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = rbus_regDataElements(rbus_handle, 1, dataElements);
|
||||
|
||||
if(rc != RBUS_ERROR_SUCCESS)
|
||||
{
|
||||
ParodusError("Register xmidt sendData method failed: %d\n", rc);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusInfo("Register xmidt sendData method %s success\n", XMIDT_SEND_METHOD);
|
||||
|
||||
//start xmidt queue consumer thread .
|
||||
processXmidtData();
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
//To print and store params output to a file
|
||||
void printRBUSParams(rbusObject_t params, char* file_path)
|
||||
{
|
||||
if( NULL != params )
|
||||
{
|
||||
FILE *fd = fopen(file_path, "w+");
|
||||
rbusObject_fwrite(params, 1, fd);
|
||||
fclose(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Params is NULL\n");
|
||||
}
|
||||
}
|
||||
85
src/xmidtsend_rbus.h
Normal file
85
src/xmidtsend_rbus.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* Copyright 2022 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @file xmidtsend_rbus.h
|
||||
*
|
||||
* @description This header defines functions required to manage xmidt send messages via rbus.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _XMIDTSEND_RBUS_H_
|
||||
#define _XMIDTSEND_RBUS_H_
|
||||
#include <rbus.h>
|
||||
#include <uuid/uuid.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define XMIDT_SEND_METHOD "Device.X_RDK_Xmidt.SendData"
|
||||
#define MAX_QUEUE_SIZE 10
|
||||
#define INPARAMS_PATH "/tmp/inparams.txt"
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Data Structures */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
typedef struct XmidtMsg__
|
||||
{
|
||||
wrp_msg_t *msg;
|
||||
rbusMethodAsyncHandle_t asyncHandle;
|
||||
struct XmidtMsg__ *next;
|
||||
} XmidtMsg;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DELIVERED_SUCCESS = 0,
|
||||
INVALID_MSG_TYPE,
|
||||
MISSING_SOURCE,
|
||||
MISSING_DEST,
|
||||
MISSING_CONTENT_TYPE,
|
||||
MISSING_PAYLOAD,
|
||||
MISSING_PAYLOADLEN,
|
||||
QUEUE_SIZE_EXCEEDED,
|
||||
WRP_ENCODE_FAILURE,
|
||||
MSG_PROCESSING_FAILED,
|
||||
ENQUEUE_FAILURE = 100,
|
||||
CLIENT_DISCONNECT = 101
|
||||
} XMIDT_STATUS;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Function Prototypes */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
rbusHandle_t get_parodus_rbus_Handle(void);
|
||||
void addToXmidtUpstreamQ(wrp_msg_t * msg, rbusMethodAsyncHandle_t asyncHandle);
|
||||
void* processXmidtUpstreamMsg();
|
||||
void processXmidtData();
|
||||
int processData(wrp_msg_t * msg, rbusMethodAsyncHandle_t asyncHandle);
|
||||
void sendXmidtEventToServer(wrp_msg_t * msg, rbusMethodAsyncHandle_t asyncHandle);
|
||||
int checkInputParameters(rbusObject_t inParams);
|
||||
char* generate_transaction_uuid();
|
||||
void parseRbusInparamsToWrp(rbusObject_t inParams, char *trans_id, wrp_msg_t **eventMsg);
|
||||
void createOutParamsandSendAck(wrp_msg_t *msg, rbusMethodAsyncHandle_t asyncHandle, char *errorMsg, int statuscode);
|
||||
int validateXmidtData(wrp_msg_t * eventMsg, char **errorMsg, int *statusCode);
|
||||
void xmidtQDequeue();
|
||||
bool highQosValueCheck(int qos);
|
||||
void waitTillConnectionIsUp();
|
||||
void printRBUSParams(rbusObject_t params, char* file_path);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _XMIDTSEND_RBUS_H_ */
|
||||
|
||||
@@ -32,6 +32,10 @@ if (FEATURE_DNS_QUERY)
|
||||
set (PARODUS_COMMON_LIBS ${PARODUS_COMMON_LIBS} -lucresolv -lresolv)
|
||||
endif (FEATURE_DNS_QUERY)
|
||||
|
||||
if (ENABLE_WEBCFGBIN)
|
||||
set (PARODUS_COMMON_LIBS ${PARODUS_COMMON_LIBS} -lrbus -lrbus-core)
|
||||
endif (ENABLE_WEBCFGBIN)
|
||||
|
||||
if(NOT DISABLE_VALGRIND)
|
||||
set (MEMORY_CHECK valgrind --leak-check=full --show-reachable=yes -v)
|
||||
endif ()
|
||||
@@ -90,16 +94,16 @@ target_link_libraries (test_spin_thread_e ${PARODUS_COMMON_LIBS} )
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_spin_thread success
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_spin_thread_s COMMAND ${MEMORY_CHECK} ./test_spin_thread_s)
|
||||
add_executable(test_spin_thread_s test_spin_thread_s.c ../src/spin_thread.c)
|
||||
target_link_libraries (test_spin_thread_s ${PARODUS_COMMON_LIBS} )
|
||||
# add_test(NAME test_spin_thread_s COMMAND ${MEMORY_CHECK} ./test_spin_thread_s)
|
||||
# add_executable(test_spin_thread_s test_spin_thread_s.c ../src/spin_thread.c)
|
||||
# target_link_libraries (test_spin_thread_s ${PARODUS_COMMON_LIBS} )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_string_helpers
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_string_helpers COMMAND ${MEMORY_CHECK} ./test_string_helpers)
|
||||
add_executable(test_string_helpers test_string_helpers.c ../src/string_helpers.c)
|
||||
target_link_libraries (test_string_helpers ${PARODUS_COMMON_LIBS} )
|
||||
# add_test(NAME test_string_helpers COMMAND ${MEMORY_CHECK} ./test_string_helpers)
|
||||
# add_executable(test_string_helpers test_string_helpers.c ../src/string_helpers.c)
|
||||
# target_link_libraries (test_string_helpers ${PARODUS_COMMON_LIBS} )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_nopoll_handlers
|
||||
@@ -154,7 +158,11 @@ set(CLIST_SRC ${CLIST_SRC} ../src/seshat_interface.c)
|
||||
else()
|
||||
set(CLIST_SRC ${CLIST_SRC} ../src/seshat_interface_stub.c)
|
||||
endif (ENABLE_SESHAT)
|
||||
|
||||
|
||||
if (ENABLE_WEBCFGBIN)
|
||||
set(CLIST_SRC ${CLIST_SRC} ../src/upstream_rbus.c ../src/xmidtsend_rbus.c)
|
||||
endif (ENABLE_WEBCFGBIN)
|
||||
|
||||
add_executable(test_client_list ${CLIST_SRC})
|
||||
#target_link_libraries (test_client_list ${PARODUS_CONN_LIBS} ${PARODUS_COMMON_LIBS})
|
||||
target_link_libraries (test_client_list ${PARODUS_COMMON_LIBS} -lcurl -luuid)
|
||||
@@ -172,6 +180,10 @@ else()
|
||||
set(SVA_SRC ${SVA_SRC} ../src/seshat_interface_stub.c)
|
||||
endif (ENABLE_SESHAT)
|
||||
|
||||
if (ENABLE_WEBCFGBIN)
|
||||
set(SVA_SRC ${SVA_SRC} ../src/upstream_rbus.c ../src/xmidtsend_rbus.c)
|
||||
endif (ENABLE_WEBCFGBIN)
|
||||
|
||||
add_executable(test_service_alive ${SVA_SRC})
|
||||
#target_link_libraries (test_service_alive ${PARODUS_CONN_LIBS} ${PARODUS_COMMON_LIBS})
|
||||
target_link_libraries (test_service_alive ${PARODUS_COMMON_LIBS} -lcurl -luuid)
|
||||
@@ -225,7 +237,7 @@ target_link_libraries (test_crud_tasks -lcmocka ${PARODUS_COMMON_LIBS} )
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_crud_internal COMMAND ${MEMORY_CHECK} ./test_crud_internal)
|
||||
add_executable(test_crud_internal test_crud_internal.c ../src/config.c ../src/close_retry.c
|
||||
../src/ParodusInternal.c ../src/string_helpers.c ../src/crud_internal.c )
|
||||
../src/ParodusInternal.c ../src/string_helpers.c ../src/crud_internal.c ../src/client_list.c)
|
||||
target_link_libraries (test_crud_internal -lcmocka ${PARODUS_COMMON_LIBS} -lcurl -luuid)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -236,7 +248,7 @@ add_executable(test_upstream test_upstream.c ../src/upstream.c ../src/close_retr
|
||||
target_link_libraries (test_upstream -lcmocka gcov -lcunit -lcimplog
|
||||
-lwrp-c -luuid -lpthread -lmsgpackc -lnopoll
|
||||
-Wl,--no-as-needed -lcjson -lcjwt -ltrower-base64
|
||||
-lssl -lcrypto -lrt -lm)
|
||||
-lssl -lcrypto -lrt -lm -lnanomsg)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_upstream_sock
|
||||
@@ -287,12 +299,16 @@ set(CONIFC_SRC test_conn_interface.c
|
||||
../src/heartBeat.c
|
||||
../src/close_retry.c
|
||||
../src/event_handler.c
|
||||
../src/client_list.c
|
||||
)
|
||||
if (ENABLE_SESHAT)
|
||||
set(CONIFC_SRC ${CONIFC_SRC} ../src/seshat_interface.c)
|
||||
else()
|
||||
set(CONIFC_SRC ${CONIFC_SRC} ../src/seshat_interface_stub.c)
|
||||
endif (ENABLE_SESHAT)
|
||||
if (ENABLE_WEBCFGBIN)
|
||||
set(CONIFC_SRC ${CONIFC_SRC} ../src/upstream_rbus.c ../src/xmidtsend_rbus.c)
|
||||
endif (ENABLE_WEBCFGBIN)
|
||||
add_executable(test_conn_interface ${CONIFC_SRC})
|
||||
target_link_libraries (test_conn_interface -lcmocka ${PARODUS_COMMON_LIBS} -lcurl -luuid )
|
||||
|
||||
@@ -339,6 +355,10 @@ else()
|
||||
set(TOKEN_SRC test_token_stub.c ${TOKEN_SRC})
|
||||
endif (FEATURE_DNS_QUERY)
|
||||
|
||||
if (ENABLE_WEBCFGBIN)
|
||||
set(TOKEN_SRC ${TOKEN_SRC} ../src/upstream_rbus.c ../src/xmidtsend_rbus.c)
|
||||
endif (ENABLE_WEBCFGBIN)
|
||||
|
||||
add_executable(test_token ${TOKEN_SRC} )
|
||||
#target_link_libraries (test_token ${PARODUS_COMMON_LIBS} ${PARODUS_JWT_LIBS} -lcmocka )
|
||||
target_link_libraries (test_token ${PARODUS_COMMON_LIBS} -lcmocka -lcurl -luuid)
|
||||
|
||||
@@ -92,7 +92,7 @@ void test_set_parodus_cfg()
|
||||
CU_ASSERT_STRING_EQUAL(cfg.hw_last_reboot_reason,get_parodus_cfg()->hw_last_reboot_reason);
|
||||
CU_ASSERT_STRING_EQUAL(cfg.fw_name,get_parodus_cfg()->fw_name);
|
||||
CU_ASSERT_STRING_EQUAL(cfg.webpa_url, get_parodus_cfg()->webpa_url);
|
||||
CU_ASSERT_STRING_EQUAL(cfg.webpa_interface_used , get_parodus_cfg()->webpa_interface_used);
|
||||
CU_ASSERT_STRING_EQUAL(cfg.webpa_interface_used , getWebpaInterface());
|
||||
CU_ASSERT_STRING_EQUAL(cfg.webpa_protocol, get_parodus_cfg()->webpa_protocol);
|
||||
CU_ASSERT_EQUAL(cfg.boot_time, get_parodus_cfg()->boot_time);
|
||||
CU_ASSERT_EQUAL(cfg.webpa_ping_timeout, get_parodus_cfg()->webpa_ping_timeout);
|
||||
@@ -113,7 +113,7 @@ void test_getWebpaConveyHeader()
|
||||
CU_ASSERT_STRING_EQUAL(get_parodus_cfg()->hw_manufacturer, cJSON_GetObjectItem(payload, HW_MANUFACTURER)->valuestring);
|
||||
CU_ASSERT_STRING_EQUAL(get_parodus_cfg()->hw_last_reboot_reason, cJSON_GetObjectItem(payload, HW_LAST_REBOOT_REASON)->valuestring);
|
||||
CU_ASSERT_STRING_EQUAL(get_parodus_cfg()->fw_name, cJSON_GetObjectItem(payload, FIRMWARE_NAME)->valuestring);
|
||||
CU_ASSERT_STRING_EQUAL(get_parodus_cfg()->webpa_interface_used, cJSON_GetObjectItem(payload, WEBPA_INTERFACE)->valuestring);
|
||||
CU_ASSERT_STRING_EQUAL(getWebpaInterface(), cJSON_GetObjectItem(payload, WEBPA_INTERFACE)->valuestring);
|
||||
CU_ASSERT_STRING_EQUAL(get_parodus_cfg()->webpa_protocol, cJSON_GetObjectItem(payload, WEBPA_PROTOCOL)->valuestring);
|
||||
CU_ASSERT_EQUAL((int)get_parodus_cfg()->boot_time, cJSON_GetObjectItem(payload, BOOT_TIME)->valueint);
|
||||
|
||||
|
||||
@@ -54,7 +54,9 @@ int curl_easy_perform(CURL *curl)
|
||||
write_callback_fn (msg, 1, strlen(msg), &test_data);
|
||||
return rtn;
|
||||
}
|
||||
int g_response_code=0;
|
||||
|
||||
extern int g_response_code;
|
||||
|
||||
void setGlobalResponseCode (int response_code)
|
||||
{
|
||||
g_response_code = response_code;
|
||||
@@ -72,6 +74,12 @@ int curl_easy_getinfo(CURL *curl, CURLINFO CURLINFO_RESPONSE_CODE, long response
|
||||
function_called();
|
||||
return (int) mock();
|
||||
}
|
||||
|
||||
char* get_global_reconnect_reason()
|
||||
{
|
||||
return "none";
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
@@ -69,6 +69,13 @@ int curl_easy_getinfo(CURL *curl, CURLINFO CURLINFO_RESPONSE_CODE, long response
|
||||
function_called();
|
||||
return (int) mock();
|
||||
}
|
||||
|
||||
char* get_global_reconnect_reason()
|
||||
{
|
||||
return "none";
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
@@ -32,6 +32,8 @@ pthread_t test_tid2;
|
||||
static void *client_rcv_task();
|
||||
static void *client2_rcv_task();
|
||||
|
||||
int numLoops;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
@@ -53,6 +53,11 @@ void create_token_script(char *fname)
|
||||
system(command);
|
||||
}
|
||||
|
||||
char* get_global_reconnect_reason()
|
||||
{
|
||||
return "none";
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -98,7 +103,7 @@ void test_setParodusConfig()
|
||||
assert_string_equal(cfg.hw_last_reboot_reason, temp->hw_last_reboot_reason);
|
||||
assert_string_equal(cfg.webpa_path_url, temp->webpa_path_url);
|
||||
assert_string_equal(cfg.webpa_url, temp->webpa_url);
|
||||
assert_string_equal(cfg.webpa_interface_used, temp->webpa_interface_used);
|
||||
assert_string_equal(cfg.webpa_interface_used, getWebpaInterface());
|
||||
assert_string_equal(cfg.webpa_protocol, temp->webpa_protocol);
|
||||
assert_string_equal(cfg.webpa_uuid, temp->webpa_uuid);
|
||||
assert_string_equal(cfg.partner_id, temp->partner_id);
|
||||
@@ -116,6 +121,8 @@ void test_setParodusConfig()
|
||||
assert_string_equal(cfg.jwt_key, temp->jwt_key);
|
||||
#endif
|
||||
assert_string_equal(cfg.crud_config_file, temp->crud_config_file);
|
||||
|
||||
free(cfg.crud_config_file);
|
||||
}
|
||||
|
||||
void test_getParodusConfig()
|
||||
@@ -201,13 +208,11 @@ void test_parseCommandLine()
|
||||
|
||||
ParodusCfg parodusCfg;
|
||||
memset(&parodusCfg,0,sizeof(parodusCfg));
|
||||
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
write_key_to_file ("../../tests/jwt_key.tst", jwt_key);
|
||||
#endif
|
||||
create_token_script("/tmp/token.sh");
|
||||
assert_int_equal (parseCommandLine(argc,command,&parodusCfg), 0);
|
||||
|
||||
assert_string_equal( parodusCfg.hw_model, "TG1682");
|
||||
assert_string_equal( parodusCfg.hw_serial_number, "Fer23u948590");
|
||||
assert_string_equal( parodusCfg.hw_manufacturer, "ARRISGroup,Inc.");
|
||||
@@ -299,8 +304,9 @@ void test_loadParodusCfg()
|
||||
{
|
||||
ParodusCfg tmpcfg;
|
||||
ParodusCfg *Cfg = NULL;
|
||||
Cfg = (ParodusCfg*)malloc(sizeof(ParodusCfg));
|
||||
char protocol[32] = {'\0'};
|
||||
Cfg = (ParodusCfg*)malloc(sizeof(ParodusCfg));
|
||||
memset(Cfg, 0, sizeof(ParodusCfg));
|
||||
|
||||
parStrncpy(Cfg->hw_model, "TG1682", sizeof(Cfg->hw_model));
|
||||
parStrncpy(Cfg->hw_serial_number, "Fer23u948590", sizeof(Cfg->hw_serial_number));
|
||||
@@ -351,6 +357,14 @@ void test_loadParodusCfg()
|
||||
assert_string_equal(tmpcfg.seshat_url, "ipc://tmp/seshat_service.url");
|
||||
#endif
|
||||
assert_string_equal(tmpcfg.crud_config_file, "parodus_cfg.json");
|
||||
|
||||
free(tmpcfg.client_cert_path);
|
||||
free(tmpcfg.token_server_url);
|
||||
free(tmpcfg.crud_config_file);
|
||||
|
||||
free(Cfg->crud_config_file);
|
||||
free(Cfg->client_cert_path);
|
||||
free(Cfg->token_server_url);
|
||||
free(Cfg);
|
||||
}
|
||||
|
||||
@@ -422,6 +436,8 @@ void test_setDefaultValuesToCfg()
|
||||
assert_string_equal(cfg->webpa_path_url, WEBPA_PATH_URL);
|
||||
assert_string_equal(cfg->webpa_uuid, "1234567-345456546");
|
||||
assert_string_equal(cfg->cloud_status, CLOUD_STATUS_OFFLINE);
|
||||
|
||||
free(cfg);
|
||||
}
|
||||
|
||||
void err_setDefaultValuesToCfg()
|
||||
|
||||
@@ -42,8 +42,9 @@ pthread_mutex_t nano_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t nano_con=PTHREAD_COND_INITIALIZER;
|
||||
pthread_mutex_t svc_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t svc_con=PTHREAD_COND_INITIALIZER;
|
||||
int numLoops;
|
||||
parodusOnPingStatusChangeHandler on_ping_status_change;
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -102,6 +103,11 @@ void set_global_shutdown_reason(char *reason)
|
||||
UNUSED(reason);
|
||||
}
|
||||
|
||||
int getDeviceId(char **device_id, size_t *device_id_len)
|
||||
{
|
||||
UNUSED(device_id); UNUSED(device_id_len);
|
||||
return 0;
|
||||
}
|
||||
void start_conn_in_progress (unsigned long start_time)
|
||||
{
|
||||
UNUSED(start_time);
|
||||
@@ -171,6 +177,18 @@ int serviceAliveTask()
|
||||
return 0;
|
||||
}
|
||||
|
||||
int validate_partner_id(wrp_msg_t *msg, partners_t **partnerIds)
|
||||
{
|
||||
UNUSED(msg); UNUSED(partnerIds);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sendUpstreamMsgToServer(void **resp_bytes, size_t resp_size)
|
||||
{
|
||||
UNUSED(resp_bytes); UNUSED(resp_size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nopoll_loop_wait(noPollCtx * ctx,long timeout)
|
||||
{
|
||||
UNUSED(ctx); UNUSED(timeout);
|
||||
@@ -291,9 +309,6 @@ void timespec_diff(struct timespec *start, struct timespec *stop,
|
||||
diff->tv_nsec = 1000;
|
||||
}
|
||||
|
||||
void deleteAllClients (void)
|
||||
{
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
@@ -337,6 +352,7 @@ void test_createSocketConnection()
|
||||
|
||||
void test_createSocketConnection1()
|
||||
{
|
||||
numLoops =0;
|
||||
noPollCtx *ctx;
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg,0, sizeof(ParodusCfg));
|
||||
@@ -366,11 +382,11 @@ void test_createSocketConnection1()
|
||||
expect_function_call(nopoll_ctx_unref);
|
||||
expect_function_call(nopoll_cleanup_library);
|
||||
createSocketConnection(NULL);
|
||||
|
||||
}
|
||||
|
||||
void test_PingMissIntervalTime()
|
||||
{
|
||||
numLoops = 6;
|
||||
noPollCtx *ctx;
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg,0,sizeof(ParodusCfg));
|
||||
@@ -388,7 +404,6 @@ void test_PingMissIntervalTime()
|
||||
//Max ping timeout is 6 sec
|
||||
cfg.webpa_ping_timeout = 6;
|
||||
set_parodus_cfg(&cfg);
|
||||
|
||||
reset_close_retry();
|
||||
expect_function_call(nopoll_thread_handlers);
|
||||
|
||||
@@ -424,11 +439,11 @@ void test_PingMissIntervalTime()
|
||||
expect_function_call(nopoll_ctx_unref);
|
||||
expect_function_call(nopoll_cleanup_library);
|
||||
createSocketConnection(NULL);
|
||||
|
||||
}
|
||||
|
||||
void err_createSocketConnection()
|
||||
{
|
||||
numLoops =0;
|
||||
set_close_retry();
|
||||
reset_heartBeatTimer();
|
||||
expect_function_call(nopoll_thread_handlers);
|
||||
@@ -461,6 +476,7 @@ void err_createSocketConnection()
|
||||
|
||||
void test_createSocketConnection_cloud_disconn()
|
||||
{
|
||||
numLoops =0;
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg,0,sizeof(ParodusCfg));
|
||||
cfg.cloud_disconnect = strdup("XPC");
|
||||
|
||||
@@ -62,10 +62,8 @@ extern int keep_trying_to_connect (create_connection_ctx_t *ctx,
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
bool close_retry;
|
||||
bool LastReasonStatus;
|
||||
bool interface_down_event = false;
|
||||
pthread_mutex_t close_mut;
|
||||
pthread_mutex_t interface_down_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t interface_down_con=PTHREAD_COND_INITIALIZER;
|
||||
|
||||
|
||||
@@ -341,7 +341,7 @@ void test_createConnection()
|
||||
|
||||
int ret = createNopollConnection(ctx);
|
||||
assert_int_equal(ret, nopoll_true);
|
||||
assert_string_equal(get_parodus_cfg()->cloud_status, CLOUD_STATUS_ONLINE);
|
||||
assert_string_equal(get_cloud_status(), CLOUD_STATUS_ONLINE);
|
||||
free(cfg);
|
||||
if (g_jwt_server_ip !=NULL)
|
||||
{
|
||||
|
||||
@@ -125,6 +125,10 @@ int processCrudRequest(wrp_msg_t *reqMsg, wrp_msg_t **responseMsg )
|
||||
return (int)mock();
|
||||
}
|
||||
|
||||
char* getWebpaInterface(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
@@ -32,9 +32,6 @@
|
||||
#include "../src/connection.h"
|
||||
#include "../src/close_retry.h"
|
||||
|
||||
bool LastReasonStatus;
|
||||
pthread_mutex_t close_mut;
|
||||
|
||||
char *get_global_reconnect_reason()
|
||||
{
|
||||
return "parodus_stopping";
|
||||
@@ -1533,7 +1530,7 @@ void test_retrieveObject_cloud_status()
|
||||
ret = retrieveObject(reqMsg, &respMsg);
|
||||
assert_int_equal (respMsg->u.crud.status, 200);
|
||||
assert_int_equal (ret, 0);
|
||||
assert_string_equal(get_parodus_cfg()->cloud_status, CLOUD_STATUS_ONLINE);
|
||||
assert_string_equal(get_cloud_status(), CLOUD_STATUS_ONLINE);
|
||||
assert_int_equal (respMsg->u.crud.payload_size, 25);
|
||||
|
||||
fp = fopen(cfg.crud_config_file, "r");
|
||||
|
||||
@@ -28,14 +28,11 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
volatile unsigned int heartBeatTimer;
|
||||
bool LastReasonStatus;
|
||||
bool interface_down_event = false;
|
||||
int closeReason = 0;
|
||||
pthread_mutex_t close_mut;
|
||||
pthread_mutex_t interface_down_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t interface_down_con=PTHREAD_COND_INITIALIZER;
|
||||
bool close_retry;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
@@ -30,10 +30,7 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
volatile unsigned int heartBeatTimer;
|
||||
bool LastReasonStatus;
|
||||
pthread_mutex_t close_mut;
|
||||
bool close_retry;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
@@ -131,6 +131,11 @@ bool get_interface_down_event()
|
||||
return false;
|
||||
}
|
||||
|
||||
char *get_cloud_status(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
@@ -32,6 +32,7 @@ static void *client_rcv_task();
|
||||
static void *keep_alive_thread();
|
||||
static void add_client();
|
||||
int sock1;
|
||||
int numLoops;
|
||||
pthread_t threadId;
|
||||
pthread_mutex_t crud_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t crud_con=PTHREAD_COND_INITIALIZER;
|
||||
|
||||
@@ -160,6 +160,7 @@ extern unsigned int get_algo_mask (const char *algo_str);
|
||||
|
||||
pthread_mutex_t crud_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t crud_con=PTHREAD_COND_INITIALIZER;
|
||||
int numLoops;
|
||||
|
||||
pthread_cond_t *get_global_crud_con(void)
|
||||
{
|
||||
|
||||
@@ -26,12 +26,12 @@
|
||||
#include <pthread.h>
|
||||
#include "../src/token.h"
|
||||
|
||||
int numLoops;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
pthread_mutex_t crud_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t crud_con=PTHREAD_COND_INITIALIZER;
|
||||
|
||||
|
||||
@@ -44,10 +44,12 @@ extern size_t metaPackSize;
|
||||
extern UpStreamMsg *UpStreamMsgQ;
|
||||
int numLoops = 1;
|
||||
int deviceIDNull =0;
|
||||
char webpa_interface[64]={'\0'};
|
||||
wrp_msg_t *temp = NULL;
|
||||
extern pthread_mutex_t nano_mut;
|
||||
extern pthread_cond_t nano_con;
|
||||
static int crud_test = 0;
|
||||
pthread_mutex_t config_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -116,6 +118,27 @@ ParodusCfg *get_parodus_cfg(void)
|
||||
return &parodusCfg;
|
||||
}
|
||||
|
||||
char *getWebpaInterface(void)
|
||||
{
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg,0,sizeof(cfg));
|
||||
#ifdef WAN_FAILOVER_SUPPORTED
|
||||
parStrncpy(cfg.webpa_interface_used , "wl0", sizeof(cfg.webpa_interface_used));
|
||||
#else
|
||||
parStrncpy(cfg.webpa_interface_used , "eth0", sizeof(cfg.webpa_interface_used));
|
||||
#endif
|
||||
set_parodus_cfg(&cfg);
|
||||
#ifdef WAN_FAILOVER_SUPPORTED
|
||||
ParodusPrint("WAN_FAILOVER_SUPPORTED mode \n");
|
||||
pthread_mutex_lock (&config_mut);
|
||||
parStrncpy(webpa_interface, get_parodus_cfg()->webpa_interface_used, sizeof(webpa_interface));
|
||||
pthread_mutex_unlock (&config_mut);
|
||||
#else
|
||||
parStrncpy(webpa_interface, get_parodus_cfg()->webpa_interface_used, sizeof(webpa_interface));
|
||||
#endif
|
||||
return webpa_interface;
|
||||
}
|
||||
|
||||
ssize_t wrp_pack_metadata( const data_t *packData, void **data )
|
||||
{
|
||||
(void) packData; (void) data;
|
||||
|
||||
@@ -46,10 +46,11 @@ extern size_t metaPackSize;
|
||||
extern UpStreamMsg *UpStreamMsgQ;
|
||||
int numLoops = 1;
|
||||
int deviceIDNull =0;
|
||||
char webpa_interface[64]={'\0'};
|
||||
wrp_msg_t *reg_msg = NULL;
|
||||
extern pthread_mutex_t nano_mut;
|
||||
extern pthread_cond_t nano_con;
|
||||
|
||||
pthread_mutex_t config_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -101,6 +102,27 @@ ParodusCfg *get_parodus_cfg(void)
|
||||
return &parodusCfg;
|
||||
}
|
||||
|
||||
char *getWebpaInterface(void)
|
||||
{
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg,0,sizeof(cfg));
|
||||
#ifdef WAN_FAILOVER_SUPPORTED
|
||||
parStrncpy(cfg.webpa_interface_used , "wl0", sizeof(cfg.webpa_interface_used));
|
||||
#else
|
||||
parStrncpy(cfg.webpa_interface_used , "eth0", sizeof(cfg.webpa_interface_used));
|
||||
#endif
|
||||
set_parodus_cfg(&cfg);
|
||||
#ifdef WAN_FAILOVER_SUPPORTED
|
||||
ParodusPrint("WAN_FAILOVER_SUPPORTED mode \n");
|
||||
pthread_mutex_lock (&config_mut);
|
||||
parStrncpy(webpa_interface, get_parodus_cfg()->webpa_interface_used, sizeof(webpa_interface));
|
||||
pthread_mutex_unlock (&config_mut);
|
||||
#else
|
||||
parStrncpy(webpa_interface, get_parodus_cfg()->webpa_interface_used, sizeof(webpa_interface));
|
||||
#endif
|
||||
return webpa_interface;
|
||||
}
|
||||
|
||||
/*-------------------------------------------
|
||||
int nn_connect (int s, const char *addr)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user