summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-01-05 22:26:34 +0000
committerLennart Poettering <lennart@poettering.net>2004-01-05 22:26:34 +0000
commit444b524c3a26d8dd83fae2a074d3d13b10ba17f7 (patch)
treee2f5d69324b7383f735fc3f350fa5a10ccaba6bc /src
parentd24a3f265ec4344b5502ec57df3cf8358f6f1499 (diff)
forgot some files
preliminary client implementation git-svn-id: file:///home/lennart/svn/public/ivam2/trunk@15 dbf6933d-3bce-0310-9bcc-ed052ba35b35
Diffstat (limited to 'src')
-rw-r--r--src/dtmffifo.c82
-rw-r--r--src/dtmffifo.h13
2 files changed, 95 insertions, 0 deletions
diff --git a/src/dtmffifo.c b/src/dtmffifo.c
new file mode 100644
index 0000000..54a1f62
--- /dev/null
+++ b/src/dtmffifo.c
@@ -0,0 +1,82 @@
+#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];
+
+ 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);
+
+ if (!mkdtemp(d->dir)) {
+ 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) {
+ daemon_log(LOG_ERR, "Failed to create FIFO '%s': %s", d->fname, strerror(errno));
+ goto fail;
+ }
+
+ 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));
+}
diff --git a/src/dtmffifo.h b/src/dtmffifo.h
new file mode 100644
index 0000000..39e39c9
--- /dev/null
+++ b/src/dtmffifo.h
@@ -0,0 +1,13 @@
+#ifndef foodtmffifohfoo
+#define foodtmffifohfoo
+
+struct dtmf_fifo {
+ int fd;
+ char *dir, *fname;
+};
+
+struct dtmf_fifo* dtmf_fifo_new(void);
+void dtmf_fifo_free(struct dtmf_fifo *d);
+void dtmf_fifo_pass(struct dtmf_fifo *d, char c);
+
+#endif