void BoshXMPPConnection::onFeatures2 (ConnectingOp * op, Error result) { if (result) { return finalize (result, op); } op->setState (ConnectingOp::WAIT_BIND); LOG_STATE ("WAIT_BIND"); function <void (Error, const String &)> xx = aOpMemFun (op, &BoshXMPPConnection::onResourceBind); result = op->stream->bindResource(mDetails.resource, aOpMemFun (op, &BoshXMPPConnection::onResourceBind)); if (result) return finalize (result, op); addAsyncOp (op); }
void BoshXMPPConnection::onFeatures (ConnectingOp * op, Error result) { if (result) { return finalize (result, op); } if (!op->withLogin) { // Yeah return finalize (NoError, op); } op->setState (ConnectingOp::WAIT_LOGIN); LOG_STATE ("WAIT_LOGIN"); result = op->stream->authenticate(mDetails.username, mDetails.password, aOpMemFun (op, &BoshXMPPConnection::onLogin)); if (result) return finalize (result, op); addAsyncOp (op); }
void BoshXMPPConnection::onLogin (ConnectingOp * op, Error result) { if (result) { return finalize (result, op); } op->setState (ConnectingOp::WAIT_FEATURE2); op->transport->restart(); op->stream->startInitAfterHandshake(op->transport); result = op->stream->waitFeatures(aOpMemFun (op, &BoshXMPPConnection::onFeatures2)); if (result) return finalize (result, op); LOG_STATE ("WAIT_FEATURE2"); // Note: Internal state, not external state setState (IMClient::CS_AUTHENTICATING); addAsyncOp (op); }
void BoshXMPPConnection::onBoshConnect (Error result, AsyncOpId id) { ConnectingOp * op; getReadyAsyncOpInState (id, CONNECT_OP, ConnectingOp::WAIT_BOSH_CONNECT, &op); if (!op) return; if (result) { return finalize (result, op); } op->stream->startInitAfterHandshake(op->transport); op->setState (ConnectingOp::WAIT_FEATURE); LOG_STATE ("WAIT_FEATURE"); result = op->stream->waitFeatures(aOpMemFun (op, &BoshXMPPConnection::onFeatures)); if (result) return finalize (result, op); addAsyncOp (op); }
void BoshXMPPConnection::onResourceBind (ConnectingOp * op, Error result, const String& fullJid) { if (result) { return finalize (result, op); } String expectedId = mDetails.fullId(); if (fullJid != mDetails.fullId()){ // Forbit this: Full JID must be predictable in order to get crypt/authentication working. Log (LogWarning) << LOGID << "Bound to wrong full jid! expected: " << expectedId << " found: " << fullJid << std::endl; return finalize (error::BadProtocol, op); } op->setState (ConnectingOp::WAIT_SESSION); LOG_STATE ("WAIT_SESSION"); result = op->stream->startSession(aOpMemFun (op, &BoshXMPPConnection::onStartSession)); if (result) return finalize (result, op); addAsyncOp (op); }
void BoshXMPPConnection::onStartSession (ConnectingOp * op, Error result) { LOG_STATE ("READY"); // we are through it finalize (result, op); }
int __attribute__((noreturn)) yflash(uint32_t blk_offs, unsigned int blk_size, const struct magic * magic) { struct { struct magic_hdr hdr; struct magic_rec rec[MAGIC_REC_MAX]; } magic_buf; struct ymodem_rcv ry; unsigned int cnt; uint32_t offs; int ret; int i; if (magic != 0) { /* copy magic check block */ cnt = magic->hdr.cnt > MAGIC_REC_MAX ? MAGIC_REC_MAX : magic->hdr.cnt; for (i = 0; i < cnt; ++i) { // usb_send(CDC_TX_EP, "\r\nmagic.", 8); magic_buf.rec[i] = magic->rec[i]; } magic_buf.hdr.cnt = cnt; magic_buf.hdr.pos = magic->hdr.pos; } else { magic_buf.hdr.cnt = 0; magic_buf.hdr.pos = 0; } DCC_LOG(LOG_TRACE, "flash_unlock()"); LOG_CODE(0); LOG_STATE(0); #if 0 if (opt & XFLASH_OPT_BYPASS) { PUTS(s_ok); usb_drain(CDC_TX_EP); return 55; } #endif do { PUTS(s_ymodem); ymodem_rcv_init(&ry); ry.fsize = blk_size; offs = blk_offs; cnt = 0; flash_unlock(); while ((ret = usb_ymodem_rcv_pkt(&ry)) >= 0) { DCC_LOG1(LOG_TRACE, "usb_ymodem_rcv_pkt() ret=%d)", ret); #if XMODEM_FALLBACK if ((ret == 0) && (ry.xmodem)) { LOG_CODE(1); break; } #endif int len = ret; if (ry.pktno == 1) { char * cp; int fsize; cp = (char *)ry.pkt.data; while (*cp != '\0') cp++; cp++; /* skip null */ fsize = dec2int(cp); if (fsize == 0) { LOG_CODE(2); break; } ry.fsize = fsize; } else { if (ry.pktno == 2) { if (!magic_match((struct magic *)&magic_buf, cnt, ry.pkt.data, len)) { DCC_LOG(LOG_WARNING, "invalid file magic!"); #if XFLASH_VERBOSE usb_ymodem_rcv_cancel(&ry); delay(1000); PUTS(s_invalid); #endif LOG_CODE(3); ret = -3; break; } // flash_erase(offs, ry->fsize); } DCC_LOG2(LOG_TRACE, "flash_erase(offs=0x%06x, len=%d)", offs, len); if ((ret = flash_erase(offs, len)) < 0) { DCC_LOG(LOG_WARNING, "flash_erase() failed!"); #if XFLASH_VERBOSE usb_ymodem_rcv_cancel(&ry); delay(1000); PUTS(s_erase); #endif LOG_CODE(4 + (-ret * 0x10000)); ret = -4; break; } DCC_LOG(LOG_TRACE, "flash_write()"); if ((ret = flash_write(offs, ry.pkt.data, len)) < 0) { DCC_LOG(LOG_WARNING, "flash_write() failed!"); #if XFLASH_VERBOSE usb_ymodem_rcv_cancel(&ry); delay(1000); PUTS(s_program); #endif LOG_CODE(5); ret = -5; break; } offs += len; cnt += len; LOG_STATE(cnt); } } // if (opt & XFLASH_OPT_RET_ERR) { // return ret; // } } while ((ret < 0) || (cnt == 0)); PUTS(s_ok); usb_drain(CDC_TX_EP); // if (opt & XFLASH_OPT_RESET) { delay(3000); reset(); // } // return 0; }