webclient.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /**
  2. * \addtogroup webclient
  3. * @{
  4. */
  5. /**
  6. * \file
  7. * Header file for the HTTP client.
  8. * \author Adam Dunkels <adam@dunkels.com>
  9. */
  10. /*
  11. * Copyright (c) 2002, Adam Dunkels.
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions
  16. * are met:
  17. * 1. Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. * 2. Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. * 3. The name of the author may not be used to endorse or promote
  24. * products derived from this software without specific prior
  25. * written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
  28. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  29. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  30. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  31. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  33. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  34. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  35. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  36. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  37. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. * This file is part of the uIP TCP/IP stack.
  40. *
  41. * $Id: webclient.h,v 1.2 2006/06/11 21:46:37 adam Exp $
  42. *
  43. */
  44. #ifndef __WEBCLIENT_H__
  45. #define __WEBCLIENT_H__
  46. #include "webclient-strings.h"
  47. #include "uipopt.h"
  48. #define WEBCLIENT_CONF_MAX_URLLEN 100
  49. struct webclient_state {
  50. u8_t timer;
  51. u8_t state;
  52. u8_t httpflag;
  53. u16_t port;
  54. char host[40];
  55. char file[WEBCLIENT_CONF_MAX_URLLEN];
  56. u16_t getrequestptr;
  57. u16_t getrequestleft;
  58. char httpheaderline[200];
  59. u16_t httpheaderlineptr;
  60. char mimetype[32];
  61. };
  62. typedef struct webclient_state uip_tcp_appstate_t;
  63. #define UIP_APPCALL webclient_appcall
  64. /**
  65. * Callback function that is called from the webclient code when HTTP
  66. * data has been received.
  67. *
  68. * This function must be implemented by the module that uses the
  69. * webclient code. The function is called from the webclient module
  70. * when HTTP data has been received. The function is not called when
  71. * HTTP headers are received, only for the actual data.
  72. *
  73. * \note This function is called many times, repetedly, when data is
  74. * being received, and not once when all data has been received.
  75. *
  76. * \param data A pointer to the data that has been received.
  77. * \param len The length of the data that has been received.
  78. */
  79. void webclient_datahandler(char *data, u16_t len);
  80. /**
  81. * Callback function that is called from the webclient code when the
  82. * HTTP connection has been connected to the web server.
  83. *
  84. * This function must be implemented by the module that uses the
  85. * webclient code.
  86. */
  87. void webclient_connected(void);
  88. /**
  89. * Callback function that is called from the webclient code if the
  90. * HTTP connection to the web server has timed out.
  91. *
  92. * This function must be implemented by the module that uses the
  93. * webclient code.
  94. */
  95. void webclient_timedout(void);
  96. /**
  97. * Callback function that is called from the webclient code if the
  98. * HTTP connection to the web server has been aborted by the web
  99. * server.
  100. *
  101. * This function must be implemented by the module that uses the
  102. * webclient code.
  103. */
  104. void webclient_aborted(void);
  105. /**
  106. * Callback function that is called from the webclient code when the
  107. * HTTP connection to the web server has been closed.
  108. *
  109. * This function must be implemented by the module that uses the
  110. * webclient code.
  111. */
  112. void webclient_closed(void);
  113. /**
  114. * Initialize the webclient module.
  115. */
  116. void webclient_init(void);
  117. /**
  118. * Open an HTTP connection to a web server and ask for a file using
  119. * the GET method.
  120. *
  121. * This function opens an HTTP connection to the specified web server
  122. * and requests the specified file using the GET method. When the HTTP
  123. * connection has been connected, the webclient_connected() callback
  124. * function is called and when the HTTP data arrives the
  125. * webclient_datahandler() callback function is called.
  126. *
  127. * The callback function webclient_timedout() is called if the web
  128. * server could not be contacted, and the webclient_aborted() callback
  129. * function is called if the HTTP connection is aborted by the web
  130. * server.
  131. *
  132. * When the HTTP request has been completed and the HTTP connection is
  133. * closed, the webclient_closed() callback function will be called.
  134. *
  135. * \note If the function is passed a host name, it must already be in
  136. * the resolver cache in order for the function to connect to the web
  137. * server. It is therefore up to the calling module to implement the
  138. * resolver calls and the signal handler used for reporting a resolv
  139. * query answer.
  140. *
  141. * \param host A pointer to a string containing either a host name or
  142. * a numerical IP address in dotted decimal notation (e.g., 192.168.23.1).
  143. *
  144. * \param port The port number to which to connect, in host byte order.
  145. *
  146. * \param file A pointer to the name of the file to get.
  147. *
  148. * \retval 0 if the host name could not be found in the cache, or
  149. * if a TCP connection could not be created.
  150. *
  151. * \retval 1 if the connection was initiated.
  152. */
  153. unsigned char webclient_get(char *host, u16_t port, char *file);
  154. /**
  155. * Close the currently open HTTP connection.
  156. */
  157. void webclient_close(void);
  158. void webclient_appcall(void);
  159. /**
  160. * Obtain the MIME type of the current HTTP data stream.
  161. *
  162. * \return A pointer to a string contaning the MIME type. The string
  163. * may be empty if no MIME type was reported by the web server.
  164. */
  165. char *webclient_mimetype(void);
  166. /**
  167. * Obtain the filename of the current HTTP data stream.
  168. *
  169. * The filename of an HTTP request may be changed by the web server,
  170. * and may therefore not be the same as when the original GET request
  171. * was made with webclient_get(). This function is used for obtaining
  172. * the current filename.
  173. *
  174. * \return A pointer to the current filename.
  175. */
  176. char *webclient_filename(void);
  177. /**
  178. * Obtain the hostname of the current HTTP data stream.
  179. *
  180. * The hostname of the web server of an HTTP request may be changed
  181. * by the web server, and may therefore not be the same as when the
  182. * original GET request was made with webclient_get(). This function
  183. * is used for obtaining the current hostname.
  184. *
  185. * \return A pointer to the current hostname.
  186. */
  187. char *webclient_hostname(void);
  188. /**
  189. * Obtain the port number of the current HTTP data stream.
  190. *
  191. * The port number of an HTTP request may be changed by the web
  192. * server, and may therefore not be the same as when the original GET
  193. * request was made with webclient_get(). This function is used for
  194. * obtaining the current port number.
  195. *
  196. * \return The port number of the current HTTP data stream, in host byte order.
  197. */
  198. unsigned short webclient_port(void);
  199. #endif /* __WEBCLIENT_H__ */
  200. /** @} */