Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
urltrans.h
Go to the documentation of this file.
1 /* ====================================================================
2  * The Kannel Software License, Version 1.0
3  *
4  * Copyright (c) 2001-2016 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 /*
58  * urltrans.h - URL translations
59  *
60  * The SMS gateway receives service requests sent as SMS messages and uses
61  * a web server to actually perform the requests. The first word of the
62  * SMS message usually specifies the service, and for each service there is
63  * a URL that specifies the web page or cgi-bin that performs the service.
64  * Thus, in effect, the gateway `translates' SMS messages to URLs.
65  *
66  * urltrans.h and urltrans.c implement a data structure for holding a list
67  * of translations and formatting a SMS request into a URL. It is used as
68  * follows:
69  *
70  * 1. Create a URLTranslation object with urltrans_create.
71  * 2. Add translations into it with urltrans_add_one or urltrans_add_cfg.
72  * 3. Receive SMS messages, and translate them into URLs with
73  * urltrans_get_url.
74  * 4. When you are done, free the object with urltrans_destroy.
75  *
76  * See below for more detailed instructions for using the functions.
77  *
78  * Lars Wirzenius for WapIT Ltd.
79  */
80 
81 #ifndef URLTRANS_H
82 #define URLTRANS_H
83 
84 #include "gwlib/gwlib.h"
85 #include "msg.h"
86 #include "numhash.h"
87 #include "gwlib/regex.h"
88 
89 /*
90  * This is the data structure that holds the list of translations. It is
91  * opaque and is defined in and usable only within urltrans.c.
92  */
94 
95 
96 /*
97  * This is the data structure that holds one translation. It is also
98  * opaque, and is accessed via some of the functions below.
99  */
101 
102 enum {
110 };
111 
112 
113 /*
114  * Create a new URLTranslationList object. Return NULL if the creation failed,
115  * or a pointer to the object if it succeded.
116  *
117  * The object is empty: it contains no translations.
118  */
120 
121 
122 /*
123  * Destroy a URLTranslationList object.
124  */
126 
127 
128 /*
129  * Add a translation to the object. The group is parsed internally.
130  *
131  * There can be several patterns for the same keyword, but with different
132  * patterns. urltrans_get_url will pick the pattern that best matches the
133  * actual SMS message. (See urltrans_get_pattern for a description of the
134  * algorithm.)
135  *
136  * There can only be one pattern with keyword "default", however.
137  *
138  * Sendsms-translations do not use keyword. Instead they use username and
139  * password
140  *
141  * Return -1 for error, or 0 for OK.
142  */
144 
145 
146 /*
147  * Add translations to a URLTranslation object from a Config object
148  * (see config.h). Translations are added from groups in `cfg' that
149  * contain variables called "keyword" and "url". For each such group,
150  * urltrans_add_one is called.
151  *
152  * Return -1 for error, 0 for OK. If -1 is returned, the URLTranslation
153  * object may have been partially modified.
154  */
156 
157 
158 /*
159  * Find the translation that corresponds to a given text string
160  *
161  * Use the translation with pattern whose keyword is the same as the first
162  * word of the text and that has the number of `%s' fields as the text
163  * has words after the first one. If no such pattern exists, use the
164  * pattern whose keyword is "default". If there is no such pattern, either,
165  * return NULL.
166  *
167  * If 'smsc' is set, only accept translation with no 'accepted-smsc' set or
168  * with matching smsc in that list.
169  *
170  * If 'account' is set, only accept translation with no 'accepted-account' set or
171  * with matching account in that list.
172  */
174 
175 /*
176  * Find the translation that corresponds to a given name
177  *
178  * Use the translation with service whose name is the same as the first
179  * word of the text. If no such pattern exists, return NULL.
180  */
182 
183 
184 /*
185  * find matching URLTranslation for the given 'username', or NULL
186  * if not found. Password must be checked afterwards
187  */
189  Octstr *name);
190 
191 
192 /*
193  * Return the populated URL octstr from the given pattern containing
194  * the escape codes with values from the Msg.
195  * urtrans_get_pattern() uses this internally, but we want to provide
196  * this function also to the external calling space for use of the
197  * defined escape codes for Msg values.
198  */
200 
201 
202 /*
203  * Return a pattern given contents of an SMS message. Find the appropriate
204  * translation pattern and fill in the missing parts from the contents of
205  * the SMS message.
206  *
207  * `sms' is the SMS message that is being translated.
208  *
209  * Return NULL if there is a failure. Otherwise, return a pointer to the
210  * pattern, which is stored in dynamically allocated memory that the
211  * caller should free when the pattern is no longer needed.
212  *
213  * The pattern is URL, fixed text or file name according to type of urltrans
214  */
216 
217 
218 /*
219  * Return the type of the translation, see enumeration above
220  */
222 
223 
224 /*
225  * Return prefix and suffix of translations, if they have been set.
226  */
229 
230 
231 /*
232  * Return default sender number, or NULL if not set.
233  */
235 
236 
237 /*
238  * Return (a recommended) faked sender number, or NULL if not set.
239  */
241 
242 
243 /*
244  * Return maximum number of SMS messages that should be generated from
245  * the web page directed by the URL translation.
246  */
248 
249 
250 /*
251  * Return the concatenation status for SMS messages that should be generated
252  * from the web page directed by the URL translation. (1=enabled)
253  */
255 
256 
257 /*
258  * Return (recommended) delimiter characters when splitting long
259  * replies into several messages
260  */
262 
263 
264 /*
265  * return a string that should be added after each sms message if it is
266  * except for the last one.
267  */
269 
270 
271 /*
272  * Return if set that should not send 'empty reply' messages
273  */
275 
276 
277 /*
278  * return a string that should be inserted to each SMS, if any
279  */
281 
282 
283 /*
284  * return a string that should be appended to each SMS, if any
285  */
287 
288 
289 /*
290  * Return the alternative charset to be used for the sms-service.
291  */
293 
294 
295 /*
296  * return the name, username or password string, or NULL if not set
297  * (used only with TRANSTYPE_SENDSMS)
298  */
302 
303 
304 /* Return forced smsc ID for send-sms user, if set */
306 
307 
308 /* Return default smsc ID for send-sms user, if set */
310 
311 
312 /* Return allow and deny IP strings, if set. */
315 
316 /* Return allowed and denied prefixes */
321 
322 /* Return white and black to number list */
327 
328 /* Return value of true (!0) or false (0) variables */
331 
334 
335 /* Return DLR related values */
338 
339 #endif
Octstr * urltrans_prefix(URLTranslation *t)
Definition: urltrans.c:772
void urltrans_destroy(URLTranslationList *list)
Definition: urltrans.c:194
Octstr * urltrans_denied_recv_prefix(URLTranslation *t)
Definition: urltrans.c:882
int urltrans_concatenation(URLTranslation *t)
Definition: urltrans.c:797
Octstr * urltrans_name(URLTranslation *t)
Definition: urltrans.c:832
int urltrans_add_one(URLTranslationList *trans, CfgGroup *grp)
Definition: urltrans.c:203
int urltrans_assume_plain_text(URLTranslation *t)
Definition: urltrans.c:907
Octstr * urltrans_username(URLTranslation *t)
Definition: urltrans.c:837
int urltrans_dlr_mask(URLTranslation *t)
Definition: urltrans.c:932
int urltrans_type(URLTranslation *t)
Definition: urltrans.c:767
regex_t * urltrans_black_list_regex(URLTranslation *t)
Definition: urltrans.c:902
Octstr * urltrans_allowed_recv_prefix(URLTranslation *t)
Definition: urltrans.c:877
Octstr * urltrans_password(URLTranslation *t)
Definition: urltrans.c:842
Octstr * urltrans_allow_ip(URLTranslation *t)
Definition: urltrans.c:857
Octstr * urltrans_alt_charset(URLTranslation *t)
Definition: urltrans.c:827
Octstr * urltrans_get_pattern(URLTranslation *t, Msg *sms)
Definition: urltrans.c:728
regex_t * urltrans_white_list_regex(URLTranslation *t)
Definition: urltrans.c:892
Octstr * urltrans_allowed_prefix(URLTranslation *t)
Definition: urltrans.c:867
Definition: msg.h:79
Definition: cfg.c:164
Octstr * urltrans_suffix(URLTranslation *t)
Definition: urltrans.c:777
Octstr * urltrans_header(URLTranslation *t)
Definition: urltrans.c:817
Octstr * urltrans_dlr_url(URLTranslation *t)
Definition: urltrans.c:927
Octstr * urltrans_split_suffix(URLTranslation *t)
Definition: urltrans.c:807
Octstr * urltrans_footer(URLTranslation *t)
Definition: urltrans.c:822
int urltrans_accept_x_kannel_headers(URLTranslation *t)
Definition: urltrans.c:912
char * name
Definition: smsc_cimd2.c:212
Octstr * urltrans_split_chars(URLTranslation *t)
Definition: urltrans.c:802
Octstr * urltrans_faked_sender(URLTranslation *t)
Definition: urltrans.c:787
URLTranslation * urltrans_find_service(URLTranslationList *trans, Msg *msg)
Definition: urltrans.c:268
Octstr * pattern
Definition: urltrans.c:90
static Cfg * cfg
Definition: smsbox.c:115
Octstr * urltrans_denied_prefix(URLTranslation *t)
Definition: urltrans.c:872
Octstr * urltrans_default_sender(URLTranslation *t)
Definition: urltrans.c:782
Definition: octstr.c:118
int urltrans_omit_empty(URLTranslation *t)
Definition: urltrans.c:812
Octstr * urltrans_fill_escape_codes(Octstr *pattern, Msg *request)
Definition: urltrans.c:323
int urltrans_send_sender(URLTranslation *t)
Definition: urltrans.c:922
int urltrans_add_cfg(URLTranslationList *trans, Cfg *cfg)
Definition: urltrans.c:228
Definition: cfg.c:73
Octstr * urltrans_deny_ip(URLTranslation *t)
Definition: urltrans.c:862
Numhash * urltrans_white_list(URLTranslation *t)
Definition: urltrans.c:887
URLTranslation * urltrans_find(URLTranslationList *trans, Msg *msg)
Definition: urltrans.c:255
URLTranslation * urltrans_find_username(URLTranslationList *trans, Octstr *name)
Definition: urltrans.c:284
int urltrans_max_messages(URLTranslation *t)
Definition: urltrans.c:792
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86
Numhash * urltrans_black_list(URLTranslation *t)
Definition: urltrans.c:897
URLTranslationList * urltrans_create(void)
Definition: urltrans.c:182
int urltrans_strip_keyword(URLTranslation *t)
Definition: urltrans.c:917
Octstr * urltrans_default_smsc(URLTranslation *t)
Definition: urltrans.c:852
Octstr * urltrans_forced_smsc(URLTranslation *t)
Definition: urltrans.c:847
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.