/** * Does network and HTTP setup */ void setupHttp() { // IP Buffer char buffer[16]; // User ID int userid; // Initialize the board brdInit(); // Initialize the socket sock_init(); // Wait for IP address to be obtained while (ifpending(IF_DEFAULT) == IF_COMING_UP) { tcp_tick(NULL); } // Output the IP Address printf("My IP address is %s\n", inet_ntoa(buffer, gethostid())); //Set up the HTTP Server http_init(); tcp_reserveport(80); // Set redirect http_set_path("/", "/index.zhtml"); // Set up authentication sspec_addrule("/", "Admin", admin, admin, SERVER_ANY, SERVER_AUTH_BASIC, NULL); // Add our users // Ario userid = sauth_adduser("ario", "fish", SERVER_ANY); sauth_setusermask(userid, admin, NULL); // Chan userid = sauth_adduser("chan", "bar", SERVER_ANY); sauth_setusermask(userid, admin, NULL); // Jeff userid = sauth_adduser("jeff", "bar7", SERVER_ANY); sauth_setusermask(userid, admin, NULL); // Shea userid = sauth_adduser("shea", "bar2", SERVER_ANY); sauth_setusermask(userid, admin, NULL); // Toby userid = sauth_adduser("toby", "bar3", SERVER_ANY); sauth_setusermask(userid, admin, NULL); //Done }
SSPEC_MIMETABLE_END int main() { int rc; char buf[20]; printf("Initializing filesystem...\n"); // Note: sspec_automount automatically initializes all known filesystems. We assume // that the first partition on the device will be a valid FAT12 or FAT16 partition // which will be mounted on '/A'. rc = sspec_automount(SSPEC_MOUNT_ANY, NULL, NULL, NULL); if (rc) printf("Failed to initialize, rc=%d\nProceeding anyway...\n", rc); // Start network and wait for interface to come up (or error exit). sock_init_or_exit(1); http_init(); http_set_path("/A/", "static.htm"); // Set a root directory (the FAT first partition) and // default resource name. tcp_reserveport(80); printf("Now try connecting via your web browser.\n"); printf("Try a URL of http://%s/\n", inet_ntoa(buf, MY_ADDR(IF_DEFAULT))); printf("\nPress any key to bring down the server cleanly.\n"); while (1) { http_handler(); if (kbhit()) { // You should always unmount the device on exit to flush cache entries fat_UnmountDevice(sspec_fatregistered(0)->dev); exit(0); } } return 0; }