summaryrefslogtreecommitdiffstats
path: root/src/simfs.c
diff options
context:
space:
mode:
authorKristen Carlson Accardi <kristen@linux.intel.com>2010-10-04 15:33:19 -0700
committerDenis Kenzior <denkenz@gmail.com>2010-10-13 05:04:46 -0500
commit19fcae699c873ea7e60d6440fdd930ed10dbedd1 (patch)
treedbcf5e35f97c243d2d94203ab67d8b33b5c67abc /src/simfs.c
parent9bc187bd45548d1fd1bb0ee7582a0417a5c4373c (diff)
downloadofono-19fcae699c873ea7e60d6440fdd930ed10dbedd1.tar.bz2
simfs: cache images
Diffstat (limited to 'src/simfs.c')
-rw-r--r--src/simfs.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/simfs.c b/src/simfs.c
index b5b12b48..5fbee8b9 100644
--- a/src/simfs.c
+++ b/src/simfs.c
@@ -47,6 +47,7 @@
#define SIM_CACHE_PATH SIM_CACHE_BASEPATH "/%04x"
#define SIM_CACHE_HEADER_SIZE 38
#define SIM_FILE_INFO_SIZE 6
+#define SIM_IMAGE_CACHE_PATH STORAGEDIR "/%s-%i/images/%d.xpm"
#define SIM_FS_VERSION 1
@@ -722,6 +723,67 @@ int sim_fs_write(struct sim_fs *fs, int id, ofono_sim_file_write_cb_t cb,
return 0;
}
+void sim_fs_cache_image(struct sim_fs *fs, const char *image, int id)
+{
+ const char *imsi;
+ enum ofono_sim_phase phase;
+
+ if (fs == NULL || image == NULL)
+ return;
+
+ imsi = ofono_sim_get_imsi(fs->sim);
+ phase = ofono_sim_get_phase(fs->sim);
+
+ if (imsi)
+ write_file((const unsigned char *) image, strlen(image),
+ SIM_CACHE_MODE, SIM_IMAGE_CACHE_PATH, imsi,
+ phase, id);
+}
+
+char *sim_fs_get_cached_image(struct sim_fs *fs, int id)
+{
+ const char *imsi;
+ enum ofono_sim_phase phase;
+ unsigned short image_length;
+ int fd;
+ char *buffer;
+ char *path;
+ int len;
+ struct stat st_buf;
+
+ if (fs == NULL)
+ return NULL;
+
+ imsi = ofono_sim_get_imsi(fs->sim);
+ phase = ofono_sim_get_phase(fs->sim);
+
+ path = g_strdup_printf(SIM_IMAGE_CACHE_PATH, imsi, phase, id);
+
+ TFR(stat(path, &st_buf));
+
+ fd = TFR(open(path, O_RDONLY));
+
+ g_free(path);
+
+ if (fd < 0)
+ return NULL;
+
+ image_length = st_buf.st_size;
+
+ buffer = g_try_malloc0(image_length + 1);
+
+ len = TFR(read(fd, buffer, image_length));
+
+ TFR(close(fd));
+
+ if (len != image_length) {
+ g_free(buffer);
+ return NULL;
+ }
+
+ return buffer;
+}
+
static void remove_cachefile(const char *imsi, enum ofono_sim_phase phase,
const struct dirent *file)
{