util: Add simple API to query protocol
This commit is contained in:
49
src/util.c
49
src/util.c
@@ -198,3 +198,52 @@ calls_find_in_store (GListModel *list,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
#endif
|
#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,
|
gpointer item,
|
||||||
guint *position);
|
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
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* CALLS__UTIL_H__ */
|
#endif /* CALLS__UTIL_H__ */
|
||||||
|
|||||||
Reference in New Issue
Block a user