| 146 | } |
| 147 | |
| 148 | void startSessionLog(ClientProtocol protocol) { |
| 149 | withClientLock([&]() { |
| 150 | closeSessionLogUnlocked(); |
| 151 | |
| 152 | if (!bruceConfig.TerminalLog || !sdcardMounted) return; |
| 153 | |
| 154 | if (!SD.exists("/Bruce")) SD.mkdir("/Bruce"); |
| 155 | if (!SD.exists("/Bruce/Terminal")) SD.mkdir("/Bruce/Terminal"); |
| 156 | |
| 157 | String basePath = "/Bruce/Terminal/" + String(getProtocolName(protocol)) + "-" + |
| 158 | sanitizeSessionLogComponent(sessionHost); |
| 159 | for (uint16_t index = 1; index < 10000; ++index) { |
| 160 | String candidate = basePath + "_" + String(index) + ".log"; |
| 161 | if (SD.exists(candidate)) continue; |
| 162 | |
| 163 | sessionLogFile = SD.open(candidate, FILE_WRITE); |
| 164 | if (!sessionLogFile) return; |
| 165 | |
| 166 | sessionLogEnabled = true; |
| 167 | sessionLogPath = candidate; |
| 168 | |
| 169 | String header = "=== Bruce Terminal Session ===\n"; |
| 170 | header += "Protocol: " + String(getProtocolName(protocol)) + "\n"; |
| 171 | header += "Host: " + sessionHost + "\n"; |
| 172 | if (!sessionUser.isEmpty()) header += "User: " + sessionUser + "\n"; |
| 173 | header += "Port: " + String(sessionPort) + "\n"; |
| 174 | header += "Started at millis: " + String(millis()) + "\n"; |
| 175 | header += "==============================\n"; |
| 176 | appendSessionLogUnlocked(header.c_str(), header.length()); |
| 177 | return; |
| 178 | } |
| 179 | }); |
| 180 | } |
| 181 | |
| 182 | void setClientTaskHandle(TaskHandle_t handle) { |
| 183 | withClientLock([&]() { clientTaskHandle = handle; }); |
no test coverage detected