filesys.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           filesys.h  -  description
00003                              -------------------
00004     begin                : Thu Dec 9 2004
00005     copyright            : (C) 2004 by VooDooMan
00006     email                : vdmfun@hotmail.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010 
00011 VooDoo cIRCle - an IRC (ro)bot
00012 Copyright (C) 2004 by Marian VooDooMan Meravy (vdmfun@hotmail.com)
00013 
00014 This program is free software; you can redistribute it and/or
00015 modify it under the terms of the GNU General Public License
00016 as published by the Free Software Foundation; either version 2
00017 of the License, or (at your option) any later version.
00018 
00019 This program is distributed in the hope that it will be useful,
00020 but WITHOUT ANY WARRANTY; without even the implied warranty of
00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022 GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License
00025 along with this program; if not, write to the Free Software
00026 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00027 
00028 ****************************************************************************/
00029 
00030 /*!
00031     \file
00032     \brief Handles filesystem
00033 */
00034 
00035 #ifndef _FILESYS_H_
00036 #define _FILESYS_H_
00037 
00038 #include <string>
00039 
00040 #include "shared.h"
00041 
00042 using namespace std;
00043 
00044 /*!
00045     \def FILESYS_NOT_PUBLISHED
00046     \brief File is not published / doesn't have attributes set yet
00047 */
00048 #define FILESYS_NOT_PUBLISHED       1
00049 /*!
00050     \def FILESYS_GOT_FILE
00051     \brief Have got a file
00052 */
00053 #define FILESYS_GOT_FILE            2
00054 /*!
00055     \def FILESYS_GOT_SECURE_MSG
00056     \brief Have got a secured message / file
00057 */
00058 #define FILESYS_GOT_SECURE_MSG      3
00059 /*!
00060     \def FILESYS_GOT_INCOMPLETE
00061     \brief File is not complete downloaded
00062 */
00063 #define FILESYS_GOT_INCOMPLETE      4
00064 
00065 /*!
00066     \def FILESYS_ALREADY_EXISTS
00067     \brief File with such public name exists, and CANNOT be replaced, because you are NOT OWNER
00068 */
00069 #define FILESYS_ALREADY_EXISTS      5
00070 /*!
00071     \def FILESYS_REPLACED
00072     \brief File with such public name exists, and will be replaced, because you are OWNER
00073 */
00074 #define FILESYS_REPLACED            6
00075 
00076 /*!
00077     \brief Specifies type of file in the filesystem
00078     \author VooDooMan
00079     \version 1
00080     \date 2004
00081 */
00082 enum e_file_type {
00083     ft_invalid=0,                            //!< Invalid entry
00084     ft_file,                                 //!< Object is a file
00085     ft_message                               //!< Object is a message
00086 };
00087 
00088 /*!
00089     \brief Stores informnations about access to the object in the filesystem
00090     \author VooDooMan
00091     \version 1
00092     \date 2004
00093 */
00094 struct s_access {
00095     bool all_users;                             //!< All users has access to this object
00096     string user_name;                           //!< Name of user that this access structure belongs to (undefined if all_users set to true)
00097     bool owner;                                 //!< The user is OWNER
00098     bool read;                                  //!< The user has READ permission
00099     bool del;                                   //!< The user has DELETE permission
00100     bool notify_owner;                          //!< OWNER wants to be notified when user reads this object
00101     bool notify_user;                           //!< User should be notified about this object
00102     bool secure;                                //!< SECURE flag: user must be authenticated in order to read this object
00103     string all_on_channel;                      //!< The message / file is for all users on this channel
00104     bool also_unknown;                          //!< The message / file is for all users on this channel (all_on_channel) and also for unknown users
00105 
00106     string notify_owner_message;                //!< If this object is a file, there is stored message for OWNER when user reads the file
00107     string notify_user_message;                 //!< If this object is a file, there is stored message for USER (a description why they should read this file)
00108 
00109     /*!
00110         \brief Clears the structure
00111         \author VooDooMan
00112         \version 1
00113         \date 2004
00114     */
00115     void clear()
00116     {
00117         all_users=false;
00118         user_name="";
00119         owner=false;
00120         read=false;
00121         del=false;
00122         notify_owner=false;
00123         notify_user=false;
00124         secure=false;
00125         notify_owner_message="";
00126         notify_user_message="";
00127         all_on_channel="";
00128         also_unknown=false;
00129     }
00130 
00131     s_access()
00132     {
00133         clear();
00134     }
00135 };
00136 
00137 /*!
00138     \brief Stores informnations about event occured to the object in the filesystem
00139     \author VooDooMan
00140     \version 1
00141     \date 2004
00142 */
00143 struct s_event {
00144     bool has_read;                  //!< User has read the object
00145     bool owner_notified;            //!< OWNER has been notified about user's read yet
00146     bool user_notified;             //!< User has been notified about this object
00147     string user_name;               //!< Name of user to which this event belongs to
00148 
00149     time_t first;                   //!< Timestamp of first occurence of event
00150 
00151     /*!
00152         \brief Clears the structure
00153         \author VooDooMan
00154         \version 1
00155         \date 2004
00156     */
00157     void clear()
00158     {
00159         has_read=false;
00160         owner_notified=false;
00161         user_notified=false;
00162         user_name="";
00163         first=0;
00164     }
00165 
00166     s_event()
00167     {
00168         clear();
00169     }
00170 };
00171 
00172 /*!
00173     \brief Stores informnations about object in the filesystem
00174     \author VooDooMan
00175     \version 1
00176     \date 2004
00177 */
00178 struct s_file {
00179     e_file_type file_type;              //!< Type of object
00180     bool published;                     //!< Has the object been published?
00181     bool complete;                      //!< Was the file complete received? (only valid if file_type==ft_file)
00182     string sender_file_name;            //!< Name of the file as provided by sender (only valid if file_type==ft_file)
00183     time_t ftime;                       //!< Time of creation of this object
00184     string internal_name;               //!< Internal file name of contents of object
00185     string public_name;                 //!< Public name of object
00186     vector<s_access> access;            //!< Access rights of object
00187     vector<s_event> events;             //!< Events that occured to the object
00188 
00189     time_t expiration;                  //!< Time of expiration
00190     bool expired;                       //!< Fas the file been deleted after expiration?
00191 
00192     /*!
00193         \brief Clears the structure
00194         \author VooDooMan
00195         \version 1
00196         \date 2004
00197     */
00198     void clear()
00199     {
00200         file_type=ft_invalid;
00201         ftime=0;
00202         published=false;
00203         sender_file_name="";
00204         complete=false;
00205         internal_name="";
00206         public_name="";
00207         access.clear();
00208         events.clear();
00209         expiration=0;
00210         expired=false;
00211     }
00212 
00213     s_file()
00214     {
00215         clear();
00216     }
00217 
00218     /*!
00219         \brief Checks if the passed user is OWNER of this object
00220         \author VooDooMan
00221         \version 1
00222         \date 2004
00223         \param user Name of user to check
00224         \return Returns true if user is OWNER
00225     */
00226     bool is_owner(string user)
00227     {
00228         vector<s_access>::iterator i1;
00229         for(i1=access.begin(); i1!=access.end(); i1++) {
00230             if((*i1).owner && ((*i1).all_users || !(*i1).user_name.compare(user)))
00231                 return true;
00232         }
00233         return false;
00234     }
00235 
00236     /*!
00237         \brief Checks if the passed user has READ permission to this object
00238         \author VooDooMan
00239         \version 1
00240         \date 2004
00241         \param user Name of user to check
00242         \return Returns true if user can READ
00243     */
00244     bool can_read(string user)
00245     {
00246         vector<s_access>::iterator i1;
00247         for(i1=access.begin(); i1!=access.end(); i1++) {
00248             if((*i1).read && ((*i1).all_users || !(*i1).user_name.compare(user)))
00249                 return true;
00250         }
00251         return false;
00252     }
00253 
00254     /*!
00255         \brief Checks if the passed user has DELETE permission to this object
00256         \author VooDooMan
00257         \version 1
00258         \date 2004
00259         \param user Name of user to check
00260         \return Returns true if user can DELETE
00261     */
00262     bool can_delete(string user)
00263     {
00264         vector<s_access>::iterator i1;
00265         for(i1=access.begin(); i1!=access.end(); i1++) {
00266             if((*i1).del && ((*i1).all_users || !(*i1).user_name.compare(user)))
00267                 return true;
00268         }
00269         return false;
00270     }
00271 };
00272 
00273 /*!
00274     \brief Stores informnations about notification of user about events in the filesystem
00275     \author VooDooMan
00276     \version 1
00277     \date 2004
00278 */
00279 struct s_dcc_notify {
00280     bool unpublished;                   //!< Has not been this object published yet?
00281     bool incomplete;
00282     bool notify_user;                   //!< User should be notified
00283     bool notify_owner;                  //!< OWNER should be notified
00284     bool secure_notify_user;            //!< User should be notified securely (after authentication)
00285     bool secure_notify_owner;           //!< OWNER should be notified securely (after authentication)
00286     string name;                        //!< Public name of the file
00287     string message;                     //!< Notify message
00288 
00289     s_dcc_notify()
00290     {
00291         unpublished=false;
00292         incomplete=false;
00293         notify_user=false;
00294         notify_owner=false;
00295         secure_notify_user=false;
00296         secure_notify_owner=false;
00297         name="";
00298         message="";
00299     }
00300 };
00301 
00302 void filesys_add_file_raw(string internal_name, string original_name, string owner, bool complete, bool after_resume);
00303 bool filesys_dcc_check_for_notifies(string user, s_user& u, vector<s_channel>& chs, string channel, vector<s_dcc_notify>& notify, bool secured, string lang, string eol);
00304 bool filesys_dcc_filelist(string user, vector<s_file>& files_, bool must_be_owner);
00305 bool filesys_dcc_get_file(string user, string public_name, s_file& file);
00306 bool filesys_dcc_set_file_attrs(string user, s_file& file, bool& forced_secure);
00307 void filesys_dcc_drop_notifies(string user, bool only_non_secure);
00308 string filesys_dcc_add_message(string from, s_file& msg, string content, bool& force_secure);
00309 void filesys_set_file_was_read(string user, string public_name);
00310 bool filesys_dcc_set_file_attrs(s_file& file);
00311 bool filesys_dcc_check_for_resume(string user, string file_name, size_t& got_bytes);
00312 void filesys_dcc_get_resume_info(string user, string file_name, string& internal_name);
00313 int filesys_dcc_delete(string user, string file_name);
00314 int filesys_check_add_file_raw(string public_name, string user_name);
00315 
00316 void filesys_flush();
00317 
00318 string filesys_get_script(string script_type);
00319 
00320 bool filesys_logic_get_file(string internal_name, s_file& file);
00321 bool filesys_logic_set_file(string internal_name, s_file& file);
00322 
00323 #endif
00324 

Generated on Sun Jul 10 03:22:53 2005 for VooDoo cIRCle by doxygen 1.4.3

Hosted by SourceForge.net Logo