[OTR-dev] [PATCH 3/9] Generalise message_malformed() and rename it.

Andreas Schlick ninox+otr at posteo.net
Wed Oct 22 14:39:21 EDT 2014


---
 src/message.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/message.c b/src/message.c
index f17e5e1..1dff951 100644
--- a/src/message.c
+++ b/src/message.c
@@ -867,17 +867,16 @@ void otrl_message_abort_smp(OtrlUserState us, const OtrlMessageAppOps *ops,
     otrl_tlv_free(sendtlv);
 }
 
-static void message_malformed(const OtrlMessageAppOps *ops,
-	void *opdata, ConnContext *context) {
+static void report_error(const OtrlMessageAppOps *ops, void *opdata,
+                         OtrlMessageEvent ome, OtrlErrorCode oec,
+                         ConnContext *context) {
+
     if (ops->handle_msg_event) {
-	ops->handle_msg_event(opdata, OTRL_MSGEVENT_RCVDMSG_MALFORMED, context,
-	    NULL, gcry_error(GPG_ERR_NO_ERROR));
+        ops->handle_msg_event(opdata, ome, context, NULL, gcry_error(GPG_ERR_NO_ERROR));
     }
 
     if (ops->inject_message && ops->otr_error_message) {
-	const char *err_msg = ops->otr_error_message(opdata, context,
-		OTRL_ERRCODE_MSG_MALFORMED);
-
+        const char *err_msg = ops->otr_error_message(opdata, context, oec);
 	if (err_msg) {
 	    char *buf = malloc(strlen(OTR_ERROR_PREFIX) + strlen(err_msg) + 1);
 
@@ -1006,7 +1005,8 @@ int otrl_message_receiving(OtrlUserState us, const OtrlMessageAppOps *ops,
 			protocol, their_instance, 1, &context_added,
 			add_appdata, data);
 	    } else {
-		message_malformed(ops, opdata, context);
+            report_error(ops, opdata, OTRL_MSGEVENT_RCVDMSG_MALFORMED,
+                         OTRL_ERRCODE_MSG_MALFORMED, context);
 		return 1;
 	    }
 	}
@@ -1077,7 +1077,8 @@ int otrl_message_receiving(OtrlUserState us, const OtrlMessageAppOps *ops,
 	}
 
 	if (err || their_instance < OTRL_MIN_VALID_INSTAG) {
-	    message_malformed(ops, opdata, context);
+        report_error(ops, opdata, OTRL_MSGEVENT_RCVDMSG_MALFORMED,
+                     OTRL_ERRCODE_MSG_MALFORMED, context);
 	    edata.ignore_message = 1;
 	    goto end;
 	}
-- 
2.1.2



More information about the OTR-dev mailing list