Merge branch 'master' of ssh://jolly@www.mISDN.org/var/git/lcr
authorAndreas Eversberg <jolly@eversberg.eu>
Tue, 27 Oct 2009 06:56:59 +0000 (07:56 +0100)
committerAndreas Eversberg <jolly@eversberg.eu>
Tue, 27 Oct 2009 06:56:59 +0000 (07:56 +0100)
Conflicts:
README

README
action_vbox.cpp
crypt.cpp
extension.c
gsm_conf.c
interface.c
macro.h
route.c
ss5.cpp
ss5.h

diff --git a/README b/README
index c7cac53..8c0d65a 100644 (file)
--- a/README
+++ b/README
@@ -521,5 +521,6 @@ Changes after Version 1.6
     external interface name in routing.conf: ": extern interfaces=XXXXX"
 - Added experimental CCITT No. 5 signalling system. (for educational purpose)
 - Added socket owner/group options to options.conf
+- Fixed/simplyfied config parser. The last digit of the last line was ignored.
 
 
index 2426610..e325c0f 100644 (file)
@@ -142,10 +142,7 @@ void EndpointAppPBX::vbox_index_read(int num)
        fduse++;
 
        i = 0;
-       while((fgets(buffer,sizeof(buffer),fp))) {
-               buffer[sizeof(buffer)-1] = '\0';
-               if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
-
+       while((GETLINE(buffer, fp))) {
                name[0] = callerid[0] = '\0';
                mon = mday = hour = min = 0;
                sscanf(buffer, "%s %d %d %d %d %d %s", name, &year, &mon, &mday, &hour, &min, callerid);
index ee8e7cc..44e901c 100644 (file)
--- a/crypt.cpp
+++ b/crypt.cpp
@@ -216,7 +216,7 @@ static unsigned int get_bogomips(void)
        }
        fduse++;
        buffer[sizeof(buffer-1)] = '\0';
-       while(fgets(buffer, sizeof(buffer)-1, fp)) {
+       while(GETLINE(buffer, fp)) {
                if (!!strncmp(buffer, "bogomips", 8))
                        continue;
                if (!strchr(buffer, ':'))
index a1c3aa7..00e5326 100644 (file)
@@ -68,10 +68,8 @@ int read_extension(struct extension *ext, char *num)
        ext->vbox_codec = CODEC_MONO;
 
        line=0;
-       while((fgets(buffer, sizeof(buffer), fp))) {
+       while((GETLINE(buffer, fp))) {
                line++;
-               buffer[sizeof(buffer)-1] = '\0';
-               if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
                p = buffer;
 
                while(*p <= 32) { /* skip spaces */
@@ -1228,10 +1226,8 @@ int parse_phonebook(char *number, char **abbrev_pointer, char **phone_pointer, c
        }
 
        line=0;
-       while((fgets(buffer, sizeof(buffer), fp))) {
+       while((GETLINE(buffer, fp))) {
                line++;
-               buffer[sizeof(buffer)-1] = '\0';
-               if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
                p = buffer;
 
                while(*p <= 32) { /* skip spaces */
@@ -1351,10 +1347,8 @@ int parse_secrets(char *number, char *remote_id, char **auth_pointer, char **cry
        }
 
        line=0;
-       while((fgets(buffer, sizeof(buffer), fp))) {
+       while((GETLINE(buffer, fp))) {
                line++;
-               buffer[sizeof(buffer)-1] = '\0';
-               if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
                p = buffer;
 
                while(*p <= 32) { /* skip spaces */
@@ -1476,10 +1470,8 @@ char *parse_directory(char *number, int type)
        }
 
        line=0;
-       while((fgets(buffer, sizeof(buffer), fp))) {
+       while((GETLINE(buffer, fp))) {
                line++;
-               buffer[sizeof(buffer)-1] = '\0';
-               if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
                p = buffer;
 
                while(*p <= 32) { /* skip spaces */
@@ -1611,10 +1603,8 @@ int parse_callbackauth(char *number, struct caller_info *callerinfo)
        }
 
        line=0;
-       while((fgets(buffer, sizeof(buffer), fp))) {
+       while((GETLINE(buffer, fp))) {
                line++;
-               buffer[sizeof(buffer)-1] = '\0';
-               if (buffer[0]) buffer[strlen(buffer)-1] = '\0';
                p = buffer;
 
                while(*p <= 32) { /* skip spaces */
index 9957b86..082a6ed 100644 (file)
@@ -47,10 +47,8 @@ int gsm_conf(struct gsm_conf *gsm_conf)
        }
 
        line=0;
-       while((fgets(buffer,sizeof(buffer),fp))) {
+       while((GETLINE(buffer, fp))) {
                line++;
-               buffer[sizeof(buffer)-1]=0;
-               if (buffer[0]) buffer[strlen(buffer)-1]=0;
                p=buffer;
 
                while(*p <= 32) { /* skip spaces */
index 42f409c..8e21c75 100644 (file)
@@ -1148,9 +1148,7 @@ struct interface *read_interfaces(void)
        }
 
        line=0;
-       while((fgets(buffer,sizeof(buffer),fp))) {
-               buffer[sizeof(buffer)-1]=0;
-               if (buffer[0]) buffer[strlen(buffer)-1]=0;
+       while((GETLINE(buffer, fp))) {
                p=buffer;
                line++;
 
diff --git a/macro.h b/macro.h
index 29b2794..9e4bcd1 100644 (file)
--- a/macro.h
+++ b/macro.h
@@ -92,7 +92,7 @@ static inline void *_malloc(unsigned int size, const char *function, int line)
        if (!addr)
                fatal(function, line, "No memory for %d bytes.\n", size);
        memset(addr, 0, size);
-       return(addr);
+       return addr;
 }
 
 /* memory freeing with clearing memory to prevent using freed memory */
@@ -104,4 +104,20 @@ static inline void _free(void *addr, int size)
        free(addr);
 }
 
+/* fill buffer and be sure that it's result is 0-terminated, also remove newline */
+#define GETLINE(buffer, fp) _getline(buffer, sizeof(buffer), fp)
+static inline char *_getline(char *buffer, int size, FILE *fp)
+{
+       if (!fgets(buffer, size-1, fp))
+               return NULL;
+       buffer[size-1] = '\0';
+       if (!buffer[0])
+               return buffer;
+       if (buffer[strlen(buffer)-1] == '\n')
+               buffer[strlen(buffer)-1] = '\0';
+       if (buffer[strlen(buffer)-1] == '\r')
+               buffer[strlen(buffer)-1] = '\0';
+       return buffer;
+}
+
 
diff --git a/route.c b/route.c
index d47f8c2..4fecf38 100644 (file)
--- a/route.c
+++ b/route.c
@@ -839,11 +839,9 @@ struct route_ruleset *ruleset_parse(void)
        go_leaf:
         line[nesting]=0;
        go_root:
-        while((fgets(buffer,sizeof(buffer),fp[nesting])))
+        while((GETLINE(buffer, fp[nesting])))
         {
                 line[nesting]++;
-                buffer[sizeof(buffer)-1]=0;
-                if (buffer[0]) buffer[strlen(buffer)-1]=0;
                 p = buffer;
 
                /* remove tabs */
diff --git a/ss5.cpp b/ss5.cpp
index 0d453e4..164ef0c 100644 (file)
--- a/ss5.cpp
+++ b/ss5.cpp
@@ -1347,7 +1347,7 @@ void Pss5::digit_ind(char digit)
        end_trace();
        new_ss5_state(SS5_STATE_IDLE);
 
-       do_setup(dial);
+       do_setup(dial, 1);
        new_state(PORT_STATE_IN_PROCEEDING);
 }
 
@@ -1392,7 +1392,7 @@ void Pss5::pulse_ind(int on)
                        }
                        if (p_state == PORT_STATE_IN_SETUP) {
                                /* sending digit as setup */
-                               do_setup(dial); /* include 'a' == KP1 */
+                               do_setup(dial, 0); /* include 'a' == KP1 */
                                new_state(PORT_STATE_IN_OVERLAP);
                        } else {
                                /* sending digit as information */
@@ -1618,13 +1618,13 @@ void Pss5::do_release(int cause, int location)
 /*
  * create endpoint and send setup
  */
-void Pss5::do_setup(char *dial)
+void Pss5::do_setup(char *dial, int complete)
 {
        class Endpoint *epoint;
        struct lcr_msg *message;
 
        SCPY(p_dialinginfo.id, dial);
-       p_dialinginfo.sending_complete = 1;
+       p_dialinginfo.sending_complete = complete;
        p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
        p_callerinfo.screen = INFO_SCREEN_NETWORK;
        p_callerinfo.ntype = INFO_NTYPE_NOTPRESENT;
diff --git a/ss5.h b/ss5.h
index 6897abd..238501f 100644 (file)
--- a/ss5.h
+++ b/ss5.h
@@ -57,7 +57,7 @@ class Pss5 : public PmISDN
        void start_signal(int);
        void start_outgoing(void);
        void do_release(int cause, int location);
-       void do_setup(char *digit);
+       void do_setup(char *digit, int complete);
 
        void seizing_ind(void);
        void digit_ind(char digit);