Source cleanup.
authorroot <root@nuedel.(none)>
Sun, 5 Jul 2009 20:14:21 +0000 (22:14 +0200)
committerroot <root@nuedel.(none)>
Sun, 5 Jul 2009 20:14:21 +0000 (22:14 +0200)
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

21 files changed:
bootstrap.c
cause.c
crypt.cpp
endpoint.cpp
genext.c
genrc.c
gentones.c
genwave.c
ie.cpp
join.cpp
joinpbx.cpp
joinremote.cpp
lcradmin.c
mail.c
main.c
message.c
route.c
socket_server.c
tones.c
trace.c
vbox.cpp

index b2d2b0c..96f7ec2 100644 (file)
@@ -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,
-       /* res*/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 (file)
--- 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;
index 87a5dde..ee8e7cc 100644 (file)
--- 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);
index e9c680f..28ea12f 100644 (file)
@@ -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);
        }
index 979a7c1..486af09 100644 (file)
--- 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 (file)
--- 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++;
index daaf9cb..6cdaf37 100644 (file)
@@ -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
index b397d3c..8f32076 100644 (file)
--- 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 (file)
--- 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++;
        }
index b3f8843..b1a06bb 100644 (file)
--- 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");
                }
 
index 630c599..5c686dc 100644 (file)
@@ -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);
index 4b92612..a4f9380 100644 (file)
@@ -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;         
        }
index 12bfa74..0138de9 100644 (file)
@@ -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 (file)
--- 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 (file)
--- 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");
index ff0d70c..403253d 100644 (file)
--- 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 (file)
--- 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') {
                               &nb