Improve mp3 player quality (bug #1527)
[asterisk/asterisk.git] / callerid.c
index f1827b7..3f3e2f7 100755 (executable)
@@ -110,8 +110,8 @@ struct callerid_state *callerid_new(void)
 {
        struct callerid_state *cid;
        cid = malloc(sizeof(struct callerid_state));
-       memset(cid, 0, sizeof(struct callerid_state));
        if (cid) {
+               memset(cid, 0, sizeof(struct callerid_state));
                cid->fskd.spb = 7;              /* 1200 baud */
                cid->fskd.hdlc = 0;             /* Async */
                cid->fskd.nbit = 8;             /* 8 bits */
@@ -274,6 +274,8 @@ int callerid_feed(struct callerid_state *cid, unsigned char *ubuf, int len, int
                                                        memcpy(cid->name, cid->rawdata + x + 1, res);
                                                        cid->name[res] = '\0';
                                                        break;
+                                               case 22: /* Something French */
+                                                       break;
                                                default:
                                                        ast_log(LOG_NOTICE, "Unknown IE %d\n", cid->rawdata[x-1]);
                                                }
@@ -324,19 +326,19 @@ void callerid_free(struct callerid_state *cid)
 static int callerid_genmsg(char *msg, int size, char *number, char *name, int flags)
 {
        time_t t;
-       struct tm *tm;
+       struct tm tm;
        char *ptr;
        int res;
        int i,x;
        /* Get the time */
        time(&t);
-       tm = localtime(&t);
+       localtime_r(&t,&tm);
        
        ptr = msg;
        
        /* Format time and message header */
-       res = snprintf(ptr, size, "\001\010%02d%02d%02d%02d", tm->tm_mon + 1,
-                               tm->tm_mday, tm->tm_hour, tm->tm_min);
+       res = snprintf(ptr, size, "\001\010%02d%02d%02d%02d", tm.tm_mon + 1,
+                               tm.tm_mday, tm.tm_hour, tm.tm_min);
        size -= res;
        ptr += res;
        if (!number || !strlen(number) || (flags & CID_UNKNOWN_NUMBER)) {
@@ -434,6 +436,9 @@ int vmwi_generate(unsigned char *buf, int active, int mdmf, int codec)
                sum += msg[x];
        sum = (256 - (sum & 255));
        msg[len++] = sum;
+       /* Wait a half a second */
+       for (x=0;x<4000;x++)
+               PUT_BYTE(0x7f);
        /* Transmit 30 0x55's (looks like a square wave) for channel seizure */
        for (x=0;x<30;x++)
                PUT_CLID(0x55);
@@ -506,7 +511,7 @@ int ast_isphonenumber(char *n)
        if (!n || !strlen(n))
                return 0;
        for (x=0;n[x];x++)
-               if (!strchr("0123456789", n[x]))
+               if (!strchr("0123456789*#+", n[x]))
                        return 0;
        return 1;
 }
@@ -536,7 +541,7 @@ int ast_callerid_parse(char *instr, char **name, char **location)
                                instr[strlen(instr) - 1] = '\0';
                        /* And leading spaces */
                        while(**name && (**name < 33))
-                               name++;
+                               (*name)++;
                        return 0;
                }
        } else {
@@ -547,8 +552,11 @@ int ast_callerid_parse(char *instr, char **name, char **location)
                        *name = NULL;
                        *location = instr;
                } else {
-                       /* Assume it's just a name */
+                       /* Assume it's just a name.  Make sure it's not quoted though */
                        *name = instr;
+                       while(*(*name) && ((*(*name) < 33) || (*(*name) == '\"'))) (*name)++;
+                       ne = *name + strlen(*name) - 1;
+                       while((ne > *name) && ((*ne < 33) || (*ne == '\"'))) { *ne = '\0'; ne--; }
                        *location = NULL;
                }
                return 0;