diff --git a/archive/README.md b/archive/README.md new file mode 100644 index 0000000000..db347d96a9 --- /dev/null +++ b/archive/README.md @@ -0,0 +1 @@ +After 6 years without touching this directory, we are purging it for Orion 4.0.0 release. If you want to get its content check [the previous version GitHub tree](https://github.com/telefonicaid/fiware-orion/tree/3.12.0/archive). diff --git a/archive/proxyCoap/README.md b/archive/proxyCoap/README.md deleted file mode 100644 index d6e03b638d..0000000000 --- a/archive/proxyCoap/README.md +++ /dev/null @@ -1,59 +0,0 @@ -This directory holds proxyCoap, no longer mantained as part of the "mainstream" code in Orion (the one -under the src/ directory at repository root) but maybe useful in the future. - -## Building - -This directory cannot be built in "standalone mode" (as the archiving work described at issue #1202 is not -completed), so by the moment if you want to compile proxyCoap you have to move the -proxyCoap/src/app/proxyCoap directory to its original location at src/app in the repository root, then add -the following to root CMakeLists.txt file: - -``` -ADD_SUBDIRECTORY(src/app/proxyCoap) -``` - -just after the line: - -``` -ADD_SUBDIRECTORY(src/app/contextBroker) -``` - -In addition, you need to do the following before running `make` to compile: - -* Install cantcoap (with dependencies). Note that we are using a particular snapshot of the code (corresponding - to around July 21st, 2014) given that cantcoap repository doesn't provide any releasing mechanism. - - -``` -sudo yum install clang CUnit-devel - -git clone https://github.com/staropram/cantcoap -cd cantcoap -git checkout 749e22376664dd3adae17492090e58882d3b28a7 -make -sudo cp cantcoap.h /usr/local/include -sudo cp dbg.h /usr/local/include -sudo cp nethelper.h /usr/local/include -sudo cp libcantcoap.a /usr/local/lib -``` - - -## Testing - -The cases/ directory contains a set of test harness files used in the past to test the -proxyCoap functionality. You need to install COAP client (an example application included in the -libcoap sources) before to use them: - -``` -wget http://sourceforge.net/projects/libcoap/files/coap-18/libcoap-4.1.1.tar.gz/download -mv download libcoap-4.1.1.tar.gz -tar xvzf libcoap-4.1.1.tar.gz -cd libcoap-4.1.1 -./configure -make -sudo cp examples/coap-client /usr/local/bin -``` - -## Miscellanea - -This directory also includes parts of harnessFunction.sh and testEnv.sh files related with CoAP. diff --git a/archive/proxyCoap/cases/0283_coap_support/coap_basic.test b/archive/proxyCoap/cases/0283_coap_support/coap_basic.test deleted file mode 100644 index 4d17b3e6ec..0000000000 --- a/archive/proxyCoap/cases/0283_coap_support/coap_basic.test +++ /dev/null @@ -1,158 +0,0 @@ -# Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -Coap Basic interaction - ---SHELL-INIT-- -dbInit CB -brokerStart CB -valgrindSleep 2 -proxyCoapStart - ---SHELL-- - -valgrindSleep 5 -echo "+++++++ Create entity +++++++++" -payload='{ - "attributes": [ - { - "name": "temperature", - "type": "centigrade", - "value": "30" - } - ] -}' -coapCurl --url /v1/contextEntities/Room1 --payload "$payload" --json -X post - - -echo "+++++++ Query +++++++++" -valgrindSleep 2 -coapCurl --url /v1/contextEntities/Room1 --json - - -echo "+++++++ Update +++++++++" -payload='{ - "attributes": [ - { - "name": "temperature", - "type": "centigrade", - "value": "29" - } - ] -}' -coapCurl --url /v1/contextEntities/Room1 --payload "$payload" --json -X put - -echo "+++++++ Query +++++++++" -valgrindSleep 2 -coapCurl --url /v1/contextEntities/Room1 --json - ---REGEXPECT-- -+++++++ Create entity +++++++++ -v:1 t:0 tkl:0 c:2 id:REGEX(\d+) - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "temperature", - "type": "centigrade", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "id": "Room1", - "isPattern": "false", - "type": "" -} -+++++++ Query +++++++++ -v:1 t:0 tkl:0 c:1 id:REGEX(\d+) - -{ - "contextElement": { - "attributes": [ - { - "name": "temperature", - "type": "centigrade", - "value": "30" - } - ], - "id": "Room1", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} -+++++++ Update +++++++++ -v:1 t:0 tkl:0 c:3 id:REGEX(\d+) - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "temperature", - "type": "centigrade", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} -+++++++ Query +++++++++ -v:1 t:0 tkl:0 c:1 id:REGEX(\d+) - -{ - "contextElement": { - "attributes": [ - { - "name": "temperature", - "type": "centigrade", - "value": "29" - } - ], - "id": "Room1", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} ---TEARDOWN-- -proxyCoapStop -brokerStop CB -dbDrop CB diff --git a/archive/proxyCoap/cases/0283_coap_support/coap_command_line_options.test b/archive/proxyCoap/cases/0283_coap_support/coap_command_line_options.test deleted file mode 100644 index 9b850b0cc1..0000000000 --- a/archive/proxyCoap/cases/0283_coap_support/coap_command_line_options.test +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - ---NAME-- -proxyCoap command-line options - ---SHELL-INIT-- - ---SHELL-- -proxyCoap -u - ---REGEXPECT-- -Usage: proxyCoap [option '-U' (extended usage)] - [option '-u' (usage)] - [option '--version' (show version)] - [option '-logDir' ] - [option '-t' ] - [option '--silent' (silent mode)] - [option '-v' (verbose mode)] - [option '-vv' (verbose2 mode)] - [option '-vvv' (verbose3 mode)] - [option '-vvvv' (verbose4 mode)] - [option '-vvvvv' (verbose5 mode)] - [option '-logAppend' (append to log-file)] - - [option '-fg' (don't start as daemon)] - [option '-localIp' ] - [option '-port' ] - [option '-cbHost' ] - [option '-cbPort' ] - [option '-ipv4' (use ip v4 only)] - [option '-ipv6' (use ip v6 only)] - ---TEARDOWN-- diff --git a/archive/proxyCoap/cases/0283_coap_support/coap_version.test b/archive/proxyCoap/cases/0283_coap_support/coap_version.test deleted file mode 100644 index 35bb18c164..0000000000 --- a/archive/proxyCoap/cases/0283_coap_support/coap_version.test +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - ---NAME-- -proxyCoap version ---SHELL-INIT-- - ---SHELL-- -# We have found sometimes problems with using CLI options with two hyphens in the .test files, breaking the testHarness.sh script. -# However, in this case, it seems to work with the double-hyphened "--version" argument. - -contextBroker --version - ---REGEXPECT-- -REGEX(\d+\.\d+\.\d+.*) -Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -Orion Context Broker is free software: you can redistribute it and/or -modify it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -Orion Context Broker is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -General Public License for more details. - -Telefonica I+D ---TEARDOWN-- diff --git a/archive/proxyCoap/harnessFunctions_coap.sh b/archive/proxyCoap/harnessFunctions_coap.sh deleted file mode 100644 index 983c57bc91..0000000000 --- a/archive/proxyCoap/harnessFunctions_coap.sh +++ /dev/null @@ -1,251 +0,0 @@ -# Copyright 2016 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es -# -# -# In order to "recover" the following functions, they should be moved back -# to harnessFunctions.sh file (and enabled with export -f at the end of that file) - -# ------------------------------------------------------------------------------ -# -# proxyCoapStart -# -function proxyCoapStart() -{ - extraParams=$* - - proxyCoap $extraParams -cbPort $CB_PORT - - # Test to see whether we have a proxy running. If not raise an error - running_proxyCoap=$(ps -fe | grep ' proxyCoap' | grep "cbPort $CB_PORT" | wc -l) - if [ "$running_proxyCoap" == "" ] - then - echo "Unable to start proxyCoap" - exit 1 - fi -} - - - -# ------------------------------------------------------------------------------ -# -# proxyCoapStop -# -function proxyCoapStop -{ - port=$COAP_PORT - - # Test to see if we have a proxy running if so kill it! - running_proxyCoap=$(ps -fe | grep proxyCoap | wc -l) - if [ $running_proxyCoap -ne 1 ]; then - kill $(ps -fe | grep proxyCoap | awk '{print $2}') 2> /dev/null - # Wait some time so the proxy can finish properly - sleep 1 - running_proxyCoap=$(ps -fe | grep proxyCoap | wc -l) - if [ $running_proxyCoap -ne 1 ]; then - # If the proxy refuses to stop politely, kill the process by brute force - kill -9 $(ps -fe | grep proxyCoap | awk '{print $2}') 2> /dev/null - sleep 1 - running_proxyCoap=$(ps -fe | grep proxyCoap | wc -l) - if [ $running_proxyCoap -ne 1 ]; then - echo "Existing proxyCoap is immortal, can not be killed!" - exit 1 - fi - fi - fi -} - - -# ------------------------------------------------------------------------------ -# -# coapCurl -# -# Options: -# -X (default: according to curl. GET if no payload, POST if with payload) -# --host (default: localhost) -# --port (default: $COAP_PORT) -# --url (default: empty string) -# --payload (default: NO PAYLOAD. Possible values: [filename | "${string}"]) -# --in (input payload) (default: xml => application/xml, If 'json': application/json) -# --out (output payload (default: xml => application/xml, If 'json': application/json) -# --json (in/out JSON) (if --in/out is used AFTER --json, it overrides) -# --tenant (tenant in HTTP header) -# --servicePath (Service Path in HTTP header) -# --noPayloadCheck (skip paylosd check filter) -# -# Any parameters are sent as is to 'curl' -# -function coapCurl() -{ - # - # Default values - # - _method="" - _host="0.0.0.0" - _port=$COAP_PORT - _url="" - _payload="" - _inFormat="" - _outFormat="" - _json="" - _tenant="" - _servicePath="" - _xtra='' - _noPayloadCheck='off' - - while [ "$#" != 0 ] - do - if [ "$1" == "-X" ]; then _method="$2"; shift; - elif [ "$1" == "--host" ]; then _host="$2"; shift; - elif [ "$1" == "--port" ]; then _port="$2"; shift; - elif [ "$1" == "--url" ]; then _url="$2"; shift; - elif [ "$1" == "--payload" ]; then _payload="$2"; shift; - elif [ "$1" == "--in" ]; then _inFormat="$2"; shift; - elif [ "$1" == "--out" ]; then _outFormat="$2"; shift; - elif [ "$1" == "--json" ]; then _inFormat=application/json; _outFormat=application/json; - elif [ "$1" == "--tenant" ]; then _tenant="$2"; shift; - elif [ "$1" == "--servicePath" ]; then _servicePath="$2"; shift; - elif [ "$1" == "--noPayloadCheck" ]; then _noPayloadCheck=on; - else _xtra="$_xtra $1"; shift; - fi - - shift - done - - # - # Sanity check of parameters - # - if [ "$_url" == "" ] - then - echo "No URL"; - return 1; - fi - - - # - # Fix for 'Content-Type' and 'Accept' short names 'xml' and 'json' - # - if [ "$_inFormat" == "xml" ]; then _inFormat=application/xml; fi; - if [ "$_outFormat" == "xml" ]; then _outFormat=application/xml; fi; - if [ "$_inFormat" == "json" ]; then _inFormat=application/json; fi; - if [ "$_outFormat" == "json" ]; then _outFormat=application/json; fi; - - - - # - # Cleanup 'compound' variables, so that we don't inherit values from previous calls - # - _METHOD='' - _URL='' - _ACCEPT='' - _CONTENTFORMAT='' - - if [ "$_inFormat" != "" ]; then _CONTENTFORMAT="-t $_inFormat"; fi - if [ "$_outFormat" != "" ]; then _ACCEPT="-A $_outFormat"; fi - if [ "$_method" != "" ]; then _METHOD=' -m '$_method; fi - - _URL="coap://$_host:$_port$_url" - - # usage: coap-client [-A type...] [-t type] [-b [num,]size] [-B seconds] [-e text] - # [-g group] [-m method] [-N] [-o file] [-P addr[:port]] [-p port] - # [-s duration] [-O num,text] [-T string] [-v num] URI - # - # URI can be an absolute or relative coap URI, - # -A type... accepted media types as comma-separated list of - # symbolic or numeric values - # -t type content type for given resource for PUT/POST - # -b [num,]size block size to be used in GET/PUT/POST requests - # (value must be a multiple of 16 not larger than 1024) - # If num is present, the request chain will start at - # block num - # -B seconds break operation after waiting given seconds - # (default is 90) - # -e text include text as payload (use percent-encoding for - # non-ASCII characters) - # -f file file to send with PUT/POST (use '-' for STDIN) - # -g group join the given multicast group - # -m method request method (get|put|post|delete), default is 'get' - # -N send NON-confirmable message - # -o file output received data to this file (use '-' for STDOUT) - # -p port listen on specified port - # -s duration subscribe for given duration [s] - # -v num verbosity level (default: 3) - # -O num,text add option num with contents text to request - # -P addr[:port] use proxy (automatically adds Proxy-Uri option to - # request) - # -T token include specified token - # - # examples: - # coap-client -m get coap://[::1]/ - # coap-client -m get coap://[::1]/.well-known/core - # coap-client -m get -T cafe coap://[::1]/time - # echo 1000 | coap-client -m put -T cafe coap://[::1]/time -f - - - - _BUILTINS='-B 1 -b 1024' - - -# echo '=====================================================================================' - if [ "$_payload" != "" ] - then -# echo "echo "$_payload" | ./coap-client -f - $_BUILTINS $_METHOD $_ACCEPT $_CONTENTFORMAT $_URL" - _response=$(echo "$_payload" | coap-client -f - $_BUILTINS $_METHOD $_ACCEPT $_CONTENTFORMAT $_URL) - else -# echo "./coap-client $_BUILTINS $_METHOD $_ACCEPT $_CONTENTFORMAT $_URL" - _response=$(coap-client $_BUILTINS $_METHOD $_ACCEPT $_CONTENTFORMAT $_URL) - fi -# echo '=====================================================================================' - - - # Get headers - _responseHeaders=$(echo "$_response" | head -n 1) - - # Strip headers and garbage bytes from response - _response=$(echo "$_response" | tail -n +2 | head -c-3) - - - echo $_responseHeaders - echo - - # - # Print and beautify response body (IF ANY) - # - if [ "$_noPayloadCheck" == "on" ] - then - echo $_response - else - if [ "$_response" != "" ] - then - if [ "$_outFormat" == application/xml ] || [ "$_outFormat" == "" ] - then - # FIXME P10: XML removal - #echo $_response | xmllint --format - - echo $_response | python -mjson.tool - elif [ "$_outFormat" == application/json ] - then - vMsg "JSON check for:" $_response - echo $_response | python -mjson.tool - else - # FIXME P10: XML removal - #echo $_response | xmllint --format - - echo $_response | python -mjson.tool - fi - fi - fi -} diff --git a/archive/proxyCoap/src/app/CMakeLists.txt b/archive/proxyCoap/src/app/CMakeLists.txt deleted file mode 100644 index 00d6d28b07..0000000000 --- a/archive/proxyCoap/src/app/CMakeLists.txt +++ /dev/null @@ -1,96 +0,0 @@ -# Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) - -SET (SOURCES - proxyCoap.cpp - HttpProxy.cpp - HttpMessage.cpp - CoapController.cpp -) - - -SET (HEADERS - HttpProxy.h - HttpMessage.h - CoapController.h -) - -SET (STATIC_LIBS - lm - pa -) - -# Include directories -# ----------------------------------------------------------------- -include_directories("${PROJECT_SOURCE_DIR}/src/app") -include_directories("${PROJECT_SOURCE_DIR}/src/lib") -include_directories("${RAPIDXML_INCLUDE}") - - -# Lib directories -# ------------------------------------------------------------ -link_directories("/usr/local/lib/") -link_directories("/usr/lib64/") -link_directories("/usr/lib/x86_64-linux-gnu") - -# FIXME P4: Issue #476: remove or keep? -link_directories("/opt/lib/") - - - -# Executable declaration -# ------------------------------------------------------------ -ADD_EXECUTABLE(proxyCoap ${SOURCES} ${HEADERS}) - -IF(${DISTRO} STREQUAL "Fedora_20") - MESSAGE("proxyCoap: Fedora DISTRO: '${DISTRO}'") - TARGET_LINK_LIBRARIES(proxyCoap ${STATIC_LIBS} cantcoap curl -lboost_thread) -ELSEIF(${DISTRO} STREQUAL "Ubuntu_13.10") - MESSAGE("proxyCoap: Ubuntu DISTRO: '${DISTRO}'") - TARGET_LINK_LIBRARIES(proxyCoap ${STATIC_LIBS} cantcoap curl boost_thread boost_system pthread) -ELSEIF(${DISTRO} STREQUAL "Ubuntu_14.04.1_LTS") - # FIXME P4: Issue #476: remove or keep? - MESSAGE("proxyCoap: Ubuntu DISTRO: '${DISTRO}'") - TARGET_LINK_LIBRARIES(proxyCoap ${STATIC_LIBS} cantcoap curl boost_thread boost_system pthread) -ELSEIF(${DISTRO} STREQUAL "Ubuntu_14.04.3_LTS") - # FIXME P4: Issue #476: remove or keep? - MESSAGE("proxyCoap: Ubuntu DISTRO: '${DISTRO}'") - TARGET_LINK_LIBRARIES(proxyCoap ${STATIC_LIBS} cantcoap curl boost_thread boost_system pthread) -ELSEIF(${DISTRO} STREQUAL "Ubuntu_14.10") - # ADDED FOR UBUNTU 14.10 - MESSAGE("contextBroker: Ubuntu DISTRO: '${DISTRO}'") - TARGET_LINK_LIBRARIES(proxyCoap ${STATIC_LIBS} cantcoap curl boost_thread boost_system pthread) -ELSEIF(${DISTRO} STREQUAL "Debian_8.0") - MESSAGE("proxyCoap: Debian DISTRO: '${DISTRO}'") - TARGET_LINK_LIBRARIES(proxyCoap ${STATIC_LIBS} cantcoap curl boost_thread boost_system pthread) -ELSEIF(${DISTRO} MATCHES "CentOS_6.*") - MESSAGE("proxyCoap: CentOS DISTRO: '${DISTRO}'") - TARGET_LINK_LIBRARIES(proxyCoap ${STATIC_LIBS} cantcoap curl -lboost_thread-mt) -ELSE() - MESSAGE("proxyCoap: Other DISTRO: '${DISTRO}'") - TARGET_LINK_LIBRARIES(proxyCoap ${STATIC_LIBS} cantcoap curl -lboost_thread -lboost_system -lpthread) -ENDIF() - -# target_link_libraries (proxyCoap cantcoap curl) - -INSTALL(TARGETS proxyCoap - RUNTIME DESTINATION bin) diff --git a/archive/proxyCoap/src/app/CoapController.cpp b/archive/proxyCoap/src/app/CoapController.cpp deleted file mode 100644 index f9dbbb2b93..0000000000 --- a/archive/proxyCoap/src/app/CoapController.cpp +++ /dev/null @@ -1,270 +0,0 @@ -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: TID Developer -*/ - -#include "CoapController.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "proxyCoap/HttpProxy.h" -#include "proxyCoap/HttpMessage.h" - -#define PORT_STRING_SIZE 6 - -CoapController::CoapController(const char *_host, unsigned short _httpPort, unsigned short _coapPort) -{ - // Read host and port values - httpPort = _httpPort; - coapPort = _coapPort; - host.assign(_host); - - char* portString = new char[PORT_STRING_SIZE]; - snprintf(portString, PORT_STRING_SIZE, "%d", _coapPort); - coapPortStr.assign(portString); -} - -/* **************************************************************************** -* -* sendDatagram - -*/ -int CoapController::sendDatagram(int sockfd, boost::scoped_ptr& res, sockaddr* recvFrom) -{ - socklen_t addrLen = sizeof(struct sockaddr_in); - if (recvFrom->sa_family == AF_INET6) - { - addrLen = sizeof(struct sockaddr_in6); - } - - ssize_t sent = sendto(sockfd, res->getPDUPointer(), res->getPDULength(), 0, recvFrom, addrLen); - - if (sent < 0) - { - LM_W(("Error sending packet: %ld.", sent)); - return 1; - } - else - { - LM_T(LmtCoap, ("Sent: %ld bytes", sent)); - } - - return 0; -} - -int CoapController::sendError(int sockfd, CoapPDU* req, sockaddr* recvFrom, CoapPDU::Code code) -{ - boost::scoped_ptr res(new CoapPDU()); - - res->setVersion(1); - res->setMessageID(req->getMessageID()); - res->setCode(code); - res->setType(CoapPDU::COAP_ACKNOWLEDGEMENT); - res->setToken(req->getTokenPointer(), req->getTokenLength()); - - return sendDatagram(sockfd, res, recvFrom); -} - -/* **************************************************************************** -* -* callback - -*/ -int CoapController::callback(CoapPDU* request, int sockfd, struct sockaddr_storage* recvFrom) -{ - // Translate request from CoAP to HTTP and send it to MHD through loopback - std::string httpResponse; - httpResponse = sendHttpRequest(host.c_str(), httpPort, request); - - if (httpResponse == "") - { - // Could not get an answer from HTTP module - sendError(sockfd, request, (sockaddr*)recvFrom, CoapPDU::COAP_INTERNAL_SERVER_ERROR); - return 1; - } - - // Parse HTTP response - boost::scoped_ptr hm(new HttpMessage(httpResponse)); - - // If CoAP message is too big, must send error to requester - if (hm->contentLength() > COAP_BUFFER_SIZE) - { - sendError(sockfd, request, (sockaddr*)recvFrom, CoapPDU::COAP_REQUEST_ENTITY_TOO_LARGE); - return 1; - } - - // Translate response from HTTP to CoAP - boost::scoped_ptr coapResponse(hm->toCoap()); - - if (!coapResponse) - { - // Could not translate HTTP into CoAP - sendError(sockfd, request, (sockaddr*)recvFrom, CoapPDU::COAP_INTERNAL_SERVER_ERROR); - return 1; - } - - // Prepare appropriate response in CoAP - coapResponse->setVersion(1); - coapResponse->setMessageID(request->getMessageID()); - coapResponse->setToken(request->getTokenPointer(), request->getTokenLength()); - - // Set type - switch (request->getType()) - { - case CoapPDU::COAP_CONFIRMABLE: - case CoapPDU::COAP_NON_CONFIRMABLE: - coapResponse->setType(CoapPDU::COAP_ACKNOWLEDGEMENT); - break; - - case CoapPDU::COAP_ACKNOWLEDGEMENT: - case CoapPDU::COAP_RESET: - break; - - default: - return 1; - break; - }; - - // Send the packet - sendDatagram(sockfd, coapResponse, (sockaddr*) recvFrom); - return 0; -} - - - -/* **************************************************************************** -* -* serve - -*/ -void CoapController::serve() -{ - // Buffers for UDP and URIs - char buffer[COAP_BUFFER_SIZE]; - char uriBuffer[COAP_URI_BUFFER_SIZE]; - int recvURILen = 0; - int ret = 0; - - // Storage for handling receive address - struct sockaddr_storage recvAddr; - socklen_t recvAddrLen = sizeof(struct sockaddr_storage); - - // Prepare binding address - struct addrinfo *bindAddr = NULL; - struct addrinfo hints; - - // Setting up bind address - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_socktype = SOCK_DGRAM; - hints.ai_flags |= AI_NUMERICSERV; - hints.ai_family = AF_INET; // ipv4, PF_INET6 for ipv6 or PF_UNSPEC to let OS decide - - int error = getaddrinfo(host.c_str(), coapPortStr.c_str(), &hints, &bindAddr); - if (error) - { - LM_W(("Could not start CoAP server: Error getting address info: %s.", gai_strerror(error))); - return; - } - - // Setting up the UDP socket - int sd = socket(bindAddr->ai_family, bindAddr->ai_socktype, bindAddr->ai_protocol); - - // Binding socket - if (bind(sd, bindAddr->ai_addr, bindAddr->ai_addrlen) != 0) - { - LM_W(("Could not start CoAP server: Error binding socket")); - return; - } - - while (1) - { - // zero out the buffer - memset(buffer, 0, COAP_BUFFER_SIZE); - - // receive packet - ret = recvfrom(sd, &buffer, COAP_BUFFER_SIZE, 0, (sockaddr*) &recvAddr, &recvAddrLen); - if (ret == -1) - { - LM_W(("Error receiving data")); - continue; - } - - boost::scoped_ptr recvPDU(new CoapPDU((uint8_t*) buffer, COAP_BUFFER_SIZE, COAP_BUFFER_SIZE)); - - // validate packet - if (ret > COAP_BUFFER_SIZE) - { - LM_W(("PDU too large to fit in pre-allocated buffer")); - continue; - } - recvPDU->setPDULength(ret); - if (recvPDU->validate() != 1) - { - LM_W(("Malformed CoAP packet")); - continue; - } - LM_T(LmtCoap, ("Valid CoAP PDU received")); - - // Treat URI - if (recvPDU->getURI(uriBuffer, COAP_URI_BUFFER_SIZE, &recvURILen) != 0) - { - LM_W(("Error retrieving URI")); - continue; - } - - if (recvURILen == 0) - { - LM_T(LmtCoap, ("There is no URI associated with this Coap PDU")); - } - else - { - // Invoke a callback thread - boost::thread* workerThread = new boost::thread(boost::bind(&CoapController::callback, this, recvPDU.get(), sd, &recvAddr)); - - // Wait for thread to finnish (like using no threads at all) for now - workerThread->join(); - - continue; - } - - // no URI, handle cases - - // code == 0, no payload, this is a ping request, send RST? - if ((recvPDU->getPDULength() == 0) && (recvPDU->getCode() == 0)) - { - LM_T(LmtCoap, ("CoAP ping request")); - } - - } -} diff --git a/archive/proxyCoap/src/app/CoapController.h b/archive/proxyCoap/src/app/CoapController.h deleted file mode 100644 index 515a56b2cd..0000000000 --- a/archive/proxyCoap/src/app/CoapController.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef COAP_CONTROLLER_H -#define COAP_CONTROLLER_H -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: TID Developer -*/ - -#include -#include -#include - -#include "cantcoap.h" - -class CoapController -{ - - std::string host; - std::string coapPortStr; - unsigned short httpPort; - unsigned short coapPort; - - int sendDatagram(int sockfd, boost::scoped_ptr& res, sockaddr* recvFrom); - int sendError(int sockfd, CoapPDU* req, sockaddr* recvFrom, CoapPDU::Code code); - - int callback(CoapPDU* request, int sockfd, struct sockaddr_storage* recvFrom); - -public: - CoapController(const char* _host, unsigned short _httpPort, unsigned short _coapPort); - void serve(); -}; - -#endif // COAP_CONTROLLER_H diff --git a/archive/proxyCoap/src/app/HttpMessage.cpp b/archive/proxyCoap/src/app/HttpMessage.cpp deleted file mode 100644 index a9b04933dd..0000000000 --- a/archive/proxyCoap/src/app/HttpMessage.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: TID Developer -*/ - -#include "proxyCoap/HttpMessage.h" - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "rest/HttpHeaders.h" - -#include // atoi -#include // istringstream - -HttpMessage::HttpMessage(std::string theMessage) -{ - _httpCode = 0; - _contentLength = 0; - _contentType = ""; - _body = ""; - - std::istringstream iss(theMessage); - std::string line; - - bool isHeader = true; - while (std::getline(iss, line)) - { - // Clean last char in headers - if (isHeader) - { - line = line.substr(0, line.size() - 1); - } - - if (line.empty()) - { - isHeader = false; - } - - if (isHeader) - { - // Is it a header or the first line with the HTTP code? - int pos = line.find(":"); - if (pos < 0) - { - // Get HTTP code - // HTTP code is always 3 chars long starting at position 9 - // - // HTTP/1.1 200 OK - // XXX - // - _httpCode = atoi(line.substr(9, 3).c_str()); - } - else - { - // Get other headers - int temp = line.find(HTTP_CONTENT_LENGTH); - if (temp >= 0) - { - _contentLength = atoi(line.substr(pos + 2).c_str()); - } - - temp = line.find(HTTP_CONTENT_TYPE); - if (temp >= 0) - { - _contentType = line.substr(pos + 2); - } - } - } - else - { - // We are parsing the body now (as is) - _body += line; - } - } -} - -CoapPDU* HttpMessage::toCoap() -{ - CoapPDU* pdu = new CoapPDU(); - - // Set code - switch (this->_httpCode) - { - case 200: - pdu->setCode(CoapPDU::COAP_CONTENT); - break; - - case 415: - pdu->setCode(CoapPDU::COAP_UNSUPPORTED_CONTENT_FORMAT); - break; - - default: - pdu->httpStatusToCode(this->_httpCode); - break; - } - - // Set payload - uint8_t* data = (uint8_t*) this->_body.c_str(); - std::size_t length = this->_body.length(); - pdu->setPayload(data, length); - - // Set content-type - if (this->_contentType == "application/json") - { - pdu->setContentFormat(CoapPDU::COAP_CONTENT_FORMAT_APP_JSON); - } - else - { - pdu->setContentFormat(CoapPDU::COAP_CONTENT_FORMAT_APP_XML); - } - - return pdu; -} diff --git a/archive/proxyCoap/src/app/HttpMessage.h b/archive/proxyCoap/src/app/HttpMessage.h deleted file mode 100644 index 24e533ed8d..0000000000 --- a/archive/proxyCoap/src/app/HttpMessage.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef HTTP_MESSAGE_H -#define HTTP_MESSAGE_H -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: TID Developer -*/ -#include -#include "cantcoap.h" - -class HttpMessage -{ - int _httpCode; - int _contentLength; - std::string _contentType; - std::string _body; - - public: - HttpMessage(std::string theMessage); - - CoapPDU* toCoap(); - int contentLength() { return _contentLength; } -}; - -#endif // HTTP_MESSAGE_H diff --git a/archive/proxyCoap/src/app/HttpProxy.cpp b/archive/proxyCoap/src/app/HttpProxy.cpp deleted file mode 100644 index 098fc26ee4..0000000000 --- a/archive/proxyCoap/src/app/HttpProxy.cpp +++ /dev/null @@ -1,236 +0,0 @@ -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: TID Developer -*/ - -#include "proxyCoap/HttpProxy.h" - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - - -/* **************************************************************************** -* -* writeMemoryCallback - -*/ -size_t writeMemoryCallback(void* contents, size_t size, size_t nmemb, void* userp) -{ - size_t realsize = size * nmemb; - MemoryStruct* mem = (MemoryStruct *) userp; - - mem->memory = (char*) realloc(mem->memory, mem->size + realsize + 1); - if (mem->memory == NULL) - { - LM_W(("Not enough memory (realloc returned NULL)\n")); - return 0; - } - - memcpy(&(mem->memory[mem->size]), contents, realsize); - mem->size += realsize; - mem->memory[mem->size] = 0; - - return realsize; -} - - -/* **************************************************************************** -* -* sendHttpRequest - -*/ -std::string sendHttpRequest(const char* host, unsigned short port, CoapPDU* request) -{ - int recvURILen = 0; - CURL* curl = curl_easy_init(); - MemoryStruct httpResponse; - CURLcode res; - char uriBuffer[COAP_URI_BUFFER_SIZE]; - - if (curl) - { - // Allocate to hold HTTP response - httpResponse.memory = (char*) malloc(1); // will grow as needed - httpResponse.size = 0; // no data at this point - - // --- Set HTTP verb - std::string httpVerb = ""; - - switch(request->getCode()) - { - case CoapPDU::COAP_POST: - httpVerb = "POST"; - break; - - case CoapPDU::COAP_PUT: - httpVerb = "PUT"; - break; - - case CoapPDU::COAP_DELETE: - httpVerb = "DELETE"; - break; - - case CoapPDU::COAP_EMPTY: - case CoapPDU::COAP_GET: - default: - httpVerb = "GET"; - break; - } - curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, httpVerb.c_str()); - LM_T(LmtCoap, ("Got an HTTP %s", httpVerb.c_str())); - - - // --- Prepare headers - struct curl_slist* headers = NULL; - CoapPDU::CoapOption* options = request->getOptions(); - int numOptions = request->getNumOptions(); - - for (int i = 0; i < numOptions ; i++) - { - u_int16_t opt = options[i].optionNumber; - std::string string = ""; - u_int8_t buffer[options[i].optionValueLength + 1]; - - memcpy(buffer, options[i].optionValuePointer, options[i].optionValueLength); - - switch (opt) - { - case CoapPDU::COAP_OPTION_URI_PATH: - buffer[options[i].optionValueLength] = '\0'; - LM_T(LmtCoap, ("Got URI_PATH option: '%s'", buffer)); - break; - - case CoapPDU::COAP_OPTION_CONTENT_FORMAT: - switch (buffer[0]) - { - case CoapPDU::COAP_CONTENT_FORMAT_APP_JSON: - string = "Content-type: application/json"; - break; - - case CoapPDU::COAP_CONTENT_FORMAT_APP_XML: - string = "Content-type: application/xml"; - break; - - default: - string = "Content-type: application/json"; - break; - } - headers = curl_slist_append(headers, string.c_str()); - LM_T(LmtCoap, ("Got CONTENT-FORMAT option: '%s'", string.c_str())); - break; - - case CoapPDU::COAP_OPTION_ACCEPT: - switch (buffer[0]) - { - case CoapPDU::COAP_CONTENT_FORMAT_APP_JSON: - string = "Accept: application/json"; - break; - - case CoapPDU::COAP_CONTENT_FORMAT_APP_XML: - string = "Accept: application/xml"; - break; - - default: - string = "Accept: application/json"; - break; - } - headers = curl_slist_append(headers, string.c_str()); - LM_T(LmtCoap, ("Got ACCEPT option: '%s'", string.c_str())); - break; - - default: - LM_T(LmtCoap, ("Got unknown option")); - break; - } - } - - - // Set Content-length - if (request->getPayloadLength() > 0) - { - std::stringstream contentLengthStringStream; - contentLengthStringStream << request->getPayloadLength(); - std::string finalString = "Content-length: " + contentLengthStringStream.str(); - headers = curl_slist_append(headers, finalString.c_str()); - LM_T(LmtCoap, ("Got: '%s'", finalString.c_str())); - - // --- Set contents - char* payload = (char*) request->getPayloadCopy(); - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (u_int8_t*) payload); - } - - // Set Expect - headers = curl_slist_append(headers, "Expect: "); - - // --- Prepare URL - request->getURI(uriBuffer, COAP_URI_BUFFER_SIZE, &recvURILen); - char url[strlen(host) + recvURILen + 1]; - strncpy(url, host, strlen(host)); - if (recvURILen > 0) - strncat(url, uriBuffer, recvURILen); - url[strlen(host) + recvURILen] = '\0'; - LM_T(LmtCoap, ("URL: '%s'", url)); - - // --- Prepare CURL handle with obtained options - curl_easy_setopt(curl, CURLOPT_URL, url); - curl_easy_setopt(curl, CURLOPT_PORT, port); - curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); // Allow redirection (?) - curl_easy_setopt(curl, CURLOPT_HEADER, 1); // Activate include the header in the body output - curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); // Put headers in place - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &writeMemoryCallback); // Send data here - curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) &httpResponse); // Custom data for response handling - - - // --- Do HTTP Request - res = curl_easy_perform(curl); - if (res != CURLE_OK) - { - LM_W(("curl_easy_perform() failed: %s\n", curl_easy_strerror(res))); - - // --- Cleanup curl environment - curl_slist_free_all(headers); - curl_easy_cleanup(curl); - - return ""; - } - - // --- Cleanup curl environment - curl_slist_free_all(headers); - curl_easy_cleanup(curl); - } - - std::string ret; - ret.assign(httpResponse.memory, httpResponse.size); - free(httpResponse.memory); - return ret; -} - diff --git a/archive/proxyCoap/src/app/HttpProxy.h b/archive/proxyCoap/src/app/HttpProxy.h deleted file mode 100644 index 14b9d40350..0000000000 --- a/archive/proxyCoap/src/app/HttpProxy.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef HTTP_PROXY_H -#define HTTP_PROXY_H -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: TID Developer -*/ -#include "cantcoap.h" -#include "proxyCoap/HttpMessage.h" - -struct MemoryStruct { - char* memory; - size_t size; -}; - -static const int COAP_URI_BUFFER_SIZE = 255; -static const int COAP_BUFFER_SIZE = 1024; - -extern std::string sendHttpRequest(const char* host, unsigned short port, CoapPDU* request); - -#endif // HTTP_PROXY_H diff --git a/archive/proxyCoap/src/app/proxyCoap.cpp b/archive/proxyCoap/src/app/proxyCoap.cpp deleted file mode 100644 index 3d4b34be8c..0000000000 --- a/archive/proxyCoap/src/app/proxyCoap.cpp +++ /dev/null @@ -1,202 +0,0 @@ -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: TID Developer -*/ - -#include -#include -#include -#include -#include -#include // getppid, for, setuid, etc. -#include // open -#include -#include -#include -#include - -#include "parseArgs/parseArgs.h" -#include "parseArgs/paConfig.h" -#include "parseArgs/paBuiltin.h" -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "rest/rest.h" - -#include "common/sem.h" -#include "common/globals.h" -#include "common/Timer.h" -#include "common/compileInfo.h" - - -#include "common/string.h" - -#include "proxyCoap/CoapController.h" -#include "proxyCoap/version.h" - -/* **************************************************************************** -* -* Option variables -*/ -bool fg; -char bindAddress[MAX_LEN_IP]; -int port; -char cbHost[64]; -int cbPort; -bool useOnlyIPv4; -bool useOnlyIPv6; - -/* **************************************************************************** -* -* parse arguments -*/ -PaArgument paArgs[] = -{ - { "-fg", &fg, "FOREGROUND", PaBool, PaOpt, false, false, true, "don't start as daemon" }, - { "-localIp", bindAddress, "LOCALIP", PaString, PaOpt, _i "0.0.0.0", PaNL, PaNL, "IP to receive new connections" }, - { "-port", &port, "PORT", PaInt, PaOpt, 5683, PaNL, PaNL, "port to receive new connections" }, - - { "-cbHost", cbHost, "FWD_HOST", PaString, PaOpt, _i "localhost", PaNL, PaNL, "host for forwarding CoAP requests" }, - { "-cbPort", &cbPort, "FWD_PORT", PaInt, PaOpt, 1026, 0, 65000, "HTTP port for forwarding CoAP requests" }, - - { "-ipv4", &useOnlyIPv4, "USEIPV4", PaBool, PaOpt, false, false, true, "use ip v4 only" }, - { "-ipv6", &useOnlyIPv6, "USEIPV6", PaBool, PaOpt, false, false, true, "use ip v6 only" }, - - - PA_END_OF_ARGS -}; - -/* **************************************************************************** -* -* sigHandler - -*/ -void sigHandler(int sigNo) -{ - LM_T(LmtPresent, ("In sigHandler - caught signal %d", sigNo)); - - switch (sigNo) - { - case SIGINT: - case SIGTERM: - LM_X(1, ("Received signal %d", sigNo)); - break; - } -} - -const char* description = - "\n" - "proxyCoap version details:\n" - " version: " PROXYCOAP_VERSION"\n" - " git hash: " GIT_HASH "\n" - " compile time: " COMPILE_TIME "\n" - " compiled by: " COMPILED_BY "\n" - " compiled in: " COMPILED_IN "\n"; - - - -/* **************************************************************************** -* -* daemonize - -*/ -void daemonize(void) -{ - pid_t pid; - pid_t sid; - - // already daemon - if (getppid() == 1) - return; - - pid = fork(); - if (pid == -1) - LM_X(1, ("fork: %s", strerror(errno))); - - // Exiting father process - if (pid > 0) - exit(0); - - // Change the file mode mask */ - umask(0); - - // Removing the controlling terminal - sid = setsid(); - if (sid == -1) - LM_X(1, ("setsid: %s", strerror(errno))); - - // Change current working directory. - // This prevents the current directory from being locked; hence not being able to remove it. - if (chdir("/") == -1) - LM_X(1, ("chdir: %s", strerror(errno))); -} - - - -/* **************************************************************************** -* -* main - -*/ -int main(int argC, char* argV[]) -{ - - signal(SIGINT, sigHandler); - signal(SIGTERM, sigHandler); - - paConfig("remove builtin", "-d"); - paConfig("remove builtin", "-r"); - paConfig("remove builtin", "-w"); - paConfig("remove builtin", "-F"); - paConfig("remove builtin", "-B"); - paConfig("remove builtin", "-b"); - paConfig("remove builtin", "-?"); - paConfig("remove builtin", "-toDo"); - paConfig("remove builtin", "-lmnc"); - paConfig("remove builtin", "-lmca"); - paConfig("remove builtin", "-lmkl"); - paConfig("remove builtin", "-lmll"); - paConfig("remove builtin", "-assert"); - paConfig("remove builtin", "-version"); - paConfig("remove builtin", "-h"); - paConfig("remove builtin", "-help"); - - paConfig("man synopsis", (void*) "[options]"); - paConfig("man shortdescription", (void*) "Options:"); - paConfig("man description", (void*) description); - paConfig("man author", (void*) "Telefonica I+D"); - paConfig("man exitstatus", (void*) "proxyCoap is a daemon. If it exits, something is wrong ..."); - paConfig("man version", (void*) PROXYCOAP_VERSION); - paConfig("log to screen", (void*) true); - paConfig("log to file", (void*) true); - paConfig("log file line format", (void*) "TYPE:DATE:EXEC-AUX/FILE[LINE] FUNC: TEXT"); - paConfig("screen line format", (void*) "TYPE@TIME FUNC[LINE]: TEXT"); - paConfig("builtin prefix", (void*) "PROXYCOAP_"); - paConfig("usage and exit on any warning", (void*) true); - - paParse(paArgs, argC, (char**) argV, 1, false); - - if (fg == false) - daemonize(); - - CoapController* cc = new CoapController(bindAddress, cbPort, port); - cc->serve(); -} - diff --git a/archive/proxyCoap/src/app/version.h b/archive/proxyCoap/src/app/version.h deleted file mode 100644 index bb2427fa30..0000000000 --- a/archive/proxyCoap/src/app/version.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef PROXYCOAP_VERSION_H -#define PROXYCOAP_VERSION_H - -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: TID Developer -*/ - - - -#define PROXYCOAP_VERSION "0.0.1-beta" - -#endif diff --git a/archive/proxyCoap/testEnv_coap.sh b/archive/proxyCoap/testEnv_coap.sh deleted file mode 100644 index ad37b76e29..0000000000 --- a/archive/proxyCoap/testEnv_coap.sh +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright 2016 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es -# -# -# In order to "recover" the following functions, they should be moved back -# to testEnv.sh file - -# o COAP_PORT - port where proxyCoap listens for connections - -export COAP_PORT=${COAP_PORT:-5683} diff --git a/archive/vagrant/Vagrantfile b/archive/vagrant/Vagrantfile deleted file mode 100644 index 645776fd27..0000000000 --- a/archive/vagrant/Vagrantfile +++ /dev/null @@ -1,42 +0,0 @@ -# -# Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es -# -# Author: Leandro Guillen - -# -*- mode: ruby -*- -# vi: set ft=ruby : - -# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! -VAGRANTFILE_API_VERSION = "2" - -Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| - # For a complete reference, please see the online documentation at vagrantup.com. - - # Cent OS 6.5 base image - config.vm.box = "chef/centos-6.5" - - # This script will be run at startup - config.vm.provision :shell, path: "../../scripts/bootstrap/centos65.sh" - - # Network configuration - config.vm.network "forwarded_port", host: 1026, guest: 1026 # Orion port - -end diff --git a/archive/vagrant/doc/manuals/vagrant.md b/archive/vagrant/doc/manuals/vagrant.md deleted file mode 100644 index 3b83c99e82..0000000000 --- a/archive/vagrant/doc/manuals/vagrant.md +++ /dev/null @@ -1,28 +0,0 @@ -## Vagrant support -If you want yo have an Orion Context Broker ready to develop in your machine easily we provide a Vagrant file so that you can get up and running. Just run: - - vagrant up - -You just need to install Vagrant if you want to use this, and at least Virtualbox. Especially useful for those that use virtual machines to develop on a Mac or a Linux distribution that is not CentOS. Keep in mind that the Vagrant file specifies CentOS 6.5 as a base operating system. - -For example, to compile in debug mode and install it in the home directory simply run: - - vagrant ssh -c 'INSTALL_DIR=/home/vagrant make di -C fiware-orion' - -After a few minutes you can run contextBroker. Again, you can either ssh into the machine with - - vagrant ssh - -and run it from the command-line, or directly run the broker with something like - - vagrant ssh -c 'contextBroker -multiservice -t 0-255' - -Orion Context Broker will be accessible at `127.0.0.1:1026`. - -You can also use these commands to automate building and running from your favorite IDE. - -*NOTE:* The virtualbox machine that is created uses additional resources to those from the broker itself. It uses around 512 MiB of RAM and around 1.20 GiB of disk space with Orion already compiled in debug mode. - - - -The bootstrap script basically goes through the installation instructions in the README. \ No newline at end of file diff --git a/archive/xml/README.md b/archive/xml/README.md deleted file mode 100644 index 13c313595b..0000000000 --- a/archive/xml/README.md +++ /dev/null @@ -1,102 +0,0 @@ -Old versions of Orion (0.28.0 and before) supported XML. This directory contains some stuff -related with that functionality that is not longer needed. - -In particular, the xmlCheck checker (which was used to check that XML in unittest testData/ -and test harness fragments were compliant with NGSI XSD). - -In addition, the following XML-based unit tests were removed. If you want to have a look to them, -have a look at code just before merging PR #2104 (this is the commit number: -https://github.com/telefonicaid/fiware-orion/commit/d6969490c8db77b2147fccbd986aab49303b5e8c). - -Deleted files containing only XML-based unit tests: - -* serviceRoutines/badNgsi10Request_test.cpp -* serviceRoutines/badNgsi9Request_test.cpp -* serviceRoutines/badRequest_test.cpp -* serviceRoutines/deleteAttributeValueInstance_test.cpp -* serviceRoutines/deleteIndividualContextEntityAttribute_test.cpp -* serviceRoutines/deleteIndividualContextEntity_test.cpp -* serviceRoutines/getAttributeValueInstance_test.cpp -* serviceRoutines/getContextEntitiesByEntityId_test.cpp -* serviceRoutines/getContextEntityAttributes_test.cpp -* serviceRoutines/getContextEntityTypeAttributeContainer_test.cpp -* serviceRoutines/getContextEntityTypeAttribute_test.cpp -* serviceRoutines/getContextEntityTypes_test.cpp -* serviceRoutines/getEntityByIdAttributeByName_test.cpp -* serviceRoutines/getIndividualContextEntityAttribute_test.cpp -* serviceRoutines/getIndividualContextEntity_test.cpp -* serviceRoutines/getNgsi10ContextEntityTypesAttribute_test.cpp -* serviceRoutines/getNgsi10ContextEntityTypes_test.cpp -* serviceRoutines/leakTreat_test.cpp -* serviceRoutines/logTraceTreat_test.cpp -* serviceRoutines/postContextEntitiesByEntityId_test.cpp -* serviceRoutines/postContextEntityAttributes_test.cpp -* serviceRoutines/postContextEntityTypeAttributeContainer_test.cpp -* serviceRoutines/postContextEntityTypeAttribute_test.cpp -* serviceRoutines/postContextEntityTypes_test.cpp -* serviceRoutines/postDiscoverContextAvailability_test.cpp -* serviceRoutines/postEntityByIdAttributeByName_test.cpp -* serviceRoutines/postIndividualContextEntityAttribute_test.cpp -* serviceRoutines/postIndividualContextEntity_test.cpp -* serviceRoutines/postQueryContext_test.cpp -* serviceRoutines/postRegisterContext_test.cpp -* serviceRoutines/postSubscribeContextAvailability_test.cpp -* serviceRoutines/postSubscribeContext_test.cpp -* serviceRoutines/postUnsubscribeContextAvailability_test.cpp -* serviceRoutines/postUnsubscribeContext_test.cpp -* serviceRoutines/postUpdateContextAvailabilitySubscription_test.cpp -* serviceRoutines/postUpdateContextSubscription_test.cpp -* serviceRoutines/postUpdateContext_test.cpp -* serviceRoutines/putAttributeValueInstance_test.cpp -* serviceRoutines/putIndividualContextEntity_test.cpp - -The following XML-based test were also removed (most of them were in DISABLED -state just before removing it): - -* TEST(compoundValue, DISABLED_updateContextValueVectorFiveItemsPlusBadOne) -* TEST(DiscoverContextAvailabilityRequest, DISABLED_entityIdIdAsAttribute_xml) -* TEST(DiscoverContextAvailabilityRequest, DISABLED_entityIdIsPattern_xml) -* TEST(DiscoverContextAvailabilityRequest, DISABLED_entityIdTypeAsField_xml) -* TEST(DiscoverContextAvailabilityRequest, DISABLED_entityIdType_xml) -* TEST(NotifyContextAvailabilityRequest, DISABLED_badEntityAttribute_xml) -* TEST(NotifyContextRequest, DISABLED_predetectedError) -* TEST(NotifyContextRequest, DISABLED_xml_invalidEntityIdAttribute) -* TEST(QueryContextRequest, DISABLED_emptyEntityList_xml) -* TEST(QueryContextRequest, DISABLED_emptyScopeType_xml) -* TEST(QueryContextRequest, DISABLED_emptyScopeValue_xml) -* TEST(QueryContextRequest, DISABLED_entityIdIdAsAttribute_xml) -* TEST(QueryContextRequest, DISABLED_entityIdIsPattern_xml) -* TEST(QueryContextRequest, DISABLED_entityIdType_xml) -* TEST(QueryContextRequest, DISABLED_fill) -* TEST(QueryContextRequest, DISABLED_noAttributeExpression_xml) -* TEST(QueryContextRequest, DISABLED_noEntityList_xml) -* TEST(QueryContextRequest, DISABLED_noRestriction_xml) -* TEST(QueryContextRequest, DISABLED_noScopeType_xml) -* TEST(QueryContextRequest, DISABLED_noScopeValue_xml) -* TEST(QueryContextRequest, DISABLED_overwriteEntityIdIsPattern_xml) -* TEST(QueryContextRequest, DISABLED_overwriteEntityIdType_xml) -* TEST(QueryContextRequest, DISABLED_unsupportedEntityIdAttribute_xml) -* TEST(QueryContextRequest, emptyEntityIdId_xml) -* TEST(QueryContextResponse, DISABLED_ok_xml) -* TEST(RegisterContextRequest, DISABLED_durationError) -* TEST(RegisterContextRequest, DISABLED_emptyContextMetadataName) -* TEST(RegisterContextRequest, DISABLED_emptyContextMetadataValue) -* TEST(RegisterContextRequest, DISABLED_emptyContextRegistration) -* TEST(RegisterContextRequest, DISABLED_emptyContextRegistrationAttributeIsDomain) -* TEST(RegisterContextRequest, DISABLED_emptyContextRegistrationAttributeName) -* TEST(RegisterContextRequest, DISABLED_emptyEntityIdList) -* TEST(RegisterContextRequest, DISABLED_emptyRegistrationMetadataValue) -* TEST(RegisterContextRequest, DISABLED_entityIdWithEmptyId) -* TEST(RegisterContextRequest, DISABLED_entityIdWithNoId) -* TEST(RegisterContextRequest, DISABLED_invalidAttributeName) -* TEST(RegisterContextRequest, DISABLED_noEntityIdList) -* TEST(RegisterContextRequest, DISABLED_present) -* TEST(restReply, DISABLED_restErrorReplyGet) -* TEST(SubscribeContextAvailabilityRequest, DISABLD_xml_noReference) -* TEST(SubscribeContextAvailabilityRequest, DISABLED_xml_badEntityId) -* TEST(SubscribeContextAvailabilityRequest, DISABLED_xml_entityIdIsPatternAsBothFieldAndAttribute) -* TEST(SubscribeContextAvailabilityRequest, DISABLED_xml_entityIdTypeAsBothFieldAndAttribute) -* TEST(SubscribeContextRequest, DISABLED_invalidEntityIdAttribute_xml) -* TEST(UpdateContextAvailabilitySubscriptionRequest, DISABLED_xml_invalidEntityAttribute) -* TEST(UpdateContextResponse, DISABLED_constructors) -* TEST(UpdateContextSubscriptionResponse, DISABLED_constructors) diff --git a/archive/xml/xmlCheck/envVarSubstitute.sh b/archive/xml/xmlCheck/envVarSubstitute.sh deleted file mode 100755 index 9d03f02c9f..0000000000 --- a/archive/xml/xmlCheck/envVarSubstitute.sh +++ /dev/null @@ -1,108 +0,0 @@ -#!/bin/bash -# Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - - - -# ----------------------------------------------------------------------------- -# -# usage -# -function usage() -{ - exitCode=$1 - - spaces=$(echo $0 | tr '0-9a-zA-Z /_.\-' ' ') - - echo $0 "[-u (usage)]" - echo "${spaces} [-v (verbose)]" - echo "${spaces} -f " - - exit $exitCode -} - - - -# ----------------------------------------------------------------------------- -# -# vMsg -# -function vMsg() -{ - if [ "$verbose" = "on" ] - then - echo $* - fi -} - - - -# ------------------------------------------------------------------------------ -# -# command line options -# -verbose="off" -file="" - -while [ "$#" != 0 ] -do - if [ "$1" == "-u" ]; then usage 0; - elif [ "$1" == "-v" ]; then verbose=on; - elif [ "$1" == "-f" ]; then file=$2; shift; - else - echo $0: bad parameter/option: "'"${1}"'" - usage 1 - fi - shift -done - -if [ "$file" == "" ] -then - echo $0: no file specified - exit 2 -fi - - - -# ------------------------------------------------------------------------------ -# -# Just substitute -# -vMsg $file to get variable substitution -unsubstituted=$(cat $file) -vMsg unsubstituted: -vMsg '----------------------------------' -vMsg $unsubstituted -vMsg '----------------------------------' - -substituted1=$(echo $unsubstituted | sed 's/\$SUB_ID/123456789012345678901234/g') -substituted2=$(echo $substituted1 | sed 's/\$SUBID/123456789012345678901234/g') -substituted3=$(echo $substituted2 | sed 's/\${LISTENER_PORT}/9999/g') -substituted4=$(echo $substituted3 | sed 's/\$subscriptionId/123456789012345678901234/g') -substituted5=$(echo $substituted4 | sed 's/\$REG_ID/123456789012345678901234/g') - -substituted=$substituted5 - -vMsg -vMsg '----------------------------------' -vMsg $substituted -vMsg '----------------------------------' - -echo "$substituted" > ${file} diff --git a/archive/xml/xmlCheck/xmlCheck.sh b/archive/xml/xmlCheck/xmlCheck.sh deleted file mode 100755 index 46252d1083..0000000000 --- a/archive/xml/xmlCheck/xmlCheck.sh +++ /dev/null @@ -1,560 +0,0 @@ -#!/bin/bash -# Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - - - -# ----------------------------------------------------------------------------- -# -# usage -# -function usage() -{ - exitCode=$1 - - spaces=$(echo $0 | tr '0-9a-zA-Z /_.\-' ' ') - - echo $0 "[-u (usage)]" - echo "${spaces} [-v (verbose)]" - echo "${spaces} [-f (file to check)]" - echo "${spaces} [--filter (test filter)]" - echo "${spaces} [--no-harness (no harness files)]" - echo "${spaces} [--dryrun (don't actually execute anything)]" - echo "${spaces} [--keep (do NOT remove harness files at end of processing)]" - echo "${spaces} [--xsd-download (download XSD files for FIWARE subversion)]" - echo "${spaces} [--xsd-dir (directory for XSD files)]" - - exit $exitCode -} - - - -# ----------------------------------------------------------------------------- -# -# vMsg -# -function vMsg() -{ - if [ "$verbose" = "on" ] - then - echo $* - fi -} - - - -# ------------------------------------------------------------------------------ -# -# xsdGet - -# -function xsdGet() -{ - prefix="$1" - xfile="$2" - - if [ "$prefix" = "ngsi9" ] - then - echo $xsdDir/Ngsi9_Operations.xsd - elif [ "$prefix" == "ngsi10" ] - then - echo $xsdDir/Ngsi10_Operations.xsd - elif [ "$prefix" == "ngsi" ] - then - echo $xsdDir/Ngsi9_10_dataStructures.xsd - else - echo "unknown file prefix: '"${prefix}"' for $xfile" - exit 2 - fi -} - - - -# ------------------------------------------------------------------------------ -# -# processFile - -# -function processFile() -{ - xmlFile=$1 - xsdFile=$2 - - if [ "$xmlFile" == "" ] || [ "$xsdFile" == "" ] - then - echo "bad parameters for file processing '"${xmlFile}"', '"${xsdFile}"'" - return; - fi - - N=$N+1 - - if [ "$dryrun" == "on" ] - then - vMsg dryrun: xmllint "$xmlFile" --schema "$xsdFile" - return - fi - - vMsg XSD: $xsdFile - if [ "$verbose2" == "on" ] - then - xmllint $xmlFile --schema $xsdFile - RESULT=$? - else - xmllint $xmlFile --schema $xsdFile > /dev/null 2>&1 - RESULT=$? - fi - - if [ "$RESULT" == "0" ] - then - echo "$xmlFile: ok" - OK=$OK+1 - else - echo "$xmlFile: FAILS (xmllint error: $RESULT)" - ERR=$ERR+1 - failingList=${failingList}" "$xmlFile - fi -} - - - -# ----------------------------------------------------------------------------- -# -# harnessFiles - -# -function harnessFiles() -{ - harnessList="" - TMP_DIR=$(mktemp -d /tmp/xmlCheck.XXXXX) - vMsg TMP_DIR: $TMP_DIR - for FILE in $(find $SRC_TOP/test/functionalTest/cases -name *.test) - do - PREFIX=$(basename ${FILE%.*}) - FILE_DIR=$(dirname $FILE) - LAST_SUBDIR=$(basename $FILE_DIR) - mkdir -p $TMP_DIR/$LAST_SUBDIR - $SRC_TOP/test/xmlCheck/xmlExtractor.py $FILE $TMP_DIR/$LAST_SUBDIR $PREFIX - done - - for FILE in $(find $TMP_DIR -name ngsi*.valid.xml) - do - grep '\$' $FILE - if [ "$?" != "0" ] - then - continue - fi - - $SRC_TOP/test/xmlCheck/envVarSubstitute.sh -f "$FILE" - done - - harnessList=$(find $TMP_DIR -name "ngsi*.valid.xml") - xmlPartsFound=$(find $TMP_DIR -name "ngsi*.xml" | wc -l) - xmlPartsValid=$(find $TMP_DIR -name "ngsi*.valid.xml" | wc -l) - xmlPartsInvalid=$(find $TMP_DIR -name "ngsi*.invalid.xml" | wc -l) - xmlPartsPostponed=$(find $TMP_DIR -name "ngsi*.postponed.xml" | wc -l) - xmlPartsUnknown=$(find $TMP_DIR -name "unknown*.xml" | wc -l) -} - - - -# ------------------------------------------------------------------------------ -# -# command line options -# -verbose="off" -filter="" -file="" -xsdDir="/tmp/xsd" -harness="on" -dryrun="off" -xsdDownload="off" -keep="off" - -while [ "$#" != 0 ] -do - if [ "$1" == "-u" ]; then usage 0; - elif [ "$1" == "-v" ]; then verbose=on; - elif [ "$1" == "-f" ]; then file=$2; shift; - elif [ "$1" == "--filter" ]; then filter=$2; shift; - elif [ "$1" == "--no-harness" ]; then harness="off"; - elif [ "$1" == "--dryrun" ]; then dryrun="on"; - elif [ "$1" == "--keep" ]; then keep="on"; - elif [ "$1" == "--xsd-download" ]; then xsdDownload="on"; - elif [ "$1" == "--xsd-dir" ]; then xsdDir=$2; shift; - else - echo $0: bad parameter/option: "'"${1}"'" - usage 1 - fi - shift -done - - - -# ----------------------------------------------------------------------------- -# -# SRC_TOP - getting the TOP directory -# -dir=$(dirname $0) -SRC_TOP1=${PWD}/${dir}/../.. # if called with a relative path -SRC_TOP2=${dir}/../.. # if called via $PATH or with an absolute path -if [ -d ${SRC_TOP1} ] -then - SRC_TOP=${SRC_TOP1} -else - SRC_TOP=${SRC_TOP2} -fi - -cd $SRC_TOP -SRC_TOP=$(pwd) -cd - > /dev/null -vMsg Git repo home: $SRC_TOP - - - -# ----------------------------------------------------------------------------- -# -# Checking the XSD directory -# -if [ ! -d "$xsdDir" ] -then - echo "$0: error: '"${xsdDir}"': no such directory" - exit 3 -fi - - - - -# ------------------------------------------------------------------------------ -# -# Download XSD files from FIWARE repo? -# -if [ "$xsdDownload" == "on" ] -then - # Get the .xsd files - echo -n "Enter username: " - read USER - - echo -n "Enter password: " - STTY_ORIG=`stty -g` - stty -echo - read PASS - stty $STTY_ORIG - echo - - \rm Ngsi10_Operations.xsd Ngsi9_Operations.xsd Ngsi9_10_dataStructures.xsd 2> /dev/null - wget -q --no-check-certificate --user=$USER --password=$PASS https://forge.fiware.org/scmrepos/svn/iot/trunk/schemes/Ngsi10_Operations.xsd - wget -q --no-check-certificate --user=$USER --password=$PASS https://forge.fiware.org/scmrepos/svn/iot/trunk/schemes/Ngsi9_Operations.xsd - wget -q --no-check-certificate --user=$USER --password=$PASS https://forge.fiware.org/scmrepos/svn/iot/trunk/schemes/Ngsi9_10_dataStructures.xsd - - if [ ! -f Ngsi10_Operations.xsd ] || [ ! -f Ngsi9_Operations.xsd ] || [ ! -f Ngsi9_10_dataStructures.xsd ] - then - echo $0: error: wget failed to download latest XSD files - exit 4 - fi - - mv Ngsi10_Operations.xsd Ngsi9_Operations.xsd Ngsi9_10_dataStructures.xsd $xsdDir - - vMsg "got XSD files" -fi - - - -# ------------------------------------------------------------------------------ -# -# XSD files there? -# -if [ ! -f $xsdDir/Ngsi10_Operations.xsd ] || [ ! -f $xsdDir/Ngsi9_Operations.xsd ] || [ ! -f $xsdDir/Ngsi9_10_dataStructures.xsd ] -then - echo "$0: error: XSD files missing in $xsdDir" - exit 5 -fi - - - -# ------------------------------------------------------------------------------ -# -# variables -# -typeset -i N -typeset -i OK -typeset -i ERR -N=0 -OK=0 -ERR=0 - - - -# ----------------------------------------------------------------------------- -# -# Setting up the file list -# -if [ "$file" != "" ] -then - fileList=$file - verbose2=on -else - if [ "$harness" == "on" ] - then - harnessFiles - fi - - ngsi9List=$(find $SRC_TOP/test -name "ngsi9.*.valid.xml") - ngsi10List=$(find $SRC_TOP/test -name "ngsi10.*.valid.xml") - fileList=${ngsi9List}" "${ngsi10List} - partList=$harnessList -fi - - - -# ------------------------------------------------------------------------------ -# -# Counters -# -typeset -i xmlFilesFound # Total number of XML files under test/ -typeset -i xmlFilesValid # Number of XML files that are valid -typeset -i xmlFilesInvalid # Number of XML files that are invalid -typeset -i xmlFilesPostponed # Number of XML files that are postponed -typeset -i xmlFilesBadName # Number of XML files whose names don't follow the naming convention - should be zero -typeset -i xmlFilesProcessed # Total number of XML files that were tested -typeset -i xmlFilesOK # Number of XML files that passed the test -typeset -i xmlFilesErrors # Number of XML files that did not pass the test - -typeset -i harnessFilesFound # Number of files in the harness directory - to part in many XML files -typeset -i xmlPartsFound # Number of XML parts created from harness directory -typeset -i xmlPartsValid # Number of XML parts that are valid -typeset -i xmlPartsInvalid # Number of XML parts that are invalid -typeset -i xmlPartsPostponed # Number of XML parts that are postponed -typeset -i xmlPartsUnknown # Number of XML parts that are unknown -typeset -i xmlPartsProcessed # Number of XML parts that were tested -typeset -i xmlPartsOK # Number of XML parts that passed the test -typeset -i xmlPartsErrors # Number of XML parts that did not pass the test -typeset -i xmlDocsFound # xmlFilesFound + xmlPartsFound -typeset -i xmlDocsProcessed # xmlFilesProcessed + xmlPartsProcessed -typeset -i xmlDocsPostponed # xmlFilesPostponed + xmlPartsPostponed -typeset -i xmlDocsOk # xmlFilesOK + xmlPartsOK -typeset -i xmlDocsErrors # xmlFilesErrors + xmlPartsErrors - -xmlFilesFound=$(find $SRC_TOP/test -name "*.xml" | wc -l) -xmlFilesValid=$(find $SRC_TOP/test -name "ngsi*.valid.xml" | wc -l) -xmlFilesInvalid=$(find $SRC_TOP/test -name "ngsi*.invalid.xml" | wc -l) -xmlFilesPostponed=$(find $SRC_TOP/test -name "ngsi*.postponed.xml" | wc -l) -xmlFilesMiddle=$(find $SRC_TOP/test -name "ngsi*.middle.xml" | wc -l) -xmlFilesOrion=$(find $SRC_TOP/test -name "orion.*.xml" | wc -l) -xmlFilesBadName=$(find $SRC_TOP/test -name "*.xml" | egrep -v 'ngsi.*\.valid\.xml' | egrep -v 'ngsi.*\.invalid\.xml' | egrep -v 'ngsi.*\.postponed\.xml' | egrep -v 'ngsi.*\.middle\.xml' | egrep -v 'orion\..*\.xml' | wc -l) -xmlFilesProcessed=0 -xmlFilesOK=0 -xmlFilesErrors=0 -harnessFilesFound=$(find $SRC_TOP/test/functionalTest/cases -name "*.test" | wc -l) -xmlPartsFound=$xmlPartsFound # already taken care of by function 'harnessFiles' -xmlPartsValid=$xmlPartsValid # already taken care of by function 'harnessFiles' -xmlPartsInvalid=$xmlPartsInvalid # already taken care of by function 'harnessFiles' -xmlPartsPostponed=$xmlPartsPostponed # already taken care of by function 'harnessFiles' -xmlPartsUnknown=$xmlPartsUnknown # already taken care of by function 'harnessFiles' -xmlPartsProcessed=0 -xmlPartsOK=0 -xmlPartsErrors=0 -xmlDocsFound=$(expr $xmlFilesFound + $xmlPartsFound) -xmlDocsProcessed=0 -xmlDocsOk=0 -xmlDocsErrors=0 - - - -# ------------------------------------------------------------------------------ -# -# Applying filter to the file lists -# -if [ "$filter" != "" ] -then - vMsg appying filter "'"${filter}"'" - newFileList="" - for xfile in $fileList - do - echo $xfile | grep "$filter" > /dev/null 2>&1 - if [ "$?" == 0 ] - then - newFileList=${newFileList}" "${xfile} - xmlFilesProcessed=$xmlFilesProcessed+1 - fi - done - fileList=$newFileList - - newPartList="" - for part in $partList - do - echo $part | grep "$filter" > /dev/null 2>&1 - if [ "$?" == 0 ] - then - newPartList=${newPartList}" "${part} - xmlPartsProcessed=$xmlPartsProcessed+1 - fi - done - partList=$newPartList -fi - - - -# ------------------------------------------------------------------------------ -# -# process the list of files to check -# -OK=0 -ERR=0 -N=0 -for xfile in $fileList -do - fileName=$(basename $xfile) - prefix=$(echo $fileName | cut -d . -f 1) - xsd=$(xsdGet "$prefix" "$xfile") - processFile "$xfile" "$xsd" -done - -xmlFilesProcessed=$N -xmlFilesOK=$OK; -xmlFilesErrors=$ERR - - - -# ------------------------------------------------------------------------------ -# -# process the list of parts to check -# -OK=0 -ERR=0 -N=0 -for part in $partList -do - partName=$(basename $part) - prefix=$(echo $partName | cut -d . -f 1) - xsd=$(xsdGet "$prefix" "$part") - processFile "$part" "$xsd" -done - -xmlPartsProcessed=$N -xmlPartsOK=$OK; -xmlPartsErrors=$ERR - - -xmlDocsProcessed=$(expr $xmlFilesProcessed + $xmlPartsProcessed) -xmlDocsOk=$(expr $xmlFilesOK + $xmlPartsOK) -xmlDocsErrors=$(expr $xmlFilesErrors + $xmlPartsErrors) - - - - - -# ------------------------------------------------------------------------------ -# -# Statistics not shown if the option '-f' is set -# -if [ "$file" != "" ] -then - if [ "$ERR" != "0" ] - then - exit 6 - else - exit 0 - fi -fi - - - -# ------------------------------------------------------------------------------ -# -# Statistics -# -echo "=====================================================================" -if [ "$xmlDocsErrors" != "0" ] -then - echo - echo "XML docs that did not pass the XML Validity test:" - - for item in $failingList - do - echo " o " $item - done - - echo - echo "=====================================================================" -fi - - -echo "Tested ${xmlDocsProcessed} (${xmlFilesProcessed} files + ${xmlPartsProcessed} parts) out of ${xmlDocsFound} (${xmlFilesFound} files + ${xmlPartsFound} parts) XML documents:" -echo " ${xmlDocsOk} documents passed the XML validity test" - -exitCode=7 - -if [ "$xmlDocsErrors" != 0 ] -then - echo " ${xmlDocsErrors} documents did not pass" -else - echo " -----------------------" - echo " ALL documents passed!!!" - echo " -----------------------" - exitCode=0 -fi - -echo -echo "${xmlFilesInvalid} documents were not tested as they on purpose don't follow the XSD" -xmlDocsPostponed=$xmlFilesPostponed+$xmlPartsPostponed -echo "${xmlDocsPostponed} documents were not tested as they still have no XSD" -echo "${xmlFilesMiddle} documents were not tested as they don't start the way the XSD states (middle)" - - -if [ "$xmlFilesBadName" != 0 ] -then - echo - if [ "$xmlFilesBadName" != "0" ] - then - echo "WARNING: $xmlFilesBadName XML files do not conform to the naming convention" - for xfile in $(find $SRC_TOP/test -name "*.xml" | grep -v "ngsi*.valid.xml" | grep -v "ngsi*.invalid.xml" | grep -v "ngsi*.postponed.xml" | grep -v "ngsi*.middle.xml" | grep -v "orion.*.xml") - do - echo " o $xfile" - done - fi - exitCode=8 -fi - - -if [ "$xmlPartsUnknown" != 0 ] -then - echo - echo "WARNING: parts marked as unknown" - for xfile in $(find $TMP_DIR -name "unknown*.xml") - do - echo " o $xfile" - done - exitCode=9 -fi - - - -# ------------------------------------------------------------------------------ -# -# Keep? -# -if [ "$keep" == "off" ] -then - rm -rf $TMP_DIR -fi - -if [ "$exitCode" != "0" ] -then - echo exiting with error code $exitCode -fi - -exit $exitCode diff --git a/archive/xml/xmlCheck/xmlExtractor.py b/archive/xml/xmlCheck/xmlExtractor.py deleted file mode 100755 index f924d4f612..0000000000 --- a/archive/xml/xmlCheck/xmlExtractor.py +++ /dev/null @@ -1,190 +0,0 @@ -#!/usr/bin/python -# -*- coding: latin-1 -*- -# Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# This script extract XML fragments of a given file (passed as first arguments), -# each fragment put in a separate file in a given directory (passed as second argument). -# This is mainly aimed at processing test harness files (.test files) to pass the -# xmlCheck.sh on then afterwards. Note that the heuristic used by the script is not -# bullet-proof: it assumes that the starting and ending tag of the root element is -# in its own line, without other child starting or ending tags (but it should suffice -# for .test files) - -__author__ = 'fermin' - -from sys import argv -import re - -def write_fragment(lines, filename): - f = open(filename, 'w') - f.writelines(lines) - f.close() - -tokens_map = { - # NGSI9 standard operations - 'registerContextRequest': ['ngsi9', 'valid'], - 'registerContextResponse': ['ngsi9', 'valid'], - 'discoverContextAvailabilityRequest': ['ngsi9', 'valid'], - 'discoverContextAvailabilityResponse': ['ngsi9', 'valid'], - 'subscribeContextAvailabilityRequest': ['ngsi9', 'valid'], - 'subscribeContextAvailabilityResponse': ['ngsi9', 'valid'], - 'updateContextAvailabilitySubscriptionRequest': ['ngsi9', 'valid'], - 'updateContextAvailabilitySubscriptionResponse': ['ngsi9', 'valid'], - 'unsubscribeContextAvailabilityRequest': ['ngsi9', 'valid'], - 'unsubscribeContextAvailabilityResponse': ['ngsi9', 'valid'], - 'notifyContextAvailabilityRequest': ['ngsi9', 'valid'], - 'notifyContextAvailabilityResponse': ['ngsi9', 'valid'], - # NGSI10 standard operatoins - 'queryContextRequest': ['ngsi10', 'valid'], - 'queryContextResponse': ['ngsi10', 'valid'], - 'updateContextRequest': ['ngsi10', 'valid'], - 'updateContextResponse': ['ngsi10', 'valid'], - 'subscribeContextRequest': ['ngsi10', 'valid'], - 'subscribeContextResponse': ['ngsi10', 'valid'], - 'updateContextSubscriptionRequest': ['ngsi10', 'valid'], - 'updateContextSubscriptionResponse': ['ngsi10', 'valid'], - 'unsubscribeContextRequest': ['ngsi10', 'valid'], - 'unsubscribeContextResponse': ['ngsi10', 'valid'], - 'notifyContextRequest': ['ngsi10', 'valid'], - 'notifyContextResponse': ['ngsi10', 'valid'], - # NGSI convenience operations exclusive types - 'registerProviderRequest': ['ngsi9', 'postponed'], - 'updateContextElementRequest': ['ngsi10', 'postponed'], - 'updateContextElementResponse': ['ngsi10', 'postponed'], - 'appendContextElementRequest': ['ngsi10', 'postponed'], - 'appendContextElementResponse': ['ngsi10', 'postponed'], - 'updateContextAttributeRequest': ['ngsi10', 'postponed'], - 'contextElementResponse': ['ngsi10', 'postponed'], - 'contextAttributeResponse': ['ngsi10', 'postponed'], - 'statusCode': ['ngsi', 'valid'], - # New operations - 'entityTypeAttributesResponse': ['ngsi10', 'postponed'], - 'entityTypesResponse': ['ngsi10', 'postponed'], - # Orion own types - 'orion': ['orion', 'invalid'], - 'orionError': ['orion', 'invalid'] -} - -if len (argv) != 4: - print 'Wrong number of arguments' - print argv[0] + ' ' - exit(1) - -file = str(argv[1]) -dir = str(argv[2]) -base_name = str(argv[3]) - -buffer = [] -xml_headers_counter = 0 -xml_headers_correction = 0 -xml_fragments_counter = 0 -search_mode = True -next_xml_invalid = False -buffer = [] - -with open (file, 'r') as f: - for l in f: - line = l - - if re.search('#SORT_START', line) or re.search('#SORT_END', line): - # Just skip these marks (they must not appear in the XML string) - continue - - if search_mode: - # Search mode is on: looking for a root element or for an 'invalid' - if re.search('<\?xml', line): - xml_headers_counter += 1 - elif re.search('User-Agent:', line): - # Heuristic: each time a User-Agent is detected, then a nofityContextRequest or notifyContextAvailabiltiyRequest - # if found in the .test file. These are fragments of code that comes from accumulator-script.py dumps, outside - # the usual "xmllint decoration" that adds the XML preamble in that case. Thus, we have to count then and apply as - # a correction factor in the warning generation - xml_headers_correction += 1 - elif re.search('#INVALID_XML', line): - next_xml_invalid = True - else: - m = re.match('\s*<(.*)>', line) - if m != None: - xml_fragments_counter += 1 - root_element = m.group(1) - - # Add XML header and root element as first elements of the buffer - buffer.append('\n') - buffer.append(line) - - search_mode = False - - else: - # Search mode is off: accumulate each line until the ending tag is found - # Note we remove any heading or trailing ' or ", that may occur in the - # case of using variables to store XMLs, e.g.: - # - # payload = ' - # - # '" - # ... - # "' - # ... - # ' - # - line = line.rstrip("'\"\n") - line = line.lstrip(" '\"") - - # We have found that strings like "http://localhost:'$CP1_PORT'/v1" that breaks validation, - # as they are not anyURI. In order to fix, we replace the "'$...'" part with a number - line = re.sub("'\$.*PORT.*'", "9999", line) - - # We have found that we cannot use things like 'REGEX((PT5S|PT7S))', given that - # duration uses type xs:duration, which has a predefined sytanx incompatible with REGEX(). Thus, we - # change these cases on the fly - if re.match('\s*', line): - line = re.sub("REGEX\(.*\)", "PT1M", line) - - # Similar case with providingApplication - if re.match('\s*', line): - line = re.sub("REGEX\(.*\)", "9997", line) - - buffer.append(line + "\n") - - if re.search('<\/'+ root_element + '>', line): - # We use some tokens in the filename to help xmlCheck.sh script - if tokens_map.has_key(root_element): - family = tokens_map[root_element][0] - vality = tokens_map[root_element][1] - else: - family = 'unknown' - vality = 'invalid' - - # No matter the result of the map, if the invalid mark was used in the .test, then - # file is alawys marked as 'invalid' - if next_xml_invalid: - vality = 'invalid' - - filename = dir + '/' + family + '.' + base_name + '.part_' + str(xml_fragments_counter) + '.' + vality + '.xml' - - write_fragment(buffer, filename) - buffer = [] - search_mode = True - next_xml_invalid = False - -if xml_headers_counter != xml_fragments_counter - xml_headers_correction: - print 'Warning in ' + base_name + ': XML headers (' + str(xml_headers_counter) + ', correction: ' + str(xml_headers_correction) + ') and ' \ - 'generated fragments (' + str(xml_fragments_counter) + ') differ'