OCT 1. 重命名 c vector 避免和std库冲突
2. 增加全局租约配置项 3. 增加DHCP MAC地址黑名单
This commit is contained in:
parent
1ea125ab6f
commit
77b0fc8843
|
@ -91,10 +91,15 @@ application:
|
||||||
|
|
||||||
# DHCP Server Config
|
# DHCP Server Config
|
||||||
dhcp_server: {
|
dhcp_server: {
|
||||||
|
# 全局租约时间
|
||||||
|
lease_time = 86400;
|
||||||
|
# 监听网卡
|
||||||
listen_on = ["192.168.30.1"];
|
listen_on = ["192.168.30.1"];
|
||||||
# 主备服务器设置
|
# 主备服务器设置
|
||||||
replication = ["192.168.30.1", "192.168.30.2"];
|
replication = ["192.168.30.1", "192.168.30.2"];
|
||||||
|
# MAC地址黑名单
|
||||||
|
mac_filter = ["00:01:02:03:04:07", "00:01:02:03:04:01"];
|
||||||
|
# IP地址池配置
|
||||||
range_set: (
|
range_set: (
|
||||||
{ dhcp_range = "192.168.30.150-192.168.30.155";
|
{ dhcp_range = "192.168.30.150-192.168.30.155";
|
||||||
subnet_mask = "255.255.255.0";
|
subnet_mask = "255.255.255.0";
|
||||||
|
|
|
@ -34,7 +34,7 @@ typedef union {
|
||||||
long long longValue;
|
long long longValue;
|
||||||
char *strValue;
|
char *strValue;
|
||||||
long double floatValue;
|
long double floatValue;
|
||||||
vector array;
|
c_vector array;
|
||||||
} CFG_VALUE, *PCFG_VALUE;
|
} CFG_VALUE, *PCFG_VALUE;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -113,11 +113,13 @@ static CFG_ITEM g_cfgItem[] = {
|
||||||
DEF_CFG_ITEM(CFG_PROTO_CRYPTO_KEY, "protocol.crypto_key", VAL_STR, "", "Protocol crypto keys"),
|
DEF_CFG_ITEM(CFG_PROTO_CRYPTO_KEY, "protocol.crypto_key", VAL_STR, "", "Protocol crypto keys"),
|
||||||
#ifdef OPENDHCPD_ON
|
#ifdef OPENDHCPD_ON
|
||||||
// 配置DHCP服务器
|
// 配置DHCP服务器
|
||||||
|
DEF_CFG_ITEM(CFG_DHCP_LEASE_TIME, "dhcp_server.lease_time", VAL_INT, "36000", "DHCP server lease time"),
|
||||||
DEF_CFG_ITEM(CFG_DHCP_LISTEN_ON, "dhcp_server.listen_on", VAL_ARRAY_STR, "", "DHCP listen interface"),
|
DEF_CFG_ITEM(CFG_DHCP_LISTEN_ON, "dhcp_server.listen_on", VAL_ARRAY_STR, "", "DHCP listen interface"),
|
||||||
DEF_CFG_ITEM(CFG_DHCP_REPLICATION_SVR, "dhcp_server.replication", VAL_ARRAY_STR, "", "DHCP replication server configure"),
|
DEF_CFG_ITEM(CFG_DHCP_REPLICATION_SVR, "dhcp_server.replication", VAL_ARRAY_STR, "", "DHCP replication server configure"),
|
||||||
DEF_CFG_ITEM(CFG_DHCP_RANGE_SET, "dhcp_server.range_set", VAL_ARRAY_OBJ, "", "DHCP IP pool"),
|
DEF_CFG_ITEM(CFG_DHCP_RANGE_SET, "dhcp_server.range_set", VAL_ARRAY_OBJ, "", "DHCP IP pool"),
|
||||||
|
DEF_CFG_ITEM(CFG_DHCP_MAC_FILTER, "dhcp_server.mac_filter", VAL_ARRAY_STR, "", "DHCP client MAC address black list"),
|
||||||
#endif
|
#endif
|
||||||
};
|
}; // clang-format on
|
||||||
|
|
||||||
static int cfg_is_upgrade(PCONFIG_ITEM pItem) {
|
static int cfg_is_upgrade(PCONFIG_ITEM pItem) {
|
||||||
|
|
||||||
|
@ -128,7 +130,6 @@ static int cfg_is_upgrade(PCONFIG_ITEM pItem) {
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
// clang-format on
|
|
||||||
|
|
||||||
static const char *load_string_value(const char *pKeyName) {
|
static const char *load_string_value(const char *pKeyName) {
|
||||||
const char *pCfgVal;
|
const char *pCfgVal;
|
||||||
|
@ -688,7 +689,7 @@ const char *cfg_get_string_value(CONFIG_ITEM_ID id) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vector cfg_get_vector(CONFIG_ITEM_ID id) {
|
c_vector cfg_get_vector(CONFIG_ITEM_ID id) {
|
||||||
PCFG_VALUE pVal = cfg_get_value(id);
|
PCFG_VALUE pVal = cfg_get_value(id);
|
||||||
|
|
||||||
if (pVal) {
|
if (pVal) {
|
||||||
|
|
|
@ -12,17 +12,25 @@ const char *config_get_proto_crypto_key() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef OPENDHCPD_ON
|
#ifdef OPENDHCPD_ON
|
||||||
vector config_get_dhcp_server_range_set() {
|
unsigned int config_get_dhcp_server_lease_time() {
|
||||||
|
return cfg_get_integral_value(CFG_DHCP_LEASE_TIME);
|
||||||
|
}
|
||||||
|
|
||||||
|
c_vector config_get_dhcp_server_range_set() {
|
||||||
return cfg_get_vector(CFG_DHCP_RANGE_SET);
|
return cfg_get_vector(CFG_DHCP_RANGE_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector config_get_dhcp_listen_on() {
|
c_vector config_get_dhcp_listen_on() {
|
||||||
return cfg_get_vector(CFG_DHCP_LISTEN_ON);
|
return cfg_get_vector(CFG_DHCP_LISTEN_ON);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector config_get_dhcp_replication_svr() {
|
c_vector config_get_dhcp_replication_svr() {
|
||||||
return cfg_get_vector(CFG_DHCP_REPLICATION_SVR);
|
return cfg_get_vector(CFG_DHCP_REPLICATION_SVR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c_vector config_get_dhcp_mac_filter() {
|
||||||
|
return cfg_get_vector(CFG_DHCP_MAC_FILTER);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const char *config_get_http_server_addr() {
|
const char *config_get_http_server_addr() {
|
||||||
|
|
|
@ -71,9 +71,13 @@ typedef enum {
|
||||||
CFG_HTTP_SVR_TCP_NODELAY,
|
CFG_HTTP_SVR_TCP_NODELAY,
|
||||||
CFG_PROTO_CRYPTO,
|
CFG_PROTO_CRYPTO,
|
||||||
CFG_PROTO_CRYPTO_KEY,
|
CFG_PROTO_CRYPTO_KEY,
|
||||||
|
#ifdef OPENDHCPD_ON
|
||||||
|
CFG_DHCP_LEASE_TIME,
|
||||||
CFG_DHCP_LISTEN_ON,
|
CFG_DHCP_LISTEN_ON,
|
||||||
CFG_DHCP_REPLICATION_SVR,
|
CFG_DHCP_REPLICATION_SVR,
|
||||||
CFG_DHCP_RANGE_SET,
|
CFG_DHCP_RANGE_SET,
|
||||||
|
CFG_DHCP_MAC_FILTER,
|
||||||
|
#endif
|
||||||
CONFIG_ITEM_ID_MAX
|
CONFIG_ITEM_ID_MAX
|
||||||
} CONFIG_ITEM_ID;
|
} CONFIG_ITEM_ID;
|
||||||
|
|
||||||
|
@ -113,7 +117,7 @@ int cfg_get_zero_mq_port();
|
||||||
const char *cfg_get_zero_mq_data_path();
|
const char *cfg_get_zero_mq_data_path();
|
||||||
|
|
||||||
const char *cfg_get_string_value(CONFIG_ITEM_ID id);
|
const char *cfg_get_string_value(CONFIG_ITEM_ID id);
|
||||||
vector cfg_get_vector(CONFIG_ITEM_ID id);
|
c_vector cfg_get_vector(CONFIG_ITEM_ID id);
|
||||||
long double cfg_get_float_value(CONFIG_ITEM_ID id);
|
long double cfg_get_float_value(CONFIG_ITEM_ID id);
|
||||||
int cfg_get_bool_value(CONFIG_ITEM_ID id);
|
int cfg_get_bool_value(CONFIG_ITEM_ID id);
|
||||||
long long cfg_get_integral_value(CONFIG_ITEM_ID id);
|
long long cfg_get_integral_value(CONFIG_ITEM_ID id);
|
||||||
|
@ -134,10 +138,13 @@ int config_get_http_server_tcp_nodelay();
|
||||||
unsigned int config_get_proto_crypto_type();
|
unsigned int config_get_proto_crypto_type();
|
||||||
const char *config_get_proto_crypto_key();
|
const char *config_get_proto_crypto_key();
|
||||||
#ifdef OPENDHCPD_ON
|
#ifdef OPENDHCPD_ON
|
||||||
vector config_get_dhcp_server_range_set();
|
unsigned int config_get_dhcp_server_lease_time();
|
||||||
vector config_get_dhcp_listen_on();
|
c_vector config_get_dhcp_server_range_set();
|
||||||
vector config_get_dhcp_replication_svr();
|
c_vector config_get_dhcp_listen_on();
|
||||||
|
c_vector config_get_dhcp_replication_svr();
|
||||||
|
c_vector config_get_dhcp_mac_filter();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -42,6 +42,8 @@ extern "C" {
|
||||||
#define MAX_IP_V4_STR (16)
|
#define MAX_IP_V4_STR (16)
|
||||||
#define MAX_MAC_ADDR_STR (18)
|
#define MAX_MAC_ADDR_STR (18)
|
||||||
|
|
||||||
|
#define DEBUG_CODE_LINE() (dzlog_debug("\n"))
|
||||||
|
|
||||||
int file_exists(const char *pPath);
|
int file_exists(const char *pPath);
|
||||||
const char *basename_v2(const char *path);
|
const char *basename_v2(const char *path);
|
||||||
int dirname_v2(const char *path, char *dir);
|
int dirname_v2(const char *path, char *dir);
|
||||||
|
|
|
@ -32,6 +32,9 @@
|
||||||
|
|
||||||
#ifndef __SDS_H
|
#ifndef __SDS_H
|
||||||
#define __SDS_H
|
#define __SDS_H
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define SDS_MAX_PREALLOC (1024 * 1024)
|
#define SDS_MAX_PREALLOC (1024 * 1024)
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
@ -52,24 +55,28 @@ struct __attribute__((__packed__)) sdshdr5 {
|
||||||
unsigned char flags; /* 3 lsb of type, and 5 msb of string length */
|
unsigned char flags; /* 3 lsb of type, and 5 msb of string length */
|
||||||
char buf[];
|
char buf[];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct __attribute__((__packed__)) sdshdr8 {
|
struct __attribute__((__packed__)) sdshdr8 {
|
||||||
uint8_t len; /* used */
|
uint8_t len; /* used */
|
||||||
uint8_t alloc; /* excluding the header and null terminator */
|
uint8_t alloc; /* excluding the header and null terminator */
|
||||||
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
||||||
char buf[];
|
char buf[];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct __attribute__((__packed__)) sdshdr16 {
|
struct __attribute__((__packed__)) sdshdr16 {
|
||||||
uint16_t len; /* used */
|
uint16_t len; /* used */
|
||||||
uint16_t alloc; /* excluding the header and null terminator */
|
uint16_t alloc; /* excluding the header and null terminator */
|
||||||
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
||||||
char buf[];
|
char buf[];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct __attribute__((__packed__)) sdshdr32 {
|
struct __attribute__((__packed__)) sdshdr32 {
|
||||||
uint32_t len; /* used */
|
uint32_t len; /* used */
|
||||||
uint32_t alloc; /* excluding the header and null terminator */
|
uint32_t alloc; /* excluding the header and null terminator */
|
||||||
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
||||||
char buf[];
|
char buf[];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct __attribute__((__packed__)) sdshdr64 {
|
struct __attribute__((__packed__)) sdshdr64 {
|
||||||
uint64_t len; /* used */
|
uint64_t len; /* used */
|
||||||
uint64_t alloc; /* excluding the header and null terminator */
|
uint64_t alloc; /* excluding the header and null terminator */
|
||||||
|
@ -270,4 +277,7 @@ void sds_free(void *ptr);
|
||||||
int sdsTest(int argc, char *argv[]);
|
int sdsTest(int argc, char *argv[]);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -28,36 +28,36 @@ extern "C" {
|
||||||
// we can use:
|
// we can use:
|
||||||
#include "zvector_checks.h"
|
#include "zvector_checks.h"
|
||||||
|
|
||||||
// Include vector configuration header
|
// Include c_vector configuration header
|
||||||
#include "zvector_config.h"
|
#include "zvector_config.h"
|
||||||
|
|
||||||
// Declare required structs:
|
// Declare required structs:
|
||||||
typedef struct p_vector *vector;
|
typedef struct p_vector *c_vector;
|
||||||
|
|
||||||
// Declare required enums:
|
// Declare required enums:
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Vector Properties Flags can be used to tell ZVector
|
* Vector Properties Flags can be used to tell ZVector
|
||||||
* which types of properties we want to enable for each
|
* which types of properties we want to enable for each
|
||||||
* given vector we are creating.
|
* given c_vector we are creating.
|
||||||
* Each vector can have multiple properties enabled at the
|
* Each c_vector can have multiple properties enabled at the
|
||||||
* same time, you can use the typical C form to specify multiple
|
* same time, you can use the typical C form to specify multiple
|
||||||
* properties for the same vector:
|
* properties for the same c_vector:
|
||||||
*
|
*
|
||||||
* ZV_SEC_WIPE | ZV_BYREF
|
* ZV_SEC_WIPE | ZV_BYREF
|
||||||
*
|
*
|
||||||
* The above will create a vector that supports passing items to
|
* The above will create a c_vector that supports passing items to
|
||||||
* it by reference (instead of copying them into the vector) and
|
* it by reference (instead of copying them into the c_vector) and
|
||||||
* having Secure Wipe enabled, so that when an element is deleted
|
* having Secure Wipe enabled, so that when an element is deleted
|
||||||
* its reference will also be fully zeroed out before freeing it.
|
* its reference will also be fully zeroed out before freeing it.
|
||||||
*/
|
*/
|
||||||
enum ZVECT_PROPERTIES {
|
enum ZVECT_PROPERTIES {
|
||||||
ZV_NONE = 0, // Sets or Resets all vector's properties to 0.
|
ZV_NONE = 0, // Sets or Resets all c_vector's properties to 0.
|
||||||
ZV_SEC_WIPE = 1 << 0, // Sets the vector for automatic Secure Wipe of items.
|
ZV_SEC_WIPE = 1 << 0, // Sets the c_vector for automatic Secure Wipe of items.
|
||||||
ZV_BYREF = 1 << 1, // Sets the vector to store items by reference instead of copying them as per default.
|
ZV_BYREF = 1 << 1, // Sets the c_vector to store items by reference instead of copying them as per default.
|
||||||
ZV_CIRCULAR = 1
|
ZV_CIRCULAR = 1
|
||||||
<< 2, // Sets the vector to be a circular vector (so it will not grow in capacity automatically). Elements will be overwritten as in typical circular buffers!
|
<< 2, // Sets the c_vector to be a circular c_vector (so it will not grow in capacity automatically). Elements will be overwritten as in typical circular buffers!
|
||||||
ZV_NOLOCKING = 1 << 3, // This Property means the vector will not use mutexes, be careful using it!
|
ZV_NOLOCKING = 1 << 3, // This Property means the c_vector will not use mutexes, be careful using it!
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ZVECT_ERR {
|
enum ZVECT_ERR {
|
||||||
|
@ -79,7 +79,7 @@ enum ZVECT_ERR {
|
||||||
// Vector construction/Destruction and memory control:
|
// Vector construction/Destruction and memory control:
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_create creates and returns a new vector
|
* vect_create creates and returns a new c_vector
|
||||||
* of the specified "capacity", with a storage area that
|
* of the specified "capacity", with a storage area that
|
||||||
* can store items of "item_size" size and, if we want to
|
* can store items of "item_size" size and, if we want to
|
||||||
* have an automatic secure erasing enabled (ZV_SEC_WIPE
|
* have an automatic secure erasing enabled (ZV_SEC_WIPE
|
||||||
|
@ -87,56 +87,56 @@ enum ZVECT_ERR {
|
||||||
* after item_size. Flags syntax is the usual C flag sets:
|
* after item_size. Flags syntax is the usual C flag sets:
|
||||||
* ZV_SEC_WIPE | ZV_BYREF etc.
|
* ZV_SEC_WIPE | ZV_BYREF etc.
|
||||||
*/
|
*/
|
||||||
vector vect_create(zvect_index capacity, size_t item_size, uint32_t properties);
|
c_vector vect_create(zvect_index capacity, size_t item_size, uint32_t properties);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_destroy destroys the specified vector and, if
|
* vect_destroy destroys the specified c_vector and, if
|
||||||
* secure_wipe is enabled, also ensure erasing each single
|
* secure_wipe is enabled, also ensure erasing each single
|
||||||
* value in the vector before destroying it.
|
* value in the c_vector before destroying it.
|
||||||
*/
|
*/
|
||||||
void vect_destroy(vector);
|
void vect_destroy(c_vector);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_shrink is useful when operating on systems with
|
* vect_shrink is useful when operating on systems with
|
||||||
* small amount of RAM, and it basically allows to shrink
|
* small amount of RAM, and it basically allows to shrink
|
||||||
* the vector capacity to match the actual used size, to
|
* the c_vector capacity to match the actual used size, to
|
||||||
* save unused memory locations.
|
* save unused memory locations.
|
||||||
*/
|
*/
|
||||||
void vect_shrink(vector const v);
|
void vect_shrink(c_vector const v);
|
||||||
#define vect_shrink_to_fit(x) vect_shrink(x)
|
#define vect_shrink_to_fit(x) vect_shrink(x)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_set_wipefunct allows you to pass ZVector a pointer to a custom
|
* vect_set_wipefunct allows you to pass ZVector a pointer to a custom
|
||||||
* function (of your creation) to securely wipe data from the vector v
|
* function (of your creation) to securely wipe data from the c_vector v
|
||||||
* when automatic safe wipe is called.
|
* when automatic safe wipe is called.
|
||||||
*/
|
*/
|
||||||
void vect_set_wipefunct(vector const v, void (*f1)(const void *item, size_t size));
|
void vect_set_wipefunct(c_vector const v, void (*f1)(const void *item, size_t size));
|
||||||
|
|
||||||
// Vector state checks:
|
// Vector state checks:
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_is_empty returns true if the vector is empty
|
* vect_is_empty returns true if the c_vector is empty
|
||||||
* and false if the vector is NOT empty.
|
* and false if the c_vector is NOT empty.
|
||||||
*/
|
*/
|
||||||
bool vect_is_empty(vector const v);
|
bool vect_is_empty(c_vector const v);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_size returns the actual size (the number of)
|
* vect_size returns the actual size (the number of)
|
||||||
* USED slots in the vector storage.
|
* USED slots in the c_vector storage.
|
||||||
*/
|
*/
|
||||||
zvect_index vect_size(vector const v);
|
zvect_index vect_size(c_vector const v);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_clear clears out a vector and also resizes it
|
* vect_clear clears out a c_vector and also resizes it
|
||||||
* to its initial capacity.
|
* to its initial capacity.
|
||||||
*/
|
*/
|
||||||
void vect_clear(vector const v);
|
void vect_clear(c_vector const v);
|
||||||
|
|
||||||
bool vect_check_status(const vector v, zvect_index flag_id);
|
bool vect_check_status(const c_vector v, zvect_index flag_id);
|
||||||
|
|
||||||
bool vect_set_status(const vector v, zvect_index flag_id);
|
bool vect_set_status(const c_vector v, zvect_index flag_id);
|
||||||
|
|
||||||
bool vect_clear_status(const vector v, zvect_index flag_id);
|
bool vect_clear_status(const c_vector v, zvect_index flag_id);
|
||||||
|
|
||||||
#if (ZVECT_THREAD_SAFE == 1)
|
#if (ZVECT_THREAD_SAFE == 1)
|
||||||
// Vector Thread Safe functions:
|
// Vector Thread Safe functions:
|
||||||
|
@ -164,57 +164,57 @@ void vect_lock_enable(void);
|
||||||
void vect_lock_disable(void);
|
void vect_lock_disable(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_lock allows you to lock the given vector to
|
* vect_lock allows you to lock the given c_vector to
|
||||||
* have exclusive write access from your own thread.
|
* have exclusive write access from your own thread.
|
||||||
* When you lock a vector directly then ZVector will
|
* When you lock a c_vector directly then ZVector will
|
||||||
* NOT use its internal locking mechanism for that
|
* NOT use its internal locking mechanism for that
|
||||||
* specific vector.
|
* specific c_vector.
|
||||||
*
|
*
|
||||||
* Example of use: To lock a vector called v
|
* Example of use: To lock a c_vector called v
|
||||||
* vect_lock(v);
|
* vect_lock(v);
|
||||||
*/
|
*/
|
||||||
zvect_retval vect_lock(vector const v);
|
zvect_retval vect_lock(c_vector const v);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_trylock will try to lock the given vector to
|
* vect_trylock will try to lock the given c_vector to
|
||||||
* have exclusive write access from your own thread.
|
* have exclusive write access from your own thread.
|
||||||
* When you lock a vector directly then ZVector will
|
* When you lock a c_vector directly then ZVector will
|
||||||
* NOT use its internal locking mechanism for that
|
* NOT use its internal locking mechanism for that
|
||||||
* specific vector.
|
* specific c_vector.
|
||||||
*
|
*
|
||||||
* Example of use: To lock a vector called v
|
* Example of use: To lock a c_vector called v
|
||||||
* vect_trylock(v);
|
* vect_trylock(v);
|
||||||
*/
|
*/
|
||||||
zvect_retval vect_trylock(vector const v);
|
zvect_retval vect_trylock(c_vector const v);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_lock allows you to unlock the given vector that
|
* vect_lock allows you to unlock the given c_vector that
|
||||||
* you have previously locked with vect_lock.
|
* you have previously locked with vect_lock.
|
||||||
*
|
*
|
||||||
* Example of use: To unlock a vector called v
|
* Example of use: To unlock a c_vector called v
|
||||||
* vect_unlock(v);
|
* vect_unlock(v);
|
||||||
*/
|
*/
|
||||||
zvect_retval vect_unlock(vector const v);
|
zvect_retval vect_unlock(c_vector const v);
|
||||||
|
|
||||||
/* TODO:
|
/* TODO:
|
||||||
* zvect_retval vect_wait_for_signal(const vector v);
|
* zvect_retval vect_wait_for_signal(const c_vector v);
|
||||||
*
|
*
|
||||||
* zvect_retval vect_lock_after_signal(const vector v);
|
* zvect_retval vect_lock_after_signal(const c_vector v);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
zvect_retval vect_move_on_signal(vector const v1,
|
zvect_retval vect_move_on_signal(c_vector const v1,
|
||||||
vector v2,
|
c_vector v2,
|
||||||
const zvect_index s2,
|
const zvect_index s2,
|
||||||
const zvect_index e2,
|
const zvect_index e2,
|
||||||
zvect_retval (*f2)(void *, void *));
|
zvect_retval (*f2)(void *, void *));
|
||||||
|
|
||||||
zvect_retval vect_send_signal(const vector v);
|
zvect_retval vect_send_signal(const c_vector v);
|
||||||
|
|
||||||
zvect_retval vect_broadcast_signal(const vector v);
|
zvect_retval vect_broadcast_signal(const c_vector v);
|
||||||
|
|
||||||
zvect_retval vect_sem_wait(const vector v);
|
zvect_retval vect_sem_wait(const c_vector v);
|
||||||
|
|
||||||
zvect_retval vect_sem_post(const vector v);
|
zvect_retval vect_sem_post(const c_vector v);
|
||||||
|
|
||||||
#endif // ( ZVECT_THREAD_SAFE == 1 )
|
#endif // ( ZVECT_THREAD_SAFE == 1 )
|
||||||
|
|
||||||
|
@ -223,174 +223,174 @@ zvect_retval vect_sem_post(const vector v);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_push and vect_pop are used to use the
|
* vect_push and vect_pop are used to use the
|
||||||
* vector as a dynamic stack.
|
* c_vector as a dynamic stack.
|
||||||
*
|
*
|
||||||
* int i = 3;
|
* int i = 3;
|
||||||
* vect_push(v, &i) pushes the element 3 at the
|
* vect_push(v, &i) pushes the element 3 at the
|
||||||
* back of the vector v, which
|
* back of the c_vector v, which
|
||||||
* corresponds to the top of a
|
* corresponds to the top of a
|
||||||
* Stack.
|
* Stack.
|
||||||
*/
|
*/
|
||||||
void vect_push(vector const v, const void *item);
|
void vect_push(c_vector const v, const void *item);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_pop(v) "pops" (returns) the element
|
* vect_pop(v) "pops" (returns) the element
|
||||||
* at the back of the vector as
|
* at the back of the c_vector as
|
||||||
* a regular pop would do with
|
* a regular pop would do with
|
||||||
* an element at the top of a
|
* an element at the top of a
|
||||||
* stack. Remember when you use
|
* stack. Remember when you use
|
||||||
* vect_pop the element you
|
* vect_pop the element you
|
||||||
* receive is also removed from
|
* receive is also removed from
|
||||||
* the vector!
|
* the c_vector!
|
||||||
*/
|
*/
|
||||||
void *vect_pop(vector const v);
|
void *vect_pop(c_vector const v);
|
||||||
#define vect_pop_back(x) vect_pop(x)
|
#define vect_pop_back(x) vect_pop(x)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_add adds a new item into the vector and,
|
* vect_add adds a new item into the c_vector and,
|
||||||
* if required, will also reorganize the vector.
|
* if required, will also reorganize the c_vector.
|
||||||
*
|
*
|
||||||
* int i = 3;
|
* int i = 3;
|
||||||
* vect_add(v, &i) will add the new item 3 in
|
* vect_add(v, &i) will add the new item 3 in
|
||||||
* the vector v at the end
|
* the c_vector v at the end
|
||||||
* (or back) of the vector v.
|
* (or back) of the c_vector v.
|
||||||
*/
|
*/
|
||||||
void vect_add(vector const v, const void *item);
|
void vect_add(c_vector const v, const void *item);
|
||||||
#define vect_push_back(x, y) vect_add(x, y)
|
#define vect_push_back(x, y) vect_add(x, y)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* int i = 4;
|
* int i = 4;
|
||||||
* vect_add_at(v, &i, 2) will add the new item 4 at
|
* vect_add_at(v, &i, 2) will add the new item 4 at
|
||||||
* position 2 in the vector v
|
* position 2 in the c_vector v
|
||||||
* and move all the elements
|
* and move all the elements
|
||||||
* from the original 2nd onward
|
* from the original 2nd onward
|
||||||
* of a position to make space
|
* of a position to make space
|
||||||
* for the new item 4.
|
* for the new item 4.
|
||||||
*/
|
*/
|
||||||
void vect_add_at(vector const v, const void *item, zvect_index index);
|
void vect_add_at(c_vector const v, const void *item, zvect_index index);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* int i = 5;
|
* int i = 5;
|
||||||
* vect_add_front(v, &i) will add the new item 5 at
|
* vect_add_front(v, &i) will add the new item 5 at
|
||||||
* the beginning of the vector
|
* the beginning of the c_vector
|
||||||
* v (or front) and will also
|
* v (or front) and will also
|
||||||
* move all the existing
|
* move all the existing
|
||||||
* elements of one position in
|
* elements of one position in
|
||||||
* the vector to make space for
|
* the c_vector to make space for
|
||||||
* the new item 5 at the front
|
* the new item 5 at the front
|
||||||
* of vector v.
|
* of c_vector v.
|
||||||
*/
|
*/
|
||||||
void vect_add_front(vector const v, const void *item);
|
void vect_add_front(c_vector const v, const void *item);
|
||||||
#define vect_push_front(x, y) vect_add_front(x, y)
|
#define vect_push_front(x, y) vect_add_front(x, y)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_get returns an item from the specified vector
|
* vect_get returns an item from the specified c_vector
|
||||||
*
|
*
|
||||||
* vect_get(v) will return the ast element in
|
* vect_get(v) will return the ast element in
|
||||||
* the v vector (but will not remove
|
* the v c_vector (but will not remove
|
||||||
* the element as it happens in
|
* the element as it happens in
|
||||||
* vect_pop(v)).
|
* vect_pop(v)).
|
||||||
*/
|
*/
|
||||||
void *vect_get(vector const v);
|
void *vect_get(c_vector const v);
|
||||||
#define vect_back(v) vect_get(v)
|
#define vect_back(v) vect_get(v)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* vect_get_at(v, 3) will return the element at location
|
* vect_get_at(v, 3) will return the element at location
|
||||||
* 3 in the vector v.
|
* 3 in the c_vector v.
|
||||||
*/
|
*/
|
||||||
void *vect_get_at(vector const v, const zvect_index i);
|
void *vect_get_at(c_vector const v, const zvect_index i);
|
||||||
#define vect_at(v, x) vect_get_at(v, x)
|
#define vect_at(v, x) vect_get_at(v, x)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_get_front(v) will return the first element in
|
* vect_get_front(v) will return the first element in
|
||||||
* the vector v.
|
* the c_vector v.
|
||||||
*/
|
*/
|
||||||
void *vect_get_front(vector const v);
|
void *vect_get_front(c_vector const v);
|
||||||
#define vect_front(v) vect_get_front(v)
|
#define vect_front(v) vect_get_front(v)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*vect_put allows you to REPLACE an item
|
*vect_put allows you to REPLACE an item
|
||||||
* in the vector.
|
* in the c_vector.
|
||||||
*
|
*
|
||||||
* int i = 3;
|
* int i = 3;
|
||||||
* vect_put(v, &i) will replace the last element
|
* vect_put(v, &i) will replace the last element
|
||||||
* in the vector with 3.
|
* in the c_vector with 3.
|
||||||
*/
|
*/
|
||||||
void vect_put(vector const v, const void *item);
|
void vect_put(c_vector const v, const void *item);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* int i = 4;
|
* int i = 4;
|
||||||
* vect_put_at(v, &i, 2) will replace the 3rd element
|
* vect_put_at(v, &i, 2) will replace the 3rd element
|
||||||
* (2 + 1, as vector's 1st item
|
* (2 + 1, as c_vector's 1st item
|
||||||
* starts at v[0]) with the
|
* starts at v[0]) with the
|
||||||
* item 4.
|
* item 4.
|
||||||
*/
|
*/
|
||||||
void vect_put_at(vector const v, const void *item, const zvect_index i);
|
void vect_put_at(c_vector const v, const void *item, const zvect_index i);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* int i = 5;
|
* int i = 5;
|
||||||
* vect_put_front(v, &i) will replace the 1st element
|
* vect_put_front(v, &i) will replace the 1st element
|
||||||
* of the vector with the item
|
* of the c_vector with the item
|
||||||
* 5.
|
* 5.
|
||||||
*/
|
*/
|
||||||
void vect_put_front(vector const v, const void *item);
|
void vect_put_front(c_vector const v, const void *item);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_remove removes an item from the vector
|
* vect_remove removes an item from the c_vector
|
||||||
* and reorganise the vector. It also returns
|
* and reorganise the c_vector. It also returns
|
||||||
* the item remove from the vector, so you can
|
* the item remove from the c_vector, so you can
|
||||||
* use it to simulate a stack behaviour as well.
|
* use it to simulate a stack behaviour as well.
|
||||||
*
|
*
|
||||||
* vect_remove(v) will remove and return the
|
* vect_remove(v) will remove and return the
|
||||||
* last item in the vector.
|
* last item in the c_vector.
|
||||||
*/
|
*/
|
||||||
void *vect_remove(vector const v);
|
void *vect_remove(c_vector const v);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_remove_at(v, 3) will remove the 3rd item in
|
* vect_remove_at(v, 3) will remove the 3rd item in
|
||||||
* the vector and return it.
|
* the c_vector and return it.
|
||||||
*/
|
*/
|
||||||
void *vect_remove_at(vector const v, const zvect_index i);
|
void *vect_remove_at(c_vector const v, const zvect_index i);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_remove_front(v) will remove the 1st item in
|
* vect_remove_front(v) will remove the 1st item in
|
||||||
* the vector and return it.
|
* the c_vector and return it.
|
||||||
*/
|
*/
|
||||||
void *vect_remove_front(vector const v);
|
void *vect_remove_front(c_vector const v);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_delete deletes an item from the vector
|
* vect_delete deletes an item from the c_vector
|
||||||
* and reorganise the vector. It does not return
|
* and reorganise the c_vector. It does not return
|
||||||
* the item like remove.
|
* the item like remove.
|
||||||
*
|
*
|
||||||
* vect_delete(v) will delete and the last
|
* vect_delete(v) will delete and the last
|
||||||
* item in the vector.
|
* item in the c_vector.
|
||||||
*/
|
*/
|
||||||
void vect_delete(vector const v);
|
void vect_delete(c_vector const v);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_delete_at(v, 3) will delete the 3rd item in
|
* vect_delete_at(v, 3) will delete the 3rd item in
|
||||||
* the vector.
|
* the c_vector.
|
||||||
*/
|
*/
|
||||||
void vect_delete_at(vector const v, const zvect_index i);
|
void vect_delete_at(c_vector const v, const zvect_index i);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_delete_range(v, 20, 30)
|
* vect_delete_range(v, 20, 30)
|
||||||
* will delete items from item
|
* will delete items from item
|
||||||
* 20 to item 30 in the vector
|
* 20 to item 30 in the c_vector
|
||||||
* v.
|
* v.
|
||||||
*/
|
*/
|
||||||
void vect_delete_range(vector const v, const zvect_index first_element, const zvect_index last_element);
|
void vect_delete_range(c_vector const v, const zvect_index first_element, const zvect_index last_element);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* vect_delete_front(v) will delete the 1st item in
|
* vect_delete_front(v) will delete the 1st item in
|
||||||
* the vector.
|
* the c_vector.
|
||||||
*/
|
*/
|
||||||
void vect_delete_front(vector const v);
|
void vect_delete_front(c_vector const v);
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
// Vector Data manipulation functions:
|
// Vector Data manipulation functions:
|
||||||
|
@ -401,70 +401,70 @@ void vect_delete_front(vector const v);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_swap is a function that allows you to swap two
|
* vect_swap is a function that allows you to swap two
|
||||||
* items in the same vector.
|
* items in the same c_vector.
|
||||||
* You just pass the vector and the index of both the
|
* You just pass the c_vector and the index of both the
|
||||||
* two items to swap.
|
* two items to swap.
|
||||||
*
|
*
|
||||||
* For example to swap item 3 with item 22 on vector v
|
* For example to swap item 3 with item 22 on c_vector v
|
||||||
* use:
|
* use:
|
||||||
* vect_swap(v, 3, 22);
|
* vect_swap(v, 3, 22);
|
||||||
*/
|
*/
|
||||||
void vect_swap(vector const v, const zvect_index s, const zvect_index e);
|
void vect_swap(c_vector const v, const zvect_index s, const zvect_index e);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_swap_range is a function that allows to swap
|
* vect_swap_range is a function that allows to swap
|
||||||
* a range of items in the same vector.
|
* a range of items in the same c_vector.
|
||||||
* You just pass the vector, the index of the first item
|
* You just pass the c_vector, the index of the first item
|
||||||
* to swap, the index of the last item to swap and the
|
* to swap, the index of the last item to swap and the
|
||||||
* index of the first item to swap with.
|
* index of the first item to swap with.
|
||||||
*
|
*
|
||||||
* For example to swap items from 10 to 20 with items
|
* For example to swap items from 10 to 20 with items
|
||||||
* from 30 to 40 on vector v, use:
|
* from 30 to 40 on c_vector v, use:
|
||||||
* vect_swap_range(v, 10, 20, 30);
|
* vect_swap_range(v, 10, 20, 30);
|
||||||
*/
|
*/
|
||||||
void vect_swap_range(vector const v, const zvect_index s1, const zvect_index e1, const zvect_index s2);
|
void vect_swap_range(c_vector const v, const zvect_index s1, const zvect_index e1, const zvect_index s2);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_rotate_left is a function that allows to rotate
|
* vect_rotate_left is a function that allows to rotate
|
||||||
* a vector of "i" positions to the left (or from the
|
* a c_vector of "i" positions to the left (or from the
|
||||||
* "front" to the "end").
|
* "front" to the "end").
|
||||||
*
|
*
|
||||||
* For example to rotate a vector called v of 5 positions
|
* For example to rotate a c_vector called v of 5 positions
|
||||||
* to the left, use:
|
* to the left, use:
|
||||||
* vect_rotate_left(v, 5);
|
* vect_rotate_left(v, 5);
|
||||||
*/
|
*/
|
||||||
void vect_rotate_left(vector const v, const zvect_index i);
|
void vect_rotate_left(c_vector const v, const zvect_index i);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_rotate_right is a function that allows to rotate
|
* vect_rotate_right is a function that allows to rotate
|
||||||
* a vector of "i" positions to the right (or from the
|
* a c_vector of "i" positions to the right (or from the
|
||||||
* "end" to the "front").
|
* "end" to the "front").
|
||||||
*
|
*
|
||||||
* For example to rotate a vector called v of 5 positions
|
* For example to rotate a c_vector called v of 5 positions
|
||||||
* to the right, use:
|
* to the right, use:
|
||||||
* vect_rotate_right(v, 5);
|
* vect_rotate_right(v, 5);
|
||||||
*/
|
*/
|
||||||
void vect_rotate_right(vector const v, const zvect_index i);
|
void vect_rotate_right(c_vector const v, const zvect_index i);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_qsort allows you to sort a given vector.
|
* vect_qsort allows you to sort a given c_vector.
|
||||||
* The algorithm used to sort a vector is Quicksort with
|
* The algorithm used to sort a c_vector is Quicksort with
|
||||||
* 3 ways partitioning which is generally much faster than
|
* 3 ways partitioning which is generally much faster than
|
||||||
* traditional quicksort.
|
* traditional quicksort.
|
||||||
*
|
*
|
||||||
* To sort a vector you need to provide a custom function
|
* To sort a c_vector you need to provide a custom function
|
||||||
* that allows vect_sort to determine the order and which
|
* that allows vect_sort to determine the order and which
|
||||||
* elements of a vector are used to order it in the way
|
* elements of a c_vector are used to order it in the way
|
||||||
* you desire. It pretty much works as a regular C qsort
|
* you desire. It pretty much works as a regular C qsort
|
||||||
* function. It quite fast given that it only reorders
|
* function. It quite fast given that it only reorders
|
||||||
* pointers to your datastructures stored in the vector.
|
* pointers to your datastructures stored in the c_vector.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void vect_qsort(vector const v, int (*compare_func)(const void *, const void *));
|
void vect_qsort(c_vector const v, int (*compare_func)(const void *, const void *));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_bsearch is a function that allows to perform
|
* vect_bsearch is a function that allows to perform
|
||||||
* a binary search over the vector we pass to it to
|
* a binary search over the c_vector we pass to it to
|
||||||
* find the item "key" using the comparison function
|
* find the item "key" using the comparison function
|
||||||
* "f1".
|
* "f1".
|
||||||
*
|
*
|
||||||
|
@ -474,7 +474,7 @@ void vect_qsort(vector const v, int (*compare_func)(const void *, const void *))
|
||||||
* some improvements over the original one (look at the
|
* some improvements over the original one (look at the
|
||||||
* sources for more details).
|
* sources for more details).
|
||||||
*
|
*
|
||||||
* For example to search for the number 5 in a vector
|
* For example to search for the number 5 in a c_vector
|
||||||
* called v using a compare function called "my_compare"
|
* called v using a compare function called "my_compare"
|
||||||
* use:
|
* use:
|
||||||
* int i = 5;
|
* int i = 5;
|
||||||
|
@ -483,7 +483,7 @@ void vect_qsort(vector const v, int (*compare_func)(const void *, const void *))
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
bool vect_bsearch(vector const v, const void *key, int (*f1)(const void *, const void *), zvect_index *item_index);
|
bool vect_bsearch(c_vector const v, const void *key, int (*f1)(const void *, const void *), zvect_index *item_index);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -491,20 +491,20 @@ bool vect_bsearch(vector const v, const void *key, int (*f1)(const void *, const
|
||||||
* vect_add_ordered allows the insertion of new items in
|
* vect_add_ordered allows the insertion of new items in
|
||||||
* an ordered fashion. Please note that for this to work
|
* an ordered fashion. Please note that for this to work
|
||||||
* fine you should always use only ordered vectors or if
|
* fine you should always use only ordered vectors or if
|
||||||
* an empty vector use vect_add_ordered only to add new
|
* an empty c_vector use vect_add_ordered only to add new
|
||||||
* values to it!
|
* values to it!
|
||||||
*
|
*
|
||||||
* As for any other ordered function you must provide
|
* As for any other ordered function you must provide
|
||||||
* your own compare function (syntax is the usual one,
|
* your own compare function (syntax is the usual one,
|
||||||
* and it's the same as for regular CLib qsort function)
|
* and it's the same as for regular CLib qsort function)
|
||||||
*
|
*
|
||||||
* To add item 3 to a vector called v using vect_add_ordered
|
* To add item 3 to a c_vector called v using vect_add_ordered
|
||||||
* (assuming your compare function is called my_compare),
|
* (assuming your compare function is called my_compare),
|
||||||
* use:
|
* use:
|
||||||
*
|
*
|
||||||
* vect_Add_ordered(v, 3, my_compare);
|
* vect_Add_ordered(v, 3, my_compare);
|
||||||
*/
|
*/
|
||||||
void vect_add_ordered(vector const v, const void *value, int (*f1)(const void *, const void *));
|
void vect_add_ordered(c_vector const v, const void *value, int (*f1)(const void *, const void *));
|
||||||
|
|
||||||
#endif // ZVECT_DMF_EXTENSIONS
|
#endif // ZVECT_DMF_EXTENSIONS
|
||||||
|
|
||||||
|
@ -513,23 +513,23 @@ void vect_add_ordered(vector const v, const void *value, int (*f1)(const void *,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_apply allows you to apply a C function to
|
* vect_apply allows you to apply a C function to
|
||||||
* each item in the vector, so you just pass the vector,
|
* each item in the c_vector, so you just pass the c_vector,
|
||||||
* the function you want to execute against each item on
|
* the function you want to execute against each item on
|
||||||
* a vector and make sure such function is declared and
|
* a c_vector and make sure such function is declared and
|
||||||
* defined to accept a "void *" pointer which will be the
|
* defined to accept a "void *" pointer which will be the
|
||||||
* pointer to the single item in the vector passed to your
|
* pointer to the single item in the c_vector passed to your
|
||||||
* function. The function has no return value because it's
|
* function. The function has no return value because it's
|
||||||
* not necessary if you receive the pointer to the item.
|
* not necessary if you receive the pointer to the item.
|
||||||
* You can simply update the content of the memory pointed
|
* You can simply update the content of the memory pointed
|
||||||
* by the item passed and that is much faster than having
|
* by the item passed and that is much faster than having
|
||||||
* to deal with return values especially when you'll be
|
* to deal with return values especially when you'll be
|
||||||
* using complex data structures as item of the vector.
|
* using complex data structures as item of the c_vector.
|
||||||
*/
|
*/
|
||||||
void vect_apply(vector const v, void (*f1)(void *));
|
void vect_apply(c_vector const v, void (*f1)(void *));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_apply_if is a function that will apply "f1" C function
|
* vect_apply_if is a function that will apply "f1" C function
|
||||||
* to each and every item in vector v1, IF the return value of
|
* to each and every item in c_vector v1, IF the return value of
|
||||||
* function f2 is true. So it allows what is known as conditional
|
* function f2 is true. So it allows what is known as conditional
|
||||||
* application. f2 will receive an item from v1 as first parameter
|
* application. f2 will receive an item from v1 as first parameter
|
||||||
* and an item from v2 (at the same position of the item in v1) as
|
* and an item from v2 (at the same position of the item in v1) as
|
||||||
|
@ -555,51 +555,55 @@ void vect_apply(vector const v, void (*f1)(void *));
|
||||||
* return false;
|
* return false;
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
void vect_apply_if(vector const v1, vector const v2, void (*f1)(void *), bool (*f2)(void *, void *));
|
void vect_apply_if(c_vector const v1, c_vector const v2, void (*f1)(void *), bool (*f2)(void *, void *));
|
||||||
|
|
||||||
// Operations with multiple vectors:
|
// Operations with multiple vectors:
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_copy is a function that allows to copy a specified
|
* vect_copy is a function that allows to copy a specified
|
||||||
* set of elements from a vector to another.
|
* set of elements from a c_vector to another.
|
||||||
* Please note: only vectors with the same data size (the
|
* Please note: only vectors with the same data size (the
|
||||||
* parameter we pass during the creation of both vectors)
|
* parameter we pass during the creation of both vectors)
|
||||||
* can be copied into the other!
|
* can be copied into the other!
|
||||||
*
|
*
|
||||||
* vect_copy(v1, v2, 3, 5) will copy all the items in
|
* vect_copy(v1, v2, 3, 5) will copy all the items in
|
||||||
* vector v2, from the 4th item
|
* c_vector v2, from the 4th item
|
||||||
* till the 9th (3 + 5, remember
|
* till the 9th (3 + 5, remember
|
||||||
* vector items start from 0) in
|
* c_vector items start from 0) in
|
||||||
* the vector v1. So at the end
|
* the c_vector v1. So at the end
|
||||||
* of the process you'll have such
|
* of the process you'll have such
|
||||||
* items copied at the end of v1.
|
* items copied at the end of v1.
|
||||||
*/
|
*/
|
||||||
void vect_copy(vector const v1, vector const v2, zvect_index start, zvect_index max_elements);
|
void vect_copy(c_vector const v1, c_vector const v2, zvect_index start, zvect_index max_elements);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_insert is a function that allows to copy a specified
|
* vect_insert is a function that allows to copy a specified
|
||||||
* set of elements from a vector to another and "insert"
|
* set of elements from a c_vector to another and "insert"
|
||||||
* them from a specified position in the destination vector.
|
* them from a specified position in the destination c_vector.
|
||||||
* Please note: only vectors with the same data size (the
|
* Please note: only vectors with the same data size (the
|
||||||
* parameter we pass during the creation of both vectors)
|
* parameter we pass during the creation of both vectors)
|
||||||
* can be copied into the other!
|
* can be copied into the other!
|
||||||
*
|
*
|
||||||
* vect_insert(v1, v2, 3, 5, 7) will copy all the items in
|
* vect_insert(v1, v2, 3, 5, 7) will copy all the items in
|
||||||
* vector v2, from the 4th item
|
* c_vector v2, from the 4th item
|
||||||
* till the 9th (3 + 5, remember
|
* till the 9th (3 + 5, remember
|
||||||
* vector items start from 0) in
|
* c_vector items start from 0) in
|
||||||
* the vector v1 from position 7.
|
* the c_vector v1 from position 7.
|
||||||
* So at the end of the process
|
* So at the end of the process
|
||||||
* you'll have such items "inserted"
|
* you'll have such items "inserted"
|
||||||
* inside v1.
|
* inside v1.
|
||||||
*/
|
*/
|
||||||
void vect_insert(vector const v1, vector const v2, const zvect_index s2, const zvect_index e2, const zvect_index s1);
|
void vect_insert(c_vector const v1,
|
||||||
|
c_vector const v2,
|
||||||
|
const zvect_index s2,
|
||||||
|
const zvect_index e2,
|
||||||
|
const zvect_index s1);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_move is a function that allows to move a specified
|
* vect_move is a function that allows to move a specified
|
||||||
* set of items from one vector to another.
|
* set of items from one c_vector to another.
|
||||||
* It will also re-organise the source vector and (obviously)
|
* It will also re-organise the source c_vector and (obviously)
|
||||||
* expand the destination vector if needed.
|
* expand the destination c_vector if needed.
|
||||||
* Please note: only vectors of the same data size can be moved
|
* Please note: only vectors of the same data size can be moved
|
||||||
* one into the other!
|
* one into the other!
|
||||||
*
|
*
|
||||||
|
@ -607,15 +611,15 @@ void vect_insert(vector const v1, vector const v2, const zvect_index s2, const z
|
||||||
* 3rd item in v2 till the 5th at
|
* 3rd item in v2 till the 5th at
|
||||||
* the end of v1.
|
* the end of v1.
|
||||||
*/
|
*/
|
||||||
void vect_move(vector const v1, vector const v2, zvect_index start, zvect_index max_elements);
|
void vect_move(c_vector const v1, c_vector const v2, zvect_index start, zvect_index max_elements);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_move_if is a function that allows to move a specified
|
* vect_move_if is a function that allows to move a specified
|
||||||
* set of items from one vector to another if the condition
|
* set of items from one c_vector to another if the condition
|
||||||
* returned by the function pointed by f2 function pointer
|
* returned by the function pointed by f2 function pointer
|
||||||
* is true.
|
* is true.
|
||||||
* It will also re-organise the source vector and (obviously)
|
* It will also re-organise the source c_vector and (obviously)
|
||||||
* expand the destination vector if needed.
|
* expand the destination c_vector if needed.
|
||||||
* Please note: only vectors of the same data size can be moved
|
* Please note: only vectors of the same data size can be moved
|
||||||
* one into the other!
|
* one into the other!
|
||||||
*
|
*
|
||||||
|
@ -624,8 +628,8 @@ void vect_move(vector const v1, vector const v2, zvect_index start, zvect_index
|
||||||
* the end of v1 if check_data returns
|
* the end of v1 if check_data returns
|
||||||
* true.
|
* true.
|
||||||
*/
|
*/
|
||||||
zvect_retval vect_move_if(vector const v1,
|
zvect_retval vect_move_if(c_vector const v1,
|
||||||
vector v2,
|
c_vector v2,
|
||||||
const zvect_index s2,
|
const zvect_index s2,
|
||||||
const zvect_index e2,
|
const zvect_index e2,
|
||||||
zvect_retval (*f2)(void *, void *));
|
zvect_retval (*f2)(void *, void *));
|
||||||
|
@ -633,14 +637,14 @@ zvect_retval vect_move_if(vector const v1,
|
||||||
/*
|
/*
|
||||||
* vect_merge is a function that merges together 2 vectors of
|
* vect_merge is a function that merges together 2 vectors of
|
||||||
* the same data size. At the end of the process, the source
|
* the same data size. At the end of the process, the source
|
||||||
* vector will be destroyed.
|
* c_vector will be destroyed.
|
||||||
*
|
*
|
||||||
* vect_merge(v1, v2) will merge vector v2 to v1 and then
|
* vect_merge(v1, v2) will merge c_vector v2 to v1 and then
|
||||||
* destroy v2. So at the end of the job
|
* destroy v2. So at the end of the job
|
||||||
* v1 will contain the old v1 items +
|
* v1 will contain the old v1 items +
|
||||||
* all v2 items.
|
* all v2 items.
|
||||||
*/
|
*/
|
||||||
void vect_merge(vector const v1, vector v2);
|
void vect_merge(c_vector const v1, c_vector v2);
|
||||||
|
|
||||||
#endif // ZVECT_SFMD_EXTENSIONS
|
#endif // ZVECT_SFMD_EXTENSIONS
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
#define ZVECT_ALWAYSINLINE
|
#define ZVECT_ALWAYSINLINE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Default vector Index type
|
// Default c_vector Index type
|
||||||
// This is set to unsigned int of 32bit
|
// This is set to unsigned int of 32bit
|
||||||
// size (so all different architectures
|
// size (so all different architectures
|
||||||
// and OS behaves in a similar way)
|
// and OS behaves in a similar way)
|
||||||
|
@ -40,7 +40,7 @@ typedef uint32_t zvect_index;
|
||||||
// it's the maximum number that can be stored in a zvect_index.
|
// it's the maximum number that can be stored in a zvect_index.
|
||||||
#define zvect_index_max (4294967295)
|
#define zvect_index_max (4294967295)
|
||||||
|
|
||||||
// Default vector return type for
|
// Default c_vector return type for
|
||||||
// error codes.
|
// error codes.
|
||||||
// Generally negative numbers identify
|
// Generally negative numbers identify
|
||||||
// an error.
|
// an error.
|
||||||
|
@ -49,13 +49,13 @@ typedef uint32_t zvect_index;
|
||||||
// attributes, like 1 is generally true
|
// attributes, like 1 is generally true
|
||||||
typedef int32_t zvect_retval;
|
typedef int32_t zvect_retval;
|
||||||
|
|
||||||
// Default vector storage size
|
// Default c_vector storage size
|
||||||
// This will be used when the user
|
// This will be used when the user
|
||||||
// specifies 0 (zero) as data type
|
// specifies 0 (zero) as data type
|
||||||
// size.
|
// size.
|
||||||
#define ZVECT_DEFAULT_DATA_SIZE sizeof(int)
|
#define ZVECT_DEFAULT_DATA_SIZE sizeof(int)
|
||||||
|
|
||||||
// Default vector capacity
|
// Default c_vector capacity
|
||||||
// This will be used when the user
|
// This will be used when the user
|
||||||
// does NOT specify an Initial Capacity
|
// does NOT specify an Initial Capacity
|
||||||
// or set it to 0 (zero):
|
// or set it to 0 (zero):
|
||||||
|
|
|
@ -288,13 +288,13 @@ p_throw_error(const zvect_retval error_code, const char *error_message) {
|
||||||
if (locally_allocated) {
|
if (locally_allocated) {
|
||||||
switch (error_code) {
|
switch (error_code) {
|
||||||
case ZVERR_VECTUNDEF:
|
case ZVERR_VECTUNDEF:
|
||||||
message = (char *)safe_strncpy("Undefined or uninitialized vector.\n\0", msg_len);
|
message = (char *)safe_strncpy("Undefined or uninitialized c_vector.\n\0", msg_len);
|
||||||
break;
|
break;
|
||||||
case ZVERR_IDXOUTOFBOUND:
|
case ZVERR_IDXOUTOFBOUND:
|
||||||
message = (char *)safe_strncpy("Index out of bound.\n\0", msg_len);
|
message = (char *)safe_strncpy("Index out of bound.\n\0", msg_len);
|
||||||
break;
|
break;
|
||||||
case ZVERR_OUTOFMEM:
|
case ZVERR_OUTOFMEM:
|
||||||
message = (char *)safe_strncpy("Not enough memory to allocate space for the vector.\n\0", msg_len);
|
message = (char *)safe_strncpy("Not enough memory to allocate space for the c_vector.\n\0", msg_len);
|
||||||
break;
|
break;
|
||||||
case ZVERR_VECTCORRUPTED:
|
case ZVERR_VECTCORRUPTED:
|
||||||
message = (char *)safe_strncpy("Vector corrupted.\n\0", msg_len);
|
message = (char *)safe_strncpy("Vector corrupted.\n\0", msg_len);
|
||||||
|
@ -303,7 +303,7 @@ p_throw_error(const zvect_retval error_code, const char *error_message) {
|
||||||
message = (char *)safe_strncpy("Race condition detected, cannot continue.\n\0", msg_len);
|
message = (char *)safe_strncpy("Race condition detected, cannot continue.\n\0", msg_len);
|
||||||
break;
|
break;
|
||||||
case ZVERR_VECTTOOSMALL:
|
case ZVERR_VECTTOOSMALL:
|
||||||
message = (char *)safe_strncpy("Destination vector is smaller than source.\n\0", msg_len);
|
message = (char *)safe_strncpy("Destination c_vector is smaller than source.\n\0", msg_len);
|
||||||
break;
|
break;
|
||||||
case ZVERR_VECTDATASIZE:
|
case ZVERR_VECTDATASIZE:
|
||||||
message = (char *)safe_strncpy(
|
message = (char *)safe_strncpy(
|
||||||
|
@ -492,7 +492,7 @@ static inline void mutex_destroy(CRITICAL_SECTION *lock) {
|
||||||
* uses ZVector primitives.
|
* uses ZVector primitives.
|
||||||
* level 3 is the priority of the User's locks.
|
* level 3 is the priority of the User's locks.
|
||||||
*/
|
*/
|
||||||
static inline zvect_retval get_mutex_lock(const vector v, const int32_t lock_type) {
|
static inline zvect_retval get_mutex_lock(const c_vector v, const int32_t lock_type) {
|
||||||
if (lock_type >= v->lock_type) {
|
if (lock_type >= v->lock_type) {
|
||||||
mutex_lock(&(v->lock));
|
mutex_lock(&(v->lock));
|
||||||
v->lock_type = lock_type;
|
v->lock_type = lock_type;
|
||||||
|
@ -501,7 +501,7 @@ static inline zvect_retval get_mutex_lock(const vector v, const int32_t lock_typ
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline zvect_retval check_mutex_trylock(const vector v, const int32_t lock_type) {
|
static inline zvect_retval check_mutex_trylock(const c_vector v, const int32_t lock_type) {
|
||||||
if ((lock_type >= v->lock_type) && (!mutex_trylock(&(v->lock)))) {
|
if ((lock_type >= v->lock_type) && (!mutex_trylock(&(v->lock)))) {
|
||||||
v->lock_type = lock_type;
|
v->lock_type = lock_type;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -509,7 +509,7 @@ static inline zvect_retval check_mutex_trylock(const vector v, const int32_t loc
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline zvect_retval lock_after_signal(const vector v, const int32_t lock_type) {
|
static inline zvect_retval lock_after_signal(const c_vector v, const int32_t lock_type) {
|
||||||
if (lock_type >= v->lock_type) {
|
if (lock_type >= v->lock_type) {
|
||||||
//if (!mutex_trylock(&(v->lock))) {
|
//if (!mutex_trylock(&(v->lock))) {
|
||||||
while (!pthread_cond_wait(&(v->cond), &(v->lock))) {
|
while (!pthread_cond_wait(&(v->cond), &(v->lock))) {
|
||||||
|
@ -540,15 +540,15 @@ static inline zvect_retval wait_for_signal(const vector v, const int32_t lock_ty
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static inline zvect_retval send_signal(const vector v, const int32_t lock_type) {
|
static inline zvect_retval send_signal(const c_vector v, const int32_t lock_type) {
|
||||||
return (lock_type >= v->lock_type) ? pthread_cond_signal(&(v->cond)) : 0;
|
return (lock_type >= v->lock_type) ? pthread_cond_signal(&(v->cond)) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline zvect_retval broadcast_signal(const vector v, const int32_t lock_type) {
|
static inline zvect_retval broadcast_signal(const c_vector v, const int32_t lock_type) {
|
||||||
return (lock_type >= v->lock_type) ? pthread_cond_broadcast(&(v->cond)) : 0;
|
return (lock_type >= v->lock_type) ? pthread_cond_broadcast(&(v->cond)) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline zvect_retval get_mutex_unlock(const vector v, const int32_t lock_type) {
|
static inline zvect_retval get_mutex_unlock(const c_vector v, const int32_t lock_type) {
|
||||||
if (lock_type == v->lock_type) {
|
if (lock_type == v->lock_type) {
|
||||||
v->lock_type = 0;
|
v->lock_type = 0;
|
||||||
mutex_unlock(&(v->lock));
|
mutex_unlock(&(v->lock));
|
||||||
|
@ -584,21 +584,21 @@ void p_init_zvect(void) {
|
||||||
// Vector's Utilities:
|
// Vector's Utilities:
|
||||||
|
|
||||||
ZVECT_ALWAYSINLINE
|
ZVECT_ALWAYSINLINE
|
||||||
static inline zvect_retval p_vect_check(const vector x) {
|
static inline zvect_retval p_vect_check(const c_vector x) {
|
||||||
return (x == NULL) ? ZVERR_VECTUNDEF : 0;
|
return (x == NULL) ? ZVERR_VECTUNDEF : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZVECT_ALWAYSINLINE
|
ZVECT_ALWAYSINLINE
|
||||||
static inline zvect_index p_vect_capacity(const vector v) {
|
static inline zvect_index p_vect_capacity(const c_vector v) {
|
||||||
return (v->cap_left + v->cap_right);
|
return (v->cap_left + v->cap_right);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZVECT_ALWAYSINLINE
|
ZVECT_ALWAYSINLINE
|
||||||
static inline zvect_index p_vect_size(const vector v) {
|
static inline zvect_index p_vect_size(const c_vector v) {
|
||||||
return (v->end > v->begin) ? (v->end - v->begin) : (v->begin - v->end);
|
return (v->end > v->begin) ? (v->end - v->begin) : (v->begin - v->end);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void p_item_safewipe(vector const v, void *const item) {
|
static inline void p_item_safewipe(c_vector const v, void *const item) {
|
||||||
if (item != NULL) {
|
if (item != NULL) {
|
||||||
if (!(v->status & ZVS_CUST_WIPE_ON)) {
|
if (!(v->status & ZVS_CUST_WIPE_ON)) {
|
||||||
memset(item, 0, v->data_size);
|
memset(item, 0, v->data_size);
|
||||||
|
@ -619,11 +619,11 @@ static inline zvect_retval p_usr_status(zvect_index flag_id) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool vect_check_status(const vector v, zvect_index flag_id) {
|
bool vect_check_status(const c_vector v, zvect_index flag_id) {
|
||||||
return (v->status >> flag_id) & 1U;
|
return (v->status >> flag_id) & 1U;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool vect_set_status(const vector v, zvect_index flag_id) {
|
bool vect_set_status(const c_vector v, zvect_index flag_id) {
|
||||||
zvect_retval rval = p_usr_status(flag_id);
|
zvect_retval rval = p_usr_status(flag_id);
|
||||||
|
|
||||||
if (!rval) {
|
if (!rval) {
|
||||||
|
@ -633,7 +633,7 @@ bool vect_set_status(const vector v, zvect_index flag_id) {
|
||||||
return (bool)rval;
|
return (bool)rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool vect_clear_status(const vector v, zvect_index flag_id) {
|
bool vect_clear_status(const c_vector v, zvect_index flag_id) {
|
||||||
zvect_retval rval = p_usr_status(flag_id);
|
zvect_retval rval = p_usr_status(flag_id);
|
||||||
|
|
||||||
if (!rval) {
|
if (!rval) {
|
||||||
|
@ -643,7 +643,7 @@ bool vect_clear_status(const vector v, zvect_index flag_id) {
|
||||||
return (bool)rval;
|
return (bool)rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool vect_toggle_status(const vector v, zvect_index flag_id) {
|
bool vect_toggle_status(const c_vector v, zvect_index flag_id) {
|
||||||
zvect_retval rval = p_usr_status(flag_id);
|
zvect_retval rval = p_usr_status(flag_id);
|
||||||
|
|
||||||
if (!rval) {
|
if (!rval) {
|
||||||
|
@ -653,7 +653,7 @@ bool vect_toggle_status(const vector v, zvect_index flag_id) {
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void p_free_items(vector const v, zvect_index first, zvect_index offset) {
|
static void p_free_items(c_vector const v, zvect_index first, zvect_index offset) {
|
||||||
if (p_vect_size(v) == 0) {
|
if (p_vect_size(v) == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -685,7 +685,7 @@ static void p_free_items(vector const v, zvect_index first, zvect_index offset)
|
||||||
/*
|
/*
|
||||||
* Set vector capacity to a specific new_capacity value
|
* Set vector capacity to a specific new_capacity value
|
||||||
*/
|
*/
|
||||||
static zvect_retval p_vect_set_capacity(vector const v, const zvect_index direction, const zvect_index new_capacity_) {
|
static zvect_retval p_vect_set_capacity(c_vector const v, const zvect_index direction, const zvect_index new_capacity_) {
|
||||||
zvect_index new_capacity = new_capacity_;
|
zvect_index new_capacity = new_capacity_;
|
||||||
|
|
||||||
if (new_capacity <= v->init_capacity) {
|
if (new_capacity <= v->init_capacity) {
|
||||||
|
@ -739,7 +739,7 @@ static zvect_retval p_vect_set_capacity(vector const v, const zvect_index direct
|
||||||
/*
|
/*
|
||||||
* This function increase the CAPACITY of a vector.
|
* This function increase the CAPACITY of a vector.
|
||||||
*/
|
*/
|
||||||
static zvect_retval p_vect_increase_capacity(vector const v, const zvect_index direction) {
|
static zvect_retval p_vect_increase_capacity(c_vector const v, const zvect_index direction) {
|
||||||
zvect_index new_capacity;
|
zvect_index new_capacity;
|
||||||
|
|
||||||
if (!direction) {
|
if (!direction) {
|
||||||
|
@ -772,7 +772,7 @@ static zvect_retval p_vect_increase_capacity(vector const v, const zvect_index d
|
||||||
/*
|
/*
|
||||||
* This function decrease the CAPACITY of a vector.
|
* This function decrease the CAPACITY of a vector.
|
||||||
*/
|
*/
|
||||||
static zvect_retval p_vect_decrease_capacity(vector const v, const zvect_index direction) {
|
static zvect_retval p_vect_decrease_capacity(c_vector const v, const zvect_index direction) {
|
||||||
// Check if new capacity is smaller than initial capacity
|
// Check if new capacity is smaller than initial capacity
|
||||||
if (p_vect_capacity(v) <= v->init_capacity) {
|
if (p_vect_capacity(v) <= v->init_capacity) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -847,7 +847,7 @@ static zvect_retval p_vect_decrease_capacity(vector const v, const zvect_index d
|
||||||
* not its size. To reduce the size of a vector we
|
* not its size. To reduce the size of a vector we
|
||||||
* need to remove items from it.
|
* need to remove items from it.
|
||||||
*/
|
*/
|
||||||
static zvect_retval p_vect_shrink(vector const v) {
|
static zvect_retval p_vect_shrink(c_vector const v) {
|
||||||
if (v->init_capacity < 2) {
|
if (v->init_capacity < 2) {
|
||||||
v->init_capacity = 2;
|
v->init_capacity = 2;
|
||||||
}
|
}
|
||||||
|
@ -898,7 +898,7 @@ static zvect_retval p_vect_shrink(vector const v) {
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
// Creation and destruction primitives:
|
// Creation and destruction primitives:
|
||||||
|
|
||||||
zvect_retval p_vect_clear(vector const v) {
|
zvect_retval p_vect_clear(c_vector const v) {
|
||||||
// Clear the vector:
|
// Clear the vector:
|
||||||
if (!vect_is_empty(v)) {
|
if (!vect_is_empty(v)) {
|
||||||
p_free_items(v, 0, (p_vect_size(v) - 1));
|
p_free_items(v, 0, (p_vect_size(v) - 1));
|
||||||
|
@ -913,7 +913,7 @@ zvect_retval p_vect_clear(vector const v) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static zvect_retval p_vect_destroy(vector v, uint32_t flags) {
|
static zvect_retval p_vect_destroy(c_vector v, uint32_t flags) {
|
||||||
// p_destroy is an exception to the rule of handling
|
// p_destroy is an exception to the rule of handling
|
||||||
// locking from the public methods. This because
|
// locking from the public methods. This because
|
||||||
// p_destroy has to destroy the vector mutex too and
|
// p_destroy has to destroy the vector mutex too and
|
||||||
|
@ -971,7 +971,7 @@ static zvect_retval p_vect_destroy(vector v, uint32_t flags) {
|
||||||
// Vector data storage primitives:
|
// Vector data storage primitives:
|
||||||
|
|
||||||
// inline implementation for all put:
|
// inline implementation for all put:
|
||||||
static inline zvect_retval p_vect_put_at(vector const v, const void *value, const zvect_index i) {
|
static inline zvect_retval p_vect_put_at(c_vector const v, const void *value, const zvect_index i) {
|
||||||
// Check if the index passed is out of bounds:
|
// Check if the index passed is out of bounds:
|
||||||
zvect_index idx = i;
|
zvect_index idx = i;
|
||||||
if (!(v->flags & ZV_CIRCULAR)) {
|
if (!(v->flags & ZV_CIRCULAR)) {
|
||||||
|
@ -1001,7 +1001,7 @@ static inline zvect_retval p_vect_put_at(vector const v, const void *value, cons
|
||||||
}
|
}
|
||||||
|
|
||||||
// inline implementation for all add(s):
|
// inline implementation for all add(s):
|
||||||
static inline zvect_retval p_vect_add_at(vector const v, const void *value, const zvect_index i) {
|
static inline zvect_retval p_vect_add_at(c_vector const v, const void *value, const zvect_index i) {
|
||||||
zvect_index idx = i;
|
zvect_index idx = i;
|
||||||
|
|
||||||
// Get vector size:
|
// Get vector size:
|
||||||
|
@ -1120,7 +1120,7 @@ static inline zvect_retval p_vect_add_at(vector const v, const void *value, cons
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the inline implementation for all the remove and pop
|
// This is the inline implementation for all the remove and pop
|
||||||
static inline zvect_retval p_vect_remove_at(vector const v, const zvect_index i, void **item) {
|
static inline zvect_retval p_vect_remove_at(c_vector const v, const zvect_index i, void **item) {
|
||||||
zvect_index idx = i;
|
zvect_index idx = i;
|
||||||
|
|
||||||
// Get the vector size:
|
// Get the vector size:
|
||||||
|
@ -1235,7 +1235,7 @@ static inline zvect_retval p_vect_remove_at(vector const v, const zvect_index i,
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the inline implementation for all the "delete" methods
|
// This is the inline implementation for all the "delete" methods
|
||||||
static inline zvect_retval p_vect_delete_at(vector const v,
|
static inline zvect_retval p_vect_delete_at(c_vector const v,
|
||||||
const zvect_index start,
|
const zvect_index start,
|
||||||
const zvect_index offset,
|
const zvect_index offset,
|
||||||
uint32_t flags) {
|
uint32_t flags) {
|
||||||
|
@ -1341,7 +1341,7 @@ static inline zvect_retval p_vect_delete_at(vector const v,
|
||||||
* Public method to request ZVector to
|
* Public method to request ZVector to
|
||||||
* shrink a vector.
|
* shrink a vector.
|
||||||
*/
|
*/
|
||||||
void vect_shrink(vector const v) {
|
void vect_shrink(c_vector const v) {
|
||||||
#if (ZVECT_THREAD_SAFE == 1)
|
#if (ZVECT_THREAD_SAFE == 1)
|
||||||
zvect_retval lock_owner = get_mutex_lock(v, 1);
|
zvect_retval lock_owner = get_mutex_lock(v, 1);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1363,23 +1363,23 @@ void vect_shrink(vector const v) {
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
// Vector Structural Information report:
|
// Vector Structural Information report:
|
||||||
|
|
||||||
bool vect_is_empty(vector const v) {
|
bool vect_is_empty(c_vector const v) {
|
||||||
return !p_vect_check(v) ? (p_vect_size(v) == 0) : (bool)ZVERR_VECTUNDEF;
|
return !p_vect_check(v) ? (p_vect_size(v) == 0) : (bool)ZVERR_VECTUNDEF;
|
||||||
}
|
}
|
||||||
|
|
||||||
zvect_index vect_size(vector const v) {
|
zvect_index vect_size(c_vector const v) {
|
||||||
return !p_vect_check(v) ? p_vect_size(v) : 0;
|
return !p_vect_check(v) ? p_vect_size(v) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
zvect_index vect_max_size(vector const v) {
|
zvect_index vect_max_size(c_vector const v) {
|
||||||
return !p_vect_check(v) ? zvect_index_max : 0;
|
return !p_vect_check(v) ? zvect_index_max : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *vect_begin(vector const v) {
|
void *vect_begin(c_vector const v) {
|
||||||
return !p_vect_check(v) ? v->data[v->begin] : NULL;
|
return !p_vect_check(v) ? v->data[v->begin] : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *vect_end(vector const v) {
|
void *vect_end(c_vector const v) {
|
||||||
return !p_vect_check(v) ? v->data[v->end] : NULL;
|
return !p_vect_check(v) ? v->data[v->end] : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1388,7 +1388,7 @@ void *vect_end(vector const v) {
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
// Vector Creation and Destruction:
|
// Vector Creation and Destruction:
|
||||||
|
|
||||||
vector vect_create(const zvect_index init_capacity, const size_t item_size, const uint32_t properties) {
|
c_vector vect_create(const zvect_index init_capacity, const size_t item_size, const uint32_t properties) {
|
||||||
// If ZVector has not been initialised yet, then initialise it
|
// If ZVector has not been initialised yet, then initialise it
|
||||||
// when creating the first vector:
|
// when creating the first vector:
|
||||||
if (p_init_state == 0) {
|
if (p_init_state == 0) {
|
||||||
|
@ -1396,7 +1396,7 @@ vector vect_create(const zvect_index init_capacity, const size_t item_size, cons
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the vector first:
|
// Create the vector first:
|
||||||
vector v = (vector)malloc(sizeof(struct p_vector));
|
c_vector v = (c_vector)malloc(sizeof(struct p_vector));
|
||||||
if (v == NULL) {
|
if (v == NULL) {
|
||||||
p_throw_error(ZVERR_OUTOFMEM, NULL);
|
p_throw_error(ZVERR_OUTOFMEM, NULL);
|
||||||
}
|
}
|
||||||
|
@ -1457,7 +1457,7 @@ vector vect_create(const zvect_index init_capacity, const size_t item_size, cons
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vect_destroy(vector v) {
|
void vect_destroy(c_vector v) {
|
||||||
// Call p_vect_destroy with flags set to 1
|
// Call p_vect_destroy with flags set to 1
|
||||||
// to destroy data according to the vector
|
// to destroy data according to the vector
|
||||||
// properties:
|
// properties:
|
||||||
|
@ -1488,31 +1488,31 @@ void vect_lock_disable(void) {
|
||||||
locking_disabled = true;
|
locking_disabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline zvect_retval p_vect_lock(vector const v) {
|
static inline zvect_retval p_vect_lock(c_vector const v) {
|
||||||
return (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 3);
|
return (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_lock(v, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
zvect_retval vect_lock(vector const v) {
|
zvect_retval vect_lock(c_vector const v) {
|
||||||
return p_vect_lock(v);
|
return p_vect_lock(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline zvect_retval p_vect_unlock(vector const v) {
|
static inline zvect_retval p_vect_unlock(c_vector const v) {
|
||||||
return (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_unlock(v, 3);
|
return (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : get_mutex_unlock(v, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
zvect_retval vect_unlock(vector const v) {
|
zvect_retval vect_unlock(c_vector const v) {
|
||||||
return p_vect_unlock(v);
|
return p_vect_unlock(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline zvect_retval p_vect_trylock(vector const v) {
|
static inline zvect_retval p_vect_trylock(c_vector const v) {
|
||||||
return (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : check_mutex_trylock(v, 3);
|
return (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 0 : check_mutex_trylock(v, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
zvect_retval vect_trylock(vector const v) {
|
zvect_retval vect_trylock(c_vector const v) {
|
||||||
return p_vect_trylock(v);
|
return p_vect_trylock(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
zvect_retval vect_sem_wait(const vector v) {
|
zvect_retval vect_sem_wait(const c_vector v) {
|
||||||
#if !defined(macOS)
|
#if !defined(macOS)
|
||||||
return sem_wait(&(v->semaphore));
|
return sem_wait(&(v->semaphore));
|
||||||
#else
|
#else
|
||||||
|
@ -1520,7 +1520,7 @@ zvect_retval vect_sem_wait(const vector v) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
zvect_retval vect_sem_post(const vector v) {
|
zvect_retval vect_sem_post(const c_vector v) {
|
||||||
#if !defined(macOS)
|
#if !defined(macOS)
|
||||||
return sem_post(&(v->semaphore));
|
return sem_post(&(v->semaphore));
|
||||||
#else
|
#else
|
||||||
|
@ -1538,19 +1538,19 @@ inline zvect_retval vect_wait_for_signal(const vector v) {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static inline zvect_retval p_vect_lock_after_signal(const vector v) {
|
static inline zvect_retval p_vect_lock_after_signal(const c_vector v) {
|
||||||
return (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 1 : lock_after_signal(v, 3);
|
return (locking_disabled || (v->flags & ZV_NOLOCKING)) ? 1 : lock_after_signal(v, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
zvect_retval vect_lock_after_signal(const vector v) {
|
zvect_retval vect_lock_after_signal(const c_vector v) {
|
||||||
return p_vect_lock_after_signal(v);
|
return p_vect_lock_after_signal(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
zvect_retval vect_send_signal(const vector v) {
|
zvect_retval vect_send_signal(const c_vector v) {
|
||||||
return send_signal(v, 3);
|
return send_signal(v, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
zvect_retval vect_broadcast_signal(const vector v) {
|
zvect_retval vect_broadcast_signal(const c_vector v) {
|
||||||
return broadcast_signal(v, 3);
|
return broadcast_signal(v, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1561,7 +1561,7 @@ zvect_retval vect_broadcast_signal(const vector v) {
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
// Vector Data Storage functions:
|
// Vector Data Storage functions:
|
||||||
|
|
||||||
void vect_clear(vector const v) {
|
void vect_clear(c_vector const v) {
|
||||||
// check if the vector exists:
|
// check if the vector exists:
|
||||||
zvect_retval rval = p_vect_check(v);
|
zvect_retval rval = p_vect_check(v);
|
||||||
if (rval) {
|
if (rval) {
|
||||||
|
@ -1587,7 +1587,7 @@ JOB_DONE:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void vect_set_wipefunct(const vector v, void (*f1)(const void *, size_t)) {
|
void vect_set_wipefunct(const c_vector v, void (*f1)(const void *, size_t)) {
|
||||||
v->SfWpFunc = (void *)malloc(sizeof(void *));
|
v->SfWpFunc = (void *)malloc(sizeof(void *));
|
||||||
if (v->SfWpFunc == NULL) {
|
if (v->SfWpFunc == NULL) {
|
||||||
p_throw_error(ZVERR_OUTOFMEM, NULL);
|
p_throw_error(ZVERR_OUTOFMEM, NULL);
|
||||||
|
@ -1600,7 +1600,7 @@ void vect_set_wipefunct(const vector v, void (*f1)(const void *, size_t)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add an item at the END (top) of the vector
|
// Add an item at the END (top) of the vector
|
||||||
inline void vect_push(const vector v, const void *value) {
|
inline void vect_push(const c_vector v, const void *value) {
|
||||||
zvect_retval rval = p_vect_check(v);
|
zvect_retval rval = p_vect_check(v);
|
||||||
if (rval) {
|
if (rval) {
|
||||||
goto JOB_DONE;
|
goto JOB_DONE;
|
||||||
|
@ -1646,12 +1646,12 @@ JOB_DONE:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add an item at the END of the vector
|
// Add an item at the END of the vector
|
||||||
void vect_add(const vector v, const void *value) {
|
void vect_add(const c_vector v, const void *value) {
|
||||||
vect_push(v, value);
|
vect_push(v, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add an item at position "i" of the vector
|
// Add an item at position "i" of the vector
|
||||||
void vect_add_at(const vector v, const void *value, const zvect_index i) {
|
void vect_add_at(const c_vector v, const void *value, const zvect_index i) {
|
||||||
zvect_retval rval = p_vect_check(v);
|
zvect_retval rval = p_vect_check(v);
|
||||||
if (rval) {
|
if (rval) {
|
||||||
goto JOB_DONE;
|
goto JOB_DONE;
|
||||||
|
@ -1701,7 +1701,7 @@ JOB_DONE:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add an item at the FRONT of the vector
|
// Add an item at the FRONT of the vector
|
||||||
void vect_add_front(vector const v, const void *value) {
|
void vect_add_front(c_vector const v, const void *value) {
|
||||||
zvect_retval rval = p_vect_check(v);
|
zvect_retval rval = p_vect_check(v);
|
||||||
if (rval) {
|
if (rval) {
|
||||||
goto JOB_DONE;
|
goto JOB_DONE;
|
||||||
|
@ -1739,7 +1739,7 @@ JOB_DONE:
|
||||||
}
|
}
|
||||||
|
|
||||||
// inline implementation for all get(s):
|
// inline implementation for all get(s):
|
||||||
static inline void *p_vect_get_at(vector const v, const zvect_index i) {
|
static inline void *p_vect_get_at(c_vector const v, const zvect_index i) {
|
||||||
// Check if passed index is out of bounds:
|
// Check if passed index is out of bounds:
|
||||||
if (i >= p_vect_size(v)) {
|
if (i >= p_vect_size(v)) {
|
||||||
p_throw_error(ZVERR_IDXOUTOFBOUND, NULL);
|
p_throw_error(ZVERR_IDXOUTOFBOUND, NULL);
|
||||||
|
@ -1749,7 +1749,7 @@ static inline void *p_vect_get_at(vector const v, const zvect_index i) {
|
||||||
return v->data[v->begin + i];
|
return v->data[v->begin + i];
|
||||||
}
|
}
|
||||||
|
|
||||||
void *vect_get(vector const v) {
|
void *vect_get(c_vector const v) {
|
||||||
// check if the vector exists:
|
// check if the vector exists:
|
||||||
zvect_retval rval = p_vect_check(v);
|
zvect_retval rval = p_vect_check(v);
|
||||||
if (!rval) {
|
if (!rval) {
|
||||||
|
@ -1761,7 +1761,7 @@ void *vect_get(vector const v) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *vect_get_at(vector const v, const zvect_index i) {
|
void *vect_get_at(c_vector const v, const zvect_index i) {
|
||||||
// check if the vector exists:
|
// check if the vector exists:
|
||||||
zvect_retval rval = p_vect_check(v);
|
zvect_retval rval = p_vect_check(v);
|
||||||
if (!rval) {
|
if (!rval) {
|
||||||
|
@ -1773,7 +1773,7 @@ void *vect_get_at(vector const v, const zvect_index i) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *vect_get_front(vector const v) {
|
void *vect_get_front(c_vector const v) {
|
||||||
// check if the vector exists:
|
// check if the vector exists:
|
||||||
zvect_retval rval = p_vect_check(v);
|
zvect_retval rval = p_vect_check(v);
|
||||||
if (!rval) {
|
if (!rval) {
|
||||||
|
@ -1785,7 +1785,7 @@ void *vect_get_front(vector const v) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vect_put(vector const v, const void *value) {
|
void vect_put(c_vector const v, const void *value) {
|
||||||
zvect_retval rval = p_vect_check(v);
|
zvect_retval rval = p_vect_check(v);
|
||||||
if (rval) {
|
if (rval) {
|
||||||
goto JOB_DONE;
|
goto JOB_DONE;
|
||||||
|
@ -1809,7 +1809,7 @@ JOB_DONE:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void vect_put_at(vector const v, const void *value, const zvect_index i) {
|
void vect_put_at(c_vector const v, const void *value, const zvect_index i) {
|
||||||
zvect_retval rval = p_vect_check(v);
|
zvect_retval rval = p_vect_check(v);
|
||||||
if (rval) {
|
if (rval) {
|
||||||
goto JOB_DONE;
|
goto JOB_DONE;
|
||||||
|
@ -1833,7 +1833,7 @@ JOB_DONE:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void vect_put_front(vector const v, const void *value) {
|
void vect_put_front(c_vector const v, const void *value) {
|
||||||
zvect_retval rval = p_vect_check(v);
|
zvect_retval rval = p_vect_check(v);
|
||||||
if (rval) {
|
if (rval) {
|
||||||
goto JOB_DONE;
|
goto JOB_DONE;
|
||||||
|
@ -1857,7 +1857,7 @@ JOB_DONE:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void *vect_pop(vector const v) {
|
inline void *vect_pop(c_vector const v) {
|
||||||
void *item = NULL;
|
void *item = NULL;
|
||||||
zvect_retval rval = p_vect_check(v);
|
zvect_retval rval = p_vect_check(v);
|
||||||
if (rval) {
|
if (rval) {
|
||||||
|
@ -1887,7 +1887,7 @@ JOB_DONE:
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *vect_remove(vector const v) {
|
void *vect_remove(c_vector const v) {
|
||||||
void *item = NULL;
|
void *item = NULL;
|
||||||
zvect_retval rval = p_vect_check(v);
|
zvect_retval rval = p_vect_check(v);
|
||||||
if (rval) {
|
if (rval) {
|
||||||
|
@ -1917,7 +1917,7 @@ JOB_DONE:
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *vect_remove_at(vector const v, const zvect_index i) {
|
void *vect_remove_at(c_vector const v, const zvect_index i) {
|
||||||
void *item = NULL;
|
void *item = NULL;
|
||||||
zvect_retval rval = p_vect_check(v);
|
zvect_retval rval = p_vect_check(v);
|
||||||
if (rval) {
|
if (rval) {
|
||||||
|
@ -1946,7 +1946,7 @@ JOB_DONE:
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *vect_remove_front(vector const v) {
|
void *vect_remove_front(c_vector const v) {
|
||||||
void *item = NULL;
|
void *item = NULL;
|
||||||
zvect_retval rval = p_vect_check(v);
|
zvect_retval rval = p_vect_check(v);
|
||||||
if (rval) {
|
if (rval) {
|
||||||
|
@ -1976,7 +1976,7 @@ JOB_DONE:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete an item at the END of the vector
|
// Delete an item at the END of the vector
|
||||||
void vect_delete(vector const v) {
|
void vect_delete(c_vector const v) {
|
||||||
zvect_retval rval = p_vect_check(v);
|
zvect_retval rval = p_vect_check(v);
|
||||||
if (rval) {
|
if (rval) {
|
||||||
goto JOB_DONE;
|
goto JOB_DONE;
|
||||||
|
@ -2001,7 +2001,7 @@ JOB_DONE:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete an item at position "i" on the vector
|
// Delete an item at position "i" on the vector
|
||||||
void vect_delete_at(const vector v, const zvect_index i) {
|
void vect_delete_at(const c_vector v, const zvect_index i) {
|
||||||
zvect_retval rval = p_vect_check(v);
|
zvect_retval rval = p_vect_check(v);
|
||||||
if (rval) {
|
if (rval) {
|
||||||
goto JOB_DONE;
|
goto JOB_DONE;
|
||||||
|
@ -2026,7 +2026,7 @@ JOB_DONE:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete a range of items from "first_element" to "last_element" on the vector v
|
// Delete a range of items from "first_element" to "last_element" on the vector v
|
||||||
void vect_delete_range(vector const v, const zvect_index first_element, const zvect_index last_element) {
|
void vect_delete_range(c_vector const v, const zvect_index first_element, const zvect_index last_element) {
|
||||||
zvect_retval rval = p_vect_check(v);
|
zvect_retval rval = p_vect_check(v);
|
||||||
if (rval) {
|
if (rval) {
|
||||||
goto JOB_DONE;
|
goto JOB_DONE;
|
||||||
|
@ -2052,7 +2052,7 @@ JOB_DONE:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete an item at the BEGINNING of a vector v
|
// Delete an item at the BEGINNING of a vector v
|
||||||
void vect_delete_front(vector const v) {
|
void vect_delete_front(c_vector const v) {
|
||||||
zvect_retval rval = p_vect_check(v);
|
zvect_retval rval = p_vect_check(v);
|
||||||
if (rval) {
|
if (rval) {
|
||||||
goto JOB_DONE;
|
goto JOB_DONE;
|
||||||
|
@ -2082,7 +2082,7 @@ JOB_DONE:
|
||||||
// Vector Data Manipulation functions
|
// Vector Data Manipulation functions
|
||||||
#ifdef ZVECT_DMF_EXTENSIONS
|
#ifdef ZVECT_DMF_EXTENSIONS
|
||||||
|
|
||||||
void vect_swap(vector const v, const zvect_index i1, const zvect_index i2) {
|
void vect_swap(c_vector const v, const zvect_index i1, const zvect_index i2) {
|
||||||
// Check parameters:
|
// Check parameters:
|
||||||
if (i1 == i2) {
|
if (i1 == i2) {
|
||||||
return;
|
return;
|
||||||
|
@ -2123,7 +2123,7 @@ JOB_DONE:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void vect_swap_range(vector const v, const zvect_index s1, const zvect_index e1, const zvect_index s2) {
|
void vect_swap_range(c_vector const v, const zvect_index s1, const zvect_index e1, const zvect_index s2) {
|
||||||
// Check parameters:
|
// Check parameters:
|
||||||
if (s1 == s2) {
|
if (s1 == s2) {
|
||||||
return;
|
return;
|
||||||
|
@ -2172,7 +2172,7 @@ JOB_DONE:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void vect_rotate_left(vector const v, const zvect_index i) {
|
void vect_rotate_left(c_vector const v, const zvect_index i) {
|
||||||
|
|
||||||
// check if the vector exists:
|
// check if the vector exists:
|
||||||
zvect_retval rval = p_vect_check(v);
|
zvect_retval rval = p_vect_check(v);
|
||||||
|
@ -2228,7 +2228,7 @@ JOB_DONE:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void vect_rotate_right(vector const v, const zvect_index i) {
|
void vect_rotate_right(c_vector const v, const zvect_index i) {
|
||||||
// check if the vector exists:
|
// check if the vector exists:
|
||||||
zvect_retval rval = p_vect_check(v);
|
zvect_retval rval = p_vect_check(v);
|
||||||
if (rval) {
|
if (rval) {
|
||||||
|
@ -2321,7 +2321,7 @@ static void p_vect_qsort(vector v, zvect_index low, zvect_index high, int (*comp
|
||||||
// it fundamentally uses the 3 ways partitioning adapted and improved
|
// it fundamentally uses the 3 ways partitioning adapted and improved
|
||||||
// to deal with arrays of pointers together with having a custom
|
// to deal with arrays of pointers together with having a custom
|
||||||
// compare function:
|
// compare function:
|
||||||
static void p_vect_qsort(const vector v,
|
static void p_vect_qsort(const c_vector v,
|
||||||
zvect_index l,
|
zvect_index l,
|
||||||
zvect_index r,
|
zvect_index r,
|
||||||
int (*compare_func)(const void *, const void *)) {
|
int (*compare_func)(const void *, const void *)) {
|
||||||
|
@ -2384,7 +2384,7 @@ static void p_vect_qsort(const vector v,
|
||||||
}
|
}
|
||||||
#endif // ! TRADITIONAL_QSORT
|
#endif // ! TRADITIONAL_QSORT
|
||||||
|
|
||||||
void vect_qsort(const vector v, int (*compare_func)(const void *, const void *)) {
|
void vect_qsort(const c_vector v, int (*compare_func)(const void *, const void *)) {
|
||||||
// Check parameters:
|
// Check parameters:
|
||||||
if (compare_func == NULL) {
|
if (compare_func == NULL) {
|
||||||
return;
|
return;
|
||||||
|
@ -2459,7 +2459,7 @@ static bool p_standard_binary_search(vector v,
|
||||||
// original design, most notably the use of custom compare
|
// original design, most notably the use of custom compare
|
||||||
// function that makes it suitable also to search through strings
|
// function that makes it suitable also to search through strings
|
||||||
// and other types of vectors.
|
// and other types of vectors.
|
||||||
static bool p_adaptive_binary_search(vector const v,
|
static bool p_adaptive_binary_search(c_vector const v,
|
||||||
const void *key,
|
const void *key,
|
||||||
zvect_index *item_index,
|
zvect_index *item_index,
|
||||||
int (*f1)(const void *, const void *)) {
|
int (*f1)(const void *, const void *)) {
|
||||||
|
@ -2538,7 +2538,7 @@ MONOBOUND:
|
||||||
}
|
}
|
||||||
#endif // ! TRADITIONAL_BINARY_SEARCH
|
#endif // ! TRADITIONAL_BINARY_SEARCH
|
||||||
|
|
||||||
bool vect_bsearch(vector const v, const void *key, int (*f1)(const void *, const void *), zvect_index *item_index) {
|
bool vect_bsearch(c_vector const v, const void *key, int (*f1)(const void *, const void *), zvect_index *item_index) {
|
||||||
// Check parameters:
|
// Check parameters:
|
||||||
if ((key == NULL) || (f1 == NULL) || (p_vect_size(v) == 0)) {
|
if ((key == NULL) || (f1 == NULL) || (p_vect_size(v) == 0)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -2586,7 +2586,7 @@ JOB_DONE:
|
||||||
* functions, the vect_add_ordered is an exception because it
|
* functions, the vect_add_ordered is an exception because it
|
||||||
* requires vect_bserach and vect_qsort to be available.
|
* requires vect_bserach and vect_qsort to be available.
|
||||||
*/
|
*/
|
||||||
void vect_add_ordered(vector const v, const void *value, int (*f1)(const void *, const void *)) {
|
void vect_add_ordered(c_vector const v, const void *value, int (*f1)(const void *, const void *)) {
|
||||||
// Check parameters:
|
// Check parameters:
|
||||||
if (value == NULL) {
|
if (value == NULL) {
|
||||||
return;
|
return;
|
||||||
|
@ -2656,7 +2656,7 @@ JOB_DONE:
|
||||||
#ifdef ZVECT_SFMD_EXTENSIONS
|
#ifdef ZVECT_SFMD_EXTENSIONS
|
||||||
// Single Function Call Multiple Data operations extensions:
|
// Single Function Call Multiple Data operations extensions:
|
||||||
|
|
||||||
void vect_apply(vector const v, void (*f)(void *)) {
|
void vect_apply(c_vector const v, void (*f)(void *)) {
|
||||||
// Check Parameters:
|
// Check Parameters:
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
return;
|
return;
|
||||||
|
@ -2689,7 +2689,7 @@ JOB_DONE:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void vect_apply_range(vector const v, void (*f)(void *), const zvect_index x, const zvect_index y) {
|
void vect_apply_range(c_vector const v, void (*f)(void *), const zvect_index x, const zvect_index y) {
|
||||||
// Check parameters:
|
// Check parameters:
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
return;
|
return;
|
||||||
|
@ -2738,7 +2738,7 @@ JOB_DONE:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void vect_apply_if(vector const v1, vector const v2, void (*f1)(void *), bool (*f2)(void *, void *)) {
|
void vect_apply_if(c_vector const v1, c_vector const v2, void (*f1)(void *), bool (*f2)(void *, void *)) {
|
||||||
// Check parameters:
|
// Check parameters:
|
||||||
if (f1 == NULL || f2 == NULL) {
|
if (f1 == NULL || f2 == NULL) {
|
||||||
return;
|
return;
|
||||||
|
@ -2780,7 +2780,7 @@ JOB_DONE:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void vect_copy(vector const v1, vector const v2, const zvect_index s2, const zvect_index e2) {
|
void vect_copy(c_vector const v1, c_vector const v2, const zvect_index s2, const zvect_index e2) {
|
||||||
// check if the vectors v1 and v2 exist:
|
// check if the vectors v1 and v2 exist:
|
||||||
zvect_retval rval = p_vect_check(v1) | p_vect_check(v2);
|
zvect_retval rval = p_vect_check(v1) | p_vect_check(v2);
|
||||||
if (rval) {
|
if (rval) {
|
||||||
|
@ -2844,7 +2844,8 @@ JOB_DONE:
|
||||||
* position s1).
|
* position s1).
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void vect_insert(vector const v1, vector const v2, const zvect_index s2, const zvect_index e2, const zvect_index s1) {
|
void vect_insert(c_vector const v1,
|
||||||
|
c_vector const v2, const zvect_index s2, const zvect_index e2, const zvect_index s1) {
|
||||||
// check if the vectors v1 and v2 exist:
|
// check if the vectors v1 and v2 exist:
|
||||||
zvect_retval rval = p_vect_check(v1) | p_vect_check(v2);
|
zvect_retval rval = p_vect_check(v1) | p_vect_check(v2);
|
||||||
if (rval) {
|
if (rval) {
|
||||||
|
@ -2943,7 +2944,7 @@ JOB_DONE:
|
||||||
* the end of it).
|
* the end of it).
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static inline zvect_retval p_vect_move(vector const v1, vector v2, const zvect_index s2, const zvect_index e2) {
|
static inline zvect_retval p_vect_move(c_vector const v1, c_vector v2, const zvect_index s2, const zvect_index e2) {
|
||||||
zvect_retval rval = 0;
|
zvect_retval rval = 0;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -3075,7 +3076,7 @@ DONE_PROCESSING:
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
// vect_move moves a portion of a vector (v2) into another (v1):
|
// vect_move moves a portion of a vector (v2) into another (v1):
|
||||||
void vect_move(vector const v1, vector v2, const zvect_index s2, const zvect_index e2) {
|
void vect_move(c_vector const v1, c_vector v2, const zvect_index s2, const zvect_index e2) {
|
||||||
// check if the vectors v1 and v2 exist:
|
// check if the vectors v1 and v2 exist:
|
||||||
zvect_retval rval = p_vect_check(v1) | p_vect_check(v2);
|
zvect_retval rval = p_vect_check(v1) | p_vect_check(v2);
|
||||||
if (rval) {
|
if (rval) {
|
||||||
|
@ -3128,8 +3129,8 @@ JOB_DONE:
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
// vect_move_if moves a portion of a vector (v2) into another (v1) if f2 is true:
|
// vect_move_if moves a portion of a vector (v2) into another (v1) if f2 is true:
|
||||||
zvect_retval vect_move_if(vector const v1,
|
zvect_retval vect_move_if(c_vector const v1,
|
||||||
vector v2,
|
c_vector v2,
|
||||||
const zvect_index s2,
|
const zvect_index s2,
|
||||||
const zvect_index e2,
|
const zvect_index e2,
|
||||||
zvect_retval (*f2)(void *, void *)) {
|
zvect_retval (*f2)(void *, void *)) {
|
||||||
|
@ -3189,8 +3190,8 @@ JOB_DONE:
|
||||||
/////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////
|
||||||
// vect_move_on_signal
|
// vect_move_on_signal
|
||||||
|
|
||||||
zvect_retval vect_move_on_signal(vector const v1,
|
zvect_retval vect_move_on_signal(c_vector const v1,
|
||||||
vector v2,
|
c_vector v2,
|
||||||
const zvect_index s2,
|
const zvect_index s2,
|
||||||
const zvect_index e2,
|
const zvect_index e2,
|
||||||
zvect_retval (*f2)(void *, void *)) {
|
zvect_retval (*f2)(void *, void *)) {
|
||||||
|
@ -3262,7 +3263,7 @@ JOB_DONE:
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////
|
||||||
// vect_merge merges a vector (v2) into another (v1)
|
// vect_merge merges a vector (v2) into another (v1)
|
||||||
void vect_merge(vector const v1, vector v2) {
|
void vect_merge(c_vector const v1, c_vector v2) {
|
||||||
// check if the vector v1 exists:
|
// check if the vector v1 exists:
|
||||||
zvect_retval rval = p_vect_check(v1) | p_vect_check(v2);
|
zvect_retval rval = p_vect_check(v1) | p_vect_check(v2);
|
||||||
if (rval) {
|
if (rval) {
|
||||||
|
|
|
@ -41,6 +41,7 @@ using namespace std;
|
||||||
#include "dhcpd.h"
|
#include "dhcpd.h"
|
||||||
#include "task_manager.h"
|
#include "task_manager.h"
|
||||||
#include "user_errno.h"
|
#include "user_errno.h"
|
||||||
|
#include "misc.h"
|
||||||
|
|
||||||
void on_system_exit(void *p);
|
void on_system_exit(void *p);
|
||||||
//Global Variables
|
//Global Variables
|
||||||
|
@ -3293,8 +3294,9 @@ void loadDHCP() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
opendhcp_add_mac_filter();
|
||||||
|
#if 0
|
||||||
ff = fopen(iniFile, "rt");
|
ff = fopen(iniFile, "rt");
|
||||||
|
|
||||||
if (ff) {
|
if (ff) {
|
||||||
char sectionName[512];
|
char sectionName[512];
|
||||||
|
|
||||||
|
@ -3390,7 +3392,7 @@ void loadDHCP() {
|
||||||
|
|
||||||
fclose(ff);
|
fclose(ff);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
f = fopen(leaFile, "rb");
|
f = fopen(leaFile, "rb");
|
||||||
|
|
||||||
if (f) {
|
if (f) {
|
||||||
|
@ -4384,7 +4386,7 @@ void *init(void *lparam) {
|
||||||
logDHCPMess(logBuff, 1);
|
logDHCPMess(logBuff, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
cfig.lease = 36000;
|
cfig.lease = opendhcp_set_lease_time();
|
||||||
loadDHCP();
|
loadDHCP();
|
||||||
|
|
||||||
if (cfig.dhcpLogLevel > 1) {
|
if (cfig.dhcpLogLevel > 1) {
|
||||||
|
|
|
@ -91,6 +91,7 @@ struct data7 //cache
|
||||||
{
|
{
|
||||||
char *mapname;
|
char *mapname;
|
||||||
time_t expiry;
|
time_t expiry;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
MYBYTE cType;
|
MYBYTE cType;
|
||||||
|
@ -98,6 +99,7 @@ struct data7 //cache
|
||||||
MYBYTE sockInd;
|
MYBYTE sockInd;
|
||||||
MYBYTE dnsIndex;
|
MYBYTE dnsIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
unsigned fixed : 1;
|
unsigned fixed : 1;
|
||||||
unsigned local : 1;
|
unsigned local : 1;
|
||||||
|
@ -107,20 +109,24 @@ struct data7 //cache
|
||||||
unsigned dhcpInd : 20;
|
unsigned dhcpInd : 20;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
union {
|
union {
|
||||||
char *name;
|
char *name;
|
||||||
MYBYTE *options;
|
MYBYTE *options;
|
||||||
};
|
};
|
||||||
|
|
||||||
union {
|
union {
|
||||||
int bytes;
|
int bytes;
|
||||||
MYDWORD ip;
|
MYDWORD ip;
|
||||||
SOCKADDR_IN *addr;
|
SOCKADDR_IN *addr;
|
||||||
};
|
};
|
||||||
|
|
||||||
union {
|
union {
|
||||||
MYBYTE *response;
|
MYBYTE *response;
|
||||||
char *hostname;
|
char *hostname;
|
||||||
char *query;
|
char *query;
|
||||||
};
|
};
|
||||||
|
|
||||||
MYBYTE data;
|
MYBYTE data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -312,10 +318,12 @@ struct data4 {
|
||||||
#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || \
|
#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || \
|
||||||
defined(__ia64) || defined(_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
|
defined(__ia64) || defined(_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
|
||||||
#define MY_MAX_TIME UINT_MAX
|
#define MY_MAX_TIME UINT_MAX
|
||||||
|
|
||||||
struct data8 //client
|
struct data8 //client
|
||||||
{
|
{
|
||||||
union {
|
union {
|
||||||
MYDWORD filler;
|
MYDWORD filler;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
unsigned dhcpInd : 20;
|
unsigned dhcpInd : 20;
|
||||||
unsigned bp_hlen : 8;
|
unsigned bp_hlen : 8;
|
||||||
|
@ -325,6 +333,7 @@ struct data8 //client
|
||||||
unsigned subnetFlg : 1;
|
unsigned subnetFlg : 1;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
MYDWORD ip;
|
MYDWORD ip;
|
||||||
time_t expiry;
|
time_t expiry;
|
||||||
MYBYTE bp_chaddr[16];
|
MYBYTE bp_chaddr[16];
|
||||||
|
@ -332,10 +341,12 @@ struct data8 //client
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
#define MY_MAX_TIME INT_MAX
|
#define MY_MAX_TIME INT_MAX
|
||||||
|
|
||||||
struct data8 //client
|
struct data8 //client
|
||||||
{
|
{
|
||||||
union {
|
union {
|
||||||
MYDWORD filler;
|
MYDWORD filler;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
unsigned dhcpInd : 20;
|
unsigned dhcpInd : 20;
|
||||||
unsigned bp_hlen : 8;
|
unsigned bp_hlen : 8;
|
||||||
|
@ -345,6 +356,7 @@ struct data8 //client
|
||||||
unsigned subnetFlg : 1;
|
unsigned subnetFlg : 1;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
MYDWORD ip;
|
MYDWORD ip;
|
||||||
time_t expiry;
|
time_t expiry;
|
||||||
MYDWORD filler1;
|
MYDWORD filler1;
|
||||||
|
@ -449,10 +461,12 @@ struct data20 {
|
||||||
struct data9 //dhcpRequst
|
struct data9 //dhcpRequst
|
||||||
{
|
{
|
||||||
MYDWORD lease;
|
MYDWORD lease;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
char raw[sizeof(dhcp_packet)];
|
char raw[sizeof(dhcp_packet)];
|
||||||
dhcp_packet dhcpp;
|
dhcp_packet dhcpp;
|
||||||
};
|
};
|
||||||
|
|
||||||
char hostname[256];
|
char hostname[256];
|
||||||
char chaddr[64];
|
char chaddr[64];
|
||||||
MYDWORD server;
|
MYDWORD server;
|
||||||
|
@ -491,10 +505,12 @@ struct DhcpConnType {
|
||||||
MYDWORD mask;
|
MYDWORD mask;
|
||||||
int reUseVal;
|
int reUseVal;
|
||||||
int reUseSize;
|
int reUseSize;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
int broadCastVal;
|
int broadCastVal;
|
||||||
bool pktinfoVal;
|
bool pktinfoVal;
|
||||||
};
|
};
|
||||||
|
|
||||||
union {
|
union {
|
||||||
int broadCastSize;
|
int broadCastSize;
|
||||||
unsigned int pktinfoSize;
|
unsigned int pktinfoSize;
|
||||||
|
@ -626,7 +642,9 @@ void prepareUserHtmlRespStatus(data19 *req);
|
||||||
void opendhcp_init_http_server();
|
void opendhcp_init_http_server();
|
||||||
void opendhcp_set_replication_svr();
|
void opendhcp_set_replication_svr();
|
||||||
void opendhcp_add_ip_pool_set();
|
void opendhcp_add_ip_pool_set();
|
||||||
|
void opendhcp_add_mac_filter();
|
||||||
int opendhcp_add_listener();
|
int opendhcp_add_listener();
|
||||||
|
unsigned int opendhcp_set_lease_time();
|
||||||
void sendUserList(data19 *req, const char *pRequest, dhcpMap *dhcpCache, data2 *cfig, time_t t);
|
void sendUserList(data19 *req, const char *pRequest, dhcpMap *dhcpCache, data2 *cfig, time_t t);
|
||||||
void sendAllLists(data19 *req, bool kRunning, dhcpMap *dhcpCache, data2 *cfig);
|
void sendAllLists(data19 *req, bool kRunning, dhcpMap *dhcpCache, data2 *cfig);
|
||||||
int getHwAddr(char *buff, char *mac);
|
int getHwAddr(char *buff, char *mac);
|
||||||
|
|
|
@ -24,11 +24,13 @@ using namespace std;
|
||||||
#include "proto.h"
|
#include "proto.h"
|
||||||
#include "user_errno.h"
|
#include "user_errno.h"
|
||||||
#include "uthash/uthash.h"
|
#include "uthash/uthash.h"
|
||||||
|
#include "sds/sds.h"
|
||||||
|
|
||||||
extern data2 cfig;
|
extern data2 cfig;
|
||||||
extern bool kRunning;
|
extern bool kRunning;
|
||||||
extern dhcpMap dhcpCache;
|
extern dhcpMap dhcpCache;
|
||||||
extern time_t t;
|
extern time_t t;
|
||||||
|
extern data71 lump;
|
||||||
|
|
||||||
static int dhcp_get_user_info(data19 *req, const char *pRequest) {
|
static int dhcp_get_user_info(data19 *req, const char *pRequest) {
|
||||||
char logBuff[512];
|
char logBuff[512];
|
||||||
|
@ -1044,13 +1046,17 @@ static void opendhcp_http_query_rangeset(http_request *request, hw_http_response
|
||||||
hw_http_response_send(response, req, response_complete);
|
hw_http_response_send(response, req, response_complete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int opendhcp_set_lease_time() {
|
||||||
|
return config_get_dhcp_server_lease_time();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加配置文件监听接口
|
* 添加配置文件监听接口
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int opendhcp_add_listener() {
|
int opendhcp_add_listener() {
|
||||||
int i;
|
int i;
|
||||||
vector listen_ip = config_get_dhcp_listen_on();
|
c_vector listen_ip = config_get_dhcp_listen_on();
|
||||||
|
|
||||||
for (i = 0; listen_ip && i < vect_size(listen_ip); i++) {
|
for (i = 0; listen_ip && i < vect_size(listen_ip); i++) {
|
||||||
const char *pIp = (const char *)vect_get_at(listen_ip, i);
|
const char *pIp = (const char *)vect_get_at(listen_ip, i);
|
||||||
|
@ -1084,7 +1090,7 @@ void opendhcp_init_http_server() {
|
||||||
* 增加 DHCP 主、从服务器配置
|
* 增加 DHCP 主、从服务器配置
|
||||||
*/
|
*/
|
||||||
void opendhcp_set_replication_svr() {
|
void opendhcp_set_replication_svr() {
|
||||||
vector replication = config_get_dhcp_replication_svr();
|
c_vector replication = config_get_dhcp_replication_svr();
|
||||||
|
|
||||||
if (replication && vect_size(replication) == 2) {
|
if (replication && vect_size(replication) == 2) {
|
||||||
cfig.zoneServers[0] = inet_addr((const char *)vect_get_at(replication, 0));
|
cfig.zoneServers[0] = inet_addr((const char *)vect_get_at(replication, 0));
|
||||||
|
@ -1096,15 +1102,65 @@ void opendhcp_set_replication_svr() {
|
||||||
* 添加配置文件中的 DHCP 地址池池配置到服务中
|
* 添加配置文件中的 DHCP 地址池池配置到服务中
|
||||||
*/
|
*/
|
||||||
void opendhcp_add_ip_pool_set() {
|
void opendhcp_add_ip_pool_set() {
|
||||||
vector pool = config_get_dhcp_server_range_set();
|
c_vector pool = config_get_dhcp_server_range_set();
|
||||||
|
|
||||||
for (int i = 0; (pool && i < vect_size(pool)); i++) {
|
for (int i = 0; (pool && i < vect_size(pool)); i++) {
|
||||||
auto pRange = (POBJ_DHCP_RNG)vect_get_at(pool, i);
|
auto pRange = (POBJ_DHCP_RNG)vect_get_at(pool, i);
|
||||||
|
|
||||||
if (pRange) {
|
if (pRange) {
|
||||||
if (dhcp_add_rangeset_to_options(pRange) != ERR_SUCCESS) {
|
if (dhcp_add_rangeset_to_options(pRange) != ERR_SUCCESS) {
|
||||||
dzlog_error("Add rangeset(\"%s\") failed!", pRange->rangAddr);
|
dzlog_error("Add rangeset(\"%s\") failed!\n", pRange->rangAddr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 增加MAC地址黑名单
|
||||||
|
*/
|
||||||
|
void opendhcp_add_mac_filter() {
|
||||||
|
c_vector pool = config_get_dhcp_mac_filter();
|
||||||
|
data20 optionData {};
|
||||||
|
optionData.options[0] = 0;
|
||||||
|
optionData.options[1] = DHCP_OPTION_END;
|
||||||
|
sds add = sdsempty();
|
||||||
|
sds err = sdsempty();
|
||||||
|
|
||||||
|
for (int i = 0; (pool && i < vect_size(pool)); i++) {
|
||||||
|
auto pRange = (char *)vect_get_at(pool, i);
|
||||||
|
|
||||||
|
if (pRange) {
|
||||||
|
data7 *dhcpEntry;
|
||||||
|
|
||||||
|
memset(&lump, 0, sizeof(data71));
|
||||||
|
lump.mapname = pRange;
|
||||||
|
lump.optionSize = 2;
|
||||||
|
lump.options = optionData.options;
|
||||||
|
dhcpEntry = createCache(&lump);
|
||||||
|
|
||||||
|
if (dhcpEntry) {
|
||||||
|
dhcpEntry->ip = 0;
|
||||||
|
dhcpEntry->rangeInd = -1;
|
||||||
|
dhcpEntry->fixed = 1;
|
||||||
|
dhcpEntry->expiry = 0;
|
||||||
|
dhcpCache[dhcpEntry->mapname] = dhcpEntry;
|
||||||
|
add = sdscatfmt(add, "\"%s\", ", pRange);
|
||||||
|
} else {
|
||||||
|
err = sdscatfmt(err, "\"%s\", ", pRange);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sdslen(add) > 0) {
|
||||||
|
sdsrange(add, 0, -3);
|
||||||
|
dzlog_debug("Add MAC [%s] for black list\n", add);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sdslen(err) > 0) {
|
||||||
|
sdsrange(err, 0, -2);
|
||||||
|
dzlog_debug("Add MAC [%s] for black list error\n", err);
|
||||||
|
}
|
||||||
|
|
||||||
|
sdsfree(add);
|
||||||
|
sdsfree(err);
|
||||||
|
}
|
Loading…
Reference in New Issue