Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

AccessList.h

Go to the documentation of this file.
00001 #ifndef _AccessList_h_
00002 #define _AccessList_h_
00003 #include <ctype.h>
00004 #include <stdio.h>
00005 #include <netdb.h>
00006 #include <sys/param.h>
00007 
00008 #include <sys/socket.h>
00009 #include <netinet/in.h>
00010 #include <arpa/inet.h>
00011 
00012 #include <iostream>
00013 #include <fstream>
00014 #include <string>
00015 #include <vector>
00016 
00017 #include "config.h"
00018 #include "Debug.h"
00019 #include "Error.h"
00020 //#include "OverviewFmt.h"
00021 #include "NewsgroupFilter.h"
00022 #include "Lexer.h"
00023 
00024 
00025 
00026 /*\class Authentication
00027  * \author Herbert Straub
00028  * \date 2003
00029  * \brief Authentication manages the parameter Authentication
00030  *
00031  * Authentication manages the values of the parameter Authentication.
00032  * The Authentication parameter ist a string with fields, seperated by
00033  * ":". The field[0] is the AuthenticationType (none, unix, file, ...).
00034  * All other fields are AuthenticationType specific.
00035  */
00036 class Authentication {
00037   public:
00038         
00039         /*
00040          * The default value for AuthenticationType is none.
00041          */
00042         Authentication () : defAuth("none"){};
00043 
00044         /*
00045          * The AuthString will be splitted into fields and stored.
00046          */
00047         void set (const std::string &AuthString);
00048 
00049         /*
00050          * Returns the field[0]. Per Definition is filed[0] the
00051          * AuthenticationType.
00052          * \param AuthString the authentication string (unix:*:*::debug)
00053          */
00054         const std::string& getType (void);
00055 
00056         /*
00057          * Returns the value of field with the number nr.
00058          */
00059         const std::string& getField(int nr);
00060 
00061         /*
00062          * Returns the number of stored fields.
00063          */
00064         int getNrOfFields (void);
00065 
00066         /*
00067          * Modify (append) the specified field with the value.
00068          * \param nr Fieldnumber
00069          * \param v value
00070          * \throw bounding error of type char
00071          */
00072         void modifyField (unsigned int nr, const char *v);
00073 
00074         /*
00075          * Modify the current object with the source.
00076          * Walk through the lists and append each 
00077          * destination field, with the source field.
00078          * \param start start with element nr start
00079          * \param source of modify operation
00080          */
00081         void modify (unsigned int start, Authentication &source);
00082 
00083         /*
00084          * Append the next field with the value.
00085          * \param v value
00086          */
00087         void appendField (const char *v);
00088 
00089         /*
00090          * print the actual setting to std:ostream
00091          */
00092         void printParameters (std::ostream *pOut) const;
00093 
00094         /*
00095          * Type equal and ignore a : on the last position
00096          * \return 0 ... equal 
00097          */
00098         int typeEqual (const std::string &v);
00099 
00100   private:
00101         std::vector<std::string> fields;
00102         string defAuth;
00103 };
00104 
00111 class AccessEntry {
00112       public:
00113         char hostname[MAXHOSTNAMELEN];
00114 
00115         enum {
00116                 af_read = 0x1,
00117                 af_post = 0x2,
00118                 af_debug = 0x4,
00119                 af_authentication = 0x8,
00120         };
00121 
00122         unsigned int access_flags;
00123 
00124         NewsgroupFilter list;   
00125         NewsgroupFilter read;   
00126         NewsgroupFilter postTo; 
00127         Authentication authentication;
00128         string PAMServicename;  
00129 
00130          AccessEntry() {
00131                 init();
00132         } void init() {
00133                 hostname[0] = '\0';
00134                 access_flags = 0x0;
00135                 PAMServicename = PAM_DEFAULT_SERVICENAME;
00136         }
00137 
00138         void clear() {
00139                 init();
00140         }
00141         void modifyAccessFlags (const std::string &flags);
00142         friend std::ostream & operator<<(std::ostream & os,
00143                                          const AccessEntry & ae);
00144 
00145         /*
00146          * print the actual setting to std:ostream
00147          * \author Herbert Straub
00148          * \date 2003
00149          */
00150         void printParameters (std::ostream *pOut);
00151 
00152         /*
00153          * Print the value of access_flags (translated from 
00154          * Hex Values to String) to std::ostream.
00155          * \author Herbert Straub
00156          * \date 2003
00157          */
00158         void printAccessFlags (std::ostream *pOut) const;
00159 };
00160 
00167 class AccessList {
00168       private:
00169         std::vector < AccessEntry > vector;
00170 
00171       public:
00172         AccessList() {
00173         } AccessEntry *client(const char *name, struct in_addr addr);
00174         void init() {
00175                 vector.clear();
00176         }
00177         void read(Lexer & lex);
00178         void readClient(Lexer & lex, const char *address);
00179 
00180         /*
00181          * print the actual setting to std:ostream
00182          * \author Herbert Straub
00183          * \date 2003
00184          */
00185         void printParameters (std::ostream *pOut);
00186 };
00187 
00188 
00189 // Inline methods
00190 inline const std::string& Authentication::getType (void)
00191 {
00192         if (fields.size() == 0) {
00193                 return defAuth;
00194         } else {
00195                 return fields[0];
00196         }
00197 }
00198 
00199 inline const std::string& Authentication::getField(int nr) 
00200 {
00201         return fields[nr];
00202 }
00203 inline int Authentication::getNrOfFields (void)
00204 {
00205         return fields.size();
00206 }
00207 inline void AccessEntry::printAccessFlags (std::ostream *pOut) const
00208 {
00209         if (access_flags == 0x0) {
00210                 *pOut << " none";
00211         }
00212         if (access_flags & af_read) {
00213                 *pOut << " read";
00214         }
00215         if (access_flags & af_post) {
00216                 *pOut << " post";
00217         }
00218         if (access_flags & af_debug) {
00219                 *pOut << " debug";
00220         }
00221 }
00222 inline void Authentication::modifyField (unsigned int nr, const char *v)
00223 {
00224         if (nr >= fields.size())
00225                 throw ("bounding error");
00226 
00227         fields[nr] += v;
00228 }
00229 
00230 inline void Authentication::appendField (const char *v)
00231 {
00232         fields.push_back (v);
00233 }
00234 #endif

Generated on Sun Oct 24 21:08:17 2004 for NewsCache by doxygen 1.3.6-20040222