| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | /* | 
| 2 |  |  |  |  |  |  | Copyright (C) 2016-2017 Alexander Borisov | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | This library is free software; you can redistribute it and/or | 
| 5 |  |  |  |  |  |  | modify it under the terms of the GNU Lesser General Public | 
| 6 |  |  |  |  |  |  | License as published by the Free Software Foundation; either | 
| 7 |  |  |  |  |  |  | version 2.1 of the License, or (at your option) any later version. | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | This library is distributed in the hope that it will be useful, | 
| 10 |  |  |  |  |  |  | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 11 |  |  |  |  |  |  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 
| 12 |  |  |  |  |  |  | Lesser General Public License for more details. | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | You should have received a copy of the GNU Lesser General Public | 
| 15 |  |  |  |  |  |  | License along with this library; if not, write to the Free Software | 
| 16 |  |  |  |  |  |  | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | Author: lex.borisov@gmail.com (Alexander Borisov) | 
| 19 |  |  |  |  |  |  | */ | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | #include "modest/finder/match.h" | 
| 22 |  |  |  |  |  |  |  | 
| 23 | 0 |  |  |  |  |  | bool modest_finder_match_attribute_only_key(myhtml_token_attr_t* attr, const char* key, size_t key_len) | 
| 24 |  |  |  |  |  |  | { | 
| 25 | 0 | 0 |  |  |  |  | if(key == NULL) | 
| 26 | 0 |  |  |  |  |  | return false; | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 0 | 0 |  |  |  |  | while (attr) | 
| 29 |  |  |  |  |  |  | { | 
| 30 | 0 | 0 |  |  |  |  | if(attr->key.length == key_len) { | 
| 31 | 0 | 0 |  |  |  |  | if(mycore_strncasecmp(key, attr->key.data, key_len) == 0) | 
| 32 | 0 |  |  |  |  |  | return true; | 
| 33 |  |  |  |  |  |  | } | 
| 34 |  |  |  |  |  |  |  | 
| 35 | 0 |  |  |  |  |  | attr = attr->next; | 
| 36 |  |  |  |  |  |  | } | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 0 |  |  |  |  |  | return false; | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 173 |  |  |  |  |  | bool modest_finder_match_attribute_eq(myhtml_token_attr_t* attr, const char* key, size_t key_len, const char* value, size_t value_len, bool case_sensitive) | 
| 42 |  |  |  |  |  |  | { | 
| 43 | 173 | 50 |  |  |  |  | if(key == NULL || value == NULL) | 
|  |  | 50 |  |  |  |  |  | 
| 44 | 0 |  |  |  |  |  | return false; | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 191 | 100 |  |  |  |  | while (attr) | 
| 47 |  |  |  |  |  |  | { | 
| 48 | 56 | 100 |  |  |  |  | if(attr->key.length == key_len) { | 
| 49 | 38 | 50 |  |  |  |  | if(mycore_strncasecmp(key, attr->key.data, key_len) == 0) | 
| 50 |  |  |  |  |  |  | { | 
| 51 | 38 | 50 |  |  |  |  | if(attr->value.length == value_len) { | 
| 52 | 38 | 50 |  |  |  |  | if(case_sensitive) { | 
| 53 | 0 | 0 |  |  |  |  | if(strncmp(value, attr->value.data, value_len) == 0) { | 
| 54 | 0 |  |  |  |  |  | return true; | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  | else { | 
| 58 | 38 | 50 |  |  |  |  | if(mycore_strncasecmp(value, attr->value.data, value_len) == 0) { | 
| 59 | 38 |  |  |  |  |  | return true; | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  | } | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  |  | 
| 64 | 0 |  |  |  |  |  | break; | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  | } | 
| 67 |  |  |  |  |  |  |  | 
| 68 | 18 |  |  |  |  |  | attr = attr->next; | 
| 69 |  |  |  |  |  |  | } | 
| 70 |  |  |  |  |  |  |  | 
| 71 | 135 |  |  |  |  |  | return false; | 
| 72 |  |  |  |  |  |  | } | 
| 73 |  |  |  |  |  |  |  | 
| 74 | 325 |  |  |  |  |  | bool modest_finder_match_attribute_ws(myhtml_token_attr_t* attr, const char* key, size_t key_len, const char* value, size_t value_len, bool case_sensitive) | 
| 75 |  |  |  |  |  |  | { | 
| 76 | 325 | 50 |  |  |  |  | if(key == NULL || value == NULL) | 
|  |  | 50 |  |  |  |  |  | 
| 77 | 0 |  |  |  |  |  | return false; | 
| 78 |  |  |  |  |  |  |  | 
| 79 | 649 | 100 |  |  |  |  | while (attr) | 
| 80 |  |  |  |  |  |  | { | 
| 81 | 421 | 100 |  |  |  |  | if(attr->key.length == key_len) { | 
| 82 | 97 | 50 |  |  |  |  | if(mycore_strncasecmp(key, attr->key.data, key_len) == 0) | 
| 83 |  |  |  |  |  |  | { | 
| 84 | 97 |  |  |  |  |  | size_t i = 0; | 
| 85 |  |  |  |  |  |  | size_t begin; | 
| 86 |  |  |  |  |  |  |  | 
| 87 | 97 | 100 |  |  |  |  | if(attr->value.length >= value_len) { | 
| 88 | 65 | 100 |  |  |  |  | if(case_sensitive) | 
| 89 |  |  |  |  |  |  | { | 
| 90 | 120 | 100 |  |  |  |  | while(i < attr->value.length) | 
| 91 |  |  |  |  |  |  | { | 
| 92 | 80 |  |  |  |  |  | begin = i; | 
| 93 | 448 | 100 |  |  |  |  | while(i < attr->value.length && mycore_utils_whithspace(attr->value.data[i], !=, &&)) {i++;} | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
| 94 |  |  |  |  |  |  |  | 
| 95 | 80 | 100 |  |  |  |  | if((i - begin) == value_len && (mycore_strncmp(value, &attr->value.data[begin], value_len) == 0)) { | 
|  |  | 100 |  |  |  |  |  | 
| 96 | 24 |  |  |  |  |  | return true; | 
| 97 |  |  |  |  |  |  | } | 
| 98 |  |  |  |  |  |  | /* skip all ws */ | 
| 99 | 72 | 100 |  |  |  |  | while(i < attr->value.length && mycore_utils_whithspace(attr->value.data[i], ==, ||)) {i++;} | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | } | 
| 101 |  |  |  |  |  |  | } | 
| 102 |  |  |  |  |  |  | else { | 
| 103 | 1 | 50 |  |  |  |  | while(i < attr->value.length) | 
| 104 |  |  |  |  |  |  | { | 
| 105 | 1 |  |  |  |  |  | begin = i; | 
| 106 | 4 | 50 |  |  |  |  | while(i < attr->value.length && mycore_utils_whithspace(attr->value.data[i], !=, &&)) {i++;} | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
| 107 |  |  |  |  |  |  |  | 
| 108 | 1 | 50 |  |  |  |  | if((i - begin) == value_len && (mycore_strncasecmp(value, &attr->value.data[begin], value_len) == 0)) { | 
|  |  | 50 |  |  |  |  |  | 
| 109 | 1 |  |  |  |  |  | return true; | 
| 110 |  |  |  |  |  |  | } | 
| 111 |  |  |  |  |  |  | /* skip all ws */ | 
| 112 | 0 | 0 |  |  |  |  | while(i < attr->value.length && mycore_utils_whithspace(attr->value.data[i], ==, ||)) {i++;} | 
|  |  | 0 |  |  |  |  |  | 
|  |  | 0 |  |  |  |  |  | 
|  |  | 0 |  |  |  |  |  | 
|  |  | 0 |  |  |  |  |  | 
|  |  | 0 |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | } | 
| 114 |  |  |  |  |  |  | } | 
| 115 |  |  |  |  |  |  | } | 
| 116 |  |  |  |  |  |  |  | 
| 117 | 72 |  |  |  |  |  | break; | 
| 118 |  |  |  |  |  |  | } | 
| 119 |  |  |  |  |  |  | } | 
| 120 |  |  |  |  |  |  |  | 
| 121 | 324 |  |  |  |  |  | attr = attr->next; | 
| 122 |  |  |  |  |  |  | } | 
| 123 |  |  |  |  |  |  |  | 
| 124 | 300 |  |  |  |  |  | return false; | 
| 125 |  |  |  |  |  |  | } | 
| 126 |  |  |  |  |  |  |  | 
| 127 | 0 |  |  |  |  |  | bool modest_finder_match_attribute_begin(myhtml_token_attr_t* attr, const char* key, size_t key_len, const char* value, size_t value_len, bool case_sensitive) | 
| 128 |  |  |  |  |  |  | { | 
| 129 | 0 | 0 |  |  |  |  | if(key == NULL || value == NULL) | 
|  |  | 0 |  |  |  |  |  | 
| 130 | 0 |  |  |  |  |  | return false; | 
| 131 |  |  |  |  |  |  |  | 
| 132 | 0 | 0 |  |  |  |  | while (attr) | 
| 133 |  |  |  |  |  |  | { | 
| 134 | 0 | 0 |  |  |  |  | if(attr->key.length == key_len) { | 
| 135 | 0 | 0 |  |  |  |  | if(mycore_strncasecmp(key, attr->key.data, key_len) == 0) | 
| 136 |  |  |  |  |  |  | { | 
| 137 | 0 | 0 |  |  |  |  | if(attr->value.length >= value_len) { | 
| 138 | 0 | 0 |  |  |  |  | if(case_sensitive) { | 
| 139 | 0 | 0 |  |  |  |  | if(mycore_strncmp(value, attr->value.data, value_len) == 0) | 
| 140 | 0 |  |  |  |  |  | return true; | 
| 141 |  |  |  |  |  |  | } | 
| 142 |  |  |  |  |  |  | else { | 
| 143 | 0 | 0 |  |  |  |  | if(mycore_strncasecmp(value, attr->value.data, value_len) == 0) | 
| 144 | 0 |  |  |  |  |  | return true; | 
| 145 |  |  |  |  |  |  | } | 
| 146 |  |  |  |  |  |  | } | 
| 147 |  |  |  |  |  |  |  | 
| 148 | 0 |  |  |  |  |  | break; | 
| 149 |  |  |  |  |  |  | } | 
| 150 |  |  |  |  |  |  | } | 
| 151 |  |  |  |  |  |  |  | 
| 152 | 0 |  |  |  |  |  | attr = attr->next; | 
| 153 |  |  |  |  |  |  | } | 
| 154 |  |  |  |  |  |  |  | 
| 155 | 0 |  |  |  |  |  | return false; | 
| 156 |  |  |  |  |  |  | } | 
| 157 |  |  |  |  |  |  |  | 
| 158 | 0 |  |  |  |  |  | bool modest_finder_match_attribute_end(myhtml_token_attr_t* attr, const char* key, size_t key_len, const char* value, size_t value_len, bool case_sensitive) | 
| 159 |  |  |  |  |  |  | { | 
| 160 | 0 | 0 |  |  |  |  | if(key == NULL || value == NULL) | 
|  |  | 0 |  |  |  |  |  | 
| 161 | 0 |  |  |  |  |  | return false; | 
| 162 |  |  |  |  |  |  |  | 
| 163 | 0 | 0 |  |  |  |  | while (attr) | 
| 164 |  |  |  |  |  |  | { | 
| 165 | 0 | 0 |  |  |  |  | if(attr->key.length == key_len) { | 
| 166 | 0 | 0 |  |  |  |  | if(mycore_strncasecmp(key, attr->key.data, key_len) == 0) | 
| 167 |  |  |  |  |  |  | { | 
| 168 | 0 | 0 |  |  |  |  | if(attr->value.length >= value_len) { | 
| 169 | 0 | 0 |  |  |  |  | if(case_sensitive) { | 
| 170 | 0 | 0 |  |  |  |  | if(mycore_strncmp(value, &attr->value.data[ (attr->value.length - value_len) ], value_len) == 0) | 
| 171 | 0 |  |  |  |  |  | return true; | 
| 172 |  |  |  |  |  |  | } | 
| 173 |  |  |  |  |  |  | else { | 
| 174 | 0 | 0 |  |  |  |  | if(mycore_strncasecmp(value, &attr->value.data[ (attr->value.length - value_len) ], value_len) == 0) | 
| 175 | 0 |  |  |  |  |  | return true; | 
| 176 |  |  |  |  |  |  | } | 
| 177 |  |  |  |  |  |  | } | 
| 178 |  |  |  |  |  |  |  | 
| 179 | 0 |  |  |  |  |  | break; | 
| 180 |  |  |  |  |  |  | } | 
| 181 |  |  |  |  |  |  | } | 
| 182 |  |  |  |  |  |  |  | 
| 183 | 0 |  |  |  |  |  | attr = attr->next; | 
| 184 |  |  |  |  |  |  | } | 
| 185 |  |  |  |  |  |  |  | 
| 186 | 0 |  |  |  |  |  | return false; | 
| 187 |  |  |  |  |  |  | } | 
| 188 |  |  |  |  |  |  |  | 
| 189 | 0 |  |  |  |  |  | bool modest_finder_match_attribute_sub(myhtml_token_attr_t* attr, const char* key, size_t key_len, const char* value, size_t value_len, bool case_sensitive) | 
| 190 |  |  |  |  |  |  | { | 
| 191 | 0 | 0 |  |  |  |  | if(key == NULL || value == NULL) | 
|  |  | 0 |  |  |  |  |  | 
| 192 | 0 |  |  |  |  |  | return false; | 
| 193 |  |  |  |  |  |  |  | 
| 194 | 0 | 0 |  |  |  |  | while (attr) | 
| 195 |  |  |  |  |  |  | { | 
| 196 | 0 | 0 |  |  |  |  | if(attr->key.length == key_len) { | 
| 197 | 0 | 0 |  |  |  |  | if(mycore_strncasecmp(key, attr->key.data, key_len) == 0) | 
| 198 |  |  |  |  |  |  | { | 
| 199 | 0 | 0 |  |  |  |  | if(attr->value.length >= value_len) { | 
| 200 | 0 |  |  |  |  |  | size_t i = 0; | 
| 201 |  |  |  |  |  |  |  | 
| 202 | 0 | 0 |  |  |  |  | if(case_sensitive) | 
| 203 |  |  |  |  |  |  | { | 
| 204 | 0 | 0 |  |  |  |  | while ((i + value_len) <= attr->value.length) | 
| 205 |  |  |  |  |  |  | { | 
| 206 | 0 | 0 |  |  |  |  | if(mycore_strncmp(value, &attr->value.data[i], value_len) == 0) | 
| 207 | 0 |  |  |  |  |  | return true; | 
| 208 |  |  |  |  |  |  |  | 
| 209 | 0 |  |  |  |  |  | i++; | 
| 210 |  |  |  |  |  |  | } | 
| 211 |  |  |  |  |  |  | } | 
| 212 |  |  |  |  |  |  | else { | 
| 213 | 0 | 0 |  |  |  |  | while ((i + value_len) <= attr->value.length) | 
| 214 |  |  |  |  |  |  | { | 
| 215 | 0 | 0 |  |  |  |  | if(mycore_strncasecmp(value, &attr->value.data[i], value_len) == 0) | 
| 216 | 0 |  |  |  |  |  | return true; | 
| 217 |  |  |  |  |  |  |  | 
| 218 | 0 |  |  |  |  |  | i++; | 
| 219 |  |  |  |  |  |  | } | 
| 220 |  |  |  |  |  |  | } | 
| 221 |  |  |  |  |  |  | } | 
| 222 |  |  |  |  |  |  |  | 
| 223 | 0 |  |  |  |  |  | break; | 
| 224 |  |  |  |  |  |  | } | 
| 225 |  |  |  |  |  |  | } | 
| 226 |  |  |  |  |  |  |  | 
| 227 | 0 |  |  |  |  |  | attr = attr->next; | 
| 228 |  |  |  |  |  |  | } | 
| 229 |  |  |  |  |  |  |  | 
| 230 | 0 |  |  |  |  |  | return false; | 
| 231 |  |  |  |  |  |  | } | 
| 232 |  |  |  |  |  |  |  | 
| 233 | 0 |  |  |  |  |  | bool modest_finder_match_attribute_hsp(myhtml_token_attr_t* attr, const char* key, size_t key_len, const char* value, size_t value_len, bool case_sensitive) | 
| 234 |  |  |  |  |  |  | { | 
| 235 | 0 | 0 |  |  |  |  | if(key == NULL || value == NULL) | 
|  |  | 0 |  |  |  |  |  | 
| 236 | 0 |  |  |  |  |  | return false; | 
| 237 |  |  |  |  |  |  |  | 
| 238 | 0 | 0 |  |  |  |  | while (attr) | 
| 239 |  |  |  |  |  |  | { | 
| 240 | 0 | 0 |  |  |  |  | if(attr->key.length == key_len) { | 
| 241 | 0 | 0 |  |  |  |  | if(mycore_strncasecmp(key, attr->key.data, key_len) == 0) | 
| 242 |  |  |  |  |  |  | { | 
| 243 | 0 | 0 |  |  |  |  | if(attr->value.length == value_len) { | 
| 244 | 0 | 0 |  |  |  |  | if(case_sensitive) { | 
| 245 | 0 | 0 |  |  |  |  | if(mycore_strncmp(value, attr->value.data, value_len) == 0) | 
| 246 | 0 |  |  |  |  |  | return true; | 
| 247 |  |  |  |  |  |  | } | 
| 248 |  |  |  |  |  |  | else { | 
| 249 | 0 | 0 |  |  |  |  | if(mycore_strncasecmp(value, attr->value.data, value_len) == 0) | 
| 250 | 0 |  |  |  |  |  | return true; | 
| 251 |  |  |  |  |  |  | } | 
| 252 |  |  |  |  |  |  | } | 
| 253 | 0 | 0 |  |  |  |  | else if(attr->value.length > value_len) { | 
| 254 | 0 | 0 |  |  |  |  | if(case_sensitive) { | 
| 255 | 0 | 0 |  |  |  |  | if(mycore_strncmp(value, attr->value.data, value_len) == 0) { | 
| 256 | 0 | 0 |  |  |  |  | if(attr->value.data[value_len] == '-') | 
| 257 | 0 |  |  |  |  |  | return true; | 
| 258 |  |  |  |  |  |  | } | 
| 259 |  |  |  |  |  |  | } | 
| 260 |  |  |  |  |  |  | else { | 
| 261 | 0 | 0 |  |  |  |  | if(mycore_strncasecmp(value, attr->value.data, value_len) == 0) { | 
| 262 | 0 | 0 |  |  |  |  | if(attr->value.data[value_len] == '-') | 
| 263 | 0 |  |  |  |  |  | return true; | 
| 264 |  |  |  |  |  |  | } | 
| 265 |  |  |  |  |  |  | } | 
| 266 |  |  |  |  |  |  | } | 
| 267 |  |  |  |  |  |  |  | 
| 268 | 0 |  |  |  |  |  | break; | 
| 269 |  |  |  |  |  |  | } | 
| 270 |  |  |  |  |  |  | } | 
| 271 |  |  |  |  |  |  |  | 
| 272 | 0 |  |  |  |  |  | attr = attr->next; | 
| 273 |  |  |  |  |  |  | } | 
| 274 |  |  |  |  |  |  |  | 
| 275 | 0 |  |  |  |  |  | return false; | 
| 276 |  |  |  |  |  |  | } | 
| 277 |  |  |  |  |  |  |  | 
| 278 |  |  |  |  |  |  |  |