📄 object.c
字号:
** If non body headers exist, we must send them. */ fsmState = OBJECT_FSM_SEND_NONBODY; } else { /* ** No non-body headers, we're free to send body headers. */ fsmState = OBJECT_FSM_SEND_BODY; } break; /* ** Send the non-body headers, if any, associated with this object. */ case OBJECT_FSM_SEND_NONBODY: OBXDBGINFO(("iobxObjectSendObject() sending non body headers...\n")); iterator = iobxIteratorReset( iterator ); while ( iobxIteratorHasNext( iterator ) && rc == OBX_RC_OK ) { if ( (header = (ObxHeader *)iobxIteratorNext( iterator )) ) { /* ** Send each non body header (if it's not already sent). ** If we send, reduce our available send ammount. */ if ( header->state != STATE_SENT && header->identifier != OBEX_HEADER_BODY && header->identifier != OBEX_HEADER_BODY_END ) { sendLength -= iobxHeaderSize( header ); OBXDBGINFO(("iobxObjectSendObject() sending non body header %02x.\n", header->identifier)); rc = iobxHeaderSend( header, handle, OBEX_HEADER_SEND_ALL ); } } } fsmState = OBJECT_FSM_FINISH; break; /* ** Send the body header, if any, associated with this object. */ case OBJECT_FSM_SEND_BODY: OBXDBGINFO(("iobxObjectSendObject() sending body header\n")); iterator = iobxIteratorReset( iterator ); while ( iobxIteratorHasNext( iterator ) && sendLength > 0 ) { if ( (header = (ObxHeader *)iobxIteratorNext( iterator )) ) { if ( header->state != STATE_SENT ) { if ( header->identifier == OBEX_HEADER_BODY || header->identifier == OBEX_HEADER_BODY_END ) { OBXDBGINFO(("iobxObjectSendObject() sending body header %02x.\n", header->identifier)); thisHeaderSize = iobxHeaderSize( header ); rc = iobxHeaderSend( header, handle, sendLength ); sendLength -= thisHeaderSize; } } } } fsmState = OBJECT_FSM_FINISH; break; /* ** Finish up. */ case OBJECT_FSM_FINISH: iobxIteratorFree( iterator ); done = TRUE; break; } } return rc;}/*** The passed object is populated by reading from the transport layer associated with the** passed ObxHandle object.*/ObxRc iobxObjectRecvObject( ObxObject *object, ObxHandle *handle ) { ObxRc rc = OBX_RC_OK; unsigned short packetLen; int length, actual; ObxBuffer *buffer; ObxConnectMeta *connectMeta; ObxSetPathMeta *setpathMeta; ObxHeader *header; void *bytebuffer; OBXDBGFLOW(("iobxObjectRecvObject() entry, object=0x%08x\thandle=0x%08x\n", object, handle)); /* ** Inbound message format: ** ** 1 byte op-code (i.e. OBX_CMD_CONNECT, OBX_CMD_PUT, OBX_CMD_GET, etc ) ** 2 byte packet length (Entire message length, including the op-code and length bytes) ** ['n' meta bytes] (optional bytes. CONNECT/SETPATH have 'extra' bytes, bone head design) ** 'n' headers (optional headers) */ /* ** Read op code */ if ( (rc=handle->transport->recv( &handle->connectionId, &object->cmd, 1, &actual, FALSE )) == OBX_RC_OK ) { handle->lastRecv = object->cmd; OBXDBGINFO(("iobxObjectRecvObject() *** inbound *** opcode = %02x\n", object->cmd)); /* ** Read length */ if ( (rc=handle->transport->recv( &handle->connectionId, &packetLen, 2, &actual, FALSE )) == OBX_RC_OK ) { length = ntohs( packetLen ); OBXDBGINFO(("iobxObjectRecvObject() cmd length = %d\n", length)); /* ** We've got the opcode and length bytes... */ length -= 3; /* ** Meta bytes expected? If so, gobble them first. For some reason, the designers ** of Obex choose to put meta bytes in the frame instead of just using a variable length ** header. */ if ( handle->lastSent == OBEX_CMD_CONNECT || object->cmd == OBEX_CMD_CONNECT ) { OBXDBGINFO(("iobxObjectRecvObject() inbound command CONNECT or last sent was CONNECT\n")); /* ** We're either CONNECTing, or receiving a response from a prior CONNECT, thus ** we read meta bytes. */ if ( (connectMeta = (ObxConnectMeta *)malloc( sizeof(ObxConnectMeta) )) ) { OBXDBGBUF(("iobxObjectRecvObject() malloc, addr=0x%08x, len=%d.\n", connectMeta, sizeof(ObxConnectMeta))); if ( (rc=handle->transport->recv( &handle->connectionId, connectMeta, sizeof( ObxConnectMeta ), &actual, FALSE )) == OBX_RC_OK ) { object->meta.connectMeta = connectMeta; // MTU is still in NetworkByteOrder - we need to change that object->meta.connectMeta->max_packet_length = ntohs(connectMeta->max_packet_length); } else { OBXDBGERR(("[ERROR] iobxObjectRecvObject() error filling ObxConnectMeta structure!\n")); return rc; } } else { OBXDBGERR(("[ERROR] iobxObjectRecvObject() error obtaining ObxConnectMeta structure!\n")); return OBX_RC_ERR_MEMORY; } length -= sizeof( ObxConnectMeta ); } else if ( (object->cmd & ~OBEX_CMD_FINAL) == OBEX_CMD_SETPATH ) { OBXDBGINFO(("iobxObjectRecvObject() following SETPATH\n")); /* ** SetPath, too, causes us to expect meta bytes. */ if ( (setpathMeta = (ObxSetPathMeta *)malloc( sizeof(ObxSetPathMeta) )) ) { OBXDBGBUF(("iobxObjectRecvObject() malloc, addr=0x%08x, len=%d.\n", setpathMeta, sizeof(ObxSetPathMeta))); if ( (rc=handle->transport->recv( &handle->connectionId, setpathMeta, sizeof( ObxSetPathMeta ), &actual, FALSE )) == OBX_RC_OK ) { object->meta.setPathMeta = setpathMeta; } else { OBXDBGERR(("[ERROR] iobxObjectRecvObject() error filling ObxSetPathMeta structure!\n")); return rc; } } else { OBXDBGERR(("[ERROR] iobxObjectRecvObject() error obtaining ObxSetPathMeta structure!\n")); return OBX_RC_ERR_MEMORY; } length -= sizeof( ObxSetPathMeta ); } else { /* ** inbound cmd has no meta associated with it. */ } /* ** Any bytes expected? */ if ( length > 0 ) { /* ** Read any header information, gobble all of them. */ if ( (buffer = iobxBufNew( length )) ) { if ( !(bytebuffer=(void *)malloc(length)) ) { OBXDBGERR(("[ERROR] iobxObjectRecvObject() error creating bytebuffer!\n")); return OBX_RC_ERR_MEMORY; } OBXDBGBUF(("iobxObjectRecvObject() malloc, addr=0x%08x, len=%d.\n", bytebuffer, length)); if ( (rc=handle->transport->recv( &handle->connectionId, bytebuffer, length, &actual, FALSE )) == OBX_RC_OK ) { /* ** Build headers from the buffer (if any). */ iobxBufWrite( buffer, bytebuffer, actual ); while ( iobxBufSize( buffer ) > 0 && rc == OBX_RC_OK ) { if ( (header=iobxHeaderNewFromBuffer( buffer, object )) ) { rc = iobxObjectAddHeader( object, header, handle ); } else { OBXDBGERR(("[ERROR] iobxObjectRecvObject() error creating header from buffer contents.\n")); rc = OBX_RC_ERR_UNSPECIFIED; } } } else { OBXDBGERR(("[ERROR] iobxObjectRecvObject() unexpected return code reading object data!\n")); } free( bytebuffer ); free( buffer ); } else { OBXDBGERR(("[ERROR] iobxObjectRecvObject() error obtaining obxBuffer!\n")); rc = OBX_RC_ERR_MEMORY; } } else { // No bytes expected } } else { OBXDBGERR(("[ERROR] iobxObjectRecvObject() unexpected return code reading object length!\n")); } } else { OBXDBGERR(("[ERROR] iobxObjectRecvObject() unexpected return code reading object opcode!\n")); } return rc;}ObxRc iobxObjectSetConnectMeta( ObxObject *object, unsigned char version, unsigned char flags, unsigned short hbo_mtu ) { ObxRc rc = OBX_RC_OK; OBXDBGFLOW(("iobxObjectSetConnectMeta() entry, object=0x%08x\tobj->cmd=%02x\tversion=%02x\tflags=%02x\tmtu=%d\n", object,object->cmd,version,flags,hbo_mtu)); if ( object->cmd == OBEX_CMD_CONNECT || (object->cmd & ~OBEX_CMD_FINAL) == OBEX_RSP_SUCCESS ) { if ( (object->meta.connectMeta = (ObxConnectMeta *)malloc( sizeof(ObxConnectMeta) )) ) { OBXDBGBUF(("iobxObjectSetConnectMeta() malloc, addr=0x%08x, len=%d.\n", object->meta.connectMeta, sizeof(ObxConnectMeta) )); object->meta.connectMeta->flags = flags; object->meta.connectMeta->version = version; object->meta.connectMeta->max_packet_length = htons( hbo_mtu ); } else { OBXDBGERR(("[ERROR] iobxObjectSetConnectMeta() failure creating connectMeta structure.\n")); rc = OBX_RC_ERR_MEMORY; } } else { rc = OBX_RC_ERR_INAPPROPRIATE; } return rc;}ObxRc iobxObjectSetSetPathMeta( ObxObject *object, unsigned char flags, unsigned char constants ) { ObxRc rc = OBX_RC_OK; OBXDBGFLOW(("iobxObjectSetSetPathMeta() entry, object=0x%08x\tflags=%02x\tconstants=%02x\n",object,flags,constants)); if ( object->cmd == OBEX_CMD_SETPATH || (object->cmd & ~OBEX_CMD_FINAL) == OBEX_RSP_SUCCESS ) { if ( (object->meta.setPathMeta = (ObxSetPathMeta *)malloc( sizeof(ObxSetPathMeta) )) ) { OBXDBGBUF(("iobxObjectSetSetPathMeta() malloc, addr=0x%08x, len=%d.\n", object->meta.setPathMeta, sizeof(ObxSetPathMeta) )); object->meta.setPathMeta->constants = constants; object->meta.setPathMeta->flags = flags; } else { OBXDBGERR(("[ERROR] iobxObjectSetSetPathMeta() failure creating SetPath meta structure.\n")); rc = OBX_RC_ERR_MEMORY; } } else { rc = OBX_RC_ERR_INAPPROPRIATE; } return rc;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -