src/server/safs/nametrans.c

changeset 136
9b48a1427aef
parent 117
a94cf2e94492
child 137
ca0cf1016a8b
--- a/src/server/safs/nametrans.c	Tue Dec 27 18:42:36 2016 +0100
+++ b/src/server/safs/nametrans.c	Tue Dec 27 19:36:19 2016 +0100
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 2013 Olaf Wintermann. All rights reserved.
+ * Copyright 2016 Olaf Wintermann. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -158,3 +158,35 @@
 }
 
 
+/*
+ * provisional rewrite saf
+ */
+int simple_rewrite(pblock *pb, Session *sn, Request *rq) {
+    char *from = pblock_findval("from", pb);
+    char *root = pblock_findval("root", pb);
+    char *path = pblock_findval("path", pb);
+    char *name = pblock_findval("name", pb);
+    
+    if(!from || !path || !root) {
+        log_ereport(LOG_MISCONFIG, "simple-rewrite: missing parameter (from, root, path)");
+        return REQ_ABORTED;
+    }
+    
+    char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
+    sstr_t u = sstr(uri);
+    sstr_t f = sstr(from);
+    if(sstrprefix(u, f)) {
+        sstr_t suf = sstrsubs(u, f.length);
+        sstr_t ppath = sstrcat(2, sstr(path), suf);
+        
+        request_set_path(sstr(root), ppath, rq->vars);
+        free(ppath.ptr);
+        
+        if(name) {
+            // add object to rq->vars
+            pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars);
+        }
+    }
+    
+    return REQ_NOACTION;
+}

mercurial