xeme/xeme

62de723fb97c
Parents 713f2c59c863
Children 19f8cef54b13
Add a bare jid out parameter to xeme_address_parse
--- a/xeme/tests/testaddress.c Thu Dec 07 21:35:02 2023 -0600
+++ b/xeme/tests/testaddress.c Thu Dec 07 21:44:47 2023 -0600
@@ -52,7 +52,7 @@
};
for(int i = 0; data[i] != NULL; i++) {
- g_assert_true(xeme_address_parse(data[i], NULL, NULL, NULL));
+ g_assert_true(xeme_address_parse(data[i], NULL, NULL, NULL, NULL));
}
}
@@ -76,7 +76,7 @@
};
for(int i = 0; data[i] != NULL; i++) {
- g_assert_false(xeme_address_parse(data[i], NULL, NULL, NULL));
+ g_assert_false(xeme_address_parse(data[i], NULL, NULL, NULL, NULL));
}
}
--- a/xeme/xemeaddress.c Thu Dec 07 21:35:02 2023 -0600
+++ b/xeme/xemeaddress.c Thu Dec 07 21:44:47 2023 -0600
@@ -20,16 +20,18 @@
#include "xemestring.h"
#define XEME_ADDRESS_REGEX \
- "^(?:(?P<local>[^\\\"&'/:<>@]+)@)?" \
- "(?P<domain>(?:[^@/[\\\\_$]+|(\\[[0-9a-fA-F:]+\\])))" \
+ "^(?P<bare_jid>" \
+ "(?:(?P<local>[^\\\"&'/:<>@]+)@)?" \
+ "(?P<domain>(?:[^@/[\\\\_$]+|(\\[[0-9a-fA-F:]+\\])))" \
+ ")" \
"(?:/(?P<resource>.+))?$"
/******************************************************************************
* Public API
*****************************************************************************/
gboolean
-xeme_address_parse(const char *address, char **local, char **domain,
- char **resource)
+xeme_address_parse(const char *address, char **bare_jid, char **local,
+ char **domain, char **resource)
{
static GRegex *regexp = NULL;
GMatchInfo *info = NULL;
@@ -58,6 +60,15 @@
return FALSE;
}
+ if(bare_jid != NULL) {
+ tmp = g_match_info_fetch_named(info, "bare_jid");
+ if(xeme_str_is_empty(tmp)) {
+ g_clear_pointer(&tmp, g_free);
+ }
+
+ *bare_jid = tmp;
+ }
+
if(local != NULL) {
tmp = g_match_info_fetch_named(info, "local");
if(xeme_str_is_empty(tmp)) {
--- a/xeme/xemeaddress.h Thu Dec 07 21:35:02 2023 -0600
+++ b/xeme/xemeaddress.h Thu Dec 07 21:44:47 2023 -0600
@@ -28,6 +28,8 @@
/**
* xeme_address_parse:
* @address: The address to parse.
+ * @bare_jid: (nullable): An optional return address for the bare jid, that is
+ * the `local@domain` part of the jid including the `@`.
* @local: (nullable): An optional return address for the localpart.
* @domain: (nullable): An optional return address for the domainpart.
* @resource: (nullable): An optional return address for the resourcepart.
@@ -41,7 +43,7 @@
* Since: 0.1.0
*/
XEME_AVAILABLE_IN_0_1
-gboolean xeme_address_parse(const char *address, char **local, char **domain, char **resource);
+gboolean xeme_address_parse(const char *address, char **bare_jid, char **local, char **domain, char **resource);
G_END_DECLS