<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -276,6 +276,37 @@ const char *get_progress_id(request_rec *r) {
   return id;
 }
 
+const char *get_json_callback_param(request_rec *r) {
+  char *p, *start_p, *end_p;
+  int i;
+  const char *callback;
+  if (r-&gt;args) {
+      i = 0;
+      p = r-&gt;args;
+      do {
+          int len = strlen(p);
+          if (len &gt;= 9 &amp;&amp; strncasecmp(p, &quot;callback=&quot;, 9) == 0) {
+              i = 1;
+              break;
+          }
+          if (len&lt;=0)
+              break;
+      } 
+      while(p++);
+
+      if (i) {
+          i = 0;
+          start_p = p += 9;
+          end_p = r-&gt;args + strlen(r-&gt;args);
+          while (p &lt;= end_p &amp;&amp; *p++ != '&amp;') {
+              i++;
+          }
+          return apr_pstrndup(r-&gt;connection-&gt;pool, start_p, p-start_p-1);
+      }
+  }
+  return callback;
+}
+
 void cache_free(ServerConfig *config, const void *ptr)
 {
   if (config-&gt;cache_rmm) {
@@ -715,6 +746,7 @@ static int reportuploads_handler(request_rec *r)
     apr_table_set(r-&gt;headers_out, &quot;Expires&quot;, &quot;Mon, 28 Sep 1970 06:00:00 GMT&quot;);
     apr_table_set(r-&gt;headers_out, &quot;Cache-Control&quot;, &quot;no-cache&quot;);
 
+
 /*
  There are 4 possibilities
    * request not yet started: found = false
@@ -724,19 +756,32 @@ static int reportuploads_handler(request_rec *r)
    * reauest in progress:     rest &gt; 0 
  */
 
+   
     if (!found) {
-        response = apr_psprintf(r-&gt;pool, &quot;new Object({ 'state' : 'starting' })\r\n&quot;);
+      response = apr_psprintf(r-&gt;pool, &quot;new Object({ 'state' : 'starting' })&quot;);
     } else if (err_status &gt;= HTTP_BAD_REQUEST  ) {
-        response = apr_psprintf(r-&gt;pool, &quot;new Object({ 'state' : 'error', 'status' : %d })\r\n&quot;, err_status);
+      response = apr_psprintf(r-&gt;pool, &quot;new Object({ 'state' : 'error', 'status' : %d })&quot;, err_status);
     } else if (done) {
-        response = apr_psprintf(r-&gt;pool, &quot;new Object({ 'state' : 'done' })\r\n&quot;);
+      response = apr_psprintf(r-&gt;pool, &quot;new Object({ 'state' : 'done' })&quot;);
     } else if ( length == 0 &amp;&amp; received == 0 ) {
-        response = apr_psprintf(r-&gt;pool, &quot;new Object({ 'state' : 'starting' })\r\n&quot;);
+      response = apr_psprintf(r-&gt;pool, &quot;new Object({ 'state' : 'starting' })&quot;);
     } else {
-        response = apr_psprintf(r-&gt;pool, &quot;new Object({ 'state' : 'uploading', 'received' : %d, 'size' : %d, 'speed' : %d  })\r\n&quot;, received, length, speed);
+      response = apr_psprintf(r-&gt;pool, &quot;new Object({ 'state' : 'uploading', 'received' : %d, 'size' : %d, 'speed' : %d  })&quot;, received, length, speed);
     }
 
-    ap_rputs(response, r);
+    char *completed_response;
+    
+    /* get the jsonp callback if any */
+    const char *jsonp = get_json_callback_param(r);
+    
+    // fix up response for jsonp request, if needed
+    if (jsonp) {
+      completed_response = apr_psprintf(r-&gt;pool, &quot;%s(%s);\r\n&quot;, jsonp, response);
+    } else {
+      completed_response = apr_psprintf(r-&gt;pool, &quot;%s\r\n&quot;, response);
+    }
+    
+    ap_rputs(completed_response, r);
 
     return OK;
 }</diff>
      <filename>mod_upload_progress.c</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>39d2d78472fb1545e358f17e64f1525cadc8a13c</id>
    </parent>
  </parents>
  <author>
    <name>deadprogrammer</name>
    <email>ron.evans@gmail.com</email>
  </author>
  <url>http://github.com/drogus/apache-upload-progress-module/commit/20fed47119d3ea70b91ccb6a91a9338c8f127304</url>
  <id>20fed47119d3ea70b91ccb6a91a9338c8f127304</id>
  <committed-date>2009-02-10T00:57:54-08:00</committed-date>
  <authored-date>2009-02-03T08:50:49-08:00</authored-date>
  <message>Handle cross-domain upload progress requests using JSON-P, in addition to normal JSON requests

Signed-off-by: Piotr Sarnacki &lt;drogus@gmail.com&gt;</message>
  <tree>77308fd9a67823a85cb2d93379d976b2ece115da</tree>
  <committer>
    <name>Piotr Sarnacki</name>
    <email>drogus@gmail.com</email>
  </committer>
</commit>
