|
28 | 28 |
|
29 | 29 | Buffer : RFLX_Types.Bytes_Ptr := |
30 | 30 | new RFLX_Types.Bytes'(Request.Message_Data (Request.Message_Data'First .. |
31 | | - RFLX_Types.Index (Request.Length))); |
| 31 | + RFLX_Types.Index'Base (Request.Length))); |
32 | 32 | Context : RFLX.CoAP.CoAP_Message.Context; |
33 | 33 |
|
34 | 34 | Request_Content : CoAP_SPARK.Messages.Content; |
|
37 | 37 |
|
38 | 38 | Last : constant RFLX_Types.Bit_Length := |
39 | 39 | RFLX_Types.To_Last_Bit_Index (RFLX_Types.Length (Request.Length)); |
| 40 | + |
40 | 41 | begin |
41 | 42 |
|
42 | 43 | RFLX_Result := |
|
48 | 49 | Options_And_Payload_Options_And_Payload => [others => 0], |
49 | 50 | Options_And_Payload_Length => 0); |
50 | 51 |
|
| 52 | + if Buffer'Length = 0 then |
| 53 | + -- Not really expected, because the message has already been validated |
| 54 | + -- in the main loop state machine. |
| 55 | + State.Current_Status := CoAP_SPARK.Unexpected_Case; |
| 56 | + RFLX.RFLX_Types.Free (Buffer); |
| 57 | + return; |
| 58 | + end if; |
| 59 | + |
51 | 60 | RFLX.CoAP.CoAP_Message.Initialize |
52 | 61 | (Ctx => Context, |
53 | 62 | Buffer => Buffer, |
|
66 | 75 | State.Current_Status := CoAP_SPARK.Invalid_Request; |
67 | 76 |
|
68 | 77 | else |
69 | | - CoAP_SPARK.Messages.Encoding.Decode_Options_And_Payload |
70 | | - (Data => Request.Message_Data, |
71 | | - Status => State.Current_Status, |
72 | | - Decoded_Content => Request_Content); |
73 | | - |
74 | | - if State.Current_Status = CoAP_SPARK.OK |
75 | | - and then State.Request_Handler not in null |
76 | | - then |
77 | | - |
78 | | - CoAP_SPARK.Log.Put_Line ("REQUEST: "); |
79 | | - CoAP_SPARK.Messages.Print_Content |
80 | | - (Item => Request_Content, |
81 | | - Log_Level_Payload => CoAP_SPARK.Log.Debug); |
82 | | - |
83 | | - -- Call the request handler with the decoded content |
84 | | - State.Request_Handler |
85 | | - (Method => RFLX.CoAP.CoAP_Message.Get_Method (Context), |
86 | | - Request_Content => Request_Content, |
87 | | - Response_Codes => Response_Codes, |
88 | | - Response_Content => Response_Content); |
89 | | - |
90 | | - CoAP_SPARK.Log.Put_Line ("RESPONSE: "); |
91 | | - CoAP_SPARK.Messages.Print_Content |
92 | | - (Item => Response_Content, |
93 | | - Log_Level_Payload => CoAP_SPARK.Log.Debug); |
94 | | - CoAP_SPARK.Messages.Print_Response_Kind (Item => Response_Codes); |
95 | | - |
96 | | - CoAP_SPARK.Messages.Encoding.Encode_Options_And_Payload |
97 | | - (Options_And_Payload => Response_Content, |
98 | | - Status => State.Current_Status, |
99 | | - Encoded_Data => |
100 | | - RFLX_Result.Options_And_Payload_Options_And_Payload, |
101 | | - Encoded_Length => |
102 | | - RFLX.CoAP.Length_16 (RFLX_Result.Options_And_Payload_Length)); |
103 | | - |
104 | | - RFLX_Result.Success_Code := RFLX.CoAP.Success_Response'Last; |
105 | | - RFLX_Result.Client_Error_Code := |
106 | | - RFLX.CoAP.Client_Error_Response'Last; |
107 | | - RFLX_Result.Server_Error_Code := |
108 | | - RFLX.CoAP.Server_Error_Response'Last; |
109 | | - RFLX_Result.Message_Class := Response_Codes.Code_Class; |
110 | | - |
111 | | - case CoAP_SPARK.Messages.Response_Code (Response_Codes.Code_Class) |
112 | | - is |
113 | | - when RFLX.CoAP.Success => |
114 | | - |
115 | | - RFLX_Result.Success_Code := Response_Codes.Success_Code; |
116 | | - |
117 | | - when RFLX.CoAP.Client_Error => |
118 | | - |
119 | | - RFLX_Result.Client_Error_Code := |
120 | | - Response_Codes.Client_Error_Code; |
121 | | - |
122 | | - when RFLX.CoAP.Server_Error => |
123 | | - |
124 | | - RFLX_Result.Server_Error_Code := |
125 | | - Response_Codes.Server_Error_Code; |
126 | | - |
127 | | - end case; |
128 | | - end if; |
| 78 | + Handle_Request : |
| 79 | + declare |
| 80 | + Opt_Payload_Length : constant RFLX_Types.Length := |
| 81 | + RFLX_Types.To_Length |
| 82 | + (RFLX.CoAP.CoAP_Message.Field_Size |
| 83 | + (Context, RFLX.CoAP.CoAP_Message.F_Options_And_Payload)); |
| 84 | + Opt_Payload_Buffer : RFLX_Types.Bytes |
| 85 | + (1 .. RFLX.RFLX_Types.Index'Base (Opt_Payload_Length)); |
| 86 | + begin |
| 87 | + RFLX.CoAP.CoAP_Message.Get_Options_And_Payload |
| 88 | + (Context, Opt_Payload_Buffer); |
| 89 | + |
| 90 | + CoAP_SPARK.Messages.Encoding.Decode_Options_And_Payload |
| 91 | + (Data => Opt_Payload_Buffer, |
| 92 | + Status => State.Current_Status, |
| 93 | + Decoded_Content => Request_Content); |
| 94 | + |
| 95 | + if State.Current_Status = CoAP_SPARK.OK |
| 96 | + and then State.Request_Handler not in null |
| 97 | + then |
| 98 | + |
| 99 | + CoAP_SPARK.Log.Put_Line ("REQUEST: "); |
| 100 | + CoAP_SPARK.Messages.Print_Content |
| 101 | + (Item => Request_Content, |
| 102 | + Log_Level_Payload => CoAP_SPARK.Log.Debug); |
| 103 | + |
| 104 | + -- Call the request handler with the decoded content |
| 105 | + State.Request_Handler |
| 106 | + (Method => |
| 107 | + RFLX.CoAP.CoAP_Message.Get_Method (Context), |
| 108 | + Request_Content => Request_Content, |
| 109 | + Response_Codes => Response_Codes, |
| 110 | + Response_Content => Response_Content); |
| 111 | + |
| 112 | + CoAP_SPARK.Log.Put_Line ("RESPONSE: "); |
| 113 | + CoAP_SPARK.Messages.Print_Content |
| 114 | + (Item => Response_Content, |
| 115 | + Log_Level_Payload => CoAP_SPARK.Log.Debug); |
| 116 | + CoAP_SPARK.Messages.Print_Response_Kind |
| 117 | + (Item => Response_Codes); |
| 118 | + |
| 119 | + CoAP_SPARK.Messages.Encoding.Encode_Options_And_Payload |
| 120 | + (Options_And_Payload => Response_Content, |
| 121 | + Status => State.Current_Status, |
| 122 | + Encoded_Data => |
| 123 | + RFLX_Result.Options_And_Payload_Options_And_Payload, |
| 124 | + Encoded_Length => |
| 125 | + RFLX.CoAP.Length_16 |
| 126 | + (RFLX_Result.Options_And_Payload_Length)); |
| 127 | + |
| 128 | + RFLX_Result.Success_Code := RFLX.CoAP.Success_Response'Last; |
| 129 | + RFLX_Result.Client_Error_Code := |
| 130 | + RFLX.CoAP.Client_Error_Response'Last; |
| 131 | + RFLX_Result.Server_Error_Code := |
| 132 | + RFLX.CoAP.Server_Error_Response'Last; |
| 133 | + RFLX_Result.Message_Class := Response_Codes.Code_Class; |
| 134 | + |
| 135 | + case CoAP_SPARK.Messages.Response_Code |
| 136 | + (Response_Codes.Code_Class) |
| 137 | + is |
| 138 | + when RFLX.CoAP.Success => |
| 139 | + |
| 140 | + RFLX_Result.Success_Code := Response_Codes.Success_Code; |
| 141 | + |
| 142 | + when RFLX.CoAP.Client_Error => |
| 143 | + |
| 144 | + RFLX_Result.Client_Error_Code := |
| 145 | + Response_Codes.Client_Error_Code; |
| 146 | + |
| 147 | + when RFLX.CoAP.Server_Error => |
| 148 | + |
| 149 | + RFLX_Result.Server_Error_Code := |
| 150 | + Response_Codes.Server_Error_Code; |
| 151 | + |
| 152 | + end case; |
| 153 | + end if; |
| 154 | + end Handle_Request; |
129 | 155 | end if; |
130 | 156 |
|
131 | 157 | RFLX.CoAP.CoAP_Message.Take_Buffer |
|
0 commit comments