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