Netxx-0.3.2/0000755000175000017500000000000012173720372012100 5ustar danieldanielNetxx-0.3.2/docs/0000755000175000017500000000000012173720372013030 5ustar danieldanielNetxx-0.3.2/docs/project/0000755000175000017500000000000012173720372014476 5ustar danieldanielNetxx-0.3.2/docs/project/resources.xml0000644000175000017500000001345712173720353017243 0ustar danieldaniel
Very quiet, mostly release announcements. [archive] Questions, comments, stories? This is the place. [archive]
Online HTML version of the Developers Manual Online HTML version of the Developers Manual (everything in one file) PDF version of the Developers Manual Doxygen generated API documentation Tarball with doxygen generated API documentation
Shows how simple the Netxx::Address and Netxx::Stream classes are to use A very simple example of the Netxx::Stream class Example TCP (Stream) server Shows how to use the Netxx::Datagram class to send datagrams Example UDP (Datagram) server Shows the use of the Netxx::TLS::Stream and Netxx::TLS::Certificate classes TCP echo client using IOStreams TLS client example TLS server example Another Netxx::Stream example code Another Netxx::Datagram example Multi-protocol server that listens on TCP and UDP ports Shows off almost all of the Netxx classes
A very large and complex, do everything library Another do everything library that glosses over network programming Framework to manage TCP, TCPSSL and UDP connections Huge networking library that implements strange things like string processing A small class library for C++ that supports an easy usage of socket-programming A thin wrapper for socket and thread support (pre-standard C++ coding style) A simple alternative to the STL that includes multi-threading and networking An iostream based C++ socket library A C++ class library that provides you with an iostream based interface to sockets
Netxx-0.3.2/docs/project/download.xml0000644000175000017500000000745512173720353017041 0ustar danieldaniel Perl (at least version 5.5) to run configure.pl OpenSSL >= 0.9.6e if you want TLS support A C++ compiler The Netxx::Netbuf is not supported with this compiler, you must use the --disable-streambuf option to the configure.pl script to turn it off. The Netxx::Netbuf is not supported with this compiler, you must use the --disable-streambuf option to the configure.pl script to turn it off. The Netxx::Netbuf is not supported with this compiler, you must use the --disable-streambuf option to the configure.pl script to turn it off. Name resolution causes errors. Anyone want to help? Name resolution causes errors. Anyone want to help? The Netxx::Netbuf is not supported with this compiler, you must use the --disable-streambuf option to the configure.pl script to turn it off. Better yet, use the build/macosx/configure.sh script to configure Netxx. This is a beta version of what became GCC 3.1. It contains bugs, including problems with exceptions. When you throw an exception the code will continue right after the throw statment. The Netxx::Netbuf is not supported with this compiler, you must use the --disable-streambuf option to the configure.pl script to turn it off. Better yet, use the build/macosx/configure.sh script to configure Netxx. Netxx-0.3.2/docs/project/news.xml0000644000175000017500000000605112173720353016175 0ustar danieldaniel Thanks to the work of volunteers, Netxx version 0.3.2 has been released. This version fixed a few major and minor bugs. Netxx now has a project page on SourceForge.net. Please take some time to review the site and volunteer to fix some bugs. Version 0.3.1 is a bug fix release. A few exception safety issues have been fixed, plus some changes for the MacOSX and Win32 ports. With a little over a year of work, Netxx 0.3.0 has been released! This version has a lot of changes, some external, but a lot of internal work. Plus TLS support is almost complete! The API is much better now, and the code is very solid. We wanted to make this release so that everyone could become familiar with the new API. As part of my portfolio I have created a new logo for Netxx. Also note that version 0.3.0 is in the works and it's going to be very cool! Netxx version 0.2 is out. This is still an alpha release of course. I wanted to get all the new changes out although some of them are not ready, like TLS on windows. Expect changes in a few classes, I am going to make the library a little easier to use. A bug was found in the code that calls select. It did not pass select a NULL pointer for a 0 timeout. This is fixed in CVS. The fix will also be in the upcoming 0.2 version. The Netxx port to Windows is almost complete. As soon as the build system is more complete, Netxx 0.2 will be released. Netxx now supports TLS via OpenSSL and some wrapper classes. Official Netxx TLS Release coming soon. An early alpha version of Netxx was released. This is so that developers can start to review the API and provide feedback. This is still an alpha release that the API is subject to change. With that said, it is very stable. Netxx-0.3.2/docs/project/project.xml0000644000175000017500000000412412173720353016666 0ustar danieldaniel 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. Very clean API with total abstraction from any operating system calls. No networking or operating system headers are used in the Netxx header files. 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. Includes support for TLS/SSL (via OpenSSL), IPv6 and Local/Unix Domain Sockets (on operating systems that support them). Cross-platform support. Netxx currently supports most flavors of Unix, Windows and MacOS X. An IOStreams streambuf is provided so you can treat network connections just like a std::iostream. Berkeley style license so you can do whatever you want with Netxx, including commercial use.
Netxx-0.3.2/docs/project/Makefile0000644000175000017500000000011212173720353016127 0ustar danieldanielPROJECT_NAME=netxx .include "${HOME}/develop/project-xslt/etc/project.mk" Netxx-0.3.2/docs/CREDITS0000644000175000017500000000176512173720353014060 0ustar danieldanielCredits Netxx it brought to you by the following people. * Peter Jones + Original designer of Netxx and project maintainer. + Ported to the Win32 platform. + Ported to the MacOS X platform. + Added TLS support via OpenSSL. * Alex Mitrofanov + Updated all the TLS code to the new internal API. + Completed Netxx::TLS::Stream so that it could act as a server. + Fixed a bug in the Netxx::TLS::Stream::read() function. + Wrote the tls_* examples. + Wrote the http_https_server example + Fixed up the new Netxx::Peer code to be more portable. + Wrote the Netxx::TLS::Certificate class. * Steve Bannister + Found and fixed a bug in the Netxx::Socket class. + Found a bug in the Netxx::StreamBase class relating to non-blocking connects. * Isaac Foraker + Answered stupid Win32 questions. Netxx-0.3.2/docs/doxygen/0000755000175000017500000000000012173720372014505 5ustar danieldanielNetxx-0.3.2/docs/doxygen/doxyfile0000644000175000017500000007756512173720353016276 0ustar danieldaniel# Doxyfile 1.2.10 # This file describes the settings to be used by the documentation system # doxygen (www.doxygen.org) for a project # # All text after a hash (#) is considered a comment and will be ignored # The format is: # TAG = value [value, ...] # For lists items can also be appended using: # TAG += value [value, ...] # Values that contain spaces should be placed between quotes (" ") #--------------------------------------------------------------------------- # General configuration options #--------------------------------------------------------------------------- # The PROJECT_NAME tag is a single word (or a sequence of words surrounded # by quotes) that should identify the project. PROJECT_NAME = Netxx # The PROJECT_NUMBER tag can be used to enter a project or revision number. # This could be handy for archiving the generated documentation or # if some version control system is used. PROJECT_NUMBER = HEAD # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # base path where the generated documentation will be put. # If a relative path is entered, it will be relative to the location # where doxygen was started. If left blank the current directory will be used. OUTPUT_DIRECTORY = # The OUTPUT_LANGUAGE tag is used to specify the language in which all # documentation generated by doxygen is written. Doxygen will use this # information to generate all constant output in the proper language. # The default language is English, other supported languages are: # Brazilian, Chinese, Croatian, Czech, Danish, Dutch, Finnish, French, # German, Hungarian, Italian, Japanese, Korean, Norwegian, Polish, # Portuguese, Romanian, Russian, Slovak, Slovene, Spanish and Swedish. OUTPUT_LANGUAGE = English # If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in # documentation are documented, even if no documentation was available. # Private class members and static file members will be hidden unless # the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES EXTRACT_ALL = NO # If the EXTRACT_PRIVATE tag is set to YES all private members of a class # will be included in the documentation. EXTRACT_PRIVATE = NO # If the EXTRACT_STATIC tag is set to YES all static members of a file # will be included in the documentation. EXTRACT_STATIC = NO # If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all # undocumented members of documented classes, files or namespaces. # If set to NO (the default) these members will be included in the # various overviews, but no documentation section is generated. # This option has no effect if EXTRACT_ALL is enabled. HIDE_UNDOC_MEMBERS = YES # If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all # undocumented classes that are normally visible in the class hierarchy. # If set to NO (the default) these class will be included in the various # overviews. This option has no effect if EXTRACT_ALL is enabled. HIDE_UNDOC_CLASSES = YES # If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will # include brief member descriptions after the members that are listed in # the file and class documentation (similar to JavaDoc). # Set to NO to disable this. BRIEF_MEMBER_DESC = YES # If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend # the brief description of a member or function before the detailed description. # Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the # brief descriptions will be completely suppressed. REPEAT_BRIEF = YES # If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then # Doxygen will generate a detailed section even if there is only a brief # description. ALWAYS_DETAILED_SEC = YES # If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full # path before files name in the file list and in the header files. If set # to NO the shortest path that makes the file name unique will be used. FULL_PATH_NAMES = NO # If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag # can be used to strip a user defined part of the path. Stripping is # only done if one of the specified strings matches the left-hand part of # the path. It is allowed to use relative paths in the argument list. STRIP_FROM_PATH = # The INTERNAL_DOCS tag determines if documentation # that is typed after a \internal command is included. If the tag is set # to NO (the default) then the documentation will be excluded. # Set it to YES to include the internal documentation. INTERNAL_DOCS = NO # If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will # generate a class diagram (in Html and LaTeX) for classes with base or # super classes. Setting the tag to NO turns the diagrams off. CLASS_DIAGRAMS = YES # If the SOURCE_BROWSER tag is set to YES then a list of source files will # be generated. Documented entities will be cross-referenced with these sources. SOURCE_BROWSER = YES # Setting the INLINE_SOURCES tag to YES will include the body # of functions and classes directly in the documentation. INLINE_SOURCES = NO # Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct # doxygen to hide any special comment blocks from generated source code # fragments. Normal C and C++ comments will always remain visible. STRIP_CODE_COMMENTS = NO # If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate # file names in lower case letters. If set to YES upper case letters are also # allowed. This is useful if you have classes or files whose names only differ # in case and if your file system supports case sensitive file names. Windows # users are adviced to set this option to NO. CASE_SENSE_NAMES = YES # If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter # (but less readable) file names. This can be useful is your file systems # doesn't support long names like on DOS, Mac, or CD-ROM. SHORT_NAMES = NO # If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen # will show members with their full class and namespace scopes in the # documentation. If set to YES the scope will be hidden. HIDE_SCOPE_NAMES = NO # If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen # will generate a verbatim copy of the header file for each class for # which an include is specified. Set to NO to disable this. VERBATIM_HEADERS = YES # If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen # will put list of the files that are included by a file in the documentation # of that file. SHOW_INCLUDE_FILES = YES # If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen # will interpret the first line (until the first dot) of a JavaDoc-style # comment as the brief description. If set to NO, the JavaDoc # comments will behave just like the Qt-style comments (thus requiring an # explict @brief command for a brief description. JAVADOC_AUTOBRIEF = YES # If the INHERIT_DOCS tag is set to YES (the default) then an undocumented # member inherits the documentation from any documented member that it # reimplements. INHERIT_DOCS = YES # If the INLINE_INFO tag is set to YES (the default) then a tag [inline] # is inserted in the documentation for inline members. INLINE_INFO = YES # If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen # will sort the (detailed) documentation of file and class members # alphabetically by member name. If set to NO the members will appear in # declaration order. SORT_MEMBER_DOCS = YES # If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC # tag is set to YES, then doxygen will reuse the documentation of the first # member in the group (if any) for the other members of the group. By default # all members of a group must be documented explicitly. DISTRIBUTE_GROUP_DOC = NO # The TAB_SIZE tag can be used to set the number of spaces in a tab. # Doxygen uses this value to replace tabs by spaces in code fragments. TAB_SIZE = 8 # The GENERATE_TODOLIST tag can be used to enable (YES) or # disable (NO) the todo list. This list is created by putting \todo # commands in the documentation. GENERATE_TODOLIST = NO # The GENERATE_TESTLIST tag can be used to enable (YES) or # disable (NO) the test list. This list is created by putting \test # commands in the documentation. GENERATE_TESTLIST = NO # The GENERATE_BUGLIST tag can be used to enable (YES) or # disable (NO) the bug list. This list is created by putting \bug # commands in the documentation. GENERATE_BUGLIST = NO # This tag can be used to specify a number of aliases that acts # as commands in the documentation. An alias has the form "name=value". # For example adding "sideeffect=\par Side Effects:\n" will allow you to # put the command \sideeffect (or @sideeffect) in the documentation, which # will result in a user defined paragraph with heading "Side Effects:". # You can put \n's in the value part of an alias to insert newlines. ALIASES = # The ENABLED_SECTIONS tag can be used to enable conditional # documentation sections, marked by \if sectionname ... \endif. ENABLED_SECTIONS = # The MAX_INITIALIZER_LINES tag determines the maximum number of lines # the initial value of a variable or define consist of for it to appear in # the documentation. If the initializer consists of more lines than specified # here it will be hidden. Use a value of 0 to hide initializers completely. # The appearance of the initializer of individual variables and defines in the # documentation can be controlled using \showinitializer or \hideinitializer # command in the documentation regardless of this setting. MAX_INITIALIZER_LINES = 30 # Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources # only. Doxygen will then generate output that is more tailored for C. # For instance some of the names that are used will be different. The list # of all members will be omitted, etc. OPTIMIZE_OUTPUT_FOR_C = NO # Set the SHOW_USED_FILES tag to NO to disable the list of files generated # at the bottom of the documentation of classes and structs. If set to YES the # list will mention the files that were used to generate the documentation. SHOW_USED_FILES = YES #--------------------------------------------------------------------------- # configuration options related to warning and progress messages #--------------------------------------------------------------------------- # The QUIET tag can be used to turn on/off the messages that are generated # by doxygen. Possible values are YES and NO. If left blank NO is used. QUIET = YES # The WARNINGS tag can be used to turn on/off the warning messages that are # generated by doxygen. Possible values are YES and NO. If left blank # NO is used. WARNINGS = YES # If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings # for undocumented members. If EXTRACT_ALL is set to YES then this flag will # automatically be disabled. WARN_IF_UNDOCUMENTED = YES # The WARN_FORMAT tag determines the format of the warning messages that # doxygen can produce. The string should contain the $file, $line, and $text # tags, which will be replaced by the file and line number from which the # warning originated and the warning text. WARN_FORMAT = # The WARN_LOGFILE tag can be used to specify a file to which warning # and error messages should be written. If left blank the output is written # to stderr. WARN_LOGFILE = #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- # The INPUT tag can be used to specify the files and/or directories that contain # documented source files. You may enter file names like "myfile.cpp" or # directories like "/usr/src/myproject". Separate the files or directories # with spaces. INPUT = ../../include/ # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp # and *.h) to filter out the source-files in the directories. If left # blank all files are included. FILE_PATTERNS = *.h # The RECURSIVE tag can be used to turn specify whether or not subdirectories # should be searched for input files as well. Possible values are YES and NO. # If left blank NO is used. RECURSIVE = YES # The EXCLUDE tag can be used to specify files and/or directories that should # excluded from the INPUT source files. This way you can easily exclude a # subdirectory from a directory tree whose root is specified with the INPUT tag. EXCLUDE = # If the value of the INPUT tag contains directories, you can use the # EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude # certain files from those directories. EXCLUDE_PATTERNS = # The EXAMPLE_PATH tag can be used to specify one or more files or # directories that contain example code fragments that are included (see # the \include command). EXAMPLE_PATH = # If the value of the EXAMPLE_PATH tag contains directories, you can use the # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp # and *.h) to filter out the source-files in the directories. If left # blank all files are included. EXAMPLE_PATTERNS = # The IMAGE_PATH tag can be used to specify one or more files or # directories that contain image that are included in the documentation (see # the \image command). IMAGE_PATH = # The INPUT_FILTER tag can be used to specify a program that doxygen should # invoke to filter for each input file. Doxygen will invoke the filter program # by executing (via popen()) the command , where # is the value of the INPUT_FILTER tag, and is the name of an # input file. Doxygen will then use the output that the filter program writes # to standard output. INPUT_FILTER = # If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using # INPUT_FILTER) will be used to filter the input files when producing source # files to browse. FILTER_SOURCE_FILES = NO #--------------------------------------------------------------------------- # configuration options related to the alphabetical class index #--------------------------------------------------------------------------- # If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index # of all compounds will be generated. Enable this if the project # contains a lot of classes, structs, unions or interfaces. ALPHABETICAL_INDEX = YES # If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then # the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns # in which this list will be split (can be a number in the range [1..20]) COLS_IN_ALPHA_INDEX = 4 # In case all classes in a project start with a common prefix, all # classes will be put under the same header in the alphabetical index. # The IGNORE_PREFIX tag can be used to specify one or more prefixes that # should be ignored while generating the index headers. IGNORE_PREFIX = #--------------------------------------------------------------------------- # configuration options related to the HTML output #--------------------------------------------------------------------------- # If the GENERATE_HTML tag is set to YES (the default) Doxygen will # generate HTML output. GENERATE_HTML = YES # The HTML_OUTPUT tag is used to specify where the HTML docs will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `html' will be used as the default path. HTML_OUTPUT = # The HTML_HEADER tag can be used to specify a personal HTML header for # each generated HTML page. If it is left blank doxygen will generate a # standard header. HTML_HEADER = # The HTML_FOOTER tag can be used to specify a personal HTML footer for # each generated HTML page. If it is left blank doxygen will generate a # standard footer. HTML_FOOTER = # The HTML_STYLESHEET tag can be used to specify a user defined cascading # style sheet that is used by each HTML page. It can be used to # fine-tune the look of the HTML output. If the tag is left blank doxygen # will generate a default style sheet HTML_STYLESHEET = # If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, # files or namespaces will be aligned in HTML using tables. If set to # NO a bullet list will be used. HTML_ALIGN_MEMBERS = YES # If the GENERATE_HTMLHELP tag is set to YES, additional index files # will be generated that can be used as input for tools like the # Microsoft HTML help workshop to generate a compressed HTML help file (.chm) # of the generated HTML documentation. GENERATE_HTMLHELP = NO # If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag # controls if a separate .chi index file is generated (YES) or that # it should be included in the master .chm file (NO). GENERATE_CHI = NO # If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag # controls whether a binary table of contents is generated (YES) or a # normal table of contents (NO) in the .chm file. BINARY_TOC = NO # The TOC_EXPAND flag can be set to YES to add extra items for group members # to the contents of the Html help documentation and to the tree view. TOC_EXPAND = NO # The DISABLE_INDEX tag can be used to turn on/off the condensed index at # top of each HTML page. The value NO (the default) enables the index and # the value YES disables it. DISABLE_INDEX = NO # This tag can be used to set the number of enum values (range [1..20]) # that doxygen will group on one line in the generated HTML documentation. ENUM_VALUES_PER_LINE = 4 # If the GENERATE_TREEVIEW tag is set to YES, a side panel will be # generated containing a tree-like index structure (just like the one that # is generated for HTML Help). For this to work a browser that supports # JavaScript and frames is required (for instance Netscape 4.0+ # or Internet explorer 4.0+). GENERATE_TREEVIEW = NO # If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be # used to set the initial width (in pixels) of the frame in which the tree # is shown. TREEVIEW_WIDTH = 250 #--------------------------------------------------------------------------- # configuration options related to the LaTeX output #--------------------------------------------------------------------------- # If the GENERATE_LATEX tag is set to YES (the default) Doxygen will # generate Latex output. GENERATE_LATEX = NO # The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `latex' will be used as the default path. LATEX_OUTPUT = # If the COMPACT_LATEX tag is set to YES Doxygen generates more compact # LaTeX documents. This may be useful for small projects and may help to # save some trees in general. COMPACT_LATEX = NO # The PAPER_TYPE tag can be used to set the paper type that is used # by the printer. Possible values are: a4, a4wide, letter, legal and # executive. If left blank a4wide will be used. PAPER_TYPE = a4wide # The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX # packages that should be included in the LaTeX output. EXTRA_PACKAGES = # The LATEX_HEADER tag can be used to specify a personal LaTeX header for # the generated latex document. The header should contain everything until # the first chapter. If it is left blank doxygen will generate a # standard header. Notice: only use this tag if you know what you are doing! LATEX_HEADER = # If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated # is prepared for conversion to pdf (using ps2pdf). The pdf file will # contain links (just like the HTML output) instead of page references # This makes the output suitable for online browsing using a pdf viewer. PDF_HYPERLINKS = NO # If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of # plain latex in the generated Makefile. Set this option to YES to get a # higher quality PDF documentation. USE_PDFLATEX = NO # If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. # command to the generated LaTeX files. This will instruct LaTeX to keep # running if errors occur, instead of asking the user for help. # This option is also used when generating formulas in HTML. LATEX_BATCHMODE = NO #--------------------------------------------------------------------------- # configuration options related to the RTF output #--------------------------------------------------------------------------- # If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output # The RTF output is optimised for Word 97 and may not look very pretty with # other RTF readers or editors. GENERATE_RTF = NO # The RTF_OUTPUT tag is used to specify where the RTF docs will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `rtf' will be used as the default path. RTF_OUTPUT = # If the COMPACT_RTF tag is set to YES Doxygen generates more compact # RTF documents. This may be useful for small projects and may help to # save some trees in general. COMPACT_RTF = NO # If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated # will contain hyperlink fields. The RTF file will # contain links (just like the HTML output) instead of page references. # This makes the output suitable for online browsing using WORD or other # programs which support those fields. # Note: wordpad (write) and others do not support links. RTF_HYPERLINKS = NO # Load stylesheet definitions from file. Syntax is similar to doxygen's # config file, i.e. a series of assigments. You only have to provide # replacements, missing definitions are set to their default value. RTF_STYLESHEET_FILE = # Set optional variables used in the generation of an rtf document. # Syntax is similar to doxygen's config file. RTF_EXTENSIONS_FILE = #--------------------------------------------------------------------------- # configuration options related to the man page output #--------------------------------------------------------------------------- # If the GENERATE_MAN tag is set to YES (the default) Doxygen will # generate man pages GENERATE_MAN = NO # The MAN_OUTPUT tag is used to specify where the man pages will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `man' will be used as the default path. MAN_OUTPUT = # The MAN_EXTENSION tag determines the extension that is added to # the generated man pages (default is the subroutine's section .3) MAN_EXTENSION = # If the MAN_LINKS tag is set to YES and Doxygen generates man output, # then it will generate one additional man file for each entity # documented in the real man page(s). These additional files # only source the real man page, but without them the man command # would be unable to find the correct page. The default is NO. MAN_LINKS = NO #--------------------------------------------------------------------------- # configuration options related to the XML output #--------------------------------------------------------------------------- # If the GENERATE_XML tag is set to YES Doxygen will # generate an XML file that captures the structure of # the code including all documentation. Note that this # feature is still experimental and incomplete at the # moment. GENERATE_XML = NO #--------------------------------------------------------------------------- # Configuration options related to the preprocessor #--------------------------------------------------------------------------- # If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will # evaluate all C-preprocessor directives found in the sources and include # files. ENABLE_PREPROCESSING = YES # If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro # names in the source code. If set to NO (the default) only conditional # compilation will be performed. Macro expansion can be done in a controlled # way by setting EXPAND_ONLY_PREDEF to YES. MACRO_EXPANSION = NO # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES # then the macro expansion is limited to the macros specified with the # PREDEFINED and EXPAND_AS_PREDEFINED tags. EXPAND_ONLY_PREDEF = NO # If the SEARCH_INCLUDES tag is set to YES (the default) the includes files # in the INCLUDE_PATH (see below) will be search if a #include is found. SEARCH_INCLUDES = YES # The INCLUDE_PATH tag can be used to specify one or more directories that # contain include files that are not input files but should be processed by # the preprocessor. INCLUDE_PATH = # You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard # patterns (like *.h and *.hpp) to filter out the header-files in the # directories. If left blank, the patterns specified with FILE_PATTERNS will # be used. INCLUDE_FILE_PATTERNS = # The PREDEFINED tag can be used to specify one or more macro names that # are defined before the preprocessor is started (similar to the -D option of # gcc). The argument of the tag is a list of macros of the form: name # or name=definition (no spaces). If the definition and the = are # omitted =1 is assumed. PREDEFINED = # If the MACRO_EXPANSION and EXPAND_PREDEF_ONLY tags are set to YES then # this tag can be used to specify a list of macro names that should be expanded. # The macro definition that is found in the sources will be used. # Use the PREDEFINED tag if you want to use a different macro definition. EXPAND_AS_DEFINED = #--------------------------------------------------------------------------- # Configuration::addtions related to external references #--------------------------------------------------------------------------- # The TAGFILES tag can be used to specify one or more tagfiles. TAGFILES = # When a file name is specified after GENERATE_TAGFILE, doxygen will create # a tag file that is based on the input files it reads. GENERATE_TAGFILE = # If the ALLEXTERNALS tag is set to YES all external classes will be listed # in the class index. If set to NO only the inherited external classes # will be listed. ALLEXTERNALS = NO # The PERL_PATH should be the absolute path and name of the perl script # interpreter (i.e. the result of `which perl'). PERL_PATH = #--------------------------------------------------------------------------- # Configuration options related to the dot tool #--------------------------------------------------------------------------- # If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is # available from the path. This tool is part of Graphviz, a graph visualization # toolkit from AT&T and Lucent Bell Labs. The other options in this section # have no effect if this option is set to NO (the default) HAVE_DOT = YES # If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen # will generate a graph for each documented class showing the direct and # indirect inheritance relations. Setting this tag to YES will force the # the CLASS_DIAGRAMS tag to NO. CLASS_GRAPH = YES # If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen # will generate a graph for each documented class showing the direct and # indirect implementation dependencies (inheritance, containment, and # class references variables) of the class with other documented classes. COLLABORATION_GRAPH = YES # If set to YES, the inheritance and collaboration graphs will show the # relations between templates and their instances. TEMPLATE_RELATIONS = YES # If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT # tags are set to YES then doxygen will generate a graph for each documented # file showing the direct and indirect include dependencies of the file with # other documented files. INCLUDE_GRAPH = YES # If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and # HAVE_DOT tags are set to YES then doxygen will generate a graph for each # documented header file showing the documented files that directly or # indirectly include this file. INCLUDED_BY_GRAPH = YES # If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen # will graphical hierarchy of all classes instead of a textual one. GRAPHICAL_HIERARCHY = YES # The tag DOT_PATH can be used to specify the path where the dot tool can be # found. If left blank, it is assumed the dot tool can be found on the path. DOT_PATH = # The DOTFILE_DIRS tag can be used to specify one or more directories that # contain dot files that are included in the documentation (see the # \dotfile command). DOTFILE_DIRS = # The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width # (in pixels) of the graphs generated by dot. If a graph becomes larger than # this value, doxygen will try to truncate the graph, so that it fits within # the specified constraint. Beware that most browsers cannot cope with very # large images. MAX_DOT_GRAPH_WIDTH = 1024 # The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height # (in pixels) of the graphs generated by dot. If a graph becomes larger than # this value, doxygen will try to truncate the graph, so that it fits within # the specified constraint. Beware that most browsers cannot cope with very # large images. MAX_DOT_GRAPH_HEIGHT = 1024 # If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will # generate a legend page explaining the meaning of the various boxes and # arrows in the dot generated graphs. GENERATE_LEGEND = YES # If the DOT_CLEANUP tag is set to YES (the default) Doxygen will # remove the intermedate dot files that are used to generate # the various graphs. DOT_CLEANUP = YES #--------------------------------------------------------------------------- # Configuration::addtions related to the search engine #--------------------------------------------------------------------------- # The SEARCHENGINE tag specifies whether or not a search engine should be # used. If set to NO the values of all tags below this one will be ignored. SEARCHENGINE = NO # The CGI_NAME tag should be the name of the CGI script that # starts the search engine (doxysearch) with the correct parameters. # A script with this name will be generated by doxygen. CGI_NAME = # The CGI_URL tag should be the absolute URL to the directory where the # cgi binaries are located. See the documentation of your http daemon for # details. CGI_URL = # The DOC_URL tag should be the absolute URL to the directory where the # documentation is located. If left blank the absolute path to the # documentation, with file:// prepended to it, will be used. DOC_URL = # The DOC_ABSPATH tag should be the absolute path to the directory where the # documentation is located. If left blank the directory on the local machine # will be used. DOC_ABSPATH = # The BIN_ABSPATH tag must point to the directory where the doxysearch binary # is installed. BIN_ABSPATH = # The EXT_DOC_PATHS tag can be used to specify one or more paths to # documentation generated for other projects. This allows doxysearch to search # the documentation for these projects as well. EXT_DOC_PATHS = Netxx-0.3.2/docs/doxygen/Makefile0000644000175000017500000000017712173720353016151 0ustar danieldanielPROJECT_NAME=netxx PROJECT_PATH=${PWD}/../../ DOXYGEN_DIR=docs/doxygen .include "${HOME}/develop/project-xslt/etc/doxygen.mk" Netxx-0.3.2/docs/TODO0000644000175000017500000000256412173720353013526 0ustar danieldanielTodo List Todo Before 1.0.0 Release * Remove any calls to malloc with calls to new char[]. (Peer.cxx). * use SUN_LEN instead of sizeof for AF_LOCAL; * Separate the inet_ntop and inet_pton implementations into their own files. * Have a separate file for OS stuff, like os_starup, os_finish, os_get_error, os_set_error. * Clean up documentation and make more complete. * Add Solaris >= 8 /dev/poll support to the Probe class. * Add thread callbacks for OpenSSL. * Call THREADS_init() if initializing OpenSSL. * Add more callbacks to TLS::Context so that developers can better customize TLS behavior. * Verify what WSAETIMEDOUT and WSAEMSGSIZE mean. * Optimize Netxx::Netbuf::xsputn(). * Add support for the FreeBSD kqueue(2) function in Probe_impl. * Should Netxx::Peer::operator<< print out something different for AF_LOCAL? * Should we allow some way to get user credentials from a local domain socket? * TLS::handle_shutdown should be more robust and support non-blocking sockets. * 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? * Add another callback to the Context class so that we can verify certs. Netxx-0.3.2/docs/manual/0000755000175000017500000000000012173720372014305 5ustar danieldanielNetxx-0.3.2/docs/manual/README0000644000175000017500000000031712173720353015165 0ustar danieldanielHow to build on FreeBSD Install the /usr/ports/textproc/docproject port make How to build on RedHat Linux 7.3 Workstation: cd /usr/share/sgml ln -s openjade-* openjade pmake PREFIX=/usr Netxx-0.3.2/docs/manual/get_started.xml0000644000175000017500000001146112173720353017336 0ustar danieldanielGetting Started with Netxx
Building Netxx The following instructions will show you how to compile Netxx on most platforms.
Building on Unix To build Netxx from the command line of a Unix-like operating system you use the configure.pl perl script. There are various command line options that can be given to configure.pl to change various compile time settings. You should begin by reviewing the available options by running ./configure.pl --help. Once you know which command line options you want to give to configure.pl you can run it. First, it will check your build environment to verify that you have the proper tools to build Netxx. After that, it will generate the make-files for your system. When configure.pl is done you can run the make program to build Netxx. After Netxx is built, you can install the library and header files. This is done with the make program and the install target.
Building on MacOS X Building Netxx on MacOS X is similar to building it on Unix. You can follow the instructions for building on Unix if you wish. Either way, you need to install the Developer Tools from Apple. There is a shell script in build/macosx called configure.sh. When you run that script the configure.pl perl script will be run with some good default values. After it is finished, you can build Netxx using the make program.
Building on Windows The following instructions apply to users of Microsoft Visual Studio. If you want to build Netxx under cygwin, follow the directions for building on Unix. There is a MSVC workspace file in build/msvc that can be used to build Netxx on Windows. Open the Netxx.dsw workspace file. Once the workspace is loaded, pull down the Build menu and choose the Batch Build... menu item. A dialog box will appear, click the Rebuild All button.
Learning the Netxx API 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. For complete API reference, you should take a look at the class reference appendix of the Netxx manual or the doxygen generated web pages. Even with these resources, the best place to hang out is in the Netxx header files.
Netxx-0.3.2/docs/manual/credits.xml0000644000175000017500000000446312173720353016472 0ustar danieldanielCredits Netxx it brought to you by the following people. Peter Jones Original designer of Netxx and project maintainer. Ported to the Win32 platform. Ported to the MacOS X platform. Added TLS support via OpenSSL. Alex Mitrofanov Updated all the TLS code to the new internal API. Completed Netxx::TLS::Stream so that it could act as a server. Fixed a bug in the Netxx::TLS::Stream::read() function. Wrote the tls_* examples. Wrote the http_https_server example Fixed up the new Netxx::Peer code to be more portable. Wrote the Netxx::TLS::Certificate class. Steve Bannister Found and fixed a bug in the Netxx::Socket class. Found a bug in the Netxx::StreamBase class relating to non-blocking connects. Isaac Foraker Answered stupid Win32 questions. Netxx-0.3.2/docs/manual/bugs.xml0000644000175000017500000000206512173720353015771 0ustar danieldanielKnown Bugs 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. Unix Operating Systems The Netxx::Address class uses gethostbyname and on most unix-like operating systems that function is NOT thread safe. I am currently looking at ways to get around this. I know that some systems supply gethostbyname_r but not all do. Microsoft Windows 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. All Platforms TLS Support is NOT thread safe. This will be fixed. Netxx-0.3.2/docs/manual/changelog.xml0000644000175000017500000001443212173720353016761 0ustar danieldanielRevision History
Version 0.3.2 July 08, 2003 Version 0.3.2 is a bug fix release. Fixed a bug where socket file descriptors could be leaked. Thanks goes to Steve Bannister. Fixed a problem with building Netxx on Cygwin. Thanks goes to Sergio Ballestrero. Updated Perl scripts to work around a bug in the Perl 5.8 regex parser. Thanks goes to Andy Chou. 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. Fixed a major bug in non-blocking connects. Thanks goes to Steve Bannister. Updated the build script for Mac OS X (configure.sh) so that IPv6 won't cause a problem under 10.2. Implemented missing copy constructor, assignment operator and swap functions for Netxx::Stream. Thanks to Sebastien Bellerive for finding this one.
Version 0.3.1 January 13, 2003 Version 0.3.1 is a bug fix release. 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. Made a small change to Netxx::Peer to allow Netxx to compile under MacOSX again. Included errno.h on windows to define EAGAIN. Thanks to Charles Kerr for the suggestion. The Netxx API appendix of this manual was removed. It caused the size of the manual to be too large.
Version 0.3.0 November 8th, 2002 Lots of changes, some bug fixes and some completely rewritten classes. Most changes were made to make the API even easier to use. 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. 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. 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. 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. 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. 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. Added Win32 MSVC Workspace files for compiling a Netxx static library under Win32. Added a shell script for building a Netxx static library under MacOS X. Added Netxx::TLS::Certificate class. Added a default passphrase function that actually works!
Version 0.2.0 October 22, 2001 New features and some bug fixes. Fixed bug in Socket::write that shows up only when write(2) returns less than the buffer size Fixed bug in call to select when timeout is 0 Added TLS classes a la OpenSSL Moved some classes around in order to add TLS classes Added the Netxx::Netbuf class which is a IOStreams streambuf Added initial support for Microsoft Windows
Version 0.1.0 September 7, 2001 The Netxx code was cleaned up and moved around. The API is now ready for a first release.
Version 0.0.0 March 1, 2001 First draft of some code put together as Netxx.
Netxx-0.3.2/docs/manual/todo.xml0000644000175000017500000000433712173720353016002 0ustar danieldanielTodo List Todo Before 1.0.0 Release Remove any calls to malloc with calls to new char[]. (Peer.cxx). use SUN_LEN instead of sizeof for AF_LOCAL; Separate the inet_ntop and inet_pton implementations into their own files. Have a separate file for OS stuff, like os_starup, os_finish, os_get_error, os_set_error. Clean up documentation and make more complete. Add Solaris >= 8 /dev/poll support to the Probe class. Add thread callbacks for OpenSSL. Call THREADS_init() if initializing OpenSSL. Add more callbacks to TLS::Context so that developers can better customize TLS behavior. Verify what WSAETIMEDOUT and WSAEMSGSIZE mean. Optimize Netxx::Netbuf::xsputn(). Add support for the FreeBSD kqueue(2) function in Probe_impl. Should Netxx::Peer::operator<< print out something different for AF_LOCAL? Should we allow some way to get user credentials from a local domain socket? TLS::handle_shutdown should be more robust and support non-blocking sockets. 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? Add another callback to the Context class so that we can verify certs. Netxx-0.3.2/docs/manual/Makefile0000644000175000017500000001112112173720353015740 0ustar danieldaniel##################################################################### # INPUT_FILE= manual.xml OTHER_INPUT= readme.xml bugs.xml changelog.xml credits.xml todo.xml get_started.xml # ##################################################################### ONE_HTML_DIR= one-html SEP_HTML_DIR= sep-html POSTSCRIPT_DIR= postscript ONE_HTML_OUT= ${ONE_HTML_DIR}/${INPUT_FILE:.xml=.html} .if defined(FREEBSDDOC) SEP_HTML_OUT= ${SEP_HTML_DIR}/index.html .else SEP_HTML_OUT= ${SEP_HTML_DIR}/book1.htm .endif POSTSCRIPT_OUT= ${POSTSCRIPT_DIR}/${INPUT_FILE:.xml=.ps} PDF_OUT= ${POSTSCRIPT_DIR}/${INPUT_FILE:.xml=.pdf} PREFIX?= /usr/local JADE= ${PREFIX}/bin/openjade .if defined(FREEBSDDOC) CATALOGS+= -c ${FREEBSDDOC}/share/sgml/catalog .endif .if ${OSTYPE} == linux CATALOGS+= -c ${PREFIX}/share/sgml/docbook/dsssl/modular/catalog CATALOGS+= -c ${PREFIX}/share/sgml/sgml-iso-entities-8879.1986/catalog CATALOGS+= -c ${PREFIX}/share/sgml/openjade/catalog .else CATALOGS+= -c ${PREFIX}/share/sgml/docbook/dsssl/modular/catalog CATALOGS+= -c ${PREFIX}/share/sgml/iso8879/catalog CATALOGS+= -c ${PREFIX}/share/sgml/docbook/4.1/catalog CATALOGS+= -c ${PREFIX}/share/sgml/openjade/catalog .endif JADE_FLAGS= ${CATALOGS} .if defined(FREEBSDDOC) DSL_HTML= ${FREEBSDDOC}/share/sgml/default.dsl DSL_PRINT= ${FREEBSDDOC}/share/sgml/default.dsl HTMLFLAGS= -ioutput.html PRINTFLAGS= -ioutput.print -ioutput.print.justify -V %two-side% -ioutput.print.twoside PRINTFLAGS+= -ioutput.print.niceheaders -V minimal-section-labels TEXCMDS= \RequirePackage{url} TEXCMDS+= \def\PageTwoSide{1} .else DSL_HTML= ${PREFIX}/share/sgml/docbook/dsssl/modular/html/docbook.dsl DSL_PRINT= ${PREFIX}/share/sgml/docbook/dsssl/modular/print/docbook.dsl HTMLFLAGS= PRINTFLAGS= TEXCMDS= .endif TIDY= ${PREFIX}/bin/tidy -i -m -raw -preserve -f /dev/null TEX= ${PREFIX}/bin/tex DVIPS= ${PREFIX}/bin/dvips PDFTEX= ${PREFIX}/bin/pdftex all: ${ONE_HTML_OUT} ${SEP_HTML_OUT} ${POSTSCRIPT_OUT} ${PDF_OUT} html: ${ONE_HTML_OUT} ${SEP_HTML_OUT} ps: ${POSTSCRIPT_OUT} pdf: ${PDF_OUT} ${ONE_HTML_OUT}: ${INPUT_FILE} ${OTHER_INPUT} mkdir -p ${ONE_HTML_DIR} cp ${INPUT_FILE} ${OTHER_INPUT} ${ONE_HTML_DIR} (\ cd ${ONE_HTML_DIR}; \ ${JADE} ${JADE_FLAGS} -V nochunks ${HTMLFLAGS} -d ${DSL_HTML} -t sgml ${INPUT_FILE} > ${INPUT_FILE:.xml=.html}; \ rm ${INPUT_FILE} ${OTHER_INPUT}; \ ) -${TIDY} ${ONE_HTML_OUT} if test -r ${FREEBSDDOC}/share/misc/docbook.css -a ! -r docbook.css ; then \ cp ${FREEBSDDOC}/share/misc/docbook.css ${ONE_HTML_DIR}; \ fi if test -r docbook.css ; then \ cp docbook.css ${ONE_HTML_DIR}; \ fi ${SEP_HTML_OUT}: ${INPUT_FILE} ${OTHER_INPUT} mkdir -p ${SEP_HTML_DIR} cp ${INPUT_FILE} ${OTHER_INPUT} ${SEP_HTML_DIR} (\ cd ${SEP_HTML_DIR}; \ ${JADE} ${JADE_FLAGS} ${HTMLFLAGS} -d ${DSL_HTML} -t sgml ${INPUT_FILE}; \ rm ${INPUT_FILE} ${OTHER_INPUT}; \ ) for file in `ls ${SEP_HTML_DIR}/*.htm?`; do \ ${TIDY} $$file || echo -n; \ done if test -r ${FREEBSDDOC}/share/misc/docbook.css -a ! -r docbook.css ; then \ cp ${FREEBSDDOC}/share/misc/docbook.css ${SEP_HTML_DIR}; \ fi if test -r docbook.css ; then \ cp docbook.css ${SEP_HTML_DIR}; \ fi ${POSTSCRIPT_OUT}: ${INPUT_FILE} ${OTHER_INPUT} mkdir -p ${POSTSCRIPT_DIR} cp ${INPUT_FILE} ${OTHER_INPUT} ${POSTSCRIPT_DIR} (\ cd ${POSTSCRIPT_DIR}; \ ${JADE} ${JADE_FLAGS} -Vtex-backend ${PRINTFLAGS} -d ${DSL_PRINT} -t tex ${INPUT_FILE}; \ rm ${INPUT_FILE} ${OTHER_INPUT}; \ ${TEX} "&jadetex" '${TEXCMDS} \nonstopmode\input{${INPUT_FILE:.xml=.tex}}' ${INPUT_FILE:.xml=.tex}; \ ${TEX} "&jadetex" '${TEXCMDS} \nonstopmode\input{${INPUT_FILE:.xml=.tex}}' ${INPUT_FILE:.xml=.tex}; \ ${TEX} "&jadetex" '${TEXCMDS} \nonstopmode\input{${INPUT_FILE:.xml=.tex}}' ${INPUT_FILE:.xml=.tex}; \ ${DVIPS} -o ${INPUT_FILE:.xml=.ps} ${INPUT_FILE:.xml=.dvi}; \ ) ${PDF_OUT}: ${POSTSCRIPT_OUT} ${INPUT_FILE} ${OTHER_INPUT} (\ cd ${POSTSCRIPT_DIR}; \ ${PDFTEX} "&pdfjadetex" '${TEXCMDS} \nonstopmode\input{${INPUT_FILE:.xml=.tex}}' ${INPUT_FILE:.xml=.tex}; \ ${PDFTEX} "&pdfjadetex" '${TEXCMDS} \nonstopmode\input{${INPUT_FILE:.xml=.tex}}' ${INPUT_FILE:.xml=.tex}; \ ${PDFTEX} "&pdfjadetex" '${TEXCMDS} \nonstopmode\input{${INPUT_FILE:.xml=.tex}}' ${INPUT_FILE:.xml=.tex}; \ ) clean: rm -rf ${ONE_HTML_DIR} ${SEP_HTML_DIR} ${POSTSCRIPT_DIR} INSTALL_DIR=${HOME}/htdocs/pjones/software/netxx/download/documentation/manual install: all mkdir -p ${INSTALL_DIR} cp -p ${PDF_OUT} ${INSTALL_DIR}/ cp -p ${ONE_HTML_OUT} ${INSTALL_DIR}/ if [ -r ${ONE_HTML_DIR}/docbook.css ] ; then \ cp -p ${ONE_HTML_DIR}/docbook.css ${INSTALL_DIR}/; \ fi cp -pr ${SEP_HTML_DIR} ${INSTALL_DIR}/ Netxx-0.3.2/docs/manual/manual.xml0000644000175000017500000000573112173720353016311 0ustar danieldaniel ]> Netxx Developers Manual Peter Jones
pjones@pmade.org
2002 2003 Peter Jones (http://pmade.org/pjones/) 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: 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. 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. 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. This document describes Netxx to developers who are going to use the library in their own projects. The latest version of this manual can be found at http://pmade.org/pjones/software/netxx/.
&include-readme; &include-getstarted; &include-todo; &include-bugs; &include-changelog; &include-credits;
Netxx-0.3.2/docs/manual/readme.xml0000644000175000017500000000312112173720353016260 0ustar danieldanielIntroduction
What is Netxx? 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. Features Very clean API with total abstraction from any operating system calls. No networking or operating system headers are used in the Netxx header files. 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. Includes support for TLS/SSL (via OpenSSL), IPv6 and Local/Unix Domain Sockets (on operating systems that support them). Cross-platform support. Netxx currently supports most flavors of Unix, Windows and MacOS X. An IOStreams streambuf is provided so you can treat network connections just like a std::iostream. Berkeley style license so you can do whatever you want with Netxx, including commercial use.
Netxx-0.3.2/docs/VERSION0000644000175000017500000000025612173720353014102 0ustar danieldaniel0.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 Netxx-0.3.2/include/0000755000175000017500000000000012173720372013523 5ustar danieldanielNetxx-0.3.2/include/Netxx/0000755000175000017500000000000012173720372014631 5ustar danieldanielNetxx-0.3.2/include/Netxx/Types.h0000644000175000017500000000512112173720353016104 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file defines some common types for Netxx. **/ #ifndef _Netxx_Types_h_ #define _Netxx_Types_h_ // standard includes #include #include namespace Netxx { /// unsigned size type (used for object sizes) typedef unsigned int size_type; /// signed size type (used for objects with possible negative values) typedef signed int signed_size_type; /// type for representing port numbers typedef unsigned short port_type; /// type for representing socket file descriptors typedef signed int socket_type; /** * The Netxx::Exception class is used by the Netxx library to signal * some error condition. It is derived from std::runtime_error which is * dervied from std::exception. This makes it suitable to only catch * std::exception objects if you wish. **/ struct Exception : public std::runtime_error { Exception (const std::string &what_arg) : std::runtime_error(what_arg) { } }; // end Netxx::Exception } // end Netxx namespace #endif Netxx-0.3.2/include/Netxx/StreamBase.h0000644000175000017500000001620212173720353017030 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the definition of the Netxx::StreamBase class. **/ #ifndef _Netxx_StreamBase_h_ #define _Netxx_StreamBase_h_ // Netxx includes #include #include #include namespace Netxx { // forward declarations class Socket; class ProbeInfo; /** * The Netxx::StreamBase class acts as a base class for the various stream * classes. You cannot directly instianciate an object of this class because * it has pure virtual funtions. **/ class StreamBase { public: //#################################################################### /** * Create a new StreamBase and set the timeout for stream operations. * * @param timeout The timeout to use for stream operations. * @author Peter Jones **/ //#################################################################### explicit StreamBase (const Timeout &timeout=Timeout()); //#################################################################### /** * StreamBase virutal destructor. Cleanup the streambase. * * @author Peter Jones **/ //#################################################################### virtual ~StreamBase (void); //#################################################################### /** * Set the timeout that is used for various stream operations. * * @param timeout The timeout to use. * @author Peter Jones **/ //#################################################################### void set_timeout (const Timeout &timeout); //#################################################################### /** * Get the current timeout value that is used for stream operations. * * @return The current timeout value. * @author Peter Jones **/ //#################################################################### const Timeout& get_timeout (void) const; //#################################################################### /** * Read data from the stream into the given buffer. This operation will * place the read data into the buffer unless there is an error or * timeout. If a stream fatal error occures an exception is throw. * * @param buffer The buffer to place read data into. * @param length The avaliable size for the given buffer. * @return Greater than 0: For the bytes read into the buffer. * @return 0 If the peer closed the connection * @return -1: For a timeout * @author Peter Jones **/ //#################################################################### virtual signed_size_type read (void *buffer, size_type length) = 0; //#################################################################### /** * Write data from a buffer into the stream. If a stream fatal error * occures an exception is thrown. * * @param buffer The data to write to the stream. * @param length The amount of data to use from the buffer. * @return Greater than 0: The number of bytes written to the stream. * @return 0 If the peer closed the connection. * @return -1: for a timeout. * @author Peter Jones **/ //#################################################################### virtual signed_size_type write (const void *buffer, size_type length) = 0; //#################################################################### /** * Close the stream connection with the peer. After the connection is * closed you should not use any of the other stream member functions. * * @author Peter Jones **/ //#################################################################### virtual void close (void) = 0; //#################################################################### /** * Return the file descriptor that is being used for the stream * connection. * * @return The file descriptor for this connection. * @author Peter Jones **/ //#################################################################### virtual socket_type get_socketfd (void) const = 0; //#################################################################### /** * Get information about how this StreamBase should be probed from * the Netxx::Probe class. * * @return A Netxx::ProbeInfo object. * @author Peter Jones **/ //#################################################################### virtual const ProbeInfo* get_probe_info (void) const = 0; protected: //#################################################################### /** * This protected member function is used to establish a connection with * one of the addresses given. This function will throw an exception if * it cannot make a connection with any of the given addresses. * * @param socket On successful return this will be the socket for the conection * @param address The list of addresses to try * @author Peter Jones **/ //#################################################################### void make_connection (Socket &socket, const Address &address); //#################################################################### /** * Used by the stream classes so they can implement a swap() member * function. * * @param other The other StreamBase to swap with. * @author Peter Jones **/ //#################################################################### void swap_base (StreamBase &other); private: Timeout timeout_; }; // end Netxx::StreamBase class } // end Netxx namespace #endif Netxx-0.3.2/include/Netxx/Probe.h0000644000175000017500000001641612173720353016060 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the defintion of the Netxx::Probe class. **/ #ifndef _Netxx_Probe_h_ #define _Netxx_Probe_h_ // Netxx includes #include #include #include // standard includes #include #include namespace Netxx { /** * The Netxx::Probe class is a wrapper around one of the Netxx probe * classes. The reason that we have a wrapper is because most operating * systems support select(2) but some also support more advanced APIs like * kqueue(2) or /dev/poll. **/ class Probe { public: /* * Bitmask for telling Probe exactly what you want and for testing the * return value from Probe::ready(). */ enum ReadyType { ready_none = 0x000000, ///< Nothing or Everything depeding on the context ready_read = 0x000001, ///< Readable ready_write = 0x000002, ///< Writable ready_oobd = 0x000004 ///< Readable Out-of-band Data }; /// type for holding the bitmask typedef unsigned int ready_type; /// type returned from ready() typedef std::pair result_type; //#################################################################### /** * Construct a new Netxx::Probe object. * * @author Peter Jones **/ //#################################################################### Probe (void); //#################################################################### /** * Netxx::Probe copy constructor. * * @param other The other Probe object to copy from. * @author Peter Jones **/ //#################################################################### Probe (const Probe &other); //#################################################################### /** * Netxx::Probe assignment operator. * * @param other The other Probe object to copy from. * @return *this. * @author Peter Jones **/ //#################################################################### Probe& operator= (const Probe &other); //#################################################################### /** * Swap this Probe and another one. Similar to std::swap(). * * @param other The other Probe to swap with. * @author Peter Jones **/ //#################################################################### void swap(Probe &other); //#################################################################### /** * Netxx::Probe destructor. * * @author Peter Jones **/ //#################################################################### ~Probe (void); //#################################################################### /** * Clear the Probe. All objects will be removed from the Probe and it * will be in a brand-new like state. * * @author Peter Jones **/ //#################################################################### void clear (void); //#################################################################### /** * Preform the probe. This function will block until either some data is * ready or the given timeout expires. You may also supply a bitmask for * the type of data you want in this probe. * * @param timeout How long to wait for data. Can be a NULL timeout to block until probe data is avaliable. * @param rt A bitmask to control what is returned. ready_none means all data in this context. * @return a std::pair where first is the ready socket and second is a bitmask to tell you what it is ready for. * @return a std::pair with first set to -1 to signal a timeout. * @author Peter Jones **/ //#################################################################### result_type ready (const Timeout &timeout=Timeout(), ready_type rt=ready_none); //#################################################################### /** * Add an object to the Probe. The object must support the * Netxx::ProbeInfo class. All Netxx classes such as Stream and Datagram * support the ProbeInfo class. * * You can optionally give a bitmask that will tell Probe what type of * data to probe for. The default is to probe for all data. In this * case, ready_none means probe for all data. * * @param t The object to add to the Probe. * @param rt A bitmask that tells Probe what to probe for. * @author Peter Jones **/ //#################################################################### template void add (const T &t, ready_type rt=ready_none) { // implemented inline to work around bug in MSVC const ProbeInfo *pi = t.get_probe_info(); std::vector::const_iterator i=pi->get_sockets().begin(), end=pi->get_sockets().end(); for (; i!=end; ++i) { if (pi->needs_pending_check()) add_socket(pi, *i, rt); else add_socket(*i, rt); } } //#################################################################### /** * Remove the given object from the Probe. * * @param t The object to remove from the Probe. * @author Peter Jones **/ //#################################################################### template void remove (const T &t) { // implemented inline to work around bug in MSVC const ProbeInfo *pi = t.get_probe_info(); std::vector::const_iterator i=pi->get_sockets().begin(), end=pi->get_sockets().end(); for (; i!=end; ++i) remove_socket(*i); } private: void add_socket (socket_type socketfd, ready_type rt); void add_socket (const ProbeInfo *pi, socket_type socketfd, ready_type rt); void remove_socket (socket_type socketfd); struct pimpl; pimpl *pimpl_; }; // end Probe class } // end Netxx namespace #endif Netxx-0.3.2/include/Netxx/SockOpt.h0000644000175000017500000001012712173720353016364 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the definition of the Netxx::SockOpt class. **/ #ifndef _Netxx_SockOpt_h_ #define _Netxx_SockOpt_h_ // Netxx includes #include namespace Netxx { /** * The Netxx::SockOpt class is used to set general socket options. **/ class SockOpt { public: //#################################################################### /** * Construct a new Netxx::SockOpt class and link it with the given * socket file descriptor. If you set the revert flag to true, any * options that you set for the socket will be reversed when this * SockOpt class is destroyed. * * @param socketfd The socket file descriptor to set options for. * @param revert Whether or not to revert in the destructor. * @author Peter Jones **/ //#################################################################### explicit SockOpt (socket_type socketfd, bool revert=false); //#################################################################### /** * Netxx::SockOpt class destructor. The destructor will possibly revert * the socket back to its original state if the revert flag was true in * the constructor. * * @author Peter Jones **/ //#################################################################### ~SockOpt (void); //#################################################################### /** * Set the socket to non-blocking. This will cause the read and write * operations to return with a timeout (-1) if the operation could not * be fullfilled imediatly. * * @return True if the socket was set to non-blocking. * @return False if there was some error setting the socket to non-blocking * @author Peter Jones **/ //#################################################################### bool set_non_blocking (void); //#################################################################### /** * Set the socket option that allows you to reuse an address/port pair * even if the state for that pair is TIMED_WAIT. * * @return True if the address could be reused. * @return False if the address could not be reused. * @author Peter Jones **/ //#################################################################### bool set_reuse_address (void); private: socket_type socket_; bool revert_; struct pimpl; pimpl *pimpl_; SockOpt (const SockOpt&); SockOpt& operator= (const SockOpt&); }; // end Netxx::SockOpt class } // end Netxx namespace #endif Netxx-0.3.2/include/Netxx/Datagram.h0000644000175000017500000002362112173720353016525 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the definition of the Netxx::Datagram class. **/ #ifndef _Netxx_Datagram_h_ #define _Netxx_Datagram_h_ // Netxx includes #include #include #include // standard includes #include #include namespace Netxx { // forward declarations class ProbeInfo; /** * The Netxx::Datagram class is a simple wrapper class for sending * datagrams. It supports both connected and unconnected datagram sockets. **/ class Datagram { public: /// the type returned from Datagram::receive() typedef std::pair receive_type; //#################################################################### /** * Construct a new Netxx::Datagram object. If you use this constructor * you must use the send() and receive() member functions instead of the * read() and write() member functions. * * @param timeout An optional timeout for datagram operations. * @author Peter Jones **/ //#################################################################### explicit Datagram (const Timeout &timeout=Timeout()); //#################################################################### /** * Construct a new Netxx::Datagram object and connect it to the given * peer. Connected Datagram objects can use the read() and write() * member functions. Any data send or received will be to/from the * connected peer. * * @param connect_to The peer to connect to. * @param timeout An optional timeout for datagram operations. * @author Peter Jones **/ //#################################################################### explicit Datagram (const Address &connect_to, const Timeout &timeout=Timeout()); //#################################################################### /** * Construct a new Netxx::Datagram object and connect it to the given * peer name and port number. The peer name and port number are given to * the Netxx::Address so please see that documentation for more info. * * Connected Datagram objects can use the read() and write() member * functions. Any data send or received will be to/from the connected * peer. * * @param peer_name The name of the peer to connect to with optional port number. * @param default_port The port to use if none is given in peer_name. * @param timeout An optional timeout to use for datagram operations. * @see Netxx::Address * @author Peter Jones **/ //#################################################################### Datagram (const char *peer_name, port_type default_port, const Timeout &timeout=Timeout()); //#################################################################### /** * Create a datagram object using an already existing socket file * descriptor. The responsiblity for the socket will be transfered to * the new datagram object. You can remove responsibility by calling the * release() member function. * * @param socketfd The file descriptor for the socket to take ownership of. * @param timeout An optional timeout for datagram operations. * @author Peter Jones **/ //#################################################################### explicit Datagram (socket_type socketfd, const Timeout &timeout=Timeout()); //#################################################################### /** * Class destructor. Clean up after the datagram by closing the socket * if necessary. * * @author Peter Jones **/ //#################################################################### ~Datagram (void); //#################################################################### /** * Send data to a specific peer address. You cannot use this function if * you created the datagram object with the connecting constructor. This * function will throw an exception if there are any errors. * * @param peer The peer to send the data to. * @param buffer The buffer to send to the peer. * @param length The size of the buffer. * @return Greater than or equal to 0: The number of bytes sent to the peer. * @return -1: A timeout occured. * @author Peter Jones **/ //#################################################################### signed_size_type send (const Peer &peer, const void *buffer, size_type length); //#################################################################### /** * Receive data from any peer. The peer that sent that data will be * returned in a std::pair. This function will throw an exception if * an error occures. You can only use this function if you did not use * the connecting constructor. * * @param buffer A place to store the incoming datagram message. * @param length The size of the buffer. * @return receive_type.first greater than or equal to 0: The number of bytes that were placed in the buffer. * @return receive_type.first == -1: A timeout occured. * @author Peter Jones **/ //#################################################################### receive_type receive (void *buffer, size_type length); //#################################################################### /** * Write data to the connected peer. You can only use this function if * you used the connecting constructor. An exception will be thrown if * an error occures. * * @param buffer The buffer that contains the messeage to send to the peer. * @param length The size of the buffer. * @return Greater than or equal to 0: The number of bytes sent to the peer. * @return -1 A timeout occured. * @author Peter Jones **/ //#################################################################### signed_size_type write (const void *buffer, size_type length); //#################################################################### /** * Read data from a connected peer into a buffer. You can only call this * function if you used the connecting constructor. An exception will be * thrown if an error occures. * * @param buffer The place to store the received message from the peer. * @param length The size of the buffer. * @return Greater than or equal to 0:The number of bytes placed in your buffer. * @return -1 A timeout occured. * @author Peter Jones **/ //#################################################################### signed_size_type read (void *buffer, size_type length); //#################################################################### /** * Get the file descriptor for the socket this Datagram object is using. * * @return The current socket file descriptor. * @author Peter Jones **/ //#################################################################### socket_type get_socketfd (void) const; //#################################################################### /** * Close the socket that the datagram object is using if it is open. * This is normally done by the datagram class destructor. * * @author Peter Jones **/ //#################################################################### void close (void); //#################################################################### /** * Release control of the socket file descriptor that is being used. * This will prevent the destructor from closing the socket. Once you * call release you must make sure that some other object takes control * of the file descriptor or it could be leaked. * * @author Peter Jones **/ //#################################################################### void release (void); //#################################################################### /** * Get information about how Datagram objects should be used with the * Netxx::Probe class. * * @return A Netxx::ProbeInfo object. * @author Peter Jones **/ //#################################################################### const ProbeInfo* get_probe_info (void) const; private: struct pimpl; pimpl *pimpl_; Datagram (const Datagram&); Datagram& operator= (const Datagram&); }; // end Netxx::Datagram class } // end Netxx namespace #endif Netxx-0.3.2/include/Netxx/StreamServer.h0000644000175000017500000001215112173720353017423 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the definition of the Netxx::StreamServer class. **/ #ifndef _Netxx_StreamServer_h_ #define _Netxx_StreamServer_h_ // Netxx includes #include #include #include #include namespace Netxx { // forward declaration class ProbeInfo; class ServerBase; /** * The Netxx::StreamServer class is used for stream based servers like TCP * through IPv4, TCP through IPv6 and TCP through Local Domain Sockets. **/ class StreamServer { public: //#################################################################### /** * Create a StreamServer that will bind to all local addresses using the * given port. You can also set a timeout value and a listen(2) backlog * value. * * @param port The port to use on all local interfaces. * @param timeout The timeout to use. Default is to block. * @param listen_backlog The listen(2) backlog parameter. * @author Peter Jones **/ //#################################################################### StreamServer (port_type port, const Timeout &timeout=Timeout(), int listen_backlog=128); //#################################################################### /** * Create a StreamServer that will bind to each address given in addr. * You can also set the timeout and listen(2) backlog value. * * @param addr The addresses to bind to. * @param timeout The timeout to use. Default is to block. * @param listen_backlog The listen(2) backlog parameter. * @author Peter Jones **/ //#################################################################### StreamServer (const Address &addr, const Timeout &timeout=Timeout(), int listen_backlog=128); //#################################################################### /** * Clean up after the StreamServer. Any sockets in use will be closed. * * @author Peter Jones **/ //#################################################################### ~StreamServer (void); //#################################################################### /** * Try to accept a connection from a Peer. The returned value will * indicate whether or not a connection was established or a timeout * occured. This member function will throw an exception if there is an * error. * * @return A Peer that contains info about the connected peer. * @return An invalid Peer to signal a timeout. * @see Netxx::Peer * @author Peter Jones **/ //#################################################################### Peer accept_connection (void); //#################################################################### /** * Get information about how this StreamServer should be probed from the * Netxx::Probe class. * * @return A Netxx::ProbeInfo object. * @author Peter Jones **/ //#################################################################### const ProbeInfo* get_probe_info (void) const; friend bool operator== (const StreamServer &ss, socket_type fd); friend bool operator== (socket_type fd, const StreamServer &ss); friend bool operator!= (const StreamServer &ss, socket_type fd); friend bool operator!= (socket_type fd, const StreamServer &ss); private: ServerBase *pimpl_; StreamServer (const StreamServer&); StreamServer& operator= (const StreamServer&); void init (const Address &addr, int backlog); }; // end Netxx::StreamServer class } // end Netxx namespace #endif Netxx-0.3.2/include/Netxx/Timeout.h0000644000175000017500000001156512173720353016437 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the definition of the Netxx::Timeout class. **/ #ifndef _Netxx_Timeout_h_ #define _Netxx_Timeout_h_ namespace Netxx { /** * The Netxx::Timeout class is used by the other Netxx classes to specifiy a * timeout value. A timeout is broken down into seconds and microseconds. * This class also has a default constructor for a null timeout, that is, no * timeout. * * As a side note, just in case you did not know, there are one million * microseconds in one second. **/ class Timeout { public: //#################################################################### /** * Construct a null timeout. This means that a timeout value should not * be used at all. This is the default for most Netxx classes. * * @author Peter Jones **/ //#################################################################### Timeout (void) : sec_(0), usec_(0) { } //#################################################################### /** * Construct a Netxx::Timeout with the given length in seconds and * optionally the addition of the given microseconds. * * @param sec The number of seconds for the timeout. * @param usec An optional number of microseconds. * @author Peter Jones **/ //#################################################################### explicit Timeout (long sec, long usec=0) : sec_(sec), usec_(usec) {} //#################################################################### /** * Set the seconds part of the timeout. * * @param sec The new value for the seconds field. * @author Peter Jones **/ //#################################################################### void set_sec (long sec) { sec_ = sec; } //#################################################################### /** * Get the seconds field of the timeout. * * @return The timeout's seconds field. * @author Peter Jones **/ //#################################################################### long get_sec (void) const { return sec_; } //#################################################################### /** * Set the microseconds field for the timeout. * * @param usec The microseconds to use for this timeout. * @author Peter Jones **/ //#################################################################### void set_usec (long usec) { usec_ = usec; } //#################################################################### /** * Get the microseconds field for this timeout. * * @return The timeout's microseconds field. * @author Peter Jones **/ //#################################################################### long get_usec (void) const { return usec_; } //#################################################################### /** * Test to see if this timeout is valid or null. * * @return True if this timeout has been set with a value. * @return False if this timeout is NULL (set to zero). * @author Peter Jones **/ //#################################################################### operator bool (void) const { return sec_ || usec_; } private: long sec_; long usec_; }; // end Netxx::Timeout class } // end Netxx namespace #endif Netxx-0.3.2/include/Netxx/ProbeInfo.h0000644000175000017500000001707312173720353016674 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the defintion of the Netxx::ProbeInfo class. **/ #ifndef _Netxx_ProbeInfo_h_ #define _Netxx_ProbeInfo_h_ // Netxx includes #include // standard includes #include namespace Netxx { /** * The Netxx::ProbeInfo class is used to provide information to the * Netxx::Probe class on how to probe another Netxx object. This * implementation of the class does not do much. The entire implementation * is inline to make most of it disapper at compile time. * * For Netxx objects that need custom probing, they will create their own * ProbeInfo class and drive from this one. **/ class ProbeInfo { public: /** * The ProbeInfo::PendingType is used to signal what state a socket is * in after a pending check. */ enum PendingType { pending_none = 0x000000, ///< The socket is not ready pending_read = 0x000001, ///< The socket is ready for reading pending_write = 0x000002, ///< The socket is ready for writing pending_oobd = 0x000004 ///< The socket is ready for reading OOB data. }; /// a type for combinding different PendingType's typedef unsigned int pending_type; //#################################################################### /** * Netxx::ProbeInfo Default constructor. * * @author Peter Jones **/ //#################################################################### ProbeInfo (void) { } //#################################################################### /** * Construct a new ProbeInfo using a vector of sockets. * * @param sockets The list of sockets to use for probing. * @author Peter Jones **/ //#################################################################### explicit ProbeInfo (const std::vector &sockets) : sockets_(sockets) { } //#################################################################### /** * Construct a new ProbeInfo using only one socket. * * @param socketfd The socket to probe for. * @author Peter Jones **/ //#################################################################### explicit ProbeInfo (socket_type socketfd) { add_socket(socketfd); } //#################################################################### /** * Copy constructor. * * @param other The ProbeInfo to copy from. * @author Peter Jones **/ //#################################################################### ProbeInfo (const ProbeInfo &other) : sockets_(other.sockets_) { } //#################################################################### /** * Assignment operator. * * @param other The ProbeInfo to copy from. * @return *this. * @author Peter Jones **/ //#################################################################### ProbeInfo& operator= (const ProbeInfo &other) { ProbeInfo tmp(other); swap(tmp); return *this; } //#################################################################### /** * Swap this ProbeInfo for another. * * @param other The ProbeInfo to swap with. * @author Peter Jones **/ //#################################################################### void swap (ProbeInfo &other) { sockets_.swap(other.sockets_); } //#################################################################### /** * Class destructor. * * @author Peter Jones **/ //#################################################################### virtual ~ProbeInfo (void) { } //#################################################################### /** * Add a socket file descriptor to the list of sockets to probe. * * @param socketfd The socket file descriptor to add. * @author Peter Jones **/ //#################################################################### void add_socket (socket_type socketfd) { sockets_.push_back(socketfd); } //#################################################################### /** * Get the list of sockets that need to be probed. * * @return A vector that contains all the sockets to be probed. * @author Peter Jones **/ //#################################################################### const std::vector& get_sockets (void) const { return sockets_; } //#################################################################### /** * Reset the list of sockets to probe. Note: this will not reset the * sockets to probe in the actual Netxx::Probe class. You should call * Netxx::Probe::clear() as well. * * @author Peter Jones **/ //#################################################################### void clear (void) { sockets_.clear(); } //#################################################################### /** * Override this function if you need special pending checks for your * socket file descriptors. * * @return True if Probe should call check_pending(). * @return False if Probe should not call check_pending(). * @author Peter Jones **/ //#################################################################### virtual bool needs_pending_check (void) const { return false; } //#################################################################### /** * Override this function to return the correct pending state for the * given socket file descriptor. This call should be very fast and * should NEVER EVER block! * * @param socket_type The socket to check pending status on. * @param pending_type What type of pending state are we looking for. * @return The pending state for the socket. * @author Peter Jones **/ //#################################################################### virtual pending_type check_pending (socket_type, pending_type) const { return pending_none; } private: std::vector sockets_; }; // end ProbeInfo class } // end Netxx namespace #endif Netxx-0.3.2/include/Netxx/Address.h0000644000175000017500000002041112173720353016364 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the definition of the Netxx::Address class. **/ #ifndef _Netxx_Address_h_ #define _Netxx_Address_h_ // Netxx includes #include #include // standard includes #include #include namespace Netxx { /** * The Netxx::Address class is used by Netxx as a container for network * addresses. An address can be used by a server to specify which local * address and port to bind to. An address can also be used by a client to * know which remote host to connect to and on which port. * * In Netxx, the address also specifies other connection related * information, such as the connection protocol. **/ class Address { public: /// address container type typedef std::vector container_type; /// address const_iterator type typedef container_type::const_iterator const_iterator; //#################################################################### /** * Netxx::Address class constructor. This constructor is designed to be * used by clients wanting the address information about a server. The * url parameter can be a host name with or without a protocol, port * number or path. Here are some examples: pmade.org pmade.org:80 * http://pmade.org http://pmade.org:80/index.html. * * Here is the order in which the port number is determined. (1) from * the port part of the hostname as in pmade.org:80, (2) from the given * protocol part such as http:// and (3) from the given default port. * * @param uri A string as described above * @param default_port The default port number for this address * @param use_ipv6 Allow the use of IPv6 if compiled in. * @author Peter Jones **/ //#################################################################### explicit Address (const char *uri, port_type default_port=0, bool use_ipv6=false); //#################################################################### /** * Netxx::Address class constructor. This constructor is designed to be * used by servers when they need to specify the local addresses and * ports to which it will bind. * * After the constructor is called, you will want to add addresses to * the address list using one of the appropriate member functions such * as add_address. * * @param use_ipv6 Allow the use of IPv6 if compiled in. * @author Peter Jones **/ //#################################################################### explicit Address (bool use_ipv6=false); //#################################################################### /** * Netxx::Address class destructor. * * @author Peter Jones **/ //#################################################################### ~Address (void); //#################################################################### /** * If the URI that was given in the constructor had a protocol specifier * such as http:// this member function will return that string. * Otherwise this function will return 0. * * @return The protcol string like "http" or 0. * @author Peter Jones **/ //#################################################################### const char* get_protocol (void) const; //#################################################################### /** * Get the hostname that was given in the constructor. This may be a raw * address if that was given to the constructor. * * @return The hostname. * @author Peter Jones **/ //#################################################################### const char* get_name (void) const; //#################################################################### /** * Get the URI path information of that was present in the constructor. * For example, if the given URI was pmade.org/index.html, this member * function will return "/index.html". If no path information was given * in the URI, this function will return 0. * * @return The path string or 0. * @author Peter Jones **/ //#################################################################### const char* get_path (void) const; //#################################################################### /** * This function will return the actual port number that was chosen by * the constructor. * * @return The final port number for this address. * @author Peter Jones **/ //#################################################################### port_type get_port (void) const; //#################################################################### /** * Get an iterator to the first address pair. * * @return The address begin iterator. * @author Peter Jones **/ //#################################################################### const_iterator begin (void) const; //#################################################################### /** * Get an iterator that points one past the last address pair. * * @return The address end iterator. * @author Peter Jones **/ //#################################################################### const_iterator end (void) const; //#################################################################### /** * Find out how many addresses are stored in this address class. * * @return The number of addresses that this class is holding. * @author Peter Jones **/ //#################################################################### size_type size (void) const; //#################################################################### /** * Add another address to the list. The URI parameter follows that of * the first constructor. * * @param uri The URI of the address. * @param default_port The default port to use. * @author Peter Jones **/ //#################################################################### void add_address(const char *uri, port_type default_port=0); //#################################################################### /** * Add all local addresses to the address list. This is meant to be used * by servers who wish to bind to all local addresses. * * @param port The port to use for all local addresses. * @author Peter Jones **/ //#################################################################### void add_all_addresses (port_type port); private: std::string protocol_; std::string name_; std::string path_; port_type port_; container_type addrs_; bool ipv6_; }; // end Netxx::Address class } // end Netxx namespace #endif Netxx-0.3.2/include/Netxx/TLS/0000755000175000017500000000000012173720372015273 5ustar danieldanielNetxx-0.3.2/include/Netxx/TLS/Context.h0000644000175000017500000001545012173720353017074 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the definition of the Netxx::TLS::Context class. **/ #ifndef _Netxx_TLS_Context_h_ #define _Netxx_TLS_Context_h_ // Netxx includes #include namespace Netxx { namespace TLS { // forward declarations class Stream; class Server; struct context_pimpl; /** * The Netxx::TLS::Context class is used to hold common TLS information. It * is needed to create TLS stream objects. You can subclass the * Netxx::TLS::Context class to customize such things as the password * callback. **/ class Context { public: /** * Provides a list of protocols that you can choose to support or not * support. It is recomended that you don't support SSLv2. */ enum Protocol { PROTOCOL_SSLv2, ///< SSL Version 2 PROTOCOL_SSLv3, ///< SSL Version 3 PROTOCOL_TLSv1, ///< TLS Version 1 }; //#################################################################### /** * Construct a new Netxx::TLS::Context object and optionally initilize * the backend TLS library. You don't want to initilize the backend TLS * library more than once so you can give the constructor false for the * allow_init flag. * * To make the Netxx::TLS::Context thread safe, you should create one * Context object and load certificate files before you start any * threads. * * @param allow_init If true, initilize the backend TLS library. * @author Peter Jones **/ //#################################################################### explicit Context (bool allow_init=true); //#################################################################### /** * Netxx::TLS::Context destructor. * * @author Peter Jones **/ //#################################################################### virtual ~Context (void); //#################################################################### /** * Load the a certificate chain from the given file. A certificate chain * file should contain PEM encoded certificate in chain order. Chain * order starts from the application certificate and ends with the root * CA certificate. * * @param filename The name of the file that contains the certificate chain. * @author Peter Jones **/ //#################################################################### void load_cert_chain (const char *filename); //#################################################################### /** * Load a possibly encrypted private key from the given file. If the * file is encrypted, the password callback will be called to get the * passphrase to decrypt the private key. * * @param filename The name of the file that contains the private key. * @author Peter Jones **/ //#################################################################### void load_private_key (const char *filename); //#################################################################### /** * Load a PEM encoded file that contains a list of trusted CA * certificates. * * @param filename The file tht contains the CA certificates. * @author Peter Jones **/ //#################################################################### void load_ca_file (const char *filename); //#################################################################### /** * Disable support for the given protocol. * * @param which_protocol The protocol to remove support for. * @author Peter Jones **/ //#################################################################### void remove_protocol (Protocol which_protocol); protected: //#################################################################### /** * Override this function so that you can handle password requests in a * custom way. For example, you may want to open a GUI dialog and ask * for the password. You must use this function on Win32. * * @param password The string to store the password in. * @param encrypting True if the password is needed for encrypting; flase for decrypting * @return True for success * @return False for failure * @author Peter Jones **/ //#################################################################### virtual bool get_password (std::string &password, bool encrypting); //#################################################################### /** * Override this function to provide a custom way to seed the * pseudorandom number generator. On platfors that don't have a * /dev/random entropy source. This function will be called when the * context is created (and if the allow_init flag was true) and should * return some seed data in the passed in std::string. * * @param seed The place to return some seed data. * @author Peter Jones **/ //#################################################################### virtual void seed_prng (std::string &seed); private: context_pimpl *pimpl_; friend struct context_pimpl; friend class Stream; friend class Server; Context (const Context&); Context& operator= (const Context&); }; // end Netxx::TLS::Context class }} // end Netxx and TLS namespace #endif Netxx-0.3.2/include/Netxx/TLS/Certificate.h0000644000175000017500000001420412173720353017666 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the definition of the TLS::Certificate class. **/ #ifndef _Netxx_TLS_Certificate_h_ #define _Netxx_TLS_Certificate_h_ // standard includes #include namespace Netxx { namespace TLS { /** * The Netxx::TLS::Certificate class allows you to access information about * an X509 certificate. You should use this so that you can verify that the * peer you are communicating with is the one you think it is. */ class Certificate { public: //#################################################################### /** * Create a new Netxx::TLS::Certificate. This is pretty useless for now * because this is a pure-virtual class. * * @author Alex Mitrofanov **/ //#################################################################### Certificate (void); //#################################################################### /** * Cleanup a Netxx::TLS::Certificate object * * @author Alex Mitrofanov **/ //#################################################################### virtual ~Certificate (void); //#################################################################### /** * Check to see if this certificate object is valid. * * @return True (1) if the certificate is valid. * @return False (0/NULL) if the certificate is NOT valid. * @author Peter Jones **/ //#################################################################### virtual operator void* (void) const = 0; //#################################################################### /** * Another way to check if this certificate object is valid. * * @return True if the certificate is NOT valid. * @return False if the certificate is valid. * @author Peter Jones **/ //#################################################################### virtual bool operator! (void) const = 0; //#################################################################### /** * Get the fully qualified domain name, or the common name from the * certificate. The FQDN is checked first, if there is no FQND, * commonName is returned. * * @return The FQDN or commonName * @return A blank string to signal error. * @author Alex Mitrofanov **/ //#################################################################### virtual std::string get_fqdn (void) const = 0; //#################################################################### /** * Get the country name from the certificate. * * @return The country name. * @return A blank string to signal error. * @author Alex Mitrofanov **/ //#################################################################### virtual std::string get_country (void) const = 0; //#################################################################### /** * Get the locality name (e.g, the state name) from the certifcate. * * @return The locality name. * @return A blank string to signal error. * @author Alex Mitrofanov **/ //#################################################################### virtual std::string get_locality (void) const = 0; //#################################################################### /** * Get the region name (e.g., city name) from the certificate. * * @return The region name. * @return A blank string to signal error. * @author Alex Mitrofanov **/ //#################################################################### virtual std::string get_region (void) const = 0; //#################################################################### /** * Get the organization name from the certificate. * * @return The organization name. * @return A blank string to signal error. * @author Alex Mitrofanov **/ //#################################################################### virtual std::string get_organization (void) const = 0; //#################################################################### /** * Get the organizational unit name from the certificate. * * @return The organizational unit name * @return A blank string to signal error. * @author Alex Mitrofanov **/ //#################################################################### virtual std::string get_organization_unit (void) const = 0; private: Certificate (const Certificate&); Certificate& operator= (const Certificate&); }; // end Netxx::TLS::Certificate class }} // namespace Netxx & namespace TLS #endif Netxx-0.3.2/include/Netxx/TLS/Stream.h0000644000175000017500000002136012173720353016700 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the definition of the Netxx::TLS::Stream class. **/ #ifndef _Netxx_TLS_Stream_h_ #define _Netxx_TLS_Stream_h_ // Netxx includes #include #include #include namespace Netxx { // forward declarations class ProbeInfo; namespace TLS { // forward declaration class Certificate; struct tls_pimpl; /** * The Netxx::TLS::Stream class is used to send and receive data on a * connected TLS socket. It has two constructors, one that connects to the * given address and another that uses an already connected socket. * * When using the constructor that can take a socket descriptor you must * specifiy whether the TLS::Stream should operate in server or client mode. * This is due to the TLS protocol being a little different for a client * than it is for a server. **/ class Stream : public Netxx::StreamBase { public: /** * The connection mode for the Netxx::TLS::Stream */ enum Mode { mode_client, ///< This Netxx::TLS::Stream should act as a TLS client. mode_server ///< This Netxx::TLS::Stream shoudl act as a TLS server. }; //#################################################################### /** * Construct a new Netxx::TLS::Stream object. This constructor will * connect to the peer given in the Netxx::Address class. * * @param context The context to use for this stream. * @param address The address to connect to. * @param timeout The timeout to use for the connect and stream operations. * @author Peter Jones **/ //#################################################################### explicit Stream (Context &context, const Address &address, const Timeout &timeout=Timeout()); //#################################################################### /** * Construct a new Netxx::TLS::Stream object. This constructor will * connect to the given address. The given address string is passed to a * Netxx::Address class. * * @param context The contect to use for this stream. * @param addr The address to connect to. * @param default_port The port to connect to if one is not given in addr. * @param timeout The timeout to use for the connect and stream operations. * @author Peter Jones **/ //#################################################################### Stream (Context &context, const char *addr, port_type default_port, const Timeout &timeout=Timeout()); //#################################################################### /** * Construct a new Netxx::TLS::Stream object and start TLS on the given * socket file descriptor. This object will then own the socket file * descriptor and will close it when it is done with it. * * A mode is needed so that the Netxx::TLS::Stream will know what parts * of the TLS protocol to use, client or server. Default is client. * * @param context The TLS::Context to use for this stream. * @param socketfd The socket file descriptor to use. * @param mode Is this a TLS server or client? * @param timeout The Timeout to use for stream operations. * @author Peter Jones **/ //#################################################################### Stream (Context &context, socket_type socketfd, Mode mode=mode_client, const Timeout &timeout=Timeout()); //#################################################################### /** * Netxx::TLS::Stream destructor. Shutdown the TLS connection if * necessary and clean things up. * * @author Peter Jones **/ //#################################################################### ~Stream (void); //#################################################################### /** * Read data from the TLS connection and place it into the given buffer. * If an error occures this function will throw an exception. * * @param buffer The buffer to store the read data into. * @param length The size of the given buffer. * @return Greater than 0: The number of bytes stored in the buffer. * @return 0: The connected peer closed the connection. * @return -1: A timeout occured. * @author Peter Jones **/ //#################################################################### signed_size_type read (void *buffer, size_type length); //#################################################################### /** * Write data from the given buffer to the TLS conection. If an error * occures this function will throw an exception. * * @param buffer The buffer to write to the connection. * @param length The number of bytes to use from the buffer. * @return Greater than 0: The number of bytes written to the connection. * @return 0: The connected peer closed the connection. * @return -1: A timeout occured. * @author Peter Jones **/ //#################################################################### signed_size_type write (const void *buffer, size_type length); //#################################################################### /** * Close the connection. Once you do this you can't call read or write * anymore. This is normally done by the destructor. * * @author Peter Jones **/ //#################################################################### void close (void); //#################################################################### /** * Get the connected peer's certificate. * * @return A valid certificate if the peer gave one to you * @return An invalid certificate if the peer does not have one * @author Alex Mitrofanov **/ //#################################################################### const Certificate& get_peer_cert (void) const; //#################################################################### /** * Get the certificate for the issuer of the connected peer's * certificate. * * @return A valid certificate if the peer gave one and it was signed by an issuer * @return An invalid certificate if there was no peer cert or no issuer * @author Alex Mitrofanov **/ //#################################################################### const Certificate& get_issuer_cert (void) const; //#################################################################### /** * Return the current socket file descriptor in use. * * @author Alex Mitrofanov **/ //#################################################################### socket_type get_socketfd (void) const; //#################################################################### /** * Get information about how this TLS::Stream should be probed from the * Netxx::Probe class. * * @return A Netxx::ProbeInfo object. * @author Peter Jones **/ //#################################################################### const ProbeInfo* get_probe_info (void) const; private: tls_pimpl *pimpl_; Stream (const Stream&); Stream& operator= (const Stream&); }; // end Netxx::TLS::Stream class }} // end Netxx and TLS namespaces #endif Netxx-0.3.2/include/Netxx/Peer.h0000644000175000017500000001726512173720353015707 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the definition of the Netxx::Peer class. **/ #ifndef _Netxx_Peer_h_ #define _Netxx_Peer_h_ // Netxx includes #include // standard includes #include namespace Netxx { /** * The Netxx::Peer class holds information about the Peer you are talking * and/or connected to. **/ class Peer { public: //#################################################################### /** * Default constructor for an invalid peer. * * @author Peter Jones **/ //#################################################################### Peer (void); //#################################################################### /** * Constructor that takes the address of the peer. * * @param addr The string form of the peer's address * @param port The peer's port. * @param saddr The peer address struct. * @param saddr_size The size of saddr. * @author Peter Jones **/ //#################################################################### Peer (const char *addr, port_type port, void *saddr, size_type saddr_size); //#################################################################### /** * Create a new Peer where the socket file descriptor used to * communicate with the peer is given in socketfd and the sockaddr * struct for the peer is given in saddr. * * @param socketfd The socket file descriptor for the peer. * @param saddr The sockaddr struct for the peer. * @param saddr_size The size of the saddr struct. * @author Peter Jones **/ //#################################################################### Peer (socket_type socketfd, void *saddr, size_type saddr_size); //#################################################################### /** * Copy constructor. * * @param other The other Peer class to copy from. * @author Peter Jones **/ //#################################################################### Peer (const Peer &other); //#################################################################### /** * Assignment operator. * * @param other The other Peer class to assign from. * @author Peter Jones **/ //#################################################################### Peer& operator= (const Peer &other); //#################################################################### /** * Swap this Peer class with another one. * * @param other Peer class to swap with. * @author Peter Jones **/ //#################################################################### void swap (Peer &other); //#################################################################### /** * Class destructor. * * @author Peter Jones **/ //#################################################################### ~Peer (void); //#################################################################### /** * Get the string version of the address of the peer. * * @return The address of the peer. * @author Peter Jones **/ //#################################################################### const char* get_address (void) const; //#################################################################### /** * Get the port number for the peer. * * @return The port number of the peer. * @author Peter Jones **/ //#################################################################### port_type get_port (void) const; //#################################################################### /** * Get the local port number for the peer. * * @return The local port number of the peer. * @author Alex Mitrofanov **/ //#################################################################### port_type get_local_port (void) const; //#################################################################### /** * Get the socket file descriptor for this peer. This member function * will return -1 if there is no socket file descriptor for this peer. * * @return The socket file descriptor or -1. * @author Peter Jones **/ //#################################################################### socket_type get_socketfd (void) const; //#################################################################### /** * Test to see if a peer is valid. * * @return True if the peer is valid. * @return False if the peer is invalid. * @author Peter Jones **/ //#################################################################### operator bool (void) const; //#################################################################### /** * Get the sockaddr struct as a void pointer if this is a valid Peer * object. * * @return A void pointer to the sockaddr struct. * @return 0 If this Peer is invalid. * @author Peter Jones **/ //#################################################################### const void* get_sa (void) const; //#################################################################### /** * Get the size of the sockaddr struct if this is a valid Peer object. * * @return The size of the sockaddr struct. * @return 0 If this Peer is invalid. * @author Peter Jones **/ //#################################################################### size_type get_sa_size (void) const; private: bool okay_; std::string addr_; port_type port_; socket_type socketfd_; void *sockaddr_; size_type sockaddr_size_; }; // end Netxx::Peer class //#################################################################### /** * Insert the string form of the peer into the given stream. * * @param stream The stream to insert the peer into. * @param peer The peer to insert. * @return The stream from the first param. * @author Peter Jones **/ //#################################################################### std::ostream& operator<< (std::ostream &stream, const Peer &peer); } // end Netxx namespace #endif Netxx-0.3.2/include/Netxx/Stream.h0000644000175000017500000002360212173720353016237 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the definition of the Netxx::Stream class. **/ #ifndef _Netxx_Stream_h_ #define _Netxx_Stream_h_ // Netxx includes #include #include namespace Netxx { // forward declarations class ProbeInfo; /** * The Netxx::Stream class is used to establish a connection with a peer. * The peer to connect to is listed in a Netxx::Address class. The peer may * have more than one address in the Netxx::Address and the Netxx::Stream * class will connect to the first one possible. * * This class is mainly for a 'client' application since it makes the * connection to a given peer. To make is useful in a server application, * this class also has a constructor that you can use to communicate with a * client that was returned from a call to accept_connection(). **/ class Stream : public StreamBase { public: //#################################################################### /** * Construct a new Netxx::Stream and connect to the given peer. The * first address in the Netxx::Address class that works will be the one * the Stream object is connected to. If the Stream object cannot * connect to any of the address an exception is trown. * * If a timeout is given, it will be used for all stream operations, * including the initial connection to the peer. * * @param address The list of addresses for the peer. * @param timeout An optional timeout to use for all operations. * @author Peter Jones **/ //#################################################################### explicit Stream (const Address &address, const Timeout &timeout=Timeout()); //#################################################################### /** * Construct a new Netxx::Stream without a Netxx::Address. Instead given * a char* that holds the name of the peer. This name will be passed to * the Netxx::Address constructor along with the given default port * number. * * @param uri The name of the peer to connect to in a possible URI format. * @param default_port The port to use if the given URI does not have one. * @param timeout An optional timeout to use for all operations. * @see Netxx::Address * @author Peter Jones **/ //#################################################################### explicit Stream (const char *uri, port_type default_port=0, const Timeout &timeout=Timeout()); //#################################################################### /** * Construct a new Netxx::Stream and take over an already established * connection. This Stream object will then own the connection socket * and will close it in its destructor. * * This is useful for server applications so that they can use a * Netxx::Stream object to communicate with a new client that was * returned from Netxx::StreamServer::accept_connection(). * * @param socketfd The file descriptor for the socket to own. * @param timeout An optional timeout to use for all operations. * @author Peter Jones **/ //#################################################################### explicit Stream (socket_type socketfd, const Timeout &timeout=Timeout()); //#################################################################### /** * Netxx::Stream copy constructor. I can't see how this would be very * useful but it is provided for safety and completeness. The copy * constructor will cause a copy of the socket to be made. * * @param other The other Netxx::Stream to copy from. * @author Peter Jones **/ //#################################################################### Stream (const Stream &other); //#################################################################### /** * Assignement operator. I can't see how this would be very useful but * it is provided for safety and completeness. This function will * preform a copy of the give Netxx::Stream object via the Netxx::Stream * copy constructor. * * @param other The other Netxx::Stream to copy from. * @author Peter Jones **/ //#################################################################### Stream& operator= (const Stream &other); //#################################################################### /** * Exchange connection information with another Netxx::Stream. This is * similar to std::swap(). * * @param other The other Netxx::Stream object to swap with. * @author Peter Jones **/ //#################################################################### void swap (Stream &other); //#################################################################### /** * Netxx::Stream destructor. Close the connection with the peer if there * is one. * * @author Peter Jones **/ //#################################################################### ~Stream (void); //#################################################################### /** * Read data from the connected peer and place then in the given buffer. * If an error occures this function will throw an exception. If a * timeout occures (only if you set a timeout) then -1 is returned. * * It is possible for this function to return -1 if you did not set a * timeout. This would happen if you had set the socket for this * connection to non-blocking via the Netxx::SockOpt class. * * @param buffer The buffer to store the read bytes into. * @param length The size of the given buffer. * @return Greater than 0: The number of bytes read from the peer and placed into your buffer. * @return 0: The peer closed the connection. * @return -1: A timeout occured. * @see Netxx::SockOpt * @author Peter Jones **/ //#################################################################### signed_size_type read (void *buffer, size_type length); //#################################################################### /** * Write data from the given buffer to the connected peer. If an error * occures this function will throw an exception. If a timeout occures * (only if you set a timeout) then -1 is returned. * * It is possible for this function to return -1 if you did not set a * timeout. This would happen if you had set the socket for this * connection to non-blocking via the Netxx::SockOpt class. * * @param buffer The buffer to take the data from and send to the peer. * @param length The amount of data to use from the buffer. * @return Greater than 0: The number of bytes that were sent to the peer. * @return 0: The peer closed the connection. * @return -1: A timeout occured. * @see Netxx::SockOpt * @author Peter Jones **/ //#################################################################### signed_size_type write (const void *buffer, size_type length); //#################################################################### /** * Close the connection to the peer. Once the connection is closed you * should not preform any other operations on this object. This function * is normally called from the destructor. * * @author Peter Jones **/ //#################################################################### void close (void); //#################################################################### /** * Return the socket file descriptor used for the peer connection. This * is useful for calls to the Netxx::SockOpt class, as well as others. * * @return The socket file descriptor being used by this object. * @author Peter Jones **/ //#################################################################### socket_type get_socketfd (void) const; //#################################################################### /** * Get information about how this Stream should be probed from the * Netxx::Probe class. * * @return A Netxx::ProbeInfo object. * @author Peter Jones **/ //#################################################################### const ProbeInfo* get_probe_info (void) const; private: struct pimpl; pimpl *pimpl_; }; // end Netxx::Stream class } // end Netxx namespace #endif Netxx-0.3.2/include/Netxx/DatagramServer.h0000644000175000017500000001477512173720353017726 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the definition of the Netxx::DatagramServer class. **/ #ifndef _Netxx_DatagramServer_h_ #define _Netxx_DatagramServer_h_ // Netxx includes #include #include #include #include // standard includes #include namespace Netxx { // forward declarations class ProbeInfo; class ServerBase; /** * The Netxx::DatagramServer class is used for datagram based servers. **/ class DatagramServer { public: /// type returned from receive_datagram typedef std::pair receive_type; //#################################################################### /** * Create a datagram server that will bind to all local addresses on the * given port number. The timeout will be used when you make a call to * receive_datagram. * * @param port The local port number to bind to. * @param timeout The timeout to use for server operations. * @author Peter Jones **/ //#################################################################### explicit DatagramServer (port_type port, const Timeout &timeout=Timeout()); //#################################################################### /** * Create a datagram server that will bind to all addresses given in the * Address class. * * @param addr The list of addresses to bind to. * @param timeout The timeout to use for server operations. * @author Peter Jones **/ //#################################################################### explicit DatagramServer (const Address &addr, const Timeout &timeout=Timeout()); //#################################################################### /** * Clean up after the DatagramServer. * * @author Peter Jones **/ //#################################################################### ~DatagramServer (void); //#################################################################### /** * Try to receive an incoming datagram. If you have set a timeout and no * datagram is pending within that timeout this memeber function will * return with -1 for the bytes read and an invalid Peer class. If no * timeout was given, this function will block until a datagram arives. * Once a datagram has been received it will be stored inside the given * buffer and the amount of stored data along with data about the sender * of the datagram will returned in a std::pair. * * @param buffer The buffer where the datagram data can be placed. * @param length The size of the buffer. * @return A std::pair where first is the bytes placed in the buffer and * second is the Peer class for the sending peer. * @author Peter Jones **/ //#################################################################### receive_type receive (void *buffer, size_type length); //#################################################################### /** * Send a datagram to the given peer. The send will occur using the * datagram server socket. This may not be thread safe. Some protocols * will send a datagram to the client using the server socket with * information about another port to start talking on. It is up to the * developer to decide which approach is better, to respond using the * server datagram socket or create a new datagram server or client for * the communication. * * Using the same DatagramServer object in multiple threads of execution * and then calling the send() member function will probably cause you * problems and a debugging nightmare. * * @param peer The peer to send the datagram to. * @param buffer The buffer that contains the datagram to send. * @param length The size of the datagram to send. * @return The number of bytes sent or -1 in the case of a timeout. **/ //#################################################################### signed_size_type send (const Peer &peer, const void *buffer, size_type length); //#################################################################### /** * Get information about how this DatagramServer should be probed from * the Netxx::Probe class. * * @return A Netxx::ProbeInfo object. * @author Peter Jones **/ //#################################################################### const ProbeInfo* get_probe_info (void) const; friend bool operator== (const DatagramServer &ds, socket_type fd); friend bool operator== (socket_type fd, const DatagramServer &ds); friend bool operator!= (const DatagramServer &ds, socket_type fd); friend bool operator!= (socket_type fd, const DatagramServer &ds); private: ServerBase *pimpl_; DatagramServer (const DatagramServer&); DatagramServer& operator= (const DatagramServer&); }; // end Netxx::DatagramServer class } // end Netxx namespace #endif Netxx-0.3.2/include/Netxx/Netbuf.h0000644000175000017500000001601512173720353016227 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the definition of the Netxx:Netbuf template class. **/ #ifndef _Netxx_Netbuf_h_ #define _Netxx_Netbuf_h_ // Netxx includes #include // standard includes #include #include #include namespace Netxx { const std::streamsize PUTBACK_SIZE = 4; } namespace Netxx { /** * The Netxx::Netbuf template class is a IOStreams streambuf. After you * create an instance of a Netxx::Netbuf class you can pass a pointer to it * to a std::iostream, std::ostream or std::istream class. Then you can do * basic IOStreams operations on it. * * This streambuf is buffered so you should call std::flush to make sure it * sends the data that you inserted. **/ template > class Netbuf : public std::basic_streambuf { public: /// int type typedef typename std::basic_streambuf::int_type int_type; /// char type typedef typename std::basic_streambuf::char_type char_type; //#################################################################### /** * Construct a Netxx::Netbuf object and link it to the given StreamBase * object. The StreamBase object will be used for reading and writing to * the Netbuf (std::streambuf) object. * * @param stream The StreamBase object to use for reading and writing. * @author Peter Jones **/ //#################################################################### explicit Netbuf (StreamBase &stream); //#################################################################### /** * Netxx::Netbuf class destructor. * * @author Peter Jones **/ //#################################################################### ~Netbuf (void); protected: // TODO streamsize xsputn (const char_type *s, streamsize n); int_type overflow (int_type c=traits::eof()); int sync (void); int_type underflow (void); int_type pbackfail (int_type c); private: StreamBase &stream_; charT putbuf_[bufsize]; charT getbuf_[bufsize]; int buffer_out (void); int buffer_in (void); Netbuf (const Netbuf&); Netbuf& operator= (const Netbuf&); }; // end Netxx::Netbuf class //############################################################################# template Netbuf::Netbuf (StreamBase &stream) : stream_(stream) { setp(putbuf_, putbuf_ + bufsize); setg(getbuf_+PUTBACK_SIZE, getbuf_+PUTBACK_SIZE, getbuf_+PUTBACK_SIZE); } //############################################################################# template Netbuf::~Netbuf (void) { sync(); } //############################################################################# template typename Netbuf::int_type Netbuf::overflow (int_type c) { if (buffer_out() < 0) { return traits::eof(); } else if (!traits::eq_int_type(c, traits::eof())) { return sputc(c); } else { return traits::not_eof(c); } } //############################################################################# template int Netbuf::sync (void) { return buffer_out(); } //############################################################################# template int Netbuf::buffer_out (void) { int length = this->pptr() - this->pbase(); int rc = stream_.write(putbuf_, length); this->pbump(-length); return rc; } //############################################################################# template typename Netbuf::int_type Netbuf::underflow (void) { if (this->gptr() < this->egptr()) return traits::to_int_type(*this->gptr()); if (buffer_in() < 0) return traits::eof(); else return traits::to_int_type(*this->gptr()); } //############################################################################# template typename Netbuf::int_type Netbuf::pbackfail(int_type c) { if (this->gptr() != this->eback()) { this->gbump(-1); if (!traits::eq_int_type(c, traits::eof())) { *(this->gptr()) = traits::to_char_type(c); } return traits::not_eof(c); } else { return traits::eof(); } } //############################################################################# template int Netbuf::buffer_in (void) { std::streamsize number_putbacks = std::min(this->gptr() - this->eback(), PUTBACK_SIZE); std::memcpy(getbuf_ + (PUTBACK_SIZE - number_putbacks) * sizeof(char_type), this->gptr() - number_putbacks * sizeof(char_type), number_putbacks * sizeof(char_type)); int rc = stream_.read(getbuf_ + PUTBACK_SIZE * sizeof(char_type), bufsize - PUTBACK_SIZE); if (rc <= 0) { this->setg(0, 0, 0); return -1; } else { this->setg(getbuf_ + PUTBACK_SIZE - number_putbacks, getbuf_ + PUTBACK_SIZE, getbuf_ + PUTBACK_SIZE + rc); return rc; } } } // end Netxx namespace #endif Netxx-0.3.2/examples/0000755000175000017500000000000012173720372013716 5ustar danieldanielNetxx-0.3.2/examples/.cvsignore0000644000175000017500000000023312173720353015713 0ustar danieldanielMakefile http_get multi_server streambuf_echo_client tcp_daytime_client tcp_echo_client tcp_echo_server udp_daytime_client udp_echo_client udp_echo_server Netxx-0.3.2/examples/tls_echo_server.cxx0000644000175000017500000000620012173720353017625 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /* * Similar to the tcp_echo_server.cxx example, this example shows you how to * write a TLS server. It will echo back everything that a TLS echo client * sends it. */ // Netxx Includes #include #include #include #include #include #include #include // Standard Includes #include #include int main (int argc, char *argv[]) { try { Netxx::Address address; Netxx::Timeout timeout(60); Netxx::TLS::Context context; context.load_private_key("example.pem"); context.load_cert_chain("example.pem"); if (argc > 1) { for (int i=1; i 0) client_stream.write(buffer, bytes_read); std::cout << argv[0] << ": client disconnected from server" << std::endl; } } catch (std::exception &e) { std::cerr << argv[0] << ": " << e.what() << std::endl; return 1; } return 0; } Netxx-0.3.2/examples/http_get.cxx0000644000175000017500000000566612173720353016274 0ustar danieldaniel/* * Copyright (C) 2001-2003 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 #include #include #include // Standard Includes #include #include 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; } Netxx-0.3.2/examples/README0000644000175000017500000000046112173720353014576 0ustar danieldanielNetxx 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! Netxx-0.3.2/examples/udp_echo_client.cxx0000644000175000017500000000566612173720353017602 0ustar danieldaniel/* * Copyright (C) 2001-2003 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 UDP API. It will read a line from * standard input and send a datagram to a server. The UDP echo server will * then send back the same data in another datagram. This example uses * "connected" UDP sockets. */ // Netxx Includes #include #include #include // Standard Includes #include #include #include int main (int argc, char *argv[]) { if (argc != 2) { std::cout << "Usage: " << argv[0] << "
\n"; return 1; } try { Netxx::Datagram datagram(argv[1], 7, Netxx::Timeout(5)); Netxx::signed_size_type bytes_received; char read_buffer[4096]; std::string write_buffer; while (std::getline(std::cin, write_buffer)) { if (write_buffer.size() > sizeof(read_buffer)) { std::cerr << argv[0] << ": can't send a line longer than "; std::cerr << sizeof(read_buffer) << " bytes\n"; return 1; } write_buffer += '\n'; datagram.write(write_buffer.c_str(), write_buffer.size()); if ( (bytes_received = datagram.read(read_buffer, sizeof(read_buffer))) > 0) { std::cout.write(read_buffer, bytes_received); } else { std::cerr << argv[0] << ": datagram receive timeout\n"; } } } catch (std::exception &e) { std::cerr << argv[0] << ": " << e.what() << "\n"; return 1; } return 0; } Netxx-0.3.2/examples/tcp_daytime_client.cxx0000644000175000017500000000447512173720353020313 0ustar danieldaniel/* * Copyright (C) 2001-2003 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 #include // Standard Includes #include #include int main (int argc, char *argv[]) { if (argc != 2) { std::cout << "Usage: " << argv[0] << "
\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; } Netxx-0.3.2/examples/http_https_server.cxx0000644000175000017500000001276712173720353020245 0ustar danieldaniel/* * Copyright (C) 2001-2003 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 #include #include #include #include #include #include #include // standard includes #include #include #include #include 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 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 = "

" "Hello from Netxx

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

Not Found

\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; } Netxx-0.3.2/examples/udp_daytime_client.cxx0000644000175000017500000000516412173720353020311 0ustar danieldaniel/* * Copyright (C) 2001-2003 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 UDP API. It sends a blank datagram * to a daytime server. The daytime server should then send back a datagram * with the current date and time. */ // Netxx Includes #include #include #include #include // Standard Includes #include #include #include int main (int argc, char *argv[]) { if (argc != 2) { std::cerr << "Usage: " << argv[0] << " address\n"; return 1; } try { Netxx::Address addr(argv[1], 13); Netxx::Datagram datagram(Netxx::Timeout(10)); char buffer[1024]; // send blank datagram to make server respond datagram.send(*addr.begin(), 0, 0); Netxx::Datagram::receive_type response = datagram.receive(buffer, sizeof(buffer)); if (response.first == -1) { std::cerr << argv[0] << ": timeout waiting for server\n"; return 1; } std::cout.write(buffer, response.first); } catch (std::exception &e) { std::cerr << argv[0] << ": " << e.what() << "\n"; return 1; } return 0; } Netxx-0.3.2/examples/streambuf_echo_client.cxx0000644000175000017500000000511712173720353020771 0ustar danieldaniel/* * Copyright (C) 2001-2003 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 #include #include // Standard Includes #include #include #include int main (int argc, char *argv[]) { if (argc != 2) { std::cout << "Usage: " << argv[0] << "
\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; } Netxx-0.3.2/examples/multi_server.cxx0000644000175000017500000001431412173720353017164 0ustar danieldaniel/* * Copyright (C) 2001-2003 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 #include #include #include #include #include // Standard Includes #include #include #include 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; } Netxx-0.3.2/examples/https_get.cxx0000644000175000017500000000736312173720353016453 0ustar danieldaniel/* * Copyright (C) 2001-2003 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 #include #include #include // Standard Includes #include #include 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; } Netxx-0.3.2/examples/tls_echo_client.cxx0000644000175000017500000000551412173720353017604 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /* * Like the tcp_echo_client.cxx example, this one shows you how to write a * TCP echo client. The difference is that this one will use the TLS API so * that you can talk with a secure echo server! */ // Netxx Includes #include #include #include #include // Standard Includes #include #include #include int main (int argc, char *argv[]) { if (argc != 2) { std::cout << "Usage: " << argv[0] << " \n"; return 1; } try { Netxx::TLS::Context context; Netxx::TLS::Stream client(context, argv[1], 7, Netxx::Timeout(10)); Netxx::signed_size_type bytes_read; 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'; client.write(write_buffer.c_str(), write_buffer.size()); bytes_read = client.read(read_buffer, sizeof(read_buffer)); std::cout.write(read_buffer, bytes_read); } } catch (std::exception &e) { std::cerr << argv[0] << ": " << e.what() << std::endl; return 1; } return 0; } Netxx-0.3.2/examples/Makefile0000644000175000017500000000352212173720353015357 0ustar danieldaniel# This Makefile automaticly generated by /home/jason/head/contrib/Netxx-0.3.2/tools/mkmf # File created on: Fri Apr 15 12:01:20 2005 # DO NOT EDIT THIS FILE! CXX=c++ CXXFLAGS=-O2 -I/home/jason/head/contrib/Netxx-0.3.2/include AR=ar ARFLAGS=rc SAR=c++ SARFLAGS= LD=c++ LDFLAGS='/home/jason/head/contrib/Netxx-0.3.2/src/libNetxx.a' POST_LDFLAGS= OBJECTS=http_get.o multi_server.o streambuf_echo_client.o tcp_daytime_client.o tcp_echo_client.o tcp_echo_server.o udp_daytime_client.o udp_echo_client.o udp_echo_server.o TARGETS=http_get multi_server streambuf_echo_client tcp_daytime_client tcp_echo_client tcp_echo_server udp_daytime_client udp_echo_client udp_echo_server all: $(TARGETS) http_get: http_get.o $(LD) -o http_get http_get.o $(LDFLAGS) $(POST_LDFLAGS) multi_server: multi_server.o $(LD) -o multi_server multi_server.o $(LDFLAGS) $(POST_LDFLAGS) streambuf_echo_client: streambuf_echo_client.o $(LD) -o streambuf_echo_client streambuf_echo_client.o $(LDFLAGS) $(POST_LDFLAGS) tcp_daytime_client: tcp_daytime_client.o $(LD) -o tcp_daytime_client tcp_daytime_client.o $(LDFLAGS) $(POST_LDFLAGS) tcp_echo_client: tcp_echo_client.o $(LD) -o tcp_echo_client tcp_echo_client.o $(LDFLAGS) $(POST_LDFLAGS) tcp_echo_server: tcp_echo_server.o $(LD) -o tcp_echo_server tcp_echo_server.o $(LDFLAGS) $(POST_LDFLAGS) udp_daytime_client: udp_daytime_client.o $(LD) -o udp_daytime_client udp_daytime_client.o $(LDFLAGS) $(POST_LDFLAGS) udp_echo_client: udp_echo_client.o $(LD) -o udp_echo_client udp_echo_client.o $(LDFLAGS) $(POST_LDFLAGS) udp_echo_server: udp_echo_server.o $(LD) -o udp_echo_server udp_echo_server.o $(LDFLAGS) $(POST_LDFLAGS) clean: - rm -f $(OBJECTS) $(TARGETS) *.core core realclean: clean - rm -f Makefile .SUFFIXES: .cxx .SUFFIXES: .obj .cxx.o: $(CXX) $(CXXFLAGS) -c $< .cxx.obj: $(CXX) $(CXXFLAGS) -c $< Netxx-0.3.2/examples/udp_echo_server.cxx0000644000175000017500000000521612173720353017621 0ustar danieldaniel/* * Copyright (C) 2001-2003 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 write a UDP server. It will send back any * datagrams that it receives. */ // Netxx Includes #include #include #include #include // Standard Includes #include #include int main (int argc, char *argv[]) { try { Netxx::Address addr; if (argc > 1) { for (int i=1; i #include #include #include #include #include // Standard Includes #include #include int main (int argc, char *argv[]) { try { Netxx::Address address; Netxx::Timeout timeout(10); if (argc > 1) { for (int i=1; i 0) client_stream.write(buffer, bytes_read); std::cout << argv[0] << ": client disconnected from server" << std::endl; } } catch (std::exception &e) { std::cerr << argv[0] << ": " << e.what() << std::endl; return 1; } return 0; } Netxx-0.3.2/examples/tcp_echo_client.cxx0000644000175000017500000000555512173720353017575 0ustar danieldaniel/* * Copyright (C) 2001-2003 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 #include // Standard Includes #include #include #include int main (int argc, char *argv[]) { if (argc != 2) { std::cout << "Usage: " << argv[0] << " \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; } Netxx-0.3.2/build/0000755000175000017500000000000012173720372013177 5ustar danieldanielNetxx-0.3.2/build/macosx/0000755000175000017500000000000012173720372014471 5ustar danieldanielNetxx-0.3.2/build/macosx/configure.sh0000644000175000017500000000062312173720353017006 0ustar danieldaniel#!/bin/sh TLS="" IPV6="" DARWIN_VERSION=`uname -v | awk '{print $4}' | sed 's/\..*//'` if [ "x$DARWIN_VERSION" = "x5" ]; then IPV6="--disable-ipv6" fi if [ -r /usr/include/openssl/ssl.h ]; then TLS="--enable-tls --openssl-prefix=/usr" elif [ -r /sw/include/openssl/ssl.h ]; then TLS="--enable-tls --openssl-prefix=/sw" fi ./configure.pl --disable-shared --disable-streambuf $TLS $IPV6 $* Netxx-0.3.2/build/msvc/0000755000175000017500000000000012173720372014147 5ustar danieldanielNetxx-0.3.2/build/msvc/tcp_echo_client.dsp0000644000175000017500000001037012173720353020001 0ustar danieldaniel# Microsoft Developer Studio Project File - Name="tcp_echo_client" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Console Application" 0x0103 CFG=tcp_echo_client - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "tcp_echo_client.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "tcp_echo_client.mak" CFG="tcp_echo_client - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "tcp_echo_client - Win32 Release" (based on "Win32 (x86) Console Application") !MESSAGE "tcp_echo_client - Win32 Debug" (based on "Win32 (x86) Console Application") !MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "" # PROP Scc_LocalPath "" CPP=cl.exe RSC=rc.exe !IF "$(CFG)" == "tcp_echo_client - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "Release" # PROP Intermediate_Dir "Release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # ADD CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /I../../include /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Release/Netxx.lib /nologo /subsystem:console /machine:I386 !ELSEIF "$(CFG)" == "tcp_echo_client - Win32 Debug" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 1 # PROP Output_Dir "Debug" # PROP Intermediate_Dir "Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c # ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /I../../include /GZ /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Debug\Netxx.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept !ENDIF # Begin Target # Name "tcp_echo_client - Win32 Release" # Name "tcp_echo_client - Win32 Debug" # Begin Group "Source Files" # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File SOURCE=..\..\examples\tcp_echo_client.cxx # End Source File # End Group # End Target # End Project Netxx-0.3.2/build/msvc/udp_echo_client.dsp0000644000175000017500000001037012173720353020003 0ustar danieldaniel# Microsoft Developer Studio Project File - Name="udp_echo_client" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Console Application" 0x0103 CFG=udp_echo_client - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "udp_echo_client.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "udp_echo_client.mak" CFG="udp_echo_client - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "udp_echo_client - Win32 Release" (based on "Win32 (x86) Console Application") !MESSAGE "udp_echo_client - Win32 Debug" (based on "Win32 (x86) Console Application") !MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "" # PROP Scc_LocalPath "" CPP=cl.exe RSC=rc.exe !IF "$(CFG)" == "udp_echo_client - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "Release" # PROP Intermediate_Dir "Release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # ADD CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /I../../include /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Release/Netxx.lib /nologo /subsystem:console /machine:I386 !ELSEIF "$(CFG)" == "udp_echo_client - Win32 Debug" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 1 # PROP Output_Dir "Debug" # PROP Intermediate_Dir "Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c # ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /I../../include /GZ /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Debug\Netxx.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept !ENDIF # Begin Target # Name "udp_echo_client - Win32 Release" # Name "udp_echo_client - Win32 Debug" # Begin Group "Source Files" # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File SOURCE=..\..\examples\udp_echo_client.cxx # End Source File # End Group # End Target # End Project Netxx-0.3.2/build/msvc/http_get.dsp0000644000175000017500000001024412173720353016475 0ustar danieldaniel# Microsoft Developer Studio Project File - Name="http_get" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Console Application" 0x0103 CFG=http_get - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "http_get.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "http_get.mak" CFG="http_get - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "http_get - Win32 Release" (based on "Win32 (x86) Console Application") !MESSAGE "http_get - Win32 Debug" (based on "Win32 (x86) Console Application") !MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "" # PROP Scc_LocalPath "" CPP=cl.exe RSC=rc.exe !IF "$(CFG)" == "http_get - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "Release" # PROP Intermediate_Dir "Release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # ADD CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /I../../include /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Release/Netxx.lib /nologo /subsystem:console /machine:I386 !ELSEIF "$(CFG)" == "http_get - Win32 Debug" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 1 # PROP Output_Dir "Debug" # PROP Intermediate_Dir "Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c # ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /I../../include /GZ /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Debug\Netxx.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept !ENDIF # Begin Target # Name "http_get - Win32 Release" # Name "http_get - Win32 Debug" # Begin Group "Source Files" # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File SOURCE=..\..\examples\http_get.cxx # End Source File # End Group # End Target # End Project Netxx-0.3.2/build/msvc/udp_daytime_client.dsp0000644000175000017500000001043412173720353020522 0ustar danieldaniel# Microsoft Developer Studio Project File - Name="udp_daytime_client" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Console Application" 0x0103 CFG=udp_daytime_client - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "udp_daytime_client.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "udp_daytime_client.mak" CFG="udp_daytime_client - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "udp_daytime_client - Win32 Release" (based on "Win32 (x86) Console Application") !MESSAGE "udp_daytime_client - Win32 Debug" (based on "Win32 (x86) Console Application") !MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "" # PROP Scc_LocalPath "" CPP=cl.exe RSC=rc.exe !IF "$(CFG)" == "udp_daytime_client - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "Release" # PROP Intermediate_Dir "Release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # ADD CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /I../../include /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Release/Netxx.lib /nologo /subsystem:console /machine:I386 !ELSEIF "$(CFG)" == "udp_daytime_client - Win32 Debug" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 1 # PROP Output_Dir "Debug" # PROP Intermediate_Dir "Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c # ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /I../../include /GZ /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Debug\Netxx.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept !ENDIF # Begin Target # Name "udp_daytime_client - Win32 Release" # Name "udp_daytime_client - Win32 Debug" # Begin Group "Source Files" # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File SOURCE=..\..\examples\udp_daytime_client.cxx # End Source File # End Group # End Target # End Project Netxx-0.3.2/build/msvc/Netxx.dsw0000644000175000017500000000422712173720353016000 0ustar danieldanielMicrosoft Developer Studio Workspace File, Format Version 6.00 # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! ############################################################################### Project: "Netxx"=".\Netxx.dsp" - Package Owner=<4> Package=<5> {{{ }}} Package=<4> {{{ }}} ############################################################################### Project: "http_get"=".\http_get.dsp" - Package Owner=<4> Package=<5> {{{ }}} Package=<4> {{{ }}} ############################################################################### Project: "tcp_echo_client"=".\tcp_echo_client.dsp" - Package Owner=<4> Package=<5> {{{ }}} Package=<4> {{{ Begin Project Dependency Project_Dep_Name Netxx End Project Dependency }}} ############################################################################### Project: "tcp_echo_server"=".\tcp_echo_server.dsp" - Package Owner=<4> Package=<5> {{{ }}} Package=<4> {{{ Begin Project Dependency Project_Dep_Name Netxx End Project Dependency }}} ############################################################################### Project: "udp_daytime_client"=".\udp_daytime_client.dsp" - Package Owner=<4> Package=<5> {{{ }}} Package=<4> {{{ Begin Project Dependency Project_Dep_Name Netxx End Project Dependency }}} ############################################################################### Project: "udp_echo_client"=".\udp_echo_client.dsp" - Package Owner=<4> Package=<5> {{{ }}} Package=<4> {{{ Begin Project Dependency Project_Dep_Name Netxx End Project Dependency }}} ############################################################################### Project: "udp_echo_server"=".\udp_echo_server.dsp" - Package Owner=<4> Package=<5> {{{ }}} Package=<4> {{{ Begin Project Dependency Project_Dep_Name Netxx End Project Dependency }}} ############################################################################### Global: Package=<5> {{{ }}} Package=<3> {{{ }}} ############################################################################### Netxx-0.3.2/build/msvc/tcp_echo_server.dsp0000644000175000017500000001037012173720353020031 0ustar danieldaniel# Microsoft Developer Studio Project File - Name="tcp_echo_server" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Console Application" 0x0103 CFG=tcp_echo_server - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "tcp_echo_server.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "tcp_echo_server.mak" CFG="tcp_echo_server - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "tcp_echo_server - Win32 Release" (based on "Win32 (x86) Console Application") !MESSAGE "tcp_echo_server - Win32 Debug" (based on "Win32 (x86) Console Application") !MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "" # PROP Scc_LocalPath "" CPP=cl.exe RSC=rc.exe !IF "$(CFG)" == "tcp_echo_server - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "Release" # PROP Intermediate_Dir "Release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # ADD CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /I../../include /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Release/Netxx.lib /nologo /subsystem:console /machine:I386 !ELSEIF "$(CFG)" == "tcp_echo_server - Win32 Debug" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 1 # PROP Output_Dir "Debug" # PROP Intermediate_Dir "Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c # ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /I../../include /GZ /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Debug\Netxx.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept !ENDIF # Begin Target # Name "tcp_echo_server - Win32 Release" # Name "tcp_echo_server - Win32 Debug" # Begin Group "Source Files" # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File SOURCE=..\..\examples\tcp_echo_server.cxx # End Source File # End Group # End Target # End Project Netxx-0.3.2/build/msvc/udp_echo_server.dsp0000644000175000017500000001037012173720353020033 0ustar danieldaniel# Microsoft Developer Studio Project File - Name="udp_echo_server" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Console Application" 0x0103 CFG=udp_echo_server - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "udp_echo_server.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "udp_echo_server.mak" CFG="udp_echo_server - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "udp_echo_server - Win32 Release" (based on "Win32 (x86) Console Application") !MESSAGE "udp_echo_server - Win32 Debug" (based on "Win32 (x86) Console Application") !MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "" # PROP Scc_LocalPath "" CPP=cl.exe RSC=rc.exe !IF "$(CFG)" == "udp_echo_server - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "Release" # PROP Intermediate_Dir "Release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # ADD CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /I../../include /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Release/Netxx.lib /nologo /subsystem:console /machine:I386 !ELSEIF "$(CFG)" == "udp_echo_server - Win32 Debug" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 1 # PROP Output_Dir "Debug" # PROP Intermediate_Dir "Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c # ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /I../../include /GZ /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Debug\Netxx.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept !ENDIF # Begin Target # Name "udp_echo_server - Win32 Release" # Name "udp_echo_server - Win32 Debug" # Begin Group "Source Files" # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File SOURCE=..\..\examples\udp_echo_server.cxx # End Source File # End Group # End Target # End Project Netxx-0.3.2/build/msvc/tcp_daytime_client.dsp0000644000175000017500000001042312173720353020516 0ustar danieldaniel# Microsoft Developer Studio Project File - Name="tcp_daytime_client" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Console Application" 0x0103 CFG=tcp_daytime_client - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "tcp_daytime_client.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "tcp_daytime_client.mak" CFG="tcp_daytime_client - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "tcp_daytime_client - Win32 Release" (based on "Win32 (x86) Console Application") !MESSAGE "tcp_daytime_client - Win32 Debug" (based on "Win32 (x86) Console Application") !MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "" # PROP Scc_LocalPath "" CPP=cl.exe RSC=rc.exe !IF "$(CFG)" == "tcp_daytime_client - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "Release" # PROP Intermediate_Dir "Release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /I../../include /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Release/Netxx.lib /nologo /subsystem:console /machine:I386 !ELSEIF "$(CFG)" == "tcp_daytime_client - Win32 Debug" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 1 # PROP Output_Dir "Debug" # PROP Intermediate_Dir "Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c # ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /I../../include /GZ /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Debug\Netxx.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept !ENDIF # Begin Target # Name "tcp_daytime_client - Win32 Release" # Name "tcp_daytime_client - Win32 Debug" # Begin Group "Source Files" # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File SOURCE=..\..\examples\tcp_daytime_client.cxx # End Source File # End Group # End Target # End Project Netxx-0.3.2/build/msvc/Netxx.dsp0000644000175000017500000001226012173720353015765 0ustar danieldaniel# Microsoft Developer Studio Project File - Name="Netxx" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Static Library" 0x0104 CFG=Netxx - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "Netxx.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "Netxx.mak" CFG="Netxx - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "Netxx - Win32 Release" (based on "Win32 (x86) Static Library") !MESSAGE "Netxx - Win32 Debug" (based on "Win32 (x86) Static Library") !MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "" # PROP Scc_LocalPath "" CPP=cl.exe RSC=rc.exe !IF "$(CFG)" == "Netxx - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "Release" # PROP Intermediate_Dir "Release" # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c # ADD CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /D "NETXX_NO_INET6" /YX /FD /I../../include /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LIB32=link.exe -lib # ADD BASE LIB32 /nologo # ADD LIB32 /nologo !ELSEIF "$(CFG)" == "Netxx - Win32 Debug" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 1 # PROP Output_Dir "Debug" # PROP Intermediate_Dir "Debug" # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c # ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /D "NETXX_NO_INET6" /YX /FD /GZ /I../../include /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LIB32=link.exe -lib # ADD BASE LIB32 /nologo # ADD LIB32 /nologo !ENDIF # Begin Target # Name "Netxx - Win32 Release" # Name "Netxx - Win32 Debug" # Begin Group "Source Files" # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File SOURCE=..\..\src\Accept.cxx # End Source File # Begin Source File SOURCE=..\..\src\Address.cxx # End Source File # Begin Source File SOURCE=..\..\src\Datagram.cxx # End Source File # Begin Source File SOURCE=..\..\src\DatagramServer.cxx # End Source File # Begin Source File SOURCE=..\..\src\inet6.cxx # End Source File # Begin Source File SOURCE=..\..\src\OSError.cxx # End Source File # Begin Source File SOURCE=..\..\src\Peer.cxx # End Source File # Begin Source File SOURCE=..\..\src\Probe.cxx # End Source File # Begin Source File SOURCE=..\..\src\Probe_select.cxx # End Source File # Begin Source File SOURCE=..\..\src\RecvFrom.cxx # End Source File # Begin Source File SOURCE=..\..\src\Resolve_gethostbyname.cxx # End Source File # Begin Source File SOURCE=..\..\src\Resolve_getservbyname.cxx # End Source File # Begin Source File SOURCE=..\..\src\ServerBase.cxx # End Source File # Begin Source File SOURCE=..\..\src\SockAddr.cxx # End Source File # Begin Source File SOURCE=..\..\src\Socket.cxx # End Source File # Begin Source File SOURCE=..\..\src\SockOpt.cxx # End Source File # Begin Source File SOURCE=..\..\src\Stream.cxx # End Source File # Begin Source File SOURCE=..\..\src\StreamBase.cxx # End Source File # Begin Source File SOURCE=..\..\src\StreamServer.cxx # End Source File # End Group # Begin Group "Header Files" # PROP Default_Filter "h;hpp;hxx;hm;inl" # Begin Source File SOURCE=..\..\include\Netxx\Address.h # End Source File # Begin Source File SOURCE=..\..\include\Netxx\Datagram.h # End Source File # Begin Source File SOURCE=..\..\include\Netxx\DatagramServer.h # End Source File # Begin Source File SOURCE=..\..\include\Netxx\Netbuf.h # End Source File # Begin Source File SOURCE=..\..\include\Netxx\Peer.h # End Source File # Begin Source File SOURCE=..\..\include\Netxx\Probe.h # End Source File # Begin Source File SOURCE=..\..\include\Netxx\ProbeInfo.h # End Source File # Begin Source File SOURCE=..\..\include\Netxx\SockOpt.h # End Source File # Begin Source File SOURCE=..\..\include\Netxx\Stream.h # End Source File # Begin Source File SOURCE=..\..\include\Netxx\StreamBase.h # End Source File # Begin Source File SOURCE=..\..\include\Netxx\StreamServer.h # End Source File # Begin Source File SOURCE=..\..\include\Netxx\Timeout.h # End Source File # Begin Source File SOURCE=..\..\include\Netxx\Types.h # End Source File # End Group # End Target # End Project Netxx-0.3.2/build/msvc/multi_server.dsp0000644000175000017500000001031312173720353017374 0ustar danieldaniel# Microsoft Developer Studio Project File - Name="multi_server" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Console Application" 0x0103 CFG=multi_server - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "multi_server.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "multi_server.mak" CFG="multi_server - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "multi_server - Win32 Release" (based on "Win32 (x86) Console Application") !MESSAGE "multi_server - Win32 Debug" (based on "Win32 (x86) Console Application") !MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "" # PROP Scc_LocalPath "" CPP=cl.exe RSC=rc.exe !IF "$(CFG)" == "multi_server - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "Release" # PROP Intermediate_Dir "Release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /I../../include /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Release/Netxx.lib /nologo /subsystem:console /machine:I386 !ELSEIF "$(CFG)" == "multi_server - Win32 Debug" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 1 # PROP Output_Dir "Debug" # PROP Intermediate_Dir "Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c # ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /I../../include /GZ /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Debug\Netxx.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept !ENDIF # Begin Target # Name "multi_server - Win32 Release" # Name "multi_server - Win32 Debug" # Begin Group "Source Files" # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File SOURCE=..\..\examples\multi_server.cxx # End Source File # End Group # End Target # End Project Netxx-0.3.2/README0000644000175000017500000000306612173720353012764 0ustar danieldaniel--------------------------------------------------------------------------- Netxx --------------------------------------------------------------------------- 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. Features: * Very clean API with total abstraction from any operating system calls. No networking or operating system headers are used in the Netxx header files. * 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. * Includes support for TLS/SSL (via OpenSSL), IPv6 and Local/Unix Domain Sockets (on operating systems that support them). * Cross-platform support. Netxx currently supports most flavors of Unix, Windows and MacOS X. * An IOStreams streambuf is provided so you can treat network connections just like a std::iostream. * Berkeley style license so you can do whatever you want with Netxx, including commercial use. For more information about Netxx please go to: http://pmade.org/pjones/software/netxx/ Netxx-0.3.2/tools/0000755000175000017500000000000012173720372013240 5ustar danieldanielNetxx-0.3.2/tools/cxxflags0000755000175000017500000003237512173720353015016 0ustar danieldaniel#! /usr/bin/perl ###################################################################### # Copyright (C) 2001-2002 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. ################################################################################ # # cxxflags (Helper script to get compiler flags) # Peter J Jones (pjones@pmade.org) # # This file is part of cxxtools (http://pmade.org/pjones/software/cxxtools/) # ################################################################################ # # Includes # ################################################################################ use strict; use Getopt::Long; ################################################################################ # # Constants # ################################################################################ use constant DATE => 'Sat Aug 18 12:09:00 2001'; use constant ID => '$Id: cxxflags,v 1.1 2003/08/12 06:28:53 jason Exp $'; ################################################################################ # # Global Variables # ################################################################################ use vars qw($VERSION); $VERSION = '0.0.1'; my %clo; my %flags = ( 'getid' => '', 'debug' => '', 'depend' => '', 'pic' => '', 'optimize' => '', 'ar' => '', 'arflags' => '', 'arextra' => '', 'sar' => '', 'sarflags' => '', 'warn' => '', 'general' => '', 'object-ext' => '', 'static-ext' => '', 'shared-ext' => '', 'static-pre' => '', 'shared-pre' => '', 'shared-mjr' => '', 'exec-ext' => '', 'mkexec' => '', 'mkstatic' => '', 'mkshared' => '', 'linker' => '', 'linkwith' => '', 'mtcompile' => '', 'mtlink' => '', ); ################################################################################ # # Code Start # ################################################################################ GetOptions( \%clo, 'help|h!', 'cxx=s', 'getid!', 'setid=s', 'arflags|A!', 'ar|a!', 'arextra', 'sar!', 'sarflags!', 'debug!', 'depend|d!', 'exec-extension!', 'general!', 'linker!', 'linkwith=s@', 'mkexec=s', 'mkstatic=s', 'mkshared=s', 'mkshared-name=s', 'major=i', 'object-extension!', 'optimize|O!', 'pic|p!', 'static-lib-extension!', 'shared-lib-extension!', 'static-lib-prefix!', 'shared-lib-prefix!', 'warn!', 'mtcompile!', 'mtlink!', ) or usage(); $clo{'help'} and usage(); sub usage { print "Usage: $0 [options]\n", <&1`; } if ($output =~ /gcc/) { my $linker = 'gnu'; # default for now if ($^O =~ /solaris/i) { if ($clo{'setid'}) { if ($clo{'setid'} eq 'gcc-sun') { $linker = 'sun'; } } else { $output = `$clo{'cxx'} -Wl,-v 2>&1`; if ($output =~ /\[-h\s+name\]/ and $output =~ /\[-G\]/) { $linker = 'sun'; } } } elsif ($^O =~ /darwin/i) { $linker = 'mach'; } $flags{'debug'} = "-g"; $flags{'depend'} = '-M'; $flags{'optimize'} = '-O2'; $flags{'ar'} = $ENV{'AR'} || 'ar'; $flags{'arflags'} = $ENV{'ARFLAGS'} || 'rc'; $flags{'sar'} = $clo{'cxx'}; $flags{'sarflags'} = $ENV{'LDFLAGS'} || ''; $flags{'warn'} = '-Wall -W -Wcast-align -Wwrite-strings'; $flags{'object-ext'} = '.o'; $flags{'static-ext'} = '.a'; $flags{'shared-ext'} = '.so'; $flags{'static-pre'} = "lib"; $flags{'shared-pre'} = "lib"; $flags{'linker'} = $clo{'cxx'}; $flags{'mkexec'} = "-o $clo{'mkexec'}" if $clo{'mkexec'}; $flags{'mkstatic'} = $clo{'mkstatic'} if $clo{'mkstatic'}; if ($clo{'mkshared'} or $clo{'mkshared-name'}) { $flags{'shared-mjr'} = "lib$clo{'mkshared-name'}.so.$clo{'major'}" if $clo{'mkshared-name'}; if ($clo{'mkshared'}) { if ($linker eq 'gnu') { $flags{'mkshared'} = "-shared -o $clo{'mkshared'} -Wl,-soname,$clo{'mkshared'}.$clo{'major'}"; } elsif ($linker eq 'sun') { $flags{'mkshared'} = "-o $clo{'mkshared'} -Wl,-G,-h,$clo{'mkshared'}.$clo{'major'}"; } elsif ($linker eq 'mach') { $flags{'mkshared'} = "-o $clo{'mkshared'} -dynamiclib -compatibility_version $clo{'major'} -current_version $clo{'major'}"; } else { print STDERR "$0: your linker is not supported.\n"; print STDERR "$0: you might want to install the GNU linker.\n"; } } } foreach (@{$clo{'linkwith'}}) { my ($path, $lib) = split(/,/, $_, 2); if ($lib) { $lib =~ s/^lib//; $flags{'linkwith'} .= "-L$path -l$lib "; } else { $path =~ s/^lib//; $flags{'linkwith'} .= "-l$path"; } } if ($^O =~ /freebsd/i) { $flags{'mtlink'} .= " -pthread"; $flags{'arextra'}.= "ranlib"; } elsif ($^O =~ /darwin/i) { $flags{'pic'} = ''; $flags{'shared.ext'} = '.dylib'; $flags{'exec-ext'} = ''; $flags{'arextra'} = "ranlib"; } elsif ($^O =~ /cygwin/i) { $flags{'pic'} = ''; } else { $flags{'mtlink'} .= " -lpthread"; $flags{'pic'} = '-fpic -shared'; } $flags{'getid'} = "gcc-$linker"; return; } ################################################################################ # Microsoft Visual C++ (cl.exe) if ($clo{'setid'} && $clo{'setid'} =~ /^microsoft/) { $output = 'Microsoft'; } else { $output = `$clo{'cxx'} -verbose=version 2>&1`; } if ($output =~ /Microsoft/) { $flags{'debug'} = '/Od /Gz /Zi'; $flags{'debug'} .= '/GA' if ($clo{'mkstatic'}); $flags{'debug'} .= '/GD' if ($clo{'mkshared'}); $flags{'depend'} = ''; $flags{'pic'} = ''; $flags{'optimize'} = '/O2 /GB'; $flags{'ar'} = $clo{'cxx'}; $flags{'ar'} =~ s/^(.*)([\/\\]).*$/$1$2lib.exe/; # $flags{'arflags'} = '-xar -o'; $flags{'sar'} = $flags{'ar'}; $flags{'sarflags'} = "/SL"; $flags{'sarflags'} .= 'd' if ($flags{'debug'}); $flags{'warn'} = '/W3'; $flags{'object-ext'} = '.obj'; $flags{'static-ext'} = '.lib'; $flags{'shared-ext'} = '.dll'; $flags{'static-pre'} = ''; $flags{'shared-pre'} = ''; $flags{'mkexec'} = "/o $clo{'mkexec'}" if $clo{'mkexec'}; $flags{'mkstatic'} = "$clo{'mkstatic'}" if $clo{'mkstatic'}; # Figure out linker name $flags{'linker'} = $clo{'cxx'}; $flags{'linker'} =~ s/^(.*)([\/\\]).*$/$1$2link.exe/; $flags{'mtcompile'} .= '/MT'; $flags{'mtcompile'} .= 'd' if ($flags{'debug'}); $flags{'mtlink'} .= '/MT'; $flags{'mtlink'} .= 'd' if ($flags{'debug'}); } ################################################################################ # sun forte if ($clo{'setid'} && $clo{'setid'} =~ /^sun/) { $output = 'Sun'; } else { $output = `$clo{'cxx'} -verbose=version 2>&1`; } if ($output =~ /Sun/) { $flags{'debug'} = "-g"; $flags{'depend'} = '-xM'; $flags{'pic'} = '-Kpic'; $flags{'optimize'} = '-s -xlibmil -xlibmopt -xO2'; $flags{'ar'} = $clo{'cxx'}; $flags{'arflags'} = '-xar -o'; $flags{'sar'} = $clo{'cxx'}; $flags{'sarflags'} = $ENV{'LDFLAGS'} || ''; $flags{'warn'} = '+w'; $flags{'object-ext'} = '.o'; $flags{'static-ext'} = '.a'; $flags{'shared-ext'} = '.so'; $flags{'static-pre'} = 'lib'; $flags{'shared-pre'} = 'lib'; $flags{'mkexec'} = "-o $clo{'mkexec'}" if $clo{'mkexec'}; $flags{'mkstatic'} = "$clo{'mkstatic'}" if $clo{'mkstatic'}; $flags{'linker'} = $clo{'cxx'}; $flags{'mtcompile'} .= " -mt"; $flags{'mtlink'} .= " -mt"; foreach (@{$clo{'linkwith'}}) { my ($path, $lib) = split(/,/, $_, 2); if ($lib) { $lib =~ s/^lib//; $flags{'linkwith'} .= "-L$path -l$lib "; } else { $path =~ s/^lib//; $flags{'linkwith'} .= "-l$path"; } } if ($clo{'mkshared'} or $clo{'mkshared-name'}) { $flags{'mkshared'} = "-G -o $clo{'mkshared'} -h $clo{'mkshared'}.$clo{'major'}" if $clo{'mkshared'}; $flags{'shared-mjr'} = "lib$clo{'mkshared-name'}.so.$clo{'major'}" if $clo{'mkshared-name'}; } $flags{'getid'} = 'sun-sun'; return; } print STDERR "$0: unknown complier $clo{'cxx'}\n"; exit 1; } Netxx-0.3.2/tools/mkrelease.sh0000755000175000017500000000262412173720353015552 0ustar danieldaniel#! /bin/sh PROJECT=Netxx VERSION_FILE=docs/VERSION VERSION=`head -1 $VERSION_FILE | perl -pe 's/\s+.*$//'` CVSTAG=`head -1 $VERSION_FILE | perl -pe 's/^[\d.]+\s+\d+\s+([^\s]+).*$/$1/'` DESTDIR="$PROJECT-$VERSION" DOCBOOK_XSL=$HOME/develop/xslt-tools/stylesheets/docbook2html.xsl README_XSL=$HOME/develop/project-xslt/stylesheets/readme.xsl W3M="w3m -cols 76 -dump" XSLT="xsltproc" echo "===> Making $PROJECT release (Version == $VERSION) (CVSTAG == $CVSTAG)" if [ ! -r $DOCBOOK_XSL ] ; then echo "missing $DOCBOOK_XSL" exit 1 fi if [ ! -r $README_XSL ] ; then echo "missing $README_XSL" exit 1 fi # checkout the correct tag/branch from CVS cvs -q checkout -r $CVSTAG -d $DESTDIR $PROJECT if [ ! -d $DESTDIR ] ; then echo "cvs checkout failed" exit 1 fi # remove the CVS directories find $DESTDIR -name CVS -type d | xargs rm -rf # create the README, INSTALL and like files TMPFILE=tmp.html ( cd $DESTDIR $XSLT $README_XSL docs/project/project.xml > $TMPFILE $W3M $TMPFILE > README $XSLT $DOCBOOK_XSL docs/manual/get_started.xml > $TMPFILE $W3M $TMPFILE > INSTALL $XSLT $DOCBOOK_XSL docs/manual/credits.xml > $TMPFILE $W3M $TMPFILE > docs/CREDITS $XSLT $DOCBOOK_XSL docs/manual/todo.xml > $TMPFILE $W3M $TMPFILE > docs/TODO rm $TMPFILE ) # create a tarball tar czvf ${DESTDIR}.tar.gz $DESTDIR # remove the directory that CVS created rm -rf $DESTDIR Netxx-0.3.2/tools/genconfig0000755000175000017500000001247012173720353015130 0ustar danieldaniel#! /usr/bin/perl ###################################################################### # Copyright (C) 2001-2003 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. ################################################################################ # # genconfig (generate a *-config script) # Peter J Jones (pjones@pmade.org) # # This file is part of cxxtools (http://pmade.org/pjones/software/cxxtools/) # ################################################################################ # # Includes # ################################################################################ use strict; use Getopt::Long; ################################################################################ # # Constants # ################################################################################ use constant DATE => 'Tue Jan 15 16:14:25 PST 2002'; use constant ID => '$Id: genconfig,v 1.1 2003/08/12 06:28:53 jason Exp $'; ################################################################################ # # Global Variables # ################################################################################ my %clo; my $now = localtime; ################################################################################ # # Code Start # ################################################################################ GetOptions( \%clo, 'help|h!', 'output|o=s', 'version=s', 'libs=s', 'cxxflags=s', 'name=s', 'desc=s', 'pkgconfig=s', 'prefix=s', 'bindir=s', 'libdir=s', 'incdir=s', ) || usage(); $clo{'help'} && usage(); sub usage { print "Usage: $0 [options]\n", <$clo{'output'}")) { print STDERR "$0: can't open file $clo{'output'}: $!\n"; exit 1; } select(OUT); $clo{'version'} ||= '0.1'; $clo{'libs'} ||= ''; $clo{'cxxflags'} ||= ''; $clo{'name'} ||= ''; $clo{'desc'} ||= ''; $clo{'pkgconfig'} ||= ''; $clo{'prefix'} ||= '/usr/local'; $clo{'bindir'} ||= "$clo{'prefix'}/bin"; $clo{'libdir'} ||= "$clo{'prefix'}/lib"; $clo{'incdir'} ||= "$clo{'prefix'}/include"; ($clo{'outfile'} = $clo{'output'}) =~ s/^.*\///; s/\^/-/g foreach ($clo{'cxxflags'}, $clo{'libs'}); print <$clo{'pkgconfig'}")) { die $clo{'pkgconfig'}; } select(PC); print < 'Tue May 8 22:21:39 2001'; use constant ID => '$Id: mkmf,v 1.1 2003/08/12 06:28:53 jason Exp $'; ################################################################################ # # Global Variables # ################################################################################ my %clo; my $object_extension; my $static_lib_extension; my $shared_lib_extension; my $static_lib_prefix; my $shared_lib_prefix; my $exec_extension; my $depend_flag; my ($ar, $arflags, $arextra); my ($sar, $sarflags); my @objects; my $rmf = "rm -f"; my $source_ext_re = qr{\.(cxx|cc|cpp|c|c\+\+)$}; my $dirsep = '/'; if ($^O =~ /mswin/i) { $dirsep = '\\'; } if ($^O =~ /mswin/i) { $rmf = "del /F /Q"; } ################################################################################ # # Code Start # ################################################################################ GetOptions( \%clo, 'help|h!', 'cxxflags=s', 'setid=s', 'developer!', 'include=s@', 'linkwith=s@', 'slinkwith=s@', 'many-exec!', 'one-exec=s', 'output|o=s', 'quiet!', 'static-lib=s', 'shared-lib=s', 'wrapper!', 'major=i', 'install=s', 'test-cmds=s', 'with-test:s', 'append=s@', 'clean-target=s@', 'clean-file=s@', 'fake-header=s@', 'mt!', ) or usage(); $clo{'help'} && usage(); $clo{'linkwith'} ||= []; $clo{'include'} ||= []; $clo{'append'} ||= []; $clo{'clean-target'} ||= []; $clo{'clean-file'} ||= []; $clo{'fake-header'} ||= []; sub usage { print "Usage: $0 \n", <$clo{'output'}") || die "$0: can't create $clo{'output'}: $!"; print MF "# This Makefile automaticly generated by $0\n"; print MF "# File created on: ", scalar localtime, "\n"; print MF "# DO NOT EDIT THIS FILE!\n\n"; if (!$clo{'wrapper'}) { print MF "CXX=$ENV{CXX}\n"; print MF "CXXFLAGS=$ENV{CXXFLAGS}\n"; print MF "AR=$ar\n"; print MF "ARFLAGS=$arflags\n"; print MF "SAR=$sar\n"; print MF "SARFLAGS=$sarflags\n"; print MF "LD=$ENV{LD}\n"; print MF "LDFLAGS=$ENV{LDFLAGS}\n"; print MF "POST_LDFLAGS=$ENV{POST_LDFLAGS}\n"; print MF "OBJECTS=", join(' ', @objects), "\n"; } if (!$clo{'quiet'}) { print '+', '-' x 70, "\n"; print "| -*- Compiler Settings -*-\n"; print "|\n"; print "| CXX = $ENV{CXX}\n"; print "| CXXFLAGS = $ENV{CXXFLAGS}\n"; print "| AR = $ar\n"; print "| ARFLAGS = $arflags\n"; print "| SAR = $sar\n"; print "| SARFLAGS = $sarflags\n"; print "| LD = $ENV{LD}\n"; print "| LDFLAGS = $ENV{LDFLAGS}\n"; print '+', '-' x 70, "\n"; } if ($clo{'one-exec'}) { my $target = $clo{'one-exec'} . $exec_extension; my $mkexec; chomp($mkexec = `$^X $clo{'cxxflags'} --mkexec $target`); print MF "TARGETS=$target\n"; print MF "\n"; print MF "all: \$(TARGETS)\n"; print MF "\n"; print MF "$target: \$(OBJECTS)\n"; print MF "\t\$(LD) $mkexec \$(OBJECTS) \$(LDFLAGS) \$(POST_LDFLAGS)\n"; } elsif ($clo{'many-exec'}) { my $x; my @targets = map{ ($x=$_) =~ s/$source_ext_re/$exec_extension/i; clean($x); $x } @ARGV; print MF "TARGETS=", join(' ', @targets), "\n"; print MF "\n"; print MF "all: \$(TARGETS)\n"; print MF "\n"; foreach my $src (@ARGV) { my $exec = $src; $exec =~ s/$source_ext_re/$exec_extension/i; my $obj = $src; $obj =~ s/$source_ext_re/$object_extension/i; my $mkexec; chomp($mkexec = `$^X $clo{'cxxflags'} --mkexec $exec`); print MF "$exec: $obj\n"; print MF "\t\$(LD) $mkexec $obj \$(LDFLAGS) \$(POST_LDFLAGS)\n"; print MF "\n"; } } elsif ($clo{'static-lib'} or $clo{'shared-lib'}) { my $static_target = $static_lib_prefix . $clo{'static-lib'} . $static_lib_extension; my $shared_target = $shared_lib_prefix . $clo{'shared-lib'} . $shared_lib_extension; my $targets = ''; my $static_lib = `$^X $clo{'cxxflags'} --mkstatic $static_target`; chomp($static_lib); clean($static_lib); my $shared_lib = `$^X $clo{'cxxflags'} --major $clo{'major'} --mkshared $shared_target`; chomp($shared_lib); clean($shared_lib); $targets .= "$static_target " if $clo{'static-lib'}; $targets .= "$shared_target " if $clo{'shared-lib'}; print MF "TARGETS=$targets\n\n"; print MF "all: \$(TARGETS)\n\n"; if ($clo{'static-lib'}) { print MF "$static_target: \$(OBJECTS)\n"; print MF "\t\$(AR) \$(ARFLAGS) $static_lib \$(OBJECTS)\n"; print MF "\t$arextra $static_lib\n" if length($arextra); print MF "\n"; } if ($clo{'shared-lib'}) { print MF "$shared_target: \$(OBJECTS)\n"; print MF "\t\$(SAR) \$(SARFLAGS) $shared_lib \$(OBJECTS) \$(POST_LDFLAGS)\n"; print MF "\n"; } } elsif ($clo{'wrapper'}) { $clo{'with-test'} ||= join(',', @ARGV); print MF "\n"; print MF "all:\n"; foreach my $dir (@ARGV) { print MF "\t\@(cd $dir; \${MAKE})\n"; } print MF "\n"; print MF "clean: ", join(' ', @{$clo{'clean-target'}}), "\n"; print MF "\t- $rmf ", join(' ', @{$clo{'clean-file'}}), "\n" if @{$clo{'clean-file'}}; foreach my $dir (@ARGV) { print MF "\t\@(cd $dir; \${MAKE} clean)\n"; } print MF "\n"; print MF "realclean:\n"; foreach my $dir (@ARGV) { print MF "\t\@(cd $dir; \${MAKE} realclean)\n"; } print MF "\trm -f $clo{'output'}\n"; print MF "\n"; if ($clo{'with-test'}) { print MF "test:\n"; foreach my $dir (split(/\s*,\s*/, $clo{'with-test'})) { print MF "\t\@(cd $dir; \${MAKE} test)\n"; } print MF "\n"; } } if ($clo{'test-cmds'}) { print MF "test: \${TARGETS}\n"; print MF "\t$_\n" foreach (split(/\s*,\s*/, $clo{'test-cmds'})); print MF "\n"; } if ($depend_flag && $clo{'developer'} && !$clo{'wrapper'}) { my @to_unlink; foreach my $fake_header (@{$clo{'fake-header'}}) { if (-e $fake_header) { print STDERR "$0: $fake_header already exists\n"; next; } unless (open(FH, ">$fake_header")) { print STDERR "$0: could not create $fake_header: $!\n"; next; } print FH "/* fake header */\n"; close FH; push(@to_unlink, $fake_header); } foreach (@ARGV) { print " ===> Generating Dependancy Information for $_\n" unless $clo{'quiet'}; print MF `$ENV{'CXX'} $ENV{'CXXFLAGS'} $depend_flag $_`; print MF "\n"; } unlink(@to_unlink); } if (!$clo{'wrapper'}) { print MF "clean: ", join(' ', @{$clo{'clean-target'}}), "\n"; print MF "\t- $rmf \$(OBJECTS) \$(TARGETS) *.core core ", join(' ', @{$clo{'clean-file'}}), "\n"; print MF "\t- rm -rf SunWS_cache ir.out\n" if $^O eq 'solaris'; print MF "\n"; print MF "realclean: clean\n"; print MF "\t- $rmf $clo{'output'}\n"; print MF "\n"; print MF ".SUFFIXES: .cxx\n"; print MF ".SUFFIXES: .obj\n"; print MF "\n"; print MF ".cxx.o:\n"; if ($^O eq 'solaris' and $clo{'many-exec'}) { print MF "\t\@if test -d SunWS_cache ; then rm -rf SunWS_cache; fi\n"; } print MF "\t\$(CXX) \$(CXXFLAGS) -c \$<\n"; print MF "\n"; print MF ".cxx.obj:\n"; if ($^O eq 'solaris' and $clo{'many-exec'}) { print MF "\t\@if test -d SunWS_cache ; then rm -rf SunWS_cache; fi\n"; } print MF "\t\$(CXX) \$(CXXFLAGS) -c \$<\n"; print MF "\n"; } if ($clo{'install'} and $^O !~ /mswin/) { unless (open(SPEC, $clo{'install'})) { print STDERR "$0: can't open install spec file $clo{'install'}: $!\n"; exit 1; } my %vars = ( 'BINDIR' => '/usr/local/bin', 'INCLUDEDIR' => '/usr/local/include', 'LIBDIR' => '/usr/local/lib', 'MANDIR' => '/usr/local/share/man', ); my @binaries; my @pkgconfig; my @include_files; my @include_dirs; my @static_libraries; my @shared_libraries; my @man_pages; while () { chomp; s/^\s+//g; s/\s+$//g; next if /^$/ or /^#/; if (/^\w+\s*=/) { my ($key, $value) = split(/\s*=\s*/, $_, 2); $key = uc $key; if (!exists $vars{$key}) { print STDERR "$0: warning, $key is not a valid variable.\n"; print STDERR "$0: from $clo{'install'}:$.\n"; next; } $vars{$key} = $value; } elsif (/^include-dir\s+(\S+)\s+(\S+)$/) { if (! -d $1) { print STDERR "$0: warning, $1 is not a directory.\n"; print STDERR "$0: from $clo{'install'}:$.\n"; next; } push(@include_dirs, [$1, $2]); } elsif (/^include-files?\s+(\S+)$/) { my @files = glob($1); if (!@files) { print STDERR "$0: glob did not match any files\n"; print STDERR "$0: from $clo{'install'}:$.\n"; next; } my @names = map{s(^.*/)()} @files; for (my $i=0; $i<@files; ++$i) { push(@include_files, [$files[$i], $names[$i]]); } } elsif (/^binary\s+(\S+)$/) { my ($full, $base) = ($1, $1); $base =~ s(^.*/)(); push(@binaries, [$full, $base]); } elsif (/^pkgconfig\s+(\S+)$/) { push(@pkgconfig, $1); } elsif (/^(static-lib|shared-lib)\s+(\S+)\s+(\S+)\s*(\d+)?$/) { if (! -d $2) { print STDERR "$0: first option to $1 should be a directory.\n"; print STDERR "$0: $2 is not a directory.\n"; print STDERR "$0: from $clo{'install'}:$.\n"; next; } if ($1 eq 'static-lib') { push(@static_libraries, [$2, $3]); } elsif ($1 eq 'shared-lib') { my $major = $4 || 1; push(@shared_libraries, [$2, $3, $major]); } } elsif (/^man\s+(\d+)\s+(.+)$/) { if (! -e $2) { print STDERR "$0: man page not found: $2\n"; next; } push(@man_pages, [$1, $2]); } else { print STDERR "$0: I don't understand this line.\n"; print STDERR "$0: $_\n"; print STDERR "$0: from $clo{'install'}:$.\n"; next; } } if (@static_libraries or @shared_libraries or @binaries or @include_dirs or @include_files or @man_pages) { print MF "install: all\n"; print MF "\tmkdir -p $vars{'BINDIR'}\n" if @binaries; print MF "\tmkdir -p $vars{'INCLUDEDIR'}\n" if @include_files or @include_dirs; print MF "\tmkdir -p $vars{'LIBDIR'}\n" if @static_libraries or @shared_libraries; print MF "\tmkdir -p $vars{'LIBDIR'}/pkgconfig\n" if @pkgconfig; print MF "\tmkdir -p $vars{'MANDIR'}\n" if @man_pages; foreach my $binary (@binaries) { print MF "\tcp $binary->[0] $vars{'BINDIR'}/$binary->[1]\n"; print MF "\tchmod 755 $vars{'BINDIR'}/$binary->[1]\n"; } foreach my $pc (@pkgconfig) { print MF "\tcp $pc $vars{'LIBDIR'}/pkgconfig/$pc\n"; print MF "\tchmod 644 $vars{'LIBDIR'}/pkgconfig/$pc\n"; } foreach my $directory (@include_dirs) { print MF "\tmkdir -p $vars{'INCLUDEDIR'}/$directory->[1]\n"; print MF "\tcp -r $directory->[0]/* $vars{'INCLUDEDIR'}/$directory->[1]\n"; print MF "\tfind $vars{'INCLUDEDIR'}/$directory->[1] -type d | xargs chmod 755\n"; print MF "\tfind $vars{'INCLUDEDIR'}/$directory->[1] -type f | xargs chmod 644\n"; } foreach my $file (@include_files) { print MF "\tcp $file->[0] $vars{'INCLUDEDIR'}/$file->[1]\n"; print MF "\tchmod 644 $vars{'INCLUDEDIR'}/$file->[1]\n"; } foreach my $library (@static_libraries) { my $libname = "$static_lib_prefix$library->[1]$static_lib_extension"; print MF "\tcp $library->[0]/$libname $vars{'LIBDIR'}/$libname\n"; print MF "\tchmod 755 $vars{'LIBDIR'}/$libname\n"; } foreach my $library (@shared_libraries) { my $libname = "$shared_lib_prefix$library->[1]$shared_lib_extension"; my $major_name = `$^X $clo{'cxxflags'} --major $library->[2] --mkshared-name $library->[1]`; chomp($major_name); clean($major_name); print MF "\tcp $library->[0]/$libname $vars{'LIBDIR'}/$major_name\n"; print MF "\tchmod 755 $vars{'LIBDIR'}/$major_name\n"; print MF "\trm -f $vars{'LIBDIR'}/$libname\n"; print MF "\t(cd $vars{'LIBDIR'}; ln -s $major_name $libname)\n"; } foreach my $manpage (@man_pages) { my $file = basename($manpage->[1]); print MF "\tmkdir -p $vars{'MANDIR'}/man$manpage->[0]\n"; print MF "\tcp $manpage->[1] $vars{'MANDIR'}/man$manpage->[0]\n"; print MF "\tchmod 644 $vars{'MANDIR'}/man$manpage->[0]/$file\n"; } print MF "\n"; } } foreach my $append (@{$clo{'append'}}) { unless (open(AP, $append)) { print STDERR "$0: can't open '$append' so that I could append it to the Makefile\n"; exit 1; } print MF "\n"; while () { print MF; } close AP; } close MF; sub addflags { clean($_[0]); clean($_[1]); chomp($_[0] .= ' ' . $_[1]); clean($_[0]); } sub clean { $_[0] =~ s/^\s+//; $_[0] =~ s/\s+$//; } Netxx-0.3.2/configure.pl0000755000175000017500000003241212173720353014422 0ustar danieldaniel#! /usr/bin/perl ###################################################################### # Copyright (C) 2001-2003 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. ################################################################################ # # configure.pl (Configure the Netxx library) # Peter J Jones (pjones@pmade.org) # ################################################################################ # # Includes # ################################################################################ use strict; use Cwd qw(cwd chdir); use Getopt::Long; ################################################################################ # # Constants # ################################################################################ use constant DATE => 'Mon Sep 3 14:38:06 2001'; use constant ID => '$Id: configure.pl,v 1.1 2003/08/12 06:28:53 jason Exp $'; ################################################################################ # # Global Variables # ################################################################################ my $libname = "Netxx"; my $pwd = cwd; my $mkmf = "$pwd/tools/mkmf"; my $cxxflags = "$pwd/tools/cxxflags"; my $genconfig = "$pwd/tools/genconfig"; my $mkmf_flags = "--cxxflags='$cxxflags' --quiet"; my $genconfig_flags = ''; my $install_spec = "$pwd/docs/install.spec"; my $version_file = "$pwd/docs/VERSION"; my $lib_version; my $lib_major; my @linkwith; my ($openssl_include, $openssl_lib); my $build_test_dir = "tests/build"; my $build_test = "test.pl"; my $build_test_conf = "tests/build/test-out.cf"; my %test_data; my @base_source_files = qw( Accept.cxx Address.cxx Datagram.cxx DatagramServer.cxx OSError.cxx Peer.cxx Probe.cxx Probe_select.cxx RecvFrom.cxx Resolve_gethostbyname.cxx Resolve_getservbyname.cxx ServerBase.cxx SockAddr.cxx Socket.cxx SockOpt.cxx StreamBase.cxx Stream.cxx StreamServer.cxx ); my @tls_source_files = qw( TLS_Certificate.cxx TLS_Context.cxx TLS_Stream.cxx TLS_tls_pimpl.cxx ); my @example_files = qw( http_get.cxx multi_server.cxx streambuf_echo_client.cxx tcp_daytime_client.cxx tcp_echo_client.cxx tcp_echo_server.cxx udp_daytime_client.cxx udp_echo_client.cxx udp_echo_server.cxx ); my @tls_example_files = qw( http_https_server.cxx https_get.cxx tls_echo_client.cxx tls_echo_server.cxx ); my $inet6_code = "inet6.cxx"; my %clo; ################################################################################ # # Code Start # ################################################################################ $|++; print <; close VER; my @fields = split(/\s+/, $first_line); $lib_version = $fields[0]; $lib_major = $fields[1]; } ###################################################################### sub gen_src_makefile { unless (chdir('src')) { print "\n"; print STDERR "$0: can't chdir to src: $!\n"; exit 1; } my $extra_flags = "--static-lib $libname "; $extra_flags .= "--shared-lib $libname --major $lib_major " unless $clo{'disable-shared'}; if ($clo{'enable-tls'} && $openssl_include) { $extra_flags .= "--include $openssl_include "; } system("$^X $mkmf $mkmf_flags $extra_flags $source_files"); chdir($pwd); print "... "; } ###################################################################### sub gen_examples_makefile { return if $clo{'disable-examples'}; unless (chdir("examples")) { print "\n"; print STDERR "$0: can't chdir to examples: $!\n"; exit 1; } my $extra_flags = "--slinkwith '$pwd/src,$libname' "; foreach (@linkwith) { if (ref $_) { $extra_flags .= "--linkwith '$_->[0],$_->[1]' "; } else { $extra_flags .= "--linkwith '$_' "; } } if ($clo{'disable-streambuf'}) { @example_files = grep {$_ ne 'streambuf_echo_client.cxx'} @example_files; @tls_example_files = grep {$_ ne 'http_https_server.cxx'} @tls_example_files; } my $files = join(' ', @example_files); $files .= ' ' . join(' ', @tls_example_files) if $clo{'enable-tls'}; system("$^X $mkmf $mkmf_flags $extra_flags --many-exec $files"); chdir($pwd); print "... "; } ###################################################################### sub gen_top_makefile { unless (open(SPEC, ">$install_spec")) { print "\n"; print STDERR "$0: can't create $install_spec: $!\n"; exit 1; } print SPEC "LIBDIR=$clo{'libdir'}\n"; print SPEC "INCLUDEDIR=$clo{'incdir'}\n"; print SPEC "BINDIR=$clo{'bindir'}\n"; print SPEC "binary $libname-config\n"; print SPEC "include-dir $pwd/include/$libname $libname\n"; print SPEC "static-lib $pwd/src $libname\n"; print SPEC "shared-lib $pwd/src $libname $lib_major\n" unless $clo{'disable-shared'}; close SPEC; my @dirs = ('src'); push(@dirs, 'examples') unless ($clo{'disable-examples'}); system("$^X $mkmf $mkmf_flags --install $install_spec --wrapper @dirs"); unlink($install_spec); print "... "; } ###################################################################### sub run_build_tests { my $extra = $clo{'debug'} ? '--debug' : ''; print "Testing build enviornment ...\n"; chdir($build_test_dir) || die "$0: can't chdir to $build_test_dir: $!"; exit 1 if system("$^X $build_test $extra"); chdir($pwd); open(CF, $build_test_conf) or die "$0: can't open test output: $!\n"; while () { chomp; my ($key, $value) = split(/\s*=\s*/, $_, 2); $test_data{$key} = $value; } close(CF); if ((exists $test_data{'inet6'} && $test_data{'inet6'} eq 'no') || $clo{'disable-ipv6'}) { $source_files .= " $inet6_code"; $ENV{'CXXFLAGS'} .= " -DNETXX_NO_INET6"; } if (exists $test_data{'libsocket'} and $test_data{'libsocket'} eq 'yes') { push(@linkwith, "socket", "nsl"); } unlink($build_test_conf); } ###################################################################### sub setup_openssl { if ($clo{'enable-tls'}) { $build_test .= " --enable-tls"; if ($clo{'openssl-prefix'}) { $openssl_include = "$clo{'openssl-prefix'}/include"; $openssl_lib = "$clo{'openssl-prefix'}/lib"; } if ($clo{'openssl-include'}) { $openssl_include = $clo{'openssl-include'}; } if ($clo{'openssl-lib'}) { $openssl_lib = $clo{'openssl-lib'}; } if ($openssl_include) { $build_test .= " --openssl-include $openssl_include"; } if ($openssl_lib) { $build_test .= " --openssl-lib $openssl_lib"; push(@linkwith, "$openssl_lib,ssl", "$openssl_lib,crypto"); } else { push(@linkwith, "ssl", "crypto"); } $source_files .= ' ' . join(' ', @tls_source_files); } } ################################################################################ sub generate_config_script { my ($all_incs, $all_libs); my $version = $lib_version; if ($clo{'enable-tls'}) { $version .= "-TLS"; } if ($clo{'contrib'}) { $all_incs = "--include $pwd/include "; $all_libs = "--slinkwith $pwd/src,$libname "; foreach (@linkwith) { $all_libs .= "--linkwith $_ "; } } else { $all_incs = "-I$clo{'incdir'} "; $all_libs = `$^X $cxxflags --linkwith $clo{'libdir'},$libname`; foreach (@linkwith) { $all_libs .= `$^X $cxxflags --linkwith $_`; } } # clean and encode foreach ($all_incs, $all_libs) { s/^\s+//; s/\s+$//; s/\s+/ /g; s/-/^/g; } my $command = "$^X $genconfig --version $version --name $libname"; $command .= " --libs \"$all_libs\" --cxxflags \"$all_incs\""; $command .= " -o $libname-config"; print "Creating $libname-config script ... "; $_ = `$command 2>&1`; print "done\n"; } Netxx-0.3.2/src/0000755000175000017500000000000012173720372012667 5ustar danieldanielNetxx-0.3.2/src/DatagramServer.cxx0000644000175000017500000001145412173720353016326 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the implementation of the Netxx::DatagramServer class. **/ // common header #include "common.h" // Netxx includes #include "Netxx/DatagramServer.h" #include "Netxx/Datagram.h" #include "Netxx/Address.h" #include "Netxx/ProbeInfo.h" #include "ServerBase.h" #include "Socket.h" #include "RecvFrom.h" // standard includes #include #include // system includes #if defined(WIN32) # include #else # include # include # include # include # include # include #endif //#################################################################### Netxx::DatagramServer::DatagramServer (port_type port, const Timeout &timeout) { std::auto_ptr ap(pimpl_ = new ServerBase(timeout)); Address addr; addr.add_all_addresses(port); pimpl_->bind_to(addr, false); ap.release(); } //#################################################################### Netxx::DatagramServer::DatagramServer (const Address &addr, const Timeout &timeout) { std::auto_ptr ap(pimpl_ = new ServerBase(timeout)); pimpl_->bind_to(addr, false); ap.release(); } //#################################################################### Netxx::DatagramServer::~DatagramServer (void) { delete pimpl_; } //#################################################################### Netxx::DatagramServer::receive_type Netxx::DatagramServer::receive (void *buffer, size_type length) { Socket *ready_socket = pimpl_->get_readable_socket(); if (!ready_socket) return std::make_pair(static_cast(-1), Peer()); return call_recvfrom(*ready_socket, buffer, length); } //#################################################################### Netxx::signed_size_type Netxx::DatagramServer::send (const Peer &peer, const void *buffer, size_type length) { /* * We will create a Netxx::Datagram to do the dirty work for us. We take * care that the Datagram class does not close our server socket! We * give the Datagram peer.get_socketfd() because that is the server * socket that recevived the datagram. */ Datagram client(peer.get_socketfd(), pimpl_->get_timeout()); client.release(); return client.send(peer, buffer, length); } //#################################################################### const Netxx::ProbeInfo* Netxx::DatagramServer::get_probe_info (void) const { return pimpl_->get_probe_info(); } namespace Netxx { //#################################################################### bool operator== (const DatagramServer &ds, socket_type fd) { return ds.pimpl_->has_socket(fd); } //#################################################################### bool operator== (socket_type fd, const DatagramServer &ds) { return ds == fd; } //#################################################################### bool operator!= (const DatagramServer &ds, socket_type fd) { return !(ds == fd); } //#################################################################### bool operator!= (socket_type fd, const DatagramServer &ds) { return !(ds == fd); } //#################################################################### } // end Netxx namespace Netxx-0.3.2/src/TLS_Context_pimpl.h0000644000175000017500000000415012173720353016406 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the definition of the Netxx::TLS::Context::pimpl struct. **/ #ifndef _Netxx_TLS_Context_pimpl_h_ #define _Netxx_TLS_Context_pimpl_h_ // declaration include #include "Netxx/TLS/Context.h" // OpenSSL includes #include namespace Netxx { namespace TLS { struct context_pimpl { context_pimpl (Context *parent) : openssl_ctx_(0), parent_(parent) { } int proxy_password_callback(char *buffer, int size, bool rwflag); SSL_CTX *openssl_ctx_; Context *parent_; }; }} // end Netxx and TLS namespaces #endif Netxx-0.3.2/src/TLS_tls_pimpl.h0000644000175000017500000000515512173720353015572 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file defines the TLS::tls_pimpl struct. **/ #ifndef _Netxx_TLS_tls_pimpl_h_ #define _Netxx_TLS_tls_pimpl_h_ // Netxx includes #include "TLS_Context_pimpl.h" #include "Netxx/ProbeInfo.h" #include "Socket.h" #include "Netxx/TLS/Certificate.h" #include "TLS_cert_pimpl.h" // OpenSSL includes #include namespace Netxx { namespace TLS { struct tls_pimpl; class TLS_ProbeInfo : public Netxx::ProbeInfo { public: TLS_ProbeInfo (tls_pimpl *p) : pimpl_(p) {} bool needs_pending_check (void) const { return true; } pending_type check_pending (socket_type, pending_type pt) const; private: mutable tls_pimpl *pimpl_; }; struct tls_pimpl { tls_pimpl (context_pimpl *ctx_pimpl, int socketfd); tls_pimpl (context_pimpl *ctx_pimpl); ~tls_pimpl (void); void init (void); void error2exception (const char *prefix=0); bool server_; SSL *openssl_ssl_; context_pimpl *ctx_pimpl_; Socket socket_; TLS_ProbeInfo pi_; cert_impl peer_cert_; cert_impl issuer_cert_; }; }} // end Netxx and TLS namespaces #endif Netxx-0.3.2/src/SockAddr.cxx0000644000175000017500000001012312173720353015101 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the implementation of the Netxx::SockAddr class. **/ // common header #include "common.h" // Netxx includes #include "SockAddr.h" // system includes #if defined(WIN32) # include #else # include # include # include # include # include # include #endif // standard includes #include //#################################################################### Netxx::SockAddr::SockAddr (Socket::Type type, port_type port) : sa_(0), sa_size_(0) { switch (type) { case Socket::TCP: case Socket::UDP: setup(AF_INET, port); break; # ifndef NETXX_NO_INET6 case Socket::TCP6: case Socket::UDP6: setup(AF_INET6, port); break; # endif # ifndef WIN32 case Socket::LOCALSTREAM: case Socket::LOCALDGRAM: setup(AF_LOCAL, 0); break; # endif default: setup(AF_INET, port); break; } } //#################################################################### Netxx::SockAddr::SockAddr (int af_type, port_type port) : sa_(0), sa_size_(0) { setup(af_type, port); } //#################################################################### sockaddr* Netxx::SockAddr::get_sa (void) { return sa_; } //#################################################################### Netxx::size_type Netxx::SockAddr::get_sa_size (void) { return sa_size_; } //#################################################################### void Netxx::SockAddr::setup (int af_type, port_type port) { switch (af_type) { case AF_INET: std::memset(&(sa_union_.sa_in), 0, sizeof(sa_union_.sa_in)); sa_union_.sa_in.sin_family = AF_INET; if (port) sa_union_.sa_in.sin_port = htons(port); sa_size_ = sizeof(sa_union_.sa_in); sa_ = reinterpret_cast(&(sa_union_.sa_in)); break; # ifndef NETXX_NO_INET6 case AF_INET6: std::memset(&(sa_union_.sa_in6), 0, sizeof(sa_union_.sa_in6)); sa_union_.sa_in6.sin6_family = AF_INET6; if (port) sa_union_.sa_in6.sin6_port = htons(port); sa_size_ = sizeof(sa_union_.sa_in6); sa_ = reinterpret_cast(&(sa_union_.sa_in6)); break; # endif # ifndef WIN32 case AF_LOCAL: std::memset(&(sa_union_.sa_un), 0, sizeof(sa_union_.sa_un)); sa_union_.sa_un.sun_family = AF_LOCAL; sa_size_ = sizeof(sa_union_.sa_un); sa_ = reinterpret_cast(&(sa_union_.sa_un)); break; # endif default: throw Exception("Netxx bug: bad socket type given to Netxx:SockAddr"); } } Netxx-0.3.2/src/SockAddr.h0000644000175000017500000000531112173720353014531 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file defines the Netxx::SockAddr class. **/ #ifndef _Netxx_SockAddr_h_ #define _Netxx_SockAddr_h_ // Netxx includes #include "Socket.h" #include "Netxx/Types.h" // system includes #if defined(WIN32) # include #else # include # include # include # include # include # include #endif namespace Netxx { /** * The SockAddr class is a thin wrapper around the sockaddr_* structs. It is * mainly used to create and cleanup after these structs. **/ class SockAddr { public: explicit SockAddr (Socket::Type type, port_type port=0); explicit SockAddr (int af_type, port_type port=0); sockaddr* get_sa (void); size_type get_sa_size (void); void setup (int af_type, port_type port); private: union { sockaddr_in sa_in; # ifndef NETXX_NO_INET6 sockaddr_in6 sa_in6; # endif # ifndef WIN32 sockaddr_un sa_un; # endif } sa_union_; sockaddr *sa_; size_type sa_size_; SockAddr (const SockAddr &); SockAddr& operator= (const SockAddr &); }; // end Netxx::SockAddr class } // end Netxx namespace #endif Netxx-0.3.2/src/common.h0000644000175000017500000000333212173720353014330 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains common stuff needed by Netxx. **/ #ifndef _Netxx_common_h_ #define _Netxx_common_h_ #include "compat.h" #include "inet6.h" #endif Netxx-0.3.2/src/TLS_Stream.cxx0000644000175000017500000002275512173720353015402 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the implementation of the Netxx::TLS::Stream class. **/ // Netxx includes #include "Netxx/TLS/Stream.h" #include "TLS_tls_pimpl.h" #include "Netxx/TLS/Context.h" #include "Socket.h" #include "Netxx/SockOpt.h" // OpenSSL includes #include #include // standard includes #include //#################################################################### namespace { void handle_shutdown (Netxx::TLS::tls_pimpl *pimpl, bool dont_throw_exceptions); void handle_connect (Netxx::TLS::tls_pimpl *pimpl, const Netxx::Timeout &timeout); void handle_accept (Netxx::TLS::tls_pimpl *pimpl, const Netxx::Timeout &timeout); } //#################################################################### Netxx::TLS::Stream::Stream (Context &context, const Address &address, const Timeout &timeout) : StreamBase(timeout) { std::auto_ptr auto_pimpl(pimpl_ = new tls_pimpl(context.pimpl_)); make_connection(pimpl_->socket_, address); pimpl_->init(); handle_connect(pimpl_, get_timeout()); auto_pimpl.release(); } //#################################################################### Netxx::TLS::Stream::Stream (Context &context, const char *addr, port_type default_port, const Timeout &timeout) : StreamBase(timeout) { Address address(addr, default_port); std::auto_ptr auto_pimpl(pimpl_ = new tls_pimpl(context.pimpl_)); make_connection(pimpl_->socket_, address); pimpl_->init(); handle_connect(pimpl_, get_timeout()); auto_pimpl.release(); } //#################################################################### Netxx::TLS::Stream::Stream (Context &context, int socketfd, Mode mode, const Timeout &timeout) : StreamBase(timeout) { std::auto_ptr auto_pimpl(pimpl_ = new tls_pimpl(context.pimpl_, socketfd)); pimpl_->init(); switch (mode) { case mode_client: handle_connect(pimpl_, get_timeout()); break; case mode_server: pimpl_->server_ = true; handle_accept(pimpl_, get_timeout()); break; } auto_pimpl.release(); } //#################################################################### Netxx::TLS::Stream::~Stream (void) { handle_shutdown(pimpl_, true); delete pimpl_; } //#################################################################### void Netxx::TLS::Stream::close (void) { handle_shutdown(pimpl_, false); } //#################################################################### int Netxx::TLS::Stream::get_socketfd (void) const { return pimpl_->socket_.get_socketfd(); } //#################################################################### Netxx::signed_size_type Netxx::TLS::Stream::write (const void *buffer, size_type length) { if (!length) return 0; // older versions of OpenSSL used char* instead of void* const char *cbuffer = static_cast(buffer); signed_size_type rc; if (get_timeout() && !pimpl_->socket_.writable(get_timeout())) return -1; for (;;) { rc = SSL_write(pimpl_->openssl_ssl_, cbuffer, length); if (rc >= 0) return rc; switch (SSL_get_error(pimpl_->openssl_ssl_, rc)) { case SSL_ERROR_ZERO_RETURN: close(); return 0; case SSL_ERROR_WANT_WRITE: if (!pimpl_->socket_.writable(get_timeout())) return -1; break; case SSL_ERROR_WANT_READ: if (!pimpl_->socket_.readable(get_timeout())) return -1; break; default: pimpl_->error2exception("failed to write"); break; } } } //#################################################################### Netxx::signed_size_type Netxx::TLS::Stream::read (void *buffer, size_type length) { // older versions of OpenSSL used char* instead of void* char *cbuffer = static_cast(buffer); signed_size_type rc; if (get_timeout() && !SSL_pending(pimpl_->openssl_ssl_) && !pimpl_->socket_.readable(get_timeout())) return -1; for (;;) { rc = SSL_read(pimpl_->openssl_ssl_, cbuffer, length); if (rc >= 0) return rc; switch (SSL_get_error(pimpl_->openssl_ssl_, rc)) { case SSL_ERROR_ZERO_RETURN: close(); return 0; case SSL_ERROR_WANT_WRITE: if (!pimpl_->socket_.writable(get_timeout())) return -1; break; case SSL_ERROR_WANT_READ: if (!pimpl_->socket_.readable(get_timeout())) return -1; break; default: pimpl_->error2exception("failed to read"); break; } } } //#################################################################### const Netxx::TLS::Certificate& Netxx::TLS::Stream::get_peer_cert (void) const { X509 *cert; X509_NAME *subject; if ( (cert = SSL_get_peer_certificate(pimpl_->openssl_ssl_)) == 0 || ( subject = X509_get_subject_name(cert)) == 0) { cert = 0; subject = 0; } pimpl_->peer_cert_.set(cert, subject); return pimpl_->peer_cert_; } //#################################################################### const Netxx::TLS::Certificate& Netxx::TLS::Stream::get_issuer_cert (void) const { X509 *cert; X509_NAME *issuer; if ( (cert = SSL_get_peer_certificate(pimpl_->openssl_ssl_)) == 0 || (issuer = X509_get_issuer_name(cert)) == 0) { cert = 0; issuer = 0; } pimpl_->issuer_cert_.set(cert, issuer); return pimpl_->issuer_cert_; } //#################################################################### const Netxx::ProbeInfo* Netxx::TLS::Stream::get_probe_info (void) const { return &(pimpl_->pi_); } //#################################################################### namespace { //#################################################################### void handle_shutdown (Netxx::TLS::tls_pimpl *pimpl, bool dont_throw_exceptions) { if (!pimpl->socket_) return; /* * FIXME * * this code does not account for a non-blocking socket * * FIXME */ if (!pimpl->server_ || (SSL_get_shutdown(pimpl->openssl_ssl_) & SSL_RECEIVED_SHUTDOWN)) { if (SSL_shutdown(pimpl->openssl_ssl_) != 1 && !dont_throw_exceptions) { pimpl->error2exception("failed TLS shutdown"); } } else { SSL_clear(pimpl->openssl_ssl_); pimpl->socket_.close(); if (!dont_throw_exceptions) { throw Netxx::Exception("TLS connection shutdown failure"); } } pimpl->socket_.close(); } //#################################################################### void handle_connect (Netxx::TLS::tls_pimpl *pimpl, const Netxx::Timeout &timeout) { Netxx::SockOpt sockop(pimpl->socket_.get_socketfd()); if (timeout) sockop.set_non_blocking(); int rc; SSL_set_connect_state(pimpl->openssl_ssl_); for (;;) { rc = SSL_connect(pimpl->openssl_ssl_); if (rc > 0) return; switch (SSL_get_error(pimpl->openssl_ssl_, rc)) { case SSL_ERROR_WANT_READ: if (!pimpl->socket_.readable(timeout)) { throw Netxx::Exception("timeout during TLS connection handshake"); } continue; case SSL_ERROR_WANT_WRITE: if (!pimpl->socket_.writable(timeout)) { throw Netxx::Exception("timeout during TLS connection handshake"); } continue; default: pimpl->error2exception("failed TLS connection handshake"); break; } } } //#################################################################### void handle_accept (Netxx::TLS::tls_pimpl *pimpl, const Netxx::Timeout &timeout) { Netxx::SockOpt sockop(pimpl->socket_.get_socketfd()); if (timeout) sockop.set_non_blocking(); int rc; SSL_set_accept_state(pimpl->openssl_ssl_); for (;;) { rc = SSL_accept(pimpl->openssl_ssl_); if (rc == 1) return; switch (SSL_get_error(pimpl->openssl_ssl_, rc)) { case SSL_ERROR_WANT_READ: if (!pimpl->socket_.readable(timeout)) { throw Netxx::Exception("timeout during TLS accept handshake"); } continue; case SSL_ERROR_WANT_WRITE: if (!pimpl->socket_.writable(timeout)) { throw Netxx::Exception("timeout during TLS accept handshake"); } continue; default: pimpl->error2exception("failed TLS accept handshake"); break; } } } //#################################################################### } // end anonymous namespace Netxx-0.3.2/src/Datagram.cxx0000644000175000017500000002656412173720353015147 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the implementation of the Netxx::Datagram class. **/ // common header #include "common.h" // Netxx includes #include "Netxx/Datagram.h" #include "Netxx/Address.h" #include "Netxx/Peer.h" #include "Socket.h" #include "SockAddr.h" #include "RecvFrom.h" #include "OSError.h" // system includes #if defined (WIN32) # include #else # include # include # include # include # include # include # include #endif // standard includes #include #include #include #include namespace { void call_connect(Netxx::Socket &socket, const Netxx::Peer &peer, std::vector &files); void call_bind(Netxx::Socket &socket, std::vector &files); void get_tmp_filename (std::string &tmp_name); } //#################################################################### struct Netxx::Datagram::pimpl { pimpl (const Timeout &timeout) : timeout_(timeout) {} pimpl (const Timeout &timeout, socket_type socketfd) : timeout_(timeout), socket_(socketfd) {} ~pimpl (void) { # ifndef WIN32 if (!files_.empty()) { socket_.close(); std::vector::const_iterator i(files_.begin()), end(files_.end()); for (; i!=end; ++i) unlink(i->c_str()); } # endif } Timeout timeout_; Socket socket_; ProbeInfo pi_; std::vector files_; }; //#################################################################### Netxx::Datagram::Datagram (const Address &connect_to, const Timeout &timeout) { if (!connect_to.size()) throw Exception("no addresses to call connect for"); std::auto_ptr ap(pimpl_ = new pimpl(timeout)); call_connect(pimpl_->socket_, *connect_to.begin(), pimpl_->files_); pimpl_->pi_.add_socket(pimpl_->socket_.get_socketfd()); ap.release(); } //#################################################################### Netxx::Datagram::Datagram (const char *peer_name, port_type default_port, const Timeout &timeout) { Address connect_to(peer_name, default_port); std::auto_ptr ap(pimpl_ = new pimpl(timeout)); call_connect(pimpl_->socket_, *connect_to.begin(), pimpl_->files_); pimpl_->pi_.add_socket(pimpl_->socket_.get_socketfd()); ap.release(); } //#################################################################### Netxx::Datagram::Datagram (socket_type socketfd, const Timeout &timeout) { std::auto_ptr ap (pimpl_ = new pimpl(timeout, socketfd)); pimpl_->pi_.add_socket(pimpl_->socket_.get_socketfd()); ap.release(); } //#################################################################### Netxx::Datagram::Datagram (const Timeout &timeout) { std::auto_ptr ap (pimpl_ = new pimpl(timeout)); pimpl_->pi_.add_socket(pimpl_->socket_.get_socketfd()); ap.release(); } //#################################################################### Netxx::Datagram::~Datagram (void) { delete pimpl_; } //#################################################################### Netxx::signed_size_type Netxx::Datagram::send (const Peer &peer, const void *buffer, size_type length) { # if defined(WIN32) const char *buffer_ptr = static_cast(buffer); # else const void *buffer_ptr = buffer; # endif const sockaddr *sa = reinterpret_cast(peer.get_sa()); size_type sa_size = peer.get_sa_size(); bool correct_type = false; /* * make sure our socket is setup to handle this type of peer */ if (peer.get_socketfd() != -1 && peer.get_socketfd() == pimpl_->socket_.get_socketfd()) { // we have to be ready! correct_type = true; } else if (pimpl_->socket_.get_socketfd() >= 0) { Socket::Type stype = pimpl_->socket_.get_type(); switch (stype) { # ifndef WIN32 case Socket::LOCALDGRAM: correct_type = sa->sa_family == AF_LOCAL; break; # endif case Socket::UDP: correct_type = sa->sa_family == AF_INET; break; # ifndef NETXX_NO_INET6 case Socket::UDP6: correct_type = sa->sa_family == AF_INET6; break; # endif default: break; } } if (!correct_type) { Socket::Type stype; switch (sa->sa_family) { case AF_INET: stype = Socket::UDP; break; # ifndef NETXX_NO_INET6 case AF_INET6: stype = Socket::UDP6; break; # endif # ifndef WIN32 case AF_LOCAL: stype = Socket::LOCALDGRAM; break; # endif default: stype = Socket::UDP; } Socket tmp_socket(stype); pimpl_->socket_.swap(tmp_socket); call_bind(pimpl_->socket_, pimpl_->files_); } if (pimpl_->timeout_ && !pimpl_->socket_.writable(pimpl_->timeout_)) return -1; signed_size_type rc; if ( (rc = sendto(pimpl_->socket_.get_socketfd(), buffer_ptr, length, 0, sa, sa_size)) < 0) { std::string error("sendto(2) failure: "); error += strerror(get_last_error()); throw Exception(error); } return rc; } //#################################################################### Netxx::Datagram::receive_type Netxx::Datagram::receive (void *buffer, size_type length) { /* * if this is not a connected datagram, the socket might not be ready * yet. We can't receive a datagram because we don't know if it should * be a AF_INET, AF_INET6 or even a AF_LOCAL datagram. */ if (pimpl_->socket_.get_socketfd() < 0) throw Exception("can't receive datagram unless one is sent first"); if (pimpl_->timeout_ && !pimpl_->socket_.readable(pimpl_->timeout_)) return std::make_pair(-1, Peer()); return call_recvfrom(pimpl_->socket_, buffer, length); } //#################################################################### Netxx::signed_size_type Netxx::Datagram::write (const void *buffer, size_type length) { return pimpl_->socket_.write(buffer, length, pimpl_->timeout_); } //#################################################################### Netxx::signed_size_type Netxx::Datagram::read (void *buffer, size_type length) { return pimpl_->socket_.read(buffer, length, pimpl_->timeout_); } //#################################################################### void Netxx::Datagram::close (void) { pimpl_->socket_.close(); pimpl_->pi_.clear(); } //#################################################################### void Netxx::Datagram::release (void) { pimpl_->socket_.release(); } //#################################################################### const Netxx::ProbeInfo* Netxx::Datagram::get_probe_info (void) const { return &(pimpl_->pi_); } //#################################################################### namespace { //#################################################################### void call_connect (Netxx::Socket &socket, const Netxx::Peer &peer, std::vector &files) { const sockaddr *sa = reinterpret_cast(peer.get_sa()); Netxx::size_type sa_size = peer.get_sa_size(); Netxx::Socket::Type stype; switch (sa->sa_family) { case AF_INET: stype = Netxx::Socket::UDP; break; # ifndef NETXX_NO_INET6 case AF_INET6: stype = Netxx::Socket::UDP6; break; # endif # ifndef WIN32 case AF_LOCAL: stype = Netxx::Socket::LOCALDGRAM; break; # endif default: stype = Netxx::Socket::UDP; } Netxx::Socket tmp_socket(stype); socket.swap(tmp_socket); call_bind(socket, files); if (connect(socket.get_socketfd(), sa, sa_size) != 0) { std::string error("connect(2) failed: "); error += strerror(Netxx::get_last_error()); throw Netxx::Exception(error); } } //#################################################################### void call_bind (Netxx::Socket &socket, std::vector &files) { # ifndef WIN32 if (socket.get_type() == Netxx::Socket::LOCALDGRAM) { Netxx::SockAddr socket_addr(socket.get_type()); sockaddr_un *saun = reinterpret_cast(socket_addr.get_sa()); Netxx::size_type saun_size = socket_addr.get_sa_size(); std::string tmp_name; get_tmp_filename(tmp_name); files.push_back(tmp_name); if (tmp_name.size() >= sizeof(saun->sun_path)) throw Netxx::Exception("temp name is too large for sockaddr_un"); std::strcpy(saun->sun_path, tmp_name.c_str()); if (bind(socket.get_socketfd(), reinterpret_cast(saun), saun_size) != 0) { std::string error("bind(2) error: "); error += strerror(Netxx::get_last_error()); throw Netxx::Exception(error); } /* * This will make a local domain socket more like a real * socket since anyone with local file system access can * connect to it. This may be a bad thing in this case * though. More to come. */ chmod(saun->sun_path, 0666); } # endif } //#################################################################### void get_tmp_filename (std::string &tmp_name) { # ifndef WIN32 char buffer[] = "/tmp/Netxx_Domain_Socket.XXXXXXXXXXXXXXXXX"; int fd; if ( (fd = mkstemp(buffer)) < 0) { std::string error("can't create temporary file: "); error += strerror(Netxx::get_last_error()); throw Netxx::Exception(error); } /* * WARNING WARNING WARNING WARNING * * The following action could create a race condition. It may * not be that big of a deal in this case since when we call * bind(2) and it will fail if the file in sun_path already * exists. * * So, if we close and unlink the file, and then before we call * bind(2) someone creates a file with the same name, bind * should fail. * * It might just be better to use tmpnam(3) but then you have to * see the linker warning about tmpnam might be used in an * unsafe manner. I think what we have here should be good * enough. * * WARNING WARNING WARNING WARNING */ close(fd); unlink(buffer); tmp_name = buffer; # endif } //#################################################################### } // end anonymous namespace Netxx-0.3.2/src/Probe.cxx0000644000175000017500000001507712173720353014473 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the implementation of the Netxx::Probe class. **/ // common header #include "common.h" // Netxx includes #include #include #include #include "Probe_impl.h" // standard includes #include #include #include //#################################################################### namespace { typedef std::list > ready_return_type; typedef std::list > pi_type; Netxx::Probe::result_type find_ready_match (ready_return_type &q, Netxx::Probe::ready_type rt); } //#################################################################### struct Netxx::Probe::pimpl { ready_return_type ready_queue_; pi_type pilist_; Probe_impl probe_impl_; }; //#################################################################### Netxx::Probe::Probe (void) { pimpl_ = new pimpl; } //#################################################################### Netxx::Probe::Probe (const Probe &other) { std::auto_ptr ap(pimpl_ = new pimpl); pimpl_->ready_queue_ = other.pimpl_->ready_queue_; pimpl_->pilist_ = other.pimpl_->pilist_; pimpl_->probe_impl_ = other.pimpl_->probe_impl_; ap.release(); } //#################################################################### Netxx::Probe& Netxx::Probe::operator= (const Probe &other) { Probe tmp(other); swap(tmp); return *this; } //#################################################################### void Netxx::Probe::swap (Probe &other) { pimpl_->ready_queue_.swap(other.pimpl_->ready_queue_); pimpl_->pilist_.swap(other.pimpl_->pilist_); pimpl_->probe_impl_.swap(other.pimpl_->probe_impl_); } //#################################################################### Netxx::Probe::~Probe (void) { delete pimpl_; } //#################################################################### void Netxx::Probe::clear (void) { pimpl_->ready_queue_.clear(); pimpl_->pilist_.clear(); pimpl_->probe_impl_.clear(); } //#################################################################### std::pair Netxx::Probe::ready (const Timeout &timeout, ready_type rt) { result_type result; bool none_match=false; if (rt != ready_none && !pimpl_->ready_queue_.empty()) { result = find_ready_match(pimpl_->ready_queue_, rt); if (result.first != -1) return result; none_match = true; } if (pimpl_->ready_queue_.empty() || none_match) { pi_type::const_iterator p_it=pimpl_->pilist_.begin(), p_end=pimpl_->pilist_.end(); for (; p_it!=p_end; ++p_it) { ProbeInfo::pending_type result = p_it->second->check_pending(p_it->first, rt); if (result != ProbeInfo::pending_none) { pimpl_->ready_queue_.push_back(std::make_pair(p_it->first, static_cast(result))); } } Probe_impl::probe_type probe_result = pimpl_->probe_impl_.probe(timeout, rt); Probe_impl::probe_type::const_iterator pr_it=probe_result.begin(), pr_end=probe_result.end(); for (; pr_it!=pr_end; ++pr_it) { pimpl_->ready_queue_.push_back(*pr_it); } } if (!pimpl_->ready_queue_.empty()) { if (rt != ready_none) { result = find_ready_match(pimpl_->ready_queue_, rt); } else { result = pimpl_->ready_queue_.front(); pimpl_->ready_queue_.erase(pimpl_->ready_queue_.begin()); } return result; } result.first = -1; result.second = ready_none; return result; } //#################################################################### void Netxx::Probe::add_socket (socket_type socketfd, ready_type rt) { pimpl_->probe_impl_.add(socketfd, rt); } //#################################################################### void Netxx::Probe::add_socket (const ProbeInfo *pi, socket_type socketfd, ready_type rt) { pimpl_->pilist_.push_back(std::make_pair(socketfd, pi)); pimpl_->probe_impl_.add(socketfd, rt); } //#################################################################### void Netxx::Probe::remove_socket (socket_type socketfd) { pi_type::iterator i=pimpl_->pilist_.begin(), end=pimpl_->pilist_.end(); for (; i!=end; ++i) if (i->first == socketfd) { pimpl_->pilist_.erase(i); break; } pimpl_->probe_impl_.remove(socketfd); } //#################################################################### namespace { //#################################################################### Netxx::Probe::result_type find_ready_match (ready_return_type &q, Netxx::Probe::ready_type rt) { Netxx::Probe::result_type result; ready_return_type::iterator q_it=q.begin(), q_end=q.end(); for (; q_it!=q_end; ++q_it) { if (rt & q_it->second) { result.first = q_it->first; result.second = q_it->second; q.erase(q_it); return result; } } result.first = -1; result.second = Netxx::Probe::ready_none; return result; } //#################################################################### } //#################################################################### Netxx-0.3.2/src/Resolve.h0000644000175000017500000000631712173720353014465 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the definitions of the Netxx resolve functions. These * functions resolve host names and service names based on a compile time * test to determin which system calls to use. **/ #ifndef _Netxx_Resolve_h_ #define _Netxx_Resolve_h_ // Netxx includes #include "Netxx/Types.h" #include "Netxx/Peer.h" // standard includes #include namespace Netxx { //#################################################################### /** * Resolve the given hostname and add each resulting address into a * given vector of Peer classes. * * @param hostname The hostname to resolve. * @param port The port used when creating Netxx::Peer classes. * @param use_ipv6 Accept IPv6 addresses. * @param addrs The vector to add peer addresses to. * @author Peter Jones **/ //#################################################################### void resolve_hostname (const char *hostname, port_type port, bool use_ipv6, std::vector &addrs); //#################################################################### /** * Resolve the given service name and return the port number. This * function does not take the protocol type and therefor will use "tcp" * everytime. This is a simplification but may break on extreamly rare * situations. * * @param service The name of the server to resolve. * @return The port number for that service or 0 if there was an error. * @author Peter Jones **/ //#################################################################### port_type resolve_service (const char *service); } // end Netxx namespace #endif Netxx-0.3.2/src/RecvFrom.h0000644000175000017500000000464712173720353014575 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the definition of the Netxx::call_recvfrom function. **/ #ifndef _Netxx_RecvFrom_h_ #define _Netxx_RecvFrom_h_ // local includes #include "Netxx/Types.h" #include "Netxx/Peer.h" #include "Socket.h" // standard includes #include namespace Netxx { //#################################################################### /** * Wrapper around the recvfrom(2) system call. * * @param socket The server socket * @param buffer Where to place the new datagram * @param length The size of the datagram buffer * @return A std::pair * @author Peter Jones **/ //#################################################################### std::pair call_recvfrom (Socket &socket, void *buffer, size_type length); } // end Netxx namespace #endif Netxx-0.3.2/src/Address.cxx0000644000175000017500000001740112173720353015002 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the implementation for the Netxx::Address class and * some of the necessary helper functions. **/ // common header #include "common.h" // Netxx includes #include "Netxx/Address.h" #include "Netxx/Types.h" #include "SockAddr.h" #include "Resolve.h" // system includes #if defined(WIN32) # include #else # include # include # include # include # include #endif // standard includes #include namespace { const char const_local_service[] = "local"; bool parse_uri (const char *uri, std::string &protocol, std::string &name, Netxx::port_type &port, std::string &path); void make_uds (const char *filename, Netxx::Address::container_type &addrs); } //#################################################################### Netxx::Address::Address (const char *uri, port_type default_port, bool use_ipv6) : port_(0), ipv6_(use_ipv6) { # if defined(WIN32) WSADATA wsdata; if (WSAStartup(MAKEWORD(2,2), &wsdata) != 0) { throw Exception("failed to load WinSock"); } # endif add_address(uri, default_port); } //#################################################################### Netxx::Address::Address (bool use_ipv6) : port_(0), ipv6_(use_ipv6) { # if defined(WIN32) WSADATA wsdata; if (WSAStartup(MAKEWORD(2,2), &wsdata) != 0) { throw Exception("failed to load WinSock"); } # endif } //#################################################################### Netxx::Address::~Address (void) { # if defined(WIN32) WSACleanup(); # endif } //#################################################################### const char* Netxx::Address::get_protocol (void) const { if (!protocol_.empty()) return protocol_.c_str(); return 0; } //#################################################################### const char* Netxx::Address::get_name (void) const { if (!name_.empty()) return name_.c_str(); return 0; } //#################################################################### const char* Netxx::Address::get_path (void) const { if (!path_.empty()) return path_.c_str(); return 0; } //#################################################################### Netxx::port_type Netxx::Address::get_port (void) const { return port_; } //#################################################################### Netxx::Address::const_iterator Netxx::Address::begin (void) const { return addrs_.begin(); } //#################################################################### Netxx::Address::const_iterator Netxx::Address::end (void) const { return addrs_.end(); } //#################################################################### Netxx::size_type Netxx::Address::size (void) const { return addrs_.size(); } //#################################################################### void Netxx::Address::add_address(const char *uri, port_type default_port) { port_type tmp_port=0; std::string protocol; if (!parse_uri(uri, protocol, name_, tmp_port, path_)) { std::string error("can't parse URI: "); error += uri; throw Exception(error); } if (!protocol.empty() && std::strcmp(protocol.c_str(), const_local_service) == 0) { make_uds(name_.c_str(), addrs_); return; } if (!tmp_port && !protocol.empty()) tmp_port = resolve_service(protocol_.c_str()); if (!tmp_port) tmp_port = default_port; port_ = tmp_port; protocol_ = protocol; resolve_hostname(name_.c_str(), port_, ipv6_, addrs_); } //#################################################################### void Netxx::Address::add_all_addresses (port_type port) { { // new scope just for safety SockAddr saddr(AF_INET, port); sockaddr_in *sai = reinterpret_cast(saddr.get_sa()); sai->sin_addr.s_addr = htons(INADDR_ANY); addrs_.push_back(Peer("localhost", port, sai, saddr.get_sa_size())); } # ifndef NETXX_NO_INET6 if (ipv6_) { SockAddr saddr(AF_INET6, port); sockaddr_in6 *sai6 = reinterpret_cast(saddr.get_sa()); sai6->sin6_addr = in6addr_any; addrs_.push_back(Peer("localhost", port, sai6, saddr.get_sa_size())); } # endif } //#################################################################### namespace { //#################################################################### bool parse_uri (const char *uri, std::string &protocol, std::string &name, Netxx::port_type &port, std::string &path) { const char *start_pos = uri, *stop_pos; # ifndef WIN32 // see if the URI is a Unix filepath if (*uri == '/') { protocol = const_local_service; name = uri; return true; } # endif // first look for the protocol seperator while (*uri != 0 && *uri != ':') ++uri; if (*uri == ':' && *(uri+1) == '/' && *(uri+2) == '/') { // looks like we may have a protocol/service name if (uri != start_pos) protocol.assign(start_pos, uri - start_pos); start_pos = uri + 3; # ifndef WIN32 // check to see if it is a local domain socket if (std::strcmp(protocol.c_str(), const_local_service) == 0) { name = start_pos; return true; } # endif } uri = start_pos; // now look for any path info while (*uri != 0 && *uri != '/') ++uri; if (*uri == '/') { // grab the path info path = uri; } stop_pos = uri; uri = start_pos; // check for a port number in the hostname while (*uri != 0 && uri != stop_pos && *uri != ':') ++uri; if (*uri == ':') { std::string tmp_port(uri+1, stop_pos - uri - 1); if (*(uri+1) != 0) port = static_cast(std::atoi(tmp_port.c_str())); } stop_pos = uri; uri = start_pos; // all we should have left is the hostname if (uri == stop_pos) return false; name.assign(uri, stop_pos - uri); return true; } //#################################################################### void make_uds (const char *filename, Netxx::Address::container_type &addrs) { # ifndef WIN32 Netxx::SockAddr saddr(AF_LOCAL); sockaddr_un *sau = reinterpret_cast(saddr.get_sa()); std::strncpy(sau->sun_path, filename, sizeof(sau->sun_path) - 1); addrs.push_back(Netxx::Peer(filename, 0, sau, saddr.get_sa_size())); # endif } //#################################################################### } // end anonymous namespace Netxx-0.3.2/src/ServerBase.h0000644000175000017500000000561212173720353015104 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the defintion of the Netxx::ServerBase class. **/ #ifndef _Netxx_ServerBase_h_ #define _Netxx_ServerBase_h_ // Netxx includes #include #include #include #include #include "Socket.h" #include "Probe_impl.h" // standard includes #include #include #include namespace Netxx { class Address; /** * The Netxx::ServerBase class implements common server code for other Netxx * server classes. **/ class ServerBase { public: explicit ServerBase (const Timeout &timeout=Timeout()); virtual ~ServerBase (void); void bind_to(const Address &addr, bool stream_server); void get_socket_list (Socket *&sockets, size_type &size); Socket* get_readable_socket (void); void set_timeout (const Timeout &timeout); const Timeout& get_timeout (void) const; bool has_socket (socket_type socketfd) const; const ProbeInfo* get_probe_info (void) const; private: Timeout timeout_; Socket *sockets_; size_type sockets_size_; std::map sockets_map_; std::vector files_; ProbeInfo pi_; Probe probe_; ServerBase (const ServerBase&); ServerBase& operator= (const ServerBase&); }; // end Netxx::ServerBase class } // end Netxx namespace #endif Netxx-0.3.2/src/Accept.h0000644000175000017500000000455712173720353014251 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the definition for the call_accept function. **/ #ifndef _Netxx_Accept_h_ #define _Netxx_Accept_h_ // Netxx includes #include "Netxx/Peer.h" namespace Netxx { class Socket; //#################################################################### /** * Make a call to accept(2). The given socket must have been created in * such a way as to have a valid Socket::Type. * * @param socket The server socket to accept for. * @param dont_block Set to true to avoid having this call block. * @return The connected Peer or an invalid peer for timeout. * @author Peter Jones **/ //#################################################################### Peer call_accept (Socket &socket, bool dont_block=false); } // end Netxx namespace #endif Netxx-0.3.2/src/compat.h0000644000175000017500000000631612173720353014330 0ustar danieldaniel/* * compat.h - Compatibility header * * Copyright (C) 2002 Isaac W. Foraker (isaac(at)tazthecat.net) * 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. * * Purpose: * Very few compilers are fully standards compliant. This header is an * attempt to tweak settings on individual compiler environments to make * standard code more portable. * */ #ifndef _compat_h_compatability_header_ #define _compat_h_compatability_header_ #ifdef __cplusplus // Only work for C++ sources // Import common standard library functions into the std namespace on Microsoft // Visual C++ 6 or earlier, but only if not already running with the STLPort // fix. #if defined(_MSC_VER) && _MSC_VER <= 1200 && !defined(_STLP_DO_IMPORT_CSTD_FUNCTIONS) # include # include # include # include # include namespace std { using ::atoi; using ::atof; using ::isalpha; using ::isdigit; using ::isalnum; using ::isgraph; using ::isspace; using ::islower; using ::isupper; using ::isxdigit; using ::ispunct; using ::isprint; using ::iscntrl; using ::toupper; using ::tolower; using ::sprintf; using ::printf; using ::sscanf; using ::scanf; using ::size_t; using ::time_t; using ::strlen; using ::strcmp; using ::strncmp; using ::strcpy; using ::strncpy; using ::memset; using ::memcpy; using ::memcmp; using ::malloc; using ::free; using ::clock; using ::time; using ::asctime; using ::gmtime; using ::localtime; } #endif // Disable some annoying MSVC++ warnings. #if defined(_MSC_VER) # if _MSC_VER <= 1200 // Older version of MSVC do not support throw() declaration # pragma warning(disable : 4290) # endif // Turn off warnings for long symbol names caused by the STL # pragma warning(disable : 4786) #endif #endif // __cplusplus #endif // _compat_h__compatability_header Netxx-0.3.2/src/Resolve_gethostbyname.cxx0000644000175000017500000001032012173720353017756 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the implementation of the resolve_hostname function * using the gethostbyname system call. **/ // common header #include "common.h" // Netxx includes #include "Resolve.h" #include "Netxx/Types.h" #include "SockAddr.h" #include "OSError.h" // system includes #if defined (WIN32) # include #else # include # include # include # include # include # include # include # include #endif // standard includes #include namespace Netxx { //#################################################################### void resolve_hostname (const char *hostname, port_type port, bool use_ipv6, std::vector &addrs) { { // first try to see if this address is already an IPv4 address SockAddr saddr(AF_INET, port); sockaddr_in *sai = reinterpret_cast(saddr.get_sa());; if (inet_pton(AF_INET, hostname, &(sai->sin_addr)) == 1) { addrs.push_back(Peer(hostname, port, sai, saddr.get_sa_size())); return; } } # ifndef NETXX_NO_INET6 if (use_ipv6) { // now try to see if this address is already an IPv6 address SockAddr saddr(AF_INET6, port); sockaddr_in6 *sai6 = reinterpret_cast(saddr.get_sa()); if (inet_pton(AF_INET6, hostname, &(sai6->sin6_addr)) == 1) { addrs.push_back(Peer(hostname, port, sai6, saddr.get_sa_size())); return; } } # endif /* * if we got this far then the address must really be a hostname so * we are going to have to call gethostbyname and either pull it out * of the hosts file or go to DNS. And don't forget NIS and WINS and * ... */ hostent *he; // WARNING not MT safe if ( (he = gethostbyname(hostname)) == 0) { std::string error("name resolution failure for "); error += hostname; throw Exception(error); } for (char **ii = he->h_addr_list; *ii != 0; ++ii) { switch (he->h_addrtype) { case AF_INET: { SockAddr saddr(AF_INET, port); sockaddr_in *sai = reinterpret_cast(saddr.get_sa()); std::memcpy(&(sai->sin_addr), *ii, sizeof(sai->sin_addr)); addrs.push_back(Peer(he->h_name, port, sai, saddr.get_sa_size())); } break; # ifndef NETXX_NO_INET6 case AF_INET6: { SockAddr saddr(AF_INET6, port); sockaddr_in6 *sai6 = reinterpret_cast(saddr.get_sa()); std::memcpy(&(sai6->sin6_addr), *ii, sizeof(sai6->sin6_addr)); addrs.push_back(Peer(he->h_name, port, sai6, saddr.get_sa_size())); } break; # endif } } } //#################################################################### } // end Netxx namespace Netxx-0.3.2/src/TLS_tls_pimpl.cxx0000644000175000017500000000751112173720353016143 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file implements the TLS::tls_pimpl struct. **/ // Netxx includes #include "TLS_tls_pimpl.h" #include "Netxx/Types.h" // OpenSSL includes #include #include #include // standard includes #include //#################################################################### namespace { const unsigned int const_error_buffer_size = 240; } //#################################################################### Netxx::TLS::tls_pimpl::tls_pimpl(context_pimpl *ctx_pimpl) : ctx_pimpl_(ctx_pimpl), pi_(this) { } //#################################################################### Netxx::TLS::tls_pimpl::tls_pimpl(context_pimpl *ctx_pimpl, int socketfd) : ctx_pimpl_(ctx_pimpl), socket_(socketfd), pi_(this) { } //#################################################################### void Netxx::TLS::tls_pimpl::init (void) { server_ = false; if ( (openssl_ssl_ = SSL_new(ctx_pimpl_->openssl_ctx_)) == 0) { throw Exception("failed to create TLS handle (struct OpenSSL::SSL)"); } BIO *tmp_bio; if ( (tmp_bio = BIO_new_socket(socket_.get_socketfd(), BIO_NOCLOSE)) == 0) throw Exception("failed to create TLS socket BIO"); SSL_set_bio(openssl_ssl_, tmp_bio, tmp_bio); pi_.add_socket(socket_.get_socketfd()); } //#################################################################### Netxx::TLS::tls_pimpl::~tls_pimpl (void) { SSL_free(openssl_ssl_); } //#################################################################### void Netxx::TLS::tls_pimpl::error2exception (const char *prefix) { char buffer[const_error_buffer_size]; std::string error("OpenSSL: "); if (prefix) { error += prefix; error += ": "; } std::memset(buffer, 0, sizeof(buffer)); ERR_error_string_n(ERR_get_error(), buffer, sizeof(buffer)); error += buffer; while (ERR_get_error() != 0); throw Exception(error); } //#################################################################### Netxx::ProbeInfo::pending_type Netxx::TLS::TLS_ProbeInfo::check_pending (socket_type, pending_type pt) const { if ((pt == pending_none || pt & pending_read) && SSL_pending(pimpl_->openssl_ssl_)) return pending_read; return pending_none; } //#################################################################### Netxx-0.3.2/src/StreamServer.cxx0000644000175000017500000001236012173720353016036 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the implementation of the Netxx::StreamServer class. **/ // common header #include "common.h" // definition include #include "Netxx/StreamServer.h" // Netxx includes #include "Netxx/Address.h" #include "Netxx/Types.h" #include "Netxx/ProbeInfo.h" #include "ServerBase.h" #include "Socket.h" #include "Accept.h" #include "OSError.h" // standard includes #include // system includes #if defined(WIN32) # include #else # include # include # include # include # include # include # include #endif //#################################################################### namespace { void call_listen (Netxx::Socket *sockets, Netxx::size_type sockets_size, int backlog); } //#################################################################### Netxx::StreamServer::StreamServer (port_type port, const Timeout &timeout, int listen_backlog) { std::auto_ptr ap(pimpl_ = new ServerBase(timeout)); Address addr; addr.add_all_addresses(port); init(addr, listen_backlog); ap.release(); } //#################################################################### Netxx::StreamServer::StreamServer (const Address &addr, const Timeout &timeout, int listen_backlog) { std::auto_ptr ap(pimpl_ = new ServerBase(timeout)); init(addr, listen_backlog); ap.release(); } //#################################################################### Netxx::StreamServer::~StreamServer (void) { delete pimpl_; } //#################################################################### Netxx::Peer Netxx::StreamServer::accept_connection (void) { Socket *ready_socket = pimpl_->get_readable_socket(); if (!ready_socket) return Peer(); return call_accept(*ready_socket, pimpl_->get_timeout()); } //#################################################################### const Netxx::ProbeInfo* Netxx::StreamServer::get_probe_info (void) const { return pimpl_->get_probe_info(); } //#################################################################### void Netxx::StreamServer::init (const Address &addr, int backlog) { pimpl_->bind_to(addr, true); Socket *sockets; size_type sockets_size; pimpl_->get_socket_list(sockets, sockets_size); call_listen(sockets, sockets_size, backlog); } //#################################################################### namespace { //#################################################################### void call_listen (Netxx::Socket *sockets, Netxx::size_type sockets_size, int backlog) { for (Netxx::size_type i=0; ihas_socket(fd); } //#################################################################### bool operator== (socket_type fd, const StreamServer &ss) { return ss == fd; } //#################################################################### bool operator!= (const StreamServer &ss, socket_type fd) { return !(ss == fd); } //#################################################################### bool operator!= (socket_type fd, const StreamServer &ss) { return !(ss == fd); } //#################################################################### } Netxx-0.3.2/src/SockOpt.cxx0000644000175000017500000000762312173720353015004 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the implementation of the Netxx::SockOpt class. **/ // common header #include "common.h" // Netxx includes #include "Netxx/SockOpt.h" #include "Netxx/Types.h" #include "OSError.h" // system includes #if defined(WIN32) # include #else # include # include # include #endif // standard includes #include //#################################################################### struct Netxx::SockOpt::pimpl { pimpl (int socket) : fcntl_flags_(0), fcntl_changed_(false), win_blocking_(false) { # ifndef WIN32 fcntl_flags_ = fcntl(socket, F_GETFL, 0); # endif } int fcntl_flags_; bool fcntl_changed_; bool win_blocking_; }; //#################################################################### Netxx::SockOpt::SockOpt (int socketfd, bool revert) : socket_(socketfd), revert_(revert) { pimpl_ = new pimpl(socket_); } //#################################################################### Netxx::SockOpt::~SockOpt (void) { if (revert_ && (pimpl_->fcntl_changed_ || pimpl_->win_blocking_)) { # if defined(WIN32) unsigned long off = 0; ioctlsocket(socket_, FIONBIO, &off); # else fcntl(socket_, F_SETFL, pimpl_->fcntl_flags_); # endif } delete pimpl_; } //#################################################################### bool Netxx::SockOpt::set_non_blocking (void) { # if defined(WIN32) /* * FIXME FIXME FIXME FIXME * * Call ioctlsocket to get the NBIO flag instead of using * win_blocking_ * * FIXME FIXME FIXME FIXME */ if (pimpl_->win_blocking_) return true; unsigned long on = 1; if (ioctlsocket(socket_, FIONBIO, &on) != 0) return false; pimpl_->win_blocking_ = true; return true; # else int flags = fcntl(socket_, F_GETFL, 0); if (flags & O_NONBLOCK) return true; if (fcntl(socket_, F_SETFL, pimpl_->fcntl_flags_ | O_NONBLOCK) == -1) return false; pimpl_->fcntl_changed_ = true; return true; # endif } //#################################################################### bool Netxx::SockOpt::set_reuse_address (void) { int on = 1; char *val = reinterpret_cast(&on); if (setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR, val, sizeof(on)) != 0) { std::string error("setsockopt(2) failure: "); error += strerror(get_last_error()); throw Exception(error); } return true; } Netxx-0.3.2/src/Stream.cxx0000644000175000017500000001155412173720353014653 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the implementation for the Netxx::Stream. **/ // common header #include "common.h" // Netxx includes #include "Netxx/Stream.h" #include "Netxx/ProbeInfo.h" #include "Socket.h" // standard includes #include #include //#################################################################### struct Netxx::Stream::pimpl { pimpl (void) {} explicit pimpl (socket_type socketfd) : socket_(socketfd) {} pimpl (const pimpl &other) : socket_(other.socket_), pi_(other.pi_) {} Socket socket_; ProbeInfo pi_; }; //#################################################################### Netxx::Stream::Stream (const Address &address, const Timeout &timeout) : StreamBase(timeout) { std::auto_ptr ap(pimpl_ = new pimpl); make_connection(pimpl_->socket_, address); pimpl_->pi_.add_socket(pimpl_->socket_.get_socketfd()); ap.release(); } //#################################################################### Netxx::Stream::Stream (socket_type socketfd, const Timeout &timeout) : StreamBase(timeout) { std::auto_ptr ap(pimpl_ = new pimpl(socketfd)); pimpl_->pi_.add_socket(pimpl_->socket_.get_socketfd()); ap.release(); } //#################################################################### Netxx::Stream::Stream (const char *uri, port_type default_port, const Timeout &timeout) : StreamBase(timeout) { Address addr(uri, default_port); std::auto_ptr ap(pimpl_ = new pimpl); make_connection(pimpl_->socket_, addr); pimpl_->pi_.add_socket(pimpl_->socket_.get_socketfd()); ap.release(); } //#################################################################### Netxx::Stream::Stream (const Stream &other) : StreamBase(other.get_timeout()) { pimpl_ = new pimpl(*(other.pimpl_)); } //#################################################################### Netxx::Stream& Netxx::Stream::operator= (const Stream &other) { Stream tmp(other); swap(tmp); return *this; } //#################################################################### void Netxx::Stream::swap (Stream &other) { pimpl_->socket_.swap(other.pimpl_->socket_); pimpl_->pi_.swap(other.pimpl_->pi_); swap_base(other); } //#################################################################### Netxx::Stream::~Stream (void) { delete pimpl_; } //#################################################################### void Netxx::Stream::close (void) { pimpl_->socket_.close(); pimpl_->pi_.clear(); } //#################################################################### int Netxx::Stream::get_socketfd (void) const { return pimpl_->socket_.get_socketfd(); } //#################################################################### Netxx::signed_size_type Netxx::Stream::write (const void *buffer, size_type length) { return pimpl_->socket_.write(buffer, length, get_timeout()); } //#################################################################### Netxx::signed_size_type Netxx::Stream::read (void *buffer, size_type length) { return pimpl_->socket_.read(buffer, length, get_timeout()); } //#################################################################### const Netxx::ProbeInfo* Netxx::Stream::get_probe_info (void) const { return &(pimpl_->pi_); } //#################################################################### Netxx-0.3.2/src/Peer.cxx0000644000175000017500000001676412173720353014323 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the implementation of the Netxx::Peer class. **/ // common header #include "common.h" // Netxx includes #include // system includes #if defined(WIN32) # include #else # include # include # include # include # include # include # include #endif // standard includes #include #include #include #include //#################################################################### namespace { const unsigned int const_max_sockaddr_size = 128; } //########################################################################### Netxx::Peer::Peer (void) : okay_(false), port_(0), socketfd_(-1), sockaddr_(0), sockaddr_size_(0) { } //########################################################################### Netxx::Peer::Peer (const char *addr, port_type port, void *saddr, size_type saddr_size) : okay_(true), addr_(addr), port_(port), socketfd_(-1), sockaddr_size_(saddr_size) { // TODO should this be sockaddr_ = new char[saddr_size];? sockaddr_ = std::malloc(saddr_size); if (!sockaddr_) throw std::bad_alloc(); std::memcpy(sockaddr_, saddr, saddr_size); } //########################################################################### Netxx::Peer::Peer (socket_type socketfd, void *saddr, size_type saddr_size) : okay_(true), port_(0), socketfd_(socketfd), sockaddr_size_(saddr_size) { // TODO should this be sockaddr_ = new char[saddr_size];? sockaddr_ = std::malloc(saddr_size); if (!sockaddr_) throw std::bad_alloc(); std::memcpy(sockaddr_, saddr, saddr_size); sockaddr *sa = static_cast(sockaddr_); switch (sa->sa_family) { case AF_INET: { char buffer[INET_ADDRSTRLEN]; if (inet_ntop(AF_INET, &(reinterpret_cast(sa)->sin_addr), buffer, sizeof(buffer))) { addr_ = buffer; port_ = ntohs(reinterpret_cast(sa)->sin_port); } } break; # ifndef NETXX_NO_INET6 case AF_INET6: { char buffer[INET6_ADDRSTRLEN]; if (inet_ntop(AF_INET6, &(reinterpret_cast(sa)->sin6_addr), buffer, sizeof(buffer))) { addr_ = buffer; port_ = ntohs(reinterpret_cast(sa)->sin6_port); } } break; # endif # ifndef WIN32 case AF_LOCAL: addr_ = reinterpret_cast(sa)->sun_path; break; # endif } } //########################################################################### Netxx::Peer::Peer (const Peer &other) : okay_(other.okay_), addr_(other.addr_), port_(other.port_), socketfd_(other.socketfd_), sockaddr_(0), sockaddr_size_(other.sockaddr_size_) { if (other.sockaddr_) { sockaddr_ = std::malloc(sockaddr_size_); if (!sockaddr_) throw std::bad_alloc(); std::memcpy(sockaddr_, other.sockaddr_, sockaddr_size_); } } //########################################################################### Netxx::Peer& Netxx::Peer::operator= (const Peer &other) { Peer tmp(other); swap(tmp); return *this; } //########################################################################### void Netxx::Peer::swap (Peer &other) { std::swap(okay_, other.okay_); std::swap(addr_, other.addr_); std::swap(port_, other.port_); std::swap(socketfd_, other.socketfd_); std::swap(sockaddr_, other.sockaddr_); std::swap(sockaddr_size_, other.sockaddr_size_); } //########################################################################### Netxx::Peer::~Peer (void) { if (sockaddr_) std::free(sockaddr_); } //########################################################################### const char* Netxx::Peer::get_address (void) const { return addr_.c_str(); } //########################################################################### Netxx::port_type Netxx::Peer::get_port (void) const { return port_; } //########################################################################### Netxx::port_type Netxx::Peer::get_local_port (void) const { size_type sa_size = const_max_sockaddr_size; union { sockaddr sa; char data[const_max_sockaddr_size]; } sau; # if defined(WIN32) || defined(__APPLE__) || defined(__CYGWIN__) int *sa_size_ptr = reinterpret_cast(&sa_size); # else size_type *sa_size_ptr = &sa_size; # endif int rc; if ( (rc = getsockname(get_socketfd(), reinterpret_cast(sau.data), sa_size_ptr))) { throw Exception(strerror(errno)); } switch (sau.sa.sa_family) { case AF_INET: return ntohs(reinterpret_cast(&sau.sa)->sin_port); # ifndef NETXX_NO_INET6 case AF_INET6: return ntohs(reinterpret_cast(&sau.sa)->sin6_port); # endif default: return 0; } } //########################################################################### Netxx::socket_type Netxx::Peer::get_socketfd (void) const { return socketfd_; } //########################################################################### Netxx::Peer::operator bool (void) const { return okay_; } //########################################################################### const void* Netxx::Peer::get_sa (void) const { return sockaddr_; } //########################################################################### Netxx::size_type Netxx::Peer::get_sa_size() const { return sockaddr_size_; } //########################################################################### namespace Netxx { //########################################################################### std::ostream& operator<< (std::ostream &stream, const Peer &peer) { const sockaddr *sa = reinterpret_cast(peer.get_sa()); if (peer) { if (sa && sa->sa_family == AF_LOCAL) { if (peer.get_address()[0] == 0) stream << "AF_LOCAL"; else stream << peer.get_address(); } else { stream << peer.get_address() << ":" << peer.get_port(); } } return stream; } //########################################################################### } Netxx-0.3.2/src/OSError.h0000644000175000017500000000436712173720353014404 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains definitions for OS error functions. **/ #ifndef _OSError_h_ #define _OSError_h_ #if defined (WIN32) # include # include # undef EINTR # define EINTR WSAEINTR # undef EWOULDBLOCK # define EWOULDBLOCK WSAEWOULDBLOCK # undef EINPROGRESS # define EINPROGRESS WSAEINPROGRESS # undef EAFNOSUPPORT # define EAFNOSUPPORT WSAEAFNOSUPPORT # undef ENOSPC # define ENOSPC WSAENOSPC # undef ECONNRESET # define ECONNRESET WSAECONNRESET # undef ECONNABORTED # define ECONNABORTED WSAECONNABORTED #else # include #endif namespace Netxx { typedef int error_type; error_type get_last_error (void); } // end Netxx namespace #endif Netxx-0.3.2/src/Probe_impl.h0000644000175000017500000000524212173720353015132 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the defintion of the Netxx::Probe_impl class. **/ #ifndef _Netxx_Probe_impl_h_ #define _Netxx_Probe_impl_h_ // Netxx includes #include #include #include // system includes #include #include namespace Netxx { /** * Probe_impl is the class that does the actuall probing of socket file * descriptors. The implementation is chosen at compile time, an example * would be Probe_select.cxx that calls select(2). **/ class Probe_impl { public: typedef std::vector< std::pair > probe_type; Probe_impl (void); Probe_impl (const Probe_impl &other); Probe_impl& operator= (const Probe_impl &other); void swap (Probe_impl &other); ~Probe_impl (void); void add (socket_type socketfd, Probe::ready_type rt=Probe::ready_none); void remove (socket_type socketfd); void clear (void); probe_type probe (const Timeout &timeout, Probe::ready_type rt=Probe::ready_none); private: void *pimpl_; }; // end Netxx::Probe_impl class } // end Netxx namespace #endif Netxx-0.3.2/src/TLS_Context.cxx0000644000175000017500000001411112173720353015556 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the implementation of the Netxx::TLS::Context class. **/ // Netxx includes #include "TLS_Context_pimpl.h" // OpenSSL includes #include #include #include // standard includes #include #include #include //#################################################################### extern "C" int openssl_password_callback (char *buffer, int size, int encrypting, void *pimpl); //#################################################################### Netxx::TLS::Context::Context (bool allow_init) { pimpl_ = new context_pimpl(this); if (allow_init) { SSL_library_init(); SSL_load_error_strings(); } if ( (pimpl_->openssl_ctx_ = SSL_CTX_new(SSLv23_method())) == 0) { throw Exception("can't create OpenSSL context object"); } // Seed the pseudorandom number generator std::string seed; seed_prng(seed); if (!seed.empty()) RAND_seed(seed.c_str(), seed.size()); // Setup the PEM password callback SSL_CTX_set_default_passwd_cb(pimpl_->openssl_ctx_, openssl_password_callback); SSL_CTX_set_default_passwd_cb_userdata(pimpl_->openssl_ctx_, pimpl_); SSL_CTX_set_options(pimpl_->openssl_ctx_, SSL_OP_ALL); // Work around a bug in older versions of OpenSSL # if (OPENSSL_VERSION_NUMBER < 0x00905100L) SSL_CTX_set_verify_depth(pimpl_->openssl_ctx_, 1); # endif } //#################################################################### Netxx::TLS::Context::~Context (void) { SSL_CTX_free(pimpl_->openssl_ctx_); delete pimpl_; } //#################################################################### void Netxx::TLS::Context::load_cert_chain (const char *filename) { if (SSL_CTX_use_certificate_chain_file(pimpl_->openssl_ctx_, filename) != 1) { std::string error("error loading certificate chain file: "); error += filename; throw Exception(error); } } //#################################################################### void Netxx::TLS::Context::load_private_key (const char *filename) { if (SSL_CTX_use_PrivateKey_file(pimpl_->openssl_ctx_, filename, SSL_FILETYPE_PEM) != 1) { std::string error("error loading private key file: "); error += filename; throw Exception(error); } } //#################################################################### void Netxx::TLS::Context::load_ca_file (const char *filename) { if (SSL_CTX_load_verify_locations(pimpl_->openssl_ctx_, filename, 0) != 1) { std::string error("error loading CA certificate file: "); error += filename; throw Exception(error); } } //#################################################################### void Netxx::TLS::Context::remove_protocol (Protocol which_protocol) { switch (which_protocol) { case PROTOCOL_SSLv2: SSL_CTX_set_options(pimpl_->openssl_ctx_, SSL_OP_NO_SSLv2); break; case PROTOCOL_SSLv3: SSL_CTX_set_options(pimpl_->openssl_ctx_, SSL_OP_NO_SSLv3); break; case PROTOCOL_TLSv1: SSL_CTX_set_options(pimpl_->openssl_ctx_, SSL_OP_NO_TLSv1); break; } } //#################################################################### bool Netxx::TLS::Context::get_password (std::string &password, bool encrypting) { #ifdef WIN32 /* can't use console for win32 */ return false; #else const char *p = EVP_get_pw_prompt(); if (!p) p = "Enter passphrase: "; char buffer[PEM_BUFSIZE]; for (;;) { if (EVP_read_pw_string(buffer, PEM_BUFSIZE, p, encrypting ? 1 : 0) != 0) return false; if (encrypting && std::strlen(buffer) < 4) std::cerr << "passphrase too short!\n"; else break; } password = buffer; return true; #endif } //#################################################################### void Netxx::TLS::Context::seed_prng (std::string&) { // FIXME Should we do anything here? } //#################################################################### int Netxx::TLS::context_pimpl::proxy_password_callback (char *buffer, int size, bool encrypting) { std::string passwd; if (!parent_->get_password(passwd, encrypting)) return -1; if (passwd.size() > static_cast(size)) return -1; std::memcpy(buffer, passwd.c_str(), passwd.size()); return static_cast(passwd.size()); } //#################################################################### extern "C" int openssl_password_callback (char *buffer, int size, int encrypting, void *pimpl) { return static_cast(pimpl)->proxy_password_callback(buffer, size, encrypting); } //#################################################################### Netxx-0.3.2/src/Probe_select.cxx0000644000175000017500000001727612173720353016035 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the implementation of the Netxx::Probe_impl class for * the select(2) system call. **/ // select sucks #define FD_SETSIZE 65536 // common header #include "common.h" // Netxx includes #include "Probe_impl.h" #include "Netxx/Types.h" #include "Netxx/Timeout.h" #include "OSError.h" // system includes #if defined(WIN32) # include #else # include # include # include # include #endif // standard includes #include #include #include #include #include //#################################################################### namespace { struct pimpl { std::list rd_sockets_; std::list wr_sockets_; std::list er_sockets_; }; } //#################################################################### Netxx::Probe_impl::Probe_impl (void) { pimpl_ = new pimpl; } //#################################################################### Netxx::Probe_impl::Probe_impl (const Probe_impl &other) { std::auto_ptr ap(new pimpl); pimpl_ = ap.get(); static_cast(pimpl_)->rd_sockets_ = static_cast(other.pimpl_)->rd_sockets_; static_cast(pimpl_)->wr_sockets_ = static_cast(other.pimpl_)->wr_sockets_; static_cast(pimpl_)->er_sockets_ = static_cast(other.pimpl_)->er_sockets_; ap.release(); } //#################################################################### Netxx::Probe_impl& Netxx::Probe_impl::operator= (const Probe_impl &other) { Probe_impl tmp(other); swap(tmp); return *this; } //#################################################################### void Netxx::Probe_impl::swap (Probe_impl &other) { static_cast(pimpl_)->rd_sockets_.swap(static_cast(other.pimpl_)->rd_sockets_); static_cast(pimpl_)->wr_sockets_.swap(static_cast(other.pimpl_)->wr_sockets_); static_cast(pimpl_)->er_sockets_.swap(static_cast(other.pimpl_)->er_sockets_); } //#################################################################### Netxx::Probe_impl::~Probe_impl (void) { delete static_cast(pimpl_); } //#################################################################### void Netxx::Probe_impl::add (socket_type socketfd, Probe::ready_type rt) { if (rt == Probe::ready_none || rt & Probe::ready_read) static_cast(pimpl_)->rd_sockets_.push_back(socketfd); if (rt == Probe::ready_none || rt & Probe::ready_write) static_cast(pimpl_)->wr_sockets_.push_back(socketfd); if (rt == Probe::ready_none || rt & Probe::ready_oobd) static_cast(pimpl_)->er_sockets_.push_back(socketfd); } //#################################################################### void Netxx::Probe_impl::remove (socket_type socketfd) { static_cast(pimpl_)->rd_sockets_.remove(socketfd); static_cast(pimpl_)->wr_sockets_.remove(socketfd); static_cast(pimpl_)->er_sockets_.remove(socketfd); } //#################################################################### void Netxx::Probe_impl::clear (void) { static_cast(pimpl_)->rd_sockets_.clear(); static_cast(pimpl_)->wr_sockets_.clear(); static_cast(pimpl_)->er_sockets_.clear(); } //#################################################################### Netxx::Probe_impl::probe_type Netxx::Probe_impl::probe (const Timeout &timeout, Probe::ready_type rt) { pimpl *p=static_cast(pimpl_); probe_type return_value; fd_set rd_fdset, wr_fdset, er_fdset; fd_set *rd_fdptr, *wr_fdptr, *er_fdptr; timeval tmp_timeout; timeval *timeout_ptr; socket_type max_fd; int rc; for (;;) { if (timeout) { tmp_timeout.tv_sec = timeout.get_sec(); tmp_timeout.tv_usec = timeout.get_usec(); timeout_ptr = &tmp_timeout; } else { timeout_ptr = 0; } FD_ZERO(&rd_fdset); FD_ZERO(&wr_fdset); FD_ZERO(&er_fdset); std::set all_sockets; std::list::const_iterator it, end; if (rt == Probe::ready_none || rt & Probe::ready_read) { for (it=p->rd_sockets_.begin(), end=p->rd_sockets_.end(); it!=end; ++it) { FD_SET(*it, &rd_fdset); all_sockets.insert(*it); } rd_fdptr = &rd_fdset; } else { rd_fdptr = 0; } if (rt == Probe::ready_none || rt & Probe::ready_write) { for (it=p->wr_sockets_.begin(), end=p->wr_sockets_.end(); it!=end; ++it) { FD_SET(*it, &wr_fdset); all_sockets.insert(*it); } wr_fdptr = &wr_fdset; } else { wr_fdptr = 0; } if (rt == Probe::ready_none || rt & Probe::ready_oobd) { for (it=p->er_sockets_.begin(), end=p->er_sockets_.end(); it!=end; ++it) { FD_SET(*it, &er_fdset); all_sockets.insert(*it); } er_fdptr = &er_fdset; } else { er_fdptr = 0; } if (all_sockets.empty()) { return return_value; } std::set::const_iterator maxfd_it = std::max_element(all_sockets.begin(), all_sockets.end()); max_fd = maxfd_it == all_sockets.end() ? 0 : *maxfd_it; if (max_fd > FD_SETSIZE) { throw Exception("Netxx::Probe: too many sockets for select"); } if ( (rc = select(max_fd+1, rd_fdptr, wr_fdptr, er_fdptr, timeout_ptr)) > 0) { std::set::const_iterator all_it=all_sockets.begin(), all_end=all_sockets.end(); Probe::ready_type ready_bits; for (; all_it!=all_end; ++all_it) { ready_bits = Probe::ready_none; if (FD_ISSET(*all_it, &rd_fdset)) ready_bits |= Probe::ready_read; if (FD_ISSET(*all_it, &wr_fdset)) ready_bits |= Probe::ready_write; if (FD_ISSET(*all_it, &er_fdset)) ready_bits |= Probe::ready_oobd; if (ready_bits != Probe::ready_none) return_value.push_back(std::make_pair(*all_it, ready_bits)); } return return_value; } else if (rc == 0) { return return_value; } else { error_type error_code = get_last_error(); switch (error_code) { case EINTR: continue; default: { std::string error("select(2): "); error += strerror(error_code); throw Exception(error); } } } } /* not reached */ return return_value; } //#################################################################### Netxx-0.3.2/src/Resolve_getservbyname.cxx0000644000175000017500000000474112173720353017772 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the implementation of the resolve_service function * using the getservbyname system call. **/ // common header #include "common.h" // Netxx includes #include "Resolve.h" #include "Netxx/Types.h" #include "OSError.h" // system includes #if defined (WIN32) # include #else # include # include # include # include # include # include # include # include #endif // standard includes #include namespace Netxx { //#################################################################### port_type resolve_service (const char *service) { servent *se; // WARNING not thread safe :-( if ( (se = getservbyname(service, "tcp")) != 0) return ntohs(se->s_port); return 0; } //#################################################################### } // end Netxx namespace Netxx-0.3.2/src/StreamBase.cxx0000644000175000017500000001364312173720353015447 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the implementation of the Netxx::StreamBase class * along with some helper functions. **/ // common header #include "common.h" // Netxx includes #include "Netxx/StreamBase.h" #include "Netxx/SockOpt.h" #include "Netxx/Address.h" #include "Netxx/Peer.h" #include "Netxx/Types.h" #include "Socket.h" #include "OSError.h" // system includes #if defined(WIN32) # include #else # include # include # include # include # include # include # include #endif // standard includes #include #include //#################################################################### namespace { bool client_connect (Netxx::Socket &socket, const Netxx::Peer &peer, const Netxx::Timeout &timeout, std::string &message); } //#################################################################### Netxx::StreamBase::StreamBase (const Timeout &timeout) : timeout_(timeout) { } //#################################################################### Netxx::StreamBase::~StreamBase (void) { } //#################################################################### void Netxx::StreamBase::make_connection (Socket &socket, const Address &address) { std::string message; // connect this socket to the given address Address::const_iterator ai(address.begin()), aend(address.end()); // make sure there is at least one network address if (ai == aend) throw Exception("no address to connect to"); // try all addresses bool connected = false; for (; ai != aend; ++ai) { if (client_connect(socket, *ai, timeout_, message)) { connected = true; break; } } // make sure we got connected if (!connected) { std::string error("failed to connect: "); error += message; throw Exception(error); } } //#################################################################### void Netxx::StreamBase::swap_base (StreamBase &other) { std::swap(timeout_, other.timeout_); } //#################################################################### void Netxx::StreamBase::set_timeout (const Timeout &timeout) { timeout_ = timeout; } //#################################################################### const Netxx::Timeout& Netxx::StreamBase::get_timeout (void) const { return timeout_; } namespace { //#################################################################### bool client_connect (Netxx::Socket &socket, const Netxx::Peer &peer, const Netxx::Timeout &timeout, std::string &message) { const sockaddr *sa = static_cast(peer.get_sa()); Netxx::size_type sa_size = peer.get_sa_size(); /* * Get the socket type for this Peer */ Netxx::Socket::Type stype; switch (sa->sa_family) { case AF_INET: stype = Netxx::Socket::TCP; break; #ifndef NETXX_NO_INET6 case AF_INET6: stype = Netxx::Socket::TCP6; break; #endif #ifndef WIN32 case AF_LOCAL: stype = Netxx::Socket::LOCALSTREAM; break; #endif default: stype = Netxx::Socket::TCP; } /* * Create a tmp socket so that the Socket class will do all the hard * work for us. Then replace the socket given in the param list with * the tmp socket. */ Netxx::Socket tmp_socket(stype); tmp_socket.swap(socket); Netxx::socket_type socketfd=socket.get_socketfd(); Netxx::SockOpt socket_options(socketfd, true); if (timeout) socket_options.set_non_blocking(); if (connect(socketfd, sa, sa_size) != 0) { Netxx::error_type error_code = Netxx::get_last_error(); if (error_code == EINPROGRESS || error_code == EWOULDBLOCK || error_code == EINTR) { if (!socket.readable_or_writable(timeout)) { message = "connection timed out"; return false; } # if defined(__APPLE__) int so_error, so_return; int so_len(sizeof(so_error)); # elif defined(WIN32) char so_error; int so_return; int so_len(sizeof(so_error)); # else int so_error, so_return; socklen_t so_len(sizeof(so_error)); # endif if ( (so_return = getsockopt(socket.get_socketfd(), SOL_SOCKET, SO_ERROR, &so_error, &so_len)) < 0) { message = strerror(so_error); return false; } return true; } message = strerror(error_code); return false; } return true; } //#################################################################### } // end anonymous namespace Netxx-0.3.2/src/TLS_Certificate.cxx0000644000175000017500000001202712173720353016360 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ // Netxx Includes #include "TLS_cert_pimpl.h" // OpenSSL includes #include #include #include // standard includes #include //#################################################################### namespace { const char const_subject_alt_name[] = "subjectAltName"; const char const_field_dns[] = "DNS"; } // end anonymous namespace //#################################################################### Netxx::TLS::Certificate::Certificate (void) { } //#################################################################### Netxx::TLS::Certificate::~Certificate (void) { } //#################################################################### Netxx::TLS::cert_impl::cert_impl() : x509_(0), x509_name_(0) { } //#################################################################### Netxx::TLS::cert_impl::~cert_impl (void) { } //#################################################################### Netxx::TLS::cert_impl::operator void* (void) const { return x509_name_; } //#################################################################### bool Netxx::TLS::cert_impl::operator! (void) const { return !x509_name_; } //#################################################################### std::string Netxx::TLS::cert_impl::get_fqdn (void) const { int extcount; if (x509_ && ( extcount = X509_get_ext_count(x509_)) > 0) { X509_EXTENSION *ext; const char *extstr; for (int i=0; ii2v(meth, meth->d2i(0, &(ext->value->data), ext->value->length), 0); for (int j=0; jname, const_field_dns) == 0) return std::string(nval->value); } } } } return get_text(NID_commonName); } //#################################################################### std::string Netxx::TLS::cert_impl::get_country (void) const { return get_text(NID_countryName); } //#################################################################### std::string Netxx::TLS::cert_impl::get_locality (void) const { return get_text(NID_localityName); } //#################################################################### std::string Netxx::TLS::cert_impl::get_region (void) const { return get_text(NID_stateOrProvinceName); } //#################################################################### std::string Netxx::TLS::cert_impl::get_organization (void) const { return get_text(NID_organizationName); } //#################################################################### std::string Netxx::TLS::cert_impl::get_organization_unit (void) const { return get_text(NID_organizationalUnitName); } //#################################################################### std::string Netxx::TLS::cert_impl::get_text (int nid) const { std::string rc; char name[128]; if (x509_name_ && X509_NAME_get_text_by_NID(x509_name_, nid, name, sizeof(name)) > 0) { rc = name; } return rc; } //#################################################################### void Netxx::TLS::cert_impl::set(X509 *x, X509_NAME *xn) { x509_ = x; x509_name_ = xn; } //#################################################################### Netxx-0.3.2/src/Makefile0000644000175000017500000000173312173720353014332 0ustar danieldaniel# This Makefile automaticly generated by /home/jason/head/sip/tfm/contrib/Netxx-0.3.2/tools/mkmf # File created on: Mon Jul 18 20:54:16 2005 # DO NOT EDIT THIS FILE! CXX=c++ CXXFLAGS=-O2 -fpic -shared -I/home/jason/head/sip/tfm/contrib/Netxx-0.3.2/include AR=ar ARFLAGS=rc SAR=c++ SARFLAGS= LD=c++ LDFLAGS= POST_LDFLAGS= OBJECTS=Accept.o Address.o Datagram.o DatagramServer.o OSError.o Peer.o Probe.o Probe_select.o RecvFrom.o Resolve_gethostbyname.o Resolve_getservbyname.o ServerBase.o SockAddr.o SockOpt.o Socket.o Stream.o StreamBase.o StreamServer.o TARGETS=libNetxx.a libNetxx.so all: $(TARGETS) libNetxx.a: $(OBJECTS) $(AR) $(ARFLAGS) libNetxx.a $(OBJECTS) libNetxx.so: $(OBJECTS) $(SAR) $(SARFLAGS) -shared -o libNetxx.so -Wl,-soname,libNetxx.so.1 $(OBJECTS) $(POST_LDFLAGS) clean: - rm -f $(OBJECTS) $(TARGETS) *.core core realclean: clean - rm -f Makefile .SUFFIXES: .cxx .SUFFIXES: .obj .cxx.o: $(CXX) $(CXXFLAGS) -c $< .cxx.obj: $(CXX) $(CXXFLAGS) -c $< Netxx-0.3.2/src/RecvFrom.cxx0000644000175000017500000000641612173720353015144 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the implementation of the Netxx::call_recvfrom function. **/ // common header #include "common.h" // Netxx includes #include "RecvFrom.h" #include "OSError.h" #include "SockAddr.h" // system includes #if defined(WIN32) # include #else # include # include # include #endif // standard includes #include #include namespace Netxx { //#################################################################### std::pair call_recvfrom (Socket &socket, void *buffer, size_type length) { # if defined(WIN32) char *buffer_ptr = static_cast(buffer); # else void *buffer_ptr(buffer); # endif SockAddr socket_address(socket.get_type()); sockaddr *sa = socket_address.get_sa(); size_type sa_size = socket_address.get_sa_size(); signed_size_type rc; # if defined(WIN32) || defined(__APPLE__) || defined(__CYGWIN__) int *sa_size_ptr = reinterpret_cast(&sa_size); # else size_type *sa_size_ptr = &sa_size; # endif for (;;) { if ( (rc = recvfrom(socket.get_socketfd(), buffer_ptr, length, 0, sa, sa_size_ptr)) < 0) { error_type error_code = get_last_error(); if (error_code == EWOULDBLOCK) error_code = EAGAIN; switch (error_code) { case EAGAIN: return std::make_pair(static_cast(-1), Peer()); case EINTR: continue; default: { std::string error("recvfrom(2) failed: "); error += strerror(error_code); throw Exception(error); } } } return std::make_pair(rc, Peer(socket.get_socketfd(), sa, sa_size)); } } //#################################################################### } // end Netxx namespace Netxx-0.3.2/src/inet6.h0000644000175000017500000000457412173720353014076 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * The file contains structs, defines and functions to fake INET6 for * systems that do not yet support INET6. **/ #ifndef _Netxx_inet6_h_ #define _Netxx_inet6_h_ // system includes #if defined(WIN32) # include #else # include # include # include # include #endif #ifndef AF_LOCAL # define AF_LOCAL AF_UNIX #endif #ifndef PF_LOCAL # define PF_LOCAL PF_UNIX #endif #ifndef INET_ADDRSTRLEN # define INET_ADDRSTRLEN 16 #endif #ifndef INADDR_NONE # define INADDR_NONE static_cast(-1) #endif #if defined(NETXX_NO_INET6) /// INET6s inet_pton int inet_pton (int family, const char *strptr, void *addrptr); /// INET6s inet_ntop const char* inet_ntop (int family, const void *addrptr, char *strptr, size_t len); #endif #endif Netxx-0.3.2/src/Socket.h0000644000175000017500000002353612173720353014300 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the definition of the Netxx::Socket class. **/ #ifndef _Netxx_Socket_h_ #define _Netxx_Socket_h_ // Netxx includes #include #include #include "Probe_impl.h" namespace Netxx { class Timeout; /** * The Socket class is a wrapper around the operating system socket * functions. It is the low level socket interface for the Netxx code, due * to the fact that there are at least two higher level classes (Server and * Client). **/ class Socket { public: enum Type { TCP, ///< TCP IPv4 Address TCP6, ///< TCP IPv6 Address UDP, ///< UDP IPv4 Address UDP6, ///< UDP IPv6 Address LOCALSTREAM, ///< Unix Domain TCP LOCALDGRAM ///< Unix Domain UDP }; Socket (void); explicit Socket (Type type); //#################################################################### /** * Socket class ctor that creates a socket from a already connected * socket file descriptor. * * @param sockedfd The socket file descriptor to use * @author Peter Jones **/ //#################################################################### explicit Socket (socket_type socketfd); //#################################################################### /** * Socket class copy ctor. The ctor will copy the other socket, so * you will have two sockets with the same file desc. * * @param other The other Socket * @author Peter Jones **/ //#################################################################### Socket (const Socket &other); //#################################################################### /** * Assignment operator * * @param other The other Socket * @author Peter Jones **/ //#################################################################### Socket& operator= (const Socket& other); //#################################################################### /** * Swap this socket for another one. * * @param other The other Socket to swap with * @author Peter Jones **/ //#################################################################### void swap (Socket &other); //#################################################################### /** * Socket class dtor * * @author Peter Jones **/ //#################################################################### ~Socket (void); //#################################################################### /** * Read data from the socket and place it into the user buffer. If the given * timeout is not a null timeout then this method will only wait for data * until the timeout expires, at which time it will return -1. If you give a * null timeout, this method will block until data arives. * * @param buffer The user buffer to write data into * @param length The max bytes to place into buffer * @param timeout How long to wait for data to arive * @return The number of bytes read from the socket, or -1 for timeout * @author Peter Jones **/ //#################################################################### signed_size_type read (void *buffer, size_type length, const Timeout &timeout); //#################################################################### /** * Write data from a user buffer to the socket. If the given timeout * is not a null timeout then this method will only wait for the * socket to become writable until the timeout expires, at which * point it will return -1. If you give a null timeout then this * method will block until all data has been written to the socket. * * @param buffer The user buffer to read from * @param length The number of bytes to read from the user buffer * @return The number of bytes written, -1 for timeout * @author Peter Jones **/ //#################################################################### signed_size_type write (const void *buffer, size_type length, const Timeout &timeout); //#################################################################### /** * Check to see if there is data to read from a socket. If you give a valid * timeout then this method will only block for that timeout. * * @param timeout The amount of time to wait for the socket to become * readable * @return True if there is data to read, false otherwise * @author Peter Jones **/ //#################################################################### bool readable (const Timeout &timeout); //#################################################################### /** * Check to see if a socket can be written to. If you give a timeout * value then this method will not block longer then the timeout. * * @param timeout How long to wait for the socket to become writable. * @return True if you can write data to the socket, false otherwise * @author Peter Jones **/ //#################################################################### bool writable (const Timeout &timeout); //#################################################################### /** * Check to see if a socket can be read from or written to. If you give * a timeout value then this method will not block longer then the * timeout. * * @param timeout How long to wait for the socket to become writable. * @return True if you can read from or write to the socket. * @reutrn False if there is a timeout. * @author Peter Jones **/ //#################################################################### bool readable_or_writable (const Timeout &timeout); //#################################################################### /** * Close the socket. * * @author Peter Jones **/ //#################################################################### void close (void); //#################################################################### /** * Release the socket fd so that it won't be closed by the close * member function or the dtor. * * @author Peter Jones **/ //#################################################################### void release (void); //#################################################################### /** * Get the socket type. This value is only valid when a socket is * constructed with a type or with another socket that was constructed * with a type. * * @return The socket type. * @author Peter Jones **/ //#################################################################### Type get_type (void) const; //#################################################################### /** * Get the file descriptor for this socket. * * @return The fd for this socket * @author Peter Jones **/ //#################################################################### socket_type get_socketfd (void) const; //#################################################################### /** * Set the socket file descriptor. This will close the current * descriptor if needed and reset this Socket to control the new socket * file descriptor. That means that the Socket destructor will close the * given file descriptor unless you call the release function. * * @param socketfd The socket file descriptor to take over * @author Peter Jones **/ //#################################################################### void set_socketfd (socket_type socketfd); //#################################################################### /** * Find out if the socket is open and ready * * @return True if socket is NOT ready * @author Peter Jones **/ //#################################################################### bool operator! (void) const; bool operator< (const Socket &other) const; bool operator< (socket_type socketfd) const; private: socket_type socketfd_; bool probe_ready_; bool type_ready_; Probe_impl probe_; Type type_; }; // end Netxx::Socket bool operator== (const Socket &first, const Socket &second); bool operator!= (const Socket &first, const Socket &second); } // end Netxx namespace #endif Netxx-0.3.2/src/Accept.cxx0000644000175000017500000000626112173720353014616 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the implementation of the call_accept function. **/ // common header #include "common.h" // Netxx includes #include "Accept.h" #include "Netxx/SockOpt.h" #include "Netxx/Types.h" #include "SockAddr.h" #include "Socket.h" #include "OSError.h" // system includes #if defined (WIN32) # include #else # include # include # include # include # include # include # include #endif namespace Netxx { //#################################################################### Peer call_accept (Socket &socket, bool dont_block) { SockOpt socket_options(socket.get_socketfd(), true); if (dont_block) socket_options.set_non_blocking(); SockAddr socket_address(socket.get_type()); sockaddr *sa = socket_address.get_sa(); size_type sa_size = socket_address.get_sa_size(); # if defined(WIN32) || defined(__APPLE__) || defined (__CYGWIN__) int *sa_size_ptr = reinterpret_cast(&sa_size); # else size_type *sa_size_ptr = &sa_size; # endif for (;;) { socket_type client = accept(socket.get_socketfd(), sa, sa_size_ptr); if (client >= 0) return Peer(client, sa, sa_size); error_type error_code = get_last_error(); switch (error_code) { case EINTR: continue; case EWOULDBLOCK: case ECONNABORTED: return Peer(); default: { std::string error("accept(2) error: "); error += strerror(error_code); throw Netxx::Exception(error); } } } } //#################################################################### } // end Netxx namespace Netxx-0.3.2/src/OSError.cxx0000644000175000017500000000350412173720353014747 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains definitions for OS error functions. **/ // declaration include #include "OSError.h" namespace Netxx { error_type get_last_error (void) { # if defined (WIN32) return WSAGetLastError(); # else return errno; # endif } } Netxx-0.3.2/src/inet6.cxx0000644000175000017500000000602712173720353014444 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * The file contains structs, defines and functions to fake INET6 * for systems that do not yet support INET6. **/ // common header #include "common.h" // declaration include #include "inet6.h" // system includes #if defined(WIN32) # include # include # define snprintf _snprintf #else # include # include #endif // standard includes #include //#################################################################### int inet_pton (int family, const char *strptr, void *addrptr) { if (family == AF_INET) { unsigned long in_val; if ( (in_val = inet_addr(strptr)) != INADDR_NONE) { in_addr in_struct; std::memset(&in_struct, 0, sizeof(in_struct)); in_struct.s_addr = in_val; std::memcpy(addrptr, &in_struct, sizeof(in_struct)); return 1; } return 0; } # ifndef WIN32 errno = EAFNOSUPPORT; # endif return -1; } //#################################################################### const char *inet_ntop (int family, const void *addrptr, char *strptr, size_t len) { const unsigned char *p = reinterpret_cast(addrptr); if (family == AF_INET) { char temp[INET_ADDRSTRLEN]; snprintf(temp, sizeof(temp), "%d.%d.%d.%d", p[0], p[1], p[2], p[3]); if (std::strlen(temp) >= len) { # ifndef WIN32 errno = ENOSPC; # endif return 0; } std::strcpy(strptr, temp); return strptr; } # ifndef WIN32 errno = EAFNOSUPPORT; # endif return 0; } Netxx-0.3.2/src/Socket.cxx0000644000175000017500000002632412173720353014651 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the implementation for the Netxx::Socket class along * with some helper functions. **/ // common header #include "common.h" // Netxx includes #include "Socket.h" #include "Netxx/Timeout.h" #include "OSError.h" // system includes #if defined(WIN32) # include # include #else # include # include # include # include # include # include #endif // standard includes #include #include #include #include //#################################################################### namespace { void get_domain_and_type (Netxx::Socket::Type stype, int &domain, int &type); } //#################################################################### Netxx::Socket::Socket (void) : socketfd_(-1), probe_ready_(false), type_ready_(false) { # if defined(WIN32) WSADATA wsdata; if (WSAStartup(MAKEWORD(2,2), &wsdata) != 0) { throw Exception("failed to load WinSock"); } # endif } //#################################################################### Netxx::Socket::Socket (Type type) : socketfd_(-1), probe_ready_(false), type_ready_(true), type_(type) { # if defined(WIN32) WSADATA wsdata; if (WSAStartup(MAKEWORD(2,2), &wsdata) != 0) { throw Exception("failed to load WinSock"); } # endif int socket_domain=0; socket_type socket_type=0, socket_fd=0; get_domain_and_type(type, socket_domain, socket_type); if ( (socket_fd = socket(socket_domain, socket_type, 0)) < 0) { std::string error("failure from socket(2): "); error += strerror(get_last_error()); throw Exception(error); } socketfd_ = socket_fd; } //#################################################################### Netxx::Socket::Socket (int socketfd) : socketfd_(socketfd), probe_ready_(false), type_ready_(false) { # if defined(WIN32) WSADATA wsdata; if (WSAStartup(MAKEWORD(2,2), &wsdata) != 0) { throw Exception("failed to load WinSock"); } # endif } //#################################################################### Netxx::Socket::Socket (const Socket &other) : probe_ready_(false), type_ready_(other.type_ready_), type_(other.type_) { if (other.socketfd_ != -1) { socket_type dup_socket; # if defined(WIN32) WSADATA wsdata; if (WSAStartup(MAKEWORD(2,2), &wsdata) != 0) throw Exception("failed to load WinSock"); WSAPROTOCOL_INFO proto_info; std::memset(&proto_info, 0, sizeof(proto_info)); if (WSADuplicateSocket(other.socketfd_, GetCurrentProcessId(), &proto_info)) { throw Exception("failed to duplicate socket"); } if ( (dup_socket = WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, &proto_info, 0, WSA_FLAG_OVERLAPPED)) == INVALID_SOCKET) { throw Exception("failed to init duplicated socket"); } # else dup_socket = dup(other.socketfd_); if (dup_socket < 0) { std::string error("dup(2) call failed: "); error += strerror(get_last_error()); throw Exception(error); } # endif socketfd_ = dup_socket; } else { socketfd_ = -1; } } //#################################################################### Netxx::Socket& Netxx::Socket::operator= (const Socket &other) { Socket tmp(other); swap(tmp); return *this; } //#################################################################### void Netxx::Socket::swap (Socket &other) { std::swap(socketfd_, other.socketfd_); std::swap(type_ready_, other.type_ready_); std::swap(type_, other.type_); probe_ready_ = other.probe_ready_ = false; probe_.clear(); other.probe_.clear(); } //#################################################################### Netxx::Socket::~Socket (void) { close(); # if defined(WIN32) WSACleanup(); # endif } //#################################################################### Netxx::signed_size_type Netxx::Socket::write (const void *buffer, size_type length, const Timeout &timeout) { const char *buffer_ptr = static_cast(buffer); signed_size_type rc, bytes_written=0; while (length) { if (timeout && !writable(timeout)) return -1; if ( (rc = send(socketfd_, buffer_ptr, length, 0)) < 0) { error_type error_code = get_last_error(); if (error_code == EWOULDBLOCK) error_code = EAGAIN; switch (error_code) { case EPIPE: case ECONNRESET: return 0; case EINTR: continue; case EAGAIN: return -1; #if defined(WIN32) case WSAENETRESET: case WSAESHUTDOWN: case WSAEHOSTUNREACH: case WSAECONNABORTED: case WSAETIMEDOUT: return 0; #endif default: { std::string error("send failed: "); error += strerror(error_code); throw Exception(error); } } } buffer_ptr += rc; bytes_written += rc; length -= rc; } return bytes_written; } //#################################################################### Netxx::signed_size_type Netxx::Socket::read (void *buffer, size_type length, const Timeout &timeout) { signed_size_type rc; # if defined(WIN32) char *buffer_ptr = static_cast(buffer); # else void *buffer_ptr(buffer); # endif for (;;) { if (timeout && !readable(timeout)) return -1; if ( (rc = recv(socketfd_, buffer_ptr, length, 0)) < 0) { error_type error_code = get_last_error(); if (error_code == EWOULDBLOCK) error_code = EAGAIN; switch (error_code) { case ECONNRESET: return 0; case EINTR: continue; case EAGAIN: return -1; #if defined(WIN32) case WSAEMSGSIZE: return length; case WSAENETRESET: case WSAESHUTDOWN: case WSAECONNABORTED: case WSAETIMEDOUT: // FIXME should this be return -1? return 0; #endif default: { std::string error("recv failure: "); error += strerror(error_code); throw Exception(error); } } } break; } return rc; } //#################################################################### bool Netxx::Socket::readable (const Timeout &timeout) { if (!probe_ready_) { probe_.add(socketfd_); probe_ready_ = true; } Probe_impl::probe_type pt = probe_.probe(timeout, Probe::ready_read); if (pt.empty()) return false; return true; } //#################################################################### bool Netxx::Socket::writable (const Timeout &timeout) { if (!probe_ready_) { probe_.add(socketfd_); probe_ready_ = true; } Probe_impl::probe_type pt = probe_.probe(timeout, Probe::ready_write); if (pt.empty()) return false; return true; } //#################################################################### bool Netxx::Socket::readable_or_writable (const Timeout &timeout) { if (!probe_ready_) { probe_.add(socketfd_); probe_ready_ = true; } Probe_impl::probe_type pt = probe_.probe(timeout, Probe::ready_read|Probe::ready_write); if (pt.empty()) return false; return true; } //#################################################################### void Netxx::Socket::close (void) { if (socketfd_ != -1) { # if defined(WIN32) closesocket(socketfd_); # else ::close(socketfd_); # endif socketfd_ = -1; } } //#################################################################### void Netxx::Socket::release (void) { socketfd_ = -1; } //#################################################################### Netxx::Socket::Type Netxx::Socket::get_type (void) const { if (!type_ready_) throw Exception("Netxx bug: Socket::get_type called when !type_ready_"); return type_; } //#################################################################### int Netxx::Socket::get_socketfd (void) const { return socketfd_; } //#################################################################### void Netxx::Socket::set_socketfd (socket_type socketfd) { close(); probe_ready_ = false; socketfd_ = socketfd; probe_.clear(); } //#################################################################### bool Netxx::Socket::operator! (void) const { return socketfd_ == -1; } //#################################################################### bool Netxx::Socket::operator< (const Socket &other) const { return socketfd_ < other.socketfd_; } //#################################################################### bool Netxx::Socket::operator< (socket_type socketfd) const { return socketfd_ < socketfd; } //#################################################################### bool Netxx::operator== (const Netxx::Socket &first, const Netxx::Socket &second) { return first.get_socketfd() == second.get_socketfd(); } //#################################################################### bool Netxx::operator!= (const Netxx::Socket &first, const Netxx::Socket &second) { return !(first == second); } //#################################################################### namespace { //#################################################################### void get_domain_and_type (Netxx::Socket::Type stype, int &domain, int &type) { switch (stype) { case Netxx::Socket::TCP: domain = PF_INET; type = SOCK_STREAM; break; case Netxx::Socket::UDP: domain = PF_INET; type = SOCK_DGRAM; break; # ifndef NETXX_NO_INET6 case Netxx::Socket::TCP6: domain = PF_INET6; type = SOCK_STREAM; break; case Netxx::Socket::UDP6: domain = PF_INET6; type = SOCK_DGRAM; break; # endif # ifndef WIN32 case Netxx::Socket::LOCALSTREAM: domain = PF_LOCAL; type = SOCK_STREAM; break; case Netxx::Socket::LOCALDGRAM: domain = PF_LOCAL; type = SOCK_DGRAM; break; # endif default: domain = PF_INET; type = SOCK_STREAM; break; } } //#################################################################### } // end anonymous namespace Netxx-0.3.2/src/TLS_cert_pimpl.h0000644000175000017500000000474612173720353015732 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ #ifndef _Netxx_TLS_cert_pimpl_h_ #define _Netxx_TLS_cert_pimpl_h_ // Netxx Includes #include // OpenSSL Includes #include namespace Netxx { namespace TLS { class cert_impl : public Certificate { public: cert_impl (void); ~cert_impl (void); operator void* (void) const; bool operator! (void) const; std::string get_fqdn (void) const; std::string get_country (void) const; std::string get_locality (void) const; std::string get_region (void) const; std::string get_organization (void) const; std::string get_organization_unit (void) const; void set (X509 *x, X509_NAME *xn); private: std::string get_text (int nid) const; cert_impl (const cert_impl&); cert_impl& operator= (const cert_impl&); X509 *x509_; X509_NAME *x509_name_; }; // end Netxx::TLS::cert_impl class }} // namespace Netxx & namespace TLS #endif Netxx-0.3.2/src/ServerBase.cxx0000644000175000017500000001623512173720353015462 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ /** @file * This file contains the implementation of the Netxx::ServerBase class. **/ // common header #include "common.h" // Netxx includes #include "ServerBase.h" #include "Netxx/Address.h" #include "Netxx/SockOpt.h" #include "Netxx/ProbeInfo.h" #include "OSError.h" #include "Socket.h" // system includes #if defined(WIN32) # include #else # include # include # include # include # include # include # include # include # include #endif // standard includes #include #include #include #include //#################################################################### namespace { # ifndef WIN32 struct unlink_functor : public std::unary_function { void operator() (const std::string &file) { unlink(file.c_str()); } }; # endif } //#################################################################### Netxx::ServerBase::ServerBase (const Timeout &timeout) : timeout_(timeout), sockets_(0), sockets_size_(0) { /* must not call bind_to from here */ } //#################################################################### Netxx::ServerBase::~ServerBase (void) { # ifndef WIN32 if (sockets_ && !files_.empty()) { std::for_each(sockets_, sockets_ + sockets_size_, std::mem_fun_ref(&Socket::close)); std::for_each(files_.begin(), files_.end(), unlink_functor()); } # endif if (sockets_) delete [] sockets_; } //#################################################################### void Netxx::ServerBase::bind_to(const Address &addr, bool stream_server) { if (sockets_) throw Exception("bug in Netxx, ServerBase::sockets_ != 0"); /* * it is safe to allocate this block of memory because the destructor * will free it even if this function dies with an exception. */ sockets_size_ = addr.size(); sockets_ = new Socket[sockets_size_]; /* * now that we have an array of sockets we need to walk through each one * and set it up. We will use a temporay socket and make it call * socket() for us. Then we can set the reuse address socket option and * call bind. */ Address::const_iterator addr_it=addr.begin(), addr_end=addr.end(); for (size_type current_socket=0; addr_it != addr_end; ++addr_it, ++current_socket) { const sockaddr *sa = static_cast(addr_it->get_sa()); size_type sa_size = addr_it->get_sa_size(); Socket::Type stype; switch (sa->sa_family) { case AF_INET: stype = stream_server ? Socket::TCP : Socket::UDP; break; # ifndef NETXX_NO_INET6 case AF_INET6: stype = stream_server ? Socket::TCP6 : Socket::UDP6; break; # endif # ifndef WIN32 case AF_LOCAL: stype = stream_server ? Socket::LOCALSTREAM : Socket::LOCALDGRAM; break; # endif default: stype = stream_server ? Socket::TCP : Socket::UDP; break; } Socket tmp_socket(stype); socket_type socketfd = tmp_socket.get_socketfd(); tmp_socket.swap(sockets_[current_socket]); SockOpt socket_opt(socketfd); socket_opt.set_reuse_address(); if (bind(socketfd, sa, sa_size) != 0) { std::string error("bind(2) error: "); error += strerror(Netxx::get_last_error()); throw Exception(error); } sockets_map_[socketfd] = &(sockets_[current_socket]); pi_.add_socket(socketfd); # ifndef WIN32 /* * check to see if we need to record a filename. we would need * to record a filename for local domain sockets in order to * remove the file when the server is done with it. * * also take this time to set the mode for the socket file to * something sane. this may be a bad assumption here but I think * this is a good value for a domain socket. */ if (sa->sa_family == AF_LOCAL) { const sockaddr_un *saun = reinterpret_cast(sa); /* * This will make a local domain socket more like a real * socket since anyone with local file system access can * connect to it. */ chmod(saun->sun_path, 0666); if (saun->sun_path[0] == '/') { files_.push_back(saun->sun_path); } else { char buffer[MAXPATHLEN]; if (getcwd(buffer, sizeof(buffer))) { std::string fullpath = buffer; fullpath += '/'; fullpath += saun->sun_path; files_.push_back(fullpath); } else { files_.push_back(saun->sun_path); } } } # endif } probe_.add(*this); } //#################################################################### void Netxx::ServerBase::get_socket_list (Socket *&sockets, size_type &size) { sockets = sockets_; size = sockets_size_; } //#################################################################### Netxx::Socket* Netxx::ServerBase::get_readable_socket (void) { Probe::result_type rt = probe_.ready(timeout_, Probe::ready_read); if (rt.first == -1) return 0; return sockets_map_[rt.first]; } //#################################################################### void Netxx::ServerBase::set_timeout (const Timeout &timeout) { timeout_ = timeout; } //#################################################################### const Netxx::Timeout& Netxx::ServerBase::get_timeout (void) const { return timeout_; } //#################################################################### const Netxx::ProbeInfo* Netxx::ServerBase::get_probe_info (void) const { return &pi_; } //#################################################################### bool Netxx::ServerBase::has_socket (socket_type socketfd) const { return sockets_map_.find(socketfd) != sockets_map_.end(); } //#################################################################### Netxx-0.3.2/Netxx-config0000755000175000017500000000143712173720353014403 0ustar danieldaniel#! /bin/sh ## # This file was auto-generated by genconfig on Mon Jul 18 20:54:17 2005 ## usage() { cat < # include #else # include # include #endif int main (void) { int fd = socket(PF_INET, SOCK_STREAM, 0); return 0; } Netxx-0.3.2/tests/build/test.pl0000755000175000017500000001430412173720353015661 0ustar danieldaniel#!/usr/bin/perl ###################################################################### # Copyright (C) 2001-2003 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. ################################################################################ # # test.pl (Build Test Driver for Netxx) # Peter J Jones (pjones@pmade.org) # ################################################################################ # # Includes # ################################################################################ use strict; use Getopt::Long; ################################################################################ # # Constants # ################################################################################ use constant DATE => 'Mon Jul 23 17:38:36 2001'; use constant ID => '$Id: test.pl,v 1.1 2003/08/12 06:28:53 jason Exp $'; ################################################################################ # # Global Variables # ################################################################################ my $cf_file = "test-out.cf"; my $broken_vector = <$cf_file") || die "$0: can't open $cf_file: $!\n"; #### my @vector = 0..99; my $vector_forward = join(" ", @vector); my $vector_reverse = join(" ", reverse @vector); my @output; print " checking std::vector for continous memory ... "; unless (compile("vector2array.cxx")) { print "failed to compile\n"; exit 1} print "... "; chomp(@output = `./vector2array$exe 2>&1`); print "... "; foreach (@output) {s/[\r\n]//g; s/^\s+//; s/\s+$//;} if ($output[1] ne $vector_forward || $output[2] ne $vector_reverse) { print "test failed\n"; print $broken_vector; if ($clo{'debug'}) { print "1: $vector_forward\n\n"; print "2: $vector_reverse\n\n"; print "3: $output[0]\n\n"; print "4: $output[1]\n\n"; print "5: $output[2]\n\n"; } exit 1; } print "... okay\n"; #### socket libraries print " checking to see if we must link with a socket library ... "; if (compile("socket.cxx", 0, $ENV{'LDFLAGS'})) { print "no\n"; } else { if (compile("socket.cxx", 0, "$ENV{'LDFLAGS'} -lsocket -lnsl")) { print "yes\n"; print CF "libsocket = yes\n"; $use_socket_lib=1; } else { print "error\n"; print "*** I can't seem to link a socket program!\n"; exit 1; } } #### IPv6 print " checking to see if you have support for IPv6 ... "; if (compile("inet6.cxx", 1)) { print "yes\n"; } else { print "no\n"; print CF "inet6 = no\n"; } #### openssl if ($clo{'enable-tls'}) { print " checking for TLS library (OpenSSL >= 0.9.6) ... "; my $extra = ''; if ($clo{'openssl-include'}) { $ENV{'CXXFLAGS'} .= " -I$clo{'openssl-include'}"; } if ($clo{'openssl-lib'}) { $extra .= " -L$clo{'openssl-lib'}"; } $extra .= " -lssl -lcrypto "; $extra .= " -lsocket -lnsl " if $use_socket_lib; if (compile("openssl.cxx", 0, $extra)) { print "yes\n"; } else { print "no\n"; print $no_openssl_message; exit 1; } } sub compile { my $filename = shift; my $just_object = shift; my $extra = shift||''; my $answer; print "debug\n" if $clo{'debug'}; if ($just_object) { print "DEBUG: $ENV{CXX} $ENV{CXXFLAGS} -c $filename\n" if $clo{'debug'}; my $out = `$ENV{CXX} $ENV{CXXFLAGS} -c $filename 2>&1`; $answer = !$?; if ($filename =~ s/(c|cxx|cc|cpp)$/o/) { push @files_to_unlink, $filename; } print "DEBUG: complier said ...\n$out\n" if $clo{'debug'} } else { my $binary; ($binary = $filename) =~ s/\.(c|cxx|cc|cpp)$//; $binary .= $exe; push(@files_to_unlink, $binary); chomp($binary = `$^X $clo{'cxxflags'} --mkexec $binary`); print "DEBUG: $ENV{CXX} $ENV{CXXFLAGS} $binary $filename $extra\n" if $clo{'debug'}; my $out = `$ENV{CXX} $ENV{CXXFLAGS} $binary $filename $extra 2>&1`; $answer = !$?; print "DEBUG: complier said ...\n$out\n" if $clo{'debug'} } print " .............. final answer: " if $clo{'debug'}; return $answer; } END { unlink @files_to_unlink; } Netxx-0.3.2/tests/build/vector2array.cxx0000644000175000017500000000453212173720353017513 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ #include #include struct test { int a; bool b; long c; char d; float e; }; void use_as_array (test *test_array, int size); int main (int argc, char *argv[]) { std::vector test_vector; const int size = 100; for (int i=0; i int main (void) { SSL_library_init(); return 0; } Netxx-0.3.2/tests/build/inet6.cxx0000644000175000017500000000326612173720353016120 0ustar danieldaniel/* * Copyright (C) 2001-2003 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. */ #include #include int main (void) { int fd = socket(PF_INET6, SOCK_STREAM, 0); return 0; } Netxx-0.3.2/tests/harness/0000755000175000017500000000000012173720372014705 5ustar danieldanielNetxx-0.3.2/tests/harness/harness.pm0000644000175000017500000001453412173720353016714 0ustar danieldanielpackage harness; ########################################################################### # Copyright (C) 2001-2003 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. ########################################################################### # # Test harness code. For generating screen output and XML output. # $Id: harness.pm,v 1.1 2003/08/12 06:28:53 jason Exp $ # # To use: # # $mytest = harness->new("Name of My test"); # # $mytest->start("sub test one"); # # $mytest->pass; # # -- or -- # # $mytest->fail("reason the test failed") # ########################################################################### use strict; ########################################################################### my $color_red = ''; my $color_green = ''; my $color_blue = ''; my $color_magenta = ''; my $color_reset = ''; my $wchar = 78; ########################################################################### eval { require Term::ANSIColor; import Term::ANSIColor; if (-t STDOUT) { $color_red = color("red"); $color_green = color("green"); $color_blue = color("blue"); $color_magenta = color("magenta"); $color_reset = color("reset"); } require Term::ReadKey; import Term::ReadKey; ($wchar, undef, undef, undef) = GetTerminalSize(); $wchar -= 4; # Term::ReadKey can sometimes be off by a few columns }; ########################################################################### sub new { my $class = shift; my $test_name = shift; if (not defined $test_name) { die "missing test name paramenter to harness->new()"; } my $self = bless({ 'name' => $test_name , 'xml' => ($ENV{'HARNESS_XML'} ? 1 : 0), 'time' => time, 'tests' => 0, 'pass' => 0, 'fail' => 0, 'die_on_fail' => 0, 'die_on_end' => 1, }, $class); if ($ENV{'HARNESS_XML_FILE'}) { $self->{'xml'} = 1; unless (open(XMLOUT, ">>$ENV{HARNESS_XML_FILE}")) { print STDERR "harness: can't open XML output file $ENV{HARNESS_XML_FILE}: $!\n"; exit 1; } select XMLOUT; } if ($self->xml) { print qq(\n); } else { print "${color_magenta}$test_name "; print '-' x ($wchar - length($test_name) - 1); print "${color_reset}\n"; } return $self; } ########################################################################### sub start { my $self = shift; my $test_name = shift; if (not defined $test_name) { die "missing test name parameter to harness->start()"; } $self->{'last_test_name'} = $test_name; if (not $self->xml) { print "$test_name "; $self->dots; } ++$self->{'tests'}; } ########################################################################### sub pass { my $self = shift; if ($self->xml) { print qq(\n); } else { print " [ ${color_green}OKAY${color_reset} ]\n"; } ++$self->{'pass'}; } ########################################################################### sub fail { my $self = shift; my $info = shift; if (not defined $info) { die "missing failure info paramenter to harness->fail()"; } if ($self->xml) { print qq(\n); } else { print " [ ${color_red}FAIL${color_reset} ]\n"; print "${color_red}", ('-' x $wchar), "${color_reset}\n"; print "$info"; print "\n" unless substr($info, -1, 1) eq "\n"; print "${color_red}", ('-' x $wchar), "${color_reset}\n"; if ($self->{'die_on_fail'}) { print STDERR "test failure for $self->{last_test_name}: $info\n"; exit 1; } } ++$self->{'fail'}; } ########################################################################### sub die_on_fail { my $self = shift; my $state = shift || 1; $self->{'die_on_fail'} = $state; } ########################################################################### sub die_on_end { my $self = shift; my $state = shift || 1; $self->{'die_on_end'} = $state; } ########################################################################### sub xml { return $_[0]->{'xml'}; } ########################################################################### sub dots { print '.' x ($wchar - length($_[0]->{'last_test_name'}) - 8) } ########################################################################### sub DESTROY { my $self = shift; if ($self->xml) { print qq(\n); } else { print "${color_magenta}"; print '-' x $wchar; print "${color_reset}\n"; print "Tests Passed: [ ${color_green}$self->{pass}${color_reset} ] "; print "Tests Failed: [ ${color_red}$self->{fail}${color_reset} ] "; print "Total Tests: [ ${color_blue}$self->{tests}${color_reset} ]\n"; print "${color_magenta}"; print '-' x $wchar; print "${color_reset}\n"; if ($self->{'die_on_end'} and $self->{'fail'}) { exit 1; } } } ########################################################################### 1; Netxx-0.3.2/tests/io/0000755000175000017500000000000012173720372013651 5ustar danieldanielNetxx-0.3.2/tests/io/stream_server.cxx0000644000175000017500000000243712173720353017263 0ustar danieldaniel#include #include #include #include #include #include #include int main (int argc, char *argv[]) { if (argc != 3) { std::cerr << "Usage: " << argv[0] << " address size\n"; return 1; } try { Netxx::Address addr; addr.add_address(argv[1], 0); Netxx::size_type buffer_size = std::atoi(argv[2]); char *buffer = new char[buffer_size]; Netxx::StreamServer server(addr, Netxx::Timeout(30)); Netxx::Peer peer = server.accept_connection(); if (!peer) throw std::runtime_error("bad peer"); Netxx::Stream client(peer.get_socketfd(), Netxx::Timeout(2)); Netxx::signed_size_type bytes_aval=buffer_size, bytes_read; char *bufptr = buffer; while (bytes_aval) { if ( (bytes_read = client.read(bufptr, bytes_aval)) <= 0) throw std::runtime_error("failed to read data from client"); bufptr += bytes_read; bytes_aval -= bytes_read; } bytes_aval = buffer_size; if (client.write(buffer, buffer_size) != bytes_aval) throw std::runtime_error("failed to write buffer to client"); } catch (std::exception &e) { std::cerr << e.what() << std::endl; return 1; } catch ( ... ) { std::cerr << "caught unknown exception\n"; return 1; } return 0; } Netxx-0.3.2/tests/io/Makefile0000644000175000017500000000067012173720353015313 0ustar danieldanielTARGETS=stream_client stream_server PERL=/usr/bin/perl BASEDIR=../.. NETXX=${BASEDIR}/src/libNetxx.a CXXFLAGS+=-I${BASEDIR}/include all: ${TARGETS} test: ${TARGETS} ${PERL} test_stream.pl stream_client: stream_client.o ${CXX} ${CXXFLAGS} -o $@ stream_client.o ${NETXX} stream_server: stream_server.o ${CXX} ${CXXFLAGS} -o $@ stream_server.o ${NETXX} clean: rm -f ${TARGETS} *.o .SUFFIXES: .cxx .cxx.o: $(CXX) $(CXXFLAGS) -c $< Netxx-0.3.2/tests/io/stream_client.cxx0000644000175000017500000000330712173720353017230 0ustar danieldaniel#include #include #include #include #include #include #include #include #include int main (int argc, char *argv[]) { if (argc != 4) { std::cerr << "Usage: " << argv[0] << " address file size\n"; return 1; } try { Netxx::Stream client(argv[1], 0, Netxx::Timeout(2)); std::ifstream file(argv[2]); if (!file) throw std::runtime_error("failed to open input file"); Netxx::size_type buffer_size = std::atoi(argv[3]); char *buffer = new char[buffer_size]; char *return_buffer = new char[buffer_size]; file.read(buffer, buffer_size); if (!file || file.gcount() != buffer_size) { std::ostringstream error; error << "read from file did not give the correct byte count, "; error << "gcount said: " << file.gcount(); error << " but I expected: " << buffer_size; throw std::runtime_error(error.str()); } if (client.write(buffer, buffer_size) != buffer_size) throw std::runtime_error("write to server did not send the correct byte count"); Netxx::signed_size_type bytes_read=0, buffer_aval=buffer_size; char *bufptr = return_buffer; while (buffer_aval) { if ( (bytes_read = client.read(bufptr, buffer_aval)) <= 0) throw std::runtime_error("read from server was less than or equal to 0"); bufptr += bytes_read; buffer_aval -= bytes_read; } if (std::memcmp(buffer, return_buffer, buffer_size) != 0) throw std::runtime_error("buffer mismatch"); } catch (std::exception &e) { std::cerr << e.what() << std::endl; return 1; } catch ( ... ) { std::cerr << "an unknown exception was caught" << std::endl; return 1; } return 0; } Netxx-0.3.2/tests/io/test_stream.pl0000755000175000017500000000230412173720353016541 0ustar danieldaniel#!/usr/bin/perl use strict; use lib qw(../harness); use harness; my $client = "stream_client"; my $server = "stream_server"; if ($^O =~ /mswin/) { $client .= ".exe"; $server .= ".exe"; } else { $client = "./$client"; $server = "./$server"; } my @addresses = qw( localhost:5005 local://stream_socket ); my $max_send = 4096; my $interval = 512; if ((stat($client))[7] <= $max_send) { print STDERR "$0: client binary is too small for test\n"; exit 1; } my $test = harness->new("Stream IO"); foreach my $addr (@addresses) { for (my $i=$interval; $i<=$max_send; $i += $interval) { $test->start("$addr with $i bytes"); run_server($addr, $i); select(undef, undef, undef, 0.75); my $out = `$client $addr $client $i 2>&1`; if ($? == 0) { $test->pass; } else { if (not defined $out or not length($out)) { $out = "unknown error"; } $test->fail($out); } } } $test->start("Bad Address"); my $out = `$client cant_resolve_this_name.fake 1024 2>&1`; if ($? == 0) { $test->fail("test should have triggerd return != 0"); } else { $test->pass(); } sub run_server { my ($address, $bytes) = @_; system("$server $address $bytes > /dev/null 2>&1 &"); }