diff --git a/src/main/java/org/asamk/signal/JsonEvtLoopReceiveMessageHandler.java b/src/main/java/org/asamk/signal/JsonEventLoopReceiveMessageHandler.java similarity index 67% rename from src/main/java/org/asamk/signal/JsonEvtLoopReceiveMessageHandler.java rename to src/main/java/org/asamk/signal/JsonEventLoopReceiveMessageHandler.java index 579d052f..ea56177d 100644 --- a/src/main/java/org/asamk/signal/JsonEvtLoopReceiveMessageHandler.java +++ b/src/main/java/org/asamk/signal/JsonEventLoopReceiveMessageHandler.java @@ -18,20 +18,20 @@ import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope; //import java.io.IOException; -public class JsonEvtLoopReceiveMessageHandler implements Manager.ReceiveMessageHandler { +public class JsonEventLoopReceiveMessageHandler implements Manager.ReceiveMessageHandler { public interface ResponseEmitter { - public void emit( JsonEvtLoopStatusReport resp); + public void emit( JsonEventLoopStatusReport resp); } final Manager m; ResponseEmitter responseEmitter; - public JsonEvtLoopReceiveMessageHandler(Manager m) { + public JsonEventLoopReceiveMessageHandler(Manager m) { this.m = m; } - public JsonEvtLoopReceiveMessageHandler( Manager m, ResponseEmitter responseEmitter) { + public JsonEventLoopReceiveMessageHandler( Manager m, ResponseEmitter responseEmitter) { this.m = m; this.responseEmitter = responseEmitter; } @@ -39,17 +39,17 @@ public class JsonEvtLoopReceiveMessageHandler implements Manager.ReceiveMessageH @Override public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) { //ObjectNode result = jsonProcessor.createObjectNode(); - JsonEvtLoopStatusReport resp = null; + JsonEventLoopStatusReport resp = null; if (exception != null) { - resp = new JsonEvtLoopStatusReport( "error", null, "error", "JsonEvtLoopReceiveMessageHandler::handleMessage: Exception: " + exception.toString()); + resp = new JsonEventLoopStatusReport( "error", null, "error", "JsonEventLoopReceiveMessageHandler::handleMessage: Exception: " + exception.toString()); //result.putPOJO("error", new JsonError(exception)); } if (envelope != null) { //result.putPOJO("envelope", new JsonMessageEnvelope(envelope, content)); - resp = new JsonEvtLoopStatusReport( new JsonMessageEnvelope(envelope, content)); + resp = new JsonEventLoopStatusReport( new JsonMessageEnvelope(envelope, content)); } if(resp == null) { - new JsonEvtLoopStatusReport( "error", null, "JsonEvtLoopReceiveMessageHandler::handleMessage: both exceptino and envelope is null!").emit(); + new JsonEventLoopStatusReport( "error", null, "JsonEventLoopReceiveMessageHandler::handleMessage: both exceptino and envelope is null!").emit(); } else { if( this.responseEmitter != null) { this.responseEmitter.emit( resp); diff --git a/src/main/java/org/asamk/signal/commands/Commands.java b/src/main/java/org/asamk/signal/commands/Commands.java index fcf529d4..a49ccc5f 100644 --- a/src/main/java/org/asamk/signal/commands/Commands.java +++ b/src/main/java/org/asamk/signal/commands/Commands.java @@ -11,7 +11,7 @@ public class Commands { addCommand("addDevice", new AddDeviceCommand()); addCommand("block", new BlockCommand()); addCommand("daemon", new DaemonCommand()); - addCommand("jsonevtloop", new JsonEvtLoopCommand()); + addCommand("jsonEventLoop", new JsonEventLoopCommand()); addCommand("link", new LinkCommand()); addCommand("listContacts", new ListContactsCommand()); addCommand("listDevices", new ListDevicesCommand()); diff --git a/src/main/java/org/asamk/signal/commands/JsonEvtLoopCommand.java b/src/main/java/org/asamk/signal/commands/JsonEventLoopCommand.java similarity index 72% rename from src/main/java/org/asamk/signal/commands/JsonEvtLoopCommand.java rename to src/main/java/org/asamk/signal/commands/JsonEventLoopCommand.java index 77dbc004..234fe01e 100644 --- a/src/main/java/org/asamk/signal/commands/JsonEvtLoopCommand.java +++ b/src/main/java/org/asamk/signal/commands/JsonEventLoopCommand.java @@ -6,7 +6,7 @@ import net.sourceforge.argparse4j.inf.Subparser; import org.asamk.Signal; import org.asamk.signal.GroupIdFormatException; -import org.asamk.signal.JsonEvtLoopReceiveMessageHandler; +import org.asamk.signal.JsonEventLoopReceiveMessageHandler; import org.asamk.signal.JsonReceiveMessageHandler; import org.asamk.signal.manager.Manager; import org.asamk.signal.storage.contacts.ContactInfo; @@ -29,7 +29,7 @@ import static org.asamk.signal.util.ErrorUtils.handleAssertionError; -public class JsonEvtLoopCommand implements LocalCommand { +public class JsonEventLoopCommand implements LocalCommand { @@ -38,14 +38,14 @@ public class JsonEvtLoopCommand implements LocalCommand { * @author bingel * */ - private static class JsonEvtLoopRequestHandler { + private static class JsonEventLoopRequestHandler { Manager m; /** * Constructor * @param m Signal Manager object */ - JsonEvtLoopRequestHandler( Manager m) { + JsonEventLoopRequestHandler( Manager m) { this.m = m; } @@ -55,28 +55,28 @@ public class JsonEvtLoopCommand implements LocalCommand { * @param reqID * @return */ - JsonEvtLoopStatusReport list_groups( JsonNode reqObj, JsonNode reqID) { + JsonEventLoopStatusReport list_groups( JsonNode reqObj, JsonNode reqID) { List groups = m.getGroups(); ObjectMapper mapper = new ObjectMapper(); JsonNode data_obj = mapper.valueToTree(groups); - return new JsonEvtLoopStatusReport( "group_list", reqID, data_obj); + return new JsonEventLoopStatusReport( "group_list", reqID, data_obj); } /** * Command Handler: list_contacts */ - JsonEvtLoopStatusReport list_contacts( JsonNode reqObj, JsonNode reqID) { + JsonEventLoopStatusReport list_contacts( JsonNode reqObj, JsonNode reqID) { List contacts = m.getContacts(); ObjectMapper mpr = new ObjectMapper(); JsonNode data_obj = mpr.valueToTree(contacts); - return new JsonEvtLoopStatusReport( "contact_list", reqID, data_obj); + return new JsonEventLoopStatusReport( "contact_list", reqID, data_obj); } /** * Command Handler: Send signal message and respond with status message * @param reqObj JSON parsed request object */ - JsonEvtLoopStatusReport send_message( JsonNode reqObj, JsonNode reqID) { + JsonEventLoopStatusReport send_message( JsonNode reqObj, JsonNode reqID) { // get body text String body_text = null; @@ -98,9 +98,9 @@ public class JsonEvtLoopCommand implements LocalCommand { try { m.sendMessage( body_text, attachments, recipientNumber); } catch( IOException e) { - return new JsonEvtLoopStatusReport( "send_message", reqID, "error", "IOException: " + e.toString() ); + return new JsonEventLoopStatusReport( "send_message", reqID, "error", "IOException: " + e.toString() ); } catch( EncapsulatedExceptions e) { - return new JsonEvtLoopStatusReport( "send_message", reqID, "error", "EncapsulatedException: " + e.toString() ); + return new JsonEventLoopStatusReport( "send_message", reqID, "error", "EncapsulatedException: " + e.toString() ); } } else if( reqObj.get("recipientGroupID") != null) { // send message to group @@ -109,17 +109,17 @@ public class JsonEvtLoopCommand implements LocalCommand { byte[] recipientGroupID_bytearray = Util.decodeGroupId(recipientGroupID); m.sendGroupMessage( body_text, attachments, recipientGroupID_bytearray); } catch( GroupIdFormatException e) { - return new JsonEvtLoopStatusReport( "send_message", reqID, "error", "GroupIdFormatException: " + e.toString() ); + return new JsonEventLoopStatusReport( "send_message", reqID, "error", "GroupIdFormatException: " + e.toString() ); } catch( IOException e) { - return new JsonEvtLoopStatusReport( "send_message", reqID, "error", "IOException: " + e.toString() ); + return new JsonEventLoopStatusReport( "send_message", reqID, "error", "IOException: " + e.toString() ); } catch( EncapsulatedExceptions e) { - return new JsonEvtLoopStatusReport( "send_message", reqID, "error", "EncapsulatedException: " + e.toString() ); + return new JsonEventLoopStatusReport( "send_message", reqID, "error", "EncapsulatedException: " + e.toString() ); } } else { - return new JsonEvtLoopStatusReport( "send_message", reqID, "error", "Neither recipientNumber or recipientGroupID present in request, nothing to do"); + return new JsonEventLoopStatusReport( "send_message", reqID, "error", "Neither recipientNumber or recipientGroupID present in request, nothing to do"); } - return new JsonEvtLoopStatusReport("send_message", reqID, "ok"); + return new JsonEventLoopStatusReport("send_message", reqID, "ok"); } /** @@ -129,7 +129,7 @@ public class JsonEvtLoopCommand implements LocalCommand { void handle( String textRow) { //System.err.println( "JsonRequestHandler: incoming string: " + textRow); - JsonEvtLoopStatusReport resp = null; + JsonEventLoopStatusReport resp = null; boolean exitNow = false; try { ObjectMapper objectMapper = new ObjectMapper(); @@ -140,10 +140,10 @@ public class JsonEvtLoopCommand implements LocalCommand { JsonNode reqID = reqObj.get("reqID"); switch(reqType) { case "alive": - resp = new JsonEvtLoopStatusReport("alive", reqID, "ok"); + resp = new JsonEventLoopStatusReport("alive", reqID, "ok"); break; case "exit": - resp = new JsonEvtLoopStatusReport("exit", reqID, "ok"); + resp = new JsonEventLoopStatusReport("exit", reqID, "ok"); //System.exit(0); exitNow = true; break; @@ -157,20 +157,20 @@ public class JsonEvtLoopCommand implements LocalCommand { resp = this.list_contacts( reqObj, reqID); break; default: - resp = new JsonEvtLoopStatusReport("error", reqID, "error", "Unknown reqType '" + reqType + "'"); + resp = new JsonEventLoopStatusReport("error", reqID, "error", "Unknown reqType '" + reqType + "'"); System.err.println("JsonEvtRequestHandler: ERROR: Unknown reqType '" + reqType + "'"); break; } } else { - resp = new JsonEvtLoopStatusReport("error", null, "error", "reqType attribute missing"); + resp = new JsonEventLoopStatusReport("error", null, "error", "reqType attribute missing"); System.err.println("JsonEvtRequestHandler: ERROR: reqType attribute is missing in request"); } } else { - resp = new JsonEvtLoopStatusReport("error", null, "error", "Failed to parse JSON, reqObj is NULL"); + resp = new JsonEventLoopStatusReport("error", null, "error", "Failed to parse JSON, reqObj is NULL"); System.err.println( "JsonEvtRequestHandler: Failed to parse JSON, reqObj is NULL"); } } catch( IOException e) { - resp = new JsonEvtLoopStatusReport("error", null, "error", "Failed to parse JSON: " + e.toString()); + resp = new JsonEventLoopStatusReport("error", null, "error", "Failed to parse JSON: " + e.toString()); System.err.println( "JsonEvtRequestHandler: Failed to parse JSON, text='" + textRow + "', IOException: " + e.toString()); } @@ -178,7 +178,7 @@ public class JsonEvtLoopCommand implements LocalCommand { if(resp != null) { resp.emit(); } else { - System.err.println( "JsonEvtRequestHandler: ERROR: No response!"); + System.err.println( "JsonEventRequestHandler: ERROR: No response!"); } // Someone requested we exit the program now @@ -194,7 +194,7 @@ public class JsonEvtLoopCommand implements LocalCommand { * */ private static class JsonStdinReader implements Runnable { - JsonEvtLoopRequestHandler jsonEvtLoopRequestHandler = null; + JsonEventLoopRequestHandler jsonEventLoopRequestHandler = null; public void run() { BufferedReader br = new BufferedReader( new InputStreamReader( System.in)); @@ -207,12 +207,12 @@ public class JsonEvtLoopCommand implements LocalCommand { System.exit(1); } if( line != null && !line.equals("")) - this.jsonEvtLoopRequestHandler.handle(line); + this.jsonEventLoopRequestHandler.handle(line); } } - public JsonStdinReader( JsonEvtLoopRequestHandler j) { - this.jsonEvtLoopRequestHandler = j; + public JsonStdinReader( JsonEventLoopRequestHandler j) { + this.jsonEventLoopRequestHandler = j; } } @@ -232,12 +232,12 @@ public class JsonEvtLoopCommand implements LocalCommand { public int handleCommand(final Namespace ns, final Manager m) { if (!m.isRegistered()) { //System.err.println("User is not registered."); - new JsonEvtLoopStatusReport( "error", null, "error", "JsonEvtLoopCommand::handleCommand: User is not registered, aborting"); + new JsonEventLoopStatusReport( "error", null, "error", "JsonEventLoopCommand::handleCommand: User is not registered, aborting"); return 1; } // Start stdin reader thread - JsonEvtLoopRequestHandler jhandler = new JsonEvtLoopRequestHandler( m); + JsonEventLoopRequestHandler jhandler = new JsonEventLoopRequestHandler( m); JsonStdinReader reader = new JsonStdinReader( jhandler); Thread jsonStdinReaderThread = new Thread( reader); jsonStdinReaderThread.start(); @@ -245,7 +245,7 @@ public class JsonEvtLoopCommand implements LocalCommand { // start JsonReceiveMessageHandler and let it run forever boolean ignoreAttachments = ns.getBoolean("ignore_attachments"); try { - final Manager.ReceiveMessageHandler handler = new JsonEvtLoopReceiveMessageHandler(m, (resp) -> { + final Manager.ReceiveMessageHandler handler = new JsonEventLoopReceiveMessageHandler(m, (resp) -> { // For future use - utilize this lambda callback to emit responses in correct channel // if that should not happen to be stdout, but for now, just emit json text to stdout resp.emit(); @@ -254,7 +254,7 @@ public class JsonEvtLoopCommand implements LocalCommand { return 0; } catch (IOException e) { System.err.println("Error while receiving messages: " + e.getMessage()); - new JsonEvtLoopStatusReport( "error", null, "error", "JsonEvtLoopCommand::handleCommand: Error while receiving messages: " + e.getMessage()).emit(); + new JsonEventLoopStatusReport( "error", null, "error", "JsonEventLoopCommand::handleCommand: Error while receiving messages: " + e.getMessage()).emit(); return 3; } catch (AssertionError e) { handleAssertionError(e); diff --git a/src/main/java/org/asamk/signal/commands/JsonEvtLoopStatusReport.java b/src/main/java/org/asamk/signal/commands/JsonEventLoopStatusReport.java similarity index 71% rename from src/main/java/org/asamk/signal/commands/JsonEvtLoopStatusReport.java rename to src/main/java/org/asamk/signal/commands/JsonEventLoopStatusReport.java index 677108e4..8fa168dc 100644 --- a/src/main/java/org/asamk/signal/commands/JsonEvtLoopStatusReport.java +++ b/src/main/java/org/asamk/signal/commands/JsonEventLoopStatusReport.java @@ -12,7 +12,7 @@ import com.fasterxml.jackson.databind.*; @JsonInclude(Include.NON_NULL) -public class JsonEvtLoopStatusReport { +public class JsonEventLoopStatusReport { public int apiVer = 2; public String respType; @@ -25,18 +25,18 @@ public class JsonEvtLoopStatusReport { /** - * Create new JsonEvtLoopStatusReport object for use for responding signal data envelopes + * Create new JsonEventLoopStatusReport object for use for responding signal data envelopes * * @param en Envelope from signal Manager */ - public JsonEvtLoopStatusReport( JsonMessageEnvelope en) { + public JsonEventLoopStatusReport( JsonMessageEnvelope en) { this.envelope = en; this.respType = "envelope"; this.status = "ok"; this.reqID = null; } - public JsonEvtLoopStatusReport( String respType, JsonNode reqID, JsonNode data) { + public JsonEventLoopStatusReport( String respType, JsonNode reqID, JsonNode data) { this.respType = respType; this.status = "ok"; this.reqID = reqID; @@ -44,27 +44,27 @@ public class JsonEvtLoopStatusReport { } /** - * Creates new JsonEvtLoopStatusReport object to use for responding to requests + * Creates new JsonEventLoopStatusReport object to use for responding to requests * * @param respType Response type (should correspond to request type somehow) * @param reqID Request ID object as present in the request * @param status Status of the operation, should be "ok" or "error" */ - public JsonEvtLoopStatusReport( String respType, JsonNode reqID, String status) { + public JsonEventLoopStatusReport( String respType, JsonNode reqID, String status) { this.respType = respType; this.reqID = reqID; this.status = status; } /** - * Creates new JsonEvtLoopStatusReport object to use for responding to requests + * Creates new JsonEventLoopStatusReport object to use for responding to requests * * @param respType Response type (should correspond to request type somehow) * @param reqID Request ID object as present in the request * @param status Status of the operation, should be "ok" or "error" * @param message Message explaining what went wrong in case of status="error" */ - public JsonEvtLoopStatusReport( String respType, JsonNode reqID, String status, String message) { + public JsonEventLoopStatusReport( String respType, JsonNode reqID, String status, String message) { this.respType = respType; this.reqID = reqID; this.status = status; @@ -82,9 +82,9 @@ public class JsonEvtLoopStatusReport { JsonNode n = mpr.valueToTree(this); System.out.println( mpr.writeValueAsString(n)); } catch( IllegalArgumentException e) { - System.err.println( "JsonEvtLoopStatusReport: ERROR: Failed to serialize object: " + e.toString()); + System.err.println( "JsonEventLoopStatusReport: ERROR: Failed to serialize object: " + e.toString()); } catch( JsonProcessingException e) { - System.err.println( "JsonEvtLoopStatusReport: ERROR: Failed to serialize object: " + e.toString()); + System.err.println( "JsonEventLoopStatusReport: ERROR: Failed to serialize object: " + e.toString()); } }