aboutsummaryrefslogtreecommitdiff
path: root/src/Thorns.c
blob: a0720bbf19a08c8e67afe1786afdc9f5d8a80742 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
 /*@@
   @file      Groups.c
   @date      Wed Sep 24 23:47:43 2000
   @author    Gabrielle Allen
   @desc 
   Pages about thorns
   @enddesc
   @version $Header$
 @@*/

#include <stdio.h>

#include "cctk.h"

#include "util_String.h"

#include "httpRequest.h"
#include "Content.h"
#include "SString_Namespace.h"
#include "SStringHTML_Namespace.h"

static const char *rcsid = "$Header$";

CCTK_FILEVERSION(CactusConnect_HTTPD_Thorns_c)

/********************************************************************
 *********************     Local Data Types   ***********************
 ********************************************************************/

/********************************************************************
 ********************* Local Routine Prototypes *********************
 ********************************************************************/

static int ThornMainPage(const cGH *cctkGH, httpRequest *request, void *data);
static int ThornPage(const cGH *cctkGH, httpRequest *request, void *data);


/********************************************************************
 ********************* Other Routine Prototypes *********************
 ********************************************************************/

int HTTPi_RegisterThornPages(void);

/********************************************************************
 *********************     Local Data   *****************************
 ********************************************************************/

/********************************************************************
 *********************     External Routines   **********************
 ********************************************************************/

 /*@@
   @routine    HTTPi_RegisterThornsPages
   @date       Wed Sep 14 11:29:43 2000
   @author     Gabrielle Allen
   @desc 
   Httpd utils registration routine.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
#define THORN_NAME_MAXLENGTH (27+20)
int HTTPi_RegisterThornPages(void)
{
  int i;
  char pagename[THORN_NAME_MAXLENGTH] = { '\0' };

  /* Register the group info page. */
  HTTP_RegisterPage("/Thorns", ThornMainPage, NULL);

  HTTP_ContentLink("/Thorns/index.html", "Thorns",
                   "Information from Flesh and individual thorns",
                   HTTP_QUICKLINK);

  for (i = 0; i < CCTK_NumCompiledThorns (); i++)
  {
    const char *thorn = CCTK_CompiledThorn(i);
    char *namecopy;

    sprintf(pagename,"/Thorns/%s", thorn);

    namecopy = Util_Strdup(thorn); /*SW isn't this a memory leak?*/

    HTTP_RegisterPage(pagename, ThornPage, namecopy);
  }

  return 0;
}

/********************************************************************
 *********************     Local Routines   *************************
 ********************************************************************/


