2007-04-28 21:01:44 +00:00
|
|
|
/*
|
|
|
|
* Asterisk -- An open source telephony toolkit.
|
|
|
|
*
|
2008-06-10 14:53:40 +00:00
|
|
|
* Copyright (C) 2007 - 2008, Digium, Inc.
|
2007-04-28 21:01:44 +00:00
|
|
|
*
|
|
|
|
* Russell Bryant <russell@digium.com>
|
|
|
|
*
|
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \file
|
|
|
|
*
|
|
|
|
* \brief Internal generic event system
|
|
|
|
*
|
2008-01-11 23:09:31 +00:00
|
|
|
* \author Russell Bryant <russell@digium.com>
|
2007-04-28 21:01:44 +00:00
|
|
|
*/
|
|
|
|
|
2012-06-15 16:20:16 +00:00
|
|
|
/*** MODULEINFO
|
|
|
|
<support_level>core</support_level>
|
|
|
|
***/
|
|
|
|
|
2007-04-28 21:01:44 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
2007-11-20 22:18:21 +00:00
|
|
|
#include "asterisk/_private.h"
|
Improve performance of the ast_event cache functionality.
This code comes from svn/asterisk/team/russell/event_performance/.
Here is a summary of the changes that have been made, in order of both
invasiveness and performance impact, from smallest to largest.
1) Asterisk 1.6.1 introduces some additional logic to be able to handle
distributed device state. This functionality comes at a cost.
One relatively minor change in this patch is that the extra processing
required for distributed device state is now completely bypassed if
it's not needed.
2) One of the things that I noticed when profiling this code was that a
_lot_ of time was spent doing string comparisons. I changed the way
strings are represented in an event to include a hash value at the front.
So, before doing a string comparison, we do an integer comparison on the
hash.
3) Finally, the code that handles the event cache has been re-written.
I tried to do this in a such a way that it had minimal impact on the API.
I did have to change one API call, though - ast_event_queue_and_cache().
However, the way it works now is nicer, IMO. Each type of event that
can be cached (MWI, device state) has its own hash table and rules for
hashing and comparing objects. This by far made the biggest impact on
performance.
For additional details regarding this code and how it was tested, please see the
review request.
(closes issue #14738)
Reported by: russell
Review: http://reviewboard.digium.com/r/205/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@184339 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-03-25 21:57:19 +00:00
|
|
|
|
2007-04-28 21:01:44 +00:00
|
|
|
#include "asterisk/event.h"
|
|
|
|
#include "asterisk/linkedlists.h"
|
2008-04-16 20:28:08 +00:00
|
|
|
#include "asterisk/dlinkedlists.h"
|
2007-04-28 21:01:44 +00:00
|
|
|
#include "asterisk/lock.h"
|
|
|
|
#include "asterisk/utils.h"
|
2007-12-11 16:29:29 +00:00
|
|
|
#include "asterisk/unaligned.h"
|
2008-06-10 14:53:40 +00:00
|
|
|
#include "asterisk/utils.h"
|
2008-05-05 22:01:56 +00:00
|
|
|
#include "asterisk/taskprocessor.h"
|
Improve performance of the ast_event cache functionality.
This code comes from svn/asterisk/team/russell/event_performance/.
Here is a summary of the changes that have been made, in order of both
invasiveness and performance impact, from smallest to largest.
1) Asterisk 1.6.1 introduces some additional logic to be able to handle
distributed device state. This functionality comes at a cost.
One relatively minor change in this patch is that the extra processing
required for distributed device state is now completely bypassed if
it's not needed.
2) One of the things that I noticed when profiling this code was that a
_lot_ of time was spent doing string comparisons. I changed the way
strings are represented in an event to include a hash value at the front.
So, before doing a string comparison, we do an integer comparison on the
hash.
3) Finally, the code that handles the event cache has been re-written.
I tried to do this in a such a way that it had minimal impact on the API.
I did have to change one API call, though - ast_event_queue_and_cache().
However, the way it works now is nicer, IMO. Each type of event that
can be cached (MWI, device state) has its own hash table and rules for
hashing and comparing objects. This by far made the biggest impact on
performance.
For additional details regarding this code and how it was tested, please see the
review request.
(closes issue #14738)
Reported by: russell
Review: http://reviewboard.digium.com/r/205/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@184339 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-03-25 21:57:19 +00:00
|
|
|
#include "asterisk/astobj2.h"
|
2010-11-20 00:52:47 +00:00
|
|
|
#include "asterisk/cli.h"
|
2007-04-28 21:01:44 +00:00
|
|
|
|
2007-08-29 19:41:16 +00:00
|
|
|
/*!
|
|
|
|
* \brief An event information element
|
|
|
|
*
|
|
|
|
* \note The format of this structure is important. Since these events may
|
|
|
|
* be sent directly over a network, changing this structure will break
|
|
|
|
* compatibility with older versions. However, at this point, this code
|
|
|
|
* has not made it into a release, so it is still fair game for change.
|
|
|
|
*/
|
2007-04-28 21:01:44 +00:00
|
|
|
struct ast_event_ie {
|
|
|
|
enum ast_event_ie_type ie_type:16;
|
|
|
|
/*! Total length of the IE payload */
|
|
|
|
uint16_t ie_payload_len;
|
|
|
|
unsigned char ie_payload[0];
|
2008-11-29 17:57:39 +00:00
|
|
|
} __attribute__((packed));
|
2007-04-28 21:01:44 +00:00
|
|
|
|
Improve performance of the ast_event cache functionality.
This code comes from svn/asterisk/team/russell/event_performance/.
Here is a summary of the changes that have been made, in order of both
invasiveness and performance impact, from smallest to largest.
1) Asterisk 1.6.1 introduces some additional logic to be able to handle
distributed device state. This functionality comes at a cost.
One relatively minor change in this patch is that the extra processing
required for distributed device state is now completely bypassed if
it's not needed.
2) One of the things that I noticed when profiling this code was that a
_lot_ of time was spent doing string comparisons. I changed the way
strings are represented in an event to include a hash value at the front.
So, before doing a string comparison, we do an integer comparison on the
hash.
3) Finally, the code that handles the event cache has been re-written.
I tried to do this in a such a way that it had minimal impact on the API.
I did have to change one API call, though - ast_event_queue_and_cache().
However, the way it works now is nicer, IMO. Each type of event that
can be cached (MWI, device state) has its own hash table and rules for
hashing and comparing objects. This by far made the biggest impact on
performance.
For additional details regarding this code and how it was tested, please see the
review request.
(closes issue #14738)
Reported by: russell
Review: http://reviewboard.digium.com/r/205/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@184339 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-03-25 21:57:19 +00:00
|
|
|
/*!
|
|
|
|
* \brief The payload for a string information element
|
|
|
|
*/
|
|
|
|
struct ast_event_ie_str_payload {
|
|
|
|
/*! \brief A hash calculated with ast_str_hash(), to speed up comparisons */
|
|
|
|
uint32_t hash;
|
|
|
|
/*! \brief The actual string, null terminated */
|
|
|
|
char str[1];
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2007-04-28 21:01:44 +00:00
|
|
|
/*!
|
|
|
|
* \brief An event
|
|
|
|
*
|
2007-08-29 19:41:16 +00:00
|
|
|
* An ast_event consists of an event header (this structure), and zero or
|
|
|
|
* more information elements defined by ast_event_ie.
|
2007-04-28 21:01:44 +00:00
|
|
|
*
|
2007-08-29 19:41:16 +00:00
|
|
|
* \note The format of this structure is important. Since these events may
|
|
|
|
* be sent directly over a network, changing this structure will break
|
|
|
|
* compatibility with older versions. However, at this point, this code
|
|
|
|
* has not made it into a release, so it is still fair game for change.
|
2007-04-28 21:01:44 +00:00
|
|
|
*/
|
|
|
|
struct ast_event {
|
|
|
|
/*! Event type */
|
|
|
|
enum ast_event_type type:16;
|
|
|
|
/*! Total length of the event */
|
|
|
|
uint16_t event_len:16;
|
|
|
|
/*! The data payload of the event, made up of information elements */
|
|
|
|
unsigned char payload[0];
|
2008-11-29 17:57:39 +00:00
|
|
|
} __attribute__((packed));
|
2007-04-28 21:01:44 +00:00
|
|
|
|
2009-03-25 22:11:35 +00:00
|
|
|
|
2007-04-28 21:01:44 +00:00
|
|
|
struct ast_event_ie_val {
|
|
|
|
AST_LIST_ENTRY(ast_event_ie_val) entry;
|
|
|
|
enum ast_event_ie_type ie_type;
|
|
|
|
enum ast_event_ie_pltype ie_pltype;
|
|
|
|
union {
|
|
|
|
uint32_t uint;
|
Improve performance of the ast_event cache functionality.
This code comes from svn/asterisk/team/russell/event_performance/.
Here is a summary of the changes that have been made, in order of both
invasiveness and performance impact, from smallest to largest.
1) Asterisk 1.6.1 introduces some additional logic to be able to handle
distributed device state. This functionality comes at a cost.
One relatively minor change in this patch is that the extra processing
required for distributed device state is now completely bypassed if
it's not needed.
2) One of the things that I noticed when profiling this code was that a
_lot_ of time was spent doing string comparisons. I changed the way
strings are represented in an event to include a hash value at the front.
So, before doing a string comparison, we do an integer comparison on the
hash.
3) Finally, the code that handles the event cache has been re-written.
I tried to do this in a such a way that it had minimal impact on the API.
I did have to change one API call, though - ast_event_queue_and_cache().
However, the way it works now is nicer, IMO. Each type of event that
can be cached (MWI, device state) has its own hash table and rules for
hashing and comparing objects. This by far made the biggest impact on
performance.
For additional details regarding this code and how it was tested, please see the
review request.
(closes issue #14738)
Reported by: russell
Review: http://reviewboard.digium.com/r/205/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@184339 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-03-25 21:57:19 +00:00
|
|
|
struct {
|
|
|
|
uint32_t hash;
|
|
|
|
const char *str;
|
|
|
|
};
|
2008-06-10 14:53:40 +00:00
|
|
|
void *raw;
|
2007-04-28 21:01:44 +00:00
|
|
|
} payload;
|
2008-06-10 14:53:40 +00:00
|
|
|
size_t raw_datalen;
|
2007-04-28 21:01:44 +00:00
|
|
|
};
|
|
|
|
|
2014-05-22 12:01:37 +00:00
|
|
|
/*!
|
|
|
|
* \brief Event Names
|
|
|
|
*/
|
|
|
|
static const char * const event_names[AST_EVENT_TOTAL] = {
|
|
|
|
[AST_EVENT_ALL] = "All",
|
|
|
|
[AST_EVENT_CUSTOM] = "Custom",
|
|
|
|
[AST_EVENT_MWI] = "MWI",
|
|
|
|
[AST_EVENT_SUB] = "Subscription",
|
|
|
|
[AST_EVENT_UNSUB] = "Unsubscription",
|
|
|
|
[AST_EVENT_DEVICE_STATE] = "DeviceState",
|
|
|
|
[AST_EVENT_DEVICE_STATE_CHANGE] = "DeviceStateChange",
|
|
|
|
[AST_EVENT_CEL] = "CEL",
|
|
|
|
[AST_EVENT_SECURITY] = "Security",
|
|
|
|
[AST_EVENT_NETWORK_CHANGE] = "NetworkChange",
|
|
|
|
[AST_EVENT_PRESENCE_STATE] = "PresenceState",
|
|
|
|
[AST_EVENT_ACL_CHANGE] = "ACLChange",
|
|
|
|
[AST_EVENT_PING] = "Ping",
|
2013-04-04 18:15:34 +00:00
|
|
|
};
|
|
|
|
|
2008-06-10 14:53:40 +00:00
|
|
|
/*!
|
2009-07-11 19:15:03 +00:00
|
|
|
* \brief IE payload types and names
|
2008-06-10 14:53:40 +00:00
|
|
|
*/
|
2014-05-22 12:01:37 +00:00
|
|
|
static const struct ie_map {
|
|
|
|
enum ast_event_ie_pltype ie_pltype;
|
|
|
|
const char *name;
|
|
|
|
} ie_maps[AST_EVENT_IE_TOTAL] = {
|
|
|
|
[AST_EVENT_IE_NEWMSGS] = { AST_EVENT_IE_PLTYPE_UINT, "NewMessages" },
|
|
|
|
[AST_EVENT_IE_OLDMSGS] = { AST_EVENT_IE_PLTYPE_UINT, "OldMessages" },
|
|
|
|
[AST_EVENT_IE_MAILBOX] = { AST_EVENT_IE_PLTYPE_STR, "Mailbox" },
|
2009-07-11 19:15:03 +00:00
|
|
|
[AST_EVENT_IE_UNIQUEID] = { AST_EVENT_IE_PLTYPE_UINT, "UniqueID" },
|
|
|
|
[AST_EVENT_IE_EVENTTYPE] = { AST_EVENT_IE_PLTYPE_UINT, "EventType" },
|
|
|
|
[AST_EVENT_IE_EXISTS] = { AST_EVENT_IE_PLTYPE_UINT, "Exists" },
|
2014-05-22 12:01:37 +00:00
|
|
|
[AST_EVENT_IE_DEVICE] = { AST_EVENT_IE_PLTYPE_STR, "Device" },
|
|
|
|
[AST_EVENT_IE_STATE] = { AST_EVENT_IE_PLTYPE_UINT, "State" },
|
2009-07-11 19:15:03 +00:00
|
|
|
[AST_EVENT_IE_CONTEXT] = { AST_EVENT_IE_PLTYPE_STR, "Context" },
|
2014-05-22 12:01:37 +00:00
|
|
|
[AST_EVENT_IE_EID] = { AST_EVENT_IE_PLTYPE_RAW, "EntityID" },
|
2009-07-11 19:15:03 +00:00
|
|
|
[AST_EVENT_IE_CEL_EVENT_TYPE] = { AST_EVENT_IE_PLTYPE_UINT, "CELEventType" },
|
|
|
|
[AST_EVENT_IE_CEL_EVENT_TIME] = { AST_EVENT_IE_PLTYPE_UINT, "CELEventTime" },
|
|
|
|
[AST_EVENT_IE_CEL_EVENT_TIME_USEC] = { AST_EVENT_IE_PLTYPE_UINT, "CELEventTimeUSec" },
|
2014-06-27 23:21:44 +00:00
|
|
|
[AST_EVENT_IE_CEL_USEREVENT_NAME] = { AST_EVENT_IE_PLTYPE_STR, "CELUserEventName" },
|
2009-07-11 19:15:03 +00:00
|
|
|
[AST_EVENT_IE_CEL_CIDNAME] = { AST_EVENT_IE_PLTYPE_STR, "CELCIDName" },
|
|
|
|
[AST_EVENT_IE_CEL_CIDNUM] = { AST_EVENT_IE_PLTYPE_STR, "CELCIDNum" },
|
|
|
|
[AST_EVENT_IE_CEL_EXTEN] = { AST_EVENT_IE_PLTYPE_STR, "CELExten" },
|
|
|
|
[AST_EVENT_IE_CEL_CONTEXT] = { AST_EVENT_IE_PLTYPE_STR, "CELContext" },
|
|
|
|
[AST_EVENT_IE_CEL_CHANNAME] = { AST_EVENT_IE_PLTYPE_STR, "CELChanName" },
|
|
|
|
[AST_EVENT_IE_CEL_APPNAME] = { AST_EVENT_IE_PLTYPE_STR, "CELAppName" },
|
|
|
|
[AST_EVENT_IE_CEL_APPDATA] = { AST_EVENT_IE_PLTYPE_STR, "CELAppData" },
|
2014-06-27 23:21:44 +00:00
|
|
|
[AST_EVENT_IE_CEL_AMAFLAGS] = { AST_EVENT_IE_PLTYPE_UINT, "CELAMAFlags" },
|
|
|
|
[AST_EVENT_IE_CEL_ACCTCODE] = { AST_EVENT_IE_PLTYPE_STR, "CELAcctCode" },
|
2009-07-11 19:15:03 +00:00
|
|
|
[AST_EVENT_IE_CEL_UNIQUEID] = { AST_EVENT_IE_PLTYPE_STR, "CELUniqueID" },
|
|
|
|
[AST_EVENT_IE_CEL_USERFIELD] = { AST_EVENT_IE_PLTYPE_STR, "CELUserField" },
|
|
|
|
[AST_EVENT_IE_CEL_CIDANI] = { AST_EVENT_IE_PLTYPE_STR, "CELCIDani" },
|
|
|
|
[AST_EVENT_IE_CEL_CIDRDNIS] = { AST_EVENT_IE_PLTYPE_STR, "CELCIDrdnis" },
|
|
|
|
[AST_EVENT_IE_CEL_CIDDNID] = { AST_EVENT_IE_PLTYPE_STR, "CELCIDdnid" },
|
|
|
|
[AST_EVENT_IE_CEL_PEER] = { AST_EVENT_IE_PLTYPE_STR, "CELPeer" },
|
|
|
|
[AST_EVENT_IE_CEL_LINKEDID] = { AST_EVENT_IE_PLTYPE_STR, "CELLinkedID" },
|
|
|
|
[AST_EVENT_IE_CEL_PEERACCT] = { AST_EVENT_IE_PLTYPE_STR, "CELPeerAcct" },
|
|
|
|
[AST_EVENT_IE_CEL_EXTRA] = { AST_EVENT_IE_PLTYPE_STR, "CELExtra" },
|
2014-06-27 23:21:44 +00:00
|
|
|
[AST_EVENT_IE_SECURITY_EVENT] = { AST_EVENT_IE_PLTYPE_UINT, "SecurityEvent" },
|
2009-07-11 19:15:03 +00:00
|
|
|
[AST_EVENT_IE_EVENT_VERSION] = { AST_EVENT_IE_PLTYPE_UINT, "EventVersion" },
|
|
|
|
[AST_EVENT_IE_SERVICE] = { AST_EVENT_IE_PLTYPE_STR, "Service" },
|
|
|
|
[AST_EVENT_IE_MODULE] = { AST_EVENT_IE_PLTYPE_STR, "Module" },
|
|
|
|
[AST_EVENT_IE_ACCOUNT_ID] = { AST_EVENT_IE_PLTYPE_STR, "AccountID" },
|
|
|
|
[AST_EVENT_IE_SESSION_ID] = { AST_EVENT_IE_PLTYPE_STR, "SessionID" },
|
|
|
|
[AST_EVENT_IE_SESSION_TV] = { AST_EVENT_IE_PLTYPE_STR, "SessionTV" },
|
|
|
|
[AST_EVENT_IE_ACL_NAME] = { AST_EVENT_IE_PLTYPE_STR, "ACLName" },
|
|
|
|
[AST_EVENT_IE_LOCAL_ADDR] = { AST_EVENT_IE_PLTYPE_STR, "LocalAddress" },
|
|
|
|
[AST_EVENT_IE_REMOTE_ADDR] = { AST_EVENT_IE_PLTYPE_STR, "RemoteAddress" },
|
|
|
|
[AST_EVENT_IE_EVENT_TV] = { AST_EVENT_IE_PLTYPE_STR, "EventTV" },
|
|
|
|
[AST_EVENT_IE_REQUEST_TYPE] = { AST_EVENT_IE_PLTYPE_STR, "RequestType" },
|
|
|
|
[AST_EVENT_IE_REQUEST_PARAMS] = { AST_EVENT_IE_PLTYPE_STR, "RequestParams" },
|
|
|
|
[AST_EVENT_IE_AUTH_METHOD] = { AST_EVENT_IE_PLTYPE_STR, "AuthMethod" },
|
|
|
|
[AST_EVENT_IE_SEVERITY] = { AST_EVENT_IE_PLTYPE_STR, "Severity" },
|
|
|
|
[AST_EVENT_IE_EXPECTED_ADDR] = { AST_EVENT_IE_PLTYPE_STR, "ExpectedAddress" },
|
|
|
|
[AST_EVENT_IE_CHALLENGE] = { AST_EVENT_IE_PLTYPE_STR, "Challenge" },
|
|
|
|
[AST_EVENT_IE_RESPONSE] = { AST_EVENT_IE_PLTYPE_STR, "Response" },
|
|
|
|
[AST_EVENT_IE_EXPECTED_RESPONSE] = { AST_EVENT_IE_PLTYPE_STR, "ExpectedResponse" },
|
2011-09-22 16:35:20 +00:00
|
|
|
[AST_EVENT_IE_RECEIVED_CHALLENGE] = { AST_EVENT_IE_PLTYPE_STR, "ReceivedChallenge" },
|
|
|
|
[AST_EVENT_IE_RECEIVED_HASH] = { AST_EVENT_IE_PLTYPE_STR, "ReceivedHash" },
|
|
|
|
[AST_EVENT_IE_USING_PASSWORD] = { AST_EVENT_IE_PLTYPE_UINT, "UsingPassword" },
|
2012-04-20 16:50:38 +00:00
|
|
|
[AST_EVENT_IE_ATTEMPTED_TRANSPORT] = { AST_EVENT_IE_PLTYPE_STR, "AttemptedTransport" },
|
2014-05-22 12:01:37 +00:00
|
|
|
[AST_EVENT_IE_CACHABLE] = { AST_EVENT_IE_PLTYPE_UINT, "Cachable" },
|
|
|
|
[AST_EVENT_IE_PRESENCE_PROVIDER] = { AST_EVENT_IE_PLTYPE_STR, "PresenceProvider" },
|
|
|
|
[AST_EVENT_IE_PRESENCE_STATE] = { AST_EVENT_IE_PLTYPE_UINT, "PresenceState" },
|
|
|
|
[AST_EVENT_IE_PRESENCE_SUBTYPE] = { AST_EVENT_IE_PLTYPE_STR, "PresenceSubtype" },
|
|
|
|
[AST_EVENT_IE_PRESENCE_MESSAGE] = { AST_EVENT_IE_PLTYPE_STR, "PresenceMessage" },
|
channel: Add multi-tenant identifier.
This patch introduces a new identifier for channels: tenantid. It's
a stringfield on the channel that can be used for general purposes. It
will be inherited by other channels the same way that linkedid is.
You can set tenantid in a few ways. The first is to set it in the
dialplan with the Set and CHANNEL functions:
exten => example,1,Set(CHANNEL(tenantid)=My tenant ID)
It can also be accessed via CHANNEL:
exten => example,2,NoOp(CHANNEL(tenantid))
Another method is to use the new tenantid option for pjsip endpoints in
pjsip.conf:
[my_endpoint]
type=endpoint
tenantid=My tenant ID
This is considered the best approach since you will be able to see the
tenant ID as early as the Newchannel event.
It can also be set using set_var in pjsip.conf on the endpoint like
setting other channel variable:
set_var=CHANNEL(tenantid)=My tenant ID
Note that set_var will not show tenant ID on the Newchannel event,
however.
Tenant ID has also been added to CDR. It's read-only and can be accessed
via CDR(tenantid). You can also get the tenant ID of the last channel
communicated with via CDR(peertenantid).
Tenant ID will also show up in CEL records if it has been set, and the
version number has been bumped accordingly.
Fixes: #740
UserNote: tenantid has been added to channels. It can be read in
dialplan via CHANNEL(tenantid), and it can be set using
Set(CHANNEL(tenantid)=My tenant ID). In pjsip.conf, it is recommended to
use the new tenantid option for pjsip endpoints (e.g., tenantid=My
tenant ID) so that it will show up in Newchannel events. You can set it
like any other channel variable using set_var in pjsip.conf as well, but
note that this will NOT show up in Newchannel events. Tenant ID is also
available in CDR and can be accessed with CDR(tenantid). The peer tenant
ID can also be accessed with CDR(peertenantid). CEL includes tenant ID
as well if it has been set.
UpgradeNote: A new versioned struct (ast_channel_initializers) has been
added that gets passed to __ast_channel_alloc_ap. The new function
ast_channel_alloc_with_initializers should be used when creating
channels that require the use of this struct. Currently the only value
in the struct is for tenantid, but now more fields can be added to the
struct as necessary rather than the __ast_channel_alloc_ap function. A
new option (tenantid) has been added to endpoints in pjsip.conf as well.
CEL has had its version bumped to include tenant ID.
2024-05-21 11:11:26 -05:00
|
|
|
[AST_EVENT_IE_CEL_TENANTID] = { AST_EVENT_IE_PLTYPE_STR, "TenantID" },
|
2008-06-10 14:53:40 +00:00
|
|
|
};
|
|
|
|
|
2014-05-22 12:01:37 +00:00
|
|
|
const char *ast_event_get_type_name(const struct ast_event *event)
|
|
|
|
{
|
|
|
|
enum ast_event_type type;
|
|
|
|
|
|
|
|
type = ast_event_get_type(event);
|
|
|
|
|
2015-04-23 15:00:42 +02:00
|
|
|
if ((unsigned int)type >= ARRAY_LEN(event_names)) {
|
2014-05-23 14:36:40 +00:00
|
|
|
ast_log(LOG_ERROR, "Invalid event type - '%u'\n", type);
|
2014-05-22 12:01:37 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return event_names[type];
|
|
|
|
}
|
|
|
|
|
2008-06-10 14:53:40 +00:00
|
|
|
const char *ast_event_get_ie_type_name(enum ast_event_ie_type ie_type)
|
|
|
|
{
|
2009-07-11 19:15:03 +00:00
|
|
|
if (ie_type <= 0 || ie_type >= ARRAY_LEN(ie_maps)) {
|
2008-06-10 14:53:40 +00:00
|
|
|
ast_log(LOG_ERROR, "Invalid IE type - '%d'\n", ie_type);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return ie_maps[ie_type].name;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum ast_event_ie_pltype ast_event_get_ie_pltype(enum ast_event_ie_type ie_type)
|
|
|
|
{
|
2009-07-11 19:15:03 +00:00
|
|
|
if (ie_type <= 0 || ie_type >= ARRAY_LEN(ie_maps)) {
|
2008-06-10 14:53:40 +00:00
|
|
|
ast_log(LOG_ERROR, "Invalid IE type - '%d'\n", ie_type);
|
|
|
|
return AST_EVENT_IE_PLTYPE_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ie_maps[ie_type].ie_pltype;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t ast_event_get_size(const struct ast_event *event)
|
|
|
|
{
|
|
|
|
size_t res;
|
|
|
|
|
|
|
|
res = ntohs(event->event_len);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2011-06-03 21:02:32 +00:00
|
|
|
/*! \brief Subscription event check list. */
|
|
|
|
struct ast_ev_check_list {
|
|
|
|
AST_LIST_HEAD_NOLOCK(, ast_event_ie_val) ie_vals;
|
|
|
|
};
|
|
|
|
|
2010-06-09 21:11:43 +00:00
|
|
|
int ast_event_iterator_init(struct ast_event_iterator *iterator, const struct ast_event *event)
|
2007-08-29 15:19:11 +00:00
|
|
|
{
|
2010-06-09 21:11:43 +00:00
|
|
|
int res = 0;
|
|
|
|
|
2010-02-10 23:19:16 +00:00
|
|
|
iterator->event_len = ast_event_get_size(event);
|
2007-08-29 15:19:11 +00:00
|
|
|
iterator->event = event;
|
2010-06-09 21:11:43 +00:00
|
|
|
if (iterator->event_len >= sizeof(*event) + sizeof(struct ast_event_ie)) {
|
|
|
|
iterator->ie = (struct ast_event_ie *) ( ((char *) event) + sizeof(*event) );
|
|
|
|
} else {
|
|
|
|
iterator->ie = NULL;
|
|
|
|
res = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
2007-08-29 15:19:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ast_event_iterator_next(struct ast_event_iterator *iterator)
|
|
|
|
{
|
2007-08-29 19:33:57 +00:00
|
|
|
iterator->ie = (struct ast_event_ie *) ( ((char *) iterator->ie) + sizeof(*iterator->ie) + ntohs(iterator->ie->ie_payload_len));
|
2008-02-13 00:55:09 +00:00
|
|
|
return ((iterator->event_len <= (((char *) iterator->ie) - ((char *) iterator->event))) ? -1 : 0);
|
2007-08-29 15:19:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum ast_event_ie_type ast_event_iterator_get_ie_type(struct ast_event_iterator *iterator)
|
|
|
|
{
|
2008-02-11 02:47:25 +00:00
|
|
|
return ntohs(iterator->ie->ie_type);
|
2007-08-29 15:19:11 +00:00
|
|
|
}
|
|
|
|
|
2007-08-29 16:03:51 +00:00
|
|
|
uint32_t ast_event_iterator_get_ie_uint(struct ast_event_iterator *iterator)
|
2007-08-29 15:19:11 +00:00
|
|
|
{
|
2007-12-11 16:29:29 +00:00
|
|
|
return ntohl(get_unaligned_uint32(iterator->ie->ie_payload));
|
2007-08-29 15:19:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *ast_event_iterator_get_ie_str(struct ast_event_iterator *iterator)
|
|
|
|
{
|
Improve performance of the ast_event cache functionality.
This code comes from svn/asterisk/team/russell/event_performance/.
Here is a summary of the changes that have been made, in order of both
invasiveness and performance impact, from smallest to largest.
1) Asterisk 1.6.1 introduces some additional logic to be able to handle
distributed device state. This functionality comes at a cost.
One relatively minor change in this patch is that the extra processing
required for distributed device state is now completely bypassed if
it's not needed.
2) One of the things that I noticed when profiling this code was that a
_lot_ of time was spent doing string comparisons. I changed the way
strings are represented in an event to include a hash value at the front.
So, before doing a string comparison, we do an integer comparison on the
hash.
3) Finally, the code that handles the event cache has been re-written.
I tried to do this in a such a way that it had minimal impact on the API.
I did have to change one API call, though - ast_event_queue_and_cache().
However, the way it works now is nicer, IMO. Each type of event that
can be cached (MWI, device state) has its own hash table and rules for
hashing and comparing objects. This by far made the biggest impact on
performance.
For additional details regarding this code and how it was tested, please see the
review request.
(closes issue #14738)
Reported by: russell
Review: http://reviewboard.digium.com/r/205/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@184339 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-03-25 21:57:19 +00:00
|
|
|
const struct ast_event_ie_str_payload *str_payload;
|
|
|
|
|
|
|
|
str_payload = (struct ast_event_ie_str_payload *) iterator->ie->ie_payload;
|
|
|
|
|
2010-02-08 23:43:00 +00:00
|
|
|
return str_payload ? str_payload->str : NULL;
|
2007-08-29 15:19:11 +00:00
|
|
|
}
|
|
|
|
|
2013-08-17 14:39:27 +00:00
|
|
|
static void *event_iterator_get_ie_raw(struct ast_event_iterator *iterator)
|
2007-08-29 15:19:11 +00:00
|
|
|
{
|
|
|
|
return iterator->ie->ie_payload;
|
|
|
|
}
|
|
|
|
|
2007-04-28 21:01:44 +00:00
|
|
|
enum ast_event_type ast_event_get_type(const struct ast_event *event)
|
|
|
|
{
|
|
|
|
return ntohs(event->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t ast_event_get_ie_uint(const struct ast_event *event, enum ast_event_ie_type ie_type)
|
|
|
|
{
|
|
|
|
const uint32_t *ie_val;
|
|
|
|
|
2014-05-22 12:01:37 +00:00
|
|
|
ie_val = ast_event_get_ie_raw(event, ie_type);
|
2007-04-28 21:01:44 +00:00
|
|
|
|
2007-12-11 16:29:29 +00:00
|
|
|
return ie_val ? ntohl(get_unaligned_uint32(ie_val)) : 0;
|
2007-04-28 21:01:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *ast_event_get_ie_str(const struct ast_event *event, enum ast_event_ie_type ie_type)
|
|
|
|
{
|
Improve performance of the ast_event cache functionality.
This code comes from svn/asterisk/team/russell/event_performance/.
Here is a summary of the changes that have been made, in order of both
invasiveness and performance impact, from smallest to largest.
1) Asterisk 1.6.1 introduces some additional logic to be able to handle
distributed device state. This functionality comes at a cost.
One relatively minor change in this patch is that the extra processing
required for distributed device state is now completely bypassed if
it's not needed.
2) One of the things that I noticed when profiling this code was that a
_lot_ of time was spent doing string comparisons. I changed the way
strings are represented in an event to include a hash value at the front.
So, before doing a string comparison, we do an integer comparison on the
hash.
3) Finally, the code that handles the event cache has been re-written.
I tried to do this in a such a way that it had minimal impact on the API.
I did have to change one API call, though - ast_event_queue_and_cache().
However, the way it works now is nicer, IMO. Each type of event that
can be cached (MWI, device state) has its own hash table and rules for
hashing and comparing objects. This by far made the biggest impact on
performance.
For additional details regarding this code and how it was tested, please see the
review request.
(closes issue #14738)
Reported by: russell
Review: http://reviewboard.digium.com/r/205/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@184339 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-03-25 21:57:19 +00:00
|
|
|
const struct ast_event_ie_str_payload *str_payload;
|
|
|
|
|
2014-05-22 12:01:37 +00:00
|
|
|
str_payload = ast_event_get_ie_raw(event, ie_type);
|
Improve performance of the ast_event cache functionality.
This code comes from svn/asterisk/team/russell/event_performance/.
Here is a summary of the changes that have been made, in order of both
invasiveness and performance impact, from smallest to largest.
1) Asterisk 1.6.1 introduces some additional logic to be able to handle
distributed device state. This functionality comes at a cost.
One relatively minor change in this patch is that the extra processing
required for distributed device state is now completely bypassed if
it's not needed.
2) One of the things that I noticed when profiling this code was that a
_lot_ of time was spent doing string comparisons. I changed the way
strings are represented in an event to include a hash value at the front.
So, before doing a string comparison, we do an integer comparison on the
hash.
3) Finally, the code that handles the event cache has been re-written.
I tried to do this in a such a way that it had minimal impact on the API.
I did have to change one API call, though - ast_event_queue_and_cache().
However, the way it works now is nicer, IMO. Each type of event that
can be cached (MWI, device state) has its own hash table and rules for
hashing and comparing objects. This by far made the biggest impact on
performance.
For additional details regarding this code and how it was tested, please see the
review request.
(closes issue #14738)
Reported by: russell
Review: http://reviewboard.digium.com/r/205/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@184339 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-03-25 21:57:19 +00:00
|
|
|
|
2010-02-08 23:43:00 +00:00
|
|
|
return str_payload ? str_payload->str : NULL;
|
2007-04-28 21:01:44 +00:00
|
|
|
}
|
|
|
|
|
2014-05-22 12:01:37 +00:00
|
|
|
const void *ast_event_get_ie_raw(const struct ast_event *event, enum ast_event_ie_type ie_type)
|
2007-04-28 21:01:44 +00:00
|
|
|
{
|
2007-08-29 16:25:30 +00:00
|
|
|
struct ast_event_iterator iterator;
|
2010-06-09 21:11:43 +00:00
|
|
|
int res;
|
2007-08-29 16:25:30 +00:00
|
|
|
|
2010-06-09 21:11:43 +00:00
|
|
|
for (res = ast_event_iterator_init(&iterator, event); !res; res = ast_event_iterator_next(&iterator)) {
|
2009-05-02 21:15:18 +00:00
|
|
|
if (ast_event_iterator_get_ie_type(&iterator) == ie_type) {
|
2013-08-17 14:39:27 +00:00
|
|
|
return event_iterator_get_ie_raw(&iterator);
|
2009-05-02 21:15:18 +00:00
|
|
|
}
|
2007-04-28 21:01:44 +00:00
|
|
|
}
|
2007-08-29 16:25:30 +00:00
|
|
|
|
2007-04-28 21:01:44 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-05-22 12:01:37 +00:00
|
|
|
static uint16_t event_iterator_get_ie_raw_payload_len(struct ast_event_iterator *iterator)
|
|
|
|
{
|
|
|
|
return ntohs(iterator->ie->ie_payload_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t ast_event_get_ie_raw_payload_len(const struct ast_event *event, enum ast_event_ie_type ie_type)
|
|
|
|
{
|
|
|
|
struct ast_event_iterator iterator;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
for (res = ast_event_iterator_init(&iterator, event); !res; res = ast_event_iterator_next(&iterator)) {
|
|
|
|
if (ast_event_iterator_get_ie_type(&iterator) == ie_type) {
|
|
|
|
return event_iterator_get_ie_raw_payload_len(&iterator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-28 21:01:44 +00:00
|
|
|
int ast_event_append_ie_str(struct ast_event **event, enum ast_event_ie_type ie_type,
|
|
|
|
const char *str)
|
|
|
|
{
|
Improve performance of the ast_event cache functionality.
This code comes from svn/asterisk/team/russell/event_performance/.
Here is a summary of the changes that have been made, in order of both
invasiveness and performance impact, from smallest to largest.
1) Asterisk 1.6.1 introduces some additional logic to be able to handle
distributed device state. This functionality comes at a cost.
One relatively minor change in this patch is that the extra processing
required for distributed device state is now completely bypassed if
it's not needed.
2) One of the things that I noticed when profiling this code was that a
_lot_ of time was spent doing string comparisons. I changed the way
strings are represented in an event to include a hash value at the front.
So, before doing a string comparison, we do an integer comparison on the
hash.
3) Finally, the code that handles the event cache has been re-written.
I tried to do this in a such a way that it had minimal impact on the API.
I did have to change one API call, though - ast_event_queue_and_cache().
However, the way it works now is nicer, IMO. Each type of event that
can be cached (MWI, device state) has its own hash table and rules for
hashing and comparing objects. This by far made the biggest impact on
performance.
For additional details regarding this code and how it was tested, please see the
review request.
(closes issue #14738)
Reported by: russell
Review: http://reviewboard.digium.com/r/205/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@184339 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-03-25 21:57:19 +00:00
|
|
|
struct ast_event_ie_str_payload *str_payload;
|
|
|
|
size_t payload_len;
|
|
|
|
|
|
|
|
payload_len = sizeof(*str_payload) + strlen(str);
|
2012-07-31 20:21:43 +00:00
|
|
|
str_payload = ast_alloca(payload_len);
|
Improve performance of the ast_event cache functionality.
This code comes from svn/asterisk/team/russell/event_performance/.
Here is a summary of the changes that have been made, in order of both
invasiveness and performance impact, from smallest to largest.
1) Asterisk 1.6.1 introduces some additional logic to be able to handle
distributed device state. This functionality comes at a cost.
One relatively minor change in this patch is that the extra processing
required for distributed device state is now completely bypassed if
it's not needed.
2) One of the things that I noticed when profiling this code was that a
_lot_ of time was spent doing string comparisons. I changed the way
strings are represented in an event to include a hash value at the front.
So, before doing a string comparison, we do an integer comparison on the
hash.
3) Finally, the code that handles the event cache has been re-written.
I tried to do this in a such a way that it had minimal impact on the API.
I did have to change one API call, though - ast_event_queue_and_cache().
However, the way it works now is nicer, IMO. Each type of event that
can be cached (MWI, device state) has its own hash table and rules for
hashing and comparing objects. This by far made the biggest impact on
performance.
For additional details regarding this code and how it was tested, please see the
review request.
(closes issue #14738)
Reported by: russell
Review: http://reviewboard.digium.com/r/205/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@184339 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-03-25 21:57:19 +00:00
|
|
|
|
|
|
|
strcpy(str_payload->str, str);
|
2013-08-17 14:39:27 +00:00
|
|
|
str_payload->hash = ast_str_hash(str);
|
Improve performance of the ast_event cache functionality.
This code comes from svn/asterisk/team/russell/event_performance/.
Here is a summary of the changes that have been made, in order of both
invasiveness and performance impact, from smallest to largest.
1) Asterisk 1.6.1 introduces some additional logic to be able to handle
distributed device state. This functionality comes at a cost.
One relatively minor change in this patch is that the extra processing
required for distributed device state is now completely bypassed if
it's not needed.
2) One of the things that I noticed when profiling this code was that a
_lot_ of time was spent doing string comparisons. I changed the way
strings are represented in an event to include a hash value at the front.
So, before doing a string comparison, we do an integer comparison on the
hash.
3) Finally, the code that handles the event cache has been re-written.
I tried to do this in a such a way that it had minimal impact on the API.
I did have to change one API call, though - ast_event_queue_and_cache().
However, the way it works now is nicer, IMO. Each type of event that
can be cached (MWI, device state) has its own hash table and rules for
hashing and comparing objects. This by far made the biggest impact on
performance.
For additional details regarding this code and how it was tested, please see the
review request.
(closes issue #14738)
Reported by: russell
Review: http://reviewboard.digium.com/r/205/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@184339 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-03-25 21:57:19 +00:00
|
|
|
|
2014-05-22 12:01:37 +00:00
|
|
|
return ast_event_append_ie_raw(event, ie_type, str_payload, payload_len);
|
2007-04-28 21:01:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ast_event_append_ie_uint(struct ast_event **event, enum ast_event_ie_type ie_type,
|
|
|
|
uint32_t data)
|
|
|
|
{
|
|
|
|
data = htonl(data);
|
2014-05-22 12:01:37 +00:00
|
|
|
return ast_event_append_ie_raw(event, ie_type, &data, sizeof(data));
|
|
|
|
}
|
|
|
|
|
|
|
|
int ast_event_append_ie_bitflags(struct ast_event **event, enum ast_event_ie_type ie_type,
|
|
|
|
uint32_t flags)
|
|
|
|
{
|
|
|
|
flags = htonl(flags);
|
|
|
|
return ast_event_append_ie_raw(event, ie_type, &flags, sizeof(flags));
|
2007-04-28 21:01:44 +00:00
|
|
|
}
|
|
|
|
|
2014-05-22 12:01:37 +00:00
|
|
|
int ast_event_append_ie_raw(struct ast_event **event, enum ast_event_ie_type ie_type,
|
2007-04-28 21:01:44 +00:00
|
|
|
const void *data, size_t data_len)
|
|
|
|
{
|
|
|
|
struct ast_event_ie *ie;
|
2013-09-10 18:05:47 +00:00
|
|
|
struct ast_event *old_event;
|
2007-04-28 21:01:44 +00:00
|
|
|
unsigned int extra_len;
|
|
|
|
uint16_t event_len;
|
|
|
|
|
|
|
|
event_len = ntohs((*event)->event_len);
|
|
|
|
extra_len = sizeof(*ie) + data_len;
|
|
|
|
|
2013-09-10 18:05:47 +00:00
|
|
|
old_event = *event;
|
|
|
|
*event = ast_realloc(*event, event_len + extra_len);
|
|
|
|
if (!*event) {
|
|
|
|
ast_free(old_event);
|
2007-04-28 21:01:44 +00:00
|
|
|
return -1;
|
2009-05-02 21:15:18 +00:00
|
|
|
}
|
2007-04-28 21:01:44 +00:00
|
|
|
|
2007-08-29 18:33:31 +00:00
|
|
|
ie = (struct ast_event_ie *) ( ((char *) *event) + event_len );
|
2007-04-28 21:01:44 +00:00
|
|
|
ie->ie_type = htons(ie_type);
|
|
|
|
ie->ie_payload_len = htons(data_len);
|
|
|
|
memcpy(ie->ie_payload, data, data_len);
|
|
|
|
|
|
|
|
(*event)->event_len = htons(event_len + extra_len);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ast_event *ast_event_new(enum ast_event_type type, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
struct ast_event *event;
|
2009-07-31 21:53:31 +00:00
|
|
|
enum ast_event_ie_type ie_type;
|
2007-04-28 21:01:44 +00:00
|
|
|
struct ast_event_ie_val *ie_val;
|
|
|
|
AST_LIST_HEAD_NOLOCK_STATIC(ie_vals, ast_event_ie_val);
|
|
|
|
|
|
|
|
/* Invalid type */
|
|
|
|
if (type >= AST_EVENT_TOTAL) {
|
|
|
|
ast_log(LOG_WARNING, "Someone tried to create an event of invalid "
|
2014-05-09 22:49:26 +00:00
|
|
|
"type '%u'!\n", type);
|
2007-04-28 21:01:44 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
va_start(ap, type);
|
2009-07-31 21:53:31 +00:00
|
|
|
for (ie_type = va_arg(ap, enum ast_event_ie_type);
|
2007-04-28 21:01:44 +00:00
|
|
|
ie_type != AST_EVENT_IE_END;
|
2009-07-31 21:53:31 +00:00
|
|
|
ie_type = va_arg(ap, enum ast_event_ie_type))
|
2007-04-28 21:01:44 +00:00
|
|
|
{
|
2019-10-23 12:36:17 -05:00
|
|
|
struct ast_event_ie_val *ie_value = ast_malloc(sizeof(*ie_value));
|
2011-06-03 21:02:32 +00:00
|
|
|
int insert = 0;
|
|
|
|
|
2008-08-10 19:35:50 +00:00
|
|
|
memset(ie_value, 0, sizeof(*ie_value));
|
|
|
|
ie_value->ie_type = ie_type;
|
|
|
|
ie_value->ie_pltype = va_arg(ap, enum ast_event_ie_pltype);
|
2014-05-22 12:01:37 +00:00
|
|
|
|
2009-05-02 21:15:18 +00:00
|
|
|
switch (ie_value->ie_pltype) {
|
|
|
|
case AST_EVENT_IE_PLTYPE_UINT:
|
2008-08-10 19:35:50 +00:00
|
|
|
ie_value->payload.uint = va_arg(ap, uint32_t);
|
2011-06-03 21:02:32 +00:00
|
|
|
insert = 1;
|
2009-05-02 21:15:18 +00:00
|
|
|
break;
|
2014-05-22 12:01:37 +00:00
|
|
|
case AST_EVENT_IE_PLTYPE_BITFLAGS:
|
|
|
|
ie_value->payload.uint = va_arg(ap, uint32_t);
|
|
|
|
insert = 1;
|
|
|
|
break;
|
2009-05-02 21:15:18 +00:00
|
|
|
case AST_EVENT_IE_PLTYPE_STR:
|
|
|
|
ie_value->payload.str = va_arg(ap, const char *);
|
2011-06-03 21:02:32 +00:00
|
|
|
insert = 1;
|
2009-05-02 21:15:18 +00:00
|
|
|
break;
|
|
|
|
case AST_EVENT_IE_PLTYPE_RAW:
|
|
|
|
{
|
2008-06-10 14:53:40 +00:00
|
|
|
void *data = va_arg(ap, void *);
|
|
|
|
size_t datalen = va_arg(ap, size_t);
|
2019-10-23 12:36:17 -05:00
|
|
|
ie_value->payload.raw = ast_malloc(datalen);
|
2008-08-10 19:35:50 +00:00
|
|
|
memcpy(ie_value->payload.raw, data, datalen);
|
|
|
|
ie_value->raw_datalen = datalen;
|
2011-06-03 21:02:32 +00:00
|
|
|
insert = 1;
|
2009-05-02 21:15:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AST_EVENT_IE_PLTYPE_UNKNOWN:
|
2014-05-22 12:01:37 +00:00
|
|
|
case AST_EVENT_IE_PLTYPE_EXISTS:
|
2009-05-02 21:15:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (insert) {
|
|
|
|
AST_LIST_INSERT_TAIL(&ie_vals, ie_value, entry);
|
2011-06-03 21:02:32 +00:00
|
|
|
} else {
|
|
|
|
ast_log(LOG_WARNING, "Unsupported PLTYPE(%d)\n", ie_value->ie_pltype);
|
2008-06-10 14:53:40 +00:00
|
|
|
}
|
2007-04-28 21:01:44 +00:00
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
|
2009-05-02 21:15:18 +00:00
|
|
|
if (!(event = ast_calloc(1, sizeof(*event)))) {
|
2007-04-28 21:01:44 +00:00
|
|
|
return NULL;
|
2009-05-02 21:15:18 +00:00
|
|
|
}
|
2007-04-28 21:01:44 +00:00
|
|
|
|
|
|
|
event->type = htons(type);
|
|
|
|
event->event_len = htons(sizeof(*event));
|
|
|
|
|
|
|
|
AST_LIST_TRAVERSE(&ie_vals, ie_val, entry) {
|
2009-05-02 21:15:18 +00:00
|
|
|
switch (ie_val->ie_pltype) {
|
|
|
|
case AST_EVENT_IE_PLTYPE_STR:
|
2007-04-28 21:01:44 +00:00
|
|
|
ast_event_append_ie_str(&event, ie_val->ie_type, ie_val->payload.str);
|
2009-05-02 21:15:18 +00:00
|
|
|
break;
|
|
|
|
case AST_EVENT_IE_PLTYPE_UINT:
|
2007-04-28 21:01:44 +00:00
|
|
|
ast_event_append_ie_uint(&event, ie_val->ie_type, ie_val->payload.uint);
|
2009-05-02 21:15:18 +00:00
|
|
|
break;
|
2014-05-22 12:01:37 +00:00
|
|
|
case AST_EVENT_IE_PLTYPE_BITFLAGS:
|
|
|
|
ast_event_append_ie_bitflags(&event, ie_val->ie_type, ie_val->payload.uint);
|
|
|
|
break;
|
2009-05-02 21:15:18 +00:00
|
|
|
case AST_EVENT_IE_PLTYPE_RAW:
|
2014-05-22 12:01:37 +00:00
|
|
|
ast_event_append_ie_raw(&event, ie_val->ie_type,
|
2009-05-02 21:15:18 +00:00
|
|
|
ie_val->payload.raw, ie_val->raw_datalen);
|
|
|
|
break;
|
2014-05-22 12:01:37 +00:00
|
|
|
case AST_EVENT_IE_PLTYPE_EXISTS:
|
2009-05-02 21:15:18 +00:00
|
|
|
case AST_EVENT_IE_PLTYPE_UNKNOWN:
|
|
|
|
break;
|
|
|
|
}
|
2007-04-28 21:01:44 +00:00
|
|
|
|
Resolve FORWARD_NULL static analysis warnings
This resolves core findings from ASTERISK-19650 numbers 0-2, 6, 7, 9-11, 14-20,
22-24, 28, 30-32, 34-36, 42-56, 82-84, 87, 89-90, 93-102, 104, 105, 109-111,
and 115. Finding numbers 26, 33, and 29 were already resolved. Those skipped
were either extended/deprecated or in areas of code that shouldn't be
disturbed.
(Closes issue ASTERISK-19650)
........
Merged revisions 366167 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 366168 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@366169 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-05-10 20:56:09 +00:00
|
|
|
/* realloc inside one of the append functions failed */
|
2009-05-02 21:15:18 +00:00
|
|
|
if (!event) {
|
2019-10-23 12:36:17 -05:00
|
|
|
goto cleanup;
|
2009-05-02 21:15:18 +00:00
|
|
|
}
|
2007-04-28 21:01:44 +00:00
|
|
|
}
|
|
|
|
|
2014-05-22 12:01:37 +00:00
|
|
|
if (!ast_event_get_ie_raw(event, AST_EVENT_IE_EID)) {
|
|
|
|
/* If the event is originating on this server, add the server's
|
|
|
|
* entity ID to the event. */
|
|
|
|
ast_event_append_eid(&event);
|
|
|
|
}
|
|
|
|
|
2019-10-23 12:36:17 -05:00
|
|
|
cleanup:
|
|
|
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&ie_vals, ie_val, entry) {
|
|
|
|
AST_LIST_REMOVE_CURRENT(entry);
|
|
|
|
|
|
|
|
if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_RAW) {
|
|
|
|
ast_free(ie_val->payload.raw);
|
|
|
|
}
|
|
|
|
ast_free(ie_val);
|
|
|
|
}
|
|
|
|
AST_LIST_TRAVERSE_SAFE_END;
|
|
|
|
|
2007-04-28 21:01:44 +00:00
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2014-05-22 12:01:37 +00:00
|
|
|
int ast_event_append_eid(struct ast_event **event)
|
|
|
|
{
|
|
|
|
return ast_event_append_ie_raw(event, AST_EVENT_IE_EID,
|
|
|
|
&ast_eid_default, sizeof(ast_eid_default));
|
|
|
|
}
|
|
|
|
|
2007-04-28 21:01:44 +00:00
|
|
|
void ast_event_destroy(struct ast_event *event)
|
|
|
|
{
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(event);
|
2007-04-28 21:01:44 +00:00
|
|
|
}
|
2014-05-22 12:01:37 +00:00
|
|
|
|
|
|
|
size_t ast_event_minimum_length(void)
|
|
|
|
{
|
|
|
|
return sizeof(struct ast_event);
|
|
|
|
}
|