Bug 34796 - Implement ContactInfo
Summary: Implement ContactInfo
Status: RESOLVED FIXED
Alias: None
Product: Telepathy
Classification: Unclassified
Component: idle (show other bugs)
Version: git master
Hardware: All All
: medium enhancement
Assignee: Telepathy bugs list
QA Contact: Telepathy bugs list
URL:
Whiteboard: review+ after a small change
Keywords: patch
Depends on:
Blocks:
 
Reported: 2011-02-27 08:55 UTC by Debarshi Ray
Modified: 2011-05-11 12:51 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
Initial patch (12.95 KB, patch)
2011-02-27 08:59 UTC, Debarshi Ray
Details | Splinter Review
Second iteration of earlier patch (13.95 KB, patch)
2011-02-27 15:52 UTC, Debarshi Ray
Details | Splinter Review
Third iteration of earlier patch (15.89 KB, patch)
2011-02-28 06:20 UTC, Debarshi Ray
Details | Splinter Review
Fourth iteration of earlier patch (18.21 KB, patch)
2011-03-02 17:04 UTC, Debarshi Ray
Details | Splinter Review
Fifth iteration of the earlier patch (18.34 KB, patch)
2011-03-03 06:12 UTC, Debarshi Ray
Details | Splinter Review
Handle ERR_NOSUCHSERVER (4.45 KB, patch)
2011-03-03 06:13 UTC, Debarshi Ray
Details | Splinter Review
Handle RPL_WHOISCHANNELS messages in response to RequestContactInfo (5.53 KB, patch)
2011-03-17 19:14 UTC, Debarshi Ray
Details | Splinter Review
Handle RPL_WHOISLOGGEDIN messages in response to RequestContactInfo (3.61 KB, patch)
2011-03-18 09:59 UTC, Debarshi Ray
Details | Splinter Review
Fix the RPL_WHOISCHANNELS patch (3.37 KB, patch)
2011-03-18 17:58 UTC, Debarshi Ray
Details | Splinter Review
Implement ContactInfo (16.49 KB, patch)
2011-03-21 15:37 UTC, Debarshi Ray
Details | Splinter Review
Handle ERR_NOSUCHSERVER (4.48 KB, patch)
2011-03-21 15:48 UTC, Debarshi Ray
Details | Splinter Review
Implement ContactInfo (16.59 KB, patch)
2011-03-29 14:12 UTC, Debarshi Ray
Details | Splinter Review
Handle RPL_WHOISSERVER messages in response to RequestContactInfo (3.52 KB, patch)
2011-04-23 03:42 UTC, Debarshi Ray
Details | Splinter Review
Handle RPL_TRYAGAIN messages in response to RequestContactInfo (3.78 KB, patch)
2011-04-25 13:21 UTC, Debarshi Ray
Details | Splinter Review
Handle WHOIS messages in our test IRC server (3.95 KB, patch)
2011-04-25 13:21 UTC, Debarshi Ray
Details | Splinter Review
constants.py: add SERVICE_BUSY (856 bytes, patch)
2011-04-25 13:22 UTC, Debarshi Ray
Details | Splinter Review
Test to cover RequestContactInfo (3.46 KB, patch)
2011-04-25 13:23 UTC, Debarshi Ray
Details | Splinter Review
Handle RPL_WHOISSERVER messages in response to RequestContactInfo (3.44 KB, patch)
2011-04-29 09:54 UTC, Debarshi Ray
Details | Splinter Review
Handle RPL_TRYAGAIN messages in response to RequestContactInfo (3.77 KB, patch)
2011-04-29 09:55 UTC, Debarshi Ray
Details | Splinter Review
Test to cover RequestContactInfo (3.70 KB, patch)
2011-04-29 09:58 UTC, Debarshi Ray
Details | Splinter Review
Handle WHOIS messages in our test IRC server (3.94 KB, patch)
2011-05-02 04:47 UTC, Debarshi Ray
Details | Splinter Review
Handle RPL_WHOISHOST messages in response to RequestContactInfo (3.92 KB, patch)
2011-05-05 16:11 UTC, Debarshi Ray
Details | Splinter Review
idletest: return an empty RPL_WHOISCHANNELS in response to WHOIS (1.54 KB, patch)
2011-05-05 16:12 UTC, Debarshi Ray
Details | Splinter Review
Handle empty RPL_WHOISCHANNELS in response to RequestContactInfo (1.10 KB, patch)
2011-05-05 16:13 UTC, Debarshi Ray
Details | Splinter Review
Handle RPL_WHOISHOST messages in response to RequestContactInfo (4.52 KB, patch)
2011-05-06 11:31 UTC, Debarshi Ray
Details | Splinter Review
Try not to mistake RPL_WHOWAS_TIME as RPL_WHOISLOGGEDIN (1.53 KB, patch)
2011-05-06 11:59 UTC, Debarshi Ray
Details | Splinter Review
Reduce boilerplate (9.67 KB, patch)
2011-05-09 12:28 UTC, Debarshi Ray
Details | Splinter Review
Handle RPL_WHOISREGNICK messages in response to RequestContactInfo (4.49 KB, patch)
2011-05-10 01:52 UTC, Debarshi Ray
Details | Splinter Review
Handle RPL_WHOISOPERATOR messages in response to RequestContactInfo (4.17 KB, patch)
2011-05-10 01:52 UTC, Debarshi Ray
Details | Splinter Review
Handle RPL_WHOISSECURE messages in response to RequestContactInfo (4.41 KB, patch)
2011-05-10 01:53 UTC, Debarshi Ray
Details | Splinter Review
Put the role played by the target nick in a channel as vCard parameter (1.92 KB, patch)
2011-05-11 10:31 UTC, Debarshi Ray
Details | Splinter Review
contactinfo-request.py: check the x-irc-server and x-host fields (1.15 KB, patch)
2011-05-11 11:09 UTC, Debarshi Ray
Details | Splinter Review
Add idle_muc_channel_is_typechar as per RFC 2811 (1.67 KB, patch)
2011-05-11 11:10 UTC, Debarshi Ray
Details | Splinter Review
Use idle_muc_channel_is_typechar (1.12 KB, patch)
2011-05-11 11:10 UTC, Debarshi Ray
Details | Splinter Review
Put the role played by the target nick in a channel as vCard parameter (1.50 KB, patch)
2011-05-11 11:11 UTC, Debarshi Ray
Details | Splinter Review

