mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-20 12:38:09 +00:00
Use a better regex to detect URIs in chat messages
This commit is contained in:
parent
288b0a14d2
commit
6ade3ddea3
3 changed files with 26 additions and 29 deletions
26
gtk/chat.c
26
gtk/chat.c
|
|
@ -31,6 +31,30 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
#define CONFIG_FILE ".linphone-history.db"
|
||||
|
||||
#include "regex.h"
|
||||
|
||||
GRegex *uri_regex = NULL;
|
||||
|
||||
static void free_uri_regex(void) {
|
||||
if(uri_regex) g_regex_unref(uri_regex);
|
||||
}
|
||||
|
||||
static const GRegex *get_uri_regex(void) {
|
||||
const gchar *pattern = BC_REGEX_URI;
|
||||
GError *error = NULL;
|
||||
if(uri_regex == NULL) {
|
||||
uri_regex = g_regex_new(pattern, G_REGEX_OPTIMIZE, 0, &error);
|
||||
if(error) {
|
||||
g_warning("Could not parse regex pattern for URIs: %s", error->message);
|
||||
g_error_free(error);
|
||||
uri_regex = NULL;
|
||||
return NULL;
|
||||
}
|
||||
atexit(free_uri_regex);
|
||||
}
|
||||
return uri_regex;
|
||||
}
|
||||
|
||||
char *linphone_gtk_message_storage_get_db_file(const char *filename){
|
||||
const int path_max=1024;
|
||||
char *db_file=NULL;
|
||||
|
|
@ -157,7 +181,7 @@ void linphone_gtk_push_text(GtkWidget *w, const LinphoneAddress *from,
|
|||
char *from_str=linphone_address_as_string_uri_only(from);
|
||||
gchar *from_message=(gchar *)g_object_get_data(G_OBJECT(w),"from_message");
|
||||
GHashTable *table=(GHashTable*)g_object_get_data(G_OBJECT(w),"table");
|
||||
const GRegex *uri_regex = linphone_gtk_get_uri_regex();
|
||||
const GRegex *uri_regex = get_uri_regex();
|
||||
GMatchInfo *match_info = NULL;
|
||||
const char *message = linphone_chat_message_get_text(msg);
|
||||
time_t t;
|
||||
|
|
|
|||
|
|
@ -340,10 +340,4 @@ LINPHONE_PUBLIC void linphone_gtk_proxy_transport_changed(GtkWidget *combo);
|
|||
LINPHONE_PUBLIC void linphone_gtk_tunnel_ok(GtkButton *button);
|
||||
LINPHONE_PUBLIC void linphone_gtk_notebook_current_page_changed(GtkNotebook *notebook, GtkWidget *page, guint page_num, gpointer user_data);
|
||||
LINPHONE_PUBLIC void linphone_gtk_reload_sound_devices(void);
|
||||
LINPHONE_PUBLIC void linphone_gtk_reload_video_devices(void);
|
||||
|
||||
/**
|
||||
* Provide a regex to match URIs
|
||||
* @return A singleton regex object
|
||||
*/
|
||||
const GRegex *linphone_gtk_get_uri_regex(void);
|
||||
LINPHONE_PUBLIC void linphone_gtk_reload_video_devices(void);
|
||||
21
gtk/main.c
21
gtk/main.c
|
|
@ -63,7 +63,6 @@ const char *this_program_ident_string="linphone_ident_string=" LINPHONE_VERSION;
|
|||
static LinphoneCore *the_core=NULL;
|
||||
static GtkWidget *the_ui=NULL;
|
||||
static LinphoneLDAPContactProvider* ldap_provider = NULL;
|
||||
static GRegex *uri_regex = NULL;
|
||||
|
||||
static void linphone_gtk_global_state_changed(LinphoneCore *lc, LinphoneGlobalState state, const char*str);
|
||||
static void linphone_gtk_registration_state_changed(LinphoneCore *lc, LinphoneProxyConfig *cfg, LinphoneRegistrationState rs, const char *msg);
|
||||
|
|
@ -2026,26 +2025,6 @@ static void populate_xdg_data_dirs_envvar(void) {
|
|||
#endif
|
||||
}
|
||||
|
||||
static void free_uri_regex(void) {
|
||||
if(uri_regex) g_regex_unref(uri_regex);
|
||||
}
|
||||
|
||||
const GRegex *linphone_gtk_get_uri_regex(void) {
|
||||
const gchar *pattern = "\\b[a-z0-9]+://[\\S]+\\b";
|
||||
GError *error = NULL;
|
||||
if(uri_regex == NULL) {
|
||||
uri_regex = g_regex_new(pattern, G_REGEX_OPTIMIZE, 0, &error);
|
||||
if(error) {
|
||||
g_warning("Could not parse regex pattern for URIs: %s", error->message);
|
||||
g_error_free(error);
|
||||
uri_regex = NULL;
|
||||
return NULL;
|
||||
}
|
||||
atexit(free_uri_regex);
|
||||
}
|
||||
return uri_regex;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
char *config_file;
|
||||
const char *factory_config_file;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue