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 "hostedavatar.hh"
00021
00022 NoHostedAvatarAccessControl NoHostedAvatarAccessControl::static_;
00023
00024
00025 HostedAvatar::HostedAvatar(MetaObject* s) : MetaObject(s)
00026 {
00027 accessControl = &NoPropertyAccessControl::static_;
00028 }
00029
00030
00031 HostedAvatar::~HostedAvatar() {
00032 }
00033
00034
00035 void HostedAvatar::setPropertyAccessControl(PropertyAccessControl* ac) {
00036 accessControl = ac;
00037 }
00038
00039 PropertyAccessControl* HostedAvatar::getPropertyAccessControl() {
00040 return accessControl;
00041 }
00042
00043 LocalHostedAvatar::LocalHostedAvatar(MetaObject* s) : HostedAvatar(s), MetaObject(s), hostedavatarAC(0)
00044 {
00045 addMessageHandler<LocalHostedAvatar>("policy:request-avatar", this, &LocalHostedAvatar::handleRequestAvatar);
00046 accessControl = &NoPropertyAccessControl::static_;
00047 }
00048
00049 LocalHostedAvatar::~LocalHostedAvatar() {
00050 }
00051
00052
00053
00054 void LocalHostedAvatar::initialize(PropertyAccessControl* ac) {
00055 accessControl = ac;
00056 initialize();
00057 }
00058
00059 void LocalHostedAvatar::initialize() {
00060
00061 vRef<LocalSite> localsite = Site::getDefaultPeer();
00062 }
00063
00064 RemoteHostedAvatar::RemoteHostedAvatar(MetaObject* s) : HostedAvatar(s), MetaObject(s)
00065 {
00066 addUpdateHandler<RemoteHostedAvatar>("policy:request-avatar-reply", this, &RemoteHostedAvatar::handleRequestAvatarReply);
00067
00068 }
00069
00070 RemoteHostedAvatar::~RemoteHostedAvatar() {
00071 }
00072
00073
00074
00075 const string HostedAvatar::getType() {
00076 return string("policy:hosted-avatar");
00077 }
00078
00079
00080 void HostedAvatar::registerExtenders() {
00081 static bool done = false;
00082 if(! done) {
00083 LocalSite::addLocalObjectExtension(typeid(LocalHostedAvatar).name(), &LocalHostedAvatar::new_LocalHostedAvatar);
00084 LocalSite::addLocalObjectExtension(typeid(HostedAvatar).name(), &LocalHostedAvatar::new_LocalHostedAvatar);
00085 LocalSite::addLocalObjectExtension("policy:hosted-avatar", &LocalHostedAvatar::new_LocalHostedAvatar);
00086 RemoteSite::addRemoteObjectExtension(typeid(RemoteHostedAvatar).name(), &RemoteHostedAvatar::new_RemoteHostedAvatar);
00087 RemoteSite::addRemoteObjectExtension(typeid(HostedAvatar).name(), &RemoteHostedAvatar::new_RemoteHostedAvatar);
00088 RemoteSite::addRemoteObjectExtension("policy:hosted-avatar", &RemoteHostedAvatar::new_RemoteHostedAvatar);
00089 done = true;
00090 }
00091 }
00092
00093
00094
00095 string HostedAvatar::getHostedAvatarIsRequired() {
00096 string s;
00097 vRef<Vobject> v = findObject("policy:hosted-avatar-is-required");
00098 meta_cast<Property&>(*v).read(s);
00099 return s;
00100 }
00101
00102 string HostedAvatar::getHostedAvatarIsRequiredDatatype() {
00103 string s;
00104 vRef<Vobject> v = findObject("policy:hosted-avatar-is-required");
00105 s = meta_cast<Property&>(*v).getDataType();
00106 return s;
00107 }
00108
00109 void HostedAvatar::setHostedAvatarIsRequired(const string& value, const string& datatype, PropertyAccessControl* ac) {
00110 if(ac == NULL)
00111 ac = accessControl;
00112 Property::setProperty(*this, "policy:hosted-avatar-is-required", value, datatype, ac);
00113 }
00114
00115 Vobject* HostedAvatar::getHostedAvatarIsRequiredObject() {
00116 return &findObject("policy:hosted-avatar-is-required");
00117 }
00118
00119 void HostedAvatar::setHostedAvatarIsRequiredObject(Vobject* newobj) {
00120 try {
00121 vRef<ParentChildRelation> pcr = findChild("policy:hosted-avatar-is-required");
00122 setChild(pcr->position, "policy:hosted-avatar-is-required", newobj);
00123 } catch (NoSuchObjectError) {
00124 insertChild(-1, "policy:hosted-avatar-is-required", newobj);
00125 }
00126 }
00127
00128
00129
00130
00131
00132 Vobject& LocalHostedAvatar::doRequestAvatar(Vobject* myavatar) {
00133 throw AccessControlError("Not implemented");
00134 }
00135
00136
00137
00138
00139
00140 void LocalHostedAvatar::handleRequestAvatar(Message* m) {
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 try {
00153 vRef<Message> reply = new Message();
00154 LocalVobject::initReply(this, &reply, m, "policy:request-avatar-reply");
00155 vRef<Vobject> from = Vobject::findObjectFromRoot(m->getFrom());
00156 vRef<Vobject> suppliedavatar;
00157
00158 try {
00159 suppliedavatar = Vobject::findObjectFromRoot(m->getField("myavatar").value);
00160 } catch(Message::NoSuchFieldError){
00161 } catch(NoSuchObjectError){
00162 }
00163
00164 try {
00165 if(hostedavatarAC) {
00166 if(hostedavatarAC->checkRequestAvatarPermission(*from, &suppliedavatar)) {
00167 vRef<Vobject> v = doRequestAvatar(&suppliedavatar);
00168 reply->insertField(-1, "path", v->getURL().getString());
00169 }
00170 } else {
00171 LOG("hostedavatar", 1, "Warning: HostedAvatar vobject " << getURL().getString() << " does not have an access control! Failing by default");
00172 throw AccessControlError("This vobject is not initialized properly");
00173 }
00174 } catch(AccessControlError e) {
00175 reply->insertField(-1, "error", e.what());
00176 }
00177
00178 from->sendMessage(&reply);
00179 } catch(Message::NoSuchFieldError e) {
00180
00181 }
00182
00183 }
00184
00185
00186
00187
00188
00189 Vobject& RemoteHostedAvatar::doRequestAvatar(Vobject* myavatar) {
00190
00191
00192
00193
00194 vRef<Message> m = new Message();
00195 vRef<LocalSite> ls = RemoteVobject::initFields(this, &m, "policy:request-avatar", true);
00196 if(myavatar) {
00197 m->insertField(-1, "myavatar", myavatar->getURL().getString());
00198 }
00199
00200 sendMessage(&m);
00201 vRef<RemoteSite> site = dynamic_cast<RemoteSite&>(getSite());
00202 vRef<Message> n = ls->waitFor(m->getNonce(), &site);
00203 try {
00204 string path = n->getField("path").value;
00205 Vobject& v = Vobject::findObjectFromRoot(path);
00206 return v;
00207 } catch(Message::NoSuchFieldError e) {
00208 try {
00209 throw AccessControlError(n->getField("error").value);
00210 } catch(Message::NoSuchFieldError) {
00211 throw RemoteError("Didn't get back an expected field");
00212 }
00213 } catch(NoSuchObjectError e) {
00214 throw RemoteError("The object in path field did not exist.");
00215 } catch(NoSuchSiteError e) {
00216 throw RemoteError("The object in path field did not exist.");
00217 } catch(URL::BadURLError e) {
00218 throw RemoteError("The object path field was maelformed.");
00219 } catch(...) {
00220 throw RemoteError("Something bad just happened.");
00221 }
00222 }
00223
00224
00225
00226
00227 MetaObject* LocalHostedAvatar::new_LocalHostedAvatar(MetaObject *s, const string& type) {
00228 LocalHostedAvatar* o = new LocalHostedAvatar(s);
00229 return o;
00230 }
00231
00232 MetaObject* RemoteHostedAvatar::new_RemoteHostedAvatar(MetaObject *s, const string& type) {
00233 return new RemoteHostedAvatar(s);
00234 }
00235
00236
00237
00238 void RemoteHostedAvatar::handleRequestAvatarReply(Message* m) { }