📄 jsint.c
字号:
int l1,l2; if (!data)internal("js_upcall_get_location called with NULL pointer!"); fd=(struct f_data_c *)data; loc=mem_alloc(MAX_STR_LEN*sizeof(unsigned char)); if (!(get_current_url(fd->ses,loc,MAX_STR_LEN))){mem_free(loc);return NULL;} if (parse_url(loc, NULL, NULL, NULL, NULL, NULL, &h, &l1, NULL, &l2, NULL, NULL, NULL)){mem_free(loc);return NULL;} p=memacpy(h,l1+l2); mem_free(loc); return p;}/* returns allocated string containing pathname of current URL in the script context * on error (or there's no protocol) NULL is returned */unsigned char *js_upcall_get_location_pathname(void *data){ struct f_data_c *fd; unsigned char *loc; unsigned char *d, *p; if (!data)internal("js_upcall_get_location called with NULL pointer!"); fd=(struct f_data_c *)data; loc=mem_alloc(MAX_STR_LEN*sizeof(unsigned char)); if (!(get_current_url(fd->ses,loc,MAX_STR_LEN))){mem_free(loc);return NULL;} if (parse_url(loc, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &d, NULL, NULL)){mem_free(loc);return NULL;} if (!d){mem_free(loc);return NULL;} p=memacpy(d,strcspn(d,"?")); mem_free(loc); return p;}/* returns allocated string containing everything after ? in current URL in the script context * on error (or there's no protocol) NULL is returned */unsigned char *js_upcall_get_location_search(void *data){ struct f_data_c *fd; unsigned char *loc; unsigned char *d, *p; if (!data)internal("js_upcall_get_location called with NULL pointer!"); fd=(struct f_data_c *)data; loc=mem_alloc(MAX_STR_LEN*sizeof(unsigned char)); if (!(get_current_url(fd->ses,loc,MAX_STR_LEN))){mem_free(loc);return NULL;} if (parse_url(loc, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &d, NULL, NULL)){mem_free(loc);return NULL;} if (!d){mem_free(loc);return NULL;} p=stracpy(strchr(d,'?')); mem_free(loc); return p;}/* returns allocated string containing everything between # and ? in current URL in the script context * on error (or there's no protocol) NULL is returned */unsigned char *js_upcall_get_location_hash(void *data){ struct f_data_c *fd; unsigned char *loc; unsigned char *d, *p; if (!data)internal("js_upcall_get_location called with NULL pointer!"); fd=(struct f_data_c *)data; loc=mem_alloc(MAX_STR_LEN*sizeof(unsigned char)); if (!(get_current_url(fd->ses,loc,MAX_STR_LEN))){mem_free(loc);return NULL;} if (parse_url(loc, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &d, NULL, NULL)){mem_free(loc);return NULL;} if (!d){mem_free(loc);return NULL;} d=strchr(d,'#'); if (!d){mem_free(loc);return NULL;} d++; p=memacpy(d,strcspn(d,"?")); mem_free(loc); return p;}/* returns allocated field of all form elements * size of the field will be stored in len * when an error occurs, returns NULL */long *js_upcall_get_form_elements(void *data, long document_id, long form_id, int *len){ struct f_data_c *js_ctx=(struct f_data_c *)data; struct f_data_c *fd; struct form_control *fc, *fc2; long *pole_Premysla_Zavorace; int b; if (!js_ctx)internal("js_upcall_get_form_elements called with NULL context pointer\n"); if ((form_id&JS_OBJ_MASK)!=JS_OBJ_T_FORM)return NULL; /* this isn't form */ fd=jsint_find_document(document_id); if (!fd||!fd->f_data||!jsint_can_access(js_ctx,fd))return NULL; fc=jsint_find_object(fd,form_id); if (!fc)return NULL; *len=0; foreach (fc2, fd->f_data->forms) if (fc2->form_num==fc->form_num)(*len)++; if (!(*len))return NULL; if ((unsigned)*len > MAXINT / sizeof(long)) overalloc(); pole_Premysla_Zavorace=mem_alloc((*len)*sizeof(long)); b=0; foreachback (fc2, fd->f_data->forms) if (fc2->form_num==fc->form_num) { switch (fc2->type) { case FC_TEXT: pole_Premysla_Zavorace[b]=JS_OBJ_T_TEXT; break; case FC_PASSWORD: pole_Premysla_Zavorace[b]=JS_OBJ_T_PASSWORD; break; case FC_TEXTAREA: pole_Premysla_Zavorace[b]=JS_OBJ_T_TEXTAREA; break; case FC_CHECKBOX: pole_Premysla_Zavorace[b]=JS_OBJ_T_CHECKBOX; break; case FC_RADIO: pole_Premysla_Zavorace[b]=JS_OBJ_T_RADIO; break; case FC_IMAGE: case FC_SELECT: pole_Premysla_Zavorace[b]=JS_OBJ_T_SELECT; break; case FC_SUBMIT: pole_Premysla_Zavorace[b]=JS_OBJ_T_SUBMIT ; break; case FC_RESET: pole_Premysla_Zavorace[b]=JS_OBJ_T_RESET ; break; case FC_HIDDEN: pole_Premysla_Zavorace[b]=JS_OBJ_T_HIDDEN ; break; case FC_BUTTON: pole_Premysla_Zavorace[b]=JS_OBJ_T_BUTTON ; break; default: /* internal("Invalid form element type.\n"); */ (*len)--; continue; } pole_Premysla_Zavorace[b]|=((fc2->g_ctrl_num)<<JS_OBJ_MASK_SIZE); b++; } return pole_Premysla_Zavorace;}/* returns allocated field with anchors * size of the field is stored in len * when there're no anchors, *len is 0 and NULL is returned * on error NULL is returned */long *js_upcall_get_anchors(void *hej_Hombre, long document_id, int *len){ struct f_data_c *js_ctx=(struct f_data_c*)hej_Hombre; struct f_data_c *fd; struct tag *t; int a; long *to_je_Ono; *len=0; if (!js_ctx)internal("js_upcall_get_anchors called with NULL context pointer\n"); fd=jsint_find_document(document_id); if (!fd||!jsint_can_access(js_ctx,fd))return NULL; if (!(fd->f_data))return NULL; foreach(t,fd->f_data->tags)(*len)++; if (!(*len))return NULL; if ((unsigned)*len > MAXINT / sizeof(long)) overalloc(); to_je_Ono=mem_alloc((*len)*sizeof(long)); a=0; foreach(t,fd->f_data->tags) { to_je_Ono[a]=JS_OBJ_T_ANCHOR+(a<<JS_OBJ_MASK_SIZE); a++; } return to_je_Ono; }/* returns whether radio or checkbox is checked * return value: 0=not checked * 1=checked * -1=error */int js_upcall_get_checkbox_radio_checked(void *smirak, long document_id, long radio_tv_id){ struct f_data_c *js_ctx=(struct f_data_c*)smirak; struct f_data_c *fd; struct hopla_mladej *hopla; int state; if (!js_ctx)internal("js_upcall_get_checkbox_radio_checked called with NULL context pointer\n"); fd=jsint_find_document(document_id); if (!fd||!jsint_can_access(js_ctx,fd))return -1; if ((radio_tv_id&JS_OBJ_MASK)!=JS_OBJ_T_RADIO&&(radio_tv_id&JS_OBJ_MASK)!=JS_OBJ_T_CHECKBOX)return -1; /* this isn't radio nor TV */ hopla=jsint_find_object(fd,radio_tv_id); if (!hopla)return -1; state=hopla->fs->state; mem_free(hopla); return state;}/* checks/unchecks radio or checkbox */void js_upcall_set_checkbox_radio_checked(void *smirak, long document_id, long radio_tv_id, int value){ struct f_data_c *js_ctx=(struct f_data_c*)smirak; struct f_data_c *fd; struct hopla_mladej *hopla; if (!js_ctx)internal("js_upcall_set_checkbox_radio_checked called with NULL context pointer\n"); if ((radio_tv_id&JS_OBJ_MASK)!=JS_OBJ_T_RADIO&&(radio_tv_id&JS_OBJ_MASK)!=JS_OBJ_T_CHECKBOX)return; /* this isn't radio nor TV */ fd=jsint_find_document(document_id); if (!fd||!jsint_can_access(js_ctx,fd))return; hopla=jsint_find_object(fd,radio_tv_id); if (!hopla)return; hopla->fs->state=!!value; mem_free(hopla); redraw_document(fd);}/* returns whether radio or checkbox is checked * return value: 0=default not checked * 1=default checked * -1=error */int js_upcall_get_checkbox_radio_default_checked(void *bidak_smirak, long document_id, long radio_tv_id){ struct f_data_c *js_ctx=(struct f_data_c*)bidak_smirak; struct f_data_c *fd; struct hopla_mladej *hopla; int default_checked; if (!js_ctx)internal("js_upcall_get_checkbox_radio_default_checked called with NULL context pointer\n"); if ((radio_tv_id&JS_OBJ_MASK)!=JS_OBJ_T_RADIO&&(radio_tv_id&JS_OBJ_MASK)!=JS_OBJ_T_CHECKBOX)return -1; /* this isn't radio nor TV */ fd=jsint_find_document(document_id); if (!fd||!jsint_can_access(js_ctx,fd))return -1; hopla=jsint_find_object(fd,radio_tv_id); if (!hopla)return -1; default_checked=hopla->fc->default_state; mem_free(hopla); return default_checked;}/* sets radio/checkbox default_checked in the form */void js_upcall_set_checkbox_radio_default_checked(void *bidak_smirak, long document_id, long radio_tv_id, int value){ struct f_data_c *js_ctx=(struct f_data_c*)bidak_smirak; struct f_data_c *fd; struct hopla_mladej *hopla; int something_changed; value=!!value; if (!js_ctx)internal("js_upcall_set_checkbox_radio_default_checked called with NULL context pointer\n"); if ((radio_tv_id&JS_OBJ_MASK)!=JS_OBJ_T_RADIO&&(radio_tv_id&JS_OBJ_MASK)!=JS_OBJ_T_CHECKBOX)return; /* this isn't radio nor TV */ fd=jsint_find_document(document_id); if (!fd||!fd->f_data||!jsint_can_access(js_ctx,fd))return; hopla=jsint_find_object(fd,radio_tv_id); if (!hopla)return; something_changed=(hopla->fc->default_state)^value; hopla->fc->default_state=value; fd->f_data->uncacheable|=something_changed; mem_free(hopla);}/* returns allocated string with name of the form element * don't forget to free the string after use * on error returns NULL */unsigned char *js_upcall_get_form_element_name(void *bidak, long document_id, long ksunt_id){ struct f_data_c *js_ctx=(struct f_data_c*)bidak; struct f_data_c *fd; struct hopla_mladej *hopla; unsigned char *hele_ho_bidaka; if (!js_ctx)internal("js_upcall_get_form_element_name called with NULL context pointer\n"); fd=jsint_find_document(document_id); if (!fd||!jsint_can_access(js_ctx,fd))return NULL; switch (ksunt_id&JS_OBJ_MASK) { case JS_OBJ_T_RADIO: case JS_OBJ_T_TEXT: case JS_OBJ_T_PASSWORD: case JS_OBJ_T_TEXTAREA: case JS_OBJ_T_CHECKBOX: case JS_OBJ_T_SELECT: case JS_OBJ_T_SUBMIT: case JS_OBJ_T_RESET: case JS_OBJ_T_HIDDEN: case JS_OBJ_T_BUTTON: break; default: return NULL; /* To neni Jim Beam! */ } hopla=jsint_find_object(fd,ksunt_id); if (!hopla)return NULL; hele_ho_bidaka=stracpy(hopla->fc->name); mem_free(hopla); return hele_ho_bidaka;}/* sets name of the form element * name is allocated string, this function deallocates it */void js_upcall_set_form_element_name(void *bidak, long document_id, long ksunt_id, unsigned char *name){ struct f_data_c *js_ctx=(struct f_data_c*)bidak; struct f_data_c *fd; struct hopla_mladej *hopla; if (!js_ctx)internal("js_upcall_set_form_element_name called with NULL context pointer\n"); fd=jsint_find_document(document_id); if (!fd||!fd->f_data||!jsint_can_access(js_ctx,fd)){if (name)mem_free(name);return;} switch (ksunt_id&JS_OBJ_MASK) { case JS_OBJ_T_RADIO: case JS_OBJ_T_TEXT: case JS_OBJ_T_PASSWORD: case JS_OBJ_T_TEXTAREA: case JS_OBJ_T_CHECKBOX: case JS_OBJ_T_SELECT: case JS_OBJ_T_SUBMIT: case JS_OBJ_T_RESET: case JS_OBJ_T_HIDDEN: case JS_OBJ_T_BUTTON: break; default: if(name) mem_free(name); return; /* To neni Jim Beam! */ } hopla=jsint_find_object(fd,ksunt_id); if (!hopla){if (name)mem_free(name);return;} if ((name||(hopla->fc->name))&&strcmp(name,hopla->fc->name)) { mem_free(hopla->fc->name); hopla->fc->name=stracpy(name); fd->f_data->uncacheable=1; } mem_free(hopla); if(name) mem_free(name);}/* returns allocated string with value of VALUE attribute of the form element * on error returns NULL * don't forget to free the string after use */unsigned char *js_upcall_get_form_element_default_value(void *bidak, long document_id, long ksunt_id){ struct f_data_c *js_ctx=(struct f_data_c*)bidak; struct f_data_c *fd; struct hopla_mladej *hopla; unsigned char *hele_ho_bidaka; struct conv_table *ct; if (!js_ctx)internal("js_upcall_get_form_element_default_value called with NULL context pointer\n"); fd=jsint_find_document(document_id); if (!fd||!fd->f_data||!jsint_can_access(js_ctx,fd))return NULL; switch (ksunt_id&JS_OBJ_MASK) { case JS_OBJ_T_RADIO: case JS_OBJ_T_TEXT: case JS_OBJ_T_PASSWORD: case JS_OBJ_T_TEXTAREA: case JS_OBJ_T_CHECKBOX: case JS_OBJ_T_SELECT: case JS_OBJ_T_SUBMIT: case JS_OBJ_T_RESET: case JS_OBJ_T_HIDDEN: break; default: return NULL; /* To neni Jim Beam! */ } hopla=jsint_find_object(fd,ksunt_id); if (!hopla)return NULL; ct=get_translation_table(fd->f_data->opt.cp,fd->f_data->cp); hele_ho_bidaka=convert_string(ct,hopla->fc->default_value,strlen(hopla->fc->default_value),NULL); mem_free(hopla); return hele_ho_bidaka;}/* sets attribute VALUE of the form element * name is allocated string that, this function frees it * when name is NULL default value will be empty */void js_upcall_set_form_element_default_value(void *bidak, long document_id, long ksunt_id, unsigned char *name){ struct f_data_c *js_ctx=(struct f_data_c*)bidak; struct f_data_c *fd; struct hopla_mladej *hopla; if (!js_ctx)internal("js_upcall_set_form_element_default_value called with NULL context pointer\n"); fd=jsint_find_document(document_id); if (!fd||!fd->f_data||!jsint_can_access(js_ctx,fd)){if (name)mem_free(name);return;} switch (ksunt_id&JS_OBJ_MASK) { case JS_OBJ_T_RADIO: case JS_OBJ_T_TEXT: case JS_OBJ_T_PASSWORD: case JS_OBJ_T_TEXTAREA: case JS_OBJ_T_CHECKBOX: case JS_OBJ_T_SELECT: case JS_OBJ_T_SUBMIT: case JS_OBJ_T_RESET: case JS_OBJ_T_HIDDEN: break; default: if (name)mem_free(name); return; /* To neni Jim Beam! */ } hopla=jsint_find_object(fd,ksunt_id); if (!hopla){if (name)mem_free(name);return;} if ((name||(hopla->fc->default_value))&&strcmp(name,hopla->fc->default_value)) { struct conv_table *ct; mem_free(hopla->fc->default_value); ct=get_translation_table(fd->f_data->cp,fd->f_data->opt.cp); hopla->fc->default_value=convert_string(ct,name,strlen(name),NULL); fd->f_data->uncacheable=1; } mem_free(hopla); if (name)mem_free(name);}static
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -