Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 99 lines (86 sloc) 3.224 kb
45fd1769 »
2012-04-16 - added static+dynamic lib target in Makefile
1 /*
2 BoostStomp - a STOMP (Simple Text Oriented Messaging Protocol) client
3 ----------------------------------------------------
4 Copyright (c) 2012 Elias Karakoulakis <elias.karakoulakis@gmail.com>
5
6 SOFTWARE NOTICE AND LICENSE
7
8 BoostStomp is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published
10 by the Free Software Foundation, either version 3 of the License,
11 or (at your option) any later version.
12
13 BoostStomp is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with BoostStomp. If not, see <http://www.gnu.org/licenses/>.
20
21 for more information on the LGPL, see:
22 http://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License
23 */
24
c4739929 »
2012-04-23 - initial support for reconnection
25 #include <boost/format.hpp>
0389cbd9 »
2012-04-25 removed boost::xpressive along with some ~5mb of needless binary blur…
26 #include <boost/lexical_cast.hpp>
f05a6360 »
2012-05-02 valgrind memcheck: first round of bug-killing
27
0389cbd9 »
2012-04-25 removed boost::xpressive along with some ~5mb of needless binary blur…
28 #include "BoostStomp.hpp"
29 #include "helpers.h"
c4739929 »
2012-04-23 - initial support for reconnection
30
45fd1769 »
2012-04-16 - added static+dynamic lib target in Makefile
31 namespace STOMP {
c4739929 »
2012-04-23 - initial support for reconnection
32
33 using namespace boost;
0389cbd9 »
2012-04-25 removed boost::xpressive along with some ~5mb of needless binary blur…
34 using namespace boost::assign;
c4739929 »
2012-04-23 - initial support for reconnection
35
45fd1769 »
2012-04-16 - added static+dynamic lib target in Makefile
36 /*
37 * Escaping is needed to allow header keys and values to contain those frame header
38 * delimiting octets as values. The CONNECT and CONNECTED frames do not escape the
39 * colon or newline octets in order to remain backward compatible with STOMP 1.0.
40 * C style string literal escapes are used to encode any colons and newlines that
41 * are found within the UTF-8 encoded headers. When decoding frame headers, the
42 * following transformations MUST be applied:
43 *
44 * \n (octet 92 and 110) translates to newline (octet 10)
45 * \c (octet 92 and 99) translates to : (octet 58)
46 * \\ (octet 92 and 92) translates to \ (octet 92)
47 */
f05a6360 »
2012-05-02 valgrind memcheck: first round of bug-killing
48 string& encode_header_token(string& str) {
49 boost::algorithm::replace_all(str, "\n", "\\n");
50 boost::algorithm::replace_all(str, ":", "\\c");
51 boost::algorithm::replace_all(str, "\\", "\\\\");
52 return(str);
45fd1769 »
2012-04-16 - added static+dynamic lib target in Makefile
53 };
54
f05a6360 »
2012-05-02 valgrind memcheck: first round of bug-killing
55 string& decode_header_token(string& str) {
56 boost::algorithm::replace_all(str, "\\n", "\n");
57 boost::algorithm::replace_all(str, "\\c", ":");
58 boost::algorithm::replace_all(str, "\\\\", "\\");
59 return(str);
45fd1769 »
2012-04-16 - added static+dynamic lib target in Makefile
60 };
61
f05a6360 »
2012-05-02 valgrind memcheck: first round of bug-killing
62 boost::asio::streambuf& Frame::encode()
45fd1769 »
2012-04-16 - added static+dynamic lib target in Makefile
63 // -------------------------------------
64 {
65 // prepare an output stream
f05a6360 »
2012-05-02 valgrind memcheck: first round of bug-killing
66 ostream os(&m_request);
45fd1769 »
2012-04-16 - added static+dynamic lib target in Makefile
67 // step 1. write the command
68 if (m_command.length() > 0) {
69 os << m_command << "\n";
70 } else {
71 throw("stomp_write: command not set!!");
72 }
73 // step 2. Write the headers (key-value pairs)
74 if( m_headers.size() > 0 ) {
75 for ( hdrmap::iterator it = m_headers.begin() ; it != m_headers.end(); it++ ) {
f05a6360 »
2012-05-02 valgrind memcheck: first round of bug-killing
76 string key = (*it).first;
77 string val = (*it).second;
78 os << encode_header_token(key)
45fd1769 »
2012-04-16 - added static+dynamic lib target in Makefile
79 << ":"
f05a6360 »
2012-05-02 valgrind memcheck: first round of bug-killing
80 << encode_header_token(val)
45fd1769 »
2012-04-16 - added static+dynamic lib target in Makefile
81 << "\n";
82 }
83 }
84 // special header: content-length
965308b2 »
2012-04-25 yay! binary bodies in frames!
85 if( m_body.v.size() > 0 ) {
86 os << "content-length:" << m_body.v.size() << "\n";
45fd1769 »
2012-04-16 - added static+dynamic lib target in Makefile
87 }
88 // write newline signifying end of headers
89 os << "\n";
90 // step 3. Write the body
965308b2 »
2012-04-25 yay! binary bodies in frames!
91 if( m_body.v.size() > 0 ) {
f05a6360 »
2012-05-02 valgrind memcheck: first round of bug-killing
92 m_request.sputn(m_body.v.data(), m_body.v.size());
45fd1769 »
2012-04-16 - added static+dynamic lib target in Makefile
93 }
94 // write terminating NULL char
f05a6360 »
2012-05-02 valgrind memcheck: first round of bug-killing
95 m_request.sputc('\0');
96 return(m_request);
45fd1769 »
2012-04-16 - added static+dynamic lib target in Makefile
97 };
98
99 }
Something went wrong with that request. Please try again.