You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by da...@apache.org on 2006/06/06 13:30:20 UTC
svn commit: r412095 - in /webservices/axis2/trunk/c/util: ./ include/ src/
test/unit/util/ test/util/
Author: damitha
Date: Tue Jun 6 04:30:20 2006
New Revision: 412095
URL: http://svn.apache.org/viewvc?rev=412095&view=rev
Log:
Added some utility function to string.c like axis2_strndup, axis2_strmemdup, axis2_memchr,
axis2_strcat. Wrote some tests to test these new functions. added new function to
hash.c call contains_key.
Modified:
webservices/axis2/trunk/c/util/configure.ac
webservices/axis2/trunk/c/util/include/axis2_hash.h
webservices/axis2/trunk/c/util/include/axis2_qname.h
webservices/axis2/trunk/c/util/include/axis2_string.h
webservices/axis2/trunk/c/util/src/hash.c
webservices/axis2/trunk/c/util/src/string.c
webservices/axis2/trunk/c/util/src/string_util.c
webservices/axis2/trunk/c/util/src/url.c
webservices/axis2/trunk/c/util/test/unit/util/util_string_test.c
webservices/axis2/trunk/c/util/test/unit/util/util_string_test.h
webservices/axis2/trunk/c/util/test/unit/util/util_test.c
webservices/axis2/trunk/c/util/test/util/test_util.c
Modified: webservices/axis2/trunk/c/util/configure.ac
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/configure.ac?rev=412095&r1=412094&r2=412095&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/configure.ac (original)
+++ webservices/axis2/trunk/c/util/configure.ac Tue Jun 6 04:30:20 2006
@@ -23,7 +23,7 @@
AC_CHECK_LIB(z, inflate)
#CFLAGS="$CFLAGS -ansi -Wall -D_LARGEFILE64_SOURCE -Wno-implicit-function-declaration"
-CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE"
+CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE -g"
if test "$GCC" = "yes"; then
CFLAGS="$CFLAGS -ansi -Wall -Wno-implicit-function-declaration -Werror"
fi
Modified: webservices/axis2/trunk/c/util/include/axis2_hash.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/include/axis2_hash.h?rev=412095&r1=412094&r2=412095&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/include/axis2_hash.h (original)
+++ webservices/axis2/trunk/c/util/include/axis2_hash.h Tue Jun 6 04:30:20 2006
@@ -209,7 +209,19 @@
, axis2_ssize_t klen, const void *h1_val, const void *h2_val
, const void *data), const void *data);
-
+/**
+ * Query whether the hash table provided as parameter contains the
+ * key provided as parameter.
+ *
+ * @param ht hash table to be queried for key
+ * @return return whether hash table contains key
+ */
+AXIS2_EXTERN axis2_bool_t AXIS2_CALL
+axis2_hash_contains_key (
+ axis2_hash_t *ht,
+ const axis2_env_t *env,
+ const axis2_char_t *key);
+
/**
* @param ht hash table to be freed
* @param env The environment to use for hash table
Modified: webservices/axis2/trunk/c/util/include/axis2_qname.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/include/axis2_qname.h?rev=412095&r1=412094&r2=412095&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/include/axis2_qname.h (original)
+++ webservices/axis2/trunk/c/util/include/axis2_qname.h Tue Jun 6 04:30:20 2006
@@ -135,7 +135,7 @@
/**
- * returns a newly created qname using a string genarated form
+ * returns a newly created qname using a string genarated from
* axis2_qname_to_string method
* freeing the returned qname is users responsibility
*/
Modified: webservices/axis2/trunk/c/util/include/axis2_string.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/include/axis2_string.h?rev=412095&r1=412094&r2=412095&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/include/axis2_string.h (original)
+++ webservices/axis2/trunk/c/util/include/axis2_string.h Tue Jun 6 04:30:20 2006
@@ -37,6 +37,41 @@
axis2_strdup (const void *ptr,
const axis2_env_t *env);
+ /**
+ * duplicate the first n characters of a string into memory allocated
+ * the new string will be null-terminated
+ * @param ptr The string to duplicate
+ * @param n The number of characters to duplicate
+ * @return The new string
+ */
+ AXIS2_EXTERN void* AXIS2_CALL
+ axis2_strndup (
+ const void *ptr,
+ int n,
+ const axis2_env_t *env );
+
+ /**
+ * Create a null-terminated string by making a copy of a sequence
+ * of characters and appending a null byte
+ * @param ptr The block of characters to duplicate
+ * @param n The number of characters to duplicate
+ * @return The new string
+ * @remark This is a faster alternative to axis2_strndup, for use
+ * when you know that the string being duplicated really
+ * has 'n' or more characters. If the string might contain
+ * fewer characters, use axis2_strndup.
+ */
+ AXIS2_EXTERN void * AXIS2_CALL
+ axis2_strmemdup(const void *ptr,
+ size_t n,
+ const axis2_env_t *env);
+
+ AXIS2_EXTERN void * AXIS2_CALL
+ memchr (
+ const void *ptr,
+ int c,
+ size_t n);
+
AXIS2_EXTERN int AXIS2_CALL
axis2_strcmp (const axis2_char_t * s1,
const axis2_char_t * s2);
@@ -61,7 +96,15 @@
axis2_stracat(const axis2_char_t *s1,
const axis2_char_t *s2,
const axis2_env_t *env);
-
+
+ /**
+ * Concatenate multiple strings, allocating memory
+ * @param ... The strings to concatenate. The final string must be NULL
+ * @return The new string
+ */
+ AXIS2_DECLARE_NONSTD(axis2_char_t *)
+ axis2_strcat(axis2_env_t *env, ...);
+
AXIS2_EXTERN axis2_char_t * AXIS2_CALL
axis2_strstr (const axis2_char_t *heystack,
const axis2_char_t *needle);
@@ -87,8 +130,18 @@
AXIS2_EXTERN axis2_char_t* AXIS2_CALL
axis2_strtrim(axis2_char_t *_s,
const axis2_char_t *_trim);
+
#define AXIS2_STRDUP(pts, env) \
axis2_strdup(pts, env)
+
+#define AXIS2_STRNDUP(pts, n, env) \
+ axis2_strndup(pts, n, env)
+
+#define AXIS2_STRMEMDUP(pts, n, env) \
+ axis2_strmemdup(pts, n, env)
+
+#define AXIS2_MEMCHR(pts, c, n) \
+ axis2_memchr(pts, c, n)
#define AXIS2_STRCMP(s1, s2) \
axis2_strcmp(s1, s2)
@@ -104,6 +157,9 @@
#define AXIS2_STRACAT(s1, s2, env) \
axis2_stracat(s1, s2, env)
+
+#define AXIS2_STRCAT(env, ...) \
+ axis2_strcat(env, ...)
#define AXIS2_STRSTR(s1, s2) \
axis2_strstr(s1, s2)
Modified: webservices/axis2/trunk/c/util/src/hash.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/src/hash.c?rev=412095&r1=412094&r2=412095&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/src/hash.c (original)
+++ webservices/axis2/trunk/c/util/src/hash.c Tue Jun 6 04:30:20 2006
@@ -16,9 +16,7 @@
#include "axis2_hash.h"
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
+#include <axis2_string.h>
/*
* The internal form of a hash table.
@@ -504,6 +502,30 @@
}
return res;
}
+
+AXIS2_EXTERN axis2_bool_t AXIS2_CALL
+axis2_hash_contains_key (
+ axis2_hash_t *ht,
+ const axis2_env_t *env,
+ const axis2_char_t *key)
+{
+ axis2_hash_index_t *i = NULL;
+
+ AXIS2_ENV_CHECK(env, AXIS2_FALSE);
+
+ for (i = axis2_hash_first (ht, env); i; i = axis2_hash_next (env, i))
+ {
+ const void *v = NULL;
+ const axis2_char_t *key_l = NULL;
+
+ axis2_hash_this (i, &v, NULL, NULL);
+ key_l = (const axis2_char_t *) v;
+ if(0 == AXIS2_STRCMP(key, key_l))
+ return AXIS2_TRUE;
+ }
+
+ return AXIS2_FALSE;
+}
static axis2_status_t
axis2_hash_entry_free (const axis2_env_t *env, axis2_hash_entry_t *hash_entry)
Modified: webservices/axis2/trunk/c/util/src/string.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/src/string.c?rev=412095&r1=412094&r2=412095&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/src/string.c (original)
+++ webservices/axis2/trunk/c/util/src/string.c Tue Jun 6 04:30:20 2006
@@ -20,6 +20,10 @@
#include <axis2_utils.h>
#include <axis2_utils_defines.h>
#include <ctype.h>
+#include <stdarg.h> /* NULL */
+
+/** this is used to cache lengths in axis2_strcat */
+#define MAX_SAVED_LENGTHS 6
AXIS2_EXTERN void* AXIS2_CALL
axis2_strdup (const void *ptr, const axis2_env_t *env)
@@ -42,6 +46,136 @@
{
return NULL;
}
+}
+
+AXIS2_EXTERN void * AXIS2_CALL
+axis2_strmemdup(const void *ptr,
+ size_t n,
+ const axis2_env_t *env)
+{
+ axis2_char_t *str;
+
+ AXIS2_ENV_CHECK(env, NULL);
+ AXIS2_PARAM_CHECK(env->error, ptr, NULL);
+
+ str = (axis2_char_t *) AXIS2_MALLOC( env->allocator,
+ sizeof(axis2_char_t) * (n + 1 ));
+ if (!str)
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+ return NULL;
+ }
+ memcpy(str, ptr, n);
+ str[n] = '\0';
+
+ return (void *) str;
+}
+
+AXIS2_EXTERN void * AXIS2_CALL
+memchr (
+ const void *ptr,
+ int c,
+ size_t n)
+{
+ const axis2_char_t *cp;
+
+ for (cp = ptr; n > 0; n--, cp++) {
+ if (*cp == c)
+ return (char *) cp; /* Casting away the const here */
+ }
+
+ return NULL;
+}
+
+AXIS2_EXTERN void* AXIS2_CALL
+axis2_strndup (
+ const void *ptr,
+ int n,
+ const axis2_env_t *env )
+{
+ const axis2_char_t *end;
+ axis2_char_t *str;
+
+ AXIS2_ENV_CHECK(env, NULL);
+ AXIS2_PARAM_CHECK(env->error, ptr, NULL);
+
+ end = memchr(ptr, '\0', n);
+ if(NULL != end)
+ n = end - (axis2_char_t *) ptr;
+ str = (axis2_char_t *) AXIS2_MALLOC( env->allocator,
+ sizeof(axis2_char_t) * (n + 1 ));
+ if (!str)
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+ return NULL;
+ }
+ memcpy(str, ptr, n);
+ str[n] = '\0';
+
+ return (void *) str;
+}
+
+AXIS2_DECLARE_NONSTD(axis2_char_t *)
+axis2_strcat(axis2_env_t *env, ...)
+{
+ axis2_char_t *cp, *argp, *str;
+ size_t saved_lengths[MAX_SAVED_LENGTHS];
+ int nargs = 0;
+
+ /* Pass one --- find length of required string */
+
+ size_t len = 0;
+ va_list adummy;
+
+ va_start(adummy, env);
+
+ while ((cp = va_arg(adummy, axis2_char_t *)) != NULL)
+ {
+ size_t cplen = strlen(cp);
+ if (nargs < MAX_SAVED_LENGTHS)
+ {
+ saved_lengths[nargs++] = cplen;
+ }
+ len += cplen;
+ }
+
+ va_end(adummy);
+
+ /* Allocate the required string */
+
+ str = (axis2_char_t *) AXIS2_MALLOC( env->allocator,
+ sizeof(axis2_char_t) * (len + 1 ));
+ if (!str)
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+ return NULL;
+ }
+ cp = str;
+
+ /* Pass two --- copy the argument strings into the result space */
+
+ va_start(adummy, env);
+
+ nargs = 0;
+ while ((argp = va_arg(adummy, axis2_char_t *)) != NULL) {
+ if (nargs < MAX_SAVED_LENGTHS) {
+ len = saved_lengths[nargs++];
+ }
+ else {
+ len = strlen(argp);
+ }
+
+ memcpy(cp, argp, len);
+ cp += len;
+ }
+
+ va_end(adummy);
+
+ /* Return the result string */
+
+ *cp = '\0';
+
+ return str;
}
AXIS2_EXTERN axis2_char_t* AXIS2_CALL
Modified: webservices/axis2/trunk/c/util/src/string_util.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/src/string_util.c?rev=412095&r1=412094&r2=412095&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/src/string_util.c (original)
+++ webservices/axis2/trunk/c/util/src/string_util.c Tue Jun 6 04:30:20 2006
@@ -138,3 +138,4 @@
return list;
}
+
Modified: webservices/axis2/trunk/c/util/src/url.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/src/url.c?rev=412095&r1=412094&r2=412095&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/src/url.c (original)
+++ webservices/axis2/trunk/c/util/src/url.c Tue Jun 6 04:30:20 2006
@@ -85,11 +85,12 @@
/***************************** End of function headers ************************/
AXIS2_EXTERN axis2_url_t * AXIS2_CALL
-axis2_url_create (const axis2_env_t *env,
- const axis2_char_t *protocol,
- const axis2_char_t *server,
- const int port,
- const axis2_char_t *path)
+axis2_url_create (
+ const axis2_env_t *env,
+ const axis2_char_t *protocol,
+ const axis2_char_t *server,
+ const int port,
+ const axis2_char_t *path)
{
axis2_url_impl_t *url_impl = NULL;
AXIS2_ENV_CHECK(env, NULL);
@@ -327,7 +328,6 @@
return AXIS2_SUCCESS;
}
-
axis2_char_t* AXIS2_CALL
axis2_url_to_external_form (axis2_url_t *url,
const axis2_env_t *env)
@@ -337,6 +337,8 @@
axis2_ssize_t len = 0;
axis2_char_t port_str[8];
AXIS2_ENV_CHECK(env, NULL);
+ AXIS2_PARAM_CHECK(env->error, url, NULL);
+
url_impl = AXIS2_INTF_TO_IMPL(url);
sprintf(port_str, "%d", url_impl->port);
len = AXIS2_STRLEN(url_impl->protocol) +
@@ -451,5 +453,4 @@
url_impl->port,
url_impl->path);
}
-
Modified: webservices/axis2/trunk/c/util/test/unit/util/util_string_test.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/test/unit/util/util_string_test.c?rev=412095&r1=412094&r2=412095&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/test/unit/util/util_string_test.c (original)
+++ webservices/axis2/trunk/c/util/test/unit/util/util_string_test.c Tue Jun 6 04:30:20 2006
@@ -23,3 +23,24 @@
CuAssertStrEquals(tc, expected, actual);
}
+
+void Testaxis2_strcat(CuTest *tc)
+{
+ axis2_char_t *actual = NULL;
+ int n = 3;
+ axis2_char_t *expected = "damitha_kumarage";
+
+ printf("******************************************\n");
+ printf("testing axis2_strcat\n");
+ printf("******************************************\n");
+
+ axis2_allocator_t *allocator = axis2_allocator_init(NULL);
+ axis2_error_t *error = axis2_error_create(allocator);
+ const axis2_env_t *env = axis2_env_create_with_error(allocator, error);
+
+ actual = axis2_strcat(env, "damitha", "_kumarage", NULL);
+ printf("actual:%s\n", actual);
+
+ CuAssertStrEquals(tc, expected, actual);
+}
+
Modified: webservices/axis2/trunk/c/util/test/unit/util/util_string_test.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/test/unit/util/util_string_test.h?rev=412095&r1=412094&r2=412095&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/test/unit/util/util_string_test.h (original)
+++ webservices/axis2/trunk/c/util/test/unit/util/util_string_test.h Tue Jun 6 04:30:20 2006
@@ -6,4 +6,6 @@
void Testaxis2_strndup(CuTest *tc);
+void Testaxis2_strcat(CuTest *tc);
+
#endif /* UTIL_STRING_TEST_H*/
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=412095&r1=412094&r2=412095&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 Tue Jun 6 04:30:20 2006
@@ -17,6 +17,7 @@
SUITE_ADD_TEST(suite, Testaxis2_array_list_get);
SUITE_ADD_TEST(suite, Testaxis2_linked_list_get);
SUITE_ADD_TEST(suite, Testaxis2_strndup);
+ SUITE_ADD_TEST(suite, Testaxis2_strcat);
SUITE_ADD_TEST(suite, Testaxis2_url_parse_string);
/* Samisa - need to remove this as we run make check before make install
SUITE_ADD_TEST(suite, Testaxis2_dir_handler_list_dir); */
Modified: webservices/axis2/trunk/c/util/test/util/test_util.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/test/util/test_util.c?rev=412095&r1=412094&r2=412095&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/test/util/test_util.c (original)
+++ webservices/axis2/trunk/c/util/test/util/test_util.c Tue Jun 6 04:30:20 2006
@@ -78,9 +78,7 @@
axis2_hash_set (ht, key2, AXIS2_HASH_KEY_STRING, a2);
for (i = axis2_hash_first (ht, env); i; i = axis2_hash_next (env, i))
{
-
axis2_hash_this (i, NULL, NULL, &v);
-
printf ("\n %s \n", ((a *) v)->value);
}
@@ -153,44 +151,6 @@
return 0;
}
-char* test_funct_for_test_env_null(const axis2_env_t *env)
-{
- if(NULL == env)
- {
- axis2_allocator_t *allocator = axis2_allocator_init (NULL);
- axis2_error_t *error = axis2_error_create (allocator);
- env = axis2_env_create_with_error(allocator, error);
- AXIS2_ERROR_SET_STATUS_CODE(env->error, AXIS2_FAILURE);
- AXIS2_ERROR_SET_ERROR_NUMBER(env->error, AXIS2_ERROR_ENVIRONMENT_IS_NULL);
- return AXIS2_STRDUP("env is null!!!", env);
- }
-
- AXIS2_ERROR_SET_STATUS_CODE(env->error, AXIS2_SUCCESS);
- return AXIS2_STRDUP("env not null, so be happy", env);
-}
-
-int test_env_null()
-{
- const axis2_env_t *env = NULL;
- char *msg;
- int status;
- /* Suppose we did properly initialized env here */
- /* But here we mistakenly make env to null */
- env = NULL;
- /*Now we call an axis2 mock function called
- * test_funct_for_test_env_null
- */
- msg = test_funct_for_test_env_null(env);
- status = axis2_env_check_status(env);
- if(AXIS2_SUCCESS == status)
- printf("%s\n", msg);
- else
- printf("status code is:%d\n", status);
-
- AXIS2_FREE((env)->allocator, msg);
- return 0;
-}
-
void test_array_list(const axis2_env_t *env)
{
axis2_array_list_t *al;
@@ -300,7 +260,6 @@
const axis2_env_t *env = test_init();
test_file_diff(env);
test_hash_get(env);
- test_env_null();
test_array_list(env);
test_uuid_gen(env);
run_test_log();
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org