| 66 | */ |
| 67 | |
| 68 | char * /* O - Destination string */ |
| 69 | cgiFormEncode(char *dst, /* I - Destination string */ |
| 70 | const char *src, /* I - Source string */ |
| 71 | size_t dstsize) /* I - Size of destination string */ |
| 72 | { |
| 73 | char *dstptr, /* Pointer into destination */ |
| 74 | *dstend; /* End of destination */ |
| 75 | static const char *hex = /* Hexadecimal characters */ |
| 76 | "0123456789ABCDEF"; |
| 77 | |
| 78 | |
| 79 | /* |
| 80 | * Mark the end of the string... |
| 81 | */ |
| 82 | |
| 83 | dstend = dst + dstsize - 1; |
| 84 | |
| 85 | /* |
| 86 | * Loop through the source string and copy... |
| 87 | */ |
| 88 | |
| 89 | for (dstptr = dst; *src && dstptr < dstend;) |
| 90 | { |
| 91 | switch (*src) |
| 92 | { |
| 93 | case ' ' : |
| 94 | /* |
| 95 | * Encode spaces with a "+"... |
| 96 | */ |
| 97 | |
| 98 | *dstptr++ = '+'; |
| 99 | src ++; |
| 100 | break; |
| 101 | |
| 102 | case '&' : |
| 103 | case '%' : |
| 104 | case '+' : |
| 105 | /* |
| 106 | * Encode special characters with %XX escape... |
| 107 | */ |
| 108 | |
| 109 | if (dstptr < (dstend - 2)) |
| 110 | { |
| 111 | *dstptr++ = '%'; |
| 112 | *dstptr++ = hex[(*src & 255) >> 4]; |
| 113 | *dstptr++ = hex[*src & 15]; |
| 114 | src ++; |
| 115 | } |
| 116 | break; |
| 117 | |
| 118 | default : |
| 119 | /* |
| 120 | * Copy other characters literally... |
| 121 | */ |
| 122 | |
| 123 | *dstptr++ = *src++; |
| 124 | break; |
| 125 | } |
no outgoing calls
no test coverage detected