[svn-commits] branch north/chan_skinny-fixup r34338 -
/team/north/chan_skinny-fixup/channels/
svn-commits at lists.digium.com
svn-commits at lists.digium.com
Thu Jun 15 12:58:33 MST 2006
Author: north
Date: Thu Jun 15 14:58:33 2006
New Revision: 34338
URL: http://svn.digium.com/view/asterisk?rev=34338&view=rev
Log:
general cleanup
fix memory handling (replace a few malloc/memset with ast_calloc)
Modified:
team/north/chan_skinny-fixup/channels/chan_skinny.c
Modified: team/north/chan_skinny-fixup/channels/chan_skinny.c
URL: http://svn.digium.com/view/asterisk/team/north/chan_skinny-fixup/channels/chan_skinny.c?rev=34338&r1=34337&r2=34338&view=diff
==============================================================================
--- team/north/chan_skinny-fixup/channels/chan_skinny.c (original)
+++ team/north/chan_skinny-fixup/channels/chan_skinny.c Thu Jun 15 14:58:33 2006
@@ -1124,15 +1124,13 @@
break;
}
- a = d->addons;
- while (a) {
+ for (a = d->addons; a; a = a->next) {
if (!strcasecmp(a->type, "7914")) {
for (i = 0; i < 14; i++)
(btn++)->buttonDefinition = BT_CUST_LINESPEEDDIAL;
} else {
ast_log(LOG_WARNING, "Unknown addon type '%s' found. Skipping.\n", a->type);
}
- a = a->next;
}
return btn;
@@ -1548,13 +1546,13 @@
int new;
int old;
struct skinny_device *d = s->device;
- struct skinny_line *l = d->lines;
+ struct skinny_line *l;
*/
transmit_displaymessage(s, NULL);
/*
- while (l) {
+ for (l = d->lines; l; l = l->next) {
if (has_voicemail(l)) {
if (skinnydebug)
ast_verbose("Checking for voicemail Skinny %s@%s\n", l->name, d->name);
@@ -1565,7 +1563,6 @@
} else {
transmit_lamp_indication(s, STIMULUS_VOICEMAIL, l->instance, SKINNY_LAMP_OFF);
}
- l = l->next;
}
*/
}
@@ -1696,14 +1693,14 @@
return RESULT_SHOWUSAGE;
}
ast_mutex_lock(&devicelock);
- d = devices;
ast_cli(fd, "Name DeviceId IP TypeId R NL\n");
ast_cli(fd, "-------------------- ---------------- --------------- ------ - --\n");
- while(d) {
- l = d->lines;
+ for (d = devices; d; d = d->next) {
numlines = 0;
- while(l) { numlines++; l = l->next; }
+ for (l = d->lines; l; l = l->next) {
+ numlines++;
+ }
ast_cli(fd, "%-20s %-16s %-15s %6X %c %2d\n",
d->name,
@@ -1712,8 +1709,6 @@
d->type,
d->registered?'Y':'N',
numlines);
-
- d = d->next;
}
ast_mutex_unlock(&devicelock);
return RESULT_SUCCESS;
@@ -1728,41 +1723,18 @@
return RESULT_SHOWUSAGE;
}
ast_mutex_lock(&devicelock);
- d = devices;
-
-#if 0
- ast_cli(fd, "Device Name Instance Name Label O R\n");
- ast_cli(fd, "-------------------- -------- -------------------- -------------------- - -\n");
- while(d) {
- l = d->lines;
- while (l) {
- ast_cli(fd, "%-20s %8d %-20s %-20s %c %c\n",
- d->name,
- l->instance,
- l->name,
- l->label,
- sub->owner?'Y':'N',
- sub->rtp?'Y':'N');
- l = l->next;
- }
- d = d->next;
- }
-#else
+
ast_cli(fd, "Device Name Instance Name Label \n");
ast_cli(fd, "-------------------- -------- -------------------- --------------------\n");
- while(d) {
- l = d->lines;
- while (l) {
+ for (d = devices; d; d = d->next) {
+ for (l = d->lines; l; l = l->next) {
ast_cli(fd, "%-20s %8d %-20s %-20s\n",
d->name,
l->instance,
l->name,
l->label);
- l = l->next;
- }
- d = d->next;
- }
-#endif
+ }
+ }
ast_mutex_unlock(&devicelock);
return RESULT_SUCCESS;
@@ -1887,13 +1859,11 @@
} else if (!strcasecmp(v->name, "linelabel")) {
ast_copy_string(linelabel, v->value, sizeof(linelabel));
} else if (!strcasecmp(v->name, "speeddial")) {
- sd = malloc(sizeof(struct skinny_speeddial));
- if (sd) {
+ if (!(sd = ast_calloc(1, sizeof(struct skinny_speeddial)))) {
char *stringp, *exten, *label;
stringp = v->value;
exten = strsep(&stringp, ",");
label = strsep(&stringp, ",");
- memset(sd, 0, sizeof(struct skinny_speeddial));
ast_mutex_init(&sd->lock);
ast_copy_string(sd->exten, exten, sizeof(sd->exten));
if (label)
@@ -1905,28 +1875,20 @@
sd->next = d->speeddials;
d->speeddials = sd;
} else {
- /* XXX Should find a way to clean up our memory */
- ast_log(LOG_WARNING, "Out of memory allocating speeddial.\n");
return NULL;
}
} else if (!strcasecmp(v->name, "addon")) {
- a = malloc(sizeof(struct skinny_addon));
- if (a) {
- memset(a, 0, sizeof(struct skinny_addon));
+ if (!(a = ast_calloc(1, sizeof(struct skinny_addon)))) {
ast_mutex_init(&a->lock);
ast_copy_string(a->type, v->value, sizeof(a->type));
a->next = d->addons;
d->addons = a;
} else {
- /* XXX Should find a way to clean up our memory */
- ast_log(LOG_WARNING, "Out of memory allocating addon.\n");
return NULL;
}
} else if (!strcasecmp(v->name, "trunk") || !strcasecmp(v->name, "line")) {
- l = malloc(sizeof(struct skinny_line));
- if (l) {
- memset(l, 0, sizeof(struct skinny_line));
+ if (!(l = ast_calloc(1, sizeof(struct skinny_line)))) {
ast_mutex_init(&l->lock);
ast_copy_string(l->name, v->value, sizeof(l->name));
@@ -1969,8 +1931,6 @@
l->next = d->lines;
d->lines = l;
} else {
- /* XXX Should find a way to clean up our memory */
- ast_log(LOG_WARNING, "Out of memory allocating line.\n");
return NULL;
}
} else {
@@ -3143,13 +3103,11 @@
int btnSet = 0;
switch (btn[i].buttonDefinition) {
case BT_CUST_LINESPEEDDIAL:
- l = d->lines;
- sd = d->speeddials;
/* assume failure */
req->data.buttontemplate.definition[i].buttonDefinition = htolel(BT_NONE);
req->data.buttontemplate.definition[i].instanceNumber = htolel(0);
- while (l) {
+ for (l = d->lines; l; l = l->next) {
if (l->instance == lineInstance) {
ast_verbose("Adding button: %d, %d\n", BT_LINE, lineInstance);
req->data.buttontemplate.definition[i].buttonDefinition = htolel(BT_LINE);
@@ -3158,11 +3116,10 @@
btnSet = 1;
break;
}
- l = l->next;
}
if (!btnSet) {
- while (sd) {
+ for (sd = d->speeddials; sd; sd = sd->next) {
if (sd->instance == speeddialInstance) {
ast_verbose("Adding button: %d, %d\n", BT_SPEEDDIAL, speeddialInstance);
req->data.buttontemplate.definition[i].buttonDefinition = htolel(BT_SPEEDDIAL);
@@ -3171,16 +3128,14 @@
btnSet = 1;
break;
}
- sd = sd->next;
}
}
break;
case BT_LINE:
- l = d->lines;
req->data.buttontemplate.definition[i].buttonDefinition = htolel(BT_NONE);
req->data.buttontemplate.definition[i].instanceNumber = htolel(0);
- while (l) {
+ for (l = d->lines; l; l = l->next) {
if (l->instance == lineInstance) {
ast_verbose("Adding button: %d, %d\n", BT_LINE, lineInstance);
req->data.buttontemplate.definition[i].buttonDefinition = htolel(BT_LINE);
@@ -3189,15 +3144,13 @@
btnSet = 1;
break;
}
- l = l->next;
}
break;
case BT_SPEEDDIAL:
- sd = d->speeddials;
req->data.buttontemplate.definition[i].buttonDefinition = BT_NONE;
req->data.buttontemplate.definition[i].instanceNumber = 0;
- while (sd) {
+ for (sd = d->speeddials; sd; sd = sd->next) {
if (sd->instance == speeddialInstance) {
ast_verbose("Adding button: %d, %d\n", BT_SPEEDDIAL, speeddialInstance);
req->data.buttontemplate.definition[i].buttonDefinition = htolel(BT_SPEEDDIAL);
@@ -3206,7 +3159,6 @@
btnSet = 1;
break;
}
- sd = sd->next;
}
break;
case BT_CUST_HINT:
@@ -3867,19 +3819,10 @@
{
skinny_req *req;
-#if 0
- req = malloc(SKINNY_MAX_PACKET);
- memset(req, 0, sizeof(skinny_req));
-#endif
-
if (!(req = ast_calloc(1, SKINNY_MAX_PACKET)))
return NULL;
ast_mutex_lock(&s->lock);
- /* +8 to account for reserved and length fields
- memcpy(req, s->inbuf, skinny_header_size);
- memcpy(data, s->inbuf+skinny_header_size, letohl(*(int*)(s->inbuf))-4);
- */
memcpy(req, s->inbuf, skinny_header_size);
memcpy(&req->data, s->inbuf+skinny_header_size, letohl(*(int*)(s->inbuf))-4);
@@ -3955,14 +3898,6 @@
ast_log(LOG_WARNING, "Failed to set Skinny tcp connection to TCP_NODELAY mode: %s\n", strerror(errno));
}
}
-/*
- s = malloc(sizeof(struct skinnysession));
- if (!s) {
- ast_log(LOG_WARNING, "Failed to allocate Skinny session: %s\n", strerror(errno));
- continue;
- }
- memset(s, 0, sizeof(struct skinnysession));
-*/
if (!(s = ast_calloc(1, sizeof(struct skinnysession))))
continue;
@@ -4065,10 +4000,6 @@
}
if (option_verbose > 2) {
ast_verbose(VERBOSE_PREFIX_3 "skinny_request(%s)\n", tmp);
-#if 0
- ast_verbose(VERBOSE_PREFIX_3 "Skinny cw: %d, dnd: %d, so: %d, sno: %d\n",
- l->callwaiting, l->dnd, sub->owner ? 1 : 0, (sub->next && sub->next->owner) ? 1: 0);
-#endif
}
tmpc = skinny_new(l, AST_STATE_DOWN);
if (!tmpc) {
More information about the svn-commits
mailing list