ESAPI-C 1.0
The OWASP Enterprise Security API for C

windows_codec.c

Go to the documentation of this file.
00001 
00008 #include <stdlib.h>
00009 #include <string.h>
00010 
00011 #include "codec.h"
00012 #include "windows_codec.h"
00013 
00014 char *windows_codec_name = "Windows";
00015 
00022 char *encode_windows_char(char *tokenbuff, char ch) {
00023 
00024         // FIXME: Pass in a list of characters that should not be encoded
00025         const char *immune = "";
00026 
00027         // check for immune characters
00028         if (strchr(immune, ch)) {
00029                 tokenbuff[1] = ch;
00030                 tokenbuff[1] = '\0';
00031         } else {
00032                 // check for alphanumeric characters
00033                 char *hex = nonatohex(ch);
00034                 if (hex == NULL) {
00035                         tokenbuff[1] = ch;
00036                         tokenbuff[1] = '\0';
00037                 } else {
00038                         tokenbuff[0] = '^';
00039                         tokenbuff[1] = '\0';
00040                 }
00041         }
00042 
00043         return tokenbuff;
00044 }
00045 
00046 /*
00047  * Returns the decoded version of the character starting at index, or
00048  * -1 if no decoding is possible.
00049  *
00050  * Formats all are legal both upper/lower case:
00051  *   \x - all special characters
00052  *
00053  */
00054 char decode_windows_char(const char *input, int *index, char *pushback) {
00055         //input.mark();
00056         char temp = *pushback;
00057         char mark = *index;
00058         char first = next(input, index, pushback);
00059         if (first == -1) {
00060                 //input.reset();
00061                 *pushback = temp;
00062                 *index = mark;
00063                 return -1;
00064         }
00065 
00066         // if this is not an encoded character, return -1
00067         if (first != '^') {
00068                 //input.reset();
00069                 *pushback = temp;
00070                 *index = mark;
00071                 return -1;
00072         }
00073 
00074         char second = next(input, index, pushback);
00075         return second;
00076 }
 All Data Structures Files Functions Variables Typedefs Defines