Permalink
Browse files

Merge branch 'release/1.2'

  • Loading branch information...
2 parents 6b86977 + 50331de commit de4089cc93d3b5c9df6fae6475a871725691b287 @ccutrer committed Jul 6, 2010
Showing with 3,066 additions and 833 deletions.
  1. +16 −6 Makefile
  2. +77 −0 autoexp.dat
  3. +8 −0 mordor.xcodeproj/project.pbxproj
  4. +21 −1 mordor/atomic.h
  5. +102 −0 mordor/examples/decodebacktrace.cpp
  6. +100 −0 mordor/examples/decodebacktrace.vcxproj
  7. +6 −0 mordor/examples/decodebacktrace.vcxproj.filters
  8. +1 −0 mordor/examples/echoserver.cpp
  9. +38 −25 mordor/examples/tunnel.cpp
  10. +27 −3 mordor/examples/wget.cpp
  11. +6 −2 mordor/exception.cpp
  12. +1 −0 mordor/exception.h
  13. +72 −1 mordor/fiber.cpp
  14. +9 −0 mordor/fiber.h
  15. +118 −2 mordor/http/auth.cpp
  16. +19 −12 mordor/http/auth.h
  17. +8 −0 mordor/http/basic.cpp
  18. +7 −5 mordor/http/basic.h
  19. +291 −179 mordor/http/broker.cpp
  20. +91 −72 mordor/http/broker.h
  21. +131 −107 mordor/http/client.cpp
  22. +17 −14 mordor/http/client.h
  23. +5 −5 mordor/http/multipart.h
  24. +1 −0 mordor/http/negotiate.cpp
  25. +9 −2 mordor/http/negotiate.h
  26. +51 −13 mordor/http/oauth.cpp
  27. +7 −7 mordor/http/oauth.h
  28. +275 −138 mordor/http/proxy.cpp
  29. +36 −36 mordor/http/proxy.h
  30. +1 −0 mordor/http/server.cpp
  31. +18 −11 mordor/http/server.h
  32. +0 −30 mordor/http/tunnel.h
  33. +4 −1 mordor/iomanager_kqueue.cpp
  34. +19 −5 mordor/json.rl
  35. +18 −6 mordor/log.cpp
  36. +13 −5 mordor/mordor.vcproj
  37. +2 −1 mordor/mordor.vcxproj
  38. +6 −3 mordor/mordor.vcxproj.filters
  39. +11 −0 mordor/mordor2010.sln
  40. +1 −0 mordor/pch.h
  41. +1 −0 mordor/predef.h
  42. +1 −1 mordor/runtime_linking.h
  43. +144 −28 mordor/socket.cpp
  44. +15 −8 mordor/socket.h
  45. +135 −0 mordor/socks.cpp
  46. +45 −0 mordor/socks.h
  47. +1 −3 mordor/streams/filter.h
  48. +147 −71 mordor/streams/http.cpp
  49. +13 −2 mordor/streams/http.h
  50. +74 −0 mordor/string.cpp
  51. +12 −0 mordor/string.h
  52. +189 −0 mordor/test/antxmllistener.cpp
  53. +60 −0 mordor/test/antxmllistener.h
  54. +8 −0 mordor/test/mordortest.vcproj
  55. +2 −0 mordor/test/mordortest.vcxproj
  56. +6 −0 mordor/test/mordortest.vcxproj.filters
  57. +69 −1 mordor/test/test.cpp
  58. +52 −2 mordor/test/test.h
  59. +283 −11 mordor/tests/http.cpp
  60. +11 −0 mordor/tests/json.cpp
  61. +15 −4 mordor/tests/run_tests.cpp
  62. +1 −0 mordor/tests/tests.vcxproj
  63. +3 −0 mordor/tests/tests.vcxproj.filters
  64. +31 −0 mordor/tests/unicode.cpp
  65. +29 −0 mordor/tests/uri.cpp
  66. +2 −2 mordor/uri.h
  67. +22 −8 mordor/uri.rl
  68. +52 −0 mordor/util.h
