00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <vos/corelibs/vos/vos.hh>
00019 #include <vos/metaobjects/property/property.hh>
00020 #include "gateway.hh"
00021
00022
00023 Gateway::Gateway(MetaObject* s) : MetaObject(s)
00024 {
00025 accessControl = &NoPropertyAccessControl::static_;
00026 }
00027
00028
00029 Gateway::~Gateway() {
00030 }
00031
00032
00033 void Gateway::setPropertyAccessControl(PropertyAccessControl* ac) {
00034 accessControl = ac;
00035 }
00036
00037 PropertyAccessControl* Gateway::getPropertyAccessControl() {
00038 return accessControl;
00039 }
00040
00041 LocalGateway::LocalGateway(MetaObject* s) : Gateway(s), MetaObject(s)
00042 {
00043 addMessageHandler<LocalGateway>("request-forward", this, &LocalGateway::handleRequestForward);
00044 accessControl = &NoPropertyAccessControl::static_;
00045 }
00046
00047 LocalGateway::~LocalGateway() {
00048 }
00049
00050
00051
00052 void LocalGateway::initialize(PropertyAccessControl* ac) {
00053 accessControl = ac;
00054 initialize();
00055 }
00056
00057 void LocalGateway::initialize() {
00058
00059 vRef<LocalSite> localsite = Site::getDefaultPeer();
00060 }
00061
00062 RemoteGateway::RemoteGateway(MetaObject* s) : Gateway(s), MetaObject(s)
00063 {
00064
00065 }
00066
00067 RemoteGateway::~RemoteGateway() {
00068 }
00069
00070
00071
00072 const string Gateway::getType() {
00073 return string("misc:gateway");
00074 }
00075
00076
00077 void Gateway::registerExtenders() {
00078 static bool done = false;
00079 if(! done) {
00080 LocalSite::addLocalObjectExtension(typeid(LocalGateway).name(), &LocalGateway::new_LocalGateway);
00081 LocalSite::addLocalObjectExtension(typeid(Gateway).name(), &LocalGateway::new_LocalGateway);
00082 LocalSite::addLocalObjectExtension("misc:gateway", &LocalGateway::new_LocalGateway);
00083 RemoteSite::addRemoteObjectExtension(typeid(RemoteGateway).name(), &RemoteGateway::new_RemoteGateway);
00084 RemoteSite::addRemoteObjectExtension(typeid(Gateway).name(), &RemoteGateway::new_RemoteGateway);
00085 RemoteSite::addRemoteObjectExtension("misc:gateway", &RemoteGateway::new_RemoteGateway);
00086 done = true;
00087 }
00088 }
00089
00090
00091
00092
00093
00094
00095
00096 void LocalGateway::requestForward(LocalSocketSite* ls) {
00097
00098 }
00099
00100
00101
00102
00103 void LocalGateway::handleRequestForward(Message* m) {
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 try {
00121 vRef<Message> reply = new Message();
00122 LocalVobject::initReply(this, &reply, m, "request-forward-reply");
00123 vRef<Vobject> from = Vobject::findObjectFromRoot(m->getFrom());
00124
00125
00126
00127 from->sendMessage(&reply);
00128 } catch(Message::NoSuchFieldError e) {
00129
00130 }
00131 }
00132
00133
00134
00135
00136
00137 void RemoteGateway::requestForward(LocalSocketSite* ls) {
00138
00139
00140
00141
00142 vRef<Message> m = new Message();
00143 vRef<LocalSite> oursite = RemoteVobject::initFields(this, &m, "request-forward", true);
00144 sendMessage(&m);
00145 vRef<RemoteSite> site = dynamic_cast<RemoteSite&>(getSite());
00146 vRef<Message> n = ls->waitFor(m->getNonce(), &site);
00147
00148 try {
00149 URL u(ls->getURL());
00150 u.setHostAndPort(n->getField("sitename").value);
00151 ls->addHostAlias(u.getHostAndPort());
00152 ls->setPrimaryHostname(u.getHostAndPort());
00153 } catch(Message::NoSuchFieldError) {
00154 try {
00155 LOG("gateway", 1, "Could not get a forward: " << n->getField("error").value);
00156 } catch(Message::NoSuchFieldError) {
00157 }
00158 }
00159 }
00160
00161
00162
00163 MetaObject* LocalGateway::new_LocalGateway(MetaObject *s, const string& type) {
00164 LocalGateway* o = new LocalGateway(s);
00165 return o;
00166 }
00167
00168 MetaObject* RemoteGateway::new_RemoteGateway(MetaObject *s, const string& type) {
00169 return new RemoteGateway(s);
00170 }
00171
00172
00173
00174 void RemoteGateway::handleRequestForwardReply(Message* m) { }