9
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.
This commit is contained in:
Harald Welte 2012-09-16 09:13:34 +02:00
parent c74c6d8b17
commit c5097633d0
3 changed files with 15 additions and 4 deletions

View File

@ -28,6 +28,7 @@ struct auc_rec {
struct llist_head list; struct llist_head list;
struct llist_head hash_list; struct llist_head hash_list;
uint8_t imsi[15+1]; uint8_t imsi[15+1];
long offset_sqn;
struct osmo_sub_auth_data auth; struct osmo_sub_auth_data auth;
}; };

View File

@ -32,8 +32,8 @@
2620301,1,000102030405060708090a0b0c0d0e0f,0f0e0d0c0b0a09080706050403020100,0001,32,0 2620301,1,000102030405060708090a0b0c0d0e0f,0f0e0d0c0b0a09080706050403020100,0001,32,0
*/ */
static struct auc_rec *auc_rec_from_csv(void *ctx, static struct auc_rec *
const char *line_orig) auc_rec_from_csv(void *ctx, const char *line_orig, long offset_nextline)
{ {
char *line = talloc_strdup(ctx, line_orig); char *line = talloc_strdup(ctx, line_orig);
char *tok; char *tok;
@ -99,6 +99,13 @@ static struct auc_rec *auc_rec_from_csv(void *ctx,
if (!tok) if (!tok)
goto ret_free; goto ret_free;
rec->auth.u.umts.sqn = strtoull(tok, NULL, 10); 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 */ /* IS_OP */
tok = strtok(NULL, ","); tok = strtok(NULL, ",");
if (!tok) if (!tok)
@ -191,11 +198,14 @@ int auc_storage_read(void *ctx, const char *fname)
while ((line = fgets(line, 256, file))) { while ((line = fgets(line, 256, file))) {
struct auc_rec *rec; struct auc_rec *rec;
long offset_nextline;
if (line[0] == '#') if (line[0] == '#')
continue; continue;
rec = auc_rec_from_csv(ctx, line); offset_nextline = ftell(file);
rec = auc_rec_from_csv(ctx, line, offset_nextline);
if (!rec) if (!rec)
continue; continue;

View File

@ -9,5 +9,5 @@ my $COUNT = $ARGV[0];
my $i; my $i;
for ($i = 0; $i < $COUNT; $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);
} }