1
0
Fork 0

[protocol] protocol.cpp -> protocol.c

This commit is contained in:
Witold Filipczyk 2023-11-25 17:06:11 +01:00
parent 9d5d9ead70
commit 970245b28a
7 changed files with 57 additions and 45 deletions

View File

@ -7,11 +7,18 @@
#include "elinks.h"
#include "dialogs/status.h"
#include "document/document.h"
#include "document/view.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/ecmascript-c.h"
#include "intl/libintl.h"
#include "protocol/uri.h"
#include "session/session.h"
#include "session/task.h"
#include "util/conv.h"
#include "util/memory.h"
#include "util/string.h"
#include "viewer/text/view.h"
extern int interpreter_count;
extern int ecmascript_enabled;
@ -34,3 +41,41 @@ toggle_ecmascript(struct session *ses)
}
print_screen_status(ses);
}
void
ecmascript_protocol_handler(struct session *ses, struct uri *uri)
{
struct document_view *doc_view = current_frame(ses);
struct string current_url = INIT_STRING(struri(uri), (int)strlen(struri(uri)));
char *redirect_url, *redirect_abs_url;
struct uri *redirect_uri;
if (!doc_view) /* Blank initial document. TODO: Start at about:blank? */
return;
assert(doc_view->vs);
if (doc_view->vs->ecmascript_fragile)
ecmascript_reset_state(doc_view->vs);
if (!doc_view->vs->ecmascript)
return;
redirect_url = ecmascript_eval_stringback(doc_view->vs->ecmascript,
&current_url);
if (!redirect_url)
return;
/* XXX: This code snippet is duplicated over here,
* location_set_property(), html_a() and who knows where else. */
redirect_abs_url = join_urls(doc_view->document->uri,
trim_chars(redirect_url, ' ', 0));
mem_free(redirect_url);
if (!redirect_abs_url)
return;
redirect_uri = get_uri(redirect_abs_url, URI_NONE);
mem_free(redirect_abs_url);
if (!redirect_uri)
return;
/* XXX: Is that safe to do at this point? --pasky */
goto_uri_frame(ses, redirect_uri, doc_view->name,
CACHE_MODE_NORMAL);
done_uri(redirect_uri);
}

View File

@ -8,10 +8,15 @@ extern "C" {
#endif
struct session;
struct uri;
int ecmascript_get_interpreter_count(void);
void toggle_ecmascript(struct session *ses);
/* Takes line with the syntax javascript:<ecmascript code>. Activated when user
* follows a link with this synstax. */
void ecmascript_protocol_handler(struct session *ses, struct uri *uri);
extern struct module ecmascript_module;
#ifdef __cplusplus

View File

@ -507,44 +507,6 @@ ecmascript_reset_state(struct view_state *vs)
vs->ecmascript_fragile = 1;
}
void
ecmascript_protocol_handler(struct session *ses, struct uri *uri)
{
struct document_view *doc_view = current_frame(ses);
struct string current_url = INIT_STRING(struri(uri), (int)strlen(struri(uri)));
char *redirect_url, *redirect_abs_url;
struct uri *redirect_uri;
if (!doc_view) /* Blank initial document. TODO: Start at about:blank? */
return;
assert(doc_view->vs);
if (doc_view->vs->ecmascript_fragile)
ecmascript_reset_state(doc_view->vs);
if (!doc_view->vs->ecmascript)
return;
redirect_url = ecmascript_eval_stringback(doc_view->vs->ecmascript,
&current_url);
if (!redirect_url)
return;
/* XXX: This code snippet is duplicated over here,
* location_set_property(), html_a() and who knows where else. */
redirect_abs_url = join_urls(doc_view->document->uri,
trim_chars(redirect_url, ' ', 0));
mem_free(redirect_url);
if (!redirect_abs_url)
return;
redirect_uri = get_uri(redirect_abs_url, URI_NONE);
mem_free(redirect_abs_url);
if (!redirect_uri)
return;
/* XXX: Is that safe to do at this point? --pasky */
goto_uri_frame(ses, redirect_uri, doc_view->name,
CACHE_MODE_NORMAL);
done_uri(redirect_uri);
}
void
ecmascript_timeout_dialog(struct terminal *term, int max_exec_time)
{

View File

@ -168,10 +168,6 @@ char *ecmascript_eval_stringback(struct ecmascript_interpreter *interpreter, str
/* Returns -1 if undefined. */
int ecmascript_eval_boolback(struct ecmascript_interpreter *interpreter, struct string *code);
/* Takes line with the syntax javascript:<ecmascript code>. Activated when user
* follows a link with this synstax. */
void ecmascript_protocol_handler(struct session *ses, struct uri *uri);
void ecmascript_timeout_dialog(struct terminal *term, int max_exec_time);
void ecmascript_set_action(char **action, char *string);

View File

@ -16,6 +16,6 @@ SUBDIRS = auth file http test
OBJS-$(CONFIG_DATA) += data.o
OBJS = about.o common.o date.o header.o protocol.obj proxy.o uri.o user.o
OBJS = about.o common.o date.o header.o protocol.o proxy.o uri.o user.o
include $(top_srcdir)/Makefile.lib

View File

@ -35,7 +35,7 @@ subdir('http')
if conf_data.get('CONFIG_DATA')
srcs += files('data.c')
endif
srcs += files('about.c', 'common.c', 'date.c', 'header.c', 'protocol.cpp', 'proxy.c', 'uri.c', 'user.c')
srcs += files('about.c', 'common.c', 'date.c', 'header.c', 'protocol.c', 'proxy.c', 'uri.c', 'user.c')
if get_option('test')
subdir('test')

View File

@ -11,7 +11,11 @@
#include "bfu/dialog.h"
#include "document/view.h"
#include "ecmascript/ecmascript.h"
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
#include "ecmascript/ecmascript-c.h"
#endif
#include "intl/libintl.h"
#include "main/module.h"
#include "network/connection.h"