? test/test_octstr_regexp.c
Index: gwlib/octstr.c
===================================================================
RCS file: /home/cvs/gateway/gwlib/octstr.c,v
retrieving revision 1.145
diff -c -r1.145 octstr.c
*** gwlib/octstr.c	19 Jun 2003 12:55:40 -0000	1.145
--- gwlib/octstr.c	4 Jul 2003 12:13:12 -0000
***************
*** 16,21 ****
--- 16,23 ----
  #include <sys/types.h>
  #include <sys/socket.h>
  #include <netinet/in.h>
+ #include <regex.h>
+ 
  
  #include "gwlib.h"
  
***************
*** 927,932 ****
--- 929,975 ----
      return -1;    
  }
  
+ void print_regerror(int errorcode, regex_t *compiled)
+ {
+   size_t length = regerror(errorcode,compiled,NULL,0);
+   char *buffer = gw_malloc(length);
+   (void) regerror(errorcode,compiled, buffer, length);
+   debug("gwlib.octstr",0,"regexp compilation error: %s",buffer);
+ 
+ }
+ 
+ 
+ int octstr_reg_matches(Octstr *haystack, Octstr *needle)
+ {
+   char *errstr;
+   int errornum;
+   regex_t *r;
+   size_t len;
+     
+   gw_assert(haystack != NULL);
+   gw_assert(needle != NULL);
+   
+   r = gw_malloc(sizeof(regex_t));
+   
+   /* compile regexp */
+   errornum = regcomp(r,octstr_get_cstr(needle),REG_NOSUB | REG_EXTENDED);
+   if (errornum == 0) {
+     /* compile OK */
+     if (regexec(r,octstr_get_cstr(haystack),0,0,0) == 0) {
+       
+       return 0; /* hit */
+     }else{
+       return 1; /* miss */
+     }
+   }else {
+     print_regerror(errornum,r);
+ 
+     regfree(r);
+     gw_free(r);
+     
+     return -1;
+   }
+ }
  
  int octstr_print(FILE *f, Octstr *ostr)
  {
