[Openvas-commits] r1260 - trunk/openvas-plugins/scripts
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Sep 1 10:14:38 CEST 2008
Author: chandra
Date: 2008-09-01 10:14:37 +0200 (Mon, 01 Sep 2008)
New Revision: 1260
Modified:
trunk/openvas-plugins/scripts/url_func.inc
Log:
Added URL Encode and Decode functions
Modified: trunk/openvas-plugins/scripts/url_func.inc
===================================================================
--- trunk/openvas-plugins/scripts/url_func.inc 2008-09-01 07:56:15 UTC (rev 1259)
+++ trunk/openvas-plugins/scripts/url_func.inc 2008-09-01 08:14:37 UTC (rev 1260)
@@ -5,6 +5,12 @@
# TODO:
# - implement free/GPL urldecode and urlencode functions
# (in order to fully implement this include)
+#
+# Added:
+# - URL Encode function
+# - URL Decode function
+# Chandan S(schandan at secpod.com)
+#
global_var HEX_LOWERCASE, HEX_UPPERCASE;
HEX_LOWERCASE=1;
@@ -35,3 +41,71 @@
return ret;
}
+ ###############################################################
+ # Function Name 'urlencode'
+ ###############################################################
+
+ function urlencode(str, unreserved)
+ {
+ local_var estr;
+ char_set = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ num_set = "0123456789";
+ specl_char_set = "_-.!~*'()";
+ unreserv_chars = char_set + num_set + specl_char_set;
+
+ if(unreserved != NULL){
+ unreserv_chars = unreserv_chars + unreserved;
+ }
+
+ for(i=0; i<strlen(str); i++)
+ {
+ flag = "non_word";
+
+ # Encode on any non word character
+ for(j=0; j<strlen(unreserv_chars); j++)
+ {
+ if (str[i] == unreserv_chars[j])
+ {
+ flag = "word";
+ break;
+ }
+ }
+
+ if(flag == "non_word"){
+ estr = estr + '%' + hexstr(str[i]);
+ }
+ else{
+ estr = estr + str[i];
+ }
+ }
+ return(estr);
+ }
+
+
+ ###############################################################
+ # Function Name 'urldecode'
+ ###############################################################
+
+ function urldecode(estr)
+ {
+ local_var dstr;
+
+ for(i=0; i<strlen(estr); i++)
+ {
+ if(estr[i] == '%')
+ {
+ dstr = dstr + url_hex2raw(s:tolower(estr[i+1] + estr[i+2]));
+ i = i + 2;
+ }
+ else if(estr[i] == '+')
+ {
+ dstr = dstr + ' ';
+ i = i + 1;
+ }
+ else{
+ dstr = dstr + estr[i];
+ }
+ }
+ dstr = ereg_replace(string:dstr, pattern:"<!--(.|\n)*-->", replace:"", icase:1);
+ return(dstr);
+ }
More information about the Openvas-commits
mailing list