mod_redir.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #ifndef _PRO_UHTTP_MODULES_MOD_REDIR_H_
  2. #define _PRO_UHTTP_MODULES_MOD_REDIR_H_
  3. /*
  4. * Copyright (C) 2012 by egnite GmbH
  5. *
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. Neither the name of the copyright holders nor the names of
  18. * contributors may be used to endorse or promote products derived
  19. * from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  31. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. *
  34. * For additional information see http://www.ethernut.de/
  35. */
  36. /*!
  37. * $Id$
  38. */
  39. #include <isc/list.h>
  40. #include <pro/uhttp/uhttpd.h>
  41. /*!
  42. * \addtogroup xgUHTTPModRedir Redirection
  43. * \ingroup xgUHTTPModules
  44. */
  45. /*@{*/
  46. /*!
  47. * \brief HTTP redirection entry type.
  48. */
  49. typedef struct _HTTP_LOCATION HTTP_LOCATION;
  50. /*!
  51. * \brief HTTP redirection information structure.
  52. */
  53. struct _HTTP_LOCATION {
  54. /*! \brief Chain link */
  55. ISC_LINK(HTTP_LOCATION) loc_link;
  56. /*! \brief Redirected resource. */
  57. char *loc_uri;
  58. /*! \brief Redirection target. */
  59. char *loc_redir;
  60. /*! \brief HTTP response code. */
  61. int loc_response;
  62. /*! \brief Not used? */
  63. const char *loc_resptext;
  64. };
  65. /*!
  66. * \brief Register an HTTP redirection.
  67. *
  68. * The following sample permanently redirects an empty resource to
  69. * the index page index.html.
  70. *
  71. * \code
  72. * #include <pro/uhttp/modules/mod_redir.h>
  73. *
  74. * HttpRegisterRedir("", "/index.html", 301);
  75. * \endcode
  76. *
  77. * This function will automatically set the default redirection handler
  78. * HttpLocationRedir().
  79. *
  80. * \param url The resource that will be redirected.
  81. * \param redir The redirection target.
  82. * \param response The HTTP response code that will be send with the
  83. * redirection.
  84. *
  85. * \return 0 if the redirection has been successfully registered.
  86. * Otherwise -1 is returned.
  87. */
  88. extern int HttpRegisterRedir(const char *url, const char *redir, int response);
  89. /*!
  90. * \brief Default HTTP redirection handler.
  91. *
  92. * This function is automatically called by the default client handler
  93. * function HttpdClientHandler() after at least one redirection entry
  94. * had been registered.
  95. *
  96. * \param hs Pointer to the session info structure.
  97. *
  98. * \return 0 if a redirection response had been sent. -1 is returned if
  99. * no redirection exists, in which case the caller should handle
  100. * the original request.
  101. */
  102. extern int HttpLocationRedir(HTTPD_SESSION *hs);
  103. /*!
  104. * \brief Retrieve redirection entry for a given resource.
  105. *
  106. * This routine may be used by custom redirection handlers.
  107. */
  108. HTTP_LOCATION *HttpLocationLookup(const char *uri);
  109. /*@}*/
  110. #endif