コード例 #1
0
ファイル: session.c プロジェクト: Commers/obexd
static void rfcomm_callback(GIOChannel *io, GError *err, gpointer user_data)
{
	struct callback_data *callback = user_data;
	struct session_data *session = callback->session;
	GwObex *obex;
	int fd;

	if (err != NULL) {
		error("%s", err->message);
		goto done;
	}

	/* do not close when gw_obex is using the fd */
	g_io_channel_set_close_on_unref(session->io, FALSE);
	g_io_channel_unref(session->io);
	session->io = NULL;

	fd = g_io_channel_unix_get_fd(io);

	obex = gw_obex_setup_fd(fd, session->target,
			session->target_len, NULL, NULL);

	session->obex = obex;

done:
	callback->func(callback->session, err, callback->data);

	session_unref(callback->session);

	g_free(callback);
}
コード例 #2
0
ファイル: session.c プロジェクト: Commers/obexd
void session_shutdown(struct session_data *session)
{
	struct transfer_data *transfer;

	DBG("%p", session);
	transfer = session->pending ? session->pending->data : NULL;

	session_ref(session);

	/* Unregister any pending transfer */
	g_slist_foreach(session->pending, (GFunc) transfer_unregister, NULL);

	session_unref(session);
}
コード例 #3
0
ファイル: session.c プロジェクト: Commers/obexd
static gboolean service_callback(GIOChannel *io, GIOCondition cond,
							gpointer user_data)
{
	struct callback_data *callback = user_data;
	sdp_list_t *search, *attrid;
	uint32_t range = 0x0000ffff;
	GError *gerr = NULL;

	if (cond & (G_IO_NVAL | G_IO_ERR))
		goto failed;

	if (sdp_set_notify(callback->sdp, search_callback, callback) < 0)
		goto failed;

	search = sdp_list_append(NULL, &callback->session->uuid);
	attrid = sdp_list_append(NULL, &range);

	if (sdp_service_search_attr_async(callback->sdp,
				search, SDP_ATTR_REQ_RANGE, attrid) < 0) {
		sdp_list_free(attrid, NULL);
		sdp_list_free(search, NULL);
		goto failed;
	}

	sdp_list_free(attrid, NULL);
	sdp_list_free(search, NULL);

	g_io_add_watch(io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
						process_callback, callback);

	return FALSE;

failed:
	sdp_close(callback->sdp);

	g_set_error(&gerr, OBEX_IO_ERROR, -EIO,
					"Unable to find service record");
	callback->func(callback->session, gerr, callback->data);
	g_clear_error(&gerr);

	session_unref(callback->session);
	g_free(callback);
	return FALSE;
}
コード例 #4
0
ファイル: session.c プロジェクト: Commers/obexd
static void session_terminate_transfer(struct session_data *session,
					struct transfer_data *transfer,
					GError *gerr)
{
	struct session_callback *callback = session->callback;

	if (callback) {
		callback->func(session, gerr, callback->data);
		return;
	}

	session_ref(session);

	transfer_unregister(transfer);

	if (session->pending)
		session_request(session, session_prepare_put,
				session->pending->data);

	session_unref(session);
}
コード例 #5
0
ファイル: media_sinker.c プロジェクト: dulton/nampu
static __inline__ void
fin_self(media_sinker *sinker)
{
	LOCK_DEL(sinker->lock);

	if (sinker->host)
	{
		session_unref(sinker->host);
	}

	if(sinker->medium)
	{
		media_unref(sinker->medium);
	}

	atomic_dec(&media_sinker_objs);
	LOG_V(
		"Media sinker objs count: %d.",
		atomic_get(&media_sinker_objs)
	);
}
コード例 #6
0
ファイル: session.c プロジェクト: Commers/obexd
static void search_callback(uint8_t type, uint16_t status,
			uint8_t *rsp, size_t size, void *user_data)
{
	struct callback_data *callback = user_data;
	unsigned int scanned, bytesleft = size;
	int seqlen = 0;
	uint8_t dataType, channel = 0;
	GError *gerr = NULL;

	if (status || type != SDP_SVC_SEARCH_ATTR_RSP)
		goto failed;

	scanned = sdp_extract_seqtype(rsp, bytesleft, &dataType, &seqlen);
	if (!scanned || !seqlen)
		goto failed;

	rsp += scanned;
	bytesleft -= scanned;
	do {
		sdp_record_t *rec;
		sdp_list_t *protos;
		int recsize, ch = -1;

		recsize = 0;
		rec = sdp_extract_pdu(rsp, bytesleft, &recsize);
		if (!rec)
			break;

		if (!recsize) {
			sdp_record_free(rec);
			break;
		}

		if (!sdp_get_access_protos(rec, &protos)) {
			ch = sdp_get_proto_port(protos, RFCOMM_UUID);
			sdp_list_foreach(protos,
					(sdp_list_func_t) sdp_list_free, NULL);
			sdp_list_free(protos, NULL);
			protos = NULL;
		}

		sdp_record_free(rec);

		if (ch > 0) {
			channel = ch;
			break;
		}

		scanned += recsize;
		rsp += recsize;
		bytesleft -= recsize;
	} while (scanned < size && bytesleft > 0);

	if (channel == 0)
		goto failed;

	callback->session->channel = channel;

	callback->session->io = rfcomm_connect(&callback->session->src,
						&callback->session->dst,
						channel, rfcomm_callback,
						callback);
	if (callback->session->io != NULL) {
		sdp_close(callback->sdp);
		return;
	}

failed:
	sdp_close(callback->sdp);

	g_set_error(&gerr, OBEX_IO_ERROR, -EIO,
					"Unable to find service record");
	callback->func(callback->session, gerr, callback->data);
	g_clear_error(&gerr);

	session_unref(callback->session);
	g_free(callback);
}