DNSKEYRecordContent getRSAKeyFromISC(rsa_context* rsa, const char* fname)
{
- char line[1024];
-
string sline;
string key,value;
map<string, mpi*> places;
unsigned char decoded[1024];
DNSKEYRecordContent drc;
string modulus, exponent;
- while(fgets(line, sizeof(line),fp)) {
- sline.assign(line);
- tie(key,value)=splitField(line, ':');
+ while(stringfgets(fp, sline)) {
+ tie(key,value)=splitField(sline, ':');
trim(value);
if(places.count(key)) {
freeaddrinfo(res);
return 0;
}
+
+//! read a line of text from a FILE* to a std::string, returns false on 'no data'
+bool stringfgets(FILE* fp, std::string& line)
+{
+ char buffer[1024];
+ line.clear();
+
+ do {
+ if(!fgets(buffer, sizeof(buffer), fp))
+ return !line.empty();
+
+ line.append(buffer);
+ } while(!strchr(buffer, '\n'));
+ return true;
+}
string labelReverse(const std::string& qname);
std::string dotConcat(const std::string& a, const std::string &b);
int makeIPv6sockaddr(const std::string& addr, struct sockaddr_in6* ret);
+bool stringfgets(FILE* fp, std::string& line);
#endif
shared_ptr<FILE> fp=shared_ptr<FILE>(rfp, fclose);
- char line[1024];
+ string line;
int linenum=0;
uint64_t before = newMap->size();
- while(linenum++, fgets(line, sizeof(line)-1, fp.get())) {
+ while(linenum++, stringfgets(fp.get(), line)) {
string domain, instructions;
tie(domain, instructions)=splitField(line, '=');
trim(domain);
return true;
}
+
bool ZoneParserTNG::getLine()
{
while(!d_filestates.empty()) {
- char buffer[16384];
- if(fgets(buffer, sizeof(buffer)-1, d_filestates.top().d_fp)) {
+ if(stringfgets(d_filestates.top().d_fp, d_line)) {
d_filestates.top().d_lineno++;
- d_line=buffer;
return true;
}
fclose(d_filestates.top().d_fp);