2 * ausearch-llist.c - Minimal linked list library
3 * Copyright (c) 2005-2008, 2011 Red Hat Inc., Durham, North Carolina.
4 * Copyright (c) 2011 IBM Corp.
7 * This software may be freely redistributed and/or modified under the
8 * terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2, or (at your option) any
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to the
19 * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * Steve Grubb <sgrubb@redhat.com>
23 * Marcelo Henrique Cerri <mhcerri@br.ibm.com>
28 #include "ausearch-llist.h"
30 void list_create(llist *l)
44 l->s.success = S_UNSET;
66 void list_last(llist *l)
68 register lnode* window;
75 window = window->next;
79 lnode *list_next(llist *l)
83 l->cur = l->cur->next;
87 lnode *list_prev(llist *l)
92 if (l->cur->item == 0)
95 list_find_item(l, l->cur->item-1);
99 void list_append(llist *l, lnode *node)
103 newnode = malloc(sizeof(lnode));
106 newnode->message = node->message;
108 newnode->message = NULL;
110 newnode->type = node->type;
111 newnode->a0 = node->a0;
112 newnode->a1 = node->a1;
113 newnode->item = l->cnt;
114 newnode->next = NULL;
116 // if we are at top, fix this up
119 else // Otherwise add pointer to newnode
120 l->cur->next = newnode;
122 // make newnode current
127 int list_find_item(llist *l, unsigned int i)
129 register lnode* window;
131 if (l->cur && (l->cur->item <= i))
132 window = l->cur; /* Try to use where we are */
134 window = l->head; /* Can't, start over */
137 if (window->item == i) {
141 window = window->next;
146 void list_clear(llist* l)
149 register lnode* current;
153 nextnode=current->next;
154 free(current->message);
164 free((char *)l->e.node);
171 l->s.success = S_UNSET;
176 l->s.hostname = NULL;
178 slist_clear(l->s.filename);
180 l->s.filename = NULL;
183 l->s.terminal = NULL;
189 slist_clear(l->s.key);
196 alist_clear(l->s.avc);
204 l->s.session_id = -2;
210 l->s.exit_is_set = 0;
213 int list_get_event(llist* l, event *e)
215 if (l == NULL || e == NULL)
219 e->milli = l->e.milli;
220 e->serial = l->e.serial;
224 lnode *list_find_msg(llist *l, int i)
226 register lnode* window;
228 window = l->head; /* start at the beginning */
230 if (window->type == i) {
234 window = window->next;
239 lnode *list_find_msg_range(llist *l, int low, int high)
241 register lnode* window;
246 window = l->head; /* Start at the beginning */
248 if (window->type >= low && window->type <= high) {
252 window = window->next;