Mercurial > hg > orthanc
comparison Plugins/Samples/Basic/Plugin.c @ 1137:d9c27f9f1a51
OrthancPluginSetHttpHeader
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 09 Sep 2014 17:33:46 +0200 |
parents | ace99e272203 |
children | 0479d02c6778 |
comparison
equal
deleted
inserted
replaced
1136:208dc67b9bab | 1137:d9c27f9f1a51 |
---|---|
163 | 163 |
164 return 0; | 164 return 0; |
165 } | 165 } |
166 | 166 |
167 | 167 |
168 ORTHANC_PLUGINS_API int32_t CallbackCreateDicom(OrthancPluginRestOutput* output, | |
169 const char* url, | |
170 const OrthancPluginHttpRequest* request) | |
171 { | |
172 const char* pathLocator = "\"Path\" : \""; | |
173 char info[1024]; | |
174 char *id, *eos; | |
175 OrthancPluginMemoryBuffer tmp; | |
176 | |
177 if (request->method != OrthancPluginHttpMethod_Post) | |
178 { | |
179 OrthancPluginSendMethodNotAllowed(context, output, "POST"); | |
180 } | |
181 else | |
182 { | |
183 /* Make POST request to create a new DICOM instance */ | |
184 sprintf(info, "{\"PatientName\":\"Test\"}"); | |
185 OrthancPluginRestApiPost(context, &tmp, "/tools/create-dicom", info, strlen(info)); | |
186 | |
187 /** | |
188 * Recover the ID of the created instance is constructed by a | |
189 * quick-and-dirty parsing of a JSON string. | |
190 **/ | |
191 id = strstr((char*) tmp.data, pathLocator) + strlen(pathLocator); | |
192 eos = strchr(id, '\"'); | |
193 eos[0] = '\0'; | |
194 | |
195 /* Delete the newly created DICOM instance. */ | |
196 OrthancPluginRestApiDelete(context, id); | |
197 OrthancPluginFreeMemoryBuffer(context, &tmp); | |
198 | |
199 /* Set some cookie */ | |
200 OrthancPluginSetCookie(context, output, "hello", "world"); | |
201 | |
202 /* Set some HTTP header */ | |
203 OrthancPluginSetHttpHeader(context, output, "Cache-Control", "max-age=0, no-cache"); | |
204 | |
205 OrthancPluginAnswerBuffer(context, output, "OK\n", 3, "text/plain"); | |
206 } | |
207 | |
208 return 0; | |
209 } | |
210 | |
211 | |
168 ORTHANC_PLUGINS_API int32_t OnStoredCallback(OrthancPluginDicomInstance* instance, | 212 ORTHANC_PLUGINS_API int32_t OnStoredCallback(OrthancPluginDicomInstance* instance, |
169 const char* instanceId) | 213 const char* instanceId) |
170 { | 214 { |
171 char buffer[256]; | 215 char buffer[256]; |
172 FILE* fp; | 216 FILE* fp; |
201 | 245 |
202 | 246 |
203 | 247 |
204 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c) | 248 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c) |
205 { | 249 { |
206 const char* pathLocator = "\"Path\" : \""; | |
207 OrthancPluginMemoryBuffer tmp; | 250 OrthancPluginMemoryBuffer tmp; |
208 char info[1024]; | 251 char info[1024]; |
209 char *id, *eos; | |
210 | 252 |
211 context = c; | 253 context = c; |
212 OrthancPluginLogWarning(context, "Sample plugin is initializing"); | 254 OrthancPluginLogWarning(context, "Sample plugin is initializing"); |
213 | 255 |
214 /* Check the version of the Orthanc core */ | 256 /* Check the version of the Orthanc core */ |
228 | 270 |
229 OrthancPluginRegisterRestCallback(context, "/(plu.*)/hello", Callback1); | 271 OrthancPluginRegisterRestCallback(context, "/(plu.*)/hello", Callback1); |
230 OrthancPluginRegisterRestCallback(context, "/plu.*/image", Callback2); | 272 OrthancPluginRegisterRestCallback(context, "/plu.*/image", Callback2); |
231 OrthancPluginRegisterRestCallback(context, "/plugin/instances/([^/]+)/info", Callback3); | 273 OrthancPluginRegisterRestCallback(context, "/plugin/instances/([^/]+)/info", Callback3); |
232 OrthancPluginRegisterRestCallback(context, "/instances/([^/]+)/preview", Callback4); | 274 OrthancPluginRegisterRestCallback(context, "/instances/([^/]+)/preview", Callback4); |
275 OrthancPluginRegisterRestCallback(context, "/plugin/create", CallbackCreateDicom); | |
233 | 276 |
234 OrthancPluginRegisterOnStoredInstanceCallback(context, OnStoredCallback); | 277 OrthancPluginRegisterOnStoredInstanceCallback(context, OnStoredCallback); |
235 | 278 |
236 /* Make REST requests to the built-in Orthanc API */ | 279 /* Make REST requests to the built-in Orthanc API */ |
237 OrthancPluginRestApiGet(context, &tmp, "/changes"); | 280 OrthancPluginRestApiGet(context, &tmp, "/changes"); |
238 OrthancPluginFreeMemoryBuffer(context, &tmp); | 281 OrthancPluginFreeMemoryBuffer(context, &tmp); |
239 OrthancPluginRestApiGet(context, &tmp, "/changes?limit=1"); | 282 OrthancPluginRestApiGet(context, &tmp, "/changes?limit=1"); |
240 OrthancPluginFreeMemoryBuffer(context, &tmp); | 283 OrthancPluginFreeMemoryBuffer(context, &tmp); |
241 | 284 |
242 /* Make POST request to create a new DICOM instance */ | |
243 sprintf(info, "{\"PatientName\":\"Test\"}"); | |
244 OrthancPluginRestApiPost(context, &tmp, "/tools/create-dicom", info, strlen(info)); | |
245 | |
246 /** | |
247 * Recover he ID of the created instance is constructed by a | |
248 * quick-and-dirty parsing of a JSON string. | |
249 **/ | |
250 id = strstr((char*) tmp.data, pathLocator) + strlen(pathLocator); | |
251 eos = strchr(id, '\"'); | |
252 eos[0] = '\0'; | |
253 | |
254 /* Delete the newly created DICOM instance. */ | |
255 OrthancPluginRestApiDelete(context, id); | |
256 OrthancPluginFreeMemoryBuffer(context, &tmp); | |
257 | |
258 /* Play with PUT by defining a new target modality. */ | 285 /* Play with PUT by defining a new target modality. */ |
259 sprintf(info, "[ \"STORESCP\", \"localhost\", 2000 ]"); | 286 sprintf(info, "[ \"STORESCP\", \"localhost\", 2000 ]"); |
260 OrthancPluginRestApiPut(context, &tmp, "/modalities/demo", info, strlen(info)); | 287 OrthancPluginRestApiPut(context, &tmp, "/modalities/demo", info, strlen(info)); |
261 | 288 |
262 return 0; | 289 return 0; |
263 } | 290 } |
264 | 291 |
265 | 292 |
266 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | 293 ORTHANC_PLUGINS_API void OrthancPluginFinalize() |