URL percent encoding
| 1284 | |
| 1285 | // URL percent encoding |
| 1286 | TSReturnCode |
| 1287 | TSStringPercentEncode(const char *str, int str_len, char *dst, size_t dst_size, size_t *length, const unsigned char *map) |
| 1288 | { |
| 1289 | sdk_assert(sdk_sanity_check_null_ptr((void *)str) == TS_SUCCESS); |
| 1290 | sdk_assert(sdk_sanity_check_null_ptr((void *)dst) == TS_SUCCESS); |
| 1291 | |
| 1292 | int new_len; // Unfortunately, a lot of the core uses "int" for length's internally... |
| 1293 | |
| 1294 | if (str_len < 0) { |
| 1295 | str_len = strlen(str); |
| 1296 | } |
| 1297 | |
| 1298 | sdk_assert(str_len < static_cast<int>(dst_size)); |
| 1299 | |
| 1300 | // TODO: Perhaps we should make escapify_url() deal with const properly... |
| 1301 | // You would think making escapify_url const correct for the source argument would be easy, but in the case where |
| 1302 | // No escaping is needed, the source argument is returned. If there is a destination argument, the source is copied over |
| 1303 | // However, if there is no destination argument, none is allocated. I don't understand the full possibility of calling cases. |
| 1304 | // It seems like we might want to review how this is being called and perhaps create a number of smaller accessor methods that |
| 1305 | // can be set up correctly. |
| 1306 | if (nullptr == Encoding::pure_escapify_url(nullptr, const_cast<char *>(str), str_len, &new_len, dst, dst_size, map)) { |
| 1307 | if (length) { |
| 1308 | *length = 0; |
| 1309 | } |
| 1310 | return TS_ERROR; |
| 1311 | } |
| 1312 | |
| 1313 | if (length) { |
| 1314 | *length = new_len; |
| 1315 | } |
| 1316 | |
| 1317 | return TS_SUCCESS; |
| 1318 | } |
| 1319 | |
| 1320 | TSReturnCode |
| 1321 | TSStringPercentDecode(const char *str, size_t str_len, char *dst, size_t dst_size, size_t *length) |