changeset 1044:6d90e2bcab60

sample
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 17 Jul 2014 16:01:41 +0200
parents be849646b2bf
children 0bfeeb6d340f
files Plugins/Samples/Basic/Plugin.c
diffstat 1 files changed, 27 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/Plugins/Samples/Basic/Plugin.c	Thu Jul 17 15:59:06 2014 +0200
+++ b/Plugins/Samples/Basic/Plugin.c	Thu Jul 17 16:01:41 2014 +0200
@@ -112,14 +112,21 @@
                                       const char* url,
                                       const OrthancPluginHttpRequest* request)
 {
-  OrthancPluginMemoryBuffer dicom;
-  if (!OrthancPluginGetDicomForInstance(context, &dicom, request->groups[0]))
+  if (request->method != OrthancPluginHttpMethod_Get)
+  {
+    OrthancPluginSendMethodNotAllowed(context, output, "GET");
+  }
+  else
   {
-    /* No error, forward the DICOM file */
-    OrthancPluginAnswerBuffer(context, output, dicom.data, dicom.size, "application/dicom");
+    OrthancPluginMemoryBuffer dicom;
+    if (!OrthancPluginGetDicomForInstance(context, &dicom, request->groups[0]))
+    {
+      /* No error, forward the DICOM file */
+      OrthancPluginAnswerBuffer(context, output, dicom.data, dicom.size, "application/dicom");
 
-    /* Free memory */
-    OrthancPluginFreeMemoryBuffer(context, &dicom);
+      /* Free memory */
+      OrthancPluginFreeMemoryBuffer(context, &dicom);
+    }
   }
 
   return 0;
@@ -135,17 +142,25 @@
   uint8_t  buffer[256 * 256];
   uint32_t x, y, value;
 
-  value = 0;
-  for (y = 0; y < 256; y++)
+  if (request->method != OrthancPluginHttpMethod_Get)
+  {
+    OrthancPluginSendMethodNotAllowed(context, output, "GET");
+  }
+  else
   {
-    for (x = 0; x < 256; x++, value++)
+    value = 0;
+    for (y = 0; y < 256; y++)
     {
-      buffer[value] = x;
+      for (x = 0; x < 256; x++, value++)
+      {
+        buffer[value] = x;
+      }
     }
+
+    OrthancPluginCompressAndAnswerPngImage(context, output, OrthancPluginPixelFormat_Grayscale8,
+                                           256, 256, 256, buffer);
   }
 
-  OrthancPluginCompressAndAnswerPngImage(context, output, OrthancPluginPixelFormat_Grayscale8,
-                                         256, 256, 256, buffer);
   return 0;
 }