From: Fabian K. <fab...@us...> - 2013-11-24 14:24:20
|
Update of /cvsroot/ijbswa/current In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv15726 Modified Files: actions.c actions.h parsers.c project.h urlmatch.c Log Message: Introduce negative tag patterns NO-REQUEST-TAG and NO-RESPONSE-TAG They apply if no matching tag is found after parsing client or server headers. Index: project.h =================================================================== RCS file: /cvsroot/ijbswa/current/project.h,v retrieving revision 1.199 retrieving revision 1.200 diff -C2 -d -r1.199 -r1.200 *** project.h 24 Nov 2013 14:23:28 -0000 1.199 --- project.h 24 Nov 2013 14:24:18 -0000 1.200 *************** *** 394,397 **** --- 394,408 ---- #define ANCHOR_RIGHT 2 + /** Pattern spec bitmap: It's an URL pattern. */ + #define PATTERN_SPEC_URL_PATTERN 0x00000001UL + + /** Pattern spec bitmap: It's a TAG pattern. */ + #define PATTERN_SPEC_TAG_PATTERN 0x00000002UL + + /** Pattern spec bitmap: It's a NO-REQUEST-TAG pattern. */ + #define PATTERN_SPEC_NO_REQUEST_TAG_PATTERN 0x00000004UL + + /** Pattern spec bitmap: It's a NO-RESPONSE-TAG pattern. */ + #define PATTERN_SPEC_NO_RESPONSE_TAG_PATTERN 0x00000008UL /** Index: parsers.c =================================================================== RCS file: /cvsroot/ijbswa/current/parsers.c,v retrieving revision 1.279 retrieving revision 1.280 diff -C2 -d -r1.279 -r1.280 *** parsers.c 6 Aug 2013 12:59:34 -0000 1.279 --- parsers.c 24 Nov 2013 14:24:17 -0000 1.280 *************** *** 1098,1101 **** --- 1098,1102 ---- } + /********************************************************************* * *************** *** 1127,1134 **** --- 1128,1138 ---- jb_err err = JB_ERR_OK; + scan_headers(csp); + if (filter_server_headers) { v = server_patterns; f = add_server_headers; + check_negative_tag_patterns(csp, PATTERN_SPEC_NO_RESPONSE_TAG_PATTERN); } else *************** *** 1136,1143 **** v = client_patterns; f = add_client_headers; } - scan_headers(csp); - while ((err == JB_ERR_OK) && (v->str != NULL)) { --- 1140,1146 ---- v = client_patterns; f = add_client_headers; + check_negative_tag_patterns(csp, PATTERN_SPEC_NO_REQUEST_TAG_PATTERN); } while ((err == JB_ERR_OK) && (v->str != NULL)) { Index: urlmatch.c =================================================================== RCS file: /cvsroot/ijbswa/current/urlmatch.c,v retrieving revision 1.76 retrieving revision 1.77 diff -C2 -d -r1.76 -r1.77 *** urlmatch.c 24 Nov 2013 14:22:51 -0000 1.76 --- urlmatch.c 24 Nov 2013 14:24:18 -0000 1.77 *************** *** 1115,1126 **** url->spec = strdup_or_die(buf); ! /* Is it a tag pattern? */ if (0 == strncmpic(url->spec, "TAG:", 4)) { /* The pattern starts with the first character after "TAG:" */ const char *tag_pattern = buf + 4; return compile_pattern(tag_pattern, NO_ANCHORING, url, &url->pattern.tag_regex); } /* If it isn't a tag pattern it must be an URL pattern. */ return compile_url_pattern(url, buf); --- 1115,1144 ---- url->spec = strdup_or_die(buf); ! /* Is it a positive tag pattern? */ if (0 == strncmpic(url->spec, "TAG:", 4)) { /* The pattern starts with the first character after "TAG:" */ const char *tag_pattern = buf + 4; + url->flags |= PATTERN_SPEC_TAG_PATTERN; + return compile_pattern(tag_pattern, NO_ANCHORING, url, &url->pattern.tag_regex); + } + /* Is it a negative tag pattern? */ + if (0 == strncmpic(url->spec, "NO-REQUEST-TAG:", 15)) + { + /* The pattern starts with the first character after "NO-REQUEST-TAG:" */ + const char *tag_pattern = buf + 15; + url->flags |= PATTERN_SPEC_NO_REQUEST_TAG_PATTERN; + return compile_pattern(tag_pattern, NO_ANCHORING, url, &url->pattern.tag_regex); + } + if (0 == strncmpic(url->spec, "NO-RESPONSE-TAG:", 16)) + { + /* The pattern starts with the first character after "NO-RESPONSE-TAG:" */ + const char *tag_pattern = buf + 16; + url->flags |= PATTERN_SPEC_NO_RESPONSE_TAG_PATTERN; return compile_pattern(tag_pattern, NO_ANCHORING, url, &url->pattern.tag_regex); } + url->flags |= PATTERN_SPEC_URL_PATTERN; + /* If it isn't a tag pattern it must be an URL pattern. */ return compile_url_pattern(url, buf); *************** *** 1251,1257 **** const struct http_request *http) { ! if (pattern->pattern.tag_regex != NULL) { ! /* It's a tag pattern and shouldn't be matched against URLs */ return 0; } --- 1269,1275 ---- const struct http_request *http) { ! if (!(pattern->flags & PATTERN_SPEC_URL_PATTERN)) { ! /* It's not an URL pattern and thus shouldn't be matched against URLs */ return 0; } Index: actions.h =================================================================== RCS file: /cvsroot/ijbswa/current/actions.h,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** actions.h 24 Nov 2013 14:23:28 -0000 1.22 --- actions.h 24 Nov 2013 14:24:17 -0000 1.23 *************** *** 65,68 **** --- 65,69 ---- #endif extern int update_action_bits_for_tag(struct client_state *csp, const char *tag); + extern jb_err check_negative_tag_patterns(struct client_state *csp, unsigned int flag); extern jb_err copy_action (struct action_spec *dest, const struct action_spec *src); Index: actions.c =================================================================== RCS file: /cvsroot/ijbswa/current/actions.c,v retrieving revision 1.88 retrieving revision 1.89 diff -C2 -d -r1.88 -r1.89 *** actions.c 24 Nov 2013 14:22:51 -0000 1.88 --- actions.c 24 Nov 2013 14:24:17 -0000 1.89 *************** *** 811,816 **** for (b = b->next; NULL != b; b = b->next) { ! /* skip the URL patterns, */ ! if (NULL == b->url->pattern.tag_regex) { continue; --- 811,816 ---- for (b = b->next; NULL != b; b = b->next) { ! /* skip everything but TAG patterns, */ ! if (!(b->url->flags & PATTERN_SPEC_TAG_PATTERN)) { continue; *************** *** 838,841 **** --- 838,911 ---- /********************************************************************* * + * Function : check_negative_tag_patterns + * + * Description : Updates the action bits based on NO-*-TAG patterns. + * + * Parameters : + * 1 : csp = Current client state (buffers, headers, etc...) + * 2 : flag = The tag pattern type + * + * Returns : JB_ERR_OK in case off success, or + * JB_ERR_MEMORY on out-of-memory error. + * + *********************************************************************/ + jb_err check_negative_tag_patterns(struct client_state *csp, unsigned int flag) + { + struct list_entry *tag; + struct file_list *fl; + struct url_actions *b = NULL; + int i; + + for (i = 0; i < MAX_AF_FILES; i++) + { + fl = csp->actions_list[i]; + if ((fl == NULL) || ((b = fl->f) == NULL)) + { + continue; + } + for (b = b->next; NULL != b; b = b->next) + { + int tag_found = 0; + if (0 == (b->url->flags & flag)) + { + continue; + } + for (tag = csp->tags->first; NULL != tag; tag = tag->next) + { + if (0 == regexec(b->url->pattern.tag_regex, tag->str, 0, NULL, 0)) + { + /* + * The pattern matches at least one tag, thus the action + * section doesn't apply and we don't need to look at the + * other tags. + */ + tag_found = 1; + break; + } + } + if (!tag_found) + { + /* + * The pattern doesn't match any tags, + * thus the action section applies. + */ + if (merge_current_action(csp->action, b->action)) + { + log_error(LOG_LEVEL_ERROR, + "Out of memory while changing action bits"); + return JB_ERR_MEMORY; + } + log_error(LOG_LEVEL_HEADER, "Updated action bits based on: %s", + b->url->spec); + } + } + } + + return JB_ERR_OK; + } + + + /********************************************************************* + * * Function : free_current_action * |