diff --git a/src/recon/ProtocolStructs.h b/src/recon/ProtocolStructs.h index 28f8a4c..351a139 100644 --- a/src/recon/ProtocolStructs.h +++ b/src/recon/ProtocolStructs.h @@ -17,4 +17,12 @@ struct TaskQueryResult bool Start ; }; +struct PACSSetting +{ + std::string AETitle; + std::string ServerAETitle; + std::string ServerIP; + int Port = 0;; +}; + #endif // __SCAN_H__ \ No newline at end of file diff --git a/src/recon/ReconClient.cpp b/src/recon/ReconClient.cpp index 9c5be99..63e97f2 100644 --- a/src/recon/ReconClient.cpp +++ b/src/recon/ReconClient.cpp @@ -10,6 +10,7 @@ namespace { const char* QUERY_VERSION_URL = "/Version/"; const char* QUERY_RECON_URL = "/Task/Query/"; const char* QUERY_TRANSFER_URL = "/Transfer/Query/"; + const char* SET_PACS_URL = "/Transfer/Setting/"; } namespace Recon { @@ -46,11 +47,13 @@ namespace Recon { content.append(str); free(str); auto resp = mRequest.post(mHost+CREATE_URL,content,mHeaders); - if (resp.httpCode() == 201){ + if (resp->httpCode() == 201){ + delete resp; return RequestResult::Success(); } else{ - mErrorMessage = resp.getContent(); + mErrorMessage = resp->getContent(); + delete resp; return RequestResult::Fail(mErrorMessage); } } @@ -65,8 +68,9 @@ namespace Recon { content.append(str); free(str); auto resp = mRequest.post(mHost+QUERY_SCAN_URL,content,mHeaders); - if (resp.httpCode() == 200){ - cJSON * scans = cJSON_Parse(resp.getContent().data()); + if (resp->httpCode() == 200){ + cJSON * scans = cJSON_Parse(resp->getContent().data()); + delete resp; int size = cJSON_GetArraySize(scans); if (size == 1){ cJSON * scaninf = cJSON_GetArrayItem(scans, 0); @@ -81,7 +85,8 @@ namespace Recon { return RequestResult::Fail(mErrorMessage); } else{ - mErrorMessage = resp.getContent(); + mErrorMessage = resp->getContent(); + delete resp; return RequestResult::Fail(mErrorMessage); } } @@ -96,16 +101,18 @@ namespace Recon { content.append(str); free(str); auto resp = mRequest.post(mHost+QUERY_RECON_URL,content,mHeaders); - if (resp.httpCode() == 204){ + if (resp->httpCode() == 204){ + delete resp; return RequestResult::Success(); } - else if (resp.httpCode() == 200){ - - aReconID = resp.getContent(); + else if (resp->httpCode() == 200){ + aReconID = resp->getContent(); + delete resp; return RequestResult::Success(aReconID); } else{ - mErrorMessage = resp.getContent(); + mErrorMessage = resp->getContent(); + delete resp; return RequestResult::Fail(mErrorMessage); } @@ -121,8 +128,9 @@ namespace Recon { content.append(str); free(str); auto resp = mRequest.post(mHost+QUERY_RECON_URL,content,mHeaders); - if (resp.httpCode() == 200){ - cJSON * task = cJSON_Parse(resp.getContent().data()); + if (resp->httpCode() == 200){ + cJSON * task = cJSON_Parse(resp->getContent().data()); + delete resp; aTask.ReconID = cJSON_GetObjectItem(task, "ReconID")->valuestring; aTask.ScanID= cJSON_GetObjectItem(task, "ScanID")->valuestring; aTask.Start = cJSON_GetObjectItem(task, "Start")->valueint!=0; @@ -131,7 +139,40 @@ namespace Recon { return RequestResult::Success(); } else{ - mErrorMessage = resp.getContent(); + mErrorMessage = resp->getContent(); + delete resp; + return RequestResult::Fail(mErrorMessage); + } + } + + RequestResult ReconClient::SetPACSSetting(const PACSSetting& aSetting) + { + cJSON * obj = cJSON_CreateObject(); + if (!aSetting.AETitle.empty()){ + cJSON_AddStringToObject(obj, "AETitle", aSetting.AETitle.c_str()); + } + if (!aSetting.ServerIP.empty()){ + cJSON_AddStringToObject(obj, "IP", aSetting.ServerIP.c_str()); + } + if (!aSetting.ServerAETitle.empty()){ + cJSON_AddStringToObject(obj, "ServerAETitle", aSetting.ServerAETitle.c_str()); + } + if (aSetting.Port>0){ + cJSON_AddNumberToObject(obj, "Port", aSetting.Port); + } + char* str = cJSON_Print(obj); + cJSON_Delete(obj); + std::string content; + content.append(str); + free(str); + auto resp = mRequest.post(mHost+SET_PACS_URL,content,mHeaders); + if (resp->httpCode() == 200){ + delete resp; + return RequestResult::Success(); + } + else{ + mErrorMessage = resp->getContent(); + delete resp; return RequestResult::Fail(mErrorMessage); } } diff --git a/src/recon/ReconClient.h b/src/recon/ReconClient.h index 4f41e26..01fe763 100644 --- a/src/recon/ReconClient.h +++ b/src/recon/ReconClient.h @@ -16,6 +16,7 @@ namespace Recon { RequestResult QueryReconID(const std::string& aScanID, std::string& aReconID); RequestResult QueryReconTask(const std::string& aReconID, TaskQueryResult& aTask); RequestResult QueryVersion(); + RequestResult SetPACSSetting(const PACSSetting& aSetting); private: std::string mVersionContent; diff --git a/thirdParty/Req/pub/include/Request.h b/thirdParty/Req/pub/include/Request.h index 136ea34..de5c5dd 100644 --- a/thirdParty/Req/pub/include/Request.h +++ b/thirdParty/Req/pub/include/Request.h @@ -15,9 +15,10 @@ namespace Req { Request &operator=(Request &&) = delete; Request &operator=(const Request &) = delete; ~Request(); + bool isValid(); void setClientCertificate(const std::string &cerPath, const std::string &keyPath); void setVerbose(bool verbose); - Response post(const std::string& url, const std::string &body = std::string(), + Response* post(const std::string& url, const std::string &body = std::string(), const std::unordered_map& headers = std::unordered_map()); @@ -27,6 +28,8 @@ namespace Req { std::string mCert; std::string mKey; bool mVerbose; + bool mValid; + }; } #endif // __REQUEST_H__ \ No newline at end of file diff --git a/thirdParty/Req/pub/include/Response.h b/thirdParty/Req/pub/include/Response.h index b9ccbe8..1a9c906 100644 --- a/thirdParty/Req/pub/include/Response.h +++ b/thirdParty/Req/pub/include/Response.h @@ -7,6 +7,7 @@ namespace Req { { public: Response(); + static Response* ErrorResponse(const std::string & content); Response(Response &&) = default; Response(const Response &) = default; Response &operator=(Response &&) = delete; @@ -15,9 +16,11 @@ namespace Req { long httpCode(); void setHttpCode(long code); std::string& getContent(); + bool isResponsed(); private: long mHttpCode = 404; std::string mContent; + bool mResponsed; }; }; #endif // __RESPONSE_H__ \ No newline at end of file diff --git a/thirdParty/Req/pub/lib/libReq.so b/thirdParty/Req/pub/lib/libReq.so index a8f36c0..b6cffa8 100644 Binary files a/thirdParty/Req/pub/lib/libReq.so and b/thirdParty/Req/pub/lib/libReq.so differ