Asterisk - The Open Source Telephony Project GIT-master-77d630f
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 147 of file func_frame_drop.c.

147 {
148 TX = 0,
149 RX,
150};
@ 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 158 of file func_frame_drop.c.

158 {
159 ast_free(data);
160}
#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 217 of file func_frame_drop.c.

218{
219 char *buffer;
220 struct frame_drop_data *framedata;
221 struct ast_datastore *datastore = NULL;
222 struct ast_framehook_interface interface = {
224 .event_cb = hook_event_cb,
225 .destroy_cb = hook_destroy_cb,
226 };
227 int i = 0;
228
229 if (!(framedata = ast_calloc(1, sizeof(*framedata)))) {
230 return 0;
231 }
232
233 interface.data = framedata;
234
235 if (!strcasecmp(data, "RX")) {
236 framedata->list_type = RX;
237 } else {
238 framedata->list_type = TX;
239 }
240
241 if (ast_asprintf(&buffer, ",%s,", value) < 0) {
242 ast_free(framedata);
243 return -1;
244 }
245 for (i = 0; i < ARRAY_LEN(frametype2str); i++) {
246 if (strcasestr(buffer, frametype2str[i].str)) {
247 framedata->values[i] = 1;
248 }
249 }
250
251 for (i = 0; i < ARRAY_LEN(controlframetype2str); i++) {
252 if (strcasestr(buffer, controlframetype2str[i].str)) {
253 framedata->controlvalues[i] = 1;
254 }
255 }
256 ast_free(buffer);
257
258 ast_channel_lock(chan);
259 i = ast_framehook_attach(chan, &interface);
260 if (i >= 0) {
261 int *id;
262 if ((datastore = ast_channel_datastore_find(chan, &frame_drop_datastore, NULL))) {
263 id = datastore->data;
264 ast_framehook_detach(chan, *id);
265 ast_channel_datastore_remove(chan, datastore);
266 ast_datastore_free(datastore);
267 }
268
269 if (!(datastore = ast_datastore_alloc(&frame_drop_datastore, NULL))) {
270 ast_framehook_detach(chan, i);
271 ast_channel_unlock(chan);
272 return 0;
273 }
274
275 if (!(id = ast_calloc(1, sizeof(int)))) {
276 ast_datastore_free(datastore);
277 ast_framehook_detach(chan, i);
278 ast_channel_unlock(chan);
279 return 0;
280 }
281
282 *id = i; /* Store off the id. The channel is still locked so it is safe to access this ptr. */
283 datastore->data = id;
284 ast_channel_datastore_add(chan, datastore);
285 }
286 ast_channel_unlock(chan);
287
288 return 0;
289}
enum queue_result id
Definition: app_queue.c:1767
char * strcasestr(const char *, const char *)
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition: astmm.h:267
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2355
int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore)
Remove a datastore from a channel.
Definition: channel.c:2364
#define ast_channel_lock(chan)
Definition: channel.h:2972
#define ast_channel_unlock(chan)
Definition: channel.h:2973
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:2369
#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 @173 frametype2str[]
static const struct ast_datastore_info frame_drop_datastore
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)
static struct @174 controlframetype2str[]
const char * str
#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:703

References ARRAY_LEN, ast_asprintf, 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, 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 167 of file func_frame_drop.c.

168{
169 ast_free(framedata);
170}

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

173{
174 int i;
175 int drop_frame = 0;
176 char buf[64];
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 ast_frame_subclass2str(frame, buf, sizeof(buf), NULL, 0);
193 }
194 break;
195 }
196 }
197 } else {
198 for (i = 0; i < ARRAY_LEN(frametype2str); i++) {
199 if (frame->frametype == frametype2str[i].type) {
200 if (framedata->values[i]) {
201 drop_frame = 1;
202 ast_frame_type2str(frame->frametype, buf, sizeof(buf));
203 }
204 break;
205 }
206 }
207 }
208
209 if (drop_frame) {
210 ast_frfree(frame);
211 frame = &ast_null_frame;
212 ast_debug(2, "Dropping %s frame\n", buf);
213 }
214 return frame;
215}
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
@ AST_FRAMEHOOK_EVENT_WRITE
Definition: framehook.h:153
@ AST_FRAMEHOOK_EVENT_READ
Definition: framehook.h:152
char * ast_frame_type2str(enum ast_frame_type frame_type, char *ftype, size_t len)
Copy the discription of a frame type into the provided string.
Definition: main/frame.c:671
#define ast_frfree(fr)
char * ast_frame_subclass2str(struct ast_frame *f, char *subclass, size_t slen, char *moreinfo, size_t mlen)
Copy the discription of a frame's subclass into the provided string.
Definition: main/frame.c:406
@ AST_FRAME_CONTROL
struct ast_frame ast_null_frame
Definition: main/frame.c:79
#define ast_debug(level,...)
Log a DEBUG message.
struct ast_frame_subclass subclass
enum ast_frame_type frametype
Definition: astman.c:222

References ARRAY_LEN, ast_debug, AST_FRAME_CONTROL, ast_frame_subclass2str(), ast_frame_type2str(), AST_FRAMEHOOK_EVENT_READ, AST_FRAMEHOOK_EVENT_WRITE, ast_frfree, ast_null_frame, buf, controlframetype2str, frame_drop_data::controlvalues, ast_frame::frametype, frametype2str, ast_frame_subclass::integer, frame_drop_data::list_type, NULL, 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 301 of file func_frame_drop.c.

302{
305}
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:1562

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

297{
299}
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 162 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 291 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 108 of file func_frame_drop.c.

Referenced by frame_drop_helper().

◆ type

int type

Definition at line 107 of file func_frame_drop.c.