1 /* -------------------------------------------------------------------- */
2 /* SMS Client, send messages to mobile phones and pagers */
3 /* */
4 /* libertel.c */
5 /* */
6 /* Copyright (C) 1998,1999 Aart Koelewijn */
7 /* */
8 /* This library is free software; you can redistribute it and/or */
9 /* modify it under the terms of the GNU Library General Public */
10 /* License as published by the Free Software Foundation; either */
11 /* version 2 of the License, or (at your option) any later version. */
12 /* */
13 /* This library is distributed in the hope that it will be useful, */
14 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
16 /* Library General Public License for more details. */
17 /* */
18 /* You should have received a copy of the GNU Library General Public */
19 /* License along with this library; if not, write to the Free */
20 /* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* */
22 /* You can contact the author at this e-mail address: */
23 /* */
24 /* jhwevers@telekabel.nl */
25 /* aart@mtack.xs4all.nl */
26 /* */
27 /* -------------------------------------------------------------------- */
28 /* $Id: libertel.c,v 0.1 1998/04/02 22:49:15 aart
29 -------------------------------------------------------------------- */
30
31 #include <stdio.h>
32 #include <string.h>
33
34 #include "common/common.h"
35 #include "logfile/logfile.h"
36 #include "driver.h"
37 #include "error.h"
38 #include "comms/comms.h"
39 #include "resource/resource.h"
40
41 /* -------------------------------------------------------------------- */
42
43 static char ACK1[] = "Welkom bij LIBERTEL Text-PC\r\n"
44 "Als u vragen heeft over deze dienst kunt u bellen naar 0800-0560\r\n";
45 static char ACK2[] = "Typ het mobiele telefoonnummer in volgens het internationale formaat, \r\n"
46 "bijvoorbeeld 31654XXXXXX, gevolgd door enter (of druk op enter om te stoppen)\r\n"
47 ">";
48
49 static char ACK3[] = "Typ uw bericht in, (maximaal 160 tekens), gevolgd door enter\r\n"
50 ">";
51
52 static char ACK4[] = "Bericht geaccepteerd\r\n";
53
54 /* -------------------------------------------------------------------- */
55
56 static struct libertel_env
57 {
58 DRIVER_DEFAULT_ENV def;
59
60 /* Place any extended driver */
61 /* variables here */
62
63 } driver_env;
64
65 /* -------------------------------------------------------------------- */
66
67 static RESOURCE resource_list[] =
68 {
69 { RESOURCE_STRING, "SMS_comms_params", 0, 1, NULL, 0, "8N1", 0, &(driver_env.def.comms_params) },
70 { RESOURCE_STRING, "SMS_centre_number", 0, 1, NULL, 0, NULL, 0, &(driver_env.def.centre_number) },
71 { RESOURCE_NUMERIC, "SMS_baud", 0, 1, NULL, 0, NULL, 1200, &(driver_env.def.baud) },
72 { RESOURCE_NUMERIC, "SMS_deliver_timeout", 0, 0, NULL, 0, NULL, 30, &(driver_env.def.deliver_timeout) },
73 { RESOURCE_NUMERIC, "SMS_timeout", 0, 0, NULL, 0, NULL, 10, &(driver_env.def.timeout) },
74 { RESOURCE_NUMERIC, "SMS_write_timeout", 0, 0, NULL, 0, NULL, 10, &(driver_env.def.write_timeout) },
75 { RESOURCE_NUMERIC, "SMS_max_deliver", 0, 0, NULL, 0, NULL, 0, &(driver_env.def.max_deliver) },
76 { RESOURCE_NULL, NULL, 0, 1, NULL, 0, NULL, 0, NULL }
77 };
78
79 /* -------------------------------------------------------------------- */
80
81 #define DELIVERTIMEOUT (driver_env.def.deliver_timeout)
82 #define TIMEOUT (driver_env.def.timeout)
83 #define WRITETIMEOUT (driver_env.def.write_timeout)
84
85 /* -------------------------------------------------------------------- */
86
87 #define FD (driver_env.def.fd)
88
89 /* -------------------------------------------------------------------- */
90
91 static void LIBERTEL_hangup(void);
92 static int LIBERTEL_sendmessage(char *msisdn, char *message);
93 static int LIBERTEL_login(void);
94 static int LIBERTEL_send_disconnect(void);
95
96 /* -------------------------------------------------------------------- */
97 /* -------------------------------------------------------------------- */
LIBERTEL_hangup(void)98 static void LIBERTEL_hangup(void)
99 { default_hangup((DRIVER_DEFAULT_ENV *)(&driver_env));
100 }
101
102
103 /* -------------------------------------------------------------------- */
104 /* -------------------------------------------------------------------- */
LIBERTEL_login(void)105 static int LIBERTEL_login(void)
106 {
107 char buf[MAX_RESPONSE_BUFSIZE];
108
109 if (expstr(FD, buf, ACK1, MAX_RESPONSE_BUFSIZE, TIMEOUT) == 0)
110 {
111 lprintf(LOG_STANDARD, "Libertel Service Login\n");
112 }
113 else
114 { lprintf(LOG_STANDARD, "No Libertel Service Response\n");
115
116 LIBERTEL_hangup();
117 return ELIBERTEL_NORESPONSE;
118 }
119
120 return 0;
121 }
122
123
124 /* -------------------------------------------------------------------- */
125 /* -------------------------------------------------------------------- */
LIBERTEL_send_disconnect(void)126 static int LIBERTEL_send_disconnect(void)
127 {
128 twrite(FD, "\r\n", strlen("\r\n"), TIMEOUT);
129 return 0;
130 }
131
132 /* -------------------------------------------------------------------- */
133 /* -------------------------------------------------------------------- */
LIBERTEL_sendmessage(char * msisdn,char * message)134 static int LIBERTEL_sendmessage(char *msisdn, char *message)
135 {
136 char buf[MAX_RESPONSE_BUFSIZE];
137
138 if (expstr(FD, buf, ACK2, MAX_RESPONSE_BUFSIZE, TIMEOUT) == 0)
139 {
140 lprintf(LOG_STANDARD, "Received Number Request\n");
141 }
142 else
143 { lprintf(LOG_STANDARD, "No Number Request\n");
144
145 LIBERTEL_hangup();
146 return ELIBERTEL_NONUMBER;
147 }
148
149
150 twrite(FD, msisdn, strlen(msisdn), WRITETIMEOUT);
151 twrite(FD, "\r\n", strlen("\r\n"), WRITETIMEOUT);
152
153 if (expstr(FD, buf, ACK3, MAX_RESPONSE_BUFSIZE, TIMEOUT) == 0)
154 {
155 lprintf(LOG_STANDARD, "Received Message Request\n");
156 }
157 else
158 { lprintf(LOG_STANDARD, "No Message Request\n");
159
160 LIBERTEL_hangup();
161 return ELIBERTEL_NOMESSAGE;
162 }
163
164
165 twrite(FD, message, strlen(message), WRITETIMEOUT);
166 twrite(FD, "\r\n", strlen("\r\n"), WRITETIMEOUT);
167
168 if (expstr(FD, buf, ACK4, MAX_RESPONSE_BUFSIZE, DELIVERTIMEOUT) == 0)
169 {
170 lprintf(LOG_STANDARD, "Received Message Delivery Response\n");
171 }
172 else
173 { lprintf(LOG_STANDARD, "No Message Delivery Response\n");
174
175 LIBERTEL_hangup();
176 return ELIBERTEL_NODELIVERY;
177 }
178
179 return 0;
180 }
181
182 /* -------------------------------------------------------------------- */
183 /* -------------------------------------------------------------------- */
184 DEVICE_ENTRY libertel_device = {
185
186 "LIBERTEL",
187 "1.0",
188 resource_list,
189 (DRIVER_DEFAULT_ENV *)(&driver_env),
190
191 default_init,
192 default_main,
193 default_validate_numeric_id,
194 default_dial,
195 default_hangup,
196 LIBERTEL_send_disconnect,
197 default_multiple_counted_deliver,
198 LIBERTEL_sendmessage,
199 LIBERTEL_login
200 };
201
202