summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2009-08-04 09:53:11 -0500
committerDenis Kenzior <denkenz@gmail.com>2009-08-04 15:01:42 -0500
commit6182c92ef7da3ce79bc2f2e88a61a7c434799642 (patch)
tree3b4e9040d57217f22711111f2705b53b8cfbc635 /src
parent749a83d0331cc1ba1647581f5ed00acce7583031 (diff)
downloadofono-6182c92ef7da3ce79bc2f2e88a61a7c434799642.tar.bz2
Make sim_op_retrieve_cb a bit more readable
Diffstat (limited to 'src')
-rw-r--r--src/sim.c49
1 files changed, 28 insertions, 21 deletions
diff --git a/src/sim.c b/src/sim.c
index b9a0c82d..aa708f34 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -311,6 +311,31 @@ static void sim_op_error(struct ofono_modem *modem)
#define SIM_CACHE_PATH_LEN(imsilen) (strlen(SIM_CACHE_PATH) - 2 + imsilen)
#define SIM_CACHE_HEADER_SIZE 6
+static gboolean cache_record(const char *path, int current, int record_len,
+ const unsigned char *data)
+{
+ int r = 0;
+ int fd;
+
+ fd = open(path, O_WRONLY);
+
+ if (fd == -1)
+ return FALSE;
+
+ if (lseek(fd, (current - 1) * record_len +
+ SIM_CACHE_HEADER_SIZE, SEEK_SET) !=
+ (off_t) -1)
+ r = write(fd, data, record_len);
+ close(fd);
+
+ if (r < record_len) {
+ unlink(path);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
static void sim_op_retrieve_cb(const struct ofono_error *error,
const unsigned char *data, int len, void *user)
{
@@ -319,10 +344,7 @@ static void sim_op_retrieve_cb(const struct ofono_error *error,
struct sim_file_op *op = g_queue_peek_head(sim->simop_q);
int total = op->length / op->record_length;
ofono_sim_file_read_cb_t cb = op->cb;
-
char *imsi = sim->imsi;
- char *path;
- int r = 0, fd;
if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
sim_op_error(modem);
@@ -333,28 +355,13 @@ static void sim_op_retrieve_cb(const struct ofono_error *error,
data, op->record_length, op->userdata);
if (op->cache && imsi) {
- /* Cache the record */
- path = g_strdup_printf(SIM_CACHE_PATH, imsi, op->id);
- fd = open(path, O_WRONLY);
-
- if (fd == -1)
- goto next;
-
- if (lseek(fd, (op->current - 1) * op->record_length +
- SIM_CACHE_HEADER_SIZE, SEEK_SET) !=
- (off_t) -1)
- r = write(fd, data, op->record_length);
- close(fd);
-
- if (r < op->record_length) {
- op->cache = 0;
- unlink(path);
- }
+ char *path = g_strdup_printf(SIM_CACHE_PATH, imsi, op->id);
+ op->cache = cache_record(path, op->current, op->record_length,
+ data);
g_free(path);
}
-next:
if (op->current == total) {
op = g_queue_pop_head(sim->simop_q);