|
@@ -51,7 +51,8 @@ static void checkdelim(std::istream& ss, const char delim = ':')
|
|
|
char d;
|
|
|
if(!(ss.get(d) && d == delim)) {
|
|
|
throw DL_ABORT_EX
|
|
|
- (StringFormat("Delimiter '%c' not found.", delim).str());
|
|
|
+ (StringFormat("Bencode decoding failed: Delimiter '%c' not found.",
|
|
|
+ delim).str());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -60,7 +61,8 @@ static std::string decoderawstring(std::istream& ss)
|
|
|
int length;
|
|
|
ss >> length;
|
|
|
if(!ss || length < 0) {
|
|
|
- throw DL_ABORT_EX("A positive integer expected but none found.");
|
|
|
+ throw DL_ABORT_EX("Bencode decoding failed:"
|
|
|
+ " A positive integer expected but none found.");
|
|
|
}
|
|
|
// TODO check length, it must be less than or equal to INT_MAX
|
|
|
checkdelim(ss);
|
|
@@ -70,7 +72,8 @@ static std::string decoderawstring(std::istream& ss)
|
|
|
delete [] buf;
|
|
|
if(ss.gcount() != static_cast<int>(length)) {
|
|
|
throw DL_ABORT_EX
|
|
|
- (StringFormat("Expected %lu bytes of data, but only %d read.",
|
|
|
+ (StringFormat("Bencode decoding failed:"
|
|
|
+ " Expected %lu bytes of data, but only %d read.",
|
|
|
static_cast<unsigned long>(length), ss.gcount()).str());
|
|
|
}
|
|
|
return str;
|
|
@@ -86,7 +89,8 @@ static BDE decodeinteger(std::istream& ss)
|
|
|
BDE::Integer integer;
|
|
|
ss >> integer;
|
|
|
if(!ss) {
|
|
|
- throw DL_ABORT_EX("Integer expected but none found");
|
|
|
+ throw DL_ABORT_EX("Bencode decoding failed:"
|
|
|
+ " Integer expected but none found");
|
|
|
}
|
|
|
checkdelim(ss, 'e');
|
|
|
return BDE(integer);
|
|
@@ -105,7 +109,8 @@ static BDE decodedict(std::istream& ss)
|
|
|
dict[key] = decodeiter(ss);
|
|
|
}
|
|
|
}
|
|
|
- throw DL_ABORT_EX("Unexpected EOF in dict context. 'e' expected.");
|
|
|
+ throw DL_ABORT_EX("Bencode decoding failed:"
|
|
|
+ " Unexpected EOF in dict context. 'e' expected.");
|
|
|
}
|
|
|
|
|
|
static BDE decodelist(std::istream& ss)
|
|
@@ -120,15 +125,17 @@ static BDE decodelist(std::istream& ss)
|
|
|
list << decodeiter(ss);
|
|
|
}
|
|
|
}
|
|
|
- throw DL_ABORT_EX("Unexpected EOF in list context. 'e' expected.");
|
|
|
+ throw DL_ABORT_EX("Bencode decoding failed:"
|
|
|
+ " Unexpected EOF in list context. 'e' expected.");
|
|
|
}
|
|
|
|
|
|
static BDE decodeiter(std::istream& ss)
|
|
|
{
|
|
|
char c;
|
|
|
if(!ss.get(c)) {
|
|
|
- throw DL_ABORT_EX("Unexpected EOF in term context."
|
|
|
- " 'd', 'l', 'i' or digit is expected.");
|
|
|
+ throw DL_ABORT_EX("Bencode decoding failed:"
|
|
|
+ " Unexpected EOF in term context."
|
|
|
+ " 'd', 'l', 'i' or digit is expected.");
|
|
|
}
|
|
|
if(c == 'd') {
|
|
|
return decodedict(ss);
|
|
@@ -169,7 +176,8 @@ BDE decodeFromFile(const std::string& filename)
|
|
|
return decode(f);
|
|
|
} else {
|
|
|
throw DL_ABORT_EX
|
|
|
- (StringFormat("Cannot open file '%s'.", filename.c_str()).str());
|
|
|
+ (StringFormat("Bencode decoding failed:"
|
|
|
+ " Cannot open file '%s'.", filename.c_str()).str());
|
|
|
}
|
|
|
}
|
|
|
|