mirror of
https://github.com/outbackdingo/parodus.git
synced 2026-01-27 18:20:04 +00:00
Compare commits
213 Commits
1.0.1
...
parodus_de
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f032d2ca30 | ||
|
|
9cfc734c51 | ||
|
|
153add9bec | ||
|
|
7679fdaf4a | ||
|
|
1c09a80493 | ||
|
|
bfad8ed44b | ||
|
|
8c576f8f48 | ||
|
|
dacac5fe8d | ||
|
|
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 | ||
|
|
b48680c358 | ||
|
|
2304951186 | ||
|
|
85004c165c | ||
|
|
94b64af4a0 | ||
|
|
d190b8b10c | ||
|
|
4e24197d24 | ||
|
|
f4d544fc40 | ||
|
|
0972ff76fd | ||
|
|
ae8a9beb8e | ||
|
|
08ed64c822 | ||
|
|
c2f6a64569 | ||
|
|
2f0244af11 | ||
|
|
f0f2903106 | ||
|
|
8c83c4ce01 | ||
|
|
385a38f10a | ||
|
|
4abad4dc13 | ||
|
|
cbe184e00e | ||
|
|
25a6a6cc72 | ||
|
|
aabe6be96a | ||
|
|
9aa18cea1c | ||
|
|
2f762fe9a1 | ||
|
|
93363b35db | ||
|
|
7e8edcaca4 | ||
|
|
81290ffd84 | ||
|
|
8a69bc3955 | ||
|
|
3634aa0a70 | ||
|
|
08a09106cf | ||
|
|
f730a41cdb | ||
|
|
f79eeb066a | ||
|
|
b4a8d8b2da | ||
|
|
b42051bf96 | ||
|
|
cd1d1ba52b | ||
|
|
44554b0dfa | ||
|
|
3bb48b48c0 | ||
|
|
1addffdeb0 | ||
|
|
ce0c43d894 | ||
|
|
4f1952ddcc | ||
|
|
eda3823ef0 | ||
|
|
774f308680 | ||
|
|
130d8f2933 | ||
|
|
5f1650b009 | ||
|
|
5cf95ac1ab | ||
|
|
c1e1a8ebdc | ||
|
|
d82c9ea187 | ||
|
|
4562592536 | ||
|
|
cdd333cc3a | ||
|
|
7ae1d2a1c4 | ||
|
|
ed1ff2b105 | ||
|
|
166b7ec7c2 | ||
|
|
97ac941a81 | ||
|
|
844a1d925a | ||
|
|
ba690db3a1 | ||
|
|
a8d077dbf5 | ||
|
|
2c3b8fc994 | ||
|
|
35509cd5b2 | ||
|
|
4f74bc037d | ||
|
|
9e3b32af69 | ||
|
|
8a20d3a7c4 | ||
|
|
19a0bc26af | ||
|
|
558f007bdf | ||
|
|
2ba26b37dc | ||
|
|
da924e89a5 | ||
|
|
6a1d908407 | ||
|
|
7b496769fc | ||
|
|
1e05869ded | ||
|
|
e7bf8cf468 | ||
|
|
e40af91fa7 | ||
|
|
f88a3f11cc | ||
|
|
db07521d64 | ||
|
|
eb0281128d | ||
|
|
7432b6f9fb | ||
|
|
db70ecf934 | ||
|
|
c49a14cb00 | ||
|
|
b7e486994f | ||
|
|
9831cefd52 | ||
|
|
ff7472be5d | ||
|
|
6f36fb7861 | ||
|
|
d8b009b5d0 |
@@ -26,7 +26,7 @@ install:
|
||||
script:
|
||||
- mkdir build
|
||||
- cd build
|
||||
- cmake .. -DINTEGRATION_TESTING:BOOL=false -DDISABLE_VALGRIND:BOOL=true -DENABLE_SESHAT:BOOL=true -DFEATURE_DNS_QUERY:BOOL=true
|
||||
- cmake .. -DINTEGRATION_TESTING:BOOL=false -DDISABLE_VALGRIND:BOOL=false -DENABLE_SESHAT:BOOL=true -DFEATURE_DNS_QUERY:BOOL=true
|
||||
- make
|
||||
- export ARGS="-V"
|
||||
- make test
|
||||
|
||||
47
CHANGELOG.md
47
CHANGELOG.md
@@ -5,8 +5,52 @@ 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]
|
||||
- Refactor of connection code (simplification).
|
||||
- Security: Added support to use auth token during initial connect to cloud
|
||||
- Fix re-registration fails that lose a socket
|
||||
- Fix mutex error in service alive
|
||||
- Security: Mutual Authentication (mTLS or two way TLS)
|
||||
- Rename command line options for MTLS cert and Key
|
||||
- Update to use nanomsg v. 1.1.4
|
||||
- requestNewAuthToken will clear the token if it fails.
|
||||
- request auth token on every retry, not just after 403
|
||||
- update to use nopoll v 1.0.2
|
||||
- Add pause/resume heartBeatTimer
|
||||
- parodus event handler to listen to interface_down and interface_up event
|
||||
- Pause connection retry during interface_down event
|
||||
- Add 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.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)
|
||||
- Memory leak fixes
|
||||
- Changed connection logic (connection.c) for retries, and added unit test
|
||||
- Partner-id comparison made case insensitive
|
||||
- Reverted from NNG to nanomag (v1.1.2)
|
||||
- reverted temporary CMake reference to https://github.com/bill1600/seshat
|
||||
- Added log for time difference of parodus connect time and boot time
|
||||
- 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 +83,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
- Initial creation
|
||||
|
||||
[Unreleased]: https://github.com/Comcast/parodus/compare/1.0.1...HEAD
|
||||
[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
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ set(INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/_install)
|
||||
set(PREFIX_DIR ${CMAKE_CURRENT_BINARY_DIR}/_prefix)
|
||||
set(INCLUDE_DIR ${INSTALL_DIR}/include)
|
||||
set(INCLUDE_UCRESOLV ${PREFIX_DIR}/ucresolv/src/ucresolv/include)
|
||||
set(PATCHES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/patches)
|
||||
set(LIBRARY_DIR ${INSTALL_DIR}/lib)
|
||||
set(LIBRARY_DIR64 ${INSTALL_DIR}/lib64)
|
||||
set(COMMON_LIBRARY_DIR ${INSTALL_DIR}/lib/${CMAKE_LIBRARY_ARCHITECTURE})
|
||||
@@ -33,6 +34,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
|
||||
@@ -71,7 +73,7 @@ if (NOT BUILD_YOCTO)
|
||||
ExternalProject_Add(trower-base64
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/trower-base64
|
||||
GIT_REPOSITORY https://github.com/Comcast/trower-base64.git
|
||||
GIT_TAG "fbb9440ae2bc1118866baefcea7ff814f16613dd"
|
||||
GIT_TAG "v1.1.1"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTING=OFF
|
||||
)
|
||||
add_library(libtrower-base64 STATIC SHARED IMPORTED)
|
||||
@@ -83,7 +85,7 @@ add_dependencies(libtrower-base64 trower-base64)
|
||||
ExternalProject_Add(nopoll
|
||||
PREFIX ${PREFIX_DIR}/nopoll
|
||||
GIT_REPOSITORY https://github.com/Comcast/nopoll.git
|
||||
GIT_TAG "739b740683b0615e5999bdeea756cbd593b7f1cc"
|
||||
GIT_TAG "1.0.2"
|
||||
CONFIGURE_COMMAND COMMAND <SOURCE_DIR>/autogen.sh --prefix=${PREFIX}
|
||||
--includedir=${INCLUDE_DIR}
|
||||
--libdir=${LIBRARY_DIR}
|
||||
@@ -99,7 +101,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 "0c1aa2b288f6b167dbafe7e29c20e6fc7e71c000"
|
||||
GIT_TAG "1.1.4"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
|
||||
)
|
||||
add_library(libnanomsg STATIC SHARED IMPORTED)
|
||||
@@ -112,7 +114,7 @@ ExternalProject_Add(cJSON
|
||||
#PREFIX ${PREFIX_DIR}/cJSON
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/cJSON
|
||||
GIT_REPOSITORY https://github.com/DaveGamble/cJSON.git
|
||||
GIT_TAG "aafb64a1c549b7b927e339df6d35b1d5059dc235"
|
||||
GIT_TAG "v1.7.8"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTING=OFF
|
||||
)
|
||||
add_library(libcJSON STATIC SHARED IMPORTED)
|
||||
@@ -124,7 +126,7 @@ add_dependencies(libcJSON cJSON)
|
||||
ExternalProject_Add(msgpack
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/msgpack
|
||||
GIT_REPOSITORY https://github.com/msgpack/msgpack-c.git
|
||||
GIT_TAG "7a98138f27f27290e680bf8fbf1f8d1b089bf138"
|
||||
GIT_TAG "cpp-3.1.1"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
|
||||
-DMSGPACK_ENABLE_CXX=OFF
|
||||
-DMSGPACK_BUILD_EXAMPLES=OFF
|
||||
@@ -133,12 +135,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 "8a5fb3c2f182241d17f5342bea5b7688c28cd1fd"
|
||||
GIT_TAG "1.0.2"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTING=OFF
|
||||
)
|
||||
add_library(libcimplog STATIC SHARED IMPORTED)
|
||||
@@ -151,7 +165,7 @@ 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 "d42ac3a63b8d6e723995b63e23aa1969e622faa5"
|
||||
GIT_TAG "1.0.1"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
|
||||
-DMSGPACK_ENABLE_CXX=OFF
|
||||
-DMSGPACK_BUILD_EXAMPLES=OFF
|
||||
@@ -163,22 +177,6 @@ ExternalProject_Add(wrp-c
|
||||
add_library(libwrp-c STATIC SHARED IMPORTED)
|
||||
add_dependencies(libwrp-c wrp-c)
|
||||
|
||||
# libparodus external dependency
|
||||
#-------------------------------------------------------------------------------
|
||||
ExternalProject_Add(libparodus
|
||||
DEPENDS trower-base64 msgpack nanomsg wrp-c
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/libparodus
|
||||
GIT_REPOSITORY https://github.com/Comcast/libparodus.git
|
||||
GIT_TAG "a7615d69bd5859e337f467fb7e33182da970a5de"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTING=OFF
|
||||
-DMAIN_PROJ_BUILD=ON
|
||||
-DMAIN_PROJ_LIB_PATH=${LIBRARY_DIR}
|
||||
-DMAIN_PROJ_LIB64_PATH=${LIBRARY_DIR64}
|
||||
-DMAIN_PROJ_COMMON_PATH=${COMMON_LIBRARY_DIR}
|
||||
-DMAIN_PROJ_INCLUDE_PATH=${INCLUDE_DIR}
|
||||
)
|
||||
add_library(liblibparodus STATIC SHARED IMPORTED)
|
||||
add_dependencies(liblibparodus libparodus)
|
||||
|
||||
if (ENABLE_SESHAT)
|
||||
# libseshat external dependency
|
||||
@@ -186,8 +184,8 @@ if (ENABLE_SESHAT)
|
||||
ExternalProject_Add(libseshat
|
||||
DEPENDS cJSON trower-base64 msgpack nanomsg wrp-c
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/libseshat
|
||||
GIT_REPOSITORY https://github.com/comcast/seshat.git
|
||||
GIT_TAG "470f8d5e9457755028aae6da65d3df9b62a53942"
|
||||
GIT_REPOSITORY https://github.com/Comcast/seshat.git
|
||||
GIT_TAG "1.0.1"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTING=OFF
|
||||
-DMAIN_PROJ_BUILD=ON
|
||||
-DMAIN_PROJ_LIB_PATH=${LIBRARY_DIR}
|
||||
@@ -206,7 +204,8 @@ endif (ENABLE_SESHAT)
|
||||
ExternalProject_Add(cjwt
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/cjwt
|
||||
GIT_REPOSITORY https://github.com/Comcast/cjwt.git
|
||||
GIT_TAG "ddd077f0f00407f9657934492b252ee5cfcde535"
|
||||
GIT_TAG "1b023c41bb2d6dbbf493c202ed81f06c84d5b51b"
|
||||
#GIT_TAG "1.0.1"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTING=OFF
|
||||
)
|
||||
add_library(libcjwt STATIC SHARED IMPORTED)
|
||||
@@ -218,7 +217,7 @@ if (FEATURE_DNS_QUERY)
|
||||
ExternalProject_Add(ucresolv
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/ucresolv
|
||||
GIT_REPOSITORY https://github.com/Comcast/libucresolv.git
|
||||
GIT_TAG "b58d49e165208791f84b44e3c079b1b4ef6d5c9d"
|
||||
GIT_TAG "1.0.0"
|
||||
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
|
||||
)
|
||||
add_library(libucresolv STATIC SHARED IMPORTED)
|
||||
|
||||
18
README.md
18
README.md
@@ -1,6 +1,6 @@
|
||||
# parodus
|
||||
|
||||
[](https://travis-ci.org/Comcast/parodus)
|
||||
[](https://travis-ci.org/xmidt-org/parodus)
|
||||
[](http://codecov.io/github/Comcast/parodus?branch=master)
|
||||
[](https://scan.coverity.com/projects/comcast-parodus)
|
||||
[](https://github.com/Comcast/parodus/blob/master/LICENSE)
|
||||
@@ -55,9 +55,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 +75,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 +88,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
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ set(SOURCES main.c mutex.c networking.c nopoll_helpers.c heartBeat.c nopoll_hand
|
||||
ParodusInternal.c string_helpers.c time.c config.c conn_interface.c
|
||||
connection.c spin_thread.c client_list.c service_alive.c
|
||||
upstream.c downstream.c thread_tasks.c partners_check.c token.c
|
||||
crud_interface.c crud_tasks.c crud_internal.c)
|
||||
crud_interface.c crud_tasks.c crud_internal.c close_retry.c auth_token.c)
|
||||
|
||||
if (ENABLE_SESHAT)
|
||||
set(SOURCES ${SOURCES} seshat_interface.c)
|
||||
@@ -30,6 +30,7 @@ target_link_libraries (parodus
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
-lwrp-c
|
||||
-lmsgpackc
|
||||
-lcurl
|
||||
-ltrower-base64
|
||||
-lnopoll
|
||||
-luuid
|
||||
|
||||
@@ -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 */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -87,6 +92,10 @@ char* getWebpaConveyHeader()
|
||||
ParodusError("Failed to GET Reconnect reason value\n");
|
||||
}
|
||||
|
||||
if(get_parodus_cfg()->boot_retry_wait > 0)
|
||||
{
|
||||
cJSON_AddNumberToObject(response, BOOT_RETRY_WAIT, get_parodus_cfg()->boot_retry_wait);
|
||||
}
|
||||
buffer = cJSON_PrintUnformatted(response);
|
||||
ParodusInfo("X-WebPA-Convey Header: [%zd]%s\n", strlen(buffer), buffer);
|
||||
|
||||
@@ -135,3 +144,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
|
||||
@@ -59,6 +61,12 @@ extern int numLoops;
|
||||
#define FOREVER() numLoops--
|
||||
#endif
|
||||
|
||||
// Return values for find_servers() in connection.c
|
||||
#define FIND_SUCCESS 0
|
||||
#define FIND_INVALID_DEFAULT -2
|
||||
#define FIND_JWT_FAIL -1
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Data Structures */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -77,9 +85,58 @@ typedef struct {
|
||||
int rr_len;
|
||||
} rr_rec_t;
|
||||
|
||||
//------------ Used in comnection.c -----------------
|
||||
typedef struct {
|
||||
int allow_insecure;
|
||||
char *server_addr; // must be freed
|
||||
unsigned int port;
|
||||
} server_t;
|
||||
|
||||
typedef struct {
|
||||
server_t defaults; // from command line
|
||||
server_t jwt; // from jwt endpoint claim
|
||||
server_t redirect; // from redirect response to
|
||||
// nopoll_conn_wait_until_connection_ready
|
||||
} server_list_t;
|
||||
|
||||
//---- Used in connection.c for expire timer
|
||||
typedef struct {
|
||||
int running;
|
||||
struct timespec start_time;
|
||||
struct timespec end_time;
|
||||
} expire_timer_t;
|
||||
|
||||
//--- Used in connection.c for backoff delay timer
|
||||
typedef struct {
|
||||
struct timespec ts;
|
||||
int count;
|
||||
int max_count;
|
||||
int delay;
|
||||
} backoff_timer_t;
|
||||
|
||||
//--- Used in connection.c for init_header_info
|
||||
typedef struct {
|
||||
char *conveyHeader; // Do not free
|
||||
char *device_id; // Need to free
|
||||
char *user_agent; // Need to free
|
||||
} header_info_t;
|
||||
|
||||
// connection context which is defined in createNopollConnection
|
||||
// and passed into functions keep_retrying_connect, connect_and_wait,
|
||||
// wait_connection_ready, and nopoll_connect
|
||||
typedef struct {
|
||||
noPollCtx *nopoll_ctx;
|
||||
server_list_t server_list;
|
||||
server_t *current_server;
|
||||
header_info_t header_info;
|
||||
char *extra_headers; // need to be freed
|
||||
expire_timer_t connect_timer;
|
||||
} create_connection_ctx_t;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
extern bool g_shutdown;
|
||||
extern ParodusMsg *ParodusMsgQ;
|
||||
int numLoops;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -102,6 +159,25 @@ void addCRUDmsgToQueue(wrp_msg_t *crudMsg);
|
||||
void timespec_diff(struct timespec *start, struct timespec *stop,
|
||||
struct timespec *result);
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------*/
|
||||
/* 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();
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
302
src/auth_token.c
Normal file
302
src/auth_token.c
Normal file
@@ -0,0 +1,302 @@
|
||||
/**
|
||||
* 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 "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 128
|
||||
#define CURL_TIMEOUT_SEC 25L
|
||||
#define MAX_CURL_RETRY_COUNT 3
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void createCurlheader(char *mac_header, char *serial_header, char *uuid_header, char *transaction_uuid, struct curl_slist *list, struct curl_slist **header_list);
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/*
|
||||
* @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 *mac_header = NULL;
|
||||
char *serial_header = NULL;
|
||||
char *uuid_header = NULL;
|
||||
char *transaction_uuid = NULL;
|
||||
double total;
|
||||
long response_code;
|
||||
|
||||
struct token_data data;
|
||||
data.size = 0;
|
||||
data.data = newToken;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl)
|
||||
{
|
||||
data.data[0] = '\0';
|
||||
|
||||
createCurlheader(mac_header, serial_header, uuid_header, transaction_uuid, list, &headers_list);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, get_parodus_cfg()->token_server_url);
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, CURL_TIMEOUT_SEC);
|
||||
|
||||
if(get_parodus_cfg()->webpa_interface_used !=NULL && strlen(get_parodus_cfg()->webpa_interface_used) >0)
|
||||
{
|
||||
curl_easy_setopt(curl, CURLOPT_INTERFACE, get_parodus_cfg()->webpa_interface_used);
|
||||
}
|
||||
/* 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, &response_code);
|
||||
ParodusInfo("themis curl response %d http_code %d\n", res, 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(response_code == 200)
|
||||
{
|
||||
ParodusInfo("cURL success\n");
|
||||
}
|
||||
}
|
||||
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.
|
||||
*/
|
||||
size_t write_callback_fn(void *buffer, size_t size, size_t nmemb, struct token_data *data)
|
||||
{
|
||||
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] mac_header mac address header key value pair
|
||||
* @param[in] serial_header serial number key value pair
|
||||
* @param[in] uuid_header transaction uuid key value pair
|
||||
* @param[in] list temp curl header list
|
||||
* @param[out] header_list output curl header list
|
||||
*/
|
||||
void createCurlheader(char *mac_header, char *serial_header, char *uuid_header, char *transaction_uuid, struct curl_slist *list, struct curl_slist **header_list)
|
||||
{
|
||||
mac_header = (char *) malloc(sizeof(char)*MAX_BUF_SIZE);
|
||||
if(mac_header !=NULL)
|
||||
{
|
||||
snprintf(mac_header, MAX_BUF_SIZE, "X-Midt-Mac-Address: %s", get_parodus_cfg()->hw_mac);
|
||||
ParodusPrint("mac_header formed %s\n", mac_header);
|
||||
list = curl_slist_append(list, mac_header);
|
||||
free(mac_header);
|
||||
mac_header = NULL;
|
||||
}
|
||||
|
||||
serial_header = (char *) malloc(sizeof(char)*MAX_BUF_SIZE);
|
||||
if(serial_header !=NULL)
|
||||
{
|
||||
snprintf(serial_header, MAX_BUF_SIZE, "X-Midt-Serial-Number: %s", get_parodus_cfg()->hw_serial_number);
|
||||
ParodusPrint("serial_header formed %s\n", serial_header);
|
||||
list = curl_slist_append(list, serial_header);
|
||||
free(serial_header);
|
||||
serial_header = NULL;
|
||||
}
|
||||
|
||||
transaction_uuid = generate_trans_uuid();
|
||||
if(transaction_uuid !=NULL)
|
||||
{
|
||||
uuid_header = (char *) malloc(sizeof(char)*MAX_BUF_SIZE);
|
||||
if(uuid_header !=NULL)
|
||||
{
|
||||
snprintf(uuid_header, MAX_BUF_SIZE, "X-Midt-Uuid: %s", transaction_uuid);
|
||||
ParodusInfo("uuid_header formed %s\n", uuid_header);
|
||||
list = curl_slist_append(list, uuid_header);
|
||||
free(transaction_uuid);
|
||||
transaction_uuid = NULL;
|
||||
free(uuid_header);
|
||||
uuid_header = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Failed to generate transaction_uuid\n");
|
||||
}
|
||||
*header_list = list;
|
||||
}
|
||||
57
src/auth_token.h
Normal file
57
src/auth_token.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* 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);
|
||||
size_t write_callback_fn(void *buffer, size_t size, size_t nmemb, struct token_data *data);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -224,3 +248,49 @@ int deleteFromList(char* service_name)
|
||||
ParodusError("Could not find the entry to delete from list\n");
|
||||
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
|
||||
*@msgSize : Total size of the msg to send to client
|
||||
*/
|
||||
int sendMsgtoRegisteredClients(char *dest,const char **Msg,size_t msgSize)
|
||||
{
|
||||
int bytes =0;
|
||||
reg_list_item_t *temp = NULL;
|
||||
temp = get_global_node();
|
||||
//Checking for individual clients & Sending msg to registered client
|
||||
while (NULL != temp)
|
||||
{
|
||||
ParodusPrint("node is pointing to temp->service_name %s \n",temp->service_name);
|
||||
// Sending message to registered clients
|
||||
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;
|
||||
}
|
||||
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,8 +51,11 @@ 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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
56
src/close_retry.c
Normal file
56
src/close_retry.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright 2018 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 close_retry.c
|
||||
*
|
||||
* @description Functions required to manage connection close retry.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "close_retry.h"
|
||||
|
||||
bool close_retry = false;
|
||||
|
||||
pthread_mutex_t close_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
// Get value of close_retry
|
||||
bool get_close_retry()
|
||||
{
|
||||
bool tmp = false;
|
||||
pthread_mutex_lock (&close_mut);
|
||||
tmp = close_retry;
|
||||
pthread_mutex_unlock (&close_mut);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// Reset value of close_retry to false
|
||||
void reset_close_retry()
|
||||
{
|
||||
pthread_mutex_lock (&close_mut);
|
||||
close_retry = false;
|
||||
pthread_mutex_unlock (&close_mut);
|
||||
}
|
||||
|
||||
// set value of close_retry to true
|
||||
void set_close_retry()
|
||||
{
|
||||
pthread_mutex_lock (&close_mut);
|
||||
close_retry = true;
|
||||
pthread_mutex_unlock (&close_mut);
|
||||
}
|
||||
|
||||
|
||||
47
src/close_retry.h
Normal file
47
src/close_retry.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright 2018 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 close_retry.h
|
||||
*
|
||||
* @description Functions required to manage connection close retry.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _CLOSERETRY_H_
|
||||
#define _CLOSERETRY_H_
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Get value of close_retry
|
||||
bool get_close_retry();
|
||||
|
||||
// Reset value of close_retry to false
|
||||
void reset_close_retry();
|
||||
|
||||
// Set value of close_retry to true
|
||||
void set_close_retry();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
297
src/config.c
297
src/config.c
@@ -26,8 +26,9 @@
|
||||
#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 */
|
||||
@@ -36,7 +37,6 @@
|
||||
static ParodusCfg parodusCfg;
|
||||
static unsigned int rsa_algorithms =
|
||||
(1<<alg_rs256) | (1<<alg_rs384) | (1<<alg_rs512);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -51,7 +51,16 @@ void set_parodus_cfg(ParodusCfg *cfg)
|
||||
memcpy(&parodusCfg, cfg, sizeof(ParodusCfg));
|
||||
}
|
||||
|
||||
static void execute_token_script(char *token, char *name, size_t len, char *mac, char *serNum);
|
||||
void set_cloud_disconnect_reason(ParodusCfg *cfg, char *disconn_reason)
|
||||
{
|
||||
cfg->cloud_disconnect = strdup(disconn_reason);
|
||||
}
|
||||
|
||||
void reset_cloud_disconnect_reason(ParodusCfg *cfg)
|
||||
{
|
||||
cfg->cloud_disconnect = NULL;
|
||||
}
|
||||
|
||||
|
||||
const char *get_tok (const char *src, int delim, char *result, int resultsize)
|
||||
{
|
||||
@@ -132,31 +141,6 @@ void read_key_from_file (const char *fname, char *buf, size_t buflen)
|
||||
ParodusInfo ("%d bytes read\n", nbytes);
|
||||
}
|
||||
|
||||
static 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)
|
||||
@@ -201,7 +185,7 @@ int server_is_http (const char *full_url,
|
||||
}
|
||||
|
||||
|
||||
int parse_webpa_url(const char *full_url,
|
||||
int parse_webpa_url__ (const char *full_url,
|
||||
char *server_addr, int server_addr_buflen,
|
||||
char *port_buf, int port_buflen)
|
||||
{
|
||||
@@ -210,6 +194,9 @@ int parse_webpa_url(const char *full_url,
|
||||
char *end_port;
|
||||
size_t server_len;
|
||||
int http_match;
|
||||
char *closeBracket = NULL;
|
||||
char *openBracket = NULL;
|
||||
char *checkPort = NULL;
|
||||
|
||||
ParodusInfo ("full url: %s\n", full_url);
|
||||
http_match = server_is_http (full_url, &server_ptr);
|
||||
@@ -222,6 +209,40 @@ int parse_webpa_url(const char *full_url,
|
||||
// If there's a '/' on end, null it out
|
||||
if ((server_len>0) && (server_addr[server_len-1] == '/'))
|
||||
server_addr[server_len-1] = '\0';
|
||||
|
||||
openBracket = strchr(server_addr,'[');
|
||||
if(openBracket != NULL){
|
||||
//Remove [ from server address
|
||||
char *remove = server_addr;
|
||||
remove++;
|
||||
parStrncpy (server_addr, remove, server_addr_buflen);
|
||||
closeBracket = strchr(server_addr,']');
|
||||
if(closeBracket != NULL){
|
||||
//Remove ] by making it as null
|
||||
*closeBracket = '\0';
|
||||
closeBracket++;
|
||||
checkPort = strchr(closeBracket,':');
|
||||
if (NULL == checkPort) {
|
||||
if (http_match)
|
||||
parStrncpy (port_buf, "80", port_buflen);
|
||||
else
|
||||
parStrncpy (port_buf, "443", port_buflen);
|
||||
} else {
|
||||
checkPort++;
|
||||
end_port = strchr (checkPort, '/');
|
||||
if (NULL != end_port)
|
||||
*end_port = '\0'; // terminate port with null
|
||||
parStrncpy (port_buf, checkPort, port_buflen);
|
||||
}
|
||||
|
||||
}else{
|
||||
ParodusError("Invalid url %s\n", full_url);
|
||||
return -1;
|
||||
}
|
||||
}else if (strchr(server_addr,']') != NULL ){
|
||||
ParodusError("Invalid url %s\n", full_url);
|
||||
return -1;
|
||||
}else{
|
||||
// Look for ':'
|
||||
port_val = strchr (server_addr, ':');
|
||||
|
||||
@@ -230,7 +251,6 @@ int parse_webpa_url(const char *full_url,
|
||||
parStrncpy (port_buf, "80", port_buflen);
|
||||
else
|
||||
parStrncpy (port_buf, "443", port_buflen);
|
||||
|
||||
end_port = strchr (server_addr, '/');
|
||||
if (NULL != end_port) {
|
||||
*end_port = '\0'; // terminate server address with null
|
||||
@@ -244,6 +264,7 @@ int parse_webpa_url(const char *full_url,
|
||||
*end_port = '\0'; // terminate port with null
|
||||
parStrncpy (port_buf, port_val, port_buflen);
|
||||
}
|
||||
}
|
||||
ParodusInfo ("server %s, port %s, http_match %d\n",
|
||||
server_addr, port_buf, http_match);
|
||||
return http_match;
|
||||
@@ -271,6 +292,49 @@ unsigned int parse_num_arg (const char *arg, const char *arg_name)
|
||||
return result;
|
||||
}
|
||||
|
||||
int parse_webpa_url (const char *full_url,
|
||||
char **server_addr, unsigned int *port)
|
||||
{
|
||||
int allow_insecure;
|
||||
unsigned int port_val;
|
||||
int buflen = strlen (full_url) + 1;
|
||||
char *url_buf = NULL;
|
||||
char port_buf[8];
|
||||
|
||||
#define ERROR__(msg) \
|
||||
ParodusError (msg); \
|
||||
if (NULL != url_buf) \
|
||||
free (url_buf);
|
||||
|
||||
*server_addr = NULL;
|
||||
|
||||
url_buf = (char *) malloc (buflen);
|
||||
if (NULL == url_buf) {
|
||||
ERROR__ ("parse_webpa_url allocatio n failed.\n")
|
||||
return -1;
|
||||
}
|
||||
allow_insecure = parse_webpa_url__ (full_url,
|
||||
url_buf, buflen, port_buf, 8);
|
||||
if (allow_insecure < 0) {
|
||||
ERROR__ ("parse_webpa_url invalid url\n")
|
||||
return -1;
|
||||
}
|
||||
port_val = parse_num_arg (port_buf, "server port");
|
||||
if (port_val == (unsigned int) -1) {
|
||||
ERROR__ ("Invalid port in server url")
|
||||
return -1;
|
||||
}
|
||||
if ((port_val == 0) || (port_val > 65535)) {
|
||||
ERROR__ ("port value out of range in server url")
|
||||
return -1;
|
||||
}
|
||||
*server_addr = url_buf;
|
||||
*port = port_val;
|
||||
return allow_insecure;
|
||||
#undef ERROR__
|
||||
}
|
||||
|
||||
|
||||
int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
|
||||
{
|
||||
static const struct option long_options[] = {
|
||||
@@ -297,9 +361,13 @@ 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'},
|
||||
{"token-acquisition-script", required_argument, 0, 'J'},
|
||||
{"boot-time-retry-wait", required_argument, 0, 'w'},
|
||||
{"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'},
|
||||
{"mtls-client-key-path", required_argument, 0, 'K'},
|
||||
{"mtls-client-cert-path", required_argument, 0,'M'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
int c;
|
||||
@@ -315,13 +383,18 @@ 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->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 */
|
||||
while (1)
|
||||
{
|
||||
|
||||
/* 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:J:46:C",
|
||||
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:S:K:M",
|
||||
long_options, &option_index);
|
||||
|
||||
/* Detect the end of the options. */
|
||||
@@ -362,6 +435,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':
|
||||
@@ -371,8 +445,6 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
|
||||
|
||||
case 'b':
|
||||
cfg->boot_time = parse_num_arg (optarg, "boot-time");
|
||||
if (cfg->boot_time == (unsigned int) -1)
|
||||
return -1;
|
||||
ParodusInfo("boot_time is %d\n",cfg->boot_time);
|
||||
break;
|
||||
|
||||
@@ -456,18 +528,40 @@ 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));
|
||||
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 '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. */
|
||||
@@ -511,63 +605,6 @@ 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)
|
||||
{
|
||||
//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");
|
||||
}
|
||||
}
|
||||
|
||||
void setDefaultValuesToCfg(ParodusCfg *cfg)
|
||||
{
|
||||
if(cfg == NULL)
|
||||
@@ -598,8 +635,13 @@ 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 = strdup("parodus_cfg.json");
|
||||
ParodusPrint("Default crud_config_file is %s\n", cfg->crud_config_file);
|
||||
cfg->crud_config_file = NULL;
|
||||
cfg->connection_health_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);
|
||||
}
|
||||
|
||||
void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg)
|
||||
@@ -737,24 +779,6 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg)
|
||||
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");
|
||||
}
|
||||
|
||||
cfg->boot_time = config->boot_time;
|
||||
cfg->webpa_ping_timeout = config->webpa_ping_timeout;
|
||||
cfg->webpa_backoff_max = config->webpa_backoff_max;
|
||||
@@ -764,6 +788,15 @@ 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->crud_config_file != NULL)
|
||||
{
|
||||
cfg->crud_config_file = strdup(config->crud_config_file);
|
||||
@@ -772,6 +805,24 @@ 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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
37
src/config.h
37
src/config.h
@@ -42,13 +42,19 @@ 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"
|
||||
#define WEBPA_BACKOFF_MAX "webpa-backoff-max"
|
||||
#define PARTNER_ID "partner-id"
|
||||
#define CERT_PATH "ssl-cert-path"
|
||||
#define CLOUD_STATUS "cloud-status"
|
||||
#define CLOUD_DISCONNECT "cloud-disconnect"
|
||||
#define CLOUD_STATUS_ONLINE "online"
|
||||
#define CLOUD_STATUS_OFFLINE "offline"
|
||||
#define CLOUD_DISCONNECT_REASON "disconnection-reason"
|
||||
#define BOOT_RETRY_WAIT "boot-time-retry-wait"
|
||||
|
||||
#define PROTOCOL_VALUE "PARODUS-2.0"
|
||||
#define WEBPA_PATH_URL "/api/v2/device"
|
||||
@@ -93,7 +99,15 @@ 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 *mtls_client_key_path;
|
||||
char *mtls_client_cert_path;
|
||||
char *crud_config_file;
|
||||
char *cloud_status;
|
||||
char *cloud_disconnect;
|
||||
unsigned int boot_retry_wait;
|
||||
} ParodusCfg;
|
||||
|
||||
#define FLAGS_IPV6_ONLY (1 << 0)
|
||||
@@ -105,7 +119,6 @@ typedef struct
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg);
|
||||
void createNewAuthToken(char *newToken, size_t len);
|
||||
|
||||
/**
|
||||
* parse command line arguments and create config structure
|
||||
@@ -119,28 +132,26 @@ void createNewAuthToken(char *newToken, size_t len);
|
||||
int parseCommandLine(int argc,char **argv,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);
|
||||
/**
|
||||
* parse a webpa url. Extract the server address, the port
|
||||
* and return whether it's secure or not
|
||||
*
|
||||
* @param full_url full url
|
||||
* @param server_addr buffer containing server address found in url
|
||||
* @param server_addr_buflen len of the server addr buffer provided by caller
|
||||
* @param port_buf buffer containing port value found in url
|
||||
* @param port_buflen len of the port buffer provided by caller
|
||||
* @param full_url full url
|
||||
* @param server_addr ptr to a server address ptr
|
||||
* will be NULL if invalid,
|
||||
* otherwise will need to be freed
|
||||
* @param port ptr to port variable
|
||||
* @return 1 if insecure connection is allowed, 0 if not,
|
||||
* or -1 if error
|
||||
*/
|
||||
int parse_webpa_url(const char *full_url,
|
||||
char *server_addr, int server_addr_buflen,
|
||||
char *port_buf, int port_buflen);
|
||||
|
||||
int parse_webpa_url (const char *full_url,
|
||||
char **server_addr, unsigned int *port);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
#include "seshat_interface.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
|
||||
@@ -45,19 +47,24 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#define HEARTBEAT_RETRY_SEC 30 /* Heartbeat (ping/pong) timeout in seconds */
|
||||
#define CLOUD_RECONNECT_TIME 5 /* Cloud disconnect max time in minutes */
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
bool close_retry = false;
|
||||
pthread_mutex_t close_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
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 */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -67,8 +74,10 @@ void createSocketConnection(void (* initKeypress)())
|
||||
//ParodusCfg *tmpCfg = (ParodusCfg*)config_in;
|
||||
noPollCtx *ctx;
|
||||
bool seshat_registered = false;
|
||||
int create_conn_rtn = 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,16 +95,24 @@ void createSocketConnection(void (* initKeypress)())
|
||||
nopoll_log_set_handler (ctx, __report_log, NULL);
|
||||
#endif
|
||||
|
||||
createNopollConnection(ctx);
|
||||
start_conn_in_progress ();
|
||||
create_conn_rtn = createNopollConnection(ctx);
|
||||
stop_conn_in_progress ();
|
||||
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)
|
||||
{
|
||||
@@ -104,6 +121,8 @@ void createSocketConnection(void (* initKeypress)())
|
||||
|
||||
seshat_registered = __registerWithSeshat();
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &start_svc_alive_timer);
|
||||
|
||||
do
|
||||
{
|
||||
struct timespec start, stop, diff;
|
||||
@@ -121,19 +140,24 @@ void createSocketConnection(void (* initKeypress)())
|
||||
if(heartBeatTimer >= webpa_ping_timeout_ms)
|
||||
{
|
||||
ParodusInfo("heartBeatTimer %d webpa_ping_timeout_ms %d\n", heartBeatTimer, webpa_ping_timeout_ms);
|
||||
if(!close_retry)
|
||||
|
||||
if(!get_close_retry())
|
||||
{
|
||||
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);
|
||||
pthread_mutex_lock (&close_mut);
|
||||
close_retry = true;
|
||||
pthread_mutex_unlock (&close_mut);
|
||||
// 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
|
||||
{
|
||||
ParodusPrint("heartBeatHandler - close_retry set to %d, hence resetting the heartBeatTimer\n",close_retry);
|
||||
{
|
||||
ParodusPrint("heartBeatHandler - close_retry set to %d, hence resetting the heartBeatTimer\n",get_close_retry());
|
||||
}
|
||||
reset_heartBeatTimer();
|
||||
}
|
||||
@@ -144,18 +168,68 @@ void createSocketConnection(void (* initKeypress)())
|
||||
if( false == seshat_registered ) {
|
||||
seshat_registered = __registerWithSeshat();
|
||||
}
|
||||
|
||||
if (get_interface_down_event ())
|
||||
if (0 != wait_while_interface_down ())
|
||||
break;
|
||||
|
||||
if(close_retry)
|
||||
if(get_close_retry())
|
||||
{
|
||||
ParodusInfo("close_retry is %d, hence closing the connection and retrying\n", close_retry);
|
||||
ParodusInfo("close_retry is %d, hence closing the connection and retrying\n", get_close_retry());
|
||||
close_and_unref_connection(get_global_conn());
|
||||
set_global_conn(NULL);
|
||||
createNopollConnection(ctx);
|
||||
}
|
||||
} while(!close_retry);
|
||||
|
||||
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());
|
||||
|
||||
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());
|
||||
}
|
||||
start_conn_in_progress ();
|
||||
createNopollConnection(ctx);
|
||||
stop_conn_in_progress ();
|
||||
}
|
||||
} while(!get_close_retry() && !g_shutdown);
|
||||
|
||||
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());
|
||||
ParodusInfo ("shutdown reason at close %s\n", get_global_shutdown_reason());
|
||||
close_and_unref_connection(get_global_conn());
|
||||
nopoll_ctx_unref(ctx);
|
||||
nopoll_cleanup_library();
|
||||
curl_global_cleanup();
|
||||
}
|
||||
|
||||
void shutdownSocketConnection(char *reason) {
|
||||
set_global_shutdown_reason (reason);
|
||||
g_shutdown = true;
|
||||
reset_interface_down_event ();
|
||||
terminate_backoff_delay ();
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ extern UpStreamMsg *UpStreamMsgQ;
|
||||
* and creates the intial connection and manages the connection wait, close mechanisms.
|
||||
*/
|
||||
void createSocketConnection(void (* initKeypress)());
|
||||
void shutdownSocketConnection(char *reason);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
1067
src/connection.c
1067
src/connection.c
File diff suppressed because it is too large
Load Diff
@@ -33,9 +33,17 @@ extern "C" {
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#define SHUTDOWN_REASON_PARODUS_STOP "parodus_stopping"
|
||||
#define SHUTDOWN_REASON_SYSTEM_RESTART "system_restarting"
|
||||
|
||||
extern bool close_retry;
|
||||
extern pthread_mutex_t close_mut;
|
||||
/**
|
||||
* 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);
|
||||
parodusOnPingStatusChangeHandler on_ping_status_change;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Function Prototypes */
|
||||
@@ -51,12 +59,32 @@ void close_and_unref_connection(noPollConn *);
|
||||
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);
|
||||
|
||||
bool get_global_reconnect_status();
|
||||
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 (void);
|
||||
void stop_conn_in_progress (void);
|
||||
|
||||
// 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
|
||||
@@ -42,9 +44,9 @@ typedef struct CrudMsg__
|
||||
/* Function Prototypes */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
//void *CRUDHandlerTask();
|
||||
//void addCRUDmsgToQueue(wrp_msg_t *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
|
||||
}
|
||||
|
||||
@@ -24,11 +24,15 @@
|
||||
#include "crud_tasks.h"
|
||||
#include "crud_internal.h"
|
||||
#include "config.h"
|
||||
#include "connection.h"
|
||||
#include "close_retry.h"
|
||||
|
||||
static void freeObjArray(char *(*obj)[], int size);
|
||||
static int writeIntoCrudJson(cJSON *res_obj, char * object, cJSON *objValue, int freeFlag);
|
||||
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);
|
||||
|
||||
int writeToJSON(char *data)
|
||||
{
|
||||
@@ -582,6 +586,24 @@ int retrieveFromMemory(char *keyName, cJSON **jsonresponse)
|
||||
ParodusInfo("retrieveFromMemory: keyName:%s value:%s\n",keyName,get_parodus_cfg()->webpa_uuid);
|
||||
cJSON_AddItemToObject( *jsonresponse, WEBPA_UUID , cJSON_CreateString(get_parodus_cfg()->webpa_uuid));
|
||||
}
|
||||
else if(strcmp(CLOUD_STATUS, keyName)==0)
|
||||
{
|
||||
if(get_parodus_cfg()->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))
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
else if(strcmp(BOOT_TIME, keyName)==0)
|
||||
{
|
||||
ParodusInfo("retrieveFromMemory: keyName:%s value:%d\n",keyName,get_parodus_cfg()->boot_time);
|
||||
@@ -852,8 +874,10 @@ int updateObject( wrp_msg_t *reqMsg, wrp_msg_t **response )
|
||||
int jsontagitemSize = 0, value =0;
|
||||
char *key = NULL, *testkey = NULL;
|
||||
const char *parse_error = NULL;
|
||||
int status =0;
|
||||
int status =0, valid =0;
|
||||
int expireFlag = 0;
|
||||
int disconnStatus = 0;
|
||||
char *disconn_str = NULL;
|
||||
|
||||
status = readFromJSON(&jsonData);
|
||||
ParodusPrint("read status %d\n", status);
|
||||
@@ -1188,12 +1212,121 @@ int updateObject( wrp_msg_t *reqMsg, wrp_msg_t **response )
|
||||
}
|
||||
else
|
||||
{
|
||||
// Return error for request format other than parodus/tag/${name}
|
||||
ParodusError("Invalid UPDATE request\n");
|
||||
(*response)->u.crud.status = 400;
|
||||
freeObjArray(&obj, objlevel);
|
||||
cJSON_Delete( json );
|
||||
return -1;
|
||||
//Checks for parodus/cloud-disconnect request with objlevel = 3
|
||||
if(objlevel == 3 && ((obj[3] != NULL) && (strcmp(obj[3] , "cloud-disconnect") == 0)))
|
||||
{
|
||||
if(reqMsg->u.crud.payload != NULL)
|
||||
{
|
||||
jsonPayload = cJSON_Parse( reqMsg->u.crud.payload );
|
||||
if(jsonPayload !=NULL)
|
||||
{
|
||||
if((cJSON_GetObjectItem( jsonPayload, CLOUD_DISCONNECT_REASON )) !=NULL)
|
||||
{
|
||||
if (cJSON_String == cJSON_GetObjectItem( jsonPayload, CLOUD_DISCONNECT_REASON )->type)
|
||||
{
|
||||
disconn_str = cJSON_GetObjectItem( jsonPayload, CLOUD_DISCONNECT_REASON )->valuestring;
|
||||
if (disconn_str != NULL && strlen(disconn_str) == 0)
|
||||
{
|
||||
ParodusError("Invalid cloud-disconnect request. disconnect reason is NULL\n");
|
||||
(*response)->u.crud.status = 400;
|
||||
cJSON_Delete( jsonPayload );
|
||||
jsonPayload = NULL;
|
||||
cJSON_Delete(json);
|
||||
json = NULL;
|
||||
freeObjArray(&obj, objlevel);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
//check disconnection reason is character string of [a-zA-Z0-9 ]*
|
||||
|
||||
valid = validateDisconnectString(disconn_str);
|
||||
if(valid >0)
|
||||
{
|
||||
//set the disconnection reason value to in-memory
|
||||
set_cloud_disconnect_reason(get_parodus_cfg(), disconn_str);
|
||||
ParodusInfo("set cloud-disconnect reason as %s \n", get_parodus_cfg()->cloud_disconnect);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Invalid cloud-disconnect request. disconnect reason is not alphanumeric\n");
|
||||
(*response)->u.crud.status = 400;
|
||||
cJSON_Delete( jsonPayload );
|
||||
jsonPayload = NULL;
|
||||
cJSON_Delete(json);
|
||||
json = NULL;
|
||||
freeObjArray(&obj, objlevel);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Invalid cloud-disconnect request, disconnect reason is not string\n");
|
||||
(*response)->u.crud.status = 400;
|
||||
cJSON_Delete( jsonPayload );
|
||||
jsonPayload = NULL;
|
||||
cJSON_Delete(json);
|
||||
json = NULL;
|
||||
freeObjArray(&obj, objlevel);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Invalid cloud-disconnect request, disconnection-reason not found\n");
|
||||
(*response)->u.crud.status = 400;
|
||||
freeObjArray(&obj, objlevel);
|
||||
cJSON_Delete( jsonPayload );
|
||||
jsonPayload = NULL;
|
||||
cJSON_Delete( json);
|
||||
return -1;
|
||||
}
|
||||
cJSON_Delete( jsonPayload );
|
||||
jsonPayload = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Invalid cloud-disconnect request, payload is not json\n");
|
||||
(*response)->u.crud.status = 400;
|
||||
freeObjArray(&obj, objlevel);
|
||||
cJSON_Delete( json);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusInfo("cloud-disconnect failed as payload is NULL\n");
|
||||
(*response)->u.crud.status = 400;
|
||||
freeObjArray(&obj, objlevel);
|
||||
return -1;
|
||||
}
|
||||
char *reason = strdup(get_parodus_cfg()->cloud_disconnect);
|
||||
disconnStatus = ConnDisconnectFromCloud(reason);
|
||||
freeObjArray(&obj, objlevel);
|
||||
cJSON_Delete( json );
|
||||
if (disconnStatus >0)
|
||||
{
|
||||
ParodusInfo("Sending update response for cloud-disconnect\n");
|
||||
(*response)->u.crud.status = 200;
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusInfo("Failure in disconnecting from cloud ..\n");
|
||||
(*response)->u.crud.status = 500;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Return error for request format other than parodus/tag/${name}
|
||||
ParodusError("Invalid UPDATE request\n");
|
||||
(*response)->u.crud.status = 400;
|
||||
freeObjArray(&obj, objlevel);
|
||||
cJSON_Delete( json );
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1206,6 +1339,25 @@ int updateObject( wrp_msg_t *reqMsg, wrp_msg_t **response )
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ConnDisconnectFromCloud(char *disconn_reason)
|
||||
{
|
||||
bool close_retry = false;
|
||||
close_retry = get_close_retry();
|
||||
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();
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusInfo("close_retry is %d, connection close and retrying is already in progress\n", close_retry);
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int deleteObject( wrp_msg_t *reqMsg, wrp_msg_t **response )
|
||||
{
|
||||
@@ -1387,7 +1539,7 @@ static int parse_dest_elements_to_string(wrp_msg_t *reqMsg, char *(*obj)[])
|
||||
|
||||
for( i = 0; i <= WRP_ID_ELEMENT__APPLICATION; i++ )
|
||||
{
|
||||
(*obj)[i] = wrp_get_msg_dest_element(i, reqMsg);
|
||||
(*obj)[i] = wrp_get_msg_element(i, reqMsg, DEST);
|
||||
if((*obj)[i] ==NULL)
|
||||
{
|
||||
break;
|
||||
@@ -1450,3 +1602,29 @@ static char* strdupptr( const char *s, const char *e )
|
||||
|
||||
return strndup(s, (size_t) (((uintptr_t)e) - ((uintptr_t)s)));
|
||||
}
|
||||
|
||||
static int validateDisconnectString(char *reason)
|
||||
{
|
||||
int k=0, rv =1;
|
||||
if(reason !=NULL && strlen(reason) >0 )
|
||||
{
|
||||
for( k = 0; k < (int)strlen(reason); k++ )
|
||||
{
|
||||
if ((isalpha(reason[k])) || ((isdigit(reason[k])) != 0))
|
||||
{
|
||||
ParodusPrint("disconnection string is valid\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("disconnection string is Invalid\n");
|
||||
rv = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = -1;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
163
src/downstream.c
163
src/downstream.c
@@ -27,7 +27,10 @@
|
||||
#include "partners_check.h"
|
||||
#include "ParodusInternal.h"
|
||||
#include "crud_interface.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Function Prototypes */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void createNewMsgForCRUD(wrp_msg_t *message, wrp_msg_t **crudMessage );
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -42,6 +45,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;
|
||||
@@ -90,7 +94,7 @@ void listenerOnMessage(void * msg, size_t msgSize)
|
||||
if(ret < 0)
|
||||
{
|
||||
response = cJSON_CreateObject();
|
||||
cJSON_AddNumberToObject(response, "statusCode", 430);
|
||||
cJSON_AddNumberToObject(response, "statusCode", 403);
|
||||
cJSON_AddStringToObject(response, "message", "Invalid partner_id");
|
||||
}
|
||||
|
||||
@@ -117,9 +121,13 @@ 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)));
|
||||
OnboardLog("%s\n",
|
||||
((WRP_MSG_TYPE__REQ == msgType) ? message->u.req.transaction_uuid :
|
||||
((WRP_MSG_TYPE__EVENT == msgType) ? "NA" : 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)
|
||||
@@ -138,10 +146,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))
|
||||
{
|
||||
@@ -153,11 +162,12 @@ 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 any unknown dest received sending error response to server
|
||||
if(destFlag ==0)
|
||||
{
|
||||
ParodusError("Unknown dest:%s\n", dest);
|
||||
@@ -183,14 +193,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;
|
||||
}
|
||||
@@ -224,8 +234,6 @@ void listenerOnMessage(void * msg, size_t msgSize)
|
||||
resp_bytes = NULL;
|
||||
}
|
||||
free(resp_msg);
|
||||
ParodusPrint("free for downstream decoded msg\n");
|
||||
wrp_free_struct(message);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -234,9 +242,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
|
||||
{
|
||||
@@ -244,3 +254,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,10 @@
|
||||
*/
|
||||
|
||||
#include "heartBeat.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
volatile unsigned int heartBeatTimer = 0;
|
||||
volatile bool paused = false;
|
||||
|
||||
pthread_mutex_t heartBeat_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
@@ -49,8 +51,27 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -39,6 +39,12 @@ 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();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
58
src/main.c
58
src/main.c
@@ -18,13 +18,15 @@
|
||||
#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
|
||||
#include "breakpad_wrapper.h"
|
||||
#else
|
||||
#include "signal.h"
|
||||
#endif
|
||||
#include "signal.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Macros */
|
||||
@@ -34,7 +36,7 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Data Structures */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* none */
|
||||
typedef void Sigfunc(int);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
@@ -44,30 +46,53 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
/* breakpad handles the signals SIGSEGV, SIGBUS, SIGFPE, and SIGILL */
|
||||
breakpad_ExceptionHandler();
|
||||
#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;
|
||||
|
||||
@@ -80,7 +105,7 @@ int main( int argc, char **argv)
|
||||
if (0 != parseCommandLine(argc,argv,cfg)) {
|
||||
abort();
|
||||
}
|
||||
getAuthToken(cfg);
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
|
||||
createSocketConnection( NULL);
|
||||
|
||||
@@ -95,7 +120,6 @@ const char *rdk_logger_module_fetch(void)
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Internal functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#ifndef INCLUDE_BREAKPAD
|
||||
static void sig_handler(int sig)
|
||||
{
|
||||
|
||||
@@ -103,12 +127,13 @@ static void sig_handler(int sig)
|
||||
{
|
||||
signal(SIGINT, sig_handler); /* reset it to this function */
|
||||
ParodusInfo("SIGINT received!\n");
|
||||
exit(0);
|
||||
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 )
|
||||
{
|
||||
@@ -132,8 +157,7 @@ static void sig_handler(int sig)
|
||||
else
|
||||
{
|
||||
ParodusInfo("Signal %d received!\n", sig);
|
||||
exit(0);
|
||||
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
|
||||
{
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "nopoll_handlers.h"
|
||||
#include "connection.h"
|
||||
#include "heartBeat.h"
|
||||
#include "close_retry.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Macros */
|
||||
@@ -166,18 +167,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");
|
||||
|
||||
pthread_mutex_lock (&close_mut);
|
||||
close_retry = true;
|
||||
pthread_mutex_unlock (&close_mut);
|
||||
ParodusPrint("listenerOnCloseMessage(): mutex unlock in producer thread\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -36,8 +36,6 @@ extern "C" {
|
||||
|
||||
extern pthread_mutex_t g_mutex;
|
||||
extern pthread_cond_t g_cond;
|
||||
extern pthread_mutex_t close_mut;
|
||||
extern bool close_retry;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Function Prototypes */
|
||||
|
||||
@@ -73,25 +73,35 @@ void sendMessage(noPollConn *conn, void *msg, size_t len)
|
||||
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);
|
||||
OnboardLog("Failed to send msg upstream as connection is not OK\n");
|
||||
|
||||
if( timeDiff >= (10*60*1000))
|
||||
if(get_interface_down_event())
|
||||
{
|
||||
ParodusError("Unable to connect to server since interface is down\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (connErr == 0)
|
||||
{
|
||||
ParodusError("conn got stuck for over 10 minutes; crashing service.\n");
|
||||
kill(getpid(),SIGTERM);
|
||||
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");
|
||||
OnboardLog("conn got stuck for over 10 minutes; crashing service.\n");
|
||||
kill(getpid(),SIGTERM);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +146,7 @@ void __report_log (noPollCtx * ctx, noPollDebugLevel level, const char * log_msg
|
||||
|
||||
if (level == NOPOLL_LEVEL_DEBUG)
|
||||
{
|
||||
//ParodusPrint("%s\n", log_msg);
|
||||
ParodusInfo("%s\n", log_msg);
|
||||
}
|
||||
if (level == NOPOLL_LEVEL_INFO)
|
||||
{
|
||||
@@ -144,11 +154,12 @@ void __report_log (noPollCtx * ctx, noPollDebugLevel level, const char * log_msg
|
||||
}
|
||||
if (level == NOPOLL_LEVEL_WARNING)
|
||||
{
|
||||
ParodusPrint("%s\n", log_msg);
|
||||
ParodusInfo("%s\n", log_msg);
|
||||
}
|
||||
if (level == NOPOLL_LEVEL_CRITICAL)
|
||||
{
|
||||
ParodusError("%s\n", log_msg );
|
||||
OnboardLog("%s\n", log_msg );
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -39,85 +39,184 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void parse_partner_id(char *partnerId, partners_t **partnersList)
|
||||
{
|
||||
char *token;
|
||||
int i = 0, j = 0, count = 0;
|
||||
ParodusPrint("********* %s ********\n",__FUNCTION__);
|
||||
while(partnerId[i] != '\0')
|
||||
{
|
||||
if(partnerId[i] == ',')
|
||||
{
|
||||
count++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
ParodusPrint("count = %d\n", count+1);
|
||||
*partnersList = (partners_t *)malloc(sizeof(partners_t)+ sizeof( char * ) * (count+1));
|
||||
memset(*partnersList, 0, sizeof(partners_t));
|
||||
(*partnersList)->count = count+1;
|
||||
while ((token = strsep(&partnerId, ",")) != NULL)
|
||||
{
|
||||
ParodusPrint("token=%s\n", token);
|
||||
(*partnersList)->partner_ids[j] = strdup(token);
|
||||
ParodusPrint("(*partnersList)->partner_ids[%d] = %s\n",j,(*partnersList)->partner_ids[j]);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
int validate_partner_id(wrp_msg_t *msg, partners_t **partnerIds)
|
||||
{
|
||||
int matchFlag = 0, i = 0, count = 0;
|
||||
size_t j = 0;
|
||||
partners_t *partnersList = NULL;
|
||||
char *partnerId = NULL;
|
||||
ParodusPrint("********* %s ********\n",__FUNCTION__);
|
||||
char *partnerId = get_parodus_cfg()->partner_id;
|
||||
if(strlen(partnerId) <= 0)
|
||||
char *temp = get_parodus_cfg()->partner_id;
|
||||
ParodusPrint("temp = %s\n",temp);
|
||||
if(temp[0] != '\0' && strlen(temp) > 0)
|
||||
{
|
||||
partnerId = strdup(temp);
|
||||
}
|
||||
ParodusPrint("partnerId = %s\n",partnerId);
|
||||
if(partnerId != NULL)
|
||||
{
|
||||
parse_partner_id(partnerId, &partnersList);
|
||||
ParodusPrint("partnersList->count = %lu\n", partnersList->count);
|
||||
if(msg->msg_type == WRP_MSG_TYPE__EVENT)
|
||||
{
|
||||
if(msg->u.event.partner_ids != NULL)
|
||||
{
|
||||
count = (int) msg->u.event.partner_ids->count;
|
||||
ParodusPrint("partner_ids count is %d\n",count);
|
||||
for(i = 0; i < count; i++)
|
||||
{
|
||||
for(j = 0; j<partnersList->count; j++)
|
||||
{
|
||||
if(NULL != partnersList->partner_ids[j]) {
|
||||
ParodusPrint("partnersList->partner_ids[%lu] = %s\n",j, partnersList->partner_ids[j]);
|
||||
ParodusPrint("msg->u.event.partner_ids->partner_ids[%lu] = %s\n",i, msg->u.event.partner_ids->partner_ids[i]);
|
||||
if(strcasecmp(partnersList->partner_ids[j], msg->u.event.partner_ids->partner_ids[i]) == 0)
|
||||
{
|
||||
ParodusInfo("partner_id match found\n");
|
||||
matchFlag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
ParodusError("partner Id in partnersList is NULL but count is not 0");
|
||||
}
|
||||
/* Commandline input partner_ids matched with partner_ids from request */
|
||||
if(matchFlag == 1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Commandline input partner_ids not matching with partner_ids from request, appending to request partner_ids*/
|
||||
if(matchFlag != 1)
|
||||
{
|
||||
(*partnerIds) = (partners_t *) malloc(sizeof(partners_t) + (sizeof(char *) * (count+partnersList->count)));
|
||||
(*partnerIds)->count = count+partnersList->count;
|
||||
for(i = 0; i < count; i++)
|
||||
{
|
||||
(*partnerIds)->partner_ids[i] = msg->u.event.partner_ids->partner_ids[i];
|
||||
ParodusPrint("(*partnerIds)->partner_ids[%d] : %s\n",i,(*partnerIds)->partner_ids[i]);
|
||||
}
|
||||
i = 0;
|
||||
for(j = count; j<(count+partnersList->count); j++)
|
||||
{
|
||||
(*partnerIds)->partner_ids[j] = (char *) malloc(sizeof(char) * 64);
|
||||
parStrncpy((*partnerIds)->partner_ids[j], partnersList->partner_ids[i], 64);
|
||||
ParodusPrint("(*partnerIds)->partner_ids[%lu] : %s\n",j,(*partnerIds)->partner_ids[j]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("partner_ids list is NULL\n");
|
||||
(*partnerIds) = (partners_t *) malloc(sizeof(partners_t) + (sizeof(char *) * partnersList->count));
|
||||
(*partnerIds)->count = partnersList->count;
|
||||
i=0;
|
||||
for(j = 0; j<partnersList->count; j++)
|
||||
{
|
||||
(*partnerIds)->partner_ids[j] = (char *) malloc(sizeof(char) * 64);
|
||||
parStrncpy((*partnerIds)->partner_ids[j], partnersList->partner_ids[i], 64);
|
||||
ParodusPrint("(*partnerIds)->partner_ids[%lu] : %s\n",j,(*partnerIds)->partner_ids[j]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(msg->msg_type == WRP_MSG_TYPE__REQ)
|
||||
{
|
||||
if(msg->u.req.partner_ids != NULL)
|
||||
{
|
||||
count = (int) msg->u.req.partner_ids->count;
|
||||
ParodusPrint("partner_ids count is %d\n",count);
|
||||
for(i = 0; i < count; i++)
|
||||
{
|
||||
for(j = 0; j<partnersList->count; j++)
|
||||
{
|
||||
if(NULL != partnersList->partner_ids[j])
|
||||
{
|
||||
ParodusPrint("partnersList->partner_ids[%lu] = %s\n",j, partnersList->partner_ids[j]);
|
||||
ParodusPrint("msg->u.req.partner_ids->partner_ids[%lu] = %s\n",i, msg->u.req.partner_ids->partner_ids[i]);
|
||||
if(strcasecmp(partnersList->partner_ids[j], msg->u.req.partner_ids->partner_ids[i]) == 0)
|
||||
{
|
||||
ParodusInfo("partner_id match found\n");
|
||||
matchFlag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
ParodusError("partner Id in partnersList is NULL but count is not 0");
|
||||
}
|
||||
}
|
||||
|
||||
/* Commandline input partner_ids not matching with partner_ids from request, ignoring request*/
|
||||
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++)
|
||||
{
|
||||
if(NULL != partnersList->partner_ids[j])
|
||||
{
|
||||
free(partnersList->partner_ids[j]);
|
||||
}
|
||||
}
|
||||
free(partnersList);
|
||||
}
|
||||
free(partnerId);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("partner_ids list is NULL\n");
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("partner_id is not available to validate\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(msg->msg_type == WRP_MSG_TYPE__EVENT)
|
||||
{
|
||||
if(msg->u.event.partner_ids != NULL)
|
||||
{
|
||||
count = (int) msg->u.event.partner_ids->count;
|
||||
ParodusPrint("partner_ids count is %d\n",count);
|
||||
for(i = 0; i < count; i++)
|
||||
{
|
||||
if(strcmp(partnerId, msg->u.event.partner_ids->partner_ids[i]) == 0)
|
||||
{
|
||||
ParodusInfo("partner_id match found\n");
|
||||
matchFlag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(matchFlag != 1)
|
||||
{
|
||||
(*partnerIds) = (partners_t *) malloc(sizeof(partners_t) + (sizeof(char *) * (count+1)));
|
||||
(*partnerIds)->count = count+1;
|
||||
for(i = 0; i < count; i++)
|
||||
{
|
||||
(*partnerIds)->partner_ids[i] = msg->u.event.partner_ids->partner_ids[i];
|
||||
ParodusPrint("(*partnerIds)->partner_ids[%d] : %s\n",i,(*partnerIds)->partner_ids[i]);
|
||||
}
|
||||
(*partnerIds)->partner_ids[count] = (char *) malloc(sizeof(char) * 64);
|
||||
parStrncpy((*partnerIds)->partner_ids[count], partnerId, 64);
|
||||
ParodusPrint("(*partnerIds)->partner_ids[%d] : %s\n",count,(*partnerIds)->partner_ids[count]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("partner_ids list is NULL\n");
|
||||
(*partnerIds) = (partners_t *) malloc(sizeof(partners_t) + (sizeof(char *) * 1));
|
||||
(*partnerIds)->count = 1;
|
||||
(*partnerIds)->partner_ids[0] = (char *) malloc(sizeof(char) * 64);
|
||||
parStrncpy((*partnerIds)->partner_ids[0], partnerId, 64);
|
||||
ParodusPrint("(*partnerIds)->partner_ids[0] : %s\n",(*partnerIds)->partner_ids[0]);
|
||||
}
|
||||
}
|
||||
else if(msg->msg_type == WRP_MSG_TYPE__REQ)
|
||||
{
|
||||
if(msg->u.req.partner_ids != NULL)
|
||||
{
|
||||
count = (int) msg->u.req.partner_ids->count;
|
||||
ParodusPrint("partner_ids count is %d\n",count);
|
||||
for(i = 0; i < count; i++)
|
||||
{
|
||||
if(strcmp(partnerId, msg->u.req.partner_ids->partner_ids[i]) == 0)
|
||||
{
|
||||
ParodusInfo("partner_id match found\n");
|
||||
matchFlag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(matchFlag != 1)
|
||||
{
|
||||
ParodusError("Invalid partner_id %s\n",partnerId);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusPrint("partner_ids list is NULL\n");
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
22
src/token.c
22
src/token.c
@@ -111,8 +111,7 @@ static void show_times (time_t exp_time, time_t cur_time)
|
||||
}
|
||||
|
||||
// returns 1 if insecure, 0 if secure, < 0 if error
|
||||
int analyze_jwt (const cjwt_t *jwt, char *url_buf, int url_buflen,
|
||||
char *port_buf, int port_buflen)
|
||||
int analyze_jwt (const cjwt_t *jwt, char **url_buf, unsigned int *port)
|
||||
{
|
||||
cJSON *claims = jwt->private_claims;
|
||||
cJSON *endpoint = NULL;
|
||||
@@ -140,13 +139,15 @@ int analyze_jwt (const cjwt_t *jwt, char *url_buf, int url_buflen,
|
||||
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;
|
||||
}
|
||||
}
|
||||
http_match = parse_webpa_url (endpoint->valuestring,
|
||||
url_buf, url_buflen, port_buf, port_buflen);
|
||||
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);
|
||||
@@ -474,8 +475,7 @@ static void get_dns_txt_record_id (char *buf)
|
||||
}
|
||||
#endif
|
||||
|
||||
int allow_insecure_conn(char *url_buf, int url_buflen,
|
||||
char *port_buf, int port_buflen)
|
||||
int allow_insecure_conn(char **server_addr, unsigned int *port)
|
||||
{
|
||||
#ifdef FEATURE_DNS_QUERY
|
||||
int insecure=0, ret = -1;
|
||||
@@ -523,13 +523,15 @@ int allow_insecure_conn(char *url_buf, int url_buflen,
|
||||
|
||||
//validate algo from --jwt_algo
|
||||
if( validate_algo(jwt) ) {
|
||||
insecure = analyze_jwt (jwt, url_buf, url_buflen, port_buf, port_buflen);
|
||||
insecure = analyze_jwt (jwt, server_addr, port);
|
||||
} else {
|
||||
insecure = TOKEN_ERR_ALGO_NOT_ALLOWED;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -537,10 +539,8 @@ end:
|
||||
if (NULL != jwt_token)
|
||||
free (jwt_token);
|
||||
#else
|
||||
(void) url_buf;
|
||||
(void) url_buflen;
|
||||
(void) port_buf;
|
||||
(void) port_buflen;
|
||||
(void) server_addr;
|
||||
(void) port;
|
||||
int insecure = TOKEN_NO_DNS_QUERY;
|
||||
#endif
|
||||
ParodusPrint ("Allow Insecure %d\n", insecure);
|
||||
|
||||
10
src/token.h
10
src/token.h
@@ -78,15 +78,13 @@ Yes Yes http True Default
|
||||
* query the dns server, obtain a jwt, determine if insecure
|
||||
* connections can be allowed.
|
||||
*
|
||||
* @param url_buf buffer containing endpoint value found in JWT
|
||||
* @param url_buflen len of the url buffer provided by caller
|
||||
* @param port_buf buffer containing port value found in JWT
|
||||
* @param port_buflen len of the port buffer provided by caller
|
||||
* @param server_addr ptr to buffer ptr containing endpoint value found in JWT
|
||||
* will be NULL if invalid, otherwise needs to be freed
|
||||
* @param port ptr to variable receiving the port number
|
||||
* @return 1 if insecure connection is allowed, 0 if not,
|
||||
* or one of the error codes given above.
|
||||
*/
|
||||
int allow_insecure_conn(char *url_buf, int url_buflen,
|
||||
char *port_buf, int port_buflen);
|
||||
int allow_insecure_conn (char **server_addr, unsigned int *port);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
259
src/upstream.c
259
src/upstream.c
@@ -28,12 +28,13 @@
|
||||
#include "connection.h"
|
||||
#include "client_list.h"
|
||||
#include "nopoll_helpers.h"
|
||||
#include "close_retry.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Macros */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#define METADATA_COUNT 12
|
||||
|
||||
#define PARODUS_SERVICE_NAME "parodus"
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -128,6 +129,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)
|
||||
@@ -136,11 +143,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));
|
||||
|
||||
@@ -176,6 +190,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
|
||||
@@ -191,11 +215,15 @@ void *processUpstreamMessage()
|
||||
{
|
||||
int rv=-1, rc = -1;
|
||||
int msgType;
|
||||
wrp_msg_t *msg;
|
||||
wrp_msg_t *msg,*retrieve_msg = NULL;
|
||||
void *bytes;
|
||||
reg_list_item_t *temp = NULL;
|
||||
int matchFlag = 0;
|
||||
int status = -1;
|
||||
char *device_id = NULL;
|
||||
size_t device_id_len = 0;
|
||||
size_t parodus_len;
|
||||
int ret = -1;
|
||||
|
||||
while(FOREVER())
|
||||
{
|
||||
@@ -216,34 +244,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)
|
||||
@@ -252,7 +286,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)
|
||||
@@ -283,11 +318,13 @@ 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);
|
||||
partners_t *partnersList = NULL;
|
||||
int j = 0;
|
||||
|
||||
int ret = validate_partner_id(msg, &partnersList);
|
||||
if(ret == 1)
|
||||
@@ -316,27 +353,84 @@ 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 );
|
||||
} 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 );
|
||||
}
|
||||
sendUpstreamMsgToServer(&message->msg, message->len);
|
||||
}
|
||||
}
|
||||
//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 );
|
||||
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)
|
||||
{
|
||||
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. */
|
||||
parodus_len = strlen( PARODUS_SERVICE_NAME );
|
||||
if( 0 == strncmp(PARODUS_SERVICE_NAME, &msg->u.crud.dest[device_id_len], parodus_len-1) )
|
||||
{
|
||||
/* For Parodus CRUD queue. */
|
||||
ParodusInfo("Create RetrieveMsg and add to parodus CRUD queue\n");
|
||||
createUpstreamRetrieveMsg(msg, &retrieve_msg);
|
||||
addCRUDmsgToQueue(retrieve_msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* For nanomsg clients. */
|
||||
getServiceNameAndSendResponse(msg, &message->msg, message->len);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Not for this device. Send upstream */
|
||||
ParodusInfo("sendUpstreamMsgToServer \n");
|
||||
sendUpstreamMsgToServer(&message->msg, message->len);
|
||||
}
|
||||
if(device_id != NULL)
|
||||
{
|
||||
free(device_id);
|
||||
device_id = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Failed to get device_id\n");
|
||||
}
|
||||
} else if (WRP_MSG_TYPE__SVC_ALIVE != msgType) {
|
||||
/* Don't reply to service alive message */
|
||||
sendUpstreamMsgToServer(&message->msg, message->len);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ParodusError("Error in msgpack decoding for upstream\n");
|
||||
}
|
||||
|
||||
//nn_freemsg should not be done for parodus/tags/ CRUD requests as it is not received through nanomsg.
|
||||
if ((msg && (msg->u.crud.source !=NULL) && strstr(msg->u.crud.source, "parodus") != NULL))
|
||||
if ((msg && (msg->u.crud.source !=NULL) && wrp_does_service_match("parodus", msg->u.crud.source) == 0))
|
||||
{
|
||||
free(message->msg);
|
||||
}
|
||||
@@ -357,6 +451,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);
|
||||
@@ -366,10 +464,112 @@ void *processUpstreamMessage()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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");
|
||||
}
|
||||
}
|
||||
|
||||
void sendUpstreamMsgToServer(void **resp_bytes, size_t resp_size)
|
||||
{
|
||||
void *appendData;
|
||||
size_t encodedSize;
|
||||
bool close_retry = false;
|
||||
//appending response with metadata
|
||||
if(metaPackSize > 0)
|
||||
{
|
||||
@@ -378,8 +578,19 @@ void sendUpstreamMsgToServer(void **resp_bytes, size_t resp_size)
|
||||
ParodusPrint("encodedSize after appending :%zu\n", encodedSize);
|
||||
|
||||
ParodusInfo("Sending response to server\n");
|
||||
sendMessage(get_global_conn(),appendData, encodedSize);
|
||||
|
||||
close_retry = get_close_retry();
|
||||
|
||||
/* send response when connection retry is not in progress. Also during cloud_disconnect UPDATE request. Here, close_retry becomes 1 hence check is added to send disconnect response to server. */
|
||||
//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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
free(appendData);
|
||||
appendData =NULL;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#define _UPSTREAM_H_
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include <wrp-c.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -47,8 +47,10 @@ typedef struct UpStreamMsg__
|
||||
void packMetaData();
|
||||
void *handle_upstream();
|
||||
void *processUpstreamMessage();
|
||||
|
||||
int getDeviceId(char **device_id, size_t *device_id_len);
|
||||
void 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);
|
||||
UpStreamMsg * get_global_UpStreamMsgQ(void);
|
||||
pthread_cond_t *get_global_nano_con(void);
|
||||
|
||||
@@ -18,7 +18,7 @@ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W -g -fprofile-arcs -ftest-cove
|
||||
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_LIBS gcov -lcunit -lcimplog -lwrp-c
|
||||
-luuid -lpthread -lmsgpackc -lnopoll -lnanomsg
|
||||
-luuid -lmsgpackc -lnopoll -lnanomsg -lpthread
|
||||
-Wl,--no-as-needed -lcjson -lcjwt -ltrower-base64
|
||||
-lssl -lcrypto -lrt -lm)
|
||||
|
||||
@@ -36,6 +36,20 @@ endif ()
|
||||
|
||||
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)
|
||||
target_link_libraries (test_heartBeatTimer ${PARODUS_COMMON_LIBS} -lcmocka)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_close_retry
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_close_retry COMMAND ${MEMORY_CHECK} ./test_close_retry)
|
||||
add_executable(test_close_retry test_close_retry.c ../src/close_retry.c)
|
||||
target_link_libraries (test_close_retry ${PARODUS_COMMON_LIBS} -lcmocka)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_mutex
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -57,26 +71,6 @@ 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)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# libpd_test
|
||||
#-------------------------------------------------------------------------------
|
||||
add_executable (libpd_test libpd_test.c ../src/string_helpers.c)
|
||||
|
||||
target_link_libraries (libpd_test
|
||||
cunit
|
||||
-llibparodus
|
||||
-lwrp-c
|
||||
-luuid
|
||||
-lmsgpackc
|
||||
-ltrower-base64
|
||||
-lnanomsg
|
||||
-lcimplog
|
||||
-lm
|
||||
-lpthread
|
||||
-lrt)
|
||||
if (ENABLE_SESHAT)
|
||||
target_link_libraries (libpd_test -llibseshat)
|
||||
endif (ENABLE_SESHAT)
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_time
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -109,7 +103,7 @@ 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)
|
||||
add_executable(test_nopoll_handlers test_nopoll_handlers.c ../src/nopoll_handlers.c ../src/heartBeat.c ../src/close_retry.c)
|
||||
target_link_libraries (test_nopoll_handlers -lnopoll -lcunit -lcimplog -Wl,--no-as-needed -lrt -lpthread -lm)
|
||||
|
||||
|
||||
@@ -117,29 +111,29 @@ 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)
|
||||
add_executable(test_nopoll_handlers_fragment test_nopoll_handlers_fragment.c ../src/nopoll_handlers.c ../src/heartBeat.c ../src/close_retry.c)
|
||||
target_link_libraries (test_nopoll_handlers_fragment -lnopoll -lcunit -lcimplog -Wl,--no-as-needed -lrt -lpthread -lm -lcmocka)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_connection
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_connection COMMAND ${MEMORY_CHECK} ./test_connection)
|
||||
#add_executable(test_connection test_connection.c ../src/connection.c ${PARODUS_COMMON_SRC})
|
||||
#target_link_libraries (test_connection ${PARODUS_COMMON_LIBS} -lcmocka)
|
||||
set(CONN_SRC test_connection.c ../src/connection.c ../src/heartBeat.c ${PARODUS_COMMON_SRC})
|
||||
add_executable(test_connection ${CONN_SRC})
|
||||
#target_link_libraries (test_connection ${PARODUS_CONN_LIBS} ${PARODUS_COMMON_LIBS} -lcmocka)
|
||||
target_link_libraries (test_connection ${PARODUS_COMMON_LIBS} -lcmocka)
|
||||
set (CONN_SRC ../src/connection.c
|
||||
../src/string_helpers.c ../src/mutex.c ../src/time.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 -lcurl -luuid)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_connection - function createNopollConnection
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_createConnection COMMAND ${MEMORY_CHECK} ./test_createConnection)
|
||||
#add_test(NAME test_createConnection COMMAND ${MEMORY_CHECK} ./test_createConnection)
|
||||
#add_executable(test_createConnection test_createConnection.c ../src/connection.c ../src/string_helpers.c ../src/config.c)
|
||||
#target_link_libraries (test_createConnection ${PARODUS_COMMON_LIBS} -lcmocka)
|
||||
add_executable(test_createConnection test_createConnection.c ../src/connection.c ../src/string_helpers.c ../src/config.c ../src/heartBeat.c)
|
||||
#add_executable(test_createConnection test_createConnection.c ../src/connection.c ../src/string_helpers.c ../src/config.c ../src/heartBeat.c)
|
||||
#target_link_libraries (test_createConnection ${PARODUS_CONN_LIBS} ${PARODUS_COMMON_LIBS} -lcmocka )
|
||||
target_link_libraries (test_createConnection ${PARODUS_COMMON_LIBS} -lcmocka )
|
||||
#target_link_libraries (test_createConnection ${PARODUS_COMMON_LIBS} -lcmocka )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_client_list
|
||||
@@ -147,9 +141,9 @@ target_link_libraries (test_createConnection ${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/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
|
||||
../src/partners_check.c ../src/crud_interface.c ../src/crud_tasks.c ../src/crud_internal.c ${PARODUS_COMMON_SRC})
|
||||
|
||||
@@ -161,7 +155,7 @@ endif (ENABLE_SESHAT)
|
||||
|
||||
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
|
||||
@@ -169,7 +163,7 @@ 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 ${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()
|
||||
@@ -178,16 +172,36 @@ endif (ENABLE_SESHAT)
|
||||
|
||||
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)
|
||||
target_link_libraries (test_auth_token_more -lcmocka
|
||||
-Wl,--no-as-needed -lcimplog
|
||||
-lcjson -lcjwt -ltrower-base64 -lssl -lcrypto -lrt -lm -lcurl -luuid
|
||||
)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -208,22 +222,39 @@ 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/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/string_helpers.c ../src/crud_internal.c )
|
||||
target_link_libraries (test_crud_internal -lcmocka ${PARODUS_COMMON_LIBS} -lcurl -luuid)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_upstream
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_upstream COMMAND ${MEMORY_CHECK} ./test_upstream)
|
||||
add_executable(test_upstream test_upstream.c ../src/upstream.c ../src/string_helpers.c)
|
||||
target_link_libraries (test_upstream -lcmocka ${PARODUS_COMMON_LIBS} )
|
||||
add_executable(test_upstream test_upstream.c ../src/upstream.c ../src/close_retry.c ../src/string_helpers.c)
|
||||
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)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# 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)
|
||||
target_link_libraries (test_downstream -lcmocka ${PARODUS_COMMON_LIBS} )
|
||||
target_link_libraries (test_downstream -lcmocka gcov -lcunit -lcimplog
|
||||
-lwrp-c -luuid -lpthread -lmsgpackc -lnopoll
|
||||
-Wl,--no-as-needed -lcjson -lcjwt -ltrower-base64
|
||||
-lssl -lcrypto -lrt -lm)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_downstream_more
|
||||
@@ -251,6 +282,7 @@ set(CONIFC_SRC test_conn_interface.c
|
||||
../src/string_helpers.c
|
||||
../src/mutex.c
|
||||
../src/heartBeat.c
|
||||
../src/close_retry.c
|
||||
)
|
||||
if (ENABLE_SESHAT)
|
||||
set(CONIFC_SRC ${CONIFC_SRC} ../src/seshat_interface.c)
|
||||
@@ -258,14 +290,14 @@ else()
|
||||
set(CONIFC_SRC ${CONIFC_SRC} ../src/seshat_interface_stub.c)
|
||||
endif (ENABLE_SESHAT)
|
||||
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
|
||||
@@ -284,10 +316,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
|
||||
)
|
||||
|
||||
if (ENABLE_SESHAT)
|
||||
@@ -304,7 +337,7 @@ endif (FEATURE_DNS_QUERY)
|
||||
|
||||
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
|
||||
@@ -346,5 +379,5 @@ set(SIMPLE_SRC ${SIMPLE_SRC} ../src/seshat_interface_stub.c)
|
||||
endif (ENABLE_SESHAT)
|
||||
add_executable(simple ${SIMPLE_SRC})
|
||||
|
||||
target_link_libraries (simple ${PARODUS_CONN_LIBS} ${PARODUS_COMMON_LIBS} gcov -lnopoll -lnanomsg )
|
||||
target_link_libraries (simple ${PARODUS_CONN_LIBS} ${PARODUS_COMMON_LIBS} gcov -lnopoll )
|
||||
endif (INTEGRATION_TESTING)
|
||||
|
||||
@@ -1,409 +0,0 @@
|
||||
/**
|
||||
* 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 <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <CUnit/Basic.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <libparodus.h>
|
||||
#include <pthread.h>
|
||||
#include "../src/ParodusInternal.h"
|
||||
|
||||
#define SEND_EVENT_MSGS 1
|
||||
|
||||
//#define TCP_URL(ip) "tcp://" ip
|
||||
|
||||
#define GOOD_CLIENT_URL "tcp://127.0.0.1:6667"
|
||||
//#define PARODUS_URL "ipc:///tmp/parodus_server.ipc"
|
||||
#define GOOD_PARODUS_URL "tcp://127.0.0.1:6666"
|
||||
//#define CLIENT_URL "ipc:///tmp/parodus_client.ipc"
|
||||
|
||||
|
||||
static void initEndKeypressHandler();
|
||||
static void *endKeypressHandlerTask();
|
||||
|
||||
static pthread_t endKeypressThreadId;
|
||||
|
||||
static const char *service_name = "iot";
|
||||
//static const char *service_name = "config";
|
||||
|
||||
static bool no_mock_send_only_test = false;
|
||||
|
||||
static libpd_instance_t test_instance;
|
||||
|
||||
// libparodus functions to be tested
|
||||
extern int flush_wrp_queue (uint32_t delay_ms);
|
||||
extern int connect_receiver (const char *rcv_url);
|
||||
extern int connect_sender (const char *send_url);
|
||||
extern void shutdown_socket (int *sock);
|
||||
|
||||
extern bool is_auth_received (void);
|
||||
extern int libparodus_receive__ (wrp_msg_t **msg, uint32_t ms);
|
||||
|
||||
// libparodus_log functions to be tested
|
||||
extern int get_valid_file_num (const char *file_name, const char *date);
|
||||
extern int get_last_file_num_in_dir (const char *date, const char *log_dir);
|
||||
|
||||
extern const char *wrp_queue_name;
|
||||
extern const char *parodus_url;
|
||||
extern const char *client_url;
|
||||
extern volatile int keep_alive_count;
|
||||
extern volatile int reconnect_count;
|
||||
|
||||
void show_src_dest_payload (char *src, char *dest, void *payload, size_t payload_size)
|
||||
{
|
||||
size_t i;
|
||||
char *payload_str = (char *) payload;
|
||||
printf (" SOURCE: %s\n", src);
|
||||
printf (" DEST : %s\n", dest);
|
||||
printf (" PAYLOAD: ");
|
||||
for (i=0; i<payload_size; i++)
|
||||
putchar (payload_str[i]);
|
||||
putchar ('\n');
|
||||
}
|
||||
|
||||
void show_wrp_req_msg (struct wrp_req_msg *msg)
|
||||
{
|
||||
show_src_dest_payload (msg->source, msg->dest, msg->payload, msg->payload_size);
|
||||
}
|
||||
|
||||
void show_wrp_event_msg (struct wrp_event_msg *msg)
|
||||
{
|
||||
show_src_dest_payload (msg->source, msg->dest, msg->payload, msg->payload_size);
|
||||
}
|
||||
|
||||
void show_wrp_msg (wrp_msg_t *wrp_msg)
|
||||
{
|
||||
printf ("Received WRP Msg type %d\n", wrp_msg->msg_type);
|
||||
if (wrp_msg->msg_type == WRP_MSG_TYPE__REQ) {
|
||||
show_wrp_req_msg (&wrp_msg->u.req);
|
||||
return;
|
||||
}
|
||||
if (wrp_msg->msg_type == WRP_MSG_TYPE__EVENT) {
|
||||
show_wrp_event_msg (&wrp_msg->u.event);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void send_reply (wrp_msg_t *wrp_msg)
|
||||
{
|
||||
size_t i;
|
||||
size_t payload_size = wrp_msg->u.req.payload_size;
|
||||
char *payload = (char *) wrp_msg->u.req.payload;
|
||||
char *temp;
|
||||
// swap source and dest
|
||||
temp = wrp_msg->u.req.source;
|
||||
wrp_msg->u.req.source = wrp_msg->u.req.dest;
|
||||
wrp_msg->u.req.dest = temp;
|
||||
// Alter the payload
|
||||
for (i=0; i<payload_size; i++)
|
||||
payload[i] = tolower (payload[i]);
|
||||
libparodus_send (test_instance, wrp_msg);
|
||||
}
|
||||
|
||||
char *new_str (const char *str)
|
||||
{
|
||||
char *buf = malloc (strlen(str) + 1);
|
||||
if (NULL == buf)
|
||||
return NULL;
|
||||
parStrncpy(buf, str, (strlen(str)+1));
|
||||
return buf;
|
||||
}
|
||||
|
||||
void insert_number_into_buf (char *buf, unsigned num)
|
||||
{
|
||||
char *pos = strrchr (buf, '#');
|
||||
if (NULL == pos)
|
||||
return;
|
||||
while (true) {
|
||||
*pos = (num%10) + '0';
|
||||
num /= 10;
|
||||
if (pos <= buf)
|
||||
break;
|
||||
pos--;
|
||||
if (*pos != '#')
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int send_event_msg (const char *src, const char *dest,
|
||||
const char *payload, unsigned event_num)
|
||||
{
|
||||
int rtn = 0;
|
||||
char *payload_buf;
|
||||
wrp_msg_t *new_msg;
|
||||
|
||||
#ifndef SEND_EVENT_MSGS
|
||||
return 0;
|
||||
#endif
|
||||
new_msg = malloc (sizeof (wrp_msg_t));
|
||||
if (NULL == new_msg)
|
||||
return -1;
|
||||
printf ("Making event msg\n");
|
||||
new_msg->msg_type = WRP_MSG_TYPE__EVENT;
|
||||
new_msg->u.event.source = new_str (src);
|
||||
new_msg->u.event.dest = new_str (dest);
|
||||
new_msg->u.event.headers = NULL;
|
||||
new_msg->u.event.metadata = NULL;
|
||||
payload_buf = new_str (payload);
|
||||
insert_number_into_buf (payload_buf, event_num);
|
||||
new_msg->u.event.payload = (void*) payload_buf;
|
||||
new_msg->u.event.payload_size = strlen (payload) + 1;
|
||||
printf ("Sending event msg %u\n", event_num);
|
||||
rtn = libparodus_send (test_instance, new_msg);
|
||||
//printf ("Freeing event msg\n");
|
||||
wrp_free_struct (new_msg);
|
||||
//printf ("Freed event msg\n");
|
||||
return rtn;
|
||||
}
|
||||
|
||||
int send_event_msgs (unsigned *msg_num, unsigned *event_num, int count)
|
||||
{
|
||||
int i;
|
||||
unsigned msg_num_mod;
|
||||
|
||||
#ifndef SEND_EVENT_MSGS
|
||||
return 0;
|
||||
#endif
|
||||
if (NULL != msg_num) {
|
||||
(*msg_num)++;
|
||||
msg_num_mod = (*msg_num) % 3;
|
||||
if (msg_num_mod != 0)
|
||||
return 0;
|
||||
}
|
||||
for (i=0; i<count; i++) {
|
||||
(*event_num)++;
|
||||
if (send_event_msg ("---LIBPARODUS---", "---ParodusService---",
|
||||
"---EventMessagePayload####", *event_num) != 0)
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_msg_num (const char *msg)
|
||||
{
|
||||
int num = -1;
|
||||
bool found_pound = false;
|
||||
int i;
|
||||
char c;
|
||||
|
||||
for (i=0; (c=msg[i]) != 0; i++)
|
||||
{
|
||||
if (!found_pound) {
|
||||
if (c == '#')
|
||||
found_pound = true;
|
||||
continue;
|
||||
}
|
||||
if ((c>='0') && (c<='9')) {
|
||||
if (num == -1)
|
||||
num = c - '0';
|
||||
else
|
||||
num = 10*num + (c - '0');
|
||||
}
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
static int flush_queue_count = 0;
|
||||
|
||||
void qfree (void * msg)
|
||||
{
|
||||
flush_queue_count++;
|
||||
free (msg);
|
||||
}
|
||||
|
||||
void delay_ms(unsigned int secs, unsigned int msecs)
|
||||
{
|
||||
struct timespec ts;
|
||||
ts.tv_sec = (time_t) secs;
|
||||
ts.tv_nsec = (long) msecs * 1000000L;
|
||||
nanosleep (&ts, NULL);
|
||||
}
|
||||
|
||||
void dbg_log_err (const char *fmt, ...)
|
||||
{
|
||||
char errbuf[100];
|
||||
|
||||
va_list arg_ptr;
|
||||
|
||||
va_start(arg_ptr, fmt);
|
||||
vprintf(fmt, arg_ptr);
|
||||
va_end(arg_ptr);
|
||||
|
||||
if( 0 == strerror_r (errno, errbuf, 100) ) {
|
||||
printf("LIBPD_TEST: %s\n", errbuf);
|
||||
} else {
|
||||
printf("LIBPD_TEST: strerror_r returned failure!\n");
|
||||
}
|
||||
}
|
||||
|
||||
void wait_auth_received (void)
|
||||
{
|
||||
if (!is_auth_received ()) {
|
||||
printf ("Waiting for auth received\n");
|
||||
sleep(1);
|
||||
}
|
||||
if (!is_auth_received ()) {
|
||||
printf ("Waiting for auth received\n");
|
||||
sleep(1);
|
||||
}
|
||||
CU_ASSERT (is_auth_received ());
|
||||
}
|
||||
|
||||
void test_send_only (void)
|
||||
{
|
||||
unsigned event_num = 0;
|
||||
|
||||
libpd_cfg_t cfg = {.service_name = service_name,
|
||||
.receive = false, .keepalive_timeout_secs = 0};
|
||||
CU_ASSERT (libparodus_init (&test_instance, &cfg) == 0);
|
||||
CU_ASSERT (send_event_msgs (NULL, &event_num, 10) == 0);
|
||||
CU_ASSERT (libparodus_shutdown (&test_instance) == 0);
|
||||
}
|
||||
|
||||
void test_1(void)
|
||||
{
|
||||
unsigned msgs_received_count = 0;
|
||||
int rtn;
|
||||
wrp_msg_t *wrp_msg;
|
||||
unsigned event_num = 0;
|
||||
unsigned msg_num = 0;
|
||||
libpd_cfg_t cfg = {.service_name = service_name,
|
||||
.receive = true, .keepalive_timeout_secs = 0};
|
||||
|
||||
if (no_mock_send_only_test) {
|
||||
test_send_only ();
|
||||
return;
|
||||
}
|
||||
|
||||
cfg.parodus_url = GOOD_PARODUS_URL;
|
||||
cfg.client_url = GOOD_CLIENT_URL;
|
||||
CU_ASSERT (libparodus_init (&test_instance, &cfg) == 0);
|
||||
printf ("LIBPD_TEST: libparodus_init successful\n");
|
||||
initEndKeypressHandler ();
|
||||
|
||||
wait_auth_received ();
|
||||
|
||||
printf ("LIBPD_TEST: starting msg receive loop\n");
|
||||
while (true) {
|
||||
rtn = libparodus_receive (test_instance, &wrp_msg, 2000);
|
||||
if (rtn == 1) {
|
||||
printf ("LIBPD_TEST: Timed out waiting for msg\n");
|
||||
if (msgs_received_count > 0)
|
||||
if (send_event_msgs (&msg_num, &event_num, 5) != 0)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
if (rtn != 0)
|
||||
break;
|
||||
show_wrp_msg (wrp_msg);
|
||||
msgs_received_count++;
|
||||
if (wrp_msg->msg_type == WRP_MSG_TYPE__REQ)
|
||||
send_reply (wrp_msg);
|
||||
wrp_free_struct (wrp_msg);
|
||||
if (send_event_msgs (&msg_num, &event_num, 5) != 0)
|
||||
break;
|
||||
}
|
||||
printf ("Messages received %u\n", msgs_received_count);
|
||||
CU_ASSERT (libparodus_shutdown (&test_instance) == 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief To initiate end keypress handler
|
||||
*/
|
||||
static void initEndKeypressHandler()
|
||||
{
|
||||
int err = 0;
|
||||
err = pthread_create(&endKeypressThreadId, NULL, endKeypressHandlerTask, NULL);
|
||||
if (err != 0)
|
||||
{
|
||||
libpd_log (LEVEL_ERROR, "Error creating End Keypress Handler thread\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("End Keypress handler Thread created successfully\n");
|
||||
printf ("\n--->> Press <Enter> to shutdown the test. ---\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief To handle End Keypress
|
||||
*/
|
||||
static void *endKeypressHandlerTask()
|
||||
{
|
||||
char inbuf[10];
|
||||
memset(inbuf, 0, 10);
|
||||
while (true) {
|
||||
fgets (inbuf, 10, stdin);
|
||||
if ((inbuf[0] != '\n') && (inbuf[0] != '\0')) {
|
||||
printf ("endKeyPressHandler exiting\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
libparodus_close_receiver (test_instance);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void add_suites( CU_pSuite *suite )
|
||||
{
|
||||
*suite = CU_add_suite( "libparodus tests", NULL, NULL );
|
||||
CU_add_test( *suite, "Test 1", test_1 );
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int main( int argc, char **argv __attribute__((unused)) )
|
||||
{
|
||||
unsigned rv = 1;
|
||||
CU_pSuite suite = NULL;
|
||||
|
||||
if (argc > 1) {
|
||||
const char *arg = argv[1];
|
||||
if ((arg[0] == 's') || (arg[0] == 'S'))
|
||||
no_mock_send_only_test = true;
|
||||
}
|
||||
|
||||
if( CUE_SUCCESS == CU_initialize_registry() ) {
|
||||
add_suites( &suite );
|
||||
|
||||
if( NULL != suite ) {
|
||||
CU_basic_set_mode( CU_BRM_VERBOSE );
|
||||
CU_basic_run_tests();
|
||||
printf( "\n" );
|
||||
CU_basic_show_failures( CU_get_failure_list() );
|
||||
printf( "\n\n" );
|
||||
rv = CU_get_number_of_tests_failed();
|
||||
}
|
||||
|
||||
CU_cleanup_registry();
|
||||
}
|
||||
|
||||
if( 0 != rv ) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
1
tests/return_failure.bsh
Executable file
1
tests/return_failure.bsh
Executable file
@@ -0,0 +1 @@
|
||||
echo -n FAILURE
|
||||
1
tests/return_ser_mac.bsh
Executable file
1
tests/return_ser_mac.bsh
Executable file
@@ -0,0 +1 @@
|
||||
echo -n SER_MAC $1 $2
|
||||
1
tests/return_success.bsh
Executable file
1
tests/return_success.bsh
Executable file
@@ -0,0 +1 @@
|
||||
echo -n SUCCESS
|
||||
@@ -108,7 +108,7 @@ void test_timespec_diff()
|
||||
clock_gettime(CLOCK_REALTIME, &stop);
|
||||
timespec_diff(&start, &stop, &diff);
|
||||
time_taken_ms = diff.tv_sec * 1000 + (diff.tv_nsec / 1000000);
|
||||
assert_int_equal(time_taken_ms, 1000);
|
||||
assert_true(time_taken_ms >= 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -124,7 +124,7 @@ void test_timespec_diff1()
|
||||
clock_gettime(CLOCK_REALTIME, &stop);
|
||||
timespec_diff(&stop, &start, &diff);
|
||||
time_taken_ms = diff.tv_sec * 1000 + (diff.tv_nsec / 1000000);
|
||||
assert_int_equal(time_taken_ms, -1001);
|
||||
assert_true(time_taken_ms <= 0);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
334
tests/test_auth_token.c
Normal file
334
tests/test_auth_token.c
Normal file
@@ -0,0 +1,334 @@
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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;
|
||||
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;
|
||||
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);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
109
tests/test_auth_token_more.c
Normal file
109
tests/test_auth_token_more.c
Normal file
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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,6 +26,9 @@
|
||||
#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();
|
||||
|
||||
@@ -58,7 +61,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 +76,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 +192,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 +209,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");
|
||||
|
||||
93
tests/test_close_retry.c
Normal file
93
tests/test_close_retry.c
Normal file
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* Copyright 2018 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 <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "../src/close_retry.h"
|
||||
#include "../src/parodus_log.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void test_close_retry() {
|
||||
/* get close_retry initial value */
|
||||
bool close_retry =false;
|
||||
close_retry = get_close_retry();
|
||||
ParodusInfo("close_retry initial value is: %d\n", close_retry);
|
||||
assert_int_equal(close_retry, 0);
|
||||
|
||||
/* set close_retry value and check whether its returning modified value or not*/
|
||||
set_close_retry();
|
||||
close_retry = get_close_retry();
|
||||
ParodusInfo("close_retry modified to: %d\n", close_retry);
|
||||
assert_int_equal(close_retry,1);
|
||||
|
||||
/* reset close_retry */
|
||||
reset_close_retry();
|
||||
close_retry = get_close_retry();
|
||||
ParodusInfo("close_retry reset to: %d\n", close_retry);
|
||||
assert_int_equal(close_retry,0);
|
||||
}
|
||||
|
||||
void *test_mutex_set_close_retry() {
|
||||
set_close_retry();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *test_mutex_reset_close_retry() {
|
||||
reset_close_retry();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void test_mutex_close_retry() {
|
||||
bool close_retry;
|
||||
pthread_t thread[3];
|
||||
|
||||
pthread_create(&thread[0], NULL, test_mutex_set_close_retry, NULL);
|
||||
pthread_create(&thread[1], NULL, test_mutex_set_close_retry, NULL);
|
||||
|
||||
pthread_join(thread[0], NULL);
|
||||
pthread_join(thread[1], NULL);
|
||||
|
||||
/* After execution of threads check the value of close_retry */
|
||||
close_retry = get_close_retry();
|
||||
ParodusInfo("Threads execution is completed, close_retry is: %d\n", close_retry);
|
||||
assert_int_equal(close_retry, 1);
|
||||
|
||||
pthread_create(&thread[2], NULL, test_mutex_reset_close_retry, NULL);
|
||||
pthread_join(thread[2], NULL);
|
||||
|
||||
close_retry = get_close_retry();
|
||||
ParodusInfo("close_retry reset to: %d\n", close_retry);
|
||||
assert_int_equal(close_retry, 0);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int main(void)
|
||||
{
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(test_close_retry),
|
||||
cmocka_unit_test(test_mutex_close_retry)
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
@@ -25,14 +25,17 @@
|
||||
#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 server_is_http (const char *full_url,
|
||||
const char **server_ptr);
|
||||
extern int parse_webpa_url(const char *full_url,
|
||||
extern int parse_webpa_url__(const char *full_url,
|
||||
char *server_addr, int server_addr_buflen,
|
||||
char *port_buf, int port_buflen);
|
||||
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);
|
||||
|
||||
@@ -49,6 +52,7 @@ void create_token_script(char *fname)
|
||||
sprintf(command, "chmod +x %s",fname);
|
||||
system(command);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -180,9 +184,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",
|
||||
@@ -210,6 +215,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);
|
||||
@@ -220,18 +226,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");
|
||||
}
|
||||
|
||||
@@ -313,13 +321,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);
|
||||
|
||||
@@ -330,14 +338,14 @@ 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");
|
||||
@@ -413,6 +421,7 @@ void test_setDefaultValuesToCfg()
|
||||
assert_int_equal((int)cfg->flags, 0);
|
||||
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);
|
||||
}
|
||||
|
||||
void err_setDefaultValuesToCfg()
|
||||
@@ -453,35 +462,89 @@ void test_server_is_http ()
|
||||
|
||||
}
|
||||
|
||||
void test_parse_webpa_url ()
|
||||
void test_parse_webpa_url__ ()
|
||||
{
|
||||
char addr_buf[80];
|
||||
char port_buf[8];
|
||||
assert_int_equal (parse_webpa_url ("mydns.mycom.net:8080",
|
||||
assert_int_equal (parse_webpa_url__ ("mydns.mycom.net:8080",
|
||||
addr_buf, 80, port_buf, 8), -1);
|
||||
assert_int_equal (parse_webpa_url ("https://mydns.mycom.net:8080",
|
||||
assert_int_equal (parse_webpa_url__ ("https://mydns.mycom.net:8080",
|
||||
addr_buf, 80, port_buf, 8), 0);
|
||||
assert_string_equal (addr_buf, "mydns.mycom.net");
|
||||
assert_string_equal (port_buf, "8080");
|
||||
assert_int_equal (parse_webpa_url ("https://mydns.mycom.net/",
|
||||
assert_int_equal (parse_webpa_url__ ("https://mydns.mycom.net/",
|
||||
addr_buf, 80, port_buf, 8), 0);
|
||||
assert_string_equal (addr_buf, "mydns.mycom.net");
|
||||
assert_string_equal (port_buf, "443");
|
||||
assert_int_equal (parse_webpa_url ("https://mydns.mycom.net/api/v2/",
|
||||
assert_int_equal (parse_webpa_url__ ("https://mydns.mycom.net/api/v2/",
|
||||
addr_buf, 80, port_buf, 8), 0);
|
||||
assert_string_equal (addr_buf, "mydns.mycom.net");
|
||||
assert_string_equal (port_buf, "443");
|
||||
assert_int_equal (parse_webpa_url ("http://mydns.mycom.net:8080",
|
||||
assert_int_equal (parse_webpa_url__ ("http://mydns.mycom.net:8080",
|
||||
addr_buf, 80, port_buf, 8), 1);
|
||||
assert_string_equal (addr_buf, "mydns.mycom.net");
|
||||
assert_string_equal (port_buf, "8080");
|
||||
assert_int_equal (parse_webpa_url ("http://mydns.mycom.net",
|
||||
assert_int_equal (parse_webpa_url__ ("http://mydns.mycom.net",
|
||||
addr_buf, 80, port_buf, 8), 1);
|
||||
assert_string_equal (addr_buf, "mydns.mycom.net");
|
||||
assert_string_equal (port_buf, "80");
|
||||
assert_int_equal (parse_webpa_url__ ("https://[2001:558:fc18:2:f816:3eff:fe7f:6efa]:8080",
|
||||
addr_buf, 80, port_buf, 8), 0);
|
||||
assert_string_equal (addr_buf, "2001:558:fc18:2:f816:3eff:fe7f:6efa");
|
||||
assert_string_equal (port_buf, "8080");
|
||||
assert_int_equal (parse_webpa_url__ ("https://[2001:558:fc18:2:f816:3eff:fe7f:6efa]",
|
||||
addr_buf, 80, port_buf, 8), 0);
|
||||
assert_string_equal (addr_buf, "2001:558:fc18:2:f816:3eff:fe7f:6efa");
|
||||
assert_string_equal (port_buf, "443");
|
||||
assert_int_equal (parse_webpa_url__ ("http://[2001:558:fc18:2:f816:3eff:fe7f:6efa]:8080",
|
||||
addr_buf, 80, port_buf, 8), 1);
|
||||
assert_string_equal (addr_buf, "2001:558:fc18:2:f816:3eff:fe7f:6efa");
|
||||
assert_string_equal (port_buf, "8080");
|
||||
assert_int_equal (parse_webpa_url__ ("http://[2001:558:fc18:2:f816:3eff:fe7f:6efa]",
|
||||
addr_buf, 80, port_buf, 8), 1);
|
||||
assert_string_equal (addr_buf, "2001:558:fc18:2:f816:3eff:fe7f:6efa");
|
||||
assert_string_equal (port_buf, "80");
|
||||
assert_int_equal (parse_webpa_url__ ("http://2001:558:fc18:2:f816:3eff:fe7f:6efa]",
|
||||
addr_buf, 80, port_buf, 8), -1);
|
||||
assert_int_equal (parse_webpa_url__ ("http://[2001:558:fc18:2:f816:3eff:fe7f:6efa",
|
||||
addr_buf, 80, port_buf, 8), -1);
|
||||
assert_int_equal (parse_webpa_url__ ("[2001:558:fc18:2:f816:3eff:fe7f:6efa",
|
||||
addr_buf, 80, port_buf, 8), -1);
|
||||
assert_int_equal (parse_webpa_url__ ("https://[2001:558:fc18:2:f816:3eff:fe7f:6efa]:8080/api/v2/",
|
||||
addr_buf, 80, port_buf, 8), 0);
|
||||
assert_string_equal (addr_buf, "2001:558:fc18:2:f816:3eff:fe7f:6efa");
|
||||
assert_string_equal (port_buf, "8080");
|
||||
|
||||
}
|
||||
|
||||
void test_parse_webpa_url ()
|
||||
{
|
||||
char *addr;
|
||||
unsigned int port;
|
||||
assert_int_equal (parse_webpa_url ("mydns.mycom.net:8080",
|
||||
&addr, &port), -1);
|
||||
assert_int_equal (parse_webpa_url ("https://mydns.mycom.net:8080",
|
||||
&addr, &port), 0);
|
||||
assert_string_equal (addr, "mydns.mycom.net");
|
||||
assert_int_equal (port, 8080);
|
||||
free (addr);
|
||||
assert_int_equal (parse_webpa_url ("https://mydns.mycom.net/",
|
||||
&addr, &port), 0);
|
||||
assert_string_equal (addr, "mydns.mycom.net");
|
||||
assert_int_equal (port, 443);
|
||||
free (addr);
|
||||
assert_int_equal (parse_webpa_url ("http://mydns.mycom.net:8080",
|
||||
&addr, &port), 1);
|
||||
assert_string_equal (addr, "mydns.mycom.net");
|
||||
assert_int_equal (port, 8080);
|
||||
free (addr);
|
||||
assert_int_equal (parse_webpa_url ("http://mydns.mycom.net",
|
||||
&addr, &port), 1);
|
||||
assert_string_equal (addr, "mydns.mycom.net");
|
||||
assert_int_equal (port, 80);
|
||||
free(addr);
|
||||
}
|
||||
|
||||
void test_get_algo_mask ()
|
||||
{
|
||||
assert_true (get_algo_mask ("RS256:RS512") == 5120);
|
||||
@@ -494,7 +557,6 @@ void test_get_algo_mask ()
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -511,11 +573,12 @@ int main(void)
|
||||
cmocka_unit_test(test_parse_mac_address),
|
||||
cmocka_unit_test(test_get_algo_mask),
|
||||
cmocka_unit_test(test_server_is_http),
|
||||
cmocka_unit_test(test_parse_webpa_url__),
|
||||
cmocka_unit_test(test_parse_webpa_url),
|
||||
cmocka_unit_test(test_parseCommandLine),
|
||||
cmocka_unit_test(test_parseCommandLineNull),
|
||||
cmocka_unit_test(err_parseCommandLine),
|
||||
cmocka_unit_test(test_parodusGitVersion),
|
||||
//cmocka_unit_test(test_parodusGitVersion),
|
||||
cmocka_unit_test(test_setDefaultValuesToCfg),
|
||||
cmocka_unit_test(err_setDefaultValuesToCfg),
|
||||
};
|
||||
|
||||
@@ -28,16 +28,20 @@
|
||||
#include "../src/connection.h"
|
||||
#include "../src/config.h"
|
||||
#include "../src/heartBeat.h"
|
||||
#include "../src/close_retry.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static char *reconnect_reason = "webpa_process_starts";
|
||||
UpStreamMsg *UpStreamMsgQ;
|
||||
ParodusMsg *ParodusMsgQ;
|
||||
extern bool close_retry;
|
||||
extern pthread_mutex_t close_mut;
|
||||
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;
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -71,12 +75,65 @@ 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);
|
||||
}
|
||||
|
||||
void start_conn_in_progress (void)
|
||||
{
|
||||
}
|
||||
|
||||
void stop_conn_in_progress (void)
|
||||
{
|
||||
}
|
||||
|
||||
void reset_interface_down_event (void)
|
||||
{
|
||||
}
|
||||
|
||||
bool get_interface_down_event (void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int wait_while_interface_down (void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void terminate_backoff_delay (void)
|
||||
{
|
||||
}
|
||||
|
||||
void packMetaData()
|
||||
{
|
||||
function_called();
|
||||
}
|
||||
|
||||
|
||||
int get_cloud_disconnect_time(void)
|
||||
{
|
||||
function_called();
|
||||
return (int) (intptr_t)mock();
|
||||
}
|
||||
|
||||
void set_cloud_disconnect_time(int Time)
|
||||
{
|
||||
UNUSED(Time);
|
||||
function_called();
|
||||
}
|
||||
|
||||
void *handle_upstream()
|
||||
{
|
||||
@@ -93,9 +150,9 @@ void *messageHandlerTask()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *serviceAliveTask()
|
||||
int serviceAliveTask()
|
||||
{
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nopoll_loop_wait(noPollCtx * ctx,long timeout)
|
||||
@@ -146,12 +203,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();
|
||||
@@ -182,6 +245,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
|
||||
@@ -195,6 +268,10 @@ void timespec_diff(struct timespec *start, struct timespec *stop,
|
||||
diff->tv_nsec = 1000;
|
||||
}
|
||||
|
||||
void deleteAllClients (void)
|
||||
{
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -204,10 +281,7 @@ void test_createSocketConnection()
|
||||
noPollCtx *ctx;
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg,0,sizeof(ParodusCfg));
|
||||
|
||||
pthread_mutex_lock (&close_mut);
|
||||
close_retry = false;
|
||||
pthread_mutex_unlock (&close_mut);
|
||||
reset_close_retry();
|
||||
expect_function_call(nopoll_thread_handlers);
|
||||
|
||||
will_return(nopoll_ctx_new, (intptr_t)&ctx);
|
||||
@@ -243,9 +317,7 @@ void test_createSocketConnection1()
|
||||
noPollCtx *ctx;
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg,0, sizeof(ParodusCfg));
|
||||
pthread_mutex_lock (&close_mut);
|
||||
close_retry = true;
|
||||
pthread_mutex_unlock (&close_mut);
|
||||
set_close_retry();
|
||||
expect_function_call(nopoll_thread_handlers);
|
||||
|
||||
will_return(nopoll_ctx_new, (intptr_t)&ctx);
|
||||
@@ -294,9 +366,7 @@ void test_PingMissIntervalTime()
|
||||
cfg.webpa_ping_timeout = 6;
|
||||
set_parodus_cfg(&cfg);
|
||||
|
||||
pthread_mutex_lock (&close_mut);
|
||||
close_retry = false;
|
||||
pthread_mutex_unlock (&close_mut);
|
||||
reset_close_retry();
|
||||
expect_function_call(nopoll_thread_handlers);
|
||||
|
||||
will_return(nopoll_ctx_new, (intptr_t)&ctx);
|
||||
@@ -336,9 +406,7 @@ void test_PingMissIntervalTime()
|
||||
|
||||
void err_createSocketConnection()
|
||||
{
|
||||
pthread_mutex_lock (&close_mut);
|
||||
close_retry = true;
|
||||
pthread_mutex_unlock (&close_mut);
|
||||
set_close_retry();
|
||||
reset_heartBeatTimer();
|
||||
expect_function_call(nopoll_thread_handlers);
|
||||
|
||||
@@ -367,6 +435,53 @@ void err_createSocketConnection()
|
||||
createSocketConnection(NULL);
|
||||
}
|
||||
|
||||
|
||||
void test_createSocketConnection_cloud_disconn()
|
||||
{
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg,0,sizeof(ParodusCfg));
|
||||
cfg.cloud_disconnect = strdup("XPC");
|
||||
set_parodus_cfg(&cfg);
|
||||
|
||||
set_close_retry();
|
||||
reset_heartBeatTimer();
|
||||
expect_function_call(nopoll_thread_handlers);
|
||||
|
||||
will_return(nopoll_ctx_new, (intptr_t)NULL);
|
||||
expect_function_call(nopoll_ctx_new);
|
||||
expect_function_call(nopoll_log_set_handler);
|
||||
will_return(createNopollConnection, nopoll_true);
|
||||
expect_function_call(createNopollConnection);
|
||||
expect_function_call(packMetaData);
|
||||
|
||||
expect_function_calls(StartThread, 5);
|
||||
will_return(nopoll_loop_wait, 1);
|
||||
expect_function_call(nopoll_loop_wait);
|
||||
|
||||
will_return(get_global_conn, (intptr_t)NULL);
|
||||
expect_function_call(get_global_conn);
|
||||
expect_function_call(close_and_unref_connection);
|
||||
expect_function_call(set_global_conn);
|
||||
|
||||
|
||||
expect_function_call(set_cloud_disconnect_time);
|
||||
will_return(get_cloud_disconnect_time, 0);
|
||||
expect_function_call(get_cloud_disconnect_time);
|
||||
will_return(get_cloud_disconnect_time, 0);
|
||||
expect_function_call(get_cloud_disconnect_time);
|
||||
will_return(get_cloud_disconnect_time, 0);
|
||||
expect_function_call(get_cloud_disconnect_time);
|
||||
|
||||
will_return(createNopollConnection, nopoll_true);
|
||||
expect_function_call(createNopollConnection);
|
||||
will_return(get_global_conn, (intptr_t)NULL);
|
||||
expect_function_call(get_global_conn);
|
||||
expect_function_call(close_and_unref_connection);
|
||||
expect_function_call(nopoll_ctx_unref);
|
||||
expect_function_call(nopoll_cleanup_library);
|
||||
createSocketConnection(NULL);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -378,6 +493,7 @@ int main(void)
|
||||
cmocka_unit_test(test_createSocketConnection1),
|
||||
cmocka_unit_test(test_PingMissIntervalTime),
|
||||
cmocka_unit_test(err_createSocketConnection),
|
||||
cmocka_unit_test(test_createSocketConnection_cloud_disconn)
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -341,6 +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);
|
||||
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 */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
@@ -29,6 +29,21 @@
|
||||
#include "../src/crud_tasks.h"
|
||||
#include "../src/config.h"
|
||||
#include "../src/crud_internal.h"
|
||||
#include "../src/connection.h"
|
||||
#include "../src/close_retry.h"
|
||||
|
||||
bool LastReasonStatus;
|
||||
pthread_mutex_t close_mut;
|
||||
|
||||
void set_global_reconnect_reason(char *reason)
|
||||
{
|
||||
UNUSED(reason);
|
||||
}
|
||||
|
||||
void set_global_reconnect_status(bool status)
|
||||
{
|
||||
UNUSED(status);
|
||||
}
|
||||
|
||||
void test_writeToJSON_Failure()
|
||||
{
|
||||
@@ -150,7 +165,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);
|
||||
@@ -185,7 +200,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);
|
||||
@@ -1420,7 +1435,6 @@ void test_retrieveObject_invalid()
|
||||
memset(&cfg,0,sizeof(cfg));
|
||||
cfg.crud_config_file = strdup("parodus_cfg.json");
|
||||
set_parodus_cfg(&cfg);
|
||||
//testdata=strdup("{\"test\":{}}}");
|
||||
testdata=strdup("{\"tags\":{\"test1\":{\"expires\":1522451870}}}");
|
||||
write_ret = writeToJSON(testdata);
|
||||
assert_int_equal (write_ret, 1);
|
||||
@@ -1487,6 +1501,130 @@ void test_retrieveObject_readOnlyObj()
|
||||
wrp_free_struct(respMsg);
|
||||
}
|
||||
|
||||
void test_retrieveObject_cloud_status()
|
||||
{
|
||||
int ret = 0;
|
||||
int write_ret = -1;
|
||||
FILE *fp;
|
||||
char *testdata = NULL;
|
||||
wrp_msg_t *reqMsg = NULL;
|
||||
reqMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(reqMsg, 0, sizeof(wrp_msg_t));
|
||||
wrp_msg_t *respMsg = NULL;
|
||||
respMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(respMsg, 0, sizeof(wrp_msg_t));
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg,0,sizeof(cfg));
|
||||
cfg.cloud_status = CLOUD_STATUS_ONLINE;
|
||||
cfg.crud_config_file = strdup("parodus_cfg.json");
|
||||
set_parodus_cfg(&cfg);
|
||||
testdata=strdup("{\"tags\":{\"test1\":{\"expires\":1522451870}}}");
|
||||
write_ret = writeToJSON(testdata);
|
||||
assert_int_equal (write_ret, 1);
|
||||
reqMsg->msg_type = 6;
|
||||
reqMsg->u.crud.transaction_uuid = strdup("1234");
|
||||
reqMsg->u.crud.dest = strdup("mac:14xxx/parodus/cloud-status");
|
||||
respMsg->msg_type = 6;
|
||||
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_int_equal (respMsg->u.crud.payload_size, 25);
|
||||
|
||||
fp = fopen(cfg.crud_config_file, "r");
|
||||
if (fp != NULL)
|
||||
{
|
||||
system("rm parodus_cfg.json");
|
||||
fclose(fp);
|
||||
}
|
||||
if(cfg.crud_config_file !=NULL)
|
||||
free(cfg.crud_config_file);
|
||||
wrp_free_struct(reqMsg);
|
||||
wrp_free_struct(respMsg);
|
||||
}
|
||||
|
||||
void err_retrieveObject_cloud_statusNULL()
|
||||
{
|
||||
int ret = 0;
|
||||
int write_ret = -1;
|
||||
FILE *fp;
|
||||
char *testdata = NULL;
|
||||
wrp_msg_t *reqMsg = NULL;
|
||||
reqMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(reqMsg, 0, sizeof(wrp_msg_t));
|
||||
wrp_msg_t *respMsg = NULL;
|
||||
respMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(respMsg, 0, sizeof(wrp_msg_t));
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg,0,sizeof(cfg));
|
||||
cfg.cloud_status = NULL;
|
||||
cfg.crud_config_file = strdup("parodus_cfg.json");
|
||||
set_parodus_cfg(&cfg);
|
||||
testdata=strdup("{\"tags\":{\"test1\":{\"expires\":1522451870}}}");
|
||||
write_ret = writeToJSON(testdata);
|
||||
assert_int_equal (write_ret, 1);
|
||||
reqMsg->msg_type = 6;
|
||||
reqMsg->u.crud.transaction_uuid = strdup("1234");
|
||||
reqMsg->u.crud.dest = strdup("mac:14xxx/parodus/cloud-status");
|
||||
respMsg->msg_type = 6;
|
||||
ret = retrieveObject(reqMsg, &respMsg);
|
||||
assert_int_equal (respMsg->u.crud.status, 400);
|
||||
assert_int_equal (ret, -1);
|
||||
assert_int_equal (respMsg->u.crud.payload_size, 0);
|
||||
|
||||
fp = fopen(cfg.crud_config_file, "r");
|
||||
if (fp != NULL)
|
||||
{
|
||||
system("rm parodus_cfg.json");
|
||||
fclose(fp);
|
||||
}
|
||||
if(cfg.crud_config_file !=NULL)
|
||||
free(cfg.crud_config_file);
|
||||
wrp_free_struct(reqMsg);
|
||||
wrp_free_struct(respMsg);
|
||||
}
|
||||
|
||||
void err_retrieveObject_cloud_statusEmpty()
|
||||
{
|
||||
int ret = 0;
|
||||
int write_ret = -1;
|
||||
FILE *fp;
|
||||
char *testdata = NULL;
|
||||
wrp_msg_t *reqMsg = NULL;
|
||||
reqMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(reqMsg, 0, sizeof(wrp_msg_t));
|
||||
wrp_msg_t *respMsg = NULL;
|
||||
respMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(respMsg, 0, sizeof(wrp_msg_t));
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg,0,sizeof(cfg));
|
||||
cfg.cloud_status = "";
|
||||
cfg.crud_config_file = strdup("parodus_cfg.json");
|
||||
set_parodus_cfg(&cfg);
|
||||
testdata=strdup("{\"tags\":{\"test1\":{\"expires\":1522451870}}}");
|
||||
write_ret = writeToJSON(testdata);
|
||||
assert_int_equal (write_ret, 1);
|
||||
reqMsg->msg_type = 6;
|
||||
reqMsg->u.crud.transaction_uuid = strdup("1234");
|
||||
reqMsg->u.crud.dest = strdup("mac:14xxx/parodus/cloud-status");
|
||||
respMsg->msg_type = 6;
|
||||
ret = retrieveObject(reqMsg, &respMsg);
|
||||
assert_int_equal (respMsg->u.crud.status, 400);
|
||||
assert_int_equal (ret, -1);
|
||||
assert_int_equal (respMsg->u.crud.payload_size, 0);
|
||||
|
||||
fp = fopen(cfg.crud_config_file, "r");
|
||||
if (fp != NULL)
|
||||
{
|
||||
system("rm parodus_cfg.json");
|
||||
fclose(fp);
|
||||
}
|
||||
if(cfg.crud_config_file !=NULL)
|
||||
free(cfg.crud_config_file);
|
||||
wrp_free_struct(reqMsg);
|
||||
wrp_free_struct(respMsg);
|
||||
}
|
||||
|
||||
void test_retrieveObject_readOnlyFailure()
|
||||
{
|
||||
int ret = 0;
|
||||
@@ -2244,6 +2382,192 @@ void err_updateObject_InvalidType()
|
||||
wrp_free_struct(respMsg);
|
||||
}
|
||||
|
||||
void err_updateObject_cloud_disconnectInvalid()
|
||||
{
|
||||
int ret = 0;
|
||||
wrp_msg_t *reqMsg = NULL;
|
||||
reqMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(reqMsg, 0, sizeof(wrp_msg_t));
|
||||
wrp_msg_t *respMsg = NULL;
|
||||
respMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(respMsg, 0, sizeof(wrp_msg_t));
|
||||
reqMsg->msg_type = 7;
|
||||
reqMsg->u.crud.transaction_uuid = strdup("1234");
|
||||
reqMsg->u.crud.source = strdup("dns:tr1d1um.webpa.comcast.net/config");
|
||||
reqMsg->u.crud.dest = strdup("mac:14cfe2142145/parodus/cloud-disconnect");
|
||||
reqMsg->u.crud.payload = strdup("{ \"disconnection-reason\": \"***\" }");
|
||||
respMsg->msg_type = 7;
|
||||
ret = updateObject(reqMsg, &respMsg);
|
||||
|
||||
assert_int_equal (respMsg->u.crud.status, 400);
|
||||
assert_int_equal (ret, -1);
|
||||
wrp_free_struct(reqMsg);
|
||||
wrp_free_struct(respMsg);
|
||||
}
|
||||
|
||||
void err_updateObject_cloud_disconnectNULL()
|
||||
{
|
||||
int ret = 0;
|
||||
wrp_msg_t *reqMsg = NULL;
|
||||
reqMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(reqMsg, 0, sizeof(wrp_msg_t));
|
||||
wrp_msg_t *respMsg = NULL;
|
||||
respMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(respMsg, 0, sizeof(wrp_msg_t));
|
||||
reqMsg->msg_type = 7;
|
||||
reqMsg->u.crud.transaction_uuid = strdup("1234");
|
||||
reqMsg->u.crud.source = strdup("dns:tr1d1um.webpa.comcast.net/config");
|
||||
reqMsg->u.crud.dest = strdup("mac:14cfe2142145/parodus/cloud-disconnect");
|
||||
reqMsg->u.crud.payload = strdup("{ \"disconnection-reason\": \"\" }");
|
||||
respMsg->msg_type = 7;
|
||||
ret = updateObject(reqMsg, &respMsg);
|
||||
|
||||
assert_int_equal (respMsg->u.crud.status, 400);
|
||||
assert_int_equal (ret, -1);
|
||||
wrp_free_struct(reqMsg);
|
||||
wrp_free_struct(respMsg);
|
||||
}
|
||||
|
||||
void err_updateObject_no_cloud_disconnectReason()
|
||||
{
|
||||
int ret = 0;
|
||||
wrp_msg_t *reqMsg = NULL;
|
||||
reqMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(reqMsg, 0, sizeof(wrp_msg_t));
|
||||
wrp_msg_t *respMsg = NULL;
|
||||
respMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(respMsg, 0, sizeof(wrp_msg_t));
|
||||
reqMsg->msg_type = 7;
|
||||
reqMsg->u.crud.transaction_uuid = strdup("1234");
|
||||
reqMsg->u.crud.source = strdup("dns:tr1d1um.webpa.comcast.net/config");
|
||||
reqMsg->u.crud.dest = strdup("mac:14cfe2142145/parodus/cloud-disconnect");
|
||||
reqMsg->u.crud.payload = strdup("{ \"discon-val\": \"XPC\" }");
|
||||
respMsg->msg_type = 7;
|
||||
ret = updateObject(reqMsg, &respMsg);
|
||||
|
||||
assert_int_equal (respMsg->u.crud.status, 400);
|
||||
assert_int_equal (ret, -1);
|
||||
wrp_free_struct(reqMsg);
|
||||
wrp_free_struct(respMsg);
|
||||
}
|
||||
|
||||
void err_updateObject_cloud_disconnectNoPayload()
|
||||
{
|
||||
int ret = 0;
|
||||
wrp_msg_t *reqMsg = NULL;
|
||||
reqMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(reqMsg, 0, sizeof(wrp_msg_t));
|
||||
wrp_msg_t *respMsg = NULL;
|
||||
respMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(respMsg, 0, sizeof(wrp_msg_t));
|
||||
reqMsg->msg_type = 7;
|
||||
reqMsg->u.crud.transaction_uuid = strdup("1234");
|
||||
reqMsg->u.crud.source = strdup("dns:tr1d1um.webpa.comcast.net/config");
|
||||
reqMsg->u.crud.dest = strdup("mac:14cfe2142145/parodus/cloud-disconnect");
|
||||
respMsg->msg_type = 7;
|
||||
ret = updateObject(reqMsg, &respMsg);
|
||||
|
||||
assert_int_equal (respMsg->u.crud.status, 400);
|
||||
assert_int_equal (ret, -1);
|
||||
wrp_free_struct(reqMsg);
|
||||
wrp_free_struct(respMsg);
|
||||
|
||||
}
|
||||
|
||||
void err_updateObject_cloud_disconnectInvalidPayload()
|
||||
{
|
||||
int ret = 0;
|
||||
wrp_msg_t *reqMsg = NULL;
|
||||
reqMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(reqMsg, 0, sizeof(wrp_msg_t));
|
||||
wrp_msg_t *respMsg = NULL;
|
||||
respMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(respMsg, 0, sizeof(wrp_msg_t));
|
||||
reqMsg->msg_type = 7;
|
||||
reqMsg->u.crud.transaction_uuid = strdup("1234");
|
||||
reqMsg->u.crud.source = strdup("dns:tr1d1um.webpa.comcast.net/config");
|
||||
reqMsg->u.crud.dest = strdup("mac:14cfe2142145/parodus/cloud-disconnect");
|
||||
reqMsg->u.crud.payload = strdup("{ \"disconnection-reason\"\"XPC\" }");
|
||||
respMsg->msg_type = 7;
|
||||
ret = updateObject(reqMsg, &respMsg);
|
||||
|
||||
assert_int_equal (respMsg->u.crud.status, 400);
|
||||
assert_int_equal (ret, -1);
|
||||
wrp_free_struct(reqMsg);
|
||||
wrp_free_struct(respMsg);
|
||||
}
|
||||
|
||||
void err_updateObject_cloud_disconnectInvalidType()
|
||||
{
|
||||
int ret = 0;
|
||||
wrp_msg_t *reqMsg = NULL;
|
||||
reqMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(reqMsg, 0, sizeof(wrp_msg_t));
|
||||
wrp_msg_t *respMsg = NULL;
|
||||
respMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(respMsg, 0, sizeof(wrp_msg_t));
|
||||
reqMsg->msg_type = 7;
|
||||
reqMsg->u.crud.transaction_uuid = strdup("1234");
|
||||
reqMsg->u.crud.source = strdup("dns:tr1d1um.webpa.comcast.net/config");
|
||||
reqMsg->u.crud.dest = strdup("mac:14cfe2142145/parodus/cloud-disconnect");
|
||||
reqMsg->u.crud.payload = strdup("{ \"disconnection-reason\":123 }");
|
||||
respMsg->msg_type = 7;
|
||||
ret = updateObject(reqMsg, &respMsg);
|
||||
|
||||
assert_int_equal (respMsg->u.crud.status, 400);
|
||||
assert_int_equal (ret, -1);
|
||||
wrp_free_struct(reqMsg);
|
||||
wrp_free_struct(respMsg);
|
||||
}
|
||||
|
||||
void err_updateObject_cloud_disconnectFailure()
|
||||
{
|
||||
int ret = 0;
|
||||
wrp_msg_t *reqMsg = NULL;
|
||||
set_close_retry();
|
||||
reqMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(reqMsg, 0, sizeof(wrp_msg_t));
|
||||
wrp_msg_t *respMsg = NULL;
|
||||
respMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(respMsg, 0, sizeof(wrp_msg_t));
|
||||
reqMsg->msg_type = 7;
|
||||
reqMsg->u.crud.transaction_uuid = strdup("1234");
|
||||
reqMsg->u.crud.source = strdup("dns:tr1d1um.webpa.comcast.net/config");
|
||||
reqMsg->u.crud.dest = strdup("mac:14cfe2142145/parodus/cloud-disconnect");
|
||||
reqMsg->u.crud.payload = strdup("{ \"disconnection-reason\":\"XPC09\" }");
|
||||
respMsg->msg_type = 7;
|
||||
ret = updateObject(reqMsg, &respMsg);
|
||||
|
||||
assert_int_equal (respMsg->u.crud.status, 500);
|
||||
assert_int_equal (ret, -1);
|
||||
wrp_free_struct(reqMsg);
|
||||
wrp_free_struct(respMsg);
|
||||
reset_close_retry();
|
||||
}
|
||||
|
||||
void test_updateObject_cloud_disconnect()
|
||||
{
|
||||
int ret = 0;
|
||||
wrp_msg_t *reqMsg = NULL;
|
||||
reqMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(reqMsg, 0, sizeof(wrp_msg_t));
|
||||
wrp_msg_t *respMsg = NULL;
|
||||
respMsg = ( wrp_msg_t *)malloc( sizeof( wrp_msg_t ) );
|
||||
memset(respMsg, 0, sizeof(wrp_msg_t));
|
||||
reqMsg->msg_type = 7;
|
||||
reqMsg->u.crud.transaction_uuid = strdup("1234");
|
||||
reqMsg->u.crud.source = strdup("dns:tr1d1um.webpa.comcast.net/config");
|
||||
reqMsg->u.crud.dest = strdup("mac:14cfe2142145/parodus/cloud-disconnect");
|
||||
reqMsg->u.crud.payload = strdup("{ \"disconnection-reason\":\"XPC\" }");
|
||||
respMsg->msg_type = 7;
|
||||
ret = updateObject(reqMsg, &respMsg);
|
||||
|
||||
assert_int_equal (respMsg->u.crud.status, 200);
|
||||
assert_int_equal (ret, 0);
|
||||
wrp_free_struct(reqMsg);
|
||||
wrp_free_struct(respMsg);
|
||||
}
|
||||
|
||||
void test_deleteObject_JsonEmpty()
|
||||
{
|
||||
int ret = 0;
|
||||
@@ -2657,6 +2981,10 @@ int main(void)
|
||||
cmocka_unit_test(test_retrieveObject_readOnlyObj),
|
||||
cmocka_unit_test(test_retrieveObject_readOnlyFailure),
|
||||
|
||||
cmocka_unit_test(test_retrieveObject_cloud_status),
|
||||
cmocka_unit_test(err_retrieveObject_cloud_statusNULL),
|
||||
cmocka_unit_test(err_retrieveObject_cloud_statusEmpty),
|
||||
|
||||
cmocka_unit_test(test_updateObject_JsonEmpty),
|
||||
cmocka_unit_test(test_updateObject_destNull),
|
||||
cmocka_unit_test(test_updateObjectWithNoConfigJson),
|
||||
@@ -2675,6 +3003,15 @@ int main(void)
|
||||
cmocka_unit_test(err_updateObject_NonExisting_InvalidType),
|
||||
cmocka_unit_test(err_updateObject_existingObj_InvalidType),
|
||||
|
||||
cmocka_unit_test(test_updateObject_cloud_disconnect),
|
||||
cmocka_unit_test(err_updateObject_cloud_disconnectNULL),
|
||||
cmocka_unit_test(err_updateObject_cloud_disconnectInvalid),
|
||||
cmocka_unit_test(err_updateObject_cloud_disconnectFailure),
|
||||
cmocka_unit_test(err_updateObject_no_cloud_disconnectReason),
|
||||
cmocka_unit_test(err_updateObject_cloud_disconnectNoPayload),
|
||||
cmocka_unit_test(err_updateObject_cloud_disconnectInvalidType),
|
||||
cmocka_unit_test(err_updateObject_cloud_disconnectInvalidPayload),
|
||||
|
||||
cmocka_unit_test(test_deleteObject_JsonEmpty),
|
||||
cmocka_unit_test(test_deleteObject_destNull),
|
||||
cmocka_unit_test(test_deleteObjectWithNoConfigJson),
|
||||
@@ -2684,7 +3021,6 @@ int main(void)
|
||||
cmocka_unit_test(test_deleteObject_NonExistObj),
|
||||
cmocka_unit_test(test_deleteObject_withTagsEmpty),
|
||||
cmocka_unit_test(test_deleteObject_tagsFailure)
|
||||
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
|
||||
@@ -61,6 +61,10 @@ reg_list_item_t * get_global_node(void)
|
||||
return mock_ptr_type(reg_list_item_t *);
|
||||
}
|
||||
|
||||
void release_global_node (void)
|
||||
{
|
||||
}
|
||||
|
||||
ssize_t wrp_to_struct( const void *bytes, const size_t length,
|
||||
const enum wrp_format fmt, wrp_msg_t **msg )
|
||||
{
|
||||
@@ -68,7 +72,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 +83,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();
|
||||
}
|
||||
|
||||
@@ -244,6 +244,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 ) {
|
||||
|
||||
94
tests/test_heartBeatTimer.c
Normal file
94
tests/test_heartBeatTimer.c
Normal file
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* Copyright 2018 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 <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "../src/heartBeat.h"
|
||||
#include "../src/parodus_log.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void test_heartBeatTimer() {
|
||||
/* get heartBeat timer's initial value */
|
||||
unsigned int heartBeatTimer =5;
|
||||
heartBeatTimer = get_heartBeatTimer();
|
||||
ParodusInfo("heartBeatTimer initial vaule is: %d\n", heartBeatTimer);
|
||||
assert_int_equal(heartBeatTimer, 0);
|
||||
|
||||
/* increment heartbeat timer value and check whether its returning modified value or not*/
|
||||
unsigned int inc_time_ms =5;
|
||||
increment_heartBeatTimer(inc_time_ms);
|
||||
heartBeatTimer = get_heartBeatTimer();
|
||||
ParodusInfo("heartBeatTimer incremented to: %d\n", heartBeatTimer);
|
||||
assert_int_equal(heartBeatTimer,5);
|
||||
|
||||
/* reset heartBeat timer to 0 */
|
||||
reset_heartBeatTimer();
|
||||
heartBeatTimer = get_heartBeatTimer();
|
||||
ParodusInfo("heartBeatTimer reset to: %d\n", heartBeatTimer);
|
||||
assert_int_equal(heartBeatTimer,0);
|
||||
}
|
||||
|
||||
void *test_mutexIncrementTimer() {
|
||||
unsigned int inc_time_ms =5;
|
||||
increment_heartBeatTimer(inc_time_ms);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *test_mutexResetTimer() {
|
||||
reset_heartBeatTimer();
|
||||
return NULL;
|
||||
}
|
||||
void test_mutexHeartBeatTimer() {
|
||||
unsigned int heartBeatTimer;
|
||||
pthread_t thread[3];
|
||||
|
||||
pthread_create(&thread[0], NULL, test_mutexIncrementTimer, NULL);
|
||||
pthread_create(&thread[1], NULL, test_mutexIncrementTimer, NULL);
|
||||
|
||||
pthread_join(thread[0], NULL);
|
||||
pthread_join(thread[1], NULL);
|
||||
|
||||
/* After execution of both the threads check the value of timer */
|
||||
heartBeatTimer = get_heartBeatTimer();
|
||||
ParodusInfo("Threads execution is completed, heartBeatTimer is: %d\n", heartBeatTimer);
|
||||
assert_int_equal(heartBeatTimer, 10);
|
||||
|
||||
pthread_create(&thread[2], NULL, test_mutexResetTimer, NULL);
|
||||
pthread_join(thread[2], NULL);
|
||||
|
||||
heartBeatTimer = get_heartBeatTimer();
|
||||
ParodusInfo("heartBeatTimer reset to: %d\n", heartBeatTimer);
|
||||
assert_int_equal(heartBeatTimer, 0);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int main(void)
|
||||
{
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(test_heartBeatTimer),
|
||||
cmocka_unit_test(test_mutexHeartBeatTimer),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <nopoll_private.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "../src/ParodusInternal.h"
|
||||
#include "../src/nopoll_handlers.h"
|
||||
#include "../src/parodus_log.h"
|
||||
|
||||
@@ -29,8 +30,11 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
volatile unsigned int heartBeatTimer;
|
||||
bool LastReasonStatus;
|
||||
bool interface_down_event = false;
|
||||
int closeReason = 0;
|
||||
pthread_mutex_t close_mut;
|
||||
pthread_mutex_t close_mut;
|
||||
pthread_mutex_t interface_down_mut=PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t interface_down_con=PTHREAD_COND_INITIALIZER;
|
||||
bool close_retry;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
@@ -46,6 +50,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 +201,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 +232,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 );
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
@@ -48,6 +48,11 @@ bool get_global_reconnect_status()
|
||||
return LastReasonStatus;
|
||||
}
|
||||
|
||||
bool get_interface_down_event()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void set_global_reconnect_status(bool status)
|
||||
{
|
||||
(void) status ;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
#include <nopoll.h>
|
||||
@@ -116,6 +117,11 @@ int kill(pid_t pid, int sig)
|
||||
return (int) mock();
|
||||
}
|
||||
|
||||
bool get_interface_down_event()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
@@ -43,7 +43,26 @@ ParodusCfg *get_parodus_cfg(void)
|
||||
|
||||
void test_validate_partner_id_for_req()
|
||||
{
|
||||
static partners_t partner_ids = {1,{"comcast"}};
|
||||
static partners_t partner_ids = {3,{"shaw","","comcast"}};
|
||||
wrp_msg_t *msg = (wrp_msg_t*) malloc(sizeof(wrp_msg_t));
|
||||
memset(msg, 0, sizeof(wrp_msg_t));
|
||||
msg->msg_type = WRP_MSG_TYPE__REQ;
|
||||
msg->u.req.partner_ids = &partner_ids;
|
||||
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg, 0, sizeof(ParodusCfg));
|
||||
parStrncpy(cfg.partner_id, "shaw,bar,comcast", sizeof(cfg.partner_id));
|
||||
|
||||
will_return(get_parodus_cfg, (intptr_t)&cfg);
|
||||
expect_function_call(get_parodus_cfg);
|
||||
int ret = validate_partner_id(msg, NULL);
|
||||
assert_int_equal(ret, 1);
|
||||
free(msg);
|
||||
}
|
||||
|
||||
void test_validate_partner_id_for_req_case_insensitive()
|
||||
{
|
||||
static partners_t partner_ids = {2,{"Shaw","Comcast"}};
|
||||
wrp_msg_t *msg = (wrp_msg_t*) malloc(sizeof(wrp_msg_t));
|
||||
memset(msg, 0, sizeof(wrp_msg_t));
|
||||
msg->msg_type = WRP_MSG_TYPE__REQ;
|
||||
@@ -68,7 +87,7 @@ void test_validate_partner_id_for_req_listNULL()
|
||||
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg, 0, sizeof(ParodusCfg));
|
||||
parStrncpy(cfg.partner_id, "comcast", sizeof(cfg.partner_id));
|
||||
parStrncpy(cfg.partner_id, "*,comcast", sizeof(cfg.partner_id));
|
||||
|
||||
will_return(get_parodus_cfg, (intptr_t)&cfg);
|
||||
expect_function_call(get_parodus_cfg);
|
||||
@@ -103,7 +122,7 @@ void err_validate_partner_id_for_req()
|
||||
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg, 0, sizeof(ParodusCfg));
|
||||
parStrncpy(cfg.partner_id, "comcast", sizeof(cfg.partner_id));
|
||||
parStrncpy(cfg.partner_id, "*,,comcast", sizeof(cfg.partner_id));
|
||||
|
||||
will_return(get_parodus_cfg, (intptr_t)&cfg);
|
||||
expect_function_call(get_parodus_cfg);
|
||||
@@ -114,7 +133,7 @@ void err_validate_partner_id_for_req()
|
||||
|
||||
void test_validate_partner_id_for_event()
|
||||
{
|
||||
static partners_t partner_ids = {1,{"comcast"}};
|
||||
static partners_t partner_ids = {4,{"shaw","","*","comcast"}};
|
||||
wrp_msg_t *msg = (wrp_msg_t*) malloc(sizeof(wrp_msg_t));
|
||||
memset(msg, 0, sizeof(wrp_msg_t));
|
||||
msg->msg_type = WRP_MSG_TYPE__EVENT;
|
||||
@@ -122,7 +141,29 @@ void test_validate_partner_id_for_event()
|
||||
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg, 0, sizeof(ParodusCfg));
|
||||
parStrncpy(cfg.partner_id, "comcast", sizeof(cfg.partner_id));
|
||||
parStrncpy(cfg.partner_id, "abc,*,comcast", sizeof(cfg.partner_id));
|
||||
|
||||
will_return(get_parodus_cfg, (intptr_t)&cfg);
|
||||
expect_function_call(get_parodus_cfg);
|
||||
|
||||
partners_t *list = NULL;
|
||||
int ret = validate_partner_id(msg, &list);
|
||||
assert_int_equal(ret, 1);
|
||||
free(list);
|
||||
free(msg);
|
||||
}
|
||||
|
||||
void test_validate_partner_id_for_event_case_insensitive()
|
||||
{
|
||||
static partners_t partner_ids = {1,{"Comcast"}};
|
||||
wrp_msg_t *msg = (wrp_msg_t*) malloc(sizeof(wrp_msg_t));
|
||||
memset(msg, 0, sizeof(wrp_msg_t));
|
||||
msg->msg_type = WRP_MSG_TYPE__EVENT;
|
||||
msg->u.event.partner_ids = &partner_ids;
|
||||
|
||||
ParodusCfg cfg;
|
||||
memset(&cfg, 0, sizeof(ParodusCfg));
|
||||
parStrncpy(cfg.partner_id, "*,comcast", sizeof(cfg.partner_id));
|
||||
|
||||
will_return(get_parodus_cfg, (intptr_t)&cfg);
|
||||
expect_function_call(get_parodus_cfg);
|
||||
@@ -218,10 +259,12 @@ int main(void)
|
||||
{
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(test_validate_partner_id_for_req),
|
||||
cmocka_unit_test(test_validate_partner_id_for_req_case_insensitive),
|
||||
cmocka_unit_test(test_validate_partner_id_for_req_listNULL),
|
||||
cmocka_unit_test(test_validate_partner_id_for_req_withoutId),
|
||||
cmocka_unit_test(err_validate_partner_id_for_req),
|
||||
cmocka_unit_test(test_validate_partner_id_for_event),
|
||||
cmocka_unit_test(test_validate_partner_id_for_event_case_insensitive),
|
||||
cmocka_unit_test(test_validate_partner_id_for_event_listNULL),
|
||||
cmocka_unit_test(test_validate_partner_id_for_event_withoutId),
|
||||
cmocka_unit_test(err_validate_partner_id_for_event),
|
||||
|
||||
@@ -33,6 +33,18 @@ static void *keep_alive_thread();
|
||||
static void add_client();
|
||||
int sock1;
|
||||
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 +60,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 +85,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 +148,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;
|
||||
|
||||
@@ -144,8 +144,7 @@ cjwt_t jwt3; // insecure
|
||||
cjwt_t jwt4; // missing endpoint
|
||||
|
||||
// internal functions in token.c to be tested
|
||||
extern int analyze_jwt (const cjwt_t *jwt, char *url_buf, int url_buflen,
|
||||
char *port_buf, int port_buflen);
|
||||
extern int analyze_jwt (const cjwt_t *jwt, char **url_buf, unsigned int *port);
|
||||
extern bool validate_algo(const cjwt_t *jwt);
|
||||
extern int nquery(const char* dns_txt_record_id,u_char *nsbuf);
|
||||
extern bool valid_b64_char (char c);
|
||||
@@ -159,6 +158,19 @@ 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;
|
||||
|
||||
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;
|
||||
@@ -323,23 +335,23 @@ void __res_nclose (res_state statp)
|
||||
// Analyzes a jwt structure
|
||||
void test_analyze_jwt ()
|
||||
{
|
||||
char port[8];
|
||||
char server_Address[256];
|
||||
unsigned int port;
|
||||
char *server_Address;
|
||||
int ret = setup_test_jwts ();
|
||||
assert_int_equal (ret, 0);
|
||||
ret = analyze_jwt (&jwt1, server_Address, (int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
ret = analyze_jwt (&jwt1, &server_Address, &port);
|
||||
assert_int_equal (ret, 0);
|
||||
assert_string_equal (server_Address, "mydns.mycom.net");
|
||||
assert_string_equal (port, "8080");
|
||||
ret = analyze_jwt (&jwt2, server_Address, (int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
assert_int_equal (port, 8080);
|
||||
free (server_Address);
|
||||
ret = analyze_jwt (&jwt2, &server_Address, &port);
|
||||
assert_int_equal (ret, TOKEN_ERR_JWT_EXPIRED);
|
||||
ret = analyze_jwt (&jwt3, server_Address, (int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
ret = analyze_jwt (&jwt3, &server_Address, &port);
|
||||
assert_int_equal (ret, 1);
|
||||
ret = analyze_jwt (&jwt4, server_Address, (int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
assert_string_equal (server_Address, "mydns.mycom.net");
|
||||
assert_int_equal (port, 8080);
|
||||
free (server_Address);
|
||||
ret = analyze_jwt (&jwt4, &server_Address, &port);
|
||||
assert_int_equal (ret, TOKEN_ERR_INVALID_JWT_CONTENT);
|
||||
}
|
||||
|
||||
@@ -614,7 +626,8 @@ void test_query_dns ()
|
||||
void test_allow_insecure_conn ()
|
||||
{
|
||||
int insecure;
|
||||
char port_buf[6] = "8080";
|
||||
char *server_addr;
|
||||
unsigned int port;
|
||||
ParodusCfg *cfg = get_parodus_cfg();
|
||||
|
||||
parStrncpy (cfg->hw_mac, "aabbccddeeff", sizeof(cfg->hw_mac));
|
||||
@@ -627,10 +640,11 @@ void test_allow_insecure_conn ()
|
||||
expect_function_call (__res_ninit);
|
||||
expect_function_call (__res_nclose);
|
||||
|
||||
insecure = allow_insecure_conn (cfg->dns_txt_url, sizeof(cfg->dns_txt_url),
|
||||
port_buf, sizeof(port_buf));
|
||||
insecure = allow_insecure_conn (&server_addr, &port);
|
||||
free (server_addr);
|
||||
assert_int_equal (insecure, 0);
|
||||
|
||||
|
||||
parStrncpy (cfg->hw_mac, "aabbccddeeff", sizeof(cfg->hw_mac));
|
||||
parStrncpy (cfg->dns_txt_url, "err5.mydns.mycom.net", sizeof(cfg->dns_txt_url));
|
||||
|
||||
@@ -638,8 +652,7 @@ void test_allow_insecure_conn ()
|
||||
expect_function_call (__res_ninit);
|
||||
expect_function_call (__res_nclose);
|
||||
|
||||
insecure = allow_insecure_conn (cfg->dns_txt_url, sizeof(cfg->dns_txt_url),
|
||||
port_buf, sizeof(port_buf));
|
||||
insecure = allow_insecure_conn (&server_addr, &port);
|
||||
assert_int_equal (insecure, TOKEN_ERR_QUERY_DNS_FAIL);
|
||||
|
||||
parStrncpy (cfg->hw_mac, "aabbccddeeff", sizeof(cfg->hw_mac));
|
||||
@@ -651,8 +664,7 @@ void test_allow_insecure_conn ()
|
||||
expect_function_call (__res_ninit);
|
||||
expect_function_call (__res_nclose);
|
||||
|
||||
insecure = allow_insecure_conn (cfg->dns_txt_url, sizeof(cfg->dns_txt_url),
|
||||
port_buf, sizeof(port_buf));
|
||||
insecure = allow_insecure_conn (&server_addr, &port);
|
||||
assert_int_equal (insecure, TOKEN_ERR_JWT_DECODE_FAIL);
|
||||
|
||||
parStrncpy (cfg->hw_mac, "aabbccddeeff", sizeof(cfg->hw_mac));
|
||||
@@ -664,8 +676,7 @@ void test_allow_insecure_conn ()
|
||||
expect_function_call (__res_ninit);
|
||||
expect_function_call (__res_nclose);
|
||||
|
||||
insecure = allow_insecure_conn (cfg->dns_txt_url, sizeof(cfg->dns_txt_url),
|
||||
port_buf, sizeof(port_buf));
|
||||
insecure = allow_insecure_conn (&server_addr, &port);
|
||||
assert_int_equal (insecure, TOKEN_ERR_ALGO_NOT_ALLOWED);
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <cmocka.h>
|
||||
#include <assert.h>
|
||||
#include <wrp-c.h>
|
||||
|
||||
#include <pthread.h>
|
||||
#include "../src/token.h"
|
||||
|
||||
|
||||
@@ -31,6 +31,20 @@
|
||||
/* 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;
|
||||
@@ -46,10 +60,9 @@ void test_allow_insecure_conn ()
|
||||
{
|
||||
int insecure;
|
||||
char *server_Address = NULL;
|
||||
char *port = NULL;
|
||||
insecure = allow_insecure_conn (server_Address,(int) sizeof(server_Address),
|
||||
port, (int) sizeof(port));
|
||||
assert_int_equal (insecure, -1);
|
||||
unsigned int port;
|
||||
insecure = allow_insecure_conn (&server_Address, &port);
|
||||
assert_int_equal (insecure, TOKEN_NO_DNS_QUERY);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
@@ -31,16 +31,19 @@
|
||||
#include "../src/client_list.h"
|
||||
#include "../src/ParodusInternal.h"
|
||||
#include "../src/partners_check.h"
|
||||
#include "../src/close_retry.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* File Scoped Variables */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
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;
|
||||
wrp_msg_t *temp = NULL;
|
||||
extern pthread_mutex_t nano_mut;
|
||||
extern pthread_cond_t nano_con;
|
||||
@@ -65,19 +68,51 @@ 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();
|
||||
return (int)mock();
|
||||
}
|
||||
|
||||
void addCRUDmsgToQueue(wrp_msg_t *crudMsg)
|
||||
{
|
||||
(void)crudMsg;
|
||||
function_called();
|
||||
return;
|
||||
}
|
||||
|
||||
int sendMsgtoRegisteredClients(char *dest,const char **Msg,size_t msgSize)
|
||||
{
|
||||
UNUSED(dest); UNUSED(Msg); UNUSED(msgSize);
|
||||
function_called();
|
||||
return (int)mock();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -180,6 +215,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);
|
||||
@@ -225,10 +267,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();
|
||||
}
|
||||
|
||||
@@ -244,10 +292,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);
|
||||
@@ -257,6 +311,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();
|
||||
@@ -305,6 +361,39 @@ void test_processUpstreamMessage()
|
||||
free(UpStreamMsgQ);
|
||||
}
|
||||
|
||||
void test_processUpstreamReqMessage()
|
||||
{
|
||||
numLoops = 1;
|
||||
metaPackSize = 20;
|
||||
UpStreamMsgQ = (UpStreamMsg *) malloc(sizeof(UpStreamMsg));
|
||||
UpStreamMsgQ->msg = "First Message";
|
||||
UpStreamMsgQ->len = 13;
|
||||
UpStreamMsgQ->next = (UpStreamMsg *) malloc(sizeof(UpStreamMsg));
|
||||
UpStreamMsgQ->next->msg = "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 = 3;
|
||||
|
||||
will_return(wrp_to_struct, 12);
|
||||
expect_function_call(wrp_to_struct);
|
||||
|
||||
will_return(appendEncodedData, 100);
|
||||
expect_function_call(appendEncodedData);
|
||||
|
||||
expect_function_call(sendMessage);
|
||||
will_return(nn_freemsg, 0);
|
||||
expect_function_call(nn_freemsg);
|
||||
expect_function_call(wrp_free_struct);
|
||||
|
||||
processUpstreamMessage();
|
||||
free(temp);
|
||||
free(UpStreamMsgQ->next);
|
||||
free(UpStreamMsgQ);
|
||||
}
|
||||
|
||||
void test_processUpstreamMessageInvalidPartner()
|
||||
{
|
||||
numLoops = 1;
|
||||
@@ -365,15 +454,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);
|
||||
|
||||
@@ -424,6 +516,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);
|
||||
|
||||
@@ -521,21 +616,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);
|
||||
|
||||
@@ -576,6 +677,21 @@ void test_sendUpstreamMsgToServer()
|
||||
free(bytes);
|
||||
}
|
||||
|
||||
void test_sendUpstreamMsg_close_retry()
|
||||
{
|
||||
set_close_retry();
|
||||
void *bytes = NULL;
|
||||
wrp_msg_t msg;
|
||||
memset(&msg, 0, sizeof(wrp_msg_t));
|
||||
msg.msg_type = WRP_MSG_TYPE__EVENT;
|
||||
wrp_struct_to( &msg, WRP_BYTES, &bytes );
|
||||
metaPackSize = 10;
|
||||
will_return(appendEncodedData, 100);
|
||||
expect_function_call(appendEncodedData);
|
||||
sendUpstreamMsgToServer(&bytes, 110);
|
||||
free(bytes);
|
||||
}
|
||||
|
||||
void err_sendUpstreamMsgToServer()
|
||||
{
|
||||
metaPackSize = 0;
|
||||
@@ -628,10 +744,132 @@ void test_processUpstreamMsgCrud_nnfree()
|
||||
expect_function_call(wrp_free_struct);
|
||||
processUpstreamMessage();
|
||||
free(UpStreamMsgQ);
|
||||
crud_test = 0;
|
||||
}
|
||||
|
||||
void test_processUpstreamMsg_cloud_status()
|
||||
{
|
||||
numLoops = 1;
|
||||
metaPackSize = 20;
|
||||
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);
|
||||
|
||||
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 test_processUpstreamMsg_sendToClient()
|
||||
{
|
||||
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;
|
||||
|
||||
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/config");
|
||||
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);
|
||||
|
||||
will_return(sendMsgtoRegisteredClients, 1);
|
||||
expect_function_call(sendMsgtoRegisteredClients);
|
||||
|
||||
expect_function_call(wrp_free_struct);
|
||||
will_return(wrp_to_struct, 12);
|
||||
expect_function_call(wrp_to_struct);
|
||||
will_return(sendMsgtoRegisteredClients, 0);
|
||||
expect_function_call(sendMsgtoRegisteredClients);
|
||||
|
||||
expect_function_call(wrp_free_struct);
|
||||
processUpstreamMessage();
|
||||
free(temp);
|
||||
free(UpStreamMsgQ);
|
||||
UpStreamMsgQ = NULL;
|
||||
}
|
||||
|
||||
void test_processUpstreamMsg_serviceNameNULL()
|
||||
{
|
||||
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 */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -646,6 +884,7 @@ int main(void)
|
||||
cmocka_unit_test(err_handleUpstreamBindFailure),
|
||||
cmocka_unit_test(err_handleUpstreamSockFailure),
|
||||
cmocka_unit_test(test_processUpstreamMessage),
|
||||
cmocka_unit_test(test_processUpstreamReqMessage),
|
||||
cmocka_unit_test(test_processUpstreamMessageInvalidPartner),
|
||||
cmocka_unit_test(test_processUpstreamMessageRegMsg),
|
||||
cmocka_unit_test(test_processUpstreamMessageRegMsgNoClients),
|
||||
@@ -654,12 +893,17 @@ int main(void)
|
||||
cmocka_unit_test(err_processUpstreamMessageMetapackFailure),
|
||||
cmocka_unit_test(err_processUpstreamMessageRegMsg),
|
||||
cmocka_unit_test(test_sendUpstreamMsgToServer),
|
||||
cmocka_unit_test(test_sendUpstreamMsg_close_retry),
|
||||
cmocka_unit_test(err_sendUpstreamMsgToServer),
|
||||
cmocka_unit_test(test_get_global_UpStreamMsgQ),
|
||||
cmocka_unit_test(test_set_global_UpStreamMsgQ),
|
||||
cmocka_unit_test(test_get_global_nano_con),
|
||||
cmocka_unit_test(test_get_global_nano_mut),
|
||||
cmocka_unit_test(test_processUpstreamMsgCrud_nnfree),
|
||||
cmocka_unit_test(test_processUpstreamMsg_cloud_status),
|
||||
cmocka_unit_test(test_processUpstreamMsg_sendToClient),
|
||||
cmocka_unit_test(test_processUpstreamMsg_serviceNameNULL),
|
||||
cmocka_unit_test(err_processUpstreamMsg_deviceID)
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
|
||||
249
tests/test_upstream_sock.c
Normal file
249
tests/test_upstream_sock.c
Normal file
@@ -0,0 +1,249 @@
|
||||
/**
|
||||
* 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;
|
||||
wrp_msg_t *reg_msg = NULL;
|
||||
extern pthread_mutex_t nano_mut;
|
||||
extern pthread_cond_t nano_con;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/*-------------------------------------------
|
||||
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