Browse Source

repository move

master
Peter J. Jones 11 years ago
parent
commit
1b841892cf
100 changed files with 12333 additions and 0 deletions
  1. 7
    0
      Jamfile
  2. 234
    0
      Jamrules
  3. 3
    0
      build/msvc7.bat
  4. 70
    0
      configure
  5. 8
    0
      docs/VERSION
  6. 1117
    0
      docs/doxygen/doxyfile
  7. 2
    0
      docs/manual/Makefile
  8. 25
    0
      docs/manual/bugs.xml
  9. 347
    0
      docs/manual/changelog.xml
  10. 59
    0
      docs/manual/credits.xml
  11. 119
    0
      docs/manual/get_started.xml
  12. 92
    0
      docs/manual/manual.xml
  13. 53
    0
      docs/manual/readme.xml
  14. 99
    0
      docs/manual/todo.xml
  15. 3
    0
      examples/.cvsignore
  16. 56
    0
      examples/Jamfile
  17. 13
    0
      examples/README
  18. 3
    0
      examples/config.jam
  19. 93
    0
      examples/http_get.cxx
  20. 173
    0
      examples/http_https_server.cxx
  21. 108
    0
      examples/https_get.cxx
  22. 183
    0
      examples/multi_server.cxx
  23. 76
    0
      examples/streambuf_echo_client.cxx
  24. 64
    0
      examples/tcp_daytime_client.cxx
  25. 82
    0
      examples/tcp_echo_client.cxx
  26. 83
    0
      examples/tcp_echo_server.cxx
  27. 79
    0
      examples/tls_echo_client.cxx
  28. 89
    0
      examples/tls_echo_server.cxx
  29. 76
    0
      examples/udp_daytime_client.cxx
  30. 85
    0
      examples/udp_echo_client.cxx
  31. 79
    0
      examples/udp_echo_server.cxx
  32. 17
    0
      examples/win32.jam
  33. 222
    0
      include/netxx/address.h
  34. 244
    0
      include/netxx/datagram.h
  35. 161
    0
      include/netxx/datagramserver.h
  36. 192
    0
      include/netxx/netbuf.h
  37. 50
    0
      include/netxx/netxx.h
  38. 227
    0
      include/netxx/peer.h
  39. 197
    0
      include/netxx/probe.h
  40. 216
    0
      include/netxx/probeinfo.h
  41. 123
    0
      include/netxx/sockopt.h
  42. 238
    0
      include/netxx/stream.h
  43. 188
    0
      include/netxx/streambase.h
  44. 133
    0
      include/netxx/streamserver.h
  45. 137
    0
      include/netxx/timeout.h
  46. 168
    0
      include/netxx/tls/certificate.h
  47. 181
    0
      include/netxx/tls/context.h
  48. 41
    0
      include/netxx/tls/netxx.h
  49. 220
    0
      include/netxx/tls/stream.h
  50. 70
    0
      include/netxx/types.h
  51. 3
    0
      src/.cvsignore
  52. 58
    0
      src/Jamfile
  53. 81
    0
      src/accept.cxx
  54. 60
    0
      src/accept.h
  55. 249
    0
      src/address.cxx
  56. 68
    0
      src/common.h
  57. 82
    0
      src/compat.h
  58. 4
    0
      src/config.jam
  59. 370
    0
      src/datagram.cxx
  60. 119
    0
      src/datagramserver.cxx
  61. 72
    0
      src/inet_ntop.cxx
  62. 42
    0
      src/inet_ntop.h
  63. 63
    0
      src/inet_pton.cxx
  64. 39
    0
      src/inet_pton.h
  65. 53
    0
      src/osutil.cxx
  66. 97
    0
      src/osutil.h
  67. 221
    0
      src/peer.cxx
  68. 194
    0
      src/probe.cxx
  69. 82
    0
      src/probe_impl.h
  70. 236
    0
      src/probe_select.cxx
  71. 87
    0
      src/recvfrom.cxx
  72. 64
    0
      src/recvfrom.h
  73. 80
    0
      src/resolve.h
  74. 128
    0
      src/resolve_getaddrinfo.cxx
  75. 110
    0
      src/resolve_gethostbyname.cxx
  76. 57
    0
      src/resolve_getservbyname.cxx
  77. 213
    0
      src/serverbase.cxx
  78. 95
    0
      src/serverbase.h
  79. 132
    0
      src/sockaddr.cxx
  80. 83
    0
      src/sockaddr.h
  81. 419
    0
      src/socket.cxx
  82. 271
    0
      src/socket.h
  83. 142
    0
      src/sockopt.cxx
  84. 144
    0
      src/stream.cxx
  85. 175
    0
      src/streambase.cxx
  86. 139
    0
      src/streamserver.cxx
  87. 79
    0
      src/tls_cert_pimpl.h
  88. 151
    0
      src/tls_certificate.cxx
  89. 177
    0
      src/tls_context.cxx
  90. 57
    0
      src/tls_context_pimpl.h
  91. 313
    0
      src/tls_stream.cxx
  92. 109
    0
      src/tls_tls_pimpl.cxx
  93. 83
    0
      src/tls_tls_pimpl.h
  94. 21
    0
      src/win32.jam
  95. 41
    0
      tests/build/Jamfile
  96. 41
    0
      tests/build/getaddrinfo.c
  97. 40
    0
      tests/build/inet6.c
  98. 42
    0
      tests/build/inet_ntop.c
  99. 42
    0
      tests/build/inet_pton.c
  100. 0
    0
      tests/build/openssl.c

+ 7
- 0
Jamfile View File

@@ -0,0 +1,7 @@
####
# standard top Jamfile stuff
TOP ?= $(DOT) ;
SubInclude TOP "src" ;
SubInclude TOP "examples" ;

# vim:ft=jam

+ 234
- 0
Jamrules View File

@@ -0,0 +1,234 @@
######################################################################
# Copyright (C) 2003-2004 Peter J Jones (pjones@pmade.org)
# All Rights Reserved
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name of the Author nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
################################################################################
#
# This file is part of the Jamtools project.
#
# http://cvs.pmade.org/view/
#
# $Id: Jamrules,v 1.12 2004/04/06 17:59:56 pjones Exp $
# $Name: $
#
################################################################################

####
# Make sure that we are using Boost.Jam
####
if ! $(JAM_VERSION)
{
ECHO "Sorry, this build requires Boost.Jam. You can download Boost.Jam" ;
ECHO "by using the Download link on http://boost.org/" ;
EXIT ;
}

####
# Make sure we were not invoked as bjam
####
if [ MATCH .*(bjam).* : $(ARGV[1]:BL) ]
{
ECHO "Please don't invoke Boost.Jam as `bjam', use `jam' instead." ;
EXIT ;
}

