/** * Invoked to process a part of request body data. * * @param d */ int htp_ch_urlencoded_callback_request_body_data(htp_tx_data_t *d) { if (d->data != NULL) { // Process one chunk of data htp_urlenp_parse_partial(d->tx->request_urlenp_body, d->data, d->len); } else { // Finalize parsing htp_urlenp_finalize(d->tx->request_urlenp_body); if (d->tx->connp->cfg->parameter_processor == NULL) { // We are going to use the parser table directly d->tx->request_params_body = d->tx->request_urlenp_body->params; d->tx->request_params_body_reused = 1; htp_transcode_params(d->tx->connp, &d->tx->request_params_body, 0); } else { // We have a parameter processor defined, which means we'll // need to create a new table d->tx->request_params_body = d->tx->cfg->create_table(table_size(d->tx->request_urlenp_body->params)); // Transform parameters and store them into the new table bstr *name; void *tvalue; table_iterator_reset(d->tx->request_urlenp_body->params); while ((name = table_iterator_next(d->tx->request_urlenp_body->params, & tvalue)) != NULL) { d->tx->connp->cfg->parameter_processor(d->tx->request_params_body, name, (bstr *)tvalue); // TODO Check return code } htp_transcode_params(d->tx->connp, &d->tx->request_params_body, 1); } } return HOOK_OK; }
/** * This callback function feeds request body data to a Urlencoded parser * and, later, feeds the parsed parameters to the correct structures. * * @param[in] d * @return HTP_OK on success, HTP_ERROR on failure. */ htp_status_t htp_ch_urlencoded_callback_request_body_data(htp_tx_data_t *d) { htp_tx_t *tx = d->tx; // Check that we were not invoked again after the finalization. if (tx->request_urlenp_body->params == NULL) return HTP_ERROR; if (d->data != NULL) { // Process one chunk of data. htp_urlenp_parse_partial(tx->request_urlenp_body, d->data, d->len); } else { // Finalize parsing. htp_urlenp_finalize(tx->request_urlenp_body); // Add all parameters to the transaction. bstr *name = NULL; bstr *value = NULL; for (size_t i = 0, n = htp_table_size(tx->request_urlenp_body->params); i < n; i++) { value = htp_table_get_index(tx->request_urlenp_body->params, i, &name); htp_param_t *param = calloc(1, sizeof (htp_param_t)); if (param == NULL) return HTP_ERROR; param->name = name; param->value = value; param->source = HTP_SOURCE_BODY; param->parser_id = HTP_PARSER_URLENCODED; param->parser_data = NULL; if (htp_tx_req_add_param(tx, param) != HTP_OK) { free(param); return HTP_ERROR; } } // All the parameter data is now owned by the transaction, and // the parser table used to store it is no longer needed. The // line below will destroy just the table, leaving keys intact. htp_table_destroy_ex(tx->request_urlenp_body->params); tx->request_urlenp_body->params = NULL; } return HTP_OK; }
/** * Parses the provided data chunk under the assumption * that it contains all the data that will be parsed. When this * method is used for parsing the finalization method should not * be invoked. * * @param urlenp * @param data * @param len * @return */ int htp_urlenp_parse_complete(htp_urlenp_t *urlenp, unsigned char *data, size_t len) { htp_urlenp_parse_partial(urlenp, data, len); return htp_urlenp_finalize(urlenp); }
/** * Finalizes parsing, forcing the parser to convert any outstanding * data into parameters. This method should be invoked at the end * of a parsing operation that used htp_urlenp_parse_partial(). * * @param urlenp * @return Success indication */ int htp_urlenp_finalize(htp_urlenp_t *urlenp) { urlenp->_complete = 1; return htp_urlenp_parse_partial(urlenp, NULL, 0); }
/** * Parses the provided data chunk under the assumption * that it contains all the data that will be parsed. When this * method is used for parsing the finalization method should not * be invoked. * * @param[in] urlenp * @param[in] data * @param[in] len * @return */ htp_status_t htp_urlenp_parse_complete(htp_urlenp_t *urlenp, const void *data, size_t len) { htp_urlenp_parse_partial(urlenp, data, len); return htp_urlenp_finalize(urlenp); }