diff --git a/phoned/remote.c b/phoned/remote.c index 4731ff5..14e63b6 100644 --- a/phoned/remote.c +++ b/phoned/remote.c @@ -28,11 +28,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -/* $Amigan: phoned/phoned/remote.c,v 1.2 2005/06/13 21:04:14 dcp1990 Exp $ */ +/* $Amigan: phoned/phoned/remote.c,v 1.3 2005/06/13 22:02:27 dcp1990 Exp $ */ /* system includes */ #include #include #include +#include +#include /* us */ #include #define MAXBUFSIZE 512 @@ -75,6 +77,7 @@ char *parse_command(cmd, cont, s) c.minute = 20; cid_notify(&c); cid_log(&c); + *cont = 0; RNF("500 OK: Notify tested.\n"); } else if(CHK("tparse")) { cid_t* rc; @@ -82,9 +85,11 @@ char *parse_command(cmd, cont, s) lprintf(info, "nam=%s;month=%d\n", rc->name, rc->month); cid_notify(rc); cid_log(rc); + *cont = 0; RNF("500 OK: Parser tested.\n"); } else if(CHK("gmm")) { give_me_modem(argvect[1] != NULL ? argvect[1] : "AT\r\n"); + *cont = 0; RNF("500 OK: Give Me Modem tested.\n"); } break; @@ -95,8 +100,9 @@ char *parse_command(cmd, cont, s) } return NULL; } -void begin_dialogue(fp) +void begin_dialogue(fp, fd) FILE* fp; + int fd; { char buffer[MAXBUFSIZE]; /* molto importante */ char *rcode, *c; @@ -104,13 +110,14 @@ void begin_dialogue(fp) state_info_t si; memset(&si, 0, sizeof(state_info_t)); si.fpo = fp; /* this is JUST for data, not real commands */ + si.fd = fd; while(keep_going == 0x1 && !feof(fp)) { - if(fgets(buffer, MAXBUFSIZE, fp) == 0x0) break; + if(recv(fd, buffer, MAXBUFSIZE - 1, 0x0) == -1) break; if((c = strrchr(buffer, '\n')) != NULL) *c = '\0'; rcode = parse_command(buffer, &keep_going, &si); if(rcode != NULL) { - fputs(rcode, fp); + send(fd, rcode, strlen(rcode) + 1, 0); if(si.freeit) free(rcode); } } diff --git a/phoned/signals.c b/phoned/signals.c index f62ce8b..7286706 100644 --- a/phoned/signals.c +++ b/phoned/signals.c @@ -42,7 +42,6 @@ void handsig(sig) case SIGINT: case SIGQUIT: case SIGTERM: - case SIGPIPE: lprintf(fatal, "Received signal %d, cleaning up...\n", sig); shutd(); exit(0); @@ -50,6 +49,11 @@ void handsig(sig) case SIGHUP: lprintf(info, "Received HUP, rereading configuration files...\n"); break; +#ifdef DEBUG + case SIGPIPE: + abort(); + break; +#endif default: lprintf(warn, "Received signal %d!\n", sig); } diff --git a/phoned/socket.c b/phoned/socket.c index 02f8ab9..d02ea41 100644 --- a/phoned/socket.c +++ b/phoned/socket.c @@ -55,9 +55,8 @@ void *handclient(k) { int sk = (int)k; FILE* tf; - lprintf(info, "Incoming client."); tf = fdopen(sk, "r+"); - begin_dialogue(tf); + begin_dialogue(tf, sk); fclose(tf); pthread_exit(NULL); return 0;