fixed some newline encodings

This commit is contained in:
Martin Willi
2009-04-16 14:00:14 +00:00
parent 6c7dde286e
commit 5cac9e4c34
2 changed files with 55 additions and 55 deletions
@@ -45,16 +45,16 @@ struct private_eap_sim_file_triplets_t {
* mutex to lock triplets list * mutex to lock triplets list
*/ */
mutex_t *mutex; mutex_t *mutex;
}; };
/** /**
* A single triplet * A single triplet
*/ */
typedef struct { typedef struct {
identification_t *imsi; identification_t *imsi;
char rand[RAND_LEN]; char rand[RAND_LEN];
char sres[SRES_LEN]; char sres[SRES_LEN];
char kc[KC_LEN]; char kc[KC_LEN];
} triplet_t; } triplet_t;
/** /**
@@ -105,7 +105,7 @@ static bool enumerator_enumerate(triplet_enumerator_t *e, identification_t **ims
char **rand, char **sres, char **kc) char **rand, char **sres, char **kc)
{ {
triplet_t *triplet; triplet_t *triplet;
if (e->inner->enumerate(e->inner, &triplet)) if (e->inner->enumerate(e->inner, &triplet))
{ {
e->current = triplet; e->current = triplet;
@@ -148,45 +148,45 @@ static void parse_token(char *to, char *from, size_t len)
memset(to, 0, len); memset(to, 0, len);
memcpy(to + len - chunk.len, chunk.ptr, chunk.len); memcpy(to + len - chunk.len, chunk.ptr, chunk.len);
free(chunk.ptr); free(chunk.ptr);
} }
/** /**
* Read the triplets from the file * Read the triplets from the file
*/ */
static void read_triplets(private_eap_sim_file_triplets_t *this, char *path) static void read_triplets(private_eap_sim_file_triplets_t *this, char *path)
{ {
char line[512]; char line[512];
FILE *file; FILE *file;
int i, nr = 0; int i, nr = 0;
file = fopen(path, "r"); file = fopen(path, "r");
if (file == NULL) if (file == NULL)
{ {
DBG1(DBG_CFG, "opening triplet file %s failed: %s", DBG1(DBG_CFG, "opening triplet file %s failed: %s",
path, strerror(errno)); path, strerror(errno));
return; return;
} }
/* read line by line */ /* read line by line */
while (fgets(line, sizeof(line), file)) while (fgets(line, sizeof(line), file))
{ {
triplet_t *triplet; triplet_t *triplet;
enumerator_t *enumerator; enumerator_t *enumerator;
char *token; char *token;
nr++; nr++;
/* skip comments, empty lines */ /* skip comments, empty lines */
switch (line[0]) switch (line[0])
{ {
case '\n': case '\n':
case '\r': case '\r':
case '#': case '#':
case '\0': case '\0':
continue; continue;
default: default:
break; break;
} }
triplet = malloc_thing(triplet_t); triplet = malloc_thing(triplet_t);
memset(triplet, 0, sizeof(triplet_t)); memset(triplet, 0, sizeof(triplet_t));
i = 0; i = 0;
@@ -214,22 +214,22 @@ static void read_triplets(private_eap_sim_file_triplets_t *this, char *path)
} }
enumerator->destroy(enumerator); enumerator->destroy(enumerator);
if (i < 4) if (i < 4)
{ {
DBG1(DBG_CFG, "error in triplet file, line %d", nr); DBG1(DBG_CFG, "error in triplet file, line %d", nr);
triplet_destroy(triplet); triplet_destroy(triplet);
continue; continue;
} }
DBG2(DBG_CFG, "triplet: imsi %D\nrand %b\nsres %b\nkc %b", DBG2(DBG_CFG, "triplet: imsi %D\nrand %b\nsres %b\nkc %b",
triplet->imsi, triplet->rand, RAND_LEN, triplet->imsi, triplet->rand, RAND_LEN,
triplet->sres, SRES_LEN, triplet->kc, KC_LEN); triplet->sres, SRES_LEN, triplet->kc, KC_LEN);
this->triplets->insert_last(this->triplets, triplet); this->triplets->insert_last(this->triplets, triplet);
} }
fclose(file); fclose(file);
DBG1(DBG_CFG, "read %d triplets from %s", DBG1(DBG_CFG, "read %d triplets from %s",
this->triplets->get_count(this->triplets), path); this->triplets->get_count(this->triplets), path);
} }
/** /**
@@ -28,17 +28,17 @@
/** /**
* size of RAND value * size of RAND value
*/ */
#define RAND_LEN 16 #define RAND_LEN 16
/** /**
* size of SRES value * size of SRES value
*/ */
#define SRES_LEN 4 #define SRES_LEN 4
/** /**
* size of KC value * size of KC value
*/ */
#define KC_LEN 8 #define KC_LEN 8
typedef struct eap_sim_file_triplets_t eap_sim_file_triplets_t; typedef struct eap_sim_file_triplets_t eap_sim_file_triplets_t;
@@ -46,7 +46,7 @@ typedef struct eap_sim_file_triplets_t eap_sim_file_triplets_t;
/** /**
* Reads triplets from a triplets.dat file. * Reads triplets from a triplets.dat file.
* *
* The file is in freeradius triplet file syntax: * The file is in freeradius triplet file syntax:
* http://www.freeradius.org/radiusd/doc/rlm_sim_triplets * http://www.freeradius.org/radiusd/doc/rlm_sim_triplets
*/ */
struct eap_sim_file_triplets_t { struct eap_sim_file_triplets_t {