summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-02-09 18:03:45 +0000
committerLennart Poettering <lennart@poettering.net>2004-02-09 18:03:45 +0000
commite36910ad6e13c82ab6b1d1206241c676ab3265ba (patch)
treed174a71895f5933dbf55f48f27b2ff9227569fc6 /src
parent299552c0ffc90d69b0593eecdc19fc859d445cbd (diff)
add patches bei Wolfgang Ocker
git-svn-id: file:///home/lennart/svn/public/ivam2/trunk@61 dbf6933d-3bce-0310-9bcc-ed052ba35b35
Diffstat (limited to 'src')
-rw-r--r--src/modem.c9
-rw-r--r--src/msntab.c227
-rw-r--r--src/msntab.h3
3 files changed, 229 insertions, 10 deletions
diff --git a/src/modem.c b/src/modem.c
index f98079a..3a3f656 100644
--- a/src/modem.c
+++ b/src/modem.c
@@ -73,8 +73,7 @@
#define INPUT_RANGE_CHILD 64
#define OUTPUT_RANGE_CHILD 1024
-#define INIT_AT_COMMANDS 16
-static const char* const init_at_commands[INIT_AT_COMMANDS*2] = {
+static const char* const init_at_commands[] = {
"\nAT&F\n", /* Reset to fabric defaults */
"OK\r\n",
@@ -108,7 +107,7 @@ static const char* const init_at_commands[INIT_AT_COMMANDS*2] = {
"ATS23=1\n",
"OK\r\n",
- "ATS16=1\n", /* send packet size */
+ "ATS16=4\n", /* send packet size (set to 4 instead of 1 to avoid a play distortion with a B1) */
"OK\r\n",
"AT\n", //S12.3=0\n", /* DCD always on */
@@ -124,6 +123,8 @@ static const char* const init_at_commands[INIT_AT_COMMANDS*2] = {
"OK\r\n",
};
+#define INIT_AT_COMMANDS ((sizeof(init_at_commands)/sizeof(init_at_commands[0]))/2)
+
static const char hup_sequence[] = { DLE, DC4, DLE, ETX, 0 };
static const char ath_sequence[] = "\nATH\n";
@@ -251,7 +252,7 @@ static void modem_next_command(struct modem *m) {
if (m->command_index == 0)
buffio_command(m->buffio, hup_sequence);
- else if (m->command_index == 15) {
+ else if (!strncmp(p, "AT&L", 4)) {
char *l = m->listen_msn ? m->listen_msn : "*";
daemon_log(LOG_INFO, "[%s] Listening on '%s'.", m->name, l);
snprintf(tmp, sizeof(tmp), p, l);
diff --git a/src/msntab.c b/src/msntab.c
index 12002d5..446971c 100644
--- a/src/msntab.c
+++ b/src/msntab.c
@@ -30,6 +30,8 @@
#include <stdio.h>
#include <unistd.h>
#include <regex.h>
+#include <time.h>
+#include <ctype.h>
#include <libdaemon/dlog.h>
@@ -82,12 +84,196 @@ int glob_match(const char *e, const char *s) {
}
}
+
+/*
+**
+** The functions make_time, time_match, and day_match have
+** been borrowed from the file rcvbox.c of vbox.
+**
+** Original Copyright:
+**
+** Copyright (C) 1996, 1997 Michael 'Ghandi' Herold
+*/
+
+static time_t make_time(time_t timenow, char *timestr, int mode)
+{
+ struct tm *locala;
+ struct tm localb;
+
+ char timestring[5 + 1];
+ char *hourstr, *minsstr;
+ int hourint, minsint, secsint;
+
+ strncpy(timestring, timestr, 5);
+
+ hourstr = timestring;
+ minsstr = index(hourstr, ':');
+
+ if (!minsstr) {
+ if (!mode)
+ minsstr = "00";
+ else
+ minsstr = "59";
+ }
+ else
+ *minsstr++ = '\0';
+
+ if (!mode)
+ secsint = 0;
+ else
+ secsint = 59;
+
+ hourint = atoi(hourstr);
+ minsint = atoi(minsstr);
+
+ if (hourint < 0 || hourint > 23)
+ return 0;
+ if (minsint < 0 || minsint > 59)
+ return 0;
+
+ locala = localtime(&timenow);
+ if (!locala)
+ return 0;
+
+ localb = *locala;
+
+ localb.tm_sec = secsint;
+ localb.tm_min = minsint;
+ localb.tm_hour = hourint;
+
+ return mktime(&localb);
+}
+
+int time_match(char *timestr)
+{
+ char *timestring;
+ char *timeptr;
+ char *timenxt;
+ char *timebeg, *timeend;
+ time_t timenow;
+ time_t timesecsbeg, timesecsend;
+ int res = 0;
+
+ timestring = strdup(timestr);
+ assert(timestring);
+
+ timeptr = timestring;
+ timenow = time(NULL);
+
+ if (!strcmp(timestring, "*")) {
+ res = 1;
+ goto out;
+ }
+
+ if (!strcmp(timestring, "!") || !strcmp(timestring, "-"))
+ goto out;
+
+ while (timeptr) {
+ timenxt = index(timeptr, ',');
+ if (timenxt)
+ *timenxt++ = '\0';
+
+ timebeg = timeptr;
+ timeend = index(timebeg, '-');
+
+ if (timeend)
+ *timeend++ = '\0';
+ else
+ timeend = timebeg;
+
+ if (!timeend)
+ timeend = timebeg;
+
+ timesecsbeg = make_time(timenow, timebeg, 0);
+ timesecsend = make_time(timenow, timeend, 1);
+
+ if (timesecsbeg < 0 || timesecsend < timesecsbeg)
+ daemon_log(LOG_WARNING, "End time less then begin time in timestring %s", timestr);
+ else if (timenow >= timesecsbeg && timenow <= timesecsend) {
+ res = 1;
+ goto out;
+ }
+
+ timeptr = timenxt;
+ }
+
+out:
+ if (timestring)
+ free(timestring);
+
+ return res;
+}
+
+int day_match(char *strdays)
+{
+ static char *weekdaynames[] = {
+ "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT",
+ "WEEKEND", "WORK", "WORK", "WORK", "WORK", "WORK", "WEEKEND",
+ NULL
+ };
+
+ struct tm *timelocal;
+ char *beg, *nxt;
+ char *days;
+ int i;
+ time_t timenow;
+ int res = 0;
+
+ days = strdup(strdays);
+ assert(days);
+
+ if (!strcmp(days, "*")) {
+ res = 1;
+ goto out;
+ }
+
+ if (!strcmp(days, "-") || !strcmp(days, "!") )
+ goto out;
+
+ timenow = time(NULL);
+
+ timelocal = localtime(&timenow);
+ if (!timelocal)
+ goto out;
+
+ for (i = 0; i < strlen(days); i++) {
+ if (!isalpha(days[i]) && days[i] != ',') {
+ daemon_log(LOG_WARNING, "Error in daystring %s", strdays);
+ goto out;
+ }
+ }
+
+ beg = days;
+
+ while (beg) {
+ nxt = index(beg, ',');
+ if (nxt)
+ *nxt++ = 0;
+
+ for (i = 0; weekdaynames[i]; i++) {
+ if (!strcasecmp(weekdaynames[i], beg) && (i%7) == timelocal->tm_wday) {
+ res = 1;
+ goto out;
+ }
+ }
+
+ beg = nxt;
+ }
+
+out:
+ if (days)
+ free(days);
+
+ return res;
+}
+
+
struct tabentry* msntab_check_call(const char *callee, const char *caller) {
struct tabentry *l = first;
while (l) {
- int a, b;
- assert(l->local && l->remote);
+ int a, b, c, d;
+ assert(l->local && l->remote && l->dayspec && l->timespec);
if (l->local[0] == '~')
a = !regex_match(l->local+1, callee);
@@ -99,8 +285,11 @@ struct tabentry* msntab_check_call(const char *callee, const char *caller) {
b = !regex_match(l->remote+1, caller);
else
b = !glob_match(l->remote, caller);
-
- if (a && b) {
+
+ c = day_match(l->dayspec);
+ d = time_match(l->timespec);
+
+ if (a && b && c && d) {
daemon_log(LOG_INFO, "MSN table entry from '%s:%u' matched.", l->filename, l->line);
return msntab_ref(l);
}
@@ -135,6 +324,8 @@ void msntab_unref(struct tabentry *t) {
free(t->local);
free(t->remote);
+ free(t->dayspec);
+ free(t->timespec);
free(t->filename);
free(t);
@@ -222,7 +413,7 @@ int msntab_load(const char *fn) {
n = 0;
while (!feof(f)) {
- char l[256], *c, *e, *local, *remote, *options, *action;
+ char l[256], *c, *e, *local, *remote, *dayspec, *timespec, *options, *action;
n++;
@@ -274,6 +465,22 @@ int msntab_load(const char *fn) {
if (c)
c+=strspn(c, " \t");
+ if (!(dayspec = strsep(&c, " \t"))) {
+ daemon_log(LOG_ERR, "Parse failure on dayspec field in '%s:%i'.", fn, n);
+ goto fail;
+ }
+
+ if (c)
+ c+=strspn(c, " \t");
+
+ if (!(timespec = strsep(&c, " \t"))) {
+ daemon_log(LOG_ERR, "Parse failure on timespec field in '%s:%i'.", fn, n);
+ goto fail;
+ }
+
+ if (c)
+ c+=strspn(c, " \t");
+
if (!(options = strsep(&c, " \t"))) {
daemon_log(LOG_ERR, "Parse failure on options field in '%s:%i'.", fn, n);
goto fail;
@@ -302,6 +509,12 @@ int msntab_load(const char *fn) {
t->remote = strdup(remote);
assert(t->remote);
+ t->dayspec = strdup(dayspec);
+ assert(t->dayspec);
+
+ t->timespec = strdup(timespec);
+ assert(t->timespec);
+
if (action[0] == '@') {
if (!strcmp(action, "@hangup"))
t->action = CALL_ACTION_HANGUP;
@@ -372,11 +585,13 @@ static void dump_entry(struct tabentry *t) {
} else
strncpy(s, "NOARGS", sizeof(s));
- daemon_log(LOG_INFO, "[%s:%02u] %-12s -> %-12s; shbuf=%c; pipehack=%c; rings=%u; action=%s; args=<%s>",
+ daemon_log(LOG_INFO, "[%s:%02u] %-12s -> %-12s; %s %s; shbuf=%c; pipehack=%c; rings=%u; action=%s; args=<%s>",
t->filename,
t->line,
t->local,
t->remote,
+ t->dayspec,
+ t->timespec,
t->shbuf ? 'y' : 'n',
t->pipehack ? 'y' : 'n',
t->rings,
diff --git a/src/msntab.h b/src/msntab.h
index 2a09f2a..fd6acc8 100644
--- a/src/msntab.h
+++ b/src/msntab.h
@@ -31,6 +31,9 @@ struct tabentry {
char *local;
char *remote;
+ char *timespec;
+ char *dayspec;
+
struct tabentry *next;
struct tabentry *prev;