View
@@ -62,7 +62,7 @@ PLATFORMDIR := $(PLATFORM)/$(ARCH)
ifeq ($(PLATFORM), Darwin)
DARWIN := 1
- BOOST_EXT := -mt
+ BOOST_EXT :=
BOOST_LIB_FLAGS := -L/opt/local/lib
PQ_LIB_FLAGS := -L/opt/local/lib/postgresql83
IOMANAGER := kqueue
@@ -170,11 +170,12 @@ ifeq ($(RAGEL_MAJOR), 6)
RLCODEGEN :=
endif
+LIBS := $(BOOST_LIB_FLAGS) $(PQ_LIB_FLAGS) -lboost_thread$(BOOST_EXT) -lboost_program_options $(BOOST_EXT) -lboost_regex$(BOOST_EXT) -lboost_date_time$(BOOST_EXT) -lssl -lcrypto -lz -ldl
+
ifeq ($(PLATFORM), Darwin)
+ LIBS += -framework SystemConfiguration -framework CoreFoundation -framework CoreServices -framework Security
endif
-LIBS := $(BOOST_LIB_FLAGS) $(PQ_LIB_FLAGS) -lboost_thread$(BOOST_EXT) -lboost_regex$(BOOST_EXT) -lboost_date_time$(BOOST_EXT) -lssl -lcrypto -lz -ldl
-
ifeq ($(PLATFORM), FreeBSD)
LIBS += -lexecinfo
endif
@@ -390,9 +391,9 @@ endif
mordor/examples/wget: mordor/examples/wget.o \
mordor/libmordor.a
ifeq ($(Q),@)
- @echo ld $@
+ @echo ld $@ -lboost_program_options$(BOOST_EXT)
endif
- $(COMPLINK)
+ $(COMPLINK) -lboost_program_options$(BOOST_EXT)
mordor/streams/socket_stream.o: mordor/streams/socket.cpp
ifeq ($(Q),@)
@@ -401,6 +402,13 @@ endif
$(Q)mkdir -p $(@D)
$(Q)$(CXX) $(CXXFLAGS) -c -o $@ $<
+mordor/streams/http_stream.o: mordor/streams/http.cpp
+ifeq ($(Q),@)
+ @echo c++ $<
+endif
+ $(Q)mkdir -p $(@D)
+ $(Q)$(CXX) $(CXXFLAGS) -c -o $@ $<
+
LIBMORDOROBJECTS := \
mordor/assert.o \
@@ -429,14 +437,15 @@ LIBMORDOROBJECTS := \
mordor/semaphore.o \
mordor/sleep.o \
mordor/socket.o \
+ mordor/socks.o \
mordor/statistics.o \
mordor/streams/buffer.o \
mordor/streams/buffered.o \
mordor/streams/cat.o \
mordor/streams/fd.o \
mordor/streams/file.o \
mordor/streams/hash.o \
- mordor/streams/http.o \
+ mordor/streams/http_stream.o \
mordor/streams/limited.o \
mordor/streams/memory.o \
mordor/streams/null.o \
@@ -471,6 +480,7 @@ endif
$(Q)$(AR) $(ARFLAGS) $@ $(filter %.o,$?)
LIBMORDORTESTOBJECTS := \
+ mordor/test/antxmllistener.o \
mordor/test/test.o \
mordor/test/stdoutlistener.o
View
@@ -0,0 +1,77 @@
+; Add to C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Packages\Debugger\autoexp.dat in the [Visualizer] section
+; The visualizer isn't perfect - it uses ; instead of :, and , instead of / between path segments
+; Also, it doesn't perform any encoding
+
+Mordor::URI{
+ preview (
+ #(
+ #if ($e.m_schemeDefined) ( #(
+ #if (($e.m_scheme._Myres) < ($e.m_scheme._BUF_SIZE)) ( [$e.m_scheme._Bx._Buf,sb] ) #else ( [$e.m_scheme._Bx._Ptr,sb] ),
+ ";")
+ ) #else ( "" ),
+ #if ($e.authority.m_hostDefined) ( #("//", $e.authority) ) #else ( "" ),
+ #if ($e.path.type == ABSOLUTE || $e.path.segments._Myfirst != $e.path.segments._Mylast) ( $e.path ) #else ( "" ),
+ #if ($e.m_queryDefined) ( #(
+ "?",
+ #if (($e.m_query._Myres) < ($e.m_query._BUF_SIZE)) ( [$e.m_query._Bx._Buf,sb] ) #else ( [$e.m_query._Bx._Ptr,sb] ))
+ ) #else ( "" ),
+ #if ($e.m_fragmentDefined) ( #(
+ "#",
+ #if (($e.m_fragment._Myres) < ($e.m_fragment._BUF_SIZE)) ( [$e.m_fragment._Bx._Buf,sb] ) #else ( [$e.m_fragment._Bx._Ptr,sb] ))
+ ) #else ( "" )
+ )
+ )
+ children (
+ #(
+ #if ($e.m_schemeDefined) ( #(scheme: $e.m_scheme) ) #else ( #array(expr: 0, size: 0) ),
+ #if ($e.authority.m_hostDefined) ( #(authority: $e.authority) ) #else ( #array(expr: 0, size: 0) ),
+ #if ($e.path.type == ABSOLUTE || $e.path.segments._Myfirst != $e.path.segments._Mylast) ( #(path: $e.path) ) #else ( #array(expr: 0, size: 0) ),
+ #if ($e.m_queryDefined) ( #(query: $e.m_query) ) #else ( #array(expr: 0, size: 0) ),
+ #if ($e.m_fragmentDefined) ( #(fragment: $e.m_fragment) ) #else ( #array(expr: 0, size: 0) ),
+ #(Actual Members: [$e,!])
+ )
+ )
+}
+
+Mordor::URI::Authority{
+ preview (
+ #(
+ #if ($e.m_userinfoDefined) ( #( #if (($e.m_userinfo._Myres) < ($e.m_userinfo._BUF_SIZE)) ( [$e.m_userinfo._Bx._Buf,sb] ) #else ( [$e.m_userinfo._Bx._Ptr,sb] ), "@") ) #else ( "" ),
+ #if ($e.m_hostDefined) ( #if (($e.m_host._Myres) < ($e.m_host._BUF_SIZE)) ( [$e.m_host._Bx._Buf,sb] ) #else ( [$e.m_host._Bx._Ptr,sb] ) ) #else ( "" ),
+ #if ($e.m_portDefined) ( #( ";", $e.m_port) ) #else ( "" )
+ )
+ )
+ children (
+ #(
+ #if ($e.m_userinfoDefined) ( #( userinfo: $e.m_userinfo) ) #else ( #array(expr: 0, size: 0) ),
+ #if ($e.m_hostDefined) ( #( host: $e.m_host) ) #else ( #array(expr: 0, size: 0) ),
+ #if ($e.m_portDefined) ( #( port: $e.m_port) ) #else ( #array(expr: 0, size: 0) ),
+ #(Actual Members: [$e,!])
+ )
+ )
+}
+
+Mordor::URI::Path{
+ preview (
+ #if ($e.type == RELATIVE && $e.segments._Myfirst == $e.segments._Mylast) (
+ ""
+ ) #else (
+ #(
+ #if ($e.type == ABSOLUTE) (
+ "/"
+ ) #else (
+ ""
+ ),
+ #array(
+ expr:
+ #if ((($e.segments._Myfirst[$i])._Myres) < (($e.segments._Myfirst[$i])._BUF_SIZE)) (
+ [($e.segments._Myfirst[$i])._Bx._Buf,sb]
+ ) #else (
+ [($e.segments._Myfirst[$i])._Bx._Ptr,sb]
+ ),
+ size: $e.segments._Mylast - $e.segments._Myfirst
+ )
+ )
+ )
+ )
+}
@@ -61,6 +61,8 @@
3CAB29E9112B347400607AEE /* timer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3CAB2798112B096700607AEE /* timer.cpp */; };
3CAC4A341151622F00F85725 /* iomanager_kqueue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3CAB271B112B096700607AEE /* iomanager_kqueue.cpp */; };
3CC4CE561138646D001C21F2 /* progress.h in Headers */ = {isa = PBXBuildFile; fileRef = 3CC4CE551138646D001C21F2 /* progress.h */; };
+ C34893CA11BEB1300044E9C8 /* socks.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C34893C811BEB1300044E9C8 /* socks.cpp */; };
+ C34893CB11BEB1300044E9C8 /* socks.h in Headers */ = {isa = PBXBuildFile; fileRef = C34893C911BEB1300044E9C8 /* socks.h */; };
E29FD2AA1136FD1D004BC293 /* timeout.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E29FD2A81136FD1D004BC293 /* timeout.cpp */; };
E29FD2AB1136FD1D004BC293 /* timeout.h in Headers */ = {isa = PBXBuildFile; fileRef = E29FD2A91136FD1D004BC293 /* timeout.h */; };
/* End PBXBuildFile section */
@@ -279,6 +281,8 @@
3CAB27A1112B096700607AEE /* xml_parser.rl */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.cpp.preprocessed; fileEncoding = 4; path = xml_parser.rl; sourceTree = "<group>"; };
3CAB29B1112B340600607AEE /* libmordor.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libmordor.a; sourceTree = BUILT_PRODUCTS_DIR; };
3CC4CE551138646D001C21F2 /* progress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = progress.h; sourceTree = "<group>"; };
+ C34893C811BEB1300044E9C8 /* socks.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = socks.cpp; sourceTree = "<group>"; };
+ C34893C911BEB1300044E9C8 /* socks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = socks.h; sourceTree = "<group>"; };
E29FD2A81136FD1D004BC293 /* timeout.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = timeout.cpp; sourceTree = "<group>"; };
E29FD2A91136FD1D004BC293 /* timeout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = timeout.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -330,6 +334,8 @@
3CAB26D4112B096700607AEE /* mordor */ = {
isa = PBXGroup;
children = (
+ C34893C811BEB1300044E9C8 /* socks.cpp */,
+ C34893C911BEB1300044E9C8 /* socks.h */,
3CAB26D5112B096700607AEE /* .gitignore */,
3CAB26D6112B096700607AEE /* anymap.h */,
3CAB26D7112B096700607AEE /* assert.cpp */,
@@ -591,6 +597,7 @@
files = (
E29FD2AB1136FD1D004BC293 /* timeout.h in Headers */,
3CC4CE561138646D001C21F2 /* progress.h in Headers */,
+ C34893CB11BEB1300044E9C8 /* socks.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -692,6 +699,7 @@
3CAB29E9112B347400607AEE /* timer.cpp in Sources */,
E29FD2AA1136FD1D004BC293 /* timeout.cpp in Sources */,
3CAC4A341151622F00F85725 /* iomanager_kqueue.cpp in Sources */,
+ C34893CA11BEB1300044E9C8 /* socks.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
@@ -5,6 +5,10 @@
#include "predef.h"
+#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1 && defined(__arm__))
+#include <boost/smart_ptr/detail/sp_counted_base_spin.hpp>
+#endif
+
namespace Mordor {
#ifdef WINDOWS
@@ -166,7 +170,7 @@ atomicSwap(volatile T &t, T newvalue)
return comparand;
}
#endif
-#elif (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
+#elif (__GNUC__ == 4 && __GNUC_MINOR__ >= 1 && !defined(__arm__))
template <class T>
typename boost::enable_if_c<sizeof(T) <= sizeof(void *), T>::type
atomicDecrement(volatile T& t) { return __sync_sub_and_fetch(&t, 1); }
@@ -220,6 +224,22 @@ atomicIncrement(volatile T& t) { return __gnu_cxx::__exchange_and_add((_Atomic_w
template <class T>
typename boost::enable_if_c<sizeof(T) <= sizeof(_Atomic_word), T>::type
atomicAdd(volatile T& t, T v) { return __gnu_cxx::__exchange_and_add((_Atomic_word*)_&t, v) + v; }
+#elif (__GNUC__ == 4 && __GNUC_MINOR__ >= 1 && defined(__arm__))
+template <class T>
+typename boost::enable_if_c<sizeof(T) <= sizeof(int), T>::type
+atomicAdd(volatile T& t, T v) { return boost::detail::atomic_exchange_and_add((int *)&t, (int)v) + v; }
+template <class T>
+typename boost::enable_if_c<sizeof(T) <= sizeof(int), T>::type
+atomicIncrement(volatile T& t) { return atomicAdd(t, (T)1); }
+template <class T>
+typename boost::enable_if_c<sizeof(T) <= sizeof(int), T>::type
+atomicCompareAndSwap(volatile T &t, T newvalue, T comparand) {
+ ::boost::detail::spinlock_pool<1>::scoped_lock lock((void *)&t);
+ T oldvalue = t;
+ if (oldvalue == comparand)
+ t = newvalue;
+ return oldvalue;
+}
#endif
template <typename T>
@@ -0,0 +1,102 @@
+// Copyright (c) 2009 - Mozy, Inc.
+
+#include "mordor/predef.h"
+
+#include <iostream>
+
+#include <DbgHelp.h>
+
+#include "mordor/config.h"
+#include "mordor/streams/buffered.h"
+#include "mordor/streams/std.h"
+
+using namespace Mordor;
+
+int main(int argc, const char *argv[])
+{
+ if (argc < 3) {
+ std::cerr << "Usage: " << argv[0] << " <symbolpath> <binary>..." << std::endl
+ << " Look for backtrace addresses on stdin, and attempt to convert them to" << std::endl
+ << " symbols of the given binaries." << std::endl << std::endl;
+ return 1;
+ }
+
+ std::vector<DWORD64> loadedModules;
+ try {
+ Config::loadFromEnvironment();
+ // Re-init symbols (it got initted statically in exception.cpp) with
+ // a symbol search path
+ if (!SymCleanup(GetCurrentProcess()))
+ MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("SymCleanup");
+ if (!SymInitialize(GetCurrentProcess(), argv[1], FALSE))
+ MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("SymInitialize");
+
+ // Load up the specified modules in their default load location
+ // Does *not* currently handle ASLR (basically, it would need to
+ // do two passes through the log, and calculate the actual load address
+ // of a module based on where the (limited) symbols that are in the
+ // file ended up; or, use a minidump to aid the process)
+ for (int i = 2; i < argc; ++i) {
+ DWORD64 baseAddress =
+ SymLoadModule64(GetCurrentProcess(), NULL, argv[i], NULL, 0, 0);
+ if (baseAddress == 0) {
+ if (GetLastError() == ERROR_SUCCESS)
+ continue;
+ MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("SymLoadModule64");
+ }
+ loadedModules.push_back(baseAddress);
+ }
+ char buf[sizeof(SYMBOL_INFO) + MAX_SYM_NAME - 1];
+ SYMBOL_INFO *symbol = (SYMBOL_INFO*)buf;
+ symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
+ symbol->MaxNameLen = MAX_SYM_NAME;
+ DWORD64 displacement64 = 0;
+
+ Stream::ptr stream(new StdinStream());
+ stream.reset(new BufferedStream(stream));
+ StdoutStream output;
+ std::string line;
+ do {
+ line = stream->getDelimited('\n', true);
+ std::string copy(line);
+ if (copy.size() >= 35 &&
+ strncmp(copy.c_str(), "[struct Mordor::tag_backtrace *] = ", 35)
+ == 0)
+ copy = copy.substr(35);
+ char *end;
+ DWORD64 address = strtoull(copy.c_str(), &end, 16);
+ if ( (end - copy.c_str()) == 8 || (end - copy.c_str()) == 16) {
+ if (SymFromAddr(GetCurrentProcess(), address, &displacement64, symbol)) {
+ std::ostringstream os;
+ if (copy != line)
+ os << "[struct Mordor::tag_backtrace *] = ";
+ os << copy.substr(0, (end - copy.c_str())) << ": "
+ << symbol->Name << "+" << displacement64;
+ IMAGEHLP_LINE64 line;
+ line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
+ DWORD displacement = 0;
+ if (SymGetLineFromAddr64(GetCurrentProcess(),
+ address, &displacement, &line)) {
+ std::cout << ": " << line.FileName << "("
+ << line.LineNumber << ")+" << displacement;
+ }
+ os << std::endl;
+ std::string newline = os.str();
+ output.write(newline.c_str(), newline.size());
+ } else {
+ output.write(line.c_str(), line.size());
+ }
+ } else {
+ output.write(line.c_str(), line.size());
+ }
+ } while (!line.empty() && line.back() == '\n');
+ } catch (...) {
+ std::cerr << boost::current_exception_diagnostic_information() << std::endl;
+ for (size_t i = 0; i < loadedModules.size(); ++i)
+ SymUnloadModule64(GetCurrentProcess(), loadedModules[i]);
+ return 2;
+ }
+ for (size_t i = 0; i < loadedModules.size(); ++i)
+ SymUnloadModule64(GetCurrentProcess(), loadedModules[i]);
+ return 0;
+}
Oops, something went wrong.

0 comments on commit de4089c

Please sign in to comment.