116 lines
2.3 KiB
C
116 lines
2.3 KiB
C
/*
|
|
* Copyright 2020 NXP
|
|
* All rights reserved.
|
|
*
|
|
*
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
|
|
#include "webconfig.h"
|
|
#include "http_server.h"
|
|
#include "httpsrv.h"
|
|
|
|
#include <string.h>
|
|
|
|
/* FS data.*/
|
|
extern const HTTPSRV_FS_DIR_ENTRY httpsrv_fs_data[];
|
|
extern const HTTPSRV_CGI_LINK_STRUCT cgi_lnk_tbl[];
|
|
|
|
bool cgi_get_varval(char *src, char *var_name, char *dst, uint32_t length)
|
|
{
|
|
char *name;
|
|
bool result;
|
|
uint32_t index;
|
|
uint32_t n_length;
|
|
|
|
result = false;
|
|
dst[0] = 0;
|
|
name = src;
|
|
|
|
n_length = strlen(var_name);
|
|
|
|
while ((name != NULL) && ((name = strstr(name, var_name)) != NULL))
|
|
{
|
|
if (name[n_length] == '=')
|
|
{
|
|
name += n_length + 1;
|
|
|
|
index = strcspn(name, "&");
|
|
if (index >= length)
|
|
{
|
|
index = length - 1;
|
|
}
|
|
strncpy(dst, name, index);
|
|
dst[index] = '\0';
|
|
result = true;
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
name = strchr(name, '&');
|
|
}
|
|
}
|
|
|
|
return (result);
|
|
}
|
|
|
|
void format_post_data(char *string)
|
|
{
|
|
/* Replace '+' with spaces. */
|
|
char *c;
|
|
while ((c = strchr(string, '+')) != NULL)
|
|
{
|
|
*c = ' ';
|
|
}
|
|
}
|
|
|
|
/* Decode URL encoded string in place. */
|
|
void cgi_urldecode(char *url)
|
|
{
|
|
char *src = url;
|
|
char *dst = url;
|
|
|
|
while (*src != '\0')
|
|
{
|
|
if ((*src == '%') && (isxdigit((unsigned char)*(src + 1))) && (isxdigit((unsigned char)*(src + 2))))
|
|
{
|
|
*src = *(src + 1);
|
|
*(src + 1) = *(src + 2);
|
|
*(src + 2) = '\0';
|
|
*dst++ = strtol(src, NULL, 16);
|
|
src += 3;
|
|
}
|
|
else
|
|
{
|
|
*dst++ = *src++;
|
|
}
|
|
}
|
|
*dst = '\0';
|
|
}
|
|
|
|
void http_srv_task(void *arg)
|
|
{
|
|
LWIP_UNUSED_ARG(arg);
|
|
|
|
HTTPSRV_PARAM_STRUCT params;
|
|
uint32_t httpsrv_handle;
|
|
|
|
/* Init Fs*/
|
|
HTTPSRV_FS_init(httpsrv_fs_data);
|
|
|
|
/* Init HTTPSRV parameters.*/
|
|
memset(¶ms, 0, sizeof(params));
|
|
params.root_dir = "";
|
|
params.index_page = "/index.html";
|
|
params.cgi_lnk_tbl = cgi_lnk_tbl;
|
|
|
|
/* Init HTTP Server.*/
|
|
httpsrv_handle = HTTPSRV_init(¶ms);
|
|
if (httpsrv_handle == 0)
|
|
{
|
|
LWIP_PLATFORM_DIAG(("HTTPSRV_init() is Failed"));
|
|
}
|
|
|
|
vTaskDelete(NULL);
|
|
}
|