mirror of
				https://github.com/asterisk/asterisk.git
				synced 2025-11-03 20:38:59 +00:00 
			
		
		
		
	This renames all files and API calls from several variants of Stasis-HTTP to ARI including: * Stasis-HTTP -> ARI * STASIS_HTTP -> ARI * stasis_http -> ari (ast_ari for global symbols, file names as well) * stasis http -> ARI Review: https://reviewboard.asterisk.org/r/2706/ (closes issue ASTERISK-22136) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@395603 65c4cc65-6c06-0410-ace0-fbb531ad65f3
		
			
				
	
	
		
			123 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			123 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
/*
 | 
						|
 * Asterisk -- An open source telephony toolkit.
 | 
						|
 *
 | 
						|
 * Copyright (C) 2013, Digium, Inc.
 | 
						|
 *
 | 
						|
 * See http://www.asterisk.org for more information about
 | 
						|
 * the Asterisk project. Please do not directly contact
 | 
						|
 * any of the maintainers of this project for assistance;
 | 
						|
 * the project provides a web site, mailing lists and IRC
 | 
						|
 * channels for your use.
 | 
						|
 *
 | 
						|
 * This program is free software, distributed under the terms of
 | 
						|
 * the GNU General Public License Version 2. See the LICENSE file
 | 
						|
 * at the top of the source tree.
 | 
						|
 */
 | 
						|
 | 
						|
/*! \file
 | 
						|
 *
 | 
						|
 * \brief Generated file - Build validators for ARI model objects.
 | 
						|
 */
 | 
						|
 | 
						|
 /*
 | 
						|
{{> do-not-edit}}
 | 
						|
 * This file is generated by a mustache template. Please see the original
 | 
						|
 * template in rest-api-templates/ari_model_validators.h.mustache
 | 
						|
 */
 | 
						|
 | 
						|
#include "asterisk.h"
 | 
						|
 | 
						|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 | 
						|
 | 
						|
#include "asterisk/logger.h"
 | 
						|
#include "asterisk/module.h"
 | 
						|
#include "ari_model_validators.h"
 | 
						|
{{#apis}}
 | 
						|
{{#api_declaration}}
 | 
						|
{{#models}}
 | 
						|
 | 
						|
int ast_ari_validate_{{c_id}}(struct ast_json *json)
 | 
						|
{
 | 
						|
	int res = 1;
 | 
						|
	struct ast_json_iter *iter;
 | 
						|
{{#properties}}
 | 
						|
{{#required}}
 | 
						|
	int has_{{name}} = 0;
 | 
						|
{{/required}}
 | 
						|
{{/properties}}
 | 
						|
{{#has_subtypes}}
 | 
						|
	const char *discriminator;
 | 
						|
 | 
						|
	discriminator = ast_json_string_get(ast_json_object_get(json, "{{discriminator.name}}"));
 | 
						|
	if (!discriminator) {
 | 
						|
		ast_log(LOG_ERROR, "ARI {{id}} missing required field {{discriminator.name}}");
 | 
						|
		return 0;
 | 
						|
	}
 | 
						|
 | 
						|
	if (strcmp("{{id}}", discriminator) == 0) {
 | 
						|
		/* Self type; fall through */
 | 
						|
	} else
 | 
						|
{{#subtypes}}
 | 
						|
	if (strcmp("{{id}}", discriminator) == 0) {
 | 
						|
		return ast_ari_validate_{{c_id}}(json);
 | 
						|
	} else
 | 
						|
{{/subtypes}}
 | 
						|
	{
 | 
						|
		ast_log(LOG_ERROR, "ARI {{id}} has undocumented subtype %s\n",
 | 
						|
			discriminator);
 | 
						|
		res = 0;
 | 
						|
	}
 | 
						|
{{/has_subtypes}}
 | 
						|
 | 
						|
	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
 | 
						|
{{#properties}}
 | 
						|
		if (strcmp("{{name}}", ast_json_object_iter_key(iter)) == 0) {
 | 
						|
			int prop_is_valid;
 | 
						|
{{#required}}
 | 
						|
			has_{{name}} = 1;
 | 
						|
{{/required}}
 | 
						|
{{#type}}
 | 
						|
{{#is_list}}
 | 
						|
			prop_is_valid = ast_ari_validate_list(
 | 
						|
				ast_json_object_iter_value(iter),
 | 
						|
				ast_ari_validate_{{c_singular_name}});
 | 
						|
{{/is_list}}
 | 
						|
{{^is_list}}
 | 
						|
			prop_is_valid = ast_ari_validate_{{c_name}}(
 | 
						|
				ast_json_object_iter_value(iter));
 | 
						|
{{/is_list}}
 | 
						|
{{/type}}
 | 
						|
			if (!prop_is_valid) {
 | 
						|
				ast_log(LOG_ERROR, "ARI {{id}} field {{name}} failed validation\n");
 | 
						|
				res = 0;
 | 
						|
			}
 | 
						|
		} else
 | 
						|
{{/properties}}
 | 
						|
		{
 | 
						|
			ast_log(LOG_ERROR,
 | 
						|
				"ARI {{id}} has undocumented field %s\n",
 | 
						|
				ast_json_object_iter_key(iter));
 | 
						|
			res = 0;
 | 
						|
		}
 | 
						|
	}
 | 
						|
 | 
						|
{{#properties}}
 | 
						|
{{#required}}
 | 
						|
	if (!has_{{name}}) {
 | 
						|
		ast_log(LOG_ERROR, "ARI {{id}} missing required field {{name}}\n");
 | 
						|
		res = 0;
 | 
						|
	}
 | 
						|
 | 
						|
{{/required}}
 | 
						|
{{/properties}}
 | 
						|
	return res;
 | 
						|
}
 | 
						|
 | 
						|
ari_validator ast_ari_validate_{{c_id}}_fn(void)
 | 
						|
{
 | 
						|
	return ast_ari_validate_{{c_id}};
 | 
						|
}
 | 
						|
{{/models}}
 | 
						|
{{/api_declaration}}
 | 
						|
{{/apis}}
 |