comparison mcabber/mcabber/screen.c @ 1974:acbebd68c7f0

Modularize url_regex
author Mikael Berthe <mikael@lilotux.net>
date Sat, 19 Mar 2011 20:06:34 +0100
parents d9255c408027
children 1d8f9135e000
comparison
equal deleted inserted replaced
1973:9fe1c0a54e73 1974:acbebd68c7f0
160 typedef struct { 160 typedef struct {
161 char *seqstr; 161 char *seqstr;
162 guint mkeycode; 162 guint mkeycode;
163 gint value; 163 gint value;
164 } keyseq; 164 } keyseq;
165
166 #ifdef HAVE_GLIB_REGEX
167 static GRegex *url_regex = NULL;
168 #endif
169 165
170 GSList *keyseqlist; 166 GSList *keyseqlist;
171 static void add_keyseq(char *seqstr, guint mkeycode, gint value); 167 static void add_keyseq(char *seqstr, guint mkeycode, gint value);
172 168
173 static void scr_write_in_window(const char *winId, const char *text, 169 static void scr_write_in_window(const char *winId, const char *text,
814 // to update Log_Win_Height and set max{X,Y} 810 // to update Log_Win_Height and set max{X,Y}
815 811
816 inputLine[0] = 0; 812 inputLine[0] = 0;
817 ptr_inputline = inputLine; 813 ptr_inputline = inputLine;
818 814
819 if (settings_opt_get("url_regex")) {
820 #ifdef HAVE_GLIB_REGEX
821 url_regex = g_regex_new(settings_opt_get("url_regex"),
822 G_REGEX_OPTIMIZE, 0, NULL);
823 #else
824 scr_LogPrint(LPRINT_LOGNORM, "ERROR: Your glib version is too old, "
825 "cannot use url_regex.");
826 #endif // HAVE_GLIB_REGEX
827 }
828
829 Curses = TRUE; 815 Curses = TRUE;
830 return; 816 return;
831 } 817 }
832 818
833 void scr_terminate_curses(void) 819 void scr_terminate_curses(void)
834 { 820 {
835 if (!Curses) return; 821 if (!Curses) return;
836 clear(); 822 clear();
837 refresh(); 823 refresh();
838 endwin(); 824 endwin();
839 #ifdef HAVE_GLIB_REGEX
840 if (url_regex) {
841 g_regex_unref(url_regex);
842 url_regex = NULL;
843 }
844 #endif
845 Curses = FALSE; 825 Curses = FALSE;
846 return; 826 return;
847 } 827 }
848 828
849 void scr_beep(void) 829 void scr_beep(void)
2169 scr_Resize(); 2149 scr_Resize();
2170 redrawwin(stdscr); 2150 redrawwin(stdscr);
2171 } 2151 }
2172 } 2152 }
2173 2153
2174 #ifdef HAVE_GLIB_REGEX
2175 static inline void scr_log_urls(const gchar *string)
2176 {
2177 GMatchInfo *match_info;
2178
2179 g_regex_match_full(url_regex, string, -1, 0, 0, &match_info, NULL);
2180 while (g_match_info_matches(match_info)) {
2181 gchar *url = g_match_info_fetch(match_info, 0);
2182 scr_print_logwindow(url);
2183 g_free(url);
2184 g_match_info_next(match_info, NULL);
2185 }
2186 g_match_info_free(match_info);
2187 }
2188 #endif
2189
2190 static void scr_write_message(const char *bjid, const char *text, 2154 static void scr_write_message(const char *bjid, const char *text,
2191 time_t timestamp, guint prefix_flags, 2155 time_t timestamp, guint prefix_flags,
2192 unsigned mucnicklen, gpointer xep184) 2156 unsigned mucnicklen, gpointer xep184)
2193 { 2157 {
2194 char *xtext; 2158 char *xtext;
2212 if (!(prefix & 2176 if (!(prefix &
2213 ~HBB_PREFIX_NOFLAG & ~HBB_PREFIX_HLIGHT & ~HBB_PREFIX_HLIGHT_OUT & 2177 ~HBB_PREFIX_NOFLAG & ~HBB_PREFIX_HLIGHT & ~HBB_PREFIX_HLIGHT_OUT &
2214 ~HBB_PREFIX_PGPCRYPT & ~HBB_PREFIX_OTRCRYPT)) 2178 ~HBB_PREFIX_PGPCRYPT & ~HBB_PREFIX_OTRCRYPT))
2215 prefix |= HBB_PREFIX_IN; 2179 prefix |= HBB_PREFIX_IN;
2216 2180
2217 #ifdef HAVE_GLIB_REGEX
2218 if (url_regex)
2219 scr_log_urls(text);
2220 #endif
2221 scr_write_message(jidfrom, text, timestamp, prefix, mucnicklen, NULL); 2181 scr_write_message(jidfrom, text, timestamp, prefix, mucnicklen, NULL);
2222 } 2182 }
2223 2183
2224 void scr_write_outgoing_message(const char *jidto, const char *text, 2184 void scr_write_outgoing_message(const char *jidto, const char *text,
2225 guint prefix, gpointer xep184) 2185 guint prefix, gpointer xep184)