Skip to content

Commit 22a920d

Browse files
committed
[ext] more external-access work
1 parent 479b6a7 commit 22a920d

6 files changed

Lines changed: 48 additions & 3 deletions

File tree

configure.ac

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ AS_IF([test "x$with_system_doctest" != "xyes"], [
134134
CPPFLAGS="-I\$(top_srcdir)/src/third-party/doctest-root $CPPFLAGS"
135135
])
136136

137+
AC_ARG_WITH([cargo],
138+
AS_HELP_STRING(
139+
[--without-cargo],
140+
[Skip the Rust extensions]
141+
),
142+
AS_IF([test "x$with_cargo" = "xno"], [
143+
CARGO_CMD=""
144+
]),
145+
[]
146+
)
137147

138148
LNAV_WITH_JEMALLOC
139149

docs/notes/log2src.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,8 @@ Steps:
7070
1. Show that the editor has moved to the source code
7171
containing the breakpoint and the variables passed to
7272
the log statement are shown.
73+
74+
Implementation tasks:
75+
76+
- [X] Make lnav remotely-controllable
77+
- [X] Add support for breakpoints

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,7 @@ target_compile_options(diag PRIVATE ${CURSES_CFLAGS})
834834
add_custom_command(
835835
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/target/release/liblnav_rs_ext.a
836836
COMMAND env CARGO_TARGET_DIR=target cargo build --manifest-path ${CMAKE_CURRENT_SOURCE_DIR}/third-party/lnav-rs-ext/Cargo.toml --package lnav-rs-ext --release
837+
DEPENDS third-party/lnav-rs-ext/src/lib.rs third-party/lnav-rs-ext/src/ext_access.rs
837838
)
838839
add_custom_target(
839840
lnav_rs_ext

src/cmds.scripting.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ com_sh(exec_context& ec, std::string cmdline, std::vector<std::string>& args)
474474
return Ok(std::string());
475475
}
476476

477+
#ifdef HAVE_RUST_DEPS
477478
namespace lnav_rs_ext {
478479

479480
::rust::String
@@ -529,12 +530,14 @@ execute_external_command(::rust::String rs_src, ::rust::String rs_script)
529530
}
530531

531532
} // namespace lnav_rs_ext
533+
#endif
532534

533535
static Result<std::string, lnav::console::user_message>
534536
com_external_access(exec_context& ec,
535537
std::string cmdline,
536538
std::vector<std::string>& args)
537539
{
540+
#ifdef HAVE_RUST_DEPS
538541
if (args.size() != 3) {
539542
return ec.make_error("Expecting port number and API key");
540543
}
@@ -550,7 +553,8 @@ com_external_access(exec_context& ec,
550553

551554
auto scan_res = scn::scan_int<uint16_t>(args[1]);
552555
if (!scan_res || !scan_res.value().range().empty()) {
553-
return ec.make_error(FMT_STRING("port value is not a number: {}"), args[1]);
556+
return ec.make_error(FMT_STRING("port value is not a number: {}"),
557+
args[1]);
554558
}
555559
auto port = scan_res->value();
556560

@@ -567,6 +571,9 @@ com_external_access(exec_context& ec,
567571
setenv("LNAV_EXTERNAL_URL", url.c_str(), 1);
568572

569573
return Ok(retval);
574+
#else
575+
return ec.make_error("lnav was compiled without Rust extensions");
576+
#endif
570577
}
571578

572579
static readline_context::command_t SCRIPTING_COMMANDS[] = {

src/lnav_commands.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ com_add_src_path(exec_context& ec,
315315
if (!ec.ec_dry_run) {
316316
lnav_rs_ext::discover_srcs();
317317
}
318-
#endif
319318
return Ok(retval);
319+
#endif
320320
}
321321

322322
static Result<std::string, lnav::console::user_message>

src/third-party/lnav-rs-ext/src/ext_access.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,28 @@ use std::time::Duration;
1414
static SERVER: LazyLock<Mutex<Option<(JoinHandle<()>, Sender<()>)>>> =
1515
LazyLock::new(|| None.into());
1616

17+
static LANDING: &'static str = r#"
18+
<html>
19+
<head>
20+
<title>The Logfile Navigator</title>
21+
</head>
22+
<body>
23+
<h1>lnav</h1>
24+
25+
The Logfile Navigator, <b>lnav</b> for short, is a log file viewer for the terminal.
26+
27+
This server provides remote access to an lnav instance.
28+
29+
<ul>
30+
<li><b>GET</b> /version - Get a JSON object with version information for this instance.</li>
31+
<li><b>POST</b> /exec - Execute a text/x-lnav-script and return the result.</li>
32+
</ul>
33+
34+
See <a href="https://lnav.org">lnav.org</a> for more information.
35+
</body>
36+
</html>
37+
"#;
38+
1739
fn do_exec(request: &Request) -> Response {
1840
let body = try_or_400!(rouille::input::plain_text_body(request));
1941

@@ -49,7 +71,7 @@ pub fn start_server(port: u16, api_key: String) -> Result<u16, Box<dyn Error + S
4971

5072
router!(request,
5173
(GET) (/) => {
52-
Response::text("Hello, World!")
74+
Response::html(LANDING)
5375
},
5476

5577
(GET) (/version) => {

0 commit comments

Comments
 (0)