#include <assert.h>
#include <ctype.h>
#include "config.h"
#include "liblogging.h"
#include "namevaluetree.h"
#include "stringbuf.h"
Functions | |
void | sbNVTRDestroy (sbNVTRObj *pThis) |
Destructor for root elements - destroys a complete list. | |
void | sbNVTEDestroy (sbNVTEObj *pThis) |
Destructor for entry elements. | |
srRetVal | sbNVTXMLEscapePCDATAintoStrB (char *pszToEscape, sbStrBObj *pStr) |
char * | sbNVTXMLEscapePCDATA (char *pszToEscape) |
XML-Escape a string. | |
sbNVTRObj * | sbNVTRConstruct (void) |
Construct a NameValueTree Root Object. | |
sbNVTEObj * | sbNVTEConstruct (void) |
Construct a NameValueTree Entry Object. | |
srRetVal | sbNVTESetChild (sbNVTEObj *pEntry, sbNVTRObj *pChildRoot) |
Link a child list to the current entry. | |
sbNVTEObj * | sbNVTAddEntry (sbNVTRObj *pRoot) |
Add an entry to the end of a NameValueTree List. | |
srRetVal | sbNVTRRemoveFirst (sbNVTRObj *pRoot) |
Removes the first entry from a list. | |
sbNVTEObj * | sbNVTUnlinkElement (sbNVTRObj *pRoot) |
Unlink the first element from a name value tree. | |
sbNVTEObj * | sbNVTSearchKeySZ (sbNVTRObj *pRoot, sbNVTEObj *pStart, char *pszSearch) |
Find the next element with a given string key inside the list. | |
sbNVTEObj * | sbNVTSearchKeyU (sbNVTRObj *pRoot, sbNVTEObj *pStart, unsigned uSearch) |
Find the next element with a given integer key inside the list. | |
sbNVTEObj * | sbNVTSearchKeyUAndPrev (sbNVTRObj *pRoot, sbNVTEObj *pStart, unsigned uSearch, sbNVTEObj **ppPrevEntry) |
This is more or less a duplicate of the sbNVTSearchKeyU. | |
sbNVTEObj * | sbNVTSearchpUsrAndPrev (sbNVTRObj *pRoot, sbNVTEObj *pStart, void *pUsr, sbNVTEObj **ppPrevEntry) |
This method searches for a specific pUsr and returns the entry in question PLUS the previous element. | |
char * | sbNVTEUtilStrDup (char *pszStrToDup) |
Duplicate a string and return it. | |
srRetVal | sbNVTESetKeySZ (sbNVTEObj *pThis, char *pszKey, int bCopy) |
Set the string key for a given entry. | |
srRetVal | sbNVTESetValueSZ (sbNVTEObj *pThis, char *pszVal, int bCopy) |
Set the string value for a given entry. | |
srRetVal | sbNVTESetKeyU (sbNVTEObj *pThis, unsigned uKey) |
Set the integer key for a given entry. | |
srRetVal | sbNVTEUnsetKeyU (sbNVTEObj *pThis) |
Remove the integer key for a given entry. | |
srRetVal | sbNVTESetUsrPtr (sbNVTEObj *pThis, void *pPtr, void(pPtrDestroy)(void *)) |
Set the user pointer for a given entry. | |
srRetVal | sbNVTESetValueU (sbNVTEObj *pThis, unsigned uVal) |
Set the integer value for a given entry. | |
srRetVal | sbNVTEGetValueU (sbNVTEObj *pThis, unsigned *puValue) |
Return the uValue for this object. | |
void | sbNVTEUnsetUsrPtr (sbNVTEObj *pEntry) |
Remove the user point from an element. | |
void | sbNVTRUnlinkFromParent (sbNVTRObj *pRoot) |
Unlinks a root element (complete list) from its parent. | |
void | sbNVTEUnlinkFromList (sbNVTRObj *pRoot, sbNVTEObj *pEntry, sbNVTEObj *pPrev) |
Unlink an entry from the current list. | |
srRetVal | sbNVTRRemoveKeyU (sbNVTRObj *pRoot, unsigned uKey) |
Remove a keyed entry from a root element. | |
srRetVal | sbNVTRRemovEntryWithpUsr (sbNVTRObj *pRoot, void *pUsr) |
Remove an entry with a specific pUsr from a root element. | |
srRetVal | sbNVTRParseXML (sbNVTRObj *pRoot, char *pszXML) |
Populate a NameValueTree based on a BEEP XML stream. | |
void | sbNVTDebugPrintTree (sbNVTRObj *pRoot, int iLevel) |
Print out a whole tree structure. | |
sbNVTEObj * | sbNVTRHasElement (sbNVTRObj *pRoot, char *pEltname, int bMustBeOnly) |
Checks if a list has the named element. |
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* 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.
* Neither the name of Adiscon GmbH or Rainer Gerhards nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER OR CONTRIBUTORS 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.
|
Add an entry to the end of a NameValueTree List. A new entry element is constructed and added onto the end of the list.
|
|
Print out a whole tree structure. This is a debug aid and ONLY AVAILABLE IN DEBUG BUILDS! We walk the tree and call ourselfs recursively.
|
|
Construct a NameValueTree Entry Object. Use this constructor whenever a new object is created!
|
|
Destructor for entry elements. This destructor destroys all elements directly associated with this entry element. As such, XML Properties and Childs are destroyed, but not the parent or sibling, as they may remain valid in another context. If there is a user pointer, the supplied free() function is called on it. |
|
Return the uValue for this object. If the uValue is already set, it is returned. If it is not yet set, we look at the szValue and see if we can convert it to an uValue. If that succeeds, we return the converted value. If that does not succeed, -1 is returned and an error is flagged.
|
|
Link a child list to the current entry.
|
|
Set the string key for a given entry. The string key is copied to a new buffer if so requested.
|
|
Set the integer key for a given entry.
|
|
Set the user pointer for a given entry.
|
|
Set the string value for a given entry. The string key is copied to a new buffer if so requested.
|
|
Set the integer value for a given entry.
|
|
Unlink an entry from the current list.
|
|
Remove the user point from an element. This is needed if the element got deleted by the user itself. If not done, the list destructor would try to delete the object, thus resulting in a double-free. If the user pointer is not set, nothing happens. |
|
Duplicate a string and return it. This is a general utility, it was just defined first in the context of NVTE.
|
|
Construct a NameValueTree Root Object. Use this constructor whenever a new object is created!
|
|
Destructor for root elements - destroys a complete list. So we need to walk it by using the raw pointers. |
|
Checks if a list has the named element. Can also check if it is the only element in the list.
|
|
Populate a NameValueTree based on a BEEP XML stream. This is a mini BEEP XML parser. It parses those constructs supported by BEEP XML. It does NOT check the DTD, this needs to be done by the caller. This is a "one stop" method, which means that it will do anything needed to do the job. The method detects syntax errors, only. If one is detected, an error state is returned. In this case, the status of the provided NameValueTree structure is undefined - probably some elements have been added, others not. It is highly recommended that the caller discards the NameValueTree structure if this method does not return error-free. If a pre-populated NameValueTree is provided, the elements found in the XML stream are ADDED to it. This is a single-pass parser. ABNF for our Mini XML Parser:
|
|
Removes the first entry from a list. The entry will be unlinked and then destroyed. It is valid to call this function on an empty list. In this case, nothing will happen. |
|
Remove a keyed entry from a root element. The key search is done on the unsigned key. The first entry with a matching key value is removed. Do not use this method on a list with potentially multiple keys of the same value - or be sure to know EXACTLY what you are doing and why... The entry shall not only be unlinked from the tree but also destroyed. |
|
Remove an entry with a specific pUsr from a root element. The first entry with a matching pUsr is removed. Do not use this method on a list with potentially multiple identical pUsrs - or be sure to know EXACTLY what you are doing and why...
|
|
Unlinks a root element (complete list) from its parent. If the root element has no parent, nothing happens. This is no error. |
|
Find the next element with a given string key inside the list.
|
|
Find the next element with a given integer key inside the list.
|
|
This is more or less a duplicate of the sbNVTSearchKeyU. The difference is that this method also delivers back the previous entry. This is done for performance reasons - it saves us from doubly-linking the list, which would otherwise be required and for sure be overdone in the current state of affairs. AllParams are like sbNVTSearchKeyU plus
|
|
This method searches for a specific pUsr and returns the entry in question PLUS the previous element. This is done for performance reasons - it saves us from doubly-linking the list, which would otherwise be required and for sure be overdone in the current state of affairs.
|
|
Unlink the first element from a name value tree. The element is not destroyed, but simply unlinked.
|
|
XML-Escape a string. The resulting string is suitable for use in #pcdata, that is as a string BETWEEN XML tags (e.g. string. It is NOT suitable to be used inside a tag parameter (e.g. ).
|