More BSD enhancements
[asterisk/asterisk.git] / channels / chan_phone.c
index 09f5b1b..80232c3 100755 (executable)
@@ -146,18 +146,18 @@ static int phone_call(struct ast_channel *ast, char *dest, int timeout)
 
        PHONE_CID cid;
        time_t UtcTime;
 
        PHONE_CID cid;
        time_t UtcTime;
-       struct tm *t;
+       struct tm tm;
 
 
        if (ast->callerid) {
                time(&UtcTime);
 
 
        if (ast->callerid) {
                time(&UtcTime);
-               t = localtime(&UtcTime);
+               localtime_r(&UtcTime,&tm);
 
 
-               if(t != NULL) {
-                       sprintf(cid.month, "%02d",(t->tm_mon + 1));
-                       sprintf(cid.day, "%02d", t->tm_mday);
-                       sprintf(cid.hour, "%02d", t->tm_hour);
-                       sprintf(cid.min, "%02d", t->tm_min);
+               if(&tm != NULL) {
+                       sprintf(cid.month, "%02d",(tm.tm_mon + 1));
+                       sprintf(cid.day, "%02d", tm.tm_mday);
+                       sprintf(cid.hour, "%02d", tm.tm_hour);
+                       sprintf(cid.min, "%02d", tm.tm_min);
                }
                strcpy(cid.name, "Unknown");
                sprintf(cid.number,"%s",ast->callerid);
                }
                strcpy(cid.name, "Unknown");
                sprintf(cid.number,"%s",ast->callerid);
@@ -299,6 +299,7 @@ static int phone_answer(struct ast_channel *ast)
        return 0;
 }
 
        return 0;
 }
 
+#if 0
 static char phone_2digit(char c)
 {
        if (c == 12)
 static char phone_2digit(char c)
 {
        if (c == 12)
@@ -310,6 +311,7 @@ static char phone_2digit(char c)
        else
                return '?';
 }
        else
                return '?';
 }
+#endif
 
 static struct ast_frame  *phone_exception(struct ast_channel *ast)
 {
 
 static struct ast_frame  *phone_exception(struct ast_channel *ast)
 {
@@ -320,7 +322,7 @@ static struct ast_frame  *phone_exception(struct ast_channel *ast)
 
        /* Some nice norms */
        p->fr.datalen = 0;
 
        /* Some nice norms */
        p->fr.datalen = 0;
-       p->fr.timelen = 0;
+       p->fr.samples = 0;
        p->fr.data =  NULL;
        p->fr.src = type;
        p->fr.offset = 0;
        p->fr.data =  NULL;
        p->fr.src = type;
        p->fr.offset = 0;
@@ -381,7 +383,7 @@ static struct ast_frame  *phone_read(struct ast_channel *ast)
 
        /* Some nice norms */
        p->fr.datalen = 0;
 
        /* Some nice norms */
        p->fr.datalen = 0;
-       p->fr.timelen = 0;
+       p->fr.samples = 0;
        p->fr.data =  NULL;
        p->fr.src = type;
        p->fr.offset = 0;
        p->fr.data =  NULL;
        p->fr.src = type;
        p->fr.offset = 0;
@@ -415,6 +417,7 @@ static struct ast_frame  *phone_read(struct ast_channel *ast)
                res = 4;
                break;
        }
                res = 4;
                break;
        }
+       p->fr.samples = 240;
        p->fr.datalen = res;
        p->fr.frametype = AST_FRAME_VOICE;
        p->fr.subclass = p->lastinput;
        p->fr.datalen = res;
        p->fr.frametype = AST_FRAME_VOICE;
        p->fr.subclass = p->lastinput;
@@ -583,7 +586,7 @@ static int phone_write(struct ast_channel *ast, struct ast_frame *frame)
                        res = phone_write_buf(p, pos, expected, maxfr);
                }
                if (res != expected) {
                        res = phone_write_buf(p, pos, expected, maxfr);
                }
                if (res != expected) {
-                       if (errno != EAGAIN) {
+                       if ((errno != EAGAIN) && (errno != EINTR)) {
                                if (res < 0) 
                                        ast_log(LOG_WARNING, "Write returned error (%s)\n", strerror(errno));
        /*
                                if (res < 0) 
                                        ast_log(LOG_WARNING, "Write returned error (%s)\n", strerror(errno));
        /*
@@ -630,6 +633,8 @@ static struct ast_channel *phone_new(struct phone_pvt *i, int state, char *conte
                strncpy(tmp->context, context, sizeof(tmp->context)-1);
                if (strlen(i->ext))
                        strncpy(tmp->exten, i->ext, sizeof(tmp->exten)-1);
                strncpy(tmp->context, context, sizeof(tmp->context)-1);
                if (strlen(i->ext))
                        strncpy(tmp->exten, i->ext, sizeof(tmp->exten)-1);
+               else
+                       strncpy(tmp->exten, "s",  sizeof(tmp->exten) - 1);
                if (strlen(i->language))
                        strncpy(tmp->language, i->language, sizeof(tmp->language)-1);
                if (strlen(i->callerid))
                if (strlen(i->language))
                        strncpy(tmp->language, i->language, sizeof(tmp->language)-1);
                if (strlen(i->callerid))
@@ -843,9 +848,9 @@ static void *do_monitor(void *data)
                                tv.tv_usec = 30000;
                                tv.tv_sec = 0;
                        }
                                tv.tv_usec = 30000;
                                tv.tv_sec = 0;
                        }
-                       res = select(n + 1, &rfds, NULL, &efds, &tv);
+                       res = ast_select(n + 1, &rfds, NULL, &efds, &tv);
                } else {
                } else {
-                       res = select(n + 1, &rfds, NULL, &efds, NULL);
+                       res = ast_select(n + 1, &rfds, NULL, &efds, NULL);
                        tv.tv_usec = 0;
                        tv.tv_sec = 0;
                        tonepos = 0;
                        tv.tv_usec = 0;
                        tv.tv_sec = 0;
                        tonepos = 0;