/******************************************************************************
 *************************** Thorn Page **************************************
 ******************************************************************************/

 /*@@
   @routine    ThornMainPage
   @date       Thu Sep 14 23:47:43 2000
   @author     Gabrielle Allen
   @desc 
   Displays the thorn main page.
   @enddesc 
   @calls     
   @calledby   
@@*/
static int ThornMainPage(const cGH *cctkGH, httpRequest *request, void *data)
{
  int i;
  int retval = -1;
  int foundone = 0;
  const char *thorn;
  String *message = String_New();

  /* avoid compiler warning about unused parameter */
  data = data;

  HTTP_SendOKHeader( request );

  HTTP_SetDoctype( message );
  HTTP_SendString(request, message);
  /* Start the page */
  HTTP_Send(request, "<html><head><title>Cactus Thorns</title>\n");

  HTTP_SetHeadInfo( message);
  HTTP_SendString(request, message );

  HTTP_Send(request,"<style type=\"text/css\">\n"
                  "\t.thorns td { text-align: left; } \n"
                  "</style>\n");
  HTTP_Send(request,"</head>\n<body>\n");

  /* HTTP_SendString out the header part. */

  HTTP_SetContentHeaderString(cctkGH,0,message,NULL);

  retval = HTTP_SendString(request, message);

  retval = HTTP_Send(request, "<h1>Thorns</h1>\n"
         "<p>These pages describe the thorns used in this simulation.</p>\n");

  retval = HTTP_Send(request, "<table><tr><td>\n");

  for (i = 0; i < CCTK_NumCompiledThorns (); i++)
  {
    thorn = CCTK_CompiledThorn (i);
    if (CCTK_IsThornActive (thorn))
    {
      if (!foundone)
      {
        HTTP_Send(request,
               "<h2>Active Thorns</h2>\n"
               "<div class=\"center\">\n"
               "<table class=\"thorns\" cellspacing=\"0\" cellpadding=\"5\">\n"
               "<tr>\n"
               "<th>Thorn Name</th>\n"
               "<th>Implementation</th>\n"
               "</tr>\n");
        foundone++;
      }
      SetToCString(message, "<tr>\n<td><a href=\"/Thorns/");
      ConcatCString(message, thorn);
      ConcatCString(message, "/\">");
      ConcatCString(message, thorn);
      ConcatCString(message, "</a></td>\n<td>");
      ConcatCString(message, CCTK_ThornImplementation(thorn));
      ConcatCString(message, "</td>\n</tr>\n");
      HTTP_SendString(request, message);
    }
  }

  if (foundone)
  {
    HTTP_Send(request,"</table></div>\n");
  }

  retval = HTTP_Send(request,"</td><td>");

  foundone = 0;
  for (i = 0; i < CCTK_NumCompiledThorns (); i++)
  {
    thorn = CCTK_CompiledThorn (i);
    if (!CCTK_IsThornActive (thorn))
    {

      if (!foundone)
      {
        HTTP_Send(request,
               "<h2>Dormant Thorns</h2>\n"
               "<div class=\"centered\">\n"
               "<table class=\"thorns\" cellspacing=\"0\" cellpadding=\"5\">\n"
               "<tr>\n"
               "<th>Thorn Name</th>\n"
               "<th>Implementation</th>\n"
               "</tr>\n");
        foundone++;
      }

      SetToCString(message, "<tr>\n<td>\n");
      ConcatCString(message, thorn);
      ConcatCString(message, "</td>\n<td>");
      ConcatCString(message, CCTK_ThornImplementation(thorn));
      ConcatCString(message, "</td>\n</tr>\n");
      HTTP_SendString(request, message);
      
    }
  }

  if (foundone)
  {
    HTTP_Send(request,"</table>\n</div>\n");
  }

  retval = HTTP_Send(request,"</td>\n</tr>\n</table>\n");

  /* Write out the footer part. */

  HTTP_SetContentFooterString(cctkGH,0,message);
  retval = HTTP_SendString(request, message);

  String_Delete( message );
  return retval;
}



 /*@@
   @routine    ThornPage
   @date       Sun Sep 24 15:13:55 2000
   @author     Gabrielle Allen
   @desc 
   Individual thorn information
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
static int ThornPage(const cGH *cctkGH, httpRequest *request, void *data)
{
  int retval=0;
  String *message = String_New();
  const char *thorn = (const char *)data;
  
  HTTP_SendOKHeader(request);

  HTTP_SetDoctype( message );
  HTTP_SendString(request, message);

  /* Start the page */
  SetToCString(message, "<html>\n<head>\n<title>Thorn Page : ");
  ConcatCString(message, thorn);
  ConcatCString(message, "</title>\n");

  HTTP_SendString(request, message);
  HTTP_SetHeadInfo( message);
  HTTP_SendString(request, message );

  HTTP_Send(request,"</head>\n<body>\n");

  HTTP_SetContentHeaderString(cctkGH,0,message,NULL);

  HTTP_SendString(request, message);

  SetToCString(message, "<h1>Thorn ");
  ConcatCString(message, thorn);
  ConcatCString(message, "</h1>\n");

  HTTP_SendString(request, message);
  
  SetToCString(message,"<p>This page will include all the information about "
                       "thorn \'");
  ConcatCString(message, thorn);
  ConcatCString(message, "\'.\n For now, only information about the parameters"
                         " is given.</p>\n");

  ConcatCString(message, "<ul>\n"
                         "<li><a href=\"/Parameters/");
  ConcatCString(message, thorn );
  ConcatCString(message, "\">Parameters</a></li>\n"
                         "</ul>\n");
  HTTP_SendString(request, message);

  /* Write out the footer part. */
    
  HTTP_SetContentFooterString(cctkGH, 0, message);
  retval = HTTP_SendString(request, message);

  String_Delete( message );
  return retval;
}