1
0
Fork 0
mirror of https://gitlab.gnome.org/GNOME/calls.git synced 2024-06-28 06:39:32 +00:00

util: Add simple API to query protocol

This commit is contained in:
Evangelos Ribeiro Tzaras 2021-04-26 12:10:43 +02:00
parent 1def4c3585
commit 1e84812938
2 changed files with 52 additions and 0 deletions

View file

@ -198,3 +198,52 @@ calls_find_in_store (GListModel *list,
return FALSE;
#endif
}
/**
* get_protocol_from_address:
* @target: The target address
*
* simply checks for the the scheme of an address without doing any validation
*
* Returns: The protocol used for address, or NULL if could not determine
*/
const char *
get_protocol_from_address (const char *target)
{
g_autofree char *lower = NULL;
g_return_val_if_fail (target, NULL);
lower = g_ascii_strdown (target, -1);
if (g_str_has_prefix (lower, "sips:"))
return "sips";
if (g_str_has_prefix (lower, "sip:"))
return "sip";
if (g_str_has_prefix (lower, "tel:"))
return "tel";
/* could not determine the protocol (which most probably means it's a telephone number) */
return NULL;
}
/**
* get_protocol_from_address_with_fallback:
* @target: The address to check
*
* simply checks for the the scheme of an address without doing any validation
*
* Returns: The protocol used for address, or "tel" as a fallback
*/
const char *
get_protocol_from_address_with_fallback (const char *target)
{
const char *protocol = get_protocol_from_address (target);
if (!protocol)
protocol = "tel";
return protocol;
}

View file

@ -138,6 +138,9 @@ gboolean calls_find_in_store (GListModel *list,
gpointer item,
guint *position);
const char* get_protocol_from_address (const char *target);
const char* get_protocol_from_address_with_fallback (const char *target);
G_END_DECLS
#endif /* CALLS__UTIL_H__ */