2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
24 * Interprocess remoting engine.
28 #include "exceptions.h"
29 #include "ServiceProvider.h"
30 #include "remoting/ListenerService.h"
32 #include <xercesc/dom/DOM.hpp>
34 using namespace shibsp;
35 using namespace xmltooling;
36 using namespace xercesc;
40 SHIBSP_DLLLOCAL PluginManager<ListenerService,string,const DOMElement*>::Factory TCPListenerServiceFactory;
42 SHIBSP_DLLLOCAL PluginManager<ListenerService,string,const DOMElement*>::Factory UnixListenerServiceFactory;
46 void SHIBSP_API shibsp::registerListenerServices()
48 SPConfig& conf=SPConfig::getConfig();
49 conf.ListenerServiceManager.registerFactory(TCP_LISTENER_SERVICE, TCPListenerServiceFactory);
51 conf.ListenerServiceManager.registerFactory(UNIX_LISTENER_SERVICE, UnixListenerServiceFactory);
63 ListenerService::ListenerService()
67 ListenerService::~ListenerService()
71 Remoted* ListenerService::regListener(const char* address, Remoted* listener)
74 map<string,Remoted*>::const_iterator i=m_listenerMap.find(address);
75 if (i!=m_listenerMap.end())
77 m_listenerMap[address]=listener;
78 Category::getInstance(SHIBSP_LOGCAT".Listener").info("registered remoted message endpoint (%s)",address);
82 bool ListenerService::unregListener(const char* address, Remoted* current, Remoted* restore)
84 map<string,Remoted*>::const_iterator i=m_listenerMap.find(address);
85 if (i!=m_listenerMap.end() && i->second==current) {
87 m_listenerMap[address]=restore;
89 m_listenerMap.erase(address);
90 Category::getInstance(SHIBSP_LOGCAT".Listener").info("unregistered remoted message endpoint (%s)",address);
96 Remoted* ListenerService::lookup(const char *address) const
98 map<string,Remoted*>::const_iterator i=m_listenerMap.find(address);
99 return (i==m_listenerMap.end()) ? nullptr : i->second;
102 void ListenerService::receive(DDF &in, ostream& out)
105 throw ListenerException("Incoming message with no destination address rejected.");
106 else if (!strcmp("ping",in.name())) {
107 DDF outmsg=DDF(nullptr).integer(in.integer() + 1);
108 DDFJanitor jan(outmsg);
112 // Two stage lookup, on the listener itself, and the SP interface.
113 ServiceProvider* sp = SPConfig::getConfig().getServiceProvider();
115 Remoted* dest = lookup(in.name());
117 dest = sp->lookupListener(in.name());
119 throw ListenerException("No destination registered for incoming message addressed to ($1).", params(1,in.name()));
122 dest->receive(in, out);
125 bool ListenerService::init(bool force)
130 void ListenerService::term()