00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifdef HAVE_CONFIG_H
00011 #include "config.h"
00012 #endif
00013
00014 #include <stdlib.h>
00015 #include <errno.h>
00016
00017 #include "WordKeyInfo.h"
00018 #include "StringList.h"
00019
00020 #define WORDKEYFIELD_BITS_MAX 64
00021
00022
00023
00024
00025
00026 WordKeyInfo::WordKeyInfo(const Configuration& config)
00027 {
00028 nfields = -1;
00029
00030 const String &keydesc = config["wordlist_wordkey_description"];
00031
00032 if(!keydesc.empty()) {
00033 Set(keydesc);
00034 } else {
00035 fprintf(stderr, "WordKeyInfo::WordKeyInfo: didn't find key description in config\n");
00036 }
00037 }
00038
00039 int
00040 WordKeyInfo::Set(const String &desc)
00041 {
00042 int ret = 0;
00043 StringList line(desc, "/");
00044
00045 if(line.Count() > WORD_KEY_MAX_NFIELDS) {
00046 fprintf(stderr, "WordKeyInfo::Set: too many fields in %s, max is %d\n", (const char*)desc, WORD_KEY_MAX_NFIELDS);
00047 return EINVAL;
00048 }
00049
00050 if(line.Count() <= 0) {
00051 fprintf(stderr, "WordKeyInfo::Set: no fields\n");
00052 return EINVAL;
00053 }
00054
00055 int i;
00056 for(i = 0; i < line.Count(); i++) {
00057 char* field = line[i];
00058 WordKeyField& key_field = fields[i];
00059
00060
00061
00062 StringList pair(field, "\t ");
00063
00064 if(pair.Count() != 2) {
00065 fprintf(stderr, "WordKeyInfo::AddField: there must be exactly two strings separated by a white space (space or tab) in a field description (%s in key description %s)\n", field, (const char*)desc);
00066 return EINVAL;
00067 }
00068
00069 key_field.bits = atoi(pair[1]);
00070 key_field.name = pair[0];
00071 }
00072
00073 nfields = line.Count();
00074
00075 return ret;
00076 }
00077