void UClientFuncPath::handleNewData(USmlTag * tag) { if (tag->isTagA("pathGetErr") ) handlePathGetMsg(tag); else printReply(tag, "UClientFuncPath::handleNewData: not mine"); }
void UClientFuncSimScan::handleNewData(USmlTag * tag) { // distribute to sub-functions if (tag->isTagA("scanGet")) handleLaserScan(tag); else printReply(tag, "UClientFuncSimScan::handleNewData: not mine"); }
void UResLaserIfObst::handleNewData(USmlTag * tag) { if (tag->isTagA("obst") ) handleObst(tag); else printReply(tag, "UResLaserIfObst::handleNewData: not mine"); msgHandled++; }
/** * Отправка команды ABOR. * * @return Флаг успешности выполнения (0 - не успешно, другое - успешно). */ int ProtocolInterpreter::sendAbor() { service->printMessage(0, "ABOR\n"); commandBuffer = "ABOR\r\n"; result = send(connectionSocket, commandBuffer.c_str(), commandBuffer.length(), 0); if (result == SOCKET_ERROR) { service->printMessage(2, "ABOR sending error!"); closesocket(connectionSocket); WSACleanup(); return 0; } printReply(); if (strstr(replyBuffer, "426 ")) { // Ненормальное завершение команды (вернется еще один отклик) printReply(); } if (strstr(replyBuffer, "225 ") || strstr(replyBuffer, "226 ")) { return 1; } else { return 0; } }
/** * Отправка команды LIST. * * @return Флаг успешности выполнения (0 - не успешно, другое - успешно). */ int ProtocolInterpreter::sendList() { if (path == "#") { commandBuffer = "LIST\r\n"; service->printMessage(0, "LIST\n"); } else { commandBuffer = "LIST " + path + "\r\n"; service->printMessage(0, "LIST " + path + "\n"); } result = send(connectionSocket, commandBuffer.c_str(), commandBuffer.length(), 0); if (result == SOCKET_ERROR) { service->printMessage(2, "LIST sending error!"); closesocket(connectionSocket); WSACleanup(); return 0; } udtp->setPassive(passive); udtp->setAddress(address); if (passive) { if (strstr(replyBuffer, "227 ")) { setPort(); udtp->setPort(port); udtp->openConnection(); } else { service->printMessage(2, "You should run PASV command first."); return 0; } } else { udtp->setPort(port); connection = CreateThread(NULL, 0, startDTP, this, 0, NULL); } udtp->setPath(path); udtp->fullList(); printReply(); printReply(); if (strstr(replyBuffer, "226 ")) { return 1; } else { return 0; } }
/** * Отправка команды QUIT. * * @return Флаг успешности выполнения (0 - не успешно, другое - успешно). */ int ProtocolInterpreter::sendQuit() { service->printMessage(0, "QUIT\n"); commandBuffer = "QUIT\r\n"; result = send(connectionSocket, commandBuffer.c_str(), commandBuffer.length(), 0); if (result == SOCKET_ERROR) { service->printMessage(2, "QUIT sending error!"); closesocket(connectionSocket); WSACleanup(); return 0; } printReply(); if (strstr(replyBuffer, "221 ")) { return 1; } else { return 0; } }
/** * Отправка команды PASS. * * @return Флаг успешности выполнения (0 - не успешно, другое - успешно). */ int ProtocolInterpreter::sendPass() { service->printMessage(0, "PASS " + password + "\n"); commandBuffer = "PASS " + password + "\r\n"; result = send(connectionSocket, commandBuffer.c_str(), commandBuffer.length(), 0); if (result == SOCKET_ERROR) { service->printMessage(2, "Additional information sending error!"); closesocket(connectionSocket); WSACleanup(); return 0; } printReply(); if (strstr(replyBuffer, "530 ")) { // Превышено максимальное кол-во возможных соединений exit(1); } else { return 1; } }
/** * Отправка команды USER. * * @return Флаг успешности выполнения (0 - не успешно, 1 - требуется дополнительная * информация в качестве пароля, другое - успешно). */ int ProtocolInterpreter::sendUser() { service->printMessage(0, "USER " + user + "\n"); commandBuffer = "USER " + user + "\r\n"; result = send(connectionSocket, commandBuffer.c_str(), commandBuffer.length(), 0); if (result == SOCKET_ERROR) { service->printMessage(2, "USER sending error!"); closesocket(connectionSocket); WSACleanup(); return 0; } printReply(); if (strstr(replyBuffer, "331 ")) { // Требуется ввод дополнительной информации в качестве пароля (например, E-Mail-адрес) return 1; } else if (strstr(replyBuffer, "230 ")) { return 2; } else { return 0; } }
/** * Отправка команды STAT. * * @return Флаг успешности выполнения (0 - не успешно, другое - успешно). */ int ProtocolInterpreter::sendStat() { if (path == "#") { service->printMessage(0, "STAT\n"); commandBuffer = "STAT\r\n"; } else { service->printMessage(0, "STAT " + path + "\n"); commandBuffer = "STAT " + path + "\r\n"; } result = send(connectionSocket, commandBuffer.c_str(), commandBuffer.length(), 0); if (result == SOCKET_ERROR) { service->printMessage(2, "STAT sending error!"); closesocket(connectionSocket); WSACleanup(); return 0; } printReply(); if (strstr(replyBuffer, "211 ") || strstr(replyBuffer, "212 ") || strstr(replyBuffer, "213 ")) { return 1; } else { return 0; } }
/** * Отправка команды STOR. * * @return Флаг успешности выполнения (0 - не успешно, другое - успешно). */ int ProtocolInterpreter::sendStor() { udtp->setAddress(address); udtp->setPath(path); udtp->setPassive(passive); if (passive) { if (strstr(replyBuffer, "227 ")) { setPort(); udtp->setPort(port); udtp->openConnection(); } else { service->printMessage(2, "You should run PASV command first."); return 0; } } else { udtp->setPort(port); connection = CreateThread(NULL, 0, startDTP, this, 0, NULL); } service->printMessage(0, "STOR " + path + "\n"); commandBuffer = "STOR " + path + "\r\n"; result = send(connectionSocket, commandBuffer.c_str(), commandBuffer.length(), 0); if (result == SOCKET_ERROR) { service->printMessage(2, "STOR sending error!"); closesocket(connectionSocket); WSACleanup(); return 0; } printReply(); if (strstr(replyBuffer, "550 ") || strstr(replyBuffer, "553 ")) { // Отсутствуют права return 0; } else if (strstr(replyBuffer, "425 ")) { if (passive) { udtp->closeConnection(); service->printMessage(1, "Passive mode using failed! Try active mode."); sendCommand("PORT"); passive = 0; udtp->setPassive(passive); udtp->setPort(port); connection = CreateThread(NULL, 0, startDTP, this, 0, NULL); sendCommand("STOR"); } else { TerminateThread(connection, 1); CloseHandle(connection); service->printMessage(1, "Active mode using failed! Try passive mode."); sendCommand("PASV"); passive = 1; udtp->setPassive(passive); setPort(); udtp->setPort(port); udtp->openConnection(); sendCommand("STOR"); } } else { udtp->store(); printReply(); } if (strstr(replyBuffer, "226 ") || strstr(replyBuffer, "250 ")) { return 1; } else { return 0; } }
void UClientFuncPath::handlePathPolygonData(USmlTag * iTag) { bool result; USmlTag tag; const int MSL = 100; char att[MAX_SML_NAME_LENGTH]; char val[MSL]; int n, cnt = 0; //bool hasEdge = false; UPosition * pos; UTime t; bool * isObst; // iTag->getNextTag(&tag, 200); result = tag.isTagA("UProbPoly"); if (not result) { // unknown tag printReply(&tag, "UClientFuncPath::handlePathPolygonData: not mine?"); // skip the rest until endtag. if (tag.isAStartTag()) tag.skipToEndTag(200); } if (result and not tag.isAStartTag()) { // is just a message or a false result = false; tag.print(""); } if (result) { // read size while (tag.getNextAttribute(att, val, MSL)) { if (strcasecmp(att, "count") == 0) n = sscanf(val, "%d", &cnt); else if (strcasecmp(att, "obstFlags") == 0) ; //hasEdge = str2bool(val); } result = (cnt > 0); } if (result) { // now get the guts of the message // that is either time or polygon data pos = poly->getPoints(); isObst = poly->getIsObst(); n = 0; while (iTag->getNextTag(&tag, 200)) { if (tag.isTagA("pos2db")) { pos->z=0.0; while (tag.getNextAttribute(att, val, MSL)) { // read 2d position with obstacle flag if (strcasecmp(att, "x") == 0) sscanf(val, "%le", &pos->x); if (strcasecmp(att, "y") == 0) sscanf(val, "%le", &pos->y); if (strcasecmp(att, "obst") == 0) *isObst = str2bool(val); } // debug //if (verboseMessages) // printf("Got %d pos2db at %f,%f obst(%s)\n", // n, pos->x, pos->y, bool2str(*isObst)); // debug if (n < poly->getPointsMax()) { // advance --- if space n++; pos++; isObst++; } } else if (tag.isTagA("time")) { tag.getTime(&t); poly->setTime(t); // debug //if (verboseMessages) // printf("Got time\n"); // debug end } else { // either an unknown extra information or an end tag if (tag.isAnEndTag()) break; if (tag.isAStartTag()) // extra grouped info tag.skipToEndTag(200); } } poly->setPointsCnt(n); result = n > 0; // debug //if (verboseMessages) // printf("Got %d positions in polygon\n", n); // debug end } if (result) newDataAvailable(poly); }