bincimap

Log | Files | Refs | LICENSE

session.h (4125B)


      1 /* -*- Mode: c++; -*- */
      2 /*  --------------------------------------------------------------------
      3  *  Filename:
      4  *    src/session.h
      5  *  
      6  *  Description:
      7  *    <--->
      8  *
      9  *  Authors:
     10  *    Andreas Aardal Hanssen <andreas-binc curly bincimap spot org>
     11  *
     12  *  Bugs:
     13  *
     14  *  ChangeLog:
     15  *
     16  *  --------------------------------------------------------------------
     17  *  Copyright 2002-2005 Andreas Aardal Hanssen
     18  *
     19  *  This program is free software; you can redistribute it and/or modify
     20  *  it under the terms of the GNU General Public License as published by
     21  *  the Free Software Foundation; either version 2 of the License, or
     22  *  (at your option) any later version.
     23  *
     24  *  This program is distributed in the hope that it will be useful,
     25  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     26  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     27  *  GNU General Public License for more details.
     28  *
     29  *  You should have received a copy of the GNU General Public License
     30  *  along with this program; if not, write to the Free Software
     31  *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
     32  *  --------------------------------------------------------------------
     33  */
     34 #ifdef HAVE_CONFIG_H
     35 #include <config.h>
     36 #endif
     37 
     38 #ifndef session_h_included
     39 #define session_h_included
     40 #include <string>
     41 #include <vector>
     42 #include <map>
     43 #include <sys/types.h>
     44 #include "argparser.h"
     45 
     46 namespace Binc {
     47 
     48   class Depot;
     49   
     50   //--------------------------------------------------------------------
     51   class Session {
     52   public:
     53     std::map<std::string, std::string> attrs;
     54 
     55     char **unparsedArgs;
     56 
     57     struct {
     58       bool help;
     59       bool version;
     60       bool ssl;
     61       std::string configfile;
     62     } command;
     63 
     64     int idletimeout;
     65     int authtimeout;
     66     int transfertimeout;
     67 
     68     bool mailboxchanges;
     69 
     70     enum State {
     71       NONAUTHENTICATED = 0x01,
     72       AUTHENTICATED = 0x02,
     73       SELECTED = 0x04,
     74       LOGOUT = 0x00
     75     };
     76 
     77     std::map<std::string, std::map<std::string, std::string> > globalconfig;
     78     std::map<std::string, std::map<std::string, std::string> > localconfig;
     79     CommandLineArgs args;
     80 
     81     int timeout() const;
     82 
     83     std::vector<std::string> subscribed;
     84     void subscribeTo(const std::string mailbox);
     85     bool unsubscribeTo(const std::string mailbox);
     86     void loadSubscribes(void);
     87     bool saveSubscribes(void) const;
     88 
     89     const int getState(void) const;
     90     void setState(int n);
     91     void exportToEnv(void);
     92     void importFromEnv(void);
     93     bool parseRequestLine(int argc, char * argv[]);
     94     void assignCommandLineArgs(void);
     95     int getWriteBytes(void) const;
     96     int getReadBytes(void) const;
     97     void addWriteBytes(int);
     98     void addReadBytes(int);
     99     int getBodies(void) const;
    100     int getStatements(void) const;
    101     void addBody(void);
    102     void addStatement(void);
    103     void setLogFacility(int facility);
    104     int getLogFacility(void) const;
    105 
    106     const std::string &getLastError(void) const;
    107     const std::string &getResponseCode(void) const;
    108     const std::string &getIP(void) const;
    109     const std::string &getUserID() const;
    110     pid_t getPid(void);
    111     const std::string &getHostname(void);
    112     void setLastError(const std::string &error) const;
    113     void setResponseCode(const std::string &error) const;
    114     void clearResponseCode(void) const;
    115     void setIP(const std::string &ip);
    116     void setUserID(const std::string &s);
    117 
    118     inline Depot *getDepot(void) const;
    119 
    120     const std::string &operator [] (const std::string &) const;
    121 
    122     //--
    123     void add(const std::string &, const std::string &);
    124 
    125     //--
    126     static Session &getInstance(void);
    127     void initConfig(void);
    128 
    129     bool initialize(int argc, char *argv[]);
    130 
    131   private:
    132     //--
    133     int state;
    134     std::string userid;
    135     std::string ip;
    136     char **argv;
    137     int argc;
    138 
    139     int logfacility;
    140 
    141     int readbytes;
    142     int writebytes;
    143     int statements;
    144     int bodies;
    145 
    146     Depot *depot;
    147 
    148     mutable std::string lastError;
    149     mutable std::string responseCode;
    150 
    151     pid_t pid;
    152     std::string hostname;
    153 
    154     Session(void);
    155   };
    156 
    157   inline Depot *Session::getDepot(void) const
    158   {
    159     return depot;
    160   }
    161 }
    162 
    163 #endif