1 #define _GNU_SOURCE /* For strcasestr */
2 #include <string.h>
3 #include <stdarg.h>
4 #include <signal.h>
5 #include <stdlib.h>
6 #include <ctype.h>
7 #ifdef WIN32
8 #  include <io.h>
9 #else
10 #  include <unistd.h>
11 #endif
12 
13 #include "../helper/locales.h"
14 
15 #include "gammu-message.h"
16 #include "common.h"
17 #include "message.h"
18 #include "memory.h"
19 #include "../helper/formats.h"
20 #include "calendar.h"
21 #include "misc.h"
22 #include "backup.h"
23 
24 #include "../helper/message-display.h"
25 #include "../helper/memory-display.h"
26 #include "../helper/message-cmdline.h"
27 #include "../helper/printing.h"
28 #include "../libgammu/misc/string.h"
29 #include "../helper/cmdline.h"
30 
31 volatile gboolean 			wasincomingsms 		= FALSE;
32 volatile int num_replies = 0;
33 
34 GSM_MultiSMSMessage		IncomingSMSData;
35 
IncomingSMS(GSM_StateMachine * sm UNUSED,GSM_SMSMessage * sms,void * user_data)36 void IncomingSMS(GSM_StateMachine *sm UNUSED, GSM_SMSMessage *sms, void *user_data)
37 {
38 	printf("%s\n", _("SMS message received"));
39 	fflush(stdout);
40 
41  	if (wasincomingsms) {
42  		printf("%s\n", _("We already have one pending, ignoring this one!"));
43 		fflush(stdout);
44  		return;
45  	}
46  	wasincomingsms = TRUE;
47  	IncomingSMSData.SMS[0] = *sms;
48  	IncomingSMSData.Number = 1;
49 }
50 
DisplayIncomingSMS(void)51 void DisplayIncomingSMS(void)
52 {
53  	GSM_SMSFolders folders;
54 	GSM_Error error;
55 
56  	if (IncomingSMSData.SMS[0].State == 0) {
57  		error=GSM_GetSMSFolders(gsm, &folders);
58  		Print_Error(error);
59 
60  		error=GSM_GetSMS(gsm, &IncomingSMSData);
61 
62  		switch (error) {
63  		case ERR_EMPTY:
64  			printf(_("Location %i\n"),IncomingSMSData.SMS[0].Location);
65  			printf("%s\n", _("Empty"));
66 			fflush(stdout);
67  			break;
68  		default:
69  			Print_Error(error);
70 			PrintSMSLocation(&IncomingSMSData.SMS[0], &folders);
71  		}
72  	}
73  	DisplayMultiSMSInfo(&IncomingSMSData,FALSE,FALSE,NULL, gsm);
74  	wasincomingsms = FALSE;
75 }
76 
IncomingCB(GSM_StateMachine * sm UNUSED,GSM_CBMessage * CB,void * user_data)77 void IncomingCB(GSM_StateMachine *sm UNUSED, GSM_CBMessage *CB, void *user_data)
78 {
79 	printf("%s\n", _("CB message received"));
80 	printf(_("Channel %i, text \"%s\"\n"),CB->Channel,DecodeUnicodeConsole(CB->Text));
81 	fflush(stdout);
82 }
83 
IncomingUSSD(GSM_StateMachine * sm UNUSED,GSM_USSDMessage * ussd,void * user_data)84 void IncomingUSSD(GSM_StateMachine *sm UNUSED, GSM_USSDMessage *ussd, void *user_data)
85 {
86 	printf("%s\n", _("USSD received"));
87 	printf(LISTFORMAT, _("Status"));
88 
89 	switch(ussd->Status) {
90 		case USSD_NoActionNeeded:
91 			printf("%s\n", _("No action needed"));
92 			break;
93 		case USSD_ActionNeeded:
94 			printf("%s\n", _("Action needed"));
95 			break;
96 		case USSD_Terminated:
97 			printf("%s\n", _("Terminated"));
98 			break;
99 		case USSD_AnotherClient:
100 			printf("%s\n", _("Another client replied"));
101 			break;
102 		case USSD_NotSupported:
103 			printf("%s\n", _("Not supported"));
104 			break;
105 		case USSD_Timeout:
106 			printf("%s\n", _("Timeout"));
107 			break;
108 #ifndef CHECK_CASES
109 		default:
110 #endif
111 		case USSD_Unknown:
112 			printf("%s\n", _("Unknown"));
113 			break;
114 	}
115 	printf(LISTFORMAT "\"%s\"\n", _("Service reply"), DecodeUnicodeConsole(ussd->Text));
116 	fflush(stdout);
117 }
118 
IncomingUSSD2(GSM_StateMachine * sm,GSM_USSDMessage * ussd,void * user_data)119 void IncomingUSSD2(GSM_StateMachine *sm, GSM_USSDMessage *ussd, void * user_data)
120 {
121 	IncomingUSSD(sm, ussd, user_data);
122 	num_replies++;
123 }
124 
GetUSSD(int argc UNUSED,char * argv[])125 void GetUSSD(int argc UNUSED, char *argv[])
126 {
127 	GSM_Error error;
128 	int last_replies;
129 	time_t last_reply;
130 
131 	GSM_Init(TRUE);
132 
133 	signal(SIGINT, interrupt);
134 	fprintf(stderr, "%s\n", _("Press Ctrl+C to break…"));
135 	fflush(stderr);
136 
137 	GSM_SetIncomingUSSDCallback(gsm, IncomingUSSD2, NULL);
138 
139 	error = GSM_SetIncomingUSSD(gsm, TRUE);
140 	Print_Error(error);
141 
142 	num_replies = 0;
143 
144 	error = GSM_DialService(gsm, argv[2]);
145 	/* Fallback to voice call, it can work with some phones */
146 	if (error == ERR_NOTIMPLEMENTED || error == ERR_NOTSUPPORTED) {
147 		error = GSM_DialVoice(gsm, argv[2], GSM_CALL_DefaultNumberPresence);
148 	}
149 	Print_Error(error);
150 
151 	last_replies = 0;
152 	last_reply = time(NULL);
153 	while (!gshutdown) {
154 		if (num_replies != last_replies) {
155 			last_replies = num_replies;
156 			last_reply = time(NULL);
157 		} else if (num_replies == 0 && difftime(time(NULL), last_reply) > 60) {
158 			/* Wait one minute for reply */
159 			gshutdown = TRUE;
160 		} else if (num_replies > 0 && difftime(time(NULL), last_reply) > 10) {
161 			/* Wait for consequent replies for 10 seconds */
162 			gshutdown = TRUE;
163 		}
164 
165 		GSM_ReadDevice(gsm, FALSE);
166 	}
167 
168 	error = GSM_SetIncomingUSSD(gsm, FALSE);
169 	Print_Error(error);
170 
171 	GSM_Terminate();
172 }
173 
SetSMSC(int argc,char * argv[])174 void SetSMSC(int argc, char *argv[])
175 {
176 	GSM_Error error;
177 	GSM_SMSC smsc;
178 
179 	smsc.Location = GetInt(argv[2]);
180 	if (smsc.Location < 1) {
181 		printf_err(_("Invalid SMSC location: %s\n"), argv[2]);
182 		return;
183 	}
184 	GSM_Init(TRUE);
185 
186 	error = GSM_GetSMSC(gsm, &smsc);
187 	Print_Error(error);
188 
189 	EncodeUnicode(smsc.Number, argv[3], strlen(argv[3]));
190 
191 	error = GSM_SetSMSC(gsm, &smsc);
192 	Print_Error(error);
193 
194 	GSM_Terminate();
195 }
196 
GetSMSC(int argc,char * argv[])197 void GetSMSC(int argc, char *argv[])
198 {
199 	GSM_SMSC smsc;
200 	GSM_Error error;
201 	int start=0, stop=0, i=0;
202 
203 	if (argc == 2) {
204 		start = 1;
205 		stop = 1;
206 	} else {
207 		GetStartStop(&start, &stop, 2, argc, argv);
208 	}
209 
210 	GSM_Init(TRUE);
211 
212 	for (i=start;i<=stop;i++) {
213 		smsc.Location=i;
214 
215 		error=GSM_GetSMSC(gsm, &smsc);
216 		Print_Error(error);
217 
218 		printf(LISTFORMAT "%d\n", _("Location"), smsc.Location);
219 
220 		if (UnicodeLength(smsc.Name) != 0) {
221 			printf(LISTFORMAT "\"%s\"\n", _("Name"),DecodeUnicodeConsole(smsc.Name));
222 		}
223 		printf(LISTFORMAT "\"%s\"\n", _("Number"),DecodeUnicodeConsole(smsc.Number));
224 		printf(LISTFORMAT "\"%s\"\n", _("Default number"),DecodeUnicodeConsole(smsc.DefaultNumber));
225 
226 		printf(LISTFORMAT, _("Format"));
227 		switch (smsc.Format) {
228 			case SMS_FORMAT_Text	: printf("%s", _("Text"));	break;
229 			case SMS_FORMAT_Fax	: printf("%s", _("Fax"));	break;
230 			case SMS_FORMAT_Email	: printf("%s", _("Email"));	break;
231 			case SMS_FORMAT_Pager	: printf("%s", _("Pager"));	break;
232 		}
233 		printf("\n");
234 
235 		printf(LISTFORMAT, _("Validity"));
236 
237 		switch (smsc.Validity.Relative) {
238 			case SMS_VALID_1_Hour	:
239 				PRINTHOURS(1);
240 				break;
241 			case SMS_VALID_6_Hours 	:
242 				PRINTHOURS(6);
243 				break;
244 			case SMS_VALID_1_Day	:
245 				PRINTDAYS(1);
246 				break;
247 			case SMS_VALID_3_Days	:
248 				PRINTDAYS(3);
249 				break;
250 			case SMS_VALID_1_Week  	:
251 				PRINTWEEKS(1);
252 				break;
253 			case SMS_VALID_Max_Time	:
254 				printf("%s", _("Maximum time"));
255 				break;
256 			default:
257 				/* Typecasting is here needed to silent GCC warning.
258 				 * Validity usually fits in some unsigned type so it is always >= 0 */
259 				if ((int)smsc.Validity.Relative >= 0 && smsc.Validity.Relative <= 143) {
260 					PRINTMINUTES((smsc.Validity.Relative + 1) * 5);
261 				} else if (smsc.Validity.Relative >= 144 && smsc.Validity.Relative <= 167) {
262 					PRINTMINUTES(12 * 60 + (smsc.Validity.Relative - 143) * 30);
263 				} else if (smsc.Validity.Relative >= 168 && smsc.Validity.Relative <= 196) {
264 					PRINTDAYS(smsc.Validity.Relative - 166);
265 				} else if (smsc.Validity.Relative >= 197 && smsc.Validity.Relative <= 255) {
266 					PRINTWEEKS(smsc.Validity.Relative - 192);
267 				}
268 		}
269 		printf("\n");
270 		fflush(stdout);
271 	}
272 	GSM_Terminate();
273 }
274 
GetSMS(int argc,char * argv[])275 void GetSMS(int argc, char *argv[])
276 {
277 	GSM_Error error;
278 	GSM_MultiSMSMessage sms;
279 	GSM_SMSFolders folders;
280 	int start=0, stop=0, j=0;
281 	long int folder;
282 
283 	GetStartStop(&start, &stop, 3, argc, argv);
284 	folder = GetInt(argv[2]);
285 
286 	GSM_Init(TRUE);
287 
288 	error=GSM_GetSMSFolders(gsm, &folders);
289 	Print_Error(error);
290 
291 	for (j = start; j <= stop; j++) {
292 		sms.SMS[0].Folder	= folder;
293 		sms.SMS[0].Location	= j;
294 		sms.Number = 0;
295 		error=GSM_GetSMS(gsm, &sms);
296 		switch (error) {
297 		case ERR_EMPTY:
298 			printf(_("Location %i\n"),sms.SMS[0].Location);
299 			printf("%s\n", _("Empty"));
300 			break;
301 		default:
302 			Print_Error(error);
303 			PrintSMSLocation(&sms.SMS[0], &folders);
304 			DisplayMultiSMSInfo(&sms,FALSE,FALSE,NULL, gsm);
305 		}
306 	}
307 	fflush(stdout);
308 	GSM_Terminate();
309 }
310 
DeleteSMS(int argc,char * argv[])311 void DeleteSMS(int argc, char *argv[])
312 {
313 	GSM_Error error;
314 	GSM_SMSMessage sms;
315 	int start=0, stop=0, i=0;
316 
317 	memset(&sms, 0, sizeof(GSM_SMSMessage));
318 	sms.Folder = GetInt(argv[2]);
319 
320 	GetStartStop(&start, &stop, 3, argc, argv);
321 
322 	GSM_Init(TRUE);
323 
324 	for (i=start;i<=stop;i++) {
325 		sms.Location	= i;
326 		error=GSM_DeleteSMS(gsm, &sms);
327 		Print_Error(error);
328 	}
329 	GSM_Terminate();
330 }
331 
GetAllSMS(int argc,char * argv[])332 void GetAllSMS(int argc, char *argv[])
333 {
334 	GSM_Error error;
335 	GSM_MultiSMSMessage 	sms;
336 	GSM_SMSFolders		folders;
337 	gboolean		start = TRUE;
338 	int			smsnum=0,smspos=0;
339 #ifndef GSM_ENABLE_BACKUP
340 	void			*BackupPtr = NULL;
341 #else
342 	GSM_Backup		*BackupPtr = NULL;
343 	GSM_Backup		Backup;
344 
345 	GSM_ClearBackup(&Backup);
346 	BackupPtr = &Backup;
347 #endif
348 
349 	sms.Number = 0;
350 	sms.SMS[0].Location = 0;
351 
352 	GSM_Init(TRUE);
353 
354 #ifdef GSM_ENABLE_BACKUP
355 	if (argc == 3 && strcasecmp(argv[2],"-pbk") == 0) {
356 		ReadPhonebook(Backup.PhonePhonebook, MEM_ME, NULL, GSM_BACKUP_MAX_PHONEPHONEBOOK, NULL, TRUE);
357 		ReadPhonebook(Backup.SIMPhonebook, MEM_SM, NULL, GSM_BACKUP_MAX_SIMPHONEBOOK, NULL, TRUE);
358 	}
359 #endif
360 
361 	error=GSM_GetSMSFolders(gsm, &folders);
362 	Print_Error(error);
363 
364 	while (error == ERR_NONE) {
365 		sms.SMS[0].Folder=0x00;
366 		error=GSM_GetNextSMS(gsm, &sms, start);
367 
368 		switch (error) {
369 		case ERR_EMPTY:
370 			break;
371 		case ERR_CORRUPTED:
372 			fprintf(stderr, "\n%s\n", _("Corrupted message, skipping"));
373 			fflush(stderr);
374 			error = ERR_NONE;
375 			continue;
376 		default:
377 			Print_Error(error);
378 			PrintSMSLocation(&sms.SMS[0], &folders);
379 			smspos++;
380 			smsnum+=sms.Number;
381 			DisplayMultiSMSInfo(&sms, FALSE, FALSE, BackupPtr, gsm);
382 		}
383 		start=FALSE;
384 	}
385 	printf("\n\n");
386 	printf(_("%i SMS parts in %i SMS sequences"),smsnum,smspos);
387 	printf("\n");
388 	fflush(stdout);
389 
390 #ifdef GSM_ENABLE_BACKUP
391 	GSM_FreeBackup(&Backup);
392 #endif
393 	GSM_Terminate();
394 }
395 
GetEachSMS(int argc,char * argv[])396 void GetEachSMS(int argc, char *argv[])
397 {
398 	GSM_Error error;
399 	GSM_MultiSMSMessage	**GetSMSData,**SortedSMS,sms;
400 	GSM_SMSFolders		folders;
401 	gboolean		start=TRUE, ems=TRUE;
402 	int			GetSMSNumber=0,i=0,j=0,smsnum=0,smspos=0;
403 #ifndef GSM_ENABLE_BACKUP
404 	void			*BackupPtr = NULL;
405 #else
406 	GSM_Backup		*BackupPtr = NULL;
407 	GSM_Backup		Backup;
408 
409 	GSM_ClearBackup(&Backup);
410 	BackupPtr = &Backup;
411 #endif
412 	GetSMSData = malloc(GSM_PHONE_MAXSMSINFOLDER * sizeof(GSM_MultiSMSMessage*));
413 	SortedSMS = malloc(GSM_PHONE_MAXSMSINFOLDER * sizeof(GSM_MultiSMSMessage*));
414 
415 	sms.Number = 0;
416 	sms.SMS[0].Location = 0;
417 
418 	GetSMSData[0] = NULL;
419 
420 	GSM_Init(TRUE);
421 
422 #ifdef GSM_ENABLE_BACKUP
423 	if (argc == 3 && strcasecmp(argv[2],"-pbk") == 0) {
424 		ReadPhonebook(Backup.PhonePhonebook, MEM_ME, NULL, GSM_BACKUP_MAX_PHONEPHONEBOOK, NULL, TRUE);
425 		ReadPhonebook(Backup.SIMPhonebook, MEM_SM, NULL, GSM_BACKUP_MAX_SIMPHONEBOOK, NULL, TRUE);
426 	}
427 #endif
428 
429 	error=GSM_GetSMSFolders(gsm, &folders);
430 	Print_Error(error);
431 
432 	fprintf(stderr, LISTFORMAT, _("Reading"));
433 
434 	while (error == ERR_NONE) {
435 		if (GetSMSNumber==GSM_PHONE_MAXSMSINFOLDER-1) {
436 			fprintf(stderr, "\n%s\n", _("SMS counter overflow"));
437 			break;
438 		}
439 		sms.SMS[0].Folder=0x00;
440 		error=GSM_GetNextSMS(gsm, &sms, start);
441 
442 		switch (error) {
443 		case ERR_EMPTY:
444 			break;
445 		case ERR_CORRUPTED:
446 			fprintf(stderr, "\n%s\n", _("Corrupted message, skipping"));
447 			error = ERR_NONE;
448 			continue;
449 		default:
450 			Print_Error(error);
451 			GetSMSData[GetSMSNumber] = malloc(sizeof(GSM_MultiSMSMessage));
452 
453 		        if (GetSMSData[GetSMSNumber] == NULL) Print_Error(ERR_MOREMEMORY);
454 			GetSMSData[GetSMSNumber+1] = NULL;
455 			memcpy(GetSMSData[GetSMSNumber],&sms,sizeof(GSM_MultiSMSMessage));
456 			GetSMSNumber++;
457 		}
458 		fprintf(stderr,"*");
459 		fflush(stderr);
460 		start=FALSE;
461 	}
462 	fprintf(stderr,"\n");
463 	fflush(stderr);
464 
465 	error = GSM_LinkSMS(GSM_GetDebug(gsm), GetSMSData, SortedSMS, ems);
466 	Print_Error(error);
467 
468 	i=0;
469 
470 	while(GetSMSData[i] != NULL) {
471 		free(GetSMSData[i]);
472 		GetSMSData[i] = NULL;
473 		i++;
474 	}
475 
476 	i=0;
477 
478 	while(SortedSMS[i] != NULL) {
479 		smspos++;
480 
481 		for (j=0;j<SortedSMS[i]->Number;j++) {
482 			smsnum++;
483 
484 			if ((j==0) || (j!=0 && SortedSMS[i]->SMS[j].Location != SortedSMS[i]->SMS[j-1].Location)) {
485 				PrintSMSLocation(&SortedSMS[i]->SMS[j], &folders);
486 			}
487 		}
488 		DisplayMultiSMSInfo(SortedSMS[i], TRUE, ems, BackupPtr, gsm);
489 
490 		free(SortedSMS[i]);
491 		SortedSMS[i] = NULL;
492 		i++;
493 	}
494 
495 #ifdef GSM_ENABLE_BACKUP
496 	GSM_FreeBackup(&Backup);
497 #endif
498 	free(SortedSMS);
499 	free(GetSMSData);
500 
501 	printf("\n");
502 	printf(_("%i SMS parts in %i SMS sequences"),smsnum,smspos);
503 	printf("\n");
504 	fflush(stdout);
505 	GSM_Terminate();
506 }
507 
GetSMSFolders(int argc UNUSED,char * argv[]UNUSED)508 void GetSMSFolders(int argc UNUSED, char *argv[] UNUSED)
509 {
510 	GSM_Error error;
511 	GSM_SMSFolders folders;
512 	int i=0;
513 
514 	GSM_Init(TRUE);
515 
516 	error=GSM_GetSMSFolders(gsm,&folders);
517 	Print_Error(error);
518 
519 	for (i=0;i<folders.Number;i++) {
520 		printf("%i. \"%30s\"",i+1,DecodeUnicodeConsole(folders.Folder[i].Name));
521 
522 		switch(folders.Folder[i].Memory) {
523 			case MEM_SM: printf("%s", _(", SIM memory")); 		break;
524 			case MEM_ME: printf("%s", _(", phone memory")); 	break;
525 			case MEM_MT: printf("%s", _(", phone or SIM memory")); break;
526 			default    : break;
527 		}
528 		if (folders.Folder[i].InboxFolder) printf("%s", _(", Inbox folder"));
529 		if (folders.Folder[i].OutboxFolder) printf("%s", _(", Outbox folder"));
530 		printf("\n");
531 	}
532 	fflush(stdout);
533 	GSM_Terminate();
534 }
535 
536 #define SEND_SAVE_SMS_BUFFER_SIZE 10000
537 
538 GSM_Error SMSStatus;
539 
SendSMSStatus(GSM_StateMachine * sm,int status,int MessageReference,void * user_data)540 void SendSMSStatus (GSM_StateMachine *sm, int status, int MessageReference, void *user_data)
541 {
542 	smprintf(gsm, "Sent SMS on device: \"%s\"\n", GSM_GetConfig(sm, -1)->Device);
543 
544 	printf("..");
545 	if (status==0) {
546 		printf("%s", _("OK"));
547 		SMSStatus = ERR_NONE;
548 	} else {
549 		printf(_("error %i"),status);
550 		SMSStatus = ERR_UNKNOWN;
551 	}
552 	printf(_(", message reference=%d"),MessageReference);
553 	printf("\n");
554 	fflush(stdout);
555 }
556 
SendSaveDisplaySMS(int argc,char * argv[])557 void SendSaveDisplaySMS(int argc, char *argv[])
558 {
559 	GSM_Error error;
560 	GSM_MultiSMSMessage *sms;
561 	GSM_Message_Type type;
562 	GSM_SMSFolders folders;
563 	int i=0;
564 
565 	sms = malloc(sizeof(GSM_MultiSMSMessage));
566 	if (sms == NULL) {
567 		return;
568 	}
569 
570 	if (strcasestr(argv[1], "savesms") != NULL) {
571 		type = SMS_Save;
572 	} else if (strcasestr(argv[1], "sendsmsdsms") != NULL) {
573 		type = SMS_SMSD;
574 	} else if (strcasestr(argv[1], "sendsms") != NULL) {
575 		type = SMS_Send;
576 	} else if (strcasestr(argv[1], "displaysms") != NULL) {
577 		type = SMS_Display;
578 	} else {
579 		free(sms);
580 		return;
581 	}
582 
583 	GSM_Init(TRUE);
584 
585 	error = CreateMessage(&type, sms, argc, 2, argv, gsm);
586 	Print_Error(error);
587 
588 	switch (type) {
589 		case SMS_Display:
590 			for (i = 0; i < sms->Number; i++) {
591 				printf(LISTFORMAT "%i\n", _("Message number"), i);
592 				error = DisplaySMSFrame(&(sms->SMS[i]), gsm);
593 				Print_Error(error);
594 			}
595 
596 			printf(LISTFORMAT "%i\n", _("Number of messages"), sms->Number);
597 			break;
598 		case SMS_Save:
599 		case SMS_SendSaved:
600 			error = GSM_GetSMSFolders(gsm, &folders);
601 			Print_Error(error);
602 
603 			if (type == SMS_SendSaved) {
604 				GSM_SetSendSMSStatusCallback(gsm, SendSMSStatus, NULL);
605 
606 				signal(SIGINT, interrupt);
607 				fprintf(stderr, "%s\n", _("If you want break, press Ctrl+C…"));
608 				fflush(stderr);
609 			}
610 
611 			for (i = 0; i < sms->Number; i++) {
612 				printf(_("Saving SMS %i/%i\n"),i+1,sms->Number);
613 				error = GSM_AddSMS(gsm, &(sms->SMS[i]));
614 				Print_Error(error);
615 				printf(_("Saved in folder number %d \"%s\", location %i"),
616 					sms->SMS[i].Folder,
617 					DecodeUnicodeConsole(folders.Folder[sms->SMS[i].Folder-1].Name),
618 					sms->SMS[i].Location);
619 				if (sms->SMS[i].Memory == MEM_SM) {
620 					printf(", %s\n", _("SIM"));
621 				} else {
622 					printf(", %s\n", _("phone"));
623 				}
624 
625 				if (type == SMS_SendSaved) {
626 					printf(_("Sending sms from folder \"%s\", location %i\n"),
627 						DecodeUnicodeString(folders.Folder[sms->SMS[i].Folder-1].Name),sms->SMS[i].Location);
628 					fflush(stdout);
629 					SMSStatus = ERR_TIMEOUT;
630 					error = GSM_SendSavedSMS(gsm, 0, sms->SMS[i].Location);
631 					Print_Error(error);
632 					printf("%s", _("…waiting for network answer"));
633 					fflush(stdout);
634 
635 					while (!gshutdown) {
636 						GSM_ReadDevice(gsm,TRUE);
637 						if (SMSStatus == ERR_UNKNOWN) {
638 							Print_Error(SMSStatus);
639 						}
640 						if (SMSStatus == ERR_NONE) break;
641 					}
642 				}
643 			}
644 			break;
645 		case SMS_Send:
646 			signal(SIGINT, interrupt);
647 			fprintf(stderr, "%s\n", _("If you want break, press Ctrl+C…"));
648 			fflush(stderr);
649 
650 			GSM_SetSendSMSStatusCallback(gsm, SendSMSStatus, NULL);
651 
652 			for (i=0;i<sms->Number;i++) {
653 				printf(_("Sending SMS %i/%i"),i+1,sms->Number);
654 				fflush(stdout);
655 				SMSStatus = ERR_TIMEOUT;
656 				error=GSM_SendSMS(gsm, &(sms->SMS[i]));
657 				Print_Error(error);
658 				printf("%s", _("…waiting for network answer"));
659 				fflush(stdout);
660 
661 				while (!gshutdown) {
662 					GSM_ReadDevice(gsm,TRUE);
663 
664 					if (SMSStatus == ERR_UNKNOWN) {
665 						Print_Error(SMSStatus);
666 					}
667 					if (SMSStatus == ERR_NONE) break;
668 				}
669 			}
670 			break;
671 		default:
672 			printf_err("%s", _("Something went wrong, unknown message operation!\n"));
673 	}
674 
675 	free(sms);
676 	GSM_Terminate();
677 }
678 
AddSMSFolder(int argc UNUSED,char * argv[])679 void AddSMSFolder(int argc UNUSED, char *argv[])
680 {
681 	unsigned char buffer[200];
682 	GSM_Error error;
683 
684 	GSM_Init(TRUE);
685 
686 	EncodeUnicode(buffer,argv[2],strlen(argv[2]));
687 	error=GSM_AddSMSFolder(gsm,buffer);
688 	Print_Error(error);
689 
690 	GSM_Terminate();
691 }
692 
DeleteAllSMS(int argc,char * argv[])693 void DeleteAllSMS(int argc, char *argv[])
694 {
695 	GSM_MultiSMSMessage 	sms;
696 	GSM_SMSFolders		folders;
697 	int			foldernum;
698 	gboolean			start = TRUE;
699 	GSM_Error error;
700 
701 	GSM_Init(TRUE);
702 
703 	error=GSM_GetSMSFolders(gsm, &folders);
704 	Print_Error(error);
705 
706 	GetStartStop(&foldernum, NULL, 2, argc, argv);
707 
708 	if (foldernum > folders.Number) {
709 		printf(_("Too high folder number (max. %i)\n"),folders.Number);
710 		fflush(stdout);
711 		GSM_Terminate();
712 		Terminate(2);
713 	}
714 
715 	printf(_("Deleting SMS from \"%s\" folder: "),DecodeUnicodeConsole(folders.Folder[foldernum-1].Name));
716 	fflush(stdout);
717 
718 	while (error == ERR_NONE) {
719 		sms.SMS[0].Folder=0x00;
720 		error=GSM_GetNextSMS(gsm, &sms, start);
721 
722 		switch (error) {
723 		case ERR_EMPTY:
724 			break;
725 		case ERR_CORRUPTED:
726 			fprintf(stderr, "\n%s\n", _("Corrupted message, skipping"));
727 			error = ERR_NONE;
728 			continue;
729 		default:
730 			Print_Error(error);
731 			if (sms.SMS[0].Folder == foldernum) {
732 				sms.SMS[0].Folder=0x00;
733 				error=GSM_DeleteSMS(gsm, &sms.SMS[0]);
734 				Print_Error(error);
735 				printf("*");
736 			}
737 		}
738 		start=FALSE;
739 	}
740 
741 	printf("\n");
742 	fflush(stdout);
743 
744 	GSM_Terminate();
745 }
746 
747 /* How should editor hadle tabs in this file? Add editor commands here.
748  * vim: noexpandtab sw=8 ts=8 sts=8:
749  */
750