Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3584 sourcerer 1
/*
2
 * Copyright 2010 John-Mark Bell 
3
 *
4
 * This file is part of NetSurf, http://www.netsurf-browser.org/
5
 *
6
 * NetSurf is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; version 2 of the License.
9
 *
10
 * NetSurf 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
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see .
17
 */
18
 
19
#include 
20
 
21
#include "utils/http/generics.h"
22
#include "utils/http/primitives.h"
23
 
24
/**
25
 * Destructor for an item list
26
 *
27
 * \param list  List to destroy
28
 */
29
void http___item_list_destroy(http__item *list)
30
{
31
	while (list != NULL) {
32
		http__item *victim = list;
33
 
34
		list = victim->next;
35
 
36
		victim->free(victim);
37
	}
38
}
39
 
40
/**
41
 * Parse a list of items
42
 *
43
 * \param input       Pointer to current input byte. Updated on exit.
44
 * \param itemparser  Pointer to function to parse list items
45
 * \param first       Pointer to first item, or NULL.
46
 * \param parameters  Pointer to location to receive on-heap parameter list.
47
 * \return NSERROR_OK on success,
48
 * 	   NSERROR_NOMEM on memory exhaustion,
49
 * 	   NSERROR_NOT_FOUND if no items could be parsed
50
 *
51
 * The returned list is owned by the caller
52
 *
53
 * \note Ownership of the \a first item is passed to this function.
54
 */
55
nserror http___item_list_parse(const char **input,
56
		http__itemparser itemparser, http__item *first,
57
		http__item **items)
58
{
59
	const char *pos = *input;
60
	const char separator = *pos;
61
	http__item *item;
62
	http__item *list = first;
63
	nserror error = NSERROR_OK;
64
 
65
	/* 1*(   ) */
66
 
67
	while (*pos == separator) {
68
		pos++;
69
 
70
		http__skip_LWS(&pos);
71
 
72
		error = itemparser(&pos, &item);
73
		if (error == NSERROR_OK) {
74
			if (list != NULL)
75
				item->next = list;
76
 
77
			list = item;
78
 
79
			http__skip_LWS(&pos);
80
		} else if (error != NSERROR_NOT_FOUND) {
81
			/* Permit  LWS  */
82
			break;
83
		}
84
	}
85
 
86
	if (error != NSERROR_OK && error != NSERROR_NOT_FOUND) {
87
		http__item_list_destroy(list);
88
	} else if (list == NULL) {
89
		error = NSERROR_NOT_FOUND;
90
	} else {
91
		error = NSERROR_OK;
92
		*items = list;
93
		*input = pos;
94
	}
95
 
96
	return error;
97
}
98