Gammu internals  1.38.0
File

Data Structures

struct  GSM_FileSystemStatus
 
struct  GSM_File
 

Enumerations

enum  GSM_FileType {
  GSM_File_Other = 1, GSM_File_Java_JAR, GSM_File_Image_JPG, GSM_File_Image_BMP,
  GSM_File_Image_GIF, GSM_File_Image_PNG, GSM_File_Image_WBMP, GSM_File_Video_3GP,
  GSM_File_Sound_AMR, GSM_File_Sound_NRT, GSM_File_Sound_MIDI, GSM_File_MMS,
  GSM_File_INVALID
}
 

Functions

GSM_Error GSM_JADFindData (GSM_File *File, char *Vendor, char *Name, char *JAR, char *Version, int *Size)
 
GSM_Error GSM_ReadFile (const char *FileName, GSM_File *File)
 
void GSM_IdentifyFileFormat (GSM_File *File)
 
GSM_Error GSM_GetNextFileFolder (GSM_StateMachine *s, GSM_File *File, gboolean start)
 
GSM_Error GSM_GetFolderListing (GSM_StateMachine *s, GSM_File *File, gboolean start)
 
GSM_Error GSM_GetNextRootFolder (GSM_StateMachine *s, GSM_File *File)
 
GSM_Error GSM_SetFileAttributes (GSM_StateMachine *s, GSM_File *File)
 
GSM_Error GSM_GetFilePart (GSM_StateMachine *s, GSM_File *File, int *Handle, size_t *Size)
 
GSM_Error GSM_AddFilePart (GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle)
 
GSM_Error GSM_SendFilePart (GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle)
 
GSM_Error GSM_GetFileSystemStatus (GSM_StateMachine *s, GSM_FileSystemStatus *Status)
 
GSM_Error GSM_DeleteFile (GSM_StateMachine *s, unsigned char *ID)
 
GSM_Error GSM_AddFolder (GSM_StateMachine *s, GSM_File *File)
 
GSM_Error GSM_DeleteFolder (GSM_StateMachine *s, unsigned char *ID)
 

Detailed Description

Files handling.

Enumeration Type Documentation

§ GSM_FileType

File type identifier.

Enumerator
GSM_File_Other 
GSM_File_Java_JAR 
GSM_File_Image_JPG 
GSM_File_Image_BMP 
GSM_File_Image_GIF 
GSM_File_Image_PNG 
GSM_File_Image_WBMP 
GSM_File_Video_3GP 
GSM_File_Sound_AMR 
GSM_File_Sound_NRT 

DCT4 binary format

GSM_File_Sound_MIDI 
GSM_File_MMS 
GSM_File_INVALID 

Definition at line 41 of file gammu-file.h.

Function Documentation

§ GSM_AddFilePart()

GSM_Error GSM_AddFilePart ( GSM_StateMachine s,
GSM_File File,
size_t *  Pos,
int *  Handle 
)

Adds file to filesystem. Call repeatedly until function returns ERR_EMPTY.

Parameters
sState machine pointer.
FileFile structure and data.
PosPosition of transmitted data. Should be 0 on start.
HandleHandle for saving file, some drivers need this information to be kept between function calls.
Returns
Error code, ERR_EMPTY after transfer end.

Adds file part to filesystem.

Definition at line 1765 of file api.c.

References GSM_Phone_Functions::AddFilePart, CHECK_PHONE_CONNECTION, GSM_Phone::Functions, _GSM_StateMachine::Phone, and PRINT_LOG_ERROR.

1766 {
1767  GSM_Error err;
1768 
1770 
1771  err = s->Phone.Functions->AddFilePart(s, File, Pos, Handle);
1772  PRINT_LOG_ERROR(err);
1773  return err;
1774 }
GSM_Error
Definition: gammu-error.h:23
GSM_Error(* AddFilePart)(GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle)
Definition: gsmstate.h:1273
GSM_Phone Phone
Definition: gsmstate.h:1431
#define PRINT_LOG_ERROR(err)
Definition: api.c:28
#define CHECK_PHONE_CONNECTION()
Definition: api.c:38
GSM_Phone_Functions * Functions
Definition: gsmstate.h:1373

§ GSM_AddFolder()

