Asterisk - The Open Source Telephony Project GIT-master-8f1982c
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
Macros | Functions | Variables
channel_internal.h File Reference

Internal channel functions for channel.c to use. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ast_channel_internal_alloc(destructor, assignedid, requestor)   __ast_channel_internal_alloc(destructor, assignedid, requestor, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 

Functions

struct ast_channel__ast_channel_internal_alloc (void(*destructor)(void *obj), const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *file, int line, const char *function)
 
struct ast_channel__ast_channel_internal_alloc_with_initializers (void(*destructor)(void *obj), const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const struct ast_channel_initializers *initializers, const char *file, int line, const char *function)
 
void ast_channel_close_storage (void)
 
void ast_channel_internal_cleanup (struct ast_channel *chan)
 
enum ast_channel_error ast_channel_internal_errno (void)
 
void ast_channel_internal_errno_set (enum ast_channel_error error)
 
void ast_channel_internal_finalize (struct ast_channel *chan)
 
int ast_channel_internal_is_finalized (struct ast_channel *chan)
 
void ast_channel_internal_set_stream_topology (struct ast_channel *chan, struct ast_stream_topology *topology)
 
void ast_channel_internal_set_stream_topology_change_source (struct ast_channel *chan, void *change_source)
 
int ast_channel_internal_setup_topics (struct ast_channel *chan)
 
void ast_channel_internal_swap_stream_topology (struct ast_channel *chan1, struct ast_channel *chan2)
 
int ast_channel_open_storage (void)
 

Variables

const struct ast_channelstorage_drivercurrent_channel_storage_driver
 The current channel storage driver. More...
 
struct ast_channelstorage_instancecurrent_channel_storage_instance
 The current channel storage instance. More...
 

Detailed Description

Internal channel functions for channel.c to use.

Definition in file channel_internal.h.

Macro Definition Documentation

◆ ast_channel_internal_alloc

#define ast_channel_internal_alloc (   destructor,
  assignedid,
  requestor 
)    __ast_channel_internal_alloc(destructor, assignedid, requestor, __FILE__, __LINE__, __PRETTY_FUNCTION__)

Definition at line 24 of file channel_internal.h.

Function Documentation

◆ __ast_channel_internal_alloc()

struct ast_channel * __ast_channel_internal_alloc ( void(*)(void *obj)  destructor,
const struct ast_assigned_ids assignedids,
const struct ast_channel requestor,
const char *  file,
int  line,
const char *  function 
)

Definition at line 1267 of file channel_internal_api.c.

1269{
1270 return __ast_channel_internal_alloc_with_initializers(destructor, assignedids, requestor, NULL, file, line, function);
1271}
struct ast_channel * __ast_channel_internal_alloc_with_initializers(void(*destructor)(void *obj), const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const struct ast_channel_initializers *initializers, const char *file, int line, const char *function)
#define NULL
Definition: resample.c:96

References __ast_channel_internal_alloc_with_initializers(), make_ari_stubs::file, and NULL.

Referenced by __ast_dummy_channel_alloc().

◆ __ast_channel_internal_alloc_with_initializers()

struct ast_channel * __ast_channel_internal_alloc_with_initializers ( void(*)(void *obj)  destructor,
const struct ast_assigned_ids assignedids,
const struct ast_channel requestor,
const struct ast_channel_initializers initializers,
const char *  file,
int  line,
const char *  function 
)

Definition at line 1190 of file channel_internal_api.c.

