Returns a url-encoded version of str */
| 938 | |
| 939 | /* Returns a url-encoded version of str */ |
| 940 | str url_encode(str s) |
| 941 | { |
| 942 | |
| 943 | |
| 944 | static char *buf = NULL; |
| 945 | static int size = 0; |
| 946 | |
| 947 | char *pstr ; |
| 948 | char *pbuf; |
| 949 | str rez; |
| 950 | int i; |
| 951 | |
| 952 | pstr = s.s; |
| 953 | if( s.len * 3 + 1 > size) |
| 954 | { |
| 955 | buf = pkg_realloc(buf, s.len * 3 + 1); |
| 956 | size = s.len * 3 + 1; |
| 957 | } |
| 958 | |
| 959 | pbuf = buf; |
| 960 | i = 0; |
| 961 | |
| 962 | while ( i < s.len ) |
| 963 | { |
| 964 | if (isalnum(*pstr) || *pstr == '-' || |
| 965 | *pstr == '_' || *pstr == '.' || *pstr == '~') |
| 966 | |
| 967 | *pbuf++ = *pstr; |
| 968 | else |
| 969 | { |
| 970 | *pbuf++ = '%'; |
| 971 | *pbuf++ = to_hex(*pstr >> 4); |
| 972 | *pbuf++ = to_hex(*pstr & 15); |
| 973 | } |
| 974 | |
| 975 | pstr++; |
| 976 | i++; |
| 977 | } |
| 978 | |
| 979 | rez.s = buf; |
| 980 | rez.len = pbuf - buf; |
| 981 | |
| 982 | |
| 983 | |
| 984 | return rez; |
| 985 | } |
| 986 | |
| 987 | db_con_t* db_http_init(const str* url) |
| 988 | { |
no test coverage detected