Skip to content

Commit

Permalink
F #4936: oned refactor
Browse files Browse the repository at this point in the history
    * Remove duplicit methods from NebulaUtil

    * Const correctness

    * Fix minor code quality issues

    * Remove ObjectCollection::clone()

    * Minor SSLUtil interface change

co-authored-by: Pavel Czerný <[email protected]>
  • Loading branch information
rsmontero and Pavel Czerný committed Jul 5, 2020
1 parent 823cbf4 commit 5650949
Show file tree
Hide file tree
Showing 115 changed files with 696 additions and 989 deletions.
10 changes: 5 additions & 5 deletions include/AclManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ class AclManager : public Callbackable, public ActionListener
* @param op The operation to be authorized
* @return true if the authorization is granted by any rule
*/
const bool authorize(int uid,
const std::set<int>& user_groups,
const PoolObjectAuth& obj_perms,
AuthRequest::Operation op);
bool authorize(int uid,
const std::set<int>& user_groups,
const PoolObjectAuth& obj_perms,
AuthRequest::Operation op);

/**
* Takes an authorization request for oneadmin
Expand All @@ -90,7 +90,7 @@ class AclManager : public Callbackable, public ActionListener
* @param op The operation to be authorized
* @return true if the authorization is granted for oneadmin
*/
const bool oneadmin_authorize(const PoolObjectAuth& obj_perms,
bool oneadmin_authorize(const PoolObjectAuth& obj_perms,
AuthRequest::Operation op);

/**
Expand Down
4 changes: 2 additions & 2 deletions include/AddressRange.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ class AddressRange
/**
* Copy security groups into set
*/
void get_security_groups(std::set<int>& sgs)
void get_security_groups(std::set<int>& sgs) const
{
for (auto sg : security_groups)
{
Expand Down Expand Up @@ -469,7 +469,7 @@ class AddressRange
* @return true if the IP is valid
*/
bool is_valid_ip(unsigned int& index, const std::string& ip_s,
bool check_free);
bool check_free) const;

/**
* Check if the given IP is valid for this address range by verifying:
Expand Down
2 changes: 1 addition & 1 deletion include/AddressRangeInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class AddressRangeInternal : public AddressRange
* @param msg with error description if any
* @return 0 on success -1 otherwise
*/
int get_range_addr(unsigned int& index, unsigned int sz, std::string& msg);
int get_range_addr(unsigned int& index, unsigned int sz, std::string& msg) const;
};

#endif
2 changes: 1 addition & 1 deletion include/AddressRangePool.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class AddressRangePool
* Gets a the security group set of all ARs
* @param sgs set with all the SG ids
*/
void get_all_security_groups(std::set<int>& sgs);
void get_all_security_groups(std::set<int>& sgs) const;

/**
* Generate a XML representation of the Address Range Pool
Expand Down
4 changes: 2 additions & 2 deletions include/AuthManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class AuthManager :
* @return the Auth driver with attribute name equal to value
* or 0 in not found
*/
const Driver<auth_msg_t> * get(const std::string& name)
const Driver<auth_msg_t> * get(const std::string& name) const
{
return DriverManager::get_driver(name);
}
Expand All @@ -187,7 +187,7 @@ class AuthManager :
* @return the TM driver owned by uid with attribute name equal to value
* or 0 in not found
*/
const Driver<auth_msg_t> * get()
const Driver<auth_msg_t> * get() const
{
return DriverManager::get_driver(auth_driver_name);
}
Expand Down
2 changes: 1 addition & 1 deletion include/AuthRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class AuthRequest : public SyncRequest
* @return a space separated list of auth requests, or an empty string if
* no auth requests were added
*/
std::string get_auths()
std::string get_auths() const
{
std::ostringstream oss;
unsigned int i;
Expand Down
36 changes: 11 additions & 25 deletions include/BitMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "Attribute.h"
#include "Callbackable.h"
#include "SSLUtil.h"

class SqlDB;

Expand Down Expand Up @@ -92,18 +93,16 @@ class BitMap : public Callbackable
*/
int select(int _id, SqlDB * db)
{
std::string * uzbs;
std::string uzbs;

id = _id;

if ( select(db, &uzbs) != 0 )
if ( select(db, uzbs) != 0 )
{
return -1;
}

bs = new std::bitset<N>(*uzbs);

delete uzbs;
bs = new std::bitset<N>(uzbs);

return 0;
}
Expand Down Expand Up @@ -134,7 +133,7 @@ class BitMap : public Callbackable
* @param bit the bit number reserved
* @return -1 in case of error
*/
int get(unsigned int hint, unsigned int& bit)
int get(unsigned int hint, unsigned int& bit) const
{
if ( hint != 0 )
{
Expand Down Expand Up @@ -205,7 +204,7 @@ class BitMap : public Callbackable
/**
* Return the start_bit of the bitmap
*/
unsigned int get_start_bit()
unsigned int get_start_bit() const
{
return start_bit;
}
Expand Down Expand Up @@ -248,16 +247,14 @@ class BitMap : public Callbackable
* be freed by caller.
* @return 0 on success
*/
int select(SqlDB * db, std::string ** uzbs)
int select(SqlDB * db, std::string &uzbs)
{
int rc;

std::ostringstream oss;

std::string zbs;

*uzbs = 0;

set_callback(static_cast<Callbackable::Callback>(&BitMap::select_cb),
static_cast<void *>(&zbs));

Expand All @@ -276,17 +273,9 @@ class BitMap : public Callbackable
return -1;
}

*uzbs = one_util::zlib_decompress(zbs, true);

if ( *uzbs == 0 )
{
rc = -1;
}

return rc;
return ssl_util::zlib_decompress64(zbs, uzbs);
}


/**
* Insert a Bitmap in the DB, the bitmap is stored in a compressed (zlib)
* string form.
Expand All @@ -297,15 +286,14 @@ class BitMap : public Callbackable
{
std::ostringstream oss;

std::string * zipped = one_util::zlib_compress(bs->to_string(), true);
std::string zipped;

if (zipped == 0)
if (ssl_util::zlib_compress64(bs->to_string(), zipped) != 0)
{
return -1;
}

char * ezipped64 = db->escape_str(*zipped);

char * ezipped64 = db->escape_str(zipped);

if (replace)
{
Expand All @@ -321,8 +309,6 @@ class BitMap : public Callbackable

int rc = db->exec_wr(oss);

delete zipped;

db->free_str(ezipped64);

return rc;
Expand Down
2 changes: 1 addition & 1 deletion include/Callbackable.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Callbackable
/**
* get affected rows variable
*/
int get_affected_rows()
int get_affected_rows() const
{
return affected_rows;
}
Expand Down
22 changes: 7 additions & 15 deletions include/Cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ class Cluster : public PoolObjectSQL
// Object Collections (Public)
// *************************************************************************

/**
* Returns a copy of the datastore IDs set
*/
std::set<int> get_datastores()
{
return datastores.clone();
};

/**
* Returns a system DS for the cluster when none is set at the API level
* @return the ID of the System
Expand All @@ -50,25 +42,25 @@ class Cluster : public PoolObjectSQL
/**
* Returns a copy of the host IDs set
*/
std::set<int> get_host_ids()
const std::set<int>& get_host_ids() const
{
return hosts.clone();
return hosts.get_collection();
}

/**
* Returns a copy of the datastore IDs set
*/
std::set<int> get_datastore_ids()
const std::set<int>& get_datastore_ids() const
{
return datastores.clone();
return datastores.get_collection();
}

/**
* Returns a copy of the vnet IDs set
*/
std::set<int> get_vnet_ids()
const std::set<int>& get_vnet_ids() const
{
return vnets.clone();
return vnets.get_collection();
}

/**
Expand Down Expand Up @@ -121,7 +113,7 @@ class Cluster : public PoolObjectSQL
* @param port reserved
* @return 0 on success
*/
int get_vnc_port(int vmid, unsigned int& port)
int get_vnc_port(int vmid, unsigned int& port) const
{
unsigned int base_port = vnc_bitmap.get_start_bit();
unsigned int hint_port = base_port + (vmid % (65535 - base_port));
Expand Down
4 changes: 2 additions & 2 deletions include/Clusterable.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class Clusterable
*
* @return The cluster IDs set
*/
std::set<int> get_cluster_ids() const
const std::set<int>& get_cluster_ids() const
{
return cluster_ids.clone();
return cluster_ids.get_collection();
};

/**
Expand Down
12 changes: 6 additions & 6 deletions include/Datastore.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ class Datastore : public PoolObjectSQL, public Clusterable
/**
* Returns a copy of the Image IDs set
*/
std::set<int> get_image_ids()
const std::set<int>& get_image_ids() const
{
return images.clone();
return images.get_collection();
}

/**
Expand Down Expand Up @@ -215,7 +215,7 @@ class Datastore : public PoolObjectSQL, public Clusterable
* @return true if the datastore is configured to enforce capacity
* checkings
*/
bool get_avail_mb(long long &avail);
bool get_avail_mb(long long &avail) const;

/**
* Returns true if the DS contains the SHARED = YES attribute
Expand All @@ -237,7 +237,7 @@ class Datastore : public PoolObjectSQL, public Clusterable
* Returns true if the DS_MAD_CONF has PERSISTENT_ONLY = "YES" flag
* @return true if persistent only
*/
bool is_persistent_only();
bool is_persistent_only() const;

/**
* Enable or disable the DS. Only for System DS.
Expand All @@ -251,7 +251,7 @@ class Datastore : public PoolObjectSQL, public Clusterable
/**
* Return a set with compatible system ds for an image ds
*/
void get_compatible_system_ds(std::set<int> &compatible_sys_ds)
void get_compatible_system_ds(std::set<int> &compatible_sys_ds) const
{
std::string compatible_sys_ds_str;

Expand All @@ -267,7 +267,7 @@ class Datastore : public PoolObjectSQL, public Clusterable
int get_tm_mad_targets(const std::string &tm_mad,
std::string& ln_target,
std::string& clone_target,
std::string& disk_type);
std::string& disk_type) const;

private:

Expand Down
2 changes: 1 addition & 1 deletion include/DispatchManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ class DispatchManager : public ActionListener
* @param only_running true to not add CPU, MEMORY and VMS counters
*/
void get_quota_template(VirtualMachine * vm,
VirtualMachineTemplate& quota_tmpl, bool only_running);
VirtualMachineTemplate& quota_tmpl, bool only_running) const;
};

#endif /*DISPATCH_MANAGER_H*/
2 changes: 1 addition & 1 deletion include/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Document : public PoolObjectSQL
*
* @return the document type
*/
int get_document_type()
int get_document_type() const
{
return type;
};
Expand Down
2 changes: 1 addition & 1 deletion include/HookAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class HookAPI : public HookImplementation
/**
* Function to build a XML message for an API hook
*/
static std::string * format_message(std::string method, ParamList& paramList,
static std::string format_message(std::string method, ParamList& paramList,
const RequestAttributes& att);

/**
Expand Down
8 changes: 4 additions & 4 deletions include/HookManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ class HookManager :
* @return the Hook driver owned by uid 0, with attribute "NAME" equal to
* name or 0 in not found
*/
const Driver<hook_msg_t> * get()
const Driver<hook_msg_t> * get() const
{
return DriverManager::get_driver(hook_driver_name);
}

static std::string * format_message(const std::string& args,
const std::string& remote_host,
int hook_id);
static std::string format_message(const std::string& args,
const std::string& remote_host,
int hook_id);

private:
/**
Expand Down
2 changes: 1 addition & 1 deletion include/HookStateHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class HookStateHost : public HookImplementation
/**
* Function to build a XML message for a state hook
*/
static std::string * format_message(Host * host);
static std::string format_message(Host * host);

private:
friend class Hook;
Expand Down
2 changes: 1 addition & 1 deletion include/HookStateVM.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class HookStateVM : public HookImplementation
/**
* Function to build a XML message for a state hook
*/
static std::string * format_message(VirtualMachine * vm);
static std::string format_message(VirtualMachine * vm);

private:
friend class Hook;
Expand Down
Loading

0 comments on commit 5650949

Please sign in to comment.