Merge branch 'master' of gitee.com:openharmony/print_print_fwk into master

Signed-off-by: 梁瑾 <liangjin16@huawei.com>
This commit is contained in:
梁瑾 2024-08-28 08:28:27 +00:00 committed by Gitee
commit 9ba248d973
2 changed files with 53 additions and 39 deletions

View File

@ -227,54 +227,56 @@ Scan_ScannerOptions* CreateScannerOptions(int32_t &optionCount)
return scannerOptions;
}
bool CopySingleBuf(char* destBuf, const char* srcBuf, size_t bufferSize)
{
if (destBuf == nullptr) {
SCAN_HILOGW("CopySingleBuf new fail");
return false;
}
if (memset_s(destBuf, bufferSize, 0, bufferSize) != 0) {
SCAN_HILOGE("CopySingleBuf memset_s fail");
return false;
}
errno_t err = strncpy_s(destBuf, bufferSize, srcBuf, bufferSize);
if (err != 0) {
SCAN_HILOGE("CopySingleBuf strncpy_s fail");
return false;
}
return true;
}
bool MemSetScannerOptions(Scan_ScannerOptions* scannerOptions, int32_t &optionCount, ScanParaTable &paraTable)
{
for (int i = 0; i < optionCount; i++) {
auto bufferSize = paraTable.titBuff[i].length() + 1;
char* titleBuf = new(std::nothrow) char[bufferSize];
if (titleBuf == nullptr) {
FreeScannerOptionsMemory(scannerOptions);
char* titBuff = new(std::nothrow) char[bufferSize];
if (CopySingleBuf(titBuff, paraTable.titBuff[i].c_str(), bufferSize)) {
if (titBuff != nullptr) {
delete[] titBuff;
}
return false;
}
if (memset_s(titleBuf, bufferSize, 0, bufferSize) != 0) {
SCAN_HILOGW("memset_s fail");
FreeScannerOptionsMemory(scannerOptions);
return false;
}
errno_t err = strncpy_s(titleBuf, bufferSize, paraTable.titBuff[i].c_str(), bufferSize);
if (err != 0) {
SCAN_HILOGW("strncpy_s fail");
FreeScannerOptionsMemory(scannerOptions);
return false;
}
scannerOptions->titles[i] = titleBuf;
scannerOptions->titles[i] = titBuff;
bufferSize = paraTable.desBuff[i].length() + 1;
char* desBuf = new (std::nothrow) char[bufferSize];
if (desBuf == nullptr) {
FreeScannerOptionsMemory(scannerOptions);
char* desBuff = new (std::nothrow) char[bufferSize];
if (CopySingleBuf(desBuff, paraTable.desBuff[i].c_str(), bufferSize)) {
if (desBuff != nullptr) {
delete[] desBuff;
}
return false;
}
if (memset_s(desBuf, bufferSize, 0, bufferSize) != 0) {
SCAN_HILOGW("memset_s fail");
FreeScannerOptionsMemory(scannerOptions);
return false;
}
strncpy_s(desBuf, bufferSize, paraTable.desBuff[i].c_str(), bufferSize);
scannerOptions->descriptions[i] = desBuf;
scannerOptions->descriptions[i] = desBuff;
bufferSize = paraTable.rangesBuff[i].length() + 1;
char* rangeBuf = new (std::nothrow) char[bufferSize];
if (rangeBuf == nullptr) {
FreeScannerOptionsMemory(scannerOptions);
char* rangesBuff = new (std::nothrow) char[bufferSize];
if (CopySingleBuf(rangesBuff, paraTable.rangesBuff[i].c_str(), bufferSize)) {
if (rangesBuff != nullptr) {
delete[] rangesBuff;
}
return false;
}
if (memset_s(rangeBuf, bufferSize, 0, bufferSize) != 0) {
SCAN_HILOGW("memset_s fail");
FreeScannerOptionsMemory(scannerOptions);
return false;
}
strncpy_s(rangeBuf, bufferSize, paraTable.rangesBuff[i].c_str(), bufferSize);
scannerOptions->ranges[i] = rangeBuf;
free(rangeBuf);
scannerOptions->ranges[i] = rangesBuff;
free(rangesBuff);
}
return true;
}
@ -293,6 +295,7 @@ Scan_ScannerOptions* GetScanParaValue(ScanParaTable &paraTable)
}
if (!MemSetScannerOptions(scannerOptions, optionCount, paraTable)) {
SCAN_HILOGE("MemSetScannerOptions error");
FreeScannerOptionsMemory(scannerOptions);
return nullptr;
}
return scannerOptions;

View File

@ -299,8 +299,9 @@ void PrintCupsClient::CopyDirectory(const char *srcDir, const char *destDir)
chmod(destFilePath.c_str(), filestat.st_mode);
} else {
char realSrc[PATH_MAX] = {};
char destSrc[PATH_MAX] = {};
if (realpath(srcFilePath.c_str(), realSrc) == nullptr ||
realpath(destFilePath.c_str(), realSrc) == nullptr) {
realpath(destDir, destSrc) == nullptr) {
PRINT_HILOGE("The realSrc is null.");
continue;
}
@ -1673,14 +1674,24 @@ bool PrintCupsClient::IsIpConflict(const std::string &printerId, std::string &ni
return false;
}
bool isWifiConnected = false;
Wifi::WifiDevice::GetInstance(OHOS::WIFI_DEVICE_SYS_ABILITY_ID)->IsConnected(isWifiConnected);
auto wifiDevice = Wifi::WifiDevice::GetInstance(OHOS::WIFI_DEVICE_SYS_ABILITY_ID);
if (!wifiDevice) {
PRINT_HILOGE("wifiDevice GetInstance failed.");
return false;
}
wifiDevice->IsConnected(isWifiConnected);
PRINT_HILOGD("isWifiConnected: %{public}d", isWifiConnected);
Wifi::WifiP2pLinkedInfo p2pLinkedInfo;
Wifi::WifiP2p::GetInstance(OHOS::WIFI_P2P_SYS_ABILITY_ID)->QueryP2pLinkedInfo(p2pLinkedInfo);
PRINT_HILOGD("P2pConnectedState: %{public}d", p2pLinkedInfo.GetConnectState());
if (isWifiConnected && p2pLinkedInfo.GetConnectState() == Wifi::P2pConnectedState::P2P_CONNECTED) {
Wifi::IpInfo info;
Wifi::WifiDevice::GetInstance(OHOS::WIFI_DEVICE_SYS_ABILITY_ID)->GetIpInfo(info);
auto wifiDevice = Wifi::WifiDevice::GetInstance(OHOS::WIFI_DEVICE_SYS_ABILITY_ID);
if (!wifiDevice) {
PRINT_HILOGE("wifiDevice GetInstance failed.");
return false;
}
wifiDevice->GetIpInfo(info);
PRINT_HILOGD("wifi server ip: %{private}s", GetIpAddress(info.serverIp).c_str());
PRINT_HILOGD("p2p go ip: %{private}s", p2pLinkedInfo.GetGroupOwnerAddress().c_str());
if (GetIpAddress(info.serverIp) == p2pLinkedInfo.GetGroupOwnerAddress()) {