├── .gitignore
├── LICENSE
├── README.md
├── app.js
├── ca-crt.pem
├── doc
├── Installation Guide Mobius_v2.0.0_EN_Linux.pdf
├── Installation Guide Mobius_v2.0.0_EN_Windows.pdf
├── Installation Guide Mobius_v2.5.12_KR_Linux.pdf
├── Installation Guide Mobius_v2.5.12_KR_MacOS.pdf
└── Installation Guide Mobius_v2.5.12_KR_Windows.pdf
├── mobius.js
├── mobius
├── acp.js
├── ae.js
├── asn.js
├── cb.js
├── cin.js
├── cnt.js
├── cnt_man.js
├── csr.js
├── db_action.js
├── fcnt.js
├── fopt.js
├── grp.js
├── lcp.js
├── mgo.js
├── mms.js
├── mn.js
├── mobiusdb.sql
├── nod.js
├── req.js
├── resource.js
├── responder.js
├── security.js
├── sgn.js
├── sgn_man.js
├── smd.js
├── sql_action.js
├── sub.js
├── tm.js
├── tr.js
├── ts.js
├── ts_agent.js
└── tsi.js
├── package.json
├── pxy_coap.js
├── pxy_mqtt.js
├── pxy_ws.js
├── server-crt.pem
├── server-key.pem
└── wdt.js
/.gitignore:
--------------------------------------------------------------------------------
1 | # Dependency directories
2 | .gitignore
3 | node_modules/
4 | .idea/
5 | log/
6 | doc/
7 | hit.json
8 | cbs_cache.json
9 | package-lock.json
10 | ss_ri_cache.json
11 | conf.json
12 | Mobius ����.drawio
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 3-Clause License
2 |
3 | Copyright (c) 2018, KETI
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | * Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | * Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | * Neither the name of the copyright holder nor the names of its
17 | contributors may be used to endorse or promote products derived from
18 | this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Mobius
2 | oneM2M IoT Server Platform
3 |
4 | ## Version
5 | 2.5.x (2.5.13)
6 |
7 | The next version of Mobius is available on [Mobius4](https://github.com/iotketi/mobius4).
8 |
9 | ## Introduction
10 | Mobius is the open source IoT server platform based on the oneM2M (http://www.oneM2M.org) standard. As oneM2M specifies, Mobius provides common services functions (e.g. registration, data management, subscription/notification, security) as middleware to IoT applications of different service domains. Not just oneM2M devices, but also non-oneM2M devices (i.e. by oneM2M interworking specifications and KETI TAS) can connect to Mobius.
11 |
12 | ## Certification
13 | Mobius has been received certification of ‘oneM2M standard’ by TTA (Telecommunications Technology Association). oneM2M Certification guarantees that oneM2M products meet oneM2M Specification and Test requirements which ensure interoperability. As Mobius is certified, it will be used as a golden sample to validate test cases and testing system.
14 |
15 |
16 |

17 |
18 |
19 | TRSL (Test Requirements Status List) is available on oneM2M certification website (http://www.onem2mcert.com/sub/sub05_01.php).
20 |
21 | ## System Stucture
22 | In oneM2M architecture, Mobius implements the IN-CSE which is the cloud server in the infrastructure domain. IoT applications communicate with field domain IoT gateways/devices via Mobius.
23 |
24 |
25 |

26 |
27 |
28 | ## Connectivity Stucture
29 | To enable Internet of Things, things are connected to &Cube via TAS (Thing Adaptation Software), then &Cube communicate with Mobius over oneM2M standard APIs. Also IoT applications use oneM2M standard APIs to retrieve thing data control things of Mobius.
30 |
31 |
32 |

33 |
34 |
35 | ## Software Architecture
36 |
37 |
38 |

39 |
40 |
41 | ## Supported Protocol Bindings
42 | - HTTP
43 | - CoAP
44 | - MQTT
45 | - WebSocket
46 |
47 | ## Installation
48 | The Mobius is based on Node.js framework and uses MySQL for database.
49 |
50 |

51 |
52 |
53 | - [MySQL Server](https://www.mysql.com/downloads/)
54 | The MySQL is an open source RDB database so that it is free and ligth. And RDB is very suitable for storing tree data just like oneM2M resource stucture. Most of nCube-Rosemary will work in a restricted hardware environment and the MySQL can work in most of embeded devices.
55 |
56 | - [Node.js](https://nodejs.org/en/)
57 | Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world. Node.js is very powerful in service impelementation because it provide a rich and free web service API. So, we use it to make RESTful API base on the oneM2M standard.
58 |
59 | - [Mosquitto](https://mosquitto.org/)
60 | Eclipse Mosquitto™ is an open source (EPL/EDL licensed) message broker that implements the MQTT protocol versions 3.1 and 3.1.1. MQTT provides a lightweight method of carrying out messaging using a publish/subscribe model. This makes it suitable for "Internet of Things" messaging such as with low power sensors or mobile devices such as phones, embedded computers or microcontrollers like the Arduino.
61 |
62 | - [Mobius](https://github.com/IoTKETI/Mobius/archive/master.zip)
63 | Mobius source codes are written in javascript. So they don't need any compilation or installation before running.
64 |
65 | ## Mobius Docker Version
66 | We deploy Mobius as a Docker image using the virtualization open source tool Docker.
67 |
68 | - [Mobius_Docker](https://github.com/IoTKETI/Mobius_Docker)
69 |
70 | ## Configuration
71 | - Import SQL script
72 | After installation of MySQL server, you need the DB Schema for storing oneM2M resources in Mobius. You can find this file in the following Mobius source directory.
73 | ```
74 | [Mobius home]/mobius/mobiusdb.sql
75 | ```
76 | - Run Mosquitto MQTT broker
77 | ```
78 | mosquitto -v
79 | ```
80 | - Open the Mobius source home directory
81 | - Install dependent libraries as below
82 | ```
83 | npm install
84 | ```
85 | - Modify the configuration file "conf.json" per your setting
86 | ```
87 | {
88 | "csebaseport": "7579", //Mobius HTTP hosting port
89 | "dbpass": "*******" //MySQL root password
90 | }
91 | ```
92 |
93 | ## Run
94 | Use node.js application execution command as below
95 | ```
96 | node mobius.js
97 | ```
98 |
99 |
100 |

101 |
102 |
103 | ## Library Dependencies
104 | This is the list of library dependencies for Mobius
105 | - body-parser
106 | - cbor
107 | - coap
108 | - crypto
109 | - events
110 | - express
111 | - file-stream-rotator
112 | - fs
113 | - http
114 | - https
115 | - ip
116 | - js2xmlparser
117 | - merge
118 | - morgan
119 | - mqtt
120 | - mysql
121 | - shortid
122 | - url
123 | - util
124 | - websocket
125 | - xml2js
126 | - xmlbuilder
127 |
128 | ## Document
129 | If you want more details please download the full [installation guide document](https://github.com/IoTKETI/Mobius/raw/master/doc/Installation%20Guide_Mobius_v2.0.0_EN(170718).pdf).
130 |
131 | # Author
132 | Jaeho Kim (jhkim@keti.re.kr)
133 | Il Yeup Ahn (iyahn@keti.re.kr)
134 |
--------------------------------------------------------------------------------
/ca-crt.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIFgDCCA2gCCQDHTc1v39XdDTANBgkqhkiG9w0BAQUFADCBgTELMAkGA1UEBhMC
3 | VVMxCzAJBgNVBAgTAk1BMQ8wDQYDVQQHEwZCb3N0b24xEzARBgNVBAoTCkV4YW1w
4 | bGUgQ28xEDAOBgNVBAsTB3RlY2hvcHMxCzAJBgNVBAMTAmNhMSAwHgYJKoZIhvcN
5 | AQkBFhFjZXJ0c0BleGFtcGxlLmNvbTAeFw0xNzAzMDkxNTA0NDJaFw00NDA3MjQx
6 | NTA0NDJaMIGBMQswCQYDVQQGEwJVUzELMAkGA1UECBMCTUExDzANBgNVBAcTBkJv
7 | c3RvbjETMBEGA1UEChMKRXhhbXBsZSBDbzEQMA4GA1UECxMHdGVjaG9wczELMAkG
8 | A1UEAxMCY2ExIDAeBgkqhkiG9w0BCQEWEWNlcnRzQGV4YW1wbGUuY29tMIICIjAN
9 | BgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAuZKaeXQTcaffq28HRA7QwVHIDp+b
10 | Khsbm40WLGbNjtTzH/AruNhL4o51DTxKLLgbOr74XM9txCcZDPJNfE7Hp2+Pmorq
11 | /sZpqzcdc0MWLCHgD9EyzI0CiQxTSt091qEd1YdAXt3QL3RJhjl8klMXfAScOwi/
12 | KqrEawYavmB99Tb8sTEDuOCVU1z/9Ms4ir3UzBw2cLgcYLhU0A2dT+v3ywvV5P1i
13 | 8OZu/i12L0o8J4MSZ7hZ0mhue8+S1W+PIcr9O2roo6yyDgJgfz6/m60yS4M+vW9n
14 | RnBvfc9ISUGB77pGIsTFUwphXGFzPfZ6VzJ2XCm6do8/lJSTD6qQmmSmFnEI2r3H
15 | Bv73Zg0rynFCGh5Pmgd32kAalg8DZ3VwlDueky0lX13MhnEUtY+PiYLWF7J/79zN
16 | zms2QLIy2KPiRihtdHJW81Avp+HdD/jGpfNDxVEGvwK+B9hpv2+i5/zlpXEl1O1/
17 | 3TVJy6Gpu1679ojvMWn7YREHn1NB/3eNMG3//pD8UPK8fmcwQ7mxDQKv97yh/YbE
18 | joekRv89NaDzFXOYjXOy33RAxvAfnTQSKM47ZInK307mHRtxNd0xucuOBBbvZkSC
19 | puuNRZxviEjefrDx2IcmochAjkQ5rEXOV9o7nKstilyqAHxr4YA48f7rQHKPW+/B
20 | p6o1GOAYXWIMqwMCAwEAATANBgkqhkiG9w0BAQUFAAOCAgEAekZR7uJdDjAY6hwE
21 | H24Fk+RWeInvu+HL+DVlH45LXXT48veVQzgE5gZZLfaajD0VMZOUf/+HbqPLK8v9
22 | X8IEYaGZYglsGHNYnI37AiZLa15KjHlJC4Q5KkTO8p4blaCk9LoMYr7nRolD5WLq
23 | GmsH62HigqD+eP3T8iPqqoU6NT++NKTF6+kRM5jVq3BRIT39a4LZ4BbMyusLf+Ly
24 | NUON/pGm2RJ1ZQD9igwMjt4MshoOgexIsjNhTWFxLoAdnjIM6ipjjWUleWPHSRpt
25 | D3uNd6yz+tHOHHXRbm3ELGwCqehNB0Hl+Uiv3SvK6P9HBMjYtguthHpcoifOhOzJ
26 | DbTrfSG2Egagv4F+7WjSxWAk9dVoSkVsksW/c50HlvSQuNtzzgX8MOzccQpciiRY
27 | lpuqQp1MXZNhmt5/FjnkBQ9dDzKSHzYppr7InEhQlCi3dDnI71lkOYLxH02LBorj
28 | GYuJCGZHo4lT9Q2gTQ7H+MxymeMwzFnMNoT05cW/S2V7N44aWypIplEqQqvRdLko
29 | CGGrfut2E0V1RvW60oPlS18mMz71X6Zv0UFJgIBfGUAdc6gRLXS6iZ7X+xNvgURo
30 | T6ZMwDnwazZ97ChPfkxmsCLT30T0cH7TAuaoIhQn8EAfFGoKZI6QhMEfHDbr6leR
31 | HaEJgd1pxHnI9ENgEnJBm7lwERg=
32 | -----END CERTIFICATE-----
33 |
--------------------------------------------------------------------------------
/doc/Installation Guide Mobius_v2.0.0_EN_Linux.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IoTKETI/Mobius/65ca7b40a8c43ec0ab3abaf237ba1035ac53a5f4/doc/Installation Guide Mobius_v2.0.0_EN_Linux.pdf
--------------------------------------------------------------------------------
/doc/Installation Guide Mobius_v2.0.0_EN_Windows.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IoTKETI/Mobius/65ca7b40a8c43ec0ab3abaf237ba1035ac53a5f4/doc/Installation Guide Mobius_v2.0.0_EN_Windows.pdf
--------------------------------------------------------------------------------
/doc/Installation Guide Mobius_v2.5.12_KR_Linux.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IoTKETI/Mobius/65ca7b40a8c43ec0ab3abaf237ba1035ac53a5f4/doc/Installation Guide Mobius_v2.5.12_KR_Linux.pdf
--------------------------------------------------------------------------------
/doc/Installation Guide Mobius_v2.5.12_KR_MacOS.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IoTKETI/Mobius/65ca7b40a8c43ec0ab3abaf237ba1035ac53a5f4/doc/Installation Guide Mobius_v2.5.12_KR_MacOS.pdf
--------------------------------------------------------------------------------
/doc/Installation Guide Mobius_v2.5.12_KR_Windows.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IoTKETI/Mobius/65ca7b40a8c43ec0ab3abaf237ba1035ac53a5f4/doc/Installation Guide Mobius_v2.5.12_KR_Windows.pdf
--------------------------------------------------------------------------------
/mobius.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2018, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file
13 | * @copyright KETI Korea 2018, KETI
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | */
16 |
17 | var fs = require('fs');
18 |
19 | var conf = {};
20 | try {
21 | conf = JSON.parse(fs.readFileSync('conf.json', 'utf8'));
22 | }
23 | catch (e) {
24 | conf.csebaseport = "7579";
25 | conf.dbpass = "dksdlfduq2";
26 | fs.writeFileSync('conf.json', JSON.stringify(conf, null, 4), 'utf8');
27 | }
28 |
29 | global.defaultbodytype = 'json';
30 |
31 | // my CSE information
32 | global.usecsetype = 'in'; // select 'in' or 'mn' or asn'
33 | global.usecsebase = 'Mobius';
34 | global.usecseid = '/Mobius2';
35 | global.usecsebaseport = conf.csebaseport;
36 |
37 | global.usedbhost = 'localhost';
38 | global.usedbpass = conf.dbpass;
39 |
40 |
41 | global.usepxywsport = '7577';
42 | global.usepxymqttport = '7578';
43 |
44 | global.use_sgn_man_port = '7599';
45 | global.use_cnt_man_port = '7583';
46 | global.use_hit_man_port = '7594';
47 |
48 | global.usetsagentport = '7582';
49 |
50 | global.use_mqtt_broker = 'localhost'; // mqttbroker for mobius
51 |
52 | global.use_secure = 'disable';
53 | global.use_mqtt_port = '1883';
54 | if(use_secure === 'enable') {
55 | use_mqtt_port = '8883';
56 | }
57 |
58 | global.useaccesscontrolpolicy = 'disable';
59 |
60 | global.wdt = require('./wdt');
61 |
62 |
63 | global.allowed_ae_ids = [];
64 | //allowed_ae_ids.push('ryeubi');
65 |
66 | global.allowed_app_ids = [];
67 | //allowed_app_ids.push('APP01');
68 |
69 | global.usesemanticbroker = '10.10.202.114';
70 |
71 | global.uservi = '2a';
72 |
73 | global.useCert = 'disable';
74 |
75 | // CSE core
76 | require('./app');
77 |
--------------------------------------------------------------------------------
/mobius/acp.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2018, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file
13 | * @copyright KETI Korea 2018, KETI
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | */
16 |
17 | var url = require('url');
18 | var xml2js = require('xml2js');
19 | var xmlbuilder = require('xmlbuilder');
20 | var util = require('util');
21 | var responder = require('./responder');
22 |
23 |
24 | exports.build_acp = function(request, response, resource_Obj, body_Obj, callback) {
25 | var rootnm = request.headers.rootnm;
26 |
27 | // body
28 | //body_Obj[rootnm].pv.acr[body_Obj[rootnm].pv.acr.length] = {acor:['Superman'], acop:'63'};
29 | //body_Obj[rootnm].pvs.acr[body_Obj[rootnm].pvs.acr.length] = {acor:['Superman'], acop:'63'};
30 | resource_Obj[rootnm].pv = body_Obj[rootnm].pv;
31 | resource_Obj[rootnm].pvs = body_Obj[rootnm].pvs;
32 |
33 | request.resourceObj = JSON.parse(JSON.stringify(resource_Obj));
34 | resource_Obj = null;
35 |
36 | callback('200');
37 | };
38 |
39 |
40 |
41 | // exports.modify_acp = function(request, response, resource_Obj, body_Obj, callback) {
42 | // var rootnm = request.headers.rootnm;
43 | //
44 | // // check M
45 | // for (var attr in update_m_attr_list[rootnm]) {
46 | // if (update_m_attr_list[rootnm].hasOwnProperty(attr)) {
47 | // if (body_Obj[rootnm].includes(attr)) {
48 | // }
49 | // else {
50 | // body_Obj = {};
51 | // body_Obj['dbg'] = 'BAD REQUEST: ' + attr + ' is \'Mandatory\' attribute';
52 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
53 | // callback('0', resource_Obj);
54 | // return '0';
55 | // }
56 | // }
57 | // }
58 | //
59 | // // check NP and body
60 | // for (attr in body_Obj[rootnm]) {
61 | // if (body_Obj[rootnm].hasOwnProperty(attr)) {
62 | // if (update_np_attr_list[rootnm].includes(attr)) {
63 | // body_Obj = {};
64 | // body_Obj['dbg'] = 'BAD REQUEST: ' + attr + ' is \'Not Present\' attribute';
65 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
66 | // callback('0', resource_Obj);
67 | // return '0';
68 | // }
69 | // else {
70 | // if (update_opt_attr_list[rootnm].includes(attr)) {
71 | // }
72 | // else {
73 | // body_Obj = {};
74 | // body_Obj['dbg'] = 'NOT FOUND: ' + attr + ' attribute is not defined';
75 | // responder.response_result(request, response, 404, body_Obj, 4004, request.url, body_Obj['dbg']);
76 | // callback('0', resource_Obj);
77 | // return '0';
78 | // }
79 | // }
80 | // }
81 | // }
82 | //
83 | // update_body(rootnm, body_Obj, resource_Obj); // (attr == 'aa' || attr == 'poa' || attr == 'lbl' || attr == 'acpi' || attr == 'srt' || attr == 'nu' || attr == 'mid' || attr == 'macp')
84 | //
85 | // resource_Obj[rootnm].st = (parseInt(resource_Obj[rootnm].st, 10) + 1).toString();
86 | //
87 | // if(body_Obj[rootnm].pv) {
88 | // body_Obj[rootnm].pv.acr[body_Obj[rootnm].pv.acr.length] = {acor:[usecseid], acop:'63'};
89 | // resource_Obj[rootnm].pv = body_Obj[rootnm].pv;
90 | // }
91 | //
92 | // if(body_Obj[rootnm].pvs) {
93 | // body_Obj[rootnm].pvs.acr[body_Obj[rootnm].pvs.acr.length] = {acor:[usecseid], acop:'63'};
94 | // resource_Obj[rootnm].pvs = body_Obj[rootnm].pvs;
95 | // }
96 | //
97 | // var cur_d = new Date();
98 | // resource_Obj[rootnm].lt = cur_d.toISOString().replace(/-/, '').replace(/-/, '').replace(/:/, '').replace(/:/, '').replace(/\..+/, '');
99 | //
100 | // if (resource_Obj[rootnm].et != '') {
101 | // if (resource_Obj[rootnm].et < resource_Obj[rootnm].ct) {
102 | // body_Obj = {};
103 | //
104 | // body_Obj['dbg'] = 'expiration time is before now';
105 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
106 | // callback('0', resource_Obj);
107 | // return '0';
108 | // }
109 | // }
110 | //
111 | // callback('1', resource_Obj);
112 | // };
113 |
114 |
--------------------------------------------------------------------------------
/mobius/ae.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2018, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file
13 | * @copyright KETI Korea 2018, KETI
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | */
16 |
17 | var url = require('url');
18 | var xml2js = require('xml2js');
19 | var xmlbuilder = require('xmlbuilder');
20 | var moment = require('moment');
21 | var util = require('util');
22 | var merge = require('merge');
23 |
24 | var responder = require('./responder');
25 |
26 | exports.build_ae = function(request, response, resource_Obj, body_Obj, callback) {
27 | var rootnm = request.headers.rootnm;
28 |
29 | // body
30 | resource_Obj[rootnm].apn = (body_Obj[rootnm].apn) ? body_Obj[rootnm].apn : '';
31 | resource_Obj[rootnm].poa = (body_Obj[rootnm].poa) ? body_Obj[rootnm].poa : [];
32 | resource_Obj[rootnm].or = (body_Obj[rootnm].or) ? body_Obj[rootnm].or : '';
33 | resource_Obj[rootnm].csz = (body_Obj[rootnm].csz) ? body_Obj[rootnm].csz : '';
34 | resource_Obj[rootnm].srv = (body_Obj[rootnm].srv) ? body_Obj[rootnm].srv : '';
35 |
36 | if( (request.headers['x-m2m-origin'] == 'S') ) {
37 | resource_Obj[rootnm].aei = 'S' + require('shortid').generate();
38 | }
39 | else if( (request.headers['x-m2m-origin'] == 'C') ) {
40 | resource_Obj[rootnm].aei = 'C' + require('shortid').generate();
41 | }
42 | else {
43 | resource_Obj[rootnm].aei = request.headers['x-m2m-origin'];
44 | }
45 |
46 | resource_Obj[rootnm].nl = '';
47 |
48 | request.resourceObj = JSON.parse(JSON.stringify(resource_Obj));
49 | resource_Obj = null;
50 |
51 | callback('200');
52 | };
53 |
54 |
55 |
56 | // exports.modify_ae = function(request, response, resource_Obj, body_Obj, callback) {
57 | // var rootnm = request.headers.rootnm;
58 | //
59 | // // check M
60 | // for (var attr in update_m_attr_list[rootnm]) {
61 | // if (update_m_attr_list[rootnm].hasOwnProperty(attr)) {
62 | // if (body_Obj[rootnm].includes(attr)) {
63 | // }
64 | // else {
65 | // body_Obj = {};
66 | // body_Obj['dbg'] = 'BAD REQUEST: ' + attr + ' is \'Mandatory\' attribute';
67 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
68 | // callback('0', resource_Obj);
69 | // return '0';
70 | // }
71 | // }
72 | // }
73 | //
74 | // // check NP and body
75 | // for (attr in body_Obj[rootnm]) {
76 | // if (body_Obj[rootnm].hasOwnProperty(attr)) {
77 | // if (update_np_attr_list[rootnm].includes(attr)) {
78 | // body_Obj = {};
79 | // body_Obj['dbg'] = 'BAD REQUEST: ' + attr + ' is \'Not Present\' attribute';
80 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
81 | // callback('0', resource_Obj);
82 | // return '0';
83 | // }
84 | // else {
85 | // if (update_opt_attr_list[rootnm].includes(attr)) {
86 | // }
87 | // else {
88 | // body_Obj = {};
89 | // body_Obj['dbg'] = 'NOT FOUND: ' + attr + ' attribute is not defined';
90 | // responder.response_result(request, response, 404, body_Obj, 4004, request.url, body_Obj['dbg']);
91 | // callback('0', resource_Obj);
92 | // return '0';
93 | // }
94 | // }
95 | // }
96 | // }
97 | //
98 | // update_body(rootnm, body_Obj, resource_Obj); // (attr == 'aa' || attr == 'poa' || attr == 'lbl' || attr == 'acpi' || attr == 'srt' || attr == 'nu' || attr == 'mid' || attr == 'macp')
99 | //
100 | // resource_Obj[rootnm].st = (parseInt(resource_Obj[rootnm].st, 10) + 1).toString();
101 | //
102 | // var cur_d = new Date();
103 | // resource_Obj[rootnm].lt = cur_d.toISOString().replace(/-/, '').replace(/-/, '').replace(/:/, '').replace(/:/, '').replace(/\..+/, '');
104 | //
105 | // if(body_Obj[rootnm].et == '') {
106 | // if (body_Obj[rootnm].et < resource_Obj[rootnm].ct) {
107 | // body_Obj = {};
108 | // body_Obj['dbg'] = 'expiration time is before now';
109 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
110 | // callback('0', resource_Obj);
111 | // return '0';
112 | // }
113 | // }
114 | //
115 | // callback('1', resource_Obj);
116 | // };
117 |
118 |
--------------------------------------------------------------------------------
/mobius/cb.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2018, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file
13 | * @copyright KETI Korea 2018, KETI
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | */
16 |
17 | var xml2js = require('xml2js');
18 | var xmlbuilder = require('xmlbuilder');
19 | var util = require('util');
20 | var ip = require('ip');
21 | var http = require('http');
22 | var merge = require('merge');
23 | var moment = require('moment');
24 |
25 | var db_sql = require('./sql_action');
26 |
27 | function cb_create_action(connection, callback) {
28 | var rootnm = 'cb';
29 | var rspObj = {};
30 | var resource_Obj = {};
31 | resource_Obj[rootnm] = {};
32 |
33 | var cur_d = new Date();
34 |
35 | resource_Obj[rootnm].ty = '5';
36 | resource_Obj[rootnm].rn = usecsebase;
37 | resource_Obj[rootnm].pi = '';
38 | resource_Obj[rootnm].ri = resource_Obj[rootnm].pi + '/' + resource_Obj[rootnm].rn;
39 | resource_Obj[rootnm].ct = moment().utc().format('YYYYMMDDTHHmmss');
40 | resource_Obj[rootnm].lt = resource_Obj[rootnm].ct;
41 | resource_Obj[rootnm].et = moment().utc().add(10, 'years').format('YYYYMMDDTHHmmss');
42 | resource_Obj[rootnm].acpi = [];
43 | resource_Obj[rootnm].lbl = [];
44 | resource_Obj[rootnm].lbl[0] = resource_Obj[rootnm].rn;
45 | resource_Obj[rootnm].at = [];
46 | resource_Obj[rootnm].aa = [];
47 | resource_Obj[rootnm].st = '0';
48 | resource_Obj[rootnm].srv = [];
49 | resource_Obj[rootnm].subl = [];
50 |
51 | resource_Obj[rootnm].srv.push('1');
52 | resource_Obj[rootnm].srv.push('2');
53 | resource_Obj[rootnm].srv.push('2a');
54 |
55 | resource_Obj[rootnm].csi = usecseid;
56 |
57 | //resource_Obj[rootnm].srt = ty_list;
58 | resource_Obj[rootnm].srt = ['1', '2', '3', '4', '5', '9', '10', '13', '14', '16', '17', '23'];
59 |
60 | resource_Obj[rootnm].poa = [];
61 | resource_Obj[rootnm].poa.push('http://' + ip.address() + ':' + usecsebaseport);
62 | // resource_Obj[rootnm].poa.push('mqtt://' + ip.address() + ':' + use_mqtt_port + '/' + resource_Obj[rootnm].csi.replace('/', ''));
63 | // resource_Obj[rootnm].poa.push('coap://' + ip.address() + ':' + usecsebaseport);
64 | // resource_Obj[rootnm].poa.push('ws://' + ip.address() + ':' + usepxywsport);
65 |
66 | resource_Obj[rootnm].nl = '';
67 | resource_Obj[rootnm].ncp = '';
68 | resource_Obj[rootnm].cst = '1';
69 |
70 | db_sql.select_ri_lookup(connection, resource_Obj[rootnm].ri, function (err, results_ri) {
71 | if(!err) {
72 | if(results_ri.length == 1) {
73 | db_sql.update_cb_poa_csi(connection, JSON.stringify(resource_Obj[rootnm].poa), resource_Obj[rootnm].csi, JSON.stringify(resource_Obj[rootnm].srt), resource_Obj[rootnm].ri, function (err, results) {
74 | if (!err) {
75 | usecseid = resource_Obj[rootnm].csi;
76 | rspObj.rsc = '2004';
77 | rspObj.ri = resource_Obj[rootnm].ri;
78 | rspObj = '';
79 | callback(rspObj);
80 | }
81 | else {
82 | rspObj.rsc = '5000';
83 | rspObj.ri = resource_Obj[rootnm].ri;
84 | rspObj = results.message;
85 | callback(rspObj);
86 | }
87 | });
88 | }
89 | else {
90 | // db_sql.get_sri_sri(connection, resource_Obj[rootnm].pi, function (err, results) {
91 | // if (!err) {
92 | resource_Obj[rootnm].spi = '';
93 | //resource_Obj[rootnm].sri = require('shortid').generate();
94 | resource_Obj[rootnm].sri = '5-' + moment().utc().format('YYYYMMDDHHmmssSSS') + (Math.random() * 999).toFixed(0).padStart(3, '0');
95 | db_sql.insert_cb(connection, resource_Obj[rootnm], function (err, results) {
96 | if (!err) {
97 | rspObj.rsc = '2001';
98 | rspObj.ri = resource_Obj[rootnm].ri;
99 | rspObj = '';
100 | }
101 | else {
102 | rspObj.rsc = '5000';
103 | rspObj.ri = resource_Obj[rootnm].ri;
104 | rspObj = results.message;
105 | }
106 | callback(rspObj);
107 | });
108 | // }
109 | // });
110 | }
111 | }
112 | else {
113 | rspObj.rsc = '5000';
114 | rspObj.ri = resource_Obj[rootnm].ri;
115 | rspObj = results_ri.message;
116 | callback(rspObj);
117 | }
118 | });
119 | }
120 |
121 | exports.create = function(connection, callback) {
122 | db_sql.set_hit(connection, '', function (err, results) {
123 | cb_create_action(connection, function(rspObj) {
124 | callback(rspObj);
125 | });
126 | });
127 |
128 |
129 | };
130 |
131 |
--------------------------------------------------------------------------------
/mobius/cin.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2018, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file
13 | * @copyright KETI Korea 2018, KETI
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | */
16 |
17 | var url = require('url');
18 | var xml2js = require('xml2js');
19 | var xmlbuilder = require('xmlbuilder');
20 | var util = require('util');
21 | var responder = require('./responder');
22 |
23 | //var _this = this;
24 |
25 |
26 |
27 | exports.build_cin = function(request, response, resource_Obj, body_Obj, callback) {
28 | var rootnm = request.headers.rootnm;
29 |
30 | // body
31 | if(body_Obj[rootnm].con.hasOwnProperty('$')) {
32 | resource_Obj[rootnm].con = body_Obj[rootnm].con['_'];
33 | }
34 | else {
35 | resource_Obj[rootnm].con = body_Obj[rootnm].con;
36 | }
37 | /*if (Array.isArray(body_Obj[rootnm].con)) {
38 | return 'array';
39 | }
40 | else if (typeof body_Obj[rootnm].con == 'string') {
41 | return 'string';
42 | }
43 | else if (body_Obj[rootnm].con != null && typeof body_Obj[rootnm].con == 'object') {
44 | if(body_Obj[rootnm].con['$'] != null) {
45 |
46 | }
47 | else {
48 | resource_Obj[rootnm].con = body_Obj[rootnm].con;
49 | }
50 | }
51 | else {
52 | return 'other';
53 | }*/
54 |
55 | var con_type = getType(resource_Obj[rootnm].con);
56 | if(con_type == 'string') {
57 | resource_Obj[rootnm].cs = Buffer.byteLength(resource_Obj[rootnm].con, 'utf8').toString();
58 |
59 | if(request.headers.hasOwnProperty('mbs')) {
60 | if(parseInt(request.headers.mbs) < parseInt(resource_Obj[rootnm].cs)) {
61 | callback('406-3');
62 | return;
63 | }
64 | }
65 | }
66 | else {
67 | if (con_type === 'string_object') {
68 | try {
69 | resource_Obj[rootnm].con = JSON.parse(resource_Obj[rootnm].con);
70 | }
71 | catch (e) {
72 | }
73 | }
74 | resource_Obj[rootnm].cs = Buffer.byteLength(JSON.stringify(resource_Obj[rootnm].con), 'utf8').toString();
75 | }
76 |
77 | resource_Obj[rootnm].cnf = (body_Obj[rootnm].cnf) ? body_Obj[rootnm].cnf : '';
78 | if(resource_Obj[rootnm].cnf != '') {
79 | if (resource_Obj[rootnm].cnf.split(':')[0] == '') {
80 | callback('400-32');
81 | return;
82 | }
83 | }
84 |
85 | resource_Obj[rootnm].or = (body_Obj[rootnm].or) ? body_Obj[rootnm].or : '';
86 | resource_Obj[rootnm].cr = (body_Obj[rootnm].cr) ? body_Obj[rootnm].cr : request.headers['x-m2m-origin'];
87 |
88 | request.resourceObj = JSON.parse(JSON.stringify(resource_Obj));
89 | resource_Obj = null;
90 |
91 | callback('200');
92 | };
93 |
--------------------------------------------------------------------------------
/mobius/cnt.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2018, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file
13 | * @copyright KETI Korea 2018, KETI
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | */
16 |
17 | var url = require('url');
18 | var xml2js = require('xml2js');
19 | var xmlbuilder = require('xmlbuilder');
20 | var util = require('util');
21 | var responder = require('./responder');
22 |
23 |
24 | exports.build_cnt = function(request, response, resource_Obj, body_Obj, callback) {
25 | var rootnm = request.headers.rootnm;
26 |
27 | // body
28 | resource_Obj[rootnm].disr = (body_Obj[rootnm].disr) ? body_Obj[rootnm].disr : '';
29 | resource_Obj[rootnm].mni = (body_Obj[rootnm].mni) ? body_Obj[rootnm].mni : '3153600000';
30 | if(parseInt(resource_Obj[rootnm].mni) >= 3153600000) {
31 | resource_Obj[rootnm].mni = '3153600000';
32 | }
33 |
34 | resource_Obj[rootnm].mbs = (body_Obj[rootnm].mbs) ? body_Obj[rootnm].mbs : '3153600000';
35 | resource_Obj[rootnm].mia = (body_Obj[rootnm].mia) ? body_Obj[rootnm].mia : '31536000';
36 |
37 | if(parseInt(resource_Obj[rootnm].mni) < 0) { // clsase 7.4.6.2.1 TS-0004
38 | callback('400-29');
39 | return;
40 | }
41 |
42 | if(parseInt(resource_Obj[rootnm].mbs) < 0) { // clsase 7.4.6.2.1 TS-0004
43 | callback('400-30');
44 | return;
45 | }
46 |
47 | if(parseInt(resource_Obj[rootnm].mia) < 0) { // clsase 7.4.6.2.1 TS-0004
48 | callback('400-31');
49 | return;
50 | }
51 |
52 | resource_Obj[rootnm].li = (body_Obj[rootnm].li) ? body_Obj[rootnm].li : '';
53 | resource_Obj[rootnm].or = (body_Obj[rootnm].or) ? body_Obj[rootnm].or : '';
54 | resource_Obj[rootnm].cr = (body_Obj[rootnm].cr) ? body_Obj[rootnm].cr : request.headers['x-m2m-origin'];
55 |
56 | resource_Obj[rootnm].cni = 0;
57 | resource_Obj[rootnm].cbs = 0;
58 |
59 | request.resourceObj = JSON.parse(JSON.stringify(resource_Obj));
60 | resource_Obj = null;
61 |
62 | callback('200');
63 | };
64 |
65 |
66 |
67 | // exports.modify_cnt = function(request, response, resource_Obj, body_Obj, callback) {
68 | // var rootnm = request.headers.rootnm;
69 | //
70 | // // check M
71 | // for (var attr in update_m_attr_list[rootnm]) {
72 | // if (update_m_attr_list[rootnm].hasOwnProperty(attr)) {
73 | // if (body_Obj[rootnm].includes(attr)) {
74 | // }
75 | // else {
76 | // body_Obj = {};
77 | // body_Obj['dbg'] = 'BAD REQUEST: ' + attr + ' is \'Mandatory\' attribute';
78 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
79 | // callback('0', resource_Obj);
80 | // return '0';
81 | // }
82 | // }
83 | // }
84 | //
85 | // // check NP and body
86 | // for (attr in body_Obj[rootnm]) {
87 | // if (body_Obj[rootnm].hasOwnProperty(attr)) {
88 | // if (update_np_attr_list[rootnm].includes(attr)) {
89 | // body_Obj = {};
90 | // body_Obj['dbg'] = 'BAD REQUEST: ' + attr + ' is \'Not Present\' attribute';
91 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
92 | // callback('0', resource_Obj);
93 | // return '0';
94 | // }
95 | // else {
96 | // if (update_opt_attr_list[rootnm].includes(attr)) {
97 | // }
98 | // else {
99 | // body_Obj = {};
100 | // body_Obj['dbg'] = 'NOT FOUND: ' + attr + ' attribute is not defined';
101 | // responder.response_result(request, response, 404, body_Obj, 4004, request.url, body_Obj['dbg']);
102 | // callback('0', resource_Obj);
103 | // return '0';
104 | // }
105 | // }
106 | // }
107 | // }
108 | //
109 | // update_body(rootnm, body_Obj, resource_Obj);
110 | //
111 | // resource_Obj[rootnm].st = (parseInt(resource_Obj[rootnm].st, 10) + 1).toString();
112 | //
113 | //
114 | // if(body_Obj[rootnm].mni) {
115 | // resource_Obj[rootnm].mni = body_Obj[rootnm].mni;
116 | // if(parseInt(resource_Obj[rootnm].mni) >= 3153600000) {
117 | // resource_Obj[rootnm].mni = '3153600000';
118 | // }
119 | // }
120 | //
121 | // var cur_d = new Date();
122 | // resource_Obj[rootnm].lt = cur_d.toISOString().replace(/-/, '').replace(/-/, '').replace(/:/, '').replace(/:/, '').replace(/\..+/, '');
123 | //
124 | // if (resource_Obj[rootnm].et != '') {
125 | // if (resource_Obj[rootnm].et < resource_Obj[rootnm].ct) {
126 | // body_Obj = {};
127 | // body_Obj['dbg'] = 'expiration time is before now';
128 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
129 | // callback('0', resource_Obj);
130 | // return '0';
131 | // }
132 | // }
133 | //
134 | // callback('1', resource_Obj);
135 | // };
136 | //
137 |
--------------------------------------------------------------------------------
/mobius/cnt_man.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2019, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file
13 | * @copyright KETI Korea 2019, KETI
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | * @date 2019.06.14
16 | */
17 |
18 | var fs = require('fs');
19 | var http = require('http');
20 | var https = require('https');
21 | var express = require('express');
22 | var bodyParser = require('body-parser');
23 | var ip = require("ip");
24 |
25 | var db_sql = require('./sql_action');
26 | //
27 | // global.NOPRINT = 'true';
28 | //
29 | // var cnt_app = express();
30 | //
31 | // var cnt_server = null;
32 | //
33 | // if(cnt_server == null) {
34 | // if(use_secure === 'disable') {
35 | // http.globalAgent.maxSockets = 10000;
36 | // cnt_server = http.createServer(cnt_app);
37 | // }
38 | // else {
39 | // var options = {
40 | // key: fs.readFileSync('server-key.pem'),
41 | // cert: fs.readFileSync('server-crt.pem'),
42 | // ca: fs.readFileSync('ca-crt.pem')
43 | // };
44 | // https.globalAgent.maxSockets = 10000;
45 | // cnt_server = https.createServer(options, cnt_app);
46 | // }
47 | //
48 | // cnt_server.listen({port: use_cnt_man_port, agent: false}, function () {
49 | // console.log('cnt_man server (' + ip.address() + ') running at ' + use_cnt_man_port + ' port');
50 | // });
51 | //
52 | // cnt_server.on('connection', function (socket) {
53 | // //console.log("A new connection was made by a client.");
54 | // // socket.setTimeout(5000, function () {
55 | // // if(socket.hasOwnProperty('_httpMessage')) {
56 | // // if (socket._httpMessage.hasOwnProperty('req')) {
57 | // // if (ss_fail_count.hasOwnProperty(socket._httpMessage.req.headers.ri)) {
58 | // // ss_fail_count[socket._httpMessage.req.headers.ri]++;
59 | // // }
60 | // // }
61 | // // }
62 | // // });
63 | // });
64 | // }
65 | //
66 | // // for updating container
67 | // var onem2mParser = bodyParser.text(
68 | // {
69 | // limit: '1mb',
70 | // type: 'application/onem2m-resource+xml;application/xml;application/json;application/vnd.onem2m-res+xml;application/vnd.onem2m-res+json'
71 | // }
72 | // );
73 | //
74 | // cnt_app.put('/cnt', onem2mParser, function(request, response, next) {
75 | // var fullBody = '';
76 | // request.on('data', function(chunk) {
77 | // fullBody += chunk.toString();
78 | // });
79 | // request.on('end', function() {
80 | // request.body = fullBody;
81 | //
82 | // var resource_Obj = JSON.parse(request.body);
83 | // setTimeout(updateAction, 0, resource_Obj);
84 | // response.status(200).end();
85 | // });
86 | // });
87 |
88 | exports.put = function(connection, bodyString) {
89 | var resource_Obj = JSON.parse(bodyString);
90 | setTimeout((connection, resource_Obj) => {
91 | var rootnm = Object.keys(resource_Obj)[0];
92 | db_sql.get_cni_count(connection, resource_Obj[rootnm], (cni, cbs, st) => {
93 | var resBody = {};
94 | resBody[resource_Obj[rootnm].ri] = {
95 | cni: cni,
96 | cbs: cbs,
97 | st: st
98 | };
99 | console.log(resBody);
100 | resource_Obj = null;
101 | resBody = null;
102 | });
103 | }, 0, connection, resource_Obj);
104 | };
105 | //
106 | // function updateAction(connection, resource_Obj) {
107 | // var rootnm = Object.keys(resource_Obj)[0];
108 | // db_sql.get_cni_count(connection, resource_Obj[rootnm], function (cni, cbs, st) {
109 | // var resBody = {};
110 | // resBody[resource_Obj[rootnm].ri] = {
111 | // cni: cni,
112 | // cbs: cbs,
113 | // st: st
114 | // };
115 | // console.log(resBody);
116 | // delete resource_Obj;
117 | // resource_Obj = null;
118 | // delete resBody;
119 | // resBody = null;
120 | // });
121 | //
122 | // }
123 |
--------------------------------------------------------------------------------
/mobius/csr.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2018, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file
13 | * @copyright KETI Korea 2018, KETI
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | */
16 |
17 | var url = require('url');
18 | var xml2js = require('xml2js');
19 | var xmlbuilder = require('xmlbuilder');
20 | var util = require('util');
21 | var responder = require('./responder');
22 |
23 |
24 | exports.build_csr = function(request, response, resource_Obj, body_Obj, callback) {
25 | var rootnm = request.headers.rootnm;
26 |
27 | // body
28 | resource_Obj[rootnm].cb = body_Obj[rootnm].cb;
29 | resource_Obj[rootnm].csi = body_Obj[rootnm].csi;
30 | resource_Obj[rootnm].rr = body_Obj[rootnm].rr;
31 |
32 | resource_Obj[rootnm].cst = (body_Obj[rootnm].cst) ? body_Obj[rootnm].cst : '1';
33 | resource_Obj[rootnm].poa = (body_Obj[rootnm].poa) ? body_Obj[rootnm].poa : [];
34 | resource_Obj[rootnm].mei = (body_Obj[rootnm].mei) ? body_Obj[rootnm].mei : '';
35 | resource_Obj[rootnm].tri = (body_Obj[rootnm].tri) ? body_Obj[rootnm].tri : '';
36 | resource_Obj[rootnm].nl = (body_Obj[rootnm].nl) ? body_Obj[rootnm].nl : '';
37 | resource_Obj[rootnm].srv = (body_Obj[rootnm].srv) ? body_Obj[rootnm].srv : '';
38 |
39 | request.resourceObj = JSON.parse(JSON.stringify(resource_Obj));
40 | resource_Obj = null;
41 |
42 | callback('200');
43 | };
44 |
45 |
46 |
47 | // exports.modify_csr = function(request, response, resource_Obj, body_Obj, callback) {
48 | // var rootnm = request.headers.rootnm;
49 | //
50 | // // check M
51 | // for (var attr in update_m_attr_list[rootnm]) {
52 | // if (update_m_attr_list[rootnm].hasOwnProperty(attr)) {
53 | // if (body_Obj[rootnm].includes(attr)) {
54 | // }
55 | // else {
56 | // body_Obj = {};
57 | // body_Obj['dbg'] = 'BAD REQUEST: ' + attr + ' is \'Mandatory\' attribute';
58 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
59 | // callback('0', resource_Obj);
60 | // return '0';
61 | // }
62 | // }
63 | // }
64 | //
65 | // // check NP and body
66 | // for (attr in body_Obj[rootnm]) {
67 | // if (body_Obj[rootnm].hasOwnProperty(attr)) {
68 | // if (update_np_attr_list[rootnm].includes(attr)) {
69 | // body_Obj = {};
70 | // body_Obj['dbg'] = 'BAD REQUEST: ' + attr + ' is \'Not Present\' attribute';
71 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
72 | // callback('0', resource_Obj);
73 | // return '0';
74 | // }
75 | // e lse {
76 | // if (update_opt_attr_list[rootnm].includes(attr)) {
77 | // }
78 | // else {
79 | // body_Obj = {};
80 | // body_Obj['dbg'] = 'NOT FOUND: ' + attr + ' attribute is not defined';
81 | // responder.response_result(request, response, 404, body_Obj, 4004, request.url, body_Obj['dbg']);
82 | // callback('0', resource_Obj);
83 | // return '0';
84 | // }
85 | // }
86 | // }
87 | // }
88 | //
89 | // update_body(rootnm, body_Obj, resource_Obj); // (attr == 'aa' || attr == 'poa' || attr == 'lbl' || attr == 'acpi' || attr == 'srt' || attr == 'nu' || attr == 'mid' || attr == 'macp')
90 | //
91 | // resource_Obj[rootnm].st = (parseInt(resource_Obj[rootnm].st, 10) + 1).toString();
92 | //
93 | // var cur_d = new Date();
94 | // resource_Obj[rootnm].lt = cur_d.toISOString().replace(/-/, '').replace(/-/, '').replace(/:/, '').replace(/:/, '').replace(/\..+/, '');
95 | //
96 | // if (resource_Obj[rootnm].et != '') {
97 | // if (resource_Obj[rootnm].et < resource_Obj[rootnm].ct) {
98 | // body_Obj = {};
99 | // body_Obj['dbg'] = 'expiration time is before now';
100 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
101 | // callback('0', resource_Obj);
102 | // return '0';
103 | // }
104 | // }
105 | //
106 | // callback('1', resource_Obj);
107 | // };
108 |
109 |
--------------------------------------------------------------------------------
/mobius/db_action.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2018, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file
13 | * @copyright KETI Korea 2018, KETI
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | */
16 |
17 | var mysql = require('mysql');
18 |
19 | var mysql_pool = null;
20 |
21 | //var _this = this;
22 |
23 |
24 | exports.connect = function (host, port, user, password, callback) {
25 | mysql_pool = mysql.createPool({
26 | host: host,
27 | port: port,
28 | user: user,
29 | password: password,
30 | database: 'mobiusdb',
31 | connectionLimit: 100,
32 | waitForConnections: true,
33 | debug: false,
34 | acquireTimeout: 50000,
35 | queueLimit: 0
36 | });
37 |
38 | callback('1');
39 | };
40 |
41 |
42 | // function executeQuery(pool, query, callback) {
43 | // pool.getConnection(function (err, connection) {
44 | // if (err) {
45 | // return callback(err, null);
46 | // }
47 | // else if (connection) {
48 | // connection.query({sql:query, timeout:60000}, function (err, rows, fields) {
49 | // connection.release();
50 | // if (err) {
51 | // return callback(err, null);
52 | // }
53 | // return callback(null, rows);
54 | // });
55 | // }
56 | // else {
57 | // return callback(true, "No Connection");
58 | // }
59 | // });
60 | // }
61 |
62 | function executeQuery(pool, query, connection, callback) {
63 | connection.query({sql:query, timeout:60000}, function (err, rows, fields) {
64 | if (err) {
65 | return callback(err, null);
66 | }
67 | return callback(null, rows);
68 | });
69 | }
70 |
71 | exports.getConnection = function(callback) {
72 | if(mysql_pool == null) {
73 | console.error("mysql is not connected");
74 | callback(true, "mysql is not connected");
75 | return '0';
76 | }
77 |
78 | mysql_pool.getConnection((err, connection) => {
79 | if (err) {
80 | callback('500-5');
81 | }
82 | else {
83 | if (connection) {
84 | callback('200', connection);
85 | }
86 | else {
87 | callback('500-5');
88 | }
89 | }
90 | });
91 | };
92 |
93 | exports.getResult = function(query, connection, callback) {
94 | if(mysql_pool == null) {
95 | console.error("mysql is not connected");
96 | return '0';
97 | }
98 |
99 | executeQuery(mysql_pool, query, connection, (err, rows) => {
100 | if (!err) {
101 | callback(null, rows);
102 | }
103 | else {
104 | callback(true, err);
105 | }
106 | });
107 | };
108 |
109 |
110 |
--------------------------------------------------------------------------------
/mobius/fcnt.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2020, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file
13 | * @copyright KETI Korea 2020, KETI
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | */
16 |
17 | var url = require('url');
18 | var xml2js = require('xml2js');
19 | var xmlbuilder = require('xmlbuilder');
20 | var util = require('util');
21 | var responder = require('./responder');
22 |
23 |
24 | exports.build_fcnt = function(request, response, resource_Obj, body_Obj, callback) {
25 | var rootnm = request.headers.rootnm;
26 |
27 | // body
28 | // - specific attributes
29 | resource_Obj[rootnm].cnd = body_Obj[rootnm].cnd;
30 | resource_Obj[rootnm].cr = (body_Obj[rootnm].cr) ? body_Obj[rootnm].cr : request.headers['x-m2m-origin'];
31 |
32 | if(rootnm == 'fcnt' && body_Obj[rootnm].cnd.includes('org.onem2m.home.device.')) {
33 | }
34 | else if(rootnm == 'hd_dooLk' && body_Obj[rootnm].cnd == 'org.onem2m.home.moduleclass.doorlock') {
35 | resource_Obj[rootnm].lock = body_Obj[rootnm].lock;
36 | }
37 | else if(rootnm == 'hd_bat' && body_Obj[rootnm].cnd == 'org.onem2m.home.moduleclass.battery') {
38 | resource_Obj[rootnm].lvl = body_Obj[rootnm].lvl;
39 | }
40 | else if(rootnm == 'hd_tempe' && body_Obj[rootnm].cnd == 'org.onem2m.home.moduleclass.temperature') {
41 | resource_Obj[rootnm].curT0 = body_Obj[rootnm].curT0;
42 | }
43 | else if(rootnm == 'hd_binSh' && body_Obj[rootnm].cnd == 'org.onem2m.home.moduleclass.binarySwitch') {
44 | resource_Obj[rootnm].powerSe = body_Obj[rootnm].powerSe;
45 | }
46 | else if(rootnm == 'hd_fauDn' && body_Obj[rootnm].cnd == 'org.onem2m.home.moduleclass.faultDetection') {
47 | resource_Obj[rootnm].sus = body_Obj[rootnm].sus;
48 | }
49 | else if(rootnm == 'hd_colSn' && body_Obj[rootnm].cnd == 'org.onem2m.home.moduleclass.colourSaturation') {
50 | resource_Obj[rootnm].colSn = body_Obj[rootnm].colSn;
51 | }
52 | else if(rootnm == 'hd_color' && body_Obj[rootnm].cnd == 'org.onem2m.home.moduleclass.colour') {
53 | resource_Obj[rootnm].red = body_Obj[rootnm].red;
54 | resource_Obj[rootnm].green = body_Obj[rootnm].green;
55 | resource_Obj[rootnm].blue = body_Obj[rootnm].blue;
56 | }
57 | else if(rootnm == 'hd_brigs' && body_Obj[rootnm].cnd == 'org.onem2m.home.moduleclass.brightness') {
58 | resource_Obj[rootnm].brigs = body_Obj[rootnm].brigs;
59 | }
60 | else {
61 | callback('400-54');
62 | return;
63 | }
64 |
65 | request.resourceObj = JSON.parse(JSON.stringify(resource_Obj));
66 | resource_Obj = null;
67 |
68 | callback('200');
69 | };
--------------------------------------------------------------------------------
/mobius/fopt.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2018, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file
13 | * @copyright KETI Korea 2018, KETI
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | */
16 |
17 | var util = require('util');
18 | var url = require('url');
19 | var http = require('http');
20 | var xml2js = require('xml2js');
21 | var xmlbuilder = require('xmlbuilder');
22 | var moment = require('moment');
23 |
24 | var responder = require('./responder');
25 | var resource = require('./resource');
26 |
27 | var db_sql = require('./sql_action');
28 |
29 | function check_body(res, body_type, res_body, callback) {
30 | var retrieve_Obj = {};
31 |
32 | if (body_type == 'xml') {
33 | var parser = new xml2js.Parser({explicitArray: false});
34 | parser.parseString(res_body, function (err, result) {
35 | if (!err) {
36 | for (var prop in result) {
37 | if(result.hasOwnProperty(prop)) {
38 | if (result[prop]['$'] != null) {
39 | if (result[prop]['$'].rn != null) {
40 | result[prop].rn = result[prop]['$'].rn;
41 | }
42 | delete result[prop]['$'];
43 | }
44 | retrieve_Obj.fr = res.req.path;
45 | retrieve_Obj.rsc = res.headers['x-m2m-rsc'];
46 | retrieve_Obj.pc = result;
47 | }
48 | }
49 | callback('1', retrieve_Obj);
50 | return '1';
51 | }
52 | else {
53 | callback('0');
54 | return '0';
55 | }
56 | });
57 | }
58 | else { // json
59 | var result = JSON.parse(res_body);
60 | if(res.req.path.charAt(0) == '/') {
61 | retrieve_Obj.fr = res.req.path.replace('/', '');
62 | }
63 | else {
64 | retrieve_Obj.fr = res.req.path;
65 | }
66 |
67 | if(res.headers.hasOwnProperty('x-m2m-rsc')) {
68 | retrieve_Obj.rsc = res.headers['x-m2m-rsc'];
69 | }
70 |
71 | if(res.headers.hasOwnProperty('x-m2m-ri')) {
72 | retrieve_Obj.rqi = res.headers['x-m2m-ri'];
73 | }
74 |
75 | if(res.headers.hasOwnProperty('x-m2m-rvi')) {
76 | retrieve_Obj.rvi = res.headers['x-m2m-rvi'];
77 | }
78 |
79 | retrieve_Obj.pc = result;
80 | callback('1', retrieve_Obj);
81 | return '1';
82 | }
83 | }
84 |
85 | function request_to_member(request, hostname, port, ri, agr, callback) {
86 | var ri_prefix = request.url.split('/fopt')[1];
87 |
88 | var options = {
89 | hostname: hostname,
90 | port: port,
91 | path: ri + ri_prefix,
92 | method: request.method,
93 | headers: request.headers
94 | };
95 |
96 | var responseBody = '';
97 | var req = http.request(options, function (res) {
98 | //res.setEncoding('utf8');
99 | res.on('data', function (chunk) {
100 | responseBody += chunk;
101 | });
102 |
103 | res.on('end', function () {
104 | check_body(res, request.usebodytype, responseBody, function (rsc, retrieve_Obj) {
105 | if (rsc == '1') {
106 | agr[retrieve_Obj.fr] = JSON.parse(JSON.stringify(retrieve_Obj));
107 | retrieve_Obj = null;
108 |
109 | callback('200');
110 | }
111 | });
112 | });
113 | });
114 |
115 | req.on('error', function (e) {
116 | if (e.message != 'read ECONNRESET') {
117 | console.log('[fopt_member] problem with request: ' + e.message);
118 | }
119 |
120 | callback('200');
121 | });
122 |
123 | req.write(request.body);
124 | req.end();
125 | }
126 |
127 | function fopt_member(request, response, req_count, mid, body_Obj, cse_poa, agr, callback) {
128 | if(req_count >= mid.length) {
129 | callback('200');
130 | }
131 | else {
132 | var ri_prefix = request.url.split('/fopt')[1];
133 | var ri = mid[req_count];
134 | db_sql.get_ri_sri(request.db_connection, ri, function (err, results) {
135 | if(!err) {
136 | ri = ((results.length == 0) ? ri : results[0].ri);
137 | var target_cb = ri.split('/')[1];
138 | var hostname = 'localhost';
139 | var port = usecsebaseport;
140 |
141 | if (target_cb != usecsebase) {
142 | if (cse_poa[target_cb]) {
143 | hostname = url.parse(cse_poa[target_cb]).hostname;
144 | port = url.parse(cse_poa[target_cb]).port;
145 | request_to_member(request, hostname, port, ri, agr, function (code) {
146 | if(code === '200') {
147 | fopt_member(request, response, req_count, mid, body_Obj, cse_poa, agr, function (code) {
148 | callback(code);
149 | });
150 | }
151 | else {
152 | callback(code);
153 | }
154 | });
155 | }
156 | else {
157 | fopt_member(request, response, ++req_count, mid, body_Obj, cse_poa, agr, function (code) {
158 | callback(code);
159 | });
160 | }
161 | }
162 | else {
163 | request_to_member(request, hostname, port, ri, agr, function (code) {
164 | if(code === '200') {
165 | fopt_member(request, response, ++req_count, mid, body_Obj, cse_poa, agr, function (code) {
166 | callback(code);
167 | });
168 | }
169 | else {
170 | callback(code);
171 | }
172 | });
173 | }
174 | }
175 | else {
176 | fopt_member(request, response, ++req_count, mid, body_Obj, cse_poa, agr, function (code) {
177 | callback(code);
178 | });
179 | }
180 | });
181 | }
182 | }
183 |
184 |
185 | exports.check = function(request, response, grp, body_Obj, callback) {
186 | request.headers.rootnm = 'agr';
187 | var cse_poa = {};
188 | update_route(request.db_connection, cse_poa, function (code) {
189 | if(code === '200') {
190 | var ri_list = [];
191 | get_ri_list_sri(request, response, grp.mid, ri_list, 0, function (code) {
192 | if(code === '200') {
193 | var req_count = 0;
194 | var agr = {};
195 | make_internal_ri(ri_list);
196 | fopt_member(request, response, req_count, ri_list, body_Obj, cse_poa, agr, function (code) {
197 | if(code == '200') {
198 | var retrieve_Obj = agr;
199 | if (Object.keys(retrieve_Obj).length != 0) {
200 | request.resourceObj = JSON.parse(JSON.stringify(retrieve_Obj));
201 | retrieve_Obj = null;
202 |
203 | callback('200');
204 | }
205 | else {
206 | callback('404-5');
207 | }
208 | }
209 | });
210 | }
211 | else {
212 | callback(code);
213 | }
214 | });
215 | }
216 | else {
217 | callback(code);
218 | }
219 | });
220 | };
221 |
222 |
--------------------------------------------------------------------------------
/mobius/grp.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2018, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file
13 | * @copyright KETI Korea 2018, KETI
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | */
16 |
17 | var url = require('url');
18 | var xml2js = require('xml2js');
19 | var xmlbuilder = require('xmlbuilder');
20 | var http = require('http');
21 | var util = require('util');
22 | var moment = require('moment');
23 |
24 | var responder = require('./responder');
25 |
26 | var db_sql = require('./sql_action');
27 |
28 | function check_mt(request, res_body, callback) {
29 | var body_type = request.usebodytype;
30 | var mt = request.mt;
31 |
32 | if (body_type == 'xml') {
33 | var parser = new xml2js.Parser({explicitArray: false});
34 | parser.parseString(res_body, function (err, result) {
35 | if (!err) {
36 | for (var prop in result) {
37 | if(result.hasOwnProperty(prop)) {
38 | if (result[prop].ty == mt) {
39 | result = null;
40 | callback('1');
41 | return;
42 | }
43 | }
44 | }
45 | result = null;
46 | callback('0');
47 | }
48 | else {
49 | result = null;
50 | callback('0');
51 | }
52 | });
53 | }
54 | else { // json
55 | var result = JSON.parse(res_body);
56 | for (var prop in result) {
57 | if(result.hasOwnProperty(prop)) {
58 | if (result[prop].ty == mt) {
59 | result = null;
60 | callback('1');
61 | return;
62 | }
63 | }
64 | }
65 | result = null;
66 | callback('0');
67 | }
68 | }
69 |
70 | function check_member(request, response, req_count, cse_poa, callback) {
71 | if(req_count >= request.mid.length) {
72 | callback('200');
73 | }
74 | else {
75 | var ri = request.mid[req_count];
76 | if (ri.charAt(0) != '/') {
77 | var absolute_ri = '/' + ri;
78 | }
79 | else {
80 | absolute_ri = ri.replace(/\/\/[^\/]+\/?/, '\/');
81 | absolute_ri = absolute_ri.replace(/\/[^\/]+\/?/, '/');
82 | }
83 | db_sql.get_ri_sri(request.db_connection, absolute_ri, function (err, results) {
84 | ri = ((results.length == 0) ? ri : results[0].ri);
85 | var target_cb = ri.split('/')[1];
86 | if (target_cb != usecsebase) {
87 | if (cse_poa[target_cb]) {
88 | var options = {
89 | hostname: url.parse(cse_poa[target_cb]).hostname,
90 | port: url.parse(cse_poa[target_cb]).port,
91 | path: ri,
92 | method: 'get',
93 | headers: {
94 | 'X-M2M-RI': require('shortid').generate(),
95 | 'Accept': 'application/' + request.usebodytype,
96 | 'X-M2M-Origin': request.headers['x-m2m-origin'],
97 | 'X-M2M-RVI': uservi
98 | }
99 | };
100 |
101 | var responseBody = '';
102 | var req = http.request(options, function (res) {
103 | //res.setEncoding('utf8');
104 | res.on('data', function (chunk) {
105 | responseBody += chunk;
106 | });
107 |
108 | res.on('end', function () {
109 | if (res.statusCode == 200) {
110 | check_mt(request, responseBody, function (rsc) {
111 | if (rsc == '1') {
112 | request.valid_mid.push(ri);
113 | }
114 |
115 | check_member(request, response, ++req_count, cse_poa, function (code) {
116 | callback(code);
117 | });
118 | });
119 | }
120 | else {
121 | check_member(request, response, ++req_count, cse_poa, function (code) {
122 | callback(code);
123 | });
124 | }
125 | });
126 | });
127 |
128 | req.on('error', function (e) {
129 | if (e.message != 'read ECONNRESET') {
130 | console.log('[check_member] problem with request: ' + e.message);
131 | }
132 |
133 | check_member(request, response, ++req_count, cse_poa, function (code) {
134 | callback(code);
135 | });
136 | });
137 |
138 | req.write('');
139 | req.end();
140 | }
141 | else {
142 | check_member(request, response, ++req_count, cse_poa, function (code) {
143 | callback(code);
144 | });
145 | }
146 | }
147 | else {
148 | check_member(request, response, ++req_count, cse_poa, function (code) {
149 | callback(code);
150 | });
151 | }
152 | });
153 | }
154 | }
155 |
156 |
157 | function check_mtv(request, response, resource_Obj, callback) {
158 | var cse_poa = {};
159 | update_route(request.db_connection, cse_poa, function (code) {
160 | if(code === '200') {
161 | var req_count = 0;
162 | var rootnm = Object.keys(resource_Obj)[0];
163 | var mid = resource_Obj[rootnm].mid;
164 | make_internal_ri(mid);
165 | request.mid = mid;
166 | request.mt = resource_Obj[Object.keys(resource_Obj)[0]].mt;
167 | request.valid_mid = [];
168 | check_member(request, response, req_count, cse_poa, function (code) {
169 | if (code === '200') {
170 | if (request.valid_mid.length == mid.length) {
171 | if (resource_Obj[rootnm].csy == '1') { // ABANDON_MEMBER
172 | resource_Obj[rootnm].mid = JSON.parse(JSON.stringify(request.valid_mid));
173 | resource_Obj[rootnm].cnm = request.valid_mid.length.toString();
174 | resource_Obj[rootnm].mtv = 'true';
175 | callback('200');
176 | }
177 | else if (resource_Obj[rootnm].csy == '2') { // ABANDON_GROUP
178 | callback('400-34');
179 | }
180 | else { // SET_MIXED
181 | resource_Obj[rootnm].mt = '0';
182 | resource_Obj[rootnm].mtv = 'false';
183 | callback('200');
184 | }
185 | }
186 | else {
187 | resource_Obj[rootnm].mtv = 'true';
188 | callback('200');
189 | }
190 | }
191 | });
192 | }
193 | else {
194 | callback(code);
195 | }
196 | });
197 | }
198 |
199 | global.remove_duplicated_mid = function(mid) {
200 | var temp_mid = {};
201 | for(var id in mid) {
202 | if (mid.hasOwnProperty(id)) {
203 | temp_mid[mid[id]] = mid[id];
204 | }
205 | }
206 |
207 | mid = [];
208 | for(id in temp_mid) {
209 | if (temp_mid.hasOwnProperty(id)) {
210 | mid.push(temp_mid[id]);
211 | }
212 | }
213 |
214 | return mid;
215 | };
216 |
217 | exports.build_grp = function(request, response, resource_Obj, body_Obj, callback) {
218 | var rootnm = request.headers.rootnm;
219 |
220 | // body
221 | resource_Obj[rootnm].mnm = body_Obj[rootnm].mnm;
222 | resource_Obj[rootnm].mid = remove_duplicated_mid(body_Obj[rootnm].mid);
223 |
224 | resource_Obj[rootnm].cr = (body_Obj[rootnm].cr) ? body_Obj[rootnm].cr : request.headers['x-m2m-origin'];
225 | resource_Obj[rootnm].macp = (body_Obj[rootnm].macp) ? body_Obj[rootnm].macp : [];
226 | resource_Obj[rootnm].mt = (body_Obj[rootnm].mt) ? body_Obj[rootnm].mt : '0';
227 | resource_Obj[rootnm].csy = (body_Obj[rootnm].csy) ? body_Obj[rootnm].csy : '1'; // default : ABANDON_MEMBER
228 | resource_Obj[rootnm].cnm = resource_Obj[rootnm].mid.length.toString();
229 | resource_Obj[rootnm].gn = (body_Obj[rootnm].gn) ? body_Obj[rootnm].gn : '';
230 |
231 | if(parseInt(resource_Obj[rootnm].mnm, 10) < parseInt(resource_Obj[rootnm].cnm)) {
232 | callback('400-33');
233 | return;
234 | }
235 |
236 | if(resource_Obj[rootnm].mt != '0') {
237 | check_mtv(request, response, resource_Obj, function(code) {
238 | if(code === '200') {
239 | request.resourceObj = JSON.parse(JSON.stringify(resource_Obj));
240 | resource_Obj = null;
241 |
242 | callback(code);
243 | }
244 | else {
245 | callback(code);
246 | }
247 | });
248 | }
249 | else {
250 | resource_Obj[rootnm].mtv = 'false';
251 |
252 | request.resourceObj = JSON.parse(JSON.stringify(resource_Obj));
253 |
254 | callback('200');
255 | }
256 | };
257 |
258 |
259 |
260 | // exports.modify_grp = function(request, response, resource_Obj, body_Obj, callback) {
261 | // var rootnm = request.headers.rootnm;
262 | //
263 | // // check M
264 | // for (var attr in update_m_attr_list[rootnm]) {
265 | // if (update_m_attr_list[rootnm].hasOwnProperty(attr)) {
266 | // if (body_Obj[rootnm].includes(attr)) {
267 | // }
268 | // else {
269 | // body_Obj = {};
270 | // body_Obj['dbg'] = 'BAD REQUEST: ' + attr + ' is \'Mandatory\' attribute';
271 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
272 | // callback('0', resource_Obj);
273 | // return '0';
274 | // }
275 | // }
276 | // }
277 | //
278 | // // check NP and body
279 | // for (attr in body_Obj[rootnm]) {
280 | // if (body_Obj[rootnm].hasOwnProperty(attr)) {
281 | // if (update_np_attr_list[rootnm].includes(attr)) {
282 | // body_Obj = {};
283 | // body_Obj['dbg'] = 'BAD REQUEST: ' + attr + ' is \'Not Present\' attribute';
284 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
285 | // callback('0', resource_Obj);
286 | // return '0';
287 | // }
288 | // else {
289 | // if (update_opt_attr_list[rootnm].includes(attr)) {
290 | // }
291 | // else {
292 | // body_Obj = {};
293 | // body_Obj['dbg'] = 'NOT FOUND: ' + attr + ' attribute is not defined';
294 | // responder.response_result(request, response, 404, body_Obj, 4004, request.url, body_Obj['dbg']);
295 | // callback('0', resource_Obj);
296 | // return '0';
297 | // }
298 | // }
299 | // }
300 | // }
301 | //
302 | // update_body(rootnm, body_Obj, resource_Obj); // (attr == 'aa' || attr == 'poa' || attr == 'lbl' || attr == 'acpi' || attr == 'srt' || attr == 'nu' || attr == 'mid' || attr == 'macp')
303 | //
304 | // resource_Obj[rootnm].st = (parseInt(resource_Obj[rootnm].st, 10) + 1).toString();
305 | //
306 | // var cur_d = new Date();
307 | // resource_Obj[rootnm].lt = cur_d.toISOString().replace(/-/, '').replace(/-/, '').replace(/:/, '').replace(/:/, '').replace(/\..+/, '');
308 | //
309 | // if (resource_Obj[rootnm].et != '') {
310 | // if (resource_Obj[rootnm].et < resource_Obj[rootnm].ct) {
311 | // body_Obj = {};
312 | // body_Obj['dbg'] = 'expiration time is before now';
313 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
314 | // callback('0', resource_Obj);
315 | // return '0';
316 | // }
317 | // }
318 | //
319 | // if(body_Obj[rootnm].mid) {
320 | // resource_Obj[rootnm].mid = body_Obj[rootnm].mid;
321 | //
322 | // if(resource_Obj[rootnm].mt != '0') {
323 | // check_mtv(resource_Obj[rootnm].mt, resource_Obj[rootnm].mid, function(rsc, results_mid) {
324 | // if(rsc == '0') { // mt inconsistency
325 | // if(results_mid.length == '0') {
326 | // body_Obj = {};
327 | // body_Obj['dbg'] = 'can not create group because mid is empty after validation check of mt requested';
328 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
329 | // callback('0', body_Obj);
330 | // return '0';
331 | // }
332 | // else {
333 | // if (resource_Obj[rootnm].csy == '1') { // ABANDON_MEMBER
334 | // resource_Obj[rootnm].mid = results_mid;
335 | // resource_Obj[rootnm].cnm = body_Obj[rootnm].mid.length.toString();
336 | // resource_Obj[rootnm].mtv = 'true';
337 | // }
338 | // else if (resource_Obj[rootnm].csy == '2') { // ABANDON_GROUP
339 | // body_Obj = {};
340 | // body_Obj['dbg'] = 'can not create group because csy is ABANDON_GROUP when MEMBER_TYPE_INCONSISTENT';
341 | // responder.response_result(request, response, 400, body_Obj, 6011, request.url, body_Obj['dbg']);
342 | // callback('0', body_Obj);
343 | // return '0';
344 | // }
345 | // else { // SET_MIXED
346 | // resource_Obj[rootnm].mt = '0';
347 | // resource_Obj[rootnm].mtv = 'false';
348 | // }
349 | // }
350 | // }
351 | // else if(rsc == '1') {
352 | // resource_Obj[rootnm].mtv = 'true';
353 | // }
354 | // else { // db error
355 | // body_Obj = {};
356 | // body_Obj['dbg'] = results_mid.message;
357 | // responder.response_result(request, response, 500, body_Obj, 5000, request.url, body_Obj['dbg']);
358 | // callback('0', body_Obj);
359 | // return '0';
360 | // }
361 | //
362 | // callback('1', resource_Obj);
363 | // });
364 | // }
365 | // else {
366 | // resource_Obj[rootnm].mtv = 'false';
367 | // callback('1', resource_Obj);
368 | // }
369 | // }
370 | // else {
371 | // callback('1', resource_Obj);
372 | // }
373 | // };
374 |
375 |
--------------------------------------------------------------------------------
/mobius/lcp.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2018, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file
13 | * @copyright KETI Korea 2018, KETI
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | */
16 |
17 | var url = require('url');
18 | var xml2js = require('xml2js');
19 | var xmlbuilder = require('xmlbuilder');
20 | var util = require('util');
21 | var responder = require('./responder');
22 |
23 | //var _this = this;
24 |
25 |
26 | exports.build_lcp = function(request, response, resource_Obj, body_Obj, callback) {
27 | var rootnm = request.headers.rootnm;
28 |
29 | // body
30 | resource_Obj[rootnm].los = body_Obj[rootnm].los;
31 | resource_Obj[rootnm].lou = (body_Obj[rootnm].lou) ? body_Obj[rootnm].lou : '0';
32 | resource_Obj[rootnm].lot = (body_Obj[rootnm].lot) ? body_Obj[rootnm].lot : '';
33 | resource_Obj[rootnm].lor = (body_Obj[rootnm].lor) ? body_Obj[rootnm].lor : '';
34 | resource_Obj[rootnm].loi = (body_Obj[rootnm].loi) ? body_Obj[rootnm].loi : '';
35 | resource_Obj[rootnm].lon = (body_Obj[rootnm].lon) ? body_Obj[rootnm].lon : '';
36 | resource_Obj[rootnm].lost = (body_Obj[rootnm].lost) ? body_Obj[rootnm].lost : '';
37 |
38 | request.resourceObj = JSON.parse(JSON.stringify(resource_Obj));
39 | resource_Obj = null;
40 |
41 | callback('200');
42 | };
43 |
44 |
45 |
46 | // exports.modify_lcp = function(request, response, resource_Obj, body_Obj, callback) {
47 | // var rootnm = request.headers.rootnm;
48 | //
49 | // // check M
50 | // for (var attr in update_m_attr_list[rootnm]) {
51 | // if (update_m_attr_list[rootnm].hasOwnProperty(attr)) {
52 | // if (body_Obj[rootnm].includes(attr)) {
53 | // }
54 | // else {
55 | // body_Obj = {};
56 | // body_Obj['dbg'] = 'BAD REQUEST: ' + attr + ' is \'Mandatory\' attribute';
57 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
58 | // callback('0', resource_Obj);
59 | // return '0';
60 | // }
61 | // }
62 | // }
63 | //
64 | // // check NP and body
65 | // for (attr in body_Obj[rootnm]) {
66 | // if (body_Obj[rootnm].hasOwnProperty(attr)) {
67 | // if (update_np_attr_list[rootnm].includes(attr)) {
68 | // body_Obj = {};
69 | // body_Obj['dbg'] = 'BAD REQUEST: ' + attr + ' is \'Not Present\' attribute';
70 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
71 | // callback('0', resource_Obj);
72 | // return '0';
73 | // }
74 | // else {
75 | // if (update_opt_attr_list[rootnm].includes(attr)) {
76 | // }
77 | // else {
78 | // body_Obj = {};
79 | // body_Obj['dbg'] = 'NOT FOUND: ' + attr + ' attribute is not defined';
80 | // responder.response_result(request, response, 404, body_Obj, 4004, request.url, body_Obj['dbg']);
81 | // callback('0', resource_Obj);
82 | // return '0';
83 | // }
84 | // }
85 | // }
86 | // }
87 | //
88 | // update_body(rootnm, body_Obj, resource_Obj); // (attr == 'aa' || attr == 'poa' || attr == 'lbl' || attr == 'acpi' || attr == 'srt' || attr == 'nu' || attr == 'mid' || attr == 'macp')
89 | //
90 | // resource_Obj[rootnm].st = (parseInt(resource_Obj[rootnm].st, 10) + 1).toString();
91 | //
92 | // var cur_d = new Date();
93 | // resource_Obj[rootnm].lt = cur_d.toISOString().replace(/-/, '').replace(/-/, '').replace(/:/, '').replace(/:/, '').replace(/\..+/, '');
94 | //
95 | // if (resource_Obj[rootnm].et != '') {
96 | // if (resource_Obj[rootnm].et < resource_Obj[rootnm].ct) {
97 | // body_Obj = {};
98 | // body_Obj['dbg'] = 'expiration time is before now';
99 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
100 | // callback('0', resource_Obj);
101 | // return '0';
102 | // }
103 | // }
104 | //
105 | // callback('1', resource_Obj);
106 | // };
107 |
108 |
--------------------------------------------------------------------------------
/mobius/mgo.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2018, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file
13 | * @copyright KETI Korea 2018, KETI
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | */
16 |
17 | var url = require('url');
18 | var xml2js = require('xml2js');
19 | var xmlbuilder = require('xmlbuilder');
20 | var util = require('util');
21 | var responder = require('./responder');
22 |
23 |
24 | exports.build_mgo = function(request, response, resource_Obj, body_Obj, callback) {
25 | var rootnm = request.headers.rootnm;
26 |
27 | // body
28 | // - specific attributes
29 | resource_Obj[rootnm].mgd = body_Obj[rootnm].mgd;
30 | resource_Obj[rootnm].objs = (body_Obj[rootnm].objs) ? body_Obj[rootnm].objs : '';
31 | resource_Obj[rootnm].obps = (body_Obj[rootnm].obps) ? body_Obj[rootnm].obps : '';
32 | resource_Obj[rootnm].dc = (body_Obj[rootnm].dc) ? body_Obj[rootnm].dc : '';
33 |
34 | if(rootnm == 'fwr' && body_Obj[rootnm].mgd == '1001') {
35 | resource_Obj[rootnm].vr = body_Obj[rootnm].vr;
36 | resource_Obj[rootnm].fwnnam = body_Obj[rootnm].fwnnam;
37 | resource_Obj[rootnm].url = body_Obj[rootnm].url;
38 | resource_Obj[rootnm].ud = body_Obj[rootnm].ud;
39 | resource_Obj[rootnm].uds = '';
40 | }
41 | else if(rootnm == 'bat' && body_Obj[rootnm].mgd == '1006') {
42 | resource_Obj[rootnm].btl = body_Obj[rootnm].btl;
43 | resource_Obj[rootnm].bts = body_Obj[rootnm].bts;
44 | }
45 | else if(rootnm == 'dvi' && body_Obj[rootnm].mgd == '1007') {
46 | resource_Obj[rootnm].dbl = body_Obj[rootnm].dbl;
47 | resource_Obj[rootnm].man = body_Obj[rootnm].man;
48 | resource_Obj[rootnm].mod = body_Obj[rootnm].mod;
49 | resource_Obj[rootnm].dty = body_Obj[rootnm].dty;
50 | resource_Obj[rootnm].fwv = body_Obj[rootnm].fwv;
51 | resource_Obj[rootnm].swv = body_Obj[rootnm].swv;
52 | resource_Obj[rootnm].hwv = body_Obj[rootnm].hwv;
53 | }
54 | else if(rootnm == 'dvc' && body_Obj[rootnm].mgd == '1008') {
55 | resource_Obj[rootnm].can = body_Obj[rootnm].can;
56 | resource_Obj[rootnm].att = body_Obj[rootnm].att;
57 | resource_Obj[rootnm].cas = body_Obj[rootnm].cas;
58 | resource_Obj[rootnm].cus = body_Obj[rootnm].cus;
59 | resource_Obj[rootnm].ena = (body_Obj[rootnm].ena) ? body_Obj[rootnm].ena : 'true';
60 | resource_Obj[rootnm].dis = (body_Obj[rootnm].dis) ? body_Obj[rootnm].dis : 'true';
61 | }
62 | else if(rootnm == 'rbo' && body_Obj[rootnm].mgd == '1009') {
63 | resource_Obj[rootnm].rbo = (body_Obj[rootnm].rbo) ? body_Obj[rootnm].rbo : 'true';
64 | resource_Obj[rootnm].far = (body_Obj[rootnm].far) ? body_Obj[rootnm].far : 'true';
65 | }
66 | else {
67 | callback('400-35');
68 | return;
69 | }
70 |
71 | request.resourceObj = JSON.parse(JSON.stringify(resource_Obj));
72 | resource_Obj = null;
73 |
74 | callback('200');
75 | };
76 |
77 | // exports.modify_mgo = function(request, response, resource_Obj, body_Obj, callback) {
78 | // var rootnm = request.headers.rootnm;
79 | //
80 | // // check M
81 | // for (var attr in update_m_attr_list[rootnm]) {
82 | // if (update_m_attr_list[rootnm].hasOwnProperty(attr)) {
83 | // if (body_Obj[rootnm].includes(attr)) {
84 | // }
85 | // else {
86 | // body_Obj = {};
87 | // body_Obj['dbg'] = 'BAD REQUEST: ' + attr + ' is \'Mandatory\' attribute';
88 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
89 | // callback('0', resource_Obj);
90 | // return '0';
91 | // }
92 | // }
93 | // }
94 | //
95 | // // check NP and body
96 | // for (attr in body_Obj[rootnm]) {
97 | // if (body_Obj[rootnm].hasOwnProperty(attr)) {
98 | // if (update_np_attr_list[rootnm].includes(attr)) {
99 | // body_Obj = {};
100 | // body_Obj['dbg'] = 'BAD REQUEST: ' + attr + ' is \'Not Present\' attribute';
101 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
102 | // callback('0', resource_Obj);
103 | // return '0';
104 | // }
105 | // else {
106 | // if (update_opt_attr_list[rootnm].includes(attr)) {
107 | // }
108 | // else {
109 | // body_Obj = {};
110 | // body_Obj['dbg'] = 'NOT FOUND: ' + attr + ' attribute is not defined';
111 | // responder.response_result(request, response, 404, body_Obj, 4004, request.url, body_Obj['dbg']);
112 | // callback('0', resource_Obj);
113 | // return '0';
114 | // }
115 | // }
116 | // }
117 | // }
118 | //
119 | // update_body(rootnm, body_Obj, resource_Obj);
120 | //
121 | // resource_Obj[rootnm].st = (parseInt(resource_Obj[rootnm].st, 10) + 1).toString();
122 | //
123 | // var cur_d = new Date();
124 | // resource_Obj[rootnm].lt = cur_d.toISOString().replace(/-/, '').replace(/-/, '').replace(/:/, '').replace(/:/, '').replace(/\..+/, '');
125 | //
126 | // if (resource_Obj[rootnm].et != '') {
127 | // if (resource_Obj[rootnm].et < resource_Obj[rootnm].ct) {
128 | // body_Obj = {};
129 | // body_Obj['dbg'] = 'expiration time is before now';
130 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
131 | // callback('0', resource_Obj);
132 | // return '0';
133 | // }
134 | // }
135 | //
136 | // callback('1', resource_Obj);
137 | // };
138 |
139 |
--------------------------------------------------------------------------------
/mobius/mms.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2018, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file
13 | * @copyright KETI Korea 2018, KETI
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | */
16 |
17 | var url = require('url');
18 | var xml2js = require('xml2js');
19 | var xmlbuilder = require('xmlbuilder');
20 | var util = require('util');
21 | var responder = require('./responder');
22 |
23 |
24 | exports.build_mms = function(request, response, resource_Obj, body_Obj, callback) {
25 | var rootnm = request.headers.rootnm;
26 |
27 | resource_Obj[rootnm].soid = body_Obj[rootnm]['soid'];
28 | resource_Obj[rootnm].asd = body_Obj[rootnm]['asd'];
29 | resource_Obj[rootnm].stid = body_Obj[rootnm]['stid'] == null ? '' : body_Obj[rootnm]['stid'];
30 | resource_Obj[rootnm].osd = body_Obj[rootnm]['osd'] == null ? '' : body_Obj[rootnm]['osd'];
31 | resource_Obj[rootnm].sst = body_Obj[rootnm]['sst'] == null ? 'OFFLINE' : body_Obj[rootnm]['sst'];
32 |
33 | resource_Obj[rootnm].sid = resource_Obj[rootnm].ri;
34 |
35 | request.resourceObj = JSON.parse(JSON.stringify(resource_Obj));
36 | resource_Obj = null;
37 |
38 | callback('200');
39 | };
40 |
41 | //
42 | //
43 | // exports.modify_mms = function(request, response, resource_Obj, body_Obj, callback) {
44 | // var rootnm = request.headers.rootnm;
45 | //
46 | // // check M
47 | // for (var attr in update_m_attr_list[rootnm]) {
48 | // if (update_m_attr_list[rootnm].hasOwnProperty(attr)) {
49 | // if (body_Obj[rootnm].includes(attr)) {
50 | // }
51 | // else {
52 | // body_Obj = {};
53 | // body_Obj['dbg'] = 'BAD REQUEST: ' + attr + ' is \'Mandatory\' attribute';
54 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
55 | // callback('0', resource_Obj);
56 | // return '0';
57 | // }
58 | // }
59 | // }
60 | //
61 | // // check NP and body
62 | // for (attr in body_Obj[rootnm]) {
63 | // if (body_Obj[rootnm].hasOwnProperty(attr)) {
64 | // if (update_np_attr_list[rootnm].includes(attr)) {
65 | // body_Obj = {};
66 | // body_Obj['dbg'] = 'BAD REQUEST: ' + attr + ' is \'Not Present\' attribute';
67 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
68 | // callback('0', resource_Obj);
69 | // return '0';
70 | // }
71 | // else {
72 | // if (update_opt_attr_list[rootnm].includes(attr)) {
73 | // }
74 | // else {
75 | // body_Obj = {};
76 | // body_Obj['dbg'] = 'NOT FOUND: ' + attr + ' attribute is not defined';
77 | // responder.response_result(request, response, 404, body_Obj, 4004, request.url, body_Obj['dbg']);
78 | // callback('0', resource_Obj);
79 | // return '0';
80 | // }
81 | // }
82 | // }
83 | // }
84 | //
85 | // update_body(rootnm, body_Obj, resource_Obj); // (attr == 'aa' || attr == 'poa' || attr == 'lbl' || attr == 'acpi' || attr == 'srt' || attr == 'nu' || attr == 'mid' || attr == 'macp')
86 | //
87 | // resource_Obj[rootnm].st = (parseInt(resource_Obj[rootnm].st, 10) + 1).toString();
88 | //
89 | // var cur_d = new Date();
90 | // resource_Obj[rootnm].lt = cur_d.toISOString().replace(/-/, '').replace(/-/, '').replace(/:/, '').replace(/:/, '').replace(/\..+/, '');
91 | //
92 | // if (resource_Obj[rootnm].et != '') {
93 | // if (resource_Obj[rootnm].et < resource_Obj[rootnm].ct) {
94 | // body_Obj = {};
95 | // body_Obj['dbg'] = 'expiration is before now';
96 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, 'expiration is before now');
97 | // callback('0', resource_Obj);
98 | // return '0';
99 | // }
100 | // }
101 | //
102 | // callback('1', resource_Obj);
103 | // };
104 |
105 |
--------------------------------------------------------------------------------
/mobius/nod.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2018, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file
13 | * @copyright KETI Korea 2018, KETI
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | */
16 |
17 | var url = require('url');
18 | var xml2js = require('xml2js');
19 | var xmlbuilder = require('xmlbuilder');
20 | var util = require('util');
21 | var responder = require('./responder');
22 |
23 |
24 | exports.build_nod = function(request, response, resource_Obj, body_Obj, callback) {
25 | var rootnm = request.headers.rootnm;
26 |
27 | // body
28 |
29 | // - specific attributes
30 | resource_Obj[rootnm].ni = body_Obj[rootnm].ni;
31 | resource_Obj[rootnm].hcl = (body_Obj[rootnm].hcl) ? body_Obj[rootnm].hcl : '';
32 | resource_Obj[rootnm].mgca = (body_Obj[rootnm].mgca) ? body_Obj[rootnm].mgca : '';
33 |
34 | request.resourceObj = JSON.parse(JSON.stringify(resource_Obj));
35 | resource_Obj = null;
36 |
37 | callback('200');
38 | };
39 |
40 |
41 |
42 | // exports.modify_nod = function(request, response, resource_Obj, body_Obj, callback) {
43 | // var rootnm = request.headers.rootnm;
44 | //
45 | // // check M
46 | // for (var attr in update_m_attr_list[rootnm]) {
47 | // if (update_m_attr_list[rootnm].hasOwnProperty(attr)) {
48 | // if (body_Obj[rootnm].includes(attr)) {
49 | // }
50 | // else {
51 | // body_Obj = {};
52 | // body_Obj['dbg'] = 'BAD REQUEST: ' + attr + ' is \'Mandatory\' attribute';
53 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
54 | // callback('0', resource_Obj);
55 | // return '0';
56 | // }
57 | // }
58 | // }
59 | //
60 | // // check NP and body
61 | // for (attr in body_Obj[rootnm]) {
62 | // if (body_Obj[rootnm].hasOwnProperty(attr)) {
63 | // if (update_np_attr_list[rootnm].includes(attr)) {
64 | // body_Obj = {};
65 | // body_Obj['dbg'] = 'BAD REQUEST: ' + attr + ' is \'Not Present\' attribute';
66 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
67 | // callback('0', resource_Obj);
68 | // return '0';
69 | // }
70 | // else {
71 | // if (update_opt_attr_list[rootnm].includes(attr)) {
72 | // }
73 | // else {
74 | // body_Obj = {};
75 | // body_Obj['dbg'] = 'NOT FOUND: ' + attr + ' attribute is not defined';
76 | // responder.response_result(request, response, 404, body_Obj, 4004, request.url, body_Obj['dbg']);
77 | // callback('0', resource_Obj);
78 | // return '0';
79 | // }
80 | // }
81 | // }
82 | // }
83 | //
84 | // update_body(rootnm, body_Obj, resource_Obj);
85 | //
86 | // resource_Obj[rootnm].st = (parseInt(resource_Obj[rootnm].st, 10) + 1).toString();
87 | //
88 | // var cur_d = new Date();
89 | // resource_Obj[rootnm].lt = cur_d.toISOString().replace(/-/, '').replace(/-/, '').replace(/:/, '').replace(/:/, '').replace(/\..+/, '');
90 | //
91 | // if (resource_Obj[rootnm].et != '') {
92 | // if (resource_Obj[rootnm].et < resource_Obj[rootnm].ct) {
93 | // body_Obj = {};
94 | // body_Obj['dbg'] = 'expiration time is before now';
95 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
96 | // callback('0', resource_Obj);
97 | // return '0';
98 | // }
99 | // }
100 | //
101 | // callback('1', resource_Obj);
102 | // };
103 | //
104 |
--------------------------------------------------------------------------------
/mobius/req.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2018, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file
13 | * @copyright KETI Korea 2018
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | */
16 |
17 | var url = require('url');
18 | var xml2js = require('xml2js');
19 | var xmlbuilder = require('xmlbuilder');
20 | var util = require('util');
21 | var responder = require('./responder');
22 |
23 | var op = {
24 | post: '1',
25 | get: '2',
26 | put: '3',
27 | delete: '4',
28 | notify: '5'
29 | };
30 |
31 | exports.build_req = function(request, response, resource_Obj, body_Obj, callback) {
32 | var rootnm = request.headers.rootnm;
33 |
34 | // body
35 | resource_Obj[rootnm].pi = '/' + usecsebase;
36 | resource_Obj[rootnm].ri = '/' + usecsebase + '/' + resource_Obj[rootnm].rn;
37 |
38 | resource_Obj[rootnm].op = (body_Obj[rootnm].op) ? body_Obj[rootnm].op : op[request.method];
39 | //resource_Obj[rootnm].tg = (body_Obj[rootnm].tg) ? body_Obj[rootnm].tg : resource_Obj[rootnm].ri;
40 | resource_Obj[rootnm].tg = (body_Obj[rootnm].tg) ? body_Obj[rootnm].tg : url.parse(request.url).pathname;
41 | resource_Obj[rootnm].org = (body_Obj[rootnm].org) ? body_Obj[rootnm].org : request.headers['x-m2m-origin'];
42 | resource_Obj[rootnm].rid = (body_Obj[rootnm].rid) ? body_Obj[rootnm].rid : request.headers['x-m2m-ri'];
43 | resource_Obj[rootnm].mi = (body_Obj[rootnm].mi) ? body_Obj[rootnm].mi : '';
44 | resource_Obj[rootnm].pc = (body_Obj[rootnm].pc) ? body_Obj[rootnm].pc : '';
45 | resource_Obj[rootnm].rs = (body_Obj[rootnm].rs) ? body_Obj[rootnm].rs : '';
46 | resource_Obj[rootnm].ors = (body_Obj[rootnm].ors) ? body_Obj[rootnm].ors : '';
47 |
48 | request.resourceObj = JSON.parse(JSON.stringify(resource_Obj));
49 | resource_Obj = null;
50 |
51 | callback('200');
52 | };
53 |
54 |
--------------------------------------------------------------------------------
/mobius/sgn_man.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2018, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file
13 | * @copyright KETI Korea 2018, KETI
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | */
16 |
17 | var fs = require('fs');
18 | var http = require('http');
19 | var https = require('https');
20 | var mqtt = require('mqtt');
21 | var url = require('url');
22 |
23 | var db = require('./db_action');
24 | var db_sql = require('./sql_action');
25 |
26 | var resp_mqtt_rqi_arr = {};
27 |
28 | global.NOPRINT = 'true';
29 |
30 | var _this = this;
31 |
32 | var resp_timeout = 2500;
33 |
34 | var MAX_NUM_RETRY = 16;
35 | var ss_fail_count = {};
36 |
37 | var sgn_mqtt_client = null;
38 |
39 | if(sgn_mqtt_client == null) {
40 | if(use_secure === 'disable') {
41 | sgn_mqtt_client = mqtt.connect('mqtt://' + use_mqtt_broker + ':' + use_mqtt_port);
42 | }
43 | else {
44 | var connectOptions = {
45 | host: use_mqtt_broker,
46 | port: use_mqtt_port,
47 | protocol: "mqtts",
48 | keepalive: 10,
49 | // clientId: serverUID,
50 | protocolId: "MQTT",
51 | protocolVersion: 4,
52 | clean: true,
53 | reconnectPeriod: 2000,
54 | connectTimeout: 2000,
55 | key: fs.readFileSync("./server-key.pem"),
56 | cert: fs.readFileSync("./server-crt.pem"),
57 | rejectUnauthorized: false
58 | };
59 | sgn_mqtt_client = mqtt.connect(connectOptions);
60 | }
61 |
62 | sgn_mqtt_client.on('connect', function () {
63 | console.log('sgn_mqtt_client is connected');
64 | });
65 |
66 | sgn_mqtt_client.on('message', sgn_mqtt_message_handler);
67 |
68 | sgn_mqtt_client.on('error', function () {
69 | sgn_mqtt_client = null;
70 | });
71 | }
72 |
73 | exports.post = function(ri, exc, nu, bodytype, rqi, bodyString, parentObj) {
74 | try {
75 | if(ss_fail_count.hasOwnProperty(ri)) {
76 | if(exc != "" && ( exc == 0 || exc == '0')) {
77 | ss_fail_count[ri] = 0;
78 | }
79 | }
80 | else {
81 | ss_fail_count[ri] = 0;
82 | }
83 |
84 | if (ss_fail_count[ri] >= MAX_NUM_RETRY) {
85 | var aeid = url.parse(nu).pathname.replace('/', '').split('?')[0];
86 | var noti_resp_topic = '/oneM2M/resp/' + usecseid.replace('/', '') + '/' + aeid + '/' + bodytype;
87 | sgn_mqtt_client.unsubscribe(noti_resp_topic);
88 |
89 | delete ss_fail_count[ri];
90 | delete_sub(ri, rqi, parentObj);
91 | }
92 | else {
93 | delete parentObj;
94 | parentObj = null;
95 | var sub_nu = url.parse(nu);
96 | if (sub_nu.protocol == 'http:' || sub_nu.protocol == 'https:') {
97 | request_noti_http(nu, ri, bodyString, bodytype, rqi);
98 | }
99 | else if (sub_nu.protocol == 'coap:') {
100 | request_noti_coap(nu, ri, bodyString, bodytype, rqi);
101 | }
102 | else if (sub_nu.protocol == 'ws:') {
103 | request_noti_ws(nu, ri, bodyString, bodytype, rqi);
104 | }
105 | else if (sub_nu.protocol == 'mqtt:') { // mqtt:
106 | request_noti_mqtt(nu, ri, bodyString, bodytype, rqi);
107 | }
108 | nu = null;
109 | }
110 | }
111 | catch (e) {
112 | console.log('[sgn_man] post function exception - ' + e.message);
113 | }
114 | };
115 |
116 | function sgn_mqtt_message_handler(topic, message) {
117 | var topic_arr = topic.split("/");
118 | if(topic_arr[5] != null) {
119 | var bodytype = (topic_arr[5] == 'xml') ? topic_arr[5] : ((topic_arr[5] == 'json') ? topic_arr[5] : ((topic_arr[5] == 'cbor') ? topic_arr[5] : 'json'));
120 | }
121 | else {
122 | bodytype = defaultbodytype;
123 | topic_arr[5] = defaultbodytype;
124 | }
125 |
126 | if((topic_arr[1] == 'oneM2M' && topic_arr[2] == 'resp' && ((topic_arr[3].replace(':', '/') == usecseid) || (topic_arr[3] == usecseid.replace('/', ''))))) {
127 | make_json_obj(bodytype, message.toString(), function(rsc, jsonObj) {
128 | if(rsc == '1') {
129 | if(jsonObj['m2m:rsp'] == null) {
130 | jsonObj['m2m:rsp'] = jsonObj;
131 | }
132 |
133 | if (jsonObj['m2m:rsp'] != null) {
134 | if(timerID.hasOwnProperty(jsonObj['m2m:rsp'].rqi)) {
135 | clearTimeout(timerID[jsonObj['m2m:rsp'].rqi]);
136 | delete timerID[jsonObj['m2m:rsp'].rqi];
137 | //sgn_mqtt_client.unsubscribe(topic);
138 | }
139 |
140 | if(resp_mqtt_rqi_arr.hasOwnProperty(jsonObj['m2m:rsp'].rqi)) {
141 | console.log('=======> [response_noti_mqtt]' + resp_mqtt_rqi_arr[jsonObj['m2m:rsp'].rqi]);
142 | delete ss_fail_count[resp_mqtt_rqi_arr[jsonObj['m2m:rsp'].rqi]];
143 | delete resp_mqtt_rqi_arr[jsonObj['m2m:rsp'].rqi];
144 | }
145 | }
146 | delete jsonObj;
147 | jsonObj = null;
148 | }
149 | else {
150 | console.log('[sgn_mqtt_message_handler] parsing error')
151 | }
152 | });
153 | }
154 | else {
155 | NOPRINT==='true'?NOPRINT='true':console.log('topic(' + topic + ') is not supported');
156 | }
157 | }
158 |
159 | function request_noti_http(nu, ri, bodyString, bodytype, xm2mri) {
160 | var bodyStr = '';
161 | var options = {
162 | hostname: url.parse(nu).hostname,
163 | port: url.parse(nu).port,
164 | path: url.parse(nu).path,
165 | method: 'POST',
166 | headers: {
167 | 'X-M2M-RI': xm2mri,
168 | 'Accept': 'application/' + bodytype,
169 | 'X-M2M-Origin': usecseid,
170 | 'Content-Type': 'application/' + bodytype,
171 | 'Content-Length' : bodyString.length //, for cert
172 | //'X-M2M-RVI': uservi
173 | //
174 | }
175 | };
176 |
177 | function response_noti_http(res) {
178 | res.on('data', function (chunk) {
179 | bodyStr += chunk;
180 | });
181 |
182 | res.on('end', function () {
183 | // if (res.statusCode == 200 || res.statusCode == 201) {
184 | // //console.log('----> [request_noti_http - ' + ss_fail_count[ri] + ']');
185 | // delete ss_fail_count[ri];
186 | // }
187 | // else {
188 | // console.log('----> [request_noti - wrong response - ' + res.statusCode + ']');
189 | // }
190 |
191 | if(timerID.hasOwnProperty(xm2mri)) {
192 | clearTimeout(timerID[xm2mri]);
193 | delete timerID[xm2mri];
194 | }
195 |
196 | if(ss_fail_count.hasOwnProperty(ri)) {
197 | console.log('=======> [response_noti_http] - ' + ri);
198 | delete ss_fail_count[ri];
199 | }
200 | });
201 | }
202 |
203 | if (url.parse(nu).protocol == 'http:') {
204 | var req = http.request(options, function (res) {
205 | response_noti_http(res);
206 | });
207 | }
208 | else {
209 | options.rejectUnauthorized = false;
210 | req = https.request(options, function (res) {
211 | response_noti_http(res);
212 | });
213 | }
214 |
215 | req.on('error', function (e) {
216 | //console.log('[request_noti_http - problem with request: ' + e.message + ']');
217 | //console.log('[request_noti_http - no response - ' + ss_fail_count[ri] + ']');
218 | });
219 |
220 | req.on('close', function () {
221 | //console.log('[request_noti_http] - close event - ' + ri + ' - ' + xm2mri);
222 | });
223 |
224 | req.on('socket',function(socket) {
225 | console.log('<======= [request_noti_http] - socket event - ' + ri + ' - ' + xm2mri);
226 | timerID[xm2mri] = setTimeout(checkResponse, resp_timeout, ri, xm2mri, socket);
227 | });
228 |
229 | console.log(bodyString);
230 | req.write(bodyString);
231 | req.end();
232 | }
233 |
234 | function checkResponse(ri, rqi, socket) {
235 | console.log('[checkResponse]');
236 |
237 | if(timerID.hasOwnProperty(rqi)) {
238 | delete timerID[rqi];
239 |
240 | if(socket != null) {
241 | socket.destroy();
242 | }
243 | }
244 |
245 | if(ss_fail_count.hasOwnProperty(ri)) {
246 | ss_fail_count[ri]++;
247 | console.log('=XXXXX=> [' + ss_fail_count[ri] + '] ' + ri);
248 |
249 | // if (ss_fail_count[ri] >= MAX_NUM_RETRY) {
250 | // delete_sub(ri, rqi);
251 | // console.log(' [sgn_man] remove subscription because no response');
252 | // }
253 | }
254 | }
255 |
256 | function request_noti_coap(nu, ri, bodyString, bodytype, xm2mri) {
257 | var options = {
258 | host: url.parse(nu).hostname,
259 | port: url.parse(nu).port,
260 | pathname: url.parse(nu).path,
261 | method: 'post',
262 | confirmable: 'false',
263 | options: {
264 | 'Accept': 'application/'+bodytype,
265 | 'Content-Type': 'application/'+bodytype,
266 | 'Content-Length' : bodyString.length
267 | }
268 | };
269 |
270 | var responseBody = '';
271 | var req = coap.request(options);
272 | req.setOption("256", new Buffer(usecseid)); // X-M2M-Origin
273 | req.setOption("257", new Buffer(xm2mri)); // X-M2M-RI
274 | req.on('response', function (res) {
275 | res.on('data', function () {
276 | responseBody += res.payload.toString();
277 | });
278 |
279 | res.on('end', function () {
280 | // if(res.code == '2.03' || res.code == '2.01') {
281 | // //console.log('----> [request_noti_coap] response for notification through coap ' + res.code + ' - ' + ri);
282 | // delete ss_fail_count[ri];
283 | // }
284 |
285 | if(timerID.hasOwnProperty(xm2mri)) {
286 | clearTimeout(timerID[xm2mri]);
287 | delete timerID[xm2mri];
288 | }
289 |
290 | if(ss_fail_count.hasOwnProperty(ri)) {
291 | console.log('=======> [response_noti_coap] - ' + ri);
292 | delete ss_fail_count[ri];
293 | }
294 | });
295 | });
296 |
297 | req.on('error', function (e) {
298 | //console.log('[request_noti_coap] problem with request: ' + e.message);
299 | });
300 |
301 | req.on('socket',function(socket) {
302 | console.log('<======= [request_noti_coap] - socket event - ' + ri + ' - ' + xm2mri);
303 | timerID[xm2mri] = setTimeout(checkResponse, resp_timeout, ri, xm2mri, socket);
304 | });
305 |
306 | console.log(bodyString);
307 | req.write(bodyString);
308 | req.end();
309 | }
310 |
311 | var timerID = {};
312 | function request_noti_mqtt(nu, ri, bodyString, bodytype, xm2mri) {
313 | try {
314 | resp_mqtt_rqi_arr[xm2mri] = ri;
315 |
316 | var aeid = url.parse(nu).pathname.replace('/', '').split('?')[0];
317 | var noti_resp_topic = '/oneM2M/resp/' + usecseid.replace('/', '') + '/' + aeid + '/' + bodytype;
318 |
319 | sgn_mqtt_client.subscribe(noti_resp_topic);
320 | console.log('subscribe noti_resp_topic as ' + noti_resp_topic);
321 |
322 | var noti_topic = '/oneM2M/req/' + usecseid.replace('/', '') + '/' + aeid + '/' + bodytype;
323 | sgn_mqtt_client.publish(noti_topic, bodyString);
324 |
325 | timerID[xm2mri] = setTimeout(checkResponseMqtt, resp_timeout, ri, noti_resp_topic, xm2mri);
326 |
327 | console.log('<======= [request_noti_mqtt - ' + ri + '] publish - ' + noti_topic);
328 | //console.log(bodyString);
329 | }
330 | catch (e) {
331 | console.log(e.message);
332 | console.log('can not send notification to ' + nu);
333 | }
334 | }
335 |
336 | function checkResponseMqtt(ri, resp_topic, rqi) {
337 | console.log('[checkResponseMqtt]');
338 |
339 | if(timerID.hasOwnProperty(rqi)) {
340 | delete timerID[rqi];
341 | // sgn_mqtt_client.unsubscribe(resp_topic);
342 | }
343 |
344 | if(resp_mqtt_rqi_arr.hasOwnProperty(rqi)) {
345 | delete resp_mqtt_rqi_arr[rqi];
346 | }
347 |
348 | if(ss_fail_count.hasOwnProperty(ri)) {
349 | ss_fail_count[ri]++;
350 | console.log('=XXXXX=> [' + ss_fail_count[ri] + '] ' + ri);
351 |
352 | // if (ss_fail_count[ri] >= MAX_NUM_RETRY) {
353 | // delete_sub(ri, rqi);
354 | // console.log(' [sgn_man] remove subscription because no response');
355 | // }
356 | }
357 | }
358 |
359 | function request_noti_ws(nu, ri, bodyString, bodytype, xm2mri) {
360 | var bodyStr = '';
361 |
362 | if(use_secure == 'disable') {
363 | var WebSocketClient = require('websocket').client;
364 | var ws_client = new WebSocketClient();
365 |
366 | if(bodytype == 'xml') {
367 | ws_client.connect(nu, 'onem2m.r2.0.xml');
368 | }
369 | else if(bodytype == 'cbor') {
370 | ws_client.connect(nu, 'onem2m.r2.0.cbor');
371 | }
372 | else {
373 | ws_client.connect(nu, 'onem2m.r2.0.json');
374 | }
375 |
376 | ws_client.on('connectFailed', function (error) {
377 | ss_fail_count[ri]++;
378 | console.log('Connect Error: ' + error.toString() + ' - ' + ss_fail_count[ri]);
379 | ws_client.removeAllListeners();
380 | });
381 |
382 | ws_client.on('connect', function (conn) {
383 | console.log('<======= [request_noti_ws] - connection - ' + ri + ' - ' + xm2mri);
384 | timerID[xm2mri] = setTimeout(checkResponse, resp_timeout, ri, xm2mri, conn);
385 |
386 | conn.sendUTF(bodyString);
387 |
388 | conn.on('error', function (error) {
389 | //console.log("[request_noti_ws] Connection Error: " + error.toString());
390 |
391 | });
392 | conn.on('close', function () {
393 | //console.log('[request_noti_ws] Connection Closed');
394 | });
395 | conn.on('message', function (message) {
396 | console.log(message.utf8Data.toString());
397 |
398 | //console.log('----> [request_noti_ws] ' + message.utf8Data.toString());
399 |
400 | //delete ss_fail_count[ri];
401 |
402 | if(timerID.hasOwnProperty(xm2mri)) {
403 | clearTimeout(timerID[xm2mri]);
404 | delete timerID[xm2mri];
405 | }
406 |
407 | if(ss_fail_count.hasOwnProperty(ri)) {
408 | console.log('=======> [response_noti_ws] - ' + ri);
409 | delete ss_fail_count[ri];
410 | }
411 |
412 | conn.close();
413 | });
414 | });
415 | }
416 | else {
417 | console.log('[request_noti_ws] not support secure notification through ws');
418 | }
419 | }
420 |
421 |
422 |
423 | function delete_sub(ri, xm2mri, parentObj) {
424 | db.getConnection(function (code, connection) {
425 | if(code === '200') {
426 | for (var idx in parentObj.subl) {
427 | if (parentObj.subl.hasOwnProperty(idx)) {
428 | if (parentObj.subl[idx].ri == ri) {
429 | parentObj.subl.splice(idx, 1);
430 | }
431 | }
432 | }
433 |
434 | db_sql.update_lookup(connection, parentObj, function (err, results) {
435 | if (!err) {
436 | db_sql.delete_ri_lookup(connection, ri, function () {
437 | console.log(' [sgn_man] remove subscription because no response');
438 | parentObj = null;
439 | connection.release();
440 | });
441 | }
442 | else {
443 | connection.release();
444 | }
445 | });
446 | }
447 | else {
448 | console.log('[delete_sub] - No Connection');
449 | }
450 | });
451 | }
452 |
--------------------------------------------------------------------------------
/mobius/smd.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2018, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file
13 | * @copyright KETI Korea 2018, KETI
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | */
16 |
17 | var url = require('url');
18 | var xml2js = require('xml2js');
19 | var xmlbuilder = require('xmlbuilder');
20 | var util = require('util');
21 | var responder = require('./responder');
22 | var http = require('http');
23 | var https = require('https');
24 | var fs = require('fs');
25 |
26 |
27 | exports.build_smd = function(request, response, resource_Obj, body_Obj, callback) {
28 | var rootnm = request.headers.rootnm;
29 |
30 | // body
31 | resource_Obj[rootnm].dsp = body_Obj[rootnm].dsp;
32 | resource_Obj[rootnm].dcrp = body_Obj[rootnm].dcrp;
33 |
34 | resource_Obj[rootnm].or = (body_Obj[rootnm].or) ? body_Obj[rootnm].or : '';
35 | resource_Obj[rootnm].cr = (body_Obj[rootnm].cr) ? body_Obj[rootnm].cr : request.headers['x-m2m-origin'];
36 | resource_Obj[rootnm].soe = (body_Obj[rootnm].soe) ? body_Obj[rootnm].soe : '';
37 | resource_Obj[rootnm].rels = (body_Obj[rootnm].rels) ? body_Obj[rootnm].rels : [];
38 |
39 | request.resourceObj = JSON.parse(JSON.stringify(resource_Obj));
40 | resource_Obj = null;
41 |
42 | callback('200');
43 | };
44 |
45 |
46 | exports.request_post = function(uri, bodyString) {
47 | var options = {
48 | hostname: usesemanticbroker,
49 | port: 7591,
50 | path: '',
51 | method: 'POST',
52 | headers: {
53 | 'Content-Type': 'application/json'
54 | }
55 | };
56 |
57 | var bodyStr = '';
58 |
59 | var req = http.request(options, function (res) {
60 | res.on('data', function (chunk) {
61 | bodyStr += chunk;
62 | });
63 |
64 | res.on('end', function () {
65 | console.log('----> [smd.request_post()] response for smd ' + res.statusCode);
66 | });
67 | });
68 |
69 | req.on('error', function (e) {
70 | console.log('[smd.request_post()] problem with request: ' + e.message);
71 | });
72 |
73 | req.on('close', function() {
74 | console.log('[smd.request_post()] close()');
75 | });
76 |
77 | console.log('<---- [smd.request_post()] request for smd');
78 | req.write(bodyString);
79 | req.end();
80 | };
81 |
82 |
83 | exports.request_get_discovery = function(request, response, callback) {
84 | var options = {
85 | hostname: usesemanticbroker,
86 | port: 7591,
87 | path: '',
88 | method: 'GET',
89 | headers: {
90 | 'smf': encodeURI(request.query.smf)
91 | }
92 | };
93 |
94 | var bodyStr = '';
95 |
96 | var req = http.request(options, function (res) {
97 | res.on('data', function (chunk) {
98 | bodyStr += chunk;
99 | });
100 |
101 | res.on('end', function () {
102 | console.log('----> [smd.request_post()] response for smd ' + res.statusCode);
103 | callback(response, res.statusCode, bodyStr);
104 |
105 | var ri_list = bodyStr.split(',');
106 | if (res.statusCode == 200) {
107 | make_cse_relative(ri_list);
108 | request.headers.rootnm = 'uril';
109 | request.resourceObj = {};
110 | request.resourceObj.uril = {};
111 | request.resourceObj.uril = ri_list;
112 |
113 | callback('200-1');
114 | }
115 | else {
116 | if(res.statusCode == 400) {
117 | callback('400-41');
118 | }
119 | else {
120 | callback('404-2');
121 | }
122 | }
123 | });
124 | });
125 |
126 | req.on('error', function (e) {
127 | console.log('[smd.request_post()] problem with request: ' + e.message);
128 |
129 | callback('404-2');
130 | });
131 |
132 | req.on('close', function() {
133 | console.log('[smd.request_post()] close()');
134 | });
135 |
136 | console.log('<---- [smd.request_post()] request for smd');
137 | req.write('');
138 | req.end();
139 | };
140 |
141 | // exports.modify_sd = function(request, response, resource_Obj, body_Obj, callback) {
142 | // var rootnm = request.headers.rootnm;
143 | //
144 | // // check M
145 | // for (var attr in update_m_attr_list[rootnm]) {
146 | // if (update_m_attr_list[rootnm].hasOwnProperty(attr)) {
147 | // if (body_Obj[rootnm].includes(attr)) {
148 | // }
149 | // else {
150 | // body_Obj = {};
151 | // body_Obj['dbg'] = 'BAD REQUEST: ' + attr + ' is \'Mandatory\' attribute';
152 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
153 | // callback('0', resource_Obj);
154 | // return '0';
155 | // }
156 | // }
157 | // }
158 | //
159 | // // check NP and body
160 | // for (attr in body_Obj[rootnm]) {
161 | // if (body_Obj[rootnm].hasOwnProperty(attr)) {
162 | // if (update_np_attr_list[rootnm].includes(attr)) {
163 | // body_Obj = {};
164 | // body_Obj['dbg'] = 'BAD REQUEST: ' + attr + ' is \'Not Present\' attribute';
165 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
166 | // callback('0', resource_Obj);
167 | // return '0';
168 | // }
169 | // else {
170 | // if (update_opt_attr_list[rootnm].includes(attr)) {
171 | // }
172 | // else {
173 | // body_Obj = {};
174 | // body_Obj['dbg'] = 'NOT FOUND: ' + attr + ' attribute is not defined';
175 | // responder.response_result(request, response, 404, body_Obj, 4004, request.url, body_Obj['dbg']);
176 | // callback('0', resource_Obj);
177 | // return '0';
178 | // }
179 | // }
180 | // }
181 | // }
182 | //
183 | // update_body(rootnm, body_Obj, resource_Obj); // (attr == 'aa' || attr == 'poa' || attr == 'lbl' || attr == 'acpi' || attr == 'srt' || attr == 'nu' || attr == 'mid' || attr == 'macp')
184 | //
185 | // resource_Obj[rootnm].st = (parseInt(resource_Obj[rootnm].st, 10) + 1).toString();
186 | //
187 | // var cur_d = new Date();
188 | // resource_Obj[rootnm].lt = cur_d.toISOString().replace(/-/, '').replace(/-/, '').replace(/:/, '').replace(/:/, '').replace(/\..+/, '');
189 | //
190 | // if (resource_Obj[rootnm].et != '') {
191 | // if (resource_Obj[rootnm].et < resource_Obj[rootnm].ct) {
192 | // body_Obj = {};
193 | // body_Obj['dbg'] = 'expiration time is before now';
194 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
195 | // callback('0', resource_Obj);
196 | // return '0';
197 | // }
198 | // }
199 | //
200 | // callback('1', resource_Obj);
201 | // };
202 |
203 |
--------------------------------------------------------------------------------
/mobius/sub.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2018, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file
13 | * @copyright KETI Korea 2018, KETI
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | */
16 |
17 |
18 | var url = require('url');
19 | var xml2js = require('xml2js');
20 | var xmlbuilder = require('xmlbuilder');
21 | var util = require('util');
22 | var responder = require('./responder');
23 | var db_sql = require('./sql_action');
24 |
25 | function verify_nu(request, response, body_Obj, req_count, callback) {
26 | var rootnm = request.headers.rootnm;
27 | var nu_arr = body_Obj[rootnm].nu;
28 |
29 | if(req_count == nu_arr.length) {
30 | callback('200');
31 | return;
32 | }
33 |
34 | var nu = nu_arr[req_count];
35 | var sub_nu = url.parse(nu);
36 | if(sub_nu.protocol == null) { // ID format
37 | if (nu.charAt(0) != '/') {
38 | var absolute_url = '/' + nu;
39 | }
40 | else {
41 | absolute_url = nu.replace(/\/\/[^\/]+\/?/, '\/');
42 | absolute_url = absolute_url.replace(/\/[^\/]+\/?/, '/');
43 | }
44 |
45 | var absolute_url_arr = absolute_url.split('/');
46 |
47 | db_sql.get_ri_sri(request.db_connection, absolute_url_arr[1].split('?')[0], function (err, results) {
48 | if (err) {
49 | callback('500-2');
50 | }
51 | else {
52 | absolute_url = (results.length == 0) ? absolute_url : ((results[0].hasOwnProperty('ri')) ? absolute_url.replace('/' + absolute_url_arr[1], results[0].ri) : absolute_url);
53 |
54 | results = null;
55 | db_sql.select_ri_lookup(request.db_connection, absolute_url, function (err, results_ri) {
56 | if (results_ri.length == 0) {
57 | callback('500-2');
58 | return;
59 | }
60 |
61 | results_ri = null;
62 | verify_nu(request, response, body_Obj, ++req_count, function (code) {
63 | callback(code);
64 | });
65 | });
66 | }
67 | });
68 | }
69 | else {
70 | verify_nu(request, response, body_Obj, ++req_count, function (code) {
71 | callback(code);
72 | });
73 | }
74 | }
75 |
76 | exports.build_sub = function(request, response, resource_Obj, body_Obj, callback) {
77 | var rootnm = request.headers.rootnm;
78 |
79 | // body
80 |
81 | // verify nu
82 | verify_nu(request, response, body_Obj, 0, function (code) {
83 | if(code === '200') {
84 | resource_Obj[rootnm].nu = body_Obj[rootnm].nu;
85 |
86 | resource_Obj[rootnm].enc = (body_Obj[rootnm].enc) ? body_Obj[rootnm].enc : {"net": ["1"]};
87 | resource_Obj[rootnm].exc = (body_Obj[rootnm].exc) ? body_Obj[rootnm].exc : '100';
88 | resource_Obj[rootnm].gpi = (body_Obj[rootnm].gpi) ? body_Obj[rootnm].gpi : '';
89 | resource_Obj[rootnm].nfu = (body_Obj[rootnm].nfu) ? body_Obj[rootnm].nfu : '';
90 | resource_Obj[rootnm].bn = (body_Obj[rootnm].bn) ? body_Obj[rootnm].bn : {};
91 | resource_Obj[rootnm].rl = (body_Obj[rootnm].rl) ? body_Obj[rootnm].rl : '';
92 | resource_Obj[rootnm].psn = (body_Obj[rootnm].psn) ? body_Obj[rootnm].psn : '';
93 | resource_Obj[rootnm].pn = (body_Obj[rootnm].pn) ? body_Obj[rootnm].pn : '';
94 | resource_Obj[rootnm].nsp = (body_Obj[rootnm].nsp) ? body_Obj[rootnm].nsp : '';
95 | resource_Obj[rootnm].ln = (body_Obj[rootnm].ln) ? body_Obj[rootnm].ln : '';
96 | resource_Obj[rootnm].nct = (body_Obj[rootnm].nct) ? body_Obj[rootnm].nct : '2';
97 | resource_Obj[rootnm].nec = (body_Obj[rootnm].nec) ? body_Obj[rootnm].nec : '';
98 | resource_Obj[rootnm].su = (body_Obj[rootnm].su) ? body_Obj[rootnm].su : '';
99 | resource_Obj[rootnm].cr = (body_Obj[rootnm].cr) ? body_Obj[rootnm].cr : request.headers['x-m2m-origin'];
100 |
101 | request.resourceObj = JSON.parse(JSON.stringify(resource_Obj));
102 | resource_Obj = null;
103 |
104 | callback(code);
105 | }
106 | else {
107 | callback(code)
108 | }
109 | });
110 | };
111 |
112 |
113 | // exports.modify_sub = function(request, response, resource_Obj, body_Obj, callback) {
114 | // var rootnm = request.headers.rootnm;
115 | //
116 | // // check M
117 | // for (var attr in update_m_attr_list[rootnm]) {
118 | // if (update_m_attr_list[rootnm].hasOwnProperty(attr)) {
119 | // if (body_Obj[rootnm].includes(attr)) {
120 | // }
121 | // else {
122 | // body_Obj = {};
123 | // body_Obj['dbg'] = 'BAD REQUEST: ' + attr + ' is \'Mandatory\' attribute';
124 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
125 | // callback('0', resource_Obj);
126 | // return '0';
127 | // }
128 | // }
129 | // }
130 | //
131 | // // check NP and body
132 | // for (attr in body_Obj[rootnm]) {
133 | // if (body_Obj[rootnm].hasOwnProperty(attr)) {
134 | // if (update_np_attr_list[rootnm].includes(attr)) {
135 | // body_Obj = {};
136 | // body_Obj['dbg'] = 'BAD REQUEST: ' + attr + ' is \'Not Present\' attribute';
137 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
138 | // callback('0', resource_Obj);
139 | // return '0';
140 | // }
141 | // else {
142 | // if (update_opt_attr_list[rootnm].includes(attr)) {
143 | // }
144 | // else {
145 | // body_Obj = {};
146 | // body_Obj['dbg'] = 'NOT FOUND: ' + attr + ' attribute is not defined';
147 | // responder.response_result(request, response, 404, body_Obj, 4004, request.url, body_Obj['dbg']);
148 | // callback('0', resource_Obj);
149 | // return '0';
150 | // }
151 | // }
152 | // }
153 | // }
154 | //
155 | // update_body(rootnm, body_Obj, resource_Obj); // (attr == 'aa' || attr == 'poa' || attr == 'lbl' || attr == 'acpi' || attr == 'srt' || attr == 'nu' || attr == 'mid' || attr == 'macp')
156 | //
157 | // resource_Obj[rootnm].st = (parseInt(resource_Obj[rootnm].st, 10) + 1).toString();
158 | //
159 | // var cur_d = new Date();
160 | // resource_Obj[rootnm].lt = cur_d.toISOString().replace(/-/, '').replace(/-/, '').replace(/:/, '').replace(/:/, '').replace(/\..+/, '');
161 | //
162 | // if (resource_Obj[rootnm].et != '') {
163 | // if (resource_Obj[rootnm].et < resource_Obj[rootnm].ct) {
164 | // body_Obj = {};
165 | // body_Obj['dbg'] = 'expiration time is before now';
166 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
167 | // callback('0', resource_Obj);
168 | // return '0';
169 | // }
170 | // }
171 | //
172 | // callback('1', resource_Obj);
173 | // };
174 |
175 |
176 |
--------------------------------------------------------------------------------
/mobius/tr.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2018, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file
13 | * @copyright KETI Korea 2018, KETI
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | */
16 |
17 | var url = require('url');
18 | var xml2js = require('xml2js');
19 | var xmlbuilder = require('xmlbuilder');
20 | var util = require('util');
21 | var responder = require('./responder');
22 | var http = require('http');
23 | var https = require('https');
24 | var fs = require('fs');
25 |
26 | var db_sql = require('./sql_action');
27 |
28 | global.tctl_v = {};
29 | tctl_v.INITIAL = '1';
30 | tctl_v.LOCK = '2';
31 | tctl_v.EXECUTE = '3';
32 | tctl_v.COMMIT = '4';
33 | tctl_v.ABORT = '5';
34 |
35 | global.tst_v = {};
36 | tst_v.INITIAL = '1';
37 | tst_v.LOCKED = '2';
38 | tst_v.EXECUTED = '3';
39 | tst_v.COMMITTED = '4';
40 | tst_v.ERROR = '5';
41 | tst_v.ABORTED = '6';
42 |
43 | exports.build_tr = function(request, response, resource_Obj, body_Obj, callback) {
44 | var rootnm = request.headers.rootnm;
45 |
46 | // body
47 | resource_Obj[rootnm].cr = (body_Obj[rootnm].cr) ? body_Obj[rootnm].cr : request.headers['x-m2m-origin'];
48 |
49 | resource_Obj[rootnm].tid = body_Obj[rootnm].tid;
50 | resource_Obj[rootnm].trqp = body_Obj[rootnm].trqp;
51 |
52 | resource_Obj[rootnm].tctl = (body_Obj[rootnm].tctl) ? body_Obj[rootnm].tctl : tctl_v.LOCK; // LOCK
53 | resource_Obj[rootnm].tst = (body_Obj[rootnm].tst) ? body_Obj[rootnm].tst : tst_v.LOCKED;
54 |
55 | resource_Obj[rootnm].tltm = (body_Obj[rootnm].tltm) ? body_Obj[rootnm].tltm : '';
56 | resource_Obj[rootnm].text = (body_Obj[rootnm].text) ? body_Obj[rootnm].text : '';
57 | resource_Obj[rootnm].tct = (body_Obj[rootnm].tct) ? body_Obj[rootnm].tct : '';
58 | resource_Obj[rootnm].tltp = (body_Obj[rootnm].tltp) ? body_Obj[rootnm].tltp : tltp_v.BLOCK_ALL; // BLOCK_ALL
59 | resource_Obj[rootnm].trqp = (body_Obj[rootnm].trqp) ? body_Obj[rootnm].trqp : '';
60 | resource_Obj[rootnm].trsp = (body_Obj[rootnm].trsp) ? body_Obj[rootnm].trsp : '';
61 |
62 | request.resourceObj = JSON.parse(JSON.stringify(resource_Obj));
63 | resource_Obj = null;
64 |
65 | callback('200');
66 | };
67 |
68 | function execute_action(ri, bodytype, res, resBody, callback) {
69 | console.log('EXECUTE of transaction'); //callback(res.headers['x-m2m-rsc'], resBody);
70 | console.log(resBody);
71 |
72 | if (res.headers['x-m2m-rsc'] == 2001 || res.headers['x-m2m-rsc'] == 2000 || res.headers['x-m2m-rsc'] == 2004 || res.headers['x-m2m-rsc'] == 2002) {
73 | var tst_value = tst_v.EXECUTED;
74 | }
75 | else {
76 | tst_value = tst_v.ABORTED;
77 | }
78 |
79 | callback('1', tst_value);
80 | }
81 |
82 | exports.request_execute = function(obj, callback) {
83 | var rqi = require('shortid').generate();
84 | var content_type = 'application/json';
85 | var bodytype = 'json';
86 |
87 | switch (obj.tr.trqp.op.toString()) {
88 | case '1':
89 | var op = 'post';
90 | content_type += (obj.tr.trqp.ty)?('; ty=' + obj.tr.trqp.ty):'';
91 | break;
92 | case '2':
93 | op = 'get';
94 | break;
95 | case '3':
96 | op = 'put';
97 | break;
98 | case '4':
99 | op = 'delete';
100 | break;
101 | }
102 |
103 | var reqBodyString = '';
104 | if( op === 'post' || op === 'put') {
105 | if (bodytype === 'xml') {
106 | obj.tr.trqp.pc[Object.keys(obj.tr.trqp.pc)[0]]['@'] = {
107 | "xmlns:m2m": "http://www.onem2m.org/xml/protocols",
108 | "xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance"
109 | };
110 |
111 | for (var prop in obj.tr.trqp.pc) {
112 | if (obj.tr.trqp.pc.hasOwnProperty(prop)) {
113 | for (var prop2 in obj.tr.trqp.pc[prop]) {
114 | if (obj.tr.trqp.pc[prop].hasOwnProperty(prop2)) {
115 | if (prop2 == 'rn') {
116 | obj.tr.trqp.pc[prop]['@'] = {rn: obj.tr.trqp.pc[prop][prop2]};
117 | delete obj.tr.trqp.pc[prop][prop2];
118 | break;
119 | }
120 | }
121 | }
122 | }
123 | }
124 |
125 | try {
126 | reqBodyString = js2xmlparser.parse(Object.keys(obj.tr.trqp.pc)[0], obj.tr.trqp.pc[Object.keys(obj.tr.trqp.pc)[0]]);
127 | }
128 | catch (e) {
129 | reqBodyString = "";
130 | }
131 | }
132 | else { // json
133 | reqBodyString = JSON.stringify(obj.tr.trqp.pc);
134 | }
135 | }
136 |
137 | var resBody = '';
138 |
139 | if (obj.tr.trqp.to.split(usespid + usecseid + '/')[0] == '') { // absolute relative
140 | obj.tr.trqp.to = obj.tr.trqp.to.replace(usespid + usecseid + '/', '/');
141 | }
142 | else if (obj.tr.trqp.to.split(usecseid + '/' + usecsebase + '/')[0] == '') { // sp relative
143 | obj.tr.trqp.to = obj.tr.trqp.to.replace(usecseid + '/', '/');
144 | }
145 | else if (obj.tr.trqp.to.split(usecsebase)[0] == '') { // cse relative
146 | obj.tr.trqp.to = '/' + obj.tr.trqp.to;
147 | }
148 |
149 | var options = {
150 | hostname: 'localhost',
151 | port: usecsebaseport,
152 | path: obj.tr.trqp.to + '?tctl=3&tid=' + obj.tr.tid,
153 | method: op,
154 | headers: {
155 | 'X-M2M-RI': rqi,
156 | 'Accept': 'application/json',
157 | 'X-M2M-Origin': obj.tr.trqp.fr,
158 | 'Content-Type': content_type,
159 | 'X-M2M-RVI': uservi
160 | }
161 | };
162 |
163 | if (use_secure == 'disable') {
164 | var req = http.request(options, function (res) {
165 | res.on('data', function (chunk) {
166 | resBody += chunk;
167 | });
168 |
169 | res.on('end', function () {
170 | execute_action(obj.tr.ri, bodytype, res, resBody, function(rsc, tst) {
171 | obj.tr.tst = tst;
172 | callback(rsc, obj);
173 | });
174 | });
175 | });
176 | }
177 | else {
178 | options.ca = fs.readFileSync('ca-crt.pem');
179 |
180 | req = https.request(options, function (res) {
181 | res.on('data', function (chunk) {
182 | resBody += chunk;
183 | });
184 |
185 | res.on('end', function () {
186 | execute_action(obj.tr.ri, bodytype, res, resBody, function(rsc, tst) {
187 | obj.tr.tst = tst;
188 | callback(rsc, obj);
189 | });
190 | });
191 | });
192 | }
193 |
194 | req.on('error', function (e) {
195 | if (e.message != 'read ECONNRESET') {
196 | console.log('[delete_TS] problem with request: ' + e.message);
197 | }
198 | });
199 |
200 | // write data to request body
201 | req.write(reqBodyString);
202 | req.end();
203 | };
204 |
205 | function trsp_action(ri, bodytype, res, resBody, callback) {
206 | console.log('COMMIT of transaction'); //callback(res.headers['x-m2m-rsc'], resBody);
207 | console.log(resBody);
208 |
209 | if (res.headers['x-m2m-rsc'] == 2001 || res.headers['x-m2m-rsc'] == 2000 || res.headers['x-m2m-rsc'] == 2004 || res.headers['x-m2m-rsc'] == 2002) {
210 | var tst_value = tst_v.COMMITTED;
211 | }
212 | else {
213 | tst_value = tst_v.ABORTED;
214 | }
215 |
216 | if (bodytype === 'xml') {
217 | try {
218 | var parser = new xml2js.Parser({explicitArray: false});
219 | parser.parseString(resBody, function (err, body_Obj) {
220 | var trsp_primitive = {};
221 | trsp_primitive.rsc = parseInt(res.headers['x-m2m-rsc']); // convert to int
222 | trsp_primitive.rqi = res.headers['x-m2m-ri'];
223 | trsp_primitive.pc = JSON.parse(body_Obj.toString());
224 |
225 | callback('1', tst_value, trsp_primitive);
226 | });
227 | }
228 | catch (e) {
229 | trsp_primitive = {};
230 | trsp_primitive.rsc = parseInt(res.headers['x-m2m-rsc']); // convert to int
231 | trsp_primitive.rqi = res.headers['x-m2m-ri'];
232 | trsp_primitive.pc = JSON.parse(resBody.toString());
233 | callback('1', tst_value, trsp_primitive);
234 | }
235 | }
236 | else if (bodytype === 'cbor') {
237 | }
238 | else {
239 | try {
240 | var trsp_primitive = {};
241 | trsp_primitive.rsc = parseInt(res.headers['x-m2m-rsc']); // convert to int
242 | trsp_primitive.rqi = res.headers['x-m2m-ri'];
243 | trsp_primitive.pc = JSON.parse(resBody.toString());
244 |
245 | callback('1', tst_value, trsp_primitive);
246 | }
247 | catch (e) {
248 | trsp_primitive = {};
249 | trsp_primitive.rsc = parseInt(res.headers['x-m2m-rsc']); // convert to int
250 | trsp_primitive.rqi = res.headers['x-m2m-ri'];
251 | trsp_primitive.pc = JSON.parse(resBody.toString());
252 | callback('1', tst_value, trsp_primitive);
253 | }
254 | }
255 | }
256 |
257 | exports.request_commit = function(obj, callback) {
258 | var rqi = require('shortid').generate();
259 | obj.tr.trqp.rqi = rqi;
260 |
261 | var content_type = 'application/json';
262 | var bodytype = 'json';
263 |
264 | switch (obj.tr.trqp.op.toString()) {
265 | case '1':
266 | var op = 'post';
267 | content_type += (obj.tr.trqp.ty)?('; ty=' + obj.tr.trqp.ty):'';
268 | break;
269 | case '2':
270 | op = 'get';
271 | break;
272 | case '3':
273 | op = 'put';
274 | break;
275 | case '4':
276 | op = 'delete';
277 | break;
278 | }
279 |
280 | var reqBodyString = '';
281 | if( op === 'post' || op === 'put') {
282 | if (bodytype === 'xml') {
283 | obj.tr.trqp.pc[Object.keys(obj.tr.trqp.pc)[0]]['@'] = {
284 | "xmlns:m2m": "http://www.onem2m.org/xml/protocols",
285 | "xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance"
286 | };
287 |
288 | for (var prop in obj.tr.trqp.pc) {
289 | if (obj.tr.trqp.pc.hasOwnProperty(prop)) {
290 | for (var prop2 in obj.tr.trqp.pc[prop]) {
291 | if (obj.tr.trqp.pc[prop].hasOwnProperty(prop2)) {
292 | if (prop2 == 'rn') {
293 | obj.tr.trqp.pc[prop]['@'] = {rn: obj.tr.trqp.pc[prop][prop2]};
294 | delete obj.tr.trqp.pc[prop][prop2];
295 | break;
296 | }
297 | }
298 | }
299 | }
300 | }
301 |
302 | try {
303 | reqBodyString = js2xmlparser.parse(Object.keys(obj.tr.trqp.pc)[0], obj.tr.trqp.pc[Object.keys(obj.tr.trqp.pc)[0]]);
304 | }
305 | catch (e) {
306 | reqBodyString = "";
307 | }
308 | }
309 | else { // json
310 | reqBodyString = JSON.stringify(obj.tr.trqp.pc);
311 | }
312 | }
313 |
314 | var resBody = '';
315 |
316 | if (obj.tr.trqp.to.split(usespid + usecseid + '/')[0] == '') { // absolute relative
317 | obj.tr.trqp.to = obj.tr.trqp.to.replace(usespid + usecseid + '/', '/');
318 | }
319 | else if (obj.tr.trqp.to.split(usecseid + '/' + usecsebase + '/')[0] == '') { // sp relative
320 | obj.tr.trqp.to = obj.tr.trqp.to.replace(usecseid + '/', '/');
321 | }
322 | else if (obj.tr.trqp.to.split(usecsebase)[0] == '') { // cse relative
323 | obj.tr.trqp.to = '/' + obj.tr.trqp.to;
324 | }
325 |
326 | var options = {
327 | hostname: 'localhost',
328 | port: usecsebaseport,
329 | path: obj.tr.trqp.to + '?tid=' + obj.tr.tid,
330 | method: op,
331 | headers: {
332 | 'X-M2M-RI': rqi,
333 | 'Accept': 'application/json',
334 | 'X-M2M-Origin': obj.tr.trqp.fr,
335 | 'Content-Type': content_type,
336 | 'X-M2M-RVI': uservi
337 | }
338 | };
339 |
340 | if (use_secure == 'disable') {
341 | var req = http.request(options, function (res) {
342 | res.on('data', function (chunk) {
343 | resBody += chunk;
344 | });
345 |
346 | res.on('end', function () {
347 | trsp_action(obj.tr.ri, bodytype, res, resBody, function(rsc, tst, trsp) {
348 | obj.tr.tst = tst;
349 | obj.tr.trsp = trsp;
350 | callback(rsc, obj);
351 | });
352 | });
353 | });
354 | }
355 | else {
356 | options.ca = fs.readFileSync('ca-crt.pem');
357 |
358 | req = https.request(options, function (res) {
359 | res.on('data', function (chunk) {
360 | resBody += chunk;
361 | });
362 |
363 | res.on('end', function () {
364 | trsp_action(obj.tr.ri, bodytype, res, resBody, function(rsc, tst, trsp) {
365 | obj.tr.tst = tst;
366 | obj.tr.trsp = trsp;
367 | callback(rsc, obj);
368 | });
369 | });
370 | });
371 | }
372 |
373 | req.on('error', function (e) {
374 | if (e.message != 'read ECONNRESET') {
375 | console.log('[delete_TS] problem with request: ' + e.message);
376 | }
377 | });
378 |
379 | // write data to request body
380 | req.write(reqBodyString);
381 | req.end();
382 | };
383 |
384 | exports.check = function(request, callback) {
385 | var pi = request.targetObject[Object.keys(request.targetObject)[0]].ri;
386 |
387 | var state = tst_v.COMMITTED;
388 | db_sql.select_tr(request.db_connection, pi, function (err, results_tr) {
389 | if (!err) {
390 | for (var i = 0; i < results_tr.length; i++) {
391 | if(request.query.tid == results_tr[i].tid) {
392 | results_tr = null;
393 | callback('200');
394 | return;
395 | }
396 |
397 | if (results_tr[i].hasOwnProperty('tltp')) {
398 | if(results_tr[i].tltp == tltp_v.BLOCK_ALL) {
399 | if (results_tr[i].hasOwnProperty('tst')) {
400 | if (results_tr[i].tst != tst_v.COMMITTED && results_tr[i].tst != tst_v.ABORTED) {
401 | state = results_tr[i].tst;
402 | break;
403 | }
404 | }
405 | }
406 | else if(results_tr[i].tltp == tltp_v.ALLOW_RETRIEVES) {
407 | if(request.method === 'GET') {
408 | state = tst_v.COMMITTED;
409 | break;
410 | }
411 | else {
412 | if (results_tr[i].hasOwnProperty('tst')) {
413 | if (results_tr[i].tst != tst_v.COMMITTED && results_tr[i].tst != tst_v.ABORTED) {
414 | state = results_tr[i].tst;
415 | break;
416 | }
417 | }
418 | }
419 | }
420 | }
421 | }
422 |
423 | if (state === tst_v.COMMITTED || state === tst_v.ABORTED) {
424 | results_tr = null;
425 | callback('200');
426 | }
427 | else {
428 | results_tr = null;
429 | callback('423-1');
430 | }
431 | }
432 | else {
433 | console.log('query error: ' + results_tr.message);
434 | results_tr = null;
435 | callback('200');
436 | }
437 | });
438 |
439 | };
440 |
--------------------------------------------------------------------------------
/mobius/ts.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2018, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file
13 | * @copyright KETI Korea 2018, KETI
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | */
16 |
17 | var url = require('url');
18 | var xml2js = require('xml2js');
19 | var xmlbuilder = require('xmlbuilder');
20 | var util = require('util');
21 | var http = require('http');
22 |
23 | var responder = require('./responder');
24 |
25 |
26 | var MISSINGDATAMAXNR = '1000';
27 |
28 | exports.build_ts = function(request, response, resource_Obj, body_Obj, callback) {
29 | var rootnm = request.headers.rootnm;
30 |
31 | // body
32 | resource_Obj[rootnm].mni = (body_Obj[rootnm].mni) ? body_Obj[rootnm].mni : '3153600000';
33 | if(parseInt(resource_Obj[rootnm].mni) >= 3153600000) {
34 | resource_Obj[rootnm].mni = '3153600000';
35 | }
36 |
37 | resource_Obj[rootnm].mbs = (body_Obj[rootnm].mbs) ? body_Obj[rootnm].mbs : '3153600000';
38 | resource_Obj[rootnm].mia = (body_Obj[rootnm].mia) ? body_Obj[rootnm].mia : '31536000';
39 | resource_Obj[rootnm].or = (body_Obj[rootnm].or) ? body_Obj[rootnm].or : '';
40 | resource_Obj[rootnm].cr = (body_Obj[rootnm].cr) ? body_Obj[rootnm].cr : request.headers['x-m2m-origin'];
41 |
42 | resource_Obj[rootnm].pei = (body_Obj[rootnm].pei) ? body_Obj[rootnm].pei : '0';
43 | resource_Obj[rootnm].mdd = (body_Obj[rootnm].mdd) ? body_Obj[rootnm].mdd : 'false';
44 | resource_Obj[rootnm].mdn = (body_Obj[rootnm].mdn) ? body_Obj[rootnm].mdn : MISSINGDATAMAXNR;
45 | resource_Obj[rootnm].mdlt = (body_Obj[rootnm].mdlt) ? body_Obj[rootnm].mdlt : '';
46 | resource_Obj[rootnm].mdc = (body_Obj[rootnm].mdc) ? body_Obj[rootnm].mdc : '0';
47 | resource_Obj[rootnm].mdt = (body_Obj[rootnm].mdt) ? body_Obj[rootnm].mdt : '0';
48 |
49 | resource_Obj[rootnm].cni = 0;
50 | resource_Obj[rootnm].cbs = 0;
51 |
52 | request.resourceObj = JSON.parse(JSON.stringify(resource_Obj));
53 | resource_Obj = null;
54 |
55 | callback('200');
56 | };
57 |
58 |
59 |
60 | // exports.modify_ts = function(request, response, resource_Obj, body_Obj, callback) {
61 | // var rootnm = request.headers.rootnm;
62 | //
63 | // // check M
64 | // for (var attr in update_m_attr_list[rootnm]) {
65 | // if (update_m_attr_list[rootnm].hasOwnProperty(attr)) {
66 | // if (body_Obj[rootnm].includes(attr)) {
67 | // }
68 | // else {
69 | // body_Obj = {};
70 | // body_Obj['dbg'] = 'BAD REQUEST: ' + attr + ' is \'Mandatory\' attribute';
71 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
72 | // callback('0', resource_Obj);
73 | // return '0';
74 | // }
75 | // }
76 | // }
77 | //
78 | // // check NP and body
79 | // for (attr in body_Obj[rootnm]) {
80 | // if (body_Obj[rootnm].hasOwnProperty(attr)) {
81 | // if (update_np_attr_list[rootnm].includes(attr)) {
82 | // body_Obj = {};
83 | // body_Obj['dbg'] = 'BAD REQUEST: ' + attr + ' is \'Not Present\' attribute';
84 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
85 | // callback('0', resource_Obj);
86 | // return '0';
87 | // }
88 | // else {
89 | // if (update_opt_attr_list[rootnm].includes(attr)) {
90 | // }
91 | // else {
92 | // body_Obj = {};
93 | // body_Obj['dbg'] = 'NOT FOUND: ' + attr + ' attribute is not defined';
94 | // responder.response_result(request, response, 404, body_Obj, 4004, request.url, body_Obj['dbg']);
95 | // callback('0', resource_Obj);
96 | // return '0';
97 | // }
98 | // }
99 | // }
100 | // }
101 | //
102 | // update_body(rootnm, body_Obj, resource_Obj); // (attr == 'aa' || attr == 'poa' || attr == 'lbl' || attr == 'acpi' || attr == 'srt' || attr == 'nu' || attr == 'mid' || attr == 'macp')
103 | //
104 | // resource_Obj[rootnm].st = (parseInt(resource_Obj[rootnm].st, 10) + 1).toString();
105 | //
106 | // if(resource_Obj[rootnm].mdt == '0') {
107 | // resource_Obj[rootnm].mdlt = '';
108 | // resource_Obj[rootnm].mdc = '0';
109 | // }
110 | //
111 | // var cur_d = new Date();
112 | // resource_Obj[rootnm].lt = cur_d.toISOString().replace(/-/, '').replace(/-/, '').replace(/:/, '').replace(/:/, '').replace(/\..+/, '');
113 | //
114 | // if (resource_Obj[rootnm].et != '') {
115 | // if (resource_Obj[rootnm].et < resource_Obj[rootnm].ct) {
116 | // body_Obj = {};
117 | // body_Obj['dbg'] = 'expiration time is before now';
118 | // responder.response_result(request, response, 400, body_Obj, 4000, request.url, body_Obj['dbg']);
119 | // callback('0', resource_Obj);
120 | // return '0';
121 | // }
122 | // }
123 | //
124 | // callback('1', resource_Obj);
125 | // };
126 |
--------------------------------------------------------------------------------
/mobius/ts_agent.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2018, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file Main code of Mobius Yellow. Role of flow router
13 | * @copyright KETI Korea 2018, KETI
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | */
16 |
17 | var fs = require('fs');
18 | var http = require('http');
19 | var https = require('https');
20 | var mysql = require('mysql');
21 | var express = require('express');
22 | var bodyParser = require('body-parser');
23 | var util = require('util');
24 | var xml2js = require('xml2js');
25 | var ip = require('ip');
26 | var js2xmlparser = require('js2xmlparser');
27 | var moment = require('moment');
28 |
29 | var db = require('./db_action');
30 | var db_sql = require('./sql_action');
31 |
32 | // ������ �����մϴ�.
33 | var ts_app = express();
34 |
35 | if(use_secure == 'disable') {
36 | http.globalAgent.maxSockets = 1000000;
37 | http.createServer(ts_app).listen({port: usetsagentport, agent: false}, function () {
38 | console.log('ts_missing agent server (' + ip.address() + ') running at ' + usetsagentport + ' port');
39 |
40 | // Searching TS with missingDetect. if it is TRUE, restart mdt
41 | init_TS(function (rsc) {
42 | console.log('init_TS - ' + rsc);
43 | });
44 | });
45 | }
46 | else {
47 | var options = {
48 | key: fs.readFileSync('server-key.pem'),
49 | cert: fs.readFileSync('server-crt.pem'),
50 | ca: fs.readFileSync('ca-crt.pem')
51 | };
52 | https.globalAgent.maxSockets = 1000000;
53 | https.createServer(options, ts_app).listen({port: usetsagentport, agent: false}, function () {
54 | console.log('ts_missing agent server (' + ip.address() + ') running at ' + usetsagentport + ' port');
55 |
56 | // Searching TS with missingDetect. if it is TRUE, restart mdt
57 | init_TS(function (rsc) {
58 | console.log('init_TS - ' + rsc);
59 | });
60 | });
61 | }
62 |
63 | function init_TS(callback) {
64 | var ri = '/missingDataDetect';
65 | var rqi = require('shortid').generate();
66 | //var reqBodyString = '';
67 | var jsonObj = {ts:{}};
68 | jsonObj.ts.ri = 'all';
69 | var reqBodyString = JSON.stringify(jsonObj);
70 |
71 | var responseBody = '';
72 |
73 | var options = {
74 | hostname: 'localhost',
75 | port: usetsagentport,
76 | path: ri,
77 | method: 'post',
78 | headers: {
79 | 'X-M2M-RI': rqi,
80 | 'Accept': 'application/json',
81 | 'X-M2M-Origin': usecseid,
82 | 'Content-Type': 'application/vnd.onem2m-res+json',
83 | 'X-M2M-RVI': uservi
84 | },
85 | rejectUnauthorized: false
86 | };
87 |
88 | if(use_secure == 'disable') {
89 | var req = http.request(options, function (res) {
90 | res.setEncoding('utf8');
91 | res.on('data', function (chunk) {
92 | responseBody += chunk;
93 | });
94 |
95 | res.on('end', function () {
96 | callback(res.headers['x-m2m-rsc'], responseBody);
97 | });
98 | });
99 | }
100 | else {
101 | options.ca = fs.readFileSync('ca-crt.pem');
102 |
103 | req = https.request(options, function (res) {
104 | res.setEncoding('utf8');
105 | res.on('data', function (chunk) {
106 | responseBody += chunk;
107 | });
108 |
109 | res.on('end', function () {
110 | callback(res.headers['x-m2m-rsc'], responseBody);
111 | });
112 | });
113 | }
114 |
115 | req.on('error', function (e) {
116 | if(e.message != 'read ECONNRESET') {
117 | console.log('[init_TS] problem with request: ' + e.message);
118 | }
119 | });
120 |
121 | // write data to request body
122 | req.write(reqBodyString);
123 | req.end();
124 | }
125 |
126 |
127 | function search_TS(request, response, callback) {
128 | var ri = '/' + usecsebase + '?fu=1&ty=29';
129 | var rqi = require('shortid').generate();
130 | var responseBody = '';
131 |
132 | var options = {
133 | hostname: 'localhost',
134 | port: usecsebaseport,
135 | path: ri,
136 | method: 'get',
137 | headers: {
138 | 'X-M2M-RI': rqi,
139 | 'Accept': 'application/json',
140 | 'X-M2M-Origin': usecseid,
141 | 'X-M2M-RVI': uservi
142 | },
143 | rejectUnauthorized: false
144 | };
145 |
146 | if(use_secure == 'disable') {
147 | var req = http.request(options, function (res) {
148 | res.setEncoding('utf8');
149 | res.on('data', function (chunk) {
150 | responseBody += chunk;
151 | });
152 |
153 | res.on('end', function () {
154 | callback(request, response, res.headers['x-m2m-rsc'], responseBody);
155 | });
156 | });
157 | }
158 | else {
159 | options.ca = fs.readFileSync('ca-crt.pem');
160 |
161 | req = https.request(options, function (res) {
162 | res.setEncoding('utf8');
163 | res.on('data', function (chunk) {
164 | responseBody += chunk;
165 | });
166 |
167 | res.on('end', function () {
168 | callback(request, response, res.headers['x-m2m-rsc'], responseBody);
169 | });
170 | });
171 | }
172 |
173 | req.on('error', function (e) {
174 | if(e.message != 'read ECONNRESET') {
175 | console.log('[search_TS] problem with request: ' + e.message);
176 | }
177 | });
178 |
179 | // write data to request body
180 | req.write('');
181 | req.end();
182 | }
183 |
184 |
185 | var onem2mParser = bodyParser.text(
186 | {
187 | limit: '1mb',
188 | type: 'application/onem2m-resource+xml;application/xml;application/json;application/vnd.onem2m-res+xml;application/vnd.onem2m-res+json'
189 | }
190 | );
191 |
192 | var ts_timer = {};
193 | var ts_timer_id = {};
194 |
195 | var missing_detect_check = function(connection, pei, mdd, mdt, cni, ri, callback) {
196 | var rsc = {};
197 | rsc.status = 2000;
198 | if((pei != null && pei != '' && pei != '0') && (mdd != null && mdd == 'TRUE') && mdt != '0') {
199 | if(ts_timer[ri] == null) {
200 | //ts_timer[ri] = new process.EventEmitter();
201 | var events = require('events');
202 | ts_timer[ri] = new events.EventEmitter();
203 | ts_timer[ri].on(ri, function () {
204 | db_sql.select_ts(connection, ri, function (err, results) {
205 | if (results.length == 1) {
206 | console.log(results[0].ri);
207 | var new_cni = results[0]['cni'];
208 | if (parseInt(new_cni, 10) == parseInt(cni, 10)) {
209 | if (parseInt(results[0].mdc, 10) <= parseInt(results[0].mdn, 10)) {
210 | var cur_d = new Date();
211 | var timestamp = cur_d.toISOString().replace(/-/, '').replace(/-/, '').replace(/:/, '').replace(/:/, '').replace(/\..+/, '');
212 | var mdlt = timestamp + ' ' + results[0].mdlt;
213 | var mdc = (parseInt(results[0].mdc, 10) + 1).toString();
214 | console.log(mdc, mdlt);
215 | db_sql.update_ts_mdcn_mdl(connection, mdc, mdlt, ri, function (err, results) {
216 | if (!err) {
217 | }
218 | else {
219 | console.log('query error: ' + results.message);
220 | }
221 | });
222 | }
223 | else {
224 | if(ts_timer_id[ri] != null) {
225 | clearInterval(ts_timer_id[ri]);
226 | delete ts_timer_id[ri];
227 | }
228 | }
229 | }
230 | cni = new_cni;
231 | }
232 | });
233 | });
234 | }
235 |
236 | if(ts_timer_id[ri] == null) {
237 | ts_timer_id[ri] = setInterval(function () {
238 | ts_timer[ri].emit(ri);
239 | }, (parseInt(mdt) * 1000));
240 | rsc.status = 2000;
241 | rsc.ri = ri;
242 | callback(rsc);
243 | }
244 | else if(ts_timer_id[ri] != null) {
245 | clearInterval(ts_timer_id[ri]);
246 | ts_timer_id[ri] = setInterval(function () {
247 | ts_timer[ri].emit(ri);
248 | }, (parseInt(mdt)*1000));
249 | rsc.status = 2000;
250 | rsc.ri = ri;
251 | callback(rsc);
252 | }
253 | else {
254 | rsc.status = 2001;
255 | rsc.ri = ri;
256 | callback(rsc);
257 | }
258 | }
259 | else {
260 | if(ts_timer_id[ri] != null) {
261 | clearInterval(ts_timer_id[ri]);
262 | delete ts_timer_id[ri];
263 | }
264 |
265 | rsc.status = 2001;
266 | rsc.ri = ri;
267 | callback(rsc);
268 | }
269 | };
270 |
271 |
272 | //
273 | ts_app.post('/missingDataDetect', onem2mParser, function(request, response) {
274 | var fullBody = '';
275 | request.on('data', function(chunk) {
276 | fullBody += chunk.toString();
277 | });
278 | request.on('end', function() {
279 | request.body = fullBody;
280 |
281 | db.getConnection(function (code, connection) {
282 | if(code === '200') {
283 | request.db_connection = connection;
284 |
285 | var jsonObj = JSON.parse(request.body);
286 | if (jsonObj.ts.ri == 'all') {
287 | search_TS(request, response, function (request, response, rsc, responseBody) {
288 | //console.log(rsc);
289 | //console.log(responseBody);
290 |
291 | var jsonObj = JSON.parse(responseBody);
292 | var ts_ri = [];
293 | if (jsonObj['m2m:dbg']) {
294 | ts_ri = [];
295 | }
296 | else if (jsonObj['m2m:uril']) {
297 | if (jsonObj['m2m:uril'].hasOwnProperty('_')) {
298 | ts_ri = jsonObj['m2m:uril']['_'].toString().split(' ');
299 | }
300 | else {
301 | ts_ri = [];
302 | }
303 | }
304 |
305 | var ts = {};
306 | if (ts_ri.length >= 1) {
307 | db_sql.select_ts_in(request.db_connection, ts_ri, function (err, results_ts) {
308 | if (!err) {
309 | if (results_ts.length >= 1) {
310 | missing_detect_check(request.db_connection, results_ts[0].pei, results_ts[0].mdd, results_ts[0].mdt, results_ts[0].cni, results_ts[0].ri, function (rsc) {
311 | console.log(rsc);
312 | request.db_connection.release();
313 | });
314 | }
315 | }
316 |
317 | response.header('X-M2M-RSC', '2000');
318 |
319 | ts.status = '2000';
320 | ts.ri = jsonObj['m2m:uril']['_'];
321 | response.status(200).end(JSON.stringify(ts));
322 | });
323 | }
324 | else {
325 | request.db_connection.release();
326 | response.header('X-M2M-RSC', '4004');
327 | ts.status = '4004';
328 | ts.ri = '';
329 | response.status(404).end(JSON.stringify(ts));
330 | }
331 | });
332 | }
333 | else {
334 | db_sql.select_ts(request.db_connection, jsonObj.ts.ri, function (err, results_ts) {
335 | if (!err) {
336 | if (results_ts.length == 1) {
337 | missing_detect_check(request.db_connection, results_ts[0].pei, results_ts[0].mdd, results_ts[0].mdt, results_ts[0].cni, results_ts[0].ri, function (rsc) {
338 | request.db_connection.release();
339 | console.log(rsc.status + ' - ' + rsc.ri);
340 | response.header('X-M2M-RSC', '2000');
341 | response.status(200).end(JSON.stringify(rsc));
342 | });
343 | }
344 | }
345 | });
346 | }
347 | }
348 | else {
349 | console.log('[ts_app.post] - /missingDataDetect - No Connection');
350 | response.header('X-M2M-RSC', '5000');
351 | ts.status = '4004';
352 | ts.ri = '';
353 | response.status(404).end("[ts_app.post] No Connection to DB");
354 | }
355 | });
356 | });
357 | });
358 |
359 |
360 | ts_app.delete('/missingDataDetect', onem2mParser, function(request, response) {
361 | var fullBody = '';
362 | request.on('data', function(chunk) {
363 | fullBody += chunk.toString();
364 | });
365 | request.on('end', function() {
366 | request.body = fullBody;
367 | if(request.body === '') {
368 | }
369 | else {
370 | var jsonObj = JSON.parse(request.body);
371 | var ri = jsonObj.ts.ri;
372 | if (ts_timer[ri] != null) {
373 | ts_timer[ri].removeAllListeners(ri);
374 | delete ts_timer[ri];
375 | }
376 |
377 | if (ts_timer_id[ri] != null) {
378 | clearInterval(ts_timer_id[ri]);
379 | delete ts_timer_id[ri];
380 | }
381 | }
382 |
383 | var rsc = {};
384 | rsc.status = 2000;
385 | rsc.ri = request.url;
386 | console.log(rsc.status + ' - ' + rsc.ri);
387 | response.header('X-M2M-RSC', '2000');
388 | response.status(200).end(JSON.stringify(rsc));
389 | });
390 | });
391 |
--------------------------------------------------------------------------------
/mobius/tsi.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2018, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file
13 | * @copyright KETI Korea 2018, KETI
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | */
16 |
17 | var url = require('url');
18 | var xml2js = require('xml2js');
19 | var xmlbuilder = require('xmlbuilder');
20 | var util = require('util');
21 |
22 | var responder = require('./responder');
23 |
24 |
25 | exports.build_tsi = function(request, response, resource_Obj, body_Obj, callback) {
26 | var rootnm = request.headers.rootnm;
27 |
28 | // body
29 | resource_Obj[rootnm].con = body_Obj[rootnm].con;
30 | resource_Obj[rootnm].cs = Buffer.byteLength(resource_Obj[rootnm].con, 'utf8').toString();
31 |
32 | resource_Obj[rootnm].dgt = (body_Obj[rootnm].dgt) ? body_Obj[rootnm].dgt : '';
33 | resource_Obj[rootnm].sqn = (body_Obj[rootnm].sqn) ? body_Obj[rootnm].sqn : '';
34 |
35 | request.resourceObj = JSON.parse(JSON.stringify(resource_Obj));
36 | resource_Obj = null;
37 |
38 | callback('200');
39 | };
40 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Mobius",
3 | "version": "2.4.36",
4 | "dependencies": {
5 | "body-parser": "^1.18.3",
6 | "cbor": "^4.1.3",
7 | "coap": "^0.22.0",
8 | "cors": "^2.8.5",
9 | "crypto": "1.0.1",
10 | "events": "^3.0.0",
11 | "express": "^4.16.4",
12 | "file-stream-rotator": "0.4.1",
13 | "fs": "0.0.2",
14 | "http": "0.0.0",
15 | "https": "^1.0.0",
16 | "ip": "^1.1.5",
17 | "js2xmlparser": "^3.0.0",
18 | "merge": "^1.2.1",
19 | "moment": "^2.22.2",
20 | "morgan": "^1.9.1",
21 | "mqtt": "^2.18.8",
22 | "mysql": "^2.16.0",
23 | "shortid": "^2.2.14",
24 | "url": "^0.11.0",
25 | "util": "^0.11.1",
26 | "websocket": "^1.0.28",
27 | "xml2js": "^0.4.19",
28 | "xmlbuilder": "^10.1.1"
29 | },
30 | "description": "Mobius",
31 | "main": "mobius.js",
32 | "devDependencies": {},
33 | "scripts": {
34 | "test": "echo \"Error: no test specified\" && exit 1"
35 | },
36 | "author": "Il Yeup Ahn, IoT Platform Center, KETI",
37 | "license": "BSD-3-Clause"
38 | }
39 |
--------------------------------------------------------------------------------
/pxy_coap.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2018, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * Created by Il Yeup, Ahn in KETI on 2016-10-18.
13 | */
14 |
15 | /**
16 | * @file
17 | * @copyright KETI Korea 2018, KETI
18 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
19 | */
20 |
21 | var fs = require('fs');
22 | var http = require('http');
23 | var https = require('https');
24 | var coap = require('coap');
25 |
26 | global.NOPRINT = 'true';
27 |
28 | var _this = this;
29 |
30 | var coap_state = 'init';
31 |
32 | //var custom = new process.EventEmitter();
33 | var events = require('events');
34 | var coap_custom = new events.EventEmitter();
35 |
36 | var usecoapcbhost = 'localhost'; // pxycoap to mobius
37 |
38 | var coap_rsc_code = {
39 | '2000': '2.05',
40 | '2001': '2.01',
41 | '2002': '2.02',
42 | '2004': '2.04',
43 | '4000': '4.00',
44 | '4004': '4.04',
45 | '4005': '4.05',
46 | '4008': '4.04',
47 | '4101': '4.03',
48 | '4102': '4.00',
49 | '4103': '4.03',
50 | '4104': '4.00',
51 | '4105': '4.03',
52 | '5000': '5.00',
53 | '5001': '5.01',
54 | '5103': '4.04',
55 | '5105': '4.03',
56 | '5106': '5.06',
57 | '5203': '4.03',
58 | '5204': '5.00',
59 | '5205': '4.03',
60 | '5206': '5.00',
61 | '5207': '4.06',
62 | '6003': '4.04',
63 | '6005': '4.04',
64 | '6010': '4.00',
65 | '6011': '4.00',
66 | '6020': '5.00',
67 | '6021': '5.00',
68 | '6022': '4.00',
69 | '6023': '4.00',
70 | '6024': '4.00',
71 | '6025': '5.00',
72 | '6026': '5.00',
73 | '6028': '4.00',
74 | '6029': '4.00'
75 | };
76 |
77 | coap_state = 'init';
78 |
79 | //setInterval(function () {
80 | // coap_custom.emit('coap_watchdog');
81 | //}, 2000);
82 |
83 | var pxycoap_server = null;
84 |
85 | //coap_custom.on('coap_watchdog', function() {
86 | exports.coap_watchdog = function () {
87 | if(coap_state === 'init') {
88 | coap_state = 'connect';
89 | }
90 | else if(coap_state === 'connect') {
91 | if(pxycoap_server == null) {
92 | pxycoap_server = coap.createServer();
93 | pxycoap_server.listen(usecsebaseport, function() {
94 | // var options = {
95 | // host: 'localhost',
96 | // port: usecsebaseport,
97 | // pathname: '/'+usecsebase,
98 | // method: 'get',
99 | // confirmable: 'false',
100 | // options: {
101 | // 'Accept': 'application/json'
102 | // }
103 | // };
104 | //
105 | // var bodyString = '';
106 | // var responseBody = '';
107 | // var req = coap.request(options);
108 | // req.setOption("256", new Buffer(usecseid)); // X-M2M-Origin
109 | // req.setOption("257", new Buffer('hello')); // X-M2M-RI
110 | // req.on('response', function (res) {
111 | // res.on('data', function () {
112 | // responseBody += res.payload.toString();
113 | // });
114 | //
115 | // res.on('end', function () {
116 | // if(res.code == '2.05') {
117 | // coap_state = 'ready';
118 | // console.log('[pxy_coap] coap ready');
119 | // }
120 | // });
121 | // });
122 | // req.on('error', function (e) {
123 | // console.log(e);
124 | // });
125 | //
126 | // req.write(bodyString);
127 | // req.end();
128 | });
129 |
130 |
131 | pxycoap_server.on('request', coap_message_handler);
132 |
133 | pxycoap_server.on('error', function (e) {
134 | console.log(e);
135 | });
136 | }
137 | }
138 | };
139 |
140 |
141 | var coap_tid = require('shortid').generate();
142 | wdt.set_wdt(coap_tid, 2, _this.coap_watchdog);
143 |
144 | function coap_message_handler(request, response) {
145 |
146 | var headers = {};
147 | headers['X-M2M-TY'] = '';
148 |
149 | // check coap options
150 | for (var idx in request.options) {
151 | if (request.options.hasOwnProperty(idx)) {
152 | if (request.options[idx].name == '256') { // 'X-M2M-Origin
153 | headers['X-M2M-Origin'] = request.options[idx].value.toString();
154 | }
155 | else if (request.options[idx].name == '257') { // 'X-M2M-RI
156 | headers['X-M2M-RI'] = request.options[idx].value.toString();
157 | }
158 | else if (request.options[idx].name == '267') { // 'X-M2M-TY
159 | headers['X-M2M-TY'] = Buffer.isBuffer(request.options[idx].value) ? request.options[idx].value[0].toString() : request.options[idx].value.toString();
160 | }
161 | // else if (request.options[idx].name == '268') { // 'X-M2M-RVI
162 | // headers['X-M2M-RVI'] = request.options[idx].value.toString();
163 | // }
164 | }
165 | }
166 |
167 | if(request.headers['Accept'])
168 | {
169 | headers['Accept'] = request.headers['Accept'];
170 | }
171 |
172 | if(request.headers['Content-Type'])
173 | {
174 | if(headers['X-M2M-TY'] == '') {
175 | headers['Content-Type'] = request.headers['Content-Type'];
176 | }
177 | else {
178 | headers['Content-Type'] = request.headers['Content-Type'] + ';ty=' + headers['X-M2M-TY'];
179 | }
180 | }
181 |
182 | delete headers['X-M2M-TY'];
183 |
184 | headers['binding'] = 'C';
185 | headers['remoteaddress'] = request.rsinfo.address;
186 |
187 | var responseBody = '';
188 |
189 | var options = {
190 | hostname: usecoapcbhost,
191 | port: usecsebaseport,
192 | path: request.url,
193 | method: request.method,
194 | headers: headers
195 | };
196 |
197 | if(use_secure === 'disable') {
198 | var req = http.request(options, function (res) {
199 | res.setEncoding('utf8');
200 | res.on('data', function (chunk) {
201 | responseBody += chunk;
202 | });
203 |
204 | res.on('end', function () {
205 | console.log('<----- [pxy_coap]');
206 | console.log(responseBody);
207 |
208 | var rsc = new Buffer(2);
209 | rsc.writeUInt16BE(parseInt(res.headers['x-m2m-rsc'], 'hex'), 0);
210 | response.setOption("265", rsc); // X-M2M-RSC
211 | //var rqi = new Buffer(2);
212 | //rqi.writeUInt16BE(parseInt(res.headers['x-m2m-ri'], 'hex'), 0);
213 | //var rqi = res.headers['x-m2m-ri'];
214 | var rqi = Buffer.from(res.headers['x-m2m-ri'], 'utf-8');
215 | response.setOption("257", rqi); // X-M2M-RQI
216 | if (res.headers['content-type']) {
217 | response.setOption("Content-Format", res.headers['content-type']);
218 | }
219 | // if(res.headers.hasOwnProperty('x-m2m-rvi')) {
220 | // var rvi = Buffer.from(res.headers['x-m2m-rvi'], 'utf-8');
221 | // response.setOption("268", rvi); // X-M2M-RVI
222 | // }
223 | response.code = coap_rsc_code[res.headers['x-m2m-rsc']];
224 | response.end(responseBody);
225 | });
226 | });
227 | }
228 | else if(use_secure === 'enable') {
229 | options.ca = fs.readFileSync('ca-crt.pem');
230 |
231 | req = https.request(options, function (res) {
232 | res.setEncoding('utf8');
233 | res.on('data', function (chunk) {
234 | responseBody += chunk;
235 | });
236 |
237 | res.on('end', function () {
238 | console.log('<----- [pxy_coap]');
239 | console.log(responseBody);
240 |
241 | var rsc = new Buffer(2);
242 | rsc.writeUInt16BE(parseInt(res.headers['x-m2m-rsc'], 'hex'), 0);
243 | response.setOption("265", rsc); // X-M2M-RSC
244 | var rqi = new Buffer(2);
245 | rqi.writeUInt16BE(parseInt(res.headers['x-m2m-ri'], 'hex'), 0);
246 | response.setOption("257", rqi); // X-M2M-RQI
247 | if (res.headers['content-type']) {
248 | response.setOption("Content-Format", res.headers['content-type']);
249 | }
250 | // if(res.headers.hasOwnProperty('x-m2m-rvi')) {
251 | // response.setOption("X-M2M-RVI", res.headers['x-m2m-rvi']);
252 | // }
253 | response.code = coap_rsc_code[res.headers['x-m2m-rsc']];
254 | response.end(responseBody);
255 | });
256 | });
257 |
258 | }
259 |
260 | req.on('error', function (e) {
261 | if (e.message != 'read ECONNRESET') {
262 | console.log('[pxycoap - http_retrieve_CSEBase] problem with request: ' + e.message);
263 | }
264 | });
265 |
266 | var bodyString = request.payload.toString();
267 | console.log('-----> [pxy_coap]');
268 | console.log(bodyString);
269 |
270 | // write data to request body
271 | req.write(bodyString);
272 | req.end();
273 | }
274 |
--------------------------------------------------------------------------------
/server-crt.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIFjDCCA3SgAwIBAgIJAKNn4zfTPGJaMA0GCSqGSIb3DQEBBQUAMIGBMQswCQYD
3 | VQQGEwJVUzELMAkGA1UECBMCTUExDzANBgNVBAcTBkJvc3RvbjETMBEGA1UEChMK
4 | RXhhbXBsZSBDbzEQMA4GA1UECxMHdGVjaG9wczELMAkGA1UEAxMCY2ExIDAeBgkq
5 | hkiG9w0BCQEWEWNlcnRzQGV4YW1wbGUuY29tMB4XDTE3MDMwOTE1MDUxMVoXDTE5
6 | MTIwMzE1MDUxMVowgYgxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJNQTEPMA0GA1UE
7 | BxMGQm9zdG9uMRMwEQYDVQQKEwpFeGFtcGxlIENvMRAwDgYDVQQLEwd0ZWNob3Bz
8 | MRIwEAYDVQQDEwlsb2NhbGhvc3QxIDAeBgkqhkiG9w0BCQEWEWNlcnRzQGV4YW1w
9 | bGUuY29tMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEApv9fSEeqATVe
10 | QvQr/WuQJ85n8nXHS/uCQ6JVfLqqu16DIrvQdVstY8TFp979r+HjwWtNU3Ey24wH
11 | Lm9ak01DLiI51l1YJr2D2AXKfzXQnRt/gYclJ/LoJ055OQibb2qK12zqGc7lZd/N
12 | y5qFmeAXZvWo20ocaIbFC7DUAbL8nBC3SJ3GGSEWnstudkgzBw4AaSRmsL+Kd/rG
13 | cD+pKXe1nIqXH+Ym++O+Eoi3djw3Swb7eLNHBVmNVfmr4TFDMQoM37KOcVGuJtT6
14 | o48axzWBDNRBCAKBbZDmNcz4ZzD6bYYp2JQQKJWVb1rKVv4jhhelR5Lud3jtbqZE
15 | j6vamRjOzcwFWu61DOML9IkKqVXNb3srtyrQP/Xy4uSekrO1r9158gA8x37jDnNp
16 | HvvmvSLKLA4eGe3q/DsireA9Ca/YmBIZXPf3i03r5FJ1zJIXl9rxqoNmdLwoLrIg
17 | WOPSFGE7f9qA7xxv6tc1EkboB16UlGJo+5GJzM0CAPVFf+p6rqa54HrBJCr79/iL
18 | KnIoQnduX/cxv8airRHd3m/+CQnf43XWK5lp9DLT/Tf+j27TxEfp+1kt/fTAiWbT
19 | g16pcW4O/LsQ/C/L5UOe/cxi41NskhyySrwMwHDOORV25/UvM6lY+xNk6lW2A1ZN
20 | xy883hLodcztIXpeZt8H4WP3QL91QOcCAwEAATANBgkqhkiG9w0BAQUFAAOCAgEA
21 | Rw6s1j0/iWaUPTMAWWZHK8qMNpjEArvtWD19qYCxuRSWpxEkNe/dRe944eND7Sou
22 | dcLQap4gof8PMU+Yv1WuK1dVCes5Ku6lpLGm6zUxdDQ3MAOptoC209r9SCLqnunq
23 | SUEjpHLERAUK6UUKzHAvXX8bIkraT65PBOHbqmlMZEdldFws8sYpEic5D/GblQJZ
24 | V2mzi3NxGSHUwkxjRlpZwAxP0XOmXvykUE9cedl4V9mVW8UjfZ5NxdkVHNs4Jf7y
25 | D386qcywjXKjmBWlsimJqGQRubonf0QcZdYCiVB6QQSHm5l00/g/EeMiOiENjkkk
26 | Ln1MbMpkeo7TXmDy21GHLj+9Mj4bBdQdec75geiaI8r7q2hwga8e+9pzONlfSqFw
27 | i4KLEpkcngz+7LTJrv1VaCDHd1s7IVPj/TEo0wDrU4MNksDqJTO2h1gbXzN7vk53
28 | H6KkoHgC57C+3wIvQ8kwEWNlpq+c5sNnu9v1L/1+QPuYSWdVq49uN6a9Uf0MdXRg
29 | gS2zo6uyARu5A7sy/pwU7I+oXIKxQiwTCiKYz3qllFhkLX1hXjhGPPedDRx3uDtG
30 | U5biC7Rg35ugKK4oYXxoyX35aRelv935sCD7kyRUXJbO7GAFf5+iTgDKFrGILcjC
31 | WKUA1VQo/L1mYzEjPmqVphuhP7fmTt61xErUI5xEhFw=
32 | -----END CERTIFICATE-----
33 |
--------------------------------------------------------------------------------
/server-key.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN RSA PRIVATE KEY-----
2 | MIIJKAIBAAKCAgEApv9fSEeqATVeQvQr/WuQJ85n8nXHS/uCQ6JVfLqqu16DIrvQ
3 | dVstY8TFp979r+HjwWtNU3Ey24wHLm9ak01DLiI51l1YJr2D2AXKfzXQnRt/gYcl
4 | J/LoJ055OQibb2qK12zqGc7lZd/Ny5qFmeAXZvWo20ocaIbFC7DUAbL8nBC3SJ3G
5 | GSEWnstudkgzBw4AaSRmsL+Kd/rGcD+pKXe1nIqXH+Ym++O+Eoi3djw3Swb7eLNH
6 | BVmNVfmr4TFDMQoM37KOcVGuJtT6o48axzWBDNRBCAKBbZDmNcz4ZzD6bYYp2JQQ
7 | KJWVb1rKVv4jhhelR5Lud3jtbqZEj6vamRjOzcwFWu61DOML9IkKqVXNb3srtyrQ
8 | P/Xy4uSekrO1r9158gA8x37jDnNpHvvmvSLKLA4eGe3q/DsireA9Ca/YmBIZXPf3
9 | i03r5FJ1zJIXl9rxqoNmdLwoLrIgWOPSFGE7f9qA7xxv6tc1EkboB16UlGJo+5GJ
10 | zM0CAPVFf+p6rqa54HrBJCr79/iLKnIoQnduX/cxv8airRHd3m/+CQnf43XWK5lp
11 | 9DLT/Tf+j27TxEfp+1kt/fTAiWbTg16pcW4O/LsQ/C/L5UOe/cxi41NskhyySrwM
12 | wHDOORV25/UvM6lY+xNk6lW2A1ZNxy883hLodcztIXpeZt8H4WP3QL91QOcCAwEA
13 | AQKCAgBNXd4sxFa0fJ8Q8cI3g8+jQXLS11Hfl8O/xcNJJ8nVSHIEc3KeDAG5SP4x
14 | SZPKGiLEBwwp7jWblQH2t0wFFjRbeSvGbjRark4YlIY97Raa0pR907iZC2YWX7q1
15 | e5FXSsrMBv9luX55dfgHrazbnv/4iTMTdQA4RMehJOjzaJKzUuM21zFhjvzF0IV6
16 | cvSA/jGehGi21eY2s42fjz61oWoX/fUJqDzDUb1LJN+p/Te4oKF8R8JNbjGWdTb1
17 | +zafz4IrWLO5OBgwkVcU00WaqOUCposCRPblZc3hevZSCFTczN0yI1ZhFvvGPQ+k
18 | wdR/WREPWbj0zKdjLdBxpzJ83wtfeG3DrMImN27ovrvc6uGTHl1VlLRkamdfIfMb
19 | gD4HpTdGeyTa6cAkVfd3kGFD1PzeYROHVaalS9AKIFfyv9are4nbRTQxCfuZqxRx
20 | cXzQJNoZtKM1AudEemcWXG0IRwscfEvi8/mgORAArjv9aQsXa3XMZDY4bC8GAqvX
21 | H51f8suTkhuXhu20RGwa6tG/iWJPIJddDMv3ivfCcnYvQPxY1yqoFQ5d4UdZdqs+
22 | mMWCG/Nh6b+l2eioeyV1kjzf3609VLw1HG1AcdIZiYm9cRoEAnJe9MFpSrHNvheh
23 | dM1pVj0RF11HjMlq/Hklp9S6tSaCMUev32FlgshWId88P3RLQQKCAQEA3YpOC7Mi
24 | TuGTngEL0DtB3TwzHvtZUDewD5Bog6L2zKboHVYdkW72dCbxI83gT2vviJrJaIBV
25 | 76Ca/MKFXgL323O1RWqxbjaFcVfcew/qvbkun3xoreSwcTftx5If1uEPSz7bNSnF
26 | icuRyzuZ3E0DpzN0pVcgwoFJwrAe2X0zDFv0QnGapdkx96a0b2icjtsRz1rd0Vrl
27 | CsI2ntPTE9H6sUJLo6OZG+OM7ctQlgAlNOis9c8lT15Q0gNjvrCTOGQNErJqDdah
28 | BPnQzy6dh9bh86012phjQB4K1KrPYqXSFiEYJAp1HTVRjviopuwJhe2T9q1+Cfz/
29 | wloqoar1+RA4MQKCAQEAwPkvoyo6XK0ZuYn7FtwsgSV2KuCCoAiFKf5AJi2r1aB3
30 | 7pNxiC5hb3Nwvd4tS22WVddstNpX5Oa2umHjLUetYcFFKCzqE/H611orMi1z7xS2
31 | YeiD+AkeOHI8GZLdlsleo5eL9B5uZgN7VnwM38gcCIzc23s6nafWKTV2jf4k6G45
32 | 8e5KT/1TvMu2HeSKroicFvSH+Y4ZFMo6aCcK++Agji5mBlj5Kweeh05vZV0Q1nzH
33 | kweQ2KkLCRXL0UJsnVVL4fYJiRcaiHNmqgqC2Yj/ZXzu6YMVzrQwv+8f53xt1mop
34 | SNfYRkWS9CMI1pMUyJkUzJqWtxO9hHkGjcZHg7rclwKCAQEAuMZzA9Ubx1jjq0RK
35 | Gxphe+mK5ctUGdDomoKieTCB0f1f2aAKt1MqYYRdWbSL4xIuTex0EiIACwYUXr7L
36 | R7cIDVQ7m7M6W6dDs15JuaZz7lu2pDS6hlcYRsYUH4Ej5y/9do/tezDk3mIYrr5+
37 | PL1LT7heEM1TuIbnA2erw1BmNGe5mXVxO+SkhV7YXZeOBKR4/U5XdhbutAN6VQxt
38 | n7lh81hNCCYaPKWU1HzgMMvcPH3YTIjCIKmUlSVYmyJhGAZy1OZUCEi8Mg8+dp71
39 | quexu3D7WuAA3+hutiPlJu0RBX4CyYSjW4IuDSYeXGLAKqEV6QeY+TG4C9zyc7bI
40 | wzwg8QKCAQAjLMjcKxRcVEk+IsKcFiIeoF97zVTCKwtq7idvTh/mXsu9ty6Yriug
41 | jyBb26XR+/XNS+lKxgoDdXKVYsZwOIKIMRyUCCva2t7oZk09Zj+dst7T1fhIPBFA
42 | JMKDvtuZYrdXhoZCR1HEUpom15HZMLa7cEHJ2BqFJlTJSi+EDnFX1M/HI7J0Bi8/
43 | WLqnlEMbMVeSb5xhht9XhM1EsukzpFUK1bZPLeStTUQ+UbPIfEBXeINAb76dX6Ld
44 | UxXF3R/DRgsA80IltQpnGPH7yNK1KF21eCJsejJ9bSb9tW7RWUMENHG2D3IizQfO
45 | bJxt0H2XWyAJc5xJXtXK0ey55wyeHG+dAoIBAE1e5wsakS+3KQhg7U2WsmNlYKZP
46 | g/ufyGdyYq0p4abJO/GtcXsDDkE/4lFXas/6HKZOB4dLzEHwITo8PsWTrtg5W1d1
47 | YeR1TUtN2c2J+xvARtBigjxksUnzb+JL0100weT/iw3F6XMsjJCZjRlCNFUjIFA3
48 | XpZnCOXmWnV5KvHCLYafTJMWoDMGKx9y+AS/Tzzk2nFABKYwkHMaq5751R2dgJxf
49 | X9jpk2FCw6RrKwzq60lkOoyuZ4HAaGSnQFgNOyf4bNp3x26OCpYFQg8+qFly7YYY
50 | t+MQdV+CUSriWPfGtPaZaEd3kuTqUioQ3pPe5ljYAJbd5jFyHb5yLez6SiM=
51 | -----END RSA PRIVATE KEY-----
52 |
--------------------------------------------------------------------------------
/wdt.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2018, KETI
3 | * All rights reserved.
4 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 | */
10 |
11 | /**
12 | * @file timer code of Mobius Yellow. manage state of Mobius
13 | * @copyright KETI Korea 2018, KETI
14 | * @author Il Yeup Ahn [iyahn@keti.re.kr]
15 | */
16 |
17 | var events = require('events');
18 | var wdt = new events.EventEmitter();
19 |
20 | var wdt_callback_q = {};
21 | var wdt_value_q = {};
22 | var wdt_tick_q = {};
23 | var wdt_param1_q = {};
24 | var wdt_param2_q = {};
25 | var wdt_param3_q = {};
26 |
27 | setInterval(function () {
28 | wdt.emit('resource_manager');
29 | }, 1000);
30 |
31 | wdt.on('resource_manager', function() {
32 | for (var id in wdt_value_q) {
33 | if(wdt_value_q.hasOwnProperty(id)) {
34 | ++wdt_tick_q[id];
35 | if((wdt_tick_q[id] % wdt_value_q[id]) == 0) {
36 | wdt_tick_q[id] = 0;
37 | if(wdt_callback_q[id]) {
38 | wdt_callback_q[id](id, wdt_param1_q[id], wdt_param2_q[id], wdt_param3_q[id]);
39 | }
40 | }
41 | }
42 | }
43 | });
44 |
45 | exports.set_wdt = function (id, sec, callback_func, param1, param2, param3) {
46 | wdt_value_q[id] = sec;
47 | wdt_tick_q[id] = 0;
48 | wdt_callback_q[id] = callback_func;
49 | wdt_param1_q[id] = param1;
50 | wdt_param2_q[id] = param2;
51 | wdt_param3_q[id] = param3;
52 | };
53 |
54 | exports.get_wdt_callback = function (id) {
55 | return wdt_callback_q[id];
56 | };
57 |
58 | exports.get_wdt_value = function (id) {
59 | return wdt_value_q[id];
60 | };
61 |
62 | exports.del_wdt = function (id) {
63 | delete wdt_value_q[id];
64 | delete wdt_callback_q[id];
65 | };
--------------------------------------------------------------------------------