8
0
Fork 0

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.
master
Harald Welte 11 years ago
parent c74c6d8b17
commit c5097633d0
  1. 1
      src/auc.h
  2. 16
      src/auc_rec_csv.c
  3. 2
      src/gen_auc_txt.pl

@ -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;
};

@ -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;

@ -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);
}