mirror of
https://github.com/outbackdingo/parodus.git
synced 2026-01-27 18:20:04 +00:00
Compare commits
397 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
85a0d9b71d | ||
|
|
03a5b96e0c | ||
|
|
066bdc180d | ||
|
|
118e8ee32f | ||
|
|
f7c9f483f9 | ||
|
|
502f56400e | ||
|
|
3e557ae4b0 | ||
|
|
0602fb243b | ||
|
|
1a7ae0b785 | ||
|
|
bc655cf9ba | ||
|
|
ad0491179d | ||
|
|
fa49a52a94 | ||
|
|
25baef78a8 | ||
|
|
9034ef9d10 | ||
|
|
9020089016 | ||
|
|
664690e6a6 | ||
|
|
4aed47b730 | ||
|
|
2f3f1424b4 | ||
|
|
91ae0e82e2 | ||
|
|
bfc2659bbb | ||
|
|
f9c2878cbf | ||
|
|
c84a1bdfad | ||
|
|
0b0ba77bd6 | ||
|
|
0b0309c3dd | ||
|
|
f4e358c179 | ||
|
|
0561c67e5c | ||
|
|
c1fc8d877b | ||
|
|
581d7fc966 | ||
|
|
0673d2624e | ||
|
|
0f82e7c2d9 | ||
|
|
4acf7f63ba | ||
|
|
df67b95244 | ||
|
|
e6e37053d3 | ||
|
|
d5a9ff36f6 | ||
|
|
f4536b778e | ||
|
|
b65b3ab3b0 | ||
|
|
954080bbd1 | ||
|
|
c8a2c95ae4 | ||
|
|
59bba50bee | ||
|
|
3090e50b02 | ||
|
|
af4eeb9199 | ||
|
|
2dd392dac6 | ||
|
|
7eae3da3f2 | ||
|
|
6e5ecc87f9 | ||
|
|
893c1c7547 | ||
|
|
3e30328738 | ||
|
|
f7412f9710 | ||
|
|
2e11d7e3ba | ||
|
|
5ddac7dc47 | ||
|
|
79d8a84c2e | ||
|
|
6f7332d054 | ||
|
|
26d409d884 | ||
|
|
d3e758ccb4 | ||
|
|
4af1aaf418 | ||
|
|
8e00ec8e5e | ||
|
|
43f55f9a99 | ||
|
|
bf3ee65360 | ||
|
|
9ebe011cb0 | ||
|
|
2bfc0a3c32 | ||
|
|
37bb19eeaa | ||
|
|
2c4980cf9e | ||
|
|
2248f31658 | ||
|
|
b97643ec42 | ||
|
|
66b16aa58f | ||
|
|
d3a56df184 | ||
|
|
8b5346e69b | ||
|
|
2a28e5d3e8 | ||
|
|
33af3f3eec | ||
|
|
c9b34d3c3f | ||
|
|
4add1c07ca | ||
|
|
75c833e3a8 | ||
|
|
5359fc79cf | ||
|
|
623192e301 | ||
|
|
b6490ba5b3 | ||
|
|
20ccd81086 | ||
|
|
f9ac95642c | ||
|
|
ae5d027612 | ||
|
|
e139a2d6b6 | ||
|
|
f655d6382b | ||
|
|
267e0eb796 | ||
|
|
00251153a4 | ||
|
|
d328a56e1a | ||
|
|
1a169561e4 | ||
|
|
8019489b86 | ||
|
|
ee3e006908 | ||
|
|
797c9de17f | ||
|
|
0bf4d754e5 | ||
|
|
3d98b4a80b | ||
|
|
80a50dead6 | ||
|
|
dd69d5ec5d | ||
|
|
1b23de5a12 | ||
|
|
8ea342b537 | ||
|
|
124fc11232 | ||
|
|
9abb37a005 | ||
|
|
c0edaaf31c | ||
|
|
32138613bb | ||
|
|
4cb167e8dd | ||
|
|
454ec26065 | ||
|
|
47af275929 | ||
|
|
34802d329d | ||
|
|
0297d994b5 | ||
|
|
ee7033c36c | ||
|
|
e35221efd2 | ||
|
|
c898fe6d0e | ||
|
|
0017e48f7d | ||
|
|
285a461f42 | ||
|
|
bb0f49a8b3 | ||
|
|
ee20e1fcb8 | ||
|
|
becacd8990 | ||
|
|
b05bfbe1fa | ||
|
|
9fb3f118b7 | ||
|
|
a124aafc5f | ||
|
|
0c4a2f407a | ||
|
|
523c9cc0d2 | ||
|
|
58492950d6 | ||
|
|
29906511b8 | ||
|
|
c6fa4b2ce8 | ||
|
|
0640f3516f | ||
|
|
60c37daa18 | ||
|
|
f51b4ef9c2 | ||
|
|
254c9f6763 | ||
|
|
8876fa9239 | ||
|
|
42fc9eb26e | ||
|
|
e8e652b076 | ||
|
|
dc935f9a09 | ||
|
|
d1462de56a | ||
|
|
13309a737e | ||
|
|
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 | ||
|
|
9afa49140a | ||
|
|
4305dc8eef | ||
|
|
f44fc2c8d9 | ||
|
|
16543800d2 | ||
|
|
bcb4840a41 | ||
|
|
b173828777 | ||
|
|
2df8cdfeb5 | ||
|
|
eba1309169 | ||
|
|
70c1c64550 | ||
|
|
e825c19ef3 | ||
|
|
95170d95c7 | ||
|
|
33142a6ce7 | ||
|
|
7b3ee1dd5a | ||
|
|
f2308e2966 | ||
|
|
9c55157da7 | ||
|
|
1c254e28fe | ||
|
|
8955787640 | ||
|
|
b633938bc7 | ||
|
|
b0aeaf1fb2 | ||
|
|
ea726e0c10 | ||
|
|
cbdf5d2be9 | ||
|
|
3d369cafb2 | ||
|
|
c0dbdb5028 | ||
|
|
12a7765f98 | ||
|
|
88c87917a4 | ||
|
|
0905387d49 | ||
|
|
a8167fa417 | ||
|
|
6ab601e758 | ||
|
|
45536eb4e1 | ||
|
|
8208d3bfd0 | ||
|
|
4fc60b6b3c | ||
|
|
990d9df7e2 | ||
|
|
fe52d9a55e | ||
|
|
9cfc734c51 | ||
|
|
153add9bec | ||
|
|
8b553f8a29 | ||
|
|
7679fdaf4a | ||
|
|
1c09a80493 | ||
|
|
bfad8ed44b | ||
|
|
17c7faff50 | ||
|
|
01120da9ac | ||
|
|
c7c6fb4926 | ||
|
|
f4b2c252ae | ||
|
|
8794ce2092 | ||
|
|
a61e97633b | ||
|
|
4d3d6ec99d | ||
|
|
e6ac264e47 | ||
|
|
70c9975ae9 | ||
|
|
11a2b6f123 | ||
|
|
81d8f59bbd | ||
|
|
846b0588c2 | ||
|
|
ad44ff0221 | ||
|
|
513647ceef | ||
|
|
2ec3443b1d | ||
|
|
55e10aa051 | ||
|
|
879a585b66 | ||
|
|
ea3534678b | ||
|
|
6ebb62ead4 | ||
|
|
5ec16a7370 | ||
|
|
7b81cb4efd | ||
|
|
4c6a6a99e6 | ||
|
|
106e1bfeb3 | ||
|
|
4f01170670 | ||
|
|
f37d1911d6 | ||
|
|
3a436999fc | ||
|
|
016c80960c | ||
|
|
b286857a22 | ||
|
|
f998106aed | ||
|
|
2d209b2a0d | ||
|
|
3f471100db | ||
|
|
ddc04f9da0 | ||
|
|
a23615f3a5 | ||
|
|
b1caff4a1a | ||
|
|
11c9052d77 | ||
|
|
5ceb57a8c3 | ||
|
|
c4ebe239ac | ||
|
|
1622c44c89 | ||
|
|
fb542586e7 | ||
|
|
0afb87c29b | ||
|
|
f168e4d148 | ||
|
|
97570a24d5 | ||
|
|
95b6f75284 | ||
|
|
f87e69c07b | ||
|
|
647905639c | ||
|
|
ceadc4b51f | ||
|
|
38dee179e7 | ||
|
|
9feafedff8 | ||
|
|
2807f8e43a | ||
|
|
5132675700 | ||
|
|
e166b9fdf5 | ||
|
|
60789f0ec8 | ||
|
|
3fb0708b15 | ||
|
|
65098e36cb | ||
|
|
c585300f76 | ||
|
|
e4e78118cf | ||
|
|
8b4541b570 | ||
|
|
acc542647b | ||
|
|
da6614b19d | ||
|
|
096271279d | ||
|
|
50176fb120 | ||
|
|
2ad896abc6 | ||
|
|
f58f85bc32 | ||
|
|
4fef26c082 | ||
|
|
1995a664ad | ||
|
|
f1b2add244 | ||
|
|
13739786a0 | ||
|
|
4fc082cb43 | ||
|
|
08feef216e | ||
|
|
2bde60e885 | ||
|
|
5d05150249 | ||
|
|
40bf7eeb0e | ||
|
|
fcec26a25f | ||
|
|
1b71082e77 | ||
|
|
4085c56ed6 | ||
|
|
0b700e57ff | ||
|
|
1b903521d2 | ||
|
|
3814f873bc | ||
|
|
8a3e4507ef | ||
|
|
c7c93254ff | ||
|
|
0875751c3f | ||
|
|
c2edbbc074 | ||
|
|
7b03fad90f | ||
|
|
a5081a5cfa | ||
|
|
25a6a99c69 | ||
|
|
5a60847e28 | ||
|
|
29f00e5850 | ||
|
|
4bd9e87125 | ||
|
|
56ab5f13fe | ||
|
|
57ca4084ce | ||
|
|
b001964b71 | ||
|
|
c33bb6c1c3 | ||
|
|
379e63be00 | ||
|
|
062fdc2ce0 | ||
|
|
200522c997 | ||
|
|
62540e8db8 | ||
|
|
f155dd601c | ||
|
|
b9a5770bf9 | ||
|
|
a717b0a909 | ||
|
|
a7b1a145a5 | ||
|
|
7bc498b376 | ||
|
|
fe00e55fff | ||
|
|
66104dcabc | ||
|
|
aedd9c972a | ||
|
|
99b09179f2 | ||
|
|
92020ec6ec | ||
|
|
9057322fd7 | ||
|
|
55c70f3c6f | ||
|
|
7c07a5dd63 | ||
|
|
cdd0a9e355 | ||
|
|
392085b01b | ||
|
|
bd67050c80 | ||
|
|
cea408a33c | ||
|
|
d1522346b4 | ||
|
|
22feddeadc | ||
|
|
df2729084d | ||
|
|
8a61e66456 | ||
|
|
8a737d6c18 | ||
|
|
905cb3bade | ||
|
|
a2d7dfeb95 | ||
|
|
342a8ed250 | ||
|
|
97da13ffcc | ||
|
|
590a43a053 | ||
|
|
0e6e833301 | ||
|
|
4525e39de9 | ||
|
|
8d9e9c014a | ||
|
|
9f6ddb2b78 | ||
|
|
c2f6a64569 | ||
|
|
2f0244af11 | ||
|
|
3bb48b48c0 |
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
|
||||
uses: xmidt-org/sonarcloud-installer-action@v1
|
||||
with:
|
||||
working-directory: build
|
||||
|
||||
- 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=true -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"
|
||||
}
|
||||
}
|
||||
66
CHANGELOG.md
66
CHANGELOG.md
@@ -5,6 +5,49 @@ 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]
|
||||
- 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
|
||||
- fix so that parodus can be killed, even if in a connection fail loop
|
||||
- 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
|
||||
|
||||
## [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
|
||||
- Additional `/cloud-status` and `/cloud-disconnect` fields.
|
||||
- Switched from nanomsg (Release 1.1.2) to NNG (Release v1.0.1)
|
||||
@@ -17,6 +60,19 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
- added NULL check for device mac id in upstream retrieve message handling
|
||||
- backoff retry to include find_servers in loop (connection.c)
|
||||
- backoff max is max count not max delay
|
||||
- used mutex protection to make client list and nn_sends thread safe
|
||||
- put mutex lock into get_global_node
|
||||
- change svc alive from a thread to a function called every 30 sec from main
|
||||
- shut down tasks properly
|
||||
- fix memory leaks
|
||||
- Fixed memory leak in upstream event message flow
|
||||
- Fixed crash in CRUD request processing
|
||||
- Fixed issue on RETRIEVE respone processing
|
||||
- Enabled valgrind
|
||||
- Fixed main loop to keep calling svc_alive_task during a cloud disconnect and retry
|
||||
- change svc alive back to a separate thread. Shut it down with pthread_cond_timedwait
|
||||
- Refactored Upsteam RETRIEVE flow
|
||||
- Fix re-registration to call nn_shutdown and nn_close, so we don't lose a socket.
|
||||
|
||||
## [1.0.1] - 2018-07-18
|
||||
### Added
|
||||
@@ -39,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
|
||||
@@ -48,7 +105,14 @@ 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)
|
||||
@@ -34,6 +35,7 @@ include_directories(${INCLUDE_DIR}
|
||||
${INCLUDE_DIR}/cjson
|
||||
${INCLUDE_DIR}/nopoll
|
||||
${INCLUDE_DIR}/msgpack
|
||||
${INCLUDE_DIR}/curl
|
||||
${INCLUDE_DIR}/trower-base64
|
||||
${INCLUDE_DIR}/wrp-c
|
||||
${INCLUDE_DIR}/libparodus
|
||||
@@ -41,6 +43,11 @@ include_directories(${INCLUDE_DIR}
|
||||
${INCLUDE_DIR}/cjwt
|
||||
)
|
||||
|
||||
if (ENABLE_WEBCFGBIN)
|
||||
include_directories(${INCLUDE_DIR}/rbus)
|
||||
endif (ENABLE_WEBCFGBIN)
|
||||
|
||||
|
||||
# Get git commit hash
|
||||
#-------------------------------------------------------------------------------
|
||||
execute_process(
|
||||
@@ -57,9 +64,18 @@ add_definitions("-DGIT_COMMIT_TAG=\"${GIT_COMMIT_TAG}\"")
|
||||
add_definitions(-std=c99)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE -DNOPOLL_LOGGER ")
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wall -Wno-missing-field-initializers")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall")
|
||||
if (DEVICE_CAMERA)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=all -Wno-missing-field-initializers")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=all")
|
||||
add_definitions(-DDEVICE_CAMERA)
|
||||
else ()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=all -Wno-missing-field-initializers")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=all")
|
||||
endif (DEVICE_CAMERA)
|
||||
|
||||
if (INCLUDE_BREAKPAD)
|
||||
add_definitions(-DINCLUDE_BREAKPAD)
|
||||
endif (INCLUDE_BREAKPAD)
|
||||
|
||||
# pthread external dependency
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -84,7 +100,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.1"
|
||||
GIT_TAG "1.0.3"
|
||||
CONFIGURE_COMMAND COMMAND <SOURCE_DIR>/autogen.sh --prefix=${PREFIX}
|
||||
--includedir=${INCLUDE_DIR}
|
||||
--libdir=${LIBRARY_DIR}
|
||||
@@ -100,7 +116,7 @@ add_dependencies(libnopoll nopoll)
|
||||
ExternalProject_Add(nanomsg
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/nanomsg
|
||||
GIT_REPOSITORY https://github.com/nanomsg/nanomsg.git
|
||||
GIT_TAG "1.1.2"
|
||||
GIT_TAG "1.1.4"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
|
||||
)
|
||||
add_library(libnanomsg STATIC SHARED IMPORTED)
|
||||
@@ -134,12 +150,24 @@ add_library(libmsgpack STATIC SHARED IMPORTED)
|
||||
add_dependencies(libmsgpack msgpack)
|
||||
|
||||
|
||||
# curl external dependency
|
||||
#-------------------------------------------------------------------------------
|
||||
ExternalProject_Add(curl
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/curl
|
||||
GIT_REPOSITORY https://github.com/curl/curl.git
|
||||
GIT_TAG "curl-7_63_0"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTING=OFF
|
||||
)
|
||||
add_library(libcurl STATIC SHARED IMPORTED)
|
||||
add_dependencies(libcurl curl)
|
||||
|
||||
|
||||
# cimplog external dependency
|
||||
#-------------------------------------------------------------------------------
|
||||
ExternalProject_Add(cimplog
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/cimplog
|
||||
GIT_REPOSITORY https://github.com/Comcast/cimplog.git
|
||||
GIT_TAG "1.0.1"
|
||||
GIT_TAG "1.0.2"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTING=OFF
|
||||
)
|
||||
add_library(libcimplog STATIC SHARED IMPORTED)
|
||||
@@ -151,8 +179,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 "b5ef4d10cb39905908788bc89ab3e4dab201db8a"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
|
||||
-DMSGPACK_ENABLE_CXX=OFF
|
||||
-DMSGPACK_BUILD_EXAMPLES=OFF
|
||||
@@ -191,7 +219,8 @@ endif (ENABLE_SESHAT)
|
||||
ExternalProject_Add(cjwt
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/cjwt
|
||||
GIT_REPOSITORY https://github.com/Comcast/cjwt.git
|
||||
GIT_TAG "1.0.1"
|
||||
GIT_TAG "1b023c41bb2d6dbbf493c202ed81f06c84d5b51b"
|
||||
#GIT_TAG "1.0.1"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTING=OFF
|
||||
)
|
||||
add_library(libcjwt STATIC SHARED IMPORTED)
|
||||
@@ -214,6 +243,26 @@ include_directories(${INCLUDE_DIR}
|
||||
|
||||
endif (FEATURE_DNS_QUERY)
|
||||
|
||||
if (ENABLE_WEBCFGBIN)
|
||||
# rbus external dependency
|
||||
#-------------------------------------------------------------------------------
|
||||
ExternalProject_Add(rbus
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/rbus
|
||||
GIT_REPOSITORY https://github.com/rdkcentral/rbus.git
|
||||
GIT_TAG main
|
||||
CMAKE_ARGS += -DBUILD_FOR_DESKTOP=ON -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTING=OFF
|
||||
)
|
||||
|
||||
add_library(librbuscore STATIC SHARED IMPORTED)
|
||||
add_dependencies(librbuscore rbuscore)
|
||||
|
||||
add_library(librtMessage STATIC SHARED IMPORTED)
|
||||
add_dependencies(librtMessage rtMessage)
|
||||
|
||||
add_library(librbus STATIC SHARED IMPORTED)
|
||||
add_dependencies(librbus rbus)
|
||||
endif (ENABLE_WEBCFGBIN)
|
||||
|
||||
if (BUILD_TESTING)
|
||||
# cmocka external dependency
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -238,6 +287,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)
|
||||
|
||||
30
README.md
30
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/Comcast/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
|
||||
@@ -55,9 +61,9 @@ make test
|
||||
|
||||
- /force-ipv6 -Forcefully connect parodus to ipv6 address (optional argument)
|
||||
|
||||
- /token-read-script -Script to get auth token for establishing secure connection (absolute path where that script is present) -optional argument
|
||||
- /client-cert-path -MTLS client cert location to request auth token for establishing secure connection [absolute path where client cert is present] (optional argument)
|
||||
|
||||
- /token-acquisition-script -Script to create new auth token for establishing secure connection (absolute path where that script is present) -optional argument
|
||||
- /token-server-url -complete server url with API path to request new auth token for establishing secure connection (optional argument)
|
||||
|
||||
- /crud-config-file -Config json file to store objects during create, retrieve, update and delete (CRUD) operations -optional argument
|
||||
|
||||
@@ -75,6 +81,12 @@ make test
|
||||
|
||||
- /jwt-public-key-file -JWT token validation key
|
||||
|
||||
# if ENABLE_MUTUAL_AUTH is enabled
|
||||
|
||||
- /mtls-client-cert-path - Provide the client cert for establishing a mutual auth secure websocket connection
|
||||
|
||||
- /mtls-client-key-path - Provide the client cert key for establishing a mutual auth secure websocket connection
|
||||
|
||||
```
|
||||
|
||||
# Sample parodus start commands:
|
||||
@@ -82,17 +94,17 @@ make test
|
||||
```
|
||||
# Seshat & FEATURE_DNS_QUERY Enabled
|
||||
|
||||
./parodus --hw-model=TGXXX --hw-serial-number=E8GBUEXXXXXXXXX --hw-manufacturer=ARRIS --hw-mac=14cfexxxxxxx --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_20170512115046sdy --boot-time=1494590301 --webpa-ping-timeout=180 --webpa-interface-used=eth0 --webpa-url=somebody.net:8080 --webpa-backoff-max=9 --parodus-local-url=tcp://127.0.0.1:6666 --partner-id=comcast --ssl-cert-path=/etc/ssl/certs/ca-certificates.crt --acquire-jwt=1 --dns-txt-url=somebody.net --jwt-public-key-file=webpa-rs256.pem --jwt-algo=RS256 --seshat-url=tcp://127.0.0.1:7777 --token-read-script=/usr/ccsp/parodus/parodus_token1.sh --token-acquisition-script=/usr/ccsp/parodus/parodus_token2.sh --force-ipv4 --crud-config-file=/tmp/parodus_cfg.json
|
||||
./parodus --hw-model=TGXXX --hw-serial-number=E8GBUEXXXXXXXXX --hw-manufacturer=ARRIS --hw-mac=14cfexxxxxxx --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_20170512115046sdy --boot-time=1494590301 --webpa-ping-timeout=180 --webpa-interface-used=eth0 --webpa-url=https://somebody.net:8080 --webpa-backoff-max=9 --parodus-local-url=tcp://127.0.0.1:6666 --partner-id=comcast --ssl-cert-path=/etc/ssl/certs/ca-certificates.crt --acquire-jwt=1 --dns-txt-url=somebody.net --jwt-public-key-file=webpa-rs256.pem --jwt-algo=RS256 --seshat-url=tcp://127.0.0.1:7777 --client-cert-path=/tmp/clientcert.mch --token-server-url=https://somebody.net:8080/token --force-ipv4 --crud-config-file=/tmp/parodus_cfg.json
|
||||
|
||||
|
||||
# Seshat is not enabled
|
||||
|
||||
./parodus --hw-model=TGXXX --hw-serial-number=E8GBUEXXXXXXXXX --hw-manufacturer=ARRIS --hw-mac=14cfexxxxxxx --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_20170512115046sdy --boot-time=1494590301 --webpa-ping-timeout=180 --webpa-interface-used=eth0 --webpa-url=somebody.net:8080 --webpa-backoff-max=9 --parodus-local-url=tcp://127.0.0.1:6666 --partner-id=comcast --ssl-cert-path=/etc/ssl/certs/ca-certificates.crt --acquire-jwt=1 --dns-txt-url=somebody.net --jwt-public-key-file=webpa-rs256.pem --jwt-algo=RS256 --token-read-script=/usr/ccsp/parodus/parodus_token1.sh --token-acquisition-script=/usr/ccsp/parodus/parodus_token2.sh --force-ipv4 --crud-config-file=/tmp/parodus_cfg.json
|
||||
./parodus --hw-model=TGXXX --hw-serial-number=E8GBUEXXXXXXXXX --hw-manufacturer=ARRIS --hw-mac=14cfexxxxxxx --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_20170512115046sdy --boot-time=1494590301 --webpa-ping-timeout=180 --webpa-interface-used=eth0 --webpa-url=https://somebody.net:8080 --webpa-backoff-max=9 --parodus-local-url=tcp://127.0.0.1:6666 --partner-id=comcast --ssl-cert-path=/etc/ssl/certs/ca-certificates.crt --acquire-jwt=1 --dns-txt-url=somebody.net --jwt-public-key-file=webpa-rs256.pem --jwt-algo=RS256 --client-cert-path=/tmp/clientcert.mch --token-server-url=https://somebody.net:8080/token --force-ipv4 --crud-config-file=/tmp/parodus_cfg.json
|
||||
|
||||
|
||||
# When both Seshat & FEATURE_DNS_QUERY not Enabled
|
||||
|
||||
./parodus --hw-model=TGXXX --hw-serial-number=E8GBUEXXXXXXXXX --hw-manufacturer=ARRIS --hw-mac=14cfexxxxxxx --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_20170512115046sdy --boot-time=1494590301 --webpa-ping-timeout=180 --webpa-interface-used=eth0 --webpa-url=somebody.net:8080 --webpa-backoff-max=9 --parodus-local-url=tcp://127.0.0.1:6666 --partner-id=comcast --ssl-cert-path=/etc/ssl/certs/ca-certificates.crt --token-read-script=/usr/ccsp/parodus/parodus_token1.sh --token-acquisition-script=/usr/ccsp/parodus/parodus_token2.sh --force-ipv4 --crud-config-file=/tmp/parodus_cfg.json
|
||||
./parodus --hw-model=TGXXX --hw-serial-number=E8GBUEXXXXXXXXX --hw-manufacturer=ARRIS --hw-mac=14cfexxxxxxx --hw-last-reboot-reason=unknown --fw-name=TG1682_DEV_master_20170512115046sdy --boot-time=1494590301 --webpa-ping-timeout=180 --webpa-interface-used=eth0 --webpa-url=https://somebody.net:8080 --webpa-backoff-max=9 --parodus-local-url=tcp://127.0.0.1:6666 --partner-id=comcast --ssl-cert-path=/etc/ssl/certs/ca-certificates.crt --client-cert-path=/tmp/clientcert.mch --token-server-url=https://somebody.net:8080/token --force-ipv4 --crud-config-file=/tmp/parodus_cfg.json
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
set(SOURCES main.c mutex.c networking.c nopoll_helpers.c heartBeat.c nopoll_handlers.c
|
||||
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
|
||||
crud_interface.c crud_tasks.c crud_internal.c close_retry.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 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})
|
||||
|
||||
@@ -30,6 +39,7 @@ target_link_libraries (parodus
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
-lwrp-c
|
||||
-lmsgpackc
|
||||
-lcurl
|
||||
-ltrower-base64
|
||||
-lnopoll
|
||||
-luuid
|
||||
@@ -52,5 +62,7 @@ if (ENABLE_SESHAT)
|
||||
target_link_libraries (parodus -llibseshat)
|
||||
endif (ENABLE_SESHAT)
|
||||
|
||||
|
||||
if (ENABLE_WEBCFGBIN)
|
||||
target_link_libraries (parodus -lrbus)
|
||||
endif (ENABLE_WEBCFGBIN)
|
||||
install (TARGETS parodus DESTINATION bin)
|
||||
|
||||
@@ -25,6 +25,11 @@
|
||||
#include "config.h"
|
||||
#include "connection.h"
|
||||
|
||||
bool interface_down_event = false;
|
||||
|
||||
pthread_mutex_t interface_down_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t interface_down_con=PTHREAD_COND_INITIALIZER;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -64,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)
|
||||
@@ -126,6 +131,27 @@ char* getWebpaConveyHeader()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int readFromFile(const char *file_name, char **data)
|
||||
{
|
||||
FILE *fp;
|
||||
int ch_count = 0;
|
||||
fp = fopen(file_name, "r+");
|
||||
if (fp == NULL)
|
||||
{
|
||||
ParodusError("Failed to open file %s (errno %d)\n", file_name, errno);
|
||||
return 0;
|
||||
}
|
||||
fseek(fp, 0, SEEK_END);
|
||||
ch_count = ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
*data = (char *) malloc(sizeof(char) * (ch_count + 1));
|
||||
fread(*data, 1, ch_count,fp);
|
||||
(*data)[ch_count] ='\0';
|
||||
fclose(fp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void timespec_diff(struct timespec *start, struct timespec *stop,
|
||||
struct timespec *diff)
|
||||
{
|
||||
@@ -139,3 +165,47 @@ void timespec_diff(struct timespec *start, struct timespec *stop,
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------*/
|
||||
/* For interface_down_event Flag */
|
||||
/*------------------------------------------------------------------------------*/
|
||||
|
||||
// Get value of interface_down_event
|
||||
bool get_interface_down_event()
|
||||
{
|
||||
bool tmp = false;
|
||||
pthread_mutex_lock (&interface_down_mut);
|
||||
tmp = interface_down_event;
|
||||
pthread_mutex_unlock (&interface_down_mut);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// Reset value of interface_down_event to false
|
||||
void reset_interface_down_event()
|
||||
{
|
||||
pthread_mutex_lock (&interface_down_mut);
|
||||
interface_down_event = false;
|
||||
pthread_cond_signal(&interface_down_con);
|
||||
pthread_mutex_unlock (&interface_down_mut);
|
||||
}
|
||||
|
||||
// set value of interface_down_event to true
|
||||
void set_interface_down_event()
|
||||
{
|
||||
pthread_mutex_lock (&interface_down_mut);
|
||||
interface_down_event = true;
|
||||
pthread_mutex_unlock (&interface_down_mut);
|
||||
}
|
||||
|
||||
pthread_cond_t *get_interface_down_con(void)
|
||||
{
|
||||
return &interface_down_con;
|
||||
}
|
||||
|
||||
pthread_mutex_t *get_interface_down_mut(void)
|
||||
{
|
||||
return &interface_down_mut;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -49,8 +49,10 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Macros */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#define UNUSED(x) (void )(x)
|
||||
#define NANOMSG_SOCKET_TIMEOUT_MSEC 2000
|
||||
#define NANO_SOCKET_SEND_TIMEOUT_MS 2000
|
||||
#define NANO_SOCKET_RCV_TIMEOUT_MS 500
|
||||
|
||||
#ifndef TEST
|
||||
#define FOREVER() 1
|
||||
@@ -106,6 +108,8 @@ typedef struct {
|
||||
|
||||
//--- Used in connection.c for backoff delay timer
|
||||
typedef struct {
|
||||
unsigned long start_time;
|
||||
struct timespec ts;
|
||||
int count;
|
||||
int max_count;
|
||||
int delay;
|
||||
@@ -123,7 +127,7 @@ typedef struct {
|
||||
// wait_connection_ready, and nopoll_connect
|
||||
typedef struct {
|
||||
noPollCtx *nopoll_ctx;
|
||||
server_list_t server_list;
|
||||
server_list_t *server_list;
|
||||
server_t *current_server;
|
||||
header_info_t header_info;
|
||||
char *extra_headers; // need to be freed
|
||||
@@ -133,8 +137,8 @@ typedef struct {
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
extern bool g_shutdown;
|
||||
extern ParodusMsg *ParodusMsgQ;
|
||||
int numLoops;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Function Prototypes */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -152,9 +156,42 @@ char* getWebpaConveyHeader();
|
||||
void *CRUDHandlerTask();
|
||||
void addCRUDmsgToQueue(wrp_msg_t *crudMsg);
|
||||
|
||||
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();
|
||||
void registerRbusLogger();
|
||||
#endif
|
||||
#ifdef WAN_FAILOVER_SUPPORTED
|
||||
void setWebpaInterface(char *value);
|
||||
#endif
|
||||
/*------------------------------------------------------------------------------*/
|
||||
/* For interface_down_event Flag */
|
||||
/*------------------------------------------------------------------------------*/
|
||||
|
||||
// Get value of interface_down_event
|
||||
bool get_interface_down_event();
|
||||
|
||||
// Reset value of interface_down_event to false
|
||||
void reset_interface_down_event();
|
||||
|
||||
// Set value of interface_down_event to true
|
||||
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);
|
||||
|
||||
int cloud_status_is_online (void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
328
src/auth_token.c
Normal file
328
src/auth_token.c
Normal file
@@ -0,0 +1,328 @@
|
||||
/**
|
||||
* Copyright 2015 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 auth_token.c
|
||||
*
|
||||
* @description This file is to fetch authorization token during parodus cloud connection.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include "config.h"
|
||||
#include "connection.h"
|
||||
#include "auth_token.h"
|
||||
#include "ParodusInternal.h"
|
||||
#include <cjwt/cjwt.h>
|
||||
#include <stdlib.h>
|
||||
#include <curl/curl.h>
|
||||
#include <uuid/uuid.h>
|
||||
|
||||
#define MAX_BUF_SIZE 256
|
||||
#define CURL_TIMEOUT_SEC 25L
|
||||
#define MAX_CURL_RETRY_COUNT 3
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void createCurlheader(struct curl_slist *list, struct curl_slist **header_list);
|
||||
long g_response_code;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int getGlobalResponseCode()
|
||||
{
|
||||
return g_response_code;
|
||||
}
|
||||
/*
|
||||
* @brief Initialize curl object with required options. create newToken using libcurl.
|
||||
* @param[out] newToken auth token string obtained from JWT curl response
|
||||
* @param[in] len total token size
|
||||
* @param[in] r_count Number of curl retries on ipv4 and ipv6 mode during failure
|
||||
* @return returns 0 if success, otherwise failed to fetch auth token and will be retried.
|
||||
*/
|
||||
|
||||
int requestNewAuthToken(char *newToken, size_t len, int r_count)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
CURLcode time_res;
|
||||
struct curl_slist *list = NULL;
|
||||
struct curl_slist *headers_list = NULL;
|
||||
|
||||
char webpa_interface[64]={'\0'};
|
||||
double total;
|
||||
|
||||
struct token_data data;
|
||||
data.size = 0;
|
||||
data.data = newToken;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl)
|
||||
{
|
||||
data.data[0] = '\0';
|
||||
|
||||
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);
|
||||
|
||||
parStrncpy(webpa_interface, getWebpaInterface(), sizeof(webpa_interface));
|
||||
if(webpa_interface !=NULL && strlen(webpa_interface) >0)
|
||||
{
|
||||
curl_easy_setopt(curl, CURLOPT_INTERFACE, webpa_interface);
|
||||
}
|
||||
/* set callback for writing received data */
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback_fn);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &data);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers_list);
|
||||
|
||||
/* setting curl resolve option as default mode.
|
||||
If any failure, retry with v4 first and then v6 mode. */
|
||||
|
||||
if(r_count == 1)
|
||||
{
|
||||
ParodusInfo("curl Ip resolve option set as V4 mode\n");
|
||||
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||
}
|
||||
else if(r_count == 2)
|
||||
{
|
||||
ParodusInfo("curl Ip resolve option set as V6 mode\n");
|
||||
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusInfo("curl Ip resolve option set as default mode\n");
|
||||
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_WHATEVER);
|
||||
}
|
||||
|
||||
/* set the cert for client authentication */
|
||||
curl_easy_setopt(curl, CURLOPT_SSLCERT, get_parodus_cfg()->client_cert_path);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_CAINFO, get_parodus_cfg()->cert_path);
|
||||
|
||||
/* disconnect if it is failed to validate server's cert */
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
|
||||
|
||||
/* Perform the request, res will get the return code */
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &g_response_code);
|
||||
ParodusInfo("themis curl response %d http_code %d\n", res, g_response_code);
|
||||
|
||||
time_res = curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total);
|
||||
if(time_res == 0)
|
||||
{
|
||||
ParodusInfo("curl response Time: %.1f seconds\n", total);
|
||||
}
|
||||
curl_slist_free_all(headers_list);
|
||||
if(res != 0)
|
||||
{
|
||||
ParodusError("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
|
||||
curl_easy_cleanup(curl);
|
||||
data.size = 0;
|
||||
memset (data.data, 0, len);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(getGlobalResponseCode() == 200)
|
||||
{
|
||||
ParodusInfo("cURL success\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Failed response from auth token server %s\n", data.data);
|
||||
curl_easy_cleanup(curl);
|
||||
data.size = 0;
|
||||
memset (data.data, 0, len);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("curl init failure\n");
|
||||
data.size = 0;
|
||||
memset (data.data, 0, len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief Fetches authorization token and update to parodus config.
|
||||
This will do curl retry in case of any failure till it reaches max curl retry count.
|
||||
* @param[in] cfg Global parodus config structure to update webpa_auth_token
|
||||
*/
|
||||
|
||||
void getAuthToken(ParodusCfg *cfg)
|
||||
{
|
||||
int status = -1;
|
||||
int retry_count = 0;
|
||||
|
||||
memset (cfg->webpa_auth_token, 0, sizeof(cfg->webpa_auth_token));
|
||||
if( cfg->hw_mac != NULL && strlen(cfg->hw_mac) !=0 )
|
||||
{
|
||||
if( cfg->client_cert_path !=NULL && strlen(cfg->client_cert_path) !=0 )
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
//Fetch new auth token using libcurl
|
||||
status = requestNewAuthToken(cfg->webpa_auth_token, sizeof(cfg->webpa_auth_token), retry_count);
|
||||
if(status == 0)
|
||||
{
|
||||
ParodusInfo("cfg->webpa_auth_token created successfully\n");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Failed to create new token\n");
|
||||
retry_count++;
|
||||
ParodusError("Curl execution is failed, retry attempt: %d\n", retry_count);
|
||||
}
|
||||
|
||||
if(retry_count == MAX_CURL_RETRY_COUNT)
|
||||
{
|
||||
ParodusError("Curl retry is reached to max %d attempts, proceeding without token\n", retry_count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("client_cert_path is NULL, failed to fetch auth token\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("hw_mac is NULL, failed to fetch auth token\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* @brief callback function for writing libcurl received data
|
||||
* @param[in] buffer curl delivered data which need to be saved.
|
||||
* @param[in] size size is always 1
|
||||
* @param[in] nmemb size of delivered data
|
||||
* @param[out] data curl response data saved.
|
||||
*/
|
||||
#ifndef DEVICE_CAMERA
|
||||
size_t write_callback_fn(void *buffer, size_t size, size_t nmemb, struct token_data *data)
|
||||
{
|
||||
#else
|
||||
size_t write_callback_fn(void *buffer, size_t size, size_t nmemb, void *datain)
|
||||
{
|
||||
struct token_data *data = (struct token_data*) datain;
|
||||
#endif //DEVICE_CAMERA
|
||||
ParodusCfg *cfg;
|
||||
size_t max_data_size = sizeof (cfg->webpa_auth_token);
|
||||
size_t index = data->size;
|
||||
size_t n = (size * nmemb);
|
||||
|
||||
data->size += n;
|
||||
|
||||
if (data->size >= max_data_size) {
|
||||
ParodusError("Auth token data overruns buffer\n");
|
||||
data->size = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy((data->data + index), buffer, n);
|
||||
data->data[data->size] = '\0';
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
/* @brief function to generate random uuid.
|
||||
*/
|
||||
char* generate_trans_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;
|
||||
}
|
||||
|
||||
/* @brief function to create curl header contains mac, serial number and uuid.
|
||||
* @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(struct curl_slist *list, struct curl_slist **header_list)
|
||||
{
|
||||
char buf[MAX_BUF_SIZE];
|
||||
char *uuid = 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);
|
||||
|
||||
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;
|
||||
}
|
||||
61
src/auth_token.h
Normal file
61
src/auth_token.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Copyright 2015 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 auth_token.h
|
||||
*
|
||||
* @description This file is to fetch authorization token during parodus cloud connection.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _AUTH_TOKEN_H_
|
||||
#define _AUTH_TOKEN_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Macros */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Data Structures */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
struct token_data {
|
||||
size_t size;
|
||||
char* data;
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Function Prototypes */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
int requestNewAuthToken(char *newToken, size_t len, int r_count);
|
||||
void getAuthToken(ParodusCfg *cfg);
|
||||
#ifndef DEVICE_CAMERA
|
||||
size_t write_callback_fn(void *buffer, size_t size, size_t nmemb, struct token_data *data);
|
||||
#else
|
||||
size_t write_callback_fn(void *buffer, size_t size, size_t nmemb, void *data);
|
||||
#endif
|
||||
char* generate_trans_uuid();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -30,6 +30,7 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static int numOfClients = 0;
|
||||
static reg_list_item_t * g_head = NULL;
|
||||
pthread_mutex_t client_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External functions */
|
||||
@@ -37,9 +38,16 @@ static reg_list_item_t * g_head = NULL;
|
||||
|
||||
reg_list_item_t * get_global_node(void)
|
||||
{
|
||||
pthread_mutex_lock (&client_mut);
|
||||
return g_head;
|
||||
}
|
||||
|
||||
void release_global_node (void)
|
||||
{
|
||||
pthread_mutex_unlock (&client_mut);
|
||||
}
|
||||
|
||||
|
||||
int get_numOfClients()
|
||||
{
|
||||
return numOfClients;
|
||||
@@ -52,11 +60,12 @@ int addToList( wrp_msg_t **msg)
|
||||
int rc = -1;
|
||||
int sock;
|
||||
int retStatus = -1;
|
||||
|
||||
sock = nn_socket( AF_SP, NN_PUSH );
|
||||
ParodusPrint("sock created for adding entries to list: %d\n", sock);
|
||||
if(sock >= 0)
|
||||
{
|
||||
int t = NANOMSG_SOCKET_TIMEOUT_MSEC;
|
||||
int t = NANO_SOCKET_SEND_TIMEOUT_MS;
|
||||
rc = nn_setsockopt(sock, NN_SOL_SOCKET, NN_SNDTIMEO, &t, sizeof(t));
|
||||
if(rc < 0)
|
||||
{
|
||||
@@ -67,7 +76,11 @@ int addToList( wrp_msg_t **msg)
|
||||
if(rc < 0)
|
||||
{
|
||||
ParodusError ("Unable to connect socket (errno=%d, %s)\n",errno, strerror(errno));
|
||||
nn_close (sock);
|
||||
if (nn_close (sock) < 0)
|
||||
{
|
||||
ParodusError ("nn_close socket=%d (err=%d, %s)\n",
|
||||
sock, errno, strerror(errno));
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
@@ -78,6 +91,7 @@ int addToList( wrp_msg_t **msg)
|
||||
{
|
||||
memset( new_node, 0, sizeof( reg_list_item_t ) );
|
||||
new_node->sock = sock;
|
||||
new_node->endpoint = rc;
|
||||
ParodusPrint("new_node->sock is %d\n", new_node->sock);
|
||||
|
||||
|
||||
@@ -210,11 +224,21 @@ int deleteFromList(char* service_name)
|
||||
}
|
||||
|
||||
ParodusPrint("Deleting the node\n");
|
||||
if(nn_shutdown(curr_node->sock, curr_node->endpoint) < 0)
|
||||
{
|
||||
ParodusError ("nn_shutdown socket=%d endpt=%d, err=%d\n",
|
||||
curr_node->sock, curr_node->endpoint, errno);
|
||||
}
|
||||
if (nn_close (curr_node->sock) < 0)
|
||||
{
|
||||
ParodusError ("nn_close socket=%d err=%d\n",
|
||||
curr_node->sock, errno);
|
||||
}
|
||||
free( curr_node );
|
||||
curr_node = NULL;
|
||||
ParodusInfo("Deleted successfully and returning..\n");
|
||||
numOfClients =numOfClients - 1;
|
||||
ParodusPrint("numOfClients after delte is %d\n", numOfClients);
|
||||
ParodusPrint("numOfClients after delete is %d\n", numOfClients);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -225,6 +249,22 @@ int deleteFromList(char* service_name)
|
||||
return -1;
|
||||
}
|
||||
|
||||
void deleteAllClients (void)
|
||||
{
|
||||
reg_list_item_t *next_node = NULL;
|
||||
|
||||
while (NULL != g_head)
|
||||
{
|
||||
next_node = g_head->next;
|
||||
free (g_head);
|
||||
g_head = next_node;
|
||||
}
|
||||
if (numOfClients > 0) {
|
||||
ParodusInfo ("Deleted %d clients\n", numOfClients);
|
||||
numOfClients = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*@dest : Client destination to send message
|
||||
*@Msg: Msg to send it to client (No free done here), user responsibilites to free the msg
|
||||
@@ -243,6 +283,7 @@ int sendMsgtoRegisteredClients(char *dest,const char **Msg,size_t msgSize)
|
||||
if( strcmp(dest, temp->service_name) == 0)
|
||||
{
|
||||
bytes = nn_send(temp->sock, *Msg, msgSize, 0);
|
||||
release_global_node ();
|
||||
ParodusInfo("sent downstream message to reg_client '%s'\n", temp->url);
|
||||
ParodusPrint("downstream bytes sent:%d\n", bytes);
|
||||
return 1;
|
||||
@@ -250,5 +291,27 @@ int sendMsgtoRegisteredClients(char *dest,const char **Msg,size_t msgSize)
|
||||
ParodusPrint("checking the next item in the list\n");
|
||||
temp= temp->next;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
typedef struct reg_list_item
|
||||
{
|
||||
int sock;
|
||||
int endpoint;
|
||||
char service_name[32];
|
||||
char url[100];
|
||||
struct reg_list_item *next;
|
||||
@@ -50,10 +51,12 @@ int sendAuthStatus(reg_list_item_t *new_node);
|
||||
|
||||
int deleteFromList(char* service_name);
|
||||
int get_numOfClients();
|
||||
void deleteAllClients (void);
|
||||
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
|
||||
|
||||
387
src/config.c
387
src/config.c
@@ -26,20 +26,36 @@
|
||||
#include "config.h"
|
||||
#include "ParodusInternal.h"
|
||||
#include <cjwt/cjwt.h>
|
||||
|
||||
#define MAX_BUF_SIZE 128
|
||||
#include <stdlib.h>
|
||||
#include <curl/curl.h>
|
||||
#include <uuid/uuid.h>
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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'};
|
||||
|
||||
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 +77,31 @@ 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)
|
||||
{
|
||||
char *status = NULL;
|
||||
pthread_mutex_lock(&config_mut);
|
||||
if(NULL != get_parodus_cfg()->cloud_status)
|
||||
{
|
||||
status = get_parodus_cfg()->cloud_status;
|
||||
}
|
||||
pthread_mutex_unlock(&config_mut);
|
||||
return status;
|
||||
}
|
||||
|
||||
const char *get_tok (const char *src, int delim, char *result, int resultsize)
|
||||
{
|
||||
@@ -141,39 +182,14 @@ void read_key_from_file (const char *fname, char *buf, size_t buflen)
|
||||
ParodusInfo ("%d bytes read\n", nbytes);
|
||||
}
|
||||
|
||||
void execute_token_script(char *token, char *name, size_t len, char *mac, char *serNum)
|
||||
{
|
||||
FILE* out = NULL, *file = NULL;
|
||||
char command[MAX_BUF_SIZE] = {'\0'};
|
||||
if(strlen(name)>0)
|
||||
{
|
||||
file = fopen(name, "r");
|
||||
if(file)
|
||||
{
|
||||
snprintf(command,sizeof(command),"%s %s %s",name,serNum,mac);
|
||||
out = popen(command, "r");
|
||||
if(out)
|
||||
{
|
||||
fgets(token, len, out);
|
||||
pclose(out);
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError ("File %s open error\n", name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// strips ':' characters
|
||||
// verifies that there exactly 12 characters
|
||||
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++;
|
||||
@@ -185,9 +201,48 @@ 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;
|
||||
}
|
||||
|
||||
int parse_serial_num(char *target, const char *arg)
|
||||
{
|
||||
char ch;
|
||||
if(arg != NULL)
|
||||
{
|
||||
if(strlen(arg) == 0)
|
||||
{
|
||||
ParodusError("Empty serial number, setting to default unknown\n");
|
||||
strcpy(target,"unknown");
|
||||
}
|
||||
for(int i=0; (ch = arg[i]) != '\0'; i++)
|
||||
{
|
||||
// check if character is ascii, a-z --> 97 to 122, A-Z --> 65 to 90, digits(0 to 9) --> 48 to 57
|
||||
if((ch >= 97 && ch <= 122) || (ch >= 65 && ch <= 90) || (ch >=48 && ch <= 57))
|
||||
{
|
||||
target[i] = ch;
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Invalid serial number, setting to default unknown\n");
|
||||
strcpy(target,"unknown");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("serial number argument is NULL\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int server_is_http (const char *full_url,
|
||||
const char **server_ptr)
|
||||
{
|
||||
@@ -239,8 +294,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
|
||||
@@ -375,6 +435,9 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
|
||||
{"webpa-backoff-max", required_argument, 0, 'o'},
|
||||
{"webpa-interface-used", required_argument, 0, 'i'},
|
||||
{"parodus-local-url", required_argument, 0, 'l'},
|
||||
#ifdef ENABLE_WEBCFGBIN
|
||||
{"max-queue-size", required_argument, 0, 'q'},
|
||||
#endif
|
||||
{"partner-id", required_argument, 0, 'p'},
|
||||
#ifdef ENABLE_SESHAT
|
||||
{"seshat-url", required_argument, 0, 'e'},
|
||||
@@ -386,10 +449,14 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
|
||||
{"ssl-cert-path", required_argument, 0, 'c'},
|
||||
{"force-ipv4", no_argument, 0, '4'},
|
||||
{"force-ipv6", no_argument, 0, '6'},
|
||||
{"token-read-script", required_argument, 0, 'T'},
|
||||
{"boot-time-retry-wait", required_argument, 0, 'w'},
|
||||
{"token-acquisition-script", required_argument, 0, 'J'},
|
||||
{"client-cert-path", required_argument, 0, 'P'},
|
||||
{"token-server-url", required_argument, 0, 'U'},
|
||||
{"crud-config-file", required_argument, 0, 'C'},
|
||||
{"connection-health-file", required_argument, 0, 'S'},
|
||||
{"close-reason-file", required_argument, 0, 'R'},
|
||||
{"mtls-client-key-path", required_argument, 0, 'K'},
|
||||
{"mtls-client-cert-path", required_argument, 0,'M'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
int c;
|
||||
@@ -405,6 +472,10 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
|
||||
cfg->jwt_algo = 0;
|
||||
parStrncpy (cfg->jwt_key, "", sizeof(cfg->jwt_key));
|
||||
cfg->crud_config_file = NULL;
|
||||
cfg->connection_health_file = NULL;
|
||||
cfg->close_reason_file = NULL;
|
||||
cfg->client_cert_path = NULL;
|
||||
cfg->token_server_url = NULL;
|
||||
cfg->cloud_status = NULL;
|
||||
cfg->cloud_disconnect = NULL;
|
||||
optind = 1; /* We need this if parseCommandLine is called again */
|
||||
@@ -413,8 +484,9 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
|
||||
|
||||
/* getopt_long stores the option index here. */
|
||||
int option_index = 0;
|
||||
c = getopt_long (argc, argv, "m:s:f:d:r:n:b:u:t:o:i:l:p:e:D:j:a:k:c:T:w:J:46:C",
|
||||
long_options, &option_index);
|
||||
c = getopt_long (argc, argv,
|
||||
"m:s:f:d:r:n:b:u:t:o:i:l:q:p:e:D:j:a:k:c:T:w:J:46:C:S:R:K:M",
|
||||
long_options, &option_index);
|
||||
|
||||
/* Detect the end of the options. */
|
||||
if (c == -1)
|
||||
@@ -428,8 +500,8 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
|
||||
break;
|
||||
|
||||
case 's':
|
||||
parStrncpy(cfg->hw_serial_number,optarg,sizeof(cfg->hw_serial_number));
|
||||
ParodusInfo("hw_serial_number is %s\n",cfg->hw_serial_number);
|
||||
if(parse_serial_num(cfg->hw_serial_number, optarg) == 0)
|
||||
ParodusInfo ("hw_serial_number is %s\n",cfg->hw_serial_number);
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
@@ -454,6 +526,7 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
|
||||
case 'r':
|
||||
parStrncpy(cfg->hw_last_reboot_reason, optarg,sizeof(cfg->hw_last_reboot_reason));
|
||||
ParodusInfo("hw_last_reboot_reason is %s\n",cfg->hw_last_reboot_reason);
|
||||
OnboardLog("Last reboot reason is %s\n",cfg->hw_last_reboot_reason);
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
@@ -498,6 +571,16 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
|
||||
parStrncpy(cfg->local_url, optarg,sizeof(cfg->local_url));
|
||||
ParodusInfo("parodus local_url is %s\n",cfg->local_url);
|
||||
break;
|
||||
|
||||
#ifdef ENABLE_WEBCFGBIN
|
||||
case 'q':
|
||||
cfg->max_queue_size = parse_num_arg (optarg, "max-queue-size");
|
||||
if (cfg->max_queue_size == (unsigned int) -1)
|
||||
return -1;
|
||||
ParodusInfo("max_queue_size is %d\n",cfg->max_queue_size);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case 'D':
|
||||
// like 'fabric' or 'test'
|
||||
// this parameter is used, along with the hw_mac parameter
|
||||
@@ -546,23 +629,45 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
|
||||
cfg->flags |= FLAGS_IPV6_ONLY;
|
||||
break;
|
||||
|
||||
case 'J':
|
||||
parStrncpy(cfg->token_acquisition_script, optarg,sizeof(cfg->token_acquisition_script));
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
parStrncpy(cfg->token_read_script, optarg,sizeof(cfg->token_read_script));
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
cfg->boot_retry_wait = parse_num_arg (optarg, "boot-time-retry-wait");
|
||||
ParodusInfo("boot_retry_wait is %d\n",cfg->boot_retry_wait);
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
cfg->crud_config_file = strdup(optarg);
|
||||
ParodusInfo("crud_config_file is %s\n", cfg->crud_config_file);
|
||||
break;
|
||||
case 'S':
|
||||
cfg->connection_health_file = strdup(optarg);
|
||||
ParodusInfo("connection_health_file is %s\n", cfg->connection_health_file);
|
||||
break;
|
||||
|
||||
case 'R':
|
||||
cfg->close_reason_file = strdup(optarg);
|
||||
ParodusInfo("sigterm_close_reason_file is %s\n", cfg->close_reason_file);
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
cfg->crud_config_file = strdup(optarg);
|
||||
ParodusInfo("crud_config_file is %s\n", cfg->crud_config_file);
|
||||
break;
|
||||
|
||||
case 'P':
|
||||
cfg->client_cert_path = strdup(optarg);
|
||||
ParodusInfo("client_cert_path is %s\n", cfg->client_cert_path);
|
||||
break;
|
||||
|
||||
case 'U':
|
||||
cfg->token_server_url = strdup(optarg);
|
||||
ParodusInfo("token_server_url is %s\n", cfg->token_server_url);
|
||||
break;
|
||||
|
||||
case 'K':
|
||||
cfg->mtls_client_key_path = strdup(optarg);
|
||||
ParodusInfo("mtls_client_key_path is %s\n", cfg->mtls_client_key_path);
|
||||
break;
|
||||
|
||||
case 'M':
|
||||
cfg->mtls_client_cert_path = strdup(optarg);
|
||||
ParodusInfo("mtls_client_cert_path is %s\n", cfg->mtls_client_cert_path);
|
||||
break;
|
||||
|
||||
case '?':
|
||||
/* getopt_long already printed an error message. */
|
||||
@@ -606,61 +711,51 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* call parodus create/acquisition script to create new auth token, if success then calls
|
||||
* execute_token_script func with args as parodus read script.
|
||||
*/
|
||||
|
||||
void createNewAuthToken(char *newToken, size_t len)
|
||||
void free_cfg(ParodusCfg *cfg)
|
||||
{
|
||||
//Call create script
|
||||
char output[12] = {'\0'};
|
||||
execute_token_script(output,get_parodus_cfg()->token_acquisition_script,sizeof(output),get_parodus_cfg()->hw_mac,get_parodus_cfg()->hw_serial_number);
|
||||
if (strlen(output)>0 && strcmp(output,"SUCCESS")==0)
|
||||
{
|
||||
//Call read script
|
||||
execute_token_script(newToken,get_parodus_cfg()->token_read_script,len,get_parodus_cfg()->hw_mac,get_parodus_cfg()->hw_serial_number);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Failed to create new token\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetches authorization token from the output of read script. If read script returns "ERROR"
|
||||
* it will call createNewAuthToken to create and read new token
|
||||
*/
|
||||
|
||||
void getAuthToken(ParodusCfg *cfg)
|
||||
{
|
||||
//local var to update cfg->webpa_auth_token only in success case
|
||||
char output[4069] = {'\0'} ;
|
||||
|
||||
if( strlen(cfg->token_read_script) !=0 && strlen(cfg->token_acquisition_script) !=0)
|
||||
{
|
||||
execute_token_script(output,cfg->token_read_script,sizeof(output),cfg->hw_mac,cfg->hw_serial_number);
|
||||
|
||||
if ((strlen(output) == 0))
|
||||
{
|
||||
ParodusError("Unable to get auth token\n");
|
||||
}
|
||||
else if(strcmp(output,"ERROR")==0)
|
||||
{
|
||||
ParodusInfo("Failed to read token from %s. Proceeding to create new token.\n",cfg->token_read_script);
|
||||
//Call create/acquisition script
|
||||
createNewAuthToken(cfg->webpa_auth_token, sizeof(cfg->webpa_auth_token));
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusInfo("update cfg->webpa_auth_token in success case\n");
|
||||
parStrncpy(cfg->webpa_auth_token, output, sizeof(cfg->webpa_auth_token));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusInfo("Both read and write file are NULL \n");
|
||||
}
|
||||
if(cfg != NULL)
|
||||
{
|
||||
if (cfg->mtls_client_cert_path != NULL )
|
||||
{
|
||||
free(cfg->mtls_client_cert_path);
|
||||
cfg->mtls_client_cert_path = NULL;
|
||||
}
|
||||
if(cfg->connection_health_file != NULL)
|
||||
{
|
||||
free(cfg->connection_health_file);
|
||||
cfg->connection_health_file = NULL;
|
||||
}
|
||||
if(cfg->token_server_url != NULL)
|
||||
{
|
||||
free(cfg->token_server_url );
|
||||
cfg->token_server_url = NULL;
|
||||
}
|
||||
if(cfg->mtls_client_key_path != NULL)
|
||||
{
|
||||
free(cfg->mtls_client_key_path);
|
||||
cfg->mtls_client_key_path = NULL;
|
||||
}
|
||||
if(cfg->client_cert_path != NULL)
|
||||
{
|
||||
free(cfg->client_cert_path);
|
||||
cfg->client_cert_path = NULL;
|
||||
}
|
||||
if(cfg->crud_config_file != NULL)
|
||||
{
|
||||
free(cfg->crud_config_file);
|
||||
cfg->crud_config_file = NULL;
|
||||
}
|
||||
if(cfg->close_reason_file != NULL)
|
||||
{
|
||||
free(cfg->close_reason_file);
|
||||
cfg->close_reason_file = NULL;
|
||||
}
|
||||
if(cfg->cloud_disconnect != NULL)
|
||||
{
|
||||
free(cfg->cloud_disconnect);
|
||||
cfg->cloud_disconnect = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setDefaultValuesToCfg(ParodusCfg *cfg)
|
||||
@@ -694,6 +789,10 @@ void setDefaultValuesToCfg(ParodusCfg *cfg)
|
||||
parStrncpy(cfg->webpa_uuid, "1234567-345456546",sizeof(cfg->webpa_uuid));
|
||||
ParodusPrint("cfg->webpa_uuid is :%s\n", cfg->webpa_uuid);
|
||||
cfg->crud_config_file = NULL;
|
||||
cfg->connection_health_file = NULL;
|
||||
cfg->close_reason_file = NULL;
|
||||
cfg->client_cert_path = NULL;
|
||||
cfg->token_server_url = NULL;
|
||||
|
||||
cfg->cloud_status = CLOUD_STATUS_OFFLINE;
|
||||
ParodusInfo("Default cloud_status is %s\n", cfg->cloud_status);
|
||||
@@ -765,7 +864,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
|
||||
{
|
||||
@@ -833,25 +932,9 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg)
|
||||
parStrncpy(cfg->cert_path, "\0", sizeof(cfg->cert_path));
|
||||
ParodusPrint("cert_path is NULL. set to empty\n");
|
||||
}
|
||||
|
||||
if(strlen(config->token_acquisition_script )!=0)
|
||||
{
|
||||
parStrncpy(cfg->token_acquisition_script, config->token_acquisition_script,sizeof(cfg->token_acquisition_script));
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("token_acquisition_script is NULL. read from tmp file\n");
|
||||
}
|
||||
|
||||
if(strlen(config->token_read_script )!=0)
|
||||
{
|
||||
parStrncpy(cfg->token_read_script, config->token_read_script,sizeof(cfg->token_read_script));
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("token_read_script is NULL. read from tmp file\n");
|
||||
}
|
||||
|
||||
#ifdef ENABLE_WEBCFGBIN
|
||||
cfg->max_queue_size = config->max_queue_size;
|
||||
#endif
|
||||
cfg->boot_time = config->boot_time;
|
||||
cfg->webpa_ping_timeout = config->webpa_ping_timeout;
|
||||
cfg->webpa_backoff_max = config->webpa_backoff_max;
|
||||
@@ -861,6 +944,24 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg)
|
||||
parStrncpy(cfg->webpa_uuid, "1234567-345456546",sizeof(cfg->webpa_uuid));
|
||||
ParodusPrint("cfg->webpa_uuid is :%s\n", cfg->webpa_uuid);
|
||||
|
||||
if(config->connection_health_file != NULL)
|
||||
{
|
||||
cfg->connection_health_file = strdup(config->connection_health_file);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("connection_health_file is NULL. set to empty\n");
|
||||
}
|
||||
|
||||
if(config->close_reason_file != NULL)
|
||||
{
|
||||
cfg->close_reason_file = strdup(config->close_reason_file);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("close_reason_file is NULL. set to empty\n");
|
||||
}
|
||||
|
||||
if(config->crud_config_file != NULL)
|
||||
{
|
||||
cfg->crud_config_file = strdup(config->crud_config_file);
|
||||
@@ -869,6 +970,46 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg)
|
||||
{
|
||||
ParodusPrint("crud_config_file is NULL. set to empty\n");
|
||||
}
|
||||
|
||||
if(config->client_cert_path != NULL)
|
||||
{
|
||||
cfg->client_cert_path = strdup(config->client_cert_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("client_cert_path is NULL. set to empty\n");
|
||||
}
|
||||
|
||||
if(config->token_server_url != NULL)
|
||||
{
|
||||
cfg->token_server_url = strdup(config->token_server_url);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("token_server_url is NULL. set to empty\n");
|
||||
}
|
||||
}
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
||||
23
src/config.h
23
src/config.h
@@ -24,6 +24,7 @@
|
||||
#ifndef _CONFIG_H_
|
||||
#define _CONFIG_H_
|
||||
|
||||
#include <pthread.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -42,7 +43,7 @@ extern "C" {
|
||||
#define BOOT_TIME "boot-time"
|
||||
#define LAST_RECONNECT_REASON "webpa-last-reconnect-reason"
|
||||
#define WEBPA_PROTOCOL "webpa-protocol"
|
||||
#define WEBPA_INTERFACE "webpa-inteface-used"
|
||||
#define WEBPA_INTERFACE "webpa-interface-used"
|
||||
#define WEBPA_UUID "webpa-uuid"
|
||||
#define WEBPA_URL "webpa-url"
|
||||
#define WEBPA_PING_TIMEOUT "webpa-ping-timeout"
|
||||
@@ -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;
|
||||
@@ -87,6 +88,9 @@ typedef struct
|
||||
char webpa_uuid[64];
|
||||
unsigned int flags;
|
||||
char local_url[124];
|
||||
#ifdef ENABLE_WEBCFGBIN
|
||||
unsigned int max_queue_size;
|
||||
#endif
|
||||
char partner_id[64];
|
||||
#ifdef ENABLE_SESHAT
|
||||
char seshat_url[128];
|
||||
@@ -99,6 +103,12 @@ typedef struct
|
||||
char webpa_auth_token[4096];
|
||||
char token_acquisition_script[64];
|
||||
char token_read_script[64];
|
||||
char *client_cert_path;
|
||||
char *token_server_url;
|
||||
char *connection_health_file;
|
||||
char *close_reason_file;
|
||||
char *mtls_client_key_path;
|
||||
char *mtls_client_cert_path;
|
||||
char *crud_config_file;
|
||||
char *cloud_status;
|
||||
char *cloud_disconnect;
|
||||
@@ -114,7 +124,6 @@ typedef struct
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg);
|
||||
void createNewAuthToken(char *newToken, size_t len);
|
||||
|
||||
/**
|
||||
* parse command line arguments and create config structure
|
||||
@@ -126,15 +135,18 @@ void createNewAuthToken(char *newToken, size_t len);
|
||||
* or -1 if error
|
||||
*/
|
||||
int parseCommandLine(int argc,char **argv,ParodusCfg * cfg);
|
||||
|
||||
void free_cfg(ParodusCfg *cfg);
|
||||
void setDefaultValuesToCfg(ParodusCfg *cfg);
|
||||
void getAuthToken(ParodusCfg *cfg);
|
||||
// Accessor for the global config structure.
|
||||
ParodusCfg *get_parodus_cfg(void);
|
||||
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);
|
||||
int get_parodus_init();
|
||||
/**
|
||||
* parse a webpa url. Extract the server address, the port
|
||||
* and return whether it's secure or not
|
||||
@@ -149,7 +161,6 @@ void reset_cloud_disconnect_reason(ParodusCfg *cfg);
|
||||
*/
|
||||
int parse_webpa_url (const char *full_url,
|
||||
char **server_addr, unsigned int *port);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -33,9 +33,11 @@
|
||||
#include "spin_thread.h"
|
||||
#include "service_alive.h"
|
||||
#include "seshat_interface.h"
|
||||
#include "event_handler.h"
|
||||
#include "crud_interface.h"
|
||||
#include "heartBeat.h"
|
||||
#include "close_retry.h"
|
||||
#include <curl/curl.h>
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
#include <ucresolv_log.h>
|
||||
#endif
|
||||
@@ -52,12 +54,18 @@
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
bool g_shutdown = false;
|
||||
pthread_t upstream_tid;
|
||||
pthread_t upstream_msg_tid;
|
||||
pthread_t downstream_tid;
|
||||
pthread_t svc_alive_tid;
|
||||
pthread_t crud_tid;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Function Prototypes */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void timespec_diff(struct timespec *start, struct timespec *stop,
|
||||
struct timespec *result);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -66,9 +74,13 @@ void createSocketConnection(void (* initKeypress)())
|
||||
{
|
||||
//ParodusCfg *tmpCfg = (ParodusCfg*)config_in;
|
||||
noPollCtx *ctx;
|
||||
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;
|
||||
|
||||
//loadParodusCfg(tmpCfg,get_parodus_cfg());
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
@@ -86,20 +98,27 @@ void createSocketConnection(void (* initKeypress)())
|
||||
nopoll_log_set_handler (ctx, __report_log, NULL);
|
||||
#endif
|
||||
|
||||
if(!createNopollConnection(ctx))
|
||||
EventHandler();
|
||||
#ifdef WAN_FAILOVER_SUPPORTED
|
||||
subscribeCurrentActiveInterfaceEvent();
|
||||
#endif
|
||||
set_server_list_null (&server_list);
|
||||
create_conn_rtn = createNopollConnection(ctx, &server_list);
|
||||
if(!create_conn_rtn)
|
||||
{
|
||||
ParodusError("Unrecovered error, terminating the process\n");
|
||||
OnboardLog("Unrecovered error, terminating the process\n");
|
||||
abort();
|
||||
}
|
||||
packMetaData();
|
||||
|
||||
UpStreamMsgQ = NULL;
|
||||
StartThread(handle_upstream);
|
||||
StartThread(processUpstreamMessage);
|
||||
StartThread(handle_upstream, &upstream_tid);
|
||||
StartThread(processUpstreamMessage, &upstream_msg_tid);
|
||||
ParodusMsgQ = NULL;
|
||||
StartThread(messageHandlerTask);
|
||||
StartThread(serviceAliveTask);
|
||||
StartThread(CRUDHandlerTask);
|
||||
StartThread(messageHandlerTask, &downstream_tid);
|
||||
StartThread(serviceAliveTask, &svc_alive_tid);
|
||||
StartThread(CRUDHandlerTask, &crud_tid);
|
||||
|
||||
if (NULL != initKeypress)
|
||||
{
|
||||
@@ -108,19 +127,24 @@ void createSocketConnection(void (* initKeypress)())
|
||||
|
||||
seshat_registered = __registerWithSeshat();
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &start_svc_alive_timer);
|
||||
|
||||
do
|
||||
{
|
||||
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)
|
||||
{
|
||||
@@ -130,8 +154,14 @@ void createSocketConnection(void (* initKeypress)())
|
||||
{
|
||||
ParodusError("ping wait time > %d . Terminating the connection with WebPA server and retrying\n", webpa_ping_timeout_ms / 1000);
|
||||
ParodusInfo("Reconnect detected, setting Ping_Miss reason for Reconnect\n");
|
||||
OnboardLog("Reconnect detected, setting Ping_Miss reason for Reconnect\n");
|
||||
set_global_reconnect_reason("Ping_Miss");
|
||||
set_global_reconnect_status(true);
|
||||
// Invoke the ping status change event callback as "missed" ping
|
||||
if(NULL != on_ping_status_change)
|
||||
{
|
||||
on_ping_status_change("missed");
|
||||
}
|
||||
set_close_retry();
|
||||
}
|
||||
else
|
||||
@@ -147,36 +177,69 @@ void createSocketConnection(void (* initKeypress)())
|
||||
if( false == seshat_registered ) {
|
||||
seshat_registered = __registerWithSeshat();
|
||||
}
|
||||
|
||||
if (get_interface_down_event ())
|
||||
if (0 != wait_while_interface_down ())
|
||||
break;
|
||||
|
||||
if(get_close_retry())
|
||||
{
|
||||
ParodusInfo("close_retry is %d, hence closing the connection and retrying\n", get_close_retry());
|
||||
close_and_unref_connection(get_global_conn());
|
||||
close_and_unref_connection(get_global_conn(), false);
|
||||
set_global_conn(NULL);
|
||||
|
||||
get_parodus_cfg()->cloud_status = CLOUD_STATUS_OFFLINE;
|
||||
ParodusInfo("cloud_status set as %s after connection close\n", get_parodus_cfg()->cloud_status);
|
||||
if(get_parodus_cfg()->cloud_disconnect !=NULL)
|
||||
{
|
||||
ParodusPrint("get_parodus_cfg()->cloud_disconnect is %s\n", get_parodus_cfg()->cloud_disconnect);
|
||||
set_cloud_disconnect_time(CLOUD_RECONNECT_TIME);
|
||||
ParodusInfo("Waiting for %d minutes for reconnecting .. \n", get_cloud_disconnect_time());
|
||||
ParodusPrint("get_parodus_cfg()->cloud_disconnect is %s\n", get_parodus_cfg()->cloud_disconnect);
|
||||
set_cloud_disconnect_time(CLOUD_RECONNECT_TIME);
|
||||
ParodusInfo("Waiting for %d minutes for reconnecting .. \n", get_cloud_disconnect_time());
|
||||
|
||||
sleep( get_cloud_disconnect_time() * 60 );
|
||||
ParodusInfo("cloud-disconnect reason reset after %d minutes\n", get_cloud_disconnect_time());
|
||||
free(get_parodus_cfg()->cloud_disconnect);
|
||||
reset_cloud_disconnect_reason(get_parodus_cfg());
|
||||
sleep (get_cloud_disconnect_time() * 60);
|
||||
ParodusInfo("cloud-disconnect reason reset after %d minutes\n", get_cloud_disconnect_time());
|
||||
free(get_parodus_cfg()->cloud_disconnect);
|
||||
reset_cloud_disconnect_reason(get_parodus_cfg());
|
||||
}
|
||||
createNopollConnection(ctx);
|
||||
createNopollConnection(ctx, &server_list);
|
||||
}
|
||||
} while(!get_close_retry() && !g_shutdown);
|
||||
//process exit only when g_shutdown is true.
|
||||
} while(FOREVER() && !g_shutdown);
|
||||
|
||||
close_and_unref_connection(get_global_conn());
|
||||
pthread_mutex_lock (get_global_svc_mut());
|
||||
pthread_cond_signal (get_global_svc_con());
|
||||
pthread_mutex_unlock (get_global_svc_mut());
|
||||
pthread_mutex_lock (get_global_crud_mut());
|
||||
pthread_cond_signal (get_global_crud_con());
|
||||
pthread_mutex_unlock (get_global_crud_mut());
|
||||
pthread_mutex_lock (&g_mutex);
|
||||
pthread_cond_signal (&g_cond);
|
||||
pthread_mutex_unlock (&g_mutex);
|
||||
pthread_mutex_lock (get_global_nano_mut ());
|
||||
pthread_cond_signal (get_global_nano_con());
|
||||
pthread_mutex_unlock (get_global_nano_mut());
|
||||
|
||||
ParodusInfo ("joining threads\n");
|
||||
JoinThread (svc_alive_tid);
|
||||
JoinThread (upstream_tid);
|
||||
JoinThread (downstream_tid);
|
||||
JoinThread (upstream_msg_tid);
|
||||
JoinThread (crud_tid);
|
||||
|
||||
deleteAllClients ();
|
||||
|
||||
ParodusInfo ("reconnect reason at close %s\n", get_global_reconnect_reason());
|
||||
close_and_unref_connection(get_global_conn(), true);
|
||||
nopoll_ctx_unref(ctx);
|
||||
nopoll_cleanup_library();
|
||||
curl_global_cleanup();
|
||||
clear_metadata();
|
||||
rdk_logger_deinit();
|
||||
free_server_list(&server_list);
|
||||
}
|
||||
|
||||
void shutdownSocketConnection(void) {
|
||||
void shutdownSocketConnection(char *reason) {
|
||||
set_global_shutdown_reason (reason);
|
||||
g_shutdown = true;
|
||||
reset_interface_down_event ();
|
||||
terminate_backoff_delay ();
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ extern UpStreamMsg *UpStreamMsgQ;
|
||||
* and creates the intial connection and manages the connection wait, close mechanisms.
|
||||
*/
|
||||
void createSocketConnection(void (* initKeypress)());
|
||||
void shutdownSocketConnection(void);
|
||||
void shutdownSocketConnection(char *reason);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
474
src/connection.c
474
src/connection.c
@@ -25,6 +25,7 @@
|
||||
#include "time.h"
|
||||
#include "token.h"
|
||||
#include "config.h"
|
||||
#include "auth_token.h"
|
||||
#include "nopoll_helpers.h"
|
||||
#include "mutex.h"
|
||||
#include "spin_thread.h"
|
||||
@@ -37,15 +38,43 @@
|
||||
|
||||
#define HTTP_CUSTOM_HEADER_COUNT 5
|
||||
#define INITIAL_CJWT_RETRY -2
|
||||
#define UPDATE_HEALTH_FILE_INTERVAL_SECS 240
|
||||
|
||||
/* Close codes defined in RFC 6455, section 11.7. */
|
||||
enum {
|
||||
CloseNormalClosure = 1000,
|
||||
CloseGoingAway = 1001,
|
||||
CloseProtocolError = 1002,
|
||||
CloseUnsupportedData = 1003,
|
||||
CloseNoStatus = 1005,
|
||||
CloseAbnormalClosure = 1006,
|
||||
CloseInvalidFramePayloadData = 1007,
|
||||
ClosePolicyViolation = 1008,
|
||||
CloseMessageTooBig = 1009,
|
||||
CloseMandatoryExtension = 1010,
|
||||
CloseInternalServerErr = 1011,
|
||||
CloseServiceRestart = 1012,
|
||||
CloseTryAgainLater = 1013,
|
||||
CloseTLSHandshake = 1015
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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;
|
||||
|
||||
static char *shutdown_reason = SHUTDOWN_REASON_PARODUS_STOP; /* goes in the close message */
|
||||
static char *reconnect_reason = "webpa_process_starts";
|
||||
static int cloud_disconnect_max_time = 5;
|
||||
static noPollConn *g_conn = NULL;
|
||||
static bool LastReasonStatus = false;
|
||||
static int init = 1;
|
||||
static noPollConnOpts * createConnOpts (char * extra_headers, bool secure);
|
||||
static char* build_extra_headers( const char *auth, const char *device_id,
|
||||
const char *user_agent, const char *convey );
|
||||
@@ -63,6 +92,16 @@ void set_global_conn(noPollConn *conn)
|
||||
g_conn = conn;
|
||||
}
|
||||
|
||||
char *get_global_shutdown_reason()
|
||||
{
|
||||
return shutdown_reason;
|
||||
}
|
||||
|
||||
void set_global_shutdown_reason(char *reason)
|
||||
{
|
||||
shutdown_reason = reason;
|
||||
}
|
||||
|
||||
char *get_global_reconnect_reason()
|
||||
{
|
||||
return reconnect_reason;
|
||||
@@ -93,7 +132,10 @@ void set_cloud_disconnect_time(int disconnTime)
|
||||
cloud_disconnect_max_time = disconnTime;
|
||||
}
|
||||
|
||||
|
||||
int get_parodus_init()
|
||||
{
|
||||
return init;
|
||||
}
|
||||
//--------------------------------------------------------------------
|
||||
// createNopollConnection_logic:
|
||||
|
||||
@@ -197,23 +239,122 @@ void init_backoff_timer (backoff_timer_t *timer, int max_count)
|
||||
timer->count = 1;
|
||||
timer->max_count = max_count;
|
||||
timer->delay = 1;
|
||||
clock_gettime (CLOCK_MONOTONIC, &timer->ts);
|
||||
timer->start_time = time(NULL);
|
||||
}
|
||||
|
||||
int update_backoff_delay (backoff_timer_t *timer)
|
||||
unsigned update_backoff_delay (backoff_timer_t *timer)
|
||||
{
|
||||
if (timer->count < timer->max_count) {
|
||||
timer->count += 1;
|
||||
timer->delay = timer->delay + timer->delay + 1;
|
||||
// 3,7,15,31 ..
|
||||
}
|
||||
return timer->delay;
|
||||
return (unsigned) timer->delay;
|
||||
}
|
||||
|
||||
static void backoff_delay (backoff_timer_t *timer)
|
||||
void add_timespec (struct timespec *t1, struct timespec *t2)
|
||||
{
|
||||
update_backoff_delay (timer);
|
||||
ParodusInfo("Waiting with backoffRetryTime %d seconds\n", timer->delay);
|
||||
sleep (timer->delay);
|
||||
t2->tv_sec += t1->tv_sec;
|
||||
t2->tv_nsec += t1->tv_nsec;
|
||||
if (t2->tv_nsec >= 1000000000) {
|
||||
t2->tv_sec += 1;
|
||||
t2->tv_nsec -= 1000000000;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned calc_random_secs (int random_num, unsigned max_secs)
|
||||
{
|
||||
unsigned delay_secs = (unsigned) random_num & max_secs;
|
||||
if (delay_secs < 3)
|
||||
return delay_secs + 3;
|
||||
else
|
||||
return delay_secs;
|
||||
}
|
||||
|
||||
unsigned calc_random_nsecs (int random_num)
|
||||
{
|
||||
/* random _num is in range 0..2147483648 */
|
||||
unsigned n = (unsigned) random_num >> 1;
|
||||
/* n is in range 0..1073741824 */
|
||||
if (n < 1000000000)
|
||||
return n;
|
||||
return n - 1000000000;
|
||||
}
|
||||
|
||||
void calc_random_expiration (int random_num1, int random_num2, backoff_timer_t *timer, struct timespec *ts)
|
||||
{
|
||||
unsigned max_secs = update_backoff_delay (timer); // 3,7,15,31
|
||||
struct timespec ts_delay = {3, 0};
|
||||
|
||||
if (max_secs > 3) {
|
||||
ts_delay.tv_sec = calc_random_secs (random_num1, max_secs);
|
||||
ts_delay.tv_nsec = calc_random_nsecs (random_num2);
|
||||
}
|
||||
ParodusInfo("Waiting max delay %u backoffRetryTime %ld secs %ld usecs\n",
|
||||
max_secs, ts_delay.tv_sec, ts_delay.tv_nsec/1000);
|
||||
|
||||
/* Add delay to expire time */
|
||||
add_timespec (&ts_delay, ts);
|
||||
}
|
||||
|
||||
void terminate_backoff_delay (void)
|
||||
{
|
||||
pthread_mutex_lock (&backoff_delay_mut);
|
||||
pthread_cond_signal(&backoff_delay_con);
|
||||
pthread_mutex_unlock (&backoff_delay_mut);
|
||||
}
|
||||
|
||||
#define BACKOFF_ERR -1
|
||||
#define BACKOFF_SHUTDOWN 1
|
||||
#define BACKOFF_DELAY_TAKEN 0
|
||||
|
||||
void start_conn_in_progress (unsigned long start_time);
|
||||
|
||||
/* backoff_delay
|
||||
*
|
||||
* delays for the number of seconds specified in parameter timer
|
||||
* g_shutdown can break out of the delay.
|
||||
*
|
||||
* returns -1 pthread_cond_timedwait error
|
||||
* 1 shutdown
|
||||
* 0 delay taken
|
||||
*/
|
||||
static int backoff_delay (backoff_timer_t *timer)
|
||||
{
|
||||
struct timespec ts;
|
||||
int rtn;
|
||||
|
||||
pthread_condattr_t backoff_delay_cond_attr;
|
||||
|
||||
pthread_condattr_init (&backoff_delay_cond_attr);
|
||||
pthread_condattr_setclock (&backoff_delay_cond_attr, CLOCK_MONOTONIC);
|
||||
pthread_cond_init (&backoff_delay_con, &backoff_delay_cond_attr);
|
||||
|
||||
// periodically update the health file.
|
||||
clock_gettime (CLOCK_MONOTONIC, &ts);
|
||||
if ((ts.tv_sec - timer->ts.tv_sec) >= UPDATE_HEALTH_FILE_INTERVAL_SECS) {
|
||||
start_conn_in_progress (timer->start_time);
|
||||
timer->ts.tv_sec += UPDATE_HEALTH_FILE_INTERVAL_SECS;
|
||||
}
|
||||
|
||||
calc_random_expiration (random(), random(), timer, &ts);
|
||||
|
||||
pthread_mutex_lock (&backoff_delay_mut);
|
||||
// The condition variable will only be set if we shut down.
|
||||
rtn = pthread_cond_timedwait (&backoff_delay_con, &backoff_delay_mut, &ts);
|
||||
pthread_mutex_unlock (&backoff_delay_mut);
|
||||
|
||||
pthread_condattr_destroy(&backoff_delay_cond_attr);
|
||||
|
||||
if (g_shutdown)
|
||||
return BACKOFF_SHUTDOWN;
|
||||
if ((rtn != 0) && (rtn != ETIMEDOUT)) {
|
||||
ParodusError ("pthread_cond_timedwait error (%d) in backoff_delay.\n", rtn);
|
||||
return BACKOFF_ERR;
|
||||
}
|
||||
|
||||
return BACKOFF_DELAY_TAKEN;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
@@ -291,18 +432,7 @@ char *build_extra_hdrs (header_info_t *header_info)
|
||||
//--------------------------------------------------------------------
|
||||
void set_current_server (create_connection_ctx_t *ctx)
|
||||
{
|
||||
ctx->current_server = get_current_server (&ctx->server_list);
|
||||
}
|
||||
|
||||
void set_extra_headers (create_connection_ctx_t *ctx, int reauthorize)
|
||||
{
|
||||
if (reauthorize && (strlen(get_parodus_cfg()->token_acquisition_script) >0))
|
||||
{
|
||||
createNewAuthToken(get_parodus_cfg()->webpa_auth_token,
|
||||
sizeof(get_parodus_cfg()->webpa_auth_token));
|
||||
}
|
||||
|
||||
ctx->extra_headers = build_extra_hdrs (&ctx->header_info);
|
||||
ctx->current_server = get_current_server (ctx->server_list);
|
||||
}
|
||||
|
||||
void free_extra_headers (create_connection_ctx_t *ctx)
|
||||
@@ -310,11 +440,26 @@ void free_extra_headers (create_connection_ctx_t *ctx)
|
||||
FREE_PTR_VAR (ctx->extra_headers)
|
||||
}
|
||||
|
||||
void set_extra_headers (create_connection_ctx_t *ctx)
|
||||
{
|
||||
ParodusCfg * cfg = get_parodus_cfg();
|
||||
|
||||
free_extra_headers (ctx);
|
||||
if ((strlen(cfg->webpa_auth_token) == 0) &&
|
||||
(cfg->client_cert_path != NULL) && (strlen(cfg->client_cert_path) > 0))
|
||||
{
|
||||
getAuthToken(cfg);
|
||||
}
|
||||
|
||||
ctx->extra_headers = build_extra_hdrs (&ctx->header_info);
|
||||
}
|
||||
|
||||
void free_connection_ctx (create_connection_ctx_t *ctx)
|
||||
{
|
||||
free_extra_headers (ctx);
|
||||
free_header_info (&ctx->header_info);
|
||||
free_server_list (&ctx->server_list);
|
||||
if (NULL != ctx->server_list)
|
||||
free_server_list (ctx->server_list);
|
||||
}
|
||||
|
||||
|
||||
@@ -331,8 +476,10 @@ int find_servers (server_list_t *server_list)
|
||||
|
||||
free_server_list (server_list);
|
||||
// parse default server URL
|
||||
if (parse_server_url (get_parodus_cfg()->webpa_url, default_server) < 0)
|
||||
return FIND_INVALID_DEFAULT; // must have valid default url
|
||||
if (parse_server_url (get_parodus_cfg()->webpa_url, default_server) < 0) {
|
||||
ParodusError ("Invalid Default URL\n");
|
||||
return FIND_INVALID_DEFAULT;
|
||||
}
|
||||
ParodusInfo("default server_Address %s\n", default_server->server_addr);
|
||||
ParodusInfo("default port %u\n", default_server->port);
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
@@ -350,7 +497,6 @@ int find_servers (server_list_t *server_list)
|
||||
return FIND_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// connect to current server
|
||||
int nopoll_connect (create_connection_ctx_t *ctx, int is_ipv6)
|
||||
@@ -384,10 +530,12 @@ int nopoll_connect (create_connection_ctx_t *ctx, int is_ipv6)
|
||||
NULL, default_url,NULL,NULL);
|
||||
}
|
||||
}
|
||||
if (NULL == connection) {
|
||||
if ((NULL == connection) && (!is_ipv6)) {
|
||||
if((checkHostIp(server->server_addr) == -2)) {
|
||||
if (check_timer_expired (&ctx->connect_timer, 15*60*1000)) {
|
||||
if (check_timer_expired (&ctx->connect_timer, 15*60*1000) && !get_interface_down_event()) {
|
||||
ParodusError("WebPA unable to connect due to DNS resolving to 10.0.0.1 for over 15 minutes; crashing service.\n");
|
||||
OnboardLog("WebPA unable to connect due to DNS resolving to 10.0.0.1 for over 15 minutes; crashing service.\n");
|
||||
OnboardLog("Reconnect detected, setting Dns_Res_webpa_reconnect reason for Reconnect\n");
|
||||
set_global_reconnect_reason("Dns_Res_webpa_reconnect");
|
||||
set_global_reconnect_status(true);
|
||||
|
||||
@@ -403,26 +551,31 @@ int nopoll_connect (create_connection_ctx_t *ctx, int is_ipv6)
|
||||
//--------------------------------------------------------------------
|
||||
// Return codes for wait_connection_ready
|
||||
#define WAIT_SUCCESS 0
|
||||
#define WAIT_ACTION_RETRY 1 // if wait_status is 307, 302, 303 or 403
|
||||
#define WAIT_ACTION_RETRY 1 // if wait_status is 307, 302, 303, or 403
|
||||
#define WAIT_FAIL 2
|
||||
|
||||
#define FREE_NON_NULL_PTR(ptr) if (NULL != ptr) free(ptr)
|
||||
|
||||
int wait_connection_ready (create_connection_ctx_t *ctx)
|
||||
{
|
||||
int wait_status;
|
||||
int wait_status = 0;
|
||||
char *redirectURL = NULL;
|
||||
|
||||
if(nopoll_conn_wait_for_status_until_connection_ready(get_global_conn(), 10,
|
||||
&wait_status, &redirectURL))
|
||||
{
|
||||
FREE_NON_NULL_PTR (redirectURL);
|
||||
return WAIT_SUCCESS;
|
||||
}
|
||||
if(wait_status == 307 || wait_status == 302 || wait_status == 303) // only when there is a http redirect
|
||||
{
|
||||
char *redirect_ptr = redirectURL;
|
||||
ParodusError("Received temporary redirection response message %s\n", redirectURL);
|
||||
ParodusInfo("Received temporary redirection response message %s\n", redirectURL);
|
||||
// Extract server Address and port from the redirectURL
|
||||
if (strncmp (redirect_ptr, "Redirect:", 9) == 0)
|
||||
redirect_ptr += 9;
|
||||
free_server (&ctx->server_list.redirect);
|
||||
if (parse_server_url (redirect_ptr, &ctx->server_list.redirect) < 0) {
|
||||
free_server (&ctx->server_list->redirect);
|
||||
if (parse_server_url (redirect_ptr, &ctx->server_list->redirect) < 0) {
|
||||
ParodusError ("Redirect url error %s\n", redirectURL);
|
||||
free (redirectURL);
|
||||
return WAIT_FAIL;
|
||||
@@ -431,15 +584,15 @@ int wait_connection_ready (create_connection_ctx_t *ctx)
|
||||
set_current_server (ctx); // set current server to redirect server
|
||||
return WAIT_ACTION_RETRY;
|
||||
}
|
||||
if (NULL != redirectURL) {
|
||||
free (redirectURL);
|
||||
}
|
||||
FREE_NON_NULL_PTR (redirectURL);
|
||||
if(wait_status == 403)
|
||||
{
|
||||
ParodusError("Received Unauthorized response with status: %d\n", wait_status);
|
||||
free_extra_headers (ctx);
|
||||
set_extra_headers (ctx, true);
|
||||
return WAIT_ACTION_RETRY;
|
||||
ParodusCfg *cfg = get_parodus_cfg();
|
||||
/* clear auth token in cfg so that we will refetch auth token */
|
||||
memset (cfg->webpa_auth_token, 0, sizeof(cfg->webpa_auth_token));
|
||||
ParodusError("Received Unauthorized response with status: %d\n", wait_status);
|
||||
OnboardLog("Received Unauthorized response with status: %d\n", wait_status);
|
||||
return WAIT_ACTION_RETRY;
|
||||
}
|
||||
ParodusError("Client connection timeout\n");
|
||||
ParodusError("RDK-10037 - WebPA Connection Lost\n");
|
||||
@@ -449,9 +602,9 @@ int wait_connection_ready (create_connection_ctx_t *ctx)
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Return codes for connect_and_wait
|
||||
#define CONN_WAIT_SUCCESS 0
|
||||
#define CONN_WAIT_ACTION_RETRY 1 // if wait_status is 307, 302, 303 or 403
|
||||
#define CONN_WAIT_RETRY_DNS 2
|
||||
#define CONN_WAIT_SUCCESS 0
|
||||
#define CONN_WAIT_ACTION_RETRY 1 // if wait_status is 307, 302, 303, or 403
|
||||
#define CONN_WAIT_FAIL 2
|
||||
|
||||
int connect_and_wait (create_connection_ctx_t *ctx)
|
||||
{
|
||||
@@ -482,7 +635,7 @@ int connect_and_wait (create_connection_ctx_t *ctx)
|
||||
} // nopoll_connected
|
||||
|
||||
if (nopoll_connected) {
|
||||
close_and_unref_connection(get_global_conn());
|
||||
close_and_unref_connection(get_global_conn(), false);
|
||||
set_global_conn(NULL);
|
||||
}
|
||||
|
||||
@@ -495,7 +648,7 @@ int connect_and_wait (create_connection_ctx_t *ctx)
|
||||
continue;
|
||||
}
|
||||
|
||||
return CONN_WAIT_RETRY_DNS;
|
||||
return CONN_WAIT_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -508,20 +661,62 @@ int keep_trying_to_connect (create_connection_ctx_t *ctx,
|
||||
{
|
||||
int rtn;
|
||||
|
||||
while (true)
|
||||
while (!g_shutdown)
|
||||
{
|
||||
set_extra_headers (ctx);
|
||||
|
||||
rtn = connect_and_wait (ctx);
|
||||
if (rtn == CONN_WAIT_SUCCESS)
|
||||
return true;
|
||||
|
||||
if (rtn == CONN_WAIT_ACTION_RETRY) // if redirected or build_headers
|
||||
continue;
|
||||
backoff_delay (backoff_timer); // 3,7,15,31 ..
|
||||
if (rtn == CONN_WAIT_RETRY_DNS)
|
||||
return false; //find_server again
|
||||
// If interface down event is set, stop retry
|
||||
// and wait till interface is up again.
|
||||
if(get_interface_down_event()) {
|
||||
if (0 != wait_while_interface_down())
|
||||
return false;
|
||||
start_conn_in_progress(backoff_timer->start_time);
|
||||
ParodusInfo("Interface is back up, re-initializing the convey header\n");
|
||||
// Reset the reconnect reason by initializing the convey header again
|
||||
((header_info_t *)(&ctx->header_info))->conveyHeader = getWebpaConveyHeader();
|
||||
ParodusInfo("Received reconnect_reason as:%s\n", reconnect_reason);
|
||||
} else {
|
||||
if (backoff_delay (backoff_timer) // 3,7,15,31 ..
|
||||
!= BACKOFF_DELAY_TAKEN) // shutdown or cond wait error
|
||||
return false;
|
||||
}
|
||||
if (rtn == CONN_WAIT_FAIL) {
|
||||
return false;
|
||||
}
|
||||
// else retry
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int wait_while_interface_down()
|
||||
|
||||
{
|
||||
int rtn;
|
||||
|
||||
ParodusError("Interface is down, hence waiting until its up\n");
|
||||
close_and_unref_connection (get_global_conn(), false);
|
||||
set_global_conn(NULL);
|
||||
|
||||
while (get_interface_down_event ()) {
|
||||
pthread_mutex_lock(get_interface_down_mut());
|
||||
rtn = pthread_cond_wait(get_interface_down_con(), get_interface_down_mut());
|
||||
pthread_mutex_unlock (get_interface_down_mut());
|
||||
if (rtn != 0)
|
||||
ParodusError
|
||||
("Error on pthread_cond_wait (%d) in wait_while_interface_down\n", rtn);
|
||||
if (g_shutdown) {
|
||||
ParodusInfo("Received g_shutdown during interface down wait, returning\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
@@ -529,14 +724,13 @@ int keep_trying_to_connect (create_connection_ctx_t *ctx,
|
||||
* @brief createNopollConnection interface to create WebSocket client connections.
|
||||
*Loads the WebPA config file and creates the intial connection and manages the connection wait, close mechanisms.
|
||||
*/
|
||||
int createNopollConnection(noPollCtx *ctx)
|
||||
int createNopollConnection(noPollCtx *ctx, server_list_t *server_list)
|
||||
{
|
||||
create_connection_ctx_t conn_ctx;
|
||||
int max_retry_count;
|
||||
int query_dns_status;
|
||||
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;
|
||||
@@ -548,45 +742,78 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
|
||||
max_retry_count = (int) get_parodus_cfg()->webpa_backoff_max;
|
||||
ParodusPrint("max_retry_count is %d\n", max_retry_count );
|
||||
|
||||
|
||||
memset (&conn_ctx, 0, sizeof(create_connection_ctx_t));
|
||||
conn_ctx.nopoll_ctx = ctx;
|
||||
init_expire_timer (&conn_ctx.connect_timer);
|
||||
init_header_info (&conn_ctx.header_info);
|
||||
set_extra_headers (&conn_ctx, false);
|
||||
set_server_list_null (&conn_ctx.server_list);
|
||||
init_backoff_timer (&backoff_timer, max_retry_count);
|
||||
/* look up server information if we don't already have it */
|
||||
if (server_is_null (&server_list->defaults))
|
||||
if (find_servers (server_list) == FIND_INVALID_DEFAULT) {
|
||||
return nopoll_false;
|
||||
}
|
||||
conn_ctx.server_list = server_list;
|
||||
init_backoff_timer (&backoff_timer, max_retry_count);
|
||||
start_conn_in_progress (backoff_timer.start_time);
|
||||
|
||||
while (true)
|
||||
while (!g_shutdown)
|
||||
{
|
||||
query_dns_status = find_servers (&conn_ctx.server_list);
|
||||
if (query_dns_status == FIND_INVALID_DEFAULT)
|
||||
return nopoll_false;
|
||||
set_current_server (&conn_ctx);
|
||||
if (keep_trying_to_connect (&conn_ctx, &backoff_timer))
|
||||
if (keep_trying_to_connect (&conn_ctx, &backoff_timer)) {
|
||||
// Don't reuse the redirect server during reconnect
|
||||
free_server (&conn_ctx.server_list->redirect);
|
||||
break;
|
||||
// retry dns query
|
||||
}
|
||||
/* 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))
|
||||
if (find_servers (conn_ctx.server_list) == FIND_INVALID_DEFAULT) {
|
||||
/* since we already found a default server, we don't expect FIND_INVALID_DEFAULT */
|
||||
g_shutdown = true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if(conn_ctx.current_server->allow_insecure <= 0)
|
||||
if(conn_ctx.current_server != NULL && conn_ctx.current_server->allow_insecure <= 0)
|
||||
{
|
||||
ParodusInfo("Connected to server over SSL\n");
|
||||
OnboardLog("Connected to server over SSL\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusInfo("Connected to server\n");
|
||||
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);
|
||||
|
||||
if(get_parodus_cfg()->boot_time != 0) {
|
||||
getCurrentTime(connectTimePtr);
|
||||
ParodusInfo("connect_time-diff-boot_time=%d\n", connectTimePtr->tv_sec - get_parodus_cfg()->boot_time);
|
||||
/* 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)
|
||||
{
|
||||
on_ping_status_change("received");
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
free_extra_headers (&conn_ctx);
|
||||
free_header_info (&conn_ctx.header_info);
|
||||
free_server_list (&conn_ctx.server_list);
|
||||
free_header_info (&conn_ctx.header_info);
|
||||
|
||||
// Reset close_retry flag and heartbeatTimer once the connection retry is successful
|
||||
ParodusPrint("createNopollConnection(): reset_close_retry\n");
|
||||
@@ -596,7 +823,10 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
set_global_reconnect_status(false);
|
||||
ParodusPrint("LastReasonStatus reset after successful connection\n");
|
||||
setMessageHandlers();
|
||||
|
||||
stop_conn_in_progress ();
|
||||
ParodusPrint("set cloud_status\n");
|
||||
set_cloud_status(CLOUD_STATUS_ONLINE);
|
||||
ParodusInfo("cloud_status set as %s after successful connection\n", get_cloud_status());
|
||||
return nopoll_true;
|
||||
}
|
||||
|
||||
@@ -623,30 +853,116 @@ static char* build_extra_headers( const char *auth, const char *device_id,
|
||||
static noPollConnOpts * createConnOpts (char * extra_headers, bool secure)
|
||||
{
|
||||
noPollConnOpts * opts;
|
||||
char * mtls_client_cert_path = NULL;
|
||||
char * mtls_client_key_path = NULL;
|
||||
|
||||
opts = nopoll_conn_opts_new ();
|
||||
if(secure)
|
||||
{
|
||||
if(strlen(get_parodus_cfg()->cert_path) > 0)
|
||||
{
|
||||
nopoll_conn_opts_set_ssl_certs(opts, NULL, NULL, NULL, get_parodus_cfg()->cert_path);
|
||||
if( ( get_parodus_cfg()->mtls_client_cert_path !=NULL && strlen(get_parodus_cfg()->mtls_client_cert_path) > 0) && (get_parodus_cfg()->mtls_client_key_path !=NULL && strlen(get_parodus_cfg()->mtls_client_key_path) > 0) )
|
||||
{
|
||||
mtls_client_cert_path = get_parodus_cfg()->mtls_client_cert_path;
|
||||
mtls_client_key_path = get_parodus_cfg()->mtls_client_key_path;
|
||||
}
|
||||
nopoll_conn_opts_set_ssl_certs(opts, mtls_client_cert_path, mtls_client_key_path, NULL, get_parodus_cfg()->cert_path);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
void close_and_unref_connection(noPollConn *conn)
|
||||
static void close_conn ( noPollConn *conn, bool is_shutting_down)
|
||||
{
|
||||
const char *effective_reason = get_global_shutdown_reason();
|
||||
|
||||
if (NULL == effective_reason) {
|
||||
effective_reason = SHUTDOWN_REASON_SYSTEM_RESTART;
|
||||
}
|
||||
else if (strcmp (effective_reason, SHUTDOWN_REASON_SIGTERM) == 0) {
|
||||
char *sigterm_reason;
|
||||
char *reason_file = get_parodus_cfg()->close_reason_file;
|
||||
if ((NULL != reason_file) && readFromFile (reason_file, &sigterm_reason) &&
|
||||
(strlen(sigterm_reason) != 0))
|
||||
{
|
||||
nopoll_conn_close_ext(conn, CloseNormalClosure, sigterm_reason,
|
||||
strlen (sigterm_reason));
|
||||
ParodusInfo ("Closed by SIGTERM, reason: %s\n", sigterm_reason);
|
||||
if (is_shutting_down)
|
||||
ParodusInfo ("shutdown reason at close %s\n", sigterm_reason);
|
||||
free (sigterm_reason);
|
||||
return;
|
||||
}
|
||||
/* file could not be read. use canned message. */
|
||||
effective_reason = SHUTDOWN_REASON_SYSTEM_RESTART;
|
||||
ParodusError ("Closed by SIGTERM, but no reason file\n");
|
||||
}
|
||||
nopoll_conn_close_ext(conn, CloseNormalClosure, effective_reason,
|
||||
strlen (effective_reason));
|
||||
if (is_shutting_down)
|
||||
ParodusInfo ("shutdown reason at close %s\n", effective_reason);
|
||||
}
|
||||
|
||||
void close_and_unref_connection(noPollConn *conn, bool is_shutting_down)
|
||||
{
|
||||
if (conn) {
|
||||
nopoll_conn_close(conn);
|
||||
if (0 < nopoll_conn_ref_count (conn)) {
|
||||
nopoll_conn_unref(conn);
|
||||
}
|
||||
close_conn (conn, is_shutting_down);
|
||||
set_cloud_status(CLOUD_STATUS_OFFLINE);
|
||||
ParodusInfo("cloud_status set as %s after connection close\n", get_cloud_status());
|
||||
}
|
||||
}
|
||||
|
||||
void write_conn_in_prog_file (bool is_starting, unsigned long start_time)
|
||||
{
|
||||
int fd;
|
||||
FILE *fp;
|
||||
unsigned long timestamp;
|
||||
ParodusCfg *cfg = get_parodus_cfg();
|
||||
|
||||
if (NULL == cfg->connection_health_file)
|
||||
return;
|
||||
fd = open (cfg->connection_health_file, O_CREAT | O_WRONLY | O_SYNC, 0666);
|
||||
if (fd < 0) {
|
||||
ParodusError ("Error(1) %d opening file %s\n", errno, cfg->connection_health_file);
|
||||
return;
|
||||
}
|
||||
ftruncate (fd, 0);
|
||||
fp = fdopen (fd, "w");
|
||||
if (fp == NULL) {
|
||||
ParodusError ("Error(2) %d opening file %s\n", errno, cfg->connection_health_file);
|
||||
return;
|
||||
}
|
||||
timestamp = (unsigned long) time(NULL);
|
||||
if (is_starting)
|
||||
fprintf (fp, "{START=%lu,%lu}\n", start_time, timestamp);
|
||||
else
|
||||
fprintf (fp, "{STOP=%lu}\n", timestamp);
|
||||
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
void start_conn_in_progress (unsigned long start_time)
|
||||
{
|
||||
write_conn_in_prog_file (true, start_time);
|
||||
}
|
||||
|
||||
void stop_conn_in_progress (void)
|
||||
{
|
||||
write_conn_in_prog_file (false, 0);
|
||||
}
|
||||
|
||||
|
||||
void registerParodusOnPingStatusChangeHandler(parodusOnPingStatusChangeHandler callback_func)
|
||||
{
|
||||
on_ping_status_change = callback_func;
|
||||
}
|
||||
|
||||
void registerParodusOnConnStatusChangeHandler(parodusOnConnStatusChangeHandler callback_func)
|
||||
{
|
||||
on_conn_status_change = callback_func;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,22 +33,46 @@ extern "C" {
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#define SHUTDOWN_REASON_PARODUS_STOP "parodus_stopping"
|
||||
#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
|
||||
* when websocket Ping status change event
|
||||
* i.e. ping_miss or ping receive after miss
|
||||
*/
|
||||
typedef void (*parodusOnPingStatusChangeHandler) (char * status);
|
||||
extern parodusOnPingStatusChangeHandler on_ping_status_change;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Function Prototypes */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
int createNopollConnection(noPollCtx *);
|
||||
void set_server_list_null (server_list_t *server_list);
|
||||
int createNopollConnection(noPollCtx *, server_list_t *);
|
||||
|
||||
/**
|
||||
* @brief Interface to terminate WebSocket client connections and clean up resources.
|
||||
*/
|
||||
void close_and_unref_connection(noPollConn *);
|
||||
void close_and_unref_connection(noPollConn *conn, bool is_shutting_down);
|
||||
|
||||
noPollConn *get_global_conn(void);
|
||||
void set_global_conn(noPollConn *);
|
||||
|
||||
char *get_global_shutdown_reason();
|
||||
void set_global_shutdown_reason(char *reason);
|
||||
|
||||
char *get_global_reconnect_reason();
|
||||
void set_global_reconnect_reason(char *reason);
|
||||
|
||||
@@ -57,6 +81,24 @@ void set_global_reconnect_status(bool status);
|
||||
|
||||
int get_cloud_disconnect_time();
|
||||
void set_cloud_disconnect_time(int disconnTime);
|
||||
|
||||
/**
|
||||
* @brief Interface to self heal connection in progress getting stuck
|
||||
*/
|
||||
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);
|
||||
|
||||
// To stop connection and wait duing interface down state
|
||||
int wait_while_interface_down (void);
|
||||
|
||||
void terminate_backoff_delay (void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -44,6 +44,16 @@ CrudMsg *crudMsgQ = NULL;
|
||||
/* External functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
pthread_cond_t *get_global_crud_con(void)
|
||||
{
|
||||
return &crud_con;
|
||||
}
|
||||
|
||||
pthread_mutex_t *get_global_crud_mut(void)
|
||||
{
|
||||
return &crud_mut;
|
||||
}
|
||||
|
||||
void addCRUDmsgToQueue(wrp_msg_t *crudMsg)
|
||||
{
|
||||
CrudMsg * crudMessage;
|
||||
@@ -122,6 +132,10 @@ void *CRUDHandlerTask()
|
||||
}
|
||||
else
|
||||
{
|
||||
if (g_shutdown) {
|
||||
pthread_mutex_unlock (&crud_mut);
|
||||
break;
|
||||
}
|
||||
pthread_cond_wait(&crud_con, &crud_mut);
|
||||
pthread_mutex_unlock (&crud_mut);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#ifndef _CRUD_INTERFACE_H_
|
||||
#define _CRUD_INTERFACE_H_
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -43,6 +45,8 @@ typedef struct CrudMsg__
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void addCRUDresponseToUpstreamQ(void *response_bytes, ssize_t response_size);
|
||||
pthread_cond_t *get_global_crud_con(void);
|
||||
pthread_mutex_t *get_global_crud_mut(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
@@ -58,22 +62,7 @@ int writeToJSON(char *data)
|
||||
|
||||
int readFromJSON(char **data)
|
||||
{
|
||||
FILE *fp;
|
||||
int ch_count = 0;
|
||||
fp = fopen(get_parodus_cfg()->crud_config_file, "r+");
|
||||
if (fp == NULL)
|
||||
{
|
||||
ParodusError("Failed to open file %s\n", get_parodus_cfg()->crud_config_file);
|
||||
return 0;
|
||||
}
|
||||
fseek(fp, 0, SEEK_END);
|
||||
ch_count = ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
*data = (char *) malloc(sizeof(char) * (ch_count + 1));
|
||||
fread(*data, 1, ch_count,fp);
|
||||
(*data)[ch_count] ='\0';
|
||||
fclose(fp);
|
||||
return 1;
|
||||
return readFromFile (get_parodus_cfg()->crud_config_file, data);
|
||||
}
|
||||
/*
|
||||
* @res_obj json object to add it in crud config json file
|
||||
@@ -548,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)
|
||||
{
|
||||
@@ -588,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)
|
||||
@@ -654,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)
|
||||
{
|
||||
@@ -1346,6 +1342,7 @@ static int ConnDisconnectFromCloud(char *disconn_reason)
|
||||
if(!close_retry)
|
||||
{
|
||||
ParodusInfo("Reconnect detected, setting reason %s for Reconnect\n", disconn_reason);
|
||||
OnboardLog("Reconnect detected, setting reason %s for Reconnect\n", disconn_reason);
|
||||
set_global_reconnect_reason(disconn_reason);
|
||||
set_global_reconnect_status(true);
|
||||
set_close_retry();
|
||||
@@ -1627,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;
|
||||
}
|
||||
|
||||
217
src/downstream.c
217
src/downstream.c
@@ -27,7 +27,13 @@
|
||||
#include "partners_check.h"
|
||||
#include "ParodusInternal.h"
|
||||
#include "crud_interface.h"
|
||||
|
||||
#ifdef ENABLE_WEBCFGBIN
|
||||
#include "xmidtsend_rbus.h"
|
||||
#endif
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Function Prototypes */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void createNewMsgForCRUD(wrp_msg_t *message, wrp_msg_t **crudMessage );
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -42,6 +48,7 @@ void listenerOnMessage(void * msg, size_t msgSize)
|
||||
{
|
||||
int rv =0;
|
||||
wrp_msg_t *message;
|
||||
wrp_msg_t *crudMessage= NULL;
|
||||
char* destVal = NULL;
|
||||
char dest[32] = {'\0'};
|
||||
int msgType;
|
||||
@@ -75,7 +82,6 @@ void listenerOnMessage(void * msg, size_t msgSize)
|
||||
case WRP_MSG_TYPE__AUTH:
|
||||
{
|
||||
ParodusInfo("Authorization Status received with Status code :%d\n", message->u.auth.status);
|
||||
wrp_free_struct(message);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -88,6 +94,7 @@ void listenerOnMessage(void * msg, size_t msgSize)
|
||||
{
|
||||
ParodusPrint("numOfClients registered is %d\n", get_numOfClients());
|
||||
int ret = validate_partner_id(message, NULL);
|
||||
ParodusPrint("validate_partner_id returns %d\n", ret);
|
||||
if(ret < 0)
|
||||
{
|
||||
response = cJSON_CreateObject();
|
||||
@@ -95,7 +102,6 @@ void listenerOnMessage(void * msg, size_t msgSize)
|
||||
cJSON_AddStringToObject(response, "message", "Invalid partner_id");
|
||||
}
|
||||
|
||||
|
||||
destVal = strdup(((WRP_MSG_TYPE__EVENT == msgType) ? message->u.event.dest :
|
||||
((WRP_MSG_TYPE__REQ == msgType) ? message->u.req.dest : message->u.crud.dest)));
|
||||
|
||||
@@ -117,10 +123,14 @@ void listenerOnMessage(void * msg, size_t msgSize)
|
||||
}
|
||||
ParodusInfo("Received downstream dest as :%s and transaction_uuid :%s\n", dest,
|
||||
((WRP_MSG_TYPE__REQ == msgType) ? message->u.req.transaction_uuid :
|
||||
((WRP_MSG_TYPE__EVENT == msgType) ? "NA" : message->u.crud.transaction_uuid)));
|
||||
((WRP_MSG_TYPE__EVENT == msgType) ? message->u.event.transaction_uuid : message->u.crud.transaction_uuid)));
|
||||
OnboardLog("%s\n",
|
||||
((WRP_MSG_TYPE__REQ == msgType) ? message->u.req.transaction_uuid :
|
||||
((WRP_MSG_TYPE__EVENT == msgType) ? message->u.event.transaction_uuid : message->u.crud.transaction_uuid)));
|
||||
|
||||
free(destVal);
|
||||
temp = get_global_node();
|
||||
|
||||
temp = get_global_node();
|
||||
//Checking for individual clients & Sending to each client
|
||||
|
||||
while (NULL != temp)
|
||||
@@ -139,10 +149,11 @@ void listenerOnMessage(void * msg, size_t msgSize)
|
||||
ParodusPrint("checking the next item in the list\n");
|
||||
temp= temp->next;
|
||||
}
|
||||
release_global_node ();
|
||||
|
||||
/* check Downstream dest for CRUD requests */
|
||||
if(destFlag ==0 && strcmp("parodus", dest)==0)
|
||||
{
|
||||
/* check Downstream dest for CRUD requests */
|
||||
if(destFlag ==0 && strcmp("parodus", dest)==0)
|
||||
{
|
||||
ParodusPrint("Received CRUD request : dest : %s\n", dest);
|
||||
if ((message->u.crud.source == NULL) || (message->u.crud.transaction_uuid == NULL))
|
||||
{
|
||||
@@ -154,18 +165,22 @@ void listenerOnMessage(void * msg, size_t msgSize)
|
||||
}
|
||||
else
|
||||
{
|
||||
addCRUDmsgToQueue(message);
|
||||
createNewMsgForCRUD(message, &crudMessage);
|
||||
addCRUDmsgToQueue(crudMessage);
|
||||
}
|
||||
destFlag =1;
|
||||
}
|
||||
//if any unknown dest received sending error response to server
|
||||
if(destFlag ==0)
|
||||
{
|
||||
ParodusError("Unknown dest:%s\n", dest);
|
||||
response = cJSON_CreateObject();
|
||||
cJSON_AddNumberToObject(response, "statusCode", 531);
|
||||
cJSON_AddStringToObject(response, "message", "Service Unavailable");
|
||||
}
|
||||
}
|
||||
//if any unknown dest received sending error response to server
|
||||
if (WRP_MSG_TYPE__EVENT != msgType)
|
||||
{
|
||||
if(destFlag ==0)
|
||||
{
|
||||
ParodusError("Unknown dest:%s\n", dest);
|
||||
response = cJSON_CreateObject();
|
||||
cJSON_AddNumberToObject(response, "statusCode", 531);
|
||||
cJSON_AddStringToObject(response, "message", "Service Unavailable");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( (WRP_MSG_TYPE__EVENT != msgType) &&
|
||||
@@ -184,14 +199,14 @@ void listenerOnMessage(void * msg, size_t msgSize)
|
||||
else
|
||||
{
|
||||
resp_msg ->u.crud.source = message->u.crud.dest;
|
||||
if(message->u.crud.source !=NULL)
|
||||
{
|
||||
resp_msg ->u.crud.dest = message->u.crud.source;
|
||||
}
|
||||
else
|
||||
{
|
||||
resp_msg ->u.crud.dest = "unknown";
|
||||
}
|
||||
if(message->u.crud.source !=NULL)
|
||||
{
|
||||
resp_msg ->u.crud.dest = message->u.crud.source;
|
||||
}
|
||||
else
|
||||
{
|
||||
resp_msg ->u.crud.dest = "unknown";
|
||||
}
|
||||
resp_msg ->u.crud.transaction_uuid = message->u.crud.transaction_uuid;
|
||||
resp_msg ->u.crud.path = message->u.crud.path;
|
||||
}
|
||||
@@ -225,9 +240,38 @@ void listenerOnMessage(void * msg, size_t msgSize)
|
||||
resp_bytes = NULL;
|
||||
}
|
||||
free(resp_msg);
|
||||
ParodusPrint("free for downstream decoded msg\n");
|
||||
wrp_free_struct(message);
|
||||
}
|
||||
#ifdef ENABLE_WEBCFGBIN
|
||||
//To handle cloud ack events received from server for the xmidt sent messages.
|
||||
if((WRP_MSG_TYPE__EVENT == msgType) && (ret >= 0))
|
||||
{
|
||||
if(get_parodus_cfg()->max_queue_size > 0)
|
||||
{
|
||||
//Process cloud ack only when qos > 24
|
||||
if(highQosValueCheck(message->u.event.qos))
|
||||
{
|
||||
if(message->u.event.transaction_uuid !=NULL)
|
||||
{
|
||||
ParodusInfo("Received cloud ack from server: transaction_uuid %s qos %d, rdr %d source %s\n", message->u.event.transaction_uuid, message->u.event.qos, message->u.event.rdr, message->u.event.source);
|
||||
addToCloudAckQ(message->u.event.transaction_uuid, message->u.event.qos, message->u.event.rdr, message->u.event.source);
|
||||
ParodusPrint("Added to cloud ack Q\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("cloud ack transaction id is NULL\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusInfo("cloud ack received with low qos %d, ignoring it\n", message->u.event.qos);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusInfo("cloud ack is ignored as max queue size is %d\n", get_parodus_cfg()->max_queue_size );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -235,9 +279,11 @@ void listenerOnMessage(void * msg, size_t msgSize)
|
||||
case WRP_MSG_TYPE__SVC_ALIVE:
|
||||
case WRP_MSG_TYPE__UNKNOWN:
|
||||
default:
|
||||
wrp_free_struct(message);
|
||||
break;
|
||||
}
|
||||
ParodusPrint("free for downstream decoded msg\n");
|
||||
wrp_free_struct(message);
|
||||
message = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -245,3 +291,116 @@ void listenerOnMessage(void * msg, size_t msgSize)
|
||||
}
|
||||
}
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Internal Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief createNewMsgForCRUD function to create new message for processing CRUD requests
|
||||
*
|
||||
* @param[in] message The message received from server
|
||||
* @param[out] crudMessage New message for processing CRUD requests
|
||||
*/
|
||||
static void createNewMsgForCRUD(wrp_msg_t *message, wrp_msg_t **crudMessage )
|
||||
{
|
||||
wrp_msg_t *msg;
|
||||
msg = ( wrp_msg_t * ) malloc( sizeof( wrp_msg_t ) );
|
||||
size_t i;
|
||||
if(msg != NULL)
|
||||
{
|
||||
memset( msg, 0, sizeof( wrp_msg_t ) );
|
||||
msg->msg_type = message->msg_type;
|
||||
if(message->u.crud.source != NULL)
|
||||
{
|
||||
ParodusPrint("message->u.crud.source = %s\n",message->u.crud.source);
|
||||
msg->u.crud.source = strdup(message->u.crud.source);
|
||||
}
|
||||
|
||||
if(message->u.crud.dest!= NULL)
|
||||
{
|
||||
ParodusPrint("message->u.crud.dest = %s\n",message->u.crud.dest);
|
||||
msg->u.crud.dest = strdup(message->u.crud.dest);
|
||||
}
|
||||
|
||||
if(message->u.crud.transaction_uuid != NULL)
|
||||
{
|
||||
ParodusPrint("message->u.crud.transaction_uuid = %s\n",message->u.crud.transaction_uuid);
|
||||
msg->u.crud.transaction_uuid = strdup(message->u.crud.transaction_uuid);
|
||||
}
|
||||
|
||||
if(message->u.crud.partner_ids!= NULL && message->u.crud.partner_ids->count >0)
|
||||
{
|
||||
msg->u.crud.partner_ids = ( partners_t * ) malloc( sizeof( partners_t ) +
|
||||
sizeof( char * ) * message->u.crud.partner_ids->count );
|
||||
if(msg->u.crud.partner_ids != NULL)
|
||||
{
|
||||
msg->u.crud.partner_ids->count = message->u.crud.partner_ids->count;
|
||||
for(i = 0; i<message->u.crud.partner_ids->count; i++)
|
||||
{
|
||||
ParodusPrint("message->u.crud.partner_ids->partner_ids[%d] = %s\n",i,message->u.crud.partner_ids->partner_ids[i]);
|
||||
msg->u.crud.partner_ids->partner_ids[i] = strdup(message->u.crud.partner_ids->partner_ids[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(message->u.crud.headers!= NULL && message->u.crud.headers->count >0)
|
||||
{
|
||||
msg->u.crud.headers = ( headers_t * ) malloc( sizeof( headers_t ) +
|
||||
sizeof( char * ) * message->u.crud.headers->count );
|
||||
if(msg->u.crud.headers != NULL)
|
||||
{
|
||||
msg->u.crud.headers->count = message->u.crud.headers->count;
|
||||
for(i = 0; i<message->u.crud.headers->count; i++)
|
||||
{
|
||||
ParodusPrint("message->u.crud.headers->headers[%d] = %s\n",i,message->u.crud.headers->headers[i]);
|
||||
msg->u.crud.headers->headers[i] = strdup(message->u.crud.headers->headers[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(message->u.crud.metadata != NULL && message->u.crud.metadata->count > 0)
|
||||
{
|
||||
msg->u.crud.metadata = (data_t *) malloc( sizeof( data_t ) );
|
||||
if(msg->u.crud.metadata != NULL)
|
||||
{
|
||||
memset( msg->u.crud.metadata, 0, sizeof( data_t ) );
|
||||
msg->u.crud.metadata->count = message->u.crud.metadata->count;
|
||||
msg->u.crud.metadata->data_items = ( struct data* )malloc( sizeof( struct data ) * ( message->u.crud.metadata->count ) );
|
||||
for(i=0; i<message->u.crud.metadata->count; i++)
|
||||
{
|
||||
if(message->u.crud.metadata->data_items[i].name != NULL)
|
||||
{
|
||||
ParodusPrint("message->u.crud.metadata->data_items[%d].name : %s\n",i,message->u.crud.metadata->data_items[i].name);
|
||||
msg->u.crud.metadata->data_items[i].name = strdup(message->u.crud.metadata->data_items[i].name);
|
||||
}
|
||||
if(message->u.crud.metadata->data_items[i].value != NULL)
|
||||
{
|
||||
ParodusPrint("message->u.crud.metadata->data_items[%d].value : %s\n",i,message->u.crud.metadata->data_items[i].value);
|
||||
msg->u.crud.metadata->data_items[i].value = strdup(message->u.crud.metadata->data_items[i].value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
msg->u.crud.include_spans = message->u.crud.include_spans;
|
||||
if(message->u.crud.content_type != NULL)
|
||||
{
|
||||
ParodusPrint("message->u.crud.content_type : %s\n",message->u.crud.content_type);
|
||||
msg->u.crud.content_type = strdup(message->u.crud.content_type);
|
||||
}
|
||||
msg->u.crud.spans.spans = NULL; /* not supported */
|
||||
msg->u.crud.spans.count = 0; /* not supported */
|
||||
msg->u.crud.status = message->u.crud.status;
|
||||
msg->u.crud.rdr = message->u.crud.rdr;
|
||||
if(message->u.crud.payload != NULL)
|
||||
{
|
||||
ParodusPrint("message->u.crud.payload = %s\n", (char *)message->u.crud.payload);
|
||||
msg->u.crud.payload = strdup((char *)message->u.crud.payload);
|
||||
}
|
||||
msg->u.crud.payload_size = message->u.crud.payload_size;
|
||||
if(message->u.crud.path != NULL)
|
||||
{
|
||||
ParodusPrint("message->u.crud.path = %s\n", message->u.crud.path);
|
||||
msg->u.crud.path = strdup(message->u.crud.path);
|
||||
}
|
||||
*crudMessage = msg;
|
||||
}
|
||||
}
|
||||
|
||||
26
src/event_handler.c
Normal file
26
src/event_handler.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* If not stated otherwise in this file or this component's Licenses.txt file the
|
||||
* following copyright and licenses apply:
|
||||
*
|
||||
* Copyright 2016 RDK Management
|
||||
* Copyright [2014] [Cisco Systems, Inc.]
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* This is a stub file that will be overridden in a patch */
|
||||
|
||||
#include "event_handler.h"
|
||||
|
||||
void EventHandler()
|
||||
{
|
||||
}
|
||||
21
src/event_handler.h
Normal file
21
src/event_handler.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* If not stated otherwise in this file or this component's Licenses.txt file the
|
||||
* following copyright and licenses apply:
|
||||
*
|
||||
* Copyright 2016 RDK Management
|
||||
* Copyright [2014] [Cisco Systems, Inc.]
|
||||
* 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.
|
||||
*/
|
||||
|
||||
void EventHandler();
|
||||
#define LOGGING_INTERVAL_SECS ( 60 * 60 )
|
||||
@@ -22,10 +22,15 @@
|
||||
*/
|
||||
|
||||
#include "heartBeat.h"
|
||||
#include "time.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
volatile unsigned int heartBeatTimer = 0;
|
||||
volatile bool paused = false;
|
||||
volatile long long pingTimeStamp = 0;
|
||||
|
||||
pthread_mutex_t heartBeat_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_mutex_t ping_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
// Get value of heartBeatTimer
|
||||
unsigned int get_heartBeatTimer()
|
||||
@@ -49,8 +54,44 @@ void reset_heartBeatTimer()
|
||||
void increment_heartBeatTimer(unsigned int inc_time_ms)
|
||||
{
|
||||
pthread_mutex_lock (&heartBeat_mut);
|
||||
heartBeatTimer += inc_time_ms;
|
||||
if (!paused)
|
||||
heartBeatTimer += inc_time_ms;
|
||||
pthread_mutex_unlock (&heartBeat_mut);
|
||||
}
|
||||
|
||||
// Pause heartBeatTimer, i.e. stop incrementing
|
||||
void pause_heartBeatTimer()
|
||||
{
|
||||
pthread_mutex_lock (&heartBeat_mut);
|
||||
heartBeatTimer = 0;
|
||||
paused = true;
|
||||
pthread_mutex_unlock (&heartBeat_mut);
|
||||
}
|
||||
|
||||
// Resume heartBeatTimer, i.e. resume incrementing
|
||||
void resume_heartBeatTimer()
|
||||
{
|
||||
pthread_mutex_lock (&heartBeat_mut);
|
||||
paused = false;
|
||||
pthread_mutex_unlock (&heartBeat_mut);
|
||||
}
|
||||
|
||||
// Set ping received timeStamp
|
||||
void set_pingTimeStamp()
|
||||
{
|
||||
struct timespec ts;
|
||||
getCurrentTime(&ts);
|
||||
pthread_mutex_lock (&ping_mut);
|
||||
pingTimeStamp = (long long)ts.tv_sec;
|
||||
pthread_mutex_unlock (&ping_mut);
|
||||
}
|
||||
|
||||
// Get ping received timeStamp
|
||||
long long get_pingTimeStamp()
|
||||
{
|
||||
long long tmp = 0;
|
||||
pthread_mutex_lock (&ping_mut);
|
||||
tmp = pingTimeStamp;
|
||||
pthread_mutex_unlock (&ping_mut);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,16 @@ void reset_heartBeatTimer();
|
||||
// Increment value of heartBeatTimer to desired value
|
||||
void increment_heartBeatTimer(unsigned int inc_time_ms);
|
||||
|
||||
// Pause heartBeatTimer, i.e. stop incrementing
|
||||
void pause_heartBeatTimer();
|
||||
|
||||
// Resume heartBeatTimer, i.e. resume incrementing
|
||||
void resume_heartBeatTimer();
|
||||
|
||||
void set_pingTimeStamp();
|
||||
|
||||
long long get_pingTimeStamp();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
90
src/main.c
90
src/main.c
@@ -18,13 +18,20 @@
|
||||
#include <string.h>
|
||||
#include "stdlib.h"
|
||||
#include "config.h"
|
||||
#include "auth_token.h"
|
||||
#include "connection.h"
|
||||
#include "conn_interface.h"
|
||||
#include "parodus_log.h"
|
||||
#include <curl/curl.h>
|
||||
#ifdef INCLUDE_BREAKPAD
|
||||
#ifndef DEVICE_CAMERA
|
||||
#include "breakpad_wrapper.h"
|
||||
#else
|
||||
#include "signal.h"
|
||||
#include "breakpadwrap.h"
|
||||
#endif //DEVICE_CAMERA
|
||||
#endif
|
||||
#include "signal.h"
|
||||
#include "privilege.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Macros */
|
||||
@@ -34,56 +41,97 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Data Structures */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* none */
|
||||
typedef void Sigfunc(int);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* none */
|
||||
int numLoops;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Function Prototypes */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#ifndef INCLUDE_BREAKPAD
|
||||
static void sig_handler(int sig);
|
||||
|
||||
Sigfunc *
|
||||
signal (int signo, Sigfunc *func)
|
||||
{
|
||||
struct sigaction act, oact;
|
||||
|
||||
act.sa_handler = func;
|
||||
sigemptyset (&act.sa_mask);
|
||||
act.sa_flags = 0;
|
||||
if (signo == SIGALRM) {
|
||||
#ifdef SA_INTERRUPT
|
||||
act.sa_flags |= SA_INTERRUPT; /* SunOS 4.x */
|
||||
#endif
|
||||
} else {
|
||||
#ifdef SA_RESTART
|
||||
act.sa_flags |= SA_RESTART; /* SVR4, 4.4BSD */
|
||||
#endif
|
||||
}
|
||||
if (sigaction (signo, &act, &oact) < 0) {
|
||||
ParodusError ("Signal Handler for signal %d not installed!\n", signo);
|
||||
return (SIG_ERR);
|
||||
}
|
||||
return (oact.sa_handler);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int main( int argc, char **argv)
|
||||
{
|
||||
#ifdef INCLUDE_BREAKPAD
|
||||
breakpad_ExceptionHandler();
|
||||
#else
|
||||
set_global_shutdown_reason (SHUTDOWN_REASON_PARODUS_STOP);
|
||||
signal(SIGTERM, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGUSR1, sig_handler);
|
||||
signal(SIGUSR2, sig_handler);
|
||||
signal(SIGQUIT, sig_handler);
|
||||
signal(SIGHUP, sig_handler);
|
||||
signal(SIGALRM, sig_handler);
|
||||
#ifdef INCLUDE_BREAKPAD
|
||||
#ifndef DEVICE_CAMERA
|
||||
/* breakpad handles the signals SIGSEGV, SIGBUS, SIGFPE, and SIGILL */
|
||||
breakpad_ExceptionHandler();
|
||||
#else
|
||||
/* breakpad handles the signals SIGSEGV, SIGBUS, SIGFPE, and SIGILL */
|
||||
BreakPadWrapExceptionHandler eh;
|
||||
eh = newBreakPadWrapExceptionHandler();
|
||||
if(NULL != eh) {
|
||||
ParodusInfo("Breakpad Initialized\n");
|
||||
}
|
||||
#endif //DEVICE_CAMERA
|
||||
#else
|
||||
signal(SIGSEGV, sig_handler);
|
||||
signal(SIGBUS, sig_handler);
|
||||
signal(SIGKILL, sig_handler);
|
||||
signal(SIGFPE, sig_handler);
|
||||
signal(SIGILL, sig_handler);
|
||||
signal(SIGQUIT, sig_handler);
|
||||
signal(SIGHUP, sig_handler);
|
||||
signal(SIGALRM, sig_handler);
|
||||
#endif
|
||||
ParodusCfg *cfg;
|
||||
|
||||
ParodusInfo ("RAND_MAX is %ld (0x%lx)\n", RAND_MAX, RAND_MAX);
|
||||
srandom (getpid());
|
||||
|
||||
/* TODO not ideal, but it fixes a more major problem for now. */
|
||||
cfg = get_parodus_cfg();
|
||||
memset(cfg,0,sizeof(ParodusCfg));
|
||||
|
||||
ParodusInfo("********** Starting component: Parodus **********\n ");
|
||||
drop_root_privilege();
|
||||
#ifdef ENABLE_WEBCFGBIN
|
||||
registerRbusLogger();
|
||||
subscribeRBUSevent();
|
||||
regXmidtSendDataMethod();
|
||||
#endif
|
||||
setDefaultValuesToCfg(cfg);
|
||||
if (0 != parseCommandLine(argc,argv,cfg)) {
|
||||
abort();
|
||||
}
|
||||
getAuthToken(cfg);
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
|
||||
createSocketConnection( NULL);
|
||||
|
||||
free_cfg(cfg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -95,7 +143,6 @@ const char *rdk_logger_module_fetch(void)
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Internal functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#ifndef INCLUDE_BREAKPAD
|
||||
static void sig_handler(int sig)
|
||||
{
|
||||
|
||||
@@ -103,17 +150,25 @@ static void sig_handler(int sig)
|
||||
{
|
||||
signal(SIGINT, sig_handler); /* reset it to this function */
|
||||
ParodusInfo("SIGINT received!\n");
|
||||
shutdownSocketConnection();
|
||||
shutdownSocketConnection(SHUTDOWN_REASON_PARODUS_STOP);
|
||||
}
|
||||
else if ( sig == SIGUSR1 )
|
||||
{
|
||||
signal(SIGUSR1, sig_handler); /* reset it to this function */
|
||||
ParodusInfo("SIGUSR1 received!\n");
|
||||
shutdownSocketConnection(SHUTDOWN_REASON_SYSTEM_RESTART);
|
||||
}
|
||||
else if ( sig == SIGUSR2 )
|
||||
{
|
||||
signal(SIGUSR2, sig_handler); /* reset it to this function */
|
||||
ParodusInfo("SIGUSR2 received!\n");
|
||||
}
|
||||
else if ( sig == SIGTERM )
|
||||
{
|
||||
signal(SIGTERM, sig_handler); /* reset it to this function */
|
||||
ParodusInfo("SIGTERM received!\n");
|
||||
shutdownSocketConnection(SHUTDOWN_REASON_SIGTERM);
|
||||
}
|
||||
else if ( sig == SIGCHLD )
|
||||
{
|
||||
signal(SIGCHLD, sig_handler); /* reset it to this function */
|
||||
@@ -132,8 +187,7 @@ static void sig_handler(int sig)
|
||||
else
|
||||
{
|
||||
ParodusInfo("Signal %d received!\n", sig);
|
||||
shutdownSocketConnection();
|
||||
shutdownSocketConnection(SHUTDOWN_REASON_PARODUS_STOP);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -70,6 +70,7 @@ int checkHostIp(char * serverIP)
|
||||
if (retVal != 0)
|
||||
{
|
||||
ParodusError("getaddrinfo: %s\n", gai_strerror(retVal));
|
||||
OnboardLog("getaddrinfo: %s\n", gai_strerror(retVal));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -149,6 +149,7 @@ void listenerOnPingMessage (noPollCtx * ctx, noPollConn * conn, noPollMsg * msg,
|
||||
if (nopoll_msg_opcode(msg) == NOPOLL_PING_FRAME)
|
||||
{
|
||||
reset_heartBeatTimer();
|
||||
set_pingTimeStamp();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,16 +168,25 @@ void listenerOnCloseMessage (noPollCtx * ctx, noPollConn * conn, noPollPtr user_
|
||||
if( closeStatus == 1006 && !get_global_reconnect_status())
|
||||
{
|
||||
ParodusInfo("Reconnect detected, setting default Reconnect reason %s\n",defaultReason);
|
||||
OnboardLog("Reconnect detected, setting default Reconnect reason %s\n",defaultReason);
|
||||
set_global_reconnect_reason(defaultReason);
|
||||
set_global_reconnect_status(true);
|
||||
}
|
||||
else if(!get_global_reconnect_status())
|
||||
{
|
||||
ParodusInfo("Reconnect detected, setting Reconnect reason as Unknown\n");
|
||||
OnboardLog("Reconnect detected, setting Reconnect reason as Unknown\n");
|
||||
set_global_reconnect_reason("Unknown");
|
||||
}
|
||||
|
||||
if(!get_interface_down_event())
|
||||
{
|
||||
ParodusInfo("Setting the close and retry connection\n");
|
||||
set_close_retry();
|
||||
}
|
||||
else
|
||||
ParodusInfo("Not Setting the close and retry connection as interface is down\n");
|
||||
|
||||
set_close_retry();
|
||||
ParodusPrint("listenerOnCloseMessage(): mutex unlock in producer thread\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "nopoll_helpers.h"
|
||||
#include "nopoll_handlers.h"
|
||||
#include "time.h"
|
||||
#include "config.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Macros */
|
||||
@@ -49,50 +50,36 @@ void setMessageHandlers()
|
||||
nopoll_conn_set_on_close(get_global_conn(), (noPollOnCloseHandler)listenerOnCloseMessage, NULL);
|
||||
}
|
||||
|
||||
int cloud_status_is_online (void)
|
||||
{
|
||||
const char *status = get_cloud_status();
|
||||
if (NULL == status)
|
||||
return false;
|
||||
return (strcmp (status, CLOUD_STATUS_ONLINE) == 0);
|
||||
}
|
||||
|
||||
/** 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;
|
||||
static int connErr=0;
|
||||
long timeDiff = 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 1;
|
||||
}
|
||||
|
||||
ParodusInfo("sendMessage length %zu\n", len);
|
||||
|
||||
if(nopoll_conn_is_ok(conn) && nopoll_conn_is_ready(conn))
|
||||
bytesWritten = sendResponse(conn, msg, len);
|
||||
ParodusPrint("Number of bytes written: %d\n", bytesWritten);
|
||||
if (bytesWritten != (int) len)
|
||||
{
|
||||
//bytesWritten = nopoll_conn_send_binary(conn, msg, len);
|
||||
bytesWritten = sendResponse(conn, msg, len);
|
||||
ParodusPrint("Number of bytes written: %d\n", bytesWritten);
|
||||
if (bytesWritten != (int) len)
|
||||
{
|
||||
ParodusError("Failed to send bytes %zu, bytes written were=%d (errno=%d, %s)..\n", len, bytesWritten, errno, strerror(errno));
|
||||
}
|
||||
connErr = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Failed to send msg upstream as connection is not OK\n");
|
||||
if (connErr == 0)
|
||||
{
|
||||
getCurrentTime(connStuck_startPtr);
|
||||
ParodusInfo("Conn got stuck, initialized the first timer\n");
|
||||
connErr = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
getCurrentTime(connStuck_endPtr);
|
||||
timeDiff = timeValDiff(connStuck_startPtr, connStuck_endPtr);
|
||||
ParodusPrint("checking timeout difference:%ld\n", timeDiff);
|
||||
|
||||
if( timeDiff >= (10*60*1000))
|
||||
{
|
||||
ParodusError("conn got stuck for over 10 minutes; crashing service.\n");
|
||||
kill(getpid(),SIGTERM);
|
||||
}
|
||||
|
||||
}
|
||||
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)
|
||||
@@ -149,6 +136,7 @@ void __report_log (noPollCtx * ctx, noPollDebugLevel level, const char * log_msg
|
||||
if (level == NOPOLL_LEVEL_CRITICAL)
|
||||
{
|
||||
ParodusError("%s\n", log_msg );
|
||||
OnboardLog("%s\n", log_msg );
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -33,3 +33,9 @@
|
||||
#define ParodusError(...) cimplog_error(LOGGING_MODULE, __VA_ARGS__)
|
||||
#define ParodusInfo(...) cimplog_info(LOGGING_MODULE, __VA_ARGS__)
|
||||
#define ParodusPrint(...) cimplog_debug(LOGGING_MODULE, __VA_ARGS__)
|
||||
#ifdef FEATURE_SUPPORT_ONBOARD_LOGGING
|
||||
#define OnboardLog(...) onboarding_log(LOGGING_MODULE, __VA_ARGS__)
|
||||
#else
|
||||
#define OnboardLog(...)
|
||||
#endif
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ int validate_partner_id(wrp_msg_t *msg, partners_t **partnerIds)
|
||||
}
|
||||
|
||||
/* Commandline input partner_ids not matching with partner_ids from request, appending to request partner_ids*/
|
||||
if(matchFlag != 1)
|
||||
if(matchFlag != 1 && partnerIds !=NULL)
|
||||
{
|
||||
(*partnerIds) = (partners_t *) malloc(sizeof(partners_t) + (sizeof(char *) * (count+partnersList->count)));
|
||||
(*partnerIds)->count = count+partnersList->count;
|
||||
@@ -132,6 +132,23 @@ int validate_partner_id(wrp_msg_t *msg, partners_t **partnerIds)
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else if (matchFlag != 1 && partnerIds == NULL)
|
||||
{
|
||||
ParodusError("partner_id match not found: command line input %s , msg partner_id %s\n", temp, msg->u.event.partner_ids->partner_ids[0]);
|
||||
if(partnersList != NULL)
|
||||
{
|
||||
for(j=0; j<partnersList->count; j++)
|
||||
{
|
||||
if(NULL != partnersList->partner_ids[j])
|
||||
{
|
||||
free(partnersList->partner_ids[j]);
|
||||
}
|
||||
}
|
||||
free(partnersList);
|
||||
}
|
||||
free(partnerId);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -178,6 +195,7 @@ int validate_partner_id(wrp_msg_t *msg, partners_t **partnerIds)
|
||||
if(matchFlag != 1)
|
||||
{
|
||||
ParodusError("Invalid partner_id %s\n",temp);
|
||||
OnboardLog("Invalid partner_id %s\n",temp);
|
||||
if(partnersList != NULL)
|
||||
{
|
||||
for(j=0; j<partnersList->count; j++)
|
||||
|
||||
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();
|
||||
@@ -31,9 +31,41 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#define KEEPALIVE_INTERVAL_SEC 30
|
||||
|
||||
pthread_mutex_t svc_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t svc_con=PTHREAD_COND_INITIALIZER;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Utiliy Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static int wait__ (unsigned int secs)
|
||||
{
|
||||
int shutdown_flag;
|
||||
struct timespec svc_alive_timer;
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &svc_alive_timer);
|
||||
svc_alive_timer.tv_sec += secs;
|
||||
pthread_mutex_lock(&svc_mut);
|
||||
pthread_cond_timedwait (&svc_con, &svc_mut, &svc_alive_timer);
|
||||
shutdown_flag = g_shutdown;
|
||||
pthread_mutex_unlock (&svc_mut);
|
||||
return shutdown_flag;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
pthread_cond_t *get_global_svc_con(void)
|
||||
{
|
||||
return &svc_con;
|
||||
}
|
||||
|
||||
pthread_mutex_t *get_global_svc_mut(void)
|
||||
{
|
||||
return &svc_mut;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @brief To handle registered services to indicate that the service is still alive.
|
||||
*/
|
||||
@@ -58,10 +90,10 @@ void *serviceAliveTask()
|
||||
while(1)
|
||||
{
|
||||
ParodusPrint("serviceAliveTask: numOfClients registered is %d\n", get_numOfClients());
|
||||
temp = get_global_node();
|
||||
if(get_numOfClients() > 0)
|
||||
{
|
||||
//sending svc msg to all the clients every 30s
|
||||
temp = get_global_node();
|
||||
size = (size_t) nbytes;
|
||||
while(NULL != temp)
|
||||
{
|
||||
@@ -82,8 +114,9 @@ void *serviceAliveTask()
|
||||
byte = 0;
|
||||
if(ret == 0)
|
||||
{
|
||||
ParodusPrint("Deletion from list is success, doing resync with head\n");
|
||||
release_global_node ();
|
||||
temp= get_global_node();
|
||||
ParodusInfo("Deletion from list is success, doing resync with head\n");
|
||||
ret = -1;
|
||||
}
|
||||
else
|
||||
@@ -91,15 +124,20 @@ void *serviceAliveTask()
|
||||
temp= temp->next;
|
||||
}
|
||||
}
|
||||
release_global_node ();
|
||||
ParodusPrint("Waiting for 30s to send keep alive msg \n");
|
||||
sleep(KEEPALIVE_INTERVAL_SEC);
|
||||
if (wait__ (KEEPALIVE_INTERVAL_SEC))
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
release_global_node ();
|
||||
ParodusInfo("No clients are registered, waiting ..\n");
|
||||
sleep(50);
|
||||
if (wait__ (50))
|
||||
break;
|
||||
}
|
||||
}
|
||||
free (svc_bytes);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#ifndef _SERVICE_ALIVE_H_
|
||||
#define _SERVICE_ALIVE_H_
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Function Prototypes */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -33,7 +35,8 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
void *serviceAliveTask();
|
||||
|
||||
pthread_cond_t *get_global_svc_con(void);
|
||||
pthread_mutex_t *get_global_svc_mut(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "spin_thread.h"
|
||||
#include "parodus_log.h"
|
||||
@@ -31,12 +30,12 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void StartThread(void *(*start_routine) (void *))
|
||||
void StartThread(void *(*start_routine) (void *), pthread_t *threadId)
|
||||
{
|
||||
int err = 0;
|
||||
pthread_t threadId;
|
||||
pthread_t __threadId;
|
||||
|
||||
err = pthread_create(&threadId, NULL, start_routine, NULL);
|
||||
err = pthread_create(&__threadId, NULL, start_routine, NULL);
|
||||
if (err != 0)
|
||||
{
|
||||
ParodusError("Error creating thread :[%s]\n", strerror(err));
|
||||
@@ -44,8 +43,13 @@ void StartThread(void *(*start_routine) (void *))
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("Thread created Successfully %lu\n", (unsigned long) threadId);
|
||||
*threadId = __threadId;
|
||||
ParodusPrint("Thread created Successfully %lu\n", (unsigned long) __threadId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void JoinThread (pthread_t threadId)
|
||||
{
|
||||
pthread_join (threadId, NULL);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#ifndef _SPIN_THREAD_H_
|
||||
#define _SPIN_THREAD_H_
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -32,8 +34,8 @@ extern "C" {
|
||||
/* Function Prototypes */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void StartThread(void *(*start_routine) (void *));
|
||||
|
||||
void StartThread(void *(*start_routine) (void *), pthread_t *threadId);
|
||||
void JoinThread (pthread_t threadId);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -43,6 +43,10 @@ void *messageHandlerTask()
|
||||
}
|
||||
else
|
||||
{
|
||||
if (g_shutdown) {
|
||||
pthread_mutex_unlock (&g_mutex);
|
||||
break;
|
||||
}
|
||||
ParodusPrint("Before pthread cond wait in consumer thread\n");
|
||||
pthread_cond_wait(&g_cond, &g_mutex);
|
||||
pthread_mutex_unlock (&g_mutex);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include "time.h"
|
||||
#include "parodus_log.h"
|
||||
#include <errno.h>
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
@@ -24,7 +25,10 @@
|
||||
|
||||
void getCurrentTime(struct timespec *timer)
|
||||
{
|
||||
clock_gettime(CLOCK_REALTIME, timer);
|
||||
if( clock_gettime(CLOCK_REALTIME, timer) == -1 )
|
||||
{
|
||||
ParodusError("clock gettime returns errno %d\n", errno );
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t getCurrentTimeInMicroSeconds(struct timespec *timer)
|
||||
@@ -34,7 +38,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)
|
||||
|
||||
@@ -139,6 +139,7 @@ int analyze_jwt (const cjwt_t *jwt, char **url_buf, unsigned int *port)
|
||||
show_times (exp_time, cur_time);
|
||||
if (exp_time < cur_time) {
|
||||
ParodusError ("JWT has expired\n");
|
||||
OnboardLog ("JWT has expired\n");
|
||||
return TOKEN_ERR_JWT_EXPIRED;
|
||||
}
|
||||
}
|
||||
@@ -146,6 +147,7 @@ int analyze_jwt (const cjwt_t *jwt, char **url_buf, unsigned int *port)
|
||||
url_buf, port);
|
||||
if (http_match < 0) {
|
||||
ParodusError ("Invalid endpoint claim in JWT\n");
|
||||
OnboardLog("Invalid endpoint claim in JWT\n");
|
||||
return TOKEN_ERR_BAD_ENDPOINT;
|
||||
}
|
||||
ParodusInfo ("JWT is_http strncmp: %d\n", http_match);
|
||||
@@ -527,7 +529,9 @@ int allow_insecure_conn(char **server_addr, unsigned int *port)
|
||||
}
|
||||
|
||||
if (insecure >= 0) {
|
||||
ParodusInfo ("JWT claims: %s\n", cJSON_Print (jwt->private_claims));
|
||||
char *claim_str = cJSON_Print (jwt->private_claims);
|
||||
ParodusInfo ("JWT claims: %s\n", claim_str);
|
||||
free (claim_str);
|
||||
}
|
||||
cjwt_destroy(&jwt);
|
||||
|
||||
|
||||
331
src/upstream.c
331
src/upstream.c
@@ -34,13 +34,13 @@
|
||||
/* Macros */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#define METADATA_COUNT 12
|
||||
#define CLOUD_STATUS_FORMAT "parodus/cloud-status"
|
||||
#define PARODUS_SERVICE_NAME "parodus"
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void *metadataPack;
|
||||
size_t metaPackSize=-1;
|
||||
size_t metaPackSize=0;
|
||||
|
||||
|
||||
UpStreamMsg *UpStreamMsgQ = NULL;
|
||||
@@ -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 );
|
||||
@@ -112,6 +110,11 @@ void packMetaData()
|
||||
ParodusError("Failed to encode metadata\n");
|
||||
}
|
||||
}
|
||||
|
||||
void clear_metadata(){
|
||||
if(metadataPack != NULL)
|
||||
free(metadataPack);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief To handle UpStream messages which is received from nanomsg server socket
|
||||
@@ -129,6 +132,12 @@ void *handle_upstream()
|
||||
sock = nn_socket( AF_SP, NN_PULL );
|
||||
if(sock >= 0)
|
||||
{
|
||||
int t = NANO_SOCKET_RCV_TIMEOUT_MS;
|
||||
int rc = nn_setsockopt(sock, NN_SOL_SOCKET, NN_RCVTIMEO, &t, sizeof(t));
|
||||
if (rc < 0)
|
||||
{
|
||||
ParodusError ("Unable to set socket receive timeout (errno=%d, %s)\n",errno, strerror(errno));
|
||||
}
|
||||
ParodusPrint("Nanomsg bind with get_parodus_cfg()->local_url %s\n", get_parodus_cfg()->local_url);
|
||||
bind = nn_bind(sock, get_parodus_cfg()->local_url);
|
||||
if(bind < 0)
|
||||
@@ -137,11 +146,18 @@ void *handle_upstream()
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusInfo("nanomsg server gone into the listening mode...\n");
|
||||
while( FOREVER() )
|
||||
{
|
||||
buf = NULL;
|
||||
ParodusInfo("nanomsg server gone into the listening mode...\n");
|
||||
bytes = nn_recv (sock, &buf, NN_MSG, 0);
|
||||
if (g_shutdown)
|
||||
break;
|
||||
if (bytes < 0) {
|
||||
if ((errno != EAGAIN) && (errno != ETIMEDOUT))
|
||||
ParodusInfo ("Error (%d) receiving message from nanomsg client\n", errno);
|
||||
continue;
|
||||
}
|
||||
ParodusInfo ("Upstream message received from nanomsg client\n");
|
||||
message = (UpStreamMsg *)malloc(sizeof(UpStreamMsg));
|
||||
|
||||
@@ -177,6 +193,16 @@ void *handle_upstream()
|
||||
ParodusError("failure in allocation for message\n");
|
||||
}
|
||||
}
|
||||
if(nn_shutdown(sock, bind) < 0)
|
||||
{
|
||||
ParodusError ("nn_shutdown bind socket=%d endpt=%d, err=%d\n",
|
||||
sock, bind, errno);
|
||||
}
|
||||
if (nn_close (sock) < 0)
|
||||
{
|
||||
ParodusError ("nn_close bind socket=%d err=%d\n",
|
||||
sock, errno);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -197,11 +223,10 @@ void *processUpstreamMessage()
|
||||
reg_list_item_t *temp = NULL;
|
||||
int matchFlag = 0;
|
||||
int status = -1;
|
||||
char *serviceName = NULL;
|
||||
char *macId = NULL;
|
||||
char *destService, *destApplication =NULL;
|
||||
char *sourceService, *sourceApplication =NULL;
|
||||
int sendStatus =-1;
|
||||
char *device_id = NULL;
|
||||
size_t device_id_len = 0;
|
||||
size_t parodus_len;
|
||||
int ret = -1;
|
||||
|
||||
while(FOREVER())
|
||||
{
|
||||
@@ -222,34 +247,40 @@ void *processUpstreamMessage()
|
||||
if(rv > 0)
|
||||
{
|
||||
msgType = msg->msg_type;
|
||||
if(msgType == 9)
|
||||
if(msgType == WRP_MSG_TYPE__SVC_REGISTRATION)
|
||||
{
|
||||
ParodusInfo("\n Nanomsg client Registration for Upstream\n");
|
||||
//Extract serviceName and url & store it in a linked list for reg_clients
|
||||
temp = get_global_node();
|
||||
if(get_numOfClients() !=0)
|
||||
{
|
||||
matchFlag = 0;
|
||||
ParodusPrint("matchFlag reset to %d\n", matchFlag);
|
||||
temp = get_global_node();
|
||||
while(temp!=NULL)
|
||||
{
|
||||
if(strcmp(temp->service_name, msg->u.reg.service_name)==0)
|
||||
{
|
||||
ParodusInfo("match found, client is already registered\n");
|
||||
parStrncpy(temp->url,msg->u.reg.url, sizeof(temp->url));
|
||||
if(nn_shutdown(temp->sock, 0) < 0)
|
||||
if(nn_shutdown(temp->sock, temp->endpoint) < 0)
|
||||
{
|
||||
ParodusError ("Failed to shutdown\n");
|
||||
ParodusError ("nn_shutdown socket=%d endpt=%d, err=%d\n",
|
||||
temp->sock, temp->endpoint, errno);
|
||||
}
|
||||
if (nn_close (temp->sock) < 0)
|
||||
{
|
||||
ParodusError ("nn_close socket=%d err=%d\n",
|
||||
temp->sock, errno);
|
||||
}
|
||||
|
||||
temp->sock = nn_socket(AF_SP,NN_PUSH );
|
||||
if(temp->sock >= 0)
|
||||
{
|
||||
int t = NANOMSG_SOCKET_TIMEOUT_MSEC;
|
||||
int t = NANO_SOCKET_SEND_TIMEOUT_MS;
|
||||
rc = nn_setsockopt(temp->sock, NN_SOL_SOCKET, NN_SNDTIMEO, &t, sizeof(t));
|
||||
if(rc < 0)
|
||||
{
|
||||
ParodusError ("Unable to set socket timeout (errno=%d, %s)\n",errno, strerror(errno));
|
||||
ParodusError ("Unable to set socket send timeout (errno=%d, %s)\n",errno, strerror(errno));
|
||||
}
|
||||
rc = nn_connect(temp->sock, msg->u.reg.url);
|
||||
if(rc < 0)
|
||||
@@ -258,7 +289,8 @@ void *processUpstreamMessage()
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusInfo("Client registered before. Sending acknowledgement \n");
|
||||
temp->endpoint = rc;
|
||||
ParodusInfo("Client registered before. Sending ack on socket %d\n", temp->sock);
|
||||
status =sendAuthStatus(temp);
|
||||
|
||||
if(status == 0)
|
||||
@@ -289,16 +321,22 @@ void *processUpstreamMessage()
|
||||
ParodusPrint("sent auth status to reg client\n");
|
||||
}
|
||||
}
|
||||
release_global_node ();
|
||||
}
|
||||
else if(msgType == WRP_MSG_TYPE__EVENT)
|
||||
{
|
||||
ParodusInfo(" Received upstream event data: dest '%s'\n", msg->u.event.dest);
|
||||
(msg->u.event.headers != NULL && msg->u.event.headers->headers[0] != NULL && msg->u.event.headers->headers[1] != NULL) ? ParodusInfo(" Received upstream event data: dest '%s' traceParent: %s traceState: %s\n", msg->u.event.dest, msg->u.event.headers->headers[0], msg->u.event.headers->headers[1]) : ParodusInfo(" Received upstream event data: dest '%s'\n", msg->u.event.dest);
|
||||
if(msg->u.event.transaction_uuid != NULL) {
|
||||
ParodusInfo("transaction_uuid in event: %s\n", msg->u.event.transaction_uuid);
|
||||
}
|
||||
partners_t *partnersList = NULL;
|
||||
int j = 0;
|
||||
|
||||
int ret = validate_partner_id(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 = msgType;
|
||||
eventMsg->u.event.content_type=msg->u.event.content_type;
|
||||
eventMsg->u.event.source=msg->u.event.source;
|
||||
@@ -308,6 +346,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)
|
||||
@@ -322,106 +369,107 @@ void *processUpstreamMessage()
|
||||
{
|
||||
sendUpstreamMsgToServer(&message->msg, message->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;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Sending to server for msgTypes 3, 5, 6, 7, 8.
|
||||
if( WRP_MSG_TYPE__REQ == msgType )
|
||||
{
|
||||
ParodusInfo(" Received upstream data with MsgType: %d dest: '%s' transaction_uuid: %s\n", msgType, msg->u.req.dest, msg->u.req.transaction_uuid );
|
||||
(msg->u.req.headers != NULL && msg->u.req.headers->headers[0] != NULL && msg->u.req.headers->headers[1] != NULL) ? ParodusInfo(" Received upstream data with MsgType: %d dest: '%s' transaction_uuid: %s traceParent: %s traceState: %s\n", msgType, msg->u.req.dest, msg->u.req.transaction_uuid, msg->u.req.headers->headers[0], msg->u.req.headers->headers[1]) : ParodusInfo(" Received upstream data with MsgType: %d dest: '%s' transaction_uuid: %s\n", msgType, msg->u.req.dest, msg->u.req.transaction_uuid);
|
||||
sendUpstreamMsgToServer(&message->msg, message->len);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusInfo(" Received upstream data with MsgType: %d dest: '%s' transaction_uuid: %s status: %d\n",msgType, msg->u.crud.dest, msg->u.crud.transaction_uuid, msg->u.crud.status );
|
||||
if(WRP_MSG_TYPE__RETREIVE == msgType && msg->u.crud.dest !=NULL && msg->u.crud.source != NULL)
|
||||
if(WRP_MSG_TYPE__RETREIVE == msgType)
|
||||
{
|
||||
macId = wrp_get_msg_element(WRP_ID_ELEMENT__ID, msg, DEST);
|
||||
destService = wrp_get_msg_element(WRP_ID_ELEMENT__SERVICE, msg, DEST);
|
||||
destApplication = wrp_get_msg_element(WRP_ID_ELEMENT__APPLICATION, msg, DEST);
|
||||
sourceService = wrp_get_msg_element(WRP_ID_ELEMENT__SERVICE, msg, SOURCE);
|
||||
sourceApplication = wrp_get_msg_element(WRP_ID_ELEMENT__APPLICATION, msg, SOURCE);
|
||||
/* Handle cloud-status retrieve request here
|
||||
Expecting dest format as mac:xxxxxxxxxxxx/parodus/cloud-status
|
||||
Parse dest field and check destService is "parodus" and destApplication is "cloud-status"
|
||||
*/
|
||||
if(macId != NULL)
|
||||
{
|
||||
if(destService != NULL && destApplication != NULL && strcmp(destService,"parodus")== 0 && strcmp(destApplication,"cloud-status")== 0)
|
||||
ret = getDeviceId(&device_id, &device_id_len);
|
||||
if(ret == 0)
|
||||
{
|
||||
retrieve_msg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(retrieve_msg, 0, sizeof(wrp_msg_t));
|
||||
retrieve_msg->msg_type = msg->msg_type;
|
||||
retrieve_msg->u.crud.transaction_uuid = strdup(msg->u.crud.transaction_uuid);
|
||||
retrieve_msg->u.crud.source = strdup(msg->u.crud.source);
|
||||
retrieve_msg->u.crud.dest = strdup(msg->u.crud.dest);
|
||||
addCRUDmsgToQueue(retrieve_msg);
|
||||
}
|
||||
else if(sourceService != NULL && sourceApplication != NULL && strcmp(sourceService,"parodus")== 0 && strcmp(sourceApplication,"cloud-status")== 0 && strncmp(msg->u.crud.dest,"mac:", 4)==0)
|
||||
{
|
||||
/* Handle cloud-status retrieve response here to send it to registered client
|
||||
Expecting src format as mac:xxxxxxxxxxxx/parodus/cloud-status and dest as mac:
|
||||
Parse src field and check sourceService is "parodus" and sourceApplication is "cloud-status"
|
||||
*/
|
||||
serviceName = wrp_get_msg_element(WRP_ID_ELEMENT__SERVICE, msg, DEST);
|
||||
if ( serviceName != NULL)
|
||||
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) )
|
||||
{
|
||||
//Send Client cloud-status response back to registered client
|
||||
ParodusInfo("Sending cloud-status response to %s client\n",serviceName);
|
||||
sendStatus=sendMsgtoRegisteredClients(serviceName,(const char **)&message->msg,message->len);
|
||||
if(sendStatus ==1)
|
||||
/* For this device. */
|
||||
parodus_len = strlen( PARODUS_SERVICE_NAME );
|
||||
if( 0 == strncmp(PARODUS_SERVICE_NAME, &msg->u.crud.dest[device_id_len], parodus_len-1) )
|
||||
{
|
||||
ParodusInfo("Send upstreamMsg successfully to registered client %s\n", serviceName);
|
||||
/* For Parodus CRUD queue. */
|
||||
ParodusInfo("Create RetrieveMsg and add to parodus CRUD queue\n");
|
||||
createUpstreamRetrieveMsg(msg, &retrieve_msg);
|
||||
addCRUDmsgToQueue(retrieve_msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Failed to send upstreamMsg to registered client %s\n", serviceName);
|
||||
/* For nanomsg clients. */
|
||||
getServiceNameAndSendResponse(msg, &message->msg, message->len);
|
||||
}
|
||||
free(serviceName);
|
||||
serviceName = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("serviceName is NULL,not sending cloud-status response to client\n");
|
||||
/* 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__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("MAC is null, not handling retrieve wrp message \n");
|
||||
ParodusError("Failed to get device_id\n");
|
||||
}
|
||||
if(sourceService !=NULL)
|
||||
{
|
||||
free(sourceService);
|
||||
sourceService = NULL;
|
||||
}
|
||||
if(sourceApplication !=NULL)
|
||||
{
|
||||
free(sourceApplication);
|
||||
sourceApplication = NULL;
|
||||
}
|
||||
if(destService !=NULL)
|
||||
{
|
||||
free(destService);
|
||||
destService = NULL;
|
||||
}
|
||||
if(destApplication !=NULL)
|
||||
{
|
||||
free(destApplication);
|
||||
destApplication = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
else if (WRP_MSG_TYPE__SVC_ALIVE != msgType) {
|
||||
/* Don't reply to service alive message */
|
||||
sendUpstreamMsgToServer(&message->msg, message->len);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -450,6 +498,10 @@ void *processUpstreamMessage()
|
||||
}
|
||||
else
|
||||
{
|
||||
if (g_shutdown) {
|
||||
pthread_mutex_unlock (&nano_mut);
|
||||
break;
|
||||
}
|
||||
ParodusPrint("Before pthread cond wait in consumer thread\n");
|
||||
pthread_cond_wait(&nano_con, &nano_mut);
|
||||
pthread_mutex_unlock (&nano_mut);
|
||||
@@ -459,11 +511,113 @@ void *processUpstreamMessage()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void sendUpstreamMsgToServer(void **resp_bytes, size_t resp_size)
|
||||
/**
|
||||
* @brief getDeviceId function to create deviceId in the format "mac:112233445xxx"
|
||||
*
|
||||
* @param[out] device_id in the format "mac:112233445xxx"
|
||||
* @param[out] total size of device_id
|
||||
*/
|
||||
int getDeviceId(char **device_id, size_t *device_id_len)
|
||||
{
|
||||
char *deviceID = NULL;
|
||||
size_t len;
|
||||
|
||||
if((get_parodus_cfg()->hw_mac !=NULL) && (strlen(get_parodus_cfg()->hw_mac)!=0))
|
||||
{
|
||||
len = strlen(get_parodus_cfg()->hw_mac) + 5;
|
||||
|
||||
deviceID = (char *) malloc(sizeof(char)*64);
|
||||
if(deviceID != NULL)
|
||||
{
|
||||
snprintf(deviceID, len, "mac:%s", get_parodus_cfg()->hw_mac);
|
||||
*device_id = deviceID;
|
||||
*device_id_len = len;
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("device_id allocation failed\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("device mac is NULL\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief createUpstreamRetrieveMsg function to create new message for processing Retrieve requests
|
||||
*
|
||||
* @param[in] message The upstream message received from cloud or internal clients
|
||||
* @param[out] retrieve_msg New message for processing Retrieve requests
|
||||
*/
|
||||
void createUpstreamRetrieveMsg(wrp_msg_t *message, wrp_msg_t **retrieve_msg)
|
||||
{
|
||||
wrp_msg_t *msg;
|
||||
msg = ( wrp_msg_t * ) malloc( sizeof( wrp_msg_t ) );
|
||||
if(msg != NULL)
|
||||
{
|
||||
memset(msg, 0, sizeof(wrp_msg_t));
|
||||
|
||||
msg->msg_type = message->msg_type;
|
||||
if(message->u.crud.transaction_uuid != NULL)
|
||||
{
|
||||
msg->u.crud.transaction_uuid = strdup(message->u.crud.transaction_uuid);
|
||||
}
|
||||
if(message->u.crud.source !=NULL)
|
||||
{
|
||||
msg->u.crud.source = strdup(message->u.crud.source);
|
||||
}
|
||||
if(message->u.crud.dest != NULL)
|
||||
{
|
||||
msg->u.crud.dest = strdup(message->u.crud.dest);
|
||||
}
|
||||
*retrieve_msg = msg;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief getServiceNameAndSendResponse function to fetch client service name and to send msg to it.
|
||||
*
|
||||
* @param[in] msg The decoded message to fetch client service name from its dest field
|
||||
* @param[in] msg_bytes The encoded upstream msg to be sent to client
|
||||
* @param[in] msg_size Total size of the msg to send to client
|
||||
*/
|
||||
void getServiceNameAndSendResponse(wrp_msg_t *msg, void **msg_bytes, size_t msg_size)
|
||||
{
|
||||
char *serviceName = NULL;
|
||||
int sendStatus =-1;
|
||||
|
||||
serviceName = wrp_get_msg_element(WRP_ID_ELEMENT__SERVICE, msg, DEST);
|
||||
if ( serviceName != NULL)
|
||||
{
|
||||
sendStatus=sendMsgtoRegisteredClients(serviceName,(const char **)msg_bytes, msg_size);
|
||||
if(sendStatus ==1)
|
||||
{
|
||||
ParodusInfo("Send upstreamMsg successfully to registered client %s\n", serviceName);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Failed to send upstreamMsg to registered client %s\n", serviceName);
|
||||
}
|
||||
free(serviceName);
|
||||
serviceName = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("serviceName is NULL,not sending retrieve response to client\n");
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -478,11 +632,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;
|
||||
@@ -490,6 +646,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,12 +47,19 @@ typedef struct UpStreamMsg__
|
||||
void packMetaData();
|
||||
void *handle_upstream();
|
||||
void *processUpstreamMessage();
|
||||
|
||||
void sendUpstreamMsgToServer(void **resp_bytes, size_t resp_size);
|
||||
void registerRBUSlistener();
|
||||
int getDeviceId(char **device_id, size_t *device_id_len);
|
||||
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);
|
||||
void clear_metadata();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
243
src/upstream_rbus.c
Normal file
243
src/upstream_rbus.c
Normal file
@@ -0,0 +1,243 @@
|
||||
/**
|
||||
* 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"
|
||||
#include "close_retry.h"
|
||||
#include "connection.h"
|
||||
#include "heartBeat.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;
|
||||
}
|
||||
|
||||
/* Enables rbus ERROR level logs in parodus. Modify RBUS_LOG_ERROR check if more debug logs are needed from rbus. */
|
||||
void rbus_log_handler(
|
||||
rbusLogLevel level,
|
||||
const char* file,
|
||||
int line,
|
||||
int threadId,
|
||||
char* message)
|
||||
{
|
||||
ParodusPrint("threadId %d\n", threadId);
|
||||
const char* slevel = "";
|
||||
|
||||
if(level < RBUS_LOG_ERROR)
|
||||
return;
|
||||
|
||||
switch(level)
|
||||
{
|
||||
case RBUS_LOG_DEBUG: slevel = "DEBUG"; break;
|
||||
case RBUS_LOG_INFO: slevel = "INFO"; break;
|
||||
case RBUS_LOG_WARN: slevel = "WARN"; break;
|
||||
case RBUS_LOG_ERROR: slevel = "ERROR"; break;
|
||||
case RBUS_LOG_FATAL: slevel = "FATAL"; break;
|
||||
}
|
||||
ParodusInfo("%5s %s:%d -- %s\n", slevel, file, line, message);
|
||||
}
|
||||
|
||||
void registerRbusLogger()
|
||||
{
|
||||
rbus_registerLogHandler(rbus_log_handler);
|
||||
ParodusPrint("Registered rbus log handler\n");
|
||||
}
|
||||
|
||||
#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;
|
||||
ParodusInfo("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);
|
||||
}
|
||||
else {
|
||||
ParodusError("newValue is NULL\n");
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// If interface is already down then reset it and reconnect cloud conn as wan failover event is received
|
||||
if(get_interface_down_event())
|
||||
{
|
||||
reset_interface_down_event();
|
||||
ParodusInfo("Interface_down_event is reset\n");
|
||||
resume_heartBeatTimer();
|
||||
}
|
||||
// Close cloud conn and reconnect with the new interface as wan failover event is received
|
||||
set_global_reconnect_reason("WAN_FAILOVER");
|
||||
set_global_reconnect_status(true);
|
||||
set_close_retry();
|
||||
|
||||
}
|
||||
else {
|
||||
if(oldValue == NULL) {
|
||||
ParodusError("oldValue is NULL\n");
|
||||
}
|
||||
if(interface == NULL) {
|
||||
ParodusError("interface is NULL\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
1771
src/xmidtsend_rbus.c
Normal file
1771
src/xmidtsend_rbus.c
Normal file
File diff suppressed because it is too large
Load Diff
127
src/xmidtsend_rbus.h
Normal file
127
src/xmidtsend_rbus.h
Normal file
@@ -0,0 +1,127 @@
|
||||
/**
|
||||
* 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 "config.h"
|
||||
#include <uuid/uuid.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define XMIDT_SEND_METHOD "Device.X_RDK_Xmidt.SendData"
|
||||
#define INPARAMS_PATH "/tmp/inparams.txt"
|
||||
|
||||
#define CLOUD_ACK_TIMEOUT_SEC 7
|
||||
#define CRITICAL_QOS_EXPIRE_TIME 30*60
|
||||
#define HIGH_QOS_EXPIRE_TIME 25*60
|
||||
#define MEDIUM_QOS_EXPIRE_TIME 20*60
|
||||
#define LOW_QOS_EXPIRE_TIME 15*60
|
||||
|
||||
#define EXPIRY_CHECK_TIME 5*60 //To check expiry in every 5 mins when cloud connection is down.
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Data Structures */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
typedef struct XmidtMsg__
|
||||
{
|
||||
wrp_msg_t *msg;
|
||||
rbusMethodAsyncHandle_t asyncHandle;
|
||||
int state;
|
||||
long long enqueueTime;
|
||||
long long sentTime;
|
||||
struct XmidtMsg__ *next;
|
||||
} XmidtMsg;
|
||||
|
||||
typedef struct CloudAck__
|
||||
{
|
||||
char *transaction_id;
|
||||
int qos;
|
||||
int rdr;
|
||||
char *source;
|
||||
struct CloudAck__ *next;
|
||||
} CloudAck;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DELIVERED_SUCCESS = 0,
|
||||
INVALID_MSG_TYPE,
|
||||
MISSING_SOURCE,
|
||||
MISSING_DEST,
|
||||
MISSING_CONTENT_TYPE,
|
||||
MISSING_PAYLOAD,
|
||||
MISSING_PAYLOADLEN,
|
||||
INVALID_CONTENT_TYPE,
|
||||
ENQUEUE_FAILURE = 100,
|
||||
CLIENT_DISCONNECT = 101,
|
||||
QUEUE_SIZE_EXCEEDED = 102,
|
||||
WRP_ENCODE_FAILURE = 103,
|
||||
MSG_PROCESSING_FAILED = 104,
|
||||
QOS_SEMANTICS_DISABLED = 105,
|
||||
MSG_EXPIRED = 106,
|
||||
QUEUE_OPTIMIZED = 107
|
||||
} XMIDT_STATUS;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PENDING = 0,
|
||||
SENT,
|
||||
DELETE
|
||||
} MSG_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(XmidtMsg *Datanode, wrp_msg_t * msg, rbusMethodAsyncHandle_t asyncHandle);
|
||||
int sendXmidtEventToServer(XmidtMsg *msgnode, 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, char *cloudsource, rbusError_t error);
|
||||
int validateXmidtData(wrp_msg_t * eventMsg, char **errorMsg, int *statusCode);
|
||||
void printSendMsgData(char* status, int qos, char* dest, char* transaction_uuid);
|
||||
bool highQosValueCheck(int qos);
|
||||
void waitTillConnectionIsUp();
|
||||
void printRBUSParams(rbusObject_t params, char* file_path);
|
||||
void addToCloudAckQ(char *transaction_id, int qos, int rdr, char *source);
|
||||
int checkCloudACK(XmidtMsg *xmdnode, rbusMethodAsyncHandle_t asyncHandle);
|
||||
int updateXmidtState(XmidtMsg * temp, int state);
|
||||
void print_xmidMsg_list();
|
||||
int deleteCloudACKNode(char* trans_id);
|
||||
int deleteFromXmidtQ(XmidtMsg **next_node);
|
||||
int checkCloudConn();
|
||||
void checkMaxQandOptimize(XmidtMsg *xmdMsg);
|
||||
void checkMsgExpiry(XmidtMsg *xmdMsg);
|
||||
void mapXmidtStatusToStatusMessage(int status, char **message);
|
||||
int xmidtQOptmize();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _XMIDTSEND_RBUS_H_ */
|
||||
|
||||
@@ -16,7 +16,9 @@ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -W -g -fprofile-arcs -ftest-coverage
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST ")
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W -g -fprofile-arcs -ftest-coverage -O0")
|
||||
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -O0")
|
||||
set (PARODUS_COMMON_SRC ../src/string_helpers.c ../src/mutex.c ../src/time.c ../src/config.c ../src/spin_thread.c ../src/token.c)
|
||||
set (PARODUS_COMMON_SRC ../src/string_helpers.c ../src/mutex.c
|
||||
../src/time.c ../src/config.c ../src/spin_thread.c
|
||||
../src/event_handler.c ../src/token.c)
|
||||
set (PARODUS_COMMON_LIBS gcov -lcunit -lcimplog -lwrp-c
|
||||
-luuid -lmsgpackc -lnopoll -lnanomsg -lpthread
|
||||
-Wl,--no-as-needed -lcjson -lcjwt -ltrower-base64
|
||||
@@ -30,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)
|
||||
endif (ENABLE_WEBCFGBIN)
|
||||
|
||||
if(NOT DISABLE_VALGRIND)
|
||||
set (MEMORY_CHECK valgrind --leak-check=full --show-reachable=yes -v)
|
||||
endif ()
|
||||
@@ -40,7 +46,7 @@ link_directories ( ${LIBRARY_DIR} )
|
||||
# test_heartBeatTimer
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_heartBeatTimer COMMAND ${MEMORY_CHECK} ./test_heartBeatTimer)
|
||||
add_executable(test_heartBeatTimer test_heartBeatTimer.c ../src/heartBeat.c)
|
||||
add_executable(test_heartBeatTimer test_heartBeatTimer.c ../src/heartBeat.c ../src/time.c)
|
||||
target_link_libraries (test_heartBeatTimer ${PARODUS_COMMON_LIBS} -lcmocka)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -55,7 +61,10 @@ target_link_libraries (test_close_retry ${PARODUS_COMMON_LIBS} -lcmocka)
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_mutex COMMAND ${MEMORY_CHECK} ./test_mutex)
|
||||
add_executable(test_mutex test_mutex.c ../src/mutex.c)
|
||||
target_link_libraries (test_mutex ${PARODUS_COMMON_LIBS} -lcmocka)
|
||||
target_link_libraries (test_mutex gcov -lcunit -lcimplog -lwrp-c
|
||||
-luuid -lmsgpackc -lnopoll -lnanomsg -lpthread
|
||||
-Wl,--no-as-needed -lcjson -lcjwt -ltrower-base64
|
||||
-lssl -lcrypto -lrt -lm -lcmocka)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_networking
|
||||
@@ -68,8 +77,8 @@ target_link_libraries (test_networking ${PARODUS_COMMON_LIBS})
|
||||
# test_nopoll_helpers
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_nopoll_helpers COMMAND ${MEMORY_CHECK} ./test_nopoll_helpers)
|
||||
add_executable(test_nopoll_helpers test_nopoll_helpers.c ../src/nopoll_helpers.c)
|
||||
target_link_libraries (test_nopoll_helpers -Wl,--no-as-needed -lrt -lcmocka -lcimplog -lnopoll)
|
||||
add_executable(test_nopoll_helpers test_nopoll_helpers.c ../src/nopoll_helpers.c ../src/string_helpers.c ../src/config.c)
|
||||
target_link_libraries (test_nopoll_helpers -Wl,--no-as-needed -lrt -lcmocka -lcimplog -lnopoll ${PARODUS_COMMON_LIBS})
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_time
|
||||
@@ -88,22 +97,22 @@ 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
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_nopoll_handlers COMMAND ${MEMORY_CHECK} ./test_nopoll_handlers)
|
||||
add_executable(test_nopoll_handlers test_nopoll_handlers.c ../src/nopoll_handlers.c ../src/heartBeat.c ../src/close_retry.c)
|
||||
add_executable(test_nopoll_handlers test_nopoll_handlers.c ../src/nopoll_handlers.c ../src/heartBeat.c ../src/close_retry.c ../src/time.c)
|
||||
target_link_libraries (test_nopoll_handlers -lnopoll -lcunit -lcimplog -Wl,--no-as-needed -lrt -lpthread -lm)
|
||||
|
||||
|
||||
@@ -111,7 +120,7 @@ target_link_libraries (test_nopoll_handlers -lnopoll -lcunit -lcimplog -Wl,--no-
|
||||
# test_nopoll_handlers_fragment
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_nopoll_handlers_fragment COMMAND ${MEMORY_CHECK} ./test_nopoll_handlers_fragment)
|
||||
add_executable(test_nopoll_handlers_fragment test_nopoll_handlers_fragment.c ../src/nopoll_handlers.c ../src/heartBeat.c ../src/close_retry.c)
|
||||
add_executable(test_nopoll_handlers_fragment test_nopoll_handlers_fragment.c ../src/nopoll_handlers.c ../src/heartBeat.c ../src/close_retry.c ../src/time.c)
|
||||
target_link_libraries (test_nopoll_handlers_fragment -lnopoll -lcunit -lcimplog -Wl,--no-as-needed -lrt -lpthread -lm -lcmocka)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -120,10 +129,10 @@ target_link_libraries (test_nopoll_handlers_fragment -lnopoll -lcunit -lcimplog
|
||||
add_test(NAME test_connection COMMAND ${MEMORY_CHECK} ./test_connection)
|
||||
set (CONN_SRC ../src/connection.c
|
||||
../src/string_helpers.c ../src/mutex.c ../src/time.c
|
||||
../src/config.c ../src/spin_thread.c ../src/heartBeat.c ../src/close_retry.c)
|
||||
../src/config.c ../src/auth_token.c ../src/spin_thread.c ../src/heartBeat.c ../src/close_retry.c)
|
||||
#set(CONN_SRC ../src/connection.c ${PARODUS_COMMON_SRC})
|
||||
add_executable(test_connection test_connection.c ${CONN_SRC})
|
||||
target_link_libraries (test_connection ${PARODUS_COMMON_LIBS} -lcmocka)
|
||||
target_link_libraries (test_connection ${PARODUS_COMMON_LIBS} -lcmocka -lcurl -luuid)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_connection - function createNopollConnection
|
||||
@@ -141,7 +150,7 @@ target_link_libraries (test_connection ${PARODUS_COMMON_LIBS} -lcmocka)
|
||||
add_test(NAME test_client_list COMMAND ${MEMORY_CHECK} ./test_client_list)
|
||||
#add_executable(test_client_list test_client_list.c ../src/client_list.c ../src/service_alive.c ../src/upstream.c ../src/networking.c ../src/nopoll_helpers.c ../src/downstream.c ../src/connection.c ../src/nopoll_handlers.c ../src/ParodusInternal.c ../src/thread_tasks.c ../src/conn_interface.c ../src/partners_check.c ${PARODUS_COMMON_SRC})
|
||||
#target_link_libraries (test_client_list ${PARODUS_COMMON_LIBS})
|
||||
set(CLIST_SRC test_client_list.c ../src/client_list.c
|
||||
set(CLIST_SRC test_client_list.c ../src/client_list.c ../src/auth_token.c
|
||||
../src/service_alive.c ../src/upstream.c ../src/networking.c ../src/nopoll_helpers.c
|
||||
../src/downstream.c ../src/connection.c ../src/nopoll_handlers.c ../src/heartBeat.c ../src/close_retry.c
|
||||
../src/ParodusInternal.c ../src/thread_tasks.c ../src/conn_interface.c
|
||||
@@ -152,10 +161,14 @@ 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})
|
||||
target_link_libraries (test_client_list ${PARODUS_COMMON_LIBS} -lcurl -luuid)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_service_alive
|
||||
@@ -163,25 +176,49 @@ target_link_libraries (test_client_list ${PARODUS_COMMON_LIBS})
|
||||
add_test(NAME test_service_alive COMMAND ${MEMORY_CHECK} ./test_service_alive)
|
||||
#add_executable(test_service_alive test_service_alive.c ../src/client_list.c ../src/service_alive.c ../src/upstream.c ../src/networking.c ../src/nopoll_helpers.c ../src/nopoll_handlers.c ../src/config.c ../src/connection.c ../src/ParodusInternal.c ../src/downstream.c ../src/thread_tasks.c ../src/conn_interface.c ../src/partners_check.c ${PARODUS_COMMON_SRC})
|
||||
#target_link_libraries (test_service_alive ${PARODUS_COMMON_LIBS})
|
||||
set(SVA_SRC test_service_alive.c ../src/client_list.c ../src/service_alive.c ../src/upstream.c ../src/networking.c ../src/nopoll_helpers.c ../src/nopoll_handlers.c ../src/config.c ../src/connection.c ../src/ParodusInternal.c ../src/downstream.c ../src/thread_tasks.c ../src/conn_interface.c ../src/partners_check.c ../src/heartBeat.c ../src/close_retry.c ${PARODUS_COMMON_SRC})
|
||||
set(SVA_SRC test_service_alive.c ../src/client_list.c ../src/service_alive.c ../src/auth_token.c ../src/upstream.c ../src/networking.c ../src/nopoll_helpers.c ../src/nopoll_handlers.c ../src/config.c ../src/connection.c ../src/ParodusInternal.c ../src/downstream.c ../src/thread_tasks.c ../src/conn_interface.c ../src/partners_check.c ../src/heartBeat.c ../src/close_retry.c ${PARODUS_COMMON_SRC})
|
||||
if (ENABLE_SESHAT)
|
||||
set(SVA_SRC ${SVA_SRC} ../src/seshat_interface.c)
|
||||
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})
|
||||
target_link_libraries (test_service_alive ${PARODUS_COMMON_LIBS} -lcurl -luuid)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_config
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_config COMMAND ${MEMORY_CHECK} ./test_config)
|
||||
add_executable(test_config test_config.c ../src/config.c ../src/string_helpers.c)
|
||||
add_executable(test_config test_config.c ../src/config.c ../src/auth_token.c ../src/string_helpers.c)
|
||||
target_link_libraries (test_config -lcmocka
|
||||
-Wl,--no-as-needed -lcimplog
|
||||
-lcjson -lcjwt -ltrower-base64 -lssl -lcrypto -lrt -lm
|
||||
-lcjson -lcjwt -ltrower-base64 -lssl -lcrypto -lrt -lm -lcurl -luuid
|
||||
)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_auth_token
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_auth_token COMMAND ${MEMORY_CHECK} ./test_auth_token)
|
||||
add_executable(test_auth_token test_auth_token.c ../src/config.c ../src/auth_token.c ../src/string_helpers.c)
|
||||
target_link_libraries (test_auth_token -lcmocka
|
||||
-Wl,--no-as-needed -lcimplog
|
||||
-lcjson -lcjwt -ltrower-base64 -lssl -lcrypto -lrt -lm -lcurl -luuid
|
||||
)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_auth_token_more
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_auth_token_more COMMAND ${MEMORY_CHECK} ./test_auth_token_more)
|
||||
add_executable(test_auth_token_more test_auth_token_more.c ../src/config.c ../src/auth_token.c ../src/string_helpers.c ../src/config.c)
|
||||
target_link_libraries (test_auth_token_more -lcmocka
|
||||
-Wl,--no-as-needed -lcimplog
|
||||
-lcjson -lcjwt -ltrower-base64 -lssl -lcrypto -lrt -lm -lcurl -luuid
|
||||
)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -202,8 +239,9 @@ target_link_libraries (test_crud_tasks -lcmocka ${PARODUS_COMMON_LIBS} )
|
||||
# test_crud_internal
|
||||
#-------------------------------------------------------------------------------
|
||||
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/string_helpers.c ../src/crud_internal.c )
|
||||
target_link_libraries (test_crud_internal -lcmocka ${PARODUS_COMMON_LIBS} )
|
||||
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/client_list.c)
|
||||
target_link_libraries (test_crud_internal -lcmocka ${PARODUS_COMMON_LIBS} -lcurl -luuid)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_upstream
|
||||
@@ -213,13 +251,24 @@ 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 -lnanomsg)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_upstream_sock
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_upstream_sock COMMAND ${MEMORY_CHECK} ./test_upstream_sock)
|
||||
add_executable(test_upstream_sock test_upstream_sock.c ../src/upstream.c
|
||||
../src/client_list.c ../src/close_retry.c ../src/string_helpers.c)
|
||||
target_link_libraries (test_upstream_sock -lcmocka gcov -lcunit -lcimplog
|
||||
-lwrp-c -luuid -lpthread -lmsgpackc -lnopoll -lnanomsg
|
||||
-Wl,--no-as-needed -lcjson -lcjwt -ltrower-base64
|
||||
-lssl -lcrypto -lrt -lm)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_downstream
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_downstream COMMAND ${MEMORY_CHECK} ./test_downstream)
|
||||
add_executable(test_downstream test_downstream.c ../src/downstream.c ../src/string_helpers.c)
|
||||
add_executable(test_downstream test_downstream.c ../src/downstream.c ../src/string_helpers.c ../src/config.c)
|
||||
target_link_libraries (test_downstream -lcmocka gcov -lcunit -lcimplog
|
||||
-lwrp-c -luuid -lpthread -lmsgpackc -lnopoll
|
||||
-Wl,--no-as-needed -lcjson -lcjwt -ltrower-base64
|
||||
@@ -229,7 +278,7 @@ target_link_libraries (test_downstream -lcmocka gcov -lcunit -lcimplog
|
||||
# test_downstream_more
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_downstream_more COMMAND ${MEMORY_CHECK} ./test_downstream_more)
|
||||
add_executable(test_downstream_more test_downstream_more.c ../src/downstream.c ../src/string_helpers.c)
|
||||
add_executable(test_downstream_more test_downstream_more.c ../src/downstream.c ../src/string_helpers.c ../src/config.c)
|
||||
target_link_libraries (test_downstream_more -lcmocka ${PARODUS_COMMON_LIBS} )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -250,23 +299,29 @@ set(CONIFC_SRC test_conn_interface.c
|
||||
../src/token.c
|
||||
../src/string_helpers.c
|
||||
../src/mutex.c
|
||||
../src/time.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} )
|
||||
target_link_libraries (test_conn_interface -lcmocka ${PARODUS_COMMON_LIBS} -lcurl -luuid )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_ParodusInternal
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_ParodusInternal COMMAND ${MEMORY_CHECK} ./test_ParodusInternal)
|
||||
add_executable(test_ParodusInternal test_ParodusInternal.c ../src/ParodusInternal.c ../src/config.c ../src/string_helpers.c)
|
||||
target_link_libraries (test_ParodusInternal -lcmocka ${PARODUS_COMMON_LIBS} )
|
||||
target_link_libraries (test_ParodusInternal -lcmocka ${PARODUS_COMMON_LIBS} -lcurl -luuid)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_partners_check
|
||||
@@ -285,11 +340,11 @@ set(TOKEN_SRC ../src/conn_interface.c ../src/config.c
|
||||
../src/nopoll_handlers.c ../src/nopoll_helpers.c
|
||||
../src/partners_check.c ../src/ParodusInternal.c
|
||||
../src/upstream.c ../src/downstream.c
|
||||
../src/networking.c
|
||||
../src/networking.c ../src/auth_token.c
|
||||
../src/thread_tasks.c ../src/time.c
|
||||
../src/string_helpers.c ../src/mutex.c
|
||||
../src/token.c ../src/heartBeat.c
|
||||
../src/close_retry.c
|
||||
../src/close_retry.c ../src/event_handler.c
|
||||
)
|
||||
|
||||
if (ENABLE_SESHAT)
|
||||
@@ -304,9 +359,13 @@ 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 )
|
||||
target_link_libraries (test_token ${PARODUS_COMMON_LIBS} -lcmocka -lcurl -luuid)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_seshat_interface - registerWithSeshat
|
||||
|
||||
104
tests/mock_event_handler.c
Normal file
104
tests/mock_event_handler.c
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* If not stated otherwise in this file or this component's Licenses.txt file the
|
||||
* following copyright and licenses apply:
|
||||
*
|
||||
* Copyright 2016 RDK Management
|
||||
* Copyright [2014] [Cisco Systems, Inc.]
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* This is a test version of event_handler.c that can be used
|
||||
* to simulate interface down, interface up event
|
||||
* You overwrite event_handler.c in the src diectory with this
|
||||
* version. It will generate interface down / interface up events
|
||||
* at random intervals between 60 secs and 124 secs
|
||||
*/
|
||||
|
||||
#include "parodus_log.h"
|
||||
#include "event_handler.h"
|
||||
#include "connection.h"
|
||||
#include "config.h"
|
||||
#include "heartBeat.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include "time.h"
|
||||
#include "close_retry.h"
|
||||
|
||||
extern bool g_shutdown;
|
||||
|
||||
static pthread_t sysevent_tid;
|
||||
|
||||
static void start_interface_down (void)
|
||||
{
|
||||
set_interface_down_event();
|
||||
ParodusInfo("Interface_down_event is set\n");
|
||||
pause_heartBeatTimer();
|
||||
}
|
||||
|
||||
static void end_interface_down (void)
|
||||
{
|
||||
reset_interface_down_event();
|
||||
ParodusInfo("Interface_down_event is reset\n");
|
||||
resume_heartBeatTimer();
|
||||
set_close_retry();
|
||||
}
|
||||
|
||||
// waits from 60 to 124 secs
|
||||
int wait_random (const char *msg)
|
||||
{
|
||||
#define HALF_SEC 500000l
|
||||
long delay = (random() >> 5) + 60000000l;
|
||||
long secs, usecs;
|
||||
struct timeval timeout;
|
||||
|
||||
secs = delay / 1000000;
|
||||
usecs = delay % 1000000;
|
||||
ParodusInfo ("Waiting %ld secs %ld usecs for %s\n", secs, usecs, msg);
|
||||
|
||||
while (!g_shutdown) {
|
||||
timeout.tv_sec = 0;
|
||||
if (delay <= HALF_SEC) {
|
||||
timeout.tv_usec = delay;
|
||||
select (0, NULL, NULL, NULL, &timeout);
|
||||
return 0;
|
||||
}
|
||||
timeout.tv_usec = HALF_SEC;
|
||||
delay -= HALF_SEC;
|
||||
select (0, NULL, NULL, NULL, &timeout);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static void *parodus_sysevent_handler (void *data)
|
||||
{
|
||||
while (!g_shutdown) {
|
||||
if (wait_random ("interface down") != 0)
|
||||
break;
|
||||
start_interface_down ();
|
||||
wait_random ("interface up");
|
||||
end_interface_down ();
|
||||
}
|
||||
ParodusInfo ("Exiting event handler\n");
|
||||
return data;
|
||||
}
|
||||
|
||||
void EventHandler()
|
||||
{
|
||||
ParodusInfo ("RAND_MAX is %ld (0x%lx)\n", RAND_MAX, RAND_MAX);
|
||||
srandom (getpid());
|
||||
|
||||
pthread_create(&sysevent_tid, NULL, parodus_sysevent_handler, NULL);
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
435
tests/test_auth_token.c
Normal file
435
tests/test_auth_token.c
Normal file
@@ -0,0 +1,435 @@
|
||||
/**
|
||||
* Copyright 2010-2016 Comcast Cable Communications Management, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <malloc.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <CUnit/Basic.h>
|
||||
|
||||
#include "../src/config.h"
|
||||
#include "../src/auth_token.h"
|
||||
#include "../src/ParodusInternal.h"
|
||||
|
||||
extern int requestNewAuthToken(char *newToken, size_t len, int r_count);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
typedef void CURL;
|
||||
|
||||
typedef enum {
|
||||
CURLINFO_RESPONSE_CODE = 2,
|
||||
CURLINFO_TOTAL_TIME
|
||||
} CURLINFO;
|
||||
|
||||
struct token_data test_data;
|
||||
|
||||
int curl_easy_perform(CURL *curl)
|
||||
{
|
||||
UNUSED(curl);
|
||||
char *msg = "response";
|
||||
int rtn;
|
||||
|
||||
function_called();
|
||||
rtn = (int) mock();
|
||||
if (0 == rtn)
|
||||
write_callback_fn (msg, 1, strlen(msg), &test_data);
|
||||
return rtn;
|
||||
}
|
||||
|
||||
extern int g_response_code;
|
||||
|
||||
void setGlobalResponseCode (int response_code)
|
||||
{
|
||||
g_response_code = response_code;
|
||||
}
|
||||
|
||||
int curl_easy_getinfo(CURL *curl, CURLINFO CURLINFO_RESPONSE_CODE, long response_code)
|
||||
{
|
||||
UNUSED(curl);
|
||||
UNUSED(CURLINFO_RESPONSE_CODE);
|
||||
if (0 != g_response_code)
|
||||
{
|
||||
response_code= g_response_code;
|
||||
ParodusInfo("response_code is %ld\n", response_code);
|
||||
}
|
||||
function_called();
|
||||
return (int) mock();
|
||||
}
|
||||
|
||||
char* get_global_reconnect_reason()
|
||||
{
|
||||
return "none";
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void getAuthToken_Null()
|
||||
{
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg,0,sizeof(cfg));
|
||||
parStrncpy(cfg.hw_mac , "123567892366", sizeof(cfg.hw_mac));
|
||||
cfg.client_cert_path = NULL;
|
||||
getAuthToken(&cfg);
|
||||
set_parodus_cfg(&cfg);
|
||||
assert( cfg.client_cert_path == NULL);
|
||||
assert_int_equal (0, (int) cfg.webpa_auth_token[0]);
|
||||
}
|
||||
|
||||
void getAuthToken_MacNull()
|
||||
{
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg,0,sizeof(cfg));
|
||||
cfg.client_cert_path = NULL;
|
||||
getAuthToken(&cfg);
|
||||
set_parodus_cfg(&cfg);
|
||||
assert( cfg.client_cert_path == NULL);
|
||||
assert_int_equal (0, (int) cfg.webpa_auth_token[0]);
|
||||
}
|
||||
|
||||
#if 0
|
||||
void test_requestNewAuthToken_init_fail ()
|
||||
{
|
||||
char token[32];
|
||||
ParodusCfg cfg;
|
||||
int output = -1;
|
||||
memset(&cfg,0,sizeof(cfg));
|
||||
|
||||
cfg.token_server_url = strdup("https://dev.comcast.net/token");
|
||||
parStrncpy(cfg.cert_path , "/etc/ssl/certs/ca-certificates.crt", sizeof(cfg.cert_path));
|
||||
parStrncpy(cfg.hw_serial_number, "Fer23u948590", sizeof(cfg.hw_serial_number));
|
||||
parStrncpy(cfg.hw_mac , "123567892366", sizeof(cfg.hw_mac));
|
||||
|
||||
set_parodus_cfg(&cfg);
|
||||
|
||||
will_return (curl_easy_perform, -1);
|
||||
expect_function_calls (curl_easy_perform, 1);
|
||||
|
||||
will_return (curl_easy_getinfo, 0);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
will_return (curl_easy_getinfo, -1);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
requestNewAuthToken (token, sizeof(token), 2);
|
||||
assert_int_equal (output, -1);
|
||||
free(cfg.token_server_url);
|
||||
}
|
||||
#endif
|
||||
|
||||
void test_requestNewAuthToken_failure ()
|
||||
{
|
||||
char token[32];
|
||||
ParodusCfg cfg;
|
||||
int output = -1;
|
||||
memset(&cfg,0,sizeof(cfg));
|
||||
|
||||
cfg.token_server_url = strdup("https://dev.comcast.net/token");
|
||||
parStrncpy(cfg.cert_path , "/etc/ssl/certs/ca-certificates.crt", sizeof(cfg.cert_path));
|
||||
parStrncpy(cfg.hw_serial_number, "Fer23u948590", sizeof(cfg.hw_serial_number));
|
||||
parStrncpy(cfg.hw_mac , "123567892366", sizeof(cfg.hw_mac));
|
||||
set_parodus_cfg(&cfg);
|
||||
|
||||
test_data.size = 0;
|
||||
test_data.data = token;
|
||||
will_return (curl_easy_perform, -1);
|
||||
expect_function_calls (curl_easy_perform, 1);
|
||||
|
||||
will_return (curl_easy_getinfo, 0);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
will_return (curl_easy_getinfo, -1);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
requestNewAuthToken (token, sizeof(token), 2);
|
||||
assert_int_equal (output, -1);
|
||||
assert_int_equal (0, (int) token[0]);
|
||||
free(cfg.token_server_url);
|
||||
}
|
||||
|
||||
|
||||
void test_requestNewAuthToken ()
|
||||
{
|
||||
char token[1024];
|
||||
ParodusCfg cfg;
|
||||
int output = -1;
|
||||
memset(&cfg,0,sizeof(cfg));
|
||||
|
||||
cfg.token_server_url = strdup("https://dev.comcast.net/token");
|
||||
parStrncpy(cfg.cert_path , "/etc/ssl/certs/ca-certificates.crt", sizeof(cfg.cert_path));
|
||||
parStrncpy(cfg.webpa_interface_used , "eth0", sizeof(cfg.webpa_interface_used));
|
||||
parStrncpy(cfg.hw_serial_number, "Fer23u948590", sizeof(cfg.hw_serial_number));
|
||||
parStrncpy(cfg.hw_mac , "123567892366", sizeof(cfg.hw_mac));
|
||||
set_parodus_cfg(&cfg);
|
||||
|
||||
test_data.size = 0;
|
||||
test_data.data = token;
|
||||
setGlobalResponseCode(200);
|
||||
will_return (curl_easy_perform, 0);
|
||||
expect_function_calls (curl_easy_perform, 1);
|
||||
will_return (curl_easy_getinfo, 0);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
will_return (curl_easy_getinfo, 0);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
output = requestNewAuthToken (token, sizeof(token), 1);
|
||||
assert_int_equal (output, 0);
|
||||
assert_string_equal (token, "response");
|
||||
free(cfg.token_server_url);
|
||||
}
|
||||
|
||||
void test_getAuthToken ()
|
||||
{
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg,0,sizeof(cfg));
|
||||
|
||||
cfg.token_server_url = strdup("https://dev.comcast.net/token");
|
||||
cfg.client_cert_path = strdup("testcert");
|
||||
parStrncpy(cfg.cert_path , "/etc/ssl/certs/ca-certificates.crt", sizeof(cfg.cert_path));
|
||||
parStrncpy(cfg.webpa_interface_used , "eth0", sizeof(cfg.webpa_interface_used));
|
||||
parStrncpy(cfg.hw_serial_number, "Fer23u948590", sizeof(cfg.hw_serial_number));
|
||||
parStrncpy(cfg.hw_mac , "123567892366", sizeof(cfg.hw_mac));
|
||||
set_parodus_cfg(&cfg);
|
||||
|
||||
/* To test curl failure case and retry on v4 mode */
|
||||
will_return (curl_easy_perform, -1);
|
||||
expect_function_calls (curl_easy_perform, 1);
|
||||
|
||||
will_return (curl_easy_getinfo, 0);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
will_return (curl_easy_getinfo, 0);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
/* To test curl failure case and retry on v6 mode */
|
||||
will_return (curl_easy_perform, -1);
|
||||
expect_function_calls (curl_easy_perform, 1);
|
||||
|
||||
will_return (curl_easy_getinfo, 0);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
will_return (curl_easy_getinfo, 0);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
/* To test curl success case */
|
||||
test_data.size = 0;
|
||||
test_data.data = cfg.webpa_auth_token;
|
||||
setGlobalResponseCode(200);
|
||||
will_return (curl_easy_perform, 0);
|
||||
expect_function_calls (curl_easy_perform, 1);
|
||||
|
||||
will_return (curl_easy_getinfo, 0);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
will_return (curl_easy_getinfo, 0);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
getAuthToken(&cfg);
|
||||
assert_string_equal (cfg.webpa_auth_token, "response");
|
||||
free(cfg.client_cert_path);
|
||||
free(cfg.token_server_url);
|
||||
}
|
||||
|
||||
void test_getAuthTokenFailure ()
|
||||
{
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg,0,sizeof(cfg));
|
||||
|
||||
cfg.token_server_url = strdup("https://dev.comcast.net/token");
|
||||
cfg.client_cert_path = strdup("testcert");
|
||||
parStrncpy(cfg.cert_path , "/etc/ssl/certs/ca-certificates.crt", sizeof(cfg.cert_path));
|
||||
parStrncpy(cfg.webpa_interface_used , "eth0", sizeof(cfg.webpa_interface_used));
|
||||
parStrncpy(cfg.hw_serial_number, "Fer23u948590", sizeof(cfg.hw_serial_number));
|
||||
parStrncpy(cfg.hw_mac , "123567892366", sizeof(cfg.hw_mac));
|
||||
set_parodus_cfg(&cfg);
|
||||
|
||||
will_return (curl_easy_perform, -1);
|
||||
expect_function_calls (curl_easy_perform, 1);
|
||||
|
||||
will_return (curl_easy_getinfo, 0);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
will_return (curl_easy_getinfo, 0);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
will_return (curl_easy_perform, -1);
|
||||
expect_function_calls (curl_easy_perform, 1);
|
||||
|
||||
will_return (curl_easy_getinfo, 0);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
will_return (curl_easy_getinfo, 0);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
will_return (curl_easy_perform, -1);
|
||||
expect_function_calls (curl_easy_perform, 1);
|
||||
|
||||
will_return (curl_easy_getinfo, 0);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
will_return (curl_easy_getinfo, 0);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
getAuthToken(&cfg);
|
||||
|
||||
assert_string_equal( cfg.webpa_auth_token, "");
|
||||
|
||||
free(cfg.client_cert_path);
|
||||
free(cfg.token_server_url);
|
||||
}
|
||||
|
||||
void test_write_callback_fn ()
|
||||
{
|
||||
ParodusCfg *cfg;
|
||||
size_t max_data_size = sizeof (cfg->webpa_auth_token);
|
||||
char *buffer1 = "response1";
|
||||
size_t buf1len = strlen(buffer1);
|
||||
char *buffer2 = "R2";
|
||||
size_t buf2len = strlen(buffer2);
|
||||
char buffer3[max_data_size];
|
||||
int out_len=0;
|
||||
struct token_data data;
|
||||
data.size = 0;
|
||||
|
||||
data.data = (char *) malloc(max_data_size);
|
||||
data.data[0] = '\0';
|
||||
|
||||
out_len = write_callback_fn(buffer1, 1, buf1len, &data);
|
||||
assert_string_equal(data.data, buffer1);
|
||||
assert_int_equal (out_len, buf1len);
|
||||
assert_int_equal (data.size, buf1len);
|
||||
|
||||
out_len = write_callback_fn(buffer2, 1, buf2len, &data);
|
||||
assert_string_equal(data.data, "response1R2");
|
||||
assert_int_equal (out_len, buf2len);
|
||||
assert_int_equal (data.size, buf1len+buf2len);
|
||||
|
||||
memset (buffer3, 'x', max_data_size);
|
||||
out_len = write_callback_fn(buffer3, 1, max_data_size, &data);
|
||||
assert_int_equal (out_len, 0);
|
||||
assert_int_equal (data.size, 0);
|
||||
|
||||
free(data.data);
|
||||
}
|
||||
|
||||
void test_requestNewAuthToken_non200 ()
|
||||
{
|
||||
char token[1024];
|
||||
ParodusCfg cfg;
|
||||
int output;
|
||||
memset(&cfg,0,sizeof(cfg));
|
||||
|
||||
cfg.token_server_url = strdup("https://dev.comcast.net/token");
|
||||
parStrncpy(cfg.cert_path , "/etc/ssl/certs/ca-certificates.crt", sizeof(cfg.cert_path));
|
||||
parStrncpy(cfg.webpa_interface_used , "eth0", sizeof(cfg.webpa_interface_used));
|
||||
parStrncpy(cfg.hw_serial_number, "Fer23u948590", sizeof(cfg.hw_serial_number));
|
||||
parStrncpy(cfg.hw_mac , "123567892366", sizeof(cfg.hw_mac));
|
||||
set_parodus_cfg(&cfg);
|
||||
|
||||
test_data.size = 0;
|
||||
test_data.data = token;
|
||||
setGlobalResponseCode(404);
|
||||
will_return (curl_easy_perform, 0);
|
||||
expect_function_calls (curl_easy_perform, 1);
|
||||
will_return (curl_easy_getinfo, 0);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
will_return (curl_easy_getinfo, 0);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
output = requestNewAuthToken (token, sizeof(token), 1);
|
||||
assert_int_equal (output, -1);
|
||||
assert_string_equal (token, "");
|
||||
ParodusInfo("requestNewAuthToken output: %d token empty len: %lu\n", output, strlen(token));
|
||||
free(cfg.token_server_url);
|
||||
}
|
||||
|
||||
void test_getAuthTokenFailure_non200 ()
|
||||
{
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg,0,sizeof(cfg));
|
||||
|
||||
cfg.token_server_url = strdup("https://dev.comcast.net/token");
|
||||
cfg.client_cert_path = strdup("testcert");
|
||||
parStrncpy(cfg.cert_path , "/etc/ssl/certs/ca-certificates.crt", sizeof(cfg.cert_path));
|
||||
parStrncpy(cfg.webpa_interface_used , "eth0", sizeof(cfg.webpa_interface_used));
|
||||
parStrncpy(cfg.hw_serial_number, "Fer23u948590", sizeof(cfg.hw_serial_number));
|
||||
parStrncpy(cfg.hw_mac , "123567892366", sizeof(cfg.hw_mac));
|
||||
set_parodus_cfg(&cfg);
|
||||
|
||||
will_return (curl_easy_perform, 0);
|
||||
expect_function_calls (curl_easy_perform, 1);
|
||||
|
||||
will_return (curl_easy_getinfo, 0);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
will_return (curl_easy_getinfo, 0);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
will_return (curl_easy_perform, 0);
|
||||
expect_function_calls (curl_easy_perform, 1);
|
||||
|
||||
will_return (curl_easy_getinfo, 0);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
will_return (curl_easy_getinfo, 0);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
will_return (curl_easy_perform, 0);
|
||||
expect_function_calls (curl_easy_perform, 1);
|
||||
|
||||
will_return (curl_easy_getinfo, 0);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
|
||||
will_return (curl_easy_getinfo, 0);
|
||||
expect_function_calls (curl_easy_getinfo, 1);
|
||||
setGlobalResponseCode(504);
|
||||
getAuthToken(&cfg);
|
||||
|
||||
assert_string_equal( cfg.webpa_auth_token, "");
|
||||
|
||||
free(cfg.client_cert_path);
|
||||
free(cfg.token_server_url);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(test_write_callback_fn),
|
||||
cmocka_unit_test(test_requestNewAuthToken),
|
||||
// cmocka_unit_test(test_requestNewAuthToken_init_fail),
|
||||
cmocka_unit_test(test_requestNewAuthToken_failure),
|
||||
cmocka_unit_test(getAuthToken_Null),
|
||||
cmocka_unit_test(getAuthToken_MacNull),
|
||||
cmocka_unit_test(test_getAuthToken),
|
||||
cmocka_unit_test(test_getAuthTokenFailure),
|
||||
cmocka_unit_test(test_requestNewAuthToken_non200),
|
||||
cmocka_unit_test(test_getAuthTokenFailure_non200)
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
116
tests/test_auth_token_more.c
Normal file
116
tests/test_auth_token_more.c
Normal file
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* Copyright 2010-2016 Comcast Cable Communications Management, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <malloc.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <CUnit/Basic.h>
|
||||
|
||||
#include "../src/config.h"
|
||||
#include "../src/auth_token.h"
|
||||
#include "../src/ParodusInternal.h"
|
||||
|
||||
extern int requestNewAuthToken(char *newToken, size_t len, int r_count);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
typedef void CURL;
|
||||
|
||||
typedef enum {
|
||||
CURLINFO_RESPONSE_CODE = 2,
|
||||
CURLINFO_TOTAL_TIME
|
||||
} CURLINFO;
|
||||
|
||||
struct token_data test_data;
|
||||
|
||||
CURL *curl_easy_init ()
|
||||
{
|
||||
function_called();
|
||||
return (CURL *) mock();
|
||||
}
|
||||
|
||||
int curl_easy_perform(CURL *curl)
|
||||
{
|
||||
UNUSED(curl);
|
||||
char *msg = "response";
|
||||
int rtn;
|
||||
|
||||
function_called();
|
||||
rtn = (int) mock();
|
||||
if (0 == rtn)
|
||||
write_callback_fn (msg, 1, strlen(msg), &test_data);
|
||||
return rtn;
|
||||
}
|
||||
|
||||
int curl_easy_getinfo(CURL *curl, CURLINFO CURLINFO_RESPONSE_CODE, long response_code)
|
||||
{
|
||||
UNUSED(curl);
|
||||
UNUSED(CURLINFO_RESPONSE_CODE);
|
||||
UNUSED(response_code);
|
||||
function_called();
|
||||
return (int) mock();
|
||||
}
|
||||
|
||||
char* get_global_reconnect_reason()
|
||||
{
|
||||
return "none";
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void test_requestNewAuthToken_init_fail ()
|
||||
{
|
||||
char token[32];
|
||||
ParodusCfg cfg;
|
||||
int output = -1;
|
||||
memset(&cfg,0,sizeof(cfg));
|
||||
|
||||
cfg.token_server_url = strdup("https://dev.comcast.net/token");
|
||||
parStrncpy(cfg.cert_path , "/etc/ssl/certs/ca-certificates.crt", sizeof(cfg.cert_path));
|
||||
parStrncpy(cfg.hw_serial_number, "Fer23u948590", sizeof(cfg.hw_serial_number));
|
||||
parStrncpy(cfg.hw_mac , "123567892366", sizeof(cfg.hw_mac));
|
||||
|
||||
set_parodus_cfg(&cfg);
|
||||
|
||||
will_return (curl_easy_init, NULL);
|
||||
expect_function_calls (curl_easy_init, 1);
|
||||
|
||||
requestNewAuthToken (token, sizeof(token), 2);
|
||||
assert_int_equal (output, -1);
|
||||
assert_int_equal (0, (int) token[0]);
|
||||
free(cfg.token_server_url);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(test_requestNewAuthToken_init_fail)
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
@@ -26,9 +26,14 @@
|
||||
#define TEST_CLIENT1_URL "tcp://127.0.0.1:6677"
|
||||
#define TEST_CLIENT2_URL "tcp://127.0.0.1:6655"
|
||||
|
||||
pthread_t test_tid;
|
||||
pthread_t test_tid2;
|
||||
|
||||
static void *client_rcv_task();
|
||||
static void *client2_rcv_task();
|
||||
|
||||
int numLoops;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -58,7 +63,7 @@ void test_client_addtolist()
|
||||
ParodusPrint("decoded service_name:%s\n", message->u.reg.service_name);
|
||||
ParodusPrint("decoded dest:%s\n", message->u.reg.url);
|
||||
|
||||
StartThread(client_rcv_task);
|
||||
StartThread(client_rcv_task, &test_tid);
|
||||
|
||||
status = addToList(&message);
|
||||
ParodusPrint("addToList status is %d\n", status);
|
||||
@@ -73,7 +78,7 @@ void test_client_addtolist()
|
||||
CU_ASSERT_STRING_EQUAL( temp->service_name, message->u.reg.service_name );
|
||||
CU_ASSERT_STRING_EQUAL( temp->url, message->u.reg.url );
|
||||
}
|
||||
|
||||
release_global_node ();
|
||||
wrp_free_struct(message);
|
||||
free(bytes);
|
||||
ParodusInfo("test_client_addtolist done..\n");
|
||||
@@ -189,7 +194,7 @@ void test_addtolist_multiple_clients()
|
||||
ParodusPrint("decoded service_name:%s\n", message->u.reg.service_name);
|
||||
ParodusPrint("decoded dest:%s\n", message->u.reg.url);
|
||||
|
||||
StartThread(client2_rcv_task);
|
||||
StartThread(client2_rcv_task, &test_tid2);
|
||||
|
||||
status = addToList(&message);
|
||||
ParodusPrint("addToList status is %d\n", status);
|
||||
@@ -206,7 +211,7 @@ void test_addtolist_multiple_clients()
|
||||
CU_ASSERT_STRING_EQUAL( temp->url, message->u.reg.url );
|
||||
|
||||
}
|
||||
|
||||
release_global_node ();
|
||||
wrp_free_struct(message);
|
||||
free(bytes);
|
||||
ParodusInfo("test_addtolist_multiple_clients done..\n");
|
||||
|
||||
@@ -25,9 +25,11 @@
|
||||
#include <CUnit/Basic.h>
|
||||
|
||||
#include "../src/config.h"
|
||||
#include "../src/auth_token.h"
|
||||
#include "../src/ParodusInternal.h"
|
||||
|
||||
extern int parse_mac_address (char *target, const char *arg);
|
||||
extern int parse_serial_num(char *target, const char *arg);
|
||||
extern int server_is_http (const char *full_url,
|
||||
const char **server_ptr);
|
||||
extern int parse_webpa_url__(const char *full_url,
|
||||
@@ -37,8 +39,6 @@ extern int parse_webpa_url (const char *full_url,
|
||||
char **server_addr, unsigned int *port);
|
||||
extern unsigned int get_algo_mask (const char *algo_str);
|
||||
extern unsigned int parse_num_arg (const char *arg, const char *arg_name);
|
||||
extern void execute_token_script(char *token, char *name, size_t len, char *mac, char *serNum);
|
||||
extern void createNewAuthToken(char *newToken, size_t len);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
@@ -53,6 +53,12 @@ void create_token_script(char *fname)
|
||||
sprintf(command, "chmod +x %s",fname);
|
||||
system(command);
|
||||
}
|
||||
|
||||
char* get_global_reconnect_reason()
|
||||
{
|
||||
return "none";
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -98,7 +104,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 +122,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()
|
||||
@@ -184,9 +192,10 @@ void test_parseCommandLine()
|
||||
#endif
|
||||
"--force-ipv4",
|
||||
"--force-ipv6",
|
||||
"--token-read-script=/tmp/token.sh",
|
||||
"--token-acquisition-script=/tmp/token.sh",
|
||||
"--boot-time-retry-wait=10",
|
||||
"--ssl-cert-path=/etc/ssl/certs/ca-certificates.crt",
|
||||
"--client-cert-path=testcert",
|
||||
"--token-server-url=https://dev.comcast.net/token",
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
"--acquire-jwt=1",
|
||||
"--dns-txt-url=mydns.mycom.net",
|
||||
@@ -200,13 +209,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.");
|
||||
@@ -214,6 +221,7 @@ void test_parseCommandLine()
|
||||
assert_string_equal( parodusCfg.hw_last_reboot_reason, "unknown");
|
||||
assert_string_equal( parodusCfg.fw_name, "TG1682_DEV_master_2016000000sdy");
|
||||
assert_int_equal( (int) parodusCfg.webpa_ping_timeout,180);
|
||||
assert_int_equal( (int) parodusCfg.boot_retry_wait,10);
|
||||
assert_string_equal( parodusCfg.webpa_interface_used, "br0");
|
||||
assert_string_equal( parodusCfg.webpa_url, "http://127.0.0.1");
|
||||
assert_int_equal( (int) parodusCfg.webpa_backoff_max,0);
|
||||
@@ -224,18 +232,20 @@ void test_parseCommandLine()
|
||||
assert_string_equal( parodusCfg.seshat_url, "ipc://127.0.0.1:7777");
|
||||
#endif
|
||||
assert_int_equal( (int) parodusCfg.flags, FLAGS_IPV6_ONLY|FLAGS_IPV4_ONLY);
|
||||
sprintf(expectedToken,"secure-token-%s-%s",parodusCfg.hw_serial_number,parodusCfg.hw_mac);
|
||||
getAuthToken(&parodusCfg);
|
||||
set_parodus_cfg(&parodusCfg);
|
||||
|
||||
set_parodus_cfg(&parodusCfg);
|
||||
getAuthToken(&parodusCfg);
|
||||
assert_string_equal( get_parodus_cfg()->webpa_auth_token,expectedToken);
|
||||
assert_string_equal( parodusCfg.cert_path,"/etc/ssl/certs/ca-certificates.crt");
|
||||
assert_string_equal( parodusCfg.client_cert_path,"testcert");
|
||||
assert_string_equal( parodusCfg.token_server_url,"https://dev.comcast.net/token");
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
assert_int_equal( (int) parodusCfg.acquire_jwt, 1);
|
||||
assert_string_equal(parodusCfg.dns_txt_url, "mydns.mycom.net");
|
||||
assert_int_equal( (int) parodusCfg.jwt_algo, 1024);
|
||||
assert_string_equal ( get_parodus_cfg()->jwt_key, jwt_key);
|
||||
#endif
|
||||
assert_int_equal( (int) parodusCfg.boot_retry_wait, 10);
|
||||
assert_string_equal(parodusCfg.crud_config_file, "parodus_cfg.json");
|
||||
}
|
||||
|
||||
@@ -295,8 +305,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));
|
||||
@@ -317,13 +328,13 @@ void test_loadParodusCfg()
|
||||
Cfg->jwt_algo = 1025;
|
||||
parStrncpy(Cfg->jwt_key, "AGdyuwyhwl2ow2ydsoioiygkshwdthuwd",sizeof(Cfg->jwt_key));
|
||||
#endif
|
||||
parStrncpy(Cfg->token_acquisition_script , "/tmp/token.sh", sizeof(Cfg->token_acquisition_script));
|
||||
parStrncpy(Cfg->token_read_script , "/tmp/token.sh", sizeof(Cfg->token_read_script));
|
||||
parStrncpy(Cfg->cert_path, "/etc/ssl.crt",sizeof(Cfg->cert_path));
|
||||
#ifdef ENABLE_SESHAT
|
||||
parStrncpy(Cfg->seshat_url, "ipc://tmp/seshat_service.url", sizeof(Cfg->seshat_url));
|
||||
#endif
|
||||
Cfg->crud_config_file = strdup("parodus_cfg.json");
|
||||
Cfg->client_cert_path = strdup("testcert");
|
||||
Cfg->token_server_url = strdup("https://dev.comcast.net/token");
|
||||
memset(&tmpcfg,0,sizeof(ParodusCfg));
|
||||
loadParodusCfg(Cfg,&tmpcfg);
|
||||
|
||||
@@ -334,19 +345,27 @@ void test_loadParodusCfg()
|
||||
assert_string_equal( tmpcfg.local_url, "tcp://10.0.0.1:6000");
|
||||
assert_string_equal( tmpcfg.partner_id, "shaw");
|
||||
assert_string_equal( tmpcfg.webpa_protocol, protocol);
|
||||
assert_string_equal(tmpcfg.client_cert_path, "testcert");
|
||||
assert_string_equal(tmpcfg.token_server_url, "https://dev.comcast.net/token");
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
assert_int_equal( (int) tmpcfg.acquire_jwt, 1);
|
||||
assert_string_equal(tmpcfg.dns_txt_url, "mydns");
|
||||
assert_int_equal( (int) tmpcfg.jwt_algo, 1025);
|
||||
assert_string_equal(tmpcfg.jwt_key, "AGdyuwyhwl2ow2ydsoioiygkshwdthuwd");
|
||||
#endif
|
||||
assert_string_equal( tmpcfg.token_acquisition_script,"/tmp/token.sh");
|
||||
assert_string_equal( tmpcfg.token_read_script,"/tmp/token.sh");
|
||||
assert_string_equal(tmpcfg.cert_path, "/etc/ssl.crt");
|
||||
#ifdef ENABLE_SESHAT
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -418,6 +437,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()
|
||||
@@ -447,6 +468,14 @@ void test_parse_mac_address ()
|
||||
assert_int_equal (parse_mac_address (result, ""), -1);
|
||||
}
|
||||
|
||||
void test_parse_serial_num()
|
||||
{
|
||||
char result[14];
|
||||
assert_int_equal (parse_serial_num (result, "1234ABC00ab"), 0);
|
||||
assert_int_equal (parse_serial_num (result, "$@@"), 0);
|
||||
assert_int_equal (parse_serial_num (result, ""), 0);
|
||||
}
|
||||
|
||||
void test_server_is_http ()
|
||||
{
|
||||
const char *server_ptr;
|
||||
@@ -553,47 +582,6 @@ void test_get_algo_mask ()
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_execute_token_script()
|
||||
{
|
||||
char *cmd1 = "../../tests/return_ser_mac.bsh";
|
||||
char *cmd2 = "nosuch";
|
||||
char token[32];
|
||||
|
||||
memset (token, '\0', sizeof(token));
|
||||
execute_token_script (token, cmd1, sizeof(token), "mac123", "ser456");
|
||||
assert_string_equal (token, "SER_MAC ser456 mac123");
|
||||
|
||||
memset (token, '\0', sizeof(token));
|
||||
execute_token_script (token, cmd2, sizeof(token), "mac123", "ser456");
|
||||
assert_string_equal (token, "");
|
||||
}
|
||||
|
||||
void test_new_auth_token ()
|
||||
{
|
||||
char token[64];
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg,0,sizeof(cfg));
|
||||
|
||||
parStrncpy (cfg.token_acquisition_script, "../../tests/return_success.bsh",
|
||||
sizeof(cfg.token_acquisition_script));
|
||||
parStrncpy (cfg.token_read_script, "../../tests/return_ser_mac.bsh",
|
||||
sizeof(cfg.token_read_script));
|
||||
parStrncpy(cfg.hw_serial_number, "Fer23u948590", sizeof(cfg.hw_serial_number));
|
||||
parStrncpy(cfg.hw_mac , "123567892366", sizeof(cfg.hw_mac));
|
||||
|
||||
set_parodus_cfg(&cfg);
|
||||
createNewAuthToken (token, sizeof(token));
|
||||
assert_string_equal (token, "SER_MAC Fer23u948590 123567892366");
|
||||
|
||||
memset (token, 0, sizeof(token));
|
||||
parStrncpy (cfg.token_acquisition_script, "../../tests/return_failure.bsh",
|
||||
sizeof(cfg.token_acquisition_script));
|
||||
set_parodus_cfg(&cfg);
|
||||
createNewAuthToken (token, sizeof(token));
|
||||
assert_string_equal (token, "");
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -608,6 +596,7 @@ int main(void)
|
||||
cmocka_unit_test(err_loadParodusCfg),
|
||||
cmocka_unit_test(test_parse_num_arg),
|
||||
cmocka_unit_test(test_parse_mac_address),
|
||||
cmocka_unit_test(test_parse_serial_num),
|
||||
cmocka_unit_test(test_get_algo_mask),
|
||||
cmocka_unit_test(test_server_is_http),
|
||||
cmocka_unit_test(test_parse_webpa_url__),
|
||||
@@ -618,8 +607,6 @@ int main(void)
|
||||
//cmocka_unit_test(test_parodusGitVersion),
|
||||
cmocka_unit_test(test_setDefaultValuesToCfg),
|
||||
cmocka_unit_test(err_setDefaultValuesToCfg),
|
||||
cmocka_unit_test(test_execute_token_script),
|
||||
cmocka_unit_test(test_new_auth_token)
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
|
||||
@@ -33,18 +33,35 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static char *reconnect_reason = "webpa_process_starts";
|
||||
UpStreamMsg *UpStreamMsgQ;
|
||||
ParodusMsg *ParodusMsgQ;
|
||||
pthread_mutex_t nano_mut;
|
||||
pthread_cond_t nano_con;
|
||||
pthread_mutex_t g_mutex=PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t g_cond=PTHREAD_COND_INITIALIZER;
|
||||
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 */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int createNopollConnection(noPollCtx *ctx)
|
||||
void set_server_list_null (server_list_t *server_list)
|
||||
{
|
||||
UNUSED(ctx);
|
||||
UNUSED(server_list);
|
||||
}
|
||||
|
||||
int find_servers (server_list_t *server_list)
|
||||
{
|
||||
UNUSED(server_list);
|
||||
return FIND_SUCCESS;
|
||||
}
|
||||
|
||||
int createNopollConnection(noPollCtx *ctx, server_list_t *server_list)
|
||||
{
|
||||
UNUSED(ctx); UNUSED(server_list);
|
||||
function_called();
|
||||
return (int) mock();
|
||||
}
|
||||
@@ -54,7 +71,10 @@ void nopoll_log_set_handler (noPollCtx *ctx, noPollLogHandler handler, noPollPtr
|
||||
UNUSED(ctx); UNUSED(handler); UNUSED(user_data);
|
||||
function_called();
|
||||
}
|
||||
|
||||
int cloud_status_is_online (void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
void __report_log (noPollCtx * ctx, noPollDebugLevel level, const char * log_msg, noPollPtr user_data)
|
||||
{
|
||||
UNUSED(ctx); UNUSED(level); UNUSED(log_msg); UNUSED(user_data);
|
||||
@@ -70,11 +90,67 @@ noPollMutexUnlock mutex_unlock
|
||||
UNUSED(mutex_create); UNUSED(mutex_destroy); UNUSED(mutex_lock); UNUSED(mutex_unlock);
|
||||
function_called();
|
||||
}
|
||||
|
||||
char *get_global_reconnect_reason()
|
||||
{
|
||||
return reconnect_reason;
|
||||
}
|
||||
|
||||
char *get_global_shutdown_reason()
|
||||
{
|
||||
return SHUTDOWN_REASON_PARODUS_STOP;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void stop_conn_in_progress (void)
|
||||
{
|
||||
}
|
||||
|
||||
void reset_interface_down_event (void)
|
||||
{
|
||||
}
|
||||
|
||||
bool get_interface_down_event (void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void set_interface_down_event (void)
|
||||
{
|
||||
}
|
||||
|
||||
int wait_while_interface_down (void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void terminate_backoff_delay (void)
|
||||
{
|
||||
}
|
||||
|
||||
void packMetaData()
|
||||
{
|
||||
function_called();
|
||||
}
|
||||
|
||||
int get_parodus_init()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_cloud_disconnect_time(void)
|
||||
{
|
||||
@@ -103,9 +179,21 @@ void *messageHandlerTask()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *serviceAliveTask()
|
||||
int serviceAliveTask()
|
||||
{
|
||||
return NULL;
|
||||
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)
|
||||
@@ -127,12 +215,19 @@ void set_global_reconnect_status(bool status)
|
||||
function_called();
|
||||
}
|
||||
|
||||
void close_and_unref_connection(noPollConn *conn)
|
||||
void close_and_unref_connection(noPollConn *conn, bool is_shutting_down)
|
||||
{
|
||||
UNUSED(conn);
|
||||
UNUSED(conn); UNUSED(is_shutting_down);
|
||||
function_called();
|
||||
}
|
||||
|
||||
int readFromFile(const char *file_name, char **data)
|
||||
{
|
||||
UNUSED(file_name);
|
||||
*data = strdup ("parodus_stopping");
|
||||
return 1;
|
||||
}
|
||||
|
||||
void nopoll_cleanup_library ()
|
||||
{
|
||||
function_called();
|
||||
@@ -156,12 +251,18 @@ void set_global_conn(noPollConn *conn)
|
||||
function_called();
|
||||
}
|
||||
|
||||
void StartThread(void *(*start_routine) (void *))
|
||||
void StartThread(void *(*start_routine) (void *), pthread_t *threadId)
|
||||
{
|
||||
UNUSED(start_routine);
|
||||
UNUSED(threadId);
|
||||
function_called();
|
||||
}
|
||||
|
||||
void JoinThread (pthread_t threadId)
|
||||
{
|
||||
UNUSED(threadId);
|
||||
}
|
||||
|
||||
noPollCtx* nopoll_ctx_new(void)
|
||||
{
|
||||
function_called();
|
||||
@@ -192,6 +293,16 @@ pthread_mutex_t *get_global_nano_mut(void)
|
||||
return &nano_mut;
|
||||
}
|
||||
|
||||
pthread_cond_t *get_global_svc_con(void)
|
||||
{
|
||||
return &svc_con;
|
||||
}
|
||||
|
||||
pthread_mutex_t *get_global_svc_mut(void)
|
||||
{
|
||||
return &svc_mut;
|
||||
}
|
||||
|
||||
/*
|
||||
* Mock func to calculate time diff between start and stop time
|
||||
* This timespec_diff retuns 1 sec as diff time
|
||||
@@ -205,6 +316,7 @@ void timespec_diff(struct timespec *start, struct timespec *stop,
|
||||
diff->tv_nsec = 1000;
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -247,6 +359,7 @@ void test_createSocketConnection()
|
||||
|
||||
void test_createSocketConnection1()
|
||||
{
|
||||
numLoops =0;
|
||||
noPollCtx *ctx;
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg,0, sizeof(ParodusCfg));
|
||||
@@ -276,12 +389,11 @@ void test_createSocketConnection1()
|
||||
expect_function_call(nopoll_ctx_unref);
|
||||
expect_function_call(nopoll_cleanup_library);
|
||||
createSocketConnection(NULL);
|
||||
assert_string_equal(get_parodus_cfg()->cloud_status, CLOUD_STATUS_OFFLINE);
|
||||
|
||||
}
|
||||
|
||||
void test_PingMissIntervalTime()
|
||||
{
|
||||
numLoops = 6;
|
||||
noPollCtx *ctx;
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg,0,sizeof(ParodusCfg));
|
||||
@@ -299,7 +411,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);
|
||||
|
||||
@@ -335,11 +446,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);
|
||||
@@ -372,6 +483,7 @@ void err_createSocketConnection()
|
||||
|
||||
void test_createSocketConnection_cloud_disconn()
|
||||
{
|
||||
numLoops =0;
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg,0,sizeof(ParodusCfg));
|
||||
cfg.cloud_disconnect = strdup("XPC");
|
||||
|
||||
@@ -15,15 +15,14 @@
|
||||
*/
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <CUnit/Basic.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
#include <assert.h>
|
||||
#include <CUnit/Basic.h>
|
||||
#include <nopoll.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "../src/ParodusInternal.h"
|
||||
#include "../src/connection.h"
|
||||
@@ -38,6 +37,11 @@ extern void init_expire_timer (expire_timer_t *timer);
|
||||
extern int check_timer_expired (expire_timer_t *timer, long timeout_ms);
|
||||
extern void init_backoff_timer (backoff_timer_t *timer, int max_count);
|
||||
extern int update_backoff_delay (backoff_timer_t *timer);
|
||||
extern void add_timespec (struct timespec *t1, struct timespec *t2);
|
||||
extern unsigned calc_random_secs (int random_num, unsigned max_secs);
|
||||
extern unsigned calc_random_nsecs (int random_num);
|
||||
void calc_random_expiration (int random_num1, int random_num2,
|
||||
backoff_timer_t *timer, struct timespec *ts);
|
||||
extern int init_header_info (header_info_t *header_info);
|
||||
extern void free_header_info (header_info_t *header_info);
|
||||
extern char *build_extra_hdrs (header_info_t *header_info);
|
||||
@@ -58,11 +62,13 @@ extern int keep_trying_to_connect (create_connection_ctx_t *ctx,
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
bool close_retry;
|
||||
bool LastReasonStatus;
|
||||
pthread_mutex_t close_mut;
|
||||
bool interface_down_event = false;
|
||||
pthread_mutex_t interface_down_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t interface_down_con=PTHREAD_COND_INITIALIZER;
|
||||
|
||||
// Mock values
|
||||
bool g_shutdown = false;
|
||||
char *mock_server_addr;
|
||||
unsigned int mock_port;
|
||||
int mock_wait_status;
|
||||
@@ -79,6 +85,42 @@ char* getWebpaConveyHeader()
|
||||
return (char*) "WebPA-1.6 (TG1682)";
|
||||
}
|
||||
|
||||
|
||||
void set_interface_down_event()
|
||||
{
|
||||
interface_down_event = true;
|
||||
}
|
||||
|
||||
void reset_interface_down_event()
|
||||
{
|
||||
pthread_mutex_lock (&interface_down_mut);
|
||||
interface_down_event = false;
|
||||
pthread_cond_signal(&interface_down_con);
|
||||
pthread_mutex_unlock (&interface_down_mut);
|
||||
}
|
||||
|
||||
bool get_interface_down_event()
|
||||
{
|
||||
return interface_down_event;
|
||||
}
|
||||
|
||||
pthread_cond_t *get_interface_down_con(void)
|
||||
{
|
||||
return &interface_down_con;
|
||||
}
|
||||
|
||||
pthread_mutex_t *get_interface_down_mut(void)
|
||||
{
|
||||
return &interface_down_mut;
|
||||
}
|
||||
|
||||
int readFromFile(const char *file_name, char **data)
|
||||
{
|
||||
UNUSED(file_name);
|
||||
*data = strdup ("parodus_stopping");
|
||||
return 1;
|
||||
}
|
||||
|
||||
noPollConn * nopoll_conn_new_opts (noPollCtx * ctx, noPollConnOpts * opts, const char * host_ip, const char * host_port, const char * host_name,const char * get_url,const char * protocols, const char * origin)
|
||||
{
|
||||
UNUSED(host_port); UNUSED(host_name); UNUSED(get_url); UNUSED(protocols);
|
||||
@@ -116,6 +158,8 @@ nopoll_bool nopoll_conn_wait_for_status_until_connection_ready (noPollConn * co
|
||||
int timeout, int *status, char ** message)
|
||||
{
|
||||
UNUSED(conn); UNUSED(timeout);
|
||||
|
||||
*message = NULL;
|
||||
if (mock_wait_status >= 1000) {
|
||||
*status = mock_wait_status / 1000;
|
||||
mock_wait_status = mock_wait_status % 1000;
|
||||
@@ -145,11 +189,9 @@ void nopoll_conn_close (noPollConn *conn)
|
||||
UNUSED(conn);
|
||||
}
|
||||
|
||||
int nopoll_conn_ref_count (noPollConn *conn)
|
||||
void nopoll_conn_close_ext (noPollConn *conn, int status, const char *reason, int reason_size)
|
||||
{
|
||||
UNUSED(conn);
|
||||
function_called ();
|
||||
return (nopoll_bool) mock();
|
||||
UNUSED(conn); UNUSED(status); UNUSED(reason); UNUSED(reason_size);
|
||||
}
|
||||
|
||||
int checkHostIp(char * serverIP)
|
||||
@@ -197,6 +239,7 @@ int allow_insecure_conn (char **server_addr, unsigned int *port)
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
void test_get_global_conn()
|
||||
{
|
||||
assert_null(get_global_conn());
|
||||
@@ -223,7 +266,7 @@ void test_set_global_reconnect_reason()
|
||||
|
||||
void test_closeConnection()
|
||||
{
|
||||
close_and_unref_connection(get_global_conn());
|
||||
close_and_unref_connection(get_global_conn(), false);
|
||||
}
|
||||
|
||||
void test_server_is_null()
|
||||
@@ -300,13 +343,67 @@ void test_expire_timer()
|
||||
|
||||
void test_backoff_delay_timer()
|
||||
{
|
||||
struct timespec t1;
|
||||
struct timespec t2;
|
||||
backoff_timer_t btimer;
|
||||
|
||||
init_backoff_timer (&btimer, 5);
|
||||
assert_int_equal (3, update_backoff_delay (&btimer));
|
||||
assert_int_equal (7, update_backoff_delay (&btimer));
|
||||
assert_int_equal (15, update_backoff_delay (&btimer));
|
||||
assert_int_equal (31, update_backoff_delay (&btimer));
|
||||
assert_int_equal (31, update_backoff_delay (&btimer));
|
||||
|
||||
t1.tv_sec = 3; t1.tv_nsec = 0;
|
||||
t2.tv_sec = 3; t2.tv_nsec = 0;
|
||||
add_timespec (&t1, &t2);
|
||||
assert_int_equal (6, t2.tv_sec);
|
||||
assert_int_equal (0, t2.tv_nsec);
|
||||
|
||||
t1.tv_sec = 3; t1.tv_nsec = 500*1000000;
|
||||
t2.tv_sec = 3; t2.tv_nsec = 499*1000000;
|
||||
add_timespec (&t1, &t2);
|
||||
assert_int_equal (6, t2.tv_sec);
|
||||
assert_int_equal (999*1000000, t2.tv_nsec);
|
||||
|
||||
t1.tv_sec = 3; t1.tv_nsec = 500*1000000;
|
||||
t2.tv_sec = 3; t2.tv_nsec = 501*1000000;
|
||||
add_timespec (&t1, &t2);
|
||||
assert_int_equal (7, t2.tv_sec);
|
||||
assert_int_equal (1000000, t2.tv_nsec);
|
||||
|
||||
assert_int_equal (3, calc_random_secs (0, 7));
|
||||
assert_int_equal (4, calc_random_secs (1, 7));
|
||||
assert_int_equal (7, calc_random_secs (15, 7));
|
||||
assert_int_equal (3, calc_random_secs (16, 15));
|
||||
assert_int_equal (14, calc_random_secs (30,15));
|
||||
|
||||
assert_int_equal (250000, calc_random_nsecs (500000));
|
||||
assert_int_equal (1, calc_random_nsecs (2000000002));
|
||||
|
||||
init_backoff_timer (&btimer, 5);
|
||||
t1.tv_sec = 0; t1.tv_nsec = 0;
|
||||
/* max delay is 3 */
|
||||
calc_random_expiration (0, 0, &btimer, &t1);
|
||||
assert_int_equal (3, t1.tv_sec);
|
||||
assert_int_equal (0, t1.tv_nsec);
|
||||
|
||||
t1.tv_sec = 0; t1.tv_nsec = 0;
|
||||
/* max delay is 7*/
|
||||
calc_random_expiration (15, 1073741824, &btimer, &t1);
|
||||
assert_int_equal (7, t1.tv_sec);
|
||||
assert_int_equal (536870912, t1.tv_nsec);
|
||||
|
||||
t1.tv_sec = 0; t1.tv_nsec = 0;
|
||||
/* max delay is 15 */
|
||||
calc_random_expiration (30, 2000000002, &btimer, &t1);
|
||||
assert_int_equal (14, t1.tv_sec);
|
||||
assert_int_equal (1, t1.tv_nsec);
|
||||
|
||||
t1.tv_sec = 0; t1.tv_nsec = 0;
|
||||
/* max delay is 31 */
|
||||
calc_random_expiration (32, 1, &btimer, &t1);
|
||||
assert_int_equal (3, t1.tv_sec);
|
||||
assert_int_equal (0, t1.tv_nsec);
|
||||
}
|
||||
|
||||
|
||||
@@ -362,16 +459,28 @@ void test_extra_headers ()
|
||||
|
||||
void test_set_current_server()
|
||||
{
|
||||
server_list_t server_list;
|
||||
create_connection_ctx_t ctx;
|
||||
memset (&ctx, 0xFF, sizeof(ctx));
|
||||
memset (&server_list, 0xFF, sizeof(server_list));
|
||||
memset (&ctx, 0, sizeof(ctx));
|
||||
ctx.server_list = &server_list;
|
||||
set_current_server (&ctx);
|
||||
assert_ptr_equal (&ctx.server_list.redirect, ctx.current_server);
|
||||
set_server_null (&ctx.server_list.redirect);
|
||||
assert_ptr_equal (&ctx.server_list->redirect, ctx.current_server);
|
||||
set_server_null (&ctx.server_list->redirect);
|
||||
set_current_server (&ctx);
|
||||
assert_ptr_equal (&ctx.server_list.jwt, ctx.current_server);
|
||||
set_server_null (&ctx.server_list.jwt);
|
||||
assert_ptr_equal (&ctx.server_list->jwt, ctx.current_server);
|
||||
set_server_null (&ctx.server_list->jwt);
|
||||
set_current_server (&ctx);
|
||||
assert_ptr_equal (&ctx.server_list.defaults, ctx.current_server);
|
||||
assert_ptr_equal (&ctx.server_list->defaults, ctx.current_server);
|
||||
}
|
||||
|
||||
void init_cfg_header_info (ParodusCfg *cfg)
|
||||
{
|
||||
parStrncpy(cfg->hw_mac , "123567892366", sizeof(cfg->hw_mac));
|
||||
parStrncpy(cfg->hw_model, "TG1682", sizeof(cfg->hw_model));
|
||||
parStrncpy(cfg->hw_manufacturer , "ARRISGroup,Inc.", sizeof(cfg->hw_manufacturer));
|
||||
parStrncpy(cfg->fw_name , "2.364s2", sizeof(cfg->fw_name));
|
||||
parStrncpy(cfg->webpa_protocol , "WebPA-1.6", sizeof(cfg->webpa_protocol));
|
||||
}
|
||||
|
||||
void test_set_extra_headers ()
|
||||
@@ -380,7 +489,6 @@ void test_set_extra_headers ()
|
||||
create_connection_ctx_t ctx;
|
||||
ParodusCfg cfg;
|
||||
const char *expected_extra_headers =
|
||||
"\r\nAuthorization: Bearer SER_MAC Fer23u948590 123567892366"
|
||||
"\r\nX-WebPA-Device-Name: mac:123567892366"
|
||||
"\r\nX-WebPA-Device-Protocols: wrp-0.11,getset-0.1"
|
||||
"\r\nUser-Agent: WebPA-1.6 (2.364s2; TG1682/ARRISGroup,Inc.;)"
|
||||
@@ -389,16 +497,10 @@ void test_set_extra_headers ()
|
||||
memset(&cfg,0,sizeof(cfg));
|
||||
memset (&ctx, 0, sizeof(ctx));
|
||||
|
||||
parStrncpy (cfg.token_acquisition_script, "../../tests/return_success.bsh",
|
||||
sizeof(cfg.token_acquisition_script));
|
||||
parStrncpy (cfg.token_read_script, "../../tests/return_ser_mac.bsh",
|
||||
sizeof(cfg.token_read_script));
|
||||
cfg.client_cert_path = strdup("testcert");
|
||||
parStrncpy(cfg.hw_serial_number, "Fer23u948590", sizeof(cfg.hw_serial_number));
|
||||
parStrncpy(cfg.hw_mac , "123567892366", sizeof(cfg.hw_mac));
|
||||
parStrncpy(cfg.hw_model, "TG1682", sizeof(cfg.hw_model));
|
||||
parStrncpy(cfg.hw_manufacturer , "ARRISGroup,Inc.", sizeof(cfg.hw_manufacturer));
|
||||
parStrncpy(cfg.fw_name , "2.364s2", sizeof(cfg.fw_name));
|
||||
parStrncpy(cfg.webpa_protocol , "WebPA-1.6", sizeof(cfg.webpa_protocol));
|
||||
init_cfg_header_info (&cfg);
|
||||
parStrncpy(cfg.cert_path , "/etc/ssl/certs/ca-certificates.crt", sizeof(cfg.cert_path));
|
||||
|
||||
set_parodus_cfg(&cfg);
|
||||
rtn = init_header_info (&ctx.header_info);
|
||||
@@ -409,9 +511,9 @@ void test_set_extra_headers ()
|
||||
assert_string_equal (ctx.header_info.conveyHeader, "WebPA-1.6 (TG1682)");
|
||||
set_extra_headers (&ctx, true);
|
||||
|
||||
assert_string_equal (get_parodus_cfg()->webpa_auth_token,
|
||||
"SER_MAC Fer23u948590 123567892366");
|
||||
assert_string_equal (ctx.extra_headers, expected_extra_headers);
|
||||
if(cfg.client_cert_path !=NULL) {
|
||||
free(cfg.client_cert_path); }
|
||||
free (ctx.extra_headers);
|
||||
free_header_info (&ctx.header_info);
|
||||
|
||||
@@ -515,34 +617,58 @@ void test_nopoll_connect ()
|
||||
test_server.allow_insecure = 1;
|
||||
will_return (nopoll_conn_new_opts, NULL);
|
||||
expect_function_call (nopoll_conn_new_opts);
|
||||
will_return (checkHostIp, 0);
|
||||
expect_function_call (checkHostIp);
|
||||
//will_return (checkHostIp, 0);
|
||||
//expect_function_call (checkHostIp);
|
||||
assert_int_equal (nopoll_connect (&ctx, true), 0);
|
||||
assert_ptr_equal(NULL, get_global_conn());
|
||||
|
||||
test_server.allow_insecure = 0;
|
||||
will_return (nopoll_conn_tls_new6, NULL);
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
//will_return (checkHostIp, 0);
|
||||
//expect_function_call (checkHostIp);
|
||||
assert_int_equal (nopoll_connect (&ctx, true), 0);
|
||||
assert_ptr_equal(NULL, get_global_conn());
|
||||
|
||||
will_return (nopoll_conn_tls_new, NULL);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (checkHostIp, 0);
|
||||
expect_function_call (checkHostIp);
|
||||
assert_int_equal (nopoll_connect (&ctx, true), 0);
|
||||
assert_int_equal (nopoll_connect (&ctx, false), 0);
|
||||
assert_ptr_equal(NULL, get_global_conn());
|
||||
|
||||
will_return (nopoll_conn_tls_new6, NULL);
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
//will_return (checkHostIp, -2);
|
||||
//expect_function_call (checkHostIp);
|
||||
assert_int_equal (nopoll_connect (&ctx, true), 0);
|
||||
assert_ptr_equal(NULL, get_global_conn());
|
||||
|
||||
will_return (nopoll_conn_tls_new, NULL);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (checkHostIp, -2);
|
||||
expect_function_call (checkHostIp);
|
||||
assert_int_equal (nopoll_connect (&ctx, true), 0);
|
||||
assert_int_equal (nopoll_connect (&ctx, false), 0);
|
||||
assert_ptr_equal(NULL, get_global_conn());
|
||||
|
||||
will_return (nopoll_conn_tls_new6, NULL);
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
//will_return (checkHostIp, -2);
|
||||
//expect_function_call (checkHostIp);
|
||||
//ctx.connect_timer.start_time.tv_sec -= (15*60);
|
||||
//will_return(kill, 1);
|
||||
//expect_function_call(kill);
|
||||
assert_int_equal (nopoll_connect (&ctx, true), 0);
|
||||
assert_ptr_equal(NULL, get_global_conn());
|
||||
|
||||
will_return (nopoll_conn_tls_new, NULL);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (checkHostIp, -2);
|
||||
expect_function_call (checkHostIp);
|
||||
ctx.connect_timer.start_time.tv_sec -= (15*60);
|
||||
will_return(kill, 1);
|
||||
expect_function_call(kill);
|
||||
assert_int_equal (nopoll_connect (&ctx, true), 0);
|
||||
assert_int_equal (nopoll_connect (&ctx, false), 0);
|
||||
assert_ptr_equal(NULL, get_global_conn());
|
||||
|
||||
init_expire_timer (&ctx.connect_timer);
|
||||
@@ -556,22 +682,17 @@ void test_nopoll_connect ()
|
||||
|
||||
// Return codes for wait_connection_ready
|
||||
#define WAIT_SUCCESS 0
|
||||
#define WAIT_ACTION_RETRY 1 // if wait_status is 307, 302, 303 or 403
|
||||
#define WAIT_ACTION_RETRY 1 // if wait_status is 307, 302, 303, or 403
|
||||
#define WAIT_FAIL 2
|
||||
|
||||
void test_wait_connection_ready ()
|
||||
{
|
||||
server_list_t server_list;
|
||||
create_connection_ctx_t ctx;
|
||||
ParodusCfg Cfg;
|
||||
const char *expected_extra_headers =
|
||||
"\r\nAuthorization: Bearer Auth---"
|
||||
"\r\nX-WebPA-Device-Name: mac:123567892366"
|
||||
"\r\nX-WebPA-Device-Protocols: wrp-0.11,getset-0.1"
|
||||
"\r\nUser-Agent: WebPA-1.6 (2.364s2; TG1682/ARRISGroup,Inc.;)"
|
||||
"\r\nX-WebPA-Convey: WebPA-1.6 (TG1682)";
|
||||
|
||||
set_server_list_null (&server_list);
|
||||
memset(&ctx,0,sizeof(ctx));
|
||||
set_server_list_null (&ctx.server_list);
|
||||
ctx.server_list = &server_list;
|
||||
|
||||
mock_wait_status = 0;
|
||||
mock_redirect = NULL;
|
||||
@@ -583,7 +704,7 @@ void test_wait_connection_ready ()
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
assert_int_equal (wait_connection_ready (&ctx), WAIT_FAIL);
|
||||
|
||||
|
||||
mock_wait_status = 503;
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
@@ -600,51 +721,40 @@ void test_wait_connection_ready ()
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
assert_int_equal (wait_connection_ready (&ctx), WAIT_ACTION_RETRY);
|
||||
assert_string_equal (ctx.server_list.redirect.server_addr, "mydns.mycom.net");
|
||||
assert_int_equal (ctx.server_list.redirect.port, 8080);
|
||||
assert_int_equal (0, ctx.server_list.redirect.allow_insecure);
|
||||
assert_ptr_equal (ctx.current_server, &ctx.server_list.redirect);
|
||||
free_server (&ctx.server_list.redirect);
|
||||
assert_string_equal (ctx.server_list->redirect.server_addr, "mydns.mycom.net");
|
||||
assert_int_equal (ctx.server_list->redirect.port, 8080);
|
||||
assert_int_equal (0, ctx.server_list->redirect.allow_insecure);
|
||||
assert_ptr_equal (ctx.current_server, &ctx.server_list->redirect);
|
||||
free_server (&ctx.server_list->redirect);
|
||||
|
||||
mock_wait_status = 303;
|
||||
mock_redirect = "http://mydns.mycom.net";
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
assert_int_equal (wait_connection_ready (&ctx), WAIT_ACTION_RETRY);
|
||||
assert_string_equal (ctx.server_list.redirect.server_addr, "mydns.mycom.net");
|
||||
assert_int_equal (ctx.server_list.redirect.port, 80);
|
||||
assert_int_equal (1, ctx.server_list.redirect.allow_insecure);
|
||||
assert_ptr_equal (ctx.current_server, &ctx.server_list.redirect);
|
||||
free_server (&ctx.server_list.redirect);
|
||||
assert_string_equal (ctx.server_list->redirect.server_addr, "mydns.mycom.net");
|
||||
assert_int_equal (ctx.server_list->redirect.port, 80);
|
||||
assert_int_equal (1, ctx.server_list->redirect.allow_insecure);
|
||||
assert_ptr_equal (ctx.current_server, &ctx.server_list->redirect);
|
||||
free_server (&ctx.server_list->redirect);
|
||||
|
||||
mock_wait_status = 403;
|
||||
memset(&Cfg, 0, sizeof(ParodusCfg));
|
||||
|
||||
parStrncpy (Cfg.webpa_auth_token, "Auth---", sizeof (Cfg.webpa_auth_token));
|
||||
parStrncpy(Cfg.hw_model, "TG1682", sizeof(Cfg.hw_model));
|
||||
parStrncpy(Cfg.hw_manufacturer , "ARRISGroup,Inc.", sizeof(Cfg.hw_manufacturer));
|
||||
parStrncpy(Cfg.hw_mac , "123567892366", sizeof(Cfg.hw_mac));
|
||||
parStrncpy(Cfg.fw_name , "2.364s2", sizeof(Cfg.fw_name));
|
||||
parStrncpy(Cfg.webpa_protocol , "WebPA-1.6", sizeof(Cfg.webpa_protocol));
|
||||
set_parodus_cfg(&Cfg);
|
||||
|
||||
init_header_info (&ctx.header_info);
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
assert_int_equal (wait_connection_ready (&ctx), WAIT_ACTION_RETRY);
|
||||
|
||||
assert_string_equal (ctx.extra_headers, expected_extra_headers);
|
||||
|
||||
free_extra_headers (&ctx);
|
||||
free_header_info (&ctx.header_info);
|
||||
}
|
||||
|
||||
// Return codes for connect_and_wait
|
||||
#define CONN_WAIT_SUCCESS 0
|
||||
#define CONN_WAIT_ACTION_RETRY 1 // if wait_status is 307, 302, 303 or 403
|
||||
#define CONN_WAIT_RETRY_DNS 2
|
||||
#define CONN_WAIT_ACTION_RETRY 1 // if wait_status is 307, 302, 303, or 403
|
||||
#define CONN_WAIT_RETRY_DNS 2
|
||||
|
||||
void test_connect_and_wait ()
|
||||
{
|
||||
server_list_t server_list;
|
||||
create_connection_ctx_t ctx;
|
||||
noPollCtx test_nopoll_ctx;
|
||||
server_t test_server;
|
||||
@@ -661,7 +771,9 @@ void test_connect_and_wait ()
|
||||
|
||||
mock_wait_status = 0;
|
||||
|
||||
set_server_list_null (&server_list);
|
||||
memset(&ctx,0,sizeof(ctx));
|
||||
ctx.server_list = &server_list;
|
||||
ctx.nopoll_ctx = &test_nopoll_ctx;
|
||||
ctx.current_server = &test_server;
|
||||
ctx.extra_headers = test_extra_headers;
|
||||
@@ -685,8 +797,6 @@ void test_connect_and_wait ()
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
assert_int_equal (connect_and_wait (&ctx), CONN_WAIT_RETRY_DNS);
|
||||
|
||||
Cfg.flags = 0;
|
||||
@@ -696,8 +806,6 @@ void test_connect_and_wait ()
|
||||
expect_function_call (nopoll_conn_new_opts);
|
||||
will_return (nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
assert_int_equal (connect_and_wait (&ctx), CONN_WAIT_RETRY_DNS);
|
||||
|
||||
will_return (nopoll_conn_new_opts, &connection1);
|
||||
@@ -714,8 +822,8 @@ void test_connect_and_wait ()
|
||||
test_server.allow_insecure = 0;
|
||||
will_return (nopoll_conn_tls_new6, NULL);
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
will_return (checkHostIp, 0);
|
||||
expect_function_call (checkHostIp);
|
||||
//will_return (checkHostIp, 0);
|
||||
//expect_function_call (checkHostIp);
|
||||
assert_int_equal (connect_and_wait (&ctx), CONN_WAIT_RETRY_DNS);
|
||||
|
||||
Cfg.flags = 0;
|
||||
@@ -723,8 +831,8 @@ void test_connect_and_wait ()
|
||||
|
||||
will_return (nopoll_conn_tls_new6, NULL);
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
will_return (checkHostIp, 0);
|
||||
expect_function_call (checkHostIp);
|
||||
//will_return (checkHostIp, 0);
|
||||
//expect_function_call (checkHostIp);
|
||||
will_return (nopoll_conn_tls_new, NULL);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (checkHostIp, 0);
|
||||
@@ -735,8 +843,6 @@ void test_connect_and_wait ()
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
will_return (nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
will_return (nopoll_conn_tls_new, NULL);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (checkHostIp, 0);
|
||||
@@ -747,8 +853,6 @@ void test_connect_and_wait ()
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
will_return (nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
@@ -768,8 +872,6 @@ void test_connect_and_wait ()
|
||||
mock_redirect = "mydns.mycom.net";
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
assert_int_equal (connect_and_wait (&ctx), CONN_WAIT_RETRY_DNS);
|
||||
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
@@ -780,40 +882,34 @@ void test_connect_and_wait ()
|
||||
mock_redirect = "https://mydns.mycom.net";
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
assert_int_equal (connect_and_wait (&ctx), CONN_WAIT_ACTION_RETRY);
|
||||
}
|
||||
|
||||
void test_keep_trying ()
|
||||
{
|
||||
int rtn;
|
||||
server_list_t server_list;
|
||||
create_connection_ctx_t ctx;
|
||||
noPollCtx test_nopoll_ctx;
|
||||
server_t test_server;
|
||||
backoff_timer_t backoff_timer;
|
||||
ParodusCfg Cfg;
|
||||
char *test_extra_headers =
|
||||
"\r\nAuthorization: Bearer SER_MAC Fer23u948590 123567892366"
|
||||
"\r\nX-WebPA-Device-Name: mac:123567892366"
|
||||
"\r\nX-WebPA-Device-Protocols: wrp-0.11,getset-0.1"
|
||||
"\r\nUser-Agent: WebPA-1.6 (2.364s2; TG1682/ARRISGroup,Inc.;)"
|
||||
"\r\nX-WebPA-Convey: WebPA-1.6 (TG1682)";
|
||||
|
||||
memset(&Cfg, 0, sizeof(ParodusCfg));
|
||||
parStrncpy (Cfg.webpa_url, "http://mydns.mycom.net:8080", sizeof(Cfg.webpa_url));
|
||||
init_cfg_header_info (&Cfg);
|
||||
|
||||
mock_wait_status = 0;
|
||||
|
||||
set_server_list_null (&server_list);
|
||||
memset(&ctx,0,sizeof(ctx));
|
||||
ctx.server_list = &server_list;
|
||||
ctx.nopoll_ctx = &test_nopoll_ctx;
|
||||
ctx.current_server = &test_server;
|
||||
ctx.extra_headers = test_extra_headers;
|
||||
|
||||
test_server.allow_insecure = 1;
|
||||
test_server.server_addr = "mydns.mycom.net";
|
||||
test_server.port = 8080;
|
||||
|
||||
server_list.defaults.allow_insecure = 1;
|
||||
server_list.defaults.server_addr = "mydns.mycom.net";
|
||||
server_list.defaults.port = 8080;
|
||||
set_current_server (&ctx);
|
||||
|
||||
Cfg.flags = 0;
|
||||
set_parodus_cfg(&Cfg);
|
||||
|
||||
@@ -827,7 +923,7 @@ void test_keep_trying ()
|
||||
rtn = keep_trying_to_connect (&ctx, &backoff_timer);
|
||||
assert_int_equal (rtn, true);
|
||||
|
||||
test_server.allow_insecure = 0;
|
||||
server_list.defaults.allow_insecure = 0;
|
||||
Cfg.flags = FLAGS_IPV4_ONLY;
|
||||
set_parodus_cfg(&Cfg);
|
||||
|
||||
@@ -839,8 +935,6 @@ void test_keep_trying ()
|
||||
mock_redirect = "https://mydns.mycom.net";
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
@@ -859,16 +953,12 @@ void test_keep_trying ()
|
||||
mock_redirect = "https://mydns.mycom.net";
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
init_backoff_timer (&backoff_timer, 5);
|
||||
rtn = keep_trying_to_connect (&ctx, &backoff_timer);
|
||||
assert_int_equal (rtn, false);
|
||||
@@ -891,8 +981,6 @@ void test_keep_trying ()
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
init_backoff_timer (&backoff_timer, 5);
|
||||
rtn = keep_trying_to_connect (&ctx, &backoff_timer);
|
||||
assert_int_equal (rtn, false);
|
||||
@@ -902,8 +990,182 @@ void test_create_nopoll_connection()
|
||||
{
|
||||
int rtn;
|
||||
ParodusCfg cfg;
|
||||
server_list_t server_list;
|
||||
noPollCtx test_nopoll_ctx;
|
||||
|
||||
set_server_list_null (&server_list);
|
||||
memset(&cfg,0,sizeof(cfg));
|
||||
|
||||
cfg.flags = 0;
|
||||
parStrncpy (cfg.webpa_url, "mydns.mycom.net:8080", sizeof(cfg.webpa_url));
|
||||
cfg.boot_time = 25;
|
||||
parStrncpy (cfg.hw_last_reboot_reason, "Test reason", sizeof(cfg.hw_last_reboot_reason));
|
||||
cfg.webpa_backoff_max = 30;
|
||||
parStrncpy (cfg.webpa_auth_token, "Auth---", sizeof (cfg.webpa_auth_token));
|
||||
parStrncpy(cfg.hw_model, "TG1682", sizeof(cfg.hw_model));
|
||||
parStrncpy(cfg.hw_manufacturer , "ARRISGroup,Inc.", sizeof(cfg.hw_manufacturer));
|
||||
parStrncpy(cfg.hw_mac , "123567892366", sizeof(cfg.hw_mac));
|
||||
parStrncpy(cfg.fw_name , "2.364s2", sizeof(cfg.fw_name));
|
||||
parStrncpy(cfg.webpa_protocol , "WebPA-1.6", sizeof(cfg.webpa_protocol));
|
||||
set_parodus_cfg(&cfg);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
|
||||
assert_int_equal (rtn, nopoll_false);
|
||||
|
||||
parStrncpy (cfg.webpa_url, "http://mydns.mycom.net:8080", sizeof(cfg.webpa_url));
|
||||
set_parodus_cfg(&cfg);
|
||||
set_server_list_null (&server_list);
|
||||
|
||||
mock_wait_status = 0;
|
||||
|
||||
will_return (nopoll_conn_new_opts, &connection1);
|
||||
expect_function_call (nopoll_conn_new_opts);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
|
||||
assert_int_equal (rtn, nopoll_true);
|
||||
|
||||
parStrncpy (cfg.webpa_url, "https://mydns.mycom.net:8080", sizeof(cfg.webpa_url));
|
||||
cfg.flags = 0;
|
||||
set_parodus_cfg(&cfg);
|
||||
set_server_list_null (&server_list);
|
||||
|
||||
will_return (nopoll_conn_tls_new6, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
will_return (nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
|
||||
assert_int_equal (rtn, nopoll_true);
|
||||
|
||||
set_server_list_null (&server_list);
|
||||
|
||||
will_return (nopoll_conn_tls_new6, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
will_return (nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
mock_wait_status = 302;
|
||||
mock_redirect = "https://mydns.mycom.net";
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
|
||||
will_return (nopoll_conn_tls_new6, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
will_return (nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
mock_wait_status = 0;
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
|
||||
assert_int_equal (rtn, nopoll_true);
|
||||
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
cfg.acquire_jwt = 1;
|
||||
cfg.flags = FLAGS_IPV4_ONLY;
|
||||
set_parodus_cfg(&cfg);
|
||||
set_server_list_null (&server_list);
|
||||
|
||||
will_return (allow_insecure_conn, -1);
|
||||
expect_function_call (allow_insecure_conn);
|
||||
will_return (nopoll_conn_tls_new, NULL);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (checkHostIp, 0);
|
||||
expect_function_call (checkHostIp);
|
||||
mock_server_addr = "mydns.myjwtcom.net";
|
||||
mock_port = 80;
|
||||
will_return (allow_insecure_conn, 0);
|
||||
expect_function_call (allow_insecure_conn);
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
|
||||
assert_int_equal (rtn, nopoll_true);
|
||||
|
||||
set_server_list_null (&server_list);
|
||||
mock_server_addr = "mydns.myjwtcom.net";
|
||||
mock_port = 80;
|
||||
will_return (allow_insecure_conn, 0);
|
||||
expect_function_call (allow_insecure_conn);
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
|
||||
assert_int_equal (rtn, nopoll_true);
|
||||
|
||||
cfg.flags = 0;
|
||||
set_parodus_cfg(&cfg);
|
||||
set_server_list_null (&server_list);
|
||||
|
||||
will_return (allow_insecure_conn, -1);
|
||||
expect_function_call (allow_insecure_conn);
|
||||
will_return (nopoll_conn_tls_new6, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
will_return (nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
mock_wait_status = 0;
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
|
||||
assert_int_equal (rtn, nopoll_true);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void test_get_interface_down_event()
|
||||
{
|
||||
assert_false(get_interface_down_event());
|
||||
set_interface_down_event();
|
||||
}
|
||||
|
||||
void *a()
|
||||
{
|
||||
sleep(15);
|
||||
reset_interface_down_event();
|
||||
pthread_exit(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void test_interface_down_retry()
|
||||
{
|
||||
int rtn;
|
||||
ParodusCfg cfg;
|
||||
noPollCtx test_nopoll_ctx;
|
||||
server_list_t server_list;
|
||||
pthread_t thread_a;
|
||||
|
||||
pthread_create(&thread_a, NULL, a, NULL);
|
||||
|
||||
memset(&cfg,0,sizeof(cfg));
|
||||
cfg.flags = 0;
|
||||
parStrncpy (cfg.webpa_url, "mydns.mycom.net:8080", sizeof(cfg.webpa_url));
|
||||
@@ -917,7 +1179,8 @@ void test_create_nopoll_connection()
|
||||
parStrncpy(cfg.fw_name , "2.364s2", sizeof(cfg.fw_name));
|
||||
parStrncpy(cfg.webpa_protocol , "WebPA-1.6", sizeof(cfg.webpa_protocol));
|
||||
set_parodus_cfg(&cfg);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx);
|
||||
set_server_list_null (&server_list);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
|
||||
assert_int_equal (rtn, nopoll_false);
|
||||
|
||||
parStrncpy (cfg.webpa_url, "http://mydns.mycom.net:8080", sizeof(cfg.webpa_url));
|
||||
@@ -931,7 +1194,8 @@ void test_create_nopoll_connection()
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx);
|
||||
set_server_list_null (&server_list);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
|
||||
assert_int_equal (rtn, nopoll_true);
|
||||
|
||||
parStrncpy (cfg.webpa_url, "https://mydns.mycom.net:8080", sizeof(cfg.webpa_url));
|
||||
@@ -942,23 +1206,20 @@ void test_create_nopoll_connection()
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
will_return (nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx);
|
||||
set_server_list_null (&server_list);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
|
||||
assert_int_equal (rtn, nopoll_true);
|
||||
|
||||
will_return (nopoll_conn_tls_new6, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
will_return (nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
@@ -967,15 +1228,11 @@ void test_create_nopoll_connection()
|
||||
mock_redirect = "https://mydns.mycom.net";
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
|
||||
will_return (nopoll_conn_tls_new6, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
will_return (nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (nopoll_conn_is_ok, nopoll_true);
|
||||
@@ -983,7 +1240,8 @@ void test_create_nopoll_connection()
|
||||
mock_wait_status = 0;
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx);
|
||||
set_server_list_null (&server_list);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
|
||||
assert_int_equal (rtn, nopoll_true);
|
||||
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
@@ -1007,7 +1265,8 @@ void test_create_nopoll_connection()
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx);
|
||||
set_server_list_null (&server_list);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
|
||||
assert_int_equal (rtn, nopoll_true);
|
||||
|
||||
cfg.flags = 0;
|
||||
@@ -1019,8 +1278,6 @@ void test_create_nopoll_connection()
|
||||
expect_function_call (nopoll_conn_tls_new6);
|
||||
will_return (nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
mock_wait_status = 0;
|
||||
will_return (nopoll_conn_tls_new, &connection1);
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
@@ -1028,12 +1285,12 @@ void test_create_nopoll_connection()
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx);
|
||||
set_server_list_null (&server_list);
|
||||
rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
|
||||
assert_int_equal (rtn, nopoll_true);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
pthread_join(thread_a, NULL);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
@@ -1061,7 +1318,9 @@ int main(void)
|
||||
cmocka_unit_test(test_wait_connection_ready),
|
||||
cmocka_unit_test(test_connect_and_wait),
|
||||
cmocka_unit_test(test_keep_trying),
|
||||
cmocka_unit_test(test_create_nopoll_connection)
|
||||
cmocka_unit_test(test_create_nopoll_connection),
|
||||
cmocka_unit_test(test_get_interface_down_event),
|
||||
cmocka_unit_test(test_interface_down_retry)
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -35,9 +35,11 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
bool g_shutdown = false;
|
||||
extern CrudMsg *crudMsgQ;
|
||||
int numLoops = 1;
|
||||
wrp_msg_t *temp = NULL;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -123,6 +125,10 @@ int processCrudRequest(wrp_msg_t *reqMsg, wrp_msg_t **responseMsg )
|
||||
return (int)mock();
|
||||
}
|
||||
|
||||
char* getWebpaInterface(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
@@ -32,8 +32,10 @@
|
||||
#include "../src/connection.h"
|
||||
#include "../src/close_retry.h"
|
||||
|
||||
bool LastReasonStatus;
|
||||
pthread_mutex_t close_mut;
|
||||
char *get_global_reconnect_reason()
|
||||
{
|
||||
return "parodus_stopping";
|
||||
}
|
||||
|
||||
void set_global_reconnect_reason(char *reason)
|
||||
{
|
||||
@@ -165,7 +167,7 @@ void test_retrieveFromMemory()
|
||||
assert_int_equal (ret, 0);
|
||||
ret = retrieveFromMemory("webpa-protocol", &jsonresponse );
|
||||
assert_int_equal (ret, 0);
|
||||
ret = retrieveFromMemory("webpa-inteface-used", &jsonresponse );
|
||||
ret = retrieveFromMemory("webpa-interface-used", &jsonresponse );
|
||||
assert_int_equal (ret, 0);
|
||||
ret = retrieveFromMemory("webpa-backoff-max", &jsonresponse );
|
||||
assert_int_equal (ret, 0);
|
||||
@@ -200,7 +202,7 @@ void test_retrieveFromMemoryFailure()
|
||||
assert_int_equal (ret, -1);
|
||||
ret = retrieveFromMemory("webpa-protocol", &jsonresponse );
|
||||
assert_int_equal (ret, -1);
|
||||
ret = retrieveFromMemory("webpa-inteface-used", &jsonresponse );
|
||||
ret = retrieveFromMemory("webpa-interface-used", &jsonresponse );
|
||||
assert_int_equal (ret, -1);
|
||||
ret = retrieveFromMemory("webpa-backoff-max", &jsonresponse );
|
||||
assert_int_equal (ret, 0);
|
||||
@@ -1528,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");
|
||||
|
||||
@@ -61,6 +61,21 @@ reg_list_item_t * get_global_node(void)
|
||||
return mock_ptr_type(reg_list_item_t *);
|
||||
}
|
||||
|
||||
void release_global_node (void)
|
||||
{
|
||||
}
|
||||
void addToCloudAckQ(char *transaction_id, int qos, int rdr)
|
||||
{
|
||||
(void)transaction_id;
|
||||
(void)qos;
|
||||
(void)rdr;
|
||||
return;
|
||||
}
|
||||
bool highQosValueCheck(int qos)
|
||||
{
|
||||
(void)qos;
|
||||
return false;
|
||||
}
|
||||
ssize_t wrp_to_struct( const void *bytes, const size_t length,
|
||||
const enum wrp_format fmt, wrp_msg_t **msg )
|
||||
{
|
||||
@@ -68,7 +83,7 @@ ssize_t wrp_to_struct( const void *bytes, const size_t length,
|
||||
function_called();
|
||||
*msg = (wrp_msg_t*) malloc(sizeof(wrp_msg_t));
|
||||
memset(*msg, 0, sizeof(wrp_msg_t));
|
||||
(*msg)->msg_type = WRP_MSG_TYPE__REQ;
|
||||
(*msg)->msg_type = WRP_MSG_TYPE__REQ;
|
||||
(*msg)->u.req.dest = (char *) malloc(sizeof(char) *100);
|
||||
(*msg)->u.req.partner_ids = (partners_t *) malloc(sizeof(partners_t));
|
||||
(*msg)->u.req.partner_ids->count = 1;
|
||||
@@ -79,8 +94,10 @@ ssize_t wrp_to_struct( const void *bytes, const size_t length,
|
||||
{
|
||||
(*msg)->msg_type = WRP_MSG_TYPE__CREATE;
|
||||
parStrncpy((*msg)->u.crud.dest,"mac:1122334455/parodus", 100);
|
||||
(*msg)->u.crud.source = "tag-update";
|
||||
(*msg)->u.crud.transaction_uuid = "1234";
|
||||
(*msg)->u.crud.source = (char *) malloc(sizeof(char) *40);
|
||||
parStrncpy ((*msg)->u.crud.source, "tag-update", 40);
|
||||
(*msg)->u.crud.transaction_uuid = (char *) malloc(sizeof(char) *40);
|
||||
parStrncpy ((*msg)->u.crud.transaction_uuid, "1234", 40);
|
||||
}
|
||||
return (ssize_t) mock();
|
||||
}
|
||||
|
||||
@@ -192,6 +192,20 @@ int validate_partner_id(wrp_msg_t *msg, partners_t **partnerIds)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void addToCloudAckQ(char *transaction_id, int qos, int rdr)
|
||||
{
|
||||
(void)transaction_id;
|
||||
(void)qos;
|
||||
(void)rdr;
|
||||
return;
|
||||
}
|
||||
|
||||
bool highQosValueCheck(int qos)
|
||||
{
|
||||
(void)qos;
|
||||
return false;
|
||||
}
|
||||
|
||||
ssize_t wrp_to_struct( const void *bytes, const size_t length, const enum wrp_format fmt,
|
||||
wrp_msg_t **msg )
|
||||
{
|
||||
@@ -244,6 +258,10 @@ reg_list_item_t *get_global_node(void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void release_global_node (void)
|
||||
{
|
||||
}
|
||||
|
||||
void wrp_free_struct( wrp_msg_t *msg )
|
||||
{
|
||||
if( WRP_MSG_TYPE__EVENT == tests[i].s.msg_type ) {
|
||||
|
||||
@@ -79,7 +79,6 @@ void test_mutexHeartBeatTimer() {
|
||||
ParodusInfo("heartBeatTimer reset to: %d\n", heartBeatTimer);
|
||||
assert_int_equal(heartBeatTimer, 0);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
@@ -21,17 +21,18 @@
|
||||
#include <nopoll_private.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "../src/ParodusInternal.h"
|
||||
#include "../src/nopoll_handlers.h"
|
||||
#include "../src/parodus_log.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
volatile unsigned int heartBeatTimer;
|
||||
bool LastReasonStatus;
|
||||
bool interface_down_event = false;
|
||||
int closeReason = 0;
|
||||
pthread_mutex_t close_mut;
|
||||
bool close_retry;
|
||||
pthread_mutex_t interface_down_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t interface_down_con=PTHREAD_COND_INITIALIZER;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -46,6 +47,24 @@ bool get_global_reconnect_status()
|
||||
return LastReasonStatus;
|
||||
}
|
||||
|
||||
void set_interface_down_event()
|
||||
{
|
||||
interface_down_event = true;
|
||||
}
|
||||
|
||||
void reset_interface_down_event()
|
||||
{
|
||||
pthread_mutex_lock (&interface_down_mut);
|
||||
interface_down_event = false;
|
||||
pthread_cond_signal(&interface_down_con);
|
||||
pthread_mutex_unlock (&interface_down_mut);
|
||||
}
|
||||
|
||||
bool get_interface_down_event()
|
||||
{
|
||||
return interface_down_event;
|
||||
}
|
||||
|
||||
void set_global_reconnect_status(bool status)
|
||||
{
|
||||
(void) status ;
|
||||
@@ -179,6 +198,30 @@ void test_listenerOnPingMessage()
|
||||
listenerOnPingMessage(NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
void test_getInterfaceDownEvent()
|
||||
{
|
||||
set_interface_down_event();
|
||||
CU_ASSERT_TRUE(get_interface_down_event());
|
||||
}
|
||||
|
||||
void test_interfaceDownEvent()
|
||||
{
|
||||
char str[] = "SSL_Socket_Close";
|
||||
set_global_reconnect_status(true);
|
||||
set_interface_down_event();
|
||||
listenerOnCloseMessage(NULL, NULL, (noPollPtr) str);
|
||||
|
||||
}
|
||||
|
||||
void test_noInterfaceDownEvent()
|
||||
{
|
||||
char str[] = "SSL_Socket_Close";
|
||||
set_global_reconnect_status(true);
|
||||
reset_interface_down_event();
|
||||
listenerOnCloseMessage(NULL, NULL, (noPollPtr) str);
|
||||
}
|
||||
|
||||
|
||||
void add_suites( CU_pSuite *suite )
|
||||
{
|
||||
ParodusInfo("--------Start of Test Cases Execution ---------\n");
|
||||
@@ -186,6 +229,9 @@ void add_suites( CU_pSuite *suite )
|
||||
CU_add_test( *suite, "Test 1", test_listenerOnMessage_queue );
|
||||
CU_add_test( *suite, "Test 2", test_listenerOnCloseMessage );
|
||||
CU_add_test( *suite, "Test 3", test_listenerOnPingMessage );
|
||||
CU_add_test( *suite, "Test 4", test_getInterfaceDownEvent );
|
||||
CU_add_test( *suite, "Test 5", test_interfaceDownEvent );
|
||||
CU_add_test( *suite, "Test 6", test_noInterfaceDownEvent );
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
@@ -30,10 +30,7 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
volatile unsigned int heartBeatTimer;
|
||||
bool LastReasonStatus;
|
||||
pthread_mutex_t close_mut;
|
||||
bool close_retry;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -48,6 +45,11 @@ bool get_global_reconnect_status()
|
||||
return LastReasonStatus;
|
||||
}
|
||||
|
||||
bool get_interface_down_event()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void set_global_reconnect_status(bool status)
|
||||
{
|
||||
(void) status ;
|
||||
@@ -66,7 +68,6 @@ nopoll_bool nopoll_msg_is_final(noPollMsg *msg)
|
||||
function_called();
|
||||
return (nopoll_bool) mock();
|
||||
}
|
||||
|
||||
const unsigned char *nopoll_msg_get_payload(noPollMsg *msg)
|
||||
{
|
||||
(void)msg;
|
||||
|
||||
@@ -16,12 +16,17 @@
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
#include <nopoll.h>
|
||||
|
||||
#include "../src/parodus_log.h"
|
||||
#include "../src/nopoll_helpers.h"
|
||||
#include "../src/config.h"
|
||||
#include <cjwt/cjwt.h>
|
||||
#include "../src/connection.h"
|
||||
#include "../src/ParodusInternal.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Macros */
|
||||
@@ -31,7 +36,8 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static noPollConn *conn;
|
||||
static noPollConn *conn = NULL;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -116,6 +122,12 @@ int kill(pid_t pid, int sig)
|
||||
return (int) mock();
|
||||
}
|
||||
|
||||
bool get_interface_down_event()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -206,13 +218,7 @@ void test_sendMessage()
|
||||
{
|
||||
int len = strlen("Hello Parodus!");
|
||||
|
||||
expect_value(nopoll_conn_is_ok, (intptr_t)conn, (intptr_t)conn);
|
||||
will_return(nopoll_conn_is_ok, nopoll_true);
|
||||
expect_function_call(nopoll_conn_is_ok);
|
||||
|
||||
expect_value(nopoll_conn_is_ready, (intptr_t)conn, (intptr_t)conn);
|
||||
will_return(nopoll_conn_is_ready, nopoll_true);
|
||||
expect_function_call(nopoll_conn_is_ready);
|
||||
get_parodus_cfg()->cloud_status = CLOUD_STATUS_ONLINE;
|
||||
|
||||
expect_value(__nopoll_conn_send_common, (intptr_t)conn, (intptr_t)conn);
|
||||
expect_value(__nopoll_conn_send_common, length, len);
|
||||
@@ -222,81 +228,21 @@ void test_sendMessage()
|
||||
sendMessage(conn, "Hello Parodus!", len);
|
||||
}
|
||||
|
||||
void connStuck_sendMessage()
|
||||
void test_sendMessageOffline()
|
||||
{
|
||||
int len = strlen("Hello Parodus!");
|
||||
|
||||
/* Initialize the timer when connection gets stuck */
|
||||
expect_value(nopoll_conn_is_ok, (intptr_t)conn, (intptr_t)NULL);
|
||||
will_return(nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call(nopoll_conn_is_ok);
|
||||
|
||||
expect_function_call(getCurrentTime);
|
||||
sendMessage(NULL, "Hello Parodus!", len);
|
||||
|
||||
/* When connection recovers within 10 mins, it should be able to re-connect */
|
||||
expect_value(nopoll_conn_is_ok, (intptr_t)conn, (intptr_t)NULL);
|
||||
will_return(nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call(nopoll_conn_is_ok);
|
||||
|
||||
expect_function_call(getCurrentTime);
|
||||
|
||||
will_return(timeValDiff, 5*60*1000);
|
||||
expect_function_call(timeValDiff);
|
||||
|
||||
expect_value(nopoll_conn_is_ok, (intptr_t)conn, (intptr_t)conn);
|
||||
will_return(nopoll_conn_is_ok, nopoll_true);
|
||||
expect_function_call(nopoll_conn_is_ok);
|
||||
|
||||
expect_value(nopoll_conn_is_ready, (intptr_t)conn, (intptr_t)conn);
|
||||
will_return(nopoll_conn_is_ready, nopoll_true);
|
||||
expect_function_call(nopoll_conn_is_ready);
|
||||
|
||||
expect_value(__nopoll_conn_send_common, (intptr_t)conn, (intptr_t)conn);
|
||||
expect_value(__nopoll_conn_send_common, length, len);
|
||||
will_return(__nopoll_conn_send_common, len);
|
||||
expect_function_calls(__nopoll_conn_send_common, 1);
|
||||
|
||||
int len = strlen("Hello Parodus!");
|
||||
|
||||
get_parodus_cfg()->cloud_status = CLOUD_STATUS_OFFLINE;
|
||||
sendMessage(conn, "Hello Parodus!", len);
|
||||
|
||||
/* When timer exceeds more than 10 mins kill the process */
|
||||
expect_value(nopoll_conn_is_ok, (intptr_t)conn, (intptr_t)NULL);
|
||||
will_return(nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call(nopoll_conn_is_ok);
|
||||
|
||||
sendMessage(NULL, "Hello Parodus!", len);
|
||||
|
||||
expect_function_call(getCurrentTime);
|
||||
|
||||
sendMessage(NULL, "Hello Parodus!", len);
|
||||
|
||||
expect_value(nopoll_conn_is_ok, (intptr_t)conn, (intptr_t)NULL);
|
||||
will_return(nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call(nopoll_conn_is_ok);
|
||||
|
||||
expect_function_call(getCurrentTime);
|
||||
|
||||
will_return(timeValDiff, 10*60*1000);
|
||||
expect_function_call(timeValDiff);
|
||||
|
||||
will_return(kill, 1);
|
||||
expect_function_call(kill);
|
||||
|
||||
sendMessage(NULL, "Hello Parodus!", len);
|
||||
|
||||
}
|
||||
|
||||
void err_sendMessage()
|
||||
{
|
||||
int len = strlen("Hello Parodus!");
|
||||
|
||||
expect_value(nopoll_conn_is_ok, (intptr_t)conn, (intptr_t)conn);
|
||||
will_return(nopoll_conn_is_ok, nopoll_true);
|
||||
expect_function_call(nopoll_conn_is_ok);
|
||||
|
||||
expect_value(nopoll_conn_is_ready, (intptr_t)conn, (intptr_t)conn);
|
||||
will_return(nopoll_conn_is_ready, nopoll_true);
|
||||
expect_function_call(nopoll_conn_is_ready);
|
||||
|
||||
get_parodus_cfg()->cloud_status = CLOUD_STATUS_ONLINE;
|
||||
|
||||
expect_value(__nopoll_conn_send_common, (intptr_t)conn,(intptr_t) conn);
|
||||
expect_value(__nopoll_conn_send_common, length, len);
|
||||
will_return(__nopoll_conn_send_common, len-2);
|
||||
@@ -314,11 +260,12 @@ void err_sendMessageConnNull()
|
||||
{
|
||||
int len = strlen("Hello Parodus!");
|
||||
|
||||
expect_value(nopoll_conn_is_ok, (intptr_t)conn, (intptr_t)NULL);
|
||||
will_return(nopoll_conn_is_ok, nopoll_false);
|
||||
expect_function_call(nopoll_conn_is_ok);
|
||||
get_parodus_cfg()->cloud_status = CLOUD_STATUS_ONLINE;
|
||||
|
||||
expect_function_call(getCurrentTime);
|
||||
expect_value(__nopoll_conn_send_common, (intptr_t)conn, NULL);
|
||||
expect_value(__nopoll_conn_send_common, length, len);
|
||||
will_return(__nopoll_conn_send_common, len);
|
||||
expect_function_calls(__nopoll_conn_send_common, 1);
|
||||
|
||||
sendMessage(NULL, "Hello Parodus!", len);
|
||||
}
|
||||
@@ -343,7 +290,7 @@ int main(void)
|
||||
cmocka_unit_test(err_sendResponseFlushWrites),
|
||||
cmocka_unit_test(err_sendResponseConnNull),
|
||||
cmocka_unit_test(test_sendMessage),
|
||||
cmocka_unit_test(connStuck_sendMessage),
|
||||
cmocka_unit_test(test_sendMessageOffline),
|
||||
cmocka_unit_test(err_sendMessage),
|
||||
cmocka_unit_test(err_sendMessageConnNull),
|
||||
cmocka_unit_test(test_reportLog),
|
||||
|
||||
@@ -32,7 +32,20 @@ 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;
|
||||
|
||||
pthread_cond_t *get_global_crud_con(void)
|
||||
{
|
||||
return &crud_con;
|
||||
}
|
||||
|
||||
pthread_mutex_t *get_global_crud_mut(void)
|
||||
{
|
||||
return &crud_mut;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
@@ -48,12 +61,14 @@ void *CRUDHandlerTask()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void add_client()
|
||||
{
|
||||
const wrp_msg_t reg = { .msg_type = WRP_MSG_TYPE__SVC_REGISTRATION,
|
||||
.u.reg.service_name = "service_client",
|
||||
.u.reg.url = TEST_SERVICE_URL};
|
||||
|
||||
pthread_t test_tid;
|
||||
void *bytes;
|
||||
int size =0;
|
||||
int rv;
|
||||
@@ -71,7 +86,7 @@ static void add_client()
|
||||
ParodusPrint("decoded service_name:%s\n", message->u.reg.service_name);
|
||||
ParodusPrint("decoded dest:%s\n", message->u.reg.url);
|
||||
|
||||
StartThread(client_rcv_task);
|
||||
StartThread(client_rcv_task, &test_tid);
|
||||
status = addToList(&message);
|
||||
ParodusPrint("addToList status is %d\n", status);
|
||||
|
||||
@@ -134,7 +149,10 @@ static void *keep_alive_thread()
|
||||
//ParodusPrint("keep_alive threadId is %d\n", threadId);
|
||||
sleep(2);
|
||||
ParodusPrint("Starting serviceAliveTask..\n");
|
||||
serviceAliveTask();
|
||||
while (true) {
|
||||
serviceAliveTask();
|
||||
sleep (30);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#include "../src/ParodusInternal.h"
|
||||
#include "../src/spin_thread.h"
|
||||
|
||||
pthread_t test_tid;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -54,7 +56,7 @@ void *_routine(void *v)
|
||||
|
||||
void test_StartThread_error()
|
||||
{
|
||||
StartThread(&_routine);
|
||||
StartThread(&_routine, &test_tid);
|
||||
}
|
||||
|
||||
void add_suites( CU_pSuite *suite )
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#include "../src/ParodusInternal.h"
|
||||
#include "../src/spin_thread.h"
|
||||
|
||||
pthread_t test_tid;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -44,7 +46,7 @@ void *_routine(void *v)
|
||||
|
||||
void test_StartThread_success()
|
||||
{
|
||||
StartThread(&_routine);
|
||||
StartThread(&_routine, &test_tid);
|
||||
}
|
||||
|
||||
void add_suites( CU_pSuite *suite )
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
bool g_shutdown = false;
|
||||
ParodusMsg *ParodusMsgQ;
|
||||
pthread_mutex_t g_mutex;
|
||||
pthread_cond_t g_cond;
|
||||
|
||||
@@ -158,6 +158,20 @@ extern void read_key_from_file (const char *fname, char *buf, size_t buflen);
|
||||
extern const char *get_tok (const char *src, int delim, char *result, int resultsize);
|
||||
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)
|
||||
{
|
||||
return &crud_con;
|
||||
}
|
||||
|
||||
pthread_mutex_t *get_global_crud_mut(void)
|
||||
{
|
||||
return &crud_mut;
|
||||
}
|
||||
|
||||
void addCRUDmsgToQueue(wrp_msg_t *crudMsg)
|
||||
{
|
||||
(void)crudMsg;
|
||||
|
||||
@@ -23,14 +23,28 @@
|
||||
#include <cmocka.h>
|
||||
#include <assert.h>
|
||||
#include <wrp-c.h>
|
||||
|
||||
#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;
|
||||
|
||||
pthread_cond_t *get_global_crud_con(void)
|
||||
{
|
||||
return &crud_con;
|
||||
}
|
||||
|
||||
pthread_mutex_t *get_global_crud_mut(void)
|
||||
{
|
||||
return &crud_mut;
|
||||
}
|
||||
|
||||
void addCRUDmsgToQueue(wrp_msg_t *crudMsg)
|
||||
{
|
||||
(void)crudMsg;
|
||||
|
||||
@@ -38,14 +38,18 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static noPollConn *conn;
|
||||
static char *reconnect_reason = "webpa_process_starts";
|
||||
bool g_shutdown = false;
|
||||
static ParodusCfg parodusCfg;
|
||||
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 */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -66,6 +70,10 @@ reg_list_item_t * get_global_node(void)
|
||||
return mock_ptr_type(reg_list_item_t *);
|
||||
}
|
||||
|
||||
void release_global_node (void)
|
||||
{
|
||||
}
|
||||
|
||||
int get_numOfClients()
|
||||
{
|
||||
function_called();
|
||||
@@ -92,11 +100,45 @@ void sendMessage(noPollConn *conn, void *msg, size_t len)
|
||||
function_called();
|
||||
}
|
||||
|
||||
void set_parodus_cfg(ParodusCfg *cfg)
|
||||
{
|
||||
memcpy(&parodusCfg, cfg, sizeof(ParodusCfg));
|
||||
}
|
||||
|
||||
ParodusCfg *get_parodus_cfg(void)
|
||||
{
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg,0,sizeof(cfg));
|
||||
parStrncpy(cfg.hw_mac , "14cfe2142xxx", sizeof(cfg.hw_mac));
|
||||
if(deviceIDNull)
|
||||
{
|
||||
parStrncpy(cfg.hw_mac , "", sizeof(cfg.hw_mac));
|
||||
}
|
||||
set_parodus_cfg(&cfg);
|
||||
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;
|
||||
@@ -196,6 +238,13 @@ int nn_shutdown (int s, int how)
|
||||
return (int)mock();
|
||||
}
|
||||
|
||||
int nn_close (int s)
|
||||
{
|
||||
UNUSED(s);
|
||||
function_called();
|
||||
return (int)mock();
|
||||
}
|
||||
|
||||
int nn_setsockopt (int s, int level, int option, const void *optval, size_t optvallen)
|
||||
{
|
||||
UNUSED(s); UNUSED(level); UNUSED(option); UNUSED(optval); UNUSED(optvallen);
|
||||
@@ -241,10 +290,16 @@ void test_handleUpstreamNull()
|
||||
UpStreamMsgQ = NULL;
|
||||
will_return(nn_socket, 1);
|
||||
expect_function_call(nn_socket);
|
||||
will_return(nn_setsockopt, 0);
|
||||
expect_function_call(nn_setsockopt);
|
||||
will_return(nn_bind, 1);
|
||||
expect_function_call(nn_bind);
|
||||
will_return(nn_recv, 12);
|
||||
expect_function_call(nn_recv);
|
||||
will_return(nn_shutdown, 0);
|
||||
expect_function_call(nn_shutdown);
|
||||
will_return(nn_close, 0);
|
||||
expect_function_call(nn_close);
|
||||
handle_upstream();
|
||||
}
|
||||
|
||||
@@ -260,10 +315,16 @@ void test_handle_upstream()
|
||||
UpStreamMsgQ->next->next = NULL;
|
||||
will_return(nn_socket, 1);
|
||||
expect_function_call(nn_socket);
|
||||
will_return(nn_setsockopt, 0);
|
||||
expect_function_call(nn_setsockopt);
|
||||
will_return(nn_bind, 1);
|
||||
expect_function_call(nn_bind);
|
||||
will_return(nn_recv, 12);
|
||||
expect_function_call(nn_recv);
|
||||
will_return(nn_shutdown, 0);
|
||||
expect_function_call(nn_shutdown);
|
||||
will_return(nn_close, 0);
|
||||
expect_function_call(nn_close);
|
||||
handle_upstream();
|
||||
free(UpStreamMsgQ->next);
|
||||
free(UpStreamMsgQ);
|
||||
@@ -273,6 +334,8 @@ void err_handleUpstreamBindFailure()
|
||||
{
|
||||
will_return(nn_socket, 1);
|
||||
expect_function_call(nn_socket);
|
||||
will_return(nn_setsockopt, 0);
|
||||
expect_function_call(nn_setsockopt);
|
||||
will_return(nn_bind, -1);
|
||||
expect_function_call(nn_bind);
|
||||
handle_upstream();
|
||||
@@ -414,15 +477,18 @@ void test_processUpstreamMessageRegMsg()
|
||||
will_return(wrp_to_struct, 12);
|
||||
expect_function_call(wrp_to_struct);
|
||||
|
||||
will_return(get_numOfClients, 1);
|
||||
expect_function_call(get_numOfClients);
|
||||
|
||||
will_return(get_global_node, (intptr_t)head);
|
||||
expect_function_call(get_global_node);
|
||||
|
||||
will_return(get_numOfClients, 1);
|
||||
expect_function_call(get_numOfClients);
|
||||
|
||||
will_return(nn_shutdown, 1);
|
||||
expect_function_call(nn_shutdown);
|
||||
|
||||
will_return(nn_close, 0);
|
||||
expect_function_call(nn_close);
|
||||
|
||||
will_return(nn_socket, 1);
|
||||
expect_function_call(nn_socket);
|
||||
|
||||
@@ -473,6 +539,9 @@ void test_processUpstreamMessageRegMsgNoClients()
|
||||
will_return(wrp_to_struct, 12);
|
||||
expect_function_call(wrp_to_struct);
|
||||
|
||||
will_return(get_global_node, (intptr_t)head);
|
||||
expect_function_call(get_global_node);
|
||||
|
||||
will_return(get_numOfClients, 0);
|
||||
expect_function_call(get_numOfClients);
|
||||
|
||||
@@ -570,21 +639,27 @@ void err_processUpstreamMessageRegMsg()
|
||||
will_return(wrp_to_struct, 12);
|
||||
expect_function_call(wrp_to_struct);
|
||||
|
||||
will_return(get_numOfClients, 1);
|
||||
expect_function_call(get_numOfClients);
|
||||
|
||||
will_return(get_global_node, (intptr_t)head);
|
||||
expect_function_call(get_global_node);
|
||||
|
||||
will_return(get_numOfClients, 1);
|
||||
expect_function_call(get_numOfClients);
|
||||
|
||||
will_return(nn_shutdown, -1);
|
||||
expect_function_call(nn_shutdown);
|
||||
|
||||
will_return(nn_close, 0);
|
||||
expect_function_call(nn_close);
|
||||
|
||||
will_return(nn_socket, -1);
|
||||
expect_function_call(nn_socket);
|
||||
|
||||
will_return(nn_shutdown, 1);
|
||||
expect_function_call(nn_shutdown);
|
||||
|
||||
will_return(nn_close, 0);
|
||||
expect_function_call(nn_close);
|
||||
|
||||
will_return(nn_socket, 1);
|
||||
expect_function_call(nn_socket);
|
||||
|
||||
@@ -726,16 +801,16 @@ void test_processUpstreamMsg_cloud_status()
|
||||
|
||||
void test_processUpstreamMsg_sendToClient()
|
||||
{
|
||||
numLoops = 2;
|
||||
metaPackSize = 20;
|
||||
numLoops = 2;
|
||||
metaPackSize = 20;
|
||||
UpStreamMsgQ = (UpStreamMsg *) malloc(sizeof(UpStreamMsg));
|
||||
UpStreamMsgQ->msg = strdup("First Message");
|
||||
UpStreamMsgQ->len = 13;
|
||||
UpStreamMsgQ->next= NULL;
|
||||
UpStreamMsgQ->next = (UpStreamMsg *) malloc(sizeof(UpStreamMsg));
|
||||
UpStreamMsgQ->next->msg = strdup("Second Message");
|
||||
UpStreamMsgQ->next->len = 15;
|
||||
UpStreamMsgQ->next->next = NULL;
|
||||
UpStreamMsgQ->next->msg = strdup("Second Message");
|
||||
UpStreamMsgQ->next->len = 15;
|
||||
UpStreamMsgQ->next->next = NULL;
|
||||
|
||||
temp = (wrp_msg_t *) malloc(sizeof(wrp_msg_t));
|
||||
memset(temp,0,sizeof(wrp_msg_t));
|
||||
@@ -758,86 +833,66 @@ void test_processUpstreamMsg_sendToClient()
|
||||
|
||||
expect_function_call(wrp_free_struct);
|
||||
processUpstreamMessage();
|
||||
free(temp);
|
||||
free(UpStreamMsgQ);
|
||||
UpStreamMsgQ = NULL;
|
||||
}
|
||||
void test_processUpstreamMessageNullCheck()
|
||||
{
|
||||
numLoops = 1;
|
||||
metaPackSize = 20;
|
||||
UpStreamMsgQ = (UpStreamMsg *) malloc(sizeof(UpStreamMsg));
|
||||
UpStreamMsgQ->msg = strdup("First Message");
|
||||
UpStreamMsgQ->len = 13;
|
||||
UpStreamMsgQ->next= NULL;
|
||||
temp = (wrp_msg_t *) malloc(sizeof(wrp_msg_t));
|
||||
memset(temp,0,sizeof(wrp_msg_t));
|
||||
temp->msg_type = WRP_MSG_TYPE__RETREIVE;
|
||||
temp->u.crud.dest = strdup("mac:14cfe2142xxx/parodus/cloud-status");
|
||||
temp->u.crud.source = strdup("mac:14cfe2142xxx/config");
|
||||
temp->u.crud.transaction_uuid = strdup("123");
|
||||
will_return(wrp_to_struct, 12);
|
||||
expect_function_call(wrp_to_struct);
|
||||
expect_function_call(addCRUDmsgToQueue);
|
||||
will_return(nn_freemsg, 0);
|
||||
expect_function_call(nn_freemsg);
|
||||
expect_function_call(wrp_free_struct);
|
||||
processUpstreamMessage();
|
||||
free(temp);
|
||||
free(UpStreamMsgQ);
|
||||
UpStreamMsgQ = NULL;
|
||||
}
|
||||
void err_processUpstreamMessageNullCheck()
|
||||
{
|
||||
numLoops = 1;
|
||||
metaPackSize = 20;
|
||||
UpStreamMsgQ = (UpStreamMsg *) malloc(sizeof(UpStreamMsg));
|
||||
UpStreamMsgQ->msg = strdup("First Message");
|
||||
UpStreamMsgQ->len = 13;
|
||||
UpStreamMsgQ->next= NULL;
|
||||
temp = (wrp_msg_t *) malloc(sizeof(wrp_msg_t));
|
||||
memset(temp,0,sizeof(wrp_msg_t));
|
||||
temp->msg_type = WRP_MSG_TYPE__RETREIVE;
|
||||
temp->u.crud.dest = strdup("mac:/parodus/cloud-status");
|
||||
temp->u.crud.source = strdup("mac:14cfe2142xxx/config");
|
||||
temp->u.crud.transaction_uuid = strdup("123");
|
||||
will_return(wrp_to_struct, 12);
|
||||
expect_function_call(wrp_to_struct);
|
||||
will_return(nn_freemsg, 0);
|
||||
expect_function_call(nn_freemsg);
|
||||
expect_function_call(wrp_free_struct);
|
||||
|
||||
processUpstreamMessage();
|
||||
free(temp);
|
||||
free(UpStreamMsgQ);
|
||||
free(temp);
|
||||
free(UpStreamMsgQ);
|
||||
UpStreamMsgQ = NULL;
|
||||
}
|
||||
void err_processUpstreamMessageWithoutMac()
|
||||
|
||||
void test_processUpstreamMsg_serviceNameNULL()
|
||||
{
|
||||
numLoops = 1;
|
||||
metaPackSize = 20;
|
||||
UpStreamMsgQ = (UpStreamMsg *) malloc(sizeof(UpStreamMsg));
|
||||
UpStreamMsgQ->msg = strdup("First Message");
|
||||
UpStreamMsgQ->len = 13;
|
||||
UpStreamMsgQ->next= NULL;
|
||||
temp = (wrp_msg_t *) malloc(sizeof(wrp_msg_t));
|
||||
memset(temp,0,sizeof(wrp_msg_t));
|
||||
temp->msg_type = WRP_MSG_TYPE__RETREIVE;
|
||||
temp->u.crud.dest = strdup("/parodus/cloud-status");
|
||||
temp->u.crud.source = strdup("mac:14cfe2142xxx/config");
|
||||
temp->u.crud.transaction_uuid = strdup("123");
|
||||
will_return(wrp_to_struct, 12);
|
||||
expect_function_call(wrp_to_struct);
|
||||
will_return(nn_freemsg, 0);
|
||||
expect_function_call(nn_freemsg);
|
||||
expect_function_call(wrp_free_struct);
|
||||
|
||||
processUpstreamMessage();
|
||||
free(temp);
|
||||
free(UpStreamMsgQ);
|
||||
UpStreamMsgQ = NULL;
|
||||
numLoops = 1;
|
||||
metaPackSize = 20;
|
||||
UpStreamMsgQ = (UpStreamMsg *) malloc(sizeof(UpStreamMsg));
|
||||
UpStreamMsgQ->msg = strdup("First Message");
|
||||
UpStreamMsgQ->len = 13;
|
||||
UpStreamMsgQ->next= NULL;
|
||||
UpStreamMsgQ->next = (UpStreamMsg *) malloc(sizeof(UpStreamMsg));
|
||||
UpStreamMsgQ->next->msg = strdup("Second Message");
|
||||
UpStreamMsgQ->next->len = 15;
|
||||
UpStreamMsgQ->next->next = NULL;
|
||||
|
||||
temp = (wrp_msg_t *) malloc(sizeof(wrp_msg_t));
|
||||
memset(temp,0,sizeof(wrp_msg_t));
|
||||
temp->msg_type = 6;
|
||||
temp->u.crud.dest = strdup("mac:14cfe2142xxx/");
|
||||
temp->u.crud.source = strdup("mac:14cfe2142xxx/parodus/cloud-status");
|
||||
temp->u.crud.transaction_uuid = strdup("123");
|
||||
|
||||
will_return(wrp_to_struct, 12);
|
||||
expect_function_call(wrp_to_struct);
|
||||
expect_function_call(wrp_free_struct);
|
||||
processUpstreamMessage();
|
||||
free(temp);
|
||||
free(UpStreamMsgQ);
|
||||
UpStreamMsgQ = NULL;
|
||||
}
|
||||
|
||||
void err_processUpstreamMsg_deviceID()
|
||||
{
|
||||
numLoops = 1;
|
||||
metaPackSize = 20;
|
||||
deviceIDNull = 1;
|
||||
UpStreamMsgQ = (UpStreamMsg *) malloc(sizeof(UpStreamMsg));
|
||||
UpStreamMsgQ->msg = "First Message";
|
||||
UpStreamMsgQ->len = 13;
|
||||
UpStreamMsgQ->next= NULL;
|
||||
temp = (wrp_msg_t *) malloc(sizeof(wrp_msg_t));
|
||||
memset(temp,0,sizeof(wrp_msg_t));
|
||||
temp->msg_type = 6;
|
||||
temp->u.crud.dest = "mac:14cfe2142xxx/parodus/cloud-status";
|
||||
temp->u.crud.source = "mac:14cfe2142xxx/config";
|
||||
temp->u.crud.transaction_uuid = "123";
|
||||
|
||||
will_return(wrp_to_struct, 12);
|
||||
expect_function_call(wrp_to_struct);
|
||||
will_return(nn_freemsg, 0);
|
||||
expect_function_call(nn_freemsg);
|
||||
expect_function_call(wrp_free_struct);
|
||||
processUpstreamMessage();
|
||||
free(temp);
|
||||
free(UpStreamMsgQ);
|
||||
UpStreamMsgQ = NULL;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -870,9 +925,8 @@ int main(void)
|
||||
cmocka_unit_test(test_processUpstreamMsgCrud_nnfree),
|
||||
cmocka_unit_test(test_processUpstreamMsg_cloud_status),
|
||||
cmocka_unit_test(test_processUpstreamMsg_sendToClient),
|
||||
cmocka_unit_test(test_processUpstreamMessageNullCheck),
|
||||
cmocka_unit_test(err_processUpstreamMessageNullCheck),
|
||||
cmocka_unit_test(err_processUpstreamMessageWithoutMac),
|
||||
cmocka_unit_test(test_processUpstreamMsg_serviceNameNULL),
|
||||
cmocka_unit_test(err_processUpstreamMsg_deviceID)
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
|
||||
271
tests/test_upstream_sock.c
Normal file
271
tests/test_upstream_sock.c
Normal file
@@ -0,0 +1,271 @@
|
||||
/**
|
||||
* Copyright 2010-2016 Comcast Cable Communications Management, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <malloc.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <nopoll.h>
|
||||
#include <wrp-c.h>
|
||||
#include <nanomsg/nn.h>
|
||||
|
||||
#include "../src/upstream.h"
|
||||
#include "../src/config.h"
|
||||
#include "../src/client_list.h"
|
||||
#include "../src/ParodusInternal.h"
|
||||
#include "../src/partners_check.h"
|
||||
#include "../src/close_retry.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#define GOOD_CLIENT_URL "tcp://127.0.0.1:6667"
|
||||
|
||||
static noPollConn *conn;
|
||||
static char *reconnect_reason = "webpa_process_starts";
|
||||
bool g_shutdown = false;
|
||||
static ParodusCfg parodusCfg;
|
||||
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 */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
reg_list_item_t *get_reg_list()
|
||||
{
|
||||
reg_list_item_t *item = get_global_node();
|
||||
release_global_node();
|
||||
return item;
|
||||
}
|
||||
|
||||
noPollConn *get_global_conn()
|
||||
{
|
||||
return conn;
|
||||
}
|
||||
|
||||
char *get_global_reconnect_reason()
|
||||
{
|
||||
return reconnect_reason;
|
||||
}
|
||||
|
||||
void addCRUDmsgToQueue(wrp_msg_t *crudMsg)
|
||||
{
|
||||
(void)crudMsg;
|
||||
function_called();
|
||||
return;
|
||||
}
|
||||
|
||||
void sendMessage(noPollConn *conn, void *msg, size_t len)
|
||||
{
|
||||
(void) conn; (void) msg; (void) len;
|
||||
function_called();
|
||||
}
|
||||
|
||||
void set_parodus_cfg(ParodusCfg *cfg)
|
||||
{
|
||||
memcpy(&parodusCfg, cfg, sizeof(ParodusCfg));
|
||||
}
|
||||
|
||||
ParodusCfg *get_parodus_cfg(void)
|
||||
{
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg,0,sizeof(cfg));
|
||||
parStrncpy(cfg.hw_mac , "14cfe2142xxx", sizeof(cfg.hw_mac));
|
||||
if(deviceIDNull)
|
||||
{
|
||||
parStrncpy(cfg.hw_mac , "", sizeof(cfg.hw_mac));
|
||||
}
|
||||
set_parodus_cfg(&cfg);
|
||||
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)
|
||||
{
|
||||
(void) s; (void) addr;
|
||||
printf ("nn_connect, socket %d\n", s);
|
||||
return 1;
|
||||
}
|
||||
---------------------------------------------*/
|
||||
|
||||
ssize_t wrp_pack_metadata( const data_t *packData, void **data )
|
||||
{
|
||||
(void) packData; (void) data;
|
||||
function_called();
|
||||
|
||||
return (ssize_t)mock();
|
||||
}
|
||||
|
||||
size_t appendEncodedData( void **appendData, void *encodedBuffer, size_t encodedSize, void *metadataPack, size_t metadataSize )
|
||||
{
|
||||
(void) encodedBuffer; (void) encodedSize; (void) metadataPack; (void) metadataSize;
|
||||
function_called();
|
||||
char *data = (char *) malloc (sizeof(char) * 100);
|
||||
parStrncpy(data, "AAAAAAAAYYYYIGkYTUYFJH", 100);
|
||||
*appendData = data;
|
||||
return (size_t)mock();
|
||||
}
|
||||
|
||||
int nn_send (int s, const void *buf, size_t len, int flags)
|
||||
{
|
||||
UNUSED(s); UNUSED(buf); UNUSED(len); UNUSED(flags);
|
||||
function_called();
|
||||
return (int)mock();
|
||||
}
|
||||
|
||||
int pthread_cond_wait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex)
|
||||
{
|
||||
UNUSED(cond); UNUSED(mutex);
|
||||
function_called();
|
||||
return (int)mock();
|
||||
}
|
||||
|
||||
ssize_t wrp_to_struct( const void *bytes, const size_t length, const enum wrp_format fmt, wrp_msg_t **msg )
|
||||
{
|
||||
UNUSED(bytes); UNUSED(length); UNUSED(fmt);
|
||||
function_called();
|
||||
*msg = reg_msg;
|
||||
return (ssize_t)mock();
|
||||
}
|
||||
|
||||
void wrp_free_struct( wrp_msg_t *msg )
|
||||
{
|
||||
UNUSED(msg);
|
||||
function_called();
|
||||
}
|
||||
|
||||
int nn_freemsg (void *msg)
|
||||
{
|
||||
UNUSED(msg);
|
||||
function_called();
|
||||
return (int)mock();
|
||||
}
|
||||
|
||||
int validate_partner_id(wrp_msg_t *msg, partners_t **partnerIds)
|
||||
{
|
||||
UNUSED(msg); UNUSED(partnerIds);
|
||||
function_called();
|
||||
return (int) mock();
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
void test_message()
|
||||
{
|
||||
metaPackSize = 20;
|
||||
UpStreamMsgQ = (UpStreamMsg *) malloc(sizeof(UpStreamMsg));
|
||||
UpStreamMsgQ->msg = "First Message";
|
||||
UpStreamMsgQ->len = 13;
|
||||
UpStreamMsgQ->next = NULL;
|
||||
|
||||
numLoops = 1;
|
||||
reg_msg = (wrp_msg_t *) malloc(sizeof(wrp_msg_t));
|
||||
memset(reg_msg,0,sizeof(wrp_msg_t));
|
||||
reg_msg->msg_type = WRP_MSG_TYPE__SVC_REGISTRATION;
|
||||
reg_msg->u.reg.service_name = "config";
|
||||
reg_msg->u.reg.url = GOOD_CLIENT_URL;
|
||||
|
||||
will_return(wrp_to_struct, 12);
|
||||
expect_function_call(wrp_to_struct);
|
||||
|
||||
will_return(nn_send, 1);
|
||||
expect_function_call(nn_send);
|
||||
|
||||
will_return(nn_freemsg, 0);
|
||||
expect_function_call(nn_freemsg);
|
||||
expect_function_call(wrp_free_struct);
|
||||
|
||||
processUpstreamMessage();
|
||||
free(reg_msg);
|
||||
free(UpStreamMsgQ);
|
||||
}
|
||||
|
||||
void test_processUpstreamMessage()
|
||||
{
|
||||
int last_sock = -1;
|
||||
reg_list_item_t * reg_item = get_reg_list ();
|
||||
|
||||
assert_null (reg_item);
|
||||
test_message();
|
||||
reg_item = get_reg_list ();
|
||||
assert_non_null (reg_item);
|
||||
if (NULL == reg_item)
|
||||
return;
|
||||
|
||||
last_sock = reg_item->sock;
|
||||
test_message ();
|
||||
assert_int_equal (get_numOfClients(), 1);
|
||||
if (get_numOfClients() != 1)
|
||||
return;
|
||||
reg_item = get_reg_list ();
|
||||
assert_int_equal (last_sock, reg_item->sock);
|
||||
if (last_sock != reg_item->sock)
|
||||
return;
|
||||
|
||||
test_message ();
|
||||
assert_int_equal (get_numOfClients(), 1);
|
||||
if (get_numOfClients() != 1)
|
||||
return;
|
||||
reg_item = get_reg_list ();
|
||||
assert_int_equal (last_sock, reg_item->sock);
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(test_processUpstreamMessage)
|
||||
};
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
Reference in New Issue
Block a user