Asterisk - The Open Source Telephony Project GIT-master-7e7a603
max_forwards.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2015, Digium, Inc.
5 *
6 * Mark Michelson <mmichelson@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not mfrectly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, mfstributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19#include "asterisk.h"
20
22#include "asterisk/channel.h"
23
24#define DEFAULT_MAX_FORWARDS 20
25
26/*!
27 * \brief Channel datastore data for max forwards
28 */
30 /*! The starting count. Used to allow resetting to the original value */
32 /*! The current count. When this reaches 0, you're outta luck */
34};
35
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}
50
51static void *max_forwards_duplicate(void *data)
52{
53 struct max_forwards *mf = data;
54
56}
57
58static void max_forwards_destroy(void *data)
59{
60 ast_free(data);
61}
62
64 .type = "mfaled-interface",
65 .duplicate = max_forwards_duplicate,
66 .destroy = max_forwards_destroy,
67};
68
70 int starting_count)
71{
72 struct ast_datastore *mf_datastore;
73 struct max_forwards *mf;
74
76 if (!mf_datastore) {
77 return NULL;
78 }
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}
92
94{
95 struct ast_datastore *mf_datastore;
96
98 if (!mf_datastore) {
100 }
101
102 return mf_datastore;
103}
104
105int ast_max_forwards_set(struct ast_channel *chan, int starting_count)
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}
120
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}
134
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}
150
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;
163
164 return 0;
165}
Asterisk main include file. File version handling, generic pbx functions.
#define ast_free(a)
Definition: astmm.h:180
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:191
General Asterisk PBX channel definitions.
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2385
#define DATASTORE_INHERIT_FOREVER
Definition: channel.h:192
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:2399
#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
static struct ast_datastore * max_forwards_datastore_alloc(struct ast_channel *chan, int starting_count)
Definition: max_forwards.c:69
static void max_forwards_destroy(void *data)
Definition: max_forwards.c:58
const struct ast_datastore_info max_forwards_info
Definition: max_forwards.c:63
static void * max_forwards_duplicate(void *data)
Definition: max_forwards.c:51
#define DEFAULT_MAX_FORWARDS
Definition: max_forwards.c:24
static struct max_forwards * max_forwards_alloc(int starting_count, int current_count)
Definition: max_forwards.c:36
int ast_max_forwards_decrement(struct ast_channel *chan)
Decrement the max forwards count for a particular channel.
Definition: max_forwards.c:135
int ast_max_forwards_get(struct ast_channel *chan)
Get the current max forwards for a particular channel.
Definition: max_forwards.c:121
int ast_max_forwards_set(struct ast_channel *chan, int starting_count)
Set the starting max forwards for a particular channel.
Definition: max_forwards.c:105
int ast_max_forwards_reset(struct ast_channel *chan)
Reset the max forwards on a channel to its starting value.
Definition: max_forwards.c:151
static struct ast_datastore * max_forwards_datastore_find_or_alloc(struct ast_channel *chan)
Definition: max_forwards.c:93
#define NULL
Definition: resample.c:96
Main Channel structure associated with a channel.
Structure for a data store type.
Definition: datastore.h:31
const char * type
Definition: datastore.h:32
Structure for a data store object.
Definition: datastore.h:64
void * data
Definition: datastore.h:66
unsigned int inheritance
Definition: datastore.h:69
Channel datastore data for max forwards.
Definition: max_forwards.c:29
int starting_count
Definition: max_forwards.c:31