00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <oasys/util/StringUtils.h>
00019
00020 #include "LoggingRegistration.h"
00021 #include "Registration.h"
00022 #include "bundling/Bundle.h"
00023 #include "bundling/BundleEvent.h"
00024 #include "bundling/BundleDaemon.h"
00025 #include "bundling/BundleList.h"
00026 #include "storage/GlobalStore.h"
00027
00028 namespace dtn {
00029
00030 LoggingRegistration::LoggingRegistration(const EndpointIDPattern& endpoint)
00031 : Registration(GlobalStore::instance()->next_regid(),
00032 endpoint, Registration::DEFER, 0)
00033 {
00034 logpathf("/dtn/reg/logging/%d", regid_);
00035 set_active(true);
00036
00037 log_info("new logging registration on endpoint %s", endpoint.c_str());
00038 }
00039
00040 void
00041 LoggingRegistration::deliver_bundle(Bundle* b)
00042 {
00043
00044
00045 oasys::StringBuffer buf;
00046 b->format_verbose(&buf);
00047 log_multiline(oasys::LOG_ALWAYS, buf.c_str());
00048
00049
00050
00051 size_t len = 128;
00052 size_t payload_len = b->payload_.length();
00053 if (payload_len < len) {
00054 len = payload_len;
00055 }
00056
00057 u_char payload_buf[payload_len];
00058 const u_char* data = b->payload_.read_data(0, len, payload_buf);
00059
00060 if (oasys::str_isascii(data, len)) {
00061 log_always(" payload (ascii): length %zu '%.*s'",
00062 payload_len, (int)len, data);
00063 } else {
00064 std::string hex;
00065 oasys::hex2str(&hex, data, len);
00066 len *= 2;
00067 if (len > 128)
00068 len = 128;
00069 log_always(" payload (binary): length %zu %.*s",
00070 payload_len, (int)len, hex.data());
00071 }
00072
00073
00074 BundleDaemon::post(new BundleDeliveredEvent(b, this));
00075 }
00076
00077 }