1 /* (c) 2002-2004 by Marcin Wiacek and Joergen Thomsen */
2 /* Copyright (c) 2009 - 2011 Michal Cihar <michal@cihar.com> */
8 #include <gammu-smsd.h>
11 #include <sys/types.h>
13 /* definition of dbobject */
14 #if defined(HAVE_MYSQL_MYSQL_H) || defined(HAVE_POSTGRESQL_LIBPQ_FE_H) || defined(LIBDBI_FOUND) || defined(ODBC_FOUND)
15 #include "services/sql-core.h"
18 #define SMSD_SHM_KEY (0xface)
19 #define SMSD_SHM_VERSION (1)
20 #define SMSD_DB_VERSION (13)
24 #include "../helper/array.h"
43 SMSD_SEND_SENDING_ERROR
,
44 SMSD_SEND_DELIVERY_PENDING
,
45 SMSD_SEND_DELIVERY_FAILED
,
46 SMSD_SEND_DELIVERY_OK
,
47 SMSD_SEND_DELIVERY_UNKNOWN
,
49 } GSM_SMSDSendingError
;
52 GSM_Error (*Init
) (GSM_SMSDConfig
*Config
);
53 GSM_Error (*Free
) (GSM_SMSDConfig
*Config
);
54 GSM_Error (*InitAfterConnect
) (GSM_SMSDConfig
*Config
);
55 GSM_Error (*SaveInboxSMS
) (GSM_MultiSMSMessage
*sms
, GSM_SMSDConfig
*Config
, char **Locations
);
56 GSM_Error (*FindOutboxSMS
) (GSM_MultiSMSMessage
*sms
, GSM_SMSDConfig
*Config
, char *ID
);
57 GSM_Error (*MoveSMS
) (GSM_MultiSMSMessage
*sms
, GSM_SMSDConfig
*Config
, char *ID
, gboolean alwaysDelete
, gboolean sent
);
58 GSM_Error (*CreateOutboxSMS
) (GSM_MultiSMSMessage
*sms
, GSM_SMSDConfig
*Config
, char *NewID
);
59 GSM_Error (*AddSentSMSInfo
) (GSM_MultiSMSMessage
*sms
, GSM_SMSDConfig
*Config
, char *ID
, int Part
, GSM_SMSDSendingError err
, int TPMR
);
60 GSM_Error (*RefreshSendStatus
) (GSM_SMSDConfig
*Config
, char *ID
);
62 * Updates phone status in service backend. Please note that
63 * this can not talk to the phone.
65 GSM_Error (*RefreshPhoneStatus
) (GSM_SMSDConfig
*Config
);
67 * Reads configuration specific for this backend.
69 GSM_Error (*ReadConfiguration
) (GSM_SMSDConfig
*Config
);
72 struct _GSM_SMSDConfig
{
73 const char *ServiceName
;
74 const char *program_name
;
76 GSM_StringArray IncludeNumbersList
, ExcludeNumbersList
;
77 GSM_StringArray IncludeSMSCList
, ExcludeSMSCList
;
78 unsigned int commtimeout
, sendtimeout
, receivefrequency
, statusfrequency
;
79 unsigned int loopsleep
;
80 int deliveryreportdelay
;
81 unsigned int resetfrequency
;
82 unsigned int hardresetfrequency
;
83 unsigned int multiparttimeout
;
84 const char *deliveryreport
, *logfilename
, *logfacility
, *PINCode
, *NetworkCode
, *PhoneCode
;
86 const char *RunOnReceive
;
87 const char *RunOnFailure
; /* run this command on phone communication failure */
88 gboolean checksecurity
;
89 gboolean checkbattery
;
92 gboolean enable_receive
;
93 unsigned int maxretries
;
96 /* options for FILES */
97 const char *inboxpath
, *outboxpath
, *sentsmspath
;
98 const char *errorsmspath
, *inboxformat
, *transmitformat
, *outboxformat
;
100 /* private variables required for work */
101 int relativevalidity
;
102 unsigned int retries
;
103 int currdeliveryreport
;
104 unsigned char SMSID
[200], prevSMSID
[200];
105 GSM_SMSC SMSC
, SMSCCache
;
106 const char *skipsmscnumber
;
108 #if defined(HAVE_MYSQL_MYSQL_H) || defined(HAVE_POSTGRESQL_LIBPQ_FE_H) || defined(LIBDBI_FOUND) || defined(ODBC_FOUND)
109 /* options for SQL database */
113 const char *database
;
115 * User name to connect to database.
119 * User password to connect to database.
121 const char *password
;
123 * Database driver to use.
127 * Path to database drivers.
129 const char *driverspath
;
131 * SQL dialect to use.
135 * Path to database directory.
139 * Address of the database (eg. hostname).
144 /* database data structure */
145 struct GSM_SMSDdbobj
*db
;
149 INI_Section
*smsdcfgfile
;
150 volatile gboolean shutdown
;
152 * Whether SMSD daemon itself is running.
156 * Whether we're connected to the database.
159 gboolean exit_on_failure
;
161 GSM_StateMachine
*gsm
;
162 char *gammu_log_buffer
;
163 size_t gammu_log_buffer_size
;
165 * Log critical messages to stderr?
169 * Log with timestamps (not applicable for syslog).
171 gboolean use_timestamps
;
174 * Where to send log messages.
176 SMSD_LogType log_type
;
179 volatile GSM_Error SendingSMSStatus
;
181 * Message reference set by callback from libGammu.
186 * Multipart messages processing.
188 int IncompleteMessageID
;
189 time_t IncompleteMessageTime
;
196 char map_key
[MAX_PATH
+ 20];
199 GSM_SMSDStatus
*Status
;
200 GSM_SMSDService
*Service
;
203 extern GSM_Error
SMSD_NoneFunction (void);
204 extern GSM_Error
SMSD_EmptyFunction (void);
205 extern GSM_Error
SMSD_NotImplementedFunction (void);
206 extern GSM_Error
SMSD_NotSupportedFunction (void);
209 #define NONEFUNCTION (void *) SMSD_NoneFunction
210 #define EMPTYFUNCTION (void *) SMSD_EmptyFunction
211 #define NOTIMPLEMENTED (void *) SMSD_NotImplementedFunction
212 #define NOTSUPPORTED (void *) SMSD_NotSupportedFunction
215 * Checks whether database version is up to date.
217 GSM_Error
SMSD_CheckDBVersion(GSM_SMSDConfig
*Config
, int version
);
220 * Terminates SMSD with logging error messages to log. This does not
221 * signal running SMSD to stop, it can be called from initialization of
222 * SMSD wrapping program to terminate with logging.
224 * \param Config Pointer to SMSD configuration data.
225 * \param msg Message to display.
226 * \param error GSM error code, if applicable.
227 * \param rc Program return code, will be passed to exit (if enabled).
229 void SMSD_Terminate(GSM_SMSDConfig
*Config
, const char *msg
, GSM_Error error
, gboolean exitprogram
, int rc
);
233 /* How should editor hadle tabs in this file? Add editor commands here.
234 * vim: noexpandtab sw=8 ts=8 sts=8: