diff --git a/.github/workflows/smoke_tests.yml b/.github/workflows/smoke_tests.yml index a7491079b8..b069eb8009 100644 --- a/.github/workflows/smoke_tests.yml +++ b/.github/workflows/smoke_tests.yml @@ -19,6 +19,8 @@ jobs: run: gem install rubocop - name: Install CppCheck run: sudo apt install -y cppcheck + - name: Install AStyle + run: sudo apt install -y astyle # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v4 diff --git a/include/AclManager.h b/include/AclManager.h index eb665666e9..7e96e8bf1f 100644 --- a/include/AclManager.h +++ b/include/AclManager.h @@ -90,7 +90,7 @@ public: * @return true if the authorization is granted for oneadmin */ bool oneadmin_authorize(const PoolObjectAuth& obj_perms, - AuthRequest::Operation op) const; + AuthRequest::Operation op) const; /** * Adds a new rule to the ACL rule set diff --git a/include/AclRule.h b/include/AclRule.h index 50cfd05705..b848bda18f 100644 --- a/include/AclRule.h +++ b/include/AclRule.h @@ -64,11 +64,11 @@ public: /** * Set the fields of the ACL, and updates its representation */ - void set(int _oid, - long long _user, - long long _resource, - long long _rights, - long long _zone) + void set(int _oid, + long long _user, + long long _resource, + long long _rights, + long long _zone) { oid = _oid; user = _user; diff --git a/include/ActionSet.h b/include/ActionSet.h index c9a56f22f3..683c9c269c 100644 --- a/include/ActionSet.h +++ b/include/ActionSet.h @@ -28,7 +28,7 @@ template class ActionSet { public: - ActionSet():action_set(0UL){}; + ActionSet():action_set(0UL) {}; ActionSet(const T * actions, int actions_len):action_set(0) { for (int i=0; i& vms, - const std::vector& vnets, const std::vector& vrs) const; + const std::vector& vnets, const std::vector& vrs) const; /** * Same as above but without the LEASES section @@ -194,7 +194,7 @@ public: * @return 0 if success */ int allocate_addr(PoolObjectSQL::ObjectType ot, int obid, - VectorAttribute * nic, const std::set &inherit); + VectorAttribute * nic, const std::set &inherit); /** * Returns the specific address by mac/ip if is not allocated. The NIC attr @@ -207,13 +207,13 @@ public: * @return 0 if success */ int allocate_by_mac(const std::string& mac, PoolObjectSQL::ObjectType ot, - int obid, VectorAttribute * nic, const std::set &inherit); + int obid, VectorAttribute * nic, const std::set &inherit); int allocate_by_ip(const std::string& ip, PoolObjectSQL::ObjectType ot, - int obid, VectorAttribute * nic, const std::set &inherit); + int obid, VectorAttribute * nic, const std::set &inherit); int allocate_by_ip6(const std::string& ip6, PoolObjectSQL::ObjectType ot, - int obid, VectorAttribute * nic, const std::set &inherit); + int obid, VectorAttribute * nic, const std::set &inherit); /** * Sets the given ip/mac on hold, the address is associated to a VM of @@ -237,7 +237,7 @@ public: int free_addr_by_ip(PoolObjectSQL::ObjectType ot, int id, const std::string& ip); - int free_addr_by_ip6(PoolObjectSQL::ObjectType ot, int id,const std::string& ip); + int free_addr_by_ip6(PoolObjectSQL::ObjectType ot, int id, const std::string& ip); /** * Frees all previous allocated address to the given object @@ -257,7 +257,7 @@ public: * @return the number of addresses freed */ int free_addr_by_range(PoolObjectSQL::ObjectType ot, int obid, - const std::string& mac, unsigned int rsize); + const std::string& mac, unsigned int rsize); /** * Adds the relevant AR definition attributes to the Security Group rule @@ -288,13 +288,13 @@ public: * @return 0 on success */ int reserve_addr_by_mac(int vid, unsigned int rsize, const std::string& mac, - AddressRange *rar); + AddressRange *rar); int reserve_addr_by_ip(int vid, unsigned int rsize, const std::string& ip, - AddressRange *rar); + AddressRange *rar); int reserve_addr_by_ip6(int vid, unsigned int rsize, const std::string& ip, - AddressRange *rar); + AddressRange *rar); // ************************************************************************* // Helpers @@ -437,7 +437,7 @@ protected: * Base constructor it cannot be called directly but from the * AddressRange factory constructor. */ - AddressRange(unsigned int _id):id(_id){}; + AddressRange(unsigned int _id):id(_id) {}; /* ---------------------------------------------------------------------- */ /* Address/AR helper functions to build/parse driver messages */ @@ -462,7 +462,7 @@ protected: * @param oss string stream to write the request to */ void addr_to_xml(unsigned int index, unsigned int size, - std::ostringstream& oss) const; + std::ostringstream& oss) const; /** * Check if the given MAC is valid for this address range by verifying: @@ -611,7 +611,7 @@ private: * @return 0 on success */ static int ip6_to_s(const unsigned int prefix[], const unsigned int mac[], - std::string& ip6_s); + std::string& ip6_s); static int ip6_to_s(const unsigned int ip6_i[], std::string& ip6_s); @@ -686,7 +686,7 @@ private: * Adds a new allocated address to the map. Updates the ALLOCATED attribute */ void set_allocated_addr(PoolObjectSQL::ObjectType ot, int obid, - unsigned int addr_index); + unsigned int addr_index); /** * Sets the address lease as used and fills a NIC attribute with the @@ -699,16 +699,16 @@ private: * @return 0 if success */ void allocate_by_index(unsigned int index, - PoolObjectSQL::ObjectType ot, - int obid, - VectorAttribute* nic, - const std::set& inherit); + PoolObjectSQL::ObjectType ot, + int obid, + VectorAttribute* nic, + const std::set& inherit); /** * Frees an address from the map. Updates the ALLOCATED attribute */ int free_allocated_addr(PoolObjectSQL::ObjectType ot, int obid, - unsigned int addr_index); + unsigned int addr_index); /** * Reserve a set of addresses from an starting one @@ -719,7 +719,7 @@ private: * @return 0 on success */ int reserve_addr_by_index(int vid, unsigned int rsize, unsigned int sindex, - AddressRange *rar); + AddressRange *rar); /* ---------------------------------------------------------------------- */ /* Restricted Attributes functions */ diff --git a/include/AddressRangeIPAM.h b/include/AddressRangeIPAM.h index 2ef740833e..e2b3e5cef0 100644 --- a/include/AddressRangeIPAM.h +++ b/include/AddressRangeIPAM.h @@ -26,9 +26,9 @@ class VectorAttribute; class AddressRangeIPAM : public AddressRange { public: - AddressRangeIPAM(unsigned int _id):AddressRange(_id){}; + AddressRangeIPAM(unsigned int _id):AddressRange(_id) {}; - virtual ~AddressRangeIPAM(){}; + virtual ~AddressRangeIPAM() {}; /* ---------------------------------------------------------------------- */ /* AddressRange Interface */ diff --git a/include/AddressRangeInternal.h b/include/AddressRangeInternal.h index 5d138019a9..07d3c2f4ad 100644 --- a/include/AddressRangeInternal.h +++ b/include/AddressRangeInternal.h @@ -26,9 +26,9 @@ class VectorAttribute; class AddressRangeInternal : public AddressRange { public: - AddressRangeInternal(unsigned int _id):AddressRange(_id), next(0){}; + AddressRangeInternal(unsigned int _id):AddressRange(_id), next(0) {}; - virtual ~AddressRangeInternal(){}; + virtual ~AddressRangeInternal() {}; /* ---------------------------------------------------------------------- */ /* AddressRange Interface */ diff --git a/include/AddressRangePool.h b/include/AddressRangePool.h index 9e0a0036cd..671e7173f5 100644 --- a/include/AddressRangePool.h +++ b/include/AddressRangePool.h @@ -89,8 +89,8 @@ public: * @return 0 on success */ int update_ar(std::vector ars, bool keep_restricted, - std::set& update_ids, std::unique_ptr& update_attr, - std::string& error_msg); + std::set& update_ids, std::unique_ptr& update_attr, + std::string& error_msg); /** * Allocates a new *empty* address range. It is not added to the pool as it * needs to be initialized. Only the AR_ID is set. @@ -121,7 +121,7 @@ public: * @return 0 if success */ int allocate_addr(PoolObjectSQL::ObjectType ot, int obid, - VectorAttribute * nic, const std::set &inherit); + VectorAttribute * nic, const std::set &inherit); /** * Allocates an address in a suitable address range from the pool by mac/ip @@ -175,13 +175,13 @@ public: * @param mac/ip the specific MAC/IP address requested */ void free_addr(unsigned int arid, PoolObjectSQL::ObjectType ot, int obid, - const std::string& mac); + const std::string& mac); void free_addr_by_ip(unsigned int arid, PoolObjectSQL::ObjectType ot, - int obid, const std::string& ip); + int obid, const std::string& ip); void free_addr_by_ip6(unsigned int arid, PoolObjectSQL::ObjectType ot, - int obid, const std::string& ip); + int obid, const std::string& ip); /** * Frees the given address by MAC/IP from all address ranges containing @@ -216,7 +216,7 @@ public: * @param rsize size of the address range */ int free_addr_by_range(unsigned int arid, PoolObjectSQL::ObjectType ot, - int obid, const std::string& mac, unsigned int rsize); + int obid, const std::string& mac, unsigned int rsize); /** * From a Security Group rule that uses this vnet, creates a new rule @@ -253,7 +253,7 @@ public: * @return 0 on success */ int reserve_addr(int vid, unsigned int rsize, unsigned int ar_id, - AddressRange *rar); + AddressRange *rar); /** * Reserve a number of addresses from an address range from a given ip/mac @@ -265,13 +265,13 @@ public: * @return 0 on success */ int reserve_addr_by_mac(int vid, unsigned int rsize, unsigned int ar_id, - const std::string& mac, AddressRange *rar); + const std::string& mac, AddressRange *rar); int reserve_addr_by_ip(int vid, unsigned int rsize, unsigned int ar_id, - const std::string& ip, AddressRange *rar); + const std::string& ip, AddressRange *rar); int reserve_addr_by_ip6(int vid, unsigned int rsize, unsigned int ar_id, - const std::string& ip, AddressRange *rar); + const std::string& ip, AddressRange *rar); // ************************************************************************* diff --git a/include/Attribute.h b/include/Attribute.h index dc44ecc93f..59beaa71f9 100644 --- a/include/Attribute.h +++ b/include/Attribute.h @@ -45,11 +45,11 @@ public: if ((size >0 && !(isalpha(aname[0]) || aname[0] == '_')) || (size >=3 && (aname[0]=='X' && aname[1]=='M' && aname[2]=='L'))) { - attribute_name.insert(0,"ONE_"); + attribute_name.insert(0, "ONE_"); } }; - virtual ~Attribute(){}; + virtual ~Attribute() {}; enum AttributeType { @@ -82,7 +82,7 @@ public: virtual void to_token(std::ostringstream& s) const = 0; virtual void to_xml(std::ostringstream& s, - const std::map> &hidden) const = 0; + const std::map> &hidden) const = 0; /** * Builds a new attribute from a string. @@ -145,7 +145,7 @@ public: , attribute_value(sa.attribute_value) {} - ~SingleAttribute(){}; + ~SingleAttribute() {}; /** * Returns the attribute value, a string. @@ -182,17 +182,17 @@ public: } void to_xml(std::ostringstream& s, - const std::map> &hidden) const override + const std::map> &hidden) const override { s << "<" << attribute_name << ">"; if (hidden.find(attribute_name) != hidden.end() ) { - s << "***"; + s << "***"; } else { - s << one_util::escape_xml(attribute_value); + s << one_util::escape_xml(attribute_value); } s << ""; @@ -282,7 +282,7 @@ public: {} VectorAttribute(const std::string& name, - const std::map& value) + const std::map& value) : Attribute(name) , attribute_value(value) {} @@ -296,12 +296,12 @@ public: VectorAttribute& operator=(const VectorAttribute& va) = default; - ~VectorAttribute(){}; + ~VectorAttribute() {}; /** * Returns the attribute value, a string. */ - const std::map& value() const + const std::map& value() const { return attribute_value; }; @@ -452,7 +452,7 @@ public: void to_xml(std::ostringstream& s) const override; void to_xml(std::ostringstream& s, - const std::map> &hidden) const override; + const std::map> &hidden) const override; void to_json(std::ostringstream& s) const override; @@ -467,7 +467,7 @@ public: /** * Replace the value of the given attribute with the provided map */ - void replace(const std::map& attr); + void replace(const std::map& attr); /** * The attributes from vattr will be copied to this vector @@ -560,7 +560,7 @@ private: static const int magic_sep_size; - std::map attribute_value; + std::map attribute_value; }; #endif /*ATTRIBUTE_H_*/ diff --git a/include/AuthManager.h b/include/AuthManager.h index 68dc136bf3..2c3142210a 100644 --- a/include/AuthManager.h +++ b/include/AuthManager.h @@ -29,17 +29,17 @@ class AuthRequest; class AuthManager : public DriverManager>, - public Listener + public Listener { public: AuthManager( - time_t timer, - const std::string& mads_location) - : DriverManager(mads_location) - , Listener("Authorization Manager") - , timer_thread(timer, [this](){timer_action();}) - , authz_enabled(false) + time_t timer, + const std::string& mads_location) + : DriverManager(mads_location) + , Listener("Authorization Manager") + , timer_thread(timer, [this]() {timer_action();}) + , authz_enabled(false) { } @@ -88,9 +88,9 @@ private: */ static const char * auth_driver_name; - /** - * True if there is an authorization driver enabled - */ + /** + * True if there is an authorization driver enabled + */ bool authz_enabled; /** diff --git a/include/AuthRequest.h b/include/AuthRequest.h index 0e2bbe4f4d..53619a6952 100644 --- a/include/AuthRequest.h +++ b/include/AuthRequest.h @@ -40,7 +40,7 @@ public: , self_authorize(true) {} - ~AuthRequest(){}; + ~AuthRequest() {}; /** * Authorization Request Type @@ -78,11 +78,11 @@ public: static Operation str_to_operation(const std::string& str) { - if (str == "USE") return USE; - else if (str == "MANAGE") return MANAGE; - else if (str == "ADMIN") return ADMIN; - else if (str == "CREATE") return CREATE; - else return NONE; + if (str == "USE") return USE; + else if (str == "MANAGE") return MANAGE; + else if (str == "ADMIN") return ADMIN; + else if (str == "CREATE") return CREATE; + else return NONE; }; /** diff --git a/include/BackupIncrements.h b/include/BackupIncrements.h index fe13f05186..f846821b16 100644 --- a/include/BackupIncrements.h +++ b/include/BackupIncrements.h @@ -36,7 +36,7 @@ class Increment : public ExtendedAttribute { public: - Increment(VectorAttribute *va, int id): ExtendedAttribute(va, id){}; + Increment(VectorAttribute *va, int id): ExtendedAttribute(va, id) {}; ~Increment() = default; @@ -90,7 +90,7 @@ public: case FULL: replace("TYPE", "FULL"); break; - case INCREMENT: + case INCREMENT: replace("TYPE", "INCREMENT"); break; } @@ -121,7 +121,7 @@ public: class IncrementSet : public ExtendedAttributeSet { public: - IncrementSet(): ExtendedAttributeSet(false){}; + IncrementSet(): ExtendedAttributeSet(false) {}; ~IncrementSet() = default; @@ -146,7 +146,7 @@ public: * @return Pointer to the new attribute */ VectorAttribute * new_increment(const std::string& source, long long sz, - Increment::Type type); + Increment::Type type); Increment * last_increment() { @@ -182,10 +182,10 @@ public: class IncIterator : public AttributeIterator { public: - IncIterator():AttributeIterator(){}; - IncIterator(const AttributeIterator& dit):AttributeIterator(dit){}; + IncIterator():AttributeIterator() {}; + IncIterator(const AttributeIterator& dit):AttributeIterator(dit) {}; - virtual ~IncIterator(){}; + virtual ~IncIterator() {}; Increment * operator*() const { @@ -229,7 +229,7 @@ private: class BackupIncrements { public: - BackupIncrements():_template(false,'=',"BACKUP_INCREMENTS"){}; + BackupIncrements():_template(false, '=', "BACKUP_INCREMENTS") {}; ~BackupIncrements() = default; diff --git a/include/BackupJob.h b/include/BackupJob.h index 94b5ef4483..7db6cae010 100644 --- a/include/BackupJob.h +++ b/include/BackupJob.h @@ -242,8 +242,8 @@ public: * @return 0 on success */ int replace_template(const std::string& tmpl_str, - bool keep_restricted, - std::string& error) override; + bool keep_restricted, + std::string& error) override; /** * Append new attributes to the *user template*. @@ -254,7 +254,7 @@ public: * @return 0 on success */ int append_template(const std::string& tmpl_str, bool keep_restricted, - std::string& error) override; + std::string& error) override; friend class BackupJobPool; friend class PoolSQL; @@ -296,7 +296,7 @@ protected: * @param db pointer to the database. * @return 0 on success. */ - int update(SqlDB * db) override; + int update(SqlDB * db) override; /** * Execute an INSERT or REPLACE Sql query. @@ -394,7 +394,7 @@ private: */ int process_backup_vms(const std::string& vms_new_str, const std::string& vms_old_str, - std::string& error); + std::string& error); /** * Remove Backup Job ID from Virtual Machines listed in BACKUP_VMS attribute diff --git a/include/BackupJobPool.h b/include/BackupJobPool.h index 0bee58927a..030c3e1c59 100644 --- a/include/BackupJobPool.h +++ b/include/BackupJobPool.h @@ -47,14 +47,14 @@ public: * -2 in case of template parse failure */ int allocate ( - int uid, - int gid, - const std::string& uname, - const std::string& gname, - int umask, - std::unique_ptr