Index: trunk/src/sh_log_parse_apache.c
===================================================================
--- trunk/src/sh_log_parse_apache.c	(revision 541)
+++ trunk/src/sh_log_parse_apache.c	(revision 588)
@@ -28,9 +28,10 @@
 #define FIL__  _("sh_log_parse_apache.c")
 
-/* Debian/Ubuntu: libpcre3-dev */
-#ifdef HAVE_PCRE_PCRE_H
-#include <pcre/pcre.h>
+/* Debian/Ubuntu: libpcre2-dev */
+#define PCRE2_CODE_UNIT_WIDTH 8
+#ifdef HAVE_PCRE2_PCRE2_H
+#include <pcre2/pcre2.h>
 #else
-#include <pcre.h>
+#include <pcre2.h>
 #endif
 
@@ -44,7 +45,7 @@
 
 struct sh_fileinfo_apache {
-  pcre * line_regex;
-  int  * line_ovector;         /* captured substrings     */
-  int    line_ovecnum;         /* how many captured       */
+  pcre2_code * line_regex;
+  PCRE2_SIZE * line_ovector;         /* captured substrings     */
+  int          line_ovecnum;         /* how many captured       */
   
   int    pos_host;
@@ -82,6 +83,6 @@
   volatile int          p_time = -1;
   char                * f_time = NULL;
-  const char * error;
-  int          erroffset;
+  int          error;
+  size_t       erroffset;
   
   /* Take the address to keep gcc from putting them into registers. 
@@ -261,5 +262,5 @@
 
   result = SH_ALLOC(sizeof(struct sh_fileinfo_apache));
-  result->line_regex = pcre_compile(sh_string_str(re_string), 0, 
+  result->line_regex = pcre2_compile((PCRE2_SPTR8)sh_string_str(re_string), sh_string_len(re_string), 0, 
 				    &error, &erroffset, NULL);
   if (!(result->line_regex))
@@ -285,5 +286,5 @@
   sh_string_destroy(&re_string);
 
-  result->line_ovector  = SH_ALLOC(sizeof(int) * (nfields+1) * 3);
+  result->line_ovector  = NULL;
   result->line_ovecnum  = nfields;
   result->pos_host      = p_host;
@@ -304,10 +305,13 @@
   char         tstr[128];
   char         sstr[128];
-  const char * hstr;
+  char       * hstr;
   int          res;
-  const char **hstr_addr = (const char **) &hstr;
+  unsigned char **hstr_addr = (unsigned char **) &hstr;
+  size_t       hstr_len;
 
   struct sh_fileinfo_apache * info = (struct sh_fileinfo_apache *) fileinfo;
 
+  pcre2_match_data * match_data = NULL;
+  
   if (sh_string_len(logline) > 0 && flag_err_debug == S_TRUE)
     {
@@ -324,24 +328,29 @@
     }
 
-  res = pcre_exec(info->line_regex, NULL, 
-		  sh_string_str(logline), (int)sh_string_len(logline), 0,
-		  0, info->line_ovector, (3*(1+info->line_ovecnum)));
-
-  if (res == (1+info->line_ovecnum))
+  match_data = pcre2_match_data_create_from_pattern(info->line_regex, NULL);
+  
+  res = pcre2_match(info->line_regex,
+		    (PCRE2_SPTR8)sh_string_str(logline), (int)sh_string_len(logline), 0,
+		    0, match_data, NULL);
+
+  if (res == 1+info->line_ovecnum) /* successful match */
     {
       struct sh_logrecord * record;
       time_t timestamp = 0;
-
+      size_t size;
+
+      info->line_ovector = pcre2_get_ovector_pointer(match_data);
+      
       if (info->pos_time > 0)
 	{
-	  res = pcre_copy_substring(sh_string_str(logline), 
-				    info->line_ovector, res,
-				    info->pos_time, tstr, sizeof(tstr));
-	  if (res <= 0)
+	  size = sizeof(tstr);
+	  res = pcre2_substring_copy_bynumber(match_data,  info->pos_time,
+					      (PCRE2_UCHAR8 *)tstr, &size);
+	  if (res != 0)
 	    goto corrupt;
 	}
       else
 	{
-	  res = 0;
+	  res = -1;
 	  timestamp = 0;
 	  info->format_time = sh_util_strdup(_("%d/%b/%Y:%T"));
@@ -349,5 +358,5 @@
 	}
 
-      if (res > 0)
+      if (res == 0)
 	{
 	  struct tm btime;
@@ -371,8 +380,8 @@
       if (info->pos_status > 0)
 	{
-	  res = pcre_copy_substring(sh_string_str(logline), 
-				    info->line_ovector, res,
-				    info->pos_status, sstr, sizeof(sstr));
-	  if (res <= 0)
+	  size = sizeof(sstr);
+	  res = pcre2_substring_copy_bynumber(match_data,  info->pos_status,
+					      (PCRE2_UCHAR8 *)sstr, &size);
+	  if (res != 0)
 	    goto corrupt;
 	}
@@ -384,8 +393,7 @@
       if (info->pos_host > 0)
 	{
-	  res = pcre_get_substring(sh_string_str(logline), 
-				   info->line_ovector, res,
-				   info->pos_host, hstr_addr);
-	  if (res <= 0)
+	  res = pcre2_substring_get_bynumber(match_data, info->pos_host,
+					     hstr_addr, &hstr_len);
+	  if (res != 0)
 	    goto corrupt;
 	}
@@ -401,5 +409,5 @@
 
       if (hstr)
-	record->host = sh_string_new_from_lchar(hstr, strlen(hstr));
+	record->host = sh_string_new_from_lchar(hstr, hstr_len);
       else
 	record->host = sh_string_new_from_lchar(sh.host.name, strlen(sh.host.name));
@@ -409,5 +417,8 @@
       record->pid       = PID_INVALID;
 
-      pcre_free_substring(hstr); 
+      /* does nothing if hstr == NULL */
+      pcre2_substring_free((PCRE2_UCHAR8 *)hstr);
+
+      pcre2_match_data_free(match_data);
       return record;
     }
@@ -415,6 +426,5 @@
     {
       char msg[128];
-      sl_snprintf(msg, sizeof(msg), _("Incorrect number of captured subexpressions: %d vs %d"),
-		  res, info->line_ovecnum);
+      sl_snprintf(msg, sizeof(msg), _("Matching error: %d"), res);
       
       SH_MUTEX_LOCK(mutex_thread_nolog);
@@ -440,4 +450,5 @@
     sh_string_destroy(&msg);
   }
+  pcre2_match_data_free(match_data);
   return NULL;
 }
