Source
err_index = duk_push_error_object(ctx, DUK_RET_TYPE_ERROR, "parameter 'key' is missing or is undefined");
/*
** 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 envied 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: 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_BUFFER:
case DUK_TYPE_OBJECT:
ptr = duk_require_buffer_data(ctx, index, len);
buf = zbx_malloc(NULL, *len);
memcpy(buf, ptr, *len);
break;
case DUK_TYPE_UNDEFINED:
case DUK_TYPE_NONE:
case DUK_TYPE_NULL:
break;
default:
if (SUCCEED == es_duktape_string_decode(duk_to_string(ctx, index), &buf))