]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
DP_QC_URI_ESCAPE
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 27 Feb 2008 13:51:57 +0000 (13:51 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 27 Feb 2008 13:51:57 +0000 (13:51 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8143 d7cf8633-e32d-0410-b094-e92efae38249

clvm_cmds.c
mvm_cmds.c
prvm_cmds.c
prvm_cmds.h
svvm_cmds.c

index cedb6e818dcf536bfbd7ae5341e6b7aa92bd20c2..08bf6c8fdd2710518b9177e25def9d72efd11466 100644 (file)
@@ -3359,10 +3359,30 @@ VM_gecko_resize,                                        // #492 void gecko_resize( string name, float w, float h )
 VM_gecko_get_texture_extent,   // #493 vector gecko_get_texture_extent( string name )
 VM_crc16,                                              // #494 float(float caseinsensitive, string s, ...) crc16 = #494 (DP_QC_CRC16)
 VM_cvar_type,                                  // #495 float(string name) cvar_type = #495; (DP_QC_CVAR_TYPE)
-NULL,                                                  // #496
-NULL,                                                  // #497
+VM_uri_escape,                                 // #496 string(string in) uri_escape = #496;
+VM_uri_unescape,                               // #497 string(string in) uri_unescape = #497;
 NULL,                                                  // #498
 NULL,                                                  // #499
+NULL,                                                  // #500
+NULL,                                                  // #501
+NULL,                                                  // #502
+NULL,                                                  // #503
+NULL,                                                  // #504
+NULL,                                                  // #505
+NULL,                                                  // #506
+NULL,                                                  // #507
+NULL,                                                  // #508
+NULL,                                                  // #509
+VM_uri_escape,                                 // #510 string(string in) uri_escape = #510;
+VM_uri_unescape,                               // #511 string(string in) uri_unescape = #511;
+NULL,                                                  // #512
+NULL,                                                  // #513
+NULL,                                                  // #514
+NULL,                                                  // #515
+NULL,                                                  // #516
+NULL,                                                  // #517
+NULL,                                                  // #518
+NULL,                                                  // #519
 };
 
 const int vm_cl_numbuiltins = sizeof(vm_cl_builtins) / sizeof(prvm_builtin_t);
index c92d5c2769d6b3f2e9b43e13f5bf82818ea1d7b8..05f50f9be814f6efbf6634c21a5121405e5996d4 100644 (file)
@@ -26,6 +26,7 @@ char *vm_m_extensions =
 "DP_QC_CRC16 "
 "FTE_STRINGS "
 "DP_QC_CVAR_TYPE "
+"DP_QC_URI_ESCAPE "
 ;
 
 /*
@@ -1297,8 +1298,8 @@ NULL,                                                                     // #506
 NULL,                                                                  // #507
 NULL,                                                                  // #508
 NULL,                                                                  // #509
-NULL,                                                                  // #510
-NULL,                                                                  // #511
+VM_uri_escape,                                 // #510 string(string in) uri_escape = #510;
+VM_uri_unescape,                               // #511 string(string in) uri_unescape = #511;
 NULL,                                                                  // #512
 NULL,                                                                  // #513
 NULL,                                                                  // #514
index 5a86819ec7f701760ddc83689451d6c11aa8af57..401c7f93e445b73c6fc19d02b9e5fb08b88116f8 100644 (file)
@@ -4580,3 +4580,83 @@ void VM_Cmd_Reset(void)
 //     VM_BufStr_ShutDown();
 }
 
+// #510 string(string input, ...) uri_escape (DP_QC_URI_ESCAPE)
+// does URI escaping on a string (replace evil stuff by %AB escapes)
+void VM_uri_escape (void)
+{
+       char src[VM_STRINGTEMP_LENGTH];
+       char dest[VM_STRINGTEMP_LENGTH];
+       char *p, *q;
+       static const char *hex = "0123456789abcdef";
+
+       VM_SAFEPARMCOUNTRANGE(1, 8, VM_uri_escape);
+       VM_VarString(0, src, sizeof(src));
+
+       for(p = src, q = dest; *p && q < dest + sizeof(dest) - 3; ++p)
+       {
+               if((*p >= 'A' && *p <= 'Z')
+                       || (*p >= 'a' && *p <= 'z')
+                       || (*p >= '0' && *p <= '9')
+                       || (*p == '-')  || (*p == '_') || (*p == '.')
+                       || (*p == '!')  || (*p == '~') || (*p == '*')
+                       || (*p == '\'') || (*p == '(') || (*p == ')'))
+                       *q++ = *p;
+               else
+               {
+                       *q++ = '%';
+                       *q++ = hex[(*(unsigned char *)p >> 4) & 0xF];
+                       *q++ = hex[ *(unsigned char *)p       & 0xF];
+               }
+       }
+       *q++ = 0;
+
+       PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(dest);
+}
+
+// #510 string(string input, ...) uri_unescape (DP_QC_URI_ESCAPE)
+// does URI unescaping on a string (get back the evil stuff)
+void VM_uri_unescape (void)
+{
+       char src[VM_STRINGTEMP_LENGTH];
+       char dest[VM_STRINGTEMP_LENGTH];
+       char *p, *q;
+       int hi, lo;
+
+       VM_SAFEPARMCOUNTRANGE(1, 8, VM_uri_unescape);
+       VM_VarString(0, src, sizeof(src));
+
+       for(p = src, q = dest; *p; ) // no need to check size, because unescape can't expand
+       {
+               if(*p == '%')
+               {
+                       if(p[1] >= '0' && p[1] <= '9')
+                               hi = p[1] - '0';
+                       else if(p[1] >= 'a' && p[1] <= 'f')
+                               hi = p[1] - 'a' + 10;
+                       else if(p[1] >= 'A' && p[1] <= 'F')
+                               hi = p[1] - 'A' + 10;
+                       else
+                               goto nohex;
+                       if(p[2] >= '0' && p[2] <= '9')
+                               lo = p[2] - '0';
+                       else if(p[2] >= 'a' && p[2] <= 'f')
+                               lo = p[2] - 'a' + 10;
+                       else if(p[2] >= 'A' && p[2] <= 'F')
+                               lo = p[2] - 'A' + 10;
+                       else
+                               goto nohex;
+                       if(hi != 0 || lo != 0) // don't unescape NUL bytes
+                               *q++ = (char) (hi * 0x10 + lo);
+                       p += 3;
+                       continue;
+               }
+
+nohex:
+               // otherwise:
+               *q++ = *p++;
+       }
+       *q++ = 0;
+
+       PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(dest);
+}
+
index fdabb68db5e0e667dfa2e7391a0193df9726784e..b523e84f81237687ef10798397ae9027b5d00dad 100644 (file)
@@ -412,3 +412,6 @@ void VM_SetTraceGlobals(const trace_t *trace);
 
 void VM_Cmd_Init(void);
 void VM_Cmd_Reset(void);
+
+void VM_uri_escape (void);
+void VM_uri_unescape (void);
index bd12a0a7355079288a0177faf32edf5f784f655f..e2d1de3b6f16d46af2f0319214118709f17024b8 100644 (file)
@@ -153,6 +153,7 @@ char *vm_sv_extensions =
 "DP_SV_SHUTDOWN "
 "DP_GECKO_SUPPORT "
 "DP_QC_GETSURFACEPOINTATTRIBUTE "
+"DP_QC_URI_ESCAPE "
 ;
 
 /*
@@ -3349,6 +3350,26 @@ NULL,                                                    // #496
 NULL,                                                  // #497
 NULL,                                                  // #498
 NULL,                                                  // #499
+NULL,                                                  // #500
+NULL,                                                  // #501
+NULL,                                                  // #502
+NULL,                                                  // #503
+NULL,                                                  // #504
+NULL,                                                  // #505
+NULL,                                                  // #506
+NULL,                                                  // #507
+NULL,                                                  // #508
+NULL,                                                  // #509
+VM_uri_escape,                                 // #510 string(string in) uri_escape = #510;
+VM_uri_unescape,                               // #511 string(string in) uri_unescape = #511;
+NULL,                                                  // #512
+NULL,                                                  // #513
+NULL,                                                  // #514
+NULL,                                                  // #515
+NULL,                                                  // #516
+NULL,                                                  // #517
+NULL,                                                  // #518
+NULL,                                                  // #519
 };
 
 const int vm_sv_numbuiltins = sizeof(vm_sv_builtins) / sizeof(prvm_builtin_t);