summaryrefslogtreecommitdiffabout
path: root/gammu/emb/gammu/smsd/s_files.c
Unidiff
Diffstat (limited to 'gammu/emb/gammu/smsd/s_files.c') (more/less context) (ignore whitespace changes)
-rw-r--r--gammu/emb/gammu/smsd/s_files.c81
1 files changed, 64 insertions, 17 deletions
diff --git a/gammu/emb/gammu/smsd/s_files.c b/gammu/emb/gammu/smsd/s_files.c
index dac8d9c..b791e58 100644
--- a/gammu/emb/gammu/smsd/s_files.c
+++ b/gammu/emb/gammu/smsd/s_files.c
@@ -1,7 +1,7 @@
1/* (c) 2002-2003 by Joergen Thomsen */ 1/* (c) 2002-2004 by Joergen Thomsen */
2 2
3#include "../../cfg/config.h" 3#include "../../cfg/config.h"
4 4
5#include <string.h> 5#include <string.h>
6#include <stdio.h> 6#include <stdio.h>
7#include <errno.h> 7#include <errno.h>
@@ -103,35 +103,44 @@ static GSM_Error SMSDFiles_SaveInboxSMS(GSM_MultiSMSMessage sms, GSM_SMSDConfig
103 } 103 }
104 return ERR_NONE; 104 return ERR_NONE;
105} 105}
106 106
107/* Find one multi SMS to sending and return it (or return ERR_EMPTY) 107/* Find one multi SMS to sending and return it (or return ERR_EMPTY)
108 * There is also set ID for SMS 108 * There is also set ID for SMS
109 * File extension convention:
110 * OUTxxxxx.txt : normal text SMS
111 * Options appended to the extension applying to this SMS only:
112 * d: delivery report requested
113 * f: flash SMS
114 * b: WAP bookmark as name,URL
115 * e.g. OUTG20040620_193810_123_+4512345678_xpq.txtdf
116 * is a flash text SMS requesting delivery reports
109 */ 117 */
110static GSM_Error SMSDFiles_FindOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID) 118static GSM_Error SMSDFiles_FindOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID)
111{ 119{
112 GSM_Error error = ERR_NOTSUPPORTED; 120 GSM_Error error = ERR_NOTSUPPORTED;
113 GSM_MultiPartSMSInfo SMSInfo; 121 GSM_MultiPartSMSInfo SMSInfo;
122 GSM_WAPBookmark Bookmark;
114 unsigned char FileName[100],FullName[400]; 123 unsigned char FileName[100],FullName[400];
115 unsigned char Buffer[(GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS+1)*2]; 124 unsigned char Buffer[(GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS+1)*2];
116 unsigned char Buffer2[(GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS+1)*2]; 125 unsigned char Buffer2[(GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS+1)*2];
117 FILE *File; 126 FILE *File;
118 int i, len, phlen; 127 int i, len, phlen;
119 char *pos1, *pos2; 128 char *pos1, *pos2, *options;
120#if defined HAVE_DIRENT_H && defined HAVE_SCANDIR & defined HAVE_ALPHASORT 129#if defined HAVE_DIRENT_H && defined HAVE_SCANDIR & defined HAVE_ALPHASORT
121 struct dirent **namelist = NULL; 130 struct dirent **namelist = NULL;
122 int l, m ,n; 131 int l, m ,n;
123 132
124 strcpy(FullName, Config->outboxpath); 133 strcpy(FullName, Config->outboxpath);
125 FullName[strlen(Config->outboxpath)-1] = '\0'; 134 FullName[strlen(Config->outboxpath)-1] = '\0';
126 n = scandir(FullName, &namelist, 0, alphasort); 135 n = scandir(FullName, &namelist, 0, alphasort);
127 m = 0; 136 m = 0;
128 while ((m < n) && ((*(namelist[m]->d_name) == '.') || 137 while ((m < n) && ((*(namelist[m]->d_name) == '.') || // directory and UNIX hidden file
129 !mystrncasecmp(namelist[m]->d_name,"out", 3) || 138 !mystrncasecmp(namelist[m]->d_name,"out", 3) || // must start with 'out'
130 ((strlen(namelist[m]->d_name) >= 4) && 139 ((strlen(namelist[m]->d_name) >= 4) &&
131 !mystrncasecmp(&namelist[m]->d_name[strlen(namelist[m]->d_name)-4],".txt",4) 140 !mystrncasecmp(strrchr(namelist[m]->d_name, '.'),".txt",4)
132 ) 141 )
133 ) 142 )
134 ) m++; 143 ) m++;
135 if (m < n) strcpy(FileName,namelist[m]->d_name); 144 if (m < n) strcpy(FileName,namelist[m]->d_name);
136 for (l=0; l < n; l++) free(namelist[l]); 145 for (l=0; l < n; l++) free(namelist[l]);
137 free(namelist); 146 free(namelist);
@@ -141,58 +150,91 @@ static GSM_Error SMSDFiles_FindOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfi
141#else 150#else
142#ifdef WIN32 151#ifdef WIN32
143 struct _finddata_t c_file; 152 struct _finddata_t c_file;
144 long hFile; 153 long hFile;
145 154
146 strcpy(FullName, Config->outboxpath); 155 strcpy(FullName, Config->outboxpath);
147 strcat(FullName, "OUT*.txt"); 156 strcat(FullName, "OUT*.txt*");
148 if((hFile = _findfirst( FullName, &c_file )) == -1L ) { 157 if((hFile = _findfirst( FullName, &c_file )) == -1L ) {
149 return ERR_EMPTY; 158 return ERR_EMPTY;
150 } else { 159 } else {
151 strcpy(FileName,c_file.name); 160 strcpy(FileName,c_file.name);
152 } 161 }
153 _findclose( hFile ); 162 _findclose( hFile );
154 error = ERR_NONE; 163 error = ERR_NONE;
155#endif 164#endif
156#endif 165#endif
157 if (error != ERR_NONE) return error; 166 if (error != ERR_NONE) return error;
158 167 options = strrchr(FileName, '.') + 4;
159 strcpy(FullName, Config->outboxpath); 168 strcpy(FullName, Config->outboxpath);
160 strcat(FullName, FileName); 169 strcat(FullName, FileName);
161 170
162 File = fopen(FullName, "rb"); 171 File = fopen(FullName, "rb");
163 len = fread(Buffer, 1, sizeof(Buffer)-2, File); 172 len = fread(Buffer, 1, sizeof(Buffer)-2, File);
164 fclose(File); 173 fclose(File);
165 if (len<2) return ERR_EMPTY;
166 174
167 if ((Buffer[0] != 0xFF || Buffer[1] != 0xFE) && 175 if ((len < 2) ||
168 (Buffer[0] != 0xFE || Buffer[1] != 0xFF)) { 176 (len >= 2 && ((Buffer[0] != 0xFF || Buffer[1] != 0xFE) &&
177 (Buffer[0] != 0xFE || Buffer[1] != 0xFF)))) {
169 if (len > GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS) len = GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS; 178 if (len > GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS) len = GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS;
170 EncodeUnicode(Buffer2, Buffer, len); 179 EncodeUnicode(Buffer2, Buffer, len);
171 len = len*2; 180 len = len*2;
172 memmove(Buffer, Buffer2, len); 181 memmove(Buffer, Buffer2, len);
173 } 182 }
174 183
175 Buffer[len] = 0; 184 Buffer[len] = 0;
176 Buffer[len+1] = 0; 185 Buffer[len+1] = 0;
177 ReadUnicodeFile(Buffer2,Buffer); 186 ReadUnicodeFile(Buffer2,Buffer);
178 187
188 GSM_ClearMultiPartSMSInfo(&SMSInfo);
189 sms->Number = 0;
190
179 SMSInfo.ReplaceMessage = 0; 191 SMSInfo.ReplaceMessage = 0;
180 SMSInfo.Entries[0].Buffer= Buffer2; 192 SMSInfo.Entries[0].Buffer= Buffer2;
181 SMSInfo.Class = -1; 193 SMSInfo.Class = -1;
182 SMSInfo.EntriesNum = 1; 194 SMSInfo.EntriesNum = 1;
195 Config->currdeliveryreport= -1;
196 if (strchr(options, 'd')) Config->currdeliveryreport= 1;
197 if (strchr(options, 'f')) SMSInfo.Class = 0; /* flash SMS */
198
183 if (mystrncasecmp(Config->transmitformat, "unicode", 0)) { 199 if (mystrncasecmp(Config->transmitformat, "unicode", 0)) {
184 SMSInfo.Entries[0].ID = SMS_ConcatenatedTextLong; 200 SMSInfo.Entries[0].ID = SMS_ConcatenatedTextLong;
185 SMSInfo.UnicodeCoding = true; 201 SMSInfo.UnicodeCoding = true;
186 } else if (mystrncasecmp(Config->transmitformat, "7bit", 0)) { 202 } else if (mystrncasecmp(Config->transmitformat, "7bit", 0)) {
187 SMSInfo.Entries[0].ID = SMS_ConcatenatedTextLong; 203 SMSInfo.Entries[0].ID = SMS_ConcatenatedTextLong;
188 SMSInfo.UnicodeCoding = false; 204 SMSInfo.UnicodeCoding = false;
189 } else { 205 } else {
190 /* auto */ 206 /* auto */
191 SMSInfo.Entries[0].ID = SMS_ConcatenatedAutoTextLong; 207 SMSInfo.Entries[0].ID = SMS_ConcatenatedAutoTextLong;
192 } 208 }
209
210 if (strchr(options, 'b')) { // WAP bookmark as title,URL
211 SMSInfo.Entries[0].Buffer = NULL;
212 SMSInfo.Entries[0].Bookmark = &Bookmark;
213 SMSInfo.Entries[0].ID = SMS_NokiaWAPBookmarkLong;
214 SMSInfo.Entries[0].Bookmark->Location= 0;
215 pos2 = mywstrstr(Buffer2, "\0,");
216 if (pos2 == NULL) {
217 pos2 = Buffer2;
218 } else {
219 *pos2 = '\0'; pos2++; *pos2 = '\0'; pos2++; // replace comma by zero
220 }
221
222 len = UnicodeLength(Buffer2);
223 if (len > 50) len = 50;
224 memmove(&SMSInfo.Entries[0].Bookmark->Title, Buffer2, len * 2);
225 pos1 = &SMSInfo.Entries[0].Bookmark->Title[0] + len * 2;
226 *pos1 = '\0'; pos1++; *pos1 = '\0';
227
228 len = UnicodeLength(pos2);
229 if (len > 255) len = 255;
230 memmove(&SMSInfo.Entries[0].Bookmark->Address, pos2, len * 2);
231 pos1 = &SMSInfo.Entries[0].Bookmark->Address[0] + len * 2;
232 *pos1 = '\0'; pos1++; *pos1 = '\0';
233 }
234
193 GSM_EncodeMultiPartSMS(&SMSInfo,sms); 235 GSM_EncodeMultiPartSMS(&SMSInfo,sms);
194 236
195 pos1 = FileName; 237 pos1 = FileName;
196 strcpy(ID,FileName); 238 strcpy(ID,FileName);
197 for (i = 1; i <= 3 && pos1 != NULL ; i++) pos1 = strchr(++pos1, '_'); 239 for (i = 1; i <= 3 && pos1 != NULL ; i++) pos1 = strchr(++pos1, '_');
198 if (pos1 != NULL) { 240 if (pos1 != NULL) {
@@ -227,21 +269,23 @@ static GSM_Error SMSDFiles_FindOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfi
227 EncodeUnicode(sms->SMS[len].Number, pos1, phlen); 269 EncodeUnicode(sms->SMS[len].Number, pos1, phlen);
228 } 270 }
229 271
230#ifdef DEBUG 272#ifdef DEBUG
231 if (sms->Number != 0) { 273 if (sms->Number != 0) {
232 DecodeUnicode(sms->SMS[0].Number,Buffer); 274 DecodeUnicode(sms->SMS[0].Number,Buffer);
233 dbgprintf("Found %i sms to \"%s\" with text \"%s\" cod %i lgt %i udh: t %i l %i\n", 275 dbgprintf("Found %i sms to \"%s\" with text \"%s\" cod %i lgt %i udh: t %i l %i dlr: %i fls: %i",
234 sms->Number, 276 sms->Number,
235 Buffer, 277 Buffer,
236 DecodeUnicodeString(sms->SMS[0].Text), 278 DecodeUnicodeString(sms->SMS[0].Text),
237 sms->SMS[0].Coding, 279 sms->SMS[0].Coding,
238 sms->SMS[0].Length, 280 sms->SMS[0].Length,
239 sms->SMS[0].UDH.Type, 281 sms->SMS[0].UDH.Type,
240 sms->SMS[0].UDH.Length); 282 sms->SMS[0].UDH.Length,
241 } else dbgprintf("error\n"); 283 Config->currdeliveryreport,
284 SMSInfo.Class);
285 } else dbgprintf("error: SMS-count = 0");
242#endif 286#endif
243 287
244 return ERR_NONE; 288 return ERR_NONE;
245} 289}
246 290
247/* After sending SMS is moved to Sent Items or Error Items. */ 291/* After sending SMS is moved to Sent Items or Error Items. */
@@ -289,25 +333,28 @@ static GSM_Error SMSDFiles_MoveSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Con
289 WriteSMSDLog("Could not delete %s (%i)", ifilename, errno); 333 WriteSMSDLog("Could not delete %s (%i)", ifilename, errno);
290 } 334 }
291 return ERR_UNKNOWN; 335 return ERR_UNKNOWN;
292 } 336 }
293} 337}
294 338
295static GSM_Error SMSDFiles_AddSentSMSInfo(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, int Part, bool OK) 339static GSM_Error SMSDFiles_AddSentSMSInfo(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, int Part, GSM_SMSDSendingError err, int TPMR)
296{ 340{
297 if (OK) WriteSMSDLog("Transmitted %s (%s: %i) to %s", Config->SMSID, (Part == sms->Number?"total":"part"),Part,DecodeUnicodeString(sms->SMS[0].Number)); 341 if (err == SMSD_SEND_OK) WriteSMSDLog("Transmitted %s (%s: %i) to %s", Config->SMSID, (Part == sms->Number?"total":"part"),Part,DecodeUnicodeString(sms->SMS[0].Number));
298 342
299 return ERR_NONE; 343 return ERR_NONE;
300} 344}
301 345
302GSM_SMSDService SMSDFiles = { 346GSM_SMSDService SMSDFiles = {
303 NONEFUNCTION, /* Init */ 347 NONEFUNCTION, /* Init */
348 NONEFUNCTION, /* InitAfterConnect */
304 SMSDFiles_SaveInboxSMS, 349 SMSDFiles_SaveInboxSMS,
305 SMSDFiles_FindOutboxSMS, 350 SMSDFiles_FindOutboxSMS,
306 SMSDFiles_MoveSMS, 351 SMSDFiles_MoveSMS,
307 NOTSUPPORTED, /* CreateOutboxSMS*/ 352 NOTSUPPORTED, /* CreateOutboxSMS*/
308 SMSDFiles_AddSentSMSInfo 353 SMSDFiles_AddSentSMSInfo,
354 NOTSUPPORTED, /* RefreshSendStatus*/
355 NOTSUPPORTED /* RefreshPhoneStatus*/
309}; 356};
310 357
311/* How should editor hadle tabs in this file? Add editor commands here. 358/* How should editor handle tabs in this file? Add editor commands here.
312 * vim: noexpandtab sw=8 ts=8 sts=8: 359 * vim: noexpandtab sw=8 ts=8 sts=8:
313 */ 360 */