summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2012-09-16 09:13:34 +0200
committerHarald Welte <laforge@gnumonks.org>2012-09-16 09:18:53 +0200
commitc5097633d01aedf9b5c47d0c3d059e58efaea95f (patch)
tree2f3cb92fdf761d1ba5fc6b7273875ad7b0cc6cf5
parentc74c6d8b179c284006c7d9dc16e3e4494bfe26bd (diff)
CSV: store file offset of SQN so we can update it efficiently later
This requires that the SQN field is large enough (8 decimal digits), in order to do in-place changes to the field in the CSV.
-rw-r--r--src/auc.h1
-rw-r--r--src/auc_rec_csv.c16
-rwxr-xr-xsrc/gen_auc_txt.pl2
3 files changed, 15 insertions, 4 deletions
diff --git a/src/auc.h b/src/auc.h
index eba9843..6560dde 100644
--- a/src/auc.h
+++ b/src/auc.h
@@ -28,6 +28,7 @@ struct auc_rec {
struct llist_head list;
struct llist_head hash_list;
uint8_t imsi[15+1];
+ long offset_sqn;
struct osmo_sub_auth_data auth;
};
diff --git a/src/auc_rec_csv.c b/src/auc_rec_csv.c
index 21a87a8..c5e257b 100644
--- a/src/auc_rec_csv.c
+++ b/src/auc_rec_csv.c
@@ -32,8 +32,8 @@
2620301,1,000102030405060708090a0b0c0d0e0f,0f0e0d0c0b0a09080706050403020100,0001,32,0
*/
-static struct auc_rec *auc_rec_from_csv(void *ctx,
- const char *line_orig)
+static struct auc_rec *
+auc_rec_from_csv(void *ctx, const char *line_orig, long offset_nextline)
{
char *line = talloc_strdup(ctx, line_orig);
char *tok;
@@ -99,6 +99,13 @@ static struct auc_rec *auc_rec_from_csv(void *ctx,
if (!tok)
goto ret_free;
rec->auth.u.umts.sqn = strtoull(tok, NULL, 10);
+ if (strlen(tok) != 8)
+ printf("SQN must be 8 digits wide in order to support updates\n");
+ else {
+ /* save file offfset for SQN so we can update it */
+ rec->offset_sqn = offset_nextline - (strlen(line_orig) - (tok - line));
+ }
+
/* IS_OP */
tok = strtok(NULL, ",");
if (!tok)
@@ -191,11 +198,14 @@ int auc_storage_read(void *ctx, const char *fname)
while ((line = fgets(line, 256, file))) {
struct auc_rec *rec;
+ long offset_nextline;
if (line[0] == '#')
continue;
- rec = auc_rec_from_csv(ctx, line);
+ offset_nextline = ftell(file);
+
+ rec = auc_rec_from_csv(ctx, line, offset_nextline);
if (!rec)
continue;
diff --git a/src/gen_auc_txt.pl b/src/gen_auc_txt.pl
index 14cae39..62b259a 100755
--- a/src/gen_auc_txt.pl
+++ b/src/gen_auc_txt.pl
@@ -9,5 +9,5 @@ my $COUNT = $ARGV[0];
my $i;
for ($i = 0; $i < $COUNT; $i++) {
- printf("90170%010u,5,%032u,%032u,0000,%u,0\n", $i, $i, $i, $i);
+ printf("90170%010u,5,%032u,%032u,0000,%08u,0\n", $i, $i, $i, $i);
}