[prev in list] [next in list] [prev in thread] [next in thread] 

List:       wsf-c-commits
Subject:    [Wsf-c-commits] svn commit r20246 - trunk/wsf/php/src
From:       nandika () wso2 ! com
Date:       2008-07-31 10:24:26
Message-ID: E1KOVKc-0005IN-SI () wso2 ! org
[Download RAW message or body]

Author: nandika
Date: Thu Jul 31 03:24:26 2008
New Revision: 20246
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=20246

Log:
code updated to support caching

Modified:
   trunk/wsf/php/src/wsf.c
   trunk/wsf/php/src/wsf.h
   trunk/wsf/php/src/wsf_common.h
   trunk/wsf/php/src/wsf_util.c
   trunk/wsf/php/src/wsf_worker.c

Modified: trunk/wsf/php/src/wsf.c
URL: http://wso2.org/svn/browse/wso2/trunk/wsf/php/src/wsf.c?rev=20246&r1=20245&r2=20246&view=diff
==============================================================================
--- trunk/wsf/php/src/wsf.c	(original)
+++ trunk/wsf/php/src/wsf.c	Thu Jul 31 03:24:26 2008
@@ -34,6 +34,7 @@
 #include <axiom_soap.h>
 #include <axis2_http_transport.h>
 #include <axis2_addr.h>
+#include <axis2_const.h>
 #include <axiom_util.h>
 #include "wsf_client.h"
 #include "wsf_policy.h"
@@ -266,7 +267,12 @@
 STD_PHP_INI_ENTRY ("wsf.log_level", "4", PHP_INI_ALL, 
         OnUpdateLong, log_level, zend_wsf_globals, wsf_globals)
 STD_PHP_INI_ENTRY ("wsf.rm_db_dir", WSF_TMP, PHP_INI_ALL,
-    OnUpdateString, rm_db_dir, zend_wsf_globals, wsf_globals)  
+	    OnUpdateString, rm_db_dir, zend_wsf_globals, wsf_globals)  
+STD_PHP_INI_ENTRY ("wsf.attachment_cache_dir", WSF_TMP, PHP_INI_ALL,
+		OnUpdateString, attachment_cache_dir, zend_wsf_globals, wsf_globals)  
+STD_PHP_INI_ENTRY ("wsf.enable_attachment_caching", "0", PHP_INI_ALL, 
+	   OnUpdateLong, enable_attachment_caching, zend_wsf_globals, wsf_globals)
+
 PHP_INI_END () 
 /* }}} */ 
     
@@ -281,6 +287,8 @@
     wsf_globals->soap_uri = AXIOM_SOAP12_SOAP_ENVELOPE_NAMESPACE_URI;
     wsf_globals->rm_db_dir = NULL;
     wsf_globals->curr_ns_index = 0;
+	wsf_globals->attachment_cache_dir = NULL;
+	wsf_globals->enable_attachment_caching = 0;
 } 
 
 /* }}} */ 
@@ -671,9 +679,21 @@
         if (!ht) return;
 	/** add properties defined in API doc */
         wsf_client_add_properties (obj, ht TSRMLS_CC);
-
-
     }
+	if(WSF_GLOBAL(enable_attachment_caching))
+	{
+		axis2_svc_ctx_t *svc_ctx = NULL;
+		axis2_conf_ctx_t *conf_ctx = NULL;
+		axutil_param_t *cache_dir = NULL;
+		axis2_conf_t *conf = NULL;
+		svc_ctx = axis2_svc_client_get_svc_ctx (svc_client, env);
+		conf_ctx = axis2_svc_ctx_get_conf_ctx (svc_ctx, env);
+		conf = axis2_conf_ctx_get_conf (conf_ctx, env);
+
+		cache_dir = axutil_param_create (env, AXIS2_ATTACHMENT_DIR, 
+			axutil_strdup(env, WSF_GLOBAL(attachment_cache_dir)));
+		axis2_conf_add_param (conf, env, cache_dir);
+	}
 }
 /* }}} */ 
     
@@ -1461,6 +1481,8 @@
     
     svc_info = (wsf_svc_info_t *) (intern->ptr);
     
+	svc_info->attachment_cache_dir = WSF_GLOBAL(attachment_cache_dir);
+	svc_info->enable_attachment_caching = WSF_GLOBAL(enable_attachment_caching);
     php_worker = svc_info->php_worker;
     
     conf_ctx = wsf_worker_get_conf_ctx (php_worker, ws_env_svr);
@@ -1472,6 +1494,8 @@
         return;
     }
 
+	
+
     zend_is_auto_global ("_SERVER", sizeof ("_SERVER") - 1 TSRMLS_CC);
     
     wsf_request_info_init (&req_info);

Modified: trunk/wsf/php/src/wsf.h
URL: http://wso2.org/svn/browse/wso2/trunk/wsf/php/src/wsf.h?rev=20246&r1=20245&r2=20246&view=diff
==============================================================================
--- trunk/wsf/php/src/wsf.h	(original)
+++ trunk/wsf/php/src/wsf.h	Thu Jul 31 03:24:26 2008
@@ -100,6 +100,8 @@
     char *rm_db_dir;
     int curr_ns_index;
     int soap_version;
+	char *attachment_cache_dir;
+	int enable_attachment_caching;
 ZEND_END_MODULE_GLOBALS (wsf)
 
 ZEND_EXTERN_MODULE_GLOBALS (wsf)

Modified: trunk/wsf/php/src/wsf_common.h
URL: http://wso2.org/svn/browse/wso2/trunk/wsf/php/src/wsf_common.h?rev=20246&r1=20245&r2=20246&view=diff
==============================================================================
--- trunk/wsf/php/src/wsf_common.h	(original)
+++ trunk/wsf/php/src/wsf_common.h	Thu Jul 31 03:24:26 2008
@@ -327,6 +327,9 @@
   char *auth_password;
   /** http_auth_type */
   char* auth_type;
+
+  char *attachment_cache_dir;
+  int enable_attachment_caching;
 }
 wsf_svc_info_t;
 

Modified: trunk/wsf/php/src/wsf_util.c
URL: http://wso2.org/svn/browse/wso2/trunk/wsf/php/src/wsf_util.c?rev=20246&r1=20245&r2=20246&view=diff
==============================================================================
--- trunk/wsf/php/src/wsf_util.c	(original)
+++ trunk/wsf/php/src/wsf_util.c	Thu Jul 31 03:24:26 2008
@@ -353,6 +353,8 @@
 	svc_info->auth_type = WSF_PHP_AUTH_TYPE_BASIC;
 	svc_info->auth_user = NULL;
 	svc_info->auth_password = NULL;
+	svc_info->attachment_cache_dir = NULL;
+	svc_info->enable_attachment_caching =0;
 
     return svc_info;
 }
@@ -862,52 +864,62 @@
                             if (zend_hash_find (attach_ht, cid, strlen (cid) + 1, 
 								(void **) &tmp) == SUCCESS && Z_TYPE_PP (tmp) == IS_STRING) 
 							{
+                                /** detach this node */
+                                axiom_node_t *text_node = NULL;
+                                axiom_text_t *text = NULL;
+                                axiom_data_handler_t *data_handler = NULL;
+                                axiom_node_detach (node, env);
 
-                                void *binary_data = NULL;
-                                int binary_data_len = 0;
+                                tmp_node = axiom_node_get_first_child (payload_node, env);
+                                while (tmp_node) 
+								{
+                                    axiom_node_t *next_tmp_node = NULL;
+                                    next_tmp_node = axiom_node_get_next_sibling (tmp_node, env);
 
-                                binary_data_len = Z_STRLEN_PP (tmp);
-                                binary_data = AXIS2_MALLOC (env->allocator, 
-									sizeof (char) * binary_data_len);
+                                    axiom_node_free_tree(tmp_node, env);
 
-                                memcpy (binary_data, Z_STRVAL_PP (tmp), binary_data_len);
-                                if (binary_data) 
+                                    tmp_node = next_tmp_node;
+                                }
+								if(WSF_GLOBAL(enable_attachment_caching))
+								{	/** If attachment caching is enabled, user will set the file name
+									instead of the binary data */
+									axis2_char_t *filename = Z_STRVAL_PP(tmp);
+									if(axutil_file_handler_access(filename, AXIS2_R_OK))
+									{
+											data_handler = axiom_data_handler_create(env, filename, cnt_type);
+									}
+								}else
 								{
-                                    /** detach this node */
-                                    axiom_node_t *text_node = NULL;
-                                    axiom_text_t *text = NULL;
-                                    axiom_data_handler_t *data_handler = NULL;
-                                    axiom_node_detach (node, env);
+									void *binary_data = NULL;
+									int binary_data_len = 0;
 
-                                    tmp_node = axiom_node_get_first_child (payload_node, env);
-                                    while (tmp_node) 
-									{
-                                        axiom_node_t *next_tmp_node = NULL;
-                                        next_tmp_node = axiom_node_get_next_sibling (tmp_node, env);
+									binary_data_len = Z_STRLEN_PP (tmp);
+									binary_data = AXIS2_MALLOC (env->allocator, sizeof (char) * binary_data_len);
 
-                                        axiom_node_free_tree(tmp_node, env);
-
-                                        tmp_node = next_tmp_node;
-                                    }
+									memcpy (binary_data, Z_STRVAL_PP (tmp), binary_data_len);
+									if(binary_data)
+									{
+									/** attachment caching is not enabled, user provides binary data directly */
+										data_handler = axiom_data_handler_create (env, NULL, cnt_type);
 
-                                    data_handler = axiom_data_handler_create (env, NULL, cnt_type);
-                                    axiom_data_handler_set_binary_data (data_handler, env, binary_data,
-                                        binary_data_len);
-                                    text = axiom_text_create_with_data_handler
-                                        (env, payload_node, data_handler, &text_node);
+										axiom_data_handler_set_binary_data (data_handler, env, binary_data,
+											binary_data_len);
+									}
+								}
+                                text = axiom_text_create_with_data_handler
+                                    (env, payload_node, data_handler, &text_node);
 
-                                    if (enable_swa) 
-									{
-                                        axiom_text_set_is_swa(text, env, AXIS2_TRUE);
-                                    }
+                                if (enable_swa) 
+								{
+                                    axiom_text_set_is_swa(text, env, AXIS2_TRUE);
+                                }
 
-                                    if (enable_mtom == AXIS2_FALSE) 
-									{
-                                        axiom_text_set_optimize (text, env,
-                                            AXIS2_FALSE);
-                                    }
-                                    return;
+                                if (enable_mtom == AXIS2_FALSE) 
+								{
+                                    axiom_text_set_optimize (text, env,
+                                        AXIS2_FALSE);
                                 }
+                                return;
                             }
                         }
                     }
@@ -952,11 +964,22 @@
                     char *cnt_type = NULL;
                     char *data = NULL;
                     int data_len = 0;
+					if(!axiom_data_handler_get_cached(data_handler, env))
+					{
+						axiom_data_handler_read_from (data_handler, env, &data, &data_len);
+	                    add_assoc_stringl (cid2str, cid, data, data_len, 1);
+					}else
+					{
+						data = axiom_data_handler_get_file_name(data_handler, env);
+						if(data)
+						{
+							data_len = strlen(data);
+						}
+						add_assoc_stringl(cid2str, cid, data, data_len, 1);
+					}
 
-                    axiom_data_handler_read_from (data_handler, env, &data, &data_len);
-                    cnt_type = axiom_data_handler_get_content_type(data_handler, env);
-                    add_assoc_stringl (cid2str, cid, data, data_len, 1);
-                    attachments_found = 1;
+					cnt_type = axiom_data_handler_get_content_type(data_handler, env);
+					attachments_found = 1;
                     if (cnt_type) {
                         add_assoc_stringl (cid2contentType, cid,
                             cnt_type, strlen (cnt_type), 1);

Modified: trunk/wsf/php/src/wsf_worker.c
URL: http://wso2.org/svn/browse/wso2/trunk/wsf/php/src/wsf_worker.c?rev=20246&r1=20245&r2=20246&view=diff
==============================================================================
--- trunk/wsf/php/src/wsf_worker.c	(original)
+++ trunk/wsf/php/src/wsf_worker.c	Thu Jul 31 03:24:26 2008
@@ -182,16 +182,16 @@
     AXIS2_FREE (env->allocator, worker);
 }
 
