2005-09-02 11:41:28 +00:00
|
|
|
/*
|
|
|
|
* Mbuni - Open Source MMS Gateway
|
|
|
|
*
|
|
|
|
* MMSBOX CFG: MMC configuration and misc. functions
|
|
|
|
*
|
2008-07-10 09:46:58 +00:00
|
|
|
* Copyright (C) 2003 - 2008, Digital Solutions Ltd. - http://www.dsmagic.com
|
2005-09-02 11:41:28 +00:00
|
|
|
*
|
|
|
|
* Paul Bagyenda <bagyenda@dsmagic.com>
|
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License, with a few exceptions granted (see LICENSE)
|
|
|
|
*/
|
|
|
|
#ifndef __MMSBOX_CFG_INCLUDED__
|
|
|
|
#define __MMSBOX_CFG_INCLUDED__
|
|
|
|
#include "mms_util.h"
|
2007-07-17 08:26:38 +00:00
|
|
|
#include "mmsbox_mt_filter.h"
|
2007-08-20 11:49:30 +00:00
|
|
|
#include "mms_queue.h"
|
2007-09-17 13:07:30 +00:00
|
|
|
#include "mmsbox_resolve.h"
|
2007-08-20 11:49:30 +00:00
|
|
|
|
2007-09-19 13:06:26 +00:00
|
|
|
#include "mmsbox_mmsc.h"
|
2008-09-12 12:02:40 +00:00
|
|
|
#include "mmsbox_cdr.h"
|
2010-10-21 17:51:16 +00:00
|
|
|
#include "mms_cfg.h"
|
|
|
|
|
|
|
|
/* Alarm callback mechanism */
|
|
|
|
enum MmsBoxAlarms {
|
|
|
|
MMSBOX_ALARM_HTTP_DOWN = 0,
|
|
|
|
MMSBOX_ALARM_FILE_WRITE_ERROR,
|
|
|
|
MMSBOX_ALARM_SOCKET_CONNECT_FAILED,
|
|
|
|
MMSBOX_ALARM_QUEUE_WRITE_ERROR,
|
|
|
|
MMSBOX_ALARM_STORAGE_API_ERROR,
|
|
|
|
MMSBOX_ALARM_MM7_PARSING_FAILURE,
|
|
|
|
MMSBOX_ALARM_MM7_NON_200_RESULT,
|
|
|
|
MMSBOX_ALARM_RETRIEVE_MMS_ERROR,
|
2010-10-26 10:18:13 +00:00
|
|
|
MMSBOX_ALARM_MM4_PARSING_FAILURE,
|
2010-10-21 17:51:16 +00:00
|
|
|
MMSBOX_ALARM_MAX_ALARM /* Must be last one */
|
|
|
|
};
|
2007-09-19 13:06:26 +00:00
|
|
|
|
2005-09-02 11:41:28 +00:00
|
|
|
typedef struct MmscGrp {
|
|
|
|
Octstr *id; /* MMSC id (for logging). */
|
2007-04-02 05:29:00 +00:00
|
|
|
Octstr *group_id; /* GROUP MMSC id (used for qf). */
|
2008-10-02 13:49:07 +00:00
|
|
|
Octstr *vasp_id; /* vasp id for SOAP mmsc */
|
2005-09-02 11:41:28 +00:00
|
|
|
Octstr *mmsc_url; /* URL at which MMSC can be reached. */
|
|
|
|
struct {
|
|
|
|
Octstr *user, *pass;
|
2005-09-07 10:10:41 +00:00
|
|
|
Octstr *allow_ip;
|
|
|
|
Octstr *deny_ip;
|
2005-09-02 11:41:28 +00:00
|
|
|
long port;
|
2008-08-29 10:23:17 +00:00
|
|
|
int ssl;
|
2005-09-02 11:41:28 +00:00
|
|
|
} incoming; /* user, pass, port (and whether SSL) that MMSC uses to connect to us. */
|
2005-09-07 10:10:41 +00:00
|
|
|
Octstr *allowed_prefix, *denied_prefix;
|
2007-12-15 08:40:22 +00:00
|
|
|
Octstr *allowed_sender_prefix, *denied_sender_prefix;
|
2011-03-24 12:58:11 +00:00
|
|
|
enum {UNKNOWN_MMSC = -1, CUSTOM_MMSC, SOAP_MMSC, EAIF_MMSC, MM4_MMSC, HTTP_MMSC, MM1_MMSC} type; /* type of connection. */
|
2008-02-14 14:46:21 +00:00
|
|
|
double throughput; /* Max send rate. */
|
2005-09-02 11:41:28 +00:00
|
|
|
long threadid; /* handler thread. */
|
2005-09-07 10:10:41 +00:00
|
|
|
|
2007-08-27 10:16:26 +00:00
|
|
|
int reroute; /* whether messages from this mmsc are re-routed outwards. */
|
|
|
|
Octstr *reroute_mmsc_id;
|
2008-04-11 07:01:35 +00:00
|
|
|
int no_senderaddress; /* used by SOAP interface: Don't add a sender address. */
|
2007-11-07 07:53:29 +00:00
|
|
|
int reroute_mod_subject; /* Set to true if we'll change subject line on reroute. */
|
2007-04-10 09:56:46 +00:00
|
|
|
MM7Version_t ver; /* supported MM7/SOAP version. */
|
2007-07-17 08:26:38 +00:00
|
|
|
int use_mt_filter; /* whether to use MT filter on this connection. */
|
2005-09-07 10:10:41 +00:00
|
|
|
Mutex *mutex;
|
2008-09-11 19:06:49 +00:00
|
|
|
|
|
|
|
Octstr *default_vasid; /* default vasid for mm7/soap */
|
2007-09-19 13:06:26 +00:00
|
|
|
|
|
|
|
MmsBoxMmscFuncs *fns; /* pointer to functions for handling this mmsc connection type */
|
|
|
|
Octstr *settings; /* settings for the above module. */
|
|
|
|
void *data; /* data for above module. */
|
2010-10-26 10:18:13 +00:00
|
|
|
int started; /* Whether it is active */
|
2008-09-02 11:07:16 +00:00
|
|
|
unsigned long mt_pdus; /* number of MT PDUs since start. */
|
|
|
|
unsigned long mo_pdus; /* number of MO PDUs since start. */
|
|
|
|
unsigned long mt_errors; /* number of MT errors since start */
|
|
|
|
unsigned long mo_errors; /* number of MO errors since start */
|
|
|
|
|
|
|
|
time_t last_pdu; /* time of last PDU */
|
|
|
|
time_t start_time; /* when was this connection started */
|
|
|
|
|
2010-10-21 17:51:16 +00:00
|
|
|
time_t last_alarm[MMSBOX_ALARM_MAX_ALARM];
|
2008-08-29 10:23:17 +00:00
|
|
|
int use_count; /* use counter. */
|
2011-03-24 12:58:11 +00:00
|
|
|
time_t delete_after; /* used to control deletion of object -- not very clean, but... */
|
2010-10-26 10:18:13 +00:00
|
|
|
|
|
|
|
long max_pkt_size;
|
|
|
|
|
|
|
|
int strip_domain; /* MM4 only */
|
2010-12-09 10:36:29 +00:00
|
|
|
|
|
|
|
long max_recipients; /* Max recpients per transaction */
|
2011-01-05 05:53:14 +00:00
|
|
|
|
|
|
|
List *strip_prefixes; /* List of prefixes to be stripped before sending out*/
|
2011-03-24 12:58:11 +00:00
|
|
|
|
|
|
|
struct MM1Info_t { /* Stuff used only by the MM1 MMSC */
|
|
|
|
Octstr *proxy; /* Proxy within the operator network, form of host:port */
|
|
|
|
Octstr *gprs_on; /* Command to start GPRS link. Must not exit. */
|
|
|
|
Octstr *gprs_off; /* Command to stop GPRS link. */
|
|
|
|
Octstr *gprs_pid; /* command to call to get PID of GPRS for stopping GPRS link (i.e. pppd). */
|
|
|
|
Octstr *smsc_on; /* command to start smsc connection */
|
|
|
|
Octstr *smsc_off; /* commadn to stop smsc connection */
|
|
|
|
Octstr *msisdn; /* Our msisdn */
|
|
|
|
Octstr *ua; /* User agent string, if given */
|
|
|
|
List *requests; /* list of requests. */
|
|
|
|
long d_tid;/* thread ID for mm1 handler. */
|
|
|
|
|
|
|
|
int sender_alive;
|
|
|
|
} mm1;
|
2005-09-02 11:41:28 +00:00
|
|
|
} MmscGrp;
|
|
|
|
|
2010-10-26 10:18:13 +00:00
|
|
|
#define DEFAULT_MAX_PKT_SIZE 1024*1024
|
2010-10-21 17:51:16 +00:00
|
|
|
|
2008-08-29 10:23:17 +00:00
|
|
|
#define MMSBOX_MMSC_MARK_INUSE(mmc) do {\
|
|
|
|
mutex_lock((mmc)->mutex); \
|
|
|
|
(mmc)->use_count++; \
|
|
|
|
mutex_unlock(mmc->mutex); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define MMSBOX_MMSC_UNMARK_INUSE(mmc) do {\
|
|
|
|
mutex_lock((mmc)->mutex); \
|
|
|
|
(mmc)->use_count--; \
|
|
|
|
mutex_unlock(mmc->mutex); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
2005-09-02 11:41:28 +00:00
|
|
|
typedef struct MmsServiceUrlParam {
|
|
|
|
Octstr *name;
|
2005-09-15 07:57:56 +00:00
|
|
|
enum {NO_PART, AUDIO_PART, IMAGE_PART, VIDEO_PART,
|
2005-09-02 11:41:28 +00:00
|
|
|
TEXT_PART, SMIL_PART , OTHER_PART,
|
2007-07-09 16:43:42 +00:00
|
|
|
ANY_PART, WHOLE_BINARY, KEYWORD_PART} type;
|
2005-09-02 11:41:28 +00:00
|
|
|
Octstr *value; /* for generic value (type == NO_PART),
|
2007-05-09 11:14:21 +00:00
|
|
|
* or for value that follows spec (e.g. %Tisatest is allowed)
|
|
|
|
*/
|
2005-09-02 11:41:28 +00:00
|
|
|
} MmsServiceUrlParam;
|
|
|
|
|
|
|
|
typedef struct MmsService {
|
|
|
|
Octstr *name; /* name of service. */
|
|
|
|
int isdefault;
|
|
|
|
int omitempty;
|
2006-05-03 13:52:40 +00:00
|
|
|
int noreply;
|
2005-09-02 11:41:28 +00:00
|
|
|
int accept_x_headers;
|
2006-05-03 13:52:40 +00:00
|
|
|
List *passthro_headers;
|
|
|
|
|
2005-09-02 11:41:28 +00:00
|
|
|
int assume_plain_text;
|
|
|
|
List *keywords; /* List of keywords matched. */
|
|
|
|
enum {TRANS_TYPE_GET_URL, TRANS_TYPE_POST_URL, TRANS_TYPE_FILE, TRANS_TYPE_EXEC,
|
|
|
|
TRANS_TYPE_TEXT} type;
|
2005-09-07 10:10:41 +00:00
|
|
|
Octstr *url; /* The value. */
|
2005-09-02 11:41:28 +00:00
|
|
|
List *params; /* of MmsServiceUrlParam */
|
|
|
|
|
|
|
|
Octstr *faked_sender;
|
|
|
|
List *allowed_mmscs; /* List of MMSCs allowed to access this service (by ID). */
|
2006-08-11 10:05:46 +00:00
|
|
|
List *denied_mmscs; /* List of MMSCs allowed to access this service (by ID). */
|
|
|
|
Octstr *service_code; /* Service code (MM7/SOAP only) */
|
2007-12-15 08:40:22 +00:00
|
|
|
|
|
|
|
Octstr *allowed_receiver_prefix, *denied_receiver_prefix;
|
2008-09-12 08:46:46 +00:00
|
|
|
Octstr *special_header; /* To be added to each content element. */
|
2005-09-02 11:41:28 +00:00
|
|
|
} MmsService;
|
|
|
|
|
|
|
|
typedef struct SendMmsUser {
|
|
|
|
Octstr *user, *pass;
|
|
|
|
Octstr *faked_sender;
|
2008-08-20 07:55:29 +00:00
|
|
|
Octstr *dlr_url, *rr_url, *mmsc;
|
2005-09-02 11:41:28 +00:00
|
|
|
} SendMmsUser;
|
|
|
|
|
|
|
|
/* Basic settings for the mmsbox. */
|
|
|
|
extern List *sendmms_users; /* list of SendMmsUser structs */
|
|
|
|
extern List *mms_services; /* list of MMS Services */
|
2005-09-07 10:10:41 +00:00
|
|
|
extern Octstr *incoming_qdir, *outgoing_qdir, *dlr_dir;
|
|
|
|
extern Octstr *unified_prefix;
|
2008-08-14 11:44:58 +00:00
|
|
|
extern Octstr *sendmail_cmd;
|
|
|
|
extern Octstr *myhostname;
|
2008-05-05 19:29:49 +00:00
|
|
|
extern List *strip_prefixes;
|
2009-05-12 05:57:47 +00:00
|
|
|
extern long svc_maxsendattempts, maxsendattempts, mmsbox_send_back_off, default_msgexpiry, max_msgexpiry;
|
2005-09-09 13:11:38 +00:00
|
|
|
extern long maxthreads;
|
|
|
|
extern double queue_interval;
|
2005-09-02 11:41:28 +00:00
|
|
|
extern struct SendMmsPortInfo {
|
|
|
|
long port; /* Might be ssl-ed. */
|
|
|
|
Octstr *allow_ip;
|
|
|
|
Octstr *deny_ip;
|
|
|
|
} sendmms_port;
|
|
|
|
|
2007-07-17 08:26:38 +00:00
|
|
|
extern struct MmsBoxMTfilter *mt_filter;
|
2007-08-20 11:49:30 +00:00
|
|
|
extern MmsQueueHandlerFuncs *qfs;
|
2007-07-19 19:45:24 +00:00
|
|
|
extern int mt_multipart;
|
2007-09-17 13:07:30 +00:00
|
|
|
|
|
|
|
extern MmsBoxResolverFuncStruct *rfs; /* resolver functions. */
|
|
|
|
extern void *rfs_data;
|
|
|
|
extern Octstr *rfs_settings;
|
|
|
|
|
2010-10-27 06:08:50 +00:00
|
|
|
extern struct SMTPRelay {
|
|
|
|
Octstr *host;
|
|
|
|
int port;
|
|
|
|
} smtp_relay;
|
2007-09-17 13:07:30 +00:00
|
|
|
|
2008-09-12 12:02:40 +00:00
|
|
|
extern MmsBoxCdrFuncStruct *cdrfs;
|
2010-10-21 17:51:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
extern struct MmsBoxHealthMonitors {
|
2010-11-18 06:51:17 +00:00
|
|
|
void (*register_thread)( char *name); /* Called by each thread to register itself with the health monitor */
|
|
|
|
void (*unregister_thread)(char *name); /* Called by each thread to unregister itself with the health monitor */
|
2010-10-21 17:51:16 +00:00
|
|
|
void (*register_port)(short port); /* Called to register each port on which we listen */
|
|
|
|
void (*unregister_port)(short port); /* Called to unregister each port on which we listen */
|
|
|
|
} *hmon; /* This should be set if you want to do any thread and port monitoring */
|
|
|
|
|
|
|
|
/* mmsbox_event_cb: Called with each mmsc event.
|
|
|
|
* mmsc - mmsc ID
|
|
|
|
* mm7_pkt_type - MM7 packet type (using MM7/SOAP codes)
|
|
|
|
* mm7_ver - value for SOAP or EAIF only
|
|
|
|
* status - 0 for Ok, -1 if failed (e.g. for submitack
|
|
|
|
* msg_size - size of mms
|
|
|
|
* num_retries - number of retries so far
|
|
|
|
* from - sender (can be NULL)
|
|
|
|
* to - recipient (can be NULL)
|
|
|
|
* transid - transaction ID
|
|
|
|
* message_id - Message ID (for submitack, deliverreq, deliveryreport or readreport)
|
|
|
|
* hdrs - List of envelope headers
|
|
|
|
* value - value associated with pkt type: e.g. for deliveryreport, report type
|
|
|
|
*/
|
|
|
|
extern void (*mmsbox_event_cb)(Octstr *mmsc, int mm7_pkt_type,
|
|
|
|
int is_mm4,
|
|
|
|
Octstr *mm7_ver, int status,
|
|
|
|
int msg_size, int num_retries,
|
|
|
|
Octstr *from, Octstr *to, Octstr *message_id, Octstr *transid,
|
|
|
|
List *hdrs, Octstr *value);
|
|
|
|
|
|
|
|
/* mmsbox_alarm_cb: Called when an alarm is raised or cleared
|
|
|
|
* mmsc - MMSC ID
|
|
|
|
* alarm - alarm type
|
|
|
|
* alarm_state - 0 = alarm cleared, 1 = alarm raised
|
|
|
|
* lev = severity level, 1 = warning, 2 = minor, 3 = major, 4+ = critical
|
|
|
|
*/
|
|
|
|
extern void (*mmsbox_alarm_cb)(Octstr*mmsc, enum MmsBoxAlarms alarm, int alarm_state, int lev);
|
|
|
|
|
|
|
|
#define MMSC_ISSUE_ALARM(mmc,alarm,lev) do { \
|
|
|
|
MmscGrp *_mmc = (mmc); \
|
|
|
|
if (_mmc) \
|
|
|
|
_mmc->last_alarm[(alarm)] = time(NULL); \
|
|
|
|
mmsbox_alarm_cb(_mmc ? _mmc->id : NULL, (alarm), 1, (lev)); \
|
|
|
|
} while (0)
|
|
|
|
#define MMSC_CLEAR_ALARM(mmc,alarm) do { \
|
|
|
|
MmscGrp *_mmc = (mmc); \
|
|
|
|
if (_mmc && _mmc->last_alarm[(alarm)] > 0 ) { \
|
|
|
|
mmsbox_alarm_cb(_mmc->id, (alarm), 0, 0); \
|
|
|
|
_mmc->last_alarm[(alarm)] = 0; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
extern int mms_load_mmsbox_settings(struct mCfgImpFuncs *cfg_funcs, Octstr *init,
|
|
|
|
gwthread_func_t *mmsc_handler_func,
|
|
|
|
MmsQueueHandlerFuncs *,
|
|
|
|
MmsEventLoggerFuncs *);
|
2008-08-29 11:26:27 +00:00
|
|
|
extern void mmsbox_settings_cleanup(void);
|
2007-12-15 08:40:22 +00:00
|
|
|
extern MmscGrp *get_handler_mmc(Octstr *id, Octstr *to, Octstr *from);
|
2008-08-29 10:23:17 +00:00
|
|
|
extern void return_mmsc_conn(MmscGrp *m);
|
2007-09-17 13:07:30 +00:00
|
|
|
|
2010-10-21 17:51:16 +00:00
|
|
|
extern Octstr *get_mmsbox_queue_dir(Octstr *from, List *to, MmscGrp *m, Octstr **mmc_id);
|
|
|
|
#if 0
|
|
|
|
MmscGrp *start_mmsc_from_conf(mCfg *cfg, mCfgGrp *x, List *errors, List *warnings);
|
|
|
|
#endif
|
|
|
|
int mmsbox_stop_mmsc(Octstr *mmc);
|
|
|
|
|
|
|
|
int mmsbox_start_mmsc(Octstr *mmc_id);
|
|
|
|
|
2010-10-26 10:18:13 +00:00
|
|
|
MmscGrp *mmsbox_get_mmsc_by_url(Octstr *mmc_url);
|
2008-08-29 10:23:17 +00:00
|
|
|
void mmsbox_stop_all_mmsc_conn(void);
|
2008-07-18 21:30:18 +00:00
|
|
|
typedef struct MmsBoxHTTPClientInfo {
|
|
|
|
HTTPClient *client;
|
|
|
|
Octstr *ua;
|
|
|
|
Octstr *ip;
|
|
|
|
List *headers;
|
|
|
|
Octstr *url;
|
|
|
|
Octstr *body;
|
|
|
|
List *cgivars;
|
|
|
|
MmscGrp *m;
|
|
|
|
} MmsBoxHTTPClientInfo;
|
|
|
|
void free_mmsbox_http_clientInfo(MmsBoxHTTPClientInfo *h, int freeh);
|
2010-10-21 17:51:16 +00:00
|
|
|
|
|
|
|
extern volatile sig_atomic_t rstop;
|
2005-09-02 11:41:28 +00:00
|
|
|
#endif
|