UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
nodeList.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 *
3 * Copyright (c) 2000-2003 Intel Corporation
4 * All rights reserved.
5 * Copyright (c) 2012 France Telecom All rights reserved.
6 * Copyright (C) 2022 GPL 3 and higher by Ingo Höft, <Ingo@Hoeft-online.de>
7 * Redistribution only with this Copyright remark. Last modified: 2025-05-29
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 * - Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 * - Neither name of Intel Corporation nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
29 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 ******************************************************************************/
38#include <ixml/ixmlparser.hpp>
39
40#include <cassert>
41#include <cstring>
42
44 assert(nList != NULL);
45
46 memset(nList, 0, sizeof(IXML_NodeList));
47}
48
49IXML_Node* ixmlNodeList_item(IXML_NodeList* nList, unsigned long index) {
50 IXML_NodeList* next;
51 unsigned int i;
52
53 /* if the list ptr is NULL */
54 if (nList == NULL) {
55 return NULL;
56 }
57 /* if index is more than list length */
58 if (index > ixmlNodeList_length(nList) - 1lu) {
59 return NULL;
60 }
61
62 next = nList;
63 for (i = 0u; i < index && next != NULL; ++i) {
64 next = next->next;
65 }
66
67 if (next == NULL) {
68 return NULL;
69 }
70
71 return next->nodeItem;
72}
73
75 IXML_NodeList* traverse = NULL;
76 IXML_NodeList* p = NULL;
77 IXML_NodeList* newListItem;
78
79 assert(add != NULL);
80
81 if (add == NULL) {
82 return IXML_FAILED;
83 }
84
85 if (*nList == NULL) {
86 /* nodelist is empty */
87 *nList = (IXML_NodeList*)malloc(sizeof(IXML_NodeList));
88 if (*nList == NULL) {
89 return IXML_INSUFFICIENT_MEMORY;
90 }
91
92 ixmlNodeList_init(*nList);
93 }
94
95 if ((*nList)->nodeItem == NULL) {
96 (*nList)->nodeItem = add;
97 } else {
98 traverse = *nList;
99 while (traverse != NULL) {
100 p = traverse;
101 traverse = traverse->next;
102 }
103
104 newListItem = (IXML_NodeList*)malloc(sizeof(IXML_NodeList));
105 if (newListItem == NULL) {
106 return IXML_INSUFFICIENT_MEMORY;
107 }
108 p->next = newListItem;
109 newListItem->nodeItem = add;
110 newListItem->next = NULL;
111 }
112
113 return IXML_SUCCESS;
114}
115
116unsigned long ixmlNodeList_length(IXML_NodeList* nList) {
117 IXML_NodeList* list;
118 unsigned long length = 0lu;
119
120 list = nList;
121 while (list != NULL) {
122 ++length;
123 list = list->next;
124 }
125
126 return length;
127}
128
130 IXML_NodeList* next;
131
132 while (nList != NULL) {
133 next = nList->next;
134 free(nList);
135 nList = next;
136 }
137}
Data structure common to all types of nodes.
Definition ixml.hpp:132
Data structure representing a list of nodes.
Definition ixml.hpp:193
unsigned long ixmlNodeList_length(IXML_NodeList *nList)
Returns the number of Nodes in a NodeList.
Definition nodeList.cpp:116
void ixmlNodeList_free(IXML_NodeList *nList)
Frees a NodeList object.
Definition nodeList.cpp:129
IXML_Node * ixmlNodeList_item(IXML_NodeList *nList, unsigned long index)
Retrieves a Node from a NodeList specified by a numerical index.
Definition nodeList.cpp:49
int ixmlNodeList_addToNodeList(IXML_NodeList **nList, IXML_Node *add)
Add a node to nodelist.
Definition nodeList.cpp:74
void ixmlNodeList_init(IXML_NodeList *nList)
Initializes a nodelist.
Definition nodeList.cpp:43