Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 93 lines (80 sloc) 3.092 kb
45fd176 @ekarak - added static+dynamic lib target in Makefile
authored
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
25 #include "StompFrame.hpp"
26
27 namespace STOMP {
28
29 /*
30 * Escaping is needed to allow header keys and values to contain those frame header
31 * delimiting octets as values. The CONNECT and CONNECTED frames do not escape the
32 * colon or newline octets in order to remain backward compatible with STOMP 1.0.
33 * C style string literal escapes are used to encode any colons and newlines that
34 * are found within the UTF-8 encoded headers. When decoding frame headers, the
35 * following transformations MUST be applied:
36 *
37 * \n (octet 92 and 110) translates to newline (octet 10)
38 * \c (octet 92 and 99) translates to : (octet 58)
39 * \\ (octet 92 and 92) translates to \ (octet 92)
40 */
41 string* encode_header_token(const char* str) {
42 string* result = new string(str);
43 boost::algorithm::replace_all(*result, "\n", "\\n");
44 boost::algorithm::replace_all(*result, ":", "\\c");
45 boost::algorithm::replace_all(*result, "\\", "\\\\");
46 return(result);
47 };
48
49 string* decode_header_token(const char* str) {
50 string* result = new string(str);
51 boost::algorithm::replace_all(*result, "\\n", "\n");
52 boost::algorithm::replace_all(*result, "\\c", ":");
53 boost::algorithm::replace_all(*result, "\\\\", "\\");
54 return(result);
55 };
56
57 void Frame::encode()
58 // -------------------------------------
59 {
60 // prepare an output stream
61 ostream os(&request);
62 // step 1. write the command
63 if (m_command.length() > 0) {
64 os << m_command << "\n";
65 } else {
66 throw("stomp_write: command not set!!");
67 }
68 // step 2. Write the headers (key-value pairs)
69 if( m_headers.size() > 0 ) {
70 for ( hdrmap::iterator it = m_headers.begin() ; it != m_headers.end(); it++ ) {
71 os << *encode_header_token((*it).first.c_str())
72 << ":"
73 << *encode_header_token((*it).second.c_str())
74 << "\n";
75 }
76 }
77 // special header: content-length
78 if( m_body.length() > 0 ) {
79 os << "content-length:" << m_body.length() << "\n";
80 }
81 // write newline signifying end of headers
82 os << "\n";
83 // step 3. Write the body
84 if( m_body.length() > 0 ) {
85 os << m_body;
86 }
87 // write terminating NULL char
88 request.sputc('\0');
89 };
90
91
92 }
Something went wrong with that request. Please try again.