LibItsHttp_Templates.ttcn 14.9 KB
Newer Older
garciay's avatar
garciay committed
/**
 *    @author   ETSI / STF549
 *    @version  $URL$
 *              $ID:$
 *    @desc     This module provides the templates for ITS HTTP based protocols.
 *    @copyright   ETSI Copyright Notification
 *                 No part may be reproduced except as authorized by written permission.
 *                 The copyright and the foregoing restriction extend to reproduction in all media.
 *                 All rights reserved.
 *    @see      ETSI TS 103 478
 */
garciay's avatar
garciay committed
module LibItsHttp_Templates {
garciay's avatar
garciay committed
    
    // LibHttp
garciay's avatar
garciay committed
    import from LibItsHttp_TypesAndValues all;
garciay's avatar
garciay committed
    import from LibItsHttp_MessageBodyTypes all;
    import from LibItsHttp_XmlMessageBodyTypes all;
    import from LibItsHttp_JsonMessageBodyTypes all;
garciay's avatar
garciay committed
    import from LibItsHttp_BinaryMessageBodyTypes all;
garciay's avatar
garciay committed
    
garciay's avatar
garciay committed
    group http_messages {
        
        template (value) HttpMessage m_http_request(
                                                    in template (value) Request p_request
        ) := {
          request := p_request
        } // End of template m_http_request
        
        template (present) HttpMessage mw_http_request(
                                                       template (present) Request p_request := ?
        ) := {
          request := p_request
        } // End of template mw_http_request
        
        template (value) HttpMessage m_http_response(
                                                     in template (value) Response p_response
        ) := {
          response := p_response
        } // End of template m_http_response
        
        template (present) HttpMessage mw_http_response(
                                                        template (present) Response p_response := ?
        ) := {
          response := p_response
        } // End of template mw_http_response
        
    } // End of group http_messages
garciay's avatar
garciay committed
    
garciay's avatar
garciay committed
    group http_headers {
        
        template (value) HeaderLine m_header_line(
                                                  in template (value) charstring p_header_name,
                                                  in template (value) charstring_list p_header_value
        ) := {
          header_name := p_header_name,
          header_value  := p_header_value
        } // End of template m_header_line
garciay's avatar
garciay committed
    
garciay's avatar
garciay committed
    } // End of group http_headers
garciay's avatar
garciay committed
    
garciay's avatar
garciay committed
    group http_requests {
        
        template (omit) Request m_http_request_get(
                                                   in charstring p_uri, 
                                                   in template (value) HeaderLines p_headers,
                                                   in template (omit) HttpMessageBody p_body := omit
        ) := {
          method        := "GET",
          uri           := p_uri,
          version_major := c_http_version_major,
          version_minor := c_http_version_minor,
          header        := p_headers,
          body          := p_body
        } // End of template m_http_request_get
        
YannGarcia's avatar
YannGarcia committed
        template Request mw_http_request_get(
                                             template (present) charstring p_uri := ?, 
                                             template (present) HeaderLines p_headers := ?,
                                             template HttpMessageBody p_body := *
garciay's avatar
garciay committed
        ) := {
YannGarcia's avatar
YannGarcia committed
          method        := "GET",
garciay's avatar
garciay committed
          uri           := p_uri,
          version_major := c_http_version_major,
          version_minor := c_http_version_minor,
          header        := p_headers,
          body          := p_body
YannGarcia's avatar
YannGarcia committed
        } // End of template mw_http_request_get
        
        template (omit) Request m_http_request_post(
                                                    in charstring p_uri, 
                                                    in template (value) HeaderLines p_headers,
                                                    in template (omit) HttpMessageBody p_body := omit
        ) modifies m_http_request_get := {
          method        := "POST"
garciay's avatar
garciay committed
        } // End of template m_http_request_post
        
Yann Garcia's avatar
Yann Garcia committed
        template Request mw_http_request_post(
                                              template (present) charstring p_uri := ?, 
                                              template (present) HeaderLines p_headers := ?,
                                              template HttpMessageBody p_body := *
YannGarcia's avatar
YannGarcia committed
        ) modifies mw_http_request_get := {
          method        := "POST"
        } // End of template mw_http_request_post
        
        template (omit) Request m_http_request_put(
                                                   in charstring p_uri, 
                                                   in template (value) HeaderLines p_headers,
                                                   in template (omit) HttpMessageBody p_body := omit
        ) modifies m_http_request_get := {
          method        := "PUT"
        } // End of template m_http_request_put
        
        template Request mw_http_request_put(
                                             template (present) charstring p_uri := ?, 
                                             template (present) HeaderLines p_headers := ?,
                                             template HttpMessageBody p_body := *
        ) modifies mw_http_request_get := {
          method        := "PUT"
        } // End of template mw_http_request_put
        
YannGarcia's avatar
YannGarcia committed
        template (omit) Request m_http_request_delete(
                                                      in charstring p_uri, 
                                                      in template (value) HeaderLines p_headers,
                                                      in template (omit) HttpMessageBody p_body := omit
        ) modifies m_http_request_get := {
          method        := "DELETE"
        } // End of template m_http_request_delete
        
        template Request mw_http_request_delete(
                                                template (present) charstring p_uri := ?, 
                                                template (present) HeaderLines p_headers := ?,
                                                template HttpMessageBody p_body := *
        ) modifies mw_http_request_get := {
          method        := "DELETE"
Yann Garcia's avatar
Yann Garcia committed
        } // End of template mw_http_request_post
        
garciay's avatar
garciay committed
    } // End of group http_requests
    
