Browse code

dsm: mod_uri: uri.encode and uri.decode

Stefan Sayer authored on 11/11/2013 20:10:50
Showing 3 changed files
... ...
@@ -44,6 +44,9 @@ MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) {
44 44
   DEF_CMD("uri.parseNameaddr", URIParseNameaddrAction);
45 45
   DEF_CMD("uri.getHeader", URIGetHeaderAction);
46 46
 
47
+  DEF_CMD("uri.encode", URIEncodeAction);
48
+  DEF_CMD("uri.decode", URIDecodeAction);
49
+
47 50
 } MOD_ACTIONEXPORT_END;
48 51
 
49 52
 MOD_CONDITIONEXPORT_NONE(MOD_CLS_NAME);
... ...
@@ -117,3 +120,28 @@ EXEC_ACTION_START(URIGetHeaderAction) {
117 120
       hname.c_str(), sc_sess->var[dstname].c_str(), dstname.c_str());
118 121
 
119 122
 } EXEC_ACTION_END;
123
+
124
+
125
+CONST_ACTION_2P(URIEncodeAction, '=', false);
126
+EXEC_ACTION_START(URIEncodeAction) {
127
+
128
+  string varname  = par1;
129
+  if (varname.size() && varname[0]=='$')
130
+    varname.erase(0,1);
131
+  string str = resolveVars(par2, sess, sc_sess, event_params);
132
+
133
+  sc_sess->var[varname] = URL_encode(str);
134
+  DBG("URL-encoded: $%s=\"%s\"\n", varname.c_str(), sc_sess->var[varname].c_str());
135
+} EXEC_ACTION_END;
136
+
137
+CONST_ACTION_2P(URIDecodeAction, '=', false);
138
+EXEC_ACTION_START(URIDecodeAction) {
139
+
140
+  string varname  = par1;
141
+  if (varname.size() && varname[0]=='$')
142
+    varname.erase(0,1);
143
+  string str = resolveVars(par2, sess, sc_sess, event_params);
144
+
145
+  sc_sess->var[varname] = URL_decode(str);
146
+  DBG("URL-decoded: $%s=\"%s\"\n", varname.c_str(), sc_sess->var[varname].c_str());
147
+} EXEC_ACTION_END;
... ...
@@ -38,4 +38,7 @@ DEF_ACTION_2P(URIParseAction);
38 38
 DEF_ACTION_2P(URIParseNameaddrAction);
39 39
 DEF_ACTION_2P(URIGetHeaderAction);
40 40
 
41
+DEF_ACTION_2P(URIEncodeAction);
42
+DEF_ACTION_2P(URIDecodeAction);
43
+
41 44
 #endif
... ...
@@ -36,3 +36,8 @@ uri.getHeader(<header>, <dst>)
36 36
     	uri.getHeader(P-Asserted-Identity, PAI);
37 37
 
38 38
  
39
+uri.encode($dstvar=text)  - encode special characters into dstvar
40
+   e.g. uri.encode($replaces_hdr=$replaces_hdr);
41
+
42
+uri.decode($dstvar=text)  - decode special characters into dstvar
43
+   e.g. uri.encode($replaces=$replaces_hdr);