mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-24 21:22:09 +00:00
sync changes in branch rupa_limit
This commit is contained in:
@@ -133,6 +133,7 @@
|
||||
#include "switch_nat.h"
|
||||
#include "switch_odbc.h"
|
||||
#include "switch_json.h"
|
||||
#include "switch_limit.h"
|
||||
|
||||
#include <libteletone.h>
|
||||
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||
* Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
* Version: MPL 1.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Anthony Minessale II <anthm@freeswitch.org>
|
||||
* Portions created by the Initial Developer are Copyright (C)
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Rupa Schomaker <rupa@rupa.com>
|
||||
*
|
||||
* switch_limit.h - Limit generic implementations
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\defgroup limit1 LIMIT code
|
||||
\ingroup core1
|
||||
\{
|
||||
*/
|
||||
#ifndef _SWITCH_LIMIT_H
|
||||
#define _SWITCH_LIMIT_H
|
||||
|
||||
SWITCH_BEGIN_EXTERN_C
|
||||
|
||||
/*!
|
||||
\brief Initilize the LIMIT Core System
|
||||
\param pool the memory pool to use for long term allocations
|
||||
\note Generally called by the core_init
|
||||
*/
|
||||
SWITCH_DECLARE(void) switch_limit_init(switch_memory_pool_t *pool);
|
||||
|
||||
/*!
|
||||
\brief Increment resource.
|
||||
\param backend to use
|
||||
\param realm
|
||||
\param resource
|
||||
\param max - 0 means no limit, just count
|
||||
\param interval - 0 means no interval
|
||||
\return true/false - true ok, false over limit
|
||||
*/
|
||||
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);
|
||||
|
||||
/*!
|
||||
\brief Release resource.
|
||||
\param backend to use
|
||||
\param realm
|
||||
\param resource
|
||||
\return true/false - true ok, false over limit
|
||||
*/
|
||||
SWITCH_DECLARE(switch_status_t) switch_limit_release(const char *backend, switch_core_session_t *session, const char *realm, const char *resource);
|
||||
|
||||
/*!
|
||||
\brief get usage count for resource
|
||||
\param backend to use
|
||||
\param realm
|
||||
\param resource
|
||||
\param rcount - output paramter, rate counter
|
||||
*/
|
||||
SWITCH_DECLARE(int) switch_limit_usage(const char *backend, const char *realm, const char *resource, uint32_t *rcount);
|
||||
|
||||
/*!
|
||||
\brief reset all usage counters
|
||||
\param backend to use
|
||||
*/
|
||||
SWITCH_DECLARE(switch_status_t) switch_limit_reset(const char *backend);
|
||||
|
||||
/*!
|
||||
\brief fire event for limit usage
|
||||
\param backend to use
|
||||
\param realm
|
||||
\param resource
|
||||
\param usage
|
||||
\param rate
|
||||
\param max
|
||||
\param ratemax
|
||||
*/
|
||||
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);
|
||||
|
||||
/*!
|
||||
\brief retrieve arbitrary status information
|
||||
\param backend to use
|
||||
\note caller must free returned value
|
||||
*/
|
||||
SWITCH_DECLARE(char *) switch_limit_status(const char *backend);
|
||||
|
||||
/*! callback to init a backend */
|
||||
#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)
|
||||
#define SWITCH_LIMIT_RELEASE(name) static switch_status_t name (switch_core_session_t *session, const char *realm, const char *resource)
|
||||
#define SWITCH_LIMIT_USAGE(name) static int name (const char *realm, const char *resource, uint32_t *rcount)
|
||||
#define SWITCH_LIMIT_RESET(name) static switch_status_t name (void)
|
||||
#define SWITCH_LIMIT_STATUS(name) static char * name (void)
|
||||
|
||||
#define LIMIT_IGNORE_TRANSFER_VARIABLE "limit_ignore_transfer"
|
||||
#define LIMIT_BACKEND_VARIABLE "limit_backend"
|
||||
#define LIMIT_EVENT_USAGE "limit::usage"
|
||||
#define LIMIT_DEF_XFER_EXTEN "limit_exceeded"
|
||||
|
||||
SWITCH_END_EXTERN_C
|
||||
#endif
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
||||
*/
|
||||
@@ -81,6 +81,8 @@ SWITCH_BEGIN_EXTERN_C
|
||||
switch_asr_interface_t *asr_interface;
|
||||
/*! the table of management interfaces the module has implmented */
|
||||
switch_management_interface_t *management_interface;
|
||||
/*! the table of limit interfaces the module has implmented */
|
||||
switch_limit_interface_t *limit_interface;
|
||||
switch_thread_rwlock_t *rwlock;
|
||||
int refs;
|
||||
switch_memory_pool_t *pool;
|
||||
@@ -204,6 +206,13 @@ SWITCH_DECLARE(switch_say_interface_t *) switch_loadable_module_get_say_interfac
|
||||
*/
|
||||
SWITCH_DECLARE(switch_management_interface_t *) switch_loadable_module_get_management_interface(const char *relative_oid);
|
||||
|
||||
/*!
|
||||
\brief Retrieve the limit interface by it's registered name
|
||||
\param name the name of the limit interface
|
||||
\return the desired limit interface
|
||||
*/
|
||||
SWITCH_DECLARE(switch_limit_interface_t *) switch_loadable_module_get_limit_interface(const char *name);
|
||||
|
||||
/*!
|
||||
\brief Retrieve the list of loaded codecs into an array
|
||||
\param array the array to populate
|
||||
@@ -315,6 +324,18 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void);
|
||||
break; \
|
||||
}
|
||||
|
||||
#define SWITCH_ADD_LIMIT(limit_int, int_name, incrptr, releaseptr, usageptr, resetptr, statusptr) \
|
||||
for (;;) { \
|
||||
limit_int = (switch_limit_interface_t *)switch_loadable_module_create_interface(*module_interface, SWITCH_LIMIT_INTERFACE); \
|
||||
limit_int->incr = incrptr; \
|
||||
limit_int->release = releaseptr; \
|
||||
limit_int->usage = usageptr; \
|
||||
limit_int->reset = resetptr; \
|
||||
limit_int->status = statusptr; \
|
||||
limit_int->interface_name = int_name; \
|
||||
break; \
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(uint32_t) switch_core_codec_next_id(void);
|
||||
|
||||
#define SWITCH_ADD_CODEC(codec_int, int_name) \
|
||||
|
||||
@@ -512,6 +512,28 @@ struct switch_management_interface {
|
||||
struct switch_management_interface *next;
|
||||
};
|
||||
|
||||
/*! \brief Abstract interface to a limit module */
|
||||
struct switch_limit_interface {
|
||||
/*! name of the interface */
|
||||
const char *interface_name;
|
||||
/*! increment */
|
||||
switch_status_t (*incr) (switch_core_session_t *session, const char *realm, const char *resource, const int max, const int interval);
|
||||
/*! release */
|
||||
switch_status_t (*release) (switch_core_session_t *session, const char *realm, const char *resource);
|
||||
/*! usage for resource */
|
||||
int (*usage) (const char *realm, const char *resource, uint32_t *rcount);
|
||||
/*! reset counters */
|
||||
switch_status_t (*reset) (void);
|
||||
/*! freform status */
|
||||
char * (*status) (void);
|
||||
/* internal */
|
||||
switch_thread_rwlock_t *rwlock;
|
||||
int refs;
|
||||
switch_mutex_t *reflock;
|
||||
switch_loadable_module_interface_t *parent;
|
||||
struct switch_limit_interface *next;
|
||||
};
|
||||
|
||||
/*! \brief Abstract interface to a directory module */
|
||||
struct switch_directory_interface {
|
||||
/*! the name of the interface */
|
||||
|
||||
@@ -267,7 +267,8 @@ typedef enum {
|
||||
SWITCH_CHAT_INTERFACE,
|
||||
SWITCH_SAY_INTERFACE,
|
||||
SWITCH_ASR_INTERFACE,
|
||||
SWITCH_MANAGEMENT_INTERFACE
|
||||
SWITCH_MANAGEMENT_INTERFACE,
|
||||
SWITCH_LIMIT_INTERFACE
|
||||
} switch_module_interface_name_t;
|
||||
|
||||
typedef enum {
|
||||
@@ -1593,6 +1594,7 @@ typedef struct switch_chat_interface switch_chat_interface_t;
|
||||
typedef struct switch_management_interface switch_management_interface_t;
|
||||
typedef struct switch_core_port_allocator switch_core_port_allocator_t;
|
||||
typedef struct switch_media_bug switch_media_bug_t;
|
||||
typedef struct switch_limit_interface switch_limit_interface_t;
|
||||
|
||||
struct switch_console_callback_match_node {
|
||||
char *val;
|
||||
|
||||
Reference in New Issue
Block a user