예제 #1
0
파일: gobex.c 프로젝트: Fiend90/obex
guint g_obex_send_req(GObex *obex, GObexPacket *req, gint timeout,
			GObexResponseFunc func, gpointer user_data,
			GError **err)
{
	GObexHeader *hdr;
	struct pending_pkt *p;
	static guint id = 1;
	guint8 op;

	g_obex_debug(G_OBEX_DEBUG_COMMAND, "conn %u", obex->conn_id);

	op = g_obex_packet_get_operation(req, NULL);
	if (op == G_OBEX_OP_PUT || op == G_OBEX_OP_GET) {
		/* Only enable SRM automatically for GET and PUT */
		prepare_srm_req(obex, req);
	}

	if (obex->conn_id == CONNID_INVALID)
		goto create_pending;

	if (obex->rx_last_op == G_OBEX_RSP_CONTINUE)
		goto create_pending;

	if (g_obex_srm_active(obex) && obex->pending_req != NULL)
		goto create_pending;

	hdr = g_obex_packet_get_header(req, G_OBEX_HDR_CONNECTION);
	if (hdr != NULL)
		goto create_pending;

	hdr = g_obex_header_new_uint32(G_OBEX_HDR_CONNECTION, obex->conn_id);
	g_obex_packet_prepend_header(req, hdr);

create_pending:
	p = g_new0(struct pending_pkt, 1);

	p->pkt = req;
	p->id = id++;
	p->rsp_func = func;
	p->rsp_data = user_data;

	if (timeout < 0)
		p->timeout = G_OBEX_DEFAULT_TIMEOUT;
	else
		p->timeout = timeout;

	if (!g_obex_send_internal(obex, p, err)) {
		pending_pkt_free(p);
		return 0;
	}

	return p->id;
}
예제 #2
0
static void test_header_uint32(void)
{
	GObexHeader *header;
	uint8_t buf[1024];
	size_t len;

	header = g_obex_header_new_uint32(G_OBEX_HDR_CONNECTION, 0x01020304);
	len = g_obex_header_encode(header, buf, sizeof(buf));

	assert_memequal(hdr_connid, sizeof(hdr_connid), buf, len);

	g_obex_header_free(header);
}
예제 #3
0
GSList *g_obex_header_create_list(guint8 first_hdr_id, va_list args,
                                  gsize *total_len)
{
    unsigned int id = first_hdr_id;
    GSList *l = NULL;

    g_obex_debug(G_OBEX_DEBUG_HEADER, "");

    *total_len = 0;

    while (id != G_OBEX_HDR_INVALID) {
        GObexHeader *hdr;
        const char *str;
        const void *bytes;
        unsigned int val;
        gsize len;

        switch (G_OBEX_HDR_ENC(id)) {
        case G_OBEX_HDR_ENC_UNICODE:
            str = va_arg(args, const char *);
            hdr = g_obex_header_new_unicode(id, str);
            break;
        case G_OBEX_HDR_ENC_BYTES:
            bytes = va_arg(args, void *);
            len = va_arg(args, gsize);
            hdr = g_obex_header_new_bytes(id, bytes, len);
            break;
        case G_OBEX_HDR_ENC_UINT8:
            val = va_arg(args, unsigned int);
            hdr = g_obex_header_new_uint8(id, val);
            break;
        case G_OBEX_HDR_ENC_UINT32:
            val = va_arg(args, unsigned int);
            hdr = g_obex_header_new_uint32(id, val);
            break;
        default:
            g_assert_not_reached();
        }

        l = g_slist_append(l, hdr);
        *total_len += hdr->hlen;
        id = va_arg(args, int);
    }

    return l;
}
예제 #4
0
파일: gobex.c 프로젝트: Fiend90/obex
static void prepare_connect_rsp(GObex *obex, GObexPacket *rsp)
{
	GObexHeader *connid;
	struct connect_data data;
	static guint32 next_connid = 1;

	init_connect_data(obex, &data);
	g_obex_packet_set_data(rsp, &data, sizeof(data), G_OBEX_DATA_COPY);

	connid = g_obex_packet_get_header(rsp, G_OBEX_HDR_CONNECTION);
	if (connid != NULL) {
		g_obex_header_get_uint32(connid, &obex->conn_id);
		return;
	}

	obex->conn_id = next_connid++;

	connid = g_obex_header_new_uint32(G_OBEX_HDR_CONNECTION,
							obex->conn_id);
	g_obex_packet_prepend_header(rsp, connid);
}