Asterisk - The Open Source Telephony Project GIT-master-d856a3e
Data Structures | Enumerations | Functions | Variables
func_frame_drop.c File Reference

Function that drops specified frames from channels. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/framehook.h"
Include dependency graph for func_frame_drop.c:

Go to the source code of this file.

Data Structures

struct  frame_drop_data
 

Enumerations

enum  direction { TX = 0 , RX }
 

Functions

 AST_MODULE_INFO_STANDARD_EXTENDED (ASTERISK_GPL_KEY, "Function to drop frames on a channel.")
 
static void datastore_destroy_cb (void *data)
 
static int frame_drop_helper (struct ast_channel *chan, const char *cmd, char *data, const char *value)
 
static void hook_destroy_cb (void *framedata)
 
static struct ast_framehook_event_cb (struct ast_channel *chan, struct ast_frame *frame, enum ast_framehook_event event, void *data)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

struct {
   const char *   str
 
   int   type
 
controlframetype2str []
 
static const struct ast_datastore_info frame_drop_datastore
 
static struct ast_custom_function frame_drop_function
 
struct {
   const char *   str
 
   enum ast_frame_type   type
 
frametype2str []
 

Detailed Description

Function that drops specified frames from channels.

Author
Naveen Albert aster.nosp@m.isk@.nosp@m.phrea.nosp@m.knet.nosp@m..org

Definition in file func_frame_drop.c.

Enumeration Type Documentation

◆ direction

enum direction
Enumerator
TX 
RX 

Definition at line 148 of file func_frame_drop.c.

148 {
149 TX = 0,
150 RX,
151};
@ RX
@ TX

Function Documentation

◆ AST_MODULE_INFO_STANDARD_EXTENDED()

AST_MODULE_INFO_STANDARD_EXTENDED ( ASTERISK_GPL_KEY  ,
"Function to drop frames on a channel."   
)

◆ datastore_destroy_cb()

static void datastore_destroy_cb ( void *  data)
static

Definition at line 159 of file func_frame_drop.c.

159 {
160 ast_free(data);
161}
#define ast_free(a)
Definition: astmm.h:180

References ast_free.

◆ frame_drop_helper()

static int frame_drop_helper ( struct ast_channel chan,
const char *  cmd,
char *  data,
const char *  value 
)
static

Definition at line 214 of file func_frame_drop.c.

215{
216 char *buffer;
217 struct frame_drop_data *framedata;
218 struct ast_datastore *datastore = NULL;
219 struct ast_framehook_interface interface = {
221 .event_cb = hook_event_cb,
222 .destroy_cb = hook_destroy_cb,
223 };
224 int i = 0;
225
226 if (!(framedata = ast_calloc(1, sizeof(*framedata)))) {
227 return 0;
228 }
229
230 interface.data = framedata;
231
232 if (!strcasecmp(data, "RX")) {
233 framedata->list_type = RX;
234 } else {
235 framedata->list_type = TX;
236 }
237
238 buffer = ast_malloc(sizeof(value) + 3); /* leading and trailing comma and null terminator */
239 snprintf(buffer, sizeof(value) + 2, ",%s,", value);
240 for (i = 0; i < ARRAY_LEN(frametype2str); i++) {
241 if (strcasestr(buffer, frametype2str[i].str)) {
242 framedata->values[i] = 1;
243 }
244 }
245
246 for (i = 0; i < ARRAY_LEN(controlframetype2str); i++) {
247 if (strcasestr(buffer, controlframetype2str[i].str)) {
248 framedata->controlvalues[i] = 1;
249 }
250 }
251 ast_free(buffer);
252
253 ast_channel_lock(chan);
254 i = ast_framehook_attach(chan, &interface);
255 if (i >= 0) {
256 int *id;
257 if ((datastore = ast_channel_datastore_find(chan, &frame_drop_datastore, NULL))) {
258 id = datastore->data;
259 ast_framehook_detach(chan, *id);
260 ast_channel_datastore_remove(chan, datastore);
261 ast_datastore_free(datastore);
262 }
263
264 if (!(datastore = ast_datastore_alloc(&frame_drop_datastore, NULL))) {
265 ast_framehook_detach(chan, i);
266 ast_channel_unlock(chan);
267 return 0;
268 }
269
270 if (!(id = ast_calloc(1, sizeof(int)))) {
271 ast_datastore_free(datastore);
272 ast_framehook_detach(chan, i);
273 ast_channel_unlock(chan);
274 return 0;
275 }
276
277 *id = i; /* Store off the id. The channel is still locked so it is safe to access this ptr. */
278 datastore->data = id;
279 ast_channel_datastore_add(chan, datastore);
280 }
281 ast_channel_unlock(chan);
282
283 return 0;
284}
enum queue_result id
Definition: app_queue.c:1638
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:191
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2404
int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore)
Remove a datastore from a channel.
Definition: channel.c:2413
#define ast_channel_lock(chan)
Definition: channel.h:2968
#define ast_channel_unlock(chan)
Definition: channel.h:2969
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Definition: channel.c:2418
#define ast_datastore_alloc(info, uid)
Definition: datastore.h:85
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition: datastore.c:68
int ast_framehook_attach(struct ast_channel *chan, struct ast_framehook_interface *i)
Attach an framehook onto a channel for frame interception.
Definition: framehook.c:132
int ast_framehook_detach(struct ast_channel *chan, int framehook_id)
Detach an framehook from a channel.
Definition: framehook.c:177
#define AST_FRAMEHOOK_INTERFACE_VERSION
Definition: framehook.h:227
static struct @170 frametype2str[]
static const struct ast_datastore_info frame_drop_datastore
static struct @171 controlframetype2str[]
static struct ast_frame * hook_event_cb(struct ast_channel *chan, struct ast_frame *frame, enum ast_framehook_event event, void *data)
static void hook_destroy_cb(void *framedata)
const char * str
char * strcasestr(const char *, const char *)
#define NULL
Definition: resample.c:96
Structure for a data store object.
Definition: datastore.h:64
void * data
Definition: datastore.h:66
int values[ARRAY_LEN(frametype2str)]
int controlvalues[ARRAY_LEN(controlframetype2str)]
enum direction list_type
int value
Definition: syslog.c:37
#define ARRAY_LEN(a)
Definition: utils.h:666

References ARRAY_LEN, ast_calloc, ast_channel_datastore_add(), ast_channel_datastore_find(), ast_channel_datastore_remove(), ast_channel_lock, ast_channel_unlock, ast_datastore_alloc, ast_datastore_free(), ast_framehook_attach(), ast_framehook_detach(), AST_FRAMEHOOK_INTERFACE_VERSION, ast_free, ast_malloc, controlframetype2str, frame_drop_data::controlvalues, ast_datastore::data, ast_framehook_interface::data, frame_drop_datastore, frametype2str, hook_destroy_cb(), hook_event_cb(), id, frame_drop_data::list_type, NULL, RX, str, strcasestr(), TX, value, frame_drop_data::values, and ast_framehook_interface::version.

◆ hook_destroy_cb()

static void hook_destroy_cb ( void *  framedata)
static

Definition at line 168 of file func_frame_drop.c.

169{
170 ast_free(framedata);
171}

References ast_free.

Referenced by frame_drop_helper().

◆ hook_event_cb()

static struct ast_frame * hook_event_cb ( struct ast_channel chan,
struct ast_frame frame,
enum ast_framehook_event  event,
void *  data 
)
static

Definition at line 173 of file func_frame_drop.c.

174{
175 int i;
176 int drop_frame = 0;
177 struct frame_drop_data *framedata = data;
178 if (!frame) {
179 return frame;
180 }
181
182 if (!((event == AST_FRAMEHOOK_EVENT_WRITE && framedata->list_type == TX) ||
183 (event == AST_FRAMEHOOK_EVENT_READ && framedata->list_type == RX))) {
184 return frame;
185 }
186
187 if (frame->frametype == AST_FRAME_CONTROL) {
188 for (i = 0; i < ARRAY_LEN(controlframetype2str); i++) {
189 if (frame->subclass.integer == controlframetype2str[i].type) {
190 if (framedata->controlvalues[i]) {
191 drop_frame = 1;
192 }
193 break;
194 }
195 }
196 } else {
197 for (i = 0; i < ARRAY_LEN(frametype2str); i++) {
198 if (frame->frametype == frametype2str[i].type) {
199 if (framedata->values[i]) {
200 drop_frame = 1;
201 }
202 break;
203 }
204 }
205 }
206
207 if (drop_frame) {
208 ast_frfree(frame);
209 frame = &ast_null_frame;
210 }
211 return frame;
212}
@ AST_FRAMEHOOK_EVENT_WRITE
Definition: framehook.h:153
@ AST_FRAMEHOOK_EVENT_READ
Definition: framehook.h:152
#define ast_frfree(fr)
@ AST_FRAME_CONTROL
struct ast_frame ast_null_frame
Definition: main/frame.c:79
struct ast_frame_subclass subclass
enum ast_frame_type frametype
Definition: astman.c:222

References ARRAY_LEN, AST_FRAME_CONTROL, AST_FRAMEHOOK_EVENT_READ, AST_FRAMEHOOK_EVENT_WRITE, ast_frfree, ast_null_frame, controlframetype2str, frame_drop_data::controlvalues, ast_frame::frametype, frametype2str, ast_frame_subclass::integer, frame_drop_data::list_type, RX, ast_frame::subclass, TX, and frame_drop_data::values.

Referenced by frame_drop_helper().

◆ load_module()

static int load_module ( void  )
static

Definition at line 296 of file func_frame_drop.c.

297{
300}
static struct ast_custom_function frame_drop_function
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1558

References ast_custom_function_register, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and frame_drop_function.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 291 of file func_frame_drop.c.

292{
294}
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.

References ast_custom_function_unregister(), and frame_drop_function.

Variable Documentation

◆ 

struct { ... } controlframetype2str[]

Referenced by frame_drop_helper(), and hook_event_cb().

◆ frame_drop_datastore

const struct ast_datastore_info frame_drop_datastore
static
Initial value:
= {
.type = "framedrop",
}
static void datastore_destroy_cb(void *data)

Definition at line 163 of file func_frame_drop.c.

Referenced by frame_drop_helper().

◆ frame_drop_function

struct ast_custom_function frame_drop_function
static
Initial value:
= {
.name = "FRAME_DROP",
}
static int frame_drop_helper(struct ast_channel *chan, const char *cmd, char *data, const char *value)

Definition at line 286 of file func_frame_drop.c.

Referenced by load_module(), and unload_module().

◆ 

struct { ... } frametype2str[]

Referenced by frame_drop_helper(), and hook_event_cb().

◆ str

const char* str

Definition at line 109 of file func_frame_drop.c.

Referenced by frame_drop_helper().

◆ type

int type

Definition at line 108 of file func_frame_drop.c.