Microchip® Advanced Software Framework

raw_http_basic_example/network/httpserver/httpd.c File Reference

Httpd server.

Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.

#include <string.h>
#include "lwip/debug.h"
#include "lwip/stats.h"
#include "lwip/tcp.h"
#include "lwipopts.h"
#include "httpd.h"
#include "fs.h"

Data Structures

struct  http_state
 

Functions

static err_t http_accept (void *arg, struct tcp_pcb *pcb, err_t err)
 Accept incoming HTTP connection requests. More...
 
static void http_close_conn (struct tcp_pcb *pcb, struct http_state *hs)
 Close HTTP connection. More...
 
static void http_conn_err (void *arg, err_t err)
 Callback called on connection error. More...
 
static err_t http_poll (void *arg, struct tcp_pcb *pcb)
 Poll for HTTP data. More...
 
static err_t http_recv (void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
 Core HTTP server receive function. More...
 
static void http_send_data (struct tcp_pcb *pcb, struct http_state *hs)
 Send HTTP data. More...
 
static err_t http_sent (void *arg, struct tcp_pcb *pcb, u16_t len)
 Callback to handle data transfer. More...
 
void httpd_init (void)
 HTTP server init. More...
 

static err_t http_accept ( void *  arg,
struct tcp_pcb *  pcb,
err_t  err 
)
static

Accept incoming HTTP connection requests.

Parameters
argPointer to structure representing the HTTP state.
pcbPointer to a TCP connection structure.
errConnection status.
Returns
ERR_OK on success.

References ERR_MEM, ERR_OK, http_state::file, http_conn_err(), http_poll(), http_recv(), http_state::left, LWIP_UNUSED_ARG, mem_malloc(), NULL, and http_state::retries.

Referenced by httpd_init().

static void http_close_conn ( struct tcp_pcb *  pcb,
struct http_state hs 
)
static

Close HTTP connection.

Parameters
pcbPointer to a TCP connection structure.
hsPointer to structure representing the HTTP state.

References mem_free(), and NULL.

Referenced by http_recv(), and http_sent().

static void http_conn_err ( void *  arg,
err_t  err 
)
static

Callback called on connection error.

Parameters
argPointer to structure representing the HTTP state.
errError code.

References LWIP_UNUSED_ARG, and mem_free().

Referenced by http_accept().

static err_t http_poll ( void *  arg,
struct tcp_pcb *  pcb 
)
static

Poll for HTTP data.

Parameters
argPointer to structure representing the HTTP state.
pcbPointer to a TCP connection structure.
Returns
ERR_OK on success, ERR_ABRT otherwise.

References ERR_ABRT, ERR_OK, http_state::file, http_send_data(), NULL, and http_state::retries.

Referenced by http_accept().

static err_t http_recv ( void *  arg,
struct tcp_pcb *  pcb,
struct pbuf p,
err_t  err 
)
static

Core HTTP server receive function.

Handle the request and process it.

Parameters
argPointer to structure representing the HTTP state.
pcbPointer to a TCP connection structure.
pIncoming request.
errConnection status.
Returns
ERR_OK.

References fs_file::data, data, ERR_OK, http_state::file, fs_open(), http_close_conn(), http_send_data(), http_sent(), http_state::left, fs_file::len, NULL, pbuf::payload, pbuf_free(), and pbuf::tot_len.

Referenced by http_accept().

static void http_send_data ( struct tcp_pcb *  pcb,
struct http_state hs 
)
static

Send HTTP data.

Parameters
pcbPointer to a TCP connection structure.
hsPointer to structure representing the HTTP state.

References ERR_MEM, ERR_OK, http_state::file, and http_state::left.

Referenced by http_poll(), http_recv(), and http_sent().

static err_t http_sent ( void *  arg,
struct tcp_pcb *  pcb,
u16_t  len 
)
static

Callback to handle data transfer.

Parameters
argPointer to structure representing the HTTP state.
pcbPointer to a TCP connection structure.
lenUnused.
Returns
ERR_OK on success, ERR_ABRT otherwise.

References ERR_OK, http_close_conn(), http_send_data(), http_state::left, LWIP_UNUSED_ARG, and http_state::retries.

Referenced by http_recv().

void httpd_init ( void  )

HTTP server init.

References http_accept(), and IP_ADDR_ANY.

Referenced by main().