Mercurial > hg > orthanc
comparison Plugins/Engine/OrthancPlugins.cpp @ 1987:ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 26 Apr 2016 17:40:55 +0200 |
parents | 9f09a20e41e2 |
children | f0acfa753973 |
comparison
equal
deleted
inserted
replaced
1986:99b249867052 | 1987:ce90d109bb64 |
---|---|
1413 CopyToMemoryBuffer(*p.target, s); | 1413 CopyToMemoryBuffer(*p.target, s); |
1414 } | 1414 } |
1415 } | 1415 } |
1416 | 1416 |
1417 | 1417 |
1418 void OrthancPlugins::CallHttpClient2(const void* parameters) | |
1419 { | |
1420 const _OrthancPluginCallHttpClient2& p = *reinterpret_cast<const _OrthancPluginCallHttpClient2*>(parameters); | |
1421 | |
1422 HttpClient client; | |
1423 client.SetUrl(p.url); | |
1424 | |
1425 if (p.timeout != 0) | |
1426 { | |
1427 client.SetTimeout(p.timeout); | |
1428 } | |
1429 | |
1430 if (p.username != NULL && | |
1431 p.password != NULL) | |
1432 { | |
1433 client.SetCredentials(p.username, p.password); | |
1434 } | |
1435 | |
1436 for (uint32_t i = 0; i < p.headersCount; i++) | |
1437 { | |
1438 if (p.headersKeys[i] == NULL || | |
1439 p.headersValues[i] == NULL) | |
1440 { | |
1441 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1442 } | |
1443 | |
1444 client.AddHeader(p.headersKeys[i], p.headersValues[i]); | |
1445 } | |
1446 | |
1447 switch (p.method) | |
1448 { | |
1449 case OrthancPluginHttpMethod_Get: | |
1450 client.SetMethod(HttpMethod_Get); | |
1451 break; | |
1452 | |
1453 case OrthancPluginHttpMethod_Post: | |
1454 client.SetMethod(HttpMethod_Post); | |
1455 client.GetBody().assign(p.body, p.bodySize); | |
1456 break; | |
1457 | |
1458 case OrthancPluginHttpMethod_Put: | |
1459 client.SetMethod(HttpMethod_Put); | |
1460 client.GetBody().assign(p.body, p.bodySize); | |
1461 break; | |
1462 | |
1463 case OrthancPluginHttpMethod_Delete: | |
1464 client.SetMethod(HttpMethod_Delete); | |
1465 break; | |
1466 | |
1467 default: | |
1468 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1469 } | |
1470 | |
1471 std::string s; | |
1472 | |
1473 if (!client.Apply(s)) | |
1474 { | |
1475 *p.httpStatus = 0; | |
1476 throw OrthancException(ErrorCode_NetworkProtocol); | |
1477 } | |
1478 | |
1479 *p.httpStatus = static_cast<uint16_t>(client.GetLastStatus()); | |
1480 | |
1481 if (p.method != OrthancPluginHttpMethod_Delete) | |
1482 { | |
1483 CopyToMemoryBuffer(*p.target, s); | |
1484 } | |
1485 } | |
1486 | |
1487 | |
1418 void OrthancPlugins::ConvertPixelFormat(const void* parameters) | 1488 void OrthancPlugins::ConvertPixelFormat(const void* parameters) |
1419 { | 1489 { |
1420 const _OrthancPluginConvertPixelFormat& p = *reinterpret_cast<const _OrthancPluginConvertPixelFormat*>(parameters); | 1490 const _OrthancPluginConvertPixelFormat& p = *reinterpret_cast<const _OrthancPluginConvertPixelFormat*>(parameters); |
1421 const ImageAccessor& source = *reinterpret_cast<const ImageAccessor*>(p.source); | 1491 const ImageAccessor& source = *reinterpret_cast<const ImageAccessor*>(p.source); |
1422 | 1492 |
2113 | 2183 |
2114 case _OrthancPluginService_CallHttpClient: | 2184 case _OrthancPluginService_CallHttpClient: |
2115 CallHttpClient(parameters); | 2185 CallHttpClient(parameters); |
2116 return true; | 2186 return true; |
2117 | 2187 |
2188 case _OrthancPluginService_CallHttpClient2: | |
2189 CallHttpClient2(parameters); | |
2190 return true; | |
2191 | |
2118 case _OrthancPluginService_ConvertPixelFormat: | 2192 case _OrthancPluginService_ConvertPixelFormat: |
2119 ConvertPixelFormat(parameters); | 2193 ConvertPixelFormat(parameters); |
2120 return true; | 2194 return true; |
2121 | 2195 |
2122 case _OrthancPluginService_GetFontsCount: | 2196 case _OrthancPluginService_GetFontsCount: |
2253 | 2327 |
2254 case _OrthancPluginService_LookupDictionary: | 2328 case _OrthancPluginService_LookupDictionary: |
2255 ApplyLookupDictionary(parameters); | 2329 ApplyLookupDictionary(parameters); |
2256 return true; | 2330 return true; |
2257 | 2331 |
2332 case _OrthancPluginService_GenerateUuid: | |
2333 { | |
2334 *reinterpret_cast<const _OrthancPluginRetrieveDynamicString*>(parameters)->result = | |
2335 CopyString(Toolbox::GenerateUuid()); | |
2336 return true; | |
2337 } | |
2338 | |
2258 default: | 2339 default: |
2259 { | 2340 { |
2260 // This service is unknown to the Orthanc plugin engine | 2341 // This service is unknown to the Orthanc plugin engine |
2261 return false; | 2342 return false; |
2262 } | 2343 } |