[asterisk-commits] pcadach: branch pcadach/chan_h323-live r41332 -
in /team/pcadach/chan_h323-li...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Wed Aug 30 06:07:30 MST 2006
Author: pcadach
Date: Wed Aug 30 08:07:29 2006
New Revision: 41332
URL: http://svn.digium.com/view/asterisk?rev=41332&view=rev
Log:
Move user/peer/alias lists to ASTOBJ
Modified:
team/pcadach/chan_h323-live/channels/chan_h323.c
team/pcadach/chan_h323-live/channels/h323/ast_h323.cpp
team/pcadach/chan_h323-live/channels/h323/chan_h323.h
Modified: team/pcadach/chan_h323-live/channels/chan_h323.c
URL: http://svn.digium.com/view/asterisk/team/pcadach/chan_h323-live/channels/chan_h323.c?rev=41332&r1=41331&r2=41332&view=diff
==============================================================================
--- team/pcadach/chan_h323-live/channels/chan_h323.c (original)
+++ team/pcadach/chan_h323-live/channels/chan_h323.c Wed Aug 30 08:07:29 2006
@@ -94,6 +94,7 @@
#include "asterisk/causes.h"
#include "asterisk/stringfields.h"
#include "asterisk/abstract_jb.h"
+#include "asterisk/astobj.h"
#ifdef __cplusplus
}
@@ -187,18 +188,15 @@
} *iflist = NULL;
static struct ast_user_list {
- struct oh323_user *users;
- ast_mutex_t lock;
+ ASTOBJ_CONTAINER_COMPONENTS(struct oh323_user);
} userl;
static struct ast_peer_list {
- struct oh323_peer *peers;
- ast_mutex_t lock;
+ ASTOBJ_CONTAINER_COMPONENTS(struct oh323_peer);
} peerl;
static struct ast_alias_list {
- struct oh323_alias *aliases;
- ast_mutex_t lock;
+ ASTOBJ_CONTAINER_COMPONENTS(struct oh323_alias);
} aliasl;
/** Asterisk RTP stuff */
@@ -254,6 +252,29 @@
.bridge = ast_rtp_bridge,
#endif
};
+
+static void oh323_destroy_alias(struct oh323_alias *alias)
+{
+ if (h323debug)
+ ast_log(LOG_DEBUG, "Destroying alias '%s'\n", alias->name);
+ free(alias);
+}
+
+static void oh323_destroy_user(struct oh323_user *user)
+{
+ if (h323debug)
+ ast_log(LOG_DEBUG, "Destroying user '%s'\n", user->name);
+ ast_free_ha(user->ha);
+ free(user);
+}
+
+static void oh323_destroy_peer(struct oh323_peer *peer)
+{
+ if (h323debug)
+ ast_log(LOG_DEBUG, "Destroying peer '%s'\n", peer->name);
+ ast_free_ha(peer->ha);
+ free(peer);
+}
/* Channel and private structures should be already locked */
static void __oh323_update_info(struct ast_channel *c, struct oh323_pvt *pvt)
@@ -949,57 +970,60 @@
}
}
-static struct oh323_user *find_user(const call_details_t *cd)
+static int oh323_addrcmp_str(struct in_addr inaddr, char *addr)
+{
+ return strcmp(ast_inet_ntoa(inaddr), addr);
+}
+
+static struct oh323_user *find_user(const call_details_t *cd, int realtime)
{
struct oh323_user *u;
- u = userl.users;
- if (userbyalias) {
- while(u) {
- if (!strcasecmp(u->name, cd->call_source_aliases)) {
- break;
- }
- u = u->next;
- }
- } else {
- while(u) {
- if (!strcasecmp(cd->sourceIp, ast_inet_ntoa(u->addr.sin_addr))) {
- break;
- }
- u = u->next;
- }
- }
+
+ if (userbyalias)
+ u = ASTOBJ_CONTAINER_FIND(&userl, cd->call_source_aliases);
+ else
+ u = ASTOBJ_CONTAINER_FIND_FULL(&userl, cd->sourceIp, addr.sin_addr, 0, 0, oh323_addrcmp_str);
+
+#if 0 /* XXX REALTIME XXX*/
+ if (!u && realtime)
+ u = realtime_user(cd);
+#endif
+
+ if (!u && h323debug)
+ ast_log(LOG_DEBUG, "Could not find user by name %s or address %s\n", cd->call_source_aliases, cd->sourceIp);
+
return u;
}
-static struct oh323_peer *find_peer(const char *peer, struct sockaddr_in *sin)
+static int oh323_addrcmp(struct sockaddr_in addr, struct sockaddr_in *sin)
+{
+ int res;
+
+ if (!sin)
+ res = -1;
+ else
+ res = inaddrcmp(&addr , sin);
+
+ return res;
+}
+
+static struct oh323_peer *find_peer(const char *peer, struct sockaddr_in *sin, int realtime)
{
struct oh323_peer *p = NULL;
- p = peerl.peers;
- if (peer) {
- while(p) {
- if (!strcasecmp(p->name, peer)) {
- ast_log(LOG_DEBUG, "Found peer %s by name\n", peer);
- break;
- }
- p = p->next;
- }
- } else {
- /* find by sin */
- if (sin) {
- while (p) {
- if ((!inaddrcmp(&p->addr, sin)) ||
- (p->addr.sin_addr.s_addr == sin->sin_addr.s_addr)) {
- ast_log(LOG_DEBUG, "Found peer %s/%s by addr\n", peer, ast_inet_ntoa(p->addr.sin_addr));
- break;
- }
- p = p->next;
- }
- }
- }
- if (!p) {
- ast_log(LOG_DEBUG, "Could not find peer %s by name or address\n", peer);
- }
+ if (peer)
+ p = ASTOBJ_CONTAINER_FIND(&peerl, peer);
+ else
+ p = ASTOBJ_CONTAINER_FIND_FULL(&peerl, sin, addr, 0, 0, oh323_addrcmp);
+
+#if 0 /* XXX REALTIME XXX */
+ if (!p && realtime)
+ p = realtime_peer(peer, sin);
+#endif
+
+ if (!p && h323debug)
+ ast_log(LOG_DEBUG, "Could not find peer by name %s or address %s\n", (peer ? peer : "<NONE>"), (sin ? ast_inet_ntoa(sin->sin_addr) : "<NONE>"));
+
return p;
}
@@ -1021,8 +1045,7 @@
port++;
}
pvt->sa.sin_family = AF_INET;
- ast_mutex_lock(&peerl.lock);
- p = find_peer(peer, NULL);
+ p = find_peer(peer, NULL, 0);
if (p) {
found++;
memcpy(&pvt->options, &p->options, sizeof(pvt->options));
@@ -1042,8 +1065,8 @@
pvt->sa.sin_addr = p->addr.sin_addr;
pvt->sa.sin_port = p->addr.sin_port;
}
- }
- ast_mutex_unlock(&peerl.lock);
+ ASTOBJ_UNREF(p, oh323_destroy_peer);
+ }
if (!p && !found) {
hostn = peer;
if (port) {
@@ -1056,9 +1079,12 @@
memcpy(&pvt->sa.sin_addr, hp->h_addr, sizeof(pvt->sa.sin_addr));
pvt->sa.sin_port = htons(portno);
/* Look peer by address */
- p = find_peer(NULL, &pvt->sa);
+ p = find_peer(NULL, &pvt->sa, 0);
memcpy(&pvt->options, (p ? &p->options : &global_options), sizeof(pvt->options));
pvt->jointcapability = pvt->options.capability;
+ if (p) {
+ ASTOBJ_UNREF(p, oh323_destroy_peer);
+ }
if (pvt->rtp) {
ast_log(LOG_DEBUG, "Setting NAT on RTP to %d\n", pvt->options.nat);
ast_rtp_setnat(pvt->rtp, pvt->options.nat);
@@ -1166,13 +1192,13 @@
{
struct oh323_alias *a;
- a = aliasl.aliases;
- while(a) {
- if (!strcasecmp(a->name, source_aliases)) {
- break;
- }
- a = a->next;
- }
+ a = ASTOBJ_CONTAINER_FIND(&aliasl, source_aliases);
+
+#if 0 /* XXX REALTIME XXX */
+ if (!a && realtime)
+ a = realtime_alias(source_aliases);
+#endif
+
return a;
}
@@ -1421,7 +1447,7 @@
} else {
/* Either this call is not from the Gatekeeper
or we are not allowing gk routed calls */
- user = find_user(cd);
+ user = find_user(cd, 0);
if (!user) {
if (!ast_strlen_zero(pvt->cd.call_dest_e164)) {
strncpy(pvt->exten, cd->call_dest_e164, sizeof(pvt->exten) - 1);
@@ -1446,6 +1472,7 @@
if (ast_strlen_zero(default_context)) {
ast_log(LOG_ERROR, "Call from '%s' rejected due to non-matching IP address (%s) and no default context\n", user->name, cd->sourceIp);
oh323_destroy(pvt);
+ ASTOBJ_UNREF(user, oh323_destroy_user);
return NULL;
}
strncpy(pvt->context, default_context, sizeof(pvt->context) - 1);
@@ -1456,6 +1483,7 @@
pvt->exten[1] = '\0';
ast_log(LOG_ERROR, "Call from '%s' rejected due to non-matching IP address (%s)s\n", user->name, cd->sourceIp);
oh323_destroy(pvt);
+ ASTOBJ_UNREF(user, oh323_destroy_user);
return NULL; /* XXX: Hmmm... Why to setup context if we drop connection immediately??? */
}
}
@@ -1472,7 +1500,8 @@
}
if (user->amaflags) {
pvt->amaflags = user->amaflags;
- }
+ }
+ ASTOBJ_UNREF(user, oh323_destroy_user);
}
}
return &pvt->options;
@@ -1976,144 +2005,152 @@
static struct oh323_alias *build_alias(char *name, struct ast_variable *v)
{
struct oh323_alias *alias;
-
- alias = (struct oh323_alias *)malloc(sizeof(struct oh323_alias));
- if (alias) {
- memset(alias, 0, sizeof(struct oh323_alias));
+ int found = 0;
+
+ alias = ASTOBJ_CONTAINER_FIND_UNLINK_FULL(&aliasl, name, name, 0, 0, strcasecmp);
+
+ if (alias)
+ found++;
+ else {
+ if (!(alias = (struct oh323_alias *)calloc(1, sizeof(*alias))))
+ return NULL;
+ ASTOBJ_INIT(alias);
+ }
+ if (!found && name)
strncpy(alias->name, name, sizeof(alias->name) - 1);
- while (v) {
- if (!strcasecmp(v->name, "e164")) {
- strncpy(alias->e164, v->value, sizeof(alias->e164) - 1);
- } else if (!strcasecmp(v->name, "prefix")) {
- strncpy(alias->prefix, v->value, sizeof(alias->prefix) - 1);
- } else if (!strcasecmp(v->name, "context")) {
- strncpy(alias->context, v->value, sizeof(alias->context) - 1);
- } else if (!strcasecmp(v->name, "secret")) {
- strncpy(alias->secret, v->value, sizeof(alias->secret) - 1);
+ for (; v; v = v->next) {
+ if (!strcasecmp(v->name, "e164")) {
+ strncpy(alias->e164, v->value, sizeof(alias->e164) - 1);
+ } else if (!strcasecmp(v->name, "prefix")) {
+ strncpy(alias->prefix, v->value, sizeof(alias->prefix) - 1);
+ } else if (!strcasecmp(v->name, "context")) {
+ strncpy(alias->context, v->value, sizeof(alias->context) - 1);
+ } else if (!strcasecmp(v->name, "secret")) {
+ strncpy(alias->secret, v->value, sizeof(alias->secret) - 1);
+ } else {
+ if (strcasecmp(v->value, "h323")) {
+ ast_log(LOG_WARNING, "Keyword %s does not make sense in type=h323\n", v->value);
+ }
+ }
+ }
+ ASTOBJ_UNMARK(alias);
+ return alias;
+}
+
+static struct oh323_user *build_user(char *name, struct ast_variable *v, int realtime)
+{
+ struct oh323_user *user;
+ struct ast_ha *oldha;
+ int found = 0;
+ int format;
+
+ user = ASTOBJ_CONTAINER_FIND_UNLINK_FULL(&userl, name, name, 0, 0, strcmp);
+
+ if (user)
+ found++;
+ else {
+ if (!(user = (struct oh323_user *)calloc(1, sizeof(*user))))
+ return NULL;
+ ASTOBJ_INIT(user);
+ }
+ oldha = user->ha;
+ user->ha = (struct ast_ha *)NULL;
+ memcpy(&user->options, &global_options, sizeof(user->options));
+ /* Set default context */
+ strncpy(user->context, default_context, sizeof(user->context) - 1);
+ if (user && !found)
+ strncpy(user->name, name, sizeof(user->name) - 1);
+ for (; v; v = v->next) {
+ if (!update_common_options(v, &user->options))
+ continue;
+ if (!strcasecmp(v->name, "context")) {
+ strncpy(user->context, v->value, sizeof(user->context) - 1);
+ } else if (!strcasecmp(v->name, "secret")) {
+ strncpy(user->secret, v->value, sizeof(user->secret) - 1);
+ } else if (!strcasecmp(v->name, "callerid")) {
+ strncpy(user->callerid, v->value, sizeof(user->callerid) - 1);
+ } else if (!strcasecmp(v->name, "accountcode")) {
+ strncpy(user->accountcode, v->value, sizeof(user->accountcode) - 1);
+ } else if (!strcasecmp(v->name, "host")) {
+ if (!strcasecmp(v->value, "dynamic")) {
+ ast_log(LOG_ERROR, "A dynamic host on a type=user does not make any sense\n");
+ ASTOBJ_UNREF(user, oh323_destroy_user);
+ return NULL;
+ } else if (ast_get_ip(&user->addr, v->value)) {
+ ASTOBJ_UNREF(user, oh323_destroy_user);
+ return NULL;
+ }
+ /* Let us know we need to use ip authentication */
+ user->host = 1;
+ } else if (!strcasecmp(v->name, "amaflags")) {
+ format = ast_cdr_amaflags2int(v->value);
+ if (format < 0) {
+ ast_log(LOG_WARNING, "Invalid AMA Flags: %s at line %d\n", v->value, v->lineno);
} else {
- if (strcasecmp(v->value, "h323")) {
- ast_log(LOG_WARNING, "Keyword %s does not make sense in type=h323\n", v->value);
- }
- }
- v = v->next;
- }
- }
- return alias;
-}
-
-static struct oh323_user *build_user(char *name, struct ast_variable *v)
-{
- struct oh323_user *user;
- int format;
-
- user = (struct oh323_user *)malloc(sizeof(struct oh323_user));
- if (user) {
- memset(user, 0, sizeof(struct oh323_user));
- strncpy(user->name, name, sizeof(user->name) - 1);
- memcpy(&user->options, &global_options, sizeof(user->options));
- /* Set default context */
- strncpy(user->context, default_context, sizeof(user->context) - 1);
- while(v) {
- if (!strcasecmp(v->name, "context")) {
- strncpy(user->context, v->value, sizeof(user->context) - 1);
- } else if (!update_common_options(v, &user->options)) {
- /* dummy */
- } else if (!strcasecmp(v->name, "secret")) {
- strncpy(user->secret, v->value, sizeof(user->secret) - 1);
- } else if (!strcasecmp(v->name, "callerid")) {
- strncpy(user->callerid, v->value, sizeof(user->callerid) - 1);
- } else if (!strcasecmp(v->name, "accountcode")) {
- strncpy(user->accountcode, v->value, sizeof(user->accountcode) - 1);
- } else if (!strcasecmp(v->name, "host")) {
- if (!strcasecmp(v->value, "dynamic")) {
- ast_log(LOG_ERROR, "A dynamic host on a type=user does not make any sense\n");
- free(user);
- return NULL;
- } else if (ast_get_ip(&user->addr, v->value)) {
- free(user);
- return NULL;
- }
- /* Let us know we need to use ip authentication */
- user->host = 1;
- } else if (!strcasecmp(v->name, "amaflags")) {
- format = ast_cdr_amaflags2int(v->value);
- if (format < 0) {
- ast_log(LOG_WARNING, "Invalid AMA Flags: %s at line %d\n", v->value, v->lineno);
- } else {
- user->amaflags = format;
- }
- }
- v = v->next;
- }
- }
+ user->amaflags = format;
+ }
+ } else if (!strcasecmp(v->name, "permit") ||
+ !strcasecmp(v->name, "deny")) {
+ user->ha = ast_append_ha(v->name, v->value, user->ha);
+ }
+ }
+ ASTOBJ_UNMARK(user);
+ ast_free_ha(oldha);
return user;
}
-static struct oh323_peer *build_peer(char *name, struct ast_variable *v)
+static struct oh323_peer *build_peer(char *name, struct ast_variable *v, int realtime)
{
struct oh323_peer *peer;
- struct oh323_peer *prev;
- struct ast_ha *oldha = NULL;
- int found=0;
-
- prev = NULL;
- ast_mutex_lock(&peerl.lock);
- peer = peerl.peers;
-
- while(peer) {
- if (!strcasecmp(peer->name, name)) {
- break;
- }
- prev = peer;
- peer = peer->next;
- }
-
- if (peer) {
+ struct ast_ha *oldha;
+ int found = 0;
+
+ peer = ASTOBJ_CONTAINER_FIND_UNLINK_FULL(&peerl, name, name, 0, 0, strcmp);
+
+ if (peer)
found++;
- /* Already in the list, remove it and it will be added back (or FREE'd) */
- if (prev) {
- prev->next = peer->next;
- } else {
- peerl.peers = peer->next;
- }
- ast_mutex_unlock(&peerl.lock);
- } else {
- ast_mutex_unlock(&peerl.lock);
- peer = (struct oh323_peer*)malloc(sizeof(struct oh323_peer));
- if (peer)
- memset(peer, 0, sizeof(struct oh323_peer));
- }
- if (peer) {
- if (!found) {
- strncpy(peer->name, name, sizeof(peer->name) - 1);
- peer->addr.sin_port = htons(h323_signalling_port);
- peer->addr.sin_family = AF_INET;
- }
- oldha = peer->ha;
- peer->ha = NULL;
- peer->addr.sin_family = AF_INET;
- memcpy(&peer->options, &global_options, sizeof(peer->options));
-
- while(v) {
- if (!update_common_options(v, &peer->options)) {
- /* dummy */
- } else if (!strcasecmp(v->name, "host")) {
- if (!strcasecmp(v->value, "dynamic")) {
- ast_log(LOG_ERROR, "Dynamic host configuration not implemented.\n");
- free(peer);
- return NULL;
- }
- if (ast_get_ip(&peer->addr, v->value)) {
- ast_log(LOG_ERROR, "Could not determine IP for %s\n", v->value);
- free(peer);
- return NULL;
- }
- } else if (!strcasecmp(v->name, "port")) {
- peer->addr.sin_port = htons(atoi(v->value));
- }
- v=v->next;
- }
- }
+ else {
+ if (!(peer = (struct oh323_peer*)calloc(1, sizeof(*peer))))
+ return NULL;
+ ASTOBJ_INIT(peer);
+ }
+ oldha = peer->ha;
+ peer->ha = NULL;
+ memcpy(&peer->options, &global_options, sizeof(peer->options));
+ peer->addr.sin_port = htons(h323_signalling_port);
+ peer->addr.sin_family = AF_INET;
+ if (!found && name)
+ strncpy(peer->name, name, sizeof(peer->name) - 1);
+#if 0 /* XXX Port channel variables functionality from chan_sip XXX */
+ if (peer->chanvars) {
+ ast_variables_destroy(peer->chanvars);
+ peer->chanvars = NULL;
+ }
+#endif
+
+ for (; v; v = v->next) {
+ if (!update_common_options(v, &peer->options))
+ continue;
+ if (!strcasecmp(v->name, "host")) {
+ if (!strcasecmp(v->value, "dynamic")) {
+ ast_log(LOG_ERROR, "Dynamic host configuration not implemented.\n");
+ ASTOBJ_UNREF(peer, oh323_destroy_peer);
+ return NULL;
+ }
+ if (ast_get_ip(&peer->addr, v->value)) {
+ ast_log(LOG_ERROR, "Could not determine IP for %s\n", v->value);
+ ASTOBJ_UNREF(peer, oh323_destroy_peer);
+ return NULL;
+ }
+ } else if (!strcasecmp(v->name, "port")) {
+ peer->addr.sin_port = htons(atoi(v->value));
+ } else if (!strcasecmp(v->name, "permit") ||
+ !strcasecmp(v->name, "deny")) {
+ peer->ha = ast_append_ha(v->name, v->value, peer->ha);
+ }
+ }
+ ASTOBJ_UNMARK(peer);
+ ast_free_ha(oldha);
return peer;
}
@@ -2127,7 +2164,8 @@
struct oh323_alias *alias = NULL;
struct ast_hostent ahp; struct hostent *hp;
char *cat;
- char *utype;
+ char *utype;
+ int is_user, is_peer, is_alias;
cfg = ast_config_load(config);
@@ -2225,47 +2263,39 @@
if (strcasecmp(cat, "general")) {
utype = ast_variable_retrieve(cfg, cat, "type");
if (utype) {
- if (!strcasecmp(utype, "user")) {
- user = build_user(cat, ast_variable_browse(cfg, cat));
+ is_user = is_peer = is_alias = 0;
+ if (!strcasecmp(utype, "user"))
+ is_user = 1;
+ else if (!strcasecmp(utype, "peer"))
+ is_peer = 1;
+ else if (!strcasecmp(utype, "friend"))
+ is_user = is_peer = 1;
+ else if (!strcasecmp(utype, "h323") || !strcasecmp(utype, "alias"))
+ is_alias = 1;
+ else {
+ ast_log(LOG_WARNING, "Unknown type '%s' for '%s' in %s\n", utype, cat, config);
+ continue;
+ }
+ if (is_user) {
+ user = build_user(cat, ast_variable_browse(cfg, cat), 0);
if (user) {
- ast_mutex_lock(&userl.lock);
- user->next = userl.users;
- userl.users = user;
- ast_mutex_unlock(&userl.lock);
+ ASTOBJ_CONTAINER_LINK(&userl, user);
+ ASTOBJ_UNREF(user, oh323_destroy_user);
}
- } else if (!strcasecmp(utype, "peer")) {
- peer = build_peer(cat, ast_variable_browse(cfg, cat));
+ }
+ if (is_peer) {
+ peer = build_peer(cat, ast_variable_browse(cfg, cat), 0);
if (peer) {
- ast_mutex_lock(&peerl.lock);
- peer->next = peerl.peers;
- peerl.peers = peer;
- ast_mutex_unlock(&peerl.lock);
+ ASTOBJ_CONTAINER_LINK(&peerl, peer);
+ ASTOBJ_UNREF(peer, oh323_destroy_peer);
}
- } else if (!strcasecmp(utype, "friend")) {
- user = build_user(cat, ast_variable_browse(cfg, cat));
- peer = build_peer(cat, ast_variable_browse(cfg, cat));
- if (user) {
- ast_mutex_lock(&userl.lock);
- user->next = userl.users;
- userl.users = user;
- ast_mutex_unlock(&userl.lock);
- }
- if (peer) {
- ast_mutex_lock(&peerl.lock);
- peer->next = peerl.peers;
- peerl.peers = peer;
- ast_mutex_unlock(&peerl.lock);
- }
- } else if (!strcasecmp(utype, "h323") || !strcasecmp(utype, "alias")) {
+ }
+ if (is_alias) {
alias = build_alias(cat, ast_variable_browse(cfg, cat));
if (alias) {
- ast_mutex_lock(&aliasl.lock);
- alias->next = aliasl.aliases;
- aliasl.aliases = alias;
- ast_mutex_unlock(&aliasl.lock);
+ ASTOBJ_CONTAINER_LINK(&aliasl, alias);
+ ASTOBJ_UNREF(alias, oh323_destroy_alias);
}
- } else {
- ast_log(LOG_WARNING, "Unknown type '%s' for '%s' in %s\n", utype, cat, config);
}
} else {
ast_log(LOG_WARNING, "Section '%s' lacks type\n", cat);
@@ -2276,78 +2306,69 @@
ast_config_destroy(cfg);
/* Register our H.323 aliases if any*/
- ast_mutex_lock(&aliasl.lock);
- while (alias) {
- if (h323_set_alias(alias)) {
+ ASTOBJ_CONTAINER_WRLOCK(&aliasl);
+ ASTOBJ_CONTAINER_TRAVERSE(&aliasl, 1, do {
+ ASTOBJ_RDLOCK(iterator);
+ if (h323_set_alias(iterator)) {
ast_log(LOG_ERROR, "Alias %s rejected by endpoint\n", alias->name);
- return -1;
- }
- alias = alias->next;
- }
- ast_mutex_unlock(&aliasl.lock);
+ ASTOBJ_UNLOCK(iterator);
+ continue;
+ }
+ ASTOBJ_UNLOCK(iterator);
+ } while (0) );
+ ASTOBJ_CONTAINER_UNLOCK(&aliasl);
return 0;
}
static void delete_users(void)
{
- struct oh323_user *user, *userlast;
- struct oh323_peer *peer;
+ int pruned = 0;
/* Delete all users */
- ast_mutex_lock(&userl.lock);
- for (user=userl.users;user;) {
- userlast = user;
- user=user->next;
- free(userlast);
- }
- userl.users=NULL;
- ast_mutex_unlock(&userl.lock);
- ast_mutex_lock(&peerl.lock);
- for (peer=peerl.peers;peer;) {
- /* Assume all will be deleted, and we'll find out for sure later */
- peer->delme = 1;
- peer = peer->next;
- }
- ast_mutex_unlock(&peerl.lock);
+ ASTOBJ_CONTAINER_WRLOCK(&userl);
+ ASTOBJ_CONTAINER_TRAVERSE(&userl, 1, do {
+ ASTOBJ_RDLOCK(iterator);
+ ASTOBJ_MARK(iterator);
+ ++pruned;
+ ASTOBJ_UNLOCK(iterator);
+ } while (0) );
+ if (pruned) {
+ ASTOBJ_CONTAINER_PRUNE_MARKED(&userl, oh323_destroy_user);
+ }
+ ASTOBJ_CONTAINER_UNLOCK(&userl);
+
+ ASTOBJ_CONTAINER_WRLOCK(&peerl);
+ ASTOBJ_CONTAINER_TRAVERSE(&peerl, 1, do {
+ ASTOBJ_RDLOCK(iterator);
+ ASTOBJ_MARK(iterator);
+ ASTOBJ_UNLOCK(iterator);
+ } while (0) );
+ ASTOBJ_CONTAINER_UNLOCK(&peerl);
}
static void delete_aliases(void)
{
- struct oh323_alias *alias, *aliaslast;
+ int pruned = 0;
- /* Delete all users */
- ast_mutex_lock(&aliasl.lock);
- for (alias=aliasl.aliases;alias;) {
- aliaslast = alias;
- alias=alias->next;
- free(aliaslast);
- }
- aliasl.aliases=NULL;
- ast_mutex_unlock(&aliasl.lock);
+ /* Delete all aliases */
+ ASTOBJ_CONTAINER_WRLOCK(&aliasl);
+ ASTOBJ_CONTAINER_TRAVERSE(&aliasl, 1, do {
+ ASTOBJ_RDLOCK(iterator);
+ ASTOBJ_MARK(iterator);
+ ++pruned;
+ ASTOBJ_UNLOCK(iterator);
+ } while (0) );
+ if (pruned) {
+ ASTOBJ_CONTAINER_PRUNE_MARKED(&aliasl, oh323_destroy_alias);
+ }
+ ASTOBJ_CONTAINER_UNLOCK(&aliasl);
}
static void prune_peers(void)
{
/* Prune peers who still are supposed to be deleted */
- struct oh323_peer *peer, *peerlast, *peernext;
- ast_mutex_lock(&peerl.lock);
- peerlast = NULL;
- for (peer=peerl.peers;peer;) {
- peernext = peer->next;
- if (peer->delme) {
- free(peer);
- if (peerlast) {
- peerlast->next = peernext;
- } else {
- peerl.peers = peernext;
- }
- } else {
- peerlast = peer;
- }
- peer = peernext;
- }
- ast_mutex_unlock(&peerl.lock);
+ ASTOBJ_CONTAINER_PRUNE_MARKED(&peerl, oh323_destroy_peer);
}
static int h323_reload(int fd, int argc, char *argv[])
@@ -2464,9 +2485,7 @@
static enum ast_module_load_result load_module(void)
{
int res;
- ast_mutex_init(&userl.lock);
- ast_mutex_init(&peerl.lock);
- ast_mutex_init(&aliasl.lock);
+
h323debug = 0;
sched = sched_context_create();
if (!sched) {
@@ -2479,6 +2498,9 @@
return AST_MODULE_LOAD_FAILURE;
}
ast_cli_register(&cli_h323_reload);
+ ASTOBJ_CONTAINER_INIT(&userl);
+ ASTOBJ_CONTAINER_INIT(&peerl);
+ ASTOBJ_CONTAINER_INIT(&aliasl);
res = reload_config();
if (res) {
return AST_MODULE_LOAD_DECLINE;
@@ -2490,12 +2512,14 @@
h323_end_process();
io_context_destroy(io);
sched_context_destroy(sched);
- delete_users();
- delete_aliases();
- prune_peers();
- ast_mutex_destroy(&aliasl.lock);
- ast_mutex_destroy(&userl.lock);
- ast_mutex_destroy(&peerl.lock);
+
+ ASTOBJ_CONTAINER_DESTROYALL(&userl, oh323_destroy_user);
+ ASTOBJ_CONTAINER_DESTROY(&userl);
+ ASTOBJ_CONTAINER_DESTROYALL(&peerl, oh323_destroy_peer);
+ ASTOBJ_CONTAINER_DESTROY(&peerl);
+ ASTOBJ_CONTAINER_DESTROYALL(&aliasl, oh323_destroy_alias);
+ ASTOBJ_CONTAINER_DESTROY(&aliasl);
+
return AST_MODULE_LOAD_FAILURE;
}
ast_cli_register_multiple(h323_cli, sizeof(h323_cli) / sizeof(h323_cli[0]));
@@ -2526,12 +2550,14 @@
h323_end_process();
io_context_destroy(io);
sched_context_destroy(sched);
- delete_users();
- delete_aliases();
- prune_peers();
- ast_mutex_destroy(&aliasl.lock);
- ast_mutex_destroy(&userl.lock);
- ast_mutex_destroy(&peerl.lock);
+
+ ASTOBJ_CONTAINER_DESTROYALL(&userl, oh323_destroy_user);
+ ASTOBJ_CONTAINER_DESTROY(&userl);
+ ASTOBJ_CONTAINER_DESTROYALL(&peerl, oh323_destroy_peer);
+ ASTOBJ_CONTAINER_DESTROY(&peerl);
+ ASTOBJ_CONTAINER_DESTROYALL(&aliasl, oh323_destroy_alias);
+ ASTOBJ_CONTAINER_DESTROY(&aliasl);
+
return AST_MODULE_LOAD_FAILURE;
}
/* Possibly register with a GK */
@@ -2609,12 +2635,14 @@
h323_end_process();
io_context_destroy(io);
sched_context_destroy(sched);
- delete_users();
- delete_aliases();
- prune_peers();
- ast_mutex_destroy(&aliasl.lock);
- ast_mutex_destroy(&userl.lock);
- ast_mutex_destroy(&peerl.lock);
+
+ ASTOBJ_CONTAINER_DESTROYALL(&userl, oh323_destroy_user);
+ ASTOBJ_CONTAINER_DESTROY(&userl);
+ ASTOBJ_CONTAINER_DESTROYALL(&peerl, oh323_destroy_peer);
+ ASTOBJ_CONTAINER_DESTROY(&peerl);
+ ASTOBJ_CONTAINER_DESTROYALL(&aliasl, oh323_destroy_alias);
+ ASTOBJ_CONTAINER_DESTROY(&aliasl);
+
return 0;
}
Modified: team/pcadach/chan_h323-live/channels/h323/ast_h323.cpp
URL: http://svn.digium.com/view/asterisk/team/pcadach/chan_h323-live/channels/h323/ast_h323.cpp?rev=41332&r1=41331&r2=41332&view=diff
==============================================================================
--- team/pcadach/chan_h323-live/channels/h323/ast_h323.cpp (original)
+++ team/pcadach/chan_h323-live/channels/h323/ast_h323.cpp Wed Aug 30 08:07:29 2006
@@ -45,6 +45,7 @@
#endif
#include "asterisk/logger.h"
#include "asterisk/channel.h"
+#include "asterisk/astobj.h"
#ifdef __cplusplus
}
#endif
Modified: team/pcadach/chan_h323-live/channels/h323/chan_h323.h
URL: http://svn.digium.com/view/asterisk/team/pcadach/chan_h323-live/channels/h323/chan_h323.h?rev=41332&r1=41331&r2=41332&view=diff
==============================================================================
--- team/pcadach/chan_h323-live/channels/h323/chan_h323.h (original)
+++ team/pcadach/chan_h323-live/channels/h323/chan_h323.h Wed Aug 30 08:07:29 2006
@@ -49,7 +49,8 @@
/* structure to hold the valid asterisk users */
struct oh323_user {
- char name[80];
+ ASTOBJ_COMPONENTS(struct oh323_user);
+// char name[80];
char context[80];
char secret[80];
char callerid[80];
@@ -59,30 +60,30 @@
struct sockaddr_in addr;
struct ast_ha *ha;
call_options_t options;
- struct oh323_user *next;
};
/* structure to hold the valid asterisk peers
All peers are registered to a GK if there is one */
struct oh323_peer {
- char name[80];
+ ASTOBJ_COMPONENTS(struct oh323_peer);
+// char name[80];
char mailbox[80];
int delme;
struct sockaddr_in addr;
struct ast_ha *ha;
call_options_t options;
- struct oh323_peer *next;
};
/* structure to hold the H.323 aliases which get registered to
the H.323 endpoint and gatekeeper */
struct oh323_alias {
- char name[80];
+ ASTOBJ_COMPONENTS(struct oh323_alias);
+// char name[80];
char e164[20]; /* tells a GK to route this E.164 to this alias */
char prefix[500]; /* tells a GK this alias supports these prefixes */
char secret[20]; /* the H.235 password to send to the GK for authentication */
char context[80];
- struct oh323_alias *next;
+// struct oh323_alias *next;
};
/** call_details struct call detail records
More information about the asterisk-commits
mailing list