mirror of
https://gitlab.gnome.org/GNOME/calls.git
synced 2024-12-12 07:37:35 +00:00
util: Add simple API to query protocol
This commit is contained in:
parent
1def4c3585
commit
1e84812938
2 changed files with 52 additions and 0 deletions
49
src/util.c
49
src/util.c
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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__ */
|
||||
|
|
Loading…
Reference in a new issue