void main(void) { /* * Get the compressed sizes of the files */ xmem2root(&text_size, alice_html, 4); text_size &= ZIMPORT_MASK; xmem2root(&image_size, alice_jpg, 4); image_size &= ZIMPORT_MASK; /* * When compressed files are added via the sspec_addxmemfile() function, * they are automatically detected as such. This is in distinction to * the static resource table setup (i.e. SSPEC_RESOURCE_* macros) which * require explicit specification at compile time. * * Note, that jpeg or gif files (as in the following) do not generally * compress well (or at all). Hence, it is best to leave image files uncompressed. */ sspec_addxmemfile("/alice.jpg", alice_jpg, SERVER_HTTP); sspec_addvariable("text_size", &text_size, INT32, "%ld", SERVER_HTTP); sspec_addvariable("image_size", &image_size, INT32, "%ld", SERVER_HTTP); // Start network and wait for interface to come up (or error exit). sock_init_or_exit(1); http_init(); while (1) { http_handler(); } }
void main() { /* FORM stuff */ sspec_addxmemfile("register.html", reg_form, SERVER_HTTP); sspec_addfunction("submit.cgi", submit, SERVER_HTTP); /* normal SSI button stuff */ sspec_addxmemfile("/", index_html, SERVER_HTTP); sspec_addxmemfile("index.shtml", index_html, SERVER_HTTP); sspec_addxmemfile("showsrc.shtml", showsrc_shtml, SERVER_HTTP); sspec_addxmemfile("rabbit1.gif", rabbit1_gif, SERVER_HTTP); sspec_addxmemfile("ledon.gif", ledon_gif, SERVER_HTTP); sspec_addxmemfile("ledoff.gif", ledoff_gif, SERVER_HTTP); sspec_addxmemfile("button.gif", button_gif, SERVER_HTTP); sspec_addxmemfile("ssi.c", ssi_c, SERVER_HTTP); sspec_addvariable("led1", led1, PTR16, "%s", SERVER_HTTP); sspec_addvariable("led2", led2, PTR16, "%s", SERVER_HTTP); sspec_addvariable("led3", led3, PTR16, "%s", SERVER_HTTP); sspec_addvariable("led4", led4, PTR16, "%s", SERVER_HTTP); sspec_addfunction("led1tog.cgi", led1toggle, SERVER_HTTP); sspec_addfunction("led2tog.cgi", led2toggle, SERVER_HTTP); sspec_addfunction("led3tog.cgi", led3toggle, SERVER_HTTP); sspec_addfunction("led4tog.cgi", led4toggle, SERVER_HTTP); sspec_addfunction("audit", audit_list_print, SERVER_HTTP); strcpy(led1,"ledon.gif"); strcpy(led2,"ledon.gif"); strcpy(led3,"ledoff.gif"); strcpy(led4,"ledon.gif"); /* Init the audit history */ AuditInit(); /* init FORM searchable names - must init ALL FORMSpec structs! */ FORMSpec[0].name = "user_name"; FORMSpec[1].name = "user_email"; // 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(); } }
void main() { auto char buf[128]; auto int rc, i, uid, handle; text_size = 12345; image_size = xgetlong(alice_jpg) & ZIMPORT_MASK; printf("Initializing filesystems...\n"); // Note: sspec_automount automatically initializes all known filesystems. rc = sspec_automount(SSPEC_MOUNT_ANY, NULL, NULL, NULL); if (rc) printf("Failed to initialize, rc=%d\nProceeding anyway...\n", rc); sspec_addxmemfile("/alice.jpg", alice_jpg, SERVER_HTTP | SERVER_COMPRESSED); sspec_addvariable("text_size", &text_size, INT32, "%ld", SERVER_HTTP); sspec_addvariable("image_size", &image_size, INT32, "%ld", SERVER_HTTP); /* * sock_init initializes the TCP/IP stack. * http_init initializes the web server. * ftp_init initializes the FTP server. */ sock_init(); http_init(); ftp_init(NULL); // Create a permissions rule for fs2, FAT, and everything else sspec_addrule("/fs2", "fs2-realm", ALL_GROUPS, ADMIN_GROUP, SERVER_ANY, 0, NULL); sspec_addrule("/fs2/file1", "another-realm", ALL_GROUPS, ADMIN_GROUP, SERVER_ANY, 0, NULL); sspec_addrule("/A", "fat-A-realm", ALL_GROUPS, ADMIN_GROUP, SERVER_ANY, 0, NULL); sspec_addrule("/E", "fat-E-realm", ALL_GROUPS, ADMIN_GROUP, SERVER_ANY, 0, NULL); // Add users and ensure users are in the correct group(s). uid = sauth_adduser("root", "super", SERVER_ANY); sauth_setwriteaccess(uid, SERVER_ANY); sauth_setusermask(uid, ALL_GROUPS, NULL); uid = sauth_adduser("admin", "work", SERVER_HTTP | SERVER_FTP); sauth_setwriteaccess(uid, SERVER_HTTP | SERVER_FTP); sauth_setusermask(uid, ADMIN_GROUP, NULL); uid = sauth_adduser("anonymous", "", SERVER_FTP); sauth_setusermask(uid, USER_GROUP, NULL); ftp_set_anonymous(uid); // This FTP user does not require password, but cannot write anything uid = sauth_adduser("foo", "bar", SERVER_HTTP); sauth_setusermask(uid, USER_GROUP, NULL); // First, let's list the current working directory as seen by the 1st HTTP server instance. // The CWD for HTTP is always the root directory. printf("Root directory listing for the HTTP server...\n"); for (handle = 0; handle >= 0; handle >= 0 ? printf(buf) : 0) handle = sspec_dirlist(handle, buf, sizeof(buf), http_getcontext(0), SSPEC_LIST_LONG); printf("\n"); /* * tcp_reserveport causes the web server to ignore requests when there * isn't an available socket (HTTP_MAXSERVERS are all serving index_html * or rabbit1.gif). This saves some memory, but can cause the client * delays when retrieving pages. */ tcp_reserveport(80); /* * http_handler needs to be called to handle the active http servers. * ftp_tick needs to be called to handle the active FTP servers. */ printf("Press any key to safely shut-down server.\n"); while (1) { http_handler(); ftp_tick(); if (kbhit()) { #ifdef DO_FAT // Unmount all of the mounted FAT partitions & devices before exit for (i = 0; i < num_fat_devices * FAT_MAX_PARTITIONS; i += FAT_MAX_PARTITIONS) { if (fat_part_mounted[i]) { fat_UnmountDevice(fat_part_mounted[i]->dev); } } #endif exit(rc); } } }
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); }
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(); } }