2 The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-)
3 Copyright (C) 2001,2002,2003 Aymeric MOIZARD jack@atosc.org
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <osipparser2/osip_port.h>
24 #include <osipparser2/osip_list.h>
27 osip_list_init (osip_list_t * li)
34 osip_list_special_free (osip_list_t * li, void *(*free_func) (void *))
41 while (!osip_list_eol (li, pos))
43 element = (void *) osip_list_get (li, pos);
44 osip_list_remove (li, pos);
51 osip_list_ofchar_free (osip_list_t * li)
58 while (!osip_list_eol (li, pos))
60 chain = (char *) osip_list_get (li, pos);
61 osip_list_remove (li, pos);
68 osip_list_size (const osip_list_t * li)
71 Robin Nayathodan <roooot@softhome.net>
84 osip_list_eol (const osip_list_t * li, int i)
86 if(li==NULL) return -1;
88 return 0; /* not end of list */
89 return 1; /* end of list */
92 /* index starts from 0; */
94 osip_list_add (osip_list_t * li, void *el, int pos)
99 if (pos == -1 || pos >= li->nb_elt)
100 { /* insert at the end */
107 li->node = (__node_t *) osip_malloc (sizeof (__node_t));
108 li->node->element = el;
113 ntmp = li->node; /* exist because nb_elt>0 */
117 li->node = (__node_t *) osip_malloc (sizeof (__node_t));
118 li->node->element = el;
119 li->node->next = ntmp;
123 /* pos = 0 insert before first elt */
128 /* when pos>i next node exist */
129 ntmp = (__node_t *) ntmp->next;
132 /* if pos==nb_elt next node does not exist */
133 if (pos == li->nb_elt)
135 ntmp->next = (__node_t *) osip_malloc (sizeof (__node_t));
136 ntmp = (__node_t *) ntmp->next;
142 /* here pos==i so next node is where we want to insert new node */
144 __node_t *nextnode = (__node_t *) ntmp->next;
146 ntmp->next = (__node_t *) osip_malloc (sizeof (__node_t));
147 ntmp = (__node_t *) ntmp->next;
149 ntmp->next = nextnode;
155 /* index starts from 0 */
157 osip_list_get (const osip_list_t * li, int pos)
162 if (pos < 0 || pos >= li->nb_elt)
163 /* element does not exist */
167 ntmp = li->node; /* exist because nb_elt>0 */
172 ntmp = (__node_t *) ntmp->next;
174 return ntmp->element;
177 /* return -1 if failed */
179 osip_list_remove (osip_list_t * li, int pos)
185 if (pos < 0 || pos >= li->nb_elt)
186 /* element does not exist */
189 ntmp = li->node; /* exist because nb_elt>0 */
193 li->node = (__node_t *) ntmp->next;
202 ntmp = (__node_t *) ntmp->next;
205 /* if pos==nb_elt next node is the last one */
207 if (pos == li->nb_elt)
209 osip_free (ntmp->next);
215 /* insert new node */
219 remnode = (__node_t *) ntmp->next;
220 ntmp->next = ((__node_t *) ntmp->next)->next;
229 Robin Nayathodan <roooot@softhome.net>
230 N.K Electronics INDIA
232 To Modify the element in the List
238 list_set(osip_list_t * li, void *el, int pos)
243 if (pos < 0 || pos >= li->nb_elt)
244 // element does not exist
248 ntmp = li->node; //exist because nb_elt>0
253 ntmp = (__node_t *) ntmp->next;