]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_permchannels.cpp
Fix iteration of ServerInstance->Users->local_users now that QuitUser can modify...
[user/henk/code/inspircd.git] / src / modules / m_permchannels.cpp
index 41a5daf333efb06cb1a6881ad342796ea354779d..a0b2adea2faa4b5e02c308c1084f161a8b87400f 100644 (file)
@@ -17,7 +17,7 @@
 
 // Not in a class due to circular dependancy hell.
 static std::string permchannelsconf;
-static bool WriteDatabase(InspIRCd *ServerInstance)
+static bool WriteDatabase()
 {
        FILE *f;
 
@@ -43,16 +43,43 @@ static bool WriteDatabase(InspIRCd *ServerInstance)
        }
 
        // Now, let's write.
-       Channel *c = NULL;
-
        for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); i++)
        {
-               c = i->second;
+               Channel* chan = i->second;
+               if (!chan->IsModeSet('P'))
+                       continue;
 
-               if (c->IsModeSet('P'))
+               char line[1024];
+               const char* items[] =
                {
-                       fprintf(f, "<permchannels channel=\"%s\" topic=\"%s\" modes=\"%s\">\n", c->name.c_str(), c->topic.c_str(), c->ChanModes(true));
+                       "<permchannels channel=",
+                       chan->name.c_str(),
+                       " topic=",
+                       chan->topic.c_str(),
+                       " modes=",
+                       chan->ChanModes(true),
+                       ">\n"
+               };
+
+               int lpos = 0, item = 0, ipos = 0;
+               while (lpos < 1022 && item < 7)
+               {
+                       char c = items[item][ipos++];
+                       if (c == 0)
+                       {
+                               // end of this string; hop to next string, insert a quote
+                               item++;
+                               ipos = 0;
+                               c = '"';
+                       }
+                       else if (c == '\\' || c == '"')
+                       {
+                               line[lpos++] = '\\';
+                       }
+                       line[lpos++] = c;
                }
+               line[--lpos] = 0;
+               fputs(line, f);
        }
 
        int write_error = 0;
@@ -61,7 +88,7 @@ static bool WriteDatabase(InspIRCd *ServerInstance)
        if (write_error)
        {
                ServerInstance->Logs->Log("m_permchannels",DEFAULT, "permchannels: Cannot write to new database! %s (%d)", strerror(errno), errno);
-               ServerInstance->SNO->WriteToSnoMask('x', "database: cannot write to new db: %s (%d)", strerror(errno), errno);
+               ServerInstance->SNO->WriteToSnoMask('a', "database: cannot write to new db: %s (%d)", strerror(errno), errno);
                return false;
        }
 
@@ -69,7 +96,7 @@ static bool WriteDatabase(InspIRCd *ServerInstance)
        if (rename(tempname.c_str(), permchannelsconf.c_str()) < 0)
        {
                ServerInstance->Logs->Log("m_permchannels",DEFAULT, "permchannels: Cannot move new to old database! %s (%d)", strerror(errno), errno);
-               ServerInstance->SNO->WriteToSnoMask('x', "database: cannot replace old with new db: %s (%d)", strerror(errno), errno);
+               ServerInstance->SNO->WriteToSnoMask('a', "database: cannot replace old with new db: %s (%d)", strerror(errno), errno);
                return false;
        }
 
@@ -100,7 +127,7 @@ class PermChannel : public ModeHandler
                                channel->SetMode('P',true);
 
                                // Save permchannels db if needed.
-                               WriteDatabase(ServerInstance);
+                               WriteDatabase();
                                return MODEACTION_ALLOW;
                        }
                }
@@ -134,7 +161,7 @@ class PermChannel : public ModeHandler
                                channel->SetMode('P',false);
 
                                // Save permchannels db if needed.
-                               WriteDatabase(ServerInstance);
+                               WriteDatabase();
                                return MODEACTION_ALLOW;
                        }
                }
@@ -253,7 +280,7 @@ public:
        virtual ModResult OnRawMode(User* user, Channel* chan, const char mode, const std::string &param, bool adding, int pcnt)
        {
                if (chan && chan->IsModeSet('P'))
-                       WriteDatabase(ServerInstance);
+                       WriteDatabase();
 
                return MOD_RES_PASSTHRU;
        }
@@ -261,7 +288,7 @@ public:
        virtual void OnPostTopicChange(User*, Channel *c, const std::string&)
        {
                if (c->IsModeSet('P'))
-                       WriteDatabase(ServerInstance);
+                       WriteDatabase();
        }
 
        virtual Version GetVersion()