####
# Having BOOST_ROOT set will break stuff.
####
if $(BOOST_ROOT)
{
ECHO "Sorry, you can't build this project if you have BOOST_ROOT set because" ;
ECHO "it prevents Boost.Jam from loading the correct Jambase." ;
EXIT ;
}

###
# Teach Jam what .cxx files are
###
rule UserObject
{
switch $(>)
{
case *.cxx : C++ $(<) : $(>) ;
}
}

################################################################################
#
# General Compiler Settings
#
################################################################################

####
# fix a problem in Jambase with regards to GCC
####
if $(C++) = "gcc" || $(C++) = "cc"
{
C++ = "g++" ;
LINK = $(C++) ;
}

####
# fix Jambase for Darwin
####
if $(OSFULL[1]:L) = "macosxppc"
{
C++ = "c++" ;
LINK = $(C++) ;
}

####
# set some good default compiler flags for GCC
####
if $(C++) = "g++" || $(C++) = "c++"
{
C++FLAGS = -Wall -W -Wcast-align -Wwrite-strings ;
C++FLAGS += -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS ;
LINKFLAGS = $(C++FLAGS) ;
}

####
# set some good compiler flags for MSVC
####
if $(JAM_TOOLSET) = "VC7" || $(JAM_TOOLSET) = "VISUALC"
{
AR = "$(AR) /nologo" ;

C++FLAGS += "/D WIN32" ;
C++FLAGS += "/EHsc" ;
C++FLAGS += "/MD" ;
C++FLAGS += "/W1" ;

LINKFLAGS += "/NODEFAULTLIB:LIBC" ;
}

################################################################################
#
# Build variants
#
################################################################################
if --release in $(ARGV)
{
ECHO "+---------------------------------------------------------+" ;
ECHO "| Release Build |" ;
ECHO "+---------------------------------------------------------+" ;

BUILD_VARIANT = "release" ;

####
# add release flags for GCC
####
if $(C++) = "g++" || $(C++) = "c++"
{
C++FLAGS += "-O2" ;
C++FLAGS += "-DNDEBUG" ;
}
####
# add release flags for MSVC
####
if $(JAM_TOOLSET) = "VC7" || $(JAM_TOOLSET) = "VISUALC"
{
C++FLAGS += "/O2 /GB" ;
C++FLAGS += "/D NDEBUG" ;
}
}
else
{
ECHO "+---------------------------------------------------------+" ;
ECHO "| Debug Build |" ;
ECHO "+---------------------------------------------------------+" ;

BUILD_VARIANT = "debug" ;

####
# add debug flags for GCC
####
if $(C++) = "g++" || $(C++) = "c++"
{
C++FLAGS += "-g" ;
}
####
# add debug flags for MSVC
####
if $(JAM_TOOLSET) = "VC7" || $(JAM_TOOLSET) = "VISUALC"
{
C++FLAGS += "/Od /Zi" ;
LINKFLAGS += "/DEBUG" ;
}
}

################################################################################
#
# Rules
#
################################################################################

####
# Help adjust LOCATE_TARGET
####
rule JT_UseVariant
{
LOCATE_TARGET = $(LOCATE_TARGET)$(SLASH)$(BUILD_VARIANT) ;
}

####
# Build a library that will be used in other parts of the project.
# Same syntax as the Jambase Library rule.
####
rule JT_MakeLibrary
{
Library $(1) : $(2) ;
JT_Made_$(SUBDIR)$(1) = "yes" ;
}

####
# Help link with a built library. The library you want to link with must
# have been built with JT_MakeLibrary.
#
# <image> : <library> : <path>
#
####
rule JT_UseLibrary
{
local library_directory = [ FDirName $($(3[1])) $(3[2-]) ] ;

if $(JT_Made_$(library_directory)$(2)) = "yes"
{
LinkLibraries $(1) : $(2) ;
}
else
{
LinkLibraries $(1) : $(library_directory)$(SLASH)$(BUILD_VARIANT)$(SLASH)$(2) ;
}
}

# vim:ft=jam

+ 3
- 0
build/msvc7.bat View File

@@ -0,0 +1,3 @@
@"%VS71COMNTOOLS%vsvars32.bat"
@SET VISUALC=%VCINSTALLDIR%\VC7
@SET JAM_TOOLSET=VC7

+ 70
- 0
configure View File

@@ -0,0 +1,70 @@
#!/bin/sh
######################################################################
# Copyright (C) 2001-2004 Peter J Jones (pjones@pmade.org)
# All Rights Reserved
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name of the Author nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
################################################################################

####
# allow override of jam
if [ "x$NETXX_JAM" = "x" ]; then
NETXX_JAM=jam
fi

export NETXX_JAM

####
# check for jam
if $NETXX_JAM -v 2>&1 > /dev/null; then
echo "found jam ..."
else
echo "Sorry, I could not find jam, please install Boost.Jam"
echo "Use the Download link on http://boost.org/"
exit 1
fi

###
# print our neat little banner
cat tools/banner

CONFIGURE_JAM="$PWD/src/config.jam"
(cd tests/build && sh test.sh "$CONFIGURE_JAM")

sh tools/examples.sh
echo

####
# print our little message
cat tools/message

