GCDWebServerPrivate.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. Copyright (c) 2012-2013, 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. * Neither the name of the <organization> nor the
  12. names of its contributors may be used to endorse or promote products
  13. derived from this software without specific 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 <COPYRIGHT HOLDER> 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 "GCDWebServerConnection.h"
  26. #ifdef __GCDWEBSERVER_LOGGING_HEADER__
  27. // Define __GCDWEBSERVER_LOGGING_HEADER__ as a preprocessor constant to redirect GCDWebServer logging to your own system
  28. #import __GCDWEBSERVER_LOGGING_HEADER__
  29. #else
  30. static inline void __LogMessage(long level, NSString* format, ...) {
  31. static const char* levelNames[] = {"DEBUG", "VERBOSE", "INFO", "WARNING", "ERROR", "EXCEPTION"};
  32. static long minLevel = -1;
  33. if (minLevel < 0) {
  34. const char* logLevel = getenv("logLevel");
  35. minLevel = logLevel ? atoi(logLevel) : 0;
  36. }
  37. if (level >= minLevel) {
  38. va_list arguments;
  39. va_start(arguments, format);
  40. NSString* message = [[NSString alloc] initWithFormat:format arguments:arguments];
  41. va_end(arguments);
  42. printf("[%s] %s\n", levelNames[level], [message UTF8String]);
  43. [message release];
  44. }
  45. }
  46. #define LOG_VERBOSE(...) __LogMessage(1, __VA_ARGS__)
  47. #define LOG_INFO(...) __LogMessage(2, __VA_ARGS__)
  48. #define LOG_WARNING(...) __LogMessage(3, __VA_ARGS__)
  49. #define LOG_ERROR(...) __LogMessage(4, __VA_ARGS__)
  50. #define LOG_EXCEPTION(__EXCEPTION__) __LogMessage(5, @"%@", __EXCEPTION__)
  51. #ifdef NDEBUG
  52. #define DCHECK(__CONDITION__)
  53. #define DNOT_REACHED()
  54. #define LOG_DEBUG(...)
  55. #else
  56. #define DCHECK(__CONDITION__) \
  57. do { \
  58. if (!(__CONDITION__)) { \
  59. abort(); \
  60. } \
  61. } while (0)
  62. #define DNOT_REACHED() abort()
  63. #define LOG_DEBUG(...) __LogMessage(0, __VA_ARGS__)
  64. #endif
  65. #endif
  66. #define kGCDWebServerDefaultMimeType @"application/octet-stream"
  67. #ifdef __cplusplus
  68. extern "C" {
  69. #endif
  70. NSString* GCDWebServerGetMimeTypeForExtension(NSString* extension);
  71. NSString* GCDWebServerUnescapeURLString(NSString* string);
  72. NSDictionary* GCDWebServerParseURLEncodedForm(NSString* form);
  73. #ifdef __cplusplus
  74. }
  75. #endif
  76. @interface GCDWebServerConnection ()
  77. - (id)initWithServer:(GCDWebServer*)server address:(NSData*)address socket:(CFSocketNativeHandle)socket;
  78. @end
  79. @interface GCDWebServer ()
  80. @property(nonatomic, readonly) NSArray* handlers;
  81. @end
  82. @interface GCDWebServerHandler : NSObject {
  83. @private
  84. GCDWebServerMatchBlock _matchBlock;
  85. GCDWebServerProcessBlock _processBlock;
  86. }
  87. @property(nonatomic, readonly) GCDWebServerMatchBlock matchBlock;
  88. @property(nonatomic, readonly) GCDWebServerProcessBlock processBlock;
  89. - (id)initWithMatchBlock:(GCDWebServerMatchBlock)matchBlock processBlock:(GCDWebServerProcessBlock)processBlock;
  90. @end