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