axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sam...@apache.org
Subject svn commit: r570685 - in /webservices/axis2/trunk/c/util: include/axutil_utils.h src/utils.c
Date Wed, 29 Aug 2007 08:04:07 GMT
Author: samisa
Date: Wed Aug 29 01:04:06 2007
New Revision: 570685

URL: http://svn.apache.org/viewvc?rev=570685&view=rev
Log:
Added XML quote function to help escape special chars

Modified:
    webservices/axis2/trunk/c/util/include/axutil_utils.h
    webservices/axis2/trunk/c/util/src/utils.c

Modified: webservices/axis2/trunk/c/util/include/axutil_utils.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/include/axutil_utils.h?rev=570685&r1=570684&r2=570685&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/include/axutil_utils.h (original)
+++ webservices/axis2/trunk/c/util/include/axutil_utils.h Wed Aug 29 01:04:06 2007
@@ -144,6 +144,25 @@
     AXIS2_EXTERN axis2_char_t** AXIS2_CALL
     axutil_parse_request_url_for_svc_and_op(const axutil_env_t *env, const axis2_char_t *request);
     
+    /**
+     * Quotes an XML string.
+     * Replace '<', '>', and '&' with '&lt;', '&gt;', and '&amp;'.
+     * If quotes is true, then replace '"' with '&quot;'.
+     * @param env pointer to environment struct
+     * @param s string to be quoted
+     * @param quotes if AXIS2_TRUE then replace '"' with '&quot;'.
+     * quotes is typically set to true for XML strings that will occur within
+     * double quotes -- attribute values.
+     * @return Encoded string if there are characters to be encoded, else NULL. 
+     * The caller is responsible to free the memory allocated by the function
+     * for the return value
+     */
+    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+    axutil_xml_quote_string(
+        const axutil_env_t *env,
+        const axis2_char_t *s,
+        axis2_bool_t quotes);
+  
 /** @} */
     
 #ifdef __cplusplus

Modified: webservices/axis2/trunk/c/util/src/utils.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/src/utils.c?rev=570685&r1=570684&r2=570685&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/src/utils.c (original)
+++ webservices/axis2/trunk/c/util/src/utils.c Wed Aug 29 01:04:06 2007
@@ -41,9 +41,9 @@
     {
         tmp = strstr(tmp, AXIS2_REQUEST_URL_PREFIX);
         if (!tmp)
-	{
+    {
             break;
-	}
+    }
         else
         {
             service_str = tmp;
@@ -93,6 +93,74 @@
     return ret;
 }
 
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+axutil_xml_quote_string(
+    const axutil_env_t *env,
+    const axis2_char_t *s,
+    axis2_bool_t quotes)
+{
+    const char *scan;
+    size_t len = 0;
+    size_t extra = 0;
+    char *qstr;
+    char *qscan;
+    char c;
+
+    for (scan = s; (c = *scan) != '\0'; ++scan, ++len) 
+    {
+        if (c == '<' || c == '>')
+            extra += 3;        /* &lt; or &gt; */
+        else if (c == '&')
+            extra += 4;        /* &amp; */
+        else if (quotes && c == '"')
+            extra += 5;        /* &quot; */
+    }
 
+    /* nothing to do */
+    if (extra == 0)
+        return NULL;
 
+    qstr = AXIS2_MALLOC(env->allocator, len + extra + 1);
+    for (scan = s, qscan = qstr; (c = *scan) != '\0'; ++scan) 
+    {
+        if (c == '<') 
+        {
+            *qscan++ = '&';
+            *qscan++ = 'l';
+            *qscan++ = 't';
+            *qscan++ = ';';
+        }
+        else if (c == '>') 
+        {
+            *qscan++ = '&';
+            *qscan++ = 'g';
+            *qscan++ = 't';
+            *qscan++ = ';';
+        }
+        else if (c == '&') 
+        {
+            *qscan++ = '&';
+            *qscan++ = 'a';
+            *qscan++ = 'm';
+            *qscan++ = 'p';
+            *qscan++ = ';';
+        }
+        else if (quotes && c == '"') 
+        {
+            *qscan++ = '&';
+            *qscan++ = 'q';
+            *qscan++ = 'u';
+            *qscan++ = 'o';
+            *qscan++ = 't';
+            *qscan++ = ';';
+        }
+        else 
+        {
+            *qscan++ = c;
+        }
+    }
+
+    *qscan = '\0';
+    return qstr;
+}
 



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org


Mime
View raw message