ELinks 0.18.0
form.c File Reference

Forms viewing/manipulation handling. More...

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "elinks.h"
#include "bfu/listmenu.h"
#include "bfu/dialog.h"
#include "config/kbdbind.h"
#include "dialogs/menu.h"
#include "document/document.h"
#include "document/forms.h"
#include "document/view.h"
#include "intl/libintl.h"
#include "formhist/formhist.h"
#include "mime/mime.h"
#include "osdep/ascii.h"
#include "osdep/osdep.h"
#include "protocol/uri.h"
#include "session/session.h"
#include "session/task.h"
#include "terminal/kbd.h"
#include "terminal/terminal.h"
#include "terminal/window.h"
#include "util/conv.h"
#include "util/error.h"
#include "util/file.h"
#include "util/memory.h"
#include "util/random.h"
#include "util/string.h"
#include "viewer/action.h"
#include "viewer/text/draw.h"
#include "viewer/text/form.h"
#include "viewer/text/link.h"
#include "viewer/text/textarea.h"
#include "viewer/text/view.h"
#include "viewer/text/vs.h"
Include dependency graph for form.c:

Data Structures

struct  files_offset
 
struct  boundary_info
 

Macros

#define _GNU_SOURCE   /* XXX: we want memrchr() ! */
 
#define BOUNDARY_LENGTH   32
 
#define realloc_bound_ptrs(bptrs, bptrs_size)    mem_align_alloc(bptrs, bptrs_size, bptrs_size + 1, 0xFF)
 

Functions

static void fixup_select_state (struct el_form_control *fc, struct form_state *fs)
 
void selected_item (struct terminal *term, void *item_, void *ses_)
 
static void init_form_state (struct document_view *doc_view, struct el_form_control *fc, struct form_state *fs)
 
struct form_statefind_form_state (struct document_view *doc_view, struct el_form_control *fc)
 
struct el_form_controlfind_form_control (struct document *document, struct form_state *fs)
 
struct form_viewfind_form_view_in_vs (struct view_state *vs, int form_num)
 
struct form_viewfind_form_view (struct document_view *doc_view, struct form *form)
 
struct formfind_form_by_form_view (struct document *document, struct form_view *fv)
 
int get_current_state (struct session *ses)
 
void draw_form_entry (struct terminal *term, struct document_view *doc_view, struct link *link)
 
void draw_forms (struct terminal *term, struct document_view *doc_view)
 
static void add_submitted_value_to_list (struct el_form_control *fc, struct form_state *fs, struct submitted_value list *list)
 
static void sort_submitted_values (struct submitted_value list *list)
 
static void get_successful_controls (struct document_view *doc_view, struct el_form_control *fc, struct submitted_value list *list)
 
char * encode_crlf (struct submitted_value *sv)
 
static void encode_controls (struct submitted_value list *l, struct string *data, int cp_from, int cp_to)
 
static void encode_multipart (struct session *ses, struct submitted_value list *l, struct string *data, struct boundary_info *boundary, struct files_offset list *bfs, int cp_from, int cp_to)
 Format a multipart/form-data body for a POST request.
 
static void encode_newlines (struct string *string, char *data)
 
static void encode_text_plain (struct submitted_value list *l, struct string *data, int cp_from, int cp_to)
 
void do_reset_form (struct document_view *doc_view, struct form *form)
 
enum frame_event_status reset_form (struct session *ses, struct document_view *doc_view, int a)
 
struct uriget_form_uri (struct session *ses, struct document_view *doc_view, struct el_form_control *fc)
 
enum frame_event_status submit_form (struct session *ses, struct document_view *doc_view, int do_reload)
 
void submit_given_form (struct session *ses, struct document_view *doc_view, struct form *form, int do_reload)
 
void auto_submit_form (struct session *ses)
 
static void set_file_form_state (struct terminal *term, void *filename_, void *fs_)
 
static void file_form_menu (struct terminal *term, void *path_, void *fs_)
 
enum frame_event_status field_op (struct session *ses, struct document_view *doc_view, struct link *link, struct term_event *ev)
 
static char * get_form_label (struct el_form_control *fc)
 
static void add_form_attr_to_string (struct string *string, struct terminal *term, char *name, char *value)
 
char * get_form_info (struct session *ses, struct document_view *doc_view)
 
static void link_form_menu_func (struct terminal *term, void *link_number_, void *ses_)
 
void link_form_menu (struct session *ses)
 

Detailed Description

Forms viewing/manipulation handling.

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE   /* XXX: we want memrchr() ! */

◆ BOUNDARY_LENGTH

#define BOUNDARY_LENGTH   32

◆ realloc_bound_ptrs

#define realloc_bound_ptrs ( bptrs,
bptrs_size )    mem_align_alloc(bptrs, bptrs_size, bptrs_size + 1, 0xFF)

Function Documentation

◆ add_form_attr_to_string()

static void add_form_attr_to_string ( struct string * string,
struct terminal * term,
char * name,
char * value )
inlinestatic

◆ add_submitted_value_to_list()

