From 40a355a42d4a9444dc753c04c6608dade2f06a23 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:13:27 +0200 Subject: Adding upstream version 125.0.1. Signed-off-by: Daniel Baumann --- browser/app/nmhproxy/src/main.rs | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 browser/app/nmhproxy/src/main.rs (limited to 'browser/app/nmhproxy/src/main.rs') diff --git a/browser/app/nmhproxy/src/main.rs b/browser/app/nmhproxy/src/main.rs new file mode 100644 index 0000000000..de9cd8c2a3 --- /dev/null +++ b/browser/app/nmhproxy/src/main.rs @@ -0,0 +1,55 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +mod commands; +use commands::ResultCode; +use std::io::Error; +use std::io::ErrorKind; + +fn main() -> Result<(), Error> { + // The general structure of these functions is to print error cases to + // stdout so that the extension can read them and then do error-handling + // on that end. + let message_length: u32 = + commands::read_message_length(std::io::stdin()).or_else(|_| -> Result { + commands::generate_response("Failed to read message length", ResultCode::Error.into()) + .expect("JSON error"); + return Err(Error::new( + ErrorKind::InvalidInput, + "Failed to read message length", + )); + })?; + let message: String = commands::read_message_string(std::io::stdin(), message_length).or_else( + |_| -> Result { + commands::generate_response("Failed to read message", ResultCode::Error.into()) + .expect("JSON error"); + return Err(Error::new( + ErrorKind::InvalidInput, + "Failed to read message", + )); + }, + )?; + // Deserialize the message with the following expected format + let native_messaging_json: commands::FirefoxCommand = + serde_json::from_str(&message).or_else(|_| -> Result { + commands::generate_response( + "Failed to deserialize message JSON", + ResultCode::Error.into(), + ) + .expect("JSON error"); + return Err(Error::new( + ErrorKind::InvalidInput, + "Failed to deserialize message JSON", + )); + })?; + commands::process_command(&native_messaging_json).or_else(|_| -> Result { + commands::generate_response("Failed to process command", ResultCode::Error.into()) + .expect("JSON error"); + return Err(Error::new( + ErrorKind::InvalidInput, + "Failed to process command", + )); + })?; + Ok(()) +} -- cgit v1.2.3