Skip to content

Commit effc537

Browse files
committed
Extended "udevices" API call by adding XML data injection with XPath
1 parent 215d9fd commit effc537

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+13765
-28
lines changed

CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,22 @@ webserver/proxyclient.cpp
308308
json/json_reader.cpp
309309
json/json_value.cpp
310310
json/json_writer.cpp
311+
tinyxpath/action_store.cpp
312+
tinyxpath/tinyxml.cpp
313+
tinyxpath/tokenlist.cpp
314+
tinyxpath/xpath_processor.cpp
315+
tinyxpath/xpath_stream.cpp
316+
tinyxpath/htmlutil.cpp
317+
tinyxpath/node_set.cpp
318+
tinyxpath/tinyxmlerror.cpp
319+
tinyxpath/xml_util.cpp
320+
tinyxpath/xpath_stack.cpp
321+
tinyxpath/xpath_syntax.cpp
322+
tinyxpath/lex_util.cpp
323+
tinyxpath/tinystr.cpp
324+
tinyxpath/tinyxmlparser.cpp
325+
tinyxpath/xpath_expression.cpp
326+
tinyxpath/xpath_static.cpp
311327
)
312328
add_executable(domoticz ${domoticz_SRCS})
313329

hardware/AnnaThermostat.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "../main/SQLHelper.h"
99
#include "../httpclient/HTTPClient.h"
1010
#include "../main/mainworker.h"
11-
#include "../hardware/openzwave/control_panel/tinyxml/tinyxml.h"
11+
#include "../tinyxpath/tinyxml.h"
1212

1313
#define round(a) ( int ) ( a + .5 )
1414

hardware/openzwave/control_panel/ozwcp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#include "Group.h"
4646
#include "Notification.h"
4747

48-
#include "tinyxml/tinyxml.h"
48+
#include "../../tinyxpath/tinyxml.h"
4949

5050
#include <sys/stat.h>
5151
#include <fstream>

main/WebServer.cpp

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ extern "C" {
5454
#endif
5555
}
5656

57+
#include "../tinyxpath/xpath_processor.h"
58+
5759

5860
#include "mainstructs.h"
5961

@@ -2319,6 +2321,42 @@ namespace http {
23192321
}
23202322
}
23212323

2324+
static int l_domoticz_applyXPath(lua_State* lua_state)
2325+
{
2326+
int nargs = lua_gettop(lua_state);
2327+
if (nargs >= 2)
2328+
{
2329+
if (lua_isstring(lua_state, 1) && lua_isstring(lua_state, 2))
2330+
{
2331+
std::string buffer = lua_tostring(lua_state, 1);
2332+
std::string xpath = lua_tostring(lua_state, 2);
2333+
2334+
TiXmlDocument doc;
2335+
doc.Parse(buffer.c_str(), 0, TIXML_ENCODING_UTF8);
2336+
2337+
TiXmlElement* root = doc.RootElement();
2338+
if (!root)
2339+
{
2340+
_log.Log(LOG_ERROR, "WebServer (applyXPath from LUA) : Invalid data received!");
2341+
return 0;
2342+
}
2343+
TinyXPath::xpath_processor processor(root,xpath.c_str());
2344+
TiXmlString xresult = processor.S_compute_xpath();
2345+
lua_pushstring(lua_state, xresult.c_str());
2346+
return 1;
2347+
}
2348+
else
2349+
{
2350+
_log.Log(LOG_ERROR, "WebServer (applyXPath from LUA) : Incorrect parameters type");
2351+
}
2352+
}
2353+
else
2354+
{
2355+
_log.Log(LOG_ERROR, "WebServer (applyXPath from LUA) : Not enough parameters");
2356+
}
2357+
return 0;
2358+
}
2359+
23222360
static int l_domoticz_applyJsonPath(lua_State* lua_state)
23232361
{
23242362
int nargs = lua_gettop(lua_state);
@@ -2565,6 +2603,9 @@ namespace http {
25652603
lua_pushcfunction(lua_state, l_domoticz_applyJsonPath);
25662604
lua_setglobal(lua_state, "domoticz_applyJsonPath");
25672605

2606+
lua_pushcfunction(lua_state, l_domoticz_applyXPath);
2607+
lua_setglobal(lua_state, "domoticz_applyXPath");
2608+
25682609
lua_createtable(lua_state, 1, 0);
25692610
lua_pushstring(lua_state, "content");
25702611
lua_pushstring(lua_state, content.c_str());
@@ -9444,10 +9485,12 @@ namespace http {
94449485
}
94459486
else if (dSubType == sTypeAlert)
94469487
{
9488+
sprintf(szData, "Level: %d", nValue);
9489+
root["result"][ii]["Data"] = szData;
94479490
if (!sValue.empty())
9448-
root["result"][ii]["Data"] = sValue;
9491+
root["result"][ii]["Desc"] = sValue;
94499492
else
9450-
root["result"][ii]["Data"] = Get_Alert_Desc(nValue);
9493+
root["result"][ii]["Desc"] = Get_Alert_Desc(nValue);
94519494
root["result"][ii]["TypeImg"] = "Alert";
94529495
root["result"][ii]["Level"] = nValue;
94539496
root["result"][ii]["HaveTimeout"] = false;

msbuild/domoticz.vcxproj

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,6 @@
169169
<ClInclude Include="..\hardware\Netatmo.h" />
170170
<ClInclude Include="..\hardware\OpenZWave.h" />
171171
<ClInclude Include="..\hardware\openzwave\control_panel\ozwcp.h" />
172-
<ClInclude Include="..\hardware\openzwave\control_panel\tinyxml\tinystr.h" />
173-
<ClInclude Include="..\hardware\openzwave\control_panel\tinyxml\tinyxml.h" />
174172
<ClInclude Include="..\hardware\OTGWBase.h" />
175173
<ClInclude Include="..\hardware\OTGWSerial.h" />
176174
<ClInclude Include="..\hardware\OTGWTCP.h" />
@@ -364,10 +362,6 @@
364362
<ClCompile Include="..\hardware\Netatmo.cpp" />
365363
<ClCompile Include="..\hardware\OpenZWave.cpp" />
366364
<ClCompile Include="..\hardware\openzwave\control_panel\ozwcp.cpp" />
367-
<ClCompile Include="..\hardware\openzwave\control_panel\tinyxml\tinystr.cpp" />
368-
<ClCompile Include="..\hardware\openzwave\control_panel\tinyxml\tinyxml.cpp" />
369-
<ClCompile Include="..\hardware\openzwave\control_panel\tinyxml\tinyxmlerror.cpp" />
370-
<ClCompile Include="..\hardware\openzwave\control_panel\tinyxml\tinyxmlparser.cpp" />
371365
<ClCompile Include="..\hardware\openzwave\control_panel\zwavelib.cpp" />
372366
<ClCompile Include="..\hardware\OTGWBase.cpp" />
373367
<ClCompile Include="..\hardware\OTGWSerial.cpp" />
@@ -526,6 +520,22 @@
526520
<ClCompile Include="..\tcpserver\TCPServer.cpp" />
527521
<ClCompile Include="..\httpclient\UrlEncode.cpp" />
528522
<ClCompile Include="..\main\WebServer.cpp" />
523+
<ClCompile Include="..\tinyxpath\action_store.cpp" />
524+
<ClCompile Include="..\tinyxpath\htmlutil.cpp" />
525+
<ClCompile Include="..\tinyxpath\lex_util.cpp" />
526+
<ClCompile Include="..\tinyxpath\node_set.cpp" />
527+
<ClCompile Include="..\tinyxpath\tinystr.cpp" />
528+
<ClCompile Include="..\tinyxpath\tinyxml.cpp" />
529+
<ClCompile Include="..\tinyxpath\tinyxmlerror.cpp" />
530+
<ClCompile Include="..\tinyxpath\tinyxmlparser.cpp" />
531+
<ClCompile Include="..\tinyxpath\tokenlist.cpp" />
532+
<ClCompile Include="..\tinyxpath\xml_util.cpp" />
533+
<ClCompile Include="..\tinyxpath\xpath_expression.cpp" />
534+
<ClCompile Include="..\tinyxpath\xpath_processor.cpp" />
535+
<ClCompile Include="..\tinyxpath\xpath_stack.cpp" />
536+
<ClCompile Include="..\tinyxpath\xpath_static.cpp" />
537+
<ClCompile Include="..\tinyxpath\xpath_stream.cpp" />
538+
<ClCompile Include="..\tinyxpath\xpath_syntax.cpp" />
529539
<ClCompile Include="..\webserver\Base64.cpp" />
530540
<ClCompile Include="..\webserver\connection.cpp" />
531541
<ClCompile Include="..\webserver\connection_manager.cpp" />

msbuild/domoticz.vcxproj.filters

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@
252252
<Filter Include="Devices\Nefit-Easy">
253253
<UniqueIdentifier>{eda6c8ec-7cdc-4897-9d23-c502aedbee4b}</UniqueIdentifier>
254254
</Filter>
255+
<Filter Include="tinyxpath">
256+
<UniqueIdentifier>{dec41c77-32d9-454a-a9fc-a9c2de0dc4a1}</UniqueIdentifier>
257+
</Filter>
255258
</ItemGroup>
256259
<ItemGroup>
257260
<None Include="..\CMakeLists.txt">
@@ -549,12 +552,6 @@
549552
<ClInclude Include="..\hardware\openzwave\control_panel\ozwcp.h">
550553
<Filter>Devices\ZWave\OpenZWave\Control Panel</Filter>
551554
</ClInclude>
552-
<ClInclude Include="..\hardware\openzwave\control_panel\tinyxml\tinystr.h">
553-
<Filter>Devices\ZWave\OpenZWave\Control Panel</Filter>
554-
</ClInclude>
555-
<ClInclude Include="..\hardware\openzwave\control_panel\tinyxml\tinyxml.h">
556-
<Filter>Devices\ZWave\OpenZWave\Control Panel</Filter>
557-
</ClInclude>
558555
<ClInclude Include="..\hardware\evohome.h">
559556
<Filter>Devices\EvoHome</Filter>
560557
</ClInclude>
@@ -1067,18 +1064,6 @@
10671064
<ClCompile Include="..\hardware\openzwave\control_panel\ozwcp.cpp">
10681065
<Filter>Devices\ZWave\OpenZWave\Control Panel</Filter>
10691066
</ClCompile>
1070-
<ClCompile Include="..\hardware\openzwave\control_panel\tinyxml\tinystr.cpp">
1071-
<Filter>Devices\ZWave\OpenZWave\Control Panel</Filter>
1072-
</ClCompile>
1073-
<ClCompile Include="..\hardware\openzwave\control_panel\tinyxml\tinyxml.cpp">
1074-
<Filter>Devices\ZWave\OpenZWave\Control Panel</Filter>
1075-
</ClCompile>
1076-
<ClCompile Include="..\hardware\openzwave\control_panel\tinyxml\tinyxmlerror.cpp">
1077-
<Filter>Devices\ZWave\OpenZWave\Control Panel</Filter>
1078-
</ClCompile>
1079-
<ClCompile Include="..\hardware\openzwave\control_panel\tinyxml\tinyxmlparser.cpp">
1080-
<Filter>Devices\ZWave\OpenZWave\Control Panel</Filter>
1081-
</ClCompile>
10821067
<ClCompile Include="..\hardware\evohome.cpp">
10831068
<Filter>Devices\EvoHome</Filter>
10841069
</ClCompile>
@@ -1304,6 +1289,54 @@
13041289
<ClCompile Include="..\hardware\NefitEasy.cpp">
13051290
<Filter>Devices\Nefit-Easy</Filter>
13061291
</ClCompile>
1292+
<ClCompile Include="..\tinyxpath\action_store.cpp">
1293+
<Filter>tinyxpath</Filter>
1294+
</ClCompile>
1295+
<ClCompile Include="..\tinyxpath\htmlutil.cpp">
1296+
<Filter>tinyxpath</Filter>
1297+
</ClCompile>
1298+
<ClCompile Include="..\tinyxpath\lex_util.cpp">
1299+
<Filter>tinyxpath</Filter>
1300+
</ClCompile>
1301+
<ClCompile Include="..\tinyxpath\node_set.cpp">
1302+
<Filter>tinyxpath</Filter>
1303+
</ClCompile>
1304+
<ClCompile Include="..\tinyxpath\tinystr.cpp">
1305+
<Filter>tinyxpath</Filter>
1306+
</ClCompile>
1307+
<ClCompile Include="..\tinyxpath\tinyxml.cpp">
1308+
<Filter>tinyxpath</Filter>
1309+
</ClCompile>
1310+
<ClCompile Include="..\tinyxpath\tinyxmlerror.cpp">
1311+
<Filter>tinyxpath</Filter>
1312+
</ClCompile>
1313+
<ClCompile Include="..\tinyxpath\tinyxmlparser.cpp">
1314+
<Filter>tinyxpath</Filter>
1315+
</ClCompile>
1316+
<ClCompile Include="..\tinyxpath\tokenlist.cpp">
1317+
<Filter>tinyxpath</Filter>
1318+
</ClCompile>
1319+
<ClCompile Include="..\tinyxpath\xml_util.cpp">
1320+
<Filter>tinyxpath</Filter>
1321+
</ClCompile>
1322+
<ClCompile Include="..\tinyxpath\xpath_expression.cpp">
1323+
<Filter>tinyxpath</Filter>
1324+
</ClCompile>
1325+
<ClCompile Include="..\tinyxpath\xpath_processor.cpp">
1326+
<Filter>tinyxpath</Filter>
1327+
</ClCompile>
1328+
<ClCompile Include="..\tinyxpath\xpath_stack.cpp">
1329+
<Filter>tinyxpath</Filter>
1330+
</ClCompile>
1331+
<ClCompile Include="..\tinyxpath\xpath_static.cpp">
1332+
<Filter>tinyxpath</Filter>
1333+
</ClCompile>
1334+
<ClCompile Include="..\tinyxpath\xpath_stream.cpp">
1335+
<Filter>tinyxpath</Filter>
1336+
</ClCompile>
1337+
<ClCompile Include="..\tinyxpath\xpath_syntax.cpp">
1338+
<Filter>tinyxpath</Filter>
1339+
</ClCompile>
13071340
</ItemGroup>
13081341
<ItemGroup>
13091342
<ResourceCompile Include="domoticz.rc">

scripts/lua_parsers/example_xml.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- Example of XML parser handling data with the following structure
2+
--<?xml version="1.0" encoding="UTF-8"?>
3+
--<sensor>
4+
-- <id>13</id>
5+
-- <value>29.99</value>
6+
--</sensor>
7+
8+
--}
9+
10+
-- A test with curl would be : curl -X POST -d "@test.xml" 'http://192.168.1.17:8080/json.htm?type=command&param=udevices&script=example_xml.lua'
11+
12+
-- Retrieve the request content
13+
s = request['content'];
14+
15+
-- Update some devices (index are here for this example)
16+
local id = domoticz_applyXPath(s,'//id/text()')
17+
local s = domoticz_applyXPath(s,'//value/text()')
18+
domoticz_updateDevice(id,'',s)

tinyxpath/AUTHORS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Authors:
2+
Yves Berquin
3+
Aman Aggarwal
4+

tinyxpath/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#set to minimum version that supports clean build on cygwin
2+
cmake_minimum_required(VERSION 2.8.4)
3+
4+
project (TINYXPATH CPP)
5+
6+
SET(TINYXPATH_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}")
7+
SET(TINYXPATH_LIBRARIES tinyxpath)
8+
9+
SET(LIBRARY_OUTPUT_PATH "" CACHE INTERNAL
10+
"Where to put the libraries for TINYXPATH"
11+
)
12+
13+
SET(CORE
14+
action_store.cpp lex_util.cpp node_set.cpp tinyxml.cpptinyxmlparser.cpp xml_util.cpp xpath_processor.cpp xpath_static.cpp xpath_syntax.cpp
15+
htmlutil.cpp tinystr.cpp tinyxmlerror.cpp tokenlist.cpp xpath_expression.cpp xpath_stack.cpp xpath_stream.cpp
16+
)
17+
18+
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
19+
SET(OperatingSystem "Linux")
20+
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
21+
22+
ADD_LIBRARY(tinyxpath ${LIB} ${CORE})

tinyxpath/ChangeLog

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// ================== 1.3.1 ==================
2+
3+
Release: June 25th, 2007
4+
5+
Bug fixes for 1.3.1
6+
- The name() function can now be used without argument as well.
7+
8+
Structural changes for 1.3.1
9+
- TinyXML version 2.5.3 is now used by default in TinyXPath
10+
11+
// ================== 1.3.0 ==================
12+
13+
Structural changes for 1.3.0 (Release date: April 29th, 2007)
14+
15+
- All code is now reentrant: we do not use the UserData anymore
16+
- Some very useful enhancements to the Linux build (Thanks Martin Bernreuther)
17+
18+
// ================== 1.2.3 ==================
19+
20+
Bug fixes for 1.2.3
21+
22+
- December 14th, 2004 : Bug fix : text was not recognized as an element (Thanks Alexey Sokirko)
23+
- June 19th, 2004 : Bug fix, when computing an expression based on a non-root element node (Thanks Augustus Sanders)
24+
- May 8th, 2004 : Bug fix by Jonathan Taylor in node_set::S_get_string_value
25+
- May 8th, 2004 : Bug fix in multiple additive expressions : a+b+c. (Thanks Jonathan Taylor)
26+
- Apr 26th, 2004 : Bug fix : missing conversion from text to double (Thanks Laura Glow)
27+
- Apr 24th, 2004 : Bug fix in expressions like "//x[text()='sub text']/@target" (Thanks Jonathan Taylor) : text() wasn't recognized
28+
as a function call in that context
29+
30+
// ================== 1.2.2 ==================
31+
32+
Release : March 13th, 2004
33+
34+
Bug fixes for 1.2.2
35+
36+
- Bug fix in the position() : it was counting the order of a node within it's brotherhood, which
37+
was correct only if the search was like *[position()=3] (Thanks Daniel C�t�)
38+
39+
Structural changes for 1.2.2
40+
41+
- The interface functions returning nodes should not return const pointers : there's no reason to
42+
forbid the user from chaning it's own structure (Thanks Colin Barschel)
43+
44+
// ================== 1.2.1 ==================
45+
46+
Released : January 18th, 2004
47+
48+
Bug fixes for 1.2.1
49+
50+
- Bug fix in predicate evaluation : the [n] count was always the childhood element number, whether the
51+
axis was a '*' or a name
52+
53+
Structural changes for 1.2.1
54+
55+
- No more syntax_backtrack exception : a syntactically correct expression doesn't yield any exception anymore
56+
- Added static functions for simpler API (xpath_static.h and xpath_static.cpp)
57+
58+
// ================== 1.2 ==================
59+
60+
Released : January 9th, 2004
61+
62+
Bug fixes for 1.2
63+
64+
- Bug fix : passing a node in the middle of a tree did destroy it's parent and siblings relationships
65+
- Bug fix : the integer value of a node set was 0
66+
- Missing processing for text() and node() node tests
67+
68+
Structural changes for 1.2
69+
70+
- Group all TinyXPath definitions in a TinyXPath namespace
71+
- New configuration header for global #defines (tinyxpath_conf.h) and exclude debuging member functions with ifdefs
72+
- Windows : Project with libraries (debug and release)
73+
- Update to latest TinyXML code, where user data are defined on the TiXmlBase level

0 commit comments

Comments
 (0)