Bug 75581

Summary: [next] remove tp_message_peek()
Product: Telepathy Reporter: Guillaume Desmottes <guillaume.desmottes>
Component: tp-glibAssignee: Telepathy bugs list <telepathy-bugs>
Status: RESOLVED FIXED QA Contact: Telepathy bugs list <telepathy-bugs>
Severity: enhancement    
Priority: medium Keywords: patch
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard: r+
i915 platform: i915 features:
Bug Depends on:    
Bug Blocks: 75204    
Attachments: cm-message: use tp_cm_message_get_sender() internally
use tp_message_dup_part() instead of tp_message_peek()
message: change string getter to _dup_
logger: use tp_message_get_pending_message_id()
logger: use tp_message_dup_part()
echo-message-parts: use tp_message_dup_part()
stop using tp_message_peek() in tests
stop using tp_message_peek() internally
remove tp_message_peek()

Description Guillaume Desmottes 2014-02-27 16:50:51 UTC
Part of the "Get rid of TpAsv API" quest.
Comment 1 Guillaume Desmottes 2014-02-27 16:51:52 UTC
Created attachment 94837 [details] [review]
cm-message: use tp_cm_message_get_sender() internally
Comment 2 Guillaume Desmottes 2014-02-27 16:52:05 UTC
Created attachment 94838 [details] [review]
use tp_message_dup_part() instead of tp_message_peek()
Comment 3 Guillaume Desmottes 2014-02-27 16:52:19 UTC
Created attachment 94839 [details] [review]
message: change string getter to _dup_
Comment 4 Guillaume Desmottes 2014-02-27 16:52:43 UTC
Created attachment 94840 [details] [review]
logger: use tp_message_get_pending_message_id()
Comment 5 Guillaume Desmottes 2014-02-27 16:52:55 UTC
Created attachment 94841 [details] [review]
logger: use tp_message_dup_part()
Comment 6 Guillaume Desmottes 2014-02-27 16:53:09 UTC
Created attachment 94842 [details] [review]
echo-message-parts: use tp_message_dup_part()
Comment 7 Guillaume Desmottes 2014-02-27 16:53:22 UTC
Created attachment 94843 [details] [review]
stop using tp_message_peek() in tests
Comment 8 Guillaume Desmottes 2014-02-27 16:53:34 UTC
Created attachment 94844 [details] [review]
stop using tp_message_peek() internally
Comment 9 Guillaume Desmottes 2014-02-27 16:53:48 UTC
Created attachment 94845 [details] [review]
remove tp_message_peek()
Comment 10 Simon McVittie 2014-02-28 16:24:37 UTC
Comment on attachment 94838 [details] [review]
use tp_message_dup_part() instead of tp_message_peek()

Review of attachment 94838 [details] [review]:
-----------------------------------------------------------------

::: telepathy-glib/cm-message.c
@@ +307,4 @@
>    g_return_val_if_fail (TP_IS_CM_MESSAGE (self), 0);
> +
> +  header = tp_message_dup_part (self, 0);
> +  g_variant_lookup (header, "message-sender", "u", &sender);

Either

if (!g_variant_lookup (...))
  sender = 0;

or pre-initialize it. Otherwise we'll return undefined stack contents if there is a message-sender but its type is wrong.
Comment 11 Simon McVittie 2014-02-28 16:28:10 UTC
Comment on attachment 94839 [details] [review]
message: change string getter to _dup_

Review of attachment 94839 [details] [review]:
-----------------------------------------------------------------

::: telepathy-logger/text-channel.c
@@ +259,5 @@
>          tpl_entity_get_identifier (sender));
>  
>  
> +  token = tp_message_dup_token (message);
> +  supersedes = tp_message_dup_supersedes (message);

Inline get_message_edit_timestamp here, maybe? (Non-blocker)

@@ +277,5 @@
>        "message-type", type,
>        "message", text,
>        NULL);
>  
> +  g_free (token);

Is supersedes leaked?
Comment 12 Simon McVittie 2014-02-28 16:28:56 UTC
Comment on attachment 94840 [details] [review]
logger: use tp_message_get_pending_message_id()

Review of attachment 94840 [details] [review]:
-----------------------------------------------------------------

Would be good to cherry-pick to logger master, maybe.
Comment 13 Simon McVittie 2014-02-28 16:33:32 UTC
Comment on attachment 94842 [details] [review]
echo-message-parts: use tp_message_dup_part()

Review of attachment 94842 [details] [review]:
-----------------------------------------------------------------

::: examples/cm/echo-message-parts/chan.c
@@ +158,5 @@
>        if (s != NULL)
>          tp_message_set_string (received, j, "lang", s);
>  
> +      value = g_variant_dict_lookup_value (&dict, "content",
> +          G_VARIANT_TYPE_STRING);

Nitpicking: this doesn't copy binary content (it can either be an 's' or an 'ay'; iirc the latter was originally to support vCard over MMS, which sends a binary blob of unspecified encoding, containing embedded charset tags analogous to HTML <meta name="charset">).

I think that's fine for example code, though.
Comment 14 Simon McVittie 2014-02-28 16:36:48 UTC
Comment on attachment 94843 [details] [review]
stop using tp_message_peek() in tests

Review of attachment 94843 [details] [review]:
-----------------------------------------------------------------

::: tests/dbus/cm-message.c
@@ +53,5 @@
>    GVariant *part_vardict;
>    gboolean valid;
>    const gchar *s;
>    gchar *token;
> +  guint u;

