1 /* -------------------------------------------------------------------- */
2 /* SMS Client, send messages to mobile phones and pagers */
3 /* */
4 /* skeleton.c */
5 /* */
6 /* Copyright (C) 1998,1999 Angelo Masci */
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 /* angelo@styx.demon.co.uk */
25 /* */
26 /* -------------------------------------------------------------------- */
27 /* $Id$
28 -------------------------------------------------------------------- */
29
30 #include <stdio.h>
31 #include <string.h>
32
33 #include "common/common.h"
34 #include "logfile/logfile.h"
35 #include "driver.h"
36 #include "error.h"
37 #include "comms/comms.h"
38 #include "resource/resource.h"
39
40 /* -------------------------------------------------------------------- */
41
42 static char ACK1[] = "Welecome to Skeleton Server\r\n";
43 static char ACK2[] = "Enter you number\r\n";
44 static char ACK3[] = "Enter you message\r\n";
45 static char ACK4[] = "Thank You.\r\n";
46
47 /* -------------------------------------------------------------------- */
48 /* The 'env' structure contains Service level data to be used for */
49 /* sending a message. */
50 /* -------------------------------------------------------------------- */
51
52 static struct skeleton_env
53 {
54 DRIVER_DEFAULT_ENV def;
55
56 /* Place any extended driver */
57 /* variables here */
58
59 } driver_env;
60
61 /* -------------------------------------------------------------------- */
62
63 static RESOURCE resource_list[] =
64 {
65 { RESOURCE_STRING, "SMS_comms_params", 0, 1, NULL, 0, "8N1", 0, &(driver_env.def.comms_params) },
66 { RESOURCE_STRING, "SMS_centre_number", 0, 1, NULL, 0, NULL, 0, &(driver_env.def.centre_number) },
67 { RESOURCE_NUMERIC, "SMS_baud", 0, 1, NULL, 0, NULL, 1200, &(driver_env.def.baud) },
68 { RESOURCE_NUMERIC, "SMS_deliver_timeout", 0, 0, NULL, 0, NULL, 30, &(driver_env.def.deliver_timeout) },
69 { RESOURCE_NUMERIC, "SMS_timeout", 0, 0, NULL, 0, NULL, 10, &(driver_env.def.timeout) },
70 { RESOURCE_NUMERIC, "SMS_write_timeout", 0, 0, NULL, 0, NULL, 10, &(driver_env.def.write_timeout) },
71 { RESOURCE_NUMERIC, "SMS_max_deliver", 0, 0, NULL, 0, NULL, 0, &(driver_env.def.max_deliver) },
72 { RESOURCE_NULL, NULL, 0, 1, NULL, 0, NULL, 0, NULL }
73 };
74
75 /* -------------------------------------------------------------------- */
76
77 #define DELIVERTIMEOUT (driver_env.def.deliver_timeout)
78 #define TIMEOUT (driver_env.def.timeout)
79 #define WRITETIMEOUT (driver_env.def.write_timeout)
80
81 /* -------------------------------------------------------------------- */
82
83 #define FD (driver_env.def.fd)
84
85 /* -------------------------------------------------------------------- */
86 /* The following defines are used to signify errors */
87 /* occuring during the dialogue between the driver and the */
88 /* service centre. This number will be returned as the delivery */
89 /* value for the message that was aborted */
90 /* */
91 /* The defines MUST be placed in 'error.h' */
92
93 #define ESKELETON_NONUMBER 250
94 #define ESKELETON_NOMESSAGE 251
95 #define ESKELETON_NODELIVERY 252
96
97 /* -------------------------------------------------------------------- */
98
99 static void SKELETON_hangup(void);
100 static int SKELETON_sendmessage(char *msisdn, char *message);
101
102 /* -------------------------------------------------------------------- */
103 /* -------------------------------------------------------------------- */
SKELETON_hangup(void)104 static void SKELETON_hangup(void)
105 { default_hangup((DRIVER_DEFAULT_ENV *)(&driver_env));
106 }
107
108 /* -------------------------------------------------------------------- */
109 /* -------------------------------------------------------------------- */
SKELETON_sendmessage(char * msisdn,char * message)110 static int SKELETON_sendmessage(char *msisdn, char *message)
111 {
112 char buf[MAX_RESPONSE_BUFSIZE];
113
114
115 if (expstr(FD, buf, ACK2, MAX_RESPONSE_BUFSIZE, TIMEOUT) == 0)
116 {
117 lprintf(LOG_STANDARD, "Received Number Request\n");
118 }
119 else
120 { lprintf(LOG_STANDARD, "No Number Request\n");
121
122 SKELETON_hangup();
123 return ESKELETON_NONUMBER;
124 }
125
126
127 twrite(FD, msisdn, strlen(msisdn), WRITETIMEOUT);
128 twrite(FD, "\r\n", strlen("\r\n"), WRITETIMEOUT);
129
130 if (expstr(FD, buf, ACK3, MAX_RESPONSE_BUFSIZE, TIMEOUT) == 0)
131 {
132 lprintf(LOG_STANDARD, "Received Message Request\n");
133 }
134 else
135 { lprintf(LOG_STANDARD, "No Message Request\n");
136
137 SKELETON_hangup();
138 return ESKELETON_NOMESSAGE;
139 }
140
141
142 twrite(FD, message, strlen(message), WRITETIMEOUT);
143 twrite(FD, "\r\n", strlen("\r\n"), WRITETIMEOUT);
144
145 if (expstr(FD, buf, ACK4, MAX_RESPONSE_BUFSIZE, DELIVERTIMEOUT) == 0)
146 {
147 lprintf(LOG_STANDARD, "Received Message Delivery Response\n");
148 }
149 else
150 { lprintf(LOG_STANDARD, "No Message Delivery Response\n");
151
152 SKELETON_hangup();
153 return ESKELETON_NODELIVERY;
154 }
155
156 return 0;
157 }
158
159 /* -------------------------------------------------------------------- */
160 /* The following structure is used by core driver code. */
161 /* The diagram below shows the call sequence of the functions. */
162 /* -------------------------------------------------------------------- */
163 DEVICE_ENTRY skeleton_device = {
164
165 "SKELETON",
166 "1.0",
167 resource_list,
168 (DRIVER_DEFAULT_ENV *)(&driver_env),
169
170 default_init, /* Init */
171 default_main, /* Main */
172 default_validate_numeric_id, /* Validation */
173 default_dial, /* Dial */
174 default_hangup, /* Hangup */
175 default_send_disconnect, /* Disconnect */
176 default_single_deliver, /* Deliver */
177 SKELETON_sendmessage, /* Send */
178 default_login /* Login */
179 };
180
181 /* -------------------------------------------------------------------- */
182 /* */
183 /* ---------- */
184 /* | Main | */
185 /* ----+----- */
186 /* | */
187 /* | */
188 /* | For Each Addressed Message */
189 /* -----+----- */
190 /* | Deliver | */
191 /* -----+----- */
192 /* | */
193 /* +----+------+----------+-------------+--------------+ */
194 /* | | | | | */
195 /* ---+---- ----+---- ---+---- ------+------- ----+----- */
196 /* | Dial | | Login | | Send | | Disconnect | | Hangup | */
197 /* -------- --------- -------- -------------- ---------- */
198 /* */
199 /* */
200 /* Note. Your driver can supply functions to be used in place of */
201 /* all the default_driver functions. */
202 /* */
203 /* -------------------------------------------------------------------- */
204
205