Index: HttpBody.cpp
===================================================================
--- HttpBody.cpp	(revision 9887)
+++ HttpBody.cpp	(working copy)
@@ -64,7 +64,10 @@
    {
       append(contentType);
       NameValueTokenizer::frontBackTrim(this, " \t");
-      //osPrintf("Content type: \"%s\"\n", mBodyContentType.data());
+      #ifdef TEST_PRINT
+	     osPrintf("Content type: \"%s\"\n", contentType);
+      #endif
+
       int boundaryIndex = index(MULTIPART_BOUNDARY_PARAMETER,
                                 0, UtlString::ignoreCase);
 
@@ -73,14 +76,12 @@
                0, UtlString::ignoreCase) == 0)
       {
          boundaryIndex += strlen(MULTIPART_BOUNDARY_PARAMETER);
-         //osPrintf("Boundary start:=>%s\n",
-         //    (mBodyContentType.data())[boundaryIndex]);
 
          // Allow white space before =
          int fieldLength = this->length();
          while(boundaryIndex < fieldLength &&
                (data()[boundaryIndex] == ' ' ||
-                data()[boundaryIndex] == '\t'))
+                data()[boundaryIndex] == '\t' ))
             boundaryIndex++;
 
          if(data()[boundaryIndex] == '=')
@@ -91,7 +92,13 @@
             if(whiteSpaceIndex > 0) mMultipartBoundary.remove(whiteSpaceIndex);
             whiteSpaceIndex = mMultipartBoundary.first('\t');
             if(whiteSpaceIndex > 0) mMultipartBoundary.remove(whiteSpaceIndex);
-            //osPrintf("HttpBody: boundary=\"%s\"\n", mMultipartBoundary.data());
+			whiteSpaceIndex = mMultipartBoundary.first('\"');
+            if(whiteSpaceIndex == 0) mMultipartBoundary.remove(whiteSpaceIndex,1);
+			whiteSpaceIndex = mMultipartBoundary.last('\"');
+            if(whiteSpaceIndex > 0) mMultipartBoundary.remove(whiteSpaceIndex);
+            #ifdef TEST_PRINT
+			   osPrintf("HttpBody: boundary=%s\n", mMultipartBoundary.data());
+            #endif
          }
       }
    }
@@ -113,40 +120,20 @@
                const char* partBytes;
                const char* parentBodyBytes;
                int partLength;
+			   int partStart;
                int parentBodyLength;
                getBytes(&parentBodyBytes, &parentBodyLength);
-               getMultipartBytes(partIndex, &partBytes, &partLength);
-               //osPrintf("Body part 1 length: %d\n", firstPart.length());
-               //osPrintf("++++ Multipart Body #1 ++++\n%s\n++++ End Multipart #1 ++++\n",
-               //    firstPart.data());
+			   getMultipartBytes(partIndex, &partBytes, &partLength, &partStart);
                if(partLength <= 0) break;
 
-               // Parse throught the header to the MIME part
-               // The first blank line is the begining of the part body
-               /*NameValueTokenizer parser(partBytes, partLength);
-                 do
-                 {
-                 parser.getNextPair(HTTP_NAME_VALUE_DELIMITER,
-                 &name, & value);
-                 if(name.compareTo(HTTP_CONTENT_TYPE_FIELD) == 0)
-                 {
-                 contentType = name;
-                 }
-                 }
-                 while(!name.isNull());*/
-
-               // This is a bit of a temporary kludge
-               //Prepend a HTTP header to make it look like a HTTP message
-               //partBytes.insert(0, "GET / HTTP/1.0\n");
-               //HttpMessage firstPartMessage(partBytes.data(), partBytes.length());
-               //const HttpBody* partFileBody = firstPartMessage.getBody();
-               //int bytesLeft = parser.getProcessedIndex() - partLength;
-
                if (partLength > 0)
                {
-                  mpBodyParts[partIndex] = new MimeBodyPart(this, partBytes - parentBodyBytes,
-                                                            partLength);
-                  // Save the number of body parts.
+                  #ifdef TEST_PRINT
+                     osPrintf("HttpBody constructor - MimeBodyPart %d added - partStart=%d - partLength=%d\n", partIndex, partStart, partLength ); // JMJ
+                  #endif
+                  mpBodyParts[partIndex] = new MimeBodyPart(this, partStart, partLength);
+
+				  // Save the number of body parts.
                   mBodyPartCount = partIndex + 1;
                }
                else
@@ -206,7 +193,7 @@
    {
       mpBodyParts[partIndex] =
          rHttpBody.mpBodyParts[partIndex] ?
-         new MimeBodyPart(*(rHttpBody.mpBodyParts[partIndex])) :
+         new MimeBodyPart(this, rHttpBody.mpBodyParts[partIndex]->getRawStart(), rHttpBody.mpBodyParts[partIndex]->getRawLength() ) :
          NULL;
    }
 }
@@ -249,8 +236,10 @@
     {
        if(mpBodyParts[partIndex]) delete mpBodyParts[partIndex];
            if (rhs.mpBodyParts[partIndex])
-                        mpBodyParts[partIndex] = new MimeBodyPart(*(rhs.mpBodyParts[partIndex]));
-           else
+                   mpBodyParts[partIndex] = new MimeBodyPart(this, rhs.mpBodyParts[partIndex]->getRawStart(), 
+				                                             rhs.mpBodyParts[partIndex]->getRawLength() );
+
+		   else
                    mpBodyParts[partIndex] = NULL;
    }
    return *this;
@@ -284,7 +273,7 @@
 
     case HTTP_BODY_CLASS:
         body = new HttpBody(sourceBody);
-#ifdef TEST_PRINT
+#ifdef TEST_PRINT2
         OsSysLog::add(FAC_SIP, PRI_DEBUG, "HttpMessage::HttpMessage HttpBody copy content-type: %s\n",
             bodyType ? bodyType : "<null>");
 #endif
@@ -501,11 +490,19 @@
 
 UtlBoolean HttpBody::getMultipartBytes(int partIndex,
                                        const char** bytes,
-                                       int* length) const
+                                       int* length, int* start) const
 {
+	#ifdef TEST_PRINT
+	    osPrintf("GetMultipartBytes: PartIndex = %d\n", partIndex);
+    #endif
+
     UtlBoolean partFound = FALSE;
     if(!mMultipartBoundary.isNull())
     {
+        #ifdef TEST_PRINT
+		    osPrintf("Multipart Boundary: %s\n", mMultipartBoundary.data() ); // JMJ
+        #endif
+
         int byteIndex = -1;
         int partNum = -1;
         int partStartIndex = -1;
@@ -513,27 +510,33 @@
         do
         {
             byteIndex = mBody.index(mMultipartBoundary.data(), byteIndex + 1);
+            #ifdef TEST_PRINT
+                osPrintf("ByteIndex: %d\n", byteIndex);
+            #endif
+
             if(byteIndex >= 0)
             {
                 partNum++;
                 if(partNum == partIndex)
                 {
-                    partStartIndex = byteIndex + mMultipartBoundary.length();
+					#ifdef TEST_PRINT
+                        osPrintf("Part Num: %d\n", partNum);
+                    #endif
+					partStartIndex = byteIndex + mMultipartBoundary.length();
                     if((mBody.data())[partStartIndex] == '\r') partStartIndex++;
                     if((mBody.data())[partStartIndex] == '\n') partStartIndex++;
+					#ifdef TEST_PRINT
+                        osPrintf("Part Start Index: %d\n", partStartIndex);
+                    #endif
                 }
                 else if(partNum == partIndex + 1)
                 {
                     partEndIndex = byteIndex - 3;
-                    //osPrintf("Part End Index: %d\n", partEndIndex);
-                    //osPrintf("End of file: %c %d\n", mBody.data()[partEndIndex],
-                    //    (int) ((mBody.data())[partEndIndex]));
                     if(((mBody.data())[partEndIndex]) == '\n') partEndIndex--;
-                    //osPrintf("End of file: %c %d\n", mBody.data()[partEndIndex],
-                    //    (int) ((mBody.data())[partEndIndex]));
                     if(((mBody.data())[partEndIndex]) == '\r') partEndIndex--;
-                    //osPrintf("End of file: %c %d\n", mBody.data()[partEndIndex],
-                    //    (int) ((mBody.data())[partEndIndex]));
+					#ifdef TEST_PRINT
+                        osPrintf("Part End Index: %d\n", partEndIndex);
+                    #endif
                 }
             }
         }
@@ -542,12 +545,14 @@
         {
             *bytes = &(mBody.data()[partStartIndex]);
             *length = partEndIndex - partStartIndex + 1;
+			*start = partStartIndex;
             partFound = TRUE;
         }
         else
         {
             *bytes = NULL;
             *length = 0;
+			*start = -1;
         }
     }
     return(partFound);
