File: ian.c

package info (click to toggle)
xtel 3.3.0-9
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 1,936 kB
  • ctags: 1,677
  • sloc: ansic: 15,677; sh: 225; makefile: 65
file content (138 lines) | stat: -rw-r--r-- 3,826 bytes parent folder | download | duplicates (15)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*	
 *   xtel - Emulateur MINITEL sous X11
 *
 *   Copyright (C) 1991-1996  Lectra Systemes & Pierre Ficheux
 *
 *   This program 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.
 *
 *   This program 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 this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
static char rcsid[] = "$Id: ian.c,v 1.2 1998/10/02 15:03:46 pierre Exp $";

/*
 * Support IAN (Eric Delaunay, delaunay@lix.polytechnique.fr)
 */
#include <stdio.h>
#include "demon.h"
#include "globald.h"

struct ian {
	char *service;	/* numro de tlphone du service */
	char *garde;	/* code mis avant la page de garde Teletel */
	char *entree1;	/* code mis lors de l'entre dans le service */
	char *entree2;	/* autre possibilit */
};

static struct ian IAN[] = {
	{ "3612",	"\033  0",	"\033!\001\0010",	"\033\"0" },
	{ "3613", 	"\033 !0",	"\033!\001\0010",	"\033\"0" },
	{ "3614",	"\033 \"0",	"\033!\001\0010",	"\033\"0" },
	{ "3615", 	"\033 #0",	"\033!\001\0010",	"\033\"0" },
	{ "3616",	"\033 $0",	"\033!\001\0010",	"\033\"0" },
	{ "3617",	"\033 %0",	"\033!\001\0010",	"\033\"0" },
	{ "3618",	"\033 &0",	"\033!\001\0010",	"\033\"0" },
	{ "3619",	"\033 '0",	"\033!\001\0010",	"\033\"0" },
	{ "3621",	"service:\021",	"tablie",		"LIB"     }
};

static int ian_courant;
static char *ian_ptr1, *ian_ptr2;
int ian_n1, ian_n2;

/*
 * initialise la dtction des IAN
 */
void ian_init( telno )
    char *telno;
{
    int i;

    ian_courant = -1;
    for( i = 0 ; i < sizeof(IAN)/sizeof(IAN[0]) ; i++ ) {
	if (!strcmp( IAN[i].service, telno )) {
	    ian_courant = i;
	    ian_ptr1 = ian_ptr2 = NULL;
#ifdef DEBUG_XTELD
	    log_debug( "Prt pour dtection des IAN (service %s)", IAN[i].service );
#endif
	    break;
	}
    }
#ifdef DEBUG_XTELD
    if (ian_courant < 0)
	log_debug( "IAN non dtermin pour le numro : %s", telno );
#endif
}

/*
 * dtection des IAN
 */
int ian_valide( type_ian, c )
    int type_ian;
    char c;
{
    if (ian_courant < 0)
	return 1;
    if (!ian_ptr1) {
	switch (type_ian) {
	case IAN_DE_GARDE:
	case IAN_DE_FIN:
#ifdef DEBUG_XTELD
	    log_debug( "attente IAN de garde [%d]", IAN_DE_GARDE );
#endif
	    ian_ptr1 = IAN[ian_courant].garde;
	    ian_n1 = 0;
	    ian_ptr2 = NULL;
	    ian_n2 = 0;
	    break;
	case IAN_D_ENTREE:
#ifdef DEBUG_XTELD
	    log_debug( "attente IAN d'entre [%d]", IAN_D_ENTREE );
#endif
	    ian_ptr1 = IAN[ian_courant].entree1;
	    ian_n1 = 0;
	    ian_ptr2 = IAN[ian_courant].entree2;
	    ian_n2 = 0;
	    break;
	default:
	    log_err ("attente IAN inconnu !");
	    return 1;	/* retourne IAN valide pour dconnecter le modem */
	}
    }
    if (ian_ptr1[ian_n1] == c || ian_ptr1[ian_n1] == '\001') {
	if (ian_ptr1[++ian_n1] == 0) {
#ifdef DEBUG_XTELD
	    log_debug( "IAN ptr1 reu" );
#endif
	    ian_ptr1 = ian_ptr2 = NULL;
	    return 1;		/* IAN dtect */
	}
    }
    else
	ian_n1 = 0;		/* caractre faux : on recommence au dbut de la chane */
    if (ian_ptr2) {
	if (ian_ptr2[ian_n2] == c || ian_ptr2[ian_n2] == '\001') {
	    if (ian_ptr2[++ian_n2] == 0) {
#ifdef DEBUG_XTELD
		log_debug( "IAN ptr1 reu" );
#endif
		ian_ptr1 = ian_ptr2 = NULL;
		return 2;	/* IAN dtect */
	    }
	}
	else
	    ian_n2 = 0;		/* caractre faux : on recommence au dbut de la chane */
    }
    return 0;	/* IAN pas trouv */
}