Network Services API  2.50.00.07
httpserver.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2018 Texas Instruments Incorporated - https://www.ti.com
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 /*
34  * ======== ti/net/http/httpserver.h ========
35  */
63 #ifndef ti_net_http_HTTPServer__include
64 #define ti_net_http_HTTPServer__include
65 
68 
69 #include <stdint.h>
70 #include <stdbool.h>
71 #include <sys/socket.h>
72 
73 #include "urlhandler.h"
74 
75 #ifdef __cplusplus
76 extern "C" {
77 #endif
78 
82 #define HTTPServer_EACCEPTFAIL (-2)
83 
87 #define HTTPServer_ESOCKETFAIL (-3)
88 
92 #define HTTPServer_EBINDFAIL (-4)
93 
97 #define HTTPServer_ELISTENFAIL (-5)
98 
102 #define HTTPServer_EMEMFAIL (-6)
103 
107 #define HTTPServer_EMQFAIL (-7)
108 
112 #define HTTPServer_EMUTEXFAIL (-8)
113 
115 /* internal utility fxn, not for end users */
116 extern void _HTTPServer_sleepms(uint32_t time);
122 typedef struct HTTPServer_Params {
126  int timeout;
135 
144 
155 
159 typedef struct HTTPServer_Object * HTTPServer_Handle;
160 
170 extern void HTTPServer_init(void);
171 
177 extern void HTTPServer_Params_init(HTTPServer_Params *params);
178 
195 extern HTTPServer_Handle HTTPServer_create(const URLHandler_Setup * urlh,
196  int numURLh, HTTPServer_Params * params);
197 
209 extern void HTTPServer_delete(HTTPServer_Handle * srv);
210 
219 extern int HTTPServer_processClient(HTTPServer_Handle srv, int s);
243 extern void HTTPServer_sendSimpleResponse(int s, int status,
244  const char * type, size_t len, const void * buf);
245 
271 extern void HTTPServer_sendResponse(int s, int status,
272  const char * headers[], int numHeaders, size_t len, const void * buf);
273 
287 extern void HTTPServer_sendErrorResponse(int s, int status);
288 
310 extern void HTTPServer_sendResponseChunked(int s, int status,
311  const char * type);
312 
335 extern void HTTPServer_sendChunk(int s, const void * buf, size_t len);
336 
350 extern int HTTPServer_serveSelect(HTTPServer_Handle srv,
351  const struct sockaddr *addr, int len, int backlog);
352 
363 extern bool HTTPServer_stop(HTTPServer_Handle srv, uint32_t timeout);
364 
366 /* internal services not quite ready to expose just yet */
367 extern int (*HTTPServer_errorResponseHook)(int s, int status);
368 
369 extern void HTTPServer_requestSend(URLHandler_Session urls);
370 
371 extern void HTTPServer_stopSession(URLHandler_Session urls);
375 #ifdef __cplusplus
376 }
377 #endif
378 
379 #endif
struct HTTPServer_Params HTTPServer_Params
HTTPServer instance create parameters.
void HTTPServer_init(void)
Initialize the HTTPServer module.
HTTPServer_Handle HTTPServer_create(const URLHandler_Setup *urlh, int numURLh, HTTPServer_Params *params)
Create an HTTPServer instance.
int maxSessions
Maximum number of active sessions.
Definition: httpserver.h:153
void HTTPServer_sendSimpleResponse(int s, int status, const char *type, size_t len, const void *buf)
Send a simple, complete response to a client.
HTTPServer instance create parameters.
Definition: httpserver.h:122
void HTTPServer_sendErrorResponse(int s, int status)
Send an error response to a client.
struct URLHandler_State * URLHandler_Session
Definition: urlhandler.h:78
int timeout
Receive timeout, in seconds.
Definition: httpserver.h:126
int maxURILen
Maximum characters in a URI request.
Definition: httpserver.h:143
int HTTPServer_serveSelect(HTTPServer_Handle srv, const struct sockaddr *addr, int len, int backlog)
Begin the HTTP Server&#39;s main processing loop.
void HTTPServer_sendResponseChunked(int s, int status, const char *type)
Begin the process of sending a chunked response to a client.
void HTTPServer_Params_init(HTTPServer_Params *params)
Initialize the instance create params structure.
int maxLineLen
Maximum characters in a request header line.
Definition: httpserver.h:134
Structure containing URL Handler components.
Definition: urlhandler.h:182
void HTTPServer_sendChunk(int s, const void *buf, size_t len)
Continue and complete the process of sending a chunked response to a client.
void HTTPServer_delete(HTTPServer_Handle *srv)
Delete an HTTPServer instance.
void HTTPServer_sendResponse(int s, int status, const char *headers[], int numHeaders, size_t len, const void *buf)
Send a complete response to a client.
URL Handler interface.
struct HTTPServer_Object * HTTPServer_Handle
HTTPServer instance object handle.
Definition: httpserver.h:159
bool HTTPServer_stop(HTTPServer_Handle srv, uint32_t timeout)
Stop a currently running server.
© Copyright 1995-2018, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale