httpd-cgi.c

Go to the documentation of this file.
00001 
00014 /*
00015  * Copyright (c) 2001-2006, Adam Dunkels.
00016  * All rights reserved.
00017  *
00018  * Redistribution and use in source and binary forms, with or without
00019  * modification, are permitted provided that the following conditions
00020  * are met:
00021  * 1. Redistributions of source code must retain the above copyright
00022  *    notice, this list of conditions and the following disclaimer.
00023  * 2. Redistributions in binary form must reproduce the above copyright
00024  *    notice, this list of conditions and the following disclaimer in the
00025  *    documentation and/or other materials provided with the distribution.
00026  * 3. The name of the author may not be used to endorse or promote
00027  *    products derived from this software without specific prior
00028  *    written permission.
00029  *
00030  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
00031  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00032  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00033  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
00034  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00035  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00036  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00037  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00038  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00039  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00040  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00041  *
00042  * This file is part of the uIP TCP/IP stack.
00043  *
00044  * $Id: httpd-cgi.c,v 1.2 2006/06/11 21:46:37 adam Exp $
00045  *
00046  */
00047 
00048 #include "uip.h"
00049 #include "psock.h"
00050 #include "httpd.h"
00051 #include "httpd-cgi.h"
00052 #include "httpd-fs.h"
00053 #include "http_func.h"
00054 
00055 #include "../mprintf/mprintf.h"
00056 #include <string.h>
00057 #include <stdio.h>
00058 
00059 HTTPD_CGI_CALL(temp, "tag-temp", cgitemperature );
00060 
00061 //HTTPD_CGI_CALL(setp, "tag-setpoint", cgisetpoint );
00062 //HTTPD_CGI_CALL(estad, "tag-estado", cgiestado );
00063 
00064 
00065 static const struct httpd_cgi_call *calls[] = { &temp, NULL };
00066 
00067 /*---------------------------------------------------------------------------*/
00068 static
00069 PT_THREAD(nullfunction(struct httpd_state *s, char *ptr))
00070 {
00071   PSOCK_BEGIN(&s->sout);
00072   PSOCK_END(&s->sout);
00073 }
00074 /*---------------------------------------------------------------------------*/
00075 httpd_cgifunction
00076 httpd_cgi(char *name)
00077 {
00078   const struct httpd_cgi_call **f;
00079 
00080   /* Find the matching name in the table, return the function. */
00081   for(f = calls; *f != NULL; ++f) {
00082     if(strncmp((*f)->name, name, strlen((*f)->name)) == 0) {
00083       return (*f)->function;
00084     }
00085   }
00086   return nullfunction;
00087 }
00088 extern unsigned char temp0, temp1, setpoint, ac_auto_on, ac_modo;
00089 
00090 static unsigned short cgi_gettemp( void *arg )
00091 {
00092         sprintf( uip_appdata, "%3d,%02d", (int)temp1, (int)temp0);
00093 
00094         return strlen( uip_appdata );
00095 }
00096 
00097 static PT_THREAD(cgitemperature(struct httpd_state *s, char *ptr))
00098 {
00099   PSOCK_BEGIN(&s->sout);
00100   PSOCK_GENERATOR_SEND(&s->sout, cgi_gettemp, NULL);
00101   PSOCK_END(&s->sout);
00102 }
00103 
00104 
00105 void cgiProcessFormInput( char *pcInputString, int xInputLength )
00106 {
00107 char *c, *d, *e, *pcText;
00108 char tac_modo, tsetpoint;
00109 char deb[100];
00110 
00111         DEBUG_ENTER;
00112         c = strstr( pcInputString, "?" );       //s
00113         sprintf(deb, "%s\n", c);
00114         DEBUG_HTTP(deb);
00115     if( c )
00116     {
00117         printf("\n\n");
00118         *c = 0x00; //terminate at the filename
00119         c++;
00120         e = strstr( c, " " );
00121         if( e != NULL )
00122         {
00123             *e = 0x00; //terminate the whole string
00124         }
00125         d = strstr( c, "slcd=");
00126         if (d) {
00127                         c=d;
00128                         c += strlen("slcd=");
00129                         d = strchr( c, '&');
00130                         *d = '\0';
00131                         http_set_lcd(c);
00132                         printf("--[%s]--",c);
00133                         c=d+1;
00134         }
00135 
00136         d = strstr( c, "shr=");
00137         if(d) {
00138                         c=d;
00139                         c += strlen("shr=");
00140                         d = strchr( c, '&');
00141                         *d = '\0';
00142                         http_set_hour(c);
00143                         //printf("--[%s]--",c);
00144                         c=d+1;
00145         }
00146 
00147         d = strstr( c, "smin=");
00148                 if(d) {
00149                         c=d;
00150                         c += strlen("smin=");
00151                         d = strchr( c, '&');
00152                         *d = '\0';
00153                         http_set_min(c);
00154                         //printf("--[%s]--",c);
00155                         c=d+1;
00156                 }
00157 
00158                 d = strstr( c, "ssec=");
00159                 if(d) {
00160                         c=d;
00161                         c += strlen("ssec=");
00162                         http_set_sec(c);
00163                         //printf("--[%s]--",c);
00164                 }
00165     }
00166     show_lcd_time();
00167     DEBUG_EXIT;
00168 }
00169