1/* 2 * (C) 2005-2012 by Pablo Neira Ayuso <pablo@netfilter.org> 3 * 4 * This program is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 */ 9 10#include <stdio.h> 11#include <stdlib.h> 12#include <string.h> 13#include <errno.h> 14 15#include "stack.h" 16 17struct stack_item * 18stack_item_alloc(int type, size_t data_len) 19{ 20 struct stack_item *e; 21 22 e = calloc(1, sizeof(struct stack_item) + data_len); 23 if (e == NULL) 24 return NULL; 25 26 e->data_len = data_len; 27 e->type = type; 28 29 return e; 30} 31 32void stack_item_free(struct stack_item *e) 33{ 34 free(e); 35} 36 37void stack_item_push(struct stack *s, struct stack_item *e) 38{ 39 list_add(&e->head, &s->list); 40} 41 42struct stack_item *stack_item_pop(struct stack *s, int type) 43{ 44 struct stack_item *cur, *tmp, *found = NULL; 45 46 list_for_each_entry_safe(cur, tmp, &s->list, head) { 47 if (cur->type != type && type != -1) 48 continue; 49 50 list_del(&cur->head); 51 found = cur; 52 break; 53 } 54 55 return found; 56} 57