Browse code

b/f: reset offer/answer state before auth-resending request

Stefan Sayer authored on 10/06/2011 15:17:10
Showing 4 changed files
... ...
@@ -59,6 +59,20 @@ const char* AmSipDialog::getStatusStr()
59 59
   return dlgStatusStr(status);
60 60
 }
61 61
 
62
+const char* __dlg_oa_status2str[AmSipDialog::__max_OA]  = {
63
+    "None",
64
+    "OfferRecved",
65
+    "OfferSent",
66
+    "Completed"
67
+};
68
+
69
+const char* getOAStatusStr(AmSipDialog::OAState st) {
70
+  if((st < 0) || (st >= AmSipDialog::__max_OA))
71
+    return "Invalid";
72
+  else
73
+    return __dlg_oa_status2str[st];
74
+}
75
+
62 76
 AmSipDialog::AmSipDialog(AmSipDialogEventHandler* h)
63 77
   : status(Disconnected),oa_state(OA_None),
64 78
     cseq(10),r_cseq_i(false),hdl(h),
... ...
@@ -100,12 +114,22 @@ AmSipDialog::~AmSipDialog()
100 114
 }
101 115
 
102 116
 void AmSipDialog::setStatus(Status new_status) {
103
-  DBG("setting  SIP dialog status: %s->%s\n",
117
+  DBG("setting SIP dialog status: %s->%s\n",
104 118
       getStatusStr(), dlgStatusStr(new_status));
105 119
 
106 120
   status = new_status;
107 121
 }
108 122
 
123
+AmSipDialog::OAState AmSipDialog::get_OA_state() {
124
+  return oa_state;
125
+}
126
+
127
+void AmSipDialog::set_OA_state(OAState new_oa_state) {
128
+  DBG("setting SIP dialog O/A status: %s->%s\n",
129
+      getOAStatusStr(oa_state), getOAStatusStr(new_oa_state));
130
+  oa_state = new_oa_state;
131
+}
132
+
109 133
 void AmSipDialog::onRxRequest(const AmSipRequest& req)
110 134
 {
111 135
   DBG("AmSipDialog::onRxRequest(req = %s)\n", req.method.c_str());
... ...
@@ -283,6 +307,7 @@ int AmSipDialog::onTxSdp(const string& body)
283 307
 
284 308
   case OA_OfferSent:
285 309
     // There is already a pending offer!!!
310
+    DBG("There is already a pending offer, onTxSdp fails\n");
286 311
     return -1;
287 312
 
288 313
   default:
... ...
@@ -1374,7 +1399,7 @@ int AmSipDialog::sendRequest(const string& method,
1374 1399
 
1375 1400
   req.content_type = content_type;
1376 1401
   req.body = body;
1377
-
1402
+  DBG("req.body = '%s'\n", req.body.c_str());
1378 1403
   OAState old_oa_state = oa_state;
1379 1404
   if(onTxRequest(req))
1380 1405
     return -1;
... ...
@@ -208,6 +208,11 @@ private:
208 208
 
209 209
   void   setStatus(Status new_status);
210 210
 
211
+  /** get offer/answer state */
212
+  OAState get_OA_state();
213
+  /** set offer/answer state (handle with caution!) */
214
+  void set_OA_state(OAState new_oa_state);
215
+
211 216
   string getContactHdr();
212 217
 
213 218
   /** 
... ...
@@ -389,6 +394,8 @@ class AmSipDialogEventHandler
389 394
 
390 395
 const char* dlgStatusStr(AmSipDialog::Status st);
391 396
 
397
+const char* getOAStatusStr(AmSipDialog::OAState st);
398
+
392 399
 
393 400
 
394 401
 #endif
... ...
@@ -183,6 +183,10 @@ bool UACAuth::onSipReply(const AmSipReply& reply, AmSipDialog::Status old_dlg_st
183 183
 	      }
184 184
 
185 185
 	    }
186
+
187
+	    // reset OA state to what is was before sending the failed request
188
+	    dlg->set_OA_state(ri->second.oa_state);
189
+
186 190
 	    // resend request 
187 191
 	    if (dlg->sendRequest(ri->second.method,
188 192
 				 ri->second.content_type,
... ...
@@ -217,7 +221,8 @@ bool UACAuth::onSendRequest(const string& method,
217 221
   sent_requests[cseq] = SIPRequestInfo(method, 
218 222
 				       content_type,
219 223
 				       body,
220
-				       hdrs);
224
+				       hdrs,
225
+				       dlg->get_OA_state());
221 226
   return false;
222 227
 }
223 228
 
... ...
@@ -85,13 +85,15 @@ struct SIPRequestInfo {
85 85
   string content_type;
86 86
   string body;
87 87
   string hdrs;
88
-	
88
+  AmSipDialog::OAState oa_state;
89
+
89 90
   SIPRequestInfo(const string& method, 
90 91
 		 const string& content_type,
91 92
 		 const string& body,
92
-		 const string& hdrs)
93
+		 const string& hdrs,
94
+		 AmSipDialog::OAState oa_state)
93 95
     : method(method), content_type(content_type),
94
-       body(body), hdrs(hdrs) { }
96
+    body(body), hdrs(hdrs), oa_state(oa_state) { }
95 97
 
96 98
   SIPRequestInfo() {}
97 99