static void add_submitted_value_to_list ( struct el_form_control * fc,
struct form_state * fs,
struct submitted_value list * list )
static

◆ auto_submit_form()

void auto_submit_form ( struct session * ses)

◆ do_reset_form()

void do_reset_form ( struct document_view * doc_view,
struct form * form )

◆ draw_form_entry()

void draw_form_entry ( struct terminal * term,
struct document_view * doc_view,
struct link * link )

◆ draw_forms()

void draw_forms ( struct terminal * term,
struct document_view * doc_view )

◆ encode_controls()

static void encode_controls ( struct submitted_value list * l,
struct string * data,
int cp_from,
int cp_to )
static

◆ encode_crlf()

char * encode_crlf ( struct submitted_value * sv)

◆ encode_multipart()

static void encode_multipart ( struct session * ses,
struct submitted_value list * l,
struct string * data,
struct boundary_info * boundary,
struct files_offset list * bfs,
int cp_from,
int cp_to )
static

Format a multipart/form-data body for a POST request.

Parameters
sesDisplay an info_box() in the terminal of this session if an error occurs.
[in]lList of values to be sent to the server.
[out]dataAppend the body here. This is in the same format as uri.post, except this never has a Content-Type at the beginning, the literal parts are not encoded in hexadecimal, and the file names are not percent-encoded. Therefore the result would be ambiguous without bfs.
[out]boundaryA random boundary string, and a list of offsets where the boundary was used, so that the caller can in principle change the string and update all of its uses if the original one conflicts with some of the submitted values. However, the caller does not do that nowadays because reading through the attached files would be too expensive. It just assumes the boundary is random enough.
[out]bfsList of offsets of names of files to be uploaded. This is how the caller knows which occurrences of FILE_CHAR in data should be encoded and which ones should not.
[in]cp_fromCodepage of the submitted-value strings in l.
[in]cp_toCodepage wanted by the server.
Todo
FIXME: shouldn't we encode data at send time (in http.c) ? –Zas
Bug
FIXME: name is not encoded. From RFC 1867: multipart/form-data contains a series of parts. Each part is expected to contain a content-disposition header where the value is "form-data" and a name attribute specifies the field name within the form, e.g., 'content-disposition: form-data; name="xxxxx"', where xxxxx is the field name corresponding to that field. Field names originally in non-ASCII character sets may be encoded using the method outlined in RFC 1522.

◆ encode_newlines()

static void encode_newlines ( struct string * string,
char * data )
static

◆ encode_text_plain()

static void encode_text_plain ( struct submitted_value list * l,
struct string * data,
int cp_from,
int cp_to )
static

◆ field_op()

enum frame_event_status field_op ( struct session * ses,
struct document_view * doc_view,
struct link * link,
struct term_event * ev )

◆ file_form_menu()

static void file_form_menu ( struct terminal * term,
void * path_,
void * fs_ )
static

◆ find_form_by_form_view()

struct form * find_form_by_form_view ( struct document * document,
struct form_view * fv )

◆ find_form_control()

struct el_form_control * find_form_control ( struct document * document,
struct form_state * fs )

◆ find_form_state()

struct form_state * find_form_state ( struct document_view * doc_view,
struct el_form_control * fc )

◆ find_form_view()

struct form_view * find_form_view ( struct document_view * doc_view,
struct form * form )

◆ find_form_view_in_vs()

struct form_view * find_form_view_in_vs ( struct view_state * vs,
int form_num )

◆ fixup_select_state()

static void fixup_select_state ( struct el_form_control * fc,
struct form_state * fs )
static

◆ get_current_state()

int get_current_state ( struct session * ses)

◆ get_form_info()

char * get_form_info ( struct session * ses,
struct document_view * doc_view )

◆ get_form_label()

static char * get_form_label ( struct el_form_control * fc)
static

◆ get_form_uri()

struct uri * get_form_uri ( struct session * ses,
struct document_view * doc_view,
struct el_form_control * fc )

◆ get_successful_controls()

static void get_successful_controls ( struct document_view * doc_view,
struct el_form_control * fc,
struct submitted_value list * list )
static

◆ init_form_state()

static void init_form_state ( struct document_view * doc_view,
struct el_form_control * fc,
struct form_state * fs )
static

◆ link_form_menu()

void link_form_menu ( struct session * ses)

◆ link_form_menu_func()

static void link_form_menu_func ( struct terminal * term,
void * link_number_,
void * ses_ )
static

◆ reset_form()

enum frame_event_status reset_form ( struct session * ses,
struct document_view * doc_view,
int a )

◆ selected_item()

void selected_item ( struct terminal * term,
void * item_,
void * ses_ )

◆ set_file_form_state()

static void set_file_form_state ( struct terminal * term,
void * filename_,
void * fs_ )
static

◆ sort_submitted_values()

static void sort_submitted_values ( struct submitted_value list * list)
static

◆ submit_form()

enum frame_event_status submit_form ( struct session * ses,
struct document_view * doc_view,
int do_reload )

◆ submit_given_form()

void submit_given_form ( struct session * ses,
struct document_view * doc_view,
struct form * form,
int do_reload )