Asterisk - The Open Source Telephony Project  18.5.0
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 137 of file func_frame_drop.c.

137  {
138  TX = 0,
139  RX,
140 };

Function Documentation

◆ AST_MODULE_INFO_STANDARD_EXTENDED()

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

Referenced by load_module().

◆ datastore_destroy_cb()

static void datastore_destroy_cb ( void *  data)
static

Definition at line 148 of file func_frame_drop.c.

References ast_free.

148  {
149  ast_free(data);
150 }
const char * data
Definition: extconf.h:241
#define ast_free(a)
Definition: astmm.h:182

◆ frame_drop_helper()

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

Definition at line 203 of file func_frame_drop.c.

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, frametype2str, hook_destroy_cb(), hook_event_cb(), id, frame_drop_data::list_type, NULL, RX, str, strcasestr(), TX, frame_drop_data::values, and ast_framehook_interface::version.

204 {
205  char *buffer;
206  struct frame_drop_data *framedata;
207  struct ast_datastore *datastore = NULL;
208  struct ast_framehook_interface interface = {
210  .event_cb = hook_event_cb,
211  .destroy_cb = hook_destroy_cb,
212  };
213  int i = 0;
214 
215  if (!(framedata = ast_calloc(1, sizeof(*framedata)))) {
216  return 0;
217  }
218 
219  interface.data = framedata;
220 
221  if (!strcasecmp(data, "RX")) {
222  framedata->list_type = RX;
223  } else {
224  framedata->list_type = TX;
225  }
226 
227  buffer = ast_malloc(sizeof(value) + 3); /* leading and trailing comma and null terminator */
228  snprintf(buffer, sizeof(value) + 2, ",%s,", value);
229  for (i = 0; i < ARRAY_LEN(frametype2str); i++) {
230  if (strcasestr(value, frametype2str[i].str)) {
231  framedata->values[i] = 1;
232  }
233  }
234 
235  for (i = 0; i < ARRAY_LEN(controlframetype2str); i++) {
237  framedata->controlvalues[i] = 1;
238  }
239  }
240  ast_free(buffer);
241 
242  ast_channel_lock(chan);
243  i = ast_framehook_attach(chan, &interface);
244  if (i >= 0) {
245  int *id;
246  if ((datastore = ast_channel_datastore_find(chan, &frame_drop_datastore, NULL))) {
247  id = datastore->data;
248  ast_framehook_detach(chan, *id);
249  ast_channel_datastore_remove(chan, datastore);
250  ast_datastore_free(datastore);
251  }
252 
253  if (!(datastore = ast_datastore_alloc(&frame_drop_datastore, NULL))) {
254  ast_framehook_detach(chan, i);
255  ast_channel_unlock(chan);
256  return 0;
257  }
258 
259  if (!(id = ast_calloc(1, sizeof(int)))) {
260  ast_datastore_free(datastore);
261  ast_framehook_detach(chan, i);
262  ast_channel_unlock(chan);
263  return 0;
264  }
265 
266  *id = i; /* Store off the id. The channel is still locked so it is safe to access this ptr. */
267  datastore->data = id;
268  ast_channel_datastore_add(chan, datastore);
269  }
270  ast_channel_unlock(chan);
271 
272  return 0;
273 }
static void hook_destroy_cb(void *framedata)
#define ast_channel_lock(chan)
Definition: channel.h:2945
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static struct ast_frame * hook_event_cb(struct ast_channel *chan, struct ast_frame *frame, enum ast_framehook_event event, void *data)
int ast_framehook_detach(struct ast_channel *chan, int framehook_id)
Detach an framehook from a channel.
Definition: framehook.c:177
Structure for a data store object.
Definition: datastore.h:68
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:2404
#define NULL
Definition: resample.c:96
int value
Definition: syslog.c:37
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition: datastore.c:68
static struct @207 frametype2str[]
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 controlvalues[ARRAY_LEN(controlframetype2str)]
const char * str
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
int values[ARRAY_LEN(frametype2str)]
#define AST_FRAMEHOOK_INTERFACE_VERSION
Definition: framehook.h:227
char * strcasestr(const char *, const char *)
#define ast_channel_unlock(chan)
Definition: channel.h:2946
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
enum direction list_type
static struct @208 controlframetype2str[]
void * data
Definition: datastore.h:70
static const struct ast_datastore_info frame_drop_datastore
#define ast_datastore_alloc(info, uid)
Definition: datastore.h:89
enum queue_result id
Definition: app_queue.c:1507
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2390
int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore)
Remove a datastore from a channel.
Definition: channel.c:2399

◆ hook_destroy_cb()

static void hook_destroy_cb ( void *  framedata)
static

Definition at line 157 of file func_frame_drop.c.

References ast_free.

Referenced by frame_drop_helper().

158 {
159  ast_free(framedata);
160 }
#define ast_free(a)
Definition: astmm.h:182

◆ 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 162 of file func_frame_drop.c.

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().

163 {
164  int i;
165  int drop_frame = 0;
166  struct frame_drop_data *framedata = data;
167  if (!frame) {
168  return frame;
169  }
170 
171  if (!((event == AST_FRAMEHOOK_EVENT_WRITE && framedata->list_type == TX) ||
172  (event == AST_FRAMEHOOK_EVENT_READ && framedata->list_type == RX))) {
173  return frame;
174  }
175 
176  if (frame->frametype == AST_FRAME_CONTROL) {
177  for (i = 0; i < ARRAY_LEN(controlframetype2str); i++) {
178  if (frame->subclass.integer == controlframetype2str[i].type) {
179  if (framedata->controlvalues[i]) {
180  drop_frame = 1;
181  }
182  break;
183  }
184  }
185  } else {
186  for (i = 0; i < ARRAY_LEN(frametype2str); i++) {
187  if (frame->frametype == frametype2str[i].type) {
188  if (framedata->values[i]) {
189  drop_frame = 1;
190  }
191  break;
192  }
193  }
194  }
195 
196  if (drop_frame) {
197  ast_frfree(frame);
198  frame = &ast_null_frame;
199  }
200  return frame;
201 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
Definition: astman.c:222
struct ast_frame_subclass subclass
static struct @207 frametype2str[]
int controlvalues[ARRAY_LEN(controlframetype2str)]
int values[ARRAY_LEN(frametype2str)]
enum direction list_type
static struct @208 controlframetype2str[]
struct ast_frame ast_null_frame
Definition: main/frame.c:79
#define ast_frfree(fr)
enum ast_frame_type frametype

◆ load_module()

static int load_module ( void  )
static

Definition at line 285 of file func_frame_drop.c.

References ast_custom_function_register, AST_MODULE_INFO_STANDARD_EXTENDED(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and ASTERISK_GPL_KEY.

286 {
289 }
static struct ast_custom_function frame_drop_function
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:1508

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 280 of file func_frame_drop.c.

References ast_custom_function_unregister().

281 {
283 }
static struct ast_custom_function frame_drop_function
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.

Variable Documentation

◆ controlframetype2str

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 152 of file func_frame_drop.c.

◆ 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 275 of file func_frame_drop.c.

◆ frametype2str

struct { ... } frametype2str[]

Referenced by frame_drop_helper(), and hook_event_cb().

◆ str

const char* str

Definition at line 98 of file func_frame_drop.c.

Referenced by frame_drop_helper().

◆ type

int type

Definition at line 97 of file func_frame_drop.c.