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 char buffer
[MAX_REQUEST_BODY
];
75 long content_length_post
= 0;
77 content_length_post
= mk_method_post_content_length(cr
->body
);
80 if (content_length_post
== -1) {
81 mk_request_error(M_CLIENT_LENGTH_REQUIRED
, cr
, sr
);
86 if (content_length_post
<= 0) {
87 mk_request_error(M_CLIENT_BAD_REQUEST
, cr
, sr
);
91 /* Content length too large */
92 if (content_length_post
>= MAX_REQUEST_BODY
) {
93 mk_request_error(M_CLIENT_REQUEST_ENTITY_TOO_LARGE
, cr
, sr
);
97 toc
= mk_cache_get(mk_cache_header_toc
);
98 tmp
= mk_request_header_find(toc
, MK_KNOWN_HEADERS
, sr
->body
.data
,
102 mk_request_error(M_CLIENT_BAD_REQUEST
, cr
, sr
);
105 sr
->content_type
= tmp
;
107 if (sr
->post_variables
.len
< content_length_post
) {
108 content_length_post
= strlen(buffer
);
111 sr
->content_length
= content_length_post
;
116 /* Return POST variables sent in request */
117 mk_pointer
mk_method_post_get_vars(char *body
, int index
)
123 str
= mk_string_copy_substr(body
, index
, strlen(body
));