[PATCH v2 17/23] conf: convert over to use GRegex for regular expressions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Reviewed-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 src/conf/domain_event.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index b33589f472..f7d1a38e46 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -22,8 +22,6 @@
 
 #include <config.h>
 
-#include <regex.h>
-
 #include "domain_event.h"
 #include "object_event.h"
 #include "object_event_private.h"
@@ -2009,7 +2007,7 @@ virDomainQemuMonitorEventNew(int id,
  * deregisters.  */
 struct virDomainQemuMonitorEventData {
     char *event;
-    regex_t regex;
+    GRegex *regex;
     unsigned int flags;
     void *opaque;
     virFreeCallback freecb;
@@ -2241,7 +2239,7 @@ virDomainQemuMonitorEventFilter(virConnectPtr conn ATTRIBUTE_UNUSED,
     if (data->flags == -1)
         return true;
     if (data->flags & VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX)
-        return regexec(&data->regex, monitorEvent->event, 0, NULL, 0) == 0;
+        return g_regex_match(data->regex, monitorEvent->event, 0, NULL) == TRUE;
     if (data->flags & VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_NOCASE)
         return STRCASEEQ(monitorEvent->event, data->event);
     return STREQ(monitorEvent->event, data->event);
@@ -2255,7 +2253,7 @@ virDomainQemuMonitorEventCleanup(void *opaque)
 
     VIR_FREE(data->event);
     if (data->flags & VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX)
-        regfree(&data->regex);
+        g_regex_unref(data->regex);
     if (data->freecb)
         (data->freecb)(data->opaque);
     VIR_FREE(data);
@@ -2306,20 +2304,17 @@ virDomainQemuMonitorEventStateRegisterID(virConnectPtr conn,
         return -1;
     data->flags = flags;
     if (event && flags != -1) {
-        int rflags = REG_NOSUB;
-
-        if (flags & VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_NOCASE)
-            rflags |= REG_ICASE;
         if (flags & VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX) {
-            int err = regcomp(&data->regex, event, rflags);
+            int cflags = 0;
+            g_autoptr(GError) err = NULL;
 
-            if (err) {
-                char error[100];
-                regerror(err, &data->regex, error, sizeof(error));
+            if (flags & VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_NOCASE)
+                cflags |= G_REGEX_CASELESS;
+            data->regex = g_regex_new(event, cflags, 0, &err);
+            if (!data->regex) {
                 virReportError(VIR_ERR_INVALID_ARG,
                                _("failed to compile regex '%s': %s"),
-                               event, error);
-                regfree(&data->regex);
+                               event, err->message);
                 VIR_FREE(data);
                 return -1;
             }
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux