home *** CD-ROM | disk | FTP | other *** search
/ ftp.muug.mb.ca / 2014.06.ftp.muug.mb.ca.tar / ftp.muug.mb.ca / pub / openh323.tar.gz / openh323.tar / openh323 / src / svcctrl.cxx < prev    next >
C/C++ Source or Header  |  2003-03-31  |  7KB  |  267 lines

  1. /*
  2.  * svcctrl.cxx
  3.  *
  4.  * H.225 Service Control protocol handler
  5.  *
  6.  * Open H323 Library
  7.  *
  8.  * Copyright (c) 2003 Equivalence Pty. Ltd.
  9.  *
  10.  * The contents of this file are subject to the Mozilla Public License
  11.  * Version 1.0 (the "License"); you may not use this file except in
  12.  * compliance with the License. You may obtain a copy of the License at
  13.  * http://www.mozilla.org/MPL/
  14.  *
  15.  * Software distributed under the License is distributed on an "AS IS"
  16.  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  17.  * the License for the specific language governing rights and limitations
  18.  * under the License.
  19.  *
  20.  * The Original Code is Open H323 Library.
  21.  *
  22.  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
  23.  *
  24.  * Contributor(s): ______________________________________.
  25.  *
  26.  * $Log: svcctrl.cxx,v $
  27.  * Revision 1.1  2003/04/01 01:06:28  robertj
  28.  * Split service control handlers from H.225 RAS header.
  29.  *
  30.  */
  31.  
  32. #include <ptlib.h>
  33.  
  34. #ifdef __GNUC__
  35. #pragma implementation "svcctrl.h"
  36. #endif
  37.  
  38. #include "svcctrl.h"
  39.  
  40. #include "h323ep.h"
  41. #include "h323pdu.h"
  42. #include "h248.h"
  43.  
  44.  
  45. #define new PNEW
  46.  
  47.  
  48. /////////////////////////////////////////////////////////////////////////////
  49.  
  50. H323ServiceControlSession::H323ServiceControlSession()
  51. {
  52. }
  53.  
  54.  
  55. PString H323ServiceControlSession::GetServiceControlType() const
  56. {
  57.   return GetClass();
  58. }
  59.  
  60.  
  61. /////////////////////////////////////////////////////////////////////////////
  62.  
  63. H323HTTPServiceControl::H323HTTPServiceControl(const PString & u)
  64.   : url(u)
  65. {
  66. }
  67.  
  68.  
  69. H323HTTPServiceControl::H323HTTPServiceControl(const H225_ServiceControlDescriptor & contents)
  70. {
  71.   OnReceivedPDU(contents);
  72. }
  73.  
  74.  
  75. BOOL H323HTTPServiceControl::IsValid() const
  76. {
  77.   return !url.IsEmpty();
  78. }
  79.  
  80.  
  81. PString H323HTTPServiceControl::GetServiceControlType() const
  82. {
  83.   return url;
  84. }
  85.  
  86.  
  87. BOOL H323HTTPServiceControl::OnReceivedPDU(const H225_ServiceControlDescriptor & contents)
  88. {
  89.   if (contents.GetTag() != H225_ServiceControlDescriptor::e_url)
  90.     return FALSE;
  91.  
  92.   const PASN_IA5String & pdu = contents;
  93.   url = pdu;
  94.   return TRUE;
  95. }
  96.  
  97.  
  98. BOOL H323HTTPServiceControl::OnSendingPDU(H225_ServiceControlDescriptor & contents) const
  99. {
  100.   contents.SetTag(H225_ServiceControlDescriptor::e_url);
  101.   PASN_IA5String & pdu = contents;
  102.   pdu = url;
  103.  
  104.   return TRUE;
  105. }
  106.  
  107.  
  108. void H323HTTPServiceControl::OnChange(unsigned type,
  109.                                       unsigned sessionId,
  110.                                       H323EndPoint & endpoint,
  111.                                       H323Connection * /*connection*/) const
  112. {
  113.   PTRACE(2, "SvcCtrl\tOnChange HTTP service control " << url);
  114.  
  115.   endpoint.OnHTTPServiceControl(type, sessionId, url);
  116. }
  117.  
  118.  
  119. /////////////////////////////////////////////////////////////////////////////
  120.  
  121. H323H248ServiceControl::H323H248ServiceControl()
  122. {
  123. }
  124.  
  125.  
  126. H323H248ServiceControl::H323H248ServiceControl(const H225_ServiceControlDescriptor & contents)
  127. {
  128.   OnReceivedPDU(contents);
  129. }
  130.  
  131.  
  132. BOOL H323H248ServiceControl::OnReceivedPDU(const H225_ServiceControlDescriptor & contents)
  133. {
  134.   if (contents.GetTag() != H225_ServiceControlDescriptor::e_signal)
  135.     return FALSE;
  136.  
  137.   const H225_H248SignalsDescriptor & pdu = contents;
  138.  
  139.   H248_SignalsDescriptor signal;
  140.   if (!pdu.DecodeSubType(signal))
  141.     return FALSE;
  142.  
  143.   return OnReceivedPDU(signal);
  144. }
  145.  
  146.  
  147. BOOL H323H248ServiceControl::OnSendingPDU(H225_ServiceControlDescriptor & contents) const
  148. {
  149.   contents.SetTag(H225_ServiceControlDescriptor::e_signal);
  150.   H225_H248SignalsDescriptor & pdu = contents;
  151.  
  152.   H248_SignalsDescriptor signal;
  153.  
  154.   pdu.EncodeSubType(signal);
  155.  
  156.   return OnSendingPDU(signal);
  157. }
  158.  
  159.  
  160. BOOL H323H248ServiceControl::OnReceivedPDU(const H248_SignalsDescriptor & descriptor)
  161. {
  162.   for (PINDEX i = 0; i < descriptor.GetSize(); i++) {
  163.     if (!OnReceivedPDU(descriptor[i]))
  164.       return FALSE;
  165.   }
  166.  
  167.   return TRUE;
  168. }
  169.  
  170.  
  171. BOOL H323H248ServiceControl::OnSendingPDU(H248_SignalsDescriptor & descriptor) const
  172. {
  173.   PINDEX last = descriptor.GetSize();
  174.   descriptor.SetSize(last+1);
  175.   return OnSendingPDU(descriptor[last]);
  176. }
  177.  
  178.  
  179. /////////////////////////////////////////////////////////////////////////////
  180.  
  181. H323CallCreditServiceControl::H323CallCreditServiceControl(const PString & amt,
  182.                                                            BOOL m,
  183.                                                            unsigned dur)
  184.   : amount(amt),
  185.     mode(m),
  186.     durationLimit(dur)
  187. {
  188. }
  189.  
  190.  
  191. H323CallCreditServiceControl::H323CallCreditServiceControl(const H225_ServiceControlDescriptor & contents)
  192. {
  193.   OnReceivedPDU(contents);
  194. }
  195.  
  196.  
  197. BOOL H323CallCreditServiceControl::IsValid() const
  198. {
  199.   return !amount || durationLimit > 0;
  200. }
  201.  
  202.  
  203. BOOL H323CallCreditServiceControl::OnReceivedPDU(const H225_ServiceControlDescriptor & contents)
  204. {
  205.   if (contents.GetTag() != H225_ServiceControlDescriptor::e_callCreditServiceControl)
  206.     return FALSE;
  207.  
  208.   const H225_CallCreditServiceControl & credit = contents;
  209.  
  210.   if (credit.HasOptionalField(H225_CallCreditServiceControl::e_amountString))
  211.     amount = credit.m_amountString;
  212.  
  213.   if (credit.HasOptionalField(H225_CallCreditServiceControl::e_billingMode))
  214.     mode = credit.m_billingMode.GetTag() == H225_CallCreditServiceControl_billingMode::e_debit;
  215.   else
  216.     mode = TRUE;
  217.  
  218.   if (credit.HasOptionalField(H225_CallCreditServiceControl::e_callDurationLimit))
  219.     durationLimit = credit.m_callDurationLimit;
  220.   else
  221.     durationLimit = 0;
  222.  
  223.   return TRUE;
  224. }
  225.  
  226.  
  227. BOOL H323CallCreditServiceControl::OnSendingPDU(H225_ServiceControlDescriptor & contents) const
  228. {
  229.   contents.SetTag(H225_ServiceControlDescriptor::e_callCreditServiceControl);
  230.   H225_CallCreditServiceControl & credit = contents;
  231.  
  232.   if (!amount) {
  233.     credit.IncludeOptionalField(H225_CallCreditServiceControl::e_amountString);
  234.     credit.m_amountString = amount;
  235.  
  236.     credit.IncludeOptionalField(H225_CallCreditServiceControl::e_billingMode);
  237.     credit.m_billingMode.SetTag(mode ? H225_CallCreditServiceControl_billingMode::e_debit
  238.                                      : H225_CallCreditServiceControl_billingMode::e_credit);
  239.   }
  240.  
  241.   if (durationLimit > 0) {
  242.     credit.IncludeOptionalField(H225_CallCreditServiceControl::e_callDurationLimit);
  243.     credit.m_callDurationLimit = durationLimit;
  244.     credit.IncludeOptionalField(H225_CallCreditServiceControl::e_enforceCallDurationLimit);
  245.     credit.m_enforceCallDurationLimit = TRUE;
  246.   }
  247.  
  248.   return !amount || durationLimit > 0;
  249. }
  250.  
  251.  
  252. void H323CallCreditServiceControl::OnChange(unsigned /*type*/,
  253.                                              unsigned /*sessionId*/,
  254.                                              H323EndPoint & endpoint,
  255.                                              H323Connection * connection) const
  256. {
  257.   PTRACE(2, "SvcCtrl\tOnChange Call Credit service control "
  258.          << amount << (mode ? " debit " : " credit ") << durationLimit);
  259.  
  260.   endpoint.OnCallCreditServiceControl(amount, mode);
  261.   if (durationLimit > 0 && connection != NULL)
  262.     connection->SetEnforcedDurationLimit(durationLimit);
  263. }
  264.  
  265.  
  266. /////////////////////////////////////////////////////////////////////////////
  267.