aboutsummaryrefslogtreecommitdiff
path: root/src/json/json_mhd.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-05-02 22:24:42 +0200
committerChristian Grothoff <christian@grothoff.org>2019-05-02 22:24:42 +0200
commit1eadd51205794a18e74f135672c96613d4f8734b (patch)
tree79dae4cf5ad1547e9e48aa87428e64c864af28f2 /src/json/json_mhd.c
parent5ef270d2a7fa5c32d874fc7da2f026998ff0ab8e (diff)
downloadgnunet-1eadd51205794a18e74f135672c96613d4f8734b.tar.gz
gnunet-1eadd51205794a18e74f135672c96613d4f8734b.zip
preparatory change to GNUNET_JSON_post_parser() API for future compression support
Diffstat (limited to 'src/json/json_mhd.c')
-rw-r--r--src/json/json_mhd.c31
1 files changed, 13 insertions, 18 deletions
diff --git a/src/json/json_mhd.c b/src/json/json_mhd.c
index f095e1011..30b29b88e 100644
--- a/src/json/json_mhd.c
+++ b/src/json/json_mhd.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -27,12 +27,13 @@
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_json_lib.h" 28#include "gnunet_json_lib.h"
29 29
30
30/** 31/**
31 * Initial size for POST request buffers. Should be big enough to 32 * Initial size for POST request buffers. Should be big enough to
32 * usually not require a reallocation, but not so big that it hurts in 33 * usually not require a reallocation, but not so big that it hurts in
33 * terms of memory use. 34 * terms of memory use.
34 */ 35 */
35#define REQUEST_BUFFER_INITIAL (2*1024) 36#define REQUEST_BUFFER_INITIAL (2 * 1024)
36 37
37 38
38/** 39/**
@@ -74,8 +75,7 @@ buffer_init (struct Buffer *buf,
74 size_t alloc_size, 75 size_t alloc_size,
75 size_t max_size) 76 size_t max_size)
76{ 77{
77 if ( (data_size > max_size) || 78 if ((data_size > max_size) || (alloc_size > max_size))
78 (alloc_size > max_size) )
79 return GNUNET_SYSERR; 79 return GNUNET_SYSERR;
80 if (data_size > alloc_size) 80 if (data_size > alloc_size)
81 alloc_size = data_size; 81 alloc_size = data_size;
@@ -145,6 +145,7 @@ buffer_append (struct Buffer *buf,
145 * #GNUNET_JSON_post_parser_callback(). 145 * #GNUNET_JSON_post_parser_callback().
146 * 146 *
147 * @param buffer_max maximum allowed size for the buffer 147 * @param buffer_max maximum allowed size for the buffer
148 * @param connection MHD connection handle (for meta data about the upload)
148 * @param con_cls the closure (will point to a `struct Buffer *`) 149 * @param con_cls the closure (will point to a `struct Buffer *`)
149 * @param upload_data the POST data 150 * @param upload_data the POST data
150 * @param upload_data_size number of bytes in @a upload_data 151 * @param upload_data_size number of bytes in @a upload_data
@@ -153,6 +154,7 @@ buffer_append (struct Buffer *buf,
153 */ 154 */
154enum GNUNET_JSON_PostResult 155enum GNUNET_JSON_PostResult
155GNUNET_JSON_post_parser (size_t buffer_max, 156GNUNET_JSON_post_parser (size_t buffer_max,
157 struct MHD_Connection *connection,
156 void **con_cls, 158 void **con_cls,
157 const char *upload_data, 159 const char *upload_data,
158 size_t *upload_data_size, 160 size_t *upload_data_size,
@@ -165,12 +167,11 @@ GNUNET_JSON_post_parser (size_t buffer_max,
165 { 167 {
166 /* We are seeing a fresh POST request. */ 168 /* We are seeing a fresh POST request. */
167 r = GNUNET_new (struct Buffer); 169 r = GNUNET_new (struct Buffer);
168 if (GNUNET_OK != 170 if (GNUNET_OK != buffer_init (r,
169 buffer_init (r, 171 upload_data,
170 upload_data, 172 *upload_data_size,
171 *upload_data_size, 173 REQUEST_BUFFER_INITIAL,
172 REQUEST_BUFFER_INITIAL, 174 buffer_max))
173 buffer_max))
174 { 175 {
175 *con_cls = NULL; 176 *con_cls = NULL;
176 buffer_deinit (r); 177 buffer_deinit (r);
@@ -187,10 +188,7 @@ GNUNET_JSON_post_parser (size_t buffer_max,
187 /* We are seeing an old request with more data available. */ 188 /* We are seeing an old request with more data available. */
188 189
189 if (GNUNET_OK != 190 if (GNUNET_OK !=
190 buffer_append (r, 191 buffer_append (r, upload_data, *upload_data_size, buffer_max))
191 upload_data,
192 *upload_data_size,
193 buffer_max))
194 { 192 {
195 /* Request too long */ 193 /* Request too long */
196 *con_cls = NULL; 194 *con_cls = NULL;
@@ -205,10 +203,7 @@ GNUNET_JSON_post_parser (size_t buffer_max,
205 203
206 /* We have seen the whole request. */ 204 /* We have seen the whole request. */
207 205
208 *json = json_loadb (r->data, 206 *json = json_loadb (r->data, r->fill, 0, NULL);
209 r->fill,
210 0,
211 NULL);
212 if (NULL == *json) 207 if (NULL == *json)
213 { 208 {
214 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 209 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,