]> git.tdb.fi Git - libs/net.git/commitdiff
Style update: spaces around assignments
authorMikko Rasa <tdb@tdb.fi>
Sat, 6 Aug 2011 20:53:52 +0000 (23:53 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 7 Aug 2011 08:46:28 +0000 (11:46 +0300)
source/client.cpp
source/message.cpp
source/message.h
source/request.cpp
source/response.cpp
source/server.cpp
source/status.h
source/utils.cpp
source/version.cpp

index be579184fa98e62a71d7ea3d09d5c247907fa16f..cb7b0eabc48302047cdfa5754bb4a40d78c877b3 100644 (file)
@@ -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<Net::SockAddr> addr=Net::resolve(host);
+               host += ":80";
+       RefPtr<Net::SockAddr> 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;
        }
 }
 
index 4aaa8bfd26d1fab34302cd6f32e0c583bac133fe..2223377cb6bea79e5379cce50a3b0164c7d3aafe 100644 (file)
@@ -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<unsigned>(i->second)-content.size();
-               unsigned len=min(needed, d.size());
+               unsigned needed = lexical_cast<unsigned>(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<d.size())
                {
                        if(chunk_length==0)
                        {
-                               unsigned lf=d.find('\n', pos);
+                               unsigned lf = d.find('\n', pos);
                                if(lf==string::npos)
                                        return pos;
-                               chunk_length=lexical_cast<unsigned>(strip(d.substr(pos, lf-pos)), "x");
+                               chunk_length = lexical_cast<unsigned>(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;
 }
index 6e139bd283c7ec9b5d942b087c1e33a3a14fe342..b1809a610f857fc2c58da542d9f91315a4216fb3 100644 (file)
@@ -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;
index 6bad3700681fefdffd40178a88e44cb146442e0b..ba47c4dcb4295a07b6d8b05cfc8f7d2a56e3a753 100644 (file)
@@ -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<string> parts=split(str.substr(0, lf-(str[lf-1]=='\r')), ' ', 2);
+       unsigned lf = str.find('\n');
+       vector<string> 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);
index 4da67422fa221735ea234f64d7430e0d2e857d88..fe7469d0780d32372f392d80bacf5fbe65be434c 100644 (file)
@@ -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<int>(status), status);
-       result+=str_common();
+       string result = format("%s %d %s\r\n", version_str(http_version), static_cast<int>(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<string> parts=split(str.substr(0, lf), ' ', 2);
+       unsigned lf = str.find('\n');
+       vector<string> 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<Status>(lexical_cast<unsigned>(parts[1]));
+       result.http_version = parse_version(parts[0]);
+       result.status = static_cast<Status>(lexical_cast<unsigned>(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));
 
index 2e427b974af5ce7a3da4231f596c314235c94463..e0aedf28c1b16d0cb6c451c33a8b7bd5d290ce23 100644 (file)
@@ -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<const Net::InetAddr &>(addr).get_port();
        return 0;
@@ -42,7 +42,7 @@ void Server::use_event_dispatcher(IO::EventDispatcher *ed)
                for(list<Client>::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> 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)
index 0ea001d43e3487fe0324b475586c442592848e5c..c04262d600d794e1be113a536679627f73cf8088 100644 (file)
@@ -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);
index b6340db7dfd2da87a9abc6c9cbb8baabb6fba999..5222f76024438deda488a6ec847b677244d14d0a 100644 (file)
@@ -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; i<str.size(); ++i)
        {
-               char c=str[i];
+               char c = str[i];
                if(c=='%')
                {
                        if(i+3>str.size())
                                throw InvalidParameterValue("Malformed data");
-                       result+=lexical_cast<unsigned char>(str.substr(i+1, 2), "x");
-                       i+=2;
+                       result += lexical_cast<unsigned char>(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<string> parts=split(str, '&');
+       vector<string> parts = split(str, '&');
        Query query;
        for(vector<string>::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;
 }
index 2966fe8495ab04d6dbb0a03e6a859c2a27a5886d..76159bae8cde30d01473036671fe596dcfd909f9 100644 (file)
@@ -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<unsigned>(match[1].str)<<4 | lexical_cast<unsigned>(match[2].str);
        else
                throw InvalidParameterValue("Invalid HTTP version");