    group http_responses {
Yann Garcia's avatar
Yann Garcia committed
      template (value) Response m_http_response_ok(
                                                   in template (value) HttpMessageBody p_body,
                                                   in template (value) HeaderLines p_header
      ) := {
          version_major := 1,
          version_minor := 1,
          statuscode    := 200,
          statustext    := "OK",
          header        := p_header,
          body          := p_body
      } // End of template m_http_response_ok
      
      template (value) Response m_http_response_ok_no_body(
                                                           in template (value) HeaderLines p_header
      ) := {
          version_major := 1,
          version_minor := 1,
          statuscode    := 200,
          statustext    := "OK",
          header        := p_header,
          body          := omit
      } // End of template m_http_response_ok_no_body
      
      template (value) Response m_http_response_204_no_content(
                                                               in template (value) HeaderLines p_header
      ) modifies m_http_response_ok_no_body := {
          statuscode    := 204,
          statustext    := "No Content"
      } // End of template m_http_response_204_no_content
      
garciay's avatar
garciay committed
      template (present) Response mw_http_response_ok(
Yann Garcia's avatar
Yann Garcia committed
                                                      template (present) HttpMessageBody p_body := ?,
garciay's avatar
garciay committed
                                                      template (present) HeaderLines p_header := ?
      ) := {
          version_major := 1,
          version_minor := 1,
          statuscode    := 200,
          statustext    := ?,
garciay's avatar
garciay committed
          header        := p_header,
          body          := p_body
      } // End of template mw_http_response_ok
      
YannGarcia's avatar
YannGarcia committed
      template (present) Response mw_http_response_201_created(
                                                               template (present) HttpMessageBody p_body := ?,
                                                               template (present) HeaderLines p_header := ?
      ) modifies mw_http_response_ok := {
          statuscode    := 201,
YannGarcia's avatar
YannGarcia committed
          statustext    := "Created"
      } // End of template mw_http_response_ok
      
      template (present) Response mw_http_response_202_accepted(
                                                                template (present) HttpMessageBody p_body := ?,
                                                                template (present) HeaderLines p_header := ?
      ) modifies mw_http_response_ok := {
          statuscode    := 202,
          statustext    := "Accepted"
      } // End of template mw_http_response_ok
YannGarcia's avatar
YannGarcia committed
      
      template (present) Response mw_http_response_204_no_content(
                                                                   template (present) HttpMessageBody p_body := ?,
                                                                   template (present) HeaderLines p_header := ?
      ) modifies mw_http_response_ok := {
          statuscode    := 204,
          statustext    := "No Content"
YannGarcia's avatar
YannGarcia committed
      } // End of template mw_http_response_ok
      
Yann Garcia's avatar
Yann Garcia committed
      template (value) Response m_http_response_ko(
                                                   in template (value) HttpMessageBody p_body,
                                                   in template (value) HeaderLines p_header,
                                                   in template (value) integer p_statuscode := 404,
                                                   in template (value) charstring p_statustext := "Not found"
      ) := {
          version_major := 1,
          version_minor := 1,
          statuscode    := p_statuscode,
          statustext    := p_statustext,
          header        := p_header,
          body          := p_body
      } // End of template m_http_response_ko
      
      template (value) Response m_http_response_ko_no_body(
                                                           in template (value) HeaderLines p_header,
                                                           in template (value) integer p_statuscode := 404,
                                                           in template (value) charstring p_statustext := "Not found"
      ) := {
          version_major := 1,
          version_minor := 1,
          statuscode    := p_statuscode,
          statustext    := p_statustext,
          header        := p_header,
          body          := omit
      } // End of template m_http_response_ko_no_body
      
garciay's avatar
garciay committed
      template Response mw_http_response_ko(
                                            template HttpMessageBody p_body  := *,
                                            template (present) HeaderLines p_header := ?
      ) := {
          version_major := 1,
          version_minor := 1,
          statuscode    := complement(200),
          statustext    := ?,
          header        := p_header,
          body          := p_body
garciay's avatar
garciay committed
      } // End of template mw_http_response_ko
      
YannGarcia's avatar
YannGarcia committed
      template Response mw_http_response_400_bad_request(
                                                         template HttpMessageBody p_body  := *,
                                                         template (present) HeaderLines p_header := ?
      ) modifies mw_http_response_ko := {
          statuscode    := 400,
YannGarcia's avatar
YannGarcia committed
          statustext    := "Bad Request"
YannGarcia's avatar
YannGarcia committed
      } // End of template mw_http_response_400_bad_request
      
      template Response mw_http_response_403_forbidden(
                                                       template HttpMessageBody p_body  := *,
                                                       template (present) HeaderLines p_header := ?
      ) modifies mw_http_response_ko := {
          statuscode    := 403,
YannGarcia's avatar
YannGarcia committed
          statustext    := "Forbidden"
      } // End of template mw_http_response_403_forbidden
YannGarcia's avatar
YannGarcia committed
      
garciay's avatar
garciay committed
      template Response mw_http_response_404_not_found(
                                                       template HttpMessageBody p_body  := *,
                                                       template (present) HeaderLines p_header := ?
      ) modifies mw_http_response_ko := {
          statuscode    := 404,
YannGarcia's avatar
YannGarcia committed
          statustext    := "Not Found"
YannGarcia's avatar
YannGarcia committed
      } // End of template mw_http_response_404_not_found
YannGarcia's avatar
YannGarcia committed
      template Response mw_http_response_412_precondition_failed(
                                                                 template HttpMessageBody p_body  := *,
                                                                 template (present) HeaderLines p_header := ?
      ) modifies mw_http_response_ko := {
          statuscode    := 412,
          statustext    := "Precondition Failed"
      } // End of template mw_http_response_412_not_found
      
garciay's avatar
garciay committed
    } // End of group http_responses
garciay's avatar
garciay committed
    
garciay's avatar
garciay committed
    group http_xml_body {
      
      template (value) HttpMessageBody m_http_message_body_xml(
                                                               in template (value) XmlBody p_xml_body
      ) := {
          xml_body := p_xml_body
      } // End of template m_http_message_body_xml
      
      template (present) HttpMessageBody mw_http_message_body_xml(
                                                                  template (present) XmlBody p_xml_body := ?
      ) := {
          xml_body := p_xml_body
      } // End of template mw_http_message_body_xml
      
    } // End of group http_xml_body
garciay's avatar
garciay committed
    
    group http_json_body {
      
      template (value) HttpMessageBody m_http_message_body_json(
                                                               in template (value) JsonBody p_json_body
      ) := {
          json_body := p_json_body
      } // End of template m_http_message_body_json
      
      template (present) HttpMessageBody mw_http_message_body_json(
                                                                  template (present) JsonBody p_json_body := ?
      ) := {
          json_body := p_json_body
      } // End of template mw_http_message_body_json
      
    } // End of group http_json_body
    
garciay's avatar
garciay committed
    group http_binary_body {
      
      template (value) HttpMessageBody m_http_message_body_binary(
                                                                  in template (value) BinaryBody p_binary_body
      ) := {
          binary_body := p_binary_body
      } // End of template m_http_message_body_binary
      
      template (present) HttpMessageBody mw_http_message_body_binary(
                                                                     template (present) BinaryBody p_binary_body := ?
      ) := {
          binary_body := p_binary_body
      } // End of template mw_http_message_body_binary
      
    } // End of group http_binary_body
    
garciay's avatar
garciay committed
} // End of module LibItsHttp_Templates