GCDWebServerFunctions.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. Copyright (c) 2012-2015, 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 <Foundation/Foundation.h>
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. /**
  30. * Converts a file extension to the corresponding MIME type.
  31. * If there is no match, "application/octet-stream" is returned.
  32. */
  33. NSString* GCDWebServerGetMimeTypeForExtension(NSString* extension);
  34. /**
  35. * Add percent-escapes to a string so it can be used in a URL.
  36. * The legal characters ":@/?&=+" are also escaped to ensure compatibility
  37. * with URL encoded forms and URL queries.
  38. */
  39. NSString* GCDWebServerEscapeURLString(NSString* string);
  40. /**
  41. * Unescapes a URL percent-encoded string.
  42. */
  43. NSString* GCDWebServerUnescapeURLString(NSString* string);
  44. /**
  45. * Extracts the unescaped names and values from an
  46. * "application/x-www-form-urlencoded" form.
  47. * http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1
  48. */
  49. NSDictionary* GCDWebServerParseURLEncodedForm(NSString* form);
  50. /**
  51. * On OS X, returns the IPv4 or IPv6 address as a string of the primary
  52. * connected service or nil if not available.
  53. *
  54. * On iOS, returns the IPv4 or IPv6 address as a string of the WiFi
  55. * interface if connected or nil otherwise.
  56. */
  57. NSString* GCDWebServerGetPrimaryIPAddress(BOOL useIPv6);
  58. /**
  59. * Converts a date into a string using RFC822 formatting.
  60. * https://tools.ietf.org/html/rfc822#section-5
  61. * https://tools.ietf.org/html/rfc1123#section-5.2.14
  62. */
  63. NSString* GCDWebServerFormatRFC822(NSDate* date);
  64. /**
  65. * Converts a RFC822 formatted string into a date.
  66. * https://tools.ietf.org/html/rfc822#section-5
  67. * https://tools.ietf.org/html/rfc1123#section-5.2.14
  68. *
  69. * @warning Timezones other than GMT are not supported by this function.
  70. */
  71. NSDate* GCDWebServerParseRFC822(NSString* string);
  72. /**
  73. * Converts a date into a string using IOS 8601 formatting.
  74. * http://tools.ietf.org/html/rfc3339#section-5.6
  75. */
  76. NSString* GCDWebServerFormatISO8601(NSDate* date);
  77. /**
  78. * Converts a ISO 8601 formatted string into a date.
  79. * http://tools.ietf.org/html/rfc3339#section-5.6
  80. *
  81. * @warning Only "calendar" variant is supported at this time and timezones
  82. * other than GMT are not supported either.
  83. */
  84. NSDate* GCDWebServerParseISO8601(NSString* string);
  85. #ifdef __cplusplus
  86. }
  87. #endif