Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Functions
mod_format.h File Reference

Header for providers of file and format handling routines. Clients of these routines should include "asterisk/file.h" instead. More...

#include "asterisk/file.h"
#include "asterisk/frame.h"
Include dependency graph for mod_format.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_filestream
 This structure is allocated by file.c in one chunk, together with buf_size and desc_size bytes of memory to be used for private purposes (e.g. buffers etc.) More...
 
struct  ast_format_def
 Each supported file format is described by the following structure. More...
 

Macros

#define ast_format_def_register(f)   __ast_format_def_register(f, AST_MODULE_SELF)
 

Functions

int __ast_format_def_register (const struct ast_format_def *f, struct ast_module *mod)
 Register a new file format capability. Adds a format to Asterisk's format abilities. More...
 
int ast_format_def_unregister (const char *name)
 Unregisters a file format. More...
 

Detailed Description

Header for providers of file and format handling routines. Clients of these routines should include "asterisk/file.h" instead.

Definition in file mod_format.h.

Macro Definition Documentation

◆ ast_format_def_register

#define ast_format_def_register (   f)    __ast_format_def_register(f, AST_MODULE_SELF)

Definition at line 136 of file mod_format.h.

Referenced by load_module().

Function Documentation

◆ __ast_format_def_register()

int __ast_format_def_register ( const struct ast_format_def f,
struct ast_module mod 
)

Register a new file format capability. Adds a format to Asterisk's format abilities.

Return values
0on success
-1on failure

Definition at line 124 of file file.c.

References a, ast_calloc, ast_format_register_type(), ast_log, AST_RWLIST_INSERT_HEAD, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, b, ast_format_def::buf_size, ast_format_def::exts, ast_format_def::list, LOG_WARNING, ast_format_def::module, ast_format_def::name, publish_format_update(), and tmp().

125 {
126  struct ast_format_def *tmp;
127 
130  if (!strcasecmp(f->name, tmp->name)) {
132  ast_log(LOG_WARNING, "Tried to register '%s' format, already registered\n", f->name);
133  return -1;
134  }
135  }
136  if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
138  return -1;
139  }
140  *tmp = *f;
141  tmp->module = mod;
142  if (tmp->buf_size) {
143  /*
144  * Align buf_size properly, rounding up to the machine-specific
145  * alignment for pointers.
146  */
147  struct _test_align { void *a, *b; } p;
148  int align = (char *)&p.b - (char *)&p.a;
149  tmp->buf_size = ((f->buf_size + align - 1) / align) * align;
150  }
151 
152  memset(&tmp->list, 0, sizeof(tmp->list));
153 
154  AST_RWLIST_INSERT_HEAD(&formats, tmp, list);
156  ast_verb(2, "Registered file format %s, extension(s) %s\n", f->name, f->exts);
158 
159  return 0;
160 }
char exts[80]
Definition: mod_format.h:45
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define LOG_WARNING
Definition: logger.h:274
static int tmp()
Definition: bt_open.c:389
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
Each supported file format is described by the following structure.
Definition: mod_format.h:43
#define ast_verb(level,...)
Definition: logger.h:463
struct ast_format_def::@276 list
struct ast_module * module
Definition: mod_format.h:93
#define AST_RWLIST_INSERT_HEAD
Definition: linkedlists.h:717
#define ast_log
Definition: astobj2.c:42
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
Definition: file.c:69
struct stasis_message_type * ast_format_register_type(void)
Get the message type used for signaling a format registration.
char name[80]
Definition: mod_format.h:44
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
static struct test_val b
static int publish_format_update(const struct ast_format_def *f, struct stasis_message_type *type)
Definition: file.c:93
static struct test_val a

◆ ast_format_def_unregister()

int ast_format_def_unregister ( const char *  name)

Unregisters a file format.

Parameters
namethe name of the format you wish to unregister Unregisters a format based on the name of the format.
Return values
0on success
-1on failure to unregister

Definition at line 162 of file file.c.

References ast_format_unregister_type(), ast_free, ast_log, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, ast_format_def::list, LOG_WARNING, ast_format_def::name, publish_format_update(), and tmp().

Referenced by unload_module().

163 {
164  struct ast_format_def *tmp;
165  int res = -1;
166 
169  if (!strcasecmp(name, tmp->name)) {
172  ast_free(tmp);
173  res = 0;
174  }
175  }
178 
179  if (!res)
180  ast_verb(2, "Unregistered format %s\n", name);
181  else
182  ast_log(LOG_WARNING, "Tried to unregister format %s, already unregistered\n", name);
183 
184  return res;
185 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define LOG_WARNING
Definition: logger.h:274
static int tmp()
Definition: bt_open.c:389
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
Each supported file format is described by the following structure.
Definition: mod_format.h:43
#define ast_verb(level,...)
Definition: logger.h:463
struct ast_format_def::@276 list
#define ast_log
Definition: astobj2.c:42
struct stasis_message_type * ast_format_unregister_type(void)
Get the message type used for signaling a format unregistration.
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:569
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:544
Definition: file.c:69
char name[80]
Definition: mod_format.h:44
static const char name[]
Definition: cdr_mysql.c:74
#define ast_free(a)
Definition: astmm.h:182
static int publish_format_update(const struct ast_format_def *f, struct stasis_message_type *type)
Definition: file.c:93
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:616