echo
echo "Netxx has been configured and is ready to compile."
echo "You can now use the "\`jam\'" command to build Netxx."
echo

+ 8
- 0
docs/VERSION View File

@@ -0,0 +1,8 @@
0.4.1 2 REL-0_4_1 2004/04/07
0.4.0 2 REL-0_4_0 2004/02/06
0.3.2 1 REL-0_3_2 2003/07/08
0.3.1 1 REL-0_3_1 2003/01/13
0.3.0 1 REL-0_3_0 2002/11/08
0.2 - REL-0_2 2001/10/22
0.1 - REL-0_1 2001/09/07
0.0 - --------- 2001/05/01

+ 1117
- 0
docs/doxygen/doxyfile
File diff suppressed because it is too large
View File


+ 2
- 0
docs/manual/Makefile View File

@@ -0,0 +1,2 @@
PROJECT_NAME=netxx
.include "${HOME}/develop/project-xslt/docbook/docbook.mk"

+ 25
- 0
docs/manual/bugs.xml View File

@@ -0,0 +1,25 @@
<appendix id="bugs"><title>Known Bugs</title>
<para>
The following is a list of bugs that may or may not be fixed. If
you have any questions about what still needs to be done to Netxx,
please take a look at the TODO file.
</para>

<itemizedlist><title>Microsoft Windows</title>
<listitem>
<para>
Of course there is no support for local domain sockets on
Win32. At some point I will add code for doing windows
pipes to simulate local domain sockets.
</para>
</listitem>
</itemizedlist>

<itemizedlist><title>All Platforms</title>
<listitem>
<para>
TLS Support is NOT thread safe. This will be fixed.
</para>
</listitem>
</itemizedlist>
</appendix>

+ 347
- 0
docs/manual/changelog.xml View File

@@ -0,0 +1,347 @@
<appendix id="changelog"><title>Revision History</title>
<!--################################################################-->
<section id="cl-041"><title>Version 0.4.1</title>
<subtitle>April 07, 2004</subtitle>

<itemizedlist>
<listitem>
<para>
Improvements to the build system. Better testing for the correct version/flavor of Jam. On Windows, /MD will
be used instead of /MT for better compatibility.
</para>
</listitem>

<listitem>
<para>
Build system and the <filename>configure</filename> script will now use <constant>NETXX_JAM</constant> when
invoking Jam. Either have Jam in your <constant>PATH</constant> or set <constant>NETXX_JAM</constant> to the
full path to Jam.
</para>
</listitem>

<listitem>
<para>
Added the <constant>OPENSSL_INC</constant> and <constant>OPENSSL_LIB</constant> variables so users can tell
the build system where OpenSSL headers and libraries are, in case they are not in standard directories.
</para>
</listitem>

<listitem>
<para>
Added support for AIX 5.2.
</para>
</listitem>

<listitem>
<para>
Removed some preprocessor magic and abstracted a few types to make porting to other operating systems much
easier.
</para>
</listitem>
</itemizedlist>
</section>
<!--################################################################-->
<section id="cl-040"><title>Version 0.4.0</title>
<subtitle>February 06, 2004</subtitle>

<para>
Version 0.4.0 is another big step forward for Netxx. Unfortunately, this version is not backwards compatible with other
versions of Netxx. On the positive side, Netxx will now be much easier to maintain, especially for multiple platforms.
</para>

<itemizedlist>
<listitem>
<para>
Netxx no longer uses the <filename>configure.pl</filename> Perl script and <command>make</command> combo. We
had lots of complaints about the build system, and we did not like it either. The new build system is based on
Boost.Jam, therefore we traded the Perl dependency for Jam. This is a very good trade off though.
</para>
</listitem>

<listitem>
<para>
Because of the above change, platform specific project files have been removed. They are no longer necessary.
</para>
</listitem>

<listitem>
<para>
All header and source files have been renamed so that they are all lowercase. The names of the classes have
not changed.
</para>
</listitem>

<listitem>
<para>
If your platform supports getaddrinfo, it will be used over gethostbyname. The getaddrinfo function is
preferred over gethostbyname because it is thread-safe. Platforms that have thread-safe versions of
gethostbyname will still use that function (Win32, HP-UX).
</para>
</listitem>

<listitem>
<para>
Fixed a problem that prevented non-blocking connects on Win32 and did not correctly report the status of the
connection on other platforms. Thanks goes to Ken Yee for finding this.
</para>
</listitem>

<listitem>
<para>
Fixed a bug that prevented the proper resolution of service names.
</para>
</listitem>

<listitem>
<para>
The inet_pton and inet_ntop functions were separated into their own source files. They will now only get built
on platforms that do not already have them.
</para>
</listitem>

<listitem>
<para>
Inserting a Netxx::Peer object that represents a Local Domain Socket (Unix Domain Socket) into a IOStream will
now produce "local domain" instead of "AF_LOCAL".
</para>
</listitem>
</itemizedlist>
</section>
<!--################################################################-->
<section id="cl-032"><title>Version 0.3.2</title>
<subtitle>July 08, 2003</subtitle>

<para>
Version 0.3.2 is a bug fix release.
</para>

<itemizedlist>
<listitem>
<para>
Fixed a bug where socket file descriptors could be leaked. Thanks goes to Steve Bannister.
</para>
</listitem>

<listitem>
<para>
Fixed a problem with building Netxx on Cygwin. Thanks goes to Sergio Ballestrero.
</para>
</listitem>

<listitem>
<para>
Updated Perl scripts to work around a bug in the Perl 5.8 regex parser. Thanks goes to Andy Chou.
</para>
</listitem>

<listitem>
<para>
Fixed a problem in the build system where Netxx could not be built on Solaris if you also wanted TLS/SSL
support. Thanks goes to James Sammut.
</para>
</listitem>

<listitem>
<para>
Fixed a major bug in non-blocking connects. Thanks goes to Steve Bannister.
</para>
</listitem>

<listitem>
<para>
Updated the build script for Mac OS X (configure.sh) so that IPv6 won't cause a problem under 10.2.
</para>
</listitem>

<listitem>
<para>
Implemented missing copy constructor, assignment operator and swap functions for Netxx::Stream. Thanks to
Sebastien Bellerive for finding this one.
</para>
</listitem>
</itemizedlist>
</section>
<!--################################################################-->
<section id="cl-031"><title>Version 0.3.1</title>
<subtitle>January 13, 2003</subtitle>

<para>
Version 0.3.1 is a bug fix release.
</para>

<itemizedlist>
<listitem>
<para>
Made some changes to the internal Netxx::ServerBase class that fixed exception safety issues and a double
delete[] call. Thanks to Steve Bannister for finding this.
</para>
</listitem>

<listitem>
<para>
Made a small change to Netxx::Peer to allow Netxx to compile under MacOSX again.
</para>
</listitem>

<listitem>
<para>
Included errno.h on windows to define EAGAIN. Thanks to Charles Kerr for the suggestion.
</para>
</listitem>

<listitem>
<para>
The Netxx API appendix of this manual was removed. It caused the size of the manual to be too large.
</para>
</listitem>
</itemizedlist>
</section>
<!--################################################################-->
<section id="cl-030"><title>Version 0.3.0</title>
<subtitle>November 8th, 2002</subtitle>

<para>
Lots of changes, some bug fixes and some completely rewritten
classes. Most changes were made to make the API even easier to
use.
</para>

<itemizedlist>
<listitem>
<para>
Rewrote Address class. The address class is now independent of its actual use. No more Address::Type.
Auto-detection of IPv4, IPv6 and Local Domain socket addresses. Much easier to use and makes input more
flexible.
</para>
</listitem>

<listitem>
<para>
Added Peer class to replace all the std::pair objects that were being used. Peer also replaces some of the
functionality of the old SockAddr class.
</para>
</listitem>

<listitem>
<para>
Moved some of the classes from the public include directory into the src directory. This means that the
classes are no longer usable outside of Netxx. The classes are: Socket and SockAddr.
</para>
</listitem>

<listitem>
<para>
Added a new Resolve class so that we can change the implementation of host name and service name resolution at
compile time based on the environment.
</para>
</listitem>

<listitem>
<para>
The server classes can now bind to more than one address. This allows you to either bind to all local
addresses or just specific ones.
</para>
</listitem>

<listitem>
<para>
Removed the MutliServer code and replaced with a new Probe class. The new Probe class can return the readable
and writable state of any Netxx socket based object. Updated the multi_server example code to use the new
Probe class.
</para>
</listitem>

<listitem>
<para>
Added Win32 MSVC Workspace files for compiling a Netxx static library under Win32.
</para>
</listitem>

<listitem>
<para>
Added a shell script for building a Netxx static library under MacOS X.
</para>
</listitem>

<listitem>
<para>
Added Netxx::TLS::Certificate class.
</para>
</listitem>

<listitem>
<para>
Added a default passphrase function that actually works!
</para>
</listitem>
</itemizedlist>
</section>
<!--################################################################-->
<section id="cl-020"><title>Version 0.2.0</title>
<subtitle>October 22, 2001</subtitle>

<para>
New features and some bug fixes.
</para>

<itemizedlist>
<listitem>
<para>
Fixed bug in Socket::write that shows up only when
write(2) returns less than the buffer size
</para>
</listitem>

<listitem>
<para>
Fixed bug in call to select when timeout is 0
</para>
</listitem>

<listitem>
<para>
Added TLS classes a la OpenSSL
</para>
</listitem>

<listitem>
<para>
Moved some classes around in order to add TLS classes
</para>
</listitem>

<listitem>
<para>
Added the Netxx::Netbuf class which is a IOStreams streambuf
</para>
</listitem>
<listitem>
<para>
Added initial support for Microsoft Windows
</para>
</listitem>
</itemizedlist>
</section>
<!--################################################################-->
<section id="cl-010"><title>Version 0.1.0</title>
<subtitle>September 7, 2001</subtitle>

<para>
The Netxx code was cleaned up and moved around. The API is now
ready for a first release.
</para>
</section>
<!--################################################################-->
<section id="cl-000"><title>Version 0.0.0</title>
<subtitle>March 1, 2001</subtitle>

<para>
First draft of some code put together as Netxx.
</para>
</section>
<!--################################################################-->
</appendix>
<!--
vim:ft=docbk:tw=130
-->

+ 59
- 0
docs/manual/credits.xml View File

@@ -0,0 +1,59 @@
<appendix id="credits"><title>Credits</title>
<para>
Netxx it brought to you by the following people.
</para>

<itemizedlist>
<!--#########################################################################################-->
<listitem>
<para>
<ulink url="http://pmade.org/r?pj">Peter Jones</ulink>
</para>

<itemizedlist>
<listitem><para>Original designer of Netxx and project maintainer.</para></listitem>
<listitem><para>Ported to the Win32 platform.</para></listitem>
<listitem><para>Ported to the MacOS X platform.</para></listitem>
<listitem><para>Added TLS support via OpenSSL.</para></listitem>
</itemizedlist>
</listitem>
<!--#########################################################################################-->
<listitem>
<para>
Alex Mitrofanov
</para>

<itemizedlist>
<listitem><para>Updated all the TLS code to the new internal API.</para></listitem>
<listitem><para>Completed Netxx::TLS::Stream so that it could act as a server.</para></listitem>
<listitem><para>Fixed a bug in the Netxx::TLS::Stream::read() function.</para></listitem>
<listitem><para>Wrote the tls_* examples.</para></listitem>
<listitem><para>Wrote the http_https_server example</para></listitem>
<listitem><para>Fixed up the new Netxx::Peer code to be more portable.</para></listitem>
<listitem><para>Wrote the Netxx::TLS::Certificate class.</para></listitem>
</itemizedlist>
</listitem>
<!--#########################################################################################-->
<listitem>
<para>
Steve Bannister
</para>

<itemizedlist>
<listitem><para>Found and fixed a bug in the Netxx::Socket class.</para></listitem>
<listitem><para>Found a bug in the Netxx::StreamBase class relating to non-blocking connects.</para></listitem>
</itemizedlist>
</listitem>
<!--#########################################################################################-->
<listitem>
<para>
<ulink url="http://pmade.org/r?if">Isaac Foraker</ulink>
</para>

<itemizedlist>
<listitem><para>Answered stupid Win32 questions.</para></listitem>
</itemizedlist>
</listitem>
<!--#########################################################################################-->
</itemizedlist>
</appendix>

+ 119
- 0
docs/manual/get_started.xml View File

@@ -0,0 +1,119 @@
<chapter id="getstarted"><title>Getting Started with Netxx</title>
<!-- ################################################################### -->
<section id="build"><title>Building Netxx</title>
<para>
The following instructions will show you how to compile Netxx on most platforms.
</para>

<!-- ################################################################### -->
<section id="build-jam"><title>Using Boost.Jam</title>
<para>
The Netxx build system uses Boost.Jam. If you don't already have Boost.Jam installed, you will need to do that
first. The Boost.Jam download site is

<link url="http://sourceforge.net/project/showfiles.php?group_id=7586&amp;package_id=72941">
http://sourceforge.net/project/showfiles.php?group_id=7586&amp;package_id=72941
</link>
</para>

<para>
By default, the Netxx build system will build a debugging version of Netxx. If you want to build a release version
(one with optimizations and no debugging symbols) you can use the <constant>--release</constant> flag to
<command>jam</command>.
</para>

<example><title>Building the Release Variant</title>
<screen>jam --release</screen>
</example>

<para>
Object files, libraries and executables are built into a release variant directory. For debug builds, they are
placed into a directory called <filename>debug</filename>. For release builds, everything will be built into the
<filename>release</filename> directory.
</para>

<para>
If OpenSSL is installed into a non-standard directory, you may need to set the <constant>OPENSSL_INC</constant>
and <constant>OPENSSL_LIB</constant> environment variables so that the Netxx build system knows where they are.
</para>
</section>
<!-- ################################################################### -->
<section id="build-unix"><title>Building on Unix</title>
<para>
To build Netxx from the command line of a Unix-like operating system you use the <filename>configure</filename>
shell script. Running this script will test your environment and create some Jamfiles.
</para>

<para>
After you run the <filename>configure</filename> script, you can run <command>jam</command> to build Netxx.
</para>

<example><title>Building Netxx on AIX</title>
<para>
Here is an example build of Netxx on AIX.
</para>

<screen>env CC=gcc OPENSSL_INC=/usr/local/include OPENSSL_LIB=/usr/local/lib ./configure</screen>
<screen>env CC=gcc OPENSSL_INC=/usr/local/include OPENSSL_LIB=/usr/local/lib jam --release</screen>
</example>
</section>
<!-- ################################################################### -->
<section id="build-win"><title>Building on Windows</title>
<para>
To build Netxx Windows, you first need to set up your environment for jam. If you will be compiling Netxx with
Microsoft Visual Studio .NET, you can use the <filename>build\msvc7.bat</filename> batch file.
</para>

<example><title>Environment Setup for MSVC7</title>
<para>
Open a CMD.EXE window, <command>cd</command> to the Netxx directory, and run the following commands.
</para>

<screen>build\msvc7.bat</screen>
<screen>jam</screen>
</example>

<para>
Once your environment is set up, you can use <command>jam</command> to build Netxx. If you would like TLS support,
you must first build OpenSSL. Then you can tell the Netxx to build in support for TLS.
</para>

<example><title>Building with TLS Support</title>
<para>
For this example, we will assume that you installed the OpenSSL header files in
<filename>c:\openssl\include</filename> and the OpenSSL libraries in <filename>c:\openssl\lib</filename>.
</para>

<screen>build\msvc7.bat</screen>
<screen>jam -sWITH_OPENSSL=yes -sOPENSSL_INC=c:\openssl\include -sOPENSSL_LIB=c:\openssl\lib</screen>

<para>
You can also set these variables in your environment.
</para>

<screen>build\msvc7.bat</screen>
<screen>set WITH_OPENSSL=yes</screen>
<screen>set OPENSSL_INC=c:\openssl\include</screen>
<screen>set OPENSSL_LIB=c:\openssl\lib</screen>
<screen>jam</screen>
</example>
</section>
<!-- ################################################################### -->
</section>
<!-- ################################################################### -->
<section id="learn"><title>Learning the Netxx API</title>
<para>
The fastest way to learn how to use Netxx is to review the included example programs. Netxx comes with many simple and
easy to understand example programs such as an echo client/server and daytime client/server.
</para>

<para>
For complete API reference, you should take a look at the doxygen generated web pages. Even with these resources, the
best place to hang out is in the Netxx header files.
</para>
</section>
<!-- ################################################################### -->
</chapter>
<!--
vim:ft=docbk:tw=130
-->

+ 92
- 0
docs/manual/manual.xml View File

@@ -0,0 +1,92 @@
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
<book id="index" xmlns:xi="http://www.w3.org/2001/XInclude">
<bookinfo>
<title>Netxx Developers Manual</title>

<authorgroup>
<author>
<firstname>Peter</firstname>
<surname>Jones</surname>
<affiliation>
<address>
<email>pjones@pmade.org</email>
</address>
</affiliation>
</author>
</authorgroup>

<copyright>
<year>2002</year>
<year>2003</year>
<year>2004</year>
<holder>Peter Jones (http://pmade.org/pjones/)</holder>
</copyright>

<legalnotice>
<para>
Redistribution and use in source (SGML DocBook) and 'compiled'
forms (SGML, HTML, PDF, PostScript, RTF and so forth) with or
without modification, are permitted provided that the following
conditions are met:
</para>

<orderedlist>
<listitem>
<para>
Redistributions of source code (SGML DocBook) must retain
the above copyright notice, this list of conditions and the
following disclaimer as the first lines of this file
unmodified.
</para>
</listitem>

<listitem>
<para>
Redistributions in compiled form (transformed to other DTDs,
converted to PDF, PostScript, RTF and other formats) must
reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
</para>
</listitem>
</orderedlist>

<important>
<para>
THIS DOCUMENTATION IS PROVIDED BY THE AUTHORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS DOCUMENTATION, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
</para>
</important>
</legalnotice>
<abstract>
<para>
This document describes Netxx to developers who are
going to use the library in their own projects.
</para>

<para>
The latest version of this manual can be found at
<ulink url="http://pmade.org/software/netxx/">http://pmade.org/software/netxx/</ulink>.
</para>
</abstract>
</bookinfo>

<xi:include href="readme.xml"/>
<xi:include href="get_started.xml"/>
<xi:include href="todo.xml"/>
<xi:include href="bugs.xml"/>
<xi:include href="changelog.xml"/>
<xi:include href="credits.xml"/>
</book>

+ 53
- 0
docs/manual/readme.xml View File

@@ -0,0 +1,53 @@
<chapter id="readme"><title>Introduction</title>
<section><title>What is Netxx?</title>
<para>
Netxx is a C++ network programming library. It is designed to take the pain out of programming network communications
applications. It does this by providing an easy to use and cross-platform interface. As a side effect, you get the safety
of automatic resource management and smaller, simpler code.
</para>

<itemizedlist><title>Features</title>
<listitem>
<para>
Very clean API with total abstraction from any operating system calls.
No networking or operating system headers are used in the Netxx header files.
</para>
</listitem>

<listitem>
<para>
Appropriate use of C++ technologies such as namespaces, templates, inheritance and exceptions. All Netxx
classes are in the Netxx namespace and exceptions are used only in exceptional situations.
</para>
</listitem>

<listitem>
<para>
Includes support for TLS/SSL (via OpenSSL), IPv6 and Local/Unix Domain Sockets (on operating systems that support
them).
</para>
</listitem>

<listitem>
<para>
Cross-platform support. Netxx currently supports most flavors of Unix, Windows and MacOS X.
</para>
</listitem>

<listitem>
<para>
An IOStreams streambuf is provided so you can treat network connections just like a std::iostream.
</para>
</listitem>

<listitem>
<para>
Berkeley style license so you can do whatever you want with Netxx, including commercial use.
</para>
</listitem>
</itemizedlist>
</section>
</chapter>
<!--
vim:ft=docbk:tw=130
-->

+ 99
- 0
docs/manual/todo.xml View File

@@ -0,0 +1,99 @@
<appendix><title>Todo List</title>
<itemizedlist><title>Todo Before 1.0.0 Release</title>
<listitem>
<para>
Remove any calls to malloc with calls to new char[]. (Peer.cxx).
</para>
</listitem>

<listitem>
<para>
use SUN_LEN instead of sizeof for AF_LOCAL;
</para>
</listitem>

<listitem>
<para>
Clean up documentation and make more complete.
</para>
</listitem>


<listitem>
<para>
Add Solaris >= 8 /dev/poll support to the Probe class.
</para>
</listitem>

<listitem>
<para>
Add thread callbacks for OpenSSL.
</para>
</listitem>

<listitem>
<para>
Call THREADS_init() if initializing OpenSSL.
</para>
</listitem>

<listitem>
<para>
Add more callbacks to TLS::Context so that developers can
better customize TLS behavior.
</para>
</listitem>

<listitem>
<para>
Verify what WSAETIMEDOUT and WSAEMSGSIZE mean.
</para>
</listitem>

<listitem>
<para>
Optimize Netxx::Netbuf::xsputn().
</para>
</listitem>

<listitem>
<para>
Add support for the FreeBSD kqueue(2) function in
Probe_impl.
</para>
</listitem>

<listitem>
<para>
Should we allow some way to get user credentials from a
local domain socket?
</para>
</listitem>

<listitem>
<para>
TLS::handle_shutdown should be more robust and support
non-blocking sockets.
</para>
</listitem>

<listitem>
<para>
How should we handle file permissions for local domain
sockets? Right now we set them to 0666. There should be some
way for the developer to override this. Maybe using a fake
port, e.g., /some/file:0600?
</para>
</listitem>

<listitem>
<para>
Add another callback to the Context class so that we can
verify certs.
</para>
</listitem>
</itemizedlist>
</appendix>
<!--
vim:ft=docbk
-->

+ 3
- 0
examples/.cvsignore View File

@@ -0,0 +1,3 @@
debug
release
config.jam

+ 56
- 0
examples/Jamfile View File

@@ -0,0 +1,56 @@
####
# standard Jamfile stuff
####
TOP ?= $(DOTDOT) ;
SubDir TOP "examples" ;
SubDirHdrs $(TOP)$(SLASH)"include" ;
JT_UseVariant ;

####
# suck in the configure generate file
####
if $(UNIX)
{
include $(TOP)$(SLASH)"examples"$(SLASH)"config.jam" ;
}

####
# suck in a file for Win32
####
if $(NT)
{
include $(TOP)$(SLASH)"examples"$(SLASH)"win32.jam" ;
}

####
# Helper rule for building examples
####
rule Build_Example
{
local image = $(1:S=) ;
Main $(image) : $(1) ;
JT_UseLibrary $(image) : libnetxx : TOP "src" ;
}

Build_Example http_get.cxx ;
Build_Example multi_server.cxx ;
Build_Example streambuf_echo_client.cxx ;
Build_Example tcp_daytime_client.cxx ;
Build_Example tcp_echo_client.cxx ;
Build_Example tcp_echo_server.cxx ;
Build_Example udp_daytime_client.cxx ;
Build_Example udp_echo_client.cxx ;
Build_Example udp_echo_server.cxx ;

####
# stuff that can only be built with OpenSSL
####
if $(HAVE_OPENSSL) = "yes"
{
Build_Example http_https_server.cxx ;
Build_Example https_get.cxx ;
Build_Example tls_echo_client.cxx ;
Build_Example tls_echo_server.cxx ;
}

# vim:ft=jam

+ 13
- 0
examples/README View File

@@ -0,0 +1,13 @@
Netxx Examples

Any of the examples in this directory that take address options can use the
URL syntax for an address. For example, to run the tcp_echo_server on port
7000:

./tcp_echo_server localhost:7000

Or, to make it use a local domain socket:

./tcp_echo_server /tmp/echo.socket

Have fun!

+ 3
- 0
examples/config.jam View File

@@ -0,0 +1,3 @@
# Created on: Mon Apr 26 12:52:05 MDT 2004
LINKLIBS += "-lssl -lcrypto" ;
HAVE_OPENSSL = "yes" ;

+ 93
- 0
examples/http_get.cxx View File

@@ -0,0 +1,93 @@
/*
* Copyright (C) 2001-2004 Peter J Jones (pjones@pmade.org)
* All Rights Reserved
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of the Author nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

/*
* This is a simple example of how you can use the Netxx::Address class and
* the Netxx::Stream class to do make a HTTP GET request to a web server.
*/

// Netxx Includes
#include <netxx/netxx.h>

// Standard Includes
#include <iostream>
#include <exception>

int main (int argc, char *argv[]) {
if (argc != 2 && argc != 3) {
std::cout << "Usage: " << argv[0] << " URI [Host: header]\n";
return 0;
}

try {
Netxx::Address addr(argv[1], 80);
Netxx::Stream client(addr, Netxx::Timeout(10));

std::string request("GET ");

if (addr.get_path()) {
request += addr.get_path();
} else {
request += "/";
}

// setup the request line and headers
request += " HTTP/1.0";
request += 13; request += 10;

// send the Host header
request += "Host: ";
if (argc == 3) request += argv[2];
else request += addr.get_name();
request += 13; request += 10;

request += "Connection: close";
request += 13; request += 10;
request += 13; request += 10;

// send the request
client.write(request.c_str(), request.size());

char buffer[1024];
Netxx::signed_size_type length;

// read back the result
while ( (length = client.read(buffer, sizeof(buffer))) > 0)
std::cout.write(buffer, length);

} catch (std::exception &e) {
std::cerr << e.what() << std::endl;
return 1;
}

return 0;
}

+ 173
- 0
examples/http_https_server.cxx View File

@@ -0,0 +1,173 @@
/*
* Copyright (C) 2001-2004 Peter J Jones (pjones@pmade.org)
* All Rights Reserved
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of the Author nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

/*
* This is a very simple web server using a lot of different classes from
* Netxx. It will accept incoming HTTP and HTTPS requests. This example is a
* little big, but is does do some basic HTTP/1.0 web server stuff!
*
* Remember, this is just an example! This web server does not have any
* security checking. In fact, using some ../../ directory references,
* someone could get your password file!
*/

// Netxx Includes
#include <netxx/tls/netxx.h>

// standard includes
#include <iostream>
#include <fstream>
#include <exception>
#include <memory>

int main (int argc, char *argv[]) {
std::string document_root;

if (argc < 2) document_root = "../src";
else document_root = argv[1];

if (document_root[document_root.size()-1] != '/')
document_root += '/';

try {
Netxx::TLS::Context context;
context.load_private_key("example.pem");
context.load_cert_chain("example.pem");

// bind to all addresses for the following ports
Netxx::Address address;
address.add_all_addresses(8080);
address.add_all_addresses(8443);

Netxx::Timeout accept_timeout(600);
Netxx::Timeout read_timeout(60);

Netxx::StreamServer server(address, accept_timeout);

std::cout << "waiting for HTTP requests on port 8080\n";
std::cout << "waiting for HTTPS requests on port 8443\n";

for (;;) {
Netxx::Peer client = server.accept_connection();

if (!client) {
std::cout << argv[0] << ": timeout waiting for connection";
std::cout << std::endl;
continue;
}

std::cout << argv[0] << ": connection from " << client;
std::cout << std::endl;

std::auto_ptr<Netxx::StreamBase> client_stream;

if (client.get_local_port() == 8080) {

client_stream.reset(new Netxx::Stream(
client.get_socketfd(), read_timeout));
} else {

client_stream.reset(new Netxx::TLS::Stream(
context, client.get_socketfd(),
Netxx::TLS::Stream::mode_server, read_timeout));
}

Netxx::Netbuf<1024> sbuf(*client_stream);
std::iostream stream(&sbuf);

std::string token;
stream >> token;

if (token != "GET") continue;

stream >> token;
std::cout << argv[0] << ": " << token << std::endl;

if (token == "/") {
std::string message = "<html><body><h1>"
"Hello from Netxx</h1></body></html>\n";

stream << "HTTP/1.0 200 OK\r\n";
stream << "Content-Type: text/html\r\n";
stream << "Content-Length: " << message.size() << "\r\n";
stream << "Connection: closed\r\n\r\n";
stream << message << std::flush;
continue;
}

std::string document = document_root + token;
std::ifstream file(document.c_str());

if (!file) {
stream << "HTTP/1.0 404 Not found\r\n";
stream << "Content-Type: text/html\r\n";
stream << "Connection: closed\r\n\r\n";
stream << "<html><body><h1>Not Found</h1></body></html>\n";
stream << std::flush;
continue;
}

stream << "HTTP/1.0 200 OK\r\n";
std::string::size_type dotpos = token.rfind(".");

if (dotpos != std::string::npos) {
std::string ext = token.substr(dotpos+1);

if (ext == "html" || ext == "htm") {
stream << "Content-Type: text/html\r\n";
} else if (ext == "jpeg" || ext == "jpg") {
stream << "Content-Type: image/jpeg\r\n";
} else if (ext == "gif") {
stream << "Content-Type: image/gif\r\n";
} else if (ext == "png") {
stream << "Content-Type: image/png\r\n";
} else {
stream << "Content-Type: text/plain\r\n";
}
} else {
stream << "Content-Type: text/plain\r\n";
}

stream << "Connection: closed\r\n\r\n";
stream << std::flush;

char buffer[4096];
while (file.read(buffer, sizeof(buffer)) || file.gcount())
stream.write(buffer, file.gcount());
}
} catch (std::exception &e) {
std::cerr << argv[0] << ": " << e.what() << std::endl;
return 1;
}

return 0;
}

+ 108
- 0
examples/https_get.cxx View File

@@ -0,0 +1,108 @@
/*
* Copyright (C) 2001-2004 Peter J Jones (pjones@pmade.org)
* All Rights Reserved
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of the Author nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

/*
* This example shows you how to make a TLS request and examin the the
* server's certificate.
*/

// Netxx Includes
#include <netxx/tls/netxx.h>

// Standard Includes
#include <iostream>
#include <exception>

int main (int argc, char *argv[]) {
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " URI\n";
return 0;
}

try {
Netxx::TLS::Context context;
Netxx::Address addr(argv[1], 443);
Netxx::TLS::Stream client(context, addr, Netxx::Timeout(10));

const Netxx::TLS::Certificate &peer_cert = client.get_peer_cert();
const Netxx::TLS::Certificate &issuer_cert = client.get_issuer_cert();

if (peer_cert) {
std::cout << "Peer Certificate:\n";
std::cout << " C: " << peer_cert.get_country() << "\n";
std::cout << " ST: " << peer_cert.get_region() << "\n";
std::cout << " O: " << peer_cert.get_organization() << "\n";
std::cout << " OU: " << peer_cert.get_organization_unit() << "\n";
std::cout << " CN: " << peer_cert.get_fqdn() << "\n\n";
} else {
std::cout << "Missing Peer Certificate\n\n";
}

if (issuer_cert) {
std::cout << "Issuer Certificate:\n";
std::cout << " C: " << issuer_cert.get_country() << "\n";
std::cout << " ST: " << issuer_cert.get_region() << "\n";
std::cout << " O: " << issuer_cert.get_organization() << "\n";
std::cout << " OU: " << issuer_cert.get_organization_unit() << "\n";
std::cout << " CN: " << issuer_cert.get_fqdn() << "\n\n";
} else {
std::cout << "Missing Issuer Certificate\n\n";
}

std::string request("GET ");
if (addr.get_path()) {
request += addr.get_path();
} else {
request += "/";
}

request += " HTTP/1.0\r\n";
request += "Host: ";
request += addr.get_name();
request += "\r\n";
request += "Connection: close\r\n\r\n";

client.write(request.c_str(), request.size());

char buffer[1024];
Netxx::signed_size_type length;

while ( (length = client.read(buffer, sizeof(buffer))) > 0)
std::cout.write(buffer, length);

} catch (std::exception &e) {
std::cerr << argv[0] << ": " << e.what() << std::endl;
return 1;
}

return 0;
}

+ 183
- 0
examples/multi_server.cxx View File

@@ -0,0 +1,183 @@
/*
* Copyright (C) 2001-2004 Peter J Jones (pjones@pmade.org)
* All Rights Reserved
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of the Author nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

/*
* This example shows you how to use the Netxx::Probe class. In this case,
* we have a group of server classes and we use the Probe to know when we
* can accept a connection on one of the servers.
*/

// Netxx Includes
#include <netxx/netxx.h>

// Standard Includes
#include <iostream>
#include <exception>
#include <ctime>

namespace {
const Netxx::port_type const_port_echo = 4000;
const Netxx::port_type const_port_daytime = 4001;
const Netxx::size_type const_buffer_size = 4096;
}

int main (int argc, char *argv[]) {
if (argc > 1) {
std::cerr << argv[0] << ": this program does not take any options\n";
return 1;
}

try {
Netxx::Timeout timeout(5);
Netxx::Probe probe;

Netxx::StreamServer tcp_echo_server(const_port_echo, timeout);
Netxx::DatagramServer udp_echo_server(const_port_echo, timeout);
Netxx::StreamServer tcp_daytime_server(const_port_daytime, timeout);
Netxx::DatagramServer udp_daytime_server(const_port_daytime, timeout);

std::cout << argv[0] << ": tcp echo server listening on port ";
std::cout << const_port_echo << std::endl;

std::cout << argv[0] << ": udp echo server listening on port ";
std::cout << const_port_echo << std::endl;

std::cout << argv[0] << ": tcp daytime server listening on port ";
std::cout << const_port_daytime << std::endl;

std::cout << argv[0] << ": udp daytime server listening on port ";
std::cout << const_port_daytime << std::endl;


/*
* add servers to the Probe for readable testing since we only care
* when the sockets are readable not writable.
*/
probe.add(tcp_echo_server, Netxx::Probe::ready_read);
probe.add(udp_echo_server, Netxx::Probe::ready_read);
probe.add(tcp_daytime_server, Netxx::Probe::ready_read);
probe.add(udp_daytime_server, Netxx::Probe::ready_read);

char buffer[const_buffer_size];
Netxx::Probe::result_type rt;

for (;;) {
rt = probe.ready(timeout);

if (rt.first == -1 || !(rt.second & Netxx::Probe::ready_read)) {
std::cout << argv[0] << ": timeout waiting for connection" << std::endl;
continue;
}

std::cout << argv[0] << ": one of the servers is ready, testing ..." << std::endl;

if (rt.first == tcp_echo_server)
{
Netxx::Peer peer = tcp_echo_server.accept_connection();

if (!peer) {
std::cout << argv[0] << ": timeout in accept" << std::endl;
continue;
}

std::cout << argv[0] << ": incoming TCP-ECHO connection from: " << peer << std::endl;

Netxx::Stream client(peer.get_socketfd(), timeout);
Netxx::signed_size_type bytes_read;

while ( (bytes_read = client.read(buffer, sizeof(buffer))) > 0)
client.write(buffer, bytes_read);

std::cout << argv[0] << ": connection with " << peer << " closed" << std::endl;
}
else if (rt.first == udp_echo_server)
{
Netxx::DatagramServer::receive_type info =
udp_echo_server.receive(buffer, sizeof(buffer));

if (!info.second) {
std::cout << argv[0] << ": timeout waiting for datagram";
std::cout << std::endl;
continue;
}

std::cout << argv[0] << ": incoming UDP-ECHO datagram from ";
std::cout << info.second << std::endl;

udp_echo_server.send(info.second, buffer, info.first);
std::cout << argv[0] << ": sent datagram to " << info.second << std::endl;
}
else if (rt.first == tcp_daytime_server)
{
Netxx::Peer peer = tcp_daytime_server.accept_connection();

if (!peer) {
std::cout << argv[0] << ": timeout in accept" << std::endl;
continue;
}

std::cout << argv[0] << ": incoming TCP-DAYTIME connection from: " << peer << std::endl;

Netxx::Stream client(peer.get_socketfd(), timeout);
std::time_t now = std::time(0);
char *time_str = std::ctime(&now);
client.write(time_str, std::strlen(time_str));

std::cout << argv[0] << ": connection with " << peer << " closed" << std::endl;
}
else if (rt.first == udp_daytime_server)
{
Netxx::DatagramServer::receive_type info =
udp_daytime_server.receive(buffer, sizeof(buffer));

if (!info.second) {
std::cout << argv[0] << ": timeout waiting for datagram";
std::cout << std::endl;
continue;
}

std::cout << argv[0] << ": incoming UDP-DAYTIME datagram from ";
std::cout << info.second << std::endl;

std::time_t now = std::time(0);
char *time_str = std::ctime(&now);
udp_daytime_server.send(info.second, time_str, std::strlen(time_str));
std::cout << argv[0] << ": sent datagram to " << info.second << std::endl;
}
}
} catch (std::exception &e) {
std::cerr << argv[0] << ": " << e.what() << std::endl;
return 1;
}

return 0;
}

+ 76
- 0
examples/streambuf_echo_client.cxx View File

@@ -0,0 +1,76 @@
/*
* Copyright (C) 2001-2004 Peter J Jones (pjones@pmade.org)
* All Rights Reserved
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of the Author nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

/*
* This example shows you how you can use the Netxx::Netbuf template class
* as a IOStreams streambuf. Doing so allows you to treat a TCP connection
* as an IOStream.
*/

// Netxx Includes
#include <netxx/netxx.h>

// Standard Includes
#include <string>
#include <iostream>
#include <exception>

int main (int argc, char *argv[]) {
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " <address>\n";
return 1;
}

try {
Netxx::Stream client(argv[1], 7, Netxx::Timeout(2));
Netxx::Netbuf<1024> sbuf(client);
std::iostream stream(&sbuf);
std::string string_buffer;

while (std::getline(std::cin, string_buffer)) {
stream << string_buffer << std::endl;

if (std::getline(stream, string_buffer)) {
std::cout << string_buffer << std::endl;
} else {
std::cerr << argv[0] << " error reading from server";
std::cerr << std::endl;
return 1;
}
}
} catch (std::exception &e) {
std::cerr << e.what() << std::endl;
return 1;
}

return 0;
}

+ 64
- 0
examples/tcp_daytime_client.cxx View File

@@ -0,0 +1,64 @@
/*
* Copyright (C) 2001-2004 Peter J Jones (pjones@pmade.org)
* All Rights Reserved
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of the Author nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

/*
* This example shows you how to use the Netxx::Stream class to establish a
* connection to a daytime server and get the current time. This is a nice
* and short example that shows how easy it can be to use Netxx.
*/

// Netxx Includes
#include <netxx/netxx.h>

// Standard Includes
#include <iostream>
#include <exception>

int main (int argc, char *argv[]) {
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " <address>\n";
return 1;
}

try {
Netxx::Stream client(argv[1], 13, Netxx::Timeout(2));
char buffer[1024];

buffer[ client.read(buffer, sizeof(buffer) - 1) ] = 0;
std::cout << buffer;
} catch (std::exception &e) {
std::cerr << argv[0] << ": " << e.what() << std::endl;
return 1;
}

return 0;
}

+ 82
- 0
examples/tcp_echo_client.cxx View File

@@ -0,0 +1,82 @@
/*
* Copyright (C) 2001-2004 Peter J Jones (pjones@pmade.org)
* All Rights Reserved
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of the Author nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

/*
* This is another example that shows how easy the Netxx API is. This
* program will connect to a TCP echo server which will echo everything
* going into this program's standard input back to it.
*/

// Netxx Includes
#include <netxx/netxx.h>

// Standard Includes
#include <string>
#include <iostream>
#include <exception>

int main (int argc, char *argv[]) {
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " <address:port>\n";
return 1;
}

try {
Netxx::Stream client(argv[1], 7);
Netxx::signed_size_type byte_count;
char read_buffer[4096];
std::string write_buffer;

while (std::getline(std::cin, write_buffer)) {
if (write_buffer.size() > sizeof(read_buffer)) {
std::cerr << "can't send a line longer than ";
std::cerr << sizeof(read_buffer) << " bytes\n";
return 1;
}

write_buffer += '\n';

if ( (byte_count = client.write(write_buffer.c_str(), write_buffer.size())) <= 0)
throw std::runtime_error("write: peer closed connection");

if ( (byte_count = client.read(read_buffer, sizeof(read_buffer))) <= 0)
throw std::runtime_error("read: peer closed connection");

std::cout.write(read_buffer, byte_count);
}
} catch (std::exception &e) {
std::cerr << argv[0] << ": " << e.what() << std::endl;
return 1;
}

return 0;
}

+ 83
- 0
examples/tcp_echo_server.cxx View File

@@ -0,0 +1,83 @@
/*
* Copyright (C) 2001-2004 Peter J Jones (pjones@pmade.org)
* All Rights Reserved
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of the Author nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

/*
* This example shows how to write a simple TCP server. It will echo back
* everything that it is sent from a connected client.
*/

// Netxx Includes
#include <netxx/netxx.h>

// Standard Includes
#include <iostream>
#include <exception>

int main (int argc, char *argv[]) {
try {
Netxx::Address address;
Netxx::Timeout timeout(10);

if (argc > 1) {
for (int i=1; i<argc; ++i) address.add_address(argv[i], 7);