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