|
Lines 48-55
Link Here
|
| 48 |
#define S_CTRL 4 /* control char started (^) */ |
48 |
#define S_CTRL 4 /* control char started (^) */ |
| 49 |
#define S_OCTAL2 5 /* octal digit 2 */ |
49 |
#define S_OCTAL2 5 /* octal digit 2 */ |
| 50 |
#define S_OCTAL3 6 /* octal digit 3 */ |
50 |
#define S_OCTAL3 6 /* octal digit 3 */ |
|
|
51 |
#define S_HEX2 7 /* hex digit 2 */ |
| 52 |
|
| 53 |
#define S_HTTP 0x080 /* %HEXHEX escape */ |
| 51 |
|
54 |
|
| 52 |
#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') |
55 |
#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') |
|
|
56 |
#define ishex(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '9' || ((u_char)(c)) >= 'a' && ((u_char)(c)) <= 'f') |
| 53 |
|
57 |
|
| 54 |
/* |
58 |
/* |
| 55 |
* unvis - decode characters previously encoded by vis |
59 |
* unvis - decode characters previously encoded by vis |
|
Lines 68-74
Link Here
|
| 68 |
return (*astate == S_GROUND ? UNVIS_NOCHAR : UNVIS_SYNBAD); |
72 |
return (*astate == S_GROUND ? UNVIS_NOCHAR : UNVIS_SYNBAD); |
| 69 |
} |
73 |
} |
| 70 |
|
74 |
|
| 71 |
switch (*astate) { |
75 |
switch (*astate & ~S_HTTP) { |
| 72 |
|
76 |
|
| 73 |
case S_GROUND: |
77 |
case S_GROUND: |
| 74 |
*cp = 0; |
78 |
*cp = 0; |
|
Lines 76-85
Link Here
|
| 76 |
*astate = S_START; |
80 |
*astate = S_START; |
| 77 |
return (0); |
81 |
return (0); |
| 78 |
} |
82 |
} |
|
|
83 |
if (flag & VIS_HTTPSTYLE && c == '%') { |
| 84 |
*astate = S_START | S_HTTP; |
| 85 |
return (0); |
| 86 |
} |
| 79 |
*cp = c; |
87 |
*cp = c; |
| 80 |
return (UNVIS_VALID); |
88 |
return (UNVIS_VALID); |
| 81 |
|
89 |
|
| 82 |
case S_START: |
90 |
case S_START: |
|
|
91 |
if (*astate & S_HTTP) { |
| 92 |
if (ishex(tolower(c))) { |
| 93 |
*cp = isdigit(c) ? (c - '0') : (tolower(c) - 'a'); |
| 94 |
*astate = S_HEX2; |
| 95 |
return (0); |
| 96 |
} |
| 97 |
} |
| 83 |
switch(c) { |
98 |
switch(c) { |
| 84 |
case '\\': |
99 |
case '\\': |
| 85 |
*cp = c; |
100 |
*cp = c; |
|
Lines 199-204
Link Here
|
| 199 |
*/ |
214 |
*/ |
| 200 |
return (UNVIS_VALIDPUSH); |
215 |
return (UNVIS_VALIDPUSH); |
| 201 |
|
216 |
|
|
|
217 |
case S_HEX2: /* second mandatory hex digit */ |
| 218 |
if (ishex(tolower(c))) { |
| 219 |
*cp = (isdigit(c) ? (*cp << 4) + (c - '0') : (*cp << 4) + (tolower(c) - 'a' + 10)); |
| 220 |
} |
| 221 |
*astate = S_GROUND; |
| 222 |
return (UNVIS_VALID); |
| 223 |
|
| 202 |
default: |
224 |
default: |
| 203 |
/* |
225 |
/* |
| 204 |
* decoder in unknown state - (probably uninitialized) |
226 |
* decoder in unknown state - (probably uninitialized) |
|
Lines 227-232
Link Here
|
| 227 |
while ( (c = *src++) ) { |
249 |
while ( (c = *src++) ) { |
| 228 |
again: |
250 |
again: |
| 229 |
switch (unvis(dst, c, &state, 0)) { |
251 |
switch (unvis(dst, c, &state, 0)) { |
|
|
252 |
case UNVIS_VALID: |
| 253 |
dst++; |
| 254 |
break; |
| 255 |
case UNVIS_VALIDPUSH: |
| 256 |
dst++; |
| 257 |
goto again; |
| 258 |
case 0: |
| 259 |
case UNVIS_NOCHAR: |
| 260 |
break; |
| 261 |
default: |
| 262 |
return (-1); |
| 263 |
} |
| 264 |
} |
| 265 |
if (unvis(dst, c, &state, UNVIS_END) == UNVIS_VALID) |
| 266 |
dst++; |
| 267 |
*dst = '\0'; |
| 268 |
return (dst - start); |
| 269 |
} |
| 270 |
|
| 271 |
int |
| 272 |
strunvisx(dst, src, flag) |
| 273 |
register char *dst; |
| 274 |
register const char *src; |
| 275 |
{ |
| 276 |
register char c; |
| 277 |
char *start = dst; |
| 278 |
int state = 0; |
| 279 |
|
| 280 |
while ( (c = *src++) ) { |
| 281 |
again: |
| 282 |
switch (unvis(dst, c, &state, flag)) { |
| 230 |
case UNVIS_VALID: |
283 |
case UNVIS_VALID: |
| 231 |
dst++; |
284 |
dst++; |
| 232 |
break; |
285 |
break; |