From 3b404dd029a2aba05efc2edadcc7f67c59746cf7 Mon Sep 17 00:00:00 2001 From: Michael Krelin Date: Mon, 18 Jun 2007 21:38:12 +0000 Subject: Adhere to Postel's Law. That is, be liberal when parsing key/value parameters from remote. Along with configure switch to disable it. --- (limited to 'lib/params.cc') diff --git a/lib/params.cc b/lib/params.cc index b181811..ea86d3a 100644 --- a/lib/params.cc +++ b/lib/params.cc @@ -4,6 +4,8 @@ #include #include +#include "config.h" + namespace opkele { using namespace std; @@ -30,12 +32,26 @@ namespace opkele { string::size_type co = kv.find(':',p); if(co==string::npos) break; +#ifndef POSTELS_LAW string::size_type nl = kv.find('\n',co+1); if(nl==string::npos) throw bad_input(OPKELE_CP_ "malformed input"); if(nl>co) insert(value_type(kv.substr(p,co-p),kv.substr(co+1,nl-co-1))); p = nl+1; +#else /* POSTELS_LAW */ + string::size_type lb = kv.find_first_of("\r\n",co+1); + if(lb==string::npos) { + insert(value_type(kv.substr(p,co-p),kv.substr(co+1))); + break; + } + if(lb>co) + insert(value_type(kv.substr(p,co-p),kv.substr(co+1,lb-co-1))); + string::size_type nolb = kv.find_first_not_of("\r\n",lb); + if(nolb==string::npos) + break; + p = nolb; +#endif /* POSTELS_LAW */ } } -- cgit v0.9.0.2