mod_cgi_func.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #ifndef _PRO_UHTTP_MODULES_MOD_CGI_H_
  2. #define _PRO_UHTTP_MODULES_MOD_CGI_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/mediatypes.h>
  41. /*!
  42. * \addtogroup xgUHTTPModCgiFunc CGI functions
  43. * \ingroup xgUHTTPModules
  44. */
  45. /*@{*/
  46. /*!
  47. * \brief Common gateway interface function entry type.
  48. */
  49. typedef struct _HTTP_CGI_FUNCTION HTTP_CGI_FUNCTION;
  50. typedef int (*HTTP_CGI_HANDLER) (HTTPD_SESSION*);
  51. /*!
  52. * \brief Common gateway interface function entry structure.
  53. *
  54. * Be prepared, that the layout of this structure may change in future
  55. * versions.
  56. */
  57. struct _HTTP_CGI_FUNCTION {
  58. /*! \brief Chain link. */
  59. ISC_LINK(HTTP_CGI_FUNCTION) cgi_link;
  60. /*! \brief URI of the CGI function. */
  61. char *cgi_uri;
  62. /*! \brief Registered CGI function. */
  63. HTTP_CGI_HANDLER cgi_handler;
  64. };
  65. /*!
  66. * \brief Register a common gateway interface function.
  67. *
  68. *
  69. * Usage example:
  70. *
  71. * \code
  72. * #include <pro/uhttp/modules/mod_cgi_func.h>
  73. *
  74. * int CgiTest(HTTPD_SESSION *hs, const HTTP_CGI_FUNCTION *cgi)
  75. * {
  76. * ...
  77. * return 0
  78. * }
  79. *
  80. * if (HttpRegisterCgiFunction("cgi/test.cgi", CgiTest) == 0) {
  81. * puts("CGI registered.");
  82. * ...
  83. * } else {
  84. * puts("Failed to register CGI.");
  85. * ...
  86. * }
  87. *
  88. * if (HttpRegisterCgiFunction("cgi/test.cgi", NULL) == 0) {
  89. * puts("CGI unregistered.");
  90. * ...
  91. * } else {
  92. * puts("Failed to unregister CGI.");
  93. * ...
  94. * }
  95. *
  96. * if (HttpRegisterMediaType("cgi", NULL, NULL, HttpCgiFunctionHandler) == 0) {
  97. * puts("Media type CGI registered.");
  98. * ...
  99. * } else {
  100. * puts("Failed to register CGI media type.");
  101. * ...
  102. * }
  103. * \endcode
  104. *
  105. * \param uri Case insensitive URI of this CGI. Previously registered
  106. * functions may be overridden by subsequent calls using
  107. * the same URI.
  108. * \param handler Pointer to the function that will be called if the given
  109. * URI is requested, or NULL to unregister the CGI function.
  110. *
  111. * \return 0 on success or -1 on error.
  112. */
  113. extern int HttpRegisterCgiFunction(const char *uri, HTTP_CGI_HANDLER handler);
  114. /*!
  115. * \brief Default media type handler for CGI functions.
  116. */
  117. extern int HttpCgiFunctionHandler(HTTPD_SESSION *hs, const MEDIA_TYPE_ENTRY *mt, const char *filepath);
  118. /*@}*/
  119. #endif