00001 /*************************************************************************** 00002 * Copyright (c) 2009-2010, Open Information Security Foundation 00003 * Copyright (c) 2009-2012, Qualys, Inc. 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are 00008 * met: 00009 * 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * * Neither the name of the Qualys, Inc. nor the names of its 00016 * contributors may be used to endorse or promote products derived from 00017 * this software without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00020 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00021 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00022 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00023 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00024 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00025 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00026 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00027 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00028 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00029 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 ***************************************************************************/ 00031 00037 #ifndef _HTP_URLENCODED_H 00038 #define _HTP_URLENCODED_H 00039 00040 typedef struct htp_urlenp_t htp_urlenp_t; 00041 typedef struct htp_urlen_param_t htp_urlen_param_t; 00042 00043 #include "htp.h" 00044 00045 #define HTP_URLENP_DEFAULT_PARAMS_SIZE 32 00046 00047 #define HTP_URLENP_STATE_KEY 1 00048 #define HTP_URLENP_STATE_VALUE 2 00049 00050 #define HTP_URLENCODED_MIME_TYPE "application/x-www-form-urlencoded" 00051 00052 #ifdef __cplusplus 00053 extern "C" { 00054 #endif 00055 00060 struct htp_urlenp_t { 00062 htp_tx_t *tx; 00063 00067 unsigned char argument_separator; 00068 00070 int decode_url_encoding; 00071 00073 table_t *params; 00074 00075 // Private fields; these are used during the parsing process only 00076 int _state; 00077 int _complete; 00078 bstr *_name; 00079 bstr_builder_t *_bb; 00080 }; 00081 00085 struct htp_urlen_param_t { 00087 bstr *name; 00088 00090 bstr *value; 00091 }; 00092 00093 htp_urlenp_t *htp_urlenp_create(htp_tx_t *tx); 00094 void htp_urlenp_destroy(htp_urlenp_t **urlenp); 00095 00096 void htp_urlenp_set_argument_separator(htp_urlenp_t *urlenp, unsigned char argument_separator); 00097 void htp_urlenp_set_decode_url_encoding(htp_urlenp_t *urlenp, int decode_url_encoding); 00098 00099 int htp_urlenp_parse_partial(htp_urlenp_t *urlenp, unsigned char *data, size_t len); 00100 int htp_urlenp_parse_complete(htp_urlenp_t *urlenp, unsigned char *data, size_t len); 00101 int htp_urlenp_finalize(htp_urlenp_t *urlenp); 00102 00103 int htp_ch_urlencoded_callback_request_line(htp_connp_t *connp); 00104 int htp_ch_urlencoded_callback_request_headers(htp_connp_t *connp); 00105 00106 #ifdef __cplusplus 00107 } 00108 #endif 00109 00110 #endif /* _HTP_URLENCODED_H */ 00111