|
|
|
|
@ -217,8 +217,6 @@ struct http_ssi_state {
|
|
|
|
|
#if !LWIP_HTTPD_SSI_INCLUDE_TAG |
|
|
|
|
const char *tag_started;/* Pointer to the first opening '<' of the tag. */ |
|
|
|
|
#endif /* !LWIP_HTTPD_SSI_INCLUDE_TAG */ |
|
|
|
|
const char *lead_in; /* Lead in for the potential current tag type. */ |
|
|
|
|
const char *lead_out; /* Lead out for the current tag type. */ |
|
|
|
|
const char *tag_end; /* Pointer to char after the closing '>' of the tag. */ |
|
|
|
|
u32_t parse_left; /* Number of unparsed bytes in buf. */ |
|
|
|
|
u16_t tag_index; /* Counter used by tag parsing state machine */ |
|
|
|
|
@ -226,11 +224,18 @@ struct http_ssi_state {
|
|
|
|
|
#if LWIP_HTTPD_SSI_MULTIPART |
|
|
|
|
u16_t tag_part; /* Counter passed to and changed by tag insertion function to insert multiple times */ |
|
|
|
|
#endif /* LWIP_HTTPD_SSI_MULTIPART */ |
|
|
|
|
u8_t tag_type; /* index into http_ssi_tag_desc array */ |
|
|
|
|
u8_t tag_name_len; /* Length of the tag name in string tag_name */ |
|
|
|
|
char tag_name[LWIP_HTTPD_MAX_TAG_NAME_LEN + 1]; /* Last tag name extracted */ |
|
|
|
|
char tag_insert[LWIP_HTTPD_MAX_TAG_INSERT_LEN + 1]; /* Insert string for tag_name */ |
|
|
|
|
enum tag_check_state tag_state; /* State of the tag processor */ |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
struct http_ssi_tag_description { |
|
|
|
|
const char *lead_in; |
|
|
|
|
const char *lead_out;
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
#endif /* LWIP_HTTPD_SSI */ |
|
|
|
|
|
|
|
|
|
struct http_state { |
|
|
|
|
@ -318,10 +323,13 @@ static int httpd_num_tags;
|
|
|
|
|
static const char **httpd_tags; |
|
|
|
|
#endif /* !LWIP_HTTPD_SSI_RAW */ |
|
|
|
|
|
|
|
|
|
static const char httpd_tag_lead_in[] = "<!--#"; |
|
|
|
|
static const char httpd_tag_lead_out[] = "-->"; |
|
|
|
|
static const char httpd_tag_lead_in_js[] = "/*#"; |
|
|
|
|
static const char httpd_tag_lead_out_js[] = "*/"; |
|
|
|
|
/* Define the available tag lead-ins and corresponding lead-outs.
|
|
|
|
|
* ATTENTION: for the algorithm below using this array, it is essential |
|
|
|
|
* that the lead in differs in the first character! */ |
|
|
|
|
const struct http_ssi_tag_description http_ssi_tag_desc[] = { |
|
|
|
|
{"<!--#", "-->"}, |
|
|
|
|
{"/*#", "*/"} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
#endif /* LWIP_HTTPD_SSI */ |
|
|
|
|
|
|
|
|
|
@ -1213,6 +1221,7 @@ http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs)
|
|
|
|
|
err_t err = ERR_OK; |
|
|
|
|
u16_t len; |
|
|
|
|
u8_t data_to_send = 0; |
|
|
|
|
u8_t tag_type; |
|
|
|
|
|
|
|
|
|
struct http_ssi_state *ssi = hs->ssi; |
|
|
|
|
LWIP_ASSERT("ssi != NULL", ssi != NULL); |
|
|
|
|
@ -1253,27 +1262,18 @@ http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs)
|
|
|
|
|
case TAG_NONE: |
|
|
|
|
/* We are not currently processing an SSI tag so scan for the
|
|
|
|
|
* start of the lead-in marker. */ |
|
|
|
|
if (*ssi->parsed == httpd_tag_lead_in[0]) { |
|
|
|
|
/* We found what could be the lead-in for a new tag so change
|
|
|
|
|
* state appropriately. */ |
|
|
|
|
ssi->lead_in = httpd_tag_lead_in; |
|
|
|
|
ssi->lead_out = httpd_tag_lead_out; |
|
|
|
|
ssi->tag_state = TAG_LEADIN; |
|
|
|
|
ssi->tag_index = 1; |
|
|
|
|
#if !LWIP_HTTPD_SSI_INCLUDE_TAG |
|
|
|
|
ssi->tag_started = ssi->parsed; |
|
|
|
|
#endif /* !LWIP_HTTPD_SSI_INCLUDE_TAG */ |
|
|
|
|
} |
|
|
|
|
if (*ssi->parsed == httpd_tag_lead_in_js[0]) { |
|
|
|
|
/* We found what could be the lead-in for a new tag so change
|
|
|
|
|
* state appropriately. */ |
|
|
|
|
ssi->lead_in = httpd_tag_lead_in_js; |
|
|
|
|
ssi->lead_out = httpd_tag_lead_out_js; |
|
|
|
|
ssi->tag_state = TAG_LEADIN; |
|
|
|
|
ssi->tag_index = 1; |
|
|
|
|
#if !LWIP_HTTPD_SSI_INCLUDE_TAG |
|
|
|
|
ssi->tag_started = ssi->parsed; |
|
|
|
|
#endif /* !LWIP_HTTPD_SSI_INCLUDE_TAG */ |
|
|
|
|
for (tag_type = 0; tag_type < LWIP_ARRAYSIZE(http_ssi_tag_desc); tag_type++) { |
|
|
|
|
if (*ssi->parsed == http_ssi_tag_desc[tag_type].lead_in[0]) { |
|
|
|
|
/* We found what could be the lead-in for a new tag so change
|
|
|
|
|
* state appropriately. */ |
|
|
|
|
ssi->tag_type = tag_type; |
|
|
|
|
ssi->tag_state = TAG_LEADIN; |
|
|
|
|
ssi->tag_index = 1; |
|
|
|
|
#if !LWIP_HTTPD_SSI_INCLUDE_TAG |
|
|
|
|
ssi->tag_started = ssi->parsed; |
|
|
|
|
#endif /* !LWIP_HTTPD_SSI_INCLUDE_TAG */ |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Move on to the next character in the buffer */ |
|
|
|
|
@ -1286,12 +1286,12 @@ http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs)
|
|
|
|
|
* the tag name. */ |
|
|
|
|
|
|
|
|
|
/* Have we reached the end of the leadin? */ |
|
|
|
|
if (ssi->lead_in[ssi->tag_index] == 0) { |
|
|
|
|
if (http_ssi_tag_desc[ssi->tag_type].lead_in[ssi->tag_index] == 0) { |
|
|
|
|
ssi->tag_index = 0; |
|
|
|
|
ssi->tag_state = TAG_FOUND; |
|
|
|
|
} else { |
|
|
|
|
/* Have we found the next character we expect for the tag leadin? */ |
|
|
|
|
if (*ssi->parsed == ssi->lead_in[ssi->tag_index]) { |
|
|
|
|
if (*ssi->parsed == http_ssi_tag_desc[ssi->tag_type].lead_in[ssi->tag_index]) { |
|
|
|
|
/* Yes - move to the next one unless we have found the complete
|
|
|
|
|
* leadin, in which case we start looking for the tag itself */ |
|
|
|
|
ssi->tag_index++; |
|
|
|
|
@ -1324,7 +1324,7 @@ http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs)
|
|
|
|
|
|
|
|
|
|
/* Have we found the end of the tag name? This is signalled by
|
|
|
|
|
* us finding the first leadout character or whitespace */ |
|
|
|
|
if ((*ssi->parsed == ssi->lead_out[0]) || |
|
|
|
|
if ((*ssi->parsed == http_ssi_tag_desc[ssi->tag_type].lead_out[0]) || |
|
|
|
|
(*ssi->parsed == ' ') || (*ssi->parsed == '\t') || |
|
|
|
|
(*ssi->parsed == '\n') || (*ssi->parsed == '\r')) { |
|
|
|
|
|
|
|
|
|
@ -1338,7 +1338,7 @@ http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs)
|
|
|
|
|
LWIP_ASSERT("ssi->tag_index <= 0xff", ssi->tag_index <= 0xff); |
|
|
|
|
ssi->tag_name_len = (u8_t)ssi->tag_index; |
|
|
|
|
ssi->tag_name[ssi->tag_index] = '\0'; |
|
|
|
|
if (*ssi->parsed == ssi->lead_out[0]) { |
|
|
|
|
if (*ssi->parsed == http_ssi_tag_desc[ssi->tag_type].lead_out[0]) { |
|
|
|
|
ssi->tag_index = 1; |
|
|
|
|
} else { |
|
|
|
|
ssi->tag_index = 0; |
|
|
|
|
@ -1374,7 +1374,7 @@ http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Have we found the next character we expect for the tag leadout? */ |
|
|
|
|
if (*ssi->parsed == ssi->lead_out[ssi->tag_index]) { |
|
|
|
|
if (*ssi->parsed == http_ssi_tag_desc[ssi->tag_type].lead_out[ssi->tag_index]) { |
|
|
|
|
/* Yes - move to the next one unless we have found the complete
|
|
|
|
|
* leadout, in which case we need to call the client to process |
|
|
|
|
* the tag. */ |
|
|
|
|
@ -1384,7 +1384,7 @@ http_send_data_ssi(struct altcp_pcb *pcb, struct http_state *hs)
|
|
|
|
|
ssi->parsed++; |
|
|
|
|
ssi->tag_index++; |
|
|
|
|
|
|
|
|
|
if (ssi->lead_out[ssi->tag_index] == 0) { |
|
|
|
|
if (http_ssi_tag_desc[ssi->tag_type].lead_out[ssi->tag_index] == 0) { |
|
|
|
|
/* Call the client to ask for the insert string for the
|
|
|
|
|
* tag we just found. */ |
|
|
|
|
#if LWIP_HTTPD_SSI_MULTIPART |
|
|
|
|
|