예제 #1
0
int trusty_ipc_dev_close(struct trusty_ipc_dev *dev, handle_t handle)
{
    int rc;
    volatile struct trusty_ipc_cmd_hdr *cmd;

    trusty_assert(dev);

    trusty_debug("%a: chan %d: closing\n", __func__, handle);

    /* prepare command */
    cmd = dev->buf_vaddr;
    memset((void *)cmd, 0, sizeof(*cmd));
    cmd->opcode = QL_TIPC_DEV_DISCONNECT;
    cmd->handle = handle;
    /* no payload */

    /* call into secure os */
    rc = trusty_dev_exec_ipc(dev->tdev,
                             &dev->buf_ns, sizeof(*cmd) + cmd->payload_len);
    if (rc) {
        trusty_error("%a: secure OS returned (%d)\n", __func__, rc);
        return TRUSTY_ERR_SECOS_ERR;
    }

    rc = check_response(dev, cmd, QL_TIPC_DEV_DISCONNECT);
    if (rc) {
        trusty_error("%a: disconnect cmd failed (%d)\n", __func__, rc);
        return rc;
    }

    trusty_debug("%a: chan %d: closed\n", __func__, handle);

    return TRUSTY_ERR_NONE;
}
예제 #2
0
void flush_internal_buffer(churl_context* context)
{
	churl_buffer* context_buffer = context->upload_buffer;
	if (context_buffer->top == 0)
		return;

	while((context->curl_still_running != 0) &&
		  ((context_buffer->top - context_buffer->bot) > 0))
	{
		/*
		 * Allow canceling a query while waiting for input from remote service
		 */
		CHECK_FOR_INTERRUPTS();

		multi_perform(context);
	}

	if ((context->curl_still_running == 0) &&
		((context_buffer->top - context_buffer->bot) > 0))
		elog(ERROR, "failed sending to remote component %s", get_dest_address(context->curl_handle));

	check_response(context);

	context_buffer->top = 0;
	context_buffer->bot = 0;
}
예제 #3
0
/*
 * check that connection is ok, read a few bytes and check response.
 */
void churl_read_check_connectivity(CHURL_HANDLE handle)
{
	churl_context* context = (churl_context*)handle;
	Assert(!context->upload);

	fill_internal_buffer(context, 1);
	check_response(context);
}
예제 #4
0
static int _command_end(usb_handle *usb)
{
    int r;
    r = check_response(usb, 0, 0);
    if(r < 0) {
        return -1;
    }
    return 0;
}
예제 #5
0
int storage_delete_file(storage_session_t session, const char *name, uint32_t opflags)
{
    struct storage_msg msg = { .cmd = STORAGE_FILE_DELETE, .flags = _to_msg_flags(opflags)};
    struct storage_file_delete_req req = { .flags = 0, };
    struct iovec tx[3] = {{&msg, sizeof(msg)}, {&req, sizeof(req)}, {(void *)name, strlen(name)}};
    struct iovec rx[1] = {{&msg, sizeof(msg)}};

    ssize_t rc = send_reqv(session, tx, 3, rx, 1);
    return check_response(&msg, rc);
}

static int _read_chunk(file_handle_t fh, storage_off_t off, void *buf, size_t size)
{
    struct storage_msg msg = { .cmd = STORAGE_FILE_READ };
    struct storage_file_read_req req = { .handle = _to_handle(fh), .size = size, .offset = off };
    struct iovec tx[2] = {{&msg, sizeof(msg)}, {&req, sizeof(req)}};
    struct iovec rx[2] = {{&msg, sizeof(msg)}, {buf, size}};

    ssize_t rc = send_reqv(_to_session(fh), tx, 2, rx, 2);
    return check_response(&msg, rc);
}

ssize_t storage_read(file_handle_t fh, storage_off_t off, void *buf, size_t size)
{
    int rc;
    size_t bytes_read = 0;
    size_t chunk = MAX_CHUNK_SIZE;
    uint8_t *ptr = buf;

    while (size) {
        if (chunk > size)
            chunk = size;
        rc = _read_chunk(fh, off, ptr, chunk);
        if (rc < 0)
            return rc;
        if (rc == 0)
            break;
        off += rc;
        ptr += rc;
        bytes_read += rc;
        size -= rc;
    }
    return bytes_read;
}
예제 #6
0
int storage_set_file_size(file_handle_t fh, storage_off_t file_size, uint32_t opflags)
{
    struct storage_msg msg = { .cmd = STORAGE_FILE_SET_SIZE, .flags = _to_msg_flags(opflags)};
    struct storage_file_set_size_req req = { .handle = _to_handle(fh), .size = file_size, };
    struct iovec tx[2] = {{&msg, sizeof(msg)}, {&req, sizeof(req)}};
    struct iovec rx[1] = {{&msg, sizeof(msg)}};

    ssize_t rc = send_reqv(_to_session(fh), tx, 2, rx, 1);
    return check_response(&msg, rc);
}
예제 #7
0
int storage_end_transaction(storage_session_t session, bool complete)
{
    struct storage_msg msg = {
        .cmd = STORAGE_END_TRANSACTION,
        .flags = complete ? STORAGE_MSG_FLAG_TRANSACT_COMPLETE : 0,
    };
    struct iovec iov = {&msg, sizeof(msg)};

    ssize_t rc = send_reqv(session, &iov, 1, &iov, 1);
    return check_response(&msg, rc);
}
예제 #8
0
static int _write_req(file_handle_t fh, storage_off_t off,
                      const void *buf, size_t size, uint32_t msg_flags)
{
    struct storage_msg msg = { .cmd = STORAGE_FILE_WRITE, .flags = msg_flags, };
    struct storage_file_write_req req = { .handle = _to_handle(fh), .offset = off, };
    struct iovec tx[3] = {{&msg, sizeof(msg)}, {&req, sizeof(req)}, {(void *)buf, size}};
    struct iovec rx[1] = {{&msg, sizeof(msg)}};

    ssize_t rc = send_reqv(_to_session(fh), tx, 3, rx, 1);
    rc = check_response(&msg, rc);
    return rc < 0 ? rc : size;
}
예제 #9
0
static GByteArray *
do_single_coding_req_test (SoupRequest *req,
			   const char *expected_encoding,
			   const char *expected_content_type,
			   MessageContentStatus status)
{
	GInputStream *stream;
	SoupMessage *msg;
	GByteArray *data;
	guchar buf[1024];
	gssize nread;
	GError *error = NULL;

	data = g_byte_array_new ();

	msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (req));

	stream = soup_test_request_send (req, NULL, &error);
	if (error) {
		debug_printf (1, "    Error sending request: %s\n",
			      error->message);
		g_error_free (error);
		errors++;
		return data;
	}

	do {
		nread = -2;
		g_input_stream_read_async (stream, buf, sizeof (buf),
					   G_PRIORITY_DEFAULT,
					   NULL, read_finished, &nread);
		while (nread == -2)
			g_main_context_iteration (NULL, TRUE);

		if (nread > 0)
			g_byte_array_append (data, buf, nread);
	} while (nread > 0);

	soup_test_request_close_stream (req, stream, NULL, &error);
	if (error) {
		debug_printf (1, "    error closing stream: %s\n",
			      error->message);
		g_error_free (error);
		errors++;
	}
	g_object_unref (stream);

	check_response (msg, expected_encoding, expected_content_type, status);
	g_object_unref (msg);

	return data;
}
예제 #10
0
void storage_close_file(file_handle_t fh)
{
    struct storage_msg msg = { .cmd = STORAGE_FILE_CLOSE };
    struct storage_file_close_req req = { .handle = _to_handle(fh)};
    struct iovec tx[2] = {{&msg, sizeof(msg)}, {&req, sizeof(req)}};
    struct iovec rx[1] = {{&msg, sizeof(msg)}};

    ssize_t rc = send_reqv(_to_session(fh), tx, 2, rx, 1);
    rc = check_response(&msg, rc);
    if (rc < 0) {
        ALOGE("close file failed (%d)\n", (int)rc);
    }
}
예제 #11
0
int trusty_ipc_dev_connect(struct trusty_ipc_dev *dev, const char *port,
                           uint64_t cookie)
{
    int rc;
    size_t port_len;
    volatile struct trusty_ipc_cmd_hdr *cmd;
    struct trusty_ipc_connect_req *req;

    trusty_assert(dev);
    trusty_assert(port);

    trusty_debug("%a: connecting to '%a'\n", __func__, port);

    /* check port name length */
    port_len = strlen((CHAR8 *)port) + 1;
    if (port_len > (dev->buf_size - sizeof(*cmd) + sizeof(*req))) {
        /* it would not fit into buffer */
        trusty_error("%a: port name is too long (%zu)\n", __func__, port_len);
        return TRUSTY_ERR_INVALID_ARGS;
    }

    /* prepare command */
    cmd = dev->buf_vaddr;
    memset((void *)cmd, 0, sizeof(*cmd));
    cmd->opcode = QL_TIPC_DEV_CONNECT;

    /* prepare payload  */
    req = (struct trusty_ipc_connect_req *)cmd->payload;
    memset((void *)req, 0, sizeof(*req));
    req->cookie = cookie;
    strcpy((CHAR8 *)req->name, (CHAR8 *)port);
    cmd->payload_len = sizeof(*req) + port_len;

    /* call secure os */
    rc = trusty_dev_exec_ipc(dev->tdev,
                             &dev->buf_ns, sizeof(*cmd) + cmd->payload_len);
    if (rc) {
        /* secure OS returned an error */
        trusty_error("%a: secure OS returned (%d)\n", __func__, rc);
        return TRUSTY_ERR_SECOS_ERR;
    }

    rc = check_response(dev, cmd, QL_TIPC_DEV_CONNECT);
    if (rc) {
        trusty_error("%a: connect cmd failed (%d)\n", __func__, rc);
        return rc;
    }

    /* success */
    return cmd->handle;
}
예제 #12
0
/*
 * Let libcurl finish the upload by
 * calling perform repeatedly
 */
void finish_upload(churl_context* context)
{
	if (!context->multi_handle)
		return;

	flush_internal_buffer(context);

	/* allow read_callback to say 'all done'
	 * by returning a zero thus ending the connection
	 */
	while(context->curl_still_running != 0)
		multi_perform(context);

	check_response(context);
}
예제 #13
0
int
cryptocard(void)
{
    char prompt[80];
    char *challenge;
    char *key;
    char *response;

    challenge = generate_challenge();
    if (challenge == NULL) return 0;

    if (strlen(challenge) + 13 > sizeof(prompt)) return 0;
    sprintf(prompt, "%s Password: ", challenge);

    alarm((unsigned int)timeout);  /* give user time to fiddle with card */
    response = getpass(prompt);  /* presents challenge and gets response */

    if (response == NULL) return 0;

    /* This requires some explanation: As root we may not be able to
       read the directory of the user if it is on an NFS mounted
       filesystem. We temporarily set our effective uid to the user-uid
       making sure that we keep root privs. in the real uid. 

       A portable solution would require a fork(), but we rely on Linux
       having the BSD setreuid() */

    {
	uid_t ruid = getuid();
	gid_t egid = getegid();

	setregid(-1, pwd->pw_gid);
	setreuid(0, pwd->pw_uid);

	/* now we can access the file */
	/* get the (properly qualified) key */
	key = get_key();

	/* reset to root privs */
	setuid(0); /* setreuid doesn't do it alone! */
	setreuid(ruid, 0);
	setregid(-1, egid);

	if (key == NULL) return 0;
    }

    return check_response(challenge, response, key);
}
예제 #14
0
//===================================
//   master burst read
void 
sc_h264d_top::master_burst_read( unsigned int &addr, unsigned char * data, unsigned int length)
{
    // write transaction
    transaction_ptr->acquire();
    transaction_ptr->set_command          ( tlm::TLM_READ_COMMAND );
    transaction_ptr->set_address          ( addr );
    //transaction_ptr->set_data_length      ( 4 );
    transaction_ptr->set_data_length      ( length );//boy
    transaction_ptr->set_streaming_width  ( length );//boy
    transaction_ptr->set_data_ptr         ( data );
    transaction_ptr->set_response_status  ( tlm::TLM_INCOMPLETE_RESPONSE );
    // send request to fifo
    request_out_port->write (transaction_ptr);
    // check response
    check_response();
}
예제 #15
0
파일: auth_mod.c 프로젝트: ZRouter/ZRouter
static inline int pv_authorize(struct sip_msg* msg, gparam_p realm,
                               hdr_types_t hftype)
{
    static char ha1[256];
    int res;
    struct hdr_field* h;
    auth_body_t* cred;
    auth_result_t ret;
    str domain;

    if(fixup_get_svalue(msg, realm, &domain)!=0)
    {
        LM_ERR("invalid realm parameter\n");
        return -1;
    }

    if (domain.len==0)
        domain.s = 0;

    ret = pre_auth(msg, &domain, hftype, &h);

    if (ret != DO_AUTHORIZATION)
        return ret;

    cred = (auth_body_t*)h->parsed;

    res = auth_get_ha1(msg, &cred->digest.username, &domain, ha1);
    if (res < 0) {
        /* Error */
        if (sigb.reply(msg, 500, &auth_500_err, NULL) == -1) {
            LM_ERR("failed to send 500 reply\n");
        }
        return ERROR;
    }
    if (res > 0) {
        /* Username not found */
        return USER_UNKNOWN;
    }

    /* Recalculate response, it must be same to authorize successfully */
    if (!check_response(&(cred->digest),&msg->first_line.u.request.method,ha1))
    {
        return post_auth(msg, h);
    }
    return INVALID_PASSWORD;
}
예제 #16
0
int trusty_ipc_dev_send(struct trusty_ipc_dev *dev, handle_t chan,
                        const struct trusty_ipc_iovec *iovs, size_t iovs_cnt)
{
    int rc;
    size_t msg_size;
    volatile struct trusty_ipc_cmd_hdr *cmd;

    trusty_assert(dev);
    /* calc message length */
    msg_size = iovec_size(iovs, iovs_cnt);
    if (msg_size > dev->buf_size - sizeof(*cmd)) {
        /* msg is too big to fit provided buffer */
        trusty_error("%a: chan %d: msg is too long (%zu)\n", __func__,
                     chan, msg_size);
        return TRUSTY_ERR_MSG_TOO_BIG;
    }

    /* prepare command */
    cmd = dev->buf_vaddr;
    memset((void *)cmd, 0, sizeof(*cmd));
    cmd->opcode = QL_TIPC_DEV_SEND;
    cmd->handle = chan;

    /* copy in message data */
    cmd->payload_len = (uint32_t)msg_size;
    msg_size = iovec_to_buf(dev->buf_vaddr + sizeof(*cmd), dev->buf_size - sizeof(*cmd),
                          iovs,  iovs_cnt);
    trusty_assert(msg_size == (size_t)cmd->payload_len);

    /* call into secure os */
    rc = trusty_dev_exec_ipc(dev->tdev,
                             &dev->buf_ns, sizeof(*cmd) + cmd->payload_len);
    if (rc < 0) {
        trusty_error("%a: secure OS returned (%d)\n", __func__, rc);
        return TRUSTY_ERR_SECOS_ERR;
    }

    rc = check_response(dev, cmd, QL_TIPC_DEV_SEND);
    if (rc) {
        trusty_error("%a: send msg failed (%d)\n", __func__, rc);
    }

    return rc;
}
예제 #17
0
int trusty_ipc_dev_get_event(struct trusty_ipc_dev *dev, handle_t chan,
                             struct trusty_ipc_event *event)
{
    int rc;
    volatile struct trusty_ipc_cmd_hdr *cmd;

