Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

urltrans.h

Go to the documentation of this file.
00001 /* ==================================================================== 
00002  * The Kannel Software License, Version 1.0 
00003  * 
00004  * Copyright (c) 2001-2008 Kannel Group  
00005  * Copyright (c) 1998-2001 WapIT Ltd.   
00006  * All rights reserved. 
00007  * 
00008  * Redistribution and use in source and binary forms, with or without 
00009  * modification, are permitted provided that the following conditions 
00010  * are met: 
00011  * 
00012  * 1. Redistributions of source code must retain the above copyright 
00013  *    notice, this list of conditions and the following disclaimer. 
00014  * 
00015  * 2. Redistributions in binary form must reproduce the above copyright 
00016  *    notice, this list of conditions and the following disclaimer in 
00017  *    the documentation and/or other materials provided with the 
00018  *    distribution. 
00019  * 
00020  * 3. The end-user documentation included with the redistribution, 
00021  *    if any, must include the following acknowledgment: 
00022  *       "This product includes software developed by the 
00023  *        Kannel Group (http://www.kannel.org/)." 
00024  *    Alternately, this acknowledgment may appear in the software itself, 
00025  *    if and wherever such third-party acknowledgments normally appear. 
00026  * 
00027  * 4. The names "Kannel" and "Kannel Group" must not be used to 
00028  *    endorse or promote products derived from this software without 
00029  *    prior written permission. For written permission, please  
00030  *    contact org@kannel.org. 
00031  * 
00032  * 5. Products derived from this software may not be called "Kannel", 
00033  *    nor may "Kannel" appear in their name, without prior written 
00034  *    permission of the Kannel Group. 
00035  * 
00036  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 
00037  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
00038  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00039  * DISCLAIMED.  IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS 
00040  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,  
00041  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  
00042  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR  
00043  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,  
00044  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE  
00045  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  
00046  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00047  * ==================================================================== 
00048  * 
00049  * This software consists of voluntary contributions made by many 
00050  * individuals on behalf of the Kannel Group.  For more information on  
00051  * the Kannel Group, please see <http://www.kannel.org/>. 
00052  * 
00053  * Portions of this software are based upon software originally written at  
00054  * WapIT Ltd., Helsinki, Finland for the Kannel project.  
00055  */ 
00056 
00057 /*
00058  * urltrans.h - URL translations
00059  *
00060  * The SMS gateway receives service requests sent as SMS messages and uses
00061  * a web server to actually perform the requests. The first word of the
00062  * SMS message usually specifies the service, and for each service there is
00063  * a URL that specifies the web page or cgi-bin that performs the service. 
00064  * Thus, in effect, the gateway `translates' SMS messages to URLs.
00065  *
00066  * urltrans.h and urltrans.c implement a data structure for holding a list
00067  * of translations and formatting a SMS request into a URL. It is used as
00068  * follows:
00069  *
00070  * 1. Create a URLTranslation object with urltrans_create.
00071  * 2. Add translations into it with urltrans_add_one or urltrans_add_cfg.
00072  * 3. Receive SMS messages, and translate them into URLs with 
00073  *    urltrans_get_url.
00074  * 4. When you are done, free the object with urltrans_destroy.
00075  *
00076  * See below for more detailed instructions for using the functions.
00077  *
00078  * Lars Wirzenius for WapIT Ltd.
00079  */
00080 
00081 #ifndef URLTRANS_H
00082 #define URLTRANS_H
00083 
00084 #include "gwlib/gwlib.h"
00085 #include "msg.h"
00086 #include "numhash.h"
00087 #include "gwlib/regex.h"
00088 
00089 /*
00090  * This is the data structure that holds the list of translations. It is
00091  * opaque and is defined in and usable only within urltrans.c.
00092  */
00093 typedef struct URLTranslationList URLTranslationList;
00094 
00095 
00096 /*
00097  * This is the data structure that holds one translation. It is also
00098  * opaque, and is accessed via some of the functions below.
00099  */
00100 typedef struct URLTranslation URLTranslation;
00101 
00102 enum {
00103     TRANSTYPE_GET_URL = 0,
00104     TRANSTYPE_POST_URL,
00105     TRANSTYPE_POST_XML,
00106     TRANSTYPE_TEXT,
00107     TRANSTYPE_FILE,
00108     TRANSTYPE_EXECUTE,
00109     TRANSTYPE_SENDSMS
00110 };
00111 
00112 
00113 /*
00114  * Create a new URLTranslationList object. Return NULL if the creation failed,
00115  * or a pointer to the object if it succeded.
00116  *
00117  * The object is empty: it contains no translations.
00118  */
00119 URLTranslationList *urltrans_create(void);
00120 
00121 
00122 /*
00123  * Destroy a URLTranslationList object.
00124  */
00125 void urltrans_destroy(URLTranslationList *list);
00126 
00127 
00128 /*
00129  * Add a translation to the object. The group is parsed internally.
00130  *
00131  * There can be several patterns for the same keyword, but with different
00132  * patterns. urltrans_get_url will pick the pattern that best matches the
00133  * actual SMS message. (See urltrans_get_pattern for a description of the
00134  * algorithm.)
00135  *
00136  * There can only be one pattern with keyword "default", however.
00137  *
00138  * Sendsms-translations do not use keyword. Instead they use username and
00139  * password
00140  *
00141  * Return -1 for error, or 0 for OK.
00142  */
00143 int urltrans_add_one(URLTranslationList *trans, CfgGroup *grp);
00144 
00145 
00146 /*
00147  * Add translations to a URLTranslation object from a Config object
00148  * (see config.h). Translations are added from groups in `cfg' that
00149  * contain variables called "keyword" and "url". For each such group,
00150  * urltrans_add_one is called.
00151  *
00152  * Return -1 for error, 0 for OK. If -1 is returned, the URLTranslation
00153  * object may have been partially modified.
00154  */
00155 int urltrans_add_cfg(URLTranslationList *trans, Cfg *cfg);
00156 
00157 
00158 /*
00159  * Find the translation that corresponds to a given text string
00160  *
00161  * Use the translation with pattern whose keyword is the same as the first
00162  * word of the text and that has the number of `%s' fields as the text
00163  * has words after the first one. If no such pattern exists, use the
00164  * pattern whose keyword is "default". If there is no such pattern, either,
00165  * return NULL.
00166  *
00167  * If 'smsc' is set, only accept translation with no 'accepted-smsc' set or
00168  * with matching smsc in that list.
00169  *
00170  * If 'account' is set, only accept translation with no 'accepted-account' set or
00171  * with matching account in that list.
00172  */
00173 URLTranslation *urltrans_find(URLTranslationList *trans, Msg *msg);
00174 
00175 /*
00176  * Find the translation that corresponds to a given name
00177  *
00178  * Use the translation with service whose name is the same as the first
00179  * word of the text. If no such pattern exists, return NULL.
00180  */
00181 URLTranslation *urltrans_find_service(URLTranslationList *trans, Msg *msg); 
00182 
00183 
00184 /*
00185  * find matching URLTranslation for the given 'username', or NULL
00186  * if not found. Password must be checked afterwards
00187  */
00188 URLTranslation *urltrans_find_username(URLTranslationList *trans, 
00189                                        Octstr *name);
00190 
00191 
00192 /* 
00193  * Return the populated URL octstr from the given pattern containing
00194  * the escape codes with values from the Msg.
00195  * urtrans_get_pattern() uses this internally, but we want to provide
00196  * this function also to the external calling space for use of the
00197  * defined escape codes for Msg values.
00198  */
00199 Octstr *urltrans_fill_escape_codes(Octstr *pattern, Msg *request);
00200 
00201 
00202 /*
00203  * Return a pattern given contents of an SMS message. Find the appropriate
00204  * translation pattern and fill in the missing parts from the contents of
00205  * the SMS message.
00206  *
00207  * `sms' is the SMS message that is being translated.
00208  *
00209  * Return NULL if there is a failure. Otherwise, return a pointer to the
00210  * pattern, which is stored in dynamically allocated memory that the
00211  * caller should free when the pattern is no longer needed.
00212  *
00213  * The pattern is URL, fixed text or file name according to type of urltrans
00214  */
00215 Octstr *urltrans_get_pattern(URLTranslation *t, Msg *sms);
00216 
00217 
00218 /*
00219  * Return the type of the translation, see enumeration above
00220  */
00221 int urltrans_type(URLTranslation *t);
00222 
00223 
00224 /*
00225  * Return prefix and suffix of translations, if they have been set.
00226  */
00227 Octstr *urltrans_prefix(URLTranslation *t);
00228 Octstr *urltrans_suffix(URLTranslation *t);
00229 
00230 
00231 /*
00232  * Return default sender number, or NULL if not set.
00233  */
00234 Octstr *urltrans_default_sender(URLTranslation *t);
00235 
00236 
00237 /*
00238  * Return (a recommended) faked sender number, or NULL if not set.
00239  */
00240 Octstr *urltrans_faked_sender(URLTranslation *t);
00241 
00242 
00243 /*
00244  * Return maximum number of SMS messages that should be generated from
00245  * the web page directed by the URL translation.
00246  */
00247 int urltrans_max_messages(URLTranslation *t);
00248 
00249 
00250 /*
00251  * Return the concatenation status for SMS messages that should be generated
00252  * from the web page directed by the URL translation. (1=enabled)
00253  */
00254 int urltrans_concatenation(URLTranslation *t);
00255 
00256 
00257 /*
00258  * Return (recommended) delimiter characters when splitting long
00259  * replies into several messages
00260  */
00261 Octstr *urltrans_split_chars(URLTranslation *t);
00262 
00263 
00264 /*
00265  * return a string that should be added after each sms message if it is
00266  * except for the last one.
00267  */
00268 Octstr *urltrans_split_suffix(URLTranslation *t);
00269 
00270 
00271 /*
00272  * Return if set that should not send 'empty reply' messages
00273  */
00274 int urltrans_omit_empty(URLTranslation *t);
00275 
00276 
00277 /*
00278  * return a string that should be inserted to each SMS, if any
00279  */
00280 Octstr *urltrans_header(URLTranslation *t);
00281 
00282 
00283 /*
00284  * return a string that should be appended to each SMS, if any
00285  */
00286 Octstr *urltrans_footer(URLTranslation *t);
00287 
00288 
00289 /*
00290  * return the name, username or password string, or NULL if not set
00291  * (used only with TRANSTYPE_SENDSMS)
00292  */
00293 Octstr *urltrans_name(URLTranslation *t);
00294 Octstr *urltrans_username(URLTranslation *t);
00295 Octstr *urltrans_password(URLTranslation *t);
00296 
00297 
00298 /* Return forced smsc ID for send-sms user, if set */
00299 Octstr *urltrans_forced_smsc(URLTranslation *t);
00300 
00301 
00302 /* Return default smsc ID for send-sms user, if set */
00303 Octstr *urltrans_default_smsc(URLTranslation *t);
00304 
00305 
00306 /* Return allow and deny IP strings, if set. */
00307 Octstr *urltrans_allow_ip(URLTranslation *t);
00308 Octstr *urltrans_deny_ip(URLTranslation *t);
00309 
00310 /* Return allowed and denied prefixes */
00311 Octstr *urltrans_allowed_prefix(URLTranslation *t);
00312 Octstr *urltrans_denied_prefix(URLTranslation *t);
00313 Octstr *urltrans_allowed_recv_prefix(URLTranslation *t);
00314 Octstr *urltrans_denied_recv_prefix(URLTranslation *t);
00315 
00316 /* Return white and black to number list */
00317 Numhash *urltrans_white_list(URLTranslation *t);
00318 Numhash *urltrans_black_list(URLTranslation *t);
00319 regex_t *urltrans_white_list_regex(URLTranslation *t);
00320 regex_t *urltrans_black_list_regex(URLTranslation *t);
00321 
00322 /* Return value of true (!0) or false (0) variables */
00323 int urltrans_assume_plain_text(URLTranslation *t);
00324 int urltrans_accept_x_kannel_headers(URLTranslation *t);
00325 
00326 int urltrans_strip_keyword(URLTranslation *t);
00327 int urltrans_send_sender(URLTranslation *t);
00328 
00329 #endif
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.