From df006bfbbe8e8b49a52296f42894d4a452ed4c90 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 6 Aug 2011 23:53:52 +0300 Subject: [PATCH] Style update: spaces around assignments --- source/client.cpp | 36 +++++++++++++------------- source/message.cpp | 62 ++++++++++++++++++++++----------------------- source/message.h | 2 +- source/request.cpp | 22 ++++++++-------- source/response.cpp | 14 +++++----- source/server.cpp | 44 ++++++++++++++++---------------- source/status.h | 14 +++++----- source/utils.cpp | 62 ++++++++++++++++++++++----------------------- source/version.cpp | 2 +- 9 files changed, 129 insertions(+), 129 deletions(-) diff --git a/source/client.cpp b/source/client.cpp index be57918..cb7b0ea 100644 --- a/source/client.cpp +++ b/source/client.cpp @@ -37,7 +37,7 @@ void Client::use_event_dispatcher(IO::EventDispatcher *ed) { if(event_disp && sock) event_disp->remove(*sock); - event_disp=ed; + event_disp = ed; if(event_disp && sock) event_disp->add(*sock); } @@ -47,13 +47,13 @@ void Client::start_request(const Request &r) if(request) throw InvalidState("Already processing a request"); - string host=r.get_header("Host"); + string host = r.get_header("Host"); if(host.find(':')==string::npos) - host+=":80"; - RefPtr addr=Net::resolve(host); + host += ":80"; + RefPtr addr = Net::resolve(host); delete sock; - sock=new Net::StreamSocket(addr->get_family()); + sock = new Net::StreamSocket(addr->get_family()); sock->set_block(false); sock->signal_data_available.connect(sigc::mem_fun(this, &Client::data_available)); @@ -63,12 +63,12 @@ void Client::start_request(const Request &r) sock->connect(*addr); - request=new Request(r); + request = new Request(r); if(!user_agent.empty()) request->set_header("User-Agent", user_agent); delete response; - response=0; + response = 0; in_buf.clear(); } @@ -84,7 +84,7 @@ void Client::tick() if(!request) return; - while(IO::PollEvent ev=IO::poll(*sock, sock->get_events(), Time::zero)) + while(IO::PollEvent ev = IO::poll(*sock, sock->get_events(), Time::zero)) sock->event(ev); if(response && response->is_complete()) @@ -92,9 +92,9 @@ void Client::tick() signal_response_complete.emit(*response); delete sock; - sock=0; + sock = 0; delete request; - request=0; + request = 0; } } @@ -107,9 +107,9 @@ void Client::wait_response() void Client::abort() { delete sock; - sock=0; + sock = 0; delete request; - request=0; + request = 0; } void Client::connect_finished(int err) @@ -120,7 +120,7 @@ void Client::connect_finished(int err) sock->close(); delete request; - request=0; + request = 0; } else sock->write(request->str()); @@ -129,21 +129,21 @@ void Client::connect_finished(int err) void Client::data_available() { char rbuf[4096]; - unsigned len=sock->read(rbuf, sizeof(rbuf)); + unsigned len = sock->read(rbuf, sizeof(rbuf)); in_buf.append(rbuf, len); if(!response) { if(in_buf.find("\r\n\r\n")!=string::npos || in_buf.find("\n\n")!=string::npos) { - response=new Response(Response::parse(in_buf)); + response = new Response(Response::parse(in_buf)); response->set_user_data(request->get_user_data()); - in_buf=string(); + in_buf = string(); } } else { - len=response->parse_content(in_buf); + len = response->parse_content(in_buf); in_buf.erase(0, len); } @@ -153,7 +153,7 @@ void Client::data_available() sock->close(); delete request; - request=0; + request = 0; } } diff --git a/source/message.cpp b/source/message.cpp index 4aaa8bf..2223377 100644 --- a/source/message.cpp +++ b/source/message.cpp @@ -23,7 +23,7 @@ Message::Message(): void Message::set_header(const string &hdr, const string &val) { - headers[normalize_header_name(hdr)]=val; + headers[normalize_header_name(hdr)] = val; } bool Message::has_header(const string &hdr) const @@ -33,7 +33,7 @@ bool Message::has_header(const string &hdr) const const string &Message::get_header(const string &hdr) const { - HeaderMap::const_iterator i=headers.find(normalize_header_name(hdr)); + HeaderMap::const_iterator i = headers.find(normalize_header_name(hdr)); if(i==headers.end()) throw KeyError("Undefined header", hdr); @@ -42,7 +42,7 @@ const string &Message::get_header(const string &hdr) const void Message::add_content(const string &d) { - content+=d; + content += d; if(headers.count("Content-Type")==0) set_header("Content-Type", "text/plain"); set_header("Content-Length", lexical_cast(content.size())); @@ -50,7 +50,7 @@ void Message::add_content(const string &d) void Message::set_user_data(const Variant &d) { - user_data=d; + user_data = d; } unsigned Message::parse_content(const string &d) @@ -58,42 +58,42 @@ unsigned Message::parse_content(const string &d) if(complete) return 0; - HeaderMap::const_iterator i=headers.find("Content-Length"); + HeaderMap::const_iterator i = headers.find("Content-Length"); if(i!=headers.end()) { - unsigned needed=lexical_cast(i->second)-content.size(); - unsigned len=min(needed, d.size()); + unsigned needed = lexical_cast(i->second)-content.size(); + unsigned len = min(needed, d.size()); content.append(d, 0, len); if(len==needed) - complete=true; + complete = true; return len; } - i=headers.find("Transfer-Encoding"); + i = headers.find("Transfer-Encoding"); if(i!=headers.end() && strcasecmp(i->second, "chunked")==0) { - unsigned pos=0; + unsigned pos = 0; while(!complete && pos(strip(d.substr(pos, lf-pos)), "x"); + chunk_length = lexical_cast(strip(d.substr(pos, lf-pos)), "x"); if(chunk_length==0) - complete=true; - pos=lf+1; + complete = true; + pos = lf+1; } else { - unsigned len=min(chunk_length, d.size()-pos); + unsigned len = min(chunk_length, d.size()-pos); content.append(d, pos, len); - chunk_length-=len; - if((pos=d.find('\n', pos+len))!=string::npos) + chunk_length -= len; + if((pos = d.find('\n', pos+len))!=string::npos) ++pos; } } @@ -101,28 +101,28 @@ unsigned Message::parse_content(const string &d) return pos; } - complete=true; + complete = true; return 0; } unsigned Message::parse_headers(const string &d) { - unsigned start=0; + unsigned start = 0; while(1) { - unsigned lf=d.find('\n', start); + unsigned lf = d.find('\n', start); if(lf==string::npos) throw InvalidParameterValue("Incomplete response"); if(lf==start || (d[start]=='\r' && lf==start+1)) return lf+1; - unsigned colon=d.find(':', start); + unsigned colon = d.find(':', start); if(colon>lf) throw InvalidParameterValue("No colon in header"); set_header(d.substr(start, colon-start), strip(d.substr(colon+1, lf-colon-1))); - start=lf+1; + start = lf+1; } } @@ -132,28 +132,28 @@ string Message::str_common() const for(HeaderMap::const_iterator i=headers.begin(); i!=headers.end(); ++i) if(i->first[0]!='-') - result+=format("%s: %s\r\n", i->first, i->second); - result+="\r\n"; - result+=content; + result += format("%s: %s\r\n", i->first, i->second); + result += "\r\n"; + result += content; return result; } string Message::normalize_header_name(const string &hdr) const { - string result=hdr; - bool upper=true; + string result = hdr; + bool upper = true; for(string::iterator i=result.begin(); i!=result.end(); ++i) { if(upper) { - *i=toupper(*i); - upper=false; + *i = toupper(*i); + upper = false; } else if(*i=='-') - upper=true; + upper = true; else - *i=tolower(*i); + *i = tolower(*i); } return result; } diff --git a/source/message.h b/source/message.h index 6e139bd..b1809a6 100644 --- a/source/message.h +++ b/source/message.h @@ -41,7 +41,7 @@ public: const Variant &get_user_data() const { return user_data; } bool is_complete() const { return complete; } unsigned parse_content(const std::string &); - virtual std::string str() const =0; + virtual std::string str() const = 0; protected: unsigned parse_headers(const std::string &); std::string str_common() const; diff --git a/source/request.cpp b/source/request.cpp index 6bad370..ba47c4d 100644 --- a/source/request.cpp +++ b/source/request.cpp @@ -23,23 +23,23 @@ Request::Request(const string &m, const string &p): string Request::str() const { - string result=format("%s %s %s\r\n", method, path, version_str(http_version)); - result+=str_common(); + string result = format("%s %s %s\r\n", method, path, version_str(http_version)); + result += str_common(); return result; } Request Request::parse(const string &str) { - unsigned lf=str.find('\n'); - vector parts=split(str.substr(0, lf-(str[lf-1]=='\r')), ' ', 2); + unsigned lf = str.find('\n'); + vector parts = split(str.substr(0, lf-(str[lf-1]=='\r')), ' ', 2); if(parts.size()<3) throw InvalidParameterValue("Invalid request"); Request result(parts[0], parts[1]); - result.http_version=parse_version(parts[2]); + result.http_version = parse_version(parts[2]); - lf+=result.parse_headers(str.substr(lf+1)); + lf += result.parse_headers(str.substr(lf+1)); result.parse_content(str.substr(lf+1)); @@ -48,16 +48,16 @@ Request Request::parse(const string &str) Request Request::from_url(const string &str) { - Url url=parse_url(str); + Url url = parse_url(str); if(url.scheme!="http") throw InvalidParameterValue("Only http scheme is supported"); - string path=url.path; + string path = url.path; if(path.empty()) - path="/"; + path = "/"; if(!url.query.empty()) { - path+='?'; - path+=url.query; + path += '?'; + path += url.query; } Request result("GET", path); diff --git a/source/response.cpp b/source/response.cpp index 4da6742..fe7469d 100644 --- a/source/response.cpp +++ b/source/response.cpp @@ -20,8 +20,8 @@ Response::Response(Status s): string Response::str() const { - string result=format("%s %d %s\r\n", version_str(http_version), static_cast(status), status); - result+=str_common(); + string result = format("%s %d %s\r\n", version_str(http_version), static_cast(status), status); + result += str_common(); return result; } @@ -30,15 +30,15 @@ Response Response::parse(const string &str) { Response result; - unsigned lf=str.find('\n'); - vector parts=split(str.substr(0, lf), ' ', 2); + unsigned lf = str.find('\n'); + vector parts = split(str.substr(0, lf), ' ', 2); if(parts.size()<2) throw InvalidParameterValue("Invalid response"); - result.http_version=parse_version(parts[0]); - result.status=static_cast(lexical_cast(parts[1])); + result.http_version = parse_version(parts[0]); + result.status = static_cast(lexical_cast(parts[1])); - lf+=result.parse_headers(str.substr(lf+1)); + lf += result.parse_headers(str.substr(lf+1)); result.parse_content(str.substr(lf+1)); diff --git a/source/server.cpp b/source/server.cpp index 2e427b9..e0aedf2 100644 --- a/source/server.cpp +++ b/source/server.cpp @@ -28,7 +28,7 @@ Server::Server(unsigned port): unsigned Server::get_port() const { - const Net::SockAddr &addr=sock.get_local_address(); + const Net::SockAddr &addr = sock.get_local_address(); if(addr.get_family()==Net::INET) return static_cast(addr).get_port(); return 0; @@ -42,7 +42,7 @@ void Server::use_event_dispatcher(IO::EventDispatcher *ed) for(list::iterator i=clients.begin(); i!=clients.end(); ++i) event_disp->remove(*i->sock); } - event_disp=ed; + event_disp = ed; if(event_disp) { event_disp->add(sock); @@ -53,23 +53,23 @@ void Server::use_event_dispatcher(IO::EventDispatcher *ed) void Server::delay_response(Response &resp) { - get_client_by_response(resp).async=true; + get_client_by_response(resp).async = true; } void Server::submit_response(Response &resp) { - Client &cl=get_client_by_response(resp); + Client &cl = get_client_by_response(resp); if(cl.async) { cl.sock->write(resp.str()); cl.sock->close(); - cl.stale=true; + cl.stale = true; } } void Server::data_available() { - Net::StreamSocket *csock=sock.accept(); + Net::StreamSocket *csock = sock.accept(); clients.push_back(Client(csock)); csock->signal_data_available.connect(sigc::bind(sigc::mem_fun(this, &Server::client_data_available), sigc::ref(clients.back()))); csock->signal_end_of_file.connect(sigc::bind(sigc::mem_fun(this, &Server::client_end_of_file), sigc::ref(clients.back()))); @@ -87,7 +87,7 @@ void Server::client_data_available(Client &cl) } char rbuf[4096]; - unsigned len=cl.sock->read(rbuf, sizeof(rbuf)); + unsigned len = cl.sock->read(rbuf, sizeof(rbuf)); cl.in_buf.append(rbuf, len); RefPtr response; @@ -97,55 +97,55 @@ void Server::client_data_available(Client &cl) { try { - cl.request=new Request(Request::parse(cl.in_buf)); + cl.request = new Request(Request::parse(cl.in_buf)); - string addr_str=cl.sock->get_peer_address().str(); - unsigned colon=addr_str.find(':'); + string addr_str = cl.sock->get_peer_address().str(); + unsigned colon = addr_str.find(':'); cl.request->set_header("-Client-Host", addr_str.substr(0, colon)); if(cl.request->get_method()!="GET" && cl.request->get_method()!="POST") { - response=new Response(NOT_IMPLEMENTED); + response = new Response(NOT_IMPLEMENTED); response->add_content("Method not implemented"); } } catch(const exception &e) { - response=new Response(BAD_REQUEST); + response = new Response(BAD_REQUEST); response->add_content(e.what()); } - cl.in_buf=string(); + cl.in_buf = string(); } } else { - len=cl.request->parse_content(cl.in_buf); + len = cl.request->parse_content(cl.in_buf); cl.in_buf.erase(0, len); } if(cl.request && cl.request->is_complete() && !response) { - response=new Response(NONE); + response = new Response(NONE); try { - cl.response=response.get(); + cl.response = response.get(); signal_request.emit(*cl.request, *response); if(cl.async) response.release(); else { - cl.response=0; + cl.response = 0; if(response->get_status()==NONE) { - response=new Response(NOT_FOUND); + response = new Response(NOT_FOUND); response->add_content("The requested resource was not found"); } } } catch(const exception &e) { - cl.response=0; - response=new Response(INTERNAL_ERROR); + cl.response = 0; + response = new Response(INTERNAL_ERROR); response->add_content(e.what()); } } @@ -154,13 +154,13 @@ void Server::client_data_available(Client &cl) { cl.sock->write(response->str()); cl.sock->close(); - cl.stale=true; + cl.stale = true; } } void Server::client_end_of_file(Client &cl) { - cl.stale=true; + cl.stale = true; } Server::Client &Server::get_client_by_response(Response &resp) diff --git a/source/status.h b/source/status.h index 0ea001d..c04262d 100644 --- a/source/status.h +++ b/source/status.h @@ -15,13 +15,13 @@ namespace Http { enum Status { - NONE=0, - OK=200, - BAD_REQUEST=400, - FORBIDDEN=403, - NOT_FOUND=404, - INTERNAL_ERROR=500, - NOT_IMPLEMENTED=501 + NONE = 0, + OK = 200, + BAD_REQUEST = 400, + FORBIDDEN = 403, + NOT_FOUND = 404, + INTERNAL_ERROR = 500, + NOT_IMPLEMENTED = 501 }; extern std::ostream &operator<<(std::ostream &, Status); diff --git a/source/utils.cpp b/source/utils.cpp index b6340db..5222f76 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -41,9 +41,9 @@ string urlencode(const string &str, EncodeLevel level) for(string::const_iterator i=str.begin(); i!=str.end(); ++i) { if(is_reserved(*i, level)) - result+=format("%%%02X", *i); + result += format("%%%02X", *i); else - result+=*i; + result += *i; } return result; } @@ -54,11 +54,11 @@ string urlencode_plus(const string &str, EncodeLevel level) for(string::const_iterator i=str.begin(); i!=str.end(); ++i) { if(*i==' ') - result+='+'; + result += '+'; else if(is_reserved(*i, level)) - result+=format("%%%02X", *i); + result += format("%%%02X", *i); else - result+=*i; + result += *i; } return result; } @@ -68,18 +68,18 @@ string urldecode(const string &str) string result; for(unsigned i=0; istr.size()) throw InvalidParameterValue("Malformed data"); - result+=lexical_cast(str.substr(i+1, 2), "x"); - i+=2; + result += lexical_cast(str.substr(i+1, 2), "x"); + i += 2; } else if(c=='+') - result+=' '; + result += ' '; else - result+=c; + result += c; } return result; } @@ -87,14 +87,14 @@ string urldecode(const string &str) Url parse_url(const string &str) { static Regex r_url("(([a-z]+)://)?([a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*(:[0-9])?)?(/[^?#]*)?(\\?([^#]+))?(#(.*))?"); - if(RegMatch m=r_url.match(str)) + if(RegMatch m = r_url.match(str)) { Url url; - url.scheme=m[2].str; - url.host=m[3].str; - url.path=urldecode(m[6].str); - url.query=m[8].str; - url.fragment=m[10].str; + url.scheme = m[2].str; + url.host = m[3].str; + url.path = urldecode(m[6].str); + url.query = m[8].str; + url.fragment = m[10].str; return url; } else @@ -107,32 +107,32 @@ string build_url(const Url &url) throw InvalidParameterValue("Only absolute paths are supported"); string str; if(!url.scheme.empty()) - str+=url.scheme+"://"; - str+=url.host; - str+=urlencode(url.path); + str += url.scheme+"://"; + str += url.host; + str += urlencode(url.path); if(!url.query.empty()) { - str+='?'; - str+=url.query; + str += '?'; + str += url.query; } if(!url.fragment.empty()) { - str+='#'; - str+=url.fragment; + str += '#'; + str += url.fragment; } return str; } Query parse_query(const std::string &str) { - vector parts=split(str, '&'); + vector parts = split(str, '&'); Query query; for(vector::const_iterator i=parts.begin(); i!=parts.end(); ++i) { - unsigned equals=i->find('='); - string &value=query[urldecode(i->substr(0, equals))]; + unsigned equals = i->find('='); + string &value = query[urldecode(i->substr(0, equals))]; if(equals!=string::npos) - value=urldecode(i->substr(equals+1)); + value = urldecode(i->substr(equals+1)); } return query; } @@ -143,10 +143,10 @@ string build_query(const Query &query) for(Query::const_iterator i=query.begin(); i!=query.end(); ++i) { if(i!=query.begin()) - str+='&'; - str+=urlencode_plus(i->first); - str+='='; - str+=urlencode_plus(i->second); + str += '&'; + str += urlencode_plus(i->first); + str += '='; + str += urlencode_plus(i->second); } return str; } diff --git a/source/version.cpp b/source/version.cpp index 2966fe8..76159ba 100644 --- a/source/version.cpp +++ b/source/version.cpp @@ -17,7 +17,7 @@ namespace Http { Version parse_version(const std::string &ver) { - if(RegMatch match=Regex("^HTTP/([0-9]+).([0-9]+)$").match(ver)) + if(RegMatch match = Regex("^HTTP/([0-9]+).([0-9]+)$").match(ver)) return lexical_cast(match[1].str)<<4 | lexical_cast(match[2].str); else throw InvalidParameterValue("Invalid HTTP version"); -- 2.45.2