[asterisk-commits] russell: branch group/security_events r192376 - in /team/group/security_event...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue May 5 09:20:28 CDT 2009
Author: russell
Date: Tue May 5 09:20:24 2009
New Revision: 192376
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=192376
Log:
Improve some code by removing a silly loop
Modified:
team/group/security_events/include/asterisk/security_events.h
team/group/security_events/main/security_events.c
Modified: team/group/security_events/include/asterisk/security_events.h
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/security_events/include/asterisk/security_events.h?view=diff&rev=192376&r1=192375&r2=192376
==============================================================================
--- team/group/security_events/include/asterisk/security_events.h (original)
+++ team/group/security_events/include/asterisk/security_events.h Tue May 5 09:20:24 2009
@@ -36,6 +36,8 @@
enum ast_security_event_type {
AST_SECURITY_EVENT_FAILED_ACL,
+ /* \brief This _must_ stay at the end. */
+ AST_SECURITY_EVENT_NUM_TYPES
};
enum ast_security_event_transport_type {
@@ -53,7 +55,7 @@
};
struct ast_security_event_failed_acl {
-#define AST_SECURITY_FAILED_ACL_VERSION 1
+#define AST_SECURITY_EVENT_FAILED_ACL_VERSION 1
struct ast_security_event_common common;
/*! \brief optional */
const char *module;
Modified: team/group/security_events/main/security_events.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/security_events/main/security_events.c?view=diff&rev=192376&r1=192375&r2=192376
==============================================================================
--- team/group/security_events/main/security_events.c (original)
+++ team/group/security_events/main/security_events.c Tue May 5 09:20:24 2009
@@ -41,10 +41,9 @@
enum ast_security_event_type event_type;
uint32_t version;
int (*handler)(const struct ast_security_event_common *);
-} sec_events[] = {
- {
- .event_type = AST_SECURITY_EVENT_FAILED_ACL,
- .version = AST_SECURITY_FAILED_ACL_VERSION,
+} sec_events[AST_SECURITY_EVENT_NUM_TYPES] = {
+ [AST_SECURITY_EVENT_FAILED_ACL] = {
+ .version = AST_SECURITY_EVENT_FAILED_ACL_VERSION,
.handler = handle_failed_acl,
},
};
@@ -72,22 +71,26 @@
int ast_security_event_report(const struct ast_security_event_common *sec)
{
- unsigned int i;
- int res = -1;
+ int res;
- for (i = 0; i < ARRAY_LEN(sec_events); i++) {
- if (sec->event_type != sec_events[i].event_type) {
- continue;
- }
+ if (sec->event_type < 0 || sec->event_type >= AST_SECURITY_EVENT_NUM_TYPES) {
+ ast_log(LOG_ERROR, "Invalid security event type\n");
+ return -1;
+ }
- if (sec->version != sec_events[i].version) {
- ast_log(LOG_WARNING, "Security event version mismatch\n");
- break;
- }
+ if (!sec_events[sec->event_type].handler) {
+ ast_log(LOG_WARNING, "Security event type %u not handled\n",
+ sec->event_type);
+ return -1;
+ }
- res = sec_events[i].handler(sec);
- break;
+ if (sec->version != sec_events[sec->event_type].version) {
+ ast_log(LOG_WARNING, "Security event %u version mismatch\n",
+ sec->event_type);
+ return -1;
}
+
+ res = sec_events[sec->event_type].handler(sec);
return res;
}
More information about the asterisk-commits
mailing list