diff --git a/src/emu/webengine.c b/src/emu/webengine.c index 583ce92f526..b0bcc75d796 100644 --- a/src/emu/webengine.c +++ b/src/emu/webengine.c @@ -292,6 +292,53 @@ int web_engine::begin_request_handler(struct mg_connection *conn) return json_slider_handler(conn); } } + else if (!strncmp(conn->uri, "/keypost",8)) + { + // Is there any sane way to determine the length of the buffer before getting it? + // A request for a way was previously filed with the mongoose devs, + // but it looks like it was never implemented. + + // For now, we'll allow a paste buffer of 32k. + // To-do: Send an error if the paste is too big? + char cmd_val[32768]; + + int pastelength = mg_get_var(conn, "val", cmd_val, sizeof(cmd_val)); + if (pastelength > 0) { + machine().ioport().natkeyboard().post_utf8(cmd_val); + } + // Send HTTP reply to the client + mg_printf(conn, + "HTTP/1.1 200 OK\r\n" + "Content-Type: text/plain\r\n" + "Content-Length: 2\r\n" // Always set Content-Length + "\r\n" + "OK"); + + // Returning non-zero tells mongoose that our function has replied to + // the client, and mongoose should not send client any more data. + return MG_TRUE; + } + else if (!strncmp(conn->uri, "/keyupload",8)) + { + const char *upload_data; + int data_length, ofs = 0; + char var_name[100], file_name[255]; + while ((ofs = mg_parse_multipart(conn->content + ofs, conn->content_len - ofs, var_name, sizeof(var_name), file_name, sizeof(file_name), &upload_data, &data_length)) > 0) { + mg_printf_data(conn, "File: %s, size: %d bytes", file_name, data_length); + } + + // That upload_data contains more than we need. It also has the headers. + // We'll need to strip it down to just what we want. + + if ((&data_length > 0) && (sizeof(file_name) > 0)) + { + char paste_data[data_length]; + strncpy (paste_data, upload_data, data_length); + // Now paste the stripped down paste_data.. + machine().ioport().natkeyboard().post_utf8(paste_data); + } + return MG_TRUE; + } else if (!strncmp(conn->uri, "/cmd",4)) { char cmd_name[64]; diff --git a/web/index.html b/web/index.html index bd019dcb22d..6e73e035978 100644 --- a/web/index.html +++ b/web/index.html @@ -79,7 +79,7 @@ updateStatusBar('Disconnected','Exited','No Driver'); } } - + function executeHardReset() { executeCommands("hardreset"); @@ -202,6 +202,25 @@ window.onload = function() { startWebSocket(); }; + +$(document).ready(function() { + $( '#pasteTextForm' ).submit(function( event ) + { + $.ajax({ + url: "/keypost", + type:'POST', + data: + { + val: pasteText.value + }, + success: function(msg) + { + } + }); + event.preventDefault(); + }); +}); + @@ -327,6 +346,11 @@
+