#include "discoverer_taskprep.h"
#include "zbxexpression.h"
#include "zbx_discoverer_constants.h"
#include "discoverer_int.h"
#define ZBX_DISCOVERER_IPRANGE_LIMIT (1 << 16)
static void dcheck_copy(const zbx_dc_dcheck_t *src, zbx_dc_dcheck_t *dst)
dst->dcheckid = src->dcheckid;
dst->druleid = src->druleid;
dst->key_ = zbx_strdup(NULL, src->key_);
dst->ports = zbx_strdup(NULL, src->ports);
dst->allow_redirect = src->allow_redirect;
dst->timeout = src->timeout;
if (SVC_SNMPv1 == src->type || SVC_SNMPv2c == src->type || SVC_SNMPv3 == src->type)
dst->snmp_community = zbx_strdup(NULL, src->snmp_community);
dst->snmpv3_securityname = zbx_strdup(NULL, src->snmpv3_securityname);
dst->snmpv3_securitylevel = src->snmpv3_securitylevel;
dst->snmpv3_authpassphrase = zbx_strdup(NULL, src->snmpv3_authpassphrase);
dst->snmpv3_privpassphrase = zbx_strdup(NULL, src->snmpv3_privpassphrase);
dst->snmpv3_authprotocol = src->snmpv3_authprotocol;
dst->snmpv3_privprotocol = src->snmpv3_privprotocol;
dst->snmpv3_contextname = zbx_strdup(NULL, src->snmpv3_contextname);
static zbx_ds_dcheck_t *dcheck_clone_get(zbx_dc_dcheck_t *dcheck, zbx_vector_ds_dcheck_ptr_t *ds_dchecks_common)
zbx_ds_dcheck_t *ds_dcheck, ds_dcheck_cmp = {.dcheck.dcheckid = dcheck->dcheckid};
zbx_dc_dcheck_t *dcheck_ptr;
if (FAIL != (idx = zbx_vector_ds_dcheck_ptr_search(ds_dchecks_common, &ds_dcheck_cmp,
ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC)))
return ds_dchecks_common->values[idx];
ds_dcheck = (zbx_ds_dcheck_t*)zbx_malloc(NULL, sizeof(zbx_ds_dcheck_t));
dcheck_ptr = &ds_dcheck->dcheck;
dcheck_copy(dcheck, dcheck_ptr);
zbx_vector_portrange_create(&ds_dcheck->portranges);
dcheck_port_ranges_get(ds_dcheck->dcheck.ports, &ds_dcheck->portranges);
if (SVC_SNMPv1 == dcheck_ptr->type || SVC_SNMPv2c == dcheck_ptr->type ||
SVC_SNMPv3 == dcheck_ptr->type)
zbx_substitute_simple_macros_unmasked(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, &dcheck_ptr->snmp_community,
ZBX_MACRO_TYPE_COMMON, NULL, 0);
zbx_substitute_key_macros(&dcheck_ptr->key_, NULL, NULL, NULL, NULL,
ZBX_MACRO_TYPE_SNMP_OID, NULL, 0);
if (SVC_SNMPv3 == dcheck_ptr->type)
zbx_substitute_simple_macros_unmasked(NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL,
&dcheck_ptr->snmpv3_securityname, ZBX_MACRO_TYPE_COMMON, NULL,
zbx_substitute_simple_macros_unmasked(NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL,
&dcheck_ptr->snmpv3_authpassphrase, ZBX_MACRO_TYPE_COMMON, NULL,
zbx_substitute_simple_macros_unmasked(NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL,
&dcheck_ptr->snmpv3_privpassphrase, ZBX_MACRO_TYPE_COMMON, NULL,
zbx_substitute_simple_macros_unmasked(NULL, NULL, NULL, NULL, NULL, NULL,