GCDWebServerPrivate.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. Copyright (c) 2012-2014, Pierre-Olivier Latour
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * The name of Pierre-Olivier Latour may not be used to endorse
  12. or promote products derived from this software without specific
  13. prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY
  18. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #import <TargetConditionals.h>
  26. #import <AvailabilityMacros.h>
  27. #if __has_feature(objc_arc)
  28. #define ARC_BRIDGE __bridge
  29. #define ARC_BRIDGE_RELEASE(__OBJECT__) CFBridgingRelease(__OBJECT__)
  30. #define ARC_RETAIN(__OBJECT__) __OBJECT__
  31. #define ARC_RELEASE(__OBJECT__)
  32. #define ARC_AUTORELEASE(__OBJECT__) __OBJECT__
  33. #define ARC_DEALLOC(__OBJECT__)
  34. #if (TARGET_OS_IPHONE && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_6_0)) || (!TARGET_OS_IPHONE && (__MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_8))
  35. #define ARC_DISPATCH_RELEASE(__OBJECT__)
  36. #else
  37. #define ARC_DISPATCH_RELEASE(__OBJECT__) dispatch_release(__OBJECT__)
  38. #endif
  39. #else
  40. #define ARC_BRIDGE
  41. #define ARC_BRIDGE_RELEASE(__OBJECT__) [(id)__OBJECT__ autorelease]
  42. #define ARC_RETAIN(__OBJECT__) [__OBJECT__ retain]
  43. #define ARC_RELEASE(__OBJECT__) [__OBJECT__ release]
  44. #define ARC_AUTORELEASE(__OBJECT__) [__OBJECT__ autorelease]
  45. #define ARC_DEALLOC(__OBJECT__) [__OBJECT__ dealloc]
  46. #define ARC_DISPATCH_RELEASE(__OBJECT__) dispatch_release(__OBJECT__)
  47. #endif
  48. #import "GCDWebServerConnection.h"
  49. #ifdef __GCDWEBSERVER_LOGGING_HEADER__
  50. // Define __GCDWEBSERVER_LOGGING_HEADER__ as a preprocessor constant to redirect GCDWebServer logging to your own system
  51. #import __GCDWEBSERVER_LOGGING_HEADER__
  52. #else
  53. extern void GCDLogMessage(long level, NSString* format, ...) NS_FORMAT_FUNCTION(2, 3);
  54. #define LOG_VERBOSE(...) GCDLogMessage(1, __VA_ARGS__)
  55. #define LOG_INFO(...) GCDLogMessage(2, __VA_ARGS__)
  56. #define LOG_WARNING(...) GCDLogMessage(3, __VA_ARGS__)
  57. #define LOG_ERROR(...) GCDLogMessage(4, __VA_ARGS__)
  58. #define LOG_EXCEPTION(__EXCEPTION__) GCDLogMessage(5, @"%@", __EXCEPTION__)
  59. #ifdef NDEBUG
  60. #define DCHECK(__CONDITION__)
  61. #define DNOT_REACHED()
  62. #define LOG_DEBUG(...)
  63. #else
  64. #define DCHECK(__CONDITION__) \
  65. do { \
  66. if (!(__CONDITION__)) { \
  67. abort(); \
  68. } \
  69. } while (0)
  70. #define DNOT_REACHED() abort()
  71. #define LOG_DEBUG(...) GCDLogMessage(0, __VA_ARGS__)
  72. #endif
  73. #endif
  74. #define kGCDWebServerDefaultMimeType @"application/octet-stream"
  75. #define kGCDWebServerGCDQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
  76. @interface GCDWebServerConnection ()
  77. - (id)initWithServer:(GCDWebServer*)server localAddress:(NSData*)localAddress remoteAddress:(NSData*)remoteAddress socket:(CFSocketNativeHandle)socket;
  78. @end
  79. @interface GCDWebServer ()
  80. @property(nonatomic, readonly) NSArray* handlers;
  81. @end
  82. @interface GCDWebServerHandler : NSObject
  83. @property(nonatomic, readonly) GCDWebServerMatchBlock matchBlock;
  84. @property(nonatomic, readonly) GCDWebServerProcessBlock processBlock;
  85. - (id)initWithMatchBlock:(GCDWebServerMatchBlock)matchBlock processBlock:(GCDWebServerProcessBlock)processBlock;
  86. @end