axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nand...@apache.org
Subject svn commit: r439282 - in /webservices/axis2/trunk/c/util: include/axis2_properties.h src/properties.c test/unit/util/util_test.c test/unit/util/util_test.h
Date Fri, 01 Sep 2006 12:00:35 GMT
Author: nandika
Date: Fri Sep  1 05:00:34 2006
New Revision: 439282

URL: http://svn.apache.org/viewvc?rev=439282&view=rev
Log:
adding files in jira 231. thanks to dimuthu

Added:
    webservices/axis2/trunk/c/util/include/axis2_properties.h
    webservices/axis2/trunk/c/util/src/properties.c
Modified:
    webservices/axis2/trunk/c/util/test/unit/util/util_test.c
    webservices/axis2/trunk/c/util/test/unit/util/util_test.h

Added: webservices/axis2/trunk/c/util/include/axis2_properties.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/include/axis2_properties.h?rev=439282&view=auto
==============================================================================
--- webservices/axis2/trunk/c/util/include/axis2_properties.h (added)
+++ webservices/axis2/trunk/c/util/include/axis2_properties.h Fri Sep  1 05:00:34 2006
@@ -0,0 +1,165 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef AXIS2_PROPERTIES_H
+#define AXIS2_PROPERTIES_H
+
+#include <axis2_utils_defines.h>
+#include <axis2_error.h>
+#include <axis2_env.h>
+#include <axis2_hash.h>
+#include <stdio.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+    
+typedef struct axis2_properties axis2_properties_t;
+typedef struct axis2_properties_ops axis2_properties_ops_t;
+    
+/**
+ * @defgroup axis2_properties properties
+ * @ingroup axis2_util 
+ * @{
+ */
+
+/** 
+ * @brief properties ops struct
+ * Encapsulator struct for ops of axis2_properties_ops
+ */
+AXIS2_DECLARE_DATA struct axis2_properties_ops
+{
+   /**
+    * free w2c_properties.
+    * @param  properties pointer to properties struct
+    * @param  env Environment. MUST NOT be NULL
+    * @return status of the op. AXIS2_SUCCESS on success
+    *     else AXIS2_FAILURE
+    */
+    axis2_status_t (AXIS2_CALL *
+    free) (axis2_properties_t *properties, 
+            const axis2_env_t *env);
+
+   /**
+    * get string value for property with specified key.
+    * @param  properties pointer to properties struct
+    * @param  env Environment. MUST NOT be NULL
+    * @param  key MUST NOT be NULL
+    * @return value of the property
+    */
+    axis2_char_t* (AXIS2_CALL *
+    get_property) (axis2_properties_t *properties,
+                const axis2_env_t *env,
+                axis2_char_t *key);
+   /**
+    * set a property ( key, value) pair.
+    * @param  properties pointer to properties struct
+    * @param  env Environment. MUST NOT be NULL
+    * @param  key Property Key. MUST NOT be NULL
+    * @param  value Property Value
+    * @return status of the op. AXIS2_SUCCESS on success
+    *     else AXIS2_FAILURE
+    */
+    axis2_status_t (AXIS2_CALL *
+    set_property) (axis2_properties_t *properties,
+                 const axis2_env_t *env,
+                 axis2_char_t *key,
+                 axis2_char_t *value);
+   /**
+    * retrieve the hash with all the properties
+    * @param  properties pointer to properties struct
+    * @param  env Environment. MUST NOT be NULL
+    * @return hash (key,value)
+    */
+    axis2_hash_t* (AXIS2_CALL *
+    get_all)( axis2_properties_t *properties,
+                const axis2_env_t *env);
+
+   /**
+    * load properties
+    * @param  properties pointer to properties struct
+    * @param  env Environment. MUST NOT be NULL
+    * @param  input Input Stream. MUST NOT be NULL
+    * @return status of the op. AXIS2_SUCCESS on success
+    *     else AXIS2_FAILURE
+    */
+    axis2_status_t (AXIS2_CALL *
+    load)(axis2_properties_t *properties,
+                 const axis2_env_t *env,
+                 FILE *input);
+  
+   /**
+    * store properties
+    * @param  properties pointer to properties struct
+    * @param  env Environment. MUST NOT be NULL
+    * @param  ouput Output Stream. MUST NOT be NULL
+    * @return status of the op. AXIS2_SUCCESS on success
+    *     else AXIS2_FAILURE
+    */
+    axis2_status_t (AXIS2_CALL *
+    store)(axis2_properties_t *properites,
+                const axis2_env_t *env,
+                FILE *output);
+};
+    
+     
+/** 
+ * @brief
+ */ 
+AXIS2_DECLARE_DATA struct axis2_properties
+{
+   axis2_properties_ops_t *ops;
+};
+
+/**
+ * create new properties
+ * @return properties newly created properties
+ */
+AXIS2_EXTERN axis2_properties_t * AXIS2_CALL
+axis2_properties_create(const axis2_env_t *env);
+
+/*************************** Function macros **********************************/
+
+#define AXIS2_PROPERTIES_FREE(properties, env) \
+      ((properties)->ops->free (properties, env))
+
+#define AXIS2_PROPERTIES_GET_PROPERTY(properties, env, key) \
+      ((properties)->ops->get_property(properties, env, key))  
+
+#define AXIS2_PROPERTIES_SET_PROPERTY(properties, env, key, value) \
+      ((properties)->ops->set_property(properties, env, key, value))  
+
+#define AXIS2_PROPERTIES_GET_ALL(properties, env) \
+      ((properties)->ops->get_all(properties, env))  
+
+#define AXIS2_PROPERTIES_LOAD(properties, env, input) \
+      ((properties)->ops->load(properties, env, input)) 
+
+#define AXIS2_PROPERTIES_STORE(properties, env, output) \
+      ((properties)->ops->store(properties, env, output))
+         
+/*************************** End of function macros ***************************/
+
+
+
+/** @} */
+    
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* AXIS2_PROPERTIES_H */

Added: webservices/axis2/trunk/c/util/src/properties.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/src/properties.c?rev=439282&view=auto
==============================================================================
--- webservices/axis2/trunk/c/util/src/properties.c (added)
+++ webservices/axis2/trunk/c/util/src/properties.c Fri Sep  1 05:00:34 2006
@@ -0,0 +1,392 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ 
+#include <axis2_properties.h>
+#include <axis2_string.h>
+#include <axis2_utils.h>
+
+typedef struct axis2_properties_impl
+{
+    axis2_properties_t properties;
+    axis2_hash_t *prop_hash; 
+}axis2_properties_impl_t;
+
+#define AXIS2_INTF_TO_IMPL(properties) \
+    ((axis2_properties_impl_t *) properties)
+
+axis2_status_t AXIS2_CALL
+axis2_properties_free (axis2_properties_t *properties, 
+                    const axis2_env_t *env); 
+
+axis2_char_t* AXIS2_CALL
+axis2_properties_get_property(axis2_properties_t *properties,
+                            const axis2_env_t *env,
+                            axis2_char_t *key);
+
+axis2_hash_t* AXIS2_CALL
+axis2_properties_get_all(axis2_properties_t *properties,
+                            const axis2_env_t *env);
+
+axis2_status_t AXIS2_CALL
+axis2_properties_set_property(axis2_properties_t *properties,
+                            const axis2_env_t *env,
+                            axis2_char_t *key,
+                            axis2_char_t *value);
+
+axis2_status_t AXIS2_CALL
+axis2_properties_load(axis2_properties_t *properties,
+                            const axis2_env_t *env,
+                            FILE *input);
+
+axis2_status_t AXIS2_CALL
+axis2_properties_store(axis2_properties_t *properties,
+                            const axis2_env_t *env,
+                            FILE *output);
+
+axis2_char_t*
+axis2_properties_read_next ( axis2_char_t* cur );
+
+axis2_char_t*
+axis2_properties_trunk_and_dup( axis2_char_t* start, axis2_char_t* end,
+                                   const axis2_env_t* env );
+
+axis2_char_t*
+axis2_properties_read( FILE* input,
+                             const axis2_env_t* env );
+
+/************************** End of function prototypes ************************/
+
+axis2_properties_t *AXIS2_CALL 
+axis2_properties_create(const axis2_env_t *env)
+{
+    axis2_properties_impl_t *properties_impl = NULL;
+    
+    AXIS2_ENV_CHECK(env, NULL);
+   
+    properties_impl = (axis2_properties_impl_t *) AXIS2_MALLOC(env->allocator, 
+        sizeof(axis2_properties_impl_t));
+   
+    if(NULL == properties_impl)
+    {
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); 
+        return NULL;
+    }
+    properties_impl->prop_hash= axis2_hash_make(env);
+    
+    properties_impl->properties.ops = 
+      AXIS2_MALLOC (env->allocator, sizeof(axis2_properties_ops_t));
+    if(NULL == properties_impl->properties.ops)
+    {
+        axis2_properties_free(&(properties_impl->properties), env);
+      AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+    
+    properties_impl->properties.ops->free =  axis2_properties_free;
+    properties_impl->properties.ops->get_property= axis2_properties_get_property;
+    properties_impl->properties.ops->set_property= axis2_properties_set_property;
+    properties_impl->properties.ops->load= axis2_properties_load;
+    properties_impl->properties.ops->store= axis2_properties_store;
+    properties_impl->properties.ops->get_all= axis2_properties_get_all;
+    return &(properties_impl->properties);
+}
+
+/***************************Function implementation****************************/
+
+axis2_status_t AXIS2_CALL 
+axis2_properties_free (axis2_properties_t *properties, 
+                    const axis2_env_t *env)
+{
+    axis2_properties_impl_t *properties_impl = NULL;
+    axis2_char_t *key = NULL;
+    axis2_char_t *value = NULL;
+    axis2_hash_index_t *hi = NULL;
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    properties_impl = AXIS2_INTF_TO_IMPL(properties);
+    
+    if(properties_impl->prop_hash)
+    {
+        for (hi = axis2_hash_first( properties_impl->prop_hash, env);
+                            hi; hi = axis2_hash_next(env, hi))
+        {
+            axis2_hash_this(hi, (void*)&key, NULL, (void*)&value);
+            if (key)
+                AXIS2_FREE ( env-> allocator, key);
+            if (value)
+                AXIS2_FREE ( env-> allocator, value);
+        }
+        axis2_hash_free( properties_impl->prop_hash, env);
+    }
+    
+    if(properties_impl->properties.ops)
+    {
+        AXIS2_FREE(env->allocator, properties_impl->properties.ops);
+        properties_impl->properties.ops = NULL;
+    }
+    
+    if(properties_impl)
+    {
+        AXIS2_FREE(env->allocator, properties_impl);
+        properties_impl = NULL;
+    }
+    return AXIS2_SUCCESS;
+}
+
+axis2_char_t* AXIS2_CALL
+axis2_properties_get_property(axis2_properties_t *properties,
+                            const axis2_env_t *env,
+                            axis2_char_t *key)
+{
+    axis2_properties_impl_t *properties_impl = NULL;
+
+    AXIS2_ENV_CHECK(env, NULL);
+    AXIS2_PARAM_CHECK(env-> error, key, NULL);
+    
+    properties_impl = AXIS2_INTF_TO_IMPL(properties);
+
+    return axis2_hash_get( properties_impl-> prop_hash,
+            key, AXIS2_HASH_KEY_STRING);
+}
+
+axis2_status_t AXIS2_CALL
+axis2_properties_set_property(axis2_properties_t *properties,
+                            const axis2_env_t *env,
+                            axis2_char_t *key,
+                            axis2_char_t *value)
+{
+    axis2_properties_impl_t *properties_impl = NULL;
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env-> error, key, AXIS2_FAILURE);
+    
+    properties_impl = AXIS2_INTF_TO_IMPL(properties);
+
+    axis2_hash_set( properties_impl-> prop_hash, key,
+            AXIS2_HASH_KEY_STRING, value);
+    return AXIS2_SUCCESS;
+}
+
+axis2_hash_t* AXIS2_CALL
+axis2_properties_get_all(axis2_properties_t *properties,
+                            const axis2_env_t *env)
+{
+    axis2_properties_impl_t *properties_impl = NULL;
+    AXIS2_ENV_CHECK(env, NULL);
+    properties_impl = AXIS2_INTF_TO_IMPL(properties);
+
+    return properties_impl-> prop_hash;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_properties_store(axis2_properties_t *properties,
+                            const axis2_env_t *env,
+                            FILE *output)
+{
+    axis2_properties_impl_t *properties_impl = NULL;
+    axis2_hash_index_t *hi = NULL;
+    axis2_char_t *key = NULL;
+    axis2_char_t *value = NULL;
+    
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env-> error, output, AXIS2_FAILURE);
+    properties_impl = AXIS2_INTF_TO_IMPL(properties);
+
+
+    if(properties_impl->prop_hash)
+    {
+        for (hi = axis2_hash_first( properties_impl->prop_hash, env);
+                            hi; hi = axis2_hash_next(env, hi))
+        {
+            axis2_hash_this(hi, (void*)&key, NULL, (void*)&value);
+            if (key)
+            {
+                if (NULL == value)
+                {
+                    value = AXIS2_STRDUP("", env); 
+                }
+                fprintf( output, "%s=%s\n", key, value);
+            }
+        }
+    }
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_properties_load(axis2_properties_t *properties,
+                            const axis2_env_t *env,
+                            FILE *input)
+{
+    axis2_properties_impl_t *properties_impl = NULL;
+    axis2_char_t *cur = NULL;
+    axis2_char_t *tag = NULL;
+    const int LINE_STARTED = -1;
+    const int LINE_MIDWAY= 0;
+    const int EQUAL_FOUND = 1;
+    const int LINE_HALFWAY= 2;
+    axis2_char_t *key = NULL;
+    axis2_hash_t *prop_hash = NULL;
+    axis2_char_t *buffer = NULL;
+    axis2_char_t loginfo[1024];
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env-> error, input, AXIS2_FAILURE);
+
+    properties_impl = AXIS2_INTF_TO_IMPL(properties);
+    prop_hash = properties_impl-> prop_hash;
+
+    buffer = axis2_properties_read(input,env );
+
+    if ( buffer == NULL )
+    {
+        sprintf( loginfo, "error in reading file\n");
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+                                            loginfo);
+        AXIS2_FREE ( env-> allocator, buffer );
+        return AXIS2_FAILURE;
+    }
+
+
+    int status = LINE_STARTED;
+    
+    for (cur =axis2_properties_read_next(buffer); *cur ;
+                       cur = axis2_properties_read_next( ++cur) )
+    {
+        if (*cur == '\r' )
+        {
+            *cur='\0';
+        }
+        else if ( *cur != '\0' && *cur != '\n' && status == LINE_STARTED
)
+        {
+            tag = cur;
+            status = LINE_MIDWAY;
+        }
+        /* equal found just create a property */
+        else if ( *cur =='=' &&  status == LINE_MIDWAY)
+        {
+            *cur = '\0';
+            if ( status != LINE_MIDWAY )
+            {
+                sprintf( loginfo, "equal apear in wrong place around %s\n",tag);
+                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+                                            loginfo);
+                AXIS2_FREE ( env-> allocator, buffer );
+                return AXIS2_FAILURE;
+            }
+            status = EQUAL_FOUND;
+            key =  axis2_properties_trunk_and_dup ( tag, cur, env );
+        }
+        /* right next to the equal found */
+        else if ( status == EQUAL_FOUND )
+        {
+            tag = cur;
+            status = LINE_HALFWAY;
+        }
+        
+        else if ( *cur =='\n' )
+        {
+            *cur ='\0';
+            if ( status == LINE_HALFWAY )
+            {
+                 tag =  axis2_properties_trunk_and_dup ( tag, cur, env );
+                 axis2_hash_set( prop_hash,  
+                                  key, AXIS2_HASH_KEY_STRING, tag);
+            }
+            status = LINE_STARTED;
+        }
+    }
+    if (status == LINE_HALFWAY )
+    {
+         *cur ='\0';
+         tag =  axis2_properties_trunk_and_dup ( tag, cur, env );
+         axis2_hash_set( prop_hash,  
+                           key, AXIS2_HASH_KEY_STRING, tag);
+         status = LINE_STARTED;
+    }
+    if ( status != LINE_STARTED )
+    {
+         sprintf( loginfo, "error parsing properties\n");
+         AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+                                            loginfo);
+         AXIS2_FREE ( env-> allocator, buffer );
+         return AXIS2_FAILURE;
+    }
+    AXIS2_FREE ( env-> allocator, buffer );
+    return AXIS2_SUCCESS;
+}
+
+
+axis2_char_t*
+axis2_properties_read_next ( axis2_char_t* cur )
+{
+   /* ignore comment */
+   if ( *cur == '#' )
+   {
+       for ( ;*cur !='\n' && *cur !='\0'; cur ++ );
+   }
+   /* check '\\''\n' case */
+   if ( *cur == '\\' && *(cur+1) == '\n' )
+   {
+       /* ignore two axis2_char_ts */
+       *(cur++) = ' ';
+       *(cur++) = ' ';
+   }
+   return cur;
+}
+
+axis2_char_t*
+axis2_properties_trunk_and_dup( axis2_char_t* start, axis2_char_t* end,
+                                   const axis2_env_t* env )
+{
+    for ( ; *start == ' '; start ++ ); /* remove front spaces */
+    for ( end --; *end == ' '; end -- ); /* remove rear spaces */
+    *(++end ) = '\0';
+    start = (axis2_char_t*)AXIS2_STRDUP ( start, env );
+    return start;
+}
+
+axis2_char_t*
+axis2_properties_read( FILE* input,
+                             const axis2_env_t* env )
+{
+    const int MAX_SIZE=1000;
+    int nread = 0;
+    axis2_char_t* out_stream = NULL;
+    int ncount = 0;
+
+    out_stream = (axis2_char_t*) AXIS2_MALLOC ( env-> allocator,
+                                   sizeof(axis2_char_t)* MAX_SIZE );
+    if (out_stream == NULL )
+    {
+        return NULL;
+    }
+
+    do{
+        nread = fread ( out_stream + ncount, sizeof(axis2_char_t), MAX_SIZE, input);
+        ncount += nread;
+        out_stream = (axis2_char_t*) AXIS2_REALLOC( env-> allocator, out_stream,
+                    sizeof(axis2_char_t)* (MAX_SIZE + ncount ) );
+        if ( out_stream == NULL )
+        {
+            return NULL;
+        }
+    }
+    while ( nread == MAX_SIZE );
+
+    out_stream[ncount] = '\0';
+    return out_stream;
+}
+

