comparison Plugins/OrthancCPlugin/OrthancCPlugin.h @ 1042:8d1845feb277

set cookies, not allowed methods, unauthorized in plugins
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 17 Jul 2014 15:55:40 +0200
parents 2c49b7dffcec
children bb82e5e818e9
comparison
equal deleted inserted replaced
1041:2c49b7dffcec 1042:8d1845feb277
241 241
242 /* Sending answers to REST calls */ 242 /* Sending answers to REST calls */
243 _OrthancPluginService_AnswerBuffer = 2000, 243 _OrthancPluginService_AnswerBuffer = 2000,
244 _OrthancPluginService_CompressAndAnswerPngImage = 2001, 244 _OrthancPluginService_CompressAndAnswerPngImage = 2001,
245 _OrthancPluginService_Redirect = 2002, 245 _OrthancPluginService_Redirect = 2002,
246 _OrthancPluginService_SendHttpStatusCode = 2003,
247 _OrthancPluginService_SendUnauthorized = 2004,
248 _OrthancPluginService_SendMethodNotAllowed = 2005,
249 _OrthancPluginService_SetCookie = 2006,
246 250
247 /* Access to the Orthanc database and API */ 251 /* Access to the Orthanc database and API */
248 _OrthancPluginService_GetDicomForInstance = 3000, 252 _OrthancPluginService_GetDicomForInstance = 3000,
249 _OrthancPluginService_RestApiGet = 3001, 253 _OrthancPluginService_RestApiGet = 3001,
250 _OrthancPluginService_RestApiPost = 3002, 254 _OrthancPluginService_RestApiPost = 3002,
771 params.bodySize = bodySize; 775 params.bodySize = bodySize;
772 return context->InvokeService(context, _OrthancPluginService_RestApiPut, &params); 776 return context->InvokeService(context, _OrthancPluginService_RestApiPut, &params);
773 } 777 }
774 778
775 779
780
776 typedef struct 781 typedef struct
777 { 782 {
778 OrthancPluginRestOutput* output; 783 OrthancPluginRestOutput* output;
779 const char* redirection; 784 const char* argument;
780 } _OrthancPluginRedirect; 785 } _OrthancPluginOutputPlusArgument;
781 786
782 /** 787 /**
783 * @brief Redirect a GET request. 788 * @brief Redirect a REST request.
784 * 789 *
785 * This function answers to a REST request by redirecting the user 790 * This function answers to a REST request by redirecting the user
786 * to another URI using HTTP status 301. 791 * to another URI using HTTP status 301.
787 * 792 *
788 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). 793 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
792 ORTHANC_PLUGIN_INLINE void OrthancPluginRedirect( 797 ORTHANC_PLUGIN_INLINE void OrthancPluginRedirect(
793 OrthancPluginContext* context, 798 OrthancPluginContext* context,
794 OrthancPluginRestOutput* output, 799 OrthancPluginRestOutput* output,
795 const char* redirection) 800 const char* redirection)
796 { 801 {
797 _OrthancPluginRedirect params; 802 _OrthancPluginOutputPlusArgument params;
798 params.output = output; 803 params.output = output;
799 params.redirection = redirection; 804 params.argument = redirection;
800 context->InvokeService(context, _OrthancPluginService_Redirect, &params); 805 context->InvokeService(context, _OrthancPluginService_Redirect, &params);
801 } 806 }
802 807
803 808
804 809
930 return result; 935 return result;
931 } 936 }
932 } 937 }
933 938
934 939
940
941 typedef struct
942 {
943 OrthancPluginRestOutput* output;
944 uint16_t status;
945 } _OrthancPluginSendHttpStatusCode;
946
947 /**
948 * @brief Send a HTTP status code.
949 *
950 * This function answers to a REST request by sending a HTTP status
951 * code (such as "400 - Bad Request"). Note that:
952 * - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer().
953 * - Redirections (status 301) must use ::OrthancPluginRedirect().
954 * - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized().
955 * - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed().
956 *
957 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
958 * @param output The HTTP connection to the client application.
959 * @param status The HTTP status code to be sent.
960 **/
961 ORTHANC_PLUGIN_INLINE void OrthancPluginSendHttpStatusCode(
962 OrthancPluginContext* context,
963 OrthancPluginRestOutput* output,
964 uint16_t status)
965 {
966 _OrthancPluginSendHttpStatusCode params;
967 params.output = output;
968 params.status = status;
969 context->InvokeService(context, _OrthancPluginService_SendHttpStatusCode, &params);
970 }
971
972
973 /**
974 * @brief Signal that a REST request is not authorized.
975 *
976 * This function answers to a REST request by signaling that it is
977 * not authorized.
978 *
979 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
980 * @param output The HTTP connection to the client application.
981 * @param realm The realm for the authorization process.
982 **/
983 ORTHANC_PLUGIN_INLINE void OrthancPluginSendUnauthorized(
984 OrthancPluginContext* context,
985 OrthancPluginRestOutput* output,
986 const char* realm)
987 {
988 _OrthancPluginOutputPlusArgument params;
989 params.output = output;
990 params.argument = realm;
991 context->InvokeService(context, _OrthancPluginService_SendUnauthorized, &params);
992 }
993
994
995 /**
996 * @brief Signal that this URI does not support this HTTP method.
997 *
998 * This function answers to a REST request by signaling that the
999 * queried URI does not support this method.
1000 *
1001 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1002 * @param output The HTTP connection to the client application.
1003 * @param allowedMethods The allowed methods for this URI (e.g. "GET,POST" after a PUT or a POST request).
1004 **/
1005 ORTHANC_PLUGIN_INLINE void OrthancPluginSendMethodNotAllowed(
1006 OrthancPluginContext* context,
1007 OrthancPluginRestOutput* output,
1008 const char* allowedMethods)
1009 {
1010 _OrthancPluginOutputPlusArgument params;
1011 params.output = output;
1012 params.argument = allowedMethods;
1013 context->InvokeService(context, _OrthancPluginService_SendMethodNotAllowed, &params);
1014 }
1015
1016
1017 typedef struct
1018 {
1019 OrthancPluginRestOutput* output;
1020 const char* cookie;
1021 const char* value;
1022 } _OrthancPluginSetCookie;
1023
1024 /**
1025 * @brief Set a cookie.
1026 *
1027 * This function sets a cookie in the HTTP client.
1028 *
1029 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1030 * @param output The HTTP connection to the client application.
1031 * @param cookie The cookie to be set.
1032 * @param value The value of the cookie.
1033 **/
1034 ORTHANC_PLUGIN_INLINE void OrthancPluginSetCookie(
1035 OrthancPluginContext* context,
1036 OrthancPluginRestOutput* output,
1037 const char* cookie,
1038 const char* value)
1039 {
1040 _OrthancPluginSetCookie params;
1041 params.output = output;
1042 params.cookie = cookie;
1043 params.value = value;
1044 context->InvokeService(context, _OrthancPluginService_SetCookie, &params);
1045 }
1046
1047
935 #ifdef __cplusplus 1048 #ifdef __cplusplus
936 } 1049 }
937 #endif 1050 #endif
938 1051
939 1052