Commit bccd447c authored by Joshua Bussdieker's avatar Joshua Bussdieker

Fix indentation style

parent 14343b22
...@@ -70,123 +70,123 @@ int enum_matchers(const char *matcher, int *type, const char **param, int *s) { ...@@ -70,123 +70,123 @@ int enum_matchers(const char *matcher, int *type, const char **param, int *s) {
} }
int enum_fields(const char *fv, const char **m, int *s) { int enum_fields(const char *fv, const char **m, int *s) {
const char *f, *b; const char *f, *b;
enum state { enum state {
start, start,
skip_space, skip_space,
scan, scan,
scan_quote, scan_quote,
scan_back, scan_back,
done, done,
end end
} cur_state = start; } cur_state = start;
do { do {
switch (cur_state) { switch (cur_state) {
case start: case start:
f = fv; f = fv;
cur_state = skip_space; cur_state = skip_space;
break; break;
case skip_space: case skip_space:
if (*f == '\0') if (*f == '\0')
cur_state = end; cur_state = end;
else if (*f == ' ' || *f == ',') else if (*f == ' ' || *f == ',')
f++; f++;
else if (*f == '"') { else if (*f == '"') {
b = f; b = f;
cur_state = scan_quote; cur_state = scan_quote;
} else { } else {
b = f; b = f;
cur_state = scan; cur_state = scan;
}
break;
case scan:
b++;
if (*b == '\0')
cur_state = scan_back;
else if (*b == '"')
cur_state = scan_quote;
else if (*b == ',')
cur_state = scan_back;
break;
case scan_quote:
b++;
if (*b == '\0')
cur_state = scan_back;
else if (*b == '\\' && b[1] != '\0')
b++;
else if (*b == '"')
cur_state = scan;
break;
case scan_back:
b--;
if (*b != ' ')
cur_state = done;
break;
case done:
*m = f;
*s = (int)(b-f)+1;
return b - fv + 1;
break;
} }
break; } while (cur_state != end);
case scan:
b++;
if (*b == '\0')
cur_state = scan_back;
else if (*b == '"')
cur_state = scan_quote;
else if (*b == ',')
cur_state = scan_back;
break;
case scan_quote:
b++;
if (*b == '\0')
cur_state = scan_back;
else if (*b == '\\' && b[1] != '\0')
b++;
else if (*b == '"')
cur_state = scan;
break;
case scan_back:
b--;
if (*b != ' ')
cur_state = done;
break;
case done:
*m = f;
*s = (int)(b-f)+1;
return b - fv + 1;
break;
}
} while (cur_state != end);
return 0; return 0;
} }
int cmp_func(const char *str1, const char *str2, int size, int case_sensitive) { int cmp_func(const char *str1, const char *str2, int size, int case_sensitive) {
if (case_sensitive == 1) if (case_sensitive == 1)
return strncmp(str1, str2, size); return strncmp(str1, str2, size);
else else
return strncasecmp(str1, str2, size); return strncasecmp(str1, str2, size);
} }
int word_matcher(const char *p, const char *fv, int ps, int case_sensitive) { int word_matcher(const char *p, const char *fv, int ps, int case_sensitive) {
int read, size, offset = 0; int read, size, offset = 0;
const char *match; const char *match;
while (read = enum_fields(fv + offset, &match, &size)) { while (read = enum_fields(fv + offset, &match, &size)) {
if (ps == size) { if (ps == size) {
if (cmp_func(match, p, size, case_sensitive) == 0) { if (cmp_func(match, p, size, case_sensitive) == 0) {
return 1; return 1;
} }
}
offset += read;
} }
offset += read; return 0;
}
return 0;
} }
int substring_matcher(const char *p, const char *fv, int ps, int case_sensitive) { int substring_matcher(const char *p, const char *fv, int ps, int case_sensitive) {
int read, size, offset = 0; int read, size, offset = 0;
const char *match; const char *match;
while (read = enum_fields(fv + offset, &match, &size)) { while (read = enum_fields(fv + offset, &match, &size)) {
if (strlen(p) <= size) { if (strlen(p) <= size) {
const char *s; const char *s;
for (s = match; s <= match + size - ps; s++) { for (s = match; s <= match + size - ps; s++) {
if (cmp_func(s, p, ps, case_sensitive) == 0) { if (cmp_func(s, p, ps, case_sensitive) == 0) {
return 1; return 1;
}
}
} }
} offset += read;
} }
offset += read; return 0;
}
return 0;
} }
int beginning_substring_matcher(const char *p, const char *fv, int ps, int case_sensitive) { int beginning_substring_matcher(const char *p, const char *fv, int ps, int case_sensitive) {
int read, size, offset = 0; int read, size, offset = 0;
const char *match; const char *match;
while (read = enum_fields(fv + offset, &match, &size)) { while (read = enum_fields(fv + offset, &match, &size)) {
if (ps <= size) { if (ps <= size) {
if (cmp_func(match, p, ps, case_sensitive) == 0) { if (cmp_func(match, p, ps, case_sensitive) == 0) {
return 1; return 1;
} }
}
offset += read;
} }
offset += read; return 0;
}
return 0;
} }
/* /*
...@@ -256,18 +256,18 @@ KEY_Create(struct busyobj *bo, struct vsb **psb) ...@@ -256,18 +256,18 @@ KEY_Create(struct busyobj *bo, struct vsb **psb)
const char *match; const char *match;
int size; int size;
while (read = enum_matchers(q, &type, &match, &size)) { while (read = enum_matchers(q, &type, &match, &size)) {
if (read < 0) { if (read < 0) {
VSLb(bo->vsl, SLT_Error, "Malformed Key header modifier"); VSLb(bo->vsl, SLT_Error, "Malformed Key header modifier");
error = 1; error = 1;
break; break;
} else { } else {
VSB_printf(sbm, "%c%.*s%c", type, size, match, 0); VSB_printf(sbm, "%c%.*s%c", type, size, match, 0);
q += read; q += read;
} }
} }
if (error == 1) if (error == 1)
break; break;
AZ(VSB_finish(sbm)); AZ(VSB_finish(sbm));
l = VSB_len(sbm); l = VSB_len(sbm);
...@@ -329,9 +329,9 @@ KEY_Create(struct busyobj *bo, struct vsb **psb) ...@@ -329,9 +329,9 @@ KEY_Create(struct busyobj *bo, struct vsb **psb)
AZ(VSB_finish(sb)); AZ(VSB_finish(sb));
if (KEY_Match(bo->bereq, VSB_data(sb)) == 0) { if (KEY_Match(bo->bereq, VSB_data(sb)) == 0) {
VSLb(bo->vsl, SLT_Error, "Cache key doesn't match request"); VSLb(bo->vsl, SLT_Error, "Cache key doesn't match request");
VSB_delete(sb); VSB_delete(sb);
return -1; return -1;
} }
*psb = sb; *psb = sb;
...@@ -366,26 +366,26 @@ KEY_Match(struct http *http, const uint8_t *key) ...@@ -366,26 +366,26 @@ KEY_Match(struct http *http, const uint8_t *key)
i = http_GetHdr(http, (const char*)(key+3), &h); i = http_GetHdr(http, (const char*)(key+3), &h);
if (l == 0xFFFF) { if (l == 0xFFFF) {
if (i != 0) if (i != 0)
result = 0; result = 0;
} else { } else {
const char *value = key + 4 + key[3] + 1; const char *value = key + 4 + key[3] + 1;
if (i == 0) {
result = 0;
} else {
AZ(vct_issp(*h));
/* Trim trailing space */
e = strchr(h, '\0');
while (e > h && vct_issp(e[-1]))
e--;
if (l != (int)(e - h)) if (i == 0) {
result = 0;
else
if (memcmp(h, value, l) != 0)
result = 0; result = 0;
} } else {
AZ(vct_issp(*h));
/* Trim trailing space */
e = strchr(h, '\0');
while (e > h && vct_issp(e[-1]))
e--;
if (l != (int)(e - h))
result = 0;
else
if (memcmp(h, value, l) != 0)
result = 0;
}
} }
// Matcher match // Matcher match
...@@ -399,36 +399,36 @@ KEY_Match(struct http *http, const uint8_t *key) ...@@ -399,36 +399,36 @@ KEY_Match(struct http *http, const uint8_t *key)
// TODO: Perhaps not matcher should allow this // TODO: Perhaps not matcher should allow this
if (i == 0) if (i == 0)
return 0; return 0;
const char *matcher = key + 4 + key[3] + 1; const char *matcher = key + 4 + key[3] + 1;
while (*matcher != 0 && *matcher != -1) { while (*matcher != 0 && *matcher != -1) {
char *m = matcher + 1; char *m = matcher + 1;
switch (matcher[0]) { switch (matcher[0]) {
case M_WORD: case M_WORD:
if (!word_matcher(m, h, strlen(m), case_flag) ^ not_flag) if (!word_matcher(m, h, strlen(m), case_flag) ^ not_flag)
result = 0; result = 0;
break; break;
case M_SUBSTRING: case M_SUBSTRING:
if (!substring_matcher(m, h, strlen(m), case_flag) ^ not_flag) if (!substring_matcher(m, h, strlen(m), case_flag) ^ not_flag)
result = 0; result = 0;
break; break;
case M_BEGINNING: case M_BEGINNING:
if (!beginning_substring_matcher(m, h, strlen(m), case_flag) ^ not_flag) if (!beginning_substring_matcher(m, h, strlen(m), case_flag) ^ not_flag)
result = 0; result = 0;
break; break;
case M_CASE: case M_CASE:
case_flag = 1; case_flag = 1;
break; break;
case M_NOT: case M_NOT:
not_flag = 1; not_flag = 1;
break; break;
default: default:
result = 0; result = 0;
break; break;
} }
matcher += strlen(m) + 2; matcher += strlen(m) + 2;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment