The CSP version of SetGetTimePage.cpp

Barracuda supports a very advanced type of server side scripting, which we call CSP. CSP is similar to Active Server Pages, ASP, which was invented by Microsoft. With CSP, you can embed C or C++ directly into an HTML template page created by an HTML designer.

Please see our CSP tag language white paper for more information on how to design and do rapid development of advanced device control logic using the CSP compiler.

1 <html> 2 <body> 3 <% /* This is the CSP version of SetGetTimePage.cpp */ 4 if(request->getMethodType() == HttpRequest_Post) /* HTTP POST request */ 5 { 6 HttpTime time; 7 struct tm tm; 8 const char* timeStr = request->getParameter("time"); 9 if(timeStr == NULL || (time=httpParseDate(timeStr)) == 0) 10 { 11 %> 12 <p> 13 Cannot parse date string. 14 Date string must be in RFC1123 or RFC850 format.<br/> 15 <a href='<%=getName()%>'>Try again</a> 16 </p> 17 <% 18 } 19 else 20 { 21 httpTime2tm(&tm, time); 22 setRTC(&tm); 23 response->sendRedirect(response->encodeRedirectURL(getName())); 24 return; 25 } 26 } 27 else /* HTTP GET request */ 28 { 29 %> 30 <p> 31 Current day and time is: <% printCurrentTime(response); %> 32 </p> 33 <p> 34 <form method='post'> 35 <input type='text' name='time' size='30'/> 36 <br/> 37 <input type='submit'/> 38 </form> 39 </p> 40 <% 41 } 42 %> 43 </body> 44 </html> 45 46 <%g 47 48 #include <HttpServerLib.h> 49 #include <time.h> 50 #include <smx.h> 51 #include <pcutil.h> 52 53 static void 54 setRTC(struct tm* tm) 55 { 56 #if PC_RTC 57 Set_RTC_Time(tm); 58 Set_RTC_Date(tm); 59 #endif 60 } 61 62 static void 63 printCurrentTime(HttpResponse* response) 64 { 65 static const char* wd[7] = { 66 "Sun","Mon", "Tue", "Wed", "Thu", "Fri", "Sat" 67 }; 68 static const char* months[12] = { 69 "Jan","Feb", "Mar", "Apr", "May", "Jun", 70 "Jul","Aug", "Sep", "Oct", "Nov", "Dec" 71 }; 72 struct tm tm; 73 dword time = get_stime(); 74 httpTime2tm(&tm, time); 75 response->printf("%s, %02d %s %d %02d:%02d:%02d GMT", 76 wd[tm.tm_wday], 77 tm.tm_mday, 78 months[tm.tm_mon], 79 tm.tm_year+1900, 80 tm.tm_hour, 81 tm.tm_min, 82 tm.tm_sec); 83 } 84 85 %>