Пример #1
0
void init_dateform(void)
{
   auto int var, form;
   static FormVar dateform[7];

   /*
    *  Set up the date form.  To set up your own form you follow a
    *  similar set of steps.  First call sspec_addform.  Then add
    *  the variables creating the variable and adding it to the form.
    *  If you want to restrict the values of the variables you can
    *  use the sspec_setfvlen, sspec_setfvrange, or define a custom
    *  validation function with sspec_fvcheck.
    */

   form = sspec_addform("date.html", dateform, 7, SERVER_HTTP);

   // Set the title of the form
   sspec_setformtitle(form, "Set Date");

   var = sspec_addvariable("hour", &hour, INT16, "%02d", SERVER_HTTP);
   var = sspec_addfv(form, var);
   sspec_setfvname(form, var, "Hour");
   sspec_setfvlen(form, var, 2);
   sspec_setfvrange(form, var, 0, 24);

   var = sspec_addvariable("minute", &minute, INT16, "%02d", SERVER_HTTP);
   var = sspec_addfv(form, var);
   sspec_setfvname(form, var, "Minute");
   sspec_setfvlen(form, var, 2);
   sspec_setfvrange(form, var, 0, 60);

   var = sspec_addvariable("second", &second, INT16, "%02d", SERVER_HTTP);
   var = sspec_addfv(form, var);
   sspec_setfvname(form, var, "Second");
   sspec_setfvlen(form, var, 2);
   sspec_setfvrange(form, var, 0, 60);

   var = sspec_addvariable("month", &month, INT16, "%02d", SERVER_HTTP);
   var = sspec_addfv(form, var);
   sspec_setfvname(form, var, "month");
   sspec_setfvlen(form, var, 2);
   sspec_setfvrange(form, var, 0, 12);

   var = sspec_addvariable("day", &day, INT16, "%02d", SERVER_HTTP);
   var = sspec_addfv(form, var);
   sspec_setfvname(form, var, "day");
   sspec_setfvlen(form, var, 2);
   sspec_setfvrange(form, var, 0, 31);

   var = sspec_addvariable("year", &year, INT16, "%04d", SERVER_HTTP);
   var = sspec_addfv(form, var);
   sspec_setfvname(form, var, "year");
   sspec_setfvlen(form, var, 4);
   sspec_setfvrange(form, var, MY_FIRST_YEAR_SETTING, MY_FINAL_YEAR_SETTING);

   /*
    *  lock_date sets a flag that disables the automatic updating
    *  of the hour, minute, second, month, day, and year variables.
    *  The prolog gets called after the form is parsed correctly,
    *  but before the variables are updated.  The set_date function
    *  gets called after the variables are updated.  The lock_date
    *  function is necessary because the update_date function in
    *  main could be called between the time the variables are
    *  updated and the prolog completes its processing.
    */

   var = sspec_addfunction("lock_date", lock_date, SERVER_HTTP);
   sspec_setformprolog(form, var);
   var = sspec_addfunction("set_date", set_date, SERVER_HTTP);
   sspec_setformepilog(form, var);
}
Пример #2
0
void main(void)
{
	// Declare the FormVar array to hold form variable information
	auto FormVar myform[5];
	auto int var;
	auto int form;
	// This array lists the options that are possible for the fail variable
	static const char* fail_options[] = {
		"Email",
		"Page",
		"Email and page",
		"Nothing"
	};

	// Initialize variables
	temphi = 80;
	tempnow = 72;
	templo = 65;
	humidity = 0.3;
	strcpy(fail, "Page");

	// Add the form (array of variables)
	form = sspec_addform("myform.html", myform, 5, SERVER_HTTP);

	// Set the title of the form
	sspec_setformtitle(form, "ACME Thermostat Settings");

	// Add the first variable, and set it up with the form
	var = sspec_addvariable("temphi", &temphi, INT16, "%d", SERVER_HTTP);
	var = sspec_addfv(form, var);
	sspec_setfvname(form, var, "High Temp");
	sspec_setfvdesc(form, var, "Maximum in temperature range (60 - 90 °F)");
	sspec_setfvlen(form, var, 5);
	sspec_setfvrange(form, var, 60, 90);
	sspec_setfvcheck(form, var, checkHighTemp);

	// Add the second variable, and set it up with the form
	var = sspec_addvariable("tempnow", &tempnow, INT16, "%d", SERVER_HTTP);
	var = sspec_addfv(form, var);
	sspec_setfvname(form, var, "Current Temp");
	sspec_setfvdesc(form, var, "Current temperature in °F");
	sspec_setfvlen(form, var, 5);
	sspec_setfvreadonly(form, var, 1);

	// Add the third variable, and set it up with the form
	var = sspec_addvariable("templo", &templo, INT16, "%d", SERVER_HTTP);
	var = sspec_addfv(form, var);
	sspec_setfvname(form, var, "Low Temp");
	sspec_setfvdesc(form, var, "Minimum in temperature range (50 - 80 °F)");
	sspec_setfvlen(form, var, 5);
	sspec_setfvrange(form, var, 50, 80);
	sspec_setfvcheck(form, var, checkLowTemp);

	// Add the fourth variable, and set it up with the form
	var = sspec_addvariable("failure", fail, PTR16, "%s", SERVER_HTTP);
	var = sspec_addfv(form, var);
	sspec_setfvname(form, var, "Failure Action");
	sspec_setfvdesc(form, var, "Action to take in case of air-conditioning failure");
	sspec_setfvlen(form, var, 20);
	sspec_setfvoptlist(form, var, fail_options, 4);
	sspec_setfventrytype(form, var, HTML_FORM_PULLDOWN);

	// Add the fifth variable, and set it up with the form
	var = sspec_addvariable("humidity", &humidity, FLOAT32, "%.2f", SERVER_HTTP);
	var = sspec_addfv(form, var);
	sspec_setfvname(form, var, "Humidity");
	sspec_setfvdesc(form, var, "Target humidity (between 0.0 and 1.0)");
	sspec_setfvlen(form, var, 8);
	sspec_setfvfloatrange(form, var, 0.0, 1.0);

	// Create aliases for this form.  This allows the form to be accessed from
	// other locations.
	sspec_aliasspec(form, "index.html");
	sspec_aliasspec(form, "/");

	// Start network and wait for interface to come up (or error exit).
	sock_init_or_exit(1);
   http_init();
   tcp_reserveport(80);

   while (1) {
      http_handler();
   }
}