forked from tomarus/nntpswitch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hlist.c
74 lines (54 loc) · 1.25 KB
/
hlist.c
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//#include <unistd.h>
//#include <stdlib.h>
//#include <string.h>
#include "aconfig.h"
#include "nntpd.h"
#include "aprotos.h"
PROTO void free_hlist(HLIST *h)
{
HLIST *h2 = h;
HLIST *h3 = NULL;
do
{
free(h2->val);
free(h2->hdr);
h3 = h2;
h2 = h2->next;
free(h3);
}
while( h2 != NULL );
}
PROTO HLIST * insert_hlist(HLIST *first, char *hdr, char *val)
{
HLIST *i = first, *last = NULL;
while (i != NULL) { last=i; i=i->next; }
i = malloc(sizeof(HLIST));
if (i == NULL) { die("No room for HLIST"); }
if (last != NULL) last->next = i;
i->hdr = strdup(hdr);
i->val = strdup(val);
i->next = NULL;
return i;
}
PROTO char * hlist_get_value(HLIST *first, char *hdr)
{
HLIST *i = first;
while ( i != NULL && strcasecmp(i->hdr, hdr) )
i = i->next;
if ( i == NULL )
return NULL;
return i->val;
}
PROTO char * hlist_replace_value(HLIST *first, char *hdr, char *replace)
{
HLIST *i = first;
while ( i != NULL && strcasecmp(i->hdr, hdr) )
i = i->next;
if ( i == NULL )
return NULL;
free(i->val);
i->val = strdup(replace);
if ( i->val == NULL )
syslog(LOG_ERR, "Out of memory for hlist replace");
return i->val;
}