/[resiprocate]/main/resip/dum/test/RegEventClient.cxx
ViewVC logotype

Contents of /main/resip/dum/test/RegEventClient.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9493 - (show annotations) (download)
Sat Apr 7 10:56:50 2012 UTC (7 years, 7 months ago) by dpocock
File MIME type: text/plain
File size: 4367 byte(s)
Include config.h from even more places where it may be needed
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #include "rutil/Logger.hxx"
6 #include "resip/stack/SipMessage.hxx"
7 #include "resip/stack/OctetContents.hxx"
8 #include "resip/dum/MasterProfile.hxx"
9 #include "resip/dum/ClientAuthManager.hxx"
10 #include "resip/dum/ClientSubscription.hxx"
11
12 #ifdef USE_SSL
13 #include "resip/stack/ssl/Security.hxx"
14 #endif
15
16 #include "RegEventClient.hxx"
17
18 using namespace resip;
19
20 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
21
22 static Token regEvent("reg");
23
24 AddAor::AddAor(RegEventClient& client, const resip::Uri& aor) :
25 mClient(client),
26 mAor(aor)
27 {
28 }
29
30 void
31 AddAor::executeCommand()
32 {
33 //InfoLog (<< "Execute: " << *this);
34 SharedPtr<SipMessage> sub = mClient.mDum.makeSubscription(resip::NameAddr(mAor), regEvent.value());
35 mClient.mDum.send(sub);
36 }
37
38 resip::Message*
39 AddAor::clone() const
40 {
41 return new AddAor(mClient, mAor);
42 }
43
44 #ifdef RESIP_USE_STL_STREAMS
45 std::ostream&
46 AddAor::encode(std::ostream& strm) const
47 #else
48 resip::ResipFastOStream&
49 AddAor::encode(resip::ResipFastOStream& strm) const
50 #endif
51 {
52 strm << "Add RegEvent watcher " << mAor;
53 return strm;
54 }
55
56 #ifdef RESIP_USE_STL_STREAMS
57 std::ostream&
58 AddAor::encodeBrief(std::ostream& strm) const
59 #else
60 resip::ResipFastOStream&
61 AddAor::encodeBrief(resip::ResipFastOStream& strm) const
62 #endif
63 {
64 return encode(strm);
65 }
66
67
68 RegEventClient::RegEventClient(SharedPtr<MasterProfile> profile) :
69 mSecurity(0),
70 mStack(mSecurity),
71 mStackThread(mStack),
72 mDum(mStack),
73 mDumThread(mDum),
74 mProfile(profile)
75 {
76 mDum.addTransport(UDP, 5060);
77 mDum.addTransport(TCP, 5060);
78
79 mProfile->addSupportedMethod(NOTIFY);
80 mProfile->addAllowedEvent(regEvent);
81 mProfile->validateAcceptEnabled() = false;
82 mProfile->validateContentEnabled() = false;
83 mProfile->setUserAgent("RFC3680-testUA");
84 mDum.setMasterProfile(mProfile);
85
86 std::auto_ptr<resip::ClientAuthManager> clam(new resip::ClientAuthManager());
87 mDum.setClientAuthManager(clam);
88 mDum.setClientRegistrationHandler(this);
89
90 mDum.addClientSubscriptionHandler(regEvent.value(), this);
91 }
92
93 RegEventClient::~RegEventClient()
94 {
95 #ifdef USE_SSL
96 delete mSecurity;
97 mSecurity = 0;
98 #endif
99 }
100
101 void
102 RegEventClient::run()
103 {
104 mStackThread.run();
105 mDumThread.run();
106 }
107
108 void
109 RegEventClient::watchAor(const resip::Uri& aor)
110 {
111 AddAor* add = new AddAor(*this, aor);
112 mDum.post(add);
113 }
114
115 const OctetContents*
116 toGenericContents(const SipMessage& notify)
117 {
118 assert(notify.getContents());
119
120 const OctetContents* generic = dynamic_cast<const OctetContents*>(notify.getContents());
121 assert(generic);
122
123 if (generic &&
124 generic->getType().type() == "application" &&
125 generic->getType().subType() == "reginfo+xml")
126 {
127 #if 0
128 TiXmlDocument doc;
129 doc.parse(generic->text().c_str());
130 if (doc.Error())
131 {
132 WarningLog (<< "Error parsing doc: " << doc.Value() << " " << doc.ErrorDesc());
133 onRegEventError(generic->text());
134 }
135 else
136 {
137
138 }
139 #endif
140
141 return generic;
142 }
143 else
144 {
145 return 0;
146 }
147 }
148
149 // Client must call acceptUpdate or rejectUpdate for any onUpdateFoo
150
151 void
152 RegEventClient::onNewSubscription(ClientSubscriptionHandle h, const SipMessage& notify)
153 {
154 InfoLog (<< "Got subscription " << notify.brief());
155 }
156
157 void
158 RegEventClient::onUpdatePending(ClientSubscriptionHandle h, const SipMessage& notify, bool outOfOrder)
159 {
160 h->acceptUpdate();
161 const OctetContents* generic = toGenericContents(notify);
162 if (generic)
163 {
164 onRegEvent(h->getDocumentKey(), generic->octets());
165 }
166 }
167
168 void
169 RegEventClient::onUpdateActive(ClientSubscriptionHandle h, const SipMessage& notify, bool outOfOrder)
170 {
171 h->acceptUpdate();
172 const OctetContents* generic = toGenericContents(notify);
173 if (generic)
174 {
175 onRegEvent(h->getDocumentKey(), generic->octets());
176 }
177 }
178
179 void
180 RegEventClient::onUpdateExtension(ClientSubscriptionHandle h, const SipMessage& notify, bool outOfOrder)
181 {
182 h->acceptUpdate();
183 }
184
185 int
186 RegEventClient::onRequestRetry(ClientSubscriptionHandle, int retrySeconds, const SipMessage& notify)
187 {
188 return -1;
189 }
190
191 void
192 RegEventClient::onTerminated(ClientSubscriptionHandle, const SipMessage* msg)
193 {
194 WarningLog (<< "Subscription terminated " << (msg ? "with message " : " with no message"));
195 if(msg)
196 {
197 WarningLog(<< msg->brief());
198 }
199 }
200
201

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27