Should be specifically guint32, I think? (Although this is going to be the least of your worries if your platform has non-32-bit ints.)
Comment 15 Guillaume Desmottes 2014-03-03 10:57:49 UTC
(In reply to comment #12)
> Comment on attachment 94840 [details] [review] [review]
> logger: use tp_message_get_pending_message_id()
> 
> Review of attachment 94840 [details] [review] [review]:
> -----------------------------------------------------------------
> 
> Would be good to cherry-pick to logger master, maybe.

done.
Comment 16 Guillaume Desmottes 2014-03-03 11:02:51 UTC
Comment on attachment 94838 [details] [review]
use tp_message_dup_part() instead of tp_message_peek()

Review of attachment 94838 [details] [review]:
-----------------------------------------------------------------

::: telepathy-glib/cm-message.c
@@ +307,4 @@
>    g_return_val_if_fail (TP_IS_CM_MESSAGE (self), 0);
> +
> +  header = tp_message_dup_part (self, 0);
> +  g_variant_lookup (header, "message-sender", "u", &sender);

Done.
Comment 17 Guillaume Desmottes 2014-03-03 11:05:59 UTC
Comment on attachment 94839 [details] [review]
message: change string getter to _dup_

Review of attachment 94839 [details] [review]:
-----------------------------------------------------------------

::: telepathy-logger/text-channel.c
@@ +259,5 @@
>          tpl_entity_get_identifier (sender));
>  
>  
> +  token = tp_message_dup_token (message);
> +  supersedes = tp_message_dup_supersedes (message);

done.

@@ +277,5 @@
>        "message-type", type,
>        "message", text,
>        NULL);
>  
> +  g_free (token);

fixed.
Comment 18 Guillaume Desmottes 2014-03-03 11:11:20 UTC
Comment on attachment 94843 [details] [review]
stop using tp_message_peek() in tests

Review of attachment 94843 [details] [review]:
-----------------------------------------------------------------

::: tests/dbus/cm-message.c
@@ +53,5 @@
>    GVariant *part_vardict;
>    gboolean valid;
>    const gchar *s;
>    gchar *token;
> +  guint u;

Fixed.

I pushed the !fixup to http://cgit.collabora.com/git/user/cassidy/telepathy-glib/log/?h=next-message-75581
Comment 19 Simon McVittie 2014-03-03 19:01:31 UTC
(In reply to comment #11)
> > +  token = tp_message_dup_token (message);
> > +  supersedes = tp_message_dup_supersedes (message);
> 
> Inline get_message_edit_timestamp here, maybe? (Non-blocker)

Sorry, I was unclear.

What I meant was that get_message_edit_timestamp() calls tp_message_dup_supersedes():

 get_message_edit_timestamp (TpMessage *message)
{
- if (tp_message_get_supersedes (message) != NULL)
- return get_network_timestamp (message);
+ gchar *supersedes;
+
+ supersedes = tp_message_dup_supersedes (message);
+ if (supersedes != NULL)
+ {
+ g_free (supersedes);
+ return get_network_timestamp (message);
+ }
else
- return 0;
+ {
+ return 0;
+ }
}

(sorry for the indentation damage, cgit is being invaluable)

and so you could save a malloc/free if you inlined get_message_edit_timestamp into its caller, which already needs to call tp_message_get_supersedes() anyway.

OTOH, if there are other callers, that's more annoying.
Comment 20 Simon McVittie 2014-03-03 19:02:34 UTC
(In reply to comment #11)
> ::: telepathy-logger/text-channel.c
> @@ +277,5 @@
> > +  g_free (token);
> 
> Is supersedes leaked?

I don't see a fix for that?
Comment 21 Simon McVittie 2014-03-03 19:03:45 UTC
(In reply to comment #20)
> I don't see a fix for that?

... because I wasn't looking hard enough. Yes, sorry, you did fix it.
Comment 22 Guillaume Desmottes 2014-03-06 09:42:18 UTC
(In reply to comment #19)
> (In reply to comment #11)
> > > +  token = tp_message_dup_token (message);
> > > +  supersedes = tp_message_dup_supersedes (message);
> > 
> > Inline get_message_edit_timestamp here, maybe? (Non-blocker)
> 
> Sorry, I was unclear.
> 
> What I meant was that get_message_edit_timestamp() calls
> tp_message_dup_supersedes():
> 
>  get_message_edit_timestamp (TpMessage *message)
> {
> - if (tp_message_get_supersedes (message) != NULL)
> - return get_network_timestamp (message);
> + gchar *supersedes;
> +
> + supersedes = tp_message_dup_supersedes (message);
> + if (supersedes != NULL)
> + {
> + g_free (supersedes);
> + return get_network_timestamp (message);
> + }
> else
> - return 0;
> + {
> + return 0;
> + }
> }
> 
> (sorry for the indentation damage, cgit is being invaluable)
> 
> and so you could save a malloc/free if you inlined
> get_message_edit_timestamp into its caller, which already needs to call
> tp_message_get_supersedes() anyway.
> 
> OTOH, if there are other callers, that's more annoying.

Done in the top commit of http://cgit.collabora.com/git/user/cassidy/telepathy-glib/log/?h=next-message-75581
Comment 23 Simon McVittie 2014-03-06 12:10:44 UTC
Great. Ship it!
Comment 24 Guillaume Desmottes 2014-03-06 12:20:36 UTC
Merged; thanks!

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.