You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficserver.apache.org by "Leif Hedstrom (Updated) (JIRA)" <ji...@apache.org> on 2011/12/30 03:33:31 UTC

[jira] [Updated] (TS-254) Add TSEscapifyString() and TSUnescapifyString()

     [ https://issues.apache.org/jira/browse/TS-254?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Leif Hedstrom updated TS-254:
-----------------------------

    Fix Version/s:     (was: 3.1.4)
                   3.1.2

This is my proposed addition to the API. Note that I did add the (optional) map argument to Encode. There's just too many "rules" in the RFCs to make something that's applicable to everyone, and e.g. the Hipes plugin would certainly need its own map (since it needs to encode much more).

Comments appreciated.

{code}
diff --git a/proxy/api/ts/ts.h.in b/proxy/api/ts/ts.h.in
index dca69be..42942da 100644
--- a/proxy/api/ts/ts.h.in
+++ b/proxy/api/ts/ts.h.in
@@ -1572,6 +1572,50 @@ extern "C"
    */
   tsapi TSReturnCode TSUrlHttpFragmentSet(TSMBuffer bufp, TSMLoc offset, const char* value, int length);
 
+  /**
+     Perform percent-encoding of the string in the buffer, storing the
+     new string in the destination buffer. The length parameter will be
+     set to the new (encoded) string length, or 0 if the encoding failed.
+
+     @param str the string buffer to encode.
+     @param str_len length of the string buffer.
+     @param dst destination buffer.
+     @param dst_size size of the destination buffer.
+     @param length amount of data written to the destination buffer.
+     @param map optional (can be NULL) map of characters to encode.
+
+  */
+  tsapi TSReturnCode TSStringPercentEncode(const char* str, int str_len, char *dst, size_t dst_size, size_t *length, const unsigned char *map);
+
+  /**
+     Similar to TSStringPercentEncode(), but works on a URL object.
+
+     @param bufp marshal buffer containing the URL.
+     @param offset location of the URL within bufp.
+     @param dst destination buffer.
+     @param dst_size size of the destination buffer.
+     @param length amount of data written to the destination buffer.
+     @param map optional (can be NULL) map of characters to encode.
+
+  */
+  tsapi TSReturnCode TSUrlPercentEncode(TSMBuffer bufp, TSMLoc offset, char *dst, size_t dst_size, size_t *length, const unsigned char *map);
+
+  /**
+     Perform percent-decoding of the string in the buffer, writing
+     to the output buffer. The source and destination can be the same,
+     in which case they overwrite. The decoded string is always 
+     guaranteed to be no longer than the source string.
+
+     @param src the string to decode (and possibly write to).
+     @param src_len length of the input string (or -1).
+     @param dst output buffer (can be the same as src).
+     @param dst_len size of the output buffer.
+
+  */
+  tsapi size_t TSStringPercentDecode(const char *src, size_t src_len, char* dst, size_t dst_size);
+
+
+
   /* --------------------------------------------------------------------------
      MIME headers */
 
{code}
                
> Add TSEscapifyString() and TSUnescapifyString() 
> ------------------------------------------------
>
>                 Key: TS-254
>                 URL: https://issues.apache.org/jira/browse/TS-254
>             Project: Traffic Server
>          Issue Type: New Feature
>          Components: TS API
>    Affects Versions: 3.0.0
>            Reporter: Leif Hedstrom
>            Assignee: Leif Hedstrom
>            Priority: Minor
>             Fix For: 3.1.2
>
>
> It would be very convenient for plugin developers to have SDK APIs that allows for escaping and unescaping of strings. E.g.
> TSEscapifyString("http://www.ogre.com/ogre.png")
>      ->  http%3A%2F%2Fwww.ogre.com%2Fogre.png
> TSUnescapifyString("http%3A%2F%2Fwww.ogre.com%2Fogre.png)
>      -> http://www.ogre.com/ogre.png
> The "unescapify" string is fairly straight forward, but the "escapify" version might benefit from taking an (optional) table which describes what characters needs to be escaped (e.g. in in some cases you want a / to be escaped, but in others you do not).

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira