Added support for <input type='hidden'>.

Hidden form fields are aded to the page attribute buffer like text form fields so there's no need for special treatment in formsubmit(). However they are not added as widgets to the window so there's no user interaction.
This commit is contained in:
Oliver Schmidt 2013-03-13 10:50:11 +01:00
parent c7b8bac006
commit 66fa843389
6 changed files with 63 additions and 49 deletions

View File

@ -32,4 +32,5 @@ html_action "action\0"
html_name "name\0"
html_text "text\0"
html_size "size\0"
html_image "image\0"
html_image "image\0"
html_hidden "hidden\0"

View File

@ -103,3 +103,6 @@ const char html_size[6] =
const char html_image[7] =
/* "image\0" */
{0x69, 0x6d, 0x61, 0x67, 0x65, 00, };
const char html_hidden[8] =
/* "hidden\0" */
{0x68, 0x69, 0x64, 0x64, 0x65, 0x6e, 00, };

View File

@ -33,3 +33,4 @@ extern const char html_name[6];
extern const char html_text[6];
extern const char html_size[6];
extern const char html_image[7];
extern const char html_hidden[8];

View File

@ -149,20 +149,20 @@ struct htmlparser_state {
unsigned char tagptr;
char tagattr[20];
unsigned char tagattrptr;
char tagattrparam[WWW_CONF_MAX_URLLEN];
char tagattrparam[WWW_CONF_MAX_URLLEN + 1];
unsigned char tagattrparamptr;
unsigned char lastchar, quotechar;
unsigned char majorstate, lastmajorstate;
char linkurl[WWW_CONF_MAX_URLLEN];
char linkurl[WWW_CONF_MAX_URLLEN + 1];
char word[WWW_CONF_WEBPAGE_WIDTH];
unsigned char wordlen;
#if WWW_CONF_FORMS
char formaction[WWW_CONF_MAX_FORMACTIONLEN];
char formaction[WWW_CONF_MAX_FORMACTIONLEN + 1];
unsigned char inputtype;
char inputname[WWW_CONF_MAX_INPUTNAMELEN];
char inputvalue[WWW_CONF_MAX_INPUTVALUELEN];
char inputname[WWW_CONF_MAX_INPUTNAMELEN + 1];
char inputvalue[WWW_CONF_MAX_INPUTVALUELEN + 1];
unsigned char inputvaluesize;
#endif /* WWW_CONF_FORMS */
};
@ -241,7 +241,10 @@ static void
init_input(void)
{
s.inputtype = HTMLPARSER_INPUTTYPE_NONE;
s.inputname[0] = s.inputvalue[0] = 0;
s.inputname[0] = s.inputvalue[0] =
s.formaction[WWW_CONF_MAX_FORMACTIONLEN] =
s.inputname[WWW_CONF_MAX_INPUTNAMELEN] =
s.inputvalue[WWW_CONF_MAX_INPUTVALUELEN] = 0;
s.inputvaluesize = 20; /* De facto default size */
}
#endif /* WWW_CONF_FORMS */
@ -474,8 +477,8 @@ parse_tag(void)
switch(s.inputtype) {
case HTMLPARSER_INPUTTYPE_NONE:
case HTMLPARSER_INPUTTYPE_TEXT:
s.inputvalue[s.inputvaluesize] = 0;
htmlparser_inputfield(s.inputvaluesize, s.inputvalue, s.inputname);
case HTMLPARSER_INPUTTYPE_HIDDEN:
htmlparser_inputfield(s.inputtype, s.inputvaluesize, s.inputvalue, s.inputname);
break;
case HTMLPARSER_INPUTTYPE_SUBMIT:
case HTMLPARSER_INPUTTYPE_IMAGE:
@ -492,14 +495,16 @@ parse_tag(void)
s.inputtype = HTMLPARSER_INPUTTYPE_IMAGE;
} else if(strncmp(s.tagattrparam, html_text, sizeof(html_text)) == 0) {
s.inputtype = HTMLPARSER_INPUTTYPE_TEXT;
} else if(strncmp(s.tagattrparam, html_hidden, sizeof(html_hidden)) == 0) {
s.inputtype = HTMLPARSER_INPUTTYPE_HIDDEN;
} else {
s.inputtype = HTMLPARSER_INPUTTYPE_OTHER;
}
} else if(strncmp(s.tagattr, html_name, sizeof(html_name)) == 0) {
strncpy(s.inputname, s.tagattrparam, WWW_CONF_MAX_INPUTNAMELEN);
} else if(strncmp(s.tagattr, html_alt, sizeof(html_alt)) == 0 &&
s.inputtype == HTMLPARSER_INPUTTYPE_IMAGE) {
strncpy(s.inputvalue, s.tagattrparam, WWW_CONF_MAX_INPUTVALUELEN);
s.inputtype == HTMLPARSER_INPUTTYPE_IMAGE) {
strncpy(s.inputvalue, s.tagattrparam, WWW_CONF_MAX_INPUTVALUELEN);
} else if(strncmp(s.tagattr, html_value, sizeof(html_value)) == 0) {
strncpy(s.inputvalue, s.tagattrparam, WWW_CONF_MAX_INPUTVALUELEN);
} else if(strncmp(s.tagattr, html_size, sizeof(html_size)) == 0) {

View File

@ -41,19 +41,20 @@ void htmlparser_link(char *text, unsigned char textlen, char *url);
void htmlparser_form(char *action);
void htmlparser_submitbutton(char *value,
char *name);
void htmlparser_inputfield(unsigned char size,
void htmlparser_inputfield(unsigned char type,
unsigned char size,
char *value,
char *name);
void htmlparser_newline(void);
void htmlparser_word(char *word, unsigned char wordlen);
#define HTMLPARSER_INPUTTYPE_NONE 0
#define HTMLPARSER_INPUTTYPE_TEXT 1
#define HTMLPARSER_INPUTTYPE_PASSWORD 2
#define HTMLPARSER_INPUTTYPE_SUBMIT 3
#define HTMLPARSER_INPUTTYPE_IMAGE 4
#define HTMLPARSER_INPUTTYPE_OTHER 5
#define HTMLPARSER_INPUTTYPE_NONE 0
#define HTMLPARSER_INPUTTYPE_TEXT 1
#define HTMLPARSER_INPUTTYPE_HIDDEN 2
#define HTMLPARSER_INPUTTYPE_SUBMIT 3
#define HTMLPARSER_INPUTTYPE_IMAGE 4
#define HTMLPARSER_INPUTTYPE_OTHER 5
/* Functions. */

View File

@ -684,7 +684,7 @@ webclient_datahandler(char *data, uint16_t len)
}
/*-----------------------------------------------------------------------------------*/
static void CC_FASTCALL
add_pagewidget(char *text, unsigned char textlen, char *attrib, unsigned char type,
add_pagewidget(char *text, unsigned char size, char *attrib, unsigned char type,
unsigned char border)
{
char *wptr;
@ -694,16 +694,13 @@ add_pagewidget(char *text, unsigned char textlen, char *attrib, unsigned char ty
return;
}
if(textlen + border == 0) {
return;
}
maxwidth = WWW_CONF_WEBPAGE_WIDTH - (1 + 2 * border);
maxwidth = size ? WWW_CONF_WEBPAGE_WIDTH - (1 + 2 * border)
: WWW_CONF_WEBPAGE_WIDTH;
/* If the text of the link is too long so that it does not fit into
the width of the current window, counting from the current x
coordinate, we first try to jump to the next line. */
if(textlen + x > maxwidth) {
if(size + x > maxwidth) {
htmlparser_newline();
if(!loading) {
return;
@ -714,9 +711,9 @@ add_pagewidget(char *text, unsigned char textlen, char *attrib, unsigned char ty
XXX: this is not really the right thing to do, we should probably
either make a link into a multiline link, or add multiple
buttons. But this will do for now. */
if(textlen > maxwidth) {
if(size > maxwidth) {
text[maxwidth] = 0;
textlen = maxwidth;
size = maxwidth;
}
if(firsty == pagey) {
@ -727,17 +724,16 @@ add_pagewidget(char *text, unsigned char textlen, char *attrib, unsigned char ty
drawing area and reference it from there. */
wptr[0] = 0;
wptr += border;
memcpy(wptr, text, textlen);
wptr[textlen] = 0;
wptr[textlen + border] = ' ';
memcpy(wptr, text, size);
wptr[size] = 0;
wptr[size + border] = ' ';
switch(type) {
case CTK_WIDGET_HYPERLINK: {
struct linkattrib *linkptr;
linkptr = (struct linkattrib *)add_pageattrib(sizeof(struct linkattrib) /* incl 1 attrib char */ + attriblen);
struct linkattrib *linkptr =
(struct linkattrib *)add_pageattrib(sizeof(struct linkattrib) /* incl 1 attrib char */ + attriblen);
if(linkptr != NULL) {
CTK_HYPERLINK_NEW(&linkptr->hyperlink, x, y + 3, textlen, wptr, linkptr->url);
CTK_HYPERLINK_NEW(&linkptr->hyperlink, x, y + 3, size, wptr, linkptr->url);
strcpy(linkptr->url, attrib);
CTK_WIDGET_SET_FLAG(&linkptr->hyperlink, CTK_WIDGET_FLAG_MONOSPACE);
CTK_WIDGET_ADD(&mainwindow, &linkptr->hyperlink);
@ -746,11 +742,10 @@ add_pagewidget(char *text, unsigned char textlen, char *attrib, unsigned char ty
}
#if WWW_CONF_FORMS
case CTK_WIDGET_BUTTON: {
struct submitattrib *submitptr;
submitptr = (struct submitattrib *)add_pageattrib(sizeof(struct submitattrib) /* incl 1 attrib char */ + attriblen);
struct submitattrib *submitptr =
(struct submitattrib *)add_pageattrib(sizeof(struct submitattrib) /* incl 1 attrib char */ + attriblen);
if(submitptr != NULL) {
CTK_BUTTON_NEW((struct ctk_button *)&submitptr->button, x, y + 3, textlen, wptr);
CTK_BUTTON_NEW((struct ctk_button *)&submitptr->button, x, y + 3, size, wptr);
add_forminput((struct inputattrib *)submitptr);
submitptr->formptr = formptr;
strcpy(submitptr->name, attrib);
@ -760,18 +755,20 @@ add_pagewidget(char *text, unsigned char textlen, char *attrib, unsigned char ty
break;
}
case CTK_WIDGET_TEXTENTRY: {
struct textattrib *textptr;
textptr = (struct textattrib *)add_pageattrib(sizeof(struct textattrib) /* incl 1 attrib char */ + attriblen + WWW_CONF_MAX_INPUTVALUELEN);
struct textattrib *textptr =
(struct textattrib *)add_pageattrib(sizeof(struct textattrib) /* incl 1 attrib char */ + attriblen
+ (size ? WWW_CONF_MAX_INPUTVALUELEN : strlen(text)) + 1);
if(textptr != NULL) {
CTK_TEXTENTRY_NEW((struct ctk_textentry *)&textptr->textentry, x, y + 3, textlen, 1,
CTK_TEXTENTRY_NEW((struct ctk_textentry *)&textptr->textentry, x, y + 3, size, 1,
textptr->name + attriblen + 1, WWW_CONF_MAX_INPUTVALUELEN);
add_forminput((struct inputattrib *)textptr);
textptr->formptr = formptr;
strcpy(textptr->textentry.text, text);
strcpy(textptr->name, attrib);
CTK_WIDGET_SET_FLAG(&textptr->textentry, CTK_WIDGET_FLAG_MONOSPACE);
CTK_WIDGET_ADD(&mainwindow, &textptr->textentry);
if(size) {
CTK_WIDGET_SET_FLAG(&textptr->textentry, CTK_WIDGET_FLAG_MONOSPACE);
CTK_WIDGET_ADD(&mainwindow, &textptr->textentry);
}
}
break;
}
@ -780,11 +777,13 @@ add_pagewidget(char *text, unsigned char textlen, char *attrib, unsigned char ty
}
/* Increase the x coordinate with the length of the link text plus
the extra space behind it and the CTK button markers. */
textlen = textlen + 1 + 2 * border;
x += textlen;
if(size) {
size += 1 + 2 * border;
}
x += size;
if(firsty == pagey) {
webpageptr += textlen;
webpageptr += size;
}
if(x == WWW_CONF_WEBPAGE_WIDTH) {
@ -868,9 +867,13 @@ htmlparser_submitbutton(char *text, char *name)
}
/*-----------------------------------------------------------------------------------*/
void
htmlparser_inputfield(unsigned char size, char *text, char *name)
htmlparser_inputfield(unsigned char type, unsigned char size, char *text, char *name)
{
add_pagewidget(text, size, name, CTK_WIDGET_TEXTENTRY, 1);
if(type == HTMLPARSER_INPUTTYPE_HIDDEN) {
add_pagewidget(text, 0, name, CTK_WIDGET_TEXTENTRY, 0);
} else {
add_pagewidget(text, size, name, CTK_WIDGET_TEXTENTRY, 1);
}
}
/*-----------------------------------------------------------------------------------*/
static void CC_FASTCALL