Source
xxxxxxxxxx
static int async_task_process_task_telnet_cb(short event, void *data, int *fd, zbx_vector_address_t *addresses,
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
ZBX_VECTOR_IMPL(telnet_recv, unsigned char)
static const char *get_telnet_step_string(zbx_zabbix_telnet_step_t step)
{
switch (step)
{
case ZABBIX_TELNET_STEP_CONNECT_INIT:
return "init";
case ZABBIX_TELNET_STEP_CONNECT_WAIT:
return "connect";
case ZABBIX_TELNET_STEP_SEND:
return "send";
case ZABBIX_TELNET_STEP_RECV:
return "receive";
default:
return "unknown";
}
}
static char telnet_lastchar(const char *buf, int offset)
{
while (0 < offset)
{
offset--;
if (' ' != buf[offset])
return buf[offset];
}
return '\0';
}
static zbx_telnet_protocol_step_t async_telnet_recv(zbx_telnet_context_t *telnet_context, short *events)
{
ssize_t nbytes;
zbx_socket_t *s = &telnet_context->s;
zbx_recv_context_t *r = &telnet_context->recv_context;
zabbix_log(LOG_LEVEL_DEBUG, "In %s():%u", __func__, r->state);
if (ZABBIX_TELNET_PROTOCOL_SEND == r->state)
r->state = ZABBIX_TELNET_PROTOCOL_RECV_FIRST;
if (0 == r->buff.values_num)
zbx_vector_telnet_recv_reserve(&r->buff, 255);
do
{
switch (r->state)
{
case ZABBIX_TELNET_PROTOCOL_RECV_FIRST:
if (1 > (nbytes = zbx_tcp_read(s, (char *)&r->c1, 1, events)))
{
if (ZBX_PROTO_ERROR == nbytes && 0 == events)
r->state = ZABBIX_TELNET_PROTOCOL_RECV_FAIL;
break;
}
if (CMD_IAC != r->c1)
{
zbx_vector_telnet_recv_append(&r->buff, r->c1);
break;