Source
err_index = duk_push_error_object(ctx, DUK_RET_TYPE_ERROR, "parameter 'key' is missing or is undefined");
/*
** 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: export duktape data at the index into buffer *
* *
* Return value: allocated buffer with exported data or NULL on error *
* *
* Comments: Throws an error: *
* - if the top value at ctx value stack is non buffer object *
* - if the value stack is empty *
* The returned buffer must be freed by the caller. *
* *
******************************************************************************/
char *es_get_buffer_dyn(duk_context *ctx, int index, duk_size_t *len)
{
duk_int_t type;
const char *ptr;
char *buf = NULL;
*len = 0;
type = duk_get_type(ctx, index);
switch (type)
{
case DUK_TYPE_UNDEFINED:
case DUK_TYPE_NONE:
case DUK_TYPE_NULL:
return NULL;
}
if (NULL != (ptr = duk_get_buffer_data(ctx, index, len)))
{
buf = zbx_malloc(NULL, *len);
memcpy(buf, ptr, *len);
return buf;
}
if (type == DUK_TYPE_BUFFER)
return NULL;
if (SUCCEED == es_duktape_string_decode(duk_safe_to_string(ctx, index), &buf))