Source
xxxxxxxxxx
static int prepare_common_parameters(const AGENT_REQUEST *request, AGENT_RESULT *result, zbx_regexp_t **regex_incl,
/*
** 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: Checks if filename matches the include-regexp and doesn't match *
* the exclude-regexp. *
* *
* Parameters: fname - [IN] filename to be checked *
* regex_incl - [IN] regexp for filenames to include (NULL means *
* include any file) *
* regex_excl - [IN] regexp for filenames to exclude (NULL means *
* exclude none) *
* *
* Return value: If filename passes both checks, nonzero value is returned. *
* If filename fails to pass, 0 is returned. *
* *
******************************************************************************/
static int filename_matches(const char *fname, const zbx_regexp_t *regex_incl, const zbx_regexp_t *regex_excl)
{
return ((NULL == regex_incl || 0 == zbx_regexp_match_precompiled(fname, regex_incl)) &&
(NULL == regex_excl || 0 != zbx_regexp_match_precompiled(fname, regex_excl)));
}
/******************************************************************************
* *
* Purpose: Adds directory to processing queue after checking if current *
* depth is less than 'max_depth'. *
* *
* Parameters: list - [IN/OUT] vector used to replace recursion *
* with iterative approach *
* path - [IN] directory path *
* depth - [IN] current traversal depth of directory *
* max_depth - [IN] maximal traversal depth allowed (use -1 *
* for unlimited directory traversal) *
* *
* Return value: SUCCEED - directory is queued, *
* FAIL - directory depth is more than allowed traversal depth. *
* *
******************************************************************************/
static int queue_directory(zbx_vector_ptr_t *list, char *path, int depth, int max_depth)
{
zbx_directory_item_t *item;
if (TRAVERSAL_DEPTH_UNLIMITED == max_depth || depth < max_depth)
{
item = (zbx_directory_item_t*)zbx_malloc(NULL, sizeof(zbx_directory_item_t));
item->depth = depth + 1;
item->path = path; /* 'path' changes ownership. Do not free 'path' in the caller. */
zbx_vector_ptr_append(list, item);
return SUCCEED;
}
return FAIL; /* 'path' did not go into 'list' - don't forget to free 'path' in the caller */
}
/******************************************************************************
* *