main() { /* Set both LED's initially ON. When update_outputs() is called, the * human will see it this way. */ strcpy(led2,led_on_gif); strcpy(led3,led_on_gif); sock_init(); http_init(); tcp_reserveport(80); /* Configure the I/O ports. Disable slave port which makes * Port A an output, and PORT E not have SCS signal. * Read shadow and set PE1 and PE7 as normal I/O. * LED's are controlled by PE1 and PE7, so make them outputs. */ WrPortI(SPCR, NULL, 0x84); WrPortI(PEFR, & PEFRShadow, ~((1<<7)|(1<<1)) & PEFRShadow); WrPortI(PEDDR, & PEDDRShadow, (1<<7)|(1<<1)); while (1) { update_outputs(); http_handler(); } }
void main() { SSL_Cert_t my_cert; // Start network and wait for interface to come up (or error exit). sock_init_or_exit(1); http_init(); memset(&my_cert, 0, sizeof(my_cert)); // When using HTTPS (i.e. HTTP over SSL or TLS), the certificates need // to be parsed and registered with the library. For use with a // server, we need to know our own private key. if (SSL_new_cert(&my_cert, server_pub_cert, SSL_DCERT_XIM, 0) || SSL_set_private_key(&my_cert, server_priv_key, SSL_DCERT_XIM)) exit(7); // Register certificate with HTTPS server. https_set_cert(&my_cert); tcp_reserveport(443); /* * http_handler needs to be called to handle the active http servers. */ while (1) { http_handler(); } }
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(void) { auto int i; // Initialized the #web-registered variables. for (i = 0; i < 5; i++) { array1[i] = i + 1; } array2[0][0] = 2; array2[0][1] = 3; array2[1][0] = 4; array2[1][1] = 5; for (i = 0; i < 3; i++) { array3[i] = i + 5; } // Initialize the TCP/IP stack and HTTP server sock_init(); http_init(); // This yields a performance improvement for an HTTP server tcp_reserveport(80); while (1) { // Drive the HTTP server http_handler(); } }
main() { // Set Port A pins for LEDs low BitWrPortI(PADR, &PADRShadow, 1, DS1); BitWrPortI(PADR, &PADRShadow, 1, DS2); BitWrPortI(PADR, &PADRShadow, 1, DS3); BitWrPortI(PADR, &PADRShadow, 1, DS4); // Make Port A bit-wide output BitWrPortI(SPCR, &SPCRShadow, 1, 2); BitWrPortI(SPCR, &SPCRShadow, 0, 3); strcpy(led1,"ledon.gif"); strcpy(led2,"ledoff.gif"); strcpy(led3,"ledon.gif"); strcpy(led4,"ledoff.gif"); sock_init_or_exit(1); http_init(); tcp_reserveport(80); while (1) { update_outputs(); http_handler(); } }
SSPEC_MIMETABLE_END void main() { /* * sock_init initializes the TCP/IP stack. * http_init initializes the web server. */ sock_init(); http_init(); /* * 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); dlp_init(); /* * http_handler needs to be called to handle the active http servers. */ for(;;) { tcp_tick(NULL); http_handler(); dlp_handler(); } }
void main(void) { // 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(); } }
main(){ int correct, i; brdInit(); // sock_init initializes the TCP/IP stack. // http_init initializes the web server. sock_init(); http_init(); tcp_reserveport(80); mode = -1; // -1 = uninitialized while(1){ if(mode== -1){ InitializeGame(); mode = 0; } http_handler(); if(numUsedGuesses == 6){ // guesses used up mode = 1; numUsedGuesses = 0; strcpy(hint,wrd->answer); } if(character) { // new character entered correct = 0; // assume incorrect guess // see if character is in word for(i = 0 ; i < strlen(wrd->answer) ; i++) { if(wrd->answer[i] == (char)character) { guess[i] = newGuess[2*i] = (char)character; correct = 1; } } // see if word is guessed correctly if( !strcmpi(guess, wrd->answer) ){ prompt[0] = 0; numUsedGuesses = 7; // 7 signals win } else if(correct == 0) { numUsedGuesses++; currentGIF++; // use next GIF sprintf(prompt,"You have %d guesses left!", 6-numUsedGuesses); } character = 0; } } }
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() { brdInit(); sock_init(); http_init(); init_dateform(); init_log(); tcp_reserveport(80); // mark port 80 as a server port. for(;;) { update_date(); http_handler(); } }
void main(void) { brdInit(); sock_init_or_exit(1); // call debug function (provides handy information) http_init(); init_dateform(); init_log(); tcp_reserveport(80); // mark port 80 as a server port. for (;;) { update_date(); http_handler(); } }
SSPEC_RESOURCETABLE_END void main() { char buf[20]; sock_init(); http_init(); tcp_reserveport(80); printf("Ready: point your browser to http://%s/\n\n", inet_ntoa(buf, MY_ADDR(IF_DEFAULT))); while (1) { http_handler(); } }
SSPEC_RESOURCETABLE_END void main() { /* 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() { SSL_Cert_t my_cert; /* * sock_init initializes the TCP/IP stack. * http_init initializes the web server. */ // Start network and wait for interface to come up (or error exit). sock_init_or_exit(1); http_init(); memset(&my_cert, 0, sizeof(my_cert)); // When using HTTPS (i.e. HTTP over SSL or TLS), the certificates need // to be parsed and registered with the library. For use with a // server, we need to know our own private key. if (SSL_new_cert(&my_cert, server_pub_cert, SSL_DCERT_XIM, 0) || SSL_set_private_key(&my_cert, server_priv_key, SSL_DCERT_XIM)) exit(7); // Register certificate with HTTPS server. https_set_cert(&my_cert); /* * 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); // Also reserve the HTTPS port tcp_reserveport(443); /* * http_handler needs to be called to handle the active http servers. */ while (1) { http_handler(); } }
/** * Task that handles HTTP requests */ void httpTask(void *data) { // Error reference INT8U err; // Loop forever while(1) { // Try to take a semaphore (this will block us the second time) OSSemPend(switchToHTTP, 0, &err); // Interact with the web http_handler(); // Post a semaphore so that the switch task can be unblocked OSSemPost(httpToSwitch); } }
void main(void) { // Initialize the temperature temperature = 72; // Initialize the TCP/IP stack and HTTP server // Start network and wait for interface to come up (or error exit). sock_init_or_exit(1); http_init(); // This yields a performance improvement for an HTTP server tcp_reserveport(80); while (1) { // Drive the HTTP server http_handler(); } }
main() { brdInit(); //initialize board for this demo strcpy(led1,"ledon.gif"); strcpy(led2,"ledoff.gif"); sock_init_or_exit(1); http_init(); tcp_reserveport(80); while (1) { update_outputs(); http_handler(); } }
void main(void) { // Initialize the global, #web-registered variables. color = 3; city = 53549; // Initialize the TCP/IP stack and HTTP server // Start network and wait for interface to come up (or error exit). sock_init_or_exit(1); http_init(); // This yields a performance improvement for an HTTP server tcp_reserveport(80); while (1) { // Drive the HTTP server http_handler(); } }
void main(void) { LogEntry loginfo; int status; char buf[200]; /* * This call is necessary to initialize target communications * beween the DeviceMate and the target processor. */ targetproc_init(); /* * Initialize the TCP/IP stack and the web server. */ sock_init(); http_init(); /* * The following improves interactive performance of the web server. */ tcp_reserveport(80); /* * Log an initial entry. */ #define LOG_TEST_STRING "~~~{ Started test run. }~~~" status = log_put(LOG_MAKEPRI(2,LOG_INFO), 0, LOG_TEST_STRING, strlen(LOG_TEST_STRING)); if (status != 0) { printf("Failed to add 1st message: %d\n", status); } /* * Drive the target communications and the web server continuously. * This is all that is necessary as the main part of the program. */ for (;;) { targetproc_tick(); http_handler(); } }
main() { // initialize the controller initsystem(); sock_init(); http_init(); tcp_reserveport(80); // set the initial state of the LED's strcpy(led_LED0,"ledon.gif"); ledOut(LED0, ON); strcpy(led_LED1,"ledon.gif"); ledOut(LED1, ON); strcpy(led_LED2,"ledon.gif"); ledOut(LED2, ON); strcpy(led_LED3,"ledon.gif"); ledOut(LED3, ON); // process WEB page requests and update the LED's while (1) { update_leds(); http_handler(); } }
void main() { // initialize the controller brdInit(); sock_init(); http_init(); tcp_reserveport(80); // set the initial state of the LED's strcpy(led_DS4,"ledon.gif"); ledOut(DS4, ON); strcpy(led_DS5,"ledon.gif"); ledOut(DS5, ON); strcpy(led_DS6,"ledoff.gif"); ledOut(DS6, OFF); strcpy(led_DS7,"ledon.gif"); ledOut(DS7, ON); strcpy(led_DS8,"ledon.gif"); ledOut(DS8, ON); // process WEB page requests and update the LED's while (1) { update_leds(); http_handler(); } }
SSPEC_RESOURCETABLE_END void main() { /* * sock_init initializes the TCP/IP stack. * http_init initializes the web server. */ #ifdef USE_IDIGI // Start iDigi services if (idigi_init()) exit(1); #else // Start network and wait for interface to come up (or error exit). sock_init_or_exit(1); #endif http_init(); /* * 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. */ while (1) { #ifdef USE_IDIGI idigi_tick(); #endif http_handler(); } }
void main(void) { // Give sane defaults to the global variables strcpy(my_string, "Hello, world!"); inum = 150; lnum = 60000; uinum = 123; fpoint = 4.0; // Initialize the TCP/IP stack and HTTP server // Start network and wait for interface to come up (or error exit). sock_init_or_exit(1); http_init(); // This yields a performance improvement for an HTTP server tcp_reserveport(80); while (1) { // Drive the HTTP server http_handler(); } }
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; }
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); } } }
//extern int vivid; //extern int proto[PROTO_CATEGORY]; void tcp_handler(const u_char *packet, int len) { const struct sniff_tcp *tcp; int size_tcp; u_short sport; u_short dport; u_short flags; tcp = (struct sniff_tcp*)(packet); size_tcp = TH_HL(tcp)*4; if (size_tcp < 20) { printf(" * Invalid TCP header length: %u bytes\n", size_tcp); return; } sport = ntohs(tcp->th_sport); dport = ntohs(tcp->th_dport); flags = (ntohs(tcp->th_hl_flags))&TH_FLAGS; #if 0 if(flags&TH_FIN) printf("\tFIN"); if(flags&TH_SYN) printf("\tSYN"); if(flags&TH_RST) printf("\tRST"); if(flags&TH_PUSH) printf("\tPSH"); if(flags&TH_ACK) printf("\tACK"); if(flags&TH_URG) printf("\tURG"); if(flags&TH_ECE) printf("\tECE"); if(flags&TH_CWR) printf("\tCWR"); if(flags&TH_NS) printf("\tNS"); if(vivid) { printf("\n Src port: %u\n", ntohs(tcp->th_sport)); printf(" Dst port: %u\n", ntohs(tcp->th_dport)); printf(" Sequence: %u\n", ntohl(tcp->th_seq)); printf(" Ack: %u\n", ntohl(tcp->th_ack)); printf(" Header length: %u bytes\n", size_tcp); printf(" Flags: 0x%03x\n", (ntohs(tcp->th_hl_flags))&TH_FLAGS); printf(" Window size: %u\n",ntohs(tcp->th_win)); printf(" Checksum: 0x%04x\n", ntohs(tcp->th_sum)); printf(" Urgent pointer: %u\n", ntohs(tcp->th_urp)); } #endif packet += size_tcp; len -= size_tcp; //printf(" Application layer len: %d\n", len); if(len <= 0) { //printf("\n"); return; } if(80 == dport || 80 == sport) { //proto[HTTP_INDEX] ++; if(80 == dport) { /* * if the first few letters meet the following requirement, * it is a http packet. */ if(0 == strncmp(packet,"GET", 3) || 0 == strncmp(packet, "POST", 4) || 0 == strncmp(packet, "HEAD", 4) || 0 == strncmp(packet, "OPTION", 6) || 0 == strncmp(packet, "PUT", 3) || 0 == strncmp(packet, "DELETE", 6) || 0 == strncmp(packet, "TRACE", 5) || 0 == strncmp(packet, "CONNECT", 7)) { http_handler(packet, 1, len); // request packet } else { printf(" TCP SEGMENT DATA: %d bytes\n", len); } } else if (80 == sport) { if(0 == strncmp(packet, "HTTP", 4)) { http_handler(packet, 2, len); // response packet } else { printf(" TCP SEGMENT DATA: %d bytes\n", len); } } } else if(20 == dport || 20 == sport) { //proto[FTP_INDEX] ++; ftp_handler(packet, 2, len); } else if(21 == dport || 21 == sport) { //proto[FTP_INDEX] ++; ftp_handler(packet, 1, len); } else if(23 == dport || 23 == sport) { //proto[TELNET_INDEX] ++; telnet_handler(packet, len); } else if(502 == dport || 502 == sport) { //proto[MODBUS_INDEX] ++; modbus_handler(packet, len); } else { //proto[UNKNOWN_INDEX] ++; //printf("unknown protocol\n"); } return; }
main() { auto unsigned wKey; auto int i; /* init FORM searchable names - must init ALL FORMSpec structs! */ FORMSpec[0].name = "email_from"; FORMSpec[0].value = emailTemp.from; FORMSpec[0].len = MAX_FROM_LEN; FORMSpec[1].name = "email_subject"; FORMSpec[1].value = emailTemp.subject; FORMSpec[1].len = MAX_SUBJECT_LEN; FORMSpec[2].name = "email_body"; FORMSpec[2].value = emailTemp.body; FORMSpec[2].len = MAX_BODY_LEN; initsystem(); sock_init(); http_init(); tcp_reserveport(80); FlagInit(); CreateEmailList(); LogInit(); DispBufferInit(); DispNoEmail(); while (1) { http_handler(); costate { keyProcess(); //scans for keypress waitfor (DelayMs(10)); } costate { waitfor (wKey = keyGet()); //get key from buffer switch (wKey) { case DELETE: if (emailList.ptr != -1) { LogAddEmailEntry("deleted", email.from, email.subject); DeleteEmail(); } DispEmail(); break; case READ: if ((emailList.ptr != -1) && (emailIndex[emailList.ptr].read != 1)) { LogAddEmailEntry("read", email.from, email.subject); emailIndex[emailList.ptr].read = 1; FlagCheck(); } break; case EMAIL_UP: if (emailList.ptr != -1) { if (emailIndex[emailList.ptr].prev != -1) { emailList.ptr = emailIndex[emailList.ptr].prev; } DispEmail(); } break; case EMAIL_DOWN: if (emailList.ptr != -1) { if (emailIndex[emailList.ptr].next != -1) { emailList.ptr = emailIndex[emailList.ptr].next; } DispEmail(); } break; case SCROLL_UP: if ((emailList.ptr != -1) && (emailDispLine > 0)) { emailDispLine--; DispUpdateWindow(); } break; case SCROLL_DOWN: if ((emailList.ptr != -1) && ((emailDispLine + 4) < emailLastLine)) { emailDispLine++; DispUpdateWindow(); } break; default: // Do nothing break; } //end switch } //end costate } }
void main() { int channel; My_Socket_Type socket; My_InOuts_Type InOuts; char DispStrIn[100]; long IOoutcnt,InCnt; // initializing InOuts.rtime = REFRESH_RATE; brdInit(); digOutConfig(0); glInit(); glBlankScreen(); glSetContrast(24); glBackLight(1); glXFontInit ( &fi10x12,10,12,0x20,0x7E,Terminal9 ); glXFontInit ( &fi14x16,14,16,0x20,0x7E,Terminal12 ); keyInit(); IOoutcnt = InCnt = 0; xmemBtn = btnInit(20); for(channel=0;channel<DIGITAL_OUTPUTS;channel++) // setting digital outputs to low state InOuts.dout[channel] = LOW_HIGH[0]; memset(socket.buff,0x00,BUFF_SIZE); socket.nextstate = 0; sock_init(); http_init(); tcp_reserveport(80); while(1) { costate //TCP_HANDLES { My_Handler(&socket); http_handler(); } costate //IO_Ctrl { waitfor(socket.nextstate == 2 && DelayMs(InOuts.rtime)); My_IO_Ctrl(&InOuts); } costate //TCP_RX { // THIS IS WHERE WE RECEIVE INFORMATION FROM THE XML SOCKET waitfor(socket.rxbytes || DelayMs(15000) ); if (socket.rxbytes) { sprintf(DispStrIn,"Msg From Host\n%s",socket.buff); btnMsgBox(0,120,320,120,&fi14x16,DispStrIn,1,0); //printf("%sRcvd: %s\n",RED,socket.buff); socket.rxbytes = 0; My_XML_Parser(socket.buff,&InOuts); } else { btnClearRegion(0,120,320,120); } } costate //TCP_TX { // THIS IS WHERE WE SEND INFORMATION TO THE XML SOCKET waitfor(socket.nextstate == 2 && DelayMs(InOuts.rtime)); My_Load_Buffer(0,&socket,&InOuts); // FILLING SOCKET BUFFER WITH ANALOG INPUTS DATA socket.nextstate = 3; // SET STATEMACHINE TO THE SEND STATE // printf("%sSent: %s\n",RED,socket.buff); yield; My_Load_Buffer(1,&socket,&InOuts); // FILLING SOCKET BUFFER WITH DIGITAL INPUTS socket.nextstate = 3; // SET STATEMACHINE TO THE SEND STATE // printf("%sSent: %s\n",RED,socket.buff); yield; My_Load_Buffer(2,&socket,&InOuts); // FILLING SOCKET BUFFER WITH DIGITAL OUTPUT STATUS socket.nextstate = 3; // SET STATEMACHINE TO THE SEND STATE // printf("%sSent: %s",RED,socket.buff); // printf("\n\n"); } } }
SSPEC_MIMETABLE_END void main(void) { int user1; int user2; int user3; int user1_enabled; int user2_enabled; int user3_enabled; int page1; int ch; printf("Press '1', '2', or '3' to disable/enable the three users.\n"); printf("Press 'b', 'd', or 'n' to set the authentication to basic, digest, or none.\n\n"); /* * sock_init initializes the TCP/IP stack. * http_init initializes the web server. */ // Start network and wait for interface to come up (or error exit). sock_init_or_exit(1); http_init(); /* * HTTP_DIGEST_AUTH is the default authentication type when * digest authentication has been enabled, so this line is not * strictly necessary. The other possible values are * HTTP_BASIC_AUTH and HTTP_NO_AUTH. */ http_setauthentication(HTTP_DIGEST_AUTH); printf("Using digest authentication\n"); /* * The following lines add three users, a web page, and an image, and * associates the users with the web page. The userx_enabled * variables are used to keep track of which users are current * enabled. */ user1_enabled = 1; user2_enabled = 1; user3_enabled = 1; user1 = sauth_adduser("foo", "bar", SERVER_HTTP); user2 = sauth_adduser("foo2", "bar2", SERVER_HTTP); user3 = sauth_adduser("foo3", "bar3", SERVER_HTTP); page1 = sspec_addxmemfile("/", index_html, SERVER_HTTP); sspec_adduser(page1, user1); sspec_adduser(page1, user2); sspec_adduser(page1, user3); sspec_setrealm(page1, "Admin"); sspec_addxmemfile("rabbit1.gif", rabbit1_gif, SERVER_HTTP); /* * 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 (versus increasing HTTP_MAXSERVERS). */ tcp_reserveport(80); while (1) { /* * Watch for user keypresses */ if (kbhit()) { ch = getchar(); switch (ch) { case '1': /* * Handle the keypress for User 1 */ user1_enabled = !user1_enabled; if (user1_enabled) { /* * sspec_adduser() adds a user to a resource */ sspec_adduser(page1, user1); printf("User 1 enabled\n"); } else { /* * sspec_removeuser() removes a user from a resource */ sspec_removeuser(page1, user1); printf("User 1 disabled\n"); } break; case '2': user2_enabled = !user2_enabled; if (user2_enabled) { sspec_adduser(page1, user2); printf("User 2 enabled\n"); } else { sspec_removeuser(page1, user2); printf("User 2 disabled\n"); } break; case '3': user3_enabled = !user3_enabled; if (user3_enabled) { sspec_adduser(page1, user3); printf("User 3 enabled\n"); } else { sspec_removeuser(page1, user3); printf("User 3 disabled\n"); } break; case 'b': http_setauthentication(HTTP_BASIC_AUTH); printf("Using basic authentication\n"); break; case 'd': http_setauthentication(HTTP_DIGEST_AUTH); printf("Using digest authentication\n"); break; case 'n': http_setauthentication(HTTP_NO_AUTH); printf("Using no authentication\n"); break; } } /* * http_handler needs to be called to handle the active http servers */ http_handler(); } }
void main(void) { auto int wKey; char buffer[20]; auto int i,j; brdInit(); initLcdKeypad(); // Initialize the #web-registered variables strcpy(passwords[0].entrypw, "12340"); strcpy(passwords[0].entryname, "JGunchy"); strcpy(passwords[0].entrytime, "no activity"); strcpy(passwords[0].exittime, "no activity"); for (i=1; i<MAX_ENTRIES; i++) { strcpy(passwords[i].entrypw, "Unused"); strcpy(passwords[i].entryname, "Unused"); strcpy(passwords[i].entrytime, "no activity"); strcpy(passwords[i].exittime, "no activity"); } updateentry(); //initialize temporary variables j= 10; i = 0; // Initialize the TCP/IP stack, HTTP server sock_init(); http_init(); while (1) { // Drive the HTTP server http_handler(); costate { keyProcess(); wKey = keyGet(); } costate { switch (wKey) { case 0: break; case '+': //entry case '-': //exit buffer[i]='\0'; TextGotoXY(&wholewindow, 0, 1); if (confirmentry(buffer, wKey)) { TextPrintf(&wholewindow, "Accepted"); TextGotoXY(&wholewindow, 0, 3); TextPrintf(&wholewindow, "Thank you %s", buffer); } else { TextPrintf(&wholewindow, "Incorrect password"); } i=0; j=10; waitfor(DelaySec(3)); glBlankScreen(); TextGotoXY(&wholewindow, 0, 0); TextPrintf(&wholewindow, "Password"); break; default: if (i<7) { buffer[i] = wKey; TextGotoXY(&wholewindow, j, 0); //TextPrintf(&wholewindow, "%c", wKey); TextPrintf(&wholewindow, "%c", '*'); j++; i++; } break; }//end switch }//end costate switch } }