Index.c revision 9f7f5161cf2f6c1e29f4f11ff2a70454b223431a
1/**
2  @file
3  Generate the list of known pages.
4
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
10
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.
13
14**/
15
16#include <WebServer.h>
17
18
19/**
20  Respond with the list of known pages
21
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
25
26  @retval EFI_SUCCESS       The request was successfully processed
27
28**/
29EFI_STATUS
30IndexPage (
31  IN int SocketFD,
32  IN WSDT_PORT * pPort,
33  OUT BOOLEAN * pbDone
34  )
35{
36  CONST DT_PAGE * pPage;
37  CONST DT_PAGE * pPageEnd;
38  EFI_STATUS Status;
39
40  DBG_ENTER ( );
41
42  //
43  //  Send the index page
44  //
45  for ( ; ; ) {
46    //
47    //  Send the page header
48    //
49    Status = HttpPageHeader ( SocketFD, pPort, L"Index" );
50    if ( EFI_ERROR ( Status )) {
51      break;
52    }
53
54    //
55    //  Build the table header
56    //
57    Status = HttpSendAnsiString ( SocketFD,
58                                  pPort,
59                                  "<h1>UEFI Web Server</h1>\r\n"
60                                  "<table border=\"1\">\r\n"
61                                  "  <tr bgcolor=\"c0c0ff\"><th>Page</th><th>Description</th></tr>\r\n" );
62    if ( EFI_ERROR ( Status )) {
63      break;
64    }
65
66    //
67    //  Walk the list of pages
68    //  Skip the first page
69    //
70    pPage = &mPageList[0];
71    pPageEnd = &pPage[mPageCount];
72    pPage += 1;
73    while ( pPageEnd > pPage ) {
74      //
75      //  Build the table entry for this page
76      //
77      Status = HttpSendAnsiString ( SocketFD,
78                                    pPort,
79                                    "<tr><td><a target=\"_blank\" href=\"" );
80      if ( EFI_ERROR ( Status )) {
81        break;
82      }
83      Status = HttpSendUnicodeString ( SocketFD,
84                                       pPort,
85                                       &pPage->pPageName[1]);
86      if ( EFI_ERROR ( Status )) {
87        break;
88      }
89      Status = HttpSendAnsiString ( SocketFD,
90                                    pPort,
91                                    "\">" );
92      if ( EFI_ERROR ( Status )) {
93        break;
94      }
95      Status = HttpSendUnicodeString ( SocketFD,
96                                       pPort,
97                                       &pPage->pPageName[1]);
98      if ( EFI_ERROR ( Status )) {
99        break;
100      }
101      Status = HttpSendAnsiString ( SocketFD,
102                                    pPort,
103                                    "</a></td><td>" );
104      if ( EFI_ERROR ( Status )) {
105        break;
106      }
107      Status = HttpSendUnicodeString ( SocketFD,
108                                       pPort,
109                                       pPage->pDescription );
110      if ( EFI_ERROR ( Status )) {
111        break;
112      }
113      Status = HttpSendAnsiString ( SocketFD,
114                                    pPort,
115                                    "</td></tr>\r\n" );
116      if ( EFI_ERROR ( Status )) {
117        break;
118      }
119
120      //
121      //  Set the next page
122      //
123      pPage += 1;
124    }
125    if ( EFI_ERROR ( Status )) {
126      break;
127    }
128
129    //
130    //  Build the table trailer
131    //
132    Status = HttpSendAnsiString ( SocketFD,
133                                  pPort,
134                                  "</table>\r\n" );
135    if ( EFI_ERROR ( Status )) {
136      break;
137    }
138
139    //
140    //  Send the page trailer
141    //
142    Status = HttpPageTrailer ( SocketFD, pPort, pbDone );
143    break;
144  }
145
146  //
147  //  Return the operation status
148  //
149  DBG_EXIT_STATUS ( Status );
150  return Status;
151}
152