Network Developers Kit API  3.70.00.10
httpif.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2018, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * */
32 /*
33  * ======== httpif.h ========
34  *
35  */
36 
48 #ifndef _HTTPIF_H_
49 #define _HTTPIF_H_
50 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 /* HTTP SERVER SERVICE */
59 
60 /* HTTP Parameter Structure */
61 typedef struct _ntparam_http {
62  int MaxCon;
63  int Port;
64 } NTPARAM_HTTP;
65 
83 extern void *httpOpen( NTARGS *pNTA, NTPARAM_HTTP *pNTP );
84 
99 extern void httpClose(void *hHTTP);
100 
102 /*
103  * This is typically an internal fxn, so is not documented. However,
104  * IPv6 users do need access to this symbol for reasons described in
105  * the API users guide.
106  */
107 
108 /* httpClientProcess */
109 /* This entry point is used to invoke HTTP directly from */
110 /* the server daemon. */
111 extern int httpClientProcess( SOCKET Sock, uint32_t unused );
112 
115 /* Public String Definitions */
116 /*
117 char *CONTENT_TYPE_APPLET = "application/octet-stream ";
118 char *CONTENT_TYPE_AU = "audio/au ";
119 char *CONTENT_TYPE_DOC = "application/msword ";
120 char *CONTENT_TYPE_GIF = "image/gif ";
121 char *CONTENT_TYPE_HTML = "text/html ";
122 char *CONTENT_TYPE_JPG = "image/jpeg ";
123 char *CONTENT_TYPE_MPEG = "video/mpeg ";
124 char *CONTENT_TYPE_PDF = "application/pdf ";
125 char *CONTENT_TYPE_WAV = "audio/wav ";
126 char *CONTENT_TYPE_ZIP = "application/zip ";
127 char *CONTENT_TYPE = "Content-type: ";
128 char *CONTENT_LENGTH = "Content-length: ";
129 char *CRLF = "\r\n";
130 char *DEFAULT_NAME = "index.html";
131 char *HTTP_VER = "HTTP/1.0 ";
132 char *SPACE = " ";
133 */
134 extern char *CONTENT_TYPE_APPLET;
135 extern char *CONTENT_TYPE_AU;
136 extern char *CONTENT_TYPE_CSS; /* Add June 1st, 2010, KQ */
137 extern char *CONTENT_TYPE_DOC;
138 extern char *CONTENT_TYPE_GIF;
139 extern char *CONTENT_TYPE_HTML;
140 extern char *CONTENT_TYPE_JPG;
141 extern char *CONTENT_TYPE_MPEG;
142 extern char *CONTENT_TYPE_PDF;
143 extern char *CONTENT_TYPE_WAV;
144 extern char *CONTENT_TYPE_ZIP;
145 extern char *CONTENT_TYPE;
146 extern char *CONTENT_LENGTH;
147 extern char *CRLF;
148 extern char *DEFAULT_NAME;
149 extern char *HTTP_VER;
150 extern char *SPACE;
151 
152 /* Status codes for httpSendFullResponse() and httpSendStatusLine() */
154 {
155  HTTP_OK=200,
163 };
164 
165 #define HTTPPORT 80
166 #define MAX_RESPONSE_SIZE 200
167 
168 extern int httpVersion(void);
169 
170 /* httpSendClientStr */
171 /* Sends the indicated NULL terminated response string to */
172 /* the indicated client socket - i.e.: calls strlen() and send() */
173 extern void httpSendClientStr( SOCKET Sock, char *Response );
174 
175 /* httpSendStatusLine */
176 /* Sends a formatted response message to Sock with the given */
177 /* status code and content type. The value of ContentType can */
178 /* be NULL if no ContentType is required. */
179 extern void httpSendStatusLine( SOCKET Sock, int StatusCode, char *ContentType );
180 
181 /* httpSendFullResponse */
182 /* Sends a full formatted response message to Sock, including the */
183 /* file indicated by the filename in RequestedFile. The status code */
184 /* for this call is usually HTTP_OK. */
185 extern void httpSendFullResponse( SOCKET Sock, int StatusCode,
186  char *RequestedFile );
187 
188 /* httpSendEntityLength */
189 /* Write out the entiry length tag, and terminates the header */
190 /* with an additional CRLF. */
191 /* Since the header is terminated, this must be the last tag */
192 /* written. Entity data should follow immediately. */
193 extern void httpSendEntityLength( SOCKET Sock, int32_t EntityLength );
194 
195 
196 /* httpSendErrorResponse */
197 /* Sends a formatted error response message to Sock based on the */
198 /* status code. */
199 extern void httpSendErrorResponse( SOCKET Sock, int StatusCode );
200 
201 
202 /* httpErrorResponseHook */
203 /* Pointer to hook error response functions. Once an application */
204 /* writes a pointer to httpErrorResponseHook, the function will */
205 /* be called to generate all HTML code contained in any error */
206 /* response message. This function is optional and should not be */
207 /* used unless required. */
208 /* The installed callback should generate only the "Content Length" */
209 /* tag, followed immediately by the HTML data. The content length */
210 /* tag can be written using the httpSendEntityLength() function. */
211 /* (This function also terminates the HTTP header.) */
212 /* The installed callback returns: */
213 /* 1 - Error was handled and HTML was generated by the callback */
214 /* 0 - No HTML was generated (HTTP server should use its default) */
215 extern int (*httpErrorResponseHook)(SOCKET Sock, int StatusCode);
216 
217 /* Common error responses */
218 #define http400(Sock) httpSendErrorResponse((Sock), HTTP_BAD_REQUEST)
219 #define http404(Sock) httpSendErrorResponse((Sock), HTTP_NOT_FOUND)
220 #define http405(Sock) httpSendErrorResponse((Sock), HTTP_NOT_ALLOWED)
221 #define http501(Sock) httpSendErrorResponse((Sock), HTTP_NOT_IMPLEMENTED)
222 
224 #ifdef __cplusplus
225 }
226 #endif /* extern "C" */
227 
228 #endif
char * CONTENT_TYPE_APPLET
struct _ntparam_http NTPARAM_HTTP
HTTP_STATUS_CODE
Definition: httpif.h:153
void httpSendStatusLine(SOCKET Sock, int StatusCode, char *ContentType)
char * CONTENT_TYPE_WAV
void httpSendFullResponse(SOCKET Sock, int StatusCode, char *RequestedFile)
int httpVersion(void)
Definition: httpif.h:161
Definition: httpif.h:61
Definition: httpif.h:160
char * HTTP_VER
char * CONTENT_TYPE_MPEG
char * DEFAULT_NAME
char * CONTENT_TYPE_PDF
char * CONTENT_TYPE_GIF
char * CONTENT_LENGTH
void * httpOpen(NTARGS *pNTA, NTPARAM_HTTP *pNTP)
Create an instance of the HTTP Server.
Definition: httpif.h:158
int(* httpErrorResponseHook)(SOCKET Sock, int StatusCode)
void * SOCKET
Definition: socketndk.h:84
Definition: httpif.h:156
void httpSendClientStr(SOCKET Sock, char *Response)
char * CONTENT_TYPE_HTML
Definition: httpif.h:159
void httpSendEntityLength(SOCKET Sock, int32_t EntityLength)
Definition: httpif.h:162
char * CONTENT_TYPE_CSS
void httpSendErrorResponse(SOCKET Sock, int StatusCode)
Definition: httpif.h:155
char * CONTENT_TYPE_DOC
int MaxCon
Definition: httpif.h:62
void httpClose(void *hHTTP)
Destroy an instance of the HTTP Server.
char * CONTENT_TYPE_ZIP
char * CONTENT_TYPE_JPG
char * CONTENT_TYPE_AU
char * CONTENT_TYPE
char * SPACE
int Port
Definition: httpif.h:63
char * CRLF
Definition: httpif.h:157
© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale