FreeSWITCH API Documentation  1.7.0
Functions
switch_limit.c File Reference
#include <switch.h>
#include <switch_module_interfaces.h>
+ Include dependency graph for switch_limit.c:

Go to the source code of this file.

Functions

static switch_limit_interface_tget_backend (const char *backend)
 
static void release_backend (switch_limit_interface_t *limit)
 
void switch_limit_init (switch_memory_pool_t *pool)
 Initilize the LIMIT Core System. More...
 
void switch_limit_fire_event (const char *backend, const char *realm, const char *key, uint32_t usage, uint32_t rate, uint32_t max, uint32_t ratemax)
 fire event for limit usage More...
 
static switch_status_t limit_state_handler (switch_core_session_t *session)
 
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. More...
 
switch_status_t switch_limit_release (const char *backend, switch_core_session_t *session, const char *realm, const char *resource)
 Release resource. More...
 
int switch_limit_usage (const char *backend, const char *realm, const char *resource, uint32_t *rcount)
 get usage count for resource More...
 
switch_status_t switch_limit_reset (const char *backend)
 reset all usage counters More...
 
switch_status_t switch_limit_interval_reset (const char *backend, const char *realm, const char *resource)
 reset interval usage counter for a given resource More...
 
char * switch_limit_status (const char *backend)
 retrieve arbitrary status information More...
 

Function Documentation

static switch_limit_interface_t* get_backend ( const char *  backend)
static

Definition at line 35 of file switch_limit.c.

References SWITCH_CHANNEL_LOG, switch_loadable_module_get_limit_interface(), SWITCH_LOG_DEBUG, and switch_log_printf().

Referenced by switch_limit_incr(), switch_limit_interval_reset(), switch_limit_release(), switch_limit_reset(), switch_limit_status(), and switch_limit_usage().

35  {
36  switch_limit_interface_t *limit = NULL;
37 
38  if (!backend) {
39  return NULL;
40  }
41 
42  if (!(limit = switch_loadable_module_get_limit_interface(backend))) {
43  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unable to locate limit backend: %s\n", backend);
44  }
45 
46  return limit;
47 }
Abstract interface to a limit module.
#define SWITCH_CHANNEL_LOG
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_limit_interface_t * switch_loadable_module_get_limit_interface(const char *name)
Retrieve the limit interface by it's registered name.
static switch_status_t limit_state_handler ( switch_core_session_t session)
static

Definition at line 78 of file switch_limit.c.

References CS_HANGUP, CS_ROUTING, LIMIT_BACKEND_VARIABLE, LIMIT_IGNORE_TRANSFER_VARIABLE, switch_channel_get_state(), switch_channel_get_variable, SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_variable, switch_core_session_get_channel(), switch_limit_release(), SWITCH_LOG_DEBUG, switch_log_printf(), switch_separate_string(), SWITCH_STATUS_SUCCESS, switch_true(), and zstr.

Referenced by switch_limit_incr().

79 {
83  const char *backendlist = switch_channel_get_variable(channel, LIMIT_BACKEND_VARIABLE);
84 
85  if (zstr(backendlist)) {
86  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Unset limit backendlist!\n");
87  return SWITCH_STATUS_SUCCESS;
88  }
89 
90  if (state >= CS_HANGUP || (state == CS_ROUTING && !switch_true(vval))) {
91  int argc = 0;
92  char *argv[6] = { 0 };
93  char *mydata = strdup(backendlist);
94  int x;
95 
96  argc = switch_separate_string(mydata, ',', argv, (sizeof(argv) / sizeof(argv[0])));
97  for (x = 0; x < argc; x++) {
98  switch_limit_release(argv[x], session, NULL, NULL);
99  }
100  switch_core_event_hook_remove_state_change(session, limit_state_handler);
101  /* Remove limit_backend variable so we register another hook if limit is called again */
103 
104  free(mydata);
105  }
106 
107  return SWITCH_STATUS_SUCCESS;
108 }
switch_channel_state_t switch_channel_get_state(switch_channel_t *channel)
Get the current state of a channel in the state engine.
#define SWITCH_CHANNEL_SESSION_LOG(x)
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
static int switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:450
#define zstr(x)
Definition: switch_utils.h:281
#define LIMIT_IGNORE_TRANSFER_VARIABLE
Definition: switch_limit.h:120
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
unsigned int switch_separate_string(_In_ char *buf, char delim, _Post_count_(return) char **array, unsigned int arraylen)
Separate a string into an array based on a character delimiter.
#define switch_channel_get_variable(_c, _v)
switch_channel_state_t
Channel States (these are the defaults, CS_SOFT_EXECUTE, CS_EXCHANGE_MEDIA, and CS_CONSUME_MEDIA are ...
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
#define LIMIT_BACKEND_VARIABLE
Definition: switch_limit.h:121
#define switch_channel_set_variable(_channel, _var, _val)
static switch_status_t limit_state_handler(switch_core_session_t *session)
Definition: switch_limit.c:78
static void release_backend ( switch_limit_interface_t limit)
static

Definition at line 49 of file switch_limit.c.

References UNPROTECT_INTERFACE.

Referenced by switch_limit_incr(), switch_limit_interval_reset(), switch_limit_release(), switch_limit_reset(), switch_limit_status(), and switch_limit_usage().

49  {
50  if (limit) {
51  UNPROTECT_INTERFACE(limit);
52  }
53 }
#define UNPROTECT_INTERFACE(_it)