Skip to content

Commit

Permalink
Extended the keyspace to include any character except '/'. Resulting …
Browse files Browse the repository at this point in the history
…file format is version 3.0.

There are no visible changes in the interface, when a file is written, it start as version 2 and
is changed to version 3 only if a non-conformant key is written.

Removed aff_name_check() from the interface, added aff_name_check[23](). Aslo added aff_reader_namecheck().

Added support for python 3


git-svn-id: file:///Users/avp/tmp/svn.20121212/LHPC/aff/trunk@2246 65d2813f-f11f-0410-b17b-8647a28db151
  • Loading branch information
avp committed Aug 9, 2011
1 parent 4d5617a commit 15ab460
Show file tree
Hide file tree
Showing 11 changed files with 1,104 additions and 143 deletions.
6 changes: 5 additions & 1 deletion lib/aff-i.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ enum {
AFF_SIG_OFF_SIZE = 28,
AFF_SIG_SIZE = 32,
AFF_HEADER_SIZE1 = 144, /* the full header size V1 */
AFF_HEADER_SIZE2 = 168 /* the full header size V2 */
AFF_HEADER_SIZE2 = 168 /* the full header size V2 and V3 */
};

#define AFF_SIG1 "LHPC AFF version 1.0"
#define AFF_SIG2 "LHPC AFF version 2.0"
#define AFF_SIG3 "LHPC AFF version 3.0"

