#include <string>
#include "namespaces.hh"
-%%{
- machine dnstext;
- write data;
-}%%
namespace {
void appendSplit(vector<string>& ret, string& segment, char c)
vector<string> segmentDNSText(const string& input )
{
+%%{
+ machine dnstext;
+ write data;
+}%%
+
const char *p = input.c_str(), *pe = input.c_str() + input.length();
const char* eof = pe;
int cs;
escaped = '\\' ((["\\]@reportEscaped) | ([0-9]{3}$reportEscapedNumber%doneEscapedNumber));
plain = (print-'\\'-'"') $ reportPlain;
- labelElement = escaped | plain;
-
-
- main := (('"' labelElement* '"' space?) >segmentBegin %segmentEnd)+;
+ txtElement = escaped | plain;
+
+ main := (('"' txtElement* '"' space?) >segmentBegin %segmentEnd)+;
# Initialize and execute.
write init;
return ret;
};
+string segmentDNSLabel(const string& input )
+{
+%%{
+ machine dnslabel;
+ write data;
+}%%
+
+ const char *p = input.c_str(), *pe = input.c_str() + input.length();
+ //const char* eof = pe;
+ int cs;
+ char val = 0;
+
+ string ret;
+ string segment;
+
+ %%{
+ action segmentEnd {
+ printf("Segment end, segment = '%s'\n", segment.c_str());
+ ret.append(1, (unsigned char)segment.size());
+ ret.append(segment);
+ segment.clear();
+ }
+ action reportEscaped {
+ printf("'\\%c' ", *fpc);
+ segment.append(1, *fpc);
+ }
+ action reportEscapedNumber {
+ char c = *fpc;
+ val *= 10;
+ val += c-'0';
+
+ }
+ action doneEscapedNumber {
+ printf("_%c_ ", val);
+ segment.append(1, val);
+ val=0;
+ }
+
+ action reportPlain {
+ printf("'%c' ", *fpc);
+ segment.append(1, *fpc);
+ }
+
+ escaped = '\\' (([\\.]@reportEscaped) | ([0-9]{3}$reportEscapedNumber%doneEscapedNumber));
+ plain = (print-'\\'-'.') $ reportPlain;
+ labelElement = escaped | plain;
+
+
+ main := ((labelElement)* %segmentEnd '.')+;
+
+ # Initialize and execute.
+ write init;
+ write exec;
+ }%%
+
+ if ( cs < dnslabel_first_final ) {
+ throw runtime_error("Unable to parse DNS Label '"+input+"'");
+ }
+ if(ret.empty() || ret[0] != 0)
+ ret.append(1, 0);
+ return ret;
+};
#if 0
int main()
{
int main(int argc, char** argv)
try
-{
+{
po::options_description desc("Allowed options");
desc.add_options()
("help,h", "produce help message")
if(g_vm.count("commands"))
cmds = g_vm["commands"].as<vector<string> >();
-
-
if(cmds.empty() || g_vm.count("help")) {
cerr<<"Usage: \npdnssec [options] [show-zone] [secure-zone] [rectify-zone] [add-zone-key] [deactivate-zone-key] [remove-zone-key] [activate-zone-key]\n";
cerr<<" [import-zone-key] [export-zone-key] [set-nsec3] [set-presigned] [unset-nsec3] [unset-presigned] [export-zone-dnskey]\n\n";