Deleting rooms: Invalid pointers; safeguarrds
[citadel.git] / webcit / roomops.c
index f16fb7f585708ed42480570359b96c863edea1e9..09534742eeaae5ba09b01b4222c68ef64487d60d 100644 (file)
@@ -1,21 +1,21 @@
 /*
  * Lots of different room-related operations.
  *
- * Copyright (c) 1996-2011 by the citadel.org team
+ * Copyright (c) 1996-2012 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.
+ * modify it under the terms of the GNU General Public License, version 3.
+ * 
+ * 
  *
  * 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"
@@ -354,20 +354,30 @@ void ParseGoto(folder *room, StrBuf *Line)
  */
 void delete_room(void)
 {
-       StrBuf *Line;
+       StrBuf *Line = NewStrBuf();
+       const StrBuf *GoBstr;
        
-       serv_puts("KILL 1");
-       StrBuf_ServGetln(Line);
-       if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
-               display_main_menu();
-       } else {
-               StrBuf *Buf;
-               
-               FlushRoomlist ();
-               Buf = NewStrBufPlain(HKEY("_BASEROOM_"));
-               smart_goto(Buf);
-               FreeStrBuf(&Buf);
+       GoBstr = sbstr("go");
+
+       if (GoBstr != NULL)
+       {
+               if (gotoroom(GoBstr) == 200)
+               {
+                       serv_puts("KILL 1");
+                       StrBuf_ServGetln(Line);
+                       if (GetServerStatusMsg(Line, NULL, 1, 2) == 2) {
+                               StrBuf *Buf;
+                               
+                               FlushRoomlist ();
+                               Buf = NewStrBufPlain(HKEY("_BASEROOM_"));
+                               smart_goto(Buf);
+                               FreeStrBuf(&Buf);
+                               FreeStrBuf(&Line);
+                               return;
+                       }
+               }
        }
+       display_main_menu();
        FreeStrBuf(&Line);
 }
 
@@ -481,7 +491,7 @@ int SaveRoomAide(folder *Room)
 }
 
 
-int GetCurrentRoomFlags(folder *Room)
+int GetCurrentRoomFlags(folder *Room, int CareForStatusMessage)
 {
        StrBuf *Buf;
 
@@ -492,8 +502,10 @@ int GetCurrentRoomFlags(folder *Room)
                FlushStrBuf(Room->XAPass);
                FlushStrBuf(Room->Directory);
                StrBufCutLeft(Buf, 4);
-               AppendImportantMessage (SKEY(Buf));
+               if (CareForStatusMessage)
+                       AppendImportantMessage (SKEY(Buf));
                FreeStrBuf(&Buf);
+               Room->XALoaded = 2;
                return 0;
        } else {
                const char *Pos;
@@ -560,10 +572,10 @@ void LoadRoomXA (void)
 {
        wcsession *WCC = WC;
                
-       if (WCC->CurRoom.XALoaded)
+       if (WCC->CurRoom.XALoaded > 0)
                return;
 
-       GetCurrentRoomFlags(&WCC->CurRoom);
+       GetCurrentRoomFlags(&WCC->CurRoom, 0);
 }
 
 
@@ -658,7 +670,7 @@ void LoadXRoomXCountFiles(void)
 void toggle_self_service(void) {
        wcsession *WCC = WC;
 
-       if (GetCurrentRoomFlags (&WCC->CurRoom) == 0)
+       if (GetCurrentRoomFlags (&WCC->CurRoom, 1) == 0)
                return;
 
        if (yesbstr("QR2_SelfList")) 
@@ -707,8 +719,10 @@ void editroom(void)
                http_transmit_thing(ChrPtr(do_template("room_edit")), 0);
                return;
        }
-       if (GetCurrentRoomFlags (&WCC->CurRoom) == 0)
+       if (GetCurrentRoomFlags (&WCC->CurRoom, 1) == 0) {
+               http_transmit_thing(ChrPtr(do_template("room_edit")), 0);
                return;
+       }
 
        LoadRoomAide();
 
@@ -849,7 +863,7 @@ void do_invt_kick(void)
        wcsession *WCC = WC;
 
 
-       if (GetCurrentRoomFlags(&WCC->CurRoom) == 1)
+       if (GetCurrentRoomFlags(&WCC->CurRoom, 1) == 1)
        {
                const char *Pos;
                UserNames = sbstr("username");
@@ -1023,7 +1037,6 @@ void set_room_policy(void) {
  * Perform changes to a room's network configuration
  */
 void netedit(void) {
-       FILE *fp;
        char buf[SIZ];
        char line[SIZ];
        char cmpa0[SIZ];
@@ -1032,8 +1045,12 @@ void netedit(void) {
        char cmpb1[SIZ];
        int i, num_addrs;
        StrBuf *Line;
+       StrBuf *TmpBuf;
        int Done;
 
+        if (havebstr("force_room")) {
+                gotoroom(sbstr("force_room"));
+       }
        /*/ TODO: do line dynamic! */
        if (havebstr("line_pop3host")) {
                strcpy(line, bstr("prefix"));
@@ -1058,18 +1075,11 @@ void netedit(void) {
                return;
        }
 
-
-       fp = tmpfile();
-       if (fp == NULL) {
-               http_transmit_thing(ChrPtr(do_template("room_edit")), 0);
-               return;
-       }
-
        Line = NewStrBuf();
+       TmpBuf = NewStrBuf();
        serv_puts("GNET");
        StrBuf_ServGetln(Line);
        if  (GetServerStatus(Line, NULL) != 1) {
-               fclose(fp);
                AppendImportantMessage(SRV_STATUS_MSG(Line));   
                FreeStrBuf(&Line);
                http_transmit_thing(ChrPtr(do_template("room_edit")), 0);
@@ -1093,26 +1103,24 @@ void netedit(void) {
                        if ( (strcasecmp(cmpa0, cmpb0)) 
                             || (strcasecmp(cmpa1, cmpb1)) ) {
                                StrBufAppendBufPlain(Line, HKEY("\n"), 0);
-                               fwrite(SKEY(Line), 1, fp);
+                               StrBufAppendBuf(TmpBuf, Line, 0);
                        }
                }
        }
 
-       rewind(fp);
        serv_puts("SNET");
        StrBuf_ServGetln(Line);
        if  (GetServerStatus(Line, NULL) != 4) {
-               fclose(fp);
+
                AppendImportantMessage(SRV_STATUS_MSG(Line));   
                http_transmit_thing(ChrPtr(do_template("room_edit")), 0);
                FreeStrBuf(&Line);
+               FreeStrBuf(&TmpBuf);
                return;
        }
 
-       while (fgets(buf, sizeof buf, fp) != NULL) {
-               buf[strlen(buf)-1] = 0;
-               serv_puts(buf);
-       }
+       serv_putbuf(TmpBuf);
+       FreeStrBuf(&TmpBuf);
 
        if (havebstr("add_button")) {
                num_addrs = num_tokens(bstr("line"), ',');
@@ -1134,7 +1142,6 @@ void netedit(void) {
        }
 
        serv_puts("000");
-       fclose(fp);
        FlushIgnetCfgs(&WC->CurRoom);
        FreeStrBuf(&Line);