[asterisk-commits] branch crichter/config-update - r7834
/team/crichter/config-update/channels/
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Fri Jan 6 02:33:16 CST 2006
Author: crichter
Date: Fri Jan 6 02:33:14 2006
New Revision: 7834
URL: http://svn.digium.com/view/asterisk?rev=7834&view=rev
Log:
further code optimizations, no functional changes.
Modified:
team/crichter/config-update/channels/chan_misdn_config.c
Modified: team/crichter/config-update/channels/chan_misdn_config.c
URL: http://svn.digium.com/view/asterisk/team/crichter/config-update/channels/chan_misdn_config.c?rev=7834&r1=7833&r2=7834&view=diff
==============================================================================
--- team/crichter/config-update/channels/chan_misdn_config.c (original)
+++ team/crichter/config-update/channels/chan_misdn_config.c Fri Jan 6 02:33:14 2006
@@ -171,19 +171,17 @@
static int get_cfg_position (char *name, int type)
{
- int i, max;
+ int i;
switch (type) {
case PORT_CFG:
- max = NUM_PORT_ELEMENTS;
- for (i = 0; i < max; ++i) {
+ for (i = 0; i < NUM_PORT_ELEMENTS; ++i) {
if (!strcasecmp(name, port_spec[i].name))
return i;
}
break;
case GEN_CFG:
- max = NUM_GEN_ELEMENTS;
- for (i = 0; i < max; ++i) {
+ for (i = 0; i < NUM_GEN_ELEMENTS; ++i) {
if (!strcasecmp(name, gen_spec[i].name))
return i;
}
@@ -253,7 +251,7 @@
free(general_cfg[i].any);
}
-void misdn_cfg_get(int port, enum misdn_cfg_elements elem, void *buf, int bufsize)
+void misdn_cfg_get (int port, enum misdn_cfg_elements elem, void *buf, int bufsize)
{
int place;
@@ -264,54 +262,56 @@
}
misdn_cfg_lock();
-
if (elem == MISDN_CFG_PTP) {
if (!memcpy(buf, &ptp[port], (bufsize > ptp[port]) ? sizeof(ptp[port]) : bufsize))
- memset(buf, 0, bufsize);
- } else if (elem < MISDN_CFG_LAST) {
- if ((place = map[elem]) >= 0) {
- switch (port_spec[place].type) {
- case MISDN_CTYPE_STR:
- if (port_cfg[port][place].str) {
- if (!memccpy(buf, port_cfg[port][place].str, 0, bufsize))
+ memset(buf, 0, bufsize);
+ } else {
+ if ((place = map[elem]) < 0) {
+ memset (buf, 0, bufsize);
+ ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Invalid element (%d) requested.\n", elem);
+ } else {
+ if (elem < MISDN_CFG_LAST) {
+ switch (port_spec[place].type) {
+ case MISDN_CTYPE_STR:
+ if (port_cfg[port][place].str) {
+ if (!memccpy(buf, port_cfg[port][place].str, 0, bufsize))
+ memset(buf, 0, 1);
+ } else if (port_cfg[0][place].str) {
+ if (!memccpy(buf, port_cfg[0][place].str, 0, bufsize))
+ memset(buf, 0, 1);
+ else
+ memset(buf, 0, 1);
+ }
+ break;
+ default:
+ if (port_cfg[port][place].any)
+ memcpy(buf, port_cfg[port][place].any, bufsize);
+ else if (port_cfg[0][place].any)
+ memcpy(buf, port_cfg[0][place].any, bufsize);
+ else
+ memset(buf, 0, bufsize);
+ }
+ } else {
+ switch (gen_spec[place].type) {
+ case MISDN_CTYPE_STR:
+ if (!general_cfg[place].str || !memccpy(buf, general_cfg[place].str, 0, bufsize))
memset(buf, 0, 1);
- } else if (port_cfg[0][place].str) {
- if (!memccpy(buf, port_cfg[0][place].str, 0, bufsize))
- memset(buf, 0, 1);
+ break;
+ default:
+ if (general_cfg[place].any)
+ memcpy(buf, general_cfg[place].any, bufsize);
else
- memset(buf, 0, 1);
+ memset(buf, 0, bufsize);
}
- break;
- default:
- if (port_cfg[port][place].any)
- memcpy(buf, port_cfg[port][place].any, bufsize);
- else if (port_cfg[0][place].any)
- memcpy(buf, port_cfg[0][place].any, bufsize);
- else
- memset(buf, 0, bufsize);
- }
- } else
- memset(buf, 0, bufsize);
- } else if ((place = map[elem]) >= 0) {
- switch (gen_spec[place].type) {
- case MISDN_CTYPE_STR:
- if (!general_cfg[place].str || !memccpy(buf, general_cfg[place].str, 0, bufsize))
- memset(buf, 0, 1);
- break;
- default:
- if (general_cfg[place].any)
- memcpy(buf, general_cfg[place].any, bufsize);
- else
- memset(buf, 0, bufsize);
- }
- } else
- memset(buf, 0, bufsize);
-
+ }
+ }
+ }
misdn_cfg_unlock();
}
int misdn_cfg_is_msn_valid (int port, char* msn)
{
+ int re = 0;
struct msn_list *iter;
if (!misdn_cfg_is_port_valid(port)) {
@@ -326,12 +326,12 @@
iter = port_cfg[0][MISDN_CFG_MSNS-1].ml;
for (; iter; iter = iter->next)
if (*(iter->msn) == '*' || ast_extension_match(iter->msn, msn)) {
- misdn_cfg_unlock();
- return 1;
+ re = 1;
+ break;
}
misdn_cfg_unlock();
- return 0;
+ return re;
}
int misdn_cfg_is_port_valid (int port)
@@ -394,7 +394,7 @@
char tempbuf[BUFFERSIZE] = "";
struct msn_list *iter;
- if (!(elem > MISDN_GEN_FIRST) && !misdn_cfg_is_port_valid(port)) {
+ if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) {
*buf = 0;
ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Port number %d is not valid.\n", port);
return;
@@ -491,26 +491,25 @@
}
int misdn_cfg_get_next_port (int port)
-{
+{
+ int p = -1;
+
misdn_cfg_lock();
for (port++; port <= max_ports; port++) {
if (port_cfg[port]) {
- misdn_cfg_unlock();
- return port;
+ p = port;
+ break;
}
}
misdn_cfg_unlock();
- return -1;
+ return p;
}
int misdn_cfg_get_next_port_spin (int port)
{
- int ret = misdn_cfg_get_next_port(port);
- if (ret > 0)
- return ret;
-
- return misdn_cfg_get_next_port(0);
+ int p = misdn_cfg_get_next_port(port);
+ return (p > 0) ? p : misdn_cfg_get_next_port(0);
}
static int _parse (union misdn_cfg_pt *dest, char *value, enum misdn_cfg_type type, int boolint_def)
@@ -586,9 +585,6 @@
static void _build_general_config (struct ast_variable *v)
{
int pos;
-
- if (!v)
- return;
for (; v; v = v->next) {
if (((pos = get_cfg_position(v->name, GEN_CFG)) < 0) ||
@@ -756,17 +752,15 @@
p += NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt);
}
general_cfg = (union misdn_cfg_pt *)calloc(1, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
-
ptp = (int *)calloc(max_ports + 1, sizeof(int));
map = (int *)calloc(MISDN_GEN_LAST + 1, sizeof(int));
_enum_array_map();
}
else {
+ /* misdn reload */
_free_port_cfg();
_free_general_cfg();
- for (i = 0; i <= max_ports; ++i) {
- memset(port_cfg[i], 0, NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt));
- }
+ memset(port_cfg[0], 0, NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt) * (max_ports + 1));
memset(general_cfg, 0, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
memset(ptp, 0, sizeof(int) * (max_ports + 1));
}
More information about the asterisk-commits
mailing list