apr_escape.h (302408) | apr_escape.h (362181) |
---|---|
1/* Licensed to the Apache Software Foundation (ASF) under one or more 2 * contributor license agreements. See the NOTICE file distributed with 3 * this work for additional information regarding copyright ownership. 4 * The ASF licenses this file to You under the Apache License, Version 2.0 5 * (the "License"); you may not use this file except in compliance with 6 * the License. You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 --- 19 unchanged lines hidden (view full) --- 28/** 29 * @defgroup APR_Util_Escaping Escape functions 30 * @ingroup APR 31 * @{ 32 */ 33 34/* Simple escape/unescape functions. 35 * | 1/* Licensed to the Apache Software Foundation (ASF) under one or more 2 * contributor license agreements. See the NOTICE file distributed with 3 * this work for additional information regarding copyright ownership. 4 * The ASF licenses this file to You under the Apache License, Version 2.0 5 * (the "License"); you may not use this file except in compliance with 6 * the License. You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 --- 19 unchanged lines hidden (view full) --- 28/** 29 * @defgroup APR_Util_Escaping Escape functions 30 * @ingroup APR 31 * @{ 32 */ 33 34/* Simple escape/unescape functions. 35 * |
36 * The design goal of these functions are: 37 * 38 * - Avoid unnecessary work. 39 * 40 * In most cases the strings passed in do not need to be escaped at all. In 41 * these cases the original string will be returned. 42 * 43 * - Lowest possible memory footprint. 44 * 45 * The amount of memory allocated for a given encoding is calculated based 46 * on the exact amount of memory needed, and not the theoretical worst case 47 * scenario. 48 * |
|
36 */ 37 38/** 39 * When passing a string to one of the escape functions, this value can be 40 * passed to indicate a string-valued key, and have the length computed 41 * automatically. 42 */ | 49 */ 50 51/** 52 * When passing a string to one of the escape functions, this value can be 53 * passed to indicate a string-valued key, and have the length computed 54 * automatically. 55 */ |
43#define APR_ESCAPE_STRING (-1) | 56#define APR_ESCAPE_STRING (-1) |
44 45/** | 57 58/** |
59 * Apply LDAP distinguished name escaping as per RFC4514. 60 */ 61#define APR_ESCAPE_LDAP_DN (0x01) 62 63/** 64 * Apply LDAP filter escaping as per RFC4515. 65 */ 66#define APR_ESCAPE_LDAP_FILTER (0x02) 67 68/** 69 * Apply both RFC4514 and RFC4515 LDAP escaping. 70 */ 71#define APR_ESCAPE_LDAP_ALL (0x03) 72 73/** |
|
46 * Perform shell escaping on the provided string. 47 * 48 * Shell escaping causes characters to be prefixed with a '\' character. 49 * @param escaped Optional buffer to write the encoded string, can be 50 * NULL 51 * @param str The original string 52 * @param slen The length of the original string, or APR_ESCAPE_STRING 53 * @param len If present, returns the length of the string --- 149 unchanged lines hidden (view full) --- 203 * @return A string allocated from the pool on success, the original string 204 * if no characters are encoded or if the string was NULL. 205 */ 206APR_DECLARE(const char *) apr_pescape_urlencoded(apr_pool_t *p, 207 const char *str) __attribute__((nonnull(1))); 208 209/** 210 * Apply entity encoding to a string. Characters are replaced as follows: | 74 * Perform shell escaping on the provided string. 75 * 76 * Shell escaping causes characters to be prefixed with a '\' character. 77 * @param escaped Optional buffer to write the encoded string, can be 78 * NULL 79 * @param str The original string 80 * @param slen The length of the original string, or APR_ESCAPE_STRING 81 * @param len If present, returns the length of the string --- 149 unchanged lines hidden (view full) --- 231 * @return A string allocated from the pool on success, the original string 232 * if no characters are encoded or if the string was NULL. 233 */ 234APR_DECLARE(const char *) apr_pescape_urlencoded(apr_pool_t *p, 235 const char *str) __attribute__((nonnull(1))); 236 237/** 238 * Apply entity encoding to a string. Characters are replaced as follows: |
211 * '<' becomes '<', '>' becomes '>', '&' becomes '&', the 212 * double quote becomes '"" and the single quote becomes '''. | 239 * '<' becomes '\<', '>' becomes '\>', '&' becomes '\&', the 240 * double quote becomes '\"" and the single quote becomes '\''. |
213 * 214 * If toasc is not zero, any non ascii character will be encoded as 215 * '%\#ddd;', where ddd is the decimal code of the character. 216 * @param escaped Optional buffer to write the encoded string, can be 217 * NULL 218 * @param str The original string 219 * @param slen The length of the original string, or APR_ESCAPE_STRING 220 * @param toasc If non zero, encode non ascii characters 221 * @param len If present, returns the length of the string 222 * @return APR_SUCCESS, or APR_NOTFOUND if no changes to the string were 223 * detected or the string was NULL 224 */ 225APR_DECLARE(apr_status_t) apr_escape_entity(char *escaped, const char *str, 226 apr_ssize_t slen, int toasc, apr_size_t *len); 227 228/** 229 * Apply entity encoding to a string, returning the result from a pool. | 241 * 242 * If toasc is not zero, any non ascii character will be encoded as 243 * '%\#ddd;', where ddd is the decimal code of the character. 244 * @param escaped Optional buffer to write the encoded string, can be 245 * NULL 246 * @param str The original string 247 * @param slen The length of the original string, or APR_ESCAPE_STRING 248 * @param toasc If non zero, encode non ascii characters 249 * @param len If present, returns the length of the string 250 * @return APR_SUCCESS, or APR_NOTFOUND if no changes to the string were 251 * detected or the string was NULL 252 */ 253APR_DECLARE(apr_status_t) apr_escape_entity(char *escaped, const char *str, 254 apr_ssize_t slen, int toasc, apr_size_t *len); 255 256/** 257 * Apply entity encoding to a string, returning the result from a pool. |
230 * Characters are replaced as follows: '<' becomes '<', '>' becomes 231 * '>', '&' becomes '&', the double quote becomes '"" and the 232 * single quote becomes '''. | 258 * Characters are replaced as follows: '<' becomes '\<', '>' becomes 259 * '\>', '&' becomes '\&', the double quote becomes '\"" and the 260 * single quote becomes '\''. |
233 * @param p Pool to allocate from 234 * @param str The original string 235 * @param toasc If non zero, encode non ascii characters 236 * @return A string allocated from the pool on success, the original string 237 * if no characters are encoded or the string is NULL. 238 */ 239APR_DECLARE(const char *) apr_pescape_entity(apr_pool_t *p, const char *str, 240 int toasc) __attribute__((nonnull(1))); --- 120 unchanged lines hidden (view full) --- 361 * @param colon If not zero, ignore colon characters between hex digits. 362 * @param len If present, returns the length of the final buffer 363 * @return A buffer allocated from the pool on success, or NULL if src was 364 * NULL, or a bad character was present. 365 */ 366APR_DECLARE(const void *) apr_punescape_hex(apr_pool_t *p, const char *str, 367 int colon, apr_size_t *len); 368 | 261 * @param p Pool to allocate from 262 * @param str The original string 263 * @param toasc If non zero, encode non ascii characters 264 * @return A string allocated from the pool on success, the original string 265 * if no characters are encoded or the string is NULL. 266 */ 267APR_DECLARE(const char *) apr_pescape_entity(apr_pool_t *p, const char *str, 268 int toasc) __attribute__((nonnull(1))); --- 120 unchanged lines hidden (view full) --- 389 * @param colon If not zero, ignore colon characters between hex digits. 390 * @param len If present, returns the length of the final buffer 391 * @return A buffer allocated from the pool on success, or NULL if src was 392 * NULL, or a bad character was present. 393 */ 394APR_DECLARE(const void *) apr_punescape_hex(apr_pool_t *p, const char *str, 395 int colon, apr_size_t *len); 396 |
397/** 398 * Apply LDAP escaping to binary data. Characters from RFC4514 and RFC4515 399 * are escaped with their hex equivalents. 400 * @param dest The destination buffer, can be NULL 401 * @param src The original buffer 402 * @param srclen The length of the original buffer 403 * @param flags APR_ESCAPE_LDAP_DN for RFC4514, APR_ESCAPE_LDAP_FILTER for 404 * RFC4515, APR_ESCAPE_LDAP_ALL for both 405 * @param len If present, returns the length of the string 406 * @return APR_SUCCESS, or APR_NOTFOUND if the string was NULL 407 */ 408APR_DECLARE(apr_status_t) apr_escape_ldap(char *dest, const void *src, 409 apr_ssize_t srclen, int flags, apr_size_t *len); 410 411/** 412 * Apply LDAP escaping to binary data, and return the results from a 413 * pool. Characters from RFC4514 and RFC4515 are escaped with their hex 414 * equivalents. 415 * @param p Pool to allocate from 416 * @param src The original buffer 417 * @param slen The length of the original buffer 418 * @param flags APR_ESCAPE_LDAP_DN for RFC4514, APR_ESCAPE_LDAP_FILTER for 419 * RFC4515, APR_ESCAPE_LDAP_ALL for both 420 * @return A zero padded buffer allocated from the pool on success, or 421 * NULL if src was NULL. 422 */ 423APR_DECLARE(const char *) apr_pescape_ldap(apr_pool_t *p, const void *src, 424 apr_ssize_t slen, int flags) __attribute__((nonnull(1))); 425 |
|
369/** @} */ 370#ifdef __cplusplus 371} 372#endif 373 374#endif /* !APR_ESCAPE_H */ | 426/** @} */ 427#ifdef __cplusplus 428} 429#endif 430 431#endif /* !APR_ESCAPE_H */ |