summaryrefslogtreecommitdiffstats
path: root/bindings/winrt/doubango_rt/src/rt_Msrp.cxx
blob: 6699495ce5937ce0650cbfede7d44def3077130b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*Copyright (C) 2013 Doubango Telecom <http://www.doubango.org>
*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*/
#include "rt_Msrp.h"
#include "rt_String.h"
#include "rt_SipSession.h"

#include "SipSession.h"
#include "Msrp.h"

#include <assert.h>

using namespace doubango_rt::BackEnd;
using namespace Platform;
using namespace std;


//
//	rtMsrpMessage
//

rtMsrpMessage::rtMsrpMessage(struct tmsrp_message_s *message)
{
    m_pMsrpMessage= new MsrpMessage(message);
}

rtMsrpMessage::~rtMsrpMessage()
{
    rtSafeDelete(m_pMsrpMessage);
}

bool rtMsrpMessage::isRequest()
{
    return m_pMsrpMessage->isRequest();
}

short rtMsrpMessage::getCode()
{
    return m_pMsrpMessage->getCode();
}

String^ rtMsrpMessage::getPhrase()
{
    return rtString::toString(m_pMsrpMessage->getPhrase());
}

rt_tmsrp_request_type_t rtMsrpMessage::getRequestType()
{
    return (rt_tmsrp_request_type_t)m_pMsrpMessage->getRequestType();
}

#if COM_VISIBLE
rtMsrpByteRange^ rtMsrpMessage::getByteRange()
{
    int64_t _start = -1, _end = -1, _total = -1;
    m_pMsrpMessage->getByteRange(&_start, &_end, &_total);
    return ref new rtMsrpByteRange(_start, _end, _total);
}
#else
void rtMsrpMessage::getByteRange(IntPtr start, IntPtr end, IntPtr total)
{
    int64_t _start = -1, _end = -1, _total = -1;
    m_pMsrpMessage->getByteRange(&_start, &_end, &_total);
    // IntPtr is 32bit or 64bit -> 32 to be sure not memory errors will raise
    *((int32_t*)(void*)start) = (int32_t)_start;
    *((int32_t*)(void*)end) = (int32_t)_end;
    *((int32_t*)(void*)total) = (int32_t)_total;
}
#endif /* COM_VISIBLE */

bool rtMsrpMessage::isLastChunck()
{
    return m_pMsrpMessage->isLastChunck();
}

bool rtMsrpMessage::isFirstChunck()
{
    return m_pMsrpMessage->isFirstChunck();
}

bool rtMsrpMessage::isSuccessReport()
{
    return m_pMsrpMessage->isSuccessReport();
}

String^ rtMsrpMessage::getMsrpHeaderValue(String^ name)
{
    return rtString::toString(m_pMsrpMessage->getMsrpHeaderValue(rtString::toUtf8(name).data()));
}

String^ rtMsrpMessage::getMsrpHeaderParamValue(String^ name, String^ param)
{
    return rtString::toString(m_pMsrpMessage->getMsrpHeaderParamValue(rtString::toUtf8(name).data(), rtString::toUtf8(param).data()));
}

unsigned rtMsrpMessage::getMsrpContentLength()
{
    return m_pMsrpMessage->getMsrpContentLength();
}

#if COM_VISIBLE
String^ rtMsrpMessage::getMsrpContent(unsigned maxsize)
{
    if(maxsize) {
        void* _s = calloc(maxsize + 1, 1);
        if(_s) {
            unsigned len = m_pMsrpMessage->getMsrpContent(_s, maxsize);
            String^ s = rtString::toString((const char*)_s);
            free(_s);
            return s;
        }
    }
    return nullptr;
}
#else
unsigned rtMsrpMessage::getMsrpContent(IntPtr output, unsigned maxsize)
{
    return m_pMsrpMessage->getMsrpContent((void*)output, maxsize);
}
#endif /* COM_VISIBLE */


//
//	rtMsrpEvent
//

rtMsrpEvent::rtMsrpEvent(const struct tmsrp_event_s *event)
{
    m_pMsrpEvent = new MsrpEvent(event);
}

rtMsrpEvent::~rtMsrpEvent()
{
    rtSafeDelete(m_pMsrpEvent);
}

rt_tmsrp_event_type_t rtMsrpEvent::getType()
{
    return (rt_tmsrp_event_type_t)m_pMsrpEvent->getType();
}

rtMsrpSession^ rtMsrpEvent::getSipSession()
{
    if(m_pMsrpEvent->getSipSession()) {
        assert(0); // FIXME: Not implemented
        return nullptr;
        // return ref new rtMsrpSession(m_pMsrpEvent->getSipSession()->getWrappedSession());
    }
    return nullptr;
}

rtMsrpMessage^ rtMsrpEvent::getMessage()
{
    if(m_pMsrpEvent->getMessage()) {
        return ref new rtMsrpMessage(const_cast<struct tmsrp_message_s *>(const_cast<MsrpMessage*>(m_pMsrpEvent->getMessage())->getWrappedMsrpMessage()));
    }
    return nullptr;
}

//
//	rtMsrpCallback
//

rtMsrpCallback::rtMsrpCallback(rtIMsrpCallback^ pI)
{
    m_pI = pI;
    m_pCallback = new MsrpCallback();
}

rtMsrpCallback::~rtMsrpCallback()
{
    rtSafeDelete(m_pCallback);
}


OpenPOWER on IntegriCloud