Translation update done using Pootle.
[gammu.git] / smsd / core.h
blob9cac06c5062e813a5f84d5edbb13190255257de1
1 /* (c) 2002-2004 by Marcin Wiacek and Joergen Thomsen */
2 /* Copyright (c) 2009 - 2011 Michal Cihar <michal@cihar.com> */
4 #ifndef __core_h_
5 #define __core_h_
7 #include <gammu.h>
8 #include <gammu-smsd.h>
10 #ifdef HAVE_SHM
11 #include <sys/types.h>
12 #endif
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"
16 #endif
18 #define SMSD_SHM_KEY (0xface)
19 #define SMSD_SHM_VERSION (1)
20 #define SMSD_DB_VERSION (13)
22 #include "log.h"
24 #include "../helper/array.h"
26 typedef enum {
27 DEBUG_ERROR = -1,
28 DEBUG_INFO = 0,
29 DEBUG_NOTICE = 1,
30 DEBUG_SQL = 2,
31 DEBUG_GAMMU = 4,
32 } SMSD_DebugLevel;
34 typedef enum {
35 SMSD_LOG_NONE,
36 SMSD_LOG_FILE,
37 SMSD_LOG_SYSLOG,
38 SMSD_LOG_EVENTLOG
39 } SMSD_LogType;
41 typedef enum {
42 SMSD_SEND_OK = 1,
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,
48 SMSD_SEND_ERROR
49 } GSM_SMSDSendingError;
51 typedef struct {
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);
61 /**
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);
66 /**
67 * Reads configuration specific for this backend.
69 GSM_Error (*ReadConfiguration) (GSM_SMSDConfig *Config);
70 } GSM_SMSDService;
72 struct _GSM_SMSDConfig {
73 const char *ServiceName;
74 const char *program_name;
75 /* general options */
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;
85 const char *PhoneID;
86 const char *RunOnReceive;
87 const char *RunOnFailure; /* run this command on phone communication failure */
88 gboolean checksecurity;
89 gboolean checkbattery;
90 gboolean checksignal;
91 gboolean enable_send;
92 gboolean enable_receive;
93 unsigned int maxretries;
94 int backend_retries;
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 */
111 * Database name.
113 const char *database;
115 * User name to connect to database.
117 const char *user;
119 * User password to connect to database.
121 const char *password;
123 * Database driver to use.
125 const char *driver;
127 * Path to database drivers.
129 const char *driverspath;
131 * SQL dialect to use.
133 const char *sql;
135 * Path to database directory.
137 const char *dbdir;
139 * Address of the database (eg. hostname).
141 const char *host;
142 char DT[40];
143 char CreatorID[200];
144 /* database data structure */
145 struct GSM_SMSDdbobj *db;
146 SQL_conn conn;
147 #endif
149 INI_Section *smsdcfgfile;
150 volatile gboolean shutdown;
152 * Whether SMSD daemon itself is running.
154 gboolean running;
156 * Whether we're connected to the database.
158 gboolean connected;
159 gboolean exit_on_failure;
160 GSM_Error failure;
161 GSM_StateMachine *gsm;
162 char *gammu_log_buffer;
163 size_t gammu_log_buffer_size;
165 * Log critical messages to stderr?
167 gboolean use_stderr;
169 * Log with timestamps (not applicable for syslog).
171 gboolean use_timestamps;
172 int debug_level;
174 * Where to send log messages.
176 SMSD_LogType log_type;
177 void *log_handle;
179 volatile GSM_Error SendingSMSStatus;
181 * Message reference set by callback from libGammu.
183 volatile int TPMR;
186 * Multipart messages processing.
188 int IncompleteMessageID;
189 time_t IncompleteMessageTime;
191 #ifdef HAVE_SHM
192 key_t shm_key;
193 int shm_handle;
194 #endif
195 #ifdef WIN32
196 char map_key[MAX_PATH + 20];
197 HANDLE map_handle;
198 #endif
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);
231 #endif
233 /* How should editor hadle tabs in this file? Add editor commands here.
234 * vim: noexpandtab sw=8 ts=8 sts=8: