⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 obex.c

📁 这是Linux环境下的openobex
💻 C
📖 第 1 页 / 共 3 页
字号:
	return 1;}/** * OBEX_ObjectSetHdrOffset - Set headeroffset * @object: OBEX object * @offset: Desired offset * * Call this function when you get a OBEX_EV_REQHINT and you know that the * command has data before the headers comes. You do NOT need to use this * function on Connect and SetPath, they are handled automatically. */int OBEX_ObjectSetHdrOffset(obex_object_t *object, unsigned int offset){	obex_return_val_if_fail(object != NULL, -1);	object->headeroffset = offset;	return 1;}/** * OBEX_UnicodeToChar - Simple unicode to char function. * @c: Destination (char) * @uc: Source (unicode) * @size: Length of destination buffer, at least half the size of source * * Buffers may not overlap. Returns -1 on error. */int OBEX_UnicodeToChar(uint8_t *c, const uint8_t *uc, int size){	int n;	DEBUG(4, "\n");			obex_return_val_if_fail(uc != NULL, -1);	obex_return_val_if_fail(c != NULL, -1);	// Make sure buffer is big enough!	for(n = 0; uc[n*2+1] != 0; n++);	obex_return_val_if_fail(n < size, -1);	for(n = 0; uc[n*2+1] != 0; n++)		c[n] = uc[n*2+1];	c[n] = 0;		return 0;}/** * OBEX_CharToUnicode - Simple char to unicode function. * @uc: Destination (unicode) * @c: Source (char) * @size: Length of destination buffer, at least twice the size of source * * Buffers may not overlap. Returns -1 on error. */int OBEX_CharToUnicode(uint8_t *uc, const uint8_t *c, int size){	int len, n;	DEBUG(4, "\n");	obex_return_val_if_fail(uc != NULL, -1);	obex_return_val_if_fail(c != NULL, -1);	len = n = strlen((char *) c);	obex_return_val_if_fail(n*2+2 <= size, -1);	uc[n*2+1] = 0;	uc[n*2] = 0;	while(n--) {		uc[n*2+1] = c[n];		uc[n*2] = 0;	}	return (len*2)+2 ;}/** * OBEX_ResponseToString - Return a human understandable string from a response-code. * @rsp: Response code. * * The returned char must not be freed. Returns %NULL on error. */char *OBEX_ResponseToString(int rsp){	DEBUG(4, "\n");	return obex_response_to_string(rsp);}/** * OBEX_GetResponseMessage - Return a human understandable string from a response-code. * @self: OBEX handle * @rsp: Response code. * * The returned char must not be freed. Returns %NULL on error. */char* OBEX_GetResponseMessage(obex_t *self, int rsp){	DEBUG(4, "\n");	return obex_response_to_string(rsp);}/* ---------------------------------------------------------------- *//** * OBEX_SetCustomData - Set customdata of an OBEX handle * @self: OBEX handle * @data: Custom Transport data * * Note : this call is *reserved* to the Custom Transport and should not * be use by the user/client. It allow to update the Custom Transport data * originally set via OBEX_RegisterCTransport(). * The Custom Transport data (or instance handle) is used to store data * relative to the specific instance (i.e. connection), such as file * descriptors, offsets and others, so that the Custom Transport can manage * multiple connections transparently (i.e. without a lookup table). * - Jean II */void OBEX_SetCustomData(obex_t *self, void * data){	obex_return_if_fail(self != NULL);	self->ctrans.customdata = data;}/** * OBEX_GetCustomData - Read the customdata from an OBEX handle * @self: OBEX handle * * Returns Custom Transport data */void * OBEX_GetCustomData(obex_t *self){	obex_return_val_if_fail(self != NULL, 0);	return self->ctrans.customdata;}/** * InOBEX_ServerRegister - Start listening for incoming connections * @self: OBEX handle * * An easier server function to use for TCP/IP (InOBEX) only. * * Returns -1 on error. */int InOBEX_ServerRegister(obex_t *self){	DEBUG(3, "\n");	obex_return_val_if_fail(self != NULL, -1);	inobex_prepare_listen(self);	return obex_transport_listen(self);}/** * InOBEX_TransportConnect - Connect Inet transport * @self: OBEX handle * * An easier connect function to use for TCP/IP (InOBEX) only. * * Note : I would like feedback on this API to know which input * parameter make most sense. Thanks... */int InOBEX_TransportConnect(obex_t *self, struct sockaddr *saddr, int addrlen){     	DEBUG(4, "\n");	obex_return_val_if_fail(self != NULL, -1);	if (self->object)	{		DEBUG(1, "We are busy.\n");		return -EBUSY;	}	obex_return_val_if_fail(saddr != NULL, -1);	inobex_prepare_connect(self, saddr, addrlen);	return obex_transport_connect_request(self);}/** * IrOBEX_ServerRegister - Start listening for incoming connections * @self: OBEX handle * @service: Service to bind to. * * An easier server function to use for IrDA (IrOBEX) only. * * Returns -1 on error. */int IrOBEX_ServerRegister(obex_t *self, const char *service){	DEBUG(3, "\n");	obex_return_val_if_fail(self != NULL, -1);	obex_return_val_if_fail(service != NULL, -1);#ifdef HAVE_IRDA	irobex_prepare_listen(self, service);	return obex_transport_listen(self);#else	return -ESOCKTNOSUPPORT;#endif /* HAVE_IRDA */}/** * IrOBEX_TransportConnect - Connect Irda transport * @self: OBEX handle * @service: IrIAS service name to connect to * * An easier connect function to use for IrDA (IrOBEX) only. */int IrOBEX_TransportConnect(obex_t *self, const char *service){     	DEBUG(4, "\n");	obex_return_val_if_fail(self != NULL, -1);	if (self->object)	{		DEBUG(1, "We are busy.\n");		return -EBUSY;	}#ifdef HAVE_IRDA	irobex_prepare_connect(self, service);	return obex_transport_connect_request(self);#else	return -ESOCKTNOSUPPORT;#endif /* HAVE_IRDA */}/** * BtOBEX_ServerRegister - Start listening for incoming connections * @self: OBEX handle * @service: Service to bind to. **FIXME** * * An easier server function to use for Bluetooth (Bluetooth OBEX) only.  * * Returns -1 on error. */int BtOBEX_ServerRegister(obex_t *self, bdaddr_t *src, uint8_t channel){	DEBUG(3, "\n");	obex_return_val_if_fail(self != NULL, -1);#ifdef HAVE_BLUETOOTH	if(src == NULL)		src = BDADDR_ANY;	btobex_prepare_listen(self, src, channel);	return obex_transport_listen(self);#else	return -ESOCKTNOSUPPORT;#endif /* HAVE_BLUETOOTH */}/** *  BtOBEX_TransportConnect - Connect Bluetooth transport *  @self: OBEX handle *  @service: IrIAS service name to connect to **FIXME** * *  An easier connect function to use for Bluetooth (Bluetooth OBEX) only.  */int BtOBEX_TransportConnect(obex_t *self, bdaddr_t *src, bdaddr_t *dst, uint8_t channel){	DEBUG(4, "\n");	obex_return_val_if_fail(self != NULL, -1);	if (self->object)	{		DEBUG(1, "We are busy.\n");		return -EBUSY;	}	obex_return_val_if_fail(dst != NULL, -1);#ifdef HAVE_BLUETOOTH	if(src == NULL)		src = BDADDR_ANY;	btobex_prepare_connect(self, src, dst, channel);	return obex_transport_connect_request(self);#else	return -ESOCKTNOSUPPORT;#endif /* HAVE_BLUETOOTH */}/* * FdOBEX_TransportSetup - setup descriptors for OBEX_TRANS_FD transport *  *  @self: OBEX handle *  @rfd: descriptor to read *  @wfd: descriptor to write *  @mtu: transport mtu: 0 - default */int FdOBEX_TransportSetup(obex_t *self, int rfd, int wfd, int mtu){	DEBUG(4, "\n");	obex_return_val_if_fail(self != NULL, -1);	if (self->object)	{		DEBUG(1, "We are busy.\n");		return -EBUSY;	}	self->fd = rfd;	self->writefd = wfd;	self->trans.mtu = mtu ? mtu : self->mtu_tx_max;	return obex_transport_connect_request(self);}/** *  OBEX_InterfaceConnect - Connect USB interface *  @self: OBEX handle *  @interface: USB interface to connect to * *  An easier connect function to connect to a discovered interface (currently *  USB OBEX only).  */int OBEX_InterfaceConnect(obex_t *self, obex_interface_t *interface){	DEBUG(4, "\n");	obex_return_val_if_fail(self != NULL, -1);	if (self->object) {		DEBUG(1, "We are busy.\n");		return -EBUSY;	}	obex_return_val_if_fail(interface != NULL, -1);	switch (self->trans.type) {	case OBEX_TRANS_USB:		obex_return_val_if_fail(interface->usb.interface != NULL, -1);#ifdef HAVE_USB		usbobex_prepare_connect(self, interface->usb.interface);		return obex_transport_connect_request(self);#else		return -ESOCKTNOSUPPORT;#endif /* HAVE_USB */	default:		return -ESOCKTNOSUPPORT;	}}/** *  OBEX_FindInterfaces - Get a list of OBEX interfaces on the system *  @self: OBEX handle *  @interfaces: A list of OBEX interfaces * *  Gets a list of OBEX interfaces, or NULL if there are none. */int OBEX_FindInterfaces(obex_t *self, obex_interface_t **interfaces){	DEBUG(4, "\n");	OBEX_FreeInterfaces(self);	switch (self->trans.type) {	case OBEX_TRANS_USB:#ifdef HAVE_USB		self->interfaces_number = usbobex_find_interfaces(&self->interfaces);#endif		break;	default:		break;	}	*interfaces = self->interfaces;	return self->interfaces_number;}/** *  OBEX_FreeInterfaces - free memory allocated to OBEX interface structures *  @self: OBEX handle * *  Frees memory allocated to OBEX interface structures after it has been  *  allocated by OBEX_FindInterfaces. */void OBEX_FreeInterfaces(obex_t *self){	switch (self->trans.type) {	case OBEX_TRANS_USB:#ifdef HAVE_USB		usbobex_free_interfaces(self->interfaces_number, self->interfaces);#endif		break;	default:		break;	}	self->interfaces_number = 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -