src/server/nametrans.c

changeset 10
e3ae779232a9
parent 6
ce8fecc9847d
--- a/src/server/nametrans.c	Thu Dec 29 18:51:23 2011 +0100
+++ b/src/server/nametrans.c	Fri Dec 30 14:06:56 2011 +0100
@@ -39,3 +39,43 @@
 
     return REQ_NOACTION;
 }
+
+/*
+ * assign_name
+ *
+ * Assigns the name specified by the name parameter if the uri has the
+ * specified prefix.
+ *
+ * pblock parameter:
+ * name     object name
+ * from     optional uri prefix
+ */
+int assign_name(pblock *pb, Session *sn, Request *rq) {
+    /* TODO: expression instead of simple prefix */
+
+    char *name = pblock_findkeyval(pb_key_name, pb);
+    char *from = pblock_findkeyval(pb_key_from, pb);
+
+    if(!name) {
+        /* TODO: add log */
+        protocol_status(sn, rq, 500, NULL);
+        return REQ_ABORTED;
+    }
+    
+    if(from) {
+        char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb);
+        char c;
+        int i = 0;
+        while((c = from[i]) != 0) {
+            if(c != uri[i]) {
+                return REQ_NOACTION;
+            }
+            i++;
+        }
+    }
+
+    /* add object to rq->vars */
+    pblock_kvinsert(pb_key_name, name, strlen(name), rq->vars);
+
+    return REQ_NOACTION;
+}

mercurial