diff --git a/include/phoned.h b/include/phoned.h index 28e8711..8676846 100644 --- a/include/phoned.h +++ b/include/phoned.h @@ -3,7 +3,7 @@ * (C)2005, Dan Ponte * BSDL w/ advert. */ -/* $Amigan: phoned/include/phoned.h,v 1.27 2005/06/23 22:06:58 dcp1990 Exp $ */ +/* $Amigan: phoned/include/phoned.h,v 1.28 2005/06/25 02:43:54 dcp1990 Exp $ */ #include /* fugly, I know... */ #define VERSION "0.1" #define LOGFILE "-" @@ -204,6 +204,7 @@ short db_check_crend(char *loginna, char *pass); cid_t *decode_sdmf(unsigned char *s); cid_t *decode_mdmf(unsigned char *s); void voice_init(void); +int dialogue_with_modem(int (*cback)(int, void*), void *arg); /* old stuff... void modem_pickup(void); void modem_hangup(void); diff --git a/phonectl/phonectl.c b/phonectl/phonectl.c index a474b02..6426f90 100644 --- a/phonectl/phonectl.c +++ b/phonectl/phonectl.c @@ -27,18 +27,20 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -/* $Amigan: phoned/phonectl/phonectl.c,v 1.5 2005/06/23 22:07:01 dcp1990 Exp $ */ +/* $Amigan: phoned/phonectl/phonectl.c,v 1.6 2005/06/25 02:43:54 dcp1990 Exp $ */ /* system includes */ #include #include #include #include +#include #include #include #include #include #include #include +#include #include #include /* us */ @@ -59,6 +61,12 @@ int main(argc, argv) perror("conn"); exit(-1); } +#if 0 + if(setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char*)&on, sizeof(on)) < 0) { + perror("setsockopt"); + exit(-1); + } +#endif if(argc == 1) { while(!feof(stdin)) { fputs("phonectl> ", stdout); @@ -69,8 +77,8 @@ int main(argc, argv) close(s); return 0; } - write(s, buff, strlen(buff) + 1); - read(s, buff, sizeof(buff)); + send(s, buff, strlen(buff) + 1, 0x0); + recv(s, buff, sizeof(buff), 0x0); fputs(buff, stdout); } } diff --git a/phoned/modem.c b/phoned/modem.c index 095bf81..7fa0ab2 100644 --- a/phoned/modem.c +++ b/phoned/modem.c @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include @@ -84,6 +83,26 @@ void stmod(str) pthread_mutex_unlock(&modemmx); } } +int dialogue_with_modem(cback, arg) + int (*cback)(int, void*); + void *arg; +{ + int rc; + if(pthread_mutex_trylock(&modemmx) != 0 && pthread_mutex_trylock(&miomx) != 0) { + pthread_mutex_lock(&mpipemx); + write(modempipes[1], "G", 1); + pthread_mutex_unlock(&mpipemx); + pthread_mutex_lock(&modemmx); + rc = cback(modemfd, arg); + pthread_cond_signal(&mpcond); + pthread_mutex_unlock(&modemmx); + } else { + pthread_mutex_lock(&modemmx); + rc = cback(modemfd, arg); + pthread_mutex_unlock(&modemmx); + } + return rc; +} char *sendwr(str, bufferback, howmuch) const char *str; char *bufferback; @@ -208,7 +227,9 @@ void modem_hread(char* cbuf) if((buffer[0] == '8' && buffer[1] == '0') || (buffer[0] == '0' && buffer[1] == '4')) doing_cid = 1; if(cbuf[0] == '\n') { +#ifdef MODEMSAID lprintf(debug, "Modem said %s", buffer); +#endif if(doing_cid) { cid_t *rc; rc = parse_cid(buffer); @@ -246,9 +267,6 @@ void *modem_io(k) pthread_mutex_lock(&modemmx); pthread_mutex_lock(&miomx); for(;;) { - pthread_mutex_lock(&cfmx); - /* dotm = cf.modem_tm; */ - pthread_mutex_unlock(&cfmx); FD_ZERO(&fds); FD_SET(modemfd, &fds); FD_SET(modempipes[0], &fds); diff --git a/phoned/remote.c b/phoned/remote.c index a1d7428..fd96354 100644 --- a/phoned/remote.c +++ b/phoned/remote.c @@ -28,13 +28,20 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -/* $Amigan: phoned/phoned/remote.c,v 1.12 2005/06/23 22:07:02 dcp1990 Exp $ */ +/* $Amigan: phoned/phoned/remote.c,v 1.13 2005/06/25 02:43:54 dcp1990 Exp $ */ /* system includes */ #include #include #include #include #include +#include +#include +#include +#include +#include +#include +#include #include /* us */ #include @@ -201,6 +208,76 @@ short log_in_user(loginna, pass, lnt) return 0; } +int dialogue_cb(fd, sck) + int fd; + void *sck; +{ + FILE *so = (FILE*)sck; + int s; + fd_set fds; + fd_set ex; + char buffer[3]; + char lastc = 0x0; + int rc; + s = fileno(so); + memset(buffer, 0, sizeof(buffer)); + for(;;) { + FD_ZERO(&fds); + FD_ZERO(&ex); + FD_SET(s, &ex); + FD_SET(fd, &fds); + FD_SET(s, &fds); + switch(select(s + 1, &fds, NULL, &ex, NULL)) { + case -1: + lprintf(error, "select on modem: %s", strerror(errno)); + return 0; + case 0: + /* WON'T HAPPEN */ + break; + default: + { + lprintf(debug, "Defaulted!"); + if(FD_ISSET(s, &ex) != 0) { + lprintf(debug, "Exceptional."); + return 0; + } + if(FD_ISSET(fd, &fds) != 0) { + rc = read(fd, buffer, 1); + if(rc == -1) { + lprintf(error, "read(): %s", strerror(errno)); + return 0; + } + rc = send(s, buffer, 1, 0x0); + lprintf(debug, "rc=%d", rc); + if(rc == -1) { + lprintf(error, "send(): %s", strerror(errno)); + return 0; + } + } + if(FD_ISSET(s, &fds) != 0) { + rc = recv(s, buffer, 1, 0x0); + lprintf(debug, "rcv=%d", rc); + if(rc == 0) { + lprintf(debug, "Socket closed! Got zero!\n"); + return 0; + } else if(rc == -1) { + lprintf(debug, "recv(): %s", strerror(errno)); + return 0; + } + if(lastc == '%' && *buffer == 'q') return 1; + lastc = *buffer; + rc = write(fd, buffer, 1); + if(rc == -1) { + lprintf(error, "write(): %s", strerror(errno)); + return 0; + } + } + } + } + } + /* NOTREACHED */ + return 1; +} char *parse_command(cmd, cont, s) const char *cmd; short *cont; @@ -274,6 +351,14 @@ char *parse_command(cmd, cont, s) cid_handle(&c); *cont = 0; RNF("500 OK: Handler tested.\n"); + } else if(CHK("mdlg")) { + int rc; + rc = dialogue_with_modem(&dialogue_cb, (void*)s->fpo); + if(!rc) { + return NULL; + } else { + RNF("500 OK: Dialogue finished"); + } } else if(CHK("tparse")) { cid_t* rc; rc = parse_cid("802701083132323130383234070F5354414E444953482048454154494E020A343031333937333337325C\n");