Ejemplo n.º 1
0
//------------------------------------------------------------------------------
// Name: createMenu
// Desc:
//------------------------------------------------------------------------------
QMenu *QGmailNotifier::createMenu() {
	QMenu *const menu = new QMenu(this);
	QAction *const view		= menu->addAction(tr("View Inbox"), this, SLOT(doView()));
	menu->addAction(tr("Compose a Message"), this, SLOT(doCompose()));
	menu->addAction(tr("Check Mail Now"), this, SLOT(doCheck()));
	menu->addAction(tr("Tell me Again..."), this, SLOT(doTell()));
	menu->addAction(tr("Options"), this, SLOT(doOptions()));
	menu->addAction(tr("About"), this, SLOT(doAbout()));

	if(currentMails_.size() != 0) {

		menu->addSeparator();
		QMenu *const convsations = menu->addMenu(tr("Unread Conversations"));

		QSettings settings;

		const int maxCons = settings.value("max_conversations", 10).value<int>();

		int index = 0;
		Q_FOREACH(GMailEntry entry, currentMails_) {
			QAction *const action = convsations->addAction(entry.author_name + " : " + entry.title, this, SLOT(readConversation()));
			action->setData(index++);
			if(index >= maxCons) {
				break;
			}
		}
Ejemplo n.º 2
0
int QTshotWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QMAINWINDOW::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: doHelp(); break;
        case 1: doQuit(); break;
        case 2: doOpen(); break;
        case 3: doNew(); break;
        case 4: doSave(); break;
        case 5: doData(); break;
        case 6: doExport(); break;
        case 7: doExportOK(); break;
        case 8: doOptions(); break;
        case 9: doToggle(); break;
        case 10: doCollapse(); break;
        case 11: doPlan(); break;
        case 12: doExtended(); break;
        case 13: do3D(); break;
        case 14: doCrossSection((*reinterpret_cast< DBlock*(*)>(_a[1])),(*reinterpret_cast< bool(*)>(_a[2])),(*reinterpret_cast< bool(*)>(_a[3]))); break;
        case 15: doCrossSection((*reinterpret_cast< DBlock*(*)>(_a[1])),(*reinterpret_cast< bool(*)>(_a[2]))); break;
        case 16: value_changed((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
        case 17: double_clicked((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2])),(*reinterpret_cast< int(*)>(_a[3])),(*reinterpret_cast< const QPoint(*)>(_a[4]))); break;
        }
        _id -= 18;
    }
    return _id;
}
Ejemplo n.º 3
0
int
main(int argc, const char** argv)
{
    int i;
    int ret;
    dtn_handle_t handle;
    dtn_endpoint_id_t source_eid;
    dtn_reg_info_t reginfo;
    dtn_reg_id_t regid;
    dtn_bundle_spec_t ping_spec;
    dtn_bundle_spec_t reply_spec;
    dtn_bundle_payload_t ping_payload;
    ping_payload_t payload_contents;
    ping_payload_t recv_contents;
    dtn_bundle_payload_t reply_payload;
    dtn_bundle_status_report_t* sr_data;
    dtn_bundle_id_t bundle_id;
    int debug = 1;
    char demux[64];
    int dest_len = 0;
    struct timeval send_times[MAX_PINGS_IN_FLIGHT];
    dtn_timestamp_t creation_times[MAX_PINGS_IN_FLIGHT];
    struct timeval now, recv_start, recv_end;
    u_int32_t nonce;
    u_int32_t seqno = 0;
    int timeout;

    // force stdout to always be line buffered, even if output is
    // redirected to a pipe or file
    setvbuf(stdout, (char *)NULL, _IOLBF, 0);
    
    doOptions(argc, argv);

    memset(&ping_spec, 0, sizeof(ping_spec));

    gettimeofday(&now, 0);
    srand(now.tv_sec);
    nonce = rand();
    
    // open the ipc handle
    int err = dtn_open(&handle);
    if (err != DTN_SUCCESS) {
        fprintf(stderr, "fatal error opening dtn handle: %s\n",
                dtn_strerror(err));
        exit(1);
    }

    // make sure they supplied a valid destination eid or
    // "localhost", in which case we just use the local daemon
    if (strcmp(dest_eid_str, "localhost") == 0) {
        dtn_build_local_eid(handle, &ping_spec.dest, "ping");
        
    } else {
        if (dtn_parse_eid_string(&ping_spec.dest, dest_eid_str)) {
            fprintf(stderr, "invalid destination eid string '%s'\n",
                    dest_eid_str);
            exit(1);
        }
    }

    dest_len = strlen(ping_spec.dest.uri);
    if ((dest_len < 4) ||
        (strcmp(ping_spec.dest.uri + dest_len - 4, "ping") != 0))
    {
        fprintf(stderr, "\nWARNING: ping destination does not end in \"ping\"\n\n");
    }
    
    // if the user specified a source eid, register on it.
    // otherwise, build a local eid based on the configuration of
    // our dtn router plus the demux string
    snprintf(demux, sizeof(demux), "/ping.%d", getpid());
    if (source_eid_str[0] != '\0') {
        if (dtn_parse_eid_string(&source_eid, source_eid_str)) {
            fprintf(stderr, "invalid source eid string '%s'\n",
                    source_eid_str);
            exit(1);
        }
    } else {
        dtn_build_local_eid(handle, &source_eid, demux);
    }

    // set the source and replyto eids in the bundle spec
    if (debug) printf("source_eid [%s]\n", source_eid.uri);
    dtn_copy_eid(&ping_spec.source, &source_eid);
    dtn_copy_eid(&ping_spec.replyto, &source_eid);
    
    // now create a new registration based on the source
    memset(&reginfo, 0, sizeof(reginfo));
    dtn_copy_eid(&reginfo.endpoint, &source_eid);
    reginfo.flags = DTN_REG_DEFER;
    reginfo.regid = DTN_REGID_NONE;
    reginfo.expiration = 0;
    if ((ret = dtn_register(handle, &reginfo, &regid)) != 0) {
        fprintf(stderr, "error creating registration: %d (%s)\n",
                ret, dtn_strerror(dtn_errno(handle)));
        exit(1);
    }    
    if (debug) printf("dtn_register succeeded, regid %d\n", regid);

    // set the expiration time and request deletion status reports
    ping_spec.expiration = expiration;
    ping_spec.dopts = DOPTS_DELETE_RCPT;

    printf("PING [%s] (expiration %u)...\n", ping_spec.dest.uri, expiration);
    if (interval == 0) {
        printf("WARNING: zero second interval will result in flooding pings!!\n");
    }
    
    // loop, sending pings and polling for activity
    for (i = 0; count == 0 || i < count; ++i) {
        gettimeofday(&send_times[seqno], NULL);
        
        // fill in a short payload string, a nonce, and a sequence number
        // to verify the echo feature and make sure we're not getting
        // duplicate responses or ping responses from another app
        memcpy(&payload_contents.ping, PING_STR, 8);
        payload_contents.seqno = seqno;
        payload_contents.nonce = nonce;
        payload_contents.time = send_times[seqno].tv_sec;
        
        memset(&ping_payload, 0, sizeof(ping_payload));
        dtn_set_payload(&ping_payload, DTN_PAYLOAD_MEM,
                        (char*)&payload_contents, sizeof(payload_contents));
        
        memset(&bundle_id, 0, sizeof(bundle_id));
        if ((ret = dtn_send(handle, regid, &ping_spec, &ping_payload,
                            &bundle_id)) != 0) {
            fprintf(stderr, "error sending bundle: %d (%s)\n",
                    ret, dtn_strerror(dtn_errno(handle)));
            exit(1);
        }
        
        creation_times[seqno] = bundle_id.creation_ts;

        memset(&reply_spec, 0, sizeof(reply_spec));
        memset(&reply_payload, 0, sizeof(reply_payload));

        // now loop waiting for replies / status reports until it's
        // time to send again, adding twice the expiration time if we
        // just sent the last ping
        timeout = interval * 1000;
        if (i == count - 1)
            timeout += expiration * 2000;
        
        do {
            gettimeofday(&recv_start, 0);
            if ((ret = dtn_recv(handle, &reply_spec,
                                DTN_PAYLOAD_MEM, &reply_payload, timeout)) < 0)
            {
                if (dtn_errno(handle) == DTN_ETIMEOUT) {
                    break; // time to send again
                }
                
                fprintf(stderr, "error getting ping reply: %d (%s)\n",
                        ret, dtn_strerror(dtn_errno(handle)));
                exit(1);
            }
            gettimeofday(&recv_end, 0);
            
            if (reply_payload.status_report != NULL)
            {
                sr_data = reply_payload.status_report;
                if (sr_data->flags != STATUS_DELETED) {
                    fprintf(stderr, "(bad status report from %s: flags 0x%x)\n",
                            reply_spec.source.uri, sr_data->flags);
                    goto next;
                }

                // find the seqno corresponding to the original
                // transmission time in the status report
                int j = 0;
                for (j = 0; j < MAX_PINGS_IN_FLIGHT; ++j) {
                    if (creation_times[j].secs  ==
                            sr_data->bundle_id.creation_ts.secs &&
                        creation_times[j].seqno ==
                            sr_data->bundle_id.creation_ts.seqno)
                    {
                        printf("bundle deleted at [%s] (%s): seqno=%d, time=%ld ms\n",
                               reply_spec.source.uri,
                               dtn_status_report_reason_to_str(sr_data->reason),
                               j, TIMEVAL_DIFF_MSEC(recv_end, send_times[j]));
                        goto next;
                    }
                }

                printf("bundle deleted at [%s] (%s): ERROR: can't find seqno\n",
                       reply_spec.source.uri, 
                       dtn_status_report_reason_to_str(sr_data->reason));
            }
            else {
                if (reply_payload.buf.buf_len != sizeof(ping_payload_t))
                {
                    printf("%d bytes from [%s]: ERROR: length != %zu\n",
                           reply_payload.buf.buf_len,
                           reply_spec.source.uri,
                           sizeof(ping_payload_t));
                    goto next;
                }

                memcpy(&recv_contents, reply_payload.buf.buf_val,
                       sizeof(recv_contents));
                
                if (recv_contents.seqno > MAX_PINGS_IN_FLIGHT)
                {
                    printf("%d bytes from [%s]: ERROR: invalid seqno %d\n",
                           reply_payload.buf.buf_len,
                           reply_spec.source.uri,
                           recv_contents.seqno);
                    goto next;
                }

                if (recv_contents.nonce != nonce)
                {
                    printf("%d bytes from [%s]: ERROR: invalid nonce %u != %u\n",
                           reply_payload.buf.buf_len,
                           reply_spec.source.uri,
                           recv_contents.nonce, nonce);
                    goto next;
                }

                if (recv_contents.time != (u_int32_t)send_times[recv_contents.seqno].tv_sec)
                {
                    printf("%d bytes from [%s]: ERROR: time mismatch -- "
                           "seqno %u reply time %u != send time %lu\n",
                           reply_payload.buf.buf_len,
                           reply_spec.source.uri,
                           recv_contents.seqno,
                           recv_contents.time,
                           (long unsigned int)send_times[recv_contents.seqno].tv_sec);
                    goto next;
                }
                
                printf("%d bytes from [%s]: '%.*s' seqno=%d, time=%ld ms\n",
                       reply_payload.buf.buf_len,
                       reply_spec.source.uri,
                       (u_int)strlen(PING_STR),
                       reply_payload.buf.buf_val,
                       recv_contents.seqno,
                       TIMEVAL_DIFF_MSEC(recv_end,
                                         send_times[recv_contents.seqno]));
                fflush(stdout);
            }
next:
            dtn_free_payload(&reply_payload);
            timeout -= TIMEVAL_DIFF_MSEC(recv_end, recv_start);

            // once we get status from all the pings we're supposed to
            // send, we're done
            reply_count++;
            if (count != 0 && reply_count == count) {
                break;
            }

        } while (timeout > 0);
        
        seqno++;
        seqno %= MAX_PINGS_IN_FLIGHT;
    }

    dtn_close(handle);

    return 0;
}
Ejemplo n.º 4
0
bool HttpServlet::start()
{
	socket_stream* in;
	socket_stream* out;
	bool cgi_mode;

	bool first = first_;
	if (first_)
		first_ = false;

	if (stream_ == NULL)
	{
		// 数据流为空,则当 CGI 模式处理,将标准输入输出
		// 作为数据流
		in = NEW socket_stream();
		in->open(ACL_VSTREAM_IN);

		out = NEW socket_stream();
		out->open(ACL_VSTREAM_OUT);
		cgi_mode = true;
	}
	else
	{
		in = out = stream_;
		cgi_mode = false;
	}

	// 在 HTTP 长连接重复请求情况下,以防万一,需要首先删除请求/响应对象
	delete req_;
	delete res_;

	res_ = NEW HttpServletResponse(*out);
	req_ = NEW HttpServletRequest(*res_, *session_, *in, local_charset_,
			 parse_body_enable_, parse_body_limit_);

	// 设置 HttpServletRequest 对象
	res_->setHttpServletRequest(req_);

	if (rw_timeout_ >= 0)
		req_->setRwTimeout(rw_timeout_);

	res_->setCgiMode(cgi_mode);

	string method_s(32);
	http_method_t method = req_->getMethod(&method_s);

	// 根据请求的值自动设定是否需要保持长连接
	if (!cgi_mode)
		res_->setKeepAlive(req_->isKeepAlive());

	bool  ret;

	switch (method)
	{
	case HTTP_METHOD_GET:
		if (upgradeWebsocket(*req_, *res_))
		{
			if (res_->sendHeader() == false)
			{
				logger_error("sendHeader error!");
				return false;
			}
			ret = doWebsocket(*req_, *res_);
		} else
			ret = doGet(*req_, *res_);
		break;
	case HTTP_METHOD_POST:
		ret = doPost(*req_, *res_);
		break;
	case HTTP_METHOD_PUT:
		ret = doPut(*req_, *res_);
		break;
	case HTTP_METHOD_CONNECT:
		ret = doConnect(*req_, *res_);
		break;
	case HTTP_METHOD_PURGE:
		ret = doPurge(*req_, *res_);
		break;
	case HTTP_METHOD_DELETE:
		ret = doDelete(*req_, *res_);
		break;
	case  HTTP_METHOD_HEAD:
		ret = doHead(*req_, *res_);
		break;
	case HTTP_METHOD_OPTION:
		ret = doOptions(*req_, *res_);
		break;
	case HTTP_METHOD_PROPFIND:
		ret = doPropfind(*req_, *res_);
		break;
	case HTTP_METHOD_OTHER:
		ret = doOther(*req_, *res_, method_s.c_str());
		break;
	default:
		ret = false; // 有可能是IO失败或未知方法
		if (req_->getLastError() == HTTP_REQ_ERR_METHOD)
			doUnknown(*req_, *res_);
		else if (first)
			doError(*req_, *res_);
		break;
	}

	if (in != out)
	{
		// 如果是标准输入输出流,则需要先将数据流与标准输入输出解绑,
		// 然后才能释放数据流对象,数据流内部会自动判断流句柄合法性
		// 这样可以保证与客户端保持长连接
		in->unbind();
		out->unbind();
		delete in;
		delete out;
	}

	return ret;
}
Ejemplo n.º 5
0
bool HttpServlet::doRun(dbuf_pool* dbuf)
{
	socket_stream* in;
	socket_stream* out;
	bool cgi_mode;

	bool first = first_;
	if (first_)
		first_ = false;

	if (stream_ == NULL)
	{
		// 数据流为空,则当 CGI 模式处理,将标准输入输出
		// 作为数据流
		in = NEW socket_stream();
		in->open(ACL_VSTREAM_IN);

		out = NEW socket_stream();
		out->open(ACL_VSTREAM_OUT);
		cgi_mode = true;
	}
	else
	{
		in = out = stream_;
		cgi_mode = false;
	}

	// req/res 采用栈变量,减少内存分配次数

	HttpServletResponse res(*out, dbuf);
	HttpServletRequest req(res, *session_, *in, local_charset_,
		parse_body_enable_, parse_body_limit_, dbuf);

	// 设置 HttpServletRequest 对象
	res.setHttpServletRequest(&req);

	if (rw_timeout_ >= 0)
		req.setRwTimeout(rw_timeout_);

	res.setCgiMode(cgi_mode);

	string method_s(32);
	http_method_t method = req.getMethod(&method_s);

	// 根据请求的值自动设定是否需要保持长连接
	if (!cgi_mode)
		res.setKeepAlive(req.isKeepAlive());

	bool  ret;

	switch (method)
	{
	case HTTP_METHOD_GET:
		ret = doGet(req, res);
		break;
	case HTTP_METHOD_POST:
		ret = doPost(req, res);
		break;
	case HTTP_METHOD_PUT:
		ret = doPut(req, res);
		break;
	case HTTP_METHOD_CONNECT:
		ret = doConnect(req, res);
		break;
	case HTTP_METHOD_PURGE:
		ret = doPurge(req, res);
		break;
	case HTTP_METHOD_DELETE:
		ret = doDelete(req, res);
		break;
	case  HTTP_METHOD_HEAD:
		ret = doHead(req, res);
		break;
	case HTTP_METHOD_OPTION:
		ret = doOptions(req, res);
		break;
	case HTTP_METHOD_PROPFIND:
		ret = doPropfind(req, res);
		break;
	case HTTP_METHOD_OTHER:
		ret = doOther(req, res, method_s.c_str());
		break;
	default:
		ret = false; // 有可能是IO失败或未知方法
		if (req.getLastError() == HTTP_REQ_ERR_METHOD)
			doUnknown(req, res);
		else if (first)
			doError(req, res);
		break;
	}

	if (in != out)
	{
		// 如果是标准输入输出流,则需要先将数据流与标准输入输出解绑,
		// 然后才能释放数据流对象,数据流内部会自动判断流句柄合法性
		// 这样可以保证与客户端保持长连接
		in->unbind();
		out->unbind();
		delete in;
		delete out;
	}

	// 返回给上层调用者:true 表示继续保持长连接,否则表示需断开连接
	return ret && req.isKeepAlive()
		&& res.getHttpHeader().get_keep_alive();
}
Ejemplo n.º 6
0
UT_Error IE_Exp_EPUB::_writeDocument()
{
    UT_Error errOptions = doOptions();

    if (errOptions == UT_SAVE_CANCELLED) //see Bug 10840
    {
        return UT_SAVE_CANCELLED;
    }
    else if (errOptions != UT_OK) {
        return UT_ERROR;
    }

    m_root = gsf_outfile_zip_new(getFp(), NULL);

    if (m_root == NULL)
    {
        UT_DEBUGMSG(("ZIP output is null\n"));
        return UT_ERROR;
    }

    m_oebps = gsf_outfile_new_child(m_root, "OEBPS", TRUE);
    if (m_oebps == NULL)
    {
        UT_DEBUGMSG(("Can`t create oebps output object\n"));
        return UT_ERROR;
    }

    // mimetype must a first file in archive
    GsfOutput *mimetype = gsf_outfile_new_child_full(m_root, "mimetype", FALSE,
        "compression-level", 0, NULL);
    gsf_output_write(mimetype, strlen(EPUB_MIMETYPE),
            (const guint8*) EPUB_MIMETYPE);
    gsf_output_close(mimetype);

    // We need to create temporary directory to which
    // HTML plugin will export our document
    m_baseTempDir = UT_go_filename_to_uri(g_get_tmp_dir());
    m_baseTempDir += G_DIR_SEPARATOR_S;

    // To generate unique directory name we`ll use document UUID
    m_baseTempDir += getDoc()->getDocUUIDString();
    // We should delete any previous temporary data for this document to prevent
    // odd files appearing in the container
    UT_go_file_remove(m_baseTempDir.c_str(), NULL);
    UT_go_directory_create(m_baseTempDir.c_str(), NULL);

    if (writeContainer() != UT_OK)
    {
        UT_DEBUGMSG(("Failed to write container\n"));
        return UT_ERROR;
    }
    if (writeStructure() != UT_OK)
    {
        UT_DEBUGMSG(("Failed to write document structure\n"));
        return UT_ERROR;
    }
    if (writeNavigation() != UT_OK)
    {
        UT_DEBUGMSG(("Failed to write navigation\n"));
        return UT_ERROR;
    }
    if (package() != UT_OK)
    {
        UT_DEBUGMSG(("Failed to package document\n"));
        return UT_ERROR;
    }

    gsf_output_close(m_oebps);
    gsf_output_close(GSF_OUTPUT(m_root));
    
    // After doing all job we should delete temporary files
    UT_go_file_remove(m_baseTempDir.c_str(), NULL);
    return UT_OK;
}
Ejemplo n.º 7
0
int
main(int argc, const char** argv)
{
    int ret;
    dtn_handle_t handle;
    dtn_endpoint_id_t source_eid;
    dtn_endpoint_id_t replyto_eid;
    dtn_reg_info_t reginfo;
    dtn_reg_id_t regid;
    dtn_bundle_spec_t ping_spec;
    dtn_bundle_spec_t reply_spec;
    dtn_bundle_payload_t ping_payload;
    ping_payload_t payload_contents;
    ping_payload_t recv_contents;
    dtn_bundle_payload_t reply_payload;
    dtn_bundle_status_report_t* sr_data;
    dtn_bundle_id_t bundle_id;
    int debug = 1;
    char demux[64];
    int dest_len = 0;
    struct timeval send_time, now;
    u_int32_t nonce;
    int done;
    time_t clock;
    struct tm* tm_buf;
    
    // force stdout to always be line buffered, even if output is
    // redirected to a pipe or file
    setvbuf(stdout, (char *)NULL, _IOLBF, 0);
    
    doOptions(argc, argv);

    memset(&ping_spec, 0, sizeof(ping_spec));

    gettimeofday(&now, 0);
    srand(now.tv_sec);
    nonce = rand();
    
    // open the ipc handle
    int err = 0;
    if (api_IP_set) err = dtn_open_with_IP(api_IP,api_port,&handle);
    else err = dtn_open(&handle);

    if (err != DTN_SUCCESS) {
        fprintf(stderr, "fatal error opening dtn handle: %s\n",
                dtn_strerror(err));
        exit(1);
    }

    // make sure they supplied a valid destination eid or
    // "localhost", in which case we just use the local daemon
    if (strcmp(dest_eid_str, "localhost") == 0) {
        dtn_build_local_eid(handle, &ping_spec.dest, "ping");
        
    } else {
        if (dtn_parse_eid_string(&ping_spec.dest, dest_eid_str)) {
            fprintf(stderr, "invalid destination eid string '%s'\n",
                    dest_eid_str);
            exit(1);
        }
    }

    dest_len = strlen(ping_spec.dest.uri);
    if ((dest_len < 4) ||
        (strcmp(ping_spec.dest.uri + dest_len - 4, "ping") != 0))
    {
        fprintf(stderr, "\nWARNING: ping destination does not end in \"ping\"\n\n");
    }
    
    // if the user specified a source eid, register on it.
    // otherwise, build a local eid based on the configuration of
    // our dtn router plus the demux string
    snprintf(demux, sizeof(demux), "/traceroute.%d", getpid());
    if (source_eid_str[0] != '\0') {
        if (dtn_parse_eid_string(&source_eid, source_eid_str)) {
            fprintf(stderr, "invalid source eid string '%s'\n",
                    source_eid_str);
            exit(1);
        }
    } else {
        dtn_build_local_eid(handle, &source_eid, demux);
    }

    if (debug) printf("source_eid [%s]\n", source_eid.uri);
    dtn_copy_eid(&ping_spec.source, &source_eid);
    
    // Make the replyto EID
    if ( replyto_eid_str[0]!=0 ) {
        if (dtn_parse_eid_string(&replyto_eid, replyto_eid_str)) {
            fprintf(stderr, "invalid replyto eid string '%s'\n",
                    replyto_eid_str);
            exit(1);
        }
        dtn_copy_eid(&ping_spec.replyto, &replyto_eid);
        printf("using user-supplied replyto\n");
    } else {
        dtn_copy_eid(&ping_spec.replyto, &source_eid);
        printf("using default replyto\n");
    }

    // now create a new registration based on the source
    // if the replyto EID is unspecified or the same as the
    // source EID then we'll get status reports, otherwise
    // they'll go somewhere else.
    memset(&reginfo, 0, sizeof(reginfo));
    dtn_copy_eid(&reginfo.endpoint, &source_eid);
    reginfo.flags = DTN_REG_DROP;
    reginfo.regid = DTN_REGID_NONE;
    reginfo.expiration = 0;
    if ((ret = dtn_register(handle, &reginfo, &regid)) != 0) {
        fprintf(stderr, "error creating registration: %d (%s)\n",
                ret, dtn_strerror(dtn_errno(handle)));
        exit(1);
    }    
    if (debug) printf("dtn_register succeeded, regid %d\n", regid);

    // set the expiration time and request a bunch of status reports
    ping_spec.expiration = expiration;
    ping_spec.dopts = DOPTS_DELETE_RCPT |
                      DOPTS_RECEIVE_RCPT |
                      DOPTS_FORWARD_RCPT |
                      DOPTS_DELIVERY_RCPT;

    // loop, sending pings and polling for activity
    gettimeofday(&send_time, NULL);
        
    // fill in a short payload string, a nonce, and a sequence number
    // to verify the echo feature and make sure we're not getting
    // duplicate responses or ping responses from another app
    memcpy(&payload_contents.ping, PING_STR, 8);
    payload_contents.seqno = 0;
    payload_contents.nonce = nonce;
    payload_contents.time  = send_time.tv_sec;
        
    memset(&ping_payload, 0, sizeof(ping_payload));
    dtn_set_payload(&ping_payload, DTN_PAYLOAD_MEM,
                    (char*)&payload_contents, sizeof(payload_contents));
        
    memset(&bundle_id, 0, sizeof(bundle_id));
    if ((ret = dtn_send(handle, regid, &ping_spec, &ping_payload, &bundle_id)) != 0) {
        fprintf(stderr, "error sending bundle: %d (%s)\n",
                ret, dtn_strerror(dtn_errno(handle)));
        exit(1);
    }
        
    memset(&reply_spec, 0, sizeof(reply_spec));
    memset(&reply_payload, 0, sizeof(reply_payload));

    clock = time(&clock);
    tm_buf = gmtime(&clock);
    printf("%s: sent at %.*s UTC\n",
           ping_spec.source.uri, 24, asctime(tm_buf));
    
    // now loop waiting for replies / status reports until we're done
    done = 0;
    while (1) {
        int timeout = done ? wait_after_done * 1000 : -1;
        if ((ret = dtn_recv(handle, &reply_spec,
                            DTN_PAYLOAD_MEM, &reply_payload, timeout)) < 0)
        {
            if (done && dtn_errno(handle) == DTN_ETIMEOUT) {
                break;
            }
            fprintf(stderr, "error getting ping reply: %d (%s)\n",
                    ret, dtn_strerror(dtn_errno(handle)));
            exit(1);
        }

        gettimeofday(&now, 0);
            
        if (reply_payload.status_report != NULL)
        {
            sr_data = reply_payload.status_report;
            if (sr_data->flags & STATUS_RECEIVED)
            {
                clock = sr_data->receipt_ts.secs + DTNTIME_OFFSET;
                tm_buf = gmtime(&clock);
                printf("%s: received at %.*s UTC (%ld ms rtt)\n",
                       reply_spec.source.uri, 24, asctime(tm_buf),
                       TIMEVAL_DIFF_MSEC(now, send_time));
            }
            if (sr_data->flags & STATUS_FORWARDED)
            {
                clock = sr_data->forwarding_ts.secs + DTNTIME_OFFSET;
                tm_buf = gmtime(&clock);
                printf("%s: forwarded at %.*s UTC (%ld ms rtt)\n",
                       reply_spec.source.uri, 24, asctime(tm_buf),
                       TIMEVAL_DIFF_MSEC(now, send_time));
            }
            if (sr_data->flags & STATUS_DELIVERED)
            {
                clock = sr_data->delivery_ts.secs + DTNTIME_OFFSET;
                tm_buf = gmtime(&clock);
                printf("%s: delivered at %.*s UTC (%ld ms rtt)\n",
                       reply_spec.source.uri, 24, asctime(tm_buf),
                       TIMEVAL_DIFF_MSEC(now, send_time));
            }
            if (sr_data->flags & STATUS_DELETED)
            {
                clock = sr_data->deletion_ts.secs + DTNTIME_OFFSET;
                tm_buf = gmtime(&clock);
                printf("%s: deleted at %.*s UTC (%s) (%ld ms rtt)\n",
                       reply_spec.source.uri, 24, asctime(tm_buf),
                       dtn_status_report_reason_to_str(sr_data->reason),
                       TIMEVAL_DIFF_MSEC(now, send_time));
                break;
            }
        }
        else {
            if (reply_payload.buf.buf_len != sizeof(ping_payload_t))
            {
                printf("%d bytes from [%s]: ERROR: length != %zu\n",
                       reply_payload.buf.buf_len,
                       reply_spec.source.uri,
                       sizeof(ping_payload_t));
                break;
            }

            memcpy(&recv_contents, reply_payload.buf.buf_val,
                   sizeof(recv_contents));
                
            if (recv_contents.seqno != 0)
            {
                printf("%d bytes from [%s]: ERROR: invalid seqno %d\n",
                       reply_payload.buf.buf_len,
                       reply_spec.source.uri,
                       recv_contents.seqno);
                break;
            }

            if (recv_contents.nonce != nonce)
            {
                printf("%d bytes from [%s]: ERROR: invalid nonce %u != %u\n",
                       reply_payload.buf.buf_len,
                       reply_spec.source.uri,
                       recv_contents.nonce, nonce);
                break;
            }

            if ((int)recv_contents.time != (int)send_time.tv_sec)
            {
                printf("%d bytes from [%s]: ERROR: time mismatch %u != %lu\n",
                       reply_payload.buf.buf_len,
                       reply_spec.source.uri,
                       recv_contents.time,
                       (long unsigned int)send_time.tv_sec);
            }
                
            clock = reply_spec.creation_ts.secs + DTNTIME_OFFSET;
            tm_buf = gmtime(&clock);
            printf("%s: echo reply at %.*s UTC (%ld ms rtt)\n",
                   reply_spec.source.uri, 24, asctime(tm_buf),
                   TIMEVAL_DIFF_MSEC(now, send_time));
            done = 1;
        }
        
        dtn_free_payload(&reply_payload);
    }
    
    dtn_close(handle);
    
    return 0;
}