/src/resiprocate/resip/stack/DtmfPayloadContents.hxx
Line | Count | Source |
1 | | #if !defined(RESIP_DTMFPAYLOADCONTENTS_HXX) |
2 | | #define RESIP_DTMFPAYLOADCONTENTS_HXX |
3 | | |
4 | | #include "resip/stack/Contents.hxx" |
5 | | #include "rutil/Data.hxx" |
6 | | #include "rutil/HashMap.hxx" |
7 | | #include "rutil/ParseBuffer.hxx" |
8 | | |
9 | | namespace resip |
10 | | { |
11 | | |
12 | | /* Provides a way to handle the application/dtmf-relay |
13 | | content-type from SIP INFO messages. |
14 | | Attempts to adhere to the IETF draft |
15 | | draft-kaplan-dispatch-info-dtmf-package-00 |
16 | | */ |
17 | | |
18 | | class DtmfPayloadContents : public Contents |
19 | | { |
20 | | |
21 | | public: |
22 | | |
23 | | class DtmfPayload |
24 | | { |
25 | | public: |
26 | | DtmfPayload(char button, int duration); |
27 | | |
28 | 6.05k | DtmfPayload() : mButton(0), mDuration(0) {} |
29 | | DtmfPayload(const DtmfPayload& rhs); |
30 | | DtmfPayload& operator=(const DtmfPayload& rhs); |
31 | | |
32 | | void parse(ParseBuffer& pb); |
33 | | EncodeStream& encode(EncodeStream&) const; |
34 | | |
35 | | /** @brief obtain representation of the button as a character |
36 | | * |
37 | | * @return the ASCII symbol for the button pressed |
38 | | **/ |
39 | 0 | char getButton() const { return mButton; } |
40 | | |
41 | | /** @brief obtain representation of the button as event code |
42 | | * |
43 | | * RFC 4733 provides a list of integer event codes for DTMF |
44 | | * symbols. |
45 | | * |
46 | | * @return the event code corresponding to the button pressed |
47 | | **/ |
48 | | unsigned short getEventCode() const; |
49 | | |
50 | | /** @brief obtain duration in milliseconds |
51 | | * |
52 | | * @return the number of milliseconds the button was pressed |
53 | | **/ |
54 | 0 | int getDuration() const { return mDuration; } |
55 | | |
56 | | private: |
57 | | char mButton; // ASCII representation of the DTMF button |
58 | | int mDuration; // milliseconds |
59 | | |
60 | | static bool isValidButton(const char c); |
61 | | |
62 | | friend class DtmfPayloadContents; |
63 | | }; |
64 | | |
65 | | DtmfPayloadContents(); |
66 | | DtmfPayloadContents(const HeaderFieldValue& hfv, const Mime& contentTypes); |
67 | | virtual ~DtmfPayloadContents(); |
68 | | |
69 | | DtmfPayloadContents& operator=(const DtmfPayloadContents& rhs); |
70 | | |
71 | | /** @brief duplicate an DtmfPayloadContents object |
72 | | * |
73 | | * @return pointer to a new DtmfPayloadContents object |
74 | | **/ |
75 | | virtual Contents* clone() const; |
76 | | |
77 | | /** @brief get the parsed payload |
78 | | * |
79 | | * @return parsed payload object |
80 | | **/ |
81 | 0 | DtmfPayload& dtmfPayload() {checkParsed(); return mDtmfPayload;} |
82 | 0 | const DtmfPayload& dtmfPayload() const {checkParsed(); return mDtmfPayload;} |
83 | | virtual EncodeStream& encodeParsed(EncodeStream& str) const; |
84 | | virtual void parse(ParseBuffer& pb); |
85 | | static const Mime& getStaticType() ; |
86 | | |
87 | | static bool init(); |
88 | | |
89 | | private: |
90 | | DtmfPayloadContents(const Data& data, const Mime& contentTypes); |
91 | | DtmfPayload mDtmfPayload; |
92 | | }; |
93 | | |
94 | | static bool invokeDtmfPayloadContentsInit = DtmfPayloadContents::init(); |
95 | | |
96 | | } |
97 | | |
98 | | |
99 | | #endif |
100 | | |
101 | | /* ==================================================================== |
102 | | * |
103 | | * Copyright 2014 Daniel Pocock http://danielpocock.com All rights reserved. |
104 | | * |
105 | | * Redistribution and use in source and binary forms, with or without |
106 | | * modification, are permitted provided that the following conditions |
107 | | * are met: |
108 | | * |
109 | | * 1. Redistributions of source code must retain the above copyright |
110 | | * notice, this list of conditions and the following disclaimer. |
111 | | * |
112 | | * 2. Redistributions in binary form must reproduce the above copyright |
113 | | * notice, this list of conditions and the following disclaimer in |
114 | | * the documentation and/or other materials provided with the |
115 | | * distribution. |
116 | | * |
117 | | * 3. Neither the name of the author(s) nor the names of any contributors |
118 | | * may be used to endorse or promote products derived from this software |
119 | | * without specific prior written permission. |
120 | | * |
121 | | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS "AS IS" AND |
122 | | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
123 | | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
124 | | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE |
125 | | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
126 | | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
127 | | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
128 | | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
129 | | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
130 | | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
131 | | * SUCH DAMAGE. |
132 | | * |
133 | | * ==================================================================== |
134 | | * |
135 | | * |
136 | | */ |
137 | | |