webserver.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /**************************************************************************
  2. *
  3. * Copyright (c) 2000-2003 Intel Corporation
  4. * 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 are met:
  8. *
  9. * - Redistributions of source code must retain the above copyright notice,
  10. * this list of conditions and the following disclaimer.
  11. * - Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. * - Neither name of Intel Corporation nor the names of its contributors
  15. * may be used to endorse or promote products derived from this software
  16. * without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
  22. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  25. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  26. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. **************************************************************************/
  31. #ifndef GENLIB_NET_HTTP_WEBSERVER_H
  32. #define GENLIB_NET_HTTP_WEBSERVER_H
  33. #include <time.h>
  34. #include "sock.h"
  35. #include "httpparser.h"
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. struct SendInstruction
  40. {
  41. int IsVirtualFile;
  42. int IsChunkActive;
  43. int IsRangeActive;
  44. int IsTrailers;
  45. char RangeHeader[200];
  46. char AcceptLanguageHeader[200];
  47. off_t RangeOffset;
  48. /*! Read from local source and send on the network. */
  49. off_t ReadSendSize;
  50. /*! Recv from the network and write into local file. */
  51. long RecvWriteSize;
  52. /* Later few more member could be added depending
  53. * on the requirement.*/
  54. };
  55. /*!
  56. * \brief Initilialize the different documents. Initialize the memory
  57. * for root directory for web server. Call to initialize global XML
  58. * document. Sets bWebServerState to WEB_SERVER_ENABLED.
  59. *
  60. * \note alias_content is not freed here
  61. *
  62. * \return
  63. * \li \c 0 - OK
  64. * \li \c UPNP_E_OUTOF_MEMORY
  65. */
  66. int web_server_init(void);
  67. /*!
  68. * \brief Release memory allocated for the global web server root
  69. * directory and the global XML document. Resets the flag bWebServerState
  70. * to WEB_SERVER_DISABLED.
  71. */
  72. void web_server_destroy(void);
  73. /*!
  74. * \brief Replaces current alias with the given alias. To remove the current
  75. * alias, set alias_name to NULL.
  76. *
  77. * \note alias_content is not freed here
  78. *
  79. * \return
  80. * \li \c 0 - OK
  81. * \li \c UPNP_E_OUTOF_MEMORY
  82. */
  83. int web_server_set_alias(
  84. /*! [in] Webserver name of alias; created by caller and freed by caller
  85. * (doesn't even have to be malloc()d. */
  86. const char* alias_name,
  87. /*! [in] The xml doc; this is allocated by the caller; and freed by
  88. * the web server. */
  89. const char* alias_content,
  90. /*! [in] Length of alias body in bytes. */
  91. size_t alias_content_length,
  92. /*! [in] Time when the contents of alias were last changed (local time). */
  93. time_t last_modified);
  94. /*!
  95. * \brief Assign the path specfied by the input const char* root_dir parameter
  96. * to the global Document root directory. Also check for path names ending
  97. * in '/'.
  98. *
  99. * \return Integer.
  100. */
  101. int web_server_set_root_dir(
  102. /*! [in] String having the root directory for the document. */
  103. const char* root_dir);
  104. /*!
  105. * \brief Main entry point into web server; Handles HTTP GET and HEAD
  106. * requests.
  107. */
  108. void web_server_callback(
  109. /*! [in] . */
  110. http_parser_t *parser,
  111. /*! [in] . */
  112. http_message_t *req,
  113. /*! [in,out] . */
  114. SOCKINFO *info);
  115. #ifdef __cplusplus
  116. } /* extern C */
  117. #endif
  118. #endif /* GENLIB_NET_HTTP_WEBSERVER_H */