Source
/*
** 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/>.
**/
/******************************************************************************
* *
* Return value: SUCCEED - char is allowed in host name *
* FAIL - otherwise *
* *
* Comments: in host name allowed characters: '0-9a-zA-Z. _-' *
* !!! Don't forget to sync the code with PHP !!! *
* *
******************************************************************************/
int zbx_is_hostname_char(unsigned char c)
{
if (0 != isalnum(c))
return SUCCEED;
if (c == '.' || c == ' ' || c == '_' || c == '-')
return SUCCEED;
return FAIL;
}
/******************************************************************************
* *
* Purpose: returns hostname and key *
* <hostname:>key *
* *
* Parameters: exp - [IN] pointer to first char of hostname *
* host:key[key params] *
* ^ *
* host - [OUT] *
* key - [OUT] *
* *
* Return value: returns SUCCEED or FAIL *
* *
******************************************************************************/
int zbx_parse_host_key(char *exp, char **host, char **key)
{
char *p, *s;
if (NULL == exp || '\0' == *exp)
return FAIL;
for (p = exp, s = exp; '\0' != *p; p++) /* check for optional hostname */
{
if (':' == *p) /* hostname:vfs.fs.size[/,total]
* --------^
*/
{