📄 uri.cc
字号:
// -*- Mode: C++; -*-// Package : omniORB// uri.cc Created on: 2000/04/03// Author : Duncan Grisby (dpg1)//// Copyright (C) 2000 AT&T Laboratories Cambridge//// This file is part of the omniORB library//// The omniORB library is free software; you can redistribute it and/or// modify it under the terms of the GNU Library General Public// License as published by the Free Software Foundation; either// version 2 of the License, or (at your option) any later version.//// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Library General Public License for more details.//// You should have received a copy of the GNU Library General Public// License along with this library; if not, write to the Free// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA // 02111-1307, USA////// Description:// Parsing for object reference URIs// *** PROPRIETARY INTERFACE ***// // $Log: uri.cc,v $// Revision 1.2.2.20 2005/07/21 15:25:09 dgrisby// Silence some gcc 4 warnings / errors.//// Revision 1.2.2.19 2004/09/13 09:43:11 dgrisby// Limited support for ssliop scheme in corbaloc. Thanks Martin Laporte.//// Revision 1.2.2.18 2003/11/20 13:39:59 dgrisby// corbaloc handler for Unix sockets. Uses omniunix scheme name.//// Revision 1.2.2.17 2003/08/06 20:34:00 dgrisby// More vxWorks patches.//// Revision 1.2.2.16 2003/02/17 02:03:09 dgrisby// vxWorks port. (Thanks Michael Sturm / Acterna Eningen GmbH).//// Revision 1.2.2.15 2002/02/13 16:03:17 dpg1// Memory leak due to missing virtual destructor.//// Revision 1.2.2.14 2002/02/01 11:20:40 dpg1// Silly bug in string_to_object wil nil objref.//// Revision 1.2.2.13 2001/12/04 14:32:27 dpg1// Minor corbaloc bugs.//// Revision 1.2.2.12 2001/08/18 17:28:38 sll// Fixed minor bug introduced by the previous update.//// Revision 1.2.2.11 2001/08/17 17:14:54 sll// Moved handler initialisation into static initialisers.//// Revision 1.2.2.10 2001/08/03 17:41:25 sll// System exception minor code overhaul. When a system exeception is raised,// a meaning minor code is provided.//// Revision 1.2.2.9 2001/07/31 17:42:11 sll// Cleanup String_var usage.//// Revision 1.2.2.8 2001/06/11 17:53:22 sll// The omniIOR ctor used by genior and corbaloc now has the option to// select whether to call interceptors and what set of interceptors to call.//// Revision 1.2.2.7 2001/06/08 17:12:22 dpg1// Merge all the bug fixes from omni3_develop.//// Revision 1.2.2.6 2001/04/18 18:18:04 sll// Big checkin with the brand new internal APIs.//// Revision 1.2.2.5 2000/11/22 14:39:55 dpg1// Treat empty host name in corbaloc: as localhost, as per 2.4 spec.//// Revision 1.2.2.4 2000/11/20 11:58:39 dpg1// No need to initialise omniIOR module before uri module.//// Revision 1.2.2.3 2000/11/09 12:27:59 dpg1// Huge merge from omni3_develop, plus full long long from omni3_1_develop.//// Revision 1.2.2.2 2000/09/27 18:24:14 sll// Use omniObjRef::_toString and _fromString. Use the new omniIOR class and// createObjRef().//// Revision 1.2.2.1 2000/07/17 10:36:00 sll// Merged from omni3_develop the diff between omni3_0_0_pre3 and omni3_0_0.//// Revision 1.3 2000/07/13 15:25:54 dpg1// Merge from omni3_develop for 3.0 release.//// Revision 1.1.2.6 2000/06/30 14:12:07 dpg1// Minor fixes for FreeBSD.//// Revision 1.1.2.5 2000/06/27 15:40:58 sll// Workaround for Cygnus gcc's inability to recognise _CORBA_Octet*& and// CORBA::Octet*& are the same type.//// Revision 1.1.2.4 2000/06/22 10:40:17 dpg1// exception.h renamed to exceptiondefs.h to avoid name clash on some// platforms.//// Revision 1.1.2.3 2000/06/19 14:18:33 dpg1// Explicit cast to (const char*) when using String_var with logger.//// Revision 1.1.2.2 2000/05/24 17:18:11 dpg1// Rename IIOP::DEFAULT_PORT IIOP::DEFAULT_CORBALOC_PORT//// Revision 1.1.2.1 2000/04/27 10:52:29 dpg1// Interoperable Naming Service//// Implementation of URI functions.//#include <stdlib.h>#include <omniORB4/CORBA.h>#include <initialiser.h>#include <exceptiondefs.h>#include <omniORB4/omniURI.h>#include <omniORB4/minorCode.h>#include <initRefs.h>#include <SocketCollection.h>#include <ctype.h>OMNI_NAMESPACE_BEGIN(omni)#define MAX_STRING_TO_OBJECT_CYCLES 10static omnivector<omniURI::URIHandler*> handlers;char*omniURI::objectToString(CORBA::Object_ptr obj){ if (obj && obj->_NP_is_pseudo()) { OMNIORB_THROW(MARSHAL,MARSHAL_InvalidIOR,CORBA::COMPLETED_NO); } omniObjRef* objref = obj ? obj->_PR_getobj() : 0; return omniObjRef::_toString(objref);}CORBA::Object_ptromniURI::stringToObject(const char* uri, unsigned int cycles){ if (!uri) OMNIORB_THROW(BAD_PARAM, BAD_PARAM_BadURIOther, CORBA::COMPLETED_NO); if (cycles > MAX_STRING_TO_OBJECT_CYCLES) { if (omniORB::trace(1)) { omniORB::logger l; l << "string_to_object reached recursion limit processing `" << uri << "'.\n"; } OMNIORB_THROW(BAD_PARAM, BAD_PARAM_BadURIOther, CORBA::COMPLETED_NO); } URIHandler* handler = 0; { omnivector<omniURI::URIHandler*>::iterator i = handlers.begin(); omnivector<omniURI::URIHandler*>::iterator last = handlers.end(); while (i != last) { if ((*i)->supports(uri)) { handler = *i; break; } i++; } } if (handler) return handler->toObject(uri, cycles); OMNIORB_THROW(BAD_PARAM, BAD_PARAM_BadSchemeName, CORBA::COMPLETED_NO); return 0;}CORBA::BooleanomniURI::uriSyntaxIsValid(const char* uri){ if (!uri) return 0; URIHandler* handler = 0; { omnivector<omniURI::URIHandler*>::iterator i = handlers.begin(); omnivector<omniURI::URIHandler*>::iterator last = handlers.end(); while (i != last) { if ((*i)->supports(uri)) { handler = *i; break; } i++; } } if (handler) return handler->syntaxIsValid(uri); return 0;}omniURI::URIHandler::~URIHandler() {}/////////////////////////////////////////////////////////////////////////////// IOR: format/////////////////////////////////////////////////////////////////////////////class iorURIHandler : public omniURI::URIHandler {public: CORBA::Boolean supports (const char* uri); CORBA::Object_ptr toObject (const char* uri, unsigned int); CORBA::Boolean syntaxIsValid(const char* uri);};CORBA::BooleaniorURIHandler::supports(const char* uri){ return ((uri[0] == 'I' || uri[0] == 'i') && (uri[1] == 'O' || uri[1] == 'o') && (uri[2] == 'R' || uri[2] == 'r') && (uri[3] == ':'));}CORBA::Object_ptriorURIHandler::toObject(const char* sior, unsigned int){ omniObjRef* objref = omniObjRef::_fromString(sior); if (!objref) return CORBA::Object::_nil(); return (CORBA::Object_ptr)objref->_ptrToObjRef(CORBA::Object::_PD_repoId);}CORBA::BooleaniorURIHandler::syntaxIsValid(const char* sior){ // Just check that the IOR is a sequence of hex digits int i; for (i=4; sior[i]; i++) { if (!((sior[i] >= '0' && sior[i] <= '9') || (sior[i] >= 'a' && sior[i] <= 'f') || (sior[i] >= 'A' && sior[i] <= 'F'))) return 0; } if (i == 4 || i % 2) { // No digits, or odd number return 0; } return 1;}/////////////////////////////////////////////////////////////////////////////// corbaloc: format/////////////////////////////////////////////////////////////////////////////class corbalocURIHandler : public omniURI::URIHandler {public: CORBA::Boolean supports (const char* uri); CORBA::Object_ptr toObject (const char* uri, unsigned int cycles); CORBA::Boolean syntaxIsValid(const char* uri); // This function actually does the work static CORBA::Object_ptr locToObject(const char*& c, unsigned int cycles, const char* def_key = 0); class ObjAddr { public: ObjAddr() : next_(0) {} virtual ~ObjAddr() {} static ObjAddr* parse(const char*& c); enum AddrKind { rir, iiop, uiop, ssliop }; virtual AddrKind kind() = 0; ObjAddr* next_; }; class ObjAddrList { public: ObjAddrList() : head_(0), tail_(0) {} ~ObjAddrList() { ObjAddr *c, *n; for (c = head_; c; c = n) { n = c->next_; delete c; } } void append(ObjAddr* addr) { if (head_) { tail_->next_ = addr; tail_ = addr; } else { head_ = addr; tail_ = addr; } } ObjAddr* head_; ObjAddr* tail_; }; class RirObjAddr : public ObjAddr { public: RirObjAddr(const char*& c) {}; virtual ~RirObjAddr() {}; ObjAddr::AddrKind kind() { return ObjAddr::rir; } }; class IiopObjAddr : public ObjAddr { public: IiopObjAddr(const char*& c); virtual ~IiopObjAddr() {}; ObjAddr::AddrKind kind() { return ObjAddr::iiop; } CORBA::Char minver() { return minver_; } CORBA::Char majver() { return majver_; } const char* host() { return (const char*)host_; } CORBA::UShort port() { return port_; } private: CORBA::Char majver_; CORBA::Char minver_; CORBA::String_var host_; CORBA::UShort port_; }; class SsliopObjAddr : public IiopObjAddr { public: SsliopObjAddr(const char*& c) : IiopObjAddr(c) {}; ObjAddr::AddrKind kind() { return ObjAddr::ssliop; } private: }; class UiopObjAddr : public ObjAddr { public: UiopObjAddr(const char*& c); virtual ~UiopObjAddr() {}; ObjAddr::AddrKind kind() { return ObjAddr::uiop; } CORBA::Char minver() { return minver_; } CORBA::Char majver() { return majver_; } const char* filename() { return (const char*)filename_; } private: CORBA::Char majver_; CORBA::Char minver_; CORBA::String_var filename_; }; // Object containing all the parsed data for a corbaloc: class Parsed { public: Parsed(const char*& c, const char* def_key); ~Parsed() {}; ObjAddrList addrList_; unsigned int addr_count_; CORBA::Boolean is_rir_; CORBA::String_var key_; unsigned int key_size_; };};CORBA::BooleancorbalocURIHandler::supports(const char* uri){ return !strncmp(uri, "corbaloc:", 9);}CORBA::Object_ptrcorbalocURIHandler::toObject(const char* uri, unsigned int cycles){ const char* c = uri + 9;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -