Removed logging subsystem from webcit. It's all syslog now.
[citadel.git] / webcit / groupdav_propfind.c
index f3a37294a2b0e60799da5ddce71b6f758ffedfb1..01dbe4f6177300562c5df06edf80a793525937d3 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * Handles GroupDAV PROPFIND requests.
  *
  * A few notes about our XML output:
  *     This makes it difficult to read, but we have discovered clients which
  *     crash when you try to pretty it up.
  *
+ * Copyright (c) 2005-2010 by the citadel.org team
+ *
+ * This program is open source software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
 #include "webcit.h"
 #include "webserver.h"
 #include "groupdav.h"
 
+extern int DisableGzip;
+
 /*
  * Given an encoded UID, translate that to an unencoded Citadel EUID and
  * then search for it in the current room.  Return a message number or -1
@@ -122,7 +137,9 @@ const folder *GetRESTFolder(int IgnoreFloor, HashList *Subfolders)
                        /* Room has more parts than the URL, it might be a sub-room? */
                        else if (iRoom <ThisFolder->nRoomNameParts) 
                        {//// TODO: ThisFolder->nRoomNameParts == urlp - IgnoreFloor???
-                               Put(Subfolders, SKEY(ThisFolder->name), ThisFolder, reference_free_handler);
+                               Put(Subfolders, SKEY(ThisFolder->name), 
+                                   /* Cast away const, its a reference. */
+                                   (void*)ThisFolder, reference_free_handler);
                        }
                }
                else {
@@ -138,7 +155,7 @@ const folder *GetRESTFolder(int IgnoreFloor, HashList *Subfolders)
                        {
                                DeleteHashPos(&itd);
                                
-                               lprintf(0, "5\n");
+                               syslog(0, "5\n");
                                continue;
                        }
                        DeleteHashPos(&itd);
@@ -149,7 +166,7 @@ const folder *GetRESTFolder(int IgnoreFloor, HashList *Subfolders)
                        {
                                DeleteHashPos(&itd);
                                
-                               lprintf(0, "5\n");
+                               syslog(0, "5\n");
                                continue;
                        }
                        DeleteHashPos(&itfl);
@@ -174,14 +191,13 @@ const folder *GetRESTFolder(int IgnoreFloor, HashList *Subfolders)
 
 
 
-long GotoRestRoom()
+long GotoRestRoom(HashList *SubRooms)
 {
        int IgnoreFloor = 0; /* deprecated... */
        wcsession *WCC = WC;
        long Count;
        long State;
        const folder *ThisFolder;
-       HashList *SubRooms = NULL;
 
        State = REST_TOPLEVEL;
 
@@ -205,33 +221,33 @@ long GotoRestRoom()
        {
                IgnoreFloor = 0;
                State |= REST_IN_FLOOR;
-               SubRooms = NewHash(1, Flathash);
+
                ThisFolder = GetRESTFolder(IgnoreFloor, SubRooms);
                if (ThisFolder != NULL)
                {
                        if (WCC->ThisRoom != NULL)
-                               if (CompareRooms(WCC->ThisRoom, ThisFolder))
+                               if (CompareRooms(WCC->ThisRoom, ThisFolder) != 0)
                                        gotoroom(ThisFolder->name);
                        State |= REST_IN_ROOM;
+                       
                }
+               if (GetCount(SubRooms) > 0)
+                       State |= REST_HAVE_SUB_ROOMS;
        }
        if ((WCC->ThisRoom != NULL) && 
            (Count + IgnoreFloor > 3))
        {
-               if (WCC->Hdr->HR.Handler.RID(ExistsID, IgnoreFloor))
+               if (WCC->Hdr->HR.Handler->RID(ExistsID, IgnoreFloor))
                {
-                       State |= REST_GOT_EUID;
-               }/////TODO
+                       State |= REST_GOT_LOCAL_PART;
+               }
                else {
                        /// WHOOPS, not there???
+                       State |= REST_NONEXIST;
                }
 
 
        }
-       /// TODO: ID detection
-       /// TODO: File detection
-
-
        return State;
 }
 
@@ -274,7 +290,8 @@ void groupdav_collection_list(void)
        groupdav_common_headers();
        hprintf("Date: %s\r\n", datestring);
        hprintf("Content-type: text/xml\r\n");
-       hprintf("Content-encoding: identity\r\n");
+       if (DisableGzip || (!WCC->Hdr->HR.gzip_ok))     
+               hprintf("Content-encoding: identity\r\n");
 
        begin_burst();
 
@@ -421,6 +438,10 @@ void groupdav_collection_list(void)
  */
 void groupdav_propfind(void) 
 {
+#ifdef DEV_RESTDAV
+       HashList *SubRooms = NULL;
+       long State;
+#endif
        wcsession *WCC = WC;
        StrBuf *dav_roomname;
        StrBuf *dav_uid;
@@ -434,7 +455,6 @@ void groupdav_propfind(void)
        int i;
        char datestring[256];
        time_t now;
-       long State;
 
        now = time(NULL);
        http_datestring(datestring, sizeof datestring, now);
@@ -448,9 +468,10 @@ void groupdav_propfind(void)
         * If the room name is blank, the client is requesting a
         * folder list.
         */
-       State = GotoRestRoom();
+       SubRooms = NewHash(1, Flathash);
+       State = GotoRestRoom(SubRooms);
        if (((State & REST_IN_ROOM) == 0) ||
-           (((State & (REST_GOT_EUID|REST_GOT_ID|REST_GOT_FILENAME)) == 0) &&
+           (((State & (REST_GOT_LOCAL_PART)) == 0) &&
             (WCC->Hdr->HR.dav_depth == 0)))
        {
                now = time(NULL);
@@ -464,7 +485,8 @@ void groupdav_propfind(void)
                groupdav_common_headers();
                hprintf("Date: %s\r\n", datestring);
                hprintf("Content-type: text/xml\r\n");
-               hprintf("Content-encoding: identity\r\n");
+               if (DisableGzip || (!WCC->Hdr->HR.gzip_ok))     
+                       hprintf("Content-encoding: identity\r\n");
 
                begin_burst();
 
@@ -476,14 +498,21 @@ void groupdav_propfind(void)
                end_burst();
                FreeStrBuf(&dav_roomname);
                FreeStrBuf(&dav_uid);
+               FreeHashList(&SubRooms);
                return;
        }
 
-       if ((State & (REST_GOT_EUID|REST_GOT_ID|REST_GOT_FILENAME)) == 0) {
+       if ((State & (REST_GOT_LOCAL_PART)) == 0) {
                readloop(headers, eReadEUIDS);
+               FreeHashList(&SubRooms);
                return;
 
        }
+
+
+       
+       FreeHashList(&SubRooms);
+
 #endif
 
        /*
@@ -544,7 +573,8 @@ void groupdav_propfind(void)
                groupdav_common_headers();
                hprintf("Date: %s\r\n", datestring);
                hprintf("Content-type: text/xml\r\n");
-               hprintf("Content-encoding: identity\r\n");
+               if (DisableGzip || (!WCC->Hdr->HR.gzip_ok))     
+                       hprintf("Content-encoding: identity\r\n");
        
                begin_burst();
        
@@ -594,7 +624,8 @@ void groupdav_propfind(void)
        groupdav_common_headers();
        hprintf("Date: %s\r\n", datestring);
        hprintf("Content-type: text/xml\r\n");
-       hprintf("Content-encoding: identity\r\n");
+       if (DisableGzip || (!WCC->Hdr->HR.gzip_ok))     
+               hprintf("Content-encoding: identity\r\n");
 
        begin_burst();
 
@@ -725,6 +756,8 @@ int ParseMessageListHeaders_EUID(StrBuf *Line,
 {
        Msg->euid = NewStrBuf();
        StrBufExtract_NextToken(Msg->euid,  Line, pos, '|');
+       Msg->date = StrBufExtractNext_long(Line, pos, '|');
+       
        return StrLength(Msg->euid) > 0;
 }