save location match results

Tue, 25 Nov 2025 19:44:58 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 25 Nov 2025 19:44:58 +0100
changeset 642
7b71e2973acc
parent 641
159172937c86
child 643
f4dc9b37a250

save location match results

src/server/daemon/location.c file | annotate | diff | comparison | revisions
src/server/daemon/location.h file | annotate | diff | comparison | revisions
--- a/src/server/daemon/location.c	Sun Nov 23 15:05:37 2025 +0100
+++ b/src/server/daemon/location.c	Tue Nov 25 19:44:58 2025 +0100
@@ -96,7 +96,7 @@
     WSLocationMatch match = WS_LOCATION_MATCH_EXACT;
     cxmutstr match_str;
     
-    int regex_flags = REG_EXTENDED | REG_NOSUB;
+    int regex_flags = REG_EXTENDED;
     int argc = serverconfig_directive_count_args(obj);
     if(argc == 2) {
         // arg0: match type
@@ -176,13 +176,13 @@
     return 0;
 }
 
-int location_match(WSLocation *loc, cxstring uri) {
+int location_match(WSLocation *loc, cxstring uri, regmatch_t *match) {
     if(loc->match == WS_LOCATION_MATCH_EXACT) {
         return !cx_strcmp(loc->match_string, uri);
     } else if(loc->match == WS_LOCATION_MATCH_PREFIX) {
         return cx_strprefix(uri, loc->match_string);
     } else {
-        return regexec(&loc->regex, uri.ptr, 0, NULL, 0) == 0;
+        return regexec(&loc->regex, uri.ptr, 0, match, WS_LOCATION_NMATCH) == 0;
     }
     return 0;
 }
@@ -195,7 +195,7 @@
     ZERO(config, sizeof(WSLocationConfig));
     
     while(loc) {
-        if(location_match(loc, uri)) {
+        if(location_match(loc, uri, config->match)) {
             if(location_apply_config(config, loc)) {
                 return NULL;
             }
--- a/src/server/daemon/location.h	Sun Nov 23 15:05:37 2025 +0100
+++ b/src/server/daemon/location.h	Tue Nov 25 19:44:58 2025 +0100
@@ -43,6 +43,8 @@
 extern "C" {
 #endif
     
+#define WS_LOCATION_NMATCH 16
+    
 typedef struct WSLocation       WSLocation;
 typedef struct WSLocationConfig WSLocationConfig;
 
@@ -55,6 +57,11 @@
     
 struct WSLocationConfig {
     /*
+     * location regex match results
+     */
+    regmatch_t match[WS_LOCATION_NMATCH];
+    
+    /*
      * Activate dirindex setting
      */
     WSBool set_dirindex;
@@ -146,7 +153,7 @@
 WSLocation* cfg_location_get(ServerConfiguration *cfg, ConfigNode *obj);
 
 int location_apply_config(WSLocationConfig *target, WSLocation *loc);
-int location_match(WSLocation *loc, cxstring uri);
+int location_match(WSLocation *loc, cxstring uri, regmatch_t *match);
 WSLocationConfig* location_match_and_get_config(pool_handle_t *pool, cxstring uri, WSLocation *loc);
 WSLocationConfig* cfg_location_match(Session *sn, Request *rq);
 

mercurial