* merge from dav_rework:
[citadel.git] / webcit / webcit.c
index 5912de4f753334abbe38797b15e278c455d48eac..e88ebf0063a72ecf8782189dfd368cf4d6442067 100644 (file)
@@ -41,7 +41,12 @@ void WebcitAddUrlHandler(const char * UrlString, long UrlSLen,
        Put(HandlerHash, UrlString, UrlSLen, NewHandler, DeleteWebcitHandler);
 }
 
-
+void tmplput_HANDLER_DISPLAYNAME(StrBuf *Target, WCTemplputParams *TP) 
+{
+       wcsession *WCC = WC;
+       if (WCC->Hdr->HR.Handler != NULL)
+               StrBufAppendTemplate(Target, TP, WCC->Hdr->HR.Handler->DisplayName, 0);
+}
 /*
  * web-printing funcion. uses our vsnprintf wrapper
  */
@@ -515,32 +520,57 @@ void ParseREST_URL(void)
        HashList *Floors;
        void *vFloor;
 
+       lprintf(1, "parsing rest URL: %s\n", ChrPtr(WCC->Hdr->HR.ReqLine));
+
        WCC->Directory = NewHash(1, Flathash);
+       WCC->CurrentFloor = NULL;
 
        Buf = NewStrBuf();
-       while (StrBufExtract_NextToken(WCC->Hdr->HR.ReqLine, 
-                                      Buf, &pCh,  '/') >= 0)
+       while (StrBufExtract_NextToken(Buf, WCC->Hdr->HR.ReqLine, &pCh,  '/') >= 0)
        {
-               Put(WCC->Directory, IKEY(i), Buf, HFreeStrBuf);
-               if (i==0)
-                       pFloor = Buf;
+               if (StrLength(Buf) != 0) {
+                       /* ignore empty path segments */
+                       StrBufUnescape(Buf, 1);
+                       Put(WCC->Directory, IKEY(i), Buf, HFreeStrBuf);
+                       if (i==0)
+                               pFloor = Buf;
+                       Buf = NewStrBuf();
+               }
                i++;
-               Buf = NewStrBuf();
        }
-       if (i == 0)
-               FreeStrBuf(&Buf);
-       else if (pFloor != NULL)
+
+       FreeStrBuf(&Buf);
+       if (pFloor != NULL)
        {
                Floors = GetFloorListHash(NULL, NULL);
                
                if (Floors != NULL)
                {
-                       if (GetHash(Floors, SKEY(pFloor), &vFloor))
+                       if (GetHash(WCC->FloorsByName, SKEY(pFloor), &vFloor))
                                WCC->CurrentFloor = (Floor*) vFloor;
                }
        }
 }
 
+int Conditional_REST_DEPTH(StrBuf *Target, WCTemplputParams *TP)
+{
+       long Depth, IsDepth;
+       long offset = 0;
+       wcsession *WCC = WC;
+
+       if (WCC->Hdr->HR.Handler != NULL)
+               offset ++;
+       Depth = GetTemplateTokenNumber(Target, TP, 2, 0);
+       IsDepth = GetCount(WCC->Directory) + offset;
+
+//     LogTemplateError(Target, "bla", 1, TP, "REST_DEPTH: %ld : %ld\n", Depth, IsDepth);
+       if (Depth < 0) {
+               Depth = -Depth;
+               return IsDepth > Depth;
+       }
+       else 
+               return Depth == IsDepth;
+}
 
 
 
@@ -781,9 +811,12 @@ InitModule_WEBCIT
 
        WebcitAddUrlHandler(HKEY("401"), "", 0, authorization_required, ANONYMOUS|COOKIEUNNEEDED);
        RegisterConditional(HKEY("COND:IMPMSG"), 0, ConditionalImportantMesage, CTX_NONE);
+       RegisterConditional(HKEY("COND:REST:DEPTH"), 0, Conditional_REST_DEPTH, CTX_NONE);
+
        RegisterNamespace("CSSLOCAL", 0, 0, tmplput_csslocal, NULL, CTX_NONE);
        RegisterNamespace("IMPORTANTMESSAGE", 0, 0, tmplput_importantmessage, NULL, CTX_NONE);
        RegisterNamespace("TRAILING_JAVASCRIPT", 0, 0, tmplput_trailing_javascript, NULL, CTX_NONE);
+       RegisterNamespace("URL:DISPLAYNAME", 0, 1, tmplput_HANDLER_DISPLAYNAME, NULL, CTX_NONE);
 
        snprintf(dir, SIZ, "%s/webcit.css", static_local_dir);
        if (!access(dir, R_OK)) {