コード例 #1
0
static void
send_response(struct vmod_fsdirector_file_system *fs, struct stat *stat_buf,
    const char *path)
{
	int fd;
	off_t offset = 0;
	ssize_t remaining = stat_buf->st_size;
	ssize_t written;

	fd = open(path, O_RDONLY);

	if(fd < 0) {
		handle_file_error(&fs->htc, errno);
		return;
	}

	prepare_answer(&fs->htc, 200);
	dprintf(fs->htc.fd, "Content-Length: %lu\r\n", stat_buf->st_size);
	add_content_type(fs, path);
	prepare_body(&fs->htc);

	while (remaining > 0) {
		written = sendfile(fs->htc.fd, fd, &offset, remaining);
		if (written < 0) {
			perror("sendfile");
			break;
		}
		remaining -= written;
	}

	// XXX too late for a 500 response...
	close(fd);
}
コード例 #2
0
ファイル: test_ppg.c プロジェクト: LeeVidor/kannel-mongodb
static Octstr *push_content_create(void)
{
    Octstr *push_content, 
           *wap_content;
    Octstr *wap_file_content,
           *pap_content,
           *pap_file_content,
           *bpos,
           *bcos;

    wap_content = NULL;
    push_content = NULL;
    if (use_hardcoded) {
        push_content = octstr_create("\r\n\r\n"
                  "--asdlfkjiurwgasf\r\n"
                  "Content-Type: application/xml\r\n\r\n"
                  "<?xml version=\"1.0\"?>"
                  "<!DOCTYPE pap PUBLIC \"-//WAPFORUM//DTD PAP//EN\""
                             " \"http://www.wapforum.org/DTD/pap_1.0.dtd\">"
                  "<pap>"
                        "<push-message push-id=\"[email protected]\""
                          " deliver-before-timestamp=\"2002-11-01T06:45:00Z\""
                          " deliver-after-timestamp=\"2000-02-27T06:45:00Z\""
                          " progress-notes-requested=\"false\">"
			     "<address address-value=\"WAPPUSH=+358408676001/"
			 	"[email protected]\">"
                             "</address>"
                             "<quality-of-service"
                               " priority=\"low\""
                               " delivery-method=\"unconfirmed\""
                               " network-required=\"true\""
                               " network=\"GSM\""
                               " bearer-required=\"true\""
                               " bearer=\"SMS\">"
                             "</quality-of-service>"
                        "</push-message>"
                  "</pap>\r\n\r\n"         
                  "--asdlfkjiurwgasf\r\n"
                  "Content-Type: text/vnd.wap.si\r\n\r\n"
                  "<?xml version=\"1.0\"?>"
                  "<!DOCTYPE si PUBLIC \"-//WAPFORUM//DTD SI 1.0//EN\" "
                    " \"http://www.wapforum.org/DTD/si.dtd\">"
                  "<si>"
                      "<indication href=\"http://wap.iobox.fi\""
                          " si-id=\"[email protected]\""
                          " action=\"signal-high\""
                          " created=\"1999-06-25T15:23:15Z\""
                          " si-expires=\"2002-12-30T00:00:00Z\">"
                          "Want to test a fetch?"
                      "</indication>"
                   "</si>\r\n\r\n"
                 "--asdlfkjiurwgasf--\r\n\r\n"
                 "");
    } else {
        add_content_type(content_flag, &wap_content);
        add_content_transfer_encoding_type(content_transfer_encoding, 
                                           wap_content);
        add_part_header(content_header, &wap_content);

        /* Read the content file. (To be pushed)*/
        if ((wap_file_content = 
                octstr_read_file(octstr_get_cstr(content_file))) == NULL)
	         panic(0, "Stopping");
        if (accept_binary) {
            octstr_delete_matching(wap_file_content, octstr_imm(" "));
            octstr_delete_matching(wap_file_content, octstr_imm("\n"));
            octstr_delete_matching(wap_file_content, octstr_imm("\r"));
            if (!octstr_is_all_hex(wap_file_content))
                panic(0, "non-hex chars in the content file, cannot continue");
            octstr_hex_to_binary(wap_file_content);            
        }

	transfer_encode(content_transfer_encoding, wap_file_content);
        octstr_append(wap_content, wap_file_content);
        octstr_destroy(wap_file_content);

        /* Read the control file. (To control pushing)*/
        pap_content = octstr_format("%s", "Content-Type: application/xml");
        add_delimiter(&pap_content);
        add_delimiter(&pap_content);
        if ((pap_file_content = 
                octstr_read_file(octstr_get_cstr(pap_file))) ==  NULL)
	        panic(0, "Stopping");
        
        octstr_append(pap_content, pap_file_content);
        octstr_destroy(pap_file_content);

        if (wap_content == NULL || pap_content == NULL)
	        panic(0, "Cannot open the push content files");

        push_content = octstr_create("");
        if (add_preamble)
            octstr_append(push_content, octstr_imm("the parser should discard this"));
        octstr_append(push_content, 
            bpos = make_part_delimiter(octstr_imm(boundary)));
        /*octstr_append(push_content, octstr_imm("\r\n"));*/ /* Do we accept an additional 
                                                          * clrf ? */
        octstr_append(push_content, pap_content);
        octstr_append(push_content, bpos);
        octstr_destroy(bpos);
        octstr_append(push_content, wap_content);
        octstr_append(push_content, 
            bcos = make_close_delimiter(octstr_imm(boundary)));
        if (add_epilogue) {
            octstr_append(push_content, octstr_imm("\r\n"));
            octstr_append(push_content, octstr_imm("the parser should discard this"));
        }
        octstr_destroy(bcos);
        octstr_destroy(pap_content);
        octstr_destroy(wap_content);
    }

    return push_content;
}