📄 jsint.c
字号:
2, /* # of buttons */ TEXT(T_YES),js_upcall_close_window_yes_pressed,NULL, TEXT(T_KILL_SCRIPT), js_kill_script_pressed,NULL ); js_mem_free(s); } else { js_mem_free(s); if (term->next == term->prev && are_there_downloads()) query_exit(fd->ses); else really_exit_prog(fd->ses); }}/* returns parent window ID of the script */long js_upcall_get_window_id(void *data){ struct f_data_c *fd; if (!data)internal("js_upcall_get_window_id called with NULL pointer!"); fd=(struct f_data_c*)data; return ((fd->id)<<JS_OBJ_MASK_SIZE)|JS_OBJ_T_FRAME;}/* aux function for js_upcall_get_string */static void js_upcall_get_string_ok_pressed(void *data, unsigned char *str){ struct f_data_c *fd; struct gimme_js_id *jsid=(struct gimme_js_id*)data; fd=jsint_find_document(jsid->id); if (!fd)return; /* context no longer exists */ if (!(fd->js)||jsid->js_id!=fd->js->ctx->js_id)return; js_downcall_vezmi_string(fd->js->ctx, stracpy(str)); /* call downcall */}struct history js_get_string_history={0, {&js_get_string_history.items, &js_get_string_history.items}};/* creates input field for string, with text s->string1, default response * s->string2 and buttons OK/Kill Script * s->string1 and s->string2 will be dealocated * s will be dealocated too * must be called from select loop */void js_upcall_get_string(void *data){ struct fax_me_tender_2_stringy *s=(struct fax_me_tender_2_stringy*)data; struct gimme_js_id* jsid; struct f_data_c *fd; struct terminal *term; unsigned char *str1,*str2; if (!s)internal("js_upcall_get_string called with NULL pointer\n"); /* to jenom kdyby na mne PerM zkousel naky oplzlosti... */ /* context must be a valid pointer ! */ fd=(struct f_data_c*)(s->ident); term=fd->ses->term; if (!fd->js) return; jsid=mem_alloc(sizeof(struct gimme_js_id)); /* kill timer, that called me */ js_spec_vykill_timer(fd->js->ctx,0); /* fill in jsid */ jsid->id=((fd->id)<<JS_OBJ_MASK_SIZE)|JS_OBJ_T_DOCUMENT; jsid->js_id=fd->js->ctx->js_id; str1=stracpy(s->string1); str2=stracpy(s->string2); js_mem_free(s->string1); js_mem_free(s->string2); input_field( term, /* terminal */ getml(str1, str2,jsid,NULL), /* mem to free */ TEXT(T_ENTER_STRING), /* title */ str1, /* question */ jsid, /* data for functions */ &js_get_string_history, /* history */ MAX_INPUT_URL_LEN, /* string len */ str2, /* string to fill the dialog with */ 0, /* min value */ 0, /* max value */ NULL, /* check fn */ TEXT(T_OK), /* ok button */ js_upcall_get_string_ok_pressed, TEXT(T_KILL_SCRIPT), /* cancel button */ js_kill_script_pressed, NULL ); js_mem_free(s);}/* clears window with javascript *//* must be called from select loop *//* javascript must halt before calling this upcall */void js_upcall_clear_window(void *data){ /* context must be a valid pointer ! */ /*struct f_data_c *fd=(struct f_data_c*)data;*/ /* no jsint_destroy context or so here, it's called automatically from reinit_f_data_c */ /* zatim jsem to zrusil ... tahle funkce musi byt volana pres timer, takhle je to uplne blbe a spadne to pri kazdem volani -- Mikulas to je <|>vina, v komentari je jasne napsano, ze tahle fce musi byt volana ze select loop, takze to nema co padat -- Brain no prave!! ze select smycky == z timeru. Z javascriptu to volat nemuzes, protoze to pod sebou ten kontext javascriptu smaze, a ten interpret spadne, protoze jeho kontext uz nebude existovat. -- Mikulas reinit_f_data_c(fd); */}/* returns allocated string with window name */unsigned char *js_upcall_get_window_name(void *data){ /* context must be a valid pointer ! */ struct f_data_c *fd=(struct f_data_c*)data; return fd->loc?stracpy(fd->loc->name):NULL;}/* returns allocated field of ID's of links in JS document * number of links is stored in len * if number of links is 0, returns NULL * on error returns NULL too */long *js_upcall_get_links(void *data, long document_id, int *len){ struct f_data_c *js_ctx=(struct f_data_c*)data; struct f_data_c *fd; struct link *l; int a; long *to_je_Ono; fd=jsint_find_document(document_id); if (!js_ctx)internal("js_upcall_get_links called with NULL context pointer\n"); if (!fd||!jsint_can_access(js_ctx,fd))return NULL; if (!(fd->f_data))return NULL; *len=fd->f_data->nlinks; if (!(*len))return NULL; l=fd->f_data->links; if ((unsigned)*len > MAXINT / sizeof(long)) overalloc(); to_je_Ono=mem_alloc((*len)*sizeof(long)); for (a=0;a<(*len);a++) /*to_je_Ono[a]=JS_OBJ_T_LINK+(((l+a)->num)<<JS_OBJ_MASK_SIZE);*/ to_je_Ono[a]=JS_OBJ_T_LINK+(a<<JS_OBJ_MASK_SIZE); return to_je_Ono;}/* returns allocated string with TARGET of the link * if the link doesn't exist in the document, returns NULL */unsigned char *js_upcall_get_link_target(void *data, long document_id, long link_id){ struct f_data_c *js_ctx=(struct f_data_c*)data; struct f_data_c *fd; struct link *l; if (!js_ctx)internal("js_upcall_get_link_target called with NULL context pointer\n"); if ((link_id&JS_OBJ_MASK)!=JS_OBJ_T_LINK)return NULL; /* this isn't link */ fd=jsint_find_document(document_id); if (!fd||!jsint_can_access(js_ctx,fd))return NULL; l=jsint_find_object(fd,link_id); if (!l)return NULL; return stracpy((l->target)?(l->target):(unsigned char *)(""));}/* returns allocated field of ID's of forms in JS document * number of forms is stored in len * if number of forms is 0, returns NULL * on error returns NULL too */long *js_upcall_get_forms(void *data, long document_id, int *len){ struct f_data_c *js_ctx=(struct f_data_c *)data; struct f_data_c *fd; struct form_control *fc; long *to_je_Ono; long last=0; if (!js_ctx)internal("js_upcall_get_forms 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; to_je_Ono=mem_alloc(sizeof(long)); *len=0; foreachback(fc, fd->f_data->forms) { long *p; int a; if ((*len)&&(fc->form_num)==last)continue; for (a=0;a<(*len);a++) if ((to_je_Ono[a]>>JS_OBJ_MASK_SIZE)==(fc->form_num))goto already_have; /* we already have this number */ (*len)++; if ((unsigned)*len > MAXINT / sizeof(long)) overalloc(); p=mem_realloc(to_je_Ono,(*len)*sizeof(long)); to_je_Ono=p; to_je_Ono[(*len)-1]=JS_OBJ_T_FORM|((fc->form_num)<<JS_OBJ_MASK_SIZE); last=fc->form_num;already_have:; } if (!(*len)){mem_free(to_je_Ono);to_je_Ono=NULL;} return to_je_Ono;}/* returns allocated string with the form action * when an error occurs, returns NULL */unsigned char *js_upcall_get_form_action(void *data, long document_id, long form_id){ struct f_data_c *js_ctx=(struct f_data_c *)data; struct f_data_c *fd; struct form_control *fc; if (!js_ctx)internal("js_upcall_get_form_action called with NULL context pointer\n"); fd=jsint_find_document(document_id); if (!fd||!jsint_can_access(js_ctx,fd))return NULL; if ((form_id&JS_OBJ_MASK)!=JS_OBJ_T_FORM)return NULL; /* this isn't form */ fc=jsint_find_object(fd,form_id); if (!fc)return NULL; return stracpy(fc->action);}/* sets form action */void js_upcall_set_form_action(void *context, long document_id, long form_id, unsigned char *action){ struct f_data_c *js_ctx=(struct f_data_c *)context; struct f_data_c *fd; struct form_control *fc; if (!js_ctx) { internal("js_upcall_set_form_action called with NULL context pointer\n"); } fd=jsint_find_document(document_id); if (!fd || !jsint_can_access(js_ctx,fd)) { if (action) mem_free(action); return; } if ( (form_id&JS_OBJ_MASK) != JS_OBJ_T_FORM ) { if (action) mem_free(action); return; } fc=jsint_find_object(fd,form_id); if (!fc) { if (action) mem_free(action); return; } if (fc->action) { mem_free (fc->action); if ( fd->loc && fd->loc->url ) fc->action=join_urls(fd->loc->url,action); else fc->action=stracpy(action); fd->f_data->uncacheable=1; } if (action) { mem_free(action); }}/* returns allocated string with the form target * when an error occurs, returns NULL */unsigned char *js_upcall_get_form_target(void *data, long document_id, long form_id){ struct f_data_c *js_ctx=(struct f_data_c *)data; struct f_data_c *fd; struct form_control *fc; if (!js_ctx)internal("js_upcall_get_form_target called with NULL context pointer\n"); fd=jsint_find_document(document_id); if (!fd||!jsint_can_access(js_ctx,fd))return NULL; if ((form_id&JS_OBJ_MASK)!=JS_OBJ_T_FORM)return NULL; /* this isn't form */ fc=jsint_find_object(fd,form_id); if (!fc)return NULL; return stracpy(fc->target);}/* returns allocated string with the form method * when an error occurs, returns NULL */unsigned char *js_upcall_get_form_method(void *data, long document_id, long form_id){ struct f_data_c *js_ctx=(struct f_data_c *)data; struct f_data_c *fd; struct form_control *fc; if (!js_ctx)internal("js_upcall_get_form_method called with NULL context pointer\n"); fd=jsint_find_document(document_id); if (!fd||!jsint_can_access(js_ctx,fd))return NULL; if ((form_id&JS_OBJ_MASK)!=JS_OBJ_T_FORM)return NULL; /* this isn't form */ fc=jsint_find_object(fd,form_id); if (!fc)return NULL; switch (fc->method) { case FM_GET: return stracpy("GET"); case FM_POST: case FM_POST_MP: return stracpy("POST"); default: internal("Invalid form method!\n"); return NULL; /* never called, but GCC likes it */ }}/* returns allocated string with the form encoding (value of attribute enctype) * when an error occurs, returns NULL */unsigned char *js_upcall_get_form_encoding(void *data, long document_id, long form_id){ struct f_data_c *js_ctx=(struct f_data_c *)data; struct f_data_c *fd; struct form_control *fc; if (!js_ctx)internal("js_upcall_get_form_encoding called with NULL context pointer\n"); fd=jsint_find_document(document_id); if (!fd||!jsint_can_access(js_ctx,fd))return NULL; if ((form_id&JS_OBJ_MASK)!=JS_OBJ_T_FORM)return NULL; /* this isn't form */ fc=jsint_find_object(fd,form_id); if (!fc)return NULL; switch (fc->method) { case FM_GET: case FM_POST: return stracpy("application/x-www-form-urlencoded"); case FM_POST_MP: return stracpy("multipart/form-data"); default: internal("Invalid form method!\n"); return NULL; /* never called, but GCC likes it */ }}/* returns allocated string containing protocol from current URL in the script context * on error (or there's no protocol) NULL is returned */unsigned char *js_upcall_get_location_protocol(void *data){ struct f_data_c *fd; unsigned char *loc; unsigned char *p; int l; 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, &l, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)){mem_free(loc);return NULL;} p=memacpy(loc,l+1); /* l is pointing to the colon, but we want protocol with colon */ mem_free(loc); return p;}/* returns allocated string containing port of current URL in the script context * on error (or there's no protocol) NULL is returned */unsigned char *js_upcall_get_location_port(void *data){ struct f_data_c *fd; unsigned char *loc; unsigned char *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;} p=get_port_str(loc); mem_free(loc); return p;}/* returns allocated string containing hostname of current URL in the script context * on error (or there's no protocol) NULL is returned */unsigned char *js_upcall_get_location_hostname(void *data){ struct f_data_c *fd; unsigned char *loc; unsigned char *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;} p=get_host_name(loc); mem_free(loc); return p;}/* returns allocated string containing hostname and port of current URL in the script context * on error (or there's no protocol) NULL is returned */unsigned char *js_upcall_get_location_host(void *data){ struct f_data_c *fd; unsigned char *loc; unsigned char *p, *h;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -