merge/upstream-full #105

Manually merged
jabber.developer merged 407 commits from merge/upstream-full into master 2026-05-26 17:54:34 +00:00
321 changed files with 10870 additions and 30766 deletions
Showing only changes of commit 5bcf859e92 - Show all commits

View File

@@ -152,6 +152,13 @@ jid_is_valid(const gchar* const str)
return (jid != NULL);
}
gboolean
jid_is_valid_user_jid(const gchar* const str)
{
auto_jid Jid* jid = jid_create(str);
return (jid != NULL && jid->localpart != NULL);
}
Jid*
jid_create_from_bare_and_resource(const gchar* const barejid, const gchar* const resource)
{

View File

@@ -53,6 +53,7 @@ typedef struct jid_t Jid;
Jid* jid_create(const gchar* const str);
gboolean jid_is_valid(const gchar* const str);
gboolean jid_is_valid_user_jid(const gchar* const str);
Jid* jid_create_from_bare_and_resource(const gchar* const barejid, const gchar* const resource);
void jid_destroy(Jid* jid);
void jid_ref(Jid* jid);

View File

@@ -154,6 +154,9 @@ main(int argc, char* argv[])
cmocka_unit_test(jid_create__returns__null_from_empty_parts),
cmocka_unit_test(jid_create__returns__null_from_multiple_at_in_bare),
cmocka_unit_test(jid_create__returns__correct_parts_with_at_in_resource_only),
cmocka_unit_test(jid_is_valid_user_jid__is__true_for_valid_user_jid),
cmocka_unit_test(jid_is_valid_user_jid__is__false_for_domain_jid),
cmocka_unit_test(jid_is_valid_user_jid__is__false_for_invalid_jid),
cmocka_unit_test(jid_is_valid__is__true_for_valid_jid),
cmocka_unit_test(jid_is_valid__is__false_for_invalid_jid),
cmocka_unit_test(jid_is_valid__is__false_for_null),

View File

@@ -306,6 +306,29 @@ jid_create__returns__correct_parts_with_at_in_resource_only(void** state)
jid_destroy(result);
}
void
jid_is_valid_user_jid__is__true_for_valid_user_jid(void** state)
{
assert_true(jid_is_valid_user_jid("myuser@mydomain/laptop"));
assert_true(jid_is_valid_user_jid("myuser@mydomain"));
}
void
jid_is_valid_user_jid__is__false_for_domain_jid(void** state)
{
jabber.developer marked this conversation as resolved
Review

We can add one more test for myuser@mydomain/user@laptop. As per RFC6122, section 2.4,

The '@' character is allowed in the resourcepart and is often used in the "nick" shown in XMPP chatrooms. For example, the JID <room@chat.example.com/user@host> describes an entity who is an occupant of the room room@chat.example.com with an (asserted) nick of user@host. However, chatroom services do not necessarily check such an asserted nick against the occupant's real JID.

We can add one more test for `myuser@mydomain/user@laptop`. As per [RFC6122, section 2.4](https://www.rfc-editor.org/rfc/rfc6122.html#section-2.4), > The '@' character is **allowed in the resourcepart** and is often used in the "nick" shown in XMPP chatrooms. For example, the JID <room@chat.example.com/user@host> describes an entity who is an occupant of the room <room@chat.example.com> with an (asserted) nick of <user@host>. However, chatroom services do not necessarily check such an asserted nick against the occupant's real JID.
assert_false(jid_is_valid_user_jid("mydomain/laptop"));
assert_false(jid_is_valid_user_jid("mydomain"));
}
void
jid_is_valid_user_jid__is__false_for_invalid_jid(void** state)
{
assert_false(jid_is_valid_user_jid("@mydomain"));
assert_false(jid_is_valid_user_jid("/laptop"));
assert_false(jid_is_valid_user_jid(NULL));
assert_false(jid_is_valid_user_jid(""));
}
void
jid_is_valid__is__true_for_valid_jid(void** state)
{

View File

@@ -30,6 +30,9 @@ void jid_create__returns__null_from_invalid_localpart_chars(void** state);
void jid_create__returns__null_from_empty_parts(void** state);
void jid_create__returns__null_from_multiple_at_in_bare(void** state);
void jid_create__returns__correct_parts_with_at_in_resource_only(void** state);
void jid_is_valid_user_jid__is__true_for_valid_user_jid(void** state);
void jid_is_valid_user_jid__is__false_for_domain_jid(void** state);
void jid_is_valid_user_jid__is__false_for_invalid_jid(void** state);
void jid_is_valid__is__true_for_valid_jid(void** state);
void jid_is_valid__is__false_for_invalid_jid(void** state);
void jid_is_valid__is__false_for_null(void** state);