Browse code

reply to OPTIONS also if no application configured

reported by Julian Santer

Conflicts:

core/sip/defs.h

Stefan Sayer authored on 12/09/2013 18:42:33
Showing 5 changed files
... ...
@@ -79,25 +79,38 @@ void AmSessionFactory::configureSession(AmSession* sess) {
79 79
 
80 80
 void AmSessionFactory::onOoDRequest(const AmSipRequest& req)
81 81
 {
82
-  string hdrs;
83
-  if (!AmConfig::OptionsTranscoderInStatsHdr.empty()) {
84
-    string usage;
85
-    B2BMediaStatistics::instance()->reportCodecReadUsage(usage);
86
-
87
-    hdrs += AmConfig::OptionsTranscoderInStatsHdr + ": ";
88
-    hdrs += usage;
89
-    hdrs += CRLF;
90
-  }
91
-  if (!AmConfig::OptionsTranscoderOutStatsHdr.empty()) {
92
-    string usage;
93
-    B2BMediaStatistics::instance()->reportCodecWriteUsage(usage);
94 82
 
95
-    hdrs += AmConfig::OptionsTranscoderOutStatsHdr + ": ";
96
-    hdrs += usage;
97
-    hdrs += CRLF;
83
+  if (req.method == SIP_METH_OPTIONS) {
84
+    replyOptions(req);
85
+    return;
98 86
   }
99 87
 
100
-  if (req.method == "OPTIONS") {
88
+  INFO("sorry, we don't support beginning a new session with "
89
+       "a '%s' message\n", req.method.c_str());
90
+
91
+  AmSipDialog::reply_error(req,501,"Not Implemented");
92
+  return;
93
+}
94
+
95
+void AmSessionFactory::replyOptions(const AmSipRequest& req) {
96
+    string hdrs;
97
+    if (!AmConfig::OptionsTranscoderInStatsHdr.empty()) {
98
+      string usage;
99
+      B2BMediaStatistics::instance()->reportCodecReadUsage(usage);
100
+
101
+      hdrs += AmConfig::OptionsTranscoderInStatsHdr + ": ";
102
+      hdrs += usage;
103
+      hdrs += CRLF;
104
+    }
105
+    if (!AmConfig::OptionsTranscoderOutStatsHdr.empty()) {
106
+      string usage;
107
+      B2BMediaStatistics::instance()->reportCodecWriteUsage(usage);
108
+
109
+      hdrs += AmConfig::OptionsTranscoderOutStatsHdr + ": ";
110
+      hdrs += usage;
111
+      hdrs += CRLF;
112
+    }
113
+
101 114
     // Basic OPTIONS support
102 115
     if (AmConfig::OptionsSessionLimit &&
103 116
 	(AmSession::getSessionNum() >= AmConfig::OptionsSessionLimit)) {
... ...
@@ -119,14 +132,7 @@ void AmSessionFactory::onOoDRequest(const AmSipRequest& req)
119 132
     }
120 133
 
121 134
     AmSipDialog::reply_error(req, 200, "OK", hdrs);
122
-    return;
123
-  }
124 135
 
125
-  INFO("sorry, we don't support beginning a new session with "
126
-       "a '%s' message\n", req.method.c_str());
127
-    
128
-  AmSipDialog::reply_error(req,501,"Not Implemented");
129
-  return;
130 136
 }
131 137
 
132 138
 // void AmSessionFactory::postEvent(AmEvent* ev) {
... ...
@@ -130,6 +130,9 @@ class AmSessionFactory: public AmPluginFactory
130 130
   int configureModule(AmConfigReader& cfg);
131 131
 
132 132
  public:
133
+
134
+  static void replyOptions(const AmSipRequest& req);
135
+
133 136
   /**
134 137
    * This function applys the module configuration 
135 138
    */
... ...
@@ -795,7 +795,7 @@ AmSessionFactory* AmPlugIn::findSessionFactory(const AmSipRequest& req, string&
795 795
     }
796 796
     
797 797
     if (m_app_name.empty()) {
798
-      ERROR("could not find any application matching configured criteria\n");
798
+      INFO("could not find any application matching configured criteria\n");
799 799
       return NULL;
800 800
     }
801 801
     
... ...
@@ -66,6 +66,7 @@ void AmSipDispatcher::handleSipMsg(AmSipRequest &req)
66 66
   AmEventDispatcher* ev_disp = AmEventDispatcher::instance();
67 67
 
68 68
   if(!local_tag.empty()) {
69
+    // in-dlg request
69 70
     AmSipRequestEvent* ev = new AmSipRequestEvent(req);
70 71
 
71 72
       if(!ev_disp->post(local_tag,ev)) {
... ...
@@ -109,14 +110,19 @@ void AmSipDispatcher::handleSipMsg(AmSipRequest &req)
109 110
 
110 111
   } else {
111 112
 
112
-      string app_name;
113
-      AmSessionFactory* sess_fact = AmPlugIn::instance()->findSessionFactory(req,app_name);
114
-      if(!sess_fact){
115
-
116
-	  AmSipDialog::reply_error(req,404,"Not found");
117
-	  return;
118
-      }
119
-
113
+    string app_name;
114
+    AmSessionFactory* sess_fact = AmPlugIn::instance()->findSessionFactory(req,app_name);
115
+    if (sess_fact) {
120 116
       sess_fact->onOoDRequest(req);
117
+      return;
118
+    }
119
+	
120
+    if (req.method == SIP_METH_OPTIONS) {
121
+      AmSessionFactory::replyOptions(req);
122
+      return;
123
+    }
124
+      
125
+    AmSipDialog::reply_error(req,404,"Not found");
121 126
   }
127
+
122 128
 }
... ...
@@ -12,6 +12,7 @@
12 12
 #define SIP_METH_ACK            "ACK"
13 13
 #define SIP_METH_SUBSCRIBE      "SUBSCRIBE"
14 14
 #define SIP_METH_NOTIFY         "NOTIFY"
15
+#define SIP_METH_OPTIONS        "OPTIONS"
15 16
 
16 17
 #define SIP_HDR_FROM            "From"
17 18
 #define SIP_HDR_TO              "To"