Source
static int punycode_encode_codepoints(zbx_uint32_t *codepoints, size_t count, char *output, size_t length)
/*
** 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/>.
**/
/******************************************************************************
* *
* Purpose: after each delta is encoded or decoded, bias should be set for *
* the next delta (should be adapted) *
* *
* Parameters: delta - [IN] punycode delta (generalized variable-length *
* integer) *
* count - [IN] is the total number of code points encoded / *
* decoded so far *
* divisor - [IN] delta divisor (to avoid overflow) *
* *
* Return value: adapted bias *
* *
******************************************************************************/
static zbx_uint32_t punycode_adapt(zbx_uint32_t delta, int count, int divisor)
{
zbx_uint32_t i;
delta /= divisor;
delta += delta / count;
for (i = 0; PUNYCODE_BIAS_LIMIT < delta; i += PUNYCODE_BASE)
delta /= PUNYCODE_BASE_MAX;
return ((PUNYCODE_BASE * delta) / (delta + PUNYCODE_SKEW)) + i;
}
/******************************************************************************
* *
* Purpose: encodes punycode digit into ansi character [a-z0-9] *
* *
* Parameters: digit - [IN] digit to encode *
* *
* Return value: encoded character *
* *
******************************************************************************/
static char punycode_encode_digit(int digit)
{
if (0 <= digit && 25 >= digit)
return digit + 'a';
else if (25 < digit && PUNYCODE_BASE > digit)
return digit + 22;
THIS_SHOULD_NEVER_HAPPEN;