GSM_Error GSM_AddFolder ( GSM_StateMachine s,
GSM_File File 
)

Adds folder to filesystem.

Parameters
sState machine pointer.
FileStructure containing information about new folder (Name and FullName).
Returns
Error code.

Adds folder to filesystem.

Definition at line 1817 of file api.c.

References GSM_Phone_Functions::AddFolder, CHECK_PHONE_CONNECTION, GSM_Phone::Functions, _GSM_StateMachine::Phone, and PRINT_LOG_ERROR.

1818 {
1819  GSM_Error err;
1820 
1822 
1823  err = s->Phone.Functions->AddFolder(s, File);
1824  PRINT_LOG_ERROR(err);
1825  return err;
1826 }
GSM_Error
Definition: gammu-error.h:23
GSM_Error(* AddFolder)(GSM_StateMachine *s, GSM_File *File)
Definition: gsmstate.h:1289
GSM_Phone Phone
Definition: gsmstate.h:1431
#define PRINT_LOG_ERROR(err)
Definition: api.c:28
#define CHECK_PHONE_CONNECTION()
Definition: api.c:38
GSM_Phone_Functions * Functions
Definition: gsmstate.h:1373

§ GSM_DeleteFile()

GSM_Error GSM_DeleteFile ( GSM_StateMachine s,
unsigned char *  ID 
)

Deletes file from filesystem.

Parameters
sState machine pointer.
IDID of folder.
Returns
Error code.

Deletes file from filessytem.

Definition at line 1804 of file api.c.

References CHECK_PHONE_CONNECTION, GSM_Phone_Functions::DeleteFile, GSM_Phone::Functions, _GSM_StateMachine::Phone, and PRINT_LOG_ERROR.

1805 {
1806  GSM_Error err;
1807 
1809 
1810  err = s->Phone.Functions->DeleteFile(s, ID);
1811  PRINT_LOG_ERROR(err);
1812  return err;
1813 }
GSM_Error
Definition: gammu-error.h:23
GSM_Error(* DeleteFile)(GSM_StateMachine *s, unsigned char *ID)
Definition: gsmstate.h:1285
GSM_Phone Phone
Definition: gsmstate.h:1431
#define PRINT_LOG_ERROR(err)
Definition: api.c:28
#define CHECK_PHONE_CONNECTION()
Definition: api.c:38
GSM_Phone_Functions * Functions
Definition: gsmstate.h:1373

§ GSM_DeleteFolder()

GSM_Error GSM_DeleteFolder ( GSM_StateMachine s,
unsigned char *  ID 
)

Deletes folder from filesystem.

Parameters
sState machine pointer.
IDID of folder.
Returns
Error code.

Deletes folder from filesystem.

Definition at line 1830 of file api.c.

References CHECK_PHONE_CONNECTION, GSM_Phone_Functions::DeleteFolder, GSM_Phone::Functions, _GSM_StateMachine::Phone, and PRINT_LOG_ERROR.

1831 {
1832  GSM_Error err;
1833 
1835 
1836  err = s->Phone.Functions->DeleteFolder(s, ID);
1837  PRINT_LOG_ERROR(err);
1838  return err;
1839 }
GSM_Error
Definition: gammu-error.h:23
GSM_Error(* DeleteFolder)(GSM_StateMachine *s, unsigned char *ID)
Definition: gsmstate.h:1293
GSM_Phone Phone
Definition: gsmstate.h:1431
#define PRINT_LOG_ERROR(err)
Definition: api.c:28
#define CHECK_PHONE_CONNECTION()
Definition: api.c:38
GSM_Phone_Functions * Functions
Definition: gsmstate.h:1373

§ GSM_GetFilePart()

GSM_Error GSM_GetFilePart ( GSM_StateMachine s,
GSM_File File,
int *  Handle,
size_t *  Size 
)

Retrieves file part.

Parameters
sState machine pointer.
FileFile structure with path, data will be stored here.
SizeSize of transmitted data.
HandleHandle for saving file, some drivers need this information to be kept between function calls.
Returns
Error code, ERR_EMPTY after transfer end.

Retrieves file part.

Definition at line 1752 of file api.c.

References CHECK_PHONE_CONNECTION, GSM_Phone::Functions, GSM_Phone_Functions::GetFilePart, _GSM_StateMachine::Phone, and PRINT_LOG_ERROR.

1753 {
1754  GSM_Error err;
1755 
1757 
1758  err = s->Phone.Functions->GetFilePart(s, File, Handle, Size);
1759  PRINT_LOG_ERROR(err);
1760  return err;
1761 }
GSM_Error
Definition: gammu-error.h:23
GSM_Phone Phone
Definition: gsmstate.h:1431
#define PRINT_LOG_ERROR(err)
Definition: api.c:28
#define CHECK_PHONE_CONNECTION()
Definition: api.c:38
GSM_Phone_Functions * Functions
Definition: gsmstate.h:1373
GSM_Error(* GetFilePart)(GSM_StateMachine *s, GSM_File *File, int *Handle, size_t *Size)
Definition: gsmstate.h:1269

§ GSM_GetFileSystemStatus()

GSM_Error GSM_GetFileSystemStatus ( GSM_StateMachine s,
GSM_FileSystemStatus Status 
)

Acquires filesystem status.

Parameters
sState machine pointer.
StatusStorage for status information.
Returns
Error code.

Acquires filesystem status.

Definition at line 1791 of file api.c.

References CHECK_PHONE_CONNECTION, GSM_Phone::Functions, GSM_Phone_Functions::GetFileSystemStatus, _GSM_StateMachine::Phone, and PRINT_LOG_ERROR.

1792 {
1793  GSM_Error err;
1794 
1796 
1797  err = s->Phone.Functions->GetFileSystemStatus(s, Status);
1798  PRINT_LOG_ERROR(err);
1799  return err;
1800 }
GSM_Error(* GetFileSystemStatus)(GSM_StateMachine *s, GSM_FileSystemStatus *Status)
Definition: gsmstate.h:1281
GSM_Error
Definition: gammu-error.h:23
GSM_Phone Phone
Definition: gsmstate.h:1431
#define PRINT_LOG_ERROR(err)
Definition: api.c:28
#define CHECK_PHONE_CONNECTION()
Definition: api.c:38
GSM_Phone_Functions * Functions
Definition: gsmstate.h:1373

§ GSM_GetFolderListing()

GSM_Error GSM_GetFolderListing ( GSM_StateMachine s,
GSM_File File,
gboolean  start 
)

Gets listing of folder.

Parameters
sState machine pointer.
FileFile structure where path will be stored, if start is FALSE, it should contain data from previous reading (at least ID). On start it should contain path to directory.
startWhether we're starting transfer.
Returns
Error code.

Gets file part from filesystem.

Definition at line 1712 of file api.c.

References CHECK_PHONE_CONNECTION, GSM_Phone::Functions, GSM_Phone_Functions::GetFolderListing, _GSM_StateMachine::Phone, PRINT_LOG_ERROR, and PRINT_START.

1713 {
1714  GSM_Error err;
1715 
1717  PRINT_START();
1718 
1719  err = s->Phone.Functions->GetFolderListing(s, File, start);
1720  PRINT_LOG_ERROR(err);
1721  return err;
1722 }
GSM_Error
Definition: gammu-error.h:23
#define PRINT_START()
Definition: api.c:21
GSM_Phone Phone
Definition: gsmstate.h:1431
#define PRINT_LOG_ERROR(err)
Definition: api.c:28
#define CHECK_PHONE_CONNECTION()
Definition: api.c:38
GSM_Phone_Functions * Functions
Definition: gsmstate.h:1373
GSM_Error(* GetFolderListing)(GSM_StateMachine *s, GSM_File *File, gboolean start)
Definition: gsmstate.h:1257

§ GSM_GetNextFileFolder()

GSM_Error GSM_GetNextFileFolder ( GSM_StateMachine s,
GSM_File File,
gboolean  start 
)

Gets next filename from filesystem.

Parameters
sState machine pointer.
FileFile structure where path will be stored, if start is FALSE, it should contain data from previous reading (at least ID).
startWhether we're starting transfer.
Returns
Error code.

Gets next filename from filesystem.

Definition at line 1698 of file api.c.

References CHECK_PHONE_CONNECTION, GSM_Phone::Functions, GSM_Phone_Functions::GetNextFileFolder, _GSM_StateMachine::Phone, PRINT_LOG_ERROR, and PRINT_START.

1699 {
1700  GSM_Error err;
1701 
1703  PRINT_START();
1704 
1705  err = s->Phone.Functions->GetNextFileFolder(s, File, start);
1706  PRINT_LOG_ERROR(err);
1707  return err;
1708 }
GSM_Error(* GetNextFileFolder)(GSM_StateMachine *s, GSM_File *File, gboolean start)
Definition: gsmstate.h:1253
GSM_Error
Definition: gammu-error.h:23
#define PRINT_START()
Definition: api.c:21
GSM_Phone Phone
Definition: gsmstate.h:1431
#define PRINT_LOG_ERROR(err)
Definition: api.c:28
#define CHECK_PHONE_CONNECTION()
Definition: api.c:38
GSM_Phone_Functions * Functions
Definition: gsmstate.h:1373

§ GSM_GetNextRootFolder()

GSM_Error GSM_GetNextRootFolder ( GSM_StateMachine s,
GSM_File File 
)

Gets next root folder.

Parameters
sState machine pointer.
FileFile structure where path will be stored.
Returns
Error code.

Gets next root folder.

Definition at line 1726 of file api.c.

References CHECK_PHONE_CONNECTION, GSM_Phone::Functions, GSM_Phone_Functions::GetNextRootFolder, _GSM_StateMachine::Phone, and PRINT_LOG_ERROR.

1727 {
1728  GSM_Error err;
1729 
1731 
1732  err = s->Phone.Functions->GetNextRootFolder(s, File);
1733  PRINT_LOG_ERROR(err);
1734  return err;
1735 }
GSM_Error(* GetNextRootFolder)(GSM_StateMachine *s, GSM_File *File)
Definition: gsmstate.h:1261
GSM_Error
Definition: gammu-error.h:23
GSM_Phone Phone
Definition: gsmstate.h:1431
#define PRINT_LOG_ERROR(err)
Definition: api.c:28
#define CHECK_PHONE_CONNECTION()
Definition: api.c:38
GSM_Phone_Functions * Functions
Definition: gsmstate.h:1373

§ GSM_IdentifyFileFormat()

void GSM_IdentifyFileFormat ( GSM_File File)

Identifies file format by checking it's content.

Parameters
FileFile data, Type member will be filled in.

Definition at line 164 of file gsmmisc.c.

References GSM_File::Buffer, GSM_File_Image_BMP, GSM_File_Image_GIF, GSM_File_Image_JPG, GSM_File_Image_PNG, GSM_File_Image_WBMP, GSM_File_Other, GSM_File_Sound_MIDI, GSM_File_Sound_NRT, PRINTF_STYLE, GSM_File::Type, and GSM_File::Used.

Referenced by GSM_ReadFile().

165 {
166  File->Type = GSM_File_Other;
167  if (File->Used > 2) {
168  if (memcmp(File->Buffer, "BM",2)==0) {
169  File->Type = GSM_File_Image_BMP;
170  } else if (memcmp(File->Buffer, "GIF",3)==0) {
171  File->Type = GSM_File_Image_GIF;
172  } else if (File->Buffer[0] == 0x00 && File->Buffer[1] == 0x00) {
173  File->Type = GSM_File_Image_WBMP;
174  } else if (memcmp(File->Buffer+1, "PNG",3)==0) {
175  File->Type = GSM_File_Image_PNG;
176  } else if (File->Buffer[0] == 0xFF && File->Buffer[1] == 0xD8) {
177  File->Type = GSM_File_Image_JPG;
178  } else if (memcmp(File->Buffer, "MThd",4)==0) {
179  File->Type = GSM_File_Sound_MIDI;
180  } else if (File->Buffer[0] == 0x00 && File->Buffer[1] == 0x02) {
181  File->Type = GSM_File_Sound_NRT;
182  }
183  }
184 }
unsigned char * Buffer
Definition: gammu-file.h:94
GSM_FileType Type
Definition: gammu-file.h:86
size_t Used
Definition: gammu-file.h:70

§ GSM_JADFindData()

GSM_Error GSM_JADFindData ( GSM_File File,
char *  Vendor,
char *  Name,
char *  JAR,
char *  Version,
int *  Size 
)

Parses JAD file.

Parameters
FileJAD file data.
VendorBuffer for vendor name.
NameBuffer for application name.
JARBuffer for JAR URL.
VersionBuffer for version of application.
SizePointer to integer to store size.
Returns
Error code.

Definition at line 136 of file gsmmisc.c.

References dbgprintf, ERR_FILENOTSUPPORTED, ERR_NONE, and GSM_JADFindLine().

137 {
138  char Size2[200];
139 
140  GSM_JADFindLine(File, "MIDlet-Vendor:", Vendor);
141  if (Vendor[0] == 0x00) return ERR_FILENOTSUPPORTED;
142  dbgprintf(NULL, "Vendor: \"%s\"\n",Vendor);
143 
144  GSM_JADFindLine(File, "MIDlet-Name:", Name);
145  if (Name[0] == 0x00) return ERR_FILENOTSUPPORTED;
146  dbgprintf(NULL, "Name: \"%s\"\n",Name);
147 
148  GSM_JADFindLine(File, "MIDlet-Jar-URL:", JAR);
149  if (JAR[0] == 0x00) return ERR_FILENOTSUPPORTED;
150  dbgprintf(NULL, "JAR file URL: \"%s\"\n",JAR);
151 
152  GSM_JADFindLine(File, "MIDlet-Jar-Size:", Size2);
153  *Size = -1;
154  if (Size2[0] == 0x00) return ERR_FILENOTSUPPORTED;
155  dbgprintf(NULL, "JAR size: \"%s\"\n",Size2);
156  (*Size) = atoi(Size2);
157 
158  GSM_JADFindLine(File, "MIDlet-Version:", Version);
159  dbgprintf(NULL, "Version: \"%s\"\n",Version);
160 
161  return ERR_NONE;
162 }
static void GSM_JADFindLine(GSM_File *File, const char *Name, char *Value)
Definition: gsmmisc.c:117
#define dbgprintf
Definition: debug.h:72

§ GSM_ReadFile()

GSM_Error GSM_ReadFile ( const char *  FileName,
GSM_File File 
)

Reads file from filesystem to GSM_File structure.

Parameters
FileNameFile to read.
FileStorage for data.
Returns
Error code.

Definition at line 74 of file gsmmisc.c.

References GSM_File::Buffer, dbgprintf, ERR_CANTOPENFILE, ERR_NONE, ERR_UNKNOWN, FALSE, Fill_GSM_DateTime(), GSM_File::Folder, GSM_IdentifyFileFormat(), GSM_File::Hidden, GSM_File::Level, GSM_File::Modified, GSM_File::ModifiedEmpty, OSDate(), GSM_File::Protected, GSM_File::ReadOnly, GSM_File::System, TRUE, and GSM_File::Used.

Referenced by DUMMY_GetFilePart(), and PHONE_FindDataFile().

75 {
76  int i = 1000;
77  FILE *file;
78  struct stat fileinfo;
79 
80  if (FileName[0] == 0x00) return ERR_UNKNOWN;
81  file = fopen(FileName,"rb");
82  if (file == NULL) return ERR_CANTOPENFILE;
83 
84  free(File->Buffer);
85  File->Buffer = NULL;
86  File->Used = 0;
87  while (i == 1000) {
88  File->Buffer = (unsigned char *)realloc(File->Buffer,File->Used + 1000);
89  i = fread(File->Buffer+File->Used,1,1000,file);
90  File->Used = File->Used + i;
91  }
92  File->Buffer = (unsigned char *)realloc(File->Buffer,File->Used + 1);
93  /* Make it 0 terminated, in case it is needed somewhere (we don't count this to length) */
94  File->Buffer[File->Used] = 0;
95  fclose(file);
96 
97  File->Level = 0;
99  File->Protected = FALSE;
100  File->Hidden = FALSE;
101  File->System = FALSE;
102  File->ReadOnly = FALSE; /* @todo TODO get this from permissions? */
103  File->Folder = FALSE;
104 
105  File->ModifiedEmpty = TRUE;
106  if (stat(FileName,&fileinfo) == 0) {
107  File->ModifiedEmpty = FALSE;
108  dbgprintf(NULL, "File info read correctly\n");
109  /* st_mtime is time of last modification of file */
110  Fill_GSM_DateTime(&File->Modified, fileinfo.st_mtime);
111  dbgprintf(NULL, "FillTime: %s\n", OSDate(File->Modified));
112  }
113 
114  return ERR_NONE;
115 }
int Level
Definition: gammu-file.h:82
char * OSDate(GSM_DateTime dt)
Definition: misc.c:305
gboolean Folder
Definition: gammu-file.h:78
gboolean ReadOnly
Definition: gammu-file.h:111
unsigned char * Buffer
Definition: gammu-file.h:94
gboolean Protected
Definition: gammu-file.h:107
size_t Used
Definition: gammu-file.h:70
gboolean System
Definition: gammu-file.h:119
void Fill_GSM_DateTime(GSM_DateTime *Date, time_t timet)
Definition: misc.c:170
#define FALSE
Definition: gammu-types.h:25
GSM_DateTime Modified
Definition: gammu-file.h:98
gboolean ModifiedEmpty
Definition: gammu-file.h:102
#define dbgprintf
Definition: debug.h:72
#define TRUE
Definition: gammu-types.h:28
void GSM_IdentifyFileFormat(GSM_File *File)
Definition: gsmmisc.c:164
gboolean Hidden
Definition: gammu-file.h:115

§ GSM_SendFilePart()

GSM_Error GSM_SendFilePart ( GSM_StateMachine s,
GSM_File File,
size_t *  Pos,
int *  Handle 
)

Sends file to phone, it's up to phone to decide what to do with it. It is usually same as when you receive file over Bluetooth from other phone. Use in same way as GSM_AddFilePart.

Parameters
sState machine pointer.
FileFile structure and data.
PosPosition of transmitted data. Should be 0 on start.
HandleHandle for saving file, some drivers need this information to be kept between function calls.
Returns
Error code, ERR_EMPTY after transfer end.

Sends file to phone, it's up to phone to decide what to do with it.

Definition at line 1778 of file api.c.

References CHECK_PHONE_CONNECTION, GSM_Phone::Functions, _GSM_StateMachine::Phone, PRINT_LOG_ERROR, and GSM_Phone_Functions::SendFilePart.

Referenced by PHONE_UploadFile().

1779 {
1780  GSM_Error err;
1781 
1783 
1784  err = s->Phone.Functions->SendFilePart(s, File, Pos, Handle);
1785  PRINT_LOG_ERROR(err);
1786  return err;
1787 }
GSM_Error
Definition: gammu-error.h:23
GSM_Error(* SendFilePart)(GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle)
Definition: gsmstate.h:1277
GSM_Phone Phone
Definition: gsmstate.h:1431
#define PRINT_LOG_ERROR(err)
Definition: api.c:28
#define CHECK_PHONE_CONNECTION()
Definition: api.c:38
GSM_Phone_Functions * Functions
Definition: gsmstate.h:1373

§ GSM_SetFileAttributes()

GSM_Error GSM_SetFileAttributes ( GSM_StateMachine s,
GSM_File File 
)

Sets file system attributes.

Parameters
sState machine pointer.
FileFile structure with path and attributes.
Returns
Error code.

Sets file system attributes.

Definition at line 1739 of file api.c.

References CHECK_PHONE_CONNECTION, GSM_Phone::Functions, _GSM_StateMachine::Phone, PRINT_LOG_ERROR, and GSM_Phone_Functions::SetFileAttributes.

1740 {
1741  GSM_Error err;
1742 
1744 
1745  err = s->Phone.Functions->SetFileAttributes(s, File);
1746  PRINT_LOG_ERROR(err);
1747  return err;
1748 }
GSM_Error(* SetFileAttributes)(GSM_StateMachine *s, GSM_File *File)
Definition: gsmstate.h:1265
GSM_Error
Definition: gammu-error.h:23
GSM_Phone Phone
Definition: gsmstate.h:1431
#define PRINT_LOG_ERROR(err)
Definition: api.c:28
#define CHECK_PHONE_CONNECTION()
Definition: api.c:38
GSM_Phone_Functions * Functions
Definition: gsmstate.h:1373