#include "trapper_proxy.h"
#include "../taskmanager/taskmanager_proxy.h"
#include "../proxyconfigwrite/proxyconfigwrite.h"
#include "zbxcomms.h"
#include "zbxcommshigh.h"
#include "zbxtasks.h"
#include "zbxmutexs.h"
#include "zbxdbwrap.h"
#include "zbxproxybuffer.h"
#include "zbxcompress.h"
#include "zbxcacheconfig.h"
#include "zbxjson.h"
#define LOCK_PROXY_HISTORY zbx_mutex_lock(proxy_lock)
#define UNLOCK_PROXY_HISTORY zbx_mutex_unlock(proxy_lock)
static zbx_mutex_t proxy_lock = ZBX_MUTEX_NULL;
int init_proxy_history_lock(unsigned char program_type, char **error)
{
if (0 != (program_type & ZBX_PROGRAM_TYPE_PROXY_PASSIVE))
return zbx_mutex_create(&proxy_lock, ZBX_MUTEX_PROXY_HISTORY, error);
return SUCCEED;
}
void free_proxy_history_lock(unsigned char program_type)
{
if (0 != (program_type & ZBX_PROGRAM_TYPE_PROXY_PASSIVE))
zbx_mutex_destroy(&proxy_lock);
}
static void active_passive_misconfig(zbx_socket_t *sock, int config_timeout)
{
char *msg = NULL;
msg = zbx_dsprintf(msg, "misconfiguration error: the proxy is running in the active mode but server at \"%s\""
" sends requests to it as to proxy in passive mode", sock->peer);
zabbix_log(LOG_LEVEL_WARNING, "%s", msg);
zbx_send_proxy_response(sock, FAIL, msg, config_timeout);
zbx_free(msg);
}
static int send_data_to_server(zbx_socket_t *sock, char **buffer, size_t buffer_size, size_t reserved,
int config_timeout, char **error)
{
if (SUCCEED != zbx_tcp_send_ext(sock, *buffer, buffer_size, reserved, ZBX_TCP_PROTOCOL | ZBX_TCP_COMPRESS,
config_timeout))
{
*error = zbx_strdup(*error, zbx_socket_strerror());
return FAIL;
}
zbx_free(*buffer);
if (SUCCEED != zbx_recv_response(sock, config_timeout, error))
return FAIL;
return SUCCEED;
}