From fffd213c8cba2135afda493d797c41c10354770e Mon Sep 17 00:00:00 2001 From: Othmar Gsenger Date: Sat, 12 Apr 2008 11:38:42 +0000 Subject: big svn cleanup --- Anycast VOIP Proxy Resultat und Meilensteine.pdf | Bin 24937 -> 0 bytes Anycast VOIP Proxy Zeitplan.pdf | Bin 10546 -> 0 bytes Doxyfile | 1252 -- Makefile | 299 - PracticalSocket.cpp | 473 - PracticalSocket.h | 400 - README | 2 +- Sockets/Ajp13Socket.cpp | 404 - Sockets/Ajp13Socket.h | 69 - Sockets/AjpBaseSocket.cpp | 258 - Sockets/AjpBaseSocket.h | 83 - Sockets/Base64.cpp | 272 - Sockets/Base64.h | 77 - Sockets/Debug.cpp | 79 - Sockets/Debug.h | 75 - Sockets/DevCpp/Sockets.dev | 1129 -- Sockets/DevCpp/Test.dev | 59 - Sockets/Event.cpp | 85 - Sockets/Event.h | 76 - Sockets/EventHandler.cpp | 223 - Sockets/EventHandler.h | 85 - Sockets/EventTime.cpp | 105 - Sockets/EventTime.h | 77 - Sockets/Exception.cpp | 48 - Sockets/Exception.h | 58 - Sockets/File.cpp | 169 - Sockets/File.h | 84 - Sockets/HTTPSocket.cpp | 413 - Sockets/HTTPSocket.h | 152 - Sockets/HttpBaseSocket.cpp | 204 - Sockets/HttpBaseSocket.h | 76 - Sockets/HttpClientSocket.cpp | 277 - Sockets/HttpClientSocket.h | 121 - Sockets/HttpDebugSocket.cpp | 125 - Sockets/HttpDebugSocket.h | 70 - Sockets/HttpGetSocket.cpp | 114 - Sockets/HttpGetSocket.h | 66 - Sockets/HttpPostSocket.cpp | 294 - Sockets/HttpPostSocket.h | 94 - Sockets/HttpPutSocket.cpp | 125 - Sockets/HttpPutSocket.h | 83 - Sockets/HttpRequest.cpp | 358 - Sockets/HttpRequest.h | 125 - Sockets/HttpResponse.cpp | 201 - Sockets/HttpResponse.h | 82 - Sockets/HttpTransaction.cpp | 244 - Sockets/HttpTransaction.h | 94 - Sockets/HttpdCookies.cpp | 270 - Sockets/HttpdCookies.h | 89 - Sockets/HttpdForm.cpp | 616 - Sockets/HttpdForm.h | 118 - Sockets/HttpdSocket.cpp | 528 - Sockets/HttpdSocket.h | 106 - Sockets/IBase.h | 44 - Sockets/IEventHandler.h | 75 - Sockets/IEventOwner.cpp | 79 - Sockets/IEventOwner.h | 77 - Sockets/IFile.h | 71 - Sockets/IHttpServer.h | 56 - Sockets/ISocketHandler.h | 233 - Sockets/Ipv4Address.cpp | 214 - Sockets/Ipv4Address.h | 98 - Sockets/Ipv6Address.cpp | 270 - Sockets/Ipv6Address.h | 107 - Sockets/ListenSocket.h | 420 - Sockets/Lock.cpp | 55 - Sockets/Lock.h | 59 - Sockets/Makefile | 154 - Sockets/Makefile.Defines.linux-x86-32 | 28 - Sockets/Makefile.Defines.macosx | 28 - Sockets/Makefile.Defines.solaris8 | 29 - Sockets/Makefile.Defines.solaris9-sparc-64 | 29 - Sockets/Makefile.Defines.win32-cygwin | 26 - Sockets/Makefile.solaris9-sparc-64 | 70 - Sockets/Makefile.version | 49 - Sockets/MemFile.cpp | 288 - Sockets/MemFile.h | 100 - Sockets/Mutex.cpp | 81 - Sockets/Mutex.h | 68 - Sockets/OSX.zip | Bin 16669 -> 0 bytes Sockets/Parse.cpp | 321 - Sockets/Parse.h | 101 - Sockets/Project.net/Sockets/Sockets.sln | 30 - Sockets/Project.net/Sockets/Sockets.vcproj | 452 - Sockets/Project.net/Test/Test.vcproj | 140 - Sockets/Project/Sockets.dsp | 526 - Sockets/Project/Sockets.dsw | 68 - Sockets/Project/Test.dsp | 102 - Sockets/Project/echoserver.dsp | 100 - Sockets/Project/stressclient.dsp | 100 - Sockets/README.macosx | 3 - Sockets/RandomNumber.cpp | 116 - Sockets/RandomNumber.h | 202 - Sockets/ResolvServer.cpp | 97 - Sockets/ResolvServer.h | 73 - Sockets/ResolvSocket.cpp | 436 - Sockets/ResolvSocket.h | 106 - Sockets/SSLInitializer.cpp | 144 - Sockets/SSLInitializer.h | 76 - Sockets/SctpSocket.cpp | 496 - Sockets/SctpSocket.h | 110 - Sockets/Semaphore.cpp | 76 - Sockets/Semaphore.h | 67 - Sockets/SmtpdSocket.cpp | 234 - Sockets/SmtpdSocket.h | 143 - Sockets/Socket.cpp | 1896 --- Sockets/Socket.h | 738 -- Sockets/SocketAddress.h | 95 - Sockets/SocketHandler.cpp | 1422 --- Sockets/SocketHandler.h | 266 - Sockets/Sockets-config.cpp | 121 - Sockets/StdLog.h | 74 - Sockets/StdoutLog.cpp | 96 - Sockets/StdoutLog.h | 57 - Sockets/StreamSocket.cpp | 169 - Sockets/StreamSocket.h | 127 - Sockets/TcpSocket.cpp | 1729 --- Sockets/TcpSocket.h | 355 - Sockets/Thread.cpp | 166 - Sockets/Thread.h | 100 - Sockets/UdpSocket.cpp | 843 -- Sockets/UdpSocket.h | 215 - Sockets/Utility.cpp | 953 -- Sockets/Utility.h | 153 - Sockets/ajp13.h | 91 - Sockets/gpl.txt | 340 - Sockets/mkdot.sh | 13 - Sockets/socket_include.cpp | 90 - Sockets/socket_include.h | 288 - Sockets/sockets-config.h | 97 - Sockets/tests/Makefile | 73 - Sockets/tests/base64.cpp | 34 - Sockets/tests/copy.cpp | 264 - Sockets/tests/crlf.cpp | 139 - Sockets/tests/echoserver.cpp | 237 - Sockets/tests/events.cpp | 212 - Sockets/tests/http.cpp | 65 - Sockets/tests/http_post.cpp | 107 - Sockets/tests/httpd.cpp | 109 - Sockets/tests/https.cpp | 113 - Sockets/tests/resolve.cpp | 156 - Sockets/tests/resume.cpp | 111 - Sockets/tests/retry.cpp | 67 - Sockets/tests/semtest.cpp | 96 - Sockets/tests/sloppy_http.cpp | 55 - Sockets/tests/sockets_test.cpp | 347 - Sockets/tests/stressclient.cpp | 516 - Sockets/tests/x.cpp | 298 - anycast-voip-diagramm.pdf | Bin 73755 -> 0 bytes anyctrOptions.cpp | 339 - anyctrOptions.h | 112 - anymuxOptions.cpp | 303 - anymuxOptions.h | 99 - anyrtpproxy/Makefile | 68 - anyrtpproxy/anyrtpproxy.cpp | 372 - anyrtpproxy/callIdQueue.cpp | 76 - anyrtpproxy/callIdQueue.h | 72 - anyrtpproxy/commandHandler.cpp | 268 - anyrtpproxy/commandHandler.h | 89 - anyrtpproxy/connectionList.cpp | 89 - anyrtpproxy/connectionList.h | 64 - anyrtpproxy/options.cpp | 308 - anyrtpproxy/options.h | 129 - anyrtpproxy/portWindow.cpp | 85 - anyrtpproxy/portWindow.h | 63 - anytun-config.cpp | 104 - anytun-controld.cpp | 181 - anytun-showtables.cpp | 131 - anytun.cpp | 517 - authAlgo.cpp | 125 - authAlgo.h | 104 - authAlgoFactory.cpp | 47 - authAlgoFactory.h | 51 - buffer.cpp | 257 - buffer.h | 76 - cipher.cpp | 167 - cipher.h | 94 - cipherFactory.cpp | 47 - cipherFactory.h | 51 - configure | 5 - connectionList.cpp | 129 - connectionList.h | 65 - connectionParam.cpp | 43 - connectionParam.h | 71 - datatypes.h | 63 - ...enger-secure-anycast-tunneling-protocol-02.html | 696 -- ...senger-secure-anycast-tunneling-protocol-02.txt | 952 -- ...senger-secure-anycast-tunneling-protocol-02.xml | 299 - encryptedPacket.cpp | 215 - encryptedPacket.h | 145 - keyDerivation.cpp | 153 - keyDerivation.h | 140 - keyDerivationFactory.cpp | 47 - keyDerivationFactory.h | 51 - log.cpp | 98 - log.h | 126 - man/Makefile | 10 - man/anytun.txt | 294 - mpi.cpp | 201 - mpi.h | 83 - muxSocket.cpp | 49 - muxSocket.h | 27 - networkAddress.cpp | 204 - networkAddress.h | 93 - networkPrefix.cpp | 84 - networkPrefix.h | 65 - openvpn/AUTHORS | 1 - openvpn/COPYING | 215 - openvpn/COPYRIGHT.GPL | 339 - openvpn/ChangeLog | 2232 ---- openvpn/INSTALL | 292 - openvpn/INSTALL-win32.txt | 3 - openvpn/Makefile.am | 130 - openvpn/Makefile.in | 907 -- openvpn/NEWS | 0 openvpn/PORTS | 94 - openvpn/README | 75 - openvpn/acinclude.m4 | 346 - openvpn/aclocal.m4 | 928 -- openvpn/base64.c | 150 - openvpn/base64.h | 44 - openvpn/basic.h | 41 - openvpn/buffer.c | 743 -- openvpn/buffer.h | 712 -- openvpn/circ_list.h | 78 - openvpn/common.h | 76 - openvpn/config-win32.h.in | 309 - openvpn/config.guess | 1466 --- openvpn/config.h.in | 513 - openvpn/config.sub | 1546 --- openvpn/configure | 12310 ------------------- openvpn/configure.ac | 636 - openvpn/contrib/README | 2 - openvpn/contrib/multilevel-init.patch | 79 - openvpn/contrib/openvpn-fwmarkroute-1.00/README | 44 - .../openvpn-fwmarkroute-1.00/fwmarkroute.down | 22 - .../openvpn-fwmarkroute-1.00/fwmarkroute.up | 49 - openvpn/contrib/pull-resolv-conf/client.down | 76 - openvpn/contrib/pull-resolv-conf/client.up | 75 - openvpn/crypto.c | 1724 --- openvpn/crypto.h | 393 - openvpn/cryptoapi.c | 463 - openvpn/cryptoapi.h | 7 - openvpn/debug/valgrind-suppress | 310 - openvpn/depcomp | 520 - openvpn/doclean | 16 - openvpn/easy-rsa/.externals | 1 - openvpn/easy-rsa/2.0/Makefile | 13 - openvpn/easy-rsa/2.0/README | 221 - openvpn/easy-rsa/2.0/build-ca | 8 - openvpn/easy-rsa/2.0/build-dh | 11 - openvpn/easy-rsa/2.0/build-inter | 7 - openvpn/easy-rsa/2.0/build-key | 7 - openvpn/easy-rsa/2.0/build-key-pass | 7 - openvpn/easy-rsa/2.0/build-key-pkcs12 | 8 - openvpn/easy-rsa/2.0/build-key-server | 10 - openvpn/easy-rsa/2.0/build-req | 7 - openvpn/easy-rsa/2.0/build-req-pass | 7 - openvpn/easy-rsa/2.0/clean-all | 16 - openvpn/easy-rsa/2.0/inherit-inter | 39 - openvpn/easy-rsa/2.0/list-crl | 13 - openvpn/easy-rsa/2.0/openssl-0.9.6.cnf | 265 - openvpn/easy-rsa/2.0/openssl.cnf | 285 - openvpn/easy-rsa/2.0/pkitool | 353 - openvpn/easy-rsa/2.0/revoke-full | 39 - openvpn/easy-rsa/2.0/sign-req | 7 - openvpn/easy-rsa/2.0/vars | 64 - openvpn/easy-rsa/2.0/whichopensslcnf | 13 - openvpn/easy-rsa/README | 161 - openvpn/easy-rsa/Windows/README.txt | 44 - openvpn/easy-rsa/Windows/build-ca.bat | 4 - openvpn/easy-rsa/Windows/build-dh.bat | 4 - openvpn/easy-rsa/Windows/build-key-pkcs12.bat | 10 - openvpn/easy-rsa/Windows/build-key-server.bat | 8 - openvpn/easy-rsa/Windows/build-key.bat | 8 - openvpn/easy-rsa/Windows/clean-all.bat | 13 - openvpn/easy-rsa/Windows/index.txt.start | 0 openvpn/easy-rsa/Windows/init-config.bat | 2 - openvpn/easy-rsa/Windows/revoke-full.bat | 13 - openvpn/easy-rsa/Windows/serial.start | 1 - openvpn/easy-rsa/Windows/vars.bat.sample | 35 - openvpn/easy-rsa/build-ca | 13 - openvpn/easy-rsa/build-dh | 12 - openvpn/easy-rsa/build-inter | 19 - openvpn/easy-rsa/build-key | 20 - openvpn/easy-rsa/build-key-pass | 20 - openvpn/easy-rsa/build-key-pkcs12 | 21 - openvpn/easy-rsa/build-key-server | 22 - openvpn/easy-rsa/build-req | 18 - openvpn/easy-rsa/build-req-pass | 18 - openvpn/easy-rsa/clean-all | 19 - openvpn/easy-rsa/list-crl | 18 - openvpn/easy-rsa/make-crl | 18 - openvpn/easy-rsa/openssl.cnf | 255 - openvpn/easy-rsa/revoke-crt | 18 - openvpn/easy-rsa/revoke-full | 29 - openvpn/easy-rsa/sign-req | 18 - openvpn/easy-rsa/vars | 49 - openvpn/errlevel.h | 161 - openvpn/error.c | 852 -- openvpn/error.h | 342 - openvpn/event.c | 1061 -- openvpn/event.h | 157 - openvpn/fdmisc.c | 60 - openvpn/fdmisc.h | 26 - openvpn/forward-inline.h | 276 - openvpn/forward.c | 1398 --- openvpn/forward.h | 84 - openvpn/fragment.c | 414 - openvpn/fragment.h | 188 - openvpn/gentoo/openvpn.init | 111 - openvpn/gremlin.c | 221 - openvpn/gremlin.h | 70 - openvpn/helper.c | 372 - openvpn/helper.h | 37 - openvpn/init.c | 2750 ----- openvpn/init.h | 122 - openvpn/install-sh | 316 - openvpn/install-win32/.svnignore | 1 - openvpn/install-win32/buildopensslpath.bat | 3 - openvpn/install-win32/openssl.bat | 5 - openvpn/install-win32/openvpn.nsi.in | 570 - openvpn/install-win32/prebuild | 145 - openvpn/install-win32/sample.ovpn | 103 - openvpn/install-win32/setpath.nsi | 231 - openvpn/install-win32/u2d.c | 20 - openvpn/integer.h | 114 - openvpn/interval.c | 83 - openvpn/interval.h | 239 - openvpn/list.c | 664 - openvpn/list.h | 220 - openvpn/lzo.c | 251 - openvpn/lzo.h | 117 - openvpn/makefile.w32 | 199 - openvpn/makefile.w32-vc | 179 - openvpn/manage.c | 2153 ---- openvpn/manage.h | 341 - openvpn/management/management-notes.txt | 436 - openvpn/mbuf.c | 187 - openvpn/mbuf.h | 110 - openvpn/memcmp.c | 40 - openvpn/memdbg.h | 112 - openvpn/misc.c | 1367 -- openvpn/misc.h | 257 - openvpn/missing | 360 - openvpn/mroute.c | 365 - openvpn/mroute.h | 165 - openvpn/mss.c | 120 - openvpn/mss.h | 34 - openvpn/mtcp.c | 727 -- openvpn/mtcp.h | 68 - openvpn/mtu.c | 303 - openvpn/mtu.h | 304 - openvpn/mudp.c | 286 - openvpn/mudp.h | 42 - openvpn/multi.c | 2137 ---- openvpn/multi.h | 445 - openvpn/ntlm.c | 188 - openvpn/ntlm.h | 11 - openvpn/occ-inline.h | 85 - openvpn/occ.c | 399 - openvpn/occ.h | 95 - openvpn/openvpn-plugin.h | 211 - openvpn/openvpn.8 | 5131 -------- openvpn/openvpn.c | 242 - openvpn/openvpn.h | 517 - openvpn/openvpn.spec.in | 273 - openvpn/options.c | 4552 ------- openvpn/options.h | 564 - openvpn/otime.c | 198 - openvpn/otime.h | 206 - openvpn/packet_id.c | 492 - openvpn/packet_id.h | 335 - openvpn/perf.c | 301 - openvpn/perf.h | 82 - openvpn/ping-inline.h | 59 - openvpn/ping.c | 96 - openvpn/ping.h | 47 - openvpn/plugin.c | 394 - openvpn/plugin.h | 101 - openvpn/plugin/README | 47 - openvpn/plugin/auth-pam/Makefile | 30 - openvpn/plugin/auth-pam/README | 74 - openvpn/plugin/auth-pam/auth-pam.c | 755 -- openvpn/plugin/auth-pam/pamdl.c | 181 - openvpn/plugin/auth-pam/pamdl.h | 7 - openvpn/plugin/down-root/Makefile | 17 - openvpn/plugin/down-root/README | 29 - openvpn/plugin/down-root/down-root.c | 551 - openvpn/plugin/examples/README | 16 - openvpn/plugin/examples/build | 14 - openvpn/plugin/examples/simple.c | 120 - openvpn/plugin/examples/simple.def | 6 - openvpn/plugin/examples/winbuild | 18 - openvpn/pool.c | 532 - openvpn/pool.h | 89 - openvpn/proto.c | 74 - openvpn/proto.h | 163 - openvpn/proxy.c | 490 - openvpn/proxy.h | 71 - openvpn/push.c | 326 - openvpn/push.h | 65 - openvpn/reliable.c | 700 -- openvpn/reliable.h | 162 - openvpn/route.c | 1814 --- openvpn/route.h | 167 - openvpn/sample-config-files/README | 6 - openvpn/sample-config-files/client.conf | 123 - openvpn/sample-config-files/firewall.sh | 108 - openvpn/sample-config-files/home.up | 2 - openvpn/sample-config-files/loopback-client | 25 - openvpn/sample-config-files/loopback-server | 26 - openvpn/sample-config-files/office.up | 2 - openvpn/sample-config-files/openvpn-shutdown.sh | 5 - openvpn/sample-config-files/openvpn-startup.sh | 34 - openvpn/sample-config-files/server.conf | 291 - openvpn/sample-config-files/static-home.conf | 72 - openvpn/sample-config-files/static-office.conf | 69 - openvpn/sample-config-files/tls-home.conf | 83 - openvpn/sample-config-files/tls-office.conf | 83 - openvpn/sample-config-files/xinetd-client-config | 11 - openvpn/sample-config-files/xinetd-server-config | 25 - openvpn/sample-keys/README | 14 - openvpn/sample-keys/client.crt | 65 - openvpn/sample-keys/client.key | 15 - openvpn/sample-keys/dh1024.pem | 5 - openvpn/sample-keys/pass.crt | 65 - openvpn/sample-keys/pass.key | 18 - openvpn/sample-keys/pkcs12.p12 | Bin 2685 -> 0 bytes openvpn/sample-keys/server.crt | 67 - openvpn/sample-keys/server.key | 15 - openvpn/sample-keys/tmp-ca.crt | 19 - openvpn/sample-keys/tmp-ca.key | 15 - openvpn/sample-scripts/auth-pam.pl | 97 - openvpn/sample-scripts/bridge-start | 39 - openvpn/sample-scripts/bridge-stop | 18 - openvpn/sample-scripts/openvpn.init | 244 - openvpn/sample-scripts/verify-cn | 52 - openvpn/schedule.c | 663 - openvpn/schedule.h | 140 - openvpn/service-win32/Makefile | 25 - openvpn/service-win32/mkpatch | 4 - openvpn/service-win32/openvpnserv.c | 513 - openvpn/service-win32/service.patch | 353 - openvpn/session_id.c | 67 - openvpn/session_id.h | 86 - openvpn/shaper.c | 100 - openvpn/shaper.h | 178 - openvpn/sig.c | 345 - openvpn/sig.h | 100 - openvpn/socket.c | 2175 ---- openvpn/socket.h | 808 -- openvpn/socks.c | 411 - openvpn/socks.h | 71 - openvpn/ssl.c | 4099 ------ openvpn/ssl.h | 690 -- openvpn/status.c | 301 - openvpn/status.h | 95 - openvpn/suse/openvpn.init | 264 - openvpn/syshead.h | 454 - openvpn/t_cltsrv.sh | 59 - openvpn/t_lpback.sh | 31 - openvpn/tap-win32/MAKEFILE | 6 - openvpn/tap-win32/SOURCES | 72 - openvpn/tap-win32/amd64/OemWin2k.inf | 183 - openvpn/tap-win32/amd64/tap.cat | 6 - openvpn/tap-win32/common.h | 82 - openvpn/tap-win32/constants.h | 55 - openvpn/tap-win32/dhcp.c | 603 - openvpn/tap-win32/dhcp.h | 168 - openvpn/tap-win32/endian.h | 39 - openvpn/tap-win32/error.c | 382 - openvpn/tap-win32/error.h | 92 - openvpn/tap-win32/hexdump.c | 73 - openvpn/tap-win32/hexdump.h | 67 - openvpn/tap-win32/i386/OemWin2k.inf | 183 - openvpn/tap-win32/i386/tap.cat | 6 - openvpn/tap-win32/instance.c | 245 - openvpn/tap-win32/lock.h | 79 - openvpn/tap-win32/macinfo.c | 158 - openvpn/tap-win32/macinfo.h | 42 - openvpn/tap-win32/mem.c | 190 - openvpn/tap-win32/proto.h | 168 - openvpn/tap-win32/prototypes.h | 219 - openvpn/tap-win32/resource.rc | 59 - openvpn/tap-win32/tapdrvr.c | 2842 ----- openvpn/tap-win32/types.h | 166 - openvpn/thread.c | 162 - openvpn/thread.h | 235 - openvpn/tun.c | 3446 ------ openvpn/tun.h | 413 - openvpn/win32.c | 758 -- openvpn/win32.h | 251 - options.cpp | 624 - options.h | 163 - packetSource.cpp | 57 - packetSource.h | 54 - ...nycast VOIP Proxy Resultat und Meilensteine.pdf | Bin 0 -> 24937 bytes papers/Anycast VOIP Proxy Zeitplan.pdf | Bin 0 -> 10546 bytes papers/anycast-voip-diagramm.pdf | Bin 0 -> 73755 bytes ...enger-secure-anycast-tunneling-protocol-02.html | 696 ++ ...senger-secure-anycast-tunneling-protocol-02.txt | 952 ++ ...senger-secure-anycast-tunneling-protocol-02.xml | 299 + papers/vortrag | 21 + plainPacket.cpp | 168 - plainPacket.h | 108 - router.cpp | 53 - router.h | 56 - routingTable.cpp | 140 - routingTable.h | 78 - rtpSession.cpp | 194 - rtpSession.h | 118 - rtpSessionTable.cpp | 121 - rtpSessionTable.h | 74 - seqWindow.cpp | 93 - seqWindow.h | 80 - signalController.cpp | 153 - signalController.h | 121 - src/Doxyfile | 1252 ++ src/Makefile | 299 + src/PracticalSocket.cpp | 473 + src/PracticalSocket.h | 400 + src/Sockets/Ajp13Socket.cpp | 404 + src/Sockets/Ajp13Socket.h | 69 + src/Sockets/AjpBaseSocket.cpp | 258 + src/Sockets/AjpBaseSocket.h | 83 + src/Sockets/Base64.cpp | 272 + src/Sockets/Base64.h | 77 + src/Sockets/Debug.cpp | 79 + src/Sockets/Debug.h | 75 + src/Sockets/DevCpp/Sockets.dev | 1129 ++ src/Sockets/DevCpp/Test.dev | 59 + src/Sockets/Event.cpp | 85 + src/Sockets/Event.h | 76 + src/Sockets/EventHandler.cpp | 223 + src/Sockets/EventHandler.h | 85 + src/Sockets/EventTime.cpp | 105 + src/Sockets/EventTime.h | 77 + src/Sockets/Exception.cpp | 48 + src/Sockets/Exception.h | 58 + src/Sockets/File.cpp | 169 + src/Sockets/File.h | 84 + src/Sockets/HTTPSocket.cpp | 413 + src/Sockets/HTTPSocket.h | 152 + src/Sockets/HttpBaseSocket.cpp | 204 + src/Sockets/HttpBaseSocket.h | 76 + src/Sockets/HttpClientSocket.cpp | 277 + src/Sockets/HttpClientSocket.h | 121 + src/Sockets/HttpDebugSocket.cpp | 125 + src/Sockets/HttpDebugSocket.h | 70 + src/Sockets/HttpGetSocket.cpp | 114 + src/Sockets/HttpGetSocket.h | 66 + src/Sockets/HttpPostSocket.cpp | 294 + src/Sockets/HttpPostSocket.h | 94 + src/Sockets/HttpPutSocket.cpp | 125 + src/Sockets/HttpPutSocket.h | 83 + src/Sockets/HttpRequest.cpp | 358 + src/Sockets/HttpRequest.h | 125 + src/Sockets/HttpResponse.cpp | 201 + src/Sockets/HttpResponse.h | 82 + src/Sockets/HttpTransaction.cpp | 244 + src/Sockets/HttpTransaction.h | 94 + src/Sockets/HttpdCookies.cpp | 270 + src/Sockets/HttpdCookies.h | 89 + src/Sockets/HttpdForm.cpp | 616 + src/Sockets/HttpdForm.h | 118 + src/Sockets/HttpdSocket.cpp | 528 + src/Sockets/HttpdSocket.h | 106 + src/Sockets/IBase.h | 44 + src/Sockets/IEventHandler.h | 75 + src/Sockets/IEventOwner.cpp | 79 + src/Sockets/IEventOwner.h | 77 + src/Sockets/IFile.h | 71 + src/Sockets/IHttpServer.h | 56 + src/Sockets/ISocketHandler.h | 233 + src/Sockets/Ipv4Address.cpp | 214 + src/Sockets/Ipv4Address.h | 98 + src/Sockets/Ipv6Address.cpp | 270 + src/Sockets/Ipv6Address.h | 107 + src/Sockets/ListenSocket.h | 420 + src/Sockets/Lock.cpp | 55 + src/Sockets/Lock.h | 59 + src/Sockets/Makefile | 154 + src/Sockets/Makefile.Defines.linux-x86-32 | 28 + src/Sockets/Makefile.Defines.macosx | 28 + src/Sockets/Makefile.Defines.solaris8 | 29 + src/Sockets/Makefile.Defines.solaris9-sparc-64 | 29 + src/Sockets/Makefile.Defines.win32-cygwin | 26 + src/Sockets/Makefile.solaris9-sparc-64 | 70 + src/Sockets/Makefile.version | 49 + src/Sockets/MemFile.cpp | 288 + src/Sockets/MemFile.h | 100 + src/Sockets/Mutex.cpp | 81 + src/Sockets/Mutex.h | 68 + src/Sockets/OSX.zip | Bin 0 -> 16669 bytes src/Sockets/Parse.cpp | 321 + src/Sockets/Parse.h | 101 + src/Sockets/Project.net/Sockets/Sockets.sln | 30 + src/Sockets/Project.net/Sockets/Sockets.vcproj | 452 + src/Sockets/Project.net/Test/Test.vcproj | 140 + src/Sockets/Project/Sockets.dsp | 526 + src/Sockets/Project/Sockets.dsw | 68 + src/Sockets/Project/Test.dsp | 102 + src/Sockets/Project/echoserver.dsp | 100 + src/Sockets/Project/stressclient.dsp | 100 + src/Sockets/README.macosx | 3 + src/Sockets/RandomNumber.cpp | 116 + src/Sockets/RandomNumber.h | 202 + src/Sockets/ResolvServer.cpp | 97 + src/Sockets/ResolvServer.h | 73 + src/Sockets/ResolvSocket.cpp | 436 + src/Sockets/ResolvSocket.h | 106 + src/Sockets/SSLInitializer.cpp | 144 + src/Sockets/SSLInitializer.h | 76 + src/Sockets/SctpSocket.cpp | 496 + src/Sockets/SctpSocket.h | 110 + src/Sockets/Semaphore.cpp | 76 + src/Sockets/Semaphore.h | 67 + src/Sockets/SmtpdSocket.cpp | 234 + src/Sockets/SmtpdSocket.h | 143 + src/Sockets/Socket.cpp | 1896 +++ src/Sockets/Socket.h | 738 ++ src/Sockets/SocketAddress.h | 95 + src/Sockets/SocketHandler.cpp | 1422 +++ src/Sockets/SocketHandler.h | 266 + src/Sockets/Sockets-config.cpp | 121 + src/Sockets/StdLog.h | 74 + src/Sockets/StdoutLog.cpp | 96 + src/Sockets/StdoutLog.h | 57 + src/Sockets/StreamSocket.cpp | 169 + src/Sockets/StreamSocket.h | 127 + src/Sockets/TcpSocket.cpp | 1729 +++ src/Sockets/TcpSocket.h | 355 + src/Sockets/Thread.cpp | 166 + src/Sockets/Thread.h | 100 + src/Sockets/UdpSocket.cpp | 843 ++ src/Sockets/UdpSocket.h | 215 + src/Sockets/Utility.cpp | 953 ++ src/Sockets/Utility.h | 153 + src/Sockets/ajp13.h | 91 + src/Sockets/gpl.txt | 340 + src/Sockets/mkdot.sh | 13 + src/Sockets/socket_include.cpp | 90 + src/Sockets/socket_include.h | 288 + src/Sockets/sockets-config.h | 97 + src/Sockets/tests/Makefile | 73 + src/Sockets/tests/base64.cpp | 34 + src/Sockets/tests/copy.cpp | 264 + src/Sockets/tests/crlf.cpp | 139 + src/Sockets/tests/echoserver.cpp | 237 + src/Sockets/tests/events.cpp | 212 + src/Sockets/tests/http.cpp | 65 + src/Sockets/tests/http_post.cpp | 107 + src/Sockets/tests/httpd.cpp | 109 + src/Sockets/tests/https.cpp | 113 + src/Sockets/tests/resolve.cpp | 156 + src/Sockets/tests/resume.cpp | 111 + src/Sockets/tests/retry.cpp | 67 + src/Sockets/tests/semtest.cpp | 96 + src/Sockets/tests/sloppy_http.cpp | 55 + src/Sockets/tests/sockets_test.cpp | 347 + src/Sockets/tests/stressclient.cpp | 516 + src/Sockets/tests/x.cpp | 298 + src/anyctrOptions.cpp | 339 + src/anyctrOptions.h | 112 + src/anymuxOptions.cpp | 303 + src/anymuxOptions.h | 99 + src/anyrtpproxy/Makefile | 68 + src/anyrtpproxy/anyrtpproxy.cpp | 372 + src/anyrtpproxy/callIdQueue.cpp | 76 + src/anyrtpproxy/callIdQueue.h | 72 + src/anyrtpproxy/commandHandler.cpp | 268 + src/anyrtpproxy/commandHandler.h | 89 + src/anyrtpproxy/connectionList.cpp | 89 + src/anyrtpproxy/connectionList.h | 64 + src/anyrtpproxy/options.cpp | 308 + src/anyrtpproxy/options.h | 129 + src/anyrtpproxy/portWindow.cpp | 85 + src/anyrtpproxy/portWindow.h | 63 + src/anytun-config.cpp | 104 + src/anytun-controld.cpp | 181 + src/anytun-showtables.cpp | 131 + src/anytun.cpp | 517 + src/authAlgo.cpp | 125 + src/authAlgo.h | 104 + src/authAlgoFactory.cpp | 47 + src/authAlgoFactory.h | 51 + src/buffer.cpp | 257 + src/buffer.h | 76 + src/cipher.cpp | 167 + src/cipher.h | 94 + src/cipherFactory.cpp | 47 + src/cipherFactory.h | 51 + src/configure | 5 + src/connectionList.cpp | 129 + src/connectionList.h | 65 + src/connectionParam.cpp | 43 + src/connectionParam.h | 71 + src/datatypes.h | 63 + src/encryptedPacket.cpp | 215 + src/encryptedPacket.h | 145 + src/keyDerivation.cpp | 153 + src/keyDerivation.h | 140 + src/keyDerivationFactory.cpp | 47 + src/keyDerivationFactory.h | 51 + src/log.cpp | 98 + src/log.h | 126 + src/man/Makefile | 10 + src/man/anytun.txt | 294 + src/mpi.cpp | 201 + src/mpi.h | 83 + src/muxSocket.cpp | 49 + src/muxSocket.h | 27 + src/networkAddress.cpp | 204 + src/networkAddress.h | 93 + src/networkPrefix.cpp | 84 + src/networkPrefix.h | 65 + src/openvpn/AUTHORS | 1 + src/openvpn/COPYING | 215 + src/openvpn/COPYRIGHT.GPL | 339 + src/openvpn/ChangeLog | 2232 ++++ src/openvpn/INSTALL | 292 + src/openvpn/INSTALL-win32.txt | 3 + src/openvpn/Makefile.am | 130 + src/openvpn/Makefile.in | 907 ++ src/openvpn/NEWS | 0 src/openvpn/PORTS | 94 + src/openvpn/README | 75 + src/openvpn/acinclude.m4 | 346 + src/openvpn/aclocal.m4 | 928 ++ src/openvpn/base64.c | 150 + src/openvpn/base64.h | 44 + src/openvpn/basic.h | 41 + src/openvpn/buffer.c | 743 ++ src/openvpn/buffer.h | 712 ++ src/openvpn/circ_list.h | 78 + src/openvpn/common.h | 76 + src/openvpn/config-win32.h.in | 309 + src/openvpn/config.guess | 1466 +++ src/openvpn/config.h.in | 513 + src/openvpn/config.sub | 1546 +++ src/openvpn/configure | 12310 +++++++++++++++++++ src/openvpn/configure.ac | 636 + src/openvpn/contrib/README | 2 + src/openvpn/contrib/multilevel-init.patch | 79 + .../contrib/openvpn-fwmarkroute-1.00/README | 44 + .../openvpn-fwmarkroute-1.00/fwmarkroute.down | 22 + .../openvpn-fwmarkroute-1.00/fwmarkroute.up | 49 + src/openvpn/contrib/pull-resolv-conf/client.down | 76 + src/openvpn/contrib/pull-resolv-conf/client.up | 75 + src/openvpn/crypto.c | 1724 +++ src/openvpn/crypto.h | 393 + src/openvpn/cryptoapi.c | 463 + src/openvpn/cryptoapi.h | 7 + src/openvpn/debug/valgrind-suppress | 310 + src/openvpn/depcomp | 520 + src/openvpn/doclean | 16 + src/openvpn/easy-rsa/.externals | 1 + src/openvpn/easy-rsa/2.0/Makefile | 13 + src/openvpn/easy-rsa/2.0/README | 221 + src/openvpn/easy-rsa/2.0/build-ca | 8 + src/openvpn/easy-rsa/2.0/build-dh | 11 + src/openvpn/easy-rsa/2.0/build-inter | 7 + src/openvpn/easy-rsa/2.0/build-key | 7 + src/openvpn/easy-rsa/2.0/build-key-pass | 7 + src/openvpn/easy-rsa/2.0/build-key-pkcs12 | 8 + src/openvpn/easy-rsa/2.0/build-key-server | 10 + src/openvpn/easy-rsa/2.0/build-req | 7 + src/openvpn/easy-rsa/2.0/build-req-pass | 7 + src/openvpn/easy-rsa/2.0/clean-all | 16 + src/openvpn/easy-rsa/2.0/inherit-inter | 39 + src/openvpn/easy-rsa/2.0/list-crl | 13 + src/openvpn/easy-rsa/2.0/openssl-0.9.6.cnf | 265 + src/openvpn/easy-rsa/2.0/openssl.cnf | 285 + src/openvpn/easy-rsa/2.0/pkitool | 353 + src/openvpn/easy-rsa/2.0/revoke-full | 39 + src/openvpn/easy-rsa/2.0/sign-req | 7 + src/openvpn/easy-rsa/2.0/vars | 64 + src/openvpn/easy-rsa/2.0/whichopensslcnf | 13 + src/openvpn/easy-rsa/README | 161 + src/openvpn/easy-rsa/Windows/README.txt | 44 + src/openvpn/easy-rsa/Windows/build-ca.bat | 4 + src/openvpn/easy-rsa/Windows/build-dh.bat | 4 + src/openvpn/easy-rsa/Windows/build-key-pkcs12.bat | 10 + src/openvpn/easy-rsa/Windows/build-key-server.bat | 8 + src/openvpn/easy-rsa/Windows/build-key.bat | 8 + src/openvpn/easy-rsa/Windows/clean-all.bat | 13 + src/openvpn/easy-rsa/Windows/index.txt.start | 0 src/openvpn/easy-rsa/Windows/init-config.bat | 2 + src/openvpn/easy-rsa/Windows/revoke-full.bat | 13 + src/openvpn/easy-rsa/Windows/serial.start | 1 + src/openvpn/easy-rsa/Windows/vars.bat.sample | 35 + src/openvpn/easy-rsa/build-ca | 13 + src/openvpn/easy-rsa/build-dh | 12 + src/openvpn/easy-rsa/build-inter | 19 + src/openvpn/easy-rsa/build-key | 20 + src/openvpn/easy-rsa/build-key-pass | 20 + src/openvpn/easy-rsa/build-key-pkcs12 | 21 + src/openvpn/easy-rsa/build-key-server | 22 + src/openvpn/easy-rsa/build-req | 18 + src/openvpn/easy-rsa/build-req-pass | 18 + src/openvpn/easy-rsa/clean-all | 19 + src/openvpn/easy-rsa/list-crl | 18 + src/openvpn/easy-rsa/make-crl | 18 + src/openvpn/easy-rsa/openssl.cnf | 255 + src/openvpn/easy-rsa/revoke-crt | 18 + src/openvpn/easy-rsa/revoke-full | 29 + src/openvpn/easy-rsa/sign-req | 18 + src/openvpn/easy-rsa/vars | 49 + src/openvpn/errlevel.h | 161 + src/openvpn/error.c | 852 ++ src/openvpn/error.h | 342 + src/openvpn/event.c | 1061 ++ src/openvpn/event.h | 157 + src/openvpn/fdmisc.c | 60 + src/openvpn/fdmisc.h | 26 + src/openvpn/forward-inline.h | 276 + src/openvpn/forward.c | 1398 +++ src/openvpn/forward.h | 84 + src/openvpn/fragment.c | 414 + src/openvpn/fragment.h | 188 + src/openvpn/gentoo/openvpn.init | 111 + src/openvpn/gremlin.c | 221 + src/openvpn/gremlin.h | 70 + src/openvpn/helper.c | 372 + src/openvpn/helper.h | 37 + src/openvpn/init.c | 2750 +++++ src/openvpn/init.h | 122 + src/openvpn/install-sh | 316 + src/openvpn/install-win32/.svnignore | 1 + src/openvpn/install-win32/buildopensslpath.bat | 3 + src/openvpn/install-win32/openssl.bat | 5 + src/openvpn/install-win32/openvpn.nsi.in | 570 + src/openvpn/install-win32/prebuild | 145 + src/openvpn/install-win32/sample.ovpn | 103 + src/openvpn/install-win32/setpath.nsi | 231 + src/openvpn/install-win32/u2d.c | 20 + src/openvpn/integer.h | 114 + src/openvpn/interval.c | 83 + src/openvpn/interval.h | 239 + src/openvpn/list.c | 664 + src/openvpn/list.h | 220 + src/openvpn/lzo.c | 251 + src/openvpn/lzo.h | 117 + src/openvpn/makefile.w32 | 199 + src/openvpn/makefile.w32-vc | 179 + src/openvpn/manage.c | 2153 ++++ src/openvpn/manage.h | 341 + src/openvpn/management/management-notes.txt | 436 + src/openvpn/mbuf.c | 187 + src/openvpn/mbuf.h | 110 + src/openvpn/memcmp.c | 40 + src/openvpn/memdbg.h | 112 + src/openvpn/misc.c | 1367 ++ src/openvpn/misc.h | 257 + src/openvpn/missing | 360 + src/openvpn/mroute.c | 365 + src/openvpn/mroute.h | 165 + src/openvpn/mss.c | 120 + src/openvpn/mss.h | 34 + src/openvpn/mtcp.c | 727 ++ src/openvpn/mtcp.h | 68 + src/openvpn/mtu.c | 303 + src/openvpn/mtu.h | 304 + src/openvpn/mudp.c | 286 + src/openvpn/mudp.h | 42 + src/openvpn/multi.c | 2137 ++++ src/openvpn/multi.h | 445 + src/openvpn/ntlm.c | 188 + src/openvpn/ntlm.h | 11 + src/openvpn/occ-inline.h | 85 + src/openvpn/occ.c | 399 + src/openvpn/occ.h | 95 + src/openvpn/openvpn-plugin.h | 211 + src/openvpn/openvpn.8 | 5131 ++++++++ src/openvpn/openvpn.c | 242 + src/openvpn/openvpn.h | 517 + src/openvpn/openvpn.spec.in | 273 + src/openvpn/options.c | 4552 +++++++ src/openvpn/options.h | 564 + src/openvpn/otime.c | 198 + src/openvpn/otime.h | 206 + src/openvpn/packet_id.c | 492 + src/openvpn/packet_id.h | 335 + src/openvpn/perf.c | 301 + src/openvpn/perf.h | 82 + src/openvpn/ping-inline.h | 59 + src/openvpn/ping.c | 96 + src/openvpn/ping.h | 47 + src/openvpn/plugin.c | 394 + src/openvpn/plugin.h | 101 + src/openvpn/plugin/README | 47 + src/openvpn/plugin/auth-pam/Makefile | 30 + src/openvpn/plugin/auth-pam/README | 74 + src/openvpn/plugin/auth-pam/auth-pam.c | 755 ++ src/openvpn/plugin/auth-pam/pamdl.c | 181 + src/openvpn/plugin/auth-pam/pamdl.h | 7 + src/openvpn/plugin/down-root/Makefile | 17 + src/openvpn/plugin/down-root/README | 29 + src/openvpn/plugin/down-root/down-root.c | 551 + src/openvpn/plugin/examples/README | 16 + src/openvpn/plugin/examples/build | 14 + src/openvpn/plugin/examples/simple.c | 120 + src/openvpn/plugin/examples/simple.def | 6 + src/openvpn/plugin/examples/winbuild | 18 + src/openvpn/pool.c | 532 + src/openvpn/pool.h | 89 + src/openvpn/proto.c | 74 + src/openvpn/proto.h | 163 + src/openvpn/proxy.c | 490 + src/openvpn/proxy.h | 71 + src/openvpn/push.c | 326 + src/openvpn/push.h | 65 + src/openvpn/reliable.c | 700 ++ src/openvpn/reliable.h | 162 + src/openvpn/route.c | 1814 +++ src/openvpn/route.h | 167 + src/openvpn/sample-config-files/README | 6 + src/openvpn/sample-config-files/client.conf | 123 + src/openvpn/sample-config-files/firewall.sh | 108 + src/openvpn/sample-config-files/home.up | 2 + src/openvpn/sample-config-files/loopback-client | 25 + src/openvpn/sample-config-files/loopback-server | 26 + src/openvpn/sample-config-files/office.up | 2 + .../sample-config-files/openvpn-shutdown.sh | 5 + src/openvpn/sample-config-files/openvpn-startup.sh | 34 + src/openvpn/sample-config-files/server.conf | 291 + src/openvpn/sample-config-files/static-home.conf | 72 + src/openvpn/sample-config-files/static-office.conf | 69 + src/openvpn/sample-config-files/tls-home.conf | 83 + src/openvpn/sample-config-files/tls-office.conf | 83 + .../sample-config-files/xinetd-client-config | 11 + .../sample-config-files/xinetd-server-config | 25 + src/openvpn/sample-keys/README | 14 + src/openvpn/sample-keys/client.crt | 65 + src/openvpn/sample-keys/client.key | 15 + src/openvpn/sample-keys/dh1024.pem | 5 + src/openvpn/sample-keys/pass.crt | 65 + src/openvpn/sample-keys/pass.key | 18 + src/openvpn/sample-keys/pkcs12.p12 | Bin 0 -> 2685 bytes src/openvpn/sample-keys/server.crt | 67 + src/openvpn/sample-keys/server.key | 15 + src/openvpn/sample-keys/tmp-ca.crt | 19 + src/openvpn/sample-keys/tmp-ca.key | 15 + src/openvpn/sample-scripts/auth-pam.pl | 97 + src/openvpn/sample-scripts/bridge-start | 39 + src/openvpn/sample-scripts/bridge-stop | 18 + src/openvpn/sample-scripts/openvpn.init | 244 + src/openvpn/sample-scripts/verify-cn | 52 + src/openvpn/schedule.c | 663 + src/openvpn/schedule.h | 140 + src/openvpn/service-win32/Makefile | 25 + src/openvpn/service-win32/mkpatch | 4 + src/openvpn/service-win32/openvpnserv.c | 513 + src/openvpn/service-win32/service.patch | 353 + src/openvpn/session_id.c | 67 + src/openvpn/session_id.h | 86 + src/openvpn/shaper.c | 100 + src/openvpn/shaper.h | 178 + src/openvpn/sig.c | 345 + src/openvpn/sig.h | 100 + src/openvpn/socket.c | 2175 ++++ src/openvpn/socket.h | 808 ++ src/openvpn/socks.c | 411 + src/openvpn/socks.h | 71 + src/openvpn/ssl.c | 4099 ++++++ src/openvpn/ssl.h | 690 ++ src/openvpn/status.c | 301 + src/openvpn/status.h | 95 + src/openvpn/suse/openvpn.init | 264 + src/openvpn/syshead.h | 454 + src/openvpn/t_cltsrv.sh | 59 + src/openvpn/t_lpback.sh | 31 + src/openvpn/tap-win32/MAKEFILE | 6 + src/openvpn/tap-win32/SOURCES | 72 + src/openvpn/tap-win32/amd64/OemWin2k.inf | 183 + src/openvpn/tap-win32/amd64/tap.cat | 6 + src/openvpn/tap-win32/common.h | 82 + src/openvpn/tap-win32/constants.h | 55 + src/openvpn/tap-win32/dhcp.c | 603 + src/openvpn/tap-win32/dhcp.h | 168 + src/openvpn/tap-win32/endian.h | 39 + src/openvpn/tap-win32/error.c | 382 + src/openvpn/tap-win32/error.h | 92 + src/openvpn/tap-win32/hexdump.c | 73 + src/openvpn/tap-win32/hexdump.h | 67 + src/openvpn/tap-win32/i386/OemWin2k.inf | 183 + src/openvpn/tap-win32/i386/tap.cat | 6 + src/openvpn/tap-win32/instance.c | 245 + src/openvpn/tap-win32/lock.h | 79 + src/openvpn/tap-win32/macinfo.c | 158 + src/openvpn/tap-win32/macinfo.h | 42 + src/openvpn/tap-win32/mem.c | 190 + src/openvpn/tap-win32/proto.h | 168 + src/openvpn/tap-win32/prototypes.h | 219 + src/openvpn/tap-win32/resource.rc | 59 + src/openvpn/tap-win32/tapdrvr.c | 2842 +++++ src/openvpn/tap-win32/types.h | 166 + src/openvpn/thread.c | 162 + src/openvpn/thread.h | 235 + src/openvpn/tun.c | 3446 ++++++ src/openvpn/tun.h | 413 + src/openvpn/win32.c | 758 ++ src/openvpn/win32.h | 251 + src/options.cpp | 624 + src/options.h | 163 + src/packetSource.cpp | 57 + src/packetSource.h | 54 + src/plainPacket.cpp | 168 + src/plainPacket.h | 108 + src/router.cpp | 53 + src/router.h | 56 + src/routingTable.cpp | 140 + src/routingTable.h | 78 + src/rtpSession.cpp | 194 + src/rtpSession.h | 118 + src/rtpSessionTable.cpp | 121 + src/rtpSessionTable.h | 74 + src/seqWindow.cpp | 93 + src/seqWindow.h | 80 + src/signalController.cpp | 153 + src/signalController.h | 121 + src/syncBuffer.cpp | 32 + src/syncBuffer.h | 63 + src/syncClientSocket.cpp | 96 + src/syncClientSocket.h | 34 + src/syncCommand.cpp | 39 + src/syncCommand.h | 58 + src/syncConnectionCommand.cpp | 16 + src/syncConnectionCommand.h | 63 + src/syncListenSocket.h | 421 + src/syncQueue.cpp | 73 + src/syncQueue.h | 61 + src/syncRouteCommand.cpp | 16 + src/syncRouteCommand.h | 34 + src/syncRtpCommand.cpp | 16 + src/syncRtpCommand.h | 31 + src/syncSocket.cpp | 82 + src/syncSocket.h | 26 + src/syncSocketHandler.cpp | 38 + src/syncSocketHandler.h | 23 + src/threadParam.h | 53 + src/threadUtils.hpp | 175 + src/tunDevice.cpp | 168 + src/tunDevice.h | 66 + syncBuffer.cpp | 32 - syncBuffer.h | 63 - syncClientSocket.cpp | 96 - syncClientSocket.h | 34 - syncCommand.cpp | 39 - syncCommand.h | 58 - syncConnectionCommand.cpp | 16 - syncConnectionCommand.h | 63 - syncListenSocket.h | 421 - syncQueue.cpp | 73 - syncQueue.h | 61 - syncRouteCommand.cpp | 16 - syncRouteCommand.h | 34 - syncRtpCommand.cpp | 16 - syncRtpCommand.h | 31 - syncSocket.cpp | 82 - syncSocket.h | 26 - syncSocketHandler.cpp | 38 - syncSocketHandler.h | 23 - threadParam.h | 53 - threadUtils.hpp | 175 - tunDevice.cpp | 168 - tunDevice.h | 66 - vortrag | 21 - 1069 files changed, 143731 insertions(+), 143731 deletions(-) delete mode 100644 Anycast VOIP Proxy Resultat und Meilensteine.pdf delete mode 100644 Anycast VOIP Proxy Zeitplan.pdf delete mode 100644 Doxyfile delete mode 100644 Makefile delete mode 100644 PracticalSocket.cpp delete mode 100644 PracticalSocket.h delete mode 100644 Sockets/Ajp13Socket.cpp delete mode 100644 Sockets/Ajp13Socket.h delete mode 100644 Sockets/AjpBaseSocket.cpp delete mode 100644 Sockets/AjpBaseSocket.h delete mode 100644 Sockets/Base64.cpp delete mode 100644 Sockets/Base64.h delete mode 100644 Sockets/Debug.cpp delete mode 100644 Sockets/Debug.h delete mode 100644 Sockets/DevCpp/Sockets.dev delete mode 100644 Sockets/DevCpp/Test.dev delete mode 100644 Sockets/Event.cpp delete mode 100644 Sockets/Event.h delete mode 100644 Sockets/EventHandler.cpp delete mode 100644 Sockets/EventHandler.h delete mode 100644 Sockets/EventTime.cpp delete mode 100644 Sockets/EventTime.h delete mode 100644 Sockets/Exception.cpp delete mode 100644 Sockets/Exception.h delete mode 100644 Sockets/File.cpp delete mode 100644 Sockets/File.h delete mode 100644 Sockets/HTTPSocket.cpp delete mode 100644 Sockets/HTTPSocket.h delete mode 100644 Sockets/HttpBaseSocket.cpp delete mode 100644 Sockets/HttpBaseSocket.h delete mode 100644 Sockets/HttpClientSocket.cpp delete mode 100644 Sockets/HttpClientSocket.h delete mode 100644 Sockets/HttpDebugSocket.cpp delete mode 100644 Sockets/HttpDebugSocket.h delete mode 100644 Sockets/HttpGetSocket.cpp delete mode 100644 Sockets/HttpGetSocket.h delete mode 100644 Sockets/HttpPostSocket.cpp delete mode 100644 Sockets/HttpPostSocket.h delete mode 100644 Sockets/HttpPutSocket.cpp delete mode 100644 Sockets/HttpPutSocket.h delete mode 100644 Sockets/HttpRequest.cpp delete mode 100644 Sockets/HttpRequest.h delete mode 100644 Sockets/HttpResponse.cpp delete mode 100644 Sockets/HttpResponse.h delete mode 100644 Sockets/HttpTransaction.cpp delete mode 100644 Sockets/HttpTransaction.h delete mode 100644 Sockets/HttpdCookies.cpp delete mode 100644 Sockets/HttpdCookies.h delete mode 100644 Sockets/HttpdForm.cpp delete mode 100644 Sockets/HttpdForm.h delete mode 100644 Sockets/HttpdSocket.cpp delete mode 100644 Sockets/HttpdSocket.h delete mode 100644 Sockets/IBase.h delete mode 100644 Sockets/IEventHandler.h delete mode 100644 Sockets/IEventOwner.cpp delete mode 100644 Sockets/IEventOwner.h delete mode 100644 Sockets/IFile.h delete mode 100644 Sockets/IHttpServer.h delete mode 100644 Sockets/ISocketHandler.h delete mode 100644 Sockets/Ipv4Address.cpp delete mode 100644 Sockets/Ipv4Address.h delete mode 100644 Sockets/Ipv6Address.cpp delete mode 100644 Sockets/Ipv6Address.h delete mode 100644 Sockets/ListenSocket.h delete mode 100644 Sockets/Lock.cpp delete mode 100644 Sockets/Lock.h delete mode 100644 Sockets/Makefile delete mode 100644 Sockets/Makefile.Defines.linux-x86-32 delete mode 100644 Sockets/Makefile.Defines.macosx delete mode 100644 Sockets/Makefile.Defines.solaris8 delete mode 100644 Sockets/Makefile.Defines.solaris9-sparc-64 delete mode 100644 Sockets/Makefile.Defines.win32-cygwin delete mode 100644 Sockets/Makefile.solaris9-sparc-64 delete mode 100644 Sockets/Makefile.version delete mode 100644 Sockets/MemFile.cpp delete mode 100644 Sockets/MemFile.h delete mode 100644 Sockets/Mutex.cpp delete mode 100644 Sockets/Mutex.h delete mode 100755 Sockets/OSX.zip delete mode 100644 Sockets/Parse.cpp delete mode 100644 Sockets/Parse.h delete mode 100644 Sockets/Project.net/Sockets/Sockets.sln delete mode 100644 Sockets/Project.net/Sockets/Sockets.vcproj delete mode 100644 Sockets/Project.net/Test/Test.vcproj delete mode 100644 Sockets/Project/Sockets.dsp delete mode 100644 Sockets/Project/Sockets.dsw delete mode 100644 Sockets/Project/Test.dsp delete mode 100644 Sockets/Project/echoserver.dsp delete mode 100644 Sockets/Project/stressclient.dsp delete mode 100644 Sockets/README.macosx delete mode 100644 Sockets/RandomNumber.cpp delete mode 100644 Sockets/RandomNumber.h delete mode 100644 Sockets/ResolvServer.cpp delete mode 100644 Sockets/ResolvServer.h delete mode 100644 Sockets/ResolvSocket.cpp delete mode 100644 Sockets/ResolvSocket.h delete mode 100644 Sockets/SSLInitializer.cpp delete mode 100644 Sockets/SSLInitializer.h delete mode 100644 Sockets/SctpSocket.cpp delete mode 100644 Sockets/SctpSocket.h delete mode 100644 Sockets/Semaphore.cpp delete mode 100644 Sockets/Semaphore.h delete mode 100644 Sockets/SmtpdSocket.cpp delete mode 100644 Sockets/SmtpdSocket.h delete mode 100644 Sockets/Socket.cpp delete mode 100644 Sockets/Socket.h delete mode 100644 Sockets/SocketAddress.h delete mode 100644 Sockets/SocketHandler.cpp delete mode 100644 Sockets/SocketHandler.h delete mode 100644 Sockets/Sockets-config.cpp delete mode 100644 Sockets/StdLog.h delete mode 100644 Sockets/StdoutLog.cpp delete mode 100644 Sockets/StdoutLog.h delete mode 100644 Sockets/StreamSocket.cpp delete mode 100644 Sockets/StreamSocket.h delete mode 100644 Sockets/TcpSocket.cpp delete mode 100644 Sockets/TcpSocket.h delete mode 100644 Sockets/Thread.cpp delete mode 100644 Sockets/Thread.h delete mode 100644 Sockets/UdpSocket.cpp delete mode 100644 Sockets/UdpSocket.h delete mode 100644 Sockets/Utility.cpp delete mode 100644 Sockets/Utility.h delete mode 100644 Sockets/ajp13.h delete mode 100644 Sockets/gpl.txt delete mode 100755 Sockets/mkdot.sh delete mode 100644 Sockets/socket_include.cpp delete mode 100644 Sockets/socket_include.h delete mode 100644 Sockets/sockets-config.h delete mode 100644 Sockets/tests/Makefile delete mode 100644 Sockets/tests/base64.cpp delete mode 100644 Sockets/tests/copy.cpp delete mode 100644 Sockets/tests/crlf.cpp delete mode 100644 Sockets/tests/echoserver.cpp delete mode 100644 Sockets/tests/events.cpp delete mode 100644 Sockets/tests/http.cpp delete mode 100644 Sockets/tests/http_post.cpp delete mode 100644 Sockets/tests/httpd.cpp delete mode 100644 Sockets/tests/https.cpp delete mode 100644 Sockets/tests/resolve.cpp delete mode 100644 Sockets/tests/resume.cpp delete mode 100644 Sockets/tests/retry.cpp delete mode 100644 Sockets/tests/semtest.cpp delete mode 100644 Sockets/tests/sloppy_http.cpp delete mode 100644 Sockets/tests/sockets_test.cpp delete mode 100644 Sockets/tests/stressclient.cpp delete mode 100644 Sockets/tests/x.cpp delete mode 100644 anycast-voip-diagramm.pdf delete mode 100644 anyctrOptions.cpp delete mode 100644 anyctrOptions.h delete mode 100644 anymuxOptions.cpp delete mode 100644 anymuxOptions.h delete mode 100644 anyrtpproxy/Makefile delete mode 100644 anyrtpproxy/anyrtpproxy.cpp delete mode 100644 anyrtpproxy/callIdQueue.cpp delete mode 100644 anyrtpproxy/callIdQueue.h delete mode 100644 anyrtpproxy/commandHandler.cpp delete mode 100644 anyrtpproxy/commandHandler.h delete mode 100644 anyrtpproxy/connectionList.cpp delete mode 100644 anyrtpproxy/connectionList.h delete mode 100644 anyrtpproxy/options.cpp delete mode 100644 anyrtpproxy/options.h delete mode 100644 anyrtpproxy/portWindow.cpp delete mode 100644 anyrtpproxy/portWindow.h delete mode 100644 anytun-config.cpp delete mode 100644 anytun-controld.cpp delete mode 100644 anytun-showtables.cpp delete mode 100644 anytun.cpp delete mode 100644 authAlgo.cpp delete mode 100644 authAlgo.h delete mode 100644 authAlgoFactory.cpp delete mode 100644 authAlgoFactory.h delete mode 100644 buffer.cpp delete mode 100644 buffer.h delete mode 100644 cipher.cpp delete mode 100644 cipher.h delete mode 100644 cipherFactory.cpp delete mode 100644 cipherFactory.h delete mode 100755 configure delete mode 100644 connectionList.cpp delete mode 100644 connectionList.h delete mode 100644 connectionParam.cpp delete mode 100644 connectionParam.h delete mode 100644 datatypes.h delete mode 100644 draft-gsenger-secure-anycast-tunneling-protocol-02.html delete mode 100644 draft-gsenger-secure-anycast-tunneling-protocol-02.txt delete mode 100644 draft-gsenger-secure-anycast-tunneling-protocol-02.xml delete mode 100644 encryptedPacket.cpp delete mode 100644 encryptedPacket.h delete mode 100644 keyDerivation.cpp delete mode 100644 keyDerivation.h delete mode 100644 keyDerivationFactory.cpp delete mode 100644 keyDerivationFactory.h delete mode 100644 log.cpp delete mode 100644 log.h delete mode 100644 man/Makefile delete mode 100644 man/anytun.txt delete mode 100644 mpi.cpp delete mode 100644 mpi.h delete mode 100644 muxSocket.cpp delete mode 100644 muxSocket.h delete mode 100644 networkAddress.cpp delete mode 100644 networkAddress.h delete mode 100644 networkPrefix.cpp delete mode 100644 networkPrefix.h delete mode 100644 openvpn/AUTHORS delete mode 100644 openvpn/COPYING delete mode 100644 openvpn/COPYRIGHT.GPL delete mode 100644 openvpn/ChangeLog delete mode 100644 openvpn/INSTALL delete mode 100644 openvpn/INSTALL-win32.txt delete mode 100644 openvpn/Makefile.am delete mode 100644 openvpn/Makefile.in delete mode 100644 openvpn/NEWS delete mode 100644 openvpn/PORTS delete mode 100644 openvpn/README delete mode 100644 openvpn/acinclude.m4 delete mode 100644 openvpn/aclocal.m4 delete mode 100644 openvpn/base64.c delete mode 100644 openvpn/base64.h delete mode 100644 openvpn/basic.h delete mode 100644 openvpn/buffer.c delete mode 100644 openvpn/buffer.h delete mode 100644 openvpn/circ_list.h delete mode 100644 openvpn/common.h delete mode 100644 openvpn/config-win32.h.in delete mode 100755 openvpn/config.guess delete mode 100644 openvpn/config.h.in delete mode 100755 openvpn/config.sub delete mode 100755 openvpn/configure delete mode 100644 openvpn/configure.ac delete mode 100644 openvpn/contrib/README delete mode 100644 openvpn/contrib/multilevel-init.patch delete mode 100644 openvpn/contrib/openvpn-fwmarkroute-1.00/README delete mode 100755 openvpn/contrib/openvpn-fwmarkroute-1.00/fwmarkroute.down delete mode 100755 openvpn/contrib/openvpn-fwmarkroute-1.00/fwmarkroute.up delete mode 100644 openvpn/contrib/pull-resolv-conf/client.down delete mode 100644 openvpn/contrib/pull-resolv-conf/client.up delete mode 100644 openvpn/crypto.c delete mode 100644 openvpn/crypto.h delete mode 100644 openvpn/cryptoapi.c delete mode 100644 openvpn/cryptoapi.h delete mode 100644 openvpn/debug/valgrind-suppress delete mode 100755 openvpn/depcomp delete mode 100755 openvpn/doclean delete mode 100644 openvpn/easy-rsa/.externals delete mode 100644 openvpn/easy-rsa/2.0/Makefile delete mode 100644 openvpn/easy-rsa/2.0/README delete mode 100755 openvpn/easy-rsa/2.0/build-ca delete mode 100755 openvpn/easy-rsa/2.0/build-dh delete mode 100755 openvpn/easy-rsa/2.0/build-inter delete mode 100755 openvpn/easy-rsa/2.0/build-key delete mode 100755 openvpn/easy-rsa/2.0/build-key-pass delete mode 100755 openvpn/easy-rsa/2.0/build-key-pkcs12 delete mode 100755 openvpn/easy-rsa/2.0/build-key-server delete mode 100755 openvpn/easy-rsa/2.0/build-req delete mode 100755 openvpn/easy-rsa/2.0/build-req-pass delete mode 100755 openvpn/easy-rsa/2.0/clean-all delete mode 100755 openvpn/easy-rsa/2.0/inherit-inter delete mode 100755 openvpn/easy-rsa/2.0/list-crl delete mode 100755 openvpn/easy-rsa/2.0/openssl-0.9.6.cnf delete mode 100755 openvpn/easy-rsa/2.0/openssl.cnf delete mode 100755 openvpn/easy-rsa/2.0/pkitool delete mode 100755 openvpn/easy-rsa/2.0/revoke-full delete mode 100755 openvpn/easy-rsa/2.0/sign-req delete mode 100755 openvpn/easy-rsa/2.0/vars delete mode 100755 openvpn/easy-rsa/2.0/whichopensslcnf delete mode 100644 openvpn/easy-rsa/README delete mode 100644 openvpn/easy-rsa/Windows/README.txt delete mode 100644 openvpn/easy-rsa/Windows/build-ca.bat delete mode 100644 openvpn/easy-rsa/Windows/build-dh.bat delete mode 100644 openvpn/easy-rsa/Windows/build-key-pkcs12.bat delete mode 100644 openvpn/easy-rsa/Windows/build-key-server.bat delete mode 100644 openvpn/easy-rsa/Windows/build-key.bat delete mode 100644 openvpn/easy-rsa/Windows/clean-all.bat delete mode 100644 openvpn/easy-rsa/Windows/index.txt.start delete mode 100755 openvpn/easy-rsa/Windows/init-config.bat delete mode 100644 openvpn/easy-rsa/Windows/revoke-full.bat delete mode 100644 openvpn/easy-rsa/Windows/serial.start delete mode 100644 openvpn/easy-rsa/Windows/vars.bat.sample delete mode 100755 openvpn/easy-rsa/build-ca delete mode 100755 openvpn/easy-rsa/build-dh delete mode 100755 openvpn/easy-rsa/build-inter delete mode 100755 openvpn/easy-rsa/build-key delete mode 100755 openvpn/easy-rsa/build-key-pass delete mode 100755 openvpn/easy-rsa/build-key-pkcs12 delete mode 100755 openvpn/easy-rsa/build-key-server delete mode 100755 openvpn/easy-rsa/build-req delete mode 100755 openvpn/easy-rsa/build-req-pass delete mode 100755 openvpn/easy-rsa/clean-all delete mode 100644 openvpn/easy-rsa/list-crl delete mode 100644 openvpn/easy-rsa/make-crl delete mode 100644 openvpn/easy-rsa/openssl.cnf delete mode 100644 openvpn/easy-rsa/revoke-crt delete mode 100755 openvpn/easy-rsa/revoke-full delete mode 100755 openvpn/easy-rsa/sign-req delete mode 100644 openvpn/easy-rsa/vars delete mode 100644 openvpn/errlevel.h delete mode 100644 openvpn/error.c delete mode 100644 openvpn/error.h delete mode 100644 openvpn/event.c delete mode 100644 openvpn/event.h delete mode 100644 openvpn/fdmisc.c delete mode 100644 openvpn/fdmisc.h delete mode 100644 openvpn/forward-inline.h delete mode 100644 openvpn/forward.c delete mode 100644 openvpn/forward.h delete mode 100644 openvpn/fragment.c delete mode 100644 openvpn/fragment.h delete mode 100755 openvpn/gentoo/openvpn.init delete mode 100644 openvpn/gremlin.c delete mode 100644 openvpn/gremlin.h delete mode 100644 openvpn/helper.c delete mode 100644 openvpn/helper.h delete mode 100644 openvpn/init.c delete mode 100644 openvpn/init.h delete mode 100755 openvpn/install-sh delete mode 100644 openvpn/install-win32/.svnignore delete mode 100755 openvpn/install-win32/buildopensslpath.bat delete mode 100755 openvpn/install-win32/openssl.bat delete mode 100755 openvpn/install-win32/openvpn.nsi.in delete mode 100755 openvpn/install-win32/prebuild delete mode 100755 openvpn/install-win32/sample.ovpn delete mode 100755 openvpn/install-win32/setpath.nsi delete mode 100755 openvpn/install-win32/u2d.c delete mode 100644 openvpn/integer.h delete mode 100644 openvpn/interval.c delete mode 100644 openvpn/interval.h delete mode 100644 openvpn/list.c delete mode 100644 openvpn/list.h delete mode 100644 openvpn/lzo.c delete mode 100644 openvpn/lzo.h delete mode 100755 openvpn/makefile.w32 delete mode 100644 openvpn/makefile.w32-vc delete mode 100644 openvpn/manage.c delete mode 100644 openvpn/manage.h delete mode 100644 openvpn/management/management-notes.txt delete mode 100644 openvpn/mbuf.c delete mode 100644 openvpn/mbuf.h delete mode 100644 openvpn/memcmp.c delete mode 100644 openvpn/memdbg.h delete mode 100644 openvpn/misc.c delete mode 100644 openvpn/misc.h delete mode 100755 openvpn/missing delete mode 100644 openvpn/mroute.c delete mode 100644 openvpn/mroute.h delete mode 100644 openvpn/mss.c delete mode 100644 openvpn/mss.h delete mode 100644 openvpn/mtcp.c delete mode 100644 openvpn/mtcp.h delete mode 100644 openvpn/mtu.c delete mode 100644 openvpn/mtu.h delete mode 100644 openvpn/mudp.c delete mode 100644 openvpn/mudp.h delete mode 100644 openvpn/multi.c delete mode 100644 openvpn/multi.h delete mode 100644 openvpn/ntlm.c delete mode 100644 openvpn/ntlm.h delete mode 100644 openvpn/occ-inline.h delete mode 100644 openvpn/occ.c delete mode 100644 openvpn/occ.h delete mode 100644 openvpn/openvpn-plugin.h delete mode 100644 openvpn/openvpn.8 delete mode 100644 openvpn/openvpn.c delete mode 100644 openvpn/openvpn.h delete mode 100644 openvpn/openvpn.spec.in delete mode 100644 openvpn/options.c delete mode 100644 openvpn/options.h delete mode 100644 openvpn/otime.c delete mode 100644 openvpn/otime.h delete mode 100644 openvpn/packet_id.c delete mode 100644 openvpn/packet_id.h delete mode 100644 openvpn/perf.c delete mode 100644 openvpn/perf.h delete mode 100644 openvpn/ping-inline.h delete mode 100644 openvpn/ping.c delete mode 100644 openvpn/ping.h delete mode 100644 openvpn/plugin.c delete mode 100644 openvpn/plugin.h delete mode 100644 openvpn/plugin/README delete mode 100755 openvpn/plugin/auth-pam/Makefile delete mode 100644 openvpn/plugin/auth-pam/README delete mode 100644 openvpn/plugin/auth-pam/auth-pam.c delete mode 100644 openvpn/plugin/auth-pam/pamdl.c delete mode 100644 openvpn/plugin/auth-pam/pamdl.h delete mode 100755 openvpn/plugin/down-root/Makefile delete mode 100644 openvpn/plugin/down-root/README delete mode 100644 openvpn/plugin/down-root/down-root.c delete mode 100644 openvpn/plugin/examples/README delete mode 100755 openvpn/plugin/examples/build delete mode 100644 openvpn/plugin/examples/simple.c delete mode 100755 openvpn/plugin/examples/simple.def delete mode 100755 openvpn/plugin/examples/winbuild delete mode 100644 openvpn/pool.c delete mode 100644 openvpn/pool.h delete mode 100644 openvpn/proto.c delete mode 100644 openvpn/proto.h delete mode 100644 openvpn/proxy.c delete mode 100644 openvpn/proxy.h delete mode 100644 openvpn/push.c delete mode 100644 openvpn/push.h delete mode 100644 openvpn/reliable.c delete mode 100644 openvpn/reliable.h delete mode 100644 openvpn/route.c delete mode 100644 openvpn/route.h delete mode 100644 openvpn/sample-config-files/README delete mode 100644 openvpn/sample-config-files/client.conf delete mode 100755 openvpn/sample-config-files/firewall.sh delete mode 100755 openvpn/sample-config-files/home.up delete mode 100644 openvpn/sample-config-files/loopback-client delete mode 100644 openvpn/sample-config-files/loopback-server delete mode 100755 openvpn/sample-config-files/office.up delete mode 100755 openvpn/sample-config-files/openvpn-shutdown.sh delete mode 100755 openvpn/sample-config-files/openvpn-startup.sh delete mode 100644 openvpn/sample-config-files/server.conf delete mode 100644 openvpn/sample-config-files/static-home.conf delete mode 100644 openvpn/sample-config-files/static-office.conf delete mode 100644 openvpn/sample-config-files/tls-home.conf delete mode 100644 openvpn/sample-config-files/tls-office.conf delete mode 100644 openvpn/sample-config-files/xinetd-client-config delete mode 100644 openvpn/sample-config-files/xinetd-server-config delete mode 100644 openvpn/sample-keys/README delete mode 100644 openvpn/sample-keys/client.crt delete mode 100644 openvpn/sample-keys/client.key delete mode 100644 openvpn/sample-keys/dh1024.pem delete mode 100644 openvpn/sample-keys/pass.crt delete mode 100644 openvpn/sample-keys/pass.key delete mode 100644 openvpn/sample-keys/pkcs12.p12 delete mode 100644 openvpn/sample-keys/server.crt delete mode 100644 openvpn/sample-keys/server.key delete mode 100644 openvpn/sample-keys/tmp-ca.crt delete mode 100644 openvpn/sample-keys/tmp-ca.key delete mode 100755 openvpn/sample-scripts/auth-pam.pl delete mode 100755 openvpn/sample-scripts/bridge-start delete mode 100755 openvpn/sample-scripts/bridge-stop delete mode 100755 openvpn/sample-scripts/openvpn.init delete mode 100755 openvpn/sample-scripts/verify-cn delete mode 100644 openvpn/schedule.c delete mode 100644 openvpn/schedule.h delete mode 100755 openvpn/service-win32/Makefile delete mode 100755 openvpn/service-win32/mkpatch delete mode 100755 openvpn/service-win32/openvpnserv.c delete mode 100755 openvpn/service-win32/service.patch delete mode 100644 openvpn/session_id.c delete mode 100644 openvpn/session_id.h delete mode 100644 openvpn/shaper.c delete mode 100644 openvpn/shaper.h delete mode 100644 openvpn/sig.c delete mode 100644 openvpn/sig.h delete mode 100644 openvpn/socket.c delete mode 100644 openvpn/socket.h delete mode 100644 openvpn/socks.c delete mode 100644 openvpn/socks.h delete mode 100644 openvpn/ssl.c delete mode 100644 openvpn/ssl.h delete mode 100644 openvpn/status.c delete mode 100644 openvpn/status.h delete mode 100644 openvpn/suse/openvpn.init delete mode 100644 openvpn/syshead.h delete mode 100755 openvpn/t_cltsrv.sh delete mode 100755 openvpn/t_lpback.sh delete mode 100755 openvpn/tap-win32/MAKEFILE delete mode 100755 openvpn/tap-win32/SOURCES delete mode 100755 openvpn/tap-win32/amd64/OemWin2k.inf delete mode 100755 openvpn/tap-win32/amd64/tap.cat delete mode 100755 openvpn/tap-win32/common.h delete mode 100755 openvpn/tap-win32/constants.h delete mode 100755 openvpn/tap-win32/dhcp.c delete mode 100755 openvpn/tap-win32/dhcp.h delete mode 100755 openvpn/tap-win32/endian.h delete mode 100755 openvpn/tap-win32/error.c delete mode 100755 openvpn/tap-win32/error.h delete mode 100755 openvpn/tap-win32/hexdump.c delete mode 100755 openvpn/tap-win32/hexdump.h delete mode 100755 openvpn/tap-win32/i386/OemWin2k.inf delete mode 100755 openvpn/tap-win32/i386/tap.cat delete mode 100755 openvpn/tap-win32/instance.c delete mode 100755 openvpn/tap-win32/lock.h delete mode 100755 openvpn/tap-win32/macinfo.c delete mode 100755 openvpn/tap-win32/macinfo.h delete mode 100755 openvpn/tap-win32/mem.c delete mode 100755 openvpn/tap-win32/proto.h delete mode 100755 openvpn/tap-win32/prototypes.h delete mode 100755 openvpn/tap-win32/resource.rc delete mode 100755 openvpn/tap-win32/tapdrvr.c delete mode 100755 openvpn/tap-win32/types.h delete mode 100644 openvpn/thread.c delete mode 100644 openvpn/thread.h delete mode 100644 openvpn/tun.c delete mode 100644 openvpn/tun.h delete mode 100755 openvpn/win32.c delete mode 100755 openvpn/win32.h delete mode 100644 options.cpp delete mode 100644 options.h delete mode 100644 packetSource.cpp delete mode 100644 packetSource.h create mode 100644 papers/Anycast VOIP Proxy Resultat und Meilensteine.pdf create mode 100644 papers/Anycast VOIP Proxy Zeitplan.pdf create mode 100644 papers/anycast-voip-diagramm.pdf create mode 100644 papers/draft-gsenger-secure-anycast-tunneling-protocol-02.html create mode 100644 papers/draft-gsenger-secure-anycast-tunneling-protocol-02.txt create mode 100644 papers/draft-gsenger-secure-anycast-tunneling-protocol-02.xml create mode 100644 papers/vortrag delete mode 100644 plainPacket.cpp delete mode 100644 plainPacket.h delete mode 100644 router.cpp delete mode 100644 router.h delete mode 100644 routingTable.cpp delete mode 100644 routingTable.h delete mode 100644 rtpSession.cpp delete mode 100644 rtpSession.h delete mode 100644 rtpSessionTable.cpp delete mode 100644 rtpSessionTable.h delete mode 100644 seqWindow.cpp delete mode 100644 seqWindow.h delete mode 100644 signalController.cpp delete mode 100644 signalController.h create mode 100644 src/Doxyfile create mode 100644 src/Makefile create mode 100644 src/PracticalSocket.cpp create mode 100644 src/PracticalSocket.h create mode 100644 src/Sockets/Ajp13Socket.cpp create mode 100644 src/Sockets/Ajp13Socket.h create mode 100644 src/Sockets/AjpBaseSocket.cpp create mode 100644 src/Sockets/AjpBaseSocket.h create mode 100644 src/Sockets/Base64.cpp create mode 100644 src/Sockets/Base64.h create mode 100644 src/Sockets/Debug.cpp create mode 100644 src/Sockets/Debug.h create mode 100644 src/Sockets/DevCpp/Sockets.dev create mode 100644 src/Sockets/DevCpp/Test.dev create mode 100644 src/Sockets/Event.cpp create mode 100644 src/Sockets/Event.h create mode 100644 src/Sockets/EventHandler.cpp create mode 100644 src/Sockets/EventHandler.h create mode 100644 src/Sockets/EventTime.cpp create mode 100644 src/Sockets/EventTime.h create mode 100644 src/Sockets/Exception.cpp create mode 100644 src/Sockets/Exception.h create mode 100644 src/Sockets/File.cpp create mode 100644 src/Sockets/File.h create mode 100644 src/Sockets/HTTPSocket.cpp create mode 100644 src/Sockets/HTTPSocket.h create mode 100644 src/Sockets/HttpBaseSocket.cpp create mode 100644 src/Sockets/HttpBaseSocket.h create mode 100644 src/Sockets/HttpClientSocket.cpp create mode 100644 src/Sockets/HttpClientSocket.h create mode 100644 src/Sockets/HttpDebugSocket.cpp create mode 100644 src/Sockets/HttpDebugSocket.h create mode 100644 src/Sockets/HttpGetSocket.cpp create mode 100644 src/Sockets/HttpGetSocket.h create mode 100644 src/Sockets/HttpPostSocket.cpp create mode 100644 src/Sockets/HttpPostSocket.h create mode 100644 src/Sockets/HttpPutSocket.cpp create mode 100644 src/Sockets/HttpPutSocket.h create mode 100644 src/Sockets/HttpRequest.cpp create mode 100644 src/Sockets/HttpRequest.h create mode 100644 src/Sockets/HttpResponse.cpp create mode 100644 src/Sockets/HttpResponse.h create mode 100644 src/Sockets/HttpTransaction.cpp create mode 100644 src/Sockets/HttpTransaction.h create mode 100644 src/Sockets/HttpdCookies.cpp create mode 100644 src/Sockets/HttpdCookies.h create mode 100644 src/Sockets/HttpdForm.cpp create mode 100644 src/Sockets/HttpdForm.h create mode 100644 src/Sockets/HttpdSocket.cpp create mode 100644 src/Sockets/HttpdSocket.h create mode 100644 src/Sockets/IBase.h create mode 100644 src/Sockets/IEventHandler.h create mode 100644 src/Sockets/IEventOwner.cpp create mode 100644 src/Sockets/IEventOwner.h create mode 100644 src/Sockets/IFile.h create mode 100644 src/Sockets/IHttpServer.h create mode 100644 src/Sockets/ISocketHandler.h create mode 100644 src/Sockets/Ipv4Address.cpp create mode 100644 src/Sockets/Ipv4Address.h create mode 100644 src/Sockets/Ipv6Address.cpp create mode 100644 src/Sockets/Ipv6Address.h create mode 100644 src/Sockets/ListenSocket.h create mode 100644 src/Sockets/Lock.cpp create mode 100644 src/Sockets/Lock.h create mode 100644 src/Sockets/Makefile create mode 100644 src/Sockets/Makefile.Defines.linux-x86-32 create mode 100644 src/Sockets/Makefile.Defines.macosx create mode 100644 src/Sockets/Makefile.Defines.solaris8 create mode 100644 src/Sockets/Makefile.Defines.solaris9-sparc-64 create mode 100644 src/Sockets/Makefile.Defines.win32-cygwin create mode 100644 src/Sockets/Makefile.solaris9-sparc-64 create mode 100644 src/Sockets/Makefile.version create mode 100644 src/Sockets/MemFile.cpp create mode 100644 src/Sockets/MemFile.h create mode 100644 src/Sockets/Mutex.cpp create mode 100644 src/Sockets/Mutex.h create mode 100755 src/Sockets/OSX.zip create mode 100644 src/Sockets/Parse.cpp create mode 100644 src/Sockets/Parse.h create mode 100644 src/Sockets/Project.net/Sockets/Sockets.sln create mode 100644 src/Sockets/Project.net/Sockets/Sockets.vcproj create mode 100644 src/Sockets/Project.net/Test/Test.vcproj create mode 100644 src/Sockets/Project/Sockets.dsp create mode 100644 src/Sockets/Project/Sockets.dsw create mode 100644 src/Sockets/Project/Test.dsp create mode 100644 src/Sockets/Project/echoserver.dsp create mode 100644 src/Sockets/Project/stressclient.dsp create mode 100644 src/Sockets/README.macosx create mode 100644 src/Sockets/RandomNumber.cpp create mode 100644 src/Sockets/RandomNumber.h create mode 100644 src/Sockets/ResolvServer.cpp create mode 100644 src/Sockets/ResolvServer.h create mode 100644 src/Sockets/ResolvSocket.cpp create mode 100644 src/Sockets/ResolvSocket.h create mode 100644 src/Sockets/SSLInitializer.cpp create mode 100644 src/Sockets/SSLInitializer.h create mode 100644 src/Sockets/SctpSocket.cpp create mode 100644 src/Sockets/SctpSocket.h create mode 100644 src/Sockets/Semaphore.cpp create mode 100644 src/Sockets/Semaphore.h create mode 100644 src/Sockets/SmtpdSocket.cpp create mode 100644 src/Sockets/SmtpdSocket.h create mode 100644 src/Sockets/Socket.cpp create mode 100644 src/Sockets/Socket.h create mode 100644 src/Sockets/SocketAddress.h create mode 100644 src/Sockets/SocketHandler.cpp create mode 100644 src/Sockets/SocketHandler.h create mode 100644 src/Sockets/Sockets-config.cpp create mode 100644 src/Sockets/StdLog.h create mode 100644 src/Sockets/StdoutLog.cpp create mode 100644 src/Sockets/StdoutLog.h create mode 100644 src/Sockets/StreamSocket.cpp create mode 100644 src/Sockets/StreamSocket.h create mode 100644 src/Sockets/TcpSocket.cpp create mode 100644 src/Sockets/TcpSocket.h create mode 100644 src/Sockets/Thread.cpp create mode 100644 src/Sockets/Thread.h create mode 100644 src/Sockets/UdpSocket.cpp create mode 100644 src/Sockets/UdpSocket.h create mode 100644 src/Sockets/Utility.cpp create mode 100644 src/Sockets/Utility.h create mode 100644 src/Sockets/ajp13.h create mode 100644 src/Sockets/gpl.txt create mode 100755 src/Sockets/mkdot.sh create mode 100644 src/Sockets/socket_include.cpp create mode 100644 src/Sockets/socket_include.h create mode 100644 src/Sockets/sockets-config.h create mode 100644 src/Sockets/tests/Makefile create mode 100644 src/Sockets/tests/base64.cpp create mode 100644 src/Sockets/tests/copy.cpp create mode 100644 src/Sockets/tests/crlf.cpp create mode 100644 src/Sockets/tests/echoserver.cpp create mode 100644 src/Sockets/tests/events.cpp create mode 100644 src/Sockets/tests/http.cpp create mode 100644 src/Sockets/tests/http_post.cpp create mode 100644 src/Sockets/tests/httpd.cpp create mode 100644 src/Sockets/tests/https.cpp create mode 100644 src/Sockets/tests/resolve.cpp create mode 100644 src/Sockets/tests/resume.cpp create mode 100644 src/Sockets/tests/retry.cpp create mode 100644 src/Sockets/tests/semtest.cpp create mode 100644 src/Sockets/tests/sloppy_http.cpp create mode 100644 src/Sockets/tests/sockets_test.cpp create mode 100644 src/Sockets/tests/stressclient.cpp create mode 100644 src/Sockets/tests/x.cpp create mode 100644 src/anyctrOptions.cpp create mode 100644 src/anyctrOptions.h create mode 100644 src/anymuxOptions.cpp create mode 100644 src/anymuxOptions.h create mode 100644 src/anyrtpproxy/Makefile create mode 100644 src/anyrtpproxy/anyrtpproxy.cpp create mode 100644 src/anyrtpproxy/callIdQueue.cpp create mode 100644 src/anyrtpproxy/callIdQueue.h create mode 100644 src/anyrtpproxy/commandHandler.cpp create mode 100644 src/anyrtpproxy/commandHandler.h create mode 100644 src/anyrtpproxy/connectionList.cpp create mode 100644 src/anyrtpproxy/connectionList.h create mode 100644 src/anyrtpproxy/options.cpp create mode 100644 src/anyrtpproxy/options.h create mode 100644 src/anyrtpproxy/portWindow.cpp create mode 100644 src/anyrtpproxy/portWindow.h create mode 100644 src/anytun-config.cpp create mode 100644 src/anytun-controld.cpp create mode 100644 src/anytun-showtables.cpp create mode 100644 src/anytun.cpp create mode 100644 src/authAlgo.cpp create mode 100644 src/authAlgo.h create mode 100644 src/authAlgoFactory.cpp create mode 100644 src/authAlgoFactory.h create mode 100644 src/buffer.cpp create mode 100644 src/buffer.h create mode 100644 src/cipher.cpp create mode 100644 src/cipher.h create mode 100644 src/cipherFactory.cpp create mode 100644 src/cipherFactory.h create mode 100755 src/configure create mode 100644 src/connectionList.cpp create mode 100644 src/connectionList.h create mode 100644 src/connectionParam.cpp create mode 100644 src/connectionParam.h create mode 100644 src/datatypes.h create mode 100644 src/encryptedPacket.cpp create mode 100644 src/encryptedPacket.h create mode 100644 src/keyDerivation.cpp create mode 100644 src/keyDerivation.h create mode 100644 src/keyDerivationFactory.cpp create mode 100644 src/keyDerivationFactory.h create mode 100644 src/log.cpp create mode 100644 src/log.h create mode 100644 src/man/Makefile create mode 100644 src/man/anytun.txt create mode 100644 src/mpi.cpp create mode 100644 src/mpi.h create mode 100644 src/muxSocket.cpp create mode 100644 src/muxSocket.h create mode 100644 src/networkAddress.cpp create mode 100644 src/networkAddress.h create mode 100644 src/networkPrefix.cpp create mode 100644 src/networkPrefix.h create mode 100644 src/openvpn/AUTHORS create mode 100644 src/openvpn/COPYING create mode 100644 src/openvpn/COPYRIGHT.GPL create mode 100644 src/openvpn/ChangeLog create mode 100644 src/openvpn/INSTALL create mode 100644 src/openvpn/INSTALL-win32.txt create mode 100644 src/openvpn/Makefile.am create mode 100644 src/openvpn/Makefile.in create mode 100644 src/openvpn/NEWS create mode 100644 src/openvpn/PORTS create mode 100644 src/openvpn/README create mode 100644 src/openvpn/acinclude.m4 create mode 100644 src/openvpn/aclocal.m4 create mode 100644 src/openvpn/base64.c create mode 100644 src/openvpn/base64.h create mode 100644 src/openvpn/basic.h create mode 100644 src/openvpn/buffer.c create mode 100644 src/openvpn/buffer.h create mode 100644 src/openvpn/circ_list.h create mode 100644 src/openvpn/common.h create mode 100644 src/openvpn/config-win32.h.in create mode 100755 src/openvpn/config.guess create mode 100644 src/openvpn/config.h.in create mode 100755 src/openvpn/config.sub create mode 100755 src/openvpn/configure create mode 100644 src/openvpn/configure.ac create mode 100644 src/openvpn/contrib/README create mode 100644 src/openvpn/contrib/multilevel-init.patch create mode 100644 src/openvpn/contrib/openvpn-fwmarkroute-1.00/README create mode 100755 src/openvpn/contrib/openvpn-fwmarkroute-1.00/fwmarkroute.down create mode 100755 src/openvpn/contrib/openvpn-fwmarkroute-1.00/fwmarkroute.up create mode 100644 src/openvpn/contrib/pull-resolv-conf/client.down create mode 100644 src/openvpn/contrib/pull-resolv-conf/client.up create mode 100644 src/openvpn/crypto.c create mode 100644 src/openvpn/crypto.h create mode 100644 src/openvpn/cryptoapi.c create mode 100644 src/openvpn/cryptoapi.h create mode 100644 src/openvpn/debug/valgrind-suppress create mode 100755 src/openvpn/depcomp create mode 100755 src/openvpn/doclean create mode 100644 src/openvpn/easy-rsa/.externals create mode 100644 src/openvpn/easy-rsa/2.0/Makefile create mode 100644 src/openvpn/easy-rsa/2.0/README create mode 100755 src/openvpn/easy-rsa/2.0/build-ca create mode 100755 src/openvpn/easy-rsa/2.0/build-dh create mode 100755 src/openvpn/easy-rsa/2.0/build-inter create mode 100755 src/openvpn/easy-rsa/2.0/build-key create mode 100755 src/openvpn/easy-rsa/2.0/build-key-pass create mode 100755 src/openvpn/easy-rsa/2.0/build-key-pkcs12 create mode 100755 src/openvpn/easy-rsa/2.0/build-key-server create mode 100755 src/openvpn/easy-rsa/2.0/build-req create mode 100755 src/openvpn/easy-rsa/2.0/build-req-pass create mode 100755 src/openvpn/easy-rsa/2.0/clean-all create mode 100755 src/openvpn/easy-rsa/2.0/inherit-inter create mode 100755 src/openvpn/easy-rsa/2.0/list-crl create mode 100755 src/openvpn/easy-rsa/2.0/openssl-0.9.6.cnf create mode 100755 src/openvpn/easy-rsa/2.0/openssl.cnf create mode 100755 src/openvpn/easy-rsa/2.0/pkitool create mode 100755 src/openvpn/easy-rsa/2.0/revoke-full create mode 100755 src/openvpn/easy-rsa/2.0/sign-req create mode 100755 src/openvpn/easy-rsa/2.0/vars create mode 100755 src/openvpn/easy-rsa/2.0/whichopensslcnf create mode 100644 src/openvpn/easy-rsa/README create mode 100644 src/openvpn/easy-rsa/Windows/README.txt create mode 100644 src/openvpn/easy-rsa/Windows/build-ca.bat create mode 100644 src/openvpn/easy-rsa/Windows/build-dh.bat create mode 100644 src/openvpn/easy-rsa/Windows/build-key-pkcs12.bat create mode 100644 src/openvpn/easy-rsa/Windows/build-key-server.bat create mode 100644 src/openvpn/easy-rsa/Windows/build-key.bat create mode 100644 src/openvpn/easy-rsa/Windows/clean-all.bat create mode 100644 src/openvpn/easy-rsa/Windows/index.txt.start create mode 100755 src/openvpn/easy-rsa/Windows/init-config.bat create mode 100644 src/openvpn/easy-rsa/Windows/revoke-full.bat create mode 100644 src/openvpn/easy-rsa/Windows/serial.start create mode 100644 src/openvpn/easy-rsa/Windows/vars.bat.sample create mode 100755 src/openvpn/easy-rsa/build-ca create mode 100755 src/openvpn/easy-rsa/build-dh create mode 100755 src/openvpn/easy-rsa/build-inter create mode 100755 src/openvpn/easy-rsa/build-key create mode 100755 src/openvpn/easy-rsa/build-key-pass create mode 100755 src/openvpn/easy-rsa/build-key-pkcs12 create mode 100755 src/openvpn/easy-rsa/build-key-server create mode 100755 src/openvpn/easy-rsa/build-req create mode 100755 src/openvpn/easy-rsa/build-req-pass create mode 100755 src/openvpn/easy-rsa/clean-all create mode 100644 src/openvpn/easy-rsa/list-crl create mode 100644 src/openvpn/easy-rsa/make-crl create mode 100644 src/openvpn/easy-rsa/openssl.cnf create mode 100644 src/openvpn/easy-rsa/revoke-crt create mode 100755 src/openvpn/easy-rsa/revoke-full create mode 100755 src/openvpn/easy-rsa/sign-req create mode 100644 src/openvpn/easy-rsa/vars create mode 100644 src/openvpn/errlevel.h create mode 100644 src/openvpn/error.c create mode 100644 src/openvpn/error.h create mode 100644 src/openvpn/event.c create mode 100644 src/openvpn/event.h create mode 100644 src/openvpn/fdmisc.c create mode 100644 src/openvpn/fdmisc.h create mode 100644 src/openvpn/forward-inline.h create mode 100644 src/openvpn/forward.c create mode 100644 src/openvpn/forward.h create mode 100644 src/openvpn/fragment.c create mode 100644 src/openvpn/fragment.h create mode 100755 src/openvpn/gentoo/openvpn.init create mode 100644 src/openvpn/gremlin.c create mode 100644 src/openvpn/gremlin.h create mode 100644 src/openvpn/helper.c create mode 100644 src/openvpn/helper.h create mode 100644 src/openvpn/init.c create mode 100644 src/openvpn/init.h create mode 100755 src/openvpn/install-sh create mode 100644 src/openvpn/install-win32/.svnignore create mode 100755 src/openvpn/install-win32/buildopensslpath.bat create mode 100755 src/openvpn/install-win32/openssl.bat create mode 100755 src/openvpn/install-win32/openvpn.nsi.in create mode 100755 src/openvpn/install-win32/prebuild create mode 100755 src/openvpn/install-win32/sample.ovpn create mode 100755 src/openvpn/install-win32/setpath.nsi create mode 100755 src/openvpn/install-win32/u2d.c create mode 100644 src/openvpn/integer.h create mode 100644 src/openvpn/interval.c create mode 100644 src/openvpn/interval.h create mode 100644 src/openvpn/list.c create mode 100644 src/openvpn/list.h create mode 100644 src/openvpn/lzo.c create mode 100644 src/openvpn/lzo.h create mode 100755 src/openvpn/makefile.w32 create mode 100644 src/openvpn/makefile.w32-vc create mode 100644 src/openvpn/manage.c create mode 100644 src/openvpn/manage.h create mode 100644 src/openvpn/management/management-notes.txt create mode 100644 src/openvpn/mbuf.c create mode 100644 src/openvpn/mbuf.h create mode 100644 src/openvpn/memcmp.c create mode 100644 src/openvpn/memdbg.h create mode 100644 src/openvpn/misc.c create mode 100644 src/openvpn/misc.h create mode 100755 src/openvpn/missing create mode 100644 src/openvpn/mroute.c create mode 100644 src/openvpn/mroute.h create mode 100644 src/openvpn/mss.c create mode 100644 src/openvpn/mss.h create mode 100644 src/openvpn/mtcp.c create mode 100644 src/openvpn/mtcp.h create mode 100644 src/openvpn/mtu.c create mode 100644 src/openvpn/mtu.h create mode 100644 src/openvpn/mudp.c create mode 100644 src/openvpn/mudp.h create mode 100644 src/openvpn/multi.c create mode 100644 src/openvpn/multi.h create mode 100644 src/openvpn/ntlm.c create mode 100644 src/openvpn/ntlm.h create mode 100644 src/openvpn/occ-inline.h create mode 100644 src/openvpn/occ.c create mode 100644 src/openvpn/occ.h create mode 100644 src/openvpn/openvpn-plugin.h create mode 100644 src/openvpn/openvpn.8 create mode 100644 src/openvpn/openvpn.c create mode 100644 src/openvpn/openvpn.h create mode 100644 src/openvpn/openvpn.spec.in create mode 100644 src/openvpn/options.c create mode 100644 src/openvpn/options.h create mode 100644 src/openvpn/otime.c create mode 100644 src/openvpn/otime.h create mode 100644 src/openvpn/packet_id.c create mode 100644 src/openvpn/packet_id.h create mode 100644 src/openvpn/perf.c create mode 100644 src/openvpn/perf.h create mode 100644 src/openvpn/ping-inline.h create mode 100644 src/openvpn/ping.c create mode 100644 src/openvpn/ping.h create mode 100644 src/openvpn/plugin.c create mode 100644 src/openvpn/plugin.h create mode 100644 src/openvpn/plugin/README create mode 100755 src/openvpn/plugin/auth-pam/Makefile create mode 100644 src/openvpn/plugin/auth-pam/README create mode 100644 src/openvpn/plugin/auth-pam/auth-pam.c create mode 100644 src/openvpn/plugin/auth-pam/pamdl.c create mode 100644 src/openvpn/plugin/auth-pam/pamdl.h create mode 100755 src/openvpn/plugin/down-root/Makefile create mode 100644 src/openvpn/plugin/down-root/README create mode 100644 src/openvpn/plugin/down-root/down-root.c create mode 100644 src/openvpn/plugin/examples/README create mode 100755 src/openvpn/plugin/examples/build create mode 100644 src/openvpn/plugin/examples/simple.c create mode 100755 src/openvpn/plugin/examples/simple.def create mode 100755 src/openvpn/plugin/examples/winbuild create mode 100644 src/openvpn/pool.c create mode 100644 src/openvpn/pool.h create mode 100644 src/openvpn/proto.c create mode 100644 src/openvpn/proto.h create mode 100644 src/openvpn/proxy.c create mode 100644 src/openvpn/proxy.h create mode 100644 src/openvpn/push.c create mode 100644 src/openvpn/push.h create mode 100644 src/openvpn/reliable.c create mode 100644 src/openvpn/reliable.h create mode 100644 src/openvpn/route.c create mode 100644 src/openvpn/route.h create mode 100644 src/openvpn/sample-config-files/README create mode 100644 src/openvpn/sample-config-files/client.conf create mode 100755 src/openvpn/sample-config-files/firewall.sh create mode 100755 src/openvpn/sample-config-files/home.up create mode 100644 src/openvpn/sample-config-files/loopback-client create mode 100644 src/openvpn/sample-config-files/loopback-server create mode 100755 src/openvpn/sample-config-files/office.up create mode 100755 src/openvpn/sample-config-files/openvpn-shutdown.sh create mode 100755 src/openvpn/sample-config-files/openvpn-startup.sh create mode 100644 src/openvpn/sample-config-files/server.conf create mode 100644 src/openvpn/sample-config-files/static-home.conf create mode 100644 src/openvpn/sample-config-files/static-office.conf create mode 100644 src/openvpn/sample-config-files/tls-home.conf create mode 100644 src/openvpn/sample-config-files/tls-office.conf create mode 100644 src/openvpn/sample-config-files/xinetd-client-config create mode 100644 src/openvpn/sample-config-files/xinetd-server-config create mode 100644 src/openvpn/sample-keys/README create mode 100644 src/openvpn/sample-keys/client.crt create mode 100644 src/openvpn/sample-keys/client.key create mode 100644 src/openvpn/sample-keys/dh1024.pem create mode 100644 src/openvpn/sample-keys/pass.crt create mode 100644 src/openvpn/sample-keys/pass.key create mode 100644 src/openvpn/sample-keys/pkcs12.p12 create mode 100644 src/openvpn/sample-keys/server.crt create mode 100644 src/openvpn/sample-keys/server.key create mode 100644 src/openvpn/sample-keys/tmp-ca.crt create mode 100644 src/openvpn/sample-keys/tmp-ca.key create mode 100755 src/openvpn/sample-scripts/auth-pam.pl create mode 100755 src/openvpn/sample-scripts/bridge-start create mode 100755 src/openvpn/sample-scripts/bridge-stop create mode 100755 src/openvpn/sample-scripts/openvpn.init create mode 100755 src/openvpn/sample-scripts/verify-cn create mode 100644 src/openvpn/schedule.c create mode 100644 src/openvpn/schedule.h create mode 100755 src/openvpn/service-win32/Makefile create mode 100755 src/openvpn/service-win32/mkpatch create mode 100755 src/openvpn/service-win32/openvpnserv.c create mode 100755 src/openvpn/service-win32/service.patch create mode 100644 src/openvpn/session_id.c create mode 100644 src/openvpn/session_id.h create mode 100644 src/openvpn/shaper.c create mode 100644 src/openvpn/shaper.h create mode 100644 src/openvpn/sig.c create mode 100644 src/openvpn/sig.h create mode 100644 src/openvpn/socket.c create mode 100644 src/openvpn/socket.h create mode 100644 src/openvpn/socks.c create mode 100644 src/openvpn/socks.h create mode 100644 src/openvpn/ssl.c create mode 100644 src/openvpn/ssl.h create mode 100644 src/openvpn/status.c create mode 100644 src/openvpn/status.h create mode 100644 src/openvpn/suse/openvpn.init create mode 100644 src/openvpn/syshead.h create mode 100755 src/openvpn/t_cltsrv.sh create mode 100755 src/openvpn/t_lpback.sh create mode 100755 src/openvpn/tap-win32/MAKEFILE create mode 100755 src/openvpn/tap-win32/SOURCES create mode 100755 src/openvpn/tap-win32/amd64/OemWin2k.inf create mode 100755 src/openvpn/tap-win32/amd64/tap.cat create mode 100755 src/openvpn/tap-win32/common.h create mode 100755 src/openvpn/tap-win32/constants.h create mode 100755 src/openvpn/tap-win32/dhcp.c create mode 100755 src/openvpn/tap-win32/dhcp.h create mode 100755 src/openvpn/tap-win32/endian.h create mode 100755 src/openvpn/tap-win32/error.c create mode 100755 src/openvpn/tap-win32/error.h create mode 100755 src/openvpn/tap-win32/hexdump.c create mode 100755 src/openvpn/tap-win32/hexdump.h create mode 100755 src/openvpn/tap-win32/i386/OemWin2k.inf create mode 100755 src/openvpn/tap-win32/i386/tap.cat create mode 100755 src/openvpn/tap-win32/instance.c create mode 100755 src/openvpn/tap-win32/lock.h create mode 100755 src/openvpn/tap-win32/macinfo.c create mode 100755 src/openvpn/tap-win32/macinfo.h create mode 100755 src/openvpn/tap-win32/mem.c create mode 100755 src/openvpn/tap-win32/proto.h create mode 100755 src/openvpn/tap-win32/prototypes.h create mode 100755 src/openvpn/tap-win32/resource.rc create mode 100755 src/openvpn/tap-win32/tapdrvr.c create mode 100755 src/openvpn/tap-win32/types.h create mode 100644 src/openvpn/thread.c create mode 100644 src/openvpn/thread.h create mode 100644 src/openvpn/tun.c create mode 100644 src/openvpn/tun.h create mode 100755 src/openvpn/win32.c create mode 100755 src/openvpn/win32.h create mode 100644 src/options.cpp create mode 100644 src/options.h create mode 100644 src/packetSource.cpp create mode 100644 src/packetSource.h create mode 100644 src/plainPacket.cpp create mode 100644 src/plainPacket.h create mode 100644 src/router.cpp create mode 100644 src/router.h create mode 100644 src/routingTable.cpp create mode 100644 src/routingTable.h create mode 100644 src/rtpSession.cpp create mode 100644 src/rtpSession.h create mode 100644 src/rtpSessionTable.cpp create mode 100644 src/rtpSessionTable.h create mode 100644 src/seqWindow.cpp create mode 100644 src/seqWindow.h create mode 100644 src/signalController.cpp create mode 100644 src/signalController.h create mode 100644 src/syncBuffer.cpp create mode 100644 src/syncBuffer.h create mode 100644 src/syncClientSocket.cpp create mode 100644 src/syncClientSocket.h create mode 100644 src/syncCommand.cpp create mode 100644 src/syncCommand.h create mode 100644 src/syncConnectionCommand.cpp create mode 100644 src/syncConnectionCommand.h create mode 100644 src/syncListenSocket.h create mode 100644 src/syncQueue.cpp create mode 100644 src/syncQueue.h create mode 100644 src/syncRouteCommand.cpp create mode 100644 src/syncRouteCommand.h create mode 100644 src/syncRtpCommand.cpp create mode 100644 src/syncRtpCommand.h create mode 100644 src/syncSocket.cpp create mode 100644 src/syncSocket.h create mode 100644 src/syncSocketHandler.cpp create mode 100644 src/syncSocketHandler.h create mode 100644 src/threadParam.h create mode 100644 src/threadUtils.hpp create mode 100644 src/tunDevice.cpp create mode 100644 src/tunDevice.h delete mode 100644 syncBuffer.cpp delete mode 100644 syncBuffer.h delete mode 100644 syncClientSocket.cpp delete mode 100644 syncClientSocket.h delete mode 100644 syncCommand.cpp delete mode 100644 syncCommand.h delete mode 100644 syncConnectionCommand.cpp delete mode 100644 syncConnectionCommand.h delete mode 100644 syncListenSocket.h delete mode 100644 syncQueue.cpp delete mode 100644 syncQueue.h delete mode 100644 syncRouteCommand.cpp delete mode 100644 syncRouteCommand.h delete mode 100644 syncRtpCommand.cpp delete mode 100644 syncRtpCommand.h delete mode 100644 syncSocket.cpp delete mode 100644 syncSocket.h delete mode 100644 syncSocketHandler.cpp delete mode 100644 syncSocketHandler.h delete mode 100644 threadParam.h delete mode 100644 threadUtils.hpp delete mode 100644 tunDevice.cpp delete mode 100644 tunDevice.h delete mode 100644 vortrag diff --git a/Anycast VOIP Proxy Resultat und Meilensteine.pdf b/Anycast VOIP Proxy Resultat und Meilensteine.pdf deleted file mode 100644 index 6df9308..0000000 Binary files a/Anycast VOIP Proxy Resultat und Meilensteine.pdf and /dev/null differ diff --git a/Anycast VOIP Proxy Zeitplan.pdf b/Anycast VOIP Proxy Zeitplan.pdf deleted file mode 100644 index 87ed6b4..0000000 Binary files a/Anycast VOIP Proxy Zeitplan.pdf and /dev/null differ diff --git a/Doxyfile b/Doxyfile deleted file mode 100644 index 9b5e4ef..0000000 --- a/Doxyfile +++ /dev/null @@ -1,1252 +0,0 @@ -# Doxyfile 1.5.1 - -# 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 (" ") - -#--------------------------------------------------------------------------- -# Project related 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 = "anytun" - -# 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 = - -# 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 = ./doc - -# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create -# 4096 sub-directories (in 2 levels) under the output directory of each output -# format and will distribute the generated files over these directories. -# Enabling this option can be useful when feeding doxygen a huge amount of -# source files, where putting all generated files in the same directory would -# otherwise cause performance problems for the file system. - -CREATE_SUBDIRS = NO - -# 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: -# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, -# Croatian, Czech, Danish, Dutch, Finnish, French, German, Greek, Hungarian, -# Italian, Japanese, Japanese-en (Japanese with English messages), Korean, -# Korean-en, Lithuanian, Norwegian, Polish, Portuguese, Romanian, Russian, -# Serbian, Slovak, Slovene, Spanish, Swedish, and Ukrainian. - -OUTPUT_LANGUAGE = English - -# This tag can be used to specify the encoding used in the generated output. -# The encoding is not always determined by the language that is chosen, -# but also whether or not the output is meant for Windows or non-Windows users. -# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES -# forces the Windows encoding (this is the default for the Windows binary), -# whereas setting the tag to NO uses a Unix-style encoding (the default for -# all platforms other than Windows). - -USE_WINDOWS_ENCODING = NO - -# 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 - -# This tag implements a quasi-intelligent brief description abbreviator -# that is used to form the text in various listings. Each string -# in this list, if found as the leading text of the brief description, will be -# stripped from the text and the result after processing the whole list, is -# used as the annotated text. Otherwise, the brief description is used as-is. -# If left blank, the following values are used ("$name" is automatically -# replaced with the name of the entity): "The $name class" "The $name widget" -# "The $name file" "is" "provides" "specifies" "contains" -# "represents" "a" "an" "the" - -ABBREVIATE_BRIEF = - -# 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 = NO - -# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all -# inherited members of a class in the documentation of that class as if those -# members were ordinary class members. Constructors, destructors and assignment -# operators of the base classes will not be shown. - -INLINE_INHERITED_MEMB = NO - -# 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 = YES - -# 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. The tag can be used to show relative paths in the file list. -# If left blank the directory from which doxygen is run is used as the -# path to strip. - -STRIP_FROM_PATH = - -# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of -# the path mentioned in the documentation of a class, which tells -# the reader which header file to include in order to use a class. -# If left blank only the name of the header file containing the class -# definition is used. Otherwise one should specify the include paths that -# are normally passed to the compiler using the -I flag. - -STRIP_FROM_INC_PATH = - -# 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 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 -# explicit @brief command for a brief description. - -JAVADOC_AUTOBRIEF = NO - -# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen -# treat a multi-line C++ special comment block (i.e. a block of //! or /// -# comments) as a brief description. This used to be the default behaviour. -# The new default is to treat a multi-line C++ comment block as a detailed -# description. Set this tag to YES if you prefer the old behaviour instead. - -MULTILINE_CPP_IS_BRIEF = NO - -# If the DETAILS_AT_TOP tag is set to YES then Doxygen -# will output the detailed description near the top, like JavaDoc. -# If set to NO, the detailed description appears after the member -# documentation. - -DETAILS_AT_TOP = NO - -# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented -# member inherits the documentation from any documented member that it -# re-implements. - -INHERIT_DOCS = YES - -# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce -# a new page for each member. If set to NO, the documentation of a member will -# be part of the file/class/namespace that contains it. - -SEPARATE_MEMBER_PAGES = 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 - -# 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 = - -# 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 OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java -# sources only. Doxygen will then generate output that is more tailored for Java. -# For instance, namespaces will be presented as packages, qualified scopes -# will look different, etc. - -OPTIMIZE_OUTPUT_JAVA = NO - -# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want to -# include (a tag file for) the STL sources as input, then you should -# set this tag to YES in order to let doxygen match functions declarations and -# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. -# func(std::string) {}). This also make the inheritance and collaboration -# diagrams that involve STL classes more complete and accurate. - -BUILTIN_STL_SUPPORT = NO - -# 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 - -# Set the SUBGROUPING tag to YES (the default) to allow class member groups of -# the same type (for instance a group of public functions) to be put as a -# subgroup of that type (e.g. under the Public Functions section). Set it to -# NO to prevent subgrouping. Alternatively, this can be done per class using -# the \nosubgrouping command. - -SUBGROUPING = YES - -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- - -# 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 = YES - -# If the EXTRACT_PRIVATE tag is set to YES all private members of a class -# will be included in the documentation. - -EXTRACT_PRIVATE = YES - -# If the EXTRACT_STATIC tag is set to YES all static members of a file -# will be included in the documentation. - -EXTRACT_STATIC = YES - -# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) -# defined locally in source files will be included in the documentation. -# If set to NO only classes defined in header files are included. - -EXTRACT_LOCAL_CLASSES = YES - -# This flag is only useful for Objective-C code. When set to YES local -# methods, which are defined in the implementation section but not in -# the interface are included in the documentation. -# If set to NO (the default) only methods in the interface are included. - -EXTRACT_LOCAL_METHODS = 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 = NO - -# 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 classes will be included in the various -# overviews. This option has no effect if EXTRACT_ALL is enabled. - -HIDE_UNDOC_CLASSES = NO - -# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all -# friend (class|struct|union) declarations. -# If set to NO (the default) these declarations will be included in the -# documentation. - -HIDE_FRIEND_COMPOUNDS = NO - -# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any -# documentation blocks found inside the body of a function. -# If set to NO (the default) these blocks will be appended to the -# function's detailed documentation block. - -HIDE_IN_BODY_DOCS = NO - -# 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 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 -# and Mac users are advised to set this option to NO. - -CASE_SENSE_NAMES = YES - -# 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 SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen -# will put a list of the files that are included by a file in the documentation -# of that file. - -SHOW_INCLUDE_FILES = 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 the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the -# brief documentation of file, namespace and class members alphabetically -# by member name. If set to NO (the default) the members will appear in -# declaration order. - -SORT_BRIEF_DOCS = NO - -# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be -# sorted by fully-qualified names, including namespaces. If set to -# NO (the default), the class list will be sorted only by class name, -# not including the namespace part. -# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. -# Note: This option applies only to the class list, not to the -# alphabetical list. - -SORT_BY_SCOPE_NAME = NO - -# 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 = YES - -# 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 = YES - -# 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 = YES - -# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or -# disable (NO) the deprecated list. This list is created by putting -# \deprecated commands in the documentation. - -GENERATE_DEPRECATEDLIST= YES - -# 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 consists 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 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 - -# If the sources in your project are distributed over multiple directories -# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy -# in the documentation. The default is NO. - -SHOW_DIRECTORIES = NO - -# The FILE_VERSION_FILTER tag can be used to specify a program or script that -# doxygen should invoke to get the current version for each file (typically from the -# version control system). Doxygen will invoke the program by executing (via -# popen()) the command , where is the value of -# the FILE_VERSION_FILTER tag, and is the name of an input file -# provided by doxygen. Whatever the program writes to standard output -# is used as the file version. See the manual for examples. - -FILE_VERSION_FILTER = - -#--------------------------------------------------------------------------- -# 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 = NO - -# 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 - -# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for -# potential errors in the documentation, such as not documenting some -# parameters in a documented function, or documenting parameters that -# don't exist or using markup commands wrongly. - -WARN_IF_DOC_ERROR = YES - -# This WARN_NO_PARAMDOC option can be abled to get warnings for -# functions that are documented, but have no documentation for their parameters -# or return value. If set to NO (the default) doxygen will only warn about -# wrong or incomplete parameter documentation, but not about the absence of -# documentation. - -WARN_NO_PARAMDOC = NO - -# 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. Optionally the format may contain -# $version, which will be replaced by the version of the file (if it could -# be obtained via FILE_VERSION_FILTER) - -WARN_FORMAT = "$file:$line: $text" - -# 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 = - -# 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 the following patterns are tested: -# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx -# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py - -FILE_PATTERNS = - -# 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 = NO - -# 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 = - -# The EXCLUDE_SYMLINKS tag can be used select whether or not files or -# directories that are symbolic links (a Unix filesystem feature) are excluded -# from the input. - -EXCLUDE_SYMLINKS = NO - -# 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. Note that the wildcards are matched -# against the file with absolute path, so to exclude all test directories -# for example use the pattern */test/* - -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 = - -# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be -# searched for input files to be used with the \include or \dontinclude -# commands irrespective of the value of the RECURSIVE tag. -# Possible values are YES and NO. If left blank NO is used. - -EXAMPLE_RECURSIVE = NO - -# 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. If FILTER_PATTERNS is specified, this tag will be -# ignored. - -INPUT_FILTER = - -# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern -# basis. Doxygen will compare the file name with each pattern and apply the -# filter if there is a match. The filters are a list of the form: -# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further -# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER -# is applied to all files. - -FILTER_PATTERNS = - -# 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 (i.e. when SOURCE_BROWSER is set to YES). - -FILTER_SOURCE_FILES = NO - -#--------------------------------------------------------------------------- -# configuration options related to source browsing -#--------------------------------------------------------------------------- - -# 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. -# Note: To get rid of all source code in the generated output, make sure also -# VERBATIM_HEADERS is set to NO. - -SOURCE_BROWSER = NO - -# 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 = YES - -# If the REFERENCED_BY_RELATION tag is set to YES (the default) -# then for each documented function all documented -# functions referencing it will be listed. - -REFERENCED_BY_RELATION = YES - -# If the REFERENCES_RELATION tag is set to YES (the default) -# then for each documented function all documented entities -# called/used by that function will be listed. - -REFERENCES_RELATION = YES - -# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) -# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from -# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will -# link to the source code. Otherwise they will link to the documentstion. - -REFERENCES_LINK_SOURCE = YES - -# If the USE_HTAGS tag is set to YES then the references to source code -# will point to the HTML generated by the htags(1) tool instead of doxygen -# built-in source browser. The htags tool is part of GNU's global source -# tagging system (see http://www.gnu.org/software/global/global.html). You -# will need version 4.8.6 or higher. - -USE_HTAGS = 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 - -#--------------------------------------------------------------------------- -# 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 = NO - -# 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 = 5 - -# 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 = html - -# The HTML_FILE_EXTENSION tag can be used to specify the file extension for -# each generated HTML page (for example: .htm,.php,.asp). If it is left blank -# doxygen will generate files with .html extension. - -HTML_FILE_EXTENSION = .html - -# 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. Note that doxygen will try to copy -# the style sheet file to the HTML output directory, so don't put your own -# stylesheet in the HTML output directory as well, or it will be erased! - -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 CHM_FILE tag can -# be used to specify the file name of the resulting .chm file. You -# can add a path in front of the file if the result should not be -# written to the html output directory. - -CHM_FILE = - -# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can -# be used to specify the location (absolute path including file name) of -# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run -# the HTML help compiler on the generated index.hhp. - -HHC_LOCATION = - -# 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, DHTML, CSS and frames is required (for instance Mozilla 1.0+, -# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are -# probably better off using the HTML help feature. - -GENERATE_TREEVIEW = YES - -# 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 = YES - -# 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 = latex - -# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be -# invoked. If left blank `latex' will be used as the default command name. - -LATEX_CMD_NAME = latex - -# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to -# generate index for LaTeX. If left blank `makeindex' will be used as the -# default command name. - -MAKEINDEX_CMD_NAME = makeindex - -# 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 - -# If LATEX_HIDE_INDICES is set to YES then doxygen will not -# include the index chapters (such as File Index, Compound Index, etc.) -# in the output. - -LATEX_HIDE_INDICES = 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 optimized 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 = rtf - -# 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 assignments. 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 = man - -# The MAN_EXTENSION tag determines the extension that is added to -# the generated man pages (default is the subroutine's section .3) - -MAN_EXTENSION = .3 - -# 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. - -GENERATE_XML = NO - -# The XML_OUTPUT tag is used to specify where the XML 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 `xml' will be used as the default path. - -XML_OUTPUT = xml - -# The XML_SCHEMA tag can be used to specify an XML schema, -# which can be used by a validating XML parser to check the -# syntax of the XML files. - -XML_SCHEMA = - -# The XML_DTD tag can be used to specify an XML DTD, -# which can be used by a validating XML parser to check the -# syntax of the XML files. - -XML_DTD = - -# If the XML_PROGRAMLISTING tag is set to YES Doxygen will -# dump the program listings (including syntax highlighting -# and cross-referencing information) to the XML output. Note that -# enabling this will significantly increase the size of the XML output. - -XML_PROGRAMLISTING = YES - -#--------------------------------------------------------------------------- -# configuration options for the AutoGen Definitions output -#--------------------------------------------------------------------------- - -# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will -# generate an AutoGen Definitions (see autogen.sf.net) file -# that captures the structure of the code including all -# documentation. Note that this feature is still experimental -# and incomplete at the moment. - -GENERATE_AUTOGEN_DEF = NO - -#--------------------------------------------------------------------------- -# configuration options related to the Perl module output -#--------------------------------------------------------------------------- - -# If the GENERATE_PERLMOD tag is set to YES Doxygen will -# generate a Perl module file that captures the structure of -# the code including all documentation. Note that this -# feature is still experimental and incomplete at the -# moment. - -GENERATE_PERLMOD = NO - -# If the PERLMOD_LATEX tag is set to YES Doxygen will generate -# the necessary Makefile rules, Perl scripts and LaTeX code to be able -# to generate PDF and DVI output from the Perl module output. - -PERLMOD_LATEX = NO - -# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be -# nicely formatted so it can be parsed by a human reader. This is useful -# if you want to understand what is going on. On the other hand, if this -# tag is set to NO the size of the Perl module output will be much smaller -# and Perl will parse it just the same. - -PERLMOD_PRETTY = YES - -# The names of the make variables in the generated doxyrules.make file -# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. -# This is useful so different doxyrules.make files included by the same -# Makefile don't overwrite each other's variables. - -PERLMOD_MAKEVAR_PREFIX = - -#--------------------------------------------------------------------------- -# 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_DEFINED 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. To prevent a macro definition from being -# undefined via #undef or recursively expanded use the := operator -# instead of the = operator. - -PREDEFINED = - -# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF 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 = - -# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then -# doxygen's preprocessor will remove all function-like macros that are alone -# on a line, have an all uppercase name, and do not end with a semicolon. Such -# function macros are typically used for boiler-plate code, and will confuse -# the parser if not removed. - -SKIP_FUNCTION_MACROS = YES - -#--------------------------------------------------------------------------- -# Configuration::additions related to external references -#--------------------------------------------------------------------------- - -# The TAGFILES option can be used to specify one or more tagfiles. -# Optionally an initial location of the external documentation -# can be added for each tagfile. The format of a tag file without -# this location is as follows: -# TAGFILES = file1 file2 ... -# Adding location for the tag files is done as follows: -# TAGFILES = file1=loc1 "file2 = loc2" ... -# where "loc1" and "loc2" can be relative or absolute paths or -# URLs. If a location is present for each tag, the installdox tool -# does not have to be run to correct the links. -# Note that each tag file must have a unique name -# (where the name does NOT include the path) -# If a tag file is not located in the directory in which doxygen -# is run, you must also specify the path to the tagfile here. - -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 - -# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed -# in the modules index. If set to NO, only the current project's groups will -# be listed. - -EXTERNAL_GROUPS = YES - -# The PERL_PATH should be the absolute path and name of the perl script -# interpreter (i.e. the result of `which perl'). - -PERL_PATH = /usr/bin/perl - -#--------------------------------------------------------------------------- -# Configuration options related to the dot tool -#--------------------------------------------------------------------------- - -# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will -# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base -# or super classes. Setting the tag to NO turns the diagrams off. Note that -# this option is superseded by the HAVE_DOT option below. This is only a -# fallback. It is recommended to install and use dot, since it yields more -# powerful graphs. - -CLASS_DIAGRAMS = YES - -# If set to YES, the inheritance and collaboration graphs will hide -# inheritance and usage relations if the target is undocumented -# or is not a class. - -HIDE_UNDOC_RELATIONS = YES - -# 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 = NO - -# 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 the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen -# will generate a graph for groups, showing the direct groups dependencies - -GROUP_GRAPHS = YES - -# If the UML_LOOK tag is set to YES doxygen will generate inheritance and -# collaboration diagrams in a style similar to the OMG's Unified Modeling -# Language. - -UML_LOOK = NO - -# If set to YES, the inheritance and collaboration graphs will show the -# relations between templates and their instances. - -TEMPLATE_RELATIONS = NO - -# 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 CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will -# generate a call dependency graph for every global function or class method. -# Note that enabling this option will significantly increase the time of a run. -# So in most cases it will be better to enable call graphs for selected -# functions only using the \callgraph command. - -CALL_GRAPH = NO - -# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then doxygen will -# generate a caller dependency graph for every global function or class method. -# Note that enabling this option will significantly increase the time of a run. -# So in most cases it will be better to enable caller graphs for selected -# functions only using the \callergraph command. - -CALLER_GRAPH = NO - -# 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 - -# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES -# then doxygen will show the dependencies a directory has on other directories -# in a graphical way. The dependency relations are determined by the #include -# relations between the files in the directories. - -DIRECTORY_GRAPH = YES - -# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images -# generated by dot. Possible values are png, jpg, or gif -# If left blank png will be used. - -DOT_IMAGE_FORMAT = png - -# 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 in 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 - -# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the -# graphs generated by dot. A depth value of 3 means that only nodes reachable -# from the root by following a path via at most 3 edges will be shown. Nodes -# that lay further from the root node will be omitted. Note that setting this -# option to 1 or 2 may greatly reduce the computation time needed for large -# code bases. Also note that a graph may be further truncated if the graph's -# image dimensions are not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH -# and MAX_DOT_GRAPH_HEIGHT). If 0 is used for the depth value (the default), -# the graph is not depth-constrained. - -MAX_DOT_GRAPH_DEPTH = 0 - -# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent -# background. This is disabled by default, which results in a white background. -# Warning: Depending on the platform used, enabling this option may lead to -# badly anti-aliased labels on the edges of a graph (i.e. they become hard to -# read). - -DOT_TRANSPARENT = NO - -# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output -# files in one run (i.e. multiple -o and -T options on the command line). This -# makes dot run faster, but since only newer versions of dot (>1.8.10) -# support this, this feature is disabled by default. - -DOT_MULTI_TARGETS = NO - -# 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 intermediate dot files that are used to generate -# the various graphs. - -DOT_CLEANUP = YES - -#--------------------------------------------------------------------------- -# Configuration::additions 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 diff --git a/Makefile b/Makefile deleted file mode 100644 index f71f6f2..0000000 --- a/Makefile +++ /dev/null @@ -1,299 +0,0 @@ -C = gcc -CFLAGS = -g -Wall -CFLAGS += -DSOCKETS_NAMESPACE=sockets -CFLAGS += -DSOCKETS_NAMESPACE_STR='"sockets"' -C++ = g++ -CCFLAGS = -g -Wall -CCFLAGS += -DSOCKETS_NAMESPACE=sockets -CCFLAGS += -DSOCKETS_NAMESPACE_STR='"sockets"' -LD = g++ -LDFLAGS = -g -Wall -O2 -ldl -lpthread -lgcrypt -lboost_serialization - -OPENVPNDEPS = openvpn/tun.o \ - openvpn/error.o \ - openvpn/socket.o \ - openvpn/buffer.o \ - openvpn/misc.o \ - openvpn/manage.o \ - openvpn/fdmisc.o \ - openvpn/otime.o \ - openvpn/options.o \ - openvpn/mtu.o \ - openvpn/plugin.o \ - openvpn/sig.o \ - openvpn/proxy.o \ - openvpn/socks.o \ - openvpn/status.o \ - openvpn/event.o \ - openvpn/route.o \ - openvpn/helper.o \ - openvpn/init.o \ - openvpn/interval.o \ - openvpn/base64.o \ - openvpn/shaper.o \ - openvpn/fragment.o - -SOCKETDEPS = Sockets/libSockets.a - -#Sockets/TcpSocket.o \ -# Sockets/Socket.o \ -# Sockets/Thread.o \ -# Sockets/SocketHandler.o \ -# Sockets/Ipv4Address.o \ -# Sockets/Mutex.o \ -# Sockets/SSLInitializer.o - - -OBJS = tunDevice.o \ - packetSource.o \ - buffer.o \ - syncBuffer.o \ - syncCommand.o \ - syncRouteCommand.o \ - syncRtpCommand.o \ - syncConnectionCommand.o \ - plainPacket.o \ - encryptedPacket.o \ - cipher.o \ - authAlgo.o \ - keyDerivation.o \ - rtpSessionTable.o \ - rtpSession.o \ - anyrtpproxy/callIdQueue.o \ - mpi.o \ - cipherFactory.o \ - authAlgoFactory.o \ - keyDerivationFactory.o \ - connectionList.o \ - connectionParam.o \ - networkAddress.o \ - networkPrefix.o \ - PracticalSocket.o \ - router.o \ - routingTable.o \ - signalController.o \ - syncSocket.o \ - syncSocketHandler.o \ - syncClientSocket.o \ - syncQueue.o \ - log.o \ - options.o \ - seqWindow.o \ - $(OPENVPNDEPS) \ - $(SOCKETDEPS) - -ANYMUXOBJS = muxSocket.o \ - anymuxOptions.o \ - signalController.o \ - log.o \ - $(SOCKETDEPS) - -ANYCTROBJS = log.o \ - buffer.o \ - keyDerivation.o \ - mpi.o \ - keyDerivationFactory.o \ - networkAddress.o \ - networkPrefix.o \ - signalController.o \ - connectionList.o \ - connectionParam.o \ - rtpSessionTable.o \ - rtpSession.o \ - anyrtpproxy/callIdQueue.o \ - syncRtpCommand.o \ - PracticalSocket.o \ - anyctrOptions.o \ - router.o \ - routingTable.o \ - seqWindow.o \ - syncSocket.o \ - syncSocketHandler.o \ - syncClientSocket.o \ - syncQueue.o \ - syncBuffer.o \ - syncCommand.o \ - syncRouteCommand.o \ - syncConnectionCommand.o \ - $(SOCKETDEPS) - -EXECUTABLE = anytun anytun-config anytun-controld anytun-showtables manpage - -all: $(EXECUTABLE) libAnysync.a anyrtpproxy - -anytun: $(OBJS) anytun.o - $(LD) $(OBJS) anytun.o -o $@ $(LDFLAGS) - -anytun-showtables: $(OBJS) anytun-showtables.o - $(LD) $(OBJS) anytun-showtables.o -o $@ $(LDFLAGS) - -anytun-config: $(ANYCTROBJS) anytun-config.o - $(LD) $(ANYCTROBJS) anytun-config.o -o $@ $(LDFLAGS) - -anytun-controld: $(ANYMUXOBJS) anytun-controld.o - $(LD) $(ANYMUXOBJS) anytun-controld.o -o $@ $(LDFLAGS) - -tunDevice.o: tunDevice.cpp tunDevice.h - $(C++) $(CCFLAGS) $< -c - -Sockets/libSockets.a: - make --directory=./Sockets - -packetSource.o: packetSource.cpp packetSource.h - $(C++) $(CCFLAGS) $< -c - -buffer.o: buffer.cpp buffer.h - $(C++) $(CCFLAGS) $< -c - -syncBuffer.o: syncBuffer.cpp syncBuffer.h - $(C++) $(CCFLAGS) $< -c - -rtpSessionTable.o: rtpSessionTable.cpp rtpSessionTable.h - $(C++) $(CCFLAGS) $< -c - -rtpSession.o: rtpSession.cpp rtpSession.h - $(C++) $(CCFLAGS) $< -c - -plainPacket.o: plainPacket.cpp plainPacket.h buffer.h - $(C++) $(CCFLAGS) $< -c - -encryptedPacket.o: encryptedPacket.cpp encryptedPacket.h buffer.h - $(C++) $(CCFLAGS) $< -c - -cipher.o: cipher.cpp cipher.h buffer.h - $(C++) $(CCFLAGS) $< -c - -muxSocket.o: muxSocket.cpp muxSocket.h - $(C++) $(CCFLAGS) $< -c - -anymuxOptions.o: anymuxOptions.cpp anymuxOptions.h - $(C++) $(CCFLAGS) $< -c - -anyctrOptions.o: anyctrOptions.cpp anyctrOptions.h - $(C++) $(CCFLAGS) $< -c - -authAlgo.o: authAlgo.cpp authAlgo.h buffer.h - $(C++) $(CCFLAGS) $< -c - -keyDerivation.o: keyDerivation.cpp keyDerivation.h - $(C++) $(CCFLAGS) $< -c - -mpi.o: mpi.cpp mpi.h - $(C++) $(CCFLAGS) $< -c - -cipherFactory.o: cipherFactory.cpp cipherFactory.h cipher.h - $(C++) $(CCFLAGS) $< -c - -authAlgoFactory.o: authAlgoFactory.cpp authAlgoFactory.h authAlgo.h - $(C++) $(CCFLAGS) $< -c - -keyDerivationFactory.o: keyDerivationFactory.cpp keyDerivationFactory.h keyDerivation.h - $(C++) $(CCFLAGS) $< -c - -routingTable.o: routingTable.cpp routingTable.h - $(C++) $(CCFLAGS) $< -c - -syncSocket.o: syncSocket.cpp syncSocket.h - $(C++) $(CCFLAGS) $< -c - -syncSocketHandler.o: syncSocketHandler.cpp syncSocketHandler.h - $(C++) $(CCFLAGS) $< -c - -syncCommand.o: syncCommand.cpp syncCommand.h - $(C++) $(CCFLAGS) $< -c - -syncRouteCommand.o: syncRouteCommand.cpp syncRouteCommand.h - $(C++) $(CCFLAGS) $< -c - -syncRtpCommand.o: syncRtpCommand.cpp syncRtpCommand.h - $(C++) $(CCFLAGS) $< -c - -syncConnectionCommand.o: syncConnectionCommand.cpp syncConnectionCommand.h - $(C++) $(CCFLAGS) $< -c - -syncClientSocket.o: syncClientSocket.cpp syncClientSocket.h - $(C++) $(CCFLAGS) $< -c - -syncQueue.o: syncQueue.cpp syncQueue.h - $(C++) $(CCFLAGS) $< -c - -signalController.o: signalController.cpp signalController.h - $(C++) $(CCFLAGS) $< -c - -PracticalSocket.o: PracticalSocket.cpp PracticalSocket.h - $(C++) $(CCFLAGS) $< -c - -log.o: log.cpp log.h - $(C++) $(CCFLAGS) $< -c - -options.o: options.cpp options.h - $(C++) $(CCFLAGS) $< -c - -seqWindow.o: seqWindow.cpp seqWindow.h - $(C++) $(CCFLAGS) $< -c - -connectionList.o: connectionList.cpp connectionList.h - $(C++) $(CCFLAGS) $< -c - -connectionParam.o: connectionParam.cpp connectionParam.h - $(C++) $(CCFLAGS) $< -c - -networkPrefix.o: networkPrefix.cpp networkPrefix.h - $(C++) $(CCFLAGS) $< -c - -networkAddress.o: networkAddress.cpp networkAddress.h - $(C++) $(CCFLAGS) $< -c - -router.o: router.cpp router.h - $(C++) $(CCFLAGS) $< -c - -anytun.o: anytun.cpp - $(C++) $(CCFLAGS) $< -c - -anytun-showtables.o: anytun-showtables.cpp - $(C++) $(CCFLAGS) $< -c - -anytun-config.o: anytun-config.cpp - $(C++) $(CCFLAGS) $< -c - -anytun-controld.o: anytun-controld.cpp - $(C++) $(CCFLAGS) $< -c - -cConnectionParam.o: cConnectionParam.cpp - $(C++) $(CCFLAGS) $< -c - -libAnysync.a: $(OBJS) - ar cru $@ $(OBJS) - ranlib $@ - -anyrtpproxy: anytun - @cd anyrtpproxy ; make - -distclean: cleanall - make --directory=$(CURDIR)/openvpn distclean - find -name *.o | xargs rm -f - rm -f config.sub config.guess - -cleanall: clean - make --directory=$(CURDIR)/man clean - make --directory=$(CURDIR)/Sockets clean - make --directory=$(CURDIR)/openvpn clean - rm -f Sockets/libSockets.a Sockets/Sockets-config - -clean: - rm -f *.o - rm -f $(EXECUTABLE) - rm -f -r doc/html/* - rm -f -r doc/latex/* - rm -f libAnysync.a - make --directory=$(CURDIR)/anyrtpproxy clean - -manpage: - @cd man ; make - -doxygen: - doxygen Doxyfile - -ctags: - ctags -R --c++-kinds=+p --fields=+iaS --extra=+q . - diff --git a/PracticalSocket.cpp b/PracticalSocket.cpp deleted file mode 100644 index 6f7b51c..0000000 --- a/PracticalSocket.cpp +++ /dev/null @@ -1,473 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -// this is from: http://cs.ecs.baylor.edu/~donahoo/practical/CSockets/practical/ -// and this is their header: -/* - * C++ sockets on Unix and Windows - * Copyright (C) 2002 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "PracticalSocket.h" - -#ifdef WIN32 - #include // For socket(), connect(), send(), and recv() - typedef int socklen_t; - typedef char raw_type; // Type used for raw data on this platform -#else - #include // For data types - #include // For socket(), connect(), send(), and recv() - #include // For gethostbyname() - #include // For inet_addr() - #include // For close() - #include // For sockaddr_in - #include - typedef void raw_type; // Type used for raw data on this platform -#endif - -#include // For errno - -using namespace std; - -#ifdef WIN32 -static bool initialized = false; -#endif - -// SocketException Code - -SocketException::SocketException(const string &message, bool inclSysMsg) - throw() : userMessage(message) { - if (inclSysMsg) { - userMessage.append(": "); - userMessage.append(strerror(errno)); - } -} - -SocketException::~SocketException() throw() { -} - -const char *SocketException::what() const throw() { - return userMessage.c_str(); -} - -// Function to fill in address structure given an address and port -static void fillAddr(const string &address, unsigned short port, - sockaddr_in &addr) { - memset(&addr, 0, sizeof(addr)); // Zero out address structure - addr.sin_family = AF_INET; // Internet address - - hostent *host; // Resolve name - if ((host = gethostbyname(address.c_str())) == NULL) { - // strerror() will not work for gethostbyname() and hstrerror() - // is supposedly obsolete - throw SocketException("Failed to resolve name (gethostbyname())"); - } - addr.sin_addr.s_addr = *((unsigned long *) host->h_addr_list[0]); - - addr.sin_port = htons(port); // Assign port in network byte order -} - -// Socket Code - -Socket::Socket(int type, int protocol) throw(SocketException) { - #ifdef WIN32 - if (!initialized) { - WORD wVersionRequested; - WSADATA wsaData; - - wVersionRequested = MAKEWORD(2, 0); // Request WinSock v2.0 - if (WSAStartup(wVersionRequested, &wsaData) != 0) { // Load WinSock DLL - throw SocketException("Unable to load WinSock DLL"); - } - initialized = true; - } - #endif - - // Make a new socket - if ((sockDesc = socket(PF_INET, type, protocol)) < 0) { - throw SocketException("Socket creation failed (socket())", true); - } -} - -Socket::Socket(int sockDesc) { - this->sockDesc = sockDesc; -} - -Socket::~Socket() { - #ifdef WIN32 - ::closesocket(sockDesc); - #else - ::close(sockDesc); - #endif - sockDesc = -1; -} - -string Socket::getLocalAddress() throw(SocketException) { - sockaddr_in addr; - unsigned int addr_len = sizeof(addr); - - if (getsockname(sockDesc, (sockaddr *) &addr, (socklen_t *) &addr_len) < 0) { - throw SocketException("Fetch of local address failed (getsockname())", true); - } - return inet_ntoa(addr.sin_addr); -} - -unsigned short Socket::getLocalPort() throw(SocketException) { - sockaddr_in addr; - unsigned int addr_len = sizeof(addr); - - if (getsockname(sockDesc, (sockaddr *) &addr, (socklen_t *) &addr_len) < 0) { - throw SocketException("Fetch of local port failed (getsockname())", true); - } - return ntohs(addr.sin_port); -} - -void Socket::setLocalPort(unsigned short localPort) throw(SocketException) { - // Bind the socket to its port - sockaddr_in localAddr; - memset(&localAddr, 0, sizeof(localAddr)); - localAddr.sin_family = AF_INET; - localAddr.sin_addr.s_addr = htonl(INADDR_ANY); - localAddr.sin_port = htons(localPort); - - if (bind(sockDesc, (sockaddr *) &localAddr, sizeof(sockaddr_in)) < 0) { - throw SocketException("Set of local port failed (bind())", true); - } -} - -void Socket::setLocalAddressAndPort(const string &localAddress, - unsigned short localPort) throw(SocketException) { - // Get the address of the requested host - sockaddr_in localAddr; - fillAddr(localAddress, localPort, localAddr); - - if (bind(sockDesc, (sockaddr *) &localAddr, sizeof(sockaddr_in)) < 0) { - throw SocketException("Set of local address and port failed (bind())", true); - } -} - -void Socket::setSocketOpt(int optionName, const void* optionValue, socklen_t optionLen) - throw(SocketException) -{ - if (::setsockopt(sockDesc, SOL_SOCKET, optionName, optionValue, optionLen) < 0) { - throw SocketException("setSockopt failed", true); - } -} - -void Socket::cleanUp() throw(SocketException) { - #ifdef WIN32 - if (WSACleanup() != 0) { - throw SocketException("WSACleanup() failed"); - } - #endif -} - -unsigned short Socket::resolveService(const string &service, - const string &protocol) { - struct servent *serv; /* Structure containing service information */ - - if ((serv = getservbyname(service.c_str(), protocol.c_str())) == NULL) - return atoi(service.c_str()); /* Service is port number */ - else - return ntohs(serv->s_port); /* Found port (network byte order) by name */ -} - -// CommunicatingSocket Code - -CommunicatingSocket::CommunicatingSocket(int type, int protocol) - throw(SocketException) : Socket(type, protocol) { -} - -CommunicatingSocket::CommunicatingSocket(int newConnSD) : Socket(newConnSD) { -} - -void CommunicatingSocket::connect(const string &foreignAddress, - unsigned short foreignPort) throw(SocketException) { - // Get the address of the requested host - sockaddr_in destAddr; - fillAddr(foreignAddress, foreignPort, destAddr); - - // Try to connect to the given port - if (::connect(sockDesc, (sockaddr *) &destAddr, sizeof(destAddr)) < 0) { - throw SocketException("Connect failed (connect())", true); - } -} - -void CommunicatingSocket::send(const void *buffer, int bufferLen) - throw(SocketException) { - if (::send(sockDesc, (raw_type *) buffer, bufferLen, 0) < 0) { - throw SocketException("Send failed (send())", true); - } -} - -int CommunicatingSocket::recv(void *buffer, int bufferLen) - throw(SocketException) { - int rtn; - if ((rtn = ::recv(sockDesc, (raw_type *) buffer, bufferLen, 0)) < 0) { - throw SocketException("Received failed (recv())", true); - } - - return rtn; -} - -int CommunicatingSocket::recvNonBlocking(void *buffer, int bufferLen, int timeOut) - throw(SocketException) -{ - struct pollfd pfd[1]; - pfd[0].fd = sockDesc; - pfd[0].events = POLLIN; - int rtn = poll(pfd,1,timeOut); - if(rtn > 0) { - if ((rtn = ::recv(sockDesc, (raw_type *) buffer, bufferLen, 0)) < 0) { - throw SocketException("non blocking receive failed", true); - } - if(!rtn) { - throw SocketException("connection closed by peer", false); - } - } - return rtn; -} - -string CommunicatingSocket::getForeignAddress() - throw(SocketException) { - sockaddr_in addr; - unsigned int addr_len = sizeof(addr); - - if (getpeername(sockDesc, (sockaddr *) &addr,(socklen_t *) &addr_len) < 0) { - throw SocketException("Fetch of foreign address failed (getpeername())", true); - } - return inet_ntoa(addr.sin_addr); -} - -unsigned short CommunicatingSocket::getForeignPort() throw(SocketException) { - sockaddr_in addr; - unsigned int addr_len = sizeof(addr); - - if (getpeername(sockDesc, (sockaddr *) &addr, (socklen_t *) &addr_len) < 0) { - throw SocketException("Fetch of foreign port failed (getpeername())", true); - } - return ntohs(addr.sin_port); -} - -// TCPSocket Code - -TCPSocket::TCPSocket() - throw(SocketException) : CommunicatingSocket(SOCK_STREAM, - IPPROTO_TCP) { -} - -TCPSocket::TCPSocket(const string &foreignAddress, unsigned short foreignPort) - throw(SocketException) : CommunicatingSocket(SOCK_STREAM, IPPROTO_TCP) { - connect(foreignAddress, foreignPort); -} - -TCPSocket::TCPSocket(int newConnSD) : CommunicatingSocket(newConnSD) { -} - -// TCPServerSocket Code - -TCPServerSocket::TCPServerSocket(unsigned short localPort, int queueLen) - throw(SocketException) : Socket(SOCK_STREAM, IPPROTO_TCP) { - const int opt = 1; - setSocketOpt(SO_REUSEADDR, &opt, sizeof(opt)); - setLocalPort(localPort); - setListen(queueLen); -} - -TCPServerSocket::TCPServerSocket(const string &localAddress, - unsigned short localPort, int queueLen) - throw(SocketException) : Socket(SOCK_STREAM, IPPROTO_TCP) { - const int opt = 1; - setSocketOpt(SO_REUSEADDR, &opt, sizeof(opt)); - setLocalAddressAndPort(localAddress, localPort); - setListen(queueLen); -} - -TCPSocket *TCPServerSocket::accept() throw(SocketException) { - int newConnSD; - if ((newConnSD = ::accept(sockDesc, NULL, 0)) < 0) { - throw SocketException("Accept failed (accept())", true); - } - - return new TCPSocket(newConnSD); -} - -void TCPServerSocket::setListen(int queueLen) throw(SocketException) { - if (listen(sockDesc, queueLen) < 0) { - throw SocketException("Set listening socket failed (listen())", true); - } -} - -// UDPSocket Code - -UDPSocket::UDPSocket() throw(SocketException) : CommunicatingSocket(SOCK_DGRAM, - IPPROTO_UDP) { - - const int opt = 1; - setSocketOpt(SO_REUSEADDR, &opt, sizeof(opt)); - setBroadcast(); -} - -UDPSocket::UDPSocket(unsigned short localPort) throw(SocketException) : - CommunicatingSocket(SOCK_DGRAM, IPPROTO_UDP) { - const int opt = 1; - setSocketOpt(SO_REUSEADDR, &opt, sizeof(opt)); - setLocalPort(localPort); - setBroadcast(); -} - -UDPSocket::UDPSocket(const string &localAddress, unsigned short localPort) - throw(SocketException) : CommunicatingSocket(SOCK_DGRAM, IPPROTO_UDP) { - const int opt = 1; - setSocketOpt(SO_REUSEADDR, &opt, sizeof(opt)); - setLocalAddressAndPort(localAddress, localPort); - setBroadcast(); -} - -void UDPSocket::setBroadcast() { - // If this fails, we'll hear about it when we try to send. This will allow - // system that cannot broadcast to continue if they don't plan to broadcast - int broadcastPermission = 1; - setsockopt(sockDesc, SOL_SOCKET, SO_BROADCAST, - (raw_type *) &broadcastPermission, sizeof(broadcastPermission)); -} - -void UDPSocket::disconnect() throw(SocketException) { - sockaddr_in nullAddr; - memset(&nullAddr, 0, sizeof(nullAddr)); - nullAddr.sin_family = AF_UNSPEC; - - // Try to disconnect - if (::connect(sockDesc, (sockaddr *) &nullAddr, sizeof(nullAddr)) < 0) { - #ifdef WIN32 - if (errno != WSAEAFNOSUPPORT) { - #else - if (errno != EAFNOSUPPORT) { - #endif - throw SocketException("Disconnect failed (connect())", true); - } - } -} - -void UDPSocket::sendTo(const void *buffer, int bufferLen, - const string &foreignAddress, unsigned short foreignPort) - throw(SocketException) { - sockaddr_in destAddr; - fillAddr(foreignAddress, foreignPort, destAddr); - - // Write out the whole buffer as a single message. - if (sendto(sockDesc, (raw_type *) buffer, bufferLen, 0, - (sockaddr *) &destAddr, sizeof(destAddr)) != bufferLen) { - throw SocketException("Send failed (sendto())", true); - } -} - -int UDPSocket::recvFrom(void *buffer, int bufferLen, string &sourceAddress, - unsigned short &sourcePort) throw(SocketException) { - sockaddr_in clntAddr; - socklen_t addrLen = sizeof(clntAddr); - int rtn; - if ((rtn = recvfrom(sockDesc, (raw_type *) buffer, bufferLen, 0, - (sockaddr *) &clntAddr, (socklen_t *) &addrLen)) < 0) { - throw SocketException("Receive failed (recvfrom())", true); - } - sourceAddress = inet_ntoa(clntAddr.sin_addr); - sourcePort = ntohs(clntAddr.sin_port); - - return rtn; -} - -int UDPSocket::recvFromNonBlocking(void *buffer, int bufferLen, string &sourceAddress, - unsigned short &sourcePort, int timeOut) throw(SocketException) { - sockaddr_in clntAddr; - socklen_t addrLen = sizeof(clntAddr); - struct pollfd pfd[1]; - pfd[0].fd = sockDesc; - pfd[0].events = POLLIN; - int rtn = poll(pfd,1,timeOut); - if(rtn > 0) { - if ((rtn = recvfrom(sockDesc, (raw_type *) buffer, bufferLen, 0, - (sockaddr *) &clntAddr, (socklen_t *) &addrLen)) < 0) { - throw SocketException("Receive failed (recvfrom())", true); - } - if(!rtn) { - throw SocketException("connection closed by peer", false); - } - } - sourceAddress = inet_ntoa(clntAddr.sin_addr); - sourcePort = ntohs(clntAddr.sin_port); - - return rtn; -} - -void UDPSocket::setMulticastTTL(unsigned char multicastTTL) throw(SocketException) { - if (setsockopt(sockDesc, IPPROTO_IP, IP_MULTICAST_TTL, - (raw_type *) &multicastTTL, sizeof(multicastTTL)) < 0) { - throw SocketException("Multicast TTL set failed (setsockopt())", true); - } -} - -void UDPSocket::joinGroup(const string &multicastGroup) throw(SocketException) { - struct ip_mreq multicastRequest; - - multicastRequest.imr_multiaddr.s_addr = inet_addr(multicastGroup.c_str()); - multicastRequest.imr_interface.s_addr = htonl(INADDR_ANY); - if (setsockopt(sockDesc, IPPROTO_IP, IP_ADD_MEMBERSHIP, - (raw_type *) &multicastRequest, - sizeof(multicastRequest)) < 0) { - throw SocketException("Multicast group join failed (setsockopt())", true); - } -} - -void UDPSocket::leaveGroup(const string &multicastGroup) throw(SocketException) { - struct ip_mreq multicastRequest; - - multicastRequest.imr_multiaddr.s_addr = inet_addr(multicastGroup.c_str()); - multicastRequest.imr_interface.s_addr = htonl(INADDR_ANY); - if (setsockopt(sockDesc, IPPROTO_IP, IP_DROP_MEMBERSHIP, - (raw_type *) &multicastRequest, - sizeof(multicastRequest)) < 0) { - throw SocketException("Multicast group leave failed (setsockopt())", true); - } -} diff --git a/PracticalSocket.h b/PracticalSocket.h deleted file mode 100644 index 58c6424..0000000 --- a/PracticalSocket.h +++ /dev/null @@ -1,400 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -// this is from: http://cs.ecs.baylor.edu/~donahoo/practical/CSockets/practical/ -// and this is their header: -/* - * C++ sockets on Unix and Windows - * Copyright (C) 2002 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef __PRACTICALSOCKET_INCLUDED__ -#define __PRACTICALSOCKET_INCLUDED__ - -#include // For string -#include // For exception class - -using namespace std; - -/** - * Signals a problem with the execution of a socket call. - */ -class SocketException : public exception { -public: - /** - * Construct a SocketException with a explanatory message. - * @param message explanatory message - * @param incSysMsg true if system message (from strerror(errno)) - * should be postfixed to the user provided message - */ - SocketException(const string &message, bool inclSysMsg = false) throw(); - - /** - * Provided just to guarantee that no exceptions are thrown. - */ - ~SocketException() throw(); - - /** - * Get the exception message - * @return exception message - */ - const char *what() const throw(); - -private: - string userMessage; // Exception message -}; - -/** - * Base class representing basic communication endpoint - */ -class Socket { -public: - /** - * Close and deallocate this socket - */ - ~Socket(); - - /** - * Get the local address - * @return local address of socket - * @exception SocketException thrown if fetch fails - */ - string getLocalAddress() throw(SocketException); - - /** - * Get the local port - * @return local port of socket - * @exception SocketException thrown if fetch fails - */ - unsigned short getLocalPort() throw(SocketException); - - /** - * Set the local port to the specified port and the local address - * to any interface - * @param localPort local port - * @exception SocketException thrown if setting local port fails - */ - void setLocalPort(unsigned short localPort) throw(SocketException); - - /** - * Set the local port to the specified port and the local address - * to the specified address. If you omit the port, a random port - * will be selected. - * @param localAddress local address - * @param localPort local port - * @exception SocketException thrown if setting local port or address fails - */ - void setLocalAddressAndPort(const string &localAddress, - unsigned short localPort = 0) throw(SocketException); - - - void setSocketOpt(int optionName, const void* optionValue, socklen_t optionLen) - throw(SocketException); - - /** - * If WinSock, unload the WinSock DLLs; otherwise do nothing. We ignore - * this in our sample client code but include it in the library for - * completeness. If you are running on Windows and you are concerned - * about DLL resource consumption, call this after you are done with all - * Socket instances. If you execute this on Windows while some instance of - * Socket exists, you are toast. For portability of client code, this is - * an empty function on non-Windows platforms so you can always include it. - * @param buffer buffer to receive the data - * @param bufferLen maximum number of bytes to read into buffer - * @return number of bytes read, 0 for EOF, and -1 for error - * @exception SocketException thrown WinSock clean up fails - */ - static void cleanUp() throw(SocketException); - - /** - * Resolve the specified service for the specified protocol to the - * corresponding port number in host byte order - * @param service service to resolve (e.g., "http") - * @param protocol protocol of service to resolve. Default is "tcp". - */ - static unsigned short resolveService(const string &service, - const string &protocol = "tcp"); - -private: - // Prevent the user from trying to use value semantics on this object - Socket(const Socket &sock); - void operator=(const Socket &sock); - -protected: - int sockDesc; // Socket descriptor - Socket(int type, int protocol) throw(SocketException); - Socket(int sockDesc); -}; - -/** - * Socket which is able to connect, send, and receive - */ -class CommunicatingSocket : public Socket { -public: - /** - * Establish a socket connection with the given foreign - * address and port - * @param foreignAddress foreign address (IP address or name) - * @param foreignPort foreign port - * @exception SocketException thrown if unable to establish connection - */ - void connect(const string &foreignAddress, unsigned short foreignPort) - throw(SocketException); - - /** - * Write the given buffer to this socket. Call connect() before - * calling send() - * @param buffer buffer to be written - * @param bufferLen number of bytes from buffer to be written - * @exception SocketException thrown if unable to send data - */ - void send(const void *buffer, int bufferLen) throw(SocketException); - - /** - * Read into the given buffer up to bufferLen bytes data from this - * socket. Call connect() before calling recv() - * @param buffer buffer to receive the data - * @param bufferLen maximum number of bytes to read into buffer - * @return number of bytes read, 0 for EOF, and -1 for error - * @exception SocketException thrown if unable to receive data - */ - int recv(void *buffer, int bufferLen) throw(SocketException); - - /** - * Read into the given buffer up to bufferLen bytes data from this - * socket. Call connect() before recvNonBlocking(). - * @param buffer buffer to receive the data - * @param bufferLen maximum number of bytes to read into buffer - * @param timeout timout in ms - * @return number of bytes read, 0 for timeout, and -1 for error - * @exception SocketException thrown if unable to receive data - */ - int recvNonBlocking(void *buffer, int bufferLen, int timeout) throw(SocketException); - - /** - * Get the foreign address. Call connect() before calling recv() - * @return foreign address - * @exception SocketException thrown if unable to fetch foreign address - */ - string getForeignAddress() throw(SocketException); - - /** - * Get the foreign port. Call connect() before calling recv() - * @return foreign port - * @exception SocketException thrown if unable to fetch foreign port - */ - unsigned short getForeignPort() throw(SocketException); - -protected: - CommunicatingSocket(int type, int protocol) throw(SocketException); - CommunicatingSocket(int newConnSD); -}; - -/** - * TCP socket for communication with other TCP sockets - */ -class TCPSocket : public CommunicatingSocket { -public: - /** - * Construct a TCP socket with no connection - * @exception SocketException thrown if unable to create TCP socket - */ - TCPSocket() throw(SocketException); - - /** - * Construct a TCP socket with a connection to the given foreign address - * and port - * @param foreignAddress foreign address (IP address or name) - * @param foreignPort foreign port - * @exception SocketException thrown if unable to create TCP socket - */ - TCPSocket(const string &foreignAddress, unsigned short foreignPort) - throw(SocketException); - -private: - // Access for TCPServerSocket::accept() connection creation - friend class TCPServerSocket; - TCPSocket(int newConnSD); -}; - -/** - * TCP socket class for servers - */ -class TCPServerSocket : public Socket { -public: - /** - * Construct a TCP socket for use with a server, accepting connections - * on the specified port on any interface - * @param localPort local port of server socket, a value of zero will - * give a system-assigned unused port - * @param queueLen maximum queue length for outstanding - * connection requests (default 5) - * @exception SocketException thrown if unable to create TCP server socket - */ - TCPServerSocket(unsigned short localPort, int queueLen = 5) - throw(SocketException); - - /** - * Construct a TCP socket for use with a server, accepting connections - * on the specified port on the interface specified by the given address - * @param localAddress local interface (address) of server socket - * @param localPort local port of server socket - * @param queueLen maximum queue length for outstanding - * connection requests (default 5) - * @exception SocketException thrown if unable to create TCP server socket - */ - TCPServerSocket(const string &localAddress, unsigned short localPort, - int queueLen = 5) throw(SocketException); - - /** - * Blocks until a new connection is established on this socket or error - * @return new connection socket - * @exception SocketException thrown if attempt to accept a new connection fails - */ - TCPSocket *accept() throw(SocketException); - -private: - void setListen(int queueLen) throw(SocketException); -}; - -/** - * UDP socket class - */ -class UDPSocket : public CommunicatingSocket { -public: - /** - * Construct a UDP socket - * @exception SocketException thrown if unable to create UDP socket - */ - UDPSocket() throw(SocketException); - - /** - * Construct a UDP socket with the given local port - * @param localPort local port - * @exception SocketException thrown if unable to create UDP socket - */ - UDPSocket(unsigned short localPort) throw(SocketException); - - /** - * Construct a UDP socket with the given local port and address - * @param localAddress local address - * @param localPort local port - * @exception SocketException thrown if unable to create UDP socket - */ - UDPSocket(const string &localAddress, unsigned short localPort) - throw(SocketException); - - /** - * Unset foreign address and port - * @return true if disassociation is successful - * @exception SocketException thrown if unable to disconnect UDP socket - */ - void disconnect() throw(SocketException); - - /** - * Send the given buffer as a UDP datagram to the - * specified address/port - * @param buffer buffer to be written - * @param bufferLen number of bytes to write - * @param foreignAddress address (IP address or name) to send to - * @param foreignPort port number to send to - * @return true if send is successful - * @exception SocketException thrown if unable to send datagram - */ - void sendTo(const void *buffer, int bufferLen, const string &foreignAddress, - unsigned short foreignPort) throw(SocketException); - - /** - * Read read up to bufferLen bytes data from this socket. The given buffer - * is where the data will be placed - * @param buffer buffer to receive data - * @param bufferLen maximum number of bytes to receive - * @param sourceAddress address of datagram source - * @param sourcePort port of data source - * @return number of bytes received and -1 for error - * @exception SocketException thrown if unable to receive datagram - */ - int recvFrom(void *buffer, int bufferLen, string &sourceAddress, - unsigned short &sourcePort) throw(SocketException); - - /** - * Read read up to bufferLen bytes data from this socket. The given buffer - * is where the data will be placed - * @param buffer buffer to receive data - * @param bufferLen maximum number of bytes to receive - * @param sourceAddress address of datagram source - * @param sourcePort port of data source - * @param timeout int ms - * @return number of bytes received and -1 for error - * @exception SocketException thrown if unable to receive datagram - */ - int recvFromNonBlocking(void *buffer, int bufferLen, string &sourceAddress, - unsigned short &sourcePort, int timeout) throw(SocketException); - - /** - * Set the multicast TTL - * @param multicastTTL multicast TTL - * @exception SocketException thrown if unable to set TTL - */ - void setMulticastTTL(unsigned char multicastTTL) throw(SocketException); - - /** - * Join the specified multicast group - * @param multicastGroup multicast group address to join - * @exception SocketException thrown if unable to join group - */ - void joinGroup(const string &multicastGroup) throw(SocketException); - - /** - * Leave the specified multicast group - * @param multicastGroup multicast group address to leave - * @exception SocketException thrown if unable to leave group - */ - void leaveGroup(const string &multicastGroup) throw(SocketException); - -private: - void setBroadcast(); -}; - -#endif diff --git a/README b/README index 82f26de..1a83c37 100644 --- a/README +++ b/README @@ -17,7 +17,7 @@ svn co http://anytun.org/svn/anytun/ Building from source -------------------- -cd anytun +cd src ./configure make diff --git a/Sockets/Ajp13Socket.cpp b/Sockets/Ajp13Socket.cpp deleted file mode 100644 index 57755f0..0000000 --- a/Sockets/Ajp13Socket.cpp +++ /dev/null @@ -1,404 +0,0 @@ -/** - ** \file Ajp13Socket.cpp - ** \date 2007-10-05 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif -#include "Ajp13Socket.h" -#include "ajp13.h" -#include "HttpRequest.h" -#include "HttpResponse.h" -#include "IFile.h" -#include "Utility.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -#ifdef _DEBUG -#define DEB(x) x -#else -#define DEB(x) -#endif - - -// -------------------------------------------------------------------------------------- -Ajp13Socket::Ajp13Socket(ISocketHandler& h) : AjpBaseSocket(h) -, m_body_size_left(0) -, m_res_file(NULL) -{ -} - - -// -------------------------------------------------------------------------------------- -void Ajp13Socket::OnHeader( short id, short len ) -{ - if (id != 0x1234) - { - fprintf(stderr, "ABORT: bad packet id: %x\n", id); - SetCloseAndDelete(); - } - else - { - DEB(fprintf(stderr, "Packet size: %d bytes\n", len);) - } -} - - -// -------------------------------------------------------------------------------------- -void Ajp13Socket::ReceiveBody(const char *buf, size_t sz) -{ - if (sz - 2 > m_body_size_left) - { - fprintf(stderr, "More body data received than expected\n"); - SetCloseAndDelete(); - return; - } - - m_req.Write( buf + 2, sz - 2 ); - m_body_size_left -= sz - 2; - - // request more body data - if (m_body_size_left) - { - int ptr = 4; - char msg[100]; - msg[0] = 'A'; - msg[1] = 'B'; - -// reply codes -// 0x3 Send Body Chunk -// 0x4 Send Headers -// 0x5 End Response -// 0x6 Get Body Chunk <------ -// 0x9 CPong Reply - - put_byte(msg, ptr, 0x06); // GET_BODY_CHUNK; - put_integer(msg, ptr, 1000); // request 1000 bytes - - short len = htons( ptr - 4 ); - memcpy( msg + 2, &len, 2 ); - - SendBuf( msg, ptr ); - return; - } - - // Close - m_req.CloseBody(); - - // no more body data left to read - execute - Execute(); - -} - - -// -------------------------------------------------------------------------------------- -void Ajp13Socket::ReceiveForwardRequest( const char *buf, size_t sz ) -{ - // - int ptr = 0; - - get_byte(buf, ptr); // skip first byte: prefix_code - unsigned char method = get_byte(buf, ptr); - std::string protocol = get_string(buf, ptr); - std::string req_uri = get_string(buf, ptr); - std::string remote_addr = get_string(buf, ptr); - std::string remote_host = get_string(buf, ptr); - std::string server_name = get_string(buf, ptr); - short server_port = get_integer(buf, ptr); - bool is_ssl = get_boolean(buf, ptr); - - std::string method_str = Utility::l2string( method ); - std::map::const_iterator it = Init.Method.find( method ); - if (it != Init.Method.end()) - { - method_str = it -> second; - } - m_req.SetHttpMethod( method_str ); - m_req.SetHttpVersion( protocol ); - m_req.SetUri( req_uri ); - m_req.SetRemoteAddr( remote_addr ); - m_req.SetRemoteHost( remote_host ); - m_req.SetServerName( server_name ); - m_req.SetServerPort( server_port ); - m_req.SetIsSsl( is_ssl ); - - // Get Headers - short num_headers = get_integer(buf, ptr); - for (int i = 0; i < num_headers; i++) - { - std::string key; - switch ( (unsigned char)buf[ptr]) // 0xa0 - { - case 0xa0: - { - unsigned short x = (unsigned short)get_integer(buf, ptr); - std::map::const_iterator it; - if ( (it = Init.Header.find(x)) != Init.Header.end()) - { - key = it -> second; - } - else - { - fprintf(stderr, "Unknown header key value: %x\n", x); - SetCloseAndDelete(); - } - } - break; - - default: // string - key = get_string(buf, ptr); - } - if (Utility::ToLower(key) == "cookie" || Utility::ToLower(key) == "cookie2") - m_req.AddCookie(get_string(buf, ptr)); - else - m_req.SetHeader(key, get_string(buf, ptr)); - } // for - - // size left to read from web server - m_body_size_left = m_req.ContentLength(); - - // Get Attributes - while ( (unsigned char)buf[ptr] != 0xff) - { - std::string key; - unsigned char code = buf[ptr++]; - switch ( code) - { - case 10: // req_attribute, attribute name follow - key = get_string(buf, ptr); - break; - default: - { - std::map::const_iterator it = Init.Attribute.find( code ); - if (it != Init.Attribute.end()) - { - key = it -> second; - } - else - { - fprintf(stderr, "Unknown attribute key: 0x%02x\n", buf[ptr]); - SetCloseAndDelete(); - } - } - } - m_req.SetAttribute(key, get_string(buf, ptr)); - } // while - - // execute at once if no body data - if (!m_body_size_left) - { - Execute(); - } - else - { - // open temporary file for body data - m_req.InitBody( m_body_size_left ); - } -} - - -// -------------------------------------------------------------------------------------- -void Ajp13Socket::ReceiveShutdown( const char *buf, size_t sz ) -{ -} - - -// -------------------------------------------------------------------------------------- -void Ajp13Socket::ReceivePing( const char *buf, size_t sz ) -{ -} - - -// -------------------------------------------------------------------------------------- -void Ajp13Socket::ReceiveCPing( const char *buf, size_t sz ) -{ -} - - -// -------------------------------------------------------------------------------------- -void Ajp13Socket::Execute() -{ - // parse form data / query_string and cookie header if available - m_req.ParseBody(); - - // prepare page - OnExec( m_req ); - -} - - -// -------------------------------------------------------------------------------------- -void Ajp13Socket::Respond(const HttpResponse& res) -{ - char msg[8192]; - msg[0] = 'A'; - msg[1] = 'B'; - -// reply codes -// 0x3 Send Body Chunk -// 0x4 Send Headers -// 0x5 End Response -// 0x6 Get Body Chunk -// 0x9 CPong Reply - - // check content length - if (!res.ContentLength() && res.GetFile().size()) - { -// res.SetContentLength( res.GetFile().size() ); - } - - // Send Headers - { - int ptr = 4; - put_byte(msg, ptr, 0x04); // send headers - put_integer(msg, ptr, res.HttpStatusCode() ); - put_string(msg, ptr, res.HttpStatusMsg() ); - put_integer(msg, ptr, (short)res.Headers().size() ); - for (std::map::const_iterator it = res.Headers().begin(); it != res.Headers().end(); ++it) - { - std::map::const_iterator it2 = Init.ResponseHeader.find( it -> first ); - if (it2 != Init.ResponseHeader.end()) - { - put_integer(msg, ptr, it2 -> second); - } - else - { - put_string(msg, ptr, it -> first); - } - put_string(msg, ptr, it -> second); - } - std::list vec = res.CookieNames(); - { - for (std::list::iterator it = vec.begin(); it != vec.end(); it++) - { - std::map::const_iterator it2 = Init.ResponseHeader.find( "set-cookie" ); - if (it2 != Init.ResponseHeader.end()) - { - put_integer(msg, ptr, it2 -> second); - } - else - { - put_string(msg, ptr, "set-cookie"); - } - put_string(msg, ptr, res.Cookie(*it) ); - } - } - - short len = htons( ptr - 4 ); - memcpy( msg + 2, &len, 2 ); - - SendBuf( msg, ptr ); - } - m_res_file = &res.GetFile(); - // Send Body Chunk - OnTransferLimit(); -} - - -// -------------------------------------------------------------------------------------- -void Ajp13Socket::OnTransferLimit() -{ - char msg[8192]; - msg[0] = 'A'; - msg[1] = 'B'; - - // Send Body Chunk - size_t n = m_res_file -> fread(msg + 7, 1, 8100); - while (n > 0) - { - int ptr = 4; - put_byte(msg, ptr, 0x03); // send body chunk - put_integer(msg, ptr, (short)n); - ptr += (int)n; - - short len = htons( ptr - 4 ); - memcpy( msg + 2, &len, 2 ); - - SendBuf( msg, ptr ); - if (GetOutputLength() > 1) - { - SetTransferLimit( 1 ); - break; - } - - // - n = m_res_file -> fread(msg + 7, 1, 8100); - } - if (!GetOutputLength()) // all body data sent and no data in output buffer - send end response - { - // End Response - int ptr = 4; - put_byte(msg, ptr, 0x05); // end response - put_boolean(msg, ptr, false); // reuse - /* - don't reuse - - but with m_req.Reset() and res.Reset() it should be possible - - also reset any AjpBaseSocket/Ajp13Socket specific states - */ - - short len = htons( ptr - 4 ); - memcpy( msg + 2, &len, 2 ); - - SendBuf( msg, ptr ); - } -} - - -// -------------------------------------------------------------------------------------- -void Ajp13Socket::OnPacket( const char *buf, size_t sz ) -{ - DEB(fprintf(stderr, "OnPacket: %d bytes, code 0x%02x %02x %02x %02x\n", sz, *buf, buf[1], buf[2], buf[3]);) - - // check body size left to read, if non-zero packet is body data - if (m_body_size_left) // must be a body packet - { - ReceiveBody(buf, sz); - return; - } - switch (*buf) - { - case 0x2: // Forward Request - ReceiveForwardRequest(buf, sz); - break; - case 0x7: // Shutdown - ReceiveShutdown(buf, sz); - break; - case 0x8: // Ping - ReceivePing(buf, sz); - break; - case 0xa: // CPing - ReceiveCPing(buf, sz); - break; - default: - fprintf(stderr, "Unknown packet type: 0x%02x\n", *buf); - SetCloseAndDelete(); - } - -} - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - - diff --git a/Sockets/Ajp13Socket.h b/Sockets/Ajp13Socket.h deleted file mode 100644 index 3da5be7..0000000 --- a/Sockets/Ajp13Socket.h +++ /dev/null @@ -1,69 +0,0 @@ -/** - ** \file Ajp13Socket.h - ** \date 2007-10-05 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_Ajp13Socket_H -#define _SOCKETS_Ajp13Socket_H - -#include "AjpBaseSocket.h" -#include "HttpRequest.h" -#include "IHttpServer.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -class HttpResponse; - -class Ajp13Socket : public AjpBaseSocket, public IHttpServer -{ -public: - Ajp13Socket(ISocketHandler& h); - - void OnHeader( short id, short len ); - void OnPacket( const char *buf, size_t sz ); - - // implements IHttpServer::Respond - void Respond(const HttpResponse& res); - - void OnTransferLimit(); - -private: - void ReceiveBody( const char *buf, size_t sz ); - void ReceiveForwardRequest( const char *buf, size_t sz ); - void ReceiveShutdown( const char *buf, size_t sz ); - void ReceivePing( const char *buf, size_t sz ); - void ReceiveCPing( const char *buf, size_t sz ); - void Execute(); - // - size_t m_body_size_left; - HttpRequest m_req; - const IFile *m_res_file; -}; - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - -#endif // _SOCKETS_Ajp13Socket_H - diff --git a/Sockets/AjpBaseSocket.cpp b/Sockets/AjpBaseSocket.cpp deleted file mode 100644 index 3b54dd0..0000000 --- a/Sockets/AjpBaseSocket.cpp +++ /dev/null @@ -1,258 +0,0 @@ -/** - ** \file AjpBaseSocket.cpp - ** \date 2007-10-05 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif -#include "AjpBaseSocket.h" -#include "ajp13.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -#ifdef _DEBUG -#define DEB(x) x -#else -#define DEB(x) -#endif - - -// --------------------------------------------------------------------------- -AjpBaseSocket::Initializer AjpBaseSocket::Init; - - -// --------------------------------------------------------------------------- -AjpBaseSocket::Initializer::Initializer() -{ - - Header[HTTP_REQUEST_ACCEPT] = "accept"; - Header[HTTP_REQUEST_ACCEPT_CHARSET] = "accept-charset"; - Header[HTTP_REQUEST_ACCEPT_ENCODING] = "accept-encoding"; - Header[HTTP_REQUEST_ACCEPT_LANGUAGE] = "accept-language"; - Header[HTTP_REQUEST_AUTHORIZATION] = "authorization"; - Header[HTTP_REQUEST_CONNECTION] = "connection"; - Header[HTTP_REQUEST_CONTENT_TYPE] = "content-type"; - Header[HTTP_REQUEST_CONTENT_LENGTH] = "content-length"; - Header[HTTP_REQUEST_COOKIE] = "cookie"; - Header[HTTP_REQUEST_COOKIE2] = "cookie2"; - Header[HTTP_REQUEST_HOST] = "host"; - Header[HTTP_REQUEST_PRAGMA] = "pragma"; - Header[HTTP_REQUEST_REFERER] = "referer"; - Header[HTTP_REQUEST_USER_AGENT] = "user-agent"; - - Method[HTTP_METHOD_OPTIONS] = "OPTIONS"; - Method[HTTP_METHOD_GET] = "GET"; - Method[HTTP_METHOD_HEAD] = "HEAD"; - Method[HTTP_METHOD_POST] = "POST"; - Method[HTTP_METHOD_PUT] = "PUT"; - Method[HTTP_METHOD_DELETE] = "DELETE"; - Method[HTTP_METHOD_TRACE] = "TRACE"; - Method[HTTP_METHOD_PROPFIND] = "PROPFIND"; - Method[HTTP_METHOD_PROPPATCH] = "PROPPATCH"; - Method[HTTP_METHOD_MKCOL] = "MKCOL"; - Method[HTTP_METHOD_COPY] = "COPY"; - Method[HTTP_METHOD_MOVE] = "MOVE"; - Method[HTTP_METHOD_LOCK] = "LOCK"; - Method[HTTP_METHOD_UNLOCK] = "UNLOCK"; - Method[HTTP_METHOD_ACL] = "ACL"; - Method[HTTP_METHOD_REPORT] = "REPORT"; - Method[HTTP_METHOD_VERSION_CONTROL] = "VERSION_CONTROL"; // with a dash "VERSION-CONTROL" - Method[HTTP_METHOD_CHECKIN] = "CHECKIN"; - Method[HTTP_METHOD_CHECKOUT] = "CHECKOUT"; - Method[HTTP_METHOD_UNCHECKOUT] = "UNCHECKOUT"; - Method[HTTP_METHOD_SEARCH] = "SEARCH"; - Method[HTTP_METHOD_MKWORKSPACE] = "MKWORKSPACE"; - Method[HTTP_METHOD_UPDATE] = "UPDATE"; - Method[HTTP_METHOD_LABEL] = "LABEL"; - Method[HTTP_METHOD_MERGE] = "MERGE"; - Method[HTTP_METHOD_BASELINE_CONTROL] = "BASELINE_CONTROL"; - Method[HTTP_METHOD_MKACTIVITY] = "MKACTIVITY"; - - Attribute[ATTR_CONTEXT] = "context"; - Attribute[ATTR_SERVLET_PATH] = "servlet_path"; - Attribute[ATTR_REMOTE_USER] = "remote_user"; - Attribute[ATTR_AUTH_TYPE] = "auth_type"; - Attribute[ATTR_QUERY_STRING] = "query_string"; - Attribute[ATTR_ROUTE] = "route"; - Attribute[ATTR_SSL_CERT] = "ssl_cert"; - Attribute[ATTR_SSL_CIPHER] = "ssl_cipher"; - Attribute[ATTR_SSL_SESSION] = "ssl_session"; - Attribute[ATTR_SSL_KEY_SIZE] = "ssl_key_size"; - Attribute[ATTR_SECRET] = "secret"; - Attribute[ATTR_STORED_METHOD] = "stored_method"; - - ResponseHeader["content-type"] = 0xa001; - ResponseHeader["content-language"] = 0xa002; - ResponseHeader["content-length"] = 0xa003; - ResponseHeader["date"] = 0xa004; - ResponseHeader["last-modified"] = 0xa005; - ResponseHeader["location"] = 0xa006; - ResponseHeader["set-cookie"] = 0xa007; - ResponseHeader["set-cookie2"] = 0xa008; - ResponseHeader["servlet-engine"] = 0xa009; - ResponseHeader["status"] = 0xa00a; - ResponseHeader["www-authenticate"] = 0xa00b; -} - - -// --------------------------------------------------------------------------- -AjpBaseSocket::AjpBaseSocket(ISocketHandler& h) : TcpSocket(h) -, m_state(0) -, m_length(4) -, m_ptr(0) -{ -} - - -// --------------------------------------------------------------------------- -void AjpBaseSocket::OnRawData(const char *buf, size_t sz) -{ -DEB(fprintf(stderr, "OnRawData: %d bytes\n", sz);) - size_t ptr = 0; - while (true) - { - size_t left = sz - ptr; -DEB(fprintf(stderr, " left: %d bytes\n", left); -fprintf(stderr, " state: %d\n", m_state);) - switch (m_state) - { - case 0: - { - size_t missing = m_length - m_ptr; - short len = (short)(missing < left ? missing : left); - memcpy(m_message + m_ptr, buf + ptr, len); - m_ptr += len; - ptr += len; - if (m_ptr < m_length) - { - return; // read more - } - int p = 0; - short id = get_integer(m_message, p); - short length = get_integer(m_message, p); - OnHeader(id, length); - m_state = 1; - m_length = length; - m_ptr = 0; // bytes in m_message - } - break; - case 1: - { - size_t missing = m_length - m_ptr; - short len = (short)(missing < left ? missing : left); - memcpy(m_message + m_ptr, buf + ptr, len); - m_ptr += len; - ptr += len; - if (m_ptr < m_length) - { - return; // read more - } - OnPacket(m_message, m_ptr); - m_state = 0; - m_length = 4; - m_ptr = 0; - } - break; - } - } -} - - -// --------------------------------------------------------------------------- -unsigned char AjpBaseSocket::get_byte(const char *buf, int& ptr) -{ - return (unsigned char)buf[ptr++]; -} - - -// --------------------------------------------------------------------------- -bool AjpBaseSocket::get_boolean(const char *buf, int& ptr) -{ - return ( (unsigned char)buf[ptr++] & 1) == 1 ? true : false; -} - - -// --------------------------------------------------------------------------- -short AjpBaseSocket::get_integer(const char *buf, int& ptr) -{ - short n; - memcpy(&n, buf + ptr, 2); - ptr += 2; - return ntohs(n); -} - - -// --------------------------------------------------------------------------- -std::string AjpBaseSocket::get_string(const char *buf, int& ptr) -{ - short len = get_integer(buf, ptr); - if (len != -1) - { - std::string tmp = buf + ptr; - ptr += len; - ptr++; // skip trailing 0x0 - tmp.resize(len); - return tmp; - } - return ""; -} - - -// --------------------------------------------------------------------------- -void AjpBaseSocket::put_byte(char *buf, int& ptr, unsigned char zz) -{ - buf[ptr++] = zz; -} - - -// --------------------------------------------------------------------------- -void AjpBaseSocket::put_boolean(char *buf, int& ptr, bool zz) -{ - buf[ptr++] = zz ? 1 : 0; -} - - -// --------------------------------------------------------------------------- -void AjpBaseSocket::put_integer(char *buf, int& ptr, short zz) -{ - short tmp = htons(zz); - memcpy(buf + ptr, &tmp, 2); - ptr += 2; -} - - -// --------------------------------------------------------------------------- -void AjpBaseSocket::put_string(char *buf, int& ptr, const std::string& zz) -{ - put_integer(buf, ptr, (short)zz.size() ); - memcpy(buf + ptr, zz.c_str(), zz.size()); - ptr += (int)zz.size(); - put_byte(buf, ptr, 0); -} - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - - diff --git a/Sockets/AjpBaseSocket.h b/Sockets/AjpBaseSocket.h deleted file mode 100644 index 222df70..0000000 --- a/Sockets/AjpBaseSocket.h +++ /dev/null @@ -1,83 +0,0 @@ -/** - ** \file AjpBaseSocket.h - ** \date 2007-10-05 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_AjpBaseSocket_H -#define _SOCKETS_AjpBaseSocket_H - -#include "TcpSocket.h" -#include - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -class AjpBaseSocket : public TcpSocket -{ - class Initializer - { - public: - Initializer(); - virtual ~Initializer() {} - - std::map Method; - std::map Header; - std::map Attribute; - - std::map ResponseHeader; - - }; - -public: - AjpBaseSocket(ISocketHandler& h); - - void OnRawData(const char *buf, size_t sz); - - virtual void OnHeader( short id, short len ) = 0; - virtual void OnPacket( const char *buf, size_t sz ) = 0; - -protected: - unsigned char get_byte(const char *buf, int& ptr); - bool get_boolean(const char *buf, int& ptr); - short get_integer(const char *buf, int& ptr); - std::string get_string(const char *buf, int& ptr); - - void put_byte(char *buf, int& ptr, unsigned char zz); - void put_boolean(char *buf, int& ptr, bool zz); - void put_integer(char *buf, int& ptr, short zz); - void put_string(char *buf, int& ptr, const std::string& zz); - - static Initializer Init; - -private: - int m_state; - int m_length; - int m_ptr; - char m_message[8192]; -}; - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - -#endif // _SOCKETS_AjpBaseSocket_H - diff --git a/Sockets/Base64.cpp b/Sockets/Base64.cpp deleted file mode 100644 index 4619756..0000000 --- a/Sockets/Base64.cpp +++ /dev/null @@ -1,272 +0,0 @@ -/** \file Base64.cpp - ** \date 2004-02-13 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#include "Base64.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -const char *Base64::bstr = - "ABCDEFGHIJKLMNOPQ" - "RSTUVWXYZabcdefgh" - "ijklmnopqrstuvwxy" - "z0123456789+/"; - -const char Base64::rstr[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0, - 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0}; - - -Base64::Base64() -{ -} - - -void Base64::encode(FILE *fil, std::string& output, bool add_crlf) -{ - size_t remain; - size_t i = 0; - size_t o = 0; - char input[4]; - - output = ""; - remain = fread(input,1,3,fil); - while (remain > 0) - { - if (add_crlf && o && o % 76 == 0) - output += "\n"; - switch (remain) - { - case 1: - output += bstr[ ((input[i] >> 2) & 0x3f) ]; - output += bstr[ ((input[i] << 4) & 0x30) ]; - output += "=="; - break; - case 2: - output += bstr[ ((input[i] >> 2) & 0x3f) ]; - output += bstr[ ((input[i] << 4) & 0x30) + ((input[i + 1] >> 4) & 0x0f) ]; - output += bstr[ ((input[i + 1] << 2) & 0x3c) ]; - output += "="; - break; - default: - output += bstr[ ((input[i] >> 2) & 0x3f) ]; - output += bstr[ ((input[i] << 4) & 0x30) + ((input[i + 1] >> 4) & 0x0f) ]; - output += bstr[ ((input[i + 1] << 2) & 0x3c) + ((input[i + 2] >> 6) & 0x03) ]; - output += bstr[ (input[i + 2] & 0x3f) ]; - } - o += 4; - // - remain = fread(input,1,3,fil); - } -} - - -void Base64::encode(const std::string& str_in, std::string& str_out, bool add_crlf) -{ - encode(str_in.c_str(), str_in.size(), str_out, add_crlf); -} - - -void Base64::encode(const char* input,size_t l,std::string& output, bool add_crlf) -{ - size_t i = 0; - size_t o = 0; - - output = ""; - while (i < l) - { - size_t remain = l - i; - if (add_crlf && o && o % 76 == 0) - output += "\n"; - switch (remain) - { - case 1: - output += bstr[ ((input[i] >> 2) & 0x3f) ]; - output += bstr[ ((input[i] << 4) & 0x30) ]; - output += "=="; - break; - case 2: - output += bstr[ ((input[i] >> 2) & 0x3f) ]; - output += bstr[ ((input[i] << 4) & 0x30) + ((input[i + 1] >> 4) & 0x0f) ]; - output += bstr[ ((input[i + 1] << 2) & 0x3c) ]; - output += "="; - break; - default: - output += bstr[ ((input[i] >> 2) & 0x3f) ]; - output += bstr[ ((input[i] << 4) & 0x30) + ((input[i + 1] >> 4) & 0x0f) ]; - output += bstr[ ((input[i + 1] << 2) & 0x3c) + ((input[i + 2] >> 6) & 0x03) ]; - output += bstr[ (input[i + 2] & 0x3f) ]; - } - o += 4; - i += 3; - } -} - - -void Base64::encode(const unsigned char* input,size_t l,std::string& output,bool add_crlf) -{ - size_t i = 0; - size_t o = 0; - - output = ""; - while (i < l) - { - size_t remain = l - i; - if (add_crlf && o && o % 76 == 0) - output += "\n"; - switch (remain) - { - case 1: - output += bstr[ ((input[i] >> 2) & 0x3f) ]; - output += bstr[ ((input[i] << 4) & 0x30) ]; - output += "=="; - break; - case 2: - output += bstr[ ((input[i] >> 2) & 0x3f) ]; - output += bstr[ ((input[i] << 4) & 0x30) + ((input[i + 1] >> 4) & 0x0f) ]; - output += bstr[ ((input[i + 1] << 2) & 0x3c) ]; - output += "="; - break; - default: - output += bstr[ ((input[i] >> 2) & 0x3f) ]; - output += bstr[ ((input[i] << 4) & 0x30) + ((input[i + 1] >> 4) & 0x0f) ]; - output += bstr[ ((input[i + 1] << 2) & 0x3c) + ((input[i + 2] >> 6) & 0x03) ]; - output += bstr[ (input[i + 2] & 0x3f) ]; - } - o += 4; - i += 3; - } -} - - -void Base64::decode(const std::string& input,std::string& output) -{ - size_t i = 0; - size_t l = input.size(); - - output = ""; - while (i < l) - { - while (i < l && (input[i] == 13 || input[i] == 10)) - i++; - if (i < l) - { - char b1 = (char)((rstr[(int)input[i]] << 2 & 0xfc) + - (rstr[(int)input[i + 1]] >> 4 & 0x03)); - output += b1; - if (input[i + 2] != '=') - { - char b2 = (char)((rstr[(int)input[i + 1]] << 4 & 0xf0) + - (rstr[(int)input[i + 2]] >> 2 & 0x0f)); - output += b2; - } - if (input[i + 3] != '=') - { - char b3 = (char)((rstr[(int)input[i + 2]] << 6 & 0xc0) + - rstr[(int)input[i + 3]]); - output += b3; - } - i += 4; - } - } -} - - -void Base64::decode(const std::string& input, unsigned char *output, size_t& sz) -{ - size_t i = 0; - size_t l = input.size(); - size_t j = 0; - - while (i < l) - { - while (i < l && (input[i] == 13 || input[i] == 10)) - i++; - if (i < l) - { - unsigned char b1 = (unsigned char)((rstr[(int)input[i]] << 2 & 0xfc) + - (rstr[(int)input[i + 1]] >> 4 & 0x03)); - if (output) - { - output[j] = b1; - } - j++; - if (input[i + 2] != '=') - { - unsigned char b2 = (unsigned char)((rstr[(int)input[i + 1]] << 4 & 0xf0) + - (rstr[(int)input[i + 2]] >> 2 & 0x0f)); - if (output) - { - output[j] = b2; - } - j++; - } - if (input[i + 3] != '=') - { - unsigned char b3 = (unsigned char)((rstr[(int)input[i + 2]] << 6 & 0xc0) + - rstr[(int)input[i + 3]]); - if (output) - { - output[j] = b3; - } - j++; - } - i += 4; - } - } - sz = j; -} - - -size_t Base64::decode_length(const std::string& str64) -{ - if (!str64.size() || str64.size() % 4) - return 0; - size_t l = 3 * (str64.size() / 4 - 1) + 1; - if (str64[str64.size() - 2] != '=') - l++; - if (str64[str64.size() - 1] != '=') - l++; - return l; -} - - -#ifdef SOCKETS_NAMESPACE -} -#endif - - diff --git a/Sockets/Base64.h b/Sockets/Base64.h deleted file mode 100644 index a632bbe..0000000 --- a/Sockets/Base64.h +++ /dev/null @@ -1,77 +0,0 @@ -/** \file Base64.h - ** \date 2004-02-13 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_Base64_H -#define _SOCKETS_Base64_H - -#include "sockets-config.h" -#ifdef _MSC_VER -#pragma warning(disable:4514) -#endif - -#include -#include - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -/** \defgroup util Utilities */ - -/** Base64 encode/decode. - \ingroup util */ -class Base64 -{ -public: - Base64(); - - void encode(FILE *, std::string& , bool add_crlf = true); - void encode(const std::string&, std::string& , bool add_crlf = true); - void encode(const char *, size_t, std::string& , bool add_crlf = true); - void encode(const unsigned char *, size_t, std::string& , bool add_crlf = true); - - void decode(const std::string&, std::string& ); - void decode(const std::string&, unsigned char *, size_t&); - - size_t decode_length(const std::string& ); - -private: - Base64(const Base64& ) {} - Base64& operator=(const Base64& ) { return *this; } -static const char *bstr; -static const char rstr[128]; -}; - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_Base64_H - diff --git a/Sockets/Debug.cpp b/Sockets/Debug.cpp deleted file mode 100644 index ce4bad6..0000000 --- a/Sockets/Debug.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include "Debug.h" -#include - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -std::map Debug::m_level; -const char *Debug::colors[] = { - "\x1B[0;0m", // &n */ - "\x1B[0;0m\x1B[31m", // &r */ - "\x1B[0;0m\x1B[32m", // &g */ - "\x1B[0;0m\x1B[33m", // &y */ - "\x1B[0;0m\x1B[34m", // &b */ - "\x1B[0;0m\x1B[35m", // &m */ - "\x1B[0;0m\x1B[36m", // &c */ - "\x1B[0;0m\x1B[37m", // &w */ - "\x1B[0;0m\x1B[30m", // &l */ - "\x1B[1;31m", // &R */ - "\x1B[1;32m", // &G */ - "\x1B[1;33m", // &Y */ - "\x1B[1;34m", // &B */ - "\x1B[1;35m", // &M */ - "\x1B[1;36m", // &C */ - "\x1B[1;37m", // &W */ - "\x1B[1;30m" }; // &L */ - - - -void Debug::Print(const char *format, ...) -{ - char slask[5000]; // temporary for vsprintf / vsnprintf - va_list ap; - - va_start(ap, format); -#ifdef _WIN32 - vsprintf(slask, format, ap); -#else - vsnprintf(slask, 5000, format, ap); -#endif - va_end(ap); - - fprintf(stderr, "%s", colors[Utility::ThreadID() % 16 + 1]); - for (int i = 0; i < m_level[Utility::ThreadID()]; i++) - fprintf(stderr, " "); - if (slask[strlen(slask) - 1] == '\n') - slask[strlen(slask) - 1] = 0; - fprintf(stderr, "%s%s\n", slask, colors[0]); -} - - -Debug& Debug::operator<<(const std::string& str) -{ - m_line += str; - return *this; -} - - -Debug& Debug::operator<<(long l) -{ - m_line += Utility::l2string(l); - return *this; -} - - -Debug& Debug::operator<<(endl) -{ - Print("%s", m_line.c_str()); - m_line = ""; - return *this; -} - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - diff --git a/Sockets/Debug.h b/Sockets/Debug.h deleted file mode 100644 index 9bc06b9..0000000 --- a/Sockets/Debug.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef _SOCKETS_Debug_H -#define _SOCKETS_Debug_H - -#include "sockets-config.h" -#include -#include "Utility.h" -#include - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -class Debug -{ -static const char *colors[]; -public: - class endl { - public: - endl() {} - virtual ~endl() {} - }; - -public: - Debug() {} - Debug(const std::string& x) : m_id(0), m_text(x) { - fprintf(stderr, "%s", colors[Utility::ThreadID() % 16 + 1]); - for (int i = 0; i < m_level[Utility::ThreadID()]; i++) - fprintf(stderr, " "); - fprintf(stderr, "%s%s\n", x.c_str(), colors[0]); - m_level[Utility::ThreadID()]++; - } - Debug(int id, const std::string& x) : m_id(id), m_text(x) { - fprintf(stderr, "%s", colors[Utility::ThreadID() % 16 + 1]); - for (int i = 0; i < m_level[Utility::ThreadID()]; i++) - fprintf(stderr, " "); - fprintf(stderr, "%d> %s%s\n", m_id, x.c_str(), colors[0]); - m_level[Utility::ThreadID()]++; - } - ~Debug() { - if (!m_text.empty()) - { - if (m_level[Utility::ThreadID()]) - m_level[Utility::ThreadID()]--; - fprintf(stderr, "%s", colors[Utility::ThreadID() % 16 + 1]); - for (int i = 0; i < m_level[Utility::ThreadID()]; i++) - fprintf(stderr, " "); - if (m_id) - fprintf(stderr, "%d> /%s%s\n", m_id, m_text.c_str(), colors[0]); - else - fprintf(stderr, "/%s%s\n", m_text.c_str(), colors[0]); - fflush(stderr); - } - } -static void Print(const char *format, ...); - - Debug& operator<<(const std::string& ); - Debug& operator<<(long); - Debug& operator<<(endl); - -private: - int m_id; - std::string m_text; -static std::map m_level; - std::string m_line; -}; - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - -#endif // _SOCKETS_Debug_H - diff --git a/Sockets/DevCpp/Sockets.dev b/Sockets/DevCpp/Sockets.dev deleted file mode 100644 index fe38522..0000000 --- a/Sockets/DevCpp/Sockets.dev +++ /dev/null @@ -1,1129 +0,0 @@ -[Project] -FileName=Sockets.dev -Name=Sockets -UnitCount=96 -Type=2 -Ver=1 -ObjFiles= -Includes=C:\OpenSSL\include -Libs=C:\OpenSSL\lib\MinGW -PrivateResource= -ResourceIncludes= -MakeIncludes= -Compiler= -CppCompiler=-D_VERSION='"2.1.9"'_@@_-D__CYGWIN___@@__@@_ -Linker=../../../../OpenSSL/lib/MinGW/ssleay32.a_@@_../../../../OpenSSL/lib/MinGW/libeay32.a_@@_ -IsCpp=1 -Icon= -ExeOutput=..\..\lib -ObjectOutput= -OverrideOutput=0 -OverrideOutputName=Sockets.a -HostApplication= -Folders="Asynchronous DNS","Basic Sockets","File handling","HTTP Sockets",Internal,"Log help classes",SMTP,Threading,"Timer Events",Utilities,"Webserver framework" -CommandLine= -UseCustomMakefile=0 -CustomMakefile= -IncludeVersionInfo=0 -SupportXPThemes=0 -CompilerSet=0 -CompilerSettings=0000000000000000000000 - -[VersionInfo] -Major=0 -Minor=1 -Release=1 -Build=1 -LanguageID=1033 -CharsetID=1050 -CompanyName= -FileVersion= -FileDescription=Developed using the Dev-C++ IDE -InternalName= -LegalCopyright= -LegalTrademarks= -OriginalFilename= -ProductName= -ProductVersion= -AutoIncBuildNr=0 - -[Unit1] -FileName=..\socket_include.cpp -CompileCpp=1 -Folder= -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit2] -FileName=..\socket_include.h -CompileCpp=1 -Folder= -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit3] -FileName=..\sockets-config.h -CompileCpp=1 -Folder= -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit4] -FileName=..\ResolvServer.cpp -CompileCpp=1 -Folder=Asynchronous DNS -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit5] -FileName=..\ResolvServer.h -CompileCpp=1 -Folder=Asynchronous DNS -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit6] -FileName=..\ResolvSocket.cpp -CompileCpp=1 -Folder=Asynchronous DNS -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit7] -FileName=..\ResolvSocket.h -CompileCpp=1 -Folder=Asynchronous DNS -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit8] -FileName=..\ListenSocket.h -CompileCpp=1 -Folder=Basic Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit9] -FileName=..\Socket.cpp -CompileCpp=1 -Folder=Basic Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit10] -FileName=..\Socket.h -CompileCpp=1 -Folder=Basic Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit11] -FileName=..\SocketHandler.cpp -CompileCpp=1 -Folder=Basic Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit12] -FileName=..\SocketHandler.h -CompileCpp=1 -Folder=Basic Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit13] -FileName=..\TcpSocket.cpp -CompileCpp=1 -Folder=Basic Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit14] -FileName=..\TcpSocket.h -CompileCpp=1 -Folder=Basic Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit15] -FileName=..\UdpSocket.cpp -CompileCpp=1 -Folder=Basic Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit16] -FileName=..\UdpSocket.h -CompileCpp=1 -Folder=Basic Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit17] -FileName=..\SctpSocket.h -CompileCpp=1 -Folder=Basic Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit18] -FileName=..\SctpSocket.cpp -CompileCpp=1 -Folder=Basic Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit19] -FileName=..\ISocketHandler.h -CompileCpp=1 -Folder=Basic Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit20] -FileName=..\StreamSocket.h -CompileCpp=1 -Folder=Basic Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit21] -FileName=..\Ipv4Address.h -CompileCpp=1 -Folder=Basic Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit22] -FileName=..\Ipv6Address.cpp -CompileCpp=1 -Folder=Basic Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit23] -FileName=..\Ipv4Address.cpp -CompileCpp=1 -Folder=Basic Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit25] -FileName=..\Ipv6Address.h -CompileCpp=1 -Folder=Basic Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit26] -FileName=..\SocketAddress.h -CompileCpp=1 -Folder=Basic Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit27] -FileName=..\MemFile.h -CompileCpp=1 -Folder=File handling -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit28] -FileName=..\File.h -CompileCpp=1 -Folder=File handling -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit29] -FileName=..\IFile.h -CompileCpp=1 -Folder=File handling -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit30] -FileName=..\MemFile.cpp -CompileCpp=1 -Folder=File handling -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit31] -FileName=..\File.cpp -CompileCpp=1 -Folder=File handling -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit32] -FileName=..\HttpDebugSocket.cpp -CompileCpp=1 -Folder=HTTP Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit33] -FileName=..\HttpDebugSocket.h -CompileCpp=1 -Folder=HTTP Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit34] -FileName=..\HttpGetSocket.cpp -CompileCpp=1 -Folder=HTTP Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit35] -FileName=..\HttpGetSocket.h -CompileCpp=1 -Folder=HTTP Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit36] -FileName=..\HttpPostSocket.cpp -CompileCpp=1 -Folder=HTTP Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit37] -FileName=..\HttpPostSocket.h -CompileCpp=1 -Folder=HTTP Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit38] -FileName=..\HttpPutSocket.cpp -CompileCpp=1 -Folder=HTTP Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit39] -FileName=..\HttpPutSocket.h -CompileCpp=1 -Folder=HTTP Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit40] -FileName=..\HTTPSocket.cpp -CompileCpp=1 -Folder=HTTP Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit41] -FileName=..\HTTPSocket.h -CompileCpp=1 -Folder=HTTP Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit42] -FileName=..\HttpClientSocket.h -CompileCpp=1 -Folder=HTTP Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit43] -FileName=..\HttpClientSocket.cpp -CompileCpp=1 -Folder=HTTP Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit45] -FileName=..\SSLInitializer.h -CompileCpp=1 -Folder=Internal -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit46] -FileName=..\StdLog.h -CompileCpp=1 -Folder=Log help classes -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit47] -FileName=..\StdoutLog.cpp -CompileCpp=1 -Folder=Log help classes -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit48] -FileName=..\StdoutLog.h -CompileCpp=1 -Folder=Log help classes -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit49] -FileName=..\SmtpdSocket.cpp -CompileCpp=1 -Folder=SMTP -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit50] -FileName=..\SmtpdSocket.h -CompileCpp=1 -Folder=SMTP -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit51] -FileName=..\sockets-config.h -CompileCpp=1 -Folder=Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit54] -FileName=..\Thread.cpp -CompileCpp=1 -Folder=Threading -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit55] -FileName=..\Thread.h -CompileCpp=1 -Folder=Threading -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit56] -FileName=..\Lock.h -CompileCpp=1 -Folder=Threading -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit57] -FileName=..\Lock.cpp -CompileCpp=1 -Folder=Threading -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit58] -FileName=..\Mutex.cpp -CompileCpp=1 -Folder=Threading -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit59] -FileName=..\Mutex.h -CompileCpp=1 -Folder=Threading -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit60] -FileName=..\EventTime.h -CompileCpp=1 -Folder=Timer Events -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit61] -FileName=..\Event.h -CompileCpp=1 -Folder=Timer Events -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit62] -FileName=..\EventHandler.cpp -CompileCpp=1 -Folder=Timer Events -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit63] -FileName=..\IEventOwner.cpp -CompileCpp=1 -Folder=Timer Events -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit64] -FileName=..\IEventOwner.h -CompileCpp=1 -Folder=Timer Events -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit65] -FileName=..\EventTime.cpp -CompileCpp=1 -Folder=Timer Events -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit66] -FileName=..\EventHandler.h -CompileCpp=1 -Folder=Timer Events -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit67] -FileName=..\IEventHandler.h -CompileCpp=1 -Folder=Timer Events -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit68] -FileName=..\Event.cpp -CompileCpp=1 -Folder=Timer Events -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit69] -FileName=..\Base64.cpp -CompileCpp=1 -Folder=Utilities -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit70] -FileName=..\Base64.h -CompileCpp=1 -Folder=Utilities -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit71] -FileName=..\Parse.cpp -CompileCpp=1 -Folder=Utilities -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit72] -FileName=..\Parse.h -CompileCpp=1 -Folder=Utilities -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit73] -FileName=..\Utility.cpp -CompileCpp=1 -Folder=Utilities -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit74] -FileName=..\Utility.h -CompileCpp=1 -Folder=Utilities -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit75] -FileName=..\RandomNumber.h -CompileCpp=1 -Folder=Utilities -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit76] -FileName=..\RandomNumber.cpp -CompileCpp=1 -Folder=Utilities -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit77] -FileName=..\HttpdSocket.h -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit78] -FileName=..\HttpdCookies.h -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit79] -FileName=..\HttpdForm.cpp -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit80] -FileName=..\HttpdForm.h -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit81] -FileName=..\HttpdSocket.cpp -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit82] -FileName=..\HttpdCookies.cpp -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit83] -FileName=..\Ajp13Socket.cpp -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit84] -FileName=..\Ajp13Socket.h -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit85] -FileName=..\AjpBaseSocket.cpp -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit86] -FileName=..\AjpBaseSocket.h -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit87] -FileName=..\HttpBaseSocket.cpp -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit88] -FileName=..\HttpBaseSocket.h -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit89] -FileName=..\HttpTransaction.cpp -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit90] -FileName=..\HttpTransaction.h -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit91] -FileName=..\HttpRequest.cpp -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit92] -FileName=..\HttpRequest.h -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit93] -FileName=..\HttpResponse.cpp -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit94] -FileName=..\HttpResponse.h -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit95] -FileName=..\ajp13.h -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit96] -FileName=..\IHttpServer.h -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit97] -FileName=..\HttpTransaction.cpp -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit98] -FileName=..\HttpTransaction.h -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit99] -FileName=..\HttpRequest.cpp -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit100] -FileName=..\HttpRequest.h -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit101] -FileName=..\HttpResponse.cpp -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit102] -FileName=..\HttpResponse.h -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit103] -FileName=..\ajp13.h -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit104] -FileName=..\IHttpServer.h -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit105] -FileName=..\HttpResponse.cpp -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit106] -FileName=..\HttpResponse.h -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit107] -FileName=..\ajp13.h -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit108] -FileName=..\IHttpServer.h -CompileCpp=1 -Folder=Webserver framework -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit24] -FileName=..\StreamSocket.cpp -CompileCpp=1 -Folder=Basic Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit44] -FileName=..\SSLInitializer.cpp -CompileCpp=1 -Folder=Internal -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit52] -FileName=..\Exception.h -CompileCpp=1 -Folder=Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit53] -FileName=..\Exception.cpp -CompileCpp=1 -Folder=Sockets -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - diff --git a/Sockets/DevCpp/Test.dev b/Sockets/DevCpp/Test.dev deleted file mode 100644 index 913d938..0000000 --- a/Sockets/DevCpp/Test.dev +++ /dev/null @@ -1,59 +0,0 @@ -[Project] -FileName=Test.dev -Name=Test -UnitCount=1 -Type=1 -Ver=1 -ObjFiles= -Includes=..;C:\OpenSSL\include -Libs=C:\OpenSSL\lib\MinGW -PrivateResource= -ResourceIncludes= -MakeIncludes= -Compiler= -CppCompiler=-DHAVE_OPENSSL_@@_-D__CYGWIN___@@_ -Linker=../../lib/Sockets.a_@@_../../../../OpenSSL/lib/MinGW/ssleay32.a_@@_../../../../OpenSSL/lib/MinGW/libeay32.a_@@_../../../../Dev-Cpp/lib/libwsock32.a_@@_../../../../Dev-Cpp/lib/libws2_32.a_@@_ -IsCpp=1 -Icon= -ExeOutput=..\..\bin -ObjectOutput=bin -OverrideOutput=0 -OverrideOutputName=Test.exe -HostApplication= -Folders= -CommandLine= -UseCustomMakefile=0 -CustomMakefile= -IncludeVersionInfo=0 -SupportXPThemes=0 -CompilerSet=0 -CompilerSettings=0000000000000000000000 - -[VersionInfo] -Major=0 -Minor=1 -Release=1 -Build=1 -LanguageID=1033 -CharsetID=1252 -CompanyName= -FileVersion= -FileDescription=Developed using the Dev-C++ IDE -InternalName= -LegalCopyright= -LegalTrademarks= -OriginalFilename= -ProductName= -ProductVersion= -AutoIncBuildNr=0 - -[Unit1] -FileName=..\tests\sockets_test.cpp -CompileCpp=1 -Folder=Test -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - diff --git a/Sockets/Event.cpp b/Sockets/Event.cpp deleted file mode 100644 index d8d1bba..0000000 --- a/Sockets/Event.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/** \file Event.cpp - ** \date 2005-12-07 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2005,2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#include "Event.h" -#ifdef _WIN32 -#else -#include -#endif - -//#include "IEventOwner.h" - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -// statics -long Event::m_unique_id = 0; - - -Event::Event(IEventOwner *from,long sec,long usec) : m_from(from), m_time(sec, usec), m_id(++m_unique_id) -{ -} - - -Event::~Event() -{ -} - - -bool Event::operator<(Event& e) -{ - return m_time < e.m_time; -} - - -long Event::GetID() -{ - return m_id; -} - - -const EventTime& Event::GetTime() const -{ - return m_time; -} - - -IEventOwner *Event::GetFrom() -{ - return m_from; -} - - -#ifdef SOCKETS_NAMESPACE -} -#endif - diff --git a/Sockets/Event.h b/Sockets/Event.h deleted file mode 100644 index cf6521b..0000000 --- a/Sockets/Event.h +++ /dev/null @@ -1,76 +0,0 @@ -/** \file Event.h - ** \date 2005-12-07 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2005,2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_Event_H -#define _SOCKETS_Event_H - -#include "sockets-config.h" -#ifdef _WIN32 -#else -#include -#endif -#include "EventTime.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -class IEventOwner; - -/** Store information about a timer event. - \ingroup timer */ -class Event -{ -public: - Event(IEventOwner *,long sec,long usec); - ~Event(); - - bool operator<(Event&); - long GetID(); - const EventTime& GetTime() const; - IEventOwner *GetFrom(); - -private: - Event(const Event& ) {} // copy constructor - Event& operator=(const Event& ) { return *this; } // assignment operator - IEventOwner *m_from; - EventTime m_time; - static long m_unique_id; - long m_id; -}; - - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_Event_H - diff --git a/Sockets/EventHandler.cpp b/Sockets/EventHandler.cpp deleted file mode 100644 index 4d90342..0000000 --- a/Sockets/EventHandler.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/** \file EventHandler.cpp - ** \date 2005-12-07 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2005,2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif -#include "EventHandler.h" -#include "IEventOwner.h" -#include "Event.h" -#include "Socket.h" -#include "TcpSocket.h" -#include "ListenSocket.h" - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -EventHandler::EventHandler(StdLog *p) : SocketHandler(p), m_quit(false), m_socket(NULL) -{ -} - - -EventHandler::EventHandler(Mutex& m,StdLog *p) : SocketHandler(m, p), m_quit(false), m_socket(NULL) -{ -} - - -EventHandler::~EventHandler() -{ - while (m_events.size()) - { - std::list::iterator it = m_events.begin(); - Event *e = *it; - e -> GetFrom() -> SetHandlerInvalid(); - delete e; - m_events.erase(it); - } -} - - -bool EventHandler::GetTimeUntilNextEvent(struct timeval *tv) -{ - if (!m_events.size()) - return false; - std::list::iterator it = m_events.begin(); - if (it != m_events.end()) - { - EventTime now; - mytime_t diff = (*it) -> GetTime() - now; - if (diff < 1) - { - diff = 1; - } - tv -> tv_sec = static_cast(diff / 1000000); - tv -> tv_usec = static_cast(diff % 1000000); - return true; - } - return false; -} - - -void EventHandler::CheckEvents() -{ - EventTime now; - std::list::iterator it = m_events.begin(); - while (it != m_events.end() && (*it) -> GetTime() < now) - { - Event *e = *it; - Socket *s = dynamic_cast(e -> GetFrom()); - /* - s == NULL This is another object implementing 'IEventOwner' and not a socket. - s != NULL This is a Socket implementing IEventOwner, and we can check that the - object instance still is valid using SocketHandler::Valid. - */ - if (!s || (s && Valid(s))) - { - e -> GetFrom() -> OnEvent(e -> GetID()); - } - for (it = m_events.begin(); it != m_events.end(); ++it) - if (*it == e) - break; - delete e; - if (it != m_events.end()) - m_events.erase(it); - it = m_events.begin(); - } -} - - -long EventHandler::AddEvent(IEventOwner *from,long sec,long usec) -{ - Event *e = new Event(from, sec, usec); - std::list::iterator it = m_events.begin(); - while (it != m_events.end() && *(*it) < *e) - { - it++; - } - m_events.insert(it, e); - if (m_socket) - { - m_socket -> Send("\n"); - } - return e -> GetID(); -} - - -void EventHandler::ClearEvents(IEventOwner *from) -{ - bool repeat; - do - { - repeat = false; - for (std::list::iterator it = m_events.begin(); it != m_events.end(); it++) - { - Event *e = *it; - if (e -> GetFrom() == from) - { - delete e; - m_events.erase(it); - repeat = true; - break; - } - } - } while (repeat); -} - - -void EventHandler::EventLoop() -{ - while (!m_quit) - { - struct timeval tv; - if (GetTimeUntilNextEvent(&tv)) - { - Select(&tv); - CheckEvents(); - } - else - { - Select(); - } - } -} - - -void EventHandler::SetQuit(bool x) -{ - m_quit = x; -} - - -void EventHandler::RemoveEvent(IEventOwner *from, long eid) -{ - for (std::list::iterator it = m_events.begin(); it != m_events.end(); it++) - { - Event *e = *it; - if (from == e -> GetFrom() && eid == e -> GetID()) - { - delete e; - m_events.erase(it); - break; - } - } -} - - -void EventHandler::Add(Socket *p) -{ - if (!m_socket) - { - ListenSocket *l = new ListenSocket(*this); - l -> SetDeleteByHandler(); - l -> Bind("127.0.0.1", 0); - m_port = l -> GetPort(); - SocketHandler::Add(l); - m_socket = new TcpSocket( *this ); - m_socket -> SetDeleteByHandler(); - m_socket -> SetConnectTimeout(5); - m_socket -> SetConnectionRetry(-1); -#ifdef ENABLE_RECONNECT - m_socket -> SetReconnect(true); -#endif - m_socket -> Open("127.0.0.1", m_port); - SocketHandler::Add(m_socket); - } - SocketHandler::Add( p ); -} - - -#ifdef SOCKETS_NAMESPACE -} -#endif - - - diff --git a/Sockets/EventHandler.h b/Sockets/EventHandler.h deleted file mode 100644 index 9ca7cde..0000000 --- a/Sockets/EventHandler.h +++ /dev/null @@ -1,85 +0,0 @@ -/** \file EventHandler.h - ** \date 2005-12-07 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2005,2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_EventHandler_H -#define _SOCKETS_EventHandler_H - -#include "sockets-config.h" -#include "SocketHandler.h" -#include "IEventHandler.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -class StdLog; -class IEventOwner; -class Event; -class TcpSocket; - -/** SocketHandler implementing the IEventHandler interface. - \ingroup timer */ -class EventHandler : public SocketHandler,public IEventHandler -{ -public: - EventHandler(StdLog * = NULL); - EventHandler(Mutex&,StdLog * = NULL); - ~EventHandler(); - - bool GetTimeUntilNextEvent(struct timeval *tv); - void CheckEvents(); - long AddEvent(IEventOwner *from,long sec,long usec); - void ClearEvents(IEventOwner *from); - void RemoveEvent(IEventOwner *from,long eid); - - /** SocketHandler while() loop implemented with event functionality. */ - void EventLoop(); - /** Stop event loop. */ - void SetQuit(bool = true); - - void Add(Socket *); - -private: - EventHandler(const EventHandler& ) {} // copy constructor - EventHandler& operator=(const EventHandler& ) { return *this; } // assignment operator - std::list m_events; - bool m_quit; - TcpSocket *m_socket; - port_t m_port; -}; - - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_EventHandler_H - diff --git a/Sockets/EventTime.cpp b/Sockets/EventTime.cpp deleted file mode 100644 index a58cbb3..0000000 --- a/Sockets/EventTime.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/** \file EventTime.cpp - ** \date 2005-12-07 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2005,2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef MACOSX -#include -#include -#include -#endif -#include "EventTime.h" -#ifdef _WIN32 -#include -#else -#include -#include -#endif - - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -EventTime::EventTime() : m_time(Tick()) -{ -} - - -EventTime::EventTime(mytime_t sec,long usec) : m_time(Tick()) -{ - m_time += sec * 1000000 + usec; -} - - -EventTime::~EventTime() -{ -} - - -mytime_t EventTime::Tick() -{ - mytime_t t; -#ifdef _WIN32 - FILETIME ft; - GetSystemTimeAsFileTime(&ft); - t = ft.dwHighDateTime; - t = t << 32; - t += ft.dwLowDateTime; - t /= 10; // us -#else - struct timeval tv; - struct timezone tz; - gettimeofday(&tv, &tz); - t = tv.tv_sec; - t *= 1000000; - t += tv.tv_usec; -#endif - return t; -} - - -EventTime EventTime::operator - (const EventTime& x) const -{ - EventTime t; - t.m_time = m_time - x.m_time; - return t; -} - - -bool EventTime::operator < (const EventTime& x) const -{ - return m_time < x.m_time; -} - - -#ifdef SOCKETS_NAMESPACE -} -#endif - diff --git a/Sockets/EventTime.h b/Sockets/EventTime.h deleted file mode 100644 index 5c77695..0000000 --- a/Sockets/EventTime.h +++ /dev/null @@ -1,77 +0,0 @@ -/** \file EventTime.h - ** \date 2005-12-07 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2005,2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_EventTime_H -#define _SOCKETS_EventTime_H - -#include "sockets-config.h" -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -#if defined( _WIN32) && !defined(__CYGWIN__) -typedef __int64 mytime_t; -#else -#include // int64_t -typedef int64_t mytime_t; -#endif - - -/** \defgroup timer EventTimer event handling */ - -/** EventTime primitive, returns current time as a 64-bit number. - \ingroup timer */ -class EventTime -{ -public: - EventTime(); - EventTime(mytime_t sec,long usec); - ~EventTime(); - - static mytime_t Tick(); - - operator mytime_t () { return m_time; } - EventTime operator - (const EventTime& x) const; - bool operator < (const EventTime& x) const; - -private: - EventTime(const EventTime& ) {} // copy constructor - EventTime& operator=(const EventTime& ) { return *this; } // assignment operator - mytime_t m_time; -}; - - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_EventTime_H - diff --git a/Sockets/Exception.cpp b/Sockets/Exception.cpp deleted file mode 100644 index a005669..0000000 --- a/Sockets/Exception.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/** - ** \file Exception.cpp - ** \date 2007-09-28 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif -#include "Exception.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - - -Exception::Exception(const std::string& description) : m_description(description) -{ -} - - -const std::string Exception::ToString() const -{ - return m_description; -} - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - diff --git a/Sockets/Exception.h b/Sockets/Exception.h deleted file mode 100644 index 81ba737..0000000 --- a/Sockets/Exception.h +++ /dev/null @@ -1,58 +0,0 @@ -/** - ** \file Exception.h - ** \date 2007-09-28 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _Sockets_Exception_H -#define _Sockets_Exception_H - -#include - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - - -class Exception -{ -public: - Exception(const std::string& description); - virtual ~Exception() {} - - virtual const std::string ToString() const; - - Exception(const Exception& ) {} // copy constructor - - Exception& operator=(const Exception& ) { return *this; } // assignment operator - -private: - std::string m_description; - -}; - - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - -#endif // _Sockets_Exception_H - diff --git a/Sockets/File.cpp b/Sockets/File.cpp deleted file mode 100644 index 4c1e5bf..0000000 --- a/Sockets/File.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/** \file File.cpp - ** \date 2005-04-25 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#include -#include -#include -#ifndef _WIN32 -#include -#endif - -#include "File.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -File::File() -:m_fil(NULL) -,m_rptr(0) -,m_wptr(0) -{ -} - - -File::~File() -{ - fclose(); -} - - -bool File::fopen(const std::string& path, const std::string& mode) -{ - m_path = path; - m_mode = mode; - m_fil = ::fopen(path.c_str(), mode.c_str()); - return m_fil ? true : false; -} - - -void File::fclose() -{ - if (m_fil) - { - ::fclose(m_fil); - m_fil = NULL; - } -} - - - -size_t File::fread(char *ptr, size_t size, size_t nmemb) const -{ - size_t r = 0; - if (m_fil) - { - fseek(m_fil, m_rptr, SEEK_SET); - r = ::fread(ptr, size, nmemb, m_fil); - m_rptr = ftell(m_fil); - } - return r; -} - - -size_t File::fwrite(const char *ptr, size_t size, size_t nmemb) -{ - size_t r = 0; - if (m_fil) - { - fseek(m_fil, m_wptr, SEEK_SET); - r = ::fwrite(ptr, size, nmemb, m_fil); - m_wptr = ftell(m_fil); - } - return r; -} - - - -char *File::fgets(char *s, int size) const -{ - char *r = NULL; - if (m_fil) - { - fseek(m_fil, m_rptr, SEEK_SET); - r = ::fgets(s, size, m_fil); - m_rptr = ftell(m_fil); - } - return r; -} - - -void File::fprintf(const char *format, ...) -{ - if (!m_fil) - return; - va_list ap; - va_start(ap, format); - fseek(m_fil, m_rptr, SEEK_SET); - vfprintf(m_fil, format, ap); - m_rptr = ftell(m_fil); - va_end(ap); -} - - -off_t File::size() const -{ - struct stat st; - if (stat(m_path.c_str(), &st) == -1) - { - return 0; - } - return st.st_size; -} - - -bool File::eof() const -{ - if (m_fil) - { - if (feof(m_fil)) - return true; - } - return false; -} - - -void File::reset_read() const -{ - m_rptr = 0; -} - - -void File::reset_write() -{ - m_wptr = 0; -} - - -#ifdef SOCKETS_NAMESPACE -} -#endif - - diff --git a/Sockets/File.h b/Sockets/File.h deleted file mode 100644 index 58a1b71..0000000 --- a/Sockets/File.h +++ /dev/null @@ -1,84 +0,0 @@ -/** \file File.h - ** \date 2005-04-25 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_File_H -#define _SOCKETS_File_H - -#include "sockets-config.h" -#include "IFile.h" -#include - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -/** IFile implementation of a disk file. - \ingroup file */ -class File : public IFile -{ -public: - File(); - ~File(); - - bool fopen(const std::string&, const std::string&); - void fclose(); - - size_t fread(char *, size_t, size_t) const; - size_t fwrite(const char *, size_t, size_t); - - char *fgets(char *, int) const; - void fprintf(const char *format, ...); - - off_t size() const; - bool eof() const; - - void reset_read() const; - void reset_write(); - -private: - File(const File& ) {} // copy constructor - File& operator=(const File& ) { return *this; } // assignment operator - - std::string m_path; - std::string m_mode; - FILE *m_fil; - mutable long m_rptr; - long m_wptr; -}; - - - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_File_H - diff --git a/Sockets/HTTPSocket.cpp b/Sockets/HTTPSocket.cpp deleted file mode 100644 index ca49822..0000000 --- a/Sockets/HTTPSocket.cpp +++ /dev/null @@ -1,413 +0,0 @@ -/** \file HTTPSocket.cpp - ** \date 2004-04-06 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif -#include "HTTPSocket.h" -#include "Parse.h" -#include "ISocketHandler.h" -#include "Utility.h" -#include - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -HTTPSocket::HTTPSocket(ISocketHandler& h) -:TcpSocket(h) -,m_first(true) -,m_header(true) -,m_http_version("HTTP/1.0") -,m_request(false) -,m_response(false) -,m_body_size_left(0) -,m_b_http_1_1(false) -,m_b_keepalive(false) -{ - SetLineProtocol(); - DisableInputBuffer(); -} - - -HTTPSocket::~HTTPSocket() -{ -} - - -void HTTPSocket::OnRawData(const char *buf,size_t len) -{ - if (!m_header) - { - if (!m_b_http_1_1 || !m_b_keepalive) - { - OnData(buf, len); - } - else - { - size_t sz = m_body_size_left < len ? m_body_size_left : len; - OnData(buf, sz); - m_body_size_left -= sz; - if (!m_body_size_left) - { - SetLineProtocol( true ); - m_first = true; - m_header = true; - m_body_size_left = 0; - if (len - sz > 0) - { - char tmp[TCP_BUFSIZE_READ]; - memcpy(tmp, buf + sz, len - sz); - tmp[len - sz] = 0; - OnRead( tmp, len - sz ); - } - } - } - } -} - - -void HTTPSocket::OnLine(const std::string& line) -{ - if (m_first) - { - Parse pa(line); - std::string str = pa.getword(); - if (str.size() > 4 && Utility::ToLower(str.substr(0,5)) == "http/") // response - { - m_http_version = str; - m_status = pa.getword(); - m_status_text = pa.getrest(); - m_response = true; - } - else // request - { - m_method = str; - m_url = pa.getword(); - size_t spl = m_url.find("?"); - if (spl != std::string::npos) - { - m_uri = m_url.substr(0,spl); - m_query_string = m_url.substr(spl + 1); - } - else - { - m_uri = m_url; - m_query_string = ""; - } - m_http_version = pa.getword(); - m_b_http_1_1 = m_http_version.size() > 4 && m_http_version.substr(4) == "/1.1"; - m_b_keepalive = m_b_http_1_1; - m_request = true; - } - m_first = false; - OnFirst(); - return; - } - if (!line.size()) - { - if (m_body_size_left || !m_b_http_1_1 || !m_b_keepalive) - { - SetLineProtocol(false); - m_header = false; - } - OnHeaderComplete(); - return; - } - Parse pa(line,":"); - std::string key = pa.getword(); - std::string value = pa.getrest(); - OnHeader(key,value); - if (Utility::ToLower(key) == "content-length") - { - m_body_size_left = atol(value.c_str()); - } - if (m_b_http_1_1 && Utility::ToLower(key) == "connection") - { - m_b_keepalive = Utility::ToLower(value) != "close"; - } - /* If remote end tells us to keep connection alive, and we're operating - in http/1.1 mode (not http/1.0 mode), then we mark the socket to be - retained. */ -#ifdef ENABLE_POOL - if (m_b_http_1_1 && m_b_keepalive) - { - SetRetain(); - } -#endif -} - - -void HTTPSocket::SendResponse() -{ - std::string msg; - msg = m_http_version + " " + m_status + " " + m_status_text + "\r\n"; - for (string_m::iterator it = m_response_header.begin(); it != m_response_header.end(); it++) - { - std::string key = (*it).first; - std::string val = (*it).second; - msg += key + ": " + val + "\r\n"; - } - for (std::list >::iterator it2 = m_response_header_append.begin(); it2 != m_response_header_append.end(); ++it2) - { - msg += it2 -> first + ": " + it2 -> second + "\r\n"; - } - msg += "\r\n"; - Send( msg ); -} - - -void HTTPSocket::AddResponseHeader(const std::string& header, const char *format, ...) -{ - char slask[5000]; // temporary for vsprintf / vsnprintf - va_list ap; - - va_start(ap, format); -#ifdef _WIN32 - vsprintf(slask, format, ap); -#else - vsnprintf(slask, 5000, format, ap); -#endif - va_end(ap); - - m_response_header[header] = slask; -} - - -void HTTPSocket::SendRequest() -{ - std::string msg; - msg = m_method + " " + m_url + " " + m_http_version + "\r\n"; - for (string_m::iterator it = m_response_header.begin(); it != m_response_header.end(); it++) - { - std::string key = (*it).first; - std::string val = (*it).second; - msg += key + ": " + val + "\r\n"; - } - msg += "\r\n"; - Send( msg ); -} - - -std::string HTTPSocket::MyUseragent() -{ - std::string version = "C++Sockets/"; -#ifdef _VERSION - version += _VERSION; -#endif - return version; -} - - -void HTTPSocket::Reset() -{ - m_first = true; - m_header = true; - m_request = false; - m_response = false; - SetLineProtocol(true); - while (m_response_header.size()) - { - string_m::iterator it = m_response_header.begin(); - m_response_header.erase(it); - } - while (m_response_header_append.size()) - { - std::list >::iterator it = m_response_header_append.begin(); - m_response_header_append.erase(it); - } - -} - - -const std::string& HTTPSocket::GetMethod() -{ - return m_method; -} - - -void HTTPSocket::SetMethod(const std::string& x) -{ - m_method = x; -} - - -const std::string& HTTPSocket::GetUrl() -{ - return m_url; -} - - -void HTTPSocket::SetUrl(const std::string& x) -{ - m_url = x; -} - - -const std::string& HTTPSocket::GetUri() -{ - return m_uri; -} - - -const std::string& HTTPSocket::GetQueryString() -{ - return m_query_string; -} - - -const std::string& HTTPSocket::GetHttpVersion() -{ - return m_http_version; -} - - -const std::string& HTTPSocket::GetStatus() -{ - return m_status; -} - - -const std::string& HTTPSocket::GetStatusText() -{ - return m_status_text; -} - - -bool HTTPSocket::IsRequest() -{ - return m_request; -} - - -bool HTTPSocket::IsResponse() -{ - return m_response; -} - - -void HTTPSocket::SetHttpVersion(const std::string& x) -{ - m_http_version = x; -} - - -void HTTPSocket::SetStatus(const std::string& x) -{ - m_status = x; -} - - -void HTTPSocket::SetStatusText(const std::string& x) -{ - m_status_text = x; -} - - -void HTTPSocket::AddResponseHeader(const std::string& x,const std::string& y) -{ - m_response_header[Utility::ToLower(x)] = y; -} - - -void HTTPSocket::AppendResponseHeader(const std::string& x,const std::string& y) -{ - m_response_header_append.push_back(std::pair(Utility::ToLower(x),y)); -} - - -void HTTPSocket::SetUri(const std::string& x) -{ - m_uri = x; -} - - -void HTTPSocket::url_this(const std::string& url_in,std::string& protocol,std::string& host,port_t& port,std::string& url,std::string& file) -{ - Parse pa(url_in,"/"); - protocol = pa.getword(); // http - if (!strcasecmp(protocol.c_str(), "https:")) - { -#ifdef HAVE_OPENSSL - EnableSSL(); -#else - Handler().LogError(this, "url_this", -1, "SSL not available", LOG_LEVEL_WARNING); -#endif - port = 443; - } - else - { - port = 80; - } - host = pa.getword(); - if (strstr(host.c_str(),":")) - { - Parse pa(host,":"); - pa.getword(host); - port = static_cast(pa.getvalue()); - } - url = "/" + pa.getrest(); - { - Parse pa(url,"/"); - std::string tmp = pa.getword(); - while (tmp.size()) - { - file = tmp; - tmp = pa.getword(); - } - } -} // url_this - - -bool HTTPSocket::ResponseHeaderIsSet(const std::string& name) -{ - string_m::iterator it = m_response_header.find( Utility::ToLower(name) ); - if (it != m_response_header.end()) - { - return true; - } - std::list >::iterator it2; - for (it2 = m_response_header_append.begin(); it2 != m_response_header_append.end(); it2++) - { - std::pair& ref = *it2; - if (ref.first == Utility::ToLower(name) ) - { - return true; - } - } - return false; -} - - -#ifdef SOCKETS_NAMESPACE -} -#endif - - diff --git a/Sockets/HTTPSocket.h b/Sockets/HTTPSocket.h deleted file mode 100644 index 00bb305..0000000 --- a/Sockets/HTTPSocket.h +++ /dev/null @@ -1,152 +0,0 @@ -/** \file HTTPSocket.h Class HTTPSocket definition. - ** \date 2004-04-06 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_HTTPSocket_H -#define _SOCKETS_HTTPSocket_H - -#include "sockets-config.h" -#include -#include "TcpSocket.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -/** \defgroup http HTTP Sockets */ -/** HTTP request/response base class. - \ingroup http */ -class HTTPSocket : public TcpSocket -{ - /** map to hold http header values. */ - typedef std::map string_m; -public: - HTTPSocket(ISocketHandler& ); - ~HTTPSocket(); - - void OnRawData(const char *buf,size_t len); - void OnLine(const std::string& line); - - /** Callback executes when first line has been received. - GetMethod, GetUrl/GetUri, and GetHttpVersion are valid when this callback is executed. */ - virtual void OnFirst() = 0; - /** For each header line this callback is executed. - \param key Http header name - \param value Http header value */ - virtual void OnHeader(const std::string& key,const std::string& value) = 0; - /** Callback fires when all http headers have been received. */ - virtual void OnHeaderComplete() = 0; - /** Chunk of http body data recevied. */ - virtual void OnData(const char *,size_t) = 0; - - /** Get http method from incoming request, ie GET/POST/PUT etc */ - const std::string& GetMethod(); - /** Set http method to be used in request. */ - void SetMethod(const std::string& x); - /** Get url from request. */ - const std::string& GetUrl(); - /** Set url to be used in outgoing request. */ - void SetUrl(const std::string& x); - /** Get part of url before '?' character. */ - const std::string& GetUri(); - /** Now why would I need this when there is a SetUrl method? */ - void SetUri(const std::string& x); - /** Get part of url after '?' character. */ - const std::string& GetQueryString(); - /** Get http version from incoming request/response. */ - const std::string& GetHttpVersion(); - /** Get http status from incoming response. */ - const std::string& GetStatus(); - /** Get http statustext from incoming response. */ - const std::string& GetStatusText(); - /** Incoming header has been identified as a request (method url http_version\r\n). */ - bool IsRequest(); - /** Incoming header has been identified as a response (http_version status status_text\r\n). */ - bool IsResponse(); - /** Set http version to be used in outgoing request/response. */ - void SetHttpVersion(const std::string& x); - /** Set http status for outgoing response. */ - void SetStatus(const std::string& x); - /** Set http statustext for outgoing response. */ - void SetStatusText(const std::string& x); - /** Add (and replace if exists) http header. */ - void AddResponseHeader(const std::string& x,const std::string& y); - /** Add (and replace if exists) http header. */ - void AddResponseHeader(const std::string& x,const char *format, ...); - /** Add http header. */ - void AppendResponseHeader(const std::string& x,const std::string& y); - /** See if http header 'name' has been set. */ - bool ResponseHeaderIsSet(const std::string& name); - /** Send response prepared with calls to methods SetHttpVersion, SetStatus, SetStatusText, - and AddResponseHeader. */ - void SendResponse(); - /** Send request prepared with calls to methods SetMethod, SetUrl, SetHttpVersion, - and AddResponseHeader. */ - void SendRequest(); - - /** Implement this to return your own User-agent string. */ - virtual std::string MyUseragent(); - - /** Parse url. If protocol is https, EnableSSL() will be called. */ - void url_this(const std::string& url_in,std::string& protocol,std::string& host,port_t& port,std::string& url,std::string& file); - -protected: - HTTPSocket(const HTTPSocket& s) : TcpSocket(s) {} - /** Reset state of socket to sucessfully implement keep-alive. */ - virtual void Reset(); - -private: - HTTPSocket& operator=(const HTTPSocket& ) { return *this; } - bool m_first; - bool m_header; - std::string m_line; - std::string m_method; - std::string m_url; - std::string m_uri; - std::string m_query_string; - std::string m_http_version; - std::string m_status; - std::string m_status_text; - bool m_request; - bool m_response; - string_m m_response_header; - size_t m_body_size_left; - bool m_b_http_1_1; - bool m_b_keepalive; - std::list > m_response_header_append; -}; - - - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_HTTPSocket_H - diff --git a/Sockets/HttpBaseSocket.cpp b/Sockets/HttpBaseSocket.cpp deleted file mode 100644 index 6f05b2e..0000000 --- a/Sockets/HttpBaseSocket.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/** - ** \file AjpBaseSocket.cpp - ** \date 2007-10-05 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif -#include "HttpBaseSocket.h" -#include "IFile.h" -#include "Utility.h" -#include "HttpResponse.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -#ifdef _DEBUG -#define DEB(x) x -#else -#define DEB(x) -#endif - - -HttpBaseSocket::HttpBaseSocket(ISocketHandler& h) -:HTTPSocket(h) -,m_res_file(NULL) -,m_b_keepalive(false) -{ -} - - -HttpBaseSocket::~HttpBaseSocket() -{ -} - - -void HttpBaseSocket::OnFirst() -{ -DEB(fprintf(stderr, " %s %s %s\n", GetMethod().c_str(), GetUri().c_str(), GetHttpVersion().c_str());) - m_req.SetHttpMethod( GetMethod() ); - m_req.SetUri( GetUri() ); - m_req.SetHttpVersion( GetHttpVersion() ); - - m_req.SetAttribute("query_string", GetQueryString() ); - - m_req.SetRemoteAddr( GetRemoteAddress() ); - m_req.SetRemoteHost( "" ); // %! - m_req.SetServerName( GetSockAddress() ); - m_req.SetServerPort( GetSockPort() ); -} - - -void HttpBaseSocket::OnHeader(const std::string& key,const std::string& value) -{ -DEB(fprintf(stderr, " (request)OnHeader %s: %s\n", key.c_str(), value.c_str());) - if (Utility::ToLower(key) == "cookie") - m_req.AddCookie(value); - else - m_req.SetHeader(key, value); -} - - -void HttpBaseSocket::OnHeaderComplete() -{ - m_body_size_left = atol( m_req.Header("content-length").c_str() ); - if (m_body_size_left > 0) - { - m_req.InitBody( m_body_size_left ); - } - else - { - // execute - Execute(); - } -} - - -void HttpBaseSocket::OnData(const char *buf,size_t sz) -{ - m_req.Write( buf, sz ); - m_body_size_left -= sz; - if (!m_body_size_left) - { - m_req.CloseBody(); - - // execute - Execute(); - } -} - - -// -------------------------------------------------------------------------------------- -void HttpBaseSocket::Execute() -{ - // parse form data / query_string and cookie header if available - m_req.ParseBody(); - - // prepare page - OnExec( m_req ); - -DEB(printf(" *** http version: %s\n", m_req.HttpVersion().c_str()); -printf(" *** connection: %s\n", m_req.Header("connection").c_str());) - if ( !(m_req.HttpVersion().size() > 4 && m_req.HttpVersion().substr(m_req.HttpVersion().size() - 4) == "/1.1") || - m_req.Header("connection") == "close") - { - m_b_keepalive = false; -DEB(printf(" *** keepalive: false\n");) - } - else - { - m_b_keepalive = true; -DEB(printf(" *** keepalive: true\n");) - } - m_req.Reset(); - Reset(); -} - - -// -------------------------------------------------------------------------------------- -void HttpBaseSocket::Respond(const HttpResponse& res) -{ -// res.SetHeader("connection", "close"); - - SetHttpVersion( res.HttpVersion() ); - SetStatus( Utility::l2string(res.HttpStatusCode()) ); - SetStatusText( res.HttpStatusMsg() ); - - if (!ResponseHeaderIsSet("content-length")) - { - AddResponseHeader( "content-length", Utility::l2string( res.GetFile().size() ) ); - } - for (std::map::const_iterator it = res.Headers().begin(); it != res.Headers().end(); ++it) - { - AddResponseHeader( it -> first, it -> second ); - } - std::list vec = res.CookieNames(); - for (std::list::iterator it2 = vec.begin(); it2 != vec.end(); it2++) - { - AppendResponseHeader( "set-cookie", res.Cookie(*it2) ); - } - SendResponse(); - - m_res_file = &res.GetFile(); - - OnTransferLimit(); -} - - -// -------------------------------------------------------------------------------------- -void HttpBaseSocket::OnTransferLimit() -{ - char msg[32768]; - size_t n = m_res_file -> fread(msg, 1, 32768); - while (n > 0) - { - SendBuf( msg, n ); - if (GetOutputLength() > 1) - { - SetTransferLimit( 1 ); - break; - } - n = m_res_file -> fread(msg, 1, 32768); - } - if (!GetOutputLength()) - { - if (!m_b_keepalive) - { - SetCloseAndDelete(); - } - } -} - - -// -------------------------------------------------------------------------------------- -void HttpBaseSocket::Reset() -{ - HTTPSocket::Reset(); - m_body_size_left = 0; -} - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - - diff --git a/Sockets/HttpBaseSocket.h b/Sockets/HttpBaseSocket.h deleted file mode 100644 index 8ce4ad8..0000000 --- a/Sockets/HttpBaseSocket.h +++ /dev/null @@ -1,76 +0,0 @@ -/** - ** \file HttpBaseSocket.h - ** \date 2007-10-05 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _HttpBaseSocket_H -#define _HttpBaseSocket_H - -#include "HTTPSocket.h" -#include "HttpRequest.h" -#include "IHttpServer.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -class HttpResponse; - -class HttpBaseSocket : public HTTPSocket, public IHttpServer -{ -public: - HttpBaseSocket(ISocketHandler& h); - ~HttpBaseSocket(); - - void OnFirst(); - void OnHeader(const std::string& key,const std::string& value); - void OnHeaderComplete(); - void OnData(const char *,size_t); - - // implements IHttpServer::Respond - void Respond(const HttpResponse& res); - - void OnTransferLimit(); - -protected: - HttpBaseSocket(const HttpBaseSocket& s) : HTTPSocket(s) {} // copy constructor - // - HttpRequest m_req; - void Reset(); - -private: - HttpBaseSocket& operator=(const HttpBaseSocket& ) { return *this; } // assignment operator - void Execute(); - // - size_t m_body_size_left; - const IFile *m_res_file; - bool m_b_keepalive; -}; - - - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - -#endif // _HttpBaseSocket_H - diff --git a/Sockets/HttpClientSocket.cpp b/Sockets/HttpClientSocket.cpp deleted file mode 100644 index c6f43e4..0000000 --- a/Sockets/HttpClientSocket.cpp +++ /dev/null @@ -1,277 +0,0 @@ -/** - ** \file HttpClientSocket.cpp - ** \date 2006-04-20 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif -#include "HttpClientSocket.h" -#include "StdLog.h" -#include "ISocketHandler.h" -#include "Utility.h" - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -HttpClientSocket::HttpClientSocket(ISocketHandler& h) -:HTTPSocket(h) -,m_data_ptr(NULL) -,m_data_size(0) -,m_content_length(0) -,m_data_ptr_set(false) -,m_fil(NULL) -,m_content_ptr(0) -,m_b_complete(false) -,m_b_close_when_complete(false) -{ -} - - -HttpClientSocket::HttpClientSocket(ISocketHandler& h,const std::string& url_in) -:HTTPSocket(h) -,m_data_ptr(NULL) -,m_data_size(0) -,m_content_length(0) -,m_data_ptr_set(false) -,m_fil(NULL) -,m_content_ptr(0) -,m_b_complete(false) -,m_b_close_when_complete(false) -{ - std::string url; - url_this(url_in, m_protocol, m_host, m_port, url, m_url_filename); - SetUrl( url ); -} - - -HttpClientSocket::~HttpClientSocket() -{ - if (m_data_ptr && !m_data_ptr_set) - { - delete[] m_data_ptr; - } - if (m_fil) - { - fclose(m_fil); - } -} - - -void HttpClientSocket::OnFirst() -{ - if (!IsResponse()) - { - Handler().LogError(this, "OnFirst", 0, "Response expected but not received - aborting", LOG_LEVEL_FATAL); - SetCloseAndDelete(); - } - m_content = GetHttpVersion() + " " + GetStatus() + " " + GetStatusText() + "\r\n"; -} - - -void HttpClientSocket::OnHeader(const std::string& key,const std::string& value) -{ - m_content += key + ": " + value + "\r\n"; - if (!strcasecmp(key.c_str(), "content-length")) - { - m_content_length = atoi(value.c_str()); - } - else - if (!strcasecmp(key.c_str(), "content-type")) - { - m_content_type = value; - } -} - - -void HttpClientSocket::OnHeaderComplete() -{ - if (m_filename.size()) - { - m_fil = fopen(m_filename.c_str(), "wb"); - } - else - if (!m_data_ptr && m_content_length) - { - m_data_ptr = new unsigned char[m_content_length]; - m_data_size = m_content_length; - } -} - - -void HttpClientSocket::OnData(const char *buf,size_t len) -{ - if (m_fil) - { - fwrite(buf, 1, len, m_fil); - } - else - if (m_data_ptr) - { - if (m_content_ptr + len > m_data_size) - { - Handler().LogError(this, "OnData", -1, "content buffer overflow", LOG_LEVEL_ERROR); - } - else - { - memcpy(m_data_ptr + m_content_ptr, buf, len); - } - } - m_content_ptr += len; - if (m_content_ptr == m_content_length && m_content_length) - { - if (m_fil) - { - fclose(m_fil); - m_fil = NULL; - } - m_b_complete = true; - OnContent(); - if (m_b_close_when_complete) - { - SetCloseAndDelete(); - } - } -} - - -void HttpClientSocket::OnDelete() -{ - if (!m_b_complete) - { - if (m_fil) - { - fclose(m_fil); - m_fil = NULL; - } - m_b_complete = true; - OnContent(); - } -} - - -void HttpClientSocket::SetFilename(const std::string& x) -{ - m_filename = x; -} - - -void HttpClientSocket::SetDataPtr(unsigned char *buf,size_t len) -{ - m_data_ptr = buf; - m_data_size = len; - m_data_ptr_set = true; -} - - -const std::string& HttpClientSocket::GetContent() -{ - return m_content; -} - - -size_t HttpClientSocket::GetContentLength() -{ - return m_content_length; -} - - -size_t HttpClientSocket::GetContentPtr() -{ - return m_content_ptr; -} - - -size_t HttpClientSocket::GetPos() -{ - return m_content_ptr; -} - - -bool HttpClientSocket::Complete() -{ - return m_b_complete; -} - - -const unsigned char *HttpClientSocket::GetDataPtr() const -{ - return m_data_ptr; -} - - -void HttpClientSocket::OnContent() -{ -} - - -void HttpClientSocket::SetCloseOnComplete(bool x) -{ - m_b_close_when_complete = x; -} - - -const std::string& HttpClientSocket::GetUrlProtocol() -{ - return m_protocol; -} - - -const std::string& HttpClientSocket::GetUrlHost() -{ - return m_host; -} - - -port_t HttpClientSocket::GetUrlPort() -{ - return m_port; -} - - -const std::string& HttpClientSocket::GetUrlFilename() -{ - return m_url_filename; -} - - -const std::string& HttpClientSocket::GetContentType() -{ - return m_content_type; -} - - -void HttpClientSocket::Url(const std::string& url_in,std::string& host,port_t& port) -{ - std::string url; - url_this(url_in, m_protocol, m_host, m_port, url, m_url_filename); - SetUrl(url); - host = GetUrlHost(); - port = GetUrlPort(); -} - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - diff --git a/Sockets/HttpClientSocket.h b/Sockets/HttpClientSocket.h deleted file mode 100644 index dc307a9..0000000 --- a/Sockets/HttpClientSocket.h +++ /dev/null @@ -1,121 +0,0 @@ -/** - ** \file HttpClientSocket.h - ** \date 2006-04-20 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_HttpClientSocket_H -#define _SOCKETS_HttpClientSocket_H - -#include "sockets-config.h" -#include "HTTPSocket.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -/** Get http response to file or memory. - \ingroup http */ -class HttpClientSocket : public HTTPSocket -{ -public: - HttpClientSocket(ISocketHandler&); - HttpClientSocket(ISocketHandler&,const std::string& url_in); - ~HttpClientSocket(); - - /** Parse url to protocol,host,port,url and file. */ - void Url(const std::string& url_in,std::string& host,port_t& port); - - void OnFirst(); - void OnHeader(const std::string&,const std::string&); - void OnHeaderComplete(); - void OnData(const char *,size_t); - void OnDelete(); - - /** New callback method fires when all data is received. */ - virtual void OnContent(); - - /** Write response to this file */ - void SetFilename(const std::string& ); - const std::string& Filename() const { return m_filename; } - - /** Store response in this buffer. */ - void SetDataPtr(unsigned char *,size_t); - - /** Get response headers. */ - const std::string& GetContent(); - - /** Get size of response body. */ - size_t GetContentLength(); - - /** Get content type from response header. */ - const std::string& GetContentType(); - - /** Get size of received response body. */ - size_t GetContentPtr(); - /** Get size of received response body. */ - size_t GetPos(); - - /** Complete response has been received. */ - bool Complete(); - - /** Get ptr to response data buffer. */ - const unsigned char *GetDataPtr() const; - - /** Close socket when response received. */ - void SetCloseOnComplete(bool = true); - - /** Get protocol used from url. */ - const std::string& GetUrlProtocol(); - /** Get hostname from url. */ - const std::string& GetUrlHost(); - /** Get port from url. */ - port_t GetUrlPort(); - /** Get filename part of url. */ - const std::string& GetUrlFilename(); - -protected: - HttpClientSocket(const HttpClientSocket& s) : HTTPSocket(s) {} // copy constructor - HttpClientSocket& operator=(const HttpClientSocket& ) { return *this; } // assignment operator -private: - std::string m_filename; ///< Filename to write response to - unsigned char *m_data_ptr; ///< Ptr to buffer where to store response - size_t m_data_size; ///< Max size of data buffer - size_t m_content_length; ///< Content-length header received from remote - std::string m_content; ///< Received http headers - bool m_data_ptr_set; ///< Buffer set from outside, do not delete - FILE *m_fil; ///< Output file - size_t m_content_ptr; ///< Number of bytes received from body - bool m_b_complete; ///< The entire content-length number of bytes has been received - bool m_b_close_when_complete; ///< Close when the full response has been received - std::string m_protocol; ///< Protocol part of url_in - std::string m_host; ///< Hostname from url_in - port_t m_port; ///< Port from url_in - std::string m_url_filename; ///< Filename from url_in - std::string m_content_type; ///< Content-type: header from response -}; - - - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif -#endif // _SOCKETS_HttpClientSocket_H - diff --git a/Sockets/HttpDebugSocket.cpp b/Sockets/HttpDebugSocket.cpp deleted file mode 100644 index 70bf75b..0000000 --- a/Sockets/HttpDebugSocket.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/** \file HttpDebugSocket.cpp - ** \date 2004-10-08 -**/ -/* -Copyright (C) 2004-2007 Anders Hedström (grymse@alhem.net) - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif -#include "HttpDebugSocket.h" -#include "Utility.h" -#include "ISocketHandler.h" - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -HttpDebugSocket::HttpDebugSocket(ISocketHandler& h) : HTTPSocket(h) -,m_content_length(0) -,m_read_ptr(0) -{ -} - - -HttpDebugSocket::~HttpDebugSocket() -{ -} - - -void HttpDebugSocket::Init() -{ - if (GetParent() -> GetPort() == 443) - { -#ifdef HAVE_OPENSSL - EnableSSL(); -#else - Handler().LogError(this, "url_this", -1, "SSL not available", LOG_LEVEL_WARNING); -#endif - } -} - - -void HttpDebugSocket::OnFirst() -{ - Send( - "HTTP/1.1 200 OK\n" - "Content-type: text/html\n" - "Connection: close\n" - "Server: HttpDebugSocket/1.0\n" - "\n"); - Send( - "Echo Request" - "

Request Header

"); - Send( "
" - "
" - "
"); - Send( "
");
-	Send(GetMethod() + " " + GetUrl() + " " + GetHttpVersion() + "\n");
-}
-
-
-void HttpDebugSocket::OnHeader(const std::string& key,const std::string& value)
-{
-	if (!strcasecmp(key.c_str(),"content-length"))
-		m_content_length = atoi(value.c_str());
-
-	Send(key + ": " + value + "\n");
-}
-
-
-void HttpDebugSocket::OnHeaderComplete()
-{
-	if (m_content_length)
-	{
-		Send("

Request Body

");
-	}
-	else
-	{
-		Send("

"); - SetCloseAndDelete(); - } -} - - -void HttpDebugSocket::OnData(const char *p,size_t l) -{ - SendBuf(p,l); - m_read_ptr += (int)l; - if (m_read_ptr >= m_content_length && m_content_length) - { - Send("
"); - SetCloseAndDelete(); - } -} - - -#ifdef SOCKETS_NAMESPACE -} -#endif - - diff --git a/Sockets/HttpDebugSocket.h b/Sockets/HttpDebugSocket.h deleted file mode 100644 index f905904..0000000 --- a/Sockets/HttpDebugSocket.h +++ /dev/null @@ -1,70 +0,0 @@ -/** \file HttpDebugSocket.h - ** \date 2004-09-27 -**/ -/* -Copyright (C) 2004-2007 Anders Hedström (grymse@alhem.net) - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_HttpDebugSocket_H -#define _SOCKETS_HttpDebugSocket_H - -#include "sockets-config.h" -#include "HTTPSocket.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -class ISocketHandler; - -/** HTTP request "echo" class. This class echoes a http request/body -with a html formatted page. - \ingroup http */ -class HttpDebugSocket : public HTTPSocket -{ -public: - HttpDebugSocket(ISocketHandler&); - ~HttpDebugSocket(); - - void Init(); - - void OnFirst(); - void OnHeader(const std::string& key,const std::string& value); - void OnHeaderComplete(); - void OnData(const char *,size_t); - -private: - HttpDebugSocket(const HttpDebugSocket& s) : HTTPSocket(s) {} // copy constructor - HttpDebugSocket& operator=(const HttpDebugSocket& ) { return *this; } // assignment operator - int m_content_length; - int m_read_ptr; -}; - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_HttpDebugSocket_H - diff --git a/Sockets/HttpGetSocket.cpp b/Sockets/HttpGetSocket.cpp deleted file mode 100644 index fe5e3d5..0000000 --- a/Sockets/HttpGetSocket.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/** \file HttpGetSocket.cpp - ** \date 2004-02-13 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _WIN32 -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif -#else -#include -#endif -#include "Utility.h" -#include "Parse.h" -#include "ISocketHandler.h" -#include "HttpGetSocket.h" - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -HttpGetSocket::HttpGetSocket(ISocketHandler& h) : HttpClientSocket(h) -{ -} - - -HttpGetSocket::HttpGetSocket(ISocketHandler& h,const std::string& url_in,const std::string& to_file) : HttpClientSocket(h, url_in) -{ - if (to_file.size()) - { - SetFilename(to_file); - } - if (!Open(GetUrlHost(),GetUrlPort())) - { - if (!Connecting()) - { - Handler().LogError(this, "HttpGetSocket", -1, "connect() failed miserably", LOG_LEVEL_FATAL); - SetCloseAndDelete(); - } - } -} - - -HttpGetSocket::HttpGetSocket(ISocketHandler& h,const std::string& host,port_t port,const std::string& url,const std::string& to_file) : HttpClientSocket(h) -{ - SetUrl(url); - if (to_file.size()) - { - SetFilename(to_file); - } - if (!Open(host, port)) - { - if (!Connecting()) - { - Handler().LogError(this, "HttpGetSocket", -1, "connect() failed miserably", LOG_LEVEL_FATAL); - SetCloseAndDelete(); - } - } -} - - -HttpGetSocket::~HttpGetSocket() -{ -} - - -void HttpGetSocket::OnConnect() -{ - SetMethod( "GET" ); - AddResponseHeader( "Accept", "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1"); - AddResponseHeader( "Accept-Language", "en-us,en;q=0.5"); - AddResponseHeader( "Accept-Encoding", "gzip,deflate"); - AddResponseHeader( "Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); - AddResponseHeader( "User-agent", MyUseragent() ); - - if (GetUrlPort() != 80 && GetUrlPort() != 443) - AddResponseHeader( "Host", GetUrlHost() + ":" + Utility::l2string(GetUrlPort()) ); - else - AddResponseHeader( "Host", GetUrlHost() ); - SendRequest(); -} - - -#ifdef SOCKETS_NAMESPACE -} -#endif - - diff --git a/Sockets/HttpGetSocket.h b/Sockets/HttpGetSocket.h deleted file mode 100644 index beb1097..0000000 --- a/Sockets/HttpGetSocket.h +++ /dev/null @@ -1,66 +0,0 @@ -/** \file HttpGetSocket.h - ** \date 2004-02-13 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_HttpGetSocket_H -#define _SOCKETS_HttpGetSocket_H - -#include "sockets-config.h" -#include "HttpClientSocket.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -/** Get http page. - \ingroup http */ -class HttpGetSocket : public HttpClientSocket -{ -public: - HttpGetSocket(ISocketHandler&); - HttpGetSocket(ISocketHandler&,const std::string& url,const std::string& to_file = ""); - HttpGetSocket(ISocketHandler&,const std::string& host,port_t port,const std::string& url,const std::string& to_file = ""); - ~HttpGetSocket(); - - void OnConnect(); - -protected: - HttpGetSocket& operator=(const HttpGetSocket& ) { return *this; } - HttpGetSocket(const HttpGetSocket& s) : HttpClientSocket(s) {} -}; - - - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_HttpGetSocket_H - diff --git a/Sockets/HttpPostSocket.cpp b/Sockets/HttpPostSocket.cpp deleted file mode 100644 index a72b8cf..0000000 --- a/Sockets/HttpPostSocket.cpp +++ /dev/null @@ -1,294 +0,0 @@ -/** \file HttpPostSocket.cpp - ** \date 2004-10-30 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _WIN32 -#ifdef _MSC_VER -#pragma warning(disable:4786) -#pragma warning(disable:4503) -#endif -#else -#include -#include -#endif -#include "ISocketHandler.h" -#include -#include -#include "Parse.h" -#include "Utility.h" -#include "Lock.h" - -#include "HttpPostSocket.h" - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -int HttpPostSocket::m_boundary_count = 0; -Mutex HttpPostSocket::m_boundary_mutex; - - -HttpPostSocket::HttpPostSocket(ISocketHandler& h) : HttpClientSocket(h) -,m_bMultipart(false) -{ -} - - -HttpPostSocket::HttpPostSocket(ISocketHandler& h,const std::string& url_in) : HttpClientSocket(h, url_in) -,m_bMultipart(false) -{ - Lock lock(m_boundary_mutex); - - m_boundary = "----"; - for (int i = 0; i < 12; i++) - { - char c = m_boundary_count++ % 128; - while (!isalnum(c)) - c = m_boundary_count++ % 128; - m_boundary += c; - } - m_boundary += "__" + Utility::l2string(m_boundary_count++); -} - - -HttpPostSocket::~HttpPostSocket() -{ -} - - -void HttpPostSocket::AddField(const std::string& name,const std::string& value) -{ - std::list vec; - vec.push_back(value); - AddMultilineField(name, vec); -} - - -void HttpPostSocket::AddMultilineField(const std::string& name,std::list& values) -{ - m_fields[name] = values; -} - - -void HttpPostSocket::AddFile(const std::string& name,const std::string& filename,const std::string& type) -{ - struct stat st; - if (!stat(filename.c_str(), &st)) - { - m_files[name] = filename; - m_content_length[filename] = st.st_size; - m_content_type[filename] = type; - m_bMultipart = true; - } - else - { - Handler().LogError(this, "AddFile", Errno, StrError(Errno), LOG_LEVEL_FATAL); - SetCloseAndDelete(); - } -} - - -void HttpPostSocket::Open() -{ - // why do I have to specify TcpSocket:: to get to the Open() method?? - TcpSocket::Open(GetUrlHost(), GetUrlPort()); -} - - -void HttpPostSocket::OnConnect() -{ - if (m_bMultipart) - { - DoMultipartPost(); - } - else - { - std::string body; - - // only fields, no files, add urlencoding - for (std::map >::iterator it = m_fields.begin(); it != m_fields.end(); it++) - { - std::string name = (*it).first; - std::list& ref = (*it).second; - if (body.size()) - { - body += '&'; - } - body += name + "="; - bool first = true; - for (std::list::iterator it = ref.begin(); it != ref.end(); it++) - { - std::string value = *it; - if (!first) - { - body += "%0d%0a"; // CRLF - } - body += Utility::rfc1738_encode(value); - first = false; - } - } - - // build header, send body - SetMethod("POST"); - SetHttpVersion( "HTTP/1.1" ); - AddResponseHeader( "Host", GetUrlHost() ); // oops - this is actually a request header that we're adding.. - AddResponseHeader( "User-agent", MyUseragent()); - AddResponseHeader( "Accept", "text/html, text/plain, */*;q=0.01" ); - AddResponseHeader( "Connection", "close" ); - AddResponseHeader( "Content-type", "application/x-www-form-urlencoded" ); - AddResponseHeader( "Content-length", Utility::l2string((long)body.size()) ); - SendRequest(); - - // send body - Send( body ); - } -} - - -void HttpPostSocket::DoMultipartPost() -{ - long length = 0; // calculate content_length of our post body - std::string tmp; - - // fields - { - for (std::map >::iterator it = m_fields.begin(); it != m_fields.end(); it++) - { - std::string name = (*it).first; - std::list& ref = (*it).second; - tmp = "--" + m_boundary + "\r\n" - "content-disposition: form-data; name=\"" + name + "\"\r\n" - "\r\n"; - for (std::list::iterator it = ref.begin(); it != ref.end(); it++) - { - std::string value = *it; - tmp += value + "\r\n"; - } - length += (long)tmp.size(); - } - } - - // files - { - for (std::map::iterator it = m_files.begin(); it != m_files.end(); it++) - { - std::string name = (*it).first; - std::string filename = (*it).second; - long content_length = m_content_length[filename]; - std::string content_type = m_content_type[filename]; - tmp = "--" + m_boundary + "\r\n" - "content-disposition: form-data; name=\"" + name + "\"; filename=\"" + filename + "\"\r\n" - "content-type: " + content_type + "\r\n" - "\r\n"; - length += (long)tmp.size(); - length += content_length; - length += 2; // crlf after file - } - } - - // end - tmp = "--" + m_boundary + "--\r\n"; - length += (long)tmp.size(); - - // build header, send body - SetMethod("POST"); - SetHttpVersion( "HTTP/1.1" ); - AddResponseHeader( "Host", GetUrlHost() ); // oops - this is actually a request header that we're adding.. - AddResponseHeader( "User-agent", MyUseragent()); - AddResponseHeader( "Accept", "text/html, text/plain, */*;q=0.01" ); - AddResponseHeader( "Connection", "close" ); - AddResponseHeader( "Content-type", "multipart/form-data; boundary=" + m_boundary ); - AddResponseHeader( "Content-length", Utility::l2string(length) ); - - SendRequest(); - - // send fields - { - for (std::map >::iterator it = m_fields.begin(); it != m_fields.end(); it++) - { - std::string name = (*it).first; - std::list& ref = (*it).second; - tmp = "--" + m_boundary + "\r\n" - "content-disposition: form-data; name=\"" + name + "\"\r\n" - "\r\n"; - for (std::list::iterator it = ref.begin(); it != ref.end(); it++) - { - std::string value = *it; - tmp += value + "\r\n"; - } - Send( tmp ); - } - } - - // send files - { - for (std::map::iterator it = m_files.begin(); it != m_files.end(); it++) - { - std::string name = (*it).first; - std::string filename = (*it).second; - std::string content_type = m_content_type[filename]; - tmp = "--" + m_boundary + "\r\n" - "content-disposition: form-data; name=\"" + name + "\"; filename=\"" + filename + "\"\r\n" - "content-type: " + content_type + "\r\n" - "\r\n"; - Send( tmp ); - { - FILE *fil = fopen(filename.c_str(),"rb"); - if (fil) - { - char slask[2000]; // for fread - size_t n; - while ((n = fread(slask, 1, 2000, fil)) > 0) - { - SendBuf(slask, n); - } - fclose(fil); - } - } - Send("\r\n"); - } - } - - // end of send - Send("--" + m_boundary + "--\r\n"); -} - - -void HttpPostSocket::SetMultipart() -{ - m_bMultipart = true; -} - - -#ifdef SOCKETS_NAMESPACE -} -#endif - - diff --git a/Sockets/HttpPostSocket.h b/Sockets/HttpPostSocket.h deleted file mode 100644 index 7815da3..0000000 --- a/Sockets/HttpPostSocket.h +++ /dev/null @@ -1,94 +0,0 @@ -/** \file HttpPostSocket.h - ** \date 2004-10-30 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_HttpPostSocket_H -#define _SOCKETS_HttpPostSocket_H - -#include "sockets-config.h" -#include "HttpClientSocket.h" -#include "Mutex.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -class ISocketHandler; - -/** Generate a http post request, get response. - \ingroup http */ -class HttpPostSocket : public HttpClientSocket -{ -public: - HttpPostSocket(ISocketHandler&); - /* client constructor, - \param url_in = 'http://host:port/resource' */ - HttpPostSocket(ISocketHandler&,const std::string& url_in); - ~HttpPostSocket(); - - // these must be specified before connecting / adding to handler - /** Add field to post. */ - void AddField(const std::string& name,const std::string& value); - /** Add multiline field to post. */ - void AddMultilineField(const std::string& name,std::list& values); - /** Add file to post. */ - void AddFile(const std::string& name,const std::string& filename,const std::string& type); - - /** use this to post with content-type multipart/form-data. - // when adding a file to the post, this is the default and only content-type */ - void SetMultipart(); - - /** connect to host:port derived from url in constructor */ - void Open(); - - /** http put client implemented in OnConnect */ - void OnConnect(); - -private: - HttpPostSocket(const HttpPostSocket& s) : HttpClientSocket(s) {} // copy constructor - HttpPostSocket& operator=(const HttpPostSocket& ) { return *this; } // assignment operator - void DoMultipartPost(); - // - std::map > m_fields; - std::map m_files; - std::string m_boundary; - std::map m_content_length; - std::map m_content_type; - bool m_bMultipart; -static int m_boundary_count; -static Mutex m_boundary_mutex; -}; - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_HttpPostSocket_H - diff --git a/Sockets/HttpPutSocket.cpp b/Sockets/HttpPutSocket.cpp deleted file mode 100644 index 90ac7e4..0000000 --- a/Sockets/HttpPutSocket.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/** \file HttpPutSocket.cpp - ** \date 2004-10-30 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _WIN32 -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif -#else -#include -#endif -#include "ISocketHandler.h" -#include -#include - -#include "Utility.h" -#include "Parse.h" - -#include "HttpPutSocket.h" - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -HttpPutSocket::HttpPutSocket(ISocketHandler& h) : HttpClientSocket(h) -{ -} - - -HttpPutSocket::HttpPutSocket(ISocketHandler& h,const std::string& url_in) : HttpClientSocket(h, url_in) -{ -} - - -HttpPutSocket::~HttpPutSocket() -{ -} - - -void HttpPutSocket::SetFile(const std::string& file) -{ - struct stat st; - if (!stat(file.c_str(), &st)) - { - m_filename = file; - m_content_length = st.st_size; - } - else - { - Handler().LogError(this, "SetFile", Errno, StrError(Errno), LOG_LEVEL_FATAL); - SetCloseAndDelete(); - } -} - - -void HttpPutSocket::SetContentType(const std::string& type) -{ - m_content_type = type; -} - - - -void HttpPutSocket::Open() -{ - // why do I have to specify TcpSocket:: to get to the Open() method?? - TcpSocket::Open(GetUrlHost(), GetUrlPort()); -} - - -void HttpPutSocket::OnConnect() -{ - SetMethod( "PUT" ); - SetHttpVersion( "HTTP/1.1" ); - AddResponseHeader( "Host", GetUrlHost() ); - AddResponseHeader( "Content-type", m_content_type ); - AddResponseHeader( "Content-length", Utility::l2string(m_content_length) ); - AddResponseHeader( "User-agent", MyUseragent() ); - SendRequest(); - - FILE *fil = fopen(m_filename.c_str(), "rb"); - if (fil) - { - size_t n; - char buf[32768]; - while ((n = fread(buf, 1, 32768, fil)) > 0) - { - SendBuf(buf, n); - } - fclose(fil); - } -} - - -#ifdef SOCKETS_NAMESPACE -} -#endif - - diff --git a/Sockets/HttpPutSocket.h b/Sockets/HttpPutSocket.h deleted file mode 100644 index cafc7b9..0000000 --- a/Sockets/HttpPutSocket.h +++ /dev/null @@ -1,83 +0,0 @@ -/** \file HttpPutSocket.h - ** \date 2004-10-30 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_HttpPutSocket_H -#define _SOCKETS_HttpPutSocket_H - -#include "sockets-config.h" -#include "HttpClientSocket.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -class ISocketHandler; - -/** Put http page. - \ingroup http */ -class HttpPutSocket : public HttpClientSocket -{ -public: - HttpPutSocket(ISocketHandler&); - /** client constructor, - \param url_in = 'http://host:port/resource' */ - HttpPutSocket(ISocketHandler&,const std::string& url_in); - ~HttpPutSocket(); - - // these must be specified before connecting / adding to handler - /** Set filename to send. */ - void SetFile(const std::string& ); - /** Set mimetype of file to send. */ - void SetContentType(const std::string& ); - - /** connect to host:port derived from url in constructor */ - void Open(); - - /** http put client implemented in OnConnect */ - void OnConnect(); - -private: - HttpPutSocket(const HttpPutSocket& s) : HttpClientSocket(s) {} // copy constructor - HttpPutSocket& operator=(const HttpPutSocket& ) { return *this; } // assignment operator - // - std::string m_filename; - std::string m_content_type; - long m_content_length; -}; - - - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_HttpPutSocket_H - diff --git a/Sockets/HttpRequest.cpp b/Sockets/HttpRequest.cpp deleted file mode 100644 index 3909595..0000000 --- a/Sockets/HttpRequest.cpp +++ /dev/null @@ -1,358 +0,0 @@ -/** - ** \file HttpRequest.cpp - ** \date 2007-10-05 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif -#include "HttpRequest.h" -#include "Utility.h" -#include "MemFile.h" -#include "HttpdForm.h" -#include "HttpdCookies.h" -#include "Parse.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -#ifdef _DEBUG -#define DEB(x) x; fflush(stderr); -#else -#define DEB(x) -#endif - - -// -------------------------------------------------------------------------------------- -HttpRequest::HttpRequest() : HttpTransaction() -, m_server_port(0) -, m_is_ssl(false) -, m_body_file(NULL) -, m_form(NULL) -{ -} - - -// -------------------------------------------------------------------------------------- -HttpRequest::HttpRequest(const HttpRequest& src) : HttpTransaction(src) -, m_method(src.m_method) -, m_protocol(src.m_protocol) -, m_req_uri(src.m_req_uri) -, m_remote_addr(src.m_remote_addr) -, m_remote_host(src.m_remote_host) -, m_server_name(src.m_server_name) -, m_server_port(src.m_server_port) -, m_is_ssl(src.m_is_ssl) -, m_attribute(src.m_attribute) -, m_null(src.m_null) -, m_body_file(src.m_body_file) -, m_form(src.m_form) -, m_cookies(src.m_cookies) -, m_cookie(src.m_cookie) -{ -} - - -// -------------------------------------------------------------------------------------- -HttpRequest::~HttpRequest() -{ - m_body_file = std::auto_ptr(NULL); - m_form = std::auto_ptr(NULL); -/* - if (m_body_file) - { - delete m_body_file; - } - if (m_form) - { - delete m_form; - } -*/ -} - - -// -------------------------------------------------------------------------------------- -void HttpRequest::SetHttpMethod(const std::string& value) -{ - m_method = value; -} - - -const std::string& HttpRequest::HttpMethod() const -{ - return m_method; -} - - - -// -------------------------------------------------------------------------------------- -void HttpRequest::SetHttpVersion(const std::string& value) -{ - m_protocol = value; -} - - -const std::string& HttpRequest::HttpVersion() const -{ - return m_protocol; -} - - - -// -------------------------------------------------------------------------------------- -void HttpRequest::SetUri(const std::string& value) -{ - m_req_uri = Utility::rfc1738_decode(value); -} - - -const std::string& HttpRequest::Uri() const -{ - return m_req_uri; -} - - - -// -------------------------------------------------------------------------------------- -void HttpRequest::SetRemoteAddr(const std::string& value) -{ - m_remote_addr = value; -} - - -const std::string& HttpRequest::RemoteAddr() const -{ - return m_remote_addr; -} - - - -// -------------------------------------------------------------------------------------- -void HttpRequest::SetRemoteHost(const std::string& value) -{ - m_remote_host = value; -} - - -const std::string& HttpRequest::RemoteHost() const -{ - return m_remote_host; -} - - - -// -------------------------------------------------------------------------------------- -void HttpRequest::SetServerName(const std::string& value) -{ - m_server_name = value; -} - - -const std::string& HttpRequest::ServerName() const -{ - return m_server_name; -} - - - -// -------------------------------------------------------------------------------------- -void HttpRequest::SetServerPort(int value) -{ - m_server_port = value; -} - - -int HttpRequest::ServerPort() const -{ - return m_server_port; -} - - - -// -------------------------------------------------------------------------------------- -void HttpRequest::SetIsSsl(bool value) -{ - m_is_ssl = value; -} - - -bool HttpRequest::IsSsl() const -{ - return m_is_ssl; -} - - - -// -------------------------------------------------------------------------------------- -void HttpRequest::SetAttribute(const std::string& key, const std::string& value) -{ - m_attribute[Utility::ToLower(key)] = value; -} - - -void HttpRequest::SetAttribute(const std::string& key, long value) -{ - m_attribute[Utility::ToLower(key)] = Utility::l2string(value); -} - - -const std::string& HttpRequest::Attribute(const std::string& key) const -{ - std::map::const_iterator it; - if ( (it = m_attribute.find(Utility::ToLower(key))) != m_attribute.end()) - return it -> second; - return m_null; -} - - -// -------------------------------------------------------------------------------------- -const std::map& HttpRequest::Attributes() const -{ - return m_attribute; -} - - -// -------------------------------------------------------------------------------------- -void HttpRequest::AddCookie(const std::string& str) -{ - m_cookies.add( str ); - Parse pa(str, ";"); - std::string lstr = pa.getword(); - while (!lstr.empty()) - { - Parse pa2(lstr, "="); - std::string name = pa2.getword(); - m_cookie[name] = lstr; -DEB(fprintf(stderr, " *** AddCookie '%s' = '%s'\n", name.c_str(), lstr.c_str());) - lstr = pa.getword(); - } -} - - -// -------------------------------------------------------------------------------------- -void HttpRequest::InitBody( size_t sz ) -{ - if (!m_body_file.get()) - m_body_file = std::auto_ptr(new MemFile); -DEB( else - fprintf(stderr, "Body data file already opened\n");) -} - - -// -------------------------------------------------------------------------------------- -void HttpRequest::Write( const char *buf, size_t sz ) -{ - if (m_body_file.get()) - m_body_file -> fwrite(buf, 1, sz); -DEB( else - fprintf(stderr, "Write: Body data file not open\n");) -} - - -// -------------------------------------------------------------------------------------- -void HttpRequest::CloseBody() -{ - if (m_body_file.get()) - m_body_file -> fclose(); -DEB( else - fprintf(stderr, "CloseBody: File not open\n");) -} - - -// -------------------------------------------------------------------------------------- -void HttpRequest::ParseBody() -{ - std::map::const_iterator it; - if ( (it = m_attribute.find("query_string")) != m_attribute.end()) - { - std::string qs = it -> second; - m_form = std::auto_ptr(new HttpdForm( qs, qs.size() )); - } - else - if (m_body_file.get()) - { - m_form = std::auto_ptr(new HttpdForm( m_body_file.get(), ContentType(), ContentLength() )); - } - else - { - // dummy - m_form = std::auto_ptr(new HttpdForm( "", 0 )); - } -} - - -// -------------------------------------------------------------------------------------- -const HttpdForm& HttpRequest::Form() const -{ - return *m_form; -} - - -// -------------------------------------------------------------------------------------- -const HttpdCookies& HttpRequest::Cookies() const -{ - return m_cookies; -} - - -// -------------------------------------------------------------------------------------- -void HttpRequest::Reset() -{ - HttpTransaction::Reset(); - m_method = ""; - m_protocol = ""; - m_req_uri = ""; - m_remote_addr = ""; - m_remote_host = ""; - m_server_name = ""; - m_server_port = 0; - m_is_ssl = false; - while (!m_attribute.empty()) - { - m_attribute.erase(m_attribute.begin()); - } - m_body_file = std::auto_ptr(NULL); - m_form = std::auto_ptr(NULL); -/* - if (m_body_file) - { - delete m_body_file; - m_body_file = NULL; - } - if (m_form) - { - delete m_form; - m_form = NULL; - } -*/ - m_cookies.Reset(); - while (!m_cookie.empty()) - { - m_cookie.erase(m_cookie.begin()); - } -} - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - - diff --git a/Sockets/HttpRequest.h b/Sockets/HttpRequest.h deleted file mode 100644 index 38290e4..0000000 --- a/Sockets/HttpRequest.h +++ /dev/null @@ -1,125 +0,0 @@ -/** - ** \file HttpRequest.h - ** \date 2007-10-05 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_HttpRequest_H -#define _SOCKETS_HttpRequest_H - -#include "HttpTransaction.h" -#include "HttpdCookies.h" -#include -#include "IFile.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -class HttpdForm; -class IFile; - -class HttpRequest : public HttpTransaction -{ -public: - HttpRequest(); - HttpRequest(const HttpRequest& src); - ~HttpRequest(); - - /** Get, Post */ - void SetHttpMethod(const std::string& value); - const std::string& HttpMethod() const; - - /** HTTP/1.x */ - void SetHttpVersion(const std::string& value); - const std::string& HttpVersion() const; - - void SetUri(const std::string& value); - const std::string& Uri() const; - - void SetRemoteAddr(const std::string& value); - const std::string& RemoteAddr() const; - - void SetRemoteHost(const std::string& value); - const std::string& RemoteHost() const; - - void SetServerName(const std::string& value); - const std::string& ServerName() const; - - void SetServerPort(int value); - int ServerPort() const; - - void SetIsSsl(bool value); - bool IsSsl() const; - - /** Set / Read attribute value */ - void SetAttribute(const std::string& key, const std::string& value); - void SetAttribute(const std::string& key, long value); - const std::string& Attribute(const std::string& key) const; - - const std::map& Attributes() const; - - /** Cookies */ - void AddCookie(const std::string& ); - const std::map& CookieMap() const { return m_cookie; } - - /** Open file for body data */ - void InitBody( size_t sz ); - - /** Write body data */ - void Write( const char *buf, size_t sz ); - - /** No more writing */ - void CloseBody(); - - void ParseBody(); - - const HttpdForm& Form() const; - const HttpdCookies& Cookies() const; - - const IFile *BodyFile() const { return m_body_file.get(); } - - void Reset(); - -private: - std::string m_method; - std::string m_protocol; - std::string m_req_uri; - std::string m_remote_addr; - std::string m_remote_host; - std::string m_server_name; - int m_server_port; - bool m_is_ssl; - std::map m_attribute; - std::string m_null; - mutable std::auto_ptr m_body_file; - mutable std::auto_ptr m_form; - HttpdCookies m_cookies; - std::map m_cookie; - -}; // end of class - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - -#endif // _SOCKETS_HttpRequest_H - diff --git a/Sockets/HttpResponse.cpp b/Sockets/HttpResponse.cpp deleted file mode 100644 index c312ee2..0000000 --- a/Sockets/HttpResponse.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/** - ** \file HttpResponse.cpp - ** \date 2007-10-05 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif -#include -#include - -#include "HttpResponse.h" -#include "HttpRequest.h" -#include "MemFile.h" -#include "File.h" -#include "Parse.h" -#include "Utility.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -#ifdef _DEBUG -#define DEB(x) x; fflush(stderr); -#else -#define DEB(x) -#endif - - -// -------------------------------------------------------------------------------------- -HttpResponse::HttpResponse(const std::string& version) : HttpTransaction() -, m_http_version( version ) -, m_http_status_code(0) -, m_file( new MemFile ) -{ -} - - -// -------------------------------------------------------------------------------------- -HttpResponse::~HttpResponse() -{ - delete m_file; -} - - -// -------------------------------------------------------------------------------------- -void HttpResponse::SetHttpVersion(const std::string& value) -{ - m_http_version = value; -} - - -// -------------------------------------------------------------------------------------- -const std::string& HttpResponse::HttpVersion() const -{ - return m_http_version; -} - - - -// -------------------------------------------------------------------------------------- -void HttpResponse::SetHttpStatusCode(int value) -{ - m_http_status_code = value; -} - - -int HttpResponse::HttpStatusCode() const -{ - return m_http_status_code; -} - - - -// -------------------------------------------------------------------------------------- -void HttpResponse::SetHttpStatusMsg(const std::string& value) -{ - m_http_status_msg = value; -} - - -const std::string& HttpResponse::HttpStatusMsg() const -{ - return m_http_status_msg; -} - - -// -------------------------------------------------------------------------------------- -void HttpResponse::SetCookie(const std::string& value) -{ - Parse pa(value, "="); - std::string name = pa.getword(); - m_cookie[Utility::ToLower(name)] = value; -DEB(fprintf(stderr, "HttpResponse::Set-Cookie<%s>: %s\n", name.c_str(), value.c_str());) -} - - -const std::string HttpResponse::Cookie(const std::string& name) const -{ - std::map::const_iterator it = m_cookie.find(name); -DEB(fprintf(stderr, "HttpResponse; get value of Cookie<%s>: ", name.c_str());) - if (it != m_cookie.end()) - { -DEB(fprintf(stderr, "%s\n", it -> second.c_str());) - return it -> second; - } -DEB(fprintf(stderr, "\n");) - return ""; -} - - -std::list HttpResponse::CookieNames() const -{ - std::list vec; - DEB(fprintf(stderr, "HttpResponse::CookieNames; ");) - for (std::map::const_iterator it = m_cookie.begin(); it != m_cookie.end(); it++) - { - DEB(fprintf(stderr, " %s", it -> first.c_str());) - vec.push_back(it -> first); - } - DEB(fprintf(stderr, "\n");) - return vec; -} - - - -// -------------------------------------------------------------------------------------- -void HttpResponse::Write( const std::string& str ) -{ - Write( str.c_str(), str.size() ); -} - - -// -------------------------------------------------------------------------------------- -void HttpResponse::Write( const char *buf, size_t sz ) -{ - m_file -> fwrite( buf, 1, sz ); -} - - -// -------------------------------------------------------------------------------------- -void HttpResponse::Writef( const char *format, ... ) -{ - va_list ap; - va_start(ap, format); - char tmp[10000]; - vsprintf(tmp, format, ap); - va_end(ap); - m_file -> fwrite( tmp, 1, strlen(tmp) ); -} - - -// -------------------------------------------------------------------------------------- -void HttpResponse::SetFile( const std::string& path ) -{ - delete m_file; - m_file = new File(); - m_file -> fopen( path, "rb" ); -} - - -// -------------------------------------------------------------------------------------- -void HttpResponse::Reset() -{ - HttpTransaction::Reset(); - m_http_version = ""; - m_http_status_code = 0; - m_http_status_msg = ""; - while (!m_cookie.empty()) - { - m_cookie.erase(m_cookie.begin()); - } - if (m_file) - { - delete m_file; - m_file = new MemFile; - } -} - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - diff --git a/Sockets/HttpResponse.h b/Sockets/HttpResponse.h deleted file mode 100644 index 089ff1d..0000000 --- a/Sockets/HttpResponse.h +++ /dev/null @@ -1,82 +0,0 @@ -/** - ** \file HttpResponse.h - ** \date 2007-10-05 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_HttpResponse_H -#define _SOCKETS_HttpResponse_H - -#include "HttpTransaction.h" -#include - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -class IFile; - -class HttpResponse : public HttpTransaction -{ -public: - HttpResponse(const std::string& version = "HTTP/1.0"); - ~HttpResponse(); - - /** HTTP/1.x */ - void SetHttpVersion(const std::string& value); - const std::string& HttpVersion() const; - - void SetHttpStatusCode(int value); - int HttpStatusCode() const; - - void SetHttpStatusMsg(const std::string& value); - const std::string& HttpStatusMsg() const; - - void SetCookie(const std::string& value); - const std::string Cookie(const std::string& name) const; - std::list CookieNames() const; - - void Write( const std::string& str ); - void Write( const char *buf, size_t sz ); - void Writef( const char *format, ... ); - - const IFile& GetFile() const { return *m_file; } - - /** Replace memfile with file on disk, opened for read. */ - void SetFile( const std::string& path ); - - void Reset(); - -private: - std::string m_http_version; - int m_http_status_code; - std::string m_http_status_msg; - std::map m_cookie; - IFile *m_file; - -}; // end of class - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - -#endif // _SOCKETS_HttpResponse_H - diff --git a/Sockets/HttpTransaction.cpp b/Sockets/HttpTransaction.cpp deleted file mode 100644 index 8221d1f..0000000 --- a/Sockets/HttpTransaction.cpp +++ /dev/null @@ -1,244 +0,0 @@ -/** - ** \file HttpTransaction.cpp - ** \date 2007-10-05 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif -#include "HttpTransaction.h" -#include "Utility.h" -#include "Parse.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -// -------------------------------------------------------------------------------------- -HttpTransaction::HttpTransaction() -{ -} - - -// -------------------------------------------------------------------------------------- -HttpTransaction::~HttpTransaction() -{ -} - - -// -------------------------------------------------------------------------------------- -void HttpTransaction::SetHeader(const std::string& key, const std::string& value) -{ - m_header[Utility::ToLower(key)] = value; -} - - -void HttpTransaction::SetHeader(const std::string& key, long value) -{ - m_header[Utility::ToLower(key)] = Utility::l2string(value); -} - - -const std::string& HttpTransaction::Header(const std::string& key) const -{ - std::map::const_iterator it; - if ((it = m_header.find(Utility::ToLower(key))) != m_header.end()) - return it -> second; - return m_null; -} - - - -// -------------------------------------------------------------------------------------- -void HttpTransaction::SetAccept(const std::string& value) -{ - SetHeader("accept", value); -} - - -const std::string& HttpTransaction::Accept() const -{ - return Header("accept"); -} - - - -// -------------------------------------------------------------------------------------- -void HttpTransaction::SetAcceptCharset(const std::string& value) -{ - SetHeader("accept-charset", value); -} - - -const std::string& HttpTransaction::AcceptCharset() const -{ - return Header("accept-charset"); -} - - - -// -------------------------------------------------------------------------------------- -void HttpTransaction::SetAcceptEncoding(const std::string& value) -{ - SetHeader("accept-encoding", value); -} - - -const std::string& HttpTransaction::AcceptEncoding() const -{ - return Header("accept-encoding"); -} - - - -// -------------------------------------------------------------------------------------- -void HttpTransaction::SetAcceptLanguage(const std::string& value) -{ - SetHeader("accept-language", value); -} - - -const std::string& HttpTransaction::AcceptLanguage() const -{ - return Header("accept-language"); -} - - - -// -------------------------------------------------------------------------------------- -void HttpTransaction::SetConnection(const std::string& value) -{ - SetHeader("connection", value); -} - - -const std::string& HttpTransaction::Connection() const -{ - return Header("connection"); -} - - - -// -------------------------------------------------------------------------------------- -void HttpTransaction::SetContentType(const std::string& value) -{ - SetHeader("content-type", value); -} - - -const std::string& HttpTransaction::ContentType() const -{ - return Header("content-type"); -} - - - -// -------------------------------------------------------------------------------------- -void HttpTransaction::SetContentLength(long value) -{ - SetHeader("content-length", value ); -} - - -long HttpTransaction::ContentLength() const -{ - return atol(Header("content-length").c_str()); -} - - - -// -------------------------------------------------------------------------------------- -void HttpTransaction::SetHost(const std::string& value) -{ - SetHeader("host", value); -} - - -const std::string& HttpTransaction::Host() const -{ - return Header("host"); -} - - - -// -------------------------------------------------------------------------------------- -void HttpTransaction::SetPragma(const std::string& value) -{ - SetHeader("pragma", value); -} - - -const std::string& HttpTransaction::Pragma() const -{ - return Header("pragma"); -} - - - -// -------------------------------------------------------------------------------------- -void HttpTransaction::SetReferer(const std::string& value) -{ - SetHeader("referer", value); -} - - -const std::string& HttpTransaction::Referer() const -{ - return Header("referer"); -} - - - -// -------------------------------------------------------------------------------------- -void HttpTransaction::SetUserAgent(const std::string& value) -{ - SetHeader("user-agent", value); -} - - -const std::string& HttpTransaction::UserAgent() const -{ - return Header("user-agent"); -} - - -// -------------------------------------------------------------------------------------- -const std::map& HttpTransaction::Headers() const -{ - return m_header; -} - - -// -------------------------------------------------------------------------------------- -void HttpTransaction::Reset() -{ - while (!m_header.empty()) - { - m_header.erase(m_header.begin()); - } -} - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - - diff --git a/Sockets/HttpTransaction.h b/Sockets/HttpTransaction.h deleted file mode 100644 index a92fdda..0000000 --- a/Sockets/HttpTransaction.h +++ /dev/null @@ -1,94 +0,0 @@ -/** - ** \file HttpTransaction.h - ** \date 2007-10-05 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_HttpTransaction_H -#define _SOCKETS_HttpTransaction_H - -#include -#include - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -class HttpTransaction -{ -public: - HttpTransaction(); - virtual ~HttpTransaction(); - - /** Set / Read http header value */ - void SetHeader(const std::string& key, const std::string& value); - void SetHeader(const std::string& key, long value); - const std::string& Header(const std::string& key) const; - - void SetAccept(const std::string& value); - const std::string& Accept() const; - - void SetAcceptCharset(const std::string& value); - const std::string& AcceptCharset() const; - - void SetAcceptEncoding(const std::string& value); - const std::string& AcceptEncoding() const; - - void SetAcceptLanguage(const std::string& value); - const std::string& AcceptLanguage() const; - - void SetConnection(const std::string& value); - const std::string& Connection() const; - - void SetContentType(const std::string& value); - const std::string& ContentType() const; - - void SetContentLength(long value); - long ContentLength() const; - - void SetHost(const std::string& value); - const std::string& Host() const; - - void SetPragma(const std::string& value); - const std::string& Pragma() const; - - void SetReferer(const std::string& value); - const std::string& Referer() const; - - void SetUserAgent(const std::string& value); - const std::string& UserAgent() const; - - const std::map& Headers() const; - - virtual void Reset(); - -private: - std::map m_header; - std::string m_null; - -}; // end of class - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - -#endif // _SOCKETS_HttpTransaction_H - diff --git a/Sockets/HttpdCookies.cpp b/Sockets/HttpdCookies.cpp deleted file mode 100644 index 9662f0d..0000000 --- a/Sockets/HttpdCookies.cpp +++ /dev/null @@ -1,270 +0,0 @@ -/** \file HttpdCookies.cpp -*/ -/* -Copyright (C) 2003-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif -#include "Parse.h" -#include "Utility.h" -#include "HTTPSocket.h" -#include "HttpdCookies.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -#ifdef _DEBUG -#define DEB(x) x; fflush(stderr); -#else -#define DEB(x) -#endif - - -HttpdCookies::HttpdCookies() -{ -} - -HttpdCookies::HttpdCookies(const std::string& s) -{ - Parse *pa = new Parse(s,";"); - - std::string slask = pa -> getword(); - while (slask.size()) - { - Parse *pa2 = new Parse(slask,"="); - std::string name = pa2 -> getword(); - std::string value = pa2 -> getword(); - delete pa2; - m_cookies.push_back(std::pair(name, value)); - // - slask = pa -> getword(); - } - delete pa; -} - -void HttpdCookies::add(const std::string& s) -{ - Parse *pa = new Parse(s,";"); -DEB(fprintf(stderr, "Parse cookie: %s\n", s.c_str());) - std::string slask = pa -> getword(); - while (slask.size()) - { - Parse *pa2 = new Parse(slask,"="); - std::string name = pa2 -> getword(); - std::string value = pa2 -> getword(); - delete pa2; - m_cookies.push_back(std::pair(name, value)); - // - slask = pa -> getword(); - } - delete pa; -} - -HttpdCookies::~HttpdCookies() -{ -} - -bool HttpdCookies::getvalue(const std::string& name,std::string& buffer) const -{ - for (cookie_v::const_iterator it = m_cookies.begin(); it != m_cookies.end(); it++) - { - const std::pair& ref = *it; - if (!strcasecmp(ref.first.c_str(),name.c_str())) - { - buffer = ref.second; - return true; - } - } - buffer = ""; - return false; -} - -void HttpdCookies::replacevalue(const std::string& name,const std::string& value) -{ - for (cookie_v::iterator it = m_cookies.begin(); it != m_cookies.end(); it++) - { - std::pair& ref = *it; - if (!strcasecmp(ref.first.c_str(),name.c_str())) - { - ref.second = value; - return; - } - } - m_cookies.push_back(std::pair(name, value)); - -} - -void HttpdCookies::replacevalue(const std::string& name,long l) -{ - replacevalue(name, Utility::l2string(l)); -} - -void HttpdCookies::replacevalue(const std::string& name,int i) -{ - replacevalue(name, Utility::l2string(i)); -} - -size_t HttpdCookies::getlength(const std::string& name) const -{ - for (cookie_v::const_iterator it = m_cookies.begin(); it != m_cookies.end(); it++) - { - const std::pair& ref = *it; - if (!strcasecmp(ref.first.c_str(),name.c_str())) - { - return ref.second.size(); - } - } - return 0; -} - -void HttpdCookies::setcookie(HTTPSocket *sock, const std::string& domain, const std::string& path, const std::string& name, const std::string& value) -{ - char *str = new char[name.size() + value.size() + domain.size() + path.size() + 100]; - - // set-cookie response - if (domain.size()) - { - sprintf(str, "%s=%s; domain=%s; path=%s; expires=%s", - name.c_str(), value.c_str(), - domain.c_str(), - path.c_str(), - expiredatetime().c_str()); - } - else - { - sprintf(str, "%s=%s; path=%s; expires=%s", - name.c_str(), value.c_str(), - path.c_str(), - expiredatetime().c_str()); - } - sock -> AddResponseHeader("Set-cookie", str); - delete[] str; - - replacevalue(name, value); -} - -void HttpdCookies::setcookie(HTTPSocket *sock, const std::string& domain, const std::string& path, const std::string& name, long value) -{ - char *str = new char[name.size() + domain.size() + path.size() + 100]; - char dt[80]; - - // set-cookie response - if (domain.size()) - { - sprintf(str, "%s=%ld; domain=%s; path=%s; expires=%s", - name.c_str(), value, - domain.c_str(), - path.c_str(), - expiredatetime().c_str()); - } - else - { - sprintf(str, "%s=%ld; path=%s; expires=%s", - name.c_str(), value, - path.c_str(), - expiredatetime().c_str()); - } - sock -> AddResponseHeader("Set-cookie", str); - delete[] str; - - sprintf(dt, "%ld", value); - replacevalue(name, dt); -} - -void HttpdCookies::setcookie(HTTPSocket *sock, const std::string& domain, const std::string& path, const std::string& name, int value) -{ - char *str = new char[name.size() + domain.size() + path.size() + 100]; - char dt[80]; - - // set-cookie response - if (domain.size()) - { - sprintf(str, "%s=%d; domain=%s; path=%s; expires=%s", - name.c_str(), value, - domain.c_str(), - path.c_str(), - expiredatetime().c_str()); - } - else - { - sprintf(str, "%s=%d; path=%s; expires=%s", - name.c_str(), value, - path.c_str(), - expiredatetime().c_str()); - } - sock -> AddResponseHeader("Set-cookie", str); - delete[] str; - - sprintf(dt, "%d", value); - replacevalue(name, dt); -} - - -const std::string& HttpdCookies::expiredatetime() const -{ - time_t t = time(NULL); - struct tm tp; -#ifdef _WIN32 - memcpy(&tp, gmtime(&t), sizeof(tp)); -#else - gmtime_r(&t, &tp); -#endif - const char *days[7] = {"Sunday", "Monday", - "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; - const char *months[12] = {"Jan", "Feb", "Mar", "Apr", "May", - "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - char dt[100]; - - sprintf(dt, "%s, %02d-%s-%04d %02d:%02d:%02d GMT", - days[tp.tm_wday], - tp.tm_mday, - months[tp.tm_mon], - tp.tm_year + 1910, - tp.tm_hour, - tp.tm_min, - tp.tm_sec); - m_date = dt; - return m_date; -} - - -void HttpdCookies::Reset() -{ - while (!m_cookies.empty()) - { - m_cookies.erase(m_cookies.begin()); - } - m_date = ""; -} - - -#ifdef SOCKETS_NAMESPACE -} -#endif - - diff --git a/Sockets/HttpdCookies.h b/Sockets/HttpdCookies.h deleted file mode 100644 index 79af17c..0000000 --- a/Sockets/HttpdCookies.h +++ /dev/null @@ -1,89 +0,0 @@ -/** \file HttpdCookies.h -*/ -/* -Copyright (C) 2003-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#ifndef _SOCKETS_HttpdCookies_H -#define _SOCKETS_HttpdCookies_H - -#include "sockets-config.h" -#include -#include - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -//! Store the cookies name/value pairs. - - - -//! Retrieve and manage cookies during a cgi call. -class HTTPSocket; - -/** HTTP Cookie parse/container class. -\sa HttpdSocket -\sa HttpdForm -\ingroup webserver */ -class HttpdCookies -{ - /** list of key/value structs. */ - typedef std::list > cookie_v; - -public: - HttpdCookies(); - HttpdCookies(const std::string& query_string); - ~HttpdCookies(); - - void add(const std::string& s); - - bool getvalue(const std::string&,std::string&) const; - void replacevalue(const std::string& ,const std::string& ); - void replacevalue(const std::string& ,long); - void replacevalue(const std::string& ,int); - size_t getlength(const std::string& ) const; - void setcookie(HTTPSocket *,const std::string& d,const std::string& p,const std::string& c,const std::string& v); - void setcookie(HTTPSocket *,const std::string& d,const std::string& p,const std::string& c,long v); - void setcookie(HTTPSocket *,const std::string& d,const std::string& p,const std::string& c,int v); - const std::string& expiredatetime() const; - - cookie_v& GetHttpdCookies() { return m_cookies; } - - void Reset(); - -private: - cookie_v m_cookies; - mutable std::string m_date; -}; - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_HttpdCookies_H - diff --git a/Sockets/HttpdForm.cpp b/Sockets/HttpdForm.cpp deleted file mode 100644 index 1b1f689..0000000 --- a/Sockets/HttpdForm.cpp +++ /dev/null @@ -1,616 +0,0 @@ -/** \file HttpdForm.cpp - read stdin, parse cgi input - ** - ** Written: 1999-Feb-10 grymse@alhem.net - **/ - -/* -Copyright (C) 1999-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif -#include "socket_include.h" -#include "Parse.h" -#include "IFile.h" -#include "HttpdForm.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -#define TMPSIZE 10000 - - -HttpdForm::HttpdForm(IFile *infil, const std::string& content_type, size_t content_length) : raw(false) -{ - CGI *cgi = NULL; - size_t extra = 2; - char name[TMPSIZE]; - - m_current = m_cgi.end(); - *name = 0; - - if (content_type.size() >= 19 && content_type.substr(0, 19) == "multipart/form-data") - { - Parse pa(content_type,";="); - char *tempcmp = NULL; - size_t tc = 0; - size_t l = 0; - std::string str = pa.getword(); - m_strBoundary = ""; - while (str.size()) - { - if (!strcmp(str.c_str(),"boundary")) - { - m_strBoundary = pa.getword(); - l = m_strBoundary.size(); - tempcmp = new char[l + extra]; - } - // - str = pa.getword(); - } - if (m_strBoundary.size()) - { - std::string content_type; - std::string current_name; - std::string current_filename; - char *slask = new char[TMPSIZE]; - infil -> fgets(slask, TMPSIZE); - while (!infil -> eof()) - { - while (strlen(slask) && (slask[strlen(slask) - 1] == 13 || slask[strlen(slask) - 1] == 10)) - { - slask[strlen(slask) - 1] = 0; - } - content_type = ""; - current_name = ""; - current_filename = ""; - if ((strstr(slask,m_strBoundary.c_str()) || strstr(m_strBoundary.c_str(),slask)) && strcmp(slask, m_strBoundary.c_str())) - { - m_strBoundary = slask; - l = m_strBoundary.size(); - delete[] tempcmp; - tempcmp = new char[l + extra]; - } - if (!strcmp(slask, m_strBoundary.c_str())) - { - // Get headers until empty line - infil -> fgets(slask, TMPSIZE); - while (strlen(slask) && (slask[strlen(slask) - 1] == 13 || slask[strlen(slask) - 1] == 10)) - { - slask[strlen(slask) - 1] = 0; - } - while (!infil -> eof() && *slask) - { - Parse pa(slask,";"); - std::string h = pa.getword(); - if (!strcasecmp(h.c_str(),"Content-type:")) - { - content_type = pa.getword(); - } - else - if (!strcasecmp(h.c_str(),"Content-Disposition:")) - { - h = pa.getword(); - if (!strcmp(h.c_str(),"form-data")) - { - pa.EnableQuote(true); - h = pa.getword(); - while (h.size()) - { - Parse pa2(slask,"="); - std::string name = pa2.getword(); - std::string h = pa2.getrest(); - if (!strcmp(name.c_str(),"name")) - { - if (h.size() && h[0] == '"') - { - current_name = h.substr(1, h.size() - 2); - } - else - { - current_name = h; - } - } - else - if (!strcmp(name.c_str(),"filename")) - { - if (h.size() && h[0] == '"') - { - current_filename = h.substr(1, h.size() - 2); - } - else - { - current_filename = h; - } - size_t x = 0; - for (size_t i = 0; i < current_filename.size(); i++) - { - if (current_filename[i] == '/' || current_filename[i] == '\\') - x = i + 1; - } - if (x) - { - current_filename = current_filename.substr(x); - } - } - h = pa.getword(); - } - } - } - // get next header value - infil -> fgets(slask, TMPSIZE); - while (strlen(slask) && (slask[strlen(slask) - 1] == 13 || slask[strlen(slask) - 1] == 10)) - { - slask[strlen(slask) - 1] = 0; - } - } - // Read content, save...? - if (!current_filename.size()) // not a file - { - std::string val; - infil -> fgets(slask, TMPSIZE); - while (!infil -> eof() && strncmp(slask,m_strBoundary.c_str(),m_strBoundary.size() )) - { - val += slask; - infil -> fgets(slask, TMPSIZE); - } - // remove trailing cr/linefeed - while (val.size() && (val[val.size() - 1] == 13 || val[val.size() - 1] == 10)) - { - val = val.substr(0,val.size() - 1); - } - cgi = new CGI(current_name, val); - m_cgi.push_back(cgi); - } - else // current_filename.size() > 0 - { - // read until m_strBoundary... - FILE *fil; - int out = 0; - char c; - char fn[2000]; // where post'd file will be saved -#ifdef _WIN32 - { - char tmp_path[2000]; - ::GetTempPathA(2000, tmp_path); - if (tmp_path[strlen(tmp_path) - 1] != '\\') - { - strcat(tmp_path, "\\"); - } - sprintf(fn,"%s%s",tmp_path,current_filename.c_str()); - } -#else - sprintf(fn,"/tmp/%s",current_filename.c_str()); -#endif - if ((fil = fopen(fn, "wb")) != NULL) - { - infil -> fread(&c,1,1); - while (!infil -> eof()) - { - if (out) - { - fwrite(&tempcmp[tc],1,1,fil); - } - tempcmp[tc] = c; - tc++; - if (tc >= l + extra) - { - tc = 0; - out = 1; - } - if (tc) - { - if (!strncmp(tempcmp + tc + extra, m_strBoundary.c_str(), l - tc) && - !strncmp(tempcmp, m_strBoundary.c_str() + l - tc, tc)) - { - break; - } - } - else - { - if (!strncmp(tempcmp + extra, m_strBoundary.c_str(), l)) - { - break; - } - } - infil -> fread(&c,1,1); - } - fclose(fil); - - cgi = new CGI(current_name,fn,fn); - m_cgi.push_back(cgi); - - strcpy(slask, m_strBoundary.c_str()); - infil -> fgets(slask + strlen(slask), TMPSIZE); // next line - } - else - { - // couldn't open file - break; - } - } - } - else - { - // Probably '--' - break; - } - } // while (!infil -> eof()) - delete[] slask; - } // if (m_strBoundary) - if (tempcmp) - { - delete[] tempcmp; - } - } - else - if (strstr(content_type.c_str(), "x-www-form-urlencoded")) - { - bool got_name = false; // tnx to FatherNitwit - int i = 0; - int cl = (int)content_length; - char c,chigh,clow; - char *slask = new char[TMPSIZE]; - m_current = m_cgi.end(); - - *name = 0; - - infil -> fread(&c,1,1); - cl--; - while (cl >= 0 && !infil -> eof()) - { - switch (c) - { - case '=': /* end of name */ - slask[i] = 0; - i = 0; - strcpy(name,slask); - got_name = true; - break; - case '&': /* end of value */ - slask[i] = 0; - i = 0; - if (got_name) - { - cgi = new CGI(name,slask); - got_name = false; - } - else - { - cgi = new CGI(slask, ""); - } - m_cgi.push_back(cgi); - break; - case '+': /* space */ - slask[i++] = ' '; - break; - case '%': /* hex value */ - infil -> fread(&chigh,1,1); - cl--; - chigh -= 48 + (chigh > '9' ? 7 : 0) + (chigh >= 'a' ? 32 : 0); - infil -> fread(&clow,1,1); - cl--; - clow -= 48 + (clow > '9' ? 7 : 0) + (clow >= 'a' ? 32 : 0); - slask[i++] = (char)(chigh * 16 + clow); - break; - default: /* just another char */ - slask[i++] = c; - break; - } - // - if (cl > 0) - { - infil -> fread(&c,1,1); - } - cl--; - } - slask[i] = 0; - i = 0; - if (got_name) - { - cgi = new CGI(name,slask); - } - else - { - cgi = new CGI(slask, ""); - } - m_cgi.push_back(cgi); - delete[] slask; - } -} - - -// HttpdForm(buffer,l) -- request_method GET - -HttpdForm::HttpdForm(const std::string& buffer,size_t l) : raw(false) -{ - CGI *cgi = NULL; - char *slask = new char[TMPSIZE]; - char *name = new char[TMPSIZE]; - int i = 0; - char c,chigh,clow; - size_t ptr = 0; - bool got_name = false; - - m_current = m_cgi.end(); - - *name = 0; - - ptr = 0; - while (ptr < l) - { - c = buffer[ptr++]; - switch (c) - { - case '=': /* end of name */ - slask[i] = 0; - i = 0; - strcpy(name,slask); - got_name = true; - break; - case '&': /* end of value */ - slask[i] = 0; - i = 0; - if (got_name) - { - cgi = new CGI(name,slask); - got_name = false; - } - else - { - cgi = new CGI(slask, ""); - } - m_cgi.push_back(cgi); - break; - case '+': /* space */ - slask[i++] = ' '; - break; - case '%': /* hex value */ - chigh = buffer[ptr++]; - chigh -= 48 + (chigh > '9' ? 7 : 0) + (chigh >= 'a' ? 32 : 0); - clow = buffer[ptr++]; - clow -= 48 + (clow > '9' ? 7 : 0) + (clow >= 'a' ? 32 : 0); - slask[i++] = (char)(chigh * 16 + clow); - break; - default: /* just another char */ - slask[i++] = c; - break; - } - } - slask[i] = 0; - i = 0; - if (got_name) - { - cgi = new CGI(name,slask); - } - else - { - cgi = new CGI(slask, ""); - } - m_cgi.push_back(cgi); - delete[] slask; - delete[] name; -} - - -HttpdForm::~HttpdForm() -{ - CGI *cgi = NULL; //,*tmp; - - for (cgi_v::iterator it = m_cgi.begin(); it != m_cgi.end(); it++) - { - cgi = *it; - delete cgi; - } -} - - -void HttpdForm::EnableRaw(bool b) -{ - raw = b; -} - - -void HttpdForm::strcpyval(std::string& v,const char *value) const -{ - v = ""; - for (size_t i = 0; i < strlen(value); i++) - { - if (value[i] == '<') - { - v += "<"; - } - else - if (value[i] == '>') - { - v += ">"; - } - else - if (value[i] == '&') - { - v += "&"; - } - else - { - v += value[i]; - } - } -} - - -bool HttpdForm::getfirst(std::string& n) const -{ - m_current = m_cgi.begin(); - return getnext(n); -} - - -bool HttpdForm::getnext(std::string& n) const -{ - if (m_current != m_cgi.end() ) - { - CGI *current = *m_current; - n = current -> name; - m_current++; - return true; - } - else - { - n = ""; - } - return false; -} - - -bool HttpdForm::getfirst(std::string& n,std::string& v) const -{ - m_current = m_cgi.begin(); - return getnext(n,v); -} - - -bool HttpdForm::getnext(std::string& n,std::string& v) const -{ - if (m_current != m_cgi.end() ) - { - CGI *current = *m_current; - n = current -> name; - if (raw) - { - v = current -> value; - } - else - { - strcpyval(v,current -> value.c_str()); - } - m_current++; - return true; - } - else - { - n = ""; - } - return false; -} - - -int HttpdForm::getvalue(const std::string& n,std::string& v) const -{ - CGI *cgi = NULL; - int r = 0; - - for (cgi_v::const_iterator it = m_cgi.begin(); it != m_cgi.end(); it++) - { - cgi = *it; - if (cgi -> name == n) - break; - cgi = NULL; - } - if (cgi) - { - if (raw) - { - v = cgi -> value; - } - else - { - strcpyval(v,cgi -> value.c_str()); - } - r++; - } - else - { - v = ""; - } - - return r; -} - - -std::string HttpdForm::getvalue(const std::string& n) const -{ - for (cgi_v::const_iterator it = m_cgi.begin(); it != m_cgi.end(); it++) - { - CGI *cgi = *it; - if (cgi -> name == n) - { - return cgi -> value; - } - } - return ""; -} - - -size_t HttpdForm::getlength(const std::string& n) const -{ - CGI *cgi = NULL; - size_t l; - - for (cgi_v::const_iterator it = m_cgi.begin(); it != m_cgi.end(); it++) - { - cgi = *it; - if (cgi -> name == n) - break; - cgi = NULL; - } - l = cgi ? cgi -> value.size() : 0; - if (cgi && !raw) - { - for (size_t i = 0; i < cgi -> value.size(); i++) - { - switch (cgi -> value[i]) - { - case '<': // < - case '>': // > - l += 4; - break; - case '&': // & - l += 5; - break; - } - } - } - return l; -} - - -HttpdForm::cgi_v& HttpdForm::getbase() -{ - return m_cgi; -} - - -const std::string& HttpdForm::GetBoundary() const -{ - return m_strBoundary; -} - - -#ifdef SOCKETS_NAMESPACE -} -#endif - - diff --git a/Sockets/HttpdForm.h b/Sockets/HttpdForm.h deleted file mode 100644 index 962a753..0000000 --- a/Sockets/HttpdForm.h +++ /dev/null @@ -1,118 +0,0 @@ -/** \file HttpdForm.h - read stdin, parse cgi input - ** - ** Written: 1999-Feb-10 grymse@alhem.net - **/ - -/* -Copyright (C) 1999-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#ifndef _SOCKETS_HttpdForm_H -#define _SOCKETS_HttpdForm_H - -#include "sockets-config.h" -#include -#include - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -class IFile; - -/** Parse/store a http query_string/form-data body. - \ingroup webserver */ -class HttpdForm -{ - /** - * Store the name/value pairs from a GET/POST operation. - * "name" does not have to be unique. - \ingroup webserver - */ - struct CGI - { - CGI(const std::string& n,const std::string& v) : name(n),value(v) {} - CGI(const std::string& n,const std::string& v,const std::string& p) : name(n),value(v),path(p) {} - std::string name; - std::string value; - std::string path; - }; - /** list of key/value pairs. */ - typedef std::list cgi_v; - -public: - /** - * Default constructor (used in POST operations). - * Input is read from stdin. Number of characters to read - * can be found in the environment variable CONTENT_LENGTH. - */ - HttpdForm(IFile *, const std::string& content_type, size_t content_length); - /** - * Another constructor (used in GET operations). - * Input is read from the environment variable QUERY_STRING. - * @param query_string The httpd server provided QUERY_STRING - * @param length Query string length. - */ - HttpdForm(const std::string& query_string,size_t length); - ~HttpdForm(); - - void EnableRaw(bool); - - /** Encode characters '<' '>' '&' as < > & */ - void strcpyval(std::string&,const char *) const; - - /* get names */ - bool getfirst(std::string& n) const; - bool getnext(std::string& n) const; - - /* get names and values */ - bool getfirst(std::string& n,std::string& v) const; - bool getnext(std::string& n,std::string& v) const; - - /* get value */ - int getvalue(const std::string& ,std::string& ) const; - std::string getvalue(const std::string& ) const; - size_t getlength(const std::string& ) const; - cgi_v& getbase(); - - const std::string& GetBoundary() const; - -private: - HttpdForm(const HttpdForm& ) {} - HttpdForm& operator=(const HttpdForm& ) { return *this; } - cgi_v m_cgi; - mutable cgi_v::const_iterator m_current; - std::string m_strBoundary; - bool raw; -}; - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_HttpdForm_H - diff --git a/Sockets/HttpdSocket.cpp b/Sockets/HttpdSocket.cpp deleted file mode 100644 index 777dd07..0000000 --- a/Sockets/HttpdSocket.cpp +++ /dev/null @@ -1,528 +0,0 @@ -/** \file HttpdSocket.cpp -*/ -/* -Copyright (C) 2001-2007 Anders Hedstrom (grymse@alhem.net) - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif -#include "Utility.h" -#include "HttpdCookies.h" -#include "HttpdForm.h" -#include "MemFile.h" -#include "HttpdSocket.h" -#include "Base64.h" - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -#define TMPSIZE 10000 - - -// statics -int HttpdSocket::m_request_count = 0; -std::string HttpdSocket::m_start = ""; - - -HttpdSocket::HttpdSocket(ISocketHandler& h) -:HTTPSocket(h) -,m_content_length(0) -,m_file(NULL) -,m_received(0) -,m_request_id(++m_request_count) -,m_cookies(NULL) -,m_form(NULL) -{ - m_http_date = datetime2httpdate(GetDate()); - if (!m_start.size()) - m_start = m_http_date; -} - - -HttpdSocket::~HttpdSocket() -{ - if (m_file) - { - delete m_file; - } - if (m_cookies) - delete m_cookies; - if (m_form) - delete m_form; -} - - -void HttpdSocket::OnFirst() -{ -} - - -void HttpdSocket::OnHeader(const std::string& key,const std::string& value) -{ - if (!strcasecmp(key.c_str(),"content-length")) - { - m_content_length = atoi(value.c_str()); - m_content_length_str = value; - } - else - if (!strcasecmp(key.c_str(),"cookie")) - { - m_http_cookie = value; - } - else - if (!strcasecmp(key.c_str(),"content-type")) - { - m_content_type = value; - } - else - if (!strcasecmp(key.c_str(),"if-modified-since")) - { - m_if_modified_since = value; - } -} - - -void HttpdSocket::OnHeaderComplete() -{ - m_cookies = new HttpdCookies(m_http_cookie); - - if (GetMethod() == "GET") - { - Utility::SetEnv("QUERY_STRING", GetQueryString()); - } - Utility::SetEnv("REQUEST_METHOD", GetMethod()); - Utility::SetEnv("HTTP_COOKIE", m_http_cookie); - Utility::SetEnv("CONTENT_TYPE", m_content_type); - Utility::SetEnv("CONTENT_LENGTH", m_content_length_str); -/* -#if (defined(SOLARIS8) || defined(SOLARIS)) - { - char slask[TMPSIZE]; - if (GetMethod() == "GET") - { - sprintf(slask,"QUERY_STRING=%s", GetQueryString().c_str()); - putenv(slask); - } - sprintf(slask,"REQUEST_METHOD=%s", GetMethod().c_str()); - putenv(slask); - sprintf(slask,"HTTP_COOKIE=%s", m_http_cookie.c_str()); - putenv(slask); - sprintf(slask,"CONTENT_TYPE=%s", m_content_type.c_str()); - putenv(slask); - sprintf(slask,"CONTENT_LENGTH=%s", m_content_length_str.c_str()); - putenv(slask); - } -#elif defined _WIN32 - { - char slask[TMPSIZE]; - if (GetMethod() == "GET") - { - sprintf(slask,"QUERY_STRING=%s", GetQueryString().c_str()); - _putenv(slask); - } - sprintf(slask,"REQUEST_METHOD=%s", GetMethod().c_str()); - _putenv(slask); - sprintf(slask,"HTTP_COOKIE=%s", m_http_cookie.c_str()); - _putenv(slask); - sprintf(slask,"CONTENT_TYPE=%s", m_content_type.c_str()); - _putenv(slask); - sprintf(slask,"CONTENT_LENGTH=%s", m_content_length_str.c_str()); - _putenv(slask); - } -#else - if (GetMethod() == "GET") - { - setenv("QUERY_STRING", GetQueryString().c_str(), 1); - } - setenv("REQUEST_METHOD", GetMethod().c_str(), 1); - setenv("HTTP_COOKIE", m_http_cookie.c_str(), 1); - setenv("CONTENT_TYPE", m_content_type.c_str(), 1); - setenv("CONTENT_LENGTH", m_content_length_str.c_str(), 1); -#endif -*/ - if (GetMethod() == "POST") - { - m_file = new MemFile; - } - else - if (GetMethod() == "GET") - { - m_form = new HttpdForm(GetQueryString(), GetQueryString().size() ); - AddResponseHeader("Date", datetime2httpdate(GetDate()) ); - if (GetUri() == "/image") - { - std::string str64 = -"iVBORw0KGgoAAAANSUhEUgAAAGAAAABeCAIAAABTioayAAAACXBIWXMAAABkAAAAZAAPlsXdAAAAUHRF" -"WHRSYXcgcHJvZmlsZSB0eXBlIEFQUDEyAApnZW5lcmljIHByb2ZpbGUKICAgICAgMTUKNDQ3NTYzNmI3" -"OTAwMDEwMDA0MDAwMDAwM2MwMDAwCg2F1B0AABb4SURBVHja7Xx7rGVXed/3WGs/zvPeuTPXMzbjcUpq" -"HAwlpQlYoUlDaJsAiVuFFKSKGlUlKgXqIKJAKxfRR4IUZEpSt1FoQEK4oYQEErlSFAoKIEoo2BQasBmc" -"2NjyYzxz5957Hnufvfd6fF//2Oecez2hvbXvmZkg3U9b556Zc85ea//291rf+n0bVRWO5P8udLUn8Jdd" -"jgA6QI4AOkCOADpAjgA6QI4AOkCOADpAjgA6QI4AOkCOADpAjgA6QI4AOkCOADpAjgA6QMxVHHtfoUWx" -"/dP+C5fvABGv4gwBAK9qPWg5NLbvrjIY302ujgapAmKrQQiqC3xAQQF0H1AIcyXSq4XeZdegfedfWs78" -"jYKAAgDi3sVri4mqzH+D9DSTu+I2dyVNTEFRl34GUTUikiqotrgoAqqIAhBxqzj7ZocAighXWJUuI0Cq" -"injJ+SMAIZKolkXlGrOzM61mjfckCoN+X9UjorU26wgb7HTSPAfDRlVVFQAR21NeOT26XAC1p10CpKoI" -"iKTO+ckkFpO4vVX1Bh3kkKRsDCIBE4sIMRNx8FTPYgwQfJ1k4ZpT3W4nAQBVQaSF/1pcw+VE63JrEKiC" -"KhChC83Fi6EYEyp2uzxYN4kFY6H1O63TIUQAiCIIEgK5Rke7zWhUE2a9AR+/JunmpIr7of/eA2hhWREA" -"QUlBkGg8af7s7E4n75+6Lu/2iBkUAgJLhP2+RkSJsNU5ACUCQCAyxTQ88eS0rt1gSGdOD621Ik8zs8uH" -"0eUCSDSqCDHGUD/2mCvLXpbWp051bEqqGoIAINHeVRHRJTMREQBEACQEUDa0vT07/2QZvbvxphO9vhGh" -"1m0j0uVzSysGaOF6QASJQvD4yKN1UeiZ053eULzX4FsspB221RdVZWYARaTFaeYXjIgiqqpEag16jw9+" -"e3daTH/gBevHjw1EoIXle0ODdJH/KQiCxiiPPOLrWX7taeh1o3ek8wQH26jUao1qa1ZPy6VbgNovtIAi" -"gCoZK17l3GPNdFLf8H2djY1cRAlJUfHyhP+VAbQM6gsPAt/404uzypw509vYoMYhKCHOQxsAiAohaqtL" -"OhdEUlAm8iEQEgAQIRHHGJGQkBSAjILyhXNaN9VzTuOgn6jOl9yXQ49WvJpXEFUhoAcf2t7apn7f5p04" -"K9XVXkVcE4IXiSoRUEkFVYiAEZnZMltmoxFUKAYFJRWQiK4JwUfvoncxBnUNKMTBMUVKzj2OdSNzXC6P" -"ka1mLbZMdkCQSbZ36q3z2Oma4yesAipwEI8iLkTD4GNEBGZGAEJSBUBQ0RAcqLBJBdRYC0gxKKqKqgrE" -"4FUFgNAY7xFAOx0a79KTT4bvu4FVlYAUFRVgpXp0WID2W6gqIMXGyeOPN73ORm8QrcUQRFUUTNNEAIyt" -"CxJ1PmQ2H093vvr1L0rUm5//N+5/4N7g4o/92Cs7/R6AiAIxi4AKsOGvf/3Ljz/x0F974S2nr7/RNd5a" -"MqSj8e60JMPl9ddvSBRiVlBYaURbgQYtXI+qAhKce7JxLuMkGquq3K63GA0YEBFEFAEFNWx8rP7nV75w" -"/sJjhs31z7n54vaWd3Vd10nWFQ1EBACERlERaHc0vrD1eNNEIkMkIURQNMY0Lj7+xGzz5CCxCMqwak/0" -"7H3QUnf2LZR0VoWHHh7PytnO9nnnQ1XVohoVIqioMBMRGEuGbZbar977xe88+tDx9ecURVNUoZgUs6Is" -"at80TfAxBAEFkdi40ASoqqqYTJomqoIoEhkyNs0StlRV9qlzJSGLCuy391XICjRoEbmEGR9/fFo10utC" -"jFrOast2Vk2NtYRoGANCkiRRJDHm22fPfvozf3jL33w1BXvx4v+alOV4NPLONT5KlCyzPsQIEHxwXtTR" -"aLQ7Gu0W5cw5EAVERKC800nyrndxNmucF8OrzxhXFcUQMLjGl1N7zanrTGKStEtkvJcYNAbxPjLbpglV" -"1YjAuacufPx37+72jv3A837iqYtPlbNpPXNFWU3GRftNERGVEGII4l10LpSzejwqyqKqZm46KVUpeA1e" -"isKRZe+SyaSZJ2ErlRVFMVBGGs2aAMYQ9fs9BXFumqdJmiaACCCzqlHwosY7+MQnP/LYYw/f9o/vEORi" -"Ot0d7c6qZjQeVVWTcjYYWCIBTBHBeW1qrWqqinp3tF3WTROVrXGunhTNeBTKWTOMvU7emUz1+IYCoEgk" -"4vnEDq1QzxKgpwcvbZfsFy5MQ+xaE0WAmLrdfpIgoRKRQlTVqm66nfSP/uj3P/PH/+0fvvbtJzb/Su0q" -"1/jJZFqU1WRazGY7H/3ob/R6HcTYRmtCCh6cl0e+862imDnvkUwIDag4J87HPLfBu3FwwetzTiVsCXSV" -"FaNnr0HL4AUAIhEVgzOjUeHzWgHyvEekWZIzY5TIDACwPjz2rW9/84MffN8PvvjlP/wjP1nVZac7dL6a" -"TkvX+GJaFdPxZz/7iRi0hR0ASZkIFCXv9WMjdV0llpUzUGFkaxVJJECSmrKYNnXsJAKSrDBpfMYALW/O" -"Eh1VJcCyno2mNRECYlPXzAwgT20V/W5qEzZs2NhmWrz/vf8u65x4zWtuZ+LhIMsTU1bFZFq4BqbT0ax0" -"r339e05ec7KtRFtjIWhVO+T0Dz555wP/+3M+oAIoAmOa5mLTTGIkgqIsbd6/OCnO9NciRAa+agDtR2oJ" -"kAiEIGTs5uZ6NZv1el0RiTEAQu0ccQYosQl33fUr933ts6dP3/C+975FoicGBNy+cFEizqpqVpZFUW2e" -"uOn0mTMqjoiYGaJOZ42xPR9pMhkVxSwEQJQonsgAKJMR0PX19cY51amE1sL2V74PZW6HctLt8CISI6hQ" -"nnYIaTjsqcJ4PBkOB8SAqDHGTqf7B7939+/8zm+dueH5SL3zF84bY0UFVMqicIJFUZSzWTkbAVVpKgRC" -"BIjqnEuzCNhUs3I2mznvptNadcyUEHOWdkSE2cQYm8apoggorcA3rwagef4sKCJRBNgIBFVjDB8/fgxQ" -"CAEMJIbP3n//r773jtPX3/zP3/Yh5swY7ORZFAEwH/iPb/va1/64CaFpmqZyvdycOG4tISEBooidVaFu" -"uqpSOwhBogICIGrTVE3tQpQQfZqmo9F0Y70nogrKtLJgf9gwL6KiAKBN02xv" -"T4hNJ82SxBpj806GKDFI1ci7/tVbtnYvvPvffHzj2BnndrMsURCM5D35RqtZ5byv66quK9FgjHZSawzPLYUQALwPABCjDIdZU9fW2DRLvZO6dgpS13WeZ7z4yQqT" -"oVVokGqMAgAhhG6WFeV4wIOqruumMgZ63WN3vu9f3PeVz7/lbXfe/MJbGr+1udlhQiT1XqsZGwoiERRANEQBVQARjcQUQqjrWhQBE5B51EeEPM+tsSKSJmysb1wd" -"Y0ySTGIZY0REYFxuq1w1gFpPqICiEqIqmMEgiYLdXj8EEY1BJOHhf/34f/7QB371lpfd+qpXvzHEyclret2cLRMAlI3vpmnVjGblyLtZiD4ExxiJmE1AVIkBAEV0" -"NqtCmAFAjI0hCKJISMgxQpJam1gFcFUTfIyArFHEECEAtstjOETGeDgTUxBRERWJqpLnSZKse+/KcrZ+bC3GEIKcP7f9s6+7/Wd++o2G0RqXGCOxVrLGMIJToB//" -"2z93zbUveN6NL/GvelOMs43jJ6whZgYAUcny1MUmRveyv/X31teve+73v3Bra5JkTlW982nWAQUEBERmTVKMIsv8bCVu+hmXXJel1dYxey/eh6ZxVdNs7QZrNpLE" -"MhMxAmhTBwhU" -"eDMa7wxz7PWstY21lCZp0zREtDtGHzuzWspxk3XTTm7zxB8/Dnlm5gOBzup44byrfVo3ShAsl3mPCCnG2FaL8jzzPjDJcDAb9oeJpcRaZiZCxMPuxj4zDbp0N1nb" -"/wQRReRQz8qwneVZr9dLOQHQKN4FCUFOHM97nTSxIU1SQxo8MkdgyDLV2Yyk6fWU2Tvv+r0OmVxViAgBQwQmO1hT2fWMIc0MU56kxrkmhIgISnFnvBMa6XZ0Y70b" -"JBplFQReDaPmUKt5XToiRRFNU5zNJiJxe3tre3u7KIrZrDQGT2z0+13D7NfWkk996g/f855f3tiwSWKtMYNB3uvRqVPZ5qY9ccKcvKY/HOS+abwPTdOUsxJQAcQa" -"3Niwv/4f7rh48dGN4700tb1+59ix9SxNsyzPsk6ScJoRES+LVIvjsLKiehBgjJLmJkmwqmaIEKOv6zgcDpxzdTUeDrKsY/MMyun2nz14v4+QWOyvZ9NCT5ywk0kw" -"hGxoPK0Iw/qgU85ciLC+1i3ruH7c7OzG8U519ptfrsvbmAFJCEkAu71OFLVJXnG0SSNRwPJyi2QlnKJnpkFPN+aWyoLzaSARcmIBxK2tHcvzPM1s42rF2Ol0vnX/" -"N19766t+6idv/dR//7RNekUDX/of99766p/+qZff8uZ/+iZj+MMf/M3f/ujdx453Bv38Xe+648v33hsovPGNb3jlT7z0H/z9n/3zBx6KkhCa7dHk4siNp6WPMai4" -"GIJGwKDqDBgFBMW2ugmEK/HShzAxvfStqnY6eaebpanpdPJer9fr9YbD9aIs3vGOn7/x+T/0mte99fOf+0JZlI88svvuf/3OW156653v/y+TIv7Ld75z89RzP/yh" -"3woOzn774XvuuefMDX/17W+9vdM99f67fv+vv/jl7/iltzS1AyARcc4XRbmzuzuZTMbjcTWrfFNp8IbpcvAwnrGTXr7uV19cfGoMV43b2dkarh/LbYaIaUbfeejP" -"LfX/2Vt/hTJ8/W1vfujBb9x371cfefTs2Qfvu/9bX5lOii//yeff8E/eXjf1ffc++KUvfvpFP/gSH8yXvvCZH/nRV9z1n37ZED7y8NlvfPMBm6RENktTiUmU2B5N" -"MfFVsTHs4JxedVUBgqfxTlodVkREQiREJNVojbm4s9sd9keTOs+zaRUn4wJIHYhR7vWG1iaN4zw//tznvnQ8Lq6/nl70opcxnXzRi3/8Yx/78MMPPvCKV77uyScK" -"Qnvt6RcgZszZbT//4sHGZhN8mvY6HZOmawIymkzzJCsnjliSNBVtAzoSLXahV+GEDluTnk8KkJCIkEANwfra4PxT57Z3dra2tqbj0ckzN06K3Y/d/WtPPPrgPb97" -"dzGbfP+NNyMZSjqv+pk31BL/9IGvKcdXvOLnPvHxDzx57tGbnv+jtjvcOHndaLv4O3/39Zsbx//kc/cQpDF4xBgjxKigOuh1DSFIHAyGCsDMuIBowf68Ghr0NHSW" -"irTIxwgBVQyhihiDKupjmfU2b//FX/vNf3/Hpz/1yTPPu3FtfXNtbfNNb373Rz5y529/+D3Dwdrtb/+3onLTTT/0kh9+5clrT2+evLZ201/4xbt+49d/6Rfe/HsR" -"4bZ/9M5ud2392HUmSceTqTWapMY19Xh31xhuw8RyDojz97CKKPbMMuk9hgIAqMYoPkgIsWl81YSmcXXtnYshiCiUVd3t9fP+cGen9JK6Wpxz3W7X+4CIAJQwjXYv" -"bhw/Nhx0ETUEr5CIRiZFgBDZC168uGWTZH1tfXd0AQkG/Rx02s3T3e1t72O/lyeGU8M2NVlms4ST1GRpkjCzQaI5P+SqFcwAgWhu98zExMzCDDEqqnbSrKkbonrQ" -"607KWQOBGVRdmggzxhgQ0sFaDzE0bjwcDijgaLzT7XXSxDCR81HqsLm5joiI/sRG3/k6S7GqtWncrCz7vV7CbFqaDBG1eLTri7lSH1p/njVAC2p3a1ZKRERMFJmZ" -"SIkQBFTVIJbTadaV4SDLsgBIWZ4TikosyzKx1DQ+SQkBkDyA63Sp3zej8e7aYNhN" -"E05w0aQACJTHFBGYOuPR7nA4yJIENBIxMzK1xwKhuXmtAKFD7WoAzkMYEREJMzMLMRCRkIAAgaYWm2rqfTUc9m3CXqssyQhtt7NujPU+IAKSVFWVZMYIGAOdLDWG" -"i2ICACFERMzzXCCyyqwoZ0XFDIYYRdkYYiIGNkgEhpEJiYB4CdBhI9khlxoICETErMzIBjkSMxsDqggiURRUEyYf/YXz59IsTfJMYrDWpmnqQ8VMbAwADQd9UW2a" -"RlUUYlFOo8S6rtsklFgIzWh7R6MYTgAEoR2XmdtXNmwMG95nYiuRw0axNlwwozEkEcPcD0GMGgnaOiGAGkKTdmdlHZq65BJIh8Oh840PfmNjw9qWA62EqBrTNEGi" -"siyzPGFIxuPx1JfqAwJYNqCKCIw0d3zMhtttJSbGuYXNHZAeXomeGUBLYmXLgSYijUogimCIhMgyBKMqGiOqIiIHRVBREUTpdVIVqYMGH3cu7HgNaZ5d3NoZrq05" -"77zz62trTV1bm0gUDca5xte7KgKItuV3LsYlanUHmckaNoaMIUJc1IBWoz7PUoP2ZQZKBAJEIkjEzMaiVVElEdMypZhBZP4rEQGANElSRBWJIhrBVc1Ove28Q8RY" -"haIsOnmH0bZfZgbLRkXaaN2GLGY2xliLxpJN2FhmA8xIzEiEuMo1x7MBaLHawAVNGZCQW1IUoFVVAYmgiqpxUVTbIxPh3O7AkgGANLeimpqEEKPIsDdUEcaIBubE" -"TpnT69oYBQDMxIaY0RhjDVvDlts8A1ur3zfJw3qjFVDw2m4mImKGKGqYhUEtAMRFJQQAQaIsd0HaQonu8Z3mbHsCBInYEvD2XRsSIszTHWPYWDaGrGVrrbXGEhkm" -"g0SkiwxoZezdZ5sHPb0w1IZ7JmajAmqVFFnm21OMqAARkVQgxgiw7Kab3+OFz8BFjaldNMByqbe0LGZmA3PjssYYYoPGEDMiQbtiRpx35V3ltdg+QwNEIAAlMECw" -"10CICIEQiABAJUIUbQmtqm2nwZ6zWNxwwkV/Ai5Aovk6GA2zMcSGbELWmsQYYykxzKZNf9r4vr9n76omirAvnC3nxAjAtOCLIyoQARIgYowaYqQAIiBRFz0sqqD7" -"am+I+5WH2hxiniAbg8aSNdZYtoYSIsNsGKmNa4gAArrSGHZ4H7QPo7YnDIgVgBRVERNgDG3sjRikLYSKgJCIggrqJYRLFNhvVy0TcZEQGottOmgNW0OGqTUuwqU5" -"4cpb7lZCwZt7IiKAFhhSQEbECNrmJoTIJMIUAkdZCqqAzjf3W19Ne9pD86yPGYnJEBlLxpBhYwwZg0xA7TGvbyxnskom8Ep40stZKQEqoKIAKBChUSRAAgJgJolq" -"WH2MIlFUVEi17VFddnjMzYsIFot0ZAZitMxsyDAaZDZIDLioJQAoos490F9OEmcr863QFhqNhIotNoREFEVjUCIlQVGKIhpx2ciyNLNFgbJ1K+16AucHATOaeWFj" -"rzxGcwtfrfNZNUB7ffCgiECttpMitMUPYQJBiCRRMLaaIyAK836fvS2kdqt9bmI8RwqJgQiZieep6Tx3aksul6+xdJUatLyBrZlw6ywVkQCh7elSZozCoqqCCu0e" -"P+3xefZyn7k/MqhtcjNXJ8KFNQG2vAVcphp7r6u8qMuB/b7esbYFF1RVZb5vFURk7nsIVEV0uaEluFeraAFibJkuS+Rg8bnuux8rYwNdIYBgX/chwDy2qMCCM4xz" -"y4I2c95rFtzPN1jokS42BeZnJmrLKC0ul8XvXAmAYMlZaiGY3+TWHWP7CIa9msBfmALCHJe9dcjyKRZIl7SqfI+1hV+CUXu5oHvE8z2a9SJz0Zb7vO/JHrjvKRSL" -"h5vsQ2+Oy+Wb+JUC6LuAden47Wf/HxO9Igb1Xca9ks8PWjjvxXV+F7X4f/12/sUrC9KVfsDSpcPtIbX/sq+aQf1FubpPoPoekKOHvB0gRwAdIEcAHSBHAB0gRwAd" -"IEcAHSBHAB0gRwAdIEcAHSBHAB0gRwAdIP8HqHccFP4Rq4QAAAAASUVORK5CYII="; - Send64(str64, "image/png"); - } - else - { - Exec(); - } - Reset(); // prepare for next request - } - else - { - AddResponseHeader("Date", GetHttpDate()); - AddResponseHeader("Connection", "close"); - SetStatus("405"); - SetStatusText("Method not allowed"); - SendResponse(); - } -} - - -void HttpdSocket::OnData(const char *p,size_t l) -{ - if (m_file) - { - m_file -> fwrite(p,1,l); - } - m_received += l; - if (m_received >= m_content_length && m_content_length) - { - // all done - if (m_file && !m_form) - { - m_form = new HttpdForm(m_file, m_content_type, m_content_length); - AddResponseHeader("Date", datetime2httpdate(GetDate()) ); - if (GetUri() == "/image") - { - std::string str64 = -"iVBORw0KGgoAAAANSUhEUgAAAGAAAABeCAIAAABTioayAAAACXBIWXMAAABkAAAAZAAPlsXdAAAAUHRF" -"WHRSYXcgcHJvZmlsZSB0eXBlIEFQUDEyAApnZW5lcmljIHByb2ZpbGUKICAgICAgMTUKNDQ3NTYzNmI3" -"OTAwMDEwMDA0MDAwMDAwM2MwMDAwCg2F1B0AABb4SURBVHja7Xx7rGVXed/3WGs/zvPeuTPXMzbjcUpq" -"HAwlpQlYoUlDaJsAiVuFFKSKGlUlKgXqIKJAKxfRR4IUZEpSt1FoQEK4oYQEErlSFAoKIEoo2BQasBmc" -"2NjyYzxz5957Hnufvfd6fF//2Oecez2hvbXvmZkg3U9b556Zc85ea//291rf+n0bVRWO5P8udLUn8Jdd" -"jgA6QI4AOkCOADpAjgA6QI4AOkCOADpAjgA6QI4AOkCOADpAjgA6QI4AOkCOADpAjgA6QMxVHHtfoUWx" -"/dP+C5fvABGv4gwBAK9qPWg5NLbvrjIY302ujgapAmKrQQiqC3xAQQF0H1AIcyXSq4XeZdegfedfWs78" -"jYKAAgDi3sVri4mqzH+D9DSTu+I2dyVNTEFRl34GUTUikiqotrgoAqqIAhBxqzj7ZocAighXWJUuI0Cq" -"injJ+SMAIZKolkXlGrOzM61mjfckCoN+X9UjorU26wgb7HTSPAfDRlVVFQAR21NeOT26XAC1p10CpKoI" -"iKTO+ckkFpO4vVX1Bh3kkKRsDCIBE4sIMRNx8FTPYgwQfJ1k4ZpT3W4nAQBVQaSF/1pcw+VE63JrEKiC" -"KhChC83Fi6EYEyp2uzxYN4kFY6H1O63TIUQAiCIIEgK5Rke7zWhUE2a9AR+/JunmpIr7of/eA2hhWREA" -"QUlBkGg8af7s7E4n75+6Lu/2iBkUAgJLhP2+RkSJsNU5ACUCQCAyxTQ88eS0rt1gSGdOD621Ik8zs8uH" -"0eUCSDSqCDHGUD/2mCvLXpbWp051bEqqGoIAINHeVRHRJTMREQBEACQEUDa0vT07/2QZvbvxphO9vhGh" -"1m0j0uVzSysGaOF6QASJQvD4yKN1UeiZ053eULzX4FsspB221RdVZWYARaTFaeYXjIgiqqpEag16jw9+" -"e3daTH/gBevHjw1EoIXle0ODdJH/KQiCxiiPPOLrWX7taeh1o3ek8wQH26jUao1qa1ZPy6VbgNovtIAi" -"gCoZK17l3GPNdFLf8H2djY1cRAlJUfHyhP+VAbQM6gsPAt/404uzypw509vYoMYhKCHOQxsAiAohaqtL" -"OhdEUlAm8iEQEgAQIRHHGJGQkBSAjILyhXNaN9VzTuOgn6jOl9yXQ49WvJpXEFUhoAcf2t7apn7f5p04" -"K9XVXkVcE4IXiSoRUEkFVYiAEZnZMltmoxFUKAYFJRWQiK4JwUfvoncxBnUNKMTBMUVKzj2OdSNzXC6P" -"ka1mLbZMdkCQSbZ36q3z2Oma4yesAipwEI8iLkTD4GNEBGZGAEJSBUBQ0RAcqLBJBdRYC0gxKKqKqgrE" -"4FUFgNAY7xFAOx0a79KTT4bvu4FVlYAUFRVgpXp0WID2W6gqIMXGyeOPN73ORm8QrcUQRFUUTNNEAIyt" -"CxJ1PmQ2H093vvr1L0rUm5//N+5/4N7g4o/92Cs7/R6AiAIxi4AKsOGvf/3Ljz/x0F974S2nr7/RNd5a" -"MqSj8e60JMPl9ddvSBRiVlBYaURbgQYtXI+qAhKce7JxLuMkGquq3K63GA0YEBFEFAEFNWx8rP7nV75w" -"/sJjhs31z7n54vaWd3Vd10nWFQ1EBACERlERaHc0vrD1eNNEIkMkIURQNMY0Lj7+xGzz5CCxCMqwak/0" -"7H3QUnf2LZR0VoWHHh7PytnO9nnnQ1XVohoVIqioMBMRGEuGbZbar977xe88+tDx9ecURVNUoZgUs6Is" -"at80TfAxBAEFkdi40ASoqqqYTJomqoIoEhkyNs0StlRV9qlzJSGLCuy391XICjRoEbmEGR9/fFo10utC" -"jFrOast2Vk2NtYRoGANCkiRRJDHm22fPfvozf3jL33w1BXvx4v+alOV4NPLONT5KlCyzPsQIEHxwXtTR" -"aLQ7Gu0W5cw5EAVERKC800nyrndxNmucF8OrzxhXFcUQMLjGl1N7zanrTGKStEtkvJcYNAbxPjLbpglV" -"1YjAuacufPx37+72jv3A837iqYtPlbNpPXNFWU3GRftNERGVEGII4l10LpSzejwqyqKqZm46KVUpeA1e" -"isKRZe+SyaSZJ2ErlRVFMVBGGs2aAMYQ9fs9BXFumqdJmiaACCCzqlHwosY7+MQnP/LYYw/f9o/vEORi" -"Ot0d7c6qZjQeVVWTcjYYWCIBTBHBeW1qrWqqinp3tF3WTROVrXGunhTNeBTKWTOMvU7emUz1+IYCoEgk" -"4vnEDq1QzxKgpwcvbZfsFy5MQ+xaE0WAmLrdfpIgoRKRQlTVqm66nfSP/uj3P/PH/+0fvvbtJzb/Su0q" -"1/jJZFqU1WRazGY7H/3ob/R6HcTYRmtCCh6cl0e+862imDnvkUwIDag4J87HPLfBu3FwwetzTiVsCXSV" -"FaNnr0HL4AUAIhEVgzOjUeHzWgHyvEekWZIzY5TIDACwPjz2rW9/84MffN8PvvjlP/wjP1nVZac7dL6a" -"TkvX+GJaFdPxZz/7iRi0hR0ASZkIFCXv9WMjdV0llpUzUGFkaxVJJECSmrKYNnXsJAKSrDBpfMYALW/O" -"Eh1VJcCyno2mNRECYlPXzAwgT20V/W5qEzZs2NhmWrz/vf8u65x4zWtuZ+LhIMsTU1bFZFq4BqbT0ax0" -"r339e05ec7KtRFtjIWhVO+T0Dz555wP/+3M+oAIoAmOa5mLTTGIkgqIsbd6/OCnO9NciRAa+agDtR2oJ" -"kAiEIGTs5uZ6NZv1el0RiTEAQu0ccQYosQl33fUr933ts6dP3/C+975FoicGBNy+cFEizqpqVpZFUW2e" -"uOn0mTMqjoiYGaJOZ42xPR9pMhkVxSwEQJQonsgAKJMR0PX19cY51amE1sL2V74PZW6HctLt8CISI6hQ" -"nnYIaTjsqcJ4PBkOB8SAqDHGTqf7B7939+/8zm+dueH5SL3zF84bY0UFVMqicIJFUZSzWTkbAVVpKgRC" -"BIjqnEuzCNhUs3I2mznvptNadcyUEHOWdkSE2cQYm8apoggorcA3rwagef4sKCJRBNgIBFVjDB8/fgxQ" -"CAEMJIbP3n//r773jtPX3/zP3/Yh5swY7ORZFAEwH/iPb/va1/64CaFpmqZyvdycOG4tISEBooidVaFu" -"uqpSOwhBogICIGrTVE3tQpQQfZqmo9F0Y70nogrKtLJgf9gwL6KiAKBN02xv" -"T4hNJ82SxBpj806GKDFI1ci7/tVbtnYvvPvffHzj2BnndrMsURCM5D35RqtZ5byv66quK9FgjHZSawzPLYUQALwPABCjDIdZU9fW2DRLvZO6dgpS13WeZ7z4yQqT" -"oVVokGqMAgAhhG6WFeV4wIOqruumMgZ63WN3vu9f3PeVz7/lbXfe/MJbGr+1udlhQiT1XqsZGwoiERRANEQBVQARjcQUQqjrWhQBE5B51EeEPM+tsSKSJmysb1wd" -"Y0ySTGIZY0REYFxuq1w1gFpPqICiEqIqmMEgiYLdXj8EEY1BJOHhf/34f/7QB371lpfd+qpXvzHEyclret2cLRMAlI3vpmnVjGblyLtZiD4ExxiJmE1AVIkBAEV0" -"NqtCmAFAjI0hCKJISMgxQpJam1gFcFUTfIyArFHEECEAtstjOETGeDgTUxBRERWJqpLnSZKse+/KcrZ+bC3GEIKcP7f9s6+7/Wd++o2G0RqXGCOxVrLGMIJToB//" -"2z93zbUveN6NL/GvelOMs43jJ6whZgYAUcny1MUmRveyv/X31teve+73v3Bra5JkTlW982nWAQUEBERmTVKMIsv8bCVu+hmXXJel1dYxey/eh6ZxVdNs7QZrNpLE" -"MhMxAmhTBwhU" -"eDMa7wxz7PWstY21lCZp0zREtDtGHzuzWspxk3XTTm7zxB8/Dnlm5gOBzup44byrfVo3ShAsl3mPCCnG2FaL8jzzPjDJcDAb9oeJpcRaZiZCxMPuxj4zDbp0N1nb" -"/wQRReRQz8qwneVZr9dLOQHQKN4FCUFOHM97nTSxIU1SQxo8MkdgyDLV2Yyk6fWU2Tvv+r0OmVxViAgBQwQmO1hT2fWMIc0MU56kxrkmhIgISnFnvBMa6XZ0Y70b" -"JBplFQReDaPmUKt5XToiRRFNU5zNJiJxe3tre3u7KIrZrDQGT2z0+13D7NfWkk996g/f855f3tiwSWKtMYNB3uvRqVPZ5qY9ccKcvKY/HOS+abwPTdOUsxJQAcQa" -"3Niwv/4f7rh48dGN4700tb1+59ix9SxNsyzPsk6ScJoRES+LVIvjsLKiehBgjJLmJkmwqmaIEKOv6zgcDpxzdTUeDrKsY/MMyun2nz14v4+QWOyvZ9NCT5ywk0kw" -"hGxoPK0Iw/qgU85ciLC+1i3ruH7c7OzG8U519ptfrsvbmAFJCEkAu71OFLVJXnG0SSNRwPJyi2QlnKJnpkFPN+aWyoLzaSARcmIBxK2tHcvzPM1s42rF2Ol0vnX/" -"N19766t+6idv/dR//7RNekUDX/of99766p/+qZff8uZ/+iZj+MMf/M3f/ujdx453Bv38Xe+648v33hsovPGNb3jlT7z0H/z9n/3zBx6KkhCa7dHk4siNp6WPMai4" -"GIJGwKDqDBgFBMW2ugmEK/HShzAxvfStqnY6eaebpanpdPJer9fr9YbD9aIs3vGOn7/x+T/0mte99fOf+0JZlI88svvuf/3OW156653v/y+TIv7Ld75z89RzP/yh" -"3woOzn774XvuuefMDX/17W+9vdM99f67fv+vv/jl7/iltzS1AyARcc4XRbmzuzuZTMbjcTWrfFNp8IbpcvAwnrGTXr7uV19cfGoMV43b2dkarh/LbYaIaUbfeejP" -"LfX/2Vt/hTJ8/W1vfujBb9x371cfefTs2Qfvu/9bX5lOii//yeff8E/eXjf1ffc++KUvfvpFP/gSH8yXvvCZH/nRV9z1n37ZED7y8NlvfPMBm6RENktTiUmU2B5N" -"MfFVsTHs4JxedVUBgqfxTlodVkREQiREJNVojbm4s9sd9keTOs+zaRUn4wJIHYhR7vWG1iaN4zw//tznvnQ8Lq6/nl70opcxnXzRi3/8Yx/78MMPPvCKV77uyScK" -"Qnvt6RcgZszZbT//4sHGZhN8mvY6HZOmawIymkzzJCsnjliSNBVtAzoSLXahV+GEDluTnk8KkJCIkEANwfra4PxT57Z3dra2tqbj0ckzN06K3Y/d/WtPPPrgPb97" -"dzGbfP+NNyMZSjqv+pk31BL/9IGvKcdXvOLnPvHxDzx57tGbnv+jtjvcOHndaLv4O3/39Zsbx//kc/cQpDF4xBgjxKigOuh1DSFIHAyGCsDMuIBowf68Ghr0NHSW" -"irTIxwgBVQyhihiDKupjmfU2b//FX/vNf3/Hpz/1yTPPu3FtfXNtbfNNb373Rz5y529/+D3Dwdrtb/+3onLTTT/0kh9+5clrT2+evLZ201/4xbt+49d/6Rfe/HsR" -"4bZ/9M5ud2392HUmSceTqTWapMY19Xh31xhuw8RyDojz97CKKPbMMuk9hgIAqMYoPkgIsWl81YSmcXXtnYshiCiUVd3t9fP+cGen9JK6Wpxz3W7X+4CIAJQwjXYv" -"bhw/Nhx0ETUEr5CIRiZFgBDZC168uGWTZH1tfXd0AQkG/Rx02s3T3e1t72O/lyeGU8M2NVlms4ST1GRpkjCzQaI5P+SqFcwAgWhu98zExMzCDDEqqnbSrKkbonrQ" -"607KWQOBGVRdmggzxhgQ0sFaDzE0bjwcDijgaLzT7XXSxDCR81HqsLm5joiI/sRG3/k6S7GqtWncrCz7vV7CbFqaDBG1eLTri7lSH1p/njVAC2p3a1ZKRERMFJmZ" -"SIkQBFTVIJbTadaV4SDLsgBIWZ4TikosyzKx1DQ+SQkBkDyA63Sp3zej8e7aYNhN" -"E05w0aQACJTHFBGYOuPR7nA4yJIENBIxMzK1xwKhuXmtAKFD7WoAzkMYEREJMzMLMRCRkIAAgaYWm2rqfTUc9m3CXqssyQhtt7NujPU+IAKSVFWVZMYIGAOdLDWG" -"i2ICACFERMzzXCCyyqwoZ0XFDIYYRdkYYiIGNkgEhpEJiYB4CdBhI9khlxoICETErMzIBjkSMxsDqggiURRUEyYf/YXz59IsTfJMYrDWpmnqQ8VMbAwADQd9UW2a" -"RlUUYlFOo8S6rtsklFgIzWh7R6MYTgAEoR2XmdtXNmwMG95nYiuRw0axNlwwozEkEcPcD0GMGgnaOiGAGkKTdmdlHZq65BJIh8Oh840PfmNjw9qWA62EqBrTNEGi" -"siyzPGFIxuPx1JfqAwJYNqCKCIw0d3zMhtttJSbGuYXNHZAeXomeGUBLYmXLgSYijUogimCIhMgyBKMqGiOqIiIHRVBREUTpdVIVqYMGH3cu7HgNaZ5d3NoZrq05" -"77zz62trTV1bm0gUDca5xte7KgKItuV3LsYlanUHmckaNoaMIUJc1IBWoz7PUoP2ZQZKBAJEIkjEzMaiVVElEdMypZhBZP4rEQGANElSRBWJIhrBVc1Ove28Q8RY" -"haIsOnmH0bZfZgbLRkXaaN2GLGY2xliLxpJN2FhmA8xIzEiEuMo1x7MBaLHawAVNGZCQW1IUoFVVAYmgiqpxUVTbIxPh3O7AkgGANLeimpqEEKPIsDdUEcaIBubE" -"TpnT69oYBQDMxIaY0RhjDVvDlts8A1ur3zfJw3qjFVDw2m4mImKGKGqYhUEtAMRFJQQAQaIsd0HaQonu8Z3mbHsCBInYEvD2XRsSIszTHWPYWDaGrGVrrbXGEhkm" -"g0SkiwxoZezdZ5sHPb0w1IZ7JmajAmqVFFnm21OMqAARkVQgxgiw7Kab3+OFz8BFjaldNMByqbe0LGZmA3PjssYYYoPGEDMiQbtiRpx35V3ltdg+QwNEIAAlMECw" -"10CICIEQiABAJUIUbQmtqm2nwZ6zWNxwwkV/Ai5Aovk6GA2zMcSGbELWmsQYYykxzKZNf9r4vr9n76omirAvnC3nxAjAtOCLIyoQARIgYowaYqQAIiBRFz0sqqD7" -"am+I+5WH2hxiniAbg8aSNdZYtoYSIsNsGKmNa4gAArrSGHZ4H7QPo7YnDIgVgBRVERNgDG3sjRikLYSKgJCIggrqJYRLFNhvVy0TcZEQGottOmgNW0OGqTUuwqU5" -"4cpb7lZCwZt7IiKAFhhSQEbECNrmJoTIJMIUAkdZCqqAzjf3W19Ne9pD86yPGYnJEBlLxpBhYwwZg0xA7TGvbyxnskom8Ep40stZKQEqoKIAKBChUSRAAgJgJolq" -"WH2MIlFUVEi17VFddnjMzYsIFot0ZAZitMxsyDAaZDZIDLioJQAoos490F9OEmcr863QFhqNhIotNoREFEVjUCIlQVGKIhpx2ciyNLNFgbJ1K+16AucHATOaeWFj" -"rzxGcwtfrfNZNUB7ffCgiECttpMitMUPYQJBiCRRMLaaIyAK836fvS2kdqt9bmI8RwqJgQiZieep6Tx3aksul6+xdJUatLyBrZlw6ywVkQCh7elSZozCoqqCCu0e" -"P+3xefZyn7k/MqhtcjNXJ8KFNQG2vAVcphp7r6u8qMuB/b7esbYFF1RVZb5vFURk7nsIVEV0uaEluFeraAFibJkuS+Rg8bnuux8rYwNdIYBgX/chwDy2qMCCM4xz" -"y4I2c95rFtzPN1jokS42BeZnJmrLKC0ul8XvXAmAYMlZaiGY3+TWHWP7CIa9msBfmALCHJe9dcjyKRZIl7SqfI+1hV+CUXu5oHvE8z2a9SJz0Zb7vO/JHrjvKRSL" -"h5vsQ2+Oy+Wb+JUC6LuAden47Wf/HxO9Igb1Xca9ks8PWjjvxXV+F7X4f/12/sUrC9KVfsDSpcPtIbX/sq+aQf1FubpPoPoekKOHvB0gRwAdIEcAHSBHAB0gRwAd" -"IEcAHSBHAB0gRwAdIEcAHSBHAB0gRwAdIP8HqHccFP4Rq4QAAAAASUVORK5CYII="; - Send64(str64, "image/png"); - } - else - { - Exec(); - } - Reset(); // prepare for next request - } - } -} - - -void HttpdSocket::Send64(const std::string& str64, const std::string& type) -{ - Base64 bb; - - if (!strcasecmp(m_start.c_str(), m_if_modified_since.c_str())) - { - SetStatus("304"); - SetStatusText("Not Modified"); - SendResponse(); - } - else - { - size_t len = bb.decode_length(str64); - unsigned char *buf = new unsigned char[len]; - - SetStatus("200"); - SetStatusText("OK"); - - AddResponseHeader("Content-length", Utility::l2string( (long)len) ); - AddResponseHeader("Content-type", type ); - AddResponseHeader("Last-modified", m_start); - SendResponse(); - - bb.decode(str64, buf, len); - SendBuf( (char *)buf, len); - delete[] buf; - } -} - - -std::string HttpdSocket::datetime2httpdate(const std::string& dt) -{ - struct tm tp; - time_t t; - const char *days[] = { "Sun","Mon","Tue","Wed","Thu","Fri","Sat" }; - const char *months[] = { "Jan","Feb","Mar","Apr","May","Jun", - "Jul","Aug","Sep","Oct","Nov","Dec" }; - int i; - char s[40]; - -/* 1997-12-16 09:50:40 */ - - if (dt.size() == 19) - { - tp.tm_year = atoi(dt.substr(0,4).c_str()) - 1900; - i = atoi(dt.substr(5,2).c_str()) - 1; - tp.tm_mon = i >= 0 ? i : 0; - tp.tm_mday = atoi(dt.substr(8,2).c_str()); - tp.tm_hour = atoi(dt.substr(11,2).c_str()); - tp.tm_min = atoi(dt.substr(14,2).c_str()); - tp.tm_sec = atoi(dt.substr(17,2).c_str()); - tp.tm_wday = 0; - tp.tm_yday = 0; - tp.tm_isdst = 0; - t = mktime(&tp); - if (t == -1) - { - Handler().LogError(this, "datetime2httpdate", 0, "mktime() failed"); - } - - sprintf(s,"%s, %02d %s %d %02d:%02d:%02d GMT", - days[tp.tm_wday], - tp.tm_mday, - months[tp.tm_mon], - tp.tm_year + 1900, - tp.tm_hour,tp.tm_min,tp.tm_sec); - } - else - { - *s = 0; - } - return s; -} - - -std::string HttpdSocket::GetDate() -{ - time_t t = time(NULL); - struct tm tp; -#ifdef _WIN32 - memcpy(&tp, localtime(&t), sizeof(tp)); -#else - localtime_r(&t, &tp); -#endif - char slask[40]; // yyyy-mm-dd hh:mm:ss - sprintf(slask,"%d-%02d-%02d %02d:%02d:%02d", - tp.tm_year + 1900, - tp.tm_mon + 1, - tp.tm_mday, - tp.tm_hour,tp.tm_min,tp.tm_sec); - return slask; -} - - -void HttpdSocket::Reset() -{ - HTTPSocket::Reset(); - m_content_length = 0; - if (m_file) - { - delete m_file; - m_file = NULL; - } - m_received = 0; - m_request_id = ++m_request_count; - if (m_cookies) - delete m_cookies; - m_cookies = NULL; - if (m_form) - delete m_form; - m_form = NULL; -} - - -const std::string& HttpdSocket::GetHttpDate() const -{ - return m_http_date; -} - - -HttpdCookies *HttpdSocket::GetCookies() -{ - return m_cookies; -} - - -const HttpdForm *HttpdSocket::GetForm() const -{ - return m_form; -} - - - -#ifdef SOCKETS_NAMESPACE -} -#endif - - diff --git a/Sockets/HttpdSocket.h b/Sockets/HttpdSocket.h deleted file mode 100644 index c4d10f5..0000000 --- a/Sockets/HttpdSocket.h +++ /dev/null @@ -1,106 +0,0 @@ -/** \file HttpdSocket.h -*/ -/* -Copyright (C) 2001-2007 Anders Hedstrom (grymse@alhem.net) - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_HttpdSocket_H -#define _SOCKETS_HttpdSocket_H - -#include "sockets-config.h" -#include "HTTPSocket.h" -#include "ISocketHandler.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -class HttpdCookies; -class HttpdForm; -class IFile; - -/** \defgroup webserver Webserver framework */ -/** Web server socket framework. - \ingroup webserver */ -class HttpdSocket : public HTTPSocket -{ -public: - HttpdSocket(ISocketHandler& ); - ~HttpdSocket(); - - void OnFirst(); - void OnHeader(const std::string& key,const std::string& value); - void OnHeaderComplete(); - void OnData(const char *,size_t); - - /** This method needs to be implemented with logic to produce - a response to an incoming request. */ - virtual void Exec() = 0; - /** Get current date in http rfc format. */ - const std::string& GetHttpDate() const; - /** Get pointer to cookie class. */ - HttpdCookies *GetCookies(); - /** Get pointer to query string/form data class. */ - const HttpdForm *GetForm() const; - - size_t ContentLength() const { return m_content_length; } - const IFile *Body() const { return m_file; } - int RequestId() const { return m_request_id; } - -protected: - HttpdSocket(const HttpdSocket& s) : HTTPSocket(s) {} - /** Decode and send a base64-encoded string. - \param str64 Base64-encoded string - \param type Mime type of content (content-type header) */ - void Send64(const std::string& str64, const std::string& type); - std::string datetime2httpdate(const std::string& dt); - std::string GetDate(); - void Reset(); - // headers - std::string m_http_cookie; - std::string m_content_type; - std::string m_content_length_str; - std::string m_if_modified_since; - -private: - HttpdSocket& operator=(const HttpdSocket& s) { return *this; } -static int m_request_count; -static std::string m_start; - size_t m_content_length; - IFile *m_file; - size_t m_received; - int m_request_id; - std::string m_http_date; - HttpdCookies *m_cookies; - HttpdForm *m_form; -}; - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_HttpdSocket_H - diff --git a/Sockets/IBase.h b/Sockets/IBase.h deleted file mode 100644 index 93bfdf9..0000000 --- a/Sockets/IBase.h +++ /dev/null @@ -1,44 +0,0 @@ -/** - ** \file - ** \date 2007-06-05 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_IBase_H -#define _SOCKETS_IBase_H - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -class IBase -{ -public: - virtual ~IBase() {} - -}; - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - -#endif // _SOCKETS_IBase_H - diff --git a/Sockets/IEventHandler.h b/Sockets/IEventHandler.h deleted file mode 100644 index fcbc432..0000000 --- a/Sockets/IEventHandler.h +++ /dev/null @@ -1,75 +0,0 @@ -/** \file IEventHandler.h - ** \date 2005-12-07 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2005,2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_IEventHandler_H -#define _SOCKETS_IEventHandler_H - -#include "sockets-config.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -class IEventOwner; - -/** Timer event handler pure virtual base class. - \ingroup timer */ -class IEventHandler -{ -public: - virtual ~IEventHandler() {} - - /** Return time left until next event. - \param tv Time struct that will be filled by method - \return true if time is set for next event */ - virtual bool GetTimeUntilNextEvent(struct timeval *) = 0; - /** Will fire events whose time has come. */ - virtual void CheckEvents() = 0; - /** Schedule event for an owner. - \param from Event owner - \param sec Seconds until event - \param usec Microseconds until event */ - virtual long AddEvent(IEventOwner *,long sec,long usec) = 0; - /** Clear all events for a specific owner. */ - virtual void ClearEvents(IEventOwner *) = 0; - /** Remove one specific event for an event owner. */ - virtual void RemoveEvent(IEventOwner *,long) = 0; - -}; - - - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_IEventHandler_H - diff --git a/Sockets/IEventOwner.cpp b/Sockets/IEventOwner.cpp deleted file mode 100644 index 6c73551..0000000 --- a/Sockets/IEventOwner.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/** \file IEventOwner.cpp - ** \date 2005-12-07 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2005,2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#include "IEventOwner.h" - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -IEventOwner::IEventOwner(IEventHandler& h) : m_event_handler(h), m_handler_invalid(false) -{ -} - - -IEventOwner::~IEventOwner() -{ - if (!m_handler_invalid) - { - m_event_handler.ClearEvents(this); - } -} - - -IEventHandler& IEventOwner::EventHandler() -{ - return m_event_handler; -} - - -long IEventOwner::AddEvent(long sec,long usec) -{ - return m_event_handler.AddEvent(this, sec, usec); -} - - -void IEventOwner::ClearEvents() -{ - m_event_handler.ClearEvents(this); -} - - -void IEventOwner::RemoveEvent(long eid) -{ - m_event_handler.RemoveEvent(this, eid); -} - - -#ifdef SOCKETS_NAMESPACE -} -#endif - diff --git a/Sockets/IEventOwner.h b/Sockets/IEventOwner.h deleted file mode 100644 index f3fc1cd..0000000 --- a/Sockets/IEventOwner.h +++ /dev/null @@ -1,77 +0,0 @@ -/** \file IEventOwner.h - ** \date 2005-12-07 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2005,2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_IEventOwner_H -#define _SOCKETS_IEventOwner_H - -#include "sockets-config.h" -#include "IEventHandler.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -/** Any class that wants to use timer events inherits this. - \ingroup timer */ -class IEventOwner -{ -public: - IEventOwner(IEventHandler& h); - virtual ~IEventOwner(); - - /** Schedule event. - \param sec Seconds until event - \param usec Microseconds until event - \return Event ID */ - long AddEvent(long sec,long usec); - /** Clear all events scheduled by this owner. */ - void ClearEvents(); - /** Remove one event scheduled by this owner. - \param eid Event ID to remove */ - void RemoveEvent(long eid); - /** Event callback will fire when time is up. */ - virtual void OnEvent(int) = 0; - - IEventHandler& EventHandler(); - void SetHandlerInvalid(bool x = true) { m_handler_invalid = x; } - -private: - IEventHandler& m_event_handler; - bool m_handler_invalid; -}; - - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_IEventOwner_H - diff --git a/Sockets/IFile.h b/Sockets/IFile.h deleted file mode 100644 index aecc50f..0000000 --- a/Sockets/IFile.h +++ /dev/null @@ -1,71 +0,0 @@ -/** \file IFile.h - ** \date 2005-04-25 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_IFile_H -#define _SOCKETS_IFile_H - -#include "sockets-config.h" -#include - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -/** \defgroup file File handling */ -/** Pure virtual file I/O interface. - \ingroup file */ -class IFile -{ -public: - virtual ~IFile() {} - - virtual bool fopen(const std::string&, const std::string&) = 0; - virtual void fclose() = 0; - - virtual size_t fread(char *, size_t, size_t) const = 0; - virtual size_t fwrite(const char *, size_t, size_t) = 0; - - virtual char *fgets(char *, int) const = 0; - virtual void fprintf(const char *format, ...) = 0; - - virtual off_t size() const = 0; - virtual bool eof() const = 0; - - virtual void reset_read() const = 0; - virtual void reset_write() = 0; - -}; - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_IFile_H - diff --git a/Sockets/IHttpServer.h b/Sockets/IHttpServer.h deleted file mode 100644 index 34e34c3..0000000 --- a/Sockets/IHttpServer.h +++ /dev/null @@ -1,56 +0,0 @@ -/** - ** \file IHttpServer.h - ** \date 2007-10-05 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_IHttpServer_H -#define _SOCKETS_IHttpServer_H - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -class HttpRequest; -class HttpResponse; - -class IHttpServer -{ -public: - virtual ~IHttpServer() {} - - /** Complete request has been received and parsed. Send response - using the Respond() method. */ - virtual void OnExec(const HttpRequest& req) = 0; - - /** Send response. */ - virtual void Respond(const HttpResponse& res) = 0; - -}; - - - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - -#endif // _SOCKETS_IHttpServer_H - diff --git a/Sockets/ISocketHandler.h b/Sockets/ISocketHandler.h deleted file mode 100644 index e32463e..0000000 --- a/Sockets/ISocketHandler.h +++ /dev/null @@ -1,233 +0,0 @@ -/** \file ISocketHandler.h - ** \date 2004-02-13 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_ISocketHandler_H -#define _SOCKETS_ISocketHandler_H -#include "sockets-config.h" - -#include -#include - -#include "socket_include.h" -#include "Socket.h" -#include "StdLog.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -typedef enum { - LIST_CALLONCONNECT = 0, -#ifdef ENABLE_DETACH - LIST_DETACH, -#endif - LIST_TIMEOUT, - LIST_RETRY, - LIST_CLOSE -} list_t; - -class SocketAddress; -class Mutex; - - -/** Socket container class, event generator. - \ingroup basic */ -class ISocketHandler -{ - friend class Socket; - -public: - /** Connection pool class for internal use by the ISocketHandler. - \ingroup internal */ -#ifdef ENABLE_POOL - class PoolSocket : public Socket - { - public: - PoolSocket(ISocketHandler& h,Socket *src) : Socket(h) { - CopyConnection( src ); - SetIsClient(); - } - - void OnRead() { - Handler().LogError(this, "OnRead", 0, "data on hibernating socket", LOG_LEVEL_FATAL); - SetCloseAndDelete(); - } - void OnOptions(int,int,int,SOCKET) {} - - }; -#endif - -public: - virtual ~ISocketHandler() {} - - /** Get mutex reference for threadsafe operations. */ - virtual Mutex& GetMutex() const = 0; - - /** Register StdLog object for error callback. - \param log Pointer to log class */ - virtual void RegStdLog(StdLog *log) = 0; - - /** Log error to log class for print out / storage. */ - virtual void LogError(Socket *p,const std::string& user_text,int err,const std::string& sys_err,loglevel_t t = LOG_LEVEL_WARNING) = 0; - - // ------------------------------------------------------------------------- - // Socket stuff - // ------------------------------------------------------------------------- - /** Add socket instance to socket map. Removal is always automatic. */ - virtual void Add(Socket *) = 0; -private: - /** Remove socket from socket map, used by Socket class. */ - virtual void Remove(Socket *) = 0; -public: - /** Get status of read/write/exception file descriptor set for a socket. */ - virtual void Get(SOCKET s,bool& r,bool& w,bool& e) = 0; - /** Set read/write/exception file descriptor sets (fd_set). */ - virtual void Set(SOCKET s,bool bRead,bool bWrite,bool bException = true) = 0; - - /** Wait for events, generate callbacks. */ - virtual int Select(long sec,long usec) = 0; - /** This method will not return until an event has been detected. */ - virtual int Select() = 0; - /** Wait for events, generate callbacks. */ - virtual int Select(struct timeval *tsel) = 0; - - /** Check that a socket really is handled by this socket handler. */ - virtual bool Valid(Socket *) = 0; - /** Return number of sockets handled by this handler. */ - virtual size_t GetCount() = 0; - - /** Override and return false to deny all incoming connections. - \param p ListenSocket class pointer (use GetPort to identify which one) */ - virtual bool OkToAccept(Socket *p) = 0; - - /** Called by Socket when a socket changes state. */ - virtual void AddList(SOCKET s,list_t which_one,bool add) = 0; - - // ------------------------------------------------------------------------- - // Connection pool - // ------------------------------------------------------------------------- -#ifdef ENABLE_POOL - /** Find available open connection (used by connection pool). */ - virtual ISocketHandler::PoolSocket *FindConnection(int type,const std::string& protocol,SocketAddress&) = 0; - /** Enable connection pool (by default disabled). */ - virtual void EnablePool(bool = true) = 0; - /** Check pool status. - \return true if connection pool is enabled */ - virtual bool PoolEnabled() = 0; -#endif // ENABLE_POOL - - // ------------------------------------------------------------------------- - // Socks4 - // ------------------------------------------------------------------------- -#ifdef ENABLE_SOCKS4 - /** Set socks4 server ip that all new tcp sockets should use. */ - virtual void SetSocks4Host(ipaddr_t) = 0; - /** Set socks4 server hostname that all new tcp sockets should use. */ - virtual void SetSocks4Host(const std::string& ) = 0; - /** Set socks4 server port number that all new tcp sockets should use. */ - virtual void SetSocks4Port(port_t) = 0; - /** Set optional socks4 userid. */ - virtual void SetSocks4Userid(const std::string& ) = 0; - /** If connection to socks4 server fails, immediately try direct connection to final host. */ - virtual void SetSocks4TryDirect(bool = true) = 0; - /** Get socks4 server ip. - \return socks4 server ip */ - virtual ipaddr_t GetSocks4Host() = 0; - /** Get socks4 port number. - \return socks4 port number */ - virtual port_t GetSocks4Port() = 0; - /** Get socks4 userid (optional). - \return socks4 userid */ - virtual const std::string& GetSocks4Userid() = 0; - /** Check status of socks4 try direct flag. - \return true if direct connection should be tried if connection to socks4 server fails */ - virtual bool Socks4TryDirect() = 0; -#endif // ENABLE_SOCKS4 - - // ------------------------------------------------------------------------- - // DNS resolve server - // ------------------------------------------------------------------------- -#ifdef ENABLE_RESOLVER - /** Enable asynchronous DNS. - \param port Listen port of asynchronous dns server */ - virtual void EnableResolver(port_t = 16667) = 0; - /** Check resolver status. - \return true if resolver is enabled */ - virtual bool ResolverEnabled() = 0; - /** Queue a dns request. - \param host Hostname to be resolved - \param port Port number will be echoed in Socket::OnResolved callback */ - virtual int Resolve(Socket *,const std::string& host,port_t port) = 0; -#ifdef ENABLE_IPV6 - virtual int Resolve6(Socket *,const std::string& host,port_t port) = 0; -#endif - /** Do a reverse dns lookup. */ - virtual int Resolve(Socket *,ipaddr_t a) = 0; -#ifdef ENABLE_IPV6 - virtual int Resolve(Socket *,in6_addr& a) = 0; -#endif - /** Get listen port of asynchronous dns server. */ - virtual port_t GetResolverPort() = 0; - /** Resolver thread ready for queries. */ - virtual bool ResolverReady() = 0; - /** Returns true if socket waiting for a resolve event. */ - virtual bool Resolving(Socket *) = 0; -#endif // ENABLE_RESOLVER - -#ifdef ENABLE_TRIGGERS - /** Fetch unique trigger id. */ - virtual int TriggerID(Socket *src) = 0; - /** Subscribe socket to trigger id. */ - virtual bool Subscribe(int id, Socket *dst) = 0; - /** Unsubscribe socket from trigger id. */ - virtual bool Unsubscribe(int id, Socket *dst) = 0; - /** Execute OnTrigger for subscribed sockets. - \param id Trigger ID - \param data Data passed from source to destination - \param erase Empty trigger id source and destination maps if 'true', - Leave them in place if 'false' - if a trigger should be called many times */ - virtual void Trigger(int id, Socket::TriggerData& data, bool erase = true) = 0; -#endif // ENABLE_TRIGGERS - -#ifdef ENABLE_DETACH - /** Indicates that the handler runs under SocketThread. */ - virtual void SetSlave(bool x = true) = 0; - /** Indicates that the handler runs under SocketThread. */ - virtual bool IsSlave() = 0; -#endif // ENABLE_DETACH - -}; - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_ISocketHandler_H - diff --git a/Sockets/Ipv4Address.cpp b/Sockets/Ipv4Address.cpp deleted file mode 100644 index 58f25e5..0000000 --- a/Sockets/Ipv4Address.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/** - ** \file Ipv4Address.cpp - ** \date 2006-09-21 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#include "Ipv4Address.h" -#include "Utility.h" -#include "Parse.h" -#ifndef _WIN32 -#include -#endif - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - - -Ipv4Address::Ipv4Address(port_t port) : m_valid(true) -{ - memset(&m_addr, 0, sizeof(m_addr)); - m_addr.sin_family = AF_INET; - m_addr.sin_port = htons( port ); -} - - -Ipv4Address::Ipv4Address(ipaddr_t a,port_t port) : m_valid(true) -{ - memset(&m_addr, 0, sizeof(m_addr)); - m_addr.sin_family = AF_INET; - m_addr.sin_port = htons( port ); - memcpy(&m_addr.sin_addr, &a, sizeof(struct in_addr)); -} - - -Ipv4Address::Ipv4Address(struct in_addr& a,port_t port) : m_valid(true) -{ - memset(&m_addr, 0, sizeof(m_addr)); - m_addr.sin_family = AF_INET; - m_addr.sin_port = htons( port ); - m_addr.sin_addr = a; -} - - -Ipv4Address::Ipv4Address(const std::string& host,port_t port) : m_valid(false) -{ - memset(&m_addr, 0, sizeof(m_addr)); - m_addr.sin_family = AF_INET; - m_addr.sin_port = htons( port ); - { - ipaddr_t a; - if (Utility::u2ip(host, a)) - { - memcpy(&m_addr.sin_addr, &a, sizeof(struct in_addr)); - m_valid = true; - } - } -} - - -Ipv4Address::Ipv4Address(struct sockaddr_in& sa) -{ - m_addr = sa; - m_valid = sa.sin_family == AF_INET; -} - - -Ipv4Address::~Ipv4Address() -{ -} - - -Ipv4Address::operator struct sockaddr *() -{ - return (struct sockaddr *)&m_addr; -} - - -Ipv4Address::operator socklen_t() -{ - return sizeof(struct sockaddr_in); -} - - -void Ipv4Address::SetPort(port_t port) -{ - m_addr.sin_port = htons( port ); -} - - -port_t Ipv4Address::GetPort() -{ - return ntohs( m_addr.sin_port ); -} - - -bool Ipv4Address::Resolve(const std::string& hostname,struct in_addr& a) -{ - struct sockaddr_in sa; - memset(&a, 0, sizeof(a)); - if (Utility::isipv4(hostname)) - { - if (!Utility::u2ip(hostname, sa, AI_NUMERICHOST)) - return false; - a = sa.sin_addr; - return true; - } - if (!Utility::u2ip(hostname, sa)) - return false; - a = sa.sin_addr; - return true; -} - - -bool Ipv4Address::Reverse(struct in_addr& a,std::string& name) -{ - struct sockaddr_in sa; - memset(&sa, 0, sizeof(sa)); - sa.sin_family = AF_INET; - sa.sin_addr = a; - return Utility::reverse((struct sockaddr *)&sa, sizeof(sa), name); -} - - -std::string Ipv4Address::Convert(bool include_port) -{ - if (include_port) - return Convert(m_addr.sin_addr) + ":" + Utility::l2string(GetPort()); - return Convert(m_addr.sin_addr); -} - - -std::string Ipv4Address::Convert(struct in_addr& a) -{ - struct sockaddr_in sa; - memset(&sa, 0, sizeof(sa)); - sa.sin_family = AF_INET; - sa.sin_addr = a; - std::string name; - Utility::reverse((struct sockaddr *)&sa, sizeof(sa), name, NI_NUMERICHOST); - return name; -} - - -void Ipv4Address::SetAddress(struct sockaddr *sa) -{ - memcpy(&m_addr, sa, sizeof(struct sockaddr_in)); -} - - -int Ipv4Address::GetFamily() -{ - return m_addr.sin_family; -} - - -bool Ipv4Address::IsValid() -{ - return m_valid; -} - - -bool Ipv4Address::operator==(SocketAddress& a) -{ - if (a.GetFamily() != GetFamily()) - return false; - if ((socklen_t)a != sizeof(m_addr)) - return false; - struct sockaddr *sa = a; - struct sockaddr_in *p = (struct sockaddr_in *)sa; - if (p -> sin_port != m_addr.sin_port) - return false; - if (memcmp(&p -> sin_addr, &m_addr.sin_addr, 4)) - return false; - return true; -} - - -std::auto_ptr Ipv4Address::GetCopy() -{ - return std::auto_ptr(new Ipv4Address(m_addr)); -} - - -std::string Ipv4Address::Reverse() -{ - std::string tmp; - Reverse(m_addr.sin_addr, tmp); - return tmp; -} - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - diff --git a/Sockets/Ipv4Address.h b/Sockets/Ipv4Address.h deleted file mode 100644 index b58c2ce..0000000 --- a/Sockets/Ipv4Address.h +++ /dev/null @@ -1,98 +0,0 @@ -/** - ** \file Ipv4Address.h - ** \date 2006-09-21 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_Ipv4Address_H -#define _SOCKETS_Ipv4Address_H - -#include "sockets-config.h" -#include "SocketAddress.h" - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -/* Ipv4 address implementation. - \ingroup basic */ -class Ipv4Address : public SocketAddress -{ -public: - /** Create empty Ipv4 address structure. - \param port Port number */ - Ipv4Address(port_t port = 0); - /** Create Ipv4 address structure. - \param a Socket address in network byte order (as returned by Utility::u2ip) - \param port Port number in host byte order */ - Ipv4Address(ipaddr_t a,port_t port); - /** Create Ipv4 address structure. - \param a Socket address in network byte order - \param port Port number in host byte order */ - Ipv4Address(struct in_addr& a,port_t port); - /** Create Ipv4 address structure. - \param host Hostname to be resolved - \param port Port number in host byte order */ - Ipv4Address(const std::string& host,port_t port); - Ipv4Address(struct sockaddr_in&); - ~Ipv4Address(); - - // SocketAddress implementation - - operator struct sockaddr *(); - operator socklen_t(); - bool operator==(SocketAddress&); - - void SetPort(port_t port); - port_t GetPort(); - - void SetAddress(struct sockaddr *sa); - int GetFamily(); - - bool IsValid(); - std::auto_ptr GetCopy(); - - /** Convert address struct to text. */ - std::string Convert(bool include_port = false); - std::string Reverse(); - - /** Resolve hostname. */ -static bool Resolve(const std::string& hostname,struct in_addr& a); - /** Reverse resolve (IP to hostname). */ -static bool Reverse(struct in_addr& a,std::string& name); - /** Convert address struct to text. */ -static std::string Convert(struct in_addr& a); - -private: - Ipv4Address(const Ipv4Address& ) {} // copy constructor - Ipv4Address& operator=(const Ipv4Address& ) { return *this; } // assignment operator - struct sockaddr_in m_addr; - bool m_valid; -}; - - - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif -#endif // _SOCKETS_Ipv4Address_H - diff --git a/Sockets/Ipv6Address.cpp b/Sockets/Ipv6Address.cpp deleted file mode 100644 index 2e0f1e9..0000000 --- a/Sockets/Ipv6Address.cpp +++ /dev/null @@ -1,270 +0,0 @@ -/** - ** \file Ipv6Address.cpp - ** \date 2006-09-21 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#include "Ipv6Address.h" -#ifdef ENABLE_IPV6 - -#include "Utility.h" -#include "Parse.h" -#ifndef _WIN32 -#include -#endif -#ifdef IPPROTO_IPV6 - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -Ipv6Address::Ipv6Address(port_t port) : m_valid(true) -{ - memset(&m_addr, 0, sizeof(m_addr)); - m_addr.sin6_family = AF_INET6; - m_addr.sin6_port = htons( port ); -} - - -Ipv6Address::Ipv6Address(struct in6_addr& a,port_t port) : m_valid(true) -{ - memset(&m_addr, 0, sizeof(m_addr)); - m_addr.sin6_family = AF_INET6; - m_addr.sin6_port = htons( port ); - m_addr.sin6_addr = a; -} - - -Ipv6Address::Ipv6Address(const std::string& host,port_t port) : m_valid(false) -{ - memset(&m_addr, 0, sizeof(m_addr)); - m_addr.sin6_family = AF_INET6; - m_addr.sin6_port = htons( port ); - { - struct in6_addr a; - if (Utility::u2ip(host, a)) - { - m_addr.sin6_addr = a; - m_valid = true; - } - } -} - - -Ipv6Address::Ipv6Address(struct sockaddr_in6& sa) -{ - m_addr = sa; - m_valid = sa.sin6_family == AF_INET6; -} - - -Ipv6Address::~Ipv6Address() -{ -} - - -Ipv6Address::operator struct sockaddr *() -{ - return (struct sockaddr *)&m_addr; -} - - -Ipv6Address::operator socklen_t() -{ - return sizeof(struct sockaddr_in6); -} - - -void Ipv6Address::SetPort(port_t port) -{ - m_addr.sin6_port = htons( port ); -} - - -port_t Ipv6Address::GetPort() -{ - return ntohs( m_addr.sin6_port ); -} - - -bool Ipv6Address::Resolve(const std::string& hostname,struct in6_addr& a) -{ - struct sockaddr_in6 sa; - memset(&a, 0, sizeof(a)); - if (Utility::isipv6(hostname)) - { - if (!Utility::u2ip(hostname, sa, AI_NUMERICHOST)) - return false; - a = sa.sin6_addr; - return true; - } - if (!Utility::u2ip(hostname, sa)) - return false; - a = sa.sin6_addr; - return true; -} - - -bool Ipv6Address::Reverse(struct in6_addr& a,std::string& name) -{ - struct sockaddr_in6 sa; - memset(&sa, 0, sizeof(sa)); - sa.sin6_family = AF_INET6; - sa.sin6_addr = a; - return Utility::reverse((struct sockaddr *)&sa, sizeof(sa), name); -} - - -std::string Ipv6Address::Convert(bool include_port) -{ - if (include_port) - return Convert(m_addr.sin6_addr) + ":" + Utility::l2string(GetPort()); - return Convert(m_addr.sin6_addr); -} - - -std::string Ipv6Address::Convert(struct in6_addr& a,bool mixed) -{ - char slask[100]; // l2ip temporary - *slask = 0; - unsigned int prev = 0; - bool skipped = false; - bool ok_to_skip = true; - if (mixed) - { - unsigned short x; - unsigned short addr16[8]; - memcpy(addr16, &a, sizeof(addr16)); - for (size_t i = 0; i < 6; i++) - { - x = ntohs(addr16[i]); - if (*slask && (x || !ok_to_skip || prev)) - strcat(slask,":"); - if (x || !ok_to_skip) - { - sprintf(slask + strlen(slask),"%x", x); - if (x && skipped) - ok_to_skip = false; - } - else - { - skipped = true; - } - prev = x; - } - x = ntohs(addr16[6]); - sprintf(slask + strlen(slask),":%u.%u",x / 256,x & 255); - x = ntohs(addr16[7]); - sprintf(slask + strlen(slask),".%u.%u",x / 256,x & 255); - } - else - { - struct sockaddr_in6 sa; - memset(&sa, 0, sizeof(sa)); - sa.sin6_family = AF_INET6; - sa.sin6_addr = a; - std::string name; - Utility::reverse((struct sockaddr *)&sa, sizeof(sa), name, NI_NUMERICHOST); - return name; - } - return slask; -} - - -void Ipv6Address::SetAddress(struct sockaddr *sa) -{ - memcpy(&m_addr, sa, sizeof(struct sockaddr_in6)); -} - - -int Ipv6Address::GetFamily() -{ - return m_addr.sin6_family; -} - - -void Ipv6Address::SetFlowinfo(uint32_t x) -{ - m_addr.sin6_flowinfo = x; -} - - -uint32_t Ipv6Address::GetFlowinfo() -{ - return m_addr.sin6_flowinfo; -} - - -#ifndef _WIN32 -void Ipv6Address::SetScopeId(uint32_t x) -{ - m_addr.sin6_scope_id = x; -} - - -uint32_t Ipv6Address::GetScopeId() -{ - return m_addr.sin6_scope_id; -} -#endif - - -bool Ipv6Address::IsValid() -{ - return m_valid; -} - - -bool Ipv6Address::operator==(SocketAddress& a) -{ - if (a.GetFamily() != GetFamily()) - return false; - if ((socklen_t)a != sizeof(m_addr)) - return false; - struct sockaddr *sa = a; - struct sockaddr_in6 *p = (struct sockaddr_in6 *)sa; - if (p -> sin6_port != m_addr.sin6_port) - return false; - if (memcmp(&p -> sin6_addr, &m_addr.sin6_addr, sizeof(struct in6_addr))) - return false; - return true; -} - - -std::auto_ptr Ipv6Address::GetCopy() -{ - return std::auto_ptr(new Ipv6Address(m_addr)); -} - - -std::string Ipv6Address::Reverse() -{ - std::string tmp; - Reverse(m_addr.sin6_addr, tmp); - return tmp; -} - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif -#endif // IPPROTO_IPV6 -#endif // ENABLE_IPV6 - diff --git a/Sockets/Ipv6Address.h b/Sockets/Ipv6Address.h deleted file mode 100644 index a071141..0000000 --- a/Sockets/Ipv6Address.h +++ /dev/null @@ -1,107 +0,0 @@ -/** - ** \file Ipv6Address.h - ** \date 2006-09-21 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_Ipv6Address_H -#define _SOCKETS_Ipv6Address_H -#include "sockets-config.h" -#ifdef ENABLE_IPV6 - -#include "SocketAddress.h" -#ifdef IPPROTO_IPV6 -#if defined( _WIN32) && !defined(__CYGWIN__) -typedef unsigned __int32 uint32_t; -#endif - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -/** Ipv6 address implementation. - \ingroup basic */ -class Ipv6Address : public SocketAddress -{ -public: - /** Create empty Ipv6 address structure. - \param port Port number */ - Ipv6Address(port_t port = 0); - /** Create Ipv6 address structure. - \param a Socket address in network byte order - \param port Port number in host byte order */ - Ipv6Address(struct in6_addr& a,port_t port); - /** Create Ipv6 address structure. - \param host Hostname to be resolved - \param port Port number in host byte order */ - Ipv6Address(const std::string& host,port_t port); - Ipv6Address(struct sockaddr_in6&); - ~Ipv6Address(); - - // SocketAddress implementation - - operator struct sockaddr *(); - operator socklen_t(); - bool operator==(SocketAddress&); - - void SetPort(port_t port); - port_t GetPort(); - - void SetAddress(struct sockaddr *sa); - int GetFamily(); - - bool IsValid(); - std::auto_ptr GetCopy(); - - /** Convert address struct to text. */ - std::string Convert(bool include_port = false); - std::string Reverse(); - - /** Resolve hostname. */ -static bool Resolve(const std::string& hostname,struct in6_addr& a); - /** Reverse resolve (IP to hostname). */ -static bool Reverse(struct in6_addr& a,std::string& name); - /** Convert address struct to text. */ -static std::string Convert(struct in6_addr& a,bool mixed = false); - - void SetFlowinfo(uint32_t); - uint32_t GetFlowinfo(); -#ifndef _WIN32 - void SetScopeId(uint32_t); - uint32_t GetScopeId(); -#endif - -private: - Ipv6Address(const Ipv6Address& ) {} // copy constructor - Ipv6Address& operator=(const Ipv6Address& ) { return *this; } // assignment operator - struct sockaddr_in6 m_addr; - bool m_valid; -}; - - - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif -#endif // IPPROTO_IPV6 -#endif // ENABLE_IPV6 -#endif // _SOCKETS_Ipv6Address_H - diff --git a/Sockets/ListenSocket.h b/Sockets/ListenSocket.h deleted file mode 100644 index f4edc37..0000000 --- a/Sockets/ListenSocket.h +++ /dev/null @@ -1,420 +0,0 @@ -/** \file ListenSocket.h - ** \date 2004-02-13 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_ListenSocket_H -#define _SOCKETS_ListenSocket_H -#include "sockets-config.h" - -#ifdef _WIN32 -#include -#else -#include -#endif - -#include "ISocketHandler.h" -#include "Socket.h" -#include "Utility.h" -#include "SctpSocket.h" -#include "Ipv4Address.h" -#include "Ipv6Address.h" -#ifdef ENABLE_EXCEPTIONS -#include "Exception.h" -#endif - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -/** Binds incoming port number to new Socket class X. - \ingroup basic */ -template -class ListenSocket : public Socket -{ -public: - /** Constructor. - \param h ISocketHandler reference - \param use_creator Optional use of creator (default true) */ - ListenSocket(ISocketHandler& h,bool use_creator = true) : Socket(h), m_depth(0), m_creator(NULL) - ,m_bHasCreate(false) - { - if (use_creator) - { - m_creator = new X(h); - Socket *tmp = m_creator -> Create(); - if (tmp && dynamic_cast(tmp)) - { - m_bHasCreate = true; - } - if (tmp) - { - delete tmp; - } - } - } - ~ListenSocket() { - if (m_creator) - { - delete m_creator; - } - } - - /** Close file descriptor. */ - int Close() { - if (GetSocket() != INVALID_SOCKET) - { - closesocket(GetSocket()); - } - return 0; - } - - /** Bind and listen to any interface. - \param port Port (0 is random) - \param depth Listen queue depth */ - int Bind(port_t port,int depth = 20) { -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (IsIpv6()) - { - Ipv6Address ad(port); - return Bind(ad, depth); - } - else -#endif -#endif - { - Ipv4Address ad(port); - return Bind(ad, depth); - } - } - - int Bind(SocketAddress& ad,int depth) { -#ifdef USE_SCTP - if (dynamic_cast(m_creator)) - { - return Bind(ad, "sctp", depth); - } -#endif - return Bind(ad, "tcp", depth); - } - - /** Bind and listen to any interface, with optional protocol. - \param port Port (0 is random) - \param protocol Network protocol - \param depth Listen queue depth */ - int Bind(port_t port,const std::string& protocol,int depth = 20) { -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (IsIpv6()) - { - Ipv6Address ad(port); - return Bind(ad, protocol, depth); - } - else -#endif -#endif - { - Ipv4Address ad(port); - return Bind(ad, protocol, depth); - } - } - - /** Bind and listen to specific interface. - \param intf Interface hostname - \param port Port (0 is random) - \param depth Listen queue depth */ - int Bind(const std::string& intf,port_t port,int depth = 20) { -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (IsIpv6()) - { - Ipv6Address ad(intf, port); - if (ad.IsValid()) - { - return Bind(ad, depth); - } - Handler().LogError(this, "Bind", 0, "name resolution of interface name failed", LOG_LEVEL_FATAL); - return -1; - } - else -#endif -#endif - { - Ipv4Address ad(intf, port); - if (ad.IsValid()) - { - return Bind(ad, depth); - } - Handler().LogError(this, "Bind", 0, "name resolution of interface name failed", LOG_LEVEL_FATAL); - return -1; - } - } - - /** Bind and listen to specific interface. - \param intf Interface hostname - \param port Port (0 is random) - \param protocol Network protocol - \param depth Listen queue depth */ - int Bind(const std::string& intf,port_t port,const std::string& protocol,int depth = 20) { -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (IsIpv6()) - { - Ipv6Address ad(intf, port); - if (ad.IsValid()) - { - return Bind(ad, protocol, depth); - } - Handler().LogError(this, "Bind", 0, "name resolution of interface name failed", LOG_LEVEL_FATAL); - return -1; - } - else -#endif -#endif - { - Ipv4Address ad(intf, port); - if (ad.IsValid()) - { - return Bind(ad, protocol, depth); - } - Handler().LogError(this, "Bind", 0, "name resolution of interface name failed", LOG_LEVEL_FATAL); - return -1; - } - } - - /** Bind and listen to ipv4 interface. - \param a Ipv4 interface address - \param port Port (0 is random) - \param depth Listen queue depth */ - int Bind(ipaddr_t a,port_t port,int depth = 20) { - Ipv4Address ad(a, port); -#ifdef USE_SCTP - if (dynamic_cast(m_creator)) - { - return Bind(ad, "sctp", depth); - } -#endif - return Bind(ad, "tcp", depth); - } - /** Bind and listen to ipv4 interface. - \param a Ipv4 interface address - \param port Port (0 is random) - \param protocol Network protocol - \param depth Listen queue depth */ - int Bind(ipaddr_t a,port_t port,const std::string& protocol,int depth) { - Ipv4Address ad(a, port); - return Bind(ad, protocol, depth); - } - -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - /** Bind and listen to ipv6 interface. - \param a Ipv6 interface address - \param port Port (0 is random) - \param depth Listen queue depth */ - int Bind(in6_addr a,port_t port,int depth = 20) { - Ipv6Address ad(a, port); -#ifdef USE_SCTP - if (dynamic_cast(m_creator)) - { - return Bind(ad, "sctp", depth); - } -#endif - return Bind(ad, "tcp", depth); - } - /** Bind and listen to ipv6 interface. - \param a Ipv6 interface address - \param port Port (0 is random) - \param protocol Network protocol - \param depth Listen queue depth */ - int Bind(in6_addr a,port_t port,const std::string& protocol,int depth) { - Ipv6Address ad(a, port); - return Bind(ad, protocol, depth); - } -#endif -#endif - - /** Bind and listen to network interface. - \param ad Interface address - \param protocol Network protocol - \param depth Listen queue depth */ - int Bind(SocketAddress& ad,const std::string& protocol,int depth) { - SOCKET s; - if ( (s = CreateSocket(ad.GetFamily(), SOCK_STREAM, protocol)) == INVALID_SOCKET) - { - return -1; - } - if (bind(s, ad, ad) == -1) - { - Handler().LogError(this, "bind", Errno, StrError(Errno), LOG_LEVEL_FATAL); - closesocket(s); -#ifdef ENABLE_EXCEPTIONS - throw Exception("bind() failed for port " + Utility::l2string(ad.GetPort()) + ": " + StrError(Errno)); -#endif - return -1; - } - if (listen(s, depth) == -1) - { - Handler().LogError(this, "listen", Errno, StrError(Errno), LOG_LEVEL_FATAL); - closesocket(s); -#ifdef ENABLE_EXCEPTIONS - throw Exception("listen() failed for port " + Utility::l2string(ad.GetPort()) + ": " + StrError(Errno)); -#endif - return -1; - } - m_depth = depth; - Attach(s); - return 0; - } - - /** Return assigned port number. */ - port_t GetPort() - { - return GetSockPort(); - } - - /** Return listen queue depth. */ - int GetDepth() - { - return m_depth; - } - - /** OnRead on a ListenSocket receives an incoming connection. */ - void OnRead() - { - struct sockaddr sa; - socklen_t sa_len = sizeof(struct sockaddr); - SOCKET a_s = accept(GetSocket(), &sa, &sa_len); - - if (a_s == INVALID_SOCKET) - { - Handler().LogError(this, "accept", Errno, StrError(Errno), LOG_LEVEL_ERROR); - return; - } - if (!Handler().OkToAccept(this)) - { - Handler().LogError(this, "accept", -1, "Not OK to accept", LOG_LEVEL_WARNING); - closesocket(a_s); - return; - } - if (Handler().GetCount() >= FD_SETSIZE) - { - Handler().LogError(this, "accept", (int)Handler().GetCount(), "ISocketHandler fd_set limit reached", LOG_LEVEL_FATAL); - closesocket(a_s); - return; - } - Socket *tmp = m_bHasCreate ? m_creator -> Create() : new X(Handler()); -#ifdef ENABLE_IPV6 - tmp -> SetIpv6( IsIpv6() ); -#endif - tmp -> SetParent(this); - tmp -> Attach(a_s); - tmp -> SetNonblocking(true); - { -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (sa_len == sizeof(struct sockaddr_in6)) - { - struct sockaddr_in6 *p = (struct sockaddr_in6 *)&sa; - if (p -> sin6_family == AF_INET6) - { - Ipv6Address ad(p -> sin6_addr,ntohs(p -> sin6_port)); - ad.SetFlowinfo(p -> sin6_flowinfo); -#ifndef _WIN32 - ad.SetScopeId(p -> sin6_scope_id); -#endif - tmp -> SetRemoteAddress(ad); - } - } -#endif -#endif - if (sa_len == sizeof(struct sockaddr_in)) - { - struct sockaddr_in *p = (struct sockaddr_in *)&sa; - if (p -> sin_family == AF_INET) - { - Ipv4Address ad(p -> sin_addr,ntohs(p -> sin_port)); - tmp -> SetRemoteAddress(ad); - } - } - } - tmp -> SetConnected(true); - tmp -> Init(); - tmp -> SetDeleteByHandler(true); - Handler().Add(tmp); -#ifdef HAVE_OPENSSL - if (tmp -> IsSSL()) // SSL Enabled socket - { - // %! OnSSLAccept calls SSLNegotiate that can finish in this one call. - // %! If that happens and negotiation fails, the 'tmp' instance is - // %! still added to the list of active sockets in the sockethandler. - // %! See bugfix for this in SocketHandler::Select - don't Set rwx - // %! flags if CloseAndDelete() flag is true. - // %! An even better fugbix (see TcpSocket::OnSSLAccept) now avoids - // %! the Add problem altogether, so ignore the above. - // %! (OnSSLAccept does no longer call SSLNegotiate().) - tmp -> OnSSLAccept(); - } - else -#endif - { - tmp -> OnAccept(); - } - } - - /** Please don't use this method. - "accept()" is handled automatically in the OnRead() method. */ - virtual SOCKET Accept(SOCKET socket, struct sockaddr *saptr, socklen_t *lenptr) - { - return accept(socket, saptr, lenptr); - } - - bool HasCreator() { return m_bHasCreate; } - - void OnOptions(int,int,int,SOCKET) { - SetSoReuseaddr(true); - } - -protected: - ListenSocket(const ListenSocket& s) : Socket(s) {} -private: - ListenSocket& operator=(const ListenSocket& ) { return *this; } - int m_depth; - X *m_creator; - bool m_bHasCreate; -}; - - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_ListenSocket_H - diff --git a/Sockets/Lock.cpp b/Sockets/Lock.cpp deleted file mode 100644 index 3f7902e..0000000 --- a/Sockets/Lock.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/** \file Lock.cpp - ** \date 2005-08-22 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2005,2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#include "Mutex.h" -#include "Lock.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -Lock::Lock(Mutex& m) : m_mutex(m) -{ - m_mutex.Lock(); -} - - -Lock::~Lock() -{ - m_mutex.Unlock(); -} - - - - -#ifdef SOCKETS_NAMESPACE -} -#endif - diff --git a/Sockets/Lock.h b/Sockets/Lock.h deleted file mode 100644 index 71fdd5e..0000000 --- a/Sockets/Lock.h +++ /dev/null @@ -1,59 +0,0 @@ -/** \file Lock.h - ** \date 2005-08-22 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2005,2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_Lock_H -#define _SOCKETS_Lock_H - -#include "sockets-config.h" -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -class Mutex; - -/** Mutex encapsulation class. - \ingroup threading */ -class Lock -{ -public: - Lock(Mutex&); - ~Lock(); - -private: - Mutex& m_mutex; -}; - - - - -#ifdef SOCKETS_NAMESPACE -} -#endif -#endif // _SOCKETS_Lock_H - diff --git a/Sockets/Makefile b/Sockets/Makefile deleted file mode 100644 index 631501d..0000000 --- a/Sockets/Makefile +++ /dev/null @@ -1,154 +0,0 @@ -# platforms: -# linux-x86-32 -# win32-cygwin -# solaris9-sparc-64 -# macosx -# solaris8 -PLATFORM = linux-x86-32 -IPPROTO_IPV6 = yes - -# .h files installed to $(PREFIX)/include/Sockets -# static lib .a files installed to $(PREFIX)/lib -PREFIX = /usr/local - -# include paths -INCLUDE = - -include Makefile.version - -# CXX, CFLAGS, LIBS -include Makefile.Defines.$(PLATFORM) - -# uncomment these lines if the library should be in its own namespace -CFLAGS += -DSOCKETS_NAMESPACE=sockets -CFLAGS += -DSOCKETS_NAMESPACE_STR='"sockets"' - -# Enable insane amounts of debug output to stdout/stderr: -#CFLAGS += -D_DEBUG -#CFLAGS += -DIPPROTO_IPV6 - - -CPPFLAGS = $(CFLAGS) - -PROGS = Sockets-config - -all: libSockets.a $(PROGS) - -libSockets.a: $(OBJS) - ar cru $@ $(OBJS) - ranlib $@ - -Sockets-config: Sockets-config.o - $(CXX) -o $@ $^ - -clean: - rm -f *.o *~ slask *.d $(PROGS) *.a */*~ - --include *.d - - -# everything which follows is www.alhem.net/Sockets website maintenance stuff, please ignore -HTDOCS = /usr/local/apache/www.alhem.net/htdocs - -diff: - diff -b -B -C 3 /usr/src/Sockets-$(DIFF_VERSION) . | \ - /usr/local/bin/d2html > \ - $(HTDOCS)/Sockets/latest_diff.html - -install: all - @mkdir -p $(PREFIX)/lib - cp libSockets.a $(PREFIX)/lib - @mkdir -p $(PREFIX)/include/Sockets - cp -a *.h $(PREFIX)/include/Sockets - @rm -f $(PREFIX)/include/Sockets/SSLSocket.* - @rm -f $(PREFIX)/include/Sockets/HttpsGetSocket.* - @rm -f $(PREFIX)/include/Sockets/HttpsSocket.* - @rm -f $(PREFIX)/include/Sockets/EventSocket.* - @rm -f $(PREFIX)/include/Sockets/PoolSocket.* - @rm -f $(PREFIX)/include/Sockets/SocketThread.* - @rm -f $(PREFIX)/include/Sockets/CircularBuffer.* - @rm -f $(PREFIX)/include/Sockets/*Crypt.h - @rm -f $(PREFIX)/include/Sockets/CTcpSocket.h - @rm -f $(PREFIX)/include/Sockets/Min*Socket.h - @rm -f $(PREFIX)/include/Sockets/Min*Handler.h - @rm -f $(PREFIX)/include/Sockets/Uid.h - @mkdir -p $(PREFIX)/bin - install Sockets-config $(PREFIX)/bin - -# no binary files, zip will translate lf to cr lf -FILES = *.h *.cpp Makefile Makefile.* Project/*.ds* \ - README.macosx gpl.txt mkdot.sh \ - Project.net/Sockets/*.vcproj Project.net/Sockets/*.sln \ - Project.net/Test/*.vcproj \ - DevCpp/*.dev tests/Makefile tests/*.cpp \ - OSX.zip - -tar: clean - rm -f MinderSocket_T.h - rm -f uuid.h - rm -f Stdin.* - rm -f sockets_test.cpp - rm -f ListenSocketBase.* - rm -f CircularBuffer.* - rm -f ICrypt.* NullCrypt.* CTcpSocket.* - rm -f Min*Socket.* Min*Handler.* - rm -f Uid.* - tar czf Sockets-$(VERSION).tar.gz $(FILES) - /usr/local/bin/tarfix.sh Sockets-$(VERSION) - cp Sockets-$(VERSION).tar.gz $(HTDOCS)/Sockets - cp Sockets-$(VERSION).zip $(HTDOCS)/Sockets - cp tests/sockets_test.cpp /usr/local/apache/www.alhem.net/htdocs/Sockets/ -# $(MAKE) -C ../SocketsLite tar - -tmptar: clean - rm -f MinderSocket_T.h - rm -f uuid.h - rm -f Stdin.* - rm -f sockets_test.cpp - rm -f ListenSocketBase.* - rm -f CircularBuffer.* - rm -f ICrypt.* NullCrypt.* CTcpSocket.* - rm -f Min*Socket.* Min*Handler.* - rm -f Uid.* - tar czf Sockets-$(VERSION).tar.gz $(FILES) - /usr/local/bin/tarfix.sh Sockets-$(VERSION) - cp Sockets-$(VERSION).tar.gz $(HTDOCS)/Sockets-tmp - cp Sockets-$(VERSION).zip $(HTDOCS)/Sockets-tmp - cp tests/sockets_test.cpp /usr/local/apache/www.alhem.net/htdocs/Sockets-tmp - $(MAKE) -C ../SocketsLite tmptar - -docs: clean - doxygen dox2.cfg - rm -f MinderSocket_T.h - rm -f uuid.h - rm -f Stdin.* - rm -f sockets_test.cpp - rm -f ListenSocketBase.* - rm -f CircularBuffer.* - rm -f ICrypt.* NullCrypt.* CTcpSocket.* - rm -f Min*Socket.* Min*Handler.* - rm -f Uid.* - rm -f tests/*.cpp - ./mkdot.sh - rm -rf /usr/local/apache/www.alhem.net/htdocs/Sockets/html - doxygen doxygen.cfg - ./packdocs.sh Sockets-$(VERSION)-doxygendocs - cvs up -# $(MAKE) -C ../SocketsLite docs - -tmpdocs: clean - rm -f MinderSocket_T.h - rm -f uuid.h - rm -f Stdin.* - rm -f sockets_test.cpp - rm -f ListenSocketBase.* - rm -f CircularBuffer.* - rm -f ICrypt.* NullCrypt.* CTcpSocket.* - rm -f Min*Socket.* Min*Handler.* - rm -f Uid.* - rm -f tests/*.cpp - ./mkdot-tmp.sh - rm -rf /usr/local/apache/www.alhem.net/htdocs/Sockets-tmp/html - doxygen doxygen-tmp.cfg - cvs up - $(MAKE) -C ../SocketsLite tmpdocs diff --git a/Sockets/Makefile.Defines.linux-x86-32 b/Sockets/Makefile.Defines.linux-x86-32 deleted file mode 100644 index 42481ec..0000000 --- a/Sockets/Makefile.Defines.linux-x86-32 +++ /dev/null @@ -1,28 +0,0 @@ -CXX = g++ - -CFLAGS += -Wall -g $(INCLUDE) -MD -D_VERSION='"$(VERSION)"' - -# turn off optimization if compiling with gcc 2.9.x: -#CFLAGS += -O0 -CFLAGS += -O2 - - -# uncomment depending on your operating system -CFLAGS += -DLINUX -#CFLAGS += -DMACOSX -# solaris > 8 -#CFLAGS += -DSOLARIS -# solaris 8 -#CFLAGS += -DSOLARIS8 -# windows and/or cygwin -#CFLAGS += -D_WIN32 -# cygwin -#CFLAGS += -D__CYGWIN__ - - -LIBS += \ - -lpthread -# -lssl -lcrypto \ - -OBJS += Semaphore.o - diff --git a/Sockets/Makefile.Defines.macosx b/Sockets/Makefile.Defines.macosx deleted file mode 100644 index 9b54559..0000000 --- a/Sockets/Makefile.Defines.macosx +++ /dev/null @@ -1,28 +0,0 @@ -CXX = g++ - -CFLAGS += -Wall -g $(INCLUDE) -MD -D_VERSION='"$(VERSION)"' - -# turn off optimization if compiling with gcc 2.9.x: -#CFLAGS += -O0 -CFLAGS += -O2 - - -# uncomment depending on your operating system -#CFLAGS += -DLINUX -CFLAGS += -DMACOSX -# solaris > 8 -#CFLAGS += -DSOLARIS -# solaris 8 -#CFLAGS += -DSOLARIS8 -# windows and/or cygwin -#CFLAGS += -D_WIN32 -# cygwin -#CFLAGS += -D__CYGWIN__ - - -LIBS += \ - -lssl -lcrypto \ - -lpthread - -OBJS += Semaphore.o - diff --git a/Sockets/Makefile.Defines.solaris8 b/Sockets/Makefile.Defines.solaris8 deleted file mode 100644 index ec31056..0000000 --- a/Sockets/Makefile.Defines.solaris8 +++ /dev/null @@ -1,29 +0,0 @@ -CXX = /opt/SUNWspro/bin/CC - -CFLAGS += -g $(INCLUDE) -MD -D_VERSION='"$(VERSION)"' -CFLAGS += -features=rtti -mt - -# turn off optimization if compiling with gcc 2.9.x: -#CFLAGS += -O0 -CFLAGS += -O2 - - -# uncomment depending on your operating system -#CFLAGS += -DLINUX -#CFLAGS += -DMACOSX -# solaris > 8 -#CFLAGS += -DSOLARIS -# solaris 8 -CFLAGS += -DSOLARIS8 -# windows and/or cygwin -#CFLAGS += -D_WIN32 -# cygwin -#CFLAGS += -D__CYGWIN__ - - -LIBS += \ - -lssl -lcrypto \ - -lpthread - -OBJS += Semaphore.o - diff --git a/Sockets/Makefile.Defines.solaris9-sparc-64 b/Sockets/Makefile.Defines.solaris9-sparc-64 deleted file mode 100644 index 42fa8c4..0000000 --- a/Sockets/Makefile.Defines.solaris9-sparc-64 +++ /dev/null @@ -1,29 +0,0 @@ -CXX = /opt/SUNWspro/bin/CC - -CFLAGS += -g $(INCLUDE) -MD -D_VERSION='"$(VERSION)"' -CFLAGS += -features=rtti -mt - -# turn off optimization if compiling with gcc 2.9.x: -#CFLAGS += -O0 -CFLAGS += -O2 - - -# uncomment depending on your operating system -#CFLAGS += -DLINUX -#CFLAGS += -DMACOSX -# solaris > 8 -CFLAGS += -DSOLARIS -# solaris 8 -#CFLAGS += -DSOLARIS8 -# windows and/or cygwin -#CFLAGS += -D_WIN32 -# cygwin -#CFLAGS += -D__CYGWIN__ - - -LIBS += \ - -lssl -lcrypto \ - -lpthread - -OBJS += Semaphore.o - diff --git a/Sockets/Makefile.Defines.win32-cygwin b/Sockets/Makefile.Defines.win32-cygwin deleted file mode 100644 index 66ca672..0000000 --- a/Sockets/Makefile.Defines.win32-cygwin +++ /dev/null @@ -1,26 +0,0 @@ -CXX = g++ - -CFLAGS += -Wall -g $(INCLUDE) -MD -D_VERSION='"$(VERSION)"' - -# turn off optimization if compiling with gcc 2.9.x: -#CFLAGS += -O0 -CFLAGS += -O2 -mno-cygwin - - -# uncomment depending on your operating system -#CFLAGS += -DLINUX -#CFLAGS += -DMACOSX -# solaris > 8 -#CFLAGS += -DSOLARIS -# solaris 8 -#CFLAGS += -DSOLARIS8 -# windows and/or cygwin -CFLAGS += -D_WIN32 -# cygwin -CFLAGS += -D__CYGWIN__ - - -LIBS += c:/openssl/lib/mingw/ssleay32.a \ - c:/openssl/lib/mingw/libeay32.a \ - -lws2_32 - diff --git a/Sockets/Makefile.solaris9-sparc-64 b/Sockets/Makefile.solaris9-sparc-64 deleted file mode 100644 index 82f5ddf..0000000 --- a/Sockets/Makefile.solaris9-sparc-64 +++ /dev/null @@ -1,70 +0,0 @@ -include Makefile.version - -INCLUDE = - -# .h files installed to $(PREFIX)/include/Sockets -# static lib .a files installed to $(PREFIX)/lib -PREFIX = /usr/local - -CXX = /opt/SUNWspro/bin/CC - -CFLAGS = -g $(INCLUDE) -MD -D_VERSION='"$(VERSION)"' -CFLAGS += -features=rtti -mt - -# turn off optimization if compiling with gcc 2.9.x: -#CFLAGS += -O0 -CFLAGS += -O2 - - -# uncomment depending on your operating system -#CFLAGS += -DLINUX -#CFLAGS += -DMACOSX -# solaris > 8 -CFLAGS += -DSOLARIS -# solaris 8 -#CFLAGS += -DSOLARIS8 -# windows and/or cygwin -#CFLAGS += -D_WIN32 -# cygwin -#CFLAGS += -D__CYGWIN__ - - -# uncomment these three lines if the library should be in its own namespace -#CFLAGS += -DSOCKETS_NAMESPACE=sockets -#CFLAGS += -DSOCKETS_NAMESPACE_STR='"sockets"' - - -# Enable insane amounts of debug output to stdout/stderr: -#CFLAGS += -D_DEBUG - - -CPPFLAGS = $(CFLAGS) - -LIBS = -lSockets -lpthread -lssl -lcrypto - -PROGS = Sockets-config - -all: libSockets.a $(PROGS) - -Sockets-config: Sockets-config.o - $(CXX) -o $@ $^ - -libSockets.a: $(OBJS) - ar cru $@ $(OBJS) - ranlib $@ - -stressclient: stressclient.o libSockets.a - g++ -o $@ $^ $(LIBS) - -echoserver: echoserver.o libSockets.a - g++ -o $@ $^ $(LIBS) - -clean: - rm -f *.o *~ slask *.d $(PROGS) *.a */*~ - -.cpp.o: - @echo Compiling $< - @$(CXX) $(CFLAGS) -c -o $@ $< - --include *.d - diff --git a/Sockets/Makefile.version b/Sockets/Makefile.version deleted file mode 100644 index cde12a1..0000000 --- a/Sockets/Makefile.version +++ /dev/null @@ -1,49 +0,0 @@ -VERSION = 2.2.6 -DIFF_VERSION = 2.2.5 - -# Sockets -OBJS = \ - Ajp13Socket.o \ - AjpBaseSocket.o \ - Base64.o \ - Debug.o \ - Event.o \ - EventHandler.o \ - EventTime.o \ - Exception.o \ - File.o \ - HTTPSocket.o \ - HttpBaseSocket.o \ - HttpClientSocket.o \ - HttpDebugSocket.o \ - HttpGetSocket.o \ - HttpPostSocket.o \ - HttpPutSocket.o \ - HttpRequest.o \ - HttpResponse.o \ - HttpTransaction.o \ - HttpdCookies.o \ - HttpdForm.o \ - HttpdSocket.o \ - IEventOwner.o \ - Ipv4Address.o \ - Ipv6Address.o \ - Lock.o \ - MemFile.o \ - Mutex.o \ - Parse.o \ - RandomNumber.o \ - ResolvServer.o \ - ResolvSocket.o \ - SSLInitializer.o \ - SctpSocket.o \ - SmtpdSocket.o \ - Socket.o \ - SocketHandler.o \ - StdoutLog.o \ - StreamSocket.o \ - TcpSocket.o \ - Thread.o \ - UdpSocket.o \ - Utility.o \ - socket_include.o diff --git a/Sockets/MemFile.cpp b/Sockets/MemFile.cpp deleted file mode 100644 index edbe619..0000000 --- a/Sockets/MemFile.cpp +++ /dev/null @@ -1,288 +0,0 @@ -/** \file MemFile.cpp - ** \date 2005-04-25 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif -#include -#include - -#include "MemFile.h" - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -std::map MemFile::m_files; - - -MemFile::MemFile() -:m_temporary(true) -,m_base(new block_t) -,m_current_read(m_base) -,m_current_write(m_base) -,m_current_write_nr(0) -,m_read_ptr(0) -,m_write_ptr(0) -,m_b_read_caused_eof(false) -{ -} - - -MemFile::MemFile(const std::string& path) -:m_path(path) -,m_temporary(false) -,m_base(m_files[path]) -,m_current_read(NULL) -,m_current_write(NULL) -,m_current_write_nr(0) -,m_read_ptr(0) -,m_write_ptr(0) -,m_b_read_caused_eof(false) -{ - if (!m_base) - { - m_base = new block_t; - m_files[path] = m_base; - } - m_current_read = m_base; - m_current_write = m_base; -} - - -MemFile::~MemFile() -{ - while (m_base && m_temporary) - { - block_t *p = m_base; - m_base = p -> next; - delete p; - } -} - - -bool MemFile::fopen(const std::string& path, const std::string& mode) -{ - return true; -} - - -void MemFile::fclose() -{ -} - - -size_t MemFile::fread(char *ptr, size_t size, size_t nmemb) const -{ - size_t p = m_read_ptr % BLOCKSIZE; - size_t sz = size * nmemb; - size_t available = m_write_ptr - m_read_ptr; - if (sz > available) // read beyond eof - { - sz = available; - m_b_read_caused_eof = true; - } - if (!sz) - { - return 0; - } - if (p + sz < BLOCKSIZE) - { - memcpy(ptr, m_current_read -> data + p, sz); - m_read_ptr += sz; - } - else - { - size_t sz1 = BLOCKSIZE - p; - size_t sz2 = sz - sz1; - memcpy(ptr, m_current_read -> data + p, sz1); - m_read_ptr += sz1; - while (sz2 > BLOCKSIZE) - { - if (m_current_read -> next) - { - m_current_read = m_current_read -> next; - memcpy(ptr + sz1, m_current_read -> data, BLOCKSIZE); - m_read_ptr += BLOCKSIZE; - sz1 += BLOCKSIZE; - sz2 -= BLOCKSIZE; - } - else - { - return sz1; - } - } - if (m_current_read -> next) - { - m_current_read = m_current_read -> next; - memcpy(ptr + sz1, m_current_read -> data, sz2); - m_read_ptr += sz2; - } - else - { - return sz1; - } - } - return sz; -} - - -size_t MemFile::fwrite(const char *ptr, size_t size, size_t nmemb) -{ - size_t p = m_write_ptr % BLOCKSIZE; - int nr = (int)m_write_ptr / BLOCKSIZE; - size_t sz = size * nmemb; - if (m_current_write_nr < nr) - { - block_t *next = new block_t; - m_current_write -> next = next; - m_current_write = next; - m_current_write_nr++; - } - if (p + sz <= BLOCKSIZE) - { - memcpy(m_current_write -> data + p, ptr, sz); - m_write_ptr += sz; - } - else - { - size_t sz1 = BLOCKSIZE - p; // size left - size_t sz2 = sz - sz1; - memcpy(m_current_write -> data + p, ptr, sz1); - m_write_ptr += sz1; - while (sz2 > BLOCKSIZE) - { - if (m_current_write -> next) - { - m_current_write = m_current_write -> next; - m_current_write_nr++; - } - else - { - block_t *next = new block_t; - m_current_write -> next = next; - m_current_write = next; - m_current_write_nr++; - } - memcpy(m_current_write -> data, ptr + sz1, BLOCKSIZE); - m_write_ptr += BLOCKSIZE; - sz1 += BLOCKSIZE; - sz2 -= BLOCKSIZE; - } - if (m_current_write -> next) - { - m_current_write = m_current_write -> next; - m_current_write_nr++; - } - else - { - block_t *next = new block_t; - m_current_write -> next = next; - m_current_write = next; - m_current_write_nr++; - } - memcpy(m_current_write -> data, ptr + sz1, sz2); - m_write_ptr += sz2; - } - return sz; -} - - - -char *MemFile::fgets(char *s, int size) const -{ - int n = 0; - while (n < size - 1 && !eof()) - { - char c; - size_t sz = fread(&c, 1, 1); - if (sz) - { - if (c == 10) - { - s[n] = 0; - return s; - } - s[n++] = c; - } - } - s[n] = 0; - return s; -} - - -void MemFile::fprintf(const char *format, ...) -{ - va_list ap; - char tmp[BLOCKSIZE]; - va_start(ap, format); -#ifdef _WIN32 - vsprintf(tmp, format, ap); -#else - vsnprintf(tmp, BLOCKSIZE - 1, format, ap); -#endif - va_end(ap); - fwrite(tmp, 1, strlen(tmp)); -} - - -off_t MemFile::size() const -{ - return (off_t)m_write_ptr; -} - - -bool MemFile::eof() const -{ - return m_b_read_caused_eof; //(m_read_ptr < m_write_ptr) ? false : true; -} - - -void MemFile::reset_read() const -{ - m_read_ptr = 0; - m_current_read = m_base; -} - - -void MemFile::reset_write() -{ - m_write_ptr = 0; - m_current_write = m_base; - m_current_write_nr = 0; -} - - -#ifdef SOCKETS_NAMESPACE -} -#endif - - diff --git a/Sockets/MemFile.h b/Sockets/MemFile.h deleted file mode 100644 index c97b6bc..0000000 --- a/Sockets/MemFile.h +++ /dev/null @@ -1,100 +0,0 @@ -/** \file MemFile.h - ** \date 2005-04-25 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_MemFile_H -#define _SOCKETS_MemFile_H - -#include "sockets-config.h" -#include -#include "IFile.h" - -#define BLOCKSIZE 32768 - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -/** Implements a memory file. - \ingroup file */ -class MemFile : public IFile -{ -public: - /** File block structure. - \ingroup file */ - struct block_t { - block_t() : next(NULL) {} - struct block_t *next; - char data[BLOCKSIZE]; - }; -public: - MemFile(); - MemFile(const std::string& path); - ~MemFile(); - - bool fopen(const std::string& path, const std::string& mode); - void fclose(); - - size_t fread(char *ptr, size_t size, size_t nmemb) const; - size_t fwrite(const char *ptr, size_t size, size_t nmemb); - - char *fgets(char *s, int size) const; - void fprintf(const char *format, ...); - - off_t size() const; - bool eof() const; - - void reset_read() const; - void reset_write(); - -private: - MemFile(const MemFile& ) {} // copy constructor - MemFile& operator=(const MemFile& ) { return *this; } // assignment operator - -static std::map m_files; - std::string m_path; - bool m_temporary; - block_t *m_base; - mutable block_t *m_current_read; - block_t *m_current_write; - int m_current_write_nr; - mutable size_t m_read_ptr; - size_t m_write_ptr; - mutable bool m_b_read_caused_eof; -}; - - - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_MemFile_H - diff --git a/Sockets/Mutex.cpp b/Sockets/Mutex.cpp deleted file mode 100644 index 4b0e681..0000000 --- a/Sockets/Mutex.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/** \file Mutex.cpp - ** \date 2004-10-30 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#include "Mutex.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -Mutex::Mutex() -{ -#ifdef _WIN32 - m_mutex = ::CreateMutex(NULL, FALSE, NULL); -#else - pthread_mutex_init(&m_mutex, NULL); -#endif -} - - -Mutex::~Mutex() -{ -#ifdef _WIN32 - ::CloseHandle(m_mutex); -#else - pthread_mutex_destroy(&m_mutex); -#endif -} - - -void Mutex::Lock() -{ -#ifdef _WIN32 - DWORD d = WaitForSingleObject(m_mutex, INFINITE); - /// \todo check 'd' for result -#else - pthread_mutex_lock(&m_mutex); -#endif -} - - -void Mutex::Unlock() -{ -#ifdef _WIN32 - ::ReleaseMutex(m_mutex); -#else - pthread_mutex_unlock(&m_mutex); -#endif -} - - -#ifdef SOCKETS_NAMESPACE -} -#endif - diff --git a/Sockets/Mutex.h b/Sockets/Mutex.h deleted file mode 100644 index 1de2776..0000000 --- a/Sockets/Mutex.h +++ /dev/null @@ -1,68 +0,0 @@ -/** \file Mutex.h - ** \date 2004-10-30 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_Mutex_H -#define _SOCKETS_Mutex_H - -#include "sockets-config.h" -#ifndef _WIN32 -#include -#else -#include -#endif - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -/** Mutex container class, used by Lock. - \ingroup threading */ -class Mutex -{ - friend class Lock; -public: - Mutex(); - ~Mutex(); - - void Lock(); - void Unlock(); -private: -#ifdef _WIN32 - HANDLE m_mutex; -#else - pthread_mutex_t m_mutex; -#endif -}; - - -#ifdef SOCKETS_NAMESPACE -} -#endif -#endif // _SOCKETS_Mutex_H - diff --git a/Sockets/OSX.zip b/Sockets/OSX.zip deleted file mode 100755 index e4046a4..0000000 Binary files a/Sockets/OSX.zip and /dev/null differ diff --git a/Sockets/Parse.cpp b/Sockets/Parse.cpp deleted file mode 100644 index 6de56f0..0000000 --- a/Sockets/Parse.cpp +++ /dev/null @@ -1,321 +0,0 @@ -/** \file Parse.cpp - parse a string - ** - ** Written: 1999-Feb-10 grymse@alhem.net - **/ - -/* -Copyright (C) 1999-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#include -#include - -#include "Parse.h" - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -/* implementation of class Parse */ - -Parse::Parse() -:pa_the_str("") -,pa_splits("") -,pa_ord("") -,pa_the_ptr(0) -,pa_breakchar(0) -,pa_enable(0) -,pa_disable(0) -,pa_nospace(0) -,pa_quote(false) -{ -} - -Parse::Parse(const std::string&s) -:pa_the_str(s) -,pa_splits("") -,pa_ord("") -,pa_the_ptr(0) -,pa_breakchar(0) -,pa_enable(0) -,pa_disable(0) -,pa_nospace(0) -,pa_quote(false) -{ -} - -Parse::Parse(const std::string&s,const std::string&sp) -:pa_the_str(s) -,pa_splits(sp) -,pa_ord("") -,pa_the_ptr(0) -,pa_breakchar(0) -,pa_enable(0) -,pa_disable(0) -,pa_nospace(0) -,pa_quote(false) -{ -} - -Parse::Parse(const std::string&s,const std::string&sp,short nospace) -:pa_the_str(s) -,pa_splits(sp) -,pa_ord("") -,pa_the_ptr(0) -,pa_breakchar(0) -,pa_enable(0) -,pa_disable(0) -,pa_nospace(1) -,pa_quote(false) -{ -} - - -Parse::~Parse() -{ -} - -#define C ((pa_the_ptr - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -/***************************************************/ -/* interface of class Parse */ - -/** Splits a string whatever way you want. - \ingroup util */ -class Parse -{ -public: - Parse(); - Parse(const std::string&); - Parse(const std::string&,const std::string&); - Parse(const std::string&,const std::string&,short); - ~Parse(); - short issplit(const char); - void getsplit(); - void getsplit(std::string&); - std::string getword(); - void getword(std::string&); - void getword(std::string&,std::string&,int); - std::string getrest(); - void getrest(std::string&); - long getvalue(); - void setbreak(const char); - int getwordlen(); - int getrestlen(); - void enablebreak(const char c) { - pa_enable = c; - } - void disablebreak(const char c) { - pa_disable = c; - } - void getline(); - void getline(std::string&); - size_t getptr() { return pa_the_ptr; } - void EnableQuote(bool b) { pa_quote = b; } - -private: - std::string pa_the_str; - std::string pa_splits; - std::string pa_ord; - size_t pa_the_ptr; - char pa_breakchar; - char pa_enable; - char pa_disable; - short pa_nospace; - bool pa_quote; -}; - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_Parse_H - diff --git a/Sockets/Project.net/Sockets/Sockets.sln b/Sockets/Project.net/Sockets/Sockets.sln deleted file mode 100644 index 9204f43..0000000 --- a/Sockets/Project.net/Sockets/Sockets.sln +++ /dev/null @@ -1,30 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Sockets", "Sockets.vcproj", "{1EC00E34-E016-4EB4-BF7D-B5B7E101AE57}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "..\Test\Test.vcproj", "{D73A0C4B-7554-4A86-A452-5A12675925A0}" - ProjectSection(ProjectDependencies) = postProject - {1EC00E34-E016-4EB4-BF7D-B5B7E101AE57} = {1EC00E34-E016-4EB4-BF7D-B5B7E101AE57} - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release - EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {1EC00E34-E016-4EB4-BF7D-B5B7E101AE57}.Debug.ActiveCfg = Debug|Win32 - {1EC00E34-E016-4EB4-BF7D-B5B7E101AE57}.Debug.Build.0 = Debug|Win32 - {1EC00E34-E016-4EB4-BF7D-B5B7E101AE57}.Release.ActiveCfg = Release|Win32 - {1EC00E34-E016-4EB4-BF7D-B5B7E101AE57}.Release.Build.0 = Release|Win32 - {D73A0C4B-7554-4A86-A452-5A12675925A0}.Debug.ActiveCfg = Debug|Win32 - {D73A0C4B-7554-4A86-A452-5A12675925A0}.Debug.Build.0 = Debug|Win32 - {D73A0C4B-7554-4A86-A452-5A12675925A0}.Release.ActiveCfg = Release|Win32 - {D73A0C4B-7554-4A86-A452-5A12675925A0}.Release.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution - EndGlobalSection -EndGlobal diff --git a/Sockets/Project.net/Sockets/Sockets.vcproj b/Sockets/Project.net/Sockets/Sockets.vcproj deleted file mode 100644 index 4e008d6..0000000 --- a/Sockets/Project.net/Sockets/Sockets.vcproj +++ /dev/null @@ -1,452 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Sockets/Project.net/Test/Test.vcproj b/Sockets/Project.net/Test/Test.vcproj deleted file mode 100644 index fa24b0e..0000000 --- a/Sockets/Project.net/Test/Test.vcproj +++ /dev/null @@ -1,140 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Sockets/Project/Sockets.dsp b/Sockets/Project/Sockets.dsp deleted file mode 100644 index b9bda66..0000000 --- a/Sockets/Project/Sockets.dsp +++ /dev/null @@ -1,526 +0,0 @@ -# Microsoft Developer Studio Project File - Name="Sockets" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Static Library" 0x0104 - -CFG=Sockets - 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 "Sockets.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 "Sockets.mak" CFG="Sockets - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "Sockets - Win32 Release" (based on "Win32 (x86) Static Library") -!MESSAGE "Sockets - 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)" == "Sockets - 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 "..\..\lib\R" -# PROP Intermediate_Dir "R" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GR /GX /O2 /I "c:\openssl\include" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /FD /c -# SUBTRACT CPP /YX -# 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 -# Begin Special Build Tool -SOURCE="$(InputPath)" -PostBuild_Cmds=xcopy ..\*.h Include /I /Y -# End Special Build Tool - -!ELSEIF "$(CFG)" == "Sockets - 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 "..\..\lib\D" -# PROP Intermediate_Dir "D" -# 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 /MTd /W3 /Gm /GR /GX /ZI /Od /I "c:\openssl\include" /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /FD /GZ /c -# SUBTRACT CPP /YX -# 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 -# Begin Special Build Tool -SOURCE="$(InputPath)" -PostBuild_Cmds=xcopy ..\*.h Include /I /Y -# End Special Build Tool - -!ENDIF - -# Begin Target - -# Name "Sockets - Win32 Release" -# Name "Sockets - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=..\Exception.cpp -# End Source File -# Begin Source File - -SOURCE=..\socket_include.cpp -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=..\Exception.h -# End Source File -# Begin Source File - -SOURCE=..\socket_include.h -# End Source File -# Begin Source File - -SOURCE="..\sockets-config.h" -# End Source File -# End Group -# Begin Group "Utilities" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\Base64.cpp -# End Source File -# Begin Source File - -SOURCE=..\Base64.h -# End Source File -# Begin Source File - -SOURCE=..\Parse.cpp -# End Source File -# Begin Source File - -SOURCE=..\Parse.h -# End Source File -# Begin Source File - -SOURCE=..\RandomNumber.cpp -# End Source File -# Begin Source File - -SOURCE=..\RandomNumber.h -# End Source File -# Begin Source File - -SOURCE=..\Utility.cpp -# End Source File -# Begin Source File - -SOURCE=..\Utility.h -# End Source File -# End Group -# Begin Group "Internal" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\SSLInitializer.cpp -# End Source File -# Begin Source File - -SOURCE=..\SSLInitializer.h -# End Source File -# End Group -# Begin Group "Webserver framework" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\HttpdCookies.cpp -# End Source File -# Begin Source File - -SOURCE=..\HttpdCookies.h -# End Source File -# Begin Source File - -SOURCE=..\HttpdForm.cpp -# End Source File -# Begin Source File - -SOURCE=..\HttpdForm.h -# End Source File -# Begin Source File - -SOURCE=..\HttpdSocket.cpp -# End Source File -# Begin Source File - -SOURCE=..\HttpdSocket.h -# End Source File -# Begin Source File - -SOURCE=..\Ajp13Socket.cpp -# End Source File -# Begin Source File - -SOURCE=..\Ajp13Socket.h -# End Source File -# Begin Source File - -SOURCE=..\AjpBaseSocket.cpp -# End Source File -# Begin Source File - -SOURCE=..\AjpBaseSocket.h -# End Source File -# Begin Source File - -SOURCE=..\HttpBaseSocket.cpp -# End Source File -# Begin Source File - -SOURCE=..\HttpBaseSocket.h -# End Source File -# Begin Source File - -SOURCE=..\HttpTransaction.cpp -# End Source File -# Begin Source File - -SOURCE=..\HttpTransaction.h -# End Source File -# Begin Source File - -SOURCE=..\HttpRequest.cpp -# End Source File -# Begin Source File - -SOURCE=..\HttpRequest.h -# End Source File -# Begin Source File - -SOURCE=..\HttpResponse.cpp -# End Source File -# Begin Source File - -SOURCE=..\HttpResponse.h -# End Source File -# Begin Source File - -SOURCE=..\ajp13.h -# End Source File -# Begin Source File - -SOURCE=..\IHttpServer.h -# End Source File -# End Group -# Begin Group "HTTP Sockets" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\HttpClientSocket.cpp -# End Source File -# Begin Source File - -SOURCE=..\HttpClientSocket.h -# End Source File -# Begin Source File - -SOURCE=..\HttpDebugSocket.cpp -# End Source File -# Begin Source File - -SOURCE=..\HttpDebugSocket.h -# End Source File -# Begin Source File - -SOURCE=..\HttpGetSocket.cpp -# End Source File -# Begin Source File - -SOURCE=..\HttpGetSocket.h -# End Source File -# Begin Source File - -SOURCE=..\HttpPostSocket.cpp -# End Source File -# Begin Source File - -SOURCE=..\HttpPostSocket.h -# End Source File -# Begin Source File - -SOURCE=..\HttpPutSocket.cpp -# End Source File -# Begin Source File - -SOURCE=..\HttpPutSocket.h -# End Source File -# Begin Source File - -SOURCE=..\HTTPSocket.cpp -# End Source File -# Begin Source File - -SOURCE=..\HTTPSocket.h -# End Source File -# End Group -# Begin Group "File handling" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\File.cpp -# End Source File -# Begin Source File - -SOURCE=..\File.h -# End Source File -# Begin Source File - -SOURCE=..\IFile.h -# End Source File -# Begin Source File - -SOURCE=..\MemFile.cpp -# End Source File -# Begin Source File - -SOURCE=..\MemFile.h -# End Source File -# End Group -# Begin Group "Asynchronous DNS" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\ResolvServer.cpp -# End Source File -# Begin Source File - -SOURCE=..\ResolvServer.h -# End Source File -# Begin Source File - -SOURCE=..\ResolvSocket.cpp -# End Source File -# Begin Source File - -SOURCE=..\ResolvSocket.h -# End Source File -# End Group -# Begin Group "Basic Sockets" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\Ipv4Address.cpp -# End Source File -# Begin Source File - -SOURCE=..\Ipv4Address.h -# End Source File -# Begin Source File - -SOURCE=..\Ipv6Address.cpp -# End Source File -# Begin Source File - -SOURCE=..\Ipv6Address.h -# End Source File -# Begin Source File - -SOURCE=..\ISocketHandler.h -# End Source File -# Begin Source File - -SOURCE=..\ListenSocket.h -# End Source File -# Begin Source File - -SOURCE=..\SctpSocket.cpp -# End Source File -# Begin Source File - -SOURCE=..\SctpSocket.h -# End Source File -# Begin Source File - -SOURCE=..\Socket.cpp -# End Source File -# Begin Source File - -SOURCE=..\Socket.h -# End Source File -# Begin Source File - -SOURCE=..\SocketAddress.h -# End Source File -# Begin Source File - -SOURCE=..\SocketHandler.cpp -# End Source File -# Begin Source File - -SOURCE=..\SocketHandler.h -# End Source File -# Begin Source File - -SOURCE=..\StreamSocket.cpp -# End Source File -# Begin Source File - -SOURCE=..\StreamSocket.h -# End Source File -# Begin Source File - -SOURCE=..\TcpSocket.cpp -# End Source File -# Begin Source File - -SOURCE=..\TcpSocket.h -# End Source File -# Begin Source File - -SOURCE=..\UdpSocket.cpp -# End Source File -# Begin Source File - -SOURCE=..\UdpSocket.h -# End Source File -# End Group -# Begin Group "Log help classes" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\StdLog.h -# End Source File -# Begin Source File - -SOURCE=..\StdoutLog.cpp -# End Source File -# Begin Source File - -SOURCE=..\StdoutLog.h -# End Source File -# End Group -# Begin Group "Threading" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\Lock.cpp -# End Source File -# Begin Source File - -SOURCE=..\Lock.h -# End Source File -# Begin Source File - -SOURCE=..\Mutex.cpp -# End Source File -# Begin Source File - -SOURCE=..\Mutex.h -# End Source File -# Begin Source File - -SOURCE=..\Thread.cpp -# End Source File -# Begin Source File - -SOURCE=..\Thread.h -# End Source File -# End Group -# Begin Group "Timer Events" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\Event.cpp -# End Source File -# Begin Source File - -SOURCE=..\Event.h -# End Source File -# Begin Source File - -SOURCE=..\EventHandler.cpp -# End Source File -# Begin Source File - -SOURCE=..\EventHandler.h -# End Source File -# Begin Source File - -SOURCE=..\EventTime.cpp -# End Source File -# Begin Source File - -SOURCE=..\EventTime.h -# End Source File -# Begin Source File - -SOURCE=..\IEventHandler.h -# End Source File -# Begin Source File - -SOURCE=..\IEventOwner.cpp -# End Source File -# Begin Source File - -SOURCE=..\IEventOwner.h -# End Source File -# End Group -# Begin Group "SMTP" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\SmtpdSocket.cpp -# End Source File -# Begin Source File - -SOURCE=..\SmtpdSocket.h -# End Source File -# End Group -# End Target -# End Project diff --git a/Sockets/Project/Sockets.dsw b/Sockets/Project/Sockets.dsw deleted file mode 100644 index 3a7694c..0000000 --- a/Sockets/Project/Sockets.dsw +++ /dev/null @@ -1,68 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 6.00 -# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! - -############################################################################### - -Project: "Sockets"=.\Sockets.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Project: "Test"=.\Test.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ - Begin Project Dependency - Project_Dep_Name Sockets - End Project Dependency -}}} - -############################################################################### - -Project: "echoserver"=.\echoserver.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Project: "stressclient"=.\stressclient.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Global: - -Package=<5> -{{{ -}}} - -Package=<3> -{{{ -}}} - -############################################################################### - diff --git a/Sockets/Project/Test.dsp b/Sockets/Project/Test.dsp deleted file mode 100644 index 74efc10..0000000 --- a/Sockets/Project/Test.dsp +++ /dev/null @@ -1,102 +0,0 @@ -# Microsoft Developer Studio Project File - Name="Test" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Console Application" 0x0103 - -CFG=Test - 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 "Test.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 "Test.mak" CFG="Test - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "Test - Win32 Release" (based on "Win32 (x86) Console Application") -!MESSAGE "Test - 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)" == "Test - 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 "bin\R" -# 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 /MT /W3 /GR /GX /O2 /I "Include" /I "c:\openssl\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "HAVE_OPENSSL" /YX /FD /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 Sockets.lib libeay32md.lib ssleay32md.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\lib\R" /libpath:"c:\openssl\lib\vc" - -!ELSEIF "$(CFG)" == "Test - 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 "bin\D" -# 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 /MTd /W3 /Gm /GR /GX /ZI /Od /I "Include" /I "c:\openssl\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "HAVE_OPENSSL" /YX /FD /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 Sockets.lib libeay32md.lib ssleay32md.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\lib\D" /libpath:"c:\openssl\lib\vc" - -!ENDIF - -# Begin Target - -# Name "Test - Win32 Release" -# Name "Test - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=..\tests\sockets_test.cpp -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" -# End Group -# End Target -# End Project diff --git a/Sockets/Project/echoserver.dsp b/Sockets/Project/echoserver.dsp deleted file mode 100644 index d848565..0000000 --- a/Sockets/Project/echoserver.dsp +++ /dev/null @@ -1,100 +0,0 @@ -# Microsoft Developer Studio Project File - Name="echoserver" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Console Application" 0x0103 - -CFG=echoserver - 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 "echoserver.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 "echoserver.mak" CFG="echoserver - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "echoserver - Win32 Release" (based on "Win32 (x86) Console Application") -!MESSAGE "echoserver - 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)" == "echoserver - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "echoserver___Win32_Release" -# PROP BASE Intermediate_Dir "echoserver___Win32_Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "R" -# PROP Intermediate_Dir "echoserver___Win32_Release" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GR /GX /O2 /I "..\..\Sockets" /I "c:\openssl\include" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "HAVE_OPENSSL" /YX /FD /c -# ADD BASE RSC /l 0x41d /d "NDEBUG" -# ADD RSC /l 0x41d /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 Sockets.lib ssleay32md.lib libeay32md.lib /nologo /subsystem:console /machine:I386 /libpath:"\openssl\lib\vc" /libpath:"..\..\lib\r" - -!ELSEIF "$(CFG)" == "echoserver - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "echoserver___Win32_Debug" -# PROP BASE Intermediate_Dir "echoserver___Win32_Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "D" -# PROP Intermediate_Dir "echoserver___Win32_Debug" -# 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 /MTd /W3 /Gm /GR /GX /ZI /Od /I "..\..\Sockets" /I "c:\openssl\include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "HAVE_OPENSSL" /YX /FD /GZ /c -# ADD BASE RSC /l 0x41d /d "_DEBUG" -# ADD RSC /l 0x41d /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 Sockets.lib ssleay32md.lib libeay32md.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"\openssl\lib\vc" /libpath:"..\..\lib\d" - -!ENDIF - -# Begin Target - -# Name "echoserver - Win32 Release" -# Name "echoserver - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=..\tests\echoserver.cpp -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" -# End Group -# End Target -# End Project diff --git a/Sockets/Project/stressclient.dsp b/Sockets/Project/stressclient.dsp deleted file mode 100644 index 34eb22d..0000000 --- a/Sockets/Project/stressclient.dsp +++ /dev/null @@ -1,100 +0,0 @@ -# Microsoft Developer Studio Project File - Name="stressclient" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Console Application" 0x0103 - -CFG=stressclient - 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 "stressclient.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 "stressclient.mak" CFG="stressclient - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "stressclient - Win32 Release" (based on "Win32 (x86) Console Application") -!MESSAGE "stressclient - 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)" == "stressclient - 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 "R" -# PROP Intermediate_Dir "Release" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GR /GX /O2 /I "..\..\Sockets" /I "c:\openssl\include" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "HAVE_OPENSSL" /YX /FD /c -# ADD BASE RSC /l 0x41d /d "NDEBUG" -# ADD RSC /l 0x41d /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 Sockets.lib ssleay32md.lib libeay32md.lib /nologo /subsystem:console /machine:I386 /libpath:"\openssl\lib\vc" /libpath:"..\..\lib\r" - -!ELSEIF "$(CFG)" == "stressclient - 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 "D" -# PROP Intermediate_Dir "Debug" -# 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 /MTd /W3 /Gm /GR /GX /ZI /Od /I "..\..\Sockets" /I "c:\openssl\include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "HAVE_OPENSSL" /YX /FD /GZ /c -# ADD BASE RSC /l 0x41d /d "_DEBUG" -# ADD RSC /l 0x41d /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 Sockets.lib ssleay32md.lib libeay32md.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"\openssl\lib\vc" /libpath:"..\..\lib\d" - -!ENDIF - -# Begin Target - -# Name "stressclient - Win32 Release" -# Name "stressclient - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=..\tests\stressclient.cpp -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" -# End Group -# End Target -# End Project diff --git a/Sockets/README.macosx b/Sockets/README.macosx deleted file mode 100644 index b886673..0000000 --- a/Sockets/README.macosx +++ /dev/null @@ -1,3 +0,0 @@ -Find uuid.h here - http://www.die.net/doc/linux/include/uuid/uuid.h - diff --git a/Sockets/RandomNumber.cpp b/Sockets/RandomNumber.cpp deleted file mode 100644 index 77ba30d..0000000 --- a/Sockets/RandomNumber.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/** - * @author Adam McLaurin - * @date September 2006 - */ -/* -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GN6U General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#include "RandomNumber.h" -#include -#include - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -const unsigned long int RandomNumber::X_SEED_DEFAULT = 123456789UL; -const unsigned long int RandomNumber::Y_SEED_DEFAULT = 362436069UL; -const unsigned long int RandomNumber::Z_SEED_DEFAULT = 521288629UL; -const unsigned long int RandomNumber::W_SEED_DEFAULT = 88675123UL; - - -RandomNumber::RandomNumber(bool time_shuffle) -:mXSeed(time_shuffle ? (unsigned long)time(NULL) ^ X_SEED_DEFAULT : X_SEED_DEFAULT) -,mYSeed(time_shuffle ? (unsigned long)time(NULL) ^ Y_SEED_DEFAULT : Y_SEED_DEFAULT) -,mZSeed(time_shuffle ? (unsigned long)time(NULL) ^ Z_SEED_DEFAULT : Z_SEED_DEFAULT) -,mWSeed(time_shuffle ? (unsigned long)time(NULL) ^ W_SEED_DEFAULT : W_SEED_DEFAULT) -{ - reset(); -} - -RandomNumber::RandomNumber( - unsigned long int x_seed, - unsigned long int y_seed, - unsigned long int z_seed, - unsigned long int w_seed) -:mXSeed(x_seed) -,mYSeed(y_seed) -,mZSeed(z_seed) -,mWSeed(w_seed) -{ - reset(); -} - -RandomNumber::~RandomNumber() -{ -} - -void RandomNumber::reset() -{ - mX = mXSeed; - mY = mYSeed; - mZ = mZSeed; - mW = mWSeed; -} - -RandomNumber::operator unsigned long int() const -{ - return(mW); -} - -unsigned long int RandomNumber::next() -{ - register unsigned long int t = (mX ^ (mX<<11)); - - mX = mY; - - mY = mZ; - - mZ = mW; - - return(mW = (mW ^ (mW>>19)) ^ (t ^ (t>>8))); -} - -unsigned long int RandomNumber::skip(unsigned long int s) -{ - for(register unsigned long int i = 0 ; i < s ; ++i) - { - (void)next(); - } - - return(mW); -} - -void RandomNumber::getSeed( - unsigned long int& x_seed, - unsigned long int& y_seed, - unsigned long int& z_seed, - unsigned long int& w_seed) -{ - x_seed = mXSeed; - y_seed = mYSeed; - z_seed = mZSeed; - w_seed = mWSeed; -} - -unsigned long int RandomNumber::max_random() -{ - return(std::numeric_limits::max()); -} - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - diff --git a/Sockets/RandomNumber.h b/Sockets/RandomNumber.h deleted file mode 100644 index 376db43..0000000 --- a/Sockets/RandomNumber.h +++ /dev/null @@ -1,202 +0,0 @@ -/** - * @author Adam McLaurin - * @date September 2006 - */ -/* -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#ifndef _SOCKET_RandomNumber_H -#define _SOCKET_RandomNumber_H - -#include "sockets-config.h" -#include - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -/** - * The following class uses an xorshift algorithm proposed in the following - * paper: - * - http://www.jstatsoft.org/v08/i14/xorshift.pdf - * - * The algorithm provides a PRNG with a period of (2^128)-1 - * - * This PRNG is *not* intended for cryptographic purposes - */ -class RandomNumber -{ - -public: - /** - * Default constructor - * - * NOTE: Internal seeds are set to defaults proposed by the paper - */ - RandomNumber(bool time_shuffle = false); - - /** - * Custom constructor - * - * @param x_seed X seed - * - * @param y_seed Y seed - * - * @param z_seed Z seed - * - * @param w_seed W seed - */ - RandomNumber( - unsigned long int x_seed, - unsigned long int y_seed, - unsigned long int z_seed, - unsigned long int w_seed); - - /** - * Destructor - */ - ~RandomNumber(); - - // public methods - - /** - * Reset internal state to initial seed values - */ - void reset(); - - /** - * Cast operator to obtain current random value in the PRNG - * - * @return Current random value in the PRNG - */ - operator unsigned long int() const; - - /** - * Go to the next number in the PRNG sequence - * - * NOTE: This method is a slightly modified implementation of the xor128() - * function proposed in the paper - * - * @return Next value produced by the PRNG (after updating) - */ - unsigned long int next(); - - /** - * Skip ahead in the PRNG sequence by a given number of iterations - * - * @param s Number of iterations to skip ahead - * - * @return Value produced by the PRNG after skipping ahead in the sequence - */ - unsigned long int skip(unsigned long int s); - - /** - * Obtain all the initial seeds for this PRNG - * - * @param x_seed X seed (output) - * - * @param y_seed Y seed (output) - * - * @param z_seed Z seed (output) - * - * @param w_seed W seed (output) - */ - void getSeed( - unsigned long int& x_seed, - unsigned long int& y_seed, - unsigned long int& z_seed, - unsigned long int& w_seed); - - /** - * Get the maximum possible random number from this PRNG - * - * @return Maximum possible random number from this PRNG - */ - static unsigned long int max_random(); - - // public constants - - /** - * Default x-seed as proposed by the paper - */ - static const unsigned long int X_SEED_DEFAULT; - - /** - * Default y-seed as proposed by the paper - */ - static const unsigned long int Y_SEED_DEFAULT; - - /** - * Default z-seed as proposed by the paper - */ - static const unsigned long int Z_SEED_DEFAULT; - - /** - * Default w-seed as proposed by the paper - */ - static const unsigned long int W_SEED_DEFAULT; - -private: - /** - * X seed - */ - unsigned long int mXSeed; - - /** - * Y seed - */ - unsigned long int mYSeed; - - /** - * Z seed - */ - unsigned long int mZSeed; - - /** - * W seed - */ - unsigned long int mWSeed; - - /** - * X value - */ - unsigned long int mX; - - /** - * Y value - */ - unsigned long int mY; - - /** - * Z value - */ - unsigned long int mZ; - - /** - * W value - * - * NOTE: This is the externally-visible next value produced by the PRNG - */ - unsigned long int mW; - -}; - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - -#endif // _SOCKETS_RandomNumber_H - diff --git a/Sockets/ResolvServer.cpp b/Sockets/ResolvServer.cpp deleted file mode 100644 index 83f842b..0000000 --- a/Sockets/ResolvServer.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/** \file ResolvServer.cpp - ** \date 2005-03-24 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif -#include "ResolvServer.h" -#ifdef ENABLE_RESOLVER -#include "StdoutLog.h" -#include "ListenSocket.h" -#include "ResolvSocket.h" -#include "SocketHandler.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -ResolvServer::ResolvServer(port_t port) -:Thread() -,m_quit(false) -,m_port(port) -,m_ready(false) -{ -} - - -ResolvServer::~ResolvServer() -{ -} - - -void ResolvServer::Run() -{ -// StdoutLog log; - SocketHandler h; - ListenSocket l(h); - - if (l.Bind("127.0.0.1", m_port)) - { - return; - } - h.Add(&l); - - m_ready = true; - while (!m_quit && IsRunning() ) - { - h.Select(0, 500000); - } - SetRunning(false); -} - - -void ResolvServer::Quit() -{ - m_quit = true; -} - - -bool ResolvServer::Ready() -{ - return m_ready; -} - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // ENABLE_RESOLVER - diff --git a/Sockets/ResolvServer.h b/Sockets/ResolvServer.h deleted file mode 100644 index f8f8f5a..0000000 --- a/Sockets/ResolvServer.h +++ /dev/null @@ -1,73 +0,0 @@ -/** \file ResolvServer.h - ** \date 2005-03-24 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_ResolvServer_H -#define _SOCKETS_ResolvServer_H -#include "sockets-config.h" -#ifdef ENABLE_RESOLVER -#include "socket_include.h" -#include "Thread.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -/** \defgroup async Asynchronous DNS */ -/** Async DNS resolver thread. - \ingroup async */ -class ResolvServer : public Thread -{ -public: - ResolvServer(port_t); - ~ResolvServer(); - - void Run(); - void Quit(); - - bool Ready(); - -private: - ResolvServer(const ResolvServer& ) {} // copy constructor - ResolvServer& operator=(const ResolvServer& ) { return *this; } // assignment operator - - bool m_quit; - port_t m_port; - bool m_ready; -}; - - - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // ENABLE_RESOLVER -#endif // _SOCKETS_ResolvServer_H - diff --git a/Sockets/ResolvSocket.cpp b/Sockets/ResolvSocket.cpp deleted file mode 100644 index 4a3644f..0000000 --- a/Sockets/ResolvSocket.cpp +++ /dev/null @@ -1,436 +0,0 @@ -/** \file ResolvSocket.cpp - ** \date 2005-03-24 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _WIN32 -#ifdef _MSC_VER -#pragma warning(disable:4786) -#pragma warning(disable:4503) -#endif -#else -#include -#endif -#include "ResolvSocket.h" -#ifdef ENABLE_RESOLVER -#include "Utility.h" -#include "Parse.h" -#include "ISocketHandler.h" -#include "Lock.h" -#include "Mutex.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -#ifdef _DEBUG -#define DEB(x) x -#else -#define DEB(x) -#endif - - -// static -ResolvSocket::cache_t ResolvSocket::m_cache; -ResolvSocket::timeout_t ResolvSocket::m_cache_to; -Mutex ResolvSocket::m_cache_mutex; - - -ResolvSocket::ResolvSocket(ISocketHandler& h) -:TcpSocket(h) -,m_bServer(false) -,m_parent(NULL) -#ifdef ENABLE_IPV6 -,m_resolve_ipv6(false) -#endif -,m_cached(false) -{ - SetLineProtocol(); -} - - -ResolvSocket::ResolvSocket(ISocketHandler& h, Socket *parent, const std::string& host, port_t port, bool ipv6) -:TcpSocket(h) -,m_bServer(false) -,m_parent(parent) -,m_resolv_host(host) -,m_resolv_port(port) -#ifdef ENABLE_IPV6 -,m_resolve_ipv6(ipv6) -#endif -,m_cached(false) -{ - SetLineProtocol(); -} - - -ResolvSocket::ResolvSocket(ISocketHandler& h, Socket *parent, ipaddr_t a) -:TcpSocket(h) -,m_bServer(false) -,m_parent(parent) -,m_resolv_port(0) -,m_resolv_address(a) -#ifdef ENABLE_IPV6 -,m_resolve_ipv6(false) -#endif -,m_cached(false) -{ - SetLineProtocol(); -} - - -#ifdef ENABLE_IPV6 -ResolvSocket::ResolvSocket(ISocketHandler& h, Socket *parent, in6_addr& a) -:TcpSocket(h) -,m_bServer(false) -,m_parent(parent) -,m_resolv_port(0) -,m_resolve_ipv6(true) -,m_resolv_address6(a) -,m_cached(false) -{ - SetLineProtocol(); -} -#endif - - -ResolvSocket::~ResolvSocket() -{ -} - - -void ResolvSocket::OnLine(const std::string& line) -{ - Parse pa(line, ":"); - if (m_bServer) - { - m_query = pa.getword(); - m_data = pa.getrest(); -DEB( fprintf(stderr, " *** ResolvSocket server; query=%s, data=%s\n", m_query.c_str(), m_data.c_str());) - // %! check cache - { - Lock lock(m_cache_mutex); - if (m_cache[m_query].find(m_data) != m_cache[m_query].end()) - { - if (time(NULL) - m_cache_to[m_query][m_data] < 3600) // ttl - { - std::string result = m_cache[m_query][m_data]; -DEB(fprintf(stderr, " *** Returning cache for [%s][%s] = '%s'\n", m_query.c_str(), m_data.c_str(), result.c_str());) - Send("Cached\n"); - if (!result.size()) /* failed */ - { - Send("Failed\n\n"); - SetCloseAndDelete(); - return; - } - else - if (m_query == "gethostbyname") - { - Send("A: " + result + "\n\n"); - SetCloseAndDelete(); - return; - } - else -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (m_query == "gethostbyname2") - { - Send("AAAA: " + result + "\n\n"); - SetCloseAndDelete(); - return; - } - else -#endif -#endif - if (m_query == "gethostbyaddr") - { - Send("Name: " + result + "\n\n"); - SetCloseAndDelete(); - return; - } - } - } - } - if (!Detach()) // detach failed? - { - SetCloseAndDelete(); - } - return; - } - std::string key = pa.getword(); - std::string value = pa.getrest(); -DEB( fprintf(stderr, " *** ResolvSocket response; %s: %s\n", key.c_str(), value.c_str());) - - if (key == "Cached") - { - m_cached = true; - } - else - if (key == "Failed" && m_parent) - { -DEB( fprintf(stderr, " ************ Resolve failed\n");) - if (Handler().Resolving(m_parent) || Handler().Valid(m_parent)) - { - m_parent -> OnResolveFailed(m_resolv_id); - } - // update cache - if (!m_cached) - { - Lock lock(m_cache_mutex); -DEB(fprintf(stderr, " *** Update cache for [%s][%s] = '%s'\n", m_query.c_str(), m_data.c_str(), value.c_str());) - m_cache[m_query][m_data] = value; - m_cache_to[m_query][m_data] = time(NULL); - } - m_parent = NULL; - } - else - if (key == "Name" && !m_resolv_host.size() && m_parent) - { - if (Handler().Resolving(m_parent) || Handler().Valid(m_parent)) - { - m_parent -> OnReverseResolved(m_resolv_id, value); - } - // update cache - if (!m_cached) - { - Lock lock(m_cache_mutex); -DEB(fprintf(stderr, " *** Update cache for [%s][%s] = '%s'\n", m_query.c_str(), m_data.c_str(), value.c_str());) - m_cache[m_query][m_data] = value; - m_cache_to[m_query][m_data] = time(NULL); - } - m_parent = NULL; - } - else - if (key == "A" && m_parent) - { - if (Handler().Resolving(m_parent) || Handler().Valid(m_parent)) - { - ipaddr_t l; - Utility::u2ip(value, l); // ip2ipaddr_t - m_parent -> OnResolved(m_resolv_id, l, m_resolv_port); - } - // update cache - if (!m_cached) - { - Lock lock(m_cache_mutex); -DEB(fprintf(stderr, " *** Update cache for [%s][%s] = '%s'\n", m_query.c_str(), m_data.c_str(), value.c_str());) - m_cache[m_query][m_data] = value; - m_cache_to[m_query][m_data] = time(NULL); - } - m_parent = NULL; // always use first ip in case there are several - } -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - else - if (key == "AAAA" && m_parent) - { - if (Handler().Resolving(m_parent) || Handler().Valid(m_parent)) - { - in6_addr a; - Utility::u2ip(value, a); - m_parent -> OnResolved(m_resolv_id, a, m_resolv_port); - } - // update cache - if (!m_cached) - { - Lock lock(m_cache_mutex); -DEB(fprintf(stderr, " *** Update cache for [%s][%s] = '%s'\n", m_query.c_str(), m_data.c_str(), value.c_str());) - m_cache[m_query][m_data] = value; - m_cache_to[m_query][m_data] = time(NULL); - } - m_parent = NULL; - } -#endif -#endif -} - - -void ResolvSocket::OnDetached() -{ -DEB( fprintf(stderr, " *** ResolvSocket::OnDetached(); query=%s, data=%s\n", m_query.c_str(), m_data.c_str());) - if (m_query == "gethostbyname") - { - struct sockaddr_in sa; - if (Utility::u2ip(m_data, sa)) - { - std::string ip; - Utility::l2ip(sa.sin_addr, ip); - Send("A: " + ip + "\n"); - } - else - { - Send("Failed\n"); - } - Send("\n"); - } - else -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (m_query == "gethostbyname2") - { - struct sockaddr_in6 sa; - if (Utility::u2ip(m_data, sa)) - { - std::string ip; - Utility::l2ip(sa.sin6_addr, ip); - Send("AAAA: " + ip + "\n"); - } - else - { - Send("Failed\n"); - } - Send("\n"); - } - else -#endif -#endif - if (m_query == "gethostbyaddr") - { - if (Utility::isipv4( m_data )) - { - struct sockaddr_in sa; - if (!Utility::u2ip(m_data, sa, AI_NUMERICHOST)) - { - Send("Failed: convert to sockaddr_in failed\n"); - } - else - { - std::string name; - if (!Utility::reverse( (struct sockaddr *)&sa, sizeof(sa), name)) - { - Send("Failed: ipv4 reverse lookup of " + m_data + "\n"); - } - else - { - Send("Name: " + name + "\n"); - } - } - } - else -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (Utility::isipv6( m_data )) - { - struct sockaddr_in6 sa; - if (!Utility::u2ip(m_data, sa, AI_NUMERICHOST)) - { - Send("Failed: convert to sockaddr_in6 failed\n"); - } - else - { - std::string name; - if (!Utility::reverse( (struct sockaddr *)&sa, sizeof(sa), name)) - { - Send("Failed: ipv6 reverse lookup of " + m_data + "\n"); - } - else - { - Send("Name: " + name + "\n"); - } - } - } - else -#endif -#endif - { - Send("Failed: malformed address\n"); - } - Send("\n"); - } - else - { - std::string msg = "Unknown query type: " + m_query; - Handler().LogError(this, "OnDetached", 0, msg); - Send("Unknown\n\n"); - } - SetCloseAndDelete(); -} - - -void ResolvSocket::OnConnect() -{ - if (m_resolv_host.size()) - { -#ifdef ENABLE_IPV6 - std::string msg = (m_resolve_ipv6 ? "gethostbyname2 " : "gethostbyname ") + m_resolv_host + "\n"; - m_query = m_resolve_ipv6 ? "gethostbyname2" : "gethostbyname"; -#else - std::string msg = "gethostbyname " + m_resolv_host + "\n"; - m_query = "gethostbyname"; -#endif - m_data = m_resolv_host; - Send( msg ); - return; - } -#ifdef ENABLE_IPV6 - if (m_resolve_ipv6) - { - std::string tmp; - Utility::l2ip(m_resolv_address6, tmp); - m_query = "gethostbyaddr"; - m_data = tmp; - std::string msg = "gethostbyaddr " + tmp + "\n"; - Send( msg ); - } -#endif - std::string tmp; - Utility::l2ip(m_resolv_address, tmp); - m_query = "gethostbyaddr"; - m_data = tmp; - std::string msg = "gethostbyaddr " + tmp + "\n"; - Send( msg ); -} - - -void ResolvSocket::OnDelete() -{ - if (m_parent) - { - if (Handler().Resolving(m_parent) || Handler().Valid(m_parent)) - { - m_parent -> OnResolveFailed(m_resolv_id); - } - // update cache - if (!m_cached) - { - Lock lock(m_cache_mutex); - std::string value; -DEB(fprintf(stderr, " *** Update cache for [%s][%s] = '%s'\n", m_query.c_str(), m_data.c_str(), value.c_str());) - m_cache[m_query][m_data] = value; - m_cache_to[m_query][m_data] = time(NULL); - } - m_parent = NULL; - } -} - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // ENABLE_RESOLVER - diff --git a/Sockets/ResolvSocket.h b/Sockets/ResolvSocket.h deleted file mode 100644 index ff4b1a5..0000000 --- a/Sockets/ResolvSocket.h +++ /dev/null @@ -1,106 +0,0 @@ -/** \file ResolvSocket.h - ** \date 2005-03-24 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_ResolvSocket_H -#define _SOCKETS_ResolvSocket_H -#include "sockets-config.h" -#ifdef ENABLE_RESOLVER -#include "TcpSocket.h" -#include - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -class Mutex; - -/** Async DNS resolver socket. - \ingroup async */ -class ResolvSocket : public TcpSocket -{ - typedef std::map > cache_t; /* host, result */ - typedef std::map > timeout_t; /* host, time */ - -public: - ResolvSocket(ISocketHandler&); - ResolvSocket(ISocketHandler&, Socket *parent, const std::string& host, port_t port, bool ipv6 = false); - ResolvSocket(ISocketHandler&, Socket *parent, ipaddr_t); -#ifdef ENABLE_IPV6 - ResolvSocket(ISocketHandler&, Socket *parent, in6_addr&); -#endif - ~ResolvSocket(); - - void OnAccept() { m_bServer = true; } - void OnLine(const std::string& line); - void OnDetached(); - void OnDelete(); - - void SetId(int x) { m_resolv_id = x; } - int GetId() { return m_resolv_id; } - - void OnConnect(); - -#ifdef ENABLE_IPV6 - void SetResolveIpv6(bool x = true) { m_resolve_ipv6 = x; } -#endif - -private: - ResolvSocket(const ResolvSocket& s) : TcpSocket(s) {} // copy constructor - ResolvSocket& operator=(const ResolvSocket& ) { return *this; } // assignment operator - - std::string m_query; - std::string m_data; - bool m_bServer; - Socket *m_parent; - int m_resolv_id; - std::string m_resolv_host; - port_t m_resolv_port; - ipaddr_t m_resolv_address; -#ifdef ENABLE_IPV6 - bool m_resolve_ipv6; - in6_addr m_resolv_address6; -#endif - static cache_t m_cache; - static timeout_t m_cache_to; - static Mutex m_cache_mutex; - bool m_cached; -}; - - - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // ENABLE_RESOLVER -#endif // _SOCKETS_ResolvSocket_H - diff --git a/Sockets/SSLInitializer.cpp b/Sockets/SSLInitializer.cpp deleted file mode 100644 index 65218b1..0000000 --- a/Sockets/SSLInitializer.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/** - ** \file SSLInitializer.cpp - ** \date 2007-04-30 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _WIN32 -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif -#include -#endif -#include "SSLInitializer.h" -#ifdef HAVE_OPENSSL -#include -#include "Utility.h" -#include -#include "Mutex.h" - -#ifdef _DEBUG -#define DEB(x) x -#else -#define DEB(x) -#endif - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - - -SSLInitializer::SSLInitializer() -{ -DEB( fprintf(stderr, "SSLInitializer()\n");) - - bio_err = NULL; - m_rand_size = 1024; - - /* An error write context */ - bio_err = BIO_new_fp(stderr, BIO_NOCLOSE); - - /* Global system initialization*/ - SSL_library_init(); - SSL_load_error_strings(); - OpenSSL_add_all_algorithms(); - CRYPTO_set_locking_callback( SSL_locking_function ); - CRYPTO_set_id_callback( SSL_id_function ); - - char *randfile = getenv("RANDFILE"); - char *home = getenv("HOME"); - if (!randfile && !home) - { - char *homepath = getenv("HOMEPATH"); - if (homepath) - { - Utility::SetEnv("HOME", homepath); - } - } - char path[512]; - *path = 0; - RAND_file_name(path, 512); - if (*path) - { - m_rand_file = path; - m_rand_size = 1024; - RAND_write_file(path); - } - else - { -DEB( fprintf(stderr, "SSLInitializer: no random file generated\n");) - } - - /* Load randomness */ - if (!m_rand_file.size() || !RAND_load_file(m_rand_file.c_str(), m_rand_size)) - { -DEB( fprintf(stderr, "SSLInitializer: PRNG not initialized\n");) - } - -} - - -SSLInitializer::~SSLInitializer() -{ -DEB( fprintf(stderr, "~SSLInitializer()\n");) - DeleteRandFile(); - // %! delete mutexes -} - - -void SSLInitializer::DeleteRandFile() -{ - if (m_rand_file.size()) - { - unlink(m_rand_file.c_str()); - } -} - - -void SSLInitializer::SSL_locking_function(int mode, int n, const char *file, int line) -{ -static std::map mmap; - if (mmap.find(n) == mmap.end()) - { - mmap[n] = new Mutex; - } - if (mode & CRYPTO_LOCK) - { - mmap[n] -> Lock(); - } - else - { - mmap[n] -> Unlock(); - } -} - - -unsigned long SSLInitializer::SSL_id_function() -{ - return Utility::ThreadID(); -} - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif -#endif // HAVE_OPENSSL - diff --git a/Sockets/SSLInitializer.h b/Sockets/SSLInitializer.h deleted file mode 100644 index 9f81d1c..0000000 --- a/Sockets/SSLInitializer.h +++ /dev/null @@ -1,76 +0,0 @@ -/** - ** \file SSLInitializer.h - ** \date 2007-04-30 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef __SOCKETS_SSLInitializer_H -#define __SOCKETS_SSLInitializer_H -#include "sockets-config.h" -#ifdef HAVE_OPENSSL - -#include -#include - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -class SSLInitializer -{ -public: - /** - init openssl - bio_err - create random file - */ - SSLInitializer(); - - /** - remove random file - */ - ~SSLInitializer(); - - void DeleteRandFile(); - - /** SSL; mutex locking function callback. */ -static void SSL_locking_function(int mode, int n, const char *file, int line); - - /** Return thread id. */ -static unsigned long SSL_id_function(); - - BIO *bio_err; - -private: - std::string m_rand_file; - long m_rand_size; - -}; - - - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif -#endif // HAVE_OPENSSL -#endif // __SOCKETS_SSLInitializer_H - diff --git a/Sockets/SctpSocket.cpp b/Sockets/SctpSocket.cpp deleted file mode 100644 index 2267086..0000000 --- a/Sockets/SctpSocket.cpp +++ /dev/null @@ -1,496 +0,0 @@ -/** - ** \file SctpSocket.cpp - ** \date 2006-09-04 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#include "SctpSocket.h" -#ifdef USE_SCTP -#include "Utility.h" -#include "ISocketHandler.h" -#include -#include "Ipv4Address.h" -#include "Ipv6Address.h" -#ifdef ENABLE_EXCEPTIONS -#include "Exception.h" -#endif - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE -{ -#endif - - -SctpSocket::SctpSocket(ISocketHandler& h,int type) : StreamSocket(h) -,m_type(type) -,m_buf(new char[SCTP_BUFSIZE_READ]) -{ - if (type != SOCK_STREAM && type != SOCK_SEQPACKET) - { - } -} - - -SctpSocket::~SctpSocket() -{ - delete[] m_buf; -} - - -int SctpSocket::Bind(const std::string& a,port_t p) -{ -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (IsIpv6()) - { - Ipv6Address ad(a, p); - return Bind(ad); - } -#endif -#endif - Ipv4Address ad(a, p); - return Bind(ad); -} - - -int SctpSocket::Bind(SocketAddress& ad) -{ - if (!ad.IsValid()) - { - Handler().LogError(this, "SctpSocket", -1, "invalid address", LOG_LEVEL_ERROR); - return -1; - } - if (GetSocket() == INVALID_SOCKET) - { - Attach(CreateSocket(ad.GetFamily(), m_type, "sctp")); - } - if (GetSocket() != INVALID_SOCKET) - { - int n = bind(GetSocket(), ad, ad); - if (n == -1) - { - Handler().LogError(this, "SctpSocket", -1, "bind() failed", LOG_LEVEL_ERROR); -#ifdef ENABLE_EXCEPTIONS - throw Exception("bind() failed for SctpSocket, port: " + Utility::l2string(ad.GetPort())); -#endif - } - return n; - } - return -1; -} - - -int SctpSocket::AddAddress(const std::string& a,port_t p) -{ -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (IsIpv6()) - { - Ipv6Address ad(a, p); - return AddAddress(ad); - } -#endif -#endif - Ipv4Address ad(a, p); - return AddAddress(ad); -} - - -int SctpSocket::AddAddress(SocketAddress& ad) -{ - if (!ad.IsValid()) - { - Handler().LogError(this, "SctpSocket", -1, "invalid address", LOG_LEVEL_ERROR); - return -1; - } - if (GetSocket() == INVALID_SOCKET) - { - Handler().LogError(this, "SctpSocket", -1, "AddAddress called with invalid file descriptor", LOG_LEVEL_ERROR); - return -1; - } - int n = sctp_bindx(GetSocket(), ad, ad, SCTP_BINDX_ADD_ADDR); - if (n == -1) - { - Handler().LogError(this, "SctpSocket", -1, "sctp_bindx() failed", LOG_LEVEL_ERROR); - } - return n; -} - - -int SctpSocket::RemoveAddress(const std::string& a,port_t p) -{ -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (IsIpv6()) - { - Ipv6Address ad(a, p); - return RemoveAddress(ad); - } -#endif -#endif - Ipv4Address ad(a, p); - return RemoveAddress(ad); -} - - -int SctpSocket::RemoveAddress(SocketAddress& ad) -{ - if (!ad.IsValid()) - { - Handler().LogError(this, "SctpSocket", -1, "invalid address", LOG_LEVEL_ERROR); - return -1; - } - if (GetSocket() == INVALID_SOCKET) - { - Handler().LogError(this, "SctpSocket", -1, "RemoveAddress called with invalid file descriptor", LOG_LEVEL_ERROR); - return -1; - } - int n = sctp_bindx(GetSocket(), ad, ad, SCTP_BINDX_REM_ADDR); - if (n == -1) - { - Handler().LogError(this, "SctpSocket", -1, "sctp_bindx() failed", LOG_LEVEL_ERROR); - } - return n; -} - - -int SctpSocket::Open(const std::string& a,port_t p) -{ -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (IsIpv6()) - { - Ipv6Address ad(a, p); - return Open(ad); - } -#endif -#endif - Ipv4Address ad(a, p); - return Open(ad); -} - - -int SctpSocket::Open(SocketAddress& ad) -{ - if (!ad.IsValid()) - { - Handler().LogError(this, "SctpSocket", -1, "invalid address", LOG_LEVEL_ERROR); - return -1; - } - if (GetSocket() == INVALID_SOCKET) - { - Attach(CreateSocket(ad.GetFamily(), m_type, "sctp")); - } - if (GetSocket() != INVALID_SOCKET) - { - if (!SetNonblocking(true)) - { - return -1; - } - int n = connect(GetSocket(), ad, ad); - if (n == -1) - { - // check error code that means a connect is in progress -#ifdef _WIN32 - if (Errno == WSAEWOULDBLOCK) -#else - if (Errno == EINPROGRESS) -#endif - { - Handler().LogError(this, "connect: connection pending", Errno, StrError(Errno), LOG_LEVEL_INFO); - SetConnecting( true ); // this flag will control fd_set's - } - else - { - Handler().LogError(this, "SctpSocket", -1, "connect() failed", LOG_LEVEL_ERROR); - } - } - return n; - } - return -1; -} - - -#ifndef SOLARIS -int SctpSocket::AddConnection(const std::string& a,port_t p) -{ -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (IsIpv6()) - { - Ipv6Address ad(a, p); - return AddConnection(ad); - } -#endif -#endif - Ipv4Address ad(a, p); - return AddConnection(ad); -} - - -int SctpSocket::AddConnection(SocketAddress& ad) -{ - if (!ad.IsValid()) - { - Handler().LogError(this, "SctpSocket", -1, "invalid address", LOG_LEVEL_ERROR); - return -1; - } - if (GetSocket() == INVALID_SOCKET) - { - Handler().LogError(this, "SctpSocket", -1, "AddConnection called with invalid file descriptor", LOG_LEVEL_ERROR); - return -1; - } - int n = sctp_connectx(GetSocket(), ad, ad); - if (n == -1) - { - Handler().LogError(this, "SctpSocket", -1, "sctp_connectx() failed", LOG_LEVEL_ERROR); - } - else - { - SetConnecting(); - } - return n; -} -#endif - - -int SctpSocket::getpaddrs(sctp_assoc_t id,std::list& vec) -{ - struct sockaddr *p = NULL; - int n = sctp_getpaddrs(GetSocket(), id, &p); - if (!n || n == -1) - { - Handler().LogError(this, "SctpSocket", -1, "sctp_getpaddrs failed", LOG_LEVEL_WARNING); - return n; - } - for (int i = 0; i < n; i++) - { - vec.push_back(Utility::Sa2String(&p[i])); - } - sctp_freepaddrs(p); - return n; -} - - -int SctpSocket::getladdrs(sctp_assoc_t id,std::list& vec) -{ - struct sockaddr *p = NULL; - int n = sctp_getladdrs(GetSocket(), id, &p); - if (!n || n == -1) - { - Handler().LogError(this, "SctpSocket", -1, "sctp_getladdrs failed", LOG_LEVEL_WARNING); - return n; - } - for (int i = 0; i < n; i++) - { - vec.push_back(Utility::Sa2String(&p[i])); - } - sctp_freeladdrs(p); - return n; -} - - -int SctpSocket::PeelOff(sctp_assoc_t id) -{ - int n = sctp_peeloff(GetSocket(), id); - if (n == -1) - { - Handler().LogError(this, "SctpSocket", -1, "PeelOff failed", LOG_LEVEL_WARNING); - return -1; - } - Socket *p = Create(); - p -> Attach(n); - p -> SetDeleteByHandler(); - Handler().Add(p); - return n; -} - - -void SctpSocket::OnRead() -{ -/* - int sctp_recvmsg(int sd, void * msg, size_t * len, - struct sockaddr * from, socklen_t * fromlen, - struct sctp_sndrcvinfo * sinfo, int * msg_flags); - - DESCRIPTION - sctp_recvmsg is a wrapper library function that can be used to receive a message from a socket while using the advanced - features of SCTP. sd is the socket descriptor on which the message pointed to by msg of length len is received. - - If from is not NULL, the source address of the message is filled in. The argument fromlen is a value-result parameter. - initialized to the size of the buffer associated with from , and modified on return to indicate the actual size of the - address stored. - - sinfo is a pointer to a sctp_sndrcvinfo structure to be filled upon receipt of the message. msg_flags is a pointer to a - integer that is filled with any message flags like MSG_NOTIFICATION or MSG_EOR. - -*/ - struct sockaddr sa; - socklen_t sa_len = 0; - struct sctp_sndrcvinfo sinfo; - int flags = 0; - int n = sctp_recvmsg(GetSocket(), m_buf, SCTP_BUFSIZE_READ, &sa, &sa_len, &sinfo, &flags); - if (n == -1) - { - Handler().LogError(this, "SctpSocket", Errno, StrError(Errno), LOG_LEVEL_FATAL); - SetCloseAndDelete(); - } - else - { - OnReceiveMessage(m_buf, n, &sa, sa_len, &sinfo, flags); - } -} - - -void SctpSocket::OnReceiveMessage(const char *buf,size_t sz,struct sockaddr *sa,socklen_t sa_len,struct sctp_sndrcvinfo *sinfo,int msg_flags) -{ -} - - -void SctpSocket::OnWrite() -{ - if (Connecting()) - { - int err = SoError(); - - // don't reset connecting flag on error here, we want the OnConnectFailed timeout later on - /// \todo add to read fd_set here - if (!err) // ok - { - Set(!IsDisableRead(), false); - SetConnecting(false); - SetCallOnConnect(); - return; - } - Handler().LogError(this, "sctp: connect failed", err, StrError(err), LOG_LEVEL_FATAL); - Set(false, false); // no more monitoring because connection failed - - // failed -#ifdef ENABLE_SOCKS4 - if (Socks4()) - { - OnSocks4ConnectFailed(); - return; - } -#endif - if (GetConnectionRetry() == -1 || - (GetConnectionRetry() && GetConnectionRetries() < GetConnectionRetry()) ) - { - // even though the connection failed at once, only retry after - // the connection timeout. - // should we even try to connect again, when CheckConnect returns - // false it's because of a connection error - not a timeout... - return; - } - SetConnecting(false); - SetCloseAndDelete( true ); - /// \todo state reason why connect failed - OnConnectFailed(); - return; - } -} - - -void SctpSocket::OnConnectTimeout() -{ - Handler().LogError(this, "connect", -1, "connect timeout", LOG_LEVEL_FATAL); -#ifdef ENABLE_SOCKS4 - if (Socks4()) - { - OnSocks4ConnectFailed(); - // retry direct connection - } - else -#endif - if (GetConnectionRetry() == -1 || - (GetConnectionRetry() && GetConnectionRetries() < GetConnectionRetry()) ) - { - IncreaseConnectionRetries(); - // ask socket via OnConnectRetry callback if we should continue trying - if (OnConnectRetry()) - { - SetRetryClientConnect(); - } - else - { - SetCloseAndDelete( true ); - /// \todo state reason why connect failed - OnConnectFailed(); - } - } - else - { - SetCloseAndDelete(true); - /// \todo state reason why connect failed - OnConnectFailed(); - } - // - SetConnecting(false); -} - - -#ifdef _WIN32 -void SctpSocket::OnException() -{ - if (Connecting()) - { -#ifdef ENABLE_SOCKS4 - if (Socks4()) - OnSocks4ConnectFailed(); - else -#endif - if (GetConnectionRetry() == -1 || - (GetConnectionRetry() && - GetConnectionRetries() < GetConnectionRetry() )) - { - // even though the connection failed at once, only retry after - // the connection timeout - // should we even try to connect again, when CheckConnect returns - // false it's because of a connection error - not a timeout... - } - else - { - SetConnecting(false); // tnx snibbe - SetCloseAndDelete(); - OnConnectFailed(); - } - return; - } - // %! exception doesn't always mean something bad happened, this code should be reworked - // errno valid here? - int err = SoError(); - Handler().LogError(this, "exception on select", err, StrError(err), LOG_LEVEL_FATAL); - SetCloseAndDelete(); -} -#endif // _WIN32 - - -int SctpSocket::Protocol() -{ - return IPPROTO_SCTP; -} - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE -#endif - - -#endif // USE_SCTP - diff --git a/Sockets/SctpSocket.h b/Sockets/SctpSocket.h deleted file mode 100644 index 12e72a0..0000000 --- a/Sockets/SctpSocket.h +++ /dev/null @@ -1,110 +0,0 @@ -/** - ** \file SctpSocket.h - ** \date 2006-09-04 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_SctpSocket_H -#define _SOCKETS_SctpSocket_H -#include "sockets-config.h" - -#include -#include "StreamSocket.h" -#ifdef USE_SCTP -#include - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -#define SCTP_BUFSIZE_READ 16400 - -class SocketAddress; - - -class SctpSocket : public StreamSocket -{ -public: - /** SctpSocket constructor. - \param h Owner - \param type SCTP_STREAM or SCTP_SEQPACKET */ - SctpSocket(ISocketHandler& h,int type); - ~SctpSocket(); - - /** bind() */ - int Bind(const std::string&,port_t); - int Bind(SocketAddress&); - /** sctp_bindx() */ - int AddAddress(const std::string&,port_t); - int AddAddress(SocketAddress&); - /** sctp_bindx() */ - int RemoveAddress(const std::string&,port_t); - int RemoveAddress(SocketAddress&); - - /** connect() */ - int Open(const std::string&,port_t); - int Open(SocketAddress&); - - /** Connect timeout callback. */ - void OnConnectTimeout(); -#ifdef _WIN32 - /** Connection failed reported as exception on win32 */ - void OnException(); -#endif - -#ifndef SOLARIS - /** sctp_connectx() */ - int AddConnection(const std::string&,port_t); - int AddConnection(SocketAddress&); -#endif - - /** Get peer addresses of an association. */ - int getpaddrs(sctp_assoc_t id,std::list&); - /** Get all bound addresses of an association. */ - int getladdrs(sctp_assoc_t id,std::list&); - - /** sctp_peeloff */ - int PeelOff(sctp_assoc_t id); - - /** recvmsg callback */ - virtual void OnReceiveMessage(const char *buf,size_t sz,struct sockaddr *sa,socklen_t sa_len,struct sctp_sndrcvinfo *sinfo,int msg_flags) = 0; - - void OnOptions(int,int,int,SOCKET) {} - - virtual int Protocol(); - -protected: - SctpSocket(const SctpSocket& s) : StreamSocket(s) {} - void OnRead(); - void OnWrite(); - -private: - SctpSocket& operator=(const SctpSocket& s) { return *this; } - int m_type; ///< SCTP_STREAM or SCTP_SEQPACKET - char *m_buf; ///< Temporary receive buffer -}; - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE -#endif - -#endif // USE_SCTP -#endif // _SOCKETS_SctpSocket_H - diff --git a/Sockets/Semaphore.cpp b/Sockets/Semaphore.cpp deleted file mode 100644 index 93cefc7..0000000 --- a/Sockets/Semaphore.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/** - ** \file Semaphore.cpp - ** \date 2007-04-13 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#include "Semaphore.h" - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -Semaphore::Semaphore() -{ - sem_init(&m_sem, 0, 0); -} - - -Semaphore::Semaphore(unsigned int start_val) -{ - sem_init(&m_sem, 0, start_val); -} - - -Semaphore::~Semaphore() -{ - sem_destroy(&m_sem); -} - - -int Semaphore::Post() -{ - return sem_post(&m_sem); -} - - -int Semaphore::Wait() -{ - return sem_wait(&m_sem); -} - - -int Semaphore::TryWait() -{ - return sem_trywait(&m_sem); -} - - -int Semaphore::GetValue(int& i) -{ - return sem_getvalue(&m_sem, &i); -} - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - diff --git a/Sockets/Semaphore.h b/Sockets/Semaphore.h deleted file mode 100644 index acafea4..0000000 --- a/Sockets/Semaphore.h +++ /dev/null @@ -1,67 +0,0 @@ -/** - ** \file Semaphore.h - ** \date 2007-04-13 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_Semaphore_H -#define _SOCKETS_Semaphore_H - -#include "sockets-config.h" -#include -#ifdef MACOSX -#include -#else -#include -#endif - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -/** pthread semaphore wrapper. - \ingroup threading */ -class Semaphore -{ -public: - Semaphore(); - Semaphore(unsigned int start_val); - ~Semaphore(); - - int Post(); - int Wait(); - int TryWait(); - int GetValue(int&); - -private: - Semaphore(const Semaphore& ) {} // copy constructor - Semaphore& operator=(const Semaphore& ) { return *this; } // assignment operator - sem_t m_sem; -}; - - - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif -#endif // _SOCKETS_Semaphore_H - diff --git a/Sockets/SmtpdSocket.cpp b/Sockets/SmtpdSocket.cpp deleted file mode 100644 index 0d62925..0000000 --- a/Sockets/SmtpdSocket.cpp +++ /dev/null @@ -1,234 +0,0 @@ -/** - ** \file SmtpdSocket.cpp - ** \date 2007-05-10 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#include "SmtpdSocket.h" -#include "Parse.h" -#include "Utility.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -SmtpdSocket::SmtpdSocket(ISocketHandler& h) -:TcpSocket(h) -,m_hello(false) -,m_data(false) -,m_header(false) -{ - SetLineProtocol(); -} - - -void SmtpdSocket::OnAccept() -{ - Send("220 ESMTP; \r\n"); -} - - -void SmtpdSocket::OnLine(const std::string& line) -{ - if (m_data) - { - if (m_header) - { - if (!line.size()) - { - if (m_header_line.size()) - { - Parse pa(m_header_line, ":"); - std::string key = pa.getword(); - OnHeader(key, pa.getrest()); - } - m_header = false; - OnHeaderComplete(); - } - else - if (line[0] == ' ' || line[0] == '\t') - { - m_header_line += line; - } - else - { - if (m_header_line.size()) - { - Parse pa(m_header_line, ":"); - std::string key = pa.getword(); - OnHeader(key, pa.getrest()); - } - m_header_line = line; - } - } - else - if (line == ".") - { - m_data = false; - if (OnDataComplete()) - Send("250 OK\r\n"); - else - Send("550 Failed\r\n"); - } - else - if (line.size() && line[0] == '.') - { - OnData(line.substr(1)); - } - else - { - OnData(line); - } - return; - } - Parse pa(line); - std::string cmd = Utility::ToUpper(pa.getword()); - - if (cmd == "EHLO") - { - if (!OnHello(pa.getrest())) - { - Send("550 Failed\r\n"); - } - else - { - m_hello = true; - Send("250 mail.alhem.net\r\n"); - } - } - else - if (cmd == "HELO") - { - if (!OnHello(pa.getrest())) - { - Send("550 Failed\r\n"); - } - else - { - m_hello = true; - Send("250 mail.alhem.net\r\n"); - } - } - else - if (!m_hello) - { - OnAbort(SMTP_NO_HELLO); - SetCloseAndDelete(); - } - else - if (cmd == "MAIL") // mail from: - { - Parse pa(line, ":"); - pa.getword(); // 'mail' - pa.getword(); // 'from' - std::string email = Utility::ToLower(pa.getrest()); - - EmailAddress addr( email ); - if (addr.GetName().size() > 64) - { - OnAbort(SMTP_NAME_TOO_LONG); - Send("500 Name too long.\r\n"); - return; - } - if (addr.GetDomain().size() > 64) - { - OnAbort(SMTP_DOMAIN_TOO_LONG); - Send("500 Domain too long.\r\n"); - return; - } - - if (!OnMailFrom( addr )) - { - Send("550 Failed\r\n"); - } - else - { - Send("250 OK\r\n"); - } - } - else - if (cmd == "RCPT") // rcpt to: - { - Parse pa(line, ":"); - pa.getword(); // 'rcpt' - pa.getword(); // 'to' - std::string email = Utility::ToLower(pa.getrest()); - // %! reject based on user / domain? - EmailAddress addr( email ); - - if (addr.GetName().size() > 64) - { - OnAbort(SMTP_NAME_TOO_LONG); - Send("500 Name too long.\r\n"); - return; - } - if (addr.GetDomain().size() > 64) - { - OnAbort(SMTP_DOMAIN_TOO_LONG); - Send("500 Domain too long.\r\n"); - return; - } - - if (!OnRcptTo( addr )) - { - Send("553 Failed\r\n"); - } - else - { - Send("250 OK\r\n"); - } - } - else - if (cmd == "DATA") - { - Send("354 Enter mail, end with \".\" on a line by itself\r\n"); - m_data = true; - m_header = false; - } - else - if (cmd == "RSET") - { - m_data = false; - m_header = false; - OnRset(); - Send("250 OK\r\n"); // %! ??? - } - else - if (cmd == "QUIT") - { - OnAbort(SMTP_QUIT); - Send("221 Bye Bye\r\n"); - SetCloseAndDelete(); - } - else - if (cmd == "NOOP") - { - Send("250 OK\r\n"); - } - else - { - OnNotSupported(cmd, pa.getrest()); - } -} - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - diff --git a/Sockets/SmtpdSocket.h b/Sockets/SmtpdSocket.h deleted file mode 100644 index d884d05..0000000 --- a/Sockets/SmtpdSocket.h +++ /dev/null @@ -1,143 +0,0 @@ -/** - ** \file SmtpdSocket.h - ** \date 2007-05-10 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_SmtpdSocket_H -#define _SOCKETS_SmtpdSocket_H - -#include "sockets-config.h" -#include -#include "TcpSocket.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -/** Smtp server base class. */ -class SmtpdSocket : public TcpSocket -{ -protected: - typedef enum { - SMTP_NO_HELLO, - SMTP_NAME_TOO_LONG, - SMTP_DOMAIN_TOO_LONG, - SMTP_QUIT - } reason_t; - -public: - class EmailAddress { - public: - EmailAddress(const std::string& str_in) - { - std::string str = str_in; - size_t i = str.find("<"); - if (i != std::string::npos) - str = str.substr(i + 1); - i = str.find("@"); - if (i != std::string::npos) - { - m_name = str.substr(0, i); - str = str.substr(i + 1); - i = str.find(">"); - if (i != std::string::npos) - str = str.substr(0, i); - m_domain = str; - } - while (m_name.size() && m_name[m_name.size() - 1] == ' ') - m_name.resize(m_name.size() - 1); - while (m_domain.size() && m_domain[m_domain.size() - 1] == ' ') - m_domain.resize(m_domain.size() - 1); - while (m_name.size() && m_name[0] == ' ') - m_name = m_name.substr(1); - while (m_domain.size() && m_domain[0] == ' ') - m_domain = m_domain.substr(1); - m_top = m_domain; - { - for (size_t i = 0; i < m_domain.size(); i++) - { - if (m_domain[i] == '.') - { - m_sub = m_top; - m_top = m_domain.substr(i + 1); - } - } - } - } - - const std::string& GetName() const { return m_name; } - const std::string& GetDomain() const { return m_domain; } - const std::string& GetTopDomain() const { return m_top; } - const std::string& GetSubDomain() const { return m_sub; } - - std::string ToString() const { return m_name + "@" + m_domain; } - - private: - std::string m_name; - std::string m_domain; - std::string m_top; - std::string m_sub; - }; - -public: - SmtpdSocket(ISocketHandler&); - - void OnAccept(); - void OnLine(const std::string&); - - /** \return 'false' to abort */ - virtual bool OnHello(const std::string& domain) = 0; - - /** \return 'false' to abort */ - virtual bool OnMailFrom(const EmailAddress& addr) = 0; - - /** \return 'false' to abort */ - virtual bool OnRcptTo(const EmailAddress& addr) = 0; - - virtual void OnHeader(const std::string& key, const std::string& value) = 0; - - virtual void OnHeaderComplete() = 0; - - virtual void OnData(const std::string& line) = 0; - - /** \return 'false' if message write failed (message will probably be resent) */ - virtual bool OnDataComplete() = 0; - - virtual void OnRset() = 0; - - virtual void OnAbort(reason_t) = 0; - - virtual void OnNotSupported(const std::string& cmd, const std::string& arg) = 0; - -private: - bool m_hello; // we need HELO or EHLO first of all - bool m_data; - bool m_header; - std::string m_header_line; -}; - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - -#endif // _SOCKETS_SmtpdSocket_H - diff --git a/Sockets/Socket.cpp b/Sockets/Socket.cpp deleted file mode 100644 index 42d2c23..0000000 --- a/Sockets/Socket.cpp +++ /dev/null @@ -1,1896 +0,0 @@ -/** \file Socket.cpp - ** \date 2004-02-13 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#include "Socket.h" -#ifdef _WIN32 -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif -#include -#else -#include -#include -#endif -#include -#include - -#include "ISocketHandler.h" -#include "Utility.h" - -#include "SocketAddress.h" -#include "SocketHandler.h" -#ifdef ENABLE_EXCEPTIONS -#include "Exception.h" -#endif -#include "Ipv4Address.h" - -#ifdef _DEBUG -#define DEB(x) x; fflush(stderr); -#else -#define DEB(x) -#endif - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -// statics -#ifdef _WIN32 -WSAInitializer Socket::m_winsock_init; -#endif - - -Socket::Socket(ISocketHandler& h) -//:m_flags(0) -:m_handler(h) -,m_socket( INVALID_SOCKET ) -,m_bDel(false) -,m_bClose(false) -,m_tCreate(time(NULL)) -,m_parent(NULL) -,m_b_disable_read(false) -,m_connected(false) -,m_b_erased_by_handler(false) -,m_tClose(0) -,m_client_remote_address(NULL) -,m_remote_address(NULL) -,m_traffic_monitor(NULL) -#ifdef HAVE_OPENSSL -,m_b_enable_ssl(false) -,m_b_ssl(false) -,m_b_ssl_server(false) -#endif -#ifdef ENABLE_IPV6 -,m_ipv6(false) -#endif -#ifdef ENABLE_POOL -,m_socket_type(0) -,m_bClient(false) -,m_bRetain(false) -,m_bLost(false) -#endif -#ifdef ENABLE_SOCKS4 -,m_bSocks4(false) -,m_socks4_host(h.GetSocks4Host()) -,m_socks4_port(h.GetSocks4Port()) -,m_socks4_userid(h.GetSocks4Userid()) -#endif -#ifdef ENABLE_DETACH -,m_detach(false) -,m_detached(false) -,m_pThread(NULL) -,m_slave_handler(NULL) -#endif -{ -} - - -Socket::~Socket() -{ - Handler().Remove(this); - if (m_socket != INVALID_SOCKET -#ifdef ENABLE_POOL - && !m_bRetain -#endif - ) - { - Close(); - } -} - - -void Socket::Init() -{ -} - - -void Socket::OnRead() -{ -} - - -void Socket::OnWrite() -{ -} - - -void Socket::OnException() -{ - // %! exception doesn't always mean something bad happened, this code should be reworked - // errno valid here? - int err = SoError(); - Handler().LogError(this, "exception on select", err, StrError(err), LOG_LEVEL_FATAL); - SetCloseAndDelete(); -} - - -void Socket::OnDelete() -{ -} - - -void Socket::OnConnect() -{ -} - - -void Socket::OnAccept() -{ -} - - -int Socket::Close() -{ - if (m_socket == INVALID_SOCKET) // this could happen - { - Handler().LogError(this, "Socket::Close", 0, "file descriptor invalid", LOG_LEVEL_WARNING); - return 0; - } - int n; - if ((n = closesocket(m_socket)) == -1) - { - // failed... - Handler().LogError(this, "close", Errno, StrError(Errno), LOG_LEVEL_ERROR); - } - Handler().Set(m_socket, false, false, false); // remove from fd_set's - Handler().AddList(m_socket, LIST_CALLONCONNECT, false); -#ifdef ENABLE_DETACH - Handler().AddList(m_socket, LIST_DETACH, false); -#endif - Handler().AddList(m_socket, LIST_TIMEOUT, false); - Handler().AddList(m_socket, LIST_RETRY, false); - Handler().AddList(m_socket, LIST_CLOSE, false); - m_socket = INVALID_SOCKET; - return n; -} - - -SOCKET Socket::CreateSocket(int af,int type, const std::string& protocol) -{ - struct protoent *p = NULL; - SOCKET s; - -#ifdef ENABLE_POOL - m_socket_type = type; - m_socket_protocol = protocol; -#endif - if (protocol.size()) - { - p = getprotobyname( protocol.c_str() ); - if (!p) - { - Handler().LogError(this, "getprotobyname", Errno, StrError(Errno), LOG_LEVEL_FATAL); - SetCloseAndDelete(); -#ifdef ENABLE_EXCEPTIONS - throw Exception(std::string("getprotobyname() failed: ") + StrError(Errno)); -#endif - return INVALID_SOCKET; - } - } - int protno = p ? p -> p_proto : 0; - - s = socket(af, type, protno); - if (s == INVALID_SOCKET) - { - Handler().LogError(this, "socket", Errno, StrError(Errno), LOG_LEVEL_FATAL); - SetCloseAndDelete(); -#ifdef ENABLE_EXCEPTIONS - throw Exception(std::string("socket() failed: ") + StrError(Errno)); -#endif - return INVALID_SOCKET; - } - Attach(s); - OnOptions(af, type, protno, s); - Attach(INVALID_SOCKET); - return s; -} - - -void Socket::Attach(SOCKET s) -{ - m_socket = s; -} - - -SOCKET Socket::GetSocket() -{ - return m_socket; -} - - -void Socket::SetDeleteByHandler(bool x) -{ - m_bDel = x; -} - - -bool Socket::DeleteByHandler() -{ - return m_bDel; -} - - -void Socket::SetCloseAndDelete(bool x) -{ - if (x != m_bClose) - { - Handler().AddList(m_socket, LIST_CLOSE, x); - m_bClose = x; - if (x) - { - m_tClose = time(NULL); - } - } -} - - -bool Socket::CloseAndDelete() -{ - return m_bClose; -} - - -void Socket::SetRemoteAddress(SocketAddress& ad) //struct sockaddr* sa, socklen_t l) -{ - m_remote_address = ad.GetCopy(); -} - - -std::auto_ptr Socket::GetRemoteSocketAddress() -{ - return std::auto_ptr(m_remote_address -> GetCopy()); -} - - -ISocketHandler& Socket::Handler() const -{ -#ifdef ENABLE_DETACH - if (IsDetached()) - return *m_slave_handler; -#endif - return m_handler; -} - - -ISocketHandler& Socket::MasterHandler() const -{ - return m_handler; -} - - -ipaddr_t Socket::GetRemoteIP4() -{ - ipaddr_t l = 0; -#ifdef ENABLE_IPV6 - if (m_ipv6) - { - Handler().LogError(this, "GetRemoteIP4", 0, "get ipv4 address for ipv6 socket", LOG_LEVEL_WARNING); - } -#endif - if (m_remote_address.get() != NULL) - { - struct sockaddr *p = *m_remote_address; - struct sockaddr_in *sa = (struct sockaddr_in *)p; - memcpy(&l, &sa -> sin_addr, sizeof(struct in_addr)); - } - return l; -} - - -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 -struct in6_addr Socket::GetRemoteIP6() -{ - if (!m_ipv6) - { - Handler().LogError(this, "GetRemoteIP6", 0, "get ipv6 address for ipv4 socket", LOG_LEVEL_WARNING); - } - struct sockaddr_in6 fail; - if (m_remote_address.get() != NULL) - { - struct sockaddr *p = *m_remote_address; - memcpy(&fail, p, sizeof(struct sockaddr_in6)); - } - else - { - memset(&fail, 0, sizeof(struct sockaddr_in6)); - } - return fail.sin6_addr; -} -#endif -#endif - - -port_t Socket::GetRemotePort() -{ - if (!m_remote_address.get()) - { - return 0; - } - return m_remote_address -> GetPort(); -} - - -std::string Socket::GetRemoteAddress() -{ - if (!m_remote_address.get()) - { - return ""; - } - return m_remote_address -> Convert(false); -} - - -std::string Socket::GetRemoteHostname() -{ - if (!m_remote_address.get()) - { - return ""; - } - return m_remote_address -> Reverse(); -} - - -bool Socket::SetNonblocking(bool bNb) -{ -#ifdef _WIN32 - unsigned long l = bNb ? 1 : 0; - int n = ioctlsocket(m_socket, FIONBIO, &l); - if (n != 0) - { - Handler().LogError(this, "ioctlsocket(FIONBIO)", Errno, ""); - return false; - } - return true; -#else - if (bNb) - { - if (fcntl(m_socket, F_SETFL, O_NONBLOCK) == -1) - { - Handler().LogError(this, "fcntl(F_SETFL, O_NONBLOCK)", Errno, StrError(Errno), LOG_LEVEL_ERROR); - return false; - } - } - else - { - if (fcntl(m_socket, F_SETFL, 0) == -1) - { - Handler().LogError(this, "fcntl(F_SETFL, 0)", Errno, StrError(Errno), LOG_LEVEL_ERROR); - return false; - } - } - return true; -#endif -} - - -bool Socket::SetNonblocking(bool bNb, SOCKET s) -{ -#ifdef _WIN32 - unsigned long l = bNb ? 1 : 0; - int n = ioctlsocket(s, FIONBIO, &l); - if (n != 0) - { - Handler().LogError(this, "ioctlsocket(FIONBIO)", Errno, ""); - return false; - } - return true; -#else - if (bNb) - { - if (fcntl(s, F_SETFL, O_NONBLOCK) == -1) - { - Handler().LogError(this, "fcntl(F_SETFL, O_NONBLOCK)", Errno, StrError(Errno), LOG_LEVEL_ERROR); - return false; - } - } - else - { - if (fcntl(s, F_SETFL, 0) == -1) - { - Handler().LogError(this, "fcntl(F_SETFL, 0)", Errno, StrError(Errno), LOG_LEVEL_ERROR); - return false; - } - } - return true; -#endif -} - - -void Socket::Set(bool bRead, bool bWrite, bool bException) -{ - Handler().Set(m_socket, bRead, bWrite, bException); -} - - -bool Socket::Ready() -{ - if (m_socket != INVALID_SOCKET && !CloseAndDelete()) - return true; - return false; -} - - -void Socket::OnLine(const std::string& ) -{ -} - - -void Socket::OnConnectFailed() -{ -} - - -Socket *Socket::GetParent() -{ - return m_parent; -} - - -void Socket::SetParent(Socket *x) -{ - m_parent = x; -} - - -port_t Socket::GetPort() -{ - Handler().LogError(this, "GetPort", 0, "GetPort only implemented for ListenSocket", LOG_LEVEL_WARNING); - return 0; -} - - -bool Socket::OnConnectRetry() -{ - return true; -} - - -#ifdef ENABLE_RECONNECT -void Socket::OnReconnect() -{ -} -#endif - - -time_t Socket::Uptime() -{ - return time(NULL) - m_tCreate; -} - - -#ifdef ENABLE_IPV6 -void Socket::SetIpv6(bool x) -{ - m_ipv6 = x; -} - - -bool Socket::IsIpv6() -{ - return m_ipv6; -} -#endif - - -void Socket::DisableRead(bool x) -{ - m_b_disable_read = x; -} - - -bool Socket::IsDisableRead() -{ - return m_b_disable_read; -} - - -void Socket::SendBuf(const char *,size_t,int) -{ -} - - -void Socket::Send(const std::string&,int) -{ -} - - -void Socket::SetConnected(bool x) -{ - m_connected = x; -} - - -bool Socket::IsConnected() -{ - return m_connected; -} - - -void Socket::OnDisconnect() -{ -} - - -void Socket::SetErasedByHandler(bool x) -{ - m_b_erased_by_handler = x; -} - - -bool Socket::ErasedByHandler() -{ - return m_b_erased_by_handler; -} - - -time_t Socket::TimeSinceClose() -{ - return time(NULL) - m_tClose; -} - - -void Socket::SetClientRemoteAddress(SocketAddress& ad) -{ - if (!ad.IsValid()) - { - Handler().LogError(this, "SetClientRemoteAddress", 0, "remote address not valid", LOG_LEVEL_ERROR); - } - m_client_remote_address = ad.GetCopy(); -} - - -std::auto_ptr Socket::GetClientRemoteAddress() -{ - if (!m_client_remote_address.get()) - { - Handler().LogError(this, "GetClientRemoteAddress", 0, "remote address not yet set", LOG_LEVEL_ERROR); - } - return std::auto_ptr(m_client_remote_address -> GetCopy()); -} - - -uint64_t Socket::GetBytesSent(bool) -{ - return 0; -} - - -uint64_t Socket::GetBytesReceived(bool) -{ - return 0; -} - - -#ifdef HAVE_OPENSSL -void Socket::OnSSLConnect() -{ -} - - -void Socket::OnSSLAccept() -{ -} - - -bool Socket::SSLNegotiate() -{ - return false; -} - - -bool Socket::IsSSL() -{ - return m_b_enable_ssl; -} - - -void Socket::EnableSSL(bool x) -{ - m_b_enable_ssl = x; -} - - -bool Socket::IsSSLNegotiate() -{ - return m_b_ssl; -} - - -void Socket::SetSSLNegotiate(bool x) -{ - m_b_ssl = x; -} - - -bool Socket::IsSSLServer() -{ - return m_b_ssl_server; -} - - -void Socket::SetSSLServer(bool x) -{ - m_b_ssl_server = x; -} - - -void Socket::OnSSLConnectFailed() -{ -} - - -void Socket::OnSSLAcceptFailed() -{ -} -#endif // HAVE_OPENSSL - - -#ifdef ENABLE_POOL -void Socket::CopyConnection(Socket *sock) -{ - Attach( sock -> GetSocket() ); -#ifdef ENABLE_IPV6 - SetIpv6( sock -> IsIpv6() ); -#endif - SetSocketType( sock -> GetSocketType() ); - SetSocketProtocol( sock -> GetSocketProtocol() ); - - SetClientRemoteAddress( *sock -> GetClientRemoteAddress() ); - SetRemoteAddress( *sock -> GetRemoteSocketAddress() ); -} - - -void Socket::SetIsClient() -{ - m_bClient = true; -} - - -void Socket::SetSocketType(int x) -{ - m_socket_type = x; -} - - -int Socket::GetSocketType() -{ - return m_socket_type; -} - - -void Socket::SetSocketProtocol(const std::string& x) -{ - m_socket_protocol = x; -} - - -const std::string& Socket::GetSocketProtocol() -{ - return m_socket_protocol; -} - - -void Socket::SetRetain() -{ - if (m_bClient) m_bRetain = true; -} - - -bool Socket::Retain() -{ - return m_bRetain; -} - - -void Socket::SetLost() -{ - m_bLost = true; -} - - -bool Socket::Lost() -{ - return m_bLost; -} -#endif // ENABLE_POOL - - -#ifdef ENABLE_SOCKS4 -void Socket::OnSocks4Connect() -{ - Handler().LogError(this, "OnSocks4Connect", 0, "Use with TcpSocket only"); -} - - -void Socket::OnSocks4ConnectFailed() -{ - Handler().LogError(this, "OnSocks4ConnectFailed", 0, "Use with TcpSocket only"); -} - - -bool Socket::OnSocks4Read() -{ - Handler().LogError(this, "OnSocks4Read", 0, "Use with TcpSocket only"); - return true; -} - - -void Socket::SetSocks4Host(const std::string& host) -{ - Utility::u2ip(host, m_socks4_host); -} - - -bool Socket::Socks4() -{ - return m_bSocks4; -} - - -void Socket::SetSocks4(bool x) -{ - m_bSocks4 = x; -} - - -void Socket::SetSocks4Host(ipaddr_t a) -{ - m_socks4_host = a; -} - - -void Socket::SetSocks4Port(port_t p) -{ - m_socks4_port = p; -} - - -void Socket::SetSocks4Userid(const std::string& x) -{ - m_socks4_userid = x; -} - - -ipaddr_t Socket::GetSocks4Host() -{ - return m_socks4_host; -} - - -port_t Socket::GetSocks4Port() -{ - return m_socks4_port; -} - - -const std::string& Socket::GetSocks4Userid() -{ - return m_socks4_userid; -} -#endif // ENABLE_SOCKS4 - - -#ifdef ENABLE_DETACH -bool Socket::Detach() -{ - if (!DeleteByHandler()) - return false; - if (m_pThread) - return false; - if (m_detached) - return false; - SetDetach(); - return true; -} - - -void Socket::DetachSocket() -{ - SetDetached(); - m_pThread = new SocketThread(this); - m_pThread -> SetRelease(true); -} - - -void Socket::OnDetached() -{ -} - - -void Socket::SetDetach(bool x) -{ - Handler().AddList(m_socket, LIST_DETACH, x); - m_detach = x; -} - - -bool Socket::IsDetach() -{ - return m_detach; -} - - -void Socket::SetDetached(bool x) -{ - m_detached = x; -} - - -const bool Socket::IsDetached() const -{ - return m_detached; -} - - -void Socket::SetSlaveHandler(ISocketHandler *p) -{ - m_slave_handler = p; -} - - -Socket::SocketThread::SocketThread(Socket *p) -:Thread(false) -,m_socket(p) -{ - // Creator will release -} - - -Socket::SocketThread::~SocketThread() -{ - if (IsRunning()) - { - SetRelease(true); - SetRunning(false); -#ifdef _WIN32 - Sleep(1000); -#else - sleep(1); -#endif - } -} - - -void Socket::SocketThread::Run() -{ - SocketHandler h; - h.SetSlave(); - h.Add(m_socket); - m_socket -> SetSlaveHandler(&h); - m_socket -> OnDetached(); - while (h.GetCount() && IsRunning()) - { - h.Select(0, 500000); - } - // m_socket now deleted oops - // yeah oops m_socket delete its socket thread, that means this - // so Socket will no longer delete its socket thread, instead we do this: - SetDeleteOnExit(); -} -#endif // ENABLE_DETACH - - -#ifdef ENABLE_RESOLVER -int Socket::Resolve(const std::string& host,port_t port) -{ - return Handler().Resolve(this, host, port); -} - - -#ifdef ENABLE_IPV6 -int Socket::Resolve6(const std::string& host,port_t port) -{ - return Handler().Resolve6(this, host, port); -} -#endif - - -int Socket::Resolve(ipaddr_t a) -{ - return Handler().Resolve(this, a); -} - - -#ifdef ENABLE_IPV6 -int Socket::Resolve(in6_addr& a) -{ - return Handler().Resolve(this, a); -} -#endif - - -void Socket::OnResolved(int,ipaddr_t,port_t) -{ -} - - -#ifdef ENABLE_IPV6 -void Socket::OnResolved(int,in6_addr&,port_t) -{ -} -#endif - - -void Socket::OnReverseResolved(int,const std::string&) -{ -} - - -void Socket::OnResolveFailed(int) -{ -} -#endif // ENABLE_RESOLVER - - -/* IP options */ - - -bool Socket::SetIpOptions(const void *p, socklen_t len) -{ -#ifdef IP_OPTIONS - if (setsockopt(GetSocket(), IPPROTO_IP, IP_OPTIONS, (char *)p, len) == -1) - { - Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_OPTIONS)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -#else - Handler().LogError(this, "ip option not available", 0, "IP_OPTIONS", LOG_LEVEL_INFO); - return false; -#endif -} - - -#ifdef IP_PKTINFO -bool Socket::SetIpPktinfo(bool x) -{ - int optval = x ? 1 : 0; - if (setsockopt(GetSocket(), IPPROTO_IP, IP_PKTINFO, (char *)&optval, sizeof(optval)) == -1) - { - Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_PKTINFO)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -} -#endif - - -#ifdef IP_RECVTOS -bool Socket::SetIpRecvTOS(bool x) -{ - int optval = x ? 1 : 0; - if (setsockopt(GetSocket(), IPPROTO_IP, IP_RECVTOS, (char *)&optval, sizeof(optval)) == -1) - { - Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_RECVTOS)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -} -#endif - - -#ifdef IP_RECVTTL -bool Socket::SetIpRecvTTL(bool x) -{ - int optval = x ? 1 : 0; - if (setsockopt(GetSocket(), IPPROTO_IP, IP_RECVTTL, (char *)&optval, sizeof(optval)) == -1) - { - Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_RECVTTL)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -} -#endif - - -#ifdef IP_RECVOPTS -bool Socket::SetIpRecvopts(bool x) -{ - int optval = x ? 1 : 0; - if (setsockopt(GetSocket(), IPPROTO_IP, IP_RECVOPTS, (char *)&optval, sizeof(optval)) == -1) - { - Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_RECVOPTS)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -} -#endif - - -#ifdef IP_RETOPTS -bool Socket::SetIpRetopts(bool x) -{ - int optval = x ? 1 : 0; - if (setsockopt(GetSocket(), IPPROTO_IP, IP_RETOPTS, (char *)&optval, sizeof(optval)) == -1) - { - Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_RETOPTS)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -} -#endif - - -bool Socket::SetIpTOS(unsigned char tos) -{ -#ifdef IP_TOS - if (setsockopt(GetSocket(), IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(tos)) == -1) - { - Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_TOS)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -#else - Handler().LogError(this, "ip option not available", 0, "IP_TOS", LOG_LEVEL_INFO); - return false; -#endif -} - - -unsigned char Socket::IpTOS() -{ - unsigned char tos = 0; -#ifdef IP_TOS - socklen_t len = sizeof(tos); - if (getsockopt(GetSocket(), IPPROTO_IP, IP_TOS, (char *)&tos, &len) == -1) - { - Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_TOS)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - } -#else - Handler().LogError(this, "ip option not available", 0, "IP_TOS", LOG_LEVEL_INFO); -#endif - return tos; -} - - -bool Socket::SetIpTTL(int ttl) -{ -#ifdef IP_TTL - if (setsockopt(GetSocket(), IPPROTO_IP, IP_TTL, (char *)&ttl, sizeof(ttl)) == -1) - { - Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_TTL)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -#else - Handler().LogError(this, "ip option not available", 0, "IP_TTL", LOG_LEVEL_INFO); - return false; -#endif -} - - -int Socket::IpTTL() -{ - int ttl = 0; -#ifdef IP_TTL - socklen_t len = sizeof(ttl); - if (getsockopt(GetSocket(), IPPROTO_IP, IP_TTL, (char *)&ttl, &len) == -1) - { - Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_TTL)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - } -#else - Handler().LogError(this, "ip option not available", 0, "IP_TTL", LOG_LEVEL_INFO); -#endif - return ttl; -} - - -bool Socket::SetIpHdrincl(bool x) -{ -#ifdef IP_HDRINCL - int optval = x ? 1 : 0; - if (setsockopt(GetSocket(), IPPROTO_IP, IP_HDRINCL, (char *)&optval, sizeof(optval)) == -1) - { - Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_HDRINCL)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -#else - Handler().LogError(this, "ip option not available", 0, "IP_HDRINCL", LOG_LEVEL_INFO); - return false; -#endif -} - - -#ifdef IP_RECVERR -bool Socket::SetIpRecverr(bool x) -{ - int optval = x ? 1 : 0; - if (setsockopt(GetSocket(), IPPROTO_IP, IP_RECVERR, (char *)&optval, sizeof(optval)) == -1) - { - Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_RECVERR)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -} -#endif - - -#ifdef IP_MTU_DISCOVER -bool Socket::SetIpMtudiscover(bool x) -{ - int optval = x ? 1 : 0; - if (setsockopt(GetSocket(), IPPROTO_IP, IP_MTU_DISCOVER, (char *)&optval, sizeof(optval)) == -1) - { - Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_MTU_DISCOVER)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -} -#endif - - -#ifdef IP_MTU -int Socket::IpMtu() -{ - int mtu = 0; - socklen_t len = sizeof(mtu); - if (getsockopt(GetSocket(), IPPROTO_IP, IP_MTU, (char *)&mtu, &len) == -1) - { - Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_MTU)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - } - return mtu; -} -#endif - - -#ifdef IP_ROUTER_ALERT -bool Socket::SetIpRouterAlert(bool x) -{ - int optval = x ? 1 : 0; - if (setsockopt(GetSocket(), IPPROTO_IP, IP_ROUTER_ALERT, (char *)&optval, sizeof(optval)) == -1) - { - Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_ROUTER_ALERT)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -} -#endif - - -bool Socket::SetIpMulticastTTL(int ttl) -{ -#ifdef IP_MULTICAST_TTL - if (setsockopt(GetSocket(), IPPROTO_IP, IP_MULTICAST_TTL, (char *)&ttl, sizeof(ttl)) == -1) - { - Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_MULTICAST_TTL)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -#else - Handler().LogError(this, "ip option not available", 0, "IP_MULTICAST_TTL", LOG_LEVEL_INFO); - return false; -#endif -} - - -int Socket::IpMulticastTTL() -{ - int ttl = 0; -#ifdef IP_MULTICAST_TTL - socklen_t len = sizeof(ttl); - if (getsockopt(GetSocket(), IPPROTO_IP, IP_MULTICAST_TTL, (char *)&ttl, &len) == -1) - { - Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_MULTICAST_TTL)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - } -#else - Handler().LogError(this, "ip option not available", 0, "IP_MULTICAST_TTL", LOG_LEVEL_INFO); -#endif - return ttl; -} - - -bool Socket::SetMulticastLoop(bool x) -{ -#ifdef IP_MULTICAST_LOOP - int optval = x ? 1 : 0; - if (setsockopt(GetSocket(), IPPROTO_IP, IP_MULTICAST_LOOP, (char *)&optval, sizeof(optval)) == -1) - { - Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_MULTICAST_LOOP)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -#else - Handler().LogError(this, "ip option not available", 0, "IP_MULTICAST_LOOP", LOG_LEVEL_INFO); - return false; -#endif -} - - -#ifdef LINUX -bool Socket::IpAddMembership(struct ip_mreqn& ref) -{ -#ifdef IP_ADD_MEMBERSHIP - if (setsockopt(GetSocket(), IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&ref, sizeof(struct ip_mreqn)) == -1) - { - Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_ADD_MEMBERSHIP)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -#else - Handler().LogError(this, "ip option not available", 0, "IP_ADD_MEMBERSHIP", LOG_LEVEL_INFO); - return false; -#endif -} -#endif - - -bool Socket::IpAddMembership(struct ip_mreq& ref) -{ -#ifdef IP_ADD_MEMBERSHIP - if (setsockopt(GetSocket(), IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&ref, sizeof(struct ip_mreq)) == -1) - { - Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_ADD_MEMBERSHIP)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -#else - Handler().LogError(this, "ip option not available", 0, "IP_ADD_MEMBERSHIP", LOG_LEVEL_INFO); - return false; -#endif -} - - -#ifdef LINUX -bool Socket::IpDropMembership(struct ip_mreqn& ref) -{ -#ifdef IP_DROP_MEMBERSHIP - if (setsockopt(GetSocket(), IPPROTO_IP, IP_DROP_MEMBERSHIP, (char *)&ref, sizeof(struct ip_mreqn)) == -1) - { - Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_DROP_MEMBERSHIP)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -#else - Handler().LogError(this, "ip option not available", 0, "IP_DROP_MEMBERSHIP", LOG_LEVEL_INFO); - return false; -#endif -} -#endif - - -bool Socket::IpDropMembership(struct ip_mreq& ref) -{ -#ifdef IP_DROP_MEMBERSHIP - if (setsockopt(GetSocket(), IPPROTO_IP, IP_DROP_MEMBERSHIP, (char *)&ref, sizeof(struct ip_mreq)) == -1) - { - Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_DROP_MEMBERSHIP)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -#else - Handler().LogError(this, "ip option not available", 0, "IP_DROP_MEMBERSHIP", LOG_LEVEL_INFO); - return false; -#endif -} - - -/* SOCKET options */ - - -bool Socket::SetSoReuseaddr(bool x) -{ -#ifdef SO_REUSEADDR - int optval = x ? 1 : 0; - if (setsockopt(GetSocket(), SOL_SOCKET, SO_REUSEADDR, (char *)&optval, sizeof(optval)) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_REUSEADDR)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -#else - Handler().LogError(this, "socket option not available", 0, "SO_REUSEADDR", LOG_LEVEL_INFO); - return false; -#endif -} - - -bool Socket::SetSoKeepalive(bool x) -{ -#ifdef SO_KEEPALIVE - int optval = x ? 1 : 0; - if (setsockopt(GetSocket(), SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_KEEPALIVE)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -#else - Handler().LogError(this, "socket option not available", 0, "SO_KEEPALIVE", LOG_LEVEL_INFO); - return false; -#endif -} - - -#ifdef SO_NOSIGPIPE -bool Socket::SetSoNosigpipe(bool x) -{ - int optval = x ? 1 : 0; - if (setsockopt(GetSocket(), SOL_SOCKET, SO_NOSIGPIPE, (char *)&optval, sizeof(optval)) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_NOSIGPIPE)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -} -#endif - - -bool Socket::SoAcceptconn() -{ - int value = 0; -#ifdef SO_ACCEPTCONN - socklen_t len = sizeof(value); - if (getsockopt(GetSocket(), SOL_SOCKET, SO_ACCEPTCONN, (char *)&value, &len) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_ACCEPTCONN)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - } -#else - Handler().LogError(this, "socket option not available", 0, "SO_ACCEPTCONN", LOG_LEVEL_INFO); -#endif - return value ? true : false; -} - - -#ifdef SO_BSDCOMPAT -bool Socket::SetSoBsdcompat(bool x) -{ - int optval = x ? 1 : 0; - if (setsockopt(GetSocket(), SOL_SOCKET, SO_BSDCOMPAT, (char *)&optval, sizeof(optval)) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_BSDCOMPAT)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -} -#endif - - -#ifdef SO_BINDTODEVICE -bool Socket::SetSoBindtodevice(const std::string& intf) -{ - if (setsockopt(GetSocket(), SOL_SOCKET, SO_BINDTODEVICE, (char *)intf.c_str(), intf.size()) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_BINDTODEVICE)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -} -#endif - - -bool Socket::SetSoBroadcast(bool x) -{ -#ifdef SO_BROADCAST - int optval = x ? 1 : 0; - if (setsockopt(GetSocket(), SOL_SOCKET, SO_BROADCAST, (char *)&optval, sizeof(optval)) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_BROADCAST)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -#else - Handler().LogError(this, "socket option not available", 0, "SO_BROADCAST", LOG_LEVEL_INFO); - return false; -#endif -} - - -bool Socket::SetSoDebug(bool x) -{ -#ifdef SO_DEBUG - int optval = x ? 1 : 0; - if (setsockopt(GetSocket(), SOL_SOCKET, SO_DEBUG, (char *)&optval, sizeof(optval)) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_DEBUG)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -#else - Handler().LogError(this, "socket option not available", 0, "SO_DEBUG", LOG_LEVEL_INFO); - return false; -#endif -} - - -int Socket::SoError() -{ - int value = 0; -#ifdef SO_ERROR - socklen_t len = sizeof(value); - if (getsockopt(GetSocket(), SOL_SOCKET, SO_ERROR, (char *)&value, &len) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_ERROR)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - } -#else - Handler().LogError(this, "socket option not available", 0, "SO_ERROR", LOG_LEVEL_INFO); -#endif - return value ? true : false; -} - - -bool Socket::SetSoDontroute(bool x) -{ -#ifdef SO_DONTROUTE - int optval = x ? 1 : 0; - if (setsockopt(GetSocket(), SOL_SOCKET, SO_DONTROUTE, (char *)&optval, sizeof(optval)) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_DONTROUTE)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -#else - Handler().LogError(this, "socket option not available", 0, "SO_DONTROUTE", LOG_LEVEL_INFO); - return false; -#endif -} - - -bool Socket::SetSoLinger(int onoff, int linger) -{ -#ifdef SO_LINGER - struct linger stl; - stl.l_onoff = onoff; - stl.l_linger = linger; - if (setsockopt(GetSocket(), SOL_SOCKET, SO_LINGER, (char *)&stl, sizeof(stl)) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_LINGER)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -#else - Handler().LogError(this, "socket option not available", 0, "SO_LINGER", LOG_LEVEL_INFO); - return false; -#endif -} - - -bool Socket::SetSoOobinline(bool x) -{ -#ifdef SO_OOBINLINE - int optval = x ? 1 : 0; - if (setsockopt(GetSocket(), SOL_SOCKET, SO_OOBINLINE, (char *)&optval, sizeof(optval)) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_OOBINLINE)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -#else - Handler().LogError(this, "socket option not available", 0, "SO_OOBINLINE", LOG_LEVEL_INFO); - return false; -#endif -} - - -#ifdef SO_PASSCRED -bool Socket::SetSoPasscred(bool x) -{ - int optval = x ? 1 : 0; - if (setsockopt(GetSocket(), SOL_SOCKET, SO_PASSCRED, (char *)&optval, sizeof(optval)) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_PASSCRED)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -} -#endif - - -#ifdef SO_PEERCRED -bool Socket::SoPeercred(struct ucred& ucr) -{ - if (setsockopt(GetSocket(), SOL_SOCKET, SO_PEERCRED, (char *)&ucr, sizeof(ucr)) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_PEERCRED)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -} -#endif - - -#ifdef SO_PRIORITY -bool Socket::SetSoPriority(int x) -{ - if (setsockopt(GetSocket(), SOL_SOCKET, SO_PRIORITY, (char *)&x, sizeof(x)) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_PRIORITY)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -} -#endif - - -bool Socket::SetSoRcvlowat(int x) -{ -#ifdef SO_RCVLOWAT - if (setsockopt(GetSocket(), SOL_SOCKET, SO_RCVLOWAT, (char *)&x, sizeof(x)) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_RCVLOWAT)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -#else - Handler().LogError(this, "socket option not available", 0, "SO_RCVLOWAT", LOG_LEVEL_INFO); - return false; -#endif -} - - -bool Socket::SetSoSndlowat(int x) -{ -#ifdef SO_SNDLOWAT - if (setsockopt(GetSocket(), SOL_SOCKET, SO_SNDLOWAT, (char *)&x, sizeof(x)) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_SNDLOWAT)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -#else - Handler().LogError(this, "socket option not available", 0, "SO_SNDLOWAT", LOG_LEVEL_INFO); - return false; -#endif -} - - -bool Socket::SetSoRcvtimeo(struct timeval& tv) -{ -#ifdef SO_RCVTIMEO - if (setsockopt(GetSocket(), SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_RCVTIMEO)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -#else - Handler().LogError(this, "socket option not available", 0, "SO_RCVTIMEO", LOG_LEVEL_INFO); - return false; -#endif -} - - -bool Socket::SetSoSndtimeo(struct timeval& tv) -{ -#ifdef SO_SNDTIMEO - if (setsockopt(GetSocket(), SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(tv)) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_SNDTIMEO)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -#else - Handler().LogError(this, "socket option not available", 0, "SO_SNDTIMEO", LOG_LEVEL_INFO); - return false; -#endif -} - - -bool Socket::SetSoRcvbuf(int x) -{ -#ifdef SO_RCVBUF - if (setsockopt(GetSocket(), SOL_SOCKET, SO_RCVBUF, (char *)&x, sizeof(x)) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_RCVBUF)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -#else - Handler().LogError(this, "socket option not available", 0, "SO_RCVBUF", LOG_LEVEL_INFO); - return false; -#endif -} - - -int Socket::SoRcvbuf() -{ - int value = 0; -#ifdef SO_RCVBUF - socklen_t len = sizeof(value); - if (getsockopt(GetSocket(), SOL_SOCKET, SO_RCVBUF, (char *)&value, &len) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_RCVBUF)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - } -#else - Handler().LogError(this, "socket option not available", 0, "SO_RCVBUF", LOG_LEVEL_INFO); -#endif - return value ? true : false; -} - - -#ifdef SO_RCVBUFFORCE -bool Socket::SetSoRcvbufforce(int x) -{ - if (setsockopt(GetSocket(), SOL_SOCKET, SO_RCVBUFFORCE, (char *)&x, sizeof(x)) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_RCVBUFFORCE)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -} -#endif - - -bool Socket::SetSoSndbuf(int x) -{ -#ifdef SO_SNDBUF - if (setsockopt(GetSocket(), SOL_SOCKET, SO_SNDBUF, (char *)&x, sizeof(x)) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_SNDBUF)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -#else - Handler().LogError(this, "socket option not available", 0, "SO_SNDBUF", LOG_LEVEL_INFO); - return false; -#endif -} - - -int Socket::SoSndbuf() -{ - int value = 0; -#ifdef SO_SNDBUF - socklen_t len = sizeof(value); - if (getsockopt(GetSocket(), SOL_SOCKET, SO_SNDBUF, (char *)&value, &len) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_SNDBUF)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - } -#else - Handler().LogError(this, "socket option not available", 0, "SO_SNDBUF", LOG_LEVEL_INFO); -#endif - return value ? true : false; -} - - -#ifdef SO_SNDBUFFORCE -bool Socket::SetSoSndbufforce(int x) -{ - if (setsockopt(GetSocket(), SOL_SOCKET, SO_SNDBUFFORCE, (char *)&x, sizeof(x)) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_SNDBUFFORCE)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -} -#endif - - -#ifdef SO_TIMESTAMP -bool Socket::SetSoTimestamp(bool x) -{ - int optval = x ? 1 : 0; - if (setsockopt(GetSocket(), SOL_SOCKET, SO_TIMESTAMP, (char *)&optval, sizeof(optval)) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_TIMESTAMP)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -} -#endif - - -int Socket::SoType() -{ - int value = 0; -#ifdef SO_TYPE - socklen_t len = sizeof(value); - if (getsockopt(GetSocket(), SOL_SOCKET, SO_TYPE, (char *)&value, &len) == -1) - { - Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_TYPE)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - } -#else - Handler().LogError(this, "socket option not available", 0, "SO_TYPE", LOG_LEVEL_INFO); -#endif - return value ? true : false; -} - - -#ifdef ENABLE_TRIGGERS -void Socket::Subscribe(int id) -{ - Handler().Subscribe(id, this); -} - - -void Socket::Unsubscribe(int id) -{ - Handler().Unsubscribe(id, this); -} - - -void Socket::OnTrigger(int, const TriggerData&) -{ -} - - -void Socket::OnCancelled(int) -{ -} -#endif - - -void Socket::SetTimeout(time_t secs) -{ - if (!secs) - { - Handler().AddList(m_socket, LIST_TIMEOUT, false); - return; - } - Handler().AddList(m_socket, LIST_TIMEOUT, true); - m_timeout_start = time(NULL); - m_timeout_limit = secs; -} - - -void Socket::OnTimeout() -{ -} - - -void Socket::OnConnectTimeout() -{ -} - - -bool Socket::Timeout(time_t tnow) -{ - if (tnow - m_timeout_start > m_timeout_limit) - return true; - return false; -} - - -/** Returns local port number for bound socket file descriptor. */ -port_t Socket::GetSockPort() -{ -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (IsIpv6()) - { - struct sockaddr_in6 sa; - socklen_t sockaddr_length = sizeof(struct sockaddr_in6); - if (getsockname(GetSocket(), (struct sockaddr *)&sa, (socklen_t*)&sockaddr_length) == -1) - memset(&sa, 0, sizeof(sa)); - return ntohs(sa.sin6_port); - } -#endif -#endif - struct sockaddr_in sa; - socklen_t sockaddr_length = sizeof(struct sockaddr_in); - if (getsockname(GetSocket(), (struct sockaddr *)&sa, (socklen_t*)&sockaddr_length) == -1) - memset(&sa, 0, sizeof(sa)); - return ntohs(sa.sin_port); -} - - -/** Returns local ipv4 address for bound socket file descriptor. */ -ipaddr_t Socket::GetSockIP4() -{ -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (IsIpv6()) - { - return 0; - } -#endif -#endif - struct sockaddr_in sa; - socklen_t sockaddr_length = sizeof(struct sockaddr_in); - if (getsockname(GetSocket(), (struct sockaddr *)&sa, (socklen_t*)&sockaddr_length) == -1) - memset(&sa, 0, sizeof(sa)); - ipaddr_t a; - memcpy(&a, &sa.sin_addr, 4); - return a; -} - - -/** Returns local ipv4 address as text for bound socket file descriptor. */ -std::string Socket::GetSockAddress() -{ -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (IsIpv6()) - { - return ""; - } -#endif -#endif - struct sockaddr_in sa; - socklen_t sockaddr_length = sizeof(struct sockaddr_in); - if (getsockname(GetSocket(), (struct sockaddr *)&sa, (socklen_t*)&sockaddr_length) == -1) - memset(&sa, 0, sizeof(sa)); - Ipv4Address addr( sa ); - return addr.Convert(); -} - - -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 -/** Returns local ipv6 address for bound socket file descriptor. */ -struct in6_addr Socket::GetSockIP6() -{ - if (IsIpv6()) - { - struct sockaddr_in6 sa; - socklen_t sockaddr_length = sizeof(struct sockaddr_in6); - if (getsockname(GetSocket(), (struct sockaddr *)&sa, (socklen_t*)&sockaddr_length) == -1) - memset(&sa, 0, sizeof(sa)); - return sa.sin6_addr; - } - struct in6_addr a; - memset(&a, 0, sizeof(a)); - return a; -} - - -/** Returns local ipv6 address as text for bound socket file descriptor. */ -std::string Socket::GetSockAddress6() -{ - if (IsIpv6()) - { - struct sockaddr_in6 sa; - socklen_t sockaddr_length = sizeof(struct sockaddr_in6); - if (getsockname(GetSocket(), (struct sockaddr *)&sa, (socklen_t*)&sockaddr_length) == -1) - memset(&sa, 0, sizeof(sa)); - Ipv6Address addr( sa ); - return addr.Convert(); - } - return ""; -} -#endif -#endif - - -#ifdef SOCKETS_NAMESPACE -} -#endif - diff --git a/Sockets/Socket.h b/Sockets/Socket.h deleted file mode 100644 index 764b69b..0000000 --- a/Sockets/Socket.h +++ /dev/null @@ -1,738 +0,0 @@ -/** \file Socket.h - ** \date 2004-02-13 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This software is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_Socket_H -#define _SOCKETS_Socket_H -#include "sockets-config.h" - -#include -#include -#include -#ifdef HAVE_OPENSSL -#include -#endif - -#include "socket_include.h" -#include -#include "SocketAddress.h" -#include "Thread.h" - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -class ISocketHandler; -class SocketAddress; -class IFile; - - -/** \defgroup basic Basic sockets */ -/** Socket base class. - \ingroup basic */ -class Socket -{ - friend class ISocketHandler; -#ifdef ENABLE_DETACH - /** Detached socket run thread. - \ingroup internal */ - class SocketThread : public Thread - { - public: - SocketThread(Socket *p); - ~SocketThread(); - - void Run(); - - private: - Socket *GetSocket() const { return m_socket; } - SocketThread(const SocketThread& s) : m_socket(s.GetSocket()) {} - SocketThread& operator=(const SocketThread& ) { return *this; } - Socket *m_socket; - }; -#endif // ENABLE_DETACH - -#ifdef ENABLE_TRIGGERS -public: - /** Data pass class from source to destination. */ - class TriggerData - { - public: - TriggerData() : m_src(NULL) {} - virtual ~TriggerData() {} - - Socket *GetSource() const { return m_src; } - void SetSource(Socket *x) { m_src = x; } - - private: - Socket *m_src; - }; -#endif // ENABLE_TRIGGERS - - /** Socket mode flags. */ -/* - enum { - // Socket - SOCK_DEL = 0x01, ///< Delete by handler flag - SOCK_CLOSE = 0x02, ///< Close and delete flag - SOCK_DISABLE_READ = 0x04, ///< Disable checking for read events - SOCK_CONNECTED = 0x08, ///< Socket is connected (tcp/udp) - - SOCK_ERASED_BY_HANDLER = 0x10, ///< Set by handler before delete - // HAVE_OPENSSL - SOCK_ENABLE_SSL = 0x20, ///< Enable SSL for this TcpSocket - SOCK_SSL = 0x40, ///< ssl negotiation mode (TcpSocket) - SOCK_SSL_SERVER = 0x80, ///< True if this is an incoming ssl TcpSocket connection - - // ENABLE_IPV6 - SOCK_IPV6 = 0x0100, ///< This is an ipv6 socket if this one is true - // ENABLE_POOL - SOCK_CLIENT = 0x0200, ///< only client connections are pooled - SOCK_RETAIN = 0x0400, ///< keep connection on close - SOCK_LOST = 0x0800, ///< connection lost - - // ENABLE_SOCKS4 - SOCK_SOCKS4 = 0x1000, ///< socks4 negotiation mode (TcpSocket) - // ENABLE_DETACH - SOCK_DETACH = 0x2000, ///< Socket ordered to detach flag - SOCK_DETACHED = 0x4000, ///< Socket has been detached - // StreamSocket - STREAMSOCK_CONNECTING = 0x8000, ///< Flag indicating connection in progress - - STREAMSOCK_FLUSH_BEFORE_CLOSE = 0x010000L, ///< Send all data before closing (default true) - STREAMSOCK_CALL_ON_CONNECT = 0x020000L, ///< OnConnect will be called next ISocketHandler cycle if true - STREAMSOCK_RETRY_CONNECT = 0x040000L, ///< Try another connection attempt next ISocketHandler cycle - STREAMSOCK_LINE_PROTOCOL = 0x080000L, ///< Line protocol mode flag - - }; -*/ - -public: - /** "Default" constructor */ - Socket(ISocketHandler&); - - virtual ~Socket(); - - /** Socket class instantiation method. Used when a "non-standard" constructor - * needs to be used for the socket class. Note: the socket class still needs - * the "default" constructor with one ISocketHandler& as input parameter. - */ - virtual Socket *Create() { return NULL; } - - /** Returns reference to sockethandler that owns the socket. - If the socket is detached, this is a reference to the slave sockethandler. - */ - ISocketHandler& Handler() const; - - /** Returns reference to sockethandler that owns the socket. - This one always returns the reference to the original sockethandler, - even if the socket is detached. - */ - ISocketHandler& MasterHandler() const; - - /** Called by ListenSocket after accept but before socket is added to handler. - * CTcpSocket uses this to create its ICrypt member variable. - * The ICrypt member variable is created by a virtual method, therefore - * it can't be called directly from the CTcpSocket constructor. - * Also used to determine if incoming HTTP connection is normal (port 80) - * or ssl (port 443). - */ - virtual void Init(); - - /** Create a socket file descriptor. - \param af Address family AF_INET / AF_INET6 / ... - \param type SOCK_STREAM / SOCK_DGRAM / ... - \param protocol "tcp" / "udp" / ... */ - SOCKET CreateSocket(int af,int type,const std::string& protocol = ""); - - /** Assign this socket a file descriptor created - by a call to socket() or otherwise. */ - void Attach(SOCKET s); - - /** Return file descriptor assigned to this socket. */ - SOCKET GetSocket(); - - /** Close connection immediately - internal use. - \sa SetCloseAndDelete */ - virtual int Close(); - - /** Add file descriptor to sockethandler fd_set's. */ - void Set(bool bRead,bool bWrite,bool bException = true); - - /** Returns true when socket file descriptor is valid - and socket is not about to be closed. */ - virtual bool Ready(); - - /** Returns pointer to ListenSocket that created this instance - * on an incoming connection. */ - Socket *GetParent(); - - /** Used by ListenSocket to set parent pointer of newly created - * socket instance. */ - void SetParent(Socket *); - - /** Get listening port from ListenSocket<>. */ - virtual port_t GetPort(); - - /** Set socket non-block operation. */ - bool SetNonblocking(bool); - - /** Set socket non-block operation. */ - bool SetNonblocking(bool, SOCKET); - - /** Total lifetime of instance. */ - time_t Uptime(); - - /** Set address/port of last connect() call. */ - void SetClientRemoteAddress(SocketAddress&); - - /** Get address/port of last connect() call. */ - std::auto_ptr GetClientRemoteAddress(); - - /** Common interface for SendBuf used by Tcp and Udp sockets. */ - virtual void SendBuf(const char *,size_t,int = 0); - - /** Common interface for Send used by Tcp and Udp sockets. */ - virtual void Send(const std::string&,int = 0); - - /** Outgoing traffic counter. */ - virtual uint64_t GetBytesSent(bool clear = false); - - /** Incoming traffic counter. */ - virtual uint64_t GetBytesReceived(bool clear = false); - - // LIST_TIMEOUT - - /** Enable timeout control. 0=disable timeout check. */ - void SetTimeout(time_t secs); - - /** Check timeout. \return true if time limit reached */ - bool Timeout(time_t tnow); - - /** Used by ListenSocket. ipv4 and ipv6 */ - void SetRemoteAddress(SocketAddress&); - - /** \name Event callbacks */ - //@{ - - /** Called when there is something to be read from the file descriptor. */ - virtual void OnRead(); - /** Called when there is room for another write on the file descriptor. */ - virtual void OnWrite(); - /** Called on socket exception. */ - virtual void OnException(); - /** Called before a socket class is deleted by the ISocketHandler. */ - virtual void OnDelete(); - /** Called when a connection has completed. */ - virtual void OnConnect(); - /** Called when an incoming connection has been completed. */ - virtual void OnAccept(); - /** Called when a complete line has been read and the socket is in - * line protocol mode. */ - virtual void OnLine(const std::string& ); - /** Called on connect timeout (5s). */ - virtual void OnConnectFailed(); - /** Called when a client socket is created, to set socket options. - \param family AF_INET, AF_INET6, etc - \param type SOCK_STREAM, SOCK_DGRAM, etc - \param protocol Protocol number (tcp, udp, sctp, etc) - \param s Socket file descriptor - */ - virtual void OnOptions(int family,int type,int protocol,SOCKET s) = 0; - /** Connection retry callback - return false to abort connection attempts */ - virtual bool OnConnectRetry(); -#ifdef ENABLE_RECONNECT - /** a reconnect has been made */ - virtual void OnReconnect(); -#endif - /** TcpSocket: When a disconnect has been detected (recv/SSL_read returns 0 bytes). */ - virtual void OnDisconnect(); - /** Timeout callback. */ - virtual void OnTimeout(); - /** Connection timeout. */ - virtual void OnConnectTimeout(); - //@} - - /** \name Socket mode flags, set/reset */ - //@{ - /** Set delete by handler true when you want the sockethandler to - delete the socket instance after use. */ - void SetDeleteByHandler(bool = true); - /** Check delete by handler flag. - \return true if this instance should be deleted by the sockethandler */ - bool DeleteByHandler(); - - // LIST_CLOSE - conditional event queue - - /** Set close and delete to terminate the connection. */ - void SetCloseAndDelete(bool = true); - /** Check close and delete flag. - \return true if this socket should be closed and the instance removed */ - bool CloseAndDelete(); - - /** Return number of seconds since socket was ordered to close. \sa SetCloseAndDelete */ - time_t TimeSinceClose(); - - /** Ignore read events for an output only socket. */ - void DisableRead(bool x = true); - /** Check ignore read events flag. - \return true if read events should be ignored */ - bool IsDisableRead(); - - /** Set connected status. */ - void SetConnected(bool = true); - /** Check connected status. - \return true if connected */ - bool IsConnected(); - - /** Set flag indicating the socket is being actively deleted by the sockethandler. */ - void SetErasedByHandler(bool x = true); - /** Get value of flag indicating socket is deleted by sockethandler. */ - bool ErasedByHandler(); - - //@} - - /** \name Information about remote connection */ - //@{ - /** Returns address of remote end. */ - std::auto_ptr GetRemoteSocketAddress(); - /** Returns address of remote end: ipv4. */ - ipaddr_t GetRemoteIP4(); -#ifdef ENABLE_IPV6 - /** Returns address of remote end: ipv6. */ -#ifdef IPPROTO_IPV6 - struct in6_addr GetRemoteIP6(); -#endif -#endif - /** Returns remote port number: ipv4 and ipv6. */ - port_t GetRemotePort(); - /** Returns remote ip as string? ipv4 and ipv6. */ - std::string GetRemoteAddress(); - /** ipv4 and ipv6(not implemented) */ - std::string GetRemoteHostname(); - //@} - - /** Returns local port number for bound socket file descriptor. */ - port_t GetSockPort(); - /** Returns local ipv4 address for bound socket file descriptor. */ - ipaddr_t GetSockIP4(); - /** Returns local ipv4 address as text for bound socket file descriptor. */ - std::string GetSockAddress(); -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - /** Returns local ipv6 address for bound socket file descriptor. */ - struct in6_addr GetSockIP6(); - /** Returns local ipv6 address as text for bound socket file descriptor. */ - std::string GetSockAddress6(); -#endif -#endif - // -------------------------------------------------------------------------- - /** @name IP options - When an ip or socket option is available on all of the operating systems - I'm testing on (linux 2.4.x, _win32, macosx, solaris9 intel) they are not - checked with an #ifdef below. - This might cause a compile error on other operating systems. */ - // -------------------------------------------------------------------------- - - // IP options - //@{ - - bool SetIpOptions(const void *p, socklen_t len); - bool SetIpTOS(unsigned char tos); - unsigned char IpTOS(); - bool SetIpTTL(int ttl); - int IpTTL(); - bool SetIpHdrincl(bool x = true); - bool SetIpMulticastTTL(int); - int IpMulticastTTL(); - bool SetMulticastLoop(bool x = true); - bool IpAddMembership(struct ip_mreq&); - bool IpDropMembership(struct ip_mreq&); - -#ifdef IP_PKTINFO - bool SetIpPktinfo(bool x = true); -#endif -#ifdef IP_RECVTOS - bool SetIpRecvTOS(bool x = true); -#endif -#ifdef IP_RECVTTL - bool SetIpRecvTTL(bool x = true); -#endif -#ifdef IP_RECVOPTS - bool SetIpRecvopts(bool x = true); -#endif -#ifdef IP_RETOPTS - bool SetIpRetopts(bool x = true); -#endif -#ifdef IP_RECVERR - bool SetIpRecverr(bool x = true); -#endif -#ifdef IP_MTU_DISCOVER - bool SetIpMtudiscover(bool x = true); -#endif -#ifdef IP_MTU - int IpMtu(); -#endif -#ifdef IP_ROUTER_ALERT - bool SetIpRouterAlert(bool x = true); -#endif -#ifdef LINUX - bool IpAddMembership(struct ip_mreqn&); -#endif -#ifdef LINUX - bool IpDropMembership(struct ip_mreqn&); -#endif - //@} - - // SOCKET options - /** @name Socket Options */ - //@{ - - bool SoAcceptconn(); - bool SetSoBroadcast(bool x = true); - bool SetSoDebug(bool x = true); - int SoError(); - bool SetSoDontroute(bool x = true); - bool SetSoLinger(int onoff, int linger); - bool SetSoOobinline(bool x = true); - bool SetSoRcvlowat(int); - bool SetSoSndlowat(int); - bool SetSoRcvtimeo(struct timeval&); - bool SetSoSndtimeo(struct timeval&); - bool SetSoRcvbuf(int); - int SoRcvbuf(); - bool SetSoSndbuf(int); - int SoSndbuf(); - int SoType(); - bool SetSoReuseaddr(bool x = true); - bool SetSoKeepalive(bool x = true); - -#ifdef SO_BSDCOMPAT - bool SetSoBsdcompat(bool x = true); -#endif -#ifdef SO_BINDTODEVICE - bool SetSoBindtodevice(const std::string& intf); -#endif -#ifdef SO_PASSCRED - bool SetSoPasscred(bool x = true); -#endif -#ifdef SO_PEERCRED - bool SoPeercred(struct ucred& ); -#endif -#ifdef SO_PRIORITY - bool SetSoPriority(int); -#endif -#ifdef SO_RCVBUFFORCE - bool SetSoRcvbufforce(int); -#endif -#ifdef SO_SNDBUFFORCE - bool SetSoSndbufforce(int); -#endif -#ifdef SO_TIMESTAMP - bool SetSoTimestamp(bool x = true); -#endif -#ifdef SO_NOSIGPIPE - bool SetSoNosigpipe(bool x = true); -#endif - //@} - - // TCP options in TcpSocket.h/TcpSocket.cpp - - -#ifdef HAVE_OPENSSL - /** @name SSL Support */ - //@{ - /** SSL client/server support - internal use. \sa TcpSocket */ - virtual void OnSSLConnect(); - /** SSL client/server support - internal use. \sa TcpSocket */ - virtual void OnSSLAccept(); - /** SSL negotiation failed for client connect. */ - virtual void OnSSLConnectFailed(); - /** SSL negotiation failed for server accept. */ - virtual void OnSSLAcceptFailed(); - /** new SSL support */ - virtual bool SSLNegotiate(); - /** Check if SSL is Enabled for this TcpSocket. - \return true if this is a TcpSocket with SSL enabled */ - bool IsSSL(); - /** Enable SSL operation for a TcpSocket. */ - void EnableSSL(bool x = true); - /** Still negotiating ssl connection. - \return true if ssl negotiating is still in progress */ - bool IsSSLNegotiate(); - /** Set flag indicating ssl handshaking still in progress. */ - void SetSSLNegotiate(bool x = true); - /** OnAccept called with SSL Enabled. - \return true if this is a TcpSocket with an incoming SSL connection */ - bool IsSSLServer(); - /** Set flag indicating that this is a TcpSocket with incoming SSL connection. */ - void SetSSLServer(bool x = true); - /** SSL; Get pointer to ssl context structure. */ - virtual SSL_CTX *GetSslContext() { return NULL; } - /** SSL; Get pointer to ssl structure. */ - virtual SSL *GetSsl() { return NULL; } - //@} -#endif // HAVE_OPENSSL - -#ifdef ENABLE_IPV6 - /** Enable ipv6 for this socket. */ - void SetIpv6(bool x = true); - /** Check ipv6 socket. - \return true if this is an ipv6 socket */ - bool IsIpv6(); -#endif - -#ifdef ENABLE_POOL - /** @name Connection Pool */ - //@{ - /** Client = connecting TcpSocket. */ - void SetIsClient(); - /** Socket type from socket() call. */ - void SetSocketType(int x); - /** Socket type from socket() call. */ - int GetSocketType(); - /** Protocol type from socket() call. */ - void SetSocketProtocol(const std::string& x); - /** Protocol type from socket() call. */ - const std::string& GetSocketProtocol(); - /** Instruct a client socket to stay open in the connection pool after use. - If you have connected to a server using tcp, you can call SetRetain - to leave the connection open after your socket instance has been deleted. - The next connection you make to the same server will reuse the already - opened connection, if it is still available. - */ - void SetRetain(); - /** Check retain flag. - \return true if the socket should be moved to connection pool after use */ - bool Retain(); - /** Connection lost - error while reading/writing from a socket - TcpSocket only. */ - void SetLost(); - /** Check connection lost status flag, used by TcpSocket only. - \return true if there was an error while r/w causing the socket to close */ - bool Lost(); - /** Copy connection parameters from sock. */ - void CopyConnection(Socket *sock); - //@} -#endif // ENABLE_POOL - -#ifdef ENABLE_SOCKS4 - /** \name Socks4 support */ - //@{ - /** Socks4 client support internal use. \sa TcpSocket */ - virtual void OnSocks4Connect(); - /** Socks4 client support internal use. \sa TcpSocket */ - virtual void OnSocks4ConnectFailed(); - /** Socks4 client support internal use. \sa TcpSocket */ - virtual bool OnSocks4Read(); - /** Called when the last write caused the tcp output buffer to - * become empty. */ - /** socket still in socks4 negotiation mode */ - bool Socks4(); - /** Set flag indicating Socks4 handshaking in progress */ - void SetSocks4(bool x = true); - - /** Set socks4 server host address to use */ - void SetSocks4Host(ipaddr_t a); - /** Set socks4 server hostname to use. */ - void SetSocks4Host(const std::string& ); - /** Socks4 server port to use. */ - void SetSocks4Port(port_t p); - /** Provide a socks4 userid if required by the socks4 server. */ - void SetSocks4Userid(const std::string& x); - /** Get the ip address of socks4 server to use. - \return socks4 server host address */ - ipaddr_t GetSocks4Host(); - /** Get the socks4 server port to use. - \return socks4 server port */ - port_t GetSocks4Port(); - /** Get socks4 userid. - \return Socks4 userid */ - const std::string& GetSocks4Userid(); - //@} -#endif // ENABLE_SOCKS4 - -#ifdef ENABLE_RESOLVER - /** \name Asynchronous Resolver */ - //@{ - /** Request an asynchronous dns resolution. - \param host hostname to be resolved - \param port port number passed along for the ride - \return Resolve ID */ - int Resolve(const std::string& host,port_t port = 0); -#ifdef ENABLE_IPV6 - int Resolve6(const std::string& host, port_t port = 0); -#endif - /** Callback returning a resolved address. - \param id Resolve ID from Resolve call - \param a resolved ip address - \param port port number passed to Resolve */ - virtual void OnResolved(int id,ipaddr_t a,port_t port); -#ifdef ENABLE_IPV6 - virtual void OnResolved(int id,in6_addr& a,port_t port); -#endif - /** Request asynchronous reverse dns lookup. - \param a in_addr to be translated */ - int Resolve(ipaddr_t a); -#ifdef ENABLE_IPV6 - int Resolve(in6_addr& a); -#endif - /** Callback returning reverse resolve results. - \param id Resolve ID - \param name Resolved hostname */ - virtual void OnReverseResolved(int id,const std::string& name); - /** Callback indicating failed dns lookup. - \param id Resolve ID */ - virtual void OnResolveFailed(int id); - //@} -#endif // ENABLE_RESOLVER - -#ifdef ENABLE_DETACH - /** \name Thread Support */ - //@{ - /** Callback fires when a new socket thread has started and this - socket is ready for operation again. - \sa ResolvSocket */ - virtual void OnDetached(); - - // LIST_DETACH - - /** Internal use. */ - void SetDetach(bool x = true); - /** Check detach flag. - \return true if the socket should detach to its own thread */ - bool IsDetach(); - - /** Internal use. */ - void SetDetached(bool x = true); - /** Check detached flag. - \return true if the socket runs in its own thread. */ - const bool IsDetached() const; - /** Order this socket to start its own thread and call OnDetached - when ready for operation. */ - bool Detach(); - /** Store the slave sockethandler pointer. */ - void SetSlaveHandler(ISocketHandler *); - /** Create new thread for this socket to run detached in. */ - void DetachSocket(); - //@} -#endif // ENABLE_DETACH - - /** Write traffic to an IFile. Socket will not delete this object. */ - void SetTrafficMonitor(IFile *p) { m_traffic_monitor = p; } - -#ifdef ENABLE_TRIGGERS - /** \name Triggers */ - //@{ - /** Subscribe to trigger id. */ - void Subscribe(int id); - /** Unsubscribe from trigger id. */ - void Unsubscribe(int id); - /** Trigger callback, with data passed from source to destination. */ - virtual void OnTrigger(int id, const TriggerData& data); - /** Trigger cancelled because source has been deleted (as in delete). */ - virtual void OnCancelled(int id); - //@} -#endif - -protected: - /** default constructor not available */ - Socket() : m_handler(m_handler) {} - /** copy constructor not available */ - Socket(const Socket& s) : m_handler(s.m_handler) {} - - /** assignment operator not available. */ - Socket& operator=(const Socket& ) { return *this; } - - /** All traffic will be written to this IFile, if set. */ - IFile *GetTrafficMonitor() { return m_traffic_monitor; } - -// unsigned long m_flags; ///< boolean flags, replacing old 'bool' members - -private: - ISocketHandler& m_handler; ///< Reference of ISocketHandler in control of this socket - SOCKET m_socket; ///< File descriptor - bool m_bDel; ///< Delete by handler flag - bool m_bClose; ///< Close and delete flag - time_t m_tCreate; ///< Time in seconds when this socket was created - Socket *m_parent; ///< Pointer to ListenSocket class, valid for incoming sockets - bool m_b_disable_read; ///< Disable checking for read events - bool m_connected; ///< Socket is connected (tcp/udp) - bool m_b_erased_by_handler; ///< Set by handler before delete - time_t m_tClose; ///< Time in seconds when ordered to close - std::auto_ptr m_client_remote_address; ///< Address of last connect() - std::auto_ptr m_remote_address; ///< Remote end address - IFile *m_traffic_monitor; - time_t m_timeout_start; ///< Set by SetTimeout - time_t m_timeout_limit; ///< Defined by SetTimeout - -#ifdef _WIN32 -static WSAInitializer m_winsock_init; ///< Winsock initialization singleton class -#endif - -#ifdef HAVE_OPENSSL - bool m_b_enable_ssl; ///< Enable SSL for this TcpSocket - bool m_b_ssl; ///< ssl negotiation mode (TcpSocket) - bool m_b_ssl_server; ///< True if this is an incoming ssl TcpSocket connection -#endif - -#ifdef ENABLE_IPV6 - bool m_ipv6; ///< This is an ipv6 socket if this one is true -#endif - -#ifdef ENABLE_POOL - int m_socket_type; ///< Type of socket, from socket() call - std::string m_socket_protocol; ///< Protocol, from socket() call - bool m_bClient; ///< only client connections are pooled - bool m_bRetain; ///< keep connection on close - bool m_bLost; ///< connection lost -#endif - -#ifdef ENABLE_SOCKS4 - bool m_bSocks4; ///< socks4 negotiation mode (TcpSocket) - ipaddr_t m_socks4_host; ///< socks4 server address - port_t m_socks4_port; ///< socks4 server port number - std::string m_socks4_userid; ///< socks4 server usedid -#endif - -#ifdef ENABLE_DETACH - bool m_detach; ///< Socket ordered to detach flag - bool m_detached; ///< Socket has been detached - SocketThread *m_pThread; ///< Detach socket thread class pointer - ISocketHandler *m_slave_handler; ///< Actual sockethandler while detached -#endif -}; - -#ifdef SOCKETS_NAMESPACE -} -#endif - - -#endif // _SOCKETS_Socket_H - diff --git a/Sockets/SocketAddress.h b/Sockets/SocketAddress.h deleted file mode 100644 index d5a5643..0000000 --- a/Sockets/SocketAddress.h +++ /dev/null @@ -1,95 +0,0 @@ -/** - ** \file SocketAddress.h - ** \date 2006-09-21 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_SocketAddress_H -#define _SOCKETS_SocketAddress_H - -#include "sockets-config.h" -#include -#include -#include "socket_include.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -/** - This class and its subclasses is intended to be used as replacement - for the internal data type 'ipaddr_t' and various implementations of - IPv6 addressing found throughout the library. - 'ipaddr_t' is an IPv4 address in network byte order. - 'port_t' is the portnumber in host byte order. - 'struct in6_addr' is an IPv6 address. - 'struct in_addr' is an IPv4 address. - \ingroup basic -*/ -class SocketAddress -{ -public: - virtual ~SocketAddress() {} - - /** Get a pointer to the address struct. */ - virtual operator struct sockaddr *() = 0; - - /** Get length of address struct. */ - virtual operator socklen_t() = 0; - - /** Compare two addresses. */ - virtual bool operator==(SocketAddress&) = 0; - - /** Set port number. - \param port Port number in host byte order */ - virtual void SetPort(port_t port) = 0; - - /** Get port number. - \return Port number in host byte order. */ - virtual port_t GetPort() = 0; - - /** Set socket address. - \param sa Pointer to either 'struct sockaddr_in' or 'struct sockaddr_in6'. */ - virtual void SetAddress(struct sockaddr *sa) = 0; - - /** Convert address to text. */ - virtual std::string Convert(bool include_port) = 0; - - /** Reverse lookup of address. */ - virtual std::string Reverse() = 0; - - /** Get address family. */ - virtual int GetFamily() = 0; - - /** Address structure is valid. */ - virtual bool IsValid() = 0; - - /** Get a copy of this SocketAddress object. */ - virtual std::auto_ptr GetCopy() = 0; -}; - - - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif -#endif // _SOCKETS_SocketAddress_H - diff --git a/Sockets/SocketHandler.cpp b/Sockets/SocketHandler.cpp deleted file mode 100644 index c563aac..0000000 --- a/Sockets/SocketHandler.cpp +++ /dev/null @@ -1,1422 +0,0 @@ -/** \file SocketHandler.cpp - ** \date 2004-02-13 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _WIN32 -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif -#endif -#include -#include - -#include "SocketHandler.h" -#include "UdpSocket.h" -#include "ResolvSocket.h" -#include "ResolvServer.h" -#include "TcpSocket.h" -#include "Mutex.h" -#include "Utility.h" -#include "SocketAddress.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -#ifdef _DEBUG -#define DEB(x) x; fflush(stderr); -#else -#define DEB(x) -#endif - - -SocketHandler::SocketHandler(StdLog *p) -:m_stdlog(p) -,m_mutex(m_mutex) -,m_b_use_mutex(false) -,m_maxsock(0) -,m_preverror(-1) -,m_errcnt(0) -,m_tlast(0) -#ifdef ENABLE_SOCKS4 -,m_socks4_host(0) -,m_socks4_port(0) -,m_bTryDirect(false) -#endif -#ifdef ENABLE_RESOLVER -,m_resolv_id(0) -,m_resolver(NULL) -#endif -#ifdef ENABLE_POOL -,m_b_enable_pool(false) -#endif -#ifdef ENABLE_TRIGGERS -,m_next_trigger_id(0) -#endif -#ifdef ENABLE_DETACH -,m_slave(false) -#endif -{ - FD_ZERO(&m_rfds); - FD_ZERO(&m_wfds); - FD_ZERO(&m_efds); -} - - -SocketHandler::SocketHandler(Mutex& mutex,StdLog *p) -:m_stdlog(p) -,m_mutex(mutex) -,m_b_use_mutex(true) -,m_maxsock(0) -,m_preverror(-1) -,m_errcnt(0) -,m_tlast(0) -#ifdef ENABLE_SOCKS4 -,m_socks4_host(0) -,m_socks4_port(0) -,m_bTryDirect(false) -#endif -#ifdef ENABLE_RESOLVER -,m_resolv_id(0) -,m_resolver(NULL) -#endif -#ifdef ENABLE_POOL -,m_b_enable_pool(false) -#endif -#ifdef ENABLE_TRIGGERS -,m_next_trigger_id(0) -#endif -#ifdef ENABLE_DETACH -,m_slave(false) -#endif -{ - m_mutex.Lock(); - FD_ZERO(&m_rfds); - FD_ZERO(&m_wfds); - FD_ZERO(&m_efds); -} - - -SocketHandler::~SocketHandler() -{ -#ifdef ENABLE_RESOLVER - if (m_resolver) - { - m_resolver -> Quit(); - } -#endif - { - while (m_sockets.size()) - { -DEB( fprintf(stderr, "Emptying sockets list in SocketHandler destructor, %d instances\n", (int)m_sockets.size());) - socket_m::iterator it = m_sockets.begin(); - Socket *p = it -> second; - if (p) - { -DEB( fprintf(stderr, " fd %d\n", p -> GetSocket());) - p -> Close(); -DEB( fprintf(stderr, " fd closed %d\n", p -> GetSocket());) -// p -> OnDelete(); // hey, I turn this back on. what's the worst that could happen??!! - // MinionSocket breaks, calling MinderHandler methods in OnDelete - - // MinderHandler is already gone when that happens... - - // only delete socket when controlled - // ie master sockethandler can delete non-detached sockets - // and a slave sockethandler can only delete a detach socket - if (p -> DeleteByHandler() -#ifdef ENABLE_DETACH - && !(m_slave ^ p -> IsDetached()) -#endif - ) - { - p -> SetErasedByHandler(); - delete p; - } - m_sockets.erase(it); - } - else - { - m_sockets.erase(it); - } -DEB( fprintf(stderr, "next\n");) - } -DEB( fprintf(stderr, "/Emptying sockets list in SocketHandler destructor, %d instances\n", (int)m_sockets.size());) - } -#ifdef ENABLE_RESOLVER - if (m_resolver) - { - delete m_resolver; - } -#endif - if (m_b_use_mutex) - { - m_mutex.Unlock(); - } -} - - -Mutex& SocketHandler::GetMutex() const -{ - return m_mutex; -} - - -#ifdef ENABLE_DETACH -void SocketHandler::SetSlave(bool x) -{ - m_slave = x; -} - - -bool SocketHandler::IsSlave() -{ - return m_slave; -} -#endif - - -void SocketHandler::RegStdLog(StdLog *log) -{ - m_stdlog = log; -} - - -void SocketHandler::LogError(Socket *p,const std::string& user_text,int err,const std::string& sys_err,loglevel_t t) -{ - if (m_stdlog) - { - m_stdlog -> error(this, p, user_text, err, sys_err, t); - } -} - - -void SocketHandler::Add(Socket *p) -{ - if (p -> GetSocket() == INVALID_SOCKET) - { - LogError(p, "Add", -1, "Invalid socket", LOG_LEVEL_WARNING); - if (p -> CloseAndDelete()) - { - m_delete.push_back(p); - } - return; - } - if (m_add.find(p -> GetSocket()) != m_add.end()) - { - LogError(p, "Add", (int)p -> GetSocket(), "Attempt to add socket already in add queue", LOG_LEVEL_FATAL); - m_delete.push_back(p); - return; - } - m_add[p -> GetSocket()] = p; -} - - -void SocketHandler::Get(SOCKET s,bool& r,bool& w,bool& e) -{ - if (s >= 0) - { - r = FD_ISSET(s, &m_rfds) ? true : false; - w = FD_ISSET(s, &m_wfds) ? true : false; - e = FD_ISSET(s, &m_efds) ? true : false; - } -} - - -void SocketHandler::Set(SOCKET s,bool bRead,bool bWrite,bool bException) -{ -DEB( fprintf(stderr, "Set(%d, %s, %s, %s)\n", s, bRead ? "true" : "false", bWrite ? "true" : "false", bException ? "true" : "false");) - if (s >= 0) - { - if (bRead) - { - if (!FD_ISSET(s, &m_rfds)) - { - FD_SET(s, &m_rfds); - } - } - else - { - FD_CLR(s, &m_rfds); - } - if (bWrite) - { - if (!FD_ISSET(s, &m_wfds)) - { - FD_SET(s, &m_wfds); - } - } - else - { - FD_CLR(s, &m_wfds); - } - if (bException) - { - if (!FD_ISSET(s, &m_efds)) - { - FD_SET(s, &m_efds); - } - } - else - { - FD_CLR(s, &m_efds); - } - } -} - - -int SocketHandler::Select(long sec,long usec) -{ - struct timeval tv; - tv.tv_sec = sec; - tv.tv_usec = usec; - return Select(&tv); -} - - -int SocketHandler::Select() -{ - if (m_fds_callonconnect.size() || -#ifdef ENABLE_DETACH - (!m_slave && m_fds_detach.size()) || -#endif - m_fds_timeout.size() || - m_fds_retry.size() || - m_fds_close.size() || - m_fds_erase.size()) - { - return Select(0, 200000); - } - return Select(NULL); -} - - -int SocketHandler::Select(struct timeval *tsel) -{ - size_t ignore = 0; - while (m_add.size() > ignore) - { - if (m_sockets.size() >= FD_SETSIZE) - { - LogError(NULL, "Select", (int)m_sockets.size(), "FD_SETSIZE reached", LOG_LEVEL_WARNING); - break; - } - socket_m::iterator it = m_add.begin(); - SOCKET s = it -> first; - Socket *p = it -> second; -DEB( fprintf(stderr, "Trying to add fd %d, m_add.size() %d, ignore %d\n", (int)s, (int)m_add.size(), (int)ignore);) - // - if (m_sockets.find(p -> GetSocket()) != m_sockets.end()) - { - LogError(p, "Add", (int)p -> GetSocket(), "Attempt to add socket already in controlled queue", LOG_LEVEL_FATAL); - // %! it's a dup, don't add to delete queue, just ignore it - m_delete.push_back(p); - m_add.erase(it); -// ignore++; - continue; - } - if (!p -> CloseAndDelete()) - { - StreamSocket *scp = dynamic_cast(p); - if (scp && scp -> Connecting()) // 'Open' called before adding socket - { - Set(s,false,true); - } - else - { - TcpSocket *tcp = dynamic_cast(p); - bool bWrite = tcp ? tcp -> GetOutputLength() != 0 : false; - if (p -> IsDisableRead()) - { - Set(s, false, bWrite); - } - else - { - Set(s, true, bWrite); - } - } - m_maxsock = (s > m_maxsock) ? s : m_maxsock; - } - else - { - LogError(p, "Add", (int)p -> GetSocket(), "Trying to add socket with SetCloseAndDelete() true", LOG_LEVEL_WARNING); - } - // only add to m_fds (process fd_set events) if - // slave handler and detached/detaching socket - // master handler and non-detached socket -#ifdef ENABLE_DETACH - if (!(m_slave ^ p -> IsDetach())) -#endif - { - m_fds.push_back(s); - } - m_sockets[s] = p; - // - m_add.erase(it); - } -#ifdef MACOSX - fd_set rfds; - fd_set wfds; - fd_set efds; - FD_COPY(&m_rfds, &rfds); - FD_COPY(&m_wfds, &wfds); - FD_COPY(&m_efds, &efds); -#else - fd_set rfds = m_rfds; - fd_set wfds = m_wfds; - fd_set efds = m_efds; -#endif - int n; - if (m_b_use_mutex) - { - m_mutex.Unlock(); - n = select( (int)(m_maxsock + 1),&rfds,&wfds,&efds,tsel); - m_mutex.Lock(); - } - else - { - n = select( (int)(m_maxsock + 1),&rfds,&wfds,&efds,tsel); - } - if (n == -1) - { - /* - EBADF An invalid file descriptor was given in one of the sets. - EINTR A non blocked signal was caught. - EINVAL n is negative. Or struct timeval contains bad time values (<0). - ENOMEM select was unable to allocate memory for internal tables. - */ - if (Errno != m_preverror || m_errcnt++ % 10000 == 0) - { - LogError(NULL, "select", Errno, StrError(Errno)); -DEB( fprintf(stderr, "m_maxsock: %d\n", m_maxsock); - fprintf(stderr, "%s\n", Errno == EINVAL ? "EINVAL" : - Errno == EINTR ? "EINTR" : - Errno == EBADF ? "EBADF" : - Errno == ENOMEM ? "ENOMEM" : ""); - // test bad fd - for (SOCKET i = 0; i <= m_maxsock; i++) - { - bool t = false; - FD_ZERO(&rfds); - FD_ZERO(&wfds); - FD_ZERO(&efds); - if (FD_ISSET(i, &m_rfds)) - { - FD_SET(i, &rfds); - t = true; - } - if (FD_ISSET(i, &m_wfds)) - { - FD_SET(i, &wfds); - t = true; - } - if (FD_ISSET(i, &m_efds)) - { - FD_SET(i, &efds); - t = true; - } - if (t && m_sockets.find(i) == m_sockets.end()) - { - fprintf(stderr, "Bad fd in fd_set: %d\n", i); - } - } -) // DEB - m_preverror = Errno; - } - /// \todo rebuild fd_set's from active sockets list (m_sockets) here - } - else - if (!n) - { - m_preverror = -1; - } - else - if (n > 0) - { - for (socket_v::iterator it2 = m_fds.begin(); it2 != m_fds.end() && n; it2++) - { - SOCKET i = *it2; - if (FD_ISSET(i, &rfds)) - { - socket_m::iterator itmp = m_sockets.find(i); - if (itmp != m_sockets.end()) // found - { - Socket *p = itmp -> second; - // new SSL negotiate method -#ifdef HAVE_OPENSSL - if (p -> IsSSLNegotiate()) - { - p -> SSLNegotiate(); - } - else -#endif - { - p -> OnRead(); - } - } - else - { - LogError(NULL, "GetSocket/handler/1", (int)i, "Did not find expected socket using file descriptor", LOG_LEVEL_WARNING); - } - n--; - } - if (FD_ISSET(i, &wfds)) - { - socket_m::iterator itmp = m_sockets.find(i); - if (itmp != m_sockets.end()) // found - { - Socket *p = itmp -> second; - // new SSL negotiate method -#ifdef HAVE_OPENSSL - if (p -> IsSSLNegotiate()) - { - p -> SSLNegotiate(); - } - else -#endif - { - p -> OnWrite(); - } - } - else - { - LogError(NULL, "GetSocket/handler/2", (int)i, "Did not find expected socket using file descriptor", LOG_LEVEL_WARNING); - } - n--; - } - if (FD_ISSET(i, &efds)) - { - socket_m::iterator itmp = m_sockets.find(i); - if (itmp != m_sockets.end()) // found - { - Socket *p = itmp -> second; - p -> OnException(); - } - else - { - LogError(NULL, "GetSocket/handler/3", (int)i, "Did not find expected socket using file descriptor", LOG_LEVEL_WARNING); - } - n--; - } - } // m_fds loop - m_preverror = -1; - } // if (n > 0) - - // check CallOnConnect - EVENT - if (m_fds_callonconnect.size()) - { - socket_v tmp = m_fds_callonconnect; - for (socket_v::iterator it = tmp.begin(); it != tmp.end(); it++) - { - Socket *p = NULL; - { - socket_m::iterator itmp = m_sockets.find(*it); - if (itmp != m_sockets.end()) // found - { - p = itmp -> second; - } - else - { - LogError(NULL, "GetSocket/handler/4", (int)*it, "Did not find expected socket using file descriptor", LOG_LEVEL_WARNING); - } - } - if (p) - { -// if (p -> CallOnConnect() && p -> Ready() ) - { - p -> SetConnected(); // moved here from inside if (tcp) check below -#ifdef HAVE_OPENSSL - if (p -> IsSSL()) // SSL Enabled socket - p -> OnSSLConnect(); - else -#endif -#ifdef ENABLE_SOCKS4 - if (p -> Socks4()) - p -> OnSocks4Connect(); - else -#endif - { - TcpSocket *tcp = dynamic_cast(p); - if (tcp) - { - if (tcp -> GetOutputLength()) - { - p -> OnWrite(); - } - } -#ifdef ENABLE_RECONNECT - if (tcp && tcp -> IsReconnect()) - p -> OnReconnect(); - else -#endif - { -// LogError(p, "Calling OnConnect", 0, "Because CallOnConnect", LOG_LEVEL_INFO); - p -> OnConnect(); - } - } -// p -> SetCallOnConnect( false ); - AddList(p -> GetSocket(), LIST_CALLONCONNECT, false); - } - } - } - } -#ifdef ENABLE_DETACH - // check detach of socket if master handler - EVENT - if (!m_slave && m_fds_detach.size()) - { - // %! why not using tmp list here??!? - for (socket_v::iterator it = m_fds_detach.begin(); it != m_fds_detach.end(); it++) - { - Socket *p = NULL; - { - socket_m::iterator itmp = m_sockets.find(*it); - if (itmp != m_sockets.end()) // found - { - p = itmp -> second; - } - else - { - LogError(NULL, "GetSocket/handler/5", (int)*it, "Did not find expected socket using file descriptor", LOG_LEVEL_WARNING); - } - } - if (p) - { -// if (p -> IsDetach()) - { - Set(p -> GetSocket(), false, false, false); - // After DetachSocket(), all calls to Handler() will return a reference - // to the new slave SocketHandler running in the new thread. - p -> DetachSocket(); - // Adding the file descriptor to m_fds_erase will now also remove the - // socket from the detach queue - tnx knightmad - m_fds_erase.push_back(p -> GetSocket()); - } - } - } - } -#endif - // check Connecting - connection timeout - conditional event - if (m_fds_timeout.size()) - { - time_t tnow = time(NULL); - if (tnow != m_tlast) - { - socket_v tmp = m_fds_timeout; -DEB( fprintf(stderr, "Checking %d socket(s) for timeout\n", tmp.size());) - for (socket_v::iterator it = tmp.begin(); it != tmp.end(); it++) - { - Socket *p = NULL; - { - socket_m::iterator itmp = m_sockets.find(*it); - if (itmp != m_sockets.end()) // found - { - p = itmp -> second; - } - else - { - itmp = m_add.find(*it); - if (itmp != m_add.end()) - { - p = itmp -> second; - } - else - { - LogError(NULL, "GetSocket/handler/6", (int)*it, "Did not find expected socket using file descriptor", LOG_LEVEL_WARNING); - } - } - } - if (p) - { - if (p -> Timeout(tnow)) - { - StreamSocket *scp = dynamic_cast(p); - if (scp && scp -> Connecting()) - p -> OnConnectTimeout(); - else - p -> OnTimeout(); - p -> SetTimeout(0); - } - } - } - m_tlast = tnow; - } // tnow != tlast - } - // check retry client connect - EVENT - if (m_fds_retry.size()) - { - socket_v tmp = m_fds_retry; - for (socket_v::iterator it = tmp.begin(); it != tmp.end(); it++) - { - Socket *p = NULL; - { - socket_m::iterator itmp = m_sockets.find(*it); - if (itmp != m_sockets.end()) // found - { - p = itmp -> second; - } - else - { - LogError(NULL, "GetSocket/handler/7", (int)*it, "Did not find expected socket using file descriptor", LOG_LEVEL_WARNING); - } - } - if (p) - { -// if (p -> RetryClientConnect()) - { - TcpSocket *tcp = dynamic_cast(p); - SOCKET nn = *it; //(*it3).first; - tcp -> SetRetryClientConnect(false); -DEB( fprintf(stderr, "Close() before retry client connect\n");) - p -> Close(); // removes from m_fds_retry - std::auto_ptr ad = p -> GetClientRemoteAddress(); - if (ad.get()) - { - tcp -> Open(*ad); - } - else - { - LogError(p, "RetryClientConnect", 0, "no address", LOG_LEVEL_ERROR); - } - Add(p); - m_fds_erase.push_back(nn); - } - } - } - } - // check close and delete - conditional event - if (m_fds_close.size()) - { - socket_v tmp = m_fds_close; -DEB( fprintf(stderr, "m_fds_close.size() == %d\n", (int)m_fds_close.size());) - for (socket_v::iterator it = tmp.begin(); it != tmp.end(); it++) - { - Socket *p = NULL; - { - socket_m::iterator itmp = m_sockets.find(*it); - if (itmp != m_sockets.end()) // found - { - p = itmp -> second; - } - else - { - itmp = m_add.find(*it); - if (itmp != m_add.end()) - { - p = itmp -> second; - } - else - { - LogError(NULL, "GetSocket/handler/8", (int)*it, "Did not find expected socket using file descriptor", LOG_LEVEL_WARNING); - } - } - } - if (p) - { -// if (p -> CloseAndDelete() ) - { - TcpSocket *tcp = dynamic_cast(p); - // new graceful tcp - flush and close timeout 5s - if (tcp && p -> IsConnected() && tcp -> GetFlushBeforeClose() && -#ifdef HAVE_OPENSSL - !tcp -> IsSSL() && -#endif - p -> TimeSinceClose() < 5) - { -DEB( fprintf(stderr, " close(1)\n");) - if (tcp -> GetOutputLength()) - { - LogError(p, "Closing", (int)tcp -> GetOutputLength(), "Sending all data before closing", LOG_LEVEL_INFO); - } - else // shutdown write when output buffer is empty - if (!(tcp -> GetShutdown() & SHUT_WR)) - { - SOCKET nn = *it; - if (nn != INVALID_SOCKET && shutdown(nn, SHUT_WR) == -1) - { - LogError(p, "graceful shutdown", Errno, StrError(Errno), LOG_LEVEL_ERROR); - } - tcp -> SetShutdown(SHUT_WR); - } - } - else -#ifdef ENABLE_RECONNECT - if (tcp && p -> IsConnected() && tcp -> Reconnect()) - { - SOCKET nn = *it; //(*it3).first; -DEB( fprintf(stderr, " close(2) fd %d\n", nn);) - p -> SetCloseAndDelete(false); - tcp -> SetIsReconnect(); - p -> SetConnected(false); -DEB( fprintf(stderr, "Close() before reconnect\n");) - p -> Close(); // dispose of old file descriptor (Open creates a new) - p -> OnDisconnect(); - std::auto_ptr ad = p -> GetClientRemoteAddress(); - if (ad.get()) - { - tcp -> Open(*ad); - } - else - { - LogError(p, "Reconnect", 0, "no address", LOG_LEVEL_ERROR); - } - tcp -> ResetConnectionRetries(); - Add(p); - m_fds_erase.push_back(nn); - } - else -#endif - { - SOCKET nn = *it; //(*it3).first; -DEB( fprintf(stderr, " close(3) fd %d GetSocket() %d\n", nn, p -> GetSocket());) - if (tcp && p -> IsConnected() && tcp -> GetOutputLength()) - { - LogError(p, "Closing", (int)tcp -> GetOutputLength(), "Closing socket while data still left to send", LOG_LEVEL_WARNING); - } -#ifdef ENABLE_POOL - if (p -> Retain() && !p -> Lost()) - { - PoolSocket *p2 = new PoolSocket(*this, p); - p2 -> SetDeleteByHandler(); - Add(p2); - // - p -> SetCloseAndDelete(false); // added - remove from m_fds_close - } - else -#endif // ENABLE_POOL - { - Set(p -> GetSocket(),false,false,false); -DEB( fprintf(stderr, "Close() before OnDelete\n");) - p -> Close(); - } - p -> OnDelete(); - if (p -> DeleteByHandler()) - { - p -> SetErasedByHandler(); - } - m_fds_erase.push_back(nn); - } - } - } - } - } - - // check erased sockets - bool check_max_fd = false; - while (m_fds_erase.size()) - { - socket_v::iterator it = m_fds_erase.begin(); - SOCKET nn = *it; -#ifdef ENABLE_DETACH - { - for (socket_v::iterator it = m_fds_detach.begin(); it != m_fds_detach.end(); it++) - { - if (*it == nn) - { - m_fds_detach.erase(it); - break; - } - } - } -#endif - { - for (socket_v::iterator it = m_fds.begin(); it != m_fds.end(); it++) - { - if (*it == nn) - { - m_fds.erase(it); - break; - } - } - } - { - socket_m::iterator it = m_sockets.find(nn); - if (it != m_sockets.end()) - { - Socket *p = it -> second; - /* Sometimes a SocketThread class can finish its run before the master - sockethandler gets here. In that case, the SocketThread has set the - 'ErasedByHandler' flag on the socket which will make us end up with a - double delete on the socket instance. - The fix is to make sure that the master sockethandler only can delete - non-detached sockets, and a slave sockethandler only can delete - detach sockets. */ - if (p -> ErasedByHandler() -#ifdef ENABLE_DETACH - && !(m_slave ^ p -> IsDetached()) -#endif - ) - { -#ifdef ENABLE_TRIGGERS - bool again = false; - do - { - again = false; - for (std::map::iterator it = m_trigger_src.begin(); it != m_trigger_src.end(); it++) - { - int id = it -> first; - Socket *src = it -> second; - if (src == p) - { - for (std::map::iterator it = m_trigger_dst[id].begin(); it != m_trigger_dst[id].end(); it++) - { - Socket *dst = it -> first; - if (Valid(dst)) - { - dst -> OnCancelled(id); - } - } - m_trigger_src.erase(m_trigger_src.find(id)); - m_trigger_dst.erase(m_trigger_dst.find(id)); - again = true; - break; - } - } - } while (again); -#endif - delete p; - } - m_sockets.erase(it); - } - } - m_fds_erase.erase(it); - check_max_fd = true; - } - // calculate max file descriptor for select() call - if (check_max_fd) - { - m_maxsock = 0; - for (socket_v::iterator it = m_fds.begin(); it != m_fds.end(); it++) - { - SOCKET s = *it; - m_maxsock = s > m_maxsock ? s : m_maxsock; - } - } - // remove Add's that fizzed - while (m_delete.size()) - { - std::list::iterator it = m_delete.begin(); - Socket *p = *it; - p -> OnDelete(); - m_delete.erase(it); - if (p -> DeleteByHandler() -#ifdef ENABLE_DETACH - && !(m_slave ^ p -> IsDetached()) -#endif - ) - { - p -> SetErasedByHandler(); -#ifdef ENABLE_TRIGGERS - bool again = false; - do - { - again = false; - for (std::map::iterator it = m_trigger_src.begin(); it != m_trigger_src.end(); it++) - { - int id = it -> first; - Socket *src = it -> second; - if (src == p) - { - for (std::map::iterator it = m_trigger_dst[id].begin(); it != m_trigger_dst[id].end(); it++) - { - Socket *dst = it -> first; - if (Valid(dst)) - { - dst -> OnCancelled(id); - } - } - m_trigger_src.erase(m_trigger_src.find(id)); - m_trigger_dst.erase(m_trigger_dst.find(id)); - again = true; - break; - } - } - } while (again); -#endif - delete p; - } - } - return n; -} - - -#ifdef ENABLE_RESOLVER -bool SocketHandler::Resolving(Socket *p0) -{ - std::map::iterator it = m_resolve_q.find(p0); - return it != m_resolve_q.end(); -} -#endif - - -bool SocketHandler::Valid(Socket *p0) -{ - for (socket_m::iterator it = m_sockets.begin(); it != m_sockets.end(); it++) - { - Socket *p = it -> second; - if (p0 == p) - return true; - } - return false; -} - - -bool SocketHandler::OkToAccept(Socket *) -{ - return true; -} - - -size_t SocketHandler::GetCount() -{ -/* -printf(" m_sockets : %d\n", m_sockets.size()); -printf(" m_add : %d\n", m_add.size()); -printf(" m_delete : %d\n", m_delete.size()); -*/ - return m_sockets.size() + m_add.size() + m_delete.size(); -} - - -#ifdef ENABLE_SOCKS4 -void SocketHandler::SetSocks4Host(ipaddr_t a) -{ - m_socks4_host = a; -} - - -void SocketHandler::SetSocks4Host(const std::string& host) -{ - Utility::u2ip(host, m_socks4_host); -} - - -void SocketHandler::SetSocks4Port(port_t port) -{ - m_socks4_port = port; -} - - -void SocketHandler::SetSocks4Userid(const std::string& id) -{ - m_socks4_userid = id; -} -#endif - - -#ifdef ENABLE_RESOLVER -int SocketHandler::Resolve(Socket *p,const std::string& host,port_t port) -{ - // check cache - ResolvSocket *resolv = new ResolvSocket(*this, p, host, port); - resolv -> SetId(++m_resolv_id); - resolv -> SetDeleteByHandler(); - ipaddr_t local; - Utility::u2ip("127.0.0.1", local); - if (!resolv -> Open(local, m_resolver_port)) - { - LogError(resolv, "Resolve", -1, "Can't connect to local resolve server", LOG_LEVEL_FATAL); - } - Add(resolv); - m_resolve_q[p] = true; -DEB( fprintf(stderr, " *** Resolve '%s:%d' id#%d m_resolve_q size: %d p: %p\n", host.c_str(), port, resolv -> GetId(), m_resolve_q.size(), p);) - return resolv -> GetId(); -} - - -#ifdef ENABLE_IPV6 -int SocketHandler::Resolve6(Socket *p,const std::string& host,port_t port) -{ - // check cache - ResolvSocket *resolv = new ResolvSocket(*this, p, host, port, true); - resolv -> SetId(++m_resolv_id); - resolv -> SetDeleteByHandler(); - ipaddr_t local; - Utility::u2ip("127.0.0.1", local); - if (!resolv -> Open(local, m_resolver_port)) - { - LogError(resolv, "Resolve", -1, "Can't connect to local resolve server", LOG_LEVEL_FATAL); - } - Add(resolv); - m_resolve_q[p] = true; - return resolv -> GetId(); -} -#endif - - -int SocketHandler::Resolve(Socket *p,ipaddr_t a) -{ - // check cache - ResolvSocket *resolv = new ResolvSocket(*this, p, a); - resolv -> SetId(++m_resolv_id); - resolv -> SetDeleteByHandler(); - ipaddr_t local; - Utility::u2ip("127.0.0.1", local); - if (!resolv -> Open(local, m_resolver_port)) - { - LogError(resolv, "Resolve", -1, "Can't connect to local resolve server", LOG_LEVEL_FATAL); - } - Add(resolv); - m_resolve_q[p] = true; - return resolv -> GetId(); -} - - -#ifdef ENABLE_IPV6 -int SocketHandler::Resolve(Socket *p,in6_addr& a) -{ - // check cache - ResolvSocket *resolv = new ResolvSocket(*this, p, a); - resolv -> SetId(++m_resolv_id); - resolv -> SetDeleteByHandler(); - ipaddr_t local; - Utility::u2ip("127.0.0.1", local); - if (!resolv -> Open(local, m_resolver_port)) - { - LogError(resolv, "Resolve", -1, "Can't connect to local resolve server", LOG_LEVEL_FATAL); - } - Add(resolv); - m_resolve_q[p] = true; - return resolv -> GetId(); -} -#endif - - -void SocketHandler::EnableResolver(port_t port) -{ - if (!m_resolver) - { - m_resolver_port = port; - m_resolver = new ResolvServer(port); - } -} - - -bool SocketHandler::ResolverReady() -{ - return m_resolver ? m_resolver -> Ready() : false; -} -#endif // ENABLE_RESOLVER - - -#ifdef ENABLE_SOCKS4 -void SocketHandler::SetSocks4TryDirect(bool x) -{ - m_bTryDirect = x; -} - - -ipaddr_t SocketHandler::GetSocks4Host() -{ - return m_socks4_host; -} - - -port_t SocketHandler::GetSocks4Port() -{ - return m_socks4_port; -} - - -const std::string& SocketHandler::GetSocks4Userid() -{ - return m_socks4_userid; -} - - -bool SocketHandler::Socks4TryDirect() -{ - return m_bTryDirect; -} -#endif - - -#ifdef ENABLE_RESOLVER -bool SocketHandler::ResolverEnabled() -{ - return m_resolver ? true : false; -} - - -port_t SocketHandler::GetResolverPort() -{ - return m_resolver_port; -} -#endif // ENABLE_RESOLVER - - -#ifdef ENABLE_POOL -ISocketHandler::PoolSocket *SocketHandler::FindConnection(int type,const std::string& protocol,SocketAddress& ad) -{ - for (socket_m::iterator it = m_sockets.begin(); it != m_sockets.end() && m_sockets.size(); it++) - { - PoolSocket *pools = dynamic_cast(it -> second); - if (pools) - { - if (pools -> GetSocketType() == type && - pools -> GetSocketProtocol() == protocol && -// %! pools -> GetClientRemoteAddress() && - *pools -> GetClientRemoteAddress() == ad) - { - m_sockets.erase(it); - pools -> SetRetain(); // avoid Close in Socket destructor - return pools; // Caller is responsible that this socket is deleted - } - } - } - return NULL; -} - - -void SocketHandler::EnablePool(bool x) -{ - m_b_enable_pool = x; -} - - -bool SocketHandler::PoolEnabled() -{ - return m_b_enable_pool; -} -#endif - - -void SocketHandler::Remove(Socket *p) -{ -#ifdef ENABLE_RESOLVER - std::map::iterator it4 = m_resolve_q.find(p); - if (it4 != m_resolve_q.end()) - m_resolve_q.erase(it4); -#endif - if (p -> ErasedByHandler()) - { - return; - } - for (socket_m::iterator it = m_sockets.begin(); it != m_sockets.end(); it++) - { - if (it -> second == p) - { - LogError(p, "Remove", -1, "Socket destructor called while still in use", LOG_LEVEL_WARNING); - m_sockets.erase(it); - return; - } - } - for (socket_m::iterator it2 = m_add.begin(); it2 != m_add.end(); it2++) - { - if ((*it2).second == p) - { - LogError(p, "Remove", -2, "Socket destructor called while still in use", LOG_LEVEL_WARNING); - m_add.erase(it2); - return; - } - } - for (std::list::iterator it3 = m_delete.begin(); it3 != m_delete.end(); it3++) - { - if (*it3 == p) - { - LogError(p, "Remove", -3, "Socket destructor called while still in use", LOG_LEVEL_WARNING); - m_delete.erase(it3); - return; - } - } -} - - -void SocketHandler::CheckSanity() -{ - CheckList(m_fds, "active sockets"); // active sockets - CheckList(m_fds_erase, "sockets to be erased"); // should always be empty anyway - CheckList(m_fds_callonconnect, "checklist CallOnConnect"); -#ifdef ENABLE_DETACH - CheckList(m_fds_detach, "checklist Detach"); -#endif - CheckList(m_fds_timeout, "checklist Timeout"); - CheckList(m_fds_retry, "checklist retry client connect"); - CheckList(m_fds_close, "checklist close and delete"); -} - - -void SocketHandler::CheckList(socket_v& ref,const std::string& listname) -{ - for (socket_v::iterator it = ref.begin(); it != ref.end(); it++) - { - SOCKET s = *it; - if (m_sockets.find(s) != m_sockets.end()) - continue; - if (m_add.find(s) != m_add.end()) - continue; - bool found = false; - for (std::list::iterator it = m_delete.begin(); it != m_delete.end(); it++) - { - Socket *p = *it; - if (p -> GetSocket() == s) - { - found = true; - break; - } - } - if (!found) - { - fprintf(stderr, "CheckList failed for \"%s\": fd %d\n", listname.c_str(), s); - } - } -} - - -void SocketHandler::AddList(SOCKET s,list_t which_one,bool add) -{ - if (s == INVALID_SOCKET) - { -DEB( fprintf(stderr, "AddList: invalid_socket\n");) - return; - } - socket_v& ref = - (which_one == LIST_CALLONCONNECT) ? m_fds_callonconnect : -#ifdef ENABLE_DETACH - (which_one == LIST_DETACH) ? m_fds_detach : -#endif - (which_one == LIST_TIMEOUT) ? m_fds_timeout : - (which_one == LIST_RETRY) ? m_fds_retry : - (which_one == LIST_CLOSE) ? m_fds_close : m_fds_close; - if (add) - { -#ifdef ENABLE_DETACH -DEB( fprintf(stderr, "AddList; %5d: %s: %s\n", s, (which_one == LIST_CALLONCONNECT) ? "CallOnConnect" : - (which_one == LIST_DETACH) ? "Detach" : - (which_one == LIST_TIMEOUT) ? "Timeout" : - (which_one == LIST_RETRY) ? "Retry" : - (which_one == LIST_CLOSE) ? "Close" : "", - add ? "Add" : "Remove");) -#else -DEB( fprintf(stderr, "AddList; %5d: %s: %s\n", s, (which_one == LIST_CALLONCONNECT) ? "CallOnConnect" : - (which_one == LIST_TIMEOUT) ? "Timeout" : - (which_one == LIST_RETRY) ? "Retry" : - (which_one == LIST_CLOSE) ? "Close" : "", - add ? "Add" : "Remove");) -#endif - } - if (add) - { - for (socket_v::iterator it = ref.begin(); it != ref.end(); it++) - { - if (*it == s) // already there - { - return; - } - } - ref.push_back(s); - return; - } - // remove - for (socket_v::iterator it = ref.begin(); it != ref.end(); it++) - { - if (*it == s) - { - ref.erase(it); - break; - } - } -//DEB( fprintf(stderr, "/AddList\n");) -} - - -#ifdef ENABLE_TRIGGERS -int SocketHandler::TriggerID(Socket *src) -{ - int id = m_next_trigger_id++; - m_trigger_src[id] = src; - return id; -} - - -bool SocketHandler::Subscribe(int id, Socket *dst) -{ - if (m_trigger_src.find(id) != m_trigger_src.end()) - { - std::map::iterator it = m_trigger_dst[id].find(dst); - if (it != m_trigger_dst[id].end()) - { - m_trigger_dst[id][dst] = true; - return true; - } - LogError(dst, "Subscribe", id, "Already subscribed", LOG_LEVEL_INFO); - return false; - } - LogError(dst, "Subscribe", id, "Trigger id not found", LOG_LEVEL_INFO); - return false; -} - - -bool SocketHandler::Unsubscribe(int id, Socket *dst) -{ - if (m_trigger_src.find(id) != m_trigger_src.end()) - { - std::map::iterator it = m_trigger_dst[id].find(dst); - if (it != m_trigger_dst[id].end()) - { - m_trigger_dst[id].erase(it); - return true; - } - LogError(dst, "Unsubscribe", id, "Not subscribed", LOG_LEVEL_INFO); - return false; - } - LogError(dst, "Unsubscribe", id, "Trigger id not found", LOG_LEVEL_INFO); - return false; -} - - -void SocketHandler::Trigger(int id, Socket::TriggerData& data, bool erase) -{ - if (m_trigger_src.find(id) != m_trigger_src.end()) - { - data.SetSource( m_trigger_src[id] ); - for (std::map::iterator it = m_trigger_dst[id].begin(); it != m_trigger_dst[id].end(); it++) - { - Socket *dst = it -> first; - if (Valid(dst)) - { - dst -> OnTrigger(id, data); - } - } - if (erase) - { - m_trigger_src.erase(m_trigger_src.find(id)); - m_trigger_dst.erase(m_trigger_dst.find(id)); - } - } - else - { - LogError(NULL, "Trigger", id, "Trigger id not found", LOG_LEVEL_INFO); - } -} -#endif // ENABLE_TRIGGERS - - -#ifdef SOCKETS_NAMESPACE -} -#endif - diff --git a/Sockets/SocketHandler.h b/Sockets/SocketHandler.h deleted file mode 100644 index c7e20df..0000000 --- a/Sockets/SocketHandler.h +++ /dev/null @@ -1,266 +0,0 @@ -/** \file SocketHandler.h - ** \date 2004-02-13 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_SocketHandler_H -#define _SOCKETS_SocketHandler_H - -#include "sockets-config.h" -#include -#include - -#include "socket_include.h" -#include "ISocketHandler.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -class Socket; -#ifdef ENABLE_RESOLVER -class ResolvServer; -#endif -class Mutex; - -/** Socket container class, event generator. - \ingroup basic */ -class SocketHandler : public ISocketHandler -{ -protected: - /** Map type for holding file descriptors/socket object pointers. */ - typedef std::map socket_m; - -public: - /** SocketHandler constructor. - \param log Optional log class pointer */ - SocketHandler(StdLog *log = NULL); - - /** SocketHandler threadsafe constructor. - \param mutex Externally declared mutex variable - \param log Optional log class pointer */ - SocketHandler(Mutex& mutex,StdLog *log = NULL); - - ~SocketHandler(); - - /** Get mutex reference for threadsafe operations. */ - Mutex& GetMutex() const; - - /** Register StdLog object for error callback. - \param log Pointer to log class */ - void RegStdLog(StdLog *log); - - /** Log error to log class for print out / storage. */ - void LogError(Socket *p,const std::string& user_text,int err,const std::string& sys_err,loglevel_t t = LOG_LEVEL_WARNING); - - /** Add socket instance to socket map. Removal is always automatic. */ - void Add(Socket *); - - /** Get status of read/write/exception file descriptor set for a socket. */ - void Get(SOCKET s,bool& r,bool& w,bool& e); - - /** Set read/write/exception file descriptor sets (fd_set). */ - void Set(SOCKET s,bool bRead,bool bWrite,bool bException = true); - - /** Wait for events, generate callbacks. */ - int Select(long sec,long usec); - - /** This method will not return until an event has been detected. */ - int Select(); - - /** Wait for events, generate callbacks. */ - int Select(struct timeval *tsel); - - /** Check that a socket really is handled by this socket handler. */ - bool Valid(Socket *); - - /** Return number of sockets handled by this handler. */ - size_t GetCount(); - - /** Override and return false to deny all incoming connections. - \param p ListenSocket class pointer (use GetPort to identify which one) */ - bool OkToAccept(Socket *p); - - /** Called by Socket when a socket changes state. */ - void AddList(SOCKET s,list_t which_one,bool add); - - // Connection pool -#ifdef ENABLE_POOL - /** Find available open connection (used by connection pool). */ - ISocketHandler::PoolSocket *FindConnection(int type,const std::string& protocol,SocketAddress&); - /** Enable connection pool (by default disabled). */ - void EnablePool(bool x = true); - /** Check pool status. - \return true if connection pool is enabled */ - bool PoolEnabled(); -#endif // ENABLE_POOL - - // Socks4 -#ifdef ENABLE_SOCKS4 - /** Set socks4 server ip that all new tcp sockets should use. */ - void SetSocks4Host(ipaddr_t); - /** Set socks4 server hostname that all new tcp sockets should use. */ - void SetSocks4Host(const std::string& ); - /** Set socks4 server port number that all new tcp sockets should use. */ - void SetSocks4Port(port_t); - /** Set optional socks4 userid. */ - void SetSocks4Userid(const std::string& ); - /** If connection to socks4 server fails, immediately try direct connection to final host. */ - void SetSocks4TryDirect(bool x = true); - /** Get socks4 server ip. - \return socks4 server ip */ - ipaddr_t GetSocks4Host(); - /** Get socks4 port number. - \return socks4 port number */ - port_t GetSocks4Port(); - /** Get socks4 userid (optional). - \return socks4 userid */ - const std::string& GetSocks4Userid(); - /** Check status of socks4 try direct flag. - \return true if direct connection should be tried if connection to socks4 server fails */ - bool Socks4TryDirect(); -#endif // ENABLE_SOCKS4 - - // DNS resolve server -#ifdef ENABLE_RESOLVER - /** Enable asynchronous DNS. - \param port Listen port of asynchronous dns server */ - void EnableResolver(port_t port = 16667); - /** Check resolver status. - \return true if resolver is enabled */ - bool ResolverEnabled(); - /** Queue a dns request. - \param host Hostname to be resolved - \param port Port number will be echoed in Socket::OnResolved callback */ - int Resolve(Socket *,const std::string& host,port_t port); -#ifdef ENABLE_IPV6 - int Resolve6(Socket *,const std::string& host,port_t port); -#endif - /** Do a reverse dns lookup. */ - int Resolve(Socket *,ipaddr_t a); -#ifdef ENABLE_IPV6 - int Resolve(Socket *,in6_addr& a); -#endif - /** Get listen port of asynchronous dns server. */ - port_t GetResolverPort(); - /** Resolver thread ready for queries. */ - bool ResolverReady(); - /** Returns true if the socket is waiting for a resolve event. */ - bool Resolving(Socket *); -#endif // ENABLE_RESOLVER - -#ifdef ENABLE_TRIGGERS - /** Fetch unique trigger id. */ - int TriggerID(Socket *src); - /** Subscribe socket to trigger id. */ - bool Subscribe(int id, Socket *dst); - /** Unsubscribe socket from trigger id. */ - bool Unsubscribe(int id, Socket *dst); - /** Execute OnTrigger for subscribed sockets. - \param id Trigger ID - \param data Data passed from source to destination - \param erase Empty trigger id source and destination maps if 'true', - Leave them in place if 'false' - if a trigger should be called many times */ - void Trigger(int id, Socket::TriggerData& data, bool erase = true); -#endif // ENABLE_TRIGGERS - -#ifdef ENABLE_DETACH - /** Indicates that the handler runs under SocketThread. */ - void SetSlave(bool x = true); - /** Indicates that the handler runs under SocketThread. */ - bool IsSlave(); -#endif - - /** Sanity check of those accursed lists. */ - void CheckSanity(); - -protected: - socket_m m_sockets; ///< Active sockets map - socket_m m_add; ///< Sockets to be added to sockets map - std::list m_delete; ///< Sockets to be deleted (failed when Add) - -protected: - StdLog *m_stdlog; ///< Registered log class, or NULL - Mutex& m_mutex; ///< Thread safety mutex - bool m_b_use_mutex; ///< Mutex correctly initialized - -private: - void CheckList(socket_v&,const std::string&); ///< Used by CheckSanity - /** Remove socket from socket map, used by Socket class. */ - void Remove(Socket *); - SOCKET m_maxsock; ///< Highest file descriptor + 1 in active sockets list - fd_set m_rfds; ///< file descriptor set monitored for read events - fd_set m_wfds; ///< file descriptor set monitored for write events - fd_set m_efds; ///< file descriptor set monitored for exceptions - int m_preverror; ///< debug select() error - int m_errcnt; ///< debug select() error - time_t m_tlast; ///< timeout control - - // state lists - socket_v m_fds; ///< Active file descriptor list - socket_v m_fds_erase; ///< File descriptors that are to be erased from m_sockets - socket_v m_fds_callonconnect; ///< checklist CallOnConnect -#ifdef ENABLE_DETACH - socket_v m_fds_detach; ///< checklist Detach -#endif - socket_v m_fds_timeout; ///< checklist timeout - socket_v m_fds_retry; ///< checklist retry client connect - socket_v m_fds_close; ///< checklist close and delete - -#ifdef ENABLE_SOCKS4 - ipaddr_t m_socks4_host; ///< Socks4 server host ip - port_t m_socks4_port; ///< Socks4 server port number - std::string m_socks4_userid; ///< Socks4 userid - bool m_bTryDirect; ///< Try direct connection if socks4 server fails -#endif -#ifdef ENABLE_RESOLVER - int m_resolv_id; ///< Resolver id counter - ResolvServer *m_resolver; ///< Resolver thread pointer - port_t m_resolver_port; ///< Resolver listen port - std::map m_resolve_q; ///< resolve queue -#endif -#ifdef ENABLE_POOL - bool m_b_enable_pool; ///< Connection pool enabled if true -#endif -#ifdef ENABLE_TRIGGERS - int m_next_trigger_id; ///< Unique trigger id counter - std::map m_trigger_src; ///< mapping trigger id to source socket - std::map > m_trigger_dst; ///< mapping trigger id to destination sockets -#endif -#ifdef ENABLE_DETACH - bool m_slave; ///< Indicates that this is a ISocketHandler run in SocketThread -#endif -}; - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_SocketHandler_H - diff --git a/Sockets/Sockets-config.cpp b/Sockets/Sockets-config.cpp deleted file mode 100644 index 7311147..0000000 --- a/Sockets/Sockets-config.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/** - ** \file Sockets-config.cpp - ** \date 2006-09-04 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#include -#include -#include "sockets-config.h" -#include "socket_include.h" - -int main(int argc,char *argv[]) -{ - if (argc > 1 && !strcmp(argv[1], "-info")) - { -#ifdef HAVE_OPENSSL - printf("SSL support\n"); -#endif -#ifdef IPPROTO_IPV6 - printf("IPv6 support\n"); -#endif -#ifdef USE_SCTP -#ifdef IPPROTO_SCTP - printf("SCTP support\n"); -# ifdef HAVE_SCTP - printf(" HAVE_SCTP: yes\n"); -# else - printf(" HAVE_SCTP: no\n"); -# endif -# ifdef HAVE_KERNEL_SCTP - printf(" HAVE_KERNEL_SCTP: yes\n"); -# else - printf(" HAVE_KERNEL_SCTP: no\n"); -# endif -# ifdef HAVE_SCTP_PRSCTP - printf(" HAVE_SCTP_PRSCTP: yes\n"); -# else - printf(" HAVE_SCTP_PRSCTP: no\n"); -# endif -# ifdef HAVE_SCTP_ADDIP - printf(" HAVE_SCTP_ADDIP: yes\n"); -# else - printf(" HAVE_SCTP_ADDIP: no\n"); -# endif -# ifdef HAVE_SCTP_CANSET_PRIMARY - printf(" HAVE_SCTP_CANSETPRIMARY: yes\n"); -# else - printf(" HAVE_SCTP_CANSETPRIMARY: no\n"); -# endif -# ifdef HAVE_SCTP_SAT_NETWORK_CAPABILITY - printf(" HAVE_SCTP_SAT_NETWORK_CAPABILITY: yes\n"); -# else - printf(" HAVE_SCTP_SAT_NETWORK_CAPABILITY: no\n"); -# endif -# ifdef HAVE_SCTP_MULTIBUF - printf(" HAVE_SCTP_MULTIBUF: yes\n"); -# else - printf(" HAVE_SCTP_MULTIBUF: no\n"); -# endif -# ifdef HAVE_SCTP_NOCONNECT - printf(" HAVE_SCTP_NOCONNECT: yes\n"); -# else - printf(" HAVE_SCTP_NOCONNECT: no\n"); -# endif -# ifdef HAVE_SCTP_EXT_RCVINFO - printf(" HAVE_SCTP_EXT_RCVINFO: yes\n"); -# else - printf(" HAVE_SCTP_EXT_RCVINFO: no\n"); -# endif -#else - printf("No SCTP support\n"); -#endif -#endif - return 0; - } - printf(" -D_VERSION='\"%s\"'", _VERSION); - -#ifdef LINUX - printf(" -DLINUX"); -#endif -#ifdef MACOSX - printf(" -DMACOSX"); -#endif -#ifdef SOLARIS - printf(" -DSOLARIS"); -#endif -#ifdef SOLARIS8 - printf(" -DSOLARIS8"); -#endif -#ifdef _WIN32 - printf(" -D_WIN32"); -#endif -#ifdef __CYGWIN__ - printf(" -D__CYGWIN__"); -#endif -#ifdef SOCKETS_NAMESPACE - printf(" -DSOCKETS_NAMESPACE=%s", SOCKETS_NAMESPACE_STR); -#endif -#ifdef _DEBUG - printf(" -D_DEBUG"); -#endif - -} - - diff --git a/Sockets/StdLog.h b/Sockets/StdLog.h deleted file mode 100644 index c07037b..0000000 --- a/Sockets/StdLog.h +++ /dev/null @@ -1,74 +0,0 @@ -/** \file StdLog.h - ** \date 2004-06-01 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_StdLog_H -#define _SOCKETS_StdLog_H - -#include "sockets-config.h" -#include - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -/** error level enum. */ -typedef enum -{ - LOG_LEVEL_WARNING = 0, - LOG_LEVEL_ERROR, - LOG_LEVEL_FATAL, - LOG_LEVEL_INFO -} loglevel_t; - - -class ISocketHandler; -class Socket; - -/** \defgroup logging Log help classes */ -/** Log class interface. - \ingroup logging */ -class StdLog -{ -public: - virtual ~StdLog() {} - - virtual void error(ISocketHandler *,Socket *, - const std::string& user_text, - int err, - const std::string& sys_err, - loglevel_t = LOG_LEVEL_WARNING) = 0; -}; - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_StdLog_H - diff --git a/Sockets/StdoutLog.cpp b/Sockets/StdoutLog.cpp deleted file mode 100644 index c01d8b8..0000000 --- a/Sockets/StdoutLog.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/** \file StdoutLog.cpp - ** \date 2004-06-01 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif -#include "ISocketHandler.h" -#include "Socket.h" -#include "StdoutLog.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - - - -void StdoutLog::error(ISocketHandler *,Socket *sock,const std::string& call,int err,const std::string& sys_err,loglevel_t lvl) -{ - time_t t = time(NULL); - struct tm tp; -#ifdef _WIN32 - memcpy(&tp, localtime(&t), sizeof(tp)); -#else - localtime_r(&t, &tp); -#endif - std::string level; - - switch (lvl) - { - case LOG_LEVEL_WARNING: - level = "Warning"; - break; - case LOG_LEVEL_ERROR: - level = "Error"; - break; - case LOG_LEVEL_FATAL: - level = "Fatal"; - break; - case LOG_LEVEL_INFO: - level = "Info"; - break; - } - if (sock) - { - printf("%d-%02d-%02d %02d:%02d:%02d :: fd %d :: %s: %d %s (%s)\n", - tp.tm_year + 1900, - tp.tm_mon + 1, - tp.tm_mday, - tp.tm_hour,tp.tm_min,tp.tm_sec, - sock -> GetSocket(), - call.c_str(),err,sys_err.c_str(),level.c_str()); - } - else - { - printf("%d-%02d-%02d %02d:%02d:%02d :: %s: %d %s (%s)\n", - tp.tm_year + 1900, - tp.tm_mon + 1, - tp.tm_mday, - tp.tm_hour,tp.tm_min,tp.tm_sec, - call.c_str(),err,sys_err.c_str(),level.c_str()); - } -} - - -#ifdef SOCKETS_NAMESPACE -} -#endif - - diff --git a/Sockets/StdoutLog.h b/Sockets/StdoutLog.h deleted file mode 100644 index 5f96b34..0000000 --- a/Sockets/StdoutLog.h +++ /dev/null @@ -1,57 +0,0 @@ -/** \file StdoutLog.h - ** \date 2004-06-01 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_StdoutLog_H -#define _SOCKETS_StdoutLog_H - -#include "sockets-config.h" -#include "StdLog.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -/** StdLog implementation, logs to stdout. - \ingroup logging */ -class StdoutLog : public StdLog -{ -public: - void error(ISocketHandler *,Socket *,const std::string& call,int err,const std::string& sys_err,loglevel_t); -}; - - - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_StdoutLog_H - diff --git a/Sockets/StreamSocket.cpp b/Sockets/StreamSocket.cpp deleted file mode 100644 index 5c5780e..0000000 --- a/Sockets/StreamSocket.cpp +++ /dev/null @@ -1,169 +0,0 @@ -#include "StreamSocket.h" -#include "ISocketHandler.h" - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -StreamSocket::StreamSocket(ISocketHandler& h) : Socket(h) -,m_bConnecting(false) -,m_connect_timeout(5) -,m_flush_before_close(true) -,m_connection_retry(0) -,m_retries(0) -,m_call_on_connect(false) -,m_b_retry_connect(false) -,m_line_protocol(false) -,m_shutdown(0) -{ -} - - -StreamSocket::~StreamSocket() -{ -} - - -void StreamSocket::SetConnecting(bool x) -{ - if (x != m_bConnecting) - { - m_bConnecting = x; - if (x) - { - SetTimeout( GetConnectTimeout() ); - } - else - { - SetTimeout( 0 ); - } - } -} - - -bool StreamSocket::Connecting() -{ - return m_bConnecting; -} - - -bool StreamSocket::Ready() -{ - if (GetSocket() != INVALID_SOCKET && !Connecting() && !CloseAndDelete()) - return true; - return false; -} - - -void StreamSocket::SetConnectTimeout(int x) -{ - m_connect_timeout = x; -} - - -int StreamSocket::GetConnectTimeout() -{ - return m_connect_timeout; -} - - -void StreamSocket::SetFlushBeforeClose(bool x) -{ - m_flush_before_close = x; -} - - -bool StreamSocket::GetFlushBeforeClose() -{ - return m_flush_before_close; -} - - -int StreamSocket::GetConnectionRetry() -{ - return m_connection_retry; -} - - -void StreamSocket::SetConnectionRetry(int x) -{ - m_connection_retry = x; -} - - -int StreamSocket::GetConnectionRetries() -{ - return m_retries; -} - - -void StreamSocket::IncreaseConnectionRetries() -{ - m_retries++; -} - - -void StreamSocket::ResetConnectionRetries() -{ - m_retries = 0; -} - - -void StreamSocket::SetCallOnConnect(bool x) -{ - Handler().AddList(GetSocket(), LIST_CALLONCONNECT, x); - m_call_on_connect = x; -} - - -bool StreamSocket::CallOnConnect() -{ - return m_call_on_connect; -} - - -void StreamSocket::SetRetryClientConnect(bool x) -{ - Handler().AddList(GetSocket(), LIST_RETRY, x); - m_b_retry_connect = x; -} - - -bool StreamSocket::RetryClientConnect() -{ - return m_b_retry_connect; -} - - -void StreamSocket::SetLineProtocol(bool x) -{ - m_line_protocol = x; -} - - -bool StreamSocket::LineProtocol() -{ - return m_line_protocol; -} - - -void StreamSocket::SetShutdown(int x) -{ - m_shutdown = x; -} - - -int StreamSocket::GetShutdown() -{ - return m_shutdown; -} - - - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - diff --git a/Sockets/StreamSocket.h b/Sockets/StreamSocket.h deleted file mode 100644 index 3c24811..0000000 --- a/Sockets/StreamSocket.h +++ /dev/null @@ -1,127 +0,0 @@ -#ifndef _StreamSocket_H -#define _StreamSocket_H - -#include "Socket.h" - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -/** SOCK_STREAM Socket base class. - \ingroup basic */ -class StreamSocket : public Socket -{ -public: - StreamSocket(ISocketHandler& ); - ~StreamSocket(); - - /** Socket should Check Connect on next write event from select(). */ - void SetConnecting(bool = true); - - /** Check connecting flag. - \return true if the socket is still trying to connect */ - bool Connecting(); - - /** Returns true when socket file descriptor is valid, - socket connection is established, and socket is not about to - be closed. */ - bool Ready(); - - /** Set timeout to use for connection attempt. - \param x Timeout in seconds */ - void SetConnectTimeout(int x); - - /** Return number of seconds to wait for a connection. - \return Connection timeout (seconds) */ - int GetConnectTimeout(); - - /** Set flush before close to make a tcp socket completely empty its - output buffer before closing the connection. */ - void SetFlushBeforeClose(bool = true); - - /** Check flush before status. - \return true if the socket should send all data before closing */ - bool GetFlushBeforeClose(); - - /** Define number of connection retries (tcp only). - n = 0 - no retry - n > 0 - number of retries - n = -1 - unlimited retries */ - void SetConnectionRetry(int n); - - /** Get number of maximum connection retries (tcp only). */ - int GetConnectionRetry(); - - /** Increase number of actual connection retries (tcp only). */ - void IncreaseConnectionRetries(); - - /** Get number of actual connection retries (tcp only). */ - int GetConnectionRetries(); - - /** Reset actual connection retries (tcp only). */ - void ResetConnectionRetries(); - - // LIST_CALLONCONNECT - - /** Instruct socket to call OnConnect callback next sockethandler cycle. */ - void SetCallOnConnect(bool x = true); - - /** Check call on connect flag. - \return true if OnConnect() should be called a.s.a.p */ - bool CallOnConnect(); - - // LIST_RETRY - - /** Set flag to initiate a connection attempt after a connection timeout. */ - void SetRetryClientConnect(bool x = true); - - /** Check if a connection attempt should be made. - \return true when another attempt should be made */ - bool RetryClientConnect(); - - /** Called after OnRead if socket is in line protocol mode. - \sa SetLineProtocol */ - /** Enable the OnLine callback. Do not create your own OnRead - * callback when using this. */ - virtual void SetLineProtocol(bool = true); - - /** Check line protocol mode. - \return true if socket is in line protocol mode */ - bool LineProtocol(); - - /** Set shutdown status. */ - void SetShutdown(int); - - /** Get shutdown status. */ - int GetShutdown(); - - /** Returns IPPROTO_TCP or IPPROTO_SCTP */ - virtual int Protocol() = 0; - -protected: - StreamSocket(const StreamSocket& ) {} // copy constructor - -private: - StreamSocket& operator=(const StreamSocket& ) { return *this; } // assignment operator - - bool m_bConnecting; ///< Flag indicating connection in progress - int m_connect_timeout; ///< Connection timeout (seconds) - bool m_flush_before_close; ///< Send all data before closing (default true) - int m_connection_retry; ///< Maximum connection retries (tcp) - int m_retries; ///< Actual number of connection retries (tcp) - bool m_call_on_connect; ///< OnConnect will be called next ISocketHandler cycle if true - bool m_b_retry_connect; ///< Try another connection attempt next ISocketHandler cycle - bool m_line_protocol; ///< Line protocol mode flag - int m_shutdown; ///< Shutdown status -}; - - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - - -#endif // _StreamSocket_H - diff --git a/Sockets/TcpSocket.cpp b/Sockets/TcpSocket.cpp deleted file mode 100644 index 960ac35..0000000 --- a/Sockets/TcpSocket.cpp +++ /dev/null @@ -1,1729 +0,0 @@ -/** \file TcpSocket.cpp - ** \date 2004-02-13 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _WIN32 -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif -#include -#else -#include -#endif -#include "ISocketHandler.h" -#include -#include -#include -#ifdef HAVE_OPENSSL -#include -#include -#endif - -#include "TcpSocket.h" -#include "Utility.h" -#include "Ipv4Address.h" -#include "Ipv6Address.h" -#include "Mutex.h" -#include "IFile.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -#ifdef _DEBUG -#define DEB(x) x -#else -#define DEB(x) -#endif - - -// statics -#ifdef HAVE_OPENSSL -SSLInitializer TcpSocket::m_ssl_init; -#endif - - -// thanks, q -#ifdef _MSC_VER -#pragma warning(disable:4355) -#endif -TcpSocket::TcpSocket(ISocketHandler& h) : StreamSocket(h) -,ibuf(TCP_BUFSIZE_READ) -,m_b_input_buffer_disabled(false) -,m_bytes_sent(0) -,m_bytes_received(0) -,m_skip_c(false) -#ifdef SOCKETS_DYNAMIC_TEMP -,m_buf(new char[TCP_BUFSIZE_READ + 1]) -#endif -,m_obuf_top(NULL) -,m_transfer_limit(0) -,m_output_length(0) -#ifdef HAVE_OPENSSL -,m_ssl_ctx(NULL) -,m_ssl(NULL) -,m_sbio(NULL) -#endif -#ifdef ENABLE_SOCKS4 -,m_socks4_state(0) -#endif -#ifdef ENABLE_RESOLVER -,m_resolver_id(0) -#endif -#ifdef ENABLE_RECONNECT -,m_b_reconnect(false) -,m_b_is_reconnect(false) -#endif -{ -} -#ifdef _MSC_VER -#pragma warning(default:4355) -#endif - - -#ifdef _MSC_VER -#pragma warning(disable:4355) -#endif -TcpSocket::TcpSocket(ISocketHandler& h,size_t isize,size_t osize) : StreamSocket(h) -,ibuf(isize) -,m_b_input_buffer_disabled(false) -,m_bytes_sent(0) -,m_bytes_received(0) -,m_skip_c(false) -#ifdef SOCKETS_DYNAMIC_TEMP -,m_buf(new char[TCP_BUFSIZE_READ + 1]) -#endif -,m_obuf_top(NULL) -,m_transfer_limit(0) -,m_output_length(0) -#ifdef HAVE_OPENSSL -,m_ssl_ctx(NULL) -,m_ssl(NULL) -,m_sbio(NULL) -#endif -#ifdef ENABLE_SOCKS4 -,m_socks4_state(0) -#endif -#ifdef ENABLE_RESOLVER -,m_resolver_id(0) -#endif -#ifdef ENABLE_RECONNECT -,m_b_reconnect(false) -,m_b_is_reconnect(false) -#endif -{ -} -#ifdef _MSC_VER -#pragma warning(default:4355) -#endif - - -TcpSocket::~TcpSocket() -{ -#ifdef SOCKETS_DYNAMIC_TEMP - delete[] m_buf; -#endif - // %! empty m_obuf -#ifdef HAVE_OPENSSL - if (m_ssl) - { - SSL_free(m_ssl); - } -#endif -} - - -bool TcpSocket::Open(ipaddr_t ip,port_t port,bool skip_socks) -{ - Ipv4Address ad(ip, port); - Ipv4Address local; - return Open(ad, local, skip_socks); -} - - -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 -bool TcpSocket::Open(in6_addr ip,port_t port,bool skip_socks) -{ - Ipv6Address ad(ip, port); - return Open(ad, skip_socks); -} -#endif -#endif - - -bool TcpSocket::Open(SocketAddress& ad,bool skip_socks) -{ - Ipv4Address bind_ad("0.0.0.0", 0); - return Open(ad, bind_ad, skip_socks); -} - - -bool TcpSocket::Open(SocketAddress& ad,SocketAddress& bind_ad,bool skip_socks) -{ - if (!ad.IsValid()) - { - Handler().LogError(this, "Open", 0, "Invalid SocketAddress", LOG_LEVEL_FATAL); - SetCloseAndDelete(); - return false; - } - if (Handler().GetCount() >= FD_SETSIZE) - { - Handler().LogError(this, "Open", 0, "no space left in fd_set", LOG_LEVEL_FATAL); - SetCloseAndDelete(); - return false; - } - SetConnecting(false); -#ifdef ENABLE_SOCKS4 - SetSocks4(false); -#endif - // check for pooling -#ifdef ENABLE_POOL - if (Handler().PoolEnabled()) - { - ISocketHandler::PoolSocket *pools = Handler().FindConnection(SOCK_STREAM, "tcp", ad); - if (pools) - { - CopyConnection( pools ); - delete pools; - - SetIsClient(); - SetCallOnConnect(); // ISocketHandler must call OnConnect - Handler().LogError(this, "SetCallOnConnect", 0, "Found pooled connection", LOG_LEVEL_INFO); - return true; - } - } -#endif - // if not, create new connection - SOCKET s = CreateSocket(ad.GetFamily(), SOCK_STREAM, "tcp"); - if (s == INVALID_SOCKET) - { - return false; - } - // socket must be nonblocking for async connect - if (!SetNonblocking(true, s)) - { - SetCloseAndDelete(); - closesocket(s); - return false; - } -#ifdef ENABLE_POOL - SetIsClient(); // client because we connect -#endif - SetClientRemoteAddress(ad); - int n = 0; - if (bind_ad.GetPort() != 0) - { - bind(s, bind_ad, bind_ad); - } -#ifdef ENABLE_SOCKS4 - if (!skip_socks && GetSocks4Host() && GetSocks4Port()) - { - Ipv4Address sa(GetSocks4Host(), GetSocks4Port()); - { - std::string sockshost; - Utility::l2ip(GetSocks4Host(), sockshost); - Handler().LogError(this, "Open", 0, "Connecting to socks4 server @ " + sockshost + ":" + - Utility::l2string(GetSocks4Port()), LOG_LEVEL_INFO); - } - SetSocks4(); - n = connect(s, sa, sa); - SetRemoteAddress(sa); - } - else -#endif - { - n = connect(s, ad, ad); - SetRemoteAddress(ad); - } - if (n == -1) - { - // check error code that means a connect is in progress -#ifdef _WIN32 - if (Errno == WSAEWOULDBLOCK) -#else - if (Errno == EINPROGRESS) -#endif - { - Attach(s); - SetConnecting( true ); // this flag will control fd_set's - } - else -#ifdef ENABLE_SOCKS4 - if (Socks4() && Handler().Socks4TryDirect() ) // retry - { - closesocket(s); - return Open(ad, true); - } - else -#endif -#ifdef ENABLE_RECONNECT - if (Reconnect()) - { - Handler().LogError(this, "connect: failed, reconnect pending", Errno, StrError(Errno), LOG_LEVEL_INFO); - Attach(s); - SetConnecting( true ); // this flag will control fd_set's - } - else -#endif - { - Handler().LogError(this, "connect: failed", Errno, StrError(Errno), LOG_LEVEL_FATAL); - SetCloseAndDelete(); - closesocket(s); - return false; - } - } - else - { - Attach(s); - SetCallOnConnect(); // ISocketHandler must call OnConnect - } - - // 'true' means connected or connecting(not yet connected) - // 'false' means something failed - return true; //!Connecting(); -} - - -bool TcpSocket::Open(const std::string &host,port_t port) -{ -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (IsIpv6()) - { -#ifdef ENABLE_RESOLVER - if (!Handler().ResolverEnabled() || Utility::isipv6(host) ) - { -#endif - in6_addr a; - if (!Utility::u2ip(host, a)) - { - SetCloseAndDelete(); - return false; - } - Ipv6Address ad(a, port); - Ipv6Address local; - return Open(ad, local); -#ifdef ENABLE_RESOLVER - } - m_resolver_id = Resolve6(host, port); - return true; -#endif - } -#endif -#endif -#ifdef ENABLE_RESOLVER - if (!Handler().ResolverEnabled() || Utility::isipv4(host) ) - { -#endif - ipaddr_t l; - if (!Utility::u2ip(host,l)) - { - SetCloseAndDelete(); - return false; - } - Ipv4Address ad(l, port); - Ipv4Address local; - return Open(ad, local); -#ifdef ENABLE_RESOLVER - } - // resolve using async resolver thread - m_resolver_id = Resolve(host, port); - return true; -#endif -} - - -#ifdef ENABLE_RESOLVER -void TcpSocket::OnResolved(int id,ipaddr_t a,port_t port) -{ -DEB( fprintf(stderr, "TcpSocket::OnResolved id %d addr %x port %d\n", id, a, port);) - if (id == m_resolver_id) - { - if (a && port) - { - Ipv4Address ad(a, port); - Ipv4Address local; - if (Open(ad, local)) - { - if (!Handler().Valid(this)) - { - Handler().Add(this); - } - } - } - else - { - Handler().LogError(this, "OnResolved", 0, "Resolver failed", LOG_LEVEL_FATAL); - SetCloseAndDelete(); - } - } - else - { - Handler().LogError(this, "OnResolved", id, "Resolver returned wrong job id", LOG_LEVEL_FATAL); - SetCloseAndDelete(); - } -} - - -#ifdef ENABLE_IPV6 -void TcpSocket::OnResolved(int id,in6_addr& a,port_t port) -{ - if (id == m_resolver_id) - { - Ipv6Address ad(a, port); - if (ad.IsValid()) - { - Ipv6Address local; - if (Open(ad, local)) - { - if (!Handler().Valid(this)) - { - Handler().Add(this); - } - } - } - } - else - { - Handler().LogError(this, "OnResolved", id, "Resolver returned wrong job id", LOG_LEVEL_FATAL); - SetCloseAndDelete(); - } -} -#endif -#endif - - -void TcpSocket::OnRead() -{ - int n = 0; -#ifdef SOCKETS_DYNAMIC_TEMP - char *buf = m_buf; -#else - char buf[TCP_BUFSIZE_READ]; -#endif -#ifdef HAVE_OPENSSL - if (IsSSL()) - { - if (!Ready()) - return; - n = SSL_read(m_ssl, buf, TCP_BUFSIZE_READ); - if (n == -1) - { - n = SSL_get_error(m_ssl, n); - switch (n) - { - case SSL_ERROR_NONE: - case SSL_ERROR_WANT_READ: - case SSL_ERROR_WANT_WRITE: - break; - case SSL_ERROR_ZERO_RETURN: -DEB( fprintf(stderr, "SSL_read() returns zero - closing socket\n");) - OnDisconnect(); - SetCloseAndDelete(true); - SetFlushBeforeClose(false); -#ifdef ENABLE_POOL - SetLost(); -#endif - break; - default: -DEB( fprintf(stderr, "SSL read problem, errcode = %d\n",n);) - OnDisconnect(); - SetCloseAndDelete(true); - SetFlushBeforeClose(false); -#ifdef ENABLE_POOL - SetLost(); -#endif - } - return; - } - else - if (!n) - { - OnDisconnect(); - SetCloseAndDelete(true); - SetFlushBeforeClose(false); -#ifdef ENABLE_POOL - SetLost(); -#endif - SetShutdown(SHUT_WR); - return; - } - else - if (n > 0 && n <= TCP_BUFSIZE_READ) - { - m_bytes_received += n; - if (GetTrafficMonitor()) - { - GetTrafficMonitor() -> fwrite(buf, 1, n); - } - if (!m_b_input_buffer_disabled && !ibuf.Write(buf,n)) - { - Handler().LogError(this, "OnRead(ssl)", 0, "ibuf overflow", LOG_LEVEL_WARNING); - } - } - else - { - Handler().LogError(this, "OnRead(ssl)", n, "abnormal value from SSL_read", LOG_LEVEL_ERROR); - } - } - else -#endif // HAVE_OPENSSL - { - n = recv(GetSocket(), buf, TCP_BUFSIZE_READ, MSG_NOSIGNAL); - if (n == -1) - { - Handler().LogError(this, "read", Errno, StrError(Errno), LOG_LEVEL_FATAL); - OnDisconnect(); - SetCloseAndDelete(true); - SetFlushBeforeClose(false); -#ifdef ENABLE_POOL - SetLost(); -#endif - return; - } - else - if (!n) - { - OnDisconnect(); - SetCloseAndDelete(true); - SetFlushBeforeClose(false); -#ifdef ENABLE_POOL - SetLost(); -#endif - SetShutdown(SHUT_WR); - return; - } - else - if (n > 0 && n <= TCP_BUFSIZE_READ) - { - m_bytes_received += n; - if (GetTrafficMonitor()) - { - GetTrafficMonitor() -> fwrite(buf, 1, n); - } - if (!m_b_input_buffer_disabled && !ibuf.Write(buf,n)) - { - Handler().LogError(this, "OnRead", 0, "ibuf overflow", LOG_LEVEL_WARNING); - } - } - else - { - Handler().LogError(this, "OnRead", n, "abnormal value from recv", LOG_LEVEL_ERROR); - } - } - // - OnRead( buf, n ); -} - - -void TcpSocket::OnRead( char *buf, size_t n ) -{ - // unbuffered - if (n > 0 && n <= TCP_BUFSIZE_READ) - { - if (LineProtocol()) - { - buf[n] = 0; - size_t i = 0; - if (m_skip_c && (buf[i] == 13 || buf[i] == 10) && buf[i] != m_c) - { - m_skip_c = false; - i++; - } - size_t x = i; - for (; i < n && LineProtocol(); i++) - { - while ((buf[i] == 13 || buf[i] == 10) && LineProtocol()) - { - char c = buf[i]; - buf[i] = 0; - if (buf[x]) - { - m_line += (buf + x); - } - OnLine( m_line ); - i++; - m_skip_c = true; - m_c = c; - if (i < n && (buf[i] == 13 || buf[i] == 10) && buf[i] != c) - { - m_skip_c = false; - i++; - } - x = i; - m_line = ""; - } - if (!LineProtocol()) - { - break; - } - } - if (!LineProtocol()) - { - if (i < n) - { - OnRawData(buf + i, n - i); - } - } - else - if (buf[x]) - { - m_line += (buf + x); - } - } - else - { - OnRawData(buf, n); - } - } - if (m_b_input_buffer_disabled) - { - return; - } - // further processing: socks4 -#ifdef ENABLE_SOCKS4 - if (Socks4()) - { - bool need_more = false; - while (GetInputLength() && !need_more && !CloseAndDelete()) - { - need_more = OnSocks4Read(); - } - } -#endif -} - - -void TcpSocket::OnWriteComplete() -{ -} - - -void TcpSocket::OnWrite() -{ - if (Connecting()) - { - int err = SoError(); - - // don't reset connecting flag on error here, we want the OnConnectFailed timeout later on - if (!err) // ok - { - Set(!IsDisableRead(), false); - SetConnecting(false); - SetCallOnConnect(); - return; - } - Handler().LogError(this, "tcp: connect failed", err, StrError(err), LOG_LEVEL_FATAL); - Set(false, false); // no more monitoring because connection failed - - // failed -#ifdef ENABLE_SOCKS4 - if (Socks4()) - { - // %! leave 'Connecting' flag set? - OnSocks4ConnectFailed(); - return; - } -#endif - if (GetConnectionRetry() == -1 || - (GetConnectionRetry() && GetConnectionRetries() < GetConnectionRetry()) ) - { - // even though the connection failed at once, only retry after - // the connection timeout. - // should we even try to connect again, when CheckConnect returns - // false it's because of a connection error - not a timeout... - return; - } - SetConnecting(false); - SetCloseAndDelete( true ); - /// \todo state reason why connect failed - OnConnectFailed(); - return; - } - // try send next block in buffer - // if full block is sent, repeat - // if all blocks are sent, reset m_wfds - - bool repeat = false; - size_t sz = m_transfer_limit ? GetOutputLength() : 0; - do - { - output_l::iterator it = m_obuf.begin(); - OUTPUT *p = *it; - repeat = false; - int n = TryWrite(p -> Buf(), p -> Len()); - if (n > 0) - { - size_t left = p -> Remove(n); - m_output_length -= n; - if (!left) - { - delete p; - m_obuf.erase(it); - if (!m_obuf.size()) - { - m_obuf_top = NULL; - OnWriteComplete(); - } - else - { - repeat = true; - } - } - } - } while (repeat); - - if (m_transfer_limit && sz > m_transfer_limit && GetOutputLength() < m_transfer_limit) - { - OnTransferLimit(); - } - - // check output buffer set, set/reset m_wfds accordingly - { - bool br; - bool bw; - bool bx; - Handler().Get(GetSocket(), br, bw, bx); - if (m_obuf.size()) - Set(br, true); - else - Set(br, false); - } -} - - -int TcpSocket::TryWrite(const char *buf, size_t len) -{ - int n = 0; -#ifdef HAVE_OPENSSL - if (IsSSL()) - { - n = SSL_write(m_ssl, buf, (int)len); - if (n == -1) - { - int errnr = SSL_get_error(m_ssl, n); - if ( errnr != SSL_ERROR_WANT_READ && errnr != SSL_ERROR_WANT_WRITE ) - { - OnDisconnect(); - SetCloseAndDelete(true); - SetFlushBeforeClose(false); -#ifdef ENABLE_POOL - SetLost(); -#endif - const char *errbuf = ERR_error_string(errnr, NULL); - Handler().LogError(this, "OnWrite/SSL_write", errnr, errbuf, LOG_LEVEL_FATAL); - } - return 0; - } - else - if (!n) - { - OnDisconnect(); - SetCloseAndDelete(true); - SetFlushBeforeClose(false); -#ifdef ENABLE_POOL - SetLost(); -#endif -DEB( int errnr = SSL_get_error(m_ssl, n); - const char *errbuf = ERR_error_string(errnr, NULL); - fprintf(stderr, "SSL_write() returns 0: %d : %s\n",errnr, errbuf);) - } - } - else -#endif // HAVE_OPENSSL - { - n = send(GetSocket(), buf, (int)len, MSG_NOSIGNAL); - if (n == -1) - { - // normal error codes: - // WSAEWOULDBLOCK - // EAGAIN or EWOULDBLOCK -#ifdef _WIN32 - if (Errno != WSAEWOULDBLOCK) -#else - if (Errno != EWOULDBLOCK) -#endif - { - Handler().LogError(this, "send", Errno, StrError(Errno), LOG_LEVEL_FATAL); - OnDisconnect(); - SetCloseAndDelete(true); - SetFlushBeforeClose(false); -#ifdef ENABLE_POOL - SetLost(); -#endif - } - return 0; - } - } - if (n > 0) - { - m_bytes_sent += n; - if (GetTrafficMonitor()) - { - GetTrafficMonitor() -> fwrite(buf, 1, n); - } - } - return n; -} - - -void TcpSocket::Buffer(const char *buf, size_t len) -{ - size_t ptr = 0; - m_output_length += len; - while (ptr < len) - { - // buf/len => pbuf/sz - size_t space = 0; - if (m_obuf_top && (space = m_obuf_top -> Space()) > 0) - { - const char *pbuf = buf + ptr; - size_t sz = len - ptr; - if (space >= sz) - { - m_obuf_top -> Add(pbuf, sz); - ptr += sz; - } - else - { - m_obuf_top -> Add(pbuf, space); - ptr += space; - } - } - else - { - m_obuf_top = new OUTPUT; - m_obuf.push_back( m_obuf_top ); - } - } -} - - -void TcpSocket::Send(const std::string &str,int i) -{ - SendBuf(str.c_str(),str.size(),i); -} - - -void TcpSocket::SendBuf(const char *buf,size_t len,int) -{ - if (!Ready() && !Connecting()) - { - Handler().LogError(this, "SendBuf", -1, "Attempt to write to a non-ready socket" ); // warning - if (GetSocket() == INVALID_SOCKET) - Handler().LogError(this, "SendBuf", 0, " * GetSocket() == INVALID_SOCKET", LOG_LEVEL_INFO); - if (Connecting()) - Handler().LogError(this, "SendBuf", 0, " * Connecting()", LOG_LEVEL_INFO); - if (CloseAndDelete()) - Handler().LogError(this, "SendBuf", 0, " * CloseAndDelete()", LOG_LEVEL_INFO); - return; - } - if (!IsConnected()) - { - Handler().LogError(this, "SendBuf", -1, "Attempt to write to a non-connected socket, will be sent on connect" ); // warning - Buffer(buf, len); - return; - } - if (m_obuf_top) - { - Buffer(buf, len); - return; - } - int n = TryWrite(buf, len); - if (n >= 0 && n < (int)len) - { - Buffer(buf + n, len - n); - } - // if ( data in buffer || !IsConnected ) - // { - // add to buffer - // } - // else - // try_send - // if any data is unsent, buffer it and set m_wfds - - // check output buffer set, set/reset m_wfds accordingly - { - bool br; - bool bw; - bool bx; - Handler().Get(GetSocket(), br, bw, bx); - if (m_obuf.size()) - Set(br, true); - else - Set(br, false); - } -} - - -void TcpSocket::OnLine(const std::string& ) -{ -} - - -#ifdef _MSC_VER -#pragma warning(disable:4355) -#endif -TcpSocket::TcpSocket(const TcpSocket& s) -:StreamSocket(s) -,ibuf(0) -{ -} -#ifdef _MSC_VER -#pragma warning(default:4355) -#endif - - -#ifdef ENABLE_SOCKS4 -void TcpSocket::OnSocks4Connect() -{ - char request[1000]; - memset(request, 0, sizeof(request)); - request[0] = 4; // socks v4 - request[1] = 1; // command code: CONNECT - { - std::auto_ptr ad = GetClientRemoteAddress(); - if (ad.get()) - { - struct sockaddr *p0 = (struct sockaddr *)*ad; - struct sockaddr_in *p = (struct sockaddr_in *)p0; - if (p -> sin_family == AF_INET) - { - memcpy(request + 2, &p -> sin_port, 2); // nwbo is ok here - memcpy(request + 4, &p -> sin_addr, sizeof(struct in_addr)); - } - else - { - /// \todo warn - } - } - else - { - /// \todo warn - } - } - strcpy(request + 8, GetSocks4Userid().c_str()); - size_t length = GetSocks4Userid().size() + 8 + 1; - SendBuf(request, length); - m_socks4_state = 0; -} - - -void TcpSocket::OnSocks4ConnectFailed() -{ - Handler().LogError(this,"OnSocks4ConnectFailed",0,"connection to socks4 server failed, trying direct connection",LOG_LEVEL_WARNING); - if (!Handler().Socks4TryDirect()) - { - SetConnecting(false); - SetCloseAndDelete(); - OnConnectFailed(); // just in case - } - else - { - SetRetryClientConnect(); - } -} - - -bool TcpSocket::OnSocks4Read() -{ - switch (m_socks4_state) - { - case 0: - ibuf.Read(&m_socks4_vn, 1); - m_socks4_state = 1; - break; - case 1: - ibuf.Read(&m_socks4_cd, 1); - m_socks4_state = 2; - break; - case 2: - if (GetInputLength() > 1) - { - ibuf.Read( (char *)&m_socks4_dstport, 2); - m_socks4_state = 3; - } - else - { - return true; - } - break; - case 3: - if (GetInputLength() > 3) - { - ibuf.Read( (char *)&m_socks4_dstip, 4); - SetSocks4(false); - - switch (m_socks4_cd) - { - case 90: - OnConnect(); - Handler().LogError(this, "OnSocks4Read", 0, "Connection established", LOG_LEVEL_INFO); - break; - case 91: - case 92: - case 93: - Handler().LogError(this,"OnSocks4Read",m_socks4_cd,"socks4 server reports connect failed",LOG_LEVEL_FATAL); - SetConnecting(false); - SetCloseAndDelete(); - OnConnectFailed(); - break; - default: - Handler().LogError(this,"OnSocks4Read",m_socks4_cd,"socks4 server unrecognized response",LOG_LEVEL_FATAL); - SetCloseAndDelete(); - break; - } - } - else - { - return true; - } - break; - } - return false; -} -#endif - - -void TcpSocket::Sendf(const char *format, ...) -{ - va_list ap; - va_start(ap, format); - char slask[5000]; // vsprintf / vsnprintf temporary -#ifdef _WIN32 - vsprintf(slask, format, ap); -#else - vsnprintf(slask, 5000, format, ap); -#endif - va_end(ap); - Send( slask ); -} - - -#ifdef HAVE_OPENSSL -void TcpSocket::OnSSLConnect() -{ - SetNonblocking(true); - { - if (m_ssl_ctx) - { -DEB( fprintf(stderr, "SSL Context already initialized - closing socket\n");) - SetCloseAndDelete(true); - return; - } - InitSSLClient(); - } - if (m_ssl_ctx) - { - /* Connect the SSL socket */ - m_ssl = SSL_new(m_ssl_ctx); - if (!m_ssl) - { -DEB( fprintf(stderr, " m_ssl is NULL\n");) - SetCloseAndDelete(true); - return; - } - SSL_set_mode(m_ssl, SSL_MODE_AUTO_RETRY); - m_sbio = BIO_new_socket((int)GetSocket(), BIO_NOCLOSE); - if (!m_sbio) - { -DEB( fprintf(stderr, " m_sbio is NULL\n");) - SetCloseAndDelete(true); - return; - } - SSL_set_bio(m_ssl, m_sbio, m_sbio); - if (!SSLNegotiate()) - { - SetSSLNegotiate(); - } - } - else - { - SetCloseAndDelete(); - } -} - - -void TcpSocket::OnSSLAccept() -{ - SetNonblocking(true); - { - if (m_ssl_ctx) - { -DEB( fprintf(stderr, "SSL Context already initialized - closing socket\n");) - SetCloseAndDelete(true); - return; - } - InitSSLServer(); - SetSSLServer(); - } - if (m_ssl_ctx) - { - m_ssl = SSL_new(m_ssl_ctx); - if (!m_ssl) - { -DEB( fprintf(stderr, " m_ssl is NULL\n");) - SetCloseAndDelete(true); - return; - } - SSL_set_mode(m_ssl, SSL_MODE_AUTO_RETRY); - m_sbio = BIO_new_socket((int)GetSocket(), BIO_NOCLOSE); - if (!m_sbio) - { -DEB( fprintf(stderr, " m_sbio is NULL\n");) - SetCloseAndDelete(true); - return; - } - SSL_set_bio(m_ssl, m_sbio, m_sbio); -// if (!SSLNegotiate()) - { - SetSSLNegotiate(); - } - } -} - - -bool TcpSocket::SSLNegotiate() -{ - if (!IsSSLServer()) // client - { - int r = SSL_connect(m_ssl); - if (r > 0) - { - SetSSLNegotiate(false); - /// \todo: resurrect certificate check... client -// CheckCertificateChain( "");//ServerHOST); - SetNonblocking(false); - // - { - SetConnected(); - if (GetOutputLength()) - { - OnWrite(); - } - } -#ifdef ENABLE_RECONNECT - if (IsReconnect()) - OnReconnect(); - else -#endif - { - OnConnect(); - } - Handler().LogError(this, "SSLNegotiate/SSL_connect", 0, "Connection established", LOG_LEVEL_INFO); - return true; - } - else - if (!r) - { - Handler().LogError(this, "SSLNegotiate/SSL_connect", 0, "Connection failed", LOG_LEVEL_INFO); - SetSSLNegotiate(false); - SetCloseAndDelete(); - OnSSLConnectFailed(); - } - else - { - r = SSL_get_error(m_ssl, r); - if (r != SSL_ERROR_WANT_READ && r != SSL_ERROR_WANT_WRITE) - { - Handler().LogError(this, "SSLNegotiate/SSL_connect", -1, "Connection failed", LOG_LEVEL_INFO); -DEB( fprintf(stderr, "SSL_connect() failed - closing socket, return code: %d\n",r);) - SetSSLNegotiate(false); - SetCloseAndDelete(true); - OnSSLConnectFailed(); - } - } - } - else // server - { - int r = SSL_accept(m_ssl); - if (r > 0) - { - SetSSLNegotiate(false); - /// \todo: resurrect certificate check... server -// CheckCertificateChain( "");//ClientHOST); - SetNonblocking(false); - // - { - SetConnected(); - if (GetOutputLength()) - { - OnWrite(); - } - } - OnAccept(); - Handler().LogError(this, "SSLNegotiate/SSL_accept", 0, "Connection established", LOG_LEVEL_INFO); - return true; - } - else - if (!r) - { - Handler().LogError(this, "SSLNegotiate/SSL_accept", 0, "Connection failed", LOG_LEVEL_INFO); - SetSSLNegotiate(false); - SetCloseAndDelete(); - OnSSLAcceptFailed(); - } - else - { - r = SSL_get_error(m_ssl, r); - if (r != SSL_ERROR_WANT_READ && r != SSL_ERROR_WANT_WRITE) - { - Handler().LogError(this, "SSLNegotiate/SSL_accept", -1, "Connection failed", LOG_LEVEL_INFO); -DEB( fprintf(stderr, "SSL_accept() failed - closing socket, return code: %d\n",r);) - SetSSLNegotiate(false); - SetCloseAndDelete(true); - OnSSLAcceptFailed(); - } - } - } - return false; -} - - -void TcpSocket::InitSSLClient() -{ - InitializeContext("", SSLv23_method()); -} - - -void TcpSocket::InitSSLServer() -{ - Handler().LogError(this, "InitSSLServer", 0, "You MUST implement your own InitSSLServer method", LOG_LEVEL_FATAL); - SetCloseAndDelete(); -} - - -void TcpSocket::InitializeContext(const std::string& context, SSL_METHOD *meth_in) -{ - /* Create our context*/ - static std::map client_contexts; - if (client_contexts.find(context) == client_contexts.end()) - { - SSL_METHOD *meth = meth_in ? meth_in : SSLv3_method(); - m_ssl_ctx = client_contexts[context] = SSL_CTX_new(meth); - SSL_CTX_set_mode(m_ssl_ctx, SSL_MODE_AUTO_RETRY); - } - else - { - m_ssl_ctx = client_contexts[context]; - } -} - - -void TcpSocket::InitializeContext(const std::string& context,const std::string& keyfile,const std::string& password,SSL_METHOD *meth_in) -{ - /* Create our context*/ - static std::map server_contexts; - if (server_contexts.find(context) == server_contexts.end()) - { - SSL_METHOD *meth = meth_in ? meth_in : SSLv3_method(); - m_ssl_ctx = server_contexts[context] = SSL_CTX_new(meth); - SSL_CTX_set_mode(m_ssl_ctx, SSL_MODE_AUTO_RETRY); - // session id - if (context.size()) - SSL_CTX_set_session_id_context(m_ssl_ctx, (const unsigned char *)context.c_str(), (unsigned int)context.size()); - else - SSL_CTX_set_session_id_context(m_ssl_ctx, (const unsigned char *)"--empty--", 9); - } - else - { - m_ssl_ctx = server_contexts[context]; - } - - /* Load our keys and certificates*/ - if (!(SSL_CTX_use_certificate_file(m_ssl_ctx, keyfile.c_str(), SSL_FILETYPE_PEM))) - { - Handler().LogError(this, "TcpSocket InitializeContext", 0, "Couldn't read certificate file " + keyfile, LOG_LEVEL_FATAL); - } - - m_password = password; - SSL_CTX_set_default_passwd_cb(m_ssl_ctx, SSL_password_cb); - SSL_CTX_set_default_passwd_cb_userdata(m_ssl_ctx, this); - if (!(SSL_CTX_use_PrivateKey_file(m_ssl_ctx, keyfile.c_str(), SSL_FILETYPE_PEM))) - { - Handler().LogError(this, "TcpSocket InitializeContext", 0, "Couldn't read private key file " + keyfile, LOG_LEVEL_FATAL); - } -} - - -void TcpSocket::InitializeContext(const std::string& context,const std::string& certfile,const std::string& keyfile,const std::string& password,SSL_METHOD *meth_in) -{ - /* Create our context*/ - static std::map server_contexts; - if (server_contexts.find(context) == server_contexts.end()) - { - SSL_METHOD *meth = meth_in ? meth_in : SSLv3_method(); - m_ssl_ctx = server_contexts[context] = SSL_CTX_new(meth); - SSL_CTX_set_mode(m_ssl_ctx, SSL_MODE_AUTO_RETRY); - // session id - if (context.size()) - SSL_CTX_set_session_id_context(m_ssl_ctx, (const unsigned char *)context.c_str(), (unsigned int)context.size()); - else - SSL_CTX_set_session_id_context(m_ssl_ctx, (const unsigned char *)"--empty--", 9); - } - else - { - m_ssl_ctx = server_contexts[context]; - } - - /* Load our keys and certificates*/ - if (!(SSL_CTX_use_certificate_file(m_ssl_ctx, certfile.c_str(), SSL_FILETYPE_PEM))) - { - Handler().LogError(this, "TcpSocket InitializeContext", 0, "Couldn't read certificate file " + keyfile, LOG_LEVEL_FATAL); - } - - m_password = password; - SSL_CTX_set_default_passwd_cb(m_ssl_ctx, SSL_password_cb); - SSL_CTX_set_default_passwd_cb_userdata(m_ssl_ctx, this); - if (!(SSL_CTX_use_PrivateKey_file(m_ssl_ctx, keyfile.c_str(), SSL_FILETYPE_PEM))) - { - Handler().LogError(this, "TcpSocket InitializeContext", 0, "Couldn't read private key file " + keyfile, LOG_LEVEL_FATAL); - } -} - - -int TcpSocket::SSL_password_cb(char *buf,int num,int rwflag,void *userdata) -{ - Socket *p0 = static_cast(userdata); - TcpSocket *p = dynamic_cast(p0); - std::string pw = p ? p -> GetPassword() : ""; - if ( (size_t)num < pw.size() + 1) - { - return 0; - } - strcpy(buf,pw.c_str()); - return (int)pw.size(); -} -#endif // HAVE_OPENSSL - - -int TcpSocket::Close() -{ - if (GetSocket() == INVALID_SOCKET) // this could happen - { - Handler().LogError(this, "Socket::Close", 0, "file descriptor invalid", LOG_LEVEL_WARNING); - return 0; - } - int n; - SetNonblocking(true); - if (IsConnected() && !(GetShutdown() & SHUT_WR)) - { - if (shutdown(GetSocket(), SHUT_WR) == -1) - { - // failed... - Handler().LogError(this, "shutdown", Errno, StrError(Errno), LOG_LEVEL_ERROR); - } - } - // - char tmp[1000]; - if ((n = recv(GetSocket(),tmp,1000,0)) >= 0) - { - if (n) - { - Handler().LogError(this, "read() after shutdown", n, "bytes read", LOG_LEVEL_WARNING); - } - } -#ifdef HAVE_OPENSSL - if (IsSSL() && m_ssl) - SSL_shutdown(m_ssl); - if (m_ssl) - { - SSL_free(m_ssl); - m_ssl = NULL; - } -#endif - return Socket::Close(); -} - - -#ifdef HAVE_OPENSSL -SSL_CTX *TcpSocket::GetSslContext() -{ - if (!m_ssl_ctx) - Handler().LogError(this, "GetSslContext", 0, "SSL Context is NULL; check InitSSLServer/InitSSLClient", LOG_LEVEL_WARNING); - return m_ssl_ctx; -} - -SSL *TcpSocket::GetSsl() -{ - if (!m_ssl) - Handler().LogError(this, "GetSsl", 0, "SSL is NULL; check InitSSLServer/InitSSLClient", LOG_LEVEL_WARNING); - return m_ssl; -} -#endif - - -#ifdef ENABLE_RECONNECT -void TcpSocket::SetReconnect(bool x) -{ - m_b_reconnect = x; -} -#endif - - -void TcpSocket::OnRawData(const char *buf_in,size_t len) -{ -} - - -size_t TcpSocket::GetInputLength() -{ - return ibuf.GetLength(); -} - - -size_t TcpSocket::GetOutputLength() -{ - return m_output_length; -} - - -uint64_t TcpSocket::GetBytesReceived(bool clear) -{ - uint64_t z = m_bytes_received; - if (clear) - m_bytes_received = 0; - return z; -} - - -uint64_t TcpSocket::GetBytesSent(bool clear) -{ - uint64_t z = m_bytes_sent; - if (clear) - m_bytes_sent = 0; - return z; -} - - -#ifdef ENABLE_RECONNECT -bool TcpSocket::Reconnect() -{ - return m_b_reconnect; -} - - -void TcpSocket::SetIsReconnect(bool x) -{ - m_b_is_reconnect = x; -} - - -bool TcpSocket::IsReconnect() -{ - return m_b_is_reconnect; -} -#endif - - -#ifdef HAVE_OPENSSL -const std::string& TcpSocket::GetPassword() -{ - return m_password; -} -#endif - - -void TcpSocket::DisableInputBuffer(bool x) -{ - m_b_input_buffer_disabled = x; -} - - -void TcpSocket::OnOptions(int family,int type,int protocol,SOCKET s) -{ -DEB( fprintf(stderr, "Socket::OnOptions()\n");) -#ifdef SO_NOSIGPIPE - SetSoNosigpipe(true); -#endif - SetSoReuseaddr(true); - SetSoKeepalive(true); -} - - -void TcpSocket::SetLineProtocol(bool x) -{ - StreamSocket::SetLineProtocol(x); - DisableInputBuffer(x); -} - - -bool TcpSocket::SetTcpNodelay(bool x) -{ -#ifdef TCP_NODELAY - int optval = x ? 1 : 0; - if (setsockopt(GetSocket(), IPPROTO_TCP, TCP_NODELAY, (char *)&optval, sizeof(optval)) == -1) - { - Handler().LogError(this, "setsockopt(IPPROTO_TCP, TCP_NODELAY)", Errno, StrError(Errno), LOG_LEVEL_FATAL); - return false; - } - return true; -#else - Handler().LogError(this, "socket option not available", 0, "TCP_NODELAY", LOG_LEVEL_INFO); - return false; -#endif -} - - -TcpSocket::CircularBuffer::CircularBuffer(size_t size) -:buf(new char[2 * size]) -,m_max(size) -,m_q(0) -,m_b(0) -,m_t(0) -,m_count(0) -{ -} - - -TcpSocket::CircularBuffer::~CircularBuffer() -{ - delete[] buf; -} - - -bool TcpSocket::CircularBuffer::Write(const char *s,size_t l) -{ - if (m_q + l > m_max) - { - return false; // overflow - } - m_count += (unsigned long)l; - if (m_t + l > m_max) // block crosses circular border - { - size_t l1 = m_max - m_t; // size left until circular border crossing - // always copy full block to buffer(buf) + top pointer(m_t) - // because we have doubled the buffer size for performance reasons - memcpy(buf + m_t, s, l); - memcpy(buf, s + l1, l - l1); - m_t = l - l1; - m_q += l; - } - else - { - memcpy(buf + m_t, s, l); - memcpy(buf + m_max + m_t, s, l); - m_t += l; - if (m_t >= m_max) - m_t -= m_max; - m_q += l; - } - return true; -} - - -bool TcpSocket::CircularBuffer::Read(char *s,size_t l) -{ - if (l > m_q) - { - return false; // not enough chars - } - if (m_b + l > m_max) // block crosses circular border - { - size_t l1 = m_max - m_b; - if (s) - { - memcpy(s, buf + m_b, l1); - memcpy(s + l1, buf, l - l1); - } - m_b = l - l1; - m_q -= l; - } - else - { - if (s) - { - memcpy(s, buf + m_b, l); - } - m_b += l; - if (m_b >= m_max) - m_b -= m_max; - m_q -= l; - } - if (!m_q) - { - m_b = m_t = 0; - } - return true; -} - - -bool TcpSocket::CircularBuffer::Remove(size_t l) -{ - return Read(NULL, l); -} - - -size_t TcpSocket::CircularBuffer::GetLength() -{ - return m_q; -} - - -const char *TcpSocket::CircularBuffer::GetStart() -{ - return buf + m_b; -} - - -size_t TcpSocket::CircularBuffer::GetL() -{ - return (m_b + m_q > m_max) ? m_max - m_b : m_q; -} - - -size_t TcpSocket::CircularBuffer::Space() -{ - return m_max - m_q; -} - - -unsigned long TcpSocket::CircularBuffer::ByteCounter(bool clear) -{ - if (clear) - { - unsigned long x = m_count; - m_count = 0; - return x; - } - return m_count; -} - - -std::string TcpSocket::CircularBuffer::ReadString(size_t l) -{ - char *sz = new char[l + 1]; - if (!Read(sz, l)) // failed, debug printout in Read() method - { - delete[] sz; - return ""; - } - sz[l] = 0; - std::string tmp = sz; - delete[] sz; - return tmp; -} - - -void TcpSocket::OnConnectTimeout() -{ - Handler().LogError(this, "connect", -1, "connect timeout", LOG_LEVEL_FATAL); -#ifdef ENABLE_SOCKS4 - if (Socks4()) - { - OnSocks4ConnectFailed(); - // retry direct connection - } - else -#endif - if (GetConnectionRetry() == -1 || - (GetConnectionRetry() && GetConnectionRetries() < GetConnectionRetry()) ) - { - IncreaseConnectionRetries(); - // ask socket via OnConnectRetry callback if we should continue trying - if (OnConnectRetry()) - { - SetRetryClientConnect(); - } - else - { - SetCloseAndDelete( true ); - /// \todo state reason why connect failed - OnConnectFailed(); - } - } - else - { - SetCloseAndDelete(true); - /// \todo state reason why connect failed - OnConnectFailed(); - } - // - SetConnecting(false); -} - - -#ifdef _WIN32 -void TcpSocket::OnException() -{ - if (Connecting()) - { -#ifdef ENABLE_SOCKS4 - if (Socks4()) - OnSocks4ConnectFailed(); - else -#endif - if (GetConnectionRetry() == -1 || - (GetConnectionRetry() && - GetConnectionRetries() < GetConnectionRetry() )) - { - // even though the connection failed at once, only retry after - // the connection timeout - // should we even try to connect again, when CheckConnect returns - // false it's because of a connection error - not a timeout... - } - else - { - SetConnecting(false); // tnx snibbe - SetCloseAndDelete(); - OnConnectFailed(); - } - return; - } - // %! exception doesn't always mean something bad happened, this code should be reworked - // errno valid here? - int err = SoError(); - Handler().LogError(this, "exception on select", err, StrError(err), LOG_LEVEL_FATAL); - SetCloseAndDelete(); -} -#endif // _WIN32 - - -int TcpSocket::Protocol() -{ - return IPPROTO_TCP; -} - - -void TcpSocket::SetTransferLimit(size_t sz) -{ - m_transfer_limit = sz; -} - - -void TcpSocket::OnTransferLimit() -{ -} - - -#ifdef SOCKETS_NAMESPACE -} -#endif - diff --git a/Sockets/TcpSocket.h b/Sockets/TcpSocket.h deleted file mode 100644 index 47f7d15..0000000 --- a/Sockets/TcpSocket.h +++ /dev/null @@ -1,355 +0,0 @@ -/** \file TcpSocket.h - ** \date 2004-02-13 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_TcpSocket_H -#define _SOCKETS_TcpSocket_H -#include "sockets-config.h" -#include "StreamSocket.h" -#ifdef HAVE_OPENSSL -#include -#include "SSLInitializer.h" -#endif - - -#define TCP_BUFSIZE_READ 16400 -#define TCP_OUTPUT_CAPACITY 1024000 - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -class SocketAddress; - - -/** Socket implementation for TCP. - \ingroup basic */ -class TcpSocket : public StreamSocket -{ - /** \defgroup internal Internal utility */ -protected: - /** Buffer class containing one read/write circular buffer. - \ingroup internal */ - class CircularBuffer - { - public: - CircularBuffer(size_t size); - ~CircularBuffer(); - - /** append l bytes from p to buffer */ - bool Write(const char *p,size_t l); - /** copy l bytes from buffer to dest */ - bool Read(char *dest,size_t l); - /** skip l bytes from buffer */ - bool Remove(size_t l); - /** read l bytes from buffer, returns as string. */ - std::string ReadString(size_t l); - - /** total buffer length */ - size_t GetLength(); - /** pointer to circular buffer beginning */ - const char *GetStart(); - /** return number of bytes from circular buffer beginning to buffer physical end */ - size_t GetL(); - /** return free space in buffer, number of bytes until buffer overrun */ - size_t Space(); - - /** return total number of bytes written to this buffer, ever */ - unsigned long ByteCounter(bool clear = false); - - private: - CircularBuffer(const CircularBuffer& s) {} - CircularBuffer& operator=(const CircularBuffer& ) { return *this; } - char *buf; - size_t m_max; - size_t m_q; - size_t m_b; - size_t m_t; - unsigned long m_count; - }; - /** Output buffer struct. - \ingroup internal */ - struct OUTPUT { - OUTPUT() : _b(0), _t(0), _q(0) {} - OUTPUT(const char *buf, size_t len) : _b(0), _t(len), _q(len) { - memcpy(_buf, buf, len); - } - size_t Space() { - return TCP_OUTPUT_CAPACITY - _t; - } - void Add(const char *buf, size_t len) { - memcpy(_buf + _t, buf, len); - _t += len; - _q += len; - } - size_t Remove(size_t len) { - _b += len; - _q -= len; - return _q; - } - const char *Buf() { - return _buf + _b; - } - size_t Len() { - return _q; - } - size_t _b; - size_t _t; - size_t _q; - char _buf[TCP_OUTPUT_CAPACITY]; - }; - typedef std::list output_l; - -public: - /** Constructor with standard values on input/output buffers. */ - TcpSocket(ISocketHandler& ); - /** Constructor with custom values for i/o buffer. - \param h ISocketHandler reference - \param isize Input buffer size - \param osize Output buffer size */ - TcpSocket(ISocketHandler& h,size_t isize,size_t osize); - ~TcpSocket(); - - /** Open a connection to a remote server. - If you want your socket to connect to a server, - always call Open before Add'ing a socket to the sockethandler. - If not, the connection attempt will not be monitored by the - socket handler... - \param ip IP address - \param port Port number - \param skip_socks Do not use socks4 even if configured */ - bool Open(ipaddr_t ip,port_t port,bool skip_socks = false); -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - /** Open connection. - \param ip Ipv6 address - \param port Port number - \param skip_socks Do not use socks4 even if configured */ - bool Open(in6_addr ip,port_t port,bool skip_socks = false); -#endif -#endif - bool Open(SocketAddress&,bool skip_socks = false); - bool Open(SocketAddress&,SocketAddress& bind_address,bool skip_socks = false); - /** Open connection. - \param host Hostname - \param port Port number */ - bool Open(const std::string &host,port_t port); - - /** Connect timeout callback. */ - void OnConnectTimeout(); -#ifdef _WIN32 - /** Connection failed reported as exception on win32 */ - void OnException(); -#endif - - /** Close file descriptor - internal use only. - \sa SetCloseAndDelete */ - int Close(); - - /** Send a string. - \param s String to send - \param f Dummy flags -- not used */ - void Send(const std::string &s,int f = 0); - /** Send string using printf formatting. */ - void Sendf(const char *format, ...); - /** Send buffer of bytes. - \param buf Buffer pointer - \param len Length of data - \param f Dummy flags -- not used */ - void SendBuf(const char *buf,size_t len,int f = 0); - /** This callback is executed after a successful read from the socket. - \param buf Pointer to the data - \param len Length of the data */ - virtual void OnRawData(const char *buf,size_t len); - - /** Called when output buffer has been sent. - Note: Will only be called IF the output buffer has been used. - Send's that was successful without needing the output buffer - will not generate a call to this method. */ - virtual void OnWriteComplete(); - /** Number of bytes in input buffer. */ - size_t GetInputLength(); - /** Number of bytes in output buffer. */ - size_t GetOutputLength(); - - /** Callback fires when a socket in line protocol has read one full line. - \param line Line read */ - void OnLine(const std::string& line); - /** Get counter of number of bytes received. */ - uint64_t GetBytesReceived(bool clear = false); - /** Get counter of number of bytes sent. */ - uint64_t GetBytesSent(bool clear = false); - - /** Socks4 specific callback. */ - void OnSocks4Connect(); - /** Socks4 specific callback. */ - void OnSocks4ConnectFailed(); - /** Socks4 specific callback. - \return 'need_more' */ - bool OnSocks4Read(); - -#ifdef ENABLE_RESOLVER - /** Callback executed when resolver thread has finished a resolve request. */ - void OnResolved(int id,ipaddr_t a,port_t port); -#ifdef ENABLE_IPV6 - void OnResolved(int id,in6_addr& a,port_t port); -#endif -#endif -#ifdef HAVE_OPENSSL - /** Callback for 'New' ssl support - replaces SSLSocket. Internal use. */ - void OnSSLConnect(); - /** Callback for 'New' ssl support - replaces SSLSocket. Internal use. */ - void OnSSLAccept(); - /** This method must be implemented to initialize - the ssl context for an outgoing connection. */ - virtual void InitSSLClient(); - /** This method must be implemented to initialize - the ssl context for an incoming connection. */ - virtual void InitSSLServer(); -#endif - -#ifdef ENABLE_RECONNECT - /** Flag that says a broken connection will try to reconnect. */ - void SetReconnect(bool = true); - /** Check reconnect on lost connection flag status. */ - bool Reconnect(); - /** Flag to determine if a reconnect is in progress. */ - void SetIsReconnect(bool x = true); - /** Socket is reconnecting. */ - bool IsReconnect(); -#endif - - void DisableInputBuffer(bool = true); - - void OnOptions(int,int,int,SOCKET); - - void SetLineProtocol(bool = true); - - // TCP options - bool SetTcpNodelay(bool = true); - - virtual int Protocol(); - - /** Trigger limit for callback OnTransferLimit. */ - void SetTransferLimit(size_t sz); - /** This callback fires when the output buffer drops below the value - set by SetTransferLimit. Default: 0 (disabled). */ - virtual void OnTransferLimit(); - -protected: - TcpSocket(const TcpSocket& ); - void OnRead(); - void OnRead( char *buf, size_t n ); - void OnWrite(); -#ifdef HAVE_OPENSSL - /** SSL; Initialize ssl context for a client socket. - \param meth_in SSL method */ - void InitializeContext(const std::string& context, SSL_METHOD *meth_in = NULL); - /** SSL; Initialize ssl context for a server socket. - \param keyfile Combined private key/certificate file - \param password Password for private key - \param meth_in SSL method */ - void InitializeContext(const std::string& context, const std::string& keyfile, const std::string& password, SSL_METHOD *meth_in = NULL); - /** SSL; Initialize ssl context for a server socket. - \param certfile Separate certificate file - \param keyfile Combined private key/certificate file - \param password Password for private key - \param meth_in SSL method */ - void InitializeContext(const std::string& context, const std::string& certfile, const std::string& keyfile, const std::string& password, SSL_METHOD *meth_in = NULL); - /** SSL; Password callback method. */ -static int SSL_password_cb(char *buf,int num,int rwflag,void *userdata); - /** SSL; Get pointer to ssl context structure. */ - virtual SSL_CTX *GetSslContext(); - /** SSL; Get pointer to ssl structure. */ - virtual SSL *GetSsl(); - /** ssl; still negotiating connection. */ - bool SSLNegotiate(); - /** SSL; Get ssl password. */ - const std::string& GetPassword(); -#endif - - CircularBuffer ibuf; ///< Circular input buffer - -private: - TcpSocket& operator=(const TcpSocket& ) { return *this; } - - /** the actual send() */ - int TryWrite(const char *buf, size_t len); - /** add data to output buffer top */ - void Buffer(const char *buf, size_t len); - - // - bool m_b_input_buffer_disabled; - uint64_t m_bytes_sent; - uint64_t m_bytes_received; - bool m_skip_c; ///< Skip second char of CRLF or LFCR sequence in OnRead - char m_c; ///< First char in CRLF or LFCR sequence - std::string m_line; ///< Current line in line protocol mode -#ifdef SOCKETS_DYNAMIC_TEMP - char *m_buf; ///< temporary read buffer -#endif - output_l m_obuf; ///< output buffer - OUTPUT *m_obuf_top; ///< output buffer on top - size_t m_transfer_limit; - size_t m_output_length; - -#ifdef HAVE_OPENSSL -static SSLInitializer m_ssl_init; - SSL_CTX *m_ssl_ctx; ///< ssl context - SSL *m_ssl; ///< ssl 'socket' - BIO *m_sbio; ///< ssl bio - std::string m_password; ///< ssl password -#endif - -#ifdef ENABLE_SOCKS4 - int m_socks4_state; ///< socks4 support - char m_socks4_vn; ///< socks4 support, temporary variable - char m_socks4_cd; ///< socks4 support, temporary variable - unsigned short m_socks4_dstport; ///< socks4 support - unsigned long m_socks4_dstip; ///< socks4 support -#endif - -#ifdef ENABLE_RESOLVER - int m_resolver_id; ///< Resolver id (if any) for current Open call -#endif - -#ifdef ENABLE_RECONNECT - bool m_b_reconnect; ///< Reconnect on lost connection flag - bool m_b_is_reconnect; ///< Trying to reconnect -#endif - -}; - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_TcpSocket_H - diff --git a/Sockets/Thread.cpp b/Sockets/Thread.cpp deleted file mode 100644 index 2717e32..0000000 --- a/Sockets/Thread.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/** \file Thread.cpp - ** \date 2004-10-30 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#include -#ifdef _WIN32 -#include -#include "socket_include.h" -#else -#include -#endif - -#include "Thread.h" - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -Thread::Thread(bool release) -:m_thread(0) -,m_running(true) -,m_release(false) -,m_b_delete_on_exit(false) -,m_b_destructor(false) -{ -#ifdef _WIN32 -// m_thread = ::CreateThread(NULL, 0, StartThread, this, 0, &m_dwThreadId); - m_thread = (HANDLE)_beginthreadex(NULL, 0, &StartThread, this, 0, &m_dwThreadId); -#else - pthread_attr_t attr; - - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED); - if (pthread_create(&m_thread,&attr, StartThread,this) == -1) - { - perror("Thread: create failed"); - SetRunning(false); - } -// pthread_attr_destroy(&attr); -#endif - m_release = release; -} - - -Thread::~Thread() -{ - m_b_destructor = true; - if (m_running) - { - SetRelease(true); - SetRunning(false); -#ifdef _WIN32 - Sleep(1000); -#else - sleep(1); -#endif - } -#ifdef _WIN32 - if (m_thread) - ::CloseHandle(m_thread); -#endif -} - - -threadfunc_t STDPREFIX Thread::StartThread(threadparam_t zz) -{ - Thread *p = (Thread *)zz; - - while (p -> m_running && !p -> m_release) - { -#ifdef _WIN32 - Sleep(1000); -#else - sleep(1); -#endif - } - if (p -> m_running) - { - p -> Run(); - } - p -> SetRunning(false); // if return - if (p -> DeleteOnExit() && !p -> IsDestructor()) - { - delete p; - } -#ifdef _WIN32 - _endthreadex(0); -#endif - return (threadfunc_t)NULL; -} - - -bool Thread::IsRunning() -{ - return m_running; -} - - -void Thread::SetRunning(bool x) -{ - m_running = x; -} - - -bool Thread::IsReleased() -{ - return m_release; -} - - -void Thread::SetRelease(bool x) -{ - m_release = x; -} - - -bool Thread::DeleteOnExit() -{ - return m_b_delete_on_exit; -} - - -void Thread::SetDeleteOnExit(bool x) -{ - m_b_delete_on_exit = x; -} - - -bool Thread::IsDestructor() -{ - return m_b_destructor; -} - - -#ifdef SOCKETS_NAMESPACE -} -#endif - - diff --git a/Sockets/Thread.h b/Sockets/Thread.h deleted file mode 100644 index d784a15..0000000 --- a/Sockets/Thread.h +++ /dev/null @@ -1,100 +0,0 @@ -/** \file Thread.h - ** \date 2004-10-30 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_Thread_H -#define _SOCKETS_Thread_H - -#include "sockets-config.h" -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -#ifdef _WIN32 -// to be -//typedef DWORD threadfunc_t; -//typedef LPVOID threadparam_t; -//#define STDPREFIX WINAPI -typedef unsigned threadfunc_t; -typedef void * threadparam_t; -#define STDPREFIX __stdcall -#else -#include - -typedef void * threadfunc_t; -typedef void * threadparam_t; -#define STDPREFIX -#endif - -/** \defgroup threading Threading */ -/** Thread base class. -The Thread class is used by the resolver (ResolvServer) and running a detached socket (SocketThread). -When you know some processing will take a long time and will freeze up a socket, there is always the -possibility to call Detach() on that socket before starting the processing. -When the OnDetached() callback is later called the processing can continue, now in its own thread. - \ingroup threading */ -class Thread -{ -public: - Thread(bool release = true); - virtual ~Thread(); - - static threadfunc_t STDPREFIX StartThread(threadparam_t); - - virtual void Run() = 0; - - bool IsRunning(); - void SetRunning(bool x); - bool IsReleased(); - void SetRelease(bool x); - bool DeleteOnExit(); - void SetDeleteOnExit(bool x = true); - bool IsDestructor(); - -private: - Thread(const Thread& ) {} - Thread& operator=(const Thread& ) { return *this; } -#ifdef _WIN32 - HANDLE m_thread; - unsigned m_dwThreadId; -#else - pthread_t m_thread; -#endif - bool m_running; - bool m_release; - bool m_b_delete_on_exit; - bool m_b_destructor; -}; - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_Thread_H - diff --git a/Sockets/UdpSocket.cpp b/Sockets/UdpSocket.cpp deleted file mode 100644 index 75bebf2..0000000 --- a/Sockets/UdpSocket.cpp +++ /dev/null @@ -1,843 +0,0 @@ -/** \file UdpSocket.cpp - ** \date 2004-02-13 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _WIN32 -#ifdef _MSC_VER -#pragma warning(disable:4786) -#endif -#include -#else -#include -#endif - -#include "ISocketHandler.h" -#include "UdpSocket.h" -#include "Utility.h" -#include "Ipv4Address.h" -#include "Ipv6Address.h" -#ifdef ENABLE_EXCEPTIONS -#include "Exception.h" -#endif -// include this to see strange sights -//#include - - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -UdpSocket::UdpSocket(ISocketHandler& h, int ibufsz, bool ipv6, int retries) : Socket(h) -, m_ibuf(new char[ibufsz]) -, m_ibufsz(ibufsz) -, m_bind_ok(false) -, m_port(0) -, m_last_size_written(-1) -, m_retries(retries) -, m_b_read_ts(false) -{ -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - SetIpv6(ipv6); -#endif -#endif -} - - -UdpSocket::~UdpSocket() -{ - Close(); - delete[] m_ibuf; -} - - -int UdpSocket::Bind(port_t &port, int range) -{ -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (IsIpv6()) - { - Ipv6Address ad(port); - return Bind(ad, range); - } -#endif -#endif - Ipv4Address ad(port); - return Bind(ad, range); -} - - -int UdpSocket::Bind(const std::string& intf, port_t &port, int range) -{ -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (IsIpv6()) - { - Ipv6Address ad(intf, port); - if (ad.IsValid()) - { - return Bind(ad, range); - } - SetCloseAndDelete(); - return -1; - } -#endif -#endif - Ipv4Address ad(intf, port); - if (ad.IsValid()) - { - return Bind(ad, range); - } - SetCloseAndDelete(); - return -1; -} - - -int UdpSocket::Bind(ipaddr_t a, port_t &port, int range) -{ - Ipv4Address ad(a, port); - return Bind(ad, range); -} - - -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 -int UdpSocket::Bind(in6_addr a, port_t &port, int range) -{ - Ipv6Address ad(a, port); - return Bind(ad, range); -} -#endif -#endif - - -int UdpSocket::Bind(SocketAddress& ad, int range) -{ - if (GetSocket() == INVALID_SOCKET) - { - Attach(CreateSocket(ad.GetFamily(), SOCK_DGRAM, "udp")); - } - if (GetSocket() != INVALID_SOCKET) - { - SetNonblocking(true); - int n = bind(GetSocket(), ad, ad); - int tries = range; - while (n == -1 && tries--) - { - ad.SetPort(ad.GetPort() + 1); - n = bind(GetSocket(), ad, ad); - } - if (n == -1) - { - Handler().LogError(this, "bind", Errno, StrError(Errno), LOG_LEVEL_FATAL); - SetCloseAndDelete(); -#ifdef ENABLE_EXCEPTIONS - throw Exception("bind() failed for UdpSocket, port:range: " + Utility::l2string(ad.GetPort()) + ":" + Utility::l2string(range)); -#endif - return -1; - } - m_bind_ok = true; - m_port = ad.GetPort(); - return 0; - } - return -1; -} - - -/** if you wish to use Send, first Open a connection */ -bool UdpSocket::Open(ipaddr_t l, port_t port) -{ - Ipv4Address ad(l, port); - return Open(ad); -} - - -bool UdpSocket::Open(const std::string& host, port_t port) -{ -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (IsIpv6()) - { - Ipv6Address ad(host, port); - if (ad.IsValid()) - { - return Open(ad); - } - return false; - } -#endif -#endif - Ipv4Address ad(host, port); - if (ad.IsValid()) - { - return Open(ad); - } - return false; -} - - -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 -bool UdpSocket::Open(struct in6_addr& a, port_t port) -{ - Ipv6Address ad(a, port); - return Open(ad); -} -#endif -#endif - - -bool UdpSocket::Open(SocketAddress& ad) -{ - if (GetSocket() == INVALID_SOCKET) - { - Attach(CreateSocket(ad.GetFamily(), SOCK_DGRAM, "udp")); - } - if (GetSocket() != INVALID_SOCKET) - { - SetNonblocking(true); - if (connect(GetSocket(), ad, ad) == -1) - { - Handler().LogError(this, "connect", Errno, StrError(Errno), LOG_LEVEL_FATAL); - SetCloseAndDelete(); - return false; - } - SetConnected(); - return true; - } - return false; -} - - -void UdpSocket::CreateConnection() -{ -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (IsIpv6()) - { - if (GetSocket() == INVALID_SOCKET) - { - SOCKET s = CreateSocket(AF_INET6, SOCK_DGRAM, "udp"); - if (s == INVALID_SOCKET) - { - return; - } - SetNonblocking(true, s); - Attach(s); - } - return; - } -#endif -#endif - if (GetSocket() == INVALID_SOCKET) - { - SOCKET s = CreateSocket(AF_INET, SOCK_DGRAM, "udp"); - if (s == INVALID_SOCKET) - { - return; - } - SetNonblocking(true, s); - Attach(s); - } -} - - -/** send to specified address */ -void UdpSocket::SendToBuf(const std::string& h, port_t p, const char *data, int len, int flags) -{ -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (IsIpv6()) - { - Ipv6Address ad(h, p); - if (ad.IsValid()) - { - SendToBuf(ad, data, len, flags); - } - return; - } -#endif -#endif - Ipv4Address ad(h, p); - if (ad.IsValid()) - { - SendToBuf(ad, data, len, flags); - } -} - - -/** send to specified address */ -void UdpSocket::SendToBuf(ipaddr_t a, port_t p, const char *data, int len, int flags) -{ - Ipv4Address ad(a, p); - SendToBuf(ad, data, len, flags); -} - - -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 -void UdpSocket::SendToBuf(in6_addr a, port_t p, const char *data, int len, int flags) -{ - Ipv6Address ad(a, p); - SendToBuf(ad, data, len, flags); -} -#endif -#endif - - -void UdpSocket::SendToBuf(SocketAddress& ad, const char *data, int len, int flags) -{ - if (GetSocket() == INVALID_SOCKET) - { - Attach(CreateSocket(ad.GetFamily(), SOCK_DGRAM, "udp")); - } - if (GetSocket() != INVALID_SOCKET) - { - SetNonblocking(true); - if ((m_last_size_written = sendto(GetSocket(), data, len, flags, ad, ad)) == -1) - { - Handler().LogError(this, "sendto", Errno, StrError(Errno), LOG_LEVEL_ERROR); - } - } -} - - -void UdpSocket::SendTo(const std::string& a, port_t p, const std::string& str, int flags) -{ - SendToBuf(a, p, str.c_str(), (int)str.size(), flags); -} - - -void UdpSocket::SendTo(ipaddr_t a, port_t p, const std::string& str, int flags) -{ - SendToBuf(a, p, str.c_str(), (int)str.size(), flags); -} - - -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 -void UdpSocket::SendTo(in6_addr a, port_t p, const std::string& str, int flags) -{ - SendToBuf(a, p, str.c_str(), (int)str.size(), flags); -} -#endif -#endif - - -void UdpSocket::SendTo(SocketAddress& ad, const std::string& str, int flags) -{ - SendToBuf(ad, str.c_str(), (int)str.size(), flags); -} - - -/** send to connected address */ -void UdpSocket::SendBuf(const char *data, size_t len, int flags) -{ - if (!IsConnected()) - { - Handler().LogError(this, "SendBuf", 0, "not connected", LOG_LEVEL_ERROR); - return; - } - if ((m_last_size_written = send(GetSocket(), data, (int)len, flags)) == -1) - { - Handler().LogError(this, "send", Errno, StrError(Errno), LOG_LEVEL_ERROR); - } -} - - -void UdpSocket::Send(const std::string& str, int flags) -{ - SendBuf(str.c_str(), (int)str.size(), flags); -} - - -#ifndef _WIN32 -int UdpSocket::ReadTS(char *ioBuf, int inBufSize, struct sockaddr *from, socklen_t fromlen, struct timeval *ts) -{ - struct msghdr msg; - struct iovec vec[1]; - union { - struct cmsghdr cm; - char data[CMSG_SPACE(sizeof(struct timeval))]; - } cmsg_un; - struct cmsghdr *cmsg; - struct timeval *tv; - - vec[0].iov_base = ioBuf; - vec[0].iov_len = inBufSize; - - memset(&msg, 0, sizeof(msg)); - memset(from, 0, fromlen); - memset(ioBuf, 0, inBufSize); - memset(&cmsg_un, 0, sizeof(cmsg_un)); - - msg.msg_name = (caddr_t)from; - msg.msg_namelen = fromlen; - msg.msg_iov = vec; - msg.msg_iovlen = 1; - msg.msg_control = cmsg_un.data; - msg.msg_controllen = sizeof(cmsg_un.data); - msg.msg_flags = 0; - - // Original version - for reference only - //int n = recvfrom(GetSocket(), m_ibuf, m_ibufsz, 0, (struct sockaddr *)&sa, &sa_len); - - int n = recvmsg(GetSocket(), &msg, MSG_DONTWAIT); - - // now ioBuf will contain the data, as if we used recvfrom - - // Now get the time - if(n != -1 && msg.msg_controllen >= sizeof(struct cmsghdr) && !(msg.msg_flags & MSG_CTRUNC)) - { - tv = 0; - for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) - { - if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_TIMESTAMP) - { - tv = (struct timeval *)CMSG_DATA(cmsg); - } - } - if (tv) - { - memcpy(ts, tv, sizeof(struct timeval)); - } - } - // The address is in network order, but that's OK right now - return n; -} -#endif - - -void UdpSocket::OnRead() -{ -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (IsIpv6()) - { - struct sockaddr_in6 sa; - socklen_t sa_len = sizeof(sa); - if (m_b_read_ts) - { - struct timeval ts; - Utility::GetTime(&ts); -#ifdef _WIN32 - int n = recvfrom(GetSocket(), m_ibuf, m_ibufsz, 0, (struct sockaddr *)&sa, &sa_len); -#else - int n = ReadTS(m_ibuf, m_ibufsz, (struct sockaddr *)&sa, sa_len, &ts); -#endif - if (n > 0) - { - this -> OnRawData(m_ibuf, n, (struct sockaddr *)&sa, sa_len, &ts); - } - else - if (n == -1) - { -#ifdef _WIN32 - if (Errno != WSAEWOULDBLOCK) -#else - if (Errno != EWOULDBLOCK) -#endif - Handler().LogError(this, "recvfrom", Errno, StrError(Errno), LOG_LEVEL_ERROR); - } - return; - } - int n = recvfrom(GetSocket(), m_ibuf, m_ibufsz, 0, (struct sockaddr *)&sa, &sa_len); - int q = m_retries; // receive max 10 at one cycle - while (n > 0) - { - if (sa_len != sizeof(sa)) - { - Handler().LogError(this, "recvfrom", 0, "unexpected address struct size", LOG_LEVEL_WARNING); - } - this -> OnRawData(m_ibuf, n, (struct sockaddr *)&sa, sa_len); - if (!q--) - break; - // - n = recvfrom(GetSocket(), m_ibuf, m_ibufsz, 0, (struct sockaddr *)&sa, &sa_len); - } - if (n == -1) - { -#ifdef _WIN32 - if (Errno != WSAEWOULDBLOCK) -#else - if (Errno != EWOULDBLOCK) -#endif - Handler().LogError(this, "recvfrom", Errno, StrError(Errno), LOG_LEVEL_ERROR); - } - return; - } -#endif -#endif - struct sockaddr_in sa; - socklen_t sa_len = sizeof(sa); - if (m_b_read_ts) - { - struct timeval ts; - Utility::GetTime(&ts); -#ifdef _WIN32 - int n = recvfrom(GetSocket(), m_ibuf, m_ibufsz, 0, (struct sockaddr *)&sa, &sa_len); -#else - int n = ReadTS(m_ibuf, m_ibufsz, (struct sockaddr *)&sa, sa_len, &ts); -#endif - if (n > 0) - { - this -> OnRawData(m_ibuf, n, (struct sockaddr *)&sa, sa_len, &ts); - } - else - if (n == -1) - { -#ifdef _WIN32 - if (Errno != WSAEWOULDBLOCK) -#else - if (Errno != EWOULDBLOCK) -#endif - Handler().LogError(this, "recvfrom", Errno, StrError(Errno), LOG_LEVEL_ERROR); - } - return; - } - int n = recvfrom(GetSocket(), m_ibuf, m_ibufsz, 0, (struct sockaddr *)&sa, &sa_len); - int q = m_retries; - while (n > 0) - { - if (sa_len != sizeof(sa)) - { - Handler().LogError(this, "recvfrom", 0, "unexpected address struct size", LOG_LEVEL_WARNING); - } - this -> OnRawData(m_ibuf, n, (struct sockaddr *)&sa, sa_len); - if (!q--) - break; - // - n = recvfrom(GetSocket(), m_ibuf, m_ibufsz, 0, (struct sockaddr *)&sa, &sa_len); - } - if (n == -1) - { -#ifdef _WIN32 - if (Errno != WSAEWOULDBLOCK) -#else - if (Errno != EWOULDBLOCK) -#endif - Handler().LogError(this, "recvfrom", Errno, StrError(Errno), LOG_LEVEL_ERROR); - } -} - - -void UdpSocket::SetBroadcast(bool b) -{ - int one = 1; - int zero = 0; - - if (GetSocket() == INVALID_SOCKET) - { - CreateConnection(); - } - if (b) - { - if (setsockopt(GetSocket(), SOL_SOCKET, SO_BROADCAST, (char *) &one, sizeof(one)) == -1) - { - Handler().LogError(this, "SetBroadcast", Errno, StrError(Errno), LOG_LEVEL_WARNING); - } - } - else - { - if (setsockopt(GetSocket(), SOL_SOCKET, SO_BROADCAST, (char *) &zero, sizeof(zero)) == -1) - { - Handler().LogError(this, "SetBroadcast", Errno, StrError(Errno), LOG_LEVEL_WARNING); - } - } -} - - -bool UdpSocket::IsBroadcast() -{ - int is_broadcast = 0; - socklen_t size; - - if (GetSocket() == INVALID_SOCKET) - { - CreateConnection(); - } - if (getsockopt(GetSocket(), SOL_SOCKET, SO_BROADCAST, (char *)&is_broadcast, &size) == -1) - { - Handler().LogError(this, "IsBroadcast", Errno, StrError(Errno), LOG_LEVEL_WARNING); - } - return is_broadcast != 0; -} - - -void UdpSocket::SetMulticastTTL(int ttl) -{ - if (GetSocket() == INVALID_SOCKET) - { - CreateConnection(); - } - if (setsockopt(GetSocket(), SOL_IP, IP_MULTICAST_TTL, (char *)&ttl, sizeof(int)) == -1) - { - Handler().LogError(this, "SetMulticastTTL", Errno, StrError(Errno), LOG_LEVEL_WARNING); - } -} - - -int UdpSocket::GetMulticastTTL() -{ - int ttl = 0; - socklen_t size = sizeof(int); - - if (GetSocket() == INVALID_SOCKET) - { - CreateConnection(); - } - if (getsockopt(GetSocket(), SOL_IP, IP_MULTICAST_TTL, (char *)&ttl, &size) == -1) - { - Handler().LogError(this, "GetMulticastTTL", Errno, StrError(Errno), LOG_LEVEL_WARNING); - } - return ttl; -} - - -void UdpSocket::SetMulticastLoop(bool x) -{ - if (GetSocket() == INVALID_SOCKET) - { - CreateConnection(); - } -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (IsIpv6()) - { - int val = x ? 1 : 0; - if (setsockopt(GetSocket(), IPPROTO_IPV6, IPV6_MULTICAST_LOOP, (char *)&val, sizeof(int)) == -1) - { - Handler().LogError(this, "SetMulticastLoop", Errno, StrError(Errno), LOG_LEVEL_WARNING); - } - return; - } -#endif -#endif - int val = x ? 1 : 0; - if (setsockopt(GetSocket(), SOL_IP, IP_MULTICAST_LOOP, (char *)&val, sizeof(int)) == -1) - { - Handler().LogError(this, "SetMulticastLoop", Errno, StrError(Errno), LOG_LEVEL_WARNING); - } -} - - -bool UdpSocket::IsMulticastLoop() -{ - if (GetSocket() == INVALID_SOCKET) - { - CreateConnection(); - } -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (IsIpv6()) - { - int is_loop = 0; - socklen_t size = sizeof(int); - if (getsockopt(GetSocket(), IPPROTO_IPV6, IPV6_MULTICAST_LOOP, (char *)&is_loop, &size) == -1) - { - Handler().LogError(this, "IsMulticastLoop", Errno, StrError(Errno), LOG_LEVEL_WARNING); - } - return is_loop ? true : false; - } -#endif -#endif - int is_loop = 0; - socklen_t size = sizeof(int); - if (getsockopt(GetSocket(), SOL_IP, IP_MULTICAST_LOOP, (char *)&is_loop, &size) == -1) - { - Handler().LogError(this, "IsMulticastLoop", Errno, StrError(Errno), LOG_LEVEL_WARNING); - } - return is_loop ? true : false; -} - - -void UdpSocket::AddMulticastMembership(const std::string& group, const std::string& local_if, int if_index) -{ - if (GetSocket() == INVALID_SOCKET) - { - CreateConnection(); - } -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (IsIpv6()) - { - struct ipv6_mreq x; - struct in6_addr addr; - if (Utility::u2ip( group, addr )) - { - x.ipv6mr_multiaddr = addr; - x.ipv6mr_interface = if_index; - if (setsockopt(GetSocket(), IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, (char *)&x, sizeof(struct ipv6_mreq)) == -1) - { - Handler().LogError(this, "AddMulticastMembership", Errno, StrError(Errno), LOG_LEVEL_WARNING); - } - } - return; - } -#endif -#endif - struct ip_mreq x; // ip_mreqn - ipaddr_t addr; - if (Utility::u2ip( group, addr )) - { - memcpy(&x.imr_multiaddr.s_addr, &addr, sizeof(addr)); - Utility::u2ip( local_if, addr); - memcpy(&x.imr_interface.s_addr, &addr, sizeof(addr)); -// x.imr_ifindex = if_index; - if (setsockopt(GetSocket(), SOL_IP, IP_ADD_MEMBERSHIP, (char *)&x, sizeof(struct ip_mreq)) == -1) - { - Handler().LogError(this, "AddMulticastMembership", Errno, StrError(Errno), LOG_LEVEL_WARNING); - } - } -} - - -void UdpSocket::DropMulticastMembership(const std::string& group, const std::string& local_if, int if_index) -{ - if (GetSocket() == INVALID_SOCKET) - { - CreateConnection(); - } -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (IsIpv6()) - { - struct ipv6_mreq x; - struct in6_addr addr; - if (Utility::u2ip( group, addr )) - { - x.ipv6mr_multiaddr = addr; - x.ipv6mr_interface = if_index; - if (setsockopt(GetSocket(), IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, (char *)&x, sizeof(struct ipv6_mreq)) == -1) - { - Handler().LogError(this, "DropMulticastMembership", Errno, StrError(Errno), LOG_LEVEL_WARNING); - } - } - return; - } -#endif -#endif - struct ip_mreq x; // ip_mreqn - ipaddr_t addr; - if (Utility::u2ip( group, addr )) - { - memcpy(&x.imr_multiaddr.s_addr, &addr, sizeof(addr)); - Utility::u2ip( local_if, addr); - memcpy(&x.imr_interface.s_addr, &addr, sizeof(addr)); -// x.imr_ifindex = if_index; - if (setsockopt(GetSocket(), SOL_IP, IP_DROP_MEMBERSHIP, (char *)&x, sizeof(struct ip_mreq)) == -1) - { - Handler().LogError(this, "DropMulticastMembership", Errno, StrError(Errno), LOG_LEVEL_WARNING); - } - } -} - - -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 -void UdpSocket::SetMulticastHops(int hops) -{ - if (GetSocket() == INVALID_SOCKET) - { - CreateConnection(); - } - if (!IsIpv6()) - { - Handler().LogError(this, "SetMulticastHops", 0, "Ipv6 only", LOG_LEVEL_ERROR); - return; - } - if (setsockopt(GetSocket(), IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (char *)&hops, sizeof(int)) == -1) - { - Handler().LogError(this, "SetMulticastHops", Errno, StrError(Errno), LOG_LEVEL_WARNING); - } -} - - -int UdpSocket::GetMulticastHops() -{ - if (GetSocket() == INVALID_SOCKET) - { - CreateConnection(); - } - if (!IsIpv6()) - { - Handler().LogError(this, "SetMulticastHops", 0, "Ipv6 only", LOG_LEVEL_ERROR); - return -1; - } - int hops = 0; - socklen_t size = sizeof(int); - if (getsockopt(GetSocket(), IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (char *)&hops, &size) == -1) - { - Handler().LogError(this, "GetMulticastHops", Errno, StrError(Errno), LOG_LEVEL_WARNING); - } - return hops; -} -#endif // IPPROTO_IPV6 -#endif - - -bool UdpSocket::IsBound() -{ - return m_bind_ok; -} - - -void UdpSocket::OnRawData(const char *buf, size_t len, struct sockaddr *sa, socklen_t sa_len) -{ -} - - -void UdpSocket::OnRawData(const char *buf, size_t len, struct sockaddr *sa, socklen_t sa_len, struct timeval *ts) -{ -} - - -port_t UdpSocket::GetPort() -{ - return m_port; -} - - -int UdpSocket::GetLastSizeWritten() -{ - return m_last_size_written; -} - - -void UdpSocket::SetTimestamp(bool x) -{ - m_b_read_ts = x; -} - - -#ifdef SOCKETS_NAMESPACE -} -#endif - - diff --git a/Sockets/UdpSocket.h b/Sockets/UdpSocket.h deleted file mode 100644 index a456172..0000000 --- a/Sockets/UdpSocket.h +++ /dev/null @@ -1,215 +0,0 @@ -/** \file UdpSocket.h - ** \date 2004-02-13 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_UdpSocket_H -#define _SOCKETS_UdpSocket_H - -#include "sockets-config.h" -#include "Socket.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -/** Socket implementation for UDP. - \ingroup basic */ -class UdpSocket : public Socket -{ -public: - /** Constructor. - \param h ISocketHandler reference - \param ibufsz Maximum size of receive message (extra bytes will be truncated) - \param ipv6 'true' if this is an ipv6 socket */ - UdpSocket(ISocketHandler& h,int ibufsz = 16384,bool ipv6 = false, int retries = 0); - ~UdpSocket(); - - /** Called when incoming data has been received. - \param buf Pointer to data - \param len Length of data - \param sa Pointer to sockaddr struct of sender - \param sa_len Length of sockaddr struct */ - virtual void OnRawData(const char *buf,size_t len,struct sockaddr *sa,socklen_t sa_len); - - /** Called when incoming data has been received and read timestamp is enabled. - \param buf Pointer to data - \param len Length of data - \param sa Pointer to sockaddr struct of sender - \param sa_len Length of sockaddr struct - \param ts Timestamp from message */ - virtual void OnRawData(const char *buf,size_t len,struct sockaddr *sa,socklen_t sa_len,struct timeval *ts); - - /** To receive incoming data, call Bind to setup an incoming port. - \param port Incoming port number - \param range Port range to try if ports already in use - \return 0 if bind succeeded */ - int Bind(port_t& port,int range = 1); - /** To receive data on a specific interface:port, use this. - \param intf Interface ip/hostname - \param port Port number - \param range Port range - \return 0 if bind succeeded */ - int Bind(const std::string& intf,port_t& port,int range = 1); - /** To receive data on a specific interface:port, use this. - \param a Ip address - \param port Port number - \param range Port range - \return 0 if bind succeeded */ - int Bind(ipaddr_t a,port_t& port,int range = 1); -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - /** To receive data on a specific interface:port, use this. - \param a Ipv6 address - \param port Port number - \param range Port range - \return 0 if bind succeeded */ - int Bind(in6_addr a,port_t& port,int range = 1); -#endif -#endif - /** To receive data on a specific interface:port, use this. - \param ad Socket address - \param range Port range - \return 0 if bind succeeded */ - int Bind(SocketAddress& ad,int range = 1); - - /** Define remote host. - \param l Address of remote host - \param port Port of remote host - \return true if successful */ - bool Open(ipaddr_t l,port_t port); - /** Define remote host. - \param host Hostname - \param port Port number - \return true if successful */ - bool Open(const std::string& host,port_t port); -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - /** Define remote host. - \param a Address of remote host, ipv6 - \param port Port of remote host - \return true if successful */ - bool Open(struct in6_addr& a,port_t port); -#endif -#endif - /** Define remote host. - \param ad Socket address - \return true if successful */ - bool Open(SocketAddress& ad); - - /** Send to specified host */ - void SendToBuf(const std::string& ,port_t,const char *data,int len,int flags = 0); - /** Send to specified address */ - void SendToBuf(ipaddr_t,port_t,const char *data,int len,int flags = 0); -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - /** Send to specified ipv6 address */ - void SendToBuf(in6_addr,port_t,const char *data,int len,int flags = 0); -#endif -#endif - /** Send to specified socket address */ - void SendToBuf(SocketAddress& ad,const char *data,int len,int flags = 0); - - /** Send string to specified host */ - void SendTo(const std::string&,port_t,const std::string&,int flags = 0); - /** Send string to specified address */ - void SendTo(ipaddr_t,port_t,const std::string&,int flags = 0); -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - /** Send string to specified ipv6 address */ - void SendTo(in6_addr,port_t,const std::string&,int flags = 0); -#endif -#endif - /** Send string to specified socket address */ - void SendTo(SocketAddress& ad,const std::string&,int flags = 0); - - /** Send to connected address */ - void SendBuf(const char *data,size_t,int flags = 0); - /** Send string to connected address. */ - void Send(const std::string& ,int flags = 0); - - /** Set broadcast */ - void SetBroadcast(bool b = true); - /** Check broadcast flag. - \return true broadcast is enabled. */ - bool IsBroadcast(); - - /** multicast */ - void SetMulticastTTL(int ttl = 1); - int GetMulticastTTL(); - void SetMulticastLoop(bool = true); - bool IsMulticastLoop(); - void AddMulticastMembership(const std::string& group,const std::string& intf = "0.0.0.0",int if_index = 0); - void DropMulticastMembership(const std::string& group,const std::string& intf = "0.0.0.0",int if_index = 0); -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - /** multicast, ipv6 only */ - void SetMulticastHops(int = -1); - /** multicast, ipv6 only */ - int GetMulticastHops(); -#endif -#endif - /** Returns true if Bind succeeded. */ - bool IsBound(); - /** Return Bind port number */ - port_t GetPort(); - - void OnOptions(int,int,int,SOCKET) {} - - int GetLastSizeWritten(); - - /** Also read timestamp information from incoming message */ - void SetTimestamp(bool = true); - -protected: - UdpSocket(const UdpSocket& s) : Socket(s) {} - void OnRead(); -#ifndef _WIN32 - /** This method emulates socket recvfrom, but uses messages so we can get the timestamp */ - int ReadTS(char *ioBuf, int inBufSize, struct sockaddr *from, socklen_t fromlen, struct timeval *ts); -#endif - -private: - UdpSocket& operator=(const UdpSocket& ) { return *this; } - /** create before using sendto methods */ - void CreateConnection(); - char *m_ibuf; ///< Input buffer - int m_ibufsz; ///< Size of input buffer - bool m_bind_ok; ///< Bind completed successfully - port_t m_port; ///< Bind port number - int m_last_size_written; - int m_retries; - bool m_b_read_ts; -}; - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_UdpSocket_H - diff --git a/Sockets/Utility.cpp b/Sockets/Utility.cpp deleted file mode 100644 index a80e2a8..0000000 --- a/Sockets/Utility.cpp +++ /dev/null @@ -1,953 +0,0 @@ -/** \file Utility.cpp - ** \date 2004-02-13 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#include "Utility.h" -#include "Parse.h" -#include "Ipv4Address.h" -#include "Ipv6Address.h" -#include "RandomNumber.h" -#include "Base64.h" -#include -#ifdef _WIN32 -#include -#else -#include -#include -#endif -#include - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -// statics -std::string Utility::m_host; -bool Utility::m_local_resolved = false; -ipaddr_t Utility::m_ip = 0; -std::string Utility::m_addr; -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 -struct in6_addr Utility::m_local_ip6; -std::string Utility::m_local_addr6; -#endif -#endif - - -std::string Utility::base64(const std::string& str_in) -{ - std::string str; - Base64 m_b; - m_b.encode(str_in, str, false); // , false == do not add cr/lf - return str; -} - - -std::string Utility::base64d(const std::string& str_in) -{ - std::string str; - Base64 m_b; - m_b.decode(str_in, str); - return str; -} - - -std::string Utility::l2string(long l) -{ - std::string str; - char tmp[100]; - sprintf(tmp,"%ld",l); - str = tmp; - return str; -} - - -std::string Utility::bigint2string(uint64_t l) -{ - std::string str; - uint64_t tmp = l; - while (tmp) - { - uint64_t a = tmp % 10; - str = (char)(a + 48) + str; - tmp /= 10; - } - if (!str.size()) - { - str = "0"; - } - return str; -} - - -uint64_t Utility::atoi64(const std::string& str) -{ - uint64_t l = 0; - for (size_t i = 0; i < str.size(); i++) - { - l = l * 10 + str[i] - 48; - } - return l; -} - - -unsigned int Utility::hex2unsigned(const std::string& str) -{ - unsigned int r = 0; - for (size_t i = 0; i < str.size(); i++) - { - r = r * 16 + str[i] - 48 - ((str[i] >= 'A') ? 7 : 0) - ((str[i] >= 'a') ? 32 : 0); - } - return r; -} - - -/* -* Encode string per RFC1738 URL encoding rules -* tnx rstaveley -*/ -std::string Utility::rfc1738_encode(const std::string& src) -{ -static char hex[] = "0123456789ABCDEF"; - std::string dst; - for (size_t i = 0; i < src.size(); i++) - { - if (isalnum(src[i])) - { - dst += src[i]; - } - else - if (src[i] == ' ') - { - dst += '+'; - } - else - { - unsigned char c = static_cast(src[i]); - dst += '%'; - dst += hex[c / 16]; - dst += hex[c % 16]; - } - } - return dst; -} // rfc1738_encode - - -/* -* Decode string per RFC1738 URL encoding rules -* tnx rstaveley -*/ -std::string Utility::rfc1738_decode(const std::string& src) -{ - std::string dst; - for (size_t i = 0; i < src.size(); i++) - { - if (src[i] == '%' && isxdigit(src[i + 1]) && isxdigit(src[i + 2])) - { - char c1 = src[++i]; - char c2 = src[++i]; - c1 = c1 - 48 - ((c1 >= 'A') ? 7 : 0) - ((c1 >= 'a') ? 32 : 0); - c2 = c2 - 48 - ((c2 >= 'A') ? 7 : 0) - ((c2 >= 'a') ? 32 : 0); - dst += (char)(c1 * 16 + c2); - } - else - if (src[i] == '+') - { - dst += ' '; - } - else - { - dst += src[i]; - } - } - return dst; -} // rfc1738_decode - - -bool Utility::isipv4(const std::string& str) -{ - int dots = 0; - // %! ignore :port? - for (size_t i = 0; i < str.size(); i++) - { - if (str[i] == '.') - dots++; - else - if (!isdigit(str[i])) - return false; - } - if (dots != 3) - return false; - return true; -} - - -bool Utility::isipv6(const std::string& str) -{ - size_t qc = 0; - size_t qd = 0; - for (size_t i = 0; i < str.size(); i++) - { - qc += (str[i] == ':') ? 1 : 0; - qd += (str[i] == '.') ? 1 : 0; - } - if (qc > 7) - { - return false; - } - if (qd && qd != 3) - { - return false; - } - Parse pa(str,":."); - std::string tmp = pa.getword(); - while (tmp.size()) - { - if (tmp.size() > 4) - { - return false; - } - for (size_t i = 0; i < tmp.size(); i++) - { - if (tmp[i] < '0' || (tmp[i] > '9' && tmp[i] < 'A') || - (tmp[i] > 'F' && tmp[i] < 'a') || tmp[i] > 'f') - { - return false; - } - } - // - tmp = pa.getword(); - } - return true; -} - - -bool Utility::u2ip(const std::string& str, ipaddr_t& l) -{ - struct sockaddr_in sa; - bool r = Utility::u2ip(str, sa); - memcpy(&l, &sa.sin_addr, sizeof(l)); - return r; -} - - -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 -bool Utility::u2ip(const std::string& str, struct in6_addr& l) -{ - struct sockaddr_in6 sa; - bool r = Utility::u2ip(str, sa); - l = sa.sin6_addr; - return r; -} -#endif -#endif - - -void Utility::l2ip(const ipaddr_t ip, std::string& str) -{ - struct sockaddr_in sa; - memset(&sa, 0, sizeof(sa)); - sa.sin_family = AF_INET; - memcpy(&sa.sin_addr, &ip, sizeof(sa.sin_addr)); - Utility::reverse( (struct sockaddr *)&sa, sizeof(sa), str, NI_NUMERICHOST); -} - - -void Utility::l2ip(const in_addr& ip, std::string& str) -{ - struct sockaddr_in sa; - memset(&sa, 0, sizeof(sa)); - sa.sin_family = AF_INET; - sa.sin_addr = ip; - Utility::reverse( (struct sockaddr *)&sa, sizeof(sa), str, NI_NUMERICHOST); -} - - -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 -void Utility::l2ip(const struct in6_addr& ip, std::string& str,bool mixed) -{ - char slask[100]; // l2ip temporary - *slask = 0; - unsigned int prev = 0; - bool skipped = false; - bool ok_to_skip = true; - if (mixed) - { - unsigned short x; - unsigned short addr16[8]; - memcpy(addr16, &ip, sizeof(addr16)); - for (size_t i = 0; i < 6; i++) - { - x = ntohs(addr16[i]); - if (*slask && (x || !ok_to_skip || prev)) - strcat(slask,":"); - if (x || !ok_to_skip) - { - sprintf(slask + strlen(slask),"%x", x); - if (x && skipped) - ok_to_skip = false; - } - else - { - skipped = true; - } - prev = x; - } - x = ntohs(addr16[6]); - sprintf(slask + strlen(slask),":%u.%u",x / 256,x & 255); - x = ntohs(addr16[7]); - sprintf(slask + strlen(slask),".%u.%u",x / 256,x & 255); - } - else - { - struct sockaddr_in6 sa; - memset(&sa, 0, sizeof(sa)); - sa.sin6_family = AF_INET6; - sa.sin6_addr = ip; - Utility::reverse( (struct sockaddr *)&sa, sizeof(sa), str, NI_NUMERICHOST); - return; - } - str = slask; -} - - -int Utility::in6_addr_compare(in6_addr a,in6_addr b) -{ - for (size_t i = 0; i < 16; i++) - { - if (a.s6_addr[i] < b.s6_addr[i]) - return -1; - if (a.s6_addr[i] > b.s6_addr[i]) - return 1; - } - return 0; -} -#endif -#endif - - -void Utility::ResolveLocal() -{ - char h[256]; - - // get local hostname and translate into ip-address - *h = 0; - gethostname(h,255); - { - if (Utility::u2ip(h, m_ip)) - { - Utility::l2ip(m_ip, m_addr); - } - } -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - memset(&m_local_ip6, 0, sizeof(m_local_ip6)); - { - if (Utility::u2ip(h, m_local_ip6)) - { - Utility::l2ip(m_local_ip6, m_local_addr6); - } - } -#endif -#endif - m_host = h; - m_local_resolved = true; -} - - -const std::string& Utility::GetLocalHostname() -{ - if (!m_local_resolved) - { - ResolveLocal(); - } - return m_host; -} - - -ipaddr_t Utility::GetLocalIP() -{ - if (!m_local_resolved) - { - ResolveLocal(); - } - return m_ip; -} - - -const std::string& Utility::GetLocalAddress() -{ - if (!m_local_resolved) - { - ResolveLocal(); - } - return m_addr; -} - - -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 -const struct in6_addr& Utility::GetLocalIP6() -{ - if (!m_local_resolved) - { - ResolveLocal(); - } - return m_local_ip6; -} - - -const std::string& Utility::GetLocalAddress6() -{ - if (!m_local_resolved) - { - ResolveLocal(); - } - return m_local_addr6; -} -#endif -#endif - - -void Utility::SetEnv(const std::string& var,const std::string& value) -{ -#if (defined(SOLARIS8) || defined(SOLARIS)) - { - static std::map vmap; - if (vmap.find(var) != vmap.end()) - { - delete[] vmap[var]; - } - vmap[var] = new char[var.size() + 1 + value.size() + 1]; - sprintf(vmap[var], "%s=%s", var.c_str(), value.c_str()); - putenv( vmap[var] ); - } -#elif defined _WIN32 - { - std::string slask = var + "=" + value; - _putenv( (char *)slask.c_str()); - } -#else - setenv(var.c_str(), value.c_str(), 1); -#endif -} - - -std::string Utility::Sa2String(struct sockaddr *sa) -{ -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - if (sa -> sa_family == AF_INET6) - { - struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)sa; - std::string tmp; - Utility::l2ip(sa6 -> sin6_addr, tmp); - return tmp + ":" + Utility::l2string(ntohs(sa6 -> sin6_port)); - } -#endif -#endif - if (sa -> sa_family == AF_INET) - { - struct sockaddr_in *sa4 = (struct sockaddr_in *)sa; - ipaddr_t a; - memcpy(&a, &sa4 -> sin_addr, 4); - std::string tmp; - Utility::l2ip(a, tmp); - return tmp + ":" + Utility::l2string(ntohs(sa4 -> sin_port)); - } - return ""; -} - - -void Utility::GetTime(struct timeval *p) -{ -#ifdef _WIN32 - FILETIME ft; // Contains a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC). - GetSystemTimeAsFileTime(&ft); - uint64_t tt; - memcpy(&tt, &ft, sizeof(tt)); - tt /= 10; // make it usecs - p->tv_sec = (long)tt / 1000000; - p->tv_usec = (long)tt % 1000000; -#else - gettimeofday(p, NULL); -#endif -} - - -std::auto_ptr Utility::CreateAddress(struct sockaddr *sa,socklen_t sa_len) -{ - switch (sa -> sa_family) - { - case AF_INET: - if (sa_len == sizeof(struct sockaddr_in)) - { - struct sockaddr_in *p = (struct sockaddr_in *)sa; - return std::auto_ptr(new Ipv4Address(*p)); - } - break; -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - case AF_INET6: - if (sa_len == sizeof(struct sockaddr_in6)) - { - struct sockaddr_in6 *p = (struct sockaddr_in6 *)sa; - return std::auto_ptr(new Ipv6Address(*p)); - } - break; -#endif -#endif - } - return std::auto_ptr(NULL); -} - - -bool Utility::u2ip(const std::string& host, struct sockaddr_in& sa, int ai_flags) -{ - memset(&sa, 0, sizeof(sa)); - sa.sin_family = AF_INET; -#ifdef NO_GETADDRINFO - if ((ai_flags & AI_NUMERICHOST) != 0 || isipv4(host)) - { - Parse pa((char *)host.c_str(), "."); - union { - struct { - unsigned char b1; - unsigned char b2; - unsigned char b3; - unsigned char b4; - } a; - ipaddr_t l; - } u; - u.a.b1 = static_cast(pa.getvalue()); - u.a.b2 = static_cast(pa.getvalue()); - u.a.b3 = static_cast(pa.getvalue()); - u.a.b4 = static_cast(pa.getvalue()); - memcpy(&sa.sin_addr, &u.l, sizeof(sa.sin_addr)); - return true; - } -#ifndef LINUX - struct hostent *he = gethostbyname( host.c_str() ); - if (!he) - { - return false; - } - memcpy(&sa.sin_addr, he -> h_addr, sizeof(sa.sin_addr)); -#else - struct hostent he; - struct hostent *result = NULL; - int myerrno = 0; - char buf[2000]; - int n = gethostbyname_r(host.c_str(), &he, buf, sizeof(buf), &result, &myerrno); - if (n || !result) - { - return false; - } - if (he.h_addr_list && he.h_addr_list[0]) - memcpy(&sa.sin_addr, he.h_addr, 4); - else - return false; -#endif - return true; -#else - struct addrinfo hints; - memset(&hints, 0, sizeof(hints)); - // AI_NUMERICHOST - // AI_CANONNAME - // AI_PASSIVE - server - // AI_ADDRCONFIG - // AI_V4MAPPED - // AI_ALL - // AI_NUMERICSERV - hints.ai_flags = ai_flags; - hints.ai_family = AF_INET; - hints.ai_socktype = 0; - hints.ai_protocol = 0; - struct addrinfo *res; - if (Utility::isipv4(host)) - hints.ai_flags |= AI_NUMERICHOST; - int n = getaddrinfo(host.c_str(), NULL, &hints, &res); - if (!n) - { - static RandomNumber prng( true ); - std::vector vec; - struct addrinfo *ai = res; - while (ai) - { - if (ai -> ai_addrlen == sizeof(sa)) - vec.push_back( ai ); - prng.next(); - // - ai = ai -> ai_next; - } - if (!vec.size()) - return false; - ai = vec[prng.next() % vec.size()]; - { - memcpy(&sa, ai -> ai_addr, ai -> ai_addrlen); - } - freeaddrinfo(res); - return true; - } - std::string error = "Error: "; -#ifndef __CYGWIN__ - error += gai_strerror(n); -#endif - return false; -#endif // NO_GETADDRINFO -} - - -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 -bool Utility::u2ip(const std::string& host, struct sockaddr_in6& sa, int ai_flags) -{ - memset(&sa, 0, sizeof(sa)); - sa.sin6_family = AF_INET6; -#ifdef NO_GETADDRINFO - if ((ai_flags & AI_NUMERICHOST) != 0 || isipv6(host)) - { - std::list vec; - size_t x = 0; - for (size_t i = 0; i <= host.size(); i++) - { - if (i == host.size() || host[i] == ':') - { - std::string s = host.substr(x, i - x); - // - if (strstr(s.c_str(),".")) // x.x.x.x - { - Parse pa(s,"."); - char slask[100]; // u2ip temporary hex2string conversion - unsigned long b0 = static_cast(pa.getvalue()); - unsigned long b1 = static_cast(pa.getvalue()); - unsigned long b2 = static_cast(pa.getvalue()); - unsigned long b3 = static_cast(pa.getvalue()); - sprintf(slask,"%lx",b0 * 256 + b1); - vec.push_back(slask); - sprintf(slask,"%lx",b2 * 256 + b3); - vec.push_back(slask); - } - else - { - vec.push_back(s); - } - // - x = i + 1; - } - } - size_t sz = vec.size(); // number of byte pairs - size_t i = 0; // index in in6_addr.in6_u.u6_addr16[] ( 0 .. 7 ) - unsigned short addr16[8]; - for (std::list::iterator it = vec.begin(); it != vec.end(); it++) - { - std::string bytepair = *it; - if (bytepair.size()) - { - addr16[i++] = htons(Utility::hex2unsigned(bytepair)); - } - else - { - addr16[i++] = 0; - while (sz++ < 8) - { - addr16[i++] = 0; - } - } - } - memcpy(&sa.sin6_addr, addr16, sizeof(addr16)); - return true; - } -#ifdef SOLARIS - int errnum = 0; - struct hostent *he = getipnodebyname( host.c_str(), AF_INET6, 0, &errnum ); -#else - struct hostent *he = gethostbyname2( host.c_str(), AF_INET6 ); -#endif - if (!he) - { - return false; - } - memcpy(&sa.sin6_addr,he -> h_addr_list[0],he -> h_length); -#ifdef SOLARIS - free(he); -#endif - return true; -#else - struct addrinfo hints; - memset(&hints, 0, sizeof(hints)); - hints.ai_flags = ai_flags; - hints.ai_family = AF_INET6; - hints.ai_socktype = 0; - hints.ai_protocol = 0; - struct addrinfo *res; - if (Utility::isipv6(host)) - hints.ai_flags |= AI_NUMERICHOST; - int n = getaddrinfo(host.c_str(), NULL, &hints, &res); - if (!n) - { - static RandomNumber prng( true ); - std::vector vec; - struct addrinfo *ai = res; - while (ai) - { - if (ai -> ai_addrlen == sizeof(sa)) - vec.push_back( ai ); - prng.next(); - // - ai = ai -> ai_next; - } - if (!vec.size()) - return false; - ai = vec[prng.next() % vec.size()]; - { - memcpy(&sa, ai -> ai_addr, ai -> ai_addrlen); - } - freeaddrinfo(res); - return true; - } - std::string error = "Error: "; -#ifndef __CYGWIN__ - error += gai_strerror(n); -#endif - return false; -#endif // NO_GETADDRINFO -} -#endif // IPPROTO_IPV6 -#endif // ENABLE_IPV6 - - -bool Utility::reverse(struct sockaddr *sa, socklen_t sa_len, std::string& hostname, int flags) -{ - std::string service; - return Utility::reverse(sa, sa_len, hostname, service, flags); -} - - -bool Utility::reverse(struct sockaddr *sa, socklen_t sa_len, std::string& hostname, std::string& service, int flags) -{ - hostname = ""; - service = ""; -#ifdef NO_GETADDRINFO - switch (sa -> sa_family) - { - case AF_INET: - if (flags & NI_NUMERICHOST) - { - union { - struct { - unsigned char b1; - unsigned char b2; - unsigned char b3; - unsigned char b4; - } a; - ipaddr_t l; - } u; - struct sockaddr_in *sa_in = (struct sockaddr_in *)sa; - memcpy(&u.l, &sa_in -> sin_addr, sizeof(u.l)); - char tmp[100]; - sprintf(tmp, "%u.%u.%u.%u", u.a.b1, u.a.b2, u.a.b3, u.a.b4); - hostname = tmp; - return true; - } - else - { - struct sockaddr_in *sa_in = (struct sockaddr_in *)sa; - struct hostent *h = gethostbyaddr( (const char *)&sa_in -> sin_addr, sizeof(sa_in -> sin_addr), AF_INET); - if (h) - { - hostname = h -> h_name; - return true; - } - } - break; -#ifdef ENABLE_IPV6 - case AF_INET6: - if (flags & NI_NUMERICHOST) - { - char slask[100]; // l2ip temporary - *slask = 0; - unsigned int prev = 0; - bool skipped = false; - bool ok_to_skip = true; - { - unsigned short addr16[8]; - struct sockaddr_in6 *sa_in6 = (struct sockaddr_in6 *)sa; - memcpy(addr16, &sa_in6 -> sin6_addr, sizeof(addr16)); - for (size_t i = 0; i < 8; i++) - { - unsigned short x = ntohs(addr16[i]); - if (*slask && (x || !ok_to_skip || prev)) - strcat(slask,":"); - if (x || !ok_to_skip) - { - sprintf(slask + strlen(slask),"%x", x); - if (x && skipped) - ok_to_skip = false; - } - else - { - skipped = true; - } - prev = x; - } - } - if (!*slask) - strcpy(slask, "::"); - hostname = slask; - return true; - } - else - { - // %! TODO: ipv6 reverse lookup - struct sockaddr_in6 *sa_in = (struct sockaddr_in6 *)sa; - struct hostent *h = gethostbyaddr( (const char *)&sa_in -> sin6_addr, sizeof(sa_in -> sin6_addr), AF_INET6); - if (h) - { - hostname = h -> h_name; - return true; - } - } - break; -#endif - } - return false; -#else - char host[NI_MAXHOST]; - char serv[NI_MAXSERV]; - // NI_NOFQDN - // NI_NUMERICHOST - // NI_NAMEREQD - // NI_NUMERICSERV - // NI_DGRAM - int n = getnameinfo(sa, sa_len, host, sizeof(host), serv, sizeof(serv), flags); - if (n) - { - // EAI_AGAIN - // EAI_BADFLAGS - // EAI_FAIL - // EAI_FAMILY - // EAI_MEMORY - // EAI_NONAME - // EAI_OVERFLOW - // EAI_SYSTEM - return false; - } - hostname = host; - service = serv; - return true; -#endif // NO_GETADDRINFO -} - - -bool Utility::u2service(const std::string& name, int& service, int ai_flags) -{ -#ifdef NO_GETADDRINFO - // %! - return false; -#else - struct addrinfo hints; - service = 0; - memset(&hints, 0, sizeof(hints)); - // AI_NUMERICHOST - // AI_CANONNAME - // AI_PASSIVE - server - // AI_ADDRCONFIG - // AI_V4MAPPED - // AI_ALL - // AI_NUMERICSERV - hints.ai_flags = ai_flags; - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = 0; - hints.ai_protocol = 0; - struct addrinfo *res; - int n = getaddrinfo(NULL, name.c_str(), &hints, &res); - if (!n) - { - service = res -> ai_protocol; - freeaddrinfo(res); - return true; - } - return false; -#endif // NO_GETADDRINFO -} - - -unsigned long Utility::ThreadID() -{ -#ifdef _WIN32 - return GetCurrentThreadId(); -#else - return (unsigned long)pthread_self(); -#endif -} - - -std::string Utility::ToLower(const std::string& str) -{ - std::string r; - for (size_t i = 0; i < str.size(); i++) - { - if (str[i] >= 'A' && str[i] <= 'Z') - r += str[i] | 32; - else - r += str[i]; - } - return r; -} - - -std::string Utility::ToUpper(const std::string& str) -{ - std::string r; - for (size_t i = 0; i < str.size(); i++) - { - if (str[i] >= 'a' && str[i] <= 'z') - r += (char)(str[i] - 32); - else - r += str[i]; - } - return r; -} - - -std::string Utility::ToString(double d) -{ - char tmp[100]; - sprintf(tmp, "%f", d); - return tmp; -} - - -#ifdef SOCKETS_NAMESPACE -} -#endif - diff --git a/Sockets/Utility.h b/Sockets/Utility.h deleted file mode 100644 index 133fbd1..0000000 --- a/Sockets/Utility.h +++ /dev/null @@ -1,153 +0,0 @@ -/** \file Utility.h - ** \date 2004-02-13 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_Utility_H -#define _SOCKETS_Utility_H - -#include "sockets-config.h" -#include -#include -#include "socket_include.h" - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -class SocketAddress; - -/** Conversion utilities. - \ingroup util */ -class Utility -{ -public: - static std::string base64(const std::string& str_in); - static std::string base64d(const std::string& str_in); - static std::string l2string(long l); - static std::string bigint2string(uint64_t l); - static uint64_t atoi64(const std::string& str); - static unsigned int hex2unsigned(const std::string& str); - static std::string rfc1738_encode(const std::string& src); - static std::string rfc1738_decode(const std::string& src); - - /** Checks whether a string is a valid ipv4/ipv6 ip number. */ - static bool isipv4(const std::string&); - /** Checks whether a string is a valid ipv4/ipv6 ip number. */ - static bool isipv6(const std::string&); - - /** Hostname to ip resolution ipv4, not asynchronous. */ - static bool u2ip(const std::string&, ipaddr_t&); - static bool u2ip(const std::string&, struct sockaddr_in& sa, int ai_flags = 0); - -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - /** Hostname to ip resolution ipv6, not asynchronous. */ - static bool u2ip(const std::string&, struct in6_addr&); - static bool u2ip(const std::string&, struct sockaddr_in6& sa, int ai_flags = 0); -#endif -#endif - - /** Reverse lookup of address to hostname */ - static bool reverse(struct sockaddr *sa, socklen_t sa_len, std::string&, int flags = 0); - static bool reverse(struct sockaddr *sa, socklen_t sa_len, std::string& hostname, std::string& service, int flags = 0); - - static bool u2service(const std::string& name, int& service, int ai_flags = 0); - - /** Convert binary ip address to string: ipv4. */ - static void l2ip(const ipaddr_t,std::string& ); - static void l2ip(const in_addr&,std::string& ); -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - /** Convert binary ip address to string: ipv6. */ - static void l2ip(const struct in6_addr&,std::string& ,bool mixed = false); - - /** ipv6 address compare. */ - static int in6_addr_compare(in6_addr,in6_addr); -#endif -#endif - /** ResolveLocal (hostname) - call once before calling any GetLocal method. */ - static void ResolveLocal(); - /** Returns local hostname, ResolveLocal must be called once before using. - \sa ResolveLocal */ - static const std::string& GetLocalHostname(); - /** Returns local ip, ResolveLocal must be called once before using. - \sa ResolveLocal */ - static ipaddr_t GetLocalIP(); - /** Returns local ip number as string. - \sa ResolveLocal */ - static const std::string& GetLocalAddress(); -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - /** Returns local ipv6 ip. - \sa ResolveLocal */ - static const struct in6_addr& GetLocalIP6(); - /** Returns local ipv6 address. - \sa ResolveLocal */ - static const std::string& GetLocalAddress6(); -#endif -#endif - /** Set environment variable. - \param var Name of variable to set - \param value Value */ - static void SetEnv(const std::string& var,const std::string& value); - /** Convert sockaddr struct to human readable string. - \param sa Ptr to sockaddr struct */ - static std::string Sa2String(struct sockaddr *sa); - - /** Get current time in sec/microseconds. */ - static void GetTime(struct timeval *); - - static std::auto_ptr CreateAddress(struct sockaddr *,socklen_t); - - static unsigned long ThreadID(); - - static std::string ToLower(const std::string& str); - static std::string ToUpper(const std::string& str); - - static std::string ToString(double d); - -private: - static std::string m_host; ///< local hostname - static ipaddr_t m_ip; ///< local ip address - static std::string m_addr; ///< local ip address in string format -#ifdef ENABLE_IPV6 -#ifdef IPPROTO_IPV6 - static struct in6_addr m_local_ip6; ///< local ipv6 address -#endif - static std::string m_local_addr6; ///< local ipv6 address in string format -#endif - static bool m_local_resolved; ///< ResolveLocal has been called if true -}; - - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // _SOCKETS_Utility_H - diff --git a/Sockets/ajp13.h b/Sockets/ajp13.h deleted file mode 100644 index b82f45d..0000000 --- a/Sockets/ajp13.h +++ /dev/null @@ -1,91 +0,0 @@ -/** - ** \file ajp13.h - ** \date 2007-10-05 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_Ajp13_H -#define _SOCKETS_Ajp13_H - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - -#define HTTP_REQUEST_ACCEPT 0xa001 -#define HTTP_REQUEST_ACCEPT_CHARSET 0xa002 -#define HTTP_REQUEST_ACCEPT_ENCODING 0xa003 -#define HTTP_REQUEST_ACCEPT_LANGUAGE 0xa004 -#define HTTP_REQUEST_AUTHORIZATION 0xa005 -#define HTTP_REQUEST_CONNECTION 0xa006 -#define HTTP_REQUEST_CONTENT_TYPE 0xa007 -#define HTTP_REQUEST_CONTENT_LENGTH 0xa008 -#define HTTP_REQUEST_COOKIE 0xa009 -#define HTTP_REQUEST_COOKIE2 0xa00a -#define HTTP_REQUEST_HOST 0xa00b -#define HTTP_REQUEST_PRAGMA 0xa00c -#define HTTP_REQUEST_REFERER 0xa00d -#define HTTP_REQUEST_USER_AGENT 0xa00e - -#define HTTP_METHOD_OPTIONS 1 -#define HTTP_METHOD_GET 2 -#define HTTP_METHOD_HEAD 3 -#define HTTP_METHOD_POST 4 -#define HTTP_METHOD_PUT 5 -#define HTTP_METHOD_DELETE 6 -#define HTTP_METHOD_TRACE 7 -#define HTTP_METHOD_PROPFIND 8 -#define HTTP_METHOD_PROPPATCH 9 -#define HTTP_METHOD_MKCOL 10 -#define HTTP_METHOD_COPY 11 -#define HTTP_METHOD_MOVE 12 -#define HTTP_METHOD_LOCK 13 -#define HTTP_METHOD_UNLOCK 14 -#define HTTP_METHOD_ACL 15 -#define HTTP_METHOD_REPORT 16 -#define HTTP_METHOD_VERSION_CONTROL 17 // with a dash "VERSION-CONTROL" -#define HTTP_METHOD_CHECKIN 18 -#define HTTP_METHOD_CHECKOUT 19 -#define HTTP_METHOD_UNCHECKOUT 20 -#define HTTP_METHOD_SEARCH 21 -#define HTTP_METHOD_MKWORKSPACE 22 -#define HTTP_METHOD_UPDATE 23 -#define HTTP_METHOD_LABEL 24 -#define HTTP_METHOD_MERGE 25 -#define HTTP_METHOD_BASELINE_CONTROL 26 -#define HTTP_METHOD_MKACTIVITY 27 - -#define ATTR_CONTEXT 1 -#define ATTR_SERVLET_PATH 2 -#define ATTR_REMOTE_USER 3 -#define ATTR_AUTH_TYPE 4 -#define ATTR_QUERY_STRING 5 -#define ATTR_ROUTE 6 -#define ATTR_SSL_CERT 7 -#define ATTR_SSL_CIPHER 8 -#define ATTR_SSL_SESSION 9 -#define ATTR_SSL_KEY_SIZE 11 -#define ATTR_SECRET 12 -#define ATTR_STORED_METHOD 13 - -#ifdef SOCKETS_NAMESPACE -} // namespace SOCKETS_NAMESPACE { -#endif - -#endif // _SOCKETS_Ajp13_H - diff --git a/Sockets/gpl.txt b/Sockets/gpl.txt deleted file mode 100644 index 5b6e7c6..0000000 --- a/Sockets/gpl.txt +++ /dev/null @@ -1,340 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/Sockets/mkdot.sh b/Sockets/mkdot.sh deleted file mode 100755 index 598de96..0000000 --- a/Sockets/mkdot.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh -PROJECT_DIR=/usr/local/apache/www.alhem.net/htdocs/Sockets -PROJECT_NAME=sockets -/usr/local/bin/dp \ - -D_RUN_DP \ - -DUSE_SCTP -D_THREADSAFE_SOCKETS \ - -DHAVE_OPENSSL -DENABLE_POOL -DENABLE_RECONNECT -DENABLE_SOCKS4 \ - -DENABLE_IPV6 -DENABLE_DETACH -DENABLE_RESOLVER -DENABLE_TRIGGERS \ - -fontsize 12 \ - -lr -dot -cluster | grep -v std > x.dot -dot -Tpng -o $PROJECT_DIR/sockets.png x.dot -dot -Tcmapx -o $PROJECT_DIR/sockets.cmap x.dot -/usr/local/bin/mkjs $PROJECT_DIR/$PROJECT_NAME.cmap > $PROJECT_DIR/$PROJECT_NAME.js diff --git a/Sockets/socket_include.cpp b/Sockets/socket_include.cpp deleted file mode 100644 index 07b986b..0000000 --- a/Sockets/socket_include.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/** \file socket_include.cpp - ** \date 2004-11-28 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#include - -// only to be included in win32 projects -const char *StrError(int x) -{ -static char tmp[100]; - switch (x) - { - case 10004: return "Interrupted function call."; - case 10013: return "Permission denied."; - case 10014: return "Bad address."; - case 10022: return "Invalid argument."; - case 10024: return "Too many open files."; - case 10035: return "Resource temporarily unavailable."; - case 10036: return "Operation now in progress."; - case 10037: return "Operation already in progress."; - case 10038: return "Socket operation on nonsocket."; - case 10039: return "Destination address required."; - case 10040: return "Message too long."; - case 10041: return "Protocol wrong type for socket."; - case 10042: return "Bad protocol option."; - case 10043: return "Protocol not supported."; - case 10044: return "Socket type not supported."; - case 10045: return "Operation not supported."; - case 10046: return "Protocol family not supported."; - case 10047: return "Address family not supported by protocol family."; - case 10048: return "Address already in use."; - case 10049: return "Cannot assign requested address."; - case 10050: return "Network is down."; - case 10051: return "Network is unreachable."; - case 10052: return "Network dropped connection on reset."; - case 10053: return "Software caused connection abort."; - case 10054: return "Connection reset by peer."; - case 10055: return "No buffer space available."; - case 10056: return "Socket is already connected."; - case 10057: return "Socket is not connected."; - case 10058: return "Cannot send after socket shutdown."; - case 10060: return "Connection timed out."; - case 10061: return "Connection refused."; - case 10064: return "Host is down."; - case 10065: return "No route to host."; - case 10067: return "Too many processes."; - case 10091: return "Network subsystem is unavailable."; - case 10092: return "Winsock.dll version out of range."; - case 10093: return "Successful WSAStartup not yet performed."; - case 10101: return "Graceful shutdown in progress."; - case 10109: return "Class type not found."; - case 11001: return "Host not found."; - case 11002: return "Nonauthoritative host not found."; - case 11003: return "This is a nonrecoverable error."; - case 11004: return "Valid name, no data record of requested type."; - - default: - break; - } - sprintf(tmp, "Winsock error code: %d", x); - return tmp; -} - - - diff --git a/Sockets/socket_include.h b/Sockets/socket_include.h deleted file mode 100644 index 213c8b3..0000000 --- a/Sockets/socket_include.h +++ /dev/null @@ -1,288 +0,0 @@ -/** \file socket_include.h - ** \date 2005-04-12 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2004-2007 Anders Hedstrom - -This library is made available under the terms of the GNU GPL. - -If you would like to use this library in a closed-source application, -a separate license agreement is available. For information about -the closed-source license agreement for the C++ sockets library, -please visit http://www.alhem.net/Sockets/license.html and/or -email license@alhem.net. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_socket_include_H -#define _SOCKETS_socket_include_H -#include "sockets-config.h" - -#ifdef _MSC_VER -#pragma warning(disable:4514) -#endif - -// common defines affecting library and applications using library - -/* Define SOCKETS_DYNAMIC_TEMP to use dynamically allocated buffers - in read operations - helps on ECOS */ -#define SOCKETS_DYNAMIC_TEMP - - -// platform specific stuff -#if (defined(__unix__) || defined(unix)) && !defined(USG) -#include -#endif -#include - -// int64 -#ifdef _WIN32 -typedef unsigned __int64 uint64_t; -#else -#include -#ifdef SOLARIS -# include -#else -# include -#endif -#endif - -#ifndef _WIN32 -// ---------------------------------------- -// common unix includes / defines -#include -#include -#include -#include -#include -#include -//#include - -// all typedefs in this file will be declared outside the sockets namespace, -// because some os's will already have one or more of the type defined. -typedef int SOCKET; -#define Errno errno -#define StrError strerror - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -// WIN32 adapt -#define closesocket close -#define INVALID_SOCKET -1 -#define SOCKET_ERROR -1 - -#ifndef INADDR_NONE -#define INADDR_NONE ((unsigned long) -1) -#endif // INADDR_NONE - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#endif // !_WIN32 - - -// ---------------------------------------- -// Generic -#ifndef SOL_IP -#define SOL_IP IPPROTO_IP -#endif - - -// ---------------------------------------- -// OS specific adaptions - -#ifdef SOLARIS -// ---------------------------------------- -// Solaris -typedef unsigned short port_t; -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif -// no defs - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#define s6_addr16 _S6_un._S6_u8 -#define MSG_NOSIGNAL 0 - -#elif defined __FreeBSD__ -// ---------------------------------------- -// FreeBSD -# if __FreeBSD_version >= 400014 -# define s6_addr16 __u6_addr.__u6_addr16 -# if !defined(MSG_NOSIGNAL) -# define MSG_NOSIGNAL 0 -# endif -# include -typedef in_addr_t ipaddr_t; -typedef in_port_t port_t; -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif -// no defs - -#ifdef SOCKETS_NAMESPACE -} -#endif - -# define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP -# define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP -# else -# error FreeBSD versions prior to 400014 does not support ipv6 -# endif - -#elif defined MACOSX -// ---------------------------------------- -// Mac OS X -#include -#include -typedef unsigned long ipaddr_t; -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif -// no defs - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#define s6_addr16 __u6_addr.__u6_addr16 -#define MSG_NOSIGNAL 0 // oops - thanks Derek -#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP -#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP - -#elif defined _WIN32 -// ---------------------------------------- -// Win32 -#ifdef _MSC_VER -#pragma comment(lib, "wsock32.lib") -#endif -#define strcasecmp _stricmp - -typedef unsigned long ipaddr_t; -typedef unsigned short port_t; -typedef int socklen_t; -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif -// no defs - -#ifdef SOCKETS_NAMESPACE -} -#endif - -// 1.8.6: define FD_SETSIZE to something bigger than 64 if there are a lot of -// simultaneous connections (must be done before including winsock.h) -//#define FD_SETSIZE 1024 - -// windows 2000 with ipv6 preview installed: -// http://msdn.microsoft.com/downloads/sdks/platform/tpipv6.asp -// see the FAQ on how to install -#define WIN32_LEAN_AND_MEAN -#include -#include -#if _MSC_VER < 1200 -#ifndef __CYGWIN__ -#ifdef ENABLE_IPV6 -#include // For IPv6 Tech Preview. -#endif -#endif -#endif // _MSC_VER < 1200 - - -#define MSG_NOSIGNAL 0 -//#define SHUT_RDWR 2 -#define SHUT_WR 1 - -#define Errno WSAGetLastError() -const char *StrError(int x); - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - - -// class WSAInitializer is a part of the Socket class (on win32) -// as a static instance - so whenever an application uses a Socket, -// winsock is initialized -class WSAInitializer // Winsock Initializer -{ -public: - WSAInitializer() { - if (WSAStartup(0x101,&m_wsadata)) - { - exit(-1); - } - } - ~WSAInitializer() { - WSACleanup(); - } -private: - WSADATA m_wsadata; -}; - -#ifdef SOCKETS_NAMESPACE -} -#endif - -#else -// ---------------------------------------- -// LINUX -typedef unsigned long ipaddr_t; -typedef unsigned short port_t; -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif -// no defs - -#ifdef SOCKETS_NAMESPACE -} -#endif - - -#endif - -#ifdef SOCKETS_NAMESPACE -namespace SOCKETS_NAMESPACE { -#endif - /** List type containing file descriptors. */ - typedef std::list socket_v; - - -#ifdef SOCKETS_NAMESPACE -} -#endif - - -// getaddrinfo / getnameinfo replacements -#ifdef NO_GETADDRINFO -#ifndef AI_NUMERICHOST -#define AI_NUMERICHOST 1 -#endif -#ifndef NI_NUMERICHOST -#define NI_NUMERICHOST 1 -#endif -#endif - - -#endif // _SOCKETS_socket_include_H - diff --git a/Sockets/sockets-config.h b/Sockets/sockets-config.h deleted file mode 100644 index 9df8cee..0000000 --- a/Sockets/sockets-config.h +++ /dev/null @@ -1,97 +0,0 @@ -/** - ** \file sockets-config.h - ** \date 2007-04-14 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2007 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifndef _SOCKETS_CONFIG_H -#define _SOCKETS_CONFIG_H - -#ifndef _RUN_DP -/* First undefine symbols if already defined. */ -#undef HAVE_OPENSSL -#undef ENABLE_IPV6 -#undef USE_SCTP -#undef NO_GETADDRINFO -#undef ENABLE_POOL -#undef ENABLE_SOCKS4 -#undef ENABLE_RESOLVER -#undef ENABLE_RECONNECT -#undef ENABLE_DETACH -#undef ENABLE_TRIGGERS -#undef ENABLE_EXCEPTIONS -#endif // _RUN_DP - - -/* OpenSSL support. */ -//#define HAVE_OPENSSL - - -/* Ipv6 support. */ -//#define ENABLE_IPV6 - - -/* SCTP support. */ -//#define USE_SCTP - - -/* Define NO_GETADDRINFO if your operating system does not support - the "getaddrinfo" and "getnameinfo" function calls. */ -#define NO_GETADDRINFO - - -/* Connection pool support. */ -//#define ENABLE_POOL - - -/* Socks4 client support. */ -//#define ENABLE_SOCKS4 - - -/* Asynchronous resolver. */ -#define ENABLE_RESOLVER - - -/* Enable TCP reconnect on lost connection. - Socket::OnReconnect - Socket::OnDisconnect -*/ -#define ENABLE_RECONNECT - - -/* Enable socket thread detach functionality. */ -#define ENABLE_DETACH - - -/* Enable socket to socket triggers. Not yet in use. */ -//#define ENABLE_TRIGGERS - - -/* Enabled exceptions. */ -#define ENABLE_EXCEPTIONS - - -/* Resolver uses the detach function so either enable both or disable both. */ -#ifndef ENABLE_DETACH -#undef ENABLE_RESOLVER -#endif - - -#endif // _SOCKETS_CONFIG_H - diff --git a/Sockets/tests/Makefile b/Sockets/tests/Makefile deleted file mode 100644 index 0bbabf8..0000000 --- a/Sockets/tests/Makefile +++ /dev/null @@ -1,73 +0,0 @@ -SOCKETS = .. -PLATFORM = linux-x86-32 -LIBS = -L$(SOCKETS) -lSockets - -INCLUDE = -I$(SOCKETS) -include $(SOCKETS)/Makefile.version -include $(SOCKETS)/Makefile.Defines.$(PLATFORM) - -CPPFLAGS = $(CFLAGS) - -#LIBS += -lsctp - -PROGS = events resolve sockets_test base64 semtest \ - echoserver stressclient http httpd retry resume \ - http_post x copy crlf https sloppy_http - -all: $(PROGS) - -events: events.o - $(CXX) -o $@ $^ $(LIBS) - -resolve: resolve.o - $(CXX) -o $@ $^ $(LIBS) - -sockets_test: sockets_test.o - $(CXX) -o $@ $^ $(LIBS) - -base64: base64.o - $(CXX) -o $@ $^ $(LIBS) - -semtest: semtest.o - $(CXX) -o $@ $^ $(LIBS) - -echoserver: echoserver.o - $(CXX) -o $@ $^ $(LIBS) - -stressclient: stressclient.o - $(CXX) -o $@ $^ $(LIBS) - -http: http.o - $(CXX) -o $@ $^ $(LIBS) - -httpd: httpd.o - $(CXX) -o $@ $^ $(LIBS) - -retry: retry.o - $(CXX) -o $@ $^ $(LIBS) - -resume: resume.o - $(CXX) -o $@ $^ $(LIBS) - -http_post: http_post.o - $(CXX) -o $@ $^ $(LIBS) - -x: x.o - $(CXX) -o $@ $^ $(LIBS) - -copy: copy.o - $(CXX) -o $@ $^ $(LIBS) - -crlf: crlf.o - $(CXX) -o $@ $^ $(LIBS) - -https: https.o - $(CXX) -o $@ $^ $(LIBS) - -sloppy_http: sloppy_http.o - $(CXX) -o $@ $^ $(LIBS) - -clean: - rm -f *.o *~ slask *.d $(PROGS) - --include *.d diff --git a/Sockets/tests/base64.cpp b/Sockets/tests/base64.cpp deleted file mode 100644 index 722439d..0000000 --- a/Sockets/tests/base64.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include - -#include "Base64.h" - - -int main(int argc,char *argv[]) -{ - if (argc < 2) - return -1; - std::string str; - std::string str2; - Base64 b; - if (!strcmp(argv[1],"-file")) - { - if (argc < 3) - return -2; - FILE *fil; - if ((fil = fopen(argv[2],"rt")) != NULL) - { - b.encode(fil, str); - fclose(fil); - } - printf("File:\n%s\n--End of File\n",str.c_str()); - b.decode(str, str2); - printf("Content:\n%s\n--End of Content\n",str2.c_str()); - } - else - { - b.encode(argv[1], strlen(argv[1]), str); - printf("'%s' ==> '%s'",argv[1], str.c_str()); - b.decode(str, str2); - printf(" ==> '%s'\n",str2.c_str()); - } -} diff --git a/Sockets/tests/copy.cpp b/Sockets/tests/copy.cpp deleted file mode 100644 index 2134ac2..0000000 --- a/Sockets/tests/copy.cpp +++ /dev/null @@ -1,264 +0,0 @@ -#include -#include -#include -#include - -#define BUFSZ 7024 - -#ifdef _WIN32 -#define MIN(a,b) (a 0 && GetOutputLength() < lim) - { - SendBuf(buf, n); - m_sz -= n; - n = MIN(m_sz, BUFSZ); - } - if (!n) - { - SetCloseAndDelete(); - } - else - { - SendBuf(buf, n); - m_sz -= n; - } - return; - } - size_t x = 0; - for (size_t i = 0; i < m_filename.size(); i++) - if (m_filename[i] == '/') - x = i + 1; - Send(m_filename.substr(x) + "\n"); - m_fil = fopen(m_filename.c_str(), "rb"); - if (m_fil) - { - char buf[BUFSZ]; - int n = fread(buf, 1, BUFSZ, m_fil); - while (n > 0 && GetOutputLength() < lim) - { - SendBuf(buf, n); - n = fread(buf, 1, BUFSZ, m_fil); - } - if (!n) - { - SetCloseAndDelete(); - fclose(m_fil); - m_fil = NULL; - } - else - { - SendBuf(buf, n); - } - } - } - - void OnWriteComplete() { - } - - void OnTransferLimit() { - if (!m_filename.size()) - { - char buf[BUFSZ]; - int n = MIN(m_sz, BUFSZ); - while (n > 0 && GetOutputLength() < lim) - { - SendBuf(buf, n); - m_sz -= n; - n = MIN(m_sz, BUFSZ); - } - if (!n) - { - SetCloseAndDelete(); - } - else - { - SendBuf(buf, n); - m_sz -= n; - } - return; - } - if (m_fil) - { - char buf[BUFSZ]; - int n = fread(buf, 1, BUFSZ, m_fil); - while (n > 0 && GetOutputLength() < lim) - { - SendBuf(buf, n); - n = fread(buf, 1, BUFSZ, m_fil); - } - if (!n) - { - SetCloseAndDelete(); - fclose(m_fil); - m_fil = NULL; - } - else - { - SendBuf(buf, n); - } - } - } - - void OnAccept() { - Utility::GetTime(&m_start); - m_b_server = true; - SetLineProtocol(); - DisableInputBuffer(); - } - - void OnLine(const std::string& line) { - if (line.size()) - m_out = fopen(line.c_str(), "wb"); - SetLineProtocol(false); - DisableInputBuffer(); - } - - void OnDelete() { - struct timeval stop; - Utility::GetTime(&stop); - stop.tv_sec -= m_start.tv_sec; - stop.tv_usec -= m_start.tv_usec; - if (stop.tv_usec < 0) - { - stop.tv_usec += 1000000; - stop.tv_sec -= 1; - } - double t = stop.tv_usec; - t /= 1000000; - t += stop.tv_sec; - printf("OnDelete: %s\n", m_b_server ? "SERVER" : "CLIENT"); - printf(" Time: %ld.%06ld (%f)\n", stop.tv_sec, stop.tv_usec, t); - double r = GetBytesReceived(); - printf(" bytes in: %lld (%f Mbytes/sec)\n", GetBytesReceived(), r / t / 1000000); - double s = GetBytesSent(); - printf(" bytes out: %lld (%f Mbytes/sec)\n", GetBytesSent(), s / t / 1000000); - printf("\n"); - if (m_out) - fclose(m_out); - } - - void OnRawData(const char *buf, size_t len) { - if (m_out) - fwrite(buf, 1, len, m_out); - } - -private: - std::string m_filename; - FILE *m_fil; - FILE *m_out; - bool m_b_server; - struct timeval m_start; - size_t m_sz; -}; - - -int main(int argc, char *argv[]) -{ - std::string host = "127.0.0.1"; - int port = 12344; - std::list filenames; - - for (int i = 1; i < argc; i++) - { - if (!strcmp(argv[i], "-host") && i < argc - 1) - host = argv[++i]; - else - if (!strcmp(argv[i], "-port") && i < argc - 1) - port = atoi(argv[++i]); - else - if (!strcmp(argv[i], "-h")) - { - fprintf(stderr, "Usage: %s [-host ] [-port ] []\n", *argv); - fprintf(stderr, " Will run as host only if isn't specified.\n"); - fprintf(stderr, " host default: 127.0.0.1\n"); - fprintf(stderr, " port default: 12344\n"); - return 0; - } - else - { - filenames.push_back( argv[i] ); - } - } - - try - { - SocketHandler h; - ListenSocket l(h); - if (filenames.empty()) - { - if (l.Bind( port ) != 0) - { - fprintf(stderr, "Bind() port %d failed - exiting\n", port); - return -1; - } - h.Add(&l); - } - for (std::list::iterator it = filenames.begin(); it != filenames.end(); it++) - { - std::string filename = *it; - size_t sz = atol(filename.c_str()); - if (sz) - { - CopySocket *sock = new CopySocket(h, sz); - sock -> SetDeleteByHandler(); - sock -> Open(host, port); - h.Add(sock); - } - else - { - CopySocket *sock = new CopySocket(h, filename); - sock -> SetDeleteByHandler(); - sock -> Open(host, port); - h.Add(sock); - } - } - if (!filenames.size()) - { - fprintf(stderr, "Starting as server only, listening on port %d\n", port); - quit++; - } - while (quit > 0) - { - h.Select(5, 0); - } - return 0; - } - catch (const Exception& e) - { - printf("%s\n", e.ToString().c_str()); - } -} - - diff --git a/Sockets/tests/crlf.cpp b/Sockets/tests/crlf.cpp deleted file mode 100644 index 34500c4..0000000 --- a/Sockets/tests/crlf.cpp +++ /dev/null @@ -1,139 +0,0 @@ -#include -#include -#include - - -static bool quit = false; - - -class IOSocket : public TcpSocket -{ -public: - IOSocket(ISocketHandler& h) : TcpSocket(h) { - SetLineProtocol(); - } - ~IOSocket() {} - - void OnConnect() { - Utility::GetTime(&m_start); - while (GetOutputLength() < 500000) - { - Send("zzzzzzzzzmmmmmmmmm1234lkkk54\r\n"); - Send("zzzzzzzzzmmmmmmmmm1234lkkk543\r\n"); - Send("zzzzzzzzzmmmmmmmmm1234lkkk54\r\n"); - Send("zzzzzzzzzmmmmmmmmm1234lkkk543\r\n"); - Send("zzzzzzzzzmmmmmmmmm1234lkkk54\r\n"); - Send("zzzzzzzzzmmmmmmmmm1234lkkk543\r\n"); - Send("zzzzzzzzzmmmmmmmmm1234lkkk54\r\n"); - Send("zzzzzzzzzmmmmmmmmm1234lkkk543\r\n"); - } -// Send("\r\n"); - } - - void OnAccept() { - SetLineProtocol(); - } - - void OnDelete() { - printf("OnDelete\n"); - } - - void OnWriteComplete() { -printf("OnWriteComplete\n"); - struct timeval tv; - Utility::GetTime(&tv); - - tv.tv_sec -= m_start.tv_sec; - tv.tv_usec -= m_start.tv_usec; - Utility::GetTime(&m_start); - if (tv.tv_usec < 0) - { - tv.tv_usec += 1000000; - tv.tv_sec -= 1; - } - double t = tv.tv_usec; - t /= 1000000; - t += tv.tv_sec; - printf(" Time: %ld.%06ld (%f)\n", tv.tv_sec, tv.tv_usec, t); - double r = GetBytesReceived(); - printf(" bytes in: %lld (%f Mbytes/sec)\n", GetBytesReceived(true), r / t / 1000000); - double s = GetBytesSent(); - printf(" bytes out: %lld (%f Mbytes/sec)\n", GetBytesSent(true), s / t / 1000000); - printf("\n"); - - while (GetOutputLength() < 500000) - { - Send("zzzzzzzzzmmmmmmmmm1234lkkk54\r\n"); - Send("zzzzzzzzzmmmmmmmmm1234lkkk543\r\n"); - Send("zzzzzzzzzmmmmmmmmm1234lkkk54\r\n"); - Send("zzzzzzzzzmmmmmmmmm1234lkkk543\r\n"); - Send("zzzzzzzzzmmmmmmmmm1234lkkk54\r\n"); - Send("zzzzzzzzzmmmmmmmmm1234lkkk543\r\n"); - Send("zzzzzzzzzmmmmmmmmm1234lkkk54\r\n"); - Send("zzzzzzzzzmmmmmmmmm1234lkkk543\r\n"); - } -// Send("\r\n"); - } - - void OnLine(const std::string& line) { - if (line == "") - { - struct timeval tv; - Utility::GetTime(&tv); - - tv.tv_sec -= m_start.tv_sec; - tv.tv_usec -= m_start.tv_usec; - Utility::GetTime(&m_start); - if (tv.tv_usec < 0) - { - tv.tv_usec += 1000000; - tv.tv_sec -= 1; - } - double t = tv.tv_usec; - t /= 1000000; - t += tv.tv_sec; - printf(" Time: %ld.%06ld (%f)\n", tv.tv_sec, tv.tv_usec, t); - double r = GetBytesReceived(); - printf(" bytes in: %lld (%f Mbytes/sec)\n", GetBytesReceived(true), r / t / 1000000); - double s = GetBytesSent(); - printf(" bytes out: %lld (%f Mbytes/sec)\n", GetBytesSent(true), s / t / 1000000); - printf("\n"); - - } - else - if (line != "zzzzzzzzzmmmmmmmmm1234lkkk54" && - line != "zzzzzzzzzmmmmmmmmm1234lkkk543") - { -printf("\n-------------------------------------------------------\n"); - for (size_t i = 0; i < line.size(); i++) - if (!isprint(line[i])) - printf("<%d>", line[i]); - else - printf("%c", line[i]); - printf("\n"); -fflush(stdout); -exit(-1); - quit = true; - } - } - - struct timeval m_start; -}; - - -int main(int argc, char *argv[]) -{ - SocketHandler h; - ListenSocket l(h); - l.Bind(12344); - h.Add(&l); - IOSocket sock(h); - sock.Open("192.168.7.4", 12344); - h.Add(&sock); - while (!quit) - { - h.Select(1, 0); - } -} - - diff --git a/Sockets/tests/echoserver.cpp b/Sockets/tests/echoserver.cpp deleted file mode 100644 index 45cb6c2..0000000 --- a/Sockets/tests/echoserver.cpp +++ /dev/null @@ -1,237 +0,0 @@ -/** - ** \file echoserver.cpp - ** \date 2006-10-02 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2006 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _WIN32 -#pragma warning(disable:4786) -#endif -#include -#include -#include -#include -#ifndef _WIN32 -#include -#endif -#include - - -#ifdef ENABLE_DETACH -static bool g_b_detach = false; -#endif -#ifdef HAVE_OPENSSL -static bool g_b_ssl = false; -#endif -static std::string gFilename = "server.pem"; -static std::string gPw; -static bool quit = false; -static bool g_b_http = false; -static bool g_b_nobuf = false; -#ifdef ENABLE_DETACH -static bool g_b_detach2 = false; -#endif - -#define DEB(x) - - -class MySocket : public TcpSocket -{ -public: - MySocket(ISocketHandler& h) : TcpSocket(h) { - SetLineProtocol(); -#ifdef HAVE_OPENSSL - if (g_b_ssl) - EnableSSL(); -#endif - if (g_b_nobuf) - DisableInputBuffer(); - } - ~MySocket() { - } - - void OnAccept() { -#ifdef ENABLE_DETACH - if (g_b_detach) - { - if (!Detach()) - fprintf(stderr, "\nDetach failed\n"); - } -#endif - } - - void OnRawData(const char *buf,size_t len) { - if (g_b_nobuf) - { - SendBuf(buf, len); - } - } - - void OnLine(const std::string& line) { -#ifdef ENABLE_DETACH - if (g_b_detach2 && !IsDetach()) - { - m_line = line; - if (!Detach()) - { - fprintf(stderr, "\nDetach failed\n"); - } - return; - } -DEB(printf("fd %d OnLine; %s\n", GetSocket(), Handler().IsSlave() ? "slave" : "master");) -#endif - Send(line + "\n"); - } - - void OnDetached() { -DEB(printf("fd %d OnDetached; %s\n", GetSocket(), Handler().IsSlave() ? "slave" : "master");) -// fprintf(stderr, "-"); -// fflush(stderr); -#ifdef ENABLE_DETACH - if (g_b_detach2) - { - Send(m_line + "\n"); - } -#endif - } - -#ifdef HAVE_OPENSSL - void InitSSLServer() { - InitializeContext("echoserver", gFilename, gPw, SSLv23_method()); - } -#endif - -private: - std::string m_line; -}; - - -#ifndef _WIN32 -void sigint(int) -{ - quit = true; -} -#endif - -int main(int argc,char *argv[]) -{ -#ifndef _WIN32 - signal(SIGPIPE, SIG_IGN); - signal(SIGINT, sigint); -#endif - port_t port = 2222; - bool enableLog = false; - int queue = 20; - for (int i = 1; i < argc; i++) - { -#ifdef ENABLE_DETACH - if (!strcmp(argv[i], "-detach")) - g_b_detach = true; - if (!strcmp(argv[i], "-detach2")) - g_b_detach2 = true; -#endif -#ifdef HAVE_OPENSSL - if (!strcmp(argv[i], "-ssl")) - g_b_ssl = true; - if (!strcmp(argv[i], "-file") && i < argc - 1) - gFilename = argv[++i]; -#endif - if (!strcmp(argv[i], "-port") && i < argc - 1) - port = atoi(argv[++i]); - if (!strcmp(argv[i], "-pw") && i < argc - 1) - gPw = argv[++i]; - if (!strcmp(argv[i], "-log")) - enableLog = true; - if (!strcmp(argv[i], "-queue") && i < argc - 1) - queue = atoi(argv[++i]); - if (!strcmp(argv[i], "-http")) - g_b_http = true; - if (!strcmp(argv[i], "-nobuf")) - g_b_nobuf = true; - if (!strcmp(argv[i], "-h")) - { - printf("Usage: %s [ options ] [-ssl]\n", *argv); - printf(" -port nn listen on port nn\n"); -#ifdef ENABLE_DETACH - printf(" -detach detach each socket on accept\n"); - printf(" -detach2 detach when line received\n"); -#endif -#ifdef HAVE_OPENSSL - printf(" -ssl run as ssl server, .pem file needed\n"); - printf(" -file xx .pem filename, default is \"server.pem\"\n"); -#endif - printf(" -pw xx private key password\n"); - printf(" -log enable sockethandler debug log\n"); - printf(" -queue nn listen queue size (default 20)\n"); - printf(" -http enable http server with dummy response\n"); - printf(" -nobuf echo raw data\n"); - exit(-1); - } - } - if (g_b_http && g_b_nobuf) - { - printf("Nobuf and Http does not work together\n"); - exit(-1); - } - StdoutLog *log = enableLog ? new StdoutLog() : NULL; - SocketHandler h(log); - ListenSocket l(h); - ListenSocket l2(h); - if (!g_b_http) - { - if (l.Bind(port, queue)) - { - fprintf(stderr, "Bind to port %d failed\n", port); - return -1; - } - fprintf(stderr, "Listening on port %d\n", port); - h.Add(&l); - } - else - { - printf("Enable HttpDebugSocket\n"); - if (l2.Bind(port, queue)) - { - fprintf(stderr, "Bind to port %d failed\n", port); - return -1; - } - fprintf(stderr, "Listening on port %d\n", port); - h.Add(&l2); - } -#ifdef ENABLE_DETACH - if (g_b_detach) - fprintf(stderr, "Will detach each incoming socket\n"); -#endif -#ifdef HAVE_OPENSSL - if (g_b_ssl) - fprintf(stderr, "Using SSL\n"); -#endif - while (!quit) - { - h.Select(1, 0); - } - fprintf(stderr, "\nExiting...\n"); - if (log) - { -// delete log; - } - return 0; -} - - diff --git a/Sockets/tests/events.cpp b/Sockets/tests/events.cpp deleted file mode 100644 index 5d08973..0000000 --- a/Sockets/tests/events.cpp +++ /dev/null @@ -1,212 +0,0 @@ -#include -#include -#include -#include -#include -#include - - -double start; - -double gettime() -{ - struct timeval tv; - Utility::GetTime(&tv); - return tv.tv_sec + (double)tv.tv_usec / 1000000; -} - - -class MyEvHandler : public EventHandler -{ -public: - MyEvHandler() : EventHandler() {} - MyEvHandler(StdLog *p) : EventHandler(p) {} - -}; - - -class EvThread : public Thread -{ -public: - EvThread(Socket *p) : m_socket(p) {} - - void Run(); - -private: - Socket *m_socket; -}; - - -class EvSocket : public TcpSocket, public IEventOwner -{ -public: - EvSocket(ISocketHandler& h) : TcpSocket(h) - , IEventOwner( static_cast(h) ) { - } - - void OnEvent(int id) { - std::cout << "OnEvent" << std::endl; - std::cout << gettime() - start << std::endl; - SetCloseAndDelete(); - } - - void OnAccept() { - std::cout << "Incoming" << std::endl; - } - - void OnConnect() { - std::cout << "Connected" << std::endl; - EvThread *thr = new EvThread( this ); - thr -> SetDeleteOnExit(); - } - - void OnDelete() { - std::cout << "EvSocket::OnDelete()" << std::endl; - } -}; - - -void EvThread::Run() -{ - Socket *p0 = (Socket *)m_socket; - EvSocket *p = dynamic_cast(p0); - if (p) - { -#ifdef _WIN32 - Sleep( 5000 ); -#else - sleep(10); -#endif - std::cout << "Add event" << std::endl; - start = gettime(); - p -> AddEvent(1, 50000); - } - else - { - std::cout << "Thread: not an EvSocket" << std::endl; - } -} - - -//------------------------------------------------------------ -// myTimer class -//------------------------------------------------------------ -class myTimer : public IEventOwner -{ -public: - // Prototype of user call back function - typedef void (*myTimer_cb)(myTimer* user_func, void* user_id); - - myTimer(IEventHandler& h, long ssec, long susec, - long psec, long pusec, myTimer_cb func, void* id); - ~myTimer(); - -private: - void OnEvent(int id); - long ssec_; - long susec_; - long psec_; - long pusec_; - myTimer_cb user_func_; - void* user_id_; - bool periodic_; -}; - - -//------------------------------------------------------------ -myTimer::myTimer(IEventHandler& h, long ssec, long susec, - long psec, long pusec, myTimer_cb user_func, - void* user_id) : - IEventOwner(h), - ssec_(ssec), - susec_(susec), - psec_(psec), - pusec_(pusec), - user_func_(user_func), - user_id_(user_id), - periodic_(psec != 0 || pusec != 0) -{ - AddEvent(ssec_, susec_); -} - - -//------------------------------------------------------------ -myTimer::~myTimer() -{ - ClearEvents(); -} - - -//------------------------------------------------------------ -void myTimer::OnEvent(int id) -{ - if (periodic_) - { - int n = AddEvent(psec_, pusec_); - } - - user_func_(this, user_id_); - - if (!periodic_) - { - delete this; - } -} - - -//------------------------------------------------------------ -static void myfunc(myTimer* t, void* user_id) -{ - printf("Event %s\n", (char*)user_id); -} - - -/* -int main(int argc, char *argv[]) -{ - EventHandler h; - - // Example 1: Create a 2 sec one-shot timer. - // No need to save the pointer as it will delete - // itself upon expiry. - new myTimer(h, 2, 0, 0, 0, myfunc, (void*)"My Timer 0"); - - // Example 2: Create a 1 sec periodic timer. - // Save the pointer because we can stop the timer - // later with a "delete mytimer". - myTimer* mytimer = new myTimer(h, 0, 0, 1, 0, myfunc, - (void*)"My Timer 1"); - - // Drop into the event handler .. - h.EventLoop(); -} -*/ - - -int main(int argc, char *argv[]) -{ - StdoutLog log; - MyEvHandler h(&log); - ListenSocket l(h); - l.Bind("localhost", 12344); - h.Add(&l); - - EvSocket sock(h); - sock.Open("localhost", 12344); - h.Add(&sock); - - // Example 1: Create a 2 sec one-shot timer. - // No need to save the pointer as it will delete - // itself upon expiry. - new myTimer(h, 2, 0, 0, 0, myfunc, (void*)"My Timer 0"); - - // Example 2: Create a 1 sec periodic timer. - // Save the pointer because we can stop the timer - // later with a "delete mytimer". - myTimer* mytimer = new myTimer(h, 0, 0, 1, 0, myfunc, - (void*)"My Timer 1"); - - h.EventLoop(); -} - - diff --git a/Sockets/tests/http.cpp b/Sockets/tests/http.cpp deleted file mode 100644 index 6800699..0000000 --- a/Sockets/tests/http.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include -#include - - -class tSocket : public HTTPSocket -{ -public: - tSocket(ISocketHandler& h, const std::string& host) : HTTPSocket(h), m_host(host) - , m_first(false) - , m_sz(0) { - Open(host, 80); - } - - void OnConnect() { - Send("GET /index.html HTTP/1.0\r\n"); - Send("Host: " + m_host + "\r\n"); - Send("\r\n"); - } - - void OnFirst() { - } - - void OnHeader(const std::string& key, const std::string& value) { - fprintf(stderr, "%s: %s\n", key.c_str(), value.c_str()); - } - - void OnHeaderComplete() { - fprintf(stderr, "\n"); - } - - void OnData(const char *buf, size_t sz) { - if (1||!m_first) - { - std::string str = buf; - str.resize( sz ); - printf("%s", str.c_str()); - m_first = true; - } - m_sz += sz; - } - - void OnDelete() { - fprintf(stderr, "Content length: %d\n", m_sz); - } - -private: - std::string m_host; - bool m_first; - size_t m_sz; -}; - - -int main(int argc, char *argv[]) -{ - std::string host = argc > 1 ? argv[1] : "www.alhem.net"; - SocketHandler h; - tSocket sock(h, host); - h.Add(&sock); - while (h.GetCount()) - { - h.Select(1, 0); - } -} - - diff --git a/Sockets/tests/http_post.cpp b/Sockets/tests/http_post.cpp deleted file mode 100644 index 3b0b830..0000000 --- a/Sockets/tests/http_post.cpp +++ /dev/null @@ -1,107 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - - -class sSocket : public HttpdSocket -{ -public: - sSocket(ISocketHandler& h) : HttpdSocket(h) { - } - - void Init() - { - if (GetParent() -> GetPort() == 443 || GetParent() -> GetPort() == 8443) - { -#ifdef HAVE_OPENSSL - EnableSSL(); -#else - fprintf(stderr, "SSL not available\n"); -#endif - } - } - - void Exec() - { - std::string name; - std::string value; - GetForm() -> getfirst(name, value); - while (name.size()) - { -fprintf(stderr, "%s: '%s'\n", name.c_str(), value.c_str()); - GetForm() -> getnext(name, value); - } - CreateHeader(); - GenerateDocument(); - } - - void CreateHeader() - { - SetStatus("200"); - SetStatusText("OK"); -fprintf(stderr, "Uri: '%s'\n", GetUri().c_str()); - { - size_t x = 0; - for (size_t i = 0; i < GetUri().size(); i++) - if (GetUri()[i] == '.') - x = i; - std::string ext = GetUri().substr(x + 1); - if (ext == "gif" || ext == "jpg" || ext == "png") - AddResponseHeader("Content-type", "image/" + ext); - else - AddResponseHeader("Content-type", "text/" + ext); - } - AddResponseHeader("Connection", "close"); - SendResponse(); - } - - void GenerateDocument() - { - Send(""); - SetCloseAndDelete(); - } - -#ifdef HAVE_OPENSSL - void InitSSLServer() - { - InitializeContext("httpd", "comb.pem", "", SSLv23_method()); - } -#endif - -}; - - -int main(int argc, char *argv[]) -{ - std::string host = argc > 1 ? argv[1] : "www.alhem.net"; - StdoutLog log; - SocketHandler h(&log); - ListenSocket l(h); - if (l.Bind(1028)) - { - printf("Bind port 1028 failed\n"); - return -1; - } - h.Add(&l); - ListenSocket l2(h); - if (l2.Bind(8443)) - { - printf("Bind port 8443 failed\n"); - return -1; - } - h.Add(&l2); - HttpPostSocket sock(h, "http://localhost:1028/postdata"); - sock.AddField("name", "value"); - sock.Open(); - h.Add(&sock); - while (h.GetCount()) - { - h.Select(1, 0); - } -} - - diff --git a/Sockets/tests/httpd.cpp b/Sockets/tests/httpd.cpp deleted file mode 100644 index e1106a0..0000000 --- a/Sockets/tests/httpd.cpp +++ /dev/null @@ -1,109 +0,0 @@ -#include -#include -#include -#include - - -class sSocket : public HttpdSocket -{ -public: - sSocket(ISocketHandler& h) : HttpdSocket(h) { - } - - void Init() - { - if (GetParent() -> GetPort() == 443 || GetParent() -> GetPort() == 8443) - { -#ifdef HAVE_OPENSSL - EnableSSL(); -#else - fprintf(stderr, "SSL not available\n"); -#endif - } - } - - void Exec() - { - CreateHeader(); - GenerateDocument(); - } - - void CreateHeader() - { - SetStatus("200"); - SetStatusText("OK"); -fprintf(stderr, "Uri: '%s'\n", GetUri().c_str()); - { - size_t x = 0; - for (size_t i = 0; i < GetUri().size(); i++) - if (GetUri()[i] == '.') - x = i; - std::string ext = GetUri().substr(x + 1); - if (ext == "gif" || ext == "jpg" || ext == "png") - AddResponseHeader("Content-type", "image/" + ext); - else - AddResponseHeader("Content-type", "text/" + ext); - } - AddResponseHeader("Connection", "close"); - SendResponse(); - } - - void GenerateDocument() - { - std::string fn = GetUri().substr(1); - FILE *fil = fopen(fn.c_str(), "rb"); - if (fil) - { - char slask[1000]; - int n = fread(slask,1,1000,fil); - while (n > 0) - { - SendBuf(slask, n); - n = fread(slask,1,1000,fil); - } - fclose(fil); - } - else - { - SetStatus("404"); - SetStatusText("Not Found"); - } - SetCloseAndDelete(); - } - -#ifdef HAVE_OPENSSL - void InitSSLServer() - { - InitializeContext("httpd", "comb.pem", "", SSLv23_method()); - } -#endif - -}; - - -int main(int argc, char *argv[]) -{ - std::string host = argc > 1 ? argv[1] : "www.alhem.net"; - StdoutLog log; - SocketHandler h(&log); - ListenSocket l(h); - if (l.Bind(1028)) - { - printf("Bind port 1028 failed\n"); - return -1; - } - h.Add(&l); - ListenSocket l2(h); - if (l2.Bind(8443)) - { - printf("Bind port 8443 failed\n"); - return -1; - } - h.Add(&l2); - while (h.GetCount()) - { - h.Select(1, 0); - } -} - - diff --git a/Sockets/tests/https.cpp b/Sockets/tests/https.cpp deleted file mode 100644 index 45b36ff..0000000 --- a/Sockets/tests/https.cpp +++ /dev/null @@ -1,113 +0,0 @@ -#include -#include -#include -#include - - -class tSocket : public HTTPSocket -{ -public: - tSocket(ISocketHandler& h) : HTTPSocket(h) - , m_first(false) - , m_sz(0) { - EnableSSL(); - } - - tSocket(ISocketHandler& h, const std::string& host) : HTTPSocket(h), m_host(host) - , m_first(false) - , m_sz(0) { - EnableSSL(); - Open(host, 4443); - } - - void InitSSLServer() { - InitializeContext("", "comb.pem", "", SSLv23_method()); - } - - void OnSSLAccept() { - printf("OnSSLAccept()\n"); - HTTPSocket::OnSSLAccept(); - } - - void OnSSLConnect() { - printf("OnSSLConnect()\n"); - HTTPSocket::OnSSLConnect(); - } - - void OnAccept() { -printf("OnAccept\n"); - } - - void OnConnect() { -printf("OnConnect\n"); - Send("GET /index.html HTTP/1.0\r\n"); - Send("Host: " + m_host + "\r\n"); - Send("\r\n"); - } - - void OnFirst() { - } - - void OnHeader(const std::string& key, const std::string& value) { - fprintf(stderr, "%s: %s\n", key.c_str(), value.c_str()); - } - - void OnHeaderComplete() { - fprintf(stderr, "\n"); - } - - void OnData(const char *buf, size_t sz) { - if (1||!m_first) - { - std::string str = buf; - str.resize( sz ); - printf("%s", str.c_str()); - m_first = true; - } - m_sz += sz; - } - - void OnDelete() { - fprintf(stderr, "Content length: %d\n", m_sz); - } - -private: - std::string m_host; - bool m_first; - size_t m_sz; -}; - - -int main(int argc, char *argv[]) -{ - try - { - SocketHandler h; - if (argc > 1 && !strcmp(argv[1], "-server")) - { - ListenSocket l(h); - l.Bind(4443); - h.Add(&l); - while (h.GetCount()) - { - h.Select(1, 0); - } - } - else - { - std::string host = argc > 1 ? argv[1] : "www.alhem.net"; - tSocket sock(h, host); - h.Add(&sock); - while (h.GetCount()) - { - h.Select(1, 0); - } - } - } - catch (const Exception& e) - { - printf("%s\n", e.ToString().c_str()); - } -} - - diff --git a/Sockets/tests/resolve.cpp b/Sockets/tests/resolve.cpp deleted file mode 100644 index 802b910..0000000 --- a/Sockets/tests/resolve.cpp +++ /dev/null @@ -1,156 +0,0 @@ -#include -#ifndef _WIN32 -#include -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include - - -int main(int argc, char *argv[]) -{ - StdoutLog log; - SocketHandler h(&log); -/* - h.EnableResolver(9999); - -// printf("Waiting for resolver ..."); - while (!h.ResolverReady()) - ; -// printf(" resolver ready!\n"); -*/ - std::string hostname = argc < 2 ? "www.ipv6.org" : argv[1]; - - { - printf("Using hostname : %s\n", hostname.c_str()); - printf("------------------------------------------- normal (old) Utility::u2ip\n"); - ipaddr_t oa; - if (!Utility::u2ip(hostname, oa)) - printf("Ipv4 lookup failed\n"); -#ifdef ENABLE_IPV6 - in6_addr oa6; - if (!Utility::u2ip(hostname, oa6)) - printf("Ipv6 lookup failed\n"); -#endif - std::string oname; - Utility::l2ip(oa, oname); - printf("Ipv4 : %s (old)\n", oname.c_str()); - -#ifdef ENABLE_IPV6 - std::string oname6; - Utility::l2ip(oa6, oname6); - printf("Ipv6 : %s (old)\n", oname6.c_str()); -#endif - - printf("------------------------------------------- new Utility::u2ip, Utility::reverse\n"); - struct sockaddr_in sa; - if (!Utility::u2ip(hostname, sa)) - printf("Ipv4 lookup failed\n"); - - ipaddr_t a; - memcpy(&a, &sa.sin_addr, sizeof(a)); - std::string l2ipname; - Utility::l2ip(a, l2ipname); - printf("Ipv4 : %s\n", l2ipname.c_str()); - - std::string numeric; - Utility::reverse((struct sockaddr *)&sa, sizeof(sa), numeric, NI_NUMERICHOST); - printf("Ipv4 numeric : %s\n", numeric.c_str()); - - std::string rname; - if (!Utility::reverse( (struct sockaddr *)&sa, sizeof(sa), rname)) - printf("Reverse Ipv4 failed\n"); - else - printf("Ipv4 Utility::reverse : %s\n", rname.c_str()); - -#ifdef ENABLE_IPV6 - printf("------------------------------------------- new Utility::u2ip, Utility::reverse (Ipv6)\n"); - struct sockaddr_in6 sa6; - if (!Utility::u2ip(hostname, sa6)) - printf("Ipv6 lookup failed\n"); - - std::string l2ipname6; - Utility::l2ip(sa6.sin6_addr, l2ipname6); - printf("Ipv6 : %s\n", l2ipname6.c_str()); - - std::string numeric6; - Utility::reverse((struct sockaddr *)&sa6, sizeof(sa6), numeric6, NI_NUMERICHOST); - printf("Ipv6 numeric : %s\n", numeric6.c_str()); - - std::string rname6; - if (!Utility::reverse( (struct sockaddr *)&sa6, sizeof(sa6), rname6)) - printf("Reverse Ipv6 failed\n"); - else - printf("Ipv6 Utility::reverse : %s\n", rname6.c_str()); -#endif - - printf("-------------------------------------------\n"); - in_addr ia; - /** Resolve hostname. */ -//static bool Resolve(const std::string& hostname,struct in_addr& a); - /** Reverse resolve (IP to hostname). */ -//static bool Reverse(struct in_addr& a,std::string& name); - /** Convert address struct to text. */ -//static std::string Convert(struct in_addr& a); - std::string name; - if (!Ipv4Address::Resolve(hostname, ia)) - printf("Ipv4 lookup failed (Ipv4Address)\n"); - memcpy(&a, &ia, sizeof(a)); - Utility::l2ip(a, name); - printf("Ipv4 : %s (Ipv4Address)\n", name.c_str()); - assert(name == l2ipname); - if (!Ipv4Address::Reverse(ia, name)) - printf("Reverse Ipv4 lookup failed (Ipv4Address)\n"); - else - printf("Reverse Ipv4 : %s\n", name.c_str()); - assert(name == rname); - assert(Ipv4Address::Convert(ia) == l2ipname); - -#ifdef ENABLE_IPV6 - printf("-------------------------------------------\n"); - /** Resolve hostname. */ -//static bool Resolve(const std::string& hostname,struct in6_addr& a); - /** Reverse resolve (IP to hostname). */ -//static bool Reverse(struct in6_addr& a,std::string& name); - /** Convert address struct to text. */ -//static std::string Convert(struct in6_addr& a,bool mixed = false); - if (!Ipv6Address::Resolve(hostname, oa6)) - printf("Ipv6 lookup failed (Ipv4Address)\n"); - Utility::l2ip(oa6, name); - assert(name == l2ipname6); - printf("Ipv6 : %s (Ipv6Address)\n", name.c_str()); - if (!Ipv6Address::Reverse(oa6, name)) - printf("Reverse Ipv6 lookup failed (Ipv4Address)\n"); - else - printf("Reverse Ipv6 : %s\n", name.c_str()); - assert(name == rname6); - std::string mixed_false = Ipv6Address::Convert(oa6, false); - std::string mixed_true = Ipv6Address::Convert(oa6, true); - printf("Ipv6Address::Convert(false) : %s\n", mixed_false.c_str()); - printf("Ipv6Address::Convert(true ) : %s\n", mixed_true.c_str()); - assert(mixed_false == l2ipname6); -#endif -/* - printf("-------------------------------------------\n"); - int protocol; - Utility::u2service("tcp", protocol); - printf("tcp: %d\n", protocol); - Utility::u2service("udp", protocol); - printf("udp: %d\n", protocol); - Utility::u2service("echo", protocol); - printf("echo: %d\n", protocol); -*/ - } - printf("\n"); - printf("OK\n"); - -// sleep(100); -} - - diff --git a/Sockets/tests/resume.cpp b/Sockets/tests/resume.cpp deleted file mode 100644 index e518109..0000000 --- a/Sockets/tests/resume.cpp +++ /dev/null @@ -1,111 +0,0 @@ -#include -#include -#include -#include -#include - - -class eHandler : public EventHandler -{ -public: - eHandler() : EventHandler() {} -}; - - -class eSocket : public TcpSocket, public IEventOwner -{ -public: - eSocket(ISocketHandler& h) : TcpSocket(h), IEventOwner(static_cast(h)), m_listen_socket(NULL), m_server(false) { - SetLineProtocol(); - } - - bool OnConnectRetry() { - printf("Retrying connect\n"); - if (GetConnectionRetries() == 5) - { - printf("Creating ListenSocket\n"); - m_listen_socket = new ListenSocket(Handler()); - if (m_listen_socket -> Bind(12345)) - { - printf("Bind port 12345 failed\n"); - } - m_listen_socket -> SetDeleteByHandler(); - Handler().Add( m_listen_socket ); - } - return true; - } - - void OnAccept() { - m_id_stop_socket = AddEvent(5, 0); -printf("Stop socket id: %d\n", m_id_stop_socket); - m_server = true; - } - - void OnConnect() { - m_id_stop_listen = AddEvent(10, 0); -printf("Stop listen id: %d\n", m_id_stop_listen); - } - - void OnEvent(int id) { -printf("Event id: %d\n", id); - if (id == m_id_stop_socket && m_server) - SetCloseAndDelete(); - if (id == m_id_stop_listen && !m_server) - m_listen_socket -> SetCloseAndDelete(); - } - - void OnLine(const std::string& line) { - printf("Incoming data: %s\n", line.c_str()); - } - - void OnDelete() { - printf("eSocket::OnDelete(), server: %s\n", m_server ? "true" : "false"); - } - - void OnDisconnect() { - printf("Disconnect, server: %s\n", m_server ? "true" : "false"); - } - -private: - ListenSocket *m_listen_socket; - int m_id_stop_socket; - int m_id_stop_listen; - bool m_server; -}; - - -class Sender : public IEventOwner -{ -public: - Sender(IEventHandler& h, TcpSocket& ref) : IEventOwner(h), m_socket(ref), m_count(1) { - AddEvent(1, 0); - } - - void OnEvent(int id) { - if (static_cast(EventHandler()).Valid(&m_socket)) - m_socket.Send("Event#" + Utility::l2string(m_count++) + "\n"); - EventHandler().AddEvent(this, 1, 0); - } - -private: - TcpSocket& m_socket; - int m_count; -}; - - -int main(int argc, char *argv[]) -{ - eHandler h; - eSocket sock(h); - sock.SetConnectTimeout(3); - sock.SetConnectionRetry(-1); -#ifdef ENABLE_RECONNECT - sock.SetReconnect(); -#endif - sock.Open("localhost", 12345); - h.Add( &sock ); - Sender send(h, sock); - h.AddEvent( &send, 1, 0 ); - h.EventLoop(); -} - diff --git a/Sockets/tests/retry.cpp b/Sockets/tests/retry.cpp deleted file mode 100644 index 36954a6..0000000 --- a/Sockets/tests/retry.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include -#include -#include - - - bool quit = false; - -/* - virtual bool OnConnectRetry(); -- void SetRetryClientConnect(bool x = true); -- bool RetryClientConnect(); - void SetConnectionRetry(int n); - int GetConnectionRetry(); - void IncreaseConnectionRetries(); - int GetConnectionRetries(); - void ResetConnectionRetries(); -*/ -class RetrySocket : public TcpSocket -{ -public: - RetrySocket(ISocketHandler& h) : TcpSocket(h) { - SetConnectTimeout(2); - SetConnectionRetry(-1); - } - - bool OnConnectRetry() { - printf("Connection attempt#%d\n", GetConnectionRetries()); - if (GetConnectionRetries() == 3) - { - ListenSocket *l = new ListenSocket(Handler()); - if (l -> Bind(12345)) - { - printf("Bind port 12345 failed\n"); - } - l -> SetDeleteByHandler(); - Handler().Add(l); - } - return true; - } - - void OnConnect() { - printf("Connected\n"); - printf("GetRemoteAddress(): %s\n", GetRemoteAddress().c_str()); - printf("Remote address: %s\n", GetRemoteSocketAddress() -> Convert(false).c_str()); - printf("Remote address: %s\n", GetRemoteSocketAddress() -> Convert(true).c_str()); - SetCloseAndDelete(); - } - - void OnDelete() { - quit = true; - } -}; - - -int main(int argc, char *argv[]) -{ - SocketHandler h; - RetrySocket sock(h); - sock.Open("localhost", 12345); - h.Add(&sock); - while (!quit) - { - h.Select(0, 200000); - } -} - - diff --git a/Sockets/tests/semtest.cpp b/Sockets/tests/semtest.cpp deleted file mode 100644 index 442d5d6..0000000 --- a/Sockets/tests/semtest.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include -#include -#ifndef _WIN32 -#include -#include -#include -#include -#include -#include - - -class MyThread : public Thread -{ -public: - void Run() { - printf("Thread\n"); - } -}; - - -class SemLock -{ -public: - SemLock(Semaphore& sem) : m_sem(sem) { - m_sem.Wait(); - } - ~SemLock() { - m_sem.Post(); - } - -private: - Semaphore& m_sem; -}; - - -/** - * Return time difference between two struct timeval's, in seconds - * \param t0 start time - * \param t end time - */ -double Diff(struct timeval t0,struct timeval t) -{ - t.tv_sec -= t0.tv_sec; - t.tv_usec -= t0.tv_usec; - if (t.tv_usec < 0) - { - t.tv_usec += 1000000; - t.tv_sec -= 1; - } - return t.tv_sec + (double)t.tv_usec / 1000000; -} - - -static int val = 0; - -void lock(Mutex& m, int i) -{ - Lock l(m); - val += i; -} - - -void lock(Semaphore& s, int i) -{ - SemLock l(s); - val += i; -} -#endif // WIN32 - - -int main() -{ -#ifndef _WIN32 - Mutex mutex; - Semaphore sema(1); - struct timeval start; - struct timeval tt; - double d; - - Utility::GetTime(&start); - for (int i = 0; i < 100000; i++) - lock(mutex, i); - Utility::GetTime(&tt); - d = Diff(start, tt); - printf("%.4f sec\n", d); - - Utility::GetTime(&start); - for (int i = 0; i < 100000; i++) - lock(sema, i); - Utility::GetTime(&tt); - d = Diff(start, tt); - printf("%.4f sec\n", d); -#endif -} - - diff --git a/Sockets/tests/sloppy_http.cpp b/Sockets/tests/sloppy_http.cpp deleted file mode 100644 index 9ea79c1..0000000 --- a/Sockets/tests/sloppy_http.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include -#include - - -class GetHttp : public TcpSocket -{ -public: - GetHttp(ISocketHandler& h, const char *request) : TcpSocket(h) - , m_request(request) {} - - void OnConnect() { - Send( m_request ); - } - - void OnRawData( const char *buf, size_t len ) { - if (len > 0) { - std::string tmp; - tmp.resize( len ); - memcpy( &tmp[0], buf, len ); - m_response += tmp; - } - } - - const std::string& Response() { - return m_response; - } - -private: - std::string m_request; - std::string m_response; -}; - - -std::string get_http(const char *host, int port, const char *request) -{ - SocketHandler h; - GetHttp sock(h, request); - sock.Open( host, port ); - h.Add(&sock); - while (h.GetCount()) { - h.Select(1, 0); - } - return sock.Response(); -} - - -int main(int argc, char *argv[]) -{ - std::string zz = get_http("www.alhem.net", 80, "GET /index.html HTTP/1.0\r\n" - "Host: www.alhem.net\r\n" - "\r\n"); - printf("%s\n%d\n", zz.c_str(), zz.size()); -} - - diff --git a/Sockets/tests/sockets_test.cpp b/Sockets/tests/sockets_test.cpp deleted file mode 100644 index 78fd2bc..0000000 --- a/Sockets/tests/sockets_test.cpp +++ /dev/null @@ -1,347 +0,0 @@ -#ifdef _WIN32 -#pragma warning(disable:4786) -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef SOCKETS_NAMESPACE -using namespace SOCKETS_NAMESPACE; -#endif - - -class MyHandler : public SocketHandler -{ -public: - MyHandler(StdLog *p) : SocketHandler(p),m_done(false),m_quit(false) {} - ~MyHandler() {} - - void List(TcpSocket *p) { - for (socket_m::iterator it = m_sockets.begin(); it != m_sockets.end(); it++) - { - Socket *p0 = (*it).second; -#ifdef ENABLE_POOL - if (dynamic_cast(p0)) - { - p -> Send("PoolSocket\n"); - } - else -#endif - if (dynamic_cast(p0)) - { - p -> Send("HttpGetSocket\n"); - } - else - if (dynamic_cast(p0)) - { - p -> Send("TcpSocket\n"); - } - else - { - p -> Send("Some kind of Socket\n"); - } - bool r; - bool w; - bool e; - Get(p -> GetSocket(), r, w, e); - char slask[1000]; - sprintf(slask," Read: %s Write: %s Exception: %s\n", - r ? "SET" : "not set", - w ? "SET" : "not set", - e ? "SET" : "not set"); - p -> Send( slask ); - } - } - void SetQuit() { m_quit = true; } - bool Quit() { return m_quit; } - void CheckHtml() { - if (m_done) - { - if (m_ok) - printf("Html OK:\n%s\n", m_html.c_str()); - else - printf("Html Failed\n"); - m_done = false; - } - } - - std::string m_html; - bool m_ok; - bool m_done; - -private: - bool m_quit; -}; - - -class MySocket : public TcpSocket -{ -public: - MySocket(ISocketHandler& h) : TcpSocket(h) { - } - void OnAccept() { - int port = GetParent() -> GetPort(); - Send("I'm the server at port " + - Utility::l2string(port) + "\n"); - SetCloseAndDelete(); - } -}; - - -class hSocket : public HttpGetSocket -{ -public: - hSocket(ISocketHandler& h,const std::string& x,const std::string& y) : HttpGetSocket(h,x,y) {} - - void OnConnect() { - printf("hSocket::OnConnect\n"); - HttpGetSocket::OnConnect(); - } -}; - - -class OrderSocket : public TcpSocket -{ -public: - OrderSocket(ISocketHandler& h) : TcpSocket(h) { - SetLineProtocol(); - } - Socket *Create() { - Handler().LogError(this, "Create", 0, "OrderSocket", LOG_LEVEL_INFO); - return new OrderSocket(Handler()); - } - void OnAccept() { - Send("Cmd (get,quit,list,stop,detach,count,resolve )>"); - } - void OnLine(const std::string& line) { - Parse pa(line); - std::string cmd = pa.getword(); - std::string arg = pa.getrest(); - if (cmd == "get") - { - HttpGetSocket *p = new hSocket(Handler(), arg, "tmpfile.html"); - p -> SetHttpVersion("HTTP/1.1"); - p -> AddResponseHeader("Connection", "keep-alive"); - p -> SetDeleteByHandler(); - Handler().Add( p ); - Send("Reading url '" + arg + "'\n"); - } - else - if (cmd == "quit") - { - Send("Goodbye!\n"); - SetCloseAndDelete(); - } - else - if (cmd == "list") - { - static_cast(Handler()).List( this ); - } - else - if (cmd == "stop") - { - static_cast(Handler()).SetQuit(); - } - else - if (cmd == "resolve") - { - //Resolve( arg ); - ipaddr_t a; - if (Utility::u2ip(arg, a)) - { - std::string tmp; - Utility::l2ip(a, tmp); - Send("Resolved: " + tmp + "\n"); - } - else - { - Send("Resolve failed: " + arg + "\n"); - } - } - else -/* - if (cmd == "reverse") - { - ipaddr_t a; - Utility::u2ip(arg, a); // ip -> ipaddr_t - int id = Socket::Resolve(a, 0); - Send("Resolve id = " + Utility::l2string(id) + "\n"); - } - else -*/ -#ifdef ENABLE_DETACH - if (cmd == "detach") - { - if (!Detach()) - { - Send("Detach() call failed\n"); - } - else - { - Send("Ok.\n"); - } - } - else -#endif - if (cmd == "count") - { - Send("Socket count: " + Utility::l2string( (long)Handler().GetCount()) + "\n"); - } - else - { - Send("Huh?\n"); - } - Send("Cmd>"); - } - void OnDelete() { - printf("OrderSocket::OnDelete()\n"); - } -#ifdef ENABLE_RESOLVER - void OnResolved(int id,ipaddr_t a,port_t port) - { - } - void OnResolved(int id,const std::string& name,port_t port) - { - Send("Resolve id " + Utility::l2string(id) + " = " + name + "\n"); - } -/* - void OnResolved(const char *p,size_t l) { - printf("OnResolved, %d bytes:\n", l); - for (size_t i = 0; i < l; i++) - { - unsigned char c = p[i]; - if (isprint(c)) - printf("%c",c); - else - printf("<%02X>",c); - } - printf("\n"); - } -*/ -#endif -#ifdef ENABLE_DETACH - void OnDetached() { - Send("\nDetached.\nCmd>"); - } -#endif -}; - - -class TestSocket : public TcpSocket -{ -public: - TestSocket(ISocketHandler& h) : TcpSocket(h) { - SetLineProtocol(); - } - void OnConnect() { - printf("TestSocket connected, sending QUIT\n"); - Send( "quit\n" ); - } - void OnConnectFailed() { - printf("TestSocket::OnConnectFailed\n"); - SetCloseAndDelete(); - } - void OnLine(const std::string& line) { - printf("TestSocket: %s\n", line.c_str()); - } - void OnDelete() { - printf("TestSocket::OnDelete()\n"); - } -#ifdef ENABLE_RESOLVER - void OnResolved(int id,ipaddr_t a,port_t port) { - printf("TestSocket::OnResolved(): %d, %08x:%d\n", id, a, port); - TcpSocket::OnResolved(id,a,port); - } -#endif -}; - - -int main() -{ - StdoutLog log; - MyHandler h(&log); - -#ifdef ENABLE_RESOLVER - h.EnableResolver(9999); -#endif -// Utility::ResolveLocal(); - printf(" *** My hostname: %s\n", Utility::GetLocalHostname().c_str()); - printf(" *** My local IP: %s\n", Utility::GetLocalAddress().c_str()); - - // socks4 options -/* - h.SetSocks4Host("127.0.0.1"); - h.SetSocks4Port(1080); - h.SetSocks4Userid("www.alhem.net"); - h.SetSocks4TryDirect( true ); - printf("Socks4Host: %x\n", h.GetSocks4Host()); -*/ - - // first server - ListenSocket l1(h); - if (l1.Bind(1024)) - { - printf("Bind 1024 failed\n"); - exit(-1); - } - h.Add(&l1); - - // second server - ListenSocket l2(h); - if (l2.Bind(1025)) - { - printf("Bind 1025 failed\n"); - exit(-1); - } - h.Add(&l2); - - // line server - ListenSocket l3(h); - if (l3.Bind(1027)) - { - printf("Bind 1027 failed\n"); - exit(-1); - } - h.Add(&l3); - - // http debug - ListenSocket l4(h); - if (l4.Bind(8080)) - { - printf("Bind 8080 failed\n"); - exit(-1); - } - h.Add(&l4); - - // wait for resolver to really start -#ifdef ENABLE_RESOLVER - printf("Waiting for resolver ..."); - while (!h.ResolverReady()) - ; - printf(" resolver ready!\n"); -#endif - - TestSocket ts(h); -printf(">>> TestSocket.Open\n"); - ts.Open("localhost", 1027); -printf(">>> Adding TestSocket\n"); - h.Add(&ts); - -printf(">>> mainloop\n"); - h.Select(0,0); - while (!h.Quit()) - { - h.Select(1,0); - h.CheckSanity(); - } - - return 0; -} - - diff --git a/Sockets/tests/stressclient.cpp b/Sockets/tests/stressclient.cpp deleted file mode 100644 index 4187868..0000000 --- a/Sockets/tests/stressclient.cpp +++ /dev/null @@ -1,516 +0,0 @@ -/** - ** \file stressclient.cpp - ** \date 2006-10-02 - ** \author grymse@alhem.net -**/ -/* -Copyright (C) 2006 Anders Hedstrom - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#ifdef _WIN32 -#pragma warning(disable:4786) -#endif -#include -#include -#include -#include -#include -#ifndef _WIN32 -#include -#include -#else -typedef __int64 int64_t; -#endif -#include - - -static double g_min_time = 10000; -static double g_max_time = 0; -static double g_tot_time = 0; -static int g_ant = 0; -static double g_min_time2 = 10000; -static double g_max_time2 = 0; -static double g_tot_time2 = 0; -static int g_ant2 = 0; -static bool gQuit = false; -static size_t g_max_connections = 0; -static std::string gHost = "localhost"; -static port_t gPort = 2222; -static bool g_b_flood = false; -static bool g_b_off = false; -static bool g_b_limit = false; -static int64_t gBytesIn = 0; -static int64_t gBytesOut = 0; -static bool g_b_repeat = false; -static std::string g_data; -static size_t g_data_size = 1024; -static bool g_b_stop = false; -#ifdef HAVE_OPENSSL -static bool g_b_ssl = false; -#endif -static bool g_b_instant = false; -static struct timeval g_t_start; - - -/** - * Return time difference between two struct timeval's, in seconds - * \param t0 start time - * \param t end time - */ -double Diff(struct timeval t0,struct timeval t) -{ - t.tv_sec -= t0.tv_sec; - t.tv_usec -= t0.tv_usec; - if (t.tv_usec < 0) - { - t.tv_usec += 1000000; - t.tv_sec -= 1; - } - return t.tv_sec + (double)t.tv_usec / 1000000; -} - - -void gettime(struct timeval *p, struct timezone *) -{ -#ifdef _WIN32 - FILETIME ft; // Contains a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC). - GetSystemTimeAsFileTime(&ft); - uint64_t tt; - memcpy(&tt, &ft, sizeof(tt)); - tt /= 10; - p->tv_sec = tt / 1000000; - p->tv_usec = tt % 1000000; -#else - gettimeofday(p, NULL); -#endif -} - - -void printreport() -{ - struct timeval tv; - gettime(&tv, NULL); - double rt = Diff(g_t_start, tv); - g_t_start = tv; - // - printf("\n"); - if (g_ant) - printf("connect; ant: %5d min: %.4f max: %.4f med: %.4f\n", g_ant, g_min_time, g_max_time, g_tot_time / g_ant); - if (g_ant2) - printf("reply; ant: %5d min: %.4f max: %.4f med: %.4f\n", g_ant2, g_min_time2, g_max_time2, g_tot_time2 / g_ant2); - double mbi = (double)gBytesIn / 1024; - mbi /= 1024; - mbi /= rt; - double mbo = (double)gBytesOut / 1024; - mbo /= 1024; - mbo /= rt; - printf("bytes in: %lld", gBytesIn); - printf(" (%.2f MB/sec)", mbi); - printf(" bytes out: %lld", gBytesOut); - printf(" (%.2f MB/sec)", mbo); - printf(" time: %.2f sec\n", rt); -} - - -void printreport_reset() -{ - printreport(); - // - g_min_time = 10000; - g_max_time = 0; - g_tot_time = 0; - g_ant = 0; - g_min_time2 = 10000; - g_max_time2 = 0; - g_tot_time2 = 0; - g_ant2 = 0; - gBytesIn = gBytesOut = 0; -} - - -class MySocket : public TcpSocket -{ -public: - MySocket(ISocketHandler& h,bool one) : TcpSocket(h), m_b_client(false), m_b_one(one), m_b_created(false), m_b_active(false) { - gettime(&m_create, NULL); - SetLineProtocol(); -#ifdef HAVE_OPENSSL - if (g_b_ssl) - EnableSSL(); -#endif - if (g_max_connections && !m_b_one && Handler().GetCount() >= g_max_connections) - { - fprintf(stderr, "\nConnection limit reached: %d, continuing in single connection stress mode\n", (int)g_max_connections); - if (g_b_off) - printreport_reset(); - g_b_limit = true; - m_b_one = true; - // - g_b_flood = g_b_repeat; - } - if (!m_b_one && Handler().GetCount() >= FD_SETSIZE - 17) - { - fprintf(stderr, "\nFD_SETSIZE connection limit reached: %d, continuing in single connection stress mode\n", (int)Handler().GetCount()); - if (g_b_off) - printreport_reset(); - g_b_limit = true; - m_b_one = true; - // - g_b_flood = g_b_repeat; - } - } - ~MySocket() { - } - - void OnConnect() { - gettime(&m_connect, NULL); - m_b_active = true; - { - double tconnect = Diff(m_create, m_connect); - // - g_min_time = tconnect < g_min_time ? tconnect : g_min_time; - g_max_time = tconnect > g_max_time ? tconnect : g_max_time; - g_tot_time += tconnect; - g_ant += 1; - } - SendBlock(); - m_b_client = true; - } - - void SendBlock() { - gettime(&m_send, NULL); - Send(g_data + "\n"); - } - - void OnLine(const std::string& line) { - gettime(&m_reply, NULL); - m_b_active = true; - { - double treply = Diff(m_send, m_reply); - // - g_min_time2 = treply < g_min_time2 ? treply : g_min_time2; - g_max_time2 = treply > g_max_time2 ? treply : g_max_time2; - g_tot_time2 += treply; - g_ant2 += 1; - } - // - if (line != g_data) - { - fprintf(stderr, "\n%s\n%s\n", line.c_str(), g_data.c_str()); - fprintf(stderr, "(reply did not match data - exiting)\n"); - exit(-1); - } - // - gBytesIn += GetBytesReceived(true); - gBytesOut += GetBytesSent(true); - if (m_b_one) - { - SetCloseAndDelete(); - } - else - if (g_b_repeat && g_b_limit) - { - SendBlock(); - } - // add another - if (!m_b_created && (!g_b_limit || !g_b_off) && !g_b_instant) - { - MySocket *p = new MySocket(Handler(), m_b_one); - p -> SetDeleteByHandler(); - p -> Open(gHost, gPort); - Handler().Add(p); - m_b_created = true; - } - } - - bool IsActive() { - bool b = m_b_active; - m_b_active = false; - return b; - } - -private: - bool m_b_client; - bool m_b_one; - bool m_b_created; - bool m_b_active; - struct timeval m_create; - struct timeval m_connect; - struct timeval m_send; - struct timeval m_reply; -}; - - -class MyHttpSocket : public HttpGetSocket -{ -public: - MyHttpSocket(ISocketHandler& h,const std::string& url) : HttpGetSocket(h,url), m_url(url) { - gettime(&m_create, NULL); - AddResponseHeader("content-length", Utility::l2string(g_data_size)); - } - ~MyHttpSocket() {} - - void OnConnect() { - gettime(&m_connect, NULL); - { - double tconnect = Diff(m_create, m_connect); - // - g_min_time = tconnect < g_min_time ? tconnect : g_min_time; - g_max_time = tconnect > g_max_time ? tconnect : g_max_time; - g_tot_time += tconnect; - g_ant += 1; - } - gettime(&m_send, NULL); - - // send request header - HttpGetSocket::OnConnect(); - - // send body - Send(g_data); - } - - void OnContent() { - gettime(&m_reply, NULL); - { - double treply = Diff(m_send, m_reply); - // - g_min_time2 = treply < g_min_time2 ? treply : g_min_time2; - g_max_time2 = treply > g_max_time2 ? treply : g_max_time2; - g_tot_time2 += treply; - g_ant2 += 1; - } - CreateNew(); - } - void CreateNew() { - if (g_b_off) - return; - MyHttpSocket *p = new MyHttpSocket(Handler(), m_url); - p -> SetDeleteByHandler(); - Handler().Add(p); - SetCloseAndDelete(); - } - -private: - std::string m_url; - struct timeval m_create; - struct timeval m_connect; - struct timeval m_send; - struct timeval m_reply; -}; - - -#ifndef _WIN32 -void sigint(int) -{ - printreport(); - gQuit = true; -} - - -void sigusr1(int) -{ - g_b_flood = true; -} - - -void sigusr2(int) -{ - printreport_reset(); -} -#endif - - -class MyHandler : public SocketHandler -{ -public: - MyHandler() : SocketHandler() { - } - MyHandler(StdoutLog *p) : SocketHandler(p) { - } - ~MyHandler() { - } - void Flood() { - for (socket_m::iterator it = m_sockets.begin(); it != m_sockets.end(); it++) - { - Socket *p0 = it -> second; - MySocket *p = dynamic_cast(p0); - if (p) - { - p -> SendBlock(); - } - } - } - void Report() { - int ant = 0; - int act = 0; - for (socket_m::iterator it = m_sockets.begin(); it != m_sockets.end(); it++) - { - MySocket *p = dynamic_cast(it -> second); - if (p) - { - ant++; - if (p -> IsActive()) - { - act++; - } - } - } - printf("Number of //stress// sockets: %d Active: %d\n", ant, act); - } -}; - - -int main(int argc,char *argv[]) -{ - bool many = false; - bool one = false; - bool enableLog = false; - bool http = false; - std::string url; - time_t report_period = 10; - for (int i = 1; i < argc; i++) - { - if (!strcmp(argv[i], "-many")) - many = true; - if (!strcmp(argv[i], "-one")) - one = true; - if (*argv[i] == '-' && strlen(argv[i]) > 1 && isdigit(argv[i][1]) ) - g_max_connections = atoi(argv[i] + 1); - if (!strcmp(argv[i], "-host") && i < argc - 1) - gHost = argv[++i]; - if (!strcmp(argv[i], "-port") && i < argc - 1) - gPort = atoi(argv[++i]); - if (!strcmp(argv[i], "-off")) - g_b_off = true; - if (!strcmp(argv[i], "-repeat")) - g_b_repeat = true; - if (!strcmp(argv[i], "-size") && i < argc - 1) - g_data_size = atoi(argv[++i]); - if (!strcmp(argv[i], "-log")) - enableLog = true; - if (!strcmp(argv[i], "-time") && i < argc - 1) - report_period = atoi(argv[++i]); - if (!strcmp(argv[i], "-stop")) - g_b_stop = true; -#ifdef HAVE_OPENSSL - if (!strcmp(argv[i], "-ssl")) - g_b_ssl = true; -#endif - if (!strcmp(argv[i], "-instant")) - g_b_instant = true; - if (!strcmp(argv[i], "-http")) - http = true; - if (!strcmp(argv[i], "-url") && i < argc - 1) - url = argv[++i]; - } - if (argc < 2 || (!many && !one && !g_max_connections && !http) ) - { - printf("Usage: %s [mode] [options]\n", *argv); - printf(" Modes (only use one of these):\n"); - printf(" -many start max number of connections\n"); - printf(" -one open - close - repeat\n"); - printf(" -nn open nn connections, then start -one mode\n"); - printf(" -http send/receive http request/response\n"); - printf(" Options:\n"); - printf(" -host xx host to connect to\n"); - printf(" -port nn port number to connection to\n"); - printf(" -off turn off new connections when connection limit reached\n"); - printf(" -repeat send new block when reply is received\n"); - printf(" -size nn size of block to send, default is 1024 bytes\n"); - printf(" -log enable debug log\n"); - printf(" -time nn time between reports, default 10s\n"); - printf(" -stop stop after time elapsed\n"); - printf(" -instant create all sockets at once\n"); -#ifdef HAVE_OPENSSL - printf(" -ssl use ssl\n"); -#endif - printf(" -url xx url to use in http mode (default http://:/)\n"); - exit(-1); - } - fprintf(stderr, "Using data size: %d bytes\n", (int)g_data_size); - std::string chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - while (g_data.size() < g_data_size) - { - g_data += chars[rand() % chars.size()]; - } -#ifndef _WIN32 - signal(SIGINT, sigint); - signal(SIGUSR1, sigusr1); - signal(SIGUSR2, sigusr2); - signal(SIGPIPE, SIG_IGN); -#endif - StdoutLog *log = enableLog ? new StdoutLog() : NULL; - MyHandler h(log); - if (http) - { - if (!url.size()) - { - url = "http://" + gHost + ":" + Utility::l2string(gPort) + "/"; - } - MyHttpSocket *s = new MyHttpSocket(h, url); - s -> SetDeleteByHandler(); - h.Add(s); - } - else - if (g_b_instant) - { - for (size_t i = 0; i < g_max_connections; i++) - { - MySocket *s = new MySocket(h, one); - s -> SetDeleteByHandler(); - s -> Open(gHost, gPort); - h.Add(s); - } - g_b_limit = true; - } - else - { - MySocket *s = new MySocket(h, one); - s -> SetDeleteByHandler(); - s -> Open(gHost, gPort); - h.Add(s); - } - time_t t = time(NULL); - gettime(&g_t_start, NULL); - while (!gQuit) - { - h.Select(1, 0); - if (g_b_flood) - { - fprintf(stderr, "\nFlooding\n"); - h.Flood(); - g_b_flood = false; - } - if (time(NULL) - t >= report_period) // report - { - t = time(NULL); - printreport_reset(); - h.Report(); - if (g_b_stop) - { - gQuit = true; - } - } - } - fprintf(stderr, "\nExiting...\n"); - if (log) - { -// delete log; - } - return 0; -} - - diff --git a/Sockets/tests/x.cpp b/Sockets/tests/x.cpp deleted file mode 100644 index 2ca9b26..0000000 --- a/Sockets/tests/x.cpp +++ /dev/null @@ -1,298 +0,0 @@ -#include -#include -#include -#ifndef _WIN32 -#include -#endif -#include -#include - -#define HOST "localhost" -#define PORT 2222 - -#define TIME_US 250000 - -#define DEB(x) x - - -static bool quit = false; -static EventHandler *ph = NULL; - -static int lc = 0; -static int l2c = 0; -static int l3c = 0; - - -#ifndef _WIN32 -void sighandler(int s) -{ - quit = true; - ph -> SetQuit(); -} - - -void sigpipe(int s) -{ -} -#endif - - -class evHandler : public EventHandler -{ -public: - evHandler() : EventHandler() {} - evHandler(StdLog *p) : EventHandler(p) {} - - void CloseAll() { - for (socket_m::iterator it = m_sockets.begin(); it != m_sockets.end(); it++) - { - Socket *p = it -> second; - p -> SetCloseAndDelete(); - } - } - -}; - - -class lSocket : public TcpSocket, public IEventOwner -{ -public: - lSocket(ISocketHandler& h, bool first = false) : TcpSocket(h), IEventOwner(static_cast(h)), m_id(0), m_first(first) { - SetLineProtocol(); - lc++; - } - ~lSocket() { - } - - void OnConnect() { - if (!m_id) - { - m_id = AddEvent(0, TIME_US); - } - printf("."); - fflush(stdout); - } - void OnConnectFailed() { - printf("lSocket::OnConnectFailed\n"); - } - - void OnDelete() { - if (m_first) - printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" - "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" - "@@@@@@@@@@@@@@ OnDelete() first @@@@@@@@@@@@@@@@@@\n" - "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" - "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"); - } - - void OnEvent(int id) { - if (id != m_id) - { - printf("ID MISMATCH!\n"); - exit(-1); - } - if (!quit) - { - lSocket *p = new lSocket(Handler()); - p -> SetDeleteByHandler(); - p -> Open(HOST, PORT); - Handler().Add(p); - } - static_cast(Handler()).SetQuit( quit ); - SetCloseAndDelete(); - } - -private: - int m_id; - bool m_first; -}; - - -class l2Socket : public TcpSocket, public IEventOwner -{ -public: - l2Socket(ISocketHandler& h, bool first = false) : TcpSocket(h), IEventOwner(static_cast(h)), m_id(0), m_first(first) { - SetLineProtocol(); - l2c++; - } - ~l2Socket() { - } - - void OnConnect() { - printf("."); - fflush(stdout); - } - void OnConnectFailed() { - printf("l2Socket::OnConnectFailed\n"); - } - - void OnLine(const std::string& line) { - if (!m_id) - { - m_id = AddEvent(0, TIME_US); - } - } - - void OnDelete() { - if (m_first) - printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" - "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" - "@@@@@@@@@@@@@@ OnDelete() first @@@@@@@@@@@@@@@@@@\n" - "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" - "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"); - } - - void OnEvent(int id) { - if (id != m_id) - { - printf("ID MISMATCH!\n"); - exit(-1); - } - if (!quit) - { - l2Socket *p = new l2Socket(Handler()); - p -> SetDeleteByHandler(); - p -> Open(HOST, PORT); - Handler().Add(p); - } - static_cast(Handler()).SetQuit( quit ); - SetCloseAndDelete(); - } - -private: - int m_id; - bool m_first; -}; - - -class l3Socket : public TcpSocket, public IEventOwner -{ -public: - l3Socket(ISocketHandler& h, bool first = false) : TcpSocket(h), IEventOwner(static_cast(h)), m_ehlo(false), m_id(0), m_first(first) { - SetLineProtocol(); - l3c++; - } - ~l3Socket() { - } - - void OnConnect() { - printf("."); - fflush(stdout); - } - void OnConnectFailed() { - printf("l3Socket::OnConnectFailed\n"); - } - - void OnLine(const std::string& line) { - if (!m_ehlo) - { - Send("EHLO alhem.net\r\n"); - m_ehlo = true; - } - else - if (!m_id) - { - m_id = AddEvent(0, TIME_US); - } - } - - void OnDelete() { - if (m_first) - printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" - "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" - "@@@@@@@@@@@@@@ OnDelete() first @@@@@@@@@@@@@@@@@@\n" - "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" - "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"); - } - - void OnEvent(int id) { - if (id != m_id) - { - printf("ID MISMATCH!\n"); - exit(-1); - } - if (!quit) - { - l3Socket *p = new l3Socket(Handler()); - p -> SetDeleteByHandler(); - p -> Open(HOST, PORT); - Handler().Add(p); - } - static_cast(Handler()).SetQuit( quit ); - Send("QUIT\r\n"); - } - -private: - bool m_ehlo; - int m_id; - bool m_first; -}; - - -int main(int argc, char *argv[]) -{ -#ifndef _WIN32 - signal(SIGHUP, sighandler); - signal(SIGINT, sighandler); - signal(SIGPIPE, sigpipe); -#endif - - time_t tstart = time(NULL); - { - StdoutLog log; - { - evHandler h(&log); - ph = &h; - { - lSocket sock(h, true); - sock.Open(HOST, PORT); - h.Add(&sock); - { - l2Socket sock2(h, true); - sock2.Open(HOST, PORT); - h.Add(&sock2); - { - l3Socket sock3(h, true); - sock3.Open(HOST, PORT); - h.Add(&sock3); - - h.EventLoop(); - h.CloseAll(); - - // %! one socket refuses to go away - while (h.GetCount() > 1) - { - h.Select(1, 0); - } - printf("Exiting 1...\n"); - fflush(stdout); - } - printf("Exiting 2...\n"); - fflush(stdout); - } - printf("Exiting 3...\n"); - fflush(stdout); - } - printf("Exiting 4...\n"); - fflush(stdout); - } - printf("Exiting 5...\n"); - fflush(stdout); - } - printf("Exiting 6...\n"); - fflush(stdout); - - time_t tstop = time(NULL); - - time_t total = tstop - tstart + 1; - - printf("lc: %d\n", lc); - printf("l2c: %d\n", l2c); - printf("l3c: %d\n", l3c); - - printf("lc: %f\n", (double)lc / (double)total); - printf("l2c: %f\n", (double)l2c / (double)total); - printf("l3c: %f\n", (double)l3c / (double)total); -} - - diff --git a/anycast-voip-diagramm.pdf b/anycast-voip-diagramm.pdf deleted file mode 100644 index af3eb78..0000000 Binary files a/anycast-voip-diagramm.pdf and /dev/null differ diff --git a/anyctrOptions.cpp b/anyctrOptions.cpp deleted file mode 100644 index 3c770bc..0000000 --- a/anyctrOptions.cpp +++ /dev/null @@ -1,339 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include -#include - -#include "datatypes.h" -#include "anyctrOptions.h" - -Options* Options::inst = NULL; -Mutex Options::instMutex; -Options& gOpt = Options::instance(); - -Options& Options::instance() -{ - Lock lock(instMutex); - static instanceCleaner c; - if(!inst) - inst = new Options(); - - return *inst; -} - -Options::Options() : key_(u_int32_t(0)), salt_(u_int32_t(0)) -{ - progname_ = "anytun-config"; - remote_addr_ = ""; - remote_port_ = 4444; - ifconfig_param_remote_netmask_ = "255.255.255.0"; - seq_window_size_ = 100; - kd_prf_ = "aes-ctr"; - mux_ = 0; - network_prefix_length_ = 32; -} - -Options::~Options() -{ -} - -#define PARSE_BOOL_PARAM(SHORT, LONG, VALUE) \ - else if(str == SHORT || str == LONG) \ - VALUE = true; - -#define PARSE_INVERSE_BOOL_PARAM(SHORT, LONG, VALUE) \ - else if(str == SHORT || str == LONG) \ - VALUE = false; - -#define PARSE_SCALAR_PARAM(SHORT, LONG, VALUE) \ - else if(str == SHORT || str == LONG) \ - { \ - if(argc < 1 || argv[i+1][0] == '-') \ - return false; \ - std::stringstream tmp; \ - tmp << argv[i+1]; \ - tmp >> VALUE; \ - argc--; \ - i++; \ - } - -#define PARSE_SCALAR_PARAM2(SHORT, LONG, VALUE1, VALUE2) \ - else if(str == SHORT || str == LONG) \ - { \ - if(argc < 2 || \ - argv[i+1][0] == '-' || argv[i+2][0] == '-') \ - return false; \ - std::stringstream tmp; \ - tmp << argv[i+1] << " " << argv[i+2]; \ - tmp >> VALUE1; \ - tmp >> VALUE2; \ - argc-=2; \ - i+=2; \ - } - -#define PARSE_HEXSTRING_PARAM_SEC(SHORT, LONG, VALUE) \ - else if(str == SHORT || str == LONG) \ - { \ - if(argc < 1 || argv[i+1][0] == '-') \ - return false; \ - VALUE = Buffer(std::string(argv[i+1])); \ - for(size_t j=0; j < strlen(argv[i+1]); ++j) \ - argv[i+1][j] = '#'; \ - argc--; \ - i++; \ - } - -#define PARSE_CSLIST_PARAM(SHORT, LONG, LIST) \ - else if(str == SHORT || str == LONG) \ - { \ - if(argc < 1 || argv[i+1][0] == '-') \ - return false; \ - std::stringstream tmp(argv[i+1]); \ - while (tmp.good()) \ - { \ - std::string tmp_line; \ - getline(tmp,tmp_line,','); \ - LIST.push(tmp_line); \ - } \ - argc--; \ - i++; \ - } - -bool Options::parse(int argc, char* argv[]) -{ - Lock lock(mutex); - - progname_ = argv[0]; - argc--; - std::queue host_port_queue; - for(int i=1; argc > 0; ++i) - { - std::string str(argv[i]); - argc--; - - if(str == "-h" || str == "--help") - return false; - PARSE_SCALAR_PARAM("-r","--remote-host", remote_addr_) - PARSE_SCALAR_PARAM("-o","--remote-port", remote_port_) - PARSE_SCALAR_PARAM("-n","--prefix", ifconfig_param_remote_netmask_) - PARSE_SCALAR_PARAM("-w","--window-size", seq_window_size_) - PARSE_SCALAR_PARAM("-m","--mux", mux_) - PARSE_SCALAR_PARAM("-l","--prefix-len", network_prefix_length_) - PARSE_HEXSTRING_PARAM_SEC("-K","--key", key_) - PARSE_HEXSTRING_PARAM_SEC("-A","--salt", salt_) - PARSE_SCALAR_PARAM("-k","--kd-prf", kd_prf_) - else - return false; - } - - while(!host_port_queue.empty()) - { - std::stringstream tmp_stream(host_port_queue.front()); - OptionConnectTo oct; - getline(tmp_stream,oct.host,':'); - if(!tmp_stream.good()) - return false; - tmp_stream >> oct.port; - host_port_queue.pop(); - connect_to_.push_back(oct); - } - return true; -} - -void Options::printUsage() -{ - std::cout << "USAGE:" << std::endl; - std::cout << "anytun-config" << std::endl; - std::cout << " [-h|--help] prints this..." << std::endl; - std::cout << " [-r|--remote-host] remote host" << std::endl; - std::cout << " [-o|--remote-port] remote port" << std::endl; - std::cout << " [-n|--prefix] remote subnet for route" << std::endl; - std::cout << " [-w|--window-size] seqence number window size" << std::endl; - std::cout << " [-m|--mux] the multiplex id to use" << std::endl; - std::cout << " [-l|--prefix-len] network prefix length" << std::endl; - std::cout << " [-K|--key] master key to use for encryption" << std::endl; - std::cout << " [-A|--salt] master salt to use for encryption" << std::endl; - std::cout << " [-k|--kd-prf] key derivation pseudo random function" << std::endl; -} - -void Options::printOptions() -{ - Lock lock(mutex); - std::cout << "Options:" << std::endl; - std::cout << "remote_addr='" << remote_addr_ << "'" << std::endl; - std::cout << "remote_port='" << remote_port_ << "'" << std::endl; - std::cout << "ifconfig_param_local='" << ifconfig_param_local_ << "'" << std::endl; - std::cout << "ifconfig_param_remote_netmask='" << ifconfig_param_remote_netmask_ << "'" << std::endl; - std::cout << "seq_window_size='" << seq_window_size_ << "'" << std::endl; - std::cout << "mux_id='" << mux_ << "'" << std::endl; - std::cout << "network_prefix_length='" << network_prefix_length_ << "'" << std::endl; - std::cout << "key=" << key_.getHexDumpOneLine() << std::endl; - std::cout << "salt=" << salt_.getHexDumpOneLine() << std::endl; - std::cout << "kd_prf='" << kd_prf_ << "'" << std::endl; -} - -std::string Options::getProgname() -{ - Lock lock(mutex); - return progname_; -} - - -Options& Options::setProgname(std::string p) -{ - Lock lock(mutex); - progname_ = p; - return *this; -} - - -std::string Options::getRemoteAddr() -{ - Lock lock(mutex); - return remote_addr_; -} - -Options& Options::setRemoteAddr(std::string r) -{ - Lock lock(mutex); - remote_addr_ = r; - return *this; -} - -u_int16_t Options::getRemotePort() -{ - return remote_port_; -} - -Options& Options::setRemotePort(u_int16_t r) -{ - remote_port_ = r; - return *this; -} - -Options& Options::setRemoteAddrPort(std::string addr, u_int16_t port) -{ - Lock lock(mutex); - remote_addr_ = addr; - remote_port_ = port; - return *this; -} - -std::string Options::getIfconfigParamRemoteNetmask() -{ - Lock lock(mutex); - return ifconfig_param_remote_netmask_; -} - -Options& Options::setIfconfigParamRemoteNetmask(std::string i) -{ - Lock lock(mutex); - ifconfig_param_remote_netmask_ = i; - return *this; -} - -window_size_t Options::getSeqWindowSize() -{ - return seq_window_size_; -} - -Options& Options::setSeqWindowSize(window_size_t s) -{ - seq_window_size_ = s; - return *this; -} - - -std::string Options::getKdPrf() -{ - Lock lock(mutex); - return kd_prf_; -} - -Options& Options::setKdPrf(std::string k) -{ - Lock lock(mutex); - kd_prf_ = k; - return *this; -} - -u_int16_t Options::getMux() -{ - Lock lock(mutex); - return mux_; -} - -Options& Options::setMux(u_int16_t m) -{ - Lock lock(mutex); - mux_ = m; - return *this; -} - -u_int16_t Options::getNetworkPrefixLength() -{ - Lock lock(mutex); - return network_prefix_length_; -} - -Options& Options::setNetworkPrefixLength(u_int16_t l) -{ - Lock lock(mutex); - network_prefix_length_ = l; - return *this; -} - -Buffer Options::getKey() -{ - Lock lock(mutex); - return key_; -} - -Options& Options::setKey(std::string k) -{ - Lock lock(mutex); - key_ = k; - return *this; -} - -Buffer Options::getSalt() -{ - Lock lock(mutex); - return salt_; -} - -Options& Options::setSalt(std::string s) -{ - Lock lock(mutex); - salt_ = s; - return *this; -} diff --git a/anyctrOptions.h b/anyctrOptions.h deleted file mode 100644 index edbd621..0000000 --- a/anyctrOptions.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _ANYCTR_OPTIONS_H_ -#define _ANYCTR_OPTIONS_H_ - -#include "datatypes.h" -#include "buffer.h" -#include "threadUtils.hpp" -#include - -typedef struct OptionConnectTo -{ - std::string host; - uint16_t port; -}; - -typedef std::list ConnectToList; - -class Options -{ -public: - static Options& instance(); - - bool parse(int argc, char* argv[]); - void printUsage(); - void printOptions(); - - std::string getProgname(); - Options& setProgname(std::string p); - std::string getRemoteAddr(); - Options& setRemoteAddr(std::string r); - u_int16_t getRemotePort(); - Options& setRemotePort(u_int16_t r); - Options& setRemoteAddrPort(std::string addr, u_int16_t port); - std::string getIfconfigParamRemoteNetmask(); - Options& setIfconfigParamRemoteNetmask(std::string i); - window_size_t getSeqWindowSize(); - Options& setSeqWindowSize(window_size_t s); - std::string getKdPrf(); - Options& setKdPrf(std::string k); - Options& setMux(u_int16_t m); - u_int16_t getMux(); - Options& setKey(std::string k); - Buffer getKey(); - Options& setSalt(std::string s); - Buffer getSalt(); - Options& setNetworkPrefixLength(u_int16_t l); - u_int16_t getNetworkPrefixLength(); - -private: - Options(); - ~Options(); - Options(const Options &l); - void operator=(const Options &l); - - static Options* inst; - static Mutex instMutex; - class instanceCleaner { - public: ~instanceCleaner() { - if(Options::inst != 0) - delete Options::inst; - } - }; - friend class instanceCleaner; - - Mutex mutex; - - ConnectToList connect_to_; - std::string progname_; - std::string remote_addr_; - u_int16_t remote_port_; - std::string ifconfig_param_local_; - std::string ifconfig_param_remote_netmask_; - window_size_t seq_window_size_; - std::string kd_prf_; - u_int16_t mux_; - u_int16_t network_prefix_length_; - Buffer key_; - Buffer salt_; -}; - -extern Options& gOpt; - -#endif diff --git a/anymuxOptions.cpp b/anymuxOptions.cpp deleted file mode 100644 index c892e26..0000000 --- a/anymuxOptions.cpp +++ /dev/null @@ -1,303 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include -#include - -#include "datatypes.h" -#include "anymuxOptions.h" - -Options* Options::inst = NULL; -Mutex Options::instMutex; -Options& gOpt = Options::instance(); - -Options& Options::instance() -{ - Lock lock(instMutex); - static instanceCleaner c; - if(!inst) - inst = new Options(); - - return *inst; -} - -Options::Options() -{ - progname_ = "anytun-controld"; - file_name_ = ""; - daemonize_ = true; - chroot_ = false; - username_ = "nobody"; - chroot_dir_ = "/var/run/anytun-controld"; - pid_file_ = ""; - bind_to_addr_ = "127.0.0.1"; - bind_to_port_ = 4445; -} - -Options::~Options() -{ -} - -#define PARSE_BOOL_PARAM(SHORT, LONG, VALUE) \ - else if(str == SHORT || str == LONG) \ - VALUE = true; - -#define PARSE_INVERSE_BOOL_PARAM(SHORT, LONG, VALUE) \ - else if(str == SHORT || str == LONG) \ - VALUE = false; - -#define PARSE_SCALAR_PARAM(SHORT, LONG, VALUE) \ - else if(str == SHORT || str == LONG) \ - { \ - if(argc < 1 || argv[i+1][0] == '-') \ - return false; \ - std::stringstream tmp; \ - tmp << argv[i+1]; \ - tmp >> VALUE; \ - argc--; \ - i++; \ - } - -#define PARSE_SCALAR_PARAM2(SHORT, LONG, VALUE1, VALUE2) \ - else if(str == SHORT || str == LONG) \ - { \ - if(argc < 2 || \ - argv[i+1][0] == '-' || argv[i+2][0] == '-') \ - return false; \ - std::stringstream tmp; \ - tmp << argv[i+1] << " " << argv[i+2]; \ - tmp >> VALUE1; \ - tmp >> VALUE2; \ - argc-=2; \ - i+=2; \ - } - -#define PARSE_HEXSTRING_PARAM_SEC(SHORT, LONG, VALUE) \ - else if(str == SHORT || str == LONG) \ - { \ - if(argc < 1 || argv[i+1][0] == '-') \ - return false; \ - VALUE = Buffer(std::string(argv[i+1])); \ - for(size_t j=0; j < strlen(argv[i+1]); ++j) \ - argv[i+1][j] = '#'; \ - argc--; \ - i++; \ - } - -#define PARSE_CSLIST_PARAM(SHORT, LONG, LIST) \ - else if(str == SHORT || str == LONG) \ - { \ - if(argc < 1 || argv[i+1][0] == '-') \ - return false; \ - std::stringstream tmp(argv[i+1]); \ - while (tmp.good()) \ - { \ - std::string tmp_line; \ - getline(tmp,tmp_line,','); \ - LIST.push(tmp_line); \ - } \ - argc--; \ - i++; \ - } - -bool Options::parse(int argc, char* argv[]) -{ - Lock lock(mutex); - - progname_ = argv[0]; - argc--; - - std::string control_host(""); - for(int i=1; argc > 0; ++i) - { - std::string str(argv[i]); - argc--; - - if(str == "-h" || str == "--help") - return false; - PARSE_SCALAR_PARAM("-f","--file", file_name_) - PARSE_INVERSE_BOOL_PARAM("-D","--nodaemonize", daemonize_) - PARSE_BOOL_PARAM("-C","--chroot", chroot_) - PARSE_SCALAR_PARAM("-u","--username", username_) - PARSE_SCALAR_PARAM("-H","--chroot-dir", chroot_dir_) - PARSE_SCALAR_PARAM("-P","--write-pid", pid_file_) - PARSE_SCALAR_PARAM("-X","--control-host", control_host) - else - return false; - } - - if(control_host != "") { - std::stringstream tmp_stream(control_host); - getline(tmp_stream,bind_to_addr_,':'); - if(!tmp_stream.good()) - return false; - tmp_stream >> bind_to_port_; - } - - return true; -} - -void Options::printUsage() -{ - std::cout << "USAGE:" << std::endl; - std::cout << "anytun-controld [-h|--help] prints this..." << std::endl; - std::cout << " [-D|--nodaemonize] don't run in background" << std::endl; - std::cout << " [-C|--chroot] chroot and drop privileges" << std::endl; - std::cout << " [-u|--username] if chroot change to this user" << std::endl; - std::cout << " [-H|--chroot-dir] chroot to this directory" << std::endl; - std::cout << " [-P|--write-pid] write pid to this file" << std::endl; - std::cout << " [-f|--file] path to file" << std::endl; - -} - -void Options::printOptions() -{ - Lock lock(mutex); - std::cout << "Options:" << std::endl; - std::cout << "daemonize=" << daemonize_ << std::endl; - std::cout << "chroot=" << chroot_ << std::endl; - std::cout << "username='" << username_ << "'" << std::endl; - std::cout << "chroot_dir='" << chroot_dir_ << "'" << std::endl; - std::cout << "pid_file='" << pid_file_ << "'" << std::endl; -} - -std::string Options::getProgname() -{ - Lock lock(mutex); - return progname_; -} - - -Options& Options::setProgname(std::string p) -{ - Lock lock(mutex); - progname_ = p; - return *this; -} - -bool Options::getDaemonize() -{ - return daemonize_; -} - -Options& Options::setDaemonize(bool d) -{ - daemonize_ = d; - return *this; -} - -bool Options::getChroot() -{ - return chroot_; -} - -Options& Options::setChroot(bool c) -{ - chroot_ = c; - return *this; -} - -std::string Options::getUsername() -{ - Lock lock(mutex); - return username_; -} - -Options& Options::setUsername(std::string u) -{ - Lock lock(mutex); - username_ = u; - return *this; -} - -std::string Options::getChrootDir() -{ - Lock lock(mutex); - return chroot_dir_; -} - -Options& Options::setChrootDir(std::string c) -{ - Lock lock(mutex); - chroot_dir_ = c; - return *this; -} - -std::string Options::getPidFile() -{ - Lock lock(mutex); - return pid_file_; -} - -Options& Options::setPidFile(std::string p) -{ - Lock lock(mutex); - pid_file_ = p; - return *this; -} - -std::string Options::getFileName() -{ - Lock lock(mutex); - return file_name_; -} - -Options& Options::setFileName(std::string f) -{ - Lock lock(mutex); - file_name_ = f; - return *this; -} - -std::string Options::getBindToAddr() -{ - Lock lock(mutex); - return bind_to_addr_; -} - -Options& Options::setBindToAddr(std::string b) -{ - Lock lock(mutex); - bind_to_addr_ = b; - return *this; -} - -uint16_t Options::getBindToPort() -{ - return bind_to_port_; -} - -Options& Options::setBindToPort(uint16_t b) -{ - bind_to_port_ = b; - return *this; -} diff --git a/anymuxOptions.h b/anymuxOptions.h deleted file mode 100644 index dfbc213..0000000 --- a/anymuxOptions.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _ANYMUX_OPTIONS_H_ -#define _ANYMUX_OPTIONS_H_ - -#include "datatypes.h" -#include "buffer.h" -#include "threadUtils.hpp" -#include - -class Options -{ -public: - static Options& instance(); - - bool parse(int argc, char* argv[]); - void printUsage(); - void printOptions(); - - std::string getProgname(); - Options& setProgname(std::string p); - bool getDaemonize(); - Options& setDaemonize(bool d); - bool getChroot(); - Options& setChroot(bool b); - std::string getUsername(); - Options& setUsername(std::string u); - std::string getChrootDir(); - Options& setChrootDir(std::string c); - std::string getPidFile(); - Options& setPidFile(std::string p); - std::string getFileName(); - Options& setFileName(std::string f); - std::string getBindToAddr(); - Options& setBindToAddr(std::string b); - uint16_t getBindToPort(); - Options& setBindToPort(uint16_t b); - - -private: - Options(); - ~Options(); - Options(const Options &l); - void operator=(const Options &l); - - static Options* inst; - static Mutex instMutex; - class instanceCleaner { - public: ~instanceCleaner() { - if(Options::inst != 0) - delete Options::inst; - } - }; - friend class instanceCleaner; - - Mutex mutex; - - std::string bind_to_addr_; - uint16_t bind_to_port_; - std::string progname_; - bool daemonize_; - bool chroot_; - std::string username_; - std::string chroot_dir_; - std::string pid_file_; - std::string file_name_; -}; - -extern Options& gOpt; - -#endif diff --git a/anyrtpproxy/Makefile b/anyrtpproxy/Makefile deleted file mode 100644 index 948a4c8..0000000 --- a/anyrtpproxy/Makefile +++ /dev/null @@ -1,68 +0,0 @@ -C = gcc -CFLAGS = -g -Wall -CFLAGS += -DSOCKETS_NAMESPACE=sockets -CFLAGS += -DSOCKETS_NAMESPACE_STR='"sockets"' -C++ = g++ -CCFLAGS = -g -Wall -CCFLAGS += -DSOCKETS_NAMESPACE=sockets -CCFLAGS += -DSOCKETS_NAMESPACE_STR='"sockets"' -LD = g++ -LDFLAGS = -g -Wall -O2 -lpthread -lssl -lboost_serialization - -OBJS = anyrtpproxy.o \ - ../signalController.o \ - ../PracticalSocket.o \ - ../log.o \ - ../buffer.o \ - ../rtpSessionTable.o \ - ../rtpSession.o \ - connectionList.o \ - ../syncSocketHandler.o \ - ../syncClientSocket.o \ - ../syncQueue.o \ - ../syncSocket.o \ - ../seqWindow.o \ - ../connectionParam.o \ - ../routingTable.o \ - ../syncBuffer.o \ - ../syncCommand.o \ - ../syncRouteCommand.o \ - ../syncRtpCommand.o \ - ../syncConnectionCommand.o \ - ../networkAddress.o \ - ../networkPrefix.o \ - ../Sockets/libSockets.a \ - commandHandler.o \ - portWindow.o \ - callIdQueue.o \ - options.o - -EXECUTABLE = anyrtpproxy - -all: $(EXECUTABLE) - -anyrtpproxy: $(OBJS) - $(LD) $(OBJS) -o $@ $(LDFLAGS) - -options.o: options.cpp options.h - $(C++) $(CCFLAGS) $< -c - -portWindow.o: portWindow.cpp portWindow.h - $(C++) $(CCFLAGS) $< -c - -connectionList.o: connectionList.cpp connectionList.h - $(C++) $(CCFLAGS) $< -c - -commandHandler.o: commandHandler.cpp commandHandler.h - $(C++) $(CCFLAGS) $< -c - -callIdQueue.o: callIdQueue.cpp callIdQueue.h - $(C++) $(CCFLAGS) $< -c - -anyrtpproxy.o: anyrtpproxy.cpp - $(C++) $(CCFLAGS) $< -c - -clean: - rm -f *.o - rm -f $(EXECUTABLE) - diff --git a/anyrtpproxy/anyrtpproxy.cpp b/anyrtpproxy/anyrtpproxy.cpp deleted file mode 100644 index d29e4d4..0000000 --- a/anyrtpproxy/anyrtpproxy.cpp +++ /dev/null @@ -1,372 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include - -#include -#include -#include - -#include "../datatypes.h" - -#include "../log.h" -#include "../signalController.h" -#include "../PracticalSocket.h" -#include "../buffer.h" -#include "connectionList.h" -#include "../rtpSessionTable.h" -#include "../syncCommand.h" -#include "../syncQueue.h" -#include "../syncSocketHandler.h" -#include "../syncListenSocket.h" - -#include "../syncSocket.h" -#include "../syncClientSocket.h" -#include "../threadUtils.hpp" - -#include "commandHandler.h" -#include "callIdQueue.h" - -#include "options.h" -#include "portWindow.h" -#include - - -#define MAX_PACKET_SIZE 1500 - - -class ThreadParam -{ -public: - ThreadParam(SyncQueue & queue_,OptionConnectTo & connto_) - : queue(queue_),connto(connto_) - {}; - SyncQueue & queue; - OptionConnectTo & connto; -}; - -class ListenerThreadParam -{ -public: - ListenerThreadParam(UDPSocket& s1, UDPSocket& s2, std::string c, int d, SyncQueue& q) : sock1_(s1), sock2_(s2), call_id_(c), - dir_(d), running_(true), queue_(q) - {}; - - UDPSocket& sock1_; - UDPSocket& sock2_; - std::string call_id_; - int dir_; - bool running_; - SyncQueue& queue_; -}; - -void* listener(void* p) -{ - ListenerThreadParam* param = reinterpret_cast(p); - - cLog.msg(Log::PRIO_NOTICE) << "listener(" << param->call_id_ << "/" << param->dir_ << ") started"; - - try - { - Buffer buf(u_int32_t(MAX_PACKET_SIZE)); - string remote_addr; - u_int16_t remote_port; - while(1) { - buf.setLength(MAX_PACKET_SIZE); - u_int32_t len=0; - if(param->dir_ == 1) - len = param->sock1_.recvFromNonBlocking(buf.getBuf(), buf.getLength(), remote_addr, remote_port, 1000); - else if(param->dir_ == 2) - len = param->sock2_.recvFromNonBlocking(buf.getBuf(), buf.getLength(), remote_addr, remote_port, 1000); - else break; - - RtpSession& session = gRtpSessionTable.getSession(param->call_id_); - if(session.isDead()) { - cLog.msg(Log::PRIO_NOTICE) << "listener(" << param->call_id_ << "/" << param->dir_ << ") session is dead, exiting"; - break; - } - - if(!len) - continue; - buf.setLength(len); - - if((param->dir_ == 1 && (remote_port != session.getRemotePort1() || remote_addr != session.getRemoteAddr1())) || - (param->dir_ == 2 && (remote_port != session.getRemotePort2() || remote_addr != session.getRemoteAddr2()))) - { - if(gOpt.getNat() || - (!gOpt.getNoNatOnce() && ((param->dir_ == 1 && !session.getSeen1()) || - (param->dir_ == 2 && !session.getSeen2())))) - { - cLog.msg(Log::PRIO_NOTICE) << "listener(" << param->call_id_ << "/" << param->dir_ << ") setting remote host to " - << remote_addr << ":" << remote_port; - if(param->dir_ == 1) { - session.setRemotePort1(remote_port); - session.setRemoteAddr1(remote_addr); - } - if(param->dir_ == 2) { - session.setRemotePort2(remote_port); - session.setRemoteAddr2(remote_addr); - } - - if(!gOpt.getNat()) { // with nat enabled sync is not needed - SyncCommand sc(param->call_id_); - param->queue_.push(sc); - } - } - else - continue; - } - session.setSeen1(); - session.setSeen2(); - - if(param->dir_ == 1) - param->sock2_.sendTo(buf.getBuf(), buf.getLength(), session.getRemoteAddr2(), session.getRemotePort2()); - else if(param->dir_ == 2) - param->sock1_.sendTo(buf.getBuf(), buf.getLength(), session.getRemoteAddr1(), session.getRemotePort1()); - else break; - } - } - catch(std::exception &e) - { - cLog.msg(Log::PRIO_ERR) << "listener(" << param->call_id_ << "/" << param->dir_ << ") exiting because: " << e.what(); - } - param->running_ = false; - gCallIdQueue.push(param->call_id_); - pthread_exit(NULL); -} - -class ListenerData -{ -public: - ListenerData(ListenerThreadParam lp1, ListenerThreadParam lp2) : param1_(lp1), param2_(lp2) - {}; - - UDPSocket* sock1_; - UDPSocket* sock2_; - pthread_t thread1_; - pthread_t thread2_; - ListenerThreadParam param1_; - ListenerThreadParam param2_; -}; - -void* listenerManager(void* p) -{ - SyncQueue* queue_ = reinterpret_cast(p); - - std::map listenerMap; - while(1) - { - try - { - std::string call_id = gCallIdQueue.front(); // waits for semaphor and returns next call_id - gCallIdQueue.pop(); - - RtpSession& session = gRtpSessionTable.getSession(call_id); - if(!session.isComplete()) - continue; - - std::map::iterator it; - it = listenerMap.find(call_id); - if(it == listenerMap.end()) // listener Threads not existing yet - { - UDPSocket* sock1 = new UDPSocket(session.getLocalAddr(), session.getLocalPort1()); - UDPSocket* sock2 = new UDPSocket(session.getLocalAddr(), session.getLocalPort2()); - - ListenerData* ld = new ListenerData(ListenerThreadParam(*sock1, *sock2, call_id, 1, *queue_), - ListenerThreadParam(*sock1, *sock2, call_id, 2, *queue_)); - ld->sock1_ = sock1; - ld->sock2_ = sock2; - pthread_create(&(ld->thread1_), NULL, listener, &(ld->param1_)); - pthread_create(&(ld->thread2_), NULL, listener, &(ld->param2_)); - - std::pair::iterator, bool> ret; - ret = listenerMap.insert(std::map::value_type(call_id, ld)); - continue; - } - - if(!it->second->param1_.running_ && !it->second->param2_.running_) - { - cLog.msg(Log::PRIO_NOTICE) << "listenerManager both threads for '" << call_id << "' exited, cleaning up"; - pthread_join(it->second->thread1_, NULL); - pthread_join(it->second->thread2_, NULL); - delete it->second->sock1_; - delete it->second->sock2_; - delete it->second; - listenerMap.erase(it); - gRtpSessionTable.delSession(call_id); - continue; - } - // TODO: reinit if session changed - } - catch(std::exception &e) - { - cLog.msg(Log::PRIO_ERR) << "listenerManager restarting after exception: " << e.what(); - usleep(500); // in case of an hard error don't block cpu (this is ugly) - } - } - cLog.msg(Log::PRIO_ERR) << "listenerManager exiting because of unknown reason"; - pthread_exit(NULL); -} - -void chrootAndDrop(string const& chrootdir, string const& username) -{ - if (getuid() != 0) - { - std::cerr << "this programm has to be run as root in order to run in a chroot" << std::endl; - exit(-1); - } - - struct passwd *pw = getpwnam(username.c_str()); - if(pw) { - if(chroot(chrootdir.c_str())) - { - std::cerr << "can't chroot to " << chrootdir << std::endl; - exit(-1); - } - std::cout << "we are in chroot jail (" << chrootdir << ") now" << std::endl; - chdir("/"); - if (initgroups(pw->pw_name, pw->pw_gid) || setgid(pw->pw_gid) || setuid(pw->pw_uid)) - { - std::cerr << "can't drop to user " << username << " " << pw->pw_uid << ":" << pw->pw_gid << std::endl; - exit(-1); - } - std::cout << "dropped user to " << username << " " << pw->pw_uid << ":" << pw->pw_gid << std::endl; - } - else - { - std::cerr << "unknown user " << username << std::endl; - exit(-1); - } -} - -void daemonize() -{ - pid_t pid; - - pid = fork(); - if(pid) exit(0); - setsid(); - pid = fork(); - if(pid) exit(0); - - std::cout << "running in background now..." << std::endl; - - int fd; - for (fd=getdtablesize();fd>=0;--fd) // close all file descriptors - close(fd); - fd=open("/dev/null",O_RDWR); // stdin - dup(fd); // stdout - dup(fd); // stderr - umask(027); -} - -void* syncConnector(void* p ) -{ - ThreadParam* param = reinterpret_cast(p); - - SocketHandler h; - ConnectionList cl; - SyncClientSocket sock(h,cl); - sock.Open( param->connto.host, param->connto.port); - h.Add(&sock); - while (h.GetCount()) - { - h.Select(); - } - pthread_exit(NULL); -} - -void* syncListener(void* p ) -{ - ThreadParam* param = reinterpret_cast(p); - ConnectionList cl; - - SyncSocketHandler h(param->queue); - SyncListenSocket l(h,cl); - - if (l.Bind(gOpt.getLocalSyncPort())) - pthread_exit(NULL); - - Utility::ResolveLocal(); // resolve local hostname - h.Add(&l); - h.Select(1,0); - while (1) { - h.Select(1,0); - } -} - -int main(int argc, char* argv[]) -{ - std::cout << "anyrtpproxy" << std::endl; - if(!gOpt.parse(argc, argv)) - { - gOpt.printUsage(); - exit(-1); - } - - if(gOpt.getChroot()) - chrootAndDrop(gOpt.getChrootDir(), gOpt.getUsername()); - if(gOpt.getDaemonize()) - daemonize(); - - cLog.setLogName("anyrtpproxy"); - cLog.msg(Log::PRIO_NOTICE) << "anyrtpproxy started..."; - - SignalController sig; - sig.init(); - - SyncQueue queue; - - pthread_t listenerManagerThread; - pthread_create(&listenerManagerThread, NULL, listenerManager, &queue); - pthread_detach(listenerManagerThread); - - pthread_t syncListenerThread; - - ConnectToList connect_to = gOpt.getConnectTo(); - ThreadParam p( queue,*(new OptionConnectTo())); - if ( gOpt.getLocalSyncPort()) - pthread_create(&syncListenerThread, NULL, syncListener, &p); - - std::list connectThreads; - for(ConnectToList::iterator it = connect_to.begin() ;it != connect_to.end(); ++it) - { - connectThreads.push_back(pthread_t()); - ThreadParam * point = new ThreadParam(queue,*it); - pthread_create(& connectThreads.back(), NULL, syncConnector, point); - } - - PortWindow port_window(gOpt.getRtpStartPort(),gOpt.getRtpEndPort()); - CommandHandler cmd(queue, gOpt.getControlInterface().addr_, gOpt.getControlInterface().port_,port_window); - - int ret = sig.run(); - return ret; -} - diff --git a/anyrtpproxy/callIdQueue.cpp b/anyrtpproxy/callIdQueue.cpp deleted file mode 100644 index bc90f08..0000000 --- a/anyrtpproxy/callIdQueue.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "callIdQueue.h" - -CallIdQueue* CallIdQueue::inst = NULL; -Mutex CallIdQueue::instMutex; -CallIdQueue& gCallIdQueue = CallIdQueue::instance(); - -CallIdQueue& CallIdQueue::instance() -{ - Lock lock(instMutex); - static instanceCleaner c; - if(!inst) - inst = new CallIdQueue(); - - return *inst; -} - -CallIdQueue::CallIdQueue() -{ -} - -CallIdQueue::~CallIdQueue() -{ - while(!callids_.empty()) - pop(); -} - -std::string& CallIdQueue::front() -{ - sem_.down(); - Lock lock(mutex_); - return callids_.front(); -} - -void CallIdQueue::push(std::string c) -{ - Lock lock(mutex_); - callids_.push(c); - sem_.up(); -} - -void CallIdQueue::pop() -{ - Lock lock(mutex_); - callids_.pop(); -} - diff --git a/anyrtpproxy/callIdQueue.h b/anyrtpproxy/callIdQueue.h deleted file mode 100644 index 67e543d..0000000 --- a/anyrtpproxy/callIdQueue.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef __CALLID_QUEUE_H__ -#define __CALLID_QUEUE_H__ - -#include -#include - -#include "../threadUtils.hpp" - -class CallIdQueue -{ -public: - static CallIdQueue& instance(); - - std::string& front(); - void push(std::string c); - void pop(); - -private: - CallIdQueue(); - ~CallIdQueue(); - - void operator=(const CallIdQueue &src); - CallIdQueue(const CallIdQueue &src); - - static CallIdQueue* inst; - static ::Mutex instMutex; - class instanceCleaner { - public: ~instanceCleaner() { - if(CallIdQueue::inst != 0) - delete CallIdQueue::inst; - } - }; - friend class instanceCleaner; - - ::Mutex mutex_; - Semaphore sem_; - std::queue callids_; -}; - -extern CallIdQueue& gCallIdQueue; - -#endif diff --git a/anyrtpproxy/commandHandler.cpp b/anyrtpproxy/commandHandler.cpp deleted file mode 100644 index 032d001..0000000 --- a/anyrtpproxy/commandHandler.cpp +++ /dev/null @@ -1,268 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include - -#include -#include - -#include "commandHandler.h" -#include "../buffer.h" -#include "../log.h" -#include "../syncQueue.h" -#include "../syncCommand.h" -#include "../rtpSessionTable.h" -#include "callIdQueue.h" - -#define MAX_COMMAND_LENGTH 1000 - -CommandHandler::CommandHandler(SyncQueue& q, u_int16_t lp,PortWindow & pw) : queue_(q), running_(true), control_sock_(lp), - local_address_("0.0.0.0"), local_port_(lp),port_window_(pw) -{ - pthread_create(&thread_, NULL, run, this); -} - -CommandHandler::CommandHandler(SyncQueue& q, string la, u_int16_t lp,PortWindow & pw) : queue_(q), running_(true), control_sock_(la, lp), - local_address_(la), local_port_(lp),port_window_(pw) -{ - pthread_create(&thread_, NULL, run, this); -} - -CommandHandler::~CommandHandler() -{ - pthread_cancel(thread_); - pthread_join(thread_, NULL); -} - -void* CommandHandler::run(void* s) -{ - CommandHandler* self = reinterpret_cast(s); - - Buffer buf(u_int32_t(MAX_COMMAND_LENGTH)); - try - { - string remote_host; - u_int16_t remote_port; - - int len; - while(1) - { - buf.setLength(MAX_COMMAND_LENGTH); - len = self->control_sock_.recvFrom(buf.getBuf(), buf.getLength(), remote_host, remote_port); - buf.setLength(len); - - std::string ret = self->handle(std::string(reinterpret_cast(buf.getBuf()), buf.getLength())); // TODO: reinterpret is ugly - - cLog.msg(Log::PRIO_DEBUG) << "CommandHandler received Command from " << remote_host << ":" << remote_port - << ", ret='" << ret << "'"; - - self->control_sock_.sendTo(ret.c_str(), ret.length(), remote_host, remote_port); - } - } - catch(SocketException &e) - { - self->running_ = false; - pthread_exit(NULL); - } - self->running_ = false; - pthread_exit(NULL); -} - -bool CommandHandler::isRunning() -{ - return running_; -} - - - -std::string CommandHandler::handle(std::string command) -{ - istringstream iss(command); - ostringstream oss; - std::string cookie; - std::string cmd; - - iss >> cookie; - oss << cookie << " "; - - if(iss.bad() || iss.eof()) { - oss << RET_ERR_SYNTAX; - return oss.str(); - } - iss >> cmd; - - std::vector params; - while(!iss.bad() && !iss.eof()) { - std::string tmp; - iss >> tmp; - params.push_back(tmp); - } - - switch(std::toupper(cmd[0])) - { - case CMD_REQUEST: - if(params.size() < 4) { oss << RET_ERR_SYNTAX; break; } - oss << handleRequest(cmd.erase(0,1), params[0], params[1], params[2], params[3], (params.size() < 5) ? "" : params[4]); - break; - case CMD_RESPONSE: - if(params.size() < 4) { oss << RET_ERR_SYNTAX; break; } - oss << handleResponse(cmd.erase(0,1), params[0], params[1], params[2], params[3], (params.size() < 5) ? "" : params[4]); - break; - case CMD_DELETE: - if(params.size() < 2) { oss << RET_ERR_SYNTAX; break; } - oss << handleDelete(params[0], params[1], (params.size() < 3) ? "" : params[2]); - break; - case CMD_VERSION: - if(cmd.length() > 1 && cmd[1] == 'F') { - if(params.size() < 1) { oss << RET_ERR_SYNTAX; break; } - oss << handleVersionF(params[0]); - break; - } - oss << handleVersion(); - break; - case CMD_INFO: - oss << handleInfo(); - break; - default: - oss << RET_ERR_SYNTAX; - break; - } - - return oss.str(); -} - -string CommandHandler::handleRequest(string modifiers, string call_id, string addr, string port, string from_tag, string to_tag) -{ - std::cout << "received request[" << modifiers << "] command ('" << call_id << "','" << addr << "','" << port - << "','" << from_tag << "','" << to_tag << "')" << std::endl; - - try - { - bool is_new; - RtpSession& session = gRtpSessionTable.getOrNewSession(call_id, is_new); - if(is_new) - { - u_int16_t port1 = port_window_.newPort(); // TODO: get next available port - u_int16_t port2 = port_window_.newPort(); // TODO: get next available port - if( !port1 || !port2) - { - if( port1) port_window_.freePort(port1); - if( port2) port_window_.freePort(port2); - throw std::runtime_error("no free port found"); - } - - session.setLocalAddr("0.0.0.0"); // TODO: read this from config - session.setLocalPort1(port1); - session.setLocalPort2(port2); - } - istringstream iss(port); - u_int16_t rport; - iss >> rport; - session.setRemotePort1(rport); - session.setRemoteAddr1(addr); - - ostringstream oss; - oss << session.getLocalPort2(); - return oss.str(); - } - catch(std::exception& e) - { - return RET_ERR_UNKNOWN; // TODO: change to corret error value - } -} - -string CommandHandler::handleResponse(string modifiers, string call_id, string addr, string port, string from_tag, string to_tag) -{ - std::cout << "received response[" << modifiers << "] command ('" << call_id << "','" << addr << "','" << port - << "','" << from_tag << "','" << to_tag << "')" << std::endl; - - try - { - RtpSession& session = gRtpSessionTable.getSession(call_id); - istringstream iss(port); - u_int16_t rport; - iss >> rport; - session.setRemotePort2(rport); - session.setRemoteAddr2(addr); - session.isComplete(true); - SyncCommand sc(call_id); - queue_.push(sc); - - ostringstream oss; - oss << session.getLocalPort1(); - return oss.str(); - } - catch(std::exception& e) - { - return RET_ERR_UNKNOWN; // TODO: change to corret error value - } -} - -string CommandHandler::handleDelete(string call_id, string from_tag, string to_tag) -{ - std::cout << "received delete command ('" << call_id << "','" << from_tag << "','" << to_tag << "')" << std::endl; - - try - { - RtpSession& session = gRtpSessionTable.getSession(call_id); - session.isDead(true); - SyncCommand sc(call_id); - queue_.push(sc); - - return RET_OK; - } - catch(std::exception& e) - { - return RET_ERR_UNKNOWN; // TODO: change to corret error value - } -} - -string CommandHandler::handleVersion() -{ - std::cout << "received version command" << std::endl; - return BASE_VERSION; -} - -string CommandHandler::handleVersionF(string date_code) -{ - std::cout << "received version[F] command ('" << date_code << "')" << std::endl; - if(!date_code.compare(SUP_VERSION)) - return "1"; - - return "0"; -} - -string CommandHandler::handleInfo() -{ - std::cout << "received info command, ignoring" << std::endl; - return RET_OK; -} - diff --git a/anyrtpproxy/commandHandler.h b/anyrtpproxy/commandHandler.h deleted file mode 100644 index 97082ca..0000000 --- a/anyrtpproxy/commandHandler.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _COMMAND_HANDLER_H_ -#define _COMMAND_HANDLER_H_ - -#include -#include "../datatypes.h" -#include "../PracticalSocket.h" -#include "../syncQueue.h" -#include "portWindow.h" - -using std::string; - -class CommandHandler -{ -public: - CommandHandler(SyncQueue& q, u_int16_t lp, PortWindow &); - CommandHandler(SyncQueue& q, string la, u_int16_t lp, PortWindow &); - ~CommandHandler(); - - bool isRunning(); - - #define CMD_REQUEST 'U' - #define CMD_RESPONSE 'L' - #define CMD_DELETE 'D' - #define CMD_VERSION 'V' - #define CMD_INFO 'I' - - #define RET_OK "0" - #define RET_ERR_SYNTAX "E1" - #define RET_ERR_UNKNOWN "E2" - - #define BASE_VERSION "20040107" - #define SUP_VERSION "20050322" - -private: - CommandHandler(const CommandHandler &c); - void operator=(const CommandHandler &c); - - static void* run(void* s); - string handle(string command); - - string handleRequest(string modifiers, string call_id, string addr, string port, string from_tag, string to_tag); - string handleResponse(string modifiers, string call_id, string addr, string port, string from_tag, string to_tag); - string handleDelete(string call_id, string from_tag, string to_tag); - string handleVersion(); - string handleVersionF(string date_code); - string handleInfo(); - - pthread_t thread_; - SyncQueue& queue_; - - bool running_; - UDPSocket control_sock_; - string local_address_; - u_int16_t local_port_; - PortWindow& port_window_; -}; - - -#endif diff --git a/anyrtpproxy/connectionList.cpp b/anyrtpproxy/connectionList.cpp deleted file mode 100644 index c8bbfa7..0000000 --- a/anyrtpproxy/connectionList.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "connectionList.h" - -ConnectionList::ConnectionList() -{ -} - -ConnectionList::~ConnectionList() -{ -} - -void ConnectionList::addConnection(ConnectionParam &conn, u_int16_t mux ) -{ -} - -const ConnectionMap::iterator ConnectionList::getEnd() -{ - return connections_.end(); -} - -ConnectionMap::iterator ConnectionList::getBeginUnlocked() -{ - return connections_.begin(); -} - -ConnectionMap::iterator ConnectionList::getEndUnlocked() -{ - return connections_.end(); -} - -const ConnectionMap::iterator ConnectionList::getConnection(u_int16_t mux) -{ - Lock lock(mutex_); - ConnectionMap::iterator it = connections_.find(mux); - return it; -} - - -ConnectionParam & ConnectionList::getOrNewConnectionUnlocked(u_int16_t mux) -{ - ConnectionMap::iterator it = connections_.find(mux); - return it->second; -} - -void ConnectionList::clear() -{ - Lock lock(mutex_); - connections_.clear(); -} - -bool ConnectionList::empty() -{ - Lock lock(mutex_); - return connections_.empty(); -} - -Mutex& ConnectionList::getMutex() -{ - return mutex_; -} diff --git a/anyrtpproxy/connectionList.h b/anyrtpproxy/connectionList.h deleted file mode 100644 index 6b02b22..0000000 --- a/anyrtpproxy/connectionList.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _CONNECTION_LIST_H -#define _CONNECTION_LIST_H - -#include - -#include "../threadUtils.hpp" -#include "../datatypes.h" -#include "../connectionParam.h" -#include "../networkAddress.h" -typedef std::map ConnectionMap; - -class ConnectionList -{ -public: - ConnectionList(); - ~ConnectionList(); - void addConnection(ConnectionParam &conn, u_int16_t mux); - const ConnectionMap::iterator getConnection(u_int16_t mux); - const ConnectionMap::iterator getEnd(); - ConnectionMap::iterator getEndUnlocked(); - ConnectionMap::iterator getBeginUnlocked(); - ConnectionParam & getOrNewConnectionUnlocked(u_int16_t mux); - bool empty(); - void clear(); - Mutex& getMutex(); - -private: - ConnectionList(const ConnectionList &s); - void operator=(const ConnectionList &s); - ConnectionMap connections_; - Mutex mutex_; -}; - -#endif diff --git a/anyrtpproxy/options.cpp b/anyrtpproxy/options.cpp deleted file mode 100644 index bdddf75..0000000 --- a/anyrtpproxy/options.cpp +++ /dev/null @@ -1,308 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include -#include - -#include "options.h" - -Options* Options::inst = NULL; -Mutex Options::instMutex; -Options& gOpt = Options::instance(); - -Options& Options::instance() -{ - Lock lock(instMutex); - static instanceCleaner c; - if(!inst) - inst = new Options(); - - return *inst; -} - -Options::Options() : control_interface_("0.0.0.0", 22222) - -{ - progname_ = "anyrtpproxy"; - chroot_ = false; - username_ = "nobody"; - chroot_dir_ = "/var/run"; - daemonize_ = true; - local_sync_port_ = 0; - rtp_start_port_ = 34000; - rtp_end_port_ = 35000; - no_nat_once_ = false; - nat_ = false; -} - -Options::~Options() -{ -} - -#define PARSE_BOOL_PARAM(SHORT, LONG, VALUE) \ - else if(str == SHORT || str == LONG) \ - VALUE = true; - -#define PARSE_INVERSE_BOOL_PARAM(SHORT, LONG, VALUE) \ - else if(str == SHORT || str == LONG) \ - VALUE = false; - -#define PARSE_SCALAR_PARAM(SHORT, LONG, VALUE) \ - else if(str == SHORT || str == LONG) \ - { \ - if(argc < 1 || argv[i+1][0] == '-') \ - return false; \ - std::stringstream tmp; \ - tmp << argv[i+1]; \ - tmp >> VALUE; \ - argc--; \ - i++; \ - } - -#define PARSE_SCALAR_PARAM2(SHORT, LONG, VALUE1, VALUE2) \ - else if(str == SHORT || str == LONG) \ - { \ - if(argc < 2 || \ - argv[i+1][0] == '-' || argv[i+2][0] == '-') \ - return false; \ - std::stringstream tmp; \ - tmp << argv[i+1] << " " << argv[i+2]; \ - tmp >> VALUE1; \ - tmp >> VALUE2; \ - argc-=2; \ - i+=2; \ - } - -#define PARSE_STRING_PARAM(SHORT, LONG, VALUE) \ - else if(str == SHORT || str == LONG) \ - { \ - if(argc < 1 || argv[i+1][0] == '-') \ - return false; \ - VALUE = std::string(argv[i+1]); \ - argc--; \ - i++; \ - } - -#define PARSE_HEXSTRING_PARAM_SEC(SHORT, LONG, VALUE) \ - else if(str == SHORT || str == LONG) \ - { \ - if(argc < 1 || argv[i+1][0] == '-') \ - return false; \ - VALUE = Buffer(std::string(argv[i+1])); \ - for(size_t j=0; j < strlen(argv[i+1]); ++j) \ - argv[i+1][j] = '#'; \ - argc--; \ - i++; \ - } - -#define PARSE_CSLIST_PARAM(SHORT, LONG, LIST) \ - else if(str == SHORT || str == LONG) \ - { \ - if(argc < 1 || argv[i+1][0] == '-') \ - return false; \ - std::stringstream tmp(argv[i+1]); \ - /* LIST.clear(); */ \ - while (tmp.good()) \ - { \ - std::string tmp_line; \ - getline(tmp,tmp_line,','); \ - LIST.push(tmp_line); \ - } \ - argc--; \ - i++; \ - } - -bool Options::parse(int argc, char* argv[]) -{ - Lock lock(mutex); - - progname_ = argv[0]; - std::queue host_port_queue; - argc--; - for(int i=1; argc > 0; ++i) - { - std::string str(argv[i]); - argc--; - - if(str == "-h" || str == "--help") - return false; - PARSE_BOOL_PARAM("-t","--chroot", chroot_) - PARSE_BOOL_PARAM("-n","--nat", nat_) - PARSE_BOOL_PARAM("-o","--no-nat-once", no_nat_once_) - PARSE_SCALAR_PARAM("-u","--user", username_) - PARSE_SCALAR_PARAM("-c","--chroot-dir", chroot_dir_) - PARSE_INVERSE_BOOL_PARAM("-d","--nodaemonize", daemonize_) - PARSE_STRING_PARAM("-s","--control", control_interface_) - PARSE_SCALAR_PARAM2("-p","--port-range", rtp_start_port_, rtp_end_port_) - PARSE_CSLIST_PARAM("-M","--sync-hosts", host_port_queue) - PARSE_SCALAR_PARAM("-S","--sync-port", local_sync_port_) -// PARSE_SCALAR_PARAM("-I","--sync-interface", local_sync_addr_) - else - return false; - } - while(!host_port_queue.empty()) - { - std::stringstream tmp_stream(host_port_queue.front()); - OptionConnectTo oct; - getline(tmp_stream,oct.host,':'); - if(!tmp_stream.good()) - return false; - tmp_stream >> oct.port; - host_port_queue.pop(); - connect_to_.push_back(oct); - } - - return sanityCheck(); -} - -bool Options::sanityCheck() -{ - if(!control_interface_.port_) control_interface_.port_ = 22220; - return true; -} - -void Options::printUsage() -{ - std::cout << "USAGE: anyrtpproxy" << std::endl; - std::cout << " [-h|--help] prints this..." << std::endl; - std::cout << " [-t|--chroot] chroot and drop priviledges" << std::endl; - std::cout << " [-u|--username] in case of chroot run as this user" << std::endl; - std::cout << " [-c|--chroot-dir] directory to make a chroot to" << std::endl; - std::cout << " [-d|--nodaemonize] don't run in background" << std::endl; - std::cout << " [-s|--control] the address/port to listen on for control commands" << std::endl; - std::cout << " [-p|--port-range] port range used to relay rtp connections" << std::endl; - std::cout << " [-n|--nat] enable permantent automatic nat detection(use only with anytun)" << std::endl; - std::cout << " [-o|--no-nat-once] disable automatic nat detection for new connections" << std::endl; -// std::cout << " [-I|--sync-interface] local unicast(sync) ip address to bind to" << std::endl; - std::cout << " [-S|--sync-port] local unicast(sync) port to bind to" << std::endl; - std::cout << " [-M|--sync-hosts] :[,:[...]]"<< std::endl; - std::cout << " List of Remote Sync Hosts/Ports"<< std::endl; -} - -void Options::printOptions() -{ - Lock lock(mutex); - std::cout << "Options:" << std::endl; - std::cout << "chroot='" << chroot_ << "'" << std::endl; - std::cout << "username='" << username_ << "'" << std::endl; - std::cout << "chroot-dir='" << chroot_dir_ << "'" << std::endl; - std::cout << "daemonize='" << daemonize_ << "'" << std::endl; - std::cout << "control-interface='" << control_interface_.toString() << "'" << std::endl; -} - -std::string Options::getProgname() -{ - Lock lock(mutex); - return progname_; -} - -bool Options::getChroot() -{ - Lock lock(mutex); - return chroot_; -} - -bool Options::getNat() -{ - Lock lock(mutex); - return nat_; -} - -bool Options::getNoNatOnce() -{ - Lock lock(mutex); - return no_nat_once_; -} - -std::string Options::getUsername() -{ - Lock lock(mutex); - return username_; -} - -std::string Options::getChrootDir() -{ - Lock lock(mutex); - return chroot_dir_; -} - -bool Options::getDaemonize() -{ - Lock lock(mutex); - return daemonize_; -} - -Host Options::getControlInterface() -{ - Lock lock(mutex); - return control_interface_; -} - -u_int16_t Options::getLocalSyncPort() -{ - return local_sync_port_; -} - -Options& Options::setLocalSyncPort(u_int16_t l) -{ - local_sync_port_ = l; - return *this; -} - -u_int16_t Options::getRtpStartPort() -{ - return rtp_start_port_; -} - -Options& Options::setRtpStartPort(u_int16_t l) -{ - rtp_start_port_ = l; - return *this; -} - -u_int16_t Options::getRtpEndPort() -{ - return rtp_end_port_; -} - -Options& Options::setRtpEndPort(u_int16_t l) -{ - rtp_end_port_ = l; - return *this; -} - -ConnectToList Options::getConnectTo() -{ - Lock lock(mutex); - return connect_to_; -} - diff --git a/anyrtpproxy/options.h b/anyrtpproxy/options.h deleted file mode 100644 index b6ac957..0000000 --- a/anyrtpproxy/options.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _OPTIONS_H_ -#define _OPTIONS_H_ - -#include "../threadUtils.hpp" -#include -#include - -typedef struct OptionConnectTo -{ - std::string host; - uint16_t port; -}; - -typedef std::list ConnectToList; - -class Host -{ -public: - Host(std::string addr, u_int16_t port) : addr_(addr), port_(port) {} - Host(std::string addr_port) - { - std::istringstream iss(addr_port); - getline(iss, addr_, ':'); - if(!(iss >> port_)) port_ = 0; - } - std::string toString() const - { - std::ostringstream oss; - oss << addr_ << ":" << port_; - return oss.str(); - } - - std::string addr_; - u_int16_t port_; -}; - -typedef std::list HostList; - -class Options -{ -public: - static Options& instance(); - - bool parse(int argc, char* argv[]); - void printUsage(); - void printOptions(); - - std::string getProgname(); - bool getChroot(); - bool getNat(); - bool getNoNatOnce(); - std::string getUsername(); - std::string getChrootDir(); - bool getDaemonize(); - Host getControlInterface(); - u_int16_t getLocalSyncPort(); - Options& setLocalSyncPort(u_int16_t l); - u_int16_t getRtpStartPort(); - Options& setRtpStartPort(u_int16_t l); - u_int16_t getRtpEndPort(); - Options& setRtpEndPort(u_int16_t l); - ConnectToList getConnectTo(); - -private: - Options(); - ~Options(); - Options(const Options &l); - void operator=(const Options &l); - bool sanityCheck(); - - static Options* inst; - static ::Mutex instMutex; - class instanceCleaner { - public: ~instanceCleaner() { - if(Options::inst != 0) - delete Options::inst; - } - }; - friend class instanceCleaner; - - ::Mutex mutex; - - std::string progname_; - bool chroot_; - bool nat_; - bool no_nat_once_; - std::string username_; - std::string chroot_dir_; - bool daemonize_; - u_int16_t local_sync_port_; - u_int16_t rtp_start_port_; - u_int16_t rtp_end_port_; - ConnectToList connect_to_; - Host control_interface_; -}; - -extern Options& gOpt; - -#endif diff --git a/anyrtpproxy/portWindow.cpp b/anyrtpproxy/portWindow.cpp deleted file mode 100644 index 3d96a06..0000000 --- a/anyrtpproxy/portWindow.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "portWindow.h" - -PortWindow::PortWindow(u_int16_t start, u_int16_t end) : start_port_(start), end_port_(end) -{ -} - -PortWindow::~PortWindow() -{ -} - -PortWindow::PortSet::size_type PortWindow::getLength() -{ - Lock lock(mutex_); - return ports_.size(); -} - -bool PortWindow::hasPort(u_int16_t port) -{ - Lock lock(mutex_); - - PortSet::const_iterator it=ports_.find(port); - if(it == ports_.end()) - return false; - return true; -} - -bool PortWindow::freePort(u_int16_t port) -{ - Lock lock(mutex_); - - PortSet::iterator it=ports_.find(port); - if(it == ports_.end()) - return false; - ports_.erase(it); - return true; -} - -u_int16_t PortWindow::newPort() -{ - Lock lock(mutex_); - u_int16_t port= start_port_; - while (port=end_port_) - return 0; - ports_.insert(port); - return port; -} - -void PortWindow::clear() -{ - Lock lock(mutex_); - ports_.clear(); -} - diff --git a/anyrtpproxy/portWindow.h b/anyrtpproxy/portWindow.h deleted file mode 100644 index c97e94f..0000000 --- a/anyrtpproxy/portWindow.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _PORT_WINDOW_H_ -#define _PORT_WINDOW_H_ - -#include -#include "../threadUtils.hpp" -#include "../datatypes.h" - -class PortWindow -{ -public: - typedef std::set PortSet; - - PortWindow(u_int16_t,u_int16_t); - ~PortWindow(); - - PortSet::size_type getLength(); - bool hasPort(u_int16_t); - bool freePort(u_int16_t); - u_int16_t newPort(); - void clear(); - - -private: - u_int16_t start_port_; - u_int16_t end_port_; - ::Mutex mutex_; - PortSet ports_; - - PortWindow(const PortWindow &s); - void operator=(const PortWindow &s); -}; - -#endif diff --git a/anytun-config.cpp b/anytun-config.cpp deleted file mode 100644 index 537fc81..0000000 --- a/anytun-config.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include - -#include "datatypes.h" - -#include "log.h" -#include "buffer.h" -#include "keyDerivation.h" -#include "keyDerivationFactory.h" -#include "signalController.h" -#include "anyctrOptions.h" -#include "connectionList.h" -#include "routingTable.h" -#include "networkAddress.h" - -#include "syncQueue.h" -#include "syncSocketHandler.h" -#include "syncListenSocket.h" - -#include "syncSocket.h" -#include "syncClientSocket.h" -#include "syncCommand.h" - - - -void createConnection(const std::string & remote_host, u_int16_t remote_port, ConnectionList & cl, u_int16_t seqSize, SyncQueue & queue, mux_t mux) -{ - SeqWindow * seq = new SeqWindow(seqSize); - seq_nr_t seq_nr_ = 0; - KeyDerivation * kd = KeyDerivationFactory::create( gOpt.getKdPrf() ); - kd->init( gOpt.getKey(), gOpt.getSalt() ); - cLog.msg(Log::PRIO_NOTICE) << "added connection remote host " << remote_host << ":" << remote_port; - ConnectionParam connparam ( (*kd), (*seq), seq_nr_, remote_host, remote_port ); - cl.addConnection( connparam, mux ); - NetworkAddress addr( ipv4, gOpt.getIfconfigParamRemoteNetmask().c_str() ); - NetworkPrefix prefix( addr,gOpt.getNetworkPrefixLength() ); - -//TODO: FIX this not -// prefix.setNetworkPrefixLength(gOpt.getNetworkPrefixLength()); - - gRoutingTable.addRoute( prefix, mux ); - std::ostringstream sout; - boost::archive::text_oarchive oa( sout ); - const SyncCommand scom( cl, mux ); - const SyncCommand scom2( prefix ); - - oa << scom; - std::cout << std::setw(5) << std::setfill('0') << sout.str().size()<< ' ' << sout.str() << std::endl; - std::ostringstream sout2; - boost::archive::text_oarchive oa2( sout2 ); - oa2 << scom2; - std::cout << std::setw(5) << std::setfill('0') << sout2.str().size()<< ' ' << sout2.str() << std::endl; -} - -int main(int argc, char* argv[]) -{ - int ret=0; - if(!gOpt.parse(argc, argv)) - { - gOpt.printUsage(); - exit(-1); - } - - SignalController sig; - sig.init(); - - ConnectionList cl; - SyncQueue queue; - - createConnection(gOpt.getRemoteAddr(),gOpt.getRemotePort(),cl,gOpt.getSeqWindowSize(), queue, gOpt.getMux()); - - return ret; -} - diff --git a/anytun-controld.cpp b/anytun-controld.cpp deleted file mode 100644 index 204694e..0000000 --- a/anytun-controld.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include -#include -#include -#include - -#include "datatypes.h" - -#include "log.h" -#include "signalController.h" -#include "anymuxOptions.h" - -#include "muxSocket.h" -#include "Sockets/ListenSocket.h" -#include "Sockets/SocketHandler.h" - - -class ThreadParam -{ -public: - ThreadParam() : addr(""), port(0) {}; - std::string addr; - u_int16_t port; -}; - - -void* syncListener(void* p ) -{ - ThreadParam* param = reinterpret_cast(p); - SOCKETS_NAMESPACE::SocketHandler h; - SOCKETS_NAMESPACE::ListenSocket l(h,true); - - if( l.Bind(param->addr, param->port) ) - pthread_exit(NULL); - - Utility::ResolveLocal(); // resolve local hostname - h.Add(&l); - h.Select(1,0); - while (1) { - h.Select(1,0); - } -} - -void chrootAndDrop(std::string const& chrootdir, std::string const& username) -{ - if (getuid() != 0) - { - std::cerr << "this programm has to be run as root in order to run in a chroot" << std::endl; - exit(-1); - } - - struct passwd *pw = getpwnam(username.c_str()); - if(pw) { - if(chroot(chrootdir.c_str())) - { - std::cerr << "can't chroot to " << chrootdir << std::endl; - exit(-1); - } - cLog.msg(Log::PRIO_NOTICE) << "we are in chroot jail (" << chrootdir << ") now" << std::endl; - chdir("/"); - if (initgroups(pw->pw_name, pw->pw_gid) || setgid(pw->pw_gid) || setuid(pw->pw_uid)) - { - std::cerr << "can't drop to user " << username << " " << pw->pw_uid << ":" << pw->pw_gid << std::endl; - exit(-1); - } - cLog.msg(Log::PRIO_NOTICE) << "dropped user to " << username << " " << pw->pw_uid << ":" << pw->pw_gid << std::endl; - } - else - { - std::cerr << "unknown user " << username << std::endl; - exit(-1); - } -} - -void daemonize() -{ - pid_t pid; - - pid = fork(); - if(pid) exit(0); - setsid(); - pid = fork(); - if(pid) exit(0); - -// std::cout << "running in background now..." << std::endl; - - int fd; -// for (fd=getdtablesize();fd>=0;--fd) // close all file descriptors - for (fd=0;fd<=2;fd++) // close all file descriptors - close(fd); - fd=open("/dev/null",O_RDWR); // stdin - dup(fd); // stdout - dup(fd); // stderr - umask(027); -} - -int main(int argc, char* argv[]) -{ - if(!gOpt.parse(argc, argv)) - { - gOpt.printUsage(); - exit(-1); - } - - std::ifstream file( gOpt.getFileName().c_str() ); - if( file.is_open() ) - file.close(); - else - { - std::cout << "ERROR: unable to open file!" << std::endl; - exit(-1); - } - - std::ofstream pidFile; - if(gOpt.getPidFile() != "") { - pidFile.open(gOpt.getPidFile().c_str()); - if(!pidFile.is_open()) { - std::cout << "can't open pid file" << std::endl; - } - } - - if(gOpt.getChroot()) - chrootAndDrop(gOpt.getChrootDir(), gOpt.getUsername()); - if(gOpt.getDaemonize()) - daemonize(); - - if(pidFile.is_open()) { - pid_t pid = getpid(); - pidFile << pid; - pidFile.close(); - } - - SignalController sig; - sig.init(); - - ThreadParam p; - p.addr = gOpt.getBindToAddr(); - p.port = gOpt.getBindToPort(); - pthread_t syncListenerThread; - pthread_create(&syncListenerThread, NULL, syncListener, &p); - - int ret = sig.run(); - - pthread_cancel(syncListenerThread); - - pthread_join(syncListenerThread, NULL); - - return ret; -} - diff --git a/anytun-showtables.cpp b/anytun-showtables.cpp deleted file mode 100644 index d9ae096..0000000 --- a/anytun-showtables.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "datatypes.h" - -#include "log.h" -#include "buffer.h" -#include "keyDerivation.h" -#include "options.h" -#include "seqWindow.h" -#include "connectionList.h" -#include "routingTable.h" -#include "networkAddress.h" -#include "syncCommand.h" - -#include -#include -#include - -#include -#include - - -void output(ConnectionList &cl) -{ - if( !cl.empty() ) - { - ConnectionMap::iterator it = cl.getBeginUnlocked(); - mux_t mux = it->first; - ConnectionParam &conn( it->second ); - std::cout << "Client " << mux << ": " ; - if( conn.remote_host_=="") - { - std::cout<< "not registered"; - } else { - std::cout<< conn.remote_host_ << ':'<first ); - std::cout << "Route: " << pref.toString() << "/" << pref.getNetworkPrefixLength() << " -> "; - mux_t mux = it->second; - std::cout << mux << std::endl; - gRoutingTable.clear(); - } -} - -int main(int argc, char* argv[]) -{ - int ret = 0; - if(!gOpt.parse(argc, argv)) - { - gOpt.printUsage(); - exit(-1); - } - - ConnectionList cl; - std::stringstream iss_; - int32_t missing_chars=-1; - int32_t buffer_size_=0; - while( std::cin.good() ) - { - char c; - std::cin.get(c); - iss_ << c; - buffer_size_++; - while (1) - { - if(missing_chars==-1 && buffer_size_>5) - { - char * buffer = new char [6+1]; - iss_.read(buffer,6); - std::stringstream tmp; - tmp.write(buffer,6); - tmp>>missing_chars; - delete[] buffer; - buffer_size_-=6; - } - else if( missing_chars>0 && missing_chars<=buffer_size_ ) - { - char * buffer = new char [missing_chars+1]; - iss_.read(buffer,missing_chars); - std::stringstream tmp; - tmp.write(buffer,missing_chars); - boost::archive::text_iarchive ia(tmp); - SyncCommand scom(cl); - ia >> scom; - buffer_size_-=missing_chars; - missing_chars=-1; - output(cl); - delete[] buffer; - } - else - break; - } - } - return ret; -} - diff --git a/anytun.cpp b/anytun.cpp deleted file mode 100644 index 5100ab8..0000000 --- a/anytun.cpp +++ /dev/null @@ -1,517 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include // for ENOMEM - -#include "datatypes.h" - -#include "log.h" -#include "buffer.h" -#include "plainPacket.h" -#include "encryptedPacket.h" -#include "cipher.h" -#include "keyDerivation.h" -#include "authAlgo.h" -#include "cipherFactory.h" -#include "authAlgoFactory.h" -#include "keyDerivationFactory.h" -#include "signalController.h" -#include "packetSource.h" -#include "tunDevice.h" -#include "options.h" -#include "seqWindow.h" -#include "connectionList.h" -#include "routingTable.h" -#include "networkAddress.h" - -#include "syncQueue.h" -#include "syncSocketHandler.h" -#include "syncListenSocket.h" - -#include "syncSocket.h" -#include "syncClientSocket.h" -#include "syncCommand.h" - -#include "threadParam.h" - -#define MAX_PACKET_LENGTH 1600 - -#define SESSION_KEYLEN_AUTH 20 // TODO: hardcoded size -#define SESSION_KEYLEN_ENCR 16 // TODO: hardcoded size -#define SESSION_KEYLEN_SALT 14 // TODO: hardcoded size - -void createConnection(const std::string & remote_host, u_int16_t remote_port, ConnectionList & cl, u_int16_t seqSize, SyncQueue & queue, mux_t mux) -{ - SeqWindow * seq= new SeqWindow(seqSize); - seq_nr_t seq_nr_=0; - KeyDerivation * kd = KeyDerivationFactory::create(gOpt.getKdPrf()); - kd->init(gOpt.getKey(), gOpt.getSalt()); - cLog.msg(Log::PRIO_NOTICE) << "added connection remote host " << remote_host << ":" << remote_port; - ConnectionParam connparam ( (*kd), (*seq), seq_nr_, remote_host, remote_port); - cl.addConnection(connparam,mux); - NetworkAddress addr(ipv4,gOpt.getIfconfigParamRemoteNetmask().c_str()); - NetworkPrefix prefix(addr,32); - gRoutingTable.addRoute(prefix,mux); - SyncCommand sc (cl,mux); - queue.push(sc); - SyncCommand sc2 (prefix); - queue.push(sc2); -} - -bool checkPacketSeqNr(EncryptedPacket& pack,ConnectionParam& conn) -{ - // compare sender_id and seq with window - if(conn.seq_window_.hasSeqNr(pack.getSenderId(), pack.getSeqNr())) - { - cLog.msg(Log::PRIO_NOTICE) << "Replay attack from " << conn.remote_host_<<":"<< conn.remote_port_ - << " seq:"<(p); - - std::auto_ptr c(CipherFactory::create(gOpt.getCipher())); - std::auto_ptr a(AuthAlgoFactory::create(gOpt.getAuthAlgo()) ); - - PlainPacket plain_packet(MAX_PACKET_LENGTH); - EncryptedPacket encrypted_packet(MAX_PACKET_LENGTH); - - Buffer session_key(u_int32_t(SESSION_KEYLEN_ENCR)); // TODO: hardcoded size - Buffer session_salt(u_int32_t(SESSION_KEYLEN_SALT)); // TODO: hardcoded size - Buffer session_auth_key(u_int32_t(SESSION_KEYLEN_AUTH)); // TODO: hardcoded size - - //TODO replace mux - u_int16_t mux = gOpt.getMux(); - while(1) - { - plain_packet.setLength(MAX_PACKET_LENGTH); - encrypted_packet.withAuthTag(false); - encrypted_packet.setLength(MAX_PACKET_LENGTH); - - // read packet from device - u_int32_t len = param->dev.read(plain_packet.getPayload(), plain_packet.getPayloadLength()); - plain_packet.setPayloadLength(len); - // set payload type - if(param->dev.getType() == TunDevice::TYPE_TUN) - plain_packet.setPayloadType(PAYLOAD_TYPE_TUN); - else if(param->dev.getType() == TunDevice::TYPE_TAP) - plain_packet.setPayloadType(PAYLOAD_TYPE_TAP); - else - plain_packet.setPayloadType(0); - - if(param->cl.empty()) - continue; - //std::cout << "got Packet for plain "< "<cl.getConnection(mux); - if(cit==param->cl.getEnd()) - continue; - ConnectionParam & conn = cit->second; - - if(conn.remote_host_==""||!conn.remote_port_) - continue; - // generate packet-key TODO: do this only when needed - conn.kd_.generate(LABEL_SATP_ENCRYPTION, conn.seq_nr_, session_key); - conn.kd_.generate(LABEL_SATP_SALT, conn.seq_nr_, session_salt); - - c->setKey(session_key); - c->setSalt(session_salt); - - // encrypt packet - c->encrypt(plain_packet, encrypted_packet, conn.seq_nr_, gOpt.getSenderId(), mux); - - encrypted_packet.setHeader(conn.seq_nr_, gOpt.getSenderId(), mux); - conn.seq_nr_++; - - // add authentication tag - if(a->getMaxLength()) { - encrypted_packet.addAuthTag(); - conn.kd_.generate(LABEL_SATP_MSG_AUTH, encrypted_packet.getSeqNr(), session_auth_key); - a->setKey(session_auth_key); - a->generate(encrypted_packet); - } - try - { - param->src.send(encrypted_packet.getBuf(), encrypted_packet.getLength(), conn.remote_host_, conn.remote_port_); - } - catch (Exception e) - { - } - } - pthread_exit(NULL); -} - -void* syncConnector(void* p ) -{ - ThreadParam* param = reinterpret_cast(p); - - SocketHandler h; - SyncClientSocket sock(h,param->cl); - // sock.EnableSSL(); - sock.Open( param->connto.host, param->connto.port); - h.Add(&sock); - while (h.GetCount()) - { - h.Select(); - } - pthread_exit(NULL); -} - -void* syncListener(void* p ) -{ - ThreadParam* param = reinterpret_cast(p); - - SyncSocketHandler h(param->queue); - SyncListenSocket l(h,param->cl); - - if (l.Bind(gOpt.getLocalSyncPort())) - pthread_exit(NULL); - - Utility::ResolveLocal(); // resolve local hostname - h.Add(&l); - h.Select(1,0); - while (1) { - h.Select(1,0); - } -} - -void* receiver(void* p) -{ - ThreadParam* param = reinterpret_cast(p); - - std::auto_ptr c( CipherFactory::create(gOpt.getCipher()) ); - std::auto_ptr a( AuthAlgoFactory::create(gOpt.getAuthAlgo()) ); - - EncryptedPacket encrypted_packet(MAX_PACKET_LENGTH); - PlainPacket plain_packet(MAX_PACKET_LENGTH); - - Buffer session_key(u_int32_t(SESSION_KEYLEN_ENCR)); // TODO: hardcoded size - Buffer session_salt(u_int32_t(SESSION_KEYLEN_SALT)); // TODO: hardcoded size - Buffer session_auth_key(u_int32_t(SESSION_KEYLEN_AUTH)); // TODO: hardcoded size - - while(1) - { - string remote_host; - u_int16_t remote_port; - - plain_packet.setLength(MAX_PACKET_LENGTH); - encrypted_packet.withAuthTag(false); - encrypted_packet.setLength(MAX_PACKET_LENGTH); - - // read packet from socket - u_int32_t len = param->src.recv(encrypted_packet.getBuf(), encrypted_packet.getLength(), remote_host, remote_port); - encrypted_packet.setLength(len); - - mux_t mux = encrypted_packet.getMux(); - // autodetect peer - if(gOpt.getRemoteAddr() == "" && param->cl.empty()) - { - cLog.msg(Log::PRIO_NOTICE) << "autodetected remote host " << remote_host << ":" << remote_port; - createConnection(remote_host, remote_port, param->cl, gOpt.getSeqWindowSize(),param->queue,mux); - } - - ConnectionMap::iterator cit = param->cl.getConnection(mux); - if (cit == param->cl.getEnd()) - continue; - ConnectionParam & conn = cit->second; - - // check whether auth tag is ok or not - if(a->getMaxLength()) { - encrypted_packet.withAuthTag(true); - conn.kd_.generate(LABEL_SATP_MSG_AUTH, encrypted_packet.getSeqNr(), session_auth_key); - a->setKey(session_auth_key); - if(!a->checkTag(encrypted_packet)) { - cLog.msg(Log::PRIO_NOTICE) << "wrong Authentication Tag!" << std::endl; - continue; - } - encrypted_packet.removeAuthTag(); - } - - //Allow dynamic IP changes - //TODO: add command line option to turn this off - if (remote_host != conn.remote_host_ || remote_port != conn.remote_port_) - { - cLog.msg(Log::PRIO_NOTICE) << "connection "<< mux << " autodetected remote host ip changed " << remote_host << ":" << remote_port; - conn.remote_host_=remote_host; - conn.remote_port_=remote_port; - SyncCommand sc (param->cl,mux); - param->queue.push(sc); - } - - // Replay Protection - if (!checkPacketSeqNr(encrypted_packet, conn)) - continue; - - // generate packet-key - conn.kd_.generate(LABEL_SATP_ENCRYPTION, encrypted_packet.getSeqNr(), session_key); - conn.kd_.generate(LABEL_SATP_SALT, encrypted_packet.getSeqNr(), session_salt); - c->setKey(session_key); - c->setSalt(session_salt); - - // decrypt packet - c->decrypt(encrypted_packet, plain_packet); - - // check payload_type - if((param->dev.getType() == TunDevice::TYPE_TUN && plain_packet.getPayloadType() != PAYLOAD_TYPE_TUN4 && - plain_packet.getPayloadType() != PAYLOAD_TYPE_TUN6) || - (param->dev.getType() == TunDevice::TYPE_TAP && plain_packet.getPayloadType() != PAYLOAD_TYPE_TAP)) - continue; - - // write it on the device - param->dev.write(plain_packet.getPayload(), plain_packet.getLength()); - } - pthread_exit(NULL); -} - -#define MIN_GCRYPT_VERSION "1.2.0" -// make libgcrypt thread safe -extern "C" { -GCRY_THREAD_OPTION_PTHREAD_IMPL; -} - -bool initLibGCrypt() -{ - // make libgcrypt thread safe - // this must be called before any other libgcrypt call - gcry_control( GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread ); - - // this must be called right after the GCRYCTL_SET_THREAD_CBS command - // no other function must be called till now - if( !gcry_check_version( MIN_GCRYPT_VERSION ) ) { - std::cout << "initLibGCrypt: Invalid Version of libgcrypt, should be >= " << MIN_GCRYPT_VERSION << std::endl; - return false; - } - - gcry_error_t err = gcry_control (GCRYCTL_DISABLE_SECMEM, 0); - if( err ) { - std::cout << "initLibGCrypt: Failed to disable secure memory: " << gpg_strerror( err ) << std::endl; - return false; - } - - // Tell Libgcrypt that initialization has completed. - err = gcry_control(GCRYCTL_INITIALIZATION_FINISHED); - if( err ) { - std::cout << "initLibGCrypt: Failed to finish the initialization of libgcrypt: " << gpg_strerror( err ) << std::endl; - return false; - } - - cLog.msg(Log::PRIO_NOTICE) << "initLibGCrypt: libgcrypt init finished"; - return true; -} - -void chrootAndDrop(std::string const& chrootdir, std::string const& username) -{ - if (getuid() != 0) - { - std::cerr << "this programm has to be run as root in order to run in a chroot" << std::endl; - exit(-1); - } - - struct passwd *pw = getpwnam(username.c_str()); - if(pw) { - if(chroot(chrootdir.c_str())) - { - std::cerr << "can't chroot to " << chrootdir << std::endl; - exit(-1); - } - cLog.msg(Log::PRIO_NOTICE) << "we are in chroot jail (" << chrootdir << ") now" << std::endl; - chdir("/"); - if (initgroups(pw->pw_name, pw->pw_gid) || setgid(pw->pw_gid) || setuid(pw->pw_uid)) - { - std::cerr << "can't drop to user " << username << " " << pw->pw_uid << ":" << pw->pw_gid << std::endl; - exit(-1); - } - cLog.msg(Log::PRIO_NOTICE) << "dropped user to " << username << " " << pw->pw_uid << ":" << pw->pw_gid << std::endl; - } - else - { - std::cerr << "unknown user " << username << std::endl; - exit(-1); - } -} - -void daemonize() -{ - pid_t pid; - - pid = fork(); - if(pid) exit(0); - setsid(); - pid = fork(); - if(pid) exit(0); - -// std::cout << "running in background now..." << std::endl; - - int fd; -// for (fd=getdtablesize();fd>=0;--fd) // close all file descriptors - for (fd=0;fd<=2;fd++) // close all file descriptors - close(fd); - fd=open("/dev/null",O_RDWR); // stdin - dup(fd); // stdout - dup(fd); // stderr - umask(027); -} - -int execScript(string const& script, string const& ifname) -{ - pid_t pid; - pid = fork(); - if(!pid) { - int fd; - for (fd=getdtablesize();fd>=0;--fd) // close all file descriptors - close(fd); - fd=open("/dev/null",O_RDWR); // stdin - dup(fd); // stdout - dup(fd); // stderr - return execl("/bin/sh", "/bin/sh", script.c_str(), ifname.c_str(), NULL); - } - int status = 0; - waitpid(pid, &status, 0); - return status; -} - -int main(int argc, char* argv[]) -{ -// std::cout << "anytun - secure anycast tunneling protocol" << std::endl; - if(!gOpt.parse(argc, argv)) { - gOpt.printUsage(); - exit(-1); - } - - cLog.msg(Log::PRIO_NOTICE) << "anytun started..."; - - std::ofstream pidFile; - if(gOpt.getPidFile() != "") { - pidFile.open(gOpt.getPidFile().c_str()); - if(!pidFile.is_open()) { - std::cout << "can't open pid file" << std::endl; - } - } - - std::string dev_type(gOpt.getDevType()); - TunDevice dev(gOpt.getDevName().c_str(), dev_type=="" ? NULL : dev_type.c_str(), - gOpt.getIfconfigParamLocal() =="" ? NULL : gOpt.getIfconfigParamLocal().c_str(), - gOpt.getIfconfigParamRemoteNetmask() =="" ? NULL : gOpt.getIfconfigParamRemoteNetmask().c_str()); - cLog.msg(Log::PRIO_NOTICE) << "dev created (opened)"; - cLog.msg(Log::PRIO_NOTICE) << "dev opened - actual name is '" << dev.getActualName() << "'"; - cLog.msg(Log::PRIO_NOTICE) << "dev type is '" << dev.getTypeString() << "'"; - if(gOpt.getPostUpScript() != "") { - int postup_ret = execScript(gOpt.getPostUpScript(), dev.getActualName()); - cLog.msg(Log::PRIO_NOTICE) << "post up script '" << gOpt.getPostUpScript() << "' returned " << postup_ret; - } - - if(gOpt.getChroot()) - chrootAndDrop(gOpt.getChrootDir(), gOpt.getUsername()); - if(gOpt.getDaemonize()) - daemonize(); - - if(pidFile.is_open()) { - pid_t pid = getpid(); - pidFile << pid; - pidFile.close(); - } - - SignalController sig; - sig.init(); - - PacketSource* src; - if(gOpt.getLocalAddr() == "") - src = new UDPPacketSource(gOpt.getLocalPort()); - else - src = new UDPPacketSource(gOpt.getLocalAddr(), gOpt.getLocalPort()); - - ConnectionList cl; - ConnectToList connect_to = gOpt.getConnectTo(); - SyncQueue queue; - - if(gOpt.getRemoteAddr() != "") - createConnection(gOpt.getRemoteAddr(),gOpt.getRemotePort(),cl,gOpt.getSeqWindowSize(), queue, gOpt.getMux()); - - ThreadParam p(dev, *src, cl, queue,*(new OptionConnectTo())); - - // this must be called before any other libgcrypt call - if(!initLibGCrypt()) - return -1; - - pthread_t senderThread; - pthread_create(&senderThread, NULL, sender, &p); - pthread_t receiverThread; - pthread_create(&receiverThread, NULL, receiver, &p); - - pthread_t syncListenerThread; - if ( gOpt.getLocalSyncPort()) - pthread_create(&syncListenerThread, NULL, syncListener, &p); - - std::list connectThreads; - for(ConnectToList::iterator it = connect_to.begin() ;it != connect_to.end(); ++it) { - connectThreads.push_back(pthread_t()); - ThreadParam * point = new ThreadParam(dev, *src, cl, queue,*it); - pthread_create(& connectThreads.back(), NULL, syncConnector, point); - } - - int ret = sig.run(); - - pthread_cancel(senderThread); - pthread_cancel(receiverThread); - if ( gOpt.getLocalSyncPort()) - pthread_cancel(syncListenerThread); - for( std::list::iterator it = connectThreads.begin() ;it != connectThreads.end(); ++it) - pthread_cancel(*it); - - pthread_join(senderThread, NULL); - pthread_join(receiverThread, NULL); - if ( gOpt.getLocalSyncPort()) - pthread_join(syncListenerThread, NULL); - - for( std::list::iterator it = connectThreads.begin() ;it != connectThreads.end(); ++it) - pthread_join(*it, NULL); - - delete src; - delete &p.connto; - - return ret; -} - diff --git a/authAlgo.cpp b/authAlgo.cpp deleted file mode 100644 index 6b1c9ec..0000000 --- a/authAlgo.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "authAlgo.h" -#include "log.h" -#include "buffer.h" -#include "encryptedPacket.h" - -#include - -#include - -//****** NullAuthAlgo ****** -void NullAuthAlgo::generate(EncryptedPacket& packet) -{ -} - -bool NullAuthAlgo::checkTag(EncryptedPacket& packet) -{ - return true; -} - -u_int32_t NullAuthAlgo::getMaxLength() -{ - return MAX_LENGTH_; -} - -//****** Sha1AuthAlgo ****** - -Sha1AuthAlgo::Sha1AuthAlgo() : ctx_(NULL) -{ - gcry_error_t err = gcry_md_open( &ctx_, GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC ); - if( err ) - cLog.msg(Log::PRIO_CRIT) << "Sha1AuthAlgo::Sha1AuthAlgo: Failed to open message digest algo"; -} - -Sha1AuthAlgo::~Sha1AuthAlgo() -{ - if(ctx_) - gcry_md_close( ctx_ ); -} - -void Sha1AuthAlgo::setKey(Buffer& key) -{ - if(!ctx_) - return; - - gcry_error_t err = gcry_md_setkey( ctx_, key.getBuf(), key.getLength() ); - if( err ) - cLog.msg(Log::PRIO_ERR) << "Sha1AuthAlgo::setKey: Failed to set cipher key: " << gpg_strerror( err ); -} - -void Sha1AuthAlgo::generate(EncryptedPacket& packet) -{ - if(!packet.getAuthTagLength()) - return; - - gcry_md_reset( ctx_ ); - - gcry_md_write( ctx_, packet.getAuthenticatedPortion(), packet.getAuthenticatedPortionLength() ); - gcry_md_final( ctx_ ); - - u_int8_t* tag = packet.getAuthTag(); - if(packet.getAuthTagLength() > MAX_LENGTH_) - std::memset(tag, 0, (packet.getAuthTagLength() - MAX_LENGTH_)); - - u_int8_t* hmac = gcry_md_read(ctx_, 0); - u_int32_t length = (packet.getAuthTagLength() < MAX_LENGTH_) ? packet.getAuthTagLength() : MAX_LENGTH_; - std::memcpy(&tag[packet.getAuthTagLength() - length], &hmac[MAX_LENGTH_ - length], length); -} - -bool Sha1AuthAlgo::checkTag(EncryptedPacket& packet) -{ - if(!packet.getAuthTagLength()) - return true; - - gcry_md_reset( ctx_ ); - - gcry_md_write( ctx_, packet.getAuthenticatedPortion(), packet.getAuthenticatedPortionLength() ); - gcry_md_final( ctx_ ); - - u_int8_t* tag = packet.getAuthTag(); - if(packet.getAuthTagLength() > MAX_LENGTH_) - for(u_int32_t i=0; i < (packet.getAuthTagLength() - MAX_LENGTH_); ++i) - if(tag[i]) return false; - - u_int8_t* hmac = gcry_md_read(ctx_, 0); - u_int32_t length = (packet.getAuthTagLength() < MAX_LENGTH_) ? packet.getAuthTagLength() : MAX_LENGTH_; - if(std::memcmp(&tag[packet.getAuthTagLength() - length], &hmac[MAX_LENGTH_ - length], length)) - return false; - - return true; -} - -u_int32_t Sha1AuthAlgo::getMaxLength() -{ - return MAX_LENGTH_; -} diff --git a/authAlgo.h b/authAlgo.h deleted file mode 100644 index b0832a5..0000000 --- a/authAlgo.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _AUTHALGO_H_ -#define _AUTHALGO_H_ - -#include "datatypes.h" -#include "buffer.h" -#include "encryptedPacket.h" - -#include - -class AuthAlgo -{ -public: - AuthAlgo() {}; - virtual ~AuthAlgo() {}; - - /** - * set the key for the auth algo - * @param key key for hmac calculation - */ - virtual void setKey(Buffer& key) = 0; - - /** - * generate the mac - * @param packet the packet to be authenticated - */ - virtual void generate(EncryptedPacket& packet) = 0; - - /** - * check the mac - * @param packet the packet to be authenticated - */ - virtual bool checkTag(EncryptedPacket& packet) = 0; - - /** - * get the maximum size of the auth algo - */ - virtual u_int32_t getMaxLength() = 0; -}; - -//****** NullAuthAlgo ****** - -class NullAuthAlgo : public AuthAlgo -{ -public: - void setKey(Buffer& key) {}; - void generate(EncryptedPacket& packet); - bool checkTag(EncryptedPacket& packet); - u_int32_t getMaxLength(); - - static const u_int32_t MAX_LENGTH_ = 0; -}; - - -//****** Sha1AuthAlgo ****** -//* HMAC SHA1 Auth Tag Generator Class - -class Sha1AuthAlgo : public AuthAlgo -{ -public: - Sha1AuthAlgo(); - ~Sha1AuthAlgo(); - - void setKey(Buffer& key); - void generate(EncryptedPacket& packet); - bool checkTag(EncryptedPacket& packet); - u_int32_t getMaxLength(); - - static const u_int32_t MAX_LENGTH_ = 20; - -private: - gcry_md_hd_t ctx_; -}; - -#endif diff --git a/authAlgoFactory.cpp b/authAlgoFactory.cpp deleted file mode 100644 index 262d7c3..0000000 --- a/authAlgoFactory.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include - -#include "authAlgoFactory.h" -#include "authAlgo.h" - - -AuthAlgo* AuthAlgoFactory::create(std::string const& type) -{ - if( type == "null" ) - return new NullAuthAlgo(); - else if( type == "sha1" ) - return new Sha1AuthAlgo(); - else - throw std::invalid_argument("auth algo not available"); -} - diff --git a/authAlgoFactory.h b/authAlgoFactory.h deleted file mode 100644 index 716e800..0000000 --- a/authAlgoFactory.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _AUTHALGO_FACTORY_H_ -#define _AUTHALGO_FACTORY_H_ - -#include - -#include "datatypes.h" -#include "authAlgo.h" - -class AuthAlgoFactory -{ -public: - static AuthAlgo* create(std::string const& type); - -private: - AuthAlgoFactory(); - AuthAlgoFactory(const AuthAlgoFactory& src); - void operator=(const AuthAlgoFactory& src); - ~AuthAlgoFactory(); -}; - -#endif diff --git a/buffer.cpp b/buffer.cpp deleted file mode 100644 index 250a806..0000000 --- a/buffer.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include -#include -#include -#include -#include "datatypes.h" -#include "buffer.h" - -Buffer::Buffer(bool allow_realloc) : buf_(0), length_(0), real_length_(0), allow_realloc_(allow_realloc) -{ -} - -Buffer::Buffer(u_int32_t length, bool allow_realloc) : length_(length), real_length_(length_ + Buffer::OVER_SIZE_), - allow_realloc_(allow_realloc) -{ - buf_ = new u_int8_t[real_length_]; - if(!buf_) { - length_ = 0; - real_length_ = 0; - throw std::bad_alloc(); - } - std::memset(buf_, 0, real_length_); -} - -Buffer::Buffer(u_int8_t* data, u_int32_t length, bool allow_realloc) : length_(length), real_length_(length + Buffer::OVER_SIZE_), - allow_realloc_(allow_realloc) -{ - if(!data) { - length_ = 0; - real_length_ = 0; - return; - } - - buf_ = new u_int8_t[real_length_]; - if(!buf_) { - length_ = 0; - real_length_ = 0; - throw std::bad_alloc(); - } - std::memcpy(buf_, data, length_); -} - -Buffer::Buffer(std::string hex_data, bool allow_realloc) : length_(hex_data.size()/2), - real_length_(length_ + Buffer::OVER_SIZE_), - allow_realloc_(allow_realloc) -{ - buf_ = new u_int8_t[real_length_]; - if(!buf_) { - length_ = 0; - real_length_ = 0; - throw std::bad_alloc(); - } - - for(u_int32_t i=0; i> std::hex >> tmp)) tmp = 0; - buf_[i] = tmp; - } -} - -Buffer::~Buffer() -{ - if(buf_) - delete[] buf_; -} - -Buffer::Buffer(const Buffer &src) : length_(src.length_), real_length_(src.real_length_), allow_realloc_(src.allow_realloc_) -{ - buf_ = new u_int8_t[real_length_]; - if(!buf_) { - length_ = 0; - real_length_ = 0; - throw std::bad_alloc(); - } - std::memcpy(buf_, src.buf_, length_); -} - -void Buffer::operator=(const Buffer &src) -{ - if(buf_) - delete[] buf_; - - length_ = src.length_; - real_length_ = src.real_length_; - allow_realloc_ = src.allow_realloc_; - - buf_ = new u_int8_t[real_length_]; - if(!buf_) { - length_ = 0; - real_length_ = 0; - throw std::bad_alloc(); - } - std::memcpy(buf_, src.buf_, length_); -} - - - -bool Buffer::operator==(const Buffer &cmp) const -{ - if(length_ != cmp.length_) - return false; - - if(!std::memcmp(buf_, cmp.buf_, length_)) - return true; - - return false; -} - -Buffer Buffer::operator^(const Buffer &xor_by) const -{ - u_int32_t res_length = (xor_by.length_ > length_) ? xor_by.length_ : length_; - u_int32_t min_length = (xor_by.length_ < length_) ? xor_by.length_ : length_; - Buffer res(res_length); - - for( u_int32_t index = 0; index < min_length; index++ ) - res[index] = buf_[index] ^ xor_by[index]; - - return res; -} - -u_int32_t Buffer::getLength() const -{ - return length_; -} - -void Buffer::setLength(u_int32_t new_length) -{ - if(new_length == length_) - return; - - if(new_length > real_length_) - { - if(!allow_realloc_) - throw std::out_of_range("buffer::setLength() - reallocation not allowed for this Buffer"); - - u_int8_t* old_buf = buf_; - u_int32_t old_length = length_; - - length_ = new_length; - real_length_ = length_ + Buffer::OVER_SIZE_; - - buf_ = new u_int8_t[real_length_]; - if(!buf_) { - length_ = 0; - real_length_ = 0; - if(old_buf) - delete[] old_buf; - - throw std::bad_alloc(); - } - std::memcpy(buf_, old_buf, old_length); - - if(old_buf) - delete[] old_buf; - - old_buf = &buf_[old_length]; - std::memset(old_buf, 0, real_length_ - old_length); - } - else - length_ = new_length; - - reinit(); -} - - -u_int8_t* Buffer::getBuf() -{ - return buf_; -} - -u_int8_t& Buffer::operator[](u_int32_t index) -{ - if(index >= length_) - throw std::out_of_range("buffer::operator[]"); - - return buf_[index]; -} - -u_int8_t Buffer::operator[](u_int32_t index) const -{ - if(index >= length_) - throw std::out_of_range("buffer::operator[] const"); - - return buf_[index]; -} - -Buffer::operator u_int8_t*() -{ - return buf_; -} - -std::string Buffer::getHexDump() const -{ - std::stringstream ss; - ss << "Length=" << length_ << std::endl << std::hex << std::uppercase; - for( u_int32_t index = 0; index < length_; index++ ) - { - ss << std::setw(2) << std::setfill('0') << u_int32_t(buf_[index]) << " "; - if(!((index+1) % 16)) { - ss << std::endl; - continue; - } - if(!((index+1) % 8)) - ss << " "; - } - return ss.str(); -} - -std::string Buffer::getHexDumpOneLine() const -{ - std::stringstream ss; - ss << length_ << " Bytes,'" << std::hex << std::uppercase; - for( u_int32_t index = 0; index < length_; index++ ) - { - ss << std::setw(2) << std::setfill('0') << u_int32_t(buf_[index]); - } - ss << "'"; - return ss.str(); -} - -bool Buffer::isReallocAllowed() const -{ - return allow_realloc_; -} diff --git a/buffer.h b/buffer.h deleted file mode 100644 index f2078be..0000000 --- a/buffer.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _BUFFER_H_ -#define _BUFFER_H_ - -#include "datatypes.h" -#include - -class TunDevice; -class UDPPacketSource; - -class Buffer -{ -public: - Buffer(bool allow_realloc = true); - Buffer(u_int32_t length, bool allow_realloc = true); - Buffer(u_int8_t* data, u_int32_t length, bool allow_realloc = true); - Buffer(std::string hex_data, bool allow_realloc = true); - virtual ~Buffer(); - Buffer(const Buffer &src); - void operator=(const Buffer &src); - bool operator==(const Buffer &cmp) const; - Buffer operator^(const Buffer &xor_by) const; - - u_int32_t getLength() const; - virtual void setLength(u_int32_t new_length); - u_int8_t* getBuf(); - u_int8_t& operator[](u_int32_t index); - u_int8_t operator[](u_int32_t index) const; - std::string getHexDump() const; - std::string getHexDumpOneLine() const; - - bool isReallocAllowed() const; - - operator u_int8_t*(); - -protected: - virtual void reinit() {}; - - u_int8_t *buf_; - u_int32_t length_; - u_int32_t real_length_; - bool allow_realloc_; - - static const u_int32_t OVER_SIZE_ = 100; -}; - -#endif diff --git a/cipher.cpp b/cipher.cpp deleted file mode 100644 index e98bc3b..0000000 --- a/cipher.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include -#include -#include - -#include "cipher.h" -#include "mpi.h" -#include "log.h" - - - // TODO: in should be const but does not work with getBuf() :( -void Cipher::encrypt(PlainPacket & in, EncryptedPacket & out, seq_nr_t seq_nr, sender_id_t sender_id, mux_t mux) -{ - u_int32_t len = cipher(in, in.getLength(), out.getPayload(), out.getPayloadLength(), seq_nr, sender_id, mux); - out.setSenderId(sender_id); - out.setSeqNr(seq_nr); - out.setMux(mux); - out.setPayloadLength(len); -} - - // TODO: in should be const but does not work with getBuf() :( -void Cipher::decrypt(EncryptedPacket & in, PlainPacket & out) -{ - u_int32_t len = decipher(in.getPayload() , in.getPayloadLength(), out, out.getLength(), in.getSeqNr(), in.getSenderId(), in.getMux()); - out.setLength(len); -} - - -//******* NullCipher ******* - -u_int32_t NullCipher::cipher(u_int8_t* in, u_int32_t ilen, u_int8_t* out, u_int32_t olen, seq_nr_t seq_nr, sender_id_t sender_id, mux_t mux) -{ - std::memcpy(out, in, (ilen < olen) ? ilen : olen); - return (ilen < olen) ? ilen : olen; -} - -u_int32_t NullCipher::decipher(u_int8_t* in, u_int32_t ilen, u_int8_t* out, u_int32_t olen, seq_nr_t seq_nr, sender_id_t sender_id, mux_t mux) -{ - std::memcpy(out, in, (ilen < olen) ? ilen : olen); - return (ilen < olen) ? ilen : olen; -} - - -//****** AesIcmCipher ****** - -AesIcmCipher::AesIcmCipher() : cipher_(NULL) -{ - // TODO: hardcoded keysize - gcry_error_t err = gcry_cipher_open( &cipher_, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CTR, 0 ); - if( err ) - cLog.msg(Log::PRIO_CRIT) << "AesIcmCipher::AesIcmCipher: Failed to open cipher"; -} - - -AesIcmCipher::~AesIcmCipher() -{ - if(cipher_) - gcry_cipher_close( cipher_ ); -} - -void AesIcmCipher::setKey(Buffer& key) -{ - if(!cipher_) - return; - - gcry_error_t err = gcry_cipher_setkey( cipher_, key.getBuf(), key.getLength() ); - if( err ) - cLog.msg(Log::PRIO_ERR) << "AesIcmCipher::setKey: Failed to set cipher key: " << gpg_strerror( err ); -} - -void AesIcmCipher::setSalt(Buffer& salt) -{ - salt_ = salt; - if(!salt_[u_int32_t(0)]) - salt_[u_int32_t(0)] = 1; // TODO: this is a outstandingly ugly workaround -} - -u_int32_t AesIcmCipher::cipher(u_int8_t* in, u_int32_t ilen, u_int8_t* out, u_int32_t olen, seq_nr_t seq_nr, sender_id_t sender_id, mux_t mux) -{ - calc(in, ilen, out, olen, seq_nr, sender_id, mux); - return (ilen < olen) ? ilen : olen; -} - -u_int32_t AesIcmCipher::decipher(u_int8_t* in, u_int32_t ilen, u_int8_t* out, u_int32_t olen, seq_nr_t seq_nr, sender_id_t sender_id, mux_t mux) -{ - calc(in, ilen, out, olen, seq_nr, sender_id, mux); - return (ilen < olen) ? ilen : olen; -} - -void AesIcmCipher::calc(u_int8_t* in, u_int32_t ilen, u_int8_t* out, u_int32_t olen, seq_nr_t seq_nr, sender_id_t sender_id, mux_t mux) -{ - if(!cipher_) - return; - - gcry_error_t err = gcry_cipher_reset( cipher_ ); - if( err ) { - cLog.msg(Log::PRIO_ERR) << "AesIcmCipher: Failed to reset cipher: " << gpg_strerror( err ); - return; - } - - // set the IV ( = CTR) - //========================================================================== - // // where the 128-bit integer value IV SHALL be defined by the SSRC, the - // // SRTP packet index i, and the SRTP session salting key k_s, as below. - // // - // // IV = (k_s * 2^16) XOR (SSRC * 2^64) XOR (i * 2^16) - // // sizeof(k_s) = 112 bit, random - - Mpi ctr(128); // TODO: hardcoded size - Mpi salt(salt_.getBuf(), salt_.getLength()); - Mpi sid_mux(32); - sid_mux = sender_id; - Mpi mux_mpi(32); - mux_mpi = mux; - sid_mux = sid_mux ^ mux_mpi.mul2exp(16); - Mpi seq(32); - seq = seq_nr; - - ctr = salt.mul2exp(16) ^ sid_mux.mul2exp(64) ^ seq.mul2exp(16); // TODO: hardcoded size - - size_t written; - u_int8_t *ctr_buf = ctr.getNewBuf(&written); // TODO: hardcoded size - err = gcry_cipher_setctr( cipher_, ctr_buf, written ); // TODO: hardcoded size - delete[] ctr_buf; - if( err ) { - cLog.msg(Log::PRIO_ERR) << "AesIcmCipher: Failed to set cipher CTR: " << gpg_strerror( err ); - return; - } - - err = gcry_cipher_encrypt( cipher_, out, olen, in, ilen ); - if( err ) { - cLog.msg(Log::PRIO_ERR) << "AesIcmCipher: Failed to generate cipher bitstream: " << gpg_strerror( err ); - return; - } -} - diff --git a/cipher.h b/cipher.h deleted file mode 100644 index 4acd601..0000000 --- a/cipher.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _CIPHER_H_ -#define _CIPHER_H_ - -#include "datatypes.h" -#include "buffer.h" -#include "encryptedPacket.h" -#include "plainPacket.h" - -#include - - -class Cipher -{ -public: - virtual ~Cipher() {}; - - // TODO: in should be const but does not work with getBuf() :( - void encrypt(PlainPacket & in, EncryptedPacket & out, seq_nr_t seq_nr, sender_id_t sender_id, mux_t mux); - void decrypt(EncryptedPacket & in, PlainPacket & out); - - virtual void setKey(Buffer& key) = 0; - virtual void setSalt(Buffer& salt) = 0; - -protected: - virtual u_int32_t cipher(u_int8_t* in, u_int32_t ilen, u_int8_t* out, u_int32_t olen, seq_nr_t seq_nr, sender_id_t sender_id, mux_t mux) = 0; - virtual u_int32_t decipher(u_int8_t* in, u_int32_t ilen, u_int8_t* out, u_int32_t olen, seq_nr_t seq_nr, sender_id_t sender_id, mux_t mux) = 0; -}; - -//****** NullCipher ****** - -class NullCipher : public Cipher -{ -public: - void setKey(Buffer& key) {}; - void setSalt(Buffer& salt) {}; - -protected: - u_int32_t cipher(u_int8_t* in, u_int32_t ilen, u_int8_t* out, u_int32_t olen, seq_nr_t seq_nr, sender_id_t sender_id, mux_t mux); - u_int32_t decipher(u_int8_t* in, u_int32_t ilen, u_int8_t* out, u_int32_t olen, seq_nr_t seq_nr, sender_id_t sender_id, mux_t mux); -}; - -//****** AesIcmCipher ****** - -class AesIcmCipher : public Cipher -{ -public: - AesIcmCipher(); - ~AesIcmCipher(); - void setKey(Buffer& key); - void setSalt(Buffer& salt); - -protected: - u_int32_t cipher(u_int8_t* in, u_int32_t ilen, u_int8_t* out, u_int32_t olen, seq_nr_t seq_nr, sender_id_t sender_id, mux_t mux); - u_int32_t decipher(u_int8_t* in, u_int32_t ilen, u_int8_t* out, u_int32_t olen, seq_nr_t seq_nr, sender_id_t sender_id, mux_t mux); - -private: - void calc(u_int8_t* in, u_int32_t ilen, u_int8_t* out, u_int32_t olen, seq_nr_t seq_nr, sender_id_t sender_id, mux_t mux); - - gcry_cipher_hd_t cipher_; - Buffer salt_; -}; - - -#endif diff --git a/cipherFactory.cpp b/cipherFactory.cpp deleted file mode 100644 index 5d7de85..0000000 --- a/cipherFactory.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include - -#include "cipherFactory.h" -#include "cipher.h" - - -Cipher* CipherFactory::create(std::string const& type) -{ - if( type == "null" ) - return new NullCipher(); - else if( type == "aes-ctr" ) - return new AesIcmCipher(); - else - throw std::invalid_argument("cipher not available"); -} - diff --git a/cipherFactory.h b/cipherFactory.h deleted file mode 100644 index b48d7d0..0000000 --- a/cipherFactory.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _CIPHER_FACTORY_H_ -#define _CIPHER_FACTORY_H_ - -#include - -#include "datatypes.h" -#include "cipher.h" - -class CipherFactory -{ -public: - static Cipher* create(std::string const& type); - -private: - CipherFactory(); - CipherFactory(const CipherFactory& src); - void operator=(const CipherFactory& src); - ~CipherFactory(); -}; - -#endif diff --git a/configure b/configure deleted file mode 100755 index 11cf0e1..0000000 --- a/configure +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -cd openvpn -./configure --disable-lzo --disable-crypto -cd .. - diff --git a/connectionList.cpp b/connectionList.cpp deleted file mode 100644 index 3c86d71..0000000 --- a/connectionList.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "threadUtils.hpp" -#include "datatypes.h" -#include "keyDerivationFactory.h" -#include "options.h" - -#include "connectionList.h" - -ConnectionList::ConnectionList() -{ -} - -ConnectionList::~ConnectionList() -{ -/* Lock lock(mutex_); - ConnectionMap::iterator it; - for(it = connections_.begin(); it != connections_.end(); ++it) - { - //delete &it->second.kd_; - } -*/ -} - -void ConnectionList::addConnection(ConnectionParam &conn, u_int16_t mux ) -{ - Lock lock(mutex_); - - std::pair ret = connections_.insert(ConnectionMap::value_type(mux, conn)); - if(!ret.second) - { - connections_.erase(ret.first); - connections_.insert(ConnectionMap::value_type(mux, conn)); - } -} - -const ConnectionMap::iterator ConnectionList::getEnd() -{ - return connections_.end(); -} - -ConnectionMap::iterator ConnectionList::getBeginUnlocked() -{ - return connections_.begin(); -} - -ConnectionMap::iterator ConnectionList::getEndUnlocked() -{ - return connections_.end(); -} - -const ConnectionMap::iterator ConnectionList::getConnection(u_int16_t mux) -{ - Lock lock(mutex_); - ConnectionMap::iterator it = connections_.find(mux); - return it; -} - - -ConnectionParam & ConnectionList::getOrNewConnectionUnlocked(u_int16_t mux) -{ - ConnectionMap::iterator it = connections_.find(mux); - if(it!=connections_.end()) - return it->second; - - uint8_t key[] = { - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', - 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p' - }; - - uint8_t salt[] = { - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', - 'i', 'j', 'k', 'l', 'm', 'n' - }; - - SeqWindow * seq= new SeqWindow(0); - seq_nr_t seq_nr_=0; - KeyDerivation * kd = KeyDerivationFactory::create(gOpt.getKdPrf()); - kd->init(Buffer(key, sizeof(key)), Buffer(salt, sizeof(salt))); - ConnectionParam conn ( (*kd), (*seq), seq_nr_, "", 0); - connections_.insert(ConnectionMap::value_type(mux, conn)); - it = connections_.find(mux); - return it->second; -} - -void ConnectionList::clear() -{ - Lock lock(mutex_); - connections_.clear(); -} - -bool ConnectionList::empty() -{ - Lock lock(mutex_); - return connections_.empty(); -} - -Mutex& ConnectionList::getMutex() -{ - return mutex_; -} diff --git a/connectionList.h b/connectionList.h deleted file mode 100644 index 5d4d70a..0000000 --- a/connectionList.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _CONNECTION_LIST_H -#define _CONNECTION_LIST_H - -#include -#include - -#include "threadUtils.hpp" -#include "datatypes.h" -#include "connectionParam.h" -#include "networkAddress.h" -typedef std::map ConnectionMap; - -class ConnectionList -{ -public: - ConnectionList(); - ~ConnectionList(); - void addConnection(ConnectionParam &conn, u_int16_t mux); - const ConnectionMap::iterator getConnection(u_int16_t mux); - const ConnectionMap::iterator getEnd(); - ConnectionMap::iterator getEndUnlocked(); - ConnectionMap::iterator getBeginUnlocked(); - ConnectionParam & getOrNewConnectionUnlocked(u_int16_t mux); - bool empty(); - void clear(); - Mutex& getMutex(); - -private: - ConnectionList(const ConnectionList &s); - void operator=(const ConnectionList &s); - ConnectionMap connections_; - Mutex mutex_; -}; - -#endif diff --git a/connectionParam.cpp b/connectionParam.cpp deleted file mode 100644 index 3f4b880..0000000 --- a/connectionParam.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "connectionParam.h" - -//ConnectionParam::ConnectionParam():kd_(*(new KeyDerivation)),seq_window_(*(new SeqWindow(0))),seq_nr_(0),remote_host_(""),remote_port_(0) -//{ -//} - -ConnectionParam::ConnectionParam(KeyDerivation& kd, SeqWindow& seq_window,seq_nr_t seq_nr, std::string remote_host, u_int16_t remote_port) : kd_(kd),seq_window_(seq_window),seq_nr_(seq_nr),remote_host_(remote_host), remote_port_(remote_port) -{ -} - -ConnectionParam::ConnectionParam(const ConnectionParam & src) : kd_(src.kd_),seq_window_(src.seq_window_),seq_nr_(src.seq_nr_),remote_host_(src.remote_host_), remote_port_(src.remote_port_),mutex_() -{ -} diff --git a/connectionParam.h b/connectionParam.h deleted file mode 100644 index 1002b23..0000000 --- a/connectionParam.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _CONNECTIONPARAM_H_ -#define _CONNECTIONPARAM_H_ - -#include "keyDerivation.h" -#include "cipher.h" -#include "authAlgo.h" -#include "seqWindow.h" -#include "threadUtils.hpp" - -#include -#include - -class ConnectionParam -{ -public: - ConnectionParam(const ConnectionParam & src); - ConnectionParam( KeyDerivation& kd, SeqWindow& seq_window, seq_nr_t seq_nr_, std::string remote_host, u_int16_t remote_port); - - KeyDerivation& kd_; - SeqWindow& seq_window_; - seq_nr_t seq_nr_; - std::string remote_host_; - u_int16_t remote_port_; - -private: - //TODO: check if this is ok - Mutex mutex_; - friend class boost::serialization::access; - template - void serialize(Archive & ar, const unsigned int version) - { - Lock lock(mutex_); - ar & kd_; - ar & seq_window_; - ar & seq_nr_; - ar & remote_host_; - ar & remote_port_; - } -}; - -#endif diff --git a/datatypes.h b/datatypes.h deleted file mode 100644 index 29ac8a7..0000000 --- a/datatypes.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _DATATYPES_H_ -#define _DATATYPES_H_ - -#include - -typedef uint8_t u_int8_t; -typedef uint16_t u_int16_t; -typedef uint32_t u_int32_t; -typedef uint64_t u_int64_t; - -typedef u_int32_t window_size_t; - -typedef u_int32_t seq_nr_t; -#define SEQ_NR_T_NTOH(a) ntohl(a) -#define SEQ_NR_T_HTON(a) htonl(a) - -typedef u_int16_t sender_id_t; -#define SENDER_ID_T_NTOH(a) ntohs(a) -#define SENDER_ID_T_HTON(a) htons(a) - -typedef u_int16_t payload_type_t; -#define PAYLOAD_TYPE_T_NTOH(a) ntohs(a) -#define PAYLOAD_TYPE_T_HTON(a) htons(a) - -typedef u_int16_t mux_t; -#define MUX_T_NTOH(a) ntohs(a) -#define MUX_T_HTON(a) htons(a) - -//typedef u_int32_t auth_tag_t; -//#define AUTH_TAG_T_NTOH(a) ntohl(a) -//#define AUTH_TAG_T_HTON(a) htonl(a) -// -#endif diff --git a/draft-gsenger-secure-anycast-tunneling-protocol-02.html b/draft-gsenger-secure-anycast-tunneling-protocol-02.html deleted file mode 100644 index 80ab6c9..0000000 --- a/draft-gsenger-secure-anycast-tunneling-protocol-02.html +++ /dev/null @@ -1,696 +0,0 @@ - -secure anycast tunneling protocol (SATP) - - - - - - - -
 TOC 
-
- - - - -
Network Working GroupO. Gsenger
Internet-DraftJanuary 2008
Intended status: Informational 
Expires: July 4, 2008 
-


secure anycast tunneling protocol (SATP)
draft-gsenger-secure-anycast-tunneling-protocol-01

- -

Status of this Memo

-

-By submitting this Internet-Draft, -each author represents that any applicable patent or other IPR claims of which -he or she is aware have been or will be disclosed, -and any of which he or she becomes aware will be disclosed, -in accordance with Section 6 of BCP 79.

-

-Internet-Drafts are working documents of the Internet Engineering -Task Force (IETF), its areas, and its working groups. -Note that other groups may also distribute working documents as -Internet-Drafts.

-

-Internet-Drafts are draft documents valid for a maximum of six months -and may be updated, replaced, or obsoleted by other documents at any time. -It is inappropriate to use Internet-Drafts as reference material or to cite -them other than as “work in progress.”

-

-The list of current Internet-Drafts can be accessed at -http://www.ietf.org/ietf/1id-abstracts.txt.

-

-The list of Internet-Draft Shadow Directories can be accessed at -http://www.ietf.org/shadow.html.

-

-This Internet-Draft will expire on July 4, 2008.

- -

Copyright Notice

-

-Copyright © The Internet Society (2008).

- -

Abstract

- -

The secure anycast tunneling protocol (SATP) defines a protocol used for communication between any combination of unicast and anycast tunnel endpoints. It allows tunneling of every ETHER TYPE protocol (ethernet, ip ...). SATP directly includes cryptography and message authentication based on the methodes used by SRTP. It can be used as an encrypted alternative to IP Encapsulation within IP (Perkins, C., “IP Encapsulation within IP,” October 1996.) [3] and Generic Routing Encapsulation (GRE) (Farinacci, D., Li, T., Hanks, S., Meyer, D., and P. Traina, “Generic Routing Encapsulation (GRE),” March 2000.) [4]. It supports both anycast receivers and senders. - -



-

Table of Contents

-

-1.  -Introduction
-    1.1.  -Notational Conventions
-2.  -Motivation and usage scenarios
-    2.1.  -Usage scenarions
-        2.1.1.  -Tunneling from unicast hosts over anycast routers to other unicast hosts
-        2.1.2.  -Tunneling from unicast hosts to anycast networks
-        2.1.3.  -Redundant tunnel connection of 2 networks
-    2.2.  -Encapsulation
-3.  -Using SATP on top of IP
-    3.1.  -Fragmentation
-    3.2.  -ICMP messages
-4.  -Protocol specification
-    4.1.  -Header format
-    4.2.  -sequence number
-    4.3.  -sender ID
-    4.4.  -MUX
-    4.5.  -payload type field
-    4.6.  -payload
-    4.7.  -padding (OPTIONAL)
-    4.8.  -padding count (OPTIONAL)
-    4.9.  -MKI (OPTIONAL)
-    4.10.  -authentication tag (RECOMMENDED)
-    4.11.  -Encryption
-5.  -Security Considerations
-    5.1.  -Replay protection
-6.  -IANA Considerations
-7.  -References
-    7.1.  -Normative References
-    7.2.  -Informational References
-§  -Author's Address
-§  -Intellectual Property and Copyright Statements
-

-
- -

-
 TOC 
-

1.  -Introduction

- -

SATP is a mixture of a generic encapsulation protocol like GRE (Farinacci, D., Li, T., Hanks, S., Meyer, D., and P. Traina, “Generic Routing Encapsulation (GRE),” March 2000.) [4] and a secure tunneling protocol as IPsec (Kent, S. and R. Atkinson, “Security Architecture for the Internet Protocol,” November 1998.) [5] in tunnel mode. It can be used to build redundant virtual private network (VPN) connections. It supports peer to peer tunnels, where tunnel endpoints can be any combination of unicast, multicast or anycast hosts, so it defines a Host Anycast Service (Partridge, C., Mendez, T., and W. Milliken, “Host Anycasting Service,” November 1993.) [6]. Encryption is done per packet, so the protocol is robust against packet loss and routing changes. - To save some header overhead it uses the encryption techniques of SRTP (Baugher, M., McGrew, D., Naslund, M., Carrara, E., and K. Norrman, “The Secure Real-time Transport Protocol (SRTP),” March 2004.) [1]. - -

-

-
 TOC 
-

1.1.  -Notational Conventions

- -

The keywords "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC2119 (Bradner, S., “Key words for use in RFCs to Indicate Requirement Levels,” March 1997.) [2]. -

-

-
 TOC 
-

2.  -Motivation and usage scenarios

- -

This section gives an overview of possible usage scenarios. Please note, that the protocols used in the figures are only examples and that SATP itself does not care about either transport protocols or encapsulated protocols. Routing is not done by SATP and each implemetation MAY choose it's own way of doing this task (e.g. using functions provided by the operating system). SATP is used only to encapsulate and encrypt data. -

-

-
 TOC 
-

2.1.  -Usage scenarions

- -

-
 TOC 
-

2.1.1.  -Tunneling from unicast hosts over anycast routers to other unicast hosts

-

- - -

An example of SATP used to tunnel in a unicast client - anycast server model -

-                    --------- router -----------
-                   /                            \
-    unicast ------+---------- router ------------+------ unicast
-    host           \                            /        host
-                    --------- router -----------
-
-  unicast  | encrypted     |  anycast  | encrypted     |  unicast
-  tunnel   | communication |  tunnel   | communication |  tunnel
-  endpoint | using SATP    |  endpoint | using SATP    |  endpoint
-
 Figure 1 

- -

In this scenario the payload gets encapsuleted into a SATP packet by a unicast host and gets transmitted to one of the anycast routers. It than gets decapsulated by the router. This router makes a routing descision based on the underlying protocol and transmits a new SATP package to one or more unicast hosts depending on the routing decision. -

-

-
 TOC 
-

2.1.2.  -Tunneling from unicast hosts to anycast networks

-

- - -

An example of SATP used to encrypt data between a unicast host and anycast networks -

-                       -------Router -+---- DNS Server
-                      /                \
-                     /                  --- 6to4 Router
-                    /
-    unicast -------+----------Router --+--- DNS Server
-    host            \                   \
-                     \                   --- 6to4 Router
-                      \
-                       -------Router -+---- DNS Server
-                                       \
-                                        --- 6to4 Router
-
-  unicast  | encrypted     |  anycast  | plaintext
-  tunnel   | communication |  tunnel   | anycast
-  endpoint | using SATP    |  endpoint | services
-
-
 Figure 2 

- -

When the unicast hosts wants to transmit data to one of the anycast DNS servers, it encapsulates the data and sends a SATP packet to the anycast address of the routers. The packet arrives at one of the routers, gets decapsulated and routed to the DNS server. This method can be used to tunnel between a clients and networks providing anycast services. It can also be used the other way to virtually locate a unicast service within anycasted networks. -

-

-
 TOC 
-

2.1.3.  -Redundant tunnel connection of 2 networks

-

- - -

An example of SATP used to connect 2 networks -

-              Router -----------   ---------------Router
-            /                   \ /                     \
-    Network - Router ------------x                       Network
-       A    \                   / \                     /   B
-              Router -----------   ---------------Router
-
-            | packets       |  packets  |  packets      |
- plaintext  | get           |  take a   |  get          | plaintext
- packets    | de/encrypted  |  random   |  de/encrypted | packets
-            |de/encapsulated|   path    |de/encapsulated|
-
-
 Figure 3 

- -

Network A has multiple routers, that act as gateway/tunnel endpoints to another network B. This is done to build a redundant encrypted tunnel connection between the two networks. All tunnel endpoints of network A share the same anycast address and all tunnel endpoints of network B share another anycast address. When a packet from network A gets transmitted to network B, it first arrives on one of network A's border routers. Which router is used is determined by network A's internal routing. This router encapsulates the package and sends it to the anycast address of the network B routers. The SATP packet arrives at one of network B's routers and gets decapsulated and routed to it's destination within network B. -

-

-
 TOC 
-

2.2.  -Encapsulation

- -

SATP does not depend on which lower layer protocols is used, but this section gives an example of how packets could look like. - -



- - -

Examples of SATP used with different lower layer and payload protocols -

-    +------+-----+-------------------------------+
-    |      |     |      +----------------+-----+ |
-    | IPv6 | UDP | SATP | Ethernet 802.3 | ... | |
-    |      |     |      +----------------+-----+ |
-    +------+-----+-------------------------------+
-
-Tunneling of Ethernet over UDP/IPv6
-
-    +------+-----+---------------------------+
-    |      |     |      +------+-----+-----+ |
-    | IPv4 | UDP | SATP | IPv6 | UDP | RTP | |
-    |      |     |      +------+-----+-----+ |
-    +------+-----+---------------------------+
-
-Tunneling of IPv6 over UDP/IPv4 with RTP payload
-
-    +------+-------------------------------+
-    |      |      +----------------+-----+ |
-    | IPv6 | SATP | Ethernet 802.3 | ... | |
-    |      |      +----------------+-----+ |
-    +------+-------------------------------+
-
-Tunneling of Ethernet over IPv6
-
-    +------+---------------------------+
-    |      |      +------+-----+-----+ |
-    | IPv4 | SATP | IPv6 | UDP | RTP | |
-    |      |      +------+-----+-----+ |
-    +------+---------------------------+
-
-Tunneling of IPv6 over IPv4 with RTP payload
-
 Figure 4 

- -

-
 TOC 
-

3.  -Using SATP on top of IP

- -

-
 TOC 
-

3.1.  -Fragmentation

- -

- The only way of fully supporting fragmentation would be to synchronise fragments between all anycast servers. This is considered to be too much overhead, so there are two non perfect solutions for these problems. Either fragmentation HAS TO be disabled or if not all fragments arrive at the same server the ip datagramm HAS TO be discarded. As routing changes are not expected to occure very frequently, the encapsulated protocol can do a retransmission and all fragments will arrive at the new server. - -

-

If the payload type is IP and the ip headers's Don't Fragment (DF) bit is set, than the DF bit of the outer IP header HAS TO be set as well. -

-

-
 TOC 
-

3.2.  -ICMP messages

- -

ICMP messages MUST be relayed according to rfc2003 section 4 (Perkins, C., “IP Encapsulation within IP,” October 1996.) [3]. This is needed for path MTU detection. -

-

-
 TOC 
-

4.  -Protocol specification

- -

-
 TOC 
-

4.1.  -Header format

-

- - -

Protocol Format -

-      0                   1                   2                   3
-      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
-     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-     |                         sequence number                       | |
-     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
-     |           sender ID           |              MUX              | |
-   +#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+ |
-   | |         payload type          |                               | |
-   | +-------------------------------+                               | |
-   | |              ....        payload        ...                   | |
-   | |                               +-------------------------------+ |
-   | |                               | padding (OPT) | pad count(OPT)| |
-   +#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+-+
-   | ~                          MKI (OPTIONAL)                       ~ |
-   | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
-   | :                 authentication tag (RECOMMENDED)              : |
-   | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
-   |                                                                   |
-   +- Encrypted Portion                       Authenticated Portion ---+
-
 Figure 5 

- -

-

-

-
 TOC 
-

4.2.  -sequence number

- -

The sequence number is a 32 bit unsigned integer in network byte order. It starts with a random value and is increased by 1 for every sent packet. After the maximum value, it starts over from 0. This overrun causes the ROC to be increased. -

-

-
 TOC 
-

4.3.  -sender ID

- -

The sender ID is a 16 bit unsigned integer. It HAS TO be unique for every sender sharing the same anycast address -

-

-
 TOC 
-

4.4.  -MUX

- -

The MUX (multiplex) field is a 16 bit unsigned integer. It is used to destinguish multible tunnel connections. -

-

-
 TOC 
-

4.5.  -payload type field

- -

The payload type field defines the payload protocol. ETHER TYPE protocol numbers are used. See IANA assigned ethernet numbers . The values 0000-05DC are reserverd and MUST NOT be used. -


- - -

Some examples for protocol types -

-HEX
-0000 Reserved
-.... Reserved
-05DC Reserved
-0800 Internet IP (IPv4)
-6558 transparent ethernet bridging
-86DD IPv6
-
 Figure 6 

- - - -

-
 TOC 
-

4.6.  -payload

- -

A packet of the type payload type (e.g. an IP packet). -

-

-
 TOC 
-

4.7.  -padding (OPTIONAL)

- -

Padding of max 255 octets. -None of the pre-defined encryption transforms uses any padding; for - these, the plaintext and encrypted payload sizes match exactly. Transforms are based on transforms of the SRTP protocol and these transforms might use the RTP padding format, so a RTP like padding is supported. If the padding count field is present, than the padding count field MUST be set to the padding length. -

-

-
 TOC 
-

4.8.  -padding count (OPTIONAL)

- -

The number of octets of the padding field. This field is optional. It's presence is signaled by the key management and not by this protocol. If this field isn't present, the padding field MUST NOT be present as well. -

-

-
 TOC 
-

4.9.  -MKI (OPTIONAL)

- -

The MKI (Master Key Identifier) is OPTIONAL and of configurable length. See SRTP Section 3.1 (Baugher, M., McGrew, D., Naslund, M., Carrara, E., and K. Norrman, “The Secure Real-time Transport Protocol (SRTP),” March 2004.) [1] for details -

-

-
 TOC 
-

4.10.  -authentication tag (RECOMMENDED)

- -

The authentication tag is RECOMMENDED and of configurable length. It contains a cryptographic checksum of the sender ID, sequence number and the encrypted portion, but not of the MKI. On sender side encryption HAS TO be done before calculating the authentication tag. A receiver HAS TO calculate the authentication tag before decrypting the encrypted portion. -

-

-
 TOC 
-

4.11.  -Encryption

- -

Encryption is done in the same way as for SRTP (Baugher, M., McGrew, D., Naslund, M., Carrara, E., and K. Norrman, “The Secure Real-time Transport Protocol (SRTP),” March 2004.) [1]. This section will only discuss some small changes that HAVE TO be made. Please read SRTP RFC3711 section 3-9 (Baugher, M., McGrew, D., Naslund, M., Carrara, E., and K. Norrman, “The Secure Real-time Transport Protocol (SRTP),” March 2004.) [1] for details. -

-

The least significant bits of SSRC are replaced by the sender ID and the most significant bits are replaced by the mux. For the SRTP SEQ the 16 least significant bits of the SATP sequence number are used and the 16 most significant bits of the sequence number replace the 16 least significant bits of the SRTP ROC. -



- - -

Difference between SRTP and SATP -

-      0                   1                   2                   3
-      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
-     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-     |                     SATP    sequence number                   |
-     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-                                     =
-     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-     |  SRTP ROC least significant   |           SRTP SEQ            |
-     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-
-
-      0                   1                   2                   3
-      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
-     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-     |           SATP  MUX           |       SATP sender ID          |
-     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-                                     =
-     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-     |                           SRTP SSRC                           |
-     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-
 Figure 7 

- -

-
 TOC 
-

5.  -Security Considerations

- -

As SATP uses the same encryption techniques as SRTP (Baugher, M., McGrew, D., Naslund, M., Carrara, E., and K. Norrman, “The Secure Real-time Transport Protocol (SRTP),” March 2004.) [1], it shares the same security issues. This section will only discuss some small changes. Please read SRTP RFC3711 section 9 (Baugher, M., McGrew, D., Naslund, M., Carrara, E., and K. Norrman, “The Secure Real-time Transport Protocol (SRTP),” March 2004.) [1] for details. -

-

-
 TOC 
-

5.1.  -Replay protection

- -

Replay protection is done by a replay list. Every anycast receiver has it's own replay list, which SHOULDN'T be syncronised, because of massive overhead. This leads to an additional possible attack. A attacker is able to replay a captured packet once to every anycast receiver. This attack is considered of be very unlikely, because multiple attack hosts in different loactions are needed to reach the seperate anycast receivers and the number of replays is limited to the count of receivers - 1. Such replays might also happen because of routing problems, so a payload protocol HAS TO be robust against a small number of duplicated packages. The window size and position HAS TO be syncronised between multible anycast receivers to limit this attack. -

-

-
 TOC 
-

6.  -IANA Considerations

- -

The protocol is intended to be used on top of IP or on top of UDP (to be compatible with NAT routers), so UDP and IP protocol numbers have to be assiged by IANA. -

-

-
 TOC 
-

7.  -References

- -

-
 TOC 
-

7.1. Normative References

- - - - - - - -
[1]Baugher, M., McGrew, D., Naslund, M., Carrara, E., and K. Norrman, “The Secure Real-time Transport Protocol (SRTP),” RFC 3711, March 2004.
[2]Bradner, S., “Key words for use in RFCs to Indicate Requirement Levels,” BCP 14, RFC 2119, March 1997 (TXT, HTML, XML).
[3]Perkins, C., “IP Encapsulation within IP,” RFC 2003, October 1996 (TXT, HTML, XML).
- -

-
 TOC 
-

7.2. Informational References

- - - - - - - -
[4]Farinacci, D., Li, T., Hanks, S., Meyer, D., and P. Traina, “Generic Routing Encapsulation (GRE),” RFC 2784, March 2000.
[5]Kent, S. and R. Atkinson, “Security Architecture for the Internet Protocol,” RFC 2401, November 1998 (TXT, HTML, XML).
[6]Partridge, C., Mendez, T., and W. Milliken, “Host Anycasting Service,” RFC 1546, November 1993.
- -

-
 TOC 
-

Author's Address

- - - - - - - - - - - - - - - -
 Othmar Gsenger
 Puerstingerstr 32
 Saalfelden 5760
 AT
Phone: 
Email: satp@gsenger.com
URI: http://www.gsenger.com/satp/
-

-
 TOC 
-

Full Copyright Statement

- - - -

Intellectual Property

- - - -

Acknowledgment

- - diff --git a/draft-gsenger-secure-anycast-tunneling-protocol-02.txt b/draft-gsenger-secure-anycast-tunneling-protocol-02.txt deleted file mode 100644 index 0a63c6f..0000000 --- a/draft-gsenger-secure-anycast-tunneling-protocol-02.txt +++ /dev/null @@ -1,952 +0,0 @@ - - - -Network Working Group O. Gsenger -Internet-Draft January 2008 -Intended status: Informational -Expires: July 4, 2008 - - - secure anycast tunneling protocol (SATP) - draft-gsenger-secure-anycast-tunneling-protocol-01 - -Status of this Memo - - By submitting this Internet-Draft, each author represents that any - applicable patent or other IPR claims of which he or she is aware - have been or will be disclosed, and any of which he or she becomes - aware will be disclosed, in accordance with Section 6 of BCP 79. - - Internet-Drafts are working documents of the Internet Engineering - Task Force (IETF), its areas, and its working groups. Note that - other groups may also distribute working documents as Internet- - Drafts. - - Internet-Drafts are draft documents valid for a maximum of six months - and may be updated, replaced, or obsoleted by other documents at any - time. It is inappropriate to use Internet-Drafts as reference - material or to cite them other than as "work in progress." - - The list of current Internet-Drafts can be accessed at - http://www.ietf.org/ietf/1id-abstracts.txt. - - The list of Internet-Draft Shadow Directories can be accessed at - http://www.ietf.org/shadow.html. - - This Internet-Draft will expire on July 4, 2008. - -Copyright Notice - - Copyright (C) The Internet Society (2008). - - - - - - - - - - - - - - -Gsenger Expires July 4, 2008 [Page 1] - -Internet-Draft secure anycast tunneling protocol (SATP) January 2008 - - -Abstract - - The secure anycast tunneling protocol (SATP) defines a protocol used - for communication between any combination of unicast and anycast - tunnel endpoints. It allows tunneling of every ETHER TYPE protocol - (ethernet, ip ...). SATP directly includes cryptography and message - authentication based on the methodes used by SRTP. It can be used as - an encrypted alternative to IP Encapsulation within IP [3] and - Generic Routing Encapsulation (GRE) [4]. It supports both anycast - receivers and senders. - - -Table of Contents - - 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3 - 1.1. Notational Conventions . . . . . . . . . . . . . . . . . . 3 - 2. Motivation and usage scenarios . . . . . . . . . . . . . . . . 4 - 2.1. Usage scenarions . . . . . . . . . . . . . . . . . . . . . 4 - 2.1.1. Tunneling from unicast hosts over anycast routers - to other unicast hosts . . . . . . . . . . . . . . . . 4 - 2.1.2. Tunneling from unicast hosts to anycast networks . . . 5 - 2.1.3. Redundant tunnel connection of 2 networks . . . . . . 5 - 2.2. Encapsulation . . . . . . . . . . . . . . . . . . . . . . 6 - 3. Using SATP on top of IP . . . . . . . . . . . . . . . . . . . 8 - 3.1. Fragmentation . . . . . . . . . . . . . . . . . . . . . . 8 - 3.2. ICMP messages . . . . . . . . . . . . . . . . . . . . . . 8 - 4. Protocol specification . . . . . . . . . . . . . . . . . . . . 9 - 4.1. Header format . . . . . . . . . . . . . . . . . . . . . . 9 - 4.2. sequence number . . . . . . . . . . . . . . . . . . . . . 9 - 4.3. sender ID . . . . . . . . . . . . . . . . . . . . . . . . 9 - 4.4. MUX . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 - 4.5. payload type field . . . . . . . . . . . . . . . . . . . . 10 - 4.6. payload . . . . . . . . . . . . . . . . . . . . . . . . . 10 - 4.7. padding (OPTIONAL) . . . . . . . . . . . . . . . . . . . . 10 - 4.8. padding count (OPTIONAL) . . . . . . . . . . . . . . . . . 10 - 4.9. MKI (OPTIONAL) . . . . . . . . . . . . . . . . . . . . . . 10 - 4.10. authentication tag (RECOMMENDED) . . . . . . . . . . . . . 10 - 4.11. Encryption . . . . . . . . . . . . . . . . . . . . . . . . 11 - 5. Security Considerations . . . . . . . . . . . . . . . . . . . 12 - 5.1. Replay protection . . . . . . . . . . . . . . . . . . . . 12 - 6. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 13 - 7. References . . . . . . . . . . . . . . . . . . . . . . . . . . 14 - 7.1. Normative References . . . . . . . . . . . . . . . . . . . 14 - 7.2. Informational References . . . . . . . . . . . . . . . . . 14 - Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 16 - Intellectual Property and Copyright Statements . . . . . . . . . . 17 - - - - - -Gsenger Expires July 4, 2008 [Page 2] - -Internet-Draft secure anycast tunneling protocol (SATP) January 2008 - - -1. Introduction - - SATP is a mixture of a generic encapsulation protocol like GRE [4] - and a secure tunneling protocol as IPsec [5] in tunnel mode. It can - be used to build redundant virtual private network (VPN) connections. - It supports peer to peer tunnels, where tunnel endpoints can be any - combination of unicast, multicast or anycast hosts, so it defines a - Host Anycast Service [6]. Encryption is done per packet, so the - protocol is robust against packet loss and routing changes. To save - some header overhead it uses the encryption techniques of SRTP [1]. - -1.1. Notational Conventions - - The keywords "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", - "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this - document are to be interpreted as described in RFC2119 [2]. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Gsenger Expires July 4, 2008 [Page 3] - -Internet-Draft secure anycast tunneling protocol (SATP) January 2008 - - -2. Motivation and usage scenarios - - This section gives an overview of possible usage scenarios. Please - note, that the protocols used in the figures are only examples and - that SATP itself does not care about either transport protocols or - encapsulated protocols. Routing is not done by SATP and each - implemetation MAY choose it's own way of doing this task (e.g. using - functions provided by the operating system). SATP is used only to - encapsulate and encrypt data. - -2.1. Usage scenarions - -2.1.1. Tunneling from unicast hosts over anycast routers to other - unicast hosts - - An example of SATP used to tunnel in a unicast client - anycast - server model - - --------- router ----------- - / \ - unicast ------+---------- router ------------+------ unicast - host \ / host - --------- router ----------- - - unicast | encrypted | anycast | encrypted | unicast - tunnel | communication | tunnel | communication | tunnel - endpoint | using SATP | endpoint | using SATP | endpoint - - Figure 1 - - In this scenario the payload gets encapsuleted into a SATP packet by - a unicast host and gets transmitted to one of the anycast routers. - It than gets decapsulated by the router. This router makes a routing - descision based on the underlying protocol and transmits a new SATP - package to one or more unicast hosts depending on the routing - decision. - - - - - - - - - - - - - - - -Gsenger Expires July 4, 2008 [Page 4] - -Internet-Draft secure anycast tunneling protocol (SATP) January 2008 - - -2.1.2. Tunneling from unicast hosts to anycast networks - - An example of SATP used to encrypt data between a unicast host and - anycast networks - - -------Router -+---- DNS Server - / \ - / --- 6to4 Router - / - unicast -------+----------Router --+--- DNS Server - host \ \ - \ --- 6to4 Router - \ - -------Router -+---- DNS Server - \ - --- 6to4 Router - - unicast | encrypted | anycast | plaintext - tunnel | communication | tunnel | anycast - endpoint | using SATP | endpoint | services - - - Figure 2 - - When the unicast hosts wants to transmit data to one of the anycast - DNS servers, it encapsulates the data and sends a SATP packet to the - anycast address of the routers. The packet arrives at one of the - routers, gets decapsulated and routed to the DNS server. This method - can be used to tunnel between a clients and networks providing - anycast services. It can also be used the other way to virtually - locate a unicast service within anycasted networks. - -2.1.3. Redundant tunnel connection of 2 networks - - An example of SATP used to connect 2 networks - - Router ----------- ---------------Router - / \ / \ - Network - Router ------------x Network - A \ / \ / B - Router ----------- ---------------Router - - | packets | packets | packets | - plaintext | get | take a | get | plaintext - packets | de/encrypted | random | de/encrypted | packets - |de/encapsulated| path |de/encapsulated| - - - - - -Gsenger Expires July 4, 2008 [Page 5] - -Internet-Draft secure anycast tunneling protocol (SATP) January 2008 - - - Figure 3 - - Network A has multiple routers, that act as gateway/tunnel endpoints - to another network B. This is done to build a redundant encrypted - tunnel connection between the two networks. All tunnel endpoints of - network A share the same anycast address and all tunnel endpoints of - network B share another anycast address. When a packet from network - A gets transmitted to network B, it first arrives on one of network - A's border routers. Which router is used is determined by network - A's internal routing. This router encapsulates the package and sends - it to the anycast address of the network B routers. The SATP packet - arrives at one of network B's routers and gets decapsulated and - routed to it's destination within network B. - -2.2. Encapsulation - - SATP does not depend on which lower layer protocols is used, but this - section gives an example of how packets could look like. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Gsenger Expires July 4, 2008 [Page 6] - -Internet-Draft secure anycast tunneling protocol (SATP) January 2008 - - - Examples of SATP used with different lower layer and payload - protocols - - +------+-----+-------------------------------+ - | | | +----------------+-----+ | - | IPv6 | UDP | SATP | Ethernet 802.3 | ... | | - | | | +----------------+-----+ | - +------+-----+-------------------------------+ - - Tunneling of Ethernet over UDP/IPv6 - - +------+-----+---------------------------+ - | | | +------+-----+-----+ | - | IPv4 | UDP | SATP | IPv6 | UDP | RTP | | - | | | +------+-----+-----+ | - +------+-----+---------------------------+ - - Tunneling of IPv6 over UDP/IPv4 with RTP payload - - +------+-------------------------------+ - | | +----------------+-----+ | - | IPv6 | SATP | Ethernet 802.3 | ... | | - | | +----------------+-----+ | - +------+-------------------------------+ - - Tunneling of Ethernet over IPv6 - - +------+---------------------------+ - | | +------+-----+-----+ | - | IPv4 | SATP | IPv6 | UDP | RTP | | - | | +------+-----+-----+ | - +------+---------------------------+ - - Tunneling of IPv6 over IPv4 with RTP payload - - Figure 4 - - - - - - - - - - - - - - - -Gsenger Expires July 4, 2008 [Page 7] - -Internet-Draft secure anycast tunneling protocol (SATP) January 2008 - - -3. Using SATP on top of IP - -3.1. Fragmentation - - The only way of fully supporting fragmentation would be to - synchronise fragments between all anycast servers. This is - considered to be too much overhead, so there are two non perfect - solutions for these problems. Either fragmentation HAS TO be - disabled or if not all fragments arrive at the same server the ip - datagramm HAS TO be discarded. As routing changes are not expected - to occure very frequently, the encapsulated protocol can do a - retransmission and all fragments will arrive at the new server. - - If the payload type is IP and the ip headers's Don't Fragment (DF) - bit is set, than the DF bit of the outer IP header HAS TO be set as - well. - -3.2. ICMP messages - - ICMP messages MUST be relayed according to rfc2003 section 4 [3]. - This is needed for path MTU detection. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Gsenger Expires July 4, 2008 [Page 8] - -Internet-Draft secure anycast tunneling protocol (SATP) January 2008 - - -4. Protocol specification - -4.1. Header format - - Protocol Format - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | sequence number | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | - | sender ID | MUX | | - +#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+ | - | | payload type | | | - | +-------------------------------+ | | - | | .... payload ... | | - | | +-------------------------------+ | - | | | padding (OPT) | pad count(OPT)| | - +#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+-+ - | ~ MKI (OPTIONAL) ~ | - | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | - | : authentication tag (RECOMMENDED) : | - | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | - | | - +- Encrypted Portion Authenticated Portion ---+ - - Figure 5 - -4.2. sequence number - - The sequence number is a 32 bit unsigned integer in network byte - order. It starts with a random value and is increased by 1 for every - sent packet. After the maximum value, it starts over from 0. This - overrun causes the ROC to be increased. - -4.3. sender ID - - The sender ID is a 16 bit unsigned integer. It HAS TO be unique for - every sender sharing the same anycast address - -4.4. MUX - - The MUX (multiplex) field is a 16 bit unsigned integer. It is used - to destinguish multible tunnel connections. - - - - - - - -Gsenger Expires July 4, 2008 [Page 9] - -Internet-Draft secure anycast tunneling protocol (SATP) January 2008 - - -4.5. payload type field - - The payload type field defines the payload protocol. ETHER TYPE - protocol numbers are used. See IANA assigned ethernet numbers [7] . - The values 0000-05DC are reserverd and MUST NOT be used. - - Some examples for protocol types - - HEX - 0000 Reserved - .... Reserved - 05DC Reserved - 0800 Internet IP (IPv4) - 6558 transparent ethernet bridging - 86DD IPv6 - - Figure 6 - -4.6. payload - - A packet of the type payload type (e.g. an IP packet). - -4.7. padding (OPTIONAL) - - Padding of max 255 octets. None of the pre-defined encryption - transforms uses any padding; for these, the plaintext and encrypted - payload sizes match exactly. Transforms are based on transforms of - the SRTP protocol and these transforms might use the RTP padding - format, so a RTP like padding is supported. If the padding count - field is present, than the padding count field MUST be set to the - padding length. - -4.8. padding count (OPTIONAL) - - The number of octets of the padding field. This field is optional. - It's presence is signaled by the key management and not by this - protocol. If this field isn't present, the padding field MUST NOT be - present as well. - -4.9. MKI (OPTIONAL) - - The MKI (Master Key Identifier) is OPTIONAL and of configurable - length. See SRTP Section 3.1 [1] for details - -4.10. authentication tag (RECOMMENDED) - - The authentication tag is RECOMMENDED and of configurable length. It - contains a cryptographic checksum of the sender ID, sequence number - - - -Gsenger Expires July 4, 2008 [Page 10] - -Internet-Draft secure anycast tunneling protocol (SATP) January 2008 - - - and the encrypted portion, but not of the MKI. On sender side - encryption HAS TO be done before calculating the authentication tag. - A receiver HAS TO calculate the authentication tag before decrypting - the encrypted portion. - -4.11. Encryption - - Encryption is done in the same way as for SRTP [1]. This section - will only discuss some small changes that HAVE TO be made. Please - read SRTP RFC3711 section 3-9 [1] for details. - - The least significant bits of SSRC are replaced by the sender ID and - the most significant bits are replaced by the mux. For the SRTP SEQ - the 16 least significant bits of the SATP sequence number are used - and the 16 most significant bits of the sequence number replace the - 16 least significant bits of the SRTP ROC. - - Difference between SRTP and SATP - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | SATP sequence number | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - = - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | SRTP ROC least significant | SRTP SEQ | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | SATP MUX | SATP sender ID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - = - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | SRTP SSRC | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - Figure 7 - - - - - - - - - - -Gsenger Expires July 4, 2008 [Page 11] - -Internet-Draft secure anycast tunneling protocol (SATP) January 2008 - - -5. Security Considerations - - As SATP uses the same encryption techniques as SRTP [1], it shares - the same security issues. This section will only discuss some small - changes. Please read SRTP RFC3711 section 9 [1] for details. - -5.1. Replay protection - - Replay protection is done by a replay list. Every anycast receiver - has it's own replay list, which SHOULDN'T be syncronised, because of - massive overhead. This leads to an additional possible attack. A - attacker is able to replay a captured packet once to every anycast - receiver. This attack is considered of be very unlikely, because - multiple attack hosts in different loactions are needed to reach the - seperate anycast receivers and the number of replays is limited to - the count of receivers - 1. Such replays might also happen because - of routing problems, so a payload protocol HAS TO be robust against a - small number of duplicated packages. The window size and position - HAS TO be syncronised between multible anycast receivers to limit - this attack. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Gsenger Expires July 4, 2008 [Page 12] - -Internet-Draft secure anycast tunneling protocol (SATP) January 2008 - - -6. IANA Considerations - - The protocol is intended to be used on top of IP or on top of UDP (to - be compatible with NAT routers), so UDP and IP protocol numbers have - to be assiged by IANA. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Gsenger Expires July 4, 2008 [Page 13] - -Internet-Draft secure anycast tunneling protocol (SATP) January 2008 - - -7. References - -7.1. Normative References - - [1] Baugher, M., McGrew, D., Naslund, M., Carrara, E., and K. - Norrman, "The Secure Real-time Transport Protocol (SRTP)", - RFC 3711, March 2004. - - [2] Bradner, S., "Key words for use in RFCs to Indicate Requirement - Levels", BCP 14, RFC 2119, March 1997. - - [3] Perkins, C., "IP Encapsulation within IP", RFC 2003, - October 1996. - -7.2. Informational References - - [4] Farinacci, D., Li, T., Hanks, S., Meyer, D., and P. Traina, - "Generic Routing Encapsulation (GRE)", RFC 2784, March 2000. - - [5] Kent, S. and R. Atkinson, "Security Architecture for the - Internet Protocol", RFC 2401, November 1998. - - [6] Partridge, C., Mendez, T., and W. Milliken, "Host Anycasting - Service", RFC 1546, November 1993. - - - - - - - - - - - - - - - - - - - - - - - - - - - -Gsenger Expires July 4, 2008 [Page 14] - -Internet-Draft secure anycast tunneling protocol (SATP) January 2008 - - -URIs - - [7] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Gsenger Expires July 4, 2008 [Page 15] - -Internet-Draft secure anycast tunneling protocol (SATP) January 2008 - - -Author's Address - - Othmar Gsenger - Puerstingerstr 32 - Saalfelden 5760 - AT - - Phone: - Email: satp@gsenger.com - URI: http://www.gsenger.com/satp/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Gsenger Expires July 4, 2008 [Page 16] - -Internet-Draft secure anycast tunneling protocol (SATP) January 2008 - - -Full Copyright Statement - - Copyright (C) The Internet Society (2008). - - This document is subject to the rights, licenses and restrictions - contained in BCP 78, and except as set forth therein, the authors - retain all their rights. - - This document and the information contained herein are provided on an - "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS - OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY AND THE INTERNET - ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, - INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE - INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED - WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - - -Intellectual Property - - The IETF takes no position regarding the validity or scope of any - Intellectual Property Rights or other rights that might be claimed to - pertain to the implementation or use of the technology described in - this document or the extent to which any license under such rights - might or might not be available; nor does it represent that it has - made any independent effort to identify any such rights. Information - on the procedures with respect to rights in RFC documents can be - found in BCP 78 and BCP 79. - - Copies of IPR disclosures made to the IETF Secretariat and any - assurances of licenses to be made available, or the result of an - attempt made to obtain a general license or permission for the use of - such proprietary rights by implementers or users of this - specification can be obtained from the IETF on-line IPR repository at - http://www.ietf.org/ipr. - - The IETF invites any interested party to bring to its attention any - copyrights, patents or patent applications, or other proprietary - rights that may cover technology that may be required to implement - this standard. Please address the information to the IETF at - ietf-ipr@ietf.org. - - -Acknowledgment - - Funding for the RFC Editor function is provided by the IETF - Administrative Support Activity (IASA). - - - - - -Gsenger Expires July 4, 2008 [Page 17] - diff --git a/draft-gsenger-secure-anycast-tunneling-protocol-02.xml b/draft-gsenger-secure-anycast-tunneling-protocol-02.xml deleted file mode 100644 index f9ec30d..0000000 --- a/draft-gsenger-secure-anycast-tunneling-protocol-02.xml +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - - -]> - - - - secure anycast tunneling protocol (SATP) - - - - -
- - Puerstingerstr 32 - Saalfelden - 5760 - AT - - - - satp@gsenger.com - http://www.gsenger.com/satp/ -
-
- - - - General - - satp - Internet-Draft - secure anycast tunneling protocol - anycast - tunnel - secure - protocol - - The secure anycast tunneling protocol (SATP) defines a protocol used for communication between any combination of unicast and anycast tunnel endpoints. It allows tunneling of every ETHER TYPE protocol (ethernet, ip ...). SATP directly includes cryptography and message authentication based on the methodes used by SRTP. It can be used as an encrypted alternative to IP Encapsulation within IP and Generic Routing Encapsulation (GRE). It supports both anycast receivers and senders. - - -
- -
- SATP is a mixture of a generic encapsulation protocol like GRE and a secure tunneling protocol as IPsec in tunnel mode. It can be used to build redundant virtual private network (VPN) connections. It supports peer to peer tunnels, where tunnel endpoints can be any combination of unicast, multicast or anycast hosts, so it defines a Host Anycast Service. Encryption is done per packet, so the protocol is robust against packet loss and routing changes. - To save some header overhead it uses the encryption techniques of SRTP. - -
- The keywords "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC2119. -
-
-
- This section gives an overview of possible usage scenarios. Please note, that the protocols used in the figures are only examples and that SATP itself does not care about either transport protocols or encapsulated protocols. Routing is not done by SATP and each implemetation MAY choose it's own way of doing this task (e.g. using functions provided by the operating system). SATP is used only to encapsulate and encrypt data. -
- -
-
- An example of SATP used to tunnel in a unicast client - anycast server model - - --------- router ----------- - / \ - unicast ------+---------- router ------------+------ unicast - host \ / host - --------- router ----------- - - unicast | encrypted | anycast | encrypted | unicast - tunnel | communication | tunnel | communication | tunnel - endpoint | using SATP | endpoint | using SATP | endpoint - -
- In this scenario the payload gets encapsuleted into a SATP packet by a unicast host and gets transmitted to one of the anycast routers. It than gets decapsulated by the router. This router makes a routing descision based on the underlying protocol and transmits a new SATP package to one or more unicast hosts depending on the routing decision. -
- -
-
- An example of SATP used to encrypt data between a unicast host and anycast networks - - -------Router -+---- DNS Server - / \ - / --- 6to4 Router - / - unicast -------+----------Router --+--- DNS Server - host \ \ - \ --- 6to4 Router - \ - -------Router -+---- DNS Server - \ - --- 6to4 Router - - unicast | encrypted | anycast | plaintext - tunnel | communication | tunnel | anycast - endpoint | using SATP | endpoint | services - - -
- When the unicast hosts wants to transmit data to one of the anycast DNS servers, it encapsulates the data and sends a SATP packet to the anycast address of the routers. The packet arrives at one of the routers, gets decapsulated and routed to the DNS server. This method can be used to tunnel between a clients and networks providing anycast services. It can also be used the other way to virtually locate a unicast service within anycasted networks. -
-
-
- An example of SATP used to connect 2 networks - - Router ----------- ---------------Router - / \ / \ - Network - Router ------------x Network - A \ / \ / B - Router ----------- ---------------Router - - | packets | packets | packets | - plaintext | get | take a | get | plaintext - packets | de/encrypted | random | de/encrypted | packets - |de/encapsulated| path |de/encapsulated| - - -
- - Network A has multiple routers, that act as gateway/tunnel endpoints to another network B. This is done to build a redundant encrypted tunnel connection between the two networks. All tunnel endpoints of network A share the same anycast address and all tunnel endpoints of network B share another anycast address. When a packet from network A gets transmitted to network B, it first arrives on one of network A's border routers. Which router is used is determined by network A's internal routing. This router encapsulates the package and sends it to the anycast address of the network B routers. The SATP packet arrives at one of network B's routers and gets decapsulated and routed to it's destination within network B. -
-
-
- SATP does not depend on which lower layer protocols is used, but this section gives an example of how packets could look like. - -
- Examples of SATP used with different lower layer and payload protocols - - +------+-----+-------------------------------+ - | | | +----------------+-----+ | - | IPv6 | UDP | SATP | Ethernet 802.3 | ... | | - | | | +----------------+-----+ | - +------+-----+-------------------------------+ - -Tunneling of Ethernet over UDP/IPv6 - - +------+-----+---------------------------+ - | | | +------+-----+-----+ | - | IPv4 | UDP | SATP | IPv6 | UDP | RTP | | - | | | +------+-----+-----+ | - +------+-----+---------------------------+ - -Tunneling of IPv6 over UDP/IPv4 with RTP payload - - +------+-------------------------------+ - | | +----------------+-----+ | - | IPv6 | SATP | Ethernet 802.3 | ... | | - | | +----------------+-----+ | - +------+-------------------------------+ - -Tunneling of Ethernet over IPv6 - - +------+---------------------------+ - | | +------+-----+-----+ | - | IPv4 | SATP | IPv6 | UDP | RTP | | - | | +------+-----+-----+ | - +------+---------------------------+ - -Tunneling of IPv6 over IPv4 with RTP payload - -
-
-
-
-
- - The only way of fully supporting fragmentation would be to synchronise fragments between all anycast servers. This is considered to be too much overhead, so there are two non perfect solutions for these problems. Either fragmentation HAS TO be disabled or if not all fragments arrive at the same server the ip datagramm HAS TO be discarded. As routing changes are not expected to occure very frequently, the encapsulated protocol can do a retransmission and all fragments will arrive at the new server. - If the payload type is IP and the ip headers's Don't Fragment (DF) bit is set, than the DF bit of the outer IP header HAS TO be set as well. -
-
- ICMP messages MUST be relayed according to rfc2003 section 4. This is needed for path MTU detection. -
-
-
-
-
- Protocol Format - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | sequence number | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | - | sender ID | MUX | | - +#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+ | - | | payload type | | | - | +-------------------------------+ | | - | | .... payload ... | | - | | +-------------------------------+ | - | | | padding (OPT) | pad count(OPT)| | - +#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+-+ - | ~ MKI (OPTIONAL) ~ | - | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | - | : authentication tag (RECOMMENDED) : | - | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | - | | - +- Encrypted Portion Authenticated Portion ---+ - -
- -
-
- The sequence number is a 32 bit unsigned integer in network byte order. It starts with a random value and is increased by 1 for every sent packet. After the maximum value, it starts over from 0. This overrun causes the ROC to be increased. -
-
- The sender ID is a 16 bit unsigned integer. It HAS TO be unique for every sender sharing the same anycast address -
-
- The MUX (multiplex) field is a 16 bit unsigned integer. It is used to destinguish multible tunnel connections. -
-
- The payload type field defines the payload protocol. ETHER TYPE protocol numbers are used. See IANA assigned ethernet numbers . The values 0000-05DC are reserverd and MUST NOT be used. -
- Some examples for protocol types - -HEX -0000 Reserved -.... Reserved -05DC Reserved -0800 Internet IP (IPv4) -6558 transparent ethernet bridging -86DD IPv6 - -
-
-
-
- A packet of the type payload type (e.g. an IP packet). -
-
- Padding of max 255 octets. -None of the pre-defined encryption transforms uses any padding; for - these, the plaintext and encrypted payload sizes match exactly. Transforms are based on transforms of the SRTP protocol and these transforms might use the RTP padding format, so a RTP like padding is supported. If the padding count field is present, than the padding count field MUST be set to the padding length. -
-
- The number of octets of the padding field. This field is optional. It's presence is signaled by the key management and not by this protocol. If this field isn't present, the padding field MUST NOT be present as well. -
-
- The MKI (Master Key Identifier) is OPTIONAL and of configurable length. See SRTP Section 3.1 for details -
-
- The authentication tag is RECOMMENDED and of configurable length. It contains a cryptographic checksum of the sender ID, sequence number and the encrypted portion, but not of the MKI. On sender side encryption HAS TO be done before calculating the authentication tag. A receiver HAS TO calculate the authentication tag before decrypting the encrypted portion. -
-
- Encryption is done in the same way as for SRTP. This section will only discuss some small changes that HAVE TO be made. Please read SRTP RFC3711 section 3-9 for details. The least significant bits of SSRC are replaced by the sender ID and the most significant bits are replaced by the mux. For the SRTP SEQ the 16 least significant bits of the SATP sequence number are used and the 16 most significant bits of the sequence number replace the 16 least significant bits of the SRTP ROC. -
- Difference between SRTP and SATP - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | SATP sequence number | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - = - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | SRTP ROC least significant | SRTP SEQ | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | SATP MUX | SATP sender ID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - = - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | SRTP SSRC | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - -
-
-
-
- As SATP uses the same encryption techniques as SRTP, it shares the same security issues. This section will only discuss some small changes. Please read SRTP RFC3711 section 9 for details. -
- Replay protection is done by a replay list. Every anycast receiver has it's own replay list, which SHOULDN'T be syncronised, because of massive overhead. This leads to an additional possible attack. A attacker is able to replay a captured packet once to every anycast receiver. This attack is considered of be very unlikely, because multiple attack hosts in different loactions are needed to reach the seperate anycast receivers and the number of replays is limited to the count of receivers - 1. Such replays might also happen because of routing problems, so a payload protocol HAS TO be robust against a small number of duplicated packages. The window size and position HAS TO be syncronised between multible anycast receivers to limit this attack. -
-
-
- The protocol is intended to be used on top of IP or on top of UDP (to be compatible with NAT routers), so UDP and IP protocol numbers have to be assiged by IANA. -
-
- - - &rfc3711; - &rfc2119; - &rfc2003; - - - &rfc2784; - &rfc2401; - &rfc1546; - - -
diff --git a/encryptedPacket.cpp b/encryptedPacket.cpp deleted file mode 100644 index c0221e9..0000000 --- a/encryptedPacket.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include -#include // for std::memcpy - -#include "encryptedPacket.h" -#include "datatypes.h" -#include "log.h" - -EncryptedPacket::EncryptedPacket(u_int32_t payload_length, bool allow_realloc) - : Buffer(payload_length + sizeof(struct HeaderStruct), allow_realloc) -{ - header_ = reinterpret_cast(buf_); - payload_ = buf_ + sizeof(struct HeaderStruct); - auth_tag_ = NULL; - if(header_) - { - header_->seq_nr = 0; - header_->sender_id = 0; - header_->mux = 0; - } -} - -seq_nr_t EncryptedPacket::getSeqNr() const -{ - if(header_) - return SEQ_NR_T_NTOH(header_->seq_nr); - - return 0; -} - -sender_id_t EncryptedPacket::getSenderId() const -{ - if(header_) - return SENDER_ID_T_NTOH(header_->sender_id); - - return 0; -} - -mux_t EncryptedPacket::getMux() const -{ - if(header_) - return MUX_T_NTOH(header_->mux); - - return 0; -} - -void EncryptedPacket::setSeqNr(seq_nr_t seq_nr) -{ - if(header_) - header_->seq_nr = SEQ_NR_T_HTON(seq_nr); -} - -void EncryptedPacket::setSenderId(sender_id_t sender_id) -{ - if(header_) - header_->sender_id = SENDER_ID_T_HTON(sender_id); -} - -void EncryptedPacket::setMux(mux_t mux) -{ - if(header_) - header_->mux = MUX_T_HTON(mux); -} - -void EncryptedPacket::setHeader(seq_nr_t seq_nr, sender_id_t sender_id, mux_t mux) -{ - if(!header_) - return; - - header_->seq_nr = SEQ_NR_T_HTON(seq_nr); - header_->sender_id = SENDER_ID_T_HTON(sender_id); - header_->mux = MUX_T_HTON(mux); -} - -u_int32_t EncryptedPacket::getPayloadLength() const -{ - if(!payload_) - return 0; - - if(!auth_tag_) - return (length_ > sizeof(struct HeaderStruct)) ? (length_ - sizeof(struct HeaderStruct)) : 0; - - return (length_ > (sizeof(struct HeaderStruct) + AUTHTAG_SIZE)) ? (length_ - sizeof(struct HeaderStruct) - AUTHTAG_SIZE) : 0; -} - -void EncryptedPacket::setPayloadLength(u_int32_t payload_length) -{ - Buffer::setLength(payload_length + sizeof(struct HeaderStruct)); - // depending on allow_realloc buf_ may point to another address - // therefore in this case reinit() gets called by Buffer::setLength() -} - -void EncryptedPacket::reinit() -{ - header_ = reinterpret_cast(buf_); - payload_ = buf_ + sizeof(struct HeaderStruct); - - if(length_ <= (sizeof(struct HeaderStruct))) - payload_ = NULL; - - if(length_ < (sizeof(struct HeaderStruct))) { - header_ = NULL; - throw std::runtime_error("packet can't be initialized, buffer is too small"); - } - - if(auth_tag_) - { - if(length_ < (sizeof(struct HeaderStruct) + AUTHTAG_SIZE)) { - auth_tag_ = NULL; - throw std::runtime_error("auth-tag can't be enabled, buffer is too small"); - } - auth_tag_ = buf_ + length_ - AUTHTAG_SIZE; - } -} - -u_int8_t* EncryptedPacket::getPayload() -{ - return payload_; -} - -u_int8_t* EncryptedPacket::getAuthenticatedPortion() -{ - return buf_; -} - -u_int32_t EncryptedPacket::getAuthenticatedPortionLength() -{ - if(!buf_) - return 0; - - if(!auth_tag_) - return length_; - - return (length_ > AUTHTAG_SIZE) ? (length_ - AUTHTAG_SIZE) : 0; -} - -void EncryptedPacket::withAuthTag(bool b) -{ - if((b && auth_tag_) || (!b && !auth_tag_)) - return; - - if(b) - { - if(length_ < (sizeof(struct HeaderStruct) + AUTHTAG_SIZE)) - throw std::runtime_error("auth-tag can't be enabled, buffer is too small"); - - auth_tag_ = buf_ + length_ - AUTHTAG_SIZE; - } - else - auth_tag_ = NULL; -} - -void EncryptedPacket::addAuthTag() -{ - if(auth_tag_) - return; - - auth_tag_ = buf_; // will be set to the correct value @ reinit - setLength(length_ + AUTHTAG_SIZE); - if(auth_tag_ == buf_) // reinit was not called by setLength - reinit(); -} - -void EncryptedPacket::removeAuthTag() -{ - if(!auth_tag_) - return; - - auth_tag_ = NULL; - setLength(length_ - AUTHTAG_SIZE); -} - -u_int8_t* EncryptedPacket::getAuthTag() -{ - return auth_tag_; -} - -u_int32_t EncryptedPacket::getAuthTagLength() -{ - if(auth_tag_) - return AUTHTAG_SIZE; - - return 0; -} diff --git a/encryptedPacket.h b/encryptedPacket.h deleted file mode 100644 index fc6fe96..0000000 --- a/encryptedPacket.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _ENCRYPTED_PACKET_H_ -#define _ENCRYPTED_PACKET_H_ - -#include "datatypes.h" -#include "buffer.h" - -class Cipher; -class EncryptedPacket : public Buffer -{ -public: - - /** - * Packet constructor - * @param the length of the payload - * @param allow reallocation of buffer - */ - EncryptedPacket(u_int32_t payload_length, bool allow_realloc = false); - - /** - * Packet destructor - */ - ~EncryptedPacket() {}; - - /** - * Get the sequence number - * @return seqence number - */ - seq_nr_t getSeqNr() const; - - /** - * Set the seqence number - * @param seq_nr sequence number - */ - void setSeqNr(seq_nr_t seq_nr); - - /** - * Get the sender id - * @return sender id - */ - sender_id_t getSenderId() const; - - /** - * Set the sender id - * @param sender_id sender id - */ - void setSenderId(sender_id_t sender_id); - - /** - * Get the mulitplex id - * @return multiplex id - */ - mux_t getMux() const; - - /** - * Set the multiplex id - * @param mux multiplex id - */ - void setMux(mux_t mux); - - /** - * Set the header of a packet - * @param seq_nr sequence number - * @param sender_id sender id - * @param mux multiplex id - */ - void setHeader(seq_nr_t seq_nr, sender_id_t sender_id, mux_t mux); - - /** - * Get the length of the payload - * @return the length of the payload - */ - u_int32_t getPayloadLength() const; - - /** - * Set the length of the payload - * @param length length of the payload - */ - void setPayloadLength(u_int32_t payload_length); - - /** - * Get the the payload - * @return the Pointer to the payload - */ - u_int8_t* getPayload(); - - - u_int8_t* getAuthenticatedPortion(); - u_int32_t getAuthenticatedPortionLength(); - - void withAuthTag(bool b); - void addAuthTag(); - void removeAuthTag(); - u_int8_t* getAuthTag(); - u_int32_t getAuthTagLength(); - -private: - EncryptedPacket(); - EncryptedPacket(const EncryptedPacket &src); - - void reinit(); - - struct HeaderStruct - { - seq_nr_t seq_nr; - sender_id_t sender_id; - mux_t mux; - }__attribute__((__packed__)); - - struct HeaderStruct* header_; - u_int8_t * payload_; - u_int8_t * auth_tag_; - static const u_int32_t AUTHTAG_SIZE = 10; // TODO: hardcoded size -}; - -#endif diff --git a/keyDerivation.cpp b/keyDerivation.cpp deleted file mode 100644 index aafde10..0000000 --- a/keyDerivation.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/* - * anytun - * - * The secure anycast tunneling protocol (satp) defines a protocol used - * for communication between any combination of unicast and anycast - * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel - * mode and allows tunneling of every ETHER TYPE protocol (e.g. - * ethernet, ip, arp ...). satp directly includes cryptography and - * message authentication based on the methodes used by SRTP. It is - * intended to deliver a generic, scaleable and secure solution for - * tunneling and relaying of packets of any protocol. - * - * - * Copyright (C) 2007 anytun.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#include "log.h" -#include "keyDerivation.h" -#include "mpi.h" -#include "threadUtils.hpp" - -#include -#include -#include - -#include - - -void KeyDerivation::setLogKDRate(const uint8_t log_rate) -{ - Lock lock(mutex_); - if( log_rate < 49 ) - ld_kdr_ = log_rate; -} - -//****** NullKeyDerivation ****** - -void NullKeyDerivation::generate(satp_prf_label label, seq_nr_t seq_nr, Buffer& key) -{ - for(u_int32_t i=0; i < key.getLength(); ++i) key[i] = 0; -} - -//****** AesIcmKeyDerivation ****** - -AesIcmKeyDerivation::~AesIcmKeyDerivation() -{ - Lock lock(mutex_); - if(cipher_) - gcry_cipher_close( cipher_ ); -} - -void AesIcmKeyDerivation::updateMasterKey() -{ - if(!cipher_) - return; - - gcry_error_t err = gcry_cipher_setkey( cipher_, master_key_.getBuf(), master_key_.getLength() ); - if( err ) - cLog.msg(Log::PRIO_ERR) << "KeyDerivation::updateMasterKey: Failed to set cipher key: " << gpg_strerror( err ); -} - -void AesIcmKeyDerivation::init(Buffer key, Buffer salt) -{ - Lock lock(mutex_); - if(cipher_) - gcry_cipher_close( cipher_ ); - - // TODO: hardcoded size - gcry_error_t err = gcry_cipher_open( &cipher_, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CTR, 0 ); - if( err ) { - cLog.msg(Log::PRIO_ERR) << "KeyDerivation::init: Failed to open cipher: " << gpg_strerror( err ); - return; - } - - master_salt_ = SyncBuffer(salt); - master_key_ = SyncBuffer(key); - - updateMasterKey(); -} - -void AesIcmKeyDerivation::generate(satp_prf_label label, seq_nr_t seq_nr, Buffer& key) -{ - Lock lock(mutex_); - if(!cipher_) - { - cLog.msg(Log::PRIO_ERR) << "KeyDerivation::generate: cipher not opened"; - return; - } - - gcry_error_t err = gcry_cipher_reset( cipher_ ); - if( err ) - cLog.msg(Log::PRIO_ERR) << "KeyDerivation::generate: Failed to reset cipher: " << gpg_strerror( err ); - - // see at: http://tools.ietf.org/html/rfc3711#section-4.3 - // * Let r = index DIV key_derivation_rate (with DIV as defined above). - // * Let key_id =