1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
5 * Copyright (C) 2001-2010, Eduardo Silva P. <edsiper@gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Library General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include <sys/types.h>
25 #include <sys/socket.h>
27 #include <netinet/in.h>
38 #include "http_status.h"
45 long int mk_method_post_content_length(char *body
)
47 struct header_toc
*toc
= NULL
;
51 /* obs: Table of Content (toc) is created when the full
52 * request has arrived, this function cannot be used from
53 * mk_http_pending_request().
55 toc
= mk_cache_get(mk_cache_header_toc
);
56 tmp
= mk_request_header_find(toc
, MK_KNOWN_HEADERS
, body
,
57 mk_rh_content_length
);
70 int mk_method_post(struct client_request
*cr
, struct request
*sr
)
72 struct header_toc
*toc
= NULL
;
74 long content_length_post
= 0;
76 content_length_post
= mk_method_post_content_length(cr
->body
);
79 if (content_length_post
== -1) {
80 mk_request_error(M_CLIENT_LENGTH_REQUIRED
, cr
, sr
);
85 if (content_length_post
<= 0) {
86 mk_request_error(M_CLIENT_BAD_REQUEST
, cr
, sr
);
90 /* Content length too large */
91 if (content_length_post
>= cr
->body_size
) {
92 mk_request_error(M_CLIENT_REQUEST_ENTITY_TOO_LARGE
, cr
, sr
);
96 toc
= mk_cache_get(mk_cache_header_toc
);
97 tmp
= mk_request_header_find(toc
, MK_KNOWN_HEADERS
, sr
->body
.data
,
101 mk_request_error(M_CLIENT_BAD_REQUEST
, cr
, sr
);
104 sr
->content_type
= tmp
;
105 sr
->content_length
= content_length_post
;
110 /* Return POST variables sent in request */
111 mk_pointer
mk_method_post_get_vars(char *body
, int index
)
117 str
= mk_string_copy_substr(body
, index
, strlen(body
));