MCPcopy Create free account
hub / github.com/apache/httpd / req_parsebody

Function req_parsebody

modules/lua/lua_request.c:380–449  ·  view source on GitHub ↗

r:parsebody(): Parses regular (url-enocded) or multipart POST data and returns two tables*/

Source from the content-addressed store, hash-verified

378
379/* r:parsebody(): Parses regular (url-enocded) or multipart POST data and returns two tables*/
380static int req_parsebody(lua_State *L)
381{
382 apr_array_header_t *pairs;
383 apr_off_t len;
384 int res;
385 apr_size_t size;
386 apr_size_t max_post_size;
387 char *multipart;
388 const char *contentType;
389 request_rec *r = ap_lua_check_request_rec(L, 1);
390 max_post_size = (apr_size_t) luaL_optinteger(L, 2, MAX_STRING_LEN);
391 multipart = apr_pcalloc(r->pool, 256);
392 contentType = apr_table_get(r->headers_in, "Content-Type");
393 lua_newtable(L);
394 lua_newtable(L); /* [table, table] */
395 if (contentType != NULL && (sscanf(contentType, "multipart/form-data; boundary=%250c", multipart) == 1)) {
396 char *buffer, *key, *filename;
397 char *start = 0, *end = 0, *crlf = 0;
398 const char *data;
399 int i;
400 size_t vlen = 0;
401 size_t len = 0;
402 if (lua_read_body(r, &data, (apr_off_t*) &size, max_post_size) != OK) {
403 return 2;
404 }
405 len = strlen(multipart);
406 i = 0;
407 for
408 (
409 start = strstr((char *) data, multipart);
410 start != NULL;
411 start = end
412 ) {
413 i++;
414 if (i == POST_MAX_VARS) break;
415 crlf = strstr((char *) start, "\r\n\r\n");
416 if (!crlf) break;
417 end = ap_lua_binstrstr(crlf, (size - (crlf - data)), multipart, len);
418 if (end == NULL) break;
419 key = (char *) apr_pcalloc(r->pool, 256);
420 filename = (char *) apr_pcalloc(r->pool, 256);
421 if (end - crlf <= 8) break;
422 vlen = end - crlf - 8;
423 buffer = (char *) apr_pcalloc(r->pool, vlen+1);
424 memcpy(buffer, crlf + 4, vlen);
425 sscanf(start + len + 2,
426 "Content-Disposition: form-data; name=\"%255[^\"]\"; filename=\"%255[^\"]\"",
427 key, filename);
428 if (*key) {
429 req_aprtable2luatable_cb_len(L, key, buffer, vlen);
430 }
431 }
432 }
433 else {
434 char *buffer;
435 res = ap_parse_form_data(r, NULL, &pairs, -1, max_post_size);
436 if (res == OK) {
437 while(pairs && !apr_is_empty_array(pairs)) {

Callers

nothing calls this directly

Calls 6

lua_read_bodyFunction · 0.85
ap_lua_binstrstrFunction · 0.85
ap_parse_form_dataFunction · 0.85
req_aprtable2luatable_cbFunction · 0.85
ap_lua_check_request_recFunction · 0.70

Tested by

no test coverage detected