Beispiel #1
0
GSM_Error SaveICS(const char *FileName, GSM_Backup *backup)
{
	int 		i;
	size_t Length = 0;
	unsigned char 	Buffer[1000];
	FILE 		*file;
	GSM_Error error;

	file = fopen(FileName, "wb");
	if (file == NULL) return ERR_CANTOPENFILE;

	Length=sprintf(Buffer, "BEGIN:VCALENDAR%c%c",13,10);
	Length+=sprintf(Buffer+Length, "VERSION:2.0%c%c",13,10);
	chk_fwrite(Buffer,1,Length,file);

	i=0;
	while (backup->Calendar[i]!=NULL) {
		sprintf(Buffer, "%c%c",13,10);
		chk_fwrite(Buffer,1,2,file);
		Length = 0;
		error = GSM_EncodeVCALENDAR(Buffer, sizeof(Buffer),&Length,backup->Calendar[i],FALSE,Mozilla_iCalendar);
		if (error != ERR_NONE) {
			fclose(file);
			return error;
		}
		chk_fwrite(Buffer,1,Length,file);
		i++;
	}
	i=0;
	while (backup->ToDo[i]!=NULL) {
		sprintf(Buffer, "%c%c",13,10);
		chk_fwrite(Buffer,1,2,file);
		Length = 0;
		error = GSM_EncodeVTODO(Buffer, sizeof(Buffer), &Length,backup->ToDo[i],FALSE,Mozilla_VToDo);
		if (error != ERR_NONE) {
			fclose(file);
			return error;
		}
		chk_fwrite(Buffer,1,Length,file);
		i++;
	}

	Length=sprintf(Buffer, "%c%cEND:VCALENDAR%c%c",13,10,13,10);
	chk_fwrite(Buffer,1,Length,file);

	fclose(file);
	return ERR_NONE;
fail:
	fclose(file);
	return ERR_WRITING_FILE;
}
Beispiel #2
0
void SaveFile(int argc, char *argv[])
{
	GSM_Error error;
	GSM_Backup		Backup;
	int			i;
	size_t data_size = 0;
	FILE			*file;
	unsigned char		Buffer[100000];
	GSM_MemoryEntry		*pbk;
	long int location;

	if (strcasecmp(argv[2],"CALENDAR") == 0) {
		if (argc < 5) {
			printf("%s\n", _("Where is backup filename and location?"));
			Terminate(2);
		}
		location = GetInt(argv[5]) - 1;
		error = GSM_ReadBackupFile(argv[4], &Backup,GSM_GuessBackupFormat(argv[4], FALSE));
		if (error != ERR_NOTIMPLEMENTED) {
			Print_Error(error);
		}
		i = 0;
		while (Backup.Calendar[i] != NULL) {
			if (i == location) break;
			i++;
		}
		if (i != location || Backup.Calendar[i] == NULL) {
			printf("%s\n", _("Calendar note not found in file"));
			GSM_FreeBackup(&Backup);
			Terminate(2);
		}
		error = GSM_EncodeVCALENDAR(Buffer, sizeof(Buffer), &data_size, Backup.Calendar[i],TRUE,Nokia_VCalendar);
		GSM_FreeBackup(&Backup);
		Print_Error(error);
	} else if (strcasecmp(argv[2],"BOOKMARK") == 0) {
		if (argc < 5) {
			printf("%s\n", _("Where is backup filename and location?"));
			Terminate(2);
		}
		location = GetInt(argv[5]) - 1;
		error = GSM_ReadBackupFile(argv[4],&Backup,GSM_GuessBackupFormat(argv[4], FALSE));
		if (error != ERR_NOTIMPLEMENTED) {
			Print_Error(error);
		}
		i = 0;
		while (Backup.WAPBookmark[i]!=NULL) {
			if (i == location) break;
			i++;
		}
		if (i != location || Backup.WAPBookmark[i] == NULL) {
			printf("%s\n", _("WAP bookmark not found in file"));
			GSM_FreeBackup(&Backup);
			Terminate(2);
		}
		error = GSM_EncodeURLFile(Buffer, &data_size, Backup.WAPBookmark[i]);
		GSM_FreeBackup(&Backup);
		Print_Error(error);
	} else if (strcasecmp(argv[2],"NOTE") == 0) {
		if (argc<5) {
			printf("%s\n", _("Where is backup filename and location?"));
			Terminate(2);
		}
		location = GetInt(argv[5]) - 1;
		error=GSM_ReadBackupFile(argv[4],&Backup,GSM_GuessBackupFormat(argv[4], FALSE));
		if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
		i = 0;
		while (Backup.Note[i]!=NULL) {
			if (i == location) break;
			i++;
		}
		if (i != location || Backup.Note[i] == NULL) {
			printf("%s\n", _("Note not found in file"));
			GSM_FreeBackup(&Backup);
			Terminate(2);
		}
		error = GSM_EncodeVNTFile(Buffer, sizeof(Buffer), &data_size, Backup.Note[i]);
		GSM_FreeBackup(&Backup);
		Print_Error(error);
	} else if (strcasecmp(argv[2],"TODO") == 0) {
		if (argc<5) {
			printf("%s\n", _("Where is backup filename and location?"));
			Terminate(2);
		}
		location = GetInt(argv[5]) - 1;
		error=GSM_ReadBackupFile(argv[4],&Backup,GSM_GuessBackupFormat(argv[4], FALSE));
		if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
		i = 0;
		while (Backup.ToDo[i]!=NULL) {
			if (i == location) break;
			i++;
		}
		if (i != location || Backup.ToDo[i] == NULL) {
			printf("%s\n", _("Todo note not found in file"));
			GSM_FreeBackup(&Backup);
			Terminate(2);
		}
		error = GSM_EncodeVTODO(Buffer, sizeof(Buffer), &data_size, Backup.ToDo[i], TRUE, Nokia_VToDo);
		GSM_FreeBackup(&Backup);
		Print_Error(error);
	} else if (strcasecmp(argv[2],"VCARD10") == 0 || strcasecmp(argv[2],"VCARD21") == 0) {
		if (argc<6) {
			printf("%s\n", _("Where is backup filename and location and memory type?"));
			Terminate(2);
		}
		location = GetInt(argv[6]) - 1;
		error=GSM_ReadBackupFile(argv[4],&Backup,GSM_GuessBackupFormat(argv[4], FALSE));
		if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
		i = 0;
		if (strcasecmp(argv[5],"SM") == 0) {
			while (Backup.SIMPhonebook[i]!=NULL) {
				if (i == location) break;
				i++;
			}
			if (i != location || Backup.SIMPhonebook[i] == NULL) {
				printf("%s\n", _("Phonebook entry not found in file"));
				GSM_FreeBackup(&Backup);
				Terminate(2);
			}
			pbk = Backup.SIMPhonebook[i];
		} else if (strcasecmp(argv[5],"ME") == 0) {
			while (Backup.PhonePhonebook[i]!=NULL) {
				if (i == location) break;
				i++;
			}
			if (i != location || Backup.PhonePhonebook[i] == NULL) {
				printf("%s\n", _("Phonebook entry not found in file"));
				GSM_FreeBackup(&Backup);
				Terminate(2);
			}
			pbk = Backup.PhonePhonebook[i];
		} else {
			printf(_("Unknown memory type: \"%s\"\n"),argv[5]);
			GSM_FreeBackup(&Backup);
			Terminate(2);
		}
		if (strcasecmp(argv[2],"VCARD10") == 0) {
			error = GSM_EncodeVCARD(GSM_GetDebug(gsm), Buffer, sizeof(Buffer), &data_size, pbk, TRUE, Nokia_VCard10);
			GSM_FreeBackup(&Backup);
			Print_Error(error);
		} else {
			error = GSM_EncodeVCARD(GSM_GetDebug(gsm), Buffer, sizeof(Buffer), &data_size, pbk, TRUE, Nokia_VCard21);
			GSM_FreeBackup(&Backup);
			Print_Error(error);
		}
	} else {
		printf(_("Unknown backup format: \"%s\"\n"), argv[2]);
		Terminate(2);
	}

	file = fopen(argv[3],"wb");
	if (file == NULL) {
		printf_err("%s", _("Error while opening file for writing!\n"));
		Terminate(3);
	}
	if (data_size != fwrite(Buffer,1,data_size,file)) {
		printf_err("%s", _("Error while writing file!\n"));
	}
	if (fclose(file) != 0) {
		printf_err("%s", _("Error while closing file!\n"));
	}
}