1 /** 2 * \file gammu-file.h 3 * \author Michal Čihař 4 * 5 * File manipulations. 6 */ 7 #ifndef __gammu_file_h 8 #define __gammu_file_h 9 10 /** 11 * \defgroup File File 12 * Files handling. 13 */ 14 15 #ifdef __cplusplus 16 extern "C" { 17 #endif 18 19 #include <gammu-types.h> 20 #include <gammu-datetime.h> 21 #include <gammu-limits.h> 22 23 /** 24 * Status of filesystem. 25 * 26 * \ingroup File 27 */ 28 typedef struct { 29 size_t Free; 30 size_t Used; 31 size_t UsedImages; 32 size_t UsedSounds; 33 size_t UsedThemes; 34 } GSM_FileSystemStatus; 35 36 /** 37 * File type identifier. 38 * 39 * \ingroup File 40 */ 41 typedef enum { 42 GSM_File_Other = 1, 43 GSM_File_Java_JAR, 44 GSM_File_Image_JPG, 45 GSM_File_Image_BMP, 46 GSM_File_Image_GIF, 47 GSM_File_Image_PNG, 48 GSM_File_Image_WBMP, 49 GSM_File_Video_3GP, 50 GSM_File_Sound_AMR, 51 /** 52 * DCT4 binary format 53 */ 54 GSM_File_Sound_NRT, 55 GSM_File_Sound_MIDI, 56 GSM_File_MMS, 57 58 GSM_File_INVALID 59 } GSM_FileType; 60 61 /** 62 * Structure for holding file information and data. 63 * 64 * \ingroup File 65 */ 66 typedef struct { 67 /** 68 * How many bytes are used. 69 */ 70 size_t Used; 71 /** 72 * Name in Unicode 73 */ 74 unsigned char Name[2 * (GSM_MAX_FILENAME_LENGTH + 1)]; 75 /** 76 * True, when folder 77 */ 78 gboolean Folder; 79 /** 80 * How much file is nested on filesystem. 81 */ 82 int Level; 83 /** 84 * Type of file. 85 */ 86 GSM_FileType Type; 87 /** 88 * ID in Unicode 89 */ 90 unsigned char ID_FullName[2 * (GSM_MAX_FILENAME_ID_LENGTH + 1)]; 91 /** 92 * Pointer to file data. 93 */ 94 unsigned char *Buffer; 95 /** 96 * Last modification date. 97 */ 98 GSM_DateTime Modified; 99 /** 100 * Whether modification date is empty. 101 */ 102 gboolean ModifiedEmpty; 103 104 /** 105 * Protected file attribute. 106 */ 107 gboolean Protected; 108 /** 109 * Read only file attribute. 110 */ 111 gboolean ReadOnly; 112 /** 113 * Hidden file attribute. 114 */ 115 gboolean Hidden; 116 /** 117 * System file attribute. 118 */ 119 gboolean System; 120 } GSM_File; 121 122 /** 123 * Parses JAD file. 124 * 125 * \param File JAD file data. 126 * \param Vendor Buffer for vendor name. 127 * \param Name Buffer for application name. 128 * \param JAR Buffer for JAR URL. 129 * \param Version Buffer for version of application. 130 * \param Size Pointer to integer to store size. 131 * 132 * \return Error code. 133 * 134 * \ingroup File 135 */ 136 GSM_Error GSM_JADFindData(GSM_File *File, char *Vendor, char *Name, char *JAR, 137 char *Version, int *Size); 138 139 /** 140 * Reads file from filesystem to \ref GSM_File structure. 141 * 142 * \param FileName File to read. 143 * \param File Storage for data. 144 * 145 * \return Error code. 146 * 147 * \ingroup File 148 */ 149 GSM_Error GSM_ReadFile(const char *FileName, GSM_File * File); 150 151 /** 152 * Identifies file format by checking it's content. 153 * 154 * \param File File data, Type member will be filled in. 155 * 156 * \ingroup File 157 */ 158 void GSM_IdentifyFileFormat(GSM_File * File); 159 160 /** 161 * Gets next filename from filesystem. 162 * 163 * \param s State machine pointer. 164 * \param File File structure where path will be stored, if start is 165 * FALSE, it should contain data from previous reading (at least ID). 166 * \param start Whether we're starting transfer. 167 * 168 * \return Error code. 169 * 170 * \ingroup File 171 */ 172 GSM_Error GSM_GetNextFileFolder(GSM_StateMachine * s, GSM_File * File, 173 gboolean start); 174 /** 175 * Gets listing of folder. 176 * 177 * \param s State machine pointer. 178 * \param File File structure where path will be stored, if start is 179 * FALSE, it should contain data from previous reading (at least ID). On 180 * start it should contain path to directory. 181 * \param start Whether we're starting transfer. 182 * 183 * \return Error code. 184 * 185 * \ingroup File 186 */ 187 GSM_Error GSM_GetFolderListing(GSM_StateMachine * s, GSM_File * File, 188 gboolean start); 189 /** 190 * Gets next root folder. 191 * 192 * \param s State machine pointer. 193 * \param File File structure where path will be stored. 194 * 195 * \return Error code. 196 * 197 * \ingroup File 198 */ 199 GSM_Error GSM_GetNextRootFolder(GSM_StateMachine * s, GSM_File * File); 200 201 /** 202 * Sets file system attributes. 203 * 204 * \param s State machine pointer. 205 * \param File File structure with path and attributes. 206 * 207 * \return Error code. 208 * 209 * \ingroup File 210 */ 211 GSM_Error GSM_SetFileAttributes(GSM_StateMachine * s, GSM_File * File); 212 213 /** 214 * Retrieves file part. 215 * 216 * \param s State machine pointer. 217 * \param File File structure with path, data will be stored here. 218 * \param Size Size of transmitted data. 219 * \param Handle Handle for saving file, some drivers need this 220 * information to be kept between function calls. 221 * 222 * \return Error code, \ref ERR_EMPTY after transfer end. 223 * 224 * \ingroup File 225 */ 226 GSM_Error GSM_GetFilePart(GSM_StateMachine * s, GSM_File * File, int *Handle, 227 size_t *Size); 228 229 /** 230 * Adds file to filesystem. Call repeatedly until function returns 231 * \ref ERR_EMPTY. 232 * 233 * \param s State machine pointer. 234 * \param File File structure and data. 235 * \param Pos Position of transmitted data. Should be 0 on start. 236 * \param Handle Handle for saving file, some drivers need this 237 * information to be kept between function calls. 238 * 239 * \return Error code, \ref ERR_EMPTY after transfer end. 240 * 241 * \ingroup File 242 */ 243 GSM_Error GSM_AddFilePart(GSM_StateMachine * s, GSM_File * File, size_t *Pos, 244 int *Handle); 245 /** 246 * Sends file to phone, it's up to phone to decide what to do with it. 247 * It is usually same as when you receive file over Bluetooth from other 248 * phone. Use in same way as \ref GSM_AddFilePart. 249 * 250 * \param s State machine pointer. 251 * \param File File structure and data. 252 * \param Pos Position of transmitted data. Should be 0 on start. 253 * \param Handle Handle for saving file, some drivers need this 254 * information to be kept between function calls. 255 * 256 * \return Error code, \ref ERR_EMPTY after transfer end. 257 * 258 * \ingroup File 259 */ 260 GSM_Error GSM_SendFilePart(GSM_StateMachine * s, GSM_File * File, size_t *Pos, 261 int *Handle); 262 /** 263 * Acquires filesystem status. 264 * 265 * \param s State machine pointer. 266 * \param Status Storage for status information. 267 * 268 * \return Error code. 269 * 270 * \ingroup File 271 */ 272 GSM_Error GSM_GetFileSystemStatus(GSM_StateMachine * s, 273 GSM_FileSystemStatus * Status); 274 /** 275 * Deletes file from filesystem. 276 * 277 * \param s State machine pointer. 278 * \param ID ID of folder. 279 * 280 * \return Error code. 281 * 282 * \ingroup File 283 */ 284 GSM_Error GSM_DeleteFile(GSM_StateMachine * s, unsigned char *ID); 285 286 /** 287 * Adds folder to filesystem. 288 * 289 * \param s State machine pointer. 290 * \param File Structure containing information about new folder (Name 291 * and FullName). 292 * 293 * \return Error code. 294 * 295 * \ingroup File 296 */ 297 GSM_Error GSM_AddFolder(GSM_StateMachine * s, GSM_File * File); 298 299 /** 300 * Deletes folder from filesystem. 301 * 302 * \param s State machine pointer. 303 * \param ID ID of folder. 304 * 305 * \return Error code. 306 * 307 * \ingroup File 308 */ 309 GSM_Error GSM_DeleteFolder(GSM_StateMachine * s, unsigned char *ID); 310 #ifdef __cplusplus 311 } 312 #endif 313 #endif 314 315 /* Editor configuration 316 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: 317 */ 318