/** var post: Hash[String, Tainted[String]] This contains key+value pairs that were sent to the server as POST variables. Any pair that has a key or a value that is not valid utf-8 will not be present. */ static lily_value *load_var_post(lily_options *options, uint16_t *unused) { lily_value *v = lily_new_empty_value(); lily_move_hash_f(MOVE_DEREF_NO_GC, v, lily_new_hash_val()); lily_hash_val *hash_val = v->value.hash; request_rec *r = (request_rec *)options->data; apr_array_header_t *pairs; apr_off_t len; apr_size_t size; char *buffer; /* Credit: I found out how to use this by reading httpd 2.4's mod_lua (specifically req_parsebody of lua_request.c). */ int res = ap_parse_form_data(r, NULL, &pairs, -1, 1024 * 8); if (res == OK) { while (pairs && !apr_is_empty_array(pairs)) { ap_form_pair_t *pair = (ap_form_pair_t *) apr_array_pop(pairs); if (lily_is_valid_utf8(pair->name) == 0) continue; apr_brigade_length(pair->value, 1, &len); size = (apr_size_t) len; buffer = lily_malloc(size + 1); if (lily_is_valid_utf8(buffer) == 0) { lily_free(buffer); continue; } apr_brigade_flatten(pair->value, buffer, &size); buffer[len] = 0; lily_value *elem_key = lily_new_string(pair->name); /* Give the buffer to the value to save memory. */ lily_value *elem_raw_value = lily_new_string_take(buffer); lily_value *elem_value = bind_tainted_of(elem_raw_value); apache_add_unique_hash_entry(options->sipkey, hash_val, elem_key, elem_value); } } return v; }
lily_bytestring_val *lily_new_bytestring_take(char *source) { return (lily_bytestring_val *)lily_new_string_take(source); }