Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Functions | Variables
max_forwards.c File Reference
#include "asterisk.h"
#include "asterisk/max_forwards.h"
#include "asterisk/channel.h"
Include dependency graph for max_forwards.c:

Go to the source code of this file.

Data Structures

struct  max_forwards
 Channel datastore data for max forwards. More...
 

Macros

#define DEFAULT_MAX_FORWARDS   20
 

Functions

int ast_max_forwards_decrement (struct ast_channel *chan)
 Decrement the max forwards count for a particular channel. More...
 
int ast_max_forwards_get (struct ast_channel *chan)
 Get the current max forwards for a particular channel. More...
 
int ast_max_forwards_reset (struct ast_channel *chan)
 Reset the max forwards on a channel to its starting value. More...
 
int ast_max_forwards_set (struct ast_channel *chan, int starting_count)
 Set the starting max forwards for a particular channel. More...
 
static struct max_forwardsmax_forwards_alloc (int starting_count, int current_count)
 
static struct ast_datastoremax_forwards_datastore_alloc (struct ast_channel *chan, int starting_count)
 
static struct ast_datastoremax_forwards_datastore_find_or_alloc (struct ast_channel *chan)
 
static void max_forwards_destroy (void *data)
 
static void * max_forwards_duplicate (void *data)
 

Variables

const struct ast_datastore_info max_forwards_info
 

Macro Definition Documentation

◆ DEFAULT_MAX_FORWARDS

#define DEFAULT_MAX_FORWARDS   20

Definition at line 24 of file max_forwards.c.

Referenced by max_forwards_datastore_find_or_alloc().

Function Documentation

◆ ast_max_forwards_decrement()

int ast_max_forwards_decrement ( struct ast_channel chan)

Decrement the max forwards count for a particular channel.

If the channel has not had max forwards set on it, then the channel will have the default max forwards set on it and that value will not be decremented.

Precondition
chan is locked

The channel for which the max forwards value should be decremented

Return values
0Success
-1Failure

Definition at line 135 of file max_forwards.c.

References max_forwards::current_count, ast_datastore::data, and max_forwards_datastore_find_or_alloc().

Referenced by __ast_request_and_dial(), ast_ari_channels_dial(), begin_dial_prerun(), call_forward_inherit(), dial_exec_full(), do_forward(), findmeexec(), ring_entry(), and wait_for_answer().

136 {
137  struct ast_datastore *mf_datastore;
138  struct max_forwards *mf;
139 
140  mf_datastore = max_forwards_datastore_find_or_alloc(chan);
141  if (!mf_datastore) {
142  return -1;
143  }
144 
145  mf = mf_datastore->data;
146  --mf->current_count;
147 
148  return 0;
149 }
Structure for a data store object.
Definition: datastore.h:68
Channel datastore data for max forwards.
Definition: max_forwards.c:29
void * data
Definition: datastore.h:70
static struct ast_datastore * max_forwards_datastore_find_or_alloc(struct ast_channel *chan)
Definition: max_forwards.c:93

◆ ast_max_forwards_get()

int ast_max_forwards_get ( struct ast_channel chan)

Get the current max forwards for a particular channel.

If the channel has not had max forwards set on it, then the channel will have the default max forwards set on it and that value will be returned.

Precondition
chan is locked
Parameters
chanThe channel to get the max forwards for.
Returns
The current max forwards count on the channel

Definition at line 121 of file max_forwards.c.

References max_forwards::current_count, ast_datastore::data, and max_forwards_datastore_find_or_alloc().

Referenced by app_exec(), begin_dial_prerun(), dial_exec_full(), func_channel_read(), and queue_exec().

122 {
123  struct ast_datastore *mf_datastore;
124  struct max_forwards *mf;
125 
126  mf_datastore = max_forwards_datastore_find_or_alloc(chan);
127  if (!mf_datastore) {
128  return -1;
129  }
130 
131  mf = mf_datastore->data;
132  return mf->current_count;
133 }
Structure for a data store object.
Definition: datastore.h:68
Channel datastore data for max forwards.
Definition: max_forwards.c:29
void * data
Definition: datastore.h:70
static struct ast_datastore * max_forwards_datastore_find_or_alloc(struct ast_channel *chan)
Definition: max_forwards.c:93

◆ ast_max_forwards_reset()

int ast_max_forwards_reset ( struct ast_channel chan)

Reset the max forwards on a channel to its starting value.

If the channel has not had max forwards set on it, then the channel will have the default max forwards set on it.

Precondition
chan is locked.
Parameters
chanThe channel on which to reset the max forwards count.
Return values
0Success
-1Failure

Definition at line 151 of file max_forwards.c.

References max_forwards::current_count, ast_datastore::data, max_forwards_datastore_find_or_alloc(), and max_forwards::starting_count.

Referenced by pre_bridge_setup().

152 {
153  struct ast_datastore *mf_datastore;
154  struct max_forwards *mf;
155 
156  mf_datastore = max_forwards_datastore_find_or_alloc(chan);
157  if (!mf_datastore) {
158  return -1;
159  }
160 
161  mf = mf_datastore->data;
162  mf->current_count = mf->starting_count;
163 
164  return 0;
165 }
int starting_count
Definition: max_forwards.c:31
Structure for a data store object.
Definition: datastore.h:68
Channel datastore data for max forwards.
Definition: max_forwards.c:29
void * data
Definition: datastore.h:70
static struct ast_datastore * max_forwards_datastore_find_or_alloc(struct ast_channel *chan)
Definition: max_forwards.c:93

◆ ast_max_forwards_set()

int ast_max_forwards_set ( struct ast_channel chan,
int  starting_count 
)

Set the starting max forwards for a particular channel.

Precondition
chan is locked
Parameters
starting_countThe value to set the max forwards to.
chanThe channel on which to set the max forwards.
Return values
0Success
1Failure

Definition at line 105 of file max_forwards.c.

References max_forwards::current_count, ast_datastore::data, max_forwards_datastore_find_or_alloc(), and max_forwards::starting_count.

Referenced by func_channel_write_real().

106 {
107  struct ast_datastore *mf_datastore;
108  struct max_forwards *mf;
109 
110  mf_datastore = max_forwards_datastore_find_or_alloc(chan);
111  if (!mf_datastore) {
112  return -1;
113  }
114 
115  mf = mf_datastore->data;
117 
118  return 0;
119 }
int starting_count
Definition: max_forwards.c:31
Structure for a data store object.
Definition: datastore.h:68
Channel datastore data for max forwards.
Definition: max_forwards.c:29
void * data
Definition: datastore.h:70
static struct ast_datastore * max_forwards_datastore_find_or_alloc(struct ast_channel *chan)
Definition: max_forwards.c:93

◆ max_forwards_alloc()

static struct max_forwards* max_forwards_alloc ( int  starting_count,
int  current_count 
)
static

Definition at line 36 of file max_forwards.c.

References ast_malloc, max_forwards::current_count, NULL, and max_forwards::starting_count.

Referenced by max_forwards_datastore_alloc(), and max_forwards_duplicate().

37 {
38  struct max_forwards *mf;
39 
40  mf = ast_malloc(sizeof(*mf));
41  if (!mf) {
42  return NULL;
43  }
44 
47 
48  return mf;
49 }
int starting_count
Definition: max_forwards.c:31
#define NULL
Definition: resample.c:96
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
Channel datastore data for max forwards.
Definition: max_forwards.c:29

◆ max_forwards_datastore_alloc()

static struct ast_datastore* max_forwards_datastore_alloc ( struct ast_channel chan,
int  starting_count 
)
static

Definition at line 69 of file max_forwards.c.

