|
|
@ -124,17 +124,17 @@ size_t httpGetBacklogSize(const HttpdConnData *conn) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Looks up the connData info for a specific connection
|
|
|
|
//Looks up the connData info for a specific connection
|
|
|
|
static HttpdConnData *httpdFindConnData(ConnTypePtr conn, const uint8_t *remIp, int remPort) |
|
|
|
static HttpdConnData *httpdFindConnData(ConnTypePtr conn, httpd_ipaddr_t remIp, int remPort) |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (int i = 0; i < HTTPD_MAX_CONNECTIONS; i++) { |
|
|
|
for (int i = 0; i < HTTPD_MAX_CONNECTIONS; i++) { |
|
|
|
if (s_connData[i] && s_connData[i]->remote_port == remPort && |
|
|
|
if (s_connData[i] && s_connData[i]->remote_port == remPort |
|
|
|
memcmp(s_connData[i]->remote_ip, remIp, 4) == 0) { |
|
|
|
&& s_connData[i]->remote_ip == remIp) { |
|
|
|
s_connData[i]->conn = conn; |
|
|
|
s_connData[i]->conn = conn; |
|
|
|
return s_connData[i]; |
|
|
|
return s_connData[i]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//Shouldn't happen.
|
|
|
|
//Shouldn't happen.
|
|
|
|
http_error("*** Unknown connection %d.%d.%d.%d:%d", remIp[0] & 0xff, remIp[1] & 0xff, remIp[2] & 0xff, remIp[3] & 0xff, remPort); |
|
|
|
http_error("Unknown connection"); |
|
|
|
httpdConnDisconnect(conn); |
|
|
|
httpdConnDisconnect(conn); |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
} |
|
|
@ -501,7 +501,7 @@ static void httpdCgiIsDone(HttpdConnData *conn) |
|
|
|
|
|
|
|
|
|
|
|
//Callback called when the data on a socket has been successfully
|
|
|
|
//Callback called when the data on a socket has been successfully
|
|
|
|
//sent.
|
|
|
|
//sent.
|
|
|
|
void httpdSentCb(ConnTypePtr rconn, const uint8_t *remIp, uint16_t remPort) |
|
|
|
void httpdSentCb(ConnTypePtr rconn, httpd_ipaddr_t remIp, uint16_t remPort) |
|
|
|
{ |
|
|
|
{ |
|
|
|
HttpdConnData *conn = httpdFindConnData(rconn, remIp, remPort); |
|
|
|
HttpdConnData *conn = httpdFindConnData(rconn, remIp, remPort); |
|
|
|
httpdContinue(conn); |
|
|
|
httpdContinue(conn); |
|
|
@ -511,7 +511,6 @@ void httpdSentCb(ConnTypePtr rconn, const uint8_t *remIp, uint16_t remPort) |
|
|
|
//resume handling an open connection asynchronously
|
|
|
|
//resume handling an open connection asynchronously
|
|
|
|
void httpdContinue(HttpdConnData *conn) |
|
|
|
void httpdContinue(HttpdConnData *conn) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int r; |
|
|
|
|
|
|
|
httpdPlatLock(); |
|
|
|
httpdPlatLock(); |
|
|
|
|
|
|
|
|
|
|
|
uint8_t *sendBuff; |
|
|
|
uint8_t *sendBuff; |
|
|
@ -550,7 +549,7 @@ void httpdContinue(HttpdConnData *conn) |
|
|
|
} |
|
|
|
} |
|
|
|
conn->priv->sendBuff = sendBuff; |
|
|
|
conn->priv->sendBuff = sendBuff; |
|
|
|
conn->priv->sendBuffLen = 0; |
|
|
|
conn->priv->sendBuffLen = 0; |
|
|
|
r = conn->cgi(conn); //Execute cgi fn.
|
|
|
|
httpd_cgi_state r = conn->cgi(conn); //Execute cgi fn.
|
|
|
|
if (r == HTTPD_CGI_DONE) { |
|
|
|
if (r == HTTPD_CGI_DONE) { |
|
|
|
httpdCgiIsDone(conn); |
|
|
|
httpdCgiIsDone(conn); |
|
|
|
} |
|
|
|
} |
|
|
@ -776,7 +775,7 @@ void httpdConnSendFinish(HttpdConnData *conn) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Callback called when there's data available on a socket.
|
|
|
|
//Callback called when there's data available on a socket.
|
|
|
|
void httpdRecvCb(ConnTypePtr rconn, const uint8_t *remIp, uint16_t remPort, uint8_t *data, size_t len) |
|
|
|
void httpdRecvCb(ConnTypePtr rconn, httpd_ipaddr_t remIp, uint16_t remPort, uint8_t *data, size_t len) |
|
|
|
{ |
|
|
|
{ |
|
|
|
httpd_cgi_state r; |
|
|
|
httpd_cgi_state r; |
|
|
|
size_t x; |
|
|
|
size_t x; |
|
|
@ -884,7 +883,7 @@ void httpdRecvCb(ConnTypePtr rconn, const uint8_t *remIp, uint16_t remPort, uint |
|
|
|
|
|
|
|
|
|
|
|
//The platform layer should ALWAYS call this function, regardless if the connection is closed by the server
|
|
|
|
//The platform layer should ALWAYS call this function, regardless if the connection is closed by the server
|
|
|
|
//or by the client.
|
|
|
|
//or by the client.
|
|
|
|
void httpdDisconCb(ConnTypePtr rconn, const uint8_t *remIp, uint16_t remPort) |
|
|
|
void httpdDisconCb(ConnTypePtr rconn, httpd_ipaddr_t remIp, uint16_t remPort) |
|
|
|
{ |
|
|
|
{ |
|
|
|
httpdPlatLock(); |
|
|
|
httpdPlatLock(); |
|
|
|
HttpdConnData *hconn = httpdFindConnData(rconn, remIp, remPort); |
|
|
|
HttpdConnData *hconn = httpdFindConnData(rconn, remIp, remPort); |
|
|
@ -917,57 +916,54 @@ static void cleanupCgiAndUserData(HttpdConnData *hconn) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int httpdConnectCb(ConnTypePtr conn, const uint8_t *remIp, uint16_t remPort) |
|
|
|
int httpdConnectCb(ConnTypePtr conn, httpd_ipaddr_t remIp, uint16_t remPort) |
|
|
|
{ |
|
|
|
{ |
|
|
|
uint8_t i; |
|
|
|
uint8_t ci; // connection index
|
|
|
|
httpdPlatLock(); |
|
|
|
httpdPlatLock(); |
|
|
|
|
|
|
|
|
|
|
|
//Find empty conndata in pool
|
|
|
|
//Find empty conndata in pool
|
|
|
|
for (i = 0; i < HTTPD_MAX_CONNECTIONS; i++) { |
|
|
|
for (ci = 0; ci < HTTPD_MAX_CONNECTIONS; ci++) { |
|
|
|
if (s_connData[i] == NULL) { |
|
|
|
if (s_connData[ci] == NULL) { |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
http_info("Conn req from %d.%d.%d.%d:%d, using pool slot %d", remIp[0], remIp[1], remIp[2], remIp[3], remPort, i); |
|
|
|
|
|
|
|
if (i >= HTTPD_MAX_CONNECTIONS) { |
|
|
|
http_info("Conn req from %d.%d.%d.%d:%d, using pool slot %d", IP_SPLIT(remIp), remPort, ci); |
|
|
|
|
|
|
|
if (ci >= HTTPD_MAX_CONNECTIONS) { |
|
|
|
http_error("Aiee, conn pool overflow!"); |
|
|
|
http_error("Aiee, conn pool overflow!"); |
|
|
|
httpdPlatUnlock(); |
|
|
|
httpdPlatUnlock(); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
s_connData[i] = httpdPlatMalloc(sizeof(HttpdConnData)); |
|
|
|
s_connData[ci] = httpdPlatMalloc(sizeof(HttpdConnData)); |
|
|
|
if (s_connData[i] == NULL) { |
|
|
|
if (s_connData[ci] == NULL) { |
|
|
|
http_warn("Out of memory allocating connData!"); |
|
|
|
http_warn("Out of memory allocating connData!"); |
|
|
|
httpdPlatUnlock(); |
|
|
|
httpdPlatUnlock(); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
memset(s_connData[i], 0, sizeof(HttpdConnData)); |
|
|
|
memset(s_connData[ci], 0, sizeof(HttpdConnData)); |
|
|
|
s_connData[i]->priv = httpdPlatMalloc(sizeof(HttpdPriv)); |
|
|
|
|
|
|
|
if (s_connData[i]->priv == NULL) { |
|
|
|
s_connData[ci]->conn = conn; |
|
|
|
|
|
|
|
s_connData[ci]->slot = ci; |
|
|
|
|
|
|
|
s_connData[ci]->remote_ip = remIp; |
|
|
|
|
|
|
|
s_connData[ci]->remote_port = remPort; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
s_connData[ci]->priv = httpdPlatMalloc(sizeof(HttpdPriv)); |
|
|
|
|
|
|
|
if (s_connData[ci]->priv == NULL) { |
|
|
|
http_error("Out of memory allocating connData priv struct!"); |
|
|
|
http_error("Out of memory allocating connData priv struct!"); |
|
|
|
httpdPlatUnlock(); |
|
|
|
httpdPlatUnlock(); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
memset(s_connData[i]->priv, 0, sizeof(HttpdPriv)); |
|
|
|
memset(s_connData[ci]->priv, 0, sizeof(HttpdPriv)); |
|
|
|
s_connData[i]->conn = conn; |
|
|
|
|
|
|
|
s_connData[i]->slot = i; |
|
|
|
s_connData[ci]->post = httpdPlatMalloc(sizeof(HttpdPostData)); |
|
|
|
// s_connData[i]->priv->headPos = 0;
|
|
|
|
if (s_connData[ci]->post == NULL) { |
|
|
|
s_connData[i]->post = httpdPlatMalloc(sizeof(HttpdPostData)); |
|
|
|
|
|
|
|
if (s_connData[i]->post == NULL) { |
|
|
|
|
|
|
|
http_error("Out of memory allocating connData post struct!"); |
|
|
|
http_error("Out of memory allocating connData post struct!"); |
|
|
|
httpdPlatUnlock(); |
|
|
|
httpdPlatUnlock(); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
memset(s_connData[i]->post, 0, sizeof(HttpdPostData)); |
|
|
|
memset(s_connData[ci]->post, 0, sizeof(HttpdPostData)); |
|
|
|
// s_connData[i]->post->buff = NULL;
|
|
|
|
s_connData[ci]->post->len = -1; |
|
|
|
// s_connData[i]->post->buffLen = 0;
|
|
|
|
|
|
|
|
// s_connData[i]->post->received = 0;
|
|
|
|
|
|
|
|
s_connData[i]->post->len = -1; |
|
|
|
|
|
|
|
// s_connData[i]->hostName = NULL;
|
|
|
|
|
|
|
|
s_connData[i]->remote_port = remPort; |
|
|
|
|
|
|
|
// s_connData[i]->priv->sendBacklog = NULL;
|
|
|
|
|
|
|
|
// s_connData[i]->priv->headersToSend = NULL;
|
|
|
|
|
|
|
|
// s_connData[i]->priv->sendBacklogSize = 0;
|
|
|
|
|
|
|
|
memcpy(s_connData[i]->remote_ip, remIp, 4); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
httpdPlatUnlock(); |
|
|
|
httpdPlatUnlock(); |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|