1192{
1193 struct ast_channel *tmp;
1194
1195 tmp = __ao2_alloc(sizeof(*tmp), destructor,
1196 AO2_ALLOC_OPT_LOCK_MUTEX, "", file, line, function);
1197
1198 if (!tmp) {
1199 return NULL;
1200 }
1201
1202 if ((ast_string_field_init(tmp, 128))) {
1203 return ast_channel_unref(tmp);
1204 }
1205
1208 if (!tmp->dialed_causes) {
1209 return ast_channel_unref(tmp);
1210 }
1211
1212 /* Check initializers validity here for early abort. Unfortunately, we can't do much here because
1213 * tenant ID is part of linked ID, which would overwrite it further down. */
1214 if (initializers) {
1215 if (initializers->version == 0) {
1216 ast_log(LOG_ERROR, "Channel initializers must have a non-zero version.\n");
1217 return ast_channel_unref(tmp);
1218 } else if (initializers->version != AST_CHANNEL_INITIALIZERS_VERSION) {
1219 ast_log(LOG_ERROR, "ABI mismatch for ast_channel_initializers. "
1220 "Please ensure all modules were compiled for "
1221 "this version of Asterisk.\n");
1222 return ast_channel_unref(tmp);
1223 }
1224 }
1225
1226 /* set the creation time in the uniqueid */
1227 tmp->uniqueid.creation_time = time(NULL);
1229
1230 /* use provided id or default to historical {system-}time.# format */
1231 if (assignedids && !ast_strlen_zero(assignedids->uniqueid)) {
1232 ast_copy_string(tmp->uniqueid.unique_id, assignedids->uniqueid, sizeof(tmp->uniqueid.unique_id));
1234 snprintf(tmp->uniqueid.unique_id, sizeof(tmp->uniqueid.unique_id), "%li.%d",
1235 (long)(tmp->uniqueid.creation_time),
1237 } else {
1238 snprintf(tmp->uniqueid.unique_id, sizeof(tmp->uniqueid.unique_id), "%s-%li.%d",
1240 (long)(tmp->uniqueid.creation_time),
1242 }
1243
1244 /* copy linked id from parent channel if known */
1245 if (requestor) {
1246 tmp->linkedid = requestor->linkedid;
1247 } else {
1248 tmp->linkedid = tmp->uniqueid;
1249 }
1250
1251 /* Things like tenant ID need to be set here, otherwise they would be overwritten by
1252 * things like inheriting linked ID above. */
1253 if (initializers) {
1254 ast_copy_string(tmp->linkedid.tenant_id, initializers->tenantid, sizeof(tmp->linkedid.tenant_id));
1255 }
1256
1257 AST_VECTOR_INIT(&tmp->fds, AST_MAX_FDS);
1258
1259 /* Force all channel snapshot segments to be created on first use, so we don't have to check if
1260 * an old snapshot exists.
1261 */
1263
1264 return tmp;
1265}
#define ast_log
Definition: astobj2.c:42
@ AO2_ALLOC_OPT_LOCK_MUTEX
Definition: astobj2.h:363
void * __ao2_alloc(size_t data_size, ao2_destructor_fn destructor_fn, unsigned int options, const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result
Definition: astobj2.c:768
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
Definition: astobj2.h:1303
#define AST_CHANNEL_INITIALIZERS_VERSION
struct ABI version
Definition: channel.h:620
#define AST_MAX_FDS
Definition: channel.h:196
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:3008
static int uniqueint
The monotonically increasing integer counter for channel uniqueids.
static int pvt_cause_cmp_fn(void *obj, void *vstr, int flags)
Comparison function for pvt cause code frames.
#define DIALED_CAUSES_BUCKETS
static int pvt_cause_hash_fn(const void *vpc, const int flags)
Hash function for pvt cause code frames.
#define LOG_ERROR
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:764
const char * ast_config_AST_SYSTEM_NAME
Definition: options.c:171
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:359
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
const char * uniqueid
Definition: channel.h:607
char unique_id[AST_MAX_UNIQUEID]
char tenant_id[AST_MAX_TENANT_ID]
const char * tenantid
Definition: channel.h:626
uint32_t version
struct ABI version
Definition: channel.h:625
Main Channel structure associated with a channel.
struct ast_channel_id uniqueid
struct ao2_container * dialed_causes
struct ast_flags snapshot_segment_flags
struct ast_channel_id linkedid
#define ast_set_flag(p, flag)
Definition: utils.h:70
#define AST_FLAGS_ALL
Definition: utils.h:196
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition: vector.h:113

References __ao2_alloc(), AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ast_atomic_fetchadd_int(), AST_CHANNEL_INITIALIZERS_VERSION, ast_channel_unref, ast_config_AST_SYSTEM_NAME, ast_copy_string(), AST_FLAGS_ALL, ast_log, AST_MAX_FDS, ast_set_flag, ast_string_field_init, ast_strlen_zero(), AST_VECTOR_INIT, ast_channel_id::creation_time, ast_channel_id::creation_unique, ast_channel::dialed_causes, DIALED_CAUSES_BUCKETS, make_ari_stubs::file, ast_channel::linkedid, LOG_ERROR, NULL, pvt_cause_cmp_fn(), pvt_cause_hash_fn(), ast_channel::snapshot_segment_flags, ast_channel_id::tenant_id, ast_channel_initializers::tenantid, ast_channel_id::unique_id, ast_assigned_ids::uniqueid, ast_channel::uniqueid, uniqueint, and ast_channel_initializers::version.

Referenced by __ast_channel_alloc_ap(), and __ast_channel_internal_alloc().

◆ ast_channel_close_storage()

void ast_channel_close_storage ( void  )

Definition at line 7939 of file channel.c.

7940{
7942}
struct ast_channelstorage_instance * current_channel_storage_instance
The current channel storage instance.
void ast_channelstorage_close(struct ast_channelstorage_instance *storage_instance)

References ast_channelstorage_close(), and current_channel_storage_instance.

◆ ast_channel_internal_cleanup()

void ast_channel_internal_cleanup ( struct ast_channel chan)

Definition at line 1364 of file channel_internal_api.c.

1365{
1366 if (chan->dialed_causes) {
1367 ao2_t_ref(chan->dialed_causes, -1,
1368 "done with dialed causes since the channel is going away");
1369 chan->dialed_causes = NULL;
1370 }
1371
1373
1376
1377 ao2_cleanup(chan->topic);
1378 chan->topic = NULL;
1379
1381
1382 AST_VECTOR_FREE(&chan->fds);
1383}
#define ao2_t_ref(o, delta, tag)
Definition: astobj2.h:460
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
void ast_channel_internal_set_stream_topology(struct ast_channel *chan, struct ast_stream_topology *topology)
struct stasis_forward * stasis_forward_cancel(struct stasis_forward *forward)
Definition: stasis.c:1575
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:374
struct stasis_topic * topic
struct stasis_forward * endpoint_forward
struct stasis_forward * channel_forward
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Definition: vector.h:174

References ao2_cleanup, ao2_t_ref, ast_channel_internal_set_stream_topology(), ast_string_field_free_memory, AST_VECTOR_FREE, ast_channel::channel_forward, ast_channel::dialed_causes, ast_channel::endpoint_forward, NULL, stasis_forward_cancel(), and ast_channel::topic.

Referenced by ast_channel_destructor(), and ast_dummy_channel_destructor().

◆ ast_channel_internal_errno()

enum ast_channel_error ast_channel_internal_errno ( void  )

Definition at line 1466 of file channel_internal_api.c.

1467{
1468 enum ast_channel_error *error_code = ast_threadstorage_get(&channel_errno, sizeof(*error_code));
1469 if (!error_code) {
1471 }
1472
1473 return *error_code;
1474}
ast_channel_error
Definition: channel.h:4871
@ AST_CHANNEL_ERROR_UNKNOWN
Definition: channel.h:4873
static struct ast_threadstorage channel_errno
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.

References AST_CHANNEL_ERROR_UNKNOWN, ast_threadstorage_get(), and channel_errno.

Referenced by ast_channel_errno().

◆ ast_channel_internal_errno_set()

void ast_channel_internal_errno_set ( enum ast_channel_error  error)

Definition at line 1456 of file channel_internal_api.c.

1457{
1458 enum ast_channel_error *error_code = ast_threadstorage_get(&channel_errno, sizeof(*error_code));
1459 if (!error_code) {
1460 return;
1461 }
1462
1463 *error_code = error;
1464}
int error(const char *format,...)
Definition: utils/frame.c:999

References ast_threadstorage_get(), channel_errno, and error().

Referenced by __ast_channel_alloc_ap().

◆ ast_channel_internal_finalize()

void ast_channel_internal_finalize ( struct ast_channel chan)

Definition at line 1385 of file channel_internal_api.c.

1386{
1387 chan->finalized = 1;
1388}
unsigned int finalized

References ast_channel::finalized.

Referenced by __ast_channel_alloc_ap().

◆ ast_channel_internal_is_finalized()

int ast_channel_internal_is_finalized ( struct ast_channel chan)

Definition at line 1390 of file channel_internal_api.c.

1391{
1392 return chan->finalized;
1393}

References ast_channel::finalized.

Referenced by ast_channel_destructor().

◆ ast_channel_internal_set_stream_topology()

void ast_channel_internal_set_stream_topology ( struct ast_channel chan,
struct ast_stream_topology topology 
)

Definition at line 516 of file channel_internal_api.c.

518{
520 chan->stream_topology = topology;
522}
static void channel_set_default_streams(struct ast_channel *chan)
void ast_stream_topology_free(struct ast_stream_topology *topology)
Unreference and destroy a stream topology.
Definition: stream.c:746
struct ast_stream_topology * stream_topology

References ast_stream_topology_free(), channel_set_default_streams(), and ast_channel::stream_topology.

Referenced by __ast_channel_alloc_ap(), ast_channel_internal_cleanup(), ast_channel_nativeformats_set(), and ast_channel_set_stream_topology().

◆ ast_channel_internal_set_stream_topology_change_source()

void ast_channel_internal_set_stream_topology_change_source ( struct ast_channel chan,
void *  change_source 
)

◆ ast_channel_internal_setup_topics()

int ast_channel_internal_setup_topics ( struct ast_channel chan)

Definition at line 1420 of file channel_internal_api.c.

1421{
1422 char *topic_name;
1423 int ret;
1424 ast_assert(chan->topic == NULL);
1425
1426 if (ast_strlen_zero(chan->uniqueid.unique_id)) {
1427 static int dummy_id;
1428 ret = ast_asprintf(&topic_name, "channel:dummy-%d", ast_atomic_fetchadd_int(&dummy_id, +1));
1429 } else {
1430 ret = ast_asprintf(&topic_name, "channel:%s", chan->uniqueid.unique_id);
1431 }
1432
1433 if (ret < 0) {
1434 return -1;
1435 }
1436
1437 chan->topic = stasis_topic_create(topic_name);
1438 ast_free(topic_name);
1439 if (!chan->topic) {
1440 return -1;
1441 }
1442
1445 if (!chan->channel_forward) {
1446 ao2_ref(chan->topic, -1);
1447 chan->topic = NULL;
1448 return -1;
1449 }
1450
1451 return 0;
1452}
#define ast_free(a)
Definition: astmm.h:180
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition: astmm.h:267
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
struct stasis_topic * ast_channel_topic(struct ast_channel *chan)
A topic which publishes the events for a particular channel.
struct stasis_topic * ast_channel_topic_all(void)
A topic which publishes the events for all channels.
struct stasis_topic * stasis_topic_create(const char *name)
Create a new topic.
Definition: stasis.c:644
struct stasis_forward * stasis_forward_all(struct stasis_topic *from_topic, struct stasis_topic *to_topic)
Create a subscription which forwards all messages from one topic to another.
Definition: stasis.c:1605
#define ast_assert(a)
Definition: utils.h:739

References ao2_ref, ast_asprintf, ast_assert, ast_atomic_fetchadd_int(), ast_channel_topic(), ast_channel_topic_all(), ast_free, ast_strlen_zero(), ast_channel::channel_forward, NULL, stasis_forward_all(), stasis_topic_create(), ast_channel::topic, ast_channel_id::unique_id, and ast_channel::uniqueid.

Referenced by __ast_channel_alloc_ap(), and __ast_dummy_channel_alloc().

◆ ast_channel_internal_swap_stream_topology()

void ast_channel_internal_swap_stream_topology ( struct ast_channel chan1,
struct ast_channel chan2 
)

Definition at line 1521 of file channel_internal_api.c.

1523{
1524 struct ast_stream_topology *tmp_topology;
1525
1526 ast_assert(chan1 != NULL && chan2 != NULL);
1527
1528 tmp_topology = chan1->stream_topology;
1529 chan1->stream_topology = chan2->stream_topology;
1530 chan2->stream_topology = tmp_topology;
1531
1534}

References ast_assert, channel_set_default_streams(), NULL, and ast_channel::stream_topology.

Referenced by channel_do_masquerade().

◆ ast_channel_open_storage()

int ast_channel_open_storage ( void  )

Definition at line 7957 of file channel.c.

7958{
7961 if (rc) {
7962 ast_log(LOG_ERROR, "No channel storage backends available\n");
7963 return -1;
7964 }
7965 }
7966
7970 ast_log(LOG_ERROR, "Failed to open channel storage driver '%s'\n",
7972 return -1;
7973 }
7974
7975 return 0;
7976}
int internal_channel_set_current_storage_driver(const char *driver_name)
Definition: channel.c:7984
const struct ast_channelstorage_driver * current_channel_storage_driver
The current channel storage driver.
struct ast_channelstorage_instance * ast_channelstorage_open(const struct ast_channelstorage_driver *storage_driver, const char *instance_name)
#define AST_CHANNELSTORAGE_DEFAULT_TYPE

References AST_CHANNELSTORAGE_DEFAULT_TYPE, ast_channelstorage_open(), ast_log, current_channel_storage_driver, current_channel_storage_instance, ast_channelstorage_driver::driver_name, internal_channel_set_current_storage_driver(), and LOG_ERROR.

Referenced by ast_channels_init().

Variable Documentation

◆ current_channel_storage_driver

const struct ast_channelstorage_driver* current_channel_storage_driver
extern

◆ current_channel_storage_instance

struct ast_channelstorage_instance* current_channel_storage_instance
extern