Hello all,

While we were studying the libotr code and peeking through the project's
bugtracker we came across enhancement #112 [0].

With the attached patch we changed the correspnding code so that it will
optionally no longer contain any information about the senders username
in the query message.

The patch contains a change in the query message formatter, replacing
the username with "You have been requested to join". It also changes the
msg buffer's allocated size and removes the ourname variable from the
sprintf call. This changes apply if the ourname formal parameter is
passed a NULL value. Otherwise nothing changes and the original code is
executed unchanged.

Two formatters are now defined in the function
otrl_proto_default_query_msg, one for including the username and one for
omiting it. A pointer points to the appropriate formatter according to
the ourname value. Then memory for the msg buffer is allocated. If
ourname is not NULL nothing changes. If it is NULL then the memory
needed is the length of the formatter plus the version tag. We must
remove 2 bytes for the "%s" special symbol used in sprintf later and
then add 1 for the null character, which leaves a total of -1. After the
allocation of the needed memory we can simply call sprintf to actually
create the query message. Again by checking the if ourname has a valid
address we can decide if we should include it in the sprintf  call.

You can also find our patch in this github fork[1]

Kind regards,
Kostis Andrikopoulos
Dimitris Kolotouros

[0]: https://bugs.otr.im/issues/112
[1]: https://github.com/Mandragorian/libotr/tree/no_username
commit 180184ccb25fddb82a73792767bca4a54b81e8d3
Author: mandragore <gkonstandi...@gmail.com>
Date:   Wed Dec 9 17:43:26 2015 +0200

    Make sending username in query message optional

diff --git a/src/proto.c b/src/proto.c
index f560a82..70c5f8c 100644
--- a/src/proto.c
+++ b/src/proto.c
@@ -237,17 +237,34 @@ char *otrl_proto_default_query_msg(const char *ourname, OtrlPolicy policy)
     int v1_supported, v2_supported, v3_supported;
     char *version_tag;
     char *bufp;
+    char *format;
     /* Don't use g_strdup_printf here, because someone (not us) is going
      * to free() the *message pointer, not g_free() it.  We can't
      * require that they g_free() it, because this pointer will probably
      * get passed to the main IM application for processing (and
      * free()ing). */
-    const char *format = "?OTR%s\n<b>%s</b> has requested an "
+    const char *format_username = "?OTR%s\n<b>%s</b> has requested an "
 	    "<a href=\"https://otr.cypherpunks.ca/\";>Off-the-Record "
 	    "private conversation</a>.  However, you do not have a plugin "
 	    "to support that.\nSee <a href=\"https://otr.cypherpunks.ca/\";>"
 	    "https://otr.cypherpunks.ca/</a> for more information.";
 
+    const char *format_no_username = "?OTR%s\nYou have been requested to join an "
+	    "<a href=\"https://otr.cypherpunks.ca/\";>Off-the-Record "
+	    "private conversation</a>.  However, you do not have a plugin "
+	    "to support that.\nSee <a href=\"https://otr.cypherpunks.ca/\";>"
+	    "https://otr.cypherpunks.ca/</a> for more information.";
+
+    /* Check if the application provided a username
+     * and use the appropriate formatter*/
+    if(ourname) {
+	format = format_username;
+    }
+    else {
+	format = format_no_username;
+    }
+
+
     /* Figure out the version tag */
     v1_supported = (policy & OTRL_POLICY_ALLOW_V1);
     v2_supported = (policy & OTRL_POLICY_ALLOW_V2);
@@ -274,13 +291,27 @@ char *otrl_proto_default_query_msg(const char *ourname, OtrlPolicy policy)
     }
     *bufp = '\0';
 
-    /* Remove two "%s", add '\0' */
-    msg = malloc(strlen(format) + strlen(version_tag) + strlen(ourname) - 3);
+    if(ourname) {
+	/* Remove two "%s", add '\0' */
+        msg = malloc(strlen(format) + strlen(version_tag) + strlen(ourname) - 3);
+    }
+    else {
+	/* Remove one "%s", add '\0' */
+	msg = malloc(strlen(format) + strlen(version_tag) - 1);
+    }
+
     if (!msg) {
 	free(version_tag);
 	return NULL;
     }
-    sprintf(msg, format, version_tag, ourname);
+
+    if(ourname) {
+        sprintf(msg, format, version_tag, ourname);
+    }
+    else {
+	sprintf(msg, format, version_tag);
+    }
+
     free(version_tag);
     return msg;
 }
_______________________________________________
OTR-dev mailing list
OTR-dev@lists.cypherpunks.ca
http://lists.cypherpunks.ca/mailman/listinfo/otr-dev

Reply via email to