Browse code

fix authentication on outgoing calls

uac auth now resets the dialog status back to what it was before
the failed request, if a request is retried with authentication.

Stefan Sayer authored on 15/07/2010 22:16:47
Showing 11 changed files
... ...
@@ -179,6 +179,11 @@ void WebConferenceDialog::onSipReply(const AmSipReply& reply, int old_dlg_status
179 179
 
180 180
   AmSession::onSipReply(reply,old_dlg_status);
181 181
 
182
+  DBG("reply: %u %s, old_dlg_status = %s, status = %s\n",
183
+      reply.code, reply.reason.c_str(),
184
+      AmSipDialog::status2str[old_dlg_status],
185
+      AmSipDialog::status2str[dlg.getStatus()]);
186
+
182 187
   if ((old_dlg_status < AmSipDialog::Connected) && 
183 188
       (dlg.getStatus() == AmSipDialog::Disconnected)) {
184 189
     DBG("Call failed.\n");
... ...
@@ -236,7 +236,7 @@ void AmB2BSession::onSipReply(const AmSipReply& reply, int old_dlg_status)
236 236
       if (is_offer) {	
237 237
 	// onSipReply from AmSession without do_200_ack in dlg.updateStatus(reply)
238 238
 	// todo (?): add do_200_ack flag to AmSession::onSipReply and call AmSession::onSipReply
239
-	CALL_EVENT_H(onSipReply,reply);
239
+	CALL_EVENT_H(onSipReply,reply,old_dlg_status);
240 240
 	
241 241
 	//int status = dlg.getStatus();
242 242
 	//dlg.updateStatus(reply, false);
... ...
@@ -713,7 +713,7 @@ void AmSession::onSipRequest(const AmSipRequest& req)
713 713
 
714 714
 void AmSession::onSipReply(const AmSipReply& reply, int old_dlg_status)
715 715
 {
716
-  CALL_EVENT_H(onSipReply,reply);
716
+  CALL_EVENT_H(onSipReply,reply,old_dlg_status);
717 717
 
718 718
   if (old_dlg_status != dlg.getStatus())
719 719
     DBG("Dialog status changed %s -> %s (stopped=%s) \n", 
... ...
@@ -43,7 +43,7 @@ bool AmSessionEventHandler::onSipRequest(const AmSipRequest&)
43 43
   return false;
44 44
 }
45 45
 
46
-bool AmSessionEventHandler::onSipReply(const AmSipReply& reply)
46
+bool AmSessionEventHandler::onSipReply(const AmSipReply& reply, int old_dlg_status)
47 47
 {
48 48
   return false;
49 49
 }
... ...
@@ -66,7 +66,7 @@ public:
66 66
   virtual bool process(AmEvent*);
67 67
 
68 68
   virtual bool onSipRequest(const AmSipRequest&);
69
-  virtual bool onSipReply(const AmSipReply&);
69
+  virtual bool onSipReply(const AmSipReply&, int old_dlg_status);
70 70
 
71 71
   virtual bool onSendRequest(const string& method, 
72 72
 			     const string& content_type,
... ...
@@ -69,6 +69,13 @@ AmSipDialog::~AmSipDialog()
69 69
   }
70 70
 }
71 71
 
72
+void AmSipDialog::setStatus(int new_status) {
73
+  DBG("setting  SIP dialog status: %s->%s\n",
74
+      status2str[status], status2str[new_status]);
75
+
76
+  status = new_status;
77
+}
78
+
72 79
 void AmSipDialog::updateStatus(const AmSipRequest& req)
73 80
 {
74 81
   DBG("AmSipDialog::updateStatus(request)\n");
... ...
@@ -161,6 +161,8 @@ class AmSipDialog
161 161
 
162 162
   bool   getUACTransPending() { return !uac_trans.empty(); }
163 163
   int    getStatus() { return status; }
164
+  void   setStatus(int new_status);
165
+
164 166
   string getContactHdr();
165 167
 
166 168
   /** update Status from locally originated request (e.g. INVITE) */
... ...
@@ -77,7 +77,7 @@ bool SessionTimer::onSipRequest(const AmSipRequest& req)
77 77
   return false;
78 78
 }
79 79
 
80
-bool SessionTimer::onSipReply(const AmSipReply& reply)
80
+bool SessionTimer::onSipReply(const AmSipReply& reply, int old_dlg_status)
81 81
 {
82 82
   updateTimer(s,reply);
83 83
   return false;
... ...
@@ -139,7 +139,7 @@ class SessionTimer: public AmSessionEventHandler
139 139
   virtual bool process(AmEvent*);
140 140
 
141 141
   virtual bool onSipRequest(const AmSipRequest&);
142
-  virtual bool onSipReply(const AmSipReply&);
142
+  virtual bool onSipReply(const AmSipReply&, int old_dlg_status);
143 143
 
144 144
   virtual bool onSendRequest(const string& method, 
145 145
 			     const string& content_type,
... ...
@@ -118,7 +118,7 @@ bool UACAuth::onSipRequest(const AmSipRequest& req)
118 118
   return false;
119 119
 }
120 120
 
121
-bool UACAuth::onSipReply(const AmSipReply& reply)
121
+bool UACAuth::onSipReply(const AmSipReply& reply, int old_dlg_status)
122 122
 {
123 123
   bool processed = false;
124 124
   if (reply.code==407 || reply.code==401) {
... ...
@@ -167,6 +167,9 @@ bool UACAuth::onSipReply(const AmSipReply& reply)
167 167
 				 ri->second.body, 
168 168
 				 hdrs) == 0) 			
169 169
 	      processed = true;
170
+	    // undo SIP dialog status change
171
+	    if (dlg->getStatus() != old_dlg_status)
172
+	      dlg->setStatus(old_dlg_status);
170 173
 	  }
171 174
 	} 
172 175
       }
... ...
@@ -138,7 +138,7 @@ class UACAuth : public AmSessionEventHandler
138 138
   virtual bool process(AmEvent*);
139 139
   virtual bool onSipEvent(AmSipEvent*);
140 140
   virtual bool onSipRequest(const AmSipRequest&);
141
-  virtual bool onSipReply(const AmSipReply&);
141
+  virtual bool onSipReply(const AmSipReply&, int old_dlg_status);
142 142
 	
143 143
   virtual bool onSendRequest(const string& method, 
144 144
 			     const string& content_type,