    trusty_assert(dev);
    trusty_assert(event);

    /* prepare command */
    cmd = dev->buf_vaddr;
    memset((void *)cmd, 0, sizeof(*cmd));
    cmd->opcode = QL_TIPC_DEV_GET_EVENT;
    cmd->handle = chan;

    /* prepare payload  */
    memset((void *)cmd->payload, 0, sizeof(struct trusty_ipc_wait_req));
    cmd->payload_len = sizeof(struct trusty_ipc_wait_req);

    /* call into secure os */
    rc = trusty_dev_exec_ipc(dev->tdev,
                             &dev->buf_ns, sizeof(*cmd) + cmd->payload_len);
    if (rc) {
        trusty_error("%a: secure OS returned (%d)\n", __func__, rc);
        return TRUSTY_ERR_SECOS_ERR;
    }

    rc = check_response(dev, cmd, QL_TIPC_DEV_GET_EVENT);
    if (rc) {
        trusty_error("%a: get event cmd failed (%d)\n", __func__, rc);
        return rc;
    }

    if ((size_t)cmd->payload_len < sizeof(*event)) {
        trusty_error("%a: invalid response length (%zd)\n",
                     __func__, (size_t)cmd->payload_len);
        return TRUSTY_ERR_SECOS_ERR;
    }

    /* copy out event */
    memcpy(event, (const void *)cmd->payload, sizeof(*event));
    return TRUSTY_ERR_NONE;
}
예제 #18
0
int trusty_ipc_dev_recv(struct trusty_ipc_dev *dev, handle_t chan,
                        const struct trusty_ipc_iovec *iovs, size_t iovs_cnt)
{
    int rc;
    size_t copied;
    volatile struct trusty_ipc_cmd_hdr *cmd;

    trusty_assert(dev);

    /* prepare command */
    cmd = dev->buf_vaddr;
    memset((void *)cmd, 0, sizeof(*cmd));
    cmd->opcode = QL_TIPC_DEV_RECV;
    cmd->handle = chan;
    /* no payload */

    /* call into secure os */
    rc = trusty_dev_exec_ipc(dev->tdev,
                             &dev->buf_ns, sizeof(*cmd) + cmd->payload_len);
    if (rc < 0) {
        trusty_error("%a: secure OS returned (%d)\n", __func__, rc);
        return TRUSTY_ERR_SECOS_ERR;
    }

    rc = check_response(dev, cmd, QL_TIPC_DEV_RECV);
    if (rc) {
        trusty_error("%a: recv cmd failed (%d)\n", __func__, rc);
        return rc;
    }

    /* copy data out to proper destination */
    copied = buf_to_iovec(iovs, iovs_cnt,
                          (const void *)cmd->payload, cmd->payload_len);
    if (copied != (size_t)cmd->payload_len) {
        /* msg is too big to fit provided buffer */
        trusty_error("%a: chan %d: buffer too small (%zu vs. %zu)\n",
                     __func__, chan, copied, (size_t)cmd->payload_len);
        return TRUSTY_ERR_MSG_TOO_BIG;
    }

    return (int)copied;
}
예제 #19
0
static void
do_coding_empty_test (void)
{
	SoupSession *session;
	SoupMessage *msg;
	SoupURI *uri;
	SoupRequester *requester;
	SoupRequest *req;
	GByteArray *body;

	debug_printf (1, "\nEmpty allegedly-encoded body test\n");

	session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
					 SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_CONTENT_DECODER,
					 SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
					 SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_REQUESTER,
					 NULL);
	requester = (SoupRequester *)soup_session_get_feature (session, SOUP_TYPE_REQUESTER);
	uri = soup_uri_new_with_base (base_uri, "/mbox");

	debug_printf (1, "  SoupMessage\n");
	msg = soup_message_new_from_uri ("GET", uri);
	soup_message_headers_append (msg->request_headers,
				     "X-Test-Options", "empty");
	soup_session_send_message (session, msg);
	check_response (msg, "gzip", "text/plain", EXPECT_NOT_DECODED);
	g_object_unref (msg);

	debug_printf (1, "  SoupRequest\n");
	req = soup_requester_request_uri (requester, uri, NULL);
	msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (req));
	soup_message_headers_append (msg->request_headers,
				     "X-Test-Options", "empty");
	g_object_unref (msg);
	body = do_single_coding_req_test (req, "gzip", "text/plain", EXPECT_NOT_DECODED);
	g_byte_array_free (body, TRUE);
	g_object_unref (req);

	soup_uri_free (uri);
	soup_test_session_abort_unref (session);
}
예제 #20
0
static	ZBX_THREAD_ENTRY(send_value, args)
{
	ZBX_THREAD_SENDVAL_ARGS	*sentdval_args;
	zbx_sock_t		sock;
	char			*answer = NULL;
	int			tcp_ret, ret = FAIL;

	assert(args);
	assert(((zbx_thread_args_t *)args)->args);

	sentdval_args = (ZBX_THREAD_SENDVAL_ARGS *)((zbx_thread_args_t *)args)->args;

#if !defined(_WINDOWS)
	signal(SIGINT,  send_signal_handler);
	signal(SIGTERM, send_signal_handler);
	signal(SIGQUIT, send_signal_handler);
	signal(SIGALRM, send_signal_handler);
#endif

	if (SUCCEED == (tcp_ret = zbx_tcp_connect(&sock, CONFIG_SOURCE_IP, sentdval_args->server, sentdval_args->port, GET_SENDER_TIMEOUT)))
	{
		if (SUCCEED == (tcp_ret = zbx_tcp_send(&sock, sentdval_args->json.buffer)))
		{
			if (SUCCEED == (tcp_ret = zbx_tcp_recv(&sock, &answer)))
			{
				zabbix_log(LOG_LEVEL_DEBUG, "answer [%s]", answer);
				if (NULL == answer || SUCCEED != check_response(answer))
					zabbix_log(LOG_LEVEL_WARNING, "incorrect answer from server [%s]", answer);
				else
					ret = SUCCEED;
			}
		}

		zbx_tcp_close(&sock);
	}

	if (FAIL == tcp_ret)
		zabbix_log(LOG_LEVEL_DEBUG, "send value error: %s", zbx_tcp_strerror());

	zbx_thread_exit(ret);
}
예제 #21
0
int storage_get_file_size(file_handle_t fh, storage_off_t *size_p)
{
    struct storage_msg msg = { .cmd = STORAGE_FILE_GET_SIZE };
    struct storage_file_get_size_req  req = { .handle = _to_handle(fh), };
    struct iovec tx[2] = {{&msg, sizeof(msg)}, {&req, sizeof(req)}};
    struct storage_file_get_size_resp rsp;
    struct iovec rx[2] = {{&msg, sizeof(msg)}, {&rsp, sizeof(rsp)}};

    ssize_t rc = send_reqv(_to_session(fh), tx, 2, rx, 2);
    rc = check_response(&msg, rc);
    if (rc < 0)
        return rc;

    if ((size_t)rc != sizeof(rsp)) {
        ALOGE("%s: invalid response length (%zd != %zd)\n", __func__, rc, sizeof(rsp));
        return -EIO;
    }

    *size_p = rsp.size;
    return 0;
}
예제 #22
0
static int _command_start(usb_handle *usb, const char *cmd, unsigned size,
                          char *response)
{
    int cmdsize = strlen(cmd);

    if(response) {
        response[0] = 0;
    }

    if(cmdsize > 64) {
        sprintf(ERROR,"command too large");
        return -1;
    }

    if(usb_write(usb, cmd, cmdsize) != cmdsize) {
        sprintf(ERROR,"command write failed (%s)", strerror(errno));
        usb_close(usb);
        return -1;
    }

    return check_response(usb, size, response);
}
예제 #23
0
int storage_open_file(storage_session_t session, file_handle_t *handle_p, const char *name,
                      uint32_t flags, uint32_t opflags)
{
    struct storage_msg msg = { .cmd = STORAGE_FILE_OPEN, .flags = _to_msg_flags(opflags)};
    struct storage_file_open_req req = { .flags = flags };
    struct iovec tx[3] = {{&msg, sizeof(msg)}, {&req, sizeof(req)}, {(void *)name, strlen(name)}};
    struct storage_file_open_resp rsp = { 0 };
    struct iovec rx[2] = {{&msg, sizeof(msg)}, {&rsp, sizeof(rsp)}};

    ssize_t rc = send_reqv(session, tx, 3, rx, 2);
    rc = check_response(&msg, rc);
    if (rc < 0)
        return rc;

    if ((size_t)rc != sizeof(rsp)) {
        ALOGE("%s: invalid response length (%zd != %zd)\n", __func__, rc, sizeof(rsp));
        return -EIO;
    }

    *handle_p = make_file_handle(session, rsp.handle);
    return 0;
}
예제 #24
0
/* Captures requested data from archiver and saves to file. */
int main(int argc, char **argv)
{
    char *server = getenv("FA_ARCHIVE_SERVER");
    if (server != NULL)
        server_name = server;

    output_file = stdout;
    FILE *stream;
    bool ok =
        parse_args(argc, argv)  &&
        validate_args()  &&

        connect_server(&stream)  &&
        IF_(output_filename != NULL,
            TEST_NULL_(
                output_file = fopen(output_filename, "w"),
                "Unable to open output file \"%s\"", output_filename))  &&
        request_data(stream)  &&
        check_response(stream)  &&

        initialise_signal()  &&
        capture_and_save(stream);
    return ok ? 0 : 1;
}
예제 #25
0
/*
 * Authorize digest credentials
 */
static inline int authorize(struct sip_msg* _m, str* _realm, char* _table,
														hdr_types_t _hftype)
{
	char ha1[256];
	int res;
	struct hdr_field* h;
	auth_body_t* cred;
	auth_result_t ret;
	str domain;
	db_res_t* result;

	domain = *_realm;

	ret = auth_api.pre_auth(_m, &domain, _hftype, &h);

	switch(ret) {
		case ERROR:            return 0;
		case NOT_AUTHORIZED:   return -1;
		case DO_AUTHORIZATION: break;
		case AUTHORIZED:       return 1;
	}

	cred = (auth_body_t*)h->parsed;

	res = get_ha1(&cred->digest.username, &domain, _table, ha1, &result);
	if (res < 0) {
		/* Error while accessing the database */
		if (sl_reply(_m, (char*)500, MESSAGE_500) == -1) {
			LOG(L_ERR, "authorize(): Error while sending 500 reply\n");
		}
		return 0;
	}
	if (res > 0) {
		/* Username not found in the database */
		auth_dbf.free_result(auth_db_handle, result);
		return -1;
	}

	/* Recalculate response, it must be same to authorize successfully */
	if (!check_response(&(cred->digest),&_m->first_line.u.request.method,ha1)) {
		ret = auth_api.post_auth(_m, h);
		switch(ret) {
		case ERROR:
			auth_dbf.free_result(auth_db_handle, result);
			return 1;

		case NOT_AUTHORIZED:
			auth_dbf.free_result(auth_db_handle, result);
			return -1;

		case AUTHORIZED:
			generate_avps(result);
			auth_dbf.free_result(auth_db_handle, result);
			return 1;

		default:
			auth_dbf.free_result(auth_db_handle, result);
			return -1;
		}
	}

	auth_dbf.free_result(auth_db_handle, result);
	return -1;
}
예제 #26
0
파일: active.c 프로젝트: rennhak/zabbix
/******************************************************************************
 *                                                                            *
 * Function: send_buffer                                                      *
 *                                                                            *
 * Purpose: Send value stgored in the buffer to ZABBIX server                 *
 *                                                                            *
 * Parameters: host - IP or Hostname of ZABBIX server                         *
 *             port - port number                                             *
 *                                                                            *
 * Return value: returns SUCCEED on succesfull parsing,                       *
 *               FAIL on other cases                                          *
 *                                                                            *
 * Author: Alexei Vladishev                                                   *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
static int	send_buffer(
		const char		*host,
		unsigned short	port
	)
{
	zbx_sock_t	s;
	char		*buf = NULL;
	int		ret = SUCCEED;
	struct zbx_json json;
	int		i;
	static int	lastsent = 0;
	int		now;

	zabbix_log( LOG_LEVEL_DEBUG, "In send_buffer('%s','%d')",
		host, port);

	zabbix_log( LOG_LEVEL_DEBUG, "Values in the buffer %d Max %d",
		buffer.count,
		CONFIG_BUFFER_SIZE);

	now = (int)time(NULL);
	if(buffer.count < CONFIG_BUFFER_SIZE && now-lastsent < CONFIG_BUFFER_SEND)
	{
		zabbix_log( LOG_LEVEL_DEBUG, "Will not send now. Now %d lastsent %d < %d",
			now,
			lastsent,
			CONFIG_BUFFER_SEND);
		return ret;
	}

	if(buffer.count < 1)
	{
		return ret;
	}

	zbx_json_init(&json, ZBX_JSON_STAT_BUF_LEN);

	zbx_json_addstring(&json, ZBX_PROTO_TAG_REQUEST, ZBX_PROTO_VALUE_AGENT_DATA, ZBX_JSON_TYPE_STRING);

	zbx_json_addarray(&json, ZBX_PROTO_TAG_DATA);

	for(i=0;i<buffer.count;i++)
	{
		zbx_json_addobject(&json, NULL);
		zbx_json_addstring(&json, ZBX_PROTO_TAG_HOST, buffer.data[i].host, ZBX_JSON_TYPE_STRING);
		zbx_json_addstring(&json, ZBX_PROTO_TAG_KEY, buffer.data[i].key, ZBX_JSON_TYPE_STRING);
		zbx_json_addstring(&json, ZBX_PROTO_TAG_VALUE, buffer.data[i].value, ZBX_JSON_TYPE_STRING);
		if (buffer.data[i].lastlogsize)
			zbx_json_adduint64(&json, ZBX_PROTO_TAG_LOGLASTSIZE, buffer.data[i].lastlogsize);
		if (buffer.data[i].timestamp)
			zbx_json_adduint64(&json, ZBX_PROTO_TAG_LOGTIMESTAMP, buffer.data[i].timestamp);
		if (buffer.data[i].source)
			zbx_json_addstring(&json, ZBX_PROTO_TAG_LOGSOURCE, buffer.data[i].source, ZBX_JSON_TYPE_STRING);
		if (buffer.data[i].severity)
			zbx_json_adduint64(&json, ZBX_PROTO_TAG_LOGSEVERITY, buffer.data[i].severity);
		zbx_json_adduint64(&json, ZBX_PROTO_TAG_CLOCK, buffer.data[i].clock);
		zbx_json_close(&json);
	}

	zbx_json_close(&json);

	zbx_json_adduint64(&json, ZBX_PROTO_TAG_CLOCK, (int)time(NULL));

	if (SUCCEED == (ret = zbx_tcp_connect(&s, CONFIG_SOURCE_IP, host, port, MIN(buffer.count*CONFIG_TIMEOUT, 60)))) {

		zabbix_log(LOG_LEVEL_DEBUG, "JSON before sending [%s]",
			json.buffer);

		ret = zbx_tcp_send(&s, json.buffer);

		if( SUCCEED == ret )
		{
			if( SUCCEED == (ret = zbx_tcp_recv(&s, &buf)) )
			{
				zabbix_log(LOG_LEVEL_DEBUG, "JSON back [%s]",
						buf);
				if( !buf || check_response(buf) != SUCCEED )
				{
					zabbix_log(LOG_LEVEL_DEBUG, "NOT OK");
				}
				else
				{
					zabbix_log(LOG_LEVEL_DEBUG, "OK");
				}
			} else
				zabbix_log(LOG_LEVEL_DEBUG, "Send value error: [recv] %s", zbx_tcp_strerror());
		} else
			zabbix_log(LOG_LEVEL_DEBUG, "Send value error: [send] %s", zbx_tcp_strerror());

		zbx_tcp_close(&s);
	} else
		zabbix_log(LOG_LEVEL_DEBUG, "Send value error: [connect] %s", zbx_tcp_strerror());

	zbx_json_free(&json);

	if(SUCCEED == ret)
	{
		/* free buffer */
		for(i=0;i<buffer.count;i++)
		{
			if(buffer.data[i].host != NULL)		zbx_free(buffer.data[i].host);
			if(buffer.data[i].key != NULL)		zbx_free(buffer.data[i].key);
			if(buffer.data[i].value != NULL)	zbx_free(buffer.data[i].value);
			if(buffer.data[i].source != NULL)	zbx_free(buffer.data[i].source);
		}
		buffer.count = 0;
	}

	if(SUCCEED == ret)	lastsent = now;

	return ret;
}
예제 #27
0
void wait::join_game(bool observe)
{
	//if we have got valid side data
	//the first condition is to make sure that we don't have another
	//WML message with a side-tag in it
	while (!level_.has_attribute("version") || !level_.child("side")) {
		network::connection data_res = dialogs::network_receive_dialog(disp(),
				_("Getting game data..."), level_);
		if (!data_res) {
			set_result(QUIT);
			return;
		}
		check_response(data_res, level_);
		if(level_.child("leave_game")) {
			set_result(QUIT);
			return;
		}
	}

	// Add the map name to the title.
	append_to_title(": " + level_["name"].t_str());

	if (!observe) {
		//search for an appropriate vacant slot. If a description is set
		//(i.e. we're loading from a saved game), then prefer to get the side
		//with the same description as our login. Otherwise just choose the first
		//available side.
		const config *side_choice = NULL;
		int side_num = -1, nb_sides = 0;
		foreach (const config &sd, level_.child_range("side"))
		{
			if (sd["controller"] == "reserved" && sd["current_player"] == preferences::login())
			{
				side_choice = &sd;
				side_num = nb_sides;
				break;
			}
			if (sd["controller"] == "network" && sd["player_id"].empty())
			{
				if (!side_choice) { // found the first empty side
					side_choice = &sd;
					side_num = nb_sides;
				}
				if (sd["current_player"] == preferences::login()) {
					side_choice = &sd;
					side_num = nb_sides;
					break;  // found the preferred one
				}
			}
			++nb_sides;
		}
		if (!side_choice) {
			set_result(QUIT);
			return;
		}

		bool allow_changes = (*side_choice)["allow_changes"].to_bool(true);

		//if the client is allowed to choose their team, instead of having
		//it set by the server, do that here.
		std::string leader_choice, gender_choice;

		if(allow_changes) {
			events::event_context context;

			const config &era = level_.child("era");
			/** @todo Check whether we have the era. If we don't inform the user. */
			if (!era)
				throw config::error(_("No era information found."));
			config::const_child_itors possible_sides = era.child_range("multiplayer_side");
			if (possible_sides.first == possible_sides.second) {
				set_result(QUIT);
				throw config::error(_("No multiplayer sides found"));
				return;
			}

			int color = side_num;
			const std::string color_str = (*side_choice)["color"];
			if (!color_str.empty())
				color = game_config::color_info(color_str).index() - 1;

			std::vector<const config *> leader_sides;
			foreach (const config &side, possible_sides) {
				leader_sides.push_back(&side);
			}

			int forced_faction = find_suitable_faction(leader_sides, *side_choice);
			if (forced_faction >= 0) {
				const config *f = leader_sides[forced_faction];
				leader_sides.clear();
				leader_sides.push_back(f);
			}

			std::vector<std::string> choices;
			foreach (const config *s, leader_sides)
			{
				const config &side = *s;
				const std::string &name = side["name"];
				const std::string &icon = side["image"];

				if (!icon.empty()) {
					std::string rgb = side["flag_rgb"];
					if (rgb.empty())
						rgb = "magenta";

					choices.push_back(IMAGE_PREFIX + icon + "~RC(" + rgb + ">" +
						lexical_cast<std::string>(color+1) + ")" + COLUMN_SEPARATOR + name);
				} else {
					choices.push_back(name);
				}
			}

			std::vector<gui::preview_pane* > preview_panes;
			leader_preview_pane leader_selector(disp(), leader_sides, color);
			preview_panes.push_back(&leader_selector);

			const int res = gui::show_dialog(disp(), NULL, _("Choose your faction:"), _("Starting position: ") + lexical_cast<std::string>(side_num + 1),
						gui::OK_CANCEL, &choices, &preview_panes);
			if(res < 0) {
				set_result(QUIT);
				return;
			}
			const int faction_choice = res;
			leader_choice = leader_selector.get_selected_leader();
			gender_choice = leader_selector.get_selected_gender();

			assert(static_cast<unsigned>(faction_choice) < leader_sides.size());

			config faction;
			config& change = faction.add_child("change_faction");
			change["name"] = preferences::login();
			change["faction"] = forced_faction >= 0 ? forced_faction : faction_choice;
			change["leader"] = leader_choice;
			change["gender"] = gender_choice;
			network::send_data(faction, 0);
		}

	}
예제 #28
0
int main(int argc, char *argv[]) {

	char pcap_buff[PCAP_ERRBUF_SIZE];	// Error buffer used by pcap
	size_t userin_len = 0;
	ssize_t n;
	int ret;
	struct pcap_pkthdr *packet_hdr = NULL;
	const u_char *packet_data = NULL;
	char *userin = NULL;
	char got_response;

	init(argc, argv, pcap_buff);

	while (!quit) {

		// read user input
		printf("Enter next IP address: ");
		// getline malloc's userin, so free it each time
		if (userin)
			free(userin);
		userin_len = 0;
		n = getline(&userin, &userin_len, stdin);
		if (n < 0) {
			if (errno == EINTR)
				break;
			perror("getline failed");
			exit(EXIT_FAILURE);
		}
		// remove new line
		userin[n-1] = '\0';

		if (0 == strcmp("", userin))
			continue;

		// send an ARP request
		n = arp_request(pcap_handle, userin);
		if (n < 0) {
			printf("ARP request failed\n");
			continue;
		}

		// wait for a response
		got_response = 0;

		// look for a response
		while (!quit) {
			// receive some data
			alarm(RESP_TIMEOUT);
			ret = pcap_next_ex(pcap_handle, &packet_hdr,
					&packet_data);
			if (ret < 0)
				break;  // timeout or error

			// if the response is ours,
			// display the result and break.
			if (check_response(packet_hdr, packet_data)) {
				got_response = 1;
				break;
			}
		}
		alarm(0);  // disable timeout
		if (!got_response) {
			printf("MAC: Lookup failed\n");		
		}
	}

	if (userin)
		free(userin);

	if (pcap_handle)
		pcap_close(pcap_handle);

	return 0;
}
예제 #29
0
CUPnPDevice::CUPnPDevice(std::string url)
{
	std::string result, head, body, charset, urlbase;
	std::string curl, eurl, name, mimetype, iurl, rcode;
	std::string::size_type pos;
	XMLTreeNode *root, *device, *service, *node, *snode, *icon;
	int width = 0;
	int height = 0;
	int depth = 0;
	bool servicefound = false;

	descurl = url;
	urlbase = url.substr(7);
	pos = urlbase.find("/");
	if (pos != std::string::npos)
		urlbase = url.substr(0,pos+7);
	else
		urlbase = url;

	result = HTTP(url);

	pos = result.find("\r\n\r\n");

	if (pos == std::string::npos)
		//throw std::runtime_error(std::string("no desc body"));
		dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: no desc body\n");

	head = result.substr(0,pos);
	body = result.substr(pos+4);

	if (body == "")
		//throw std::runtime_error(std::string("desc body empty"));
		printf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: desc body empty\n");

	if (!check_response(head, charset, rcode))
		//throw std::runtime_error(std::string("protocol error"));
		dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: protocol error\n");

	if (rcode != "200")
		//throw std::runtime_error(std::string("description url returned ") + rcode);
		printf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: description url error\n");
	
	XMLTreeParser parser(charset.c_str());
	parser.Parse(body.c_str(), body.size(), 1);
	root = parser.RootNode();
	if (!root)
		//throw std::runtime_error(std::string("XML: no root node"));
		dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: no root node\n");

	if (strcmp(root->GetType(),"root"))
		//throw std::runtime_error(std::string("XML: no root"));
		dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: no root\n");

	for (node = root->GetChild(); node; node=node->GetNext())
	{
		if (!strcmp(node->GetType(),"URLBase"))
		{
			urlbase = std::string(node->GetData());
			if ((urlbase.length() > 0) && (urlbase[urlbase.length()-1] == '/'))
				urlbase.erase(urlbase.length()-1);
		}

	}

	node = root->GetChild();
	if (!node)
		//throw std::runtime_error(std::string("XML: no root child"));
		dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: no root child\n");

	while (strcmp(node->GetType(),"device"))
	{
		node = node->GetNext();
		if (!node)
			//throw std::runtime_error(std::string("XML: no device"));
			dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: no device\n");
	}
	device = node;

	for (node=device->GetChild(); node; node=node->GetNext())
	{
		if (!strcmp(node->GetType(),"deviceType"))
			devicetype = std::string(node->GetData()?node->GetData():"");

		if (!strcmp(node->GetType(),"friendlyName"))
			friendlyname = std::string(node->GetData()?node->GetData():"");

		if (!strcmp(node->GetType(),"manufacturer"))
			manufacturer = std::string(node->GetData()?node->GetData():"");

		if (!strcmp(node->GetType(),"manufacturerURL"))
			manufacturerurl = std::string(node->GetData()?node->GetData():"");

		if (!strcmp(node->GetType(),"modelDescription"))
			modeldescription = std::string(node->GetData()?node->GetData():"");

		if (!strcmp(node->GetType(),"modelName"))
			modelname = std::string(node->GetData()?node->GetData():"");

		if (!strcmp(node->GetType(),"modelNumber"))
			modelnumber = std::string(node->GetData()?node->GetData():"");

		if (!strcmp(node->GetType(),"modelURL"))
			modelurl = std::string(node->GetData()?node->GetData():"");

		if (!strcmp(node->GetType(),"serialNumber"))
			serialnumber = std::string(node->GetData()?node->GetData():"");

		if (!strcmp(node->GetType(),"UDN"))
			udn = std::string(node->GetData()?node->GetData():"");

		if (!strcmp(node->GetType(),"UPC"))
			upc = std::string(node->GetData()?node->GetData():"");

		if (!strcmp(node->GetType(),"iconList"))
		{
			for (icon=node->GetChild(); icon; icon=icon->GetNext())
			{
				bool foundm = false;
				bool foundw = false;
				bool foundh = false;
				bool foundd = false;
				bool foundu = false;

				if (strcmp(icon->GetType(),"icon"))
					//throw std::runtime_error(std::string("XML: no icon"));
					dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: no icon\n");
				
				for (snode=icon->GetChild(); snode; snode=snode->GetNext())
				{
					if (!strcmp(snode->GetType(),"mimetype"))
					{
						mimetype=std::string(snode->GetData()?snode->GetData():"");
						foundm = true;
					}
					if (!strcmp(snode->GetType(),"width"))
					{
						width=snode->GetData()?atoi(snode->GetData()):0;
						foundw = true;
					}
					if (!strcmp(snode->GetType(),"height"))
					{
						height=snode->GetData()?atoi(snode->GetData()):0;
						foundh = true;
					}
					if (!strcmp(snode->GetType(),"depth"))
					{
						depth=snode->GetData()?atoi(snode->GetData()):0;
						foundd = true;
					}
					if (!strcmp(snode->GetType(),"url"))
					{
						url=std::string(snode->GetData()?snode->GetData():"");
						foundu = true;
					}
				}
				if (!foundm)
					//throw std::runtime_error(std::string("XML: icon without mime"));
					dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: icon without mime\n");
				if (!foundw)
					//throw std::runtime_error(std::string("XML: icon without width"));
					dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: icon without width\n");
				if (!foundh)
					//throw std::runtime_error(std::string("XML: icon without height"));
					dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: icon without height\n");
				if (!foundd)
					//throw std::runtime_error(std::string("XML: icon without depth"));
					dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: icon without depth\n");
				if (!foundu)
					//throw std::runtime_error(std::string("XML: icon without url"));
					dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: icon without url\n");
				
				UPnPIcon e = {mimetype, url, width, height, depth};
				icons.push_back(e);
			}
		}
		if (!strcmp(node->GetType(),"serviceList"))
		{
			servicefound = true;
			for (service=node->GetChild(); service; service=service->GetNext())
			{
				bool foundc = false;
				bool founde = false;
				bool foundn = false;

				if (strcmp(service->GetType(),"service"))
					//throw std::runtime_error(std::string("XML: no service"));
					dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: no service\n");
				
				for (snode=service->GetChild(); snode; snode=snode->GetNext())
				{
					if (!strcmp(snode->GetType(),"serviceType"))
					{
						name=std::string(snode->GetData()?snode->GetData():"");
						foundn = true;
					}
					if (!strcmp(snode->GetType(),"eventSubURL"))
					{
						char *p;
						p = snode->GetData();
						if (!p)
							eurl=urlbase + "/";
						else if (p[0]=='/')
							eurl=urlbase + std::string(p);
						else
							eurl=urlbase + "/" + std::string(p);
						founde = true;
					}
					if (!strcmp(snode->GetType(),"controlURL"))
					{
						char *p;
						p = snode->GetData();
						if (!p)
							curl=urlbase + "/";
						else if (p[0]=='/')
							curl=urlbase + std::string(p);
						else
							curl=urlbase + "/" + std::string(p);
						foundc = true;
					}
				}
				if (!foundn)
					//throw std::runtime_error(std::string("XML: no service type"));
					dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: no service type\n");
				if (!founde)
					//throw std::runtime_error(std::string("XML: no event url"));
					dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: no service url\n");
				if (!foundc)
					//throw std::runtime_error(std::string("XML: no control url"));
					dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: no control url\n");
				//try
				{
					services.push_back(CUPnPService(this, curl, eurl, name));
				}
				
				//catch (std::runtime_error error)
				//{
				//	std::cout << "error " << error.what() << "\n";
				//}
			}
		}
	}
	if (!servicefound)
		//throw std::runtime_error(std::string("XML: no service list"));
		dprintf(DEBUG_NORMAL, "CUPnPDevice::CUPnPDevice: no service list\n");
}
예제 #30
0
static void
do_coding_test (void)
{
	SoupSession *session;
	SoupMessage *msg, *msgz, *msgj, *msge, *msgzl, *msgzlj, *msgzle, *msgzlr, *msgzlre;
	SoupURI *uri;

	debug_printf (1, "SoupMessage tests\n");

	session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
	uri = soup_uri_new_with_base (base_uri, "/mbox");

	/* Plain text data, no claim */
	debug_printf (1, "  GET /mbox, plain\n");
	msg = soup_message_new_from_uri ("GET", uri);
	soup_session_send_message (session, msg);
	check_response (msg, NULL, "text/plain", EXPECT_NOT_DECODED);

	/* Plain text data, claim gzip */
	debug_printf (1, "  GET /mbox, Accept-Encoding: gzip\n");
	soup_session_add_feature_by_type (session, SOUP_TYPE_CONTENT_DECODER);
	msgz = soup_message_new_from_uri ("GET", uri);
	soup_session_send_message (session, msgz);
	check_response (msgz, "gzip", "text/plain", EXPECT_DECODED);
	check_msg_bodies (msg, msgz, "plain", "compressed");

	/* Plain text data, claim gzip w/ junk */
	debug_printf (1, "  GET /mbox, Accept-Encoding: gzip, plus trailing junk\n");
	msgj = soup_message_new_from_uri ("GET", uri);
	soup_message_headers_append (msgj->request_headers,
				     "X-Test-Options", "trailing-junk");
	soup_session_send_message (session, msgj);
	check_response (msgj, "gzip", "text/plain", EXPECT_DECODED);
	check_msg_bodies (msg, msgj, "plain", "compressed w/ junk");

	/* Plain text data, claim gzip with server error */
	debug_printf (1, "  GET /mbox, Accept-Encoding: gzip, with server error\n");
	msge = soup_message_new_from_uri ("GET", uri);
	soup_message_headers_append (msge->request_headers,
				     "X-Test-Options", "force-encode");
	soup_session_send_message (session, msge);
	check_response (msge, "gzip", "text/plain", EXPECT_NOT_DECODED);

	/* Failed content-decoding should have left the body untouched
	 * from what the server sent... which happens to be the
	 * uncompressed data.
	 */
	check_msg_bodies (msg, msge, "plain", "mis-encoded");

	/* Plain text data, claim deflate */
	debug_printf (1, "  GET /mbox, Accept-Encoding: deflate\n");
	msgzl = soup_message_new_from_uri ("GET", uri);
	soup_message_headers_append (msgzl->request_headers,
				     "X-Test-Options", "prefer-deflate-zlib");
	soup_session_send_message (session, msgzl);
	check_response (msgzl, "deflate", "text/plain", EXPECT_DECODED);
	check_msg_bodies (msg, msgzl, "plain", "compressed");

	/* Plain text data, claim deflate w/ junk */
	debug_printf (1, "  GET /mbox, Accept-Encoding: deflate, plus trailing junk\n");
	msgzlj = soup_message_new_from_uri ("GET", uri);
	soup_message_headers_append (msgzlj->request_headers,
				     "X-Test-Options", "prefer-deflate-zlib, trailing-junk");
	soup_session_send_message (session, msgzlj);
	check_response (msgzlj, "deflate", "text/plain", EXPECT_DECODED);
	check_msg_bodies (msg, msgzlj, "plain", "compressed w/ junk");

	/* Plain text data, claim deflate with server error */
	debug_printf (1, "  GET /mbox, Accept-Encoding: deflate, with server error\n");
	msgzle = soup_message_new_from_uri ("GET", uri);
	soup_message_headers_append (msgzle->request_headers,
				     "X-Test-Options", "force-encode, prefer-deflate-zlib");
	soup_session_send_message (session, msgzle);
	check_response (msgzle, "deflate", "text/plain", EXPECT_NOT_DECODED);
	check_msg_bodies (msg, msgzle, "plain", "mis-encoded");

	/* Plain text data, claim deflate (no zlib headers)*/
	debug_printf (1, "  GET /mbox, Accept-Encoding: deflate (raw data)\n");
	msgzlr = soup_message_new_from_uri ("GET", uri);
	soup_message_headers_append (msgzlr->request_headers,
				     "X-Test-Options", "prefer-deflate-raw");
	soup_session_send_message (session, msgzlr);
	check_response (msgzlr, "deflate", "text/plain", EXPECT_DECODED);
	check_msg_bodies (msg, msgzlr, "plain", "compressed");

	/* Plain text data, claim deflate with server error */
	debug_printf (1, "  GET /mbox, Accept-Encoding: deflate (raw data), with server error\n");
	msgzlre = soup_message_new_from_uri ("GET", uri);
	soup_message_headers_append (msgzlre->request_headers,
				     "X-Test-Options", "force-encode, prefer-deflate-raw");
	soup_session_send_message (session, msgzlre);
	check_response (msgzlre, "deflate", "text/plain", EXPECT_NOT_DECODED);
	check_msg_bodies (msg, msgzlre, "plain", "mis-encoded");

	g_object_unref (msg);
	g_object_unref (msgzlre);
	g_object_unref (msgzlr);
	g_object_unref (msgzlj);
	g_object_unref (msgzle);
	g_object_unref (msgzl);
	g_object_unref (msgz);
	g_object_unref (msgj);
	g_object_unref (msge);
	soup_uri_free (uri);

	soup_test_session_abort_unref (session);
}