diff options
Diffstat (limited to 'util')
181 files changed, 31667 insertions, 0 deletions
diff --git a/util/AUTHORS b/util/AUTHORS new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/util/AUTHORS diff --git a/util/COPYING b/util/COPYING new file mode 100644 index 0000000..6b0b127 --- /dev/null +++ b/util/COPYING @@ -0,0 +1,203 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. + diff --git a/util/CREDITS b/util/CREDITS new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/util/CREDITS diff --git a/util/ChangeLog b/util/ChangeLog new file mode 100644 index 0000000..10da7b3 --- /dev/null +++ b/util/ChangeLog @@ -0,0 +1,6 @@ +Apache Axis2/C Util + + * Seperated Util module from Axis2/C + +-- Axis2-C team <axis-c-dev@ws.apache.org> Thu, 18 May 2006 + diff --git a/util/INSTALL b/util/INSTALL new file mode 100644 index 0000000..8654e1f --- /dev/null +++ b/util/INSTALL @@ -0,0 +1,14 @@ +Getting Axis2/C Utils source working on Linux +============================================= +Build the source +This can be done using the following command sequence: + ./configure + make + make install + use './configure --help' for options + +NOTE: If you don't provide a --prefix configure option, it will by default +install into /usr/local/axis2_util directory. + + + diff --git a/util/LICENSE b/util/LICENSE new file mode 100644 index 0000000..6b0b127 --- /dev/null +++ b/util/LICENSE @@ -0,0 +1,203 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. + diff --git a/util/Makefile.am b/util/Makefile.am new file mode 100644 index 0000000..a7b0aaa --- /dev/null +++ b/util/Makefile.am @@ -0,0 +1,11 @@ +datadir=$(prefix) +tmpincludedir=$(prefix)/include/axis2-1.6.0/ +includedir=$(prefix)/include/axis2-1.6.0/ +SUBDIRS = src $(TESTDIR) include +include_HEADERS=$(top_builddir)/include/*.h +tmpinclude_DATA=config.h +data_DATA= INSTALL README AUTHORS NEWS CREDITS LICENSE COPYING +EXTRA_DIST = build.sh autogen.sh CREDITS LICENSE +dist-hook: + rm -rf `find $(distdir)/ -type d -name .svn` + rm -rf `find $(distdir)/ -type d -name .deps` diff --git a/util/NEWS b/util/NEWS new file mode 100644 index 0000000..6466fb3 --- /dev/null +++ b/util/NEWS @@ -0,0 +1,7 @@ +Util module seperated from Axis2/C +====================================== +Initially this was inside Axis2/C code base as util directory. As the +project expands it's moved to the top level with the view of making it a +seperate Apache project called Apache Axis2/C util. + +-- Axis2-C team <axis-c-dev@ws.apache.org> Thu, 18 May 2006 diff --git a/util/README b/util/README new file mode 100644 index 0000000..1779690 --- /dev/null +++ b/util/README @@ -0,0 +1,55 @@ +
+ Apache Axis2/C Util
+ ====================
+
+ What is it?
+ -----------
+ Axis2/C Util project is supposed to contain some utilities which are going to be
+ used across the Axis2/C platform. Initially this was inside Axis2/C code base
+ as util folder. But as the project expands and as related projects were emerging
+ there was a need to use those utilities across those projects of Axis2 C platform.
+ The resulting was springing of a new project called Axis2 C/Util.
+
+ As a project of the Apache Software Foundation, the
+ developers aim to collaboratively develop and maintain a robust,
+ commercial-grade, standards-based Web Services stack implementation with
+ freely available source code.
+
+ The Latest Version
+ ------------------
+
+ You can get the latest svn checkout of Apache Axis2/C util module from
+
+ https://svn.apache.org/repos/asf/webservices/axis2/trunk/c/util
+
+ Installation
+ ------------
+
+ Please see the file called INSTALL.
+
+ Licensing
+ ---------
+
+ Please see the file called LICENSE.
+
+ Contacts
+ --------
+
+ o If you want freely available support for using Apache Axis2/C Util please
+ join the Apache Axis2/C user community by subscribing to users mailing
+ list, axis-c-user@ws.apache.org' as described at
+ http://ws.apache.org/axis2/c/mail-lists.html
+
+ o If you have a bug report for Apache Axis2/C Guththila please log-in and create a JIRA issue
+ at http://issues.apache.org/jira/browse/AXIS2C
+
+ o If you want to participate actively in developing Apache Axis2/C Guththila please
+ subscribe to the `axis-c-dev@ws.apache.org' mailing list as described at
+ http://ws.apache.org/axis2/c/mail-lists.html
+
+
+ Acknowledgments
+ ----------------
+
+ Apache Axis2/C Util relies heavily on the use of autoconf, automake and libtool
+ to provide a build environment.
diff --git a/util/autogen.sh b/util/autogen.sh new file mode 100755 index 0000000..3862edc --- /dev/null +++ b/util/autogen.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +echo -n 'Running libtoolize...' +if [ `uname -s` = Darwin ] +then + LIBTOOLIZE=glibtoolize +else + LIBTOOLIZE=libtoolize +fi + +if $LIBTOOLIZE --force > /dev/null 2>&1; then + echo 'done.' +else + echo 'failed.' + exit 1 +fi + +echo -n 'Running aclocal...' +if aclocal > /dev/null 2>&1; then + echo 'done.' +else + echo 'failed.' + exit 1 +fi + +echo -n 'Running autoheader...' +if autoheader > /dev/null 2>&1; then + echo 'done.' +else + echo 'failed.' + exit 1 +fi + +echo -n 'Running autoconf...' +if autoconf > /dev/null 2>&1; then + echo 'done.' +else + echo 'failed.' + exit 1 +fi + +echo -n 'Running automake...' +if automake --add-missing > /dev/null 2>&1; then + echo 'done.' +else + echo 'failed.' + exit 1 +fi + +echo 'done' diff --git a/util/build.sh b/util/build.sh new file mode 100755 index 0000000..99458e3 --- /dev/null +++ b/util/build.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +./autogen.sh +./configure --prefix=${AXIS2C_HOME} --enable-static=no +make +make install diff --git a/util/configure.ac b/util/configure.ac new file mode 100644 index 0000000..720b42c --- /dev/null +++ b/util/configure.ac @@ -0,0 +1,275 @@ +dnl run autogen.sh to generate the configure script. + +AC_PREREQ(2.59) + +AC_INIT(axis2_util-src, 1.6.0) +AC_CANONICAL_SYSTEM +AM_CONFIG_HEADER(config.h) +AM_INIT_AUTOMAKE +AC_PREFIX_DEFAULT(/usr/local/axis2_util) + +dnl Checks for programs. +AC_PROG_CC +AC_PROG_CXX +AC_PROG_CPP +AC_PROG_LIBTOOL +AC_PROG_INSTALL +AC_PROG_LN_S +AC_PROG_MAKE_SET + +dnl check for flavours of varargs macros (test from GLib) +AC_MSG_CHECKING(for ISO C99 varargs macros in C) +AC_TRY_COMPILE([],[ +int a(int p1, int p2, int p3); +#define call_a(...) a(1,__VA_ARGS__) +call_a(2,3); +],axis2c_have_iso_c_varargs=yes,axis2c_have_iso_c_varargs=no) +AC_MSG_RESULT($axis2c_have_iso_c_varargs) + +AC_MSG_CHECKING(for GNUC varargs macros) +AC_TRY_COMPILE([],[ +int a(int p1, int p2, int p3); +#define call_a(params...) a(1,params) +call_a(2,3); +],axis2c_have_gnuc_varargs=yes,axis2c_have_gnuc_varargs=no) +AC_MSG_RESULT($axis2c_have_gnuc_varargs) + +dnl Output varargs tests +if test x$axis2c_have_iso_c_varargs = xyes; then + AC_DEFINE(HAVE_ISO_VARARGS,1,[Have ISO C99 varargs macros]) +fi +if test x$axis2c_have_gnuc_varargs = xyes; then + AC_DEFINE(HAVE_GNUC_VARARGS,1,[Have GNU-style varargs macros]) +fi + +dnl Checks for libraries. +AC_CHECK_LIB(dl, dlopen) +AC_CHECK_LIB(z, inflate) +AC_CHECK_LIB(socket, socket) + +dnl This can be removed when the ftime call in +dnl ./util/src/platforms/unix/date_time_util_unix.c +dnl is changed to call gettimeofday +AC_CHECK_LIB(compat, ftime) + +#CFLAGS="$CFLAGS -ansi -Wall -D_LARGEFILE64_SOURCE -Wno-implicit-function-declaration" +CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE" +if test "$GCC" = "yes"; then + CFLAGS="$CFLAGS -ansi -Wall -Werror -Wno-implicit-function-declaration -D_GNU_SOURCE" +fi + +dnl Checks for header files. +AC_HEADER_STDC +AC_CHECK_HEADERS([stdio.h stdlib.h string.h]) +AC_CHECK_HEADERS([sys/socket.h]) +AC_CHECK_HEADERS([net/if.h], [], [], +[#include <stdio.h> +#if STDC_HEADERS +# include <stdlib.h> +# include <stddef.h> +#else +# if HAVE_STDLIB_H +# include <stdlib.h> +# endif +#endif +#if HAVE_SYS_SOCKET_H +# include <sys/socket.h> +#endif +]) +AC_CHECK_HEADERS([linux/if.h],[],[], +[ +#if HAVE_SYS_SOCKET_H +# include <sys/socket.h> +#endif +]) +AC_CHECK_HEADERS([net/if_types.h net/if_dl.h]) + +dnl This is a check to see if we are running MacOS X +dnl It may be better to do a Darwin check +AC_CHECK_HEADER([sys/appleapiopts.h], + [AC_DEFINE([IS_MACOSX],[1],[Define to 1 if compiling on MacOS X])], + []) + +dnl Checks for typedefs, structures, and compiler characteristics. +dnl AC_C_CONST +AC_CHECK_TYPES([struct lifreq]) +AC_CHECK_TYPES([struct sockaddr_dl], [], [], +[ +#if HAVE_NET_IF_DL_H +# include <net/if_dl.h> +#endif +]) + +dnl Checks for library functions. +dnl AC_FUNC_MALLOC +dnl AC_FUNC_REALLOC +#AC_CHECK_FUNCS([memmove]) +AC_CHECK_FUNCS(getifaddrs) + +# System-dependent adjustments. +cygwin=no +darwin=no +solaris=no +no_undefined=no + +case "${host_cpu}" in +alpha*) + if test x"$GCC" = xyes + then + CFLAGS="$CFLAGS -mfp-rounding-mode=d -mieee" + CXXFLAGS="$CXXFLAGS -mfp-rounding-mode=d -mieee" + else + CFLAGS="$CFLAGS -fprm d -ieee -underflow_to_zero" + CXXFLAGS="$CXXFLAGS -fprm d -ieee -underflow_to_zero" + fi + ;; +*) + ;; +esac + +case "${host_os}" in +cygwin) + cygwin=yes + no_undefined=yes + ;; +darwin*) + darwin=yes + if test x"$GCC" = xyes + then + CFLAGS="$CFLAGS -Wno-long-double" + CXXFLAGS="$CXXFLAGS -Wno-long-double" + fi + ;; +solaris*) + solaris=yes + AC_DEFINE(AXIS2_SOLARIS,1,[Am I on Solaris?]) + + ;; +*) + ;; +esac + +AM_CONDITIONAL(HOST_OS_CYGWIN, test x$cygwin = xyes) +AM_CONDITIONAL(HOST_OS_DARWIN, test x$darwin = xyes) +AM_CONDITIONAL(HOST_OS_SOLARIS, test x$solaris = xyes) +AM_CONDITIONAL(NO_UNDEFINED, test x$no_undefined = xyes) + + +AC_MSG_CHECKING(whether to build guththila xml parser library) +AC_ARG_ENABLE(guththila, [ --enable-guththila build guththila xml parser library wrapper. default=no], +[ case "${enableval}" in + no) + AC_MSG_RESULT(no) + GUTHTHILA_DIR="" + ;; + *) + AC_MSG_RESULT(yes) + GUTHTHILA_DIR="guththila" + + ;; + esac ], + AC_MSG_RESULT(no) + GUTHTHILA_DIR="" +) + +AC_MSG_CHECKING(whether to enable trace) +AC_ARG_ENABLE(trace, [ --enable-trace + enable logging trace messages useful when debugging (default=no)], +[ case "${enableval}" in + no) + AC_MSG_RESULT(no) + CFLAGS="$CFLAGS" + ;; + *) + AC_MSG_RESULT(yes) + CFLAGS="$CFLAGS -DAXIS2_TRACE" + ;; + esac ], + AC_MSG_RESULT(no) + CFLAGS="$CFLAGS" +) + +AC_MSG_CHECKING(whether to build tests) +AC_ARG_ENABLE(tests, [ --enable-tests build tests. default=yes], +[ case "${enableval}" in + yes) + AC_MSG_RESULT(yes) + TESTDIR="test" + ;; + *) + AC_MSG_RESULT(no) + TESTDIR="" + + ;; + esac ], + AC_MSG_RESULT(no) + TESTDIR="" +) + +AC_MSG_CHECKING(whether to use archive) +AC_ARG_WITH(archive, +[ --with-archive[=PATH] Find the zlib header files in 'PATH'. + If you omit the '=PATH' part completely, the configure script will search + '/usr/include/' for zlib headers.], +[ case "$withval" in + no) + AC_MSG_RESULT(no) + ZLIBBUILD="" + zliblibs="" + ;; + *) + AC_MSG_RESULT(yes) + zliblibs="minizip/libaxis2_minizip.la" + CFLAGS="$CFLAGS -DAXIS2_ARCHIVE_ENABLED" + if test -d $withval; then + zlibinc="-I$withval" + elif test -d '/usr/include'; then + zlibinc="-I/usr/include" + else + AC_MSG_ERROR(could not find zlib stop) + fi + ZLIBBUILD="minizip" + ;; + esac ], + AC_MSG_RESULT(no) +) + + + +CFLAGS="$CFLAGS $GUTHTHILA_CFLAGS" + +UTILINC=$axis2_utilinc +ZLIBINC=$zlibinc +ZLIBLIBS=$zliblibs +VERSION_NO="6:0:6" + +AC_SUBST(VERSION_NO) +AC_SUBST(UTILINC) +AC_SUBST(ZLIBINC) +AC_SUBST(ZLIBLIBS) +AC_SUBST(ZLIBBUILD) +AC_SUBST(GUTHTHILA_DIR) +AC_SUBST(GUTHTHILA_LIBS) +AC_SUBST(TESTDIR) + +AC_CONFIG_FILES([Makefile \ + src/Makefile \ + src/platforms/unix/Makefile \ + src/minizip/Makefile \ + include/Makefile \ + test/Makefile \ + test/util/Makefile \ + test/allocator/Makefile \ + test/date_time/Makefile \ + test/duration/Makefile \ + test/link_list/Makefile \ + test/properties/Makefile \ + test/rand/Makefile \ + test/stack/Makefile \ + test/string_util/Makefile \ + test/uri/Makefile \ + test/url/Makefile \ + test/utils/Makefile \ + ]) + +AC_OUTPUT diff --git a/util/include/Makefile.am b/util/include/Makefile.am new file mode 100644 index 0000000..3cf1d6d --- /dev/null +++ b/util/include/Makefile.am @@ -0,0 +1,2 @@ +includedir=$(prefix)/include/axis2-1.6.0/ +nobase_include_HEADERS= platforms/axutil_platform_auto_sense.h platforms/unix/*.h platforms/windows/*.h diff --git a/util/include/axutil_allocator.h b/util/include/axutil_allocator.h new file mode 100644 index 0000000..698ebfe --- /dev/null +++ b/util/include/axutil_allocator.h @@ -0,0 +1,200 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_ALLOCATOR_H +#define AXUTIL_ALLOCATOR_H + +/** + * @file axutil_allocator.h + * @brief Axis2 memory allocator interface + */ + +#include <axutil_utils_defines.h> +#include <stdlib.h> +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_allocator allocator + * @ingroup axis2_util + * @{ + */ + + /** + * \brief Axis2 memory allocator + * + * Encapsulator for memory allocating routines + */ + typedef struct axutil_allocator + { + + /** + * Function pointer representing the function that allocates memory. + * @param allocator pointer to allocator struct. In the default + * implementation this is not used, however this parameter is useful + * when the allocator implementation is dealing with a memory pool. + * @param size size of the memory block to be allocated + * @return pointer to the allocated memory block + */ + void *( + AXIS2_CALL + * malloc_fn)( + struct axutil_allocator * allocator, + size_t size); + + /** + * Function pointer representing the function that re-allocates memory. + * @param allocator pointer to allocator struct. In the default + * implementation this is not used, however this parameter is useful + * when the allocator implementation is dealing with a memory pool. + * @param ptr memory block who's size to be changed + * @param size size of the memory block to be allocated + * @return pointer to the allocated memory block + */ + void *( + AXIS2_CALL + * realloc)( + struct axutil_allocator * allocator, + void *ptr, + size_t size); + + /** + * Function pointer representing the function that frees memory. + * @param allocator pointer to allocator struct. In the default + * implementation this is not used, however this parameter is useful + * when the allocator implementation is dealing with a memory pool. + * @param ptr pointer to be freed + * @return void + */ + void( + AXIS2_CALL + * free_fn)( + struct axutil_allocator * allocator, + void *ptr); + + /** + * Local memory pool. Local pool is used to allocate per request + * local values. + */ + void *local_pool; + + /** + * Global memory pool. Global pool is used to allocate values that + * live beyond a request + */ + void *global_pool; + + /** + * Memory pool currently in use. The functions + * axutil_allocator_switch_to_global_pool and + * axutil_allocator_switch_to_local_pool should be used to + * set the current pool to global pool or to local pool respectively. + */ + void *current_pool; + + /** + * This variable has meaning only when allocator is initialized when Axis2/C is used in + * Apache2 module. When switching to global poo this ref counter is increased by one. When + * switching to local pool it is descreased by one. When creating allocator this variable + * is initialized to 0 which means it points to the local pool. If user has switched to the + * global pool several times without switching back to the local pool this ref counter has + * a positive value. If at this stage switching to lcoal pool called then this ref counter + * is reduced and checked if its value is zero. If only it's value is zero then pool is + * switched to local pool. This functionality avoid unintended switching to localpool by + * some code fragment. Still user has to make sure that each global switch has a + * corresponding local switch. + */ + int global_pool_ref; + + } + axutil_allocator_t; + + /** + * Initializes (creates) a memory allocator. + * @param allocator user defined allocator. If NULL, a default allocator + * will be returned. + * @return initialized allocator. NULL on error. + */ + AXIS2_EXTERN axutil_allocator_t *AXIS2_CALL + axutil_allocator_init( + axutil_allocator_t * allocator); + + /** + * Creates a clone of given allocator + * @param allocator user defined allocator. Cannot be NULL + * @return initialized allocator. NULL on error. + */ + AXIS2_EXTERN axutil_allocator_t *AXIS2_CALL + axutil_allocator_clone( + axutil_allocator_t * allocator); + + /** + * This function should be used to deallocate memory if the default + * allocator was provided by the axutil_allocator_init() call. + * @param allocator allocator struct to be freed + * @return void + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_allocator_free( + axutil_allocator_t * allocator); + + /** + * Swaps the local_pool and global_pool and makes the global pool the + * current pool. + * In case of using pools, local_pool is supposed to hold the pool out of which + * local values are allocated. In case of values that live beyond a request + * global pool should be used, hence this method has to be called to switch to + * global pool for allocation. + * @param allocator allocator whose memory pools are to be switched + * @return void + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_allocator_switch_to_global_pool( + axutil_allocator_t * allocator); + + /** + * Swaps the local_pool and global_pool and makes the local pool the + * current pool. + * In case of using pools, local_pool is supposed to hold the pool out of which + * local values are allocated. In case of values that live beyond a request + * global pool should be used. This method can be used to inverse the switching + * done by axutil_allocator_switch_to_global_pool, to start using the local pool again. + * @param allocator allocator whose memory pools are to be switched + * @return void + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_allocator_switch_to_local_pool( + axutil_allocator_t * allocator); + +#define AXIS2_MALLOC(allocator, size) \ + ((allocator)->malloc_fn(allocator, size)) + +#define AXIS2_REALLOC(allocator, ptr, size) \ + ((allocator)->realloc(allocator, ptr, size)) + +#define AXIS2_FREE(allocator, ptr) \ + ((allocator)->free_fn(allocator, ptr)) + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_ALLOCATOR_H */ diff --git a/util/include/axutil_array_list.h b/util/include/axutil_array_list.h new file mode 100644 index 0000000..792df3b --- /dev/null +++ b/util/include/axutil_array_list.h @@ -0,0 +1,250 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_ARRAY_LIST_H +#define AXUTIL_ARRAY_LIST_H + +/** + * @defgroup axutil_array_list array list + * @ingroup axis2_util + * Description. + * @{ + */ + +/** + * @file axutil_array_list.h + * @brief Axis2 array_list interface + */ + +#include <axutil_utils_defines.h> +#include <axutil_env.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define AXIS2_ARRAY_LIST_DEFAULT_CAPACITY 16 + + /** + * Array List struct + */ + typedef struct axutil_array_list axutil_array_list_t; + + /** + * Constructs a new array list with the supplied initial capacity. + * If capacity is invalid (<= 0) then default capacity is used + * @param env pointer to environment struct + * @param capacity initial capacity of this array_list + */ + AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL + axutil_array_list_create( + const axutil_env_t * env, + int capacity); + + /** + * Free array passed as void pointer. + * @param array_list pointer to array list + * @param env pointer to environment struct + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_array_list_free_void_arg( + void *array_list, + const axutil_env_t * env); + + /** + * Guarantees that this list will have at least enough capacity to + * hold min_capacity elements. This implementation will grow the list to + * max(current * 2, min_capacity) + * @param array_list pointer to array_list + * @param env pointer to environment struct + * @param min_capacity the minimum guaranteed capacity + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_array_list_ensure_capacity( + struct axutil_array_list *array_list, + const axutil_env_t * env, + int min_capacity); + + /** + * Returns the number of elements in this list. + * @param array_list pointer to array list + * @param env pointer to environment struct + * @return the list size + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_array_list_size( + struct axutil_array_list *array_list, + const axutil_env_t * env); + + /** + * Checks if the list is empty. + * @param array_list pointer to array list + * @param env pointer to environment struct + * @return true if there are no elements, else false + */ + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + axutil_array_list_is_empty( + struct axutil_array_list *array_list, + const axutil_env_t * env); + + /** + * Returns true iff element is in this array_list. + * @param array_list pointer to array list + * @param env pointer to environment struct + * @param e the element whose inclusion in the List is being tested + * @return true if the list contains e + */ + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + axutil_array_list_contains( + struct axutil_array_list *array_list, + const axutil_env_t * env, + void *e); + + /** + * Returns the lowest index at which element appears in this List, or + * -1 if it does not appear. This looks for the pointer value equality only, + * does not look into pointer content + * @param array_list pointer to array list + * @param env pointer to environment struct + * @param e the element whose inclusion in the List is being tested + * @return the index where e was found + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_array_list_index_of( + struct axutil_array_list *array_list, + const axutil_env_t * env, + void *e); + + /** + * Retrieves the element at the user-supplied index. + * @param array_list pointer to array list + * @param env pointer to environment struct + * @param index the index of the element we are fetching + * @return element at the given index + */ + AXIS2_EXTERN void *AXIS2_CALL + axutil_array_list_get( + struct axutil_array_list *array_list, + const axutil_env_t * env, + int index); + + /** + * Sets the element at the specified index. The new element, e, + * can be an object of any type or null. + * @param array_list pointer to array list + * @param env pointer to environment struct + * @param index the index at which the element is being set + * @param e the element to be set + * @return the element previously at the specified index + */ + AXIS2_EXTERN void *AXIS2_CALL + axutil_array_list_set( + struct axutil_array_list *array_list, + const axutil_env_t * env, + int index, + void *e); + + /** + * Appends the supplied element to the end of this list. + * The element, e, can be a pointer of any type or NULL. + * @param array_list pointer to array list + * @param env pointer to environment struct + * @param e the element to be appended to this list + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_array_list_add( + struct axutil_array_list *array_list, + const axutil_env_t * env, + const void *e); + + /** + * Adds the supplied element at the specified index, shifting all + * elements currently at that index or higher one to the right. + * The element, e, can be a pointer of any type or NULL. + * @param array_list pointer to array list + * @param env pointer to environment struct + * @param index the index at which the element is being added + * @param e the item being added + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_array_list_add_at( + struct axutil_array_list *array_list, + const axutil_env_t * env, + const int index, + const void *e); + + /** + * Removes the element at the user-supplied index. + * @param array_list pointer to array list + * @param env pointer to environment struct + * @param index the index of the element to be removed + * @return the removed void* pointer + */ + AXIS2_EXTERN void *AXIS2_CALL + axutil_array_list_remove( + struct axutil_array_list *array_list, + const axutil_env_t * env, + int index); + + /** + * Checks that the index is in the range of possible elements (inclusive). + * @param array_list pointer to array list + * @param env pointer to environment struct + * @param index the index to check + * @return AXIS2_FALSE if index > size or index < 0, else AXIS2_TRUE + */ + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + + axutil_array_list_check_bound_inclusive( + struct axutil_array_list *array_list, + const axutil_env_t * env, + int index); + + /** + * Checks that the index is in the range of existing elements (exclusive). + * @param array_list pointer to array list + * @param env pointer to environment struct + * @param index the index to check + * @return AXIS2_FALSE if index >= size or index < 0, else AXIS2_TRUE + */ + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + + axutil_array_list_check_bound_exclusive( + struct axutil_array_list *array_list, + const axutil_env_t * env, + int index); + + /** + * @param array_list pointer to array list + * @param env pointer to environment struct + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_array_list_free( + struct axutil_array_list *array_list, + const axutil_env_t * env); + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_ARRAY_LIST_H */ diff --git a/util/include/axutil_base64.h b/util/include/axutil_base64.h new file mode 100644 index 0000000..d52e3af --- /dev/null +++ b/util/include/axutil_base64.h @@ -0,0 +1,122 @@ + +/* + * Copyright 2003-2004 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 <axutil_utils_defines.h> + +/* + * @file axutil_base64.h + * @brief AXIS2-UTIL Base64 Encoding + */ +#ifndef AXUTIL_BASE64_H +#define AXUTIL_BASE64_H + +#ifdef __cplusplus +extern "C" +{ +#endif + + /* + * @defgroup AXIS2_Util_Base64 base64 encoding + * @ingroup AXIS2_Util + */ + + /* Simple BASE64 encode/decode functions. + * + * As we might encode binary strings, hence we require the length of + * the incoming plain source. And return the length of what we decoded. + * + * The decoding function takes any non valid char (i.e. whitespace, \0 + * or anything non A-Z,0-9 etc as terminal. + * + * plain strings/binary sequences are not assumed '\0' terminated. Encoded + * strings are neither. But probably should. + * + */ + + /* + * Given the length of an un-encrypted string, get the length of the + * encrypted string. + * @param len the length of an unencrypted string. + * @return the length of the string after it is encrypted + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_base64_encode_len( + int len); + + /* + * Encode a text string using base64encoding. + * @param coded_dst The destination string for the encoded string. + * @param plain_src The original string in plain text + * @param len_plain_src The length of the plain text string + * @return the length of the encoded string + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_base64_encode( + char *coded_dst, + const char *plain_src, + int len_plain_src); + + /* + * Encode an EBCDIC string using base64encoding. + * @param coded_dst The destination string for the encoded string. + * @param plain_src The original string in plain text + * @param len_plain_src The length of the plain text string + * @return the length of the encoded string + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_base64_encode_binary( + char *coded_dst, + const unsigned char *plain_src, + int len_plain_src); + + /* + * Determine the length of a plain text string given the encoded version + * @param coded_src The encoded string + * @return the length of the plain text string + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_base64_decode_len( + const char *coded_src); + + /* + * Decode a string to plain text + * @param plain_dst The destination string for the plain text. size of this should be axutil_base64_decode_len + 1 + * @param coded_src The encoded string + * @return the length of the plain text string + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_base64_decode( + char *plain_dst, + const char *coded_src); + + /* + * Decode an EBCDIC string to plain text + * @param plain_dst The destination string for the plain text. size of this should be axutil_base64_decode_len + * @param coded_src The encoded string + * @return the length of the plain text string + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_base64_decode_binary( + unsigned char *plain_dst, + const char *coded_src); + + /* @} */ +#ifdef __cplusplus +} +#endif + +#endif /* !AXIS2_BASE64_H */ diff --git a/util/include/axutil_base64_binary.h b/util/include/axutil_base64_binary.h new file mode 100644 index 0000000..ba99f0a --- /dev/null +++ b/util/include/axutil_base64_binary.h @@ -0,0 +1,173 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_BASE64_BINARY_H +#define AXUTIL_BASE64_BINARY_H + +#include <axutil_base64.h> +#include <axutil_utils_defines.h> +#include <axutil_env.h> + +/** + * @defgroup axutil_base64_binary encoding holder + * @ingroup axis2_util + * @{ + */ + +/** + * @file axutil_base64_binary.h + * @brief axis2-util base64 encoding holder + */ + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** Type name for struct axutil_base64_binary */ + typedef struct axutil_base64_binary axutil_base64_binary_t; + + /** + * Creates axutil_base64_binary struct + * @param env double pointer to environment struct. MUST NOT be NULL + * @return pointer to newly created axutil_base64_binary struct + */ + AXIS2_EXTERN axutil_base64_binary_t *AXIS2_CALL + + axutil_base64_binary_create( + const axutil_env_t * env); + + /** + * Creates axutil_base64_binary struct + * @param env double pointer to environment struct. MUST NOT be NULL + * @param plain_binary binary buffer to initialize + * @return pointer to newly created axutil_base64_binary struct + */ + AXIS2_EXTERN axutil_base64_binary_t *AXIS2_CALL + + axutil_base64_binary_create_with_plain_binary( + const axutil_env_t * env, + const unsigned char *plain_binary, + int plain_binary_len); + + /** + * Creates axutil_base64_binary struct. + * @param env double pointer to environment struct. MUST NOT be NULL + * @param encoded_binary binary buffer to initialize + * @return pointer to newly created axutil_base64_binary struct + */ + AXIS2_EXTERN axutil_base64_binary_t *AXIS2_CALL + + axutil_base64_binary_create_with_encoded_binary( + const axutil_env_t * env, + const char *encoded_binary); + + /** + * free the axutil_base64_binary. + * @param base64_binary represet the type object + * @param env pointer to environment struct. MUST NOT be NULL + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_base64_binary_free( + axutil_base64_binary_t * base64_binary, + const axutil_env_t * env); + + /** + * store the value from plain binary. + * @param base64_binary represet the type object + * @param env pointer to environment struct. MUST NOT be NULL + * @param plain_binary binary buffer to store + * @param plain_binary_len length of the plain_binary binary buffer + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axutil_base64_binary_set_plain_binary( + axutil_base64_binary_t * base64_binary, + const axutil_env_t * env, + const unsigned char *plain_binary, + int plain_binary_len); + + /** + * retrieve the value from plain binary. + * @param base64_binary represet the type object + * @param env pointer to environment struct. MUST NOT be NULL + * @param plain_binary_len length of the plain_binary binary buffer + * @return the plain binary + */ + + AXIS2_EXTERN unsigned char *AXIS2_CALL + + axutil_base64_binary_get_plain_binary( + axutil_base64_binary_t * base64_binary, + const axutil_env_t * env, + int *plain_binary_len); + + /** + * store the value from encoded binary. + * @param base64_binary represet the type object + * @param env pointer to environment struct. MUST NOT be NULL + * @param encoded_binary encoded binary buffer to store + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axutil_base64_binary_set_encoded_binary( + axutil_base64_binary_t * base64_binary, + const axutil_env_t * env, + const char *encoded_binary); + + /** + * retrieve the value from encoded binary. + * @param base64_binary represet the type object + * @param env pointer to environment struct. MUST NOT be NULL + * @return the encoded binary + */ + AXIS2_EXTERN char *AXIS2_CALL + axutil_base64_binary_get_encoded_binary( + axutil_base64_binary_t * base64_binary, + const axutil_env_t * env); + + /** + * retrieve the value from encoded binary length. + * @param base64_binary represet the type object + * @param env pointer to environment struct. MUST NOT be NULL + * @return the encoded binary length + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_base64_binary_get_encoded_binary_len( + axutil_base64_binary_t * base64_binary, + const axutil_env_t * env); + + /** + * retrieve the value from decoded binary length. + * @param base64_binary represet the type object + * @param env pointer to environment struct. MUST NOT be NULL + * @return the decoded binary length + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_base64_binary_get_decoded_binary_len( + axutil_base64_binary_t * base64_binary, + const axutil_env_t * env); + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_BASE64_BINARY_H */ diff --git a/util/include/axutil_class_loader.h b/util/include/axutil_class_loader.h new file mode 100644 index 0000000..99a0f95 --- /dev/null +++ b/util/include/axutil_class_loader.h @@ -0,0 +1,63 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_CLASS_LOADER_H +#define AXUTIL_CLASS_LOADER_H + +/** + * @file axutil_class_loader.h + * @brief axis2 class loader interface + */ + +#include <axutil_utils_defines.h> +#include <axutil_qname.h> +#include <axutil_error.h> +#include <axutil_utils.h> +#include <axutil_dll_desc.h> +#include <axutil_param.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** @defgroup axutil_class_loader class loader + * @ingroup axis2_util + * @{ + */ + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_class_loader_init( + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_class_loader_delete_dll( + const axutil_env_t * env, + axutil_dll_desc_t * dll_desc); + + AXIS2_EXTERN void *AXIS2_CALL + axutil_class_loader_create_dll( + const axutil_env_t * env, + axutil_param_t * impl_info_param); + + /** @} */ +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_CLASS_LOADER_H */ diff --git a/util/include/axutil_config.h b/util/include/axutil_config.h new file mode 100644 index 0000000..a35c0bd --- /dev/null +++ b/util/include/axutil_config.h @@ -0,0 +1,42 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_CONFIG_H +#define AXUTIL_CONFIG_H + +/* undef unwated cnfig macros to avoid conflicts with APR macros */ +#undef PACKAGE +#undef PACKAGE_BUGREPORT +#undef PACKAGE_NAME +#undef PACKAGE_STRING +#undef PACKAGE_TARNAME +#undef PACKAGE_VERSION +#undef VERSION + +#include <config.h> + +/* undef unwated cnfig macros to avoid conflicts with APR macros */ +#undef PACKAGE +#undef PACKAGE_BUGREPORT +#undef PACKAGE_NAME +#undef PACKAGE_STRING +#undef PACKAGE_TARNAME +#undef PACKAGE_VERSION +#undef VERSION + +#endif /* AXIS2_UTILS_H */ diff --git a/util/include/axutil_date_time.h b/util/include/axutil_date_time.h new file mode 100644 index 0000000..eeac9e6 --- /dev/null +++ b/util/include/axutil_date_time.h @@ -0,0 +1,350 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_DATE_TIME_H +#define AXUTIL_DATE_TIME_H + +#include <axutil_utils_defines.h> +#include <axutil_env.h> + +/** + * @file axutil_date_time.h + * @brief axis2-util + */ + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_date_time + * @ingroup axis2_util + * @{ + */ + + typedef struct axutil_date_time axutil_date_time_t; + + typedef enum + { + AXIS2_DATE_TIME_COMP_RES_FAILURE = -1, + AXIS2_DATE_TIME_COMP_RES_UNKNOWN, + AXIS2_DATE_TIME_COMP_RES_EXPIRED, + AXIS2_DATE_TIME_COMP_RES_EQUAL, + AXIS2_DATE_TIME_COMP_RES_NOT_EXPIRED + } axutil_date_time_comp_result_t; + + /** + * Creates axutil_date_time struct with current date time + * @param env double pointer to environment struct. MUST NOT be NULL + * @return pointer to newly created axutil_date_time struct + */ + AXIS2_EXTERN axutil_date_time_t *AXIS2_CALL + axutil_date_time_create( + const axutil_env_t * env); + + /* + * Creates axutil_date_time struct with an additional offset value + * If the offset is a positive value then the time will be in the future + * offset is 0, then the time will be the current time + * offset is a negative value then the time is in the past. + * @param env double pointer to environment struct. MUST NOT be NULL + * @param offset the offset from the current time in seconds + * @return pointer to newly created axutil_date_time struct + **/ + AXIS2_EXTERN axutil_date_time_t *AXIS2_CALL + + axutil_date_time_create_with_offset( + const axutil_env_t * env, + int offset); + + /** + * free the axutil_date_time. + * @param date_time represet the type object + * @param env pointer to environment struct. MUST NOT be NULL + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_date_time_free( + axutil_date_time_t * date_time, + const axutil_env_t * env); + + /** + * store the time value from plain text. + * @param date_time represet the type object + * @param env pointer to environment struct. MUST NOT be NULL + * @param time time as a string format HH:MM:TTZ + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_date_time_deserialize_time( + axutil_date_time_t * date_time, + const axutil_env_t * env, + const axis2_char_t * time_str); + + /** + * store the date value from plain text. + * @param date_time represet the type object + * @param env pointer to environment struct. MUST NOT be NULL + * @param date date as a string format YYYY-MM-DD + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_date_time_deserialize_date( + axutil_date_time_t * date_time, + const axutil_env_t * env, + const axis2_char_t * date_str); + + /** + * store the date value from plain text. + * @param date_time represet the type object + * @param env pointer to environment struct. MUST NOT be NULL + * @param date_time string format YYYY-MM-DDTHH:MM:SSZ + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axutil_date_time_deserialize_date_time( + axutil_date_time_t * date_time, + const axutil_env_t * env, + const axis2_char_t * date_time_str); + + /** + * store the date value from set of values + * @param date_time represet the type object + * @param env pointer to environment struct. MUST NOT be NULL + * @param year Integer -1 can be used to ignore + * @param month Integer -1 can be used to ignore + * @param date Integer -1 can be used to ignore + * @param hour Integer -1 can be used to ignore + * @param min Integer -1 can be used to ignore + * @param second Integer -1 can be used to ignore + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_date_time_set_date_time( + axutil_date_time_t * date_time, + const axutil_env_t * env, + int year, + int month, + int date, + int hour, + int min, + int second, + int milliseconds); + + /** + * retrive the stored time as a string + * @param date_time represet the type object + * @param env pointer to environment struct. MUST NOT be NULL + * @return time as a string format HH:MM:SSZ + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_date_time_serialize_time( + axutil_date_time_t * date_time, + const axutil_env_t * env); + + /** + * retrive the stored date as a string + * @param date_time represet the type object + * @param env pointer to environment struct. MUST NOT be NULL + * @return date as a string format YYYY-MM-DD + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_date_time_serialize_date( + axutil_date_time_t * date_time, + const axutil_env_t * env); + + /** + * retrive the stored date time as a string with millisecond precision + * @param date_time represet the type object + * @param env pointer to environment struct. MUST NOT be NULL + * @return time as a string format YYYY-MM-DDTHH:MM:SS.msZ + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + + axutil_date_time_serialize_date_time( + axutil_date_time_t * date_time, + const axutil_env_t * env); + + /** + * retrive the stored date time as a string without millisecond + * @param date_time represet the type object + * @param env pointer to environment struct. MUST NOT be NULL + * @return time as a string format YYYY-MM-DDTHH:MM:SSZ + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_date_time_serialize_date_time_without_millisecond( + axutil_date_time_t * date_time, + const axutil_env_t * env); + + /** + * retrieve the year of the date time + * @param date_time represet the type object + * @param env pointer to environment struct. MUST NOT be NULL + * @return year as an integer + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_date_time_get_year( + axutil_date_time_t * date_time, + const axutil_env_t * env); + + /** + * retrieve the month of the date time + * @param date_time represet the type object + * @param env pointer to environment struct. MUST NOT be NULL + * @return month as an integer + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_date_time_get_month( + axutil_date_time_t * date_time, + const axutil_env_t * env); + + /** + * retrieve the date of the date time + * @param date_time represet the type object + * @param env pointer to environment struct. MUST NOT be NULL + * @return date as an integer + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_date_time_get_date( + axutil_date_time_t * date_time, + const axutil_env_t * env); + + /** + * retrieve the hour of the date time + * @param date_time represet the type object + * @param env pointer to environment struct. MUST NOT be NULL + * @return hour as an integer + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_date_time_get_hour( + axutil_date_time_t * date_time, + const axutil_env_t * env); + + /** + * retrieve the minute of the date time + * @param date_time represet the type object + * @param env pointer to environment struct. MUST NOT be NULL + * @return minute as an integer + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_date_time_get_minute( + axutil_date_time_t * date_time, + const axutil_env_t * env); + + /** + * retrieve the second of the date time + * @param date_time represet the type object + * @param env pointer to environment struct. MUST NOT be NULL + * @return second as an integer + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_date_time_get_second( + axutil_date_time_t * date_time, + const axutil_env_t * env); + + AXIS2_EXTERN int AXIS2_CALL + axutil_date_time_get_msec( + axutil_date_time_t * date_time, + const axutil_env_t * env); + + /** + * Compare the date and time of @date_time with the reference @ref. + * If the @date_time < @ref this returns NOT_EXPIRED. + * If the @date_time > @ref this returns EXPIRED. + * If the @date_time = @ref this returns EQUAL. + * @param date_time the date time to be compared + * @param env pointer to environment struct. MUST NOT be NULL + * @ref the reference date time + * @return NOT_EXPIRED/EXPIRED/EQUAL if valid otherwise return FAILURE + */ + AXIS2_EXTERN axutil_date_time_comp_result_t AXIS2_CALL + axutil_date_time_compare( + axutil_date_time_t * date_time, + const axutil_env_t * env, + axutil_date_time_t * ref); + + AXIS2_EXTERN axutil_date_time_t *AXIS2_CALL + axutil_date_time_utc_to_local( + axutil_date_time_t * date_time, + const axutil_env_t * env, + axis2_bool_t is_positive, + int hour, + int min); + + AXIS2_EXTERN axutil_date_time_t *AXIS2_CALL + axutil_date_time_local_to_utc( + axutil_date_time_t * date_time, + const axutil_env_t * env); + + AXIS2_EXTERN int AXIS2_CALL + axutil_date_time_get_time_zone_hour( + axutil_date_time_t * date_time, + const axutil_env_t * env); + + AXIS2_EXTERN int AXIS2_CALL + axutil_date_time_get_time_zone_minute( + axutil_date_time_t * date_time, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + axutil_date_time_is_time_zone_positive( + axutil_date_time_t * date_time, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_date_time_set_time_zone( + axutil_date_time_t * date_time, + const axutil_env_t * env, + axis2_bool_t is_positive, + int hour, + int min); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_date_time_deserialize_date_time_with_time_zone( + axutil_date_time_t * date_time, + const axutil_env_t * env, + const axis2_char_t * date_time_str); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_date_time_deserialize_time_with_time_zone( + axutil_date_time_t * date_time, + const axutil_env_t * env, + const axis2_char_t * time_str); + + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_date_time_serialize_date_time_with_time_zone( + axutil_date_time_t * date_time, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_date_time_serialize_time_with_time_zone( + axutil_date_time_t * date_time, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + axutil_date_time_is_utc( + axutil_date_time_t * date_time, + const axutil_env_t * env); + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_DATE_TIME_H */ diff --git a/util/include/axutil_date_time_util.h b/util/include/axutil_date_time_util.h new file mode 100644 index 0000000..bd4aca0 --- /dev/null +++ b/util/include/axutil_date_time_util.h @@ -0,0 +1,51 @@ + +/* + * 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 count 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 AXUTIL_DATE_TIME_UTIL_H +#define AXUTIL_DATE_TIME_UTIL_H + +#include <axutil_utils.h> +#include <axutil_utils_defines.h> +#include <axutil_env.h> +#include <platforms/axutil_platform_auto_sense.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_uuid_gen UUID generator + * @ingroup axis2_util + * @{ + */ + + /** + * generate a uuid + * @return generated uuid as a string + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_get_milliseconds( + const axutil_env_t * env); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_DATE_TIME_UTIL_H */ diff --git a/util/include/axutil_digest_calc.h b/util/include/axutil_digest_calc.h new file mode 100644 index 0000000..ac27ab0 --- /dev/null +++ b/util/include/axutil_digest_calc.h @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_DIGEST_CALC_H +#define AXUTIL_DIGEST_CALC_H + +/** + * @file axutil_digest_calc.h + * @brief implements the calculations of H(A1), H(A2), + * request-digest and response-digest for Axis2 based on rfc2617. + */ + +#include <axutil_utils_defines.h> +#include <axutil_env.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axis2_util utilities + * @ingroup axis2 + * @{ + * @} + */ + + /** + * @defgroup axutil_digest_calc digest_calc + * @ingroup axis2_util + * @{ + */ + + #define AXIS2_DIGEST_HASH_LEN 16 + #define AXIS2_DIGEST_HASH_HEX_LEN 32 + + typedef unsigned char axutil_digest_hash_t[AXIS2_DIGEST_HASH_LEN]; + typedef unsigned char axutil_digest_hash_hex_t[AXIS2_DIGEST_HASH_HEX_LEN + 1]; + + /** + * calculate H(A1) as per HTTP Digest spec + * @param env, pointer to env struct + * @param algorithm, algorithm + * @param user_name, user name + * @param realm, reaalm + * @param password, password + * @param nonce, nonce from server + * @param cnonce, client nonce + * @param session_key, H(A1) + * @return AXIS2_SUCCESS on success or AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_digest_calc_get_h_a1( + const axutil_env_t * env, + char * algorithm, + char * user_name, + char * realm, + char * password, + char * nonce, + char * cnonce, + axutil_digest_hash_hex_t session_key); + + /** + * calculate request-digest/response-digest as per HTTP Digest spec + * @param env, pointer to env struct + * @param h_a1, H(A1) + * @param nonce, nonce from server + * @param cnonce, client nonce + * @param qop, qop-value: "", "auth", "auth-int" + * @param method, method from the request + * @param digest_uri, requested URL + * @param h_entry, H(entity body) if qop="auth-int" + * @param response, request-digest or response-digest + * @return AXIS2_SUCCESS on success or AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_digest_calc_get_response( + const axutil_env_t * env, + axutil_digest_hash_hex_t h_a1, + char * nonce, + char * nonce_count, + char * cnonce, + char * qop, + char * method, + char * digest_uri, + axutil_digest_hash_hex_t h_entity, + axutil_digest_hash_hex_t response); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_DIGEST_CALC_H */ diff --git a/util/include/axutil_dir_handler.h b/util/include/axutil_dir_handler.h new file mode 100644 index 0000000..d66e42e --- /dev/null +++ b/util/include/axutil_dir_handler.h @@ -0,0 +1,73 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_DIR_HANDLER_H +#define AXUTIL_DIR_HANDLER_H + +#include <axutil_utils_defines.h> +#include <axutil_error.h> +#include <axutil_env.h> +#include <axutil_string.h> +#include <axutil_array_list.h> +#include <axutil_utils.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_dir_handler dir handler + * @ingroup axis2_util + * @{ + */ + + /** + * List the dll files in the given service or module folder path + * @param pathname path to your service or module directory + * @return array list of dll file names + */ + AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL + + axutil_dir_handler_list_services_or_modules_in_dir( + const axutil_env_t * env, + const axis2_char_t * pathname); + + /** + * List services or modules directories in the services or modules folder + * respectively + * @param pathname path your modules or services folder + * @return array list of contents of services or modules folder + */ + AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL + + axutil_dir_handler_list_service_or_module_dirs( + const axutil_env_t * env, + const axis2_char_t * pathname); + + /* + *extentions for module and service archives + */ +#define AXIS2_AAR_SUFFIX ".aar" +#define AXIS2_MAR_SUFFIX ".mar" + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_DIR_HANDLER_H */ diff --git a/util/include/axutil_dll_desc.h b/util/include/axutil_dll_desc.h new file mode 100644 index 0000000..30f69f1 --- /dev/null +++ b/util/include/axutil_dll_desc.h @@ -0,0 +1,191 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_DLL_DESC_H +#define AXUTIL_DLL_DESC_H + +/** + * @file axutil_dll_desc.h + * @brief Axis2 dll_desc interface + */ + +#include <axutil_utils_defines.h> +#include <axutil_qname.h> +#include <axutil_error.h> +#include <axutil_utils.h> +#include <platforms/axutil_platform_auto_sense.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_dll_desc DLL description + * @ingroup axis2_util + * @{ + */ + + typedef struct axutil_dll_desc axutil_dll_desc_t; + + typedef int( + *CREATE_FUNCT)( + void **inst, + const axutil_env_t * env); + + typedef int( + *DELETE_FUNCT)( + void *inst, + const axutil_env_t * env); + + typedef int axis2_dll_type_t; + + /** + * creates dll_desc struct + * @param qname qname, can be NULL + */ + AXIS2_EXTERN axutil_dll_desc_t *AXIS2_CALL + axutil_dll_desc_create( + const axutil_env_t * env); + + AXIS2_EXTERN void AXIS2_CALL + axutil_dll_desc_free_void_arg( + void *dll_desc, + const axutil_env_t * env); + + AXIS2_EXTERN void AXIS2_CALL + axutil_dll_desc_free( + axutil_dll_desc_t * dll_desc, + const axutil_env_t * env); + + /** + * Set path qualified platform specific dll name + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_dll_desc_set_name( + axutil_dll_desc_t * dll_desc, + const axutil_env_t * env, + axis2_char_t * name); + + /** + * Return the path qualified platform specific dll name + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_dll_desc_get_name( + axutil_dll_desc_t * dll_desc, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_dll_desc_set_type( + axutil_dll_desc_t * dll_desc, + const axutil_env_t * env, + axis2_dll_type_t type); + + AXIS2_EXTERN axis2_dll_type_t AXIS2_CALL + axutil_dll_desc_get_type( + axutil_dll_desc_t * dll_desc, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_dll_desc_set_load_options( + axutil_dll_desc_t * dll_desc, + const axutil_env_t * env, + int options); + + AXIS2_EXTERN int AXIS2_CALL + axutil_dll_desc_get_load_options( + axutil_dll_desc_t * dll_desc, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_dll_desc_set_dl_handler( + axutil_dll_desc_t * dll_desc, + const axutil_env_t * env, + AXIS2_DLHANDLER dl_handler); + + AXIS2_EXTERN AXIS2_DLHANDLER AXIS2_CALL + axutil_dll_desc_get_dl_handler( + axutil_dll_desc_t * dll_desc, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_dll_desc_set_create_funct( + axutil_dll_desc_t * dll_desc, + const axutil_env_t * env, + CREATE_FUNCT funct); + + AXIS2_EXTERN CREATE_FUNCT AXIS2_CALL + axutil_dll_desc_get_create_funct( + axutil_dll_desc_t * dll_desc, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_dll_desc_set_delete_funct( + axutil_dll_desc_t * dll_desc, + const axutil_env_t * env, + DELETE_FUNCT funct); + + AXIS2_EXTERN DELETE_FUNCT AXIS2_CALL + axutil_dll_desc_get_delete_funct( + axutil_dll_desc_t * dll_desc, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_dll_desc_set_timestamp( + axutil_dll_desc_t * dll_desc, + const axutil_env_t * env, + AXIS2_TIME_T timestamp); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_dll_desc_set_error_code( + axutil_dll_desc_t * dll_desc, + const axutil_env_t * env, + axutil_error_codes_t error_code); + + AXIS2_EXTERN axutil_error_codes_t AXIS2_CALL + + axutil_dll_desc_get_error_code( + axutil_dll_desc_t * dll_desc, + const axutil_env_t * env); + + AXIS2_EXTERN AXIS2_TIME_T AXIS2_CALL + axutil_dll_desc_get_timestamp( + axutil_dll_desc_t * dll_desc, + const axutil_env_t * env); + + /** + * This function will accept the library name without any platform + * dependant prefixes or suffixes. It then prefix and suffix + * platform dependant prefix and suffix macros to the original name + * and return the platform specific dll name + * + * @param class_name + * @return platform specific dll name + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + + axutil_dll_desc_create_platform_specific_dll_name( + axutil_dll_desc_t * dll_desc, + const axutil_env_t * env, + const axis2_char_t * class_name); + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_DLL_DESC_H */ diff --git a/util/include/axutil_duration.h b/util/include/axutil_duration.h new file mode 100644 index 0000000..7de4fda --- /dev/null +++ b/util/include/axutil_duration.h @@ -0,0 +1,181 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_DURATION_H +#define AXUTIL_DURATION_H + +#include <axutil_utils_defines.h> +#include <axutil_env.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_duration + * @ingroup axis2_util + * @{ + */ + + typedef struct axutil_duration axutil_duration_t; + + /** + * Creates axutil_duration struct with current date time + * @param env double pointer to environment struct. MUST NOT be NULL + * @return pointer to newly created axutil_duration struct + */ + AXIS2_EXTERN axutil_duration_t *AXIS2_CALL + axutil_duration_create( + axutil_env_t * env); + + AXIS2_EXTERN axutil_duration_t *AXIS2_CALL + + axutil_duration_create_from_values( + const axutil_env_t * env, + axis2_bool_t negative, + int years, + int months, + int days, + int hours, + int minutes, + double seconds); + + AXIS2_EXTERN axutil_duration_t *AXIS2_CALL + + axutil_duration_create_from_string( + const axutil_env_t * env, + const axis2_char_t * duration_str); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_duration_free( + axutil_duration_t * duration, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axutil_duration_deserialize_duration( + axutil_duration_t * duration, + const axutil_env_t * env, + const char *duration_str); + + AXIS2_EXTERN char *AXIS2_CALL + axutil_duration_serialize_duration( + axutil_duration_t * duration, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_duration_set_duration( + axutil_duration_t * duration, + const axutil_env_t * env, + axis2_bool_t negative, + int years, + int months, + int days, + int hours, + int mins, + double seconds); + + AXIS2_EXTERN int AXIS2_CALL + axutil_duration_get_years( + axutil_duration_t * duration, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_duration_set_years( + axutil_duration_t * duration, + const axutil_env_t * env, + int years); + + AXIS2_EXTERN int AXIS2_CALL + axutil_duration_get_months( + axutil_duration_t * duration, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_duration_set_months( + axutil_duration_t * duration, + const axutil_env_t * env, + int months); + + AXIS2_EXTERN int AXIS2_CALL + axutil_duration_get_days( + axutil_duration_t * duration, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_duration_set_days( + axutil_duration_t * duration, + const axutil_env_t * env, + int days); + + AXIS2_EXTERN int AXIS2_CALL + axutil_duration_get_hours( + axutil_duration_t * duration, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_duration_set_hours( + axutil_duration_t * duration, + const axutil_env_t * env, + int hours); + + AXIS2_EXTERN int AXIS2_CALL + axutil_duration_get_mins( + axutil_duration_t * duration, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_duration_set_mins( + axutil_duration_t * duration, + const axutil_env_t * env, + int mins); + + AXIS2_EXTERN double AXIS2_CALL + axutil_duration_get_seconds( + axutil_duration_t * duration, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_duration_set_seconds( + axutil_duration_t * duration, + const axutil_env_t * env, + double seconds); + + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + axutil_duration_get_is_negative( + axutil_duration_t * duration, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_duration_set_is_negative( + axutil_duration_t * duration, + const axutil_env_t * env, + axis2_bool_t is_negative); + + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + axutil_duration_compare( + axutil_duration_t * duration_one, + axutil_duration_t * duration_two, + axutil_env_t * env); + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_DURATION_H */ diff --git a/util/include/axutil_env.h b/util/include/axutil_env.h new file mode 100644 index 0000000..d59e5de --- /dev/null +++ b/util/include/axutil_env.h @@ -0,0 +1,233 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_ENV_H +#define AXUTIL_ENV_H + +/** + * @file axutil_env.h + * @brief Axis2 environment that acts as a container for error, log and memory + * allocator routines + */ + +#include <axutil_allocator.h> +#include <axutil_error.h> +#include <axutil_log.h> +#include <axutil_thread_pool.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axis2_util utilities + * @ingroup axis2 + * @{ + * @} + */ + + struct axutil_env; + struct axutil_env_ops; + + /** + * @defgroup axutil_env environment + * @ingroup axis2_util + * @{ + */ + + /** + * \brief Axis2 Environment struct + * + * Environment acts as a container for error, log, memory allocator and + * threading routines + */ + typedef struct axutil_env + { + + /** Memory allocation routines */ + axutil_allocator_t *allocator; + + /** Error handling */ + axutil_error_t *error; + + /** Logging routines */ + axutil_log_t *log; + + /** This flag indicate whether logging is enabled or not */ + axis2_bool_t log_enabled; + + /** Thread pool routines */ + axutil_thread_pool_t *thread_pool; + + int ref; + + axis2_status_t (*set_session_fn)(void*, const char*, const char*); + char * (*get_session_fn)(void*, const char*); + } + axutil_env_t; + + /** + * Creates an environment struct. Would include a default log and error + * structs within the created environment. By default, logging would be enabled + * and the default log level would be debug. + * @param allocator pointer to an instance of allocator struct. Must not be NULL + * @return pointer to the newly created environment struct + */ + AXIS2_EXTERN axutil_env_t *AXIS2_CALL + axutil_env_create( + axutil_allocator_t * allocator); + + /** + * Creates an environment struct with all of its default parts, + * that is an allocator, error, log and a thread pool. + * @param log_file name of the log file. If NULL, a default log would be created. + * @param log_level log level to be used. If not valid, debug would be + * used as the default log level + * @return pointer to the newly created environment struct + */ + AXIS2_EXTERN axutil_env_t *AXIS2_CALL + axutil_env_create_all( + const axis2_char_t * log_file, + const axutil_log_levels_t log_level); + + + /** + * Creates an environment struct with given error struct. + * @param allocator pointer to an instance of allocator struct. Must not be NULL + * @param error pointer to an instance of error struct. Must not be NULL + * @return pointer to the newly created environment struct + */ + AXIS2_EXTERN axutil_env_t *AXIS2_CALL + axutil_env_create_with_error( + axutil_allocator_t * allocator, + axutil_error_t * error); + + /** + * Creates an environment struct with given error and log structs. + * @param allocator pointer to an instance of allocator struct. Must not be NULL + * @param error pointer to an instance of error struct. Must not be NULL + * @param log pointer to an instance of log struct. If NULL it would be + * assumed that logging is disabled. + * @return pointer to the newly created environment struct + */ + AXIS2_EXTERN axutil_env_t *AXIS2_CALL + axutil_env_create_with_error_log( + axutil_allocator_t * allocator, + axutil_error_t * error, + axutil_log_t * log); + + /** + * Creates an environment struct with given error, log and thread pool structs. + * @param allocator pointer to an instance of allocator struct. Must not be NULL + * @param error pointer to an instance of error struct. Must not be NULL + * @param log pointer to an instance of log struct. If NULL it would be + * assumed that logging is disabled. + * @param pool pointer to an instance of thread_pool. Must not be NULL + * @return pointer to the newly created environment struct + */ + AXIS2_EXTERN axutil_env_t *AXIS2_CALL + axutil_env_create_with_error_log_thread_pool( + axutil_allocator_t * allocator, + axutil_error_t * error, + axutil_log_t * log, + axutil_thread_pool_t * pool); + + /** + * Enable or disable logging. + * @param env pointer to environment struct + * @param enable AXIS2_TRUE to enable logging and AXIS2_FALSE to + * disable logging + * @return AXIS2_SUCCESS on success else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_env_enable_log( + axutil_env_t * env, + axis2_bool_t enable); + + /** + * Checks the status code of environment stored within error struct. + * @param env pointer to environment struct + * @return error status code or AXIS2_CRITICAL_FAILURE in case of + * a failure + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_env_check_status( + const axutil_env_t * env); + + /** + * Frees an environment struct instance. + * @param env pointer to environment struct instance to be freed. + * @return void + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_env_free( + axutil_env_t * env); + + + #define AXIS_ENV_FREE_LOG 0x1 + #define AXIS_ENV_FREE_ERROR 0x2 + #define AXIS_ENV_FREE_THREADPOOL 0x4 + + /** + * Frees the environment components based on the mask. + * @param env pointer to environment struct to be freed + * @param mask bit pattern indicating which components of the env + * struct are to be freed + * AXIS_ENV_FREE_LOG - Frees the log + * AXIS_ENV_FREE_ERROR - Frees the error + * AXIS_ENV_FREE_THREADPOOL - Frees the thread pool + * You can use combinations to free multiple components as well + * E.g : AXIS_ENV_FREE_LOG | AXIS_ENV_FREE_ERROR frees both log and error, but not the thread pool + * @return void + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_env_free_masked( + axutil_env_t * env, + char mask); + + /** + * Incrent the reference count.This is used when objects are created + * using this env and keeping this for future use. + * @param env pointer to environment struct instance to be freed. + * @return void + */ + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_env_increment_ref( + axutil_env_t * env); + + + +/* AXIS2_ENV_CHECK is a macro to check environment pointer. + Currently this is set to an empty value. + But it was used to be defined as: + #define AXIS2_ENV_CHECK(env, error_return) \ + if(!env) \ + { \ + return error_return; \ + } +*/ +#define AXIS2_ENV_CHECK(env, error_return) + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_ENV_H */ diff --git a/util/include/axutil_error.h b/util/include/axutil_error.h new file mode 100644 index 0000000..3b27a81 --- /dev/null +++ b/util/include/axutil_error.h @@ -0,0 +1,876 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_ERROR_H +#define AXUTIL_ERROR_H + +#include <axutil_utils_defines.h> +#include <axutil_allocator.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + +#define AXUTIL_ERROR_MESSAGE_BLOCK_SIZE 512 +#define AXUTIL_ERROR_LAST AXUTIL_ERROR_MESSAGE_BLOCK_SIZE +#define NEETHI_ERROR_CODES_START AXIS2_ERROR_LAST +#define RAMPART_ERROR_CODES_START (NEETHI_ERROR_CODES_START + AXUTIL_ERROR_MESSAGE_BLOCK_SIZE) +#define SANDESHA2_ERROR_CODES_START (RAMPART_ERROR_CODES_START + AXUTIL_ERROR_MESSAGE_BLOCK_SIZE) +#define SAVAN_ERROR_CODES_START (SANDESHA2_ERROR_CODES_START + AXUTIL_ERROR_MESSAGE_BLOCK_SIZE) +#define USER_ERROR_CODES_START (SAVAN_ERROR_CODES_START + AXUTIL_ERROR_MESSAGE_BLOCK_SIZE) + +/* AXUTIL_ERROR_MAX define the maximum size of the error array */ +#define AXUTIL_ERROR_MAX (USER_ERROR_CODES_START + AXUTIL_ERROR_MESSAGE_BLOCK_SIZE) + + + /** + * \brief Axis2 status codes + * + * Possible status values for Axis2 + */ + enum axis2_status_codes + { + /** Critical Failure state */ + AXIS2_CRITICAL_FAILURE = -1, + + /** Failure state */ + AXIS2_FAILURE, + + /** Success state */ + AXIS2_SUCCESS + }; + + /** + * \brief Axis2 error codes + * + * Set of error codes for Axis2 + */ + enum axutil_error_codes + { + + /** + * No error. + * This must be the first error all the time and the assigned value of 0 + * must not be changed as it is assumed in the error message array that + * the error list starts with a value of 0. + * Further, none of the error codes in this enum should not be initialized + * to an arbitrary value as it is assumed in the implementation when mapping + * error codes to error messages that the error codes are contiguous and + * the last error value is always AXIS2_ERROR_LAST. + */ + AXIS2_ERROR_NONE = 0, + + /* + * Group - Common Errors + */ + + /** Out of memory */ + AXIS2_ERROR_NO_MEMORY, + + /** NULL parameter was passed when a non NULL parameter was expected */ + AXIS2_ERROR_INVALID_NULL_PARAM, + + /* + * Group - core:addr + */ + + /* + * Group - core:clientapi + */ + + /** Blocking invocation expects response */ + AXIS2_ERROR_BLOCKING_INVOCATION_EXPECTS_RESPONSE, + + /** cannot infer transport from URL */ + AXIS2_ERROR_CANNOT_INFER_TRANSPORT, + + /** Client side support only one configuration context */ + AXIS2_ERROR_CLIENT_SIDE_SUPPORT_ONLY_ONE_CONF_CTX, + /* MEP cannot be NULL in MEP client */ + AXIS2_ERROR_MEP_CANNOT_BE_NULL_IN_MEP_CLIENT, + /* MEP Mismatch */ + AXIS2_ERROR_MEP_MISMATCH_IN_MEP_CLIENT, + + /** Two way channel needs addressing module to be engaged */ + AXIS2_ERROR_TWO_WAY_CHANNEL_NEEDS_ADDRESSING, + + /** Unknown Transport */ + AXIS2_ERROR_UNKNOWN_TRANSPORT, + /* Unsupported SOAP style */ + AXIS2_ERROR_UNSUPPORTED_TYPE, + /* Options object is not set */ + AXIS2_ERROR_OPTIONS_OBJECT_IS_NOT_SET, + + /* Session Timeout */ + AXIS2_ERROR_SESSION_TIMEOUT, + /* + * Group - core:clientapi:diclient + */ + + /* + * Group - core:context + */ + + /** Invalid SOAP envelope state */ + AXIS2_ERROR_INVALID_SOAP_ENVELOPE_STATE, + + /** Invalid message context state */ + AXIS2_ERROR_INVALID_STATE_MSG_CTX, + + /** Service accessed has invalid state */ + AXIS2_ERROR_INVALID_STATE_SVC, + + /** Service group accessed has invalid state */ + AXIS2_ERROR_INVALID_STATE_SVC_GRP, + + /** Service not yet found */ + AXIS2_ERROR_SERVICE_NOT_YET_FOUND, + + /* + * Group - core:deployment + */ + /* Invalid phase found in phase validation */ + AXI2_ERROR_INVALID_PHASE, + /* axis2.xml cannot be found */ + AXIS2_ERROR_CONFIG_NOT_FOUND, + /* Data element of the OM Node is null */ + AXIS2_ERROR_DATA_ELEMENT_IS_NULL, + /* In transport sender, Inflow is not allowed */ + AXIS2_ERROR_IN_FLOW_NOT_ALLOWED_IN_TRS_OUT, + + /** Invalid handler state */ + AXIS2_ERROR_INVALID_HANDLER_STATE, + /* Invalid Module Ref encountered */ + AXIS2_ERROR_INVALID_MODUELE_REF, + /* Invalid Module Reference by Operation */ + AXIS2_ERROR_INVALID_MODUELE_REF_BY_OP, + /* Invalid Module Configuration */ + AXIS2_ERROR_INVALID_MODULE_CONF, + /* Description Builder is found to be in invalid state */ + AXIS2_ERROR_INVALID_STATE_DESC_BUILDER, + /* Module Not Found */ + AXIS2_ERROR_MODULE_NOT_FOUND, + /* Module Validation Failed */ + AXIS2_ERROR_MODULE_VALIDATION_FAILED, + + /** Module xml file is not found in the given path */ + AXIS2_ERROR_MODULE_XML_NOT_FOUND_FOR_THE_MODULE, + /* No dispatcher found */ + AXIS2_ERROR_NO_DISPATCHER_FOUND, + /* Operation name is missing */ + AXIS2_ERROR_OP_NAME_MISSING, + /* In transport Receiver, Outflow is not allowed */ + AXIS2_ERROR_OUT_FLOW_NOT_ALLOWED_IN_TRS_IN, + /* Repository name cannot be NULL */ + AXIS2_ERROR_REPO_CAN_NOT_BE_NULL, + /* Repository in path does not exist */ + AXIS2_ERROR_REPOSITORY_NOT_EXIST, + /* Repository Listener initialization failed */ + AXIS2_ERROR_REPOS_LISTENER_INIT_FAILED, + + /** Service xml file is not found in the given path */ + AXIS2_ERROR_SERVICE_XML_NOT_FOUND, + /* Service Name Error */ + AXIS2_ERROR_SVC_NAME_ERROR, + /* Transport Sender Error */ + AXIS2_ERROR_TRANSPORT_SENDER_ERROR, + /* Path to Config can not be NULL */ + AXIS2_PATH_TO_CONFIG_CAN_NOT_BE_NULL, + /* Invalid Service */ + AXIS2_ERROR_INVALID_SVC, + + + /* + * Group - core:description + */ + /* Cannot correlate message */ + AXIS2_ERROR_CANNOT_CORRELATE_MSG, + + /** Could not Map the MEP URI to a axis MEP constant value */ + AXIS2_ERROR_COULD_NOT_MAP_MEP_URI_TO_MEP_CONSTANT, + /* Invalid message addition , operation context completed */ + AXIS2_ERROR_INVALID_MESSAGE_ADDITION, + + /** Module description accessed has invalid state */ + AXIS2_ERROR_INVALID_STATE_MODULE_DESC, + + /** Parameter container not set */ + AXIS2_ERROR_INVALID_STATE_PARAM_CONTAINER, + + /** module has already engaged to the op op terminated !!! */ + AXIS2_ERROR_MODULE_ALREADY_ENGAGED_TO_OP, + + /** module has already been engaged on the service.Operation terminated !!! */ + AXIS2_ERROR_MODULE_ALREADY_ENGAGED_TO_SVC, + + /** module has already been engaged on the service. Group Operation terminated !!! */ + AXIS2_ERROR_MODULE_ALREADY_ENGAGED_TO_SVC_GRP, + + /** Parameter locked, Cannot override */ + AXIS2_ERROR_PARAMETER_LOCKED_CANNOT_OVERRIDE, + /* schema list is empty or NULL in svc */ + AXIS2_ERROR_EMPTY_SCHEMA_LIST, + /* + * Group - core:engine + */ + + /** Both before and after handlers cannot be the same */ + AXIS2_ERROR_BEFORE_AFTER_HANDLERS_SAME, + + /** Invalid handler rules */ + AXIS2_ERROR_INVALID_HANDLER_RULES, + /* Invalid Module */ + AXIS2_ERROR_INVALID_MODULE, + + /** Invalid first handler for phase */ + AXIS2_ERROR_INVALID_PHASE_FIRST_HANDLER, + + /** Invalid last handler for phase */ + AXIS2_ERROR_INVALID_PHASE_LAST_HANDLER, + + /** Invalid engine config state */ + AXIS2_ERROR_INVALID_STATE_CONF, + + /** Message context processing a fault already */ + AXIS2_ERROR_INVALID_STATE_PROCESSING_FAULT_ALREADY, + + /** fault to field not specified in message context */ + AXIS2_ERROR_NOWHERE_TO_SEND_FAULT, + + /** Only one handler allowed for phase, adding handler is not allowed */ + AXIS2_ERROR_PHASE_ADD_HANDLER_INVALID, + + /** First handler of phase already set */ + AXIS2_ERROR_PHASE_FIRST_HANDLER_ALREADY_SET, + + /** Last handler of phase already set */ + AXIS2_ERROR_PHASE_LAST_HANDLER_ALREADY_SET, + + /**Two service can not have same name, a service with same name already + exist in the system */ + AXIS2_ERROR_TWO_SVCS_CANNOT_HAVE_SAME_NAME, + /* + * Group - core:phase resolver + */ + /* Invalid Module Ref */ + AXIS2_ERROR_INVALID_MODULE_REF, + /* Invalid Phase */ + AXIS2_ERROR_INVALID_PHASE, + /* No Transport Receiver is configured */ + AXIS2_ERROR_NO_TRANSPORT_IN_CONFIGURED, + /* No Transport Sender is configured */ + AXIS2_ERROR_NO_TRANSPORT_OUT_CONFIGURED, + /* Phase is not specified */ + AXIS2_ERROR_PHASE_IS_NOT_SPECIFED, + /* Service module can not refer global phase */ + AXIS2_ERROR_SERVICE_MODULE_CAN_NOT_REFER_GLOBAL_PHASE, + + /* + * Group - core:wsdl + */ + + /** Schema is NULL */ + AXIS2_ERROR_WSDL_SCHEMA_IS_NULL, + /* + * Group - core:receivers + */ + /* Om Element has invalid state */ + AXIS2_ERROR_OM_ELEMENT_INVALID_STATE, + /* Om Elements do not match */ + AXIS2_ERROR_OM_ELEMENT_MISMATCH, + /* RPC style SOAP body don't have a child element */ + AXIS2_ERROR_RPC_NEED_MATCHING_CHILD, + /* Operation Description has unknown operation style */ + AXIS2_ERROR_UNKNOWN_STYLE, + /* String does not represent a valid NCName */ + AXIS2_ERROR_STRING_DOES_NOT_REPRESENT_A_VALID_NC_NAME, + /* + * Group - core:transport + */ + + /* + * Group - core:transport:http + */ + /* Error occurred in transport */ + AXIS2_ERROR_HTTP_CLIENT_TRANSPORT_ERROR, + + /** A read attempt(HTTP) for the reply without sending the request */ + AXIS2_ERROR_HTTP_REQUEST_NOT_SENT, + + /** Invalid string passed as a http header */ + AXIS2_ERROR_INVALID_HEADER, + /* Invalid header start line (request line or response line) */ + AXIS2_ERROR_INVALID_HTTP_HEADER_START_LINE, + /* Transport protocol is unsupported by axis2 */ + AXIS2_ERROR_INVALID_TRANSPORT_PROTOCOL, + + /** No body present in the request or the response */ + AXIS2_ERROR_NULL_BODY, + /* A valid conf_ctx is reqd for the http worker */ + AXIS2_ERROR_NULL_CONFIGURATION_CONTEXT, + /* HTTP version cannot be null in the status/request line */ + AXIS2_ERROR_NULL_HTTP_VERSION, + /* Input stream is NULL in msg_ctx */ + AXIS2_ERROR_NULL_IN_STREAM_IN_MSG_CTX, + /* OM output is NULL */ + AXIS2_ERROR_NULL_OM_OUTPUT, + /* Null SOAP envelope in msg_ctx */ + AXIS2_ERROR_NULL_SOAP_ENVELOPE_IN_MSG_CTX, + /* NULL stream in the http chucked stream */ + AXIS2_ERROR_NULL_STREAM_IN_CHUNKED_STREAM, + /* We got a NULL stream in the response body */ + AXIS2_ERROR_NULL_STREAM_IN_RESPONSE_BODY, + + /** URL NULL in http client */ + AXIS2_ERROR_NULL_URL, + /** Invalid URL format */ + AXIS2_ERROR_INVALID_URL_FORMAT, + /** Duplicate URL REST Mapping */ + AXIS2_ERROR_DUPLICATE_URL_REST_MAPPING, + /* We need transport_info in msg_ctx */ + AXIS2_ERROR_OUT_TRNSPORT_INFO_NULL, + /*Content-Type header missing in HTTP response" */ + AXIS2_ERROR_RESPONSE_CONTENT_TYPE_MISSING, + + /** Response timed out */ + AXIS2_ERROR_RESPONSE_TIMED_OUT, + + /** Server shutdown*/ + AXIS2_ERROR_RESPONSE_SERVER_SHUTDOWN, + + /** SOAP envelope or SOAP body NULL */ + AXIS2_ERROR_SOAP_ENVELOPE_OR_SOAP_BODY_NULL, + /* Error occurred in SSL engine */ + AXIS2_ERROR_SSL_ENGINE, + /* Either axis2c cannot find certificates or the env variable is not set */ + AXIS2_ERROR_SSL_NO_CA_FILE, + /* Error in writing the response in response writer */ + AXIS2_ERROR_WRITING_RESPONSE, + /* Required parameter is missing in URL encoded request */ + AXIS2_ERROR_REQD_PARAM_MISSING, + /* Unsupported schema type in REST */ + AXIS2_ERROR_UNSUPPORTED_SCHEMA_TYPE, + /* Service or operation not found */ + AXIS2_ERROR_SVC_OR_OP_NOT_FOUND, + /* + * Group - mod_addr + */ + AXIS2_ERROR_NO_MSG_INFO_HEADERS, + /* + * Group - platforms + */ + + /* + * Group - utils + */ + + /** Could not open the axis2 file */ + AXIS2_ERROR_COULD_NOT_OPEN_FILE, + /* Failed in creating DLL */ + AXIS2_ERROR_DLL_CREATE_FAILED, + /* DLL loading failed */ + AXIS2_ERROR_DLL_LOADING_FAILED, + + /** Environment passed is null */ + AXIS2_ERROR_ENVIRONMENT_IS_NULL, + /* Axis2 File does not have a file name */ + AXIS2_ERROR_FILE_NAME_NOT_SET, + /* DLL Description Info Object has invalid state */ + AXIS2_ERROR_INVALID_STATE_DLL_DESC, + /* Failed in creating Handler */ + AXIS2_ERROR_HANDLER_CREATION_FAILED, + + /** Array list index out of bounds */ + AXIS2_ERROR_INDEX_OUT_OF_BOUNDS, + + /** Invalid IP or host name */ + AXIS2_ERROR_INVALID_ADDRESS, + + /** Trying to do operation on invalid file descriptor */ + AXIS2_ERROR_INVALID_FD, + + /** Trying to do operation on closed/not opened socket */ + AXIS2_ERROR_INVALID_SOCKET, + + /** Parameter not set */ + AXIS2_ERROR_INVALID_STATE_PARAM, + /* Module create failed */ + AXIS2_ERROR_MODULE_CREATION_FAILED, + /* Failed in creating Message Receiver */ + AXIS2_ERROR_MSG_RECV_CREATION_FAILED, + + /** No such element */ + AXIS2_ERROR_NO_SUCH_ELEMENT, + + /** Socket bind failed. Another process may be already using this port*/ + AXIS2_ERROR_SOCKET_BIND_FAILED, + + /** Error creating a socket. Most probably error returned by OS */ + AXIS2_ERROR_SOCKET_ERROR, + /* Listen failed for the server socket */ + AXIS2_ERROR_SOCKET_LISTEN_FAILED, + /* Failed in creating Service Skeleton */ + AXIS2_ERROR_SVC_SKELETON_CREATION_FAILED, + /* Failed in creating Transport Receiver */ + AXIS2_ERROR_TRANSPORT_RECV_CREATION_FAILED, + /* Failed in creating Transport Sender */ + AXIS2_ERROR_TRANSPORT_SENDER_CREATION_FAILED, + /* Generation of platform dependent uuid failed */ + AXIS2_ERROR_UUID_GEN_FAILED, + /* Possible deadlock */ + AXIS2_ERROR_POSSIBLE_DEADLOCK, + /* + * Group - WSDL + */ + /* Interface or Port Type not found for the binding */ + AXIS2_ERROR_INTERFACE_OR_PORT_TYPE_NOT_FOUND_FOR_THE_BINDING, + /* Interfaces or Ports not found for the partially built WOM */ + AXIS2_ERROR_INTERFACES_OR_PORTS_NOT_FOUND_FOR_PARTIALLY_BUILT_WOM, + + /** Wsdl op accessed has invalid state */ + AXIS2_ERROR_INVALID_STATE_WSDL_OP, + + /** Wsdl Service accessed has invalid state */ + AXIS2_ERROR_INVALID_STATE_WSDL_SVC, + /* Cannot determine MEP */ + AXIS2_ERROR_MEP_CANNOT_DETERMINE_MEP, + /* Wsdl binding name cannot be NULL(Is required) */ + AXIS2_ERROR_WSDL_BINDING_NAME_IS_REQUIRED, + /* PortType/Interface name cannot be null(Required) */ + AXIS2_ERROR_WSDL_INTERFACE_NAME_IS_REQUIRED, + /* Wsdl parsing has resulted in an invalid state */ + AXIS2_ERROR_WSDL_PARSER_INVALID_STATE, + /* Wsdl svc name cannot be null(Required) */ + AXIS2_ERROR_WSDL_SVC_NAME_IS_REQUIRED, + /* + * Group - xml + */ + + /* + * Group - xml:attachments + */ + /** Attachment is missing */ + AXIS2_ERROR_ATTACHMENT_MISSING, + + /* + * Group - xml:om + */ + + /** Builder done with pulling. Cannot pull any more */ + AXIS2_ERROR_BUILDER_DONE_CANNOT_PULL, + + /** Discard failed because the builder state is invalid */ + AXIS2_ERROR_INVALID_BUILDER_STATE_CANNOT_DISCARD, + + /** Builder's last node is NULL when it is not supposed to be NULL */ + AXIS2_ERROR_INVALID_BUILDER_STATE_LAST_NODE_NULL, + + /** Document root is NULL, when it is not supposed to be NULL */ + AXIS2_ERROR_INVALID_DOCUMENT_STATE_ROOT_NULL, + + /** Undefined namespace used */ + AXIS2_ERROR_INVALID_DOCUMENT_STATE_UNDEFINED_NAMESPACE, + + /** error a namespace should have a valid uri */ + AXIS2_ERROR_INVALID_EMPTY_NAMESPACE_URI, + + /** next method has not been called so cannot remove + an element before calling next valid for any om iterator */ + AXIS2_ERROR_ITERATOR_NEXT_METHOD_HAS_NOT_YET_BEEN_CALLED, + + /** remove method has already been called once so cannot remove till + next method is called valid for any om children iterator*/ + AXIS2_ERROR_ITERATOR_REMOVE_HAS_ALREADY_BEING_CALLED, + + /** axiom_xml_reader returned NULL element */ + AXIS2_ERROR_XML_READER_ELEMENT_NULL, + + /** axiom_xml_reader returned NULL value */ + AXIS2_ERROR_XML_READER_VALUE_NULL, + /* + * Group - xml:parser + */ + + /** error occurred creating xml stream reader */ + AXIS2_ERROR_CREATING_XML_STREAM_READER, + + /** error occurred creating xml stream writer */ + AXIS2_ERROR_CREATING_XML_STREAM_WRITER, + + /** error in writing attribute */ + AXIS2_ERROR_WRITING_ATTRIBUTE, + + /** error in writing attribute with namespace */ + AXIS2_ERROR_WRITING_ATTRIBUTE_WITH_NAMESPACE, + + /** error in writing attribute with namespace prefix */ + AXIS2_ERROR_WRITING_ATTRIBUTE_WITH_NAMESPACE_PREFIX, + + /** error in writing comment */ + AXIS2_ERROR_WRITING_COMMENT, + + /** error in writing data source*/ + AXIS2_ERROR_WRITING_DATA_SOURCE, + + /** error in writing default namespace */ + AXIS2_ERROR_WRITING_DEFAULT_NAMESPACE, + + /** error in writing DDT */ + AXIS2_ERROR_WRITING_DTD, + + /** error occurred in writing empty element */ + AXIS2_ERROR_WRITING_EMPTY_ELEMENT, + + /** error occurred in writing empty element with namespace */ + AXIS2_ERROR_WRITING_EMPTY_ELEMENT_WITH_NAMESPACE, + + /** error in writing empty element with namespace prefix */ + AXIS2_ERROR_WRITING_EMPTY_ELEMENT_WITH_NAMESPACE_PREFIX, + + /** error occurred in writing end document in xml writer */ + AXIS2_ERROR_WRITING_END_DOCUMENT, + + /** error occurred in writing end element in xml writer */ + AXIS2_ERROR_WRITING_END_ELEMENT, + + /** error in writing processing instruction */ + AXIS2_ERROR_WRITING_PROCESSING_INSTRUCTION, + + /** error occurred in writing start element in start document in xml writer */ + AXIS2_ERROR_WRITING_START_DOCUMENT, + + /** error occurred in writing start element in xml writer */ + AXIS2_ERROR_WRITING_START_ELEMENT, + + /** error occurred in writing start element with namespace in xml writer*/ + AXIS2_ERROR_WRITING_START_ELEMENT_WITH_NAMESPACE, + + /** error occurred in writing start element with namespace prefix */ + AXIS2_ERROR_WRITING_START_ELEMENT_WITH_NAMESPACE_PREFIX, + + /** error in writing cdata section */ + AXIS2_ERROR_WRITING_CDATA, + + /** AXIS2_XML_PARSER_TYPE_BUFFER or AXIS2_XML_PARSER_TYPE_DOC is expected */ + AXIS2_ERROR_XML_PARSER_INVALID_MEM_TYPE, + + /* + * Group - xml:SOAP + */ + + /** invalid type passed */ + AXIS2_ERROR_INVALID_BASE_TYPE, + + /** invalid SOAP namespace uri found */ + AXIS2_ERROR_INVALID_SOAP_NAMESPACE_URI, + + /** Invalid SOAP version */ + AXIS2_ERROR_INVALID_SOAP_VERSION, + /* invalid value found in must understand attribute */ + AXIS2_ERROR_INVALID_VALUE_FOUND_IN_MUST_UNDERSTAND, + /*multiple code elements encountered in SOAP fault element */ + AXIS2_ERROR_MULTIPLE_CODE_ELEMENTS_ENCOUNTERED, + /*multiple detail elements encountered in SOAP fault element */ + AXIS2_ERROR_MULTIPLE_DETAIL_ELEMENTS_ENCOUNTERED, + /*multiple node elements encountered in SOAP fault element */ + AXIS2_ERROR_MULTIPLE_NODE_ELEMENTS_ENCOUNTERED, + /*multiple reason elements encountered in SOAP fault element */ + AXIS2_ERROR_MULTIPLE_REASON_ELEMENTS_ENCOUNTERED, + /*multiple role elements encountered in SOAP fault element */ + AXIS2_ERROR_MULTIPLE_ROLE_ELEMENTS_ENCOUNTERED, + /*multiple sub code values encountered in SOAP fault element */ + AXIS2_ERROR_MULTIPLE_SUB_CODE_VALUES_ENCOUNTERED, + /* multiple value elements encountered */ + AXIS2_ERROR_MULTIPLE_VALUE_ENCOUNTERED_IN_CODE_ELEMENT, + /* must understand attribute should have values of true or false */ + AXIS2_ERROR_MUST_UNDERSTAND_SHOULD_BE_1_0_TRUE_FALSE, + + /** om element is expected */ + AXIS2_ERROR_OM_ELEMENT_EXPECTED, + /* processing SOAP 1.1 fault value element should have only + text as its children */ + AXIS2_ERROR_ONLY_CHARACTERS_ARE_ALLOWED_HERE, + + /** only one SOAP fault allowed in SOAP body */ + AXIS2_ERROR_ONLY_ONE_SOAP_FAULT_ALLOWED_IN_BODY, + /*SOAP 1.1 fault actor element should not have child elements */ + AXIS2_ERROR_SOAP11_FAULT_ACTOR_SHOULD_NOT_HAVE_CHILD_ELEMENTS, + + /** SOAP builder found a child element other than header or body in envelope + element */ + AXIS2_ERROR_SOAP_BUILDER_ENVELOPE_CAN_HAVE_ONLY_HEADER_AND_BODY, + + /** SOAP builder encountered body element first and header next */ + AXIS2_ERROR_SOAP_BUILDER_HEADER_BODY_WRONG_ORDER, + + /** SOAP builder multiple body elements encountered */ + AXIS2_ERROR_SOAP_BUILDER_MULTIPLE_BODY_ELEMENTS_ENCOUNTERED, + + /** SOAP builder encountered multiple headers */ + AXIS2_ERROR_SOAP_BUILDER_MULTIPLE_HEADERS_ENCOUNTERED, + /*SOAP fault code element should a mandatory fault value element */ + AXIS2_ERROR_SOAP_FAULT_CODE_DOES_NOT_HAVE_A_VALUE, + /*SOAP fault reason element should have a text */ + AXIS2_ERROR_SOAP_FAULT_REASON_ELEMENT_SHOULD_HAVE_A_TEXT, + /*SOAP fault role element should have a text value */ + AXIS2_ERROR_SOAP_FAULT_ROLE_ELEMENT_SHOULD_HAVE_A_TEXT, + /* SOAP fault value should be present before sub code element in SOAP fault code */ + AXIS2_ERROR_SOAP_FAULT_VALUE_SHOULD_BE_PRESENT_BEFORE_SUB_CODE, + + /** SOAP message does not have an envelope element */ + AXIS2_ERROR_SOAP_MESSAGE_DOES_NOT_CONTAIN_AN_ENVELOPE, + /*SOAP message first element must contain a localname */ + AXIS2_ERROR_SOAP_MESSAGE_FIRST_ELEMENT_MUST_CONTAIN_LOCAL_NAME, + /* this localname is not supported inside a reason element */ + AXIS2_ERROR_THIS_LOCALNAME_IS_NOT_SUPPORTED_INSIDE_THE_REASON_ELEMENT, + /*this localname is not supported inside a sub code element */ + AXIS2_ERROR_THIS_LOCALNAME_IS_NOT_SUPPORTED_INSIDE_THE_SUB_CODE_ELEMENT, + /*this localname is not supported inside the code element */ + AXIS2_ERROR_THIS_LOCALNAME_NOT_SUPPORTED_INSIDE_THE_CODE_ELEMENT, + /*transport level identified SOAP version does not match with the SOAP version */ + AXIS2_ERROR_TRANSPORT_LEVEL_INFORMATION_DOES_NOT_MATCH_WITH_SOAP, + /*unsupported element in SOAP fault element */ + AXIS2_ERROR_UNSUPPORTED_ELEMENT_IN_SOAP_FAULT_ELEMENT, + /*wrong element order encountered */ + AXIS2_ERROR_WRONG_ELEMENT_ORDER_ENCOUNTERED, + /* + * Group - services + */ + + /** Invalid XML format in request */ + AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, + + /** Input OM node NULL, Probably error in SOAP request */ + AXIS2_ERROR_SVC_SKEL_INPUT_OM_NODE_NULL, + + /** Invalid parameters for service operation in SOAP request */ + AXIS2_ERROR_SVC_SKEL_INVALID_OPERATION_PARAMETERS_IN_SOAP_REQUEST, + + /* + * Group - repos + */ + /* not authenticated */ + AXIS2_ERROR_REPOS_NOT_AUTHENTICATED, + /* unsupported mode */ + AXIS2_ERROR_REPOS_UNSUPPORTED_MODE, + /* expired */ + AXIS2_ERROR_REPOS_EXPIRED, + /* not implemented */ + AXIS2_ERROR_REPOS_NOT_IMPLEMENTED, + /* not found */ + AXIS2_ERROR_REPOS_NOT_FOUND, + /* bad search text */ + AXIS2_ERROR_REPOS_BAD_SEARCH_TEXT, + + /* + *Group - Neethi + */ + /* No Namespace */ + AXIS2_ERROR_NEETHI_ELEMENT_WITH_NO_NAMESPACE, + /*Policy cannot be created from element */ + AXIS2_ERROR_NEETHI_POLICY_CREATION_FAILED_FROM_ELEMENT, + /*All Cannot be created from element */ + AXIS2_ERROR_NEETHI_ALL_CREATION_FAILED_FROM_ELEMENT, + /*Exactly one Cannot be created element */ + AXIS2_ERROR_NEETHI_EXACTLYONE_CREATION_FAILED_FROM_ELEMENT, + /*Reference Cannot be created from element */ + AXIS2_ERROR_NEETHI_REFERENCE_CREATION_FAILED_FROM_ELEMENT, + /*Assertion Cannot be created from element */ + AXIS2_ERROR_NEETHI_ASSERTION_CREATION_FAILED_FROM_ELEMENT, + /*All creation failed */ + AXIS2_ERROR_NEETHI_ALL_CREATION_FAILED, + /*Exactly one creation failed */ + AXIS2_ERROR_NEETHI_EXACTLYONE_CREATION_FAILED, + /*Policy Creation failed */ + AXIS2_ERROR_NEETHI_POLICY_CREATION_FAILED, + /*Normalization failed */ + AXIS2_ERROR_NEETHI_NORMALIZATION_FAILED, + /*Merging Failed. Wrong Input */ + AXIS2_ERROR_NEETHI_WRONG_INPUT_FOR_MERGE, + /*Merging Failed. Cross Product failed */ + AXIS2_ERROR_NEETHI_CROSS_PRODUCT_FAILED, + /*No Children Policy Components */ + AXIS2_ERROR_NEETHI_NO_CHILDREN_POLICY_COMPONENTS, + /*Uri Not specified */ + AXIS2_ERROR_NEETHI_URI_NOT_SPECIFIED, + /*Policy NULL for the given uri */ + AXIS2_ERROR_NEETHI_NO_ENTRY_FOR_THE_GIVEN_URI, + /*Exactly one not found in Normalized policy */ + AXIS2_ERROR_NEETHI_EXACTLYONE_NOT_FOUND_IN_NORMALIZED_POLICY, + /*Exactly one is Empty */ + AXIS2_ERROR_NEETHI_EXACTLYONE_IS_EMPTY, + /*Exactly one not found while getting cross product */ + AXIS2_ERROR_NEETHI_ALL_NOT_FOUND_WHILE_GETTING_CROSS_PRODUCT, + /*Unknown Assertion*/ + AXIS2_ERROR_NEETHI_UNKNOWN_ASSERTION, + /** + * The following has to be the last error value all the time. + * All other error codes should appear above this. + * AXIS2_ERROR_LAST is used to track the number of error codes present + * for the purpose of sizing the error messages array. + */ + AXIS2_ERROR_LAST + }; + + struct axutil_error; + typedef enum axis2_status_codes axis2_status_codes_t; + typedef enum axutil_error_codes axutil_error_codes_t; + + /** + * @defgroup axutil_error error + * @ingroup axis2_util + * @{ + */ + + /** + * Axutil error struct. + * Error holds the last error number, the status code as well as the + * last error message. + */ + typedef struct axutil_error + { + /** + * Memory allocator associated with the error struct. + * It is this allocator that would be used to allocate memory + * for the error struct instance in create method. + */ + axutil_allocator_t *allocator; + + /** Last error number. */ + int error_number; + /** Last status code. */ + int status_code; + /** + * Error message. This could be set to a custom message to be + * returned, instead of standard errors set in the error messages + * array by the axutil_error_init function call. + */ + axis2_char_t *message; + } + axutil_error_t; + + /** + * Gets the error message corresponding to the last error occurred. + * @param error pointer to error struct + * @return string representing the error message for the last error occurred + */ + AXIS2_EXTERN const axis2_char_t *AXIS2_CALL + axutil_error_get_message( + const struct axutil_error *error); + + /** + * This function is supposed to be overridden in an extended error structure. + * For example in Sandesha error structure this function is overridden so that + * errors of axis2 range call the get_message function of error struct but + * errors of sandesha2 range get the messages from an array of that struct. + * @return error message for the extended struct. + * @deprecated this function is not in use, so should be removed. + */ + /*AXIS2_EXTERN const axis2_char_t *AXIS2_CALL + axutil_error_get_extended_message( + const struct axutil_error *error);*/ + + /** + * Sets the error number. + * @param error pointer to error struct + * @param error_number error number to be set + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_error_set_error_number( + struct axutil_error *error, + axutil_error_codes_t error_number); + + /** + * Sets the status code. + * @param error pointer to error struct + * @param status_code status code to be set + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_error_set_status_code( + struct axutil_error *error, + axis2_status_codes_t status_code); + + /** + * Gets the status code. + * @param error pointer to error struct + * @return last status code set on error struct + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_error_get_status_code( + struct axutil_error *error); + + /** + * Sets error message to the given value. + * @param error pointer to error struct + * @param message error message to be set + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_error_set_error_message( + struct axutil_error *error, + axis2_char_t *message); + + /** + * Initializes the axutil_error_messages array. This array holds the + * error messages that corresponds to the error codes. This function + * must be call before using the error struct instance. + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_error_init(void); + + /** + * De-allocates an error struct instance. + * @param error pointer to error struct instance to be freed. + * @return void + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_error_free( + struct axutil_error *error); + +/** + * @deprecated The following macros are no longer useful as we can use the + * function calls directly. Hence these macros should be removed + */ + +#define AXIS2_ERROR_FREE(error) axutil_error_free(error) + +#define AXIS2_ERROR_GET_MESSAGE(error) \ + axutil_error_get_message(error) + +#define AXIS2_ERROR_SET_MESSAGE(error, message) \ + axutil_error_set_error_message(error, message) + +#define AXIS2_ERROR_SET_ERROR_NUMBER(error, error_number) \ + axutil_error_set_error_number(error, error_number) + +#define AXIS2_ERROR_SET_STATUS_CODE(error, status_code) \ + axutil_error_set_status_code(error, status_code) + +#define AXIS2_ERROR_GET_STATUS_CODE(error) axutil_error_get_status_code(error) + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_ERROR_H */ diff --git a/util/include/axutil_error_default.h b/util/include/axutil_error_default.h new file mode 100644 index 0000000..82a611c --- /dev/null +++ b/util/include/axutil_error_default.h @@ -0,0 +1,52 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_ERROR_DEFAULT_H +#define AXUTIL_ERROR_DEFAULT_H + +#include <axutil_utils_defines.h> +#include <axutil_allocator.h> +#include <axutil_error.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_error error + * @ingroup axis2_util + * @{ + */ + + /** + * Creates an error struct + * @param allocator allocator to be used. Mandatory, cannot be NULL + * @return pointer to the newly created error struct + */ + AXIS2_EXTERN axutil_error_t *AXIS2_CALL + axutil_error_create( + axutil_allocator_t * allocator); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_ERROR_DEFAULT_H */ diff --git a/util/include/axutil_file.h b/util/include/axutil_file.h new file mode 100644 index 0000000..d03e4df --- /dev/null +++ b/util/include/axutil_file.h @@ -0,0 +1,99 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_FILE_H +#define AXUTIL_FILE_H + +#include <axutil_utils_defines.h> +#include <axutil_error.h> +#include <axutil_env.h> +#include <axutil_utils.h> +#include <platforms/axutil_platform_auto_sense.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct axutil_file axutil_file_t; + + /** + * @defgroup axutil_file file + * @ingroup axis2_util + * @{ + */ + + /** + * create new file + * @return file newly created file + */ + AXIS2_EXTERN axutil_file_t *AXIS2_CALL + axutil_file_create( + const axutil_env_t * env); + + AXIS2_EXTERN void AXIS2_CALL + axutil_file_free( + axutil_file_t * file, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_file_set_name( + axutil_file_t * file, + const axutil_env_t * env, + axis2_char_t * name); + + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_file_get_name( + axutil_file_t * file, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_file_set_path( + axutil_file_t * file, + const axutil_env_t * env, + axis2_char_t * path); + + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_file_get_path( + axutil_file_t * file, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_file_set_timestamp( + axutil_file_t * file, + const axutil_env_t * env, + AXIS2_TIME_T timestamp); + + AXIS2_EXTERN AXIS2_TIME_T AXIS2_CALL + axutil_file_get_timestamp( + axutil_file_t * file, + const axutil_env_t * env); + + /** + * create a newly allocated clone of the argument file + */ + AXIS2_EXTERN axutil_file_t *AXIS2_CALL + axutil_file_clone( + axutil_file_t * file, + const axutil_env_t * env); + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_FILE_H */ diff --git a/util/include/axutil_file_handler.h b/util/include/axutil_file_handler.h new file mode 100644 index 0000000..18bc92a --- /dev/null +++ b/util/include/axutil_file_handler.h @@ -0,0 +1,91 @@ + +/* + * 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 count 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 AXUTIL_FILE_HANDLER_H +#define AXUTIL_FILE_HANDLER_H + +#include <axutil_string.h> +#include <stdio.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_file_handler file handler + * @ingroup axis2_util + * @{ + */ + + /** + * open a file for read according to the file options given + * @param file_name file to be opened + * @param options file options given. + * @return status code + */ + AXIS2_EXTERN void *AXIS2_CALL + axutil_file_handler_open( + const char *file_name, + const char *options); + + /** + * close a file + * @param file_ptr file pointer of the file need to be closed + * @return status code + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_file_handler_close( + void *file_ptr); + + /** + * determine accessibility of file + * checks the named file for accessibility according to mode + * @param path path name naming a file + * @param mode + * AXIS2_R_OK + * - test for read permission + * AXIS2_W_OK + * - test for write permission + * AXIS2_X_OK + * - test for execute or search permission + * AXIS2_F_OK + * - test whether the directories leading to the file can be searched and the + * file exists + * @return status + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_file_handler_access( + const axis2_char_t * path, + int mode); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_file_handler_copy( + FILE *from, + FILE *to); + + AXIS2_EXTERN long AXIS2_CALL + axutil_file_handler_size( + const axis2_char_t *const name); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_FILE_HANDLER_H */ diff --git a/util/include/axutil_generic_obj.h b/util/include/axutil_generic_obj.h new file mode 100644 index 0000000..b724b9a --- /dev/null +++ b/util/include/axutil_generic_obj.h @@ -0,0 +1,85 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_GENERIC_OBJ_H +#define AXUTIL_GENERIC_OBJ_H + +#include <axutil_utils_defines.h> +#include <axutil_error.h> +#include <axutil_env.h> +#include <axutil_utils.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct axutil_generic_obj axutil_generic_obj_t; + + /** + * @defgroup axutil_generic_obj generic object + * @ingroup axis2_util + * @{ + */ + + /** + * create new generic_obj + * @return generic_obj newly created generic_obj + */ + AXIS2_EXTERN axutil_generic_obj_t *AXIS2_CALL + axutil_generic_obj_create( + const axutil_env_t * env); + + AXIS2_EXTERN void AXIS2_CALL + axutil_generic_obj_free( + axutil_generic_obj_t * generic_obj, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_generic_obj_set_free_func( + axutil_generic_obj_t * generic_obj, + const axutil_env_t * env, + AXIS2_FREE_VOID_ARG free_func); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_generic_obj_set_value( + axutil_generic_obj_t * generic_obj, + const axutil_env_t * env, + void *value); + + AXIS2_EXTERN void *AXIS2_CALL + axutil_generic_obj_get_value( + axutil_generic_obj_t * generic_obj, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_generic_obj_set_type( + axutil_generic_obj_t * generic_obj, + const axutil_env_t * env, + int type); + + AXIS2_EXTERN int AXIS2_CALL + axutil_generic_obj_get_type( + axutil_generic_obj_t * generic_obj, + const axutil_env_t * env); + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_GENERIC_OBJ_H */ diff --git a/util/include/axutil_hash.h b/util/include/axutil_hash.h new file mode 100644 index 0000000..084f2bc --- /dev/null +++ b/util/include/axutil_hash.h @@ -0,0 +1,301 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_HASH_H +#define AXUTIL_HASH_H + +/** + * @file axutil_hash.h + * @brief Axis2 Hash Tables + */ + +#include <axutil_utils_defines.h> +#include <axutil_env.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_hash hash + * @ingroup axis2_util + * @{ + */ + + /** + * When passing a key to axutil_hash_set or axutil_hash_get, this value can be + * passed to indicate a string-valued key, and have axutil_hash compute the + * length automatically. + * + * @remark axutil_hash will use strlen(key) for the length. The NUL terminator + * is not included in the hash value (why throw a constant in?). + * Since the hash table merely references the provided key (rather + * than copying it), axutil_hash_this() will return the NUL-term'd key. + */ +#define AXIS2_HASH_KEY_STRING (unsigned int)(-1) + + /** + * Abstract type for hash tables. + */ + typedef struct axutil_hash_t axutil_hash_t; + + /** + * Abstract type for scanning hash tables. + */ + typedef struct axutil_hash_index_t axutil_hash_index_t; + + /** + * Callback functions for calculating hash values. + * @param key The key. + * @param klen The length of the key, or AXIS2_HASH_KEY_STRING to use the string + * length. If AXIS2_HASH_KEY_STRING then returns the actual key length. + */ + typedef unsigned int( + *axutil_hashfunc_t)( + const char *key, + axis2_ssize_t * klen); + + /** + * The default hash function. + */ + unsigned int axutil_hashfunc_default( + const char *key, + axis2_ssize_t * klen); + + /** + * Create a hash table. + * @param env The environment to allocate the hash table out of + * @return The hash table just created + */ + AXIS2_EXTERN axutil_hash_t *AXIS2_CALL + axutil_hash_make( + const axutil_env_t * env); + + /** + * Create a hash table with a custom hash function + * @param env The environment to allocate the hash table out of + * @param hash_func A custom hash function. + * @return The hash table just created + */ + AXIS2_EXTERN axutil_hash_t *AXIS2_CALL + axutil_hash_make_custom( + const axutil_env_t * env, + axutil_hashfunc_t hash_func); + + /** + * Make a copy of a hash table + * @param ht The hash table to clone + * @param env The environment from which to allocate the new hash table + * @return The hash table just created + * @remark Makes a shallow copy + */ + AXIS2_EXTERN axutil_hash_t *AXIS2_CALL + axutil_hash_copy( + const axutil_hash_t * ht, + const axutil_env_t * env); + + /** + * Associate a value with a key in a hash table. + * @param ht The hash table + * @param key Pointer to the key + * @param klen Length of the key. Can be AXIS2_HASH_KEY_STRING to use the string length. + * @param val Value to associate with the key + * @remark If the value is NULL the hash entry is deleted. + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_hash_set( + axutil_hash_t * ht, + const void *key, + axis2_ssize_t klen, + const void *val); + + /** + * Look up the value associated with a key in a hash table. + * @param ht The hash table + * @param key Pointer to the key + * @param klen Length of the key. Can be AXIS2_HASH_KEY_STRING to use the string length. + * @return Returns NULL if the key is not present. + */ + AXIS2_EXTERN void *AXIS2_CALL + axutil_hash_get( + axutil_hash_t * ht, + const void *key, + axis2_ssize_t klen); + + /** + * Start iterating over the entries in a hash table. + * @param ht The hash table + * @param p The environment to allocate the axutil_hash_index_t iterator. If this + * environment is NULL, then an internal, non-thread-safe iterator is used. + * @remark There is no restriction on adding or deleting hash entries during + * an iteration (although the results may be unpredictable unless all you do + * is delete the current entry) and multiple iterations can be in + * progress at the same time. + + * @example + */ + + /** + * <PRE> + * + * int sum_values(const axutil_env_t *env, axutil_hash_t *ht) + * { + * axutil_hash_index_t *hi; + * void *val; + * int sum = 0; + * for (hi = axutil_hash_first(p, ht); hi; hi = axutil_hash_next(p, hi)) { + * axutil_hash_this(hi, NULL, NULL, &val); + * sum += *(int *)val; + * } + * return sum; + * } + * </PRE> + */ + AXIS2_EXTERN axutil_hash_index_t *AXIS2_CALL + axutil_hash_first( + axutil_hash_t * ht, + const axutil_env_t * env); + + /** + * Continue iterating over the entries in a hash table. + * @param hi The iteration state + * @return a pointer to the updated iteration state. NULL if there are no more + * entries. + */ + AXIS2_EXTERN axutil_hash_index_t *AXIS2_CALL + axutil_hash_next( + const axutil_env_t * env, + axutil_hash_index_t * hi); + + /** + * Get the current entry's details from the iteration state. + * @param hi The iteration state + * @param key Return pointer for the pointer to the key. + * @param klen Return pointer for the key length. + * @param val Return pointer for the associated value. + * @remark The return pointers should point to a variable that will be set to the + * corresponding data, or they may be NULL if the data isn't interesting. + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_hash_this( + axutil_hash_index_t * hi, + const void **key, + axis2_ssize_t * klen, + void **val); + + /** + * Get the number of key/value pairs in the hash table. + * @param ht The hash table + * @return The number of key/value pairs in the hash table. + */ + AXIS2_EXTERN unsigned int AXIS2_CALL + axutil_hash_count( + axutil_hash_t * ht); + + /** + * Merge two hash tables into one new hash table. The values of the overlay + * hash override the values of the base if both have the same key. Both + * hash tables must use the same hash function. + * @param overlay The table to add to the initial table + * @param p The environment to use for the new hash table + * @param base The table that represents the initial values of the new table + * @return A new hash table containing all of the data from the two passed in + */ + AXIS2_EXTERN axutil_hash_t *AXIS2_CALL + axutil_hash_overlay( + const axutil_hash_t * overlay, + const axutil_env_t * env, + const axutil_hash_t * base); + + /** + * Merge two hash tables into one new hash table. If the same key + * is present in both tables, call the supplied merge function to + * produce a merged value for the key in the new table. Both + * hash tables must use the same hash function. + * @param h1 The first of the tables to merge + * @param p The environment to use for the new hash table + * @param h2 The second of the tables to merge + * @param merger A callback function to merge values, or NULL to + * make values from h1 override values from h2 (same semantics as + * axutil_hash_overlay()) + * @param data Client data to pass to the merger function + * @return A new hash table containing all of the data from the two passed in + */ + AXIS2_EXTERN axutil_hash_t *AXIS2_CALL + axutil_hash_merge( + const axutil_hash_t * h1, + const axutil_env_t * env, + const axutil_hash_t * h2, + void *(*merger)(const axutil_env_t * env, + const void *key, + 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 + axutil_hash_contains_key( + axutil_hash_t * ht, + const axutil_env_t * env, + const axis2_char_t * key); + + /** + * @param ht hash table to be freed + * @param env The environment to use for hash table + * @return return status code + * + */ + + AXIS2_EXTERN void AXIS2_CALL + axutil_hash_free( + axutil_hash_t * ht, + const axutil_env_t * env); + + /** + * Free a hash table with hash table given as void + * @param ht hash table to be freed as a void * + * @param env The environment to use for hash table + * @return return status code + */ + + AXIS2_EXTERN void AXIS2_CALL + axutil_hash_free_void_arg( + void *ht_void, + const axutil_env_t * env); + + AXIS2_EXTERN void AXIS2_CALL + axutil_hash_set_env( + axutil_hash_t * ht, + const axutil_env_t * env); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* !AXIS2_HASH_H */ diff --git a/util/include/axutil_http_chunked_stream.h b/util/include/axutil_http_chunked_stream.h new file mode 100644 index 0000000..7fc7a18 --- /dev/null +++ b/util/include/axutil_http_chunked_stream.h @@ -0,0 +1,132 @@ + +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The ASF licenses this file to You 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 AXUTIL_HTTP_CHUNKED_STREAM_H +#define AXUTIL_HTTP_CHUNKED_STREAM_H + +/** + * @defgroup axutil_http_chunked_stream http chunked stream + * @ingroup axis2_core_trans_http + * Description + * @{ + */ + +/** + * @file axutil_http_chunked_stream.h + * @brief axis2 HTTP Chunked Stream + */ + +#include <axutil_env.h> +#include <axutil_stream.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** Type name for struct axutil_http_chunked_stream */ + typedef struct axutil_http_chunked_stream axutil_http_chunked_stream_t; + + struct axis2_callback_info + { + const axutil_env_t *env; + void *in_stream; + int content_length; + int unread_len; + axutil_http_chunked_stream_t *chunked_stream; + }; + typedef struct axis2_callback_info axis2_callback_info_t; + + + /** + * @param chunked_stream pointer to chunked stream + * @param env pointer to environment struct + * @param buffer + * @param count + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_http_chunked_stream_read( + axutil_http_chunked_stream_t * chunked_stream, + const axutil_env_t * env, + void *buffer, + size_t count); + + /** + * @param env pointer to environment struct + * @param buffer + * @param count + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_http_chunked_stream_write( + axutil_http_chunked_stream_t * chunked_stream, + const axutil_env_t * env, + const void *buffer, + size_t count); + + /** + * @param chunked_stream pointer to chunked stream + * @param env pointer to environment struct + */ + AXIS2_EXTERN int AXIS2_CALL + + axutil_http_chunked_stream_get_current_chunk_size( + const axutil_http_chunked_stream_t * chunked_stream, + const axutil_env_t * env); + + /** + * @param chunked_stream pointer to chunked stream + * @param env pointer to environment struct + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + + axutil_http_chunked_stream_write_last_chunk( + axutil_http_chunked_stream_t * chunked_stream, + const axutil_env_t * env); + + /** + * @param chunked_stream pointer to chunked stream + * @param env pointer to environment struct + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_http_chunked_stream_free( + axutil_http_chunked_stream_t * chunked_stream, + const axutil_env_t * env); + + /** + * @param env pointer to environment struct + * @param stream pointer to stream + */ + AXIS2_EXTERN axutil_http_chunked_stream_t *AXIS2_CALL + + axutil_http_chunked_stream_create( + const axutil_env_t * env, + axutil_stream_t * stream); + + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + axutil_http_chunked_stream_get_end_of_chunks( + axutil_http_chunked_stream_t * chunked_stream, + const axutil_env_t * env); + + + /** @} */ +#ifdef __cplusplus +} +#endif +#endif /* AXUTIL_HTTP_CHUNKED_STREAM_H */ diff --git a/util/include/axutil_linked_list.h b/util/include/axutil_linked_list.h new file mode 100644 index 0000000..59454d5 --- /dev/null +++ b/util/include/axutil_linked_list.h @@ -0,0 +1,334 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_LINKED_LIST_H +#define AXUTIL_LINKED_LIST_H + +/** + * @file axutil_linked_list.h + * @brief Axis2 linked_list interface + */ + +#include <axutil_utils_defines.h> +#include <axutil_env.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct axutil_linked_list axutil_linked_list_t; + + /** + * @defgroup axutil_linked_list linked list + * @ingroup axis2_util + * @{ + */ + + /** + * Struct to represent an entry in the list. Holds a single element. + */ + typedef struct entry_s + { + + /** The element in the list. */ + void *data; + + /** The next list entry, null if this is last. */ + struct entry_s *next; + + /** The previous list entry, null if this is first. */ + struct entry_s *previous; + + } + entry_t; /* struct entry */ + + /** + * Create an empty linked list. + */ + AXIS2_EXTERN axutil_linked_list_t *AXIS2_CALL + axutil_linked_list_create( + const axutil_env_t * env); + + AXIS2_EXTERN void AXIS2_CALL + axutil_linked_list_free( + axutil_linked_list_t * linked_list, + const axutil_env_t * env); + + /** + * Obtain the Entry at a given position in a list. This method of course + * takes linear time, but it is intelligent enough to take the shorter of the + * paths to get to the Entry required. This implies that the first or last + * entry in the list is obtained in constant time, which is a very desirable + * property. + * For speed and flexibility, range checking is not done in this method: + * Incorrect values will be returned if (n < 0) or (n >= size). + * + * @param n the number of the entry to get + * @return the entry at position n + */ + AXIS2_EXTERN entry_t *AXIS2_CALL + axutil_linked_list_get_entry( + axutil_linked_list_t * linked_list, + const axutil_env_t * env, + int n); + + /** + * Remove an entry from the list. This will adjust size and deal with + * `first' and `last' appropriatly. + * + * @param e the entry to remove + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_linked_list_remove_entry( + axutil_linked_list_t * linked_list, + const axutil_env_t * env, + entry_t * e); + + /** + * Checks that the index is in the range of possible elements (inclusive). + * + * @param index the index to check + */ + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + + axutil_linked_list_check_bounds_inclusive( + axutil_linked_list_t * linked_list, + const axutil_env_t * env, + int index); + + /** + * Checks that the index is in the range of existing elements (exclusive). + * + * @param index the index to check + */ + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + + axutil_linked_list_check_bounds_exclusive( + axutil_linked_list_t * linked_list, + const axutil_env_t * env, + int index); + + /** + * Returns the first element in the list. + * + * @return the first list element + */ + AXIS2_EXTERN void *AXIS2_CALL + axutil_linked_list_get_first( + axutil_linked_list_t * linked_list, + const axutil_env_t * env); + + /** + * Returns the last element in the list. + * + * @return the last list element + */ + AXIS2_EXTERN void *AXIS2_CALL + axutil_linked_list_get_last( + axutil_linked_list_t * linked_list, + const axutil_env_t * env); + + /** + * Remove and return the first element in the list. + * + * @return the former first element in the list + */ + AXIS2_EXTERN void *AXIS2_CALL + axutil_linked_list_remove_first( + axutil_linked_list_t * linked_list, + const axutil_env_t * env); + + /** + * Remove and return the last element in the list. + * + * @return the former last element in the list + */ + AXIS2_EXTERN void *AXIS2_CALL + axutil_linked_list_remove_last( + axutil_linked_list_t * linked_list, + const axutil_env_t * env); + + /** + * Insert an element at the first of the list. + * + * @param o the element to insert + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_linked_list_add_first( + axutil_linked_list_t * linked_list, + const axutil_env_t * env, + void *o); + + /** + * Insert an element at the last of the list. + * + * @param o the element to insert + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_linked_list_add_last( + axutil_linked_list_t * linked_list, + const axutil_env_t * env, + void *o); + + /** + * Returns true if the list contains the given object. Comparison is done by + * <code>o == null ? e = null : o.equals(e)</code>. + * + * @param o the element to look for + * @return true if it is found + */ + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + axutil_linked_list_contains( + axutil_linked_list_t * linked_list, + const axutil_env_t * env, + void *o); + + /** + * Returns the size of the list. + * + * @return the list size + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_linked_list_size( + axutil_linked_list_t * linked_list, + const axutil_env_t * env); + + /** + * Adds an element to the end of the list. + * + * @param e the entry to add + * @return true, as it always succeeds + */ + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + axutil_linked_list_add( + axutil_linked_list_t * linked_list, + const axutil_env_t * env, + void *o); + + /** + * Removes the entry at the lowest index in the list that matches the given + * object, comparing by <code>o == null ? e = null : o.equals(e)</code>. + * + * @param o the object to remove + * @return true if an instance of the object was removed + */ + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + axutil_linked_list_remove( + axutil_linked_list_t * linked_list, + const axutil_env_t * env, + void *o); + + /** + * Remove all elements from this list. + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_linked_list_clear( + axutil_linked_list_t * linked_list, + const axutil_env_t * env); + + /** + * Return the element at index. + * + * @param index the place to look + * @return the element at index + */ + AXIS2_EXTERN void *AXIS2_CALL + axutil_linked_list_get( + axutil_linked_list_t * linked_list, + const axutil_env_t * env, + int index); + + /** + * Replace the element at the given location in the list. + * + * @param index which index to change + * @param o the new element + * @return the prior element + */ + AXIS2_EXTERN void *AXIS2_CALL + axutil_linked_list_set( + axutil_linked_list_t * linked_list, + const axutil_env_t * env, + int index, + void *o); + + /** + * Inserts an element in the given position in the list. + * + * @param index where to insert the element + * @param o the element to insert + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_linked_list_add_at_index( + axutil_linked_list_t * linked_list, + const axutil_env_t * env, + int index, + void *o); + + /** + * Removes the element at the given position from the list. + * + * @param index the location of the element to remove + * @return the removed element + */ + AXIS2_EXTERN void *AXIS2_CALL + axutil_linked_list_remove_at_index( + axutil_linked_list_t * linked_list, + const axutil_env_t * env, + int index); + + /** + * Returns the first index where the element is located in the list, or -1. + * + * @param o the element to look for + * @return its position, or -1 if not found + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_linked_list_index_of( + axutil_linked_list_t * linked_list, + const axutil_env_t * env, + void *o); + + /** + * Returns the last index where the element is located in the list, or -1. + * + * @param o the element to look for + * @return its position, or -1 if not found + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_linked_list_last_index_of( + axutil_linked_list_t * linked_list, + const axutil_env_t * env, + void *o); + + /** + * Returns an array which contains the elements of the list in order. + * + * @return an array containing the list elements + */ + AXIS2_EXTERN void **AXIS2_CALL + axutil_linked_list_to_array( + axutil_linked_list_t * linked_list, + const axutil_env_t * env); + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_LINKED_LIST_H */ diff --git a/util/include/axutil_log.h b/util/include/axutil_log.h new file mode 100644 index 0000000..09e9242 --- /dev/null +++ b/util/include/axutil_log.h @@ -0,0 +1,259 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_LOG_H +#define AXUTIL_LOG_H + +#include <axutil_allocator.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct axutil_log_ops axutil_log_ops_t; + typedef struct axutil_log axutil_log_t; + +#define AXIS2_LOG_SI __FILE__,__LINE__ + + /** + * @defgroup axutil_log log + * @ingroup axis2_util + * @{ + */ + + /** + *Examples + *To write debug information to log + *AXIS2_LOG_DEBUG(log,AXIS2_LOG_SI,"log this %s %d","test",123); + *This would log + *"log this test 123" into the log file + * + *similar macros are defined for different log levels: CRITICAL,ERROR,WARNING and INFO + * and SERVICE + * + *CRITICAL and ERROR logs are always written to file and other logs are written + *depending on the log level set (log->level) + */ + + /** + * \brief Axis2 log levels + */ + typedef enum axutil_log_levels + { + + /** Critical level, logs only critical errors */ + AXIS2_LOG_LEVEL_CRITICAL = 0, + + /** Error level, logs only errors */ + AXIS2_LOG_LEVEL_ERROR, + + /** Warning level, logs only warnings */ + AXIS2_LOG_LEVEL_WARNING, + + /** Info level, logs information */ + AXIS2_LOG_LEVEL_INFO, + + /** Debug level, logs everything */ + AXIS2_LOG_LEVEL_DEBUG, + + /** User level, logs only user level debug messages */ + AXIS2_LOG_LEVEL_USER, + + /** Trace level, Enable with compiler time option AXIS2_TRACE */ + AXIS2_LOG_LEVEL_TRACE + + } axutil_log_levels_t; + + /** + * \brief Axis2 log ops struct + * + * Encapsulator struct for ops of axutil_log + */ + struct axutil_log_ops + { + + /** + * deletes the log + * @return axis2_status_t AXIS2_SUCCESS on success else AXIS2_FAILURE + */ + + void( + AXIS2_CALL + * free)( + axutil_allocator_t * allocator, + struct axutil_log * log); + + /** + * writes to the log + * @param buffer buffer to be written to log + * @param size size of the buffer to be written to log + * @return satus of the op. AXIS2_SUCCESS on success else AXIS2_FAILURE + */ + void( + AXIS2_CALL + * write)( + axutil_log_t * log, + const axis2_char_t * buffer, + axutil_log_levels_t level, + const axis2_char_t * file, + const int line); + }; + + /** + * \brief Axis2 Log struct + * + * Log is the encapsulating struct for all log related data and ops + */ + struct axutil_log + { + + /** Log related ops */ + const axutil_log_ops_t *ops; + + /** Log level */ + axutil_log_levels_t level; + + /** Maximum log file size */ + int size; + + /** Is logging enabled? */ + axis2_bool_t enabled; + + }; + + AXIS2_EXTERN void AXIS2_CALL + axutil_log_impl_log_critical( + axutil_log_t * log, + const axis2_char_t * filename, + const int linenumber, + const axis2_char_t * format, + ...); + + AXIS2_EXTERN void AXIS2_CALL + axutil_log_impl_log_error( + axutil_log_t * log, + const axis2_char_t * filename, + const int linenumber, + const axis2_char_t * format, + ...); + + AXIS2_EXTERN void AXIS2_CALL + axutil_log_impl_log_warning( + axutil_log_t * log, + const axis2_char_t * filename, + const int linenumber, + const axis2_char_t * format, + ...); + + AXIS2_EXTERN void AXIS2_CALL + axutil_log_impl_log_info( + axutil_log_t * log, + const axis2_char_t * format, + ...); + + AXIS2_EXTERN void AXIS2_CALL + axutil_log_impl_log_user( + axutil_log_t * log, + const axis2_char_t * filename, + const int linenumber, + const axis2_char_t * format, + ...); + + AXIS2_EXTERN void AXIS2_CALL + axutil_log_impl_log_debug( + axutil_log_t * log, + const axis2_char_t * filename, + const int linenumber, + const axis2_char_t * format, + ...); + + AXIS2_EXTERN void AXIS2_CALL + axutil_log_impl_log_trace( + axutil_log_t * log, + const axis2_char_t * filename, + const int linenumber, + const axis2_char_t * format, + ...); + + AXIS2_EXTERN void AXIS2_CALL + axutil_log_free( + axutil_allocator_t * allocator, + struct axutil_log *log); + + AXIS2_EXTERN void AXIS2_CALL + axutil_log_write( + axutil_log_t * log, + const axis2_char_t * buffer, + axutil_log_levels_t level, + const axis2_char_t * file, + const int line); + + +#define AXIS2_LOG_FREE(allocator, log) \ + axutil_log_free(allocator, log) + +#define AXIS2_LOG_WRITE(log, buffer, level, file) \ + axutil_log_write(log, buffer, level, file, AXIS2_LOG_SI) + +#define AXIS2_LOG_USER axutil_log_impl_log_user +#define AXIS2_LOG_DEBUG axutil_log_impl_log_debug +#define AXIS2_LOG_INFO axutil_log_impl_log_info +#define AXIS2_LOG_WARNING axutil_log_impl_log_warning +#define AXIS2_LOG_ERROR axutil_log_impl_log_error +#define AXIS2_LOG_CRITICAL axutil_log_impl_log_critical + +#ifdef AXIS2_TRACE +#define AXIS2_LOG_TRACE axutil_log_impl_log_trace +#else +# ifdef HAVE_GNUC_VARARGS +# define AXIS2_LOG_TRACE(params, args ...) +# elif defined HAVE_ISO_VARARGS +# define AXIS2_LOG_TRACE(params, ...) +# elif __STDC__ && __STDC_VERSION > 199901L +# define AXIS2_LOG_TRACE(params, ...) +# elif WIN32 +# define AXIS2_LOG_TRACE axutil_log_impl_log_trace +# else +# define AXIS2_LOG_TRACE axutil_log_impl_log_trace +# endif +#endif + +#ifndef AXIS2_LOG_PROJECT_PREFIX + /** Each module/project should undef and define the following.. */ +#define AXIS2_LOG_PROJECT_PREFIX "[axis2c]" +#endif + +#define AXIS2_LOG_USER_MSG(log, msg) AXIS2_LOG_USER (log, AXIS2_LOG_SI, "%s %s", AXIS2_LOG_PROJECT_PREFIX, msg) +#define AXIS2_LOG_DEBUG_MSG(log, msg) AXIS2_LOG_DEBUG (log, AXIS2_LOG_SI, "%s %s", AXIS2_LOG_PROJECT_PREFIX, msg) +#define AXIS2_LOG_INFO_MSG(log, msg) AXIS2_LOG_INFO (log, "%s %s", AXIS2_LOG_PROJECT_PREFIX, msg) +#define AXIS2_LOG_WARNING_MSG(log, msg) AXIS2_LOG_WARNING (log, AXIS2_LOG_SI, "%s %s", AXIS2_LOG_PROJECT_PREFIX, msg) +#define AXIS2_LOG_ERROR_MSG(log, msg) AXIS2_LOG_ERROR (log, AXIS2_LOG_SI, "%s %s", AXIS2_LOG_PROJECT_PREFIX, msg) +#define AXIS2_LOG_CRITICAL_MSG(log, msg) AXIS2_LOG_CRITICAL (log, AXIS2_LOG_SI, "%s %s", AXIS2_LOG_PROJECT_PREFIX, msg) +#define AXIS2_LOG_TRACE_MSG(log, msg) AXIS2_LOG_TRACE (log, AXIS2_LOG_SI, "%s %s", AXIS2_LOG_PROJECT_PREFIX, msg) + + +#define IF_AXIS2_LOG_DEBUG_ENABLED(log) if(AXIS2_LOG_LEVEL_DEBUG <= log->level && log->level != AXIS2_LOG_LEVEL_USER) + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_LOG_H */ diff --git a/util/include/axutil_log_default.h b/util/include/axutil_log_default.h new file mode 100644 index 0000000..4165f85 --- /dev/null +++ b/util/include/axutil_log_default.h @@ -0,0 +1,64 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_LOG_DEFAULT_H +#define AXUTIL_LOG_DEFAULT_H + +#include <stdlib.h> +#include <stdarg.h> +#include <axutil_log.h> +#include <axutil_allocator.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_log Log + * @ingroup axis2_util + * @{ + */ + +#define AXIS2_LEN_VALUE 6000 + + /** + * Creates a log struct + * @param allocator allocator to be used. Mandatory, cannot be NULL + * @return pointer to the newly created log struct + */ + AXIS2_EXTERN axutil_log_t *AXIS2_CALL + axutil_log_create( + axutil_allocator_t * allocator, + axutil_log_ops_t * ops, + const axis2_char_t * stream_name); + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_log_impl_get_time_str( + void); + + AXIS2_EXTERN axutil_log_t *AXIS2_CALL + axutil_log_create_default( + axutil_allocator_t * allocator); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_LOG_DEFAULT_H */ diff --git a/util/include/axutil_md5.h b/util/include/axutil_md5.h new file mode 100644 index 0000000..b13bcb1 --- /dev/null +++ b/util/include/axutil_md5.h @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_MD5_H +#define AXUTIL_MD5_H + +/** + * @file axutil_md5.h + * @brief MD5 Implementation for Axis2 based on rfc1321. + */ + +#include <axutil_utils_defines.h> +#include <axutil_env.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axis2_util utilities + * @ingroup axis2 + * @{ + * @} + */ + + /** + * @defgroup axutil_md5 md5 + * @ingroup axis2_util + * @{ + */ + + /** The MD5 digest size */ + #define AXIS2_MD5_DIGESTSIZE 16 + + typedef struct axutil_md5_ctx + { + /** state (ABCD) */ + unsigned int state[4]; + /** number of bits, modulo 2^64 (lsb first) */ + unsigned int count[2]; + /** input buffer */ + unsigned char buffer[64]; + } + axutil_md5_ctx_t; + + /** + * Creates md5_ctx struct, which is used for the MD5 message-digest + * operation. Initialization of the struct is done during the creation + * process. + * @param env, pointer to the env struct. + * @return pointer to md5_ctx struct created. + */ + AXIS2_EXTERN axutil_md5_ctx_t *AXIS2_CALL + axutil_md5_ctx_create( + const axutil_env_t * env); + + /** + * Frees the md5_ctx struct + * @param md5_ctx, pointer to struct to free. + * @param env, pointer to the env struct. + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_md5_ctx_free( + axutil_md5_ctx_t * md5_ctx, + const axutil_env_t * env); + + /** + * MD5 block update operation. Continue an MD5 message-digest operation, + * processing another message block, and updating the context. + * @param context The MD5 content to update. + * @param env, pointer to the env struct. + * @param input_str next message block to update + * @param inputLen The length of the next message block + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_md5_update( + axutil_md5_ctx_t *context, + const axutil_env_t * env, + const void *input_str, + size_t inputLen); + + /** + * MD5 finalization. Ends an MD5 message-digest operation, writing the + * message digest and zeroing the context. + * @param digest The final MD5 digest. + * @param env, pointer to the env struct. + * @param context The MD5 content we are finalizing. + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_md5_final( + axutil_md5_ctx_t *context, + const axutil_env_t * env, + unsigned char digest[AXIS2_MD5_DIGESTSIZE]); + + /** + * MD5 in one step. + * @param env, pointer to the env struct. + * @param digest The final MD5 digest. + * @param input_str The message block to use. + * @param inputLen The length of the message block. + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_md5( + const axutil_env_t * env, + unsigned char digest[AXIS2_MD5_DIGESTSIZE], + const void *input_str, + size_t inputLen); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_MD5_H */ diff --git a/util/include/axutil_network_handler.h b/util/include/axutil_network_handler.h new file mode 100644 index 0000000..3d55cd1 --- /dev/null +++ b/util/include/axutil_network_handler.h @@ -0,0 +1,194 @@ +
+/*
+ * 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 count 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 AXUTIL_NETWORK_HANDLER_H
+#define AXUTIL_NETWORK_HANDLER_H
+
+#include <axutil_utils.h>
+#include <axutil_utils_defines.h>
+#include <axutil_env.h>
+#include <sys/types.h>
+#include <platforms/axutil_platform_auto_sense.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /**
+ * @defgroup axutil_network_handler network handler
+ * @ingroup axis2_util
+ * @{
+ */
+
+ /**
+ * open a socket for a given server
+ * @param server ip address or the fqn of the server
+ * @param port port of the service
+ * @return opened socket
+ */
+ AXIS2_EXTERN axis2_socket_t AXIS2_CALL
+
+ axutil_network_handler_open_socket(
+ const axutil_env_t * env,
+ char *server,
+ int port);
+
+ /**
+ * creates a server socket for a given port
+ * @param port port of the socket to be bound
+ * @return creates server socket
+ */
+ AXIS2_EXTERN axis2_socket_t AXIS2_CALL
+
+ axutil_network_handler_create_server_socket(
+ const axutil_env_t * env,
+ int port);
+
+ /**
+ * closes a socket
+ * @param opened socket that need to be closed
+ * @return status code
+ */
+ AXIS2_EXTERN axis2_status_t AXIS2_CALL
+
+ axutil_network_handler_close_socket(
+ const axutil_env_t * env,
+ axis2_socket_t socket);
+
+ /**
+ * used to set up socket options such as timeouts, non-blocking ..etc
+ * @param socket valid socket (obtained by socket() or similar call)
+ * @param option the name of the option
+ * @param value Value to be set
+ * @return status of the operations as axis2_status_t
+ */
+ AXIS2_EXTERN axis2_status_t AXIS2_CALL
+
+ axutil_network_handler_set_sock_option(
+ const axutil_env_t * env,
+ axis2_socket_t socket,
+ int option,
+ int value);
+
+ /**
+ * Accepts remote connections for a server socket
+ * @param socket valid server socket (obtained by socket() or similar call)
+ * @return created socket to handle the incoming client connection
+ */
+ AXIS2_EXTERN axis2_socket_t AXIS2_CALL
+
+ axutil_network_handler_svr_socket_accept(
+ const axutil_env_t * env,
+ axis2_socket_t socket);
+
+ /**
+ * Returns the ip address of the server associated with the socket
+ * @param socket valid socket (obtained by accept() or similar call)
+ * @return ip address asoociated with the socket or NULL
+ */
+ AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+ axutil_network_handler_get_svr_ip(
+ const axutil_env_t * env,
+ axis2_socket_t socket);
+
+ AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+ axutil_network_handler_get_peer_ip(
+ const axutil_env_t * env,
+ axis2_socket_t socket);
+
+ /*
+ * Create a datagram socket.
+ * @param env pointer to env
+ * @return a datagram socket
+ */
+ AXIS2_EXTERN axis2_socket_t AXIS2_CALL
+ axutil_network_handler_open_dgram_socket(const axutil_env_t *env);
+
+ /*
+ * Send a UDP packet to the given source and port address.
+ * Read a incoming UDP packet from the port and server address.
+ * @param env pointer to the env structure
+ * @param socket a datagram socket
+ * @param buffer a buffer containing the data to be sent
+ * @param buf_len length of the buffer
+ * @param addr address of the source field
+ * @param port udp port number
+ * @return success if everything goes well
+ */
+ AXIS2_EXTERN axis2_status_t AXIS2_CALL
+ axutil_network_handler_send_dgram(const axutil_env_t *env, axis2_socket_t socket,
+ axis2_char_t *buff, int *buf_len,
+ axis2_char_t *addr, int dest_port, int *source_port);
+
+ /*
+ * Read a incoming UDP packet from the port and server address.
+ * @param env pointer to the env structure
+ * @param socket a datagram socket
+ * @param buffer a buffer allocated and passed to be filled
+ * @param buf_len length of the buffer allocated. In return buffer len
+ contains the length of the data read
+ * @param addr address of the sender. This is a return value.
+ * @param port senders port address. Return value
+ * @return if everything goes well return success
+ */
+ AXIS2_EXTERN axis2_status_t AXIS2_CALL
+ axutil_network_handler_read_dgram(const axutil_env_t *env, axis2_socket_t socket,
+ axis2_char_t *buffer, int *buf_len,
+ axis2_char_t **addr, int *port);
+
+ /*
+ * Create a datagram socket to receive incoming UDP packets.
+ * @param env a pointer to the env structure
+ * @param port udp port to listen
+ * @return AXIS2_SUCCESS if everything goes well
+ */
+ AXIS2_EXTERN axis2_socket_t AXIS2_CALL
+ axutil_network_handler_create_dgram_svr_socket(
+ const axutil_env_t *env,
+ int port);
+
+ /*
+ * Bind a socket to the specified address
+ * @param env a pointer to the env structure
+ * @param sock socket
+ * @param port port number to bind to
+ * @return AXIS2_SUCCESS if binding is performed
+ */
+ AXIS2_EXTERN axis2_status_t AXIS2_CALL
+ axutil_network_handler_bind_socket(const axutil_env_t *env,
+ axis2_socket_t sock, int port);
+
+ /*
+ * Create a multicast socket for listening on the given port.
+ * @param env a pointer to the env structure
+ * @param port udp port to listen
+ * @param mul_addr multicast address to join. The address should be valid and in dotted format.
+ * @param ttl TTL value.
+ * @return AXIS2_SUCCESS if everything goes well.s
+ */
+ AXIS2_EXTERN axis2_socket_t AXIS2_CALL
+ axutil_network_hadler_create_multicast_svr_socket(const axutil_env_t *env,
+ int port, axis2_char_t *mul_addr);
+
+ /** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* AXIS2_NETWORK_HANDLER_H */
diff --git a/util/include/axutil_param.h b/util/include/axutil_param.h new file mode 100644 index 0000000..415e201 --- /dev/null +++ b/util/include/axutil_param.h @@ -0,0 +1,200 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_PARAM_H +#define AXUTIL_PARAM_H + +/** + * @file axutil_param.h + * @brief Axis2 param interface + */ + +#include <axutil_utils_defines.h> +#include <axutil_env.h> +#include <axutil_hash.h> +#include <axutil_array_list.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_param parameter + * @ingroup axis2_util + * @{ + */ + + /** + * TEXT PARAM + */ +#define AXIS2_TEXT_PARAM 0 + + /** + * Field DOM_PARAM + */ +#define AXIS2_DOM_PARAM 1 + + typedef struct axutil_param axutil_param_t; + + /** + * each type which is passed as a param value to a parameter, must have this + * type of function implemented. When the param value is set this function + * should also be assigned to param free function + */ + typedef void( + AXIS2_CALL + * AXIS2_PARAM_VALUE_FREE) ( + void *param_value, + const axutil_env_t * env); + + /** + * creates param struct + */ + AXIS2_EXTERN axutil_param_t *AXIS2_CALL + axutil_param_create( + const axutil_env_t * env, + axis2_char_t * name, + void *value); + + /** + * Parameter name accessor + * @return name of the param + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_param_get_name( + struct axutil_param *param, + const axutil_env_t * env); + + /** + * Parameter value accessor + * @return Object + */ + AXIS2_EXTERN void *AXIS2_CALL + axutil_param_get_value( + struct axutil_param *param, + const axutil_env_t * env); + + /** + * param name mutator + * @param name + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_param_set_name( + struct axutil_param *param, + const axutil_env_t * env, + const axis2_char_t * name); + + /** + * Method setValue + * + * @param value + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_param_set_value( + struct axutil_param *param, + const axutil_env_t * env, + const void *value); + + /** + * Method isLocked + * + * @return boolean + */ + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + axutil_param_is_locked( + struct axutil_param *param, + const axutil_env_t * env); + + /** + * Method setLocked + * + * @param value + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_param_set_locked( + struct axutil_param *param, + const axutil_env_t * env, + axis2_bool_t value); + + /** + * Method getParameterType + * + * @return int + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_param_get_param_type( + struct axutil_param *param, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_param_set_param_type( + struct axutil_param *param, + const axutil_env_t * env, + int type); + + AXIS2_EXTERN void AXIS2_CALL + axutil_param_free( + struct axutil_param *param, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_param_set_attributes( + struct axutil_param *param, + const axutil_env_t * env, + axutil_hash_t * attrs); + + AXIS2_EXTERN axutil_hash_t *AXIS2_CALL + axutil_param_get_attributes( + struct axutil_param *param, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_param_set_value_list( + struct axutil_param *param, + const axutil_env_t * env, + axutil_array_list_t * value_list); + + AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL + axutil_param_get_value_list( + struct axutil_param *param, + const axutil_env_t * env); + + AXIS2_EXTERN void AXIS2_CALL + axutil_param_value_free( + void *param_value, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_param_set_value_free( + struct axutil_param *param, + const axutil_env_t * env, + AXIS2_PARAM_VALUE_FREE free_fn); + + AXIS2_EXTERN void AXIS2_CALL + axutil_param_dummy_free_fn( + void *param, + const axutil_env_t * env); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_PARAM_H */ diff --git a/util/include/axutil_param_container.h b/util/include/axutil_param_container.h new file mode 100644 index 0000000..e61b9d5 --- /dev/null +++ b/util/include/axutil_param_container.h @@ -0,0 +1,134 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_PARAM_CONTAINER_H +#define AXUTIL_PARAM_CONTAINER_H + +/** @defgroup axutil_param_container Parameter Container + * @ingroup axis2_descript + * @{ + */ + +/** + * @file axutil_param_container.h + * @brief Axis2 Param container interface + */ + +#include <axutil_utils.h> +#include <axutil_error.h> +#include <axutil_utils_defines.h> +#include <axutil_env.h> +#include <axutil_allocator.h> +#include <axutil_string.h> +#include <axutil_array_list.h> +#include <axutil_hash.h> + +/*#include <axiom_element.h>*/ +#include <axutil_qname.h> +#include <axutil_param.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct axutil_param_container axutil_param_container_t; + + /** + * Creates param container struct + * @return pointer to newly created param container + */ + AXIS2_EXTERN axutil_param_container_t *AXIS2_CALL + + axutil_param_container_create( + const axutil_env_t * env); + + /** + * Free param_container passed as void pointer. This will be + * cast into appropriate type and then pass the cast object + * into the param_container structure's free method + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_param_container_free_void_arg( + void *param_container, + const axutil_env_t * env); + + /** De-allocate memory + * @return status code + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_param_container_free( + axutil_param_container_t * param_container, + const axutil_env_t * env); + + /** Add a param + * @param param param to be added + * @return status code + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_param_container_add_param( + axutil_param_container_t * param_container, + const axutil_env_t * env, + axutil_param_t * param); + + /** To get a param in a given description + * @param name param name + * @return param + */ + AXIS2_EXTERN axutil_param_t *AXIS2_CALL + axutil_param_container_get_param( + axutil_param_container_t * param_container, + const axutil_env_t * env, + const axis2_char_t * name); + + /** To get all the params in a given description + * @return all the params contained + */ + AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL + + axutil_param_container_get_params( + axutil_param_container_t * param_container, + const axutil_env_t * env); + + /** To check whether the paramter is locked at any level + * @param param_name name of the param + * @return whether param is locked + */ + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + + axutil_param_container_is_param_locked( + axutil_param_container_t * param_container, + const axutil_env_t * env, + const axis2_char_t * param_name); + + /** Remove parameter from the param container + * @param parameter name of the param to be removed + * @return status of AXIS2_SUCCESS or AXIS2_FAILURE + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_param_container_delete_param( + axutil_param_container_t *param_container, + const axutil_env_t *env, + const axis2_char_t *param_name); + + /** @} */ + +#ifdef __cplusplus +} +#endif +#endif /* AXIS2_PARAM_CONTAINER_H */ diff --git a/util/include/axutil_properties.h b/util/include/axutil_properties.h new file mode 100644 index 0000000..d5610f3 --- /dev/null +++ b/util/include/axutil_properties.h @@ -0,0 +1,137 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_PROPERTIES_H +#define AXUTIL_PROPERTIES_H + +#include <axutil_utils_defines.h> +#include <axutil_error.h> +#include <axutil_env.h> +#include <axutil_hash.h> +#include <stdio.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_properties properties + * @ingroup axis2_util + * @{ + */ + + typedef struct axutil_properties axutil_properties_t; + + /** + * create new properties + * @return properties newly created properties + */ + AXIS2_EXTERN axutil_properties_t *AXIS2_CALL + axutil_properties_create( + const axutil_env_t * env); + + /** + * 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_EXTERN void AXIS2_CALL + axutil_properties_free( + axutil_properties_t * properties, + const axutil_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_EXTERN axis2_char_t *AXIS2_CALL + axutil_properties_get_property( + axutil_properties_t * properties, + const axutil_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_EXTERN axis2_status_t AXIS2_CALL + axutil_properties_set_property( + axutil_properties_t * properties, + const axutil_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_EXTERN axutil_hash_t *AXIS2_CALL + axutil_properties_get_all( + axutil_properties_t * properties, + const axutil_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_EXTERN axis2_status_t AXIS2_CALL + axutil_properties_load( + axutil_properties_t * properties, + const axutil_env_t * env, + axis2_char_t * input_filename); + + /** + * 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_EXTERN axis2_status_t AXIS2_CALL + axutil_properties_store( + axutil_properties_t * properites, + const axutil_env_t * env, + FILE * output); + + /*************************** End of function macros ***************************/ + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_PROPERTIES_H */ diff --git a/util/include/axutil_property.h b/util/include/axutil_property.h new file mode 100644 index 0000000..335db25 --- /dev/null +++ b/util/include/axutil_property.h @@ -0,0 +1,124 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_PROPERTY_H +#define AXUTIL_PROPERTY_H + +#include <axutil_utils_defines.h> +#include <axutil_error.h> +#include <axutil_env.h> +#include <axutil_utils.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_property property + * @ingroup axis2_util + * @{ + */ + + typedef struct axutil_property axutil_property_t; + + /** + * create new property + * @return property newly created property + */ + AXIS2_EXTERN axutil_property_t *AXIS2_CALL + axutil_property_create( + const axutil_env_t * env); + + /** + * create new property + * @param env axis2 environment + * @param scope scope can be one of following + * AXIS2_SCOPE_REQUEST + * AXIS2_SCOPE_SESSION + * AXIS2_SCOPE_APPLICATION + * pass 0 to use default scope of AXIS2_SCOPE_REQUEST + * @param own_value whether value is owned by the property or not. + * if the value is owned by the property it should be freed + * by the proeprty. + * @param free_func free function for the value freeing. Pass 0 if + * param value is a string + * @param value value of the property + * @return property newly created property + */ + AXIS2_EXTERN axutil_property_t *AXIS2_CALL + + axutil_property_create_with_args( + const axutil_env_t * env, + axis2_scope_t scope, + axis2_bool_t own_value, + AXIS2_FREE_VOID_ARG free_func, + void *value); + + AXIS2_EXTERN void AXIS2_CALL + axutil_property_free( + axutil_property_t * property, + const axutil_env_t * env); + + /** + * Default scope is AXIS2_SCOPE_REQUEST + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_property_set_scope( + axutil_property_t * property, + const axutil_env_t * env, + axis2_scope_t scope); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_property_set_free_func( + axutil_property_t * property, + const axutil_env_t * env, + AXIS2_FREE_VOID_ARG free_func); + + /*************************** Function macros **********************************/ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_property_set_value( + axutil_property_t * property, + const axutil_env_t * env, + void *value); + + AXIS2_EXTERN void *AXIS2_CALL + axutil_property_get_value( + axutil_property_t * property, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_property_set_own_value( + axutil_property_t * property, + const axutil_env_t * env, + axis2_bool_t own_value); + + AXIS2_EXTERN axutil_property_t *AXIS2_CALL + axutil_property_clone( + axutil_property_t * property, + const axutil_env_t * env); + + /*************************** End of function macros ***************************/ + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_PROPERTY_H */ diff --git a/util/include/axutil_qname.h b/util/include/axutil_qname.h new file mode 100644 index 0000000..da78461 --- /dev/null +++ b/util/include/axutil_qname.h @@ -0,0 +1,142 @@ + +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The ASF licenses this file to You 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 AXUTIL_QNAME_H +#define AXUTIL_QNAME_H + +/** + * @file axutil_qname.h + * @brief represents a qualified name + */ + +#include <axutil_utils_defines.h> +#include <axutil_env.h> + +#include <axutil_string.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_qname qname + * @ingroup axis2_util + * @{ + */ + + typedef struct axutil_qname axutil_qname_t; + + /** + * creates a qname struct + * returns a pointer to a qname struct + * @localpart mandatory + * @prefix mandatory + * @ns_uri optional + * The prefix. Must not be null. Use "" (empty string) to indicate that no + * namespace URI is present or the namespace URI is not relevant + * if null is passed for prefix and uri , "'(empty string ) will be assinged to + * those fields + * @return a pointer to newly created qname struct + */ + + AXIS2_EXTERN axutil_qname_t *AXIS2_CALL + axutil_qname_create( + const axutil_env_t * env, + const axis2_char_t * localpart, + const axis2_char_t * namespace_uri, + const axis2_char_t * prefix); + + /** + * returns a newly created qname using a string genarated from + * axutil_qname_to_string method + * freeing the returned qname is users responsibility + */ + + AXIS2_EXTERN axutil_qname_t *AXIS2_CALL + axutil_qname_create_from_string( + const axutil_env_t * env, + const axis2_char_t * string); + + /** + * Free a qname struct + * @return Status code + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_qname_free( + struct axutil_qname *qname, + const axutil_env_t * env); + + /** + * Compare two qnames + * prefix is ignored when comparing + * If ns_uri and localpart of qname1 and qname2 is equal returns true + * @return true if qname1 equals qname2, false otherwise + */ + + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + axutil_qname_equals( + const struct axutil_qname *qname, + const axutil_env_t * env, + const struct axutil_qname *qname1); + + /** + * clones a given qname + * @param qname , qname struct instance to be cloned + * @env environment , double pointer to environment + * @returns the newly cloned qname struct instance + */ + + AXIS2_EXTERN struct axutil_qname *AXIS2_CALL + axutil_qname_clone( + struct axutil_qname *qname, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_qname_get_uri( + const struct axutil_qname *qname, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_qname_get_prefix( + const struct axutil_qname *qname, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_qname_get_localpart( + const struct axutil_qname *qname, + const axutil_env_t * env); + + /** + * returns a unique string created by concatanting namespace uri + * and localpart . + * The string is of the form localpart|url + * The returned char* is freed when qname free function is called. + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_qname_to_string( + struct axutil_qname *qname, + const axutil_env_t * env); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_QNAME_H */ diff --git a/util/include/axutil_rand.h b/util/include/axutil_rand.h new file mode 100644 index 0000000..f89f283 --- /dev/null +++ b/util/include/axutil_rand.h @@ -0,0 +1,83 @@ + +/* + * 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 AXUTIL_RAND_H +#define AXUTIL_RAND_H + +#include <axutil_error.h> +#include <axutil_env.h> +#include <axutil_date_time.h> +#include <axutil_base64_binary.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_rand rand + * @ingroup axis2_util + * @{ + */ + + /** + * @file axutil_rand.h + * @brief A simple thread safe and reentrant random number generator + */ + + /** + * This is reentrant and thread safe simple random number generator + * function. it is passed an pointer to an unsigned int state value + * which is used inside the function and changed in each call. + * @param seedp pointer to an unsigned int used as the internal state + * @return int <code>int<code> + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_rand( + unsigned int *seedp); + + /** + * This is reentrant and thread safe simple random number generator + * function. it is passed an pointer to an unsigned int state value + * which is used inside the function and changed in each call. Also + * it is passed a range in which the random number is selected + * @param seedp pointer to an unsigned int used as the internal state + * @param start start of the range + * @param end end of the range + * @return int If invalid range is entered -1 is returned <code>int<code> + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_rand_with_range( + unsigned int *seedp, + int start, + int end); + + /** + * A random seed value generated based on the time + */ + AXIS2_EXTERN unsigned int AXIS2_CALL + + axutil_rand_get_seed_value_based_on_time( + const axutil_env_t * env); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_RAND_H */ diff --git a/util/include/axutil_stack.h b/util/include/axutil_stack.h new file mode 100644 index 0000000..5eba102 --- /dev/null +++ b/util/include/axutil_stack.h @@ -0,0 +1,93 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_STACK_H +#define AXUTIL_STACK_H + +/** +* @file axutil_stack.h +* @brief represents a stack +*/ + +#include <axutil_utils_defines.h> +#include <axutil_env.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axis2_util_stack stack + * @ingroup axis2_util + * @{ + */ + + typedef struct axutil_stack axutil_stack_t; + + AXIS2_EXTERN axutil_stack_t *AXIS2_CALL + axutil_stack_create( + const axutil_env_t * env); + + /** + * Free function of the stack + * @param stack pointer to stack + * @param env environemnt + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_stack_free( + axutil_stack_t * stack, + const axutil_env_t * env); + + AXIS2_EXTERN void *AXIS2_CALL + axutil_stack_pop( + axutil_stack_t * stack, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_stack_push( + axutil_stack_t * stack, + const axutil_env_t * env, + void *value); + + AXIS2_EXTERN int AXIS2_CALL + axutil_stack_size( + axutil_stack_t * stack, + const axutil_env_t * env); + + /** + * returns the last put value from the stack + * without removing it from stack + */ + AXIS2_EXTERN void *AXIS2_CALL + axutil_stack_get( + axutil_stack_t * stack, + const axutil_env_t * env); + + AXIS2_EXTERN void *AXIS2_CALL + axutil_stack_get_at( + axutil_stack_t * stack, + const axutil_env_t * env, + int i); + + /** @} */ + +#ifdef __cplusplus +} +#endif +#endif /* AXIS2_STACK_H */ diff --git a/util/include/axutil_stream.h b/util/include/axutil_stream.h new file mode 100644 index 0000000..729f1e3 --- /dev/null +++ b/util/include/axutil_stream.h @@ -0,0 +1,294 @@ + +/* + * 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 count 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 AXUTIL_STREAM_H +#define AXUTIL_STREAM_H + +#include <axutil_utils.h> +#include <axutil_utils_defines.h> +#include <axutil_env.h> +#include <stdio.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define AXIS2_STREAM_DEFAULT_BUF_SIZE 2048 + + /** + * @defgroup axutil_stream stream + * @ingroup axis2_util + * @{ + */ + + /** + * \brief Axis2 stream types + * + * This is used to create a stream to correspond to + * particular i/o mtd + */ + enum axutil_stream_type + { + AXIS2_STREAM_BASIC = 0, + AXIS2_STREAM_FILE, + AXIS2_STREAM_SOCKET, + AXIS2_STREAM_MANAGED /* Example Wrapper stream for Apache2 read mechanism */ + }; + + typedef enum axutil_stream_type axutil_stream_type_t; + typedef struct axutil_stream axutil_stream_t; + + typedef int( + AXIS2_CALL + * AXUTIL_STREAM_READ)( + axutil_stream_t * stream, + const axutil_env_t * env, + void *buffer, + size_t count); + + typedef int( + AXIS2_CALL + * AXUTIL_STREAM_WRITE)( + axutil_stream_t * stream, + const axutil_env_t * env, + const void *buffer, + size_t count); + + typedef int( + AXIS2_CALL + * AXUTIL_STREAM_SKIP)( + axutil_stream_t * stream, + const axutil_env_t * env, + int count); + + struct axutil_stream + { + axutil_stream_type_t stream_type; + int len; + int max_len; + /* Only one of these is used for a perticlar + * instance depending on the type + */ + axis2_char_t *buffer; + axis2_char_t *buffer_head; + FILE *fp; + int socket; + + int axis2_eof; + + /** + * reads from stream + * @param buffer buffer into which the content is to be read + * @param count size of the buffer + * @return no: of bytes read + */ + int( + AXIS2_CALL + * read)( + axutil_stream_t * stream, + const axutil_env_t * env, + void *buffer, + size_t count); + + /** + * writes into stream + * @param buffer buffer to be written + * @param count size of the buffer + * @return no: of bytes actually written + */ + int( + AXIS2_CALL + * write)( + axutil_stream_t * stream, + const axutil_env_t * env, + const void *buffer, + size_t count); + + /** + * Skips over and discards n bytes of data from this input stream. + * @param count number of bytes to be discarded + * @return no: of bytes actually skipped + */ + int( + AXIS2_CALL + * skip)( + axutil_stream_t * stream, + const axutil_env_t * env, + int count); + }; + + /** + * Deletes the stream + * @return axis2_status_t AXIS2_SUCCESS on success else AXIS2_FAILURE + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_stream_free( + axutil_stream_t * stream, + const axutil_env_t * env); + + AXIS2_EXTERN void AXIS2_CALL + axutil_stream_free_void_arg( + void *stream, + const axutil_env_t * env); + + /** + * reads from stream + * @param buffer buffer into which the content is to be read + * @param count size of the buffer + * @return no: of bytes read + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_stream_read( + axutil_stream_t * stream, + const axutil_env_t * env, + void *buffer, + size_t count); + + /** + * writes into stream + * @param buffer buffer to be written + * @param count size of the buffer + * @return no: of bytes actually written + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_stream_write( + axutil_stream_t * stream, + const axutil_env_t * env, + const void *buffer, + size_t count); + + /** + * Skips over and discards n bytes of data from this input stream. + * @param count number of bytes to be discarded + * @return no: of bytes actually skipped + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_stream_skip( + axutil_stream_t * stream, + const axutil_env_t * env, + int count); + + /** + * Returns the length of the stream (applicable only to basic stream) + * @return Length of the buffer if its type is basic, else -1 + * (we can't define a length of a stream unless it is just a buffer) + */ + AXIS2_EXTERN int AXIS2_CALL + axutil_stream_get_len( + axutil_stream_t * stream, + const axutil_env_t * env); + + /** \brief Constructor for creating an in memory stream + * @return axutil_stream (in memory) + */ + AXIS2_EXTERN axutil_stream_t *AXIS2_CALL + axutil_stream_create_basic( + const axutil_env_t * env); + + /** \brief Constructor for creating a file stream + * @param valid file pointer (opened file) + * @return axutil_stream (file) + */ + AXIS2_EXTERN axutil_stream_t *AXIS2_CALL + axutil_stream_create_file( + const axutil_env_t * env, + FILE * fp); + + /** \brief Constructor for creating a file stream + * @param valid socket (opened socket) + * @return axutil_stream (socket) + */ + AXIS2_EXTERN axutil_stream_t *AXIS2_CALL + axutil_stream_create_socket( + const axutil_env_t * env, + int socket); + + /** + *Free stream + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_stream_free( + axutil_stream_t * stream, + const axutil_env_t * env); + + /** + * Free stream passed as void pointer. This will be + * cast into appropriate type and then pass the cast object + * into the module_desc structure's free method + */ + + AXIS2_EXTERN void AXIS2_CALL + axutil_stream_free_void_arg( + void *stream, + const axutil_env_t * env); + + /** + * Gets the buffer + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_stream_get_buffer( + const axutil_stream_t * stream, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_stream_flush_buffer( + axutil_stream_t * stream, + const axutil_env_t * env); + + AXIS2_EXTERN int AXIS2_CALL + axutil_stream_peek_socket( + axutil_stream_t * stream, + const axutil_env_t * env, + void *buffer, + size_t count); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_stream_flush( + axutil_stream_t * stream, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_stream_close( + axutil_stream_t * stream, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_stream_set_read( + axutil_stream_t * stream, + const axutil_env_t * env, + AXUTIL_STREAM_READ func); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_stream_set_write( + axutil_stream_t * stream, + const axutil_env_t * env, + AXUTIL_STREAM_WRITE func); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_stream_set_skip( + axutil_stream_t * stream, + const axutil_env_t * env, + AXUTIL_STREAM_SKIP func); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_STREAM_H */ diff --git a/util/include/axutil_string.h b/util/include/axutil_string.h new file mode 100644 index 0000000..6331cd8 --- /dev/null +++ b/util/include/axutil_string.h @@ -0,0 +1,350 @@ + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_STRING_H +#define AXUTIL_STRING_H + +#include <axutil_utils_defines.h> +#include <axutil_error.h> +#include <axutil_env.h> +#include <string.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_string string + * @ingroup axis2_util + * @{ + */ + + typedef struct axutil_string axutil_string_t; + + /** + * Creates a string struct. + * @param str pointer to string. string struct would create a duplicate of + * this + * @param env pointer to environment struct + * @return a pointer to newly created string struct + */ + AXIS2_EXTERN axutil_string_t *AXIS2_CALL + axutil_string_create( + const axutil_env_t * env, + const axis2_char_t * str); + + /** + * Creates a string struct. + * @param str pointer to string. string struct would not create a duplicate + * of this, but would assume ownership + * @param env pointer to environment struct + * @return a pointer to newly created string struct + */ + AXIS2_EXTERN axutil_string_t *AXIS2_CALL + + axutil_string_create_assume_ownership( + const axutil_env_t * env, + axis2_char_t ** str); + + /** + * Creates a string struct. + * @param str pointer to string. string struct would not create a duplicate + * of this and assumes the str would have longer life than that of itself + * @param env pointer to environment struct + * @return a pointer to newly created string struct + */ + AXIS2_EXTERN axutil_string_t *AXIS2_CALL + axutil_string_create_const( + const axutil_env_t * env, + axis2_char_t ** str); + + /** + * Frees string struct. + * @param string pointer to string struct + * @param env pointer to environment struct + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_string_free( + struct axutil_string *string, + const axutil_env_t * env); + + /** + * Compares two strings. Checks if the two strings point to the same buffer. + * Do not cmpare the buffer contents. + * @param string pointer to string struct + * @param env pointer to environment struct + * @param string1 pointer to string struct to be compared + * @return AXIS2_TRUE if string equals string1, AXIS2_FALSE otherwise + */ + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + axutil_string_equals( + const struct axutil_string *string, + const axutil_env_t * env, + const struct axutil_string *string1); + + /** + * Clones a given string. Does not duplicate the buffer, rather + * increments the reference count. Each call to clone needs to have a + * matching free, when the clone is done with. + * @param string pointer to string struct + * @param env pointer to environment struct + * @returns pointer to cloned string struct instance + */ + AXIS2_EXTERN struct axutil_string *AXIS2_CALL + axutil_string_clone( + struct axutil_string *string, + const axutil_env_t * env); + + /** + * Gets string buffer. + * @param string pointer to string struct + * @param env pointer to environment struct + * @returns pointer to string buffer + */ + AXIS2_EXTERN const axis2_char_t *AXIS2_CALL + axutil_string_get_buffer( + const struct axutil_string *string, + const axutil_env_t * env); + + /** + * Gets string length. * @param string pointer to string struct * @param env pointer to environment struct * @returns buffer length */ + AXIS2_EXTERN unsigned int AXIS2_CALL + axutil_string_get_length( + const struct axutil_string *string, + const axutil_env_t * env); + + /** @} */ + + /** + * @defgroup axutil_string_utils string_utils + * @ingroup axis2_util + * @{ + */ + + AXIS2_EXTERN void *AXIS2_CALL + axutil_strdup( + const axutil_env_t * env, + const void *ptr); + + /** + * 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 + axutil_strndup( + const axutil_env_t * env, + const void *ptr, + int n); + + /** + * 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 + axutil_strmemdup( + const void *ptr, + size_t n, + const axutil_env_t * env); + + AXIS2_EXTERN void *AXIS2_CALL + axutil_memchr( + const void *ptr, + int c, + size_t n); + + AXIS2_EXTERN int AXIS2_CALL + axutil_strcmp( + const axis2_char_t * s1, + const axis2_char_t * s2); + + AXIS2_EXTERN int AXIS2_CALL + axutil_strncmp( + const axis2_char_t * s1, + const axis2_char_t * s2, + int n); + + AXIS2_EXTERN axis2_ssize_t AXIS2_CALL + axutil_strlen( + const axis2_char_t * s); + + AXIS2_EXTERN int AXIS2_CALL + axutil_strcasecmp( + const axis2_char_t * s1, + const axis2_char_t * s2); + + AXIS2_EXTERN int AXIS2_CALL + axutil_strncasecmp( + const axis2_char_t * s1, + const axis2_char_t * s2, + const int n); + + /* much similar to the strcat behaviour. But the difference is + * this allocates new memory to put the conatenated string rather than + * modifying the first argument. The user should free the allocated + * memory for the return value + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_stracat( + const axutil_env_t * env, + const axis2_char_t * s1, + const axis2_char_t * s2); + + /** + * Concatenate multiple strings, allocating memory + * @param ... The strings to concatenate. The final string must be NULL + * @return The new string + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_strcat( + const axutil_env_t * env, + ...); + + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_strstr( + const axis2_char_t * heystack, + const axis2_char_t * needle); + + /** + * Finds the first occurrence of a character in a string + * @param s String in which the character is searched + * @param ch Character to be searched + * @return Pointer to to the first occurence of the charecter if it could + * be found in the string, NULL otherwise + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_strchr( + const axis2_char_t * s, + axis2_char_t ch); + + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_rindex( + const axis2_char_t * s, + axis2_char_t c); + + /* replaces s1 with s2 */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_replace( + const axutil_env_t * env, + axis2_char_t * str, + int s1, + int s2); + + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_strltrim( + const axutil_env_t * env, + const axis2_char_t * _s, + const axis2_char_t * _trim); + + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_strrtrim( + const axutil_env_t * env, + const axis2_char_t * _s, + const axis2_char_t * _trim); + + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_strtrim( + const axutil_env_t * env, + const axis2_char_t * _s, + const axis2_char_t * _trim); + + /** + * replace given axis2_character with a new one. + * @param str string operation apply + * @param old_char the old axis2_character which would be replaced + * @param new_char new axis2_char_tacter + * @return replaced string + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_string_replace( + axis2_char_t * str, + axis2_char_t old_char, + axis2_char_t new_char); + + /** + * gives a sub string starting with given index. + * @param str string operation apply + * @param c starting index + * @return substring + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + + axutil_string_substring_starting_at( + axis2_char_t * str, + int s); + + /** + * gives a sub string ending with given index. + * @param str string operation apply + * @param c ending index + * @return substring + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_string_substring_ending_at( + axis2_char_t * str, + int e); + + /** + * set a string to lowercase. + * @param str string + * @return string with lowercase + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_string_tolower( + axis2_char_t * str); + + /** + * set a string to uppercase. + * @param str string + * @return string with uppercase + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_string_toupper( + axis2_char_t * str); + + /** + * Finds the first occurrence of the substring needle in the string + * haystack, ignores the case of both arguments. + * @param haystack string in which the given string is to be found + * @param needle string to be found in haystack + * @return pointer to the beginning of the substring, + * or NULL if the substring is not found + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_strcasestr( + const axis2_char_t * heystack, + const axis2_char_t * needle); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_STRING_H */ diff --git a/util/include/axutil_string_util.h b/util/include/axutil_string_util.h new file mode 100644 index 0000000..e1de886 --- /dev/null +++ b/util/include/axutil_string_util.h @@ -0,0 +1,56 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_STRING_UTIL_H +#define AXUTIL_STRING_UTIL_H + +#include <axutil_array_list.h> +#include <axutil_string.h> +#ifdef __cplusplus +extern "C" +{ +#endif + + AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL + axutil_tokenize( + const axutil_env_t * env, + axis2_char_t * in, + int delim); + + AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL + axutil_first_token( + const axutil_env_t * env, + axis2_char_t * in, + int delim); + + /** + * @return returns array_list containing, the string portion + * without the last token as the first item and the last + * token as the second. If the last token was the only token + * found, the first item will be a "" string. + */ + AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL + axutil_last_token( + const axutil_env_t * env, + axis2_char_t * in, + int delim); + +#ifdef __cplusplus +} +#endif +#endif /* AXIS2_STRING_UTIL_H */ diff --git a/util/include/axutil_thread.h b/util/include/axutil_thread.h new file mode 100644 index 0000000..271c2aa --- /dev/null +++ b/util/include/axutil_thread.h @@ -0,0 +1,272 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_THREAD_H +#define AXUTIL_THREAD_H + +/** + * @file axutil_thread.h + * @brief axis2 thread api + */ + +#include <axutil_allocator.h> +#include <axutil_utils_defines.h> +#include <axutil_error.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_thread thread + * @ingroup axis2_util + * @{ + */ + + /** + * Thread callbacks from axis2 functions must be declared with AXIS2_THREAD_FUNC + * so that they follow the platform's calling convention. + */ + /*#define AXIS2_THREAD_FUNC */ + + /** Thread structure. */ + typedef struct axutil_thread_t axutil_thread_t; + + /** Thread attributes structure. */ + typedef struct axutil_threadattr_t axutil_threadattr_t; + + /** Control variable for one-time atomic variables. */ + typedef struct axutil_thread_once_t axutil_thread_once_t; + + /** + * The prototype for any AXIS2 thread worker functions. + */ + typedef void *( + AXIS2_THREAD_FUNC * axutil_thread_start_t)( + axutil_thread_t *, + void *); + + /** Thread private address space. */ + typedef struct axutil_threadkey_t axutil_threadkey_t; + + /* Thread Function definitions */ + + /** + * Create and initialize a new threadattr variable + * @param cont The pool to use + * @return Newly created thread attribute + */ + AXIS2_EXTERN axutil_threadattr_t *AXIS2_CALL + axutil_threadattr_create( + axutil_allocator_t * allocator); + + /** + * Set if newly created threads should be created in detached state. + * @param attr The threadattr to affect + * @param on Non-zero if detached threads should be created. + * @return The status of the operation + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_threadattr_detach_set( + axutil_threadattr_t * attr, + axis2_bool_t detached); + + /** + * Get the detach state for this threadattr. + * @param attr The threadattr to reference + * @return AXIS2_TRUE if threads are to be detached, or AXIS2_FALSE + * if threads are to be joinable. + */ + AXIS2_EXTERN axis2_bool_t AXIS2_CALL + axutil_threadattr_is_detach( + axutil_threadattr_t * attr, + axutil_allocator_t * allocator); + + /** + * Create a new thread of execution + * @param attr The threadattr to use to determine how to create the thread + * @param func The function to start the new thread in + * @param data Any data to be passed to the starting function + * @param cont The pool to use + * @return The newly created thread handle. + */ + AXIS2_EXTERN axutil_thread_t *AXIS2_CALL + axutil_thread_create( + axutil_allocator_t * allocator, + axutil_threadattr_t * attr, + axutil_thread_start_t func, + void *data); + + /** + * Stop the current thread + * @param thd The thread to stop + * @return The status of the operation + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_thread_exit( + axutil_thread_t * thd, + axutil_allocator_t * allocator); + + /** + * Block until the desired thread stops executing. + * @param thd The thread to join + * @return The status of the operation + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_thread_join( + axutil_thread_t * thd); + + /** + * force the current thread to yield the processor + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_thread_yield(void + ); + + /** + * function is used to allocate a new key. This key now becomes valid for all threads in our process. + * When a key is created, the value it points to defaults to NULL. Later on each thread may change + * its copy of the value as it wishes. + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_thread_key_create( + axutil_threadkey_t * axis2_key); + /** + * This function is used to get the value of a given key + * @return void*. A key's value is simply a void pointer (void*) + */ + AXIS2_EXTERN void *AXIS2_CALL + axutil_thread_getspecific( + axutil_threadkey_t * axis2_key); + + /** + * This function is used to get the value of a given key + * @param keys value. A key's value is simply a void pointer (void*), so we can + * store in it anything that we want + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_thread_setspecific( + axutil_threadkey_t * axis2_key, + void *value); + + /** + * This function is used free the tls key. + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_thread_key_free( + axutil_threadkey_t * axis2_key); + + /** + * Initialize the control variable for axutil_thread_once. + * @param control The control variable to initialize + * @return The status of the operation + */ + AXIS2_EXTERN axutil_thread_once_t *AXIS2_CALL + axutil_thread_once_init( + axutil_allocator_t * allocator); + + /** + * Run the specified function one time, regardless of how many threads + * call it. + * @param control The control variable. The same variable should + * be passed in each time the function is tried to be + * called. This is how the underlying functions determine + * if the function has ever been called before. + * @param func The function to call. + * @return The status of the operation + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_thread_once( + axutil_thread_once_t * control, + void(*func)(void)); + + /** + * detach a thread + * @param thd The thread to detach + * @return The status of the operation + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_thread_detach( + axutil_thread_t * thd); + + + /*************************Thread locking functions*****************************/ + + /** Opaque thread-local mutex structure */ + typedef struct axutil_thread_mutex_t axutil_thread_mutex_t; + +#define AXIS2_THREAD_MUTEX_DEFAULT 0x0 /**< platform-optimal lock behavior */ + +#define AXIS2_THREAD_MUTEX_NESTED 0x1 /**< enable nested (recursive) locks */ + +#define AXIS2_THREAD_MUTEX_UNNESTED 0x2 /**< disable nested locks */ + + /** + * Create and initialize a mutex that can be used to synchronize threads. + * @param allocator Memory allocator to allocate memory for the mutex + * @warning Be cautious in using AXIS2_THREAD_MUTEX_DEFAULT. While this is the + * most optimal mutex based on a given platform's performance characteristics, + * it will behave as either a nested or an unnested lock. + */ + AXIS2_EXTERN axutil_thread_mutex_t *AXIS2_CALL + + axutil_thread_mutex_create( + axutil_allocator_t * allocator, + unsigned int flags); + + /** + * Acquire the lock for the given mutex. If the mutex is already locked, + * the current thread will be put to sleep until the lock becomes available. + * @param mutex the mutex on which to acquire the lock. + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_thread_mutex_lock( + axutil_thread_mutex_t * mutex); + + /** + * Attempt to acquire the lock for the given mutex. If the mutex has already + * been acquired, the call returns immediately + * @param mutex the mutex on which to attempt the lock acquiring. + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_thread_mutex_trylock( + axutil_thread_mutex_t * mutex); + + /** + * Release the lock for the given mutex. + * @param mutex the mutex from which to release the lock. + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_thread_mutex_unlock( + axutil_thread_mutex_t * mutex); + + /** + * Destroy the mutex and free the memory associated with the lock. + * @param mutex the mutex to destroy. + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_thread_mutex_destroy( + axutil_thread_mutex_t * mutex); + + /** @} */ +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_THREAD_H */ diff --git a/util/include/axutil_thread_pool.h b/util/include/axutil_thread_pool.h new file mode 100644 index 0000000..d8bd8a0 --- /dev/null +++ b/util/include/axutil_thread_pool.h @@ -0,0 +1,126 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_THREAD_POOL_H +#define AXUTIL_THREAD_POOL_H + +/** + * @file axutil_thread_pool.h + * @brief Axis2 thread pool interface + */ + +#include <axutil_utils_defines.h> +#include <axutil_allocator.h> +#include <axutil_thread.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_thread_pool thread pool + * @ingroup axis2_util + * @{ + */ + + typedef struct axutil_thread_pool axutil_thread_pool_t; + struct axutil_env; + + /** + * Retrives a thread from the thread pool + * @param func function to be executed in the new thread + * @param data arguments to be passed to the function + * @return pointer to a thread in ready state. + */ + AXIS2_EXTERN axutil_thread_t *AXIS2_CALL + axutil_thread_pool_get_thread( + axutil_thread_pool_t * pool, + axutil_thread_start_t func, + void *data); + + /** + * Blocks until the desired thread stops executing. + * @param thd The thread to joined + * @return status of the operation + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_thread_pool_join_thread( + axutil_thread_pool_t * pool, + axutil_thread_t * thd); + + /** + * Stop the execution of current thread + * @param thd thread to be stopped + * @return status of the operation + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_thread_pool_exit_thread( + axutil_thread_pool_t * pool, + axutil_thread_t * thd); + + /** + * Detaches a thread + * @param thd thread to be detached + * @return status of the operation + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_thread_pool_thread_detach( + axutil_thread_pool_t * pool, + axutil_thread_t * thd); + + /** + * Frees resources used by thread_pool + * @param pool thread_pool to be freed + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_thread_pool_free( + axutil_thread_pool_t * pool); + + /** + * Initializes (creates) an thread_pool. + * @param allocator user defined allocator for the memory allocation. + * @return initialized thread_pool. NULL on error. + */ + AXIS2_EXTERN axutil_thread_pool_t *AXIS2_CALL + axutil_thread_pool_init( + axutil_allocator_t * allocator); + + /** + * This function can be used to initialize the environment in case of + * spawning a new thread via a thread function + */ + AXIS2_EXTERN struct axutil_env *AXIS2_CALL + axutil_init_thread_env( + const struct axutil_env *system_env); + + /** + * This function can be used to free the environment that was used + * in a thread function + */ + AXIS2_EXTERN void AXIS2_CALL + axutil_free_thread_env( + struct axutil_env *thread_env); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_THREAD_POOL_H */ diff --git a/util/include/axutil_types.h b/util/include/axutil_types.h new file mode 100644 index 0000000..d6df339 --- /dev/null +++ b/util/include/axutil_types.h @@ -0,0 +1,73 @@ + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_TYPES_H +#define AXUTIL_TYPES_H + +#include <axutil_utils_defines.h> +#include <axutil_error.h> +#include <axutil_env.h> +#include <stdlib.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_types type convertors + * @ingroup axis2_util + * @{ + */ + + AXIS2_EXTERN int AXIS2_CALL + axutil_atoi( + const char *s); + +#define AXIS2_ATOI(s) axutil_atoi(s) + + AXIS2_EXTERN uint64_t AXIS2_CALL + axutil_strtoul( + const char *nptr, + char **endptr, + int base); + +#define AXIS2_STRTOUL(s, e, b) axutil_strtoul(s, e, b) + + AXIS2_EXTERN int64_t AXIS2_CALL + axutil_strtol( + const char *nptr, + char **endptr, + int base); + +#define AXIS2_STRTOL(s, e, b) axutil_strtol(s, e, b) + + + AXIS2_EXTERN int64_t AXIS2_CALL + axutil_atol( + const char *s); + +#define AXIS2_ATOL(s) axutil_atol(s) + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_TYPES_H */ diff --git a/util/include/axutil_uri.h b/util/include/axutil_uri.h new file mode 100644 index 0000000..45edc64 --- /dev/null +++ b/util/include/axutil_uri.h @@ -0,0 +1,277 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_URI_H +#define AXUTIL_URI_H + +/** + * @file axutil_uri.h + * @brief AXIS2-UTIL URI Routines + * axutil_uri.h: External Interface of axutil_uri.c + */ + +#include <axutil_string.h> +#include <axutil_utils.h> +#include <axutil_utils_defines.h> +#include <axutil_env.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_uri URI + * @ingroup axis2_util + * @{ + */ + +#define AXIS2_URI_FTP_DEFAULT_PORT 21 /**< default FTP port */ + +#define AXIS2_URI_SSH_DEFAULT_PORT 22 /**< default SSH port */ + +#define AXIS2_URI_TELNET_DEFAULT_PORT 23 /**< default telnet port */ + +#define AXIS2_URI_GOPHER_DEFAULT_PORT 70 /**< default Gopher port */ + +#define AXIS2_URI_HTTP_DEFAULT_PORT 80 /**< default HTTP port */ + +#define AXIS2_URI_POP_DEFAULT_PORT 110 /**< default POP port */ + +#define AXIS2_URI_NNTP_DEFAULT_PORT 119 /**< default NNTP port */ + +#define AXIS2_URI_IMAP_DEFAULT_PORT 143 /**< default IMAP port */ + +#define AXIS2_URI_PROSPERO_DEFAULT_PORT 191 /**< default Prospero port */ + +#define AXIS2_URI_WAIS_DEFAULT_PORT 210 /**< default WAIS port */ + +#define AXIS2_URI_LDAP_DEFAULT_PORT 389 /**< default LDAP port */ + +#define AXIS2_URI_HTTPS_DEFAULT_PORT 443 /**< default HTTPS port */ + +#define AXIS2_URI_RTSP_DEFAULT_PORT 554 /**< default RTSP port */ + +#define AXIS2_URI_SNEWS_DEFAULT_PORT 563 /**< default SNEWS port */ + +#define AXIS2_URI_ACAP_DEFAULT_PORT 674 /**< default ACAP port */ + +#define AXIS2_URI_NFS_DEFAULT_PORT 2049 /**< default NFS port */ + +#define AXIS2_URI_TIP_DEFAULT_PORT 3372 /**< default TIP port */ + +#define AXIS2_URI_SIP_DEFAULT_PORT 5060 /**< default SIP port */ + + /** Flags passed to unparse_uri_components(): */ + + /** suppress "scheme://user\@site:port" */ +#define AXIS2_URI_UNP_OMITSITEPART (1U<<0) + + /** Just omit user */ +#define AXIS2_URI_UNP_OMITUSER (1U<<1) + + /** Just omit password */ +#define AXIS2_URI_UNP_OMITPASSWORD (1U<<2) + + /** omit "user:password\@" part */ +#define AXIS2_URI_UNP_OMITUSERINFO (AXIS2_URI_UNP_OMITUSER | \ + AXIS2_URI_UNP_OMITPASSWORD) + + /** Show plain text password (default: show XXXXXXXX) */ +#define AXIS2_URI_UNP_REVEALPASSWORD (1U<<3) + + /** Show "scheme://user\@site:port" only */ +#define AXIS2_URI_UNP_OMITPATHINFO (1U<<4) + + /** Omit the "?queryarg" from the path */ +#define AXIS2_URI_UNP_OMITQUERY_ONLY (1U<<5) + + /** Omit the "#fragment" from the path */ +#define AXIS2_URI_UNP_OMITFRAGMENT_ONLY (1U<<6) + + /** Omit the "?queryarg" and "#fragment" from the path */ +#define AXIS2_URI_UNP_OMITQUERY (AXIS2_URI_UNP_OMITQUERY_ONLY | \ + AXIS2_URI_UNP_OMITFRAGMENT_ONLY) + + /** @see axutil_uri_t */ + typedef unsigned short axis2_port_t; + /* axutil_uri.c */ + + typedef struct axutil_uri axutil_uri_t; + + /** + * Creates axutil_uri struct. + * @param env pointer to environment struct. MUST NOT be NULL + * @return pointer to newly created axutil_uri struct + */ + AXIS2_EXTERN axutil_uri_t *AXIS2_CALL + axutil_uri_create( + const axutil_env_t * env); + + /** + * Return the default port for a given scheme. The schemes recognized are + * http, ftp, https, gopher, wais, nntp, snews, and prospero + * @param scheme_str The string that contains the current scheme + * @return The default port for this scheme + */ + AXIS2_EXTERN axis2_port_t AXIS2_CALL + axutil_uri_port_of_scheme( + const axis2_char_t * scheme_str); + + /** + * Parse a given URI, fill in all supplied fields of a axutil_uri + * structure. This eliminates the necessity of extracting host, port, + * path, query info repeatedly in the modules. + * @param uri The uri to parse + * @param uptr The axutil_uri_t to fill out + * @return AXIS2_SUCCESS for success or error code + */ + AXIS2_EXTERN axutil_uri_t *AXIS2_CALL + axutil_uri_parse_string( + const axutil_env_t * env, + const axis2_char_t * uri); + + /** + * Special case for CONNECT parsing: it comes with the hostinfo part only + * @param hostinfo The hostinfo string to parse + * @param uptr The axutil_uri_t to fill out + * @return AXIS2_SUCCESS for success or error code + */ + AXIS2_EXTERN axutil_uri_t *AXIS2_CALL + axutil_uri_parse_hostinfo( + const axutil_env_t * env, + const axis2_char_t * hostinfo); + + /** Resolve relative to a base. This means host/etc, and (crucially) path */ + AXIS2_EXTERN axutil_uri_t *AXIS2_CALL + axutil_uri_resolve_relative( + const axutil_env_t * env, + const axutil_uri_t * base, + axutil_uri_t * uptr); + + /** + * Return a URI created from a context URI and a relative URI. + * If a valid URI cannot be created the only other possibility + * this method will consider is that an absolute file path has + * been passed in as the relative URI argument, and it will try + * to create a 'file' URI from it. + * + * @param context_uri the document base URI + * @param uri a file URI relative to the context_uri or an + * absolute file path + * @return the URIcreated from context_uri and uri + */ + AXIS2_EXTERN axutil_uri_t *AXIS2_CALL + axutil_uri_parse_relative( + const axutil_env_t * env, + const axutil_uri_t * base, + const char *uri); + + AXIS2_EXTERN void AXIS2_CALL + axutil_uri_free( + axutil_uri_t * uri, + const axutil_env_t * env); + + /** + * Unparse a axutil_uri_t structure to an URI string. Optionally + * suppress the password for security reasons. + * @param uptr All of the parts of the uri + * @param flags How to unparse the uri. One of: + * <PRE> + * AXIS2_URI_UNP_OMITSITEPART Suppress "scheme://user\@site:port" + * AXIS2_URI_UNP_OMITUSER Just omit user + * AXIS2_URI_UNP_OMITPASSWORD Just omit password + * AXIS2_URI_UNP_OMITUSERINFO Omit "user:password\@" part + * AXIS2_URI_UNP_REVEALPASSWORD Show plain text password (default: show XXXXXXXX) + * AXIS2_URI_UNP_OMITPATHINFO Show "scheme://user\@site:port" only + * AXIS2_URI_UNP_OMITQUERY Omit "?queryarg" or "#fragment" + * </PRE> + * @return The uri as a string + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_uri_to_string( + const axutil_uri_t * uri, + const axutil_env_t * env, + unsigned flags); + + /** + * @return returns actual reference, not a cloned copy. + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_uri_get_protocol( + axutil_uri_t * uri, + const axutil_env_t * env); + + /** + * @return returns actual reference, not a cloned copy. + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_uri_get_server( + axutil_uri_t * uri, + const axutil_env_t * env); + + /** + * @return returns actual reference, not a cloned copy. + * For IPv6 addresses, the IPv6 Address will be returned + * rather than the IP-literal as defined in RFC3986. + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_uri_get_host( + axutil_uri_t * uri, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_port_t AXIS2_CALL + axutil_uri_get_port( + axutil_uri_t * uri, + const axutil_env_t * env); + + /** + * @return returns actual reference, not a cloned copy. + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_uri_get_path( + axutil_uri_t * uri, + const axutil_env_t * env); + + AXIS2_EXTERN axutil_uri_t *AXIS2_CALL + axutil_uri_clone( + const axutil_uri_t * uri, + const axutil_env_t * env); + + /** + * @return returns actual reference, not a cloned copy. + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_uri_get_query( + axutil_uri_t * uri, + const axutil_env_t * env); + + /** + * @return returns actual reference, not a cloned copy. + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_uri_get_fragment( + axutil_uri_t * uri, + const axutil_env_t * env); + + /** @} */ +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_URI_H */ diff --git a/util/include/axutil_url.h b/util/include/axutil_url.h new file mode 100644 index 0000000..7a42c2a --- /dev/null +++ b/util/include/axutil_url.h @@ -0,0 +1,149 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_URL_H +#define AXUTIL_URL_H + +/** + * @file axutil_url.h + * @brief axis2 URL container implementation + */ + +#include <axutil_utils.h> +#include <axutil_utils_defines.h> +#include <axutil_env.h> +#include <axutil_uri.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @ingroup axis2_core_transport_http + * @{ + */ + + typedef struct axutil_url axutil_url_t; + + AXIS2_EXTERN axutil_url_t *AXIS2_CALL + axutil_url_create( + const axutil_env_t * env, + const axis2_char_t * protocol, + const axis2_char_t * host, + const int port, + const axis2_char_t * path); + + AXIS2_EXTERN axutil_url_t *AXIS2_CALL + axutil_url_parse_string( + const axutil_env_t * env, + const axis2_char_t * str_url); + + AXIS2_EXTERN axutil_uri_t *AXIS2_CALL + axutil_url_to_uri( + axutil_url_t * url, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_url_to_external_form( + axutil_url_t * url, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_url_set_protocol( + axutil_url_t * url, + const axutil_env_t * env, + axis2_char_t * protocol); + + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_url_get_protocol( + axutil_url_t * url, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_url_set_host( + axutil_url_t * url, + const axutil_env_t * env, + axis2_char_t * host); + + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_url_get_host( + axutil_url_t * url, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_url_set_server( + axutil_url_t * url, + const axutil_env_t * env, + axis2_char_t * server); + + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_url_get_server( + axutil_url_t * url, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_url_set_port( + axutil_url_t * url, + const axutil_env_t * env, + int port); + + AXIS2_EXTERN int AXIS2_CALL + axutil_url_get_port( + axutil_url_t * url, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_url_set_path( + axutil_url_t * url, + const axutil_env_t * env, + axis2_char_t * path); + + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_url_get_path( + axutil_url_t * url, + const axutil_env_t * env); + + AXIS2_EXTERN axutil_url_t *AXIS2_CALL + axutil_url_clone( + axutil_url_t * url, + const axutil_env_t * env); + + AXIS2_EXTERN void AXIS2_CALL + axutil_url_free( + axutil_url_t * url, + const axutil_env_t * env); + + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_url_encode ( + const axutil_env_t * env, + axis2_char_t * dest, + axis2_char_t * buff, int len); + + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_url_get_query( + axutil_url_t * url, + const axutil_env_t * env); + + + /** @} */ +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_URL_H */ diff --git a/util/include/axutil_utils.h b/util/include/axutil_utils.h new file mode 100644 index 0000000..8c156d1 --- /dev/null +++ b/util/include/axutil_utils.h @@ -0,0 +1,263 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_UTILS_H +#define AXUTIL_UTILS_H + +#include <axutil_utils_defines.h> +#include <axutil_error.h> +#include <axutil_env.h> +#include <axutil_date_time.h> +#include <axutil_base64_binary.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_utils utils + * @ingroup axis2_util + * @{ + */ + + /** + * @file axutil_utils.h + */ + +#define AXUTIL_LOG_FILE_SIZE 1024 * 1024 * 32 +#define AXUTIL_LOG_FILE_NAME_SIZE 512 + + /** This macro is called to check whether structure on which function is called + * is NULL and to check whether the environment structure passed is valid. + * @param object structure on which function is called + * @param env environment to be checked for validity + * @param error_return If function return a status it should pass here + * AXIS2_FAILURE. If function return a type pointer it should + * pass NULL + * @return If function return a status code return AXIS2_SUCCESS. Else if + * function return a type pointer return NULL + */ +#define AXIS2_FUNC_PARAM_CHECK(object, env, error_return) \ + if (!object) \ + { \ + AXIS2_ERROR_SET_ERROR_NUMBER(env->error, AXIS2_ERROR_INVALID_NULL_PARAM); \ + AXIS2_ERROR_SET_STATUS_CODE(env->error, AXIS2_FAILURE); \ + return error_return; \ + } \ + else \ + { \ + AXIS2_ERROR_SET_STATUS_CODE(env->error, AXIS2_SUCCESS); \ + } + + + /**This macro is called to check whether an object is NULL. + * if object is NULL error number and status code is set + * @param object object to be check for NULL + * @param error_return If function return a status it should pass here + * AXIS2_FAILURE. If function return a type pointer it should + * pass NULL + * @return If function return a status code return AXIS2_SUCCESS. Else if + * function return a type pointer return NULL + */ +#define AXIS2_PARAM_CHECK(error, object, error_return) \ + if (!object) \ + { \ + AXIS2_ERROR_SET_ERROR_NUMBER(error, AXIS2_ERROR_INVALID_NULL_PARAM); \ + AXIS2_ERROR_SET_STATUS_CODE(error, AXIS2_FAILURE); \ + return error_return; \ + } \ + else \ + { \ + AXIS2_ERROR_SET_STATUS_CODE(error, AXIS2_SUCCESS); \ + } + + + +#define AXIS2_PARAM_CHECK_VOID(error, object) \ + if (!object) \ + { \ + AXIS2_ERROR_SET_ERROR_NUMBER(error, AXIS2_ERROR_INVALID_NULL_PARAM); \ + AXIS2_ERROR_SET_STATUS_CODE(error, AXIS2_FAILURE); \ + return; \ + } + + + + /**This macro is used to handle error situation. + * @param error_number Error number for the error occured + * @param error_return If function return a status it should pass here + * AXIS2_FAILURE. If function return a type pointer it should + * pass NULL + * @return If function return a status code return AXIS2_SUCCESS. Else if + * function return a type pointer return NULL + */ +#define AXIS2_ERROR_SET(error, error_number, status_code) \ + { \ + AXIS2_ERROR_SET_ERROR_NUMBER(error, error_number); \ + AXIS2_ERROR_SET_STATUS_CODE(error, status_code); \ + } + + /** + * This macro is used to set and error, and log it. In addition to that + * you are capable of specifying the file name and line number + * @param env Reference to env struct + * @param error_number Error number for the error occured + * @param status_code The Error Status to be set + * @param file_name_line_no File name and line number constant + */ +#define AXIS2_HANDLE_ERROR_WITH_FILE(env, error_number, \ + status_code, file_name_line_no) \ + { \ + AXIS2_ERROR_SET(env->error, error_number, status_code); \ + AXIS2_LOG_ERROR(env->log, file_name_line_no, \ + AXIS2_ERROR_GET_MESSAGE(env->error)); \ + } + + /** + * This macro is used to set and error, and log it + * @param env Reference to env struct + * @param error_number Error number for the error occured + * @param status_code The Error Status to be set + */ +#define AXIS2_HANDLE_ERROR(env, error_number, status_code) \ + AXIS2_HANDLE_ERROR_WITH_FILE(env, error_number, status_code, \ + AXIS2_LOG_SI) \ + + /** Method names in the loadable libraries */ + +#define AXIS2_CREATE_FUNCTION "axis2_get_instance" +#define AXIS2_DELETE_FUNCTION "axis2_remove_instance" + + typedef void( + AXIS2_CALL + * AXIS2_FREE_VOID_ARG)( + void *obj_to_be_freed, + const axutil_env_t * env); + + /* Function pointer typedef for read callback */ + typedef int( + AXIS2_CALL + * AXIS2_READ_INPUT_CALLBACK)( + char *buffer, + int size, + void *ctx); + + /* Function pointer typedef for close callback */ + typedef int( + AXIS2_CALL + * AXIS2_CLOSE_INPUT_CALLBACK)( + void *ctx); + + /** + * \brief Axis2 scopes + * + * Possible scope value for Axis2 + */ + enum axis2_scopes + { + + /** Request scope */ + AXIS2_SCOPE_REQUEST = 0, + + /** Session scope */ + AXIS2_SCOPE_SESSION, + + /** Application scope */ + AXIS2_SCOPE_APPLICATION + }; + +#define AXIS2_TARGET_EPR "target_epr" +#define AXIS2_DUMP_INPUT_MSG_TRUE "dump" + + /** + * This function allows the user match a REST URL template with the + * Request URL. It returns a 3-dimensional array with pairs of elements + * of axis2_char_t arrays (strings). The caller is responsible to free + * the memory allocated by the function for the return value. + * @param env pointer to environment struct + * @param tmpl Template to Match + * @param url Request URL + * @param match_count variable to store match count + * @param matches axis2_char_t *** <code>axis2_char_t ***<code> + * @return AXIS2_SUCCESS if all matches were found or AXIS2_FAILURE. + */ + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_parse_rest_url_for_params( + const axutil_env_t * env, + const axis2_char_t * tmpl, + const axis2_char_t * url, + int * match_count, + axis2_char_t **** matches); + + /** + * This function allows users to resolve the service and op from the + * url. It returns an array of 2 elements of axis2_char_t arrays (strings). + * The caller is responsible to free the memory allocated by the function + * for the return value. + * @param env pointer to environment struct + * @param request url + * @return axis2_char_t ** <code>axis2_char_t **<code> + */ + AXIS2_EXTERN axis2_char_t **AXIS2_CALL + axutil_parse_request_url_for_svc_and_op( + const axutil_env_t * env, + const axis2_char_t * request); + + /** + * Quotes an XML string. + * Replace '<', '>', and '&' with '<', '>', and '&'. + * If quotes is true, then replace '"' with '"'. + * @param env pointer to environment struct + * @param s string to be quoted + * @param quotes if AXIS2_TRUE then replace '"' with '"'. + * quotes is typically set to true for XML strings that will occur within + * double quotes -- attribute values. + * @return Encoded string if there are characters to be encoded, else NULL. + * The caller is responsible to free the memory allocated by the function + * for the return value + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_xml_quote_string( + const axutil_env_t * env, + const axis2_char_t * s, + axis2_bool_t quotes); + + AXIS2_EXTERN int AXIS2_CALL + axutil_hexit(axis2_char_t c); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axutil_url_decode( + const axutil_env_t * env, + axis2_char_t * dest, + axis2_char_t * src); + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_char_2_byte( + const axutil_env_t *env, + axis2_char_t *char_buffer, + axis2_byte_t **byte_buffer, + int *byte_buffer_size); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_UTILS_H */ diff --git a/util/include/axutil_utils_defines.h b/util/include/axutil_utils_defines.h new file mode 100644 index 0000000..c12c842 --- /dev/null +++ b/util/include/axutil_utils_defines.h @@ -0,0 +1,226 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_UTILS_DEFINES_H +#define AXUTIL_UTILS_DEFINES_H + +#include <stddef.h> + +#if !defined(_WIN32) +#include <stdint.h> +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + +#if defined(_WIN32) && !defined(AXIS2_SKIP_INT_TYPEDEFS) + /** + * ANSI Type definitions for Windows + */ + typedef unsigned __int8 uint8_t; + typedef __int8 int8_t; + typedef unsigned __int16 uint16_t; + typedef __int16 int16_t; + typedef unsigned __int32 uint32_t; + typedef __int32 int32_t; + typedef unsigned __int64 uint64_t; + typedef __int64 int64_t; +#endif + +/** + * Definition of format specifiers + * for printf family of functions + */ + +#if defined(_WIN32) +#define AXIS2_PRINTF_INT64_FORMAT_SPECIFIER "%I64d" +#define AXIS2_PRINTF_UINT64_FORMAT_SPECIFIER "%I64u" +#define AXIS2_PRINTF_INT32_FORMAT_SPECIFIER "%I32d" +#define AXIS2_PRINTF_UINT32_FORMAT_SPECIFIER "%I32u" +#else +#if __WORDSIZE == 64 +#define AXIS2_PRINTF_INT64_FORMAT_SPECIFIER "%ld" +#define AXIS2_PRINTF_UINT64_FORMAT_SPECIFIER "%lu" +#else +#define AXIS2_PRINTF_INT64_FORMAT_SPECIFIER "%lld" +#define AXIS2_PRINTF_UINT64_FORMAT_SPECIFIER "%llu" +#endif +#define AXIS2_PRINTF_INT32_FORMAT_SPECIFIER "%d" +#define AXIS2_PRINTF_UINT32_FORMAT_SPECIFIER "%u" +#endif + + /** + * Type definitions + */ + typedef char axis2_char_t; + typedef int axis2_bool_t; + typedef int axis2_status_t; + typedef int axis2_scope_t; + typedef unsigned int axis2_ssize_t; + typedef char axis2_byte_t; + typedef unsigned char axis2_unsigned_byte_t; + +#define AXIS2_STRING(s) s + +#define AXIS2_CHAR(c) c + +#define AXIS2_CRLF_LENGTH 2 + +#define AXIS2_CRLF "\r\n" + + /* These constant definitions should later be moved to platform dependant + * files + */ + +#define AXIS2_EOLN '\0' + + /** + * Boolean values + */ +#define AXIS2_TRUE 1 +#define AXIS2_FALSE 0 + + /** + * Exporting + */ +#if defined(_WIN32) && !defined(AXIS2_DECLARE_STATIC) +#define AXIS2_EXPORT __declspec(dllexport) +#else +#define AXIS2_EXPORT +#endif + + /** + * Importing + */ +#if defined(_WIN32) +#define AXIS2_IMPORT __declspec(dllimport) +#else +#define AXIS2_IMPORT +#endif + + /** + * Calling Conventions + */ +#if defined(__GNUC__) +#if defined(__i386) +#define AXIS2_CALL __attribute__((cdecl)) +#define AXIS2_WUR __attribute__((warn_unused_result)) +#else +#define AXIS2_CALL +#define AXIS2_WUR + + +#endif +#else +#if defined(__unix) +#define AXIS2_CALL +#define AXIS2_WUR + + +#else /* WIN32 */ +#define AXIS2_CALL __stdcall +#define AXIS2_WUR +#endif +#endif +#define AXIS2_THREAD_FUNC AXIS2_CALL + + +#ifdef DOXYGEN + + /* define these just so doxygen documents them */ + + /** + * AXIS2_DECLARE_STATIC is defined when including Axis2's Core headers, + * to provide static linkage when the dynamic library may be unavailable. + * + * @see AXIS2_DECLARE_EXPORT + * + * AXIS2_DECLARE_STATIC and AXIS2_DECLARE_EXPORT are left undefined when + * including Axis2's Core headers, to import and link the symbols from the + * dynamic Axis2 Core library and assure appropriate indirection and calling + * conventions at compile time. + */ +# define AXIS2_DECLARE_STATIC + + /** + * AXIS2_DECLARE_EXPORT is defined when building the Axis2 Core dynamic + * library, so that all public symbols are exported. + * + * @see AXIS2_DECLARE_STATIC + */ +# define AXIS2_DECLARE_EXPORT + +#endif /* def DOXYGEN */ + +#if !defined(_WIN32) + + /** + * Axis2 Core functions are declared with AXIS2_EXTERN AXIS2_CALL + + , so they may + * use the most appropriate calling convention. Other + * Core functions with variable arguments must use AXIS2_DECLARE_NONSTD(). + * @code + * AXIS2_EXTERN rettype) axis2_func(args AXIS2_CALL + + + * @endcode + */ +#define AXIS2_EXTERN + + /** + * Axis2 Core variable argument and hook functions are declared with + * AXIS2_DECLARE_NONSTD(), as they must use the C language calling convention. + * @see AXIS2_DECLARE + * @code + * AXIS2_DECLARE_NONSTD(rettype) axis2_func(args [...]) + * @endcode + */ +#define AXIS2_DECLARE_NONSTD(type) type + + /** + * Axis2 Core variables are declared with AXIS2_DECLARE_DATA. + * This assures the appropriate indirection is invoked at compile time. + * + * @code + * AXIS2_DECLARE_DATA type axis2_variable + * @endcode + */ +#define AXIS2_DECLARE_DATA + +#elif defined(AXIS2_DECLARE_STATIC) +#define AXIS2_EXTERN +#define AXIS2_EXTERN_NONSTD +#define AXIS2_DECLARE_DATA +#elif defined(AXIS2_DECLARE_EXPORT) +#define AXIS2_EXTERN AXIS2_EXPORT +#define AXIS2_EXTERN_NONSTD AXIS2_EXPORT +#define AXIS2_DECLARE_DATA +#else +#define AXIS2_EXTERN AXIS2_IMPORT +#define AXIS2_EXTERN_NONSTD AXIS2_IMPORT +#define AXIS2_DECLARE_DATA +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_UTILS_DEFINES_H */ diff --git a/util/include/axutil_uuid_gen.h b/util/include/axutil_uuid_gen.h new file mode 100644 index 0000000..2db4583 --- /dev/null +++ b/util/include/axutil_uuid_gen.h @@ -0,0 +1,51 @@ + +/* + * 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 count 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 AXUTIL_UUID_GEN_H +#define AXUTIL_UUID_GEN_H + +#include <axutil_utils.h> +#include <axutil_utils_defines.h> +#include <axutil_env.h> +#include <platforms/axutil_platform_auto_sense.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_uuid_gen UUID generator + * @ingroup axis2_util + * @{ + */ + + /** + * generate a uuid + * @return generated uuid as a string + */ + AXIS2_EXTERN axis2_char_t *AXIS2_CALL + axutil_uuid_gen( + const axutil_env_t * env); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_UUID_GEN_H */ diff --git a/util/include/axutil_version.h b/util/include/axutil_version.h new file mode 100644 index 0000000..116ddfa --- /dev/null +++ b/util/include/axutil_version.h @@ -0,0 +1,140 @@ + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_VERSION_H +#define AXUTIL_VERSION_H + +/* The numeric compile-time version constants. These constants are the + * authoritative version numbers for AXIS2. + */ + +/** major version + * Major API changes that could cause compatibility problems for older + * programs such as structure size changes. No binary compatibility is + * possible across a change in the major version. + */ +#define AXIS2_MAJOR_VERSION 1 + +/** minor version + * Minor API changes that do not cause binary compatibility problems. + * Reset to 0 when upgrading AXIS2_MAJOR_VERSION + */ +#define AXIS2_MINOR_VERSION 6 + +/** patch level + * The Patch Level never includes API changes, simply bug fixes. + * Reset to 0 when upgrading AXIS2_MINOR_VERSION + */ +#define AXIS2_PATCH_VERSION 0 + +/** + * The symbol AXIS2_IS_DEV_VERSION is only defined for internal, + * "development" copies of AXIS2. It is undefined for released versions + * of AXIS2. + */ +#undef AXIS2_IS_DEV_VERSION + +#if defined(AXIS2_IS_DEV_VERSION) || defined(DOXYGEN) + +/** Internal: string form of the "is dev" flag */ +#define AXIS2_IS_DEV_STRING "-dev" +#else +#define AXIS2_IS_DEV_STRING "" +#endif + +/** Properly quote a value as a string in the C preprocessor */ +#define AXIS2_STRINGIFY(n) AXIS2_STRINGIFY_HELPER(n) + +/** Helper macro for AXIS2_STRINGIFY */ +#define AXIS2_STRINGIFY_HELPER(n) #n + +/** The formatted string of AXIS2's version */ +#define AXIS2_VERSION_STRING \ + AXIS2_STRINGIFY(AXIS2_MAJOR_VERSION) "." \ + AXIS2_STRINGIFY(AXIS2_MINOR_VERSION) "." \ + AXIS2_STRINGIFY(AXIS2_PATCH_VERSION) \ + AXIS2_IS_DEV_STRING + +/** An alternative formatted string of AXIS2's version */ + +/* macro for Win32 .rc files using numeric csv representation */ +#define AXIS2_VERSION_STRING_CSV AXIS2_MAJOR_VERSION ##, \ + ##AXIS2_MINOR_VERSION ##, \ + ##AXIS2_PATCH_VERSION + +#ifndef AXIS2_VERSION_ONLY + +/* The C language API to access the version at run time, + * as opposed to compile time. AXIS2_VERSION_ONLY may be defined + * externally when preprocessing axutil_version.h to obtain strictly + * the C Preprocessor macro declarations. + */ + +#include "axutil_env.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * The numeric version information is broken out into fields within this + * structure. + */ + typedef struct + { + + int major; + + /**< major number */ + + int minor; + + /**< minor number */ + + int patch; + + /**< patch number */ + + int is_dev; + + /**< is development (1 or 0) */ + } + axis2_version_t; + + /** + * Return AXIS2's version information information in a numeric form. + * + * @param pvsn Pointer to a version structure for returning the version + * information. + */ + AXIS2_EXTERN void AXIS2_CALL + axis2_version( + axis2_version_t * pvsn); + + /** Return AXIS2's version information as a string. */ + AXIS2_EXTERN const char *AXIS2_CALL + axis2_version_string( + void); + +#ifdef __cplusplus +} +#endif +#endif + +#endif /* AXIS2_VERSION_H */ diff --git a/util/include/platforms/axutil_platform_auto_sense.h b/util/include/platforms/axutil_platform_auto_sense.h new file mode 100644 index 0000000..feec323 --- /dev/null +++ b/util/include/platforms/axutil_platform_auto_sense.h @@ -0,0 +1,63 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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_PLATFORM_AUTOSENSE_H +#define AXIS2_PLATFORM_AUTOSENSE_H + +/** + * @file axutil_platform_auto_sense.h + * @brief axis2 platform auto sense + */ + +/* +#ifdef __cplusplus +extern "C" +{ +#endif +*/ + + /** @defgroup axis2_platform_auto_sense + * @ingroup axis2_platforms + * @{ + */ + +#if defined(_WIN32 ) +#include "windows/axutil_windows.h" +#include "windows/axutil_dir_windows.h" +#include "windows/axutil_uuid_gen_windows.h" +#include "windows/axutil_getopt_windows.h" +#include "windows/axutil_date_time_util_windows.h" +#include "windows/axutil_thread_windows.h" +#elif defined ( __OS400__ ) +#include <os400/axis2_os400.h> +#elif defined ( AIX ) +#include <aix/aix.h> +#elif defined ( HPUX ) +#include <hp-ux/axis2_ht-ux.h> +#else +#include <platforms/unix/axutil_unix.h> +#endif + + /** @} */ +/* +#ifdef __cplusplus +} +#endif +*/ + +#endif /* AXIS2_PLATFORM_AUTOSENSE_H */ diff --git a/util/include/platforms/unix/axutil_date_time_util_unix.h b/util/include/platforms/unix/axutil_date_time_util_unix.h new file mode 100644 index 0000000..9979395 --- /dev/null +++ b/util/include/platforms/unix/axutil_date_time_util_unix.h @@ -0,0 +1,46 @@ + +/* + * 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 count 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 AXUTIL_DATE_TIME_UTIL_UNIX_H +#define AXUTIL_DATE_TIME_UTIL_UNIX_H + +#include <axutil_utils.h> +#include <axutil_utils_defines.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/timeb.h> +#include <time.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axis2_milliseconds + * @ingroup axis2_milliseconds + * @{ + */ + AXIS2_EXTERN int AXIS2_CALL + axis2_platform_get_milliseconds(void + ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/util/include/platforms/unix/axutil_thread_unix.h b/util/include/platforms/unix/axutil_thread_unix.h new file mode 100644 index 0000000..5ee5992 --- /dev/null +++ b/util/include/platforms/unix/axutil_thread_unix.h @@ -0,0 +1,59 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 AXUTIL_THREAD_UNIX_H +#define AXUTIL_THREAD_UNIX_H + +#include <axutil_thread.h> +#include <pthread.h> + +#define SHELL_PATH "/bin/sh" + +typedef pthread_t axis2_os_thread_t; /* Native thread */ + +struct axutil_thread_t +{ + pthread_t *td; + void *data; + axutil_thread_start_t func; + axis2_bool_t try_exit; +}; + +struct axutil_threadattr_t +{ + pthread_attr_t attr; +}; + +struct axutil_threadkey_t +{ + pthread_key_t key; +}; + +struct axutil_thread_once_t +{ + pthread_once_t once; +}; + +/*************************Thread locking functions*****************************/ +struct axutil_thread_mutex_t +{ + axutil_allocator_t *allocator; + pthread_mutex_t mutex; +}; + +#endif /* AXIS2_THREAD_UNIX_H */ diff --git a/util/include/platforms/unix/axutil_unix.h b/util/include/platforms/unix/axutil_unix.h new file mode 100644 index 0000000..fa23eae --- /dev/null +++ b/util/include/platforms/unix/axutil_unix.h @@ -0,0 +1,279 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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_UNIX_H +#define AXIS2_UNIX_H + +#include <axutil_config.h> + +/** + * @file axutil_unix.h + * @brief axis2 unix platform specific interface + */ + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** @defgroup axis2_unix Platform Specific + * @ingroup axis2_platforms_unix + * @{ + */ + + /*************************************************************** + * Default paths to shared library/DLLs and files + *************************************************************** + */ + +#define AXIS2_PLATFORM_DEFAULT_DEPLOY_PATH "" + +#define AXIS2_PLATFORM_XMLPARSER_PATH "libaxis2_parser.so" +#define AXIS2_PLATFORM_TRANSPORTHTTP_PATH "libhttp_transport.so" +#define AXIS2_PLATFORM_CHANNEL_PATH "libhttp_channel.so" +#define AXIS2_PLATFORM_SSLCHANNEL_PATH "Unknown" + +#define AXIS2_PLATFORM_LOG_PATH "/usr/local/axis2/log/axutil_log" +#define AXIS2_PLATFORM_CLIENTLOG_PATH "/usr/local/axis2/log/axis2_client_log" +#define AXIS2_PLATFORM_CONFIG_PATH "/etc/axiscpp.conf" +#define AXIS2_PLATFORM_SECUREINFO "" + + /** + * Resource that contains the configuration + */ +#define AXIS2_CONFIGURATION_RESOURCE "/usr/local/axis2/axis2.xml" + + /***************************************************************** + * Library loading and procedure resolution + ****************************************************************/ +#ifdef USE_LTDL +#include <ltdl.h> +#define AXIS2_DLHANDLER lt_dlhandle + +#define AXIS2_PLATFORM_LOADLIBINIT lt_dlinit +#define AXIS2_PLATFORM_LOADLIB(_lib) lt_dlopen(_lib) +#define AXIS2_PLATFORM_UNLOADLIB lt_dlclose +#define AXIS2_PLATFORM_GETPROCADDR lt_dlsym +#define AXIS2_PLATFORM_LOADLIBEXIT lt_dlexit +#define AXIS2_PLATFORM_LOADLIB_ERROR lt_dlerror() +#else +#include <dlfcn.h> +#define AXIS2_DLHANDLER void* + +#define AXIS2_PLATFORM_LOADLIBINIT() +#define AXIS2_PLATFORM_LOADLIB(_lib) dlopen(_lib, RTLD_LAZY) + /*#define AXIS2_PLATFORM_LOADLIB(_lib) dlopen(_lib, RTLD_NOW) */ + +#define AXIS2_PLATFORM_UNLOADLIB dlclose +#define AXIS2_PLATFORM_GETPROCADDR dlsym +#define AXIS2_PLATFORM_LOADLIBEXIT() +#define AXIS2_PLATFORM_LOADLIB_ERROR dlerror() + +#endif + + /*************************************************************** + * National Language Support + ****************************************************************/ + + /* STRTOASC is to translate single byte 'native' character representation to ASCII */ + + /* ASCTOSTR is to translate single byte ascii representation to 'native' character */ + + /* CANNOT be used with constants */ +#define AXIS2_PLATFORM_STRTOASC( x ) ( x ) +#define AXIS2_PLATFORM_ASCTOSTR( x ) ( x ) + + /*************************************************************** + * Miscellaneous + ****************************************************************/ +#include <sys/time.h> +#include <sys/timeb.h> + + /*#include <unistd.h> */ +#include <errno.h> +#include <sys/param.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <sys/stat.h> +#include <sys/types.h> +#include "axutil_uuid_gen_unix.h" /* uuid_gen unix implementation */ +#include <netinet/tcp.h> /* TCP_NODELAY */ +#include <utime.h> +#include <getopt.h> +#include "axutil_date_time_util_unix.h" + + /* for file access handling */ +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif /*HAVE_UNISTD_H */ + + /* network handling */ +#include <sys/socket.h> +#include <arpa/inet.h> +#include <netinet/in.h> +#include <netdb.h> +#include <sys/ioctl.h> + +#include <fcntl.h> + + /* dir handling */ +#include <sys/types.h> +#include <dirent.h> + +#define AXIS2_STRRCHR(x, y) (strrchr(x, y)) + +#define AXIS2_PLATFORM_SLEEP(x) sleep(0); + + /** sleep function abstraction */ +#define AXIS2_SLEEP sleep +#define AXIS2_USLEEP usleep + + /** + * Get the last error code from the system. + * Please ensure that this is a thread safe implementation + * and that it returns a long + * @return long the last error message for this thread + */ + + /*#define AXIS2_GETLASTERROR errno; */ + + /** + * From the last error number get a sensible std::string representing it + * @param errorNumber the error Number you are trying to get a message for + * @return the error message. NOTE: The caller is responsible for deleting the returned string + */ + + /*#define AXIS2_PLATFORM_GET_ERROR_MESSAGE(errorNumber) new string(strerror(errorNumber)); */ + + /** + * Platform specific method to obtain current thread ID + */ +#include <pthread.h> +#define AXIS2_PLATFORM_GET_THREAD_ID() pthread_self() + + /** + * Platform specific method to obtain current time in milli seconds + */ +#define AXIS2_PLATFORM_GET_TIME_IN_MILLIS ftime +#define AXIS2_PLATFORM_TIMEB timeb + + /** + * type to be used for 64bit integers + */ +#define AXIS2_LONGLONG long long +#define AXIS2_LONGLONGVALUE(value) value##LL +#define AXIS2_UNSIGNED_LONGLONGVALUE(value) value##ULL + + /** + * Format string to be used in printf for 64bit integers + */ +#define AXIS2_PRINTF_LONGLONG_FORMAT_SPECIFIER "%lld" +#define AXIS2_PRINTF_LONGLONG_FORMAT_SPECIFIER_CHARS "lld" +#define AXIS2_PRINTF_UNSIGNED_LONGLONG_FORMAT_SPECIFIER "%llu" +#define AXIS2_PRINTF_UNSIGNED_LONGLONG_FORMAT_SPECIFIER_CHARS "llu" + + /** + * Platform specific path separator char + */ +#ifdef IS_MACOSX +#define AXIS2_PATH_SEP_CHAR '/' +#define AXIS2_PATH_SEP_STR "/" +#define AXIS2_LIB_PREFIX "lib" +#define AXIS2_LIB_SUFFIX ".dylib" +#else +#define AXIS2_PATH_SEP_CHAR '/' +#define AXIS2_PATH_SEP_STR "/" +#define AXIS2_LIB_PREFIX "lib" +#define AXIS2_LIB_SUFFIX ".so" +#endif + + /** + * Platform specific time + */ +#define AXIS2_TIME_T time_t + + /** + * Platform specific file handling + */ +#define AXIS2_FOPEN fopen +#define AXIS2_FREAD fread +#define AXIS2_FWRITE fwrite +#define AXIS2_FCLOSE fclose +#define AXIS2_FTELL ftell +#define AXIS2_ACCESS(zpath,imode) access(zpath,imode) +#define AXIS2_R_OK R_OK /* test for read permission */ +#define AXIS2_W_OK W_OK /* test for write permission */ +#define AXIS2_X_OK X_OK /* test for execute or search permission */ +#define AXIS2_F_OK F_OK /* test whether the directories leading to the file can be + searched and the file exists */ + + /** + * Platform specific environment variable access method + */ +#define AXIS2_GETENV(_env_var_name) getenv(_env_var_name) + + /** + * unix specific directory handling functions + */ +#define AXIS2_SCANDIR scandir +#define AXIS2_ALPHASORT alphasort +#define AXIS2_OPENDIR opendir +#define AXIS2_CLOSEDIR closedir +#define AXIS2_READDIR readdir +#define AXIS2_READDIR_R readdir_r +#define AXIS2_REWINDDIR rewinddir +#define AXIS2_MKDIR mkdir +#define AXIS2_GETCWD getcwd +#define AXIS2_CHDIR chdir + + /** + * network specific functions and defs + */ +#define axis2_socket_t int +#define AXIS2_INVALID_SOCKET -1 +#define AXIS2_INADDR_NONE (in_addr_t)-1 +#define axis2_unsigned_short_t uint16_t +#define AXIS2_CLOSE_SOCKET(sock) close(sock) +#define AXIS2_CLOSE_SOCKET_ON_EXIT(sock) fcntl(sock,F_SETFD, FD_CLOEXEC); +#define axis2_socket_len_t socklen_t +#define AXIS2_SHUT_WR SHUT_WR + + /** getopt function */ +#define AXIS2_GETOPT getopt + + /** minizip functions */ +#define axis2_fill_win32_filefunc(ffunc) +#define AXIS2_UNZOPEN2(zipfilename,ffunc) unzOpen2(zipfilename,NULL); memset(&ffunc, 0, sizeof(ffunc)); + + /** + * handling variable number of arguments (for log.c) + */ +#define AXIS2_VSNPRINTF vsnprintf + +#define AXIS2_SNPRINTF snprintf + +#define axis2_gmtime_r gmtime_r + + /** @} */ +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_UNIX_H */ diff --git a/util/include/platforms/unix/axutil_uuid_gen_unix.h b/util/include/platforms/unix/axutil_uuid_gen_unix.h new file mode 100644 index 0000000..d3b25ba --- /dev/null +++ b/util/include/platforms/unix/axutil_uuid_gen_unix.h @@ -0,0 +1,94 @@ + +/* + * 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 count 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 AXUTIL_UUID_GEN_UNIX_H +#define AXUTIL_UUID_GEN_UNIX_H + +#include <axutil_utils.h> +#include <axutil_utils_defines.h> + +#define UUIDS_PER_TICK 100 +#define UUID_TIMEOFFSET AXIS2_UNSIGNED_LONGLONGVALUE(0x01B21DD213814000) +#define AXIS2_LOCAL_MAC_ADDR "000000" + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_uuid_gen UUID Generator + * @ingroup axis2_util + * @{ + */ + + struct axutil_uuid + { + unsigned int time_low; + unsigned short int time_mid; + unsigned short int time_high_version; + short int clock_variant; + unsigned char mac_addr[6]; + }; + + /* bits 0-59 time field + * bits 60-63 version + * bits 64-65 2 bit variant + * bits 66-79 clock sequence + * bits 80-107 node MAC address + */ + struct axutil_uuid_st + { + unsigned char mac[6]; /* pre-determined MAC address */ + struct timeval time_last; /* last retrieved timestamp */ + unsigned long time_seq; /* last timestamp sequence counter */ + short int clock; /* clock tick - incremented random number */ + }; + + typedef struct axutil_uuid axutil_uuid_t; + + /** + * Returns the mac address of the first ethernet intsrface + * @return MAC address as a <code>char[6]</code> + */ + char *AXIS2_CALL + axutil_uuid_get_mac_addr(void + ); + + /** + * Generates a uuid in version1 format (node - timestamp based) + * @return generated uuid as a axutil_uuid_t + */ + axutil_uuid_t *AXIS2_CALL + axutil_uuid_gen_v1(void + ); + + /** + * Generates a uuid + * @return generated uuid as a string + */ + axis2_char_t *AXIS2_CALL + axutil_platform_uuid_gen( + char *s); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* AXIS2_UUID_GEN_UNIX_H */ diff --git a/util/include/platforms/windows/axutil_date_time_util_windows.h b/util/include/platforms/windows/axutil_date_time_util_windows.h new file mode 100644 index 0000000..2c5eef9 --- /dev/null +++ b/util/include/platforms/windows/axutil_date_time_util_windows.h @@ -0,0 +1,45 @@ + +/* + * 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 count 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 AXUTIL_DATE_TIME_UTIL_WINDOWS_H +#define AXUTIL_DATE_TIME_UTIL_WINDOWS_H + +#include <axutil_utils.h> +#include <axutil_utils_defines.h> +#include <stdio.h> +#include <sys/timeb.h> +#include <time.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup axutil_date_time_util + * @ingroup axutil_date_time_util + * @{ + */ + AXIS2_EXTERN int AXIS2_CALL + axis2_platform_get_milliseconds( + ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/util/include/platforms/windows/axutil_dir_windows.h b/util/include/platforms/windows/axutil_dir_windows.h new file mode 100644 index 0000000..89ba297 --- /dev/null +++ b/util/include/platforms/windows/axutil_dir_windows.h @@ -0,0 +1,123 @@ + +/* + * 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 READDIR_H +#define READDIR_H +#include <search.h> +#include <string.h> +#include <io.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <windows.h> +#include <axutil_utils_defines.h> + + +/* struct dirent - same as Unix dirent.h */ +struct dirent +{ + long d_ino; /* inode number (always 1 in WIN32) */ + off_t d_off; /* offset to this dirent */ + unsigned short d_reclen; /* length of d_name */ + char d_name[_MAX_FNAME + 1]; /* filename (null terminated) */ + + /*unsigned char d_type; *//*type of file */ +}; + + +/* def struct DIR - different from Unix DIR */ +typedef struct +{ + long handle; /* _findfirst/_findnext handle */ + short offset; /* offset into directory */ + short finished; /* 1 if there are not more files */ + struct _finddata_t fileinfo; /* from _findfirst/_findnext */ + char *dirname; /* the dir we are reading */ + struct dirent dent; /* the dirent to return */ + +} +AXIS2_DIR; + + +/* Function prototypes */ + + +/** + * open a directory on a given name + * returns a DIR if successful, or NULL if the path cannot be opened + */ +AXIS2_EXTERN AXIS2_DIR * AXIS2_CALL + axis2_opendir(const char *); + + +/** + * Close the directory stream DIRP. + * Return 0 if successful, -1 otherwise. + */ +AXIS2_EXTERN int AXIS2_CALL + axis2_closedir( + AXIS2_DIR *); + + +/** + * Read a directory entry from DIRP. Return a pointer to a `struct + * dirent' describing the entry, or NULL for EOF or error. + */ +AXIS2_EXTERN struct dirent *AXIS2_CALL + axis2_readdir( + AXIS2_DIR *); + + +/** + * Reentrant version of `readdir' + */ +AXIS2_EXTERN int AXIS2_CALL + axis2_readdir_r( + AXIS2_DIR *, + struct dirent *, + struct dirent **); + + +/** + * Rewind DIRP to the beginning of the directory. + */ +AXIS2_EXTERN int AXIS2_CALL + axis2_rewinddir( + AXIS2_DIR *); + + +/** + * Scan the directory DIR + * Returns the number of entries selected, or -1 on error + */ +AXIS2_EXTERN int AXIS2_CALL + axis2_scandir( + const char *_dirname, + struct dirent **__namelist[], + int(*selector)(const struct dirent * entry), + int(*compare)(const struct dirent ** a, + const struct dirent ** b)); + + +/** + * Compare two `struct dirent's alphabetically + */ +extern int alphasort( + const struct dirent **__d1, + const struct dirent **__d2); + +#endif /* READDIR_H */ diff --git a/util/include/platforms/windows/axutil_getopt_windows.h b/util/include/platforms/windows/axutil_getopt_windows.h new file mode 100644 index 0000000..8234fba --- /dev/null +++ b/util/include/platforms/windows/axutil_getopt_windows.h @@ -0,0 +1,79 @@ + +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The ASF licenses this file to You 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_GETOPT_WINDOWS_H_ +#define _AXIS2_GETOPT_WINDOWS_H_ + +#include <axutil_utils_defines.h> + +/** + * @file axis2_getopt_windows.h + * @brief windows cutdown version of getopt function in unix + */ + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** @defgroup axis2_getopt_windows getopt + * @ingroup axis2_windows + * @{ + */ +#ifndef AXIS2_GET_OPT_DEFINE_MODE_NO_IMPORT + AXIS2_IMPORT extern int opterr; + AXIS2_IMPORT extern int optopt; + AXIS2_IMPORT extern char *optarg; +#else + AXIS2_EXPORT int opterr; + AXIS2_EXPORT int optopt; + AXIS2_EXPORT char *optarg; +#endif + + /** + * return and log error + * @param __optopt option + * @param __err error code + * @param __showerr whether or not send to stderr + * @return ':' or '?' + */ + int _axis2_opt_error( + int __optopt, + int __err, + int __showerr); + + /** + * cutdown version of getopt in unix + * @param __argc no of arguments + * @param __argv list of arguments + * @param __shortopts options + * @return option char if successful, -1 if over, ':' or '?' if error + */ + AXIS2_EXTERN int AXIS2_CALL + axis2_getopt( + int __argc, + char *const *__argv, + const char *__shortopts); + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/util/include/platforms/windows/axutil_thread_mutex_windows.h b/util/include/platforms/windows/axutil_thread_mutex_windows.h new file mode 100644 index 0000000..4fed951 --- /dev/null +++ b/util/include/platforms/windows/axutil_thread_mutex_windows.h @@ -0,0 +1,44 @@ + +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The ASF licenses this file to You 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_THREAD_MUTEX_WINDOWS_H +#define AXIS2_THREAD_MUTEX_WINDOWS_H + +#include <process.h> +#include <windows.h> +#include <axutil_allocator.h> +typedef enum thread_mutex_type +{ + thread_mutex_critical_section, + thread_mutex_unnested_event, + thread_mutex_nested_mutex +} thread_mutex_type; + +/* handle applies only to unnested_event on all platforms + * and nested_mutex on Win9x only. Otherwise critical_section + * is used for NT nexted mutexes providing optimal performance. + */ +struct axutil_thread_mutex_t +{ + thread_mutex_type type; + HANDLE handle; + CRITICAL_SECTION section; + axutil_allocator_t *allocator; +}; + +#endif /* AXIS2_THREAD_MUTEX_WINDOWS_H */ diff --git a/util/include/platforms/windows/axutil_thread_windows.h b/util/include/platforms/windows/axutil_thread_windows.h new file mode 100644 index 0000000..739b4c2 --- /dev/null +++ b/util/include/platforms/windows/axutil_thread_windows.h @@ -0,0 +1,140 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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_THREAD_WINDOWS_H +#define AXIS2_THREAD_WINDOWS_H + +#include <windows.h> +#include <process.h> +#include <axutil_thread.h> + +#define SHELL_PATH "cmd.exe" + +typedef HANDLE axis2_os_thread_t; /* Native thread */ + +/* Chosen for us by apr_initialize */ + +struct axutil_thread_t +{ + HANDLE *td; + void *data; + axutil_thread_start_t func; + axis2_bool_t try_exit; +}; + +struct axutil_threadattr_t +{ + int detach; + size_t stacksize; +}; + +struct axutil_threadkey_t +{ + DWORD key; +}; + +struct axutil_thread_once_t +{ + long value; +}; + +AXIS2_EXTERN axutil_threadattr_t *AXIS2_CALL +axutil_threadattr_create( + axutil_allocator_t * allocator); + +/* Destroy the threadattr object */ +AXIS2_EXTERN axis2_status_t AXIS2_CALL +threadattr_cleanup( + void *data); + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_threadattr_detach_set( + axutil_threadattr_t * attr, + axis2_bool_t detached); + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_threadattr_detach_get( + axutil_threadattr_t * attr, + const axutil_env_t * env); + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_threadattr_stacksize_set( + axutil_threadattr_t * attr, + size_t stacksize); + +AXIS2_EXTERN axutil_thread_t *AXIS2_CALL +axutil_thread_create( + axutil_allocator_t * allocator, + axutil_threadattr_t * attr, + axutil_thread_start_t func, + void *data); + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_exit( + axutil_thread_t * thd, + axutil_allocator_t * allocator); + +AXIS2_EXTERN axis2_os_thread_t AXIS2_CALL +axis2_os_thread_current( + void); + +AXIS2_EXTERN int AXIS2_CALL +axis2_os_thread_equal( + axis2_os_thread_t tid1, + axis2_os_thread_t tid2); + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_join( + axutil_thread_t * thd); + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_detach( + axutil_thread_t * thd); + +AXIS2_EXTERN axis2_os_thread_t AXIS2_CALL +axis2_os_thread_get( + axutil_thread_t * thd, + const axutil_env_t * env); + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_key_create( + axutil_threadkey_t * axis2_key); + +AXIS2_EXTERN void *AXIS2_CALL +axutil_thread_getspecific( + axutil_threadkey_t * axis2_key); + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_setspecific( + axutil_threadkey_t * axis2_key, + void *value); + +AXIS2_EXTERN void AXIS2_CALL +axutil_thread_key_free( + axutil_threadkey_t * axis2_key); + +AXIS2_EXTERN axutil_thread_once_t *AXIS2_CALL +axutil_thread_once_init( + axutil_allocator_t * allocator); + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_once( + axutil_thread_once_t * control, + void(*func)(void)); + +#endif /* AXIS2_THREAD_WINDOWS_H */ diff --git a/util/include/platforms/windows/axutil_uuid_gen_windows.h b/util/include/platforms/windows/axutil_uuid_gen_windows.h new file mode 100644 index 0000000..f8c0872 --- /dev/null +++ b/util/include/platforms/windows/axutil_uuid_gen_windows.h @@ -0,0 +1,46 @@ + +/*
+ * 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_UDDI_GEN_WINDOWS_H
+#define AXIS2_UDDI_GEN_WINDOWS_H
+
+#include <axutil_utils_defines.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+
+#endif /*
*/
+
+ /* Function prototypes */
+
+
+ /**
+ * Generate universally unique id
+ * @return a char pointer to uuid
+ */
+ AXIS2_EXTERN axis2_char_t * AXIS2_CALL
+
axutil_platform_uuid_gen(
+
char *s);
+
+
+ /** @} */
+#ifdef __cplusplus
+}
+#endif /*
*/
+
+#endif /* AXIS2_UDDI_GEN_WINDOWS_H */
diff --git a/util/include/platforms/windows/axutil_windows.h b/util/include/platforms/windows/axutil_windows.h new file mode 100644 index 0000000..a473264 --- /dev/null +++ b/util/include/platforms/windows/axutil_windows.h @@ -0,0 +1,278 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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_WINDOWS_H +#define AXIS2_WINDOWS_H + +/** + * @file axutil_unix.h + * @brief axis2 unix platform specific interface + */ +#include <axutil_utils_defines.h> +#define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */ +#include <windows.h> + + /*for minizip uncompression library */ +# include <direct.h> + + /*for file access check */ +#include <io.h> +#include <sys/stat.h> + + /*for network handling */ +#include <winsock2.h> +#include <fcntl.h> +#include <Mswsock.h> +#include <Ws2tcpip.h> + + /* for time */ +#include <time.h> +#include <sys/timeb.h> + + /* get opt */ +#include "axutil_getopt_windows.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** @defgroup axis2_unix Platform Specific + * @ingroup axis2_platforms_unix + * @{ + */ + + /*enum platform_error_codes + { + PLATFORM_ERROR_UUID_NO_ADDRESS = 0, + PLATFORM_ERROR_OUT_OF_MEMORY = 1 + }; */ + + + + AXIS2_EXTERN HMODULE AXIS2_CALL + callLoadLib( + char *lib); + + AXIS2_EXTERN struct tm *AXIS2_CALL + axis2_win_gmtime( + const time_t * timep, + struct tm *result); + + + /* Get the last Error */ + AXIS2_EXTERN void AXIS2_CALL + axutil_win32_get_last_error(axis2_char_t *buff, + unsigned int buf_size); + + /* Get the last Socket Error */ + AXIS2_EXTERN void AXIS2_CALL + axutil_win32_get_last_wsa_error(axis2_char_t *buff, + unsigned int buf_size); + +#define AXUTIL_WIN32_ERROR_BUFSIZE 256 + + /*************************************************************** + * Default paths to shared library/DLLs and files + *************************************************************** + */ + +#define AXIS2_PLATFORM_DEFAULT_DEPLOY_PATH "" + +#define AXIS2_PLATFORM_XMLPARSER_PATH "axis2_parser.dll" +#define AXIS2_PLATFORM_TRANSPORTHTTP_PATH "http_transport.dll" +#define AXIS2_PLATFORM_CHANNEL_PATH "http_channel.dll" +#define AXIS2_PLATFORM_SSLCHANNEL_PATH "Unknown" + +#define AXIS2_PLATFORM_LOG_PATH "" /*/usr/local/axis2/log/axutil_log */ +#define AXIS2_PLATFORM_CLIENTLOG_PATH "" /* /usr/local/axis2/log/axis2_client_log */ +#define AXIS2_PLATFORM_CONFIG_PATH "" /* /etc/axiscpp.conf */ +#define AXIS2_PLATFORM_SECUREINFO "" + + /** + * Resource that contains the configuration + */ +#define AXIS2_CONFIGURATION_RESOURCE "" /* should be set */ + +/* + * ============================================================= + * Library loading and procedure resolution + * ============================================================= + */ +#define DLHandler HINSTANCE +#define RTLD_LAZY 0 /* not sure this is needed? */ + +#define AXIS2_PLATFORM_LOADLIBINIT() +#define AXIS2_PLATFORM_LOADLIB(_lib) /*LoadLibrary(_lib) */ callLoadLib(_lib) +#define AXIS2_PLATFORM_UNLOADLIB FreeLibrary +#define AXIS2_PLATFORM_GETPROCADDR GetProcAddress +#define AXIS2_PLATFORM_LOADLIBEXIT() +#define AXIS2_PLATFORM_LOADLIB_ERROR axutil_win32_get_last_error() + +#define AXIS2_DLHANDLER void* + + +/* + * ============================================================= + * National Language Support + * ============================================================= + */ + +/* + * STRTOASC is to translate single byte 'native' character representation to ASCII + * ASCTOSTR is to translate single byte ascii representation to 'native' character + * CANNOT be used with constants + */ +#define AXIS2_PLATFORM_STRTOASC( x ) ( x ) +#define AXIS2_PLATFORM_ASCTOSTR( x ) ( x ) + +/* + * ============================================================= + * Miscellaneous + * ============================================================= + */ + +#define AXIS2_STRRCHR(x, y) (strrchr(x, y)) + +#define AXIS2_PLATFORM_SLEEP(x) Sleep(0); + +#define AXIS2_SLEEP(x) Sleep((x)*1000) +#define AXIS2_USLEEP(x) Sleep((x)/1000); + + /** + * Get the last error code from the system. + * Please ensure that this is a thread safe implementation + * and that it returns a long + * @return long the last error message for this thread + */ +#define AXIS2_GETLASTERROR GetLastError(); + + /** + * From the last error number get a sensible std::string representing it + * @param errorNumber the error Number you are trying to get a message for + * @return the error message. NOTE: The caller is responsible for deleting the returned string + */ +#define AXIS2_PLATFORM_GET_ERROR_MESSAGE(errorNumber) getPlatformErrorMessage(errorNumber); + + /** + * Platform specific method to obtain current thread ID + */ +#define AXIS2_PLATFORM_GET_THREAD_ID() GetCurrentThreadId() + /** + * type to be used for 64bit integers + */ +#define AXIS2_LONGLONG __int64 + + /** + * Format string to be used in printf for 64bit integers + */ +#define AXIS2_PRINTF_LONGLONG_FORMAT_SPECIFIER "%I64d" +#define AXIS2_PRINTF_LONGLONG_FORMAT_SPECIFIER_CHARS "I64d" + + + /** + * Platform specific path separator char + */ +#define AXIS2_PATH_SEP_CHAR '/' +#define AXIS2_PATH_SEP_STR "/" +#define AXIS2_LIB_PREFIX "" +#define AXIS2_LIB_SUFFIX ".dll" + + /** + * Platform specific time + */ +#define AXIS2_TIME_T time_t + + /** + * Platform specific method to obtain current time in milli seconds + */ +#define AXIS2_PLATFORM_GET_TIME_IN_MILLIS _ftime +#define AXIS2_PLATFORM_TIMEB _timeb + + /** + * Platform specific file handling + */ +#define AXIS2_FOPEN fopen +#define AXIS2_FREAD fread +#define AXIS2_FWRITE fwrite +#define AXIS2_FCLOSE fclose +#define AXIS2_FTELL ftell +#define AXIS2_ACCESS(zpath,imode) _access(zpath,imode) +#define AXIS2_R_OK 04 /* test for read permission */ +#define AXIS2_W_OK 02 /* test for write permission */ +#define AXIS2_X_OK 00 /* test for execute or search permission */ +#define AXIS2_F_OK 00 /* test whether the directories leading to the file can be + searched and the file exists * / + + /** + * windows specific directory handling functions + */ +#define AXIS2_SCANDIR axis2_scandir +#define AXIS2_ALPHASORT alphasort +#define AXIS2_OPENDIR axis2_opendir +#define AXIS2_CLOSEDIR axis2_closedir +#define AXIS2_READDIR axis2_readdir +#define AXIS2_READDIR_R axis2_readdir_r +#define AXIS2_REWINDDIR axis2_rewinddir +#define AXIS2_MKDIR(path,x) _mkdir(path) +#define AXIS2_GETCWD _getcwd +#define AXIS2_CHDIR _chdir + + /** + * network specific functions and defs + */ +#define axis2_socket_t SOCKET + +#define AXIS2_INVALID_SOCKET INVALID_SOCKET +#define AXIS2_INADDR_NONE INADDR_NONE +#define axis2_unsigned_short_t u_short +#define AXIS2_CLOSE_SOCKET(sock) closesocket(sock) +#define AXIS2_CLOSE_SOCKET_ON_EXIT(sock) +#define axis2_socket_len_t int +#define AXIS2_SHUT_WR SD_SEND + + /** + * Platform specific environment variable access method + */ +#define AXIS2_GETENV(_env_var_name) getenv(_env_var_name) + + /** + * minizip functions + */ +#define axis2_fill_win32_filefunc(ffunc) fill_win32_filefunc(ffunc) +#define AXIS2_UNZOPEN2(zipfilename,ffunc) unzOpen2(zipfilename,NULL) + + /** + * handling variable number of arguments (for log.c) + */ + + /** getopt function */ +#define AXIS2_GETOPT axis2_getopt + + /** string functions */ +#define AXIS2_VSNPRINTF _vsnprintf + +#define AXIS2_SNPRINTF _snprintf + +#define axis2_gmtime_r axis2_win_gmtime + + /** @} */ +#ifdef __cplusplus +} +#endif +#endif /* AXIS2_WINDOWS_H */ diff --git a/util/src/Makefile.am b/util/src/Makefile.am new file mode 100644 index 0000000..5b1ab14 --- /dev/null +++ b/util/src/Makefile.am @@ -0,0 +1,51 @@ +SUBDIRS = platforms/unix @ZLIBBUILD@ +lib_LTLIBRARIES = libaxutil.la +libaxutil_la_SOURCES = hash.c \ + allocator.c \ + env.c \ + error.c \ + stream.c \ + log.c \ + string.c \ + string_util.c \ + qname.c \ + array_list.c \ + linked_list.c \ + utils.c \ + dir_handler.c \ + file_handler.c \ + class_loader.c\ + network_handler.c \ + file.c\ + uuid_gen.c\ + thread_pool.c \ + property.c \ + types.c \ + param.c \ + param_container.c \ + dll_desc.c\ + url.c\ + stack.c \ + generic_obj.c \ + base64.c \ + uri.c \ + date_time.c \ + base64_binary.c \ + properties.c \ + rand.c \ + date_time_util.c \ + version.c \ + duration.c \ + md5.c \ + http_chunked_stream.c \ + digest_calc.c + +libaxutil_la_LIBADD = $(top_builddir)/src/platforms/unix/libaxis2_unix.la \ + -lpthread \ + @ZLIBLIBS@ + +libaxutil_la_LDFLAGS = -version-info $(VERSION_NO) + +INCLUDES = -I$(top_builddir)/include + +EXTRA_DIST=platforms/windows string_util.c diff --git a/util/src/allocator.c b/util/src/allocator.c new file mode 100644 index 0000000..1b31048 --- /dev/null +++ b/util/src/allocator.c @@ -0,0 +1,151 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_allocator.h> +#include <axutil_utils.h> +#include <stdlib.h> +#include <string.h> + +void *AXIS2_CALL axutil_allocator_malloc_impl( + axutil_allocator_t * allocator, + size_t size); + +void *AXIS2_CALL axutil_allocator_realloc_impl( + axutil_allocator_t * allocator, + void *ptr, + size_t size); + +void AXIS2_CALL axutil_allocator_free_impl( + axutil_allocator_t * allocator, + void *ptr); + +AXIS2_EXTERN axutil_allocator_t *AXIS2_CALL +axutil_allocator_init( + axutil_allocator_t * allocator) +{ + if(allocator) + return allocator; + + else + { + allocator = (axutil_allocator_t *)malloc(sizeof(axutil_allocator_t)); + memset(allocator, 0, sizeof(axutil_allocator_t)); + if(allocator) + { + allocator->malloc_fn = axutil_allocator_malloc_impl; + allocator->realloc = axutil_allocator_realloc_impl; + allocator->free_fn = axutil_allocator_free_impl; + allocator->global_pool_ref = 0; + + return allocator; + } + } + return NULL; +} + +AXIS2_EXTERN axutil_allocator_t *AXIS2_CALL +axutil_allocator_clone( + axutil_allocator_t * allocator) +{ + if(!allocator) + return NULL; + + else + { + axutil_allocator_t* clone = NULL; + clone = (axutil_allocator_t *)malloc(sizeof(axutil_allocator_t)); + memset(clone, 0, sizeof(axutil_allocator_t)); + if(clone) + { + clone->malloc_fn = allocator->malloc_fn; + clone->realloc = allocator->realloc; + clone->free_fn = allocator->free_fn; + clone->current_pool = allocator->current_pool; + clone->global_pool = allocator->global_pool; + clone->local_pool = allocator->local_pool; + clone->global_pool_ref = 0; + + return clone; + } + } + return NULL; +} +AXIS2_EXTERN void AXIS2_CALL +axutil_allocator_free( + axutil_allocator_t * allocator) +{ + if(allocator) + { + allocator->free_fn(allocator, allocator); + } + return; +} + +void *AXIS2_CALL +axutil_allocator_malloc_impl( + axutil_allocator_t * allocator, + size_t size) +{ + return malloc(size); +} + +void *AXIS2_CALL +axutil_allocator_realloc_impl( + axutil_allocator_t * allocator, + void *ptr, + size_t size) +{ + return realloc(ptr, size); +} + +void AXIS2_CALL +axutil_allocator_free_impl( + axutil_allocator_t * allocator, + void *ptr) +{ + free(ptr); +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_allocator_switch_to_global_pool( + axutil_allocator_t * allocator) +{ + if(!allocator) + return; + allocator->global_pool_ref++; + allocator->current_pool = allocator->global_pool; + return; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_allocator_switch_to_local_pool( + axutil_allocator_t * allocator) +{ + if(!allocator) + return; + if(allocator->global_pool_ref > 0) + { + allocator->global_pool_ref--; + } + + if(allocator->global_pool_ref == 0) + { + allocator->current_pool = allocator->local_pool; + } + return; +} + diff --git a/util/src/array_list.c b/util/src/array_list.c new file mode 100644 index 0000000..a40ecf9 --- /dev/null +++ b/util/src/array_list.c @@ -0,0 +1,304 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_array_list.h> +#include <axutil_utils.h> +#include <string.h> + +struct axutil_array_list +{ + + /**The number of elements in this list. */ + int size; + + /**Current capacity of this list. */ + int capacity; + + /** Where the data is stored. */ + void **data; +}; + +AXIS2_EXTERN struct axutil_array_list *AXIS2_CALL +axutil_array_list_create( + const axutil_env_t * env, + int capacity) +{ + axutil_array_list_t *array_list = NULL; + + array_list = AXIS2_MALLOC(env->allocator, sizeof(axutil_array_list_t)); + if(!array_list) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + + array_list->size = 0; + array_list->capacity = 0; + array_list->data = NULL; + + /* Check capacity, and set the default if error */ + if(capacity <= 0) + capacity = AXIS2_ARRAY_LIST_DEFAULT_CAPACITY; + array_list->data = AXIS2_MALLOC(env->allocator, sizeof(void *) * capacity); + if(!array_list->data) + { + axutil_array_list_free(array_list, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + array_list->capacity = capacity; + + return array_list; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_array_list_ensure_capacity( + struct axutil_array_list * array_list, + const axutil_env_t * env, + int min_capacity) +{ + AXIS2_PARAM_CHECK(env->error, array_list, AXIS2_FAILURE); + if(min_capacity > array_list->capacity) + { + int new_capacity = (array_list->capacity * 2 > min_capacity) ? (array_list->capacity * 2) + : min_capacity; + void **data = (void **)AXIS2_MALLOC(env->allocator, sizeof(void *) * new_capacity); + if(!data) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return AXIS2_FAILURE; + } + memcpy(data, array_list->data, sizeof(void *) * array_list->capacity); + + AXIS2_FREE(env->allocator, array_list->data); + + array_list->data = data; + array_list->capacity = new_capacity; + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_array_list_size( + struct axutil_array_list *array_list, + const axutil_env_t * env) +{ + /* Don't use AXIS2_PARAM_CHECK to verify array_list, as it clobbers + env->error->status_code on no error destroying the information + therein that an error has already occurred. */ + if(!array_list) + return 0; + return array_list->size; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axutil_array_list_is_empty( + struct axutil_array_list * array_list, + const axutil_env_t * env) +{ + AXIS2_PARAM_CHECK(env->error, array_list, AXIS2_FAILURE); + return array_list->size == 0; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axutil_array_list_contains( + struct axutil_array_list * array_list, + const axutil_env_t * env, + void *e) +{ + AXIS2_PARAM_CHECK(env->error, array_list, AXIS2_FAILURE); + return axutil_array_list_index_of(array_list, env, e) != -1; +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_array_list_index_of( + struct axutil_array_list *array_list, + const axutil_env_t * env, + void *e) +{ + int i = 0; + + AXIS2_PARAM_CHECK(env->error, array_list, AXIS2_FAILURE); + for(i = 0; i < array_list->size; i++) + if(e == array_list->data[i]) + return i; + return -1; +} + +AXIS2_EXTERN void *AXIS2_CALL +axutil_array_list_get( + struct axutil_array_list *array_list, + const axutil_env_t * env, + int index) +{ + /* Don't use AXIS2_PARAM_CHECK to verify array_list, as it clobbers + env->error->status_code on no error destroying the information + therein that an error has already occurred. */ + if(axutil_array_list_check_bound_exclusive(array_list, env, index)) + return array_list->data[index]; + else + return NULL; +} + +AXIS2_EXTERN void *AXIS2_CALL +axutil_array_list_set( + struct axutil_array_list *array_list, + const axutil_env_t * env, + int index, + void *e) +{ + void *result = NULL; + + AXIS2_PARAM_CHECK(env->error, array_list, NULL); + if(axutil_array_list_check_bound_exclusive(array_list, env, index)) + { + result = array_list->data[index]; + array_list->data[index] = e; + } + return result; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_array_list_add( + struct axutil_array_list * array_list, + const axutil_env_t * env, + const void *e) +{ + AXIS2_PARAM_CHECK(env->error, array_list, AXIS2_FAILURE); + if(array_list->size == array_list->capacity) + if(axutil_array_list_ensure_capacity(array_list, env, array_list->size + 1) + != AXIS2_SUCCESS) + return AXIS2_FAILURE; + array_list->data[array_list->size++] = (void *)e; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_array_list_add_at( + struct axutil_array_list * array_list, + const axutil_env_t * env, + const int index, + const void *e) +{ + int i = 0; + AXIS2_PARAM_CHECK(env->error, array_list, AXIS2_FAILURE); + + if(!axutil_array_list_check_bound_inclusive(array_list, env, index)) + return AXIS2_FAILURE; + if(array_list->size == array_list->capacity) + { + if(axutil_array_list_ensure_capacity(array_list, env, array_list->size + 1) + != AXIS2_SUCCESS) + return AXIS2_FAILURE; + } + if(index != array_list->size) + { + for(i = array_list->size; i > index; i--) + array_list->data[i] = array_list->data[i - 1]; + } + array_list->data[index] = (void *)e; + array_list->size++; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN void *AXIS2_CALL +axutil_array_list_remove( + struct axutil_array_list *array_list, + const axutil_env_t * env, + int index) +{ + void *result = NULL; + int i = 0; + AXIS2_PARAM_CHECK(env->error, array_list, NULL); + + if(axutil_array_list_check_bound_exclusive(array_list, env, index)) + { + result = array_list->data[index]; + for(i = index; i < array_list->size - 1; i++) + array_list->data[i] = array_list->data[i + 1]; + array_list->size--; + } + + return result; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axutil_array_list_check_bound_inclusive( + struct axutil_array_list * array_list, + const axutil_env_t * env, + int index) +{ + /* Don't use AXIS2_PARAM_CHECK to verify array_list, as it clobbers + env->error->status_code on no error destroying the information + therein that an error has already occurred. */ + if(!array_list || index < 0 || index > array_list->size) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INDEX_OUT_OF_BOUNDS, AXIS2_FAILURE); + return AXIS2_FALSE; + } + return AXIS2_TRUE; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axutil_array_list_check_bound_exclusive( + struct axutil_array_list * array_list, + const axutil_env_t * env, + int index) +{ + /* Don't use AXIS2_PARAM_CHECK to verify array_list, as it clobbers + env->error->status_code on no error destroying the information + therein that an error has already occurred. */ + if(!array_list || index < 0 || index >= array_list->size) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INDEX_OUT_OF_BOUNDS, AXIS2_FAILURE); + return AXIS2_FALSE; + } + return AXIS2_TRUE; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_array_list_free( + struct axutil_array_list *array_list, + const axutil_env_t * env) +{ + AXIS2_PARAM_CHECK_VOID(env->error, array_list); + + if(array_list->data) + { + AXIS2_FREE(env->allocator, array_list->data); + } + AXIS2_FREE(env->allocator, array_list); + return; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_array_list_free_void_arg( + void *array_list, + const axutil_env_t * env) +{ + axutil_array_list_t *array_list_l = NULL; + + AXIS2_PARAM_CHECK_VOID(env->error, array_list); + + array_list_l = (axutil_array_list_t *)array_list; + axutil_array_list_free(array_list_l, env); + return; +} + diff --git a/util/src/base64.c b/util/src/base64.c new file mode 100644 index 0000000..0789169 --- /dev/null +++ b/util/src/base64.c @@ -0,0 +1,284 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +/* base64 encoder/decoder. Originally part of main/util.c + * but moved here so that support/ab and axis2_sha1.c could + * use it. This meant removing the axis2_palloc()s and adding + * ugly 'len' functions, which is quite a nasty cost. + */ + +#include <axutil_base64.h> + +static const unsigned char pr2six[256] = { +#ifndef __OS400__ + /* ASCII table */ + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64, + 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64, + 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 +#else /* __OS400__ */ + /* EBCDIC table */ + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 63, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 64, 64, 64, 64, 64, 64, + 64, 35, 36, 37, 38, 39, 40, 41, 42, 43, 64, 64, 64, 64, 64, 64, + 64, 64, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 64, 64, 64, 64, 64, 64, + 64, 9, 10, 11, 12, 13, 14, 15, 16, 17, 64, 64, 64, 64, 64, 64, + 64, 64, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64, 64, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64 +#endif /* AXIS2_CHARSET_EBCDIC */ +}; + +#ifdef __OS400__ + +static unsigned char os_toascii[256] = { + /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ + 0, 1, 2, 3, 156, 9, 134, 127, 151, 141, 142, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 157, 133, 8, 135, 24, 25, 146, 143, 28, 29, 30, 31, + 128, 129, 130, 131, 132, 10, 23, 27, 136, 137, 138, 139, 140, 5, 6, 7, + 144, 145, 22, 147, 148, 149, 150, 4, 152, 153, 154, 155, 20, 21, 158, 26, + 32, 160, 226, 228, 224, 225, 227, 229, 231, 241, 162, 46, 60, 40, 43, 124, + 38, 233, 234, 235, 232, 237, 238, 239, 236, 223, 33, 36, 42, 41, 59, 172, + 45, 47, 194, 196, 192, 193, 195, 197, 199, 209, 166, 44, 37, 95, 62, 63, + 248, 201, 202, 203, 200, 205, 206, 207, 204, 96, 58, 35, 64, 39, 61, 34, + 216, 97, 98, 99, 100, 101, 102, 103, 104, 105, 171, 187, 240, 253, 254, 177, + 176, 106, 107, 108, 109, 110, 111, 112, 113, 114, 170, 186, 230, 184, 198, + 164, + 181, 126, 115, 116, 117, 118, 119, 120, 121, 122, 161, 191, 208, 221, 222, + 174, + 94, 163, 165, 183, 169, 167, 182, 188, 189, 190, 91, 93, 175, 168, 180, 215, + 123, 65, 66, 67, 68, 69, 70, 71, 72, 73, 173, 244, 246, 242, 243, 245, + 125, 74, 75, 76, 77, 78, 79, 80, 81, 82, 185, 251, 252, 249, 250, 255, + 92, 247, 83, 84, 85, 86, 87, 88, 89, 90, 178, 212, 214, 210, 211, 213, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 179, 219, 220, 217, 218, 159 +}; + +#endif /* __OS400__ */ + +AXIS2_EXTERN int AXIS2_CALL +axutil_base64_decode_len( + const char *bufcoded) +{ + int nbytesdecoded; + register const unsigned char *bufin; + register int nprbytes; + + if(!bufcoded) + { + return -1; + } + + bufin = (const unsigned char *)bufcoded; + while(pr2six[*(bufin++)] <= 63) + ; + + nprbytes = (int)(bufin - (const unsigned char *)bufcoded) - 1; + /* We are sure that the difference lies within the int range */ + + nbytesdecoded = ((nprbytes >> 2) * 3); + + if(nprbytes & 0x03) + nbytesdecoded += (nprbytes & 0x03) - 1; + + return nbytesdecoded; + +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_base64_decode( + char *bufplain, + const char *bufcoded) +{ + int len; + len = axutil_base64_decode_binary((unsigned char *)bufplain, bufcoded); + bufplain[len] = '\0'; + return len; +} + +/* This is the same as axutil_base64_decode() except on EBCDIC machines, where + * the conversion of the output to ebcdic is left out. + */ + +AXIS2_EXTERN int AXIS2_CALL +axutil_base64_decode_binary( + unsigned char *bufplain, + const char *bufcoded) +{ + int nbytesdecoded; + register const unsigned char *bufin; + register unsigned char *bufout; + register int nprbytes; + + if(!bufcoded) + { + return -1; + } + + bufin = (const unsigned char *)bufcoded; + while(pr2six[*(bufin++)] <= 63) + ; + nprbytes = (int)(bufin - (const unsigned char *)bufcoded) - 1; + /* We are sure that the difference lies within the int range */ + nbytesdecoded = ((nprbytes + 3) / 4) * 3; + + bufout = (unsigned char *)bufplain; + bufin = (const unsigned char *)bufcoded; + + while(nprbytes > 4) + { + *(bufout++) = (unsigned char)(pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4); + *(bufout++) = (unsigned char)(pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2); + *(bufout++) = (unsigned char)(pr2six[bufin[2]] << 6 | pr2six[bufin[3]]); + bufin += 4; + nprbytes -= 4; + } + + /* Note: (nprbytes == 1) would be an error, so just ingore that case */ + if(nprbytes > 1) + { + *(bufout++) = (unsigned char)(pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4); + } + if(nprbytes > 2) + { + *(bufout++) = (unsigned char)(pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2); + } + if(nprbytes > 3) + { + *(bufout++) = (unsigned char)(pr2six[bufin[2]] << 6 | pr2six[bufin[3]]); + } + + nbytesdecoded -= (4 - nprbytes) & 3; + return nbytesdecoded; +} + +static const char basis_64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + +AXIS2_EXTERN int AXIS2_CALL +axutil_base64_encode_len( + int len) +{ + return ((len + 2) / 3 * 4) + 1; +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_base64_encode( + char *encoded, + const char *string, + int len) +{ +#ifndef __OS400__ + return axutil_base64_encode_binary(encoded, (const unsigned char *)string, len); +#else /* __OS400__ */ + int i; + char *p; + + p = encoded; + for (i = 0; i < len - 2; i += 3) + { + *p++ = basis_64[(os_toascii[string[i]] >> 2) & 0x3F]; + *p++ = + basis_64[((os_toascii[string[i]] & 0x3) << 4) | + ((int) (os_toascii[string[i + 1]] & 0xF0) >> 4)]; + *p++ = + basis_64[((os_toascii[string[i + 1]] & 0xF) << 2) | + ((int) (os_toascii[string[i + 2]] & 0xC0) >> 6)]; + *p++ = basis_64[os_toascii[string[i + 2]] & 0x3F]; + } + if (i < len) + { + *p++ = basis_64[(os_toascii[string[i]] >> 2) & 0x3F]; + if (i == (len - 1)) + { + *p++ = basis_64[((os_toascii[string[i]] & 0x3) << 4)]; + *p++ = '='; + } + else + { + *p++ = + basis_64[((os_toascii[string[i]] & 0x3) << 4) | + ((int) (os_toascii[string[i + 1]] & 0xF0) >> 4)]; + *p++ = basis_64[((os_toascii[string[i + 1]] & 0xF) << 2)]; + } + *p++ = '='; + } + + *p++ = '\0'; + return p - encoded; +#endif /* __OS400__ */ +} + +/* This is the same as axutil_base64_encode() except on EBCDIC machines, where + * the conversion of the input to ascii is left out. + */ +AXIS2_EXTERN int AXIS2_CALL +axutil_base64_encode_binary( + char *encoded, + const unsigned char *string, + int len) +{ + int i; + char *p; + + p = encoded; + for(i = 0; i < len - 2; i += 3) + { + *p++ = basis_64[(string[i] >> 2) & 0x3F]; + *p++ = basis_64[((string[i] & 0x3) << 4) | ((int)(string[i + 1] & 0xF0) >> 4)]; + *p++ = basis_64[((string[i + 1] & 0xF) << 2) | ((int)(string[i + 2] & 0xC0) >> 6)]; + *p++ = basis_64[string[i + 2] & 0x3F]; + } + if(i < len) + { + *p++ = basis_64[(string[i] >> 2) & 0x3F]; + if(i == (len - 1)) + { + *p++ = basis_64[((string[i] & 0x3) << 4)]; + *p++ = '='; + } + else + { + *p++ = basis_64[((string[i] & 0x3) << 4) | ((int)(string[i + 1] & 0xF0) >> 4)]; + *p++ = basis_64[((string[i + 1] & 0xF) << 2)]; + } + *p++ = '='; + } + + *p++ = '\0'; + return (int)(p - encoded); + /* We are sure that the difference lies within the int range */ +} diff --git a/util/src/base64_binary.c b/util/src/base64_binary.c new file mode 100644 index 0000000..2d3ff87 --- /dev/null +++ b/util/src/base64_binary.c @@ -0,0 +1,258 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_base64_binary.h> +#include <string.h> +#include <axutil_utils.h> + +struct axutil_base64_binary +{ + unsigned char *plain_binary; + int plain_binary_len; +}; + +AXIS2_EXTERN axutil_base64_binary_t *AXIS2_CALL +axutil_base64_binary_create( + const axutil_env_t * env) +{ + axutil_base64_binary_t *base64_binary = NULL; + AXIS2_ENV_CHECK(env, NULL); + + base64_binary = (axutil_base64_binary_t *)AXIS2_MALLOC(env->allocator, + sizeof(axutil_base64_binary_t)); + + if(!base64_binary) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + base64_binary->plain_binary = NULL; + base64_binary->plain_binary_len = 0; + return base64_binary; +} + +AXIS2_EXTERN axutil_base64_binary_t *AXIS2_CALL +axutil_base64_binary_create_with_plain_binary( + const axutil_env_t * env, + const unsigned char *plain_binary, + int plain_binary_len) +{ + axutil_base64_binary_t *base64_binary = NULL; + + AXIS2_ENV_CHECK(env, NULL); + AXIS2_PARAM_CHECK(env->error, plain_binary, NULL); + + base64_binary = (axutil_base64_binary_t *)axutil_base64_binary_create(env); + if(!base64_binary) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + + base64_binary->plain_binary = AXIS2_MALLOC(env->allocator, sizeof(unsigned char) + * plain_binary_len); + + if(!base64_binary->plain_binary) + { + axutil_base64_binary_free(base64_binary, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + memcpy(base64_binary->plain_binary, plain_binary, plain_binary_len); + base64_binary->plain_binary_len = plain_binary_len; + + return base64_binary; +} + +AXIS2_EXTERN axutil_base64_binary_t *AXIS2_CALL +axutil_base64_binary_create_with_encoded_binary( + const axutil_env_t * env, + const char *encoded_binary) +{ + axutil_base64_binary_t *base64_binary = NULL; + int plain_binary_len = 0; + + AXIS2_ENV_CHECK(env, NULL); + AXIS2_PARAM_CHECK(env->error, encoded_binary, NULL); + + base64_binary = (axutil_base64_binary_t *)axutil_base64_binary_create(env); + if(!base64_binary) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + + plain_binary_len = axutil_base64_decode_len(encoded_binary); + base64_binary->plain_binary = AXIS2_MALLOC(env->allocator, sizeof(unsigned char) + * plain_binary_len); + + if(!base64_binary->plain_binary) + { + axutil_base64_binary_free(base64_binary, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + axutil_base64_decode_binary(base64_binary->plain_binary, encoded_binary); + base64_binary->plain_binary_len = plain_binary_len; + + return base64_binary; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_base64_binary_free( + axutil_base64_binary_t *base64_binary, + const axutil_env_t *env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(!base64_binary) + { + return; + } + + if(base64_binary->plain_binary) + { + AXIS2_FREE(env->allocator, base64_binary->plain_binary); + } + + if(base64_binary) + { + AXIS2_FREE(env->allocator, base64_binary); + } + + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_base64_binary_set_plain_binary( + axutil_base64_binary_t *base64_binary, + const axutil_env_t *env, + const unsigned char *plain_binary, + int plain_binary_len) +{ + + AXIS2_PARAM_CHECK(env->error, plain_binary, AXIS2_FAILURE); + + base64_binary->plain_binary = AXIS2_MALLOC(env->allocator, sizeof(unsigned char) + * plain_binary_len); + if(!base64_binary->plain_binary) + { + axutil_base64_binary_free(base64_binary, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return AXIS2_FAILURE; + } + memcpy(base64_binary->plain_binary, plain_binary, plain_binary_len); + base64_binary->plain_binary_len = plain_binary_len; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN unsigned char *AXIS2_CALL +axutil_base64_binary_get_plain_binary( + axutil_base64_binary_t *base64_binary, + const axutil_env_t *env, + int *plain_binary_len) +{ + AXIS2_PARAM_CHECK(env->error, base64_binary, NULL); + *plain_binary_len = base64_binary->plain_binary_len; + return base64_binary->plain_binary; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_base64_binary_set_encoded_binary( + axutil_base64_binary_t *base64_binary, + const axutil_env_t *env, + const char *encoded_binary) +{ + int plain_binary_len = 0; + + AXIS2_PARAM_CHECK(env->error, base64_binary, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, encoded_binary, AXIS2_FAILURE); + + plain_binary_len = axutil_base64_decode_len(encoded_binary); + base64_binary->plain_binary = AXIS2_MALLOC(env->allocator, sizeof(unsigned char) + * plain_binary_len); + + if(!base64_binary->plain_binary) + { + axutil_base64_binary_free(base64_binary, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return AXIS2_FAILURE; + } + axutil_base64_decode_binary(base64_binary->plain_binary, encoded_binary); + base64_binary->plain_binary_len = plain_binary_len; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN char *AXIS2_CALL +axutil_base64_binary_get_encoded_binary( + axutil_base64_binary_t *base64_binary, + const axutil_env_t *env) +{ + char *encoded_binary = NULL; + int encoded_binary_len = 0; + AXIS2_PARAM_CHECK(env->error, base64_binary, NULL); + + encoded_binary_len = axutil_base64_encode_len(base64_binary->plain_binary_len); + encoded_binary = AXIS2_MALLOC(env->allocator, sizeof(char) * encoded_binary_len); + + if(!encoded_binary) + { + axutil_base64_binary_free(base64_binary, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + axutil_base64_encode_binary(encoded_binary, base64_binary->plain_binary, + base64_binary->plain_binary_len); + return encoded_binary; +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_base64_binary_get_encoded_binary_len( + axutil_base64_binary_t *base64_binary, + const axutil_env_t *env) +{ + int encoded_binary_len = 0; + if(!base64_binary) + { + return 0; + } + + encoded_binary_len = axutil_base64_encode_len(base64_binary->plain_binary_len); + return encoded_binary_len; +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_base64_binary_get_decoded_binary_len( + axutil_base64_binary_t *base64_binary, + const axutil_env_t *env) +{ + if(!base64_binary) + { + return 0; + } + return base64_binary->plain_binary_len; +} diff --git a/util/src/class_loader.c b/util/src/class_loader.c new file mode 100644 index 0000000..ea3be7d --- /dev/null +++ b/util/src/class_loader.c @@ -0,0 +1,189 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_class_loader.h> + +axis2_status_t +axutil_class_loader_load_lib( + const axutil_env_t *env, + axutil_dll_desc_t *dll_desc); + +axis2_status_t +axutil_class_loader_unload_lib( + const axutil_env_t *env, + axutil_dll_desc_t *dll_desc); + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_class_loader_init( + const axutil_env_t *env) +{ + AXIS2_PLATFORM_LOADLIBINIT(); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_class_loader_delete_dll( + const axutil_env_t *env, + axutil_dll_desc_t *dll_desc) +{ + if(!dll_desc) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_DLL_CREATE_FAILED, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + axutil_class_loader_unload_lib(env, dll_desc); + AXIS2_PLATFORM_LOADLIBEXIT(); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN void *AXIS2_CALL +axutil_class_loader_create_dll( + const axutil_env_t *env, + axutil_param_t *impl_info_param) +{ + void *obj = NULL; + CREATE_FUNCT create_funct = NULL; + DELETE_FUNCT delete_funct = NULL; + AXIS2_DLHANDLER dl_handler = NULL; + axutil_dll_desc_t *dll_desc = NULL; + axis2_status_t status = AXIS2_FAILURE; + axutil_error_codes_t error_code = AXIS2_ERROR_NONE; + + dll_desc = axutil_param_get_value(impl_info_param, env); + if(!dll_desc) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_DLL_CREATE_FAILED, AXIS2_FAILURE); + return NULL; + } + dl_handler = axutil_dll_desc_get_dl_handler(dll_desc, env); + if(!dl_handler) + { + status = axutil_class_loader_load_lib(env, dll_desc); + if(AXIS2_SUCCESS != status) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_DLL_CREATE_FAILED, AXIS2_FAILURE); + return NULL; + } + dl_handler = axutil_dll_desc_get_dl_handler(dll_desc, env); + if(!dl_handler) + { + return NULL; + } + + create_funct = (CREATE_FUNCT)AXIS2_PLATFORM_GETPROCADDR(dl_handler, AXIS2_CREATE_FUNCTION); + if(!create_funct) + { + return NULL; + } + status = axutil_dll_desc_set_create_funct(dll_desc, env, create_funct); + if(AXIS2_FAILURE == status) + { + axutil_class_loader_unload_lib(env, dll_desc); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_DLL_CREATE_FAILED, AXIS2_FAILURE); + return NULL; + } + + delete_funct = (DELETE_FUNCT)AXIS2_PLATFORM_GETPROCADDR(dl_handler, AXIS2_DELETE_FUNCTION); + if(!delete_funct) + { + return NULL; + } + status = axutil_dll_desc_set_delete_funct(dll_desc, env, delete_funct); + if(AXIS2_FAILURE == status) + { + axutil_class_loader_unload_lib(env, dll_desc); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_DLL_CREATE_FAILED, AXIS2_FAILURE); + return NULL; + } + } + create_funct = axutil_dll_desc_get_create_funct(dll_desc, env); + if(!create_funct) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_STATE_DLL_DESC, AXIS2_FAILURE); + return NULL; + } + error_code = axutil_dll_desc_get_error_code(dll_desc, env); + + create_funct(&obj, env); + if(!obj) + { + axutil_class_loader_unload_lib(env, dll_desc); + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "Object create function returned NULL"); + AXIS2_ERROR_SET(env->error, error_code, AXIS2_FAILURE); + return NULL; + } + else + { + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "%s shared lib loaded successfully", + axutil_dll_desc_get_name(dll_desc, env)); + } + + return obj; +} + +axis2_status_t +axutil_class_loader_load_lib( + const axutil_env_t * env, + axutil_dll_desc_t * dll_desc) +{ + axis2_char_t *dll_name = NULL; + AXIS2_DLHANDLER dl_handler = NULL; + axis2_status_t status = AXIS2_FAILURE; + + dll_name = axutil_dll_desc_get_name(dll_desc, env); + dl_handler = AXIS2_PLATFORM_LOADLIB(dll_name); + if(!dl_handler) + { +#ifndef WIN32 + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Loading shared library %s Failed. DLERROR IS %s", + dll_name, AXIS2_PLATFORM_LOADLIB_ERROR); +#else + axis2_char_t buff[AXUTIL_WIN32_ERROR_BUFSIZE]; + axutil_win32_get_last_error(buff, AXUTIL_WIN32_ERROR_BUFSIZE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Loading shared library %s Failed. DLERROR IS %s", + dll_name, buff); +#endif + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_DLL_LOADING_FAILED, AXIS2_FAILURE); + + return AXIS2_FAILURE; + } + status = axutil_dll_desc_set_dl_handler(dll_desc, env, dl_handler); + + if(AXIS2_SUCCESS != status) + { + AXIS2_PLATFORM_UNLOADLIB(dl_handler); + dl_handler = NULL; + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_DLL_LOADING_FAILED, AXIS2_FAILURE); + return status; + } + + return AXIS2_SUCCESS; +} + +axis2_status_t +axutil_class_loader_unload_lib( + const axutil_env_t * env, + axutil_dll_desc_t * dll_desc) +{ + AXIS2_DLHANDLER dl_handler = axutil_dll_desc_get_dl_handler(dll_desc, env); + if(dl_handler) + { + AXIS2_PLATFORM_UNLOADLIB(dl_handler); + } + + return AXIS2_SUCCESS; +} diff --git a/util/src/date_time.c b/util/src/date_time.c new file mode 100644 index 0000000..ad15774 --- /dev/null +++ b/util/src/date_time.c @@ -0,0 +1,1034 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_date_time.h> +#include <stdio.h> +#include <time.h> +#include <stdlib.h> +#include <axutil_error.h> +#include <axutil_utils.h> +#include <axutil_date_time_util.h> + +struct axutil_date_time +{ + int year; + int mon; + int day; + int hour; + int min; + float sec; + axis2_bool_t tz_pos; + int tz_hour; + int tz_min; +}; + +AXIS2_EXTERN axutil_date_time_t *AXIS2_CALL +axutil_date_time_create_with_offset( + const axutil_env_t *env, + int offset) +{ + axutil_date_time_t *date_time = NULL; + time_t t; + struct tm *utc_time = NULL; + AXIS2_ENV_CHECK(env, NULL); + + date_time = (axutil_date_time_t *)AXIS2_MALLOC(env->allocator, sizeof(axutil_date_time_t)); + + if(!date_time) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + + t = time(NULL) + offset; + + utc_time = gmtime(&t); + + date_time->year = utc_time->tm_year; + date_time->mon = utc_time->tm_mon; + date_time->day = utc_time->tm_mday; + date_time->hour = utc_time->tm_hour; + date_time->min = utc_time->tm_min; + date_time->sec = (float)utc_time->tm_sec; + date_time->sec += (float)axutil_get_milliseconds(env) / 1000; + date_time->tz_hour = 0; + date_time->tz_min = 0; + date_time->tz_pos = AXIS2_TRUE; + + return date_time; +} + +AXIS2_EXTERN axutil_date_time_t *AXIS2_CALL +axutil_date_time_create( + const axutil_env_t *env) +{ + return axutil_date_time_create_with_offset(env, 0); +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_date_time_free( + axutil_date_time_t *date_time, + const axutil_env_t *env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(date_time) + { + AXIS2_FREE(env->allocator, date_time); + } + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_date_time_deserialize_time( + axutil_date_time_t *date_time, + const axutil_env_t *env, + const axis2_char_t *time_str) +{ + int hour; + int min; + float sec; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + sscanf(time_str, "%d:%d:%fZ", &hour, &min, &sec); + if(hour < 0 || hour > 23) + { + return AXIS2_FAILURE; + } + if(min < 0 || min > 59) + { + return AXIS2_FAILURE; + } + if(sec < 0 || sec >= 60) + { + return AXIS2_FAILURE; + } + date_time->hour = hour; + date_time->min = min; + date_time->sec = sec; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_date_time_deserialize_time_with_time_zone( + axutil_date_time_t *date_time, + const axutil_env_t *env, + const axis2_char_t *time_str) +{ + int hour; + int min; + float sec; + int tz_hour; + int tz_min; + + axis2_bool_t tz_pos = AXIS2_TRUE; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(strchr(time_str, 'Z')) + { + return AXIS2_FAILURE; + } + else if(!strchr(time_str, '+')) + { + tz_pos = AXIS2_FALSE; + } + + if(tz_pos) + { + sscanf(time_str, "%d:%d:%f+%d:%d", &hour, &min, &sec, &tz_hour, &tz_min); + } + else + { + sscanf(time_str, "%d:%d:%f-%d:%d", &hour, &min, &sec, &tz_hour, &tz_min); + } + if(hour < 0 || hour > 23) + { + return AXIS2_FAILURE; + } + if(min < 0 || min > 59) + { + return AXIS2_FAILURE; + } + if(sec < 0 || sec >= 60) + { + return AXIS2_FAILURE; + } + if(tz_hour < 0 || tz_hour > 14) + { + return AXIS2_FAILURE; + } + if(tz_min < 0 || tz_min > 59) + { + return AXIS2_FAILURE; + } + if(tz_hour == 14 && tz_min != 0) + { + return AXIS2_FAILURE; + } + date_time->hour = hour; + date_time->min = min; + date_time->sec = sec; + date_time->tz_pos = tz_pos; + date_time->tz_hour = tz_hour; + date_time->tz_min = tz_min; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_date_time_deserialize_date( + axutil_date_time_t *date_time, + const axutil_env_t *env, + const axis2_char_t *date_str) +{ + int year; + int mon; + int day; + int is_year_neg = 0; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(!date_str || *date_str == '+') + { + return AXIS2_FAILURE; + } + if(strchr(date_str,'T')) + { + return AXIS2_FAILURE; + } + if(*date_str == '-') + { + is_year_neg++; + } + sscanf(date_str + is_year_neg, "%d-%d-%d", &year, &mon, &day); + if(is_year_neg) + { + year *= -1; + } + if(mon < 1 || mon > 12) + { + return AXIS2_FAILURE; + } + if(day < 1 || day > 31) + { + return AXIS2_FAILURE; + } + if(day == 31 && (mon == 2 || mon == 4 || mon == 6 || mon == 9 || mon == 11)) + { + return AXIS2_FAILURE; + } + if(day == 30 && mon == 2) + { + return AXIS2_FAILURE; + } + if(day == 29 && mon == 2) + { + if(year % 4 != 0 || year % 400 == 0) + { + return AXIS2_FAILURE; + } + } + date_time->year = year - 1900; + date_time->mon = mon - 1; + date_time->day = day; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_date_time_deserialize_date_time( + axutil_date_time_t *date_time, + const axutil_env_t *env, + const axis2_char_t *date_time_str) +{ + int year; + int mon; + int day; + int hour; + int min; + float sec; + int is_year_neg = 0; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(!date_time_str || *date_time_str == '+') + { + return AXIS2_FAILURE; + } + if(*date_time_str == '-') + { + is_year_neg++; + } + sscanf(date_time_str + is_year_neg, "%d-%d-%dT%d:%d:%fZ", &year, &mon, &day, &hour, &min, &sec); + + if(is_year_neg) + { + year *= -1; + } + if(mon < 1 || mon > 12) + { + return AXIS2_FAILURE; + } + if(day < 1 || day > 31) + { + return AXIS2_FAILURE; + } + if(day == 31 && (mon == 2 || mon == 4 || mon == 6 || mon == 9 || mon == 11)) + { + return AXIS2_FAILURE; + } + if(day == 30 && mon == 2) + { + return AXIS2_FAILURE; + } + if(day == 29 && mon == 2) + { + if(year % 4 != 0 || year % 400 == 0) + { + return AXIS2_FAILURE; + } + } + if(hour < 0 || hour > 23) + { + return AXIS2_FAILURE; + } + if(min < 0 || min > 59) + { + return AXIS2_FAILURE; + } + if(sec < 0 || sec >= 60) + { + return AXIS2_FAILURE; + } + date_time->year = year - 1900; + date_time->mon = mon - 1; + date_time->day = day; + date_time->hour = hour; + date_time->min = min; + date_time->sec = sec; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_date_time_deserialize_date_time_with_time_zone( + axutil_date_time_t *date_time, + const axutil_env_t *env, + const axis2_char_t *date_time_str) +{ + int year; + int mon; + int day; + int hour; + int min; + float sec; + int tz_hour; + int tz_min; + int is_year_neg = 0; + axis2_bool_t tz_pos = AXIS2_FALSE; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(!date_time_str || *date_time_str == '+') + { + return AXIS2_FAILURE; + } + if(*date_time_str == '-') + { + is_year_neg++; + } + + if(strchr(date_time_str, 'Z')) + { + return AXIS2_FAILURE; + } + else if(strchr(date_time_str, '+')) + { + tz_pos = AXIS2_TRUE; + } + + if(tz_pos) + { + sscanf(date_time_str + is_year_neg, "%d-%d-%dT%d:%d:%f+%d:%d", &year, &mon, &day, &hour, + &min, &sec, &tz_hour, &tz_min); + } + else + { + sscanf(date_time_str + is_year_neg, "%d-%d-%dT%d:%d:%f-%d:%d", &year, &mon, &day, &hour, + &min, &sec, &tz_hour, &tz_min); + } + + if(is_year_neg) + { + year *= -1; + } + if(mon < 1 || mon > 12) + { + return AXIS2_FAILURE; + } + if(day < 1 || day > 31) + { + return AXIS2_FAILURE; + } + if(day == 31 && (mon == 2 || mon == 4 || mon == 6 || mon == 9 || mon == 11)) + { + return AXIS2_FAILURE; + } + if(day == 30 && mon == 2) + { + return AXIS2_FAILURE; + } + if(day == 29 && mon == 2) + { + if(year % 4 != 0 || year % 400 == 0) + { + return AXIS2_FAILURE; + } + } + if(hour < 0 || hour > 23) + { + return AXIS2_FAILURE; + } + if(min < 0 || min > 59) + { + return AXIS2_FAILURE; + } + if(sec < 0 || sec >= 60) + { + return AXIS2_FAILURE; + } + if(tz_hour < 0 || tz_hour > 14) + { + return AXIS2_FAILURE; + } + if(tz_min < 0 || tz_min > 59) + { + return AXIS2_FAILURE; + } + if(tz_hour == 14 && tz_min != 0) + { + return AXIS2_FAILURE; + } + date_time->year = year - 1900; + date_time->mon = mon - 1; + date_time->day = day; + date_time->hour = hour; + date_time->min = min; + date_time->sec = sec; + date_time->tz_pos = tz_pos; + date_time->tz_hour = tz_hour; + date_time->tz_min = tz_min; + return AXIS2_SUCCESS; +} + +/*Check if the @data_time is not expired, compared to @ref*/ +AXIS2_EXTERN axutil_date_time_comp_result_t AXIS2_CALL +axutil_date_time_compare( + axutil_date_time_t *date_time, + const axutil_env_t *env, + axutil_date_time_t *ref) +{ + int dt_min; + int ref_min; + int dt_hour; + int ref_hour; + AXIS2_ENV_CHECK(env, AXIS2_DATE_TIME_COMP_RES_FAILURE); + + if(date_time->year < ref->year) + { + return AXIS2_DATE_TIME_COMP_RES_NOT_EXPIRED; + } + else if(date_time->year > ref->year) + { + return AXIS2_DATE_TIME_COMP_RES_EXPIRED; + } + + if(date_time->mon < ref->mon) + { + return AXIS2_DATE_TIME_COMP_RES_NOT_EXPIRED; + } + else if(date_time->mon > ref->mon) + { + return AXIS2_DATE_TIME_COMP_RES_EXPIRED; + } + + if(date_time->day < ref->day) + { + return AXIS2_DATE_TIME_COMP_RES_NOT_EXPIRED; + } + else if(date_time->day > ref->day) + { + return AXIS2_DATE_TIME_COMP_RES_EXPIRED; + } + + dt_min = date_time->tz_min; + dt_hour = date_time->tz_hour; + ref_min = ref->tz_min; + ref_hour = ref->tz_hour; + if(date_time->tz_pos) + { + dt_min *= -1; + dt_hour *= -1; + } + if(ref->tz_pos) + { + ref_min *= -1; + ref_hour *= -1; + } + + dt_min += date_time->min; + dt_hour += date_time->hour; + ref_min += ref->min; + ref_hour += ref->hour; + + if(dt_hour < ref_hour) + { + return AXIS2_DATE_TIME_COMP_RES_NOT_EXPIRED; + } + else if(dt_hour > ref_hour) + { + return AXIS2_DATE_TIME_COMP_RES_EXPIRED; + } + + if(dt_min < ref_min) + { + return AXIS2_DATE_TIME_COMP_RES_NOT_EXPIRED; + } + else if(dt_min > ref_min) + { + return AXIS2_DATE_TIME_COMP_RES_EXPIRED; + } + + if(date_time->sec < ref->sec) + { + return AXIS2_DATE_TIME_COMP_RES_NOT_EXPIRED; + } + else if(date_time->sec > ref->sec) + { + return AXIS2_DATE_TIME_COMP_RES_EXPIRED; + } + + return AXIS2_DATE_TIME_COMP_RES_EQUAL; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_date_time_set_time_zone( + axutil_date_time_t *date_time, + const axutil_env_t *env, + axis2_bool_t is_positive, + int hour, + int min) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + if(hour < 0 || hour > 14) + { + return AXIS2_FAILURE; + } + if(min < 0 || min > 59) + { + return AXIS2_FAILURE; + } + if(hour == 14 && min != 0) + { + return AXIS2_FAILURE; + } + date_time->tz_pos = is_positive; + date_time->tz_hour = hour; + date_time->tz_min = min; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_date_time_set_date_time( + axutil_date_time_t *date_time, + const axutil_env_t *env, + int year, + int mon, + int day, + int hour, + int min, + int sec, + int msec) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(mon < 1 || mon > 12) + { + return AXIS2_FAILURE; + } + if(day < 1 || day > 31) + { + return AXIS2_FAILURE; + } + if(day == 31 && (mon == 2 || mon == 4 || mon == 6 || mon == 9 || mon == 11)) + { + return AXIS2_FAILURE; + } + if(day == 30 && mon == 2) + { + return AXIS2_FAILURE; + } + if(day == 29 && mon == 2) + { + if(year % 4 != 0 || year % 400 == 0) + { + return AXIS2_FAILURE; + } + } + if(hour < 0 || hour > 23) + { + return AXIS2_FAILURE; + } + if(min < 0 || min > 59) + { + return AXIS2_FAILURE; + } + if(sec < 0 || sec > 59) + { + return AXIS2_FAILURE; + } + if(msec < 0 || msec > 999) + { + return AXIS2_FAILURE; + } + + date_time->year = year - 1900; + date_time->mon = mon - 1; + date_time->day = day; + date_time->hour = hour; + date_time->min = min; + date_time->sec = (float)sec; + date_time->sec += (float)msec / 1000; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_date_time_serialize_time( + axutil_date_time_t *date_time, + const axutil_env_t *env) +{ + axis2_char_t *time_str = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + time_str = (axis2_char_t *)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * 32); + sprintf(time_str, "%02d:%02d:%06.3fZ", date_time->hour, date_time->min, date_time->sec); + return time_str; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_date_time_serialize_time_with_time_zone( + axutil_date_time_t *date_time, + const axutil_env_t *env) +{ + axis2_char_t *time_str = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + if(!date_time->tz_hour && !date_time->tz_min) + { + return axutil_date_time_serialize_time(date_time, env); + } + + time_str = (axis2_char_t *)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * 37); + sprintf(time_str, "%02d:%02d:%06.3f%c%02d:%02d", date_time->hour, date_time->min, + date_time->sec, date_time->tz_pos ? '+' : '-', date_time->tz_hour, date_time->tz_min); + return time_str; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_date_time_serialize_date( + axutil_date_time_t *date_time, + const axutil_env_t *env) +{ + axis2_char_t *date_str = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + date_str = (axis2_char_t *)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * 32); + + sprintf(date_str, "%d-%02d-%02d", date_time->year + 1900, date_time->mon + 1, date_time->day); + return date_str; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_date_time_serialize_date_time( + axutil_date_time_t *date_time, + const axutil_env_t *env) +{ + axis2_char_t *date_time_str = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + date_time_str = AXIS2_MALLOC(env->allocator, sizeof(char) * 32); + sprintf(date_time_str, "%d-%02d-%02dT%02d:%02d:%06.3fZ", date_time->year + 1900, date_time->mon + + 1, date_time->day, date_time->hour, date_time->min, date_time->sec); + return date_time_str; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_date_time_serialize_date_time_without_millisecond( + axutil_date_time_t *date_time, + const axutil_env_t *env) +{ + axis2_char_t *date_time_str = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + date_time_str = AXIS2_MALLOC(env->allocator, sizeof(char) * 32); + sprintf(date_time_str, "%d-%02d-%02dT%02d:%02d:%02.0fZ", date_time->year + 1900, date_time->mon + + 1, date_time->day, date_time->hour, date_time->min, date_time->sec); + return date_time_str; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_date_time_serialize_date_time_with_time_zone( + axutil_date_time_t *date_time, + const axutil_env_t *env) +{ + axis2_char_t *date_time_str = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + if(!date_time->tz_hour && !date_time->tz_min) + { + return axutil_date_time_serialize_date_time(date_time, env); + } + + date_time_str = AXIS2_MALLOC(env->allocator, sizeof(char) * 37); + sprintf(date_time_str, "%d-%02d-%02dT%02d:%02d:%06.3f%c%02d:%02d", date_time->year + 1900, + date_time->mon + 1, date_time->day, date_time->hour, date_time->min, date_time->sec, + date_time->tz_pos ? '+' : '-', date_time->tz_hour, date_time->tz_min); + return date_time_str; +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_date_time_get_year( + axutil_date_time_t *date_time, + const axutil_env_t *env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + return (date_time->year + 1900); +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_date_time_get_month( + axutil_date_time_t *date_time, + const axutil_env_t *env) +{ + return (date_time->mon + 1); +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_date_time_get_date( + axutil_date_time_t *date_time, + const axutil_env_t *env) +{ + return (date_time->day); +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_date_time_get_hour( + axutil_date_time_t *date_time, + const axutil_env_t *env) +{ + return (date_time->hour); +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_date_time_get_minute( + axutil_date_time_t *date_time, + const axutil_env_t *env) +{ + return (date_time->min); +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_date_time_get_second( + axutil_date_time_t *date_time, + const axutil_env_t *env) +{ + return (int)(date_time->sec); +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_date_time_get_msec( + axutil_date_time_t *date_time, + const axutil_env_t *env) +{ + /* Precision is 1/100 of a millisecond */ + float ret = (float)((date_time->sec - (float)((int)date_time->sec)) * 1000.0); + return (int)((ret * 100.0 + 0.5) / 100.0); +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_date_time_get_time_zone_hour( + axutil_date_time_t *date_time, + const axutil_env_t *env) +{ + return (date_time->tz_hour); +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_date_time_get_time_zone_minute( + axutil_date_time_t *date_time, + const axutil_env_t *env) +{ + return (date_time->tz_min); +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_date_time_is_time_zone_positive( + axutil_date_time_t *date_time, + const axutil_env_t *env) +{ + return (date_time->tz_pos); +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axutil_date_time_is_utc( + axutil_date_time_t *date_time, + const axutil_env_t *env) +{ + axis2_bool_t is_utc = AXIS2_TRUE; + if(date_time->tz_hour || date_time->tz_min) + { + is_utc = AXIS2_FALSE; + } + return is_utc; +} + +AXIS2_EXTERN axutil_date_time_t *AXIS2_CALL +axutil_date_time_local_to_utc( + axutil_date_time_t *date_time, + const axutil_env_t *env) +{ + int year; + int mon; + int day; + int hour; + int min; + float sec; + int tz_hour; + int tz_min; + axis2_bool_t tz_pos = AXIS2_FALSE; + + axutil_date_time_t *ret = NULL; + + year = date_time->year; + mon = date_time->mon; + day = date_time->day; + hour = date_time->hour; + min = date_time->min; + sec = date_time->sec; + tz_pos = date_time->tz_pos; + tz_hour = date_time->tz_hour; + tz_min = date_time->tz_min; + + if(tz_pos) + { + tz_hour *= -1; + tz_min *= -1; + } + hour += tz_hour; + min += tz_min; + + if(min > 59) + { + hour += min / 60; + min %= 60; + } + while(min < 0) + { + hour--; + min += 60; + } + + if(hour > 23) + { + day += hour / 24; + hour %= 24; + } + while(hour < 0) + { + day--; + hour += 24; + } + + mon--; + while(mon < 0) + { + mon += 12; + year--; + } + while(mon > 11) + { + mon -= 12; + year++; + } + mon++; + + day--; + while(day > 27) + { + if(mon == 2) + { + if(year % 4 != 0 || year % 400 == 0) + { + day -= 28; + mon++; + } + else if(day > 28) + { + day -= 29; + mon++; + } + else + { + break; + } + } + else if(day > 29) + { + if(mon == 4 || mon == 6 || mon == 9 || mon == 11) + { + day -= 30; + } + else if(day > 30) + { + day -= 31; + } + else + { + break; + } + mon++; + } + else + { + break; + } + if(mon > 12) + { + mon = 1; + year++; + } + } + while(day < 0) + { + if(mon == 3) + { + day += 28; + if(year % 4 == 0 || year % 400 != 0) + { + day++; + } + } + if(mon == 5 || mon == 7 || mon == 10 || mon == 12) + { + day += 30; + } + else + { + day += 31; + } + mon--; + if(mon < 1) + { + mon = 12; + year--; + } + } + day++; + + if(mon < 1 || mon > 12) + { + return NULL; + } + if(day < 1 || day > 31) + { + return NULL; + } + if(day == 31 && (mon == 2 || mon == 4 || mon == 6 || mon == 9 || mon == 11)) + { + return NULL; + } + if(day == 30 && mon == 2) + { + return NULL; + } + if(day == 29 && mon == 2) + { + if(year % 4 != 0 || year % 400 == 0) + { + return NULL; + } + } + if(hour < 0 || hour > 23) + { + return NULL; + } + if(min < 0 || min > 59) + { + return NULL; + } + if(sec < 0 || sec >= 60) + { + return NULL; + } + + ret = axutil_date_time_create(env); + ret->year = year - 1900; + ret->mon = mon - 1; + ret->day = day; + ret->hour = hour; + ret->min = min; + ret->sec = sec; + return ret; +} + +AXIS2_EXTERN axutil_date_time_t *AXIS2_CALL +axutil_date_time_utc_to_local( + axutil_date_time_t *date_time_in, + const axutil_env_t *env, + axis2_bool_t is_positive, + int hour, + int min) +{ + axutil_date_time_t *date_time = NULL; + axutil_date_time_t *ret = NULL; + if(date_time_in->tz_hour && date_time_in->tz_min) + { + return NULL; + } + date_time->year = date_time_in->year; + date_time->mon = date_time_in->mon; + date_time->day = date_time_in->day; + date_time->hour = date_time_in->hour; + date_time->min = date_time_in->min; + date_time->sec = date_time_in->sec; + date_time->tz_hour = hour; + date_time->tz_min = min; + + date_time->tz_pos = is_positive ? AXIS2_FALSE : AXIS2_TRUE; + ret = axutil_date_time_local_to_utc(date_time, env); + ret->tz_hour = hour; + ret->tz_min = min; + + ret->tz_pos = is_positive; + + axutil_date_time_free(date_time, env); + return ret; +} diff --git a/util/src/date_time_util.c b/util/src/date_time_util.c new file mode 100644 index 0000000..ec1149c --- /dev/null +++ b/util/src/date_time_util.c @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_date_time_util.h> + +AXIS2_EXTERN int AXIS2_CALL +axutil_get_milliseconds( + const axutil_env_t *env) +{ + return axis2_platform_get_milliseconds(); +} diff --git a/util/src/digest_calc.c b/util/src/digest_calc.c new file mode 100644 index 0000000..f89a902 --- /dev/null +++ b/util/src/digest_calc.c @@ -0,0 +1,144 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_string.h> +#include <axutil_md5.h> +#include <axutil_digest_calc.h> + +void AXIS2_CALL convert_to_hex( + axutil_digest_hash_t bin, + axutil_digest_hash_hex_t hex); + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_digest_calc_get_h_a1( + const axutil_env_t *env, + char *algorithm, + char *user_name, + char *realm, + char *password, + char *nonce, + char *cnonce, + axutil_digest_hash_hex_t session_key) +{ + axutil_md5_ctx_t *ctx; + axutil_digest_hash_t ha1; + + ctx = axutil_md5_ctx_create(env); + if(!ctx) + return AXIS2_FAILURE; + axutil_md5_update(ctx, env, user_name, strlen(user_name)); + axutil_md5_update(ctx, env, ":", 1); + axutil_md5_update(ctx, env, realm, strlen(realm)); + axutil_md5_update(ctx, env, ":", 1); + axutil_md5_update(ctx, env, password, strlen(password)); + axutil_md5_final(ctx, env, ha1); + axutil_md5_ctx_free(ctx, env); + if(!axutil_strcasecmp(algorithm, "md5-sess")) + { + ctx = axutil_md5_ctx_create(env); + if(!ctx) + return AXIS2_FAILURE; + axutil_md5_update(ctx, env, ha1, AXIS2_DIGEST_HASH_LEN); + axutil_md5_update(ctx, env, ":", 1); + axutil_md5_update(ctx, env, nonce, strlen(nonce)); + axutil_md5_update(ctx, env, ":", 1); + axutil_md5_update(ctx, env, cnonce, strlen(cnonce)); + axutil_md5_final(ctx, env, ha1); + axutil_md5_ctx_free(ctx, env); + } + convert_to_hex(ha1, session_key); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_digest_calc_get_response( + const axutil_env_t *env, + axutil_digest_hash_hex_t h_a1, + char *nonce, + char *nonce_count, + char *cnonce, + char *qop, + char *method, + char *digest_uri, + axutil_digest_hash_hex_t h_entity, + axutil_digest_hash_hex_t response) +{ + axutil_md5_ctx_t *ctx; + axutil_digest_hash_t ha2; + axutil_digest_hash_t resp_hash; + axutil_digest_hash_hex_t ha2_hex; + + ctx = axutil_md5_ctx_create(env); + if(!ctx) + return AXIS2_FAILURE; + axutil_md5_update(ctx, env, method, strlen(method)); + axutil_md5_update(ctx, env, ":", 1); + axutil_md5_update(ctx, env, digest_uri, strlen(digest_uri)); + if(!axutil_strcasecmp(qop, "auth-int")) + { + axutil_md5_update(ctx, env, ":", 1); + axutil_md5_update(ctx, env, h_entity, AXIS2_DIGEST_HASH_HEX_LEN); + }; + axutil_md5_final(ctx, env, ha2); + axutil_md5_ctx_free(ctx, env); + convert_to_hex(ha2, ha2_hex); + + ctx = axutil_md5_ctx_create(env); + if(!ctx) + return AXIS2_FAILURE; + axutil_md5_update(ctx, env, h_a1, AXIS2_DIGEST_HASH_HEX_LEN); + axutil_md5_update(ctx, env, ":", 1); + axutil_md5_update(ctx, env, nonce, strlen(nonce)); + axutil_md5_update(ctx, env, ":", 1); + if(*qop) + { + axutil_md5_update(ctx, env, nonce_count, strlen(nonce_count)); + axutil_md5_update(ctx, env, ":", 1); + axutil_md5_update(ctx, env, cnonce, strlen(cnonce)); + axutil_md5_update(ctx, env, ":", 1); + axutil_md5_update(ctx, env, qop, strlen(qop)); + axutil_md5_update(ctx, env, ":", 1); + }; + axutil_md5_update(ctx, env, ha2_hex, AXIS2_DIGEST_HASH_HEX_LEN); + axutil_md5_final(ctx, env, resp_hash); + axutil_md5_ctx_free(ctx, env); + convert_to_hex(resp_hash, response); + return AXIS2_SUCCESS; +} + +void AXIS2_CALL convert_to_hex( + axutil_digest_hash_t bin, + axutil_digest_hash_hex_t hex) +{ + unsigned short i; + unsigned char j; + + for (i = 0; i < AXIS2_DIGEST_HASH_LEN; i++) + { + j = (bin[i] >> 4) & 0xf; + if (j <= 9) + hex[i*2] = (j + '0'); + else + hex[i*2] = (j + 'a' - 10); + j = bin[i] & 0xf; + if (j <= 9) + hex[i*2+1] = (j + '0'); + else + hex[i*2+1] = (j + 'a' - 10); + } + hex[AXIS2_DIGEST_HASH_HEX_LEN] = '\0'; +} diff --git a/util/src/dir_handler.c b/util/src/dir_handler.c new file mode 100644 index 0000000..4a5e51e --- /dev/null +++ b/util/src/dir_handler.c @@ -0,0 +1,371 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_dir_handler.h> +#include <axutil_file.h> +#include <platforms/axutil_platform_auto_sense.h> +#include <axutil_string.h> +#ifndef S_ISDIR +# define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR) +#endif + +#ifdef AXIS2_ARCHIVE_ENABLED +#include <minizip/axis2_archive_extract.h> +#endif + + +extern int AXIS2_ALPHASORT( + ); +#ifdef IS_MACOSX +int dir_select( + struct dirent *entry); +int file_select( + struct dirent *entry); +#else +int dir_select( + const struct dirent *entry); +int file_select( + const struct dirent *entry); +#endif + +/** + * List the dll files in the given service or module folder path + * @param pathname path to your service or module directory + * @return array list of dll file names + */ +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +axutil_dir_handler_list_services_or_modules_in_dir( + const axutil_env_t *env, + const axis2_char_t *pathname) +{ + axutil_array_list_t *file_list = NULL; + struct stat *buf = NULL; + int count = 1; + int i = 0; + struct dirent **files = NULL; + /*int file_select( + );*/ + /* Removed un-wanted redefinition leading to warnings on + * Windows. If this is the desired behaviour, please look + * into the file_select function definition below and comment + * out the code if neccessary. + */ + axis2_status_t status = AXIS2_FAILURE; + + AXIS2_ENV_CHECK(env, NULL); + file_list = axutil_array_list_create(env, 100); + count = AXIS2_SCANDIR(pathname, &files, file_select, AXIS2_ALPHASORT); + /* If no files found, make a non-selectable menu item */ + if(count <= 0) + { + axutil_array_list_free(file_list, env); + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "No files in the path %s.", pathname); + return NULL; + } + + for(i = 1; i < (count + 1); ++i) + { + axis2_char_t *fname = NULL; + axutil_file_t *arch_file = NULL; + axis2_char_t *path = NULL; + axis2_char_t *temp_path = NULL; + + fname = files[i - 1]->d_name; + arch_file = (axutil_file_t *)axutil_file_create(env); + if(!arch_file) + { + int size = 0; + int j = 0; + axutil_file_t *del_file = NULL; + + size = axutil_array_list_size(file_list, env); + for(j = 0; j < size; j++) + { + del_file = axutil_array_list_get(file_list, env, j); + axutil_file_free(del_file, env); + } + axutil_array_list_free(file_list, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + axutil_file_set_name(arch_file, env, fname); + temp_path = axutil_stracat(env, pathname, AXIS2_PATH_SEP_STR); + path = axutil_stracat(env, temp_path, fname); + AXIS2_FREE(env->allocator, temp_path); + if(!path) + { + int size = 0; + int j = 0; + axutil_file_t *del_file = NULL; + + axutil_file_free(arch_file, env); + size = axutil_array_list_size(file_list, env); + for(j = 0; j < size; j++) + { + del_file = axutil_array_list_get(file_list, env, j); + axutil_file_free(del_file, env); + } + axutil_array_list_free(file_list, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + axutil_file_set_path(arch_file, env, path); + buf = AXIS2_MALLOC(env->allocator, sizeof(struct stat)); + if(!buf) + { + int size = 0; + int j = 0; + axutil_file_t *del_file = NULL; + + AXIS2_FREE(env->allocator, path); + axutil_file_free(arch_file, env); + size = axutil_array_list_size(file_list, env); + for(j = 0; j < size; j++) + { + del_file = axutil_array_list_get(file_list, env, j); + axutil_file_free(del_file, env); + } + axutil_array_list_free(file_list, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + stat(path, buf); + axutil_file_set_timestamp(arch_file, env, (time_t)buf->st_ctime); + status = axutil_array_list_add(file_list, env, arch_file); + if(AXIS2_SUCCESS != status) + { + int size = 0; + int j = 0; + axutil_file_t *del_file = NULL; + + axutil_file_free(arch_file, env); + AXIS2_FREE(env->allocator, path); + AXIS2_FREE(env->allocator, buf); + size = axutil_array_list_size(file_list, env); + for(j = 0; j < size; j++) + { + del_file = axutil_array_list_get(file_list, env, j); + axutil_file_free(del_file, env); + } + axutil_array_list_free(file_list, env); + return NULL; + } + AXIS2_FREE(env->allocator, path); + AXIS2_FREE(env->allocator, buf); + + } + return file_list; +} + +/** + * List services or modules directories in the services or modules folder + * respectively + * @param pathname path your modules or services folder + * @return array list of contents of services or modules folder + */ +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +axutil_dir_handler_list_service_or_module_dirs( + const axutil_env_t *env, + const axis2_char_t *pathname) +{ + axutil_array_list_t *file_list = NULL; + struct stat *buf = NULL; + int count = 1; + int i = 0; + struct dirent **files = NULL; + char cwd[500]; + int chdir_result = 0; + + /**FIXME: + * This magic number 500 was selected as a temporary solution. It has to be + * replaced with dynamic memory allocation. This will be done once the use of + * errno after getwcd() on Windows is figured out. + */ + + axis2_status_t status = AXIS2_FAILURE; + AXIS2_ENV_CHECK(env, NULL); + file_list = axutil_array_list_create(env, 0); + if(!AXIS2_GETCWD(cwd, 500)) + exit(1); + + /* pathname is path of services directory or modules directory. */ + chdir_result = AXIS2_CHDIR(pathname); +#ifdef AXIS2_ARCHIVE_ENABLED + axis2_archive_extract(); +#endif + + count = AXIS2_SCANDIR(pathname, &files, dir_select, AXIS2_ALPHASORT); + chdir_result = AXIS2_CHDIR(cwd); + + /* If no files found, make a non-selectable menu item */ + if(count <= 0) + { + axutil_array_list_free(file_list, env); + AXIS2_LOG_INFO(env->log, "No files in the path %s.", pathname); + return NULL; + } + + for(i = 1; i < (count + 1); ++i) + { + axis2_char_t *fname = NULL; + axutil_file_t *arch_file = NULL; + axis2_char_t *path = NULL; + axis2_char_t *temp_path = NULL; + + fname = files[i - 1]->d_name; + arch_file = (axutil_file_t *)axutil_file_create(env); + if(!arch_file) + { + int size = 0; + int j = 0; + axutil_file_t *del_file = NULL; + + size = axutil_array_list_size(file_list, env); + for(j = 0; j < size; j++) + { + del_file = axutil_array_list_get(file_list, env, j); + axutil_file_free(del_file, env); + } + axutil_array_list_free(file_list, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + axutil_file_set_name(arch_file, env, fname); + temp_path = axutil_stracat(env, pathname, AXIS2_PATH_SEP_STR); + path = axutil_stracat(env, temp_path, fname); + if(!path) + { + int size = 0; + int j = 0; + axutil_file_t *del_file = NULL; + + axutil_file_free(arch_file, env); + size = axutil_array_list_size(file_list, env); + for(j = 0; j < size; j++) + { + del_file = axutil_array_list_get(file_list, env, j); + axutil_file_free(del_file, env); + } + axutil_array_list_free(file_list, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + axutil_file_set_path(arch_file, env, path); + AXIS2_FREE(env->allocator, temp_path); + buf = AXIS2_MALLOC(env->allocator, sizeof(struct stat)); + if(!buf) + { + int size = 0; + int j = 0; + axutil_file_t *del_file = NULL; + + axutil_file_free(arch_file, env); + AXIS2_FREE(env->allocator, path); + size = axutil_array_list_size(file_list, env); + for(j = 0; j < size; j++) + { + del_file = axutil_array_list_get(file_list, env, j); + axutil_file_free(del_file, env); + } + axutil_array_list_free(file_list, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + stat(path, buf); + axutil_file_set_timestamp(arch_file, env, (time_t)buf->st_ctime); + status = axutil_array_list_add(file_list, env, arch_file); + if(AXIS2_SUCCESS != status) + { + int size = 0; + int j = 0; + axutil_file_t *del_file = NULL; + + axutil_file_free(arch_file, env); + AXIS2_FREE(env->allocator, path); + AXIS2_FREE(env->allocator, buf); + size = axutil_array_list_size(file_list, env); + for(j = 0; j < size; j++) + { + del_file = axutil_array_list_get(file_list, env, j); + axutil_file_free(del_file, env); + } + axutil_array_list_free(file_list, env); + return NULL; + } + AXIS2_FREE(env->allocator, path); + AXIS2_FREE(env->allocator, buf); + } + + for(i = 0; i < count; i++) + { + free(files[i]); + } + free(files); + return file_list; +} + +#ifdef IS_MACOSX + int file_select(struct dirent *entry) +{ +#else + int file_select(const struct dirent *entry) +{ +#endif + /** FIXME: + * This block of code has been sitting here doing nothing. + * I have made the existing logic use this code portion. + * Have no idea about the side-effects of this modification. + * If this code block is not required, we might as well remove + * it. + */ + axis2_char_t *ptr; + + if((strcmp(entry->d_name, ".") == 0) || (strcmp(entry->d_name, "..") == 0)) + return (AXIS2_FALSE); + + /* Check for filename extensions */ + ptr = axutil_rindex(entry->d_name, '.'); + if((ptr) && ((strcmp(ptr, AXIS2_LIB_SUFFIX) == 0))) + { + return (AXIS2_TRUE); + } + else + return (AXIS2_FALSE); +} + +#ifdef IS_MACOSX +int +dir_select( + struct dirent *entry) +#else +int +dir_select( + const struct dirent *entry) +#endif +{ + struct stat stat_p; + + if(-1 == stat(entry->d_name, &stat_p)) + return (AXIS2_FALSE); + + if((entry->d_name[0] == '.') || (!S_ISDIR(stat_p.st_mode))) + { + return (AXIS2_FALSE); + } + + return AXIS2_TRUE; +} diff --git a/util/src/dll_desc.c b/util/src/dll_desc.c new file mode 100644 index 0000000..697caf3 --- /dev/null +++ b/util/src/dll_desc.c @@ -0,0 +1,298 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_dll_desc.h> +#include <axutil_class_loader.h> + +struct axutil_dll_desc +{ + axis2_char_t *dll_name; + axis2_char_t *path_qualified_dll_name; + axis2_dll_type_t dll_type; + int load_options; + AXIS2_DLHANDLER dl_handler; + CREATE_FUNCT create_funct; + DELETE_FUNCT delete_funct; + AXIS2_TIME_T timestamp; + axutil_error_codes_t error_code; + +}; + +AXIS2_EXTERN axutil_dll_desc_t *AXIS2_CALL +axutil_dll_desc_create( + const axutil_env_t *env) +{ + axutil_dll_desc_t *dll_desc = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + dll_desc = (axutil_dll_desc_t *)AXIS2_MALLOC(env->allocator, sizeof(axutil_dll_desc_t)); + + if(!dll_desc) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + + dll_desc->dll_name = NULL; + dll_desc->path_qualified_dll_name = NULL; + dll_desc->dll_type = 0; + dll_desc->load_options = 0; + dll_desc->dl_handler = NULL; + dll_desc->create_funct = NULL; + dll_desc->delete_funct = NULL; + dll_desc->timestamp = 0; + dll_desc->error_code = AXIS2_ERROR_NONE; + + return dll_desc; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_dll_desc_free( + axutil_dll_desc_t *dll_desc, + const axutil_env_t *env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(dll_desc->dl_handler) + { + axutil_class_loader_delete_dll(env, dll_desc); + } + + if(dll_desc->dll_name) + { + AXIS2_FREE(env->allocator, dll_desc->dll_name); + dll_desc->dll_name = NULL; + } + + if(dll_desc->path_qualified_dll_name) + { + AXIS2_FREE(env->allocator, dll_desc->path_qualified_dll_name); + dll_desc->path_qualified_dll_name = NULL; + } + + if(dll_desc) + { + AXIS2_FREE(env->allocator, dll_desc); + } + return; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_dll_desc_free_void_arg( + void *dll_desc, + const axutil_env_t *env) +{ + axutil_dll_desc_t *dll_desc_l = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + dll_desc_l = (axutil_dll_desc_t *)dll_desc; + axutil_dll_desc_free(dll_desc_l, env); + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_dll_desc_set_name( + axutil_dll_desc_t *dll_desc, + const axutil_env_t *env, + axis2_char_t *name) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, name, AXIS2_FAILURE); + + if(dll_desc->path_qualified_dll_name) + { + AXIS2_FREE(env->allocator, dll_desc->path_qualified_dll_name); + dll_desc->path_qualified_dll_name = NULL; + } + + dll_desc->path_qualified_dll_name = axutil_strdup(env, name); + if(!dll_desc->path_qualified_dll_name) + { + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_dll_desc_get_name( + axutil_dll_desc_t *dll_desc, + const axutil_env_t *env) +{ + return dll_desc->path_qualified_dll_name; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_dll_desc_set_load_options( + axutil_dll_desc_t *dll_desc, + const axutil_env_t *env, + int options) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + dll_desc->load_options = options; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_dll_desc_set_type( + axutil_dll_desc_t *dll_desc, + const axutil_env_t *env, + axis2_dll_type_t type) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + dll_desc->dll_type = type; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_dll_type_t AXIS2_CALL +axutil_dll_desc_get_type( + axutil_dll_desc_t *dll_desc, + const axutil_env_t *env) +{ + return dll_desc->dll_type; +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_dll_desc_get_load_options( + axutil_dll_desc_t *dll_desc, + const axutil_env_t *env) +{ + return dll_desc->load_options; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_dll_desc_set_dl_handler( + axutil_dll_desc_t *dll_desc, + const axutil_env_t *env, + AXIS2_DLHANDLER dl_handler) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, dl_handler, AXIS2_FAILURE); + + if(dll_desc->dl_handler) + { + AXIS2_FREE(env->allocator, dll_desc->dl_handler); + } + dll_desc->dl_handler = dl_handler; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN AXIS2_DLHANDLER AXIS2_CALL +axutil_dll_desc_get_dl_handler( + axutil_dll_desc_t *dll_desc, + const axutil_env_t *env) +{ + return dll_desc->dl_handler; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_dll_desc_set_create_funct( + axutil_dll_desc_t *dll_desc, + const axutil_env_t *env, + CREATE_FUNCT funct) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + dll_desc->create_funct = funct; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN CREATE_FUNCT AXIS2_CALL +axutil_dll_desc_get_create_funct( + axutil_dll_desc_t *dll_desc, + const axutil_env_t *env) +{ + return dll_desc->create_funct; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_dll_desc_set_delete_funct( + axutil_dll_desc_t *dll_desc, + const axutil_env_t *env, + DELETE_FUNCT funct) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + dll_desc->delete_funct = funct; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN DELETE_FUNCT AXIS2_CALL +axutil_dll_desc_get_delete_funct( + axutil_dll_desc_t *dll_desc, + const axutil_env_t *env) +{ + return dll_desc->delete_funct; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_dll_desc_set_timestamp( + axutil_dll_desc_t *dll_desc, + const axutil_env_t *env, + AXIS2_TIME_T timestamp) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + dll_desc->timestamp = timestamp; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN AXIS2_TIME_T AXIS2_CALL +axutil_dll_desc_get_timestamp( + axutil_dll_desc_t *dll_desc, + const axutil_env_t *env) +{ + return dll_desc->timestamp; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_dll_desc_set_error_code( + axutil_dll_desc_t *dll_desc, + const axutil_env_t *env, + axutil_error_codes_t error_code) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + dll_desc->error_code = error_code; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axutil_error_codes_t AXIS2_CALL +axutil_dll_desc_get_error_code( + axutil_dll_desc_t *dll_desc, + const axutil_env_t *env) +{ + return dll_desc->error_code; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_dll_desc_create_platform_specific_dll_name( + axutil_dll_desc_t *dll_desc, + const axutil_env_t *env, + const axis2_char_t *class_name) +{ + axis2_char_t *temp_name = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + temp_name = axutil_stracat(env, AXIS2_LIB_PREFIX, class_name); + dll_desc->dll_name = axutil_stracat(env, temp_name, AXIS2_LIB_SUFFIX); + AXIS2_FREE(env->allocator, temp_name); + return dll_desc->dll_name; +} diff --git a/util/src/duration.c b/util/src/duration.c new file mode 100644 index 0000000..381f025 --- /dev/null +++ b/util/src/duration.c @@ -0,0 +1,576 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_duration.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <axutil_error.h> +#include <axutil_utils.h> + +struct axutil_duration +{ + axis2_bool_t is_negative; + int years; + int months; + int days; + int hours; + int mins; + double secs; +}; + +AXIS2_EXTERN axutil_duration_t *AXIS2_CALL +axutil_duration_create( + axutil_env_t *env) +{ + return axutil_duration_create_from_values(env, 0, 0, 0, 0, 0, 0, 0.0); +} + +AXIS2_EXTERN axutil_duration_t *AXIS2_CALL +axutil_duration_create_from_values( + const axutil_env_t *env, + axis2_bool_t negative, + int years, + int months, + int days, + int hours, + int minutes, + double seconds) +{ + axutil_duration_t *duration = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + duration = (axutil_duration_t *)AXIS2_MALLOC(env->allocator, sizeof(axutil_duration_t)); + if(!duration) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + + duration->is_negative = negative; + if(years > -1) + { + duration->years = years; + } + else + { + duration->years = 0; + } + if(months > -1) + { + duration->months = months; + } + else + { + duration->months = 0; + } + if(days > -1) + { + duration->days = days; + } + else + { + duration->days = 0; + } + if(hours > -1) + { + duration->hours = hours; + } + else + { + duration->hours = 0; + } + if(minutes > -1) + { + duration->mins = minutes; + } + else + { + duration->mins = 0; + } + if(seconds >= 0) + { + duration->secs = seconds; + } + else + { + duration->secs = 0.0; + } + return duration; +} + +AXIS2_EXTERN axutil_duration_t *AXIS2_CALL +axutil_duration_create_from_string( + const axutil_env_t *env, + const axis2_char_t *duration_str) +{ + axutil_duration_t *duration = NULL; + + duration = (axutil_duration_t *)AXIS2_MALLOC(env->allocator, sizeof(axutil_duration_t)); + if(!duration) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + + axutil_duration_deserialize_duration(duration, env, duration_str); + return duration; +} + +/***************************Function implementation****************************/ + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_duration_free( + axutil_duration_t *duration, + const axutil_env_t *env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(duration) + { + AXIS2_FREE(env->allocator, duration); + duration = NULL; + } + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_duration_deserialize_duration( + axutil_duration_t *duration, + const axutil_env_t *env, + const axis2_char_t *duration_str) +{ + const axis2_char_t *cur = duration_str; + double num; + int num_type = 0; + unsigned int seq = 0; + const char desig[] = { 'Y', 'M', 'D', 'H', 'M', 'S' }; + + AXIS2_PARAM_CHECK(env->error, duration, AXIS2_FAILURE); + + duration->is_negative = AXIS2_FALSE; + duration->years = duration->months = duration->days = duration->hours = duration->mins = 0; + duration->secs = 0; + + if(!duration_str) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + + if(*cur == '-') + { + duration->is_negative = 1; + cur++; + } + + if(*cur++ != 'P') + { + duration->is_negative = AXIS2_FALSE; + duration->years = duration->months = duration->days = duration->hours = duration->mins = 0; + duration->secs = 0; + + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NONE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + + if(!*cur) + { + duration->is_negative = AXIS2_FALSE; + duration->years = duration->months = duration->days = duration->hours = duration->mins = 0; + duration->secs = 0; + + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NONE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + + while(*cur) + { + if(seq >= sizeof(desig)) + { + duration->is_negative = AXIS2_FALSE; + duration->years = duration->months = duration->days = duration->hours = duration->mins + = 0; + duration->secs = 0; + + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NONE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + + if(*cur == 'T') + { + if(!(seq > 3)) + { + seq = 3; + cur++; + } + else + { + duration->is_negative = AXIS2_FALSE; + duration->years = duration->months = duration->days = duration->hours + = duration->mins = 0; + duration->secs = 0; + + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NONE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + } + num = 0; + + if((*cur < '0') || (*cur > '9')) + num_type = -1; + else + { + num_type = 0; + while((*cur >= '0') && (*cur <= '9')) + { + num = num * 10 + (*cur - '0'); + cur++; + } + } + + if(!num_type && (*cur == '.')) + { + double mult = 1; + cur++; + if((*cur < '0') || (*cur > '9')) + num_type = -1; + else + num_type = 1; + while((*cur >= '0') && (*cur <= '9')) + { + mult /= 10; + num += (*cur - '0') * mult; + cur++; + } + } + + if((num_type == -1) || (*cur == 0)) + { + duration->is_negative = AXIS2_FALSE; + duration->years = duration->months = duration->days = duration->hours = duration->mins + = 0; + duration->secs = 0; + + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NONE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + + while(seq < sizeof(desig)) + { + if(*cur == desig[seq]) + { + num_type = 0; + /*if (seq < (sizeof(desig) - 1)) + { + duration->is_negative = AXIS2_FALSE; + duration->years = duration->months = duration->days = duration->hours = duration->mins = 0; + duration->secs = 0; + + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NONE, + AXIS2_FAILURE); + return AXIS2_FAILURE; + }*/ + + switch(seq) + { + case 0: + duration->years = (int)num; + seq++; + break; + case 1: + duration->months = (int)num; + seq++; + break; + case 2: + duration->days = (int)num; + seq++; + break; + case 3: + duration->hours = (int)num; + seq++; + break; + case 4: + duration->mins = (int)num; + seq++; + break; + case 5: + duration->secs = num; + seq++; + break; + } + break; + } + if((++seq == 3) || (seq == 6)) + return AXIS2_SUCCESS; + } + cur++; + } + return AXIS2_SUCCESS; + +} + +AXIS2_EXTERN char *AXIS2_CALL +axutil_duration_serialize_duration( + axutil_duration_t *duration, + const axutil_env_t *env) +{ + axis2_char_t *duration_str = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + duration_str = (axis2_char_t *)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * 64); + + if(duration->is_negative == 0) + sprintf(duration_str, "P%dY%dM%dDT%dH%dM%fS", duration->years, duration->months, + duration->days, duration->hours, duration->mins, duration->secs); + else + sprintf(duration_str, "-P%dY%dM%dDT%dH%dM%fS", duration->years, duration->months, + duration->days, duration->hours, duration->mins, duration->secs); + + return duration_str; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_duration_set_duration( + axutil_duration_t *duration, + const axutil_env_t *env, + axis2_bool_t negative, + int years, + int months, + int days, + int hours, + int mins, + double seconds) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(years > -1) + duration->years = years; + if(months > -1) + duration->months = months; + if(days > -1) + duration->days = days; + if(hours > -1) + duration->hours = hours; + if(mins > -1) + duration->mins = mins; + if(seconds >= 0) + duration->secs = seconds; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_duration_get_years( + axutil_duration_t *duration, + const axutil_env_t *env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + return duration->years; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_duration_set_years( + axutil_duration_t *duration, + const axutil_env_t *env, + int years) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + if(years > -1) + { + duration->years = years; + } + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_duration_get_months( + axutil_duration_t *duration, + const axutil_env_t *env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + return duration->months; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_duration_set_months( + axutil_duration_t *duration, + const axutil_env_t *env, + int months) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + if(months > -1) + { + duration->months = months; + } + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_duration_get_days( + axutil_duration_t *duration, + const axutil_env_t *env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + return duration->days; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_duration_set_days( + axutil_duration_t *duration, + const axutil_env_t *env, + int days) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + if(days > -1) + { + duration->days = days; + } + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_duration_get_hours( + axutil_duration_t *duration, + const axutil_env_t *env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + return duration->hours; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_duration_set_hours( + axutil_duration_t *duration, + const axutil_env_t *env, + int hours) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + if(hours > -1) + { + duration->hours = hours; + } + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_duration_get_mins( + axutil_duration_t *duration, + const axutil_env_t *env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + return duration->mins; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_duration_set_mins( + axutil_duration_t *duration, + const axutil_env_t *env, + int mins) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + if(mins > -1) + { + duration->mins = mins; + } + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN double AXIS2_CALL +axutil_duration_get_seconds( + axutil_duration_t *duration, + const axutil_env_t *env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + return duration->secs; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_duration_set_seconds( + axutil_duration_t *duration, + const axutil_env_t *env, + double seconds) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + if(seconds >= 0) + { + duration->secs = seconds; + } + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axutil_duration_get_is_negative( + axutil_duration_t *duration, + const axutil_env_t *env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + return duration->is_negative; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_duration_set_is_negative( + axutil_duration_t *duration, + const axutil_env_t *env, + axis2_bool_t is_negative) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + duration->is_negative = is_negative; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axutil_duration_compare( + axutil_duration_t *duration_one, + axutil_duration_t *duration_two, + axutil_env_t *env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + if(!duration_one || !duration_two) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE); + return AXIS2_FALSE; + } + + if(duration_one->is_negative != duration_two->is_negative) + return AXIS2_FALSE; + if(duration_one->years != duration_two->years) + return AXIS2_FALSE; + if(duration_one->months != duration_two->months) + return AXIS2_FALSE; + if(duration_one->days != duration_two->days) + return AXIS2_FALSE; + if(duration_one->hours != duration_two->hours) + return AXIS2_FALSE; + if(duration_one->mins != duration_two->mins) + return AXIS2_FALSE; + if(duration_one->secs != duration_two->secs) + return AXIS2_FALSE; + return AXIS2_SUCCESS; +} + diff --git a/util/src/env.c b/util/src/env.c new file mode 100644 index 0000000..38b89d3 --- /dev/null +++ b/util/src/env.c @@ -0,0 +1,305 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <stdlib.h> +#include <string.h> +#include <axutil_env.h> +#include <axutil_error_default.h> +#include <axutil_log_default.h> +#include <axutil_string.h> + +AXIS2_EXTERN axutil_env_t *AXIS2_CALL +axutil_env_create( + axutil_allocator_t *allocator) +{ + axutil_env_t *env; + + if(!allocator) + return NULL; + + env = (axutil_env_t *)AXIS2_MALLOC(allocator, sizeof(axutil_env_t)); + + if(!env) + return NULL; + + memset(env, 0, sizeof(axutil_env_t)); + + env->allocator = allocator; + + env->log = axutil_log_create_default(allocator); + env->log->level = AXIS2_LOG_LEVEL_DEBUG; /* default log level is debug */ + env->log_enabled = AXIS2_TRUE; + + /* Create default error struct */ + env->error = axutil_error_create(allocator); + if(!env->error) + { + AXIS2_FREE(allocator, env); + return NULL; + } + + /* Call error init to fill in the axutil_error_messages array. + This array holds the error messages with respect to error codes */ + axutil_error_init(); + + env->ref = 1; + env->get_session_fn = NULL; + env->set_session_fn = NULL; + + return env; +} + +AXIS2_EXTERN axutil_env_t *AXIS2_CALL +axutil_env_create_with_error_log( + axutil_allocator_t *allocator, + axutil_error_t *error, + axutil_log_t *log) +{ + axutil_env_t *env; + if(!allocator || !error) + return NULL; + + env = (axutil_env_t *)AXIS2_MALLOC(allocator, sizeof(axutil_env_t)); + + if(!env) + return NULL; + + memset(env, 0, sizeof(axutil_env_t)); + + env->allocator = allocator; + env->error = error; + env->log = log; + + if(env->log) + env->log_enabled = AXIS2_TRUE; + else + env->log_enabled = AXIS2_FALSE; + + axutil_error_init(); + + env->ref = 1; + env->get_session_fn = NULL; + env->set_session_fn = NULL; + + return env; +} + +AXIS2_EXTERN axutil_env_t *AXIS2_CALL +axutil_env_create_with_error( + axutil_allocator_t *allocator, + axutil_error_t *error) +{ + return axutil_env_create_with_error_log(allocator, error, NULL); +} + +AXIS2_EXTERN axutil_env_t *AXIS2_CALL +axutil_env_create_with_error_log_thread_pool( + axutil_allocator_t *allocator, + axutil_error_t *error, + axutil_log_t *log, + axutil_thread_pool_t *pool) +{ + axutil_env_t *env; + if(!allocator || !error || !pool) + return NULL; + + env = (axutil_env_t *)AXIS2_MALLOC(allocator, sizeof(axutil_env_t)); + + if(!env) + return NULL; + + memset(env, 0, sizeof(axutil_env_t)); + + env->allocator = allocator; + env->error = error; + env->log = log; + + env->thread_pool = pool; + + if(env->log) + env->log_enabled = AXIS2_TRUE; + else + env->log_enabled = AXIS2_FALSE; + + axutil_error_init(); + + env->ref = 1; + env->get_session_fn = NULL; + env->set_session_fn = NULL; + + return env; +} + +AXIS2_EXTERN axutil_env_t *AXIS2_CALL +axutil_env_create_all( + const axis2_char_t *log_file, + const axutil_log_levels_t log_level) +{ + axutil_env_t *env = NULL; + axutil_error_t *error = NULL; + axutil_log_t *log = NULL; + axutil_allocator_t *allocator = NULL; + axutil_thread_pool_t *thread_pool = NULL; + + allocator = axutil_allocator_init(NULL); + error = axutil_error_create(allocator); + + if(log_file) + { + log = axutil_log_create(allocator, NULL, log_file); + } + + /* if log file name was not given or the log could not be create with + given name, create default log */ + if(!log) + { + log = axutil_log_create_default(allocator); + } + + thread_pool = axutil_thread_pool_init(allocator); + + env = axutil_env_create_with_error_log_thread_pool(allocator, error, log, thread_pool); + if(env->log) + { + if(AXIS2_LOG_LEVEL_CRITICAL <= log_level && log_level <= AXIS2_LOG_LEVEL_TRACE) + { + env->log->level = log_level; + } + else + { + env->log->level = AXIS2_LOG_LEVEL_DEBUG; /* default log level is debug */ + } + } + + env->ref = 1; + env->get_session_fn = NULL; + env->set_session_fn = NULL; + + return env; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_env_check_status( + const axutil_env_t *env) +{ + if(env && env->error) + return AXIS2_ERROR_GET_STATUS_CODE(env->error); + + return AXIS2_CRITICAL_FAILURE; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_env_enable_log( + axutil_env_t *env, + axis2_bool_t enable) +{ + if(env) + { + env->log_enabled = enable; + return AXIS2_SUCCESS; + } + + return AXIS2_CRITICAL_FAILURE; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_env_free( + axutil_env_t *env) +{ + axutil_allocator_t *allocator = NULL; + + if(!env) + return; + + if(--(env->ref) > 0) + { + return; + } + + allocator = env->allocator; + + if(env->log) + { + AXIS2_LOG_FREE(env->allocator, env->log); + } + + if(env->error) + { + AXIS2_ERROR_FREE(env->error); + } + + if(env->thread_pool) + { + axutil_thread_pool_free(env->thread_pool); + } + + if(env->allocator) + { + AXIS2_FREE(env->allocator, env); + } + + if(allocator) + { + AXIS2_FREE(allocator, allocator); + } + + return; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_env_free_masked( + axutil_env_t *env, + char mask) +{ + if(!env) + return; + + if(--(env->ref) > 0) + { + return; + } + + if(mask & AXIS_ENV_FREE_LOG) + { + AXIS2_LOG_FREE(env->allocator, env->log); + } + + if(mask & AXIS_ENV_FREE_ERROR) + { + AXIS2_ERROR_FREE(env->error); + } + + if(mask & AXIS_ENV_FREE_THREADPOOL) + { + axutil_thread_pool_free(env->thread_pool); + } + + if(env) + AXIS2_FREE(env->allocator, env); + + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_env_increment_ref( + axutil_env_t *env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + env->ref++; + return AXIS2_SUCCESS; +} + diff --git a/util/src/error.c b/util/src/error.c new file mode 100644 index 0000000..bb35d96 --- /dev/null +++ b/util/src/error.c @@ -0,0 +1,565 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <stdlib.h> +#include <string.h> +#include "axutil_error_default.h" + +#define AXIS2_ERROR_MESSAGE_ARRAY_SIZE AXUTIL_ERROR_MAX + +/** + * Array to hold error messages corresponding to the pre-defined error codes. + * Note that array has capacity for additional error messages. These are + * reserved for modules. + * + * TODO: We have to review and change the following definition and also + * need to come up with a reserve strategy for module error code blocks. + * + * In writing a module following steps must be followed in extending Axis2/C + * errors + * 1. Declare and register the start of error messages for the new + * module. + * 2. New module can use up to 1000 messages for its errors. + * 3. In axis2c documentation an entry about new modules error range must + * be inserted so that another new module can know about the already + * occupied spaces. + */ + +AXIS2_EXPORT const axis2_char_t* axutil_error_messages[AXIS2_ERROR_MESSAGE_ARRAY_SIZE]; + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_error_init() +{ + int i = 0; + for(i = 0; i < AXIS2_ERROR_MESSAGE_ARRAY_SIZE; i++) + { + axutil_error_messages[i] = "Unknown Error :("; + } + + /* Common Errors */ + axutil_error_messages[AXIS2_ERROR_NONE] = "No Error"; + axutil_error_messages[AXIS2_ERROR_NO_MEMORY] = "Out of memory"; + axutil_error_messages[AXIS2_ERROR_INVALID_NULL_PARAM] + = "NULL parameter was passed when a non NULL parameter was expected"; + /* core:addr */ + + /* core:clientapi */ + axutil_error_messages[AXIS2_ERROR_BLOCKING_INVOCATION_EXPECTS_RESPONSE] + = "Blocking invocation expects response"; + axutil_error_messages[AXIS2_ERROR_CANNOT_INFER_TRANSPORT] = "Cannot infer transport from URL"; + axutil_error_messages[AXIS2_ERROR_CLIENT_SIDE_SUPPORT_ONLY_ONE_CONF_CTX] + = "Client side support only one configuration context"; + axutil_error_messages[AXIS2_ERROR_MEP_CANNOT_BE_NULL_IN_MEP_CLIENT] + = "MEP cannot be NULL in MEP client"; + axutil_error_messages[AXIS2_ERROR_MEP_MISMATCH_IN_MEP_CLIENT] = "MEP mismatch"; + axutil_error_messages[AXIS2_ERROR_TWO_WAY_CHANNEL_NEEDS_ADDRESSING] + = "Two way channel needs addressing module to be engaged"; + axutil_error_messages[AXIS2_ERROR_UNKNOWN_TRANSPORT] = "Unknown transport"; + axutil_error_messages[AXIS2_ERROR_UNSUPPORTED_TYPE] = "Type is not supported"; + axutil_error_messages[AXIS2_ERROR_OPTIONS_OBJECT_IS_NOT_SET] = "Options object is not set"; + axutil_error_messages[AXIS2_ERROR_SESSION_TIMEOUT] = "Session Timeout"; + /* core:clientapi:diclient */ + + /* core:context */ + axutil_error_messages[AXIS2_ERROR_INVALID_SOAP_ENVELOPE_STATE] = "Invalid SOAP envelope state"; + axutil_error_messages[AXIS2_ERROR_INVALID_STATE_MSG_CTX] = "Invalid message context state"; + axutil_error_messages[AXIS2_ERROR_INVALID_STATE_SVC] = "Service accessed has invalid state"; + axutil_error_messages[AXIS2_ERROR_INVALID_STATE_SVC_GRP] + = "Service group accessed has invalid state"; + axutil_error_messages[AXIS2_ERROR_SERVICE_NOT_YET_FOUND] = "Service not yet found"; + /* core:deployment */ + axutil_error_messages[AXI2_ERROR_INVALID_PHASE] = "Invalid phase found in phase validation*"; + axutil_error_messages[AXIS2_ERROR_CONFIG_NOT_FOUND] = "Configuration file cannot be found"; + axutil_error_messages[AXIS2_ERROR_DATA_ELEMENT_IS_NULL] = "Data element of the OM Node is NULL"; + axutil_error_messages[AXIS2_ERROR_IN_FLOW_NOT_ALLOWED_IN_TRS_OUT] + = "In transport sender, Inflow is not allowed"; + axutil_error_messages[AXIS2_ERROR_INVALID_HANDLER_STATE] = "Invalid handler state"; + axutil_error_messages[AXIS2_ERROR_INVALID_MODUELE_REF] = "Invalid module reference encountered"; + axutil_error_messages[AXIS2_ERROR_INVALID_MODUELE_REF_BY_OP] + = "Invalid module referenced by operation"; + axutil_error_messages[AXIS2_ERROR_INVALID_MODULE_CONF] = "Invalid module configuration"; + axutil_error_messages[AXIS2_ERROR_INVALID_STATE_DESC_BUILDER] + = "Description builder is found to be in invalid state"; + axutil_error_messages[AXIS2_ERROR_MODULE_NOT_FOUND] = "Module not found"; + axutil_error_messages[AXIS2_ERROR_MODULE_VALIDATION_FAILED] = "Module validation failed"; + axutil_error_messages[AXIS2_ERROR_MODULE_XML_NOT_FOUND_FOR_THE_MODULE] + = "Module XML file is not found in the given path"; + axutil_error_messages[AXIS2_ERROR_NO_DISPATCHER_FOUND] = "No dispatcher found"; + axutil_error_messages[AXIS2_ERROR_OP_NAME_MISSING] = "Operation name is missing"; + axutil_error_messages[AXIS2_ERROR_OUT_FLOW_NOT_ALLOWED_IN_TRS_IN] + = "In transport receiver, outflow is not allowed"; + axutil_error_messages[AXIS2_ERROR_REPO_CAN_NOT_BE_NULL] = "Repository name cannot be NULL"; + axutil_error_messages[AXIS2_ERROR_REPOSITORY_NOT_EXIST] = "Repository in path does not exist"; + axutil_error_messages[AXIS2_ERROR_REPOS_LISTENER_INIT_FAILED] + = "Repository listener initialization failed"; + axutil_error_messages[AXIS2_ERROR_SERVICE_XML_NOT_FOUND] + = "Service XML file is not found in the given path"; + axutil_error_messages[AXIS2_ERROR_SVC_NAME_ERROR] = "Service name error"; + axutil_error_messages[AXIS2_ERROR_TRANSPORT_SENDER_ERROR] = "Transport sender error"; + axutil_error_messages[AXIS2_PATH_TO_CONFIG_CAN_NOT_BE_NULL] + = "Path to configuration file can not be NULL"; + axutil_error_messages[AXIS2_ERROR_INVALID_SVC] = "Invalid service"; + /* core:description */ + axutil_error_messages[AXIS2_ERROR_CANNOT_CORRELATE_MSG] = "Cannot correlate message"; + axutil_error_messages[AXIS2_ERROR_COULD_NOT_MAP_MEP_URI_TO_MEP_CONSTANT] + = "Could not map the MEP URI to an Axis2/C MEP constant value"; + axutil_error_messages[AXIS2_ERROR_INVALID_MESSAGE_ADDITION] + = "Invalid message addition operation context completed"; + axutil_error_messages[AXIS2_ERROR_INVALID_STATE_MODULE_DESC] + = "Module description accessed has invalid state"; + axutil_error_messages[AXIS2_ERROR_INVALID_STATE_PARAM_CONTAINER] + = "Parameter container not set"; + axutil_error_messages[AXIS2_ERROR_MODULE_ALREADY_ENGAGED_TO_OP] + = "Module has already been engaged to the operation"; + axutil_error_messages[AXIS2_ERROR_MODULE_ALREADY_ENGAGED_TO_SVC] + = "Module has already been engaged on the service."; + axutil_error_messages[AXIS2_ERROR_MODULE_ALREADY_ENGAGED_TO_SVC_GRP] + = "Module has already been engaged on the service."; + axutil_error_messages[AXIS2_ERROR_PARAMETER_LOCKED_CANNOT_OVERRIDE] + = "Parameter locked, cannot override"; + axutil_error_messages[AXIS2_ERROR_EMPTY_SCHEMA_LIST] + = "Schema list is empty or NULL in service"; + /* core:engine */ + axutil_error_messages[AXIS2_ERROR_BEFORE_AFTER_HANDLERS_SAME] + = "Both before and after handlers cannot be the same"; + axutil_error_messages[AXIS2_ERROR_INVALID_HANDLER_RULES] = "Invalid handler rules"; + axutil_error_messages[AXIS2_ERROR_INVALID_MODULE] = "Invalid module"; + axutil_error_messages[AXIS2_ERROR_INVALID_PHASE_FIRST_HANDLER] + = "Invalid first handler for phase"; + axutil_error_messages[AXIS2_ERROR_INVALID_PHASE_LAST_HANDLER] + = "Invalid last handler for phase"; + axutil_error_messages[AXIS2_ERROR_INVALID_STATE_CONF] = "Invalid engine configuration state"; + axutil_error_messages[AXIS2_ERROR_INVALID_STATE_PROCESSING_FAULT_ALREADY] + = "Message context processing a fault already"; + axutil_error_messages[AXIS2_ERROR_NOWHERE_TO_SEND_FAULT] + = "fault to field not specified in message context"; + axutil_error_messages[AXIS2_ERROR_PHASE_ADD_HANDLER_INVALID] + = "Only one handler allowed for phase, adding another handler is not allowed"; + axutil_error_messages[AXIS2_ERROR_PHASE_FIRST_HANDLER_ALREADY_SET] + = "First handler of phase already set"; + axutil_error_messages[AXIS2_ERROR_PHASE_LAST_HANDLER_ALREADY_SET] + = "Last handler of phase already set"; + axutil_error_messages[AXIS2_ERROR_TWO_SVCS_CANNOT_HAVE_SAME_NAME] + = "Two service can not have same name, a service with same name already"; + /* core:phaseresolver */ + axutil_error_messages[AXIS2_ERROR_INVALID_MODULE_REF] = "Invalid module reference"; + axutil_error_messages[AXIS2_ERROR_INVALID_PHASE] = "Invalid Phase"; + axutil_error_messages[AXIS2_ERROR_NO_TRANSPORT_IN_CONFIGURED] + = "There are no in transport chains configured"; + axutil_error_messages[AXIS2_ERROR_NO_TRANSPORT_OUT_CONFIGURED] + = "There are no out transport chains configured"; + axutil_error_messages[AXIS2_ERROR_PHASE_IS_NOT_SPECIFED] = "Phase is not specified"; + axutil_error_messages[AXIS2_ERROR_SERVICE_MODULE_CAN_NOT_REFER_GLOBAL_PHASE] + = "Service module can not refer global phase"; + /* core:wsdl */ + axutil_error_messages[AXIS2_ERROR_WSDL_SCHEMA_IS_NULL] = "Schema is NULL"; + /* core:receivers */ + axutil_error_messages[AXIS2_ERROR_OM_ELEMENT_INVALID_STATE] = "AXIOM element has invalid state"; + axutil_error_messages[AXIS2_ERROR_OM_ELEMENT_MISMATCH] = "AXIOM elements do not match"; + axutil_error_messages[AXIS2_ERROR_RPC_NEED_MATCHING_CHILD] + = "RPC style SOAP body don't have a child element"; + axutil_error_messages[AXIS2_ERROR_UNKNOWN_STYLE] + = "Operation description has unknown operation style"; + axutil_error_messages[AXIS2_ERROR_STRING_DOES_NOT_REPRESENT_A_VALID_NC_NAME] + = "String does not represent a valid NCName"; + /* core:transport */ + + /* core:transport:http */ + axutil_error_messages[AXIS2_ERROR_HTTP_CLIENT_TRANSPORT_ERROR] = "Error occurred in transport"; + axutil_error_messages[AXIS2_ERROR_HTTP_REQUEST_NOT_SENT] + = "A read attempt(HTTP) for the reply without sending the request"; + axutil_error_messages[AXIS2_ERROR_INVALID_HEADER] = "Invalid string passed as a HTTP header"; + axutil_error_messages[AXIS2_ERROR_INVALID_HTTP_HEADER_START_LINE] + = "Invalid status line or invalid request line"; + axutil_error_messages[AXIS2_ERROR_INVALID_TRANSPORT_PROTOCOL] + = "Transport protocol is unsupported by axis2"; + axutil_error_messages[AXIS2_ERROR_NULL_BODY] = "No body present in the request or the response"; + axutil_error_messages[AXIS2_ERROR_NULL_CONFIGURATION_CONTEXT] + = "A valid configuration context is required for the HTTP worker"; + axutil_error_messages[AXIS2_ERROR_NULL_HTTP_VERSION] + = "HTTP version cannot be NULL in the status/request line"; + axutil_error_messages[AXIS2_ERROR_NULL_IN_STREAM_IN_MSG_CTX] + = "Input stream is NULL in message context"; + axutil_error_messages[AXIS2_ERROR_NULL_OM_OUTPUT] = "OM output is NULL"; + axutil_error_messages[AXIS2_ERROR_NULL_SOAP_ENVELOPE_IN_MSG_CTX] + = "NULL SOAP envelope in message context"; + axutil_error_messages[AXIS2_ERROR_NULL_STREAM_IN_CHUNKED_STREAM] + = "NULL stream in the HTTP chucked stream"; + axutil_error_messages[AXIS2_ERROR_NULL_STREAM_IN_RESPONSE_BODY] + = "NULL stream in the response body"; + axutil_error_messages[AXIS2_ERROR_NULL_URL] = "URL NULL in HTTP client"; + axutil_error_messages[AXIS2_ERROR_OUT_TRNSPORT_INFO_NULL] + = "Transport information must be set in message context"; + axutil_error_messages[AXIS2_ERROR_RESPONSE_CONTENT_TYPE_MISSING] + = "Content-Type header missing in HTTP response"; + axutil_error_messages[AXIS2_ERROR_RESPONSE_TIMED_OUT] = "Response timed out"; + axutil_error_messages[AXIS2_ERROR_SOAP_ENVELOPE_OR_SOAP_BODY_NULL] + = "SOAP envelope or SOAP body NULL"; + axutil_error_messages[AXIS2_ERROR_SSL_ENGINE] = "Error occurred in SSL engine"; + axutil_error_messages[AXIS2_ERROR_SSL_NO_CA_FILE] = "Cannot find certificates"; + axutil_error_messages[AXIS2_ERROR_WRITING_RESPONSE] + = "Error in writing the response in response writer"; + axutil_error_messages[AXIS2_ERROR_REQD_PARAM_MISSING] + = "Required parameter is missing in URL encoded request"; + axutil_error_messages[AXIS2_ERROR_UNSUPPORTED_SCHEMA_TYPE] = " Unsupported schema type in REST"; + axutil_error_messages[AXIS2_ERROR_SVC_OR_OP_NOT_FOUND] = "Service or operation not found"; + /* mod_addr */ + axutil_error_messages[AXIS2_ERROR_NO_MSG_INFO_HEADERS] = "No messgae info headers"; + /* platforms */ + + /* utils */ + axutil_error_messages[AXIS2_ERROR_COULD_NOT_OPEN_FILE] = "Could not open the file"; + axutil_error_messages[AXIS2_ERROR_DLL_CREATE_FAILED] = "Failed in creating DLL"; + axutil_error_messages[AXIS2_ERROR_DLL_LOADING_FAILED] = "DLL loading failed"; + axutil_error_messages[AXIS2_ERROR_ENVIRONMENT_IS_NULL] = "Environment passed is NULL"; + axutil_error_messages[AXIS2_ERROR_FILE_NAME_NOT_SET] = "Axis2 File does not have a file name"; + axutil_error_messages[AXIS2_ERROR_INVALID_STATE_DLL_DESC] + = "DLL description has invalid state of not having valid DLL create function, \ + of valid delete function or valid dll_handler"; + axutil_error_messages[AXIS2_ERROR_HANDLER_CREATION_FAILED] = "Failed in creating Handler"; + axutil_error_messages[AXIS2_ERROR_INDEX_OUT_OF_BOUNDS] = "Array list index out of bounds"; + axutil_error_messages[AXIS2_ERROR_INVALID_ADDRESS] = "Invalid IP or hostname"; + axutil_error_messages[AXIS2_ERROR_INVALID_FD] + = "Trying to do operation on invalid file descriptor"; + axutil_error_messages[AXIS2_ERROR_INVALID_SOCKET] + = "Trying to do operation on closed/not opened socket"; + axutil_error_messages[AXIS2_ERROR_INVALID_STATE_PARAM] = "Parameter not set"; + axutil_error_messages[AXIS2_ERROR_MODULE_CREATION_FAILED] = "Module create failed"; + axutil_error_messages[AXIS2_ERROR_MSG_RECV_CREATION_FAILED] + = "Failed in creating Message Receiver"; + axutil_error_messages[AXIS2_ERROR_NO_SUCH_ELEMENT] = "No such element"; + axutil_error_messages[AXIS2_ERROR_SOCKET_BIND_FAILED] + = "Socket bind failed. Another process may be already using this port"; + axutil_error_messages[AXIS2_ERROR_SOCKET_ERROR] + = "Error creating a socket. Most probably error returned by OS"; + axutil_error_messages[AXIS2_ERROR_SOCKET_LISTEN_FAILED] = "Listen failed for the server socket"; + axutil_error_messages[AXIS2_ERROR_SVC_SKELETON_CREATION_FAILED] + = "Failed in creating Service Skeleton"; + axutil_error_messages[AXIS2_ERROR_TRANSPORT_RECV_CREATION_FAILED] + = "Failed in creating Transport Receiver"; + axutil_error_messages[AXIS2_ERROR_TRANSPORT_SENDER_CREATION_FAILED] + = "Failed in creating Transport Sender"; + axutil_error_messages[AXIS2_ERROR_UUID_GEN_FAILED] + = "Generation of platform dependent UUID failed"; + axutil_error_messages[AXIS2_ERROR_POSSIBLE_DEADLOCK] = "Possible deadlock"; + /* WSDL */ + axutil_error_messages[AXIS2_ERROR_INTERFACE_OR_PORT_TYPE_NOT_FOUND_FOR_THE_BINDING] + = "Interface or Port Type not found for the binding"; + axutil_error_messages[AXIS2_ERROR_INTERFACES_OR_PORTS_NOT_FOUND_FOR_PARTIALLY_BUILT_WOM] + = "Interfaces or Ports not found for the partially built WOM"; + axutil_error_messages[AXIS2_ERROR_INVALID_STATE_WSDL_OP] + = "WSDL operation accessed has invalid state"; + axutil_error_messages[AXIS2_ERROR_INVALID_STATE_WSDL_SVC] + = "WSDL Service accessed has invalid state"; + axutil_error_messages[AXIS2_ERROR_MEP_CANNOT_DETERMINE_MEP] = "Cannot determine MEP"; + axutil_error_messages[AXIS2_ERROR_WSDL_BINDING_NAME_IS_REQUIRED] + = "WSDL binding name is cannot be NULL"; + axutil_error_messages[AXIS2_ERROR_WSDL_INTERFACE_NAME_IS_REQUIRED] + = "PortType/Interface name cannot be NULL"; + axutil_error_messages[AXIS2_ERROR_WSDL_PARSER_INVALID_STATE] + = "WSDL parsing has resulted in an invalid state"; + axutil_error_messages[AXIS2_ERROR_WSDL_SVC_NAME_IS_REQUIRED] + = "WSDL service name cannot be NULL"; + /* XML */ + + /* XML:attachments */ + axutil_error_messages[AXIS2_ERROR_ATTACHMENT_MISSING] = "Attachment is missing"; + /* XML:om */ + axutil_error_messages[AXIS2_ERROR_BUILDER_DONE_CANNOT_PULL] + = "XML builder done with pulling. Pull parser cannot pull any more"; + axutil_error_messages[AXIS2_ERROR_INVALID_BUILDER_STATE_CANNOT_DISCARD] + = "Discard failed because the builder state is invalid"; + axutil_error_messages[AXIS2_ERROR_INVALID_BUILDER_STATE_LAST_NODE_NULL] + = "Invalid builder state; Builder's last node is NULL"; + axutil_error_messages[AXIS2_ERROR_INVALID_DOCUMENT_STATE_ROOT_NULL] + = "Invalid document state; Document root is NULL"; + axutil_error_messages[AXIS2_ERROR_INVALID_DOCUMENT_STATE_UNDEFINED_NAMESPACE] + = "Undefined namespace used"; + axutil_error_messages[AXIS2_ERROR_INVALID_EMPTY_NAMESPACE_URI] + = "Namespace should have a valid URI"; + axutil_error_messages[AXIS2_ERROR_ITERATOR_NEXT_METHOD_HAS_NOT_YET_BEEN_CALLED] + = "Next method has not been called so cannot remove" + "an element before calling next valid for any om iterator"; + axutil_error_messages[AXIS2_ERROR_ITERATOR_REMOVE_HAS_ALREADY_BEING_CALLED] + = "Document root is NULL, when it is not supposed to be NULL"; + axutil_error_messages[AXIS2_ERROR_XML_READER_ELEMENT_NULL] + = "AXIOM XML reader returned NULL element"; + axutil_error_messages[AXIS2_ERROR_XML_READER_VALUE_NULL] + = "AXIOM XML reader returned NULL value"; + /* XML:parser */ + axutil_error_messages[AXIS2_ERROR_CREATING_XML_STREAM_READER] + = "Error occurred creating XML stream reader"; + axutil_error_messages[AXIS2_ERROR_CREATING_XML_STREAM_WRITER] + = "Error occurred creating XML stream writer"; + axutil_error_messages[AXIS2_ERROR_WRITING_ATTRIBUTE] = "Error in writing attribute"; + axutil_error_messages[AXIS2_ERROR_WRITING_ATTRIBUTE_WITH_NAMESPACE] + = "Error in writing attribute with namespace"; + axutil_error_messages[AXIS2_ERROR_WRITING_ATTRIBUTE_WITH_NAMESPACE_PREFIX] + = "Error in writing attribute with namespace prefix"; + axutil_error_messages[AXIS2_ERROR_WRITING_COMMENT] = "Error in writing comment"; + axutil_error_messages[AXIS2_ERROR_WRITING_DATA_SOURCE] = "Error in writing data source"; + axutil_error_messages[AXIS2_ERROR_WRITING_DEFAULT_NAMESPACE] + = "Error in writing default namespace"; + axutil_error_messages[AXIS2_ERROR_WRITING_DTD] = "Error in writing DDT"; + axutil_error_messages[AXIS2_ERROR_WRITING_EMPTY_ELEMENT] + = "Error occurred in writing empty element"; + axutil_error_messages[AXIS2_ERROR_WRITING_EMPTY_ELEMENT_WITH_NAMESPACE] + = "Error occurred in writing empty element with namespace"; + axutil_error_messages[AXIS2_ERROR_WRITING_EMPTY_ELEMENT_WITH_NAMESPACE_PREFIX] + = "Error in writing empty element with namespace prefix"; + axutil_error_messages[AXIS2_ERROR_WRITING_END_DOCUMENT] + = "Error occurred in writing end document in XML writer"; + axutil_error_messages[AXIS2_ERROR_WRITING_END_ELEMENT] + = "Error occurred in writing end element in XML writer"; + axutil_error_messages[AXIS2_ERROR_WRITING_PROCESSING_INSTRUCTION] + = "Error in writing processing instruction"; + axutil_error_messages[AXIS2_ERROR_WRITING_START_DOCUMENT] + = "Error occurred in writing start element in start document in XML writer"; + axutil_error_messages[AXIS2_ERROR_WRITING_START_ELEMENT] + = "Error occurred in writing start element in XML writer"; + axutil_error_messages[AXIS2_ERROR_WRITING_START_ELEMENT_WITH_NAMESPACE] + = "Error occurred in writing start element with namespace in XML writer"; + axutil_error_messages[AXIS2_ERROR_WRITING_START_ELEMENT_WITH_NAMESPACE_PREFIX] + = "Error occurred in writing start element with namespace prefix"; + axutil_error_messages[AXIS2_ERROR_WRITING_CDATA] = "Error in writing CDATA section"; + axutil_error_messages[AXIS2_ERROR_XML_PARSER_INVALID_MEM_TYPE] + = "AXIS2_XML_PARSER_TYPE_BUFFER or AXIS2_XML_PARSER_TYPE_DOC is expected"; + + /* invalid type passed */ + axutil_error_messages[AXIS2_ERROR_INVALID_BASE_TYPE] = "Invalid base type passed"; + axutil_error_messages[AXIS2_ERROR_INVALID_SOAP_NAMESPACE_URI] + = "Invalid SOAP namespace URI found"; + axutil_error_messages[AXIS2_ERROR_INVALID_SOAP_VERSION] = "Invalid SOAP version"; + axutil_error_messages[AXIS2_ERROR_INVALID_VALUE_FOUND_IN_MUST_UNDERSTAND] + = "Invalid value found in must understand"; + axutil_error_messages[AXIS2_ERROR_MULTIPLE_CODE_ELEMENTS_ENCOUNTERED] + = "Multiple fault code elements encountered in SOAP fault"; + axutil_error_messages[AXIS2_ERROR_MULTIPLE_DETAIL_ELEMENTS_ENCOUNTERED] + = "Multiple fault detail elements encountered in SOAP fault"; + axutil_error_messages[AXIS2_ERROR_MULTIPLE_NODE_ELEMENTS_ENCOUNTERED] + = "Multiple fault node elements encountered in SOAP fault"; + axutil_error_messages[AXIS2_ERROR_MULTIPLE_REASON_ELEMENTS_ENCOUNTERED] + = "Multiple fault reason elements encountered in SOAP fault"; + axutil_error_messages[AXIS2_ERROR_MULTIPLE_ROLE_ELEMENTS_ENCOUNTERED] + = "Multiple fault role elements encountered in SOAP fault "; + axutil_error_messages[AXIS2_ERROR_MULTIPLE_SUB_CODE_VALUES_ENCOUNTERED] + = "Multiple fault sub-code value elements encountered"; + axutil_error_messages[AXIS2_ERROR_MULTIPLE_VALUE_ENCOUNTERED_IN_CODE_ELEMENT] + = "Multiple fault value elements encountered"; + axutil_error_messages[AXIS2_ERROR_MUST_UNDERSTAND_SHOULD_BE_1_0_TRUE_FALSE] + = "Must understand attribute should have a value of either true or false"; + axutil_error_messages[AXIS2_ERROR_OM_ELEMENT_EXPECTED] = "AXIOM element is expected"; + axutil_error_messages[AXIS2_ERROR_ONLY_CHARACTERS_ARE_ALLOWED_HERE] + = "Processing SOAP 1.1 fault value element should have only" + "text as its children"; + axutil_error_messages[AXIS2_ERROR_ONLY_ONE_SOAP_FAULT_ALLOWED_IN_BODY] + = "Only one SOAP fault is allowed in SOAP body"; + axutil_error_messages[AXIS2_ERROR_SOAP11_FAULT_ACTOR_SHOULD_NOT_HAVE_CHILD_ELEMENTS] + = "SOAP 1.1 fault actor should not have any child elements"; + axutil_error_messages[AXIS2_ERROR_SOAP_BUILDER_ENVELOPE_CAN_HAVE_ONLY_HEADER_AND_BODY] + = "SOAP builder found a child element other than header or body in envelope" + "element"; + axutil_error_messages[AXIS2_ERROR_SOAP_BUILDER_HEADER_BODY_WRONG_ORDER] + = "SOAP builder encountered body element first and header next"; + axutil_error_messages[AXIS2_ERROR_SOAP_BUILDER_MULTIPLE_BODY_ELEMENTS_ENCOUNTERED] + = "SOAP builder multiple body elements encountered"; + axutil_error_messages[AXIS2_ERROR_SOAP_BUILDER_MULTIPLE_HEADERS_ENCOUNTERED] + = "SOAP builder encountered multiple headers"; + axutil_error_messages[AXIS2_ERROR_SOAP_FAULT_CODE_DOES_NOT_HAVE_A_VALUE] + = "SOAP fault code does not have a value"; + axutil_error_messages[AXIS2_ERROR_SOAP_FAULT_REASON_ELEMENT_SHOULD_HAVE_A_TEXT] + = "SOAP fault reason element should have a text value"; + axutil_error_messages[AXIS2_ERROR_SOAP_FAULT_ROLE_ELEMENT_SHOULD_HAVE_A_TEXT] + = "SOAP fault role element should have a text value"; + axutil_error_messages[AXIS2_ERROR_SOAP_FAULT_VALUE_SHOULD_BE_PRESENT_BEFORE_SUB_CODE] + = "SOAP fault value should be present before sub-code element in SOAP fault code"; + axutil_error_messages[AXIS2_ERROR_SOAP_MESSAGE_DOES_NOT_CONTAIN_AN_ENVELOPE] + = "SOAP message does not contain a SOAP envelope element"; + axutil_error_messages[AXIS2_ERROR_SOAP_MESSAGE_FIRST_ELEMENT_MUST_CONTAIN_LOCAL_NAME] + = "SOAP message's first element should have a localname"; + axutil_error_messages[AXIS2_ERROR_THIS_LOCALNAME_IS_NOT_SUPPORTED_INSIDE_THE_REASON_ELEMENT] + = "Localname not supported inside a reason element"; + axutil_error_messages[AXIS2_ERROR_THIS_LOCALNAME_IS_NOT_SUPPORTED_INSIDE_THE_SUB_CODE_ELEMENT] + = "Localname not supported inside the sub-code element"; + axutil_error_messages[AXIS2_ERROR_THIS_LOCALNAME_NOT_SUPPORTED_INSIDE_THE_CODE_ELEMENT] + = "Localname not supported inside the code element"; + axutil_error_messages[AXIS2_ERROR_TRANSPORT_LEVEL_INFORMATION_DOES_NOT_MATCH_WITH_SOAP] + = "Transport identified SOAP version does not match with SOAP message version"; + axutil_error_messages[AXIS2_ERROR_UNSUPPORTED_ELEMENT_IN_SOAP_FAULT_ELEMENT] + = "Unsupported element found in SOAP fault element"; + axutil_error_messages[AXIS2_ERROR_WRONG_ELEMENT_ORDER_ENCOUNTERED] + = "Wrong element order encountered "; + /* services */ + axutil_error_messages[AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST] + = "Invalid XML format in request"; + axutil_error_messages[AXIS2_ERROR_SVC_SKEL_INPUT_OM_NODE_NULL] + = "Input OM node NULL, Probably error in SOAP request"; + axutil_error_messages[AXIS2_ERROR_SVC_SKEL_INVALID_OPERATION_PARAMETERS_IN_SOAP_REQUEST] + = "Invalid parameters for service operation in SOAP request"; + + axutil_error_messages[AXIS2_ERROR_WSDL_SCHEMA_IS_NULL] = "Schema is NULL"; + + /* repos */ + axutil_error_messages[AXIS2_ERROR_REPOS_NOT_AUTHENTICATED] = "Not authenticated"; + axutil_error_messages[AXIS2_ERROR_REPOS_UNSUPPORTED_MODE] = "Unsupported mode"; + axutil_error_messages[AXIS2_ERROR_REPOS_EXPIRED] = "Expired"; + axutil_error_messages[AXIS2_ERROR_REPOS_NOT_IMPLEMENTED] = "Not implemented"; + axutil_error_messages[AXIS2_ERROR_REPOS_NOT_FOUND] = "Not found"; + axutil_error_messages[AXIS2_ERROR_REPOS_BAD_SEARCH_TEXT] = "Bad search text"; + + /* neethi */ + axutil_error_messages[AXIS2_ERROR_NEETHI_ELEMENT_WITH_NO_NAMESPACE] + = "Element with no namespace"; + axutil_error_messages[AXIS2_ERROR_NEETHI_POLICY_CREATION_FAILED_FROM_ELEMENT] + = "Policy creation failed from element"; + axutil_error_messages[AXIS2_ERROR_NEETHI_ALL_CREATION_FAILED_FROM_ELEMENT] + = "All creation failed from element"; + axutil_error_messages[AXIS2_ERROR_NEETHI_EXACTLYONE_CREATION_FAILED_FROM_ELEMENT] + = "Exactly one creation failed from element"; + axutil_error_messages[AXIS2_ERROR_NEETHI_REFERENCE_CREATION_FAILED_FROM_ELEMENT] + = "Reference creation failed from element"; + axutil_error_messages[AXIS2_ERROR_NEETHI_ASSERTION_CREATION_FAILED_FROM_ELEMENT] + = "Assertion creation failed from element"; + axutil_error_messages[AXIS2_ERROR_NEETHI_ALL_CREATION_FAILED] = "All creation failed"; + axutil_error_messages[AXIS2_ERROR_NEETHI_EXACTLYONE_CREATION_FAILED] + = "Exactly one creation failed"; + axutil_error_messages[AXIS2_ERROR_NEETHI_POLICY_CREATION_FAILED] = "Policy creation failed"; + axutil_error_messages[AXIS2_ERROR_NEETHI_NORMALIZATION_FAILED] = "Normalization failed"; + axutil_error_messages[AXIS2_ERROR_NEETHI_WRONG_INPUT_FOR_MERGE] = "Wrong input for merge"; + axutil_error_messages[AXIS2_ERROR_NEETHI_CROSS_PRODUCT_FAILED] = "Cross product failed"; + axutil_error_messages[AXIS2_ERROR_NEETHI_NO_CHILDREN_POLICY_COMPONENTS] + = "No children policy components"; + axutil_error_messages[AXIS2_ERROR_NEETHI_URI_NOT_SPECIFIED] = "Reference URI not specified"; + axutil_error_messages[AXIS2_ERROR_NEETHI_NO_ENTRY_FOR_THE_GIVEN_URI] + = "No entry for the given URI"; + axutil_error_messages[AXIS2_ERROR_NEETHI_EXACTLYONE_NOT_FOUND_IN_NORMALIZED_POLICY] + = "Exactly one not found in normalized policy"; + axutil_error_messages[AXIS2_ERROR_NEETHI_EXACTLYONE_IS_EMPTY] = "Exactly one is empty"; + axutil_error_messages[AXIS2_ERROR_NEETHI_ALL_NOT_FOUND_WHILE_GETTING_CROSS_PRODUCT] + = "All not found while getting cross product"; + axutil_error_messages[AXIS2_ERROR_NEETHI_UNKNOWN_ASSERTION] = "Unknown Assertion"; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axutil_error_t *AXIS2_CALL +axutil_error_create( + axutil_allocator_t * allocator) +{ + axutil_error_t *error; + if(!allocator) + return NULL; + + error = (axutil_error_t *)AXIS2_MALLOC(allocator, sizeof(axutil_error_t)); + memset(error, 0, sizeof(axutil_error_t)); + + if(!error) + return NULL; + + error->allocator = allocator; + error->status_code = AXIS2_SUCCESS; + + return error; +} + +AXIS2_EXTERN const axis2_char_t *AXIS2_CALL +axutil_error_get_message( + const axutil_error_t * error) +{ + const axis2_char_t *message = NULL; + if(error) + { + if(error->error_number > AXIS2_ERROR_NONE && error->error_number < AXUTIL_ERROR_MAX) /* TODO; This needs to be + fixed to include module defined and user defined errors */ + message = axutil_error_messages[error->error_number]; + else + { + if(error->message) + { + message = error->message; + } + else if(error->error_number == AXIS2_ERROR_NONE) + { + message = axutil_error_messages[AXIS2_ERROR_NONE]; + } + else + { + message = "Undefined error returned by business logic implementation"; + } + } + } + + return message; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_error_set_error_number( + axutil_error_t * error, + axutil_error_codes_t error_number) +{ + if(!error) + return AXIS2_FAILURE; + error->error_number = error_number; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_error_set_status_code( + axutil_error_t * error, + axis2_status_codes_t status_code) +{ + if(!error) + return AXIS2_FAILURE; + error->status_code = status_code; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_error_get_status_code( + axutil_error_t * error) +{ + if(error) + return error->status_code; + else + return AXIS2_CRITICAL_FAILURE; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_error_set_error_message( + axutil_error_t * error, + axis2_char_t * message) +{ + if(message && error) + { + error->message = message; + return AXIS2_SUCCESS; + } + + return AXIS2_FAILURE; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_error_free( + axutil_error_t * error) +{ + if(error) + { + AXIS2_FREE(error->allocator, error); + } + return; +} + diff --git a/util/src/file.c b/util/src/file.c new file mode 100644 index 0000000..2ecd2d4 --- /dev/null +++ b/util/src/file.c @@ -0,0 +1,188 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_file.h> +#include <axutil_string.h> + +struct axutil_file +{ + axis2_char_t *name; + axis2_char_t *path; + AXIS2_TIME_T timestamp; +}; + +AXIS2_EXTERN axutil_file_t *AXIS2_CALL +axutil_file_create( + const axutil_env_t *env) +{ + axutil_file_t *file = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + file = (axutil_file_t *)AXIS2_MALLOC(env->allocator, sizeof(axutil_file_t)); + + if(!file) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + file->name = NULL; + file->path = NULL; + file->timestamp = 0; + + return file; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_file_free( + axutil_file_t *file, + const axutil_env_t *env) +{ + if(file->name) + { + AXIS2_FREE(env->allocator, file->name); + } + + if(file->path) + { + AXIS2_FREE(env->allocator, file->path); + } + + if(file) + { + AXIS2_FREE(env->allocator, file); + } + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_file_set_name( + axutil_file_t *file, + const axutil_env_t *env, + axis2_char_t *name) +{ + AXIS2_PARAM_CHECK(env->error, name, AXIS2_FAILURE); + + if(file->name) + { + AXIS2_FREE(env->allocator, file->name); + file->name = NULL; + } + file->name = axutil_strdup(env, name); + if(!file->name) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_file_get_name( + axutil_file_t *file, + const axutil_env_t *env) +{ + if(!file->name) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_FILE_NAME_NOT_SET, AXIS2_FAILURE); + return NULL; + } + return (file->name); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_file_set_path( + axutil_file_t *file, + const axutil_env_t *env, + axis2_char_t *path) +{ + if(!path) + { + return AXIS2_SUCCESS; + } + + if(file->path) + { + AXIS2_FREE(env->allocator, file->path); + file->path = NULL; + } + file->path = axutil_strdup(env, path); + if(!(file->path)) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_file_get_path( + axutil_file_t *file, + const axutil_env_t *env) +{ + if(!(file->path)) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_FILE_NAME_NOT_SET, AXIS2_FAILURE); + return NULL; + } + + return (file->path); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_file_set_timestamp( + axutil_file_t *file, + const axutil_env_t *env, + AXIS2_TIME_T timestamp) +{ + file->timestamp = timestamp; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN AXIS2_TIME_T AXIS2_CALL +axutil_file_get_timestamp( + axutil_file_t *file, + const axutil_env_t *env) +{ + return file->timestamp; +} + +AXIS2_EXTERN axutil_file_t *AXIS2_CALL +axutil_file_clone( + axutil_file_t *file, + const axutil_env_t *env) +{ + axutil_file_t *new_file = NULL; + axis2_status_t status = AXIS2_FAILURE; + new_file = axutil_file_create(env); + status = axutil_file_set_name(new_file, env, file->name); + if(AXIS2_SUCCESS != status) + { + return NULL; + } + status = axutil_file_set_path(new_file, env, file->path); + if(AXIS2_SUCCESS != status) + { + return NULL; + } + axutil_file_set_timestamp(new_file, env, file->timestamp); + return new_file; +} + diff --git a/util/src/file_handler.c b/util/src/file_handler.c new file mode 100644 index 0000000..61064c1 --- /dev/null +++ b/util/src/file_handler.c @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <string.h> +#include <stdlib.h> +#include <stdio.h> +#include <platforms/axutil_platform_auto_sense.h> +#include <sys/stat.h> + +#include <axutil_file_handler.h> + +AXIS2_EXTERN void *AXIS2_CALL +axutil_file_handler_open( + const axis2_char_t *file_name, + const axis2_char_t *options) +{ + FILE *file_ptr; + + if(!file_name) + return NULL; + + if(!options) + return NULL; + + file_ptr = fopen(file_name, options); + return file_ptr; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_file_handler_close( + void *file_ptr) +{ + int status = 0; + + if(!file_ptr) + return AXIS2_FAILURE; + + status = fclose(file_ptr); + + /*if successfully closed, it will return 0. otherwise EOF is returned */ + if(status != 0) + { + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_file_handler_access( + const axis2_char_t *path, + int mode) +{ + int i = 0; + axis2_status_t status = AXIS2_FAILURE; + i = AXIS2_ACCESS(path, mode); + if(0 == i) + { + status = AXIS2_SUCCESS; + } + else if(-1 == i) + { + status = AXIS2_FAILURE; + } + return status; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_file_handler_copy( + FILE *from, + FILE *to) +{ + axis2_char_t ch; + + /* It is assumed that source and destination files are accessible and open*/ + while(!feof(from)) + { + ch = (axis2_char_t)fgetc(from); + /* We are sure that the conversion is safe */ + if(ferror(from)) + { + /* Error reading source file */ + return AXIS2_FAILURE; + } + if(!feof(from)) + fputc(ch, to); + if(ferror(to)) + { + /* Error writing destination file */ + return AXIS2_FAILURE; + } + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN long AXIS2_CALL +axutil_file_handler_size( + const axis2_char_t * const name) +{ + struct stat stbuf; + if(stat(name, &stbuf) == -1) + { + /* The file could not be accessed */ + return AXIS2_FAILURE; + } + return stbuf.st_size; +} + diff --git a/util/src/generic_obj.c b/util/src/generic_obj.c new file mode 100644 index 0000000..883fcb1 --- /dev/null +++ b/util/src/generic_obj.c @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_generic_obj.h> + +struct axutil_generic_obj +{ + AXIS2_FREE_VOID_ARG free_func; + int type; + void *value; +}; + +AXIS2_EXTERN axutil_generic_obj_t *AXIS2_CALL +axutil_generic_obj_create( + const axutil_env_t *env) +{ + axutil_generic_obj_t *generic_obj = NULL; + AXIS2_ENV_CHECK(env, NULL); + + generic_obj + = (axutil_generic_obj_t *)AXIS2_MALLOC(env->allocator, sizeof(axutil_generic_obj_t)); + + if(!generic_obj) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + generic_obj->value = NULL; + generic_obj->free_func = 0; + + return generic_obj; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_generic_obj_free( + axutil_generic_obj_t *generic_obj, + const axutil_env_t *env) +{ + if(generic_obj->value) + { + if(generic_obj->free_func) + { + generic_obj->free_func(generic_obj->value, env); + } + else + { + AXIS2_FREE(env->allocator, generic_obj->value); + } + + } + + if(generic_obj) + { + AXIS2_FREE(env->allocator, generic_obj); + } + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_generic_obj_set_free_func( + axutil_generic_obj_t *generic_obj, + const axutil_env_t *env, + AXIS2_FREE_VOID_ARG free_func) +{ + generic_obj->free_func = free_func; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_generic_obj_set_value( + axutil_generic_obj_t *generic_obj, + const axutil_env_t *env, + void *value) +{ + generic_obj->value = value; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN void *AXIS2_CALL +axutil_generic_obj_get_value( + axutil_generic_obj_t *generic_obj, + const axutil_env_t *env) +{ + return generic_obj->value; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_generic_obj_set_type( + axutil_generic_obj_t *generic_obj, + const axutil_env_t *env, + int type) +{ + generic_obj->type = type; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_generic_obj_get_type( + axutil_generic_obj_t *generic_obj, + const axutil_env_t *env) +{ + return generic_obj->type; +} + diff --git a/util/src/hash.c b/util/src/hash.c new file mode 100644 index 0000000..77cea73 --- /dev/null +++ b/util/src/hash.c @@ -0,0 +1,671 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 "axutil_hash.h" + +#include <axutil_string.h> +#include <axutil_utils.h> + +/* + * The internal form of a hash table. + * + * The table is an array indexed by the hash of the key; collisions + * are resolved by hanging a linked list of hash entries off each + * element of the array. Although this is a really simple design it + * isn't too bad given that environments have a low allocation overhead. + */ + +typedef struct axutil_hash_entry_t axutil_hash_entry_t; + +struct axutil_hash_entry_t +{ + axutil_hash_entry_t *next; + unsigned int hash; + const void *key; + axis2_ssize_t klen; + const void *val; +}; + +/* + * Data structure for iterating through a hash table. + * We keep a pointer to the next hash entry here to allow the current + * hash entry to be freed or otherwise mangled between calls to + * axutil_hash_next(). + */ +struct axutil_hash_index_t +{ + axutil_hash_t *ht; + axutil_hash_entry_t *this, *next; + unsigned int index; +}; + +/* + * The size of the array is always a power of two. We use the maximum + * index rather than the size so that we can use bitwise-AND for + * modular arithmetic. + * The count of hash entries may be greater depending on the chosen + * collision rate. + */ +struct axutil_hash_t +{ + const axutil_env_t *env; + axutil_hash_entry_t **array; + axutil_hash_index_t iterator; /* For axutil_hash_first(NULL, ...) */ + unsigned int count; + unsigned int max; + axutil_hashfunc_t hash_func; + axutil_hash_entry_t *free; /* List of recycled entries */ +}; + +#define INITIAL_MAX 15 /* tunable == 2^n - 1 */ + +/* + * Hash creation functions. + */ + +static axutil_hash_entry_t ** +axutil_hash_alloc_array( + axutil_hash_t *ht, + unsigned int max) +{ + return memset(AXIS2_MALLOC(ht->env->allocator, sizeof(*ht->array) * (max + 1)), 0, + sizeof(*ht->array) * (max + 1)); +} + +AXIS2_EXTERN axutil_hash_t *AXIS2_CALL +axutil_hash_make( + const axutil_env_t *env) +{ + axutil_hash_t *ht; + AXIS2_ENV_CHECK(env, NULL); + + ht = AXIS2_MALLOC(env->allocator, sizeof(axutil_hash_t)); + if(!ht) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + axutil_env_increment_ref((axutil_env_t*)env); + ht->env = env; + ht->free = NULL; + ht->count = 0; + ht->max = INITIAL_MAX; + ht->array = axutil_hash_alloc_array(ht, ht->max); + ht->hash_func = axutil_hashfunc_default; + return ht; +} + +AXIS2_EXTERN axutil_hash_t *AXIS2_CALL +axutil_hash_make_custom( + const axutil_env_t *env, + axutil_hashfunc_t hash_func) +{ + axutil_hash_t *ht; + AXIS2_ENV_CHECK(env, NULL); + ht = axutil_hash_make(env); + if(ht) + { + ht->hash_func = hash_func; + } + return ht; +} + +/* + * Hash iteration functions. + */ + +AXIS2_EXTERN axutil_hash_index_t *AXIS2_CALL +axutil_hash_next( + const axutil_env_t *env, + axutil_hash_index_t *hi) +{ + hi->this = hi->next; + while(!hi->this) + { + if(hi->index > hi->ht->max) + { + if(env) + AXIS2_FREE(env->allocator, hi); + return NULL; + } + + hi->this = hi->ht->array[hi->index++]; + } + hi->next = hi->this->next; + return hi; +} + +AXIS2_EXTERN axutil_hash_index_t *AXIS2_CALL +axutil_hash_first( + axutil_hash_t *ht, + const axutil_env_t *env) +{ + axutil_hash_index_t *hi; + if(env) + hi = AXIS2_MALLOC(env->allocator, sizeof(*hi)); + else + hi = &ht->iterator; + + hi->ht = ht; + hi->index = 0; + hi->this = NULL; + hi->next = NULL; + return axutil_hash_next(env, hi); +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_hash_this( + axutil_hash_index_t *hi, + const void **key, + axis2_ssize_t *klen, + void **val) +{ + if(key) + *key = hi->this->key; + if(klen) + *klen = hi->this->klen; + if(val) + *val = (void *)hi->this->val; +} + +/* + * Expanding a hash table + */ + +static void +axutil_hash_expand_array( + axutil_hash_t *ht) +{ + axutil_hash_index_t *hi; + + axutil_hash_entry_t **new_array; + unsigned int new_max; + + new_max = ht->max * 2 + 1; + new_array = axutil_hash_alloc_array(ht, new_max); + for(hi = axutil_hash_first(ht, NULL); hi; hi = axutil_hash_next(NULL, hi)) + { + unsigned int i = hi->this->hash & new_max; + hi->this->next = new_array[i]; + new_array[i] = hi->this; + } + AXIS2_FREE(ht->env->allocator, ht->array); + ht->array = new_array; + ht->max = new_max; +} + +unsigned int +axutil_hashfunc_default( + const char *char_key, + axis2_ssize_t *klen) +{ + unsigned int hash = 0; + const unsigned char *key = (const unsigned char *)char_key; + const unsigned char *p; + axis2_ssize_t i; + + /* + * This is the popular `times 33' hash algorithm which is used by + * perl and also appears in Berkeley DB. This is one of the best + * known hash functions for strings because it is both computed + * very fast and distributes very well. + * + * The originator may be Dan Bernstein but the code in Berkeley DB + * cites Chris Torek as the source. The best citation I have found + * is "Chris Torek, Hash function for text in C, Usenet message + * <27038@mimsy.umd.edu> in comp.lang.c , October, 1990." in Rich + * Salz's USENIX 1992 paper about INN which can be found at + * <http://citeseer.nj.nec.com/salz92internetnews.html>. + * + * The magic of number 33, i.e. why it works better than many other + * constants, prime or not, has never been adequately explained by + * anyone. So I try an explanation: if one experimentally tests all + * multipliers between 1 and 256 (as I did while writing a low-level + * data structure library some time ago) one detects that even + * numbers are not useable at all. The remaining 128 odd numbers + * (except for the number 1) work more or less all equally well. + * They all distribute in an acceptable way and this way fill a hash + * table with an average percent of approx. 86%. + * + * If one compares the chi^2 values of the variants (see + * Bob Jenkins ``Hashing Frequently Asked Questions'' at + * http://burtleburtle.net/bob/hash/hashfaq.html for a description + * of chi^2), the number 33 not even has the best value. But the + * number 33 and a few other equally good numbers like 17, 31, 63, + * 127 and 129 have nevertheless a great advantage to the remaining + * numbers in the large set of possible multipliers: their multiply + * op can be replaced by a faster op based on just one + * shift plus either a single addition or subtraction op. And + * because a hash function has to both distribute good _and_ has to + * be very fast to compute, those few numbers should be preferred. + * + * -- Ralf S. Engelschall <rse@engelschall.com> + */ + + if(*klen == AXIS2_HASH_KEY_STRING) + { + for(p = key; *p; p++) + { + hash = hash * 33 + *p; + } + *klen = (axis2_ssize_t)(p - key); + /* We are sure that the difference lies within the axis2_ssize_t range */ + } + else + { + for(p = key, i = *klen; i; i--, p++) + { + hash = hash * 33 + *p; + } + } + + return hash; +} + +/* + * This is where we keep the details of the hash function and control + * the maximum collision rate. + * + * If val is non-NULL it creates and initializes a new hash entry if + * there isn't already one there; it returns an updatable pointer so + * that hash entries can be removed. + */ + +static axutil_hash_entry_t ** +axutil_hash_find_entry( + axutil_hash_t *ht, + const void *key, + axis2_ssize_t klen, + const void *val) +{ + axutil_hash_entry_t **hep, *he; + unsigned int hash; + + hash = ht->hash_func(key, &klen); + + /* scan linked list */ + for(hep = &ht->array[hash & ht->max], he = *hep; he; hep = &he->next, he = *hep) + { + if(he->hash == hash && he->klen == klen && memcmp(he->key, key, klen) == 0) + break; + } + + if(he || !val) + return hep; + + /* add a new entry for non-NULL values */ + he = ht->free; + if(he) + ht->free = he->next; + else + he = AXIS2_MALLOC(ht->env->allocator, sizeof(*he)); + he->next = NULL; + he->hash = hash; + he->key = key; + he->klen = klen; + he->val = val; + *hep = he; + ht->count++; + return hep; +} + +AXIS2_EXTERN axutil_hash_t *AXIS2_CALL +axutil_hash_copy( + const axutil_hash_t *orig, + const axutil_env_t *env) +{ + axutil_hash_t *ht; + axutil_hash_entry_t *new_vals; + unsigned int i, j; + + ht = AXIS2_MALLOC(env->allocator, sizeof(axutil_hash_t) + sizeof(*ht->array) * (orig->max + 1) + + sizeof(axutil_hash_entry_t) * orig->count); + ht->env = env; + axutil_env_increment_ref((axutil_env_t*)env); + ht->free = NULL; + ht->count = orig->count; + ht->max = orig->max; + ht->hash_func = orig->hash_func; + ht->array = (axutil_hash_entry_t **)((char *)ht + sizeof(axutil_hash_t)); + + new_vals = (axutil_hash_entry_t *)((char *)(ht) + sizeof(axutil_hash_t) + sizeof(*ht->array) + * (orig->max + 1)); + j = 0; + for(i = 0; i <= ht->max; i++) + { + axutil_hash_entry_t **new_entry = &(ht->array[i]); + axutil_hash_entry_t *orig_entry = orig->array[i]; + while(orig_entry) + { + *new_entry = &new_vals[j++]; + (*new_entry)->hash = orig_entry->hash; + (*new_entry)->key = orig_entry->key; + (*new_entry)->klen = orig_entry->klen; + (*new_entry)->val = orig_entry->val; + new_entry = &((*new_entry)->next); + orig_entry = orig_entry->next; + } + *new_entry = NULL; + } + return ht; +} + +AXIS2_EXTERN void *AXIS2_CALL +axutil_hash_get( + axutil_hash_t *ht, + const void *key, + axis2_ssize_t klen) +{ + axutil_hash_entry_t *he; + he = *axutil_hash_find_entry(ht, key, klen, NULL); + if(he) + return (void *)he->val; + else + return NULL; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_hash_set( + axutil_hash_t *ht, + const void *key, + axis2_ssize_t klen, + const void *val) +{ + axutil_hash_entry_t **hep; + hep = axutil_hash_find_entry(ht, key, klen, val); + if(*hep) + { + if(!val) + { + /* delete entry */ + axutil_hash_entry_t *old = *hep; + *hep = (*hep)->next; + old->next = ht->free; + ht->free = old; + --ht->count; + } + else + { + /* replace entry */ + (*hep)->val = val; + /* check that the collision rate isn't too high */ + if(ht->count > ht->max) + { + axutil_hash_expand_array(ht); + } + } + } + /* else key not present and val==NULL */ +} + +AXIS2_EXTERN unsigned int AXIS2_CALL +axutil_hash_count( + axutil_hash_t *ht) +{ + return ht->count; +} + +AXIS2_EXTERN axutil_hash_t *AXIS2_CALL +axutil_hash_overlay( + const axutil_hash_t *overlay, + const axutil_env_t *env, + const axutil_hash_t *base) +{ + return axutil_hash_merge(overlay, env, base, NULL, NULL); +} + +AXIS2_EXTERN axutil_hash_t *AXIS2_CALL +axutil_hash_merge( + const axutil_hash_t *overlay, + const axutil_env_t *env, + const axutil_hash_t *base, + void * + (*merger)( + const axutil_env_t *env, + const void *key, + axis2_ssize_t klen, + const void *h1_val, + const void *h2_val, + const void *data), + const void *data) +{ + axutil_hash_t *res; + axutil_hash_entry_t *new_vals = NULL; + axutil_hash_entry_t *iter; + axutil_hash_entry_t *ent; + unsigned int i, k; + +#if AXIS2_POOL_DEBUG + /* we don't copy keys and values, so it's necessary that + * overlay->a.env and base->a.env have a life span at least + * as long as p + */ + if (!axutil_env_is_ancestor(overlay->env, p)) + { + fprintf(stderr, + "axutil_hash_merge: overlay's env is not an ancestor of p\n"); + abort(); + } + if (!axutil_env_is_ancestor(base->env, p)) + { + fprintf(stderr, + "axutil_hash_merge: base's env is not an ancestor of p\n"); + abort(); + } +#endif + + res = AXIS2_MALLOC(env->allocator, sizeof(axutil_hash_t)); + res->env = env; + axutil_env_increment_ref((axutil_env_t*)env); + res->free = NULL; + res->hash_func = base->hash_func; + res->count = base->count; + res->max = (overlay->max > base->max) ? overlay->max : base->max; + if(base->count + overlay->count > res->max) + { + res->max = res->max * 2 + 1; + } + res->array = axutil_hash_alloc_array(res, res->max); + for(k = 0; k <= base->max; k++) + { + for(iter = base->array[k]; iter; iter = iter->next) + { + i = iter->hash & res->max; + new_vals = AXIS2_MALLOC(env->allocator, sizeof(axutil_hash_entry_t)); + new_vals->klen = iter->klen; + new_vals->key = iter->key; + new_vals->val = iter->val; + new_vals->hash = iter->hash; + new_vals->next = res->array[i]; + res->array[i] = new_vals; + } + } + + for(k = 0; k <= overlay->max; k++) + { + for(iter = overlay->array[k]; iter; iter = iter->next) + { + i = iter->hash & res->max; + for(ent = res->array[i]; ent; ent = ent->next) + { + if((ent->klen == iter->klen) && (memcmp(ent->key, iter->key, iter->klen) == 0)) + { + if(merger) + { + ent->val = (*merger)(env, iter->key, iter->klen, iter->val, ent->val, data); + } + else + { + ent->val = iter->val; + } + break; + } + } + if(!ent) + { + new_vals = AXIS2_MALLOC(env->allocator, sizeof(axutil_hash_entry_t)); + new_vals->klen = iter->klen; + new_vals->key = iter->key; + new_vals->val = iter->val; + new_vals->hash = iter->hash; + new_vals->next = res->array[i]; + res->array[i] = new_vals; + res->count++; + } + } + } + return res; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axutil_hash_contains_key( + axutil_hash_t *ht, + const axutil_env_t *env, + const axis2_char_t *key) +{ + axutil_hash_index_t *i = NULL; + + for(i = axutil_hash_first(ht, env); i; i = axutil_hash_next(env, i)) + { + const void *v = NULL; + const axis2_char_t *key_l = NULL; + + axutil_hash_this(i, &v, NULL, NULL); + key_l = (const axis2_char_t *)v; + if(0 == axutil_strcmp(key, key_l)) + return AXIS2_TRUE; + } + + return AXIS2_FALSE; +} + +/* + void + axutil_hash_entry_free( + const axutil_env_t *env, + axutil_hash_entry_t *hash_entry) + { + if (!hash_entry) + return; + if (hash_entry->next) + { + axutil_hash_entry_free(env, hash_entry->next); + } + AXIS2_FREE(env->allocator, hash_entry); + return; + } + */ + +AXIS2_EXTERN void AXIS2_CALL +axutil_hash_free( + axutil_hash_t *ht, + const axutil_env_t *env) +{ + unsigned int i = 0; + if(ht) + { + for(i = 0; i <= ht->max; i++) + { + axutil_hash_entry_t *next = NULL; + axutil_hash_entry_t *current = ht->array[i]; + while(current) + { + next = current->next; + AXIS2_FREE(env->allocator, current); + current = NULL; + current = next; + } + } + if(ht->free) + { + axutil_hash_entry_t *next = NULL; + axutil_hash_entry_t *current = ht->free; + while(current) + { + next = current->next; + AXIS2_FREE(env->allocator, current); + current = NULL; + current = next; + } + } + + if(ht->env) + { + /*since we now keep a ref count in env and incrementing it + *inside hash_make we need to free the env.Depending on the + situation the env struct is freed or ref count will be + decremented.*/ + + axutil_free_thread_env((axutil_env_t*)(ht->env)); + ht->env = NULL; + } + + AXIS2_FREE(env->allocator, (ht->array)); + AXIS2_FREE(env->allocator, ht); + } + return; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_hash_free_void_arg( + void *ht_void, + const axutil_env_t *env) +{ + unsigned int i = 0; + axutil_hash_t *ht = (axutil_hash_t *)ht_void; + if(ht) + { + for(i = 0; i < ht->max; i++) + { + axutil_hash_entry_t *next = NULL; + axutil_hash_entry_t *current = ht->array[i]; + while(current) + { + next = current->next; + AXIS2_FREE(env->allocator, current); + current = next; + } + } + AXIS2_FREE(env->allocator, (ht->array)); + AXIS2_FREE(env->allocator, ht); + } + return; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_hash_set_env( + axutil_hash_t * ht, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + if(ht) + { + if(ht->env) + { + /*since we now keep a ref count in env and incrementing it + *inside hash_make we need to free the env.Depending on the + situation the env struct is freed or ref count will be + decremented.*/ + + axutil_free_thread_env((axutil_env_t*)(ht->env)); + ht->env = NULL; + } + ht->env = env; + axutil_env_increment_ref((axutil_env_t*)env); + } +} + diff --git a/util/src/http_chunked_stream.c b/util/src/http_chunked_stream.c new file mode 100644 index 0000000..3a04ca2 --- /dev/null +++ b/util/src/http_chunked_stream.c @@ -0,0 +1,232 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_http_chunked_stream.h> +#include <axutil_string.h> +#include <string.h> +#include <stdlib.h> + +#define AXIS2_HTTP_CRLF "\r\n" + +struct axutil_http_chunked_stream +{ + axutil_stream_t *stream; + int current_chunk_size; + int unread_len; + axis2_bool_t end_of_chunks; + axis2_bool_t chunk_started; +}; + +static axis2_status_t +axutil_http_chunked_stream_start_chunk( + axutil_http_chunked_stream_t * chunked_stream, + const axutil_env_t *env); + +AXIS2_EXTERN axutil_http_chunked_stream_t *AXIS2_CALL +axutil_http_chunked_stream_create( + const axutil_env_t *env, + axutil_stream_t *stream) +{ + axutil_http_chunked_stream_t *chunked_stream = NULL; + AXIS2_PARAM_CHECK(env->error, stream, NULL); + + chunked_stream = (axutil_http_chunked_stream_t *)AXIS2_MALLOC(env->allocator, + sizeof(axutil_http_chunked_stream_t)); + if(!chunked_stream) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + chunked_stream->stream = stream; + chunked_stream->current_chunk_size = -1; + chunked_stream->unread_len = -1; + chunked_stream->end_of_chunks = AXIS2_FALSE; + chunked_stream->chunk_started = AXIS2_FALSE; + + return chunked_stream; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_http_chunked_stream_free( + axutil_http_chunked_stream_t *chunked_stream, + const axutil_env_t *env) +{ + AXIS2_FREE(env->allocator, chunked_stream); +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_http_chunked_stream_read( + axutil_http_chunked_stream_t *chunked_stream, + const axutil_env_t *env, + void *buffer, + size_t count) +{ + int len = -1; + int yet_to_read = 0; + axutil_stream_t *stream = chunked_stream->stream; + + if(!buffer) + { + return -1; + } + if(!stream) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NULL_STREAM_IN_CHUNKED_STREAM, AXIS2_FAILURE); + return -1; + } + if(AXIS2_TRUE == chunked_stream->end_of_chunks) + { + return 0; + } + if(AXIS2_FALSE == chunked_stream->chunk_started) + { + axutil_http_chunked_stream_start_chunk(chunked_stream, env); + } + yet_to_read = (int)count; + /* We are sure that the difference lies within the int range */ + while(AXIS2_FALSE == chunked_stream->end_of_chunks && yet_to_read > 0) + { + if(chunked_stream->unread_len < yet_to_read) + { + len = axutil_stream_read(chunked_stream->stream, env, (axis2_char_t *)buffer + count + - yet_to_read, chunked_stream->unread_len); + yet_to_read -= len; + chunked_stream->unread_len -= len; + if(chunked_stream->unread_len <= 0) + { + axutil_http_chunked_stream_start_chunk(chunked_stream, env); + } + } + else + { + len = axutil_stream_read(chunked_stream->stream, env, (axis2_char_t *)buffer + count + - yet_to_read, yet_to_read); + yet_to_read -= len; + chunked_stream->unread_len -= len; + } + } + return ((int)count - yet_to_read); + /* We are sure that the difference lies within the int range */ +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_http_chunked_stream_write( + axutil_http_chunked_stream_t *chunked_stream, + const axutil_env_t *env, + const void *buffer, + size_t count) +{ + axutil_stream_t *stream = chunked_stream->stream; + int len = -1; + axis2_char_t tmp_buf[10]; + + if(!buffer) + { + return -1; + } + if(!stream) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NULL_STREAM_IN_CHUNKED_STREAM, AXIS2_FAILURE); + return -1; + } + sprintf(tmp_buf, "%x%s", (unsigned int)count, AXIS2_HTTP_CRLF); + axutil_stream_write(stream, env, tmp_buf, axutil_strlen(tmp_buf)); + len = axutil_stream_write(stream, env, buffer, count); + axutil_stream_write(stream, env, AXIS2_HTTP_CRLF, 2); + return len; +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_http_chunked_stream_get_current_chunk_size( + const axutil_http_chunked_stream_t *chunked_stream, + const axutil_env_t *env) +{ + return chunked_stream->current_chunk_size; +} + +static axis2_status_t +axutil_http_chunked_stream_start_chunk( + axutil_http_chunked_stream_t *chunked_stream, + const axutil_env_t *env) +{ + axis2_char_t tmp_buf[3] = ""; + axis2_char_t str_chunk_len[512] = ""; + axis2_char_t *tmp = NULL; + int read = -1; + + /* remove the last CRLF of the previous chunk if any */ + if(AXIS2_TRUE == chunked_stream->chunk_started) + { + read = axutil_stream_read(chunked_stream->stream, env, tmp_buf, 2); + chunked_stream->chunk_started = AXIS2_FALSE; + } + /* read the len and chunk extension */ + while((read = axutil_stream_read(chunked_stream->stream, env, tmp_buf, 1)) > 0) + { + tmp_buf[read] = '\0'; + strcat(str_chunk_len, tmp_buf); + if(0 != strstr(str_chunk_len, AXIS2_HTTP_CRLF)) + { + break; + } + } + /* check whether we have extensions */ + tmp = strchr(str_chunk_len, ';'); + if(tmp) + { + /* we don't use extensions right now */ + *tmp = '\0'; + } + chunked_stream->current_chunk_size = strtol(str_chunk_len, NULL, 16); + if(0 == chunked_stream->current_chunk_size) + { + /* Read the last CRLF */ + read = axutil_stream_read(chunked_stream->stream, env, tmp_buf, 2); + chunked_stream->end_of_chunks = AXIS2_TRUE; + } + else + { + chunked_stream->chunk_started = AXIS2_TRUE; + chunked_stream->unread_len = chunked_stream->current_chunk_size; + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_http_chunked_stream_write_last_chunk( + axutil_http_chunked_stream_t *chunked_stream, + const axutil_env_t *env) +{ + axutil_stream_t *stream = NULL; + + stream = chunked_stream->stream; + if(axutil_stream_write(stream, env, "0\r\n\r\n", 5) == 5) + { + return AXIS2_SUCCESS; + } + return AXIS2_FAILURE; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axutil_http_chunked_stream_get_end_of_chunks( + axutil_http_chunked_stream_t *chunked_stream, + const axutil_env_t *env) +{ + return chunked_stream->end_of_chunks; +} + diff --git a/util/src/linked_list.c b/util/src/linked_list.c new file mode 100644 index 0000000..7ba83f8 --- /dev/null +++ b/util/src/linked_list.c @@ -0,0 +1,573 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_linked_list.h> +#include <axutil_utils.h> + +struct axutil_linked_list +{ + + /**The number of elements in this list. */ + int size; + + /** + * The first element in the list. + */ + entry_t *first; + + /** + * The last element in the list. + */ + entry_t *last; + + /** + * A count of the number of structural modifications that have been made to + * the list (that is, insertions and removals). Structural modifications + * are ones which change the list size or affect how iterations would + * behave. This field is available for use by Iterator and ListIterator, + * in order to set an error code in response + * to the next op on the iterator. This <i>fail-fast</i> behavior + * saves the user from many subtle bugs otherwise possible from concurrent + * modification during iteration. + * <p> + * + * To make lists fail-fast, increment this field by just 1 in the + * <code>add(int, Object)</code> and <code>remove(int)</code> methods. + * Otherwise, this field may be ignored. + */ + int mod_count; +}; + +AXIS2_EXTERN axutil_linked_list_t *AXIS2_CALL +axutil_linked_list_create( + const axutil_env_t *env) +{ + axutil_linked_list_t *linked_list = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + linked_list = AXIS2_MALLOC(env->allocator, sizeof(axutil_linked_list_t)); + if(!linked_list) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + + linked_list->size = 0; + linked_list->mod_count = 0; + linked_list->first = NULL; + linked_list->last = NULL; + + return linked_list; +} + +static entry_t * +axutil_linked_list_create_entry( + const axutil_env_t *env, + void *data) +{ + entry_t *entry = (entry_t *)AXIS2_MALLOC(env->allocator, sizeof(entry_t)); + if(!entry) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + + entry->data = data; + entry->previous = NULL; + entry->next = NULL; + return entry; +} + +static axis2_status_t +axutil_linked_list_add_last_entry( + axutil_linked_list_t *linked_list, + const axutil_env_t *env, + entry_t * e) +{ + AXIS2_PARAM_CHECK(env->error, e, AXIS2_FAILURE); + + linked_list->mod_count++; + if(linked_list->size == 0) + { + linked_list->first = linked_list->last = e; + } + else + { + e->previous = linked_list->last; + linked_list->last->next = e; + linked_list->last = e; + } + linked_list->size++; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_linked_list_free( + axutil_linked_list_t *linked_list, + const axutil_env_t *env) +{ + entry_t *current = NULL, *next = NULL; + + current = linked_list->first; + while(current) + { + next = current->next; + AXIS2_FREE(env->allocator, current); + current = next; + } + AXIS2_FREE(env->allocator, linked_list); + linked_list = NULL; +} + +AXIS2_EXTERN entry_t *AXIS2_CALL +axutil_linked_list_get_entry( + axutil_linked_list_t *linked_list, + const axutil_env_t *env, + int n) +{ + entry_t *e = NULL; + if(n < linked_list->size / 2) + { + e = linked_list->first; + /* n less than size/2, iterate from start */ + while(n > 0) + { + e = e->next; + n = n - 1; + } + } + else + { + e = linked_list->last; + /* n greater than size/2, iterate from end */ + while((n = n + 1) < linked_list->size) + { + e = e->previous; + } + } + + return e; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_linked_list_remove_entry( + axutil_linked_list_t *linked_list, + const axutil_env_t *env, + entry_t *e) +{ + AXIS2_PARAM_CHECK(env->error, e, AXIS2_FAILURE); + linked_list->mod_count++; + linked_list->size--; + if(linked_list->size == 0) + { + linked_list->first = linked_list->last = NULL; + } + else + { + if(e == linked_list->first) + { + linked_list->first = e->next; + e->next->previous = NULL; + } + else if(e == linked_list->last) + { + linked_list->last = e->previous; + e->previous->next = NULL; + } + else + { + e->next->previous = e->previous; + e->previous->next = e->next; + } + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axutil_linked_list_check_bounds_inclusive( + axutil_linked_list_t *linked_list, + const axutil_env_t *env, + int index) +{ + if(index < 0 || index > linked_list->size) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INDEX_OUT_OF_BOUNDS, AXIS2_FAILURE); + return AXIS2_FALSE; + } + return AXIS2_TRUE; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axutil_linked_list_check_bounds_exclusive( + axutil_linked_list_t *linked_list, + const axutil_env_t *env, + int index) +{ + if(index < 0 || index >= linked_list->size) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INDEX_OUT_OF_BOUNDS, AXIS2_FAILURE); + return AXIS2_FALSE; + } + return AXIS2_TRUE; +} + +AXIS2_EXTERN void *AXIS2_CALL +axutil_linked_list_get_first( + axutil_linked_list_t *linked_list, + const axutil_env_t *env) +{ + if(linked_list->size == 0) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_SUCH_ELEMENT, AXIS2_FAILURE); + return NULL; + } + + return linked_list->first->data; +} + +AXIS2_EXTERN void *AXIS2_CALL +axutil_linked_list_get_last( + axutil_linked_list_t *linked_list, + const axutil_env_t *env) +{ + if(linked_list->size == 0) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_SUCH_ELEMENT, AXIS2_FAILURE); + return NULL; + } + + return linked_list->last->data; +} + +AXIS2_EXTERN void *AXIS2_CALL +axutil_linked_list_remove_first( + axutil_linked_list_t *linked_list, + const axutil_env_t *env) +{ + void *r; + + if(linked_list->size == 0) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_SUCH_ELEMENT, AXIS2_FAILURE); + return NULL; + } + + linked_list->mod_count++; + linked_list->size--; + r = linked_list->first->data; + + if(linked_list->first->next) + { + linked_list->first->next->previous = NULL; + } + else + { + linked_list->last = NULL; + } + + linked_list->first = linked_list->first->next; + + return r; +} + +AXIS2_EXTERN void *AXIS2_CALL +axutil_linked_list_remove_last( + axutil_linked_list_t *linked_list, + const axutil_env_t *env) +{ + void *r = NULL; + + if(linked_list->size == 0) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_SUCH_ELEMENT, AXIS2_FAILURE); + return NULL; + } + + linked_list->mod_count++; + linked_list->size--; + r = linked_list->last->data; + + if(linked_list->last->previous) + { + linked_list->last->previous->next = NULL; + } + else + { + linked_list->first = NULL; + } + + linked_list->last = linked_list->last->previous; + + return r; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_linked_list_add_first( + axutil_linked_list_t *linked_list, + const axutil_env_t *env, + void *o) +{ + entry_t *e; + AXIS2_PARAM_CHECK(env->error, o, AXIS2_FAILURE); + + e = axutil_linked_list_create_entry(env, o); + + linked_list->mod_count++; + if(linked_list->size == 0) + { + linked_list->first = linked_list->last = e; + } + else + { + e->next = linked_list->first; + linked_list->first->previous = e; + linked_list->first = e; + } + linked_list->size++; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_linked_list_add_last( + axutil_linked_list_t *linked_list, + const axutil_env_t *env, + void *o) +{ + entry_t *e; + AXIS2_PARAM_CHECK(env->error, o, AXIS2_FAILURE); + + e = axutil_linked_list_create_entry(env, o); + return axutil_linked_list_add_last_entry(linked_list, env, e); +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axutil_linked_list_contains( + axutil_linked_list_t *linked_list, + const axutil_env_t *env, + void *o) +{ + entry_t *e; + AXIS2_PARAM_CHECK(env->error, o, AXIS2_FALSE); + + e = linked_list->first; + while(e) + { + if(o == e->data) + return AXIS2_TRUE; + e = e->next; + } + return AXIS2_FALSE; +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_linked_list_size( + axutil_linked_list_t *linked_list, + const axutil_env_t *env) +{ + return linked_list->size; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axutil_linked_list_add( + axutil_linked_list_t *linked_list, + const axutil_env_t *env, + void *o) +{ + entry_t *e; + AXIS2_PARAM_CHECK(env->error, o, AXIS2_FALSE); + e = axutil_linked_list_create_entry(env, o); + return axutil_linked_list_add_last_entry(linked_list, env, e); +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axutil_linked_list_remove( + axutil_linked_list_t *linked_list, + const axutil_env_t *env, + void *o) +{ + entry_t *e; + AXIS2_PARAM_CHECK(env->error, o, AXIS2_FALSE); + + e = linked_list->first; + while(e) + { + if(o == e->data) + { + return axutil_linked_list_remove_entry(linked_list, env, e); + } + e = e->next; + } + return AXIS2_FALSE; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_linked_list_clear( + axutil_linked_list_t *linked_list, + const axutil_env_t *env) +{ + if(linked_list->size > 0) + { + linked_list->mod_count++; + linked_list->first = NULL; + linked_list->last = NULL; + linked_list->size = 0; + } + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN void *AXIS2_CALL +axutil_linked_list_get( + axutil_linked_list_t *linked_list, + const axutil_env_t *env, + int index) +{ + axutil_linked_list_check_bounds_exclusive(linked_list, env, index); + return axutil_linked_list_get_entry(linked_list, env, index)->data; +} + +AXIS2_EXTERN void *AXIS2_CALL +axutil_linked_list_set( + axutil_linked_list_t *linked_list, + const axutil_env_t *env, + int index, + void *o) +{ + entry_t *e; + void *old; + AXIS2_PARAM_CHECK(env->error, o, NULL); + axutil_linked_list_check_bounds_exclusive(linked_list, env, index); + e = axutil_linked_list_get_entry(linked_list, env, index); + old = e->data; + e->data = o; + return old; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_linked_list_add_at_index( + axutil_linked_list_t *linked_list, + const axutil_env_t *env, + int index, + void *o) +{ + entry_t *after = NULL; + entry_t *e; + AXIS2_PARAM_CHECK(env->error, o, AXIS2_FAILURE); + + axutil_linked_list_check_bounds_inclusive(linked_list, env, index); + e = axutil_linked_list_create_entry(env, o); + + if(index < linked_list->size) + { + linked_list->mod_count++; + after = axutil_linked_list_get_entry(linked_list, env, index); + e->next = after; + e->previous = after->previous; + if(after->previous == NULL) + linked_list->first = e; + else + after->previous->next = e; + after->previous = e; + linked_list->size++; + } + else + { + axutil_linked_list_add_last_entry(linked_list, env, e); + } + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN void *AXIS2_CALL +axutil_linked_list_remove_at_index( + axutil_linked_list_t *linked_list, + const axutil_env_t *env, + int index) +{ + entry_t *e; + axutil_linked_list_check_bounds_exclusive(linked_list, env, index); + e = axutil_linked_list_get_entry(linked_list, env, index); + axutil_linked_list_remove_entry(linked_list, env, e); + return e->data; +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_linked_list_index_of( + axutil_linked_list_t *linked_list, + const axutil_env_t *env, + void *o) +{ + int index = 0; + entry_t *e; + AXIS2_PARAM_CHECK(env->error, o, AXIS2_FAILURE); + + e = linked_list->first; + while(e) + { + if(o == e->data) + return index; + index++; + e = e->next; + } + return -1; +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_linked_list_last_index_of( + axutil_linked_list_t *linked_list, + const axutil_env_t *env, + void *o) +{ + int index; + entry_t *e; + AXIS2_PARAM_CHECK(env->error, o, AXIS2_FAILURE); + + index = linked_list->size - 1; + e = linked_list->last; + while(e) + { + if(o == e->data) + return index; + index--; + e = e->previous; + } + return -1; +} + +AXIS2_EXTERN void **AXIS2_CALL +axutil_linked_list_to_array( + axutil_linked_list_t *linked_list, + const axutil_env_t *env) +{ + int i = 0; + void **array; + entry_t *e; + array = (void **)AXIS2_MALLOC(env->allocator, linked_list->size * sizeof(void *)); + e = linked_list->first; + for(i = 0; i < linked_list->size; i++) + { + array[i] = e->data; + e = e->next; + } + return array; +} + diff --git a/util/src/log.c b/util/src/log.c new file mode 100644 index 0000000..72a2508 --- /dev/null +++ b/util/src/log.c @@ -0,0 +1,576 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <platforms/axutil_platform_auto_sense.h> +#include <axutil_log_default.h> +#include <axutil_file_handler.h> +#include <axutil_thread.h> +#include <signal.h> + +typedef struct axutil_log_impl axutil_log_impl_t; + +static axis2_status_t +axutil_log_impl_rotate( + axutil_log_t *log); + +static void AXIS2_CALL axutil_log_impl_write( + axutil_log_t *log, + const axis2_char_t *buffer, + axutil_log_levels_t level, + const axis2_char_t *file, + const int line); + +AXIS2_EXTERN void AXIS2_CALL axutil_log_impl_write_to_file( + axutil_log_t *log, + axutil_thread_mutex_t *mutex, + axutil_log_levels_t level, + const axis2_char_t *file, + const int line, + const axis2_char_t *value); + +static void AXIS2_CALL axutil_log_impl_free( + axutil_allocator_t *allocator, + axutil_log_t *log); + +struct axutil_log_impl +{ + axutil_log_t log; + void *stream; + axis2_char_t *file_name; + axutil_thread_mutex_t *mutex; +}; + +#define AXUTIL_INTF_TO_IMPL(log) ((axutil_log_impl_t*)(log)) + +static const axutil_log_ops_t axutil_log_ops_var = { axutil_log_impl_free, axutil_log_impl_write }; + +static void AXIS2_CALL +axutil_log_impl_free( + axutil_allocator_t *allocator, + axutil_log_t *log) +{ + axutil_log_impl_t *log_impl = NULL; + + if(log) + { + log_impl = AXUTIL_INTF_TO_IMPL(log); + + if(log_impl->mutex) + { + axutil_thread_mutex_destroy(log_impl->mutex); + } + if(log_impl->stream) + { + axutil_file_handler_close(log_impl->stream); + } + if(log_impl->file_name) + { + AXIS2_FREE(allocator, log_impl->file_name); + } + AXIS2_FREE(allocator, log_impl); + } +} + +AXIS2_EXTERN axutil_log_t *AXIS2_CALL +axutil_log_create( + axutil_allocator_t *allocator, + axutil_log_ops_t *ops, + const axis2_char_t *stream_name) +{ + axutil_log_impl_t *log_impl; + axis2_char_t *path_home; + axis2_char_t log_file_name[AXUTIL_LOG_FILE_NAME_SIZE]; + axis2_char_t log_dir[AXUTIL_LOG_FILE_NAME_SIZE]; + axis2_char_t tmp_filename[AXUTIL_LOG_FILE_NAME_SIZE]; + + if(!allocator) + return NULL; + + log_impl = (axutil_log_impl_t *)AXIS2_MALLOC(allocator, sizeof(axutil_log_impl_t)); + + if(!log_impl) + return NULL; + + log_impl->mutex = axutil_thread_mutex_create(allocator, AXIS2_THREAD_MUTEX_DEFAULT); + + if(!log_impl->mutex) + { + fprintf(stderr, "cannot create log mutex \n"); + return NULL; + } + +#ifndef WIN32 + signal(SIGXFSZ, SIG_IGN); +#endif + + /* default log file is axis2.log */ + if(stream_name) + AXIS2_SNPRINTF(tmp_filename, AXUTIL_LOG_FILE_NAME_SIZE, "%s", stream_name); + else + AXIS2_SNPRINTF(tmp_filename, AXUTIL_LOG_FILE_NAME_SIZE, "%s", "axis2.log"); + + /* we write all logs to AXIS2C_HOME/logs if it is set otherwise + * to the working dir + */ + if(stream_name && !(axutil_rindex(stream_name, AXIS2_PATH_SEP_CHAR))) + { + path_home = AXIS2_GETENV("AXIS2C_HOME"); + if(path_home) + { + AXIS2_SNPRINTF(log_dir, AXUTIL_LOG_FILE_NAME_SIZE, "%s%c%s", path_home, + AXIS2_PATH_SEP_CHAR, "logs"); + if(AXIS2_SUCCESS == axutil_file_handler_access(log_dir, AXIS2_F_OK)) + { + AXIS2_SNPRINTF(log_file_name, AXUTIL_LOG_FILE_NAME_SIZE, "%s%c%s", log_dir, + AXIS2_PATH_SEP_CHAR, tmp_filename); + } + else + { + fprintf(stderr, "log folder %s does not exist - log file %s " + "is written to . dir\n", log_dir, tmp_filename); + AXIS2_SNPRINTF(log_file_name, AXUTIL_LOG_FILE_NAME_SIZE, "%s", tmp_filename); + } + } + else + { + fprintf(stderr, "AXIS2C_HOME is not set - log is written to . dir\n"); + AXIS2_SNPRINTF(log_file_name, AXUTIL_LOG_FILE_NAME_SIZE, "%s", tmp_filename); + } + } + else + { + AXIS2_SNPRINTF(log_file_name, AXUTIL_LOG_FILE_NAME_SIZE, "%s", tmp_filename); + } + log_impl->file_name = AXIS2_MALLOC(allocator, AXUTIL_LOG_FILE_NAME_SIZE); + log_impl->log.size = AXUTIL_LOG_FILE_SIZE; + sprintf(log_impl->file_name, "%s", log_file_name); + + axutil_thread_mutex_lock(log_impl->mutex); + + log_impl->stream = axutil_file_handler_open(log_file_name, "a+"); + axutil_log_impl_rotate((axutil_log_t *)log_impl); + + axutil_thread_mutex_unlock(log_impl->mutex); + + if(!log_impl->stream) + log_impl->stream = stderr; + + /* by default, log is enabled */ + log_impl->log.enabled = 1; + log_impl->log.level = AXIS2_LOG_LEVEL_DEBUG; + + if(ops) + { + log_impl->log.ops = ops; + } + else + { + log_impl->log.ops = &axutil_log_ops_var; + } + + return &(log_impl->log); +} + +static void AXIS2_CALL +axutil_log_impl_write( + axutil_log_t *log, + const axis2_char_t *buffer, + axutil_log_levels_t level, + const axis2_char_t *file, + const int line) +{ + if(log && log->enabled && buffer) + { + axutil_log_impl_t *l = AXUTIL_INTF_TO_IMPL(log); + if(!l->mutex) + fprintf(stderr, "Log mutex is not found\n"); + if(!l->stream) + fprintf(stderr, "Stream is not found\n"); + if(level <= log->level || level == AXIS2_LOG_LEVEL_CRITICAL) + { + axutil_log_impl_write_to_file(log, l->mutex, level, file, line, buffer); + } + } +#ifndef AXIS2_NO_LOG_FILE + else if(buffer) + fprintf(stderr, "please check your log and buffer"); +#endif + else + fprintf(stderr, "please check your log and buffer"); +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_log_impl_write_to_file( + axutil_log_t *log, + axutil_thread_mutex_t *mutex, + axutil_log_levels_t level, + const axis2_char_t *file, + const int line, + const axis2_char_t *value) +{ + const char *level_str = ""; + axutil_log_impl_t *log_impl = AXUTIL_INTF_TO_IMPL(log); + FILE *fd = NULL; + + /** + * print all critical and error logs irrespective of log->level setting + */ + + switch(level) + { + case AXIS2_LOG_LEVEL_CRITICAL: + level_str = "[critical] "; + break; + case AXIS2_LOG_LEVEL_ERROR: + level_str = "[error] "; + break; + case AXIS2_LOG_LEVEL_WARNING: + level_str = "[warning] "; + break; + case AXIS2_LOG_LEVEL_INFO: + level_str = "[info] "; + break; + case AXIS2_LOG_LEVEL_DEBUG: + level_str = "[debug] "; + break; + case AXIS2_LOG_LEVEL_TRACE: + level_str = "[...TRACE...] "; + break; + case AXIS2_LOG_LEVEL_USER: + break; + } + axutil_thread_mutex_lock(mutex); + + axutil_log_impl_rotate(log); + fd = log_impl->stream; + + if(fd) + { + if(file) + fprintf(fd, "[%s] %s%s(%d) %s\n", axutil_log_impl_get_time_str(), level_str, file, + line, value); + else + fprintf(fd, "[%s] %s %s\n", axutil_log_impl_get_time_str(), level_str, value); + fflush(fd); + } + axutil_thread_mutex_unlock(mutex); +} + +static axis2_status_t +axutil_log_impl_rotate( + axutil_log_t *log) +{ + long size = -1; + FILE *old_log_fd = NULL; + axis2_char_t old_log_file_name[AXUTIL_LOG_FILE_NAME_SIZE]; + axutil_log_impl_t *log_impl = AXUTIL_INTF_TO_IMPL(log); + if(log_impl->file_name) + size = axutil_file_handler_size(log_impl->file_name); + + if(size >= log->size) + { + AXIS2_SNPRINTF(old_log_file_name, AXUTIL_LOG_FILE_NAME_SIZE, "%s%s", log_impl->file_name, + ".old"); + axutil_file_handler_close(log_impl->stream); + old_log_fd = axutil_file_handler_open(old_log_file_name, "w+"); + log_impl->stream = axutil_file_handler_open(log_impl->file_name, "r"); + if(old_log_fd && log_impl->stream) + { + axutil_file_handler_copy(log_impl->stream, old_log_fd); + axutil_file_handler_close(old_log_fd); + axutil_file_handler_close(log_impl->stream); + old_log_fd = NULL; + log_impl->stream = NULL; + } + if(old_log_fd) + { + axutil_file_handler_close(old_log_fd); + } + if(log_impl->stream) + { + axutil_file_handler_close(log_impl->stream); + } + log_impl->stream = axutil_file_handler_open(log_impl->file_name, "w+"); + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_log_impl_log_user( + axutil_log_t *log, + const axis2_char_t *file, + const int line, + const axis2_char_t *format, + ...) +{ + if(log && log->ops && log->ops->write && format && log->enabled) + { + if(AXIS2_LOG_LEVEL_DEBUG <= log->level) + { + char value[AXIS2_LEN_VALUE + 1]; + va_list ap; + va_start(ap, format); + AXIS2_VSNPRINTF(value, AXIS2_LEN_VALUE, format, ap); + va_end(ap); + log->ops->write(log, value, AXIS2_LOG_LEVEL_DEBUG, file, line); + } + } +#ifndef AXIS2_NO_LOG_FILE + else + fprintf(stderr, "please check your log and buffer"); +#endif +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_log_impl_log_debug( + axutil_log_t *log, + const axis2_char_t *file, + const int line, + const axis2_char_t *format, + ...) +{ + if(log && log->ops && log->ops->write && format && log->enabled) + { + if(AXIS2_LOG_LEVEL_DEBUG <= log->level && log->level != AXIS2_LOG_LEVEL_USER) + { + char value[AXIS2_LEN_VALUE + 1]; + va_list ap; + va_start(ap, format); + AXIS2_VSNPRINTF(value, AXIS2_LEN_VALUE, format, ap); + va_end(ap); + log->ops->write(log, value, AXIS2_LOG_LEVEL_DEBUG, file, line); + } + } +#ifndef AXIS2_NO_LOG_FILE + else + fprintf(stderr, "please check your log and buffer"); +#endif +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_log_impl_log_info( + axutil_log_t *log, + const axis2_char_t *format, + ...) +{ + if(log && log->ops && log->ops->write && format && log->enabled) + { + if(AXIS2_LOG_LEVEL_INFO <= log->level && log->level != AXIS2_LOG_LEVEL_USER) + { + char value[AXIS2_LEN_VALUE + 1]; + va_list ap; + va_start(ap, format); + AXIS2_VSNPRINTF(value, AXIS2_LEN_VALUE, format, ap); + va_end(ap); + log->ops->write(log, value, AXIS2_LOG_LEVEL_INFO, NULL, -1); + } + } +#ifndef AXIS2_NO_LOG_FILE + else + fprintf(stderr, "please check your log and buffer"); +#endif +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_log_impl_log_warning( + axutil_log_t *log, + const axis2_char_t *file, + const int line, + const axis2_char_t *format, + ...) +{ + if(log && log->ops && log->ops->write && format && log->enabled) + { + if(AXIS2_LOG_LEVEL_WARNING <= log->level && log->level != AXIS2_LOG_LEVEL_USER) + { + char value[AXIS2_LEN_VALUE + 1]; + va_list ap; + va_start(ap, format); + AXIS2_VSNPRINTF(value, AXIS2_LEN_VALUE, format, ap); + va_end(ap); + log->ops->write(log, value, AXIS2_LOG_LEVEL_WARNING, file, line); + } + } +#ifndef AXIS2_NO_LOG_FILE + else + fprintf(stderr, "please check your log and buffer"); +#endif +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_log_impl_log_error( + axutil_log_t *log, + const axis2_char_t *file, + const int line, + const axis2_char_t *format, + ...) +{ + if(log && log->ops && log->ops->write && format && log->enabled) + { + char value[AXIS2_LEN_VALUE + 1]; + va_list ap; + va_start(ap, format); + AXIS2_VSNPRINTF(value, AXIS2_LEN_VALUE, format, ap); + va_end(ap); + log->ops->write(log, value, AXIS2_LOG_LEVEL_ERROR, file, line); + } +#ifndef AXIS2_NO_LOG_FILE + else + fprintf(stderr, "please check your log and buffer"); +#endif +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_log_impl_log_critical( + axutil_log_t *log, + const axis2_char_t *file, + const int line, + const axis2_char_t *format, + ...) +{ + if(log && log->ops && log->ops->write && format && log->enabled) + { + char value[AXIS2_LEN_VALUE + 1]; + va_list ap; + va_start(ap, format); + AXIS2_VSNPRINTF(value, AXIS2_LEN_VALUE, format, ap); + va_end(ap); + log->ops->write(log, value, AXIS2_LOG_LEVEL_CRITICAL, file, line); + } +#ifndef AXIS2_NO_LOG_FILE + else + fprintf(stderr, "please check your log and buffer"); +#endif +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_log_impl_get_time_str( + void) +{ + time_t tp; + char *time_str; + tp = time(&tp); + time_str = ctime(&tp); + if(!time_str) + { + return NULL; + } + if('\n' == time_str[strlen(time_str) - 1]) + { + time_str[strlen(time_str) - 1] = '\0'; + } + return time_str; +} + +AXIS2_EXTERN axutil_log_t *AXIS2_CALL +axutil_log_create_default( + axutil_allocator_t *allocator) +{ + axutil_log_impl_t *log_impl; + + if(!allocator) + return NULL; + + log_impl = (axutil_log_impl_t *)AXIS2_MALLOC(allocator, sizeof(axutil_log_impl_t)); + + if(!log_impl) + return NULL; + + log_impl->mutex = axutil_thread_mutex_create(allocator, AXIS2_THREAD_MUTEX_DEFAULT); + + if(!log_impl->mutex) + { + fprintf(stderr, "cannot create log mutex \n"); + return NULL; + } + + axutil_thread_mutex_lock(log_impl->mutex); + log_impl->file_name = NULL; + log_impl->log.size = AXUTIL_LOG_FILE_SIZE; + log_impl->stream = stderr; + axutil_thread_mutex_unlock(log_impl->mutex); + /* by default, log is enabled */ + log_impl->log.enabled = 1; + log_impl->log.level = AXIS2_LOG_LEVEL_DEBUG; + + log_impl->log.ops = &axutil_log_ops_var; + + return &(log_impl->log); +} + +#ifdef AXIS2_TRACE +AXIS2_EXTERN void AXIS2_CALL +axutil_log_impl_log_trace( + axutil_log_t *log, + const axis2_char_t *file, + const int line, + const axis2_char_t *format, + ...) +{ + if (log && log->ops && log->ops->write && + format && log->enabled) + { + if(AXIS2_LOG_LEVEL_TRACE <= log->level && log->level != AXIS2_LOG_LEVEL_USER) + { + char value[AXIS2_LEN_VALUE + 1]; + va_list ap; + va_start(ap, format); + AXIS2_VSNPRINTF(value, AXIS2_LEN_VALUE, format, ap); + va_end(ap); + log->ops->write(log, value, AXIS2_LOG_LEVEL_TRACE, file, line); + } + } +#ifndef AXIS2_NO_LOG_FILE + else + fprintf(stderr, "please check your log and buffer"); +#endif +} + +#else +AXIS2_EXTERN void AXIS2_CALL +axutil_log_impl_log_trace( + axutil_log_t *log, + const axis2_char_t *filename, + const int linenumber, + const axis2_char_t *format, + ...) +{ +} +#endif + +AXIS2_EXTERN void AXIS2_CALL +axutil_log_free( + axutil_allocator_t *allocator, + struct axutil_log *log) +{ + log->ops->free(allocator, log); +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_log_write( + axutil_log_t *log, + const axis2_char_t *buffer, + axutil_log_levels_t level, + const axis2_char_t *file, + const int line) +{ + log->ops->write(log, buffer, level, file, line); +} + diff --git a/util/src/md5.c b/util/src/md5.c new file mode 100644 index 0000000..0768df3 --- /dev/null +++ b/util/src/md5.c @@ -0,0 +1,350 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <stdlib.h> +#include <string.h> +#include <axutil_md5.h> +#include <axutil_error_default.h> +#include <axutil_string.h> + +#define S11 7 +#define S12 12 +#define S13 17 +#define S14 22 +#define S21 5 +#define S22 9 +#define S23 14 +#define S24 20 +#define S31 4 +#define S32 11 +#define S33 16 +#define S34 23 +#define S41 6 +#define S42 10 +#define S43 15 +#define S44 21 + +static void AXIS2_CALL md5_transform( + unsigned int state[4], + const unsigned char block[64]); + +static void AXIS2_CALL encode( + unsigned char *output, + const unsigned int *input, + unsigned int len); + +static void AXIS2_CALL decode( + unsigned int *output, + const unsigned char *input, + unsigned int len); + +static unsigned char PADDING[64] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + +/* F, G, H and I are basic MD5 functions. + */ +#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) +#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) +#define H(x, y, z) ((x) ^ (y) ^ (z)) +#define I(x, y, z) ((y) ^ ((x) | (~z))) + +/* ROTATE_LEFT rotates x left n bits. + */ +#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) + +/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. + * Rotation is separate from addition to prevent recomputation. + */ +#define FF(a, b, c, d, x, s, ac) { \ + (a) += F ((b), (c), (d)) + (x) + (unsigned int)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ + } +#define GG(a, b, c, d, x, s, ac) { \ + (a) += G ((b), (c), (d)) + (x) + (unsigned int)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ + } +#define HH(a, b, c, d, x, s, ac) { \ + (a) += H ((b), (c), (d)) + (x) + (unsigned int)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ + } +#define II(a, b, c, d, x, s, ac) { \ + (a) += I ((b), (c), (d)) + (x) + (unsigned int)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ + } + +AXIS2_EXTERN axutil_md5_ctx_t *AXIS2_CALL +axutil_md5_ctx_create( + const axutil_env_t *env) +{ + axutil_md5_ctx_t *context; + AXIS2_ENV_CHECK(env, NULL); + + context = (axutil_md5_ctx_t *)AXIS2_MALLOC(env->allocator, sizeof(axutil_md5_ctx_t)); + if(!context) + { + return NULL; + } + context->count[0] = context->count[1] = 0; + + /* Load magic initialization constants. */ + context->state[0] = 0x67452301; + context->state[1] = 0xefcdab89; + context->state[2] = 0x98badcfe; + context->state[3] = 0x10325476; + return context; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_md5_ctx_free( + axutil_md5_ctx_t *md5_ctx, + const axutil_env_t *env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + if(md5_ctx) + { + AXIS2_FREE(env->allocator, md5_ctx); + } +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_md5_update( + axutil_md5_ctx_t *context, + const axutil_env_t *env, + const void *input_str, + size_t inputLen) +{ + const unsigned char *input = input_str; + unsigned int i, idx, partLen; + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + /* Compute number of bytes mod 64 */ + idx = (unsigned int)((context->count[0] >> 3) & 0x3F); + + /* Update number of bits */ + if((context->count[0] += ((unsigned int)inputLen << 3)) < ((unsigned int)inputLen << 3)) + context->count[1]++; + context->count[1] += (unsigned int)inputLen >> 29; + + partLen = 64 - idx; + + /* Transform as many times as possible. */ + if(inputLen >= partLen) + { + memcpy(&context->buffer[idx], input, partLen); + md5_transform(context->state, context->buffer); + + for(i = partLen; i + 63 < inputLen; i += 64) + md5_transform(context->state, &input[i]); + + idx = 0; + } + else + i = 0; + + /* Buffer remaining input */ + memcpy(&context->buffer[idx], &input[i], inputLen - i); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_md5_final( + axutil_md5_ctx_t *context, + const axutil_env_t *env, + unsigned char digest[AXIS2_MD5_DIGESTSIZE]) +{ + unsigned char bits[8]; + unsigned int idx, padLen; + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + /* Save number of bits */ + encode(bits, context->count, 8); + + /* Pad out to 56 mod 64. */ + idx = (unsigned int)((context->count[0] >> 3) & 0x3f); + padLen = (idx < 56) ? (56 - idx) : (120 - idx); + axutil_md5_update(context, env, PADDING, padLen); + + /* Append length (before padding) */ + axutil_md5_update(context, env, bits, 8); + + /* Store state in digest */ + encode(digest, context->state, AXIS2_MD5_DIGESTSIZE); + + /* Zeroize sensitive information. */ + memset(context, 0, sizeof(*context)); + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_md5( + const axutil_env_t *env, + unsigned char digest[AXIS2_MD5_DIGESTSIZE], + const void *input_str, + size_t inputLen) +{ + const unsigned char *input = input_str; + axutil_md5_ctx_t *ctx; + axis2_status_t rv; + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + ctx = axutil_md5_ctx_create(env); + if(!ctx) + return AXIS2_FAILURE; + + rv = axutil_md5_update(ctx, env, input, inputLen); + if(rv != AXIS2_SUCCESS) + return rv; + + rv = axutil_md5_final(ctx, env, digest); + axutil_md5_ctx_free(ctx, env); + return rv; +} + +/* MD5 basic transformation. Transforms state based on block. */ +static void AXIS2_CALL md5_transform( + unsigned int state[4], + const unsigned char block[64]) +{ + unsigned int a = state[0], b = state[1], c = state[2], d = state[3], + x[AXIS2_MD5_DIGESTSIZE]; + + decode(x, block, 64); + + /* Round 1 */ + FF(a, b, c, d, x[0], S11, 0xd76aa478); /* 1 */ + FF(d, a, b, c, x[1], S12, 0xe8c7b756); /* 2 */ + FF(c, d, a, b, x[2], S13, 0x242070db); /* 3 */ + FF(b, c, d, a, x[3], S14, 0xc1bdceee); /* 4 */ + FF(a, b, c, d, x[4], S11, 0xf57c0faf); /* 5 */ + FF(d, a, b, c, x[5], S12, 0x4787c62a); /* 6 */ + FF(c, d, a, b, x[6], S13, 0xa8304613); /* 7 */ + FF(b, c, d, a, x[7], S14, 0xfd469501); /* 8 */ + FF(a, b, c, d, x[8], S11, 0x698098d8); /* 9 */ + FF(d, a, b, c, x[9], S12, 0x8b44f7af); /* 10 */ + FF(c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ + FF(b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ + FF(a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ + FF(d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ + FF(c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ + FF(b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ + + /* Round 2 */ + GG(a, b, c, d, x[1], S21, 0xf61e2562); /* 17 */ + GG(d, a, b, c, x[6], S22, 0xc040b340); /* 18 */ + GG(c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ + GG(b, c, d, a, x[0], S24, 0xe9b6c7aa); /* 20 */ + GG(a, b, c, d, x[5], S21, 0xd62f105d); /* 21 */ + GG(d, a, b, c, x[10], S22, 0x2441453); /* 22 */ + GG(c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ + GG(b, c, d, a, x[4], S24, 0xe7d3fbc8); /* 24 */ + GG(a, b, c, d, x[9], S21, 0x21e1cde6); /* 25 */ + GG(d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ + GG(c, d, a, b, x[3], S23, 0xf4d50d87); /* 27 */ + GG(b, c, d, a, x[8], S24, 0x455a14ed); /* 28 */ + GG(a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ + GG(d, a, b, c, x[2], S22, 0xfcefa3f8); /* 30 */ + GG(c, d, a, b, x[7], S23, 0x676f02d9); /* 31 */ + GG(b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ + + /* Round 3 */ + HH(a, b, c, d, x[5], S31, 0xfffa3942); /* 33 */ + HH(d, a, b, c, x[8], S32, 0x8771f681); /* 34 */ + HH(c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ + HH(b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ + HH(a, b, c, d, x[1], S31, 0xa4beea44); /* 37 */ + HH(d, a, b, c, x[4], S32, 0x4bdecfa9); /* 38 */ + HH(c, d, a, b, x[7], S33, 0xf6bb4b60); /* 39 */ + HH(b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ + HH(a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ + HH(d, a, b, c, x[0], S32, 0xeaa127fa); /* 42 */ + HH(c, d, a, b, x[3], S33, 0xd4ef3085); /* 43 */ + HH(b, c, d, a, x[6], S34, 0x4881d05); /* 44 */ + HH(a, b, c, d, x[9], S31, 0xd9d4d039); /* 45 */ + HH(d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ + HH(c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ + HH(b, c, d, a, x[2], S34, 0xc4ac5665); /* 48 */ + + /* Round 4 */ + II(a, b, c, d, x[0], S41, 0xf4292244); /* 49 */ + II(d, a, b, c, x[7], S42, 0x432aff97); /* 50 */ + II(c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ + II(b, c, d, a, x[5], S44, 0xfc93a039); /* 52 */ + II(a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ + II(d, a, b, c, x[3], S42, 0x8f0ccc92); /* 54 */ + II(c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ + II(b, c, d, a, x[1], S44, 0x85845dd1); /* 56 */ + II(a, b, c, d, x[8], S41, 0x6fa87e4f); /* 57 */ + II(d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ + II(c, d, a, b, x[6], S43, 0xa3014314); /* 59 */ + II(b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ + II(a, b, c, d, x[4], S41, 0xf7537e82); /* 61 */ + II(d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ + II(c, d, a, b, x[2], S43, 0x2ad7d2bb); /* 63 */ + II(b, c, d, a, x[9], S44, 0xeb86d391); /* 64 */ + + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; + + /* Zeroize sensitive information. */ + memset(x, 0, sizeof(x)); +} + +/* encodes input (unsigned int) into output (unsigned char). Assumes len is + * a multiple of 4. + */ +static void AXIS2_CALL encode( + unsigned char *output, + const unsigned int *input, + unsigned int len) +{ + unsigned int i, j; + unsigned int k; + + for (i = 0, j = 0; j < len; i++, j += 4) + { + k = input[i]; + output[j] = (unsigned char)(k & 0xff); + output[j + 1] = (unsigned char)((k >> 8) & 0xff); + output[j + 2] = (unsigned char)((k >> 16) & 0xff); + output[j + 3] = (unsigned char)((k >> 24) & 0xff); + } +} + +/* decodes input (unsigned char) into output (unsigned int). Assumes len is + * a multiple of 4. + */ +static void AXIS2_CALL decode( + unsigned int *output, + const unsigned char *input, + unsigned int len) +{ + unsigned int i, j; + + for (i = 0, j = 0; j < len; i++, j += 4) + output[i] = ((unsigned int)input[j]) | + (((unsigned int)input[j + 1]) << 8) | + (((unsigned int)input[j + 2]) << 16) | + (((unsigned int)input[j + 3]) << 24); +} diff --git a/util/src/minizip/Makefile.am b/util/src/minizip/Makefile.am new file mode 100644 index 0000000..6fc3413 --- /dev/null +++ b/util/src/minizip/Makefile.am @@ -0,0 +1,18 @@ +lib_LTLIBRARIES = libaxis2_minizip.la + +libaxis2_minizip_la_SOURCES = ioapi.c \ + unzip.c \ + archive_extract.c \ + crypt.c + +libaxis2_minizip_la_LDFLAGS = -version-info $(VERSION_NO) + +INCLUDES = -I$(top_builddir)/include \ + -I$(top_builddir)/platforms + +EXTRA_DIST= axis2_archive_extract.h \ + axis2_crypt.h \ + axis2_ioapi.h \ + axis2_iowin32.h \ + axis2_unzip.h \ + iowin32.c diff --git a/util/src/minizip/archive_extract.c b/util/src/minizip/archive_extract.c new file mode 100644 index 0000000..dd68efb --- /dev/null +++ b/util/src/minizip/archive_extract.c @@ -0,0 +1,361 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_dir_handler.h> +#include <platforms/axutil_platform_auto_sense.h> +#include <axutil_string.h> +#include <zlib.h> +#include <fcntl.h> +#include <axis2_unzip.h> +#include <axis2_crypt.h> +#include <axis2_ioapi.h> + +#ifdef WIN32 +#include <axis2_iowin32.h> +#endif + +#define CASESENSITIVITY (0) +#define WRITEBUFFERSIZE (8192) +#define MAXFILENAME (256) + +axis2_status_t aar_select( + ); +int aar_extract( + axis2_char_t * d_name); + +extern int AXIS2_ALPHASORT( + ); + +int +axis2_mkdir(const axis2_char_t * + dir_name) +{ + int value = 0; + value = AXIS2_MKDIR(dir_name, 0775); + return value; +} + +int +axis2_create_dir( + axis2_char_t *new_dir) +{ + axis2_char_t *buffer; + axis2_char_t *p; + axis2_bool_t loop_state = AXIS2_TRUE; + int len = (int) strlen(new_dir); + + if (len <= 0) + return 0; + + buffer = (axis2_char_t *) malloc(len + 1); + strcpy(buffer, new_dir); + + if (buffer[len - 1] == '/') + { + buffer[len - 1] = '\0'; + } + + if (axis2_mkdir(buffer) == 0) + { + free(buffer); + return 1; + } + + p = buffer + 1; + while (loop_state) + { + axis2_char_t hold; + + while (*p && *p != '\\' && *p != '/') + p++; + hold = *p; + *p = 0; + if ((axis2_mkdir(buffer) == -1)) + { + free(buffer); + return 0; + } + if (hold == 0) + break; + *p++ = hold; + } + free(buffer); + return 1; +} + +int +axis2_extract_currentfile( + unzFile uf, + const int *popt_extract_without_path, + int *popt_overwrite, + const axis2_char_t *password) +{ + axis2_char_t filename_inzip[256]; + axis2_char_t *filename_withoutpath; + axis2_char_t *p; + int err = UNZ_OK; + FILE *fout = NULL; + void *buf; + uInt size_buf; + + unz_file_info file_info; + err = + unzGetCurrentFileInfo(uf, &file_info, filename_inzip, + sizeof(filename_inzip), NULL, 0, NULL, 0); + + if (err != UNZ_OK) + { + return err; + } + + size_buf = WRITEBUFFERSIZE; + buf = (void *) malloc(size_buf); + if (buf == NULL) + return UNZ_INTERNALERROR; + + p = filename_withoutpath = filename_inzip; + while ((*p) != '\0') + { + if (((*p) == '/') || ((*p) == '\\')) + filename_withoutpath = p + 1; + p++; + } + + if ((*filename_withoutpath) == '\0') + { + if ((*popt_extract_without_path) == 0) + { + axis2_mkdir(filename_inzip); + } + } + else + { + axis2_char_t *write_filename; + int skip = 0; + + if ((*popt_extract_without_path) == 0) + write_filename = filename_inzip; + else + write_filename = filename_withoutpath; + + err = unzOpenCurrentFilePassword(uf, password); + + if ((skip == 0) && (err == UNZ_OK)) + { + fout = fopen(write_filename, "wb"); + + if ((fout == NULL) && ((*popt_extract_without_path) == 0) && + (filename_withoutpath != (axis2_char_t *) filename_inzip)) + { + axis2_char_t c = *(filename_withoutpath - 1); + *(filename_withoutpath - 1) = '\0'; + axis2_create_dir(write_filename); + *(filename_withoutpath - 1) = c; + fout = fopen(write_filename, "wb"); + } + + } + + if (fout) + { + do + { + err = unzReadCurrentFile(uf, buf, size_buf); + if (err < 0) + { + break; + } + if (err > 0) + if (fwrite(buf, err, 1, fout) != 1) + { + err = UNZ_ERRNO; + break; + } + } + while (err > 0); + if (fout) + fclose(fout); + } + + if (err == UNZ_OK) + { + err = unzCloseCurrentFile(uf); + } + else + unzCloseCurrentFile(uf); + } + + free(buf); + return err; +} + +int +axis2_extract( + unzFile uf, + int opt_extract_without_path, + int opt_overwrite, + const axis2_char_t *password) +{ + uLong i; + unz_global_info gi; + int err; + + err = unzGetGlobalInfo(uf, &gi); + if (err != UNZ_OK) + return -1; + + for (i = 0; i < gi.number_entry; i++) + { + if (axis2_extract_currentfile(uf, &opt_extract_without_path, + &opt_overwrite, password) != UNZ_OK) + break; + + if ((i + 1) < gi.number_entry) + { + err = unzGoToNextFile(uf); + if (err != UNZ_OK) + { + return -1; + break; + } + } + } + + return 0; +} + +int +aar_extract( + axis2_char_t * d_name) +{ + const axis2_char_t *zipfilename = NULL; + const axis2_char_t *filename_to_extract = NULL; + const axis2_char_t *password = NULL; + axis2_char_t filename_try[MAXFILENAME + 16] = ""; + int opt_do_extract_withoutpath = 0; + int opt_overwrite = 0; + int opt_extractdir = 0; + const axis2_char_t *dir_name = NULL; + int ret = 0; + unzFile uf = NULL; + + if (zipfilename == NULL) + zipfilename = d_name; + + filename_to_extract = d_name; + + if (zipfilename) + { + zlib_filefunc_def ffunc; + strncpy(filename_try, zipfilename, MAXFILENAME - 1); + filename_try[MAXFILENAME] = '\0'; + + axis2_fill_win32_filefunc(&ffunc); + + uf = AXIS2_UNZOPEN2(zipfilename, ffunc); + + if (uf == NULL) + { + strcat(filename_try, ".zip"); + uf = AXIS2_UNZOPEN2(zipfilename, ffunc); + } + } + + if (uf == NULL) + return -1; + + if (opt_extractdir && AXIS2_CHDIR(dir_name)) + exit(-1); + + ret = axis2_extract(uf, opt_do_extract_withoutpath, opt_overwrite, + password); + /*unzCloseCurrentFile(uf);*/ + return ret; +} + +int +axis2_extract_onefile( + unzFile uf, + const axis2_char_t *filename, + int opt_extract_without_path, + int opt_overwrite, + const axis2_char_t *password) +{ + if (unzLocateFile(uf, filename, CASESENSITIVITY) != UNZ_OK) + return -1; + + if (axis2_extract_currentfile(uf, &opt_extract_without_path, + &opt_overwrite, password) == UNZ_OK) + return 0; + else + return -1; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_archive_extract( + ) +{ + struct dirent **namelist; + int n, + i; + axis2_char_t *ptr; + +#ifdef WIN32 + n = axis2_scandir(".", &namelist, 0, alphasort); +#else + n = scandir(".", &namelist, 0, alphasort); +#endif + + if (n < 0) + return AXIS2_FALSE; + else + { + while (n--) + { + if ((strcmp(namelist[n]->d_name, ".") == 0) || + (strcmp(namelist[n]->d_name, "..") == 0)) + { + for (i = n; i >= 0; i--) /* clean remaining memory before return */ + free(namelist[i]); + free(namelist); + return (AXIS2_FALSE); + } + + ptr = axutil_rindex(namelist[n]->d_name, '.'); + if ((ptr) && + (((strcmp(ptr, AXIS2_AAR_SUFFIX) == 0)) || + (strcmp(ptr, AXIS2_MAR_SUFFIX) == 0))) + for (i = 0; i < n; i++) + if (strncmp + (namelist[n]->d_name, namelist[i]->d_name, + strlen(namelist[i]->d_name)) == 0) + { + int j; + for (j = n; j >= 0; j--) /* clean remaining memory before return */ + free(namelist[j]); + free(namelist); + return (AXIS2_FALSE); + } + + aar_extract(namelist[n]->d_name); + free(namelist[n]); + } + free(namelist); + } + return (AXIS2_TRUE); +} diff --git a/util/src/minizip/axis2_archive_extract.h b/util/src/minizip/axis2_archive_extract.h new file mode 100644 index 0000000..92cbab6 --- /dev/null +++ b/util/src/minizip/axis2_archive_extract.h @@ -0,0 +1,35 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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_ARCHIVE_EXTRACT_H +#define AXIS2_ARCHIVE_EXTRACT_H + +#ifdef __cplusplus +extern "C" +{ +#endif + + AXIS2_EXTERN axis2_status_t AXIS2_CALL + axis2_archive_extract( + ); + +#ifdef __cplusplus +} +#endif + +#endif /** AXIS2_ARCHIVE_EXTRACT_H */ diff --git a/util/src/minizip/axis2_crypt.h b/util/src/minizip/axis2_crypt.h new file mode 100644 index 0000000..dcdf524 --- /dev/null +++ b/util/src/minizip/axis2_crypt.h @@ -0,0 +1,94 @@ + +/* + * 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. +*/ + +/* crypt.h -- base code for crypt/uncrypt ZIPfile + + Version 1.01e, February 12th, 2005 + + Copyright (C) 1998-2005 Gilles Vollant + + This code is a modified version of crypting code in Infozip distribution + + The encryption/decryption parts of this source code (as opposed to the + non-echoing password parts) were originally written in Europe. The + whole source package can be freely distributed, including from the USA. + (Prior to January 2000, re-export from the US was a violation of US law.) + + This encryption code is a direct transcription of the algorithm from + Roger Schlafly, described by Phil Katz in the file appnote.txt. This + file (appnote.txt) is distributed with the PKZIP program (even in the + version without encryption capabilities). + + If you don't need crypting in your application, just define symbols + NOCRYPT and NOUNCRYPT. + + This code support the "Traditional PKWARE Encryption". + + The new AES encryption added on Zip format by Winzip (see the page + http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong + Encryption is not supported. +*/ + +#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) + +/*********************************************************************** + * Return the next byte in the pseudo-random sequence + */ +int decrypt_byte( + unsigned long *pkeys, + const unsigned long *pcrc_32_tab); + +/*********************************************************************** + * Update the encryption keys with the next byte of plain text + */ +int update_keys( + unsigned long *pkeys, + const unsigned long *pcrc_32_tab, + int c); + +/*********************************************************************** + * Initialize the encryption keys and the random header according to + * the given password. + */ +void init_keys( + const char *passwd, + unsigned long *pkeys, + const unsigned long *pcrc_32_tab); + +#define zdecode(pkeys,pcrc_32_tab,c) \ + (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) + +#define zencode(pkeys,pcrc_32_tab,c,t) \ + (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) + +#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED + +#define RAND_HEAD_LEN 12 +/* "last resort" source for second part of crypt seed pattern */ +# ifndef ZCR_SEED2 +# define ZCR_SEED2 3141592654UL /* use PI as default pattern */ +# endif + +int crypthead( + passwd, + buf, + bufSize, + pkeys, + pcrc_32_tab, + crcForCrypting); + +#endif diff --git a/util/src/minizip/axis2_ioapi.h b/util/src/minizip/axis2_ioapi.h new file mode 100644 index 0000000..8f14574 --- /dev/null +++ b/util/src/minizip/axis2_ioapi.h @@ -0,0 +1,118 @@ + +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The ASF licenses this file to You 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. +*/ + +/* ioapi.h -- IO base function header for compress/uncompress .zip + files using zlib + zip or unzip API + + Version 1.01e, February 12th, 2005 + + Copyright (C) 1998-2005 Gilles Vollant +*/ + +#ifndef _ZLIBIOAPI_H +#define _ZLIBIOAPI_H + +#define ZLIB_FILEFUNC_SEEK_CUR (1) +#define ZLIB_FILEFUNC_SEEK_END (2) +#define ZLIB_FILEFUNC_SEEK_SET (0) + +#define ZLIB_FILEFUNC_MODE_READ (1) +#define ZLIB_FILEFUNC_MODE_WRITE (2) +#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) + +#define ZLIB_FILEFUNC_MODE_EXISTING (4) +#define ZLIB_FILEFUNC_MODE_CREATE (8) + +#ifndef ZCALLBACK + +#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) +#define ZCALLBACK CALLBACK +#else +#define ZCALLBACK +#endif +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef voidpf( + ZCALLBACK * open_file_func) OF( + (voidpf opaque, + const char *filename, + int mode)); + typedef uLong( + ZCALLBACK * read_file_func) OF( + (voidpf opaque, + voidpf stream, + void *buf, + uLong size)); + typedef uLong( + ZCALLBACK * write_file_func) OF( + (voidpf opaque, + voidpf stream, + const void *buf, + uLong size)); + typedef long( + ZCALLBACK * tell_file_func) OF( + (voidpf opaque, + voidpf stream)); + typedef long( + ZCALLBACK * seek_file_func) OF( + (voidpf opaque, + voidpf stream, + uLong offset, + int origin)); + typedef int( + ZCALLBACK * close_file_func) OF( + (voidpf opaque, + voidpf stream)); + typedef int( + ZCALLBACK * testerror_file_func) OF( + (voidpf opaque, + voidpf stream)); + + typedef struct zlib_filefunc_def_s + { + open_file_func zopen_file; + read_file_func zread_file; + write_file_func zwrite_file; + tell_file_func ztell_file; + seek_file_func zseek_file; + close_file_func zclose_file; + testerror_file_func zerror_file; + voidpf opaque; + } + zlib_filefunc_def; + + void fill_fopen_filefunc OF( + (zlib_filefunc_def * pzlib_filefunc_def)); + +#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size)) +#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size)) +#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream)) +#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode)) +#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream)) +#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream)) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/util/src/minizip/axis2_iowin32.h b/util/src/minizip/axis2_iowin32.h new file mode 100644 index 0000000..bfe95cf --- /dev/null +++ b/util/src/minizip/axis2_iowin32.h @@ -0,0 +1,40 @@ + +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The ASF licenses this file to You 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. +*/ + +/* iowin32.h -- IO base function header for compress/uncompress .zip + files using zlib + zip or unzip API + This IO API version uses the Win32 API (for Microsoft Windows) + + Version 1.01e, February 12th, 2005 + + Copyright (C) 1998-2005 Gilles Vollant +*/ + +#include <windows.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + + void fill_win32_filefunc OF( + (zlib_filefunc_def * pzlib_filefunc_def)); + +#ifdef __cplusplus +} +#endif diff --git a/util/src/minizip/axis2_unzip.h b/util/src/minizip/axis2_unzip.h new file mode 100644 index 0000000..f2e1f19 --- /dev/null +++ b/util/src/minizip/axis2_unzip.h @@ -0,0 +1,417 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +/* unzip.h -- IO for uncompress .zip files using zlib + Version 1.01e, February 12th, 2005 + + Copyright (C) 1998-2005 Gilles Vollant + + This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g + WinZip, InfoZip tools and compatible. + + Multi volume ZipFile (span) are not supported. + Encryption compatible with pkzip 2.04g only supported + Old compressions used by old PKZip 1.x are not supported + + I WAIT FEEDBACK at mail info@winimage.com + Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution + + Condition of use and distribution are the same than zlib : + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + +*/ + +/* for more info about .ZIP format, see + http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip + http://www.info-zip.org/pub/infozip/doc/ + PkWare has also a specification at : + ftp://ftp.pkware.com/probdesc.zip +*/ + +#ifndef _unz_H +#define _unz_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#ifndef _ZLIB_H +#include "zlib.h" +#endif + +#ifndef _ZLIBIOAPI_H +#include "axis2_ioapi.h" +#endif + +#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) + + /* like the STRICT of WIN32, we define a pointer that cannot be converted + from (void*) without cast */ + typedef struct TagunzFile__ + { + int unused; + } + unzFile__; + typedef unzFile__ *unzFile; +#else + typedef voidp unzFile; +#endif + +#define UNZ_OK (0) +#define UNZ_END_OF_LIST_OF_FILE (-100) +#define UNZ_ERRNO (Z_ERRNO) +#define UNZ_EOF (0) +#define UNZ_PARAMERROR (-102) +#define UNZ_BADZIPFILE (-103) +#define UNZ_INTERNALERROR (-104) +#define UNZ_CRCERROR (-105) + + /* tm_unz contain date/time info */ + typedef struct tm_unz_s + { + uInt tm_sec; /* seconds after the minute - [0,59] */ + uInt tm_min; /* minutes after the hour - [0,59] */ + uInt tm_hour; /* hours since midnight - [0,23] */ + uInt tm_mday; /* day of the month - [1,31] */ + uInt tm_mon; /* months since January - [0,11] */ + uInt tm_year; /* years - [1980..2044] */ + } + tm_unz; + + /* unz_global_info structure contain global data about the ZIPfile + These data comes from the end of central dir */ + typedef struct unz_global_info_s + { + uLong number_entry; /* total number of entries in + the central dir on this disk */ + uLong size_comment; /* size of the global comment of the zipfile */ + } + unz_global_info; + + /* unz_file_info contain information about a file in the zipfile */ + typedef struct unz_file_info_s + { + uLong version; /* version made by 2 bytes */ + uLong version_needed; /* version needed to extract 2 bytes */ + uLong flag; /* general purpose bit flag 2 bytes */ + uLong compression_method; /* compression method 2 bytes */ + uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ + uLong crc; /* crc-32 4 bytes */ + uLong compressed_size; /* compressed size 4 bytes */ + uLong uncompressed_size; /* uncompressed size 4 bytes */ + uLong size_filename; /* filename length 2 bytes */ + uLong size_file_extra; /* extra field length 2 bytes */ + uLong size_file_comment; /* file comment length 2 bytes */ + + uLong disk_num_start; /* disk number start 2 bytes */ + uLong internal_fa; /* internal file attributes 2 bytes */ + uLong external_fa; /* external file attributes 4 bytes */ + + tm_unz tmu_date; + } + unz_file_info; + + extern int ZEXPORT unzStringFileNameCompare OF( + (const char *fileName1, + const char *fileName2, + int iCaseSensitivity)); + + /* + Compare two filename (fileName1,fileName2). + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + or strcasecmp) + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + (like 1 on Unix, 2 on Windows) + */ + + extern unzFile ZEXPORT unzOpen OF( + (const char *path)); + + /* + Open a Zip file. path contain the full pathname (by example, + on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer + "zlib/zlib113.zip". + If the zipfile cannot be opened (file don't exist or in not valid), the + return value is NULL. + Else, the return value is a unzFile Handle, usable with other function + of this unzip package. + */ + + extern unzFile ZEXPORT unzOpen2 OF( + (const char *path, + zlib_filefunc_def * pzlib_filefunc_def)); + + /* + Open a Zip file, like unzOpen, but provide a set of file low level API + for read/write the zip file (see axis2_ioapi.h) + */ + + extern int ZEXPORT unzClose OF( + (unzFile file)); + + /* + Close a ZipFile opened with unzipOpen. + If there is files inside the .Zip opened with unzOpenCurrentFile (see later), + these files MUST be closed with unzipCloseCurrentFile before call unzipClose. + return UNZ_OK if there is no problem. */ + + extern int ZEXPORT unzGetGlobalInfo OF( + (unzFile file, + unz_global_info * pglobal_info)); + + /* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. */ + + extern int ZEXPORT unzGetGlobalComment OF( + (unzFile file, + char *szComment, + uLong uSizeBuf)); + + /* + Get the global comment string of the ZipFile, in the szComment buffer. + uSizeBuf is the size of the szComment buffer. + return the number of byte copied or an error code <0 + */ + + /***************************************************************************/ + + /* Unzip package allow you browse the directory of the zipfile */ + + extern int ZEXPORT unzGoToFirstFile OF( + (unzFile file)); + + /* + Set the current file of the zipfile to the first file. + return UNZ_OK if there is no problem + */ + + extern int ZEXPORT unzGoToNextFile OF( + (unzFile file)); + + /* + Set the current file of the zipfile to the next file. + return UNZ_OK if there is no problem + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. + */ + + extern int ZEXPORT unzLocateFile OF( + (unzFile file, + const char *szFileName, + int iCaseSensitivity)); + + /* + Try locate the file szFileName in the zipfile. + For the iCaseSensitivity signification, see unzStringFileNameCompare + + return value : + UNZ_OK if the file is found. It becomes the current file. + UNZ_END_OF_LIST_OF_FILE if the file is not found + */ + + /* ****************************************** */ + + /* Ryan supplied functions */ + + /* unz_file_info contain information about a file in the zipfile */ + typedef struct unz_file_pos_s + { + uLong pos_in_zip_directory; /* offset in zip file directory */ + uLong num_of_file; /* # of file */ + } + unz_file_pos; + + extern int ZEXPORT unzGetFilePos( + unzFile file, + unz_file_pos * file_pos); + + extern int ZEXPORT unzGoToFilePos( + unzFile file, + unz_file_pos * file_pos); + + /* ****************************************** */ + + extern int ZEXPORT unzGetCurrentFileInfo OF( + (unzFile file, + unz_file_info * pfile_info, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); + + /* + Get Info about the current file + if pfile_info!=NULL, the *pfile_info structure will contain somes info about + the current file + if szFileName!=NULL, the filemane string will be copied in szFileName + (fileNameBufferSize is the size of the buffer) + if extraField!=NULL, the extra field information will be copied in extraField + (extraFieldBufferSize is the size of the buffer). + This is the Central-header version of the extra field + if szComment!=NULL, the comment string of the file will be copied in szComment + (commentBufferSize is the size of the buffer) + */ + + /***************************************************************************/ + + /* for reading the content of the current zipfile, you can open it, read data + from it, and close it (you can close it before reading all the file) + */ + + extern int ZEXPORT unzOpenCurrentFile OF( + (unzFile file)); + + /* + Open for reading data the current file in the zipfile. + If there is no error, the return value is UNZ_OK. + */ + + extern int ZEXPORT unzOpenCurrentFilePassword OF( + (unzFile file, + const char *password)); + + /* + Open for reading data the current file in the zipfile. + password is a crypting password + If there is no error, the return value is UNZ_OK. + */ + + extern int ZEXPORT unzOpenCurrentFile2 OF( + (unzFile file, + int *method, + int *level, + int raw)); + + /* + Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) + if raw==1 + *method will receive method of compression, *level will receive level of + compression + note : you can set level parameter as NULL (if you did not want known level, + but you CANNOT set method parameter as NULL + */ + + extern int ZEXPORT unzOpenCurrentFile3 OF( + (unzFile file, + int *method, + int *level, + int raw, + const char *password)); + + /* + Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) + if raw==1 + *method will receive method of compression, *level will receive level of + compression + note : you can set level parameter as NULL (if you did not want known level, + but you CANNOT set method parameter as NULL + */ + + extern int ZEXPORT unzCloseCurrentFile OF( + (unzFile file)); + + /* + Close the file in zip opened with unzOpenCurrentFile + Return UNZ_CRCERROR if all the file was read but the CRC is not good + */ + + extern int ZEXPORT unzReadCurrentFile OF( + (unzFile file, + voidp buf, + unsigned len)); + + /* + Read bytes from the current file (opened by unzOpenCurrentFile) + buf contain buffer where data must be copied + len the size of buf. + + return the number of byte copied if somes bytes are copied + return 0 if the end of file was reached + return <0 with error code if there is an error + (UNZ_ERRNO for IO error, or zLib error for uncompress error) + */ + + extern z_off_t ZEXPORT unztell OF( + (unzFile file)); + + /* + Give the current position in uncompressed data + */ + + extern int ZEXPORT unzeof OF( + (unzFile file)); + + /* + return 1 if the end of file was reached, 0 elsewhere + */ + + extern int ZEXPORT unzGetLocalExtrafield OF( + (unzFile file, + voidp buf, + unsigned len)); + + /* + Read extra field from the current file (opened by unzOpenCurrentFile) + This is the local-header version of the extra field (sometimes, there is + more info in the local-header version than in the central-header) + + if buf==NULL, it return the size of the local extra field + + if buf!=NULL, len is the size of the buffer, the extra header is copied in + buf. + the return value is the number of bytes copied in buf, or (if <0) + the error code + */ + + /***************************************************************************/ + + /* Get the current file offset */ + extern uLong ZEXPORT unzGetOffset( + unzFile file); + + /* Set the current file offset */ + extern int ZEXPORT unzSetOffset( + unzFile file, + uLong pos); + +#ifdef __cplusplus +} +#endif + +#endif /* _unz_H */ diff --git a/util/src/minizip/crypt.c b/util/src/minizip/crypt.c new file mode 100644 index 0000000..bf2b1d8 --- /dev/null +++ b/util/src/minizip/crypt.c @@ -0,0 +1,172 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +/* crypt.h -- base code for crypt/uncrypt ZIPfile + + Version 1.01e, February 12th, 2005 + + Copyright (C) 1998-2005 Gilles Vollant + + This code is a modified version of crypting code in Infozip distribution + + The encryption/decryption parts of this source code (as opposed to the + non-echoing password parts) were originally written in Europe. The + whole source package can be freely distributed, including from the USA. + (Prior to January 2000, re-export from the US was a violation of US law.) + + This encryption code is a direct transcription of the algorithm from + Roger Schlafly, described by Phil Katz in the file appnote.txt. This + file (appnote.txt) is distributed with the PKZIP program (even in the + version without encryption capabilities). + + If you don't need crypting in your application, just define symbols + NOCRYPT and NOUNCRYPT. + + This code support the "Traditional PKWARE Encryption". + + The new AES encryption added on Zip format by Winzip (see the page + http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong + Encryption is not supported. +*/ + +#include <axis2_crypt.h> + +#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) + +/*********************************************************************** + * Return the next byte in the pseudo-random sequence + */ +int +decrypt_byte( + unsigned long *pkeys, + const unsigned long *pcrc_32_tab) +{ + unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an + * unpredictable manner on 16-bit systems; not a problem + * with any known compiler so far, though */ + + temp = ((unsigned) (*(pkeys + 2)) & 0xffff) | 2; + return (int) (((temp * (temp ^ 1)) >> 8) & 0xff); +} + +/*********************************************************************** + * Update the encryption keys with the next byte of plain text + */ +int +update_keys( + unsigned long *pkeys, + const unsigned long *pcrc_32_tab, + int c) +{ + (*(pkeys + 0)) = CRC32((*(pkeys + 0)), c); + (*(pkeys + 1)) += (*(pkeys + 0)) & 0xff; + (*(pkeys + 1)) = (*(pkeys + 1)) * 134775813L + 1; + { + register int keyshift = (int) ((*(pkeys + 1)) >> 24); + (*(pkeys + 2)) = CRC32((*(pkeys + 2)), keyshift); + } + return c; +} + +/*********************************************************************** + * Initialize the encryption keys and the random header according to + * the given password. + */ +void +init_keys( + const char *passwd, + unsigned long *pkeys, + const unsigned long *pcrc_32_tab) +{ + *(pkeys + 0) = 305419896L; + *(pkeys + 1) = 591751049L; + *(pkeys + 2) = 878082192L; + while (*passwd != '\0') + { + update_keys(pkeys, pcrc_32_tab, (int) *passwd); + passwd++; + } +} + +#define zdecode(pkeys,pcrc_32_tab,c) \ + (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) + +#define zencode(pkeys,pcrc_32_tab,c,t) \ + (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) + +#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED + +#define RAND_HEAD_LEN 12 + +/* "last resort" source for second part of crypt seed pattern */ +# ifndef ZCR_SEED2 +# define ZCR_SEED2 3141592654UL /* use PI as default pattern */ +# endif + +int +crypthead( + passwd, + buf, + bufSize, + pkeys, + pcrc_32_tab, + crcForCrypting) + const char *passwd; /* password string */ + unsigned char *buf; /* where to write header */ + int bufSize; + unsigned long *pkeys; + const unsigned long *pcrc_32_tab; + unsigned long crcForCrypting; +{ + int n; /* index in random header */ + int t; /* temporary */ + int c; /* random byte */ + unsigned char header[RAND_HEAD_LEN - 2]; /* random header */ + static unsigned calls = 0; /* ensure different random header each time */ + + if (bufSize < RAND_HEAD_LEN) + return 0; + + /* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the + * output of rand() to get less predictability, since rand() is + * often poorly implemented. + */ + if (++calls == 1) + { + srand((unsigned) (time(NULL) ^ ZCR_SEED2)); + } + init_keys(passwd, pkeys, pcrc_32_tab); + for (n = 0; n < RAND_HEAD_LEN - 2; n++) + { + c = (rand() >> 7) & 0xff; + header[n] = (unsigned char) zencode(pkeys, pcrc_32_tab, c, t); + } + /* Encrypt random header (last two bytes is high word of crc) */ + init_keys(passwd, pkeys, pcrc_32_tab); + for (n = 0; n < RAND_HEAD_LEN - 2; n++) + { + buf[n] = (unsigned char) zencode(pkeys, pcrc_32_tab, header[n], t); + } + buf[n++] = + zencode(pkeys, pcrc_32_tab, (int) (crcForCrypting >> 16) & 0xff, t); + buf[n++] = + zencode(pkeys, pcrc_32_tab, (int) (crcForCrypting >> 24) & 0xff, t); + return n; +} + +#endif diff --git a/util/src/minizip/ioapi.c b/util/src/minizip/ioapi.c new file mode 100644 index 0000000..7a0ac22 --- /dev/null +++ b/util/src/minizip/ioapi.c @@ -0,0 +1,197 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +/* ioapi.c -- IO base function header for compress/uncompress .zip + files using zlib + zip or unzip API + + Version 1.01e, February 12th, 2005 + + Copyright (C) 1998-2005 Gilles Vollant +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "zlib.h" +#include "axis2_ioapi.h" + +/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ + +#ifndef SEEK_CUR +#define SEEK_CUR 1 +#endif + +#ifndef SEEK_END +#define SEEK_END 2 +#endif + +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif + +voidpf ZCALLBACK fopen_file_func OF( + (voidpf opaque, + const char *filename, + int mode)); + +uLong ZCALLBACK fread_file_func OF( + (voidpf opaque, + voidpf stream, + void *buf, + uLong size)); + +uLong ZCALLBACK fwrite_file_func OF( + (voidpf opaque, + voidpf stream, + const void *buf, + uLong size)); + +long ZCALLBACK ftell_file_func OF( + (voidpf opaque, + voidpf stream)); + +long ZCALLBACK fseek_file_func OF( + (voidpf opaque, + voidpf stream, + uLong offset, + int origin)); + +int ZCALLBACK fclose_file_func OF( + (voidpf opaque, + voidpf stream)); + +int ZCALLBACK ferror_file_func OF( + (voidpf opaque, + voidpf stream)); + +voidpf ZCALLBACK +fopen_file_func( + voidpf opaque, + const char *filename, + int mode) +{ + FILE *file = NULL; + const char *mode_fopen = NULL; + if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ) + mode_fopen = "rb"; + else if (mode & ZLIB_FILEFUNC_MODE_EXISTING) + mode_fopen = "r+b"; + else if (mode & ZLIB_FILEFUNC_MODE_CREATE) + mode_fopen = "wb"; + + if ((filename) && (mode_fopen != NULL)) + file = fopen(filename, mode_fopen); + return file; +} + +uLong ZCALLBACK +fread_file_func( + voidpf opaque, + voidpf stream, + void *buf, + uLong size) +{ + uLong ret; + ret = (uLong) fread(buf, 1, (size_t) size, (FILE *) stream); + return ret; +} + +uLong ZCALLBACK +fwrite_file_func( + voidpf opaque, + voidpf stream, + const void *buf, + uLong size) +{ + uLong ret; + ret = (uLong) fwrite(buf, 1, (size_t) size, (FILE *) stream); + return ret; +} + +long ZCALLBACK +ftell_file_func( + voidpf opaque, + voidpf stream) +{ + long ret; + ret = ftell((FILE *) stream); + return ret; +} + +long ZCALLBACK +fseek_file_func( + voidpf opaque, + voidpf stream, + uLong offset, + int origin) +{ + int fseek_origin = 0; + long ret; + switch (origin) + { + case ZLIB_FILEFUNC_SEEK_CUR: + fseek_origin = SEEK_CUR; + break; + case ZLIB_FILEFUNC_SEEK_END: + fseek_origin = SEEK_END; + break; + case ZLIB_FILEFUNC_SEEK_SET: + fseek_origin = SEEK_SET; + break; + default: + return -1; + } + ret = 0; + fseek((FILE *) stream, offset, fseek_origin); + return ret; +} + +int ZCALLBACK +fclose_file_func( + voidpf opaque, + voidpf stream) +{ + int ret; + ret = fclose((FILE *) stream); + return ret; +} + +int ZCALLBACK +ferror_file_func( + voidpf opaque, + voidpf stream) +{ + int ret; + ret = ferror((FILE *) stream); + return ret; +} + +void +fill_fopen_filefunc( + zlib_filefunc_def *pzlib_filefunc_def) +{ + pzlib_filefunc_def->zopen_file = fopen_file_func; + pzlib_filefunc_def->zread_file = fread_file_func; + pzlib_filefunc_def->zwrite_file = fwrite_file_func; + pzlib_filefunc_def->ztell_file = ftell_file_func; + pzlib_filefunc_def->zseek_file = fseek_file_func; + pzlib_filefunc_def->zclose_file = fclose_file_func; + pzlib_filefunc_def->zerror_file = ferror_file_func; + pzlib_filefunc_def->opaque = NULL; +} diff --git a/util/src/minizip/iowin32.c b/util/src/minizip/iowin32.c new file mode 100644 index 0000000..f774437 --- /dev/null +++ b/util/src/minizip/iowin32.c @@ -0,0 +1,300 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +/* iowin32.c -- IO base function header for compress/uncompress .zip + files using zlib + zip or unzip API + This IO API version uses the Win32 API (for Microsoft Windows) + + Version 1.01e, February 12th, 2005 + + Copyright (C) 1998-2005 Gilles Vollant +*/ + +#include <stdlib.h> + +#include "zlib.h" +#include "axis2_ioapi.h" +#include "axis2_iowin32.h" + +#ifndef INVALID_HANDLE_VALUE +#define INVALID_HANDLE_VALUE (0xFFFFFFFF) +#endif + +#ifndef INVALID_SET_FILE_POINTER +#define INVALID_SET_FILE_POINTER ((DWORD)-1) +#endif + +voidpf ZCALLBACK win32_open_file_func OF( + (voidpf opaque, + const char *filename, + int mode)); + +uLong ZCALLBACK win32_read_file_func OF( + (voidpf opaque, + voidpf stream, + void *buf, + uLong size)); + +uLong ZCALLBACK win32_write_file_func OF( + (voidpf opaque, + voidpf stream, + const void *buf, + uLong size)); + +long ZCALLBACK win32_tell_file_func OF( + (voidpf opaque, + voidpf stream)); + +long ZCALLBACK win32_seek_file_func OF( + (voidpf opaque, + voidpf stream, + uLong offset, + int origin)); + +int ZCALLBACK win32_close_file_func OF( + (voidpf opaque, + voidpf stream)); + +int ZCALLBACK win32_error_file_func OF( + (voidpf opaque, + voidpf stream)); + +typedef struct +{ + HANDLE hf; + int error; +} +WIN32FILE_IOWIN; + +voidpf ZCALLBACK +win32_open_file_func( + voidpf opaque, + const char *filename, + int mode) +{ + /*const char *mode_fopen = NULL;*/ + DWORD dwDesiredAccess, + dwCreationDisposition, + dwShareMode, + dwFlagsAndAttributes; + HANDLE hFile = 0; + voidpf ret = NULL; + + dwDesiredAccess = dwShareMode = dwFlagsAndAttributes = dwCreationDisposition = 0; + /* dwCreationDisposition = 0, to avoid C4701 */ + + if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ) + { + dwDesiredAccess = GENERIC_READ; + dwCreationDisposition = OPEN_EXISTING; + dwShareMode = FILE_SHARE_READ; + } + else if (mode & ZLIB_FILEFUNC_MODE_EXISTING) + { + dwDesiredAccess = GENERIC_WRITE | GENERIC_READ; + dwCreationDisposition = OPEN_EXISTING; + } + else if (mode & ZLIB_FILEFUNC_MODE_CREATE) + { + dwDesiredAccess = GENERIC_WRITE | GENERIC_READ; + dwCreationDisposition = CREATE_ALWAYS; + } + + if ((filename) && (dwDesiredAccess != 0)) + hFile = + CreateFile((LPCTSTR) filename, dwDesiredAccess, dwShareMode, NULL, + dwCreationDisposition, dwFlagsAndAttributes, NULL); + + if (hFile == INVALID_HANDLE_VALUE) + hFile = NULL; + + if (hFile) + { + WIN32FILE_IOWIN w32fiow; + w32fiow.hf = hFile; + w32fiow.error = 0; + ret = malloc(sizeof(WIN32FILE_IOWIN)); + if (ret == NULL) + CloseHandle(hFile); + else + *((WIN32FILE_IOWIN *) ret) = w32fiow; + } + return ret; +} + +uLong ZCALLBACK +win32_read_file_func( + voidpf opaque, + voidpf stream, + void *buf, + uLong size) +{ + uLong ret = 0; + HANDLE hFile = NULL; + if (stream) + hFile = ((WIN32FILE_IOWIN *) stream)->hf; + if (hFile) + if (!ReadFile(hFile, buf, size, &ret, NULL)) + { + DWORD dwErr = GetLastError(); + if (dwErr == ERROR_HANDLE_EOF) + dwErr = 0; + ((WIN32FILE_IOWIN *) stream)->error = (int) dwErr; + } + + return ret; +} + +uLong ZCALLBACK +win32_write_file_func( + voidpf opaque, + voidpf stream, + const void *buf, + uLong size) +{ + uLong ret = 0; + HANDLE hFile = NULL; + if (stream) + hFile = ((WIN32FILE_IOWIN *) stream)->hf; + + if (hFile) + if (!WriteFile(hFile, buf, size, &ret, NULL)) + { + DWORD dwErr = GetLastError(); + if (dwErr == ERROR_HANDLE_EOF) + dwErr = 0; + ((WIN32FILE_IOWIN *) stream)->error = (int) dwErr; + } + + return ret; +} + +long ZCALLBACK +win32_tell_file_func( + voidpf opaque, + voidpf stream) +{ + long ret = -1; + HANDLE hFile = NULL; + if (stream) + hFile = ((WIN32FILE_IOWIN *) stream)->hf; + if (hFile) + { + DWORD dwSet = SetFilePointer(hFile, 0, NULL, FILE_CURRENT); + if (dwSet == INVALID_SET_FILE_POINTER) + { + DWORD dwErr = GetLastError(); + ((WIN32FILE_IOWIN *) stream)->error = (int) dwErr; + ret = -1; + } + else + ret = (long) dwSet; + } + return ret; +} + +long ZCALLBACK +win32_seek_file_func( + voidpf opaque, + voidpf stream, + uLong offset, + int origin) +{ + DWORD dwMoveMethod = 0xFFFFFFFF; + HANDLE hFile = NULL; + + long ret = -1; + if (stream) + hFile = ((WIN32FILE_IOWIN *) stream)->hf; + switch (origin) + { + case ZLIB_FILEFUNC_SEEK_CUR: + dwMoveMethod = FILE_CURRENT; + break; + case ZLIB_FILEFUNC_SEEK_END: + dwMoveMethod = FILE_END; + break; + case ZLIB_FILEFUNC_SEEK_SET: + dwMoveMethod = FILE_BEGIN; + break; + default: + return -1; + } + + if (hFile) + { + DWORD dwSet = SetFilePointer(hFile, offset, NULL, dwMoveMethod); + if (dwSet == INVALID_SET_FILE_POINTER) + { + DWORD dwErr = GetLastError(); + ((WIN32FILE_IOWIN *) stream)->error = (int) dwErr; + ret = -1; + } + else + ret = 0; + } + return ret; +} + +int ZCALLBACK +win32_close_file_func( + voidpf opaque, + voidpf stream) +{ + int ret = -1; + + if (stream) + { + HANDLE hFile; + hFile = ((WIN32FILE_IOWIN *) stream)->hf; + if (hFile) + { + CloseHandle(hFile); + ret = 0; + } + free(stream); + } + return ret; +} + +int ZCALLBACK +win32_error_file_func( + voidpf opaque, + voidpf stream) +{ + int ret = -1; + if (stream) + { + ret = ((WIN32FILE_IOWIN *) stream)->error; + } + return ret; +} + +void +fill_win32_filefunc( + zlib_filefunc_def *pzlib_filefunc_def) +{ + pzlib_filefunc_def->zopen_file = win32_open_file_func; + pzlib_filefunc_def->zread_file = win32_read_file_func; + pzlib_filefunc_def->zwrite_file = win32_write_file_func; + pzlib_filefunc_def->ztell_file = win32_tell_file_func; + pzlib_filefunc_def->zseek_file = win32_seek_file_func; + pzlib_filefunc_def->zclose_file = win32_close_file_func; + pzlib_filefunc_def->zerror_file = win32_error_file_func; + pzlib_filefunc_def->opaque = NULL; +} diff --git a/util/src/minizip/unzip.c b/util/src/minizip/unzip.c new file mode 100644 index 0000000..146d93a --- /dev/null +++ b/util/src/minizip/unzip.c @@ -0,0 +1,1655 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +/* unzip.c -- IO for uncompress .zip files using zlib + * Version 1.01e, February 12th, 2005 + * + * Copyright (C) 1998-2005 Gilles Vollant + * + * Read axis2_unzip.h for more info + * + * + * Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of + * compatibility with older software. The following is from the original crypt.c. Code + * woven in by Terry Thorsen 1/2003. + * + * + * + * Copyright (c) 1990-2000 Info-ZIP. All rights reserved. + * + * See the accompanying file LICENSE, version 2000-Apr-09 or later + * (the contents of which are also included in zip.h) for terms of use. + * If, for some reason, all these files are missing, the Info-ZIP license + * also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html + * + * + * + * crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h] + * + * The encryption/decryption parts of this source code (as opposed to the + * non-echoing password parts) were originally written in Europe. The + * whole source package can be freely distributed, including from the USA. + * (Prior to January 2000, re-export from the US was a violation of US law.) + * + * + * + * This encryption code is a direct transcription of the algorithm from + * Roger Schlafly, described by Phil Katz in the file appnote.txt. This + * file (appnote.txt) is distributed with the PKZIP program (even in the + * version without encryption capabilities). + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "zlib.h" +#include "axis2_unzip.h" + +#ifdef STDC +# include <stddef.h> +# include <string.h> +# include <stdlib.h> +#endif +#ifdef NO_ERRNO_H +extern int errno; +#else +# include <errno.h> +#endif + +#ifndef local +# define local static +#endif + +/* compile with -Dlocal if your debugger can't find static symbols */ + +#ifndef CASESENSITIVITYDEFAULT_NO +# if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) +# define CASESENSITIVITYDEFAULT_NO +# endif +#endif + +#ifndef UNZ_BUFSIZE +#define UNZ_BUFSIZE (16384) +#endif + +#ifndef UNZ_MAXFILENAMEINZIP +#define UNZ_MAXFILENAMEINZIP (256) +#endif + +#ifndef ALLOC +# define ALLOC(size) (malloc(size)) +#endif +#ifndef TRYFREE +# define TRYFREE(p) {if (p) free(p);} +#endif + +#define SIZECENTRALDIRITEM (0x2e) +#define SIZEZIPLOCALHEADER (0x1e) + +const char unz_copyright[] = + " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; + +/* unz_file_info_interntal contain internal info about a file in zipfile*/ +typedef struct unz_file_info_internal_s +{ + uLong offset_curfile; /* relative offset of local header 4 bytes */ +} +unz_file_info_internal; + +/* + * file_in_zip_read_info_s contain internal information about a file in zipfile, + * when reading and decompress it + */ +typedef struct +{ + char *read_buffer; /* internal buffer for compressed data */ + z_stream stream; /* zLib stream structure for inflate */ + + uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek */ + uLong stream_initialised; /* flag set if stream structure is initialised */ + + uLong offset_local_extrafield; /* offset of the local extra field */ + uInt size_local_extrafield; /* size of the local extra field */ + uLong pos_local_extrafield; /* position in the local extra field in read */ + + uLong crc32; /* crc32 of all data uncompressed */ + uLong crc32_wait; /* crc32 we must obtain after decompress all */ + uLong rest_read_compressed; /* number of byte to be decompressed */ + uLong rest_read_uncompressed; /*number of byte to be obtained after decomp */ + zlib_filefunc_def z_filefunc; + voidpf filestream; /* io structore of the zipfile */ + uLong compression_method; /* compression method (0==store) */ + uLong byte_before_the_zipfile; /* byte before the zipfile, (>0 for sfx) */ + int raw; +} +file_in_zip_read_info_s; + +/* unz_s contain internal information about the zipfile */ +typedef struct +{ + zlib_filefunc_def z_filefunc; + voidpf filestream; /* io structore of the zipfile */ + unz_global_info gi; /* public global information */ + uLong byte_before_the_zipfile; /* byte before the zipfile, (>0 for sfx) */ + uLong num_file; /* number of the current file in the zipfile */ + uLong pos_in_central_dir; /* pos of the current file in the central dir */ + uLong current_file_ok; /* flag about the usability of the current file */ + uLong central_pos; /* position of the beginning of the central dir */ + + uLong size_central_dir; /* size of the central directory */ + uLong offset_central_dir; /* offset of start of central directory with + * respect to the starting disk number */ + + unz_file_info cur_file_info; /* public info about the current file in zip */ + unz_file_info_internal cur_file_info_internal; /* private info about it */ + file_in_zip_read_info_s *pfile_in_zip_read; /* structure about the current + * file if we are decompressing it */ + int encrypted; +# ifndef NOUNCRYPT + unsigned long keys[3]; /* keys defining the pseudo-random sequence */ + const unsigned long *pcrc_32_tab; +# endif +} +unz_s; + +#ifndef NOUNCRYPT +#include <axis2_crypt.h> +#endif + +/* + * Read a byte from a gz_stream; update next_in and avail_in. Return EOF + * for end of file. + * IN assertion: the stream s has been sucessfully opened for reading. + */ + +local int unzlocal_getByte OF( + (const zlib_filefunc_def * pzlib_filefunc_def, + voidpf filestream, + int *pi)); + +local int +unzlocal_getByte( + const zlib_filefunc_def *pzlib_filefunc_def, + voidpf filestream, + int *pi) +{ + unsigned char c; + int err = (int) ZREAD(*pzlib_filefunc_def, filestream, &c, 1); + if (err == 1) + { + *pi = (int) c; + return UNZ_OK; + } + else + { + if (ZERROR(*pzlib_filefunc_def, filestream)) + return UNZ_ERRNO; + else + return UNZ_EOF; + } +} + +/* Reads a long in LSB order from the given gz_stream. Sets */ +local int unzlocal_getShort OF( + (const zlib_filefunc_def * pzlib_filefunc_def, + voidpf filestream, + uLong * pX)); + +local int +unzlocal_getShort( + const zlib_filefunc_def *pzlib_filefunc_def, + voidpf filestream, + uLong *pX) +{ + uLong x; + int i = 0; + int err = 0; + + err = unzlocal_getByte(pzlib_filefunc_def, filestream, &i); + x = (uLong) i; + + if (err == UNZ_OK) + err = unzlocal_getByte(pzlib_filefunc_def, filestream, &i); + x += ((uLong) i) << 8; + + if (err == UNZ_OK) + *pX = x; + else + *pX = 0; + return err; +} + +local int unzlocal_getLong OF( + (const zlib_filefunc_def * pzlib_filefunc_def, + voidpf filestream, + uLong * pX)); + +local int +unzlocal_getLong( + const zlib_filefunc_def *pzlib_filefunc_def, + voidpf filestream, + uLong *pX) +{ + uLong x; + int i = 0; + int err = 0; + + err = unzlocal_getByte(pzlib_filefunc_def, filestream, &i); + x = (uLong) i; + + if (err == UNZ_OK) + err = unzlocal_getByte(pzlib_filefunc_def, filestream, &i); + x += ((uLong) i) << 8; + + if (err == UNZ_OK) + err = unzlocal_getByte(pzlib_filefunc_def, filestream, &i); + x += ((uLong) i) << 16; + + if (err == UNZ_OK) + err = unzlocal_getByte(pzlib_filefunc_def, filestream, &i); + x += ((uLong) i) << 24; + + if (err == UNZ_OK) + *pX = x; + else + *pX = 0; + return err; +} + +/* My own strcmpi / strcasecmp */ +local int +strcmpcasenosensitive_internal( + const char *fileName1, + const char *fileName2) +{ + for (;;) + { + char c1 = *(fileName1++); + char c2 = *(fileName2++); + if ((c1 >= 'a') && (c1 <= 'z')) + c1 -= 0x20; + if ((c2 >= 'a') && (c2 <= 'z')) + c2 -= 0x20; + if (c1 == '\0') + return ((c2 == '\0') ? 0 : -1); + if (c2 == '\0') + return 1; + if (c1 < c2) + return -1; + if (c1 > c2) + return 1; + } +} + +#ifdef CASESENSITIVITYDEFAULT_NO +#define CASESENSITIVITYDEFAULTVALUE 2 +#else +#define CASESENSITIVITYDEFAULTVALUE 1 +#endif + +#ifndef STRCMPCASENOSENTIVEFUNCTION +#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal +#endif + +/* + * Compare two filename (fileName1,fileName2). + * If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) + * If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + * or strcasecmp) + * If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + * (like 1 on Unix, 2 on Windows) + */ +extern int ZEXPORT +unzStringFileNameCompare( + const char *fileName1, + const char *fileName2, + int iCaseSensitivity) +{ + if (iCaseSensitivity == 0) + iCaseSensitivity = CASESENSITIVITYDEFAULTVALUE; + + if (iCaseSensitivity == 1) + return strcmp(fileName1, fileName2); + + return STRCMPCASENOSENTIVEFUNCTION(fileName1, fileName2); +} + +#ifndef BUFREADCOMMENT +#define BUFREADCOMMENT (0x400) +#endif + +/* + * Locate the Central directory of a zipfile (at the end, just before + * the global comment) + */ +local uLong unzlocal_SearchCentralDir OF( + (const zlib_filefunc_def * pzlib_filefunc_def, + voidpf filestream)); + +local uLong +unzlocal_SearchCentralDir( + const zlib_filefunc_def *pzlib_filefunc_def, + voidpf filestream) +{ + unsigned char *buf; + uLong uSizeFile; + uLong uBackRead; + uLong uMaxBack = 0xffff; /* maximum size of global comment */ + uLong uPosFound = 0; + + if (ZSEEK(*pzlib_filefunc_def, filestream, 0, ZLIB_FILEFUNC_SEEK_END) != 0) + return 0; + + uSizeFile = ZTELL(*pzlib_filefunc_def, filestream); + + if (uMaxBack > uSizeFile) + uMaxBack = uSizeFile; + + buf = (unsigned char *) ALLOC(BUFREADCOMMENT + 4); + if (buf == NULL) + return 0; + + uBackRead = 4; + while (uBackRead < uMaxBack) + { + uLong uReadSize, + uReadPos; + int i = 0; + if (uBackRead + BUFREADCOMMENT > uMaxBack) + uBackRead = uMaxBack; + else + uBackRead += BUFREADCOMMENT; + uReadPos = uSizeFile - uBackRead; + + uReadSize = ((BUFREADCOMMENT + 4) < (uSizeFile - uReadPos)) ? + (BUFREADCOMMENT + 4) : (uSizeFile - uReadPos); + if (ZSEEK + (*pzlib_filefunc_def, filestream, uReadPos, + ZLIB_FILEFUNC_SEEK_SET) != 0) + break; + + if (ZREAD(*pzlib_filefunc_def, filestream, buf, uReadSize) != uReadSize) + break; + + for (i = (int) uReadSize - 3; (i--) > 0;) + if (((*(buf + i)) == 0x50) && ((*(buf + i + 1)) == 0x4b) && + ((*(buf + i + 2)) == 0x05) && ((*(buf + i + 3)) == 0x06)) + { + uPosFound = uReadPos + i; + break; + } + + if (uPosFound != 0) + break; + } + TRYFREE(buf); + return uPosFound; +} + +/* + * Open a Zip file. path contain the full pathname (by example, + * on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer + * "zlib/zlib114.zip". + * If the zipfile cannot be opened (file doesn't exist or in not valid), the + * return value is NULL. + * Else, the return value is a unzFile Handle, usable with other function + * of this unzip package. + */ +extern unzFile ZEXPORT +unzOpen2( + const char *path, + zlib_filefunc_def *pzlib_filefunc_def) +{ + unz_s us; + unz_s *s; + uLong central_pos, + uL; + + uLong number_disk; /* number of the current dist, used for + * spaning ZIP, unsupported, always 0 */ + uLong number_disk_with_CD; /* number the the disk with central dir, used + * for spaning ZIP, unsupported, always 0 */ + uLong number_entry_CD; /* total number of entries in + * the central dir + * (same than number_entry on nospan) */ + + int err = UNZ_OK; + + if (unz_copyright[0] != ' ') + return NULL; + + if (pzlib_filefunc_def == NULL) + fill_fopen_filefunc(&us.z_filefunc); + else + us.z_filefunc = *pzlib_filefunc_def; + + us.filestream = (*(us.z_filefunc.zopen_file)) (us.z_filefunc.opaque, + path, + ZLIB_FILEFUNC_MODE_READ | + ZLIB_FILEFUNC_MODE_EXISTING); + if (us.filestream == NULL) + return NULL; + + central_pos = unzlocal_SearchCentralDir(&us.z_filefunc, us.filestream); + if (central_pos == 0) + err = UNZ_ERRNO; + + if (ZSEEK(us.z_filefunc, us.filestream, + central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0) + err = UNZ_ERRNO; + + /* the signature, already checked */ + if (unzlocal_getLong(&us.z_filefunc, us.filestream, &uL) != UNZ_OK) + err = UNZ_ERRNO; + + /* number of this disk */ + if (unzlocal_getShort(&us.z_filefunc, us.filestream, &number_disk) != + UNZ_OK) + err = UNZ_ERRNO; + + /* number of the disk with the start of the central directory */ + if (unzlocal_getShort(&us.z_filefunc, us.filestream, &number_disk_with_CD) + != UNZ_OK) + err = UNZ_ERRNO; + + /* total number of entries in the central dir on this disk */ + if (unzlocal_getShort(&us.z_filefunc, us.filestream, &us.gi.number_entry) != + UNZ_OK) + err = UNZ_ERRNO; + + /* total number of entries in the central dir */ + if (unzlocal_getShort(&us.z_filefunc, us.filestream, &number_entry_CD) != + UNZ_OK) + err = UNZ_ERRNO; + + if ((number_entry_CD != us.gi.number_entry) || + (number_disk_with_CD != 0) || (number_disk != 0)) + err = UNZ_BADZIPFILE; + + /* size of the central directory */ + if (unzlocal_getLong(&us.z_filefunc, us.filestream, &us.size_central_dir) != + UNZ_OK) + err = UNZ_ERRNO; + + /* offset of start of central directory with respect to the + * starting disk number */ + if (unzlocal_getLong(&us.z_filefunc, us.filestream, &us.offset_central_dir) + != UNZ_OK) + err = UNZ_ERRNO; + + /* zipfile comment length */ + if (unzlocal_getShort(&us.z_filefunc, us.filestream, &us.gi.size_comment) != + UNZ_OK) + err = UNZ_ERRNO; + + if ((central_pos < us.offset_central_dir + us.size_central_dir) && + (err == UNZ_OK)) + err = UNZ_BADZIPFILE; + + if (err != UNZ_OK) + { + ZCLOSE(us.z_filefunc, us.filestream); + return NULL; + } + + us.byte_before_the_zipfile = central_pos - + (us.offset_central_dir + us.size_central_dir); + us.central_pos = central_pos; + us.pfile_in_zip_read = NULL; + us.encrypted = 0; + + s = (unz_s *) ALLOC(sizeof(unz_s)); + *s = us; + unzGoToFirstFile((unzFile) s); + return (unzFile) s; +} + +extern unzFile ZEXPORT +unzOpen( + const char *path) +{ + return unzOpen2(path, NULL); +} + +/* + * Close a ZipFile opened with unzipOpen. + * If there is files inside the .Zip opened with unzipOpenCurrentFile (see later), + * these files MUST be closed with unzipCloseCurrentFile before call unzipClose. + * return UNZ_OK if there is no problem. + */ +extern int ZEXPORT +unzClose( + unzFile file) +{ + unz_s *s; + if (file == NULL) + return UNZ_PARAMERROR; + s = (unz_s *) file; + + if (s->pfile_in_zip_read) + unzCloseCurrentFile(file); + + ZCLOSE(s->z_filefunc, s->filestream); + TRYFREE(s); + return UNZ_OK; +} + +/* + * Write info about the ZipFile in the *pglobal_info structure. + * No preparation of the structure is needed + * return UNZ_OK if there is no problem. + */ +extern int ZEXPORT +unzGetGlobalInfo( + unzFile file, + unz_global_info *pglobal_info) +{ + unz_s *s; + if (file == NULL) + return UNZ_PARAMERROR; + s = (unz_s *) file; + *pglobal_info = s->gi; + return UNZ_OK; +} + +/* Translate date/time from Dos format to tm_unz (readable more easilty) */ +local void +unzlocal_DosDateToTmuDate( + uLong ulDosDate, + tm_unz *ptm) +{ + uLong uDate; + uDate = (uLong) (ulDosDate >> 16); + ptm->tm_mday = (uInt) (uDate & 0x1f); + ptm->tm_mon = (uInt) ((((uDate) & 0x1E0) / 0x20) - 1); + ptm->tm_year = (uInt) (((uDate & 0x0FE00) / 0x0200) + 1980); + + ptm->tm_hour = (uInt) ((ulDosDate & 0xF800) / 0x800); + ptm->tm_min = (uInt) ((ulDosDate & 0x7E0) / 0x20); + ptm->tm_sec = (uInt) (2 * (ulDosDate & 0x1f)); +} + +/* Get Info about the current file in the zipfile, with internal only info */ +local int unzlocal_GetCurrentFileInfoInternal OF( + (unzFile file, + unz_file_info * pfile_info, + unz_file_info_internal * pfile_info_internal, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); + +local int +unzlocal_GetCurrentFileInfoInternal( + unzFile file, + unz_file_info *pfile_info, + unz_file_info_internal *pfile_info_internal, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize) +{ + unz_s *s; + unz_file_info file_info; + unz_file_info_internal file_info_internal; + int err = UNZ_OK; + uLong uMagic = 0x00000000; + long lSeek = 0; + + if (file == NULL) + return UNZ_PARAMERROR; + s = (unz_s *) file; + if (ZSEEK(s->z_filefunc, s->filestream, + s->pos_in_central_dir + s->byte_before_the_zipfile, + ZLIB_FILEFUNC_SEEK_SET) != 0) + err = UNZ_ERRNO; + + /* we check the magic */ + if (err == UNZ_OK) + { + if (unzlocal_getLong(&s->z_filefunc, s->filestream, &uMagic) != UNZ_OK) + err = UNZ_ERRNO; + } + else if (uMagic != 0x02014b50) + { + err = UNZ_BADZIPFILE; + } + + if (unzlocal_getShort(&s->z_filefunc, s->filestream, &file_info.version) != + UNZ_OK) + err = UNZ_ERRNO; + + if (unzlocal_getShort + (&s->z_filefunc, s->filestream, &file_info.version_needed) != UNZ_OK) + err = UNZ_ERRNO; + + if (unzlocal_getShort(&s->z_filefunc, s->filestream, &file_info.flag) != + UNZ_OK) + err = UNZ_ERRNO; + + if (unzlocal_getShort + (&s->z_filefunc, s->filestream, + &file_info.compression_method) != UNZ_OK) + err = UNZ_ERRNO; + + if (unzlocal_getLong(&s->z_filefunc, s->filestream, &file_info.dosDate) != + UNZ_OK) + err = UNZ_ERRNO; + + unzlocal_DosDateToTmuDate(file_info.dosDate, &file_info.tmu_date); + + if (unzlocal_getLong(&s->z_filefunc, s->filestream, &file_info.crc) != + UNZ_OK) + err = UNZ_ERRNO; + + if (unzlocal_getLong + (&s->z_filefunc, s->filestream, &file_info.compressed_size) != UNZ_OK) + err = UNZ_ERRNO; + + if (unzlocal_getLong + (&s->z_filefunc, s->filestream, &file_info.uncompressed_size) != UNZ_OK) + err = UNZ_ERRNO; + + if (unzlocal_getShort + (&s->z_filefunc, s->filestream, &file_info.size_filename) != UNZ_OK) + err = UNZ_ERRNO; + + if (unzlocal_getShort + (&s->z_filefunc, s->filestream, &file_info.size_file_extra) != UNZ_OK) + err = UNZ_ERRNO; + + if (unzlocal_getShort + (&s->z_filefunc, s->filestream, &file_info.size_file_comment) != UNZ_OK) + err = UNZ_ERRNO; + + if (unzlocal_getShort + (&s->z_filefunc, s->filestream, &file_info.disk_num_start) != UNZ_OK) + err = UNZ_ERRNO; + + if (unzlocal_getShort(&s->z_filefunc, s->filestream, &file_info.internal_fa) + != UNZ_OK) + err = UNZ_ERRNO; + + if (unzlocal_getLong(&s->z_filefunc, s->filestream, &file_info.external_fa) + != UNZ_OK) + err = UNZ_ERRNO; + + if (unzlocal_getLong + (&s->z_filefunc, s->filestream, + &file_info_internal.offset_curfile) != UNZ_OK) + err = UNZ_ERRNO; + + lSeek += file_info.size_filename; + if ((err == UNZ_OK) && (szFileName)) + { + uLong uSizeRead; + if (file_info.size_filename < fileNameBufferSize) + { + *(szFileName + file_info.size_filename) = '\0'; + uSizeRead = file_info.size_filename; + } + else + uSizeRead = fileNameBufferSize; + + if ((file_info.size_filename > 0) && (fileNameBufferSize > 0)) + if (ZREAD(s->z_filefunc, s->filestream, szFileName, uSizeRead) != + uSizeRead) + err = UNZ_ERRNO; + lSeek -= uSizeRead; + } + + if ((err == UNZ_OK) && (extraField)) + { + uLong uSizeRead; + if (file_info.size_file_extra < extraFieldBufferSize) + uSizeRead = file_info.size_file_extra; + else + uSizeRead = extraFieldBufferSize; + + if (lSeek != 0) + { + if (ZSEEK + (s->z_filefunc, s->filestream, lSeek, + ZLIB_FILEFUNC_SEEK_CUR) == 0) + lSeek = 0; + else + err = UNZ_ERRNO; + } + if ((file_info.size_file_extra > 0) && (extraFieldBufferSize > 0)) + if (ZREAD(s->z_filefunc, s->filestream, extraField, uSizeRead) != + uSizeRead) + err = UNZ_ERRNO; + lSeek += file_info.size_file_extra - uSizeRead; + } + else + lSeek += file_info.size_file_extra; + + if ((err == UNZ_OK) && (szComment)) + { + uLong uSizeRead; + if (file_info.size_file_comment < commentBufferSize) + { + *(szComment + file_info.size_file_comment) = '\0'; + uSizeRead = file_info.size_file_comment; + } + else + uSizeRead = commentBufferSize; + + if (lSeek != 0) + { + if (ZSEEK + (s->z_filefunc, s->filestream, lSeek, + ZLIB_FILEFUNC_SEEK_CUR) == 0) + lSeek = 0; + else + err = UNZ_ERRNO; + } + if ((file_info.size_file_comment > 0) && (commentBufferSize > 0)) + if (ZREAD(s->z_filefunc, s->filestream, szComment, uSizeRead) != + uSizeRead) + err = UNZ_ERRNO; + lSeek += file_info.size_file_comment - uSizeRead; + } + else + lSeek += file_info.size_file_comment; + + if ((err == UNZ_OK) && (pfile_info)) + *pfile_info = file_info; + + if ((err == UNZ_OK) && (pfile_info_internal)) + *pfile_info_internal = file_info_internal; + + return err; +} + +/* + * Write info about the ZipFile in the *pglobal_info structure. + * No preparation of the structure is needed + * return UNZ_OK if there is no problem. + */ +extern int ZEXPORT +unzGetCurrentFileInfo( + unzFile file, + unz_file_info *pfile_info, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize) +{ + return unzlocal_GetCurrentFileInfoInternal(file, pfile_info, NULL, + szFileName, fileNameBufferSize, + extraField, extraFieldBufferSize, + szComment, commentBufferSize); +} + +/* + * Set the current file of the zipfile to the first file. + * return UNZ_OK if there is no problem + */ +extern int ZEXPORT +unzGoToFirstFile( + unzFile file) +{ + int err = UNZ_OK; + unz_s *s; + if (file == NULL) + return UNZ_PARAMERROR; + s = (unz_s *) file; + s->pos_in_central_dir = s->offset_central_dir; + s->num_file = 0; + err = unzlocal_GetCurrentFileInfoInternal(file, &s->cur_file_info, + &s->cur_file_info_internal, + NULL, 0, NULL, 0, NULL, 0); + s->current_file_ok = (err == UNZ_OK); + return err; +} + +/* + * Set the current file of the zipfile to the next file. + * return UNZ_OK if there is no problem + * return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. + */ +extern int ZEXPORT +unzGoToNextFile( + unzFile file) +{ + unz_s *s; + int err; + + if (file == NULL) + return UNZ_PARAMERROR; + s = (unz_s *) file; + if (!s->current_file_ok) + return UNZ_END_OF_LIST_OF_FILE; + if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */ + if (s->num_file + 1 == s->gi.number_entry) + return UNZ_END_OF_LIST_OF_FILE; + + s->pos_in_central_dir += + SIZECENTRALDIRITEM + s->cur_file_info.size_filename + + s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment; + s->num_file++; + err = unzlocal_GetCurrentFileInfoInternal(file, &s->cur_file_info, + &s->cur_file_info_internal, + NULL, 0, NULL, 0, NULL, 0); + s->current_file_ok = (err == UNZ_OK); + return err; +} + +/* + * Try locate the file szFileName in the zipfile. + * For the iCaseSensitivity signification, see unzipStringFileNameCompare + * + * return value : + * UNZ_OK if the file is found. It becomes the current file. + * UNZ_END_OF_LIST_OF_FILE if the file is not found + */ +extern int ZEXPORT +unzLocateFile( + unzFile file, + const char *szFileName, + int iCaseSensitivity) +{ + unz_s *s; + int err = 0; + + /* We remember the 'current' position in the file so that we can jump + * back there if we fail. + */ + unz_file_info cur_file_infoSaved; + unz_file_info_internal cur_file_info_internalSaved; + uLong num_fileSaved; + uLong pos_in_central_dirSaved; + + if (file == NULL) + return UNZ_PARAMERROR; + + if (strlen(szFileName) >= UNZ_MAXFILENAMEINZIP) + return UNZ_PARAMERROR; + + s = (unz_s *) file; + if (!s->current_file_ok) + return UNZ_END_OF_LIST_OF_FILE; + + /* Save the current state */ + num_fileSaved = s->num_file; + pos_in_central_dirSaved = s->pos_in_central_dir; + cur_file_infoSaved = s->cur_file_info; + cur_file_info_internalSaved = s->cur_file_info_internal; + + err = unzGoToFirstFile(file); + + while (err == UNZ_OK) + { + char szCurrentFileName[UNZ_MAXFILENAMEINZIP + 1]; + err = unzGetCurrentFileInfo(file, NULL, + szCurrentFileName, + sizeof(szCurrentFileName) - 1, NULL, 0, + NULL, 0); + if (err == UNZ_OK) + { + if (unzStringFileNameCompare(szCurrentFileName, + szFileName, iCaseSensitivity) == 0) + return UNZ_OK; + err = unzGoToNextFile(file); + } + } + + /* We failed, so restore the state of the 'current file' to where we + * were. + */ + s->num_file = num_fileSaved; + s->pos_in_central_dir = pos_in_central_dirSaved; + s->cur_file_info = cur_file_infoSaved; + s->cur_file_info_internal = cur_file_info_internalSaved; + return err; +} + +/* + * Contributed by Ryan Haksi (mailto://cryogen@infoserve.net) + * I need random access + * + * Further optimization could be realized by adding an ability + * to cache the directory in memory. The goal being a single + * comprehensive file read to put the file I need in a memory. + */ + +/* +typedef struct unz_file_pos_s +{ + uLong pos_in_zip_directory; + uLong num_of_file; +} unz_file_pos; +*/ + +extern int ZEXPORT +unzGetFilePos( + unzFile file, + unz_file_pos *file_pos) +{ + unz_s *s; + + if (file == NULL || file_pos == NULL) + return UNZ_PARAMERROR; + s = (unz_s *) file; + if (!s->current_file_ok) + return UNZ_END_OF_LIST_OF_FILE; + + file_pos->pos_in_zip_directory = s->pos_in_central_dir; + file_pos->num_of_file = s->num_file; + + return UNZ_OK; +} + +extern int ZEXPORT +unzGoToFilePos( + unzFile file, + unz_file_pos *file_pos) +{ + unz_s *s; + int err = 0; + + if (file == NULL || file_pos == NULL) + return UNZ_PARAMERROR; + s = (unz_s *) file; + + /* jump to the right spot */ + s->pos_in_central_dir = file_pos->pos_in_zip_directory; + s->num_file = file_pos->num_of_file; + + /* set the current file */ + err = unzlocal_GetCurrentFileInfoInternal(file, &s->cur_file_info, + &s->cur_file_info_internal, + NULL, 0, NULL, 0, NULL, 0); + /* return results */ + s->current_file_ok = (err == UNZ_OK); + return err; +} + +/* + * Unzip Helper Functions - should be here? + */ + +/* + * Read the local header of the current zipfile + * Check the coherency of the local header and info in the end of central + * directory about this file + * store in *piSizeVar the size of extra info in local header + * (filename and size of extra field data) + */ +local int +unzlocal_CheckCurrentFileCoherencyHeader( + unz_s *s, + uInt *piSizeVar, + uLong *poffset_local_extrafield, + uInt *psize_local_extrafield) +{ + uLong uMagic, + uData, + uFlags; + uLong size_filename; + uLong size_extra_field; + int err = UNZ_OK; + + *piSizeVar = 0; + *poffset_local_extrafield = 0; + *psize_local_extrafield = 0; + + if (ZSEEK + (s->z_filefunc, s->filestream, + s->cur_file_info_internal.offset_curfile + s->byte_before_the_zipfile, + ZLIB_FILEFUNC_SEEK_SET) != 0) + return UNZ_ERRNO; + + if (err == UNZ_OK) + { + if (unzlocal_getLong(&s->z_filefunc, s->filestream, &uMagic) != UNZ_OK) + err = UNZ_ERRNO; + else if (uMagic != 0x04034b50) + err = UNZ_BADZIPFILE; + } + + if (unzlocal_getShort(&s->z_filefunc, s->filestream, &uData) != UNZ_OK) + err = UNZ_ERRNO; + /* + * else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) + * err=UNZ_BADZIPFILE; + */ + if (unzlocal_getShort(&s->z_filefunc, s->filestream, &uFlags) != UNZ_OK) + err = UNZ_ERRNO; + + if (unzlocal_getShort(&s->z_filefunc, s->filestream, &uData) != UNZ_OK) + err = UNZ_ERRNO; + else if ((err == UNZ_OK) && (uData != s->cur_file_info.compression_method)) + err = UNZ_BADZIPFILE; + + if ((err == UNZ_OK) && (s->cur_file_info.compression_method != 0) && + (s->cur_file_info.compression_method != Z_DEFLATED)) + err = UNZ_BADZIPFILE; + + if (unzlocal_getLong(&s->z_filefunc, s->filestream, &uData) != UNZ_OK) /* date/time */ + err = UNZ_ERRNO; + + if (unzlocal_getLong(&s->z_filefunc, s->filestream, &uData) != UNZ_OK) /* crc */ + err = UNZ_ERRNO; + else if ((err == UNZ_OK) && (uData != s->cur_file_info.crc) && + ((uFlags & 8) == 0)) + err = UNZ_BADZIPFILE; + + if (unzlocal_getLong(&s->z_filefunc, s->filestream, &uData) != UNZ_OK) /* size compr */ + err = UNZ_ERRNO; + else if ((err == UNZ_OK) && (uData != s->cur_file_info.compressed_size) && + ((uFlags & 8) == 0)) + err = UNZ_BADZIPFILE; + + if (unzlocal_getLong(&s->z_filefunc, s->filestream, &uData) != UNZ_OK) /* size uncompr */ + err = UNZ_ERRNO; + else if ((err == UNZ_OK) && (uData != s->cur_file_info.uncompressed_size) && + ((uFlags & 8) == 0)) + err = UNZ_BADZIPFILE; + + if (unzlocal_getShort(&s->z_filefunc, s->filestream, &size_filename) != + UNZ_OK) + err = UNZ_ERRNO; + else if ((err == UNZ_OK) && + (size_filename != s->cur_file_info.size_filename)) + err = UNZ_BADZIPFILE; + + *piSizeVar += (uInt) size_filename; + + if (unzlocal_getShort(&s->z_filefunc, s->filestream, &size_extra_field) != + UNZ_OK) + err = UNZ_ERRNO; + *poffset_local_extrafield = s->cur_file_info_internal.offset_curfile + + SIZEZIPLOCALHEADER + size_filename; + *psize_local_extrafield = (uInt) size_extra_field; + + *piSizeVar += (uInt) size_extra_field; + + return err; +} + +/* + * Open for reading data the current file in the zipfile. + * If there is no error and the file is opened, the return value is UNZ_OK. + */ +extern int ZEXPORT +unzOpenCurrentFile3( + unzFile file, + int *method, + int *level, + int raw, + const char *password) +{ + int err = UNZ_OK; + uInt iSizeVar; + unz_s *s; + file_in_zip_read_info_s *pfile_in_zip_read_info; + uLong offset_local_extrafield; /* offset of the local extra field */ + uInt size_local_extrafield; /* size of the local extra field */ +# ifndef NOUNCRYPT + char source[12]; +# else + if (password) + return UNZ_PARAMERROR; +# endif + + if (file == NULL) + return UNZ_PARAMERROR; + s = (unz_s *) file; + if (!s->current_file_ok) + return UNZ_PARAMERROR; + + if (s->pfile_in_zip_read) + unzCloseCurrentFile(file); + + if (unzlocal_CheckCurrentFileCoherencyHeader(s, &iSizeVar, + &offset_local_extrafield, + &size_local_extrafield) != + UNZ_OK) + return UNZ_BADZIPFILE; + + pfile_in_zip_read_info = (file_in_zip_read_info_s *) + ALLOC(sizeof(file_in_zip_read_info_s)); + if (pfile_in_zip_read_info == NULL) + return UNZ_INTERNALERROR; + + pfile_in_zip_read_info->read_buffer = (char *) ALLOC(UNZ_BUFSIZE); + pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield; + pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield; + pfile_in_zip_read_info->pos_local_extrafield = 0; + pfile_in_zip_read_info->raw = raw; + + if (pfile_in_zip_read_info->read_buffer == NULL) + { + TRYFREE(pfile_in_zip_read_info); + return UNZ_INTERNALERROR; + } + + pfile_in_zip_read_info->stream_initialised = 0; + + if (method) + *method = (int) s->cur_file_info.compression_method; + + if (level) + { + *level = 6; + switch (s->cur_file_info.flag & 0x06) + { + case 6: + *level = 1; + break; + case 4: + *level = 2; + break; + case 2: + *level = 9; + break; + } + } + + if ((s->cur_file_info.compression_method != 0) && + (s->cur_file_info.compression_method != Z_DEFLATED)) + err = UNZ_BADZIPFILE; + + pfile_in_zip_read_info->crc32_wait = s->cur_file_info.crc; + pfile_in_zip_read_info->crc32 = 0; + pfile_in_zip_read_info->compression_method = + s->cur_file_info.compression_method; + pfile_in_zip_read_info->filestream = s->filestream; + pfile_in_zip_read_info->z_filefunc = s->z_filefunc; + pfile_in_zip_read_info->byte_before_the_zipfile = + s->byte_before_the_zipfile; + + pfile_in_zip_read_info->stream.total_out = 0; + + if ((s->cur_file_info.compression_method == Z_DEFLATED) && (!raw)) + { + pfile_in_zip_read_info->stream.zalloc = (alloc_func) 0; + pfile_in_zip_read_info->stream.zfree = (free_func) 0; + pfile_in_zip_read_info->stream.opaque = (voidpf) 0; + pfile_in_zip_read_info->stream.next_in = (voidpf) 0; + pfile_in_zip_read_info->stream.avail_in = 0; + + err = inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); + if (err == Z_OK) + pfile_in_zip_read_info->stream_initialised = 1; + else + { + TRYFREE(pfile_in_zip_read_info); + return err; + } + /* windowBits is passed < 0 to tell that there is no zlib header. + * Note that in this case inflate *requires* an extra "dummy" byte + * after the compressed stream in order to complete decompression and + * return Z_STREAM_END. + * In unzip, i don't wait absolutely Z_STREAM_END because I known the + * size of both compressed and uncompressed data + */ + } + pfile_in_zip_read_info->rest_read_compressed = + s->cur_file_info.compressed_size; + pfile_in_zip_read_info->rest_read_uncompressed = + s->cur_file_info.uncompressed_size; + + pfile_in_zip_read_info->pos_in_zipfile = + s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + + iSizeVar; + + pfile_in_zip_read_info->stream.avail_in = (uInt) 0; + + s->pfile_in_zip_read = pfile_in_zip_read_info; + +# ifndef NOUNCRYPT + if (password) + { + int i = 0; + s->pcrc_32_tab = get_crc_table(); + init_keys(password, s->keys, s->pcrc_32_tab); + if (ZSEEK(s->z_filefunc, s->filestream, + s->pfile_in_zip_read->pos_in_zipfile + + s->pfile_in_zip_read->byte_before_the_zipfile, SEEK_SET) != 0) + return UNZ_INTERNALERROR; + if (ZREAD(s->z_filefunc, s->filestream, source, 12) < 12) + return UNZ_INTERNALERROR; + + for (i = 0; i < 12; i++) + zdecode(s->keys, s->pcrc_32_tab, source[i]); + + s->pfile_in_zip_read->pos_in_zipfile += 12; + s->encrypted = 1; + } +# endif + + return UNZ_OK; +} + +extern int ZEXPORT +unzOpenCurrentFile( + unzFile file) +{ + return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL); +} + +extern int ZEXPORT +unzOpenCurrentFilePassword( + unzFile file, + const char *password) +{ + return unzOpenCurrentFile3(file, NULL, NULL, 0, password); +} + +extern int ZEXPORT +unzOpenCurrentFile2( + unzFile file, + int *method, + int *level, + int raw) +{ + return unzOpenCurrentFile3(file, method, level, raw, NULL); +} + +/* + * Read bytes from the current file. + * buf contain buffer where data must be copied + * len the size of buf. + * + * return the number of byte copied if somes bytes are copied + * return 0 if the end of file was reached + * return <0 with error code if there is an error + * (UNZ_ERRNO for IO error, or zLib error for uncompress error) + */ +extern int ZEXPORT +unzReadCurrentFile( + unzFile file, + voidp buf, + unsigned len) +{ + int err = UNZ_OK; + uInt iRead = 0; + unz_s *s; + file_in_zip_read_info_s *pfile_in_zip_read_info; + if (file == NULL) + return UNZ_PARAMERROR; + s = (unz_s *) file; + pfile_in_zip_read_info = s->pfile_in_zip_read; + + if (pfile_in_zip_read_info == NULL) + return UNZ_PARAMERROR; + + if ((pfile_in_zip_read_info->read_buffer == NULL)) + return UNZ_END_OF_LIST_OF_FILE; + if (len == 0) + return 0; + + pfile_in_zip_read_info->stream.next_out = (Bytef *) buf; + + pfile_in_zip_read_info->stream.avail_out = (uInt) len; + + if ((len > pfile_in_zip_read_info->rest_read_uncompressed) && + (!(pfile_in_zip_read_info->raw))) + pfile_in_zip_read_info->stream.avail_out = + (uInt) pfile_in_zip_read_info->rest_read_uncompressed; + + if ((len > pfile_in_zip_read_info->rest_read_compressed + + pfile_in_zip_read_info->stream.avail_in) && + (pfile_in_zip_read_info->raw)) + pfile_in_zip_read_info->stream.avail_out = + (uInt) pfile_in_zip_read_info->rest_read_compressed + + pfile_in_zip_read_info->stream.avail_in; + + while (pfile_in_zip_read_info->stream.avail_out > 0) + { + if ((pfile_in_zip_read_info->stream.avail_in == 0) && + (pfile_in_zip_read_info->rest_read_compressed > 0)) + { + uInt uReadThis = UNZ_BUFSIZE; + if (pfile_in_zip_read_info->rest_read_compressed < uReadThis) + uReadThis = (uInt) pfile_in_zip_read_info->rest_read_compressed; + if (uReadThis == 0) + return UNZ_EOF; + if (ZSEEK(pfile_in_zip_read_info->z_filefunc, + pfile_in_zip_read_info->filestream, + pfile_in_zip_read_info->pos_in_zipfile + + pfile_in_zip_read_info->byte_before_the_zipfile, + ZLIB_FILEFUNC_SEEK_SET) != 0) + return UNZ_ERRNO; + if (ZREAD(pfile_in_zip_read_info->z_filefunc, + pfile_in_zip_read_info->filestream, + pfile_in_zip_read_info->read_buffer, + uReadThis) != uReadThis) + return UNZ_ERRNO; + +# ifndef NOUNCRYPT + if (s->encrypted) + { + uInt i; + for (i = 0; i < uReadThis; i++) + pfile_in_zip_read_info->read_buffer[i] = + (char)zdecode(s->keys, s->pcrc_32_tab, + pfile_in_zip_read_info->read_buffer[i]); + /* We are sure that the conversion is safe */ + } +# endif + + pfile_in_zip_read_info->pos_in_zipfile += uReadThis; + + pfile_in_zip_read_info->rest_read_compressed -= uReadThis; + + pfile_in_zip_read_info->stream.next_in = + (Bytef *) pfile_in_zip_read_info->read_buffer; + pfile_in_zip_read_info->stream.avail_in = (uInt) uReadThis; + } + + if ((pfile_in_zip_read_info->compression_method == 0) || + (pfile_in_zip_read_info->raw)) + { + uInt uDoCopy, + i; + + if ((pfile_in_zip_read_info->stream.avail_in == 0) && + (pfile_in_zip_read_info->rest_read_compressed == 0)) + return (iRead == 0) ? UNZ_EOF : iRead; + + if (pfile_in_zip_read_info->stream.avail_out < + pfile_in_zip_read_info->stream.avail_in) + uDoCopy = pfile_in_zip_read_info->stream.avail_out; + else + uDoCopy = pfile_in_zip_read_info->stream.avail_in; + + for (i = 0; i < uDoCopy; i++) + *(pfile_in_zip_read_info->stream.next_out + i) = + *(pfile_in_zip_read_info->stream.next_in + i); + + pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, + pfile_in_zip_read_info-> + stream.next_out, uDoCopy); + pfile_in_zip_read_info->rest_read_uncompressed -= uDoCopy; + pfile_in_zip_read_info->stream.avail_in -= uDoCopy; + pfile_in_zip_read_info->stream.avail_out -= uDoCopy; + pfile_in_zip_read_info->stream.next_out += uDoCopy; + pfile_in_zip_read_info->stream.next_in += uDoCopy; + pfile_in_zip_read_info->stream.total_out += uDoCopy; + iRead += uDoCopy; + } + else + { + uLong uTotalOutBefore, + uTotalOutAfter; + const Bytef *bufBefore; + uLong uOutThis; + int flush = Z_SYNC_FLUSH; + + uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; + bufBefore = pfile_in_zip_read_info->stream.next_out; + + /* + * if ((pfile_in_zip_read_info->rest_read_uncompressed == + * pfile_in_zip_read_info->stream.avail_out) && + * (pfile_in_zip_read_info->rest_read_compressed == 0)) + * flush = Z_FINISH; + */ + err = inflate(&pfile_in_zip_read_info->stream, flush); + + if ((err >= 0) && (pfile_in_zip_read_info->stream.msg)) + err = Z_DATA_ERROR; + + uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; + uOutThis = uTotalOutAfter - uTotalOutBefore; + + pfile_in_zip_read_info->crc32 = + crc32(pfile_in_zip_read_info->crc32, bufBefore, + (uInt) (uOutThis)); + + pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis; + + iRead += (uInt) (uTotalOutAfter - uTotalOutBefore); + + if (err == Z_STREAM_END) + return (iRead == 0) ? UNZ_EOF : iRead; + if (err != Z_OK) + break; + } + } + + if (err == Z_OK) + return iRead; + return err; +} + +/* Give the current position in uncompressed data */ +extern z_off_t ZEXPORT +unztell( + unzFile file) +{ + unz_s *s; + file_in_zip_read_info_s *pfile_in_zip_read_info; + if (file == NULL) + return UNZ_PARAMERROR; + s = (unz_s *) file; + pfile_in_zip_read_info = s->pfile_in_zip_read; + + if (pfile_in_zip_read_info == NULL) + return UNZ_PARAMERROR; + + return (z_off_t) pfile_in_zip_read_info->stream.total_out; +} + +/* return 1 if the end of file was reached, 0 elsewhere */ +extern int ZEXPORT +unzeof( + unzFile file) +{ + unz_s *s; + file_in_zip_read_info_s *pfile_in_zip_read_info; + if (file == NULL) + return UNZ_PARAMERROR; + s = (unz_s *) file; + pfile_in_zip_read_info = s->pfile_in_zip_read; + + if (pfile_in_zip_read_info == NULL) + return UNZ_PARAMERROR; + + if (pfile_in_zip_read_info->rest_read_uncompressed == 0) + return 1; + else + return 0; +} + +/* + * Read extra field from the current file (opened by unzOpenCurrentFile) + * This is the local-header version of the extra field (sometimes, there is + * more info in the local-header version than in the central-header) + * + * if buf==NULL, it return the size of the local extra field that can be read + * + * if buf!=NULL, len is the size of the buffer, the extra header is copied in + * buf. + * the return value is the number of bytes copied in buf, or (if <0) + * the error code + */ +extern int ZEXPORT +unzGetLocalExtrafield( + unzFile file, + voidp buf, + unsigned len) +{ + unz_s *s; + file_in_zip_read_info_s *pfile_in_zip_read_info; + uInt read_now; + uLong size_to_read; + + if (file == NULL) + return UNZ_PARAMERROR; + s = (unz_s *) file; + pfile_in_zip_read_info = s->pfile_in_zip_read; + + if (pfile_in_zip_read_info == NULL) + return UNZ_PARAMERROR; + + size_to_read = (pfile_in_zip_read_info->size_local_extrafield - + pfile_in_zip_read_info->pos_local_extrafield); + + if (buf == NULL) + return (int) size_to_read; + + if (len > size_to_read) + read_now = (uInt) size_to_read; + else + read_now = (uInt) len; + + if (read_now == 0) + return 0; + + if (ZSEEK(pfile_in_zip_read_info->z_filefunc, + pfile_in_zip_read_info->filestream, + pfile_in_zip_read_info->offset_local_extrafield + + pfile_in_zip_read_info->pos_local_extrafield, + ZLIB_FILEFUNC_SEEK_SET) != 0) + return UNZ_ERRNO; + + if (ZREAD(pfile_in_zip_read_info->z_filefunc, + pfile_in_zip_read_info->filestream, buf, read_now) != read_now) + return UNZ_ERRNO; + + return (int) read_now; +} + +/* + * Close the file in zip opened with unzipOpenCurrentFile + * Return UNZ_CRCERROR if all the file was read but the CRC is not good + */ +extern int ZEXPORT +unzCloseCurrentFile( + unzFile file) +{ + int err = UNZ_OK; + + unz_s *s; + file_in_zip_read_info_s *pfile_in_zip_read_info; + if (file == NULL) + return UNZ_PARAMERROR; + s = (unz_s *) file; + pfile_in_zip_read_info = s->pfile_in_zip_read; + + if (pfile_in_zip_read_info == NULL) + return UNZ_PARAMERROR; + + if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) && + (!pfile_in_zip_read_info->raw)) + { + if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait) + err = UNZ_CRCERROR; + } + + TRYFREE(pfile_in_zip_read_info->read_buffer); + pfile_in_zip_read_info->read_buffer = NULL; + if (pfile_in_zip_read_info->stream_initialised) + inflateEnd(&pfile_in_zip_read_info->stream); + + pfile_in_zip_read_info->stream_initialised = 0; + TRYFREE(pfile_in_zip_read_info); + + s->pfile_in_zip_read = NULL; + + return err; +} + +/* + * Get the global comment string of the ZipFile, in the szComment buffer. + * uSizeBuf is the size of the szComment buffer. + * return the number of byte copied or an error code <0 + */ +extern int ZEXPORT +unzGetGlobalComment( + unzFile file, + char *szComment, + uLong uSizeBuf) +{ + unz_s *s; + uLong uReadThis; + if (file == NULL) + return UNZ_PARAMERROR; + s = (unz_s *) file; + + uReadThis = uSizeBuf; + if (uReadThis > s->gi.size_comment) + uReadThis = s->gi.size_comment; + + if (ZSEEK + (s->z_filefunc, s->filestream, s->central_pos + 22, + ZLIB_FILEFUNC_SEEK_SET) != 0) + return UNZ_ERRNO; + + if (uReadThis > 0) + { + *szComment = '\0'; + if (ZREAD(s->z_filefunc, s->filestream, szComment, uReadThis) != + uReadThis) + return UNZ_ERRNO; + } + + if ((szComment) && (uSizeBuf > s->gi.size_comment)) + *(szComment + s->gi.size_comment) = '\0'; + return (int) uReadThis; +} + +/* Additions by RX '2004 */ +extern uLong ZEXPORT +unzGetOffset( + unzFile file) +{ + unz_s *s; + + if (file == NULL) + return 0; + s = (unz_s *) file; + if (!s->current_file_ok) + return 0; + if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff) + if (s->num_file == s->gi.number_entry) + return 0; + return s->pos_in_central_dir; +} + +extern int ZEXPORT +unzSetOffset( + unzFile file, + uLong pos) +{ + unz_s *s; + int err; + + if (file == NULL) + return UNZ_PARAMERROR; + s = (unz_s *) file; + + s->pos_in_central_dir = pos; + s->num_file = s->gi.number_entry; /* hack */ + err = unzlocal_GetCurrentFileInfoInternal(file, &s->cur_file_info, + &s->cur_file_info_internal, + NULL, 0, NULL, 0, NULL, 0); + s->current_file_ok = (err == UNZ_OK); + return err; +} diff --git a/util/src/network_handler.c b/util/src/network_handler.c new file mode 100644 index 0000000..a8d154e --- /dev/null +++ b/util/src/network_handler.c @@ -0,0 +1,644 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <axutil_network_handler.h>
+#include <fcntl.h>
+
+
+#if defined(WIN32)
+/* fix for an older version of winsock2.h */
+#if !defined(SO_EXCLUSIVEADDRUSE)
+#define SO_EXCLUSIVEADDRUSE ((int)(~SO_REUSEADDR))
+#endif
+#endif
+
+#if defined(WIN32)
+static int is_init_socket = 0;
+axis2_bool_t axis2_init_socket(
+);
+#endif
+
+AXIS2_EXTERN axis2_socket_t AXIS2_CALL
+axutil_network_handler_open_socket(
+ const axutil_env_t *env,
+ char *server,
+ int port)
+{
+ axis2_socket_t sock = AXIS2_INVALID_SOCKET;
+ struct sockaddr_in sock_addr;
+ struct linger ll;
+ int nodelay = 1;
+
+#if defined(WIN32)
+ if (is_init_socket == 0)
+ {
+ axis2_init_socket();
+ is_init_socket = 1;
+ }
+#endif
+
+ AXIS2_ENV_CHECK(env, AXIS2_CRITICAL_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, server, AXIS2_INVALID_SOCKET);
+
+#ifndef WIN32
+ if((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
+ /*AF_INET is not defined in sys/socket.h but PF_INET */
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_ERROR, AXIS2_FAILURE);
+ return AXIS2_INVALID_SOCKET;
+ }
+#else
+ if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
+ /* In Win 32 if the socket creation failed it return 0 not a negative value */
+ {
+ char buf[AXUTIL_WIN32_ERROR_BUFSIZE];
+ /* Get the detailed error message */
+ axutil_win32_get_last_wsa_error(buf, AXUTIL_WIN32_ERROR_BUFSIZE);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, buf);
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_ERROR, AXIS2_FAILURE);
+ return AXIS2_INVALID_SOCKET;
+ }
+#endif
+
+ memset(&sock_addr, 0, sizeof(sock_addr));
+ sock_addr.sin_family = AF_INET;
+ sock_addr.sin_addr.s_addr = inet_addr(server); /*arpa/inet.d */
+
+ if(sock_addr.sin_addr.s_addr == AXIS2_INADDR_NONE) /*netinet/in.h */
+ {
+ /*
+ * server may be a host name
+ */
+ struct hostent *lphost = NULL;
+ lphost = gethostbyname(server);
+
+ if(lphost)
+ {
+ sock_addr.sin_addr.s_addr = ((struct in_addr *)lphost->h_addr)->s_addr;
+ }
+ else
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_ADDRESS, AXIS2_FAILURE);
+ return AXIS2_INVALID_SOCKET;
+ }
+ }
+
+ sock_addr.sin_port = htons((axis2_unsigned_short_t)port);
+
+ /* Connect to server */
+ if(connect(sock, (struct sockaddr *)&sock_addr, sizeof(sock_addr)) < 0)
+ {
+ AXIS2_CLOSE_SOCKET(sock);
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_ERROR, AXIS2_FAILURE);
+ return AXIS2_INVALID_SOCKET;
+ }
+ setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (const char *)&nodelay, sizeof(nodelay));
+ ll.l_onoff = 1;
+ ll.l_linger = 5;
+ setsockopt(sock, SOL_SOCKET, SO_LINGER, (const char *)&ll, sizeof(struct linger));
+ return sock;
+}
+
+AXIS2_EXTERN axis2_socket_t AXIS2_CALL
+axutil_network_handler_create_server_socket(
+ const axutil_env_t *env,
+ int port)
+{
+ axis2_socket_t sock = AXIS2_INVALID_SOCKET;
+ axis2_socket_t i = 0;
+ struct sockaddr_in sock_addr;
+
+ AXIS2_ENV_CHECK(env, AXIS2_CRITICAL_FAILURE);
+#if defined(WIN32)
+ if (is_init_socket == 0)
+ {
+ axis2_init_socket();
+ is_init_socket = 1;
+ }
+#endif
+ sock = socket(AF_INET, SOCK_STREAM, 0);
+
+#ifndef WIN32
+ if(sock < 0)
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_ERROR, AXIS2_FAILURE);
+ return AXIS2_INVALID_SOCKET;
+ }
+#else
+ if (sock == INVALID_SOCKET)
+ {
+ axis2_char_t buf[AXUTIL_WIN32_ERROR_BUFSIZE];
+ axutil_win32_get_last_wsa_error(buf, AXUTIL_WIN32_ERROR_BUFSIZE);
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_ERROR, AXIS2_FAILURE);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, buf);
+ return AXIS2_INVALID_SOCKET;
+ }
+#endif
+ /* Address re-use */
+ i = 1;
+#if defined(WIN32)
+ setsockopt(sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (char *) &i, sizeof(axis2_socket_t)); /*casted 4th param to char* */
+#else
+ setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&i, sizeof(axis2_socket_t)); /*casted 4th param to char* */
+#endif
+
+ /* Exec behaviour */
+ AXIS2_CLOSE_SOCKET_ON_EXIT(sock) memset(&sock_addr, 0, sizeof(sock_addr));
+
+ sock_addr.sin_family = AF_INET;
+ sock_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ sock_addr.sin_port = htons((axis2_unsigned_short_t)port);
+
+ /* Bind the socket to our port number */
+ if(bind(sock, (struct sockaddr *)&sock_addr, sizeof(sock_addr)) < 0)
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_BIND_FAILED, AXIS2_FAILURE);
+ return AXIS2_INVALID_SOCKET;
+ }
+ if(listen(sock, 50) < 0)
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_LISTEN_FAILED, AXIS2_FAILURE);
+ return AXIS2_INVALID_SOCKET;
+ }
+ return sock;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+axutil_network_handler_close_socket(
+ const axutil_env_t *env,
+ axis2_socket_t socket)
+{
+ int i = 0;
+ char buf[32];
+ if(socket < 0)
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_SOCKET, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ shutdown(socket, AXIS2_SHUT_WR);
+ axutil_network_handler_set_sock_option(env, socket, SO_RCVTIMEO, 1);
+ i = recv(socket, buf, 32, 0);
+ AXIS2_CLOSE_SOCKET(socket);
+ return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+axutil_network_handler_set_sock_option(
+ const axutil_env_t *env,
+ axis2_socket_t socket,
+ int option,
+ int value)
+{
+ if(option == SO_RCVTIMEO || option == SO_SNDTIMEO)
+ {
+#if defined(WIN32)
+ DWORD tv = value; /* windows expects milliseconds in a DWORD */
+#else
+ struct timeval tv;
+ /* we deal with milliseconds */
+ tv.tv_sec = value / 1000;
+ tv.tv_usec = (value % 1000) * 1000;
+#endif
+ setsockopt(socket, SOL_SOCKET, option, (char *)&tv, sizeof(tv));
+ return AXIS2_SUCCESS;
+ }
+ else if(option == SO_REUSEADDR)
+ {
+ if((setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, (char *)&value, sizeof(value))) < 0)
+ {
+ return AXIS2_FAILURE;
+ }
+ return AXIS2_SUCCESS;
+ }
+ return AXIS2_FAILURE;
+}
+
+AXIS2_EXTERN axis2_socket_t AXIS2_CALL
+axutil_network_handler_svr_socket_accept(
+ const axutil_env_t *env,
+ axis2_socket_t svr_socket)
+{
+ struct sockaddr cli_addr;
+ struct linger ll;
+ int nodelay = 1;
+ axis2_socket_len_t cli_len = 0;
+ axis2_socket_t cli_socket = AXIS2_INVALID_SOCKET;
+ AXIS2_ENV_CHECK(env, AXIS2_CRITICAL_FAILURE);
+
+ cli_len = sizeof(cli_addr);
+ cli_socket = accept(svr_socket, (struct sockaddr *)&cli_addr, &cli_len);
+#ifndef WIN32
+ if(cli_socket < 0)
+ {
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+ "[Axis2][network_handler] Socket accept \
+ failed");
+ }
+#else
+ if (cli_socket == INVALID_SOCKET)
+ {
+ axis2_char_t buf[AXUTIL_WIN32_ERROR_BUFSIZE];
+ axutil_win32_get_last_wsa_error(buf, AXUTIL_WIN32_ERROR_BUFSIZE);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, buf);
+ }
+#endif
+
+ setsockopt(svr_socket, IPPROTO_TCP, TCP_NODELAY, (const char *)&nodelay, (int)sizeof(nodelay));
+ /* We are sure that the difference lies within the int range */
+ ll.l_onoff = 1;
+ ll.l_linger = 5;
+ setsockopt(cli_socket, SOL_SOCKET, SO_LINGER, (const char *)&ll, (int)sizeof(struct linger));
+ /* We are sure that the difference lies within the int range */
+ return cli_socket;
+}
+
+#if defined (WIN32)
+axis2_bool_t
+axis2_init_socket(
+)
+{
+ WORD wVersionRequested;
+ WSADATA wsaData;
+ int err;
+ wVersionRequested = MAKEWORD(2, 2);
+
+ err = WSAStartup(wVersionRequested, &wsaData);
+
+ if (err != 0)
+ return 0; /* WinSock 2.2 not found */
+
+ /* Confirm that the WinSock DLL supports 2.2.
+ * Note that if the DLL supports versions greater
+ * than 2.2 in addition to 2.2, it will still return
+ * 2.2 in wVersion since that is the version we
+ * requested.
+ */
+
+ if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2)
+ {
+ WSACleanup();
+ return 0; /* WinSock 2.2 not supported */
+ }
+ return 1;
+}
+#endif
+
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+axutil_network_handler_get_svr_ip(
+ const axutil_env_t *env,
+ axis2_socket_t socket)
+{
+ struct sockaddr_in addr;
+ axis2_socket_len_t len = sizeof(addr);
+ char *ret = NULL;
+ memset(&addr, 0, sizeof(addr));
+ if(getsockname(socket, (struct sockaddr *)&addr, &len) < 0)
+ {
+ return NULL;
+ }
+ ret = inet_ntoa(addr.sin_addr);
+ return ret;
+}
+
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+axutil_network_handler_get_peer_ip(
+ const axutil_env_t *env,
+ axis2_socket_t socket)
+{
+ struct sockaddr_in addr;
+ axis2_socket_len_t len = sizeof(addr);
+ char *ret = NULL;
+ memset(&addr, 0, sizeof(addr));
+ if(getpeername(socket, (struct sockaddr *)&addr, &len) < 0)
+ {
+ return NULL;
+ }
+ ret = inet_ntoa(addr.sin_addr);
+ return ret;
+}
+
+AXIS2_EXTERN axis2_socket_t AXIS2_CALL
+axutil_network_handler_create_dgram_svr_socket(
+ const axutil_env_t *env,
+ int port)
+{
+ axis2_socket_t sock = AXIS2_INVALID_SOCKET;
+ struct sockaddr_in sock_addr;
+
+ AXIS2_ENV_CHECK(env, AXIS2_CRITICAL_FAILURE);
+#if defined(WIN32)
+ if (is_init_socket == 0)
+ {
+ axis2_init_socket();
+ is_init_socket = 1;
+ }
+#endif
+ sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+
+#ifndef WIN32
+ if(sock < 0)
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_ERROR, AXIS2_FAILURE);
+ return AXIS2_INVALID_SOCKET;
+ }
+#else
+ if (sock == INVALID_SOCKET)
+ {
+ axis2_char_t buf[AXUTIL_WIN32_ERROR_BUFSIZE];
+ axutil_win32_get_last_wsa_error(buf, AXUTIL_WIN32_ERROR_BUFSIZE);
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_ERROR, AXIS2_FAILURE);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, buf);
+ return AXIS2_INVALID_SOCKET;
+ }
+#endif
+ /* Exec behaviour */
+ AXIS2_CLOSE_SOCKET_ON_EXIT(sock) memset(&sock_addr, 0, sizeof(sock_addr));
+
+ sock_addr.sin_family = AF_INET;
+ sock_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ sock_addr.sin_port = htons((axis2_unsigned_short_t)port);
+
+ /* Bind the socket to our port number */
+ if(bind(sock, (struct sockaddr *)&sock_addr, sizeof(sock_addr)) < 0)
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_BIND_FAILED, AXIS2_FAILURE);
+ return AXIS2_INVALID_SOCKET;
+ }
+ return sock;
+}
+
+AXIS2_EXTERN axis2_socket_t AXIS2_CALL
+axutil_network_handler_open_dgram_socket(
+ const axutil_env_t *env)
+{
+ axis2_socket_t sock = AXIS2_INVALID_SOCKET;
+#if defined(WIN32)
+ if (is_init_socket == 0)
+ {
+ axis2_init_socket();
+ is_init_socket = 1;
+ }
+#endif
+
+#ifndef WIN32
+ if((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ /*AF_INET is not defined in sys/socket.h but PF_INET */
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_ERROR, AXIS2_FAILURE);
+ return AXIS2_INVALID_SOCKET;
+ }
+#else
+ if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET)
+ /* In Win 32 if the socket creation failed it return 0 not a negative value */
+ {
+ char buf[AXUTIL_WIN32_ERROR_BUFSIZE];
+ /* Get the detailed error message */
+ axutil_win32_get_last_wsa_error(buf, AXUTIL_WIN32_ERROR_BUFSIZE);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, buf);
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_ERROR, AXIS2_FAILURE);
+ return AXIS2_INVALID_SOCKET;
+ }
+#endif
+ return sock;
+}
+
+/*
+ * This function blocks until data is available to read from the socket
+ * and read all the data in the socket. If the buffer size specified is
+ * lesser than the actual data a failure will be returned.
+ */
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+axutil_network_handler_read_dgram(
+ const axutil_env_t *env,
+ axis2_socket_t sock,
+ axis2_char_t *buffer,
+ int *buf_len,
+ axis2_char_t **addr,
+ int *port)
+{
+ struct sockaddr_in sender_address;
+ int received = 0;
+ unsigned int sender_address_size = sizeof(sender_address);
+
+ received = recvfrom(sock, buffer, *buf_len, 0, (struct sockaddr *)&sender_address,
+ &sender_address_size);
+
+#ifdef WIN32
+ if (SOCKET_ERROR == received)
+ {
+ axis2_char_t buf[AXUTIL_WIN32_ERROR_BUFSIZE];
+ axutil_win32_get_last_wsa_error(buf, AXUTIL_WIN32_ERROR_BUFSIZE);
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_ERROR, AXIS2_FAILURE);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, buf);
+ return AXIS2_FAILURE;
+ }
+#else
+ if(received < 0)
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_ERROR, AXIS2_FAILURE);
+ return AXIS2_INVALID_SOCKET;
+ }
+#endif
+ if(port && addr)
+ {
+ *port = ntohs(sender_address.sin_port);
+ *addr = inet_ntoa(sender_address.sin_addr);
+ }
+ *buf_len = received;
+ return AXIS2_SUCCESS;
+}
+
+/*
+ * Sends a datagram to the specified location.
+ */
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+axutil_network_handler_send_dgram(
+ const axutil_env_t *env,
+ axis2_socket_t sock,
+ axis2_char_t *buff,
+ int *buf_len,
+ axis2_char_t *addr,
+ int dest_port,
+ int *source_port)
+{
+ struct sockaddr_in recv_addr, source_addr;
+ int send_bytes = 0;
+ unsigned int recv_addr_size = 0;
+ unsigned int source_addr_size = sizeof(source_addr);
+ recv_addr_size = sizeof(recv_addr);
+
+ memset(&recv_addr, 0, sizeof(recv_addr));
+ memset(&recv_addr, 0, sizeof(source_addr));
+
+ recv_addr.sin_addr.s_addr = inet_addr(addr);
+ if(recv_addr.sin_addr.s_addr == AXIS2_INADDR_NONE) /*netinet/in.h */
+ {
+ /*
+ * server may be a host name
+ */
+ struct hostent *lphost = NULL;
+ lphost = gethostbyname(addr);
+
+ if(lphost)
+ {
+ recv_addr.sin_addr.s_addr = ((struct in_addr *)lphost->h_addr)->s_addr;
+ }
+ else
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_ADDRESS, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ }
+
+ recv_addr.sin_family = AF_INET;
+ recv_addr.sin_port = htons((axis2_unsigned_short_t)dest_port);
+
+ send_bytes = sendto(sock, buff, *buf_len, 0, (struct sockaddr *)&recv_addr, recv_addr_size);
+
+ getsockname(sock, (struct sockaddr *)&source_addr, &source_addr_size);
+
+#ifdef WIN32
+ if (send_bytes == SOCKET_ERROR)
+ {
+ axis2_char_t buf[AXUTIL_WIN32_ERROR_BUFSIZE];
+ axutil_win32_get_last_wsa_error(buf, AXUTIL_WIN32_ERROR_BUFSIZE);
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_ERROR, AXIS2_FAILURE);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, buf);
+ return AXIS2_FAILURE;
+ }
+#else
+ if(send_bytes < 0)
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_ERROR, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+#endif
+ if(source_port)
+ {
+ *source_port = ntohs(source_addr.sin_port);
+ }
+ *buf_len = send_bytes;
+ return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+axutil_network_handler_bind_socket(
+ const axutil_env_t *env,
+ axis2_socket_t sock,
+ int port)
+{
+ struct sockaddr_in source_addr;
+
+ memset(&source_addr, 0, sizeof(source_addr));
+ source_addr.sin_family = AF_INET;
+ source_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ source_addr.sin_port = htons((axis2_unsigned_short_t)port);
+#ifdef WIN32
+ if (bind(sock, (struct sockaddr *)&source_addr, sizeof(source_addr)) == SOCKET_ERROR)
+ {
+ axis2_char_t buf[AXUTIL_WIN32_ERROR_BUFSIZE];
+ axutil_win32_get_last_wsa_error(buf, AXUTIL_WIN32_ERROR_BUFSIZE);
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_ERROR, AXIS2_FAILURE);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, buf);
+ return AXIS2_FAILURE;
+ }
+#else
+ if(bind(sock, (struct sockaddr *)&source_addr, sizeof(source_addr)) < 0)
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_ERROR, AXIS2_FAILURE);
+ return AXIS2_INVALID_SOCKET;
+ }
+#endif
+ return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN axis2_socket_t AXIS2_CALL
+axutil_network_hadler_create_multicast_svr_socket(
+ const axutil_env_t *env,
+ int port,
+ axis2_char_t *mul_addr)
+{
+ axis2_socket_t sock = AXIS2_INVALID_SOCKET;
+ struct sockaddr_in sock_addr;
+ struct ip_mreq mc_req;
+
+ AXIS2_ENV_CHECK(env, AXIS2_CRITICAL_FAILURE);
+#if defined(WIN32)
+ if (is_init_socket == 0)
+ {
+ axis2_init_socket();
+ is_init_socket = 1;
+ }
+#endif
+ sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+
+#ifndef WIN32
+ if(sock < 0)
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_ERROR, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+#else
+ if (sock == INVALID_SOCKET)
+ {
+ axis2_char_t buf[AXUTIL_WIN32_ERROR_BUFSIZE];
+ axutil_win32_get_last_wsa_error(buf, AXUTIL_WIN32_ERROR_BUFSIZE);
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_ERROR, AXIS2_FAILURE);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, buf);
+ return AXIS2_FAILURE;
+ }
+#endif
+
+ /* Exec behaviour */
+ AXIS2_CLOSE_SOCKET_ON_EXIT(sock) memset(&sock_addr, 0, sizeof(sock_addr));
+
+ sock_addr.sin_family = AF_INET;
+ sock_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ sock_addr.sin_port = htons((axis2_unsigned_short_t)port);
+
+ /* Bind the socket to our port number */
+ if(bind(sock, (struct sockaddr *)&sock_addr, sizeof(sock_addr)) < 0)
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_BIND_FAILED, AXIS2_FAILURE);
+ return AXIS2_INVALID_SOCKET;
+ }
+
+ /* Send an IGMP request to join the multicast group */
+ mc_req.imr_multiaddr.s_addr = inet_addr(mul_addr);
+ mc_req.imr_interface.s_addr = htonl(INADDR_ANY);
+#ifdef WIN32
+ if ((setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &mc_req, sizeof(mc_req))) == SOCKET_ERROR)
+ {
+ axis2_char_t buf[AXUTIL_WIN32_ERROR_BUFSIZE];
+ axutil_win32_get_last_wsa_error(buf, AXUTIL_WIN32_ERROR_BUFSIZE);
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_ERROR, AXIS2_FAILURE);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, buf);
+ return AXIS2_FAILURE;
+ }
+#else
+ if((setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&mc_req, sizeof(mc_req))) < 0)
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_ERROR, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+#endif
+ return sock;
+}
+
diff --git a/util/src/param.c b/util/src/param.c new file mode 100644 index 0000000..48e14ae --- /dev/null +++ b/util/src/param.c @@ -0,0 +1,302 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_param.h> +#include <axutil_utils.h> +#include <axutil_string.h> +#include <axutil_generic_obj.h> + +struct axutil_param +{ + /** Parameter name */ + axis2_char_t *name; + + /** Parameter value */ + void *value; + + /** Parameter locked? */ + axis2_bool_t locked; + + /** Parameter type */ + int type; /*default is AXIS2_TEXT_PARAM */ + axutil_hash_t *attrs; + axutil_array_list_t *value_list; + void( + AXIS2_CALL *value_free) ( + void *param_value, + const axutil_env_t *env); +}; + +AXIS2_EXTERN axutil_param_t *AXIS2_CALL +axutil_param_create( + const axutil_env_t *env, + axis2_char_t *name, + void *value) +{ + axutil_param_t *param = NULL; + AXIS2_ENV_CHECK(env, NULL); + + param = AXIS2_MALLOC(env->allocator, sizeof(axutil_param_t)); + if(!param) + { + AXIS2_ERROR_SET_ERROR_NUMBER(env->error, AXIS2_ERROR_NO_MEMORY); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Not enough memory"); + AXIS2_ERROR_SET_STATUS_CODE(env->error, AXIS2_FAILURE); + return NULL; + } + + param->name = axutil_strdup(env, name); + param->value = value; /* shallow copy. */ + param->locked = AXIS2_FALSE; + param->type = AXIS2_TEXT_PARAM; + param->attrs = NULL; + param->value_list = NULL; + param->value_free = NULL; + + return param; +} + +axis2_char_t *AXIS2_CALL +axutil_param_get_name( + axutil_param_t *param, + const axutil_env_t *env) +{ + return param->name; +} + +void *AXIS2_CALL +axutil_param_get_value( + axutil_param_t *param, + const axutil_env_t *env) +{ + return param->value; +} + +axis2_status_t AXIS2_CALL +axutil_param_set_name( + axutil_param_t *param, + const axutil_env_t *env, + const axis2_char_t *name) +{ + param->name = axutil_strdup(env, name); + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axutil_param_set_value( + axutil_param_t *param, + const axutil_env_t *env, + const void *value) +{ + void *param_value = NULL; + param_value = axutil_param_get_value(param, env); + if(param_value) + { + if(param && param->value_free) + { + param->value_free(param_value, env); + } + else /* we assume that param value is axis2_char_t* */ + { + AXIS2_FREE(env->allocator, param_value); + } + } + param->value = (void *)value; + return AXIS2_SUCCESS; +} + +axis2_bool_t AXIS2_CALL +axutil_param_is_locked( + axutil_param_t *param, + const axutil_env_t *env) +{ + return param->locked; +} + +axis2_status_t AXIS2_CALL +axutil_param_set_locked( + axutil_param_t *param, + const axutil_env_t *env, + axis2_bool_t value) +{ + param->locked = value; + return AXIS2_SUCCESS; +} + +int AXIS2_CALL +axutil_param_get_param_type( + axutil_param_t *param, + const axutil_env_t *env) +{ + return param->type; +} + +axis2_status_t AXIS2_CALL +axutil_param_set_param_type( + axutil_param_t *param, + const axutil_env_t *env, + int type) +{ + param->type = type; + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axutil_param_set_attributes( + axutil_param_t *param, + const axutil_env_t *env, + axutil_hash_t *attrs) +{ + AXIS2_PARAM_CHECK(env->error, attrs, AXIS2_FAILURE); + + if(param->attrs) + { + axutil_hash_index_t *i = NULL; + void *v = NULL; + + for(i = axutil_hash_first(param->attrs, env); i; i = axutil_hash_next(env, i)) + { + axutil_hash_this(i, NULL, NULL, &v); + axutil_generic_obj_free(v, env); + } + axutil_hash_free(param->attrs, env); + } + + param->attrs = attrs; + return AXIS2_SUCCESS; +} + +axutil_hash_t *AXIS2_CALL +axutil_param_get_attributes( + axutil_param_t *param, + const axutil_env_t *env) +{ + return param->attrs; +} + +axis2_status_t AXIS2_CALL +axutil_param_set_value_list( + axutil_param_t *param, + const axutil_env_t *env, + axutil_array_list_t *value_list) +{ + AXIS2_PARAM_CHECK(env->error, value_list, AXIS2_FAILURE); + + if(param->value_list) + { + int i = 0, size = 0; + + size = axutil_array_list_size(param->value_list, env); + for(i = 0; i < size; i++) + { + axutil_param_t *param = NULL; + + param = (axutil_param_t *)axutil_array_list_get(param->value_list, env, i); + axutil_param_free(param, env); + } + axutil_array_list_free(param->value_list, env); + } + param->value_list = value_list; + + return AXIS2_SUCCESS; +} + +axutil_array_list_t *AXIS2_CALL +axutil_param_get_value_list( + axutil_param_t *param, + const axutil_env_t *env) +{ + return param->value_list; +} + +void AXIS2_CALL +axutil_param_free( + axutil_param_t *param, + const axutil_env_t *env) +{ + void *param_value = NULL; + axis2_char_t *param_name = NULL; + + param_value = axutil_param_get_value(param, env); + if(param_value) + { + if(param && param->value_free) + { + param->value_free(param_value, env); + } + else /* we assume that param value is axis2_char_t* */ + { + AXIS2_FREE(env->allocator, param_value); + } + } + + if(param->attrs) + { + axutil_hash_index_t *i = NULL; + void *v = NULL; + + for(i = axutil_hash_first(param->attrs, env); i; i = axutil_hash_next(env, i)) + { + axutil_hash_this(i, NULL, NULL, &v); + axutil_generic_obj_free(v, env); + } + axutil_hash_free(param->attrs, env); + } + + if(param->value_list) + { + int i = 0, size = 0; + + size = axutil_array_list_size(param->value_list, env); + for(i = 0; i < size; i++) + { + axutil_param_t *param_l = NULL; + + param_l = (axutil_param_t *)axutil_array_list_get(param->value_list, env, i); + if(param_l) + { + axutil_param_free(param_l, env); + } + } + axutil_array_list_free(param->value_list, env); + } + param_name = axutil_param_get_name(param, env); + AXIS2_FREE(env->allocator, param_name); + AXIS2_FREE(env->allocator, param); + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_param_set_value_free( + axutil_param_t *param, + const axutil_env_t *env, + AXIS2_PARAM_VALUE_FREE free_fn) +{ + param->value_free = free_fn; + return AXIS2_SUCCESS; +} + +/* Use this function for the copied parameters + * to avoid double free + */ +AXIS2_EXTERN void AXIS2_CALL +axutil_param_dummy_free_fn( + void *param, + const axutil_env_t *env) +{ + return; +} diff --git a/util/src/param_container.c b/util/src/param_container.c new file mode 100644 index 0000000..8d9f188 --- /dev/null +++ b/util/src/param_container.c @@ -0,0 +1,228 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_param_container.h> + +struct axutil_param_container +{ + axutil_hash_t *params; + axutil_array_list_t *params_list; +}; + +AXIS2_EXTERN axutil_param_container_t *AXIS2_CALL +axutil_param_container_create( + const axutil_env_t *env) +{ + axutil_param_container_t *param_container = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + param_container = (axutil_param_container_t *)AXIS2_MALLOC(env->allocator, + sizeof(axutil_param_container_t)); + + if(!param_container) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Not enough memory"); + return NULL; + } + + param_container->params = NULL; + param_container->params_list = NULL; + param_container->params_list = axutil_array_list_create(env, 0); + + param_container->params = axutil_hash_make(env); + if(!param_container->params) + { + axutil_param_container_free(param_container, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Not enough memory"); + return NULL; + } + + return param_container; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_param_container_free( + axutil_param_container_t *param_container, + const axutil_env_t *env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(param_container->params) + { + axutil_hash_index_t *hi = NULL; + void *val = NULL; + for(hi = axutil_hash_first(param_container->params, env); hi; hi + = axutil_hash_next(env, hi)) + { + axutil_param_t *param = NULL; + axutil_hash_this(hi, NULL, NULL, &val); + param = (axutil_param_t *)val; + if(param) + { + axutil_param_free(param, env); + param = NULL; + } + val = NULL; + } + axutil_hash_free(param_container->params, env); + } + if(param_container->params_list) + { + /* This is the array list which is returned when all params are + * requested from param_container. Params referenced here are + * actually contained in params hash table + */ + axutil_array_list_free(param_container->params_list, env); + param_container->params_list = NULL; + } + + AXIS2_FREE(env->allocator, param_container); + return; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_param_container_free_void_arg( + void *param_container, + const axutil_env_t *env) +{ + axutil_param_container_t *param_container_l = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + param_container_l = (axutil_param_container_t *)param_container; + axutil_param_container_free(param_container_l, env); + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_param_container_add_param( + axutil_param_container_t *param_container, + const axutil_env_t *env, + axutil_param_t *param) +{ + axis2_char_t *param_name = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, param, AXIS2_FAILURE); + + if(!(param_container->params)) + { + param_container->params = axutil_hash_make(env); + if(!param_container->params) + { + return AXIS2_FAILURE; + } + } + param_name = axutil_param_get_name(param, env); + if(!param_name) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_STATE_PARAM, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Invalid param state"); + return AXIS2_FAILURE; + } + axutil_hash_set(param_container->params, param_name, AXIS2_HASH_KEY_STRING, param); + axutil_array_list_add(param_container->params_list, env, param); + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axutil_param_t *AXIS2_CALL +axutil_param_container_get_param( + axutil_param_container_t *param_container, + const axutil_env_t *env, + const axis2_char_t *name) +{ + return (axutil_param_t *)(axutil_hash_get(param_container->params, name, AXIS2_HASH_KEY_STRING)); +} + +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +axutil_param_container_get_params( + axutil_param_container_t *param_container, + const axutil_env_t *env) +{ + if(param_container->params_list) + { + return param_container->params_list; + }else + { + axutil_hash_index_t *hi = NULL; + void *val = NULL; + + param_container->params_list = axutil_array_list_create(env, 0); + + for(hi = axutil_hash_first(param_container->params, env); hi; hi + = axutil_hash_next(env, hi)) + { + axutil_param_t *param = NULL; + axutil_hash_this(hi, NULL, NULL, &val); + param = (axutil_param_t *)val; + if(param) + { + axutil_array_list_add(param_container->params_list, env, param); + } + } + } + return param_container->params_list; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axutil_param_container_is_param_locked( + axutil_param_container_t *param_container, + const axutil_env_t *env, + const axis2_char_t *param_name) +{ + axutil_param_t *param = NULL; + + param = (axutil_param_t *)(axutil_hash_get(param_container->params, param_name, + AXIS2_HASH_KEY_STRING)); + if(!param) + { + /* In this case we consider param is not locked */ + return AXIS2_FALSE; + } + return axutil_param_is_locked(param, env); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_param_container_delete_param( + axutil_param_container_t *param_container, + const axutil_env_t *env, + const axis2_char_t *param_name) +{ + axutil_param_t *param = NULL; + + if(!param_name) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "The requested parameter does not exist"); + return AXIS2_FAILURE; + } + param = axutil_hash_get(param_container->params, param_name, AXIS2_HASH_KEY_STRING); + if(param) + { + /** Parameter exists, So remove it from hash table and delete the array list param_list + which will be built in the next call to get_params + */ + axutil_hash_set(param_container->params, param_name, AXIS2_HASH_KEY_STRING, NULL); + axutil_param_free(param, env); + axutil_array_list_free(param_container->params_list, env); + param_container->params_list = NULL; + return AXIS2_SUCCESS; + } + return AXIS2_FAILURE; +} diff --git a/util/src/platforms/unix/Makefile.am b/util/src/platforms/unix/Makefile.am new file mode 100644 index 0000000..6506a01 --- /dev/null +++ b/util/src/platforms/unix/Makefile.am @@ -0,0 +1,8 @@ +noinst_LTLIBRARIES = libaxis2_unix.la + +libaxis2_unix_la_SOURCES = uuid_gen_unix.c\ + thread_unix.c date_time_util_unix.c + +INCLUDES = -I$(top_builddir)/include \ + -I$(top_builddir)/include/platforms \ + -I$(top_builddir)/include/platforms/unix diff --git a/util/src/platforms/unix/date_time_util_unix.c b/util/src/platforms/unix/date_time_util_unix.c new file mode 100644 index 0000000..e0c4a28 --- /dev/null +++ b/util/src/platforms/unix/date_time_util_unix.c @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <platforms/unix/axutil_date_time_util_unix.h> + +AXIS2_EXTERN int AXIS2_CALL +axis2_platform_get_milliseconds() +{ + struct timeb t_current; + int milliseconds; + + ftime(&t_current); + milliseconds = t_current.millitm; + + return milliseconds; + +} diff --git a/util/src/platforms/unix/thread_unix.c b/util/src/platforms/unix/thread_unix.c new file mode 100644 index 0000000..ccedd06 --- /dev/null +++ b/util/src/platforms/unix/thread_unix.c @@ -0,0 +1,362 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <config.h> +#include "axutil_thread_unix.h" + +AXIS2_EXTERN axutil_threadattr_t *AXIS2_CALL +axutil_threadattr_create( + axutil_allocator_t * allocator) +{ + int stat = 0; + axutil_threadattr_t *new = NULL; + + new = AXIS2_MALLOC(allocator, sizeof(axutil_threadattr_t)); + if(!new) + { + return NULL; + } + stat = pthread_attr_init(&(new->attr)); + + if(stat != 0) + { + AXIS2_FREE(allocator, new); + return NULL; + } + return new; +} + +/* Destroy the threadattr object */ +AXIS2_EXTERN axis2_status_t AXIS2_CALL +threadattr_cleanup( + void *data) +{ + axutil_threadattr_t *attr = data; + int rv; + + rv = pthread_attr_destroy(&(attr->attr)); + + if(0 != rv) + { + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +#define DETACH_ARG(v) ((v) ? PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE) + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_threadattr_detach_set( + axutil_threadattr_t * attr, + axis2_bool_t detached) +{ + if(0 == pthread_attr_setdetachstate(&(attr->attr), DETACH_ARG(detached))) + { + return AXIS2_SUCCESS; + } + return AXIS2_FAILURE; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_threadattr_detach_get( + axutil_threadattr_t * attr) +{ + int state = 0; + pthread_attr_getdetachstate(&(attr->attr), &state); + if(state == 1) + { + return AXIS2_TRUE; + } + return AXIS2_FALSE; +} + +static void * +dummy_worker( + void *opaque) +{ + axutil_thread_t *thread = (axutil_thread_t *)opaque; + return thread->func(thread, thread->data); +} + +AXIS2_EXTERN axutil_thread_t *AXIS2_CALL +axutil_thread_create( + axutil_allocator_t * allocator, + axutil_threadattr_t * attr, + axutil_thread_start_t func, + void *data) +{ + axis2_status_t stat; + pthread_attr_t *temp = NULL; + axutil_thread_t *new = NULL; + + new = (axutil_thread_t *)AXIS2_MALLOC(allocator, sizeof(axutil_thread_t)); + + if(!new) + { + return NULL; + } + new->td = (pthread_t *)AXIS2_MALLOC(allocator, sizeof(pthread_t)); + if(!new->td) + { + return NULL; + } + + new->data = data; + new->func = func; + new->try_exit = AXIS2_FALSE; + + if(attr) + { + temp = &(attr->attr); + } + else + { + temp = NULL; + } + + if((stat = pthread_create(new->td, temp, dummy_worker, new)) == 0) + { + return new; + } + return NULL; +} + +AXIS2_EXTERN axis2_os_thread_t AXIS2_CALL +axis2_os_thread_current( + void) +{ + return pthread_self(); +} + +AXIS2_EXTERN int AXIS2_CALL +axis2_os_thread_equal( + axis2_os_thread_t tid1, + axis2_os_thread_t tid2) +{ + return pthread_equal(tid1, tid2); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_exit( + axutil_thread_t * thd, + axutil_allocator_t * allocator) +{ + axis2_bool_t same_thread = AXIS2_TRUE; + if(thd) + { + while(!thd->try_exit) + { + sleep(1); + } + + if(thd->td) + { + same_thread = pthread_equal(pthread_self(), *thd->td); + if(!same_thread) + { + pthread_kill(*(thd->td), 0); + axutil_thread_join(thd); + } + AXIS2_FREE(allocator, thd->td); + } + AXIS2_FREE(allocator, thd); + } + if(same_thread) + { + pthread_exit(NULL); + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_join( + axutil_thread_t * thd) +{ + void *thread_stat; + if(0 == pthread_join(*(thd->td), (void *)(&thread_stat))) + { + return AXIS2_SUCCESS; + } + return AXIS2_FAILURE; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_detach( + axutil_thread_t * thd) +{ + if(0 == pthread_detach(*(thd->td))) + { + thd->try_exit = AXIS2_TRUE; + return AXIS2_SUCCESS; + } + return AXIS2_FAILURE; +} + +void +axutil_thread_yield( + void) +{ + return; +} + +/** + * function is used to allocate a new key. This key now becomes valid for all threads in our process. + * When a key is created, the value it points to defaults to NULL. Later on each thread may change + * its copy of the value as it wishes. + */ +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_key_create( + axutil_threadkey_t * axis2_key) +{ + int rc = -1; + pthread_key_t key = axis2_key->key; + rc = pthread_key_create(&key, NULL); + if(0 == rc) + return AXIS2_SUCCESS; + else + return AXIS2_FAILURE; +} + +/** + * This function is used to get the value of a given key + * @return void*. A key's value is simply a void pointer (void*) + */ +AXIS2_EXTERN void *AXIS2_CALL +axutil_thread_getspecific( + axutil_threadkey_t * axis2_key) +{ + void *value = NULL; + pthread_key_t key = axis2_key->key; + value = pthread_getspecific(key); + return value; +} + +/** + * This function is used to get the value of a given key + * @param keys value. A key's value is simply a void pointer (void*), so we can + * store in it anything that we want + */ +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_setspecific( + axutil_threadkey_t * axis2_key, + void *value) +{ + int rc = -1; + pthread_key_t key = axis2_key->key; + rc = pthread_setspecific(key, value); + if(0 == rc) + return AXIS2_SUCCESS; + else + return AXIS2_FAILURE; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_thread_key_free( + axutil_threadkey_t * axis2_key) +{ + pthread_key_t key = axis2_key->key; + pthread_key_delete(key); +} + +AXIS2_EXTERN axis2_os_thread_t *AXIS2_CALL +axis2_os_thread_get( + axutil_thread_t * thd) +{ + if(!thd) + { + return NULL; + } + return thd->td; +} + +AXIS2_EXTERN axutil_thread_once_t *AXIS2_CALL +axutil_thread_once_init( + axutil_allocator_t * allocator) +{ +#if defined(AXIS2_SOLARIS) && (__GNUC__ <= 3) + static const pthread_once_t once_init = + { PTHREAD_ONCE_INIT}; +#else + static const pthread_once_t once_init = PTHREAD_ONCE_INIT; +#endif + axutil_thread_once_t *control = AXIS2_MALLOC(allocator, sizeof(axutil_thread_once_t)); + if(!control) + { + return NULL;; + } + (control)->once = once_init; + return control; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_once( + axutil_thread_once_t * control, + void + (*func)( + void)) +{ + return pthread_once(&(control->once), func); +} + +/*************************Thread locking functions*****************************/ +AXIS2_EXTERN axutil_thread_mutex_t *AXIS2_CALL +axutil_thread_mutex_create( + axutil_allocator_t * allocator, + unsigned int flags) +{ + axutil_thread_mutex_t *new_mutex = NULL; + + new_mutex = AXIS2_MALLOC(allocator, sizeof(axutil_thread_mutex_t)); + new_mutex->allocator = allocator; + + if(pthread_mutex_init(&(new_mutex->mutex), NULL) != 0) + { + AXIS2_FREE(allocator, new_mutex); + return NULL; + } + return new_mutex; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_mutex_lock( + axutil_thread_mutex_t * mutex) +{ + return pthread_mutex_lock(&(mutex->mutex)); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_mutex_unlock( + axutil_thread_mutex_t * mutex) +{ + if(pthread_mutex_unlock(&(mutex->mutex)) != 0) + { + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_mutex_destroy( + axutil_thread_mutex_t * mutex) +{ + if(0 != pthread_mutex_destroy(&(mutex->mutex))) + { + return AXIS2_FAILURE; + } + AXIS2_FREE(mutex->allocator, mutex); + return AXIS2_SUCCESS; +} diff --git a/util/src/platforms/unix/uuid_gen_unix.c b/util/src/platforms/unix/uuid_gen_unix.c new file mode 100644 index 0000000..cdc2544 --- /dev/null +++ b/util/src/platforms/unix/uuid_gen_unix.c @@ -0,0 +1,345 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <config.h> + +#include <sys/ioctl.h> +#include <string.h> +#include <arpa/inet.h> +#include <netinet/in.h> +#include <netdb.h> +#include <fcntl.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/time.h> + +#ifdef HAVE_LINUX_IF_H +# include <linux/if.h> +#else +# ifdef HAVE_NET_IF_H +# include <sys/sockio.h> +# include <net/if.h> +# include <net/if_arp.h> +# endif +# ifdef HAVE_NET_IF_TYPES_H +# include <net/if_types.h> +# endif +# ifdef HAVE_NET_IF_DL_H +# include <net/if_dl.h> +# endif +#endif +#ifdef HAVE_GETIFADDRS +#include <ifaddrs.h> +#endif +#include <platforms/unix/axutil_uuid_gen_unix.h> +#include <platforms/axutil_platform_auto_sense.h> + +/* We need these static variables to track throughout the program execution */ +static axis2_bool_t axutil_uuid_gen_is_first = AXIS2_TRUE; +static struct axutil_uuid_st axutil_uuid_static; + +axutil_uuid_t *AXIS2_CALL +axutil_uuid_gen_v1() +{ + struct timeval time_now; + struct timeval tv; + unsigned long long time_val; + unsigned long long time_val2; + unsigned short int clck = 0; + axutil_uuid_t *ret_uuid = NULL; + unsigned short int time_high_version = 0; + + if(AXIS2_TRUE == axutil_uuid_gen_is_first) + { + char *mac_addr = axutil_uuid_get_mac_addr(); + memcpy(axutil_uuid_static.mac, mac_addr, 6); + axutil_uuid_static.time_seq = 0; + axutil_uuid_static.clock = 0; + free(mac_addr); + axutil_uuid_gen_is_first = AXIS2_FALSE; + } + /* + * GENERATE TIME + */ + + /* determine current system time and sequence counter */ + if(gettimeofday(&time_now, NULL) == -1) + return NULL; + + /* check whether system time changed since last retrieve */ + if(!(time_now.tv_sec == axutil_uuid_static.time_last.tv_sec && time_now.tv_usec + == axutil_uuid_static.time_last.tv_usec)) + { + /* reset time sequence counter and continue */ + axutil_uuid_static.time_seq = 0; + } + + /* until we are out of UUIDs per tick, increment + the time/tick sequence counter and continue */ + while(axutil_uuid_static.time_seq < UUIDS_PER_TICK) + { + axutil_uuid_static.time_seq++; + } + /* sleep for 1000ns (1us) */ + tv.tv_sec = 0; + tv.tv_usec = 1; + /* + The following select causes severe performance problems. + Hence commenting out. I am not sure why this is required. - Samisa. + select(0, NULL, NULL, NULL, &tv); */ + + time_val = (unsigned long long)time_now.tv_sec * 10000000ull; + time_val += (unsigned long long)time_now.tv_usec * 10ull; + + ret_uuid = malloc(sizeof(axutil_uuid_t)); + + time_val += UUID_TIMEOFFSET; + /* compensate for low resolution system clock by adding + the time/tick sequence counter */ + if(axutil_uuid_static.time_seq > 0) + time_val += (unsigned long long)axutil_uuid_static.time_seq; + + time_val2 = time_val; + ret_uuid->time_low = (unsigned long)time_val2; + time_val2 >>= 32; + ret_uuid->time_mid = (unsigned short int)time_val2; + time_val2 >>= 16; + time_high_version = (unsigned short int)time_val2; + + /* store the 60 LSB of the time in the UUID and make version 1 */ + time_high_version <<= 4; + time_high_version &= 0xFFF0; + time_high_version |= 0x0001; + ret_uuid->time_high_version = time_high_version; + + /* + * GENERATE CLOCK + */ + + /* retrieve current clock sequence */ + clck = axutil_uuid_static.clock; + + /* generate new random clock sequence (initially or if the + time has stepped backwards) or else just increase it */ + if(clck == 0 || (time_now.tv_sec < axutil_uuid_static.time_last.tv_sec || (time_now.tv_sec + == axutil_uuid_static.time_last.tv_sec && time_now.tv_usec + < axutil_uuid_static.time_last.tv_usec))) + { + srand(time_now.tv_usec); + clck = rand(); + } + else + { + clck++; + } + clck %= (2 << 14); + + /* store back new clock sequence */ + axutil_uuid_static.clock = clck; + + clck &= 0x1FFF; + clck |= 0x2000; + + /* + * FINISH + */ + /* remember current system time for next iteration */ + axutil_uuid_static.time_last.tv_sec = time_now.tv_sec; + axutil_uuid_static.time_last.tv_usec = time_now.tv_usec; + + if(!ret_uuid) + { + return NULL; + } + ret_uuid->clock_variant = clck; + memcpy(ret_uuid->mac_addr, axutil_uuid_static.mac, 6); + return ret_uuid; +} + +axis2_char_t *AXIS2_CALL +axutil_platform_uuid_gen( + char *s) +{ + axutil_uuid_t *uuid_struct = NULL; + axis2_char_t *uuid_str = NULL; + unsigned char mac[7]; + char mac_hex[13]; + + if(!s) + { + return NULL; + } + uuid_struct = axutil_uuid_gen_v1(); + if(!uuid_struct) + { + return NULL; + } + uuid_str = s; + if(!uuid_str) + { + return NULL; + } + memcpy(mac, uuid_struct->mac_addr, 6); + sprintf(mac_hex, "%02x%02x%02x%02x%02x%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + sprintf(uuid_str, "%08x-%04x-%04x-%04x-%s", uuid_struct->time_low, uuid_struct->time_mid, + uuid_struct->time_high_version, uuid_struct->clock_variant, mac_hex); + free(uuid_struct); + uuid_struct = NULL; + return uuid_str; +} + +#ifdef HAVE_LINUX_IF_H /* Linux */ + +char *AXIS2_CALL +axutil_uuid_get_mac_addr( +) +{ + struct ifreq ifr; + struct ifreq *IFR; + struct ifconf ifc; + struct sockaddr *sa; + int s = 0; + int i = 0; + char *buffer = NULL; + char buf[1024]; + int ok = AXIS2_FALSE; + + if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) + return NULL; + + ifc.ifc_len = sizeof(buf); + ifc.ifc_buf = buf; + ioctl(s, SIOCGIFCONF, &ifc); + IFR = ifc.ifc_req; + + for (i = ifc.ifc_len / sizeof(struct ifreq); --i >= 0; IFR++) + { + strcpy(ifr.ifr_name, IFR->ifr_name); + /*sprintf(ifr.ifr_name, "eth0"); */ + if (ioctl(s, SIOCGIFFLAGS, &ifr) == 0) + { + if (!(ifr.ifr_flags & IFF_LOOPBACK)) + { + if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0) + { + ok = AXIS2_TRUE; + break; + } + } + } + } + buffer = (char *) malloc(6 * sizeof(char)); + if (ok) + { + sa = (struct sockaddr *) &ifr.ifr_addr; + for (i = 0; i < 6; i++) + buffer[i] = (unsigned char) (sa->sa_data[i] & 0xff); + } + else + { + for (i = 0; i < 6; i++) + buffer[i] = (unsigned char) ((AXIS2_LOCAL_MAC_ADDR[i]) - '0'); + } + close(s); + return buffer; +} + +#else + +#ifdef HAVE_GETIFADDRS /* NetBSD, MacOSX, etc... */ + +#ifndef max +# define max(a,b) ((a) > (b) ? (a) : (b)) +#endif /* !max */ + +char *AXIS2_CALL +axutil_uuid_get_mac_addr( +) +{ + struct ifaddrs *ifap; + struct ifaddrs *ifap_head; + const struct sockaddr_dl *sdl; + unsigned char *ucp; + int i; + char *data_ptr; + + if (getifaddrs(&ifap_head) < 0) + return NULL; + for (ifap = ifap_head; ifap != NULL; ifap = ifap->ifa_next) + { + if (ifap->ifa_addr != NULL && ifap->ifa_addr->sa_family == AF_LINK) + { + sdl = (const struct sockaddr_dl *) (void *) ifap->ifa_addr; + ucp = (unsigned char *) (sdl->sdl_data + sdl->sdl_nlen); + if (sdl->sdl_alen > 0) + { + data_ptr = malloc(6 * sizeof(char)); + for (i = 0; i < 6 && i < sdl->sdl_alen; i++, ucp++) + data_ptr[i] = (unsigned char) (*ucp & 0xff); + + freeifaddrs(ifap_head); + return data_ptr; + } + } + } + freeifaddrs(ifap_head); + return NULL; +} +# else /* Solaris-ish */ + +/* code modified from that posted on: + * http://forum.sun.com/jive/thread.jspa?threadID=84804&tstart=30 + */ + +char *AXIS2_CALL +axutil_uuid_get_mac_addr() +{ + char hostname[MAXHOSTNAMELEN]; + char *data_ptr; + struct hostent *he; + struct arpreq ar; + struct sockaddr_in *sa; + int s; + int i; + + if(gethostname(hostname, sizeof(hostname)) < 0) + return NULL; + if((he = gethostbyname(hostname)) == NULL) + return NULL; + if((s = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) + return NULL; + memset(&ar, 0, sizeof(ar)); + sa = (struct sockaddr_in *)((void *)&(ar.arp_pa)); + sa->sin_family = AF_INET; + memcpy(&(sa->sin_addr), *(he->h_addr_list), sizeof(struct in_addr)); + if(ioctl(s, SIOCGARP, &ar) < 0) + { + close(s); + return NULL; + } + close(s); + if(!(ar.arp_flags & ATF_COM)) + return NULL; + data_ptr = malloc(6 * sizeof(char)); + for(i = 0; i < 6; i++) + data_ptr[i] = (unsigned char)(ar.arp_ha.sa_data[i] & 0xff); + + return data_ptr; +} +# endif +#endif diff --git a/util/src/platforms/windows/axutil_windows.c b/util/src/platforms/windows/axutil_windows.c new file mode 100644 index 0000000..e2abb5d --- /dev/null +++ b/util/src/platforms/windows/axutil_windows.c @@ -0,0 +1,93 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 <windows/axutil_windows.h>
+#include <stdio.h>
+
+
+/*
+
+std::string* getPlatformErrorMessage(long errorNumber)
+{
+ std::string* returningString = new std::string();
+ LPVOID lpMsgBuf;
+
+ FormatMessage(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL,
+ errorNumber,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) &lpMsgBuf,
+ 0, NULL );
+
+ returningString->append((LPTSTR)lpMsgBuf);
+ LocalFree(lpMsgBuf);
+
+ return returningString;
+}
+ */
+AXIS2_EXTERN HMODULE AXIS2_CALL
+callLoadLib(
+ char *lib)
+{
+ /* Disable display of the critical-error-handler message box */
+ SetErrorMode(SEM_FAILCRITICALERRORS);
+ return LoadLibraryEx(lib, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
+}
+
+AXIS2_EXTERN struct tm *AXIS2_CALL
+axis2_win_gmtime(
+ const time_t * timep,
+ struct tm *result)
+{
+ return gmtime(timep);
+}
+
+AXIS2_EXTERN void AXIS2_CALL
+axutil_win32_get_last_error(
+ axis2_char_t *buf,
+ unsigned int buf_size)
+{
+ LPVOID lpMsgBuf;
+ int rc = GetLastError();
+ sprintf(buf, "DLL Load Error %d: ", rc);
+ FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, rc, 0,
+ (LPTSTR) & lpMsgBuf, 0, NULL);
+ if(lpMsgBuf)
+ {
+ strncat(buf, (char*)lpMsgBuf, buf_size - strlen(buf) - 1);
+ }
+ LocalFree(lpMsgBuf);
+}
+
+AXIS2_EXTERN void AXIS2_CALL
+axutil_win32_get_last_wsa_error(
+ axis2_char_t *buf,
+ unsigned int buf_size)
+{
+ LPVOID lpMsgBuf;
+ int rc = WSAGetLastError();
+ sprintf(buf, "Winsock error %d: ", rc);
+ FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, rc, 0,
+ (LPTSTR) & lpMsgBuf, 0, NULL);
+ if(lpMsgBuf)
+ {
+ strncat(buf, (char*)lpMsgBuf, buf_size - strlen(buf) - 1);
+ }
+ LocalFree(lpMsgBuf);
+}
diff --git a/util/src/platforms/windows/date_time_util_windows.c b/util/src/platforms/windows/date_time_util_windows.c new file mode 100644 index 0000000..c07903b --- /dev/null +++ b/util/src/platforms/windows/date_time_util_windows.c @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <platforms/windows/axutil_date_time_util_windows.h> + +AXIS2_EXTERN int AXIS2_CALL +axis2_platform_get_milliseconds() +{ + struct _timeb timebuffer; + char *timeline; + int milliseconds = 0; + + _ftime(&timebuffer); + timeline = ctime(&(timebuffer.time)); + milliseconds = timebuffer.millitm; + + return milliseconds; +} diff --git a/util/src/platforms/windows/dir_windows.c b/util/src/platforms/windows/dir_windows.c new file mode 100644 index 0000000..1e0ad8f --- /dev/null +++ b/util/src/platforms/windows/dir_windows.c @@ -0,0 +1,272 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <malloc.h> +#include <string.h> +#include <errno.h> + +#include <platforms/windows/axutil_dir_windows.h> + +/*dirent.h style mehtods for win32*/ + +AXIS2_DIR *AXIS2_CALL +axis2_opendir( + const char *_dirname) +{ + AXIS2_DIR *dirp; + char *filespec; + long handle; + int index; + + filespec = malloc(strlen(_dirname) + 2 + 1); + strcpy(filespec, _dirname); + index = (int)strlen(filespec) - 1; + if(index >= 0 && (filespec[index] == '/' || (filespec[index] == '\\' && !IsDBCSLeadByte( + filespec[index - 1])))) + filespec[index] = '\0'; + strcat(filespec, "/*"); + + dirp = (AXIS2_DIR *)malloc(sizeof(AXIS2_DIR)); + dirp->offset = 0; + dirp->finished = 0; + + if((handle = (long)_findfirst(filespec, &(dirp->fileinfo))) < 0) + /* We are sure that the difference lies within the long range */ + { + if(errno == ENOENT || errno == EINVAL) + dirp->finished = 1; + else + { + free(dirp); + free(filespec); + return NULL; + } + } + /* We are using the ISO C++ conformant name: _strdup, as demanded by VS 2005 */ + dirp->dirname = _strdup(_dirname); + dirp->handle = handle; + free(filespec); + + return dirp; +} + +int AXIS2_CALL +axis2_closedir( + AXIS2_DIR * _dirp) +{ + int iret = -1; + if(!_dirp) + return iret; + iret = _findclose(_dirp->handle); + if(_dirp->dirname) + free(_dirp->dirname); + if(_dirp) + free(_dirp); + + return iret; +} + +struct dirent *AXIS2_CALL +axis2_readdir( + AXIS2_DIR * _dirp) +{ + if(!_dirp || _dirp->finished) + return NULL; + + if(_dirp->offset != 0) + { + if(_findnext(_dirp->handle, &(_dirp->fileinfo)) < 0) + { + _dirp->finished = 1; + return NULL; + } + } + _dirp->offset++; + + strcpy(_dirp->dent.d_name, _dirp->fileinfo.name); /*, _MAX_FNAME+1); */ + _dirp->dent.d_ino = 1; + _dirp->dent.d_reclen = (unsigned short)strlen(_dirp->dent.d_name); + _dirp->dent.d_off = _dirp->offset; + + return &(_dirp->dent); +} + +int AXIS2_CALL +axis2_readdir_r( + AXIS2_DIR * _dirp, + struct dirent *_entry, + struct dirent **__result) +{ + if(!_dirp || _dirp->finished) + { + *__result = NULL; + return -1; + } + + if(_dirp->offset != 0) + { + if(_findnext(_dirp->handle, &(_dirp->fileinfo)) < 0) + { + _dirp->finished = 1; + *__result = NULL; + return -1; + } + } + _dirp->offset++; + + strcpy(_dirp->dent.d_name, _dirp->fileinfo.name); /*, _MAX_FNAME+1); */ + _dirp->dent.d_ino = 1; + _dirp->dent.d_reclen = (unsigned short)strlen(_dirp->dent.d_name); + _dirp->dent.d_off = _dirp->offset; + + memcpy(_entry, &_dirp->dent, sizeof(*_entry)); + + *__result = &_dirp->dent; + + return 0; +} + +int AXIS2_CALL +axis2_rewinddir( + AXIS2_DIR * dirp) +{ + char *filespec; + long handle; + int index; + + _findclose(dirp->handle); + + dirp->offset = 0; + dirp->finished = 0; + + filespec = malloc(strlen(dirp->dirname) + 2 + 1); + strcpy(filespec, dirp->dirname); + index = (int)(strlen(filespec) - 1); + if(index >= 0 && (filespec[index] == '/' || filespec[index] == '\\')) + filespec[index] = '\0'; + strcat(filespec, "/*"); + + if((handle = (long)_findfirst(filespec, &(dirp->fileinfo))) < 0) + /* We are sure that the difference lies within the int range */ + { + if(errno == ENOENT || errno == EINVAL) + dirp->finished = 1; + } + dirp->handle = handle; + free(filespec); + + return 0; +} + +int +alphasort( + const struct dirent **__d1, + const struct dirent **__d2) +{ + return strcoll((*__d1)->d_name, (*__d2)->d_name); +} + +int AXIS2_CALL +axis2_scandir( + const char *_dirname, + struct dirent **__namelist[], + int + (*selector)( + const struct dirent * entry), + int + (*compare)( + const struct dirent ** __d1, + const struct dirent ** __d2)) +{ + AXIS2_DIR *dirp = NULL; + struct dirent **vector = NULL; + struct dirent *dp = NULL; + int vector_size = 0; + int nfiles = 0; + + if(__namelist == NULL) + { + return -1; + } + dirp = axis2_opendir(_dirname); + if(!dirp) + { + return -1; + } + dp = axis2_readdir(dirp); + while(dp) + { + int dsize = 0; + struct dirent *newdp = NULL; + + if(selector && (*selector)(dp) == 0) + { + dp = axis2_readdir(dirp); + continue; + } + + if(nfiles == vector_size) + { + struct dirent **newv; + if(vector_size == 0) + { + vector_size = 10; + } + else + { + vector_size *= 2; + } + + newv = (struct dirent **)realloc(vector, vector_size * sizeof(struct dirent *)); + if(!newv) + { + return -1; + } + vector = newv; + } + + /*dsize = + (int) sizeof(struct dirent) + + (int) ((strlen(dp->d_name) + 1) * sizeof(char));*/ + dsize = (int)sizeof(struct dirent); + newdp = (struct dirent *)malloc(dsize); + + if(newdp == NULL) + { + while(nfiles-- > 0) + { + free(vector[nfiles]); + } + free(vector); + return -1; + } + + vector[nfiles++] = (struct dirent *)memcpy(newdp, dp, dsize); + dp = axis2_readdir(dirp); + } + + axis2_closedir(dirp); + + *__namelist = vector; + + if(compare) + { + qsort(*__namelist, nfiles, sizeof(struct dirent *), compare); + } + + return nfiles; +} diff --git a/util/src/platforms/windows/getopt_windows.c b/util/src/platforms/windows/getopt_windows.c new file mode 100644 index 0000000..6f5e18b --- /dev/null +++ b/util/src/platforms/windows/getopt_windows.c @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <stdlib.h> +#include <string.h> +#include <stdio.h> + +#ifndef AXIS2_GET_OPT_DEFINE_MODE_NO_IMPORT +/* Required by "axutil_getopt_windows.h" */ +#define AXIS2_GET_OPT_DEFINE_MODE_NO_IMPORT +#endif +#include <platforms/windows/axutil_getopt_windows.h> + +int optind = 1; +int opterr = 1; +int optopt; +char *optarg; + +#define AXIS2_OPT_ERR_NO_ARG 1 +#define AXIS2_OPT_ERR_INVALID_OPTION 2 +#define AXIS2_OPT_ERR_BAD_ARG 3 + +int +_axis2_opt_error( + int __optopt, + int __err, + int __showerr) +{ + switch(__err) + { + case AXIS2_OPT_ERR_NO_ARG: + if(__showerr) + fprintf(stderr, " option requires an argument -- %c\n", __optopt); + break; + case AXIS2_OPT_ERR_INVALID_OPTION: + if(__showerr) + fprintf(stderr, " illegal option -- %c\n", __optopt); + break; + case AXIS2_OPT_ERR_BAD_ARG: + return (int)':'; + default: + if(__showerr) + fprintf(stderr, "unknown\n"); + } + return (int)'?'; +} + +AXIS2_EXTERN int AXIS2_CALL +axis2_getopt( + int __argc, + char * const *__argv, + const char *__shortopts) +{ + static char *pos = ""; + char *olstindex = NULL; + + if(!*pos) + { + /* no option or invalid option */ + if(optind >= __argc || *(pos = __argv[optind]) != '-') + { + pos = ""; + return -1; + } + + /*-- option*/ + if(pos[1] && *++pos == '-') + { + ++optind; + pos = ""; + return -1; + } + } + + if((optopt = (int)*pos++) == (int)':') + { + if(optopt == (int)'-') + return -1; + if(!*pos) + ++optind; + if(*__shortopts != ':') + return _axis2_opt_error(optopt, AXIS2_OPT_ERR_BAD_ARG, opterr); + _axis2_opt_error(optopt, AXIS2_OPT_ERR_INVALID_OPTION, opterr); + } + else + { + olstindex = strchr(__shortopts, optopt); + if(!olstindex) + { + if(optopt == (int)'-') + return -1; + if(!*pos) + ++optind; + if(*__shortopts != ':') + return _axis2_opt_error(optopt, AXIS2_OPT_ERR_BAD_ARG, opterr); + _axis2_opt_error(optopt, AXIS2_OPT_ERR_INVALID_OPTION, opterr); + } + } + + if(!olstindex || *++olstindex != ':') + { + optarg = NULL; + if(!*pos) + ++optind; + } + else + { + if(*pos) + optarg = pos; + else if(__argc <= ++optind) + { + pos = ""; + if(*__shortopts == ':') + return _axis2_opt_error(-1, AXIS2_OPT_ERR_BAD_ARG, opterr); + return _axis2_opt_error(optopt, AXIS2_OPT_ERR_NO_ARG, opterr); + } + else + optarg = __argv[optind]; + pos = ""; + ++optind; + } + return optopt; +} diff --git a/util/src/platforms/windows/thread_mutex_windows.c b/util/src/platforms/windows/thread_mutex_windows.c new file mode 100644 index 0000000..13df497 --- /dev/null +++ b/util/src/platforms/windows/thread_mutex_windows.c @@ -0,0 +1,148 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_thread.h> +#include <platforms/windows/axutil_thread_mutex_windows.h> + +static axis2_status_t +thread_mutex_cleanup( + void *data) +{ + axutil_thread_mutex_t *lock = NULL; + axutil_allocator_t *allocator = NULL; + if(!data) + return AXIS2_FAILURE; + + lock = (axutil_thread_mutex_t *)data; + allocator = lock->allocator; + + if(lock->type == thread_mutex_critical_section) + { + DeleteCriticalSection(&lock->section); + } + else + { + if(!CloseHandle(lock->handle)) + { + return AXIS2_FAILURE; + } + } + + AXIS2_FREE(allocator, lock); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axutil_thread_mutex_t *AXIS2_CALL +axutil_thread_mutex_create( + axutil_allocator_t * allocator, + unsigned int flags) +{ + axutil_thread_mutex_t *mutex = NULL; + + mutex = (axutil_thread_mutex_t *)AXIS2_MALLOC(allocator, sizeof(axutil_thread_mutex_t)); + mutex->allocator = allocator; + + if(flags == AXIS2_THREAD_MUTEX_DEFAULT) /*unnested */ + { + /* Use an auto-reset signaled event, ready to accept one + * waiting thread. + */ + mutex->type = thread_mutex_unnested_event; + mutex->handle = CreateEvent(NULL, FALSE, TRUE, NULL); + } + else + { + /* TODO :support critical_section and nested_mutex */ + } + + return mutex; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_mutex_lock( + axutil_thread_mutex_t * mutex) +{ + if(mutex->type == thread_mutex_critical_section) + { + EnterCriticalSection(&mutex->section); + } + else + { + DWORD rv = WaitForSingleObject(mutex->handle, INFINITE); + if((rv != WAIT_OBJECT_0) && (rv != WAIT_ABANDONED)) + { + return AXIS2_FAILURE; + /*can be either BUSY or an os specific error */ + } + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_mutex_trylock( + axutil_thread_mutex_t * mutex) +{ + + if(mutex->type == thread_mutex_critical_section) + { + /* TODO :implement trylock for critical section */ + } + else + { + DWORD rv = WaitForSingleObject(mutex->handle, 0); + if((rv != WAIT_OBJECT_0) && (rv != WAIT_ABANDONED)) + { + /*can be either BUSY or an os specific error */ + return AXIS2_FAILURE; + } + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_mutex_unlock( + axutil_thread_mutex_t * mutex) +{ + if(mutex->type == thread_mutex_critical_section) + { + LeaveCriticalSection(&mutex->section); + } + else if(mutex->type == thread_mutex_unnested_event) + { + if(!SetEvent(mutex->handle)) + { + /*os specific error */ + return AXIS2_FAILURE; + } + } + else if(mutex->type == thread_mutex_nested_mutex) + { + if(!ReleaseMutex(mutex->handle)) + { + /*os specific error */ + return AXIS2_FAILURE; + } + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_mutex_destroy( + axutil_thread_mutex_t * mutex) +{ + return thread_mutex_cleanup((void *)mutex); +} diff --git a/util/src/platforms/windows/thread_windows.c b/util/src/platforms/windows/thread_windows.c new file mode 100644 index 0000000..67af332 --- /dev/null +++ b/util/src/platforms/windows/thread_windows.c @@ -0,0 +1,326 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_utils.h> +#include <platforms/windows/axutil_thread_windows.h> + +DWORD tls_axutil_thread = 0; + +AXIS2_EXTERN axutil_threadattr_t *AXIS2_CALL +axutil_threadattr_create( + axutil_allocator_t * allocator) +{ + axutil_threadattr_t *new = NULL; + + new = AXIS2_MALLOC(allocator, sizeof(axutil_threadattr_t)); + if(!new) + { + /*AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE) */ + return NULL; + } + new->detach = 0; + new->stacksize = 0; + + return new; +} + +/* Destroy the threadattr object */ +AXIS2_EXTERN axis2_status_t AXIS2_CALL +threadattr_cleanup( + void *data) +{ + /*axutil_threadattr_t *attr = data;*/ + /*nothing to clean up */ + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_threadattr_detach_set( + axutil_threadattr_t * attr, + axis2_bool_t detached) +{ + attr->detach = detached; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_threadattr_detach_get( + axutil_threadattr_t * attr, + const axutil_env_t * env) +{ + if(1 == attr->detach) + { + return AXIS2_TRUE; + } + return AXIS2_FALSE; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_threadattr_stacksize_set( + axutil_threadattr_t * attr, + size_t stacksize) +{ + attr->stacksize = stacksize; + return AXIS2_SUCCESS; +} + +static void * +dummy_worker( + void *opaque) +{ + axutil_thread_t *thd = (axutil_thread_t *)opaque; + TlsSetValue(tls_axutil_thread, thd->td); + return thd->func(thd, thd->data); +} + +AXIS2_EXTERN axutil_thread_t *AXIS2_CALL +axutil_thread_create( + axutil_allocator_t * allocator, + axutil_threadattr_t * attr, + axutil_thread_start_t func, + void *data) +{ + HANDLE handle; + unsigned long temp; + axutil_thread_t *new = NULL; + + new = (axutil_thread_t *)AXIS2_MALLOC(allocator, sizeof(axutil_thread_t)); + + if(!new) + { + return NULL; + } + + new->data = data; + new->func = func; + new->td = NULL; + new->try_exit = AXIS2_FALSE; + + /* Use 0 for Thread Stack Size, because that will default the stack to the + * same size as the calling thread. + */ + if((handle = + CreateThread(NULL, attr && + attr->stacksize > 0 ? attr->stacksize : 0, + (unsigned long (AXIS2_THREAD_FUNC *) (void *)) + dummy_worker, new, 0, &temp)) == 0) + { + return NULL; + } + + if(attr && attr->detach) + { + CloseHandle(handle); + } + else + new->td = handle; + + return new; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_exit( + axutil_thread_t * thd, + axutil_allocator_t * allocator) +{ + axis2_status_t status = AXIS2_SUCCESS; + + if(thd) + { + if(thd->td && (axis2_os_thread_current() != thd->td)) + { + TerminateThread(thd->td, 0); + axutil_thread_join(thd); + AXIS2_FREE(allocator, thd); + return status; + } + AXIS2_FREE(allocator, thd); + } + if(status) + { + ExitThread(0); + } + + return status; +} + +AXIS2_EXTERN axis2_os_thread_t AXIS2_CALL +axis2_os_thread_current( + void) +{ + HANDLE hthread = (HANDLE)TlsGetValue(tls_axutil_thread); + HANDLE hproc; + + if(hthread) + { + return hthread; + } + + hproc = GetCurrentProcess(); + hthread = GetCurrentThread(); + if(!DuplicateHandle(hproc, hthread, hproc, &hthread, 0, FALSE, DUPLICATE_SAME_ACCESS)) + { + return NULL; + } + TlsSetValue(tls_axutil_thread, hthread); + return hthread; +} + +AXIS2_EXTERN int AXIS2_CALL +axis2_os_thread_equal( + axis2_os_thread_t tid1, + axis2_os_thread_t tid2) +{ + return (tid1 == tid2); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_join( + axutil_thread_t * thd) +{ + axis2_status_t rv = AXIS2_SUCCESS, rv1; + + if(!thd->td) + { + /* Can not join on detached threads */ + return AXIS2_FAILURE; + } + rv1 = WaitForSingleObject(thd->td, INFINITE); + if(rv1 == WAIT_OBJECT_0 || rv1 == WAIT_ABANDONED) + { + /*rv = AXIS2_INCOMPLETE; */ + } + else + rv = AXIS2_FAILURE; + CloseHandle(thd->td); + thd->td = NULL; + + return rv; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_detach( + axutil_thread_t * thd) +{ + if(thd->td && CloseHandle(thd->td)) + { + thd->td = NULL; + return AXIS2_SUCCESS; + } + else + { + return AXIS2_FAILURE; + } +} + +AXIS2_EXTERN axis2_os_thread_t AXIS2_CALL +axis2_os_thread_get( + axutil_thread_t * thd, + const axutil_env_t * env) +{ + return thd->td; +} + +/** + * function is used to allocate a new key. This key now becomes valid for all threads in our process. + * When a key is created, the value it points to defaults to NULL. Later on each thread may change + * its copy of the value as it wishes. + */ +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_key_create( + axutil_threadkey_t * axis2_key) +{ + DWORD tls_key = axis2_key->key; + if ((tls_key = TlsAlloc()) == TLS_OUT_OF_INDEXES) + { + return AXIS2_FAILURE; + } + else + { + return AXIS2_SUCCESS; + } +} + +/** + * This function is used to get the value of a given key + * @return void*. A key's value is simply a void pointer (void*) + */ +AXIS2_EXTERN void *AXIS2_CALL +axutil_thread_getspecific( + axutil_threadkey_t * axis2_key) +{ + void *value = NULL; + DWORD tls_key = axis2_key->key; + value = TlsGetValue(tls_key); + return value; +} + +/** + * This function is used to get the value of a given key + * @param keys value. A key's value is simply a void pointer (void*), so we can + * store in it anything that we want + */ +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_setspecific( + axutil_threadkey_t * axis2_key, + void *value) +{ + DWORD tls_key = axis2_key->key; + if(!TlsSetValue(tls_key, value)) + { + return AXIS2_FAILURE; + } + else + { + return AXIS2_SUCCESS; + } +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_thread_key_free( + axutil_threadkey_t * axis2_key) +{ + DWORD tls_key = axis2_key->key; + TlsFree(tls_key); +} + +AXIS2_EXTERN axutil_thread_once_t *AXIS2_CALL +axutil_thread_once_init( + axutil_allocator_t * allocator) +{ + axutil_thread_once_t *control = NULL; + control = AXIS2_MALLOC(allocator, sizeof(*control)); + if(control) + { + control->value = 0; + } + return control; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_once( + axutil_thread_once_t * control, + void + (*func)( + void)) +{ + if(!InterlockedExchange(&control->value, 1)) + { + func(); + } + return AXIS2_SUCCESS; +} diff --git a/util/src/platforms/windows/uuid_gen_windows.c b/util/src/platforms/windows/uuid_gen_windows.c new file mode 100644 index 0000000..c075746 --- /dev/null +++ b/util/src/platforms/windows/uuid_gen_windows.c @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <platforms/windows/axutil_uuid_gen_windows.h> +#include <rpc.h> +#include <stdio.h> +#include <string.h> +#include <axutil_utils_defines.h> + +AXIS2_EXTERN axis2_char_t * AXIS2_CALL +axutil_platform_uuid_gen( + char *s) +{ + RPC_STATUS retval; + UUID uuid; + unsigned char *str; + axis2_char_t * retstr; + + if(!s) + { + return NULL; + } + + retstr = s; + retval = UuidCreate(&uuid); + if(retval == RPC_S_UUID_LOCAL_ONLY) + { + printf("warning - unique within computer \n"); + } + else if(retval == RPC_S_UUID_NO_ADDRESS) + { + return NULL; + } + + retval = UuidToStringA(&uuid, &str); + + if(retval == RPC_S_OK) + { + strcpy(retstr, (char *)str); + RpcStringFree(&str); + } + else if(retval == RPC_S_OUT_OF_MEMORY) + { + return NULL; + } + return retstr; +} diff --git a/util/src/properties.c b/util/src/properties.c new file mode 100644 index 0000000..265765e --- /dev/null +++ b/util/src/properties.c @@ -0,0 +1,363 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_properties.h> +#include <axutil_string.h> +#include <axutil_utils.h> + +#define MAX_SIZE 1024 +#define MAX_ALLOC (MAX_SIZE * 64) + +axis2_char_t * +axutil_properties_read( + FILE *input, + const axutil_env_t *env); + +axis2_char_t * +axutil_properties_read_next( + axis2_char_t *cur); + +axis2_char_t * +axutil_properties_trunk_and_dup( + axis2_char_t *start, + axis2_char_t *end, + const axutil_env_t *env); + +struct axutil_properties +{ + axutil_hash_t *prop_hash; +}; + +AXIS2_EXTERN axutil_properties_t *AXIS2_CALL +axutil_properties_create( + const axutil_env_t *env) +{ + axutil_properties_t *properties = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + properties = (axutil_properties_t *)AXIS2_MALLOC(env->allocator, sizeof(axutil_properties_t)); + + if(!properties) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Not enough memory"); + return NULL; + } + properties->prop_hash = axutil_hash_make(env); + + return properties; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_properties_free( + axutil_properties_t *properties, + const axutil_env_t *env) +{ + axis2_char_t *key = NULL; + axis2_char_t *value = NULL; + axutil_hash_index_t *hi = NULL; + + if(properties->prop_hash) + { + for(hi = axutil_hash_first(properties->prop_hash, env); hi; hi = axutil_hash_next(env, hi)) + { + axutil_hash_this(hi, (void *)&key, NULL, (void *)&value); + if(key) + { + AXIS2_FREE(env->allocator, key); + } + if(value) + { + AXIS2_FREE(env->allocator, value); + } + } + axutil_hash_free(properties->prop_hash, env); + } + + if(properties) + { + AXIS2_FREE(env->allocator, properties); + } + return; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_properties_get_property( + axutil_properties_t *properties, + const axutil_env_t *env, + axis2_char_t *key) +{ + AXIS2_PARAM_CHECK(env->error, key, NULL); + + return axutil_hash_get(properties->prop_hash, key, AXIS2_HASH_KEY_STRING); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_properties_set_property( + axutil_properties_t *properties, + const axutil_env_t *env, + axis2_char_t *key, + axis2_char_t *value) +{ + axis2_char_t *old = NULL; + AXIS2_PARAM_CHECK(env->error, key, AXIS2_FAILURE); + + old = axutil_properties_get_property(properties, env, key); + if(old) + { + AXIS2_FREE(env->allocator, old); + axutil_hash_set(properties->prop_hash, key, AXIS2_HASH_KEY_STRING, + axutil_strdup(env, value)); + return AXIS2_SUCCESS; + } + axutil_hash_set(properties->prop_hash, axutil_strdup(env, key), AXIS2_HASH_KEY_STRING, + axutil_strdup(env, value)); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axutil_hash_t *AXIS2_CALL +axutil_properties_get_all( + axutil_properties_t *properties, + const axutil_env_t *env) +{ + return properties->prop_hash; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_properties_store( + axutil_properties_t *properties, + const axutil_env_t *env, + FILE *output) +{ + axutil_hash_index_t *hi = NULL; + axis2_char_t *key = NULL; + axis2_char_t *value = NULL; + + AXIS2_PARAM_CHECK(env->error, output, AXIS2_FAILURE); + + if(properties->prop_hash) + { + for(hi = axutil_hash_first(properties->prop_hash, env); hi; hi = axutil_hash_next(env, hi)) + { + axutil_hash_this(hi, (void *)&key, NULL, (void *)&value); + if(key) + { + if(!value) + { + value = axutil_strdup(env, ""); + } + fprintf(output, "%s=%s\n", key, value); + } + } + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_properties_load( + axutil_properties_t *properties, + const axutil_env_t *env, + axis2_char_t *input_filename) +{ + FILE *input = 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; + int status = LINE_STARTED; + + axis2_char_t *key = NULL; + axutil_hash_t *prop_hash = NULL; + axis2_char_t *buffer = NULL; + axis2_char_t loginfo[1024]; + + AXIS2_PARAM_CHECK(env->error, input_filename, AXIS2_FAILURE); + + prop_hash = properties->prop_hash; + + input = fopen(input_filename, "r+"); + if(!input) + { + return AXIS2_FAILURE; + } + buffer = axutil_properties_read(input, env); + + if(!buffer) + { + sprintf(loginfo, "error in reading file\n"); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, loginfo); + AXIS2_FREE(env->allocator, buffer); + return AXIS2_FAILURE; + } + + for(cur = axutil_properties_read_next(buffer); *cur; cur = axutil_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 = axutil_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 = axutil_properties_trunk_and_dup(tag, cur, env); + axutil_hash_set(prop_hash, key, AXIS2_HASH_KEY_STRING, tag); + } + status = LINE_STARTED; + } + } + if(status == LINE_HALFWAY) + { + *cur = '\0'; + tag = axutil_properties_trunk_and_dup(tag, cur, env); + axutil_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; + } + if(input) + { + fclose(input); + } + AXIS2_FREE(env->allocator, buffer); + return AXIS2_SUCCESS; +} + +axis2_char_t * +axutil_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 * +axutil_properties_trunk_and_dup( + axis2_char_t *start, + axis2_char_t *end, + const axutil_env_t *env) +{ + for(; *start == ' '; start++) + ; /* remove front spaces */ + for(end--; *end == ' '; end--) + ; /* remove rear spaces */ + *(++end) = '\0'; + start = (axis2_char_t *)axutil_strdup(env, start); + return start; +} + +axis2_char_t * +axutil_properties_read( + FILE *input, + const axutil_env_t *env) +{ + size_t nread = 0; + axis2_char_t *out_stream = NULL; + size_t ncount = 0; + size_t curr_alloc = MAX_SIZE * 2; + size_t total_alloc = curr_alloc; + + out_stream = (axis2_char_t *)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * curr_alloc); + if(!out_stream) + { + return NULL; + } + + do + { + nread = fread(out_stream + ncount, sizeof(axis2_char_t), MAX_SIZE, input); + ncount += nread; + + if(ncount + MAX_SIZE > total_alloc) + { + axis2_char_t *new_stream = NULL; + if(curr_alloc < MAX_ALLOC) + { + curr_alloc *= 2; + } + + total_alloc += curr_alloc; + new_stream = AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * total_alloc); + if(!new_stream) + { + if(out_stream) + { + AXIS2_FREE(env->allocator, out_stream); + } + return NULL; + } + + memcpy(new_stream, out_stream, sizeof(axis2_char_t) * ncount); + if(out_stream) + { + AXIS2_FREE(env->allocator, out_stream); + } + out_stream = new_stream; + } + } + while(nread == MAX_SIZE); + + out_stream[ncount] = '\0'; + return out_stream; +} diff --git a/util/src/property.c b/util/src/property.c new file mode 100644 index 0000000..55826d1 --- /dev/null +++ b/util/src/property.c @@ -0,0 +1,193 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_property.h> +#include <stdio.h> + +struct axutil_property +{ + axis2_scope_t scope; + AXIS2_FREE_VOID_ARG free_func; + void *value; + axis2_bool_t own_value; +}; + +axutil_property_t *AXIS2_CALL +axutil_property_create( + const axutil_env_t * env) +{ + axutil_property_t *property = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + property = (axutil_property_t *)AXIS2_MALLOC(env->allocator, sizeof(axutil_property_t)); + + if(!property) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + property->value = NULL; + property->scope = AXIS2_SCOPE_REQUEST; + property->free_func = 0; + property->own_value = AXIS2_TRUE; + + return property; +} + +/*****************************************************************************/ +axutil_property_t *AXIS2_CALL +axutil_property_create_with_args( + const axutil_env_t * env, + axis2_scope_t scope, + axis2_bool_t own_value, + AXIS2_FREE_VOID_ARG free_func, + void *value) +{ + axutil_property_t *property = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + property = (axutil_property_t *)axutil_property_create(env); + + if(!property) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + property->value = value; + property->scope = scope; + property->own_value = own_value; + property->free_func = free_func; + + return property; +} + +void AXIS2_CALL +axutil_property_free( + axutil_property_t * property, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(property->value) + { + if(property->scope != AXIS2_SCOPE_APPLICATION) + { + if(property->free_func && property->own_value) + { + property->free_func(property->value, env); + } + else if(property->own_value) + { + AXIS2_FREE(env->allocator, property->value); + } + } + } + + if(property) + { + AXIS2_FREE(env->allocator, property); + } + return; +} + +axis2_status_t AXIS2_CALL +axutil_property_set_scope( + axutil_property_t * property, + const axutil_env_t * env, + axis2_scope_t scope) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + property->scope = scope; + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axutil_property_set_free_func( + axutil_property_t * property, + const axutil_env_t * env, + AXIS2_FREE_VOID_ARG free_func) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + property->free_func = free_func; + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axutil_property_set_value( + axutil_property_t * property, + const axutil_env_t * env, + void *value) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(property->value) + { + if(property->scope != AXIS2_SCOPE_APPLICATION) + { + if(property->free_func && property->own_value) + { + property->free_func(property->value, env); + } + else if(property->own_value) + { + AXIS2_FREE(env->allocator, property->value); + } + } + } + + property->value = value; + return AXIS2_SUCCESS; +} + +void *AXIS2_CALL +axutil_property_get_value( + axutil_property_t * property, + const axutil_env_t * env) +{ + return property->value; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_property_set_own_value( + axutil_property_t * property, + const axutil_env_t * env, + axis2_bool_t own_value) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + property->own_value = own_value; + return AXIS2_SUCCESS; +} + +axutil_property_t *AXIS2_CALL +axutil_property_clone( + axutil_property_t * property, + const axutil_env_t * env) +{ + axutil_property_t *new_property = NULL; + AXIS2_ENV_CHECK(env, NULL); + new_property = axutil_property_create(env); + axutil_property_set_free_func(new_property, env, property->free_func); + axutil_property_set_scope(new_property, env, property->scope); + axutil_property_set_own_value(new_property, env, property->own_value); + axutil_property_set_value(new_property, env, property->value); + return new_property; +} diff --git a/util/src/qname.c b/util/src/qname.c new file mode 100644 index 0000000..e4197c3 --- /dev/null +++ b/util/src/qname.c @@ -0,0 +1,337 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_qname.h> +#include <axutil_env.h> +#include <axutil_utils.h> +#include <axutil_utils_defines.h> +#include <string.h> +#include <stdio.h> + +struct axutil_qname +{ + + /** localpart of qname is mandatory */ + axis2_char_t *localpart; + + /** namespace uri is optional */ + axis2_char_t *namespace_uri; + + /** prefix mandatory */ + axis2_char_t *prefix; + + /** qname represented as a string, used as keys in hash tables, etc. */ + axis2_char_t *qname_string; + unsigned int ref; +}; + +AXIS2_EXTERN axutil_qname_t *AXIS2_CALL +axutil_qname_create( + const axutil_env_t *env, + const axis2_char_t *localpart, + const axis2_char_t *namespace_uri, + const axis2_char_t *prefix) +{ + + axutil_qname_t *qname = NULL; + AXIS2_ENV_CHECK(env, NULL); + + /* localpart can't be null */ + if(!localpart) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "NULL parameter was passed when a non NULL parameter was expected"); + return NULL; + } + + qname = (axutil_qname_t *)AXIS2_MALLOC(env->allocator, sizeof(axutil_qname_t)); + if(!qname) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + /* set properties */ + qname->localpart = NULL; + qname->qname_string = NULL; + qname->prefix = NULL; + qname->namespace_uri = NULL; + qname->ref = 1; + + qname->localpart = (axis2_char_t *)axutil_strdup(env, localpart); + if(!(qname->localpart)) + { + AXIS2_ERROR_SET_ERROR_NUMBER(env->error, AXIS2_ERROR_NO_MEMORY); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + AXIS2_ERROR_SET_STATUS_CODE(env->error, AXIS2_FAILURE); + axutil_qname_free(qname, env); + return NULL; + } + + if(prefix) + { + qname->prefix = (axis2_char_t *)axutil_strdup(env, prefix); + } + + if(prefix && !(qname->prefix)) + { + AXIS2_ERROR_SET_ERROR_NUMBER(env->error, AXIS2_ERROR_NO_MEMORY); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + AXIS2_ERROR_SET_STATUS_CODE(env->error, AXIS2_FAILURE); + axutil_qname_free(qname, env); + return NULL; + } + + if(namespace_uri) + { + qname->namespace_uri = (axis2_char_t *)axutil_strdup(env, namespace_uri); + } + + if(namespace_uri && !(qname->namespace_uri)) + { + AXIS2_ERROR_SET_ERROR_NUMBER(env->error, AXIS2_ERROR_NO_MEMORY); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + AXIS2_ERROR_SET_STATUS_CODE(env->error, AXIS2_FAILURE); + axutil_qname_free(qname, env); + return NULL; + } + + return qname; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_qname_free( + axutil_qname_t *qname, + const axutil_env_t *env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + qname->ref--; + + if(qname->ref > 0) + { + return; + } + + if(qname->localpart) + { + AXIS2_FREE(env->allocator, qname->localpart); + } + if(qname->namespace_uri) + { + AXIS2_FREE(env->allocator, qname->namespace_uri); + } + if(qname->prefix) + { + AXIS2_FREE(env->allocator, qname->prefix); + } + if(qname->qname_string) + { + AXIS2_FREE(env->allocator, qname->qname_string); + } + + AXIS2_FREE(env->allocator, qname); + + return; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axutil_qname_equals( + const axutil_qname_t *qname, + const axutil_env_t *env, + const axutil_qname_t *qname2) +{ + int uris_differ = 0; + int localparts_differ = 0; + + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + if(!qname2) + { + AXIS2_ERROR_SET_ERROR_NUMBER(env->error, AXIS2_ERROR_INVALID_NULL_PARAM); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "NULL parameter was passed when a non NULL parameter was expected"); + AXIS2_ERROR_SET_STATUS_CODE(env->error, AXIS2_FAILURE); + return AXIS2_FALSE; + } + + if(qname->localpart && qname2->localpart) + { + localparts_differ = axutil_strcmp(qname->localpart, qname2->localpart); + } + else + { + localparts_differ = ((qname->localpart) || (qname2->localpart)); + } + + if(qname->namespace_uri && qname2->namespace_uri) + { + uris_differ = axutil_strcmp(qname->namespace_uri, qname2->namespace_uri); + } + else + { + uris_differ = ((qname->namespace_uri) || (qname2->namespace_uri)); + } + + return (!uris_differ && !localparts_differ) ? AXIS2_TRUE : AXIS2_FALSE; +} + +AXIS2_EXTERN axutil_qname_t *AXIS2_CALL +axutil_qname_clone( + axutil_qname_t *qname, + const axutil_env_t *env) +{ + AXIS2_ENV_CHECK(env, NULL); + + if(!qname) + { + return NULL; + } + qname->ref++; + + return qname; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_qname_get_uri( + const axutil_qname_t *qname, + const axutil_env_t *env) +{ + AXIS2_PARAM_CHECK(env->error, qname, NULL); + return qname->namespace_uri; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_qname_get_prefix( + const axutil_qname_t *qname, + const axutil_env_t *env) +{ + AXIS2_PARAM_CHECK(env->error, qname, NULL); + return qname->prefix; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_qname_get_localpart( + const axutil_qname_t *qname, + const axutil_env_t *env) +{ + AXIS2_PARAM_CHECK(env->error, qname, NULL); + return qname->localpart; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_qname_to_string( + axutil_qname_t *qname, + const axutil_env_t *env) +{ + AXIS2_ENV_CHECK(env, NULL); + if(qname->qname_string) + { + return qname->qname_string; + } + + if(!(qname->namespace_uri) || axutil_strcmp(qname->namespace_uri, "") == 0) + { + qname->qname_string = axutil_strdup(env, qname->localpart); + } + else if(!(qname->prefix) || axutil_strcmp(qname->prefix, "") == 0) + { + axis2_char_t *temp_string1 = NULL; + temp_string1 = axutil_stracat(env, qname->localpart, "|"); + qname->qname_string = axutil_stracat(env, temp_string1, qname->namespace_uri); + if(temp_string1) + { + AXIS2_FREE(env->allocator, temp_string1); + } + } + else + { + axis2_char_t *temp_string1 = NULL; + axis2_char_t *temp_string2 = NULL; + axis2_char_t *temp_string3 = NULL; + + temp_string1 = axutil_stracat(env, qname->localpart, "|"); + temp_string2 = axutil_stracat(env, temp_string1, qname->namespace_uri); + temp_string3 = axutil_stracat(env, temp_string2, "|"); + qname->qname_string = axutil_stracat(env, temp_string3, qname->prefix); + + if(temp_string1) + { + AXIS2_FREE(env->allocator, temp_string1); + } + if(temp_string2) + { + AXIS2_FREE(env->allocator, temp_string2); + } + if(temp_string3) + { + AXIS2_FREE(env->allocator, temp_string3); + } + } + return qname->qname_string; +} + +AXIS2_EXTERN axutil_qname_t *AXIS2_CALL +axutil_qname_create_from_string( + const axutil_env_t *env, + const axis2_char_t *qstring) +{ + axis2_char_t *localpart = NULL; + axis2_char_t *namespace_uri = NULL; + axis2_char_t *prefix = NULL; + axis2_char_t *index = NULL; + axis2_char_t *next = NULL; + axis2_char_t *temp_string = NULL; + axutil_qname_t *qname = NULL; + if(!qstring || axutil_strcmp(qstring, "") == 0) + return NULL; + + temp_string = axutil_strdup(env, qstring); + + index = strchr(temp_string, '|'); + if(index) + { + next = index + 1; + temp_string[index - temp_string] = '\0'; + localpart = temp_string; + + index = strchr(next, '|'); + if(index) + { + prefix = index + 1; + next[index - next] = '\0'; + namespace_uri = next; + qname = axutil_qname_create(env, localpart, namespace_uri, prefix); + } + else + { + /** only uri and localpart is available */ + qname = axutil_qname_create(env, localpart, next, NULL); + } + } + else + { + /** only localpart is there in this qname */ + qname = axutil_qname_create(env, temp_string, NULL, NULL); + } + if(temp_string) + { + AXIS2_FREE(env->allocator, temp_string); + } + return qname; +} diff --git a/util/src/rand.c b/util/src/rand.c new file mode 100644 index 0000000..c3a7aa9 --- /dev/null +++ b/util/src/rand.c @@ -0,0 +1,66 @@ +/* + * 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 <stdlib.h> +#include <axutil_rand.h> +#include <axutil_string.h> +#include <platforms/axutil_platform_auto_sense.h> + +#define AXIS2_RAND_MAX 32768 + +AXIS2_EXTERN int AXIS2_CALL +axutil_rand( + unsigned int *seedp) +{ + *seedp = *seedp * 1103515245 + 12345; + return ((unsigned)(*seedp / (2 * AXIS2_RAND_MAX)) % AXIS2_RAND_MAX); +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_rand_with_range( + unsigned int *seedp, + int start, + int end) +{ + int rand = -1; + float range = 0.0; + if(start < 0 || end <= 0) + return -1; + if(start >= AXIS2_RAND_MAX || end > AXIS2_RAND_MAX) + return -1; + if(end <= start) + return -1; + + range = (float)(end - start); + rand = axutil_rand(seedp); + rand = start + (int)(range * rand / (AXIS2_RAND_MAX + 1.0)); + return rand; +} + +AXIS2_EXTERN unsigned int AXIS2_CALL +axutil_rand_get_seed_value_based_on_time( + const axutil_env_t * env) +{ + axutil_date_time_t *date = axutil_date_time_create(env); + unsigned int rand_var = axutil_date_time_get_year(date, env); + rand_var += axutil_date_time_get_month(date, env); + rand_var += axutil_date_time_get_date(date, env); + rand_var += axutil_date_time_get_hour(date, env); + rand_var += axutil_date_time_get_minute(date, env); + rand_var += axutil_date_time_get_second(date, env); + axutil_date_time_free(date, env); + return rand_var; +} diff --git a/util/src/stack.c b/util/src/stack.c new file mode 100644 index 0000000..5d45a93 --- /dev/null +++ b/util/src/stack.c @@ -0,0 +1,182 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_stack.h> +#include <axutil_utils.h> +#include <axutil_env.h> +#include <stdlib.h> +#include <string.h> + +#define AXIS2_STACK_DEFAULT_CAPACITY 10 + +struct axutil_stack +{ + void **data; + + /** current number of elements */ + int size; + + /** total capacity */ + int capacity; + axis2_bool_t is_empty_stack; +}; + +AXIS2_EXTERN axutil_stack_t *AXIS2_CALL +axutil_stack_create( + const axutil_env_t *env) +{ + axutil_stack_t *stack = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + stack = (axutil_stack_t *)AXIS2_MALLOC(env->allocator, sizeof(axutil_stack_t)); + + if(!stack) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + + stack->data = NULL; + stack->size = 0; + stack->capacity = AXIS2_STACK_DEFAULT_CAPACITY; + stack->is_empty_stack = AXIS2_TRUE; + + stack->data = AXIS2_MALLOC(env->allocator, sizeof(void *) * AXIS2_STACK_DEFAULT_CAPACITY); + if(!stack->data) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + axutil_stack_free(stack, env); + return NULL; + } + + return stack; +} + +void AXIS2_CALL +axutil_stack_free( + axutil_stack_t *stack, + const axutil_env_t *env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(stack->data) + { + AXIS2_FREE(env->allocator, stack->data); + } + AXIS2_FREE(env->allocator, stack); + return; +} + +void *AXIS2_CALL +axutil_stack_pop( + axutil_stack_t *stack, + const axutil_env_t *env) +{ + void *value = NULL; + AXIS2_ENV_CHECK(env, NULL); + + if(stack->is_empty_stack == AXIS2_TRUE || stack->size == 0) + { + return NULL; + } + if(stack->size > 0) + { + value = stack->data[stack->size - 1]; + stack->data[stack->size - 1] = NULL; + stack->size--; + if(stack->size == 0) + { + stack->is_empty_stack = AXIS2_TRUE; + } + } + return value; +} + +axis2_status_t AXIS2_CALL +axutil_stack_push( + axutil_stack_t *stack, + const axutil_env_t *env, + void *value) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, value, AXIS2_FAILURE); + + if((stack->size < stack->capacity) && (stack->capacity > 0)) + { + stack->data[stack->size++] = value; + } + else + { + void **new_data = NULL; + + int new_capacity = stack->capacity + AXIS2_STACK_DEFAULT_CAPACITY; + + new_data = AXIS2_MALLOC(env->allocator, sizeof(void *) * new_capacity); + if(!new_data) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return AXIS2_FAILURE; + } + memset(new_data, 0, sizeof(void *) * new_capacity); + memcpy(new_data, stack->data, sizeof(void *) * (stack->capacity)); + stack->capacity = new_capacity; + + AXIS2_FREE(env->allocator, stack->data); + stack->data = new_data; + + stack->data[stack->size++] = value; + } + stack->is_empty_stack = AXIS2_FALSE; + return AXIS2_SUCCESS; +} + +int AXIS2_CALL +axutil_stack_size( + axutil_stack_t *stack, + const axutil_env_t *env) +{ + return stack->size; +} + +void *AXIS2_CALL +axutil_stack_get( + axutil_stack_t *stack, + const axutil_env_t *env) +{ + if(stack->size > 0) + { + return stack->data[stack->size - 1]; + } + return NULL; +} + +void *AXIS2_CALL +axutil_stack_get_at( + axutil_stack_t *stack, + const axutil_env_t *env, + int i) +{ + if((stack->size == 0) || (i < 0) || (i >= stack->size)) + { + return NULL; + } + return stack->data[i]; +} diff --git a/util/src/stream.c b/util/src/stream.c new file mode 100644 index 0000000..1034a03 --- /dev/null +++ b/util/src/stream.c @@ -0,0 +1,719 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <string.h> +#include <stdlib.h> +#include <axutil_stream.h> +#include <platforms/axutil_platform_auto_sense.h> + +/** basic stream operatons **/ +int AXIS2_CALL axutil_stream_write_basic( + axutil_stream_t *stream, + const axutil_env_t *env, + const void *buffer, + size_t count); + +int AXIS2_CALL axutil_stream_read_basic( + axutil_stream_t *stream, + const axutil_env_t *env, + void *buffer, + size_t count); + +int AXIS2_CALL axutil_stream_skip_basic( + axutil_stream_t *stream, + const axutil_env_t *env, + int count); + +/** file stream operations **/ +int AXIS2_CALL axutil_stream_write_file( + axutil_stream_t *stream, + const axutil_env_t *env, + const void *buffer, + size_t count); + +int AXIS2_CALL axutil_stream_read_file( + axutil_stream_t *stream, + const axutil_env_t *env, + void *buffer, + size_t count); + +int AXIS2_CALL axutil_stream_skip_file( + axutil_stream_t *stream, + const axutil_env_t *env, + int count); + +/** socket stream operations **/ +int AXIS2_CALL axutil_stream_write_socket( + axutil_stream_t *stream, + const axutil_env_t *env, + const void *buffer, + size_t count); + +int AXIS2_CALL axutil_stream_read_socket( + axutil_stream_t *stream, + const axutil_env_t *env, + void *buffer, + size_t count); + +int AXIS2_CALL axutil_stream_skip_socket( + axutil_stream_t *stream, + const axutil_env_t *env, + int count); + +AXIS2_EXTERN axutil_stream_t *AXIS2_CALL +axutil_stream_create_internal( + const axutil_env_t *env) +{ + axutil_stream_t *stream = NULL; + stream = (axutil_stream_t *)AXIS2_MALLOC(env->allocator, sizeof(axutil_stream_t)); + if(!stream) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory. Cannot create axutil stream"); + return NULL; + } + stream->buffer = NULL; + stream->buffer_head = NULL; + stream->fp = NULL; + stream->socket = -1; + stream->len = -1; + stream->max_len = -1; + stream->axis2_eof = EOF; + + return stream; +} + +void AXIS2_CALL +axutil_stream_free( + axutil_stream_t *stream, + const axutil_env_t *env) +{ + switch(stream->stream_type) + { + case AXIS2_STREAM_BASIC: + { + if(stream->buffer_head) + { + AXIS2_FREE(env->allocator, stream->buffer_head); + } + stream->buffer = NULL; + stream->len = -1; + break; + } + case AXIS2_STREAM_FILE: + { + stream->fp = NULL; + stream->len = -1; + break; + } + case AXIS2_STREAM_SOCKET: + { + if(stream->fp) + { + fclose(stream->fp); + } + stream->socket = -1; + stream->len = -1; + break; + } + default: + break; + } + + AXIS2_FREE(env->allocator, stream); +} + +void AXIS2_CALL +axutil_stream_free_void_arg( + void *stream, + const axutil_env_t *env) +{ + axutil_stream_t *stream_l = NULL; + + stream_l = (axutil_stream_t *)stream; + axutil_stream_free(stream_l, env); + return; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_stream_flush( + axutil_stream_t *stream, + const axutil_env_t *env) +{ + if(stream->fp) + { + if(fflush(stream->fp)) + { + return AXIS2_FAILURE; + } + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_stream_close( + axutil_stream_t *stream, + const axutil_env_t *env) +{ + switch(stream->stream_type) + { + case AXIS2_STREAM_BASIC: + { + if(stream->buffer_head) + { + AXIS2_FREE(env->allocator, stream->buffer_head); + } + stream->buffer = NULL; + stream->len = -1; + break; + } + case AXIS2_STREAM_FILE: + { + if(stream->fp) + { + if(fclose(stream->fp)) + { + return AXIS2_FAILURE; + } + } + stream->fp = NULL; + stream->len = -1; + break; + } + case AXIS2_STREAM_SOCKET: + { + if(stream->fp) + { + if(fclose(stream->fp)) + { + return AXIS2_FAILURE; + } + } + stream->socket = -1; + stream->len = -1; + break; + } + default: + break; + } + + return AXIS2_SUCCESS; +} + +/************************ Basic Stream Operations *****************************/ +AXIS2_EXTERN axutil_stream_t *AXIS2_CALL +axutil_stream_create_basic( + const axutil_env_t *env) +{ + axutil_stream_t *stream = NULL; + + AXIS2_ENV_CHECK(env, NULL); + stream = axutil_stream_create_internal(env); + if(!stream) + { + /* + * We leave the error returned by the + * axutil_stream_create_internal intact + */ + return NULL; + } + stream->stream_type = AXIS2_STREAM_BASIC; + stream->read = axutil_stream_read_basic; + stream->write = axutil_stream_write_basic; + stream->skip = axutil_stream_skip_basic; + stream->buffer = (axis2_char_t *)AXIS2_MALLOC(env->allocator, AXIS2_STREAM_DEFAULT_BUF_SIZE + * sizeof(axis2_char_t)); + stream->buffer_head = stream->buffer; + stream->len = 0; + stream->max_len = AXIS2_STREAM_DEFAULT_BUF_SIZE; + + if(!stream->buffer) + { + axutil_stream_free(stream, env); + return NULL; + } + return stream; +} + +int AXIS2_CALL +axutil_stream_read_basic( + axutil_stream_t *stream, + const axutil_env_t *env, + void *buffer, + size_t count) +{ + int len = 0; + char *buf = NULL; + + buf = stream->buffer; + if(!buf) + { + return -1; + } + if(!buffer) + { + return -1; + } + if((int)(count - 1) > stream->len) + /* We are sure that the difference lies within the int range */ + { + len = stream->len; + } + else + { + len = (int)(count - 1); + /* We are sure that the difference lies within the int range */ + } + memcpy(buffer, buf, len); + /* + * Finally we need to remove the read bytes from the stream + * adjust the length of the stream. + */ + stream->len -= len; + stream->buffer = buf + len; + ((axis2_char_t *)buffer)[len] = '\0'; + return len; +} + +int AXIS2_CALL +axutil_stream_write_basic( + axutil_stream_t *stream, + const axutil_env_t *env, + const void *buffer, + size_t count) +{ + int new_len = 0; + + if(!buffer) + return -1; + + new_len = (int)(stream->len + count); + /* We are sure that the difference lies within the int range */ + if(new_len > stream->max_len) + { + axis2_char_t *tmp = (axis2_char_t *)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) + * (new_len + AXIS2_STREAM_DEFAULT_BUF_SIZE)); + if(!tmp) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return -1; + } + /* + * pre allocation: extra AXIS2_STREAM_DEFAULT_BUF_SIZE more bytes + * allocated + */ + stream->max_len = new_len + AXIS2_STREAM_DEFAULT_BUF_SIZE; + memcpy(tmp, stream->buffer, sizeof(axis2_char_t) * stream->len); + AXIS2_FREE(env->allocator, stream->buffer_head); + stream->buffer = tmp; + stream->buffer_head = tmp; + } + memcpy(stream->buffer + (stream->len * sizeof(axis2_char_t)), buffer, count); + stream->len += (int)count; + /* We are sure that the difference lies within the int range */ + return (int)count; +} + +int AXIS2_CALL +axutil_stream_get_len( + axutil_stream_t *stream, + const axutil_env_t *env) +{ + return stream->len; +} + +int AXIS2_CALL +axutil_stream_skip_basic( + axutil_stream_t *stream, + const axutil_env_t *env, + int count) +{ + int del_len = 0; + + if(count > 0) + { + if(count <= stream->len) + { + del_len = count; + } + else + { + del_len = stream->len; + } + stream->len -= del_len; + stream->buffer += del_len; + return del_len; + } + return -1; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_stream_get_buffer( + const axutil_stream_t *stream, + const axutil_env_t *env) +{ + return stream->buffer; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_stream_flush_buffer( + axutil_stream_t *stream, + const axutil_env_t *env) +{ + stream->len = 0; + return AXIS2_SUCCESS; +} + +/********************* End of Basic Stream Operations *************************/ + +/************************** File Stream Operations ****************************/ +AXIS2_EXTERN axutil_stream_t *AXIS2_CALL +axutil_stream_create_file( + const axutil_env_t *env, + FILE * fp) +{ + axutil_stream_t *stream = NULL; + + AXIS2_ENV_CHECK(env, NULL); + stream = axutil_stream_create_internal(env); + if(!stream) + { + /* + * We leave the error returned by the + * axutil_stream_create_internal intact + */ + return NULL; + } + stream->stream_type = AXIS2_STREAM_FILE; + stream->fp = fp; + + stream->read = axutil_stream_read_file; + stream->write = axutil_stream_write_file; + stream->skip = axutil_stream_skip_file; + + return stream; +} + +int AXIS2_CALL +axutil_stream_read_file( + axutil_stream_t *stream, + const axutil_env_t *env, + void *buffer, + size_t count) +{ + FILE *fp = NULL; + + if(!stream->fp) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_FD, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Trying to do operation on invalid file descriptor"); + + return -1; + } + fp = stream->fp; + if(!buffer) + { + return -1; + } + return (int)fread(buffer, sizeof(axis2_char_t), count, fp); + /* We are sure that the difference lies within the int range */ +} + +int AXIS2_CALL +axutil_stream_write_file( + axutil_stream_t *stream, + const axutil_env_t *env, + const void *buffer, + size_t count) +{ + int len = 0; + FILE *fp = NULL; + + if(!(stream->fp)) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_FD, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Trying to do operation on invalid file descriptor"); + + return -1; + } + fp = stream->fp; + if(!buffer) + return -1; + len = (int)fwrite(buffer, sizeof(axis2_char_t), count, fp); + /* We are sure that the difference lies within the int range */ + return len; +} + +int AXIS2_CALL +axutil_stream_skip_file( + axutil_stream_t *stream, + const axutil_env_t *env, + int count) +{ + int c = -1; + int i = count; + if(!(stream->fp)) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_FD, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Trying to do operation on invalid file descriptor"); + return -1; + } + while(EOF != (c = fgetc(stream->fp)) && i > 0) + { + i--; + } + return count - i; +} + +/********************** End of File Stream Operations *************************/ + +/************************** Socket Stream Operations **************************/ +AXIS2_EXTERN axutil_stream_t *AXIS2_CALL +axutil_stream_create_socket( + const axutil_env_t *env, + int socket) +{ + axutil_stream_t *stream = NULL; + stream = axutil_stream_create_internal(env); + if(!stream) + { + /* + * We leave the error returned by the + * axutil_stream_create_internal intact + */ + return NULL; + } + + stream->read = axutil_stream_read_socket; + stream->write = axutil_stream_write_socket; + stream->skip = axutil_stream_skip_socket; + stream->stream_type = AXIS2_STREAM_SOCKET; + stream->socket = socket; + stream->fp = NULL; + + return stream; +} + +int AXIS2_CALL +axutil_stream_read_socket( + axutil_stream_t *stream, + const axutil_env_t *env, + void *buffer, + size_t count) +{ + int len = 0; + + if(-1 == stream->socket) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_SOCKET, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Trying to do operation on closed/not-opened socket"); + return -1; + } + if(!buffer) + { + return -1; + } + + len = (int)recv(stream->socket, buffer, (int)count, 0); + /* We are sure that the difference lies within the int range */ +#ifdef AXIS2_TCPMON + if (len > 1) + { + axis2_char_t *temp = NULL; + temp = (axis2_char_t *) AXIS2_MALLOC(env->allocator, (len + 1) * sizeof(axis2_char_t)); + if (temp) + { + memcpy(temp, buffer, len * sizeof(axis2_char_t)); + temp[len] = '\0'; + fprintf(stderr, "%s", temp); + AXIS2_FREE(env->allocator, temp); + } + } +#endif + return len; +} + +int AXIS2_CALL +axutil_stream_write_socket( + axutil_stream_t *stream, + const axutil_env_t *env, + const void *buffer, + size_t count) +{ + int len = 0; +#ifdef AXIS2_TCPMON + axis2_char_t *temp = NULL; +#endif + + if(-1 == stream->socket) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_SOCKET, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Trying to do operation on closed/not-opened socket"); + return -1; + } + if(!buffer) + return -1; + len = (int)send(stream->socket, buffer, (int)count, 0); + /* We are sure that the difference lies within the int range */ +#ifdef AXIS2_TCPMON + if (len > 0) + { + temp = + (axis2_char_t *) AXIS2_MALLOC(env->allocator, + (len + 1) * sizeof(axis2_char_t)); + if (temp) + { + memcpy(temp, buffer, len * sizeof(axis2_char_t)); + temp[len] = '\0'; + fprintf(stderr, "%s", temp); + AXIS2_FREE(env->allocator, temp); + } + } +#endif + return len; + +} + +int AXIS2_CALL +axutil_stream_skip_socket( + axutil_stream_t *stream, + const axutil_env_t *env, + int count) +{ + int len = 0; + int received = 0; + char buffer[2]; + + if(-1 == stream->socket) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_SOCKET, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Trying to do operation on closed/not-opened socket"); + return -1; + } + while(len < count) + { + received = recv(stream->socket, buffer, 1, 0); + if(received == 0) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_ERROR, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Socket has being shutdown"); + return -1; + } + if(received < 0) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_ERROR, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error while trying to read the socke"); + return -1; + } + len += received; + } + return len; +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_stream_peek_socket( + axutil_stream_t *stream, + const axutil_env_t *env, + void *buffer, + size_t count) +{ + int len = 0; + + /* Added to prevent a segfault */ + AXIS2_PARAM_CHECK(env->error, stream, -1); + + if(-1 == stream->socket) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_SOCKET, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Trying to do operation on closed/not-opened socket"); + return -1; + } + if(!buffer) + { + return -1; + } + + len = (int)recv(stream->socket, buffer, (int)count, MSG_PEEK); + /* We are sure that the difference lies within the int range */ + + return len; +} + +/********************** End of Socket Stream Operations ***********************/ + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_stream_set_read( + axutil_stream_t *stream, + const axutil_env_t *env, + AXUTIL_STREAM_READ func) +{ + stream->read = func; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_stream_set_write( + axutil_stream_t *stream, + const axutil_env_t *env, + AXUTIL_STREAM_WRITE func) +{ + stream->write = func; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_stream_set_skip( + axutil_stream_t *stream, + const axutil_env_t *env, + AXUTIL_STREAM_SKIP func) +{ + stream->skip = func; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_stream_read( + axutil_stream_t *stream, + const axutil_env_t *env, + void *buffer, + size_t count) +{ + return stream->read(stream, env, buffer, count); +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_stream_write( + axutil_stream_t *stream, + const axutil_env_t *env, + const void *buffer, + size_t count) +{ + return stream->write(stream, env, buffer, count); +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_stream_skip( + axutil_stream_t *stream, + const axutil_env_t *env, + int count) +{ + return stream->skip(stream, env, count); +} diff --git a/util/src/string.c b/util/src/string.c new file mode 100644 index 0000000..4a3f8f0 --- /dev/null +++ b/util/src/string.c @@ -0,0 +1,822 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_string.h> +#include <stdlib.h> +#include <ctype.h> +#include <axutil_utils.h> +#include <axutil_utils_defines.h> +#include <stdarg.h> /* NULL */ + +struct axutil_string +{ + axis2_char_t *buffer; + unsigned int length; + unsigned int ref_count; + axis2_bool_t owns_buffer; +}; + +AXIS2_EXTERN axutil_string_t *AXIS2_CALL +axutil_string_create( + const axutil_env_t *env, + const axis2_char_t *str) +{ + axutil_string_t *string = NULL; + AXIS2_ENV_CHECK(env, NULL); + + /* str can't be null */ + if(!str) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "NULL parameter was passed when a non NULL parameter was expected"); + return NULL; + } + + string = (axutil_string_t *)AXIS2_MALLOC(env->allocator, sizeof(axutil_string_t)); + if(!string) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + /* set properties */ + string->buffer = NULL; + string->ref_count = 1; + string->owns_buffer = AXIS2_TRUE; + + string->length = axutil_strlen(str); + + if(string->length < 0) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "NULL parameter was passed when a non NULL parameter was expected"); + axutil_string_free(string, env); + return NULL; + } + + string->buffer = (axis2_char_t *)AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) + * (string->length + 1)); + if(!(string->buffer)) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + axutil_string_free(string, env); + return NULL; + } + memcpy(string->buffer, str, string->length + 1); + + return string; +} + +AXIS2_EXTERN axutil_string_t *AXIS2_CALL +axutil_string_create_assume_ownership( + const axutil_env_t *env, + axis2_char_t **str) +{ + axutil_string_t *string = NULL; + AXIS2_ENV_CHECK(env, NULL); + + /* str can't be null */ + if(!str || !(*str)) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "NULL parameter was passed when a non NULL parameter was expected"); + return NULL; + } + + string = (axutil_string_t *)AXIS2_MALLOC(env->allocator, sizeof(axutil_string_t)); + if(!string) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + /* set properties */ + string->buffer = *str; + string->length = axutil_strlen(*str); + string->ref_count = 1; + string->owns_buffer = AXIS2_TRUE; + + if(string->length < 0) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "NULL parameter was passed when a non NULL parameter was expected"); + axutil_string_free(string, env); + return NULL; + } + + return string; +} + +AXIS2_EXTERN axutil_string_t *AXIS2_CALL +axutil_string_create_const( + const axutil_env_t *env, + axis2_char_t **str) +{ + axutil_string_t *string = NULL; + AXIS2_ENV_CHECK(env, NULL); + + /* str can't be null */ + if(!str) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "NULL parameter was passed when a non NULL parameter was expected"); + + return NULL; + } + + string = (axutil_string_t *)AXIS2_MALLOC(env->allocator, sizeof(axutil_string_t)); + if(!string) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + /* set properties */ + string->buffer = *str; + string->length = axutil_strlen(*str); + string->ref_count = 1; + string->owns_buffer = AXIS2_FALSE; + + if(string->length < 0) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "NULL parameter was passed when a non NULL parameter was expected"); + axutil_string_free(string, env); + return NULL; + } + + return string; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_string_free( + struct axutil_string *string, + const axutil_env_t *env) +{ + if(!string) + { + return; + } + + string->ref_count--; + + if(string->ref_count > 0) + { + return; + } + + if(string->owns_buffer && string->buffer) + { + AXIS2_FREE(env->allocator, string->buffer); + } + + AXIS2_FREE(env->allocator, string); + return; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axutil_string_equals( + const struct axutil_string *string, + const axutil_env_t * env, + const struct axutil_string *string1) +{ + if(!string || !string1) + { + return AXIS2_FALSE; + } + + return (string->buffer == string1->buffer); +} + +AXIS2_EXTERN struct axutil_string *AXIS2_CALL +axutil_string_clone( + struct axutil_string *string, + const axutil_env_t *env) +{ + if(!string) + { + return NULL; + } + + string->ref_count++; + + return string; +} + +AXIS2_EXTERN const axis2_char_t *AXIS2_CALL +axutil_string_get_buffer( + const struct axutil_string *string, + const axutil_env_t *env) +{ + if(!string) + { + return NULL; + } + + return string->buffer; +} + +AXIS2_EXTERN unsigned int AXIS2_CALL +axutil_string_get_length( + const struct axutil_string *string, + const axutil_env_t *env) +{ + int error_return = -1; + if(!string) + { + return error_return; + } + + return string->length; +} + +/* END of string struct implementation */ + +/** this is used to cache lengths in axutil_strcat */ +#define MAX_SAVED_LENGTHS 6 + +AXIS2_EXTERN void *AXIS2_CALL +axutil_strdup( + const axutil_env_t *env, + const void *ptr) +{ + if(ptr) + { + int len = axutil_strlen(ptr); + axis2_char_t *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); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + memcpy(str, ptr, len + 1); + return (void *)str; + } + else + { + return NULL; + } +} + +AXIS2_EXTERN void *AXIS2_CALL +axutil_strmemdup( + const void *ptr, + size_t n, + const axutil_env_t *env) +{ + axis2_char_t *str; + + 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); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + memcpy(str, ptr, n); + str[n] = '\0'; + + return (void *)str; +} + +AXIS2_EXTERN void *AXIS2_CALL +axutil_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 +axutil_strndup( + const axutil_env_t *env, + const void *ptr, + int n) +{ + const axis2_char_t *end; + axis2_char_t *str; + + AXIS2_PARAM_CHECK(env->error, ptr, NULL); + + end = axutil_memchr(ptr, '\0', n); + if(end) + n = (int)(end - (axis2_char_t *)ptr); + /* We are sure that the difference lies within the int range */ + 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); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + memcpy(str, ptr, n); + str[n] = '\0'; + + return (void *)str; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_strcat( + const axutil_env_t *env, + ...) +{ + axis2_char_t *cp, *argp, *str; + size_t saved_lengths[MAX_SAVED_LENGTHS]; + int nargs = 0; + int str_len = 0; + + /* Pass one --- find length of required string */ + + size_t len = 0; + va_list adummy; + + va_start(adummy, env); + + cp = va_arg(adummy, axis2_char_t *); + while(cp) + { + size_t cplen = strlen(cp); + if(nargs < MAX_SAVED_LENGTHS) + { + saved_lengths[nargs++] = cplen; + } + len += cplen; + cp = va_arg(adummy, axis2_char_t *); + } + + va_end(adummy); + + /* Allocate the required string */ + str_len = (int)(sizeof(axis2_char_t) * (len + 1)); + /* We are sure that the difference lies within the int range */ + str = (axis2_char_t *) AXIS2_MALLOC(env->allocator, str_len); + if (!str) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + cp = str; + + /* Pass two --- copy the argument strings into the result space */ + + va_start(adummy, env); + + nargs = 0; + argp = va_arg(adummy, axis2_char_t *); + while (argp) + { + if (nargs < MAX_SAVED_LENGTHS) + { + len = saved_lengths[nargs++]; + } + else + { + len = strlen(argp); + } + + memcpy(cp, argp, len); + cp += len; + argp = va_arg(adummy, axis2_char_t *); + } + + va_end(adummy); + + /* Return the result string */ + + *cp = '\0'; + return str; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_stracat( + const axutil_env_t *env, + const axis2_char_t *s1, + const axis2_char_t *s2) +{ + axis2_char_t *ret = NULL; + int alloc_len = -1; + int len1 = 0; + int len2 = 0; + + if(!s1 && !s2) + { + return NULL; + } + if(!s1) + { + return (axis2_char_t *)axutil_strdup(env, s2); + } + if(!s2) + { + return (axis2_char_t *)axutil_strdup(env, s1); + } + + len1 = axutil_strlen(s1); + len2 = axutil_strlen(s2); + alloc_len = len1 + len2 + 1; + ret = (axis2_char_t *)AXIS2_MALLOC(env->allocator, alloc_len * sizeof(axis2_char_t)); + memcpy(ret, s1, len1 * sizeof(axis2_char_t)); + memcpy((ret + len1 * sizeof(axis2_char_t)), s2, len2 * sizeof(axis2_char_t)); + ret[alloc_len * sizeof(axis2_char_t) - sizeof(axis2_char_t)] = '\0'; + return ret; +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_strcmp( + const axis2_char_t *s1, + const axis2_char_t *s2) +{ + if(s1 && s2) + { + return strcmp(s1, s2); + } + else + { + return -1; + } +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_strncmp( + const axis2_char_t *s1, + const axis2_char_t *s2, + int n) +{ + if(s1 && s2) + { + return strncmp(s1, s2, n); + } + else + { + return -1; + } +} + +AXIS2_EXTERN axis2_ssize_t AXIS2_CALL +axutil_strlen( + const axis2_char_t *s) +{ + int error_return = -1; + if(s) + { + return (axis2_ssize_t)strlen(s); + /* We are sure that the difference lies within the axis2_ssize_t range */ + } + return error_return; +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_strcasecmp( + const axis2_char_t *s1, + const axis2_char_t *s2) +{ + while(*s1 != '\0' && *s2 != '\0') + { + if(*s1 >= 'A' && *s1 <= 'Z' && *s2 >= 'a' && *s2 <= 'z') + { + if(*s2 - *s1 - (char)32 != 0) + { + return 1; + } + } + else if(*s1 >= 'a' && *s1 <= 'z' && *s2 >= 'A' && *s2 <= 'Z') + { + if(*s1 - *s2 - 32 != 0) + { + return 1; + } + } + else if(*s1 - *s2 != 0) + { + return 1; + } + s1++; + s2++; + } + if(*s1 != *s2) + { + return 1; + } + + return 0; +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_strncasecmp( + const axis2_char_t *s1, + const axis2_char_t *s2, + const int n) +{ + axis2_char_t *str1 = (axis2_char_t *)s1, *str2 = (axis2_char_t *)s2; + int i = (int)n; + + while(--i >= 0 && toupper((int)*str1) == toupper((int)*str2++)) + { + if(toupper((int)*str1++) == '\0') + { + return (0); + } + } + return (i < 0 ? 0 : toupper((int)*str1) - toupper((int)*--str2)); +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_strstr( + const axis2_char_t *haystack, + const axis2_char_t *needle) +{ + return strstr(haystack, needle); +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_strchr( + const axis2_char_t *s, + axis2_char_t ch) +{ + return (axis2_char_t *)strchr(s, ch); +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_rindex( + const axis2_char_t *_s, + axis2_char_t _ch) +{ + int i, ilen = axutil_strlen(_s); + if(ilen < 1) + { + return NULL; + } + for(i = ilen - 1; i >= 0; i--) + { + if(_s[i] == _ch) + { + return (axis2_char_t *)(_s + i); + } + } + return NULL; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_replace( + const axutil_env_t *env, + axis2_char_t *str, + int s1, + int s2) +{ + axis2_char_t *newstr = NULL; + axis2_char_t *index = NULL; + if(!str) + { + return NULL; + } + + newstr = axutil_strdup(env, str); + index = strchr(newstr, s1); + while(index) + { + newstr[index - newstr] = (axis2_char_t)s2; + /* We are sure that the conversion is safe */ + index = strchr(newstr, s1); + } + return newstr; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_strltrim( + const axutil_env_t *env, + const axis2_char_t *_s, + const axis2_char_t *_trim) +{ + axis2_char_t *_p = NULL; + axis2_char_t *ret = NULL; + + if(!_s) + { + return NULL; + } + _p = (axis2_char_t *)_s; + if(!_trim) + { + _trim = " \t\r\n"; + } + + while(*_p) + { + if(!strchr(_trim, *_p)) + { + ret = (axis2_char_t *)axutil_strdup(env, _p); + break; + } + ++_p; + } + return ret; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_strrtrim( + const axutil_env_t *env, + const axis2_char_t *_in, + const axis2_char_t *_trim) +{ + axis2_char_t *__tail; + axis2_char_t *_s = NULL; + axis2_char_t *ret = NULL; + + if(_in) + { + _s = axutil_strdup(env, _in); + } + if(!_s) + { + return NULL; + } + __tail = _s + axutil_strlen(_s); + if(!_trim) + { + _trim = " \t\n\r"; + } + while(_s < __tail--) + { + if(!strchr(_trim, *__tail)) + { + ret = _s; + break; + } + *__tail = 0; + } + if(!ret && _s) + { + AXIS2_FREE(env->allocator, _s); + } + return ret; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_strtrim( + const axutil_env_t *env, + const axis2_char_t *_s, + const axis2_char_t *_trim) +{ + axis2_char_t *_p = NULL; + axis2_char_t *_q = NULL; + + _p = axutil_strltrim(env, _s, _trim); + _q = axutil_strrtrim(env, _p, _trim); + if(_p) + { + AXIS2_FREE(env->allocator, _p); + } + return _q; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_string_replace( + axis2_char_t *str, + axis2_char_t old, + axis2_char_t new) +{ + axis2_char_t *str_returns = str; + for(; *str != '\0'; str++) + { + if(*str == old) + { + *str = new; + } + } + return str_returns; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_string_substring_starting_at( + axis2_char_t *str, + int s) +{ + int len; + int pos_to_shift; + + len = (int)strlen(str); + /* We are sure that the difference lies within the int range */ + pos_to_shift = len - s + 1; + + if(len <= s) + { + return NULL; + } + memmove(str, str + s, pos_to_shift); + return str; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_string_substring_ending_at( + axis2_char_t *str, + int e) +{ + axis2_char_t *ptr = NULL; + int length = 0; + + length = (int)strlen(str); + /* We are sure that the difference lies within the int range */ + ptr = str; + if(length <= e) + { + return NULL; + } + ptr += e; + *ptr = '\0'; + return str; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_string_tolower( + axis2_char_t *str) +{ + axis2_char_t *temp_str = NULL; + for(temp_str = str; *temp_str != '\0'; temp_str++) + { + *temp_str = (axis2_char_t)tolower((int)*temp_str); + /* We are sure that the conversion is safe */ + } + return str; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_string_toupper( + axis2_char_t *str) +{ + axis2_char_t *temp_str = NULL; + for(temp_str = str; *temp_str != '\0'; temp_str++) + { + *temp_str = (axis2_char_t)toupper((int)*temp_str); + /* We are sure that the conversion is safe */ + } + return str; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_strcasestr( + const axis2_char_t *haystack, + const axis2_char_t *needle) +{ + axis2_char_t start, current; + size_t len; + + if(!haystack || !needle) + { + return NULL; + } + + if((start = *needle++)) + { + len = strlen(needle); + do + { + do + { + if(!(current = *haystack++)) + { + return NULL; + } + } + while(toupper((int)current) != toupper((int)start)); + } + while(axutil_strncasecmp(haystack, needle, (int)len)); + /* We are sure that the difference lies within the int range */ + haystack--; + } + return (axis2_char_t *)haystack; +} diff --git a/util/src/string_util.c b/util/src/string_util.c new file mode 100644 index 0000000..b89f6fb --- /dev/null +++ b/util/src/string_util.c @@ -0,0 +1,160 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_string_util.h> +#include <string.h> +#include <axutil_utils.h> + +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +axutil_tokenize( + const axutil_env_t *env, + axis2_char_t *in, + int delim) +{ + axutil_array_list_t *list = NULL; + axis2_char_t *rest = NULL; + axis2_char_t *str = NULL; + axis2_char_t *temp = NULL; + axis2_bool_t loop_state = AXIS2_TRUE; + + axis2_char_t *index = NULL; + + if(!in || !*in) + { + return NULL; + } + list = axutil_array_list_create(env, 10); + if(!list) + { + return NULL; + } + + str = axutil_strdup(env, in); + temp = str; + + do + { + index = strchr(str, delim); + if((!index) && str && *str) + { + axutil_array_list_add(list, env, axutil_strdup(env, str)); + break; + } + + rest = index + 1; + str[index - str] = '\0'; + if(str && *str) + { + axutil_array_list_add(list, env, axutil_strdup(env, str)); + } + + if(!rest || !*rest) + { + break; + } + str = rest; + rest = NULL; + index = NULL; + + } + while(loop_state); + if(temp) + { + AXIS2_FREE(env->allocator, temp); + } + return list; +} + +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +axutil_first_token( + const axutil_env_t *env, + axis2_char_t *in, + int delim) +{ + axutil_array_list_t *list = NULL; + axis2_char_t *str = NULL; + axis2_char_t *rest = NULL; + axis2_char_t *index = NULL; + + if(!in && !*in) + { + return NULL; + } + + list = axutil_array_list_create(env, 2); + if(!list) + { + return NULL; + } + str = axutil_strdup(env, in); + + index = strchr(str, delim); + if(!index) + { + axutil_array_list_add(list, env, str); + axutil_array_list_add(list, env, axutil_strdup(env, "")); + return list; + } + + rest = index + 1; + str[index - str] = '\0'; + + axutil_array_list_add(list, env, str); + axutil_array_list_add(list, env, axutil_strdup(env, rest)); + return list; +} + +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +axutil_last_token( + const axutil_env_t *env, + axis2_char_t *in, + int delim) +{ + axutil_array_list_t *list = NULL; + axis2_char_t *str = NULL; + axis2_char_t *rest = NULL; + axis2_char_t *index = NULL; + + if(!in && !*in) + { + return NULL; + } + + list = axutil_array_list_create(env, 2); + if(!list) + { + return NULL; + } + + str = axutil_strdup(env, in); + index = axutil_rindex(str, (axis2_char_t)delim); + /* We are sure that the conversion is safe */ + if(!index) + { + axutil_array_list_add(list, env, axutil_strdup(env, "")); + axutil_array_list_add(list, env, str); + return list; + } + + rest = index + 1; + str[index - str] = '\0'; + + axutil_array_list_add(list, env, str); + axutil_array_list_add(list, env, axutil_strdup(env, rest)); + + return list; +} diff --git a/util/src/thread_pool.c b/util/src/thread_pool.c new file mode 100644 index 0000000..cf1078d --- /dev/null +++ b/util/src/thread_pool.c @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_thread_pool.h> +#include <axutil_env.h> +#include <axutil_error_default.h> + +struct axutil_thread_pool +{ + axutil_allocator_t *allocator; +}; + +AXIS2_EXTERN axutil_thread_pool_t *AXIS2_CALL +axutil_thread_pool_init( + axutil_allocator_t *allocator) +{ + axutil_thread_pool_t *pool = NULL; + + pool = (axutil_thread_pool_t *)AXIS2_MALLOC(allocator, sizeof(axutil_thread_pool_t)); + + if(!pool) + { + return NULL; + } + pool->allocator = allocator; + + return pool; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_thread_pool_free( + axutil_thread_pool_t *pool) +{ + if(!pool) + { + return; + } + if(!pool->allocator) + { + return; + } + AXIS2_FREE(pool->allocator, pool); + return; +} + +AXIS2_EXTERN axutil_thread_t *AXIS2_CALL +axutil_thread_pool_get_thread( + axutil_thread_pool_t *pool, + axutil_thread_start_t func, + void *data) +{ + if(!pool) + { + return NULL; + } + if(!pool->allocator) + { + return NULL; + } + return axutil_thread_create(pool->allocator, NULL, func, data); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_pool_join_thread( + axutil_thread_pool_t *pool, + axutil_thread_t *thd) +{ + if(!pool || !thd) + { + return AXIS2_FAILURE; + } + return axutil_thread_join(thd); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_pool_exit_thread( + axutil_thread_pool_t *pool, + axutil_thread_t *thd) +{ + if(!pool || !thd) + { + return AXIS2_FAILURE; + } + return axutil_thread_exit(thd, pool->allocator); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_thread_pool_thread_detach( + axutil_thread_pool_t *pool, + axutil_thread_t *thd) +{ + if(!pool || !thd) + { + return AXIS2_FAILURE; + } + return axutil_thread_detach(thd); +} + +AXIS2_EXTERN axutil_env_t *AXIS2_CALL +axutil_init_thread_env( + const axutil_env_t *system_env) +{ + axutil_allocator_t * allocator = NULL; + axutil_error_t *error = NULL; + allocator = axutil_allocator_clone(system_env->allocator); + error = axutil_error_create(allocator); + return axutil_env_create_with_error_log_thread_pool(allocator, error, system_env->log, + system_env-> thread_pool); +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_free_thread_env( + struct axutil_env *thread_env) +{ + if(!thread_env) + { + return; + } + + if(--(thread_env->ref) > 0) + { + return; + } + + /* log, thread_pool and allocator are shared, so do not free them */ + thread_env->log = NULL; + thread_env->thread_pool = NULL; + if(thread_env->error) + { + AXIS2_ERROR_FREE(thread_env->error); + } + AXIS2_FREE(thread_env->allocator, thread_env); +} diff --git a/util/src/types.c b/util/src/types.c new file mode 100644 index 0000000..a47cc67 --- /dev/null +++ b/util/src/types.c @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_types.h> + +AXIS2_EXTERN int AXIS2_CALL +axutil_atoi( + const char *s) +{ + int i, n; + + n = 0; + for(i = 0; s[i] >= '0' && s[i] <= '9'; ++i) + { + n = 10 * n + (s[i] - '0'); + } + return n; +} + +AXIS2_EXTERN int64_t AXIS2_CALL +axutil_atol( + const char *s) +{ + int i; + int64_t n; + + n = 0; + for(i = 0; s[i] >= '0' && s[i] <= '9'; ++i) + { + n = 10 * n + (s[i] - '0'); + } + return n; +} + +AXIS2_EXTERN uint64_t AXIS2_CALL +axutil_strtoul( + const char *s, + char **endptr, + int base) +{ + int i; + uint64_t n; + + n = 0; + for(i = 0; s[i] >= '0' && s[i] <= '9'; ++i) + { + n = 10 * n + (s[i] - '0'); + } + if(endptr != NULL) + { + *endptr = (char *)(s + i); + } + return n; +} + +AXIS2_EXTERN int64_t AXIS2_CALL +axutil_strtol( + const char *s, + char **endptr, + int base) +{ + int i; + int64_t n; + + n = 0; + for(i = 0; s[i] >= '0' && s[i] <= '9'; ++i) + { + n = 10 * n + (s[i] - '0'); + } + if(endptr != NULL) + { + *endptr = (char *)(s + i); + } + return n; +} diff --git a/util/src/uri.c b/util/src/uri.c new file mode 100644 index 0000000..d9e1bd6 --- /dev/null +++ b/util/src/uri.c @@ -0,0 +1,970 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <stdlib.h> +#define AXIS2_WANT_STRFUNC +#include <axutil_uri.h> + +typedef struct schemes_t schemes_t; + +/** Structure to store various schemes and their default ports */ +struct schemes_t +{ + /** The name of the scheme */ + const axis2_char_t *name; + + /** The default port for the scheme */ + axis2_port_t default_port; +}; + +/* Some WWW schemes and their default ports; this is basically /etc/services */ + +/* This will become global when the protocol abstraction comes */ + +/* As the schemes are searched by a linear search, */ + +/* they are sorted by their expected frequency */ +static schemes_t schemes[] = { + {"http", AXIS2_URI_HTTP_DEFAULT_PORT}, + {"ftp", AXIS2_URI_FTP_DEFAULT_PORT}, + {"https", AXIS2_URI_HTTPS_DEFAULT_PORT}, + {"gopher", AXIS2_URI_GOPHER_DEFAULT_PORT}, + {"ldap", AXIS2_URI_LDAP_DEFAULT_PORT}, + {"nntp", AXIS2_URI_NNTP_DEFAULT_PORT}, + {"snews", AXIS2_URI_SNEWS_DEFAULT_PORT}, + {"imap", AXIS2_URI_IMAP_DEFAULT_PORT}, + {"pop", AXIS2_URI_POP_DEFAULT_PORT}, + {"sip", AXIS2_URI_SIP_DEFAULT_PORT}, + {"rtsp", AXIS2_URI_RTSP_DEFAULT_PORT}, + {"wais", AXIS2_URI_WAIS_DEFAULT_PORT}, + {"z39.50r", AXIS2_URI_WAIS_DEFAULT_PORT}, + {"z39.50s", AXIS2_URI_WAIS_DEFAULT_PORT}, + {"prospero", AXIS2_URI_PROSPERO_DEFAULT_PORT}, + {"nfs", AXIS2_URI_NFS_DEFAULT_PORT}, + {"tip", AXIS2_URI_TIP_DEFAULT_PORT}, + {"acap", AXIS2_URI_ACAP_DEFAULT_PORT}, + {"telnet", AXIS2_URI_TELNET_DEFAULT_PORT}, + {"ssh", AXIS2_URI_SSH_DEFAULT_PORT}, + {NULL, 0xFFFF} /* unknown port */ +}; + +/* Here is the hand-optimized parse_uri_components(). There are some wild + * tricks we could pull in assembly language that we don't pull here... like we + * can do word-at-time scans for delimiter characters using the same technique + * that fast axutil_memchr()s use. But that would be way non-portable. -djg + */ + +/* We have a axis2_table_t that we can index by character and it tells us if the + * character is one of the interesting delimiters. Note that we even get + * compares for NUL for free -- it's just another delimiter. + */ + +#define T_COLON 0x01 /* ':' */ +#define T_SLASH 0x02 /* '/' */ +#define T_QUESTION 0x04 /* '?' */ +#define T_HASH 0x08 /* '#' */ +#define T_NUL 0x80 /* '\0' */ + +#if AXIS2_CHARSET_EBCDIC + +/* Delimiter table for the EBCDIC character set */ +static const unsigned char uri_delims[256] = { + T_NUL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, T_SLASH, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, T_QUESTION, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, T_COLON, T_HASH, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; +#else + +/* Delimiter table for the ASCII character set */ +static const unsigned char uri_delims[256] = { + T_NUL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, T_HASH, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, T_SLASH, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, T_COLON, 0, 0, 0, 0, T_QUESTION, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; +#endif + +/* it works like this: + if (uri_delims[ch] & NOTEND_foobar) { + then we're not at a delimiter for foobar + } +*/ + +/* Note that we optimize the scheme scanning here, we cheat and let the + * compiler know that it doesn't have to do the & masking. + */ +#define NOTEND_SCHEME (0xff) +#define NOTEND_HOSTINFO (T_SLASH | T_QUESTION | T_HASH | T_NUL) +#define NOTEND_PATH (T_QUESTION | T_HASH | T_NUL) + +/** + * A structure to encompass all of the fields in a uri + */ +struct axutil_uri +{ + /** scheme ("http"/"ftp"/...) */ + axis2_char_t *scheme; + + /** combined [user[:password]\@]host[:port] */ + axis2_char_t *hostinfo; + + /** user name, as in http://user:passwd\@host:port/ */ + axis2_char_t *user; + + /** password, as in http://user:passwd\@host:port/ */ + axis2_char_t *password; + + /** hostname from URI (or from Host: header) */ + axis2_char_t *hostname; + + /** port string (integer representation is in "port") */ + axis2_char_t *port_str; + + /** the request path (or "/" if only scheme://host was given) */ + axis2_char_t *path; + + /** Everything after a '?' in the path, if present */ + axis2_char_t *query; + + /** Trailing "#fragment" string, if present */ + axis2_char_t *fragment; + + /** structure returned from gethostbyname() */ + struct hostent *hostent; + + /** The port number, numeric, valid only if port_str */ + axis2_port_t port; + + /** has the structure been initialized */ + unsigned is_initialized:1; + + /** has the DNS been looked up yet */ + unsigned dns_looked_up:1; + + /** has the dns been resolved yet */ + unsigned dns_resolved:1; + + /** is it an IPv6 URL */ + unsigned is_ipv6:1; +}; + +AXIS2_EXTERN axutil_uri_t *AXIS2_CALL +axutil_uri_create( + const axutil_env_t *env) +{ + axutil_uri_t *uri = NULL; + AXIS2_ENV_CHECK(env, NULL); + + uri = (axutil_uri_t *)AXIS2_MALLOC(env->allocator, sizeof(axutil_uri_t)); + + if(!uri) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + uri->scheme = NULL; + uri->hostinfo = NULL; + uri->user = NULL; + uri->password = NULL; + uri->hostname = NULL; + uri->port_str = NULL; + uri->path = NULL; + uri->query = NULL; + uri->fragment = NULL; + uri->hostent = NULL; + uri->port = 0; + uri->is_ipv6 = 0; + + return uri; +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_uri_free( + axutil_uri_t *uri, + const axutil_env_t *env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(uri->scheme) + { + AXIS2_FREE(env->allocator, uri->scheme); + uri->scheme = NULL; + } + + if(uri->hostinfo) + { + AXIS2_FREE(env->allocator, uri->hostinfo); + uri->hostinfo = NULL; + } + + if(uri->user) + { + AXIS2_FREE(env->allocator, uri->user); + uri->user = NULL; + } + + if(uri->password) + { + AXIS2_FREE(env->allocator, uri->password); + uri->password = NULL; + } + + if(uri->hostname) + { + AXIS2_FREE(env->allocator, uri->hostname); + uri->hostname = NULL; + } + + if(uri->port_str) + { + AXIS2_FREE(env->allocator, uri->port_str); + uri->port_str = NULL; + } + + if(uri->path) + { + AXIS2_FREE(env->allocator, uri->path); + uri->path = NULL; + } + + if(uri->query) + { + AXIS2_FREE(env->allocator, uri->query); + uri->query = NULL; + } + + if(uri->fragment) + { + AXIS2_FREE(env->allocator, uri->fragment); + uri->fragment = NULL; + } + + AXIS2_FREE(env->allocator, uri); + + return; +} + +/* parse_uri_components(): + * Parse a given URI, fill in all supplied fields of a uri_components + * structure. This eliminates the necessity of extracting host, port, + * path, query info repeatedly in the modules. + * Side effects: + * - fills in fields of uri_components *uptr + * - none on any of the r->* fields + */ + +AXIS2_EXTERN axutil_uri_t *AXIS2_CALL +axutil_uri_parse_string( + const axutil_env_t *env, + const axis2_char_t *uri_str) +{ + axutil_uri_t *uri = NULL; + const axis2_char_t *s; + const axis2_char_t *s1; + const axis2_char_t *hostinfo; + axis2_char_t *endstr; + int port; + int v6_offset1 = 0, v6_offset2 = 0; + + AXIS2_PARAM_CHECK(env->error, uri_str, NULL); + + uri = (axutil_uri_t *)axutil_uri_create(env); + + /* Initialize the structure. parse_uri() and parse_uri_components() + * can be called more than once per request. + */ + uri->is_initialized = 1; + + /* We assume the processor has a branch predictor like most -- + * it assumes forward branches are untaken and backwards are taken. That's + * the reason for the gotos. + */ + if(uri_str[0] == '/') + { + /* RFC2396 #4.3 says that two leading slashes mean we have an + * authority component, not a path! Fixing this looks scary + * with the gotos here. But if the existing logic is valid, + * then presumably a goto pointing to deal_with_authority works. + * + * RFC2396 describes this as resolving an ambiguity. In the + * case of three or more slashes there would seem to be no + * ambiguity, so it is a path after all. + */ + if(uri_str[1] == '/' && uri_str[2] != '/') + { + s = uri_str + 2; + goto deal_with_authority; + } + + deal_with_path: + /* we expect uri to point to first character of path ... remember + * that the path could be empty -- http://foobar?query for example + */ + s = uri_str; + if((!uri->hostinfo && uri_str[0] == '/' && uri_str[1] == '/') || (!uri->scheme + && uri_str[0] == ':')) + { + if(uri) + { + axutil_uri_free(uri, env); + } + uri = NULL; + goto end; + } + while((uri_delims[*(unsigned char *)s] & NOTEND_PATH) == 0) + { + ++s; + } + if(s != uri_str) + { + uri->path = axutil_strmemdup(uri_str, s - uri_str, env); + } + if(*s == 0) + { + goto end; + } + if(*s == '?') + { + ++s; + s1 = strchr(s, '#'); + if(s1) + { + uri->fragment = axutil_strdup(env, s1 + 1); + uri->query = axutil_strmemdup(s, s1 - s, env); + } + else + { + uri->query = axutil_strdup(env, s); + } + goto end; + } + /* otherwise it's a fragment */ + uri->fragment = axutil_strdup(env, s + 1); + + goto end; + } + + /* find the scheme: */ + s = uri_str; + while((uri_delims[*(unsigned char *)s] & NOTEND_SCHEME) == 0) + { + ++s; + } + /* scheme must be non-empty and followed by :// */ + if(s == uri_str || s[0] != ':' || s[1] != '/' || s[2] != '/') + { + if(uri->scheme) + { + AXIS2_FREE(env->allocator, uri->scheme); + uri->scheme = NULL; + } + s = uri_str; /* restart from beginning as the loop must have ended in + * in a wrong place. */ + goto deal_with_authority; + /* backwards predicted taken! */ + } + + uri->scheme = axutil_strmemdup(uri_str, s - uri_str, env); + s += 3; + + deal_with_authority: hostinfo = s; + while((uri_delims[*(unsigned char *)s] & NOTEND_HOSTINFO) == 0) + { + ++s; + } + uri_str = s; /* whatever follows hostinfo is start of uri */ + uri->hostinfo = axutil_strmemdup(hostinfo, uri_str - hostinfo, env); + + /* If there's a username:password@host:port, the @ we want is the last @... + * too bad there's no memrchr()... For the C purists, note that hostinfo + * is definately not the first character of the original uri so therefore + * &hostinfo[-1] < &hostinfo[0] ... and this loop is valid C. + */ + do + { + --s; + } + while(s >= hostinfo && *s != '@'); + if(s < hostinfo) + { + /* again we want the common case to be fall through */ + deal_with_host: + /* We expect hostinfo to point to the first character of + * the hostname. If there's a port it is the first colon, + * except with IPv6. + */ + if(*hostinfo == '[') + { + if(*(hostinfo + 1) == ']') + { + if(uri) + { + axutil_uri_free(uri, env); + } + uri = NULL; + goto end; + } + if((*(hostinfo + 1) >= '0' && *(hostinfo + 1) <= '9') || (*(hostinfo + 1) >= 'a' + && *(hostinfo + 1) <= 'z') || (*(hostinfo + 1) >= 'A' && *(hostinfo + 1) <= 'Z') + || (*(hostinfo + 1) == ':' && *(hostinfo + 2) == ':')) + { + uri->is_ipv6 = 1; + } + else + { + if(uri) + { + axutil_uri_free(uri, env); + } + uri = NULL; + goto end; + } + v6_offset1 = 1; + v6_offset2 = 2; + s = axutil_memchr(hostinfo, ']', uri_str - hostinfo); + if(!s) + { + if(uri) + { + axutil_uri_free(uri, env); + } + uri = NULL; + goto end; + } + if(*++s != ':') + { + s = NULL; /* no port */ + } + } + else if(!*hostinfo || (*hostinfo >= '0' && *hostinfo <= '9') || (*hostinfo >= 'a' + && *hostinfo <= 'z') || (*hostinfo >= 'A' && *hostinfo <= 'Z') || *hostinfo == '?' + || *hostinfo == '/' || *hostinfo == '#') + { + s = axutil_memchr(hostinfo, ':', uri_str - hostinfo); + } + else + { + if(uri) + { + axutil_uri_free(uri, env); + } + uri = NULL; + goto end; + } + if(!s) + { + /* we expect the common case to have no port */ + uri->hostname = axutil_strmemdup(hostinfo + v6_offset1, + uri_str - hostinfo - v6_offset2, env); + goto deal_with_path; + } + uri->hostname = axutil_strmemdup(hostinfo + v6_offset1, s - hostinfo - v6_offset2, env); + ++s; + uri->port_str = axutil_strmemdup(s, uri_str - s, env); + if(uri_str != s) + { + port = strtol(uri->port_str, &endstr, 10); + uri->port = (axis2_port_t)port; + /* We are sure that the conversion is safe */ + if(*endstr == '\0') + { + goto deal_with_path; + } + /* Invalid characters after ':' found */ + if(uri) + { + axutil_uri_free(uri, env); + } + uri = NULL; + goto end; + } + uri->port = axutil_uri_port_of_scheme(uri->scheme); + goto deal_with_path; + } + + /* first colon delimits username:password */ + s1 = axutil_memchr(hostinfo, ':', s - hostinfo); + if(s1) + { + uri->user = axutil_strmemdup(hostinfo, s1 - hostinfo, env); + ++s1; + uri->password = axutil_strmemdup(s1, s - s1, env); + } + else + { + uri->user = axutil_strmemdup(hostinfo, s - hostinfo, env); + } + hostinfo = s + 1; + goto deal_with_host; + + /* End of function call */ + end: return uri; +} + +/* Special case for CONNECT parsing: it comes with the hostinfo part only */ + +/* See the INTERNET-DRAFT document "Tunneling SSL Through a WWW Proxy" + * currently at http://muffin.doit.org/docs/rfc/tunneling_ssl.html + * for the format of the "CONNECT host:port HTTP/1.0" request + */ +AXIS2_EXTERN axutil_uri_t *AXIS2_CALL +axutil_uri_parse_hostinfo( + const axutil_env_t *env, + const axis2_char_t *hostinfo) +{ + axutil_uri_t *uri = NULL; + const axis2_char_t *s; + axis2_char_t *endstr; + const axis2_char_t *rsb; + int v6_offset1 = 0; + + AXIS2_PARAM_CHECK(env->error, hostinfo, NULL); + + uri = (axutil_uri_t *)axutil_uri_create(env); + if(!uri) + { + return NULL; + } + /* Initialize the structure. parse_uri() and parse_uri_components() + * can be called more than once per request. + */ + memset(uri, '\0', sizeof(*uri)); + uri->is_initialized = 1; + uri->hostinfo = axutil_strdup(env, hostinfo); + + /* We expect hostinfo to point to the first character of + * the hostname. There must be a port, separated by a colon + */ + if(*hostinfo == '[') + { + if(*(hostinfo + 1) == ']') + { + axutil_uri_free(uri, env); + return NULL; + } + uri->is_ipv6 = 1; + rsb = strchr(hostinfo, ']'); + if(!rsb || *(rsb + 1) != ':') + { + axutil_uri_free(uri, env); + return NULL; + } + /* literal IPv6 address + * Special allowances has been made according to RFC3986 for + * IPv6 addresses beginning with "::" + */ + s = rsb + 1; + if((*(hostinfo + 1) >= '0' && *(hostinfo + 1) <= '9') || (*(hostinfo + 1) >= 'a' + && *(hostinfo + 1) <= 'z') || (*(hostinfo + 1) >= 'A' && *(hostinfo + 1) <= 'Z') + || (*(hostinfo + 1) == ':' && *(hostinfo + 2) == ':')) + { + ++hostinfo; + } + else + { + axutil_uri_free(uri, env); + return NULL; + } + v6_offset1 = 1; + } + else if((*hostinfo >= '0' && *hostinfo <= '9') || (*hostinfo >= 'a' && *hostinfo <= 'z') + || (*hostinfo >= 'A' && *hostinfo <= 'Z')) + { + s = strchr(hostinfo, ':'); + } + else + { + axutil_uri_free(uri, env); + return NULL; + } + if(!s) + { + axutil_uri_free(uri, env); + return NULL; + } + uri->hostname = axutil_strndup(env, hostinfo, (int)(s - hostinfo - v6_offset1)); + /* We are sure that the difference lies within the int range */ + ++s; + uri->port_str = axutil_strdup(env, s); + if(*s != '\0') + { + uri->port = (unsigned short)strtol(uri->port_str, &endstr, 10); + if(*endstr == '\0') + { + return uri; + } + /* Invalid characters after ':' found */ + } + axutil_uri_free(uri, env); + return NULL; +} + +/* Resolve relative to a base. This means host/etc, and (crucially) path */ +AXIS2_EXTERN axutil_uri_t *AXIS2_CALL +axutil_uri_resolve_relative( + const axutil_env_t *env, + const axutil_uri_t *base, + axutil_uri_t *uri) +{ + AXIS2_PARAM_CHECK(env->error, base, NULL); + AXIS2_PARAM_CHECK(env->error, uri, NULL); + + if(!uri || !base || !base->is_initialized || !uri->is_initialized) + { + return NULL; + } + /* The interesting bit is the path. */ + if(!uri->path) + { + if(!uri->hostname) + { + /* is this compatible with is_initialised? Harmless in any case */ + uri->path = base->path ? base->path : axutil_strdup(env, "/"); + } + else + { + /* deal with the idiosyncracy of APR allowing path==NULL + * without risk of breaking back-compatibility + */ + uri->path = axutil_strdup(env, "/"); + } + } + else if(uri->path[0] != '/') + { + size_t baselen; + const char *basepath = base->path ? base->path : "/"; + char *path = uri->path; + char *temp = NULL; + const char *base_end = strrchr(basepath, '/'); + + temp = path; + + /* if base is nonsensical, bail out */ + if(basepath[0] != '/') + { + return NULL; + } + /* munch "up" components at the start, and chop them from base path */ + while(!strncmp(path, "../", 3)) + { + while(base_end > basepath) + { + if(*--base_end == '/') + { + break; + } + } + path += 3; + } + /* munch "here" components at the start */ + while(!strncmp(path, "./", 2)) + { + path += 2; + } + baselen = base_end - basepath + 1; + uri->path = AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * baselen + strlen(path) + 1); + memcpy(uri->path, basepath, baselen); + strcpy(uri->path + baselen, path); + if(temp) + { + AXIS2_FREE(env->allocator, temp); + } + } + + /* The trivial bits are everything-but-path */ + if(!uri->scheme) + { + uri->scheme = axutil_strdup(env, base->scheme); + } + if(!uri->hostinfo) + { + uri->hostinfo = axutil_strdup(env, base->hostinfo); + } + if(!uri->user) + { + uri->user = axutil_strdup(env, base->user); + } + if(!uri->password) + { + uri->password = axutil_strdup(env, base->password); + } + if(!uri->hostname) + { + uri->hostname = axutil_strdup(env, base->hostname); + } + if(!uri->port_str) + { + uri->port_str = axutil_strdup(env, base->port_str); + } + if(!uri->hostent) + { + uri->hostent = base->hostent; + } + if(!uri->port) + { + uri->port = base->port; + } + uri->is_ipv6 = base->is_ipv6; + + return uri; +} + +AXIS2_EXTERN axutil_uri_t *AXIS2_CALL +axutil_uri_parse_relative( + const axutil_env_t *env, + const axutil_uri_t *base, + const char *uri) +{ + axutil_uri_t *uptr = NULL; + axutil_uri_t *temp = NULL; + + uptr = axutil_uri_parse_string(env, uri); + if(!uptr && AXIS2_SUCCESS != AXIS2_ERROR_GET_STATUS_CODE(env->error)) + { + return uptr; + } + temp = uptr; + uptr = axutil_uri_resolve_relative(env, base, uptr); + + if(!uptr) + { + axutil_uri_free(temp, env); + } + + return uptr; +} +AXIS2_EXTERN axis2_port_t AXIS2_CALL +axutil_uri_port_of_scheme( + const axis2_char_t *scheme_str) +{ + schemes_t *scheme; + + if(scheme_str) + { + for(scheme = schemes; scheme->name; ++scheme) + { + if(axutil_strcasecmp(scheme_str, scheme->name) == 0) + { + return scheme->default_port; + } + } + } + return 0; +} + +AXIS2_EXTERN axutil_uri_t *AXIS2_CALL +axutil_uri_clone( + const axutil_uri_t *uri, + const axutil_env_t *env) +{ + axutil_uri_t *new_uri = NULL; + + new_uri = (axutil_uri_t *)axutil_uri_create(env); + + new_uri->scheme = axutil_strdup(env, uri->scheme); + new_uri->hostinfo = axutil_strdup(env, uri->hostinfo); + new_uri->user = axutil_strdup(env, uri->user); + new_uri->password = axutil_strdup(env, uri->password); + new_uri->hostname = axutil_strdup(env, uri->hostname); + new_uri->port_str = axutil_strdup(env, uri->port_str); + new_uri->path = axutil_strdup(env, uri->path); + new_uri->query = axutil_strdup(env, uri->query); + new_uri->fragment = axutil_strdup(env, uri->fragment); + new_uri->hostent = uri->hostent; + new_uri->port = uri->port; + new_uri->is_initialized = uri->is_initialized; + new_uri->dns_looked_up = uri->dns_looked_up; + new_uri->dns_resolved = uri->dns_resolved; + new_uri->is_ipv6 = uri->is_ipv6; + + return new_uri; +} + +/* Unparse a axutil_uri_t structure to an URI string. + * Optionally suppress the password for security reasons. + */ +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_uri_to_string( + const axutil_uri_t *uri, + const axutil_env_t *env, + unsigned flags) +{ + axis2_char_t *ret = ""; + axis2_char_t *temp = NULL; + AXIS2_ENV_CHECK(env, NULL); + + /* If suppressing the site part, omit both user name & scheme://hostname */ + if(!(flags & AXIS2_URI_UNP_OMITSITEPART)) + { + + /* Construct a "user:password@" string, honoring the passed + * AXIS2_URI_UNP_ flags: */ + if(uri->user || uri->password) + { + ret = axutil_strcat(env, (uri->user && !(flags & AXIS2_URI_UNP_OMITUSER)) ? uri-> user + : "", (uri->password && !(flags & AXIS2_URI_UNP_OMITPASSWORD)) ? ":" : "", + (uri->password && !(flags & AXIS2_URI_UNP_OMITPASSWORD)) ? ((flags + & AXIS2_URI_UNP_REVEALPASSWORD) ? uri-> password : "XXXXXXXX") : "", + ((uri->user && !(flags & AXIS2_URI_UNP_OMITUSER)) || (uri->password && !(flags + & AXIS2_URI_UNP_OMITPASSWORD))) ? "@" : "", NULL); + temp = ret; + } + + /* Construct scheme://site string */ + if(uri->hostname) + { + int is_default_port; + const axis2_char_t *lbrk = "", *rbrk = ""; + + if(uri->is_ipv6) + { /* v6 literal */ + lbrk = "["; + rbrk = "]"; + } + + is_default_port = (uri->port_str == NULL || uri->port == 0 || uri->port + == axutil_uri_port_of_scheme(uri->scheme)); + + if(uri->scheme) + { + ret = axutil_strcat(env, uri->scheme, "://", ret, lbrk, uri->hostname, rbrk, + is_default_port ? "" : ":", is_default_port ? "" : uri->port_str, NULL); + if(temp) + { + AXIS2_FREE(env->allocator, temp); + } + temp = ret; + } + else + { + /* Fixed to support Abbreviated URLs as in RFC2396. + * Thus, if no scheme, we omit "//" too, eventhough + * it is a part of authority. + */ + ret = axutil_strcat(env, ret, lbrk, uri->hostname, rbrk, + is_default_port ? "" : ":", is_default_port ? "" : uri->port_str, NULL); + /*ret = + axutil_strcat(env, "//", ret, lbrk, uri->hostname, rbrk, + is_default_port ? "" : ":", + is_default_port ? "" : uri->port_str, NULL);*/ + if(temp) + { + AXIS2_FREE(env->allocator, temp); + } + temp = ret; + } + } + } + + /* Should we suppress all path info? */ + if(!(flags & AXIS2_URI_UNP_OMITPATHINFO)) + { + /* Append path, query and fragment strings: */ + ret = axutil_strcat(env, ret, (uri->path) ? uri->path : "", (uri->query && !(flags + & AXIS2_URI_UNP_OMITQUERY_ONLY)) ? "?" : "", (uri->query && !(flags + & AXIS2_URI_UNP_OMITQUERY_ONLY)) ? uri-> query : "", (uri->fragment && !(flags + & AXIS2_URI_UNP_OMITFRAGMENT_ONLY)) ? "#" : NULL, (uri->fragment && !(flags + & AXIS2_URI_UNP_OMITFRAGMENT_ONLY)) ? uri-> fragment : NULL, NULL); + if(temp) + { + AXIS2_FREE(env->allocator, temp); + } + } + return ret; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_uri_get_protocol( + axutil_uri_t *uri, + const axutil_env_t *env) +{ + return uri->scheme; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_uri_get_server( + axutil_uri_t *uri, + const axutil_env_t *env) +{ + return uri->hostinfo; +} + +AXIS2_EXTERN axis2_port_t AXIS2_CALL +axutil_uri_get_port( + axutil_uri_t *uri, + const axutil_env_t *env) +{ + return uri->port; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_uri_get_host( + axutil_uri_t *uri, + const axutil_env_t *env) +{ + return uri->hostname; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_uri_get_query( + axutil_uri_t *uri, + const axutil_env_t *env) +{ + return uri->query; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_uri_get_fragment( + axutil_uri_t *uri, + const axutil_env_t *env) +{ + return uri->fragment; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_uri_get_path( + axutil_uri_t *uri, + const axutil_env_t *env) +{ + return uri->path; +} diff --git a/util/src/url.c b/util/src/url.c new file mode 100644 index 0000000..e13c87c --- /dev/null +++ b/util/src/url.c @@ -0,0 +1,699 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_url.h> +#include <axutil_string.h> +#include <axutil_string.h> +#include <axutil_file_handler.h> +#include <axutil_network_handler.h> +#include <axutil_types.h> + +struct axutil_url +{ + axis2_char_t *protocol; + axis2_char_t *host; + int port; + axis2_char_t *path; + axis2_char_t *query; + axis2_char_t *server; +}; + +static int +is_safe_or_unreserve( + char c); + +AXIS2_EXTERN axutil_url_t *AXIS2_CALL +axutil_url_create( + const axutil_env_t *env, + const axis2_char_t *protocol, + const axis2_char_t *host, + const int port, + const axis2_char_t *path) +{ + axutil_url_t *url = NULL; + AXIS2_ENV_CHECK(env, NULL); + AXIS2_PARAM_CHECK(env->error, protocol, NULL); + + if(!protocol || !*protocol || strstr(protocol, "://") || (host && strchr(host, '/'))) + { + return NULL; + } + + url = (axutil_url_t *)AXIS2_MALLOC(env->allocator, sizeof(axutil_url_t)); + + if(!url) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + url->protocol = axutil_strdup(env, protocol); + url->host = NULL; + url->path = NULL; + url->server = NULL; + url->query = NULL; + + if(host) + { + url->host = (axis2_char_t *)axutil_strdup(env, host); + url->port = port; + } + else + { + url->port = 0; + } + + /** if the path is not starting with / we have to make it so + */ + if(path) + { + axis2_char_t *params = NULL; + axis2_char_t *temp = NULL; + if(path[0] == '/') + { + temp = (axis2_char_t *)axutil_strdup(env, path); + } + else + { + temp = axutil_stracat(env, "/", path); + } + params = strchr(temp, '?'); + if(!params) + { + params = strchr(temp, '#'); + } + if(params) + { + url->query = (axis2_char_t *)axutil_strdup(env, params); + *params = '\0'; + } + url->path = (axis2_char_t *)axutil_strdup(env, temp); + AXIS2_FREE(env->allocator, temp); + } + + return url; +} + +AXIS2_EXTERN axutil_url_t *AXIS2_CALL +axutil_url_parse_string( + const axutil_env_t *env, + const axis2_char_t *str_url) +{ + /** + * Only accepted format is : + * protocol://host:port/path + * Added file:///path + * port is optional and the default port is assumed + * if path is not present / (root) is assumed + */ + axis2_char_t *tmp_url_str = NULL; + axutil_url_t *ret = NULL; + const axis2_char_t *protocol = NULL; + axis2_char_t *path = NULL; + axis2_char_t *port_str = NULL; + axis2_char_t *host = NULL; + int port = 0; + + AXIS2_ENV_CHECK(env, NULL); + AXIS2_PARAM_CHECK(env->error, str_url, NULL); + + tmp_url_str = axutil_strdup(env, str_url); + if(!tmp_url_str) + { + return NULL; + } + protocol = tmp_url_str; + host = strstr(tmp_url_str, "://"); + if(!host) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_ADDRESS, AXIS2_FAILURE); + + AXIS2_FREE(env->allocator, tmp_url_str); + return NULL; + } + if(axutil_strlen(host) < 3 * sizeof(axis2_char_t)) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_ADDRESS, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Invalid IP or hostname"); + AXIS2_FREE(env->allocator, tmp_url_str); + return NULL; + } + *host = '\0'; + host += 3 * sizeof(axis2_char_t); /* skip "://" part */ + if(axutil_strlen(host) <= 0) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_ADDRESS, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Invalid IP or hostname"); + AXIS2_FREE(env->allocator, tmp_url_str); + return NULL; + } + /* if the url is file:// thing we need the protocol and + * path only + */ + if(0 == axutil_strcasecmp(protocol, (const axis2_char_t *)"file")) + { + ret = axutil_url_create(env, protocol, NULL, 0, host); + AXIS2_FREE(env->allocator, tmp_url_str); + return ret; + } + + port_str = strchr(host, ':'); + if(!port_str) + { + path = strchr(host, '/'); + if(!path) + { + path = strchr(host, '?'); + } + else + { + *path++ = '\0'; + } + if(!path) + { + path = strchr(host, '#'); + } + if(!path) + { + /* No path - assume def path ('/') */ + /* here we have protocol + host + def port + def path */ + ret = axutil_url_create(env, protocol, host, port, "/"); + AXIS2_FREE(env->allocator, tmp_url_str); + return ret; + } + else + { + axis2_char_t *path_temp = NULL; + + path_temp = axutil_strdup(env, path); + *path = '\0'; + /* here we have protocol + host + def port + path */ + ret = axutil_url_create(env, protocol, host, port, path_temp); + AXIS2_FREE(env->allocator, tmp_url_str); + AXIS2_FREE(env->allocator, path_temp); + return ret; + } + } + else + { + *port_str++ = '\0'; + path = strchr(port_str, '/'); + if(!path) + { + path = strchr(port_str, '?'); + if(path) + { + *path = '\0'; + port = AXIS2_ATOI(port_str); + *path = '?'; + } + } + else + { + *path++ = '\0'; + port = AXIS2_ATOI(port_str); + } + if(!path) + { + path = strchr(port_str, '#'); + if(path) + { + *path = '\0'; + port = AXIS2_ATOI(port_str); + *path = '#'; + } + } + if(!path) + { + port = AXIS2_ATOI(port_str); + /* here we have protocol + host + port + def path */ + ret = axutil_url_create(env, protocol, host, port, "/"); + AXIS2_FREE(env->allocator, tmp_url_str); + return ret; + } + else + { + if(axutil_strlen(path) > 0) + { + axis2_char_t *path_temp = NULL; + + path_temp = axutil_strdup(env, path); + *path = '\0'; + /* here we have protocol + host + port + path */ + ret = axutil_url_create(env, protocol, host, port, path_temp); + AXIS2_FREE(env->allocator, tmp_url_str); + AXIS2_FREE(env->allocator, path_temp); + return ret; + } + else + { + /* here we have protocol + host + port + def path */ + ret = axutil_url_create(env, protocol, host, port, "/"); + AXIS2_FREE(env->allocator, tmp_url_str); + return ret; + } + } + } +} + +AXIS2_EXTERN void AXIS2_CALL +axutil_url_free( + axutil_url_t *url, + const axutil_env_t *env) +{ + if(url->protocol) + { + AXIS2_FREE(env->allocator, url->protocol); + url->protocol = NULL; + } + if(url->host) + { + AXIS2_FREE(env->allocator, url->host); + url->host = NULL; + } + if(url->server) + { + AXIS2_FREE(env->allocator, url->server); + url->server = NULL; + } + if(url->path) + { + AXIS2_FREE(env->allocator, url->path); + url->path = NULL; + } + if(url->query) + { + AXIS2_FREE(env->allocator, url->query); + url->query = NULL; + } + AXIS2_FREE(env->allocator, url); + return; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_url_to_external_form( + axutil_url_t *url, + const axutil_env_t *env) +{ + axis2_char_t *external_form = NULL; + axis2_ssize_t len = 0; + axis2_char_t port_str[8]; + axis2_bool_t print_port = AXIS2_FALSE; + AXIS2_PARAM_CHECK(env->error, url, NULL); + + if(!url->protocol) + { + return NULL; + } + + if(url->port != 0 && url->port != axutil_uri_port_of_scheme(url->protocol)) + { + print_port = AXIS2_TRUE; + sprintf(port_str, "%d", url->port); + } + + len = axutil_strlen(url->protocol) + 6; + if(url->host) + { + len += axutil_strlen(url->host); + } + if(url->path) + { + len += axutil_strlen(url->path); + } + if(url->query) + { + len += axutil_strlen(url->query); + } + if(print_port) + { + len += axutil_strlen(port_str) + 1; + } + external_form = (axis2_char_t *)AXIS2_MALLOC(env->allocator, len); + sprintf(external_form, "%s://%s%s%s%s%s", url->protocol, (url->host) ? url->host : "", + (print_port) ? ":" : "", (print_port) ? port_str : "", (url->path) ? url->path : "", + (url->query) ? url->query : ""); + return external_form; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_url_set_protocol( + axutil_url_t *url, + const axutil_env_t *env, + axis2_char_t *protocol) +{ + AXIS2_PARAM_CHECK(env->error, protocol, AXIS2_FAILURE); + if(url->protocol) + { + AXIS2_FREE(env->allocator, url->protocol); + url->protocol = NULL; + } + url->protocol = axutil_strdup(env, protocol); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_url_get_protocol( + axutil_url_t *url, + const axutil_env_t *env) +{ + return url->protocol; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_url_set_host( + axutil_url_t *url, + const axutil_env_t *env, + axis2_char_t *host) +{ + axis2_ssize_t len = 0; + axis2_char_t port_str[8]; + axis2_bool_t print_port = AXIS2_FALSE; + AXIS2_PARAM_CHECK(env->error, host, AXIS2_FAILURE); + + if(url->host) + { + AXIS2_FREE(env->allocator, url->host); + } + url->host = axutil_strdup(env, host); + if(url->server) + { + AXIS2_FREE(env->allocator, url->server); + } + if(!url->host) + { + return AXIS2_SUCCESS; + } + len += axutil_strlen(url->host); + if(url->port != 0 && (!url->protocol || url->port != axutil_uri_port_of_scheme(url->protocol))) + { + print_port = AXIS2_TRUE; + sprintf(port_str, "%d", url->port); + len += axutil_strlen(port_str) + 1; + } + url->server = (axis2_char_t *)AXIS2_MALLOC(env->allocator, len); + sprintf(url->server, "%s%s%s", url->host, (print_port) ? ":" : "", (print_port) ? port_str : ""); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_url_get_host( + axutil_url_t *url, + const axutil_env_t *env) +{ + return url->host; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_url_set_server( + axutil_url_t *url, + const axutil_env_t *env, + axis2_char_t *server) +{ + axis2_char_t *temp = NULL; + axis2_char_t *port_str = NULL; + AXIS2_PARAM_CHECK(env->error, server, AXIS2_FAILURE); + + temp = axutil_strdup(env, server); + if(temp && *temp == ':') + { + AXIS2_FREE(env->allocator, temp); + return AXIS2_FAILURE; + } + + if(strchr(temp, '/')) + { + AXIS2_FREE(env->allocator, temp); + return AXIS2_FAILURE; + } + + if(url->server) + { + AXIS2_FREE(env->allocator, url->server); + } + if(url->host) + { + AXIS2_FREE(env->allocator, url->host); + } + url->port = 0; + + url->server = axutil_strdup(env, server); + + port_str = strchr(temp, ':'); + if(port_str) + { + *port_str++ = '\0'; + url->port = AXIS2_ATOI(port_str); + } + + url->host = axutil_strdup(env, temp); + AXIS2_FREE(env->allocator, temp); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_url_get_server( + axutil_url_t *url, + const axutil_env_t *env) +{ + axis2_ssize_t len = 0; + axis2_char_t port_str[8]; + axis2_bool_t print_port = AXIS2_FALSE; + + if(!url->server && !url->host) + { + return NULL; + } + else if(!url->host) + { + AXIS2_FREE(env->allocator, url->server); + url->server = NULL; + return NULL; + } + else if(url->server) + { + return url->server; + } + len += axutil_strlen(url->host); + if(url->port != 0 && (!url->protocol || url->port != axutil_uri_port_of_scheme(url->protocol))) + { + print_port = AXIS2_TRUE; + sprintf(port_str, "%d", url->port); + len += axutil_strlen(port_str) + 1; /* +1 is for ':' */ + } + url->server = (axis2_char_t *)AXIS2_MALLOC(env->allocator, len + 1); /* +1 is for '/0' */ + sprintf(url->server, "%s%s%s", url->host, (print_port) ? ":" : "", (print_port) ? port_str : ""); + return url->server; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_url_set_port( + axutil_url_t *url, + const axutil_env_t *env, + int port) +{ + axis2_ssize_t len = 0; + axis2_char_t port_str[8]; + axis2_bool_t print_port = AXIS2_FALSE; + if(url->port == port) + { + return AXIS2_SUCCESS; + } + url->port = port; + if(url->server) + { + AXIS2_FREE(env->allocator, url->server); + } + if(!url->host) + { + return AXIS2_SUCCESS; + } + len += axutil_strlen(url->host); + if(url->port != 0 && (!url->protocol || url->port != axutil_uri_port_of_scheme(url->protocol))) + { + print_port = AXIS2_TRUE; + sprintf(port_str, "%d", url->port); + len += axutil_strlen(port_str) + 1; + } + url->server = (axis2_char_t *)AXIS2_MALLOC(env->allocator, len); + sprintf(url->server, "%s%s%s", url->host, (print_port) ? ":" : "", (print_port) ? port_str : ""); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_url_get_port( + axutil_url_t *url, + const axutil_env_t *env) +{ + if(!url->port) + { + return axutil_uri_port_of_scheme(url->protocol); + } + return url->port; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_url_set_path( + axutil_url_t *url, + const axutil_env_t *env, + axis2_char_t * path) +{ + AXIS2_PARAM_CHECK(env->error, path, AXIS2_FAILURE); + if(url->path) + { + AXIS2_FREE(env->allocator, url->path); + } + url->path = axutil_strdup(env, path); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_url_get_path( + axutil_url_t *url, + const axutil_env_t *env) +{ + return url->path; +} + +AXIS2_EXTERN axutil_url_t *AXIS2_CALL +axutil_url_clone( + axutil_url_t *url, + const axutil_env_t *env) +{ + axis2_char_t *temp = NULL; + axutil_url_t *ret = NULL; + + if(url->path && url->query) + { + temp = axutil_stracat(env, url->path, url->query); + } + else if(url->path) + { + temp = axutil_strdup(env, url->path); + } + else if(url->query) + { + temp = axutil_strdup(env, url->query); + } + + ret = axutil_url_create(env, url->protocol, url->host, url->port, url->path); + if(temp) + { + AXIS2_FREE(env->allocator, temp); + } + return ret; +} + +AXIS2_EXTERN axutil_uri_t *AXIS2_CALL +axutil_url_to_uri( + axutil_url_t *url, + const axutil_env_t *env) +{ + axis2_char_t *url_str = NULL; + axutil_uri_t *uri = NULL; + url_str = axutil_url_to_external_form(url, env); + uri = axutil_uri_parse_string(env, url_str); + return uri; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_url_encode( + const axutil_env_t *env, + axis2_char_t *dest, + axis2_char_t *buff, + int len) +{ + axis2_char_t string[4]; + axis2_char_t *expand_buffer = NULL; + axis2_char_t *temp = NULL; + int i; + for(i = 0; i < len && buff[i]; i++) + { + if(isalnum(buff[i]) || is_safe_or_unreserve(buff[i])) + { + sprintf(string, "%c", buff[i]); + } + else + { + /* %%%x is to print % mark with the hex value */ + sprintf(string, "%%%x", buff[i]); + } + + if(((int)strlen(dest) + 4) > len) + { + expand_buffer = (axis2_char_t *)AXIS2_MALLOC(env->allocator, len * 2); + memset(expand_buffer, 0, len * 2); + len *= 2; + temp = memmove(expand_buffer, dest, strlen(dest)); + if(dest) + { + AXIS2_FREE(env->allocator, dest); + dest = NULL; + } + dest = temp; + } + strcat(dest, string); + } + return dest; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_url_get_query( + axutil_url_t *url, + const axutil_env_t *env) +{ + return url->query; +} + +static int +is_safe_or_unreserve( + char c) +{ + char safe[] = { '-', '_', '.', '~' }; + char reserve[] = { ';', '/', '?', ':', '@', '&', '=', '#', '[', ']', '!', '$', '\'', '(', ')', + '*', '+', ',' }; + + /* These are reserved and safe charaters , got from RFC + * + * reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" + * safe = "$" | "-" | "_" | "." | "+" + */ + + int flag = 0; + int i = 0; + + int size = sizeof(safe) / sizeof(safe[0]); + for(i = 0; i < size; i++) + { + if(c == safe[i]) + { + flag = 1; + return flag; + } + } + + size = sizeof(reserve) / sizeof(reserve[0]); + for(i = 0; i < size; i++) + { + if(c == reserve[i]) + { + flag = 0; + return flag; + } + } + return flag; +} diff --git a/util/src/utils.c b/util/src/utils.c new file mode 100644 index 0000000..c69b948 --- /dev/null +++ b/util/src/utils.c @@ -0,0 +1,607 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_utils.h> +#include <stdlib.h> +#include <axutil_string.h> +#include <string.h> +#include <platforms/axutil_platform_auto_sense.h> + +AXIS2_EXPORT axis2_char_t *axis2_request_url_prefix = "services"; + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_parse_rest_url_for_params( + const axutil_env_t *env, + const axis2_char_t *tmpl, + const axis2_char_t *url, + int *match_count, + axis2_char_t ****matches) +{ + axis2_char_t ***ret = NULL; + axis2_char_t *tmp1 = NULL; + axis2_char_t **tmp2 = NULL; + axis2_char_t ***tmp3 = NULL; + axis2_char_t *tmp4 = NULL; + axis2_char_t *resource = NULL; + axis2_char_t *query = NULL; + axis2_char_t *url_tmp = NULL; + axis2_char_t *url_resource = NULL; + axis2_char_t *url_query = NULL; + axis2_bool_t finished = AXIS2_FALSE; + axis2_status_t status = AXIS2_FAILURE; + int ret_count = 0; + int i = 0; + int j = 0; + axis2_bool_t in_tok = AXIS2_FALSE; + + tmp2 = AXIS2_MALLOC(env->allocator, 2 * (sizeof(axis2_char_t *))); + memset(tmp2, 0, 2 * sizeof(axis2_char_t *)); + + if(tmpl[0] == '/') + { + tmp1 = (axis2_char_t *)tmpl; + tmp1++; + resource = axutil_strdup(env, tmp1); + } + else + { + resource = axutil_strdup(env, tmpl); + } + i = (int)strlen(resource); + /* We are sure that the difference lies within the int range */ + if(resource[i] == '/') + { + resource[i] = '\0'; + } + tmp1 = strchr(resource, '?'); + if(tmp1) + { + axis2_char_t *tmp4 = NULL; + + tmp4 = tmp1; + tmp1++; + resource[tmp4 - resource] = '\0'; + if(*tmp1 && ((tmp1 - resource) < (int)strlen(resource) - 1)) + /* We are sure that the difference lies within the int range */ + { + query = tmp1; + /* + * Query String based matching is not implemented. This is + * reserved for future implementations. + */ + } + } + + /* Validation of Template */ + i = (int)strlen(resource); + /* We are sure that the difference lies within the int range */ + + if(!strchr(resource, '{') && !strchr(resource, '}')) + { + i = 0; + } + for(j = 0; j < i; j++) + { + if(!in_tok) + { + if(resource[j] == '}') + { + AXIS2_FREE(env->allocator, resource); + return AXIS2_FAILURE; + } + else if(resource[j] == '{') + { + if(j + 1 == i || resource[j + 1] == '}') + { + AXIS2_FREE(env->allocator, resource); + return AXIS2_FAILURE; + } + else if(resource[j + 1] == '{') + { + j++; + } + else + { + in_tok = AXIS2_TRUE; + } + } + } + else + { + if(resource[j] == '{') + { + AXIS2_FREE(env->allocator, resource); + return AXIS2_FAILURE; + } + else if(resource[j] == '}') + { + if(j + 1 < i && resource[j + 1] == '}') + { + j++; + } + else + { + in_tok = AXIS2_FALSE; + } + } + } + } + if(in_tok) + { + AXIS2_FREE(env->allocator, resource); + return AXIS2_FAILURE; + } + + /* Validity of template guaranteed if not returned */ + + if(url[0] == '/') + { + tmp1 = (axis2_char_t *)url; + tmp1++; + url_resource = axutil_strdup(env, tmp1); + } + else + { + url_resource = axutil_strdup(env, url); + } + i = (int)strlen(url_resource); + + /* We are sure that the difference lies within the int range */ + + if(url_resource[i] == '/') + { + url_resource[i] = '\0'; + } + i = 0; + url_tmp = url_resource; + tmp1 = strchr(url_resource, '?'); + if(tmp1) + { + axis2_char_t *tmp4 = NULL; + + tmp4 = tmp1; + tmp1++; + url_resource[tmp4 - url_resource] = '\0'; + if(*tmp1 && ((tmp1 - url_resource) < (int)strlen(url_resource) - 1)) + /* We are sure that the difference lies within the int range */ + { + url_query = tmp1; + } + } + tmp1 = resource; + + /* Simplest case match */ + + if(!strchr(resource, '{')) + { + if(strcmp(resource, url_resource) == 0) + { + finished = AXIS2_TRUE; + } + } + + while(!finished) + { + tmp4 = strchr(tmp1, '{'); + if(tmp4 && tmp4[1]) + { + if(tmp4[1] != '{') + { + axis2_char_t *tmp5 = NULL; + axis2_char_t *tmp6 = NULL; + axis2_char_t *tmp7 = NULL; + axis2_char_t *tmp8 = NULL; + axis2_char_t *tmp9 = NULL; + + /* Logic for finding out constant portion to match */ + i = (int)(tmp4 - tmp1); + tmp2[0] = AXIS2_MALLOC(env->allocator, (i + 1) * sizeof(char)); + strncpy(tmp2[0], tmp1, i); + tmp2[0][i] = '\0'; + if(url_tmp && *url_tmp) + { + tmp6 = url_tmp; + tmp5 = strstr(tmp6, tmp2[0]); + if(tmp5) + { + tmp5 += strlen(tmp2[0]); + tmp7 = tmp4; + tmp8 = tmp4; + tmp7++; + if(*tmp7) + { + axis2_bool_t finished_tmp = AXIS2_FALSE; + while(!finished_tmp) + { + tmp6 = strchr(tmp8, '}'); + if(tmp6 && *tmp6) + { + if(tmp6[1] != '}') + { + tmp8 = tmp6 + 1; + break; + } + } + else + { + finished_tmp = AXIS2_TRUE; + } + } + if(!finished_tmp && !strchr(tmp8, '{')) + { + tmp7 = tmp8 + strlen(tmp8); + } + else + { + while(!finished_tmp) + { + tmp6 = strchr(tmp8, '{'); + if(tmp6 && tmp6[1]) + { + if(tmp6[1] != '{') + { + tmp7 = tmp6; + break; + } + } + else + { + finished_tmp = AXIS2_TRUE; + } + } + } + if(!finished_tmp) + { + i = (int)(tmp7 - tmp8); + tmp9 = AXIS2_MALLOC(env->allocator, (i + 1) * sizeof(char)); + strncpy(tmp9, tmp8, i); + tmp9[i] = '\0'; + } + } + if(tmp9 && *tmp9) + { + tmp6 = strstr(tmp5, tmp9); + AXIS2_FREE(env->allocator, tmp9); + tmp9 = NULL; + } + else + { + tmp6 = strchr(tmp5, '/'); + } + /* Logic for saving the match */ + if(tmp6 && tmp6 != tmp5) + { + i = (int)(tmp6 - tmp5); + url_tmp = tmp6; + tmp2[1] = AXIS2_MALLOC(env->allocator, (i + 1) * sizeof(char)); + strncpy(tmp2[1], tmp5, i); + tmp2[1][i] = '\0'; + } + else + { + i = (int)strlen(tmp5); + /* We are sure that the difference lies within the int range */ + tmp2[1] = AXIS2_MALLOC(env->allocator, (i + 1) * sizeof(char)); + strncpy(tmp2[1], tmp5, i); + tmp2[1][i] = '\0'; + url_tmp = NULL; + } + } + } + else + { + break; + } + while(!finished) + { + tmp1 = tmp4 + 1; + tmp4 = strchr(tmp1, '}'); + if(tmp4 && *tmp4) + { + if(tmp4[1] != '}') + { + /* Logic for saving the key for the match */ + i = (int)(tmp4 - tmp1); + if(tmp2[0]) + { + AXIS2_FREE(env->allocator, tmp2[0]); + } + tmp2[0] = AXIS2_MALLOC(env->allocator, (i + 1) * sizeof(char)); + strncpy(tmp2[0], tmp1, i); + tmp2[0][i] = '\0'; + tmp3 = ret; + ret_count++; + ret = AXIS2_MALLOC(env->allocator, ret_count * 2 + * (sizeof(axis2_char_t *))); + memset(ret, 0, ret_count * 2 * sizeof(axis2_char_t *)); + for(i = 0; i < ret_count - 1; i++) + { + ret[i] = tmp3[i]; + } + ret[i] = tmp2; + tmp2 = AXIS2_MALLOC(env->allocator, 2 * (sizeof(axis2_char_t *))); + memset(tmp2, 0, 2 * sizeof(axis2_char_t *)); + tmp3 = NULL; + break; + } + else + { + tmp4++; + } + } + else + { + finished = AXIS2_TRUE; + } + } + } + else + { + tmp4++; + } + } + else + { + /* Result of mismatch at the simplest case */ + if(!strchr(resource, '{')) + { + finished = AXIS2_FALSE; + break; + } + finished = AXIS2_TRUE; + } + tmp1 = tmp4 + 1; + } + if(resource) + { + AXIS2_FREE(env->allocator, resource); + } + if(url_resource) + { + AXIS2_FREE(env->allocator, url_resource); + } + if(tmp2) + { + if(tmp2[0]) + { + AXIS2_FREE(env->allocator, tmp2[0]); + } + if(tmp2[1]) + { + AXIS2_FREE(env->allocator, tmp2[1]); + } + AXIS2_FREE(env->allocator, tmp2); + } + if(finished) + { + status = AXIS2_SUCCESS; + } + *match_count = ret_count; + *matches = ret; + return status; +} + +AXIS2_EXTERN axis2_char_t **AXIS2_CALL +axutil_parse_request_url_for_svc_and_op( + const axutil_env_t *env, + const axis2_char_t *request) +{ + axis2_char_t **ret = NULL; + axis2_char_t *service_str = NULL; + axis2_char_t *tmp = NULL; + int i = 0; + ret = AXIS2_MALLOC(env->allocator, 2 * (sizeof(axis2_char_t *))); + memset(ret, 0, 2 * sizeof(axis2_char_t *)); + tmp = (axis2_char_t *)request; + + tmp = strstr(tmp, axis2_request_url_prefix); + if(tmp) + { + service_str = tmp; + tmp += axutil_strlen(axis2_request_url_prefix); + /*break stop on first prefix as user may have prefix in service name */ + } + if(service_str) + { + service_str += axutil_strlen(axis2_request_url_prefix); + if('\0' != *service_str) + { + if(*service_str == '/') + service_str++; /*to remove the leading '/' */ + tmp = strchr(service_str, '/'); + if(tmp) + { + i = (int)(tmp - service_str); + ret[0] = AXIS2_MALLOC(env->allocator, i * sizeof(char) + 1); + strncpy(ret[0], service_str, i); + ret[0][i] = '\0'; + + /* Now search for the op */ + service_str = tmp; + if('\0' != *service_str) + { + service_str++; + tmp = strchr(service_str, '?'); + if(tmp) + { + i = (int)(tmp - service_str); + ret[1] = AXIS2_MALLOC(env->allocator, i * sizeof(char) + 1); + strncpy(ret[1], service_str, i); + ret[1][i] = '\0'; + } + else + { + ret[1] = axutil_strdup(env, service_str); + } + } + } + else + { + ret[0] = axutil_strdup(env, service_str); + } + } + } + return ret; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_xml_quote_string( + const axutil_env_t *env, + const axis2_char_t *s, + axis2_bool_t quotes) +{ + const char *scan; + size_t len = 0; + size_t extra = 0; + char *qstr; + char *qscan; + char c; + + for(scan = s; (c = *scan) != '\0'; ++scan, ++len) + { + if(c == '<' || c == '>') + extra += 3; /* < or > */ + else if(c == '&') + extra += 4; /* & */ + else if(quotes && c == '"') + extra += 5; /* " */ + } + + /* nothing to do */ + if(extra == 0) + return NULL; + + qstr = AXIS2_MALLOC(env->allocator, len + extra + 1); + for(scan = s, qscan = qstr; (c = *scan) != '\0'; ++scan) + { + if(c == '<') + { + *qscan++ = '&'; + *qscan++ = 'l'; + *qscan++ = 't'; + *qscan++ = ';'; + } + else if(c == '>') + { + *qscan++ = '&'; + *qscan++ = 'g'; + *qscan++ = 't'; + *qscan++ = ';'; + } + else if(c == '&') + { + *qscan++ = '&'; + *qscan++ = 'a'; + *qscan++ = 'm'; + *qscan++ = 'p'; + *qscan++ = ';'; + } + else if(quotes && c == '"') + { + *qscan++ = '&'; + *qscan++ = 'q'; + *qscan++ = 'u'; + *qscan++ = 'o'; + *qscan++ = 't'; + *qscan++ = ';'; + } + else + { + *qscan++ = c; + } + } + + *qscan = '\0'; + return qstr; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axutil_url_decode( + const axutil_env_t *env, + axis2_char_t *dest, + axis2_char_t *src) +{ + AXIS2_PARAM_CHECK(env->error, dest, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, src, AXIS2_FAILURE); + + for(; *src != '\0'; ++dest, ++src) + { + if(src[0] == '%' && isxdigit(src[1]) && isxdigit(src[2])) + { + *dest = (axis2_char_t)(axutil_hexit(src[1]) * 16 + axutil_hexit(src[2])); + /* We are sure that the conversion is safe */ + src += 2; + } + else + { + *dest = *src; + } + } + *dest = '\0'; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_hexit( + axis2_char_t c) +{ + if(c >= '0' && c <= '9') + { + return c - '0'; + } + if(c >= 'a' && c <= 'f') + { + return c - 'a' + 10; + } + if(c >= 'A' && c <= 'F') + { + return c - 'A' + 10; + } + return 0; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_char_2_byte( + const axutil_env_t *env, + axis2_char_t *char_buffer, + axis2_byte_t **byte_buffer, + int *byte_buffer_size) +{ + int length = 0; + int i = 0; + axis2_byte_t *bytes = NULL; + + length = (int)axutil_strlen(char_buffer); + bytes = (axis2_byte_t *)AXIS2_MALLOC(env->allocator, length * sizeof(axis2_byte_t)); + + if(!bytes) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create byte buffer"); + return AXIS2_FAILURE; + } + + for(i = 0; i < length; i++) + { + bytes[i] = (axis2_byte_t)char_buffer[i]; + } + *byte_buffer = bytes; + *byte_buffer_size = length; + return AXIS2_SUCCESS; +} + diff --git a/util/src/uuid_gen.c b/util/src/uuid_gen.c new file mode 100644 index 0000000..945b295 --- /dev/null +++ b/util/src/uuid_gen.c @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_uuid_gen.h> + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axutil_uuid_gen( + const axutil_env_t *env) +{ + + axis2_char_t *str = AXIS2_MALLOC(env->allocator, 40 * sizeof(char)); + axutil_platform_uuid_gen(str); + if(!str) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_UUID_GEN_FAILED, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "AXIS2_ERROR_UUID_GEN_FAILED"); + return NULL; + } + return str; +} diff --git a/util/src/version.c b/util/src/version.c new file mode 100644 index 0000000..9ab586d --- /dev/null +++ b/util/src/version.c @@ -0,0 +1,39 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <axutil_version.h> + +AXIS2_EXTERN void AXIS2_CALL +axis2_version( + axis2_version_t *pvsn) +{ + pvsn->major = AXIS2_MAJOR_VERSION; + pvsn->minor = AXIS2_MINOR_VERSION; + pvsn->patch = AXIS2_PATCH_VERSION; +#ifdef AXIS2_IS_DEV_VERSION + pvsn->is_dev = 1; +#else + pvsn->is_dev = 0; +#endif +} + +AXIS2_EXTERN const char *AXIS2_CALL +axis2_version_string( + void) +{ + return AXIS2_VERSION_STRING; +} diff --git a/util/test/Makefile.am b/util/test/Makefile.am new file mode 100644 index 0000000..cfbf7f6 --- /dev/null +++ b/util/test/Makefile.am @@ -0,0 +1,2 @@ +SUBDIRS = util allocator date_time duration link_list properties rand stack string_util uri url utils + diff --git a/util/test/allocator/Makefile.am b/util/test/allocator/Makefile.am new file mode 100644 index 0000000..02dfa27 --- /dev/null +++ b/util/test/allocator/Makefile.am @@ -0,0 +1,13 @@ +TESTS = allocator_test +check_PROGRAMS = allocator_test +noinst_PROGRAMS = allocator_test +allocator_test_SOURCES = allocator_test.c ../util/create_env.c + +allocator_test_LDADD = \ + $(top_builddir)/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../axiom/include \ + -I ../../../include + + diff --git a/util/test/allocator/allocator_test.c b/util/test/allocator/allocator_test.c new file mode 100644 index 0000000..70e0bad --- /dev/null +++ b/util/test/allocator/allocator_test.c @@ -0,0 +1,147 @@ +#include <axutil_log_default.h> +#include <axutil_error_default.h> +#include <axiom_node.h> +#include <stdio.h> +#include "../util/create_env.h" + +int plain_binary_len; +unsigned char *plain_binary ; + +/** @brief read binary + * read the binary file + */ + +int read_binary() +{ + unsigned char buffer[1024]; + FILE *in = fopen("test","rb"); + FILE *out = fopen("test.doc","w"); + int fwrite_result = 0; + + if (!(in && out)) + { + fprintf (stderr, "unable to open streams\n"); + return -1; + } + + while((plain_binary_len = fread(buffer,1,sizeof(buffer),in)) > 0) + { + fwrite_result = fwrite(buffer,1,plain_binary_len,out); + } + + fclose(in); + fclose(out); + plain_binary = buffer; + printf("%s",buffer); + return plain_binary_len; +} + +/** @brief test base64 + * create duration from values and retrieve values + */ +axis2_status_t test_base64(axutil_env_t *env) +{ + axis2_status_t status = AXIS2_FAILURE; + axutil_base64_binary_t *base64_binary; + axutil_base64_binary_t *plain_base64_binary; + const char *encoded_binary; + char * get_binary = NULL; + int binary_len; + unsigned char * plain_binary = NULL; + read_binary(); + + base64_binary = axutil_base64_binary_create(env); + if(!base64_binary) + { + printf("The test axutil_base64_binary_create is failed\n"); + axutil_base64_binary_free(base64_binary,env); + return AXIS2_FAILURE; + } + else + printf("The test axutil_base64_binary_create is successfull\n"); + + plain_base64_binary = axutil_base64_binary_create_with_plain_binary(env, + plain_binary, + plain_binary_len); + if(!plain_base64_binary) + { + printf("The test axutil_base64_binary_create_with_plain_binary is failed\n"); + axutil_base64_binary_free(plain_base64_binary,env); + } + else + printf("The test axutil_base64_binary_create_with_plain_binary is successfull\n"); + + encoded_binary = axutil_base64_binary_get_encoded_binary(base64_binary,env); + if(!encoded_binary) + { + printf("The test axutil_base64_binary_get_encoded_binary is failed\n"); + axutil_base64_binary_free(base64_binary,env); + } + else + printf("The test axutil_base64_binary_get_encoded_binary is successfull\n"); + + status = axutil_base64_binary_set_plain_binary(base64_binary,env,plain_binary, + plain_binary_len); + if (status == AXIS2_SUCCESS) + printf("The test axutil_base64_binary_set_plain_binary is successful\n"); + else + printf("The test axutil_base64_binary_set_plain_binary failed\n") ; + + plain_binary = axutil_base64_binary_get_plain_binary(base64_binary,env,&plain_binary_len); + if(!plain_binary) + { + printf("The test axutil_base64_binary_get_plain_binary is failed\n"); + axutil_base64_binary_free(base64_binary,env); + } + else + printf("The test axutil_base64_binary_get_plain_binary is successfull\n" ); + + status = axutil_base64_binary_set_encoded_binary(base64_binary,env,encoded_binary); + if (status == AXIS2_SUCCESS) + printf("The test axutil_base64_binary_set_encoded_binary is successful\n"); + else + printf("The test axutil_base64_binary_set_encoded_binary failed\n"); + + get_binary = axutil_base64_binary_get_encoded_binary(base64_binary,env); + if(!get_binary) + { + printf("The test axutil_base64_binary_get_encoded_binary is failed\n"); + axutil_base64_binary_free(base64_binary,env); + } + else + printf("The test axutil_base64_binary_get_encoded_binary is successfull\n"); + + binary_len = axutil_base64_binary_get_encoded_binary_len(base64_binary,env); + if(!binary_len) + { + printf("The test axutil_base64_binary_get_encoded_binary_len is failed\n"); + axutil_base64_binary_free(base64_binary,env); + } + else + printf("The test axutil_base64_binary_get_encoded_binary_len is successfull\n"); + + return AXIS2_SUCCESS; +} + +int main() +{ + int status = AXIS2_SUCCESS; + axutil_env_t *env = NULL; + env = create_environment(); + status = test_base64(env); + + if(status == AXIS2_FAILURE) + { + printf("build failed"); + } + axutil_env_free(env); + return 0; +} + + + + + + + + diff --git a/util/test/allocator/build.sh b/util/test/allocator/build.sh new file mode 100644 index 0000000..e5dabf2 --- /dev/null +++ b/util/test/allocator/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +gcc allocator_test.c ../util/create_env.c -g -I$AXIS2C_HOME/include/axis2-1.2 -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -o allocator_test diff --git a/util/test/allocator/test b/util/test/allocator/test Binary files differnew file mode 100755 index 0000000..919cd65 --- /dev/null +++ b/util/test/allocator/test diff --git a/util/test/allocator/test.doc b/util/test/allocator/test.doc Binary files differnew file mode 100644 index 0000000..919cd65 --- /dev/null +++ b/util/test/allocator/test.doc diff --git a/util/test/date_time/Makefile.am b/util/test/date_time/Makefile.am new file mode 100644 index 0000000..08d90d7 --- /dev/null +++ b/util/test/date_time/Makefile.am @@ -0,0 +1,13 @@ +TESTS = date_time_test +noinst_PROGRAMS = date_time_test +check_PROGRAMS = date_time_test +date_time_test_SOURCES = date_time_test.c ../util/create_env.c + +date_time_test_LDADD = \ + $(top_builddir)/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../axiom/include \ + -I ../../../include + + diff --git a/util/test/date_time/build.sh b/util/test/date_time/build.sh new file mode 100644 index 0000000..5236acd --- /dev/null +++ b/util/test/date_time/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +gcc date_time_test.c ../util/create_env.c -g -I$AXIS2C_HOME/include/axis2-1.3.0 -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -o date_time_test -ldl -Wl,--rpath -Wl,$AXIS2C_HOME/lib diff --git a/util/test/date_time/date_time_test.c b/util/test/date_time/date_time_test.c new file mode 100644 index 0000000..553fada --- /dev/null +++ b/util/test/date_time/date_time_test.c @@ -0,0 +1,138 @@ +#include <axutil_date_time.h> +#include <time.h> +#include <axutil_date_time_util.h> +#include <stdio.h> +#include <axutil_env.h> +#include "../util/create_env.h" + +/** @brief test_rand + * * deserialize and serialize the time + * */ + +axis2_status_t test_date_time(axutil_env_t *env) +{ + axutil_date_time_t *date_time = NULL; + axutil_date_time_t *ref = NULL; + axutil_date_time_t *date_time_offset = NULL; + axis2_char_t *time_str = "22:45:12"; + axis2_char_t *date_str = "2000-12-12"; + axis2_char_t *date_time_str = "2000-11-11T12:30:24"; + axis2_status_t status = AXIS2_FAILURE; + axutil_date_time_comp_result_t compare_res = AXIS2_DATE_TIME_COMP_RES_FAILURE; + axis2_char_t *t_str = NULL, *d_str = NULL, *dt_str = NULL; + int year , month , date , hour , min , sec , msec; + + date_time_offset = axutil_date_time_create_with_offset(env, 100); + if(!date_time_offset) + { + printf("axutil_date_time_t creation failed.\n"); + return AXIS2_FAILURE; + } + date_time = axutil_date_time_create(env); + if(!date_time) + { + printf("axutil_date_time_t creation failed.\n"); + return AXIS2_FAILURE; + } + status = axutil_date_time_deserialize_time(date_time, env, time_str); + if(status) + printf("axutil_date_time_t time string deserialization success.\n"); + status = axutil_date_time_deserialize_date(date_time, env, date_str); + if(status) + printf("axutil_date_time_t date string deserialization success.\n"); + status = axutil_date_time_deserialize_date_time(date_time, env, date_time_str); + if(status) + printf("axutil_date_time_t date time string deserialization success.\n"); + + ref = axutil_date_time_create(env); + if(!ref) + { + printf("axutil_date_time_t creation failed.\n"); + return AXIS2_FAILURE; + } + compare_res = axutil_date_time_compare(date_time, env, ref); + if(compare_res == AXIS2_DATE_TIME_COMP_RES_FAILURE) + { + printf("axutil_date_time comparison failed.\n"); + } + + status = axutil_date_time_deserialize_date_time(ref, env, date_time_str); + if(status) + printf("axutil_date_time_t date time string deserialization success.\n"); + compare_res = axutil_date_time_compare(date_time, env, ref); + if(compare_res == AXIS2_DATE_TIME_COMP_RES_EQUAL) + { + printf("axutil_date_time_t comparison success."); + } + status = axutil_date_time_set_date_time(date_time, env, 2008, 1, 8, 12, 18, 57, 799); + if(status) + { + printf("axutil_date_time_t set date time success.\n"); + } + + t_str = axutil_date_time_serialize_time(date_time, env); + if(!t_str) + { + printf("axutil_date_time_t time serialization failed.\n"); + } + else + { + printf("axutil_date_time_t Time: %s\n", t_str); + } + d_str = axutil_date_time_serialize_date(date_time, env); + if(!d_str) + { + printf("axutil_date_time_t date serialization failed.\n"); + } + else + { + printf("axutil_date_time_t Date: %s\n", d_str); + } + dt_str = axutil_date_time_serialize_date_time(date_time, env); + if(!dt_str) + { + printf("axutil_date_time_t date time serialization failed.\n"); + } + else + { + printf("axutil_date_time_t Date Time: %s\n", dt_str); + } + year = axutil_date_time_get_year(date_time,env); + month=axutil_date_time_get_month(date_time,env); + date = axutil_date_time_get_date(date_time,env); + hour = axutil_date_time_get_hour(date_time,env); + min = axutil_date_time_get_minute(date_time,env); + sec = axutil_date_time_get_second(date_time,env); + msec = axutil_date_time_get_msec(date_time,env); + printf("axutil_date_time_t year: %d \n",year); + printf("axutil_date_time_t month: %d \n",month); + printf("axutil_date_time_t date: %d \n",date); + printf("axutil_date_time_t hour: %d \n",hour); + printf("axutil_date_time_t min: %d \n",min); + printf("axutil_date_time_t sec: %d \n",sec); + printf("axutil_date_time_t msec: %d \n",msec); + + axutil_date_time_free(date_time,env); + axutil_date_time_free(ref, env); + axutil_date_time_free(date_time_offset, env); + return AXIS2_SUCCESS; +} + +int main() +{ + axutil_env_t *env = NULL; + int status = AXIS2_SUCCESS; + env = create_environment(); + status = test_date_time(env); + if(status != AXIS2_SUCCESS) + { + printf("axutil_date_time_t test failed"); + } + else + { + printf("axutil_date_time_t test successful"); + } + axutil_env_free(env); + return 0; +} + diff --git a/util/test/duration/Makefile.am b/util/test/duration/Makefile.am new file mode 100644 index 0000000..cab6dcd --- /dev/null +++ b/util/test/duration/Makefile.am @@ -0,0 +1,13 @@ +TESTS = duration_test +check_PROGRAMS = duration_test +noinst_PROGRAMS = duration_test +duration_test_SOURCES = duration_test.c ../util/create_env.c + +duration_test_LDADD = \ + $(top_builddir)/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../axiom/include \ + -I ../../../include + + diff --git a/util/test/duration/build.sh b/util/test/duration/build.sh new file mode 100644 index 0000000..ef2771e --- /dev/null +++ b/util/test/duration/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +gcc duration_test.c ../util/create_env.c -g -I$AXIS2C_HOME/include/axis2-1.3.0 -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -o duration_test -ldl -Wl,--rpath -Wl,$AXIS2C_HOME/lib diff --git a/util/test/duration/duration_test.c b/util/test/duration/duration_test.c new file mode 100644 index 0000000..c3fafe3 --- /dev/null +++ b/util/test/duration/duration_test.c @@ -0,0 +1,172 @@ +#include <axutil_duration.h> +#include "../util/create_env.h" + +/** @brief test duration + * create duration from values and retrieve values + */ +axis2_status_t test_duration(axutil_env_t *env) +{ + axis2_status_t status = AXIS2_FAILURE; + axis2_char_t * duration_str = "P3Y12M23DT11H45M45.000000S"; + axis2_char_t * duration_str1 = "-P3Y12M23DT11H45M45.000000S"; + int year,month,day,hour,minute; + double second; + axutil_duration_t * duration; + axutil_duration_t * duration_one; + axutil_duration_t * duration_two; + axutil_duration_t * duration_three; + axutil_duration_t * duration_four; + axis2_bool_t is_negative = AXIS2_FALSE; + axis2_char_t * neg_str = ""; + + duration = axutil_duration_create_from_values(env,AXIS2_TRUE,3,12,23,11,45,45.00); + duration_one = axutil_duration_create_from_values(env,AXIS2_FALSE,7,11,2,23,11,50.00); + duration_two = axutil_duration_create_from_string(env,duration_str); + duration_three = axutil_duration_create(env); + duration_four = axutil_duration_create(env); + + year = axutil_duration_get_years(duration,env); + month = axutil_duration_get_months(duration,env); + day = axutil_duration_get_days(duration,env); + hour = axutil_duration_get_hours(duration,env); + minute = axutil_duration_get_mins(duration,env); + second = axutil_duration_get_seconds(duration,env); + is_negative = axutil_duration_get_is_negative(duration,env); + + status = axutil_duration_deserialize_duration(duration_three,env,duration_str); + if (status == AXIS2_SUCCESS) + printf("The test 1 is successful\n"); + else + printf("The test 1 failed\n"); + status = axutil_duration_deserialize_duration(duration_four,env,duration_str1); + if (status == AXIS2_SUCCESS) + printf("The test 2 is successful\n"); + else + printf("The test 2 failed\n"); + printf("Duration for test 3: %s\n", axutil_duration_serialize_duration(duration,env)); + printf("The test 3 is completed\n"); + status = axutil_duration_set_duration(duration,env,AXIS2_TRUE,3,12,23,11,45,56.00); + if (status == AXIS2_SUCCESS) + { + printf("The test 4 is successful\n"); + } + else + { + printf("The test 4 failed\n"); + } + axutil_duration_free(duration,env); + axutil_duration_free(duration_one,env); + axutil_duration_free(duration_two,env); + axutil_duration_free(duration_three,env); + axutil_duration_free(duration_four,env); + if (is_negative) + neg_str = "(-) "; + printf("Duration for test 5: %s%d-%d-%d %d:%d:%.0f\n",neg_str,year,month,day,hour,minute,second); + printf("The test 5 is completed\n"); + return AXIS2_SUCCESS; +} + +/** @brief set values + * set values for the duration and get the values + */ +axis2_status_t set_values(axutil_env_t *env) +{ + axutil_duration_t * duration; + axutil_duration_t * duration_one; + int get_year,get_month,get_day,get_hour,get_minute; + axis2_bool_t is_negative; + double get_second; + + duration = axutil_duration_create(env); + duration_one = axutil_duration_create_from_values(env,AXIS2_TRUE,5,9,29,59,21,49); + + if (axutil_duration_set_is_negative(duration,env,AXIS2_TRUE) != AXIS2_SUCCESS) + { + axutil_duration_free(duration,env); + axutil_duration_free(duration_one,env); + return AXIS2_FAILURE; + } + is_negative = axutil_duration_get_is_negative(duration,env); + if (!is_negative) + { + axutil_duration_free(duration,env); + axutil_duration_free(duration_one,env); + return AXIS2_FAILURE; + } + + if (axutil_duration_set_years(duration,env,5) != AXIS2_SUCCESS) + { + axutil_duration_free(duration,env); + axutil_duration_free(duration_one,env); + return AXIS2_FAILURE; + } + get_year = axutil_duration_get_years(duration,env); + if (axutil_duration_set_months(duration,env,9) != AXIS2_SUCCESS) + { + axutil_duration_free(duration,env); + axutil_duration_free(duration_one,env); + return AXIS2_FAILURE; + } + get_month = axutil_duration_get_months(duration,env); + if (axutil_duration_set_days(duration,env,29) != AXIS2_SUCCESS) + { + axutil_duration_free(duration,env); + axutil_duration_free(duration_one,env); + return AXIS2_FAILURE; + } + get_day = axutil_duration_get_days(duration,env); + if (axutil_duration_set_hours(duration,env,59) != AXIS2_SUCCESS) + { + axutil_duration_free(duration,env); + axutil_duration_free(duration_one,env); + return AXIS2_FAILURE; + } + get_hour = axutil_duration_get_hours(duration,env); + if (axutil_duration_set_mins(duration,env,21) != AXIS2_SUCCESS) + { + axutil_duration_free(duration,env); + axutil_duration_free(duration_one,env); + return AXIS2_FAILURE; + } + get_minute = axutil_duration_get_mins(duration,env); + if (axutil_duration_set_seconds(duration,env,49) != AXIS2_SUCCESS) + { + axutil_duration_free(duration,env); + axutil_duration_free(duration_one,env); + return AXIS2_FAILURE; + } + get_second = axutil_duration_get_seconds(duration,env); + printf("Duration for test 6: %d-%d-%d %d:%d:%.0f\n",get_year,get_month,get_day,get_hour,get_minute,get_second); + printf("The test 6 is completed\n"); + if (!axutil_duration_compare(duration_one,duration,env)) + { + printf("The test 7 failed\n"); + axutil_duration_free(duration,env); + axutil_duration_free(duration_one,env); + return AXIS2_FAILURE; + } + printf("The test 7 is successful\n"); + axutil_duration_free(duration,env); + axutil_duration_free(duration_one,env); + return AXIS2_SUCCESS; +} +int main() +{ + int status = AXIS2_SUCCESS; + + axutil_env_t *env = NULL; + env = create_environment(); + + status = test_duration(env); + if(status == AXIS2_FAILURE) + { + printf("The test test_duration failed\n"); + } + status = set_values(env); + if(status == AXIS2_FAILURE) + { + printf("The test set_values failed\n"); + } + axutil_env_free(env); + return 0; +} diff --git a/util/test/link_list/Makefile.am b/util/test/link_list/Makefile.am new file mode 100644 index 0000000..409d710 --- /dev/null +++ b/util/test/link_list/Makefile.am @@ -0,0 +1,13 @@ +TESTS = link_list_test +check_PROGRAMS = link_list_test +noinst_PROGRAMS = link_list_test +link_list_test_SOURCES = link_list_test.c ../util/create_env.c + +link_list_test_LDADD = \ + $(top_builddir)/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../axiom/include \ + -I ../../../include + + diff --git a/util/test/link_list/build.sh b/util/test/link_list/build.sh new file mode 100644 index 0000000..154b0d3 --- /dev/null +++ b/util/test/link_list/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +gcc link_list_test.c ../util/create_env.c -g -I$AXIS2C_HOME/include/axis2-1.3.0 -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -o link_list_test diff --git a/util/test/link_list/link_list_test.c b/util/test/link_list/link_list_test.c new file mode 100644 index 0000000..c32f360 --- /dev/null +++ b/util/test/link_list/link_list_test.c @@ -0,0 +1,69 @@ +#include <axutil_linked_list.h> +#include "../util/create_env.h" + +axutil_env_t *env = NULL; +axutil_linked_list_t * linked_list = NULL; +entry_t *entry = NULL; + +axis2_status_t test_link_list(axutil_env_t *env,char * first_item,char * second_item,char * third_item,char *last_item,char *array) +{ + linked_list = axutil_linked_list_create(env); + if(linked_list) + { + printf("link list is created \n"); + } + if(!linked_list) + { + printf("link list is not created "); + } + axutil_linked_list_add_first(linked_list,env,(void *)first_item); + axutil_linked_list_contains(linked_list,env,(void *)second_item); + axutil_linked_list_add(linked_list,env,(void *)third_item); + axutil_linked_list_add_last(linked_list,env,(void *)last_item); + int index_of_item = axutil_linked_list_index_of(linked_list,env,third_item); + printf("The index of item is %d\n",index_of_item); + int index_of_last_item = axutil_linked_list_last_index_of(linked_list,env,last_item); + entry_t * entry = axutil_linked_list_get_entry(linked_list,env,0); + printf("The index of last item is %d\n",index_of_last_item); + void *get_item = axutil_linked_list_get(linked_list,env,1); + printf("The get item is %s\n",(char *)get_item); + axutil_linked_list_set(linked_list,env,1,(void *)array); + axutil_linked_list_to_array(linked_list,env); + axutil_linked_list_add_at_index(linked_list,env,1,(void *)second_item); + axutil_linked_list_remove_at_index(linked_list,env,1); + axutil_linked_list_check_bounds_inclusive(linked_list,env,1); + axutil_linked_list_remove_entry(linked_list,env,entry); + axutil_linked_list_remove_first(linked_list,env); + axutil_linked_list_remove_last(linked_list,env); + axutil_linked_list_remove(linked_list,env,(void *)third_item); + axutil_linked_list_free(linked_list,env); + if(index_of_item && index_of_last_item && get_item) + { + printf("The test is SUCCESS\n"); + } + if(!index_of_item || !index_of_last_item || !get_item) + { + printf("The test is FAIL\n"); + } + return AXIS2_SUCCESS; +} + +int main() +{ + int status = AXIS2_SUCCESS; + env = create_environment(); + status = test_link_list(env,"first entry","secnd entry","third entry","last entry" ,"test"); + if(status == AXIS2_FAILURE) + { + printf(" build failed"); + } + axutil_env_free(env); + return 0; +} + + + + + + + diff --git a/util/test/properties/Makefile.am b/util/test/properties/Makefile.am new file mode 100644 index 0000000..69bb83b --- /dev/null +++ b/util/test/properties/Makefile.am @@ -0,0 +1,13 @@ +TESTS = property_test +check_PROGRAMS = property_test +noinst_PROGRAMS = property_test +property_test_SOURCES = property_test.c ../util/create_env.c + +property_test_LDADD = \ + $(top_builddir)/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../axiom/include \ + -I ../../../include + + diff --git a/util/test/properties/build.sh b/util/test/properties/build.sh new file mode 100644 index 0000000..9948fc6 --- /dev/null +++ b/util/test/properties/build.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +gcc property_test.c ../util/create_env.c -g -I$AXIS2C_HOME/include/axis2-1.2 -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -o property_test + + + + diff --git a/util/test/properties/input.doc b/util/test/properties/input.doc new file mode 100644 index 0000000..67fd61d --- /dev/null +++ b/util/test/properties/input.doc @@ -0,0 +1 @@ +This is the content of the input file diff --git a/util/test/properties/output.doc b/util/test/properties/output.doc new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/util/test/properties/output.doc diff --git a/util/test/properties/property_test.c b/util/test/properties/property_test.c new file mode 100644 index 0000000..e7e3a8f --- /dev/null +++ b/util/test/properties/property_test.c @@ -0,0 +1,117 @@ +#include <stdio.h> +#include <axutil_env.h> +#include "../util/create_env.h" +#include <axutil_properties.h> + +axis2_char_t * +axutil_properties_read( + FILE *input, + const axutil_env_t *env); + +/** @brief test properties + * read file and give the output + */ +axis2_status_t test_properties(axutil_env_t *env) +{ + axutil_hash_t* all_properties = NULL; + axis2_status_t status = AXIS2_FAILURE; + axis2_char_t* cur = NULL; + axis2_char_t* input_filename = "test.doc"; + axutil_properties_t * properties = NULL; + axis2_status_t store_properties ; + axis2_status_t load_properties ; + axis2_char_t * key = "key"; + axis2_char_t * value = "value"; + FILE *input = fopen("input.doc","rb"); + FILE *output = fopen("output.doc","rb"); + if (!(input && output)) + { + return AXIS2_FAILURE; + } + + properties = axutil_properties_create(env); + if(!properties) + { + printf("Properties are not created\n"); + axutil_property_free(properties,env); + return AXIS2_FAILURE; + } + else + printf("The the axutil_properties_create is successfull\n"); + + cur = axutil_properties_read(input,env); + if(!cur) + { + printf("Can't read properties\n"); + axutil_property_free(properties,env); + return AXIS2_FAILURE; + } + else + printf("The test axutil_properties_read is successfull\n"); + + status = axutil_properties_set_property(properties,env, key, value); + if (status == AXIS2_SUCCESS) + printf("The test axutil_properties_set_property is successful\n"); + else + printf("The test axutil_properties_set_property failed\n") ; + + + store_properties = axutil_properties_store(properties,env,output); + if(!store_properties) + { + printf("Can not store the properties\n"); + axutil_property_free(properties,env); + return AXIS2_FAILURE; + } + else + printf("The test axutil_properties_store is successfull\n"); + + load_properties = axutil_properties_load(properties,env,input_filename); + if(!load_properties) + { + printf("Properties can't be loaded\n"); + axutil_property_free(properties,env); + return AXIS2_FAILURE; + } + else + printf("The test axutil_properties_load is successfull\n"); + + all_properties = axutil_properties_get_all(properties,env); + if(!all_properties) + { + printf("Can't call properties_get_all\n"); + axutil_property_free(properties,env); + return AXIS2_FAILURE; + } + else + printf("The test axutil_properties_get_all is successfull\n"); + + axutil_property_free(properties,env); + + return AXIS2_SUCCESS; +} + +int main() +{ + axutil_env_t *env = NULL; + int status = AXIS2_SUCCESS; + env = create_environment(); + status = test_properties(env); + + if(status == AXIS2_FAILURE) + { + printf(" The test is failed\n"); + } + + axutil_env_free(env); + return 0; +} + + + + + + + + + diff --git a/util/test/properties/test.doc b/util/test/properties/test.doc new file mode 100644 index 0000000..d687785 --- /dev/null +++ b/util/test/properties/test.doc @@ -0,0 +1 @@ +this use for test perposes diff --git a/util/test/rand/Makefile.am b/util/test/rand/Makefile.am new file mode 100644 index 0000000..6c75e30 --- /dev/null +++ b/util/test/rand/Makefile.am @@ -0,0 +1,13 @@ +TESTS = rand_test +check_PROGRAMS = rand_test +noinst_PROGRAMS = rand_test +rand_test_SOURCES = rand_test.c ../util/create_env.c + +rand_test_LDADD = \ + $(top_builddir)/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../axiom/include \ + -I ../../../include + + diff --git a/util/test/rand/build.sh b/util/test/rand/build.sh new file mode 100644 index 0000000..ee98324 --- /dev/null +++ b/util/test/rand/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +gcc rand_test.c ../util/create_env.c -g -Werror -I$AXIS2C_HOME/include/axis2-1.3.0 -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -o rand_test -ldl -Wl,--rpath -Wl,$AXIS2C_HOME/lib diff --git a/util/test/rand/rand_test.c b/util/test/rand/rand_test.c new file mode 100644 index 0000000..90c566b --- /dev/null +++ b/util/test/rand/rand_test.c @@ -0,0 +1,64 @@ +#include "../util/create_env.h" + +/** @brief test_rand + * create random variable and get it's value + */ + +axis2_status_t test_rand(axutil_env_t *env) +{ + int rand_number,rand_value,start = 2,end = 8,rand_range; + unsigned seed = 10; + + rand_number = axutil_rand(&seed); + if(!rand_number) + { + printf("Test axutil_rand failed\n"); + } + else + { + printf("Test axutil_rand is successfull\n"); + printf("The random value is %d\n",rand_number); + } + + rand_range = axutil_rand_with_range(&seed,start,end); + if(rand_range == -1) + { + printf("Test axutil_rand_with_range failed\n"); + } + else + { + printf("Test axutil_rand_with_range is successfull\n"); + printf("The random seed value is %d\n",rand_range); + } + + rand_value = axutil_rand_get_seed_value_based_on_time(env); + if(!rand_value) + { + printf("The test axutil_rand_get_seed_value_based_on_time failed\n"); + } + else + { + printf("Test axutil_rand_get_seed_value_based_on_time is successfull\n"); + printf("The random range is %d\n",rand_value); + } + + return AXIS2_SUCCESS; +} + +int main() +{ + int status = AXIS2_SUCCESS; + axutil_env_t *env = NULL; + + env = create_environment(); + status = test_rand(env); + + if(status == AXIS2_FAILURE) + { + printf("Test failed\n"); + } + axutil_env_free(env); + return 0; +} + + diff --git a/util/test/stack/Makefile.am b/util/test/stack/Makefile.am new file mode 100644 index 0000000..10308c8 --- /dev/null +++ b/util/test/stack/Makefile.am @@ -0,0 +1,13 @@ +TESTS = stack_test +check_PROGRAMS = stack_test +noinst_PROGRAMS = stack_test +stack_test_SOURCES = stack_test.c ../util/create_env.c + +stack_test_LDADD = \ + $(top_builddir)/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../axiom/include \ + -I ../../../include + + diff --git a/util/test/stack/build.sh b/util/test/stack/build.sh new file mode 100644 index 0000000..8ca7aff --- /dev/null +++ b/util/test/stack/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +gcc stack_test.c ../util/create_env.c -g -I$AXIS2C_HOME/include/axis2-1.3.0 -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -o stack_test -ldl -Wl,--rpath -Wl,$AXIS2C_HOME/lib diff --git a/util/test/stack/stack_test.c b/util/test/stack/stack_test.c new file mode 100644 index 0000000..833adc2 --- /dev/null +++ b/util/test/stack/stack_test.c @@ -0,0 +1,71 @@ +#include "../util/create_env.h" +#include <axutil_stack.h> + +axis2_status_t test_stack(axutil_env_t * env, char * value) +{ + axutil_stack_t * stack = NULL; + axis2_status_t status = AXIS2_FAILURE; + stack = axutil_stack_create(env); + void * get_value = NULL; + if (!stack) + { + printf("Creation of stack failed"); + return AXIS2_FAILURE; + } + status = axutil_stack_push(stack,env,(void *)value); + if (status != AXIS2_SUCCESS) + { + printf("Adding value to stack failed"); + axutil_stack_free(stack,env); + return AXIS2_FAILURE; + } + if (axutil_stack_size(stack,env) != 1) + { + printf("Incorrect size of stack is reported"); + axutil_stack_free(stack,env); + return AXIS2_FAILURE; + } + if (value != (char *)axutil_stack_get(stack,env)) + { + printf("Stack returns incorrect object"); + axutil_stack_free(stack,env); + return AXIS2_FAILURE; + } + get_value = axutil_stack_get_at(stack,env,0); + printf("The value of stack is %s",(char *)get_value); + if (value != (char *)axutil_stack_pop(stack,env)) + { + printf("Stack returns incorrect object"); + axutil_stack_free(stack,env); + return AXIS2_FAILURE; + } + if (axutil_stack_size(stack,env) != 0) + { + printf("Incorrect size of stack is reported"); + axutil_stack_free(stack,env); + return AXIS2_FAILURE; + } + if(stack) + { + axutil_stack_free(stack,env); + printf("The test is SUCCESSFUL\n"); + return AXIS2_SUCCESS; + } + + return AXIS2_FAILURE; +} +int main() +{ + char value[10] = "test\n"; + int status = AXIS2_SUCCESS; + axutil_env_t *env = NULL; + env = create_environment(); + status = test_stack(env,value); + if(status != AXIS2_SUCCESS) + { + printf("The test failed"); + } + axutil_env_free(env); + return 0; +} + diff --git a/util/test/string_util/Makefile.am b/util/test/string_util/Makefile.am new file mode 100644 index 0000000..09ce78f --- /dev/null +++ b/util/test/string_util/Makefile.am @@ -0,0 +1,13 @@ +TESTS = string_util_test +noinst_PROGRAMS = string_util_test +check_PROGRAMS = string_util_test +string_util_test_SOURCES = string_util_test.c ../util/create_env.c + +string_util_test_LDADD = \ + $(top_builddir)/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../axiom/include \ + -I ../../../include + + diff --git a/util/test/string_util/build.sh b/util/test/string_util/build.sh new file mode 100644 index 0000000..504ca27 --- /dev/null +++ b/util/test/string_util/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +gcc string_util_test.c ../util/create_env.c -g -I$AXIS2C_HOME/include/axis2-1.2 -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -o string_util_test diff --git a/util/test/string_util/string_util_test.c b/util/test/string_util/string_util_test.c new file mode 100644 index 0000000..d9e0cb2 --- /dev/null +++ b/util/test/string_util/string_util_test.c @@ -0,0 +1,66 @@ +#include <string.h> +#include "../util/create_env.h" +#include <axutil_string_util.h> +#include <axutil_array_list.h> + +/** @brief test string + * tokenize a string + */ + +axis2_status_t test_string(axutil_env_t *env) +{ + int delim = ' '; + void *token = NULL; + void *last_token_string = NULL; + void *first_token_string = NULL; + axutil_array_list_t * first_token, * last_token; + axis2_char_t * in = "this is a test string"; + + axutil_array_list_t * tokenize = axutil_tokenize(env, in, delim); + if(tokenize) + { + token = axutil_array_list_get(tokenize,env,4); + printf("The test axutil_tokenize is successfull\n"); + printf("The tokenize string is %s\n",(char *)token); + } + else + return AXIS2_FAILURE; + + first_token = axutil_first_token(env,in,delim); + if(first_token) + { + first_token_string = axutil_array_list_get(first_token,env,1); + printf("The test axutil_first_token is successfull\n"); + printf("First token string is %s\n",(char *)first_token_string); + } + else + return AXIS2_FAILURE; + + last_token = axutil_last_token(env,in,delim); + if(last_token) + { + last_token_string = axutil_array_list_get(last_token,env,1); + printf("The test axutil_last_token is successfull\n"); + printf("Last token string is %s\n",(char *)last_token_string); + } + else + return AXIS2_FAILURE; + + return AXIS2_SUCCESS; +} +int main() +{ + axutil_env_t *env = NULL; + int status = AXIS2_SUCCESS; + env = create_environment(); + status = test_string(env); + if(status == AXIS2_FAILURE) + { + printf("build failed"); + } + axutil_env_free(env); + return 0; +} + + + diff --git a/util/test/uri/Makefile.am b/util/test/uri/Makefile.am new file mode 100644 index 0000000..98475e8 --- /dev/null +++ b/util/test/uri/Makefile.am @@ -0,0 +1,13 @@ +TESTS = uri_test +check_PROGRAMS = uri_test +noinst_PROGRAMS = uri_test +uri_test_SOURCES = uri_test.c ../util/create_env.c + +uri_test_LDADD = \ + $(top_builddir)/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../axiom/include \ + -I ../../../include + + diff --git a/util/test/uri/build.sh b/util/test/uri/build.sh new file mode 100644 index 0000000..4239290 --- /dev/null +++ b/util/test/uri/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +gcc uri_test.c ../util/create_env.c -g -Werror -I$AXIS2C_HOME/include/axis2-1.3.0 -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -o uri_test -ldl -Wl,--rpath -Wl,$AXIS2C_HOME/lib diff --git a/util/test/uri/uri_test.c b/util/test/uri/uri_test.c new file mode 100644 index 0000000..95ff453 --- /dev/null +++ b/util/test/uri/uri_test.c @@ -0,0 +1,140 @@ +#include <axutil_uri.h> +#include "../util/create_env.h" +/** @brief test uri + * * create URI and get the values of it's components + * */ +axis2_status_t test_uri(axutil_env_t *env) +{ + axis2_char_t * uri_str = "http://user:pass@example.com:80/foo?bar#item5"; + axis2_char_t * host = "home.netscape.com:443"; + axis2_char_t * uri_str_base = "http://user:pass@example.com:80/foo?bar"; + axis2_char_t * scheme_str = "http"; + axutil_uri_t * base = NULL; + axutil_uri_t * hostinfo = NULL; + axutil_uri_t * uri = NULL; + axutil_uri_t * clone = NULL; + axutil_uri_t * rel = NULL; + axis2_char_t * protocol = NULL; + axis2_char_t * server = NULL; + axis2_char_t * path = NULL; + axis2_port_t scheme_port; + axis2_port_t port; + + hostinfo = axutil_uri_parse_hostinfo(env,host); + if(hostinfo) + { + printf("The host information of uri is %s\n",axutil_uri_to_string(hostinfo,env,0)); + } + else + { + printf("Test hostinfo faild\n"); + } + + scheme_port = axutil_uri_port_of_scheme(scheme_str); + if(scheme_port) + { + printf("port of scheme is %u\n", scheme_port); + } + else + { + printf("Test port failed\n"); + } + + uri = axutil_uri_parse_string(env,uri_str); + if(uri) + { + printf("The uri is %s\n",axutil_uri_to_string(uri,env,0)); + axutil_uri_free(uri, env); + } + else + { + return AXIS2_FAILURE; + } + + base = axutil_uri_parse_string(env,uri_str_base); + if(base) + { + printf("The base of uri is %s\n",axutil_uri_to_string(base,env,0)); + } + else + { + printf("Test base failed\n"); + } + + clone = axutil_uri_clone(uri,env); + if(clone) + { + printf("The clone of uri is %s\n",axutil_uri_to_string(clone,env,0)); + axutil_uri_free(clone,env); + } + else + { + printf("Test clone failed"); + } + + rel = axutil_uri_resolve_relative(env,base,clone); + if(rel) + { + printf("The resolved relative uri is %s\n",axutil_uri_to_string(rel,env,0)); + } + else + { + printf("Test resolve relative failed"); + } + + protocol = axutil_uri_get_protocol(uri,env); + if (!protocol) + { + axutil_uri_free(uri,env); + return AXIS2_FAILURE; + } + + server = axutil_uri_get_server(uri,env); + if (!server) + { + axutil_uri_free(uri,env); + return AXIS2_FAILURE; + } + + port = axutil_uri_get_port(uri,env); + if (!port) + { + axutil_uri_free(uri,env); + return AXIS2_FAILURE; + } + + path = axutil_uri_get_path(uri,env); + if (!path) + { + axutil_uri_free(uri,env); + return AXIS2_FAILURE; + } + + printf("The protocol is %s\n",protocol); + printf("The server is %s \n",server); + printf("The port is %u \n",port); + printf("The path is %s\n",path); + axutil_uri_free(uri,env); + return AXIS2_SUCCESS; +} + +int main() +{ + int status = AXIS2_SUCCESS; + axutil_env_t *env = NULL; + + env = create_environment(); + status = test_uri(env); + + if(status == AXIS2_FAILURE) + { + printf("The Test failed"); + } + axutil_env_free(env); + + return 0; +} + + + + diff --git a/util/test/url/Makefile.am b/util/test/url/Makefile.am new file mode 100644 index 0000000..ff7b8fb --- /dev/null +++ b/util/test/url/Makefile.am @@ -0,0 +1,13 @@ +TESTS = url_test +noinst_PROGRAMS = url_test +check_PROGRAMS = url_test +url_test_SOURCES = url_test.c ../util/create_env.c + +url_test_LDADD = \ + $(top_builddir)/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../axiom/include \ + -I ../../../include + + diff --git a/util/test/url/build.sh b/util/test/url/build.sh new file mode 100644 index 0000000..455a8a9 --- /dev/null +++ b/util/test/url/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +gcc url_test.c ../util/create_env.c -g -Werror -I$AXIS2C_HOME/include/axis2-1.3.0 -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -o url_test -ldl -Wl,--rpath -Wl,$AXIS2C_HOME/lib diff --git a/util/test/url/url_test.c b/util/test/url/url_test.c new file mode 100644 index 0000000..65f93da --- /dev/null +++ b/util/test/url/url_test.c @@ -0,0 +1,130 @@ +#include <axutil_url.h> +#include "../util/create_env.h" + +/** @brief test url + * create URL and get the values of it's components + */ + +axis2_status_t test_url(axutil_env_t *env) +{ + axutil_url_t * url; + axis2_char_t *url_str = "https://issues.apache.org/jira/secure/ManageAttachments.jspa?id=12386356"; + axis2_char_t *set_server = "www.yahoo.com"; + axis2_char_t *set_protocol = "file"; + axis2_char_t *set_path = "/bar/"; + axis2_port_t set_port = 80; + axis2_char_t *get_protocol; + axis2_char_t *get_server; + axis2_port_t get_port; + axis2_char_t *get_path; + axis2_status_t status; + + url = axutil_url_parse_string(env,url_str); + if(url) + { + printf("The url is created \n"); + } + else + { + return AXIS2_FAILURE; + } + + status = axutil_url_set_protocol(url,env,set_protocol); + + if (status == AXIS2_SUCCESS) + printf("The test 1 is successful\n"); + else + printf("The test 1 failed\n") ; + + status = axutil_url_set_server(url,env,set_server); + + if (status == AXIS2_SUCCESS) + printf("The test 2 is successful\n"); + else + printf("The test 2 failed\n") ; + + status = axutil_url_set_port(url,env,set_port); + + if (status == AXIS2_SUCCESS) + printf("The test 3 is successful\n"); + else + printf("The test 3 failed\n") ; + + status = axutil_url_set_path(url,env,set_path); + + if (status == AXIS2_SUCCESS) + printf("The test 4 is successful\n"); + else + printf("The test 4 failed\n") ; + + get_protocol = axutil_url_get_protocol(url,env); + + if (!get_protocol) + { + axutil_url_free(url,env); + return AXIS2_FAILURE; + } + else + { + printf("The protocol is %s\n",get_protocol); + } + + get_server = axutil_url_get_server(url,env); + + if (!get_server) + { + axutil_url_free(url,env); + return AXIS2_FAILURE; + } + else + { + printf("The server is %s\n",get_server); + } + + get_port = axutil_url_get_port(url,env); + + if (!get_port) + { + axutil_url_free(url,env); + return AXIS2_FAILURE; + } + else + { + printf("The port is %d\n",get_port); + } + + get_path = axutil_url_get_path(url,env); + + if (!get_path) + { + axutil_url_free(url,env); + return AXIS2_FAILURE; + } + else + { + printf("The path is %s\n",get_path); + } + + axutil_url_free(url,env); + return AXIS2_SUCCESS; +} + +int main() +{ + int status = AXIS2_SUCCESS; + axutil_env_t *env = NULL; + + env = create_environment(); + status = test_url(env); + + if(status == AXIS2_FAILURE) + { + printf("Test failed"); + } + axutil_env_free(env); + + return 0; +} + + + diff --git a/util/test/util/Makefile.am b/util/test/util/Makefile.am new file mode 100644 index 0000000..4d3a701 --- /dev/null +++ b/util/test/util/Makefile.am @@ -0,0 +1,20 @@ +TESTS = test_thread test_util +noinst_PROGRAMS = test_util test_thread +noinst_HEADERS = test_log.h \ + test_thread.h \ + create_env.h\ + test_md5.h +check_PROGRAMS = test_util test_thread +SUBDIRS = +test_util_SOURCES = test_util.c test_log.c test_string.c test_md5.c +test_thread_SOURCES = test_thread.c + +test_util_LDADD = \ + $(top_builddir)/src/libaxutil.la \ + -lpthread + +test_thread_LDADD = \ + $(top_builddir)/src/libaxutil.la \ + -lpthread + +INCLUDES = -I$(top_builddir)/include diff --git a/util/test/util/create_env.c b/util/test/util/create_env.c new file mode 100644 index 0000000..5a26182 --- /dev/null +++ b/util/test/util/create_env.c @@ -0,0 +1,17 @@ +#include "create_env.h" + +axutil_env_t * create_environment() +{ + axutil_allocator_t *allocator = NULL; + axutil_log_t *log = NULL; + axutil_error_t *error = NULL; + axutil_env_t *env = NULL; + allocator = axutil_allocator_init(NULL); + log = axutil_log_create(allocator, NULL, NULL); + + error = axutil_error_create(allocator); + env = axutil_env_create_with_error_log(allocator, error, log); + return env; +} + + diff --git a/util/test/util/create_env.h b/util/test/util/create_env.h new file mode 100644 index 0000000..e3ea7b8 --- /dev/null +++ b/util/test/util/create_env.h @@ -0,0 +1,10 @@ +#include <axutil_log_default.h> +#include <axutil_error_default.h> +#include <stdio.h> +#include <axutil_env.h> + +axutil_env_t * create_environment(); + + + + diff --git a/util/test/util/test_log.c b/util/test/util/test_log.c new file mode 100644 index 0000000..4539b4e --- /dev/null +++ b/util/test/util/test_log.c @@ -0,0 +1,182 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <stdio.h> +#include <axutil_error_default.h> +#include <axutil_log.h> +#include <axutil_log_default.h> +#include <axutil_allocator.h> +#include <test_log.h> +#include <string.h> +const axutil_env_t * +create_env_with_error_log( + ) +{ + axutil_allocator_t *allocator = axutil_allocator_init(NULL); + if (!allocator) + { + printf("allocator is NULL\n"); + return NULL; + } + axutil_error_t *error = axutil_error_create(allocator); + if (!error) + { + printf("cannot create error\n"); + return NULL; + } + + axutil_log_t *log22 = axutil_log_create(allocator, NULL, NULL); + if (!log22) + { + printf("cannot create log\n"); + return NULL; + } + /* + * allow all types of logs + */ + log22->level = AXIS2_LOG_LEVEL_DEBUG; + /* log22->enabled = 0; */ + const axutil_env_t *env = + axutil_env_create_with_error_log(allocator, error, log22); + if (!env) + { + printf("cannot create env with error and log\n"); + return NULL; + } + return env; +} + +void +test_axutil_log_write( + const axutil_env_t * env) +{ + char msg[32]; + printf("\n####start of test_axutil_log_write\n\n"); + strcpy(msg, "abcd test123"); + printf("\n####end of test_axutil_log_write\n\n"); +} + +void +test_axutil_log_debug( + const axutil_env_t * env) +{ + printf("\n####start of test_axutil_log_degug\n\n"); + env->log->level = AXIS2_LOG_LEVEL_DEBUG; + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "log_debug test %s %d", "foo", 1); + printf("\n####end of test_axutil_log_debug\n\n"); +} + +void +test_axutil_log_debug_off( + const axutil_env_t * env) +{ + printf("\n####start of test_axutil_log_degug_off\n\n"); + env->log->level = AXIS2_LOG_LEVEL_ERROR; /*log only ERROR's and CRITICAL's */ + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, + "this should not be logged log_debug test %s %d", "foo", 1); + printf("\n####end of test_axutil_log_debug_off\n\n"); +} + +void +test_axutil_log_info( + const axutil_env_t * env) +{ + printf("\n####start of test_axutil_log_info\n\n"); + env->log->level = AXIS2_LOG_LEVEL_DEBUG; + AXIS2_LOG_INFO(env->log, "log_info test %s %d", "foo", 1); + printf("\n####end of test_axutil_log_info\n\n"); +} + +void +test_axutil_log_info_off( + const axutil_env_t * env) +{ + printf("\n####start of test_axutil_log_info_off\n\n"); + env->log->level = AXIS2_LOG_LEVEL_ERROR; /*log only ERROR's and CRITICAL's */ + AXIS2_LOG_INFO(env->log, "this should not be logged log_info test %s %d", + "foo", 1); + printf("\n####end of test_axutil_log_info_off\n\n"); +} + +void +test_axutil_log_warning( + const axutil_env_t * env) +{ + printf("\n####start of test_axutil_log_warning\n\n"); + env->log->level = AXIS2_LOG_LEVEL_DEBUG; + AXIS2_LOG_WARNING(env->log, AXIS2_LOG_SI, "log_warning test %s %d", "foo", + 1); + printf("\n####end of test_axutil_log_warning\n\n"); +} + +void +test_axutil_log_warning_off( + const axutil_env_t * env) +{ + printf("\n####start of test_axutil_log_warning_off\n\n"); + env->log->level = AXIS2_LOG_LEVEL_ERROR; /*log only ERROR's and CRITICAL's */ + AXIS2_LOG_WARNING(env->log, AXIS2_LOG_SI, + "this should not be logged log_warning test %s %d", "foo", + 1); + printf("\n####end of test_axutil_log_warning_off\n\n"); +} + +/*no need to sent log level, should always log*/ +void +test_axutil_log_error( + const axutil_env_t * env) +{ + printf("\n####start of test_axutil_log_error\n\n"); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "log_error test %s %d", "foo", 1); + printf("\n####end of test_axutil_log_error\n\n"); +} + +/*no need to sent log level, should always log*/ +void +test_axutil_log_critical( + const axutil_env_t * env) +{ + printf("\n####start of test_axutil_log_critical\n\n"); + AXIS2_LOG_CRITICAL(env->log, AXIS2_LOG_SI, "log_critical test %s %d", "foo", + 1); + printf("\n####end of test_axutil_log_critical\n\n"); +} + +void +run_test_log( + ) +{ + printf("\n####start of run_test_log test suite\n\n"); + const axutil_env_t *env = create_env_with_error_log(); + if (!env) + return; + test_axutil_log_write(env); + test_axutil_log_debug(env); + test_axutil_log_debug_off(env); + + test_axutil_log_info(env); + test_axutil_log_info_off(env); + + test_axutil_log_warning(env); + test_axutil_log_warning_off(env); + + test_axutil_log_error(env); + + test_axutil_log_critical(env); + printf("\n####end of run_test_log test suite \n\n"); +} diff --git a/util/test/util/test_log.h b/util/test/util/test_log.h new file mode 100644 index 0000000..d88669e --- /dev/null +++ b/util/test/util/test_log.h @@ -0,0 +1,47 @@ + +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The ASF licenses this file to You 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 _TEST_LOG_H_ +#define _TEST_LOG_H_ + +#include <axutil_env.h> + +void run_test_log( +); +const axutil_env_t *create_env_with_error_log( +); +void test_axutil_log_write( + const axutil_env_t * env); +void test_axutil_log_debug( + const axutil_env_t * env); +void test_axutil_log_debug_off( + const axutil_env_t * env); +void test_axutil_log_info( + const axutil_env_t * env); +void test_axutil_log_info_off( + const axutil_env_t * env); +void test_axutil_log_warning( + const axutil_env_t * env); +void test_axutil_log_warning_off( + const axutil_env_t * env); +void test_axutil_log_error( + const axutil_env_t * env); +void test_axutil_log_critical( + const axutil_env_t * env); + +#endif /* _TEST_LOG_H_ */ diff --git a/util/test/util/test_md5.c b/util/test/util/test_md5.c new file mode 100644 index 0000000..7c360ce --- /dev/null +++ b/util/test/util/test_md5.c @@ -0,0 +1,55 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <test_md5.h> +#include <stdio.h> +#include <axutil_string.h> +#include <axutil_md5.h> + +/* Digests a string and prints the result. + */ +static void MDString (char * string, const axutil_env_t * env) +{ + axutil_md5_ctx_t * context; + unsigned char digest[16]; + unsigned int i; + unsigned int len = axutil_strlen(string); + + context = axutil_md5_ctx_create(env); + axutil_md5_update(context, env, string, len); + axutil_md5_final(context, env, digest); + axutil_md5_ctx_free(context, env); + + printf ("MD%d (\"%s\") = ", 5, string); + for (i = 0; i < 16; i++) + printf ("%02x", digest[i]); + printf ("\n"); +} + +void test_md5(const axutil_env_t *env) +{ + printf ("\nMD5 test suite:\n"); + printf ("test confirmation: Rivest, R., \"The MD5 Message-Digest Algorithm\", RFC 1321, April 1992.\n"); + MDString ("", env); + MDString ("a", env); + MDString ("abc", env); + MDString ("message digest", env); + MDString ("abcdefghijklmnopqrstuvwxyz", env); + MDString ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", env); + MDString ("12345678901234567890123456789012345678901234567890123456789012345678901234567890", env); +} diff --git a/util/test/util/test_md5.h b/util/test/util/test_md5.h new file mode 100644 index 0000000..215a096 --- /dev/null +++ b/util/test/util/test_md5.h @@ -0,0 +1,27 @@ + +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The ASF licenses this file to You 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 _TEST_MD5_H_ +#define _TEST_MD5_H_ + +#include <axutil_env.h> + +void test_md5( + const axutil_env_t * env); + +#endif /* _TEST_MD5_H_ */ diff --git a/util/test/util/test_string.c b/util/test/util/test_string.c new file mode 100644 index 0000000..d4d7bbc --- /dev/null +++ b/util/test/util/test_string.c @@ -0,0 +1,84 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <stdio.h> +#include <axutil_error_default.h> +#include <axutil_log.h> +#include <axutil_string.h> + +void +test_strltrim( + const axutil_env_t * env) +{ + axis2_char_t *s = axutil_strdup(env, " abcd efgh "); + axis2_char_t *trimmed = NULL; + trimmed = axutil_strltrim(env, s, " \t\r\n"); + if (0 == axutil_strcmp(trimmed, "abcd efgh ")) + printf("axutil_strltrim successful\n"); + else + printf("axutil_strltrim failed [%s]\n", trimmed); + if (trimmed) + AXIS2_FREE(env->allocator, trimmed); + if (s) + AXIS2_FREE(env->allocator, s); +} + +void +test_strrtrim( + const axutil_env_t * env) +{ + axis2_char_t *s = axutil_strdup(env, "abcd efgh "); + axis2_char_t *trimmed = NULL; + trimmed = axutil_strrtrim(env, s, " \t\r\n"); + if (0 == axutil_strcmp(trimmed, " abcd efgh")) + printf("axutil_strrtrim successful\n"); + else + printf("axutil_strrtrim failed [%s]\n", trimmed); + if (trimmed) + AXIS2_FREE(env->allocator, trimmed); + if (s) + AXIS2_FREE(env->allocator, s); +} + +void +test_strtrim( + const axutil_env_t * env) +{ + axis2_char_t *s = axutil_strdup(env, " abcd efgh "); + axis2_char_t *trimmed = NULL; + trimmed = axutil_strtrim(env, s, " \t\r\n"); + if (0 == axutil_strcmp(trimmed, "abcd efgh")) + printf("axutil_strtrim successful\n"); + else + printf("axutil_strtrim failed [%s]\n", trimmed); + if (trimmed) + AXIS2_FREE(env->allocator, trimmed); + if (s) + AXIS2_FREE(env->allocator, s); +} + +void +run_test_string( + axutil_env_t * env) +{ + if (!env) + return; + test_strltrim(env); + test_strrtrim(env); + test_strtrim(env); +} diff --git a/util/test/util/test_thread.c b/util/test/util/test_thread.c new file mode 100644 index 0000000..e10b5b7 --- /dev/null +++ b/util/test/util/test_thread.c @@ -0,0 +1,345 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <stdio.h> +#include <string.h> +#include <axutil_error_default.h> +#include <axutil_log.h> +#include <axutil_log_default.h> +#include <axutil_allocator.h> +#include <axutil_utils.h> +#include "test_thread.h" +#include <unistd.h> + +const axutil_env_t *env = NULL; +static axutil_thread_mutex_t *thread_lock = NULL; +static axutil_thread_once_t *control = NULL; +static int x = 0; +static int value = 0; + +static axutil_thread_t *t1 = NULL; +static axutil_thread_t *t2 = NULL; + +/*for detach tests*/ +static axutil_thread_t *t3 = NULL; +static axutil_thread_t *t4 = NULL; + +void +init_func( + void) +{ + value++; +} + +void +thread_init( + const axutil_env_t * env) +{ + axutil_allocator_t *allocator = NULL; + + allocator = env->allocator; + + control = axutil_thread_once_init(allocator); + + if (control) + printf("success - thread_init - axutil_thread_once_init \n"); + else + printf("failure - thread_init - axutil_thread_once_init \n"); + + thread_lock = + axutil_thread_mutex_create(allocator, AXIS2_THREAD_MUTEX_DEFAULT); + + if (thread_lock) + printf("success - thread_init - axutil_thread_mutex_create \n"); + else + printf("failure - thread_init - axutil_thread_mutex_create \n"); +} + +void *AXIS2_CALL +test_function( + axutil_thread_t * td, + void *param) +{ + int i; + i = *((int *) param); + printf("thread data = %d \n", i); + + axutil_thread_once(control, init_func); + + axutil_thread_mutex_lock(thread_lock); + printf("x = %d \n", ++x); + axutil_thread_mutex_unlock(thread_lock); + + /*axutil_thread_exit(td, env->allocator); */ + + return (void *) 1; +} + +void +test_axutil_thread_create( + const axutil_env_t * env) +{ + axis2_status_t rv = AXIS2_FAILURE; + axutil_allocator_t *allocator = NULL; + int *i = NULL, + *j = NULL; + + allocator = env->allocator; + i = AXIS2_MALLOC(allocator, sizeof(int)); + *i = 5; + t1 = axutil_thread_create(allocator, NULL, test_function, (void *) i); + + if (t1) + printf("success - test_axutil_thread_create - axutil_thread_create \n"); + else + printf("failure - test_axutil_thread_create - axutil_thread_create \n"); + + j = AXIS2_MALLOC(allocator, sizeof(int)); + *j = 25; + + t2 = axutil_thread_create(allocator, NULL, test_function, (void *) j); + + if (t2) + printf("success - test_axutil_thread_create - axutil_thread_create \n"); + else + printf("failure - test_axutil_thread_create - axutil_thread_create \n"); + + rv = axutil_thread_join(t1); + + if (AXIS2_SUCCESS == rv) + printf("success - test_axutil_thread_create - axutil_thread_join \n"); + else + printf + ("failure - thread_init - test_axutil_thread_create - axutil_thread_join \n"); + + rv = axutil_thread_join(t2); + + if (AXIS2_SUCCESS == rv) + printf("success - test_axutil_thread_create - axutil_thread_join \n"); + else + printf + ("failure - thread_init - test_axutil_thread_create - axutil_thread_join \n"); + +} + +void *AXIS2_CALL +test_function2( + axutil_thread_t * td, + void *param) +{ + printf("thread \n"); + /*axutil_thread_exit(td, env->allocator); */ + + return (void *) 1; +} + +void +test_axutil_thread_detach( + const axutil_env_t * env) +{ + axutil_threadattr_t *attr = NULL; + axutil_allocator_t *allocator = NULL; + axis2_status_t rv = AXIS2_FAILURE; + + allocator = env->allocator; + attr = axutil_threadattr_create(allocator); + if (!attr) + { + printf("failure - test_axutil_thread_detach\n"); + return; + } + rv = axutil_threadattr_detach_set(attr, 1); + + if (AXIS2_SUCCESS != rv) + { + printf("failure - test_axutil_thread_detach\n"); + return; + } + t3 = axutil_thread_create(allocator, attr, test_function2, NULL); + + if (!t3) + { + printf("failure - test_axutil_thread_detach\n"); + return; + } + + /* + * thread is already detached - should return AXIS2_FAILURE + */ + rv = axutil_thread_detach(t3); + + if (AXIS2_FAILURE != rv) + { + printf("failure - test_axutil_thread_detach\n"); + return; + } + + /* + * thread is already detached - should return AXIS2_FAILURE + * cannot join detached threads + */ + /*rv = axutil_thread_join(t3); */ + if (AXIS2_FAILURE != rv) + { + printf("failure - test_axutil_thread_detach\n"); + return; + } + printf("success - test_axutil_thread_detach\n"); +} + +void +test_axutil_thread_detach2( + const axutil_env_t * env) +{ + axutil_threadattr_t *attr = NULL; + axutil_allocator_t *allocator = NULL; + axis2_status_t rv = AXIS2_FAILURE; + + allocator = env->allocator; + attr = axutil_threadattr_create(allocator); + if (!attr) + { + printf("failure - test_axutil_thread_detach2\n"); + return; + } + + t4 = axutil_thread_create(allocator, attr, test_function2, NULL); + + if (!t4) + { + printf("failure - test_axutil_thread_detach2\n"); + return; + } + + /* + * thread is not detached yet - should return AXIS2_SUCCESS + */ + rv = axutil_thread_detach(t4); + + if (AXIS2_SUCCESS != rv) + { + printf("failure - test_axutil_thread_detach\n"); + return; + } + + /* + * thread is already detached - should return AXIS2_FAILURE + * cannot join detached threads + */ + /*rv = axutil_thread_join(t4); */ + if (AXIS2_FAILURE != rv) + { + printf("failure - test_axutil_thread_detach2\n"); + return; + } + printf("success - test_axutil_thread_detach2\n"); +} + +void +check_locks( + ) +{ + if (2 == x) + printf("success - check_locks \n"); + else + printf("failure - check_locks \n"); + +} + +void +check_thread_once( + ) +{ + if (1 == value) + printf("success - check_thread_once \n"); + else + printf("failure - check_thread_once \n"); +} + +void +run_test_thread( + const axutil_env_t * env) +{ + thread_init(env); + test_axutil_thread_create(env); + check_locks(); + check_thread_once(); + test_axutil_thread_detach(env); + test_axutil_thread_detach2(env); + +#if defined (WIN32) + Sleep(1000); /*to give time for detached threads to execute */ +#else + sleep(2); +#endif + + axutil_thread_mutex_destroy(thread_lock); +} + +const axutil_env_t * +create_env_with_error_log( + ) +{ + axutil_error_t *error = NULL; + axutil_log_t *log22 = NULL; + const axutil_env_t *env = NULL; + axutil_allocator_t *allocator = axutil_allocator_init(NULL); + if (!allocator) + { + printf("allocator is NULL\n"); + return NULL; + } + error = axutil_error_create(allocator); + if (!error) + { + printf("cannot create error\n"); + return NULL; + } + + log22 = axutil_log_create(allocator, NULL, "test123.log"); + if (!log22) + { + printf("cannot create log\n"); + return NULL; + } + /* + * allow all types of logs + */ + log22->level = AXIS2_LOG_LEVEL_DEBUG; + /* log22->enabled = 0; */ + env = axutil_env_create_with_error_log(allocator, error, log22); + if (!env) + { + printf("cannot create env with error and log\n"); + return NULL; + } + return env; +} + +int +main( + void) +{ + env = create_env_with_error_log(); + + if (!env) + return -1; + run_test_thread(env); + + return 0; +} diff --git a/util/test/util/test_thread.h b/util/test/util/test_thread.h new file mode 100644 index 0000000..b006b3f --- /dev/null +++ b/util/test/util/test_thread.h @@ -0,0 +1,50 @@ + +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The ASF licenses this file to You 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 TEST_LOG_H +#define TEST_LOG_H + +#include <axutil_env.h> +#include <axutil_thread.h> + +void init_func( + void); +void thread_init( + const axutil_env_t * env); +void *AXIS2_CALL +test_function( + axutil_thread_t * td, + void *param); +void test_axutil_thread_create( + const axutil_env_t * env); +void *AXIS2_CALL +test_function2( + axutil_thread_t * td, + void *param); +void test_axutil_thread_detach( + const axutil_env_t * env); +void test_axutil_thread_detach2( + const axutil_env_t * env); +void check_locks( +); + +/*call this method from main*/ +void run_test_thread( + const axutil_env_t * env); + +#endif diff --git a/util/test/util/test_util.c b/util/test/util/test_util.c new file mode 100644 index 0000000..dd37710 --- /dev/null +++ b/util/test/util/test_util.c @@ -0,0 +1,304 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 <stdio.h> +#include <axutil_hash.h> +#include <axutil_string.h> +#include <axutil_error_default.h> +#include <axutil_array_list.h> +#include <platforms/axutil_platform_auto_sense.h> +#include <axutil_uuid_gen.h> +#include <axutil_log_default.h> +#include <axutil_log.h> +#include <axutil_dir_handler.h> +#include <axutil_file.h> +#include "axutil_log.h" +#include "test_thread.h" +#include <test_log.h> + +typedef struct a +{ + axis2_char_t *value; +} +a; + +const axutil_env_t * +test_init( + ) +{ + axutil_allocator_t *allocator = axutil_allocator_init(NULL); + axutil_error_t *error = axutil_error_create(allocator); + const axutil_env_t *env = axutil_env_create_with_error(allocator, error); + return env; +} + +int +test_hash_get( + const axutil_env_t * env) +{ + axutil_hash_t *ht; + a *a1, + *a2, + *a3, + *a4; + + axutil_hash_index_t *i = 0; + void *v = NULL; + + char *key1 = "key1"; + char *key2 = "key2"; + char *key3 = "key3"; + char *key4 = "key4"; + int cnt = 0; + axis2_char_t ***rettt = NULL; + axis2_status_t stat = AXIS2_FAILURE; + stat = axutil_parse_rest_url_for_params(env, "ech{a}tring", "/echoString?text=Hello%20World%21", &cnt, &rettt); + stat = axutil_parse_rest_url_for_params(env, "{a}ny/mor/sum", "echoStringmany/mor/sum", &cnt, &rettt); +/* rettt = axutil_parse_rest_url_for_params(env, "echoString/{a}re/{b}?", "/echoString/more/sum/?"); + rettt = axutil_parse_rest_url_for_params(env, "/ech{c}tring{a}more/{b}/", "/echoStringma/nymore/sum?"); + rettt = axutil_parse_rest_url_for_params(env, "echoString/{a}/more/{b}?{c}", "echoString/many/more/sum/"); + rettt = axutil_parse_rest_url_for_params(env, "echoString/{a}/more/{b}/?", "echoString/many/more/sum/?test=");*/ + + a1 = (a *) AXIS2_MALLOC(env->allocator, sizeof(a)); + a2 = (a *) AXIS2_MALLOC(env->allocator, sizeof(a)); + a3 = (a *) AXIS2_MALLOC(env->allocator, sizeof(a)); + a4 = (a *) AXIS2_MALLOC(env->allocator, sizeof(a)); + + a1->value = axutil_strdup(env, "value1"); + a2->value = axutil_strdup(env, "value2"); + a3->value = axutil_strdup(env, "value3"); + a4->value = axutil_strdup(env, "value4"); + + ht = axutil_hash_make(env); + + axutil_hash_set(ht, key1, AXIS2_HASH_KEY_STRING, a1); + axutil_hash_set(ht, key2, AXIS2_HASH_KEY_STRING, a2); + axutil_hash_set(ht, key3, AXIS2_HASH_KEY_STRING, a3); + axutil_hash_set(ht, key4, AXIS2_HASH_KEY_STRING, a4); + + axutil_hash_set(ht, key2, AXIS2_HASH_KEY_STRING, NULL); + axutil_hash_set(ht, key2, AXIS2_HASH_KEY_STRING, a2); + for (i = axutil_hash_first(ht, env); i; i = axutil_hash_next(env, i)) + { + axutil_hash_this(i, NULL, NULL, &v); + printf("\n %s \n", ((a *) v)->value); + } + + printf("\n demo get %s ", + ((a *) axutil_hash_get(ht, key1, AXIS2_HASH_KEY_STRING))->value); + + printf("\n demo get %s ", + ((a *) axutil_hash_get(ht, key2, AXIS2_HASH_KEY_STRING))->value); + + printf("\n demo get %s ", + ((a *) axutil_hash_get(ht, key3, AXIS2_HASH_KEY_STRING))->value); + + printf("\n demo get %s \n", + ((a *) axutil_hash_get(ht, key4, AXIS2_HASH_KEY_STRING))->value); + + axutil_hash_free(ht, env); + AXIS2_FREE(env->allocator, a1->value); + AXIS2_FREE(env->allocator, a2->value); + AXIS2_FREE(env->allocator, a3->value); + AXIS2_FREE(env->allocator, a4->value); + AXIS2_FREE(env->allocator, a1); + AXIS2_FREE(env->allocator, a2); + AXIS2_FREE(env->allocator, a3); + AXIS2_FREE(env->allocator, a4); + return 0; +} + +void +test_axutil_dir_handler_list_service_or_module_dirs( + ) +{ + int i, + isize; + axutil_file_t *file = NULL; + axis2_char_t *filename = NULL; + axutil_allocator_t *allocator = axutil_allocator_init(NULL); + axutil_error_t *error = axutil_error_create(allocator); + axutil_log_t *log = axutil_log_create(allocator, NULL, NULL); + const axutil_env_t *env = + axutil_env_create_with_error_log(allocator, error, log); + + axis2_char_t *pathname = axutil_strdup(env, "/tmp/test/"); + + axutil_array_list_t *arr_folders = + axutil_dir_handler_list_service_or_module_dirs(env, pathname); + if (arr_folders == NULL) + { + printf("List of folders is NULL\n"); + return; + } + + isize = axutil_array_list_size(arr_folders, env); + printf("Folder array size = %d \n", isize); + + for (i = 0; i < isize; ++i) + { + file = (axutil_file_t *) axutil_array_list_get(arr_folders, env, i); + filename = axutil_file_get_name(file, env); + printf("filename = %s \n", filename); + } + printf + ("----end of test_axutil_dir_handler_list_service_or_module_dirs----\n"); + +} + +/** + * This test is intended to test whether given two files are equal or not. + * Spaces and new lines are ignored in comparing + */ +int +test_file_diff( + const axutil_env_t * env) +{ + /* axis2_char_t *expected_file_name = axutil_strdup("expected", env); + axis2_char_t *actual_file_name = axutil_strdup("actual", env); */ + return 0; +} + +void +test_array_list( + const axutil_env_t * env) +{ + axutil_array_list_t *al; + a *entry = NULL; + int size; + + al = axutil_array_list_create(env, 1); + printf("list size %d\n", axutil_array_list_size(al, env)); + + entry = (a *) AXIS2_MALLOC(env->allocator, sizeof(a)); + entry->value = axutil_strdup(env, "value1"); + axutil_array_list_add(al, env, (void *) entry); + + entry = (a *) AXIS2_MALLOC(env->allocator, sizeof(a)); + entry->value = axutil_strdup(env, "value2"); + axutil_array_list_add(al, env, (void *) entry); + + entry = (a *) AXIS2_MALLOC(env->allocator, sizeof(a)); + entry->value = axutil_strdup(env, "value3"); + axutil_array_list_add(al, env, (void *) entry); + + entry = (a *) AXIS2_MALLOC(env->allocator, sizeof(a)); + entry->value = axutil_strdup(env, "value4"); + axutil_array_list_add(al, env, (void *) entry); + + entry = (a *) AXIS2_MALLOC(env->allocator, sizeof(a)); + entry->value = axutil_strdup(env, "value5"); + axutil_array_list_add(al, env, (void *) entry); + + entry = (a *) AXIS2_MALLOC(env->allocator, sizeof(a)); + entry->value = axutil_strdup(env, "value6"); + axutil_array_list_add(al, env, (void *) entry); + + entry = (a *) AXIS2_MALLOC(env->allocator, sizeof(a)); + entry->value = axutil_strdup(env, "value7"); + axutil_array_list_set(al, env, 3, (void *) entry); + axutil_array_list_remove(al, env, 2); + + entry = (a *) axutil_array_list_get(al, env, 0); + printf("entry->value:%s\n", entry->value); + + entry = (a *) axutil_array_list_get(al, env, 2); + printf("entry->value:%s\n", entry->value); + size = axutil_array_list_size(al, env); + printf("list size %d\n", axutil_array_list_size(al, env)); + +} + +void +test_uuid_gen( + const axutil_env_t * env) +{ + char *uuid = NULL; + printf("starting uuid_gen test...\n"); + uuid = axutil_uuid_gen(env); + printf("Generated UUID 1:%s\n", uuid); + AXIS2_FREE(env->allocator, uuid); + uuid = axutil_uuid_gen(env); + printf("Generated UUID 2:%s\n", uuid); + AXIS2_FREE(env->allocator, uuid); + printf("finished uuid_gen test...\n"); +} + +void +test_log_write( + ) +{ + char msg[10]; + printf("start of test_log_write\n\n"); + axutil_allocator_t *allocator = axutil_allocator_init(NULL); + if (!allocator) + { + printf("allocator is NULL\n"); + return; + } + axutil_error_t *error = axutil_error_create(allocator); + if (!error) + { + printf("cannot create error\n"); + return; + } + axutil_log_t *log22 = axutil_log_create(allocator, NULL, NULL); + if (!log22) + { + printf("cannot create log\n"); + return; + } + log22->level = AXIS2_LOG_LEVEL_DEBUG; + + const axutil_env_t *env = + axutil_env_create_with_error_log(allocator, error, log22); + if (!env) + { + printf("cannot create env with error and log\n"); + return; + } + strcpy(msg, "abcd test123"); + + AXIS2_LOG_CRITICAL(env->log, AXIS2_LOG_SI, "log1 %s", "test1"); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "log2 %d", 2); + AXIS2_LOG_WARNING(env->log, AXIS2_LOG_SI, "log3 %s", "test3"); + AXIS2_LOG_INFO(env->log, AXIS2_LOG_SI, "log4 %s %s", "info1", "info2"); + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "log5 %s %d", "test", 5); + printf("end of test_log_write \n\n"); + +} + +int +main( + void) +{ + const axutil_env_t *env = test_init(); + test_hash_get(env); + test_file_diff(env); + test_array_list(env); + test_uuid_gen(env); + test_md5(env); + run_test_log(); + run_test_string(env); + test_axutil_dir_handler_list_service_or_module_dirs(); + axutil_allocator_t *allocator = env->allocator; + +/* axutil_env_free(env);*/ + axutil_allocator_free(allocator); + return 0; +} diff --git a/util/test/utils/Makefile.am b/util/test/utils/Makefile.am new file mode 100644 index 0000000..0fbcc8d --- /dev/null +++ b/util/test/utils/Makefile.am @@ -0,0 +1,13 @@ +TESTS = utils_test +check_PROGRAMS = utils_test +noinst_PROGRAMS = utils_test +utils_test_SOURCES = utils_test.c ../util/create_env.c + +utils_test_LDADD = \ + $(top_builddir)/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../axiom/include \ + -I ../../../include + + diff --git a/util/test/utils/build.sh b/util/test/utils/build.sh new file mode 100644 index 0000000..09e7ef6 --- /dev/null +++ b/util/test/utils/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +gcc utils_test.c ../util/create_env.c -g -I$AXIS2C_HOME/include/axis2-1.2 -L$AXIS2C_HOME/lib -laxutil -laxis2_axiom -laxis2_parser -o utils_test diff --git a/util/test/utils/utils_test.c b/util/test/utils/utils_test.c new file mode 100644 index 0000000..2bbf67f --- /dev/null +++ b/util/test/utils/utils_test.c @@ -0,0 +1,47 @@ +#include "../util/create_env.h" +#include <axutil_utils.h> + +axutil_env_t *env = NULL; +axis2_char_t * request = "This is a requset"; +axis2_char_t * s = "<root>This is a & '""xml string</root>"; +axis2_char_t c = 'c'; + +/** @brief test utils + * test quote string + */ + +axis2_status_t test_utils() +{ + axis2_char_t **op, *quote_string; + int hexit; + env = create_environment(); + op = axutil_parse_request_url_for_svc_and_op(env,request); + quote_string = axutil_xml_quote_string(env,s,1); + printf("The quote string is%s\n",(char *)quote_string); + hexit = axutil_hexit(c); + printf("%d\n",hexit); + if(op && quote_string) + { + printf("The test is SUCCESS\n"); + } + if(!op || !quote_string) + { + printf("The test is FAIL"); + } + return AXIS2_SUCCESS; +} +int main() +{ + int status = AXIS2_SUCCESS; + env = create_environment(); + status = test_utils(); + if(status == AXIS2_FAILURE) + { + printf(" test failed"); + } + axutil_env_free(env); + return 0; +} + + + |