aboutsummaryrefslogtreecommitdiff
path: root/src/cookie.c
blob: eaa221fd53846a85d34d461e77678f7533f89e7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "cookie.h"

#include <stdlib.h>
#include <string.h>


int magi_cookie_list_add(struct magi_cookie_list ** list,
                         struct magi_cookie *       item)
{
    struct magi_cookie_list * node = malloc(sizeof(*node));
    if (node) {
        node->next = *list;
        node->item = *item;
        *list      = node;
    }
    return !!node;
}

struct magi_cookie * magi_cookie_list_get(struct magi_cookie_list * list,
                                          const char *              name)
{
    if (!list || !name) {
        return 0;
    } else if (!strcmp(list->item.name, name)) {
        return &list->item;
    } else {
        return magi_cookie_list_get(list->next, name);
    }
}

void magi_cookie_list_destroy(struct magi_cookie_list * list)
{
    if (list) {
        magi_cookie_list_destroy(list->next);
        free(list->next);
        free(list->item.name);
        free(list->item.data);
        free(list->item.path);
        free(list->item.domain);
        free(list->item.port);
    }
}