Network Services API  2.75.00.17
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 #include <ti/net/slnetsock.h>
73 
74 #include "urlhandler.h"
75 
76 #ifdef __cplusplus
77 extern "C" {
78 #endif
79 
83 #define HTTPServer_EACCEPTFAIL (-2)
84 
88 #define HTTPServer_ESOCKETFAIL (-3)
89 
93 #define HTTPServer_EBINDFAIL (-4)
94 
98 #define HTTPServer_ELISTENFAIL (-5)
99 
103 #define HTTPServer_EMEMFAIL (-6)
104 
108 #define HTTPServer_EMQFAIL (-7)
109 
113 #define HTTPServer_EMUTEXFAIL (-8)
114 
116 /* internal utility fxn, not for end users */
117 extern void _HTTPServer_sleepms(uint32_t time);
123 typedef struct HTTPServer_Params {
127  int timeout;
136 
145 
156 
160 typedef struct HTTPServer_Object * HTTPServer_Handle;
161 
171 extern void HTTPServer_init(void);
172 
178 extern void HTTPServer_Params_init(HTTPServer_Params *params);
179 
197 extern void HTTPServer_enableSecurity(HTTPServer_Handle srv,
198  SlNetSockSecAttrib_t * securityAttributes, bool beginSecurely);
199 
216 extern HTTPServer_Handle HTTPServer_create(const URLHandler_Setup * urlh,
217  int numURLh, HTTPServer_Params * params);
218 
230 extern void HTTPServer_delete(HTTPServer_Handle * srv);
231 
240 extern int HTTPServer_processClient(HTTPServer_Handle srv, int s);
264 extern void HTTPServer_sendSimpleResponse(int s, int status,
265  const char * type, size_t len, const void * buf);
266 
292 extern void HTTPServer_sendResponse(int s, int status,
293  const char * headers[], int numHeaders, size_t len, const void * buf);
294 
308 extern void HTTPServer_sendErrorResponse(int s, int status);
309 
331 extern void HTTPServer_sendResponseChunked(int s, int status,
332  const char * type);
333 
356 extern void HTTPServer_sendChunk(int s, const void * buf, size_t len);
357 
371 extern int HTTPServer_serveSelect(HTTPServer_Handle srv,
372  const struct sockaddr *addr, int len, int backlog);
373 
384 extern bool HTTPServer_stop(HTTPServer_Handle srv, uint32_t timeout);
385 
387 /* internal services not quite ready to expose just yet */
388 extern int (*HTTPServer_errorResponseHook)(int s, int status);
389 
390 extern void HTTPServer_requestSend(URLHandler_Session urls);
391 
392 extern void HTTPServer_stopSession(URLHandler_Session urls);
403 
405 #ifdef __cplusplus
406 }
407 #endif
408 
409 #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:154
void HTTPServer_sendSimpleResponse(int s, int status, const char *type, size_t len, const void *buf)
Send a simple, complete response to a client.
void HTTPServer_enableSecurity(HTTPServer_Handle srv, SlNetSockSecAttrib_t *securityAttributes, bool beginSecurely)
Attach security params to the created, but not yet initialized server.
HTTPServer instance create parameters.
Definition: httpserver.h:123
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:127
int maxURILen
Maximum characters in a URI request.
Definition: httpserver.h:144
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.
Secure socket attribute context.
Definition: slnetsock.h:569
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:135
Structure containing URL Handler components.
Definition: urlhandler.h:226
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.
bool HTTPServer_isSessionSecure(URLHandler_Session sess)
Obtain the session&#39;s security status.
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:160
bool HTTPServer_stop(HTTPServer_Handle srv, uint32_t timeout)
Stop a currently running server.
© Copyright 1995-2020, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale