... | ... |
@@ -50,15 +50,20 @@ |
50 | 50 |
#define AC_SPECIAL_ALT_STR 2 |
51 | 51 |
#define AC_SPECIAL_LINE_MARKER 3 |
52 | 52 |
#define AC_SPECIAL_BOUNDARY 4 |
53 |
- |
|
54 |
-#define AC_BOUNDARY_LEFT 1 |
|
55 |
-#define AC_BOUNDARY_LEFT_NEGATIVE 2 |
|
56 |
-#define AC_BOUNDARY_RIGHT 4 |
|
57 |
-#define AC_BOUNDARY_RIGHT_NEGATIVE 8 |
|
58 |
-#define AC_LINE_MARKER_LEFT 16 |
|
59 |
-#define AC_LINE_MARKER_LEFT_NEGATIVE 32 |
|
60 |
-#define AC_LINE_MARKER_RIGHT 64 |
|
61 |
-#define AC_LINE_MARKER_RIGHT_NEGATIVE 128 |
|
53 |
+#define AC_SPECIAL_WORD_MARKER 5 |
|
54 |
+ |
|
55 |
+#define AC_BOUNDARY_LEFT 0x0001 |
|
56 |
+#define AC_BOUNDARY_LEFT_NEGATIVE 0x0002 |
|
57 |
+#define AC_BOUNDARY_RIGHT 0x0004 |
|
58 |
+#define AC_BOUNDARY_RIGHT_NEGATIVE 0x0008 |
|
59 |
+#define AC_LINE_MARKER_LEFT 0x0010 |
|
60 |
+#define AC_LINE_MARKER_LEFT_NEGATIVE 0x0020 |
|
61 |
+#define AC_LINE_MARKER_RIGHT 0x0040 |
|
62 |
+#define AC_LINE_MARKER_RIGHT_NEGATIVE 0x0080 |
|
63 |
+#define AC_WORD_MARKER_LEFT 0x0100 |
|
64 |
+#define AC_WORD_MARKER_LEFT_NEGATIVE 0x0200 |
|
65 |
+#define AC_WORD_MARKER_RIGHT 0x0400 |
|
66 |
+#define AC_WORD_MARKER_RIGHT_NEGATIVE 0x0800 |
|
62 | 67 |
|
63 | 68 |
static char boundary[256] = { |
64 | 69 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 2, 0, 0, |
... | ... |
@@ -890,6 +895,11 @@ int cli_ac_chklsig(const char *expr, const char *end, uint32_t *lsigcnt, unsigne |
890 | 890 |
match = !special->negative; \ |
891 | 891 |
break; \ |
892 | 892 |
\ |
893 |
+ case AC_SPECIAL_WORD_MARKER: \ |
|
894 |
+ if(!isalnum(b)) \ |
|
895 |
+ match = !special->negative; \ |
|
896 |
+ break; \ |
|
897 |
+ \ |
|
893 | 898 |
default: \ |
894 | 899 |
cli_errmsg("ac_findmatch: Unknown special\n"); \ |
895 | 900 |
match = 0; \ |
... | ... |
@@ -970,6 +980,24 @@ inline static int ac_findmatch(const unsigned char *buffer, uint32_t offset, uin |
970 | 970 |
return 0; |
971 | 971 |
} |
972 | 972 |
|
973 |
+ if(pattern->boundary & AC_WORD_MARKER_LEFT) { |
|
974 |
+ match = !!(pattern->boundary & AC_WORD_MARKER_LEFT_NEGATIVE); |
|
975 |
+ if(!fileoffset || (offset && !isalnum(buffer[offset - 1]))) |
|
976 |
+ match = !match; |
|
977 |
+ |
|
978 |
+ if(!match) |
|
979 |
+ return 0; |
|
980 |
+ } |
|
981 |
+ |
|
982 |
+ if(pattern->boundary & AC_WORD_MARKER_RIGHT) { |
|
983 |
+ match = !!(pattern->boundary & AC_WORD_MARKER_RIGHT_NEGATIVE); |
|
984 |
+ if((length <= SCANBUFF) && (bp == length || !isalnum(buffer[offset - 1]))) |
|
985 |
+ match = !match; |
|
986 |
+ |
|
987 |
+ if(!match) |
|
988 |
+ return 0; |
|
989 |
+ } |
|
990 |
+ |
|
973 | 991 |
if(!(pattern->ch[1] & CLI_MATCH_IGNORE)) { |
974 | 992 |
bp += pattern->ch_mindist[1]; |
975 | 993 |
|
... | ... |
@@ -1836,6 +1864,20 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex |
1836 | 1836 |
mpool_free(root->mempool, newspecial); |
1837 | 1837 |
continue; |
1838 | 1838 |
} |
1839 |
+ } else if(!strcmp(pt, "W")) { |
|
1840 |
+ if(!*start) { |
|
1841 |
+ new->boundary |= AC_WORD_MARKER_RIGHT; |
|
1842 |
+ if(newspecial->negative) |
|
1843 |
+ new->boundary |= AC_WORD_MARKER_RIGHT_NEGATIVE; |
|
1844 |
+ mpool_free(root->mempool, newspecial); |
|
1845 |
+ continue; |
|
1846 |
+ } else if(pt - 1 == hexcpy) { |
|
1847 |
+ new->boundary |= AC_WORD_MARKER_LEFT; |
|
1848 |
+ if(newspecial->negative) |
|
1849 |
+ new->boundary |= AC_WORD_MARKER_LEFT_NEGATIVE; |
|
1850 |
+ mpool_free(root->mempool, newspecial); |
|
1851 |
+ continue; |
|
1852 |
+ } |
|
1839 | 1853 |
} |
1840 | 1854 |
cli_strlcat(hexnew, "()", hexnewsz); |
1841 | 1855 |
new->special++; |
... | ... |
@@ -1854,10 +1896,8 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex |
1854 | 1854 |
newspecial->type = AC_SPECIAL_BOUNDARY; |
1855 | 1855 |
} else if(!strcmp(pt, "L")) { |
1856 | 1856 |
newspecial->type = AC_SPECIAL_LINE_MARKER; |
1857 |
- /* |
|
1858 |
- } else if(strcmp(pt, "W")) { |
|
1859 |
- newspecial->type = AC_SPECIAL_WHITE; |
|
1860 |
- */ |
|
1857 |
+ } else if(!strcmp(pt, "W")) { |
|
1858 |
+ newspecial->type = AC_SPECIAL_WORD_MARKER; |
|
1861 | 1859 |
} else { |
1862 | 1860 |
newspecial->num = 1; |
1863 | 1861 |
for(i = 0; i < strlen(pt); i++) |