Browse code

multi-mime: plugins: adapt to core API changes.

Raphael Coeffic authored on 20/02/2012 09:10:35
Showing 11 changed files
... ...
@@ -149,19 +149,21 @@ void AnnounceTransferDialog::onSipRequest(const AmSipRequest& req)
149 149
       if (strip_header_params(getHeader(req.hdrs,"Event", "o", true)) != "refer") 
150 150
 	throw AmSession::Exception(481, "Subscription does not exist");
151 151
 
152
-      if ((strip_header_params(req.content_type) != "message/sipfrag"))
152
+      if (!req.body.isContentType("message/sipfrag"))
153 153
 	throw AmSession::Exception(415, "Unsupported Media Type");
154 154
 
155
-      if (req.body.length()<8)
155
+      string body((const char*)req.body.getPayload(),
156
+		  req.body.getLen());
157
+
158
+      if (body.length()<8)
156 159
 	throw AmSession::Exception(400, "Short Body");
157 160
 			
158
-      string sipfrag_sline = req.body.substr(8, req.body.find("\n") - 8);
161
+      string sipfrag_sline = body.substr(8, body.find("\n") - 8);
159 162
       DBG("extracted start line from sipfrag '%s'\n", sipfrag_sline.c_str());
160 163
       unsigned int code;
161 164
       string res_msg;
162
-
163 165
 			
164
-      if ((req.body.length() < 11)
166
+      if ((body.length() < 11)
165 167
 	  || (parse_return_code(sipfrag_sline.c_str(), code, res_msg))) {
166 168
 	throw AmSession::Exception(400, "Bad Request");				
167 169
       }
... ...
@@ -179,9 +181,9 @@ void AnnounceTransferDialog::onSipRequest(const AmSipRequest& req)
179 181
 	  dlg.bye();
180 182
 	setStopped();
181 183
       }
182
-      dlg.reply(req, 200, "OK", "", "");
184
+      dlg.reply(req, 200, "OK", NULL);
183 185
     } catch (const AmSession::Exception& e) {
184
-      dlg.reply(req, e.code, e.reason, "", "");
186
+      dlg.reply(req, e.code, e.reason, NULL);
185 187
     }
186 188
   } else {
187 189
     AmSession::onSipRequest(req);
... ...
@@ -191,7 +191,6 @@ void C2DCallerDialog::onInvite(const AmSipRequest& req)
191 191
 void C2DCallerDialog::onInvite2xx(const AmSipReply& reply)
192 192
 {
193 193
   invite_req.body = reply.body;
194
-  invite_req.content_type = reply.content_type;
195 194
   invite_req.cseq = reply.cseq;
196 195
   est_invite_cseq = reply.cseq;
197 196
 }
... ...
@@ -822,7 +822,7 @@ void ConferenceDialog::createDialoutParticipant(const string& uri_user)
822 822
   dialout_dlg.remote_party = uri;
823 823
   dialout_dlg.remote_uri   = uri;
824 824
 
825
-  dialout_dlg.sendRequest(SIP_METH_INVITE,"","",
825
+  dialout_dlg.sendRequest(SIP_METH_INVITE,NULL,
826 826
 			  extra_headers);
827 827
 
828 828
   dialout_session->start();
... ...
@@ -268,8 +268,11 @@ int EarlyAnnounceFactory::onLoad()
268 268
 
269 269
 void EarlyAnnounceDialog::onInvite(const AmSipRequest& req) 
270 270
 {
271
+  AmMimeBody sdp_body;
272
+  sdp_body.addPart(SIP_APPLICATION_SDP);
273
+
271 274
   if(dlg.reply(req,183,"Session Progress",
272
-	       "application/sdp") != 0){
275
+	       &sdp_body) != 0){
273 276
     throw AmSession::Exception(500,"could not reply");
274 277
   } else {
275 278
     invite_req = req;
... ...
@@ -101,7 +101,11 @@ void MWI::publish(const string& user, const string& domain)
101 101
 
102 102
   body += "Message-Account: sip:" + user + "@" + domain + "\r\n";
103 103
   body += "Voice-Message: " + vm_buf + " (" + vm_buf + ")\r\n";
104
-    
104
+
105
+  AmMimeBody sms_body;
106
+  sms_body.addPart("application/simple-message-summary");
107
+  sms_body.setPayload((const unsigned char*)body.c_str(),body.length());
108
+
105 109
   AmSipDialog tmp_d(NULL);
106 110
   tmp_d.local_party = string("<sip:mwi-publisher@") + presence_server + ">";
107 111
   tmp_d.remote_party = domain.c_str();
... ...
@@ -109,7 +113,7 @@ void MWI::publish(const string& user, const string& domain)
109 113
   tmp_d.remote_uri = "sip:" + user + "@" + domain;
110 114
   tmp_d.callid = AmSession::getNewId() + "@" + presence_server;
111 115
   tmp_d.local_tag = AmSession::getNewId();
112
-  tmp_d.sendRequest("PUBLISH", "application/simple-message-summary", body, headers);              
116
+  tmp_d.sendRequest(SIP_METH_NOTIFY, &sms_body, headers);     
113 117
 };
114 118
 
115 119
 void MWI::invoke(const string& method, const AmArg& args, AmArg& ret)
... ...
@@ -708,9 +708,12 @@ RtmpSession* RtmpConnection::startSession(const char* uri)
708 708
   case AmSessionContainer::Inserted:
709 709
     break;
710 710
   }
711
+  
712
+  AmMimeBody sdp_body;
713
+  sdp_body.addPart(SIP_APPLICATION_SDP);
711 714
 
712 715
   RtmpSession* pn_session = n_session.release();
713
-  if(dialout_dlg.sendRequest(SIP_METH_INVITE,"application/sdp") < 0) {
716
+  if(dialout_dlg.sendRequest(SIP_METH_INVITE,&sdp_body) < 0) {
714 717
     ERROR("dialout_dlg.sendRequest() returned an error\n");
715 718
     AmSessionContainer::instance()->destroySession(pn_session);
716 719
     return NULL;
... ...
@@ -909,7 +909,7 @@ void SBCDialog::onSipRequest(const AmSipRequest& req) {
909 909
        call_profile.messagefilter_list.end());
910 910
     if (is_filtered) {
911 911
       DBG("replying 405 to filtered message '%s'\n", req.method.c_str());
912
-      dlg.reply(req, 405, "Method Not Allowed", "", "", "", SIP_FLAGS_VERBATIM);
912
+      dlg.reply(req, 405, "Method Not Allowed", NULL, "", SIP_FLAGS_VERBATIM);
913 913
       return;
914 914
     }
915 915
   }
... ...
@@ -923,7 +923,7 @@ void SBCDialog::onSipReply(const AmSipReply& reply, AmSipDialog::Status old_dlg_
923 923
   bool fwd = t != relayed_req.end();
924 924
 
925 925
   DBG("onSipReply: %i %s (fwd=%i)\n",reply.code,reply.reason.c_str(),fwd);
926
-  DBG("onSipReply: content-type = %s\n",reply.content_type.c_str());
926
+  DBG("onSipReply: content-type = %s\n",reply.body.getCTStr().c_str());
927 927
   if (fwd) {
928 928
       CALL_EVENT_H(onSipReply,reply, old_dlg_status);
929 929
   }
... ...
@@ -1190,7 +1190,7 @@ bool SBCDialog::CCStart(const AmSipRequest& req) {
1190 1190
 
1191 1191
 	  dlg.reply(req,
1192 1192
 		    ret[i][SBC_CC_REFUSE_CODE].asInt(), ret[i][SBC_CC_REFUSE_REASON].asCStr(),
1193
-		    "", "", headers);
1193
+		    NULL, headers);
1194 1194
 
1195 1195
 	  // call 'end' of call control modules up to here
1196 1196
 	  call_end_ts.tv_sec = call_start_ts.tv_sec;
... ...
@@ -1511,7 +1511,7 @@ void SBCCalleeSession::onSipRequest(const AmSipRequest& req) {
1511 1511
        call_profile.messagefilter_list.end());
1512 1512
     if (is_filtered) {
1513 1513
       DBG("replying 405 to filtered message '%s'\n", req.method.c_str());
1514
-      dlg.reply(req, 405, "Method Not Allowed", "", "", "", SIP_FLAGS_VERBATIM);
1514
+      dlg.reply(req, 405, "Method Not Allowed", NULL, "", SIP_FLAGS_VERBATIM);
1515 1515
       return;
1516 1516
     }
1517 1517
   }
... ...
@@ -1525,7 +1525,7 @@ void SBCCalleeSession::onSipReply(const AmSipReply& reply, AmSipDialog::Status o
1525 1525
   TransMap::iterator t = relayed_req.find(reply.cseq);
1526 1526
   bool fwd = t != relayed_req.end();
1527 1527
   DBG("onSipReply: %i %s (fwd=%i)\n",reply.code,reply.reason.c_str(),fwd);
1528
-  DBG("onSipReply: content-type = %s\n",reply.content_type.c_str());
1528
+  DBG("onSipReply: content-type = %s\n",reply.body.getCTStr().c_str());
1529 1529
   if(fwd) {
1530 1530
     CALL_EVENT_H(onSipReply,reply, old_dlg_status);
1531 1531
   }
... ...
@@ -105,8 +105,8 @@ bool SessionTimer::onSipReply(const AmSipReply& reply, AmSipDialog::Status old_d
105 105
 	    session_interval = i_minse;
106 106
 	    unsigned int new_cseq = s->dlg.cseq;
107 107
 	    // resend request with interval i_minse
108
-	    if (s->dlg.sendRequest(orig_req.method,orig_req.content_type,
109
-				    orig_req.body, orig_req.hdrs) == 0) {
108
+	    if (s->dlg.sendRequest(orig_req.method, &orig_req.body,
109
+				   orig_req.hdrs) == 0) {
110 110
               DBG("request with new Session Interval %u successfully sent.\n", i_minse);
111 111
 	      // undo SIP dialog status change
112 112
 	      if (s->dlg.getStatus() != old_dlg_status)
... ...
@@ -136,8 +136,7 @@ bool SessionTimer::onSipReply(const AmSipReply& reply, AmSipDialog::Status old_d
136 136
 }
137 137
 
138 138
 bool SessionTimer::onSendRequest(const string& method, 
139
-				 const string& content_type,
140
-				 const string& body,
139
+				 const AmMimeBody* body,
141 140
 				 string& hdrs,
142 141
 				 int flags,
143 142
 				 unsigned int cseq)
... ...
@@ -152,7 +151,6 @@ bool SessionTimer::onSendRequest(const string& method,
152 151
     // save INVITE and UPDATE so we can resend on 422 reply
153 152
     DBG("adding %d to list of sent requests.\n", cseq);
154 153
     sent_requests[cseq] = SIPRequestInfo(method,
155
-					 content_type,
156 154
 					 body,
157 155
 					 hdrs);
158 156
   }
... ...
@@ -158,8 +158,7 @@ class SessionTimer: public AmSessionEventHandler
158 158
   virtual bool onSipReply(const AmSipReply&, AmSipDialog::Status old_dlg_status);
159 159
 
160 160
   virtual bool onSendRequest(const string& method, 
161
-			     const string& content_type,
162
-			     const string& body,
161
+			     const AmMimeBody* body,
163 162
 			     string& hdrs,
164 163
 			     int flags,
165 164
 			     unsigned int cseq);
... ...
@@ -171,16 +170,16 @@ class SessionTimer: public AmSessionEventHandler
171 170
 /** \brief contains necessary information for UAC auth of a SIP request */
172 171
 struct SIPRequestInfo {
173 172
   string method;
174
-  string content_type;
175
-  string body;
173
+  AmMimeBody body;
176 174
   string hdrs;
177 175
 
178 176
   SIPRequestInfo(const string& method,
179
-		 const string& content_type,
180
-		 const string& body,
177
+		 const AmMimeBody* body,
181 178
 		 const string& hdrs)
182
-    : method(method), content_type(content_type),
183
-       body(body), hdrs(hdrs) { }
179
+    : method(method), hdrs(hdrs) 
180
+  { 
181
+    if(body) this->body = *body;
182
+  }
184 183
 
185 184
   SIPRequestInfo() {}
186 185
 
... ...
@@ -132,7 +132,7 @@ bool UACAuth::onSipReply(const AmSipReply& reply, AmSipDialog::Status old_dlg_st
132 132
   if (reply.code==407 || reply.code==401) {
133 133
     DBG("SIP reply with code %d cseq %d .\n", reply.code, reply.cseq);
134 134
 		
135
-    std::map<unsigned int, SIPRequestInfo >::iterator ri = 
135
+    std::map<unsigned int, SIPRequestInfo>::iterator ri = 
136 136
       sent_requests.find(reply.cseq);
137 137
     if (ri!= sent_requests.end())
138 138
       {
... ...
@@ -160,7 +160,7 @@ bool UACAuth::onSipReply(const AmSipReply& reply, AmSipDialog::Status old_dlg_st
160 160
 
161 161
 	  if (do_auth(reply.code, auth_hdr,  
162 162
 		      ri->second.method,
163
-		      auth_uri, ri->second.body, result)) {
163
+		      auth_uri, &(ri->second.body), result)) {
164 164
 	    string hdrs = ri->second.hdrs;
165 165
 
166 166
 	    // strip other auth headers
... ...
@@ -198,8 +198,7 @@ bool UACAuth::onSipReply(const AmSipReply& reply, AmSipDialog::Status old_dlg_st
198 198
 
199 199
 	    // resend request 
200 200
 	    if (dlg->sendRequest(ri->second.method,
201
-				 ri->second.content_type,
202
-				 ri->second.body, 
201
+				 &(ri->second.body),
203 202
 				 hdrs, SIP_FLAGS_VERBATIM | SIP_FLAGS_NOAUTH) == 0) {
204 203
 	      processed = true;
205 204
               DBG("authenticated request successfully sent.\n");
... ...
@@ -221,8 +220,7 @@ bool UACAuth::onSipReply(const AmSipReply& reply, AmSipDialog::Status old_dlg_st
221 220
 }
222 221
 
223 222
 bool UACAuth::onSendRequest(const string& method, 
224
-			    const string& content_type,
225
-			    const string& body,
223
+			    const AmMimeBody* body,
226 224
 			    string& hdrs,
227 225
 			    int flags,
228 226
 			    unsigned int cseq)
... ...
@@ -232,8 +230,7 @@ bool UACAuth::onSendRequest(const string& method,
232 230
   if (!(flags & SIP_FLAGS_NOAUTH) &&
233 231
       !challenge.nonce.empty() &&
234 232
       do_auth(challenge, challenge_code,
235
-	      method,
236
-	      dlg->remote_uri, body, result)) {
233
+	      method, dlg->remote_uri, body, result)) {
237 234
     // add headers
238 235
     if (hdrs == "\r\n" || hdrs == "\r" || hdrs == "\n")
239 236
       hdrs = result;
... ...
@@ -247,7 +244,6 @@ bool UACAuth::onSendRequest(const string& method,
247 244
 
248 245
   DBG("adding %d to list of sent requests.\n", cseq);
249 246
   sent_requests[cseq] = SIPRequestInfo(method, 
250
-				       content_type,
251 247
 				       body,
252 248
 				       hdrs,
253 249
 				       dlg->getOAState());
... ...
@@ -309,7 +305,7 @@ bool UACAuth::parse_header(const string& auth_hdr, UACAuthDigestChallenge& chall
309 305
 
310 306
 bool UACAuth::do_auth(const unsigned int code, const string& auth_hdr,  
311 307
 		      const string& method, const string& uri,
312
-		      const string& body, string& result)
308
+		      const AmMimeBody* body, string& result)
313 309
 {
314 310
   if (!auth_hdr.length()) {
315 311
     ERROR("empty auth header.\n");
... ...
@@ -330,7 +326,7 @@ bool UACAuth::do_auth(const unsigned int code, const string& auth_hdr,
330 326
 bool UACAuth::do_auth(const UACAuthDigestChallenge& challenge,
331 327
 		      const unsigned int code,
332 328
 		      const string& method, const string& uri, 
333
-		      const string& body, string& result) 
329
+		      const AmMimeBody* body, string& result) 
334 330
 {
335 331
   if ((challenge.algorithm.length()) && (challenge.algorithm != "MD5")) {
336 332
     DBG("unsupported algorithm: '%s'\n", challenge.algorithm.c_str());
... ...
@@ -347,7 +343,7 @@ bool UACAuth::do_auth(const UACAuthDigestChallenge& challenge,
347 343
     DBG("authentication realm mismatch ('%s' vs '%s').\n", 
348 344
  	credential->realm.c_str(),challenge.realm.c_str());
349 345
   }
350
- 
346
+
351 347
   HASHHEX ha1;
352 348
   HASHHEX ha2;
353 349
   HASHHEX hentity;
... ...
@@ -372,7 +368,9 @@ bool UACAuth::do_auth(const UACAuthDigestChallenge& challenge,
372 368
 	nonce_count = 1;
373 369
 
374 370
       if(qop_auth_int){
375
-	uac_calc_hentity(body,hentity);
371
+	string body_str;
372
+	if(body) body->print(body_str);
373
+	uac_calc_hentity(body_str,hentity);
376 374
 	qop_value = "auth-int";
377 375
       }
378 376
       else
... ...
@@ -78,18 +78,19 @@ class UACAuthFactory
78 78
 /** \brief contains necessary information for UAC auth of a SIP request */
79 79
 struct SIPRequestInfo {
80 80
   string method;
81
-  string content_type;
82
-  string body;
81
+  AmMimeBody body;
83 82
   string hdrs;
84 83
   AmOfferAnswer::OAState oa_state;
85 84
 
86 85
   SIPRequestInfo(const string& method, 
87
-		 const string& content_type,
88
-		 const string& body,
86
+		 const AmMimeBody* body,
89 87
 		 const string& hdrs,
90 88
 		 AmOfferAnswer::OAState oa_state)
91
-    : method(method), content_type(content_type),
92
-    body(body), hdrs(hdrs), oa_state(oa_state) { }
89
+    : method(method), hdrs(hdrs), 
90
+      oa_state(oa_state) 
91
+  {
92
+    if(body) this->body = *body;
93
+  }
93 94
 
94 95
   SIPRequestInfo() {}
95 96
 
... ...
@@ -136,7 +137,7 @@ class UACAuth : public AmSessionEventHandler
136 137
    */
137 138
   bool do_auth(const unsigned int code, const string& auth_hdr,  
138 139
 	       const string& method, const string& uri, 
139
-	       const string& body, string& result);
140
+	       const AmMimeBody* body, string& result);
140 141
 
141 142
   /**
142 143
    *  do auth on cmd with saved challenge
... ...
@@ -145,7 +146,7 @@ class UACAuth : public AmSessionEventHandler
145 146
   bool do_auth(const UACAuthDigestChallenge& challenge,
146 147
 	       const unsigned int code,
147 148
 	       const string& method, const string& uri,
148
-	       const string& body, string& result);
149
+	       const AmMimeBody* body, string& result);
149 150
 	
150 151
  public:
151 152
 	
... ...
@@ -159,8 +160,7 @@ class UACAuth : public AmSessionEventHandler
159 160
   virtual bool onSipReply(const AmSipReply&, AmSipDialog::Status old_dlg_status);
160 161
 	
161 162
   virtual bool onSendRequest(const string& method, 
162
-			     const string& content_type,
163
-			     const string& body,
163
+			     const AmMimeBody* body,
164 164
 			     string& hdrs,
165 165
 			     int flags,
166 166
 			     unsigned int cseq);