changeset 1974:acbebd68c7f0

Modularize url_regex
author Mikael Berthe <mikael@lilotux.net>
date Sat, 19 Mar 2011 20:06:34 +0100
parents 9fe1c0a54e73
children a23799244335
files mcabber/configure.ac mcabber/mcabber/screen.c mcabber/mcabberrc.example mcabber/modules/Makefile.am
diffstat 4 files changed, 11 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/configure.ac	Sat Mar 19 13:20:22 2011 +0100
+++ b/mcabber/configure.ac	Sat Mar 19 20:06:34 2011 +0100
@@ -283,6 +283,7 @@
                  modules/beep/Makefile
                  modules/xttitle/Makefile
                  modules/fifo/Makefile
+                 modules/urlregex/Makefile
                  doc/Makefile
                  doc/guide/Makefile
                  doc/help/Makefile
--- a/mcabber/mcabber/screen.c	Sat Mar 19 13:20:22 2011 +0100
+++ b/mcabber/mcabber/screen.c	Sat Mar 19 20:06:34 2011 +0100
@@ -163,10 +163,6 @@
   gint  value;
 } keyseq;
 
-#ifdef HAVE_GLIB_REGEX
-static GRegex *url_regex = NULL;
-#endif
-
 GSList *keyseqlist;
 static void add_keyseq(char *seqstr, guint mkeycode, gint value);
 
@@ -816,16 +812,6 @@
   inputLine[0] = 0;
   ptr_inputline = inputLine;
 
-  if (settings_opt_get("url_regex")) {
-#ifdef HAVE_GLIB_REGEX
-    url_regex = g_regex_new(settings_opt_get("url_regex"),
-                            G_REGEX_OPTIMIZE, 0, NULL);
-#else
-    scr_LogPrint(LPRINT_LOGNORM, "ERROR: Your glib version is too old, "
-                 "cannot use url_regex.");
-#endif // HAVE_GLIB_REGEX
-  }
-
   Curses = TRUE;
   return;
 }
@@ -836,12 +822,6 @@
   clear();
   refresh();
   endwin();
-#ifdef HAVE_GLIB_REGEX
-  if (url_regex) {
-    g_regex_unref(url_regex);
-    url_regex = NULL;
-  }
-#endif
   Curses = FALSE;
   return;
 }
@@ -2171,22 +2151,6 @@
   }
 }
 
-#ifdef HAVE_GLIB_REGEX
-static inline void scr_log_urls(const gchar *string)
-{
-  GMatchInfo *match_info;
-
-  g_regex_match_full(url_regex, string, -1, 0, 0, &match_info, NULL);
-  while (g_match_info_matches(match_info)) {
-    gchar *url = g_match_info_fetch(match_info, 0);
-    scr_print_logwindow(url);
-    g_free(url);
-    g_match_info_next(match_info, NULL);
-  }
-  g_match_info_free(match_info);
-}
-#endif
-
 static void scr_write_message(const char *bjid, const char *text,
                               time_t timestamp, guint prefix_flags,
                               unsigned mucnicklen, gpointer xep184)
@@ -2214,10 +2178,6 @@
         ~HBB_PREFIX_PGPCRYPT & ~HBB_PREFIX_OTRCRYPT))
     prefix |= HBB_PREFIX_IN;
 
-#ifdef HAVE_GLIB_REGEX
-  if (url_regex)
-    scr_log_urls(text);
-#endif
   scr_write_message(jidfrom, text, timestamp, prefix, mucnicklen, NULL);
 }
 
--- a/mcabber/mcabberrc.example	Sat Mar 19 13:20:22 2011 +0100
+++ b/mcabber/mcabberrc.example	Sat Mar 19 20:06:34 2011 +0100
@@ -269,6 +269,15 @@
 #
 #module load fifo
 
+# URL extractor
+# Set 'url_regex' to a regular expression matching urls.  If it matches an
+# url in an incoming messages, it'll print it to the log window.
+# Don't forget to load the urlregex module if you plan to use this feature!
+#set url_regex = "(((https?|ftps?|nntp)://)|www[.][-a-z0-9.]+|(mailto:|news:))(%[0-9A-F]{2}|[-_.!~*';/?:@&=+$,#[:alnum:]])+"
+#
+#module load urlregex
+
+
 # Traces logging
 # If you want advanced traces, please specify a file and a level here.
 # There are currently 4 tracelog levels:
@@ -457,10 +466,6 @@
 #
 # Set 'info' to anything you'd like to see in your lower status line.
 #set info = woot
-#
-# Set 'url_regex' to a regular expression matching urls.  If it matches an
-# url in an incoming messages, it'll print it to the log window.
-#set url_regex = "(((https?|ftps?|nntp)://)|www[.][-a-z0-9.]+|(mailto:|news:))(%[0-9A-F]{2}|[-_.!~*';/?:@&=+$,#[:alnum:]])+"
 
 # Contacts PGP information
 # You can provide a PGP key to be used for a given Jabber user, or
--- a/mcabber/modules/Makefile.am	Sat Mar 19 13:20:22 2011 +0100
+++ b/mcabber/modules/Makefile.am	Sat Mar 19 20:06:34 2011 +0100
@@ -1,1 +1,1 @@
-SUBDIRS = beep xttitle fifo
+SUBDIRS = beep xttitle fifo urlregex