Kannel: Open Source WAP and SMS gateway  svn-r5335
smscconn_p.h
Go to the documentation of this file.
1 /* ====================================================================
2  * The Kannel Software License, Version 1.0
3  *
4  * Copyright (c) 2001-2018 Kannel Group
5  * Copyright (c) 1998-2001 WapIT Ltd.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Kannel Group (http://www.kannel.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Kannel" and "Kannel Group" must not be used to
28  * endorse or promote products derived from this software without
29  * prior written permission. For written permission, please
30  * contact org@kannel.org.
31  *
32  * 5. Products derived from this software may not be called "Kannel",
33  * nor may "Kannel" appear in their name, without prior written
34  * permission of the Kannel Group.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS
40  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
41  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
42  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
44  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
45  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
46  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Kannel Group. For more information on
51  * the Kannel Group, please see <http://www.kannel.org/>.
52  *
53  * Portions of this software are based upon software originally written at
54  * WapIT Ltd., Helsinki, Finland for the Kannel project.
55  */
56 
57 #ifndef SMSCCONN_P_H
58 #define SMSCCONN_P_H
59 
60 /* SMSC Connection private header
61  *
62  * Defines internal private structure
63  *
64  * Kalle Marjola 2000 for project Kannel
65  *
66 
67  ADDING AND WORKING OF NEW SMS CENTER CONNECTIONS:
68 
69  These are guidelines and rules for adding new SMSC Connections to
70  Kannel. See file bb_smscconn_cb.h for callback function prototypes.
71 
72  An SMSC Connection handler is free-formed module which only has the following
73  rules:
74 
75  1) Each new SMSC Connection MUST implement function
76  smsc_xxx_create(SMSCConn *conn, CfgGrp *cfg), which:
77 
78  a) SHOULD NOT block (XXX)
79  b) MUST warn about any configuration group variables it does
80  not support (XXX)
81  c) MUST set up send_msg dynamic function to handle messages
82  to-be-sent. This function MAY NOT block. This function MAY
83  NOT destroy or alter the supplied message, but instead copy
84  it if need to be stored
85  d) CAN set up private shutdown function, which MAY NOT block
86  e) SHOULD set private function to return number of queued messages
87  to-be-sent inside the driver
88  f) MUST set SMSCConn->name
89 
90  2) Each SMSC Connection MUST call certain BB callback functions when
91  certain things occur:
92 
93  a) Each SMSC Connection MUST call callback function
94  bb_smscconn_killed when it dies because it was put down earlier
95  with bb_smscconn_shutdown or it simply cannot keep the connection
96  up (wrong password etc. When killed,
97  SMSC Connection MUST release all memory it has taken EXCEPT for
98  the basic SMSCConn struct, which is laterwards released by the
99  bearerbox.
100 
101  b) When SMSC Connection receives a message from SMSC, it must
102  create a new Msg from it and call bb_smscconn_received
103 
104  c) When SMSC Connection has sent a message to SMSC, it MUST call
105  callback function bb_smscconn_sent. The msg-parameter must be
106  identical to msg supplied with smscconn_send, but it can be
107  a duplicate of it
108 
109  d) When SMSC Connection has failed to send a message to SMSC, it
110  MUST call callback function bb_smscconn_send_failed with appropriate
111  reason. The message supplied as with bb_smscconn_send
112 
113  e) When SMSC Connection changes to SMSCCONN_ACTIVE, connection MUST
114  call bb_smscconn_connected
115 
116  3) SMSC Connection MUST fill up SMSCConn structure as needed to, and is
117  responsible for any concurrency timings. SMSCConn->status MAY NOT be
118  set to SMSCCONN_DEAD until the connection is really that.
119  Use why_killed to make internally dead, supplied with reason.
120 
121  If the connection is disconnected temporarily, the connection SHOULD
122  call bb_smscconn_send_failed for each message in its internal list
123 
124  4) When SMSC Connection shuts down (shutdown called), it MUST try to send
125  all messages so-far relied to it to be sent if 'finish_sending' is set
126  to non-zero. If set to 0, it MUST call bb_smscconn_send_failed
127  for each message not yet sent.
128 
129  After everything is ready (it can happen in different thread), before
130  calling callback function bb_smscconn_killed it MUST release all memory it
131  has taken except for basic SMSCConn structure, and set status to
132  SMSCCONN_DEAD so it can be finally deleted.
133 
134  5) Callback bb_smscconn_ready is automatically called by main
135  smscconn_create. New implementation MAY NOT call it directly
136 
137  6) SMSC Connection driver must obey is_stopped/stopped variable to
138  suspend receiving (it can still send/re-connect), or must set
139  appropriate function calls. When connection is stopped, it is not
140  allowed to receive any new messages
141 */
142 
143 #include <signal.h>
144 #include "gwlib/gwlib.h"
145 #include "gwlib/gw-regex.h"
146 #include "smscconn.h"
147 #include "load.h"
148 
149 struct smscconn {
150  /* variables set by appropriate SMSCConn driver */
151  smscconn_status_t status; /* see smscconn.h */
152  int load; /* load factor, 0 = no load */
153  smscconn_killed_t why_killed; /* time to die with reason, set when
154  * shutdown called */
155  time_t connect_time; /* When connection to SMSC was established */
156 
157  Mutex *flow_mutex; /* used to lock SMSCConn structure (both
158  * in smscconn.c and specific driver) */
159 
160  /* connection specific counters (created in smscconn.c, updated
161  * by callback functions in bb_smscconn.c, NOT used by specific driver) */
167 
168  /* SMSCConn variables set in smscconn.c */
169  volatile sig_atomic_t is_stopped;
170 
171  Octstr *chksum; /* MD5 hash of the whole configuration */
172  Octstr *chksum_conn; /* MD5 hash minus the routing configuration */
173  Octstr *name; /* Descriptive name filled from connection info */
174  Octstr *id; /* Abstract name specified in configuration and
175  used for logging and routing */
183 
191 
192  Octstr *our_host; /* local device IP to bind for TCP communication */
193 
194  /* Our smsc specific log-file data */
196  long log_level;
197  int log_idx; /* index position within the global logfiles[] array in gwlib/log.c */
198 
199  long reconnect_delay; /* delay in seconds while re-connect attempts */
200 
201  int alt_dcs; /* use alternate DCS 0xFX */
202 
203  double throughput; /* message thoughput per sec. to be delivered to SMSC */
204 
205  /* Stores rerouting information for this specific smsc-id */
206  int reroute; /* simply turn MO into MT and process internally */
207  Dict *reroute_by_receiver; /* reroute receiver numbers to specific smsc-ids */
208  List *reroute_by_receiver_regex; /* same as above, but with regex patterns */
209  Octstr *reroute_to_smsc; /* define a smsc-id to reroute to */
210  int reroute_dlr; /* should DLR's are rereouted too? */
211  int dead_start; /* don't connect this SMSC at startup time */
212 
213  long max_sms_octets; /* max allowed octets for this SMSC */
214 
219 
220  /* XXX: move rest global data from Smsc here
221  */
222 
223  /* pointers set by specific driver, but initiated to NULL by smscconn.
224  * Note that flow_mutex is always locked before these functions are
225  * called, and released after execution returns from them */
226 
227  /* pointer to function called when smscconn_shutdown called.
228  * Note that this function is not needed always. If set, this
229  * function MUST set why_killed */
230  int (*shutdown) (SMSCConn *conn, int finish_sending);
231 
232  /* pointer to function called when a new message is needed to be sent.
233  * MAY NOT block. Connection MAY NOT use msg directly after it has
234  * returned from this function, but must instead duplicate it if need to.
235  */
236  int (*send_msg) (SMSCConn *conn, Msg *msg);
237 
238  /* pointer to function which returns current number of queued
239  * messages to-be-sent. The function CAN also set load factor directly
240  * to SMSCConn structure (above) */
241  long (*queued) (SMSCConn *conn);
242 
243  /* pointers to functions called when connection started/stopped
244  * (suspend/resume), if not NULL */
245 
246  void (*start_conn) (SMSCConn *conn);
247  void (*stop_conn) (SMSCConn *conn);
248 
249 
250  void *data; /* SMSC specific stuff */
251 };
252 
253 
254 typedef struct pattern_route {
255  regex_t *re;
257 } pattern_route;
258 
259 
260 /*
261  * Initializers for various SMSC connection implementations,
262  * each should take same arguments and return an int,
263  * which is 0 for okay and -1 for error.
264  *
265  * Each function is responsible for setting up all dynamic
266  * function pointers at SMSCConn structure and starting up any
267  * threads it might need.
268  *
269  * If conn->is_stopped is set (!= 0), create function MUST set
270  * its internal state as stopped, so that laterwards called
271  * smscconn_start works fine (and until it is called, no messages
272  * are received)
273  */
274 
275 /* generic wrapper for old SMSC implementations (uses old smsc.h).
276  * Responsible file: smsc/smsc_wrapper.c */
278 
279 /* Responsible file: smsc/smsc_fake.c */
281 
282 /* Responsible file: smsc/smsc_cimd2.c */
284 
285 /* Responsible file: smsc/smsc_emi.c */
287 
288 /* Responsible file: smsc/smsc_http.c */
290 
291 /* Responsible file: smsc/smsc_smpp.c */
293 
294 /* Responsible file: smsc/smsc_cgw.c */
295 int smsc_cgw_create(SMSCConn *conn, CfgGroup *cfg);
296 
297 /* Responsible file: smsc/smsc_at.c. */
298 int smsc_at2_create(SMSCConn *conn, CfgGroup *cfg);
299 
300 /* Responsible file: smsc/smsc_smasi.c */
302 
303 /* Responsible file: smsc/smsc_oisd.c */
305 
306 /* Responsible file: smsc/smsc_loopback.c */
308 
309 #ifdef HAVE_GSOAP
310 /* Responsible file: smsc/smsc_soap_parlayx.c */
311 int smsc_soap_parlayx_create(SMSCConn *conn, CfgGroup *cfg);
312 #endif
313 
314 /* ADD NEW CREATE FUNCTIONS HERE
315  *
316  * int smsc_xxx_create(SMSCConn *conn, CfgGroup *cfg);
317  */
318 
319 
320 #endif
Load * incoming_sms_load
Definition: smscconn_p.h:216
Octstr * name
Definition: smscconn_p.h:173
regex_t * re
Definition: smscconn_p.h:255
regex_t * allowed_smsc_id_regex
Definition: smscconn_p.h:180
long max_sms_octets
Definition: smscconn_p.h:213
smscconn_killed_t
Definition: smscconn.h:105
int smsc_wrapper_create(SMSCConn *conn, CfgGroup *cfg)
Definition: smsc_wrapper.c:397
int alt_dcs
Definition: smscconn_p.h:201
int dead_start
Definition: smscconn_p.h:211
List * reroute_by_receiver_regex
Definition: smscconn_p.h:208
Octstr * id
Definition: smscconn_p.h:174
void * data
Definition: smscconn_p.h:250
Counter * failed
Definition: smscconn_p.h:166
void(* stop_conn)(SMSCConn *conn)
Definition: smscconn_p.h:247
Octstr * denied_prefix
Definition: smscconn_p.h:186
int log_idx
Definition: smscconn_p.h:197
Octstr * allowed_prefix
Definition: smscconn_p.h:184
Octstr * id
Definition: smscconn_p.h:256
Dict * reroute_by_receiver
Definition: smscconn_p.h:207
Octstr * our_host
Definition: smscconn_p.h:192
long log_level
Definition: smscconn_p.h:196
static Cfg * cfg
Definition: opensmppbox.c:95
List * denied_smsc_id
Definition: smscconn_p.h:178
void(* start_conn)(SMSCConn *conn)
Definition: smscconn_p.h:246
long reconnect_delay
Definition: smscconn_p.h:199
regex_t * preferred_prefix_regex
Definition: smscconn_p.h:189
Octstr * log_file
Definition: smscconn_p.h:195
Load * outgoing_sms_load
Definition: smscconn_p.h:215
smscconn_killed_t why_killed
Definition: smscconn_p.h:153
regex_t * allowed_prefix_regex
Definition: smscconn_p.h:185
Counter * sent
Definition: smscconn_p.h:164
Counter * received_dlr
Definition: smscconn_p.h:163
Definition: msg.h:79
regex_t * preferred_smsc_id_regex
Definition: smscconn_p.h:182
Octstr * reroute_to_smsc
Definition: smscconn_p.h:209
Octstr * chksum_conn
Definition: smscconn_p.h:172
Octstr * admin_id
Definition: smscconn_p.h:176
List * preferred_smsc_id
Definition: smscconn_p.h:179
Octstr * unified_prefix
Definition: smscconn_p.h:190
Octstr * chksum
Definition: smscconn_p.h:171
struct pattern_route pattern_route
time_t connect_time
Definition: smscconn_p.h:155
int reroute
Definition: smscconn_p.h:206
Definition: dict.c:116
double throughput
Definition: smscconn_p.h:203
smscconn_status_t
Definition: smscconn.h:96
Mutex * flow_mutex
Definition: smscconn_p.h:157
int smsc_loopback_create(SMSCConn *conn, CfgGroup *cfg)
Octstr * preferred_prefix
Definition: smscconn_p.h:188
regex_t * denied_prefix_regex
Definition: smscconn_p.h:187
int smsc_at2_create(SMSCConn *conn, CfgGroup *cfg)
Definition: smsc_at.c:1519
volatile sig_atomic_t is_stopped
Definition: smscconn_p.h:169
List * allowed_smsc_id
Definition: smscconn_p.h:177
Counter * received
Definition: smscconn_p.h:162
Counter * sent_dlr
Definition: smscconn_p.h:165
int smsc_emi2_create(SMSCConn *conn, CfgGroup *cfg)
Definition: smsc_emi.c:1629
Definition: octstr.c:118
int(* shutdown)(SMSCConn *conn, int finish_sending)
Definition: smscconn_p.h:230
int smsc_smasi_create(SMSCConn *conn, CfgGroup *cfg)
Definition: smsc_smasi.c:1129
Load * outgoing_dlr_load
Definition: smscconn_p.h:218
int smsc_smpp_create(SMSCConn *conn, CfgGroup *cfg)
Definition: smsc_smpp.c:2599
Definition: cfg.c:73
int smsc_cimd2_create(SMSCConn *conn, CfgGroup *cfg)
Definition: smsc_cimd2.c:2321
Definition: load.c:76
smscconn_status_t status
Definition: smscconn_p.h:151
Load * incoming_dlr_load
Definition: smscconn_p.h:217
long(* queued)(SMSCConn *conn)
Definition: smscconn_p.h:241
int(* send_msg)(SMSCConn *conn, Msg *msg)
Definition: smscconn_p.h:236
int smsc_cgw_create(SMSCConn *conn, CfgGroup *cfg)
Definition: smsc_cgw.c:431
Definition: thread.h:76
int smsc_fake_create(SMSCConn *conn, CfgGroup *cfg)
Definition: smsc_fake.c:540
int smsc_oisd_create(SMSCConn *conn, CfgGroup *cfg)
Definition: smsc_oisd.c:1498
int smsc_http_create(SMSCConn *conn, CfgGroup *cfg)
Definition: smsc_http.c:489
regex_t * denied_smsc_id_regex
Definition: smscconn_p.h:181
int reroute_dlr
Definition: smscconn_p.h:210
Definition: list.c:102
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86
int load
Definition: smscconn_p.h:152
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.