MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / url_encode

Function url_encode

modules/db_http/http_dbase.c:940–985  ·  view source on GitHub ↗

Returns a url-encoded version of str */

Source from the content-addressed store, hash-verified

938
939/* Returns a url-encoded version of str */
940str 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
987db_con_t* db_http_init(const str* url)
988{

Callers 4

append_keysFunction · 0.85
append_valuesFunction · 0.85
append_opsFunction · 0.85
do_http_opFunction · 0.85

Calls 1

to_hexFunction · 0.85

Tested by

no test coverage detected