httpd.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #ifndef _PRO_HTTPD_H_
  2. #define _PRO_HTTPD_H_
  3. /*
  4. * Copyright (C) 2001-2004 by egnite Software GmbH. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
  23. * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. /*
  35. * $Log: httpd.h,v $
  36. * Revision 1.8 2006/10/08 16:43:53 haraldkipp
  37. * Authentication info depended on static memory kept by the caller. Now a
  38. * local copy is held and NutClearAuth (which should have been named
  39. * NutHttpAuthClear, btw.) works correctly.
  40. *
  41. * Revision 1.7 2006/08/25 13:42:16 olereinhardt
  42. * added NutClearAuth(void); Thanks to Peter Sondermanns
  43. *
  44. * Revision 1.6 2006/03/16 15:25:34 haraldkipp
  45. * Changed human readable strings from u_char to char to stop GCC 4 from
  46. * nagging about signedness.
  47. *
  48. * Revision 1.5 2005/08/26 14:12:39 olereinhardt
  49. * Added NutHttpProcessPostQuery(FILE *stream, REQUEST * req)
  50. *
  51. * Revision 1.4 2005/08/05 11:23:11 olereinhardt
  52. * Added support to register a custom handler for mime types.
  53. * Added Server side include support and ASP support.
  54. *
  55. * Revision 1.3 2005/06/26 13:35:26 chaac
  56. * Added forgotten prototype for NutRegisterHttpRoot, fixes bug #1215853. Also fixed some prototypes when compiling with C++.
  57. *
  58. * Revision 1.2 2004/12/16 10:17:18 haraldkipp
  59. * Added Mikael Adolfsson's excellent parameter parsing routines.
  60. *
  61. */
  62. #include <stdio.h>
  63. /*!
  64. * \file pro/httpd.h
  65. * \brief HTTP protocol definitions for daemons.
  66. */
  67. /*!
  68. * \addtogroup xgHTTPD
  69. */
  70. /*@{*/
  71. #define METHOD_GET 1
  72. #define METHOD_POST 2
  73. #define METHOD_HEAD 3
  74. typedef struct _REQUEST REQUEST;
  75. /*!
  76. * \struct _REQUEST httpd.h pro/httpd.h
  77. * \brief HTTP request information structure.
  78. */
  79. struct _REQUEST {
  80. int req_method; /*!< \brief Request method. */
  81. int req_version; /*!< \brief 11 = HTTP/1.1, 10 = HTTP/1.0, 9 = HTTP/0.9 */
  82. int req_length; /*!< \brief Content length */
  83. char *req_url; /*!< \brief URI portion of the GET or POST request line */
  84. char *req_query; /*!< \brief Argument string. */
  85. char *req_type; /*!< \brief Content type. */
  86. char *req_cookie; /*!< \brief Cookie. */
  87. char *req_auth; /*!< \brief Authorization info. */
  88. char *req_agent; /*!< \brief User agent. */
  89. char **req_qptrs; /*!< \brief Table of request parameters */
  90. int req_numqptrs; /*!< \brief Number of request parameters */
  91. };
  92. __BEGIN_DECLS
  93. extern void NutHttpProcessRequest(FILE * stream);
  94. extern void NutHttpProcessQueryString(REQUEST * req);
  95. extern void NutHttpSendHeaderTop(FILE * stream, REQUEST * req, int status, char *title);
  96. extern void NutHttpSendHeaderBot(FILE * stream, char *mime_type, long bytes);
  97. extern void NutHttpSendError(FILE * stream, REQUEST * req, int status);
  98. extern char *NutGetMimeType(char *name);
  99. extern void *NutGetMimeHandler(char *name);
  100. extern u_char NutSetMimeHandler(char *extension, void (*handler)(FILE *stream, int fd, int file_len, char *http_root, REQUEST *req));
  101. __END_DECLS
  102. /*
  103. * Authorization
  104. */
  105. typedef struct _AUTHINFO AUTHINFO;
  106. /*!
  107. * \struct _AUTHINFO httpd.h pro/httpd.h
  108. * \brief HTTP authorization information structure.
  109. */
  110. struct _AUTHINFO {
  111. AUTHINFO *auth_next; /*!< \brief Link to next AUTHINFO structure */
  112. char *auth_dirname; /*!< \brief Pathname of protected directory */
  113. char *auth_login; /*!< \brief Login user and password, separated by a colon. */
  114. };
  115. __BEGIN_DECLS
  116. extern int NutHttpAuthValidate(REQUEST * req);
  117. extern int NutRegisterAuth(CONST char *dirname, CONST char *login);
  118. extern void NutClearAuth(void);
  119. __END_DECLS
  120. /*
  121. * CGI
  122. */
  123. typedef struct _CGIFUNCTION CGIFUNCTION;
  124. /*!
  125. * \struct _CGIFUNCTION httpd.h pro/httpd.h
  126. * \brief Registered CGI function.
  127. */
  128. struct _CGIFUNCTION {
  129. CGIFUNCTION *cgi_next; /*!< \brief Link to next CGIFUNCTION structure */
  130. CONST char *cgi_name; /*!< \brief Name of this function */
  131. int (*cgi_func) (FILE *, REQUEST *); /*!< \brief Pointer to function code. */
  132. };
  133. /*@}*/
  134. __BEGIN_DECLS
  135. /* Function prototypes. */
  136. extern int NutRegisterHttpRoot(char *path);
  137. extern int NutRegisterCgi(char *name, int (*func) (FILE *, REQUEST *));
  138. extern void NutCgiProcessRequest(FILE * stream, REQUEST * req);
  139. extern void NutHttpProcessPostQuery(FILE *stream, REQUEST * req);
  140. extern char *NutHttpURLEncode(char *str);
  141. extern void NutHttpURLDecode(char *str);
  142. extern char *NutHttpGetParameter(REQUEST * req, char *name);
  143. extern int NutHttpGetParameterCount(REQUEST * req);
  144. extern char *NutHttpGetParameterName(REQUEST * req, int index);
  145. extern char *NutHttpGetParameterValue(REQUEST * req, int index);
  146. __END_DECLS
  147. /* */
  148. #endif