]>
git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Sockets/WebServer/Handles.c
3 Display the handles in the system
5 Copyright (c) 2011-2012, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <WebServer.h>
20 Respond with the handles in the system
22 @param [in] SocketFD The socket's file descriptor to add to the list.
23 @param [in] pPort The WSDT_PORT structure address
24 @param [out] pbDone Address to receive the request completion status
26 @retval EFI_SUCCESS The request was successfully processed
42 EFI_HANDLE
* pHandleArray
;
44 EFI_HANDLE
* pHandleEnd
;
45 EFI_GUID
** ppGuidArray
;
47 EFI_GUID
** ppGuidEnd
;
51 CONST UINTN cDigit
[] = {
52 3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15 };
57 // Send the handles page
61 // Send the page header
63 Status
= HttpPageHeader ( SocketFD
, pPort
, L
"Handle Database" );
64 if ( EFI_ERROR ( Status
)) {
69 // Build the table header
71 Status
= HttpSendAnsiString ( SocketFD
,
73 "<h1>Handle Database</h1>\r\n"
74 "<table border=\"1\">\r\n"
75 " <tr bgcolor=\"c0c0ff\"><th>Handle</th><th>Protocol Guids</th></tr>\r\n" );
76 if ( EFI_ERROR ( Status
)) {
81 // Determine the number of handles in the database
84 Status
= gBS
->LocateHandle ( AllHandles
,
89 if ( EFI_BUFFER_TOO_SMALL
== Status
) {
91 // Allocate space for the handles
93 Status
= gBS
->AllocatePool ( EfiRuntimeServicesData
,
95 (VOID
**) &pHandleArray
);
96 if ( !EFI_ERROR ( Status
)) {
98 // Get the list of handles
100 Status
= gBS
->LocateHandle ( AllHandles
,
105 if ( !EFI_ERROR ( Status
)) {
106 Entries
= LengthInBytes
/ sizeof ( *pHandleArray
);
107 pHandle
= pHandleArray
;
108 pHandleEnd
= &pHandle
[ Entries
];
109 while ( pHandleEnd
> pHandle
) {
111 // Build the table entry for this page
113 Status
= HttpSendAnsiString ( SocketFD
,
115 "<tr><td><code>0x" );
116 if ( EFI_ERROR ( Status
)) {
119 Value
= (UINTN
) *pHandle
;
120 for ( Shift
= ( sizeof ( Shift
) << 3 ) - 4; 0 <= Shift
; Shift
-= 4 ) {
122 // Convert the next address nibble to ANSI hex
124 Digit
= (( Value
>> Shift
) & 0xf ) | '0';
126 Digit
+= 'a' - '0' - 10;
130 // Display the address digit
132 Status
= HttpSendByte ( SocketFD
,
135 if ( EFI_ERROR ( Status
)) {
139 if ( EFI_ERROR ( Status
)) {
144 // Start the second column
146 Status
= HttpSendAnsiString ( SocketFD
,
148 "</code></td><td><code>\r\n" );
149 if ( EFI_ERROR ( Status
)) {
154 // Determine the number of protocols connected to this handle
156 Status
= gBS
->ProtocolsPerHandle ( *pHandle
,
159 if ( EFI_ERROR ( Status
)) {
162 ppGuid
= ppGuidArray
;
163 ppGuidEnd
= &ppGuid
[ GuidCount
];
164 while ( ppGuidEnd
> ppGuid
) {
168 pDigit
= (UINT8
*) *ppGuid
;
169 for ( Index
= 0; 16 > Index
; Index
++ ) {
171 // Separate the portions of the GUID
172 // 99E87DCF-6162-40c5-9FA1-32111F5197F7
177 || ( 10 == Index
)) {
178 Status
= HttpSendByte ( SocketFD
,
181 if ( EFI_ERROR ( Status
)) {
187 // Display the GUID digits
189 Value
= pDigit
[ cDigit
[ Index
]];
190 for ( Shift
= 4; 0 <= Shift
; Shift
-= 4 ) {
192 // Convert the next address nibble to ANSI hex
194 Digit
= (( Value
>> Shift
) & 0xf ) | '0';
196 Digit
+= 'a' - '0' - 10;
200 // Display the address digit
202 Status
= HttpSendByte ( SocketFD
,
205 if ( EFI_ERROR ( Status
)) {
209 if ( EFI_ERROR ( Status
)) {
215 // Separate each GUID
217 Status
= HttpSendAnsiString ( SocketFD
,
220 if ( EFI_ERROR ( Status
)) {
225 // Set the next protocol
231 // Free the GUID array
233 gBS
->FreePool ( ppGuidArray
);
234 if ( EFI_ERROR ( Status
)) {
241 Status
= HttpSendAnsiString ( SocketFD
,
243 "</code></td></tr>\r\n" );
244 if ( EFI_ERROR ( Status
)) {
249 // Set the next handle
256 // Done with the handle array
258 gBS
->FreePool ( pHandleArray
);
263 // Build the table trailer
265 Status
= HttpSendAnsiString ( SocketFD
,
268 if ( EFI_ERROR ( Status
)) {
273 // Send the page trailer
275 Status
= HttpPageTrailer ( SocketFD
, pPort
, pbDone
);
280 // Return the operation status
282 DBG_EXIT_STATUS ( Status
);