summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot2009-07-05 22:14:21 +0200
committerroot2009-07-05 22:14:21 +0200
commite9bfe48fc5254e79e59c6ffc1698912175edf4e3 (patch)
tree63c13b3d019b9a45bcd1b48354e243f133292401
parentChanged GSM api to current development tree of OpenBSC. (diff)
downloadlcr-e9bfe48fc5254e79e59c6ffc1698912175edf4e3.tar.gz
lcr-e9bfe48fc5254e79e59c6ffc1698912175edf4e3.tar.xz
lcr-e9bfe48fc5254e79e59c6ffc1698912175edf4e3.zip
Source cleanup.
modified: bootstrap.c modified: cause.c modified: crypt.cpp modified: endpoint.cpp modified: genext.c modified: genrc.c modified: gentones.c modified: genwave.c modified: ie.cpp modified: join.cpp modified: joinpbx.cpp modified: joinremote.cpp modified: lcradmin.c modified: mail.c modified: main.c modified: message.c modified: route.c modified: socket_server.c modified: tones.c modified: trace.c modified: vbox.cpp
-rw-r--r--bootstrap.c128
-rw-r--r--cause.c3
-rw-r--r--crypt.cpp312
-rw-r--r--endpoint.cpp27
-rw-r--r--genext.c21
-rw-r--r--genrc.c27
-rw-r--r--gentones.c120
-rw-r--r--genwave.c27
-rw-r--r--ie.cpp396
-rw-r--r--join.cpp15
-rw-r--r--joinpbx.cpp219
-rw-r--r--joinremote.cpp18
-rw-r--r--lcradmin.c537
-rw-r--r--mail.c27
-rw-r--r--main.c219
-rw-r--r--message.c5
-rw-r--r--route.c669
-rw-r--r--socket_server.c297
-rw-r--r--tones.c187
-rw-r--r--trace.c73
-rw-r--r--vbox.cpp63
21 files changed, 1128 insertions, 2262 deletions
diff --git a/bootstrap.c b/bootstrap.c
index b2d2b0c..96f7ec2 100644
--- a/bootstrap.c
+++ b/bootstrap.c
@@ -636,7 +636,7 @@ static u_int8_t si1[] = {
/* s1 reset*/0x2B
};
-static u_int8_t *gsm48_si1(struct gsm_bts_conf *conf)
+static u_int8_t *gsm48_si1(u_int8_t *arfcn_list, int arfcn_len, int max_trans, int tx_integer, int cell_barr, int re, int ec, u_int8_t *ac_list, int ac_len)
{
static u_int8_t si[23];
int i, bit, octet;
@@ -647,24 +647,24 @@ static u_int8_t *gsm48_si1(struct gsm_bts_conf *conf)
si[0] = 0x55;
si[1] = 0x06;
si[2] = 0x19;
- /* ccdesc 10.5.2.1b.2 (bit map 0 format) */
- for (i = 0; i < conf->arfcn_len; i++) {
- if (conf->arfcn_list[i] <= 124 && conf->arfcn_list[i] > 0) {
- bit = (conf->arfcn_list[i] - 1) & 7;
- octet = (conf->arfcn_list[i] -1) / 8;
+ /* ccdesc */
+ for (i = 0; i < arfcn_len; i++) {
+ if (arfcn_list[i] <= 124 && arfcn_list[i] > 0) {
+ bit = (arfcn_list[i] - 1) & 7;
+ octet = (arfcn_list[i] -1) / 8;
si[18 - octet] |= (1 << bit);
}
}
- /* rach 10.5.2.29 */
- si[19] = (conf->max_trans << 6);
- si[19] |= (conf->tx_integer << 2);
- si[19] |= (conf->cell_barr << 1);
- si[19] |= conf->re;
- si[20] = (conf->ec << 2);
- for (i = 0; i < conf->ac_len; i++) {
- if (conf->ac_list[i] <= 15 && conf->ac_list[i] != 10) {
- bit = conf->ac_list[i] & 7;
- octet = conf->ac_list[i] / 8;
+ /* rach */
+ si[19] = (max_trans << 6);
+ si[19] |= (tx_integer << 2);
+ si[19] |= (cell_barr << 1);
+ si[19] |= re;
+ si[20] = (ec << 2);
+ for (i = 0; i < ac_len; i++) {
+ if (ac_list[i] <= 15 && ac_list[i] != 10) {
+ bit = ac_list[i] & 7;
+ octet = ac_list[i] / 8;
si[21 - octet] |= (1 << bit);
}
}
@@ -701,7 +701,7 @@ static u_int8_t si2[] = {
/* rach*/0xD5, 0x00, 0x00
};
-static u_int8_t *gsm48_si2(struct gsm_bts_conf *conf)
+static u_int8_t *gsm48_si2(int ba, u_int8_t *arfcn_list, int arfcn_len, u_int8_t ncc, int max_trans, int tx_integer, int cell_barr, int re, int ec, u_int8_t *ac_list, int ac_len)
{
static u_int8_t si[23];
int i, bit, octet;
@@ -712,27 +712,27 @@ static u_int8_t *gsm48_si2(struct gsm_bts_conf *conf)
si[0] = 0x59;
si[1] = 0x06;
si[2] = 0x1A;
- /* ncdesc 10.5.2.22 */
- si[3] = (ba_ind << 4);
- for (i = 0; i < conf->ncell_arfcn_len; i++) {
- if (conf->ncell_arfcn_list[i] <= 124 && conf->ncell_arfcn_list[i] > 0) {
- bit = (conf->ncell_arfcn_list[i] - 1) & 7;
- octet = (conf->ncell_arfcn_list[i] -1) / 8;
+ /* ncdesc */
+ si[3] = (ba << 4);
+ for (i = 0; i < arfcn_len; i++) {
+ if (arfcn_list[i] <= 124 && arfcn_list[i] > 0) {
+ bit = (arfcn_list[i] - 1) & 7;
+ octet = (arfcn_list[i] -1) / 8;
si[18 - octet] |= (1 << bit);
}
}
- /* ncc 10.5.2.27 */
- si[19] = conf->ncc;
- /* rach 10.5.2.29 */
- si[20] = (conf->max_trans << 6);
- si[20] |= (conf->tx_integer << 2);
- si[20] |= (conf->cell_barr << 1);
- si[20] |= conf->re;
- si[21] = (conf->ec << 2);
- for (i = 0; i < conf->ac_len; i++) {
- if (conf->ac_list[i] <= 15 && conf->ac_list[i] != 10) {
- bit = conf->ac_list[i] & 7;
- octet = data->ac_list[i] / 8;
+ /* ncc */
+ si[19] = ncc;
+ /* rach */
+ si[20] = (max_trans << 6);
+ si[20] |= (tx_integer << 2);
+ si[20] |= (cell_barr << 1);
+ si[20] |= re;
+ si[21] = (ec << 2);
+ for (i = 0; i < ac_len; i++) {
+ if (ac_list[i] <= 15 && ac_list[i] != 10) {
+ bit = ac_list[i] & 7;
+ octet = ac_list[i] / 8;
si[22 - octet] |= (1 << bit);
}
}
@@ -784,7 +784,6 @@ SYSTEM INFORMATION TYPE 3
Scheduling Information is not sent in SYSTEM INFORMATION TYPE 9 on the BCCH
*/
static u_int8_t si3[] = {
-#warning nicht 0x59 == 22 octets + length
/* header */0x49, 0x06, 0x1B,
/* cell */0x00, 0x01,
/* lai */0x00, 0xF1, 0x10, 0x00, 0x01,
@@ -792,60 +791,9 @@ static u_int8_t si3[] = {
/* option*/0x28,
/* selection*/0x62, 0x00,
/* rach */0xD5, 0x00, 0x00,
- /* rest */0x80, 0x00, 0x00, 0x2B
+ /* reset*/0x80, 0x00, 0x00, 0x2B
};
-static u_int8_t *gsm48_si3(struct gsm_net *net, struct gsm_bts_conf *conf)
-{
- static u_int8_t si[23];
- int i, bit, octet;
-
- memset(&si, 0, sizeof(si));
-
- /* header */
-#warning testing
- si[0] = 0x59;
- si[1] = 0x06;
- si[2] = 0x1B;
- /* cell 10.5.1.1 */
- si[3] = ci >> 8;
- si[4] = ci;
- /* lai 10.5.1.3 */
- gsm0408_generate_lai(&si[5], network->country_code,
- network->network_code,
- conf->location_area_code);
- /* desc 10.5.2.11 */
- si[10] = conf->att << 6;
- si[10] |= conf->bs_ag_blks_res << 3;
- si[10] |= conf->ccch_conf;
- si[11] = conf->bs_pa_mfrms;
- si[12] = conf->t3212_decihours;
- /* option 10.5.2.3 */
- si[13] = conf->pwrc << 6;
- si[13] |= conf->dtx << 4;
- si[13] |= conf->rl_timeout;
- /* selection 10.5.2.4 */
- si[14] = conf->csel_hyst << 5;
- si[14] |= conf->ms_txpwr_max_cch;
- si[15] = conf->acs << 7;
- si[15] |= conf->neci << 6;
- si[15] |= conf->rxlev_access_min;
- /* rach 10.5.2.29 */
- si[16] = (conf->max_trans << 6);
- si[16] |= (conf->tx_integer << 2);
- si[16] |= (conf->cell_barr << 1);
- si[16] |= conf->re;
- si[17] = (conf->ec << 2);
- for (i = 0; i < conf->ac_len; i++) {
- if (conf->ac_list[i] <= 15 && conf->ac_list[i] != 10) {
- bit = conf->ac_list[i] & 7;
- octet = data->ac_list[i] / 8;
- si[18 - octet] |= (1 << bit);
- }
- }
- /* rest 10.5.2.34 */
-}
-
/*
SYSTEM INFORMATION TYPE 4
Location area identification
@@ -920,8 +868,8 @@ static u_int8_t *gsm48_si5(int ba, u_int8_t *arfcn_list, int arfcn_len)
}
/* testig */
- if (memcmp(&si5, &si, sizeof(si)))
- printf("SI5 does not match default template.\n");
+ if (memcmp(&si3, &si, sizeof(si)))
+ printf("SI3 does not match default template.\n");
return si;
}
diff --git a/cause.c b/cause.c
index b6fba82..3b9ae8d 100644
--- a/cause.c
+++ b/cause.c
@@ -340,8 +340,7 @@ char *get_isdn_cause(int cause, int location, int type)
if (cause<0 || cause>127)
cause = 0;
- switch(type)
- {
+ switch(type) {
case DISPLAY_CAUSE_NUMBER:
SPRINT(result, "Cause %d", cause);
break;
diff --git a/crypt.cpp b/crypt.cpp
index 87a5dde..ee8e7cc 100644
--- a/crypt.cpp
+++ b/crypt.cpp
@@ -160,11 +160,9 @@ unsigned char *crypt_key(unsigned char *key, int *binary_len)
return(NULL);
/* check for 0xXXXX... type of key */
- if (!strncmp((char *)key, "0x", 2))
- {
+ if (!strncmp((char *)key, "0x", 2)) {
key+=2;
- while(*key)
- {
+ while(*key) {
if (i == (int)sizeof(binary_key))
return(NULL);
@@ -212,15 +210,13 @@ static unsigned int get_bogomips(void)
char buffer[64], *p;
fp = fopen("/proc/cpuinfo", "r");
- if (!fp)
- {
+ if (!fp) {
PERROR("Cannot access /proc/cpuinfo. Will not use cpuinfo for identification of pear\n");
return(0);
}
fduse++;
buffer[sizeof(buffer-1)] = '\0';
- while(fgets(buffer, sizeof(buffer)-1, fp))
- {
+ while(fgets(buffer, sizeof(buffer)-1, fp)) {
if (!!strncmp(buffer, "bogomips", 8))
continue;
if (!strchr(buffer, ':'))
@@ -250,8 +246,7 @@ static unsigned int crc_reflect(unsigned int ref, char ch)
int i;
i = 1;
- while(i < ch+1)
- {
+ while(i < ch+1) {
if(ref & 1)
value |= 1 << (ch - i);
ref >>= 1;
@@ -269,12 +264,10 @@ void crc_init(void)
int i, j;
i = 0;
- while(i < 256)
- {
+ while(i < 256) {
crc32_table[i] = crc_reflect(i, 8) << 24;
j = 0;
- while(j < 8)
- {
+ while(j < 8) {
crc32_table[i] = (crc32_table[i] << 1) ^ (crc32_table[i] & (1 << 31) ? ulPolynomial : 0);
j++;
}
@@ -332,20 +325,17 @@ static void *keyengine_child(void *arg)
PDEBUG((DEBUG_EPOINT | DEBUG_CRYPT), "EPOINT(%d) child process started for using libcrypto\n", apppbx->ea_endpoint->ep_serial);
/* lower priority to keep pbx running fluently */
- if (options.schedule > 0)
- {
+ if (options.schedule > 0) {
memset(&schedp, 0, sizeof(schedp));
schedp.sched_priority = 0;
ret = sched_setscheduler(0, SCHED_OTHER, &schedp);
- if (ret < 0)
- {
+ if (ret < 0) {
PERROR("Scheduling to normal priority failed (errno = %d).\nExitting child process...\n", errno);
goto done;
}
}
- switch(job)
- {
+ switch(job) {
/* generate rsa key pair */
case CK_GENRSA_REQ:
#ifndef CRYPTO
@@ -357,16 +347,14 @@ static void *keyengine_child(void *arg)
exponent = 65537;
// if (exponent < 3) exponent = 3; /* >= 3 */
rsa = RSA_generate_key(RSA_BITS, exponent, NULL, NULL);
- if (!rsa)
- {
+ if (!rsa) {
PERROR("Failed to generate rsa key pair.\n");
apppbx->e_crypt_keyengine_return = -1;
break;
}
ememuse++;
apppbx->e_crypt_rsa_n_len = BN_num_bytes(rsa->n);
- if (apppbx->e_crypt_rsa_n_len > (int)sizeof(apppbx->e_crypt_rsa_n))
- {
+ if (apppbx->e_crypt_rsa_n_len > (int)sizeof(apppbx->e_crypt_rsa_n)) {
kerror_buffer:
PERROR("e_crypt_rsa_* too small for bignum.\n");
apppbx->e_crypt_keyengine_return = -1;
@@ -426,8 +414,7 @@ static void *keyengine_child(void *arg)
/* generating session key */
srandom(*((unsigned int *)mISDN_rand) ^ random());
i = 0;
- while(i < 56)
- {
+ while(i < 56) {
apppbx->e_crypt_key[i] = random();
apppbx->e_crypt_key[i] ^= mISDN_rand[random() & 0xff];
i++;
@@ -435,8 +422,7 @@ static void *keyengine_child(void *arg)
apppbx->e_crypt_key_len = i;
/* encrypt via rsa */
rsa = RSA_new();
- if (!rsa)
- {
+ if (!rsa) {
PERROR("Failed to allocate rsa structure.\n");
apppbx->e_crypt_keyengine_return = 1;
break;
@@ -444,16 +430,14 @@ static void *keyengine_child(void *arg)
ememuse++;
rsa->n = BN_new();
rsa->e = BN_new();
- if (!rsa->n || !rsa->e)
- {
+ if (!rsa->n || !rsa->e) {
PERROR("Failed to generate rsa structure.\n");
apppbx->e_crypt_keyengine_return = -1;
RSA_free(rsa);
ememuse--;
break;
}
- if (!BN_bin2bn(apppbx->e_crypt_rsa_n, apppbx->e_crypt_rsa_n_len, rsa->n))
- {
+ if (!BN_bin2bn(apppbx->e_crypt_rsa_n, apppbx->e_crypt_rsa_n_len, rsa->n)) {
eerror_bin2bn:
PERROR("Failed to convert binary to bignum.\n");
apppbx->e_crypt_keyengine_return = -1;
@@ -461,8 +445,7 @@ static void *keyengine_child(void *arg)
ememuse--;
break;
}
- if ((apppbx->e_crypt_rsa_n_len*8) != BN_num_bits(rsa->n))
- {
+ if ((apppbx->e_crypt_rsa_n_len*8) != BN_num_bits(rsa->n)) {
PERROR("SOFTWARE API ERROR: length not equal stored data. (%d != %d)\n", apppbx->e_crypt_rsa_n_len*8, BN_num_bits(rsa->n));
apppbx->e_crypt_keyengine_return = -1;
RSA_free(rsa);
@@ -497,8 +480,7 @@ static void *keyengine_child(void *arg)
apppbx->e_crypt_keyengine_return = -1;
#else
rsa = RSA_new();
- if (!rsa)
- {
+ if (!rsa) {
PERROR("Failed to allocate rsa structure.\n");
apppbx->e_crypt_keyengine_return = 1;
break;
@@ -515,16 +497,14 @@ static void *keyengine_child(void *arg)
if (!rsa->n || !rsa->e
|| !rsa->d || !rsa->p
|| !rsa->q || !rsa->dmp1
- || !rsa->dmq1 || !rsa->iqmp)
- {
+ || !rsa->dmq1 || !rsa->iqmp) {
PERROR("Failed to generate rsa structure.\n");
apppbx->e_crypt_keyengine_return = 1;
RSA_free(rsa);
ememuse--;
break;
}
- if (!BN_bin2bn(apppbx->e_crypt_rsa_n, apppbx->e_crypt_rsa_n_len, rsa->n))
- {
+ if (!BN_bin2bn(apppbx->e_crypt_rsa_n, apppbx->e_crypt_rsa_n_len, rsa->n)) {
derror_bin2bn:
PERROR("Failed to convert binary to bignum.\n");
apppbx->e_crypt_keyengine_return = -1;
@@ -580,8 +560,7 @@ void EndpointAppPBX::cryptman_keyengine(int job)
struct auth_args *arg;
pthread_t tid;
- if (e_crypt_keyengine_busy)
- {
+ if (e_crypt_keyengine_busy) {
e_crypt_keyengine_return = -1;
PERROR("engine currently busy.\n");
return;
@@ -594,8 +573,7 @@ void EndpointAppPBX::cryptman_keyengine(int job)
e_crypt_keyengine_busy = job;
ea_endpoint->ep_use++;
- if ((pthread_create(&tid, NULL, keyengine_child, arg)<0))
- {
+ if ((pthread_create(&tid, NULL, keyengine_child, arg)<0)) {
ea_endpoint->ep_use--;
PERROR("failed to create keyengine-thread.\n");
e_crypt_keyengine_return = -1;
@@ -612,17 +590,13 @@ void EndpointAppPBX::cryptman_keyengine(int job)
*/
void EndpointAppPBX::cryptman_handler(void)
{
- if (e_crypt_keyengine_busy)
- {
- if (e_crypt_keyengine_return < 0)
- {
+ if (e_crypt_keyengine_busy) {
+ if (e_crypt_keyengine_return < 0) {
e_crypt_keyengine_busy = 0;
cryptman_message(CK_ERROR_IND, NULL, 0);
} else
- if (e_crypt_keyengine_return > 0)
- {
- switch(e_crypt_keyengine_busy)
- {
+ if (e_crypt_keyengine_return > 0) {
+ switch(e_crypt_keyengine_busy) {
case CK_GENRSA_REQ:
e_crypt_keyengine_busy = 0;
cryptman_message(CK_GENRSA_CONF, NULL, 0);
@@ -640,8 +614,7 @@ void EndpointAppPBX::cryptman_handler(void)
}
/* check for event, make next event */
- if (e_crypt_timeout_sec) if (e_crypt_timeout_sec<now_tv.tv_sec || (e_crypt_timeout_sec==now_tv.tv_sec && e_crypt_timeout_usec<now_tv.tv_usec))
- {
+ if (e_crypt_timeout_sec) if (e_crypt_timeout_sec<now_tv.tv_sec || (e_crypt_timeout_sec==now_tv.tv_sec && e_crypt_timeout_usec<now_tv.tv_usec)) {
e_crypt_timeout_sec = 0;
e_crypt_timeout_usec = 0;
cryptman_message(CT_TIMEOUT, NULL, 0);
@@ -660,29 +633,25 @@ void EndpointAppPBX::cr_ident(int message, unsigned char *param, int len)
int l;
l = CM_SIZEOFINF(CM_INFO_RANDOM);
- if (l != 4)
- {
+ if (l != 4) {
PDEBUG(DEBUG_CRYPT, "EPOINT(%d) missing (or corrupt) random number, ignoring (len = %d)\n", ea_endpoint->ep_serial, l);
return;
}
p = CM_GETINF(CM_INFO_RANDOM, buf);
ran = (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3];
l = CM_SIZEOFINF(CM_INFO_BOGOMIPS);
- if (l != 4)
- {
+ if (l != 4) {
PDEBUG(DEBUG_CRYPT, "EPOINT(%d) missing (or corrupt) random bogomips, just comparing random (len = %d)\n", ea_endpoint->ep_serial, l);
goto compare_random;
}
p = CM_GETINF(CM_INFO_BOGOMIPS, buf);
bogomips = (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3];
- if (e_crypt_bogomips > bogomips)
- {
+ if (e_crypt_bogomips > bogomips) {
PDEBUG(DEBUG_CRYPT, "EPOINT(%d) our cpu is faster, so we are master (%d > %d)\n", ea_endpoint->ep_serial, e_crypt_bogomips, bogomips);
cr_master(message, NULL, 0);
return;
}
- if (e_crypt_bogomips < bogomips)
- {
+ if (e_crypt_bogomips < bogomips) {
PDEBUG(DEBUG_CRYPT, "EPOINT(%d) our cpu is slower, so we are slave (%d < %d)\n", ea_endpoint->ep_serial, e_crypt_bogomips, bogomips);
cr_slave(message, NULL, 0);
return;
@@ -690,14 +659,12 @@ void EndpointAppPBX::cr_ident(int message, unsigned char *param, int len)
PDEBUG(DEBUG_CRYPT, "EPOINT(%d) our cpu is equal speed, so we check for random value (%d == %d)\n", ea_endpoint->ep_serial, e_crypt_bogomips, bogomips);
compare_random:
/* bogomips are equal, so we compare */
- if (e_crypt_random > ran)
- {
+ if (e_crypt_random > ran) {
PDEBUG(DEBUG_CRYPT, "EPOINT(%d) our random value is greater, so we are master (%d > %d)\n", ea_endpoint->ep_serial, e_crypt_random, ran);
cr_master(message, NULL, 0);
return;
}
- if (e_crypt_random < ran)
- {
+ if (e_crypt_random < ran) {
PDEBUG(DEBUG_CRYPT, "EPOINT(%d) our random value is smaller, so we are slave (%d < %d)\n", ea_endpoint->ep_serial, e_crypt_random, ran);
cr_slave(message, NULL, 0);
return;
@@ -728,8 +695,7 @@ void EndpointAppPBX::cr_activate(int message, unsigned char *param, int len)
CM_ADDINF(CM_INFO_RANDOM, 4, ran);
/* cpu speed element */
e_crypt_bogomips = get_bogomips();
- if (e_crypt_bogomips > 0)
- {
+ if (e_crypt_bogomips > 0) {
bogomips[0] = e_crypt_bogomips >> 24;
bogomips[1] = e_crypt_bogomips >> 16;
bogomips[2] = e_crypt_bogomips >> 8;
@@ -772,8 +738,7 @@ void EndpointAppPBX::cr_master(int message, unsigned char *param, int len)
/* change to master state */
cryptman_state(CM_ST_KEYGEN);
- if (message == CP_IDENT)
- {
+ if (message == CP_IDENT) {
/* send you-are-slave-message */
msg = CMSG_SLAVE;
CM_ADDINF(CM_INFO_MESSAGE, 1, &msg);
@@ -795,8 +760,7 @@ void EndpointAppPBX::cr_slave(int message, unsigned char *param, int len)
/* change to slave state */
cryptman_state(CM_ST_KEYWAIT);
- if (message == CP_IDENT)
- {
+ if (message == CP_IDENT) {
/* send you-are-slave-message */
msg = CMSG_MASTER;
/* message */
@@ -819,8 +783,7 @@ void EndpointAppPBX::cr_looped(int message, unsigned char *param, int len)
cryptman_state(CM_ST_NULL);
/* deactivate listener */
cryptman_msg2crengine(CR_UNLISTEN_REQ, NULL, 0);
- if (message == CP_IDENT)
- {
+ if (message == CP_IDENT) {
/* send looped */
msg = CMSG_LOOPED;
/* message */
@@ -839,8 +802,7 @@ void EndpointAppPBX::cr_abort(int message, unsigned char *param, int len)
/* if already encrypting */
if (e_crypt_state==CM_ST_WAIT_CRYPT
|| e_crypt_state==CM_ST_SWAIT
- || e_crypt_state==CM_ST_ACTIVE)
- {
+ || e_crypt_state==CM_ST_ACTIVE) {
/* deactivate blowfish */
cryptman_msg2crengine(CC_DACT_REQ, NULL, 0);
}
@@ -941,8 +903,7 @@ void EndpointAppPBX::cr_pubkey(int message, unsigned char *param, int len)
int l;
l = CM_SIZEOFINF(CM_INFO_PUBKEY);
- if (l<1 || l>(int)sizeof(e_crypt_rsa_n))
- {
+ if (l<1 || l>(int)sizeof(e_crypt_rsa_n)) {
size_error:
/* change to idle state */
cryptman_state(CM_ST_NULL);
@@ -1009,8 +970,7 @@ void EndpointAppPBX::cr_cskey(int message, unsigned char *param, int len)
/* disable timeout */
cryptman_timeout(0);
l = CM_SIZEOFINF(CM_INFO_CSKEY);
- if (l<1 || l>(int)sizeof(e_crypt_ckey))
- {
+ if (l<1 || l>(int)sizeof(e_crypt_ckey)) {
/* change to idle state */
cryptman_state(CM_ST_NULL);
/* deactivate listener */
@@ -1152,8 +1112,7 @@ void EndpointAppPBX::cryptman_message(int message, unsigned char *param, int len
if (message == CU_INFO_REQ)
{ cr_info(message, param, len); return; }
- switch(e_crypt_state)
- {
+ switch(e_crypt_state) {
/* in idle state */
case CM_ST_NULL:
if (message == CU_ACTK_REQ) /* request key-exchange encryption */
@@ -1307,49 +1266,41 @@ void EndpointAppPBX::cryptman_msg2man(unsigned char *param, int len)
/* check if frame is correct */
PDEBUG(DEBUG_CRYPT, "EPOINT(%d) message from peer to crypt_manager.\n", ea_endpoint->ep_serial);
- if (len == 0)
- {
+ if (len == 0) {
PDEBUG(DEBUG_CRYPT, "ignoring message with 0-length.\n");
return;
}
i = 0;
p = param;
- while(*p)
- {
- if (i == len)
- {
+ while(*p) {
+ if (i == len) {
PDEBUG(DEBUG_CRYPT, "end of message without 0-termination.\n");
return;
}
- if (i+3 > len)
- {
+ if (i+3 > len) {
PDEBUG(DEBUG_CRYPT, "message with element size, outside the frame length.\n");
return;
}
l = (p[1]<<8) + p[2];
// PDEBUG(DEBUG_CRYPT, " inf %d (len = %d)\n", *p, l);
- if (i+3+l > len)
- {
+ if (i+3+l > len) {
PDEBUG(DEBUG_CRYPT, "message with element data, outside the frame length.\n");
return;
}
i += l + 3;
p += l + 3;
}
- if (i+1 != len)
- {
+ if (i+1 != len) {
PDEBUG(DEBUG_CRYPT, "warning: received null-element before end of frame.\n");
}
l = CM_SIZEOFINF(CM_INFO_MESSAGE);
- if (l != 1)
- {
+ if (l != 1) {
PDEBUG(DEBUG_CRYPT, "received message without (valid) message element (len = %d)\n", len);
return;
}
CM_GETINF(CM_INFO_MESSAGE, &msg);
- switch (msg)
- {
+ switch (msg) {
case CMSG_IDENT:
cryptman_message(CP_IDENT, param, len);
break;
@@ -1380,11 +1331,9 @@ void EndpointAppPBX::cryptman_addinf(unsigned char *buf, int buf_size, int eleme
int l;
/* skip what we already have in the buffer */
- while (buf[0])
- {
+ while (buf[0]) {
l = (buf[1]<<8) + buf[2];
- if (l >= buf_size-3)
- {
+ if (l >= buf_size-3) {
PERROR("EPOINT(%d) buffer overflow while adding information to peer message.\n", ea_endpoint->ep_serial);
return;
}
@@ -1392,8 +1341,7 @@ void EndpointAppPBX::cryptman_addinf(unsigned char *buf, int buf_size, int eleme
buf += l + 3;
}
/* check if we have not enough space to add element including id, len, data, and the null-termination */
- if (len+4 > buf_size)
- {
+ if (len+4 > buf_size) {
PERROR("EPOINT(%d) cannot add element to message, because buffer would overflow.\n", ea_endpoint->ep_serial);
return;
}
@@ -1411,8 +1359,7 @@ int EndpointAppPBX::cryptman_sizeofinf(unsigned char *buf, int element)
int l;
/* skip what we already have in the buffer */
- while (buf[0])
- {
+ while (buf[0]) {
l = (buf[1]<<8) + buf[2];
if (buf[0] == element)
return(l);
@@ -1429,11 +1376,9 @@ unsigned char *EndpointAppPBX::cryptman_getinf(unsigned char *buf, int element,
int l;
/* skip what we already have in the buffer */
- while (buf[0])
- {
+ while (buf[0]) {
l = (buf[1]<<8) + buf[2];
- if (buf[0] == element)
- {
+ if (buf[0] == element) {
memcpy(to, buf+3, l);
return(to);
}
@@ -1453,14 +1398,12 @@ void EndpointAppPBX::cryptman_msg2peer(unsigned char *buf)
int l;
/* get len */
- while(p[0])
- {
+ while(p[0]) {
l = (p[1]<<8) + p[2];
len += l + 3;
p += l + 3;
}
- if (len+1 > (int)sizeof(message->param.crypt.data))
- {
+ if (len+1 > (int)sizeof(message->param.crypt.data)) {
PERROR("EPOINT(%d) message larger than allowed in param->crypt.data.\n", ea_endpoint->ep_serial);
return;
}
@@ -1471,12 +1414,10 @@ void EndpointAppPBX::cryptman_msg2peer(unsigned char *buf)
memcpy(message->param.crypt.data, buf, len+1);
message_put(message);
- if (options.deb & DEBUG_CRYPT)
- {
+ if (options.deb & DEBUG_CRYPT) {
PDEBUG(DEBUG_CRYPT, "EPOINT(%d) sending message\n", ea_endpoint->ep_serial);
p = buf;
- while(p[0])
- {
+ while(p[0]) {
l = (p[1]<<8) + p[2];
PDEBUG(DEBUG_CRYPT, " inf %d (len = %d)\n", p[0], l);
len += l + 3;
@@ -1491,8 +1432,7 @@ void EndpointAppPBX::cryptman_msg2crengine(int msg, unsigned char *buf, int len)
{
struct lcr_msg *message;
- if (len > (int)sizeof(message->param.crypt.data))
- {
+ if (len > (int)sizeof(message->param.crypt.data)) {
PERROR("EPOINT(%d) message larger than allowed in param->crypt.data.\n", ea_endpoint->ep_serial);
return;
}
@@ -1504,8 +1444,7 @@ void EndpointAppPBX::cryptman_msg2crengine(int msg, unsigned char *buf, int len)
memcpy(message->param.crypt.data, buf, len);
message_put(message);
- if (options.deb & DEBUG_CRYPT)
- {
+ if (options.deb & DEBUG_CRYPT) {
const char *msgtext = "<<UNKNOWN MESSAGE>>";
if (msg>=0 && msg<cm_msg_num)
@@ -1525,15 +1464,13 @@ void EndpointAppPBX::cryptman_msg2user(int msg, const char *text)
if (!text)
text = "";
SCPY(e_crypt_info, text);
- if (text[0])
- {
+ if (text[0]) {
UNCPY((char *)message->param.crypt.data, e_crypt_info, sizeof(message->param.crypt.data)-1);
message->param.crypt.len = strlen((char *)message->param.crypt.data)+1;
}
message_put(message);
- if (options.deb & DEBUG_CRYPT)
- {
+ if (options.deb & DEBUG_CRYPT) {
const char *msgtext = "<<UNKNOWN MESSAGE>>";
if (msg>=0 && msg<cm_msg_num)
@@ -1555,13 +1492,11 @@ void EndpointAppPBX::cryptman_state(int state)
*/
void EndpointAppPBX::cryptman_timeout(int secs)
{
- if (secs)
- {
+ if (secs) {
e_crypt_timeout_sec = now_tv.tv_sec+secs;
e_crypt_timeout_usec = now_tv.tv_usec;
PDEBUG(DEBUG_CRYPT, "Changing timeout to %d seconds\n", secs);
- } else
- {
+ } else {
e_crypt_timeout_sec = 0;
e_crypt_timeout_usec = 0;
PDEBUG(DEBUG_CRYPT, "turning timeout off\n", secs);
@@ -1576,8 +1511,7 @@ int cryptman_encode_bch(unsigned char *data, int len, unsigned char *buf, int bu
int overhead = 18;
len--; /* without null-termination */
- if (buf_len < len+overhead)
- {
+ if (buf_len < len+overhead) {
PERROR("frame too long for buffer");
return(0);
}
@@ -1620,8 +1554,7 @@ void PmISDN::cryptman_listen_bch(unsigned char *p, int l)
return;
/* check for the keyword */
- if (p_m_crypt_listen_state == 0)
- {
+ if (p_m_crypt_listen_state == 0) {
while((*p++)!='C' && l)
l--;
if (!l)
@@ -1631,14 +1564,11 @@ void PmISDN::cryptman_listen_bch(unsigned char *p, int l)
if (!l)
return;
}
- if (p_m_crypt_listen_state < 8)
- {
+ if (p_m_crypt_listen_state < 8) {
i = p_m_crypt_listen_state;
- while(i < 8)
- {
+ while(i < 8) {
l--;
- if (*p++ != "CRYPTMAN"[i])
- {
+ if (*p++ != "CRYPTMAN"[i]) {
p_m_crypt_listen_state = 0;
goto retry;
}
@@ -1651,64 +1581,55 @@ void PmISDN::cryptman_listen_bch(unsigned char *p, int l)
return;
}
/* high byte of length */
- if (p_m_crypt_listen_state == 8)
- {
+ if (p_m_crypt_listen_state == 8) {
p_m_crypt_listen_len = (*p++) << 8;
p_m_crypt_listen_state++;
if (!(--l))
return;
}
/* low byte of length */
- if (p_m_crypt_listen_state == 9)
- {
+ if (p_m_crypt_listen_state == 9) {
p_m_crypt_listen_len += *p++;
p_m_crypt_listen_state++;
if (!(--l))
return;
}
/* crc */
- if (p_m_crypt_listen_state == 10)
- {
+ if (p_m_crypt_listen_state == 10) {
p_m_crypt_listen_crc = (*p++) << 24;
p_m_crypt_listen_state++;
if (!(--l))
return;
}
- if (p_m_crypt_listen_state == 11)
- {
+ if (p_m_crypt_listen_state == 11) {
p_m_crypt_listen_crc += (*p++) << 16;
p_m_crypt_listen_state++;
if (!(--l))
return;
}
- if (p_m_crypt_listen_state == 12)
- {
+ if (p_m_crypt_listen_state == 12) {
p_m_crypt_listen_crc += (*p++) << 8;
p_m_crypt_listen_state++;
if (!(--l))
return;
}
- if (p_m_crypt_listen_state == 13)
- {
+ if (p_m_crypt_listen_state == 13) {
unsigned char lencheck[2];
p_m_crypt_listen_crc += *p++;
/* check for CRC */
lencheck[0] = p_m_crypt_listen_len >> 8;
lencheck[1] = p_m_crypt_listen_len & 0xff;
- if (crc32(lencheck, 2) != p_m_crypt_listen_crc)
- {
+ if (crc32(lencheck, 2) != p_m_crypt_listen_crc) {
PDEBUG(DEBUG_CRYPT, "PmISDN(%s) received a block of %d bytes, but checksumme of length is incorrect (must %08x is %08x\n", p_name, p_m_crypt_listen_len, crc32(lencheck, 2), p_m_crypt_listen_crc);
p_m_crypt_listen_state = 0;
goto retry;
}
- if (p_m_crypt_listen_len > (int)sizeof(p_m_crypt_listen_msg))
- {
+ if (p_m_crypt_listen_len > (int)sizeof(p_m_crypt_listen_msg)) {
PDEBUG(DEBUG_CRYPT, "PmISDN(%s) received a block of %d bytes, but too big for buffer (%d bytes)\n", p_name, p_m_crypt_listen_len, sizeof(p_m_crypt_listen_msg));
p_m_crypt_listen_state = 0;
goto retry;
}
- if (!p_m_crypt_listen_len)
- {
+ if (!p_m_crypt_listen_len) {
PDEBUG(DEBUG_CRYPT, "PmISDN(%s) received a block of 0 bytes\n", p_name);
p_m_crypt_listen_state = 0;
goto retry;
@@ -1718,42 +1639,36 @@ void PmISDN::cryptman_listen_bch(unsigned char *p, int l)
return;
}
/* read message */
- while (p_m_crypt_listen_state>=14 && p_m_crypt_listen_state<(p_m_crypt_listen_len+14))
- {
+ while (p_m_crypt_listen_state>=14 && p_m_crypt_listen_state<(p_m_crypt_listen_len+14)) {
p_m_crypt_listen_msg[p_m_crypt_listen_state-14] = *p++;
p_m_crypt_listen_state++;
if (!(--l))
return;
}
/* crc */
- if (p_m_crypt_listen_state == 14+p_m_crypt_listen_len)
- {
+ if (p_m_crypt_listen_state == 14+p_m_crypt_listen_len) {
p_m_crypt_listen_crc = (*p++) << 24;
p_m_crypt_listen_state++;
if (!(--l))
return;
}
- if (p_m_crypt_listen_state == 15+p_m_crypt_listen_len)
- {
+ if (p_m_crypt_listen_state == 15+p_m_crypt_listen_len) {
p_m_crypt_listen_crc += (*p++) << 16;
p_m_crypt_listen_state++;
if (!(--l))
return;
}
- if (p_m_crypt_listen_state == 16+p_m_crypt_listen_len)
- {
+ if (p_m_crypt_listen_state == 16+p_m_crypt_listen_len) {
p_m_crypt_listen_crc += (*p++) << 8;
p_m_crypt_listen_state++;
if (!(--l))
return;
}
- if (p_m_crypt_listen_state == 17+p_m_crypt_listen_len)
- {
+ if (p_m_crypt_listen_state == 17+p_m_crypt_listen_len) {
l--;
p_m_crypt_listen_crc += *p++;
/* check for CRC */
- if (crc32(p_m_crypt_listen_msg, p_m_crypt_listen_len) != p_m_crypt_listen_crc)
- {
+ if (crc32(p_m_crypt_listen_msg, p_m_crypt_listen_len) != p_m_crypt_listen_crc) {
PDEBUG(DEBUG_CRYPT, "PmISDN(%s) received a block of %d bytes, but checksumme of data block is incorrect\n", p_name, p_m_crypt_listen_len);
p_m_crypt_listen_state = 0;
if (!l)
@@ -1763,8 +1678,7 @@ void PmISDN::cryptman_listen_bch(unsigned char *p, int l)
/* now send message */
p_m_crypt_listen_state = 0;
PDEBUG(DEBUG_CRYPT, "PmISDN(%s) received a block of %d bytes sending to crypt manager\n", p_name, p_m_crypt_listen_len);
- if ((int)sizeof(message->param.crypt.data) < p_m_crypt_listen_len+1) /* null-terminated */
- {
+ if ((int)sizeof(message->param.crypt.data) < p_m_crypt_listen_len+1) /* null-terminated */ {
PDEBUG(DEBUG_CRYPT, "PmISDN(%s) received a block of %d bytes that is too large for message buffer\n", p_name, p_m_crypt_listen_len);
if (!l)
return;
@@ -1796,8 +1710,7 @@ void EndpointAppPBX::encrypt_shared(void)
int ret;
/* redisplay current crypt display */
- if (e_crypt != CRYPT_OFF)
- {
+ if (e_crypt != CRYPT_OFF) {
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) encryption in progress, so we request the current message.\n", ea_endpoint->ep_serial);
message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_CRYPT);
message->param.crypt.type = CU_INFO_REQ;
@@ -1805,8 +1718,7 @@ void EndpointAppPBX::encrypt_shared(void)
return;
}
- if (check_external(&errstr, &port))
- {
+ if (check_external(&errstr, &port)) {
reject:
message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
SCPY(message->param.notifyinfo.display, errstr);
@@ -1819,58 +1731,48 @@ void EndpointAppPBX::encrypt_shared(void)
/* check the key for the call */
if (port->p_type==PORT_TYPE_DSS1_TE_OUT || port->p_type==PORT_TYPE_DSS1_NT_OUT)
ret = parse_secrets((char *)e_ext.number, (char *)port->p_dialinginfo.id, &auth_pointer, &crypt_pointer, &key_pointer);
- else
- {
- if (!port->p_callerinfo.id[0])
- {
+ else {
+ if (!port->p_callerinfo.id[0]) {
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) incoming remote call has no caller ID.\n", ea_endpoint->ep_serial);
errstr = "No Remote ID";
goto reject;
}
ret = parse_secrets((char *)e_ext.number, (char *)numberrize_callerinfo(port->p_callerinfo.id, port->p_callerinfo.ntype, options.national, options.international), &auth_pointer, &crypt_pointer, &key_pointer);
}
- if (!ret)
- {
+ if (!ret) {
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) Key was not found.\n", ea_endpoint->ep_serial);
errstr = "No Key";
goto reject;
}
key = crypt_key((unsigned char *)key_pointer, &key_len);
- if (!key)
- {
+ if (!key) {
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) Key invalid.\n", ea_endpoint->ep_serial);
errstr = "Invalid Key";
goto reject;
}
- if (key_len > 128)
- {
+ if (key_len > 128) {
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) Key too long.\n", ea_endpoint->ep_serial);
errstr = "Key Too Long";
goto reject;
}
- if (!!strcasecmp(auth_pointer, "manual"))
- {
+ if (!!strcasecmp(auth_pointer, "manual")) {
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) Wrong authentication method.\n", ea_endpoint->ep_serial);
errstr = "Wrong Auth Type";
goto reject;
}
- if (!strcasecmp(crypt_pointer, "blowfish"))
- {
+ if (!strcasecmp(crypt_pointer, "blowfish")) {
type = CC_ACTBF_REQ;
- if (key_len < 4)
- {
+ if (key_len < 4) {
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) Key too short.\n", ea_endpoint->ep_serial);
errstr = "Key Too Short";
goto reject;
}
- if (key_len > 56)
- {
+ if (key_len > 56) {
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) Key too long.\n", ea_endpoint->ep_serial);
errstr = "Key Too Long";
goto reject;
}
- } else
- {
+ } else {
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) Wrong crypt method.\n", ea_endpoint->ep_serial);
errstr = "Wrong Crypt Type";
goto reject;
@@ -1898,8 +1800,7 @@ void EndpointAppPBX::encrypt_keyex(void)
class Port *port;
/* redisplay current crypt display */
- if (e_crypt != CRYPT_OFF)
- {
+ if (e_crypt != CRYPT_OFF) {
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) encryption in progress, so we request the current message.\n", ea_endpoint->ep_serial);
message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_join_id, EPOINT_TO_JOIN, MESSAGE_CRYPT);
message->param.crypt.type = CU_INFO_REQ;
@@ -1908,8 +1809,7 @@ void EndpointAppPBX::encrypt_keyex(void)
}
- if (check_external(&errstr, &port))
- {
+ if (check_external(&errstr, &port)) {
message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
SCPY(message->param.notifyinfo.display, errstr);
message_put(message);
@@ -1946,15 +1846,13 @@ void EndpointAppPBX::encrypt_off(void)
{
struct lcr_msg *message;
- if (e_crypt!=CRYPT_ON && e_crypt!=CRYPT_OFF)
- {
+ if (e_crypt!=CRYPT_ON && e_crypt!=CRYPT_OFF) {
message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
SCPY(message->param.notifyinfo.display, "Please Wait");
message_put(message);
return;
}
- if (e_crypt == CRYPT_OFF)
- {
+ if (e_crypt == CRYPT_OFF) {
message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
SCPY(message->param.notifyinfo.display, "No Encryption");
message_put(message);
@@ -1983,8 +1881,7 @@ void EndpointAppPBX::encrypt_result(int msg, char *text)
{
struct lcr_msg *message;
- switch(msg)
- {
+ switch(msg) {
case CU_ACTK_CONF:
case CU_ACTS_CONF:
PDEBUG(DEBUG_EPOINT, "EPOINT(%d) encryption now active.\n", ea_endpoint->ep_serial);
@@ -1992,8 +1889,7 @@ void EndpointAppPBX::encrypt_result(int msg, char *text)
e_tone[0] = '\0';
e_crypt = CRYPT_ON;
display:
- if (text) if (text[0])
- {
+ if (text) if (text[0]) {
SCPY(e_crypt_info, text);
message = message_create(ea_endpoint->ep_serial, ea_endpoint->ep_portlist->port_id, EPOINT_TO_PORT, MESSAGE_NOTIFY);
SCPY(message->param.notifyinfo.display, e_crypt_info);
diff --git a/endpoint.cpp b/endpoint.cpp
index e9c680f..28ea12f 100644
--- a/endpoint.cpp
+++ b/endpoint.cpp
@@ -23,8 +23,7 @@ class Endpoint *find_epoint_id(unsigned int epoint_id)
{
class Endpoint *epoint = epoint_first;
- while(epoint)
- {
+ while(epoint) {
//printf("comparing: '%s' with '%s'\n", name, epoint->name);
if (epoint->ep_serial == epoint_id)
return(epoint);
@@ -62,11 +61,9 @@ Endpoint::Endpoint(unsigned int port_id, unsigned int join_id)
ep_serial = epoint_serial++;
/* link to join or port */
- if (port_id)
- {
+ if (port_id) {
port = find_port_id(port_id);
- if (port)
- {
+ if (port) {
if ((port->p_type&PORT_CLASS_MASK) == PORT_CLASS_mISDN)
earlyb = ((class PmISDN *)port)->p_m_mISDNport->earlyb;
if (!portlist_new(port_id, port->p_type, earlyb))
@@ -97,17 +94,14 @@ Endpoint::~Endpoint(void)
delete ep_app;
/* free relations */
- if (ep_join_id)
- {
+ if (ep_join_id) {
PERROR("warning: still relation to join.\n");
}
/* free portlist */
portlist = ep_portlist;
- while(portlist)
- {
- if (portlist->port_id)
- {
+ while(portlist) {
+ if (portlist->port_id) {
PERROR("warning: still relation to port (portlist list)\n");
}
mtemp = portlist;
@@ -120,8 +114,7 @@ Endpoint::~Endpoint(void)
/* detach */
temp =epoint_first;
tempp = &epoint_first;
- while(temp)
- {
+ while(temp) {
if (temp == this)
break;
@@ -171,8 +164,7 @@ void Endpoint::free_portlist(struct port_list *portlist)
temp = ep_portlist;
tempp = &ep_portlist;
- while(temp)
- {
+ while(temp) {
if (temp == portlist)
break;
@@ -195,8 +187,7 @@ void Endpoint::free_portlist(struct port_list *portlist)
*/
int Endpoint::handler(void)
{
- if (ep_use <= 0)
- {
+ if (ep_use <= 0) {
delete this;
return(-1);
}
diff --git a/genext.c b/genext.c
index 979a7c1..486af09 100644
--- a/genext.c
+++ b/genext.c
@@ -53,14 +53,12 @@ int main(int argc, char *argv[])
char pathname[256];
FILE *fp;
- if (!read_options())
- {
+ if (!read_options()) {
PERROR("%s", options_error);
return(-1);
}
- if (argc != 4)
- {
+ if (argc != 4) {
printf("Usage: %s <extension> <interfaces> <callerid>\n\n", argv[0]);
printf("extension: any number for the extension (e.g 200)\n");
printf("interfaces: internal interface(s) to reach extension, NOT port numbers\n");
@@ -70,8 +68,7 @@ int main(int argc, char *argv[])
}
SPRINT(pathname, "%s/%s", EXTENSION_DATA, argv[1]);
- if (mkdir(pathname, 0755) < 0)
- {
+ if (mkdir(pathname, 0755) < 0) {
if (errno == EEXIST)
PERROR("Extension's directory already exists. Nothing done!\n");
else PERROR("Cannot open extension's directory '%s'.\n", pathname);
@@ -91,12 +88,10 @@ int main(int argc, char *argv[])
write_extension(&ext, argv[1]);
SPRINT(pathname, "%s/%s/phonebook", EXTENSION_DATA, argv[1]);
- if (!(fp = fopen(pathname, "w")))
- {
+ if (!(fp = fopen(pathname, "w"))) {
PERROR("Failed to write phonebook example '%s'.\n", pathname);
return(-1);
- } else
- {
+ } else {
fprintf(fp, "# fromat: <shortcut> <phone number> [<Name>]\n");
fprintf(fp, "# The shotcut may have any number of digits. \n");
fprintf(fp, "# The phone number must include the dialing code for external, internal or\n");
@@ -113,12 +108,10 @@ int main(int argc, char *argv[])
}
SPRINT(pathname, "%s/%s/secrets", EXTENSION_DATA, argv[1]);
- if (!(fp = fopen(pathname, "w")))
- {
+ if (!(fp = fopen(pathname, "w"))) {
PERROR("Failed to write secrets example '%s'.\n", pathname);
return(-1);
- } else
- {
+ } else {
fprintf(fp, "# Format: <remote number> <key exchange> <cypher> [<key>]\n");
fprintf(fp, "# The remote number must match the dialed number for outgoing calls.\n");
fprintf(fp, "# The remote number must match the caller id for incoming calls.\n");
diff --git a/genrc.c b/genrc.c
index e5b998a..3e349f4 100644
--- a/genrc.c
+++ b/genrc.c
@@ -43,17 +43,14 @@ int main(void)
printf("\n\nThis program generates a script, which is used to start/stop/restart mISDN\n");
printf("driver. Please select card only once. Mode and options are given by LCR.\n");
- while(1)
- {
+ while(1) {
printf("\nSelect %sdriver for cards:\n\n", i?"another ":"");
jj = 0;
- while(cards[jj].name)
- {
+ while(cards[jj].name) {
printf(" (%d) %s\n", jj+1, cards[jj].name);
jj++;
}
- do
- {
+ do {
printf("\nSelect driver number[1-n] (or enter 'done'): "); fflush(stdout);
scanf("%s", input);
} while (atoi(input) <= 0 && !!strcmp(input, "done"));
@@ -63,8 +60,7 @@ int main(void)
break;
}
- if (!i)
- {
+ if (!i) {
printf("\nNo cards defined!\n");
return(-1);
}
@@ -95,8 +91,7 @@ int main(void)
printf("\n\nFinally tell me where to write the mISDN rc file.\nEnter the name 'mISDN' for current directory.\nYou may want to say '/usr/local/lcr/mISDN' or '/etc/rc.d/mISDN'\n: "); fflush(stdout);
scanf("%s", file);
- if (!(fp=fopen(file, "w")))
- {
+ if (!(fp=fopen(file, "w"))) {
fprintf(stderr, "\nError: Failed to open '%s', try again.\n", file);
exit(EXIT_FAILURE);
}
@@ -106,11 +101,9 @@ int main(void)
fprintf(fp, "\t\t%s %smISDN_core%s debug=0x%x\n", input[0]?"insmod -f":"modprobe --ignore-install", input, input[0]?".ko":"", coredebug);
fprintf(fp, "\t\t%s %smISDN_dsp%s debug=0x%x options=0x%x\n", input[0]?"insmod -f":"modprobe --ignore-install", input, input[0]?".ko":"", dspdebug, lawopt);
j = 0;
- while(cards[j].name)
- {
+ while(cards[j].name) {
jj = 0;
- while (jj < n)
- {
+ while (jj < n) {
if (type[jj] == j+1)
fprintf(fp, "\t\t%s %s%s%s debug=0x%x\n", input[0]?"insmod -f":"modprobe --ignore-install", input, cards[j].module, input[0]?".ko":"", carddebug);
jj++;
@@ -120,12 +113,10 @@ int main(void)
fprintf(fp, "\t\tsleep 1\n");
fprintf(fp, "\t\t;;\n\n");
fprintf(fp, "\tstop|--stop)\n");
- while(j)
- {
+ while(j) {
j--;
jj = 0;
- while (jj < n)
- {
+ while (jj < n) {
if (type[jj] == j+1)
fprintf(fp, "\t\trmmod %s\n", cards[j].module);
jj++;
diff --git a/gentones.c b/gentones.c
index daaf9cb..6cdaf37 100644
--- a/gentones.c
+++ b/gentones.c
@@ -91,16 +91,14 @@ unsigned char encode_isdn(short sample, char law)
int best_diff = 9999;
i=0;
- while(i<256)
- {
+ while(i<256) {
diff = (law=='u')?isdn_audio_ulaw_to_s16[i]:isdn_audio_alaw_to_s16[i]-sample;
//printf("s16=%d sample%d diff=%d\n",isdn_audio_to_s16[i],sample,diff);
if (diff<0)
diff=0-diff;
//printf("diff=%d\n",diff);
- if (diff<best_diff || best<0)
- {
+ if (diff<best_diff || best<0) {
//printf("better %d\n",i);
best_diff=diff;
best=i;
@@ -117,8 +115,7 @@ void write_tone(FILE *fp,double t1,double t2,int length,int fade_in,int fade_out
int i;
i=0;
- while(i<length)
- {
+ while(i<length) {
if (i < fade_in)
fade=(double)i / (double)fade_in;
else fade=1.0;
@@ -154,12 +151,10 @@ void write_wav(FILE *fp, char *wav, char law)
signed int size, chunk;
int gotfmt = 0, gotdata = 0;
- if ((wfp=fopen(wav,"r")))
- {
+ if ((wfp=fopen(wav,"r"))) {
fread(buffer,8,1,wfp);
size=(buffer[4]) + (buffer[5]<<8) + (buffer[6]<<16) + (buffer[7]<<24);
- if (!!strncmp((char *)buffer, "RIFF", 4))
- {
+ if (!!strncmp((char *)buffer, "RIFF", 4)) {
fclose(wfp);
fprintf(stderr, "Error: %s is no riff file!\n", wav);
return;
@@ -167,16 +162,13 @@ void write_wav(FILE *fp, char *wav, char law)
printf("%c%c%c%c size=%d\n",buffer[0],buffer[1],buffer[2],buffer[3],size);
fread(buffer,4,1,wfp);
size -= 4;
- if (!!strncmp((char *)buffer, "WAVE", 4))
- {
+ if (!!strncmp((char *)buffer, "WAVE", 4)) {
fclose(wfp);
fprintf(stderr, "Error: %s is no wave file!\n", wav);
return;
}
- while(size > 0)
- {
- if (size>0 && size<8)
- {
+ while(size > 0) {
+ if (size>0 && size<8) {
fclose(wfp);
fprintf(stderr, "Error: Remaining file size %d not large enough for next chunk.\n",size);
return;
@@ -185,38 +177,32 @@ void write_wav(FILE *fp, char *wav, char law)
chunk=(buffer[4]) + (buffer[5]<<8) + (buffer[6]<<16) + (buffer[7]<<24);
//printf("DEBUG: size(%d) - (8+chunk(%d) = size(%d)\n", size, chunk, size-chunk-8);
size -= (8+chunk);
- if (size < 0)
- {
+ if (size < 0) {
fclose(wfp);
fprintf(stderr, "Error: Chunk '%c%c%c%c' is larger than remainig file size (length=%d)\n",buffer[0],buffer[1],buffer[2],buffer[3], chunk);
return;
}
// printf("%c%c%c%c lenght=%d\n",buffer[0],buffer[1],buffer[2],buffer[3],chunk);
- if (!strncmp((char *)buffer, "fmt ", 4))
- {
- if (chunk != 16)
- {
+ if (!strncmp((char *)buffer, "fmt ", 4)) {
+ if (chunk != 16) {
fclose(wfp);
fprintf(stderr, "Error: Fmt chunk illegal size.\n");
return;
}
fread(buffer, chunk, 1, wfp);
fmt = (struct fmt *)buffer;
- if (fmt->channels<1 || fmt->channels>2)
- {
+ if (fmt->channels<1 || fmt->channels>2) {
fclose(wfp);
fprintf(stderr, "Error: Only support one or two channels file.\n");
return;
}
channels = fmt->channels;
printf("Channels: %d\n", channels);
- if (fmt->sample_rate != 8000)
- {
+ if (fmt->sample_rate != 8000) {
fprintf(stderr, "Warning: File has sample rate of %d.\n", fmt->sample_rate);
}
printf("Sample Rate: %d\n", fmt->sample_rate);
- if (fmt->bits_sample!=8 && fmt->bits_sample!=16)
- {
+ if (fmt->bits_sample!=8 && fmt->bits_sample!=16) {
fclose(wfp);
fprintf(stderr, "Error: File has neigher 8 nor 16 bit samples.\n");
return;
@@ -225,30 +211,24 @@ void write_wav(FILE *fp, char *wav, char law)
printf("Bit-Resolution: %d\n", bytes*16-16);
gotfmt = 1;
} else
- if (!strncmp((char *)buffer, "data", 4))
- {
- if (!gotfmt)
- {
+ if (!strncmp((char *)buffer, "data", 4)) {
+ if (!gotfmt) {
fclose(wfp);
fprintf(stderr, "Error: No fmt chunk fount in file.\n");
return;
}
printf("Length: %d samples (%d.%03d seconds)\n", chunk/bytes/channels, chunk/bytes/channels/8000, ((chunk/bytes/channels)%8000)*1000/8000);
i=0;
- if (bytes==2 && channels==1)
- {
- while(i<chunk)
- {
+ if (bytes==2 && channels==1) {
+ while(i<chunk) {
fread(buffer, 2, 1, wfp);
sample=(buffer[1]<<8) + (buffer[0]);
fputc(encode_isdn(sample, law),fp);
i+=2;
}
}
- if (bytes==2 && channels==2)
- {
- while(i<chunk)
- {
+ if (bytes==2 && channels==2) {
+ while(i<chunk) {
fread(buffer, 4, 1, wfp);
sample=(buffer[1]<<8) + (buffer[0]);
sample2=(buffer[3]<<8) + (buffer[2]);
@@ -257,20 +237,16 @@ void write_wav(FILE *fp, char *wav, char law)
i+=4;
}
}
- if (bytes==1 && channels==1)
- {
- while(i<chunk)
- {
+ if (bytes==1 && channels==1) {
+ while(i<chunk) {
fread(buffer, 1, 1, wfp);
sample=(buffer[0]<<8);
fputc(encode_isdn(sample, law),fp);
i+=1;
}
}
- if (bytes==1 && channels==2)
- {
- while(i<chunk)
- {
+ if (bytes==1 && channels==2) {
+ while(i<chunk) {
fread(buffer, 2, 1, wfp);
sample=(buffer[0]<<8);
sample2=(buffer[1]<<8);
@@ -280,11 +256,9 @@ void write_wav(FILE *fp, char *wav, char law)
}
}
gotdata = 1;
- } else
- {
+ } else {
printf("Ignoring chunk '%c%c%c%c' (length=%d)\n",buffer[0],buffer[1],buffer[2],buffer[3], chunk);
- while(chunk > (signed int)sizeof(buffer))
- {
+ while(chunk > (signed int)sizeof(buffer)) {
fread(buffer, sizeof(buffer), 1, wfp);
chunk -= sizeof(buffer);
}
@@ -294,8 +268,7 @@ void write_wav(FILE *fp, char *wav, char law)
}
fclose(wfp);
- if (!gotdata)
- {
+ if (!gotdata) {
fprintf(stderr, "Error: No data chunk fount in file.\n");
return;
}
@@ -306,8 +279,7 @@ int main(int argc, char *argv[])
{
FILE *fp;
- if (argc <= 1)
- {
+ if (argc <= 1) {
usage:
printf("Usage:\n");
printf("%s wave2alaw <wav file> <alaw file>\n", argv[0]);
@@ -320,56 +292,44 @@ int main(int argc, char *argv[])
return(0);
}
- if (!strcmp(argv[1], "wave2alaw"))
- {
+ if (!strcmp(argv[1], "wave2alaw")) {
if (argc <= 3)
goto usage;
- if ((fp=fopen(argv[3],"w")))
- {
+ if ((fp=fopen(argv[3],"w"))) {
write_wav(fp,argv[2],'a');
fclose(fp);
- } else
- {
+ } else {
printf("Cannot open isdn file %s\n",argv[3]);
}
} else
- if (!strcmp(argv[1], "wave2ulaw"))
- {
+ if (!strcmp(argv[1], "wave2ulaw")) {
if (argc <= 3)
goto usage;
- if ((fp=fopen(argv[3],"w")))
- {
+ if ((fp=fopen(argv[3],"w"))) {
write_wav(fp,argv[2],'u');
fclose(fp);
- } else
- {
+ } else {
printf("Cannot open isdn file %s\n",argv[3]);
}
} else
- if (!strcmp(argv[1], "tone2alaw"))
- {
+ if (!strcmp(argv[1], "tone2alaw")) {
if (argc <= 7)
goto usage;
- if ((fp=fopen(argv[7],"a")))
- {
+ if ((fp=fopen(argv[7],"a"))) {
write_tone(fp,strtod(argv[2],NULL),strtod(argv[3],NULL),atoi(argv[4]),atoi(argv[5]),atoi(argv[6]),'a');
fclose(fp);
- } else
- {
+ } else {
printf("Cannot open isdn file %s\n",argv[7]);
}
} else
- if (!strcmp(argv[1], "tone2ulaw"))
- {
+ if (!strcmp(argv[1], "tone2ulaw")) {
if (argc <= 7)
goto usage;
- if ((fp=fopen(argv[7],"a")))
- {
+ if ((fp=fopen(argv[7],"a"))) {
write_tone(fp,atoi(argv[2]),atoi(argv[3]),atoi(argv[4]),atoi(argv[5]),atoi(argv[6]),'u');
fclose(fp);
- } else
- {
+ } else {
printf("Cannot open isdn file %s\n",argv[7]);
}
} else
diff --git a/genwave.c b/genwave.c
index b397d3c..8f32076 100644
--- a/genwave.c
+++ b/genwave.c
@@ -101,8 +101,7 @@ void write_law(FILE *fp, char *name, char law)
short sample;
unsigned int size, wsize;
- if ((lfp=fopen(name,"r")))
- {
+ if ((lfp=fopen(name,"r"))) {
/* get size */
fseek(lfp, 0, SEEK_END);
size = ftell(lfp);
@@ -131,8 +130,7 @@ void write_law(FILE *fp, char *name, char law)
/* data */
fprintf(fp, "data%c%c%c%c", (char)(size&0xff), (char)((size>>8)&0xff), (char)((size>>16)&0xff), (char)(size>>24));
i = 0;
- while(i < size)
- {
+ while(i < size) {
fread(buffer, 1, 1, lfp);
if (law == 'a')
sample = isdn_audio_alaw_to_s16[*buffer];
@@ -156,8 +154,7 @@ int main(int argc, char *argv[])
{
FILE *fp;
- if (argc <= 1)
- {
+ if (argc <= 1) {
usage:
printf("Usage:\n");
printf("%s ulaw2wave <alaw file> <wav file>\n", argv[0]);
@@ -165,29 +162,23 @@ int main(int argc, char *argv[])
return(0);
}
- if (!strcmp(argv[1], "alaw2wave"))
- {
+ if (!strcmp(argv[1], "alaw2wave")) {
if (argc <= 3)
goto usage;
- if ((fp=fopen(argv[3],"w")))
- {
+ if ((fp=fopen(argv[3],"w"))) {
write_law(fp,argv[2],'a');
fclose(fp);
- } else
- {
+ } else {
printf("Cannot open wave file %s\n",argv[3]);
}
} else
- if (!strcmp(argv[1], "ulaw2wave"))
- {
+ if (!strcmp(argv[1], "ulaw2wave")) {
if (argc <= 3)
goto usage;
- if ((fp=fopen(argv[3],"w")))
- {
+ if ((fp=fopen(argv[3],"w"))) {
write_law(fp,argv[2],'u');
fclose(fp);
- } else
- {
+ } else {
printf("Cannot open wave file %s\n",argv[3]);
}
} else
diff --git a/ie.cpp b/ie.cpp
index 1e18b77..933287e 100644
--- a/ie.cpp
+++ b/ie.cpp
@@ -29,14 +29,12 @@ static void strnncpy(unsigned char *dest, unsigned char *src, int len, int dst_l
void Pdss1::enc_ie_complete(struct l3_msg *l3m, int complete)
{
- if (complete<0 || complete>1)
- {
+ if (complete<0 || complete>1) {
PERROR("complete(%d) is out of range.\n", complete);
return;
}
- if (complete)
- {
+ if (complete) {
add_trace("complete", NULL, NULL);
l3m->sending_complete++;
}
@@ -61,38 +59,31 @@ void Pdss1::enc_ie_bearer(struct l3_msg *l3m, int coding, int capability, int mo
unsigned char p[256];
int l;
- if (coding<0 || coding>3)
- {
+ if (coding<0 || coding>3) {
PERROR("coding(%d) is out of range.\n", coding);
return;
}
- if (capability<0 || capability>31)
- {
+ if (capability<0 || capability>31) {
PERROR("capability(%d) is out of range.\n", capability);
return;
}
- if (mode<0 || mode>3)
- {
+ if (mode<0 || mode>3) {
PERROR("mode(%d) is out of range.\n", mode);
return;
}
- if (rate<0 || rate>31)
- {
+ if (rate<0 || rate>31) {
PERROR("rate(%d) is out of range.\n", rate);
return;
}
- if (multi>127)
- {
+ if (multi>127) {
PERROR("multi(%d) is out of range.\n", multi);
return;
}
- if (user>31)
- {
+ if (user>31) {
PERROR("user L1(%d) is out of range.\n", user);
return;
}
- if (rate!=24 && multi>=0)
- {
+ if (rate!=24 && multi>=0) {
PERROR("multi(%d) is only possible if rate(%d) would be 24.\n", multi, rate);
multi = -1;
}
@@ -128,26 +119,22 @@ void Pdss1::dec_ie_bearer(struct l3_msg *l3m, int *coding, int *capability, int
unsigned char *p = l3m->bearer_capability;
if (!p)
return;
- if (p[0] < 2)
- {
+ if (p[0] < 2) {
add_trace("bearer", "error", "IE too short (len=%d)", p[0]);
return;
}
*coding = (p[1]&0x60) >> 5;
*capability = p[1] & 0x1f;
- if (p[0]>=2)
- {
+ if (p[0]>=2) {
*mode = (p[2]&0x60) >> 5;
*rate = p[2] & 0x1f;
}
- if (p[0]>=3 && *rate==0x18)
- {
+ if (p[0]>=3 && *rate==0x18) {
*multi = p[3] & 0x7f;
if (p[0]>=4)
*user = p[4] & 0x1f;
- } else
- {
+ } else {
if (p[0]>=3)
*user = p[3] & 0x1f;
}
@@ -167,28 +154,23 @@ void Pdss1::enc_ie_hlc(struct l3_msg *l3m, int coding, int interpretation, int p
unsigned char p[256];
int l;
- if (coding<0 || coding>3)
- {
+ if (coding<0 || coding>3) {
PERROR("coding(%d) is out of range.\n", coding);
return;
}
- if (interpretation<0 || interpretation>7)
- {
+ if (interpretation<0 || interpretation>7) {
PERROR("interpretation(%d) is out of range.\n", interpretation);
return;
}
- if (presentation<0 || presentation>3)
- {
+ if (presentation<0 || presentation>3) {
PERROR("presentation(%d) is out of range.\n", presentation);
return;
}
- if (hlc<0 || hlc>127)
- {
+ if (hlc<0 || hlc>127) {
PERROR("hlc(%d) is out of range.\n", hlc);
return;
}
- if (exthlc>127)
- {
+ if (exthlc>127) {
PERROR("hlc(%d) is out of range.\n", exthlc);
return;
}
@@ -204,8 +186,7 @@ void Pdss1::enc_ie_hlc(struct l3_msg *l3m, int coding, int interpretation, int p
p[0] = IE_HLC;
p[1] = l;
p[2] = 0x80 + (coding<<5) + (interpretation<<2) + presentation;
- if (exthlc >= 0)
- {
+ if (exthlc >= 0) {
p[3] = hlc;
p[4] = 0x80 + exthlc;
} else
@@ -224,8 +205,7 @@ void Pdss1::dec_ie_hlc(struct l3_msg *l3m, int *coding, int *interpretation, int
unsigned char *p = l3m->hlc;
if (!p)
return;
- if (p[0] < 2)
- {
+ if (p[0] < 2) {
add_trace("hlc", "error", "IE too short (len=%d)", p[0]);
return;
}
@@ -234,8 +214,7 @@ void Pdss1::dec_ie_hlc(struct l3_msg *l3m, int *coding, int *interpretation, int
*interpretation = (p[1]&0x1c) >> 2;
*presentation = p[1] & 0x03;
*hlc = p[2] & 0x7f;
- if (p[0]>=3)
- {
+ if (p[0]>=3) {
*exthlc = p[3] & 0x7f;
}
@@ -257,19 +236,16 @@ void Pdss1::enc_ie_call_id(struct l3_msg *l3m, unsigned char *callid, int callid
char buffer[25];
int i;
- if (!callid || callid_len<=0)
- {
+ if (!callid || callid_len<=0) {
return;
}
- if (callid_len > 8)
- {
+ if (callid_len > 8) {
PERROR("callid_len(%d) is out of range.\n", callid_len);
return;
}
i = 0;
- while(i < callid_len)
- {
+ while(i < callid_len) {
UPRINT(buffer+(i*3), " %02x", callid[i]);
i++;
}
@@ -293,8 +269,7 @@ void Pdss1::dec_ie_call_id(struct l3_msg *l3m, unsigned char *callid, int *calli
unsigned char *p = l3m->call_id;
if (!p)
return;
- if (p[0] > 8)
- {
+ if (p[0] > 8) {
add_trace("callid", "error", "IE too long (len=%d)", p[0]);
return;
}
@@ -303,8 +278,7 @@ void Pdss1::dec_ie_call_id(struct l3_msg *l3m, unsigned char *callid, int *calli
memcpy(callid, p+1, *callid_len);
i = 0;
- while(i < *callid_len)
- {
+ while(i < *callid_len) {
UPRINT(buffer+(i*3), " %02x", callid[i]);
i++;
}
@@ -319,18 +293,15 @@ void Pdss1::enc_ie_called_pn(struct l3_msg *l3m, int type, int plan, unsigned ch
unsigned char p[256];
int l;
- if (type<0 || type>7)
- {
+ if (type<0 || type>7) {
PERROR("type(%d) is out of range.\n", type);
return;
}
- if (plan<0 || plan>15)
- {
+ if (plan<0 || plan>15) {
PERROR("plan(%d) is out of range.\n", plan);
return;
}
- if (!number[0])
- {
+ if (!number[0]) {
PERROR("number is not given.\n");
return;
}
@@ -358,8 +329,7 @@ void Pdss1::dec_ie_called_pn(struct l3_msg *l3m, int *type, int *plan, unsigned
unsigned char *p = l3m->called_nr;
if (!p)
return;
- if (p[0] < 2)
- {
+ if (p[0] < 2) {
add_trace("called_pn", "error", "IE too short (len=%d)", p[0]);
return;
}
@@ -380,23 +350,19 @@ void Pdss1::enc_ie_calling_pn(struct l3_msg *l3m, int type, int plan, int presen
unsigned char p[256];
int l;
- if (type<0 || type>7)
- {
+ if (type<0 || type>7) {
PERROR("type(%d) is out of range.\n", type);
return;
}
- if (plan<0 || plan>15)
- {
+ if (plan<0 || plan>15) {
PERROR("plan(%d) is out of range.\n", plan);
return;
}
- if (present>3)
- {
+ if (present>3) {
PERROR("present(%d) is out of range.\n", present);
return;
}
- if (present >= 0) if (screen<0 || screen>3)
- {
+ if (present >= 0) if (screen<0 || screen>3) {
PERROR("screen(%d) is out of range.\n", screen);
return;
}
@@ -414,14 +380,12 @@ void Pdss1::enc_ie_calling_pn(struct l3_msg *l3m, int type, int plan, int presen
l += 1;
p[0] = IE_CALLING_PN;
p[1] = l;
- if (present >= 0)
- {
+ if (present >= 0) {
p[2] = 0x00 + (type<<4) + plan;
p[3] = 0x80 + (present<<5) + screen;
if (number) if (number[0])
UNCPY((char *)p+4, (char *)number, strlen((char *)number));
- } else
- {
+ } else {
p[2] = 0x80 + (type<<4) + plan;
if (number) if (number[0])
UNCPY((char *)p+3, (char *)number, strlen((char *)number));
@@ -432,23 +396,19 @@ void Pdss1::enc_ie_calling_pn(struct l3_msg *l3m, int type, int plan, int presen
if (type2 < 0)
return;
- if (type2>7)
- {
+ if (type2>7) {
PERROR("type2(%d) is out of range.\n", type2);
return;
}
- if (plan2<0 || plan2>15)
- {
+ if (plan2<0 || plan2>15) {
PERROR("plan2(%d) is out of range.\n", plan2);
return;
}
- if (present2>3)
- {
+ if (present2>3) {
PERROR("present2(%d) is out of range.\n", present2);
return;
}
- if (present2 >= 0) if (screen2<0 || screen2>3)
- {
+ if (present2 >= 0) if (screen2<0 || screen2>3) {
PERROR("screen2(%d) is out of range.\n", screen2);
return;
}
@@ -466,14 +426,12 @@ void Pdss1::enc_ie_calling_pn(struct l3_msg *l3m, int type, int plan, int presen
l += 1;
p[0] = IE_CALLING_PN;
p[1] = l;
- if (present2 >= 0)
- {
+ if (present2 >= 0) {
p[2] = 0x00 + (type2<<4) + plan2;
p[3] = 0x80 + (present2<<5) + screen2;
if (number2) if (number2[0])
UNCPY((char *)p+4, (char *)number2, strlen((char *)number2));
- } else
- {
+ } else {
p[2] = 0x80 + (type2<<4) + plan2;
if (number2) if (number2[0])
UNCPY((char *)p+3, (char *)number2, strlen((char *)number2));
@@ -499,26 +457,22 @@ void Pdss1::dec_ie_calling_pn(struct l3_msg *l3m, int *type, int *plan, int *pre
unsigned char *p = l3m->calling_nr;
if (!p)
return;
- if (p[0] < 1)
- {
+ if (p[0] < 1) {
add_trace("calling_pn", "error", "IE too short (len=%d)", p[0]);
return;
}
*type = (p[1]&0x70) >> 4;
*plan = p[1] & 0xf;
- if (!(p[1] & 0x80))
- {
- if (p[0] < 2)
- {
+ if (!(p[1] & 0x80)) {
+ if (p[0] < 2) {
add_trace("calling_pn", "error", "IE too short (len=%d)", p[0]);
return;
}
*present = (p[2]&0x60) >> 5;
*screen = p[2] & 0x3;
strnncpy(number, p+3, p[0]-2, number_len);
- } else
- {
+ } else {
strnncpy(number, p+2, p[0]-1, number_len);
}
@@ -531,12 +485,10 @@ void Pdss1::dec_ie_calling_pn(struct l3_msg *l3m, int *type, int *plan, int *pre
/* second calling party number */
p = NULL;
i = 0;
- while(i < numextra)
- {
+ while(i < numextra) {
if (!l3m->extra[i].val)
break;
- if (l3m->extra[i].ie == IE_CALLING_PN)
- {
+ if (l3m->extra[i].ie == IE_CALLING_PN) {
p = l3m->extra[i].val;
break;
}
@@ -544,26 +496,22 @@ void Pdss1::dec_ie_calling_pn(struct l3_msg *l3m, int *type, int *plan, int *pre
}
if (!p)
return;
- if (p[0] < 1)
- {
+ if (p[0] < 1) {
add_trace("calling_pn2", "error", "IE too short (len=%d)", p[0]);
return;
}
*type2 = (p[1]&0x70) >> 4;
*plan2 = p[1] & 0xf;
- if (!(p[1] & 0x80))
- {
- if (p[0] < 2)
- {
+ if (!(p[1] & 0x80)) {
+ if (p[0] < 2) {
add_trace("calling_pn2", "error", "IE too short (len=%d)", p[0]);
return;
}
*present2 = (p[2]&0x60) >> 5;
*screen2 = p[2] & 0x3;
strnncpy(number2, p+3, p[0]-2, number_len2);
- } else
- {
+ } else {
strnncpy(number2, p+2, p[0]-1, number_len2);
}
@@ -581,23 +529,19 @@ void Pdss1::enc_ie_connected_pn(struct l3_msg *l3m, int type, int plan, int pres
unsigned char p[256];
int l;
- if (type<0 || type>7)
- {
+ if (type<0 || type>7) {
PERROR("type(%d) is out of range.\n", type);
return;
}
- if (plan<0 || plan>15)
- {
+ if (plan<0 || plan>15) {
PERROR("plan(%d) is out of range.\n", plan);
return;
}
- if (present>3)
- {
+ if (present>3) {
PERROR("present(%d) is out of range.\n", present);
return;
}
- if (present >= 0) if (screen<0 || screen>3)
- {
+ if (present >= 0) if (screen<0 || screen>3) {
PERROR("screen(%d) is out of range.\n", screen);
return;
}
@@ -615,14 +559,12 @@ void Pdss1::enc_ie_connected_pn(struct l3_msg *l3m, int type, int plan, int pres
l += 1;
p[0] = IE_CONNECT_PN;
p[1] = l;
- if (present >= 0)
- {
+ if (present >= 0) {
p[2] = 0x00 + (type<<4) + plan;
p[3] = 0x80 + (present<<5) + screen;
if (number) if (number[0])
UNCPY((char *)p+4, (char *)number, strlen((char *)number));
- } else
- {
+ } else {
p[2] = 0x80 + (type<<4) + plan;
if (number) if (number[0])
UNCPY((char *)p+3, (char *)number, strlen((char *)number));
@@ -641,26 +583,22 @@ void Pdss1::dec_ie_connected_pn(struct l3_msg *l3m, int *type, int *plan, int *p
unsigned char *p = l3m->connected_nr;
if (!p)
return;
- if (p[0] < 1)
- {
+ if (p[0] < 1) {
add_trace("connect_pn", "error", "IE too short (len=%d)", p[0]);
return;
}
*type = (p[1]&0x70) >> 4;
*plan = p[1] & 0xf;
- if (!(p[1] & 0x80))
- {
- if (p[0] < 2)
- {
+ if (!(p[1] & 0x80)) {
+ if (p[0] < 2) {
add_trace("connect_pn", "error", "IE too short (len=%d)", p[0]);
return;
}
*present = (p[2]&0x60) >> 5;
*screen = p[2] & 0x3;
strnncpy(number, p+3, p[0]-2, number_len);
- } else
- {
+ } else {
strnncpy(number, p+2, p[0]-1, number_len);
}
@@ -678,13 +616,11 @@ void Pdss1::enc_ie_cause(struct l3_msg *l3m, int location, int cause)
unsigned char p[256];
int l;
- if (location<0 || location>7)
- {
+ if (location<0 || location>7) {
PERROR("location(%d) is out of range.\n", location);
return;
}
- if (cause<0 || cause>127)
- {
+ if (cause<0 || cause>127) {
PERROR("cause(%d) is out of range.\n", cause);
return;
}
@@ -718,8 +654,7 @@ void Pdss1::dec_ie_cause(struct l3_msg *l3m, int *location, int *cause)
unsigned char *p = l3m->cause;
if (!p)
return;
- if (p[0] < 2)
- {
+ if (p[0] < 2) {
add_trace("cause", "error", "IE too short (len=%d)", p[0]);
return;
}
@@ -739,23 +674,20 @@ void Pdss1::enc_ie_channel_id(struct l3_msg *l3m, int exclusive, int channel)
int l;
int pri = p_m_mISDNport->pri;
- if (exclusive<0 || exclusive>1)
- {
+ if (exclusive<0 || exclusive>1) {
PERROR("exclusive(%d) is out of range.\n", exclusive);
return;
}
if ((channel<=0 && channel!=CHANNEL_NO && channel!=CHANNEL_ANY)
|| (!pri && channel>2)
|| (pri && channel>127)
- || (pri && channel==16))
- {
+ || (pri && channel==16)) {
PERROR("channel(%d) is out of range.\n", channel);
return;
}
add_trace("channel_id", "exclusive", "%d", exclusive);
- switch(channel)
- {
+ switch(channel) {
case CHANNEL_ANY:
add_trace("channel_id", "channel", "any channel");
break;
@@ -766,8 +698,7 @@ void Pdss1::enc_ie_channel_id(struct l3_msg *l3m, int exclusive, int channel)
add_trace("channel_id", "channel", "%d", channel);
}
- if (!pri)
- {
+ if (!pri) {
/* BRI */
l = 1;
p[0] = IE_CHANNEL_ID;
@@ -778,13 +709,11 @@ void Pdss1::enc_ie_channel_id(struct l3_msg *l3m, int exclusive, int channel)
channel = 3;
p[2] = 0x80 + (exclusive<<3) + channel;
add_layer3_ie(l3m, p[0], p[1], p+2);
- } else
- {
+ } else {
/* PRI */
if (channel == CHANNEL_NO) /* no channel */
return; /* IE not present */
- if (channel == CHANNEL_ANY) /* any channel */
- {
+ if (channel == CHANNEL_ANY) /* any channel */ {
l = 1;
p[0] = IE_CHANNEL_ID;
p[1] = l;
@@ -812,29 +741,24 @@ void Pdss1::dec_ie_channel_id(struct l3_msg *l3m, int *exclusive, int *channel)
unsigned char *p = l3m->channel_id;
if (!p)
return;
- if (p[0] < 1)
- {
+ if (p[0] < 1) {
add_trace("channel_id", "error", "IE too short (len=%d)", p[0]);
return;
}
- if (p[1] & 0x40)
- {
+ if (p[1] & 0x40) {
add_trace("channel_id", "error", "refering to channels of other interfaces is not supported");
return;
}
- if (p[1] & 0x04)
- {
+ if (p[1] & 0x04) {
add_trace("channel_id", "error", "using d-channel is not supported");
return;
}
*exclusive = (p[1]&0x08) >> 3;
- if (!pri)
- {
+ if (!pri) {
/* BRI */
- if (p[1] & 0x20)
- {
+ if (p[1] & 0x20) {
add_trace("channel_id", "error", "extended channel ID with non PRI interface");
return;
}
@@ -843,53 +767,44 @@ void Pdss1::dec_ie_channel_id(struct l3_msg *l3m, int *exclusive, int *channel)
*channel = CHANNEL_ANY;
else if (*channel == 0)
*channel = CHANNEL_NO;
- } else
- {
+ } else {
/* PRI */
- if (p[0] < 1)
- {
+ if (p[0] < 1) {
add_trace("channel_id", "error", "IE too short for PRI (len=%d)", p[0]);
return;
}
- if (!(p[1] & 0x20))
- {
+ if (!(p[1] & 0x20)) {
add_trace("channel_id", "error", "basic channel ID with PRI interface");
return;
}
- if ((p[1]&0x03) == 0x00)
- {
+ if ((p[1]&0x03) == 0x00) {
/* no channel */
*channel = CHANNEL_NO;
return;
}
- if ((p[1]&0x03) == 0x03)
- {
+ if ((p[1]&0x03) == 0x03) {
/* any channel */
*channel = CHANNEL_ANY;
return;
}
- if (p[0] < 3)
- {
+ if (p[0] < 3) {
add_trace("channel_id", "error", "IE too short for PRI with channel (len=%d)", p[0]);
return;
}
- if (p[2] & 0x10)
- {
+ if (p[2] & 0x10) {
add_trace("channel_id", "error", "channel map not supported");
return;
}
*channel = p[3] & 0x7f;
- if ((*channel<1) || (*channel==16))
- {
+ if ((*channel<1) || (*channel==16)) {
add_trace("channel_id", "error", "PRI interface channel out of range (%d)", *channel);
return;
}
}
add_trace("channel_id", "exclusive", "%d", *exclusive);
- switch(*channel)
- {
+ switch(*channel) {
case CHANNEL_ANY:
add_trace("channel_id", "channel", "any channel");
break;
@@ -911,8 +826,7 @@ void Pdss1::enc_ie_date(struct l3_msg *l3m, time_t ti, int no_seconds)
struct tm *tm;
tm = localtime(&ti);
- if (!tm)
- {
+ if (!tm) {
PERROR("localtime() returned NULL.\n");
return;
}
@@ -940,14 +854,12 @@ void Pdss1::enc_ie_display(struct l3_msg *l3m, unsigned char *display)
unsigned char p[256];
int l;
- if (!display[0])
- {
+ if (!display[0]) {
PERROR("display text not given.\n");
return;
}
- if (strlen((char *)display) > 80)
- {
+ if (strlen((char *)display) > 80) {
PERROR("display text too long (max 80 chars), cutting.\n");
display[80] = '\0';
}
@@ -968,8 +880,7 @@ void Pdss1::dec_ie_display(struct l3_msg *l3m, unsigned char *display, int displ
unsigned char *p = l3m->display;
if (!p)
return;
- if (p[0] < 1)
- {
+ if (p[0] < 1) {
add_trace("display", "error", "IE too short (len=%d)", p[0]);
return;
}
@@ -986,8 +897,7 @@ void Pdss1::enc_ie_keypad(struct l3_msg *l3m, unsigned char *keypad)
unsigned char p[256];
int l;
- if (!keypad[0])
- {
+ if (!keypad[0]) {
PERROR("keypad info not given.\n");
return;
}
@@ -1008,8 +918,7 @@ void Pdss1::dec_ie_keypad(struct l3_msg *l3m, unsigned char *keypad, int keypad_
unsigned char *p = l3m->keypad;
if (!p)
return;
- if (p[0] < 1)
- {
+ if (p[0] < 1) {
add_trace("keypad", "error", "IE too short (len=%d)", p[0]);
return;
}
@@ -1026,8 +935,7 @@ void Pdss1::enc_ie_notify(struct l3_msg *l3m, int notify)
unsigned char p[256];
int l;
- if (notify<0 || notify>0x7f)
- {
+ if (notify<0 || notify>0x7f) {
PERROR("notify(%d) is out of range.\n", notify);
return;
}
@@ -1048,8 +956,7 @@ void Pdss1::dec_ie_notify(struct l3_msg *l3m, int *notify)
unsigned char *p = l3m->notify;
if (!p)
return;
- if (p[0] < 1)
- {
+ if (p[0] < 1) {
add_trace("notify", "error", "IE too short (len=%d)", p[0]);
return;
}
@@ -1066,18 +973,15 @@ void Pdss1::enc_ie_progress(struct l3_msg *l3m, int coding, int location, int pr
unsigned char p[256];
int l;
- if (coding<0 || coding>0x03)
- {
+ if (coding<0 || coding>0x03) {
PERROR("coding(%d) is out of range.\n", coding);
return;
}
- if (location<0 || location>0x0f)
- {
+ if (location<0 || location>0x0f) {
PERROR("location(%d) is out of range.\n", location);
return;
}
- if (progress<0 || progress>0x7f)
- {
+ if (progress<0 || progress>0x7f) {
PERROR("progress(%d) is out of range.\n", progress);
return;
}
@@ -1103,8 +1007,7 @@ void Pdss1::dec_ie_progress(struct l3_msg *l3m, int *coding, int *location, int
unsigned char *p = l3m->progress;
if (!p)
return;
- if (p[0] < 1)
- {
+ if (p[0] < 1) {
add_trace("progress", "error", "IE too short (len=%d)", p[0]);
return;
}
@@ -1125,28 +1028,23 @@ void Pdss1::enc_ie_redir_nr(struct l3_msg *l3m, int type, int plan, int present,
unsigned char p[256];
int l;
- if (type<0 || type>7)
- {
+ if (type<0 || type>7) {
PERROR("type(%d) is out of range.\n", type);
return;
}
- if (plan<0 || plan>15)
- {
+ if (plan<0 || plan>15) {
PERROR("plan(%d) is out of range.\n", plan);
return;
}
- if (present > 3)
- {
+ if (present > 3) {
PERROR("present(%d) is out of range.\n", present);
return;
}
- if (present >= 0) if (screen<0 || screen>3)
- {
+ if (present >= 0) if (screen<0 || screen>3) {
PERROR("screen(%d) is out of range.\n", screen);
return;
}
- if (reason > 0x0f)
- {
+ if (reason > 0x0f) {
PERROR("reason(%d) is out of range.\n", reason);
return;
}
@@ -1161,32 +1059,27 @@ void Pdss1::enc_ie_redir_nr(struct l3_msg *l3m, int type, int plan, int present,
l = 1;
if (number)
l += strlen((char *)number);
- if (present >= 0)
- {
+ if (present >= 0) {
l += 1;
if (reason >= 0)
l += 1;
}
p[0] = IE_REDIR_NR;
p[1] = l;
- if (present >= 0)
- {
- if (reason >= 0)
- {
+ if (present >= 0) {
+ if (reason >= 0) {
p[2] = 0x00 + (type<<4) + plan;
p[3] = 0x00 + (present<<5) + screen;
p[4] = 0x80 + reason;
if (number)
UNCPY((char *)p+5, (char *)number, strlen((char *)number));
- } else
- {
+ } else {
p[2] = 0x00 + (type<<4) + plan;
p[3] = 0x80 + (present<<5) + screen;
if (number)
UNCPY((char *)p+4, (char *)number, strlen((char *)number));
}
- } else
- {
+ } else {
p[2] = 0x80 + (type<<4) + plan;
if (number) if (number[0])
UNCPY((char *)p+3, (char *)number, strlen((char *)number));
@@ -1206,28 +1099,23 @@ void Pdss1::dec_ie_redir_nr(struct l3_msg *l3m, int *type, int *plan, int *prese
unsigned char *p = l3m->redirect_nr;
if (!p)
return;
- if (p[0] < 1)
- {
+ if (p[0] < 1) {
add_trace("redir'ing", "error", "IE too short (len=%d)", p[0]);
return;
}
*type = (p[1]&0x70) >> 4;
*plan = p[1] & 0xf;
- if (!(p[1] & 0x80))
- {
+ if (!(p[1] & 0x80)) {
*present = (p[2]&0x60) >> 5;
*screen = p[2] & 0x3;
- if (!(p[2] & 0x80))
- {
+ if (!(p[2] & 0x80)) {
*reason = p[3] & 0x0f;
strnncpy(number, p+4, p[0]-3, number_len);
- } else
- {
+ } else {
strnncpy(number, p+3, p[0]-2, number_len);
}
- } else
- {
+ } else {
strnncpy(number, p+2, p[0]-1, number_len);
}
@@ -1246,18 +1134,15 @@ void Pdss1::enc_ie_redir_dn(struct l3_msg *l3m, int type, int plan, int present,
unsigned char p[256];
int l;
- if (type<0 || type>7)
- {
+ if (type<0 || type>7) {
PERROR("type(%d) is out of range.\n", type);
return;
}
- if (plan<0 || plan>15)
- {
+ if (plan<0 || plan>15) {
PERROR("plan(%d) is out of range.\n", plan);
return;
}
- if (present > 3)
- {
+ if (present > 3) {
PERROR("present(%d) is out of range.\n", present);
return;
}
@@ -1274,14 +1159,12 @@ void Pdss1::enc_ie_redir_dn(struct l3_msg *l3m, int type, int plan, int present,
l += 1;
p[0] = IE_REDIR_DN;
p[1] = l;
- if (present >= 0)
- {
+ if (present >= 0) {
p[2] = 0x00 + (type<<4) + plan;
p[3] = 0x80 + (present<<5);
if (number)
UNCPY((char *)p+4, (char *)number, strlen((char *)number));
- } else
- {
+ } else {
p[2] = 0x80 + (type<<4) + plan;
if (number)
UNCPY((char *)p+3, (char *)number, strlen((char *)number));
@@ -1299,20 +1182,17 @@ void Pdss1::dec_ie_redir_dn(struct l3_msg *l3m, int *type, int *plan, int *prese
unsigned char *p = l3m->redirect_dn;
if (!p)
return;
- if (p[0] < 1)
- {
+ if (p[0] < 1) {
add_trace("redir'tion", "error", "IE too short (len=%d)", p[0]);
return;
}
*type = (p[1]&0x70) >> 4;
*plan = p[1] & 0xf;
- if (!(p[1] & 0x80))
- {
+ if (!(p[1] & 0x80)) {
*present = (p[2]&0x60) >> 5;
strnncpy(number, p+3, p[0]-2, number_len);
- } else
- {
+ } else {
strnncpy(number, p+2, p[0]-1, number_len);
}
@@ -1332,14 +1212,12 @@ void Pdss1::enc_ie_facility(struct l3_msg *l3m, unsigned char *facility, int fac
char buffer[768];
int i;
- if (!facility || facility_len<=0)
- {
+ if (!facility || facility_len<=0) {
return;
}
i = 0;
- while(i < facility_len)
- {
+ while(i < facility_len) {
UPRINT(buffer+(i*3), " %02x", facility[i]);
i++;
}
@@ -1368,8 +1246,7 @@ void Pdss1::dec_ie_facility(struct l3_msg *l3m, unsigned char *facility, int *fa
memcpy(facility, p+1, *facility_len);
i = 0;
- while(i < *facility_len)
- {
+ while(i < *facility_len) {
UPRINT(debug+(i*3), " %02x", facility[i]);
i++;
}
@@ -1388,8 +1265,7 @@ void Pdss1::dec_facility_centrex(struct l3_msg *l3m, unsigned char *cnip, int cn
*cnip = '\0';
dec_ie_facility(l3m, centrex, &facility_len);
- if (facility_len >= 2)
- {
+ if (facility_len >= 2) {
if (centrex[i++] != CENTREX_FAC)
return;
if (centrex[i++] != CENTREX_ID)
@@ -1397,15 +1273,12 @@ void Pdss1::dec_facility_centrex(struct l3_msg *l3m, unsigned char *cnip, int cn
}
/* loop sub IEs of facility */
- while(facility_len > i+1)
- {
- if (centrex[i+1]+i+1 > facility_len)
- {
+ while(facility_len > i+1) {
+ if (centrex[i+1]+i+1 > facility_len) {
PERROR("short read of centrex facility.\n");
return;
}
- switch(centrex[i])
- {
+ switch(centrex[i]) {
case 0x80:
strnncpy(cnip, &centrex[i+2], centrex[i+1], cnip_len);
add_trace("facility", "cnip", "%s", cnip);
@@ -1413,8 +1286,7 @@ void Pdss1::dec_facility_centrex(struct l3_msg *l3m, unsigned char *cnip, int cn
default:
j = 0;
- while(j < centrex[i+1])
- {
+ while(j < centrex[i+1]) {
UPRINT(debug+(j*3), " %02x", centrex[i+1+j]);
i++;
}
@@ -1434,19 +1306,16 @@ void Pdss1::enc_ie_useruser(struct l3_msg *l3m, int protocol, unsigned char *use
char buffer[768];
int i;
- if (protocol<0 || protocol>127)
- {
+ if (protocol<0 || protocol>127) {
PERROR("protocol(%d) is out of range.\n", protocol);
return;
}
- if (!user || user_len<=0)
- {
+ if (!user || user_len<=0) {
return;
}
i = 0;
- while(i < user_len)
- {
+ while(i < user_len) {
UPRINT(buffer+(i*3), " %02x", user[i]);
i++;
}
@@ -1481,8 +1350,7 @@ void Pdss1::dec_ie_useruser(struct l3_msg *l3m, int *protocol, unsigned char *us
memcpy(user, p+2, (*user_len<=128)?*(user_len):128); /* clip to 128 maximum */
i = 0;
- while(i < *user_len)
- {
+ while(i < *user_len) {
UPRINT(buffer+(i*3), " %02x", user[i]);
i++;
}
diff --git a/join.cpp b/join.cpp
index b3f8843..b1a06bb 100644
--- a/join.cpp
+++ b/join.cpp
@@ -27,8 +27,7 @@ class Join *find_join_id(unsigned int join_id)
{
class Join *join = join_first;
- while(join)
- {
+ while(join) {
//printf("comparing: '%s' with '%s'\n", name, join->j_name);
if (join->j_serial == join_id)
return(join);
@@ -71,8 +70,7 @@ Join::~Join()
cl = join_first;
clp = &join_first;
- while(cl)
- {
+ while(cl) {
if (cl == this)
break;
clp = &cl->next;
@@ -106,15 +104,12 @@ int Join::handler(void)
void join_free(void)
{
- if (!join_first)
- {
+ if (!join_first) {
PDEBUG(DEBUG_JOIN, "no more pending join(s), done!\n");
return;
}
- while(join_first)
- {
- if (options.deb & DEBUG_JOIN)
- {
+ while(join_first) {
+ if (options.deb & DEBUG_JOIN) {
PDEBUG(DEBUG_JOIN, "freeing pending join\n");
}
diff --git a/joinpbx.cpp b/joinpbx.cpp
index 630c599..5c686dc 100644
--- a/joinpbx.cpp
+++ b/joinpbx.cpp
@@ -24,11 +24,9 @@ static int notify_state_change(int join_id, int epoint_id, int old_state, int ne
if (old_state == new_state)
return(old_state);
- switch(old_state)
- {
+ switch(old_state) {
case NOTIFY_STATE_ACTIVE:
- switch(new_state)
- {
+ switch(new_state) {
case NOTIFY_STATE_HOLD:
notify_on = INFO_NOTIFY_REMOTE_HOLD;
break;
@@ -42,8 +40,7 @@ static int notify_state_change(int join_id, int epoint_id, int old_state, int ne
break;
case NOTIFY_STATE_HOLD:
- switch(new_state)
- {
+ switch(new_state) {
case NOTIFY_STATE_ACTIVE:
notify_off = INFO_NOTIFY_REMOTE_RETRIEVAL;
break;
@@ -59,8 +56,7 @@ static int notify_state_change(int join_id, int epoint_id, int old_state, int ne
break;
case NOTIFY_STATE_SUSPEND:
- switch(new_state)
- {
+ switch(new_state) {
case NOTIFY_STATE_ACTIVE:
notify_off = INFO_NOTIFY_USER_RESUMED;
break;
@@ -76,8 +72,7 @@ static int notify_state_change(int join_id, int epoint_id, int old_state, int ne
break;
case NOTIFY_STATE_CONFERENCE:
- switch(new_state)
- {
+ switch(new_state) {
case NOTIFY_STATE_ACTIVE:
notify_off = INFO_NOTIFY_CONFERENCE_DISCONNECTED;
break;
@@ -93,15 +88,13 @@ static int notify_state_change(int join_id, int epoint_id, int old_state, int ne
break;
}
- if (join_id && notify_off)
- {
+ if (join_id && notify_off) {
message = message_create(join_id, epoint_id, JOIN_TO_EPOINT, MESSAGE_NOTIFY);
message->param.notifyinfo.notify = notify_off;
message_put(message);
}
- if (join_id && notify_on)
- {
+ if (join_id && notify_on) {
message = message_create(join_id, epoint_id, JOIN_TO_EPOINT, MESSAGE_NOTIFY);
message->param.notifyinfo.notify = notify_on;
message_put(message);
@@ -129,11 +122,9 @@ void joinpbx_debug(class JoinPBX *joinpbx, const char *function)
if (!relation)
PDEBUG(DEBUG_JOIN, "join has no relations\n");
- while(relation)
- {
+ while(relation) {
epoint = find_epoint_id(relation->epoint_id);
- if (!epoint)
- {
+ if (!epoint) {
PDEBUG(DEBUG_JOIN, "warning: relations epoint id=%d doesn't exists!\n", relation->epoint_id);
relation = relation->next;
continue;
@@ -142,8 +133,7 @@ void joinpbx_debug(class JoinPBX *joinpbx, const char *function)
UPRINT(strchr(buffer,0), "*** ep%d", relation->epoint_id);
UPRINT(strchr(buffer,0), " ifs=");
portlist = epoint->ep_portlist;
- while(portlist)
- {
+ while(portlist) {
port = find_port_id(portlist->port_id);
if (port)
UPRINT(strchr(buffer,0), "%s,", port->p_name);
@@ -153,8 +143,7 @@ void joinpbx_debug(class JoinPBX *joinpbx, const char *function)
}
// UPRINT(strchr(buffer,0), " endpoint=%d on=%s hold=%s", epoint->ep_serial, (epoint->ep_join_id==joinpbx->j_serial)?"yes":"no", (epoint->get_hold_id()==joinpbx->j_serial)?"yes":"no");
UPRINT(strchr(buffer,0), " endpoint=%d on=%s", epoint->ep_serial, (epoint->ep_join_id==joinpbx->j_serial)?"yes":"no");
- switch(relation->type)
- {
+ switch(relation->type) {
case RELATION_TYPE_CALLING:
UPRINT(strchr(buffer,0), " type=CALLING");
break;
@@ -172,8 +161,7 @@ void joinpbx_debug(class JoinPBX *joinpbx, const char *function)
UPRINT(strchr(buffer,0), " channel=CONNECT");
else
UPRINT(strchr(buffer,0), " channel=HOLD");
- switch(relation->tx_state)
- {
+ switch(relation->tx_state) {
case NOTIFY_STATE_ACTIVE:
UPRINT(strchr(buffer,0), " tx_state=ACTIVE");
break;
@@ -190,8 +178,7 @@ void joinpbx_debug(class JoinPBX *joinpbx, const char *function)
UPRINT(strchr(buffer,0), " tx_state=unknown");
break;
}
- switch(relation->rx_state)
- {
+ switch(relation->rx_state) {
case NOTIFY_STATE_ACTIVE:
UPRINT(strchr(buffer,0), " rx_state=ACTIVE");
break;
@@ -265,8 +252,7 @@ JoinPBX::~JoinPBX()
struct join_relation *relation, *rtemp;
relation = j_relation;
- while(relation)
- {
+ while(relation) {
rtemp = relation->next;
FREE(relation, sizeof(struct join_relation));
cmemuse--;
@@ -293,30 +279,26 @@ void JoinPBX::bridge(void)
#endif
relation = j_relation;
- while(relation)
- {
+ while(relation) {
/* count all relations */
relations++;
/* check for relation's objects */
epoint = find_epoint_id(relation->epoint_id);
- if (!epoint)
- {
+ if (!epoint) {
PERROR("software error: relation without existing endpoints.\n");
relation = relation->next;
continue;
}
portlist = epoint->ep_portlist;
- if (!portlist)
- {
+ if (!portlist) {
PDEBUG(DEBUG_JOIN, "join%d ignoring relation without port object.\n", j_serial);
//#warning testing: keep on hold until single audio stream available
relation->channel_state = 0;
relation = relation->next;
continue;
}
- if (portlist->next)
- {
+ if (portlist->next) {
PDEBUG(DEBUG_JOIN, "join%d ignoring relation with ep%d due to port_list.\n", j_serial, epoint->ep_serial);
//#warning testing: keep on hold until single audio stream available
relation->channel_state = 0;
@@ -324,17 +306,14 @@ void JoinPBX::bridge(void)
continue;
}
port = find_port_id(portlist->port_id);
- if (!port)
- {
+ if (!port) {
PDEBUG(DEBUG_JOIN, "join%d ignoring relation without existing port object.\n", j_serial);
relation = relation->next;
continue;
}
- if ((port->p_type&PORT_CLASS_MASK)!=PORT_CLASS_mISDN)
- {
+ if ((port->p_type&PORT_CLASS_MASK)!=PORT_CLASS_mISDN) {
PDEBUG(DEBUG_JOIN, "join%d ignoring relation ep%d because it's port is not mISDN.\n", j_serial, epoint->ep_serial);
- if (allmISDN)
- {
+ if (allmISDN) {
PDEBUG(DEBUG_JOIN, "join%d not all endpoints are mISDN.\n", j_serial);
allmISDN = 0;
}
@@ -348,8 +327,7 @@ void JoinPBX::bridge(void)
PDEBUG(DEBUG_JOIN, "join%d members=%d %s\n", j_serial, relations, (allmISDN)?"(all are mISDN-members)":"(not all are mISDN-members)");
/* we notify all relations about rxdata. */
relation = j_relation;
- while(relation)
- {
+ while(relation) {
/* count connected relations */
if ((relation->channel_state == 1)
&& (relation->rx_state != NOTIFY_STATE_SUSPEND)
@@ -361,15 +339,13 @@ void JoinPBX::bridge(void)
&& relation->rx_state != NOTIFY_STATE_HOLD
&& relation->rx_state != NOTIFY_STATE_SUSPEND
&& relations>1 // no conf with one member
- && allmISDN) // no conf if any member is not mISDN
- {
+ && allmISDN) { // no conf if any member is not mISDN
message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_mISDNSIGNAL);
message->param.mISDNsignal.message = mISDNSIGNAL_CONF;
message->param.mISDNsignal.conf = j_serial<<16 | j_pid;
PDEBUG(DEBUG_JOIN, "join%d EP%d +on+ id: 0x%08x\n", j_serial, relation->epoint_id, message->param.mISDNsignal.conf);
message_put(message);
- } else
- {
+ } else {
message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_mISDNSIGNAL);
message->param.mISDNsignal.message = mISDNSIGNAL_CONF;
message->param.mISDNsignal.conf = 0;
@@ -393,33 +369,28 @@ void JoinPBX::bridge(void)
}
/* two people just exchange their states */
- if (relations==2 && !j_partyline)
- {
+ if (relations==2 && !j_partyline) {
PDEBUG(DEBUG_JOIN, "join%d 2 relations / no partyline\n", j_serial);
relation = j_relation;
relation->tx_state = notify_state_change(j_serial, relation->epoint_id, relation->tx_state, relation->next->rx_state);
relation->next->tx_state = notify_state_change(j_serial, relation->next->epoint_id, relation->next->tx_state, relation->rx_state);
} else
/* one member in a join, so we put her on hold */
- if ((relations==1 || numconnect==1)/* && !j_partyline_jingle*/)
- {
+ if ((relations==1 || numconnect==1)/* && !j_partyline_jingle*/) {
PDEBUG(DEBUG_JOIN, "join%d 1 member or only 1 connected, put on hold\n", j_serial);
relation = j_relation;
- while(relation)
- {
+ while(relation) {
if ((relation->channel_state == 1)
&& (relation->rx_state != NOTIFY_STATE_SUSPEND)
&& (relation->rx_state != NOTIFY_STATE_HOLD))
relation->tx_state = notify_state_change(j_serial, relation->epoint_id, relation->tx_state, NOTIFY_STATE_HOLD);
relation = relation->next;
}
- } else
+ } else {
/* if conference/partyline (or more than two members and more than one is connected), so we set conference state */
- {
PDEBUG(DEBUG_JOIN, "join%d %d members, %d connected, signal conference\n", j_serial, relations, numconnect);
relation = j_relation;
- while(relation)
- {
+ while(relation) {
if ((relation->channel_state == 1)
&& (relation->rx_state != NOTIFY_STATE_SUSPEND)
&& (relation->rx_state != NOTIFY_STATE_HOLD))
@@ -450,8 +421,7 @@ void JoinPBX::bridge_data(unsigned int epoint_from, struct join_relation *relati
/* get destination relation */
relation_to = j_relation;
- if (relation_to == relation_from)
- {
+ if (relation_to == relation_from) {
/* oops, we are the first, so destination is: */
relation_to = relation_to->next;
}
@@ -481,8 +451,7 @@ int JoinPBX::release(struct join_relation *relation, int location, int cause)
int destroy = 0;
/* remove from bridge */
- if (relation->channel_state != 0)
- {
+ if (relation->channel_state != 0) {
relation->channel_state = 0;
j_updatebridge = 1; /* update bridge flag */
// note: if join is not released, bridge must be updated
@@ -491,8 +460,7 @@ int JoinPBX::release(struct join_relation *relation, int location, int cause)
/* detach given interface */
reltemp = j_relation;
relationpointer = &j_relation;
- while(reltemp)
- {
+ while(reltemp) {
/* endpoint of function call */
if (relation == reltemp)
break;
@@ -508,8 +476,7 @@ int JoinPBX::release(struct join_relation *relation, int location, int cause)
relation = reltemp = NULL; // just in case of reuse fault;
/* if no more relation */
- if (!j_relation)
- {
+ if (!j_relation) {
PDEBUG(DEBUG_JOIN, "join is completely removed.\n");
/* there is no more endpoint related to the join */
destroy = 1;
@@ -518,13 +485,11 @@ int JoinPBX::release(struct join_relation *relation, int location, int cause)
PDEBUG(DEBUG_JOIN, "join completely removed!\n");
} else
/* if join is a party line */
- if (j_partyline)
- {
+ if (j_partyline) {
PDEBUG(DEBUG_JOIN, "join is a conference room, so we keep it alive until the last party left.\n");
} else
/* if only one relation left */
- if (!j_relation->next)
- {
+ if (!j_relation->next) {
PDEBUG(DEBUG_JOIN, "join has one relation left, so we send it a release with the given cause %d.\n", cause);
message = message_create(j_serial, j_relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_RELEASE);
message->param.disconnectinfo.cause = cause;
@@ -537,8 +502,7 @@ int JoinPBX::release(struct join_relation *relation, int location, int cause)
}
join = join_first;
- while(join)
- {
+ while(join) {
if (options.deb & DEBUG_JOIN && join->j_type==JOIN_TYPE_PBX)
joinpbx_debug((class JoinPBX *)join, "join_release{all joins left}");
join = join->next;
@@ -570,8 +534,7 @@ int joinpbx_countrelations(unsigned int join_id)
i = 0;
relation = joinpbx->j_relation;
- while(relation)
- {
+ while(relation) {
i++;
relation = relation->next;
}
@@ -588,15 +551,13 @@ void JoinPBX::remove_relation(struct join_relation *relation)
temp = j_relation;
tempp = &j_relation;
- while(temp)
- {
+ while(temp) {
if (temp == relation)
break;
tempp = &temp->next;
temp = temp->next;
}
- if (!temp)
- {
+ if (!temp) {
PERROR("relation not in join.\n");
return;
}
@@ -612,8 +573,7 @@ struct join_relation *JoinPBX::add_relation(void)
{
struct join_relation *relation;
- if (!j_relation)
- {
+ if (!j_relation) {
PERROR("there is no first relation to this join\n");
return(NULL);
}
@@ -643,24 +603,19 @@ void JoinPBX::message_epoint(unsigned int epoint_id, int message_type, union par
// int size, writesize, oldpointer;
char *number, *numbers;
- if (!epoint_id)
- {
+ if (!epoint_id) {
PERROR("software error, epoint == NULL\n");
return;
}
-// if (options.deb & DEBUG_JOIN)
-// {
+// if (options.deb & DEBUG_JOIN) {
// PDEBUG(DEBUG_JOIN, "message %d received from ep%d.\n", message, epoint->ep_serial);
// joinpbx_debug(join,"Join::message_epoint");
// }
- if (options.deb & DEBUG_JOIN)
- {
- if (message_type != MESSAGE_DATA)
- {
+ if (options.deb & DEBUG_JOIN) {
+ if (message_type != MESSAGE_DATA) {
cl = join_first;
- while(cl)
- {
+ while(cl) {
if (cl->j_type == JOIN_TYPE_PBX)
joinpbx_debug((class JoinPBX *)cl, "Join::message_epoint{all joins before processing}");
cl = cl->next;
@@ -670,28 +625,23 @@ void JoinPBX::message_epoint(unsigned int epoint_id, int message_type, union par
/* check relation */
relation = j_relation;
- while(relation)
- {
+ while(relation) {
if (relation->epoint_id == epoint_id)
break;
relation = relation->next;
}
- if (!relation)
- {
+ if (!relation) {
PDEBUG(DEBUG_JOIN, "no relation back to the endpoint found, ignoring (join=%d, endpoint=%d)\n", j_serial, epoint_id);
return;
}
/* process party line */
- if (message_type == MESSAGE_SETUP) if (param->setup.partyline && !j_partyline)
- {
+ if (message_type == MESSAGE_SETUP) if (param->setup.partyline && !j_partyline) {
j_partyline = param->setup.partyline;
j_partyline_jingle = param->setup.partyline_jingle;
}
- if (j_partyline)
- {
- switch(message_type)
- {
+ if (j_partyline) {
+ switch(message_type) {
case MESSAGE_SETUP:
PDEBUG(DEBUG_JOIN, "respsone with connect in partyline mode.\n");
relation->type = RELATION_TYPE_CONNECT;
@@ -706,8 +656,7 @@ void JoinPBX::message_epoint(unsigned int epoint_id, int message_type, union par
case MESSAGE_AUDIOPATH:
PDEBUG(DEBUG_JOIN, "join received channel message: %d.\n", param->audiopath);
- if (relation->channel_state != param->audiopath)
- {
+ if (relation->channel_state != param->audiopath) {
relation->channel_state = param->audiopath;
j_updatebridge = 1; /* update bridge flag */
if (options.deb & DEBUG_JOIN)
@@ -738,13 +687,11 @@ void JoinPBX::message_epoint(unsigned int epoint_id, int message_type, union par
/* process messages */
- switch(message_type)
- {
+ switch(message_type) {
/* process audio path message */
case MESSAGE_AUDIOPATH:
PDEBUG(DEBUG_JOIN, "join received channel message: %d.\n", param->audiopath);
- if (relation->channel_state != param->audiopath)
- {
+ if (relation->channel_state != param->audiopath) {
relation->channel_state = param->audiopath;
j_updatebridge = 1; /* update bridge flag */
if (options.deb & DEBUG_JOIN)
@@ -754,8 +701,7 @@ void JoinPBX::message_epoint(unsigned int epoint_id, int message_type, union par
/* track notify */
case MESSAGE_NOTIFY:
- switch(param->notifyinfo.notify)
- {
+ switch(param->notifyinfo.notify) {
case INFO_NOTIFY_USER_SUSPENDED:
case INFO_NOTIFY_USER_RESUMED:
case INFO_NOTIFY_REMOTE_HOLD:
@@ -763,8 +709,7 @@ void JoinPBX::message_epoint(unsigned int epoint_id, int message_type, union par
case INFO_NOTIFY_CONFERENCE_ESTABLISHED:
case INFO_NOTIFY_CONFERENCE_DISCONNECTED:
new_state = track_notify(relation->rx_state, param->notifyinfo.notify);
- if (new_state != relation->rx_state)
- {
+ if (new_state != relation->rx_state) {
relation->rx_state = new_state;
j_updatebridge = 1;
if (options.deb & DEBUG_JOIN)
@@ -775,10 +720,8 @@ void JoinPBX::message_epoint(unsigned int epoint_id, int message_type, union par
default:
/* send notification to all other endpoints */
reltemp = j_relation;
- while(reltemp)
- {
- if (reltemp->epoint_id!=epoint_id && reltemp->epoint_id)
- {
+ while(reltemp) {
+ if (reltemp->epoint_id!=epoint_id && reltemp->epoint_id) {
message = message_create(j_serial, reltemp->epoint_id, JOIN_TO_EPOINT, MESSAGE_NOTIFY);
memcpy(&message->param, param, sizeof(union parameter));
message_put(message);
@@ -802,11 +745,9 @@ void JoinPBX::message_epoint(unsigned int epoint_id, int message_type, union par
/* release other relations in setup state */
release_again:
reltemp = j_relation;
- while(reltemp)
- {
+ while(reltemp) {
//printf("connect, checking relation %d\n", reltemp->epoint_id);
- if (reltemp->type == RELATION_TYPE_SETUP)
- {
+ if (reltemp->type == RELATION_TYPE_SETUP) {
//printf("relation %d is of type setup, releasing\n", reltemp->epoint_id);
/* send release to endpoint */
message = message_create(j_serial, reltemp->epoint_id, JOIN_TO_EPOINT, MESSAGE_RELEASE);
@@ -826,8 +767,7 @@ void JoinPBX::message_epoint(unsigned int epoint_id, int message_type, union par
/* release is sent by endpoint */
case MESSAGE_RELEASE:
- switch(relation->type)
- {
+ switch(relation->type) {
case RELATION_TYPE_SETUP: /* by called */
/* collect cause and send collected cause */
collect_cause(&j_multicause, &j_multilocation, param->disconnectinfo.cause, param->disconnectinfo.location);
@@ -839,18 +779,15 @@ void JoinPBX::message_epoint(unsigned int epoint_id, int message_type, union par
case RELATION_TYPE_CALLING: /* by calling */
/* remove us, if we don't have a called releation yet */
- if (!j_relation->next)
- {
+ if (!j_relation->next) {
release(j_relation, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL);
return; // must return, because join IS destroyed
}
/* remove all relations that are in called */
release_again2:
reltemp = j_relation;
- while(reltemp)
- {
- if (reltemp->type == RELATION_TYPE_SETUP)
- {
+ while(reltemp) {
+ if (reltemp->type == RELATION_TYPE_SETUP) {
/* send release to endpoint */
message = message_create(j_serial, reltemp->epoint_id, JOIN_TO_EPOINT, message_type);
memcpy(&message->param, param, sizeof(union parameter));
@@ -876,30 +813,24 @@ void JoinPBX::message_epoint(unsigned int epoint_id, int message_type, union par
num=joinpbx_countrelations(j_serial);
/* check number of relations */
- if (num > 2)
- {
+ if (num > 2) {
PDEBUG(DEBUG_JOIN, "join has more than two relations so there is no need to send a message.\n");
return;
}
/* find interfaces not related to calling epoint */
relation = j_relation;
- while(relation)
- {
+ while(relation) {
if (relation->epoint_id != epoint_id)
break;
relation = relation->next;
}
- if (!relation)
- {
- switch(message_type)
- {
+ if (!relation) {
+ switch(message_type) {
case MESSAGE_SETUP:
- if (param->setup.dialinginfo.itype == INFO_ITYPE_ISDN_EXTENSION)
- {
+ if (param->setup.dialinginfo.itype == INFO_ITYPE_ISDN_EXTENSION) {
numbers = param->setup.dialinginfo.id;
- while((number = strsep(&numbers, ",")))
- {
+ while((number = strsep(&numbers, ","))) {
if (out_setup(epoint_id, message_type, param, number))
return; // join destroyed
}
@@ -912,8 +843,7 @@ void JoinPBX::message_epoint(unsigned int epoint_id, int message_type, union par
default:
PDEBUG(DEBUG_JOIN, "no need to send a message because there is no other endpoint than the calling one.\n");
}
- } else
- {
+ } else {
PDEBUG(DEBUG_JOIN, "sending message ep%ld -> ep%ld.\n", epoint_id, relation->epoint_id);
message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, message_type);
memcpy(&message->param, param, sizeof(union parameter));
@@ -937,8 +867,7 @@ int JoinPBX::handler(void)
// char *p;
/* the bridge must be updated */
- if (j_updatebridge)
- {
+ if (j_updatebridge) {
bridge();
j_updatebridge = 0;
return(1);
@@ -952,8 +881,7 @@ int track_notify(int oldstate, int notify)
{
int newstate = oldstate;
- switch(notify)
- {
+ switch(notify) {
case INFO_NOTIFY_USER_RESUMED:
case INFO_NOTIFY_REMOTE_RETRIEVAL:
case INFO_NOTIFY_CONFERENCE_DISCONNECTED:
@@ -1033,8 +961,7 @@ void JoinPBX::play_jingle(int in)
return;
if (!relation->next)
return;
- while(relation)
- {
+ while(relation) {
message = message_create(j_serial, relation->epoint_id, JOIN_TO_EPOINT, MESSAGE_TONE);
SCPY(message->param.tone.name, (char *)((in)?"joined":"left"));
message_put(message);
diff --git a/joinremote.cpp b/joinremote.cpp
index 4b92612..a4f9380 100644
--- a/joinremote.cpp
+++ b/joinremote.cpp
@@ -67,14 +67,12 @@ void JoinRemote::message_epoint(unsigned int epoint_id, int message_type, union
return;
/* look for Remote's interface */
- if (admin_message_from_join(j_remote_id, j_serial, message_type, param)<0)
- {
+ if (admin_message_from_join(j_remote_id, j_serial, message_type, param)<0) {
PERROR("No socket with remote application '%s' found, this shall not happen. Closing socket shall cause release of all joins.\n", j_remote_name);
return;
}
- if (message_type == MESSAGE_RELEASE)
- {
+ if (message_type == MESSAGE_RELEASE) {
delete this;
return;
}
@@ -85,8 +83,7 @@ void JoinRemote::message_remote(int message_type, union parameter *param)
struct lcr_msg *message;
/* create relation if no relation exists */
- if (!j_epoint_id)
- {
+ if (!j_epoint_id) {
class Endpoint *epoint;
if (!(epoint = new Endpoint(0, j_serial)))
@@ -98,8 +95,7 @@ void JoinRemote::message_remote(int message_type, union parameter *param)
/* set serial on bchannel message
* also ref is given, so we send message with ref */
- if (message_type == MESSAGE_BCHANNEL)
- {
+ if (message_type == MESSAGE_BCHANNEL) {
message_bchannel_from_remote(this, param->bchannel.type, param->bchannel.handle);
return;
}
@@ -109,8 +105,7 @@ void JoinRemote::message_remote(int message_type, union parameter *param)
memcpy(&message->param, param, sizeof(message->param));
message_put(message);
- if (message_type == MESSAGE_RELEASE)
- {
+ if (message_type == MESSAGE_RELEASE) {
delete this;
return;
}
@@ -130,8 +125,7 @@ void message_bchannel_to_remote(unsigned int remote_id, unsigned int ref, int ty
if (crypt_len)
memcpy(param.bchannel.crypt, crypt, crypt_len);
param.bchannel.crypt_type = crypt_type;
- if (admin_message_from_join(remote_id, ref, MESSAGE_BCHANNEL, &param)<0)
- {
+ if (admin_message_from_join(remote_id, ref, MESSAGE_BCHANNEL, &param)<0) {
PERROR("No socket with remote id %d found, this happens, if the socket is closed before all bchannels are imported.\n", remote_id);
return;
}
diff --git a/lcradmin.c b/lcradmin.c
index 12bfa74..0138de9 100644
--- a/lcradmin.c
+++ b/lcradmin.c
@@ -130,8 +130,7 @@ int debug_port(struct admin_message *msg, struct admin_message *m, int line, int
addstr(buffer);
color(cyan);
addstr(" state=");
- switch (m[i].u.p.state)
- {
+ switch (m[i].u.p.state) {
case ADMIN_STATE_IDLE:
color(red);
addstr("'idle'");
@@ -185,23 +184,20 @@ int debug_port(struct admin_message *msg, struct admin_message *m, int line, int
addstr("'--NONE--'");
}
- if (m[i].u.p.isdn)
- {
+ if (m[i].u.p.isdn) {
color(cyan);
addstr(" bchannel=");
color(white);
SPRINT(buffer,"%d", m[i].u.p.isdn_chan);
addstr(buffer);
- if (m[i].u.p.isdn_ces >= 0)
- {
+ if (m[i].u.p.isdn_ces >= 0) {
color(cyan);
addstr(" ces=");
color(yellow);
SPRINT(buffer, "%d", m[i].u.p.isdn_ces);
addstr(buffer);
}
- if (m[i].u.p.isdn_hold)
- {
+ if (m[i].u.p.isdn_hold) {
color(red);
addstr(" hold");
}
@@ -222,8 +218,7 @@ int debug_epoint(struct admin_message *msg, struct admin_message *m, int line, i
addstr(buffer);
color(cyan);
addstr(" state=");
- switch (m[i].u.e.state)
- {
+ switch (m[i].u.e.state) {
case ADMIN_STATE_IDLE:
color(red);
addstr("'idle'");
@@ -276,8 +271,7 @@ int debug_epoint(struct admin_message *msg, struct admin_message *m, int line, i
color(blue);
addstr("'--NONE--'");
}
- if (m[i].u.e.terminal[0])
- {
+ if (m[i].u.e.terminal[0]) {
color(cyan);
addstr(" terminal=");
color(green);
@@ -290,26 +284,22 @@ int debug_epoint(struct admin_message *msg, struct admin_message *m, int line, i
addstr("->");
color(white);
addstr(m[i].u.e.dialing);
- if (m[i].u.e.action[0])
- {
+ if (m[i].u.e.action[0]) {
color(cyan);
addstr(" action=");
color(yellow);
addstr(m[i].u.e.action);
}
- if (m[i].u.e.park)
- {
+ if (m[i].u.e.park) {
color(cyan);
addstr(" park="); /* 9 digits */
color(green);
UCPY(buffer, "\""); /* 9 digits */
j = 0;
jj = m[i].u.e.park_len;
- while(j < jj)
- {
+ while(j < jj) {
c = m[i].u.e.park_callid[j];
- if (c >= 32 && c < 127 && c != '[')
- {
+ if (c >= 32 && c < 127 && c != '[') {
SCCAT(buffer, c);
} else
UPRINT(buffer+strlen(buffer), "[%02x]", c);
@@ -317,11 +307,9 @@ int debug_epoint(struct admin_message *msg, struct admin_message *m, int line, i
}
SCAT(buffer, "\"");
addstr(buffer);
- } else
- {
+ } else {
color(red);
- switch(m[i].u.e.rx_state)
- {
+ switch(m[i].u.e.rx_state) {
case NOTIFY_STATE_SUSPEND:
addstr(" in=suspend");
break;
@@ -332,8 +320,7 @@ int debug_epoint(struct admin_message *msg, struct admin_message *m, int line, i
addstr(" in=conference");
break;
}
- switch(m[i].u.e.tx_state)
- {
+ switch(m[i].u.e.tx_state) {
case NOTIFY_STATE_SUSPEND:
addstr(" out=suspend");
break;
@@ -345,16 +332,13 @@ int debug_epoint(struct admin_message *msg, struct admin_message *m, int line, i
break;
}
}
- if (m[i].u.e.crypt)
- {
+ if (m[i].u.e.crypt) {
color(cyan);
addstr(" crypt=");
- if (m[i].u.e.crypt) /* crypt on */
- {
+ if (m[i].u.e.crypt) { /* crypt on */
color(green);
addstr("active");
- } else
- {
+ } else {
color(yellow);
addstr("pending");
}
@@ -363,10 +347,8 @@ int debug_epoint(struct admin_message *msg, struct admin_message *m, int line, i
ltee = 0;
j = msg->u.s.interfaces+msg->u.s.remotes+msg->u.s.joins+msg->u.s.epoints;
jj = j + msg->u.s.ports;
- while(j < jj)
- {
- if (m[j].u.p.epoint == epoint)
- {
+ while(j < jj) {
+ if (m[j].u.p.epoint == epoint) {
color(cyan);
move(++line>1?line:1, 1);
if (vline)
@@ -383,8 +365,7 @@ int debug_epoint(struct admin_message *msg, struct admin_message *m, int line, i
}
j++;
}
- if (ltee)
- {
+ if (ltee) {
color(cyan);
move(ltee>1?line:1, 5);
LLCORNER
@@ -401,16 +382,14 @@ int debug_join(struct admin_message *msg, struct admin_message *m, int line, int
color(white);
SPRINT(buffer,"JOIN(%d)", join);
addstr(buffer);
- if (m[i].u.j.partyline)
- {
+ if (m[i].u.j.partyline) {
color(cyan);
addstr(" partyline=");
color(white);
SPRINT(buffer, "%d\n", m[i].u.j.partyline);
addstr(buffer);
}
- if (m[i].u.j.remote[0])
- {
+ if (m[i].u.j.remote[0]) {
color(cyan);
addstr(" remote=");
color(white);
@@ -421,8 +400,7 @@ int debug_join(struct admin_message *msg, struct admin_message *m, int line, int
j = msg->u.s.interfaces+msg->u.s.remotes+msg->u.s.joins;
jj = j + msg->u.s.epoints;
i = 0;
- while(j < jj)
- {
+ while(j < jj) {
if (m[j].u.e.join == join)
i++;
j++;
@@ -430,10 +408,8 @@ int debug_join(struct admin_message *msg, struct admin_message *m, int line, int
/* loop all related endpoints */
j = msg->u.s.interfaces+msg->u.s.remotes+msg->u.s.joins;
jj = j + msg->u.s.epoints;
- while(j < jj)
- {
- if (m[j].u.e.join == join)
- {
+ while(j < jj) {
+ if (m[j].u.e.join == join) {
i--;
move(++line>1?line:1, 1);
color(cyan);
@@ -482,40 +458,34 @@ const char *admin_state(int sock, char *argv[])
memset(&msg, 0, sizeof(msg));
msg.message = ADMIN_REQUEST_STATE;
// printf("sizeof=%d\n",sizeof(msg));fflush(stdout);
- if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
- {
+ if (write(sock, &msg, sizeof(msg)) != sizeof(msg)) {
cleanup_curses();
return("Broken pipe while sending command.");
}
/* receive response */
- if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
- {
+ if (read(sock, &msg, sizeof(msg)) != sizeof(msg)) {
cleanup_curses();
return("Broken pipe while receiving response.");
}
- if (msg.message != ADMIN_RESPONSE_STATE)
- {
+ if (msg.message != ADMIN_RESPONSE_STATE) {
cleanup_curses();
return("Response not valid. Expecting state response.");
}
num = msg.u.s.interfaces + msg.u.s.remotes + msg.u.s.joins + msg.u.s.epoints + msg.u.s.ports;
m = (struct admin_message *)MALLOC(num*sizeof(struct admin_message));
off=0;
- if (num)
- {
+ if (num) {
readagain:
- if ((len = read(sock, ((unsigned char *)(m))+off, num*sizeof(struct admin_message)-off)) != num*(int)sizeof(struct admin_message)-off)
- {
+ if ((len = read(sock, ((unsigned char *)(m))+off, num*sizeof(struct admin_message)-off)) != num*(int)sizeof(struct admin_message)-off) {
if (len <= 0) {
FREE(m, 0);
// fprintf(stderr, "got=%d expected=%d\n", i, num*sizeof(struct admin_message));
cleanup_curses();
return("Broken pipe while receiving state infos.");
}
- if (len < num*(int)sizeof(struct admin_message))
- {
+ if (len < num*(int)sizeof(struct admin_message)) {
off+=len;
goto readagain;
}
@@ -524,11 +494,9 @@ const char *admin_state(int sock, char *argv[])
j = 0;
i = 0;
// fprintf("getting =%d interfaces\n", msg.u.s.interfaces);
- while(i < msg.u.s.interfaces)
- {
+ while(i < msg.u.s.interfaces) {
// fprintf(stderr, "j=%d message=%d\n", j, m[j].message);
- if (m[j].message != ADMIN_RESPONSE_S_INTERFACE)
- {
+ if (m[j].message != ADMIN_RESPONSE_S_INTERFACE) {
FREE(m, 0);
cleanup_curses();
return("Response not valid. Expecting interface information.");
@@ -537,10 +505,8 @@ const char *admin_state(int sock, char *argv[])
j++;
}
i = 0;
- while(i < msg.u.s.remotes)
- {
- if (m[j].message != ADMIN_RESPONSE_S_REMOTE)
- {
+ while(i < msg.u.s.remotes) {
+ if (m[j].message != ADMIN_RESPONSE_S_REMOTE) {
FREE(m, 0);
cleanup_curses();
return("Response not valid. Expecting remote application information.");
@@ -549,10 +515,8 @@ const char *admin_state(int sock, char *argv[])
j++;
}
i = 0;
- while(i < msg.u.s.joins)
- {
- if (m[j].message != ADMIN_RESPONSE_S_JOIN)
- {
+ while(i < msg.u.s.joins) {
+ if (m[j].message != ADMIN_RESPONSE_S_JOIN) {
FREE(m, 0);
cleanup_curses();
return("Response not valid. Expecting join information.");
@@ -561,10 +525,8 @@ const char *admin_state(int sock, char *argv[])
j++;
}
i = 0;
- while(i < msg.u.s.epoints)
- {
- if (m[j].message != ADMIN_RESPONSE_S_EPOINT)
- {
+ while(i < msg.u.s.epoints) {
+ if (m[j].message != ADMIN_RESPONSE_S_EPOINT) {
FREE(m, 0);
cleanup_curses();
return("Response not valid. Expecting endpoint information.");
@@ -573,10 +535,8 @@ const char *admin_state(int sock, char *argv[])
j++;
}
i = 0;
- while(i < msg.u.s.ports)
- {
- if (m[j].message != ADMIN_RESPONSE_S_PORT)
- {
+ while(i < msg.u.s.ports) {
+ if (m[j].message != ADMIN_RESPONSE_S_PORT) {
FREE(m, 0);
cleanup_curses();
return("Response not valid. Expecting port information.");
@@ -592,34 +552,29 @@ const char *admin_state(int sock, char *argv[])
line = 1-offset;
/* change log */
- if (!!strcmp(logfile, msg.u.s.logfile))
- {
+ if (!!strcmp(logfile, msg.u.s.logfile)) {
SCPY(logfile, msg.u.s.logfile);
if (logfh >= 0)
close(logfh);
i = 0;
ii = LOGLINES;
- while(i < ii)
- {
+ while(i < ii) {
logline[i][0] = '~';
logline[i][1] = '\0';
i++;
}
logcur = 0;
logfh = open(logfile, O_RDONLY|O_NONBLOCK);
- if (logfh >= 0)
- {
+ if (logfh >= 0) {
/* seek at the end -8000 chars */
lseek(logfh, -8000, SEEK_END);
/* if not at the beginning, read until endofline */
logline[logcur % LOGLINES][0] = '\0';
l = read(logfh, logline[logcur % LOGLINES], sizeof(logline[logcur % LOGLINES])-1);
- if (l > 0)
- {
+ if (l > 0) {
/* read first line and skip junk */
logline[logcur % LOGLINES][l] = '\0';
- if ((p = strchr(logline[logcur % LOGLINES],'\n')))
- {
+ if ((p = strchr(logline[logcur % LOGLINES],'\n'))) {
logcur++;
SCPY(logline[logcur % LOGLINES], p+1);
SCPY(logline[(logcur-1) % LOGLINES], "...");
@@ -630,10 +585,8 @@ const char *admin_state(int sock, char *argv[])
}
/* read log */
- if (logfh >= 0)
- {
- while(42)
- {
+ if (logfh >= 0) {
+ while(42) {
ll = strlen(logline[logcur % LOGLINES]);
l = read(logfh, logline[logcur % LOGLINES]+ll, sizeof(logline[logcur % LOGLINES])-ll-1);
if (l<=0)
@@ -641,15 +594,13 @@ const char *admin_state(int sock, char *argv[])
logline[logcur % LOGLINES][ll+l] = '\0';
finish_line:
/* put data to lines */
- while ((p = strchr(logline[logcur % LOGLINES],'\n')))
- {
+ while ((p = strchr(logline[logcur % LOGLINES],'\n'))) {
*p = '\0';
logcur++;
SCPY(logline[logcur % LOGLINES], p+1);
}
/* if line is full without return, go next line */
- if (strlen(logline[logcur % LOGLINES]) == sizeof(logline[logcur % LOGLINES])-1)
- {
+ if (strlen(logline[logcur % LOGLINES]) == sizeof(logline[logcur % LOGLINES])-1) {
logcur++;
logline[logcur % LOGLINES][0] = '\0';
}
@@ -657,18 +608,15 @@ const char *admin_state(int sock, char *argv[])
}
/* display interfaces */
- if (show_interfaces > 0)
- {
+ if (show_interfaces > 0) {
anything = 0;
i = 0;
ii = i + msg.u.s.interfaces;
- while(i < ii)
- {
+ while(i < ii) {
/* show interface summary */
move(++line>1?line:1, 0);
color(white);
- if (m[i].u.i.block >= 2)
- {
+ if (m[i].u.i.block >= 2) {
if (m[i].u.i.portnum < 0)
SPRINT(buffer, "%s (port ?: %s)%s", m[i].u.i.interface_name, m[i].u.i.portname, (m[i].u.i.extension)?" exten":"");
else
@@ -676,8 +624,7 @@ const char *admin_state(int sock, char *argv[])
addstr(buffer);
color(red);
addstr(" not loaded");
- } else
- {
+ } else {
SPRINT(buffer, "%s", m[i].u.i.interface_name);
addstr(buffer);
color(yellow);
@@ -692,22 +639,18 @@ const char *admin_state(int sock, char *argv[])
color(blue);
SPRINT(buffer, " use:%d", m[i].u.i.use);
addstr(buffer);
- if (m[i].u.i.ptp || !m[i].u.i.ntmode)
- {
+ if (m[i].u.i.ptp || !m[i].u.i.ntmode) {
color((m[i].u.i.l2link > 0)?green:red);
if (m[i].u.i.l2link < 0)
addstr(" L2 unkn");
else
addstr((m[i].u.i.l2link)?" L2 UP":" L2 down");
- } else
- {
+ } else {
k = 0;
color(green);
j = 0;
- while(j < 128)
- {
- if (m[i].u.i.l2mask[j>>3] & (1 << (j&7)))
- {
+ while(j < 128) {
+ if (m[i].u.i.l2mask[j>>3] & (1 << (j&7))) {
SPRINT(buffer, "%s%d", k?",":" TEI(", j);
addstr(buffer);
k = 1;
@@ -722,51 +665,41 @@ const char *admin_state(int sock, char *argv[])
addstr(" L1 unkn");
else
addstr((m[i].u.i.l1link)?" L1 UP":" L1 down");
- if (m[i].u.i.los)
- {
+ if (m[i].u.i.los) {
color(red);
addstr(" LOS");
}
- if (m[i].u.i.ais)
- {
+ if (m[i].u.i.ais) {
color(red);
addstr(" AIS");
}
- if (m[i].u.i.rdi)
- {
+ if (m[i].u.i.rdi) {
color(red);
addstr(" RDI");
}
- if (m[i].u.i.slip_tx || m[i].u.i.slip_rx)
- {
+ if (m[i].u.i.slip_tx || m[i].u.i.slip_rx) {
color(red);
SPRINT(buffer, " SLIP(tx:%d rx:%d)", m[i].u.i.slip_tx, m[i].u.i.slip_rx);
addstr(buffer);
}
- if (m[i].u.i.block)
- {
+ if (m[i].u.i.block) {
color(red);
addstr(" blocked");
}
if (line+2 >= LINES) goto end;
/* show channels */
- if (show_interfaces > 1)
- {
+ if (show_interfaces > 1) {
ltee = 0;
j = k =0;
jj = m[i].u.i.channels;
- while(j < jj)
- {
+ while(j < jj) {
/* show all channels */
- if (show_interfaces>2 || m[i].u.i.busy[j]>0)
- {
+ if (show_interfaces>2 || m[i].u.i.busy[j]>0) {
color(cyan);
/* show left side / right side */
- if ((k & 1) && (COLS > 70))
- {
+ if ((k & 1) && (COLS > 70)) {
move(line>1?line:1,4+((COLS-4)/2));
- } else
- {
+ } else {
move(++line>1?line:1, 1);
LTEE
ltee = 1;
@@ -780,15 +713,12 @@ const char *admin_state(int sock, char *argv[])
if (m[i].u.i.mode[j] == B_MODE_HDLC)
SCAT(buffer,"HDLC ");
addstr(buffer);
- switch(m[i].u.i.busy[j])
- {
+ switch(m[i].u.i.busy[j]) {
case B_STATE_IDLE:
- if ((!m[i].u.i.l2link && m[i].u.i.ptp) || m[i].u.i.block)
- {
+ if ((!m[i].u.i.l2link && m[i].u.i.ptp) || m[i].u.i.block) {
color(red);
addstr("blocked ");
- } else
- {
+ } else {
color(blue);
addstr("idle ");
}
@@ -818,25 +748,20 @@ const char *admin_state(int sock, char *argv[])
addstr("imp'ing ");
break;
}
- if (m[i].u.i.port[j])
- {
+ if (m[i].u.i.port[j]) {
/* search for port */
l = msg.u.s.interfaces+msg.u.s.remotes+msg.u.s.joins+msg.u.s.epoints;
ll = l+msg.u.s.ports;
- while(l < ll)
- {
- if (m[l].u.p.serial == m[i].u.i.port[j])
- {
+ while(l < ll) {
+ if (m[l].u.p.serial == m[i].u.i.port[j]) {
SPRINT(buffer, " %s(%ld)", m[l].u.p.name, m[l].u.p.serial);
addstr(buffer);
}
l++;
}
}
- if (line+2 >= LINES)
- {
- if (ltee)
- {
+ if (line+2 >= LINES) {
+ if (ltee) {
color(cyan);
move(line>1?line:1, 1);
LLCORNER
@@ -846,26 +771,22 @@ const char *admin_state(int sock, char *argv[])
}
j++;
}
- if (ltee)
- {
+ if (ltee) {
color(cyan);
move(line>1?line:1, 1);
LLCORNER
}
if (line+2 >= LINES) goto end;
/* show summary if no channels were shown */
- if (show_interfaces<2 && ltee==0)
- {
+ if (show_interfaces<2 && ltee==0) {
color(cyan);
move(++line>1?line:1, 1);
LLCORNER
- if (m[i].u.i.l2link && m[i].u.i.block==0)
- {
+ if (m[i].u.i.l2link && m[i].u.i.block==0) {
color(green);
SPRINT(buffer,"all %d channels free", m[i].u.i.channels);
- } else
- {
+ } else {
color(red);
SPRINT(buffer,"all %d channels blocked", m[i].u.i.channels);
}
@@ -879,8 +800,7 @@ const char *admin_state(int sock, char *argv[])
}
i = msg.u.s.interfaces;
ii = i + msg.u.s.remotes;
- while(i < ii)
- {
+ while(i < ii) {
/* show remote summary */
move(++line>1?line:1, 0);
color(white);
@@ -893,23 +813,19 @@ const char *admin_state(int sock, char *argv[])
if (line+2 >= LINES) goto end;
}
/* display calls (brief) */
- if (show_calls == 1)
- {
+ if (show_calls == 1) {
anything = 0;
i = msg.u.s.interfaces+msg.u.s.remotes+msg.u.s.joins;
ii = i+msg.u.s.epoints;
- while(i < ii)
- {
+ while(i < ii) {
/* for each endpoint... */
- if (!m[i].u.e.join)
- {
+ if (!m[i].u.e.join) {
move(++line>1?line:1, 0);
color(white);
SPRINT(buffer, "(%d): ", m[i].u.e.serial);
addstr(buffer);
color(cyan);
- if (m[i].u.e.terminal[0])
- {
+ if (m[i].u.e.terminal[0]) {
addstr("intern=");
color(green);
addstr(m[i].u.e.terminal);
@@ -923,8 +839,7 @@ const char *admin_state(int sock, char *argv[])
color(white);
SPRINT(buffer, "%s", m[i].u.e.dialing);
addstr(buffer);
- if (m[i].u.e.action[0])
- {
+ if (m[i].u.e.action[0]) {
color(cyan);
addstr(" action=");
color(yellow);
@@ -937,8 +852,7 @@ const char *admin_state(int sock, char *argv[])
}
j = msg.u.s.interfaces+msg.u.s.remotes;
jj = j+msg.u.s.joins;
- while(j < jj)
- {
+ while(j < jj) {
/* for each call... */
move(++line>1?line:1, 0);
color(white);
@@ -946,17 +860,14 @@ const char *admin_state(int sock, char *argv[])
addstr(buffer);
i = msg.u.s.interfaces+msg.u.s.remotes+msg.u.s.joins;
ii = i+msg.u.s.epoints;
- while(i < ii)
- {
+ while(i < ii) {
/* for each endpoint... */
- if (m[i].u.e.join == m[j].u.j.serial)
- {
+ if (m[i].u.e.join == m[j].u.j.serial) {
color(white);
SPRINT(buffer, " (%d)", m[i].u.e.serial);
addstr(buffer);
color(cyan);
- if (m[i].u.e.terminal[0])
- {
+ if (m[i].u.e.terminal[0]) {
addstr("int=");
color(green);
addstr(m[i].u.e.terminal);
@@ -982,16 +893,13 @@ const char *admin_state(int sock, char *argv[])
if (line+2 >= LINES) goto end;
}
/* display calls (structurd) */
- if (show_calls == 2)
- {
+ if (show_calls == 2) {
/* show all ports with no epoint */
anything = 0;
i = msg.u.s.interfaces+msg.u.s.remotes+msg.u.s.joins+msg.u.s.epoints;
ii = i+msg.u.s.ports;
- while(i < ii)
- {
- if (!m[i].u.p.epoint)
- {
+ while(i < ii) {
+ if (!m[i].u.p.epoint) {
move(++line>1?line:1, 8);
if (line+2 >= LINES) goto end;
line = debug_port(&msg, m, line, i, 0);
@@ -1008,10 +916,8 @@ const char *admin_state(int sock, char *argv[])
anything = 0;
i = msg.u.s.interfaces+msg.u.s.remotes+msg.u.s.joins;
ii = i+msg.u.s.epoints;
- while(i < ii)
- {
- if (!m[i].u.e.join)
- {
+ while(i < ii) {
+ if (!m[i].u.e.join) {
move(++line>1?line:1, 4);
if (line+2 >= LINES) goto end;
line = debug_epoint(&msg, m, line, i, 0);
@@ -1028,8 +934,7 @@ const char *admin_state(int sock, char *argv[])
anything = 0;
i = msg.u.s.interfaces+msg.u.s.remotes;
ii = i+msg.u.s.joins;
- while(i < ii)
- {
+ while(i < ii) {
move(++line>1?line:1, 0);
if (line+2 >= LINES) goto end;
line = debug_join(&msg, m, line, i);
@@ -1044,10 +949,8 @@ const char *admin_state(int sock, char *argv[])
}
/* show log */
- if (show_log)
- {
- if (line+2 < LINES)
- {
+ if (show_log) {
+ if (line+2 < LINES) {
move(line++>1?line-1:1, 0);
color(blue);
hline(ACS_HLINE, COLS);
@@ -1057,15 +960,13 @@ const char *admin_state(int sock, char *argv[])
ll = logcur;
if (ll-l >= LOGLINES)
l = ll-LOGLINES+1;
- while(l!=ll)
- {
+ while(l!=ll) {
move(line++>1?line-1:1, 0);
if ((int)strlen(logline[l % LOGLINES]) > hoffset)
SCPY(buffer, logline[l % LOGLINES] + hoffset);
else
buffer[0] = '\0';
- if (COLS < (int)strlen(buffer))
- {
+ if (COLS < (int)strlen(buffer)) {
buffer[COLS-1] = '\0';
addstr(buffer);
color(mangenta);
@@ -1089,8 +990,7 @@ const char *admin_state(int sock, char *argv[])
msg.u.s.version_string[sizeof(msg.u.s.version_string)-1] = '\0';
SPRINT(buffer, "LCR %s", msg.u.s.version_string);
addstr(buffer);
- if (COLS>50)
- {
+ if (COLS>50) {
move(0, COLS-19);
SPRINT(buffer, "%04d-%02d-%02d %02d:%02d:%02d",
msg.u.s.tm.tm_year+1900, msg.u.s.tm.tm_mon+1, msg.u.s.tm.tm_mday,
@@ -1101,15 +1001,13 @@ const char *admin_state(int sock, char *argv[])
move(1, 0);
color(blue);
hline(ACS_HLINE, COLS);
- if (offset)
- {
+ if (offset) {
move(1, 1);
SPRINT(buffer, "Offset +%d", offset);
color(red);
addstr(buffer);
}
- if (hoffset)
- {
+ if (hoffset) {
move(1, 13);
SPRINT(buffer, "H-Offset +%d", hoffset);
color(red);
@@ -1120,12 +1018,10 @@ const char *admin_state(int sock, char *argv[])
color(blue);
hline(ACS_HLINE, COLS);
move(LINES-1, 0);
- if (enter)
- {
+ if (enter) {
color(white);
SPRINT(buffer, "-> %s", enter_string);
- } else
- {
+ } else {
color(cyan);
SPRINT(buffer, "i=interfaces '%s' c=calls '%s' l=log q=quit +-*/=scroll enter", text_interfaces[show_interfaces], text_calls[show_calls]);
}
@@ -1133,20 +1029,17 @@ const char *admin_state(int sock, char *argv[])
refresh();
/* resize */
- if (lastlines!=LINES || lastcols!=COLS)
- {
+ if (lastlines!=LINES || lastcols!=COLS) {
cleanup_curses();
init_curses();
goto again;
}
- if (enter)
- {
+ if (enter) {
/* user input in enter mode */
ch = getch();
enter_again:
- if (ch == 10)
- {
+ if (ch == 10) {
FILE *fp;
enter = 0;
@@ -1160,8 +1053,7 @@ const char *admin_state(int sock, char *argv[])
!!strncmp(enter_string, "block ", 6) &&
!!strncmp(enter_string, "unblock ", 8) &&
!!strncmp(enter_string, "load ", 5) &&
- !!strncmp(enter_string, "unload ", 7))
- {
+ !!strncmp(enter_string, "unload ", 7)) {
SPRINT(logline[logcur++ % LOGLINES], "usage:");
SPRINT(logline[logcur++ % LOGLINES], "interface (reload interface.conf)");
SPRINT(logline[logcur++ % LOGLINES], "route (reload routing.conf)");
@@ -1169,18 +1061,15 @@ const char *admin_state(int sock, char *argv[])
SPRINT(logline[logcur++ % LOGLINES], "block <port> (block port for further calls)");
SPRINT(logline[logcur++ % LOGLINES], "unblock/load <port> (unblock port for further calls, load if not loaded)");
SPRINT(logline[logcur++ % LOGLINES], "unload <port> (unload mISDN stack, release call calls)");
- } else
- {
+ } else {
/* applend output to log window */
SPRINT(buffer, "%s %s", argv[0], enter_string);
fp = popen(buffer, "r");
- if (fp)
- {
+ if (fp) {
while(fgets(logline[logcur % LOGLINES], sizeof(logline[0]), fp))
logline[logcur++ % LOGLINES][sizeof(logline[0])-1] = '\0';
pclose(fp);
- } else
- {
+ } else {
SPRINT(logline[logcur++ % LOGLINES], "failed to execute '%s'", buffer);
}
}
@@ -1188,16 +1077,14 @@ const char *admin_state(int sock, char *argv[])
enter_string[0] = '\0';
goto again;
}
- if (ch>=32 && ch<=126)
- {
+ if (ch>=32 && ch<=126) {
SCCAT(enter_string, ch);
ch = getch();
if (ch > 0)
goto enter_again;
goto again;
} else
- if (ch==8 || ch==127)
- {
+ if (ch==8 || ch==127) {
if (enter_string[0])
enter_string[strlen(enter_string)-1] = '\0';
ch = getch();
@@ -1205,8 +1092,7 @@ const char *admin_state(int sock, char *argv[])
goto enter_again;
goto again;
} else
- if (ch != 3)
- {
+ if (ch != 3) {
ch = getch();
if (ch > 0)
goto enter_again;
@@ -1217,11 +1103,9 @@ const char *admin_state(int sock, char *argv[])
select(1, &select_rfds, NULL, NULL, &select_tv);
goto again;
}
- } else
- {
+ } else {
/* user input in normal mode */
- switch(getch())
- {
+ switch(getch()) {
case 12: /* refresh */
cleanup_curses();
init_curses();
@@ -1303,39 +1187,33 @@ const char *admin_portinfo(int sock, int argc, char *argv[])
/* send state request command */
memset(&msg, 0, sizeof(msg));
msg.message = ADMIN_REQUEST_STATE;
- if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
- {
+ if (write(sock, &msg, sizeof(msg)) != sizeof(msg)) {
cleanup_curses();
return("Broken pipe while sending command.");
}
/* receive response */
- if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
- {
+ if (read(sock, &msg, sizeof(msg)) != sizeof(msg)) {
cleanup_curses();
return("Broken pipe while receiving response.");
}
- if (msg.message != ADMIN_RESPONSE_STATE)
- {
+ if (msg.message != ADMIN_RESPONSE_STATE) {
cleanup_curses();
return("Response not valid. Expecting state response.");
}
num = msg.u.s.interfaces + msg.u.s.remotes + msg.u.s.joins + msg.u.s.epoints + msg.u.s.ports;
m = (struct admin_message *)MALLOC(num*sizeof(struct admin_message));
off=0;
- if (num)
- {
+ if (num) {
readagain:
- if ((len = read(sock, ((unsigned char *)(m))+off, num*sizeof(struct admin_message)-off)) != num*(int)sizeof(struct admin_message)-off)
- {
+ if ((len = read(sock, ((unsigned char *)(m))+off, num*sizeof(struct admin_message)-off)) != num*(int)sizeof(struct admin_message)-off) {
if (len <= 0) {
FREE(m, 0);
cleanup_curses();
return("Broken pipe while receiving state infos.");
}
- if (len < num*(int)sizeof(struct admin_message))
- {
+ if (len < num*(int)sizeof(struct admin_message)) {
off+=len;
goto readagain;
}
@@ -1343,10 +1221,8 @@ const char *admin_portinfo(int sock, int argc, char *argv[])
}
j = 0;
i = 0;
- while(i < msg.u.s.interfaces)
- {
- if (m[j].message != ADMIN_RESPONSE_S_INTERFACE)
- {
+ while(i < msg.u.s.interfaces) {
+ if (m[j].message != ADMIN_RESPONSE_S_INTERFACE) {
FREE(m, 0);
cleanup_curses();
return("Response not valid. Expecting interface information.");
@@ -1355,10 +1231,8 @@ const char *admin_portinfo(int sock, int argc, char *argv[])
j++;
}
i = 0;
- while(i < msg.u.s.remotes)
- {
- if (m[j].message != ADMIN_RESPONSE_S_REMOTE)
- {
+ while(i < msg.u.s.remotes) {
+ if (m[j].message != ADMIN_RESPONSE_S_REMOTE) {
FREE(m, 0);
cleanup_curses();
return("Response not valid. Expecting remote application information.");
@@ -1367,10 +1241,8 @@ const char *admin_portinfo(int sock, int argc, char *argv[])
j++;
}
i = 0;
- while(i < msg.u.s.joins)
- {
- if (m[j].message != ADMIN_RESPONSE_S_JOIN)
- {
+ while(i < msg.u.s.joins) {
+ if (m[j].message != ADMIN_RESPONSE_S_JOIN) {
FREE(m, 0);
cleanup_curses();
return("Response not valid. Expecting join information.");
@@ -1379,10 +1251,8 @@ const char *admin_portinfo(int sock, int argc, char *argv[])
j++;
}
i = 0;
- while(i < msg.u.s.epoints)
- {
- if (m[j].message != ADMIN_RESPONSE_S_EPOINT)
- {
+ while(i < msg.u.s.epoints) {
+ if (m[j].message != ADMIN_RESPONSE_S_EPOINT) {
FREE(m, 0);
cleanup_curses();
return("Response not valid. Expecting endpoint information.");
@@ -1391,10 +1261,8 @@ const char *admin_portinfo(int sock, int argc, char *argv[])
j++;
}
i = 0;
- while(i < msg.u.s.ports)
- {
- if (m[j].message != ADMIN_RESPONSE_S_PORT)
- {
+ while(i < msg.u.s.ports) {
+ if (m[j].message != ADMIN_RESPONSE_S_PORT) {
FREE(m, 0);
cleanup_curses();
return("Response not valid. Expecting port information.");
@@ -1407,12 +1275,9 @@ const char *admin_portinfo(int sock, int argc, char *argv[])
/* output interfaces */
i = 0;
ii = i + msg.u.s.interfaces;
- while(i < ii)
- {
- if (argc > 2)
- {
- if (!!strcmp(argv[2], m[i].u.i.interface_name))
- {
+ while(i < ii) {
+ if (argc > 2) {
+ if (!!strcmp(argv[2], m[i].u.i.interface_name)) {
i++;
continue;
}
@@ -1423,11 +1288,9 @@ const char *admin_portinfo(int sock, int argc, char *argv[])
else
printf("\t port = %d \"%s\"\n",m[i].u.i.portnum, m[i].u.i.portname);
printf("\t extension = %s\n", (m[i].u.i.extension)?"yes":"no");
- if (m[i].u.i.block >= 2)
- {
+ if (m[i].u.i.block >= 2) {
printf("\t status = not loaded\n");
- } else
- {
+ } else {
if (m[i].u.i.block)
printf("\t status = blocked\n");
else
@@ -1437,8 +1300,7 @@ const char *admin_portinfo(int sock, int argc, char *argv[])
printf("\t l1 link = unknown\n");
else
printf("\t l1 link = %s\n", (m[i].u.i.l1link)?"up":"down");
- if (m[i].u.i.ptp || !m[i].u.i.ntmode)
- {
+ if (m[i].u.i.ptp || !m[i].u.i.ntmode) {
if (m[i].u.i.l2link < 0)
printf("\t l2 link = unknown\n");
else
@@ -1465,8 +1327,7 @@ const char *admin_cmd(int sock, int mode, char *extension, char *number)
/* send reload command */
memset(&msg, 0, sizeof(msg));
- switch(mode)
- {
+ switch(mode) {
case MODE_INTERFACE:
msg.message = ADMIN_REQUEST_CMD_INTERFACE;
break;
@@ -1504,8 +1365,7 @@ const char *admin_cmd(int sock, int mode, char *extension, char *number)
/* receive response */
if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
return("Broken pipe while receiving response.");
- switch(mode)
- {
+ switch(mode) {
case MODE_INTERFACE:
if (msg.message != ADMIN_RESPONSE_CMD_INTERFACE)
return("Response not valid.");
@@ -1531,8 +1391,7 @@ const char *admin_cmd(int sock, int mode, char *extension, char *number)
}
/* process response */
- if (msg.u.x.error)
- {
+ if (msg.u.x.error) {
return(msg.u.x.message);
}
printf("Command successfull.\n");
@@ -1560,41 +1419,35 @@ const char *admin_testcall(int sock, int argc, char *argv[])
printf("pid=%d\n", getpid()); fflush(stdout);
- while (argc > ar)
- {
- if (!strcmp(argv[ar], "--setup-timeout"))
- {
+ while (argc > ar) {
+ if (!strcmp(argv[ar], "--setup-timeout")) {
ar++;
if (argc == ar)
return("Missing setup timeout value.\n");
stimeout = atoi(argv[ar]);
ar++;
} else
- if (!strcmp(argv[ar], "--proceeding-timeout"))
- {
+ if (!strcmp(argv[ar], "--proceeding-timeout")) {
ar++;
if (argc == ar)
return("Missing proceeding timeout value.\n");
ptimeout = atoi(argv[ar]);
ar++;
} else
- if (!strcmp(argv[ar], "--alerting-timeout"))
- {
+ if (!strcmp(argv[ar], "--alerting-timeout")) {
ar++;
if (argc == ar)
return("Missing alerting timeout value.\n");
atimeout = atoi(argv[ar]);
ar++;
} else
- if (!strcmp(argv[ar], "--connect-timeout"))
- {
+ if (!strcmp(argv[ar], "--connect-timeout")) {
ar++;
if (argc == ar)
return("Missing connect timeout value.\n");
ctimeout = atoi(argv[ar]);
ar++;
- } else
- {
+ } else {
break;
}
}
@@ -1604,23 +1457,19 @@ const char *admin_testcall(int sock, int argc, char *argv[])
msg.message = ADMIN_CALL_SETUP;
msg.u.call.present = 1;
- if (argc > ar)
- {
+ if (argc > ar) {
SCPY(msg.u.call.interface, argv[ar]);
}
ar++;
- if (argc > ar)
- {
+ if (argc > ar) {
SCPY(msg.u.call.callerid, argv[ar]);
}
ar++;
- if (argc > ar)
- {
+ if (argc > ar) {
SCPY(msg.u.call.dialing, argv[ar]);
}
ar++;
- if (argc > ar)
- {
+ if (argc > ar) {
if (argv[ar][0] == 'r')
msg.u.call.present = 0;
}
@@ -1671,8 +1520,7 @@ const char *admin_testcall(int sock, int argc, char *argv[])
if (ioctl(sock, FIONBIO, (unsigned char *)(&on)) < 0)
return("Failed to set socket into non-blocking IO.");
- if (stimeout)
- {
+ if (stimeout) {
GET_NOW();
timer = now_d + (double)stimeout;
}
@@ -1680,15 +1528,11 @@ const char *admin_testcall(int sock, int argc, char *argv[])
/* receive response */
next:
l = read(sock, &msg, sizeof(msg));
- if (l < 0)
- {
- if (errno == EWOULDBLOCK)
- {
- if (timer)
- {
+ if (l < 0) {
+ if (errno == EWOULDBLOCK) {
+ if (timer) {
GET_NOW();
- if (timer <= now_d)
- {
+ if (timer <= now_d) {
printf("Timeout\n"); fflush(stdout);
return(NULL);
}
@@ -1700,16 +1544,14 @@ next:
}
if (l != sizeof(msg))
return("Response has unexpected message size.");
- switch(msg.message)
- {
+ switch(msg.message) {
case ADMIN_CALL_SETUP_ACK:
printf("SETUP ACKNOWLEDGE\n"); fflush(stdout);
goto next;
case ADMIN_CALL_PROCEEDING:
printf("PROCEEDING\n"); fflush(stdout);
- if (ptimeout)
- {
+ if (ptimeout) {
GET_NOW();
timer = now_d + (double)ptimeout;
}
@@ -1717,8 +1559,7 @@ next:
case ADMIN_CALL_ALERTING:
printf("ALERTING\n"); fflush(stdout);
- if (atimeout)
- {
+ if (atimeout) {
GET_NOW();
timer = now_d + (double)atimeout;
}
@@ -1726,8 +1567,7 @@ next:
case ADMIN_CALL_CONNECT:
printf("CONNECT\n number=%s\n", msg.u.call.callerid); fflush(stdout);
- if (ctimeout)
- {
+ if (ctimeout) {
GET_NOW();
timer = now_d + (double)ctimeout;
}
@@ -1763,8 +1603,7 @@ const char *admin_trace(int sock, int argc, char *argv[])
int i;
/* show help */
- if (argc > 2) if (!strcasecmp(argv[2], "help"))
- {
+ if (argc > 2) if (!strcasecmp(argv[2], "help")) {
printf("Trace Help\n----------\n");
printf("%s trace [brief|short] [<filter>=<value> [...]]\n\n", argv[0]);
printf("By default a complete trace is shown in detailed format.\n");
@@ -1790,8 +1629,7 @@ const char *admin_trace(int sock, int argc, char *argv[])
/* parse args */
i = 2;
- while(i < argc)
- {
+ while(i < argc) {
if (!strcasecmp(argv[i], "brief"))
msg.u.trace_req.detail = 1;
else if (!strcasecmp(argv[i], "short"))
@@ -1840,8 +1678,7 @@ int main(int argc, char *argv[])
/* show options */
- if (argc <= 1)
- {
+ if (argc <= 1) {
usage:
printf("\n");
printf("Usage: %s state | interface | route | dial ...\n", argv[0]);
@@ -1865,64 +1702,52 @@ int main(int argc, char *argv[])
}
/* check mode */
- if (!(strcasecmp(argv[1],"state")))
- {
+ if (!(strcasecmp(argv[1],"state"))) {
mode = MODE_STATE;
} else
- if (!(strcasecmp(argv[1],"portinfo")))
- {
+ if (!(strcasecmp(argv[1],"portinfo"))) {
mode = MODE_PORTINFO;
} else
- if (!(strcasecmp(argv[1],"interface")))
- {
+ if (!(strcasecmp(argv[1],"interface"))) {
mode = MODE_INTERFACE;
} else
- if (!(strcasecmp(argv[1],"route")))
- {
+ if (!(strcasecmp(argv[1],"route"))) {
mode = MODE_ROUTE;
} else
- if (!(strcasecmp(argv[1],"dial")))
- {
+ if (!(strcasecmp(argv[1],"dial"))) {
if (argc <= 3)
goto usage;
mode = MODE_DIAL;
} else
- if (!(strcasecmp(argv[1],"release")))
- {
+ if (!(strcasecmp(argv[1],"release"))) {
if (argc <= 2)
goto usage;
mode = MODE_RELEASE;
} else
if (!(strcasecmp(argv[1],"unblock"))
- || !(strcasecmp(argv[1],"load")))
- {
+ || !(strcasecmp(argv[1],"load"))) {
if (argc <= 2)
goto usage;
mode = MODE_UNBLOCK;
} else
- if (!(strcasecmp(argv[1],"block")))
- {
+ if (!(strcasecmp(argv[1],"block"))) {
if (argc <= 2)
goto usage;
mode = MODE_BLOCK;
} else
- if (!(strcasecmp(argv[1],"unload")))
- {
+ if (!(strcasecmp(argv[1],"unload"))) {
if (argc <= 2)
goto usage;
mode = MODE_UNLOAD;
} else
- if (!(strcasecmp(argv[1],"testcall")))
- {
+ if (!(strcasecmp(argv[1],"testcall"))) {
if (argc <= 4)
goto usage;
mode = MODE_TESTCALL;
} else
- if (!(strcasecmp(argv[1],"trace")))
- {
+ if (!(strcasecmp(argv[1],"trace"))) {
mode = MODE_TRACE;
- } else
- {
+ } else {
goto usage;
}
@@ -1932,24 +1757,21 @@ int main(int argc, char *argv[])
//pipeagain:
/* open socket */
- if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0)
- {
+ if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
fprintf(stderr, "Failed to create socket.\n");
exit(EXIT_FAILURE);
}
memset(&sock_address, 0, sizeof(sock_address));
SPRINT(sock_address.sun_path, SOCKET_NAME, options.lock);
sock_address.sun_family = PF_UNIX;
- if ((conn = connect(sock, (struct sockaddr *)&sock_address, SUN_LEN(&sock_address))) < 0)
- {
+ if ((conn = connect(sock, (struct sockaddr *)&sock_address, SUN_LEN(&sock_address))) < 0) {
close(sock);
fprintf(stderr, "Failed to connect to socket \"%s\".\nIs LCR running?\n", sock_address.sun_path);
exit(EXIT_FAILURE);
}
/* process mode */
- switch(mode)
- {
+ switch(mode) {
case MODE_STATE:
ret = admin_state(sock, argv);
break;
@@ -1985,8 +1807,7 @@ int main(int argc, char *argv[])
close(sock);
/* now we say good bye */
- if (ret)
- {
+ if (ret) {
// if (!strncasecmp(ret, "Broken Pipe", 11))
// goto pipeagain;
printf("%s\n", ret);
diff --git a/mail.c b/mail.c
index efe32ab..445e268 100644
--- a/mail.c
+++ b/mail.c
@@ -64,13 +64,11 @@ static void *mail_child(void *arg)
PDEBUG(DEBUG_EPOINT, "child process started for sending a mail\n");
/* lower priority to keep pbx running fluently */
- if (options.schedule > 0)
- {
+ if (options.schedule > 0) {
memset(&schedp, 0, sizeof(schedp));
schedp.sched_priority = 0;
ret = sched_setscheduler(0, SCHED_OTHER, &schedp);
- if (ret < 0)
- {
+ if (ret < 0) {
PERROR("Scheduling to normal priority failed (errno = %d).\nExitting child process...\n", errno);
goto done;
}
@@ -78,8 +76,7 @@ static void *mail_child(void *arg)
/* open process */
SPRINT(command, "%s -f%s %s", SENDMAIL, options.email, email);
- if ((ph = popen(command, "w")) < 0)
- {
+ if ((ph = popen(command, "w")) < 0) {
PERROR("Cannot send mail using command '%s'\n", command);
goto done;
}
@@ -102,8 +99,7 @@ static void *mail_child(void *arg)
fprintf(ph, "\n * date: %s %d %d %d:%02d\n\n", months[mon], mday, year+1900, hour, min);
/* attach audio file */
- if ((filename[0]) && ((fh = open(filename, O_RDONLY))))
- {
+ if ((filename[0]) && ((fh = open(filename, O_RDONLY)))) {
while(strchr(filename, '/'))
filename = strchr(filename, '/')+1;
fprintf(ph, "--next_part\n");
@@ -113,23 +109,20 @@ static void *mail_child(void *arg)
fprintf(ph, "Content-Transfer-Encoding: base64\nContent-Disposition: inline;\n\tfilename=\"%s\"\n\n", filename);
/* stream from disk and encode */
- while(42)
- {
+ while(42) {
/* read exactly one line */
cnt = read(fh, rbuf, 54);
if (cnt <= 0)
break;
/* encode */
n = cnt;
- while (n%3)
- {
+ while (n%3) {
rbuf[n] = 0;
n++;
}
n = n/3;
i = 0;
- while(i<n)
- {
+ while(i<n) {
e1 = rbuf[i+i+i];
e2 = rbuf[i+i+i+1];
e3 = rbuf[i+i+i+2];
@@ -151,8 +144,7 @@ static void *mail_child(void *arg)
fprintf(ph, "\n\n");
close(fh);
- } else
- {
+ } else {
SPRINT(buffer, "-Error- Failed to read audio file: '%s'.\n\n", filename);
fprintf(ph, "%s", buffer);
PERROR("%s", buffer);
@@ -193,8 +185,7 @@ void send_mail(char *filename, char *callerid, char *callerintern, char *callern
SCPY(arg->callername, callername);
SCPY(arg->terminal, terminal);
- if ((pthread_create(&tid, NULL, mail_child, arg)<0))
- {
+ if ((pthread_create(&tid, NULL, mail_child, arg)<0)) {
PERROR("failed to create mail-thread.\n");
return;
}
diff --git a/main.c b/main.c
index 522b214..8d06aea 100644
--- a/main.c
+++ b/main.c
@@ -63,8 +63,7 @@ void debug_usleep(int msec, const char *file, int line, int hour, int min, int s
void debug(const char *function, int line, const char *prefix, char *buffer)
{
/* if we have a new debug count, we add a mark */
- if (last_debug != debug_count)
- {
+ if (last_debug != debug_count) {
last_debug = debug_count;
if (!nooutput)
printf("\033[34m--------------------- %04d.%02d.%02d %02d:%02d:%02d %06d\033[36m\n", now_tm->tm_year+1900, now_tm->tm_mon+1, now_tm->tm_mday, now_tm->tm_hour, now_tm->tm_min, now_tm->tm_sec, debug_count%1000000);
@@ -72,8 +71,7 @@ void debug(const char *function, int line, const char *prefix, char *buffer)
fprintf(debug_fp, "--------------------- %04d.%02d.%02d %02d:%02d:%02d %06d\n", now_tm->tm_year+1900, now_tm->tm_mon+1, now_tm->tm_mday, now_tm->tm_hour, now_tm->tm_min, now_tm->tm_sec, debug_count%1000000);
}
- if (!nooutput)
- {
+ if (!nooutput) {
if (debug_newline)
printf("\033[32m%06d %s\033[37m%s", debug_count%1000000, prefix?prefix:"", prefix?" ":"");
if (function)
@@ -82,10 +80,8 @@ void debug(const char *function, int line, const char *prefix, char *buffer)
printf("%s", buffer);
}
- if (debug_fp)
- {
- if (debug_newline)
- {
+ if (debug_fp) {
+ if (debug_newline) {
if (function)
fprintf(debug_fp, "%s%s(in %s() line %d): %s", prefix?prefix:"", prefix?" ":"", function, line, buffer);
else
@@ -133,8 +129,7 @@ void _printerror(const char *function, int line, const char *fmt, ...)
if (options.deb)
debug(function, line, "ERROR", buffer);
- else /* only if we do not debug */
- {
+ else { /* only if we do not debug */
if (function)
fprintf(stderr, "ERROR (in %s() line %d) %s", function, line, buffer);
else
@@ -153,12 +148,10 @@ void sighandler(int sigset)
return;
if (sigset == SIGPIPE)
return;
- if (!quit)
- {
+ if (!quit) {
quit = sigset;
/* set scheduler & priority */
- if (options.schedule > 1)
- {
+ if (options.schedule > 1) {
memset(&schedp, 0, sizeof(schedp));
schedp.sched_priority = 0;
sched_setscheduler(0, SCHED_OTHER, &schedp);
@@ -206,8 +199,7 @@ int main(int argc, char *argv[])
printf("\n** %s Version %s\n\n", NAME, VERSION_STRING);
/* show options */
- if (argc <= 1)
- {
+ if (argc <= 1) {
usage:
printf("\n");
printf("Usage: lcr (query | start | fork | rules | route)\n");
@@ -227,36 +219,31 @@ int main(int argc, char *argv[])
crc_init();
/* the mutex init */
- if (pthread_mutex_init(&mutexd, NULL))
- {
+ if (pthread_mutex_init(&mutexd, NULL)) {
fprintf(stderr, "cannot create 'PDEBUG' mutex\n");
goto free;
}
created_mutexd = 1;
-// if (pthread_mutex_init(&mutext, NULL))
-// {
+// if (pthread_mutex_init(&mutext, NULL)) {
// fprintf(stderr, "cannot create 'trace' mutex\n");
// goto free;
// }
// created_mutext = 1;
- if (pthread_mutex_init(&mutexe, NULL))
- {
+ if (pthread_mutex_init(&mutexe, NULL)) {
fprintf(stderr, "cannot create 'PERROR' mutex\n");
goto free;
}
created_mutexe = 1;
/* show interface */
- if (!(strcasecmp(argv[1],"interface")))
- {
+ if (!(strcasecmp(argv[1],"interface"))) {
doc_interface();
ret = 0;
goto free;
}
/* show rules */
- if (!(strcasecmp(argv[1],"rules")))
- {
+ if (!(strcasecmp(argv[1],"rules"))) {
if (argc <= 2)
doc_rules(NULL);
else
@@ -266,8 +253,7 @@ int main(int argc, char *argv[])
}
/* query available isdn ports */
- if (!(strcasecmp(argv[1],"query")))
- {
+ if (!(strcasecmp(argv[1],"query"))) {
fprintf(stderr, "-> Using 'misdn_info'\n");
system("misdn_info");
ret = 0;
@@ -275,8 +261,7 @@ int main(int argc, char *argv[])
}
/* read options */
- if (read_options() == 0)
- {
+ if (read_options() == 0) {
PERROR("%s", options_error);
goto free;
}
@@ -293,8 +278,7 @@ int main(int argc, char *argv[])
/* set pointer to main ruleset */
ruleset_main = getrulesetbyname("main");
- if (!ruleset_main)
- {
+ if (!ruleset_main) {
fprintf(stderr, "\n***\n -> Missing 'main' ruleset, causing ALL calls to be disconnected.\n***\n\n");
PDEBUG(DEBUG_LOG, "Missing 'main' ruleset, causing ALL calls to be disconnected.\n");
sleep(2);
@@ -302,8 +286,7 @@ int main(int argc, char *argv[])
#if 0
/* query available isdn ports */
- if (!(strcasecmp(argv[1],"route")))
- {
+ if (!(strcasecmp(argv[1],"route"))) {
ruleset_debug(ruleset_first);
ret = 0;
goto free;
@@ -311,21 +294,18 @@ int main(int argc, char *argv[])
#endif
/* do fork in special cases */
- if (!(strcasecmp(argv[1],"fork")))
- {
+ if (!(strcasecmp(argv[1],"fork"))) {
pid_t pid;
FILE *pidfile;
/* do daemon fork */
pid = fork();
- if (pid < 0)
- {
+ if (pid < 0) {
fprintf(stderr, "Cannot fork!\n");
goto free;
}
- if (pid != 0)
- {
+ if (pid != 0) {
exit(0);
}
usleep(200000);
@@ -334,13 +314,11 @@ int main(int argc, char *argv[])
/* do second fork */
pid = fork();
- if (pid < 0)
- {
+ if (pid < 0) {
fprintf(stderr, "Cannot fork!\n");
goto free;
}
- if (pid != 0)
- {
+ if (pid != 0) {
printf("LCR: Starting daemon.\n");
exit(0);
}
@@ -348,28 +326,24 @@ int main(int argc, char *argv[])
/* write pid file */
pidfile = fopen("/var/run/lcr.pid","w");
- if (pidfile)
- {
+ if (pidfile) {
fprintf(pidfile, "%d\n", getpid());
fclose(pidfile);
}
} else
/* if not start */
- if (!!strcasecmp(argv[1],"start"))
- {
+ if (!!strcasecmp(argv[1],"start")) {
goto usage;
}
/* create lock and lock! */
SPRINT(lock, "%s/lcr.lock", options.lock);
- if ((lockfd = open(lock, O_CREAT | O_WRONLY, S_IWUSR)) < 0)
- {
+ if ((lockfd = open(lock, O_CREAT | O_WRONLY, S_IWUSR)) < 0) {
fprintf(stderr, "Cannot create lock file: %s\n", lock);
fprintf(stderr, "Check options.conf to change to path with permissions for you.\n");
goto free;
}
- if (flock(lockfd, LOCK_EX|LOCK_NB) < 0)
- {
+ if (flock(lockfd, LOCK_EX|LOCK_NB) < 0) {
if (errno == EWOULDBLOCK)
fprintf(stderr, "LCR: Another LCR process is running. Please kill the other one.\n");
else fprintf(stderr, "Locking process failed: errno=%d\n", errno);
@@ -378,8 +352,7 @@ int main(int argc, char *argv[])
created_lock = 1;
/* initialize admin socket */
- if (admin_init())
- {
+ if (admin_init()) {
fprintf(stderr, "Unable to initialize admin socket.\n");
goto free;
}
@@ -388,30 +361,26 @@ int main(int argc, char *argv[])
generate_tables(options.law);
/* load tones (if requested) */
- if (fetch_tones() == 0)
- {
+ if (fetch_tones() == 0) {
fprintf(stderr, "Unable to fetch tones into memory.\n");
goto free;
}
#ifdef WITH_GSM
/* handle gsm */
- if (options.gsm && gsm_init())
- {
+ if (options.gsm && gsm_init()) {
fprintf(stderr, "GSM initialization failed.\n");
goto free;
}
#else
- if (options.gsm)
- {
+ if (options.gsm) {
fprintf(stderr, "GSM is enabled, but not compiled. Use --with-gsm while configure!\n");
goto free;
}
#endif
/* read interfaces and open ports */
- if (!read_interfaces())
- {
+ if (!read_interfaces()) {
PERROR_RUNTIME("No interfaces specified or failed to parse interface.conf.\n");
fprintf(stderr, "No interfaces specified or failed to parse interface.conf.\n");
goto free;
@@ -422,17 +391,14 @@ int main(int argc, char *argv[])
/* locking memory paging */
i = 0;
- while(i < 10)
- {
+ while(i < 10) {
if (mlockall(MCL_CURRENT | MCL_FUTURE) >= 0)
break;
usleep(200000);
i++;
}
- if (i == 10)
- {
- switch(errno)
- {
+ if (i == 10) {
+ switch(errno) {
case ENOMEM:
fprintf(stderr, "Warning: Not enough memory to lock paging.\n");
break;
@@ -448,13 +414,11 @@ int main(int argc, char *argv[])
}
/* set real time scheduler & priority */
- if (options.schedule > 1)
- {
+ if (options.schedule > 1) {
memset(&schedp, 0, sizeof(schedp));
schedp.sched_priority = options.schedule;
ret = sched_setscheduler(0, SCHED_RR, &schedp);
- if (ret < 0)
- {
+ if (ret < 0) {
PERROR("Scheduling failed with given priority %d (errno = %d).\nCheck options.conf 'schedule', exitting...\n", options.schedule, errno);
goto free;
}
@@ -474,13 +438,11 @@ int main(int argc, char *argv[])
end_trace();
GET_NOW();
quit = 0;
- while(!quit)
- {
+ while(!quit) {
last_d = now_d;
GET_NOW();
- if (now_d-last_d > 1.0)
- {
+ if (now_d-last_d > 1.0) {
PERROR("LCR was stalling %d.%d seconds\n", ((int)((now_d-last_d)*10.0))/10, (int)((now_d-last_d)*10.0));
}
/* all loops must be counted from the beginning since nodes might get freed during handler */
@@ -501,8 +463,7 @@ BUDETECT
/* loop through all port ports and call their handler */
port_again:
port = port_first;
- while(port)
- {
+ while(port) {
debug_prefix = port->p_name;
debug_count++;
ret = port->handler();
@@ -516,8 +477,7 @@ BUDETECT
/* loop through all epoint and call their handler */
epoint_again:
epoint = epoint_first;
- while(epoint)
- {
+ while(epoint) {
debug_prefix = prefix_string;
SPRINT(prefix_string, "ep%ld", epoint->ep_serial);
debug_count++;
@@ -532,8 +492,7 @@ BUDETECT
/* loop through all joins and call their handler */
join_again:
join = join_first;
- while(join)
- {
+ while(join) {
debug_prefix = "join";
debug_count++;
ret = join->handler();
@@ -549,25 +508,19 @@ BUDETECT
/* process any message */
debug_count++;
debug_prefix = "message";
- while ((message = message_get()))
- {
+ while ((message = message_get())) {
all_idle = 0;
- switch(message->flow)
- {
+ switch(message->flow) {
case PORT_TO_EPOINT:
debug_prefix = "msg port->epoint";
epoint = find_epoint_id(message->id_to);
- if (epoint)
- {
- if (epoint->ep_app)
- {
+ if (epoint) {
+ if (epoint->ep_app) {
epoint->ep_app->ea_message_port(message->id_from, message->type, &message->param);
- } else
- {
+ } else {
PDEBUG(DEBUG_MSG, "Warning: message %s from port %d to endpoint %d. endpoint doesn't have an application.\n", messages_txt[message->type], message->id_from, message->id_to);
}
- } else
- {
+ } else {
PDEBUG(DEBUG_MSG, "Warning: message %s from port %d to endpoint %d. endpoint doesn't exist anymore.\n", messages_txt[message->type], message->id_from, message->id_to);
}
break;
@@ -575,11 +528,9 @@ BUDETECT
case EPOINT_TO_JOIN:
debug_prefix = "msg epoint->join";
join = find_join_id(message->id_to);
- if (join)
- {
+ if (join) {
join->message_epoint(message->id_from, message->type, &message->param);
- } else
- {
+ } else {
PDEBUG(DEBUG_MSG, "Warning: message %s from endpoint %d to join %d. join doesn't exist anymore\n", messages_txt[message->type], message->id_from, message->id_to);
}
break;
@@ -587,17 +538,13 @@ BUDETECT
case JOIN_TO_EPOINT:
debug_prefix = "msg join->epoint";
epoint = find_epoint_id(message->id_to);
- if (epoint)
- {
- if (epoint->ep_app)
- {
+ if (epoint) {
+ if (epoint->ep_app) {
epoint->ep_app->ea_message_join(message->id_from, message->type, &message->param);
- } else
- {
+ } else {
PDEBUG(DEBUG_MSG, "Warning: message %s from join %d to endpoint %d. endpoint doesn't have an application.\n", messages_txt[message->type], message->id_from, message->id_to);
}
- } else
- {
+ } else {
PDEBUG(DEBUG_MSG, "Warning: message %s from join %d to endpoint %d. endpoint doesn't exist anymore.\n", messages_txt[message->type], message->id_from, message->id_to);
}
break;
@@ -605,12 +552,10 @@ BUDETECT
case EPOINT_TO_PORT:
debug_prefix = "msg epoint->port";
port = find_port_id(message->id_to);
- if (port)
- {
+ if (port) {
port->message_epoint(message->id_from, message->type, &message->param);
BUDETECT
- } else
- {
+ } else {
PDEBUG(DEBUG_MSG, "Warning: message %s from endpoint %d to port %d. port doesn't exist anymore\n", messages_txt[message->type], message->id_from, message->id_to);
}
break;
@@ -640,8 +585,7 @@ BUDETECT
#if 0
/* check for child to exit (eliminate zombies) */
- if (waitpid(-1, NULL, WNOHANG) > 0)
- {
+ if (waitpid(-1, NULL, WNOHANG) > 0) {
PDEBUG(DEBUG_EPOINT, "a child process (created by endpoint) has exitted.\n");
all_idle = 0;
}
@@ -650,16 +594,14 @@ BUDETECT
// debug_usleep(1, __FILE__, __LINE__, now_tm->tm_hour, now_tm->tm_min, now_tm->tm_sec);
/* do idle checking */
- if (idlecheck != now)
- {
+ if (idlecheck != now) {
PDEBUG(DEBUG_IDLETIME, "Idle time : %d%%\n", idletime/10000);
idletime = 0;
idlecheck = now;
}
/* did we do nothing? so we wait to give time to other processes */
- if (all_idle)
- {
+ if (all_idle) {
// pthread_mutex_unlock(&mutex_lcr); // unlock LCR
debug_usleep(4000, __FILE__, __LINE__, now_tm->tm_hour, now_tm->tm_min, now_tm->tm_sec);
// pthread_mutex_lock(&mutex_lcr); // lock LCR
@@ -680,15 +622,13 @@ free:
/* set scheduler & priority
*/
- if (options.schedule > 1)
- {
+ if (options.schedule > 1) {
memset(&schedp, 0, sizeof(schedp));
schedp.sched_priority = options.schedule;
sched_setscheduler(0, SCHED_OTHER, &schedp);
}
/* reset signals */
- if (created_signal)
- {
+ if (created_signal) {
signal(SIGINT,SIG_DFL);
signal(SIGHUP,SIG_DFL);
signal(SIGTERM,SIG_DFL);
@@ -698,13 +638,11 @@ free:
/* destroy objects */
debug_prefix = "free";
- while(port_first)
- {
+ while(port_first) {
debug_count++;
delete port_first;
}
- while(epoint_first)
- {
+ while(epoint_first) {
debug_count++;
delete epoint_first;
}
@@ -723,13 +661,11 @@ free:
/* flush messages */
debug_count++;
i = 0;
- while ((message = message_get()))
- {
+ while ((message = message_get())) {
i++;
message_free(message);
}
- if (i)
- {
+ if (i) {
PDEBUG(DEBUG_MSG, "freed %d pending messages\n", i);
}
@@ -743,8 +679,7 @@ free:
/* close lock */
if (created_lock)
flock(lockfd, LOCK_UN);
- if (lockfd >= 0)
- {
+ if (lockfd >= 0) {
chmod(lock, 0700);
unlink(lock);
close(lockfd);
@@ -778,8 +713,7 @@ free:
/* display memory leak */
#define MEMCHECK(a, b) \
- if (b) \
- { \
+ if (b) { \
SPRINT(tracetext, a, NAME); \
start_trace(-1, NULL, NULL, NULL, 0, 0, 0, tracetext); \
if (ret) add_trace("blocks", NULL, "%d", b); \
@@ -823,22 +757,16 @@ void budetect(const char *file, int line, const char *function)
struct mISDNport *mISDNport = mISDNport_first;
int i, ii;
- while(mISDNport)
- {
+ while(mISDNport) {
i = 0;
ii = mISDNport->b_num;
- while(i < ii)
- {
- if (mISDNport->b_port[i])
- {
+ while(i < ii) {
+ if (mISDNport->b_port[i]) {
port = port_first;
- while(port)
- {
- if ((port->p_type&PORT_CLASS_MASK) == PORT_CLASS_ISDN)
- {
+ while(port) {
+ if ((port->p_type&PORT_CLASS_MASK) == PORT_CLASS_ISDN) {
pmisdn = (class PmISDN *)port;
- if (pmisdn->p_isdn_crypt_listen)
- {
+ if (pmisdn->p_isdn_crypt_listen) {
PERROR_RUNTIME("************************************************\n");
PERROR_RUNTIME("** BUG detected in %s, line %d, function %s\n", file, line, function);
PERROR_RUNTIME("** p_isdn_crypt_listen = %d\n", pmisdn->p_isdn_crypt_listen);
@@ -849,8 +777,7 @@ void budetect(const char *file, int line, const char *function)
if (port == mISDNport->b_port[i])
break;
port = port->next;
- if (!port)
- {
+ if (!port) {
PERROR_RUNTIME("************************************************\n");
PERROR_RUNTIME("** BUG detected in %s, line %d, function %s\n", file, line, function);
PERROR_RUNTIME("** b_port not in list.\n");
diff --git a/message.c b/message.c
index ff0d70c..403253d 100644
--- a/message.c
+++ b/message.c
@@ -37,8 +37,7 @@ struct lcr_msg *message_create(int id_from, int id_to, int flow, int type)
/* attaches a message to the end of the message chain */
void message_put(struct lcr_msg *message)
{
- if (message->id_to == 0)
- {
+ if (message->id_to == 0) {
PDEBUG(DEBUG_MSG, "message %s not written, because destination is 0.\n", messages_txt[message->type]);
message_free(message);
return;
@@ -77,9 +76,7 @@ struct lcr_msg *message_get(void)
struct lcr_msg *message;
if (!message_first)
- {
return(0);
- }
message = message_first;
message_first = message->next;
diff --git a/route.c b/route.c
index da59e98..d47f8c2 100644
--- a/route.c
+++ b/route.c
@@ -388,17 +388,14 @@ void doc_rules(const char *name)
{
int i, j;
- if (name)
- {
+ if (name) {
i = 0;
- while(action_defs[i].name)
- {
+ while(action_defs[i].name) {
if (!strcasecmp(action_defs[i].name, name))
break;
i++;
}
- if (!action_defs[i].name)
- {
+ if (!action_defs[i].name) {
fprintf(stderr, "Given action '%s' unknown.\n", name);
return;
}
@@ -412,13 +409,11 @@ void doc_rules(const char *name)
printf("...\n");
printf("Please refer to the documentation for description on rule format.\n\n");
- if (!name)
- {
+ if (!name) {
printf("Available conditions to match:\n");
printf("------------------------------\n\n");
i = 0;
- while(cond_defs[i].name)
- {
+ while(cond_defs[i].name) {
printf("Usage: %s\n", cond_defs[i].doc);
printf("%s\n\n", cond_defs[i].help);
i++;
@@ -426,38 +421,31 @@ void doc_rules(const char *name)
printf("Available actions with their parameters:\n");
printf("----------------------------------------\n\n");
- } else
- {
+ } else {
printf("Detailes parameter description of action:\n");
printf("-----------------------------------------\n\n");
}
i = 0;
- while(action_defs[i].name)
- {
- if (name && !!strcmp(action_defs[i].name,name)) /* not selected */
- {
+ while(action_defs[i].name) {
+ if (name && !!strcmp(action_defs[i].name,name)) { /* not selected */
i++;
continue;
}
- if (!action_defs[i].help) /* not internal actions */
- {
+ if (!action_defs[i].help) { /* not internal actions */
i++;
continue;
}
printf("Usage: %s", action_defs[i].name);
j = 0;
- while(j < 64)
- {
+ while(j < 64) {
if ((1LL<<j) & action_defs[i].params)
printf(" [%s]", param_defs[j].doc);
j++;
}
printf("\n%s\n\n", action_defs[i].help);
- if (name) /* only show parameter help for specific action */
- {
+ if (name) { /* only show parameter help for specific action */
j = 0;
- while(j < 64)
- {
+ while(j < 64) {
if ((1LL<<j) & action_defs[i].params)
printf("%s:\n\t%s\n", param_defs[j].doc, param_defs[j].help);
j++;
@@ -476,24 +464,19 @@ void ruleset_free(struct route_ruleset *ruleset_start)
struct route_action *action;
struct route_param *param;
- while(ruleset_start)
- {
+ while(ruleset_start) {
ruleset = ruleset_start;
ruleset_start = ruleset->next;
- while(ruleset->rule_first)
- {
+ while(ruleset->rule_first) {
rule = ruleset->rule_first;
ruleset->rule_first = rule->next;
- while(rule->cond_first)
- {
+ while(rule->cond_first) {
cond = rule->cond_first;
- if (cond->string_value)
- {
+ if (cond->string_value) {
FREE(cond->string_value, 0);
rmemuse--;
}
- if (cond->string_value_to)
- {
+ if (cond->string_value_to) {
FREE(cond->string_value_to, 0);
rmemuse--;
}
@@ -501,16 +484,13 @@ void ruleset_free(struct route_ruleset *ruleset_start)
FREE(cond, sizeof(struct route_cond));
rmemuse--;
}
- while(rule->action_first)
- {
+ while(rule->action_first) {
action = rule->action_first;
rule->action_first = action->next;
- while(action->param_first)
- {
+ while(action->param_first) {
param = action->param_first;
action->param_first = param->next;
- if (param->string_value)
- {
+ if (param->string_value) {
FREE(param->string_value, 0);
rmemuse--;
}
@@ -538,17 +518,14 @@ void ruleset_debug(struct route_ruleset *ruleset_start)
int first;
ruleset = ruleset_start;
- while(ruleset)
- {
+ while(ruleset) {
printf("Ruleset: '%s'\n", ruleset->name);
rule = ruleset->rule_first;
- while(rule)
- {
+ while(rule) {
/* CONDITION */
first = 1;
cond = rule->cond_first;
- while(cond)
- {
+ while(cond) {
if (first)
printf(" Condition:");
else
@@ -558,8 +535,7 @@ void ruleset_debug(struct route_ruleset *ruleset_start)
if (cond->value_type != VALUE_TYPE_NULL)
printf(" = ");
next_cond_value:
- switch(cond->value_type)
- {
+ switch(cond->value_type) {
case VALUE_TYPE_NULL:
break;
@@ -582,8 +558,7 @@ void ruleset_debug(struct route_ruleset *ruleset_start)
default:
printf("Software error: VALUE_TYPE_* %d not known in function '%s' line=%d", cond->value_type, __FUNCTION__, __LINE__);
}
- if (cond->value_extension && cond->next)
- {
+ if (cond->value_extension && cond->next) {
cond = cond->next;
printf(" or ");
goto next_cond_value;
@@ -595,14 +570,12 @@ void ruleset_debug(struct route_ruleset *ruleset_start)
/* ACTION */
action = rule->action_first;
- while(action)
- {
+ while(action) {
printf(" Action: %s\n", action_defs[action->index].name);
/* PARAM */
first = 1;
param = action->param_first;
- while(param)
- {
+ while(param) {
if (first)
printf(" Param:");
else
@@ -611,16 +584,13 @@ void ruleset_debug(struct route_ruleset *ruleset_start)
printf(" %s", param_defs[param->index].name);
if (param->value_type != VALUE_TYPE_NULL)
printf(" = ");
- switch(param->value_type)
- {
+ switch(param->value_type) {
case VALUE_TYPE_NULL:
break;
case VALUE_TYPE_INTEGER:
- if (param_defs[param->index].type == PARAM_TYPE_CALLERIDTYPE)
- {
- switch(param->integer_value)
- {
+ if (param_defs[param->index].type == PARAM_TYPE_CALLERIDTYPE) {
+ switch(param->integer_value) {
case INFO_NTYPE_UNKNOWN:
printf("unknown");
break;
@@ -638,10 +608,8 @@ void ruleset_debug(struct route_ruleset *ruleset_start)
}
break;
}
- if (param_defs[param->index].type == PARAM_TYPE_CAPABILITY)
- {
- switch(param->integer_value)
- {
+ if (param_defs[param->index].type == PARAM_TYPE_CAPABILITY) {
+ switch(param->integer_value) {
case INFO_BC_SPEECH:
printf("speech");
break;
@@ -665,10 +633,8 @@ void ruleset_debug(struct route_ruleset *ruleset_start)
}
break;
}
- if (param_defs[param->index].type == PARAM_TYPE_DIVERSION)
- {
- switch(param->integer_value)
- {
+ if (param_defs[param->index].type == PARAM_TYPE_DIVERSION) {
+ switch(param->integer_value) {
case INFO_DIVERSION_CFU:
printf("cfu");
break;
@@ -686,10 +652,8 @@ void ruleset_debug(struct route_ruleset *ruleset_start)
}
break;
}
- if (param_defs[param->index].type == PARAM_TYPE_TYPE)
- {
- switch(param->integer_value)
- {
+ if (param_defs[param->index].type == PARAM_TYPE_TYPE) {
+ switch(param->integer_value) {
case INFO_NTYPE_UNKNOWN:
printf("unknown");
break;
@@ -707,10 +671,8 @@ void ruleset_debug(struct route_ruleset *ruleset_start)
}
break;
}
- if (param_defs[param->index].type == PARAM_TYPE_YESNO)
- {
- switch(param->integer_value)
- {
+ if (param_defs[param->index].type == PARAM_TYPE_YESNO) {
+ switch(param->integer_value) {
case 1:
printf("yes");
break;
@@ -722,8 +684,7 @@ void ruleset_debug(struct route_ruleset *ruleset_start)
}
break;
}
- if (param_defs[param->index].type == PARAM_TYPE_NULL)
- {
+ if (param_defs[param->index].type == PARAM_TYPE_NULL) {
break;
}
printf("%d", param->integer_value);
@@ -760,28 +721,22 @@ static char *read_string(char *p, char *key, int key_size, const char *special)
{
key[0] = 0;
- if (*p == '\"')
- {
+ if (*p == '\"') {
p++;
/* quote */
- while(*p)
- {
- if (*p == '\"')
- {
+ while(*p) {
+ if (*p == '\"') {
p++;
*key = '\0';
return(p);
}
- if (*p == '\\')
- {
+ if (*p == '\\') {
p++;
- if (*p == '\0')
- {
+ if (*p == '\0') {
break;
}
}
- if (--key_size == 0)
- {
+ if (--key_size == 0) {
UPRINT(key, "\001String too long.");
return(p);
}
@@ -792,24 +747,19 @@ static char *read_string(char *p, char *key, int key_size, const char *special)
}
/* no quote */
- while(*p)
- {
- if (strchr(special, *p))
- {
+ while(*p) {
+ if (strchr(special, *p)) {
*key = '\0';
return(p);
}
- if (*p == '\\')
- {
+ if (*p == '\\') {
p++;
- if (*p == '\0')
- {
+ if (*p == '\0') {
UPRINT(key, "\001Unexpected end of line.");
return(p);
}
}
- if (--key_size == 0)
- {
+ if (--key_size == 0) {
UPRINT(key, "\001String too long.");
return(p);
}
@@ -857,10 +807,8 @@ struct route_ruleset *ruleset_parse(void)
/* check the integrity of IDs for ACTION_* and PARAM_* */
i = 0;
- while(action_defs[i].name)
- {
- if (action_defs[i].id != i)
- {
+ while(action_defs[i].name) {
+ if (action_defs[i].id != i) {
PERROR("Software Error action '%s' must have id of %d, but has %d.\n",
action_defs[i].name, i, action_defs[i].id);
goto openerror;
@@ -868,10 +816,8 @@ struct route_ruleset *ruleset_parse(void)
i++;
}
i = 0; j = 1;
- while(param_defs[i].name)
- {
- if (param_defs[i].id != j)
- {
+ while(param_defs[i].name) {
+ if (param_defs[i].id != j) {
PERROR("Software Error param '%s' must have id of 0x%llx, but has 0x%llx.\n",
param_defs[i].name, j, param_defs[i].id);
goto openerror;
@@ -917,8 +863,7 @@ struct route_ruleset *ruleset_parse(void)
}
/* skip comments */
- if (*p == '#')
- {
+ if (*p == '#') {
p++;
/* don't skip "define" */
if (!!strncmp(p, "define", 6))
@@ -927,21 +872,18 @@ struct route_ruleset *ruleset_parse(void)
if (*p != 32)
continue;
/* skip spaces */
- while(*p == 32)
- {
+ while(*p == 32) {
if (*p == 0)
break;
p++;
}
p++;
p = read_string(p, key, sizeof(key), " ");
- if (key[0] == 1) /* error */
- {
+ if (key[0] == 1) { /* error */
SPRINT(failure, "Parsing Filename failed: %s", key+1);
goto parse_error;
}
- if (nesting == MAXNESTING-1)
- {
+ if (nesting == MAXNESTING-1) {
SPRINT(failure, "'include' is nesting too deep.\n");
goto parse_error;
}
@@ -949,8 +891,7 @@ struct route_ruleset *ruleset_parse(void)
SCPY(filename[nesting+1], key);
else
SPRINT(filename[nesting+1], "%s/%s", CONFIG_DATA, key);
- if (!(fp[nesting+1]=fopen(filename[nesting+1],"r")))
- {
+ if (!(fp[nesting+1]=fopen(filename[nesting+1],"r"))) {
PERROR("Cannot open %s\n", filename[nesting+1]);
goto parse_error;
}
@@ -966,12 +907,10 @@ struct route_ruleset *ruleset_parse(void)
continue;
/* expecting ruleset */
- if (expecting)
- {
+ if (expecting) {
new_ruleset:
/* expecting [ */
- if (*p != '[')
- {
+ if (*p != '[') {
SPRINT(failure, "Expecting ruleset name starting with '['.");
goto parse_error;
}
@@ -979,8 +918,7 @@ struct route_ruleset *ruleset_parse(void)
/* reading ruleset name text */
i = 0;
- while(*p>' ' && *p<127 && *p!=']')
- {
+ while(*p>' ' && *p<127 && *p!=']') {
if (*p>='A' && *p<='Z') *p = *p-'A'+'a'; /* lower case */
key[i++] = *p++;
if (i == sizeof(key)) i--; /* limit */
@@ -1004,10 +942,8 @@ struct route_ruleset *ruleset_parse(void)
/* check for duplicate rulesets */
ruleset = ruleset_start;
- while(ruleset)
- {
- if (!strcmp(ruleset->name, key))
- {
+ while(ruleset) {
+ if (!strcmp(ruleset->name, key)) {
SPRINT(failure, "Duplicate ruleset '%s', already defined in file '%s' line %d.", key, ruleset->file, ruleset->line);
goto parse_error;
}
@@ -1028,8 +964,7 @@ struct route_ruleset *ruleset_parse(void)
}
/* for new ruleset [ */
- if (*p == '[')
- {
+ if (*p == '[') {
goto new_ruleset;
}
@@ -1044,65 +979,53 @@ struct route_ruleset *ruleset_parse(void)
rule->line = line[nesting];
/* loop CONDITIONS */
- while(*p!=':' && *p!='\0')
- {
+ while(*p!=':' && *p!='\0') {
/* read item text */
i = 0;
- while((*p>='a' && *p<='z') || (*p>='A' && *p<='Z') || (*p>='0' && *p<='9'))
- {
+ while((*p>='a' && *p<='z') || (*p>='A' && *p<='Z') || (*p>='0' && *p<='9')) {
if (*p>='A' && *p<='Z') *p = *p-'A'+'a'; /* lower case */
key[i++] = *p++;
if (i == sizeof(key)) i--; /* limit */
}
key[i] = 0;
- if (key[0] == '\0')
- {
+ if (key[0] == '\0') {
SPRINT(failure, "Expecting condition item name or ':' for end of condition list.");
goto parse_error;
}
- if (*p!=' ' && *p!='=')
- {
+ if (*p!=' ' && *p!='=') {
SPRINT(failure, "Illegal character '%c' after condition name '%s'. Expecting '=' for equation or ' ' to seperate condition items.", *p, key);
goto parse_error;
}
/* check if condition exists */
index = 0;
- while(cond_defs[index].name)
- {
+ while(cond_defs[index].name) {
if (!strcmp(cond_defs[index].name, key))
break;
index++;
}
- if (cond_defs[index].name == NULL)
- {
+ if (cond_defs[index].name == NULL) {
SPRINT(failure, "Unknown condition item name '%s'.", key);
goto parse_error;
}
/* items without values must not have any parameter */
- if (cond_defs[index].type == COND_TYPE_NULL)
- {
- if (*p == '=')
- {
+ if (cond_defs[index].type == COND_TYPE_NULL) {
+ if (*p == '=') {
SPRINT(failure, "Condition item '%s' must not have any value. Don't use '=' for this type of condition.", key);
goto parse_error;
}
- if (*p != ' ')
- {
+ if (*p != ' ') {
SPRINT(failure, "Condition item '%s' must not have any value. Expecting ' ' or tab after item name.", key);
goto parse_error;
}
// p++;
- } else
- {
- if (*p == ' ')
- {
+ } else {
+ if (*p == ' ') {
SPRINT(failure, "Condition item '%s' must have at least one value, '=' expected, and not a space.", key);
goto parse_error;
}
- if (*p != '=')
- {
+ if (*p != '=') {
SPRINT(failure, "Condition item '%s' must have at least one value, '=' expected.", key);
goto parse_error;
}
@@ -1111,10 +1034,8 @@ struct route_ruleset *ruleset_parse(void)
/* check for duplicate condition */
cond = rule->cond_first;
- while(cond)
- {
- if (cond->index == index)
- {
+ while(cond) {
+ if (cond->index == index) {
SPRINT(failure, "Duplicate condition '%s', use ',' to give multiple values.", key);
goto parse_error;
}
@@ -1129,11 +1050,9 @@ struct route_ruleset *ruleset_parse(void)
cond_pointer = &(cond->next);
cond->index = index;
cond->match = cond_defs[index].match;
- switch(cond_defs[index].type)
- {
+ switch(cond_defs[index].type) {
case COND_TYPE_NULL:
- if (*p=='=')
- {
+ if (*p=='=') {
SPRINT(failure, "Expecting no value.");
goto parse_error;
}
@@ -1148,40 +1067,33 @@ struct route_ruleset *ruleset_parse(void)
case COND_TYPE_WDAY:
case COND_TYPE_YEAR:
integer = integer_to = 0;
- if (*p==',' || *p==' ' || *p=='\0')
- {
+ if (*p==',' || *p==' ' || *p=='\0') {
SPRINT(failure, "Missing integer value.");
goto parse_error;
}
- while(*p>='0' && *p<='9')
- {
+ while(*p>='0' && *p<='9') {
integer = integer*10 + *p-'0';
p++;
}
value_type = VALUE_TYPE_INTEGER;
- if (*p == '-')
- {
+ if (*p == '-') {
p++;
- if (*p==',' || *p==' ' || *p=='\0')
- {
+ if (*p==',' || *p==' ' || *p=='\0') {
SPRINT(failure, "Missing integer value.");
goto parse_error;
}
- while(*p>='0' && *p<='9')
- {
+ while(*p>='0' && *p<='9') {
integer_to = integer_to*10 + *p-'0';
p++;
}
value_type = VALUE_TYPE_INTEGER_RANGE;
}
- if (cond_defs[index].type == COND_TYPE_TIME)
- {
+ if (cond_defs[index].type == COND_TYPE_TIME) {
// Simon: i store the time as decimal, later i compare it correctly:
// hours * 100 + minutes
if (integer == 2400)
integer = 0;
- if (integer >= 2400)
- {
+ if (integer >= 2400) {
timeoutofrange1:
SPRINT(failure, "Given time '%d' not in range 0000..2359 (or 2400 for 0000)", integer);
goto parse_error;
@@ -1192,8 +1104,7 @@ struct route_ruleset *ruleset_parse(void)
goto integer_done;
if (integer_to == 2400)
integer_to = 0;
- if (integer_to >= 2400)
- {
+ if (integer_to >= 2400) {
timeoutofrange2:
SPRINT(failure, "Given time '%d' not in range 0000..2359 (or 2400 for 0000)", integer_to);
goto parse_error;
@@ -1201,62 +1112,50 @@ struct route_ruleset *ruleset_parse(void)
if (integer_to%100 >= 60)
goto timeoutofrange2;
}
- if (cond_defs[index].type == COND_TYPE_MDAY)
- {
- if (integer<1 || integer>31)
- {
+ if (cond_defs[index].type == COND_TYPE_MDAY) {
+ if (integer<1 || integer>31) {
SPRINT(failure, "Given day-of-month '%d' not in range 1..31", integer);
goto parse_error;
}
if (value_type == VALUE_TYPE_INTEGER)
goto integer_done;
- if (integer_to<1 || integer_to>31)
- {
+ if (integer_to<1 || integer_to>31) {
SPRINT(failure, "Given day-of-month '%d' not in range 1..31", integer_to);
goto parse_error;
}
}
- if (cond_defs[index].type == COND_TYPE_WDAY)
- {
- if (integer<1 || integer>7)
- {
+ if (cond_defs[index].type == COND_TYPE_WDAY) {
+ if (integer<1 || integer>7) {
SPRINT(failure, "Given day-of-week '%d' not in range 1..7", integer);
goto parse_error;
}
if (value_type == VALUE_TYPE_INTEGER)
goto integer_done;
- if (integer_to<1 || integer_to>7)
- {
+ if (integer_to<1 || integer_to>7) {
SPRINT(failure, "Given day-of-week '%d' not in range 1..7", integer_to);
goto parse_error;
}
}
- if (cond_defs[index].type == COND_TYPE_MONTH)
- {
- if (integer<1 || integer>12)
- {
+ if (cond_defs[index].type == COND_TYPE_MONTH) {
+ if (integer<1 || integer>12) {
SPRINT(failure, "Given month '%d' not in range 1..12", integer);
goto parse_error;
}
if (value_type == VALUE_TYPE_INTEGER)
goto integer_done;
- if (integer_to<1 || integer_to>12)
- {
+ if (integer_to<1 || integer_to>12) {
SPRINT(failure, "Given month '%d' not in range 1..12", integer_to);
goto parse_error;
}
}
- if (cond_defs[index].type == COND_TYPE_YEAR)
- {
- if (integer<1970 || integer>2106)
- {
+ if (cond_defs[index].type == COND_TYPE_YEAR) {
+ if (integer<1970 || integer>2106) {
SPRINT(failure, "Given year '%d' not in range 1970..2106", integer);
goto parse_error;
}
if (value_type == VALUE_TYPE_INTEGER)
goto integer_done;
- if (integer_to<1970 || integer_to>2106)
- {
+ if (integer_to<1970 || integer_to>2106) {
SPRINT(failure, "Given year '%d' not in range 1970..2106", integer_to);
goto parse_error;
}
@@ -1270,40 +1169,33 @@ struct route_ruleset *ruleset_parse(void)
/* parse all string values/ranges */
case COND_TYPE_STRING:
key[0] = key_to[0] = '\0';
- if (*p==',' || *p==' ' || *p=='\0')
- {
+ if (*p==',' || *p==' ' || *p=='\0') {
SPRINT(failure, "Missing string value, use \"\" for empty string.");
goto parse_error;
}
p = read_string(p, key, sizeof(key), "-, ");
- if (key[0] == 1) /* error */
- {
+ if (key[0] == 1) { /* error */
SPRINT(failure, "Parsing String failed: %s", key+1);
goto parse_error;
}
value_type = VALUE_TYPE_STRING;
- if (*p == '-')
- {
+ if (*p == '-') {
p++;
- if (*p==',' || *p==' ' || *p=='\0')
- {
+ if (*p==',' || *p==' ' || *p=='\0') {
SPRINT(failure, "Missing string value, use \"\" for empty string.");
goto parse_error;
}
p = read_string(p, key_to, sizeof(key_to), "-, ");
- if (key_to[0] == 1) /* error */
- {
+ if (key_to[0] == 1) { /* error */
SPRINT(failure, "Parsing string failed: %s", key_to+1);
goto parse_error;
}
value_type = VALUE_TYPE_STRING_RANGE;
- if (strlen(key) != strlen(key_to))
- {
+ if (strlen(key) != strlen(key_to)) {
SPRINT(failure, "Given range of strings \"%s\"-\"%s\" have unequal length.", key, key_to);
goto parse_error;
}
- if (key[0] == '\0')
- {
+ if (key[0] == '\0') {
SPRINT(failure, "Given range has no length.");
goto parse_error;
}
@@ -1312,8 +1204,7 @@ struct route_ruleset *ruleset_parse(void)
cond->string_value = (char *)MALLOC(strlen(key)+1);
rmemuse++;
UCPY(cond->string_value, key);
- if (value_type == VALUE_TYPE_STRING_RANGE)
- {
+ if (value_type == VALUE_TYPE_STRING_RANGE) {
cond->string_value_to = (char *)MALLOC(strlen(key_to)+1);
rmemuse++;
UCPY(cond->string_value_to, key_to);
@@ -1336,8 +1227,7 @@ struct route_ruleset *ruleset_parse(void)
cond->integer_value = INFO_BC_DATAUNRESTRICTED;
else if (!strncasecmp("digital-unrestricted-tones", p, 26))
cond->integer_value = INFO_BC_DATAUNRESTRICTED_TONES;
- else
- {
+ else {
SPRINT(failure, "Given service type is invalid or misspelled.");
goto parse_error;
}
@@ -1350,8 +1240,7 @@ struct route_ruleset *ruleset_parse(void)
cond->integer_value = INFO_BMODE_CIRCUIT;
else if (!strncasecmp("hdlc", p, 4))
cond->integer_value = INFO_BMODE_PACKET;
- else
- {
+ else {
SPRINT(failure, "Given bchannel mode is invalid or misspelled.");
goto parse_error;
}
@@ -1361,29 +1250,24 @@ struct route_ruleset *ruleset_parse(void)
/* parse interface attribute <if>:<value> */
case COND_TYPE_IFATTR:
key[0] = key_to[0] = '\0';
- if (*p==':' || *p==',' || *p==' ' || *p=='\0')
- {
+ if (*p==':' || *p==',' || *p==' ' || *p=='\0') {
SPRINT(failure, "Missing interface name.");
goto parse_error;
}
p = read_string(p, key, sizeof(key), ":-, ");
- if (key[0] == 1) /* error */
- {
+ if (key[0] == 1) { /* error */
SPRINT(failure, "Parsing interface failed: %s", key+1);
goto parse_error;
}
- if (*p != ':')
- {
+ if (*p != ':') {
SPRINT(failure, "Expeciting kolon to seperate value behind interface name.");
goto parse_error;
}
SCCAT(key, *p++);
- while(*p>='0' && *p<='9')
- {
+ while(*p>='0' && *p<='9') {
SCCAT(key, *p++);
}
- if (*p!=',' && *p!=' ' && *p!='\0')
- {
+ if (*p!=',' && *p!=' ' && *p!='\0') {
SPRINT(failure, "Invalid characters behind value.");
goto parse_error;
}
@@ -1396,16 +1280,14 @@ struct route_ruleset *ruleset_parse(void)
goto parse_error;
}
/* if we have another value for that item, we attach it */
- if (*p == ',')
- {
+ if (*p == ',') {
p++;
/* next item */
cond->value_extension = 1;
goto nextcondvalue;
}
/* to seperate the items, a space is required */
- if (*p != ' ')
- {
+ if (*p != ' ') {
SPRINT(failure, "Character '%c' not expected here. Use ',' to seperate multiple possible values.", *p);
goto parse_error;
}
@@ -1419,8 +1301,7 @@ struct route_ruleset *ruleset_parse(void)
}
/* we are done with CONDITIONS, so we expect the ACTION */
- if (*p != ':')
- {
+ if (*p != ':') {
SPRINT(failure, "Expecting ':' after condition item(s).");
goto parse_error;
}
@@ -1437,8 +1318,7 @@ struct route_ruleset *ruleset_parse(void)
/* read action name */
i = 0;
- while((*p>='a' && *p<='z') || (*p>='A' && *p<='Z') || (*p>='0' && *p<='9') || *p == '-')
- {
+ while((*p>='a' && *p<='z') || (*p>='A' && *p<='Z') || (*p>='0' && *p<='9') || *p == '-') {
if (*p>='A' && *p<='Z') *p = *p-'A'+'a'; /* lower case */
key[i++] = *p++;
if (i == sizeof(key)) i--; /* limit */
@@ -1451,10 +1331,8 @@ struct route_ruleset *ruleset_parse(void)
/* check if item exists */
index = 0;
- while(action_defs[index].name)
- {
- if (!action_defs[index].help) /* not internal actions */
- {
+ while(action_defs[index].name) {
+ if (!action_defs[index].help) { /* not internal actions */
index++;
continue;
}
@@ -1462,8 +1340,7 @@ struct route_ruleset *ruleset_parse(void)
break;
index++;
}
- if (action_defs[index].name == NULL)
- {
+ if (action_defs[index].name == NULL) {
SPRINT(failure, "Unknown action name '%s'.", key);
goto parse_error;
}
@@ -1487,12 +1364,10 @@ struct route_ruleset *ruleset_parse(void)
}
/* loop PARAMS */
- while(*p != 0)
- {
+ while(*p != 0) {
/* read param text */
i = 0;
- while((*p>='a' && *p<='z') || (*p>='A' && *p<='Z') || (*p>='0' && *p<='9'))
- {
+ while((*p>='a' && *p<='z') || (*p>='A' && *p<='Z') || (*p>='0' && *p<='9')) {
if (*p>='A' && *p<='Z') *p = *p-'A'+'a'; /* lower case */
key[i++] = *p++;
if (i == sizeof(key)) i--; /* limit */
@@ -1505,42 +1380,34 @@ struct route_ruleset *ruleset_parse(void)
/* check if item exists */
index = 0;
- while(param_defs[index].name)
- {
+ while(param_defs[index].name) {
if (!strcmp(param_defs[index].name, key))
break;
index++;
}
- if (param_defs[index].name == NULL)
- {
+ if (param_defs[index].name == NULL) {
SPRINT(failure, "Unknown param name '%s'.", key);
goto parse_error;
}
/* check if item is allowed for the action */
- if (!(param_defs[index].id & allowed_params))
- {
+ if (!(param_defs[index].id & allowed_params)) {
SPRINT(failure, "Param name '%s' exists, but not for this action.", key);
goto parse_error;
}
/* params without values must not have any parameter */
- if (param_defs[index].type == PARAM_TYPE_NULL)
- {
- if (*p!=' ' && *p!='\0')
- {
+ if (param_defs[index].type == PARAM_TYPE_NULL) {
+ if (*p!=' ' && *p!='\0') {
SPRINT(failure, "Parameter '%s' must not have any value.", key);
goto parse_error;
}
- } else
- {
- if (*p == ' ')
- {
+ } else {
+ if (*p == ' ') {
SPRINT(failure, "Parameter '%s' must have at least one value, '=' expected and not a space.", key);
goto parse_error;
}
- if (*p != '=')
- {
+ if (*p != '=') {
SPRINT(failure, "Parameter '%s' must have at least one value, '=' expected.", key);
goto parse_error;
}
@@ -1548,45 +1415,37 @@ struct route_ruleset *ruleset_parse(void)
}
/* special timeout value */
- if (!strcmp("timeout", key))
- {
- if (action->timeout)
- {
+ if (!strcmp("timeout", key)) {
+ if (action->timeout) {
SPRINT(failure, "Duplicate timeout value.");
goto parse_error;
}
- if (*p==',' || *p==' ' || *p=='\0')
- {
+ if (*p==',' || *p==' ' || *p=='\0') {
SPRINT(failure, "Missing integer value.");
goto parse_error;
}
integer = 0;
- while(*p>='0' && *p<='9')
- {
+ while(*p>='0' && *p<='9') {
integer = integer*10 + *p-'0';
p++;
}
- if (integer < 1)
- {
+ if (integer < 1) {
SPRINT(failure, "Expecting timeout value greater 0.");
goto parse_error;
}
- if (*p!=' ' && *p!='\0')
- {
+ if (*p!=' ' && *p!='\0') {
SPRINT(failure, "Character '%c' not expected here. Use ' ' to seperate parameters.", *p);
goto parse_error;
}
/* skip spaces */
- while(*p == 32)
- {
+ while(*p == 32) {
if (*p == 0)
break;
p++;
}
action->timeout = integer;
/* check for next ACTION */
- if (*p == ':')
- {
+ if (*p == ':') {
p++;
goto nextaction;
}
@@ -1595,10 +1454,8 @@ struct route_ruleset *ruleset_parse(void)
/* check for duplicate parameters */
param = action->param_first;
- while(param)
- {
- if (param->index == index)
- {
+ while(param) {
+ if (param->index == index) {
SPRINT(failure, "Duplicate parameter '%s', use ',' to give multiple values.", key);
goto parse_error;
}
@@ -1614,8 +1471,7 @@ struct route_ruleset *ruleset_parse(void)
param->index = index;
param->id = param_defs[index].id;
- switch(param_defs[index].type)
- {
+ switch(param_defs[index].type) {
/* parse null value */
case PARAM_TYPE_NULL:
param->value_type = VALUE_TYPE_NULL;
@@ -1624,13 +1480,11 @@ struct route_ruleset *ruleset_parse(void)
/* parse integer value */
case PARAM_TYPE_INTEGER:
integer = 0;
- if (*p==',' || *p==' ' || *p=='\0')
- {
+ if (*p==',' || *p==' ' || *p=='\0') {
SPRINT(failure, "Missing integer value.");
goto parse_error;
}
- while(*p>='0' && *p<='9')
- {
+ while(*p>='0' && *p<='9') {
integer = integer*10 + *p-'0';
p++;
}
@@ -1642,33 +1496,27 @@ struct route_ruleset *ruleset_parse(void)
/* parse ports value */
case PARAM_TYPE_PORTS:
key[0] = '\0';
- if (*p==',' || *p==' ' || *p=='\0')
- {
+ if (*p==',' || *p==' ' || *p=='\0') {
SPRINT(failure, "Missing port number, omit parameter or give port number.");
goto parse_error;
}
i = 0;
nextport:
integer = 0;
- while(*p>='0' && *p<='9')
- {
- if (i < (int)sizeof(key)-1)
- {
+ while(*p>='0' && *p<='9') {
+ if (i < (int)sizeof(key)-1) {
key[i] = *p;
key[i++] = '\0';
}
integer = integer*10 + *p-'0';
p++;
}
- if (integer > 255)
- {
+ if (integer > 255) {
SPRINT(failure, "Port number too high.");
goto parse_error;
}
- if (*p==',')
- {
- if (i < (int)sizeof(key)-1)
- {
+ if (*p==',') {
+ if (i < (int)sizeof(key)-1) {
key[i] = *p;
key[i++] = '\0';
}
@@ -1689,173 +1537,140 @@ struct route_ruleset *ruleset_parse(void)
case PARAM_TYPE_YESNO:
case PARAM_TYPE_ON:
key[0] = '\0';
- if (*p==',' || *p==' ' || *p=='\0')
- {
+ if (*p==',' || *p==' ' || *p=='\0') {
SPRINT(failure, "Missing string value, use \"\" for empty string.");
goto parse_error;
}
p = read_string(p, key, sizeof(key), " ");
- if (key[0] == 1) /* error */
- {
+ if (key[0] == 1) { /* error */
SPRINT(failure, "Parsing string failed: %s", key+1);
goto parse_error;
}
- if (param_defs[index].type == PARAM_TYPE_CALLERIDTYPE)
- {
+ if (param_defs[index].type == PARAM_TYPE_CALLERIDTYPE) {
param->value_type = VALUE_TYPE_INTEGER;
- if (!strcasecmp(key, "unknown"))
- {
+ if (!strcasecmp(key, "unknown")) {
param->integer_value = INFO_NTYPE_UNKNOWN;
break;
}
- if (!strcasecmp(key, "subscriber"))
- {
+ if (!strcasecmp(key, "subscriber")) {
param->integer_value = INFO_NTYPE_SUBSCRIBER;
break;
}
- if (!strcasecmp(key, "national"))
- {
+ if (!strcasecmp(key, "national")) {
param->integer_value = INFO_NTYPE_NATIONAL;
break;
}
- if (!strcasecmp(key, "international"))
- {
+ if (!strcasecmp(key, "international")) {
param->integer_value = INFO_NTYPE_INTERNATIONAL;
break;
}
SPRINT(failure, "Caller ID type '%s' unknown.", key);
goto parse_error;
}
- if (param_defs[index].type == PARAM_TYPE_ON)
- {
+ if (param_defs[index].type == PARAM_TYPE_ON) {
param->value_type = VALUE_TYPE_INTEGER;
- if (!strcasecmp(key, "init"))
- {
+ if (!strcasecmp(key, "init")) {
param->integer_value = INFO_ON_INIT;
break;
}
- if (!strcasecmp(key, "hangup"))
- {
+ if (!strcasecmp(key, "hangup")) {
param->integer_value = INFO_ON_HANGUP;
break;
}
SPRINT(failure, "Execute on '%s' unknown.", key);
goto parse_error;
}
- if (param_defs[index].type == PARAM_TYPE_CAPABILITY)
- {
+ if (param_defs[index].type == PARAM_TYPE_CAPABILITY) {
param->value_type = VALUE_TYPE_INTEGER;
- if (!strcasecmp(key, "speech"))
- {
+ if (!strcasecmp(key, "speech")) {
param->integer_value = INFO_BC_SPEECH;
break;
}
- if (!strcasecmp(key, "audio"))
- {
+ if (!strcasecmp(key, "audio")) {
param->integer_value = INFO_BC_AUDIO;
break;
}
- if (!strcasecmp(key, "video"))
- {
+ if (!strcasecmp(key, "video")) {
param->integer_value = INFO_BC_VIDEO;
break;
}
- if (!strcasecmp(key, "digital-restricted"))
- {
+ if (!strcasecmp(key, "digital-restricted")) {
param->integer_value = INFO_BC_DATARESTRICTED;
break;
}
- if (!strcasecmp(key, "digital-unrestricted"))
- {
+ if (!strcasecmp(key, "digital-unrestricted")) {
param->integer_value = INFO_BC_DATAUNRESTRICTED;
break;
}
- if (!strcasecmp(key, "digital-unrestricted-tones"))
- {
+ if (!strcasecmp(key, "digital-unrestricted-tones")) {
param->integer_value = INFO_BC_DATAUNRESTRICTED_TONES;
break;
}
SPRINT(failure, "Service type '%s' unknown.", key);
goto parse_error;
}
- if (param_defs[index].type == PARAM_TYPE_BMODE)
- {
+ if (param_defs[index].type == PARAM_TYPE_BMODE) {
param->value_type = VALUE_TYPE_INTEGER;
- if (!strcasecmp(key, "transparent"))
- {
+ if (!strcasecmp(key, "transparent")) {
param->integer_value = INFO_BMODE_CIRCUIT;
break;
}
- if (!strcasecmp(key, "hdlc"))
- {
+ if (!strcasecmp(key, "hdlc")) {
param->integer_value = INFO_BMODE_PACKET;
break;
}
SPRINT(failure, "Bchannel mode '%s' unknown.", key);
goto parse_error;
}
- if (param_defs[index].type == PARAM_TYPE_DIVERSION)
- {
+ if (param_defs[index].type == PARAM_TYPE_DIVERSION) {
param->value_type = VALUE_TYPE_INTEGER;
- if (!strcasecmp(key, "cfu"))
- {
+ if (!strcasecmp(key, "cfu")) {
param->integer_value = INFO_DIVERSION_CFU;
break;
}
- if (!strcasecmp(key, "cfb"))
- {
+ if (!strcasecmp(key, "cfb")) {
param->integer_value = INFO_DIVERSION_CFB;
break;
}
- if (!strcasecmp(key, "cfnr"))
- {
+ if (!strcasecmp(key, "cfnr")) {
param->integer_value = INFO_DIVERSION_CFNR;
break;
}
- if (!strcasecmp(key, "cfp"))
- {
+ if (!strcasecmp(key, "cfp")) {
param->integer_value = INFO_DIVERSION_CFP;
break;
}
SPRINT(failure, "Diversion type '%s' unknown.", key);
goto parse_error;
}
- if (param_defs[index].type == PARAM_TYPE_TYPE)
- {
+ if (param_defs[index].type == PARAM_TYPE_TYPE) {
param->value_type = VALUE_TYPE_INTEGER;
- if (!strcasecmp(key, "unknown"))
- {
+ if (!strcasecmp(key, "unknown")) {
param->integer_value = INFO_NTYPE_UNKNOWN;
break;
}
- if (!strcasecmp(key, "subscriber"))
- {
+ if (!strcasecmp(key, "subscriber")) {
param->integer_value = INFO_NTYPE_SUBSCRIBER;
break;
}
- if (!strcasecmp(key, "national"))
- {
+ if (!strcasecmp(key, "national")) {
param->integer_value = INFO_NTYPE_NATIONAL;
break;
}
- if (!strcasecmp(key, "international"))
- {
+ if (!strcasecmp(key, "international")) {
param->integer_value = INFO_NTYPE_INTERNATIONAL;
break;
}
SPRINT(failure, "Number type '%s' unknown.", key);
goto parse_error;
}
- if (param_defs[index].type == PARAM_TYPE_YESNO)
- {
+ if (param_defs[index].type == PARAM_TYPE_YESNO) {
param->value_type = VALUE_TYPE_INTEGER;
- if (!strcasecmp(key, "yes"))
- {
+ if (!strcasecmp(key, "yes")) {
param->integer_value = 1;
break;
}
- if (!strcasecmp(key, "no"))
- {
+ if (!strcasecmp(key, "no")) {
param->integer_value = 0;
break;
}
@@ -1873,8 +1688,7 @@ struct route_ruleset *ruleset_parse(void)
goto parse_error;
}
- if (*p == ',')
- {
+ if (*p == ',') {
p++;
/* next item */
param->value_extension = 1;
@@ -1886,8 +1700,7 @@ struct route_ruleset *ruleset_parse(void)
break;
/* to seperate the items, a space is required */
- if (*p != ' ')
- {
+ if (*p != ' ') {
SPRINT(failure, "Character '%c' not expected here. Use ' ' to seperate parameters, or ',' for multiple values.", *p);
goto parse_error;
}
@@ -1900,8 +1713,7 @@ struct route_ruleset *ruleset_parse(void)
}
/* check for next ACTION */
- if (*p == ':')
- {
+ if (*p == ':') {
p++;
goto nextaction;
}
@@ -1914,8 +1726,7 @@ struct route_ruleset *ruleset_parse(void)
if (nesting >= 0)
goto go_root;
- if (!ruleset_start)
- {
+ if (!ruleset_start) {
SPRINT(failure, "No ruleset defined.");
}
return(ruleset_start);
@@ -1931,8 +1742,7 @@ struct route_ruleset *ruleset_parse(void)
SPRINT(ruleset_error, "Error in file %s, line %d: %s", filename[nesting], line[nesting], failure);
openerror:
- while(nesting >= 0)
- {
+ while(nesting >= 0) {
fclose(fp[nesting--]);
fduse--;
}
@@ -1948,10 +1758,8 @@ struct route_ruleset *getrulesetbyname(const char *name)
{
struct route_ruleset *ruleset = ruleset_first;
- while(ruleset)
- {
- if (!strcasecmp(name, ruleset->name))
- {
+ while(ruleset) {
+ if (!strcasecmp(name, ruleset->name)) {
break;
}
ruleset = ruleset->next;
@@ -1995,21 +1803,18 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
SCPY(redirid, numberrize_callerinfo(e_redirinfo.id, e_redirinfo.ntype, options.national, options.international));
PDEBUG(DEBUG_ROUTE, "parsing ruleset '%s'\n", ruleset->name);
- while(rule)
- {
+ while(rule) {
PDEBUG(DEBUG_ROUTE, "checking rule in line %d\n", rule->line);
match = 1; /* this rule matches */
dialing_required = 0;
timeout = 0; /* timeout time */
cond = rule->cond_first;
- while(cond)
- {
+ while(cond) {
condition = 0; /* any condition element is true (1) or could be true (2) */
checkextension:
istrue = 0; /* this condition-element is true */
couldbetrue = 0; /* this conditions-element could be true */
- switch(cond->match)
- {
+ switch(cond->match) {
case MATCH_EXTERN:
if (!e_ext.number[0])
istrue = 1;
@@ -2138,8 +1943,7 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
case MATCH_FILE:
tfp = fopen(cond->string_value, "r");
- if (!tfp)
- {
+ if (!tfp) {
break;
}
if (fgetc(tfp) == '1')
@@ -2169,18 +1973,15 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
comp_len = comp_len-(unsigned long)cond->string_value;
avail = 0;
mISDNport = mISDNport_first;
- while(mISDNport)
- {
+ while(mISDNport) {
if (mISDNport->ifport)
if (strlen(mISDNport->ifport->interface->name) == comp_len)
if (!strncasecmp(mISDNport->ifport->interface->name, cond->string_value, comp_len))
- if (!mISDNport->l2hold || mISDNport->l2link>0)
- {
+ if (!mISDNport->l2hold || mISDNport->l2link>0) {
j = 0;
jj = mISDNport->b_num;
avail += jj;
- while(j < jj)
- {
+ while(j < jj) {
if (mISDNport->b_state[j])
avail--;
j++;
@@ -2188,12 +1989,10 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
}
mISDNport = mISDNport->next;
}
- if (cond->match == MATCH_FREE)
- {
+ if (cond->match == MATCH_FREE) {
if (avail >= atoi(cond->string_value + comp_len + 1))
istrue = 1;
- } else
- {
+ } else {
if (avail < atoi(cond->string_value + comp_len + 1))
istrue = 1;
}
@@ -2202,8 +2001,7 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
case MATCH_DOWN:
mISDNport = mISDNport_first;
- while(mISDNport)
- {
+ while(mISDNport) {
if (mISDNport->ifport)
if (!strcasecmp(mISDNport->ifport->interface->name, cond->string_value))
if (!mISDNport->l2hold || mISDNport->l2link>0)
@@ -2216,8 +2014,7 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
case MATCH_UP:
mISDNport = mISDNport_first;
- while(mISDNport)
- {
+ while(mISDNport) {
if (mISDNport->ifport)
if (!strcasecmp(mISDNport->ifport->interface->name, cond->string_value))
if (!mISDNport->l2hold || mISDNport->l2link>0)
@@ -2233,8 +2030,7 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
case MATCH_IDLE:
any = 0;
mISDNport = mISDNport_first;
- while(mISDNport)
- {
+ while(mISDNport) {
if (mISDNport->ifport)
if (!strcasecmp(mISDNport->ifport->interface->name, cond->string_value))
if (mISDNport->use) /* break if in use */
@@ -2250,8 +2046,7 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
case MATCH_REMOTE:
case MATCH_NOTREMOTE:
admin = admin_first;
- while(admin)
- {
+ while(admin) {
if (admin->remote_name[0] && !strcmp(cond->string_value, admin->remote_name))
break;
admin = admin->next;
@@ -2267,18 +2062,15 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
break;
match_integer:
- if (cond->value_type == VALUE_TYPE_INTEGER)
- {
+ if (cond->value_type == VALUE_TYPE_INTEGER) {
if (integer != cond->integer_value)
break;
istrue = 1;
break;
}
- if (cond->value_type == VALUE_TYPE_INTEGER_RANGE)
- {
+ if (cond->value_type == VALUE_TYPE_INTEGER_RANGE) {
/* check if negative range (2100 - 700 o'clock) */
- if (cond->integer_value > cond->integer_value_to)
- {
+ if (cond->integer_value > cond->integer_value_to) {
if (integer>=cond->integer_value && integer<=cond->integer_value_to)
istrue = 1;
break;
@@ -2297,23 +2089,18 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
match_string_prefix:
comp_len = strlen(cond->string_value); /* because we must reach value's length */
/* we must have greater or equal length to values */
- if ((unsigned long)strlen(string) < comp_len)
- {
+ if ((unsigned long)strlen(string) < comp_len) {
/* special case for unfinished dialing */
- if (cond->match == MATCH_DIALING)
- {
+ if (cond->match == MATCH_DIALING) {
couldbetrue = 1; /* could match */
comp_len = strlen(string);
- } else
- {
+ } else {
break;
}
}
/* on single string match */
- if (cond->value_type == VALUE_TYPE_STRING)
- {
- if (!strncmp(string, cond->string_value, comp_len))
- {
+ if (cond->value_type == VALUE_TYPE_STRING) {
+ if (!strncmp(string, cond->string_value, comp_len)) {
istrue = 1;
/* must be set for changing 'e_extdialing' */
if (cond->match == MATCH_DIALING)
@@ -2323,21 +2110,17 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
break;
}
/* on range match */
- if (cond->value_type == VALUE_TYPE_STRING_RANGE)
- {
+ if (cond->value_type == VALUE_TYPE_STRING_RANGE) {
/* check if negative range ("55"-"22") */
- if (cond->comp_string > 0)
- {
- if (strncmp(string, cond->string_value, comp_len) >= 0)
- {
+ if (cond->comp_string > 0) {
+ if (strncmp(string, cond->string_value, comp_len) >= 0) {
istrue = 1;
/* must be set for changing 'e_extdialing' */
if (cond->match == MATCH_DIALING)
dialing_required = comp_len;
break;
}
- if (strncmp(string, cond->string_value_to, comp_len) <= 0)
- {
+ if (strncmp(string, cond->string_value_to, comp_len) <= 0) {
/* must be set for changing 'e_extdialing' */
istrue = 1;
if (cond->match == MATCH_DIALING)
@@ -2366,11 +2149,9 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
condition = 2; /* element could match and other elements don't match, so condition could match */
/* if not matching or could match */
- if (condition != 1)
- {
+ if (condition != 1) {
/* if we have more values to check */
- if (cond->value_extension && cond->next)
- {
+ if (cond->value_extension && cond->next) {
cond = cond->next;
goto checkextension;
}
@@ -2385,16 +2166,14 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
cond = cond->next;
}
if (timeout>now_d && match==1) /* the matching rule with timeout in the future */
- if (e_match_timeout<1 || timeout<e_match_timeout) /* first timeout or lower */
- {
+ if (e_match_timeout<1 || timeout<e_match_timeout) { /* first timeout or lower */
/* set timeout in the furture */
e_match_timeout = timeout;
e_match_to_action = rule->action_first;
e_match_to_extdialing = e_dialinginfo.id + dialing_required;
match = 0; /* matches in the future */
}
- if (match == 1)
- {
+ if (match == 1) {
/* matching, we return first action */
action = rule->action_first;
e_match_timeout = 0; /* no timeout */
@@ -2402,8 +2181,7 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
e_extdialing = e_dialinginfo.id + dialing_required;
break;
}
- if (match == 2)
- {
+ if (match == 2) {
/* rule could match if more is dialed */
couldmatch = 1;
}
@@ -2419,8 +2197,7 @@ struct route_param *EndpointAppPBX::routeparam(struct route_action *action, unsi
{
struct route_param *param = action->param_first;
- while(param)
- {
+ while(param) {
if (param->id == id)
break;
param = param->next;
diff --git a/socket_server.c b/socket_server.c
index 9abb5b2..cea929c 100644
--- a/socket_server.c
+++ b/socket_server.c
@@ -29,8 +29,7 @@ int admin_init(void)
unsigned int on = 1;
/* open and bind socket */
- if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0)
- {
+ if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
PERROR("Failed to create admin socket. (errno=%d)\n", errno);
return(-1);
}
@@ -40,8 +39,7 @@ int admin_init(void)
sock_address.sun_family = AF_UNIX;
UCPY(sock_address.sun_path, socket_name);
unlink(socket_name);
- if (bind(sock, (struct sockaddr *)(&sock_address), SUN_LEN(&sock_address)) < 0)
- {
+ if (bind(sock, (struct sockaddr *)(&sock_address), SUN_LEN(&sock_address)) < 0) {
close(sock);
unlink(socket_name);
fhuse--;
@@ -49,8 +47,7 @@ int admin_init(void)
PERROR("Failed to bind admin socket to \"%s\". (errno=%d)\n", sock_address.sun_path, errno);
return(-1);
}
- if (listen(sock, 5) < 0)
- {
+ if (listen(sock, 5) < 0) {
close(sock);
unlink(socket_name);
fhuse--;
@@ -58,8 +55,7 @@ int admin_init(void)
PERROR("Failed to listen to socket \"%s\". (errno=%d)\n", sock_address.sun_path, errno);
return(-1);
}
- if (ioctl(sock, FIONBIO, (unsigned char *)(&on)) < 0)
- {
+ if (ioctl(sock, FIONBIO, (unsigned char *)(&on)) < 0) {
close(sock);
unlink(socket_name);
fhuse--;
@@ -67,8 +63,7 @@ int admin_init(void)
PERROR("Failed to set socket \"%s\" into non-blocking mode. (errno=%d)\n", sock_address.sun_path, errno);
return(-1);
}
- if (chmod(socket_name, options.socketrights) < 0)
- {
+ if (chmod(socket_name, options.socketrights) < 0) {
PERROR("Failed to change socket rigts to %d. (errno=%d)\n", options.socketrights, errno);
}
return(0);
@@ -89,8 +84,7 @@ void free_connection(struct admin_list *admin)
int i, ii;
/* free remote joins */
- if (admin->remote_name[0])
- {
+ if (admin->remote_name[0]) {
start_trace(-1,
NULL,
NULL,
@@ -103,14 +97,11 @@ void free_connection(struct admin_list *admin)
end_trace();
/* release all exported channels */
mISDNport = mISDNport_first;
- while(mISDNport)
- {
+ while(mISDNport) {
i = 0;
ii = mISDNport->b_num;
- while(i < ii)
- {
- if (mISDNport->b_remote_id[i] == admin->sock)
- {
+ while(i < ii) {
+ if (mISDNport->b_remote_id[i] == admin->sock) {
mISDNport->b_state[i] = B_STATE_IDLE;
mISDNport->b_timer[i] = 0;
mISDNport->b_remote_id[i] = 0;
@@ -122,11 +113,9 @@ void free_connection(struct admin_list *admin)
}
/* release join */
join = join_first;
- while(join)
- {
+ while(join) {
joinnext = join->next;
- if (join->j_type==JOIN_TYPE_REMOTE) if (((class JoinRemote *)join)->j_remote_id == admin->sock)
- {
+ if (join->j_type==JOIN_TYPE_REMOTE) if (((class JoinRemote *)join)->j_remote_id == admin->sock) {
memset(&param, 0, sizeof(param));
param.disconnectinfo.cause = CAUSE_OUTOFORDER;
param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
@@ -137,15 +126,13 @@ void free_connection(struct admin_list *admin)
}
}
- if (admin->sock >= 0)
- {
+ if (admin->sock >= 0) {
close(admin->sock);
fhuse--;
}
// printf("new\n", response);
response = admin->response;
- while (response)
- {
+ while (response) {
//#warning
// printf("%x\n", response);
temp = response->next;
@@ -168,16 +155,14 @@ void admin_cleanup(void)
struct admin_list *admin, *next;;
admin = admin_first;
- while(admin)
- {
+ while(admin) {
//printf("clean\n");
next = admin->next;
free_connection(admin);
admin = next;
}
- if (sock >= 0)
- {
+ if (sock >= 0) {
close(sock);
fhuse--;
}
@@ -195,14 +180,12 @@ int admin_interface(struct admin_queue **responsep)
const char *err_txt = "";
int err = 0;
- if (read_interfaces())
- {
+ if (read_interfaces()) {
relink_interfaces();
free_interfaces(interface_first);
interface_first = interface_newlist;
interface_newlist = NULL;
- } else
- {
+ } else {
err_txt = interface_error;
err = -1;
}
@@ -241,20 +224,17 @@ int admin_route(struct admin_queue **responsep)
#if 0
n = 0;
apppbx = apppbx_first;
- while(apppbx)
- {
+ while(apppbx) {
n++;
apppbx = apppbx->next;
}
- if (apppbx_first)
- {
+ if (apppbx_first) {
SPRINT(err_txt, "Cannot reload routing, because %d endpoints active\n", n);
err = -1;
goto response;
}
#endif
- if (!(ruleset_new = ruleset_parse()))
- {
+ if (!(ruleset_new = ruleset_parse())) {
SPRINT(err_txt, ruleset_error);
err = -1;
goto response;
@@ -262,18 +242,14 @@ int admin_route(struct admin_queue **responsep)
ruleset_free(ruleset_first);
ruleset_first = ruleset_new;
ruleset_main = getrulesetbyname("main");
- if (!ruleset_main)
- {
+ if (!ruleset_main) {
SPRINT(err_txt, "Ruleset reloaded, but rule 'main' not found.\n");
err = -1;
}
apppbx = apppbx_first;
- while(apppbx)
- {
- if (apppbx->e_action)
- {
- switch(apppbx->e_action->index)
- {
+ while(apppbx) {
+ if (apppbx->e_action) {
+ switch(apppbx->e_action->index) {
case ACTION_INTERNAL:
apppbx->e_action = &action_internal;
break;
@@ -292,8 +268,7 @@ int admin_route(struct admin_queue **responsep)
default:
goto release;
}
- } else if (apppbx->e_state != EPOINT_STATE_CONNECT)
- {
+ } else if (apppbx->e_state != EPOINT_STATE_CONNECT) {
release:
apppbx->e_callback = 0;
apppbx->e_action = NULL;
@@ -352,8 +327,7 @@ int admin_dial(struct admin_queue **responsep, char *message)
response->am[0].message = ADMIN_RESPONSE_CMD_DIAL;
/* process request */
- if (!(p = strchr(message,':')))
- {
+ if (!(p = strchr(message,':'))) {
response->am[0].u.x.error = -EINVAL;
SPRINT(response->am[0].u.x.message, "no seperator ':' in message to seperate number from extension");
goto out;
@@ -361,8 +335,7 @@ int admin_dial(struct admin_queue **responsep, char *message)
*p++ = 0;
/* modify extension */
- if (!read_extension(&ext, message))
- {
+ if (!read_extension(&ext, message)) {
response->am[0].u.x.error = -EINVAL;
SPRINT(response->am[0].u.x.message, "extension doesn't exist");
goto out;
@@ -417,11 +390,9 @@ int admin_block(struct admin_queue **responsep, int portnum, int block)
/* search for port */
ifport = NULL;
interface = interface_first;
- while(interface)
- {
+ while(interface) {
ifport = interface->ifport;
- while(ifport)
- {
+ while(ifport) {
if (ifport->portnum == portnum)
break;
ifport = ifport->next;
@@ -431,8 +402,7 @@ int admin_block(struct admin_queue **responsep, int portnum, int block)
interface = interface->next;
}
/* not found, we return -1 */
- if (!ifport)
- {
+ if (!ifport) {
response->am[0].u.x.block = -1;
response->am[0].u.x.error = 1;
SPRINT(response->am[0].u.x.message, "Port %d does not exist.", portnum);
@@ -440,11 +410,9 @@ int admin_block(struct admin_queue **responsep, int portnum, int block)
}
/* no interface */
- if (!ifport->mISDNport)
- {
+ if (!ifport->mISDNport) {
/* not loaded anyway */
- if (block >= 2)
- {
+ if (block >= 2) {
response->am[0].u.x.block = 2;
goto out;
}
@@ -454,8 +422,7 @@ int admin_block(struct admin_queue **responsep, int portnum, int block)
load_port(ifport);
/* port cannot load */
- if (ifport->block >= 2)
- {
+ if (ifport->block >= 2) {
response->am[0].u.x.block = 2;
response->am[0].u.x.error = 1;
SPRINT(response->am[0].u.x.message, "Port %d will not load.", portnum);
@@ -468,8 +435,7 @@ int admin_block(struct admin_queue **responsep, int portnum, int block)
}
/* if we shall unload interface */
- if (block >= 2)
- {
+ if (block >= 2) {
mISDNport_close(ifport->mISDNport);
ifport->mISDNport = 0;
ifport->block = 2;
@@ -505,14 +471,12 @@ int admin_release(struct admin_queue **responsep, char *message)
id = atoi(message);
apppbx = apppbx_first;
- while(apppbx)
- {
+ while(apppbx) {
if (apppbx->ea_endpoint->ep_serial == id)
break;
apppbx = apppbx->next;
}
- if (!apppbx)
- {
+ if (!apppbx) {
response->am[0].u.x.error = -EINVAL;
SPRINT(response->am[0].u.x.message, "Given endpoint %d doesn't exist.", id);
goto out;
@@ -579,8 +543,7 @@ void admin_call_response(int adminid, int message, const char *connected, int ca
* maybe there is no admin instance, because the calling port was not
* initiated by admin_call */
admin = admin_first;
- while(admin)
- {
+ while(admin) {
if (adminid == admin->sockserial)
break;
admin = admin->next;
@@ -591,8 +554,7 @@ void admin_call_response(int adminid, int message, const char *connected, int ca
/* seek to end of response list */
response = admin->response;
responsep = &admin->response;
- while(response)
- {
+ while(response) {
responsep = &response->next;
response = response->next;
}
@@ -625,23 +587,19 @@ int admin_message_to_join(struct admin_msg *msg, struct admin_list *admin)
struct admin_list *temp;
/* hello message */
- if (msg->type == MESSAGE_HELLO)
- {
- if (admin->remote_name[0])
- {
+ if (msg->type == MESSAGE_HELLO) {
+ if (admin->remote_name[0]) {
PERROR("Remote application repeats hello message.\n");
return(-1);
}
/* look for second application */
temp = admin_first;
- while(temp)
- {
+ while(temp) {
if (!strcmp(temp->remote_name, msg->param.hello.application))
break;
temp = temp->next;
}
- if (temp)
- {
+ if (temp) {
PERROR("Remote application connects twice??? (ignoring)\n");
return(-1);
}
@@ -661,19 +619,16 @@ int admin_message_to_join(struct admin_msg *msg, struct admin_list *admin)
}
/* check we have no application name */
- if (!admin->remote_name[0])
- {
+ if (!admin->remote_name[0]) {
PERROR("Remote application did not send us a hello message.\n");
return(-1);
}
/* new join */
- if (msg->type == MESSAGE_NEWREF)
- {
+ if (msg->type == MESSAGE_NEWREF) {
/* create new join instance */
join = new JoinRemote(0, admin->remote_name, admin->sock); // must have no serial, because no endpoint is connected
- if (!join)
- {
+ if (!join) {
FATAL("No memory for remote join instance\n");
return(-1);
}
@@ -685,42 +640,36 @@ int admin_message_to_join(struct admin_msg *msg, struct admin_list *admin)
if (msg->type == MESSAGE_BCHANNEL)
if (msg->param.bchannel.type == BCHANNEL_ASSIGN_ACK
|| msg->param.bchannel.type == BCHANNEL_REMOVE_ACK
- || msg->param.bchannel.type == BCHANNEL_RELEASE)
- {
+ || msg->param.bchannel.type == BCHANNEL_RELEASE) {
/* no ref, but address */
message_bchannel_from_remote(NULL, msg->param.bchannel.type, msg->param.bchannel.handle);
return(0);
}
/* check for ref */
- if (!msg->ref)
- {
+ if (!msg->ref) {
PERROR("Remote application did not send us a valid ref with a message.\n");
return(-1);
}
/* find join instance */
join = join_first;
- while(join)
- {
+ while(join) {
if (join->j_serial == msg->ref)
break;
join = join->next;
}
- if (!join)
- {
+ if (!join) {
PDEBUG(DEBUG_LOG, "No join found with serial %d. (May have been already released.)\n", msg->ref);
return(0);
}
/* check application */
- if (join->j_type != JOIN_TYPE_REMOTE)
- {
+ if (join->j_type != JOIN_TYPE_REMOTE) {
PERROR("Ref %d does not belong to a remote join instance.\n", msg->ref);
return(-1);
}
- if (admin->sock != ((class JoinRemote *)join)->j_remote_id)
- {
+ if (admin->sock != ((class JoinRemote *)join)->j_remote_id) {
PERROR("Ref %d belongs to remote application %s, but not to sending application %s.\n", msg->ref, ((class JoinRemote *)join)->j_remote_name, admin->remote_name);
return(-1);
}
@@ -744,8 +693,7 @@ int admin_message_from_join(int remote_id, unsigned int ref, int message_type, u
* maybe there is no given remote application
*/
admin = admin_first;
- while(admin)
- {
+ while(admin) {
if (admin->remote_name[0] && admin->sock==remote_id)
break;
admin = admin->next;
@@ -756,8 +704,7 @@ int admin_message_from_join(int remote_id, unsigned int ref, int message_type, u
/* seek to end of response list */
responsep = &admin->response;
- while(*responsep)
- {
+ while(*responsep) {
responsep = &(*responsep)->next;
}
@@ -810,11 +757,9 @@ int admin_state(struct admin_queue **responsep)
/* interface count */
i = 0;
interface = interface_first;
- while(interface)
- {
+ while(interface) {
ifport = interface->ifport;
- while(ifport)
- {
+ while(ifport) {
i++;
ifport = ifport->next;
}
@@ -824,8 +769,7 @@ int admin_state(struct admin_queue **responsep)
/* remote connection count */
i = 0;
admin = admin_first;
- while(admin)
- {
+ while(admin) {
if (admin->remote_name[0])
i++;
admin = admin->next;
@@ -834,8 +778,7 @@ int admin_state(struct admin_queue **responsep)
/* join count */
join = join_first;
i = 0;
- while(join)
- {
+ while(join) {
i++;
join = join->next;
}
@@ -843,8 +786,7 @@ int admin_state(struct admin_queue **responsep)
/* apppbx count */
apppbx = apppbx_first;
i = 0;
- while(apppbx)
- {
+ while(apppbx) {
i++;
apppbx = apppbx->next;
}
@@ -852,8 +794,7 @@ int admin_state(struct admin_queue **responsep)
/* port count */
i = 0;
port = port_first;
- while(port)
- {
+ while(port) {
i++;
port = port->next;
}
@@ -877,11 +818,9 @@ int admin_state(struct admin_queue **responsep)
responsep = &response->next;
interface = interface_first;
num = 0;
- while(interface)
- {
+ while(interface) {
ifport = interface->ifport;
- while(ifport)
- {
+ while(ifport) {
/* message */
response->am[num].message = ADMIN_RESPONSE_S_INTERFACE;
/* interface */
@@ -894,8 +833,7 @@ int admin_state(struct admin_queue **responsep)
response->am[num].u.i.extension = interface->extension;
/* block */
response->am[num].u.i.block = ifport->block;
- if (ifport->mISDNport)
- {
+ if (ifport->mISDNport) {
mISDNport = ifport->mISDNport;
/* ptp */
@@ -929,8 +867,7 @@ int admin_state(struct admin_queue **responsep)
/* channel info */
i = 0;
anybusy = 0;
- while(i < mISDNport->b_num)
- {
+ while(i < mISDNport->b_num) {
response->am[num].u.i.busy[i] = mISDNport->b_state[i];
if (mISDNport->b_port[i])
response->am[num].u.i.port[i] = mISDNport->b_port[i]->p_serial;
@@ -947,10 +884,8 @@ int admin_state(struct admin_queue **responsep)
/* create response for all remotes */
admin = admin_first;
- while(admin)
- {
- if (admin->remote_name[0])
- {
+ while(admin) {
+ if (admin->remote_name[0]) {
/* message */
response->am[num].message = ADMIN_RESPONSE_S_REMOTE;
/* name */
@@ -963,8 +898,7 @@ int admin_state(struct admin_queue **responsep)
/* create response for all joins */
join = join_first;
- while(join)
- {
+ while(join) {
/* message */
response->am[num].message = ADMIN_RESPONSE_S_JOIN;
/* serial */
@@ -982,8 +916,7 @@ int admin_state(struct admin_queue **responsep)
/* create response for all endpoint */
apppbx = apppbx_first;
- while(apppbx)
- {
+ while(apppbx) {
/* message */
response->am[num].message = ADMIN_RESPONSE_S_EPOINT;
/* serial */
@@ -995,8 +928,7 @@ int admin_state(struct admin_queue **responsep)
/* tx notification */
response->am[num].u.e.tx_state = apppbx->e_tx_state;
/* state */
- switch(apppbx->e_state)
- {
+ switch(apppbx->e_state) {
case EPOINT_STATE_IN_SETUP:
response->am[num].u.e.state = ADMIN_STATE_IN_SETUP;
break;
@@ -1059,8 +991,7 @@ int admin_state(struct admin_queue **responsep)
/* create response for all ports */
port = port_first;
- while(port)
- {
+ while(port) {
/* message */
response->am[num].message = ADMIN_RESPONSE_S_PORT;
/* serial */
@@ -1070,8 +1001,7 @@ int admin_state(struct admin_queue **responsep)
/* epoint */
response->am[num].u.p.epoint = ACTIVE_EPOINT(port->p_epointlist);
/* state */
- switch(port->p_state)
- {
+ switch(port->p_state) {
case PORT_STATE_IN_SETUP:
response->am[num].u.p.state = ADMIN_STATE_IN_SETUP;
break;
@@ -1109,8 +1039,7 @@ int admin_state(struct admin_queue **responsep)
response->am[num].u.p.state = ADMIN_STATE_IDLE;
}
/* isdn */
- if ((port->p_type&PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1)
- {
+ if ((port->p_type&PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1) {
response->am[num].u.p.isdn = 1;
pdss1 = (class Pdss1 *)port;
response->am[num].u.p.isdn_chan = pdss1->p_m_b_channel;
@@ -1144,13 +1073,11 @@ int admin_handle(void)
return(0);
/* check for new incoming connections */
- if ((new_sock = accept(sock, (struct sockaddr *)&sock_address, &sock_len)) >= 0)
- {
+ if ((new_sock = accept(sock, (struct sockaddr *)&sock_address, &sock_len)) >= 0) {
work = 1;
/* insert new socket */
admin = (struct admin_list *)MALLOC(sizeof(struct admin_list));
- if (ioctl(new_sock, FIONBIO, (unsigned char *)(&on)) >= 0)
- {
+ if (ioctl(new_sock, FIONBIO, (unsigned char *)(&on)) >= 0) {
//#warning
// PERROR("DEBUG incoming socket %d, serial=%d\n", new_sock, sockserial);
memuse++;
@@ -1163,10 +1090,8 @@ int admin_handle(void)
close(new_sock);
FREE(admin, sizeof(struct admin_list));
}
- } else
- {
- if (errno != EWOULDBLOCK)
- {
+ } else {
+ if (errno != EWOULDBLOCK) {
PERROR("Failed to accept connection from socket \"%s\". (errno=%d) Closing socket.\n", sock_address.sun_path, errno);
admin_cleanup();
return(1);
@@ -1176,14 +1101,11 @@ int admin_handle(void)
/* loop all current socket connections */
admin = admin_first;
adminp = &admin_first;
- while(admin)
- {
+ while(admin) {
/* read command */
len = read(admin->sock, &msg, sizeof(msg));
- if (len < 0)
- {
- if (errno != EWOULDBLOCK)
- {
+ if (len < 0) {
+ if (errno != EWOULDBLOCK) {
work = 1;
brokenpipe:
PDEBUG(DEBUG_LOG, "Broken pipe on socket %d. (errno=%d).\n", admin->sock, errno);
@@ -1197,16 +1119,13 @@ int admin_handle(void)
work = 1;
//#warning
//PERROR("DEBUG socket %d got data. serial=%d\n", admin->sock, admin->sockserial);
- if (len == 0)
- {
+ if (len == 0) {
end:
/*release endpoint if exists */
- if (admin->epointid)
- {
+ if (admin->epointid) {
epoint = find_epoint_id(admin->epointid);
- if (epoint)
- {
+ if (epoint) {
((class DEFAULT_ENDPOINT_APP *)epoint->ep_app)->
release(RELEASE_ALL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL, CAUSE_NORMAL);
}
@@ -1220,8 +1139,7 @@ int admin_handle(void)
//PERROR("DEBUG (admin_first=%x)\n", admin_first);
continue;
}
- if (len != sizeof(msg))
- {
+ if (len != sizeof(msg)) {
PERROR("Short/long read on socket %d. (len=%d != size=%d).\n", admin->sock, len, sizeof(msg));
*adminp = admin->next;
free_connection(admin);
@@ -1229,75 +1147,65 @@ int admin_handle(void)
continue;
}
/* process socket command */
- if (admin->response && msg.message != ADMIN_MESSAGE)
- {
+ if (admin->response && msg.message != ADMIN_MESSAGE) {
PERROR("Data from socket %d while sending response.\n", admin->sock);
*adminp = admin->next;
free_connection(admin);
admin = *adminp;
continue;
}
- switch (msg.message)
- {
+ switch (msg.message) {
case ADMIN_REQUEST_CMD_INTERFACE:
- if (admin_interface(&admin->response) < 0)
- {
+ if (admin_interface(&admin->response) < 0) {
PERROR("Failed to create dial response for socket %d.\n", admin->sock);
goto response_error;
}
break;
case ADMIN_REQUEST_CMD_ROUTE:
- if (admin_route(&admin->response) < 0)
- {
+ if (admin_route(&admin->response) < 0) {
PERROR("Failed to create dial response for socket %d.\n", admin->sock);
goto response_error;
}
break;
case ADMIN_REQUEST_CMD_DIAL:
- if (admin_dial(&admin->response, msg.u.x.message) < 0)
- {
+ if (admin_dial(&admin->response, msg.u.x.message) < 0) {
PERROR("Failed to create dial response for socket %d.\n", admin->sock);
goto response_error;
}
break;
case ADMIN_REQUEST_CMD_RELEASE:
- if (admin_release(&admin->response, msg.u.x.message) < 0)
- {
+ if (admin_release(&admin->response, msg.u.x.message) < 0) {
PERROR("Failed to create release response for socket %d.\n", admin->sock);
goto response_error;
}
break;
case ADMIN_REQUEST_STATE:
- if (admin_state(&admin->response) < 0)
- {
+ if (admin_state(&admin->response) < 0) {
PERROR("Failed to create state response for socket %d.\n", admin->sock);
goto response_error;
}
break;
case ADMIN_TRACE_REQUEST:
- if (admin_trace(admin, &msg.u.trace_req) < 0)
- {
+ if (admin_trace(admin, &msg.u.trace_req) < 0) {
PERROR("Failed to create trace response for socket %d.\n", admin->sock);
goto response_error;
}
break;
case ADMIN_REQUEST_CMD_BLOCK:
- if (admin_block(&admin->response, msg.u.x.portnum, msg.u.x.block) < 0)
- {
+ if (admin_block(&admin->response, msg.u.x.portnum, msg.u.x.block) < 0) {
PERROR("Failed to create block response for socket %d.\n", admin->sock);
goto response_error;
}
break;
case ADMIN_MESSAGE:
- if (admin_message_to_join(&msg.u.msg, admin) < 0)
- {
+ if (admin_message_to_join(&msg.u.msg, admin) < 0) {
PERROR("Failed to deliver message for socket %d.\n", admin->sock);
goto response_error;
}
@@ -1307,8 +1215,7 @@ int admin_handle(void)
struct admin_queue *response;
printf("Chain: ");
response = admin->response;
- while(response)
- {
+ while(response) {
printf("%c", '0'+response->am[0].message);
response=response->next;
}
@@ -1318,8 +1225,7 @@ int admin_handle(void)
break;
case ADMIN_CALL_SETUP:
- if (admin_call(admin, &msg) < 0)
- {
+ if (admin_call(admin, &msg) < 0) {
PERROR("Failed to create call for socket %d.\n", admin->sock);
response_error:
*adminp = admin->next;
@@ -1338,15 +1244,12 @@ int admin_handle(void)
}
/* write queue */
send_data:
- if (admin->response)
- {
+ if (admin->response) {
//#warning
//PERROR("DEBUG socket %d sending data.\n", admin->sock);
len = write(admin->sock, ((unsigned char *)(admin->response->am))+admin->response->offset, sizeof(struct admin_message)*(admin->response->num)-admin->response->offset);
- if (len < 0)
- {
- if (errno != EWOULDBLOCK)
- {
+ if (len < 0) {
+ if (errno != EWOULDBLOCK) {
work = 1;
goto brokenpipe;
}
@@ -1355,12 +1258,10 @@ int admin_handle(void)
work = 1;
if (len == 0)
goto end;
- if (len < (int)(sizeof(struct admin_message)*(admin->response->num) - admin->response->offset))
- {
+ if (len < (int)(sizeof(struct admin_message)*(admin->response->num) - admin->response->offset)) {
admin->response->offset+=len;
goto next;
- } else
- {
+ } else {
temp = admin->response;
admin->response = admin->response->next;
FREE(temp, 0);
diff --git a/tones.c b/tones.c
index 4f8a40f..93d04e9 100644
--- a/tones.c
+++ b/tones.c
@@ -52,46 +52,36 @@ int open_tone(char *file, int *codec, signed int *length, signed int *left)
/* try to open the law file */
SPRINT(filename, "%s.isdn", file);
- if ((fh = open(filename, O_RDONLY)) >= 0)
- {
+ if ((fh = open(filename, O_RDONLY)) >= 0) {
/* stat tone */
l = 0;
- while(42)
- {
- if (l >= 10)
- {
+ while(42) {
+ if (l >= 10) {
close(fh);
PERROR("Link chain too deep: '%s'\n", filename);
return(-1);
}
- if (lstat(filename, &_stat) == -1)
- {
+ if (lstat(filename, &_stat) == -1) {
close(fh);
PERROR("Cannot stat file: '%s'\n", filename);
return(-1);
}
- if (!S_ISLNK(_stat.st_mode))
- {
+ if (!S_ISLNK(_stat.st_mode)) {
break;
}
- if ((linksize=readlink(filename, linkname, sizeof(linkname))) > 0)
- {
+ if ((linksize=readlink(filename, linkname, sizeof(linkname))) > 0) {
linkname[linksize] = '\0';
- } else
- {
+ } else {
close(fh);
PERROR("Cannot read link information: '%s'\n", filename);
return(-1);
}
if (linkname[0] == '/') /* absolute link */
- {
SCPY(filename, linkname);
- } else /* relative link */
- {
+ else { /* relative link */
/* remove filename */
p = filename;
- while(strchr(p, '/'))
- {
+ while(strchr(p, '/')) {
p = strchr(p, '/')+1;
}
*p = 0;
@@ -112,13 +102,11 @@ int open_tone(char *file, int *codec, signed int *length, signed int *left)
/* try to open the wave file */
SPRINT(filename, "%s.wav", file);
- if ((fh = open(filename, O_RDONLY)) >= 0)
- {
+ if ((fh = open(filename, O_RDONLY)) >= 0) {
/* get wave header */
read(fh, buffer, 8);
size=(buffer[4]) + (buffer[5]<<8) + (buffer[6]<<16) + (buffer[7]<<24);
- if (!!strncmp((char *)buffer, "RIFF", 4))
- {
+ if (!!strncmp((char *)buffer, "RIFF", 4)) {
close(fh);
errno = 0;
PERROR("%s is no riff file!\n", filename);
@@ -127,17 +115,14 @@ int open_tone(char *file, int *codec, signed int *length, signed int *left)
// printf("%c%c%c%c size=%ld\n",buffer[0],buffer[1],buffer[2],buffer[3],size);
read(fh, buffer, 4);
size -= 4;
- if (!!strncmp((char *)buffer, "WAVE", 4))
- {
+ if (!!strncmp((char *)buffer, "WAVE", 4)) {
close(fh);
errno = 0;
PERROR("%s is no wave file!\n", filename);
return(-1);
}
- while(size)
- {
- if (size>0 && size<8)
- {
+ while(size) {
+ if (size>0 && size<8) {
close(fh);
errno = 0;
PERROR("Remaining file size %ld not large enough for next chunk.\n",size);
@@ -147,17 +132,14 @@ int open_tone(char *file, int *codec, signed int *length, signed int *left)
chunk=(buffer[4]) + (buffer[5]<<8) + (buffer[6]<<16) + (buffer[7]<<24);
size -= (8+chunk);
// printf("%c%c%c%c length=%d\n",buffer[0],buffer[1],buffer[2],buffer[3],chunk);
- if (size < 0)
- {
+ if (size < 0) {
close(fh);
errno = 0;
PERROR("Chunk '%c%c%c%c' is larger than remainig file size (length=%ld)\n",buffer[0],buffer[1],buffer[2],buffer[3], chunk);
return(-1);
}
- if (!strncmp((char *)buffer, "fmt ", 4))
- {
- if (chunk < 16)
- {
+ if (!strncmp((char *)buffer, "fmt ", 4)) {
+ if (chunk < 16) {
close(fh);
errno = 0;
PERROR("File %s Fmt chunk illegal size.\n", filename);
@@ -165,8 +147,7 @@ int open_tone(char *file, int *codec, signed int *length, signed int *left)
}
read(fh, buffer, chunk);
fmt = (struct fmt *)buffer;
- if (fmt->channels<1 || fmt->channels>2)
- {
+ if (fmt->channels<1 || fmt->channels>2) {
close(fh);
errno = 0;
PERROR("File %s Only support one or two channels file.\n", filename);
@@ -174,13 +155,11 @@ int open_tone(char *file, int *codec, signed int *length, signed int *left)
}
channels = fmt->channels;
// printf("Channels: %d\n", channels);
- if (fmt->sample_rate != 8000)
- {
+ if (fmt->sample_rate != 8000) {
PERROR("Warning: File %s has sample rate of %ld.\n", filename, fmt->sample_rate);
}
// printf("Sample Rate: %ld\n", fmt->sample_rate);
- if (fmt->bits_sample!=8 && fmt->bits_sample!=16)
- {
+ if (fmt->bits_sample!=8 && fmt->bits_sample!=16) {
close(fh);
errno = 0;
PERROR("File %s has neigher 8 nor 16 bit samples.\n", filename);
@@ -190,18 +169,15 @@ int open_tone(char *file, int *codec, signed int *length, signed int *left)
// printf("Bit-Resolution: %d\n", bytes*16-16);
gotfmt = 1;
} else
- if (!strncmp((char *)buffer, "data", 4))
- {
- if (!gotfmt)
- {
+ if (!strncmp((char *)buffer, "data", 4)) {
+ if (!gotfmt) {
close(fh);
errno = 0;
PERROR("File %s No fmt chunk found before data chunk.\n", filename);
return(-1);
}
// printf("Length: %ld samples (%ld.%03ld seconds)\n", chunk/bytes/channels, chunk/bytes/channels/8000, ((chunk/bytes/channels)%8000)*1000/8000);
- if (bytes==2 && channels==1)
- {
+ if (bytes==2 && channels==1) {
if (codec)
*codec = CODEC_MONO;
if (length)
@@ -210,8 +186,7 @@ int open_tone(char *file, int *codec, signed int *length, signed int *left)
*left = ((signed int)chunk)>>1;
// printf("left=%d\n",*left);
} else
- if (bytes==2 && channels==2)
- {
+ if (bytes==2 && channels==2) {
if (codec)
*codec = CODEC_STEREO;
if (length)
@@ -219,27 +194,23 @@ int open_tone(char *file, int *codec, signed int *length, signed int *left)
if (left)
*left = ((signed int)chunk)>>2;
} else
- if (bytes==1 && channels==1)
- {
+ if (bytes==1 && channels==1) {
if (codec)
*codec = CODEC_8BIT;
if (length)
*length = (signed int)chunk;
if (left)
*left = (signed int)chunk;
- } else
- {
+ } else {
close(fh);
errno = 0;
PERROR("File %s Is not MONO8, MONO16 nor STEREO16.\n", filename);
return(-1);
}
return(fh);
- } else
- {
+ } else {
// PDEBUG(DEBUG_PORT, "Unknown chunk '%c%c%c%c'\n",buffer[0],buffer[1],buffer[2],buffer[3]);
- while(chunk > sizeof(buffer))
- {
+ while(chunk > sizeof(buffer)) {
read(fh, buffer, sizeof(buffer));
chunk -= sizeof(buffer);
}
@@ -248,8 +219,7 @@ int open_tone(char *file, int *codec, signed int *length, signed int *left)
}
}
- if (!gotfmt)
- {
+ if (!gotfmt) {
close(fh);
errno = 0;
PERROR("File %s No fmt chunk found in file.\n", filename);
@@ -285,19 +255,16 @@ int read_tone(int fh, unsigned char *buffer, int codec, int len, signed int size
if (!left)
goto unknown_length;
- if (speed!=1)
- {
+ if (speed!=1) {
offset = ((len&(~4)) * (speed-1));
lseek(fh, offset, SEEK_CUR); /* step fowards, backwards (len must be round to 4 bytes, to be sure, that 16bit stereo will not drift out of sync)*/
*left -= offset; /* correct the current bytes left */
- if (*left < 0)
- {
+ if (*left < 0) {
/* eof */
*left = 0;
return(0);
}
- if (*left >= size)
- {
+ if (*left >= size) {
/* eof */
*left = size;
return(0);
@@ -310,19 +277,16 @@ int read_tone(int fh, unsigned char *buffer, int codec, int len, signed int size
if (*left < len)
len = *left;
unknown_length:
- switch(codec)
- {
+ switch(codec) {
case CODEC_LAW:
l = read(fh, buffer, len); /* as is */
break;
case CODEC_MONO:
l = read(fh, buf16, len<<1);
- if (l>0)
- {
+ if (l>0) {
l = l>>1;
- while(i < l)
- {
+ while(i < l) {
sample = *buf16++;
if (sample < -32767)
sample = -32767;
@@ -335,36 +299,28 @@ int read_tone(int fh, unsigned char *buffer, int codec, int len, signed int size
break;
case CODEC_STEREO:
- {
- l = read(fh, buf32, len<<2);
- if (l>0)
- {
- l = l>>2;
- while(i < l)
- {
- sample = (*buf32++);
- sample += (*buf32++);
- if (sample < -32767)
- sample = -32767;
- if (sample > 32767)
- sample = 32767;
- *buffer++ = audio_s16_to_law[sample & 0xffff];
- i++;
- }
+ l = read(fh, buf32, len<<2);
+ if (l>0) {
+ l = l>>2;
+ while(i < l) {
+ sample = (*buf32++);
+ sample += (*buf32++);
+ if (sample < -32767)
+ sample = -32767;
+ if (sample > 32767)
+ sample = 32767;
+ *buffer++ = audio_s16_to_law[sample & 0xffff];
+ i++;
}
}
break;
case CODEC_8BIT:
- {
- l = read(fh, buf8, len);
- if (l>0)
- {
- while(i < l)
- {
- *buffer++ = audio_s16_to_law[(((*buf8++)<<8)-0x8000) & 0xffff];
- i++;
- }
+ l = read(fh, buf8, len);
+ if (l>0) {
+ while(i < l) {
+ *buffer++ = audio_s16_to_law[(((*buf8++)<<8)-0x8000) & 0xffff];
+ i++;
}
}
break;
@@ -391,11 +347,9 @@ void free_tones(void)
void *temp;
toneset_temp = toneset_first;
- while(toneset_temp)
- {
+ while(toneset_temp) {
tonesettone_temp = toneset_temp->first;
- while(tonesettone_temp)
- {
+ while(tonesettone_temp) {
temp = tonesettone_temp;
tonesettone_temp = tonesettone_temp->next;
FREE(temp, sizeof(struct tonesettone));
@@ -436,13 +390,10 @@ int fetch_tones(void)
if (*p == '\0')
return(1);
- while (*p)
- {
+ while (*p) {
p_next = p;
- while(*p_next)
- {
- if (*p_next == ',')
- {
+ while(*p_next) {
+ if (*p_next == ',') {
*p_next = '\0';
p_next++;
break;
@@ -465,24 +416,20 @@ int fetch_tones(void)
SPRINT(path, "%s/%s", SHARE_DATA, p);
dir = opendir(path);
- if (dir == NULL)
- {
+ if (dir == NULL) {
PERROR("Tone set not found: '%s'\n", path);
return(0);
}
- while((dirent=readdir(dir)))
- {
+ while((dirent=readdir(dir))) {
SPRINT(name, "%s", dirent->d_name);
/* remove .isdn and .wave */
- if (strlen(name) >= 4)
- {
+ if (strlen(name) >= 4) {
if (!strcmp(name+strlen(name)-4, ".wav"))
name[strlen(name)-4] = '\0';
}
- if (strlen(name) >= 5)
- {
+ if (strlen(name) >= 5) {
if (!strcmp(name+strlen(name)-5, ".isdn"))
name[strlen(name)-5] = '\0';
}
@@ -497,15 +444,13 @@ int fetch_tones(void)
/* open file */
fh = open_tone(filename, &tone_codec, &tone_size, &tone_left);
- if (fh < 0)
- {
+ if (fh < 0) {
PERROR("Cannot open file: '%s'\n", filename);
continue;
}
fduse++;
- if (tone_size < 0)
- {
+ if (tone_size < 0) {
PERROR("File has 0-length: '%s'\n", filename);
close(fh);
fduse--;
@@ -556,8 +501,7 @@ void *open_tone_fetched(char *dir, char *file, int *codec, signed int *length, s
/* find set */
toneset = toneset_first;
- while(toneset)
- {
+ while(toneset) {
//printf("1. comparing '%s' with '%s'\n", toneset->directory, dir);
if (!strcmp(toneset->directory, dir))
break;
@@ -568,8 +512,7 @@ void *open_tone_fetched(char *dir, char *file, int *codec, signed int *length, s
/* find tone */
tonesettone = toneset->first;
- while(tonesettone)
- {
+ while(tonesettone) {
//printf("2. comparing '%s' with '%s'\n", tonesettone->name, file);
if (!strcmp(tonesettone->name, file))
break;
diff --git a/trace.c b/trace.c
index 2050a2d..73686ff 100644
--- a/trace.c
+++ b/trace.c
@@ -59,8 +59,7 @@ void _add_trace(const char *__file, int __line, const char *name, const char *su
/* check for required name value */
if (!name)
goto nostring;
- if (!name[0])
- {
+ if (!name[0]) {
nostring:
PERROR("trace with name=%s gets element with no string\n", trace.name);
return;
@@ -70,8 +69,7 @@ void _add_trace(const char *__file, int __line, const char *name, const char *su
SCPY(trace.element[trace.elements].name, name);
if (sub) if (sub[0])
SCPY(trace.element[trace.elements].sub, sub);
- if (fmt) if (fmt[0])
- {
+ if (fmt) if (fmt[0]) {
va_start(args, fmt);
VUNPRINT(trace.element[trace.elements].value, sizeof(trace.element[trace.elements].value)-1, fmt, args);
va_end(args);
@@ -112,21 +110,17 @@ static char *print_trace(int detail, int port, char *interface, char *caller, ch
if (!(category & trace.category)) return(NULL);
/* head */
- if (detail >= 3)
- {
+ if (detail >= 3) {
SCAT(trace_string, "------------------------------------------------------------------------------\n");
/* "Port: 1 (BRI PTMP TE)" */
- if (trace.port >= 0)
- {
+ if (trace.port >= 0) {
mISDNport = mISDNport_first;
- while(mISDNport)
- {
+ while(mISDNport) {
if (mISDNport->portnum == trace.port)
break;
mISDNport = mISDNport->next;
}
- if (mISDNport)
- {
+ if (mISDNport) {
SPRINT(buffer, "Port: %d (%s %s %s)", trace.port, (mISDNport->pri)?"PRI":"BRI", (mISDNport->ptp)?"PTP":"PTMP", (mISDNport->ntmode)?"NT":"TE");
/* copy interface, if we have a port */
if (mISDNport->ifport) if (mISDNport->ifport->interface)
@@ -137,16 +131,14 @@ static char *print_trace(int detail, int port, char *interface, char *caller, ch
} else
SCAT(trace_string, "Port: ---");
- if (trace.interface[0])
- {
+ if (trace.interface[0]) {
/* " Interface: 'Ext'" */
SPRINT(buffer, " Interface: '%s'", trace.interface);
SCAT(trace_string, buffer);
} else
SCAT(trace_string, " Interface: ---");
- if (trace.caller[0])
- {
+ if (trace.caller[0]) {
/* " Caller: '021256493'" */
SPRINT(buffer, " Caller: '%s'\n", trace.caller);
SCAT(trace_string, buffer);
@@ -158,16 +150,14 @@ static char *print_trace(int detail, int port, char *interface, char *caller, ch
SPRINT(buffer, "Time: %02d.%02d.%02d %02d:%02d:%02d.%03d", tm->tm_mday, tm->tm_mon+1, tm->tm_year%100, tm->tm_hour, tm->tm_min, tm->tm_sec, trace.usec/1000);
SCAT(trace_string, buffer);
- if (trace.direction)
- {
+ if (trace.direction) {
/* " Direction: out" */
SPRINT(buffer, " Direction: %s", (trace.direction==DIRECTION_OUT)?"OUT":"IN");
SCAT(trace_string, buffer);
} else
SCAT(trace_string, " Direction: ---");
- if (trace.dialing[0])
- {
+ if (trace.dialing[0]) {
/* " Dialing: '57077'" */
SPRINT(buffer, " Dialing: '%s'\n", trace.dialing);
SCAT(trace_string, buffer);
@@ -177,16 +167,15 @@ static char *print_trace(int detail, int port, char *interface, char *caller, ch
SCAT(trace_string, "------------------------------------------------------------------------------\n");
}
- if (detail < 3)
- {
+ if (detail < 3) {
tm = localtime(&ti);
SPRINT(buffer, "%02d.%02d.%02d %02d:%02d:%02d.%03d ", tm->tm_mday, tm->tm_mon+1, tm->tm_year%100, tm->tm_hour, tm->tm_min, tm->tm_sec, trace.usec/1000);
SCAT(trace_string, buffer);
}
/* "CH(45): CC_SETUP (net->user)" */
- switch (trace.category)
- { case CATEGORY_CH:
+ switch (trace.category) {
+ case CATEGORY_CH:
SCAT(trace_string, "CH");
break;
@@ -204,17 +193,14 @@ static char *print_trace(int detail, int port, char *interface, char *caller, ch
SCAT(trace_string, buffer);
/* elements */
- switch(detail)
- {
+ switch(detail) {
case 1: /* brief */
- if (trace.port >= 0)
- {
+ if (trace.port >= 0) {
SPRINT(buffer, " port %d", trace.port);
SCAT(trace_string, buffer);
}
i = 0;
- while(i < trace.elements)
- {
+ while(i < trace.elements) {
SPRINT(buffer, " %s", trace.element[i].name);
if (i) if (!strcmp(trace.element[i].name, trace.element[i-1].name))
buffer[0] = '\0';
@@ -238,8 +224,7 @@ static char *print_trace(int detail, int port, char *interface, char *caller, ch
case 3: /* long */
SCAT(trace_string, "\n");
i = 0;
- while(i < trace.elements)
- {
+ while(i < trace.elements) {
SPRINT(buffer, " %s%s", trace.element[i].name, &spaces[strlen(trace.element[i].name)]);
if (i) if (!strcmp(trace.element[i].name, trace.element[i-1].name))
SPRINT(buffer, " ");
@@ -280,20 +265,16 @@ void _end_trace(const char *__file, int __line)
if (!trace.name[0])
PERROR("trace not started in file %s line %d\n", __file, __line);
- if (options.deb || options.log[0])
- {
+ if (options.deb || options.log[0]) {
string = print_trace(1, -1, NULL, NULL, NULL, 0);
- if (string)
- {
+ if (string) {
/* process debug */
if (options.deb)
debug(NULL, 0, "trace", string);
/* process log */
- if (options.log[0])
- {
+ if (options.log[0]) {
fp = fopen(options.log, "a");
- if (fp)
- {
+ if (fp) {
fwrite(string, strlen(string), 1, fp);
fclose(fp);
}
@@ -303,18 +284,14 @@ void _end_trace(const char *__file, int __line)
/* process admin */
admin = admin_first;
- while(admin)
- {
- if (admin->trace.detail)
- {
+ while(admin) {
+ if (admin->trace.detail) {
string = print_trace(admin->trace.detail, admin->trace.port, admin->trace.interface, admin->trace.caller, admin->trace.dialing, admin->trace.category);
- if (string)
- {
+ if (string) {
/* seek to end of response list */
response = admin->response;
responsep = &admin->response;
- while(response)
- {
+ while(response) {
responsep = &response->next;
response = response->next;
}
diff --git a/vbox.cpp b/vbox.cpp
index 1ff9960..84d679e 100644
--- a/vbox.cpp
+++ b/vbox.cpp
@@ -36,8 +36,7 @@ VBoxPort::VBoxPort(int type, struct port_settings *settings) : Port(type, "vbox"
*/
VBoxPort::~VBoxPort()
{
- if (p_vbox_announce_fh >= 0)
- {
+ if (p_vbox_announce_fh >= 0) {
close(p_vbox_announce_fh);
p_vbox_announce_fh = -1;
fhuse--;
@@ -74,13 +73,10 @@ int VBoxPort::handler(void)
if ((ret = Port::handler()))
return(ret);
- if (p_vbox_record_start && p_vbox_record_limit)
- {
+ if (p_vbox_record_start && p_vbox_record_limit) {
time(&currenttime);
- if (currenttime > (p_vbox_record_limit+p_vbox_record_start))
- {
- while(p_epointlist)
- {
+ if (currenttime > (p_vbox_record_limit+p_vbox_record_start)) {
+ while(p_epointlist) {
/* send release */
message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
message->param.disconnectinfo.cause = 16;
@@ -100,8 +96,7 @@ int VBoxPort::handler(void)
}
/* set time the first time */
- if (p_vbox_audio_start < 1)
- {
+ if (p_vbox_audio_start < 1) {
p_vbox_audio_start = now_d;
return(0);
}
@@ -118,11 +113,9 @@ int VBoxPort::handler(void)
p_vbox_audio_transferred += tosend;
/* if announcement is currently played, send audio data */
- if (p_vbox_announce_fh >=0)
- {
+ if (p_vbox_announce_fh >=0) {
tosend = read_tone(p_vbox_announce_fh, buffer, p_vbox_announce_codec, tosend, p_vbox_announce_size, &p_vbox_announce_left, 1);
- if (tosend <= 0)
- {
+ if (tosend <= 0) {
/* end of file */
close(p_vbox_announce_fh);
p_vbox_announce_fh = -1;
@@ -133,11 +126,9 @@ int VBoxPort::handler(void)
/* connect if not already */
epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
- if (epoint)
- {
+ if (epoint) {
/* if we sent our announcement during ringing, we must now connect */
- if (p_vbox_ext.vbox_free)
- {
+ if (p_vbox_ext.vbox_free) {
/* send connect message */
message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info));
@@ -149,15 +140,13 @@ int VBoxPort::handler(void)
}
/* start recording, if not already */
- if (p_vbox_mode == VBOX_MODE_NORMAL)
- {
+ if (p_vbox_mode == VBOX_MODE_NORMAL) {
/* recording start */
open_record(p_vbox_ext.vbox_codec, 2, 0, p_vbox_ext.number, p_vbox_ext.anon_ignore, p_vbox_ext.vbox_email, p_vbox_ext.vbox_email_file);
vbox_trace_header(this, "RECORDING (announcement is over)", DIRECTION_IN);
end_trace();
} else // else!!
- if (p_vbox_mode == VBOX_MODE_ANNOUNCEMENT)
- {
+ if (p_vbox_mode == VBOX_MODE_ANNOUNCEMENT) {
/* send release */
message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
message->param.disconnectinfo.cause = 16;
@@ -171,8 +160,7 @@ int VBoxPort::handler(void)
delete this;
return(-1); /* must return because port is gone */
}
- } else
- {
+ } else {
if (p_record)
record(buffer, tosend, 0); // from down
message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DATA);
@@ -199,14 +187,12 @@ int VBoxPort::message_epoint(unsigned int epoint_id, int message_id, union param
return(1);
epoint = find_epoint_id(epoint_id);
- if (!epoint)
- {
+ if (!epoint) {
PDEBUG(DEBUG_EPOINT|DEBUG_VBOX, "PORT(%s) no endpoint object found where the message is from.\n", p_name);
return(0);
}
- switch(message_id)
- {
+ switch(message_id) {
case MESSAGE_DATA:
record(param->data.data, param->data.len, 1); // from up
return(1);
@@ -218,8 +204,7 @@ int VBoxPort::message_epoint(unsigned int epoint_id, int message_id, union param
add_trace("cause", "location", "%d", param->disconnectinfo.location);
end_trace();
- while(p_epointlist)
- {
+ while(p_epointlist) {
message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
message->param.disconnectinfo.cause = CAUSE_NORMAL;
message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
@@ -252,15 +237,13 @@ int VBoxPort::message_epoint(unsigned int epoint_id, int message_id, union param
/* get apppbx */
memcpy(&p_vbox_ext, &((class EndpointAppPBX *)(epoint->ep_app))->e_ext, sizeof(p_vbox_ext));
/* extract optional announcement file */
- if ((c = strchr(param->setup.dialinginfo.id, ',')))
- {
+ if ((c = strchr(param->setup.dialinginfo.id, ','))) {
if (c[1] == '/')
SPRINT(filename, c+1);
else
SPRINT(filename, "%s/%s/vbox/%s", EXTENSION_DATA, p_vbox_ext.number);
*c = '\0';
- } else
- {
+ } else {
SPRINT(filename, "%s/%s/vbox/announcement", EXTENSION_DATA, p_vbox_ext.number);
}
vbox_trace_header(this, "SETUP to VBox", DIRECTION_OUT);
@@ -285,8 +268,7 @@ int VBoxPort::message_epoint(unsigned int epoint_id, int message_id, union param
p_connectinfo.screen = INFO_SCREEN_NETWORK;
/* connect unless we can send announcement while ringing */
- if (!p_vbox_ext.vbox_free)
- {
+ if (!p_vbox_ext.vbox_free) {
/* send connect message */
message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_CONNECT);
memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info));
@@ -294,8 +276,7 @@ int VBoxPort::message_epoint(unsigned int epoint_id, int message_id, union param
vbox_trace_header(this, "CONNECT from VBox (after setup)", DIRECTION_IN);
end_trace();
new_state(PORT_STATE_CONNECT);
- } else
- {
+ } else {
/* send alerting message */
message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_ALERTING);
message_put(message);
@@ -305,8 +286,7 @@ int VBoxPort::message_epoint(unsigned int epoint_id, int message_id, union param
}
/* play the announcement */
- if ((p_vbox_announce_fh = open_tone(filename, &p_vbox_announce_codec, &p_vbox_announce_size, &p_vbox_announce_left)) >= 0)
- {
+ if ((p_vbox_announce_fh = open_tone(filename, &p_vbox_announce_codec, &p_vbox_announce_size, &p_vbox_announce_left)) >= 0) {
fhuse++;
}
vbox_trace_header(this, "ANNOUNCEMENT", DIRECTION_OUT);
@@ -316,8 +296,7 @@ int VBoxPort::message_epoint(unsigned int epoint_id, int message_id, union param
/* start recording if desired */
p_vbox_mode = p_vbox_ext.vbox_mode;
p_vbox_record_limit = p_vbox_ext.vbox_time;
- if (p_vbox_announce_fh<0 || p_vbox_mode==VBOX_MODE_PARALLEL)
- {
+ if (p_vbox_announce_fh<0 || p_vbox_mode==VBOX_MODE_PARALLEL) {
/* recording start */
open_record(p_vbox_ext.vbox_codec, 2, 0, p_vbox_ext.number, p_vbox_ext.anon_ignore, p_vbox_ext.vbox_email, p_vbox_ext.vbox_email_file);
vbox_trace_header(this, "RECORDING", DIRECTION_IN);