From 0425aadc78680e53000fd0108b540d6eca048516 Mon Sep 17 00:00:00 2001 From: gmcdonald Date: Sat, 13 Feb 2010 01:32:03 +0000 Subject: Moving axis svn, part of TLP move INFRA-2441 git-svn-id: http://svn.apache.org/repos/asf/axis/axis2/c/core/trunk@909681 13f79535-47bb-0310-9956-ffa450edef68 --- tools/codegen/javatool/README | 29 + tools/codegen/javatool/WSDL2C.bat | 9 + tools/codegen/javatool/WSDL2C.sh | 11 + tools/md5/AUTHORS | 0 tools/md5/COPYING | 203 ++++++ tools/md5/ChangeLog | 0 tools/md5/INSTALL | 14 + tools/md5/LICENSE | 203 ++++++ tools/md5/Makefile.am | 5 + tools/md5/NEWS | 0 tools/md5/README | 21 + tools/md5/autogen.sh | 50 ++ tools/md5/build.sh | 13 + tools/md5/configure.ac | 75 +++ tools/md5/src/Makefile.am | 14 + tools/md5/src/md5.c | 80 +++ tools/md5/test/Makefile.am | 1 + tools/tcpmon/AUTHORS | 0 tools/tcpmon/COPYING | 203 ++++++ tools/tcpmon/ChangeLog | 0 tools/tcpmon/INSTALL | 14 + tools/tcpmon/LICENSE | 203 ++++++ tools/tcpmon/Makefile.am | 6 + tools/tcpmon/NEWS | 0 tools/tcpmon/README | 21 + tools/tcpmon/autogen.sh | 50 ++ tools/tcpmon/build.sh | 13 + tools/tcpmon/configure.ac | 122 ++++ tools/tcpmon/include/tcpmon_entry.h | 234 +++++++ tools/tcpmon/include/tcpmon_session.h | 291 +++++++++ tools/tcpmon/include/tcpmon_util.h | 91 +++ tools/tcpmon/src/Makefile.am | 21 + tools/tcpmon/src/entry.c | 656 +++++++++++++++++++ tools/tcpmon/src/session.c | 632 +++++++++++++++++++ tools/tcpmon/src/tcpmon.c | 1037 +++++++++++++++++++++++++++++++ tools/tcpmon/src/tcpmon_entry_local.h | 16 + tools/tcpmon/src/tcpmon_session_local.h | 15 + tools/tcpmon/src/util.c | 806 ++++++++++++++++++++++++ tools/tcpmon/test/Makefile.am | 1 + tools/tcpmon/test/unit/Makefile.am | 19 + tools/tcpmon/test/unit/main.c | 44 ++ tools/tcpmon/test/unit/result | 14 + tools/tcpmon/test/unit/tcpmon_test.c | 85 +++ tools/tcpmon/test/unit/tcpmon_test.h | 9 + 44 files changed, 5331 insertions(+) create mode 100644 tools/codegen/javatool/README create mode 100644 tools/codegen/javatool/WSDL2C.bat create mode 100755 tools/codegen/javatool/WSDL2C.sh create mode 100644 tools/md5/AUTHORS create mode 100644 tools/md5/COPYING create mode 100644 tools/md5/ChangeLog create mode 100644 tools/md5/INSTALL create mode 100644 tools/md5/LICENSE create mode 100644 tools/md5/Makefile.am create mode 100644 tools/md5/NEWS create mode 100644 tools/md5/README create mode 100755 tools/md5/autogen.sh create mode 100644 tools/md5/build.sh create mode 100644 tools/md5/configure.ac create mode 100644 tools/md5/src/Makefile.am create mode 100644 tools/md5/src/md5.c create mode 100644 tools/md5/test/Makefile.am create mode 100644 tools/tcpmon/AUTHORS create mode 100644 tools/tcpmon/COPYING create mode 100644 tools/tcpmon/ChangeLog create mode 100644 tools/tcpmon/INSTALL create mode 100644 tools/tcpmon/LICENSE create mode 100644 tools/tcpmon/Makefile.am create mode 100644 tools/tcpmon/NEWS create mode 100644 tools/tcpmon/README create mode 100755 tools/tcpmon/autogen.sh create mode 100644 tools/tcpmon/build.sh create mode 100644 tools/tcpmon/configure.ac create mode 100644 tools/tcpmon/include/tcpmon_entry.h create mode 100644 tools/tcpmon/include/tcpmon_session.h create mode 100644 tools/tcpmon/include/tcpmon_util.h create mode 100644 tools/tcpmon/src/Makefile.am create mode 100644 tools/tcpmon/src/entry.c create mode 100644 tools/tcpmon/src/session.c create mode 100644 tools/tcpmon/src/tcpmon.c create mode 100644 tools/tcpmon/src/tcpmon_entry_local.h create mode 100644 tools/tcpmon/src/tcpmon_session_local.h create mode 100644 tools/tcpmon/src/util.c create mode 100644 tools/tcpmon/test/Makefile.am create mode 100644 tools/tcpmon/test/unit/Makefile.am create mode 100644 tools/tcpmon/test/unit/main.c create mode 100644 tools/tcpmon/test/unit/result create mode 100644 tools/tcpmon/test/unit/tcpmon_test.c create mode 100644 tools/tcpmon/test/unit/tcpmon_test.h (limited to 'tools') diff --git a/tools/codegen/javatool/README b/tools/codegen/javatool/README new file mode 100644 index 0000000..395bbb0 --- /dev/null +++ b/tools/codegen/javatool/README @@ -0,0 +1,29 @@ +WSDL2C.sh and WSDL2C.bat +======================== + +These scripts are provided to simplify the C code generation using WSDL2C Java tool that comes with Apache Axis2/Java. + +How to use +---------- +1. Set AXIS2_HOME envionment vaiable to you Axis2 Java installation directory. + eg: 'export AXIS2_HOME=/home/axis2java' +3. Run WSDL2C.sh giving WSDL2C command line arguments as the arguments to the shell script. + +Note: Do the same for the bat file on Windows. + + +Examples +-------- + +To generate a sevice skeleton in C: +Linux: + sh WSDL2C.sh -uri interoptestdoclitparameters.wsdl -ss -sd -d adb -u +Windows: + WSDL2C.bat -uri interoptestdoclitparameters.wsdl -ss -sd -d adb -u + +To generate a client stub in C: +Linux: + sh WSDL2C.sh -uri interoptestdoclitparameters.wsdl -d adb -u +Windows + WSDL2C.bat -uri interoptestdoclitparameters.wsdl -d adb -u + diff --git a/tools/codegen/javatool/WSDL2C.bat b/tools/codegen/javatool/WSDL2C.bat new file mode 100644 index 0000000..d97b038 --- /dev/null +++ b/tools/codegen/javatool/WSDL2C.bat @@ -0,0 +1,9 @@ +echo off +REM set AXIS2_HOME=C:\axis2-SNAPSHOT +setlocal EnableDelayedExpansion +set AXIS2_CLASSPATH=%AXIS2_HOME% +FOR %%c in ("%AXIS2_HOME%\lib\*.jar") DO set AXIS2_CLASSPATH=!AXIS2_CLASSPATH!;%%c; + +java -classpath %AXIS2_CLASSPATH% org.apache.axis2.wsdl.WSDL2C %* + + diff --git a/tools/codegen/javatool/WSDL2C.sh b/tools/codegen/javatool/WSDL2C.sh new file mode 100755 index 0000000..7882533 --- /dev/null +++ b/tools/codegen/javatool/WSDL2C.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +#export AXIS2_HOME=/home/axis2java +for f in $AXIS2_HOME/lib/*.jar +do + AXIS2_CLASSPATH=$AXIS2_CLASSPATH:$f +done +export AXIS2_CLASSPATH + +echo the classpath $AXIS2_CLASSPATH +java -classpath $AXIS2_CLASSPATH org.apache.axis2.wsdl.WSDL2C $* diff --git a/tools/md5/AUTHORS b/tools/md5/AUTHORS new file mode 100644 index 0000000..e69de29 diff --git a/tools/md5/COPYING b/tools/md5/COPYING new file mode 100644 index 0000000..6b0b127 --- /dev/null +++ b/tools/md5/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/tools/md5/ChangeLog b/tools/md5/ChangeLog new file mode 100644 index 0000000..e69de29 diff --git a/tools/md5/INSTALL b/tools/md5/INSTALL new file mode 100644 index 0000000..a151ea5 --- /dev/null +++ b/tools/md5/INSTALL @@ -0,0 +1,14 @@ +Getting Axis2/C md5 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/md5 directory. + + + diff --git a/tools/md5/LICENSE b/tools/md5/LICENSE new file mode 100644 index 0000000..6b0b127 --- /dev/null +++ b/tools/md5/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/tools/md5/Makefile.am b/tools/md5/Makefile.am new file mode 100644 index 0000000..0020f57 --- /dev/null +++ b/tools/md5/Makefile.am @@ -0,0 +1,5 @@ +datadir=$(prefix)/bin/tools/md5 +SUBDIRS = src +includedir=$(prefix)/include/axis2-1.6.0 +data_DATA= INSTALL README AUTHORS NEWS LICENSE COPYING +EXTRA_DIST=LICENSE diff --git a/tools/md5/NEWS b/tools/md5/NEWS new file mode 100644 index 0000000..e69de29 diff --git a/tools/md5/README b/tools/md5/README new file mode 100644 index 0000000..48433b8 --- /dev/null +++ b/tools/md5/README @@ -0,0 +1,21 @@ + Axis2C MD5 Generator + ====================== + +What is it? +----------- + +Axis2 MD5 project is aimed at generating md5 checksums for files. It works only in command line interface. + +How to run the MD5 Generator? +----------------------------- + +Run the file called md5 with the File Name. +For instruction run md5 -h + + +Installation +------------ + +Please see the file called INSTALL. + + diff --git a/tools/md5/autogen.sh b/tools/md5/autogen.sh new file mode 100755 index 0000000..718c23c --- /dev/null +++ b/tools/md5/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/tools/md5/build.sh b/tools/md5/build.sh new file mode 100644 index 0000000..17d3548 --- /dev/null +++ b/tools/md5/build.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +./autogen.sh + +if test -z ${AXIS2C_HOME} +then + AXIS2C_HOME=`pwd`/../deploy +fi + +export AXIS2C_HOME + +./configure --prefix=${AXIS2C_HOME} --enable-tests=no +make diff --git a/tools/md5/configure.ac b/tools/md5/configure.ac new file mode 100644 index 0000000..213ab14 --- /dev/null +++ b/tools/md5/configure.ac @@ -0,0 +1,75 @@ +dnl run autogen.sh to generate the configure script. + +AC_PREREQ(2.59) + +AC_INIT(md5-src, 1.6.0) +AC_CANONICAL_SYSTEM +AM_CONFIG_HEADER(config.h) +AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION) +AC_PREFIX_DEFAULT(/usr/local/md5) + +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 + + +CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE -g" +if test "$GCC" = "yes"; then + CFLAGS="$CFLAGS -ansi -Wall -Wno-implicit-function-declaration" +fi + +LDFLAGS="$LDFLAGS -lpthread" + +dnl Checks for header files. +AC_HEADER_STDC +AC_CHECK_HEADERS([stdio.h stdlib.h string.h]) + +dnl Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST + +dnl Checks for library functions. +AC_FUNC_MALLOC +AC_FUNC_REALLOC +AC_CHECK_FUNCS([memmove]) + +AC_CHECK_LIB(z, inflate) +dnl AC_CHECK_LIB(cutest, CuTestInit) + + +AC_MSG_CHECKING(whether to build tests) +AC_ARG_ENABLE(tests, +[ --enable-tests build tests. default=no], +[ case "${enableval}" in + no) + AC_MSG_RESULT(no) + TESTDIR="" + ;; + *) + AC_MSG_RESULT(yes) + TESTDIR="test" + + ;; + esac ], + AC_MSG_RESULT(no) + TESTDIR="" +) + + +UTILINC=$axis2_utilinc + +AC_SUBST(UTILINC) +AC_SUBST(TESTDIR) +AC_SUBST(WRAPPER_DIR) + +CFLAGS="$CFLAGS" + +AC_CONFIG_FILES([Makefile \ + src/Makefile \ + ]) + +AC_OUTPUT diff --git a/tools/md5/src/Makefile.am b/tools/md5/src/Makefile.am new file mode 100644 index 0000000..40be3c9 --- /dev/null +++ b/tools/md5/src/Makefile.am @@ -0,0 +1,14 @@ +prgbindir=$(prefix)/bin/tools/md5 + +prgbin_PROGRAMS = md5 + +md5_SOURCES = md5.c + +md5_LDADD = \ + ../../../util/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../util/include \ + -I ../../../include \ + -I ../include + diff --git a/tools/md5/src/md5.c b/tools/md5/src/md5.c new file mode 100644 index 0000000..81ae359 --- /dev/null +++ b/tools/md5/src/md5.c @@ -0,0 +1,80 @@ + +/* + * 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 +#include +#include + +static void md5_file (char *filename, const axutil_env_t * env) +{ + FILE * file; + axutil_md5_ctx_t * context; + int len, i; + unsigned char buffer[1024], digest[16]; + + if ((file = fopen (filename, "rb")) == NULL) + { + printf ("%s can't be opened\n", filename); + } + else + { + context = axutil_md5_ctx_create(env); + while ((len = fread (buffer, 1, 1024, file)) != 0) + { + axutil_md5_update(context, env, buffer, len); + } + axutil_md5_final(context, env, digest); + axutil_md5_ctx_free(context, env); + fclose (file); + printf ("MD5 (%s) = ", filename); + for (i = 0; i < 16; i++) + { + printf ("%02x", digest[i]); + } + printf ("\n"); + } +} + +int +main( + int argc, + char **argv) +{ + const axutil_env_t *env = NULL; + + env = axutil_env_create_all("md5.log", AXIS2_LOG_LEVEL_DEBUG); + if (argc > 1) + { + if (axutil_strcmp(argv[1], "-h") == 0) + { + printf("Usage : %s [file_name]\n", argv[0]); + printf("use -h for help\n"); + return 0; + } + else + { + md5_file(argv[1], env); + } + } + if (env) + { + axutil_env_free((axutil_env_t *) env); + env = NULL; + } + return 0; +} diff --git a/tools/md5/test/Makefile.am b/tools/md5/test/Makefile.am new file mode 100644 index 0000000..85eb6ca --- /dev/null +++ b/tools/md5/test/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = unit diff --git a/tools/tcpmon/AUTHORS b/tools/tcpmon/AUTHORS new file mode 100644 index 0000000..e69de29 diff --git a/tools/tcpmon/COPYING b/tools/tcpmon/COPYING new file mode 100644 index 0000000..6b0b127 --- /dev/null +++ b/tools/tcpmon/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/tools/tcpmon/ChangeLog b/tools/tcpmon/ChangeLog new file mode 100644 index 0000000..e69de29 diff --git a/tools/tcpmon/INSTALL b/tools/tcpmon/INSTALL new file mode 100644 index 0000000..fb59719 --- /dev/null +++ b/tools/tcpmon/INSTALL @@ -0,0 +1,14 @@ +Getting Axis2/C tcpmon 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/tcpmon directory. + + + diff --git a/tools/tcpmon/LICENSE b/tools/tcpmon/LICENSE new file mode 100644 index 0000000..6b0b127 --- /dev/null +++ b/tools/tcpmon/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/tools/tcpmon/Makefile.am b/tools/tcpmon/Makefile.am new file mode 100644 index 0000000..243c271 --- /dev/null +++ b/tools/tcpmon/Makefile.am @@ -0,0 +1,6 @@ +datadir=$(prefix)/bin/tools/tcpmon +SUBDIRS = src +includedir=$(prefix)/include/axis2-1.6.0 +include_HEADERS=$(top_builddir)/include/*.h +data_DATA= INSTALL README AUTHORS NEWS LICENSE COPYING +EXTRA_DIST=LICENSE diff --git a/tools/tcpmon/NEWS b/tools/tcpmon/NEWS new file mode 100644 index 0000000..e69de29 diff --git a/tools/tcpmon/README b/tools/tcpmon/README new file mode 100644 index 0000000..23755f4 --- /dev/null +++ b/tools/tcpmon/README @@ -0,0 +1,21 @@ + Axis2C TCP Monitor + ======================= + +What is it? +----------- + +Axis2 TCP monitor project is aimed at capture the SOAP messages sent and received. It works only in command line interface. + +How to run the TCP monitor? +--------------------------- + +Run the file called tcpmon with the Listen Port, Target port and Host name. +For instruction run tcpmon -h + + +Installation +------------ + +Please see the file called INSTALL. + + diff --git a/tools/tcpmon/autogen.sh b/tools/tcpmon/autogen.sh new file mode 100755 index 0000000..718c23c --- /dev/null +++ b/tools/tcpmon/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/tools/tcpmon/build.sh b/tools/tcpmon/build.sh new file mode 100644 index 0000000..17d3548 --- /dev/null +++ b/tools/tcpmon/build.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +./autogen.sh + +if test -z ${AXIS2C_HOME} +then + AXIS2C_HOME=`pwd`/../deploy +fi + +export AXIS2C_HOME + +./configure --prefix=${AXIS2C_HOME} --enable-tests=no +make diff --git a/tools/tcpmon/configure.ac b/tools/tcpmon/configure.ac new file mode 100644 index 0000000..5619c87 --- /dev/null +++ b/tools/tcpmon/configure.ac @@ -0,0 +1,122 @@ +dnl run autogen.sh to generate the configure script. + +AC_PREREQ(2.59) + +AC_INIT(tcpmon-src, 1.6.0) +AC_CANONICAL_SYSTEM +AM_CONFIG_HEADER(config.h) +AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION) +AC_PREFIX_DEFAULT(/usr/local/tcpmon) + +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 + + +CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE -g" +if test "$GCC" = "yes"; then + CFLAGS="$CFLAGS -ansi -Wall -Wno-implicit-function-declaration" +fi + +LDFLAGS="$LDFLAGS -lpthread" + +dnl Checks for header files. +AC_HEADER_STDC +AC_CHECK_HEADERS([stdio.h stdlib.h string.h]) + +dnl Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST + +dnl Checks for library functions. +AC_FUNC_MALLOC +AC_FUNC_REALLOC +AC_CHECK_FUNCS([memmove]) + +AC_CHECK_LIB(z, inflate) +dnl AC_CHECK_LIB(cutest, CuTestInit) + + +AC_MSG_CHECKING(whether to build tests) +AC_ARG_ENABLE(tests, +[ --enable-tests build tests. default=no], +[ case "${enableval}" in + no) + AC_MSG_RESULT(no) + TESTDIR="" + ;; + *) + AC_MSG_RESULT(yes) + TESTDIR="test" + + ;; + esac ], + AC_MSG_RESULT(no) + TESTDIR="" +) + +GUTHTHILA_LIBS="" + +AC_MSG_CHECKING(whether to build guththila xml parser library) +AC_ARG_ENABLE(guththila, [ --enable-guththila + build Guththila XML parser library wrapper (default=yes)], +[ case "${enableval}" in + no) + AC_MSG_RESULT(no) + ;; + *) + AC_MSG_RESULT(yes) + CFLAGS="$CFLAGS -DAXIS2_GUTHTHILA_ENABLED" + CPPFLAGS="$CPPFLAGS -DAXIS2_GUTHTHILA_ENABLED" + WRAPPER_DIR="guththila" + + ;; + esac ], + AC_MSG_RESULT(yes) + WRAPPER_DIR="guththila" + CFLAGS="$CFLAGS -DAXIS2_GUTHTHILA_ENABLED" + CPPFLAGS="$CPPFLAGS -DAXIS2_GUTHTHILA_ENABLED" + AC_CONFIG_SUBDIRS(guththila) + GUTHTHILA_LIBS="/guththila/src/" + GUTHTHILA_DIR="guththila" +) + + +AC_MSG_CHECKING(whether to build libxml2 xml parser library) +AC_ARG_ENABLE(libxml2, [ --enable-libxml2 + build Libxml2 XML parser library wrapper (default=no)], +[ case "${enableval}" in + no) + AC_MSG_RESULT(no) + WRAPPER_DIR="" + ;; + *) + AC_MSG_RESULT(yes) + WRAPPER_DIR="libxml2" + PKG_CHECK_MODULES(LIBXML2, libxml-2.0) + CFLAGS="$CFLAGS -DAXIS2_LIBXML2_ENABLED" + CPPFLAGS="$CPPFLAGS $PARSER_CFLAGS -DAXIS2_LIBXML2_ENABLED" + LDFLAGS="$LDFLAGS $PARSER_LIBS" + ;; + esac ], + AC_MSG_RESULT(no) +) + + +UTILINC=$axis2_utilinc + +AC_SUBST(UTILINC) +AC_SUBST(TESTDIR) +AC_SUBST(WRAPPER_DIR) + +CFLAGS="$CFLAGS" + +AC_CONFIG_FILES([Makefile \ + src/Makefile \ + ]) + +AC_OUTPUT diff --git a/tools/tcpmon/include/tcpmon_entry.h b/tools/tcpmon/include/tcpmon_entry.h new file mode 100644 index 0000000..b918ad5 --- /dev/null +++ b/tools/tcpmon/include/tcpmon_entry.h @@ -0,0 +1,234 @@ + +/* + * 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 TCPMON_ENTRY_H +#define TCPMON_ENTRY_H + +#include +#include + +/** + * @file tcpmon_entry.h + * @brief represent entry of tcpmon + */ + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup represent entry of tcpmon + * @ingroup tcpmon + * @{ + */ + + typedef struct tcpmon_entry_ops tcpmon_entry_ops_t; + typedef struct tcpmon_entry tcpmon_entry_t; + + struct tcpmon_entry_ops + { + + /** + * free the tcpmon_entry. + * @param entry represet the type object. + * @param env pointer to environment struct. MUST NOT be NULL. + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE. + */ + axis2_status_t( + AXIS2_CALL + * free)( + tcpmon_entry_t * entry, + const axutil_env_t * env); + + /** + * retrieve the arrived_time + * @param entry represet the type object. + * @param env pointer to environment struct. MUST NOT be NULL. + */ + axis2_char_t *( + AXIS2_CALL + * arrived_time)( + tcpmon_entry_t * entry, + const axutil_env_t * env); + + /** + * retrieve the sent_time + * @param entry represet the type object. + * @param env pointer to environment struct. MUST NOT be NULL. + */ + axis2_char_t *( + AXIS2_CALL + * sent_time)( + tcpmon_entry_t * entry, + const axutil_env_t * env); + + /** + * retrieve the arrived_time - sent_time ( in seconds) + * @param entry represet the type object. + * @param env pointer to environment struct. MUST NOT be NULL. + */ + axis2_char_t *( + AXIS2_CALL + * time_diff)( + tcpmon_entry_t * entry, + const axutil_env_t * env); + + /** + * retrieve the sent data + * @param entry represet the type object. + * @param env pointer to environment struct. MUST NOT be NULL. + */ + axis2_char_t *( + AXIS2_CALL + * sent_data)( + tcpmon_entry_t * entry, + const axutil_env_t * env); + + /** + * retrieve the arrived data + * @param entry represet the type object. + * @param env pointer to environment struct. MUST NOT be NULL. + */ + axis2_char_t *( + AXIS2_CALL + * arrived_data)( + tcpmon_entry_t * entry, + const axutil_env_t * env); + + /** + * retrieve the sent headers + * @param entry represet the type object. + * @param env pointer to environment struct. MUST NOT be NULL. + */ + axis2_char_t *( + AXIS2_CALL + * sent_headers)( + tcpmon_entry_t * entry, + const axutil_env_t * env); + + /** + * retrieve the arrived headers + * @param entry represet the type object. + * @param env pointer to environment struct. MUST NOT be NULL. + */ + axis2_char_t *( + AXIS2_CALL + * arrived_headers)( + tcpmon_entry_t * entry, + const axutil_env_t * env); + + /** + * retrieve whether the transportation success + * @param entry represet the type object. + * @param env pointer to environment struct. MUST NOT be NULL. + */ + axis2_bool_t( + AXIS2_CALL + * is_success)( + tcpmon_entry_t * entry, + const axutil_env_t * env); + + int( + AXIS2_CALL + * get_format_bit)( + tcpmon_entry_t * entry, + const axutil_env_t * env); + + int( + AXIS2_CALL + * get_sent_data_length)( + tcpmon_entry_t * entry, + const axutil_env_t * env); + + int( + AXIS2_CALL + * get_arrived_data_length)( + tcpmon_entry_t * entry, + const axutil_env_t * env); + + axis2_status_t( + AXIS2_CALL + * set_format_bit)( + tcpmon_entry_t * entry, + const axutil_env_t * env, + int format_bit); + }; + + struct tcpmon_entry + { + tcpmon_entry_ops_t *ops; + }; + + /** + * Creates tcpmon_entry struct + * @param env double pointer to environment struct. MUST NOT be NULL + * @return pointer to newly created tcpmon_entry struct + */ + tcpmon_entry_t *AXIS2_CALL + tcpmon_entry_create( + const axutil_env_t * env); + + /*************************** Function macros **********************************/ + +#define TCPMON_ENTRY_FREE(entry, env) \ + ((entry)->ops->free (entry, env)) + +#define TCPMON_ENTRY_ARRIVED_TIME(entry, env) \ + ((entry)->ops->arrived_time(entry, env)) + +#define TCPMON_ENTRY_SENT_TIME(entry, env) \ + ((entry)->ops->sent_time(entry, env)) + +#define TCPMON_ENTRY_TIME_DIFF(entry, env) \ + ((entry)->ops->time_diff(entry, env)) + +#define TCPMON_ENTRY_SENT_DATA(entry, env) \ + ((entry)->ops->sent_data(entry, env)) + +#define TCPMON_ENTRY_ARRIVED_DATA(entry, env) \ + ((entry)->ops->arrived_data(entry, env)) + +#define TCPMON_ENTRY_SENT_HEADERS(entry, env) \ + ((entry)->ops->sent_headers(entry, env)) + +#define TCPMON_ENTRY_ARRIVED_HEADERS(entry, env) \ + ((entry)->ops->arrived_headers(entry, env)) + +#define TCPMON_ENTRY_IS_SUCCESS(entry, env) \ + ((entry)->ops->is_success(entry, env)) + +#define TCPMON_ENTRY_SET_FORMAT_BIT(entry, env, format_bit) \ + ((entry)->ops->set_format_bit(entry, env, format_bit)) + +#define TCPMON_ENTRY_GET_FORMAT_BIT(entry, env) \ + ((entry)->ops->get_format_bit(entry, env)) + +#define TCPMON_ENTRY_GET_SENT_DATA_LENGTH(entry, env) \ + ((entry)->ops->get_sent_data_length(entry, env)) + +#define TCPMON_ENTRY_GET_ARRIVED_DATA_LENGTH(entry, env) \ + ((entry)->ops->get_arrived_data_length(entry, env)) + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* TCPMON_ENTRY_H */ diff --git a/tools/tcpmon/include/tcpmon_session.h b/tools/tcpmon/include/tcpmon_session.h new file mode 100644 index 0000000..53181c5 --- /dev/null +++ b/tools/tcpmon/include/tcpmon_session.h @@ -0,0 +1,291 @@ + +/* + * 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 TCPMON_SESSION_H +#define TCPMON_SESSION_H + +#include +#include +#include + +/** + * @file tcpmon_session.h + * @brief represent session of tcpmon + */ + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup represent session of tcpmon + * @ingroup tcpmon + * @{ + */ + + typedef struct tcpmon_session_ops tcpmon_session_ops_t; + typedef struct tcpmon_session tcpmon_session_t; + + /** + * callback functions for the tcpmon session + */ + typedef int( + *TCPMON_SESSION_NEW_ENTRY_FUNCT)( + const axutil_env_t * env, + tcpmon_entry_t * entry, + int status); /* 0-started, 1-finished */ + + typedef int( + *TCPMON_SESSION_TRANS_ERROR_FUNCT)( + const axutil_env_t * env, + axis2_char_t * error_message); + + struct tcpmon_session_ops + { + + /** + * free the tcpmon_session. + * @param session represet the type object. + * @param env pointer to environment struct. MUST NOT be NULL. + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE. + */ + axis2_status_t( + AXIS2_CALL + * free)( + tcpmon_session_t * session, + const axutil_env_t * env); + + axis2_status_t( + AXIS2_CALL + * set_test_bit)( + tcpmon_session_t * session, + const axutil_env_t * env, + int test_bit); + + axis2_status_t( + AXIS2_CALL + * get_test_bit)( + tcpmon_session_t * session, + const axutil_env_t * env); + axis2_status_t( + AXIS2_CALL + * set_format_bit)( + tcpmon_session_t * session, + const axutil_env_t * env, + int format_bit); + + int( + AXIS2_CALL + * get_format_bit)( + tcpmon_session_t * session, + const axutil_env_t * env); + + /** + * configure the listening port. + * @param session represet the type object. + * @param env pointer to environment struct. MUST NOT be NULL. + * @param listen_port listening port ( port of a localhost). + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE. + */ + axis2_status_t( + AXIS2_CALL + * set_listen_port)( + tcpmon_session_t * session, + const axutil_env_t * env, + int listen_port); + + /** + * retrieve the listening port + * @param session represet the type object. + * @param env pointer to environment struct. MUST NOT be NULL. + */ + int( + AXIS2_CALL + * get_listen_port)( + tcpmon_session_t * session, + const axutil_env_t * env); + + /** + * configure the target port + * @param session represet the type object. + * @param env pointer to environment struct. MUST NOT be NULL. + * @param target_port tartet port + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE. + */ + axis2_status_t( + AXIS2_CALL + * set_target_port)( + tcpmon_session_t * session, + const axutil_env_t * env, + int target_port); + + /** + * retrieve the target port + * @param session represet the type object. + * @param env pointer to environment struct. MUST NOT be NULL. + */ + int( + AXIS2_CALL + * get_target_port)( + tcpmon_session_t * session, + const axutil_env_t * env); + + /** + * configure the target host + * @param session represet the type object. + * @param env pointer to environment struct. MUST NOT be NULL. + * @param target_host url of the target host + * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE. + */ + axis2_status_t( + AXIS2_CALL + * set_target_host)( + tcpmon_session_t * session, + const axutil_env_t * env, + axis2_char_t * target_host); + + /** + * retrieve the base uri of the target host + * @param session represet the type object. + * @param env pointer to environment struct. MUST NOT be NULL. + */ + axis2_char_t *( + AXIS2_CALL + * get_target_host)( + tcpmon_session_t * session, + const axutil_env_t * env); + + /** + * start the session + * @param session represet the type object. + * @param env pointer to environment struct. MUST NOT be NULL. + */ + axis2_status_t( + AXIS2_CALL + * start)( + tcpmon_session_t * session, + const axutil_env_t * env); + + /** + * stop the session. + * @param session represet the type object. + * @param env pointer to environment struct. MUST NOT be NULL. + */ + axis2_status_t( + AXIS2_CALL + * stop)( + tcpmon_session_t * session, + const axutil_env_t * env); + + /** + * set on new entry. + * @param session represet the type object. + * @param env pointer to environment struct. MUST NOT be NULL. + * @param on_new_entry_funct function to triger on new entry + */ + axis2_status_t( + AXIS2_CALL + * on_new_entry)( + tcpmon_session_t * session, + const axutil_env_t * env, + TCPMON_SESSION_NEW_ENTRY_FUNCT on_new_entry_funct); + + /** + * set on new entry. + * @param session represet the type object. + * @param env pointer to environment struct. MUST NOT be NULL. + * @param on_new_entry function to triger on new entry + */ + axis2_status_t( + AXIS2_CALL + * on_trans_fault)( + tcpmon_session_t * session, + const axutil_env_t * env, + TCPMON_SESSION_TRANS_ERROR_FUNCT on_trans_fault_funct); + + }; + + struct tcpmon_session + { + tcpmon_session_ops_t *ops; + }; + + /** + * Creates tcpmon_session struct + * @param env double pointer to environment struct. MUST NOT be NULL + * @return pointer to newly created tcpmon_session struct + */ + tcpmon_session_t *AXIS2_CALL + tcpmon_session_create( + const axutil_env_t * env); + + /*************************** Function macros **********************************/ + +#define TCPMON_SESSION_FREE(session, env) \ + ((session)->ops->free (session, env)) + +#define TCPMON_SESSION_SET_TEST_BIT(session, env, test_bit) \ + ((session)->ops->set_test_bit(session, env, test_bit)) + +#define TCPMON_SESSION_GET_TEST_BIT(session, env) \ + ((session)->ops->get_test_bit(session, env)) + +#define TCPMON_SESSION_SET_FORMAT_BIT(session, env, format_bit) \ + ((session)->ops->set_format_bit(session, env, format_bit)) + +#define TCPMON_SESSION_GET_FORMAT_BIT(session, env) \ + ((session)->ops->get_format_bit(session, env)) + +#define TCPMON_SESSION_SET_LISTEN_PORT(session, env, listen_port) \ + ((session)->ops->set_listen_port(session, env, listen_port)) + +#define TCPMON_SESSION_GET_LISTEN_PORT(session, env) \ + ((session)->ops->get_listen_port(session, env)) + +#define TCPMON_SESSION_SET_TARGET_PORT(session, env, target_port) \ + ((session)->ops->set_target_port(session, env, target_port)) + +#define TCPMON_SESSION_GET_TARGET_PORT(session, env) \ + ((session)->ops->get_target_port(session, env)) + +#define TCPMON_SESSION_SET_TARGET_HOST(session, env, target_host) \ + ((session)->ops->set_target_host(session, env, target_host)) + +#define TCPMON_SESSION_GET_TARGET_HOST(session, env) \ + ((session)->ops->get_target_host(session, env)) + +#define TCPMON_SESSION_START(session, env) \ + ((session)->ops->start(session, env)) + +#define TCPMON_SESSION_STOP(session, env) \ + ((session)->ops->stop(session, env)) + +#define TCPMON_SESSION_ON_TRANS_FAULT(session, env, funct) \ + ((session)->ops->on_trans_fault(session, env, funct)) + +#define TCPMON_SESSION_ON_NEW_ENTRY(session, env, funct) \ + ((session)->ops->on_new_entry(session, env, funct)) + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* TCPMON_SESSION_H */ diff --git a/tools/tcpmon/include/tcpmon_util.h b/tools/tcpmon/include/tcpmon_util.h new file mode 100644 index 0000000..646be66 --- /dev/null +++ b/tools/tcpmon/include/tcpmon_util.h @@ -0,0 +1,91 @@ + +/* + * 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 TCPMON_UTIL_H +#define TCPMON_UTIL_H + +#include +#include +#include + +/** + * @file tcpmon_util.h + * @brief hold util functions of tcpmon + */ + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @defgroup hold util functions of tcpmon + * @ingroup tcpmon + * @{ + */ + + /** + * format the data as xml + * @param env pointer to environment struct. MUST NOT be NULL. + * @param data to be formatted + */ + axis2_char_t *tcpmon_util_format_as_xml( + const axutil_env_t * env, + axis2_char_t * data, + int format); + + char *str_replace( + char *str, + const char *search, + const char *replace); + + axis2_char_t * tcpmon_util_strcat( + axis2_char_t * dest, + axis2_char_t * source, + int *buff_size, + const axutil_env_t * env); + + axis2_char_t * + tcpmon_util_read_current_stream( + const axutil_env_t * env, + axutil_stream_t * stream, + int *stream_size, + axis2_char_t ** header, + axis2_char_t ** data); + + char * + tcpmon_util_str_replace( + const axutil_env_t *env, + char *str, + const char *search, + const char *replace); + + int + tcpmon_util_write_to_file( + char *filename, + char *buffer); + + + + /** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* TCPMON_UTIL_H */ diff --git a/tools/tcpmon/src/Makefile.am b/tools/tcpmon/src/Makefile.am new file mode 100644 index 0000000..674fbca --- /dev/null +++ b/tools/tcpmon/src/Makefile.am @@ -0,0 +1,21 @@ +prgbindir=$(prefix)/bin/tools/tcpmon + +prgbin_PROGRAMS = tcpmon + +tcpmon_SOURCES = tcpmon.c \ + entry.c \ + session.c \ + util.c + +tcpmon_LDADD = \ + ../../../util/src/libaxutil.la \ + ../../../axiom/src/om/libaxis2_axiom.la \ + ../../../axiom/src/parser/$(WRAPPER_DIR)/libaxis2_parser.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../util/include \ + -I ../../../axiom/include \ + -I ../../../include \ + -I ../include + +EXTRA_DIST=tcpmon_entry_local.h tcpmon_session_local.h diff --git a/tools/tcpmon/src/entry.c b/tools/tcpmon/src/entry.c new file mode 100644 index 0000000..37d2af1 --- /dev/null +++ b/tools/tcpmon/src/entry.c @@ -0,0 +1,656 @@ + +/* + * 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 +#include +#include +#include +#include +#include +#include + +#include "tcpmon_entry_local.h" +#include "tcpmon_session_local.h" +#include "tcpmon_util.h" + +#define AXIS2_TCPMON + +/** + * @brief + */ +typedef struct tcpmon_entry_impl +{ + tcpmon_entry_t entry; + + axis2_char_t *arrived_time; + axis2_char_t *sent_time; + axis2_char_t *sent_data; + axis2_char_t *arrived_data; + axis2_char_t *sent_headers; + axis2_char_t *arrived_headers; + axis2_bool_t is_success; + axis2_char_t *time_diff; + axis2_char_t *test_file_name; + int format_bit; + int sent_data_length; + int arrived_data_length; +} +tcpmon_entry_impl_t; + +#define AXIS2_INTF_TO_IMPL(entry) \ + ((tcpmon_entry_impl_t *) entry) + +/************************* Function prototypes ********************************/ + + +axis2_status_t AXIS2_CALL tcpmon_entry_free( + tcpmon_entry_t * entry, + const axutil_env_t * env); + +axis2_char_t *AXIS2_CALL tcpmon_entry_arrived_time( + tcpmon_entry_t * entry, + const axutil_env_t * env); + +axis2_char_t *AXIS2_CALL tcpmon_entry_sent_time( + tcpmon_entry_t * entry, + const axutil_env_t * env); + +axis2_char_t *AXIS2_CALL tcpmon_entry_time_diff( + tcpmon_entry_t * entry, + const axutil_env_t * env); + +axis2_char_t *AXIS2_CALL tcpmon_entry_sent_data( + tcpmon_entry_t * entry, + const axutil_env_t * env); + +axis2_char_t *AXIS2_CALL tcpmon_entry_sent_headers( + tcpmon_entry_t * entry, + const axutil_env_t * env); + +axis2_char_t *AXIS2_CALL tcpmon_entry_arrived_data( + tcpmon_entry_t * entry, + const axutil_env_t * env); + +axis2_char_t *AXIS2_CALL tcpmon_entry_arrived_headers( + tcpmon_entry_t * entry, + const axutil_env_t * env); + +axis2_bool_t AXIS2_CALL tcpmon_entry_is_success( + tcpmon_entry_t * entry, + const axutil_env_t * env); + +axis2_char_t *get_current_stream_to_buffer( + const axutil_env_t * env, + axutil_stream_t * stream, + int *stream_size); + + +int AXIS2_CALL tcpmon_entry_get_format_bit( + tcpmon_entry_t * entry, + const axutil_env_t * env); + +int AXIS2_CALL tcpmon_entry_get_sent_data_length( + tcpmon_entry_t * entry, + const axutil_env_t * env); + +int AXIS2_CALL tcpmon_entry_get_arrived_data_length( + tcpmon_entry_t * entry, + const axutil_env_t * env); + +axis2_status_t AXIS2_CALL tcpmon_entry_set_format_bit( + tcpmon_entry_t * entry, + const axutil_env_t * env, + int format_bit); + +/************************** End of function prototypes ************************/ + +tcpmon_entry_t *AXIS2_CALL +tcpmon_entry_create( + const axutil_env_t * env) +{ + tcpmon_entry_impl_t *entry_impl = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + entry_impl = (tcpmon_entry_impl_t *) AXIS2_MALLOC(env-> + allocator, + sizeof + (tcpmon_entry_impl_t)); + + if (!entry_impl) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + entry_impl->arrived_time = AXIS2_MALLOC(env->allocator, 32); + entry_impl->sent_time = AXIS2_MALLOC(env->allocator, 32); + entry_impl->time_diff = AXIS2_MALLOC(env->allocator, 32); + entry_impl->arrived_data = NULL; + entry_impl->sent_data = NULL; + entry_impl->arrived_headers = NULL; + entry_impl->sent_headers = NULL; + entry_impl->is_success = AXIS2_FALSE; + entry_impl->format_bit = 0; + entry_impl->sent_data_length = 0; + entry_impl->arrived_data_length = 0; + + entry_impl->entry.ops = + AXIS2_MALLOC(env->allocator, sizeof(tcpmon_entry_ops_t)); + if (!entry_impl->entry.ops) + { + tcpmon_entry_free(&(entry_impl->entry), env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + entry_impl->entry.ops->free = tcpmon_entry_free; + entry_impl->entry.ops->arrived_time = tcpmon_entry_arrived_time; + entry_impl->entry.ops->sent_time = tcpmon_entry_sent_time; + entry_impl->entry.ops->time_diff = tcpmon_entry_time_diff; + entry_impl->entry.ops->sent_data = tcpmon_entry_sent_data; + entry_impl->entry.ops->sent_headers = tcpmon_entry_sent_headers; + entry_impl->entry.ops->arrived_data = tcpmon_entry_arrived_data; + entry_impl->entry.ops->arrived_headers = tcpmon_entry_arrived_headers; + entry_impl->entry.ops->is_success = tcpmon_entry_is_success; + entry_impl->entry.ops->set_format_bit = tcpmon_entry_set_format_bit; + entry_impl->entry.ops->get_format_bit = tcpmon_entry_get_format_bit; + entry_impl->entry.ops->get_sent_data_length = tcpmon_entry_get_sent_data_length; + entry_impl->entry.ops->get_arrived_data_length = tcpmon_entry_get_arrived_data_length; + + return &(entry_impl->entry); +} + +/***************************Function implementation****************************/ + +axis2_status_t AXIS2_CALL +tcpmon_entry_free( + tcpmon_entry_t * entry, + const axutil_env_t * env) +{ + tcpmon_entry_impl_t *entry_impl = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + entry_impl = AXIS2_INTF_TO_IMPL(entry); + + if (entry->ops) + { + AXIS2_FREE(env->allocator, entry->ops); + entry->ops = NULL; + } + + if (entry_impl->arrived_time) + { + AXIS2_FREE(env->allocator, entry_impl->arrived_time); + entry_impl->arrived_time = NULL; + } + if (entry_impl->sent_time) + { + AXIS2_FREE(env->allocator, entry_impl->sent_time); + entry_impl->sent_time = NULL; + } + if (entry_impl->time_diff) + { + AXIS2_FREE(env->allocator, entry_impl->time_diff); + entry_impl->time_diff = NULL; + } + if (entry_impl->arrived_data) + { + AXIS2_FREE(env->allocator, entry_impl->arrived_data); + entry_impl->arrived_data = NULL; + } + if (entry_impl->sent_data) + { + AXIS2_FREE(env->allocator, entry_impl->sent_data); + entry_impl->sent_data = NULL; + } + if (entry_impl->arrived_headers) + { + AXIS2_FREE(env->allocator, entry_impl->arrived_headers); + entry_impl->arrived_headers = NULL; + } + if (entry_impl->sent_headers) + { + AXIS2_FREE(env->allocator, entry_impl->sent_headers); + entry_impl->sent_headers = NULL; + } + + if (entry_impl) + { + AXIS2_FREE(env->allocator, entry_impl); + entry_impl = NULL; + } + + return AXIS2_SUCCESS; +} + +axis2_char_t *AXIS2_CALL +tcpmon_entry_arrived_time( + tcpmon_entry_t * entry, + const axutil_env_t * env) +{ + tcpmon_entry_impl_t *entry_impl = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + entry_impl = AXIS2_INTF_TO_IMPL(entry); + + return entry_impl->arrived_time; +} + +axis2_char_t *AXIS2_CALL +tcpmon_entry_sent_time( + tcpmon_entry_t * entry, + const axutil_env_t * env) +{ + tcpmon_entry_impl_t *entry_impl = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + entry_impl = AXIS2_INTF_TO_IMPL(entry); + + return entry_impl->sent_time; +} + +axis2_char_t *AXIS2_CALL +tcpmon_entry_time_diff( + tcpmon_entry_t * entry, + const axutil_env_t * env) +{ + tcpmon_entry_impl_t *entry_impl = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + entry_impl = AXIS2_INTF_TO_IMPL(entry); + + return entry_impl->time_diff; +} + +axis2_char_t *AXIS2_CALL +tcpmon_entry_sent_data( + tcpmon_entry_t * entry, + const axutil_env_t * env) +{ + tcpmon_entry_impl_t *entry_impl = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + entry_impl = AXIS2_INTF_TO_IMPL(entry); + + return entry_impl->sent_data; +} + +axis2_char_t *AXIS2_CALL +tcpmon_entry_sent_headers( + tcpmon_entry_t * entry, + const axutil_env_t * env) +{ + tcpmon_entry_impl_t *entry_impl = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + entry_impl = AXIS2_INTF_TO_IMPL(entry); + + return entry_impl->sent_headers; +} + +axis2_char_t *AXIS2_CALL +tcpmon_entry_arrived_data( + tcpmon_entry_t * entry, + const axutil_env_t * env) +{ + tcpmon_entry_impl_t *entry_impl = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + entry_impl = AXIS2_INTF_TO_IMPL(entry); + + return entry_impl->arrived_data; +} + +axis2_char_t *AXIS2_CALL +tcpmon_entry_arrived_headers( + tcpmon_entry_t * entry, + const axutil_env_t * env) +{ + tcpmon_entry_impl_t *entry_impl = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + entry_impl = AXIS2_INTF_TO_IMPL(entry); + + return entry_impl->arrived_headers; +} + +axis2_bool_t AXIS2_CALL +tcpmon_entry_is_success( + tcpmon_entry_t * entry, + const axutil_env_t * env) +{ + tcpmon_entry_impl_t *entry_impl = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + entry_impl = AXIS2_INTF_TO_IMPL(entry); + + return entry_impl->is_success; +} + +int AXIS2_CALL +tcpmon_entry_get_format_bit( + tcpmon_entry_t * entry, + const axutil_env_t * env) +{ + tcpmon_entry_impl_t *entry_impl = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + entry_impl = AXIS2_INTF_TO_IMPL(entry); + + return entry_impl->format_bit; +} + +int AXIS2_CALL +tcpmon_entry_get_sent_data_length( + tcpmon_entry_t * entry, + const axutil_env_t * env) +{ + tcpmon_entry_impl_t *entry_impl = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + entry_impl = AXIS2_INTF_TO_IMPL(entry); + + return entry_impl->sent_data_length; +} + +int AXIS2_CALL +tcpmon_entry_get_arrived_data_length( + tcpmon_entry_t * entry, + const axutil_env_t * env) +{ + tcpmon_entry_impl_t *entry_impl = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + entry_impl = AXIS2_INTF_TO_IMPL(entry); + + return entry_impl->arrived_data_length; +} + +axis2_status_t AXIS2_CALL +tcpmon_entry_set_format_bit( + tcpmon_entry_t * entry, + const axutil_env_t * env, + int format_bit) +{ + tcpmon_entry_impl_t *entry_impl = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + entry_impl = AXIS2_INTF_TO_IMPL(entry); + + entry_impl->format_bit = format_bit; + + return AXIS2_SUCCESS; +} + +/** implimentations for protected methods */ + +/** executes as new entry arises */ +void *AXIS2_CALL +tcpmon_entry_new_entry_funct( + axutil_thread_t * thd, + void *data) +{ + tcpmon_entry_request_data_t *req_data = (tcpmon_entry_request_data_t *) data; + const axutil_env_t *env = NULL; + int client_socket = -1; + int host_socket = -1; + tcpmon_session_t *session; + TCPMON_SESSION_TRANS_ERROR_FUNCT on_trans_fault_funct; + TCPMON_SESSION_NEW_ENTRY_FUNCT on_new_entry; + + axutil_stream_t *client_stream = NULL; + axutil_stream_t *host_stream = NULL; + int buffer_size = 0; + axis2_char_t *headers = NULL; + axis2_char_t *content = NULL; + axis2_char_t *buffer = NULL; + time_t now; + struct tm *localTime = NULL; + int arrived_secs = 0; + int sent_secs = 0; + int time_diff_i = 0; + int target_port = 0; + axis2_char_t *target_host = NULL; + int test_bit = 0; + int format_bit = 0; + tcpmon_entry_t *entry = NULL; + tcpmon_entry_impl_t *entry_impl = NULL; + + env = req_data->env; + client_socket = req_data->socket; + session = req_data->session; + on_trans_fault_funct = tcpmon_session_get_on_trans_fault(session, env); + on_new_entry = tcpmon_session_get_on_new_entry(session, env); + + entry = tcpmon_entry_create(env); + entry_impl = AXIS2_INTF_TO_IMPL(entry); + + target_port = TCPMON_SESSION_GET_TARGET_PORT(session, env); + target_host = TCPMON_SESSION_GET_TARGET_HOST(session, env); + if (target_port == -1 || target_host == NULL) + { + axutil_network_handler_close_socket(env, client_socket); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Missing target port and host" + "input missing"); + if (on_trans_fault_funct) + { + (on_trans_fault_funct) (env, "Missing target port and host"); + } + if (thd) + { + AXIS2_FREE(env->allocator, thd); + } + if (data) + { + AXIS2_FREE(env->allocator, (tcpmon_entry_request_data_t *)data); + } + return NULL; + } + client_stream = axutil_stream_create_socket(env, client_socket); + if (!client_stream) + { + axutil_network_handler_close_socket(env, client_socket); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Error in creating client stream" "handling response"); + + /** call the callback */ + if (on_trans_fault_funct) + { + (on_trans_fault_funct) (env, "error in creating the client stream"); + } + if (thd) + { + AXIS2_FREE(env->allocator, thd); + } + if (data) + { + AXIS2_FREE(env->allocator, (tcpmon_entry_request_data_t *)data); + } + return NULL; + } + + buffer = tcpmon_util_read_current_stream(env, client_stream, &buffer_size, + &headers, &content); + + headers =(char *) tcpmon_util_str_replace(env, headers,"localhost", target_host); + test_bit = TCPMON_SESSION_GET_TEST_BIT(session, env); + + if (test_bit) + { + tcpmon_util_write_to_file("reqest", buffer); + } + + format_bit = TCPMON_SESSION_GET_FORMAT_BIT(session, env); + TCPMON_ENTRY_SET_FORMAT_BIT(entry, env, format_bit); + + now = time(NULL); + localTime = localtime(&now); + + sprintf(entry_impl->sent_time, "%d:%d:%d", localTime->tm_hour, + localTime->tm_min, localTime->tm_sec); + sent_secs = + localTime->tm_hour * 60 * 60 + localTime->tm_min * 60 + + localTime->tm_sec; + + /*free ( localTime); */ + + entry_impl->sent_headers = headers; + entry_impl->sent_data = content; + entry_impl->sent_data_length = buffer_size; + + if (on_new_entry) + { + (on_new_entry) (env, entry, 0); + } + + host_socket = + (int)axutil_network_handler_open_socket(env, target_host, target_port); + if (-1 == host_socket) + { + axutil_stream_write(client_stream, env, NULL, 0); + axutil_stream_free(client_stream, env); + axutil_network_handler_close_socket(env, client_socket); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error in creating host_socket" + "creating socket"); + + /** call the callback */ + if (on_trans_fault_funct) + { + (on_trans_fault_funct) (env, "error in creating the host socket"); + } + if (thd) + { + AXIS2_FREE(env->allocator, thd); + } + if (data) + { + AXIS2_FREE(env->allocator, (tcpmon_entry_request_data_t *)data); + } + return NULL; + } + + host_stream = axutil_stream_create_socket(env, host_socket); + if (!host_stream) + { + axutil_stream_write(client_stream, env, NULL, 0); + axutil_stream_free(client_stream, env); + axutil_network_handler_close_socket(env, client_socket); + axutil_network_handler_close_socket(env, host_socket); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error in creating host stream" + "handling response"); + + /** call the callback */ + if (on_trans_fault_funct) + { + (on_trans_fault_funct) (env, "error in creating the host stream"); + } + if (thd) + { + AXIS2_FREE(env->allocator, thd); + } + if (data) + { + AXIS2_FREE(env->allocator, (tcpmon_entry_request_data_t *)data); + } + return NULL; + } + + axutil_stream_write(host_stream, env, buffer, buffer_size); + AXIS2_FREE(env->allocator, buffer); + + buffer = tcpmon_util_read_current_stream(env, host_stream, &buffer_size, + &headers, &content); + + test_bit = TCPMON_SESSION_GET_TEST_BIT(session, env); + if (test_bit) + { + tcpmon_util_write_to_file("response", buffer); + } + + now = time(NULL); + localTime = localtime(&now); + + sprintf(entry_impl->arrived_time, "%d:%d:%d", localTime->tm_hour, + localTime->tm_min, localTime->tm_sec); + arrived_secs = + localTime->tm_hour * 60 * 60 + localTime->tm_min * 60 + + localTime->tm_sec; + /*free ( localTime); */ + + time_diff_i = arrived_secs - sent_secs; + if (time_diff_i < 0) + { + time_diff_i += 24 * 60 * 60; + } + sprintf(entry_impl->time_diff, "%d sec(s)", time_diff_i); + + entry_impl->arrived_headers = headers; + entry_impl->arrived_data = content; + entry_impl->arrived_data_length = buffer_size; + if (buffer == NULL || buffer_size == 0) + { + entry_impl->is_success = 0; + } + else + { + entry_impl->is_success = 1; + } + + if (on_new_entry) + { + (on_new_entry) (env, entry, 1); + } + + axutil_stream_write(client_stream, env, buffer, buffer_size); + AXIS2_FREE(env->allocator, buffer); + + axutil_stream_free(client_stream, env); + axutil_stream_free(host_stream, env); + axutil_network_handler_close_socket(env, client_socket); + axutil_network_handler_close_socket(env, host_socket); + + if (entry_impl) + { + tcpmon_entry_free(&(entry_impl->entry), env); + } + if (thd) + { + AXIS2_FREE(env->allocator, thd); + } + if (data) + { + AXIS2_FREE(env->allocator, (tcpmon_entry_request_data_t *)data); + } + return NULL; +} + + diff --git a/tools/tcpmon/src/session.c b/tools/tcpmon/src/session.c new file mode 100644 index 0000000..29d4c78 --- /dev/null +++ b/tools/tcpmon/src/session.c @@ -0,0 +1,632 @@ + +/* + * 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 +#include +#include +#include +#include +#include +#include +#include + +#include "tcpmon_session_local.h" +#include "tcpmon_entry_local.h" +#include "tcpmon_util.h" + +/** + * @brief + */ +typedef struct tcpmon_session_impl +{ + tcpmon_session_t session; + int listen_port; + int target_port; + int test_bit; + int format_bit; + axis2_char_t *target_host; + TCPMON_SESSION_NEW_ENTRY_FUNCT on_new_entry_funct; + TCPMON_SESSION_TRANS_ERROR_FUNCT on_trans_fault_funct; + axutil_array_list_t *entries; + + axis2_bool_t is_running; +} +tcpmon_session_impl_t; + +typedef struct tcpmon_session_server_thread_data +{ + tcpmon_session_impl_t *session_impl; + const axutil_env_t *env; +} +tcpmon_session_server_thread_data_t; + +#define AXIS2_INTF_TO_IMPL(session) \ + ((tcpmon_session_impl_t *) session) +axutil_thread_t *server_thread = NULL; +tcpmon_session_server_thread_data_t *thread_data = NULL; + + +/************************* Function prototypes ********************************/ + +axis2_status_t AXIS2_CALL tcpmon_session_free( + tcpmon_session_t * session, + const axutil_env_t * env); + +axis2_status_t AXIS2_CALL tcpmon_session_set_listen_port( + tcpmon_session_t * session, + const axutil_env_t * env, + int listen_port); + +int AXIS2_CALL tcpmon_session_get_listen_port( + tcpmon_session_t * session, + const axutil_env_t * env); + +axis2_status_t AXIS2_CALL tcpmon_session_set_target_port( + tcpmon_session_t * session, + const axutil_env_t * env, + int target_port); + +int AXIS2_CALL tcpmon_session_get_target_port( + tcpmon_session_t * session, + const axutil_env_t * env); + +axis2_status_t AXIS2_CALL tcpmon_session_set_target_host( + tcpmon_session_t * session, + const axutil_env_t * env, + axis2_char_t * target_host); + +axis2_char_t *AXIS2_CALL tcpmon_session_get_target_host( + tcpmon_session_t * session, + const axutil_env_t * env); + +axis2_status_t AXIS2_CALL tcpmon_session_start( + tcpmon_session_t * session, + const axutil_env_t * env); + +axis2_status_t AXIS2_CALL tcpmon_session_stop( + tcpmon_session_t * session, + const axutil_env_t * env); + +axis2_status_t AXIS2_CALL tcpmon_session_on_new_entry( + tcpmon_session_t * session, + const axutil_env_t * env, + TCPMON_SESSION_NEW_ENTRY_FUNCT on_new_entry_funct); + +axis2_status_t AXIS2_CALL tcpmon_session_on_trans_fault( + tcpmon_session_t * session, + const axutil_env_t * env, + TCPMON_SESSION_TRANS_ERROR_FUNCT on_trans_fault_funct); + +int AXIS2_CALL tcpmon_session_get_test_bit( + tcpmon_session_t * session, + const axutil_env_t * env); + +int AXIS2_CALL tcpmon_session_set_test_bit( + tcpmon_session_t * session, + const axutil_env_t * env, + int test_bit); + +int AXIS2_CALL tcpmon_session_get_format_bit( + tcpmon_session_t * session, + const axutil_env_t * env); + +int AXIS2_CALL tcpmon_session_set_format_bit( + tcpmon_session_t * session, + const axutil_env_t * env, + int format_bit); + +/** internal implementations */ + +static void *AXIS2_THREAD_FUNC server_funct( + axutil_thread_t * thd, + void *data); + +/************************** End of function prototypes ************************/ + +tcpmon_session_t *AXIS2_CALL +tcpmon_session_create( + const axutil_env_t * env) +{ + tcpmon_session_impl_t *session_impl = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + session_impl = (tcpmon_session_impl_t *) AXIS2_MALLOC(env-> + allocator, + sizeof + (tcpmon_session_impl_t)); + + if (!session_impl) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + session_impl->listen_port = -1; + session_impl->target_port = -1; + session_impl->test_bit = -1; + session_impl->format_bit = 0; + session_impl->target_host = NULL; + + session_impl->on_new_entry_funct = NULL; + session_impl->on_trans_fault_funct = NULL; + session_impl->entries = + axutil_array_list_create(env, AXIS2_ARRAY_LIST_DEFAULT_CAPACITY); + + session_impl->session.ops = + AXIS2_MALLOC(env->allocator, sizeof(tcpmon_session_ops_t)); + if (!session_impl->session.ops) + { + tcpmon_session_free(&(session_impl->session), env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + session_impl->is_running = AXIS2_FALSE; + session_impl->session.ops->free = tcpmon_session_free; + session_impl->session.ops->set_test_bit = tcpmon_session_set_test_bit; + session_impl->session.ops->get_test_bit = tcpmon_session_get_test_bit; + session_impl->session.ops->get_format_bit = tcpmon_session_get_format_bit; + session_impl->session.ops->set_format_bit = tcpmon_session_set_format_bit; + session_impl->session.ops->set_listen_port = tcpmon_session_set_listen_port; + session_impl->session.ops->get_listen_port = tcpmon_session_get_listen_port; + session_impl->session.ops->set_target_port = tcpmon_session_set_target_port; + session_impl->session.ops->get_target_port = tcpmon_session_get_target_port; + session_impl->session.ops->set_target_host = tcpmon_session_set_target_host; + session_impl->session.ops->get_target_host = tcpmon_session_get_target_host; + session_impl->session.ops->start = tcpmon_session_start; + session_impl->session.ops->stop = tcpmon_session_stop; + session_impl->session.ops->on_new_entry = tcpmon_session_on_new_entry; + session_impl->session.ops->on_trans_fault = tcpmon_session_on_trans_fault; + + return &(session_impl->session); +} + +/***************************Function implementation****************************/ + +axis2_status_t AXIS2_CALL +tcpmon_session_free( + tcpmon_session_t * session, + const axutil_env_t * env) +{ + tcpmon_session_impl_t *session_impl = NULL; + int entries_size = 0; + tcpmon_entry_t *entry = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + session_impl = AXIS2_INTF_TO_IMPL(session); + + for (entries_size = axutil_array_list_size(session_impl->entries, env) - 1; + entries_size >= 0; entries_size--) + { + TCPMON_ENTRY_FREE(entry, env); + } + axutil_array_list_free(session_impl->entries, env); + + if (session->ops) + { + AXIS2_FREE(env->allocator, session->ops); + session->ops = NULL; + } + + if (session_impl->target_host) + { + AXIS2_FREE(env->allocator, session_impl->target_host); + session_impl->target_host = NULL; + } + + if (session_impl) + { + AXIS2_FREE(env->allocator, session_impl); + session_impl = NULL; + } + + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +tcpmon_session_set_test_bit( + tcpmon_session_t * session, + const axutil_env_t * env, + int test_bit) +{ + tcpmon_session_impl_t *session_impl = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + session_impl = AXIS2_INTF_TO_IMPL(session); + session_impl->test_bit = test_bit; + return AXIS2_SUCCESS; +} + +int AXIS2_CALL +tcpmon_session_get_test_bit( + tcpmon_session_t * session, + const axutil_env_t * env) +{ + tcpmon_session_impl_t *session_impl = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + session_impl = AXIS2_INTF_TO_IMPL(session); + + return session_impl->test_bit; +} + +axis2_status_t AXIS2_CALL +tcpmon_session_set_format_bit( + tcpmon_session_t * session, + const axutil_env_t * env, + int format_bit) +{ + tcpmon_session_impl_t *session_impl = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + session_impl = AXIS2_INTF_TO_IMPL(session); + + session_impl->format_bit = format_bit; + + return AXIS2_SUCCESS; +} + +int AXIS2_CALL +tcpmon_session_get_format_bit( + tcpmon_session_t * session, + const axutil_env_t * env) +{ + tcpmon_session_impl_t *session_impl = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + session_impl = AXIS2_INTF_TO_IMPL(session); + + return session_impl->format_bit; +} + +axis2_status_t AXIS2_CALL +tcpmon_session_set_listen_port( + tcpmon_session_t * session, + const axutil_env_t * env, + int listen_port) +{ + tcpmon_session_impl_t *session_impl = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + session_impl = AXIS2_INTF_TO_IMPL(session); + + session_impl->listen_port = listen_port; + return AXIS2_SUCCESS; +} + +int AXIS2_CALL +tcpmon_session_get_listen_port( + tcpmon_session_t * session, + const axutil_env_t * env) +{ + tcpmon_session_impl_t *session_impl = NULL; + + AXIS2_ENV_CHECK(env, -1); + + session_impl = AXIS2_INTF_TO_IMPL(session); + + return session_impl->listen_port; +} + +axis2_status_t AXIS2_CALL +tcpmon_session_set_target_port( + tcpmon_session_t * session, + const axutil_env_t * env, + int target_port) +{ + tcpmon_session_impl_t *session_impl = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + session_impl = AXIS2_INTF_TO_IMPL(session); + + session_impl->target_port = target_port; + return AXIS2_SUCCESS; +} + +int AXIS2_CALL +tcpmon_session_get_target_port( + tcpmon_session_t * session, + const axutil_env_t * env) +{ + tcpmon_session_impl_t *session_impl = NULL; + + AXIS2_ENV_CHECK(env, -1); + + session_impl = AXIS2_INTF_TO_IMPL(session); + + return session_impl->target_port; +} + +axis2_status_t AXIS2_CALL +tcpmon_session_set_target_host( + tcpmon_session_t * session, + const axutil_env_t * env, + axis2_char_t * target_host) +{ + tcpmon_session_impl_t *session_impl = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + session_impl = AXIS2_INTF_TO_IMPL(session); + + session_impl->target_host = + (axis2_char_t *) axutil_strdup(env, target_host); + return AXIS2_SUCCESS; +} + +axis2_char_t *AXIS2_CALL +tcpmon_session_get_target_host( + tcpmon_session_t * session, + const axutil_env_t * env) +{ + tcpmon_session_impl_t *session_impl = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + session_impl = AXIS2_INTF_TO_IMPL(session); + + return session_impl->target_host; +} + +axis2_status_t AXIS2_CALL +tcpmon_session_start( + tcpmon_session_t * session, + const axutil_env_t * env) +{ + tcpmon_session_impl_t *session_impl = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + session_impl = AXIS2_INTF_TO_IMPL(session); + + thread_data = + (tcpmon_session_server_thread_data_t *) AXIS2_MALLOC(env->allocator, + sizeof + (tcpmon_session_server_thread_data_t)); + thread_data->session_impl = session_impl; + thread_data->env = env; + + session_impl->is_running = AXIS2_TRUE; + server_thread = axutil_thread_pool_get_thread(env->thread_pool, + server_funct, + (void *) thread_data); + if (!server_thread) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Thread creation failed" + "server thread"); + if (session_impl->on_trans_fault_funct) + { + (session_impl->on_trans_fault_funct) (env, + "error in creating the server thread"); + } + } + + axutil_thread_pool_thread_detach(env->thread_pool, server_thread); + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +tcpmon_session_stop( + tcpmon_session_t * session, + const axutil_env_t * env) +{ + tcpmon_session_impl_t *session_impl = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + session_impl = AXIS2_INTF_TO_IMPL(session); + session_impl->is_running = AXIS2_FALSE; + + if (server_thread) + { + AXIS2_FREE(env->allocator, server_thread); + server_thread = NULL; + } + if (thread_data) + { + AXIS2_FREE(env->allocator, (tcpmon_session_server_thread_data_t *)thread_data); + thread_data = NULL; + } + + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +tcpmon_session_on_new_entry( + tcpmon_session_t * session, + const axutil_env_t * env, + TCPMON_SESSION_NEW_ENTRY_FUNCT on_new_entry_funct) +{ + tcpmon_session_impl_t *session_impl = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + session_impl = AXIS2_INTF_TO_IMPL(session); + + session_impl->on_new_entry_funct = on_new_entry_funct; + + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +tcpmon_session_on_trans_fault( + tcpmon_session_t * session, + const axutil_env_t * env, + TCPMON_SESSION_TRANS_ERROR_FUNCT on_trans_fault_funct) +{ + tcpmon_session_impl_t *session_impl = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + session_impl = AXIS2_INTF_TO_IMPL(session); + + session_impl->on_trans_fault_funct = on_trans_fault_funct; + return AXIS2_SUCCESS; +} + +/** internal implementations */ +static void *AXIS2_THREAD_FUNC +server_funct( + axutil_thread_t * thd, + void *data) +{ + tcpmon_session_server_thread_data_t *thread_data = (tcpmon_session_server_thread_data_t *)data; + tcpmon_session_impl_t *session_impl = NULL; + const axutil_env_t *env = NULL; + int listen_socket = -1; + int socket = -1; + axutil_thread_t *request_thread = NULL; + tcpmon_entry_request_data_t *request_thread_data = NULL; + + session_impl = thread_data->session_impl; + env = thread_data->env; + + listen_socket = (int)axutil_network_handler_create_server_socket + (env, session_impl->listen_port); + if (-1 == listen_socket) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "error in creating the server socket, " + "port may be already occupied", "create socket"); + if (session_impl->on_trans_fault_funct) + { + (session_impl->on_trans_fault_funct) (env, + "error in creating the server socket, " + "port may be already occupied"); + } + if (thd) + { + AXIS2_FREE(env->allocator, server_thread); + server_thread = NULL; + } + if (data) + { + AXIS2_FREE(env->allocator, (tcpmon_session_server_thread_data_t *)data); + thread_data = NULL; + } + return NULL; + } + while (session_impl->is_running) + { + socket = (int)axutil_network_handler_svr_socket_accept(env, listen_socket); + if (socket == -1) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "error in creating the socket" "create socket"); + if (session_impl->on_trans_fault_funct) + { + (session_impl->on_trans_fault_funct) (env, + "error in creating the socket"); + } + break; + } + + request_thread_data = + (tcpmon_entry_request_data_t *) AXIS2_MALLOC(env->allocator, + sizeof + (tcpmon_entry_request_data_t)); + request_thread_data->env = env; + request_thread_data->socket = socket; + request_thread_data->session = (tcpmon_session_t *) session_impl; + + request_thread = axutil_thread_pool_get_thread(env->thread_pool, + tcpmon_entry_new_entry_funct, + (void *) + request_thread_data); + if (!request_thread) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Thread creation failed" + "request thread"); + if (session_impl->on_trans_fault_funct) + { + (session_impl->on_trans_fault_funct) (env, + "fail in creating the thread"); + } + break; + } + + axutil_thread_pool_thread_detach(env->thread_pool, request_thread); + } + axutil_network_handler_close_socket(env, listen_socket); + if (thd) + { + AXIS2_FREE(env->allocator, server_thread); + server_thread = NULL; + } + if (data) + { + AXIS2_FREE(env->allocator, (tcpmon_session_server_thread_data_t *)data); + thread_data = NULL; + } + return NULL; +} + +/* implementations for protected functions */ + +axis2_status_t +tcpmon_session_add_new_entry( + tcpmon_session_t * session, + const axutil_env_t * env, + tcpmon_entry_t * entry) +{ + tcpmon_session_impl_t *session_impl = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + session_impl = AXIS2_INTF_TO_IMPL(session); + + axutil_array_list_add(session_impl->entries, env, entry); + return AXIS2_SUCCESS; + +} + +TCPMON_SESSION_TRANS_ERROR_FUNCT +tcpmon_session_get_on_trans_fault( + tcpmon_session_t * session, + const axutil_env_t * env) +{ + tcpmon_session_impl_t *session_impl = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + session_impl = AXIS2_INTF_TO_IMPL(session); + + return session_impl->on_trans_fault_funct; +} + +TCPMON_SESSION_NEW_ENTRY_FUNCT +tcpmon_session_get_on_new_entry( + tcpmon_session_t * session, + const axutil_env_t * env) +{ + tcpmon_session_impl_t *session_impl = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + session_impl = AXIS2_INTF_TO_IMPL(session); + + return session_impl->on_new_entry_funct; +} diff --git a/tools/tcpmon/src/tcpmon.c b/tools/tcpmon/src/tcpmon.c new file mode 100644 index 0000000..567bfc3 --- /dev/null +++ b/tools/tcpmon/src/tcpmon.c @@ -0,0 +1,1037 @@ + +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define SIZE 1024 +axis2_char_t *tcpmon_traffic_log = "tcpmon_traffic.log"; +axutil_env_t *system_env = NULL; +tcpmon_session_t *session = NULL; +char *target_host = NULL; + +int on_new_entry( + const axutil_env_t * env, + tcpmon_entry_t * entry, + int status); + +int on_new_entry_to_file( + const axutil_env_t * env, + tcpmon_entry_t * entry, + int status); + +int on_error_func( + const axutil_env_t * env, + char *error_message); + + +void sig_handler( + int signal); + +int resend_request( + const axutil_env_t * env, + int status); + +int +main( + int argc, + char **argv) +{ + axutil_env_t *env = NULL; + int c; + int listen_port = 9099, + target_port = 9090; /* the default port simple axis2 server is run on 9090 */ + int test_bit = 0; + int format_bit = 0; /* pretty print the request/response SOAP messages */ + int ii = 1; + + if (!axutil_strcmp(argv[1], "-h")) + { + printf + ("Usage : %s [-lp LISTEN_PORT] [-tp TARGET_PORT] [-th TARGET_HOST] [-f LOG_FILE] [options]\n", + argv[0]); + fprintf(stdout, " Options :\n"); + fprintf(stdout, + "\t-lp LISTEN_PORT \tport number to listen on, default is 9099\n"); + fprintf(stdout, + "\t-tp TARGET_PORT \tport number to connect and re-direct messages, default is 9090\n"); + fprintf(stdout, + "\t-th TARGET_HOST \ttarget host to connect, default is localhost\n"); + fprintf(stdout, + "\t-f LOG_FILE \tfile to write the messages to, default is %s\n", + tcpmon_traffic_log); + fprintf(stdout, + "\t--format \tenable xml formatting\n"); + fprintf(stdout, + "\t--test \tenable testing last request/response by logging it separately\n"); + fprintf(stdout, " Help :\n\t-h \tdisplay this help screen.\n\n"); + return 0; + } + + env = axutil_env_create_all("axis2_tcpmon.log", AXIS2_LOG_LEVEL_DEBUG); + + signal(SIGINT, sig_handler); + system_env = env; +#ifndef WIN32 + signal(SIGPIPE, sig_handler); +#endif + + target_host = axutil_strdup(env, "localhost"); + + while (ii < argc) + { + if (!strcmp("-lp", argv[ii])) + { + ii++; + if (argv[ii]) + { + listen_port = atoi(argv[ii++]); + if (listen_port == 0) + { + printf("INVALID value for listen port\n"); + printf("Use -h for help\n"); + AXIS2_FREE(env->allocator, target_host); + if (env) + { + axutil_env_free((axutil_env_t *) env); + env = NULL; + } + return 0; + } + } + } + else if (!strcmp("-tp", argv[ii])) + { + ii++; + if (argv[ii]) + { + target_port = atoi(argv[ii++]); + if (target_port == 0) + { + printf("INVALID value for target port\n"); + printf("Use -h for help\n"); + AXIS2_FREE(env->allocator, target_host); + if (env) + { + axutil_env_free((axutil_env_t *) env); + env = NULL; + } + return 0; + } + } + } + else if (!strcmp("-th", argv[ii])) + { + ii++; + if (argv[ii]) + { + AXIS2_FREE(env->allocator, target_host); + target_host = (char *) axutil_strdup(env, argv[ii++]); + } + } + else if (!strcmp("--test", argv[ii])) + { + ii++; + test_bit = 1; + } + else if (!strcmp("--format", argv[ii])) + { + ii++; + format_bit = 1; + } + else if (!strcmp("-f", argv[ii])) + { + ii++; + if (argv[ii]) + { + tcpmon_traffic_log = argv[ii++]; + } + } + else + { + printf("INVALID value for tcpmon \n"); + printf("Use -h for help\n"); + AXIS2_FREE(env->allocator, target_host); + if (env) + { + axutil_env_free((axutil_env_t *) env); + env = NULL; + } + return 0; + } + } + + if (!(listen_port && target_port && target_host)) + { + printf("ERROR: essential argument missing \n"); + printf + ("Please recheck values of listen_port (-lp), target_port(-tp) and target_host (-th)\n"); + AXIS2_FREE(env->allocator, target_host); + if (env) + { + axutil_env_free((axutil_env_t *) env); + env = NULL; + } + return 0; + } + + printf("Listen port : %d Target port : %d Target host: %s\n", + listen_port, target_port, target_host); + session = tcpmon_session_create(env); + + TCPMON_SESSION_SET_LISTEN_PORT(session, env, listen_port); + TCPMON_SESSION_SET_TARGET_PORT(session, env, target_port); + TCPMON_SESSION_SET_TARGET_HOST(session, env, target_host); + TCPMON_SESSION_ON_TRANS_FAULT(session, env, on_error_func); + + TCPMON_SESSION_ON_NEW_ENTRY(session, env, on_new_entry_to_file); + + TCPMON_SESSION_SET_TEST_BIT(session, env, test_bit); + TCPMON_SESSION_SET_FORMAT_BIT(session, env, format_bit); + TCPMON_SESSION_START(session, env); + + do + { + c = getchar(); + if (c == 'f') + { + format_bit = format_bit ? 0 : 1; + TCPMON_SESSION_SET_FORMAT_BIT(session, env, format_bit); + } + else if (c == 'r') + { + resend_request(env, 0); + } + } + while (c != 'q'); + printf("\n\n"); + + TCPMON_SESSION_STOP(session, env); + TCPMON_SESSION_FREE(session, env); + AXIS2_FREE(env->allocator, target_host); + if (env) + { + axutil_env_free((axutil_env_t *) env); + env = NULL; + } + return 0; +} + +int +on_new_entry_to_file( + const axutil_env_t * env, + tcpmon_entry_t * entry, + int status) +{ + char *plain_buffer = NULL; + char *formated_buffer = NULL; + int format = 0; + FILE *file; + char *convert = NULL; + char *uuid = NULL; + int resend = 0; + + file = fopen(tcpmon_traffic_log, "ab"); + + if (NULL == file) + { + printf("\ncould not create or open log-file\n"); + return -1; + } + + fprintf(file, + "\n= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =\n"); + + format = TCPMON_ENTRY_GET_FORMAT_BIT(entry, env); + + if (status == 0) + { + if (strstr(TCPMON_ENTRY_SENT_HEADERS(entry, env), AXIS2_HTTP_HEADER_USER_AGENT + ": " AXIS2_HTTP_HEADER_SERVER_AXIS2C "TCPMon\r\n")) + { + resend = 1; + } + plain_buffer = TCPMON_ENTRY_SENT_DATA(entry, env); + if (plain_buffer) /* this can be possible as no xml present */ + { + if (TCPMON_ENTRY_GET_SENT_DATA_LENGTH(entry, env) != + (int)strlen(TCPMON_ENTRY_SENT_HEADERS(entry, env)) + + (int)strlen(plain_buffer) + 4) + { + format = 0; /* mtom scenario */ + } + formated_buffer = tcpmon_util_format_as_xml + (env, plain_buffer, format); + } + else + { + formated_buffer = ""; + } + /* 2 screen */ + printf("\n\n%s\n", resend ? "RESENDING DATA..": "SENDING DATA.."); + printf("/* sending time = %s*/\n", TCPMON_ENTRY_SENT_TIME(entry, env)); + uuid = axutil_uuid_gen(env); + printf("/* message uuid = %s*/\n", uuid); + printf("---------------------\n"); + + if (format || TCPMON_ENTRY_GET_SENT_DATA_LENGTH(entry, env) == + (int)strlen(TCPMON_ENTRY_SENT_HEADERS(entry, env)) + + (int)strlen(formated_buffer) + 4) + { + printf("%s\n\n%s\n\n", TCPMON_ENTRY_SENT_HEADERS(entry, env), + formated_buffer); + } + else + { + int count = 0; + int printed = 0; + axis2_char_t *formated_buffer_temp = formated_buffer; + printf("%s\n\n", TCPMON_ENTRY_SENT_HEADERS(entry, env)); + count = TCPMON_ENTRY_GET_SENT_DATA_LENGTH(entry, env) - 4 - + (int)strlen(TCPMON_ENTRY_SENT_HEADERS(entry, env)); + while (count > printed) + { + int plen = 0; + plen = ((int)strlen(formated_buffer) + 1); + if (plen != 1) + { + printf("%s", formated_buffer); + } + printed += plen; + if (count > printed) + { + printf("%c", '\0'); + formated_buffer += plen; + } + } + formated_buffer = formated_buffer_temp; + } + + /* 2 file */ + fprintf(file, "%s\n", resend ? "RESENDING DATA..": "SENDING DATA.."); + fprintf(file, "/* sending time = %s*/\n", + TCPMON_ENTRY_SENT_TIME(entry, env)); + fprintf(file, "/* message uuid = %s*/\n", uuid); + AXIS2_FREE(env->allocator, uuid); + fprintf(file, "---------------------\n"); + + convert = axutil_strdup(env, TCPMON_ENTRY_SENT_HEADERS(entry, env)); + convert = tcpmon_util_str_replace(env, convert, "; ", ";\n\t"); + fprintf(file, "%s\r\n\r\n", convert); + if (convert) + { + AXIS2_FREE(env->allocator, convert); + convert = NULL; + } + if (strcmp(formated_buffer, "") != 0) + { + if (format || TCPMON_ENTRY_GET_SENT_DATA_LENGTH(entry, env) == + (int)strlen(TCPMON_ENTRY_SENT_HEADERS(entry, env)) + + (int)strlen(formated_buffer) + 4) + { + convert = axutil_strdup(env, formated_buffer); + convert = tcpmon_util_str_replace(env, convert, "><", ">\n<"); + fprintf(file, "%s", convert); + if (convert) + { + AXIS2_FREE(env->allocator, convert); + convert = NULL; + } + } + else + { + int count = 0; + int printed = 0; + count = TCPMON_ENTRY_GET_SENT_DATA_LENGTH(entry, env) - 4 - + (int)strlen(TCPMON_ENTRY_SENT_HEADERS(entry, env)); + while (count > printed) + { + int plen = 0; + plen = ((int)strlen(formated_buffer) + 1); + if (plen != 1) + { + fprintf(file, "%s", formated_buffer); + } + printed += plen; + if (count > printed) + { + fprintf(file, "%c", '\0'); + formated_buffer += plen; + } + } + } + } + } + if (status == 1) + { + plain_buffer = TCPMON_ENTRY_ARRIVED_DATA(entry, env); + if (plain_buffer) /* this can be possible as no xml present */ + { + if (TCPMON_ENTRY_GET_ARRIVED_DATA_LENGTH(entry, env) != + (int)strlen(TCPMON_ENTRY_ARRIVED_HEADERS(entry, env)) + + (int)strlen(plain_buffer) + 4) + { + format = 0; /* mtom scenario */ + } + formated_buffer = tcpmon_util_format_as_xml + (env, plain_buffer, format); + } + else + { + formated_buffer = ""; + } + /* 2 screen */ + printf("\n\n%s\n", "RETRIEVING DATA.."); + printf("/* retrieving time = %s*/\n", + TCPMON_ENTRY_ARRIVED_TIME(entry, env)); + printf("/* time throughput = %s*/\n", + TCPMON_ENTRY_TIME_DIFF(entry, env)); + printf("---------------------\n"); + + if (format || TCPMON_ENTRY_GET_ARRIVED_DATA_LENGTH(entry, env) == + (int)strlen(TCPMON_ENTRY_ARRIVED_HEADERS(entry, env)) + + (int)strlen(formated_buffer) + 4) + { + printf("%s\n\n%s\n\n", TCPMON_ENTRY_ARRIVED_HEADERS(entry, env), + formated_buffer); + } + else + { + int count = 0; + int printed = 0; + axis2_char_t *formated_buffer_temp = formated_buffer; + printf("%s\n\n", TCPMON_ENTRY_ARRIVED_HEADERS(entry, env)); + count = TCPMON_ENTRY_GET_ARRIVED_DATA_LENGTH(entry, env) - 4 - + (int)strlen(TCPMON_ENTRY_ARRIVED_HEADERS(entry, env)); + while (count > printed) + { + int plen = 0; + plen = ((int)strlen(formated_buffer) + 1); + if (plen != 1) + { + printf("%s", formated_buffer); + } + printed += plen; + if (count > printed) + { + printf("%c", '\0'); + formated_buffer += plen; + } + } + formated_buffer = formated_buffer_temp; + } + + /* 2 file */ + fprintf(file, "%s\n", "RETRIEVING DATA.."); + fprintf(file, "/* retrieving time = %s*/\n", + TCPMON_ENTRY_ARRIVED_TIME(entry, env)); + fprintf(file, "/* time throughput = %s*/\n", + TCPMON_ENTRY_TIME_DIFF(entry, env)); + fprintf(file, "---------------------\n"); + + convert = axutil_strdup(env, TCPMON_ENTRY_ARRIVED_HEADERS(entry, env)); + convert = tcpmon_util_str_replace(env, convert, "; ", ";\n\t"); + fprintf(file, "%s\r\n\r\n", convert); + if (convert) + { + AXIS2_FREE(env->allocator, convert); + convert = NULL; + } + if (strcmp(formated_buffer, "") != 0) + { + if (format || TCPMON_ENTRY_GET_ARRIVED_DATA_LENGTH(entry, env) == + (int)strlen(TCPMON_ENTRY_ARRIVED_HEADERS(entry, env)) + + (int)strlen(formated_buffer) + 4) + { + convert = axutil_strdup(env, formated_buffer); + convert = tcpmon_util_str_replace(env, convert, "><", ">\n<"); + fprintf(file, "%s", convert); + if (convert) + { + AXIS2_FREE(env->allocator, convert); + convert = NULL; + } + } + else + { + int count = 0; + int printed = 0; + count = TCPMON_ENTRY_GET_ARRIVED_DATA_LENGTH(entry, env) - 4 - + (int)strlen(TCPMON_ENTRY_ARRIVED_HEADERS(entry, env)); + while (count > printed) + { + int plen = 0; + plen = ((int)strlen(formated_buffer) + 1); + if (plen != 1) + { + fprintf(file, "%s", formated_buffer); + } + printed += plen; + if (count > printed) + { + fprintf(file, "%c", '\0'); + formated_buffer += plen; + } + } + } + } + } + fclose(file); + return 0; +} + +int +resend_request( + const axutil_env_t * env, + int status) +{ + FILE *file; + axis2_char_t *uuid = NULL; + axis2_char_t *buffer = NULL; + int read_len = 0; + + if (status == 0) + { + int c; + int i = 0; + do + { + c = getchar(); + } + while (c == ' '); + uuid = AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * 37); + for (i = 0; i < 36; i++) + { + if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || c == '-') + { + uuid[i] = (axis2_char_t)c; + } + else if (c >= 'A' && c <= 'F') + { + uuid[i] = (axis2_char_t)(c + 32); + } + else + { + return 0; + } + c = getchar(); + } + uuid[i] = '\0'; + } + + file = fopen(tcpmon_traffic_log, "rb"); + + if (!file) + { + printf("\ncould not create or open log-file\n"); + return -1; + } + + buffer = AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t) * SIZE); + if (!buffer) + { + printf("\ngimme more memory\n"); + return -1; + } + buffer[SIZE - 1] = '\0'; + + read_len = (int)fread(buffer, sizeof(char), SIZE - 1, file); + + while(read_len) + { + axis2_char_t *search = "/* message uuid = "; + axis2_char_t *tmp1 = NULL; + axis2_char_t *tmp2 = NULL; + axis2_char_t *tmp3 = NULL; + axis2_char_t *uuid_match = NULL; + int offset = 0; + int loop_state = 1; + int end_reached = 0; + int rounds = 0; + + offset = (int)strlen(search); + tmp3 = buffer; + if (read_len >= SIZE) + { + AXIS2_FREE(env->allocator, buffer); + AXIS2_FREE(env->allocator, uuid); + printf("\nbuffer overflow\n"); + return -1; + } + if (read_len < SIZE - 1) + { + end_reached = 1; + } + while (loop_state) + { + int temp_len = 0; + tmp1 = strstr(tmp3, search); + temp_len = (int)strlen(tmp3) + 1; + /* loop below is for mtom cases */ + while (!tmp1 && (read_len - rounds > temp_len)) + { + tmp3 += (int)strlen(tmp3) + 1; + tmp1 = strstr(tmp3, search); + temp_len += (int)strlen(tmp3) + 1; + } + if (!tmp1) + { + if (end_reached) + { + break; + } + memmove(buffer, buffer + (SIZE - 1 - offset), offset); + read_len = (int)fread(buffer + offset, sizeof(char), + SIZE - 1 - offset, file) + offset; + break; + } + else + { + rounds = (int)(tmp1 - tmp3) + offset + 36; + tmp3 = tmp1 + offset + 36; + } + if (read_len - offset - 36 < (int)(tmp1 - buffer)) + { + if (end_reached) + { + break; + } + offset += 36; + memmove(buffer, buffer + (SIZE - 1 - offset), offset); + read_len = (int)fread(buffer + offset, sizeof(char), + SIZE - 1 - offset, file) + offset; + break; + } + tmp2 = tmp1 + offset; + uuid_match = AXIS2_MALLOC(env->allocator, + sizeof(axis2_char_t) * 37); + if (!uuid_match) + { + printf("\ngimme more memory\n"); + return -1; + } + memcpy(uuid_match, tmp2, 36); + uuid_match[36] = '\0'; + if (!axutil_strcasecmp(uuid_match, uuid)) + { + axis2_char_t *header_str = "*/\n---------------------\n"; + axis2_char_t *footer_str = + "\n= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ="; + int seek_len = 0; + int has_raw_binary = 0; + axis2_char_t *request_buffer = NULL; + AXIS2_FREE(env->allocator, uuid_match); + AXIS2_FREE(env->allocator, uuid); + end_reached = 1; + tmp2 += 36; + offset = (int)strlen(header_str); + if (read_len - offset < (int)(tmp2 - buffer)) + { + seek_len = (int)(tmp2 - buffer) + offset - read_len; + if (seek_len > 0) + { + read_len = fread(buffer, sizeof(char), seek_len, file); + } + seek_len = 0; + } + else + { + seek_len = read_len - (int)(tmp2 - buffer) - offset; + } + request_buffer = AXIS2_MALLOC(env->allocator, + sizeof(axis2_char_t) * (48 * 1024 + 1)); + if (!request_buffer) + { + printf("\ngimme more memory\n"); + return -1; + } + if (seek_len > 0) + { + memcpy(request_buffer, buffer + (read_len - seek_len), seek_len); + } + read_len = (int)fread(request_buffer + seek_len, + sizeof(char), 48 * 1024 - seek_len, file) + seek_len; + tmp1 = NULL; + tmp3 = request_buffer; + tmp1 = strstr(tmp3, footer_str); + temp_len = (int)strlen(tmp3) + 1; + /* loop below is for mtom cases */ + while (!tmp1 && (read_len > temp_len)) + { + if (!has_raw_binary) + { + has_raw_binary = 1; + } + tmp3 += (int)strlen(tmp3) + 1; + tmp1 = strstr(tmp3, footer_str); + temp_len += (int)strlen(tmp3) + 1; + } + if (tmp1) + { + axis2_char_t *req_header = NULL; + axis2_char_t *req_payload = NULL; + int req_content_len = 0; + req_content_len = (int)(tmp1 - request_buffer) - 4; + *tmp1 = '\0'; + tmp1 = NULL; + tmp1 = strstr(request_buffer, "\r\n\r\n"); + if (tmp1) + { + axis2_char_t *listen_host = "localhost"; + int write_socket = -1; + axutil_stream_t *write_stream = NULL; + tmp1 += 2; + *tmp1 = '\0'; + req_payload = tmp1 + 2; + tmp1 = axutil_strdup(env, request_buffer); + req_content_len -= (int)strlen(tmp1); + tmp1 = tcpmon_util_str_replace(env, tmp1, ";\n\t", "; "); + req_header = tmp1; + tmp2 = strstr(req_header, AXIS2_HTTP_HEADER_USER_AGENT ":"); + if (tmp2) + { + tmp3 = strstr(tmp2, "\r\n"); + if (tmp3) + { + int header_len = 0; + axis2_char_t *user_agent = AXIS2_HTTP_HEADER_USER_AGENT + ": " AXIS2_HTTP_HEADER_SERVER_AXIS2C " TCPMon"; + header_len = (int)(tmp3 - tmp2) + 2; + tmp1 = AXIS2_MALLOC(env->allocator, + sizeof(axis2_char_t) * header_len + 1); + memcpy(tmp1, tmp2, header_len); + tmp1[header_len] = '\0'; + header_len = 2 + (int)strlen(user_agent); + tmp2 = AXIS2_MALLOC(env->allocator, + sizeof(axis2_char_t) * (header_len + 1)); + sprintf(tmp2, "%s\r\n", user_agent); + req_header = tcpmon_util_str_replace(env, req_header, tmp1, tmp2); + AXIS2_FREE(env->allocator, tmp1); + AXIS2_FREE(env->allocator, tmp2); + tmp1 = NULL; + tmp2 = NULL; + } + } + if (!has_raw_binary) + { + tmp2 = strstr(req_header, AXIS2_HTTP_HEADER_CONTENT_LENGTH ":"); + if (tmp2) + { + tmp3 = strstr(tmp2, "\r\n"); + if (tmp3) + { + int header_len = 0; + header_len = (int)(tmp3 - tmp2) + 2; + tmp1 = AXIS2_MALLOC(env->allocator, + sizeof(axis2_char_t) * header_len + 1); + memcpy(tmp1, tmp2, header_len); + tmp1[header_len] = '\0'; + tmp2 = AXIS2_MALLOC(env->allocator, + sizeof(axis2_char_t) * (header_len + 2)); + req_content_len = (int)strlen(req_payload); + sprintf(tmp2, "%s%d\r\n", AXIS2_HTTP_HEADER_CONTENT_LENGTH + ": ", req_content_len); + req_header = tcpmon_util_str_replace(env, req_header, tmp1, tmp2); + AXIS2_FREE(env->allocator, tmp1); + AXIS2_FREE(env->allocator, tmp2); + tmp1 = NULL; + tmp2 = NULL; + } + } + } + tmp2 = strstr(req_header, AXIS2_HTTP_HEADER_HOST ":"); + if (tmp2) + { + tmp3 = strstr(tmp2, "\r\n"); + if (tmp3) + { + int header_len = 0; + header_len = (int)(tmp3 - tmp2) + 2; + tmp1 = AXIS2_MALLOC(env->allocator, + sizeof(axis2_char_t) * header_len + 1); + memcpy(tmp1, tmp2, header_len); + tmp1[header_len] = '\0'; + header_len = 16 + (int)strlen(target_host); + tmp2 = AXIS2_MALLOC(env->allocator, + sizeof(axis2_char_t) * (header_len + 1)); + sprintf(tmp2, "%s%s:%d\r\n", AXIS2_HTTP_HEADER_HOST ": ", target_host, + TCPMON_SESSION_GET_LISTEN_PORT(session, env)); + req_header = tcpmon_util_str_replace(env, req_header, tmp1, tmp2); + AXIS2_FREE(env->allocator, tmp1); + AXIS2_FREE(env->allocator, tmp2); + tmp1 = NULL; + tmp2 = NULL; + } + } + write_socket = + (int)axutil_network_handler_open_socket(env, listen_host, + TCPMON_SESSION_GET_LISTEN_PORT(session, env)); + if (write_socket == -1) + { + printf("\nerror in creating socket\n"); + } + else + { + write_stream = axutil_stream_create_socket(env, write_socket); + } + if (!write_stream) + { + printf("\nerror in creating stream\n"); + } + else + { + axutil_stream_write(write_stream, env, req_header, strlen(req_header)); + axutil_stream_write(write_stream, env, "\r\n", 2); + axutil_stream_write(write_stream, env, req_payload, req_content_len); + axutil_stream_free(write_stream, env); + axutil_network_handler_close_socket(env, write_socket); + } + AXIS2_FREE(env->allocator, req_header); + } + } + else if (read_len == 48 * 1024) + { + printf("\nrequest size greater than buffer\n"); + } + AXIS2_FREE(env->allocator, request_buffer); + break; + } + AXIS2_FREE(env->allocator, uuid_match); + } + if (end_reached) + { + break; + } + } + AXIS2_FREE(env->allocator, buffer); + + fclose(file); + return 0; +} + +int +on_new_entry( + const axutil_env_t * env, + tcpmon_entry_t * entry, + int status) +{ + char *plain_buffer = NULL; + char *formated_buffer = NULL; + int format = 0; + char *uuid = NULL; + int resend = 0; + + format = TCPMON_ENTRY_GET_FORMAT_BIT(entry, env); + + if (status == 0) + { + if (strstr(TCPMON_ENTRY_SENT_HEADERS(entry, env), + AXIS2_HTTP_HEADER_USER_AGENT ": "\ + AXIS2_HTTP_HEADER_SERVER_AXIS2C " TCPMon\r\n")) + { + resend = 1; + } + plain_buffer = TCPMON_ENTRY_SENT_DATA(entry, env); + if (plain_buffer) /* this can be possible as no xml present */ + { + if (TCPMON_ENTRY_GET_SENT_DATA_LENGTH(entry, env) == + (int)strlen(TCPMON_ENTRY_SENT_HEADERS(entry, env)) + + (int)strlen(plain_buffer) + 4) + { + format = 0; /* mtom scenario */ + } + formated_buffer = tcpmon_util_format_as_xml + (env, plain_buffer, format); + } + else + { + formated_buffer = ""; + } + printf("\n\n%s\n", resend ? "RESENDING DATA..": "SENDING DATA.."); + printf("/* sending time = %s*/\n", TCPMON_ENTRY_SENT_TIME(entry, env)); + uuid = axutil_uuid_gen(env); + printf("/* message uuid = %s*/\n", uuid); + AXIS2_FREE(env->allocator, uuid); + printf("---------------------\n"); + + if (format || TCPMON_ENTRY_GET_SENT_DATA_LENGTH(entry, env) == + (int)strlen(TCPMON_ENTRY_SENT_HEADERS(entry, env)) + + (int)strlen(formated_buffer) + 4) + { + printf("%s\n\n%s\n\n", TCPMON_ENTRY_SENT_HEADERS(entry, env), + formated_buffer); + } + else + { + int count = 0; + int printed = 0; + axis2_char_t *formated_buffer_temp = formated_buffer; + printf("%s\n", TCPMON_ENTRY_SENT_HEADERS(entry, env)); + count = TCPMON_ENTRY_GET_SENT_DATA_LENGTH(entry, env) - 4 - + (int)strlen(TCPMON_ENTRY_SENT_HEADERS(entry, env)); + while (count > printed) + { + int plen = 0; + plen = ((int)strlen(formated_buffer) + 1); + if (plen != 1) + { + printf("%s", formated_buffer); + } + printed += plen; + if (count > printed) + { + printf("%c", '\0'); + formated_buffer += plen; + } + } + formated_buffer = formated_buffer_temp; + } + } + if (status == 1) + { + plain_buffer = TCPMON_ENTRY_ARRIVED_DATA(entry, env); + if (plain_buffer) /* this can be possible as no xml present */ + { + if (TCPMON_ENTRY_GET_ARRIVED_DATA_LENGTH(entry, env) == + (int)strlen(TCPMON_ENTRY_ARRIVED_HEADERS(entry, env)) + + (int)strlen(plain_buffer) + 4) + { + format = 0; /* mtom scenario */ + } + formated_buffer = tcpmon_util_format_as_xml + (env, plain_buffer, format); + } + else + { + formated_buffer = ""; + } + printf("\n\n%s\n", "RETRIEVING DATA.."); + printf("/* retrieving time = %s*/\n", + TCPMON_ENTRY_ARRIVED_TIME(entry, env)); + printf("/* time throughput = %s*/\n", + TCPMON_ENTRY_TIME_DIFF(entry, env)); + printf("---------------------\n"); + + if (format || TCPMON_ENTRY_GET_ARRIVED_DATA_LENGTH(entry, env) == + (int)strlen(TCPMON_ENTRY_ARRIVED_HEADERS(entry, env)) + + (int)strlen(formated_buffer) + 4) + { + printf("%s\n\n%s\n\n", TCPMON_ENTRY_ARRIVED_HEADERS(entry, env), + formated_buffer); + } + else + { + int count = 0; + int printed = 0; + axis2_char_t *formated_buffer_temp = formated_buffer; + printf("%s\n", TCPMON_ENTRY_ARRIVED_HEADERS(entry, env)); + count = TCPMON_ENTRY_GET_ARRIVED_DATA_LENGTH(entry, env) - 4 - + (int)strlen(TCPMON_ENTRY_ARRIVED_HEADERS(entry, env)); + while (count > printed) + { + int plen = 0; + plen = ((int)strlen(formated_buffer) + 1); + if (plen != 1) + { + printf("%s", formated_buffer); + } + printed += plen; + if (count > printed) + { + printf("%c", '\0'); + formated_buffer += plen; + } + } + formated_buffer = formated_buffer_temp; + } + } + return 0; +} + +int +on_error_func( + const axutil_env_t * env, + char *error_message) +{ + fprintf(stderr, "ERROR: %s\n", error_message); + return 0; +} + + +/** + * Signal handler + */ +void +sig_handler( + int signal) +{ + + if (!system_env) + { + AXIS2_LOG_ERROR(system_env->log, AXIS2_LOG_SI, + "Received signal %d, unable to proceed system_env is NULL,\ + system exit with -1", signal); + _exit (-1); + } + + switch (signal) + { + case SIGINT: + { + AXIS2_LOG_INFO(system_env->log, "Received signal SIGINT. Utility " + "shutting down"); + printf("\n\n"); + TCPMON_SESSION_STOP(session, system_env); + TCPMON_SESSION_FREE(session, system_env); + AXIS2_FREE(system_env->allocator, target_host); + if (system_env) + { + axutil_env_free(system_env); + } + exit(0); + } +#ifndef WIN32 + case SIGPIPE: + { + AXIS2_LOG_INFO(system_env->log, "Received signal SIGPIPE. Operation " + "aborted"); + return; + } +#endif + case SIGSEGV: + { + fprintf(stderr, "Received deadly signal SIGSEGV. Terminating\n"); + _exit(-1); + } + } +} + diff --git a/tools/tcpmon/src/tcpmon_entry_local.h b/tools/tcpmon/src/tcpmon_entry_local.h new file mode 100644 index 0000000..8ba9c6a --- /dev/null +++ b/tools/tcpmon/src/tcpmon_entry_local.h @@ -0,0 +1,16 @@ +#include +#include "tcpmon_entry.h" +#include "tcpmon_session_local.h" + +typedef struct tcpmon_entry_request_data +{ + const axutil_env_t *env; + int socket; + tcpmon_session_t *session; +} +tcpmon_entry_request_data_t; + +void *AXIS2_CALL +tcpmon_entry_new_entry_funct( + axutil_thread_t * thd, + void *data); diff --git a/tools/tcpmon/src/tcpmon_session_local.h b/tools/tcpmon/src/tcpmon_session_local.h new file mode 100644 index 0000000..eee9cc6 --- /dev/null +++ b/tools/tcpmon/src/tcpmon_session_local.h @@ -0,0 +1,15 @@ +#include +#include + +axis2_status_t tcpmon_session_add_new_entry( + tcpmon_session_t * session, + const axutil_env_t * env, + tcpmon_entry_t * entry); + +TCPMON_SESSION_TRANS_ERROR_FUNCT tcpmon_session_get_on_trans_fault( + tcpmon_session_t * session, + const axutil_env_t * env); + +TCPMON_SESSION_NEW_ENTRY_FUNCT tcpmon_session_get_on_new_entry( + tcpmon_session_t * session, + const axutil_env_t * env); diff --git a/tools/tcpmon/src/util.c b/tools/tcpmon/src/util.c new file mode 100644 index 0000000..d4a73ee --- /dev/null +++ b/tools/tcpmon/src/util.c @@ -0,0 +1,806 @@ + +/* + * 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 +#include + +#include + +#define START_ELEMENT 1 +#define CHAR_VALUE 2 +#define END_ELEMENT 3 +#define EMPTY_ELEMENT 4 + +typedef struct tcpmon_util_allocator +{ + int allocated; + int index; + axis2_char_t *buffer; +} +tcpmon_util_allocator_t; + +/*static void add_string(const axutil_env_t* env, + tcpmon_util_allocator_t* allocator, + axis2_char_t* string); +*/ + +/*static void add_axis2_char_t(const axutil_env_t* env, + tcpmon_util_allocator_t* allocator, + axis2_char_t c, + int turns); +*/ +axis2_char_t * +tcpmon_util_format_as_xml( + const axutil_env_t * env, + axis2_char_t * data, + int format) +{ + if (format) + { + int c; + int tab_pos = 0; + int has_value = 0; + int has_space = 0; + int start_ele = 0; + int prev_case = 0; + int buffer_size = 0; + + axis2_char_t *out; + + axiom_xml_reader_t *xml_reader = NULL; + + buffer_size = 2 * ((int)strlen(data)); + /* We are sure that the difference lies within the int range */ + out = AXIS2_MALLOC(env->allocator, buffer_size * sizeof(axis2_char_t)); + + if (data) + { + int size = 0; + size = (int)strlen(data); + /* We are sure that the difference lies within the int range */ + xml_reader = + axiom_xml_reader_create_for_memory(env, data, size, "utf-8", + AXIS2_XML_PARSER_TYPE_BUFFER); + if (!xml_reader) + return NULL; + } + + axiom_xml_reader_init(); + + while ((c = axiom_xml_reader_next(xml_reader, env)) != -1) + { + switch (c) + { + case AXIOM_XML_READER_START_DOCUMENT: + { + int ix; + + tcpmon_util_strcat(out, " 0; ix--) + { + axis2_char_t *attr_prefix; + axis2_char_t *attr_name; + axis2_char_t *attr_value; + + attr_prefix = + (axis2_char_t *) + axiom_xml_reader_get_attribute_prefix_by_number + (xml_reader, env, ix); + if (attr_prefix) + { + tcpmon_util_strcat(out, attr_prefix, &buffer_size, env); + tcpmon_util_strcat(out, ":", &buffer_size, env); + } + + attr_name = + (axis2_char_t *) + axiom_xml_reader_get_attribute_name_by_number + (xml_reader, env, ix); + if (attr_name) + { + tcpmon_util_strcat(out, attr_name, &buffer_size, env); + tcpmon_util_strcat(out, "=\"", &buffer_size, env); + } + + attr_value = + (axis2_char_t *) + axiom_xml_reader_get_attribute_value_by_number + (xml_reader, env, ix); + if (attr_value) + { + tcpmon_util_strcat(out, attr_value, &buffer_size, env); + tcpmon_util_strcat(out, "\"", &buffer_size, env); + } + } + + printf("?>"); + } + break; + case AXIOM_XML_READER_START_ELEMENT: + { + int i, + ix, + has_prefix = 0; + + axis2_char_t *ele_name; + axis2_char_t *ele_prefix; + + prev_case = START_ELEMENT; + + has_value = 0; + has_space = 0; + + if (start_ele != 0) + tcpmon_util_strcat(out, "\n", &buffer_size, env); + + for (i = 0; i < tab_pos; i++) + tcpmon_util_strcat(out, "\t", &buffer_size, env); + + tcpmon_util_strcat(out, "<", &buffer_size, env); + + ele_prefix = + (axis2_char_t *) axiom_xml_reader_get_prefix(xml_reader, + env); + if (ele_prefix) + { + tcpmon_util_strcat(out, ele_prefix, &buffer_size, env); + tcpmon_util_strcat(out, ":", &buffer_size, env); + } + + ele_name = + (axis2_char_t *) axiom_xml_reader_get_name(xml_reader, + env); + if (ele_name) + { + tcpmon_util_strcat(out, ele_name, &buffer_size, env); + } + + ix = axiom_xml_reader_get_attribute_count(xml_reader, env); + for (; ix > 0; ix--) + { + axis2_char_t *attr_prefix; + axis2_char_t *attr_name; + axis2_char_t *attr_value; + + attr_prefix = + (axis2_char_t *) + axiom_xml_reader_get_attribute_prefix_by_number + (xml_reader, env, ix); + if (attr_prefix) + { + has_prefix = 1; + tcpmon_util_strcat(out, " ", &buffer_size, env); + tcpmon_util_strcat(out, attr_prefix, &buffer_size, env); + tcpmon_util_strcat(out, ":", &buffer_size, env); + } + + attr_name = + (axis2_char_t *) + axiom_xml_reader_get_attribute_name_by_number + (xml_reader, env, ix); + if (attr_name) + { + if (has_prefix) + { + tcpmon_util_strcat(out, attr_name, &buffer_size, + env); + tcpmon_util_strcat(out, "=\"", &buffer_size, env); + } + else + { + tcpmon_util_strcat(out, " ", &buffer_size, env); + tcpmon_util_strcat(out, attr_name, &buffer_size, + env); + tcpmon_util_strcat(out, "=\"", &buffer_size, env); + } + + has_prefix = 0; + } + + attr_value = + (axis2_char_t *) + axiom_xml_reader_get_attribute_value_by_number + (xml_reader, env, ix); + if (attr_value) + { + tcpmon_util_strcat(out, attr_value, &buffer_size, env); + tcpmon_util_strcat(out, "\"", &buffer_size, env); + } + } + + tcpmon_util_strcat(out, ">", &buffer_size, env); + + tab_pos++; + start_ele = 1; + } + break; + case AXIOM_XML_READER_CHARACTER: + { + axis2_char_t *ele_value; + + prev_case = CHAR_VALUE; + + ele_value = axiom_xml_reader_get_value(xml_reader, env); + if (ele_value) + tcpmon_util_strcat(out, ele_value, &buffer_size, env); + + has_value = 1; + + } + break; + case AXIOM_XML_READER_EMPTY_ELEMENT: + { + int i, + ix, + has_prefix = 0; + + axis2_char_t *ele_name; + axis2_char_t *ele_prefix; + + prev_case = EMPTY_ELEMENT; + + has_value = 0; + has_space = 0; + + if (start_ele != 0) + tcpmon_util_strcat(out, "\n", &buffer_size, env); + + for (i = 0; i < tab_pos; i++) + tcpmon_util_strcat(out, "\t", &buffer_size, env); + + tcpmon_util_strcat(out, "<", &buffer_size, env); + + ele_prefix = + (axis2_char_t *) axiom_xml_reader_get_prefix(xml_reader, + env); + if (ele_prefix) + { + tcpmon_util_strcat(out, ele_prefix, &buffer_size, env); + tcpmon_util_strcat(out, ":", &buffer_size, env); + } + + ele_name = + (axis2_char_t *) axiom_xml_reader_get_name(xml_reader, + env); + if (ele_name) + tcpmon_util_strcat(out, ele_name, &buffer_size, env); + + ix = axiom_xml_reader_get_attribute_count(xml_reader, env); + for (; ix > 0; ix--) + { + axis2_char_t *attr_prefix; + axis2_char_t *attr_name; + axis2_char_t *attr_value; + + attr_prefix = + (axis2_char_t *) + axiom_xml_reader_get_attribute_prefix_by_number + (xml_reader, env, ix); + if (attr_prefix) + { + has_prefix = 1; + tcpmon_util_strcat(out, " ", &buffer_size, env); + tcpmon_util_strcat(out, attr_prefix, &buffer_size, env); + tcpmon_util_strcat(out, ":", &buffer_size, env); + } + + attr_name = + (axis2_char_t *) + axiom_xml_reader_get_attribute_name_by_number + (xml_reader, env, ix); + if (attr_name) + { + if (has_prefix) + { + tcpmon_util_strcat(out, attr_name, &buffer_size, + env); + tcpmon_util_strcat(out, "=\"", &buffer_size, env); + } + else + { + tcpmon_util_strcat(out, " ", &buffer_size, env); + tcpmon_util_strcat(out, attr_name, &buffer_size, + env); + tcpmon_util_strcat(out, "=\"", &buffer_size, env); + } + has_prefix = 0; + } + + attr_value = + (axis2_char_t *) + axiom_xml_reader_get_attribute_value_by_number + (xml_reader, env, ix); + if (attr_value) + { + tcpmon_util_strcat(out, attr_value, &buffer_size, env); + tcpmon_util_strcat(out, "\"", &buffer_size, env); + } + } + + tcpmon_util_strcat(out, "/>", &buffer_size, env); + start_ele = 1; + } + break; + case AXIOM_XML_READER_END_ELEMENT: + { + int i; + + axis2_char_t *ele_prefix; + axis2_char_t *ele_name; + + tab_pos--; + + if (has_value == 0 && prev_case != START_ELEMENT) + { + tcpmon_util_strcat(out, "\n", &buffer_size, env); + for (i = 0; i < tab_pos; i++) + tcpmon_util_strcat(out, "\t", &buffer_size, env); + } + + has_value = 0; + + tcpmon_util_strcat(out, "", &buffer_size, env); + } + prev_case = END_ELEMENT; + + } + break; + } + } + return out; + } + return data; +} + +/*void add_string(const axutil_env_t* env, + tcpmon_util_allocator_t* allocator, + axis2_char_t* string) +{ + int additional_len = 0; + void* dest = NULL; + void* src = NULL; + int count = 0; + + additional_len = axutil_strlen(string) + 1; + if (allocator-> index + additional_len >= allocator-> allocated) + { + if (allocator-> allocated == 0) + { + allocator-> buffer = + AXIS2_MALLOC(env-> allocator, additional_len); + } + else + { + allocator-> buffer = + AXIS2_REALLOC(env-> allocator, allocator-> buffer, + allocator-> allocated + additional_len); + } + allocator-> allocated += additional_len; + } + + dest = allocator-> buffer + allocator-> index; + src = string; + count = additional_len; + memcpy(dest, src, count); + + allocator-> index += count - 1; +} +*/ + +/*void add_axis2_char_t(const axutil_env_t* env, + tcpmon_util_allocator_t* allocator, + axis2_char_t c, + int turns) +{ + int additional_len = 0; + + additional_len = turns + 1; + if (allocator-> index + additional_len >= allocator-> allocated) + { + if (allocator-> allocated == 0) + { + allocator-> buffer = + AXIS2_MALLOC(env-> allocator, additional_len); + } + else + { + allocator-> buffer = + AXIS2_REALLOC(env-> allocator, allocator-> buffer, + allocator-> allocated + additional_len); + } + allocator-> allocated += additional_len; + } + + memset(allocator-> buffer + allocator-> index, c, turns); + + allocator-> index += turns; + +} */ + +axis2_char_t * +tcpmon_util_strcat( + axis2_char_t * dest, + axis2_char_t * source, + int *buff_size, + const axutil_env_t * env) +{ + int cur_len = 0; + int source_len = 0; + + axis2_char_t *tmp; + cur_len = (int)strlen(dest); + /* We are sure that the difference lies within the int range */ + source_len = (int)strlen(source); + /* We are sure that the difference lies within the int range */ + + if ((*buff_size - cur_len) < source_len) + { + *buff_size = *buff_size + (*buff_size * 2); + tmp = + (axis2_char_t *) AXIS2_REALLOC(env->allocator, dest, + *buff_size * sizeof(axis2_char_t)); + dest = tmp; + strcat((char *) dest, (char *) source); + } + else + { + strcat((char *) dest, (char *) source); + } + + return dest; +} + +char * +tcpmon_util_str_replace( + const axutil_env_t *env, + char *str, + const char *search, + const char *replace) +{ + char *str_return = NULL; + char *str_tmp = NULL; + char *str_relic = NULL; + int size = ((int)strlen(str)) * 2; + /* We are sure that the difference lies within the int range */ + int addmem = size; + int diff = (int)(strlen(replace) - strlen(search)); + /* We are sure that the difference lies within the int range */ + + str_return = (char *) AXIS2_MALLOC(env->allocator, ((size + 1) * sizeof(char))); + str_tmp = (char *) AXIS2_MALLOC(env->allocator, (size * sizeof(char))); + + + if (str_return == NULL || str_tmp == NULL) + { + AXIS2_FREE(env->allocator, str_return); + str_return = NULL; + AXIS2_FREE(env->allocator, str_tmp); + str_tmp = NULL; + return "function tcpmon_util_str_replace : give me more memory"; + } + if (!strcmp(search, replace)) + { + AXIS2_FREE(env->allocator, str_return); + str_return = NULL; + AXIS2_FREE(env->allocator, str_tmp); + str_tmp = NULL; + return str; + } + + strcpy(str_return, str); + + while ((str_relic = strstr(str_return, search)) != NULL) + { + if ((int)strlen(str_return) + diff >= addmem) + /* We are sure that the difference lies within the int range */ + { + str_return = (char *) realloc(str_return, addmem += size); + str_tmp = (char *) realloc(str_tmp, addmem); + + if (str_return == NULL || str_tmp == NULL) + { + AXIS2_FREE(env->allocator, str_return); + str_return = NULL; + AXIS2_FREE(env->allocator, str_tmp); + str_tmp = NULL; + return "function tcpmon_str_replace : gimme more memory"; + } + } + + strcpy(str_tmp, replace); + strcat(str_tmp, (str_relic + strlen(search))); + *str_relic = '\0'; + + strcat(str_return, str_tmp); + } + + AXIS2_FREE(env->allocator, str_tmp); + str_tmp = NULL; + /* free(str); */ /* we are not allocating memory using str */ + str_return[addmem] = '\0'; + return (str_return); +} + + +axis2_char_t * +tcpmon_util_read_current_stream( + const axutil_env_t * env, + axutil_stream_t * stream, + int *stream_size, + axis2_char_t ** header, + axis2_char_t ** data) +{ + int read_size = 0; + axis2_char_t *buffer = NULL; + axis2_char_t *header_ptr = NULL; + axis2_char_t *body_ptr = NULL; + int header_found = 0; + int header_just_finished = 0; + int read = 0; + int header_width = 0; + int current_line_offset = 0; + int mtom_optimized = 0; + axis2_char_t *current_line = NULL; + int line_just_ended = 1; + axis2_char_t *length_char = 0; + int length = -1; + int chunked_encoded = 0; + int is_get = 0; + int zero_content_length = 0; + + buffer = AXIS2_MALLOC(env->allocator, sizeof(axis2_char_t)); + *data = NULL; + *header = NULL; + do + { + buffer = AXIS2_REALLOC(env->allocator, buffer, + sizeof(axis2_char_t) * (read_size + 1)); + *(buffer + read_size) = '\0'; + read = axutil_stream_read(stream, env, buffer + read_size, 1); + + if (header_just_finished) + { + header_just_finished = 0; + header_width = read_size; + } + + /** identify the content lenth*/ + if (!header_found && *(buffer + read_size) == '\r') + { + *(buffer + read_size) = '\0'; + current_line = buffer + current_line_offset; + if (!mtom_optimized && strstr(current_line, "multipart/related")) + mtom_optimized = 1; + if (strstr(current_line, "Content-Length")) + { + length_char = strstr(current_line, ":"); + if (length_char) + { + length_char++; + length = atoi(length_char); + if (length == 0) + { + zero_content_length = 1; + } + } + } + if (strstr(current_line, "GET") || strstr(current_line, "HEAD") + || strstr(current_line, "DELETE")) + { + is_get = 1; + /** Captures GET style requests */ + } + *(buffer + read_size) = '\r'; + } + if (!header_found && line_just_ended) + { + line_just_ended = 0; + current_line_offset = read_size; + } + if (!header_found && *(buffer + read_size) == '\n') + { + line_just_ended = 1; /* set for the next loop to read */ + } + if (header_found) + { + length--; + } + if (header_found && + read_size >= 4 && + chunked_encoded == 1 && + *(buffer + read_size) == '\n' && + *(buffer + read_size - 1) == '\r' && + *(buffer + read_size - 2) == '\n' && + *(buffer + read_size - 3) == '\r' && + *(buffer + read_size - 4) == '0') + { + + length = 0; /** this occurs in chunked transfer encoding */ + } + + /** identify the end of the header */ + if (!header_found && + read_size >= 3 && + *(buffer + read_size) == '\n' && + *(buffer + read_size - 1) == '\r' && + *(buffer + read_size - 2) == '\n' && + *(buffer + read_size - 3) == '\r') + { + header_found = 1; + *(buffer + read_size - 3) = '\0'; + if (header_ptr) + { + AXIS2_FREE(env->allocator, header_ptr); + } + header_ptr = (axis2_char_t *) axutil_strdup(env, buffer); + header_just_finished = 1; + *(buffer + read_size - 3) = '\r'; + if (is_get && length == -1) + { + break; + } + } + read_size++; + if (!chunked_encoded && length < -1) + { + header_width = 0; + /* break; */ + + /** this is considered as transfer-encoding = chunked */ + chunked_encoded = 1; + header_found = 1; + *(buffer + read_size - 3) = '\0'; + if (header_ptr) + { + AXIS2_FREE(env->allocator, header_ptr); + } + header_ptr = (axis2_char_t *) axutil_strdup(env, buffer); + header_just_finished = 1; + *(buffer + read_size - 3) = '\r'; + } + if (!(*(buffer + read_size - 1))) + { + if (!mtom_optimized) + { + read_size--; + length = 0; + } + else + { + /**(buffer + read_size - 1) = ' ';*/ + } + } + } + while (length != 0); + + if (is_get) + { + read_size++; + } + else if (zero_content_length) + { + read_size += 3; + } + + buffer = AXIS2_REALLOC(env->allocator, buffer, + sizeof(axis2_char_t) * (read_size + 1)); + *(buffer + read_size) = '\0'; + + if (header_width != 0) + { + body_ptr = buffer + header_width; + if (body_ptr && *body_ptr) + { + if (mtom_optimized) + { + int count = read_size - (int)strlen(header_ptr) - 4; + int copied = 0; + int plen = 0; + axis2_char_t *temp = NULL; + temp = AXIS2_MALLOC(env->allocator, + sizeof(axis2_char_t) * count + 1); + while(count > copied) + { + plen = 0; + plen = ((int)strlen(body_ptr) + 1); + if (plen != 1) + { + sprintf(temp, "%s", body_ptr); + } + copied += plen; + if (count > copied) + { + temp += plen; + body_ptr += plen; + } + } + copied -= plen; + temp -= copied; + temp[count] = '\0'; + *data = temp; + } + else + { + *data = (axis2_char_t *) axutil_strdup(env, body_ptr); + } + } + body_ptr = NULL; + } + else + { + /** soap body part is unavailable */ + if (is_get) + { + *data = (axis2_char_t *) axutil_strdup(env, "\n"); + *(buffer + read_size - 1) = '\n'; + } + else if (zero_content_length) + { + *data = (axis2_char_t *) axutil_strdup(env, "\n"); + *(buffer + read_size - 3) = '\n'; + *(buffer + read_size - 2) = '\r'; + *(buffer + read_size - 1) = '\n'; + } + if (header_ptr) + { + AXIS2_FREE(env->allocator, header_ptr); + } + header_ptr = (axis2_char_t *) axutil_strdup(env, buffer); + } + + *header = header_ptr; + *stream_size = read_size; + return buffer; +} + + +int +tcpmon_util_write_to_file( + char *filename, + char *buffer) +{ + int size = 0; + if (filename) + { + FILE *fp = fopen(filename, "ab"); + size = (int)fwrite(buffer, 1, strlen(buffer), fp); + /* We are sure that the difference lies within the int range */ + fclose(fp); + } + return size; +} + diff --git a/tools/tcpmon/test/Makefile.am b/tools/tcpmon/test/Makefile.am new file mode 100644 index 0000000..85eb6ca --- /dev/null +++ b/tools/tcpmon/test/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = unit diff --git a/tools/tcpmon/test/unit/Makefile.am b/tools/tcpmon/test/unit/Makefile.am new file mode 100644 index 0000000..719bd16 --- /dev/null +++ b/tools/tcpmon/test/unit/Makefile.am @@ -0,0 +1,19 @@ +TESTS = +prgbindir=$(prefix)/bin/unit_test +prgbin_PROGRAMS = tcpmon_unit_test_suite + +tcpmon_unit_test_suite_SOURCES = main.c tcpmon_test.c + +tcpmon_unit_test_suite_LDADD = \ + $(top_builddir)/src/libaxis2_tcpmon.la \ + -L$(CUTEST_HOME)/lib \ + -lcutest \ + ../../../../util/src/libaxutil.la \ + ../../../../axiom/src/om/libaxis2_axiom.la \ + $(NULL) + + +INCLUDES = -I${CUTEST_HOME}/include \ + -I$(top_builddir)/include \ + -I ../../../../util/include \ + $(NULL) diff --git a/tools/tcpmon/test/unit/main.c b/tools/tcpmon/test/unit/main.c new file mode 100644 index 0000000..531ed66 --- /dev/null +++ b/tools/tcpmon/test/unit/main.c @@ -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. + */ + +#include +#include +#include "tcpmon_test.h" + +void +RunAllTests( + void) +{ + CuString *output = CuStringNew(); + CuSuite *suite = CuSuiteNew(); + + CuSuiteAddSuite(suite, (CuSuite *) tcpmon_GetSuite()); + + CuSuiteRun(suite); + CuSuiteSummary(suite, output); + CuSuiteDetails(suite, output); + printf("%s\n", output->buffer); +} + +int +main( + void) +{ + RunAllTests(); + return 0; +} diff --git a/tools/tcpmon/test/unit/result b/tools/tcpmon/test/unit/result new file mode 100644 index 0000000..130ca3a --- /dev/null +++ b/tools/tcpmon/test/unit/result @@ -0,0 +1,14 @@ +F + +There was 1 failure: +1) test_format_xml: tcpmon_test.c:28: expected < + check for one step + + > but was < + check for one step + +í> + +!!!FAILURES!!! +Runs: 1 Passes: 0 Fails: 1 + diff --git a/tools/tcpmon/test/unit/tcpmon_test.c b/tools/tcpmon/test/unit/tcpmon_test.c new file mode 100644 index 0000000..f5ee7be --- /dev/null +++ b/tools/tcpmon/test/unit/tcpmon_test.c @@ -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. + */ + +#include +#include +#include "tcpmon_test.h" +#include +#include + +#include + +void +test_format_xml( + CuTest * tc) +{ + axutil_env_t *env; + axutil_allocator_t *allocator; + axis2_char_t *input; + axis2_char_t *actual; + axis2_char_t *expected; + + allocator = axutil_allocator_init(NULL); + env = axutil_env_create(allocator); + + input = (char *) axutil_strdup(env, "check for one step"); + actual = (char *) tcpmon_util_format_as_xml(env, input); + expected = "\n" "\tcheck for one step\n" "\n"; + CuAssertStrEquals(tc, expected, actual); + free(actual); + free(input); + + input = + (char *) axutil_strdup(env, + "check for one step"); + actual = (char *) tcpmon_util_format_as_xml(env, input); + expected = + "\n" + "\t\n" + "\t\t\n" + "\t\t\tcheck for one step\n" + "\t\t\n" "\t\n" "\n"; + + CuAssertStrEquals(tc, expected, actual); + free(actual); + free(input); + + input = (char *) axutil_strdup(env, + "check for one step"); + actual = (char *) tcpmon_util_format_as_xml(env, input); + expected = "\n" + "\n" + "\t\n" + "\t\t\n" + "\t\t\tcheck for one step\n" + "\t\t\n" "\t\n" "\n"; + + CuAssertStrEquals(tc, expected, actual); + free(actual); + free(input); + +} + +CuSuite * +tcpmon_GetSuite( + ) +{ + CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_format_xml); + return suite; +} diff --git a/tools/tcpmon/test/unit/tcpmon_test.h b/tools/tcpmon/test/unit/tcpmon_test.h new file mode 100644 index 0000000..66c2e0a --- /dev/null +++ b/tools/tcpmon/test/unit/tcpmon_test.h @@ -0,0 +1,9 @@ +#ifndef TCPMON_TEST_H +#define TCPMON_TEST_H + +#include + +CuSuite *tcpmon_GetSuite( +); + +#endif /* TCPMON_TEST_H */ -- cgit v1.1-32-gdbae