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