1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
/* $Id$ */
/***
This file is part of ivam2.
ivam2 is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ivam2 is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.
You should have received a copy of the GNU General Public License
along with ivam2; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <unistd.h>
#include <libdaemon/dlog.h>
#include <limits.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <sys/stat.h>
#include "dtmffifo.h"
struct dtmf_fifo* dtmf_fifo_new(void) {
struct dtmf_fifo *d = NULL;
char p[PATH_MAX];
mode_t u;
d = malloc(sizeof(struct dtmf_fifo));
assert(d);
memset(d, 0, sizeof(struct dtmf_fifo));
d->fd = -1;
d->dir = strdup("/tmp/ivamd.XXXXXX");
assert(d->dir);
u = umask(0077);
if (!mkdtemp(d->dir)) {
umask(u);
daemon_log(LOG_ERR, "Failed to create temporary directory '%s': %s", d->dir, strerror(errno));
goto fail;
}
snprintf(p, sizeof(p), "%s/%s", d->dir, "dtmf");
d->fname = strdup(p);
assert(d->fname);
if (mkfifo(d->fname, 0700) != 0) {
umask(u);
daemon_log(LOG_ERR, "Failed to create FIFO '%s': %s", d->fname, strerror(errno));
goto fail;
}
umask(u);
if ((d->fd = open(d->fname, O_RDWR|O_NDELAY)) < 0) {
daemon_log(LOG_ERR, "Failed to open FIFO '%s': %s", d->fname, strerror(errno));
goto fail;
}
daemon_log(LOG_INFO, "Sucessfully opened DTMF FIFO '%s'.", d->fname);
return d;
fail:
if (d)
dtmf_fifo_free(d);
return NULL;
}
void dtmf_fifo_free(struct dtmf_fifo *d) {
assert(d);
if (d->fd >= 0)
close(d->fd);
if (d->fname) {
unlink(d->fname);
free(d->fname);
}
if (d->dir) {
rmdir(d->dir);
free(d->dir);
}
free(d);
}
void dtmf_fifo_pass(struct dtmf_fifo *d, char c) {
assert(d && d->fd >= 0);
//daemon_log(LOG_INFO, "Recieved DTMF character '%c'", c);
if (write(d->fd, &c, 1) != 1)
daemon_log(LOG_ERR, "Failed to write to DTMF FIFO: %s", strerror(errno));
}
|