APIRegistration.cc

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2005-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 
00018 #include "APIRegistration.h"
00019 #include "bundling/Bundle.h"
00020 #include "bundling/BundleDaemon.h"
00021 #include "bundling/BundleList.h"
00022 
00023 namespace dtn {
00024 
00025 APIRegistration::APIRegistration(const oasys::Builder& builder)
00026     : Registration(builder)
00027 {
00028     bundle_list_ = new BlockingBundleList(logpath_);
00029 }
00030     
00031 APIRegistration::APIRegistration(u_int32_t regid,
00032                                  const EndpointIDPattern& endpoint,
00033                                  failure_action_t action,
00034                                  u_int32_t expiration,
00035                                  const std::string& script)
00036     : Registration(regid, endpoint, action, expiration, script)
00037 {
00038     bundle_list_ = new BlockingBundleList(logpath_);
00039 }
00040 
00041 APIRegistration::~APIRegistration()
00042 {
00043     delete bundle_list_;
00044 }
00045 
00046 void
00047 APIRegistration::deliver_bundle(Bundle* bundle)
00048 {
00049     if (!active() && (failure_action_ == DROP)) {
00050         log_info("deliver_bundle: "
00051                  "dropping bundle id %d for passive registration %d (%s)",
00052                  bundle->bundleid_, regid_, endpoint_.c_str());
00053         
00054         // post an event saying we "delivered" it
00055         BundleDaemon::post(new BundleDeliveredEvent(bundle, this));
00056         return;
00057     }
00058 
00059     if (!active() && (failure_action_ == EXEC)) {
00060         // this sure seems like a security hole, but what can you
00061         // do -- it's in the spec
00062         log_info("deliver_bundle: "
00063                  "running script '%s' for registration %d (%s)",
00064                  script_.c_str(), regid_, endpoint_.c_str());
00065         
00066         system(script_.c_str());
00067         // fall through
00068     }
00069 
00070     log_info("deliver_bundle: queuing bundle id %d for %s delivery to %s",
00071              bundle->bundleid_,
00072              active() ? "active" : "deferred",
00073              endpoint_.c_str());
00074 
00075     if (BundleDaemon::instance()->params_.test_permuted_delivery_) {
00076         bundle_list_->insert_random(bundle);
00077     } else {
00078         bundle_list_->push_back(bundle);
00079     }
00080 }
00081 
00082 
00083 } // namespace dtn

Generated on Thu Jun 7 16:56:48 2007 for DTN Reference Implementation by  doxygen 1.5.1