Description Debarshi Ray 2011-02-27 08:55:18 UTC
Implement ContactInfo in Idle.
Comment 1 Debarshi Ray 2011-02-27 08:59:58 UTC
Created attachment 43889 [details] [review]
Initial patch
Comment 2 Debarshi Ray 2011-02-27 15:52:01 UTC
Created attachment 43906 [details] [review]
Second iteration of earlier patch

+ Fixes a build failure due to a last minute change in the earlier patch.

+ Instead of directly returning from a IDLE_PARSER_NUMERIC_WHOISUSER message, it
waits for a IDLE_PARSER_NUMERIC_ENDOFWHOIS message. That way it would be possible to return more information than just what is available in a IDLE_PARSER_NUMERIC_WHOISUSER message.
Comment 3 Will Thompson 2011-02-28 04:11:34 UTC
Review of attachment 43906 [details] [review]:

Great! One functional issue, and a few nitpicks:

::: src/idle-connection.c
@@ +77,3 @@
 G_DEFINE_TYPE_WITH_CODE(IdleConnection, idle_connection, TP_TYPE_BASE_CONNECTION,
 		G_IMPLEMENT_INTERFACE(TP_TYPE_SVC_CONNECTION_INTERFACE_ALIASING, _aliasing_iface_init);
+		G_IMPLEMENT_INTERFACE(TP_TYPE_SVC_CONNECTION_INTERFACE_CONTACT_INFO, idle_contact_info_iface_init);

I think you also want to add TP_IFACE_CONNECTION_INTERFACE_CONTACT_INFO to interfaces_always_present later in the file. This will make it appear in the Connection's Interfaces property <http://telepathy.freedesktop.org/spec/Connection.html#Property:Interfaces> which the client-side bindings use to determine whether or not an interface is implemented. Without this, clients may not realise that they can use these methods.

::: src/idle-contact-info.c
@@ +48,3 @@
+ */
+static void _insert_contact_field(GPtrArray *contact_info, const gchar *field_name, const gchar * const *field_params, const gchar * const *field_values) {
+	gchar *field_name_down = g_ascii_strdown (field_name, -1);

Nitpick: given that we only ever pass strings provided by Idle itself as 'field_name', can't we just assume they're lower-case (or else the code calling _insert_contact_field is buggy)?

@@ +108,3 @@
+
+	tp_svc_connection_interface_contact_info_return_from_refresh_contact_info(context);
+}

You could just omit the stub implementations of GetContactInfo, RefreshContactInfo and SetContactInfo entirely: tp-glib would fall back to returning a NotImplemented error.

@@ +178,3 @@
+		g_error_free(error);
+		return;
+	}

If tp_handle_is_valid said that 'contact' was valid, tp_handle_inspect() on it will always return non-NULL.

::: src/idle-contact-info.h
@@ +35,3 @@
+extern TpDBusPropertiesMixinPropImpl *idle_contact_info_properties;
+void idle_contact_info_properties_getter (GObject *object, GQuark interface,
+    GQuark name, GValue *value, gpointer getter_data);

Looks like you didn't actually implement the two properties: <http://telepathy.freedesktop.org/spec/Connection_Interface_Contact_Info.html#properties>. But since their values would be '0' and '[]' anyway, this doesn't seem like a big deal. :)
Comment 4 Debarshi Ray 2011-02-28 06:17:49 UTC
(In reply to comment #3)
> Review of attachment 43906 [details] [review]:
> 
> Great! One functional issue, and a few nitpicks:
> 
> ::: src/idle-connection.c
> @@ +77,3 @@
>  G_DEFINE_TYPE_WITH_CODE(IdleConnection, idle_connection,
> TP_TYPE_BASE_CONNECTION,
>          G_IMPLEMENT_INTERFACE(TP_TYPE_SVC_CONNECTION_INTERFACE_ALIASING,
> _aliasing_iface_init);
> +        G_IMPLEMENT_INTERFACE(TP_TYPE_SVC_CONNECTION_INTERFACE_CONTACT_INFO,
> idle_contact_info_iface_init);
> 
> I think you also want to add TP_IFACE_CONNECTION_INTERFACE_CONTACT_INFO to
> interfaces_always_present later in the file.

Done.

> ::: src/idle-contact-info.c
> @@ +48,3 @@
> + */
> +static void _insert_contact_field(GPtrArray *contact_info, const gchar
> *field_name, const gchar * const *field_params, const gchar * const
> *field_values) {
> +    gchar *field_name_down = g_ascii_strdown (field_name, -1);
> 
> Nitpick: given that we only ever pass strings provided by Idle itself as
> 'field_name', can't we just assume they're lower-case (or else the code calling
> _insert_contact_field is buggy)?

You are right. I had thought about it too. Thing is that I copied the function and the comments above it verbatim from telepathy-gabble. Apart from some style fixes I did not change the code to avoid fragmented copies of the same code. But I have no strong opinion about this. :-)
 
> @@ +108,3 @@
> +
> +   
> tp_svc_connection_interface_contact_info_return_from_refresh_contact_info(context);
> +}
> 
> You could just omit the stub implementations of GetContactInfo,
> RefreshContactInfo and SetContactInfo entirely: tp-glib would fall back to
> returning a NotImplemented error.

I intend to implement those methods. :-)
 
> @@ +178,3 @@
> +        g_error_free(error);
> +        return;
> +    }
> 
> If tp_handle_is_valid said that 'contact' was valid, tp_handle_inspect() on it
> will always return non-NULL.

Done.
 
> ::: src/idle-contact-info.h
> @@ +35,3 @@
> +extern TpDBusPropertiesMixinPropImpl *idle_contact_info_properties;
> +void idle_contact_info_properties_getter (GObject *object, GQuark interface,
> +    GQuark name, GValue *value, gpointer getter_data);
> 
> Looks like you didn't actually implement the two properties:

Ok. I will look into this.
Comment 5 Debarshi Ray 2011-02-28 06:20:23 UTC
Created attachment 43927 [details] [review]
Third iteration of earlier patch

+ It addresses some of the issues raised in the earlier review.

+ RequestContactInfo returns the away message and idle time in addition to the real name. x-irc-away and x-irc-idle are used as the vcard field names.
Comment 6 Debarshi Ray 2011-03-02 17:04:55 UTC
Created attachment 44043 [details] [review]
Fourth iteration of earlier patch

+ Implemented the properties: ContactInfoFlags, SupportedFields

+ x-presence-type, x-presence-status-identifier, x-presence-status-message are used in a manner analogous to http://telepathy.freedesktop.org/spec/Connection_Interface_Simple_Presence.html

+ Worked around a GIMPNet "bug" where the away is status of a nick that is not connected to the same server as you is only returned when "WHOIS foo foo" is issued. "WHOIS foo" does not return the away status if both are not on the same server.
Comment 7 Debarshi Ray 2011-03-03 06:12:04 UTC
Created attachment 44074 [details] [review]
Fifth iteration of the earlier patch

This is a minor improvement to basically ensure that _return_from_request_contact_info is called only if there is a valid request->contact_info. The NULL pointer check is now done in _end_whois_handler.
Comment 8 Debarshi Ray 2011-03-03 06:13:15 UTC
Created attachment 44075 [details] [review]
Handle ERR_NOSUCHSERVER
Comment 9 Debarshi Ray 2011-03-17 19:14:42 UTC
Created attachment 44566 [details] [review]
Handle RPL_WHOISCHANNELS messages in response to RequestContactInfo

RFC 2812 (http://tools.ietf.org/html/rfc2812#section-5.1) defines RPL_WHOISCHANNELS as:
"<nick> :*( ( "@" / "+" ) <channel> " " )"

Preliminary testing (IRCNet and GIMPNet) suggests that it is actually:
"<nick> :1*( ( "@" / "+" ) <channel> " " )"

To maintain strict compliance with the RFC I defined the format as IIIc., but I am not sure if anything strange might happen if we get a "blank" RPL_WHOISCHANNELS from some server.

Also, how will g_strsplit behave with Unicode? Channels can have non-ASCII even though the RFC (http://tools.ietf.org/html/rfc2812#section-2.3.1) does not seem to explicitly say so.
Comment 10 Debarshi Ray 2011-03-18 09:59:20 UTC
Created attachment 44584 [details] [review]
Handle RPL_WHOISLOGGEDIN messages in response to RequestContactInfo
Comment 11 Debarshi Ray 2011-03-18 17:58:43 UTC
Created attachment 44601 [details] [review]
Fix the RPL_WHOISCHANNELS patch

Instead of:
["x-irc-channels"], [], ["#telepathy", "#freenode"]
do:
["x-irc-channel"], [], ["#telepathy"]
["x-irc-channel"], [], ["#freenode"]
Comment 12 Will Thompson 2011-03-21 08:18:35 UTC
Review of attachment 44074 [details] [review]:

::: src/idle-contact-info.c
@@ +49,3 @@
+ */
+static void _insert_contact_field(GPtrArray *contact_info, const gchar *field_name, const gchar * const *field_params, const gchar * const *field_values) {
+	gchar *field_name_down = g_ascii_strdown (field_name, -1);

I'd still just use field_name directly, and make sure nothing passes uppercase strings to this function (as nothing does, so that's fine).

@@ +136,3 @@
+	ContactInfoRequest *request;
+
+	request = g_new0(ContactInfoRequest, 1);

As a general rule, when allocating fixed-sized structs use g_slice_new0() and g_slice_free(). (Obviously this code is not performance-critical! ☺)

@@ +181,3 @@
+	TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED(TP_BASE_CONNECTION(iface), context);
+	tp_svc_connection_interface_contact_info_return_from_set_contact_info(context);
+}

Just leave SetContactInfo entirely unimplemented. Then telepathy-glib will return a NotImplemented error on your behalf.

@@ +292,3 @@
+		g_value_set_static_boxed(value, getter_data);
+	else
+		g_value_set_uint(value, GPOINTER_TO_UINT(getter_data));

Does NULL really work as SupportedFields? It's meant to be a GPtrArray of GValues, and part of me would expect dbus-glib to crash if you use NULL instead.

(It took me a few moments to figure this out; maybe it would be clearer to define the values in this function, rather than stashing them in getter_data and casting it.)
Comment 13 Will Thompson 2011-03-21 09:11:11 UTC
Review of attachment 44075 [details] [review]:

Looks mostly good.

::: src/idle-contact-info.c
@@ +269,3 @@
+	g_value_array_prepend(norm_args, &value);
+
+	 * caused by us, and we do not want to handle it.

These contortions make it look like _is_valid_response() should be changed to take a TpHandle as the second argument, rather than having to fake up a GValueArray which it just grabs the first element of.

@@ +274,3 @@
+	request = g_queue_peek_head(conn->contact_info_requests);
+
+	 * To check this we map the value of the <server name> to a handle and see if it matches the handle for which we had made the request.

The fact that the error is “no such server” is an IRC protocol oddity, and I imagine this will confuse people reading dbus-monitor! Maybe the message could be something like “User '%s' unknown; they may have disconnected”?
Comment 14 Will Thompson 2011-03-21 09:13:41 UTC
Review of attachment 44584 [details] [review]:

Looks good.
Comment 15 Will Thompson 2011-03-21 09:41:46 UTC
Review of attachment 44601 [details] [review]:

Looks good.
Comment 16 Debarshi Ray 2011-03-21 15:36:49 UTC
(In reply to comment #12)
> Review of attachment 44074 [details] [review]:
> 
> ::: src/idle-contact-info.c
> @@ +49,3 @@
> + */
> +static void _insert_contact_field(GPtrArray *contact_info, const gchar
> *field_name, const gchar * const *field_params, const gchar * const
> *field_values) {
> +    gchar *field_name_down = g_ascii_strdown (field_name, -1);
> 
> I'd still just use field_name directly, and make sure nothing passes uppercase
> strings to this function (as nothing does, so that's fine).

Done.

> @@ +136,3 @@
> +    ContactInfoRequest *request;
> +
> +    request = g_new0(ContactInfoRequest, 1);
> 
> As a general rule, when allocating fixed-sized structs use g_slice_new0() and
> g_slice_free(). (Obviously this code is not performance-critical! ☺)

Done.

> @@ +181,3 @@
> +    TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED(TP_BASE_CONNECTION(iface),
> context);
> +   
> tp_svc_connection_interface_contact_info_return_from_set_contact_info(context);
> +}
> 
> Just leave SetContactInfo entirely unimplemented. Then telepathy-glib will
> return a NotImplemented error on your behalf.

Done. Also removed the GetContactInfo, RefreshContactInfo stubs.

> @@ +292,3 @@
> +        g_value_set_static_boxed(value, getter_data);
> +    else
> +        g_value_set_uint(value, GPOINTER_TO_UINT(getter_data));
> 
> Does NULL really work as SupportedFields? It's meant to be a GPtrArray of
> GValues, and part of me would expect dbus-glib to crash if you use NULL
> instead.
> 
> (It took me a few moments to figure this out; maybe it would be clearer to
> define the values in this function, rather than stashing them in getter_data
> and casting it.)

I am a bit clueless about properties and was just imitating Gabble code. I will try to look at it more closely.
Comment 17 Debarshi Ray 2011-03-21 15:37:59 UTC
Created attachment 44695 [details] [review]
Implement ContactInfo
Comment 18 Debarshi Ray 2011-03-21 15:47:00 UTC
(In reply to comment #13)
> Review of attachment 44075 [details] [review]:

> ::: src/idle-contact-info.c
> @@ +269,3 @@
> +    g_value_array_prepend(norm_args, &value);
> +
> +     * caused by us, and we do not want to handle it.
> 
> These contortions make it look like _is_valid_response() should be changed to
> take a TpHandle as the second argument, rather than having to fake up a
> GValueArray which it just grabs the first element of.

That is true. I never thought about it.

On the other hand, this ERR_NOSUCHSERVER is an exception in the sense that all the other numeric replies to a WHOIS will have a handle as the first element. So by passing the whole GValueArray we can avoid having the following statement repeated in all the handlers:
    TpHandle handle = g_value_get_uint(g_value_array_get_nth(args, 0));

Having said that, even now the following snippet is repeated in almost every handler:
    request = g_queue_peek_head(conn->contact_info_requests);

    if (request->contact_info == NULL)
        request->contact_info = dbus_g_type_specialized_construct(TP_ARRAY_TYPE_CONTACT_INFO_FIELD_LIST);

I have no preferences. :-)

> @@ +274,3 @@
> +    request = g_queue_peek_head(conn->contact_info_requests);
> +
> +     * To check this we map the value of the <server name> to a handle and see
> if it matches the handle for which we had made the request.
> 
> The fact that the error is “no such server” is an IRC protocol oddity, and I
> imagine this will confuse people reading dbus-monitor! Maybe the message could
> be something like “User '%s' unknown; they may have disconnected”?

Done.
Comment 19 Debarshi Ray 2011-03-21 15:48:10 UTC
Created attachment 44696 [details] [review]
Handle ERR_NOSUCHSERVER
Comment 20 Debarshi Ray 2011-03-29 14:11:24 UTC
(In reply to comment #16)
> (In reply to comment #12)
> > Review of attachment 44074 [details] [review] [details]:
> > @@ +292,3 @@
> > +        g_value_set_static_boxed(value, getter_data);
> > +    else
> > +        g_value_set_uint(value, GPOINTER_TO_UINT(getter_data));
> > 
> > Does NULL really work as SupportedFields? It's meant to be a GPtrArray of
> > GValues, and part of me would expect dbus-glib to crash if you use NULL
> > instead.
> > 
> > (It took me a few moments to figure this out; maybe it would be clearer to
> > define the values in this function, rather than stashing them in getter_data
> > and casting it.)
 
> I am a bit clueless about properties and was just imitating Gabble code. I will
> try to look at it more closely.

I have fixed it now to return an empty GPtrArray.

I have also taken this opportunity to not use the 'getter_data' field, and just directly return the value of the property. Makes the code a bit easier to read in my opinion.
Comment 21 Debarshi Ray 2011-03-29 14:12:59 UTC
Created attachment 45013 [details] [review]
Implement ContactInfo
Comment 22 Will Thompson 2011-04-11 08:48:43 UTC
(In reply to comment #18)
> On the other hand, this ERR_NOSUCHSERVER is an exception in the sense that all
> the other numeric replies to a WHOIS will have a handle as the first element.
> So by passing the whole GValueArray we can avoid having the following statement
> repeated in all the handlers:
>     TpHandle handle = g_value_get_uint(g_value_array_get_nth(args, 0));

You're right; I think faking up the GValueArray is arguably neater. :)

I've merged these four patches: <http://cgit.freedesktop.org/telepathy/telepathy-idle/log/?id=5c3672d0d66eb9f51ef1c86d287d637b5d9f69d9>.

As discussed on IRC, it would be good to handle RPL_TRYAGAIN by returning an error (such as ServiceBusy) from RequestContactInfo.
Comment 23 Debarshi Ray 2011-04-23 03:42:45 UTC
Created attachment 45989 [details] [review]
Handle RPL_WHOISSERVER messages in response to RequestContactInfo

I don't know if x-irc-server[-info] is the best name for the vCard field or not.
Comment 24 Debarshi Ray 2011-04-25 01:10:03 UTC
(In reply to comment #23)
> Created an attachment (id=45989) [details]
> Handle RPL_WHOISSERVER messages in response to RequestContactInfo
> 
> I don't know if x-irc-server[-info] is the best name for the vCard field or
> not.

Or maybe we should do:
['x-irc-server'], [], ['lindbohm.freenode.net', 'Stockholm, Sweden'], or
['x-irc-whoisserver'], [], ['lindbohm.freenode.net', 'Stockholm, Sweden'], instead of
['x-irc-server'], [], ['lindbohm.freenode.net', and
['x-irc-server-info'], [], ['Stockholm, Sweden']

What do you say?
Comment 25 Olli Salli 2011-04-25 01:12:26 UTC
(In reply to comment #24)
> (In reply to comment #23)
> > Created an attachment (id=45989) [details] [details]
> > Handle RPL_WHOISSERVER messages in response to RequestContactInfo
> > 
> > I don't know if x-irc-server[-info] is the best name for the vCard field or
> > not.
> 
> Or maybe we should do:
> ['x-irc-server'], [], ['lindbohm.freenode.net', 'Stockholm, Sweden'], or

> What do you say?

This would get my vote.
Comment 26 Debarshi Ray 2011-04-25 13:21:15 UTC
Created attachment 46064 [details] [review]
Handle RPL_TRYAGAIN messages in response to RequestContactInfo
Comment 27 Debarshi Ray 2011-04-25 13:21:49 UTC
Created attachment 46065 [details] [review]
Handle WHOIS messages in our test IRC server
Comment 28 Debarshi Ray 2011-04-25 13:22:26 UTC
Created attachment 46066 [details] [review]
constants.py: add SERVICE_BUSY
Comment 29 Debarshi Ray 2011-04-25 13:23:19 UTC
Created attachment 46067 [details] [review]
Test to cover RequestContactInfo
Comment 30 Will Thompson 2011-04-28 03:35:39 UTC
(In reply to comment #25)
> (In reply to comment #24)
> > (In reply to comment #23)
> > > Created an attachment (id=45989) [details] [details] [details]
> > > Handle RPL_WHOISSERVER messages in response to RequestContactInfo
> > > 
> > > I don't know if x-irc-server[-info] is the best name for the vCard field or
> > > not.
> > 
> > Or maybe we should do:
> > ['x-irc-server'], [], ['lindbohm.freenode.net', 'Stockholm, Sweden'], or
> 
> > What do you say?
> 
> This would get my vote.

Sounds good.
Comment 31 Will Thompson 2011-04-29 05:33:32 UTC
Review of attachment 46064 [details] [review]:

Looks functionally fine, though I have a couple of nitpicks :)

::: src/idle-contact-info.c
@@ +256,3 @@
+	command = g_ascii_strup(g_value_get_string(g_value_array_get_nth(args, 0)), -1);
+	if (g_strcmp0(command, "WHOIS"))
+	 * WHOIS. So we assume that the last WHOIS request that we had issued has resulted in this RPL_TRYAGAIN. This is fine as long nobody else is

You can use g_ascii_strcasecmp() to avoid having to uppercase the string, which avoids needing the goto cleanup.

@@ +262,3 @@
+	msg = g_value_get_string(g_value_array_get_nth(args, 1));
+
+

g_error_new_literal().
Comment 32 Will Thompson 2011-04-29 05:35:18 UTC
Review of attachment 46065 [details] [review]:

Looks good — while I am not much enamoured of the way the Idle test suite auto-responds to requests (unlike the Gabble one, say, where the test case generally manually sends the replies), this change fits in well with the current model.
Comment 33 Will Thompson 2011-04-29 05:39:12 UTC
Review of attachment 46066 [details] [review]:

Looks good.
Comment 34 Will Thompson 2011-04-29 05:45:22 UTC
Review of attachment 46067 [details] [review]:

Just some tiny nitpicks:

::: tests/twisted/messages/contactinfo-request.py
@@ +15,3 @@
+    for (name, parameters, value) in vcard:
+        if name == 'fn':
+            assert value[0] == 'Test User'

Does servicetest.py in Idle have the assertEquals() etc. family of functions that are included in Gabble's version of servicetest.py? If not, okay, but maybe in the future Idle's copy could be refreshed.

@@ +39,3 @@
+    call_async(q, conn, 'GetSelfHandle')
+    event = q.expect('dbus-return', method='GetSelfHandle')
+    self_handle = event.value[0]

You can spell this as self_handle = conn.GetSelfHandle()

@@ +51,3 @@
+    call_async(q, contact_info, 'RequestContactInfo', self_handle)
+    event = q.expect('dbus-error', method='RequestContactInfo')
+    assert event.name == SERVICE_BUSY

Maybe you could comment this to explain that the test server alternates success and failure?
Comment 35 Debarshi Ray 2011-04-29 09:54:18 UTC
Created attachment 46158 [details] [review]
Handle RPL_WHOISSERVER messages in response to RequestContactInfo
Comment 36 Debarshi Ray 2011-04-29 09:55:00 UTC
(In reply to comment #31)
> Review of attachment 46064 [details] [review]:
> 
> Looks functionally fine, though I have a couple of nitpicks :)
> 
> ::: src/idle-contact-info.c
> @@ +256,3 @@
> +    command = g_ascii_strup(g_value_get_string(g_value_array_get_nth(args,
> 0)), -1);
> +    if (g_strcmp0(command, "WHOIS"))
> +     * WHOIS. So we assume that the last WHOIS request that we had issued has
> resulted in this RPL_TRYAGAIN. This is fine as long nobody else is
> 
> You can use g_ascii_strcasecmp() to avoid having to uppercase the string, which
> avoids needing the goto cleanup.

Fixed.

> @@ +262,3 @@
> +    msg = g_value_get_string(g_value_array_get_nth(args, 1));
> +
> +
> 
> g_error_new_literal().

Fixed.
Comment 37 Debarshi Ray 2011-04-29 09:55:48 UTC
Created attachment 46160 [details] [review]
Handle RPL_TRYAGAIN messages in response to RequestContactInfo
Comment 38 Debarshi Ray 2011-04-29 09:57:50 UTC
(In reply to comment #34)
> Review of attachment 46067 [details] [review]:
> 
> Just some tiny nitpicks:
> 
> ::: tests/twisted/messages/contactinfo-request.py
> @@ +15,3 @@
> +    for (name, parameters, value) in vcard:
> +        if name == 'fn':
> +            assert value[0] == 'Test User'
> 
> Does servicetest.py in Idle have the assertEquals() etc. family of functions
> that are included in Gabble's version of servicetest.py?

It does. Fixed to use assertEquals.
 
> @@ +39,3 @@
> +    call_async(q, conn, 'GetSelfHandle')
> +    event = q.expect('dbus-return', method='GetSelfHandle')
> +    self_handle = event.value[0]
> 
> You can spell this as self_handle = conn.GetSelfHandle()

Done. What is the difference? I thought this would cause a synchronous DBus call.
 
> @@ +51,3 @@
> +    call_async(q, contact_info, 'RequestContactInfo', self_handle)
> +    event = q.expect('dbus-error', method='RequestContactInfo')
> +    assert event.name == SERVICE_BUSY
> 
> Maybe you could comment this to explain that the test server alternates success
> and failure?

Done.
Comment 39 Debarshi Ray 2011-04-29 09:58:39 UTC
Created attachment 46161 [details] [review]
Test to cover RequestContactInfo
Comment 40 Will Thompson 2011-05-02 04:18:06 UTC
(In reply to comment #38)
> Done. What is the difference? I thought this would cause a synchronous DBus
> call.

That's exactly what it does… it's just more readable in this context, I think. (Particularly since there's a synchronous call to RequestHandles() below it!)

The revised patches look good; commit away!
Comment 41 Debarshi Ray 2011-05-02 04:47:23 UTC
Created attachment 46248 [details] [review]
Handle WHOIS messages in our test IRC server

Removed a spurious space due to a typo in the 378 numeric. This does not affect anything at the moment because we don't handle it and hence don't test for it at the moment.
Comment 42 Debarshi Ray 2011-05-02 04:50:51 UTC
(In reply to comment #40)
> The revised patches look good; commit away!

Committed and pushed.
Comment 43 Debarshi Ray 2011-05-05 16:11:44 UTC
Created attachment 46377 [details] [review]
Handle RPL_WHOISHOST messages in response to RequestContactInfo
Comment 44 Debarshi Ray 2011-05-05 16:12:45 UTC
Created attachment 46378 [details] [review]
idletest: return an empty RPL_WHOISCHANNELS in response to WHOIS
Comment 45 Debarshi Ray 2011-05-05 16:13:21 UTC
Created attachment 46379 [details] [review]
Handle empty RPL_WHOISCHANNELS in response to RequestContactInfo
Comment 46 Will Thompson 2011-05-06 04:26:35 UTC
Review of attachment 46377 [details] [review]:

::: src/idle-contact-info.c
@@ +321,3 @@
+
+	/* msg == "is connecting from *@<hostname> <IP>" */
+	request = g_queue_peek_head(conn->contact_info_requests);

You need to check that there are actually more than three elements in the string. Relying on the server not sending malformed data, and crashing if it does, doesn't seem wise.

I think I would check whether the string actually has the expected prefix; if it does, strsplit the remainder of the string and put that in the contact info field; if it does not, either just include the whole string verbatim or ignore it?
Comment 47 Will Thompson 2011-05-06 04:27:10 UTC
Review of attachment 46378 [details] [review]:

Looks fine.
Comment 48 Will Thompson 2011-05-06 04:27:19 UTC
Review of attachment 46379 [details] [review]:

Looks fine, I guess it fixes a crash exposed by the change to the test case?
Comment 49 Debarshi Ray 2011-05-06 11:30:38 UTC
(In reply to comment #46)
> Review of attachment 46377 [details] [review]:
> 
> ::: src/idle-contact-info.c
> @@ +321,3 @@
> +
> +    /* msg == "is connecting from *@<hostname> <IP>" */
> +    request = g_queue_peek_head(conn->contact_info_requests);
> 
> You need to check that there are actually more than three elements in the
> string. Relying on the server not sending malformed data, and crashing if it
> does, doesn't seem wise.
> 
> I think I would check whether the string actually has the expected prefix; if
> it does, strsplit the remainder of the string and put that in the contact info
> field; if it does not, either just include the whole string verbatim or ignore
> it?

I chose to check the prefix. Checking it cleverly will ensure that there are atleast 3 elements in the string.

Also, as explained in the patch since there is some conflicting (arcane?) use of 378, I chose to bail out if the prefix does not match. It is not our problem if daemons make crazy little changes to the protocol here and there.
Comment 50 Debarshi Ray 2011-05-06 11:31:20 UTC
Created attachment 46403 [details] [review]
Handle RPL_WHOISHOST messages in response to RequestContactInfo
Comment 51 Debarshi Ray 2011-05-06 11:32:08 UTC
(In reply to comment #48)
> Review of attachment 46379 [details] [review]:
> 
> Looks fine, I guess it fixes a crash exposed by the change to the test case?

Yes.
Comment 52 Debarshi Ray 2011-05-06 11:59:57 UTC
Created attachment 46405 [details] [review]
Try not to mistake RPL_WHOWAS_TIME as RPL_WHOISLOGGEDIN

I feel like herding all ircd developers into a single room and beating each of them with a cluebat.
Comment 53 Will Thompson 2011-05-09 08:36:34 UTC
Review of attachment 46403 [details] [review]:

Kind of a kludge but seem like the protocol doesn't actually give us much choice. :)

::: src/idle-contact-info.c
@@ +323,3 @@
+
+	if (request->contact_info == NULL)
+

I'm sure I've seen this code somewhere before. :)

How about combining this with _is_valid_response? Something like this:

static ContactInfoRequest *
_is_valid_response (IdleConnection *conn, GValueArray *args)
{
  // current body of _is_valid_response, returning NULL rather than FALSE;

  if (request->contact_info == NULL)
    request->contact_info = dbus_g_type_specialized_construct(TP_ARRAY_TYPE_CONTACT_INFO_FIELD_LIST);

  return request;
}

and then the boilerplate at the top of each function would just be:

{
  // ...
  ContactInfoRequest *request = _is_valid_response (conn, args);

  if (request == NULL)
    return IDLE_PARSER_HANDLER_RESULT_NOT_HANDLED;

  // ...

(This is a general comment on the contact-info code, rather than specifically about this patch.)
Comment 54 Will Thompson 2011-05-09 08:41:15 UTC
Review of attachment 46405 [details] [review]:

I don't blame you for your fantasies of bludgeoning ircd hackers.

::: src/idle-contact-info.c
@@ +373,3 @@
+	if (g_strcmp0(msg, "is logged in as"))
+		return IDLE_PARSER_HANDLER_RESULT_NOT_HANDLED;
+

So the message format is "<nickname> :is logged in as"? Weird! :)
Comment 55 Debarshi Ray 2011-05-09 09:37:00 UTC
(In reply to comment #54)
> Review of attachment 46405 [details] [review]:
> 
> I don't blame you for your fantasies of bludgeoning ircd hackers.

They get away with all these weird things because most IRC clients just dump whatever they get on the UI with minimal processing. Things get a bit tricky for Telepathy because stuff needs to fit into a pre-defined format.

> ::: src/idle-contact-info.c
> @@ +373,3 @@
> +    if (g_strcmp0(msg, "is logged in as"))
> +        return IDLE_PARSER_HANDLER_RESULT_NOT_HANDLED;
> +
> 
> So the message format is "<nickname> :is logged in as"? Weird! :)

Something like this:
lindbohm.freenode.net 330 rishi debarshi :is logged in as

Here I am using 'rishi' as my nick, but 'debarshi' is my primary nick (or account name) on Freenode.
Comment 56 Will Thompson 2011-05-09 10:27:03 UTC
Weird but I guess it makes sense from the “just dump it to the terminal” viewpoint! ++
Comment 57 Debarshi Ray 2011-05-09 12:26:39 UTC
Committed and pushed.
Comment 58 Debarshi Ray 2011-05-09 12:28:59 UTC
Created attachment 46501 [details] [review]
Reduce boilerplate
Comment 59 Debarshi Ray 2011-05-10 01:52:22 UTC
Created attachment 46523 [details] [review]
Handle RPL_WHOISREGNICK messages in response to RequestContactInfo
Comment 60 Debarshi Ray 2011-05-10 01:52:54 UTC
Created attachment 46524 [details] [review]
Handle RPL_WHOISOPERATOR messages in response to RequestContactInfo
Comment 61 Debarshi Ray 2011-05-10 01:53:30 UTC
Created attachment 46525 [details] [review]
Handle RPL_WHOISSECURE messages in response to RequestContactInfo
Comment 62 Will Thompson 2011-05-10 02:18:05 UTC
Review of attachment 46501 [details] [review]:

Looks good.
Comment 63 Will Thompson 2011-05-10 02:24:02 UTC
Review of attachment 46523 [details] [review]:

Looks fine.
Comment 64 Will Thompson 2011-05-10 02:29:10 UTC
Review of attachment 46524 [details] [review]:

++
Comment 65 Will Thompson 2011-05-10 02:30:18 UTC
Review of attachment 46525 [details] [review]:

++
Comment 66 Debarshi Ray 2011-05-10 10:09:12 UTC
Committed and pushed.
Comment 67 Debarshi Ray 2011-05-11 10:31:25 UTC
Created attachment 46610 [details] [review]
Put the role played by the target nick in a channel as vCard parameter

Contains slight duplication of code from src/idle-handles.c.
Comment 68 Will Thompson 2011-05-11 10:41:32 UTC
Review of attachment 46610 [details] [review]:

::: src/idle-contact-info.c
@@ +63,3 @@
+{
+	return (c == '#') || (c == '!') || (c == '&') || (c == '+');
+}

Why not turn this code into a function in muc-channel, like _is_modechar(), and call it from the two places?

@@ +304,3 @@
 	for (i = 0; channelsv[i] != NULL; i++) {
+		const gchar *channel = channelsv[i];
+		const gchar *field_params[2] = {NULL, NULL};

This shouldn't be const. You shouldn't have to cast the const away at the end of the block when you free the string. I think you can past a char *[] to a function expecting const char * const *?

It might be nice to avoid allocating a fresh string but I see why you have. :)
Comment 69 Debarshi Ray 2011-05-11 11:08:58 UTC
(In reply to comment #68)
> Review of attachment 46610 [details] [review]:
> 
> ::: src/idle-contact-info.c
> @@ +63,3 @@
> +{
> +    return (c == '#') || (c == '!') || (c == '&') || (c == '+');
> +}
> 
> Why not turn this code into a function in muc-channel, like _is_modechar(),
> and call it from the two places?

Done.

> @@ +304,3 @@
>      for (i = 0; channelsv[i] != NULL; i++) {
> +        const gchar *channel = channelsv[i];
> +        const gchar *field_params[2] = {NULL, NULL};
> 
> This shouldn't be const. You shouldn't have to cast the const away at the end
> of the block when you free the string. I think you can past a char *[] to a
> function expecting const char * const *?

Since we can't assign char ** to const char **, lets use a char ** and use the cast while passing the value to the function.
Comment 70 Debarshi Ray 2011-05-11 11:09:37 UTC
Created attachment 46612 [details] [review]
contactinfo-request.py: check the x-irc-server and x-host fields
Comment 71 Debarshi Ray 2011-05-11 11:10:15 UTC
Created attachment 46613 [details] [review]
Add idle_muc_channel_is_typechar as per RFC 2811

Yes, RFC 2811 and not 2812. :-)
Comment 72 Debarshi Ray 2011-05-11 11:10:40 UTC
Created attachment 46614 [details] [review]
Use idle_muc_channel_is_typechar
Comment 73 Debarshi Ray 2011-05-11 11:11:16 UTC
Created attachment 46615 [details] [review]
Put the role played by the target nick in a channel as vCard parameter
Comment 74 Will Thompson 2011-05-11 11:26:27 UTC
Review of attachment 46612 [details] [review]:

++
Comment 75 Will Thompson 2011-05-11 11:27:13 UTC
Review of attachment 46613 [details] [review]:

++
Comment 76 Will Thompson 2011-05-11 11:27:20 UTC
Review of attachment 46614 [details] [review]:

++
Comment 77 Will Thompson 2011-05-11 11:27:44 UTC
Review of attachment 46615 [details] [review]:

++
Comment 78 Debarshi Ray 2011-05-11 12:51:37 UTC
Committed and pushed.


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.