| 1 | 42a43,160 |
|---|
| 2 | > // The following are declarations needed for the modp_burl string decoding |
|---|
| 3 | > // functions. They were cribbed from the stringencoders-v3.7.0 source tree. |
|---|
| 4 | > // syc 1/20/09 |
|---|
| 5 | > |
|---|
| 6 | > /** |
|---|
| 7 | > * \file |
|---|
| 8 | > * <pre> |
|---|
| 9 | > * BFASTURL.c High performance URL encoder/decoder |
|---|
| 10 | > * http://code.google.com/p/stringencoders/ |
|---|
| 11 | > * |
|---|
| 12 | > * Copyright © 2006,2007 Nick Galbreath -- nickg [at] modp [dot] com |
|---|
| 13 | > * All rights reserved. |
|---|
| 14 | > * |
|---|
| 15 | > * Redistribution and use in source and binary forms, with or without |
|---|
| 16 | > * modification, are permitted provided that the following conditions are |
|---|
| 17 | > * met: |
|---|
| 18 | > * |
|---|
| 19 | > * Redistributions of source code must retain the above copyright |
|---|
| 20 | > * notice, this list of conditions and the following disclaimer. |
|---|
| 21 | > * |
|---|
| 22 | > * Redistributions in binary form must reproduce the above copyright |
|---|
| 23 | > * notice, this list of conditions and the following disclaimer in the |
|---|
| 24 | > * documentation and/or other materials provided with the distribution. |
|---|
| 25 | > * |
|---|
| 26 | > * Neither the name of the modp.com nor the names of its |
|---|
| 27 | > * contributors may be used to endorse or promote products derived from |
|---|
| 28 | > * this software without specific prior written permission. |
|---|
| 29 | > * |
|---|
| 30 | > * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|---|
| 31 | > * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|---|
| 32 | > * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|---|
| 33 | > * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|---|
| 34 | > * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|---|
| 35 | > * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|---|
| 36 | > * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|---|
| 37 | > * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|---|
| 38 | > * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|---|
| 39 | > * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|---|
| 40 | > * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 41 | > * |
|---|
| 42 | > * This is the standard "new" BSD license: |
|---|
| 43 | > * http://www.opensource.org/licenses/bsd-license.php |
|---|
| 44 | > * </PRE> |
|---|
| 45 | > */ |
|---|
| 46 | > |
|---|
| 47 | > static const uint32_t gsHexDecodeMap[256] = { |
|---|
| 48 | > 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, |
|---|
| 49 | > 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, |
|---|
| 50 | > 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, |
|---|
| 51 | > 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, |
|---|
| 52 | > 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 256, 256, |
|---|
| 53 | > 256, 256, 256, 256, 256, 10, 11, 12, 13, 14, 15, 256, |
|---|
| 54 | > 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, |
|---|
| 55 | > 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, |
|---|
| 56 | > 256, 10, 11, 12, 13, 14, 15, 256, 256, 256, 256, 256, |
|---|
| 57 | > 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, |
|---|
| 58 | > 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, |
|---|
| 59 | > 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, |
|---|
| 60 | > 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, |
|---|
| 61 | > 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, |
|---|
| 62 | > 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, |
|---|
| 63 | > 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, |
|---|
| 64 | > 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, |
|---|
| 65 | > 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, |
|---|
| 66 | > 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, |
|---|
| 67 | > 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, |
|---|
| 68 | > 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, |
|---|
| 69 | > 256, 256, 256, 256 |
|---|
| 70 | > }; |
|---|
| 71 | > |
|---|
| 72 | > |
|---|
| 73 | > int modp_burl_decode(char* dest, const char* s, int len) |
|---|
| 74 | > { |
|---|
| 75 | > uint32_t d = 0; // used for decoding %XX |
|---|
| 76 | > const uint8_t* src = (const uint8_t*) s; |
|---|
| 77 | > const char* deststart = dest; |
|---|
| 78 | > const uint8_t* srcend = (const uint8_t*)(src + len); |
|---|
| 79 | > const uint8_t* srcendloop = (const uint8_t*)(srcend - 2); |
|---|
| 80 | > |
|---|
| 81 | > while (src < srcendloop) { |
|---|
| 82 | > switch (*src) { |
|---|
| 83 | > case '+': |
|---|
| 84 | > *dest++ = ' '; |
|---|
| 85 | > src++; |
|---|
| 86 | > break; |
|---|
| 87 | > case '%': |
|---|
| 88 | > d = (gsHexDecodeMap[(uint32_t)(*(src + 1))] << 4) | |
|---|
| 89 | > gsHexDecodeMap[(uint32_t)(*(src + 2))]; |
|---|
| 90 | > if (d < 256) { // if one of the hex chars is bad, d >= 256 |
|---|
| 91 | > *dest = (char) d; |
|---|
| 92 | > dest++; |
|---|
| 93 | > src += 3; |
|---|
| 94 | > } else { |
|---|
| 95 | > *dest++ = '%'; |
|---|
| 96 | > src++; |
|---|
| 97 | > } |
|---|
| 98 | > break; |
|---|
| 99 | > default: |
|---|
| 100 | > *dest++ = *src++; |
|---|
| 101 | > } |
|---|
| 102 | > } |
|---|
| 103 | > |
|---|
| 104 | > // handle last two chars |
|---|
| 105 | > // dont decode "%XX" |
|---|
| 106 | > while (src < srcend) { |
|---|
| 107 | > switch (*src) { |
|---|
| 108 | > case '+': |
|---|
| 109 | > *dest++ = ' '; |
|---|
| 110 | > src++; |
|---|
| 111 | > break; |
|---|
| 112 | > default: |
|---|
| 113 | > *dest++ = *src++; |
|---|
| 114 | > } |
|---|
| 115 | > } |
|---|
| 116 | > |
|---|
| 117 | > *dest = '\0'; |
|---|
| 118 | > return dest - deststart; // compute "strlen" of dest. |
|---|
| 119 | > } |
|---|
| 120 | 56c174 |
|---|
| 121 | < " string, int, count, double, bool, time, \n" |
|---|
| 122 | --- |
|---|
| 123 | > " string, urlstring, int, count, double, bool, time, \n" |
|---|
| 124 | 59c177,179 |
|---|
| 125 | < " net=10.10.10.0 and subnet=10.0.0.0/8\n"; |
|---|
| 126 | --- |
|---|
| 127 | > " net=10.10.10.0, subnet=10.0.0.0/8\n" |
|---|
| 128 | > " urlstring is a url encoded string type - use this when\n" |
|---|
| 129 | > " whitespace can be found in the strings\n"; |
|---|
| 130 | 231a352,354 |
|---|
| 131 | > char *urlstr = NULL; |
|---|
| 132 | > int urlstrsz = 0; |
|---|
| 133 | > |
|---|
| 134 | 239c362 |
|---|
| 135 | < host = default_host; |
|---|
| 136 | --- |
|---|
| 137 | > host = default_host + ":" + default_port; |
|---|
| 138 | 281,282c404,409 |
|---|
| 139 | < if (argc == 1) |
|---|
| 140 | < host = argv[0]; |
|---|
| 141 | --- |
|---|
| 142 | > if (argc == 1) { |
|---|
| 143 | > host = argv[0]; |
|---|
| 144 | > if (host.find(':') == string::npos) |
|---|
| 145 | > host += ":" + default_port; |
|---|
| 146 | > } |
|---|
| 147 | > |
|---|
| 148 | 361a489,509 |
|---|
| 149 | > else if (tkn_type == "urlstring") |
|---|
| 150 | > { |
|---|
| 151 | > BroString arg; |
|---|
| 152 | > bro_string_init(&arg); |
|---|
| 153 | > int sz= strlen(tkn_data.c_str()) + 1; |
|---|
| 154 | > if ( sz > urlstrsz) { |
|---|
| 155 | > if (urlstr) |
|---|
| 156 | > free( urlstr); |
|---|
| 157 | > urlstr = (char *)malloc( sz); |
|---|
| 158 | > if (urlstr == NULL) { |
|---|
| 159 | > fprintf( stderr,"Could not allocate %d bytes for url conversion buffer\n",sz); |
|---|
| 160 | > return(1); |
|---|
| 161 | > } |
|---|
| 162 | > urlstrsz = sz; |
|---|
| 163 | > } |
|---|
| 164 | > modp_burl_decode(urlstr,tkn_data.c_str(),strlen(tkn_data.c_str())); |
|---|
| 165 | > bro_string_set(&arg,urlstr); |
|---|
| 166 | > bro_event_add_val(ev, BRO_TYPE_STRING, NULL, &arg); |
|---|
| 167 | > bro_string_cleanup(&arg); |
|---|
| 168 | > } |
|---|
| 169 | > |
|---|