These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!

Committer:
frank26080115
Date:
Sun Mar 20 05:38:56 2011 +0000
Revision:
0:bf7b9fba3924

        

Who changed what in which revision?

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