References ast_channel_datastore_add(), ast_datastore_alloc, ast_datastore_free(), ast_datastore::data, DATASTORE_INHERIT_FOREVER, ast_datastore::inheritance, max_forwards_alloc(), and NULL.

Referenced by max_forwards_datastore_find_or_alloc().

71 {
72  struct ast_datastore *mf_datastore;
73  struct max_forwards *mf;
74 
75  mf_datastore = ast_datastore_alloc(&max_forwards_info, NULL);
76  if (!mf_datastore) {
77  return NULL;
78  }
79  mf_datastore->inheritance = DATASTORE_INHERIT_FOREVER;
80 
82  if (!mf) {
83  ast_datastore_free(mf_datastore);
84  return NULL;
85  }
86  mf_datastore->data = mf;
87 
88  ast_channel_datastore_add(chan, mf_datastore);
89 
90  return mf_datastore;
91 }
int starting_count
Definition: max_forwards.c:31
Structure for a data store object.
Definition: datastore.h:68
#define NULL
Definition: resample.c:96
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition: datastore.c:68
static struct max_forwards * max_forwards_alloc(int starting_count, int current_count)
Definition: max_forwards.c:36
Channel datastore data for max forwards.
Definition: max_forwards.c:29
#define DATASTORE_INHERIT_FOREVER
Definition: channel.h:193
unsigned int inheritance
Definition: datastore.h:73
void * data
Definition: datastore.h:70
const struct ast_datastore_info max_forwards_info
Definition: max_forwards.c:63
#define ast_datastore_alloc(info, uid)
Definition: datastore.h:89
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2390

◆ max_forwards_datastore_find_or_alloc()

static struct ast_datastore* max_forwards_datastore_find_or_alloc ( struct ast_channel chan)
static

Definition at line 93 of file max_forwards.c.

References ast_channel_datastore_find(), DEFAULT_MAX_FORWARDS, max_forwards_datastore_alloc(), and NULL.

Referenced by ast_max_forwards_decrement(), ast_max_forwards_get(), ast_max_forwards_reset(), and ast_max_forwards_set().

94 {
95  struct ast_datastore *mf_datastore;
96 
97  mf_datastore = ast_channel_datastore_find(chan, &max_forwards_info, NULL);
98  if (!mf_datastore) {
100  }
101 
102  return mf_datastore;
103 }
#define DEFAULT_MAX_FORWARDS
Definition: max_forwards.c:24
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
static struct ast_datastore * max_forwards_datastore_alloc(struct ast_channel *chan, int starting_count)
Definition: max_forwards.c:69
const struct ast_datastore_info max_forwards_info
Definition: max_forwards.c:63

◆ max_forwards_destroy()

static void max_forwards_destroy ( void *  data)
static

Definition at line 58 of file max_forwards.c.

References ast_free.

59 {
60  ast_free(data);
61 }
#define ast_free(a)
Definition: astmm.h:182
void * data
Definition: datastore.h:70

◆ max_forwards_duplicate()

static void* max_forwards_duplicate ( void *  data)
static

Definition at line 51 of file max_forwards.c.

References max_forwards::current_count, max_forwards_alloc(), and max_forwards::starting_count.

52 {
53  struct max_forwards *mf = data;
54 
56 }
int starting_count
Definition: max_forwards.c:31
static struct max_forwards * max_forwards_alloc(int starting_count, int current_count)
Definition: max_forwards.c:36
Channel datastore data for max forwards.
Definition: max_forwards.c:29

Variable Documentation

◆ max_forwards_info

const struct ast_datastore_info max_forwards_info
Initial value:
= {
.type = "mfaled-interface",
.duplicate = max_forwards_duplicate,
}
static void max_forwards_destroy(void *data)
Definition: max_forwards.c:58
static void * max_forwards_duplicate(void *data)
Definition: max_forwards.c:51

Definition at line 63 of file max_forwards.c.