-static void wsf_worker_send_mtom_message(
-	wsf_response_info_t *response,
-	const axutil_env_t * env,
-	axutil_array_list_t *mime_parts TSRMLS_DC)
-{
-	int i = 0;
-	axiom_mime_part_t *mime_part = NULL;
-	axis2_status_t status = AXIS2_SUCCESS;
-	/*int written = 0;*/
-	int len = 0;    
+static void wsf_worker_send_mtom_message(
+	wsf_response_info_t *response,
+	const axutil_env_t * env,
+	axutil_array_list_t *mime_parts TSRMLS_DC)
+{
+	int i = 0;
+	axiom_mime_part_t *mime_part = NULL;
+	axis2_status_t status = AXIS2_SUCCESS;
+	/*int written = 0;*/
+	int len = 0;    
 	if(response && response->http_status_code_name)
 	{
 		char status_line[100];
@@ -204,19 +204,83 @@
 			content_type = emalloc(strlen (response->content_type) * sizeof (char) + 20);
 			sprintf (content_type, "Content-Type: %s", response->content_type);
 			sapi_add_header (content_type, strlen (content_type), 1);
-		}
-	}
-	if(mime_parts)
-	{
-		for(i = 0; i < axutil_array_list_size(mime_parts, env); i++)
-		{
-			mime_part = (axiom_mime_part_t *)axutil_array_list_get(mime_parts, env, i);
-			if((mime_part->type) == AXIOM_MIME_PART_BUFFER)
-			{
-				php_write(mime_part->part, mime_part->part_size TSRMLS_CC);
-			}    
-		}
-	}
+		}
+	}
+	if(mime_parts)
+	{
+		for(i = 0; i < axutil_array_list_size(mime_parts, env); i++)
+		{
+			mime_part = (axiom_mime_part_t *)axutil_array_list_get(mime_parts, env, i);
+			if((mime_part->type) == AXIOM_MIME_PART_BUFFER)
+			{
+				php_write(mime_part->part, mime_part->part_size TSRMLS_CC);
+			}
+			if((mime_part->type) == AXIOM_MIME_PART_FILE)
+			{
+				int count = 0;     
+				int len = 0;
+				FILE *f = NULL;
+				axis2_byte_t *output_buffer = NULL;                
+				int output_buffer_size = 0;
+
+				f = fopen(mime_part->file_name, "rb");
+				if (!f)
+				{
+					AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error opening file %s for reading",
+						mime_part->file_name);
+					return ;
+				}
+				if(mime_part->part_size > AXIS2_MTOM_OUTPUT_BUFFER_SIZE)
+				{
+					output_buffer_size = AXIS2_MTOM_OUTPUT_BUFFER_SIZE;
+				}
+				else
+				{
+					output_buffer_size = mime_part->part_size;
+				}
+				output_buffer =  AXIS2_MALLOC(env->allocator, 
+					(output_buffer_size + 1) * sizeof(axis2_char_t));
+
+				do
+				{
+					count = (int)fread(output_buffer, 1, output_buffer_size + 1, f);
+					if (ferror(f))
+					{
+						AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error in reading file containing the attachment");
+						if (output_buffer)
+						{
+							AXIS2_FREE(env->allocator, output_buffer);
+							output_buffer = NULL;
+						}
+						fclose(f);
+						return;
+					}
+
+					if(count > 0)
+					{
+						php_write(output_buffer, count TSRMLS_CC);
+						
+					}
+					else
+					{
+						if (output_buffer)
+						{
+							AXIS2_FREE(env->allocator, output_buffer);
+							output_buffer = NULL;
+						}
+						fclose(f);
+						return;
+					}   
+					memset(output_buffer, 0, output_buffer_size);    
+				}
+				while(!feof(f));
+
+				fclose(f);
+				AXIS2_FREE(env->allocator, output_buffer);
+
+			}
+		}
+	}
 }
 
 static void 
@@ -344,6 +408,14 @@
 	op = wsf_worker_find_op_and_params_with_location_and_method(env, 
 					request->request_method, svc_info,request,msg_ctx);
 
+	if(svc_info->enable_attachment_caching)
+	{
+		axutil_param_t *cache_dir = NULL;
+		cache_dir = axutil_param_create(env, AXIS2_ATTACHMENT_DIR, 
+			axutil_strdup(env, svc_info->attachment_cache_dir));
+		axis2_svc_add_param(svc_info->svc, env, cache_dir);
+	}
+
 	if(op)
 	{
 		axis2_msg_ctx_set_op(msg_ctx, env, op);
@@ -473,17 +545,17 @@
         if (out_msg_ctx)
         {
 			
-			do_mtom = axis2_msg_ctx_get_doing_mtom(out_msg_ctx, env);
-			if(do_mtom)
-			{
-				axutil_array_list_t *mime_parts = NULL;
-				mime_parts = axis2_msg_ctx_get_mime_parts(out_msg_ctx, env);
-				if(!mime_parts)
-				{
-					do_mtom = 0;
-				}
-				wsf_worker_send_mtom_message(response, env, mime_parts TSRMLS_CC);
-			}
+			do_mtom = axis2_msg_ctx_get_doing_mtom(out_msg_ctx, env);
+			if(do_mtom)
+			{
+				axutil_array_list_t *mime_parts = NULL;
+				mime_parts = axis2_msg_ctx_get_mime_parts(out_msg_ctx, env);
+				if(!mime_parts)
+				{
+					do_mtom = 0;
+				}
+				wsf_worker_send_mtom_message(response, env, mime_parts TSRMLS_CC);
+			}
 
             axis2_msg_ctx_free(out_msg_ctx, env);
             msg_ctx_map[AXIS2_WSDL_MESSAGE_LABEL_OUT] = NULL;

_______________________________________________
Wsf-c-commits mailing list
Wsf-c-commits@wso2.org
http://mailman.wso2.org/cgi-bin/mailman/listinfo/wsf-c-commits
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic