📄 jsint.c
字号:
if (!data)internal("js_upcall_get_document_id called with NULL pointer!"); fd=(struct f_data_c*)data; return (((fd->id)<<JS_OBJ_MASK_SIZE)|JS_OBJ_T_DOCUMENT);}/* same as get_document_id, but returned type is FRAME */static long js_upcall_get_frame_id(void *data){ struct f_data_c *fd; if (!data)internal("js_upcall_get_document_id called with NULL pointer!"); fd=(struct f_data_c*)data; return (((fd->id)<<JS_OBJ_MASK_SIZE)|JS_OBJ_T_FRAME);}/* writes "len" bytes starting at "str" to document */void js_upcall_document_write(void *p, unsigned char *str, int len){ int pos; unsigned char *s; struct f_data_c *fd = p; struct js_state *js = fd->js; if (!js)return; if (!js->active) internal("js_upcall_document_write: no request active"); if (js->active->write_pos == -1) return; if (js->active->write_pos < 0) internal("js_upcall_document_write: js->active trashed"); if (!js->src) { unsigned char *s, *eof; if (get_file(fd->rq, &s, &eof)) return; if (!(js->src = memacpy(s, eof - s))) return; js->srclen = eof - s; } if ((unsigned)js->srclen + (unsigned)len > MAXINT) overalloc(); if ((unsigned)js->srclen + (unsigned)len < (unsigned)len) overalloc(); s = mem_realloc(js->src, js->srclen + len); js->src = s; if ((pos = js->srclen - js->active->write_pos) < 0) pos = 0; memmove(s + pos + len, s + pos, js->srclen - pos); memcpy(s + pos, str, len); js->srclen += len; js->newdata += len; js_zaflaknuto_pameti += len; js->active->wrote = 1;}/* returns title of actual document (=document in the script context) *//* when an error occurs, returns NULL *//* returned string should be deallocated after use */unsigned char *js_upcall_get_title(void *data){ struct f_data_c *fd; unsigned char *title, *t; struct conv_table* ct; if (!data)internal("js_upcall_get_title called with NULL pointer!"); fd=(struct f_data_c *)data; title=mem_alloc(MAX_STR_LEN*sizeof(unsigned char)); if (!(get_current_title(fd->ses,title,MAX_STR_LEN))){mem_free(title);return NULL;} if (fd->f_data) { ct=get_translation_table(fd->f_data->opt.cp,fd->f_data->cp); t = convert_string(ct, title, strlen(title), NULL); mem_free(title); title=t; } return title;}/* sets title of actual document (=document in the script context) *//* string title will be deallocated after use */void js_upcall_set_title(void *data, unsigned char *title){ unsigned char *t; struct conv_table* ct; struct f_data_c *fd; int l=0; if (!data)internal("js_upcall_get_title called with NULL pointer!"); fd=(struct f_data_c *)data; if (!title)return; if (!(fd->f_data)){mem_free(title);return;} if (fd->f_data->title)mem_free(fd->f_data->title); fd->f_data->title=init_str(); fd->f_data->uncacheable=1; ct=get_translation_table(fd->f_data->cp,fd->f_data->opt.cp); t = convert_string(ct, title, strlen(title), NULL); add_to_str(&(fd->f_data->title),&l,t); mem_free(t); mem_free(title); redraw_document(fd);}/* returns URL of actual document (=document in the script context) *//* when an error occurs, returns NULL *//* returned string should be deallocated after use */unsigned char *js_upcall_get_location(void *data){ struct f_data_c *fd; unsigned char *loc; 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;} return loc; }/* returns string containing last modification date *//* or NULL when the date is not known or when an error occurs */unsigned char *js_upcall_document_last_modified(void *data, long document_id){ struct f_data_c *fd; struct f_data_c *document; unsigned char *retval; document=jsint_find_document(document_id); if (!data)internal("js_upcall_document_last_modified called with NULL pointer!"); fd=(struct f_data_c *)data; if (!document)return NULL; /* document not found */ if (!jsint_can_access(fd, document))return NULL; /* you have no permissions to look at the document */ if (!fd->rq||!fd->rq->ce)return NULL; retval=stracpy(fd->rq->ce->last_modified); return retval;}/* returns allocated string with user-agent */unsigned char *js_upcall_get_useragent(void *data){ struct f_data_c *fd; unsigned char *retval=init_str(); int l=0; if (!data)internal("js_upcall_get_useragent called with NULL pointer!"); fd=(struct f_data_c *)data; if (!http_bugs.fake_useragent||!(*http_bugs.fake_useragent)) { add_to_str(&retval, &l, "Links (" VERSION_STRING "; "); add_to_str(&retval, &l, system_name); add_to_str(&retval, &l, ")"); } else { add_to_str(&retval, &l, http_bugs.fake_useragent); } return retval;}/* returns allocated string with browser name */unsigned char *js_upcall_get_appname(void){ if (!http_bugs.fake_useragent||!(*http_bugs.fake_useragent)) return stracpy("Links"); else return stracpy(http_bugs.fake_useragent);}/* returns allocated string with browser name */unsigned char *js_upcall_get_appcodename(void){ if (!http_bugs.fake_useragent||!(*http_bugs.fake_useragent)) return stracpy("Links"); else return stracpy(http_bugs.fake_useragent);}/* returns allocated string with browser version: "version_number (system_name)" */unsigned char *js_upcall_get_appversion(void){ unsigned char *str; int l=0; if (http_bugs.fake_useragent&&(*http_bugs.fake_useragent))return stracpy(http_bugs.fake_useragent); str=init_str(); add_to_str(&str,&l,VERSION_STRING); add_to_str(&str,&l," ("); add_to_str(&str,&l,system_name); add_to_str(&str,&l,")"); return str;}/* returns allocated string with referrer */unsigned char *js_upcall_get_referrer(void *data){ struct f_data_c *fd; unsigned char *retval=init_str(); unsigned char *loc; int l=0; if (!data)internal("js_upcall_get_referrer called with NULL pointer!"); fd=(struct f_data_c *)data; switch (http_bugs.referer) { case REFERER_FAKE: add_to_str(&retval, &l, http_bugs.fake_referer); break; case REFERER_SAME_URL: loc=mem_alloc(MAX_STR_LEN*sizeof(unsigned char)); if (!(get_current_url(fd->ses,loc,MAX_STR_LEN))){mem_free(loc);break;} add_to_str(&retval, &l, loc); mem_free(loc); break; case REFERER_REAL: { unsigned char *post; if (!fd->rq||!(fd->rq->prev_url))break; /* no referrer */ post=strchr(fd->rq->prev_url, POST_CHAR); if (!post)add_to_str(&retval, &l, fd->rq->prev_url); else add_bytes_to_str(&retval, &l, fd->rq->prev_url, post - fd->rq->prev_url); } break; } return retval;}struct gimme_js_id{ long id; /* id of f_data_c */ long js_id; /* unique id of javascript */};/* tady se netestuje js_id, protoze BFU to chce killnout, tak to proste killne *//* aux function for all dialog upcalls */static void js_kill_script_pressed(void *data){ 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))return; js_downcall_game_over(fd->js->ctx); /* call downcall */}/* aux function for js_upcall_confirm */static void js_upcall_confirm_ok_pressed(void *data){ 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_true(fd->js->ctx); /* call downcall */}/* aux function for js_upcall_confirm */static void js_upcall_confirm_cancel_pressed(void *data){ 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_false(fd->js->ctx); /* call downcall */}/* creates dialog with text s->string and buttons OK/Cancel *//* s->string will be dealocated *//* s will be dealocated too *//* must be called from select loop */void js_upcall_confirm(void *data){ struct fax_me_tender_string *s=(struct fax_me_tender_string*)data; struct gimme_js_id* jsid; struct f_data_c *fd; struct terminal *term; unsigned char *txt; if (!s)internal("js_upcall_confirm 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; skip_nonprintable(s->string); if (fd->f_data) { struct conv_table* ct; ct=get_translation_table(fd->f_data->cp,fd->f_data->opt.cp); txt=convert_string(ct,s->string,strlen(s->string),NULL); } else txt=stracpy(s->string); js_mem_free(s->string); msg_box( term, /* terminal */ getml(txt,jsid,NULL), /* memory blocks to free */ TEXT(T_QUESTION), /* title */ AL_CENTER, /* alignment */ txt, /* message */ jsid, /* data for button functions */ 3, /* # of buttons */ TEXT(T_OK),js_upcall_confirm_ok_pressed,B_ENTER, /* first button */ TEXT(T_CANCEL),js_upcall_confirm_cancel_pressed,B_ESC, /* second button */ TEXT(T_KILL_SCRIPT), js_kill_script_pressed,NULL ); js_mem_free(s);}/* aux function for js_upcall_alert */static void js_upcall_alert_ok_pressed(void *data){ 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_null(fd->js->ctx); /* call downcall */}/* gets struct fax_me_tender_string* *//* creates dialog with title "Alert" and message got from struct fax_me_tender_string *//* structure and the text are both deallocated *//* must be called from select loop */void js_upcall_alert(void * data){ struct fax_me_tender_string *s=(struct fax_me_tender_string*)data; struct gimme_js_id* jsid; struct f_data_c *fd; struct terminal *term; unsigned char *txt; if (!s)internal("Alert 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; skip_nonprintable(s->string); if (fd->f_data) { struct conv_table* ct; ct=get_translation_table(fd->f_data->cp,fd->f_data->opt.cp); txt=convert_string(ct,s->string,strlen(s->string),NULL); } else txt=stracpy(s->string); js_mem_free(s->string); msg_box( term, /* terminal */ getml(txt,jsid,NULL), /* memory blocks to free */ TEXT(T_ALERT), /* title */ AL_CENTER, /* alignment */ txt, /* message */ jsid, /* data for button functions */ 2, /* # of buttons */ TEXT(T_OK),js_upcall_alert_ok_pressed,B_ENTER|B_ESC, TEXT(T_KILL_SCRIPT), js_kill_script_pressed,NULL ); js_mem_free(s);}/* aux function for js_upcall_close_window *//* tady se netestuje js_id, protoze BFU zmacklo, ze chce zavrit okno a v * nekterych pripadech by ho to nezavrelo (kdyby se testovalo) a to by vypadalo * blbe */static void js_upcall_close_window_yes_pressed(void *data){ 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 */ really_exit_prog(fd->ses);}/* asks user if he really wants to close the window and calls really_exit_prog *//* argument is struct fax_me_tender_nothing* *//* must be called from select loop */void js_upcall_close_window(void *data){ struct fax_me_tender_nothing *s=(struct fax_me_tender_nothing*)data; struct f_data_c *fd; struct terminal *term; if (!s)internal("js_upcall_close_window 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); if (!fd->js) return; term=fd->ses->term; /* kill timer, that called me */ js_spec_vykill_timer(fd->js->ctx,0); if (js_manual_confirmation) { struct gimme_js_id* jsid; jsid=mem_alloc(sizeof(struct gimme_js_id)); /* fill in jsid */ jsid->id=((fd->id)<<JS_OBJ_MASK_SIZE)|JS_OBJ_T_DOCUMENT; jsid->js_id=fd->js->ctx->js_id; msg_box( term, /* terminal */ getml(jsid,NULL), /* memory blocks to free */ TEXT(T_EXIT_LINKS), /* title */ AL_CENTER, /* alignment */ TEXT(T_SCRIPT_TRYING_TO_CLOSE_WINDOW), /* message */ jsid, /* data for button functions */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -