1 /* -------------------------------------------------------------------- */
2 /* SMS Client, send messages to mobile phones and pagers */
3 /* */
4 /* cellnet_web.c */
5 /* */
6 /* Copyright (C) 1997,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 <stdlib.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 "comms/http.h"
40 #include "resource/resource.h"
41
42 /* -------------------------------------------------------------------- */
43
44 static struct cellnet_web_env
45 {
46 DRIVER_DEFAULT_ENV def;
47
48 /* Place any extended driver */
49 /* variables here */
50
51 char *url,
52 *username,
53 *password;
54
55 } driver_env;
56
57 /* -------------------------------------------------------------------- */
58
59 static RESOURCE resource_list[] =
60 {
61 { RESOURCE_STRING, "SMS_comms_params", 0, 1, NULL, 0, "8N1", 0, &(driver_env.def.comms_params) },
62 { RESOURCE_STRING, "SMS_centre_number", 0, 1, NULL, 0, NULL, 0, &(driver_env.def.centre_number) },
63 { RESOURCE_NUMERIC, "SMS_baud", 0, 1, NULL, 0, NULL, 9600, &(driver_env.def.baud) },
64 { RESOURCE_NUMERIC, "SMS_deliver_timeout", 0, 0, NULL, 0, NULL, 30, &(driver_env.def.deliver_timeout) },
65 { RESOURCE_NUMERIC, "SMS_timeout", 0, 0, NULL, 0, NULL, 10, &(driver_env.def.timeout) },
66 { RESOURCE_NUMERIC, "SMS_write_timeout", 0, 0, NULL, 0, NULL, 10, &(driver_env.def.write_timeout) },
67 { RESOURCE_NUMERIC, "SMS_max_deliver", 0, 0, NULL, 0, NULL, 3, &(driver_env.def.max_deliver) },
68
69 { RESOURCE_STRING, "SMS_url", 0, 1, NULL, 0, "http://www.genie.co.uk/gmail_mdl/externalsend.hnspl", 0, &(driver_env.url) },
70 { RESOURCE_STRING, "SMS_username", 0, 1, NULL, 0, "", 0, &(driver_env.username) },
71 { RESOURCE_STRING, "SMS_password", 0, 1, NULL, 0, "", 0, &(driver_env.password) },
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
87 static int CELLNET_WEB_dial(DRIVER_DEFAULT_ENV *env);
88 static int CELLNET_WEB_sendmessage(char *msisdn, char *message);
89 static void CELLNET_WEB_hangup(DRIVER_DEFAULT_ENV *env);
90
91 /* -------------------------------------------------------------------- */
92 /* -------------------------------------------------------------------- */
CELLNET_WEB_dial(DRIVER_DEFAULT_ENV * env)93 static int CELLNET_WEB_dial(DRIVER_DEFAULT_ENV *env)
94 {
95 return 0;
96 }
97
98 /* -------------------------------------------------------------------- */
99 /* -------------------------------------------------------------------- */
CELLNET_WEB_sendmessage(char * msisdn,char * message)100 static int CELLNET_WEB_sendmessage(char *msisdn, char *message)
101 {
102 char *escaped_message,
103 data[1024],
104 *document;
105
106 int document_len;
107
108
109 escaped_message = escape_input(message);
110 if (escaped_message == NULL)
111 {
112 exit(-1);
113 }
114
115 sms_snprintf(data, 1024, "ac=guest&username=%s&password=%s&TO=%s"
116 "&MSG_MESSAGE=%s&submit=Send&count=1",
117 driver_env.username,
118 driver_env.password,
119 msisdn,
120 escaped_message);
121
122 free(escaped_message);
123
124
125
126 document = get_document(driver_env.url, &document_len, "POST", data, NULL, NULL);
127 if (document != NULL)
128 {
129 lprintf(LOG_VERYVERBOSE, "%s\n", document);
130
131 if (strstr(document, "has been queued") != NULL)
132 {
133 lprintf(LOG_STANDARD, "Your message has been successfully queued for transmission\n");
134 }
135 else
136 if (strstr(document, "couldn't send your message") != NULL)
137 {
138 lprintf(LOG_ERROR, "Trying to Deliver message - Genie didn't like your submission\n");
139
140 free(document);
141 return -1;
142 }
143 else
144 { lprintf(LOG_ERROR, "Trying to Deliver message - Unexpected response\n");
145
146 free(document);
147 return -1;
148 }
149
150 free(document);
151 }
152 else
153 { lprintf(LOG_ERROR, "Trying to Deliver message - Failed to connect\n");
154 return -1;
155 }
156
157 return 0;
158 }
159
160 /* -------------------------------------------------------------------- */
161 /* -------------------------------------------------------------------- */
CELLNET_WEB_hangup(DRIVER_DEFAULT_ENV * env)162 static void CELLNET_WEB_hangup(DRIVER_DEFAULT_ENV *env)
163 {
164 }
165
166 /* -------------------------------------------------------------------- */
167 /* -------------------------------------------------------------------- */
168 DEVICE_ENTRY cellnet_web_device = {
169
170 "CELLNET_WEB",
171 "1.2",
172 resource_list,
173 (DRIVER_DEFAULT_ENV *)(&driver_env),
174
175 default_init,
176 default_main,
177 default_validate_numeric_id,
178 CELLNET_WEB_dial,
179 CELLNET_WEB_hangup,
180 default_send_disconnect,
181 default_single_deliver,
182 CELLNET_WEB_sendmessage,
183 default_login
184 };
185
186
187
188