Source
static int punycode_encode_codepoints(zbx_uint32_t *codepoints, size_t count, char *output, size_t length)
/*
** Zabbix
** Copyright (C) 2001-2023 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
/******************************************************************************
* *
* 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)