Modified: webservices/axis2/trunk/c/util/test/unit/util/util_test.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/test/unit/util/util_test.c?rev=439282&r1=439281&r2=439282&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/test/unit/util/util_test.c (original)
+++ webservices/axis2/trunk/c/util/test/unit/util/util_test.c Fri Sep  1 05:00:34 2006
@@ -41,8 +41,6 @@
     SUITE_ADD_TEST(suite, Testaxis2_uri_get_path); 
     /* Samisa - need to remove this as we run make check before make install
     SUITE_ADD_TEST(suite, Testaxis2_dir_handler_list_dir); */
-    SUITE_ADD_TEST(suite, Test_properties); 
-    SUITE_ADD_TEST(suite, Test_date_time); 
 
     return suite;
 }

Modified: webservices/axis2/trunk/c/util/test/unit/util/util_test.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/test/unit/util/util_test.h?rev=439282&r1=439281&r2=439282&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/test/unit/util/util_test.h (original)
+++ webservices/axis2/trunk/c/util/test/unit/util/util_test.h Fri Sep  1 05:00:34 2006
@@ -29,8 +29,6 @@
 #include "util_url_test.h"
 #include "util_string_test.h"
 #include "util_uri_test.h"
-#include "util_properties_test.h"
-#include "util_date_time_test.h"
 
 CuSuite* axis2_utilGetSuite();
 



---------------------------------------------------------------------
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