axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sam...@apache.org
Subject svn commit: r397051 - in /webservices/axis2/trunk/c/modules/xml/attachments: axis2_data_handler.h axis2_mime_body_part.h axis2_mime_output.h data_handler.c mime_body_part.c mime_output.c
Date Wed, 26 Apr 2006 02:13:30 GMT
Author: samisa
Date: Tue Apr 25 19:13:27 2006
New Revision: 397051

URL: http://svn.apache.org/viewcvs?rev=397051&view=rev
Log:
Commiting in the MTOM related patches by Kapila

Modified:
    webservices/axis2/trunk/c/modules/xml/attachments/axis2_data_handler.h
    webservices/axis2/trunk/c/modules/xml/attachments/axis2_mime_body_part.h
    webservices/axis2/trunk/c/modules/xml/attachments/axis2_mime_output.h
    webservices/axis2/trunk/c/modules/xml/attachments/data_handler.c
    webservices/axis2/trunk/c/modules/xml/attachments/mime_body_part.c
    webservices/axis2/trunk/c/modules/xml/attachments/mime_output.c

Modified: webservices/axis2/trunk/c/modules/xml/attachments/axis2_data_handler.h
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/xml/attachments/axis2_data_handler.h?rev=397051&r1=397050&r2=397051&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/xml/attachments/axis2_data_handler.h (original)
+++ webservices/axis2/trunk/c/modules/xml/attachments/axis2_data_handler.h Tue Apr 25 19:13:27 2006
@@ -66,8 +66,9 @@
 	
 	axis2_byte_t * (AXIS2_CALL *get_input_stream)(axis2_data_handler_t *data_handler, axis2_env_t **env); 
 
-	axis2_status_t (AXIS2_CALL *write_to)(axis2_data_handler_t *data_handler, axis2_env_t **env, \
-							axis2_byte_t output_stream);
+    axis2_status_t (AXIS2_CALL *
+    write_to)(axis2_data_handler_t *data_handler, axis2_env_t **env, 
+                axis2_byte_t** output_stream, int *output_stream_size);
 
 	/** Deallocate memory
      * @return status code
@@ -94,17 +95,21 @@
  * @return pointer to newly created data_handler
  */
 AXIS2_DECLARE(axis2_data_handler_t *) 
-axis2_data_handler_create (axis2_env_t **env, void *data, axis2_char_t *data_type);
+axis2_data_handler_create (axis2_env_t **env, axis2_char_t *file_name, axis2_char_t *mime_type);
 
 /*************************** Function macros **********************************/
 
-#define AXIS2_DATA_HANDLER_FREE(data_handler, env) ((data_handler)->ops->free (data_handler, env))
+#define AXIS2_DATA_HANDLER_FREE(data_handler, env) \
+    ((data_handler)->ops->free (data_handler, env))
 
-#define AXIS2_DATA_HANDLER_GET_CONTENT_TYPE(data_handler, env) ((data_handler)->ops->get_content_type (data_handler, env))
+#define AXIS2_DATA_HANDLER_GET_CONTENT_TYPE(data_handler, env) \
+    ((data_handler)->ops->get_content_type (data_handler, env))
 
-#define AXIS2_DATA_HANDLER_GET_INPUT_STREAM(data_handler, env) ((data_handler)->ops->get_input_stream (data_handler, env))
+#define AXIS2_DATA_HANDLER_GET_INPUT_STREAM(data_handler, env) \
+    ((data_handler)->ops->get_input_stream (data_handler, env))
 
-#define AXIS2_DATA_HANDLER_WRITE_TO(data_handler, env, output_stream) ((data_handler)->ops->write_to (data_handler, env, output_stream));
+#define AXIS2_DATA_HANDLER_WRITE_TO(data_handler, env, output_stream, output_stream_size) \
+    ((data_handler)->ops->write_to (data_handler, env, output_stream, output_stream_size))
 
 /*************************** End of function macros ***************************/
 

Modified: webservices/axis2/trunk/c/modules/xml/attachments/axis2_mime_body_part.h
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/xml/attachments/axis2_mime_body_part.h?rev=397051&r1=397050&r2=397051&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/xml/attachments/axis2_mime_body_part.h (original)
+++ webservices/axis2/trunk/c/modules/xml/attachments/axis2_mime_body_part.h Tue Apr 25 19:13:27 2006
@@ -37,47 +37,46 @@
 {
 #endif
 
-
-/* This should be moved to header file later axis2_defines.h*/    
-#define axis2_byte_t char
 	
 typedef struct axis2_mime_body_part_ops axis2_mime_body_part_ops_t;
 typedef struct axis2_mime_body_part axis2_mime_body_part_t;	
 
-/*
-      private final DataSource ds;
-      private final DataFlavor flavor;
-      private CommandMap commandMap;
-      private DataContentHandler dch;
-*/
-
-/** @defgroup axis2_mime_body_part Flow
+/** @defgroup axis2_mime_body_part
   * @ingroup axis2_mime_body_part
   * @{
   */
 
 /** 
- * @brief Flow ops struct
+ * @brief ops struct
  * Encapsulator struct for ops of axis2_mime_body_part
  */
 struct axis2_mime_body_part_ops
 {
-	axis2_status_t (AXIS2_CALL *add_header)(axis2_mime_body_part_t *mime_body_part, axis2_env_t **env, axis2_char_t *name, axis2_char_t *value); 
+	axis2_status_t (AXIS2_CALL *
+    add_header)(axis2_mime_body_part_t *mime_body_part, 
+            axis2_env_t **env, 
+            axis2_char_t *name, 
+            axis2_char_t *value); 
 	
-    axis2_status_t (AXIS2_CALL *set_data_handler)(axis2_mime_body_part_t *mime_body_part, axis2_env_t **env, axis2_data_handler_t *data_handler); 
-
-    axis2_status_t (AXIS2_CALL *write_to)(axis2_mime_body_part_t *mime_body_part, axis2_env_t **env,axis2_byte_t **output_stream, int *output_stream_size, axis2_char_t *ignore_list); 
+    axis2_status_t (AXIS2_CALL *
+    set_data_handler)(axis2_mime_body_part_t *mime_body_part, 
+            axis2_env_t **env, 
+            axis2_data_handler_t *data_handler); 
+
+    axis2_status_t (AXIS2_CALL *
+    write_to)(axis2_mime_body_part_t *mime_body_part, 
+            axis2_env_t **env,
+            axis2_byte_t **output_stream, 
+            int *output_stream_size); 
 
 	/** Deallocate memory
      * @return status code
      */
-    axis2_status_t (AXIS2_CALL *free) (axis2_mime_body_part_t *mime_body_part, axis2_env_t **env);
+    axis2_status_t (AXIS2_CALL *
+    free) (axis2_mime_body_part_t *mime_body_part, 
+            axis2_env_t **env);
 };
 
-/** 
- * @brief Flow struct
- *	Flow  
- */ 
 struct axis2_mime_body_part
 {
 	axis2_mime_body_part_ops_t *ops;
@@ -93,14 +92,17 @@
 
 /*************************** Function macros **********************************/
 
-#define AXIS2_MIME_BODY_PART_FREE(mime_body_part, env) ((mime_body_part)->ops->free (mime_body_part, env))
-
-#define AXIS2_MIME_BODY_PART_ADD_HEADER(mime_body_part, env, name, value) ((mime_body_part)->ops->add_header (mime_body_part, env, name, value))
+#define AXIS2_MIME_BODY_PART_FREE(mime_body_part, env) \
+    ((mime_body_part)->ops->free (mime_body_part, env))
 
-#define AXIS2_MIME_BODY_PART_SET_DATA_HANDLER(mime_body_part, env, data_handler) ((mime_body_part)->ops->set_data_handler (mime_body_part, env, data_handler))
+#define AXIS2_MIME_BODY_PART_ADD_HEADER(mime_body_part, env, name, value) \
+    ((mime_body_part)->ops->add_header (mime_body_part, env, name, value))
 
-#define AXIS2_MIME_BODY_WRITE_TO(mime_body_part, env, output_stream, output_stream_size, ignore_list)
+#define AXIS2_MIME_BODY_PART_SET_DATA_HANDLER(mime_body_part, env, data_handler) \
+    ((mime_body_part)->ops->set_data_handler (mime_body_part, env, data_handler))
 
+#define AXIS2_MIME_BODY_PART_WRITE_TO(mime_body_part, env, output_stream, output_stream_size) \
+    ((mime_body_part)->ops->write_to (mime_body_part, env, output_stream, output_stream_size))
 
 /*************************** End of function macros ***************************/
 

Modified: webservices/axis2/trunk/c/modules/xml/attachments/axis2_mime_output.h
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/xml/attachments/axis2_mime_output.h?rev=397051&r1=397050&r2=397051&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/xml/attachments/axis2_mime_output.h (original)
+++ webservices/axis2/trunk/c/modules/xml/attachments/axis2_mime_output.h Tue Apr 25 19:13:27 2006
@@ -57,12 +57,15 @@
 {
 
     axis2_byte_t* (AXIS2_CALL *complete)(axis2_mime_output_t *mime_output,
-                            axis2_env_t **env, axis2_byte_t **output_stream,
+                            axis2_env_t **env, 
+                            axis2_byte_t **output_stream,
 							int *output_stream_size,
-                            axis2_char_t *string_to_write, 
+                            axis2_char_t *soap_body_buffer,
                             axis2_array_list_t *binary_node_list,
-                            axis2_char_t *boundary, axis2_char_t *content_id,
-                            axis2_char_t *char_set_encoding,axis2_char_t *soap_content_type);
+                            axis2_char_t *boundary, 
+                            axis2_char_t *content_id,
+                            axis2_char_t *char_set_encoding,
+                            axis2_char_t *soap_content_type);
 
     axis2_char_t* (AXIS2_CALL *get_content_type_for_mime)(axis2_mime_output_t *mime_output, axis2_env_t **env, 
                         axis2_char_t *boundary, axis2_char_t *content_id, axis2_char_t *char_set_encoding, axis2_char_t *soap_content_type);
@@ -95,8 +98,8 @@
 
 #define AXIS2_MIME_OUTPUT_FREE(mime_output, env) ((mime_output)->ops->free (mime_output, env))
 
-#define AXIS2_MIME_OUTPUT_COMPLETE(mime_output, env, output_stream, output_stream_size, string_to_write, binary_node_list, boundary, content_id, char_set_encoding, soap_content_type) \
-((mime_output)->ops->complete(mime_output, env, output_stream, output_stream_size, string_to_write, boundary, binary_node_list, content_id, char_set_encoding, soap_content_type))
+#define AXIS2_MIME_OUTPUT_COMPLETE(mime_output, env, output_stream, output_stream_size, soap_body_buffer, binary_node_list, boundary, content_id, char_set_encoding, soap_content_type) \
+((mime_output)->ops->complete(mime_output, env, output_stream, output_stream_size, soap_body_buffer, binary_node_list, boundary, content_id, char_set_encoding, soap_content_type))
 
 #define AXIS2_MIME_OUTPUT_GET_CONTENT_TYPE_FOR_MIME(mime_output, env, boundary, content_id, char_set_encoding, soap_content_type) \
 ((mime_output)->ops->get_content_type_for_mime(mime_output, env, boundary, content_id, char_set_encoding, soap_content_type))

Modified: webservices/axis2/trunk/c/modules/xml/attachments/data_handler.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/xml/attachments/data_handler.c?rev=397051&r1=397050&r2=397051&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/xml/attachments/data_handler.c (original)
+++ webservices/axis2/trunk/c/modules/xml/attachments/data_handler.c Tue Apr 25 19:13:27 2006
@@ -15,21 +15,13 @@
  */
  
 #include <axis2_data_handler.h>
+#include <stdio.h>
 
-/** 
- * @brief Flow struct impl
- *	Axis2 Flow impl  
- */
 typedef struct axis2_data_handler_impl
 {
 	axis2_data_handler_t data_handler;
-    /**
-     * Field list
-     */
-    /*   
-	axis2_char_t type;
-    *void handler;
-	*/
+	axis2_char_t* mime_type;
+    axis2_char_t* file_name;
 } axis2_data_handler_impl_t;
 
 
@@ -48,13 +40,13 @@
 axis2_data_handler_get_input_stream (axis2_data_handler_t *data_handler, axis2_env_t **env); 
 
 axis2_status_t AXIS2_CALL
-axis2_data_handler_write_to(axis2_data_handler_t *data_handler, axis2_env_t **env, \
-							axis2_byte_t output_stream);
+axis2_data_handler_write_to(axis2_data_handler_t *data_handler, axis2_env_t **env, 
+                                axis2_byte_t** output_stream, int *output_stream_size);
 
 /************************** End of Function headers ************************/
 
 AXIS2_DECLARE(axis2_data_handler_t *)
-axis2_data_handler_create (axis2_env_t **env, void *data, axis2_char_t *data_type)
+axis2_data_handler_create (axis2_env_t **env, axis2_char_t *file_name, axis2_char_t *mime_type)
 {
     axis2_data_handler_impl_t *data_handler_impl = NULL;
     
@@ -69,6 +61,29 @@
     }
 	
     data_handler_impl->data_handler.ops = NULL;
+    data_handler_impl->mime_type = NULL;
+    data_handler_impl->file_name = NULL;
+
+    if (mime_type)
+    {
+        data_handler_impl->mime_type = AXIS2_STRDUP(mime_type, env);
+        if (!(data_handler_impl->mime_type))
+        {
+            axis2_data_handler_free(&(data_handler_impl->data_handler), env);
+            AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+            return NULL;
+        }
+    }
+    if (file_name)
+    {
+        data_handler_impl->file_name = AXIS2_STRDUP(file_name, env);
+        if (!(data_handler_impl->file_name))
+        {
+            axis2_data_handler_free(&(data_handler_impl->data_handler), env);
+            AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+            return NULL;
+        }
+    }
     
 	data_handler_impl->data_handler.ops = AXIS2_MALLOC ((*env)->allocator, 
         sizeof(axis2_data_handler_ops_t));
@@ -115,9 +130,7 @@
 axis2_data_handler_get_content_type (axis2_data_handler_t *data_handler, axis2_env_t **env) 
 {
     AXIS2_ENV_CHECK(env, NULL);       
-	
-	/*@TODO implement the following*/
-	return "";
+	return AXIS2_INTF_TO_IMPL(data_handler)->mime_type;
 }
 
 axis2_byte_t * AXIS2_CALL
@@ -126,277 +139,120 @@
     AXIS2_ENV_CHECK(env, NULL);       
 	
 	/*@TODO implement the following*/
-	/**
-	InputStream getInputStream()
-	final DataContentHandler dch = getDataContentHandler();
-             if (dch == null) {
-                 throw new UnsupportedDataTypeException();
-           }
-             final PipedInputStream is = new PipedInputStream();
-             Thread thread = new Thread() {
-                 public void run() {
-                     try {
-                         PipedOutputStream os = new PipedOutputStream(is);
-                        is.connect(os);
-                         try {
-                             dch.writeTo(data, mimeType, os);
-                         } finally {
-                            os.close();
-                         }
-                     } catch (IOException e) {
-                         // ignore, per spec - doh!
-                     }
-                 }
-             };
-             thread.start();
-             return is;
-	*/		
 	return "";
 }
 
 axis2_status_t AXIS2_CALL
-axis2_data_handler_write_to(axis2_data_handler_t *data_handler, axis2_env_t **env, \
-							axis2_byte_t output_stream)
+axis2_data_handler_write_to(axis2_data_handler_t *data_handler, axis2_env_t **env, 
+							axis2_byte_t** output_stream, int *output_stream_size)
 {
-	/**
-          if (ds instanceof ObjectDataSource) {
-              ObjectDataSource ods = (ObjectDataSource) ds;
-              DataContentHandler dch = getDataContentHandler();
-              if (dch == null) {
-                  throw new UnsupportedDataTypeException();
-              }
-              dch.writeTo(ods.data, ods.mimeType, os);
-          } else {
-              byte[] buffer = new byte[1024];
-              InputStream is = getInputStream();
-              try {
-                  int count;
-                  while ((count = is.read(buffer)) != -1) {
-                      os.write(buffer, 0, count);
-                  }
-              } finally {
-                  is.close();
-              }
-          }
-	*/  
+    axis2_data_handler_impl_t *data_handler_impl = NULL;
+    
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    data_handler_impl = AXIS2_INTF_TO_IMPL(data_handler);
+    
+    if (data_handler_impl->file_name)
+    {
+        FILE *f = NULL;
+        axis2_byte_t *byte_stream = NULL;
+        axis2_byte_t *temp_byte_stream = NULL;
+        axis2_byte_t *read_stream = NULL;
+        int byte_stream_size = 0;
+        int temp_byte_stream_size = 0;
+        int read_stream_size = 0;
+        int count = 0;
+        
+        f = fopen(data_handler_impl->file_name, "rb");
+        if (!f)
+            return AXIS2_FAILURE;
+        
+        do {
+            read_stream_size = 1024;
+            read_stream = AXIS2_MALLOC((*env)->allocator, (read_stream_size) * sizeof(axis2_byte_t));
+            if (!read_stream)
+            {
+                AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+                if (byte_stream)
+                {
+                    AXIS2_FREE((*env)->allocator, byte_stream);
+                    byte_stream = NULL;
+                }
+                return AXIS2_FAILURE;
+            }
+            count = fread(read_stream, sizeof(axis2_byte_t), 1024, f);
+            if (ferror(f) != 0)
+            {
+                /*TODO : need to set the correct error code */
+                AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+                if (byte_stream)
+                {
+                    AXIS2_FREE((*env)->allocator, byte_stream);
+                    byte_stream = NULL;
+                }
+                if (read_stream)
+                {
+                    AXIS2_FREE((*env)->allocator, read_stream);
+                    read_stream = NULL;
+                }
+                return AXIS2_FAILURE;
+            }
+            
+            /* copy the read bytes */
+            if (count > 0)
+            {
+                if (byte_stream)
+                {
+                    temp_byte_stream = byte_stream;
+                    temp_byte_stream_size = byte_stream_size;
+                    byte_stream_size = temp_byte_stream_size + count;
+                    byte_stream = AXIS2_MALLOC((*env)->allocator, (byte_stream_size) * sizeof(axis2_byte_t));
+                    if (!byte_stream)
+                    {
+                        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+                        if (read_stream)
+                        {
+                            AXIS2_FREE((*env)->allocator, read_stream);
+                            read_stream = NULL;
+                        }
+                        if (temp_byte_stream)
+                        {
+                            AXIS2_FREE((*env)->allocator, temp_byte_stream);
+                            temp_byte_stream = NULL;
+                        }
+                        return AXIS2_FAILURE;
+                    }
+                    
+                    memcpy(byte_stream, temp_byte_stream, temp_byte_stream_size);
+                    memcpy(byte_stream + temp_byte_stream_size, read_stream, count);
+                    
+                    if (read_stream)
+                    {
+                        AXIS2_FREE((*env)->allocator, read_stream);
+                        read_stream = NULL;
+                        read_stream_size = 0;
+                    }
+                    if (temp_byte_stream)
+                    {
+                        AXIS2_FREE((*env)->allocator, temp_byte_stream);
+                        temp_byte_stream = NULL;
+                        temp_byte_stream_size = 0;
+                    }
+                }
+                else
+                {
+                    byte_stream = read_stream;
+                    byte_stream_size = read_stream_size;
+                    read_stream = NULL;
+                    read_stream_size = 0;
+                }
+            }
+        }while (!feof(f));
+        
+        fclose(f);
+        
+        *output_stream = byte_stream;
+        *output_stream_size = byte_stream_size;
+    }
+	
     return AXIS2_SUCCESS;
 }
-
-/* Private Functions */
-
-
-/* ========================================================================= */
-/*
-55      public DataSource getDataSource() {
-56          return ds;
-57      }
-58  
-59      public String getName() {
-60          return ds.getName();
-61      }
-62  
-
-	
-66  
-70  
-
-92  
-93      public OutputStream getOutputStream() throws IOException {
-94          return ds.getOutputStream();
-95      }
-96  
-97      public synchronized DataFlavor[] getTransferDataFlavors() {
-98          return getDataContentHandler().getTransferDataFlavors();
-99      }
-100 
-101     public boolean isDataFlavorSupported(DataFlavor flavor) {
-102         DataFlavor[] flavors = getTransferDataFlavors();
-103         for (int i = 0; i < flavors.length; i++) {
-104             DataFlavor dataFlavor = flavors[i];
-105             if (dataFlavor.equals(flavor)) {
-106                 return true;
-107             }
-108         }
-109         return false;
-110     }
-111 
-112     public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
-113         DataContentHandler dch = getDataContentHandler();
-114         if (dch != null) {
-115             return dch.getTransferData(flavor, ds);
-116         } else if (this.flavor.match(flavor)) {
-117             if (ds instanceof ObjectDataSource) {
-118                 return ((ObjectDataSource) ds).data;
-119             } else {
-120                 return ds.getInputStream();
-121             }
-122         } else {
-123             throw new UnsupportedFlavorException(flavor);
-124         }
-125     }
-126 
-127     public CommandInfo[] getPreferredCommands() {
-128         return getCommandMap().getPreferredCommands(ds.getContentType());
-129     }
-130 
-131     public CommandInfo[] getAllCommands() {
-132         return getCommandMap().getAllCommands(ds.getContentType());
-133     }
-134 
-135     public CommandInfo getCommand(String cmdName) {
-136         return getCommandMap().getCommand(ds.getContentType(), cmdName);
-137     }
-138 
-139     public Object getContent() throws IOException {
-140         if (ds instanceof ObjectDataSource) {
-141             return ((ObjectDataSource) ds).data;
-142         } else {
-143             DataContentHandler dch = getDataContentHandler();
-144             if (dch != null) {
-145                 return dch.getContent(ds);
-146             } else {
-147                 return ds.getInputStream();
-148             }
-149         }
-150     }
-151 
-152     public Object getBean(CommandInfo cmdinfo) {
-153         try {
-154             return cmdinfo.getCommandObject(this, this.getClass().getClassLoader());
-155         } catch (IOException e) {
-156             return null;
-157         } catch (ClassNotFoundException e) {
-158             return null;
-159         }
-160     }
-161
-*/
-     /**
-163      * A local implementation of DataSouce used to wrap an Object and mime-type.
-164      */
-/*
-165     private class ObjectDataSource implements DataSource {
-166         private final Object data;
-167         private final String mimeType;
-168 
-169         public ObjectDataSource(Object data, String mimeType) {
-170             this.data = data;
-171             this.mimeType = mimeType;
-172         }
-173 
-174         public String getName() {
-175             return null;
-176         }
-177 
-178         public String getContentType() {
-179             return mimeType;
-180         }
-181 
-182         public InputStream getInputStream() throws IOException {
-183             final DataContentHandler dch = getDataContentHandler();
-184             if (dch == null) {
-185                 throw new UnsupportedDataTypeException();
-186             }
-187             final PipedInputStream is = new PipedInputStream();
-188             Thread thread = new Thread() {
-189                 public void run() {
-190                     try {
-191                         PipedOutputStream os = new PipedOutputStream(is);
-192                         is.connect(os);
-193                         try {
-194                             dch.writeTo(data, mimeType, os);
-195                         } finally {
-196                             os.close();
-197                         }
-198                     } catch (IOException e) {
-199                         // ignore, per spec - doh!
-200                     }
-201                 }
-202             };
-203             thread.start();
-204             return is;
-205         }
-206 
-207         public OutputStream getOutputStream() throws IOException {
-208             return null;
-209         }
-210     }
-211 
-212     public synchronized void setCommandMap(CommandMap commandMap) {
-213         this.commandMap = commandMap;
-214         this.dch = null;
-215     }
-216 
-217     private synchronized CommandMap getCommandMap() {
-218         return commandMap != null ? commandMap : CommandMap.getDefaultCommandMap();
-219     }
-220
-*/
-     /**
-222      * Search for a DataContentHandler for our mime type.
-223      * The search is performed by first checking if a global factory has been set using
-224      * {@link #setDataContentHandlerFactory(DataContentHandlerFactory)};
-225      * if found then it is called to attempt to create a handler.
-226      * If this attempt fails, we then call the command map set using {@link #setCommandMap(CommandMap)}
-227      * (or if that has not been set, the default map returned by {@link CommandMap#getDefaultCommandMap()})
-228      * to create the handler.
-229      *
-230      * The resulting handler is cached until the global factory is changed.
-231      *
-232      * @return
-233      */
-/*
-234     private synchronized DataContentHandler getDataContentHandler() {
-235         DataContentHandlerFactory localFactory;
-236         synchronized (DataHandler.class) {
-237             if (factory != originalFactory) {
-238                 // setDCHF was called - clear our cached copy of the DCH and DCHF
-239                 dch = null;
-240                 originalFactory = factory;
-241             }
-242             localFactory = originalFactory;
-243         }
-244         if (dch == null) {
-245             String contentType = ds.getContentType();
-246             if (localFactory != null) {
-247                 dch = localFactory.createDataContentHandler(contentType);
-248             }
-249             if (dch == null) {
-250                 if (commandMap != null) {
-251                     dch = commandMap.createDataContentHandler(contentType);
-252                 } else {
-253                     dch = CommandMap.getDefaultCommandMap().createDataContentHandler(contentType);
-254                 }
-255             }
-256         }
-257         return dch;
-258     }
-259 
-261      * This is used to check if the DataContentHandlerFactory has been changed.
-262      * This is not specified behaviour but this check is required to make this work like the RI.
-264     private DataContentHandlerFactory originalFactory;
-265 
-266     {
-267         synchronized (DataHandler.class) {
-268             originalFactory = factory;
-269         }
-270     }
-271 
-272     private static DataContentHandlerFactory factory;
-273 
-275      * Set the DataContentHandlerFactory to use.
-276      * If this method has already been called then an Error is raised.
-277      *
-278      * @param newFactory the new factory
-279      * @throws SecurityException if the caller does not have "SetFactory" RuntimePermission
-281     public static synchronized void setDataContentHandlerFactory(DataContentHandlerFactory newFactory) {
-282         if (factory != null) {
-283             throw new Error("javax.activation.DataHandler.setDataContentHandlerFactory has already been defined");
-284         }
-285         SecurityManager sm = System.getSecurityManager();
-286         if (sm != null) {
-287             sm.checkSetFactory();
-288         }
-289         factory = newFactory;
-290     }	
-*/

Modified: webservices/axis2/trunk/c/modules/xml/attachments/mime_body_part.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/xml/attachments/mime_body_part.c?rev=397051&r1=397050&r2=397051&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/xml/attachments/mime_body_part.c (original)
+++ webservices/axis2/trunk/c/modules/xml/attachments/mime_body_part.c Tue Apr 25 19:13:27 2006
@@ -15,21 +15,17 @@
  */
  
 #include <axis2_mime_body_part.h>
+#include <axis2_data_handler.h>
 
-/** 
- * @brief Flow struct impl
- *	Axis2 Flow impl  
- */
 typedef struct axis2_mime_body_part_impl
 {
 	axis2_mime_body_part_t mime_body_part;
-    /**
-     * Field list
-     */
-	/** Hash map to hold header name, value pairs */
+	/** hash map to hold header name, value pairs */
 	axis2_hash_t *header_map;
+    axis2_data_handler_t *data_handler;
 } axis2_mime_body_part_impl_t;
 
+extern axis2_char_t AXIS2_CRLF[];
 
 
 #define AXIS2_INTF_TO_IMPL(mime_body_part) ((axis2_mime_body_part_impl_t *)(mime_body_part))
@@ -48,8 +44,7 @@
 
 axis2_status_t AXIS2_CALL
 axis2_mime_body_part_write_to (axis2_mime_body_part_t *mime_body_part, axis2_env_t **env, 
-                                axis2_byte_t **output_stream, int *output_stream_size, 
-                                axis2_char_t *ignore_list);
+                                axis2_byte_t **output_stream, int *output_stream_size);
 /************************** End of Function headers ************************/
 
 AXIS2_DECLARE(axis2_mime_body_part_t *)
@@ -67,8 +62,18 @@
         return NULL;
     }
 	
+    mime_body_part_impl->header_map = NULL;
+    mime_body_part_impl->data_handler = NULL;
     mime_body_part_impl->mime_body_part.ops = NULL;
     
+    mime_body_part_impl->header_map = axis2_hash_make(env);
+    if (!(mime_body_part_impl->header_map))
+    {
+        axis2_mime_body_part_free(&(mime_body_part_impl->mime_body_part), env);
+		AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+    
 	mime_body_part_impl->mime_body_part.ops = AXIS2_MALLOC ((*env)->allocator, 
         sizeof(axis2_mime_body_part_ops_t));
 	if(NULL == mime_body_part_impl->mime_body_part.ops)
@@ -95,6 +100,12 @@
     
     AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
     mime_body_part_impl = AXIS2_INTF_TO_IMPL(mime_body_part);
+
+    if (mime_body_part_impl->header_map)
+    {
+        axis2_hash_free(mime_body_part_impl->header_map, env);
+        mime_body_part_impl->header_map = NULL;
+    }
     
     if(NULL != mime_body_part->ops)
     {
@@ -116,65 +127,100 @@
 axis2_mime_body_part_add_header (axis2_mime_body_part_t *mime_body_part, axis2_env_t **env,
     axis2_char_t *name, axis2_char_t *value) 
 {
-	AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
-	/* headers.addHeader(name, value);     */
+    axis2_mime_body_part_impl_t *mime_body_part_impl = NULL;
+       
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK((*env)->error, name, AXIS2_FAILURE);
+    
+    mime_body_part_impl = AXIS2_INTF_TO_IMPL(mime_body_part);
+    
+    axis2_hash_set(mime_body_part_impl->header_map, name, 
+        AXIS2_HASH_KEY_STRING, value);
     return AXIS2_SUCCESS;
 }
 
-/**
- * This method provides the mechanism to set this body part's content.
- * The given DataHandler object should wrap the actual content.
- * 
- * @param   dh      The DataHandler for the content
- */                 
-
 axis2_status_t AXIS2_CALL
-axis2_mime_body_part_set_data_handler (axis2_mime_body_part_t *mime_body_part, axis2_env_t **env, axis2_data_handler_t *data_handler) 
+axis2_mime_body_part_set_data_handler (axis2_mime_body_part_t *mime_body_part, 
+    axis2_env_t **env, axis2_data_handler_t *data_handler) 
 {
 	AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_INTF_TO_IMPL(mime_body_part)->data_handler = data_handler;
     return AXIS2_SUCCESS;
-
-	/*** 
-	setDataHandler(DataHandler dh) 
-	this.dh = dh;
-	MimeBodyPart.invalidateContentHeaders(this);
-	*/
 }
 
 axis2_status_t AXIS2_CALL
 axis2_mime_body_part_write_to (axis2_mime_body_part_t *mime_body_part, axis2_env_t **env, 
-                                axis2_byte_t **output_stream, int *output_stream_size, 
-                                axis2_char_t *ignore_list) 
+                                axis2_byte_t **output_stream, int *output_stream_size) 
 {
-	AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+	axis2_mime_body_part_impl_t *mime_body_part_impl = NULL;
+    axis2_hash_index_t *hash_index = NULL;
+    const void *key = NULL;
+    void *value = NULL;
+    axis2_char_t *header_str = NULL;
+    int header_str_size = 0;
+    axis2_byte_t *data_handler_stream = NULL;
+    int data_handler_stream_size = 0;
+    axis2_status_t status = AXIS2_FAILURE;
+    axis2_byte_t *byte_stream = NULL;
+    int size = 0;
+    
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    
+    mime_body_part_impl = AXIS2_INTF_TO_IMPL(mime_body_part);
+    
+    for (hash_index = axis2_hash_first (mime_body_part_impl->header_map, env);
+             hash_index; hash_index = axis2_hash_next (env, hash_index))
+    {
+        axis2_hash_this (hash_index, &key, NULL, &value);
+        if (key && value)
+        {
+            header_str = AXIS2_STRACAT(header_str, (axis2_char_t*)key, env);
+            header_str = AXIS2_STRACAT(header_str, ": ", env);
+            header_str = AXIS2_STRACAT(header_str, (axis2_char_t*)value, env);
+            header_str = AXIS2_STRACAT(header_str, "\r\n", env);
+        }
+    }
+    
+    if (header_str)
+        header_str_size = AXIS2_STRLEN(header_str);
+    
+    /* TODO encoding needs to be done, we only support binary as of now,
+       Java supports "base64", "uuencode", "x-uuencode", "x-uue", 
+       "quoted-printable" 
+    */
+    if (mime_body_part_impl->data_handler)
+    {
+        status = AXIS2_DATA_HANDLER_WRITE_TO(mime_body_part_impl->data_handler, env,
+                    &data_handler_stream, &data_handler_stream_size);
+        if (status == AXIS2_FAILURE)
+            return AXIS2_FAILURE;
+    }
+    
+    size = header_str_size + data_handler_stream_size;
+    byte_stream = AXIS2_MALLOC((*env)->allocator, (size) * sizeof(axis2_byte_t));
+    if (!byte_stream)
+    {
+		AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        if (data_handler_stream)
+        {
+            AXIS2_FREE((*env)->allocator, data_handler_stream);
+            data_handler_stream = NULL;
+        }
+        if (header_str)
+        {
+            AXIS2_FREE((*env)->allocator, header_str);
+            header_str = NULL;
+        }
+        return AXIS2_FAILURE;
+    }
+    /*TODO char2byte header_str */
+    if (header_str)
+        memcpy(byte_stream, header_str, header_str_size);
+    if (data_handler_stream)
+        memcpy(byte_stream + header_str_size, data_handler_stream, data_handler_stream_size);
+
+    *output_stream = byte_stream;
+    *output_stream_size = size;
+    
     return AXIS2_SUCCESS;
 }
-
-
-/**
-    static void writeTo(MimePart part, OutputStream os, String[] ignoreList)
-			throws IOException, MessagingException {
-
-	// see if we already have a LOS
-	LineOutputStream los = null;
-	if (os instanceof LineOutputStream) {
-	    los = (LineOutputStream) os;
-	} else {
-	    los = new LineOutputStream(os);
-	}
-
-	// First, write out the header
-	Enumeration hdrLines = part.getNonMatchingHeaderLines(ignoreList);
-	while (hdrLines.hasMoreElements())
-	    los.writeln((String)hdrLines.nextElement());
-
-	// The CRLF separator between header and content
-	los.writeln();
-
-	// Finally, the content. Encode if required.
-	// XXX: May need to account for ESMTP ?
-	os = MimeUtility.encode(os, part.getEncoding());
-	part.getDataHandler().writeTo(os);
-	os.flush(); // Needed to complete encoding
-    }
-*/

Modified: webservices/axis2/trunk/c/modules/xml/attachments/mime_output.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/xml/attachments/mime_output.c?rev=397051&r1=397050&r2=397051&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/xml/attachments/mime_output.c (original)
+++ webservices/axis2/trunk/c/modules/xml/attachments/mime_output.c Tue Apr 25 19:13:27 2006
@@ -18,34 +18,19 @@
 #include <axis2_data_handler.h>
 #include <axis2_mime_body_part.h>
 #include <axis2_string.h>
-/** 
- * @brief Flow struct impl
- *	Axis2 Flow impl  
- */
-
+#include <axis2_om_text.h>
 
 axis2_char_t AXIS2_CRLF[] =  { 13, 10 };
-int AXIS2_CRLF_LENGTH = 2;
 
 typedef struct axis2_mime_output_impl
 {
 	axis2_mime_output_t mime_output;
-    /**
-     * Field list
-     *private XMLStreamWriter xmlWriter;
-     *private OutputStream outStream;
-     *private LinkedList binaryNodeList = new LinkedList();
-     *private StringWriter bufferedSOAPBody;
-     *private OMOutputFormat format = new OMOutputFormat();
-     */
-    
-    
 } axis2_mime_output_impl_t;
 
 #define AXIS2_INTF_TO_IMPL(mime_output) ((axis2_mime_output_impl_t *)(mime_output))
 #define AXIS2_MIME_BOUNDARY_BYTE 45
 #define AXIS2_MIME_CRLF_BYTE 13
-/* private static byte[] CRLF =  { 13, 10 }; */
+
 
 axis2_status_t axis2_char_2_byte(axis2_env_t **env, axis2_char_t *char_buffer, axis2_byte_t **byte_buffer, int *byte_buffer_size);
 
@@ -55,17 +40,17 @@
     int length;
     int i = 0;
     axis2_byte_t *bytes;
-    /*env check*/
+    AXIS2_ENV_CHECK(env, NULL);
+
     length = AXIS2_STRLEN(char_buffer);
     bytes = AXIS2_MALLOC((*env)->allocator, length * sizeof(axis2_byte_t));
-    /*@TODO do the char to byte conversion*/
     
     for(i = 0; i < length; i++)
     {
         bytes[i] = (axis2_byte_t) char_buffer[i];
     }
-    byte_buffer = &bytes;
-    *byte_buffer_size = length;
+    *byte_buffer = bytes;
+    *byte_buffer_size = length;
 	return AXIS2_SUCCESS;
 }
 
@@ -76,19 +61,22 @@
 
 axis2_byte_t * AXIS2_CALL
 axis2_mime_output_complete(axis2_mime_output_t *mime_output,
-                            axis2_env_t **env, axis2_byte_t **output_stream, 
+                            axis2_env_t **env, 
+                            axis2_byte_t **output_stream, 
                             int *output_stream_size, 
-                            axis2_char_t *string_to_write, 
+                            axis2_char_t *soap_body_buffer,
                             axis2_array_list_t *binary_node_list,
-                            axis2_char_t *boundary, axis2_char_t *content_id,
-                            axis2_char_t *char_set_encoding,axis2_char_t *soap_content_type);
+                            axis2_char_t *boundary, 
+                            axis2_char_t *content_id,
+                            axis2_char_t *char_set_encoding,
+                            axis2_char_t *soap_content_type);
 axis2_status_t AXIS2_CALL
 axis2_start_writing_mime (axis2_mime_output_t *mime_output, 
                             axis2_env_t **env, axis2_byte_t **output_stream, 
                             int *output_stream_size, axis2_char_t *boundary);
 
 axis2_mime_body_part_t * AXIS2_CALL
-axis2_create_mime_body_part (axis2_mime_output_t *mime_output, axis2_env_t **env);
+axis2_create_mime_body_part (axis2_om_text_t *text, axis2_env_t **env);
 
 axis2_status_t AXIS2_CALL
 axis2_write_body_part (axis2_mime_output_t *mime_output, axis2_env_t **env, 
@@ -105,8 +93,12 @@
                         axis2_byte_t **output_stream, int *output_stream_size, axis2_char_t *boundary);
 
 axis2_char_t * AXIS2_CALL
-axis2_mime_output_get_content_type_for_mime (axis2_mime_output_t *mime_output, axis2_env_t **env, 
-                        axis2_char_t *boundary, axis2_char_t *content_id, axis2_char_t *char_set_encoding, axis2_char_t *soap_content_type);
+axis2_mime_output_get_content_type_for_mime (axis2_mime_output_t *mime_output, 
+        axis2_env_t **env, 
+        axis2_char_t *boundary, 
+        axis2_char_t *content_id, 
+        axis2_char_t *char_set_encoding, 
+        axis2_char_t *soap_content_type);
 
 /************************** End of Function headers ************************/
 
@@ -171,90 +163,175 @@
 
 axis2_byte_t * AXIS2_CALL
 axis2_mime_output_complete(axis2_mime_output_t *mime_output,
-                            axis2_env_t **env, axis2_byte_t **output_stream, 
+                            axis2_env_t **env, 
+                            axis2_byte_t **output_stream, 
                             int *output_stream_size, 
-                            axis2_char_t *string_to_write, 
+                            axis2_char_t *soap_body_buffer,
                             axis2_array_list_t *binary_node_list,
-                            axis2_char_t *boundary, axis2_char_t *content_id,
-                            axis2_char_t *char_set_encoding,axis2_char_t *soap_content_type)
+                            axis2_char_t *boundary, 
+                            axis2_char_t *content_id,
+                            axis2_char_t *char_set_encoding, 
+                            axis2_char_t *soap_content_type)
 {
-            /*axis2_byte_t *mime_stream = NULL;
-            AXIS2_CRLF_LENGTH
-            axis2_byte_t *root_mime_body_part = NULL;
-            Define this
-            int root_mime_body_part_length = 0;
-            int mime_stream_length = (AXIS2_CRLF_LENGTH * 2) + (root_mime_body_part_length);
-            mime_stream = AXIS2_MALLOC((*env)->allocator, (mime_stream_length * sizeof(mime_stream_length)));
-            */
+    axis2_status_t status = AXIS2_FAILURE;
     axis2_char_t *encoding_string = NULL;
     axis2_char_t *header_value = NULL;
-    axis2_char_t *content_id_string = NULL;
-    axis2_data_handler_t *data_handler = NULL;
+    axis2_char_t *content_id_string = NULL;
+    axis2_data_handler_t *data_handler = NULL;
 	axis2_mime_body_part_t *root_mime_body_part = NULL;
-
+    axis2_byte_t *output_stream_start = NULL;
+    int output_stream_start_size = 0;
+    axis2_byte_t *output_stream_body = NULL;
+    int output_stream_body_size = 0;
+    axis2_byte_t *output_stream_body_parts = NULL;
+    int output_stream_body_parts_size = 0;
+    axis2_byte_t *boundary_stream = NULL;
+    int boundary_stream_size = 0;
+    axis2_byte_t *stream_buffer = NULL;
+    int stream_buffer_size = 0;
+    int soap_body_buffer_size = 0;
+    
     AXIS2_ENV_CHECK(env, NULL); 
          
-    axis2_start_writing_mime (mime_output, env, output_stream, output_stream_size, boundary);
-
-    encoding_string = AXIS2_STRDUP("text/xml; charset=", env);
-    AXIS2_STRACAT(encoding_string, char_set_encoding, env);    
-       
-    data_handler = axis2_data_handler_create(env, (void*)string_to_write, encoding_string);
+    status = axis2_start_writing_mime (mime_output, env, &output_stream_start, &output_stream_start_size, boundary);
+    if (status == AXIS2_FAILURE)
+        return NULL;
     
+
     root_mime_body_part = axis2_mime_body_part_create(env);
-    /*@TODO please check the correctness of the parameters passed*/
-    AXIS2_MIME_BODY_PART_SET_DATA_HANDLER(root_mime_body_part, env ,data_handler);
 
+    /* content-type */
     header_value = AXIS2_STRDUP("application/xop+xml; charset=", env);
-    AXIS2_STRACAT(header_value, char_set_encoding, env);
-    AXIS2_STRACAT(header_value, "; typeAXIS2_CRLF=\"", env);
-    AXIS2_STRACAT(header_value, soap_content_type, env);
-    AXIS2_STRACAT(header_value, "\";", env);
-    /*@TODO please check the correctness of the parameters passed*/
-    AXIS2_MIME_BODY_PART_ADD_HEADER(root_mime_body_part, env, "content-transfer-encoding","binary");
-
-    AXIS2_STRACAT(content_id_string, "<", env);
-    AXIS2_STRACAT(content_id_string, content_id, env);
-    AXIS2_STRACAT(content_id_string, ">", env);
-    /*@TODO please check the correctness of the parameters passed*/
-    AXIS2_MIME_BODY_PART_ADD_HEADER(root_mime_body_part, env, "content-id",content_id_string);
-    /***/
-    /*@TODO please check the correctness of the parameters passed*/
-    axis2_write_body_part (mime_output, env, output_stream, output_stream_size, root_mime_body_part, boundary);
-            
-            /*javax.activation.DataHandler dh = new javax.activation.DataHandler(writer.toString(),
-                    "text/xml; charset=" + char_set_encoding);
-            MimeBodyPart rootMimeBodyPart = new MimeBodyPart();
-            rootMimeBodyPart.setDataHandler(dh);
-            
-            rootMimeBodyPart.addHeader("content-type",
-                    "application/xop+xml; charset=" + char_set_encoding + 
-					"; typeAXIS2_CRLF=\""+soap_content_type+"\";");
-            rootMimeBodyPart.addHeader("content-transfer-encoding", "binary");
-            rootMimeBodyPart.addHeader("content-id","<"+content_id+">");
-            */
+    header_value = AXIS2_STRACAT(header_value, char_set_encoding, env);
+    header_value = AXIS2_STRACAT(header_value, "; type=\"", env);
+    header_value = AXIS2_STRACAT(header_value, soap_content_type, env);
+    header_value = AXIS2_STRACAT(header_value, "\";", env);
+    AXIS2_MIME_BODY_PART_ADD_HEADER(root_mime_body_part, env, "content-type", header_value);
+    
+    /* content-transfer-encoding */
+    AXIS2_MIME_BODY_PART_ADD_HEADER(root_mime_body_part, env, "content-transfer-encoding", "binary");
+
+    /* content-id */
+    content_id_string = "<";
+    content_id_string = AXIS2_STRACAT(content_id_string, content_id, env);
+    content_id_string = AXIS2_STRACAT(content_id_string, ">", env);
+    AXIS2_MIME_BODY_PART_ADD_HEADER(root_mime_body_part, env, "content-id", content_id_string);
     
-            /*writeBodyPart(outStream, rootMimeBodyPart, boundary);*/
+    axis2_write_body_part (mime_output, env, &output_stream_body, &output_stream_body_size, root_mime_body_part, boundary);
+            
+    if (binary_node_list)
+    {
+        int j = 0;
+        axis2_byte_t *temp_stream = NULL;
+        int temp_stream_size = 0;
+        axis2_byte_t *temp = NULL;
+        int temp_size = 0;
+        for (j = 0; j < AXIS2_ARRAY_LIST_SIZE(binary_node_list, env); j++)
+        {
+            axis2_om_text_t *text = (axis2_om_text_t *)AXIS2_ARRAY_LIST_GET(binary_node_list, env, j);
+            if (text)
+            {
+                axis2_mime_body_part_t *mime_body_part = NULL;
+                mime_body_part = axis2_create_mime_body_part(text, env);
+                axis2_write_body_part(mime_output, env, &temp_stream, 
+                    &temp_stream_size, mime_body_part, boundary);
+                temp = output_stream_body_parts;
+                temp_size = output_stream_body_parts_size;
+                output_stream_body_parts_size = temp_size + 
+                    output_stream_start_size + temp_stream_size;
+                output_stream_body_parts = AXIS2_MALLOC((*env)->allocator, 
+                        output_stream_body_parts_size * sizeof(axis2_byte_t));
+                if (!output_stream_body_parts)
+                {
+                    AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+                    return NULL;
+                }
+                
+                if (temp) 
+                {
+                    memcpy(output_stream_body_parts, temp, temp_size);
+                    AXIS2_FREE((*env)->allocator, temp);
+                    temp = NULL;
+                }
+
+                if (output_stream_start)
+                {
+                    memcpy(output_stream_body_parts + temp_size, 
+                        output_stream_start, output_stream_start_size);
+                }
+                
+                if (temp_stream) 
+                {
+                    memcpy(output_stream_body_parts + temp_size + 
+                        output_stream_start_size, temp_stream, temp_stream_size);
+                    AXIS2_FREE((*env)->allocator, temp_stream);
+                    temp_stream = NULL;
+                }
+
+                temp_size = 0;
+                temp_stream_size = 0;
+            }
+        }
+    }
+
+    axis2_write_finish_writing_mime (mime_output,  env, &boundary_stream, 
+            &boundary_stream_size, boundary);
     
+    if (soap_body_buffer)
+    {
+        soap_body_buffer_size = AXIS2_STRLEN(soap_body_buffer);
+    }
     
+	stream_buffer_size = output_stream_start_size + output_stream_body_size + 
+            soap_body_buffer_size + output_stream_body_parts_size + 
+            boundary_stream_size;
             
-            /*
-            Iterator binaryNodeIterator = binary_node_list.iterator();
-            while (binaryNodeIterator.hasNext()) {
-                OMText binaryNode = (OMText) binaryNodeIterator.next();
-                writeBodyPart(outStream, createMimeBodyPart(binaryNode),
-                        boundary);
-
-            finishWritingMime(outStream);
-            */
-	return NULL;
-}
+    stream_buffer = AXIS2_MALLOC((*env)->allocator, 
+            stream_buffer_size * sizeof(axis2_byte_t));
 
+    if (output_stream_start)
+    {
+        memcpy(stream_buffer, output_stream_start, output_stream_start_size);
+        AXIS2_FREE((*env)->allocator, output_stream_start);
+        output_stream_start = NULL;
+    }
+    
+    if (output_stream_body)
+    {
+        memcpy(stream_buffer + output_stream_start_size, output_stream_body, 
+                output_stream_body_size);
+        AXIS2_FREE((*env)->allocator, output_stream_body);
+        output_stream_body = NULL;
+    }
 
-/**
-  * This will write the boundary with CRLF data_handler 
-  * The method is a private method and is called from axis2_output_complete method
-  */
+    if (soap_body_buffer)
+    {
+         memcpy(stream_buffer + output_stream_start_size + output_stream_body_size, 
+                soap_body_buffer, soap_body_buffer_size);
+    }
+    
+    if (output_stream_body_parts)
+    {
+        memcpy(stream_buffer + output_stream_start_size + output_stream_body_size +
+                soap_body_buffer_size, 
+                output_stream_body_parts, output_stream_body_parts_size);
+        AXIS2_FREE((*env)->allocator, output_stream_body_parts);
+        output_stream_body_parts = NULL;
+    }
+    
+    if (boundary_stream)
+    {
+        memcpy(stream_buffer + output_stream_start_size + output_stream_body_size + 
+                soap_body_buffer_size + output_stream_body_parts_size, 
+                boundary_stream, boundary_stream_size);
+        AXIS2_FREE((*env)->allocator, boundary_stream);
+        boundary_stream = NULL;
+    }
+    
+    *output_stream = stream_buffer;
+    *output_stream_size = stream_buffer_size;
+    return stream_buffer;
+}
 
 axis2_status_t AXIS2_CALL
 axis2_start_writing_mime (axis2_mime_output_t *mime_output,
@@ -262,118 +339,127 @@
                             int *output_stream_size, axis2_char_t *boundary)
 {
     AXIS2_ENV_CHECK(env, AXIS2_FAILURE);     
-    axis2_write_mime_boundary (mime_output, env, output_stream, output_stream_size, boundary);
-	return AXIS2_SUCCESS;
+    return axis2_write_mime_boundary (mime_output, env, output_stream, output_stream_size, boundary);
 }
 
-
- 
-/*
-    public static void writeMimeBoundary(OutputStream outStream,
-                                         axis2_char_t *boundary) throws IOException {
-        outStream.write(new byte[]{45, 45});
-        outStream.write(boundary.getBytes());
-    }
-*/
-/*@TODO please check the coretness of the following method*/
 axis2_status_t AXIS2_CALL
 axis2_write_mime_boundary (axis2_mime_output_t *mime_output, axis2_env_t **env,
                             axis2_byte_t **output_stream, int *output_stream_size, 
                             axis2_char_t *boundary)
 {
-    axis2_byte_t *byte_buffer;
-    axis2_byte_t *byte_stream;
-    int size;
+    axis2_byte_t *byte_buffer = NULL;
+    axis2_byte_t *byte_stream = NULL;
+    int size = 0;
         
     AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
     
     axis2_char_2_byte(env, boundary, &byte_buffer, &size);
-    byte_stream = AXIS2_MALLOC((*env)->allocator, (size + 1) * sizeof(axis2_byte_t));
-    byte_stream[size + 1] = AXIS2_MIME_BOUNDARY_BYTE;
-    
-    
+    if (!byte_buffer)
+        return AXIS2_FAILURE;
+    byte_stream = AXIS2_MALLOC((*env)->allocator, (size + 2) * sizeof(axis2_byte_t));
+    if (!byte_stream)
+    {
+		AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return AXIS2_FAILURE;
+    }
+
+    byte_stream[0] = AXIS2_MIME_BOUNDARY_BYTE;
+    byte_stream[1] = AXIS2_MIME_BOUNDARY_BYTE;
+    if (byte_buffer)
+    {
+        memcpy (byte_stream + 2, byte_buffer, size);
+        AXIS2_FREE((*env)->allocator, byte_buffer);
+        byte_buffer = NULL;
+    }
+        
     AXIS2_FREE((*env)->allocator, byte_buffer);
     
-    output_stream = &byte_stream;
-    *output_stream_size = size + 1;
+    *output_stream = byte_stream;
+    *output_stream_size = size + 2;
         
     return AXIS2_SUCCESS;
 }
 
-
 axis2_mime_body_part_t * AXIS2_CALL
-axis2_create_mime_body_part (axis2_mime_output_t *mime_output, axis2_env_t **env)
-/*public static MimeBodyPart createMimeBodyPart(OMText node)*/
+axis2_create_mime_body_part (axis2_om_text_t *text, axis2_env_t **env)
 {
-    /**    
-      *MimeBodyPart mimeBodyPart = new MimeBodyPart();
-      *mimeBodyPart.setDataHandler((javax.activation.DataHandler)node.getDataHandler());
-      *mimeBodyPart.addHeader("content-id", "<"+node.getContentID()+">");
-      *mimeBodyPart.addHeader("content-type", "application/octet-stream");
-      *mimeBodyPart.addHeader("content-transfer-encoding", "binary");
-      *return mimeBodyPart;
-     */
-    AXIS2_ENV_CHECK(env, NULL);
-	return NULL;
-}
-
-
+    axis2_data_handler_t *data_handler = NULL;
+    axis2_char_t * content_type = "application/octet-stream";
+    axis2_mime_body_part_t * mime_body_part = axis2_mime_body_part_create(env);
+    axis2_char_t * content_id = "<";
+    if (!mime_body_part)
+        return NULL;
+    data_handler = AXIS2_OM_TEXT_SET_GET_DATA_HANDLER(text, env);
 
-/**
-     * Writes a CRLF for the earlier boundary then the BodyPart data
-     * with headers followed by boundary. Writes only the boundary. No more, int *output_stream_size, 
-     * CRLF's are written after that.
-     *
-     */
-/*  
-  public static void writeBodyPart(OutputStream outStream,
-                                     MimeBodyPart part, 
-                                     axis2_char_t *boundary) throws IOException,
-            MessagingException {
-        outStream.write(CRLF);
-        part.writeTo(outStream);
-        outStream.write(CRLF);
-        writeMimeBoundary(outStream, boundary);
+    if (data_handler)
+    {
+        content_type = AXIS2_DATA_HANDLER_GET_CONTENT_TYPE(data_handler, env);
     }
-*/
+    
+    AXIS2_MIME_BODY_PART_SET_DATA_HANDLER(mime_body_part, env, 
+            data_handler);
+    content_id = AXIS2_STRACAT(content_id, 
+        AXIS2_OM_TEXT_SET_GET_CONTENT_ID(text, env), env);
+    content_id = AXIS2_STRACAT(content_id, ">", env); 
+    AXIS2_MIME_BODY_PART_ADD_HEADER(mime_body_part, env, "content-id", content_id);
+    AXIS2_MIME_BODY_PART_ADD_HEADER(mime_body_part, env, "content-type", content_type);
+    AXIS2_MIME_BODY_PART_ADD_HEADER(mime_body_part, env, "content-transfer-encoding", "binary");
 
+	return mime_body_part;
+}
 
 axis2_status_t AXIS2_CALL
 axis2_write_body_part (axis2_mime_output_t *mime_output, axis2_env_t **env, 
                         axis2_byte_t **output_stream, int *output_stream_size, 
                         axis2_mime_body_part_t *part, axis2_char_t *boundary)
 {
-    axis2_byte_t *byte_buffer;
-    axis2_byte_t *byte_stream;
-    int size;
+    axis2_byte_t *byte_buffer = NULL;
+    axis2_byte_t *byte_stream = NULL;
+    int byte_buffer_size = 0;
+    axis2_byte_t *body_stream = NULL;
+    int body_stream_size = 0;
+    int size = 0;
         
     AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
     
-    axis2_char_2_byte(env, boundary, &byte_buffer, &size);
-    byte_stream = AXIS2_MALLOC((*env)->allocator, (size + 2) * sizeof(axis2_byte_t));
-    /*@TODO pls implement this part*/
-    /*
-    byte_stream[0] = AXIS2_MIME_CRLF_BYTE;
-    memcpy(&byte_stream[2], byte_buffer, size);
-    byte_stream[3] = AXIS2_MIME_CRLF_BYTE;
-    */
-    AXIS2_FREE((*env)->allocator, byte_buffer);
+    AXIS2_MIME_BODY_PART_WRITE_TO(part, env, &body_stream, &body_stream_size);
     
-    output_stream = &byte_stream;
-    *output_stream_size = size + 2;
+    size = byte_buffer_size + body_stream_size + 4;
+        
+    byte_stream = AXIS2_MALLOC((*env)->allocator, size * sizeof(axis2_byte_t));
+    if (!byte_stream)
+    {
+		AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+
+    byte_stream[0] = AXIS2_CRLF[0];
+    byte_stream[1] = AXIS2_CRLF[1];
+    
+    if (body_stream)
+    {
+        memcpy(byte_stream + 2, body_stream, body_stream_size);
+        AXIS2_FREE((*env)->allocator, body_stream);
+        body_stream = NULL;
+    }
+    
+    byte_stream[body_stream_size + 2] = AXIS2_CRLF[0];
+    byte_stream[body_stream_size + 3] = AXIS2_CRLF[1];
+    
+    if (byte_buffer)
+    {
+        memcpy(byte_stream + 2 + body_stream_size + 2, byte_buffer, byte_buffer_size);
+        AXIS2_FREE((*env)->allocator, byte_buffer);
+        byte_buffer = NULL;
+    }
+    
+    *output_stream = byte_stream;
+    *output_stream_size = size;
         
     return AXIS2_SUCCESS;    
     
 }
 
-
-   /* ========================== ================================*/
-
-
-/**
-     * This will write "--" to the end of last boundary
-     */
-
 axis2_status_t AXIS2_CALL
 axis2_write_finish_writing_mime (axis2_mime_output_t *mime_output, axis2_env_t **env, 
                         axis2_byte_t **output_stream, int *output_stream_size, axis2_char_t *boundary)
@@ -385,64 +471,70 @@
     AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
     
     axis2_char_2_byte(env, boundary, &byte_buffer, &size);
-    byte_stream = AXIS2_MALLOC((*env)->allocator, (size + 2) * sizeof(axis2_byte_t));
+    byte_stream = AXIS2_MALLOC((*env)->allocator, (size + 4) * sizeof(axis2_byte_t));
+    
+    byte_stream[0] = AXIS2_MIME_BOUNDARY_BYTE;
+    byte_stream[1] = AXIS2_MIME_BOUNDARY_BYTE;
+    if (byte_buffer)
+    {
+        memcpy (byte_stream + 2, byte_buffer, size);
+        AXIS2_FREE((*env)->allocator, byte_buffer);
+        byte_buffer = NULL;
+    }
+    
+    byte_stream[size + 2] = AXIS2_MIME_BOUNDARY_BYTE;
+    byte_stream[size + 3] = AXIS2_MIME_BOUNDARY_BYTE;
     
     AXIS2_FREE((*env)->allocator, byte_buffer);
     
-    output_stream = &byte_stream;
-    *output_stream_size = size + 2;
+    *output_stream = byte_stream;
+    *output_stream_size = size + 4;
         
     return AXIS2_SUCCESS;    
 
 }
-/*  public static void finishWritingMime(OutputStream outStream)
-            throws IOException {
-        outStream.write(new byte[]{45, 45});
-    }
-*/
-
 
 axis2_char_t * AXIS2_CALL
-axis2_mime_output_get_content_type_for_mime (axis2_mime_output_t *mime_output, axis2_env_t **env, 
-                        axis2_char_t *boundary, axis2_char_t *content_id, axis2_char_t *char_set_encoding, axis2_char_t *soap_content_type)
+axis2_mime_output_get_content_type_for_mime (axis2_mime_output_t *mime_output, 
+        axis2_env_t **env, 
+        axis2_char_t *boundary, 
+        axis2_char_t *content_id, 
+        axis2_char_t *char_set_encoding, 
+        axis2_char_t *soap_content_type)
 {
     axis2_char_t *content_type_string = NULL;
     
     AXIS2_ENV_CHECK(env, NULL);
     
     content_type_string = AXIS2_STRDUP("multipart/related", env);
-    AXIS2_STRACAT(content_type_string, "; ", env);       
-    AXIS2_STRACAT(content_type_string, "boundary=", env);
-    AXIS2_STRACAT(content_type_string, boundary, env);
-    AXIS2_STRACAT(content_type_string, "; ", env);
-    AXIS2_STRACAT(content_type_string, "type=\"application/xop+xml\"", env);
-    AXIS2_STRACAT(content_type_string, "; ", env);
-    AXIS2_STRACAT(content_type_string, "start=\"<", env);
-    AXIS2_STRACAT(content_type_string, content_id , env);
-    AXIS2_STRACAT(content_type_string, ">\"", env);
-    AXIS2_STRACAT(content_type_string, "; ", env);
-    AXIS2_STRACAT(content_type_string, "start-info=\"", env);
-    AXIS2_STRACAT(content_type_string, soap_content_type, env);
-    AXIS2_STRACAT(content_type_string, "\"", env);    
+    content_type_string = AXIS2_STRACAT(content_type_string, "; ", env);
+    if (boundary)
+    {
+        content_type_string = AXIS2_STRACAT(content_type_string, "boundary=", env);
+        content_type_string = AXIS2_STRACAT(content_type_string, boundary, env);
+        content_type_string = AXIS2_STRACAT(content_type_string, "; ", env);
+    }
+    content_type_string = AXIS2_STRACAT(content_type_string, "type=\"application/xop+xml\"", env);
+    content_type_string = AXIS2_STRACAT(content_type_string, "; ", env);
+    if (content_id)
+    {
+        content_type_string = AXIS2_STRACAT(content_type_string, "start=\"<", env);
+        content_type_string = AXIS2_STRACAT(content_type_string, content_id , env);
+        content_type_string = AXIS2_STRACAT(content_type_string, ">\"", env);
+        content_type_string = AXIS2_STRACAT(content_type_string, "; ", env);
+    }
+    if (soap_content_type)
+    {
+        content_type_string = AXIS2_STRACAT(content_type_string, "start-info=\"", env);
+        content_type_string = AXIS2_STRACAT(content_type_string, soap_content_type, env);
+        content_type_string = AXIS2_STRACAT(content_type_string, "\"; ", env);    
+    }
+    if (char_set_encoding)
+    {
+        content_type_string = AXIS2_STRACAT(content_type_string, "charset=\"", env);
+        content_type_string = AXIS2_STRACAT(content_type_string, char_set_encoding, env);
+        content_type_string = AXIS2_STRACAT(content_type_string, "\"", env);    
+    }
     
-    /*@TODO check this line*/
     return content_type_string;
 }
-
-/*
-    public static axis2_char_t *getContentTypeForMime(axis2_char_t *boundary, axis2_char_t *content_id, axis2_char_t *char_set_encoding, axis2_char_t *soap_content_type) {
-        StringBuffer sb = new StringBuffer();
-        sb.append("multipart/related");
-        sb.append("; ");
-        sb.append("boundary=");
-        sb.append(boundary);
-        sb.append("; ");
-        sb.append("type=\"application/xop+xml\"");
-        sb.append("; ");
-        sb.append("start=\"<" + content_id + ">\"");
-        sb.append("; ");
-        sb.append("start-info=\""+soap_content_type+"\"");
-        return sb.toString();
-    }
-}
-*/



Mime
View raw message