/* * Embedded HTTP Server Dynamic Content/Handler User Entries * * ./software/ch7/emhttps/user.c * * mtj@cogitollc.com * */ #include #include "dyncntnt.h" static char dataline[80]; /*---------------------------------------------------------------------------- * myvarfunc() - Our function to emit dynamic content for "myvar". *--------------------------------------------------------------------------*/ char *myvarfunc() { static int myvar = 0; myvar++; sprintf(dataline, "%d", myvar); return(dataline); } /*---------------------------------------------------------------------------- * devstatefunc() - Our function to emit dynamic content for "devstate". *--------------------------------------------------------------------------*/ char *devstateFunc() { /* Dummy return... */ return( "on" ); } /*---------------------------------------------------------------------------- * devtempfunc() - Our function to emit dynamic content for "devtemp". *--------------------------------------------------------------------------*/ char *devtempFunc() { /* Dummy return... */ return( "25C" ); } /*---------------------------------------------------------------------------- * devaccessFunc() - Our function to emit dynamic content for "devaccess". *--------------------------------------------------------------------------*/ char *devaccessFunc() { static int accesses = 0; accesses++; sprintf(dataline, "%d", accesses); return(dataline); } /*---------------------------------------------------------------------------- * myHandler() - Our function to handle form posting for "/control". *--------------------------------------------------------------------------*/ void myHandler( char *content ) { char value[80]; printf("\nmyHandler called!!!\n"); if (parseVariable(content, "Test1", value) == 0) { printf("Test1 is %s\n", value); } else { printf("Test1 not found\n"); } if (parseVariable(content, "Test2", value) == 0) { printf("Test2 is %s\n", value); } else { printf("Test2 not found\n"); } if (parseVariable(content, "Test3", value) == 0) { printf("Test3 is %s\n", value); } else { printf("Test3 not found\n"); } } /*---------------------------------------------------------------------------- * userInit() - Add our entry to the dynamic content module. *--------------------------------------------------------------------------*/ void userInit() { addDynamicContent("myvar", &myvarfunc); addDynamicContent("devstate", &devstateFunc); addDynamicContent("devtemp", &devtempFunc); addDynamicContent("devaccess", &devaccessFunc); addDynamicHandler("/control", &myHandler); } /* * Copyright (c) 2002 Charles River Media. All rights reserved. * * Redistribution and use in source and binary forms, with or * without modification, is hereby granted without fee provided * that the following conditions are met: * * 1. Redistributions of source code must retain the above * copyright notice, this list of conditions and the * following disclaimer. * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * 3. Neither the name of Charles River Media nor the names of * its contributors may be used to endorse or promote products * derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED BY CHARLES RIVER MEDIA AND CONTRIBUTERS * 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CHARLES * RIVER MEDIA OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARAY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */