OpenH323 1.18.0
|
00001 /* 00002 * opalosp.h 00003 * 00004 * OSP protocol handler 00005 * 00006 * OpenH323 Library 00007 * 00008 * Copyright (C) 2004 Post Increment 00009 * 00010 * The contents of this file are subject to the Mozilla Public License 00011 * Version 1.0 (the "License"); you may not use this file except in 00012 * compliance with the License. You may obtain a copy of the License at 00013 * http://www.mozilla.org/MPL/ 00014 * 00015 * Software distributed under the License is distributed on an "AS IS" 00016 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00017 * the License for the specific language governing rights and limitations 00018 * under the License. 00019 * 00020 * The Original Code is Open H323 Library. 00021 * 00022 * The Initial Developer of the Original Code is Post Increment 00023 * 00024 * This code was written with assistance from TransNexus, Inc. 00025 * http://www.transnexus.com 00026 * 00027 * Contributor(s): ______________________________________. 00028 * 00029 * $Log: opalosp.h,v $ 00030 * Revision 1.16 2005/12/20 02:08:02 csoutheren 00031 * Look for called and calling number information in Q.931 header for OSP validation 00032 * 00033 * Revision 1.15 2005/12/02 00:07:12 csoutheren 00034 * Look for calling number information in Q.931 header 00035 * 00036 * Revision 1.14 2005/11/30 13:05:01 csoutheren 00037 * Changed tags for Doxygen 00038 * 00039 * Revision 1.13 2005/10/13 12:34:47 csoutheren 00040 * Removed redundant inline statement 00041 * 00042 * Revision 1.12 2005/09/16 08:08:36 csoutheren 00043 * Split ReportUsage from CallEnd function 00044 * 00045 * Revision 1.11 2005/08/30 08:30:14 csoutheren 00046 * Added support for setting connection count on OSP server 00047 * 00048 * Revision 1.10 2005/08/27 02:11:58 csoutheren 00049 * Added support for different pthread library required by new OSP toolkit on Windows 00050 * Added support for new parameters to GetFirst and GetNext 00051 * Fixed incorrect usage of destination address and destination device 00052 * 00053 * Revision 1.9 2005/08/15 01:58:13 csoutheren 00054 * Adde support for version 3.3.2 of the OSP Toolkit 00055 * 00056 * Revision 1.8 2005/07/25 01:23:28 csoutheren 00057 * Added ability to select token algorithm when validating OSP tokens 00058 * 00059 * Revision 1.7 2005/01/03 06:25:52 csoutheren 00060 * Added extensive support for disabling code modules at compile time 00061 * 00062 * Revision 1.6 2004/12/20 02:32:34 csoutheren 00063 * Cleeaned up OSP functions 00064 * 00065 * Revision 1.5 2004/12/16 00:34:35 csoutheren 00066 * Fixed reporting of call end time and code 00067 * Added GetNextDestination 00068 * 00069 * Revision 1.4 2004/12/14 06:22:21 csoutheren 00070 * More OSP implementation 00071 * 00072 * Revision 1.3 2004/12/09 23:38:34 csoutheren 00073 * More OSP implementation 00074 * 00075 * Revision 1.2 2004/12/08 05:16:13 csoutheren 00076 * Fixed OSP compilation on Linux 00077 * 00078 * Revision 1.1 2004/12/08 01:59:23 csoutheren 00079 * initial support for Transnexus OSP toolkit 00080 * 00081 */ 00082 00083 #ifndef __OSP_H 00084 #define __OSP_H 00085 00086 #ifdef P_USE_PRAGMA 00087 #pragma interface 00088 #endif 00089 00090 #include "openh323buildopts.h" 00091 #include <guid.h> 00092 #include <ptclib/pssl.h> 00093 00094 #include "transports.h" 00095 #include "h225.h" 00096 00097 class H225_AliasAddress; 00098 class H323SignalPDU; 00099 class H225_Setup_UUIE; 00100 class H225_AdmissionRequest; 00101 class H323Connection; 00102 00103 #ifdef H323_TRANSNEXUS_OSP 00104 00109 // include the Transnexus headers 00110 #include <osp/osp.h> 00111 00112 namespace OpalOSP { 00113 00114 #define DECLARE_GET_SET(var, suffix, type) \ 00115 public: \ 00116 void Set##suffix(type v) { var = v; } \ 00117 type Get##suffix() const { return var; } \ 00118 protected: \ 00119 type var; \ 00120 00121 00122 // 00123 // Global functions (inside the OpalOSP namespace) 00124 // 00125 00129 void Initialise(BOOL uninitialise = FALSE); 00130 00133 PString AddressToOSPString( 00134 const PString & taddr 00135 ); 00136 H323TransportAddress OSPStringToAddress( 00137 const PString & str, WORD defaultPort 00138 ); 00139 PString TransportAddressToOSPString( 00140 const H323TransportAddress & taddr 00141 ); 00142 inline PString TransportAddressToOSPString( 00143 const H225_TransportAddress & taddr 00144 ) 00145 { return TransportAddressToOSPString(H323TransportAddress(taddr)); } 00146 00149 BOOL ConvertAliasToOSPString( 00150 const H225_AliasAddress & alias, 00151 int & format, 00152 PString & str 00153 ); 00154 00155 inline PString IpAddressToOSPString( 00156 const PIPSocket::Address & addr 00157 ) 00158 { 00159 return psprintf("[%d.%d.%d.%d]", addr.Byte1(), addr.Byte2(), addr.Byte3(), addr.Byte4()); 00160 } 00161 00162 inline PString IpAddressPortToOSPString( 00163 const PIPSocket::Address & addr, 00164 WORD port 00165 ) 00166 { 00167 return psprintf("[%d.%d.%d.%d]:%d", addr.Byte1(), addr.Byte2(), addr.Byte3(), addr.Byte4(), port); 00168 } 00169 00171 00176 class Provider : public PObject 00177 { 00178 PCLASSINFO(Provider, PObject); 00179 public: 00180 enum { 00181 IllegalHandle = -1 00182 }; 00183 00186 Provider(); 00187 00191 ~Provider(); 00192 00199 inline int Open( 00200 const PString & servicePoint 00201 ) 00202 { return Open(servicePoint, PDirectory()); } 00203 int Open( 00204 const PString & servicePoint, 00205 const PDirectory & certDir 00206 ); 00209 int Open( 00210 const PString & servicePoint, 00211 const PFilePath & localPrivateKeyName, 00212 const PFilePath & localPublicCertName, 00213 const PFilePath & localAuthCertName 00214 ); 00215 00218 int Open( 00219 const PString & servicePoint, 00220 PSSLPrivateKey & localPrivateKey, 00221 PSSLCertificate & localPublicCert, 00222 PSSLCertificate & localAuthCert 00223 ); 00224 00227 int Close(); 00228 00232 inline operator ::OSPTPROVHANDLE () 00233 { return handle; } 00234 00237 inline BOOL IsOpen() const 00238 { return handle != IllegalHandle; } 00239 00240 inline PIPSocket::Address GetHostAddress() const 00241 { return hostAddress; } 00242 00247 DECLARE_GET_SET(deleteTimeout, DeleteTimeout, int); 00248 DECLARE_GET_SET(maxSimultConn, MaxSimultConn, int); 00249 DECLARE_GET_SET(httpPersist, HttpPersist, int); 00250 DECLARE_GET_SET(httpRetryDelay, HttpRetryDelay, int); 00251 DECLARE_GET_SET(httpRetry, HttpRetry, int); 00252 DECLARE_GET_SET(httpTimeout, HttpTimeout, int); 00253 DECLARE_GET_SET(sslLifeTime, SSLLifetime, int); 00254 DECLARE_GET_SET(deviceID, DeviceID, PString); 00255 DECLARE_GET_SET(customerID, CustomerID, PString); 00256 DECLARE_GET_SET(messageCount, MessageCount, int); 00257 00258 protected: 00259 ::OSPTPROVHANDLE handle; 00260 PIPSocket::Address hostAddress; 00261 }; 00262 00264 00269 class Transaction : public PObject 00270 { 00271 PCLASSINFO(Transaction, PObject); 00272 public: 00273 enum { 00274 IllegalHandle = -1 00275 }; 00276 00279 Transaction(); 00280 00284 ~Transaction(); 00285 00288 int Open(Provider & _provider) 00289 { return Open(_provider, ""); } 00290 00291 int Open( 00292 Provider & _provider, 00293 const PString & user 00294 ); 00295 00299 struct AuthorisationInfo { 00300 00303 BOOL Extract( 00304 const H323SignalPDU & setupPDU 00305 ); 00306 00309 BOOL Extract( 00310 const H225_AdmissionRequest & arqPDU 00311 ); 00312 00313 PString ospvSource; 00314 PString ospvSourceDevice; 00315 H225_AliasAddress callingNumber; 00316 H225_AliasAddress calledNumber; 00317 PBYTEArray callID; 00318 }; 00321 int Authorise( 00322 AuthorisationInfo & info, 00323 unsigned & numberOfDestinations 00324 ); 00325 int Authorise( 00326 const PString & ospvSource, 00327 const PString & ospvSourceDevice, 00328 const H225_AliasAddress & callingNumber, 00329 const H225_AliasAddress & calledNumber, 00330 const PBYTEArray & callID, 00331 unsigned & numberOfDestinations 00332 ); 00333 int Authorise( 00334 const PString & ospvSource, 00335 const PString & ospvSourceDevice, 00336 const PString & ospvCallingNumber, 00337 int ospvCallingNumberFormat, 00338 const PString & ospvCalledNumber, 00339 int ospvCalledNumberFormat, 00340 const PBYTEArray & callID, 00341 unsigned & numberOfDestinations 00342 ); 00343 00346 struct DestinationInfo { 00347 00350 BOOL Insert( 00351 H323SignalPDU & setupPDU, 00352 BOOL useCiscoBug = FALSE 00353 ); 00354 BOOL Insert( 00355 H225_Setup_UUIE & setupPDU, 00356 BOOL useCiscoBug = FALSE 00357 ); 00358 00361 BOOL Insert( 00362 H225_AdmissionConfirm & acf, 00363 BOOL useCiscoBug = FALSE 00364 ); 00365 00366 void InsertToken(H225_ArrayOf_ClearToken & clearTokens, BOOL useCiscoBug = FALSE); 00367 00368 unsigned timeLimit; 00369 PBYTEArray callID; 00370 H225_AliasAddress calledNumber; 00371 BOOL hasCallingNumber; 00372 H225_AliasAddress callingNumber; 00373 H323TransportAddress destinationAddress; 00374 PString destination; 00375 PBYTEArray token; 00376 }; 00377 00380 int GetFirstDestination( 00381 DestinationInfo & info 00382 ); 00383 inline int GetFirstDestination( 00384 unsigned & timeLimit, 00385 PBYTEArray & callID, 00386 PString & calledNumber, 00387 PString & destination, 00388 PString & device, 00389 PBYTEArray & token 00390 ) 00391 { PString callingNumber; return GetFirstDestination(timeLimit, callID, calledNumber, callingNumber, destination, device, token); } 00392 int GetFirstDestination( 00393 unsigned & timeLimit, 00394 PBYTEArray & callID, 00395 PString & calledNumber, 00396 PString & callingNumber, 00397 PString & destination, 00398 PString & device, 00399 PBYTEArray & token 00400 ); 00401 00404 int GetNextDestination( 00405 int endReason, 00406 DestinationInfo & info 00407 ); 00408 inline int GetNextDestination( 00409 int endReason, 00410 unsigned & timeLimit, 00411 PBYTEArray & callID, 00412 PString & calledNumber, 00413 PString & destination, 00414 PString & device, 00415 PBYTEArray & token 00416 ) 00417 { PString callingNumber; return GetNextDestination(endReason, timeLimit, callID, calledNumber, callingNumber, destination, device, token); } 00418 int GetNextDestination( 00419 int endReason, 00420 unsigned & timeLimit, 00421 PBYTEArray & callID, 00422 PString & calledNumber, 00423 PString & callingNumber, 00424 PString & destination, 00425 PString & device, 00426 PBYTEArray & token 00427 ); 00428 00431 void CallStatistics( 00432 unsigned lostSentPackets, 00433 signed lostFractionSent, 00434 unsigned lostReceivedPackets, 00435 signed lostFractionReceived, 00436 const PTime & firstRTPTime 00437 ); 00438 00441 void CallEnd( 00442 H323Connection & conn 00443 ); 00444 00448 void ReportUsage( 00449 H323Connection & conn 00450 ); 00451 00454 struct ValidationInfo { 00455 00456 ValidationInfo() 00457 { tokenAlgo = TOKEN_ALGO_SIGNED; } 00458 00461 BOOL Extract( 00462 const H323SignalPDU & setupPDU 00463 ); 00464 00467 BOOL Extract( 00468 const H225_AdmissionRequest & arqPDU 00469 ); 00470 00471 BOOL ExtractToken( 00472 const H225_ArrayOf_ClearToken & clearTokens 00473 ); 00474 00475 PString ospvSource; 00476 PString ospvDest; 00477 PString ospvSourceDevice; 00478 PString ospvDestDevice; 00479 H225_AliasAddress callingNumber; 00480 H225_AliasAddress calledNumber; 00481 PBYTEArray callID; 00482 PBYTEArray token; 00483 unsigned tokenAlgo; 00484 }; 00485 int Validate( 00486 const ValidationInfo & info, 00487 BOOL & authorised, 00488 unsigned & timeLimit 00489 ); 00490 // backward compatible API 00491 int Validate( 00492 const PString & ospvSource, 00493 const PString & ospvDest, 00494 const PString & ospvSourceDevice, 00495 const PString & ospvDestDevice, 00496 const H225_AliasAddress & callingNumber, 00497 const H225_AliasAddress & calledNumber, 00498 const PBYTEArray & callID, 00499 const PBYTEArray & token, 00500 BOOL & authorised, 00501 unsigned & timeLimit 00502 ) 00503 { return Validate(ospvSource, ospvDest, ospvSourceDevice, ospvDestDevice, 00504 callingNumber, calledNumber, 00505 callID, token, TOKEN_ALGO_SIGNED, authorised, timeLimit); 00506 } 00507 00508 // backward compatible API 00509 int Validate( 00510 const PString & ospvSource, 00511 const PString & ospvDest, 00512 const PString & ospvSourceDevice, 00513 const PString & ospvDestDevice, 00514 int ospvCallingNumberFormat, 00515 const PString & ospvCallingNumber, 00516 int ospvCalledNumberFormat, 00517 const PString & ospvCalledNumber, 00518 const PBYTEArray & callID, 00519 const PBYTEArray & token, 00520 BOOL & authorised, 00521 unsigned & timeLimit 00522 ) 00523 { return Validate(ospvSource, ospvDest, ospvSourceDevice, ospvDestDevice, 00524 ospvCallingNumberFormat, ospvCallingNumber, 00525 ospvCalledNumberFormat, ospvCalledNumber, 00526 callID, token, TOKEN_ALGO_SIGNED, authorised, timeLimit); 00527 } 00528 00529 int Validate( 00530 const PString & ospvSource, 00531 const PString & ospvDest, 00532 const PString & ospvSourceDevice, 00533 const PString & ospvDestDevice, 00534 const H225_AliasAddress & callingNumber, 00535 const H225_AliasAddress & calledNumber, 00536 const PBYTEArray & callID, 00537 const PBYTEArray & token, 00538 unsigned int tokenAlgo, 00539 BOOL & authorised, 00540 unsigned & timeLimit 00541 ); 00542 int Validate( 00543 const PString & ospvSource, 00544 const PString & ospvDest, 00545 const PString & ospvSourceDevice, 00546 const PString & ospvDestDevice, 00547 int ospvCallingNumberFormat, 00548 const PString & ospvCallingNumber, 00549 int ospvCalledNumberFormat, 00550 const PString & ospvCalledNumber, 00551 const PBYTEArray & callID, 00552 const PBYTEArray & token, 00553 unsigned int tokenAlgo, 00554 BOOL & authorised, 00555 unsigned & timeLimit 00556 ); 00557 00560 int Close(); 00561 00564 inline BOOL IsOpen() const 00565 { return handle != IllegalHandle; } 00566 00567 BOOL CheckOpenedAndNotEnded(const char * str); 00568 00569 inline operator ::OSPTTRANHANDLE () 00570 { return handle; } 00571 00572 Provider * GetProvider() const 00573 { return provider; } 00574 00575 protected: 00576 Provider * provider; 00577 PString user; 00578 ::OSPTTRANHANDLE handle; 00579 00580 BOOL ended; 00581 00582 unsigned lostSentPackets; 00583 unsigned lostReceivedPackets; 00584 signed lostFractionSent; 00585 signed lostFractionReceived; 00586 PTime firstRTPTime; 00587 }; 00588 00589 } // namespace OpalOSP 00590 00591 #endif // H323_TRANSNEXUS_OSP 00592 00593 #endif