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 #ifndef SMSCCONN_H 00058 #define SMSCCONN_H 00059 00060 /* 00061 * SMSC Connection 00062 * 00063 * Interface for main bearerbox to SMS center connection modules 00064 * 00065 * At first stage a simple wrapper for old ugly smsc module 00066 * 00067 * Kalle Marjola 2000 00068 */ 00069 00070 #include "gwlib/gwlib.h" 00071 #include "gw/msg.h" 00072 00073 /* 00074 * Structure hierarchy: 00075 * 00076 * Bearerbox keeps list of pointers to SMSCConn structures, which 00077 * include all data needed by connection, including routing data. 00078 * If any extra data not linked to that SMSC Connection is needed, 00079 * that is held in bearerbox 00080 * 00081 * SMSCConn is internal structure for smscconn module. It has a list 00082 * of common variables like number of sent/received messages and 00083 * and pointers to appropriate lists, and then it has a void pointer 00084 * to appropriate smsc structure defined and used by corresponding smsc 00085 * connection type module (like CIMD2, SMPP etc al) 00086 * 00087 * Concurrency notes: 00088 * 00089 * bearerbox is responsible for not calling cleanup at the same time 00090 * as it calls other functions, but must call it after it has noticed that 00091 * status == KILLED 00092 */ 00093 00094 typedef struct smscconn SMSCConn; 00095 00096 typedef enum { 00097 SMSCCONN_CONNECTING, 00098 SMSCCONN_ACTIVE, 00099 SMSCCONN_ACTIVE_RECV, 00100 SMSCCONN_RECONNECTING, 00101 SMSCCONN_DISCONNECTED, 00102 SMSCCONN_DEAD /* ready to be cleaned */ 00103 } smscconn_status_t; 00104 00105 typedef enum { 00106 SMSCCONN_ALIVE = 0, 00107 SMSCCONN_KILLED_WRONG_PASSWORD = 1, 00108 SMSCCONN_KILLED_CANNOT_CONNECT = 2, 00109 SMSCCONN_KILLED_SHUTDOWN = 3 00110 } smscconn_killed_t; 00111 00112 typedef struct smsc_state { 00113 smscconn_status_t status; /* see enumeration, below */ 00114 smscconn_killed_t killed; /* if we are killed, why */ 00115 int is_stopped; /* is connection currently in stopped state? */ 00116 unsigned long received; /* total number */ 00117 unsigned long sent; /* total number */ 00118 unsigned long failed; /* total number */ 00119 long queued; /* set our internal outgoing queue length */ 00120 long online; /* in seconds */ 00121 int load; /* subjective value 'how loaded we are' for 00122 * routing purposes, similar to sms/wapbox load */ 00123 } StatusInfo; 00124 00125 /* create new SMS center connection from given configuration group, 00126 * or return NULL if failed. 00127 * 00128 * The new connection does its work in its own privacy, and calls 00129 * callback functions at bb_smscconn_cb module. It calls function 00130 * bb_smscconn_ready when it has put everything up. 00131 * 00132 * NOTE: this function starts one or more threads to 00133 * handle traffic with SMSC, and caller does not need to 00134 * care about it afterwards. 00135 */ 00136 SMSCConn *smscconn_create(CfgGroup *cfg, int start_as_stopped); 00137 00138 /* shutdown/destroy smscc. Stop receiving messages and accepting 00139 * new message to-be-sent. Die when any internal queues are empty, 00140 * if finish_sending != 0, or if set to 0, kill connection ASAP and 00141 * call send_failed -callback for all messages still in queue 00142 */ 00143 void smscconn_shutdown(SMSCConn *smscconn, int finish_sending); 00144 00145 /* this is final function to cleanup all memory still held by 00146 * SMSC Connection after it has been killed (for synchronization 00147 * problems it cannot be cleaned automatically) 00148 * Call this after send returns problems or otherwise notice that 00149 * status is KILLED. Returns 0 if OK, -1 if it cannot be (yet) destroyed. 00150 */ 00151 int smscconn_destroy(SMSCConn *smscconn); 00152 00153 /* stop smscc. A stopped smscc does not receive any messages, but can 00154 * still send messages, so that internal queue can be emptied. The caller 00155 * is responsible for not to add new messages into queue if the caller wants 00156 * the list to empty at some point 00157 */ 00158 int smscconn_stop(SMSCConn *smscconn); 00159 00160 /* start stopped smscc. Return -1 if failed, 0 otherwise */ 00161 void smscconn_start(SMSCConn *smscconn); 00162 00163 /* Return name of the SMSC, as reference - caller may not free it! */ 00164 const Octstr *smscconn_name(SMSCConn *smscconn); 00165 00166 /* Return ID of the SMSC, as reference - caller may not free it! */ 00167 const Octstr *smscconn_id(SMSCConn *conn); 00168 00169 /* Check if this SMSC Connection is usable as sender for given 00170 * message. The bearerbox must then select the good SMSC for sending 00171 * according to load levels and connected/disconnected status, this 00172 * function only checks preferred/denied strings and overall status 00173 * 00174 * Return -1 if not (denied or permanently down), 0 if okay, 00175 * 1 if preferred one. 00176 */ 00177 int smscconn_usable(SMSCConn *conn, Msg *msg); 00178 00179 /* Call SMSC specific function to handle sending of 'msg' 00180 * Returns immediately, with 0 if successful and -1 if failed. 00181 * In any case the caller is still responsible for 'msg' after this 00182 * call 00183 * Note that return value does NOT mean that message has been send 00184 * or send has failed, but SMSC Connection calls appropriate callback 00185 * function later 00186 */ 00187 int smscconn_send(SMSCConn *smsccconn, Msg *msg); 00188 00189 /* Return just status as defined below */ 00190 int smscconn_status(SMSCConn *smscconn); 00191 00192 /* return current status of the SMSC connection, filled to infotable. 00193 * For unknown numbers, put -1. Return -1 if either argument was NULL. 00194 */ 00195 int smscconn_info(SMSCConn *smscconn, StatusInfo *infotable); 00196 00197 00198 #endif