bitz-server  2.0.0
lib/icap/util.h
1 /*
2  * C++ ICAP library
3  * Copyright (C) 2012 Uditha Atukorala
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19 
20 #ifndef ICAP_UTIL_H
21 #define ICAP_UTIL_H
22 
23 #include <sstream>
24 
25 #include <psocksxx/iosockstream.h>
26 #include "request.h"
27 #include "response.h"
28 
29 #ifndef ICAP_BUFFER_SIZE
30 #define ICAP_BUFFER_SIZE 1024
31 #endif
32 
33 
34 namespace icap {
35 
36  namespace util {
37 
38  struct chunk_t {
39  unsigned int size;
40  std::string extention;
41  std::string data;
42  };
43 
50  template <typename T> std::string itoa( T number ) {
51  std::ostringstream ss;
52  ss << number;
53 
54  return ss.str();
55  }
56 
63  unsigned int hextodec( const std::string &hex ) throw();
64 
71  const std::string dectohex( const unsigned int &dec ) throw();
72 
83  int read_line( psocksxx::iosockstream * socket, char * buf, int buf_length, bool incl_endl = false ) throw();
84 
93  std::string read_line( psocksxx::iosockstream * socket, bool incl_endl = false ) throw();
94 
102  std::string read_data( psocksxx::iosockstream * socket, int size ) throw();
103 
110  unsigned int read_chunk_size( psocksxx::iosockstream * socket ) throw();
111 
118  void read_chunk_header( psocksxx::iosockstream * socket, chunk_t &chunk ) throw();
119 
126  chunk_t read_chunk( psocksxx::iosockstream * socket ) throw();
127 
134  std::string read_chunked( psocksxx::iosockstream * socket ) throw();
135 
143  bool read_chunked_payload( psocksxx::iosockstream * socket, std::string &payload ) throw();
144 
152  bool send_line( const std::string &line, psocksxx::iosockstream * socket ) throw();
153 
163  bool send_data( const std::string &data, psocksxx::iosockstream * socket ) throw();
164 
172  bool send_chunked( const std::string &data, psocksxx::iosockstream * socket ) throw();
173 
180  std::vector<std::string> split( const std::string &str, const std::string &delimiter = " " ) throw();
181 
188  std::string &ltrim( std::string &str ) throw();
189 
196  std::string &rtrim( std::string &str ) throw();
197 
204  std::string &trim( std::string &str ) throw();
205 
212  icap::RequestHeader * read_req_header( psocksxx::iosockstream * socket ) throw();
213 
222  bool read_req_data( icap::Request * request, psocksxx::iosockstream * socket ) throw();
223 
232  bool read_req_continue_data( icap::Request * request, psocksxx::iosockstream * socket ) throw();
233 
241  bool send_headers( icap::Header::headers_t headers, psocksxx::iosockstream * socket ) throw();
242 
251  bool send_response( icap::Response * response, psocksxx::iosockstream * socket ) throw();
252 
258  const std::string response_status( const ResponseHeader::status_t &status ) throw();
259 
260  } /* end of namespace util */
261 
262 } /* end of namespace icap */
263 
264 #endif /* !ICAP_UTIL_H */
265 
Definition: response.h:29
Definition: lib/icap/util.h:38
Definition: request_header.h:31
Definition: lib/icap/common.h:26
Definition: request.h:29