Esempio n. 1
0
/*
 * Function obex_transport_connect_request (self, service)
 *
 *    Try to connect transport
 *
 */
int obex_transport_connect_request(obex_t *self)
{
	int ret = -1;

	if (self->trans.connected)
		return 1;

	switch (self->trans.type) {
#ifdef HAVE_IRDA
	case OBEX_TRANS_IRDA:
		ret = irobex_connect_request(self);
		break;
#endif /*HAVE_IRDA*/
	case OBEX_TRANS_INET:
		/* needed as compat for apps that call OBEX_TransportConnect
		 * instead of InOBEX_TransportConnect (e.g. obexftp)
		 */
		if (self->trans.peer.inet6.sin6_family == AF_INET)
			inobex_prepare_connect(self,
					       (struct sockaddr*) &self->trans.peer.inet6,
					       sizeof(self->trans.peer.inet6));
		ret = inobex_connect_request(self);
		break;
	case OBEX_TRANS_CUSTOM:
		DEBUG(4, "Custom connect\n");
		if (self->ctrans.connect)
			ret = self->ctrans.connect(self, self->ctrans.customdata);
		else {
			DEBUG(4, "No connect-callback exist!\n");
		}
		DEBUG(4, "ret=%d\n", ret);
		break;
#ifdef HAVE_BLUETOOTH
	case OBEX_TRANS_BLUETOOTH:
		ret = btobex_connect_request(self);
		break;
#endif /*HAVE_BLUETOOTH*/
	case OBEX_TRANS_FD:
		/* no real connect on the file */
		if (self->fd != INVALID_SOCKET && self->writefd != INVALID_SOCKET)
			ret = 0;
		break;
#ifdef HAVE_USB
	case OBEX_TRANS_USB:
		ret = usbobex_connect_request(self);
		break;
#endif /*HAVE_USB*/
	default:
		DEBUG(4, "Transport not implemented!\n");
		break;
	}

	if (ret >= 0)
		self->trans.connected = TRUE;

	return ret;
}
Esempio n. 2
0
/**
	Connect TCP transport.
	\param self OBEX handle
	\param addr Address to connect to ([::1]:650 if NULL)
	\param addrlen Length of address structure
	\return -1 on error

	An easier connect function to use for TCP/IP (TcpOBEX) only.
	It supports IPv4 (AF_INET) and IPv6 (AF_INET6).
 */
LIB_SYMBOL
int CALLAPI TcpOBEX_TransportConnect(obex_t *self, struct sockaddr *addr, int addrlen)
{
	DEBUG(4, "\n");

	errno = EINVAL;
	obex_return_val_if_fail(self != NULL, -1);

	if (self->object) {
		DEBUG(1, "We are busy.\n");
		errno = EBUSY;
		return -1;
	}

	inobex_prepare_connect(self, addr, addrlen);

	return obex_transport_connect_request(self);
}