MCPcopy Create free account
hub / github.com/acl-dev/acl / acl_url_encode

Function acl_url_encode

lib_acl/src/code/acl_urlcode.c:17–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15static unsigned char enc_tab[] = "0123456789ABCDEF";
16
17char *acl_url_encode(const char *str, ACL_DBUF_POOL *dbuf)
18{
19 int i, j, len, tmp_len;
20 unsigned char *tmp;
21
22 len = (int) strlen(str);
23 tmp_len = len;
24
25 if (dbuf != NULL)
26 tmp = (unsigned char*) acl_dbuf_pool_alloc(dbuf, len + 1);
27 else
28 tmp = (unsigned char*) acl_mymalloc(len + 1);
29
30 for (i = 0, j = 0; i < len; i++, j++) {
31 tmp[j] = (unsigned char) str[i];
32 /* if (tmp[j] == ' ')
33 tmp[j] = '+';
34 else */
35 if (!isalnum(tmp[j]) && strchr("_-.", tmp[j]) == NULL) {
36 tmp_len += 3;
37 if (dbuf != NULL) {
38 unsigned char *t = (unsigned char*)
39 acl_dbuf_pool_alloc(dbuf, tmp_len);
40 if (j > 0)
41 memcpy(t, tmp, j);
42 tmp = t;
43 } else
44 tmp = acl_myrealloc(tmp, tmp_len);
45
46 tmp[j++] = '%';
47 tmp[j++] = enc_tab[(unsigned char)str[i] >> 4];
48 tmp[j] = enc_tab[(unsigned char)str[i] & 0x0F];
49 }
50 }
51
52 tmp[j] = '\0';
53 return (char*) tmp;
54}
55
56static unsigned char dec_tab[256] = {
57 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

Callers 4

test_urlcodeFunction · 0.85
encodeMethod · 0.85
string.cppFile · 0.85
add_strFunction · 0.85

Calls 2

acl_dbuf_pool_allocFunction · 0.85
memcpyFunction · 0.85

Tested by 1

test_urlcodeFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…