1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

'v3.6.3.1'

This commit is contained in:
gnosygnu
2016-06-19 23:58:10 -04:00
parent 96636f3161
commit d4e8590345
1960 changed files with 20790 additions and 9272 deletions

View File

@@ -36,30 +36,25 @@ package gplx.xowa.apps.servers.http; import gplx.*; import gplx.xowa.*; import g
import gplx.core.threads.*; import gplx.core.net.*; import gplx.core.primitives.*; import gplx.core.envs.*;
import gplx.langs.jsons.*; import gplx.langs.htmls.encoders.*;
import gplx.xowa.wikis.pages.*;
public class Http_server_mgr implements GfoInvkAble {
private final Object thread_lock = new Object();
private final Gfo_usr_dlg usr_dlg;
public class Http_server_mgr implements Gfo_invk {
private final Object thread_lock = new Object();
private final Gfo_usr_dlg usr_dlg;
private Http_server_socket wkr;
private byte retrieve_mode = File_retrieve_mode.Mode_wait;
private boolean running, init_gui_done;
private boolean running, init_gui_needed = true;
public Http_server_mgr(Xoae_app app) {
this.app = app;
this.usr_dlg = app.Usr_dlg();
this.request_parser = new Http_request_parser(server_wtr, false);
}
public Xoae_app App() {return app;} private final Xoae_app app;
public Http_server_wtr Server_wtr() {return server_wtr;} private final Http_server_wtr server_wtr = Http_server_wtr_.new_console();
public Http_request_parser Request_parser() {return request_parser;} private final Http_request_parser request_parser;
public Gfo_url_encoder Encoder() {return encoder;} private final Gfo_url_encoder encoder = Gfo_url_encoder_.New__http_url().Make();
public Xoae_app App() {return app;} private final Xoae_app app;
public Http_server_wtr Server_wtr() {return server_wtr;} private final Http_server_wtr server_wtr = Http_server_wtr_.new_console();
public Http_request_parser Request_parser() {return request_parser;} private final Http_request_parser request_parser;
public Gfo_url_encoder Encoder() {return encoder;} private final Gfo_url_encoder encoder = Gfo_url_encoder_.New__http_url().Make();
public int Port() {return port;} public Http_server_mgr Port_(int v) {port = v; return this;} private int port = 8080;
public Http_server_wkr_pool Wkr_pool() {return wkr_pool;} private final Http_server_wkr_pool wkr_pool = new Http_server_wkr_pool();
public Int_pool Uid_pool() {return uid_pool;} private final Int_pool uid_pool = new Int_pool();
public Http_server_wkr_pool Wkr_pool() {return wkr_pool;} private final Http_server_wkr_pool wkr_pool = new Http_server_wkr_pool();
public Int_pool Uid_pool() {return uid_pool;} private final Int_pool uid_pool = new Int_pool();
public byte[] Home() {return home;} public void Home_(byte[] v) {home = Bry_.Add(Byte_ascii.Slash_bry, v);} private byte[] home = Bry_.new_a7("/home/wiki/Main_Page");
private void Init_gui() { // create a shim gui to automatically handle default XOWA gui JS calls
if (init_gui_done) return;
init_gui_done = true;
Gxw_html_server.Init_gui_for_server(app, null);
}
private void Running_(boolean val) {
if (val) {
if (running)
@@ -81,7 +76,7 @@ public class Http_server_mgr implements GfoInvkAble {
}
public void Run() {
if (wkr == null) wkr = new Http_server_socket(this);
Thread_adp_.invk_("thread:xowa.http_server.server", wkr, Http_server_socket.Invk_run).Start();
Thread_adp_.Start_by_key("thread:xowa.http_server.server", wkr, Http_server_socket.Invk_run);
Note("HTTP Server started: Navigate to http://localhost:" + Int_.To_str(port));
}
public void Run_xowa_cmd(Xoae_app app, String url_encoded_str) {
@@ -89,34 +84,43 @@ public class Http_server_mgr implements GfoInvkAble {
String cmd = url_converter.Decode_str(url_encoded_str);
app.Gfs_mgr().Run_str(cmd);
}
public String Parse_page_to_html(Http_data__client data__client, byte[] wiki_domain, byte[] page_ttl) {
public String Parse_page_to_html(Http_data__client data__client, byte[] wiki_domain, byte[] ttl_bry) {
synchronized (thread_lock) {
Init_gui();
Xowe_wiki wiki = (Xowe_wiki)app.Wiki_mgr().Get_by_or_make_init_y(wiki_domain); // get the wiki; assert init for Main_Page; EX:click zh.w on wiki sidebar; DATE:2015-07-19
if (Env_.System_memory_total() > Io_mgr.Len_gb) Xow_wiki_.Rls_mem(wiki, true); // release memory at 1 GB; DATE:2015-09-11
if (Bry_.Len_eq_0(page_ttl)) page_ttl = wiki.Props().Main_page();
Xoa_url page_url = wiki.Utl__url_parser().Parse(page_ttl); // get the url (needed for query args)
Xoa_ttl ttl = Xoa_ttl.parse(wiki, page_ttl); // get the ttl
Xoae_page page = wiki.Data_mgr().Load_page_by_ttl(page_url, ttl); // get page and parse it
Gxw_html_server.Assert_tab(app, page); // HACK: assert at least 1 tab
app.Gui_mgr().Browser_win().Active_page_(page); // HACK: init gui_mgr's page for output (which server ordinarily doesn't need)
if (page.Missing()) { // if page does not exist, replace with message; else null_ref error; DATE:2014-03-08
// create a shim gui to automatically handle default XOWA gui JS calls
if (init_gui_needed) {
init_gui_needed = false;
Gxw_html_server.Init_gui_for_server(app, null);
}
// get the wiki
Xowe_wiki wiki = (Xowe_wiki)app.Wiki_mgr().Get_by_or_make_init_y(wiki_domain); // assert init for Main_Page; EX:click zh.w on wiki sidebar; DATE:2015-07-19
if (Env_.System_memory_total() > Io_mgr.Len_gb) Xowe_wiki_.Rls_mem(wiki, true); // release memory at 1 GB; DATE:2015-09-11
// get the url / ttl
if (Bry_.Len_eq_0(ttl_bry)) ttl_bry = wiki.Props().Main_page();
Xoa_url url = wiki.Utl__url_parser().Parse(ttl_bry);
Xoa_ttl ttl = Xoa_ttl.parse(wiki, ttl_bry);
// get the page
gplx.xowa.guis.views.Xog_tab_itm tab = Gxw_html_server.Assert_tab2(app, wiki); // HACK: assert tab exists
Xoae_page page = wiki.Page_mgr().Load_page(url, ttl, tab);
app.Gui_mgr().Browser_win().Active_page_(page); // HACK: init gui_mgr's page for output (which server ordinarily doesn't need)
if (page.Missing()) { // if page does not exist, replace with message; else null_ref error; DATE:2014-03-08
page.Data_raw_(Bry_.new_a7("'''Page not found.'''"));
wiki.Parser_mgr().Parse(page, false);
}
page.Html_data().Head_mgr().Itm__server().Init_by_http(data__client).Enabled_y_();
byte[] output_html = wiki.Html_mgr().Page_wtr_mgr().Gen(page, Xopg_page_.Tid_read); // write html from page data
// generate html
switch (retrieve_mode) {
case File_retrieve_mode.Mode_skip: break; // noop
case File_retrieve_mode.Mode_async_server: app.Gui_mgr().Browser_win().Page__async__bgn(page.Tab_data().Tab()); break;
case File_retrieve_mode.Mode_wait:
if (page.File_queue().Count() > 0) {
app.Gui_mgr().Browser_win().Active_tab().Async();
output_html = wiki.Html_mgr().Page_wtr_mgr().Gen(page, Xopg_page_.Tid_read);
}
case File_retrieve_mode.Mode_async_server: app.Gui_mgr().Browser_win().Page__async__bgn(tab); break;
case File_retrieve_mode.Mode_wait:
gplx.xowa.guis.views.Xog_async_wkr.Async(page, tab.Html_itm());
page = wiki.Page_mgr().Load_page(url, ttl, tab); // HACK: fetch page again so that HTML will now include img data
break;
}
return String_.new_u8(output_html);
return String_.new_u8(wiki.Html_mgr().Page_wtr_mgr().Gen(page, Xopg_page_.Tid_read));
}
}
private void Note(String s) {
@@ -131,7 +135,7 @@ public class Http_server_mgr implements GfoInvkAble {
else if (ctx.Match(k, Invk_retrieve_mode)) return File_retrieve_mode.Xto_str(retrieve_mode);
else if (ctx.Match(k, Invk_retrieve_mode_)) retrieve_mode = File_retrieve_mode.Xto_byte(m.ReadStr("v"));
else if (ctx.Match(k, Invk_retrieve_mode_list)) return File_retrieve_mode.Options__list;
else return GfoInvkAble_.Rv_unhandled;
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String

View File

@@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps.servers.http; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*;
import gplx.core.net.*; import gplx.core.threads.*; import gplx.core.primitives.*;
class Http_server_socket implements GfoInvkAble {
private final Http_server_mgr server_mgr;
class Http_server_socket implements Gfo_invk {
private final Http_server_mgr server_mgr;
private Server_socket_adp server_socket;
public Http_server_socket(Http_server_mgr server_mgr) {this.server_mgr = server_mgr;}
public boolean Canceled() {return canceled;}
@@ -53,12 +53,12 @@ class Http_server_socket implements GfoInvkAble {
}
Http_server_wkr_v2 wkr = new Http_server_wkr_v2(server_mgr, wkr_uid);
wkr.Init_by_thread(client_socket);
Thread_adp_.invk_("thread:xowa.http_server.client", wkr, Http_server_wkr_v2.Invk_run).Start();
Thread_adp_.Start_by_key("thread:xowa.http_server.client", wkr, Http_server_wkr_v2.Invk_run);
}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_run)) this.Run();
else return GfoInvkAble_.Rv_unhandled;
else return Gfo_invk_.Rv_unhandled;
return this;
} public static final String Invk_run = "run";
}

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.apps.servers.http; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*;
import gplx.core.primitives.*;
public class Http_server_wkr_pool {
private final Ordered_hash hash = Ordered_hash_.New(); private final Int_obj_ref hash_key = Int_obj_ref.neg1_();
private final Ordered_hash hash = Ordered_hash_.New(); private final Int_obj_ref hash_key = Int_obj_ref.New_neg1();
public boolean Enabled() {return max != 0;}
public int Max() {return max;} private int max;
public int Timeout() {return timeout;} private int timeout;
@@ -28,7 +28,7 @@ public class Http_server_wkr_pool {
public void Add(int uid) {
if (max == 0) return; // disabled
synchronized (hash) {
Int_obj_ref wkr_key = Int_obj_ref.new_(uid);
Int_obj_ref wkr_key = Int_obj_ref.New(uid);
hash.Add(wkr_key, wkr_key);
++len;
}

View File

@@ -16,11 +16,11 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps.servers.http; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*;
import gplx.core.ios.*;
import gplx.core.ios.*; import gplx.core.ios.streams.*;
import gplx.core.primitives.*; import gplx.core.net.*; import gplx.langs.htmls.encoders.*;
import gplx.xowa.apps.*;
import gplx.xowa.htmls.js.*;
class Http_server_wkr_v2 implements GfoInvkAble {
class Http_server_wkr_v2 implements Gfo_invk {
private final int uid;
private final Http_server_mgr server_mgr;
private final Http_server_wtr server_wtr;
@@ -31,7 +31,7 @@ class Http_server_wkr_v2 implements GfoInvkAble {
private final Xoae_app app;
private final String root_dir_http;
private final byte[] root_dir_fsys;
private final Bry_bfr tmp_bfr = Bry_bfr.new_(64);
private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(64);
private Socket_adp socket;
private Http_data__client data__client;
public Http_server_wkr_v2(Http_server_mgr server_mgr, int uid){
@@ -149,7 +149,7 @@ class Http_server_wkr_v2 implements GfoInvkAble {
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_run)) {this.Run();}
else return GfoInvkAble_.Rv_unhandled;
else return Gfo_invk_.Rv_unhandled;
return this;
} public static final String Invk_run = "run";
private static final byte[]
@@ -163,7 +163,7 @@ class Xosrv_http_wkr_ {
public static void Write_response_as_html(Http_client_wtr client_wtr, boolean cross_domain, byte[] html) {
try{
client_wtr.Write_bry(Rsp__http_ok);
// TODO: add command-line argument to allow testing from local file
// TODO_OLD: add command-line argument to allow testing from local file
// if (cross_domain)
// client_wtr.Write_str("Access-Control-Allow-Origin: *\n"); // No 'Access-Control-Allow-Origin' header is present on the requested resource.
client_wtr.Write_bry(Rsp__content_type_html);