Remove redundant macro definitions from curl_ext.c

Now that a hard copy of linux/list.h is restored in the obix package
itself, no external dependency on kernel-devel any more and the required
macros are always defined in that hard copy.
Cosmetic changes on the history.c

Remove redundant error messages, and printing out the content of
a bad formatted abstract node on error conditions
Cosmetic updates on README.md

The "-o cat" option should be used for journalctl to focus on the actual
messages instead of meta data such as timestamps
New test case to simulate how history index files are read

Add a new test case to simulate how history index files are read,
which can be used to evaluate the difference between xmlParseFile()
and xmlReadFile()

Turns out only the XML document generated by xmlParseFile can
support have its root subtree re-parented to another document.

At starts-up, the history subsystem will create a new node for
a history facility of a particular device under
/obix/historyService/histories/ and then read its index file and
reparent its root subtree to the previous node. So to this end,
only the xmlParseFile should be used so far.
Merge pull request #55 from Qingtao-Cao/devel

Devel
Remove XPath usage from history initialisation code.

As a matter of fact, the index file of a history facility is very
straightforward which contains just a list of file abstract objects
for all existing raw history data files, therefore a simple for
loop suits best to traverse all items in the list. Whereas XPath
will be an overkill in this case.
Improve the initialisation code of history facility

The common for_each_file_name() is used to concise the logic to
establish history facilities for all existing folders under
<res>/histories/ folder on the harddrive.

Redundant code of sanity checks on the given directory name and traversal
of each subdir have been safely removed by using this common API.
Improve the error handling of obix_server_init

On error handling, if a facility has not been established successfully
in the first place relevant cleanup function should not be invoked,
although current code won't double dispose any facility.

Also renaming xmldb_dispose() to obix_xmldb_dispose() so as to be
compatible with naming conventions of other init/dispose functions
The About contract of the oBIX server should be visiable

Make the about contract of the oBIX server visiable, which provides
some abstract information of the oBIX server instance.
Better the comment for the history facility template

Add comments about the fact that the automatically created history
facility nodes won't have the index list, and one history facility
may have others nodes as its children.
Merge pull request #56 from Qingtao-Cao/devel

Devel
Fix invalid memory accesses in history cleanup code

Whenever a history facility become a child of another, it should
be disposed before its parent so as to avoid double-free of its node
in the global DOM tree.

Note the history facility descriptor holds pointers to relevant node
in the global DOM tree. If the parent facility is destroyed first, then
its whole subtree are destroyed including relevant node of its child
facility. However, unfortunately, when the child facility is destroyed
later, it will try to destroy its node again which has been removed
already along with its parent. That's the reason valgrind throws out
tons of error messages as below:

==23172== Invalid read of size 4
==23172==    at 0x3C626578F2: xmlFreeNode (tree.c:3751)
==23172==    by 0x4C3DEE1: xml_delete_node (xml_utils.c:532)
==23172==    by 0x40DDDF: xmldb_delete_node (xml_storage.c:530)
==23172==    by 0x40605E: hist_destroy_dev (history.c:830)
==23172==    by 0x40789C: obix_hist_dispose (history.c:1688)
==23172==    by 0x40990C: obix_server_exit (server.c:184)
==23172==    by 0x4087CB: obix_fcgi_exit (obix_fcgi.c:110)
==23172==    by 0x409136: main (obix_fcgi.c:425)
==23172==  Address 0xbc37c88 is 8 bytes inside a block of size 120 free'd
==23172==    at 0x4A074C4: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==23172==    by 0x3C626574B7: xmlFreeNodeList (tree.c:3683)
==23172==    by 0x3C6265786B: xmlFreeNode (tree.c:3728)
==23172==    by 0x4C3DEE1: xml_delete_node (xml_utils.c:532)
==23172==    by 0x40DDDF: xmldb_delete_node (xml_storage.c:530)
==23172==    by 0x40605E: hist_destroy_dev (history.c:830)
==23172==    by 0x40789C: obix_hist_dispose (history.c:1688)
==23172==    by 0x40990C: obix_server_exit (server.c:184)
==23172==    by 0x4087CB: obix_fcgi_exit (obix_fcgi.c:110)
==23172==    by 0x409136: main (obix_fcgi.c:425)
==23172==
==23172== Invalid read of size 8
==23172==    at 0x3C62657902: xmlFreeNode (tree.c:3756)
==23172==    by 0x4C3DEE1: xml_delete_node (xml_utils.c:532)
==23172==    by 0x40DDDF: xmldb_delete_node (xml_storage.c:530)
==23172==    by 0x40605E: hist_destroy_dev (history.c:830)
==23172==    by 0x40789C: obix_hist_dispose (history.c:1688)
==23172==    by 0x40990C: obix_server_exit (server.c:184)
==23172==    by 0x4087CB: obix_fcgi_exit (obix_fcgi.c:110)
==23172==    by 0x409136: main (obix_fcgi.c:425)
==23172==  Address 0xbc37ce0 is 96 bytes inside a block of size 120 free'd
==23172==    at 0x4A074C4: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==23172==    by 0x3C626574B7: xmlFreeNodeList (tree.c:3683)
==23172==    by 0x3C6265786B: xmlFreeNode (tree.c:3728)
==23172==    by 0x4C3DEE1: xml_delete_node (xml_utils.c:532)
==23172==    by 0x40DDDF: xmldb_delete_node (xml_storage.c:530)
==23172==    by 0x40605E: hist_destroy_dev (history.c:830)
==23172==    by 0x40789C: obix_hist_dispose (history.c:1688)
==23172==    by 0x40990C: obix_server_exit (server.c:184)
==23172==    by 0x4087CB: obix_fcgi_exit (obix_fcgi.c:110)
==23172==    by 0x409136: main (obix_fcgi.c:425)
==23172==
==23172== Invalid free() / delete / delete[] / realloc()
==23172==    at 0x4A074C4: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==23172==    by 0x4C3DEE1: xml_delete_node (xml_utils.c:532)
==23172==    by 0x40DDDF: xmldb_delete_node (xml_storage.c:530)
==23172==    by 0x40605E: hist_destroy_dev (history.c:830)
==23172==    by 0x40789C: obix_hist_dispose (history.c:1688)
==23172==    by 0x40990C: obix_server_exit (server.c:184)
==23172==    by 0x4087CB: obix_fcgi_exit (obix_fcgi.c:110)
==23172==    by 0x409136: main (obix_fcgi.c:425)
==23172==  Address 0xbc37c80 is 0 bytes inside a block of size 120 free'd
==23172==    at 0x4A074C4: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==23172==    by 0x3C626574B7: xmlFreeNodeList (tree.c:3683)
==23172==    by 0x3C6265786B: xmlFreeNode (tree.c:3728)
==23172==    by 0x4C3DEE1: xml_delete_node (xml_utils.c:532)
==23172==    by 0x40DDDF: xmldb_delete_node (xml_storage.c:530)
==23172==    by 0x40605E: hist_destroy_dev (history.c:830)
==23172==    by 0x40789C: obix_hist_dispose (history.c:1688)
==23172==    by 0x40990C: obix_server_exit (server.c:184)
==23172==    by 0x4087CB: obix_fcgi_exit (obix_fcgi.c:110)
==23172==    by 0x409136: main (obix_fcgi.c:425)

By no means the obix_hist_dispose could ever be called more than once,
nor any history node is parented to more than one ancestor node. It's
this race condition about the position of the parent and child facilities
descriptors in the queue that is the root cause of all these invalid
memory access

To address this issue, the histroy facilities descriptors are now organised
in a certain order to ensure parent facilities are always positioned before
child facilities, so that at cleanup the list can be traversed in a reverse
order to have the child facilities and their nodes in the global DOM tree
removed first.
Merge pull request #59 from Qingtao-Cao/devel

Devel
Apply XML_PARSE_NOBLANKS option

Apply XML_PARSE_NOBLANKS option to avoid empty nodes at all

Signed-off-by: Qingtao Cao <harry.cao@nextdc.com>
Improve the read_hist_index.c test case

Improve the read_hist_index.c test case to demonstrate how the XML
parser's internal dictionary should be taken cared when the root
node of a parsed document is reparented to a brand new generated
document

Signed-off-by: Qingtao Cao <harry.cao@nextdc.com>
Maintain consistency of XML parser's internal dictionary

Whenever a root node of a parsed document is reparented to a new
temp doc to generate a response, the temp doc should manipulate
the same dictionary built up along with the original parsed document
so as not to release any string referenced there when the temp
doc is destroyed. Otherwise invalid release of strings cached up
in the dictionary ensue:

==10740== Invalid free() / delete / delete[] / realloc()
==10740==    at 0x4A074C4: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==10740==    by 0x3C6265769A: xmlFreeProp (tree.c:2082)
==10740==    by 0x3C6265773B: xmlFreePropList (tree.c:2056)
==10740==    by 0x3C6265750D: xmlFreeNodeList (tree.c:3659)
==10740==    by 0x3C62657450: xmlFreeNodeList (tree.c:3654)
==10740==    by 0x3C62657450: xmlFreeNodeList (tree.c:3654)
==10740==    by 0x3C62657255: xmlFreeDoc (tree.c:1242)
==10740==    by 0x40A1B7: obix_server_reply_object (server.c:575)
==10740==    by 0x40A033: obix_server_handlePOST (server.c:494)
==10740==    by 0x408DD6: obix_handle_request (obix_fcgi.c:319)
==10740==    by 0x408E87: payload (obix_fcgi.c:370)
==10740==    by 0x408F64: main (obix_fcgi.c:423)
==10740==  Address 0xbf4d91b is 91 bytes inside a block of size 1,048 alloc'd
==10740==    at 0x4A06409: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==10740==    by 0x3C626FD82B: xmlDictAddString.isra.0 (dict.c:270)
==10740==    by 0x3C626FE441: xmlDictLookup (dict.c:923)
==10740==    by 0x3C6263A38C: xmlDetectSAX2 (parser.c:1041)
==10740==    by 0x3C62650DE7: xmlParseChunk (parser.c:12178)
==10740==    by 0x408B55: obix_fcgi_read (obix_fcgi.c:259)
==10740==    by 0x408DBF: obix_handle_request (obix_fcgi.c:318)
==10740==    by 0x408E87: payload (obix_fcgi.c:370)
==10740==    by 0x408F64: main (obix_fcgi.c:423)

Said that, above issue can be avoided by duplicating the root node
of the parsed document before adding to the temp doc. Since copying
will duplicate the string in the dictionary. Or, no dictionary is
setup in the first place. Either way is not good enough.

The best approach is to mainpuate a dictionary but carefully have
its consistency maintained so as to avoid duplication of the root
node of the parsed document.
Merge pull request #62 from Qingtao-Cao/devel

Devel
Switch to using memcpy to avoid strict aliasing rule errors in GCC 4.4
Avoid unconditional copy of node in the PUT handler

The xmldb_update_node used to unconditionally copy the input root node
before reparenting it to the global DOM tree to avoid corruption of
the global DOM tree. Now it is made clear that this relates to the XML
parser's internal dictionary and an extra copy of the input root node
will only take place if a dictionary has been used.

To start with, the global DOM tree is made independent from any parser's
internal dictionary. Optimisation could be done in the near future once
we figure out how to use XML parser dictionary in a thread-safe manner.
Replace xmlParseFile with xmlReadFile on the server side.

The xmlReadFile is superior to xmlParseFile in that it enables the
flexibility of specifying different parser options.

Currently the XML_PARSE_NODICT is used for oBIX server's static
configuration files and history index files.