Hangup implemented for filters, along with the appropriate modem stuffs
This commit is contained in:
parent
7ac6d1d89c
commit
2d9eff8e76
@ -3,7 +3,7 @@
|
|||||||
* (C)2005, Dan Ponte
|
* (C)2005, Dan Ponte
|
||||||
* BSDL w/ advert.
|
* BSDL w/ advert.
|
||||||
*/
|
*/
|
||||||
/* $Amigan: phoned/include/phoned.h,v 1.12 2005/06/13 22:02:19 dcp1990 Exp $ */
|
/* $Amigan: phoned/include/phoned.h,v 1.13 2005/06/16 21:04:58 dcp1990 Exp $ */
|
||||||
#include <pcre.h> /* fugly, I know... */
|
#include <pcre.h> /* fugly, I know... */
|
||||||
#define VERSION "0.1"
|
#define VERSION "0.1"
|
||||||
#define LOGFILE "/var/log/phoned.log"
|
#define LOGFILE "/var/log/phoned.log"
|
||||||
@ -146,3 +146,5 @@ void *modem_io(void *k);
|
|||||||
void give_me_modem(char* str);
|
void give_me_modem(char* str);
|
||||||
char *parse_command(const char *cmd, short *cont, state_info_t *s);
|
char *parse_command(const char *cmd, short *cont, state_info_t *s);
|
||||||
void begin_dialogue(FILE* fp, int fd);
|
void begin_dialogue(FILE* fp, int fd);
|
||||||
|
void modem_pickup(void);
|
||||||
|
void modem_hangup(void);
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
/* $Amigan: phoned/phoned/filters.c,v 1.9 2005/06/12 22:17:44 dcp1990 Exp $ */
|
/* $Amigan: phoned/phoned/filters.c,v 1.10 2005/06/16 21:05:00 dcp1990 Exp $ */
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -195,7 +195,10 @@ void check_condition(cid)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(c->action & CTACT_HUP) {
|
if(c->action & CTACT_HUP) {
|
||||||
lprintf(error, "Hangup not yet implemented! Check back later. (cond %s)\n", c->filtername);
|
modem_pickup();
|
||||||
|
sleep(2);
|
||||||
|
modem_hangup();
|
||||||
|
lprintf(info, "Hangup! (%s)\n", c->filtername);
|
||||||
}
|
}
|
||||||
if(c->action & CTACT_RNOT) {
|
if(c->action & CTACT_RNOT) {
|
||||||
lprintf(error, "Mail not yet implemented! Check back later. (cond %s)\n", c->filtername);
|
lprintf(error, "Mail not yet implemented! Check back later. (cond %s)\n", c->filtername);
|
||||||
|
@ -46,7 +46,9 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <phoned.h>
|
#include <phoned.h>
|
||||||
#define INITSTRING "ATZ\r\nAT E0 #CID=2 V0\r\n"
|
#define ROCKWELL_INITSTRING "ATZ\r\nAT E0 #CID=2 V0\r\n"
|
||||||
|
#define ROCKWELL_PICKUP "ATH1\r\n"
|
||||||
|
#define ROCKWELL_HANGUP "ATH\r\n"
|
||||||
/* globals */
|
/* globals */
|
||||||
FILE* modem;
|
FILE* modem;
|
||||||
int modemfd;
|
int modemfd;
|
||||||
@ -56,29 +58,33 @@ short doing_cid = 0;
|
|||||||
extern struct conf cf;
|
extern struct conf cf;
|
||||||
pthread_t modemth;
|
pthread_t modemth;
|
||||||
pthread_mutex_t modemmx = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t modemmx = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
pthread_mutex_t miomx = PTHREAD_MUTEX_INITIALIZER; /* is modem_io() running? */
|
||||||
pthread_mutex_t mpipemx = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t mpipemx = PTHREAD_MUTEX_INITIALIZER;
|
||||||
pthread_mutex_t buffermx = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t buffermx = PTHREAD_MUTEX_INITIALIZER;
|
||||||
pthread_cond_t mpcond = PTHREAD_COND_INITIALIZER;
|
pthread_cond_t mpcond = PTHREAD_COND_INITIALIZER;
|
||||||
int modempipes[2];
|
int modempipes[2];
|
||||||
extern pthread_mutex_t cfmx;
|
extern pthread_mutex_t cfmx;
|
||||||
void give_me_modem(str)
|
void stmod(str)
|
||||||
char* str;
|
const char* str;
|
||||||
{
|
{
|
||||||
|
if(pthread_mutex_trylock(&modemmx) != 0 && pthread_mutex_trylock(&miomx) == 0) {
|
||||||
pthread_mutex_lock(&mpipemx);
|
pthread_mutex_lock(&mpipemx);
|
||||||
write(modempipes[1], "G", 1);
|
write(modempipes[1], "G", 1);
|
||||||
pthread_mutex_unlock(&mpipemx);
|
pthread_mutex_unlock(&mpipemx);
|
||||||
pthread_mutex_lock(&modemmx);
|
pthread_mutex_lock(&modemmx);
|
||||||
fputs(str, modem);
|
write(modemfd, str, strlen(str) + 1);
|
||||||
fflush(modem);
|
|
||||||
pthread_cond_signal(&mpcond);
|
pthread_cond_signal(&mpcond);
|
||||||
pthread_mutex_unlock(&modemmx);
|
pthread_mutex_unlock(&modemmx);
|
||||||
}
|
} else {
|
||||||
void stmod(const char* str)
|
|
||||||
{
|
|
||||||
pthread_mutex_lock(&modemmx);
|
pthread_mutex_lock(&modemmx);
|
||||||
fputs(str, modem);
|
write(modemfd, str, strlen(str) + 1);
|
||||||
fflush(modem);
|
pthread_mutex_lock(&modemmx);
|
||||||
pthread_mutex_unlock(&modemmx);
|
}
|
||||||
|
}
|
||||||
|
void give_me_modem(str) /* warning: deprecated! */
|
||||||
|
char *str;
|
||||||
|
{
|
||||||
|
stmod(str);
|
||||||
}
|
}
|
||||||
int close_modem(char* dev)
|
int close_modem(char* dev)
|
||||||
{
|
{
|
||||||
@ -129,7 +135,7 @@ int init_modem(char* dev)
|
|||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&modemmx);
|
pthread_mutex_unlock(&modemmx);
|
||||||
stmod(INITSTRING);
|
stmod(ROCKWELL_INITSTRING);
|
||||||
pthread_mutex_lock(&mpipemx);
|
pthread_mutex_lock(&mpipemx);
|
||||||
pipe(modempipes);
|
pipe(modempipes);
|
||||||
pthread_mutex_unlock(&mpipemx);
|
pthread_mutex_unlock(&mpipemx);
|
||||||
@ -190,10 +196,7 @@ void modem_hread(char* cbuf)
|
|||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* XXX: this is inefficient
|
* XXX: this is inefficient
|
||||||
* TODO: move this so we have a global pipe that is select()ed.
|
* Thanks jilles for the tip on the pipe method used below :)
|
||||||
* Threads lock its mutex, write ONE BYTE to it, and the select() receives it. The calling thread unlocks the pipe mux.
|
|
||||||
* This unlocks the modem mutex, waits, and tries to keep locking (maybe using a conditional)
|
|
||||||
* until it gets it and reselects. DO IT. (thanks jilles)
|
|
||||||
* Do all this after a trylock().
|
* Do all this after a trylock().
|
||||||
*/
|
*/
|
||||||
void *modem_io(k)
|
void *modem_io(k)
|
||||||
@ -206,6 +209,7 @@ void *modem_io(k)
|
|||||||
k = 0;
|
k = 0;
|
||||||
*cbuf = '\0'; cbuf[1] = '\0';
|
*cbuf = '\0'; cbuf[1] = '\0';
|
||||||
pthread_mutex_lock(&modemmx);
|
pthread_mutex_lock(&modemmx);
|
||||||
|
pthread_mutex_lock(&miomx);
|
||||||
for(;;) {
|
for(;;) {
|
||||||
pthread_mutex_lock(&cfmx);
|
pthread_mutex_lock(&cfmx);
|
||||||
/* dotm = cf.modem_tm; */
|
/* dotm = cf.modem_tm; */
|
||||||
@ -230,7 +234,9 @@ void *modem_io(k)
|
|||||||
{
|
{
|
||||||
if(FD_ISSET(modemfd, &fds) != 0) {
|
if(FD_ISSET(modemfd, &fds) != 0) {
|
||||||
read(modemfd, cbuf, 1);
|
read(modemfd, cbuf, 1);
|
||||||
|
pthread_mutex_unlock(&modemmx); /* so we can use the same functions for sep. threads */
|
||||||
modem_hread(cbuf);
|
modem_hread(cbuf);
|
||||||
|
pthread_mutex_lock(&modemmx);
|
||||||
*cbuf = '\0';
|
*cbuf = '\0';
|
||||||
}
|
}
|
||||||
if(FD_ISSET(modempipes[0], &fds) != 0) {
|
if(FD_ISSET(modempipes[0], &fds) != 0) {
|
||||||
@ -240,7 +246,20 @@ void *modem_io(k)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pthread_mutex_unlock(&miomx);
|
||||||
pthread_mutex_unlock(&modemmx);
|
pthread_mutex_unlock(&modemmx);
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
/* Modem control stuff: be forewarned, this might become pluggable!
|
||||||
|
* Rockwell for now.
|
||||||
|
*/
|
||||||
|
void modem_pickup(void)
|
||||||
|
{
|
||||||
|
/* no locking because stmod() does it for us */
|
||||||
|
stmod(ROCKWELL_PICKUP);
|
||||||
|
}
|
||||||
|
void modem_hangup(void)
|
||||||
|
{
|
||||||
|
stmod(ROCKWELL_HANGUP);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user