コード例 #1
0
ファイル: px_utils.c プロジェクト: PerimeterX/mod_perimeterx
// Functions escape_urlencoded & pescape_urlencoded were copied from APR v1.6
// http://svn.apache.org/repos/asf/apr/apr/branches/1.6.x/include/apr_escape.h
static int escape_urlencoded(char *escaped, const char *str, apr_size_t *len) {
    apr_size_t size = 1;
    int found = 0;
    const unsigned char *s = (const unsigned char *) str;
    unsigned char *d = (unsigned char *) escaped;
    unsigned c;

    if (s) {
        if (d) {
            while ((c = *s)) {
                if (TEST_CHAR(c, T_ESCAPE_URLENCODED)) {
                    d = c2x(c, '%', d);
                    size += 2;
                    found = 1;
                }
                else if (c == ' ') {
                    *d++ = '+';
                    found = 1;
                }
                else {
                    *d++ = c;
                }
                ++s;
                size++;
            }
            *d = '\0';
        }
        else {
            while ((c = *s)) {
                if (TEST_CHAR(c, T_ESCAPE_URLENCODED)) {
                    size += 2;
                    found = 1;
                }
                else if (c == ' ') {
                    found = 1;
                }
                ++s;
                size++;
            }
        }
    }

    if (len) {
        *len = size;
    }
    if (!found) {
        return 1;
    }

    return 0;
}
コード例 #2
0
ファイル: session.c プロジェクト: azenk/mod_auth_openidc
AP_DECLARE(char *) ap_escape_urlencoded_buffer(char *copy, const char *buffer) {
	const unsigned char *s = (const unsigned char *) buffer;
	unsigned char *d = (unsigned char *) copy;
	unsigned c;

	while ((c = *s)) {
		if (TEST_CHAR(c, T_ESCAPE_URLENCODED)) {
			d = c2x(c, '%', d);
		} else if (c == ' ') {
			*d++ = '+';
		} else {
			*d++ = c;
		}
		++s;
	}
	*d = '\0';
	return copy;
}