]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_sqlv2.h
Add Base64 encode/decode functions to the core
[user/henk/code/inspircd.git] / src / modules / m_sqlv2.h
index a9297bd805c8effab3bff60637a34482d9c7203e..9b6bd36b3dce8e4a2d25b6bbb26981f65314ce1a 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
  * See: http://wiki.inspircd.org/Credits
  *
  * This program is free but copyrighted software; see
@@ -61,7 +61,7 @@ public:
  * The error string varies from database software to database software
  * and should be used to display informational error messages to users.
  */
-class SQLerror : public classbase
+class SQLerror
 {
        /** The error id
         */
@@ -149,7 +149,7 @@ public:
  *
  * SQLrequest foo = SQLrequest(this, target, "databaseid", (SQLquery("SELECT.. ?"), parameter, parameter));
  */
-class SQLquery : public classbase
+class SQLquery
 {
 public:
        /** The query 'format string'
@@ -214,6 +214,8 @@ public:
         * Priority queries may 'queue jump' in the request queue.
         */
        bool pri;
+       /** True if this query has been cancelled; send no response */
+       bool cancel;
        /** The query ID, assigned by the SQL api.
         * After your request is processed, this will
         * be initialized for you by the API to a valid request ID,
@@ -240,19 +242,17 @@ public:
        {
        }
 
+       // Copy constructor - XXX probably shouldn't be needed
+       SQLrequest(const SQLrequest& o)
+               : Request(o.source, o.dest, SQLREQID), query(o.query), dbid(o.dbid), pri(o.pri), cancel(o.cancel),
+               id(o.id), error(o.error) {}
+
        /** Set the priority of a request.
         */
        void Priority(bool p = true)
        {
                pri = p;
        }
-
-       /** Set the source of a request. You should not need to use this method.
-        */
-       void SetSource(Module* mod)
-       {
-               source = mod;
-       }
 };
 
 /**
@@ -457,13 +457,13 @@ class SQLhost
 
 /** Overload operator== for two SQLhost objects for easy comparison.
  */
-bool operator== (const SQLhost& l, const SQLhost& r)
+inline bool operator== (const SQLhost& l, const SQLhost& r)
 {
        return (l.id == r.id && l.host == r.host && l.port == r.port && l.name == r.name && l.user == r.user && l.pass == r.pass && l.ssl == r.ssl);
 }
 /** Overload operator!= for two SQLhost objects for easy comparison.
  */
-bool operator!= (const SQLhost& l, const SQLhost& r)
+inline bool operator!= (const SQLhost& l, const SQLhost& r)
 {
        return (l.id != r.id || l.host != r.host || l.port != r.port || l.name != r.name || l.user != r.user || l.pass != r.pass || l.ssl != r.ssl);
 }
@@ -494,10 +494,10 @@ bool operator!= (const SQLhost& l, const SQLhost& r)
  * until pop() is called.
  */
 
-class QueryQueue : public classbase
+class QueryQueue
 {
 private:
-       typedef std::deque<SQLrequest> ReqDeque;
+       typedef std::deque<SQLrequest*> ReqDeque;
 
        ReqDeque priority;      /* The priority queue */
        ReqDeque normal;        /* The 'normal' queue */
@@ -509,9 +509,9 @@ public:
        {
        }
 
-       void push(const SQLrequest &q)
+       void push(SQLrequest *q)
        {
-               if(q.pri)
+               if(q->pri)
                        priority.push_back(q);
                else
                        normal.push_back(q);
@@ -534,7 +534,7 @@ public:
                /* Silently do nothing if there was no element to pop() */
        }
 
-       SQLrequest& front()
+       SQLrequest* front()
        {
                switch(which)
                {
@@ -554,14 +554,8 @@ public:
                                        which = NOR;
                                        return normal.front();
                                }
-
-                               /* This will probably result in a segfault,
-                                * but the caller should have checked totalsize()
-                                * first so..meh - moron :p
-                                */
-
-                               return priority.front();
                }
+               return NULL;
        }
 
        std::pair<int, int> size()
@@ -583,14 +577,16 @@ public:
 private:
        void DoPurgeModule(Module* mod, ReqDeque& q)
        {
-               for(ReqDeque::iterator iter = q.begin(); iter != q.end(); iter++)
+               ReqDeque::iterator iter = q.begin();
+               while (iter != q.end())
                {
-                       if(iter->GetSource() == mod)
+                       if((**iter).source == mod)
                        {
-                               if(iter->id == front().id)
+                               if (*iter == front())
                                {
                                        /* It's the currently active query.. :x */
-                                       iter->SetSource(NULL);
+                                       (**iter).cancel = true;
+                                       iter++;
                                }
                                else
                                {
@@ -598,6 +594,8 @@ private:
                                        iter = q.erase(iter);
                                }
                        }
+                       else
+                               iter++;
                }
        }
 };