struct WSection_s {
uint64_t start;
Expand All @@ -29,6 +30,7 @@ struct AffWriter_s {
struct AffMD5_s header_md5;
int header_size;
const char *error;
int version;
int fatal_error;

FILE *file;
Expand All @@ -51,6 +53,7 @@ struct RSection_s {

struct AffReader_s {
const char *error;
int version;
int fatal_error;

FILE *file;
Expand All @@ -66,6 +69,7 @@ struct AffReader_s {

extern uint8_t aff_signature1[];
extern uint8_t aff_signature2[];
extern uint8_t aff_signature3[];

char *aff_strsep(char *str, char **end, char delim);

Expand Down
39 changes: 32 additions & 7 deletions lib/aff-namecheck.c
Original file line number Diff line number Diff line change
@@ -1,21 +1,46 @@
#include <stdint.h>
#include <string.h>
#include <ctype.h>
#include "aff.h"
#include "md5.h"
#include "aff-i.h"

int
aff_name_check(const char *name)
aff_name_check3(const char *name)
{
if (name == 0 || *name == 0)
return 1;
for (;*name; name++) {
if (*name == '/')
return 1;
}
return 0;
}

int
aff_name_check2(const char *name)
{
int ch;
if (name == 0 || *name == 0)
return 1;
return 1;
ch = name[0];
if (!(isalpha(ch) || strchr(":_", ch)))
return 1;
return 1;
for (;*++name;) {
ch = *name;
if (!(isalnum(ch) || strchr(":_-.", ch)))
return 1;
ch = *name;
if (!(isalnum(ch) || strchr(":_-.", ch)))
return 1;
}
return 0;
}

int aff_reader_namecheck(struct AffReader_s *aff, const char *name)
{
switch (aff->version) {
case 2:
return aff_name_check2(name);
case 3:
return aff_name_check3(name);
default:
return 1;
}
}
1 change: 1 addition & 0 deletions lib/aff-signature.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
#include "aff-i.h"
uint8_t aff_signature1[] = AFF_SIG1;
uint8_t aff_signature2[] = AFF_SIG2;
uint8_t aff_signature3[] = AFF_SIG3;
8 changes: 6 additions & 2 deletions lib/aff.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
#define MARK_c7329614_7d7a_4efe_9f6d_87477961bc99

/* AFF library information */
#define AFF_VERSION "XXX Version 2.1.0x $Id$"
#define AFF_VERSION "XXX Version 3.0.0x $Id$"
const char *aff_version(void);
int aff_name_check(const char *name);
int aff_name_check2(const char *name);
int aff_name_check3(const char *name);

/* AFF objects. Writers.
*
Expand All @@ -24,6 +25,7 @@ struct AffNode_s;
struct AffWriter_s *aff_writer(const char *file_name);
const char *aff_writer_close(struct AffWriter_s *aff);
const char *aff_writer_errstr(struct AffWriter_s *aff);
int aff_writer_clearerr(struct AffWriter_s *aff);
struct AffSTable_s *aff_writer_stable(struct AffWriter_s *aff);
struct AffTree_s *aff_writer_tree(struct AffWriter_s *aff);
struct AffNode_s *aff_writer_root(struct AffWriter_s *aff);
Expand Down Expand Up @@ -66,6 +68,7 @@ struct AffReader_s;
struct AffReader_s *aff_reader(const char *file_name);
void aff_reader_close(struct AffReader_s *aff);
const char *aff_reader_errstr(struct AffReader_s *aff);
int aff_reader_clearerr(struct AffReader_s *aff);
struct AffTree_s *aff_reader_tree(struct AffReader_s *aff);
struct AffSTable_s *aff_reader_stable(struct AffReader_s *aff);
int aff_reader_check(struct AffReader_s *aff);
Expand All @@ -92,5 +95,6 @@ int aff_node_get_complex(struct AffReader_s *aff,
struct AffNode_s *n,
double _Complex *d,
uint32_t s);
int aff_reader_namecheck(struct AffReader_s *aff, const char *name);

#endif /* !defined(MARK_c7329614_7d7a_4efe_9f6d_87477961bc99) */
30 changes: 20 additions & 10 deletions lib/raff-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,10 @@ unpack2(struct AffReader_s *aff, struct RSection_s *section,

static int
read_sig(struct AffReader_s *aff,
const uint8_t sig[AFF_SIG_SIZE],
const uint8_t *aff_sig)
const uint8_t sig[AFF_SIG_SIZE])
{
uint32_t d_exp;

if (memcmp(sig, aff_sig, AFF_SIG_ID_SIZE) != 0) {
aff->error = "AFF signature mismatch";
aff->fatal_error = 1;
return 1;
}

if (sig[AFF_SIG_OFF_DBITS] != sizeof (double) * CHAR_BIT) {
aff->error = "AFF size of double mismatch";
aff->fatal_error = 1;
Expand Down Expand Up @@ -127,9 +120,16 @@ read_header1(struct AffReader_s *aff,
uint8_t md5_read[16];
uint8_t buf[AFF_HEADER_SIZE1 - AFF_SIG_SIZE];

if (read_sig(aff, sig, aff_signature1))
if (read_sig(aff, sig))
return 1;

if (memcmp(sig, aff_signature1, AFF_SIG_ID_SIZE) != 0) {
aff->error = "AFF signature mismatch";
aff->fatal_error = 1;
return 1;
}
aff->version = 2;

if (fread(buf, sizeof (buf), 1, aff->file) != 1) {
aff->error = "Reading V1 header failed";
aff->fatal_error = 1;
Expand Down Expand Up @@ -160,9 +160,19 @@ read_header2(struct AffReader_s *aff,
uint8_t md5_read[16];
uint8_t buf[AFF_HEADER_SIZE2 - AFF_SIG_SIZE];

if (read_sig(aff, sig, aff_signature2))
if (read_sig(aff, sig))
return 1;

if (memcmp(sig, aff_signature2, AFF_SIG_ID_SIZE) == 0) {
aff->version = 2;
} else if (memcmp(sig, aff_signature3, AFF_SIG_ID_SIZE) == 0) {
aff->version = 3;
} else {
aff->error = "AFF signature mismatch";
aff->fatal_error = 1;
return 1;
}

if (fread(buf, sizeof (buf), 1, aff->file) != 1) {
aff->error = "Reading V2 header failed";
aff->fatal_error = 1;
Expand Down
23 changes: 17 additions & 6 deletions lib/waff-fini.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,24 @@ aff_writer_close(struct AffWriter_s *aff)
}

aff_md5_init(&aff->header_md5);
aff->header_size = strlen((const char *)aff_signature2) + 1;
if (fwrite(aff_signature2, aff->header_size, 1, aff->file) != 1) {
aff->error = "AFF Signature writing erorr";
aff->fatal_error = 1;
goto end;
{
const uint8_t *sig = 0;
switch (aff->version) {
case 2: sig = (const uint8_t *)aff_signature2; break;
case 3: sig = (const uint8_t *)aff_signature3; break;
default:
aff->error = "AFF internal error";
aff->fatal_error = 1;
goto end;
}
aff->header_size = strlen((char *)sig) + 1;
if (fwrite(sig, aff->header_size, 1, aff->file) != 1) {
aff->error = "AFF Signature writing erorr";
aff->fatal_error = 1;
goto end;
}
aff_md5_update(&aff->header_md5, sig, aff->header_size);
}
aff_md5_update(&aff->header_md5, aff_signature2, aff->header_size);

buffer[0] = sizeof (double) * CHAR_BIT;
buffer[1] = FLT_RADIX;
Expand Down
1 change: 1 addition & 0 deletions lib/waff-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ aff_writer(const char *file_name)
aff->data_hdr.size = 0;
aff->data_hdr.records = 0;
aff->data_hdr.start = AFF_HEADER_SIZE2;
aff->version = 2; /* upgrade to 3 only if a post version 2 key is created */

return aff;

Expand Down
35 changes: 24 additions & 11 deletions lib/waff-mkdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,40 @@

struct AffNode_s *
aff_writer_mkdir(struct AffWriter_s *aff,
struct AffNode_s *dir,
const char *name)
struct AffNode_s *dir,
const char *name)
{
struct AffNode_s *res;

if (aff == 0 || aff->error)
return 0;
return 0;
if (dir == 0) {
aff->error = "NULL dir in aff_writer_mkdir()";
return 0;
aff->error = "NULL dir in aff_writer_mkdir()";
return 0;
}
if (name == 0) {
aff->error = "NULL name in aff_writer_mkdir()";
return 0;
aff->error = "NULL name in aff_writer_mkdir()";
return 0;
}
if (aff_name_check(name)) {
aff->error = "Illegal name in aff_writer_mkdir()";
return 0;
switch (aff->version) {
case 2:
if (aff_name_check2(name) == 0)
break;
/* through */
case 3:
if (aff_name_check3(name)) {
aff->error = "Illegal name in aff_writer_mkdir()";
return 0;
}
aff->version = 3;
break;
default:
aff->error = "AFF internal error in aff_writer_mkdir()";
aff->fatal_error = 1;
return 0;
}
res = aff_node_chdir(aff->tree, aff->stable, dir, 1, name);
if (res == 0)
aff->error = "aff_writer_mkdir() failed";
aff->error = "aff_writer_mkdir() failed";
return res;
}
Loading

0 comments on commit 15ab460

Please sign in to comment.