1 #ifndef EVEL_THROTTLE_INCLUDED
2 #define EVEL_THROTTLE_INCLUDED
4 /**************************************************************************//**
6 * EVEL throttle definitions.
8 * These are internal definitions related to throttling specicications, which
9 * are required within the library but are not intended for external
15 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
17 * Licensed under the Apache License, Version 2.0 (the "License");
18 * you may not use this file except in compliance with the License.
19 * You may obtain a copy of the License at
20 * http://www.apache.org/licenses/LICENSE-2.0
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS,
24 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
27 *****************************************************************************/
29 #include "evel_internal.h"
32 /*****************************************************************************/
33 /* Maximum depth of JSON response that we can handle. */
34 /*****************************************************************************/
35 #define EVEL_JSON_STACK_DEPTH 10
37 /**************************************************************************//**
38 * Maximum number of tokens that we allow for in a JSON response.
39 *****************************************************************************/
40 #define EVEL_MAX_RESPONSE_TOKENS 1024
42 /**************************************************************************//**
43 * The nature of the next token that we are iterating through. Within an
44 * object, we alternate between collecting keys and values. Within an array,
45 * we only collect items.
46 *****************************************************************************/
53 /**************************************************************************//**
54 * States which we move through during JSON processing, tracking our way
55 * through the supported JSON structure.
56 *****************************************************************************/
59 /***************************************************************************/
61 /***************************************************************************/
64 /***************************************************************************/
65 /* {"commandList": [ */
66 /***************************************************************************/
67 EVEL_JCS_COMMAND_LIST,
69 /***************************************************************************/
70 /* {"commandList": [{ */
71 /***************************************************************************/
72 EVEL_JCS_COMMAND_LIST_ENTRY,
74 /***************************************************************************/
75 /* {"commandList": [{"command": { */
76 /***************************************************************************/
79 /***************************************************************************/
80 /* ... "eventDomainThrottleSpecification": { */
81 /***************************************************************************/
84 /***************************************************************************/
85 /* ... "suppressedFieldNames": [ */
86 /***************************************************************************/
89 /***************************************************************************/
90 /* ... "suppressedNvPairsList": [ */
91 /***************************************************************************/
94 /***************************************************************************/
95 /* ... "suppressedNvPairsList": [{ */
96 /***************************************************************************/
97 EVEL_JCS_PAIRS_LIST_ENTRY,
99 /***************************************************************************/
100 /* ... "suppressedNvPairNames": [ */
101 /***************************************************************************/
102 EVEL_JCS_NV_PAIR_NAMES,
105 } EVEL_JSON_COMMAND_STATE;
107 /**************************************************************************//**
108 * An entry in the JSON stack.
109 *****************************************************************************/
110 typedef struct evel_json_stack_entry {
112 /***************************************************************************/
113 /* The number of elements required at this level. */
114 /***************************************************************************/
117 /***************************************************************************/
118 /* The number of elements collected at this level. */
119 /***************************************************************************/
122 /***************************************************************************/
123 /* The collection state at this level in the JSON stack. */
124 /***************************************************************************/
125 EVEL_JSON_STATE json_state;
127 /***************************************************************************/
128 /* The key being collected (if json_state is EVEL_JSON_VALUE), or NULL. */
129 /***************************************************************************/
132 } EVEL_JSON_STACK_ENTRY;
134 /**************************************************************************//**
136 *****************************************************************************/
137 typedef struct evel_json_stack {
139 /***************************************************************************/
140 /* The current position of the stack - starting at zero. */
141 /***************************************************************************/
144 /***************************************************************************/
145 /* The stack itself. */
146 /***************************************************************************/
147 EVEL_JSON_STACK_ENTRY entry[EVEL_JSON_STACK_DEPTH];
149 /***************************************************************************/
150 /* The underlying memory chunk. */
151 /***************************************************************************/
152 const MEMORY_CHUNK * chunk;
156 /**************************************************************************//**
157 * Initialize event throttling to the default state.
159 * Called from ::evel_initialize.
160 *****************************************************************************/
161 void evel_throttle_initialize();
163 /**************************************************************************//**
164 * Clean up event throttling.
166 * Called from ::evel_terminate.
167 *****************************************************************************/
168 void evel_throttle_terminate();
170 /**************************************************************************//**
171 * Handle a JSON response from the listener, as a list of tokens from JSMN.
173 * @param chunk Memory chunk containing the JSON buffer.
174 * @param json_tokens Array of tokens to handle.
175 * @param num_tokens The number of tokens to handle.
176 * @param post The memory chunk in which to place any resulting POST.
177 * @return true if the command was handled, false otherwise.
178 *****************************************************************************/
179 bool evel_handle_command_list(const MEMORY_CHUNK * const chunk,
180 const jsmntok_t * const json_tokens,
181 const int num_tokens,
182 MEMORY_CHUNK * const post);
184 /**************************************************************************//**
185 * Return the ::EVEL_THROTTLE_SPEC for a given domain.
187 * @param domain The domain for which to return state.
188 *****************************************************************************/
189 EVEL_THROTTLE_SPEC * evel_get_throttle_spec(EVEL_EVENT_DOMAINS domain);
191 /**************************************************************************//**
192 * Determine whether a field_name should be suppressed.
194 * @param throttle_spec Throttle specification for the domain being encoded.
195 * @param field_name The field name to encoded or suppress.
196 * @return true if the field_name should be suppressed, false otherwise.
197 *****************************************************************************/
198 bool evel_throttle_suppress_field(EVEL_THROTTLE_SPEC * throttle_spec,
199 const char * const field_name);
201 /**************************************************************************//**
202 * Determine whether a name-value pair should be allowed (not suppressed).
204 * @param throttle_spec Throttle specification for the domain being encoded.
205 * @param field_name The field name holding the name-value pairs.
206 * @param name The name of the name-value pair to encoded or suppress.
207 * @return true if the name-value pair should be suppressed, false otherwise.
208 *****************************************************************************/
209 bool evel_throttle_suppress_nv_pair(EVEL_THROTTLE_SPEC * throttle_spec,
210 const char * const field_name,
211 const char * const name);