FreeSWITCH API Documentation  1.7.0
switch_limit.h
Go to the documentation of this file.
1 /*
2  * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
3  * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
4  *
5  * Version: MPL 1.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
18  *
19  * The Initial Developer of the Original Code is
20  * Anthony Minessale II <anthm@freeswitch.org>
21  * Portions created by the Initial Developer are Copyright (C)
22  * the Initial Developer. All Rights Reserved.
23  *
24  * Contributor(s):
25  *
26  * Rupa Schomaker <rupa@rupa.com>
27  *
28  * switch_limit.h - Limit generic implementations
29  *
30  */
31 
32 
33  /*!
34  \defgroup limit1 LIMIT code
35  \ingroup core1
36  \{
37 */
38 #ifndef _SWITCH_LIMIT_H
39 #define _SWITCH_LIMIT_H
40 
42 
43 /*!
44  \brief Initilize the LIMIT Core System
45  \param pool the memory pool to use for long term allocations
46  \note Generally called by the core_init
47 */
49 
50 /*!
51  \brief Increment resource.
52  \param backend to use
53  \param realm
54  \param resource
55  \param max - 0 means no limit, just count
56  \param interval - 0 means no interval
57  \return true/false - true ok, false over limit
58 */
59 SWITCH_DECLARE(switch_status_t) switch_limit_incr(const char *backend, switch_core_session_t *session, const char *realm, const char *resource, const int max, const int interval);
60 
61 /*!
62  \brief Release resource.
63  \param backend to use
64  \param realm
65  \param resource
66  \return true/false - true ok, false over limit
67 */
68 SWITCH_DECLARE(switch_status_t) switch_limit_release(const char *backend, switch_core_session_t *session, const char *realm, const char *resource);
69 
70 /*!
71  \brief get usage count for resource
72  \param backend to use
73  \param realm
74  \param resource
75  \param rcount - output paramter, rate counter
76 */
77 SWITCH_DECLARE(int) switch_limit_usage(const char *backend, const char *realm, const char *resource, uint32_t *rcount);
78 
79 /*!
80  \brief reset interval usage counter for a given resource
81  \param backend
82  \param realm
83  \param resource
84 */
85 SWITCH_DECLARE(switch_status_t) switch_limit_interval_reset(const char *backend, const char *realm, const char *resource);
86 
87 /*!
88  \brief reset all usage counters
89  \param backend to use
90 */
92 
93 /*!
94  \brief fire event for limit usage
95  \param backend to use
96  \param realm
97  \param resource
98  \param usage
99  \param rate
100  \param max
101  \param ratemax
102 */
103 SWITCH_DECLARE(void) switch_limit_fire_event(const char *backend, const char *realm, const char *resource, uint32_t usage, uint32_t rate, uint32_t max, uint32_t ratemax);
104 
105 /*!
106  \brief retrieve arbitrary status information
107  \param backend to use
108  \note caller must free returned value
109 */
110 SWITCH_DECLARE(char *) switch_limit_status(const char *backend);
111 
112 /*! callback to init a backend */
113 #define SWITCH_LIMIT_INCR(name) static switch_status_t name (switch_core_session_t *session, const char *realm, const char *resource, const int max, const int interval)
114 #define SWITCH_LIMIT_RELEASE(name) static switch_status_t name (switch_core_session_t *session, const char *realm, const char *resource)
115 #define SWITCH_LIMIT_USAGE(name) static int name (const char *realm, const char *resource, uint32_t *rcount)
116 #define SWITCH_LIMIT_RESET(name) static switch_status_t name (void)
117 #define SWITCH_LIMIT_INTERVAL_RESET(name) static switch_status_t name (const char *realm, const char *resource)
118 #define SWITCH_LIMIT_STATUS(name) static char * name (void)
119 
120 #define LIMIT_IGNORE_TRANSFER_VARIABLE "limit_ignore_transfer"
121 #define LIMIT_BACKEND_VARIABLE "limit_backend"
122 #define LIMIT_EVENT_USAGE "limit::usage"
123 #define LIMIT_DEF_XFER_EXTEN "limit_exceeded"
124 
126 #endif
127 /* For Emacs:
128  * Local Variables:
129  * mode:c
130  * indent-tabs-mode:t
131  * tab-width:4
132  * c-basic-offset:4
133  * End:
134  * For VIM:
135  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
136  */
#define SWITCH_END_EXTERN_C
Definition: switch.h:43
switch_status_t switch_limit_interval_reset(const char *backend, const char *realm, const char *resource)
reset interval usage counter for a given resource
Definition: switch_limit.c:199
switch_memory_pool_t * pool
char * switch_limit_status(const char *backend)
retrieve arbitrary status information
Definition: switch_limit.c:221
switch_status_t switch_limit_release(const char *backend, switch_core_session_t *session, const char *realm, const char *resource)
Release resource.
Definition: switch_limit.c:148
switch_status_t switch_limit_reset(const char *backend)
reset all usage counters
Definition: switch_limit.c:182
switch_status_t switch_limit_incr(const char *backend, switch_core_session_t *session, const char *realm, const char *resource, const int max, const int interval)
Increment resource.
Definition: switch_limit.c:111
static const char usage[]
Definition: switch.c:409
void switch_limit_fire_event(const char *backend, const char *realm, const char *resource, uint32_t usage, uint32_t rate, uint32_t max, uint32_t ratemax)
fire event for limit usage
Definition: switch_limit.c:62
SWITCH_BEGIN_EXTERN_C void switch_limit_init(switch_memory_pool_t *pool)
Initilize the LIMIT Core System.
Definition: switch_limit.c:55
int switch_limit_usage(const char *backend, const char *realm, const char *resource, uint32_t *rcount)
get usage count for resource
Definition: switch_limit.c:165
switch_status_t
Common return values.
#define SWITCH_DECLARE(type)
struct apr_pool_t switch_memory_pool_t
#define SWITCH_BEGIN_EXTERN_C
Definition: switch.h:42