Mercurial > hg > orthanc
comparison Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 2968:e361df74639f
added few plugin helpers
author | am@osimis.io |
---|---|
date | Wed, 05 Dec 2018 16:30:28 +0100 |
parents | bb7a66efbeb1 |
children | 9b734c3e1095 |
comparison
equal
deleted
inserted
replaced
2967:146eaed9b02c | 2968:e361df74639f |
---|---|
1111 } | 1111 } |
1112 } | 1112 } |
1113 | 1113 |
1114 #endif /* HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 */ | 1114 #endif /* HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 */ |
1115 | 1115 |
1116 void AnswerJson(const Json::Value& value, | |
1117 OrthancPluginRestOutput* output | |
1118 ) | |
1119 { | |
1120 Json::StyledWriter writer; | |
1121 std::string bodyString = writer.write(value); | |
1122 | |
1123 OrthancPluginAnswerBuffer(GetGlobalContext(), output, bodyString.c_str(), bodyString.size(), "application/json"); | |
1124 } | |
1125 | |
1126 bool RestApiGetString(std::string& result, | |
1127 const std::string& uri, | |
1128 bool applyPlugins) | |
1129 { | |
1130 MemoryBuffer answer; | |
1131 if (!answer.RestApiGet(uri, applyPlugins)) | |
1132 { | |
1133 return false; | |
1134 } | |
1135 else | |
1136 { | |
1137 answer.ToString(result); | |
1138 return true; | |
1139 } | |
1140 } | |
1141 | |
1116 | 1142 |
1117 bool RestApiGet(Json::Value& result, | 1143 bool RestApiGet(Json::Value& result, |
1118 const std::string& uri, | 1144 const std::string& uri, |
1119 bool applyPlugins) | 1145 bool applyPlugins) |
1120 { | 1146 { |
1309 { | 1335 { |
1310 return false; | 1336 return false; |
1311 } | 1337 } |
1312 } | 1338 } |
1313 | 1339 |
1340 const char* GetMimeType(const std::string& path) | |
1341 { | |
1342 size_t dot = path.find_last_of('.'); | |
1343 | |
1344 std::string extension = (dot == std::string::npos) ? "" : path.substr(dot); | |
1345 std::transform(extension.begin(), extension.end(), extension.begin(), tolower); | |
1346 | |
1347 if (extension == ".html") | |
1348 { | |
1349 return "text/html"; | |
1350 } | |
1351 else if (extension == ".css") | |
1352 { | |
1353 return "text/css"; | |
1354 } | |
1355 else if (extension == ".js") | |
1356 { | |
1357 return "application/javascript"; | |
1358 } | |
1359 else if (extension == ".gif") | |
1360 { | |
1361 return "image/gif"; | |
1362 } | |
1363 else if (extension == ".svg") | |
1364 { | |
1365 return "image/svg+xml"; | |
1366 } | |
1367 else if (extension == ".json") | |
1368 { | |
1369 return "application/json"; | |
1370 } | |
1371 else if (extension == ".xml") | |
1372 { | |
1373 return "application/xml"; | |
1374 } | |
1375 else if (extension == ".wasm") | |
1376 { | |
1377 return "application/wasm"; | |
1378 } | |
1379 else if (extension == ".png") | |
1380 { | |
1381 return "image/png"; | |
1382 } | |
1383 else if (extension == ".jpg" || extension == ".jpeg") | |
1384 { | |
1385 return "image/jpeg"; | |
1386 } | |
1387 else | |
1388 { | |
1389 return "application/octet-stream"; | |
1390 } | |
1391 } | |
1314 | 1392 |
1315 | 1393 |
1316 | 1394 |
1317 #if HAS_ORTHANC_PLUGIN_PEERS == 1 | 1395 #if HAS_ORTHANC_PLUGIN_PEERS == 1 |
1318 size_t OrthancPeers::GetPeerIndex(const std::string& name) const | 1396 size_t OrthancPeers::GetPeerIndex(const std::string& name) const |