NetSurf
content-disposition.c
Go to the documentation of this file.
1/*
2 * Copyright 2010 John-Mark Bell <jmb@netsurf-browser.org>
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 <http://www.gnu.org/licenses/>.
17 */
18
19#include <stdlib.h>
20
21#include "utils/http.h"
22
23#include "utils/http/generics.h"
26
27/* See content-disposition.h for documentation */
28nserror http_parse_content_disposition(const char *header_value,
30{
31 const char *pos = header_value;
32 lwc_string *mtype;
33 http_parameter *params = NULL;
35 nserror error;
36
37 /* disposition-type *( ";" parameter ) */
38
39 http__skip_LWS(&pos);
40
41 error = http__parse_token(&pos, &mtype);
42 if (error != NSERROR_OK)
43 return error;
44
45 http__skip_LWS(&pos);
46
47 if (*pos == ';') {
48 error = http__item_list_parse(&pos,
49 http__parse_parameter, NULL, &params);
50 if (error != NSERROR_OK && error != NSERROR_NOT_FOUND) {
51 lwc_string_unref(mtype);
52 return error;
53 }
54 }
55
56 cd = malloc(sizeof(*cd));
57 if (cd == NULL) {
59 lwc_string_unref(mtype);
60 return NSERROR_NOMEM;
61 }
62
63 cd->disposition_type = mtype;
64 cd->parameters = params;
65
66 *result = cd;
67
68 return NSERROR_OK;
69}
70
71/* See content-disposition.h for documentation */
73{
74 lwc_string_unref(victim->disposition_type);
76 free(victim);
77}
78
STATIC char result[100]
Definition: arexx.c:77
nserror http_parse_content_disposition(const char *header_value, http_content_disposition **result)
Parse an HTTP Content-Disposition header value.
void http_content_disposition_destroy(http_content_disposition *victim)
Destroy a content disposition object.
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_NOT_FOUND
Requested item not found.
Definition: errors.h:34
@ NSERROR_NOMEM
Memory exhaustion.
Definition: errors.h:32
@ NSERROR_OK
No error.
Definition: errors.h:30
#define http__item_list_parse(i, p, f, r)
Definition: generics.h:52
HTTP header parsing functions.
void http_parameter_list_destroy(http_parameter *list)
Destroy a list of HTTP parameters.
Definition: parameter.c:149
nserror http__parse_parameter(const char **input, http_parameter **parameter)
Parse an HTTP parameter.
Definition: parameter.c:61
nserror http__parse_token(const char **input, lwc_string **value)
Parse an HTTP token.
Definition: primitives.c:68
void http__skip_LWS(const char **input)
Skip past linear whitespace in input.
Definition: primitives.c:31
Representation of an HTTP parameter.
Definition: parameter.c:31
iconv_t cd
Iconv conversion descriptor.
Definition: utf8.c:145