[2838] in BarnOwl Developers
Re: [PATCH] Build reply commands from scratch on outgoing zwrites
daemon@ATHENA.MIT.EDU (Nelson Elhage)
Tue Dec 28 18:39:38 2010
In-Reply-To: <1292398149-9937-2-git-send-email-davidben@mit.edu>
Date: Tue, 28 Dec 2010 18:39:36 -0500
From: Nelson Elhage <nelhage@nelhage.com>
To: David Benjamin <davidben@mit.edu>
Cc: barnowl-dev@mit.edu
I'd be inclined to just redefine "zwriteline", since I don't think a
zwriteline with -m's in it is going to do anyone good. Other than
that, lgtm.
- Nelson
On Wed, Dec 15, 2010 at 2:29 AM, David Benjamin <davidben@mit.edu> wrote:
> We currently reuse the original zwrite line which is problematic when
> the user passed -m. Instead regenerates the zwrite line from the
> parsed owl_zwrite.
> ---
> =C2=A0message.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 18 ++++++++++++++
> =C2=A0perl/lib/BarnOwl/Message/Zephyr.pm | =C2=A0 =C2=A02 +-
> =C2=A0zwrite.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A0 45 ++++++++++++++++++++++++++++=
++++++++
> =C2=A03 files changed, 64 insertions(+), 1 deletions(-)
>
> diff --git a/message.c b/message.c
> index 2ab9051..8aab470 100644
> --- a/message.c
> +++ b/message.c
> @@ -483,6 +483,18 @@ void owl_message_set_zwriteline(owl_message *m, cons=
t char *line)
> =C2=A0 owl_message_set_attribute(m, "zwriteline", line);
> =C2=A0}
>
> +const char *owl_message_get_replyline(const owl_message *m)
> +{
> + =C2=A0const char *z =3D owl_message_get_attribute_value(m, "replyline")=
;
> + =C2=A0if (!z) return "";
> + =C2=A0return z;
> +}
> +
> +void owl_message_set_replyline(owl_message *m, const char *line)
> +{
> + =C2=A0owl_message_set_attribute(m, "replyline", line);
> +}
> +
> =C2=A0int owl_message_is_delete(const owl_message *m)
> =C2=A0{
> =C2=A0 if (m =3D=3D NULL) return(0);
> @@ -963,6 +975,7 @@ void owl_message_create_from_zwrite(owl_message *m, c=
onst owl_zwrite *z, const c
> =C2=A0{
> =C2=A0 int ret;
> =C2=A0 char hostbuff[5000];
> + =C2=A0char *replyline;
>
> =C2=A0 owl_message_init(m);
>
> @@ -983,6 +996,11 @@ void owl_message_create_from_zwrite(owl_message *m, =
const owl_zwrite *z, const c
> =C2=A0 if(z->zwriteline) {
> =C2=A0 =C2=A0 owl_message_set_zwriteline(m, z->zwriteline);
> =C2=A0 }
> +
> + =C2=A0replyline =3D owl_zwrite_get_replyline(z);
> + =C2=A0owl_message_set_replyline(m, replyline);
> + =C2=A0owl_free(replyline);
> +
> =C2=A0 owl_message_set_body(m, body);
> =C2=A0 owl_message_set_zsig(m, owl_zwrite_get_zsig(z));
>
> diff --git a/perl/lib/BarnOwl/Message/Zephyr.pm b/perl/lib/BarnOwl/Messag=
e/Zephyr.pm
> index 83fabba..94a309d 100644
> --- a/perl/lib/BarnOwl/Message/Zephyr.pm
> +++ b/perl/lib/BarnOwl/Message/Zephyr.pm
> @@ -137,7 +137,7 @@ sub replycmd {
> =C2=A0 =C2=A0 $sender =3D 0 unless defined $sender;
> =C2=A0 =C2=A0 my ($class, $instance, $to, $cc);
> =C2=A0 =C2=A0 if($self->is_outgoing) {
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0return $self->{zwriteline};
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0return $self->{replyline};
> =C2=A0 =C2=A0 }
>
> =C2=A0 =C2=A0 if($sender && $self->opcode eq WEBZEPHYR_OPCODE) {
> diff --git a/zwrite.c b/zwrite.c
> index 3412ef8..7d7d480 100644
> --- a/zwrite.c
> +++ b/zwrite.c
> @@ -389,3 +389,48 @@ void owl_zwrite_cleanup(owl_zwrite *z)
> =C2=A0 if (z->message) owl_free(z->message);
> =C2=A0 if (z->zsig) owl_free(z->zsig);
> =C2=A0}
> +
> +/*
> + * Returns a zwrite line suitable for replying, specifically the
> + * message field is stripped out. Result should be freed with
> + * owl_free.
> + */
> +char *owl_zwrite_get_replyline(const owl_zwrite *z)
> +{
> + =C2=A0/* Match ordering in zwrite help. */
> + =C2=A0GString *buf =3D g_string_new("");
> + =C2=A0int i;
> +
> + =C2=A0/* Disturbingly, it is apparently possible to z->cmd to be null i=
f
> + =C2=A0 * owl_zwrite_create_from_line got something starting with -. And=
we
> + =C2=A0 * can't kill it because this is exported to perl. */
> + =C2=A0owl_string_append_quoted_arg(buf, z->cmd ? z->cmd : "zwrite");
> + =C2=A0if (z->noping) {
> + =C2=A0 =C2=A0g_string_append(buf, " -n");
> + =C2=A0}
> + =C2=A0if (z->cc) {
> + =C2=A0 =C2=A0g_string_append(buf, " -C");
> + =C2=A0}
> + =C2=A0if (strcmp(z->class, "message")) {
> + =C2=A0 =C2=A0g_string_append(buf, " -c ");
> + =C2=A0 =C2=A0owl_string_append_quoted_arg(buf, z->class);
> + =C2=A0}
> + =C2=A0if (strcmp(z->inst, "personal")) {
> + =C2=A0 =C2=A0g_string_append(buf, " -i ");
> + =C2=A0 =C2=A0owl_string_append_quoted_arg(buf, z->inst);
> + =C2=A0}
> + =C2=A0if (z->realm && z->realm[0] !=3D '\0') {
> + =C2=A0 =C2=A0g_string_append(buf, " -r ");
> + =C2=A0 =C2=A0owl_string_append_quoted_arg(buf, z->realm);
> + =C2=A0}
> + =C2=A0if (z->opcode && z->opcode[0] !=3D '\0') {
> + =C2=A0 =C2=A0g_string_append(buf, " -O ");
> + =C2=A0 =C2=A0owl_string_append_quoted_arg(buf, z->opcode);
> + =C2=A0}
> + =C2=A0for (i =3D 0; i < owl_list_get_size(&(z->recips)); i++) {
> + =C2=A0 =C2=A0g_string_append_c(buf, ' ');
> + =C2=A0 =C2=A0owl_string_append_quoted_arg(buf, owl_list_get_element(&(z=
->recips), i));
> + =C2=A0}
> +
> + =C2=A0return g_string_free(buf, FALSE);
> +}
> --
> 1.7.3.3.399.g06ddf
>
>