* @brief Processes a JSON "raw" command that forwards base64 data to the device. */
| 941 | * @brief Processes a JSON "raw" command that forwards base64 data to the device. |
| 942 | */ |
| 943 | void API::Server::processRawJsonCommand(QTcpSocket* socket, |
| 944 | ConnectionState& state, |
| 945 | const QJsonObject& json) |
| 946 | { |
| 947 | Q_ASSERT(socket); |
| 948 | |
| 949 | const QString id = json.value(QStringLiteral("id")).toString(); |
| 950 | |
| 951 | if (!json.contains(QStringLiteral("data"))) { |
| 952 | sendResponseToSocket( |
| 953 | socket, |
| 954 | CommandResponse::makeError( |
| 955 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: data")) |
| 956 | .toJsonBytes()); |
| 957 | return; |
| 958 | } |
| 959 | |
| 960 | const QString dataStr = json.value(QStringLiteral("data")).toString(); |
| 961 | const QByteArray rawData = QByteArray::fromBase64(dataStr.toUtf8()); |
| 962 | if (rawData.isEmpty() && !dataStr.isEmpty()) { |
| 963 | sendResponseToSocket( |
| 964 | socket, |
| 965 | CommandResponse::makeError(id, ErrorCode::InvalidParam, QStringLiteral("Invalid base64 data")) |
| 966 | .toJsonBytes()); |
| 967 | return; |
| 968 | } |
| 969 | |
| 970 | if (rawData.size() > kMaxApiRawBytes) { |
| 971 | qWarning() << "[API] Raw data size limit exceeded:" << state.peerAddress << ":" |
| 972 | << state.peerPort << "- Raw data size:" << rawData.size() |
| 973 | << "- Limit:" << kMaxApiRawBytes; |
| 974 | |
| 975 | sendResponseToSocket( |
| 976 | socket, |
| 977 | CommandResponse::makeError( |
| 978 | id, ErrorCode::ExecutionError, QStringLiteral("Raw payload exceeds size limit")) |
| 979 | .toJsonBytes()); |
| 980 | return; |
| 981 | } |
| 982 | |
| 983 | if (!authorizeDeviceWrite()) { |
| 984 | sendResponseToSocket(socket, |
| 985 | CommandResponse::makeError(id, |
| 986 | ErrorCode::ExecutionError, |
| 987 | QStringLiteral("Device write denied by user")) |
| 988 | .toJsonBytes()); |
| 989 | return; |
| 990 | } |
| 991 | |
| 992 | auto& manager = IO::ConnectionManager::instance(); |
| 993 | if (!manager.isConnected()) { |
| 994 | sendResponseToSocket( |
| 995 | socket, |
| 996 | CommandResponse::makeError(id, ErrorCode::ExecutionError, QStringLiteral("Not connected")) |
| 997 | .toJsonBytes()); |
| 998 | return; |
| 999 | } |
| 1000 |
nothing calls this directly
no test coverage detected