diff options
Diffstat (limited to 'render')
-rw-r--r-- | render/box.c | 17 | ||||
-rw-r--r-- | render/box.h | 29 | ||||
-rw-r--r-- | render/form.c | 230 | ||||
-rw-r--r-- | render/form.h | 5 |
4 files changed, 156 insertions, 125 deletions
diff --git a/render/box.c b/render/box.c index d014d3be5..12b696d78 100644 --- a/render/box.c +++ b/render/box.c @@ -1179,8 +1179,8 @@ void add_option(xmlNode* n, struct form_control* current_select, const char *tex struct box_result box_input(xmlNode *n, struct box_status *status, struct css_style *style) { - struct box* box = 0; - struct form_control *gadget = 0; + struct box* box = NULL; + struct form_control *gadget = NULL; char *s, *type, *url; type = (char *) xmlGetProp(n, (const xmlChar *) "type"); @@ -1219,21 +1219,20 @@ struct box_result box_input(xmlNode *n, struct box_status *status, xmlFree(type); return (struct box_result) {0, false, true}; } + gadget->length = strlen(gadget->value); } } else if (type && (strcasecmp(type, "checkbox") == 0 || strcasecmp(type, "radio") == 0)) { box = box_create(style, NULL, 0, status->content->data.html.box_pool); - box->gadget = gadget = form_new_control(GADGET_RADIO); + box->gadget = gadget = form_new_control((type[0] == 'c' || type[0] == 'C') ? GADGET_CHECKBOX : GADGET_RADIO); if (!gadget) { box_free_box(box); xmlFree(type); return (struct box_result) {0, false, true}; } gadget->box = box; - if (type[0] == 'c' || type[0] == 'C') - gadget->type = GADGET_CHECKBOX; if ((s = (char *) xmlGetProp(n, (const xmlChar *) "checked"))) { gadget->selected = true; @@ -1248,6 +1247,7 @@ struct box_result box_input(xmlNode *n, struct box_status *status, xmlFree(type); return (struct box_result) {0, false, true}; } + gadget->length = strlen(gadget->value); } } else if (type && (strcasecmp(type, "submit") == 0 || @@ -1365,7 +1365,7 @@ struct box *box_input_text(xmlNode *n, struct box_status *status, struct box *inline_container, *inline_box; box->type = BOX_INLINE_BLOCK; - box->gadget = form_new_control(GADGET_TEXTBOX); + box->gadget = form_new_control((password) ? GADGET_PASSWORD : GADGET_TEXTBOX); box->gadget->box = box; box->gadget->maxlength = 100; @@ -1376,13 +1376,14 @@ struct box *box_input_text(xmlNode *n, struct box_status *status, s = (char *) xmlGetProp(n, (const xmlChar *) "value"); box->gadget->value = strdup((s != NULL) ? s : ""); - box->gadget->initial_value = strdup(box->gadget->value); + box->gadget->initial_value = strdup((box->gadget->value != NULL) ? box->gadget->value : ""); if (s) xmlFree(s); if (box->gadget->value == NULL || box->gadget->initial_value == NULL) { box_free(box); return NULL; } + box->gadget->length = strlen(box->gadget->value); inline_container = box_create(0, 0, 0, status->content->data.html.box_pool); @@ -1392,13 +1393,11 @@ struct box *box_input_text(xmlNode *n, struct box_status *status, inline_box->type = BOX_INLINE; inline_box->style_clone = 1; if (password) { - box->gadget->type = GADGET_PASSWORD; inline_box->length = strlen(box->gadget->value); inline_box->text = malloc(inline_box->length + 1); memset(inline_box->text, '*', inline_box->length); inline_box->text[inline_box->length] = '\0'; } else { - box->gadget->type = GADGET_TEXTBOX; /* replace spaces/TABs with hard spaces to prevent line wrapping */ inline_box->text = cnv_space2nbsp(box->gadget->value); inline_box->length = strlen(inline_box->text); diff --git a/render/box.h b/render/box.h index 58328884b..72303964b 100644 --- a/render/box.h +++ b/render/box.h @@ -98,12 +98,12 @@ typedef enum { /* parameters for <object> and related elements */ struct object_params { - char* data; - char* type; - char* codetype; - char* codebase; - char* classid; - struct plugin_params* params; + char* data; + char* type; + char* codetype; + char* codebase; + char* classid; + struct plugin_params* params; /* not a parameter, but stored here for convenience */ char* basehref; char* filename; @@ -115,12 +115,11 @@ struct object_params { }; struct plugin_params { - - char* name; - char* value; - char* type; - char* valuetype; - struct plugin_params* next; + char* name; + char* value; + char* type; + char* valuetype; + struct plugin_params* next; }; /** Node in box tree. All dimensions are in pixels. */ @@ -207,10 +206,10 @@ struct box { /** Form control data, or 0 if not a form control. */ struct form_control* gadget; - char *usemap; /** (Image)map to use with this object, or 0 if none */ + char *usemap; /** (Image)map to use with this object, or 0 if none */ - /** Background image for this box, or 0 if none */ - struct content *background; + /** Background image for this box, or 0 if none */ + struct content *background; /** Object in this box (usually an image), or 0 if none. */ struct content* object; diff --git a/render/form.c b/render/form.c index 6b1b247df..3713071e9 100644 --- a/render/form.c +++ b/render/form.c @@ -33,19 +33,22 @@ struct form_control *form_new_control(form_control_type type) { struct form_control *control; - control = malloc(sizeof *control); - if (!control) - return 0; + if ((control = malloc(sizeof *control)) == NULL) + return NULL; control->type = type; - control->name = 0; - control->value = 0; - control->initial_value = 0; + control->name = NULL; + control->value = NULL; + control->initial_value = NULL; control->disabled = false; - control->form = 0; - control->box = 0; + control->form = NULL; + control->box = NULL; + control->caret_inline_container = NULL; + control->caret_text_box = NULL; + control->caret_box_offset = control->caret_form_offset = 0; + control->length = control->maxlength = 0; control->selected = false; - control->prev = 0; - control->next = 0; + control->prev = NULL; + control->next = NULL; return control; } @@ -57,11 +60,11 @@ struct form_control *form_new_control(form_control_type type) void form_add_control(struct form *form, struct form_control *control) { control->form = form; - if (form->controls) { + if (form->controls != NULL) { assert(form->last_control); form->last_control->next = control; control->prev = form->last_control; - control->next = 0; + control->next = NULL; form->last_control = control; } else { form->controls = form->last_control = control; @@ -106,11 +109,13 @@ struct form_successful_control *form_successful_controls(struct form *form, struct form_control *control; struct form_option *option; struct form_successful_control sentinel, *last_success; + last_success = &sentinel; sentinel.next = 0; for (control = form->controls; control; control = control->next) { struct form_successful_control *success_new; + bool add_val; /* ignore disabled controls */ if (control->disabled) @@ -120,93 +125,120 @@ struct form_successful_control *form_successful_controls(struct form *form, if (!control->name) continue; - /* only the activated submit button is successful */ - if (control->type == GADGET_SUBMIT && control != submit_button) - continue; - - /* ignore checkboxes and radio buttons which aren't selected */ - if (control->type == GADGET_CHECKBOX && !control->selected) - continue; - if (control->type == GADGET_RADIO && !control->selected) - continue; - - /* select */ - if (control->type == GADGET_SELECT) { - for (option = control->data.select.items; option; - option = option->next) { - if (option->selected) { - success_new = xcalloc(1, sizeof(*success_new)); - success_new->file = false; - success_new->name = xstrdup(control->name); - success_new->value = xstrdup(option->value); - success_new->next = 0; - last_success->next = success_new; - last_success = success_new; + switch (control->type) { + case GADGET_HIDDEN: + case GADGET_TEXTBOX: + case GADGET_PASSWORD: + add_val = true; + break; + + case GADGET_RADIO: + case GADGET_CHECKBOX: + /* ignore checkboxes and radio buttons which + * aren't selected + */ + add_val = control->selected; + break; + + case GADGET_SELECT: + /* select */ + for (option = control->data.select.items; + option != NULL; + option = option->next) { + if (option->selected) { + success_new = xcalloc(1, sizeof(*success_new)); + success_new->file = false; + success_new->name = cnv_str_local_enc(control->name); + success_new->value = cnv_str_local_enc(option->value); + success_new->next = NULL; + last_success->next = success_new; + last_success = success_new; + } } - } - continue; - } - - /* textarea */ - if (control->type == GADGET_TEXTAREA) { - success_new = xcalloc(1, sizeof(*success_new)); - success_new->file = false; - success_new->name = xstrdup(control->name); - success_new->value = form_textarea_value(control); - success_new->next = 0; - last_success->next = success_new; - last_success = success_new; - continue; - } - - /* image */ - if (control->type == GADGET_IMAGE) { - unsigned int len = strlen(control->name) + 3; - /* x */ - success_new = xcalloc(1, sizeof(*success_new)); - success_new->file = false; - success_new->name = xcalloc(1, len); - sprintf(success_new->name, "%s.x", control->name); - success_new->value = xcalloc(1, 20); - sprintf(success_new->value, "%i", control->data.image.mx); - success_new->next = 0; - last_success->next = success_new; - last_success = success_new; - /* y */ - success_new = xcalloc(1, sizeof(*success_new)); - success_new->file = false; - success_new->name = xcalloc(1, len); - sprintf(success_new->name, "%s.y", control->name); - success_new->value = xcalloc(1, 20); - sprintf(success_new->value, "%i", control->data.image.my); - success_new->next = 0; - last_success->next = success_new; - last_success = success_new; - } - /* ignore reset */ - if (control->type == GADGET_RESET) - continue; + add_val = false; + break; + + case GADGET_TEXTAREA: + /* textarea */ + success_new = xcalloc(1, sizeof(*success_new)); + success_new->file = false; + success_new->name = cnv_str_local_enc(control->name); + success_new->value = form_textarea_value(control); + success_new->next = 0; + last_success->next = success_new; + last_success = success_new; + + add_val = false; + break; + + case GADGET_IMAGE: { + /* image */ + const size_t len = strlen(control->name) + 3; + + /* x */ + success_new = xcalloc(1, sizeof(*success_new)); + success_new->file = false; + success_new->name = xcalloc(1, len); + sprintf(success_new->name, "%s.x", control->name); + success_new->value = xcalloc(1, 20); + sprintf(success_new->value, "%i", control->data.image.mx); + success_new->next = 0; + last_success->next = success_new; + last_success = success_new; + + /* y */ + success_new = xcalloc(1, sizeof(*success_new)); + success_new->file = false; + success_new->name = xcalloc(1, len); + sprintf(success_new->name, "%s.y", control->name); + success_new->value = xcalloc(1, 20); + sprintf(success_new->value, "%i", control->data.image.my); + success_new->next = 0; + last_success->next = success_new; + last_success = success_new; + + add_val = false; + break; + } - /* file */ - if (control->type == GADGET_FILE && control->value) { - success_new = xcalloc(1, sizeof(*success_new)); - success_new->file = true; - success_new->name = xstrdup(control->name); - success_new->value = xstrdup(control->value); - success_new->next = 0; - last_success->next = success_new; - last_success = success_new; - continue; + case GADGET_SUBMIT: + /* only the activated submit button is + * successful + */ + add_val = (control != submit_button) ? false : true; + break; + + case GADGET_RESET: + /* ignore reset */ + add_val = false; + break; + + case GADGET_FILE: + /* file */ + success_new = xcalloc(1, sizeof(*success_new)); + success_new->file = true; + success_new->name = cnv_str_local_enc(control->name); + success_new->value = cnv_str_local_enc(control->value); + success_new->next = 0; + last_success->next = success_new; + last_success = success_new; + + add_val = false; + break; + + default: + assert(0); + break; } /* all others added if they have a value */ - if (control->value) { + if (add_val && control->value != NULL) { success_new = xcalloc(1, sizeof(*success_new)); success_new->file = false; - success_new->name = xstrdup(control->name); - success_new->value = xstrdup(control->value); - success_new->next = 0; + success_new->name = cnv_str_local_enc(control->name); + success_new->value = cnv_str_local_enc(control->value); + success_new->next = NULL; last_success->next = success_new; last_success = success_new; } @@ -228,10 +260,10 @@ char *form_textarea_value(struct form_control *textarea) /* find required length */ for (inline_container = textarea->box->children; - inline_container; + inline_container != NULL; inline_container = inline_container->next) { for (text_box = inline_container->children; - text_box; + text_box != NULL; text_box = text_box->next) { len += text_box->length + 1; } @@ -241,10 +273,10 @@ char *form_textarea_value(struct form_control *textarea) /* construct value */ s = value = xcalloc(1, len); for (inline_container = textarea->box->children; - inline_container; + inline_container != NULL; inline_container = inline_container->next) { for (text_box = inline_container->children; - text_box; + text_box != NULL; text_box = text_box->next) { strncpy(s, text_box->text, text_box->length); s += text_box->length; @@ -269,14 +301,14 @@ char *form_url_encode(struct form_successful_control *control) unsigned int len = 0, len1; for (; control; control = control->next) { - char *name = curl_escape(control->name, 0); - char *value = curl_escape(control->value, 0); + const char *name = curl_escape(control->name, 0); + const char *value = curl_escape(control->value, 0); len1 = len + strlen(name) + strlen(value) + 2; s = xrealloc(s, len1 + 1); sprintf(s + len, "%s=%s&", name, value); len = len1; - curl_free(name); - curl_free(value); + curl_free(name); + curl_free(value); } if (len) s[len - 1] = 0; diff --git a/render/form.h b/render/form.h index 013cb30ed..e6f77aaa7 100644 --- a/render/form.h +++ b/render/form.h @@ -58,13 +58,14 @@ struct form_control { struct box *box; struct box *caret_inline_container; struct box *caret_text_box; - int caret_char_offset; + unsigned int caret_box_offset, caret_form_offset; + unsigned int length; int caret_pixel_offset; unsigned int maxlength; bool selected; union { struct { - int mx, my; + int mx, my; } image; struct { int num_items; |