Main Page | Class Hierarchy | Class List | Directories | File List | Class Members

DdtManager.h

00001 /* -*- Mode: C++; c-file-style: "stroustrup"; indent-tabs-mode: nil -*- */
00002 /*
00003  * DdtManager.h
00004  *   Class that calls database and dns routines. This class is an
00005  *   abstraction layer that allows us to use any implementation of
00006  *   a database and dns backend.
00007  *
00008  * $Id: DdtManager.h,v 1.14 2003/04/24 04:44:56 benoit Exp $
00009  *
00010  * Copyright (c) 2000-2001 Remi Lefebvre <remi@dhis.net>
00011  * Copyright (c) 2000 Benoit Joly <benoit@dhis.net>
00012  * Copyright (c) 2000 Luca Filipozzi <lfilipoz@dhis.net>
00013  *
00014  * DDT comes with ABSOLUTELY NO WARRANTY and is licenced under the
00015  * GNU General Public License (version 2 or later). This license
00016  * can be retrieved from http://www.gnu.org/copyleft/gnu.html.
00017  *
00018  */
00019 
00020 #ifndef DDTMANAGER_H
00021 #define DDTMANAGER_H
00022 
00023 //#include <map> // for 0.6
00024 
00025 // general defines
00026 #include "global.h"
00027 
00028 #include "Logger.h"
00029 #include "Dns.h"
00030 #include "Db.h"
00031 
00032 /*
00033 struct runtimeInfo
00034 {
00035     unsigned long addr;
00036     // etc ...
00037 };
00038 */
00039 
00040 class DdtManager
00041 {
00042   public:
00049     DdtManager(Logger *log, Db *db, Dns *dns);
00050 
00054     ~DdtManager(); 
00055 
00056 
00057     /**************  methods for user accounts  **************/
00058 
00064     int addUserAccount(UserAccount *account);
00065 
00070     void delUserAccount(int id);
00071 
00076     void logonUserAccount(int id);
00077 
00082     void logoffUserAccount(int id);
00083 
00089     void updateIPAddress(int id, unsigned long ip);
00090 
00095     void updateTimeStamp(int id);
00096 
00101     void modifyUserAccount(UserAccount *account);
00102 
00103 
00104 
00105     /****************** methods for dns records *****************/
00106     
00114     void addDnsRecord(int id, const char *dname, DnsRecordType type,
00115                       const char *data);
00116 
00124     void delDnsRecord(int id, const char *dname, DnsRecordType type,
00125                       const char *data);
00126 
00132     void delDnsRecords(int id);
00133 
00134 
00139     void listDnsRecords(int id, std::vector<DnsRecord> &dnsRecordList);
00140 
00141 
00142     /***************    compatibility methods only    ****************/
00143     int markOnline(int id, unsigned int ip) 
00144         { updateIPAddress(id, ip); return 0; }
00145 
00146     int markOffline(int id) { logoffUserAccount(id); return 0; }
00147 
00148     int markAlive(int id) { updateTimeStamp(id); return 0; }
00149 
00150     bool getAcctInfo (int id, userAccount *account)
00151         {
00152             db->fetchAccountInfo(id, account);
00153             return 0;
00154         }
00155 
00156     bool fetchAccountInfo(int id, char *field, char *dest, int length)
00157         {
00158             UserAccount a;
00159             db->fetchAccountInfo(id, &a);
00160 
00161             if (strcasecmp(field, "adminPassword") == 0)
00162                 strncpy(dest, a.adminPassword, length);
00163             else if (strcasecmp(field, "updatePassword") == 0)
00164                 strncpy(dest, a.updatePassword, length);
00165             else if (strcasecmp(field, "contactName") == 0)
00166                 strncpy(dest, a.contactName, length);
00167             else if (strcasecmp(field, "contactEmail") == 0)
00168                 strncpy(dest, a.contactEmail, length);
00169             else if (strcasecmp(field, "arch") == 0)
00170                 strncpy(dest, a.arch, length);
00171             else if (strcasecmp(field, "os") == 0)
00172                 strncpy(dest, a.os, length);
00173             else if (strcasecmp(field, "fqdn") == 0)
00174                 strncpy(dest, a.fqdn, length);
00175             else if (strcasecmp(field, "ipAddress") == 0)
00176                 strncpy(dest, a.ipAddress, length);
00177             else
00178                 return false;
00179 
00180             return true;
00181         }
00182 
00183     int findUserAccountIdFromFqdn(char *fqdn)
00184         { 
00185             return db->findUserAccountIdFromFqdn(fqdn);
00186         }
00187 
00188     int modUserAccount(int id, char *field, char *value)
00189         {
00190             db->modUserAccount(id, field, value);
00191             return 0;
00192         }
00193 
00194     int pruneActiveAccount(void (*func)(int, unsigned long, time_t)) 
00195         { return db->pruneActiveAccount(func); }
00196 
00197     unsigned long fetchAcctAddr(int uid) { return db->fetchAcctAddr(uid); }
00198 
00199 
00200   protected:
00201     Logger *log;
00202     Db *db;
00203     Dns *dns;
00204 
00205 //    map<int, runtimeInfo> onlineAccounts; // for 0.6 only
00206 };
00207 
00208 #endif // DDTMANAGER_H

Generated on Tue Sep 13 01:32:46 2005 for DDT Project by  doxygen 1.4.4