/[resiprocate]/main/sip/resiprocate/dum/Dialog.cxx
ViewVC logotype

Contents of /main/sip/resiprocate/dum/Dialog.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2556 - (show annotations) (download)
Sun Apr 4 20:37:18 2004 UTC (15 years, 9 months ago) by ken
File size: 5208 byte(s)
-Moving closer to a compile...

1 #include "resiprocate/Contents.hxx"
2 //#include "resiprocate/OctetContents.hxx"
3 //#include "resiprocate/HeaderFieldValueList.hxx"
4 #include "resiprocate/sam/Dialog.hxx"
5 #include "resiprocate/sam/ClientInviteSession.hxx"
6
7 using namespace resip;
8 using namespace std;
9
10 class ServerInviteSession;
11
12 DialogId Dialog::getId() const
13 {
14 return mId;
15 }
16
17 BaseUsage&
18 Dialog::findInvSession()
19 {
20 std::list<BaseUsage*>::iterator it = mUsages.begin();
21 BaseUsage *usage;
22 while (it != mUsages.end())
23 {
24 usage = it->next();
25 if ((dynamic_cast<ClientInviteSession*>(usage) != NULL) ||
26 (dynamic_cast<ServerInviteSession*>(usage) != NULL))
27 {
28 return *usage;
29 }
30 }
31 return BaseUsage::empty();
32 }
33
34 UsageSet
35 Dialog::findSubscriptions()
36 {
37 std::list<BaseUsage*>::iterator it = mUsages.begin();
38 BaseUsage *usage;
39 UsageSet usageSet;
40 while (it != mUsages.end())
41 {
42 usage = it.next();
43 if ((dynamic_cast<ClientSubscription*>(usage) != null) ||
44 (dynamic_cast<ServerSubscription*>(usage) != null))
45 {
46 usageSet.push_back(*usage);
47 }
48 }
49 return usageSet:
50 }
51
52 BaseUsage&
53 Dialog::findRegistration()
54 {
55 std::list<BaseUsage*>::iterator it = mUsages.begin();
56 BaseUsage *usage;
57 while (it != mUsages.end())
58 {
59 usage = it.next();
60 if ((dynamic_cast<CientRegistration*>(usage) != null) ||
61 (dynamic_cast<ServerRegistration*>(usage) != null))
62 {
63 return *usage;
64 }
65 }
66 return BaseUsage::empty();
67 }
68
69
70 BaseUsage&
71 Dialog::findPublication()
72 {
73 std::list<BaseUsage*>::iterator it = mUsages.begin();
74 BaseUsage *usage;
75 while (it != mUsages.end())
76 {
77 usage = it.next();
78 if ((dynamic_cast<CientPublication*>(usage) != null) ||
79 (dynamic_cast<ServerPublication*>(usage) != null))
80 {
81 return *usage;
82 }
83 }
84 return BaseUsage::empty();
85 }
86
87 UsageSet
88 Dialog::findOutOfDialogs()
89 {
90 std::list<BaseUsage*>::iterator it = mUsages.begin();
91 BaseUsage *usage;
92 UsageSet usageSet;
93 while (it != mUsages.end())
94 {
95 usage = it.next();
96 if ((dynamic_cast<ClientOutOfDialogReq*>(usage) != null) ||
97 (dynamic_cast<ServerOutOfDialogReq*>(usage) != null))
98 {
99 usageSet.push_back(*usage);
100 }
101 }
102 return usageSet:
103 }
104
105 void
106 Dialog::process(const SipMessage& msg)
107 {
108 switch (request.header(h_RequestLine).getMethod())
109 {
110 // a NOTIFY is the only request that can
111 // create a full dialog (when the 2xx from the
112 // SUBSCRIBE arrives *after* the NOTIFY
113 case NOTIFY :
114 processNotify(msg);
115 break;
116
117 case REFER:
118 // !jf! wierdo
119 // affects an InvSession and a ServerSubscription
120 break;
121
122 case SUBSCRIBE:
123 processSubscribe(msg);
124 break;
125
126 case CANCEL:
127 // should only occur when canceling a re-INVITE
128 case INVITE:
129 // should only occur for a re-INVITE
130 case ACK:
131 case PRACK:
132 case BYE:
133 case UPDATE:
134 case INFO:
135 processInviteRelated(msg);
136 break;
137
138 case REGISTER:
139 {
140 assert(0); // already handled
141 break;
142 }
143
144 case PUBLISH:
145 assert(0);
146 break;
147
148 case MESSAGE:
149 case OPTIONS:
150 assert(0);
151 break;
152
153 default:
154 assert(0);
155 break;
156 }
157 }
158
159 void
160 Dialog::processNotify(const SipMessage& notify)
161 {
162 if (notify.isRequest())
163 {
164 if (findSubscriptions().empty())
165 {
166 SubscriptionCreator* creator = dynamic_cast<SubscriptionCreator*>(DialogSetId(notify).getCreator());
167 if (creator)
168 {
169 creator->makeNewSubscription(notify);
170 }
171 }
172 else
173 {
174 for (std::list<BaseUsage*>::iterator i=mUsages.begin(); i!=mUsages.end(); i++)
175 {
176 ClientSubscription* sub = dynamic_cast<ClientSubscription*>(*i);
177 if (sub && sub->matches(notify))
178 {
179 sub->process(notify);
180 break;
181 }
182 }
183 }
184 }
185 }
186
187 void
188 Dialog::processSubscribe(const SipMessage& subscribe)
189 {
190 for (std::list<BaseUsage*>::iterator i=mUsages.begin(); i!=mUsages.end(); i++)
191 {
192 ServerSubscription* sub = dynamic_cast<ServerSubscription*>(*i);
193 if (sub && sub->matches(subscribe))
194 {
195 sub->process(subscribe); // a resubscribe or unsubscribe
196 return;
197 }
198 }
199
200 // a subscribe on an existing dialog with a different BaseUsage
201 ServerSubscription* sub = new ServerSubscription(mDum, subscribe);
202 }
203
204 void
205 Dialog::processInviteRelated(const SipMessage& msg)
206 {
207 for (std::list<BaseUsage*>::iterator i=mUsages.begin(); i!=mUsages.end(); i++)
208 {
209 ServerInvSession* server = dynamic_cast<ServerInvSession*>(*i);
210 ClientInvSession* client = dynamic_cast<ClientInvSession*>(*i);
211 if (server)
212 {
213 server->process(msg);
214 break;
215 }
216 else if (client)
217 {
218 client->process(msg);
219 break;
220 }
221 }
222 }

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27