//***************************************************************************** // // Searches the list of parameters passed to a CGI handler for a parameter // with the given name and, if found, reads the parameter value as a decimal // number. // // \param pcName is a pointer to a string containing the name of the // parameter that is to be found. // \param pcParam is an array of character pointers, each containing the name // of a single parameter as encoded in the URI requesting the CGI. // \param iNumParams is the number of elements in the pcParam array. // \param pcValues is an array of values associated with each parameter from // the pcParam array. // \param pbError is a pointer that will be written to \b true if there is any // error during the parameter parsing process (parameter not found, value is // not a valid decimal number). // // This function searches an array of parameters to find the string passed in // \e pcName. If the string is found, the corresponding parameter value is // read from array pcValues and checked to make sure that it is a valid // decimal number. If so, the number is returned. If any error is detected, // parameter \e pbError is written to \b true. Note that \e pbError is NOT // written if the parameter is successfully found and validated. This is to // allow multiple parameters to be parsed without the caller needing to check // return codes after each individual call. // // \return Returns the value of the parameter or 0 if an error is detected (in // which case \e *pbError will be \b true). // //***************************************************************************** long GetCGIParam(const char *pcName, char *pcParams[], char *pcValue[], int iNumParams, tBoolean *pbError) { int iParam; long lValue; tBoolean bRetcode; // // Is the parameter we are looking for in the list? // iParam = FindCGIParameter(pcName, pcParams, iNumParams); if(iParam != -1) { // // We found the parameter so now get its value. // bRetcode = CheckDecimalParam(pcValue[iParam], &lValue); if(bRetcode) { // // All is well - return the parameter value. // return(lValue); } } // // If we reach here, there was a problem so return 0 and set the error // flag. // *pbError = true; return(0); }
/** * * This CGI handler is called whenever the web browser requests set.cgi. * This CGI parses the GET Parameters and sets the values * */ static char * SetCGIHandler(int iIndex, int iNumParams, char *pcParam[], char *pcValue[]) { int i; long value = 0, r_value, decimal_place = 0, hour = 0, minute = 0; char *name, save = 0, error = 0, *str_value = NULL, *str_decimal_place = NULL; #if DEBUG_CGI printf("SetCGIHandler: new set.cgi request with %d Params\n", iNumParams); #endif /* // TODO MEMORY HANDLING if (paramsSet != NULL && valuesSet != NULL) { for (i = 0; i <= paramValueLen; i++) { vPortFree(*(valuesSet + i)); vPortFree(*(paramsSet + i)); } / vPortFree(**(paramsSet)); #if DEBUG_SSI printf("io_print_saved_params: freed paramsSet \n"); #endif vPortFree(**(valuesSet)); #if DEBUG_SSI printf("io_print_saved_params: freed valuesSet \n"); #endif } else { // TODO statische allokkierung dynamisch machen paramsSet = pvPortMalloc(sizeof(char **) * 10); valuesSet = pvPortMalloc(sizeof(char **) * 10); paramValueLen = -1; } */ //test if set was success full if (iNumParams > 0) { for (i = 0; i < iNumParams; i++) { name = pcParam[i]; if (strcmp(name, "uid") == 0 || strcmp(name, "ajax") == 0) { // ignore params ajax and uid ; } else { xCom_msg.cmd = SET; xCom_msg.dataSouce = DATA; xCom_msg.from = xHttpdQueue; xCom_msg.taskToResume = xLwipTaskHandle; xCom_msg.freeItem = pdFALSE; xCom_msg.item = name; /* check for checkbox value */ if (strcmp(pcValue[i], "on") == 0) { #if DEBUG_CGI printf("SetCGIHandler: Found Checkbox %s\n", name); #endif xCom_msg.value = 1; save = 1; } else /*------ check for float value ----------------------*/ if (name[0] == 'f' && name[1] == '_') { // Found float value str_value = strtok(pcValue[i], "."); str_decimal_place = strtok(NULL, "."); if ((CheckDecimalParam((const char*) str_decimal_place, &decimal_place) == pdTRUE) && (CheckDecimalParam( (const char*) str_value, &value) == pdTRUE)) { name += 2; //remove 'f_' value = value * 10 + decimal_place; xCom_msg.value = value; // zehntelschritte xCom_msg.item = name; save = 1; #if DEBUG_CGI printf( "SetCGIHandler: Found VALID float param: %s=%d.%d \n", name + 2, (int) value, (int) decimal_place); #endif } else { #if DEBUG_CGI printf( "SetCGIHandler: Found INVALID float param: %s=%s \n", name + 2, pcValue[i]); #endif save = 0; return "/set_nok.htm"; } } else /*----- check for time value ----------*/ if (pcParam[i][0] == 't' && pcParam[i][1] == '_') { if (CheckDecimalParam((const char*) pcValue[i], &hour) == pdTRUE) { #if DEBUG_CGI printf( "SetCGIHandler: Found first VALID time param - hour: %s=%d \n", pcParam[i] + 2, (int) hour); #endif //go to the next param , look for the minutes i++; if (i < iNumParams) { if (pcParam[i][0] == 't' && pcParam[i][1] == '_') { if (CheckDecimalParam((const char*) pcValue[i], &minute) == pdTRUE) { #if DEBUG_CGI printf( "SetCGIHandler: Found second VALID time param - minute: %s=%d \n", pcParam[i] + 2, (int) minute); #endif name += 2; //remove t_ xCom_msg.item = name; value = hour * 60 + minute; xCom_msg.value = value; save = 1; hour = 0; minute = 0; } else { printf( "SetCGIHandler: Found second INVALID time param: %s=%s \n", pcParam[i] + 2, pcValue[i]); return "/set_nok.htm"; } } else { #if DEBUG_CGI printf( "SetCGIHandler: Found first INVALID time param: %s=%s \n", pcParam[i] + 2, pcValue[i]); #endif return "/set_nok.htm"; } } } } else /*------ check for standard integer value ---------*/ if (CheckDecimalParam((const char*) pcValue[i], &value) == pdTRUE) { #if DEBUG_CGI printf("SetCGIHandler: Found integer param: %s=%d \n", name, (int) value); #endif xCom_msg.value = value; save = 1; } /*---------- no valid param found ! -> ERROR --------*/ else { #if DEBUG_CGI printf("SetCGIHandler: ERROR invalid param %s=%s \n", name, pcValue[i]); #endif } if (save == 1) { // send value to comTask save = 0; xQueueSend(xComQueue, &xCom_msg, (portTickType) 0); /* Add params to global fields for ssi tag SavedParams */ /* if (paramsSet != NULL && valuesSet != NULL && i < 10) { *(paramsSet + i) = pvPortMalloc(strlen(name) + 1); *(valuesSet + i) = pvPortMalloc(strlen(pcValue[i]) + 1); if (*(paramsSet + i) != NULL && *(valuesSet + i) != NULL) { strcpy(*(paramsSet + i), name); strcpy(*(valuesSet + i), pcValue[i]); #if DEBUG_CGI printf("SetCGIHandler: added %s=%s to param/valueSet \n", *(paramsSet+i), *(valuesSet+i)); #endif } */ paramValueLen = i; // gesetzten parameter reuecklesen, zur ueberpruefung ob ok r_value = io_get_value_from_comtask(name); if (r_value != value) { printf( "SetCGIHandler: error rereading the value with id '%s'\n", name); return "/set_nok.htm"; } } } } if (FindCGIParameter("ajax", pcParam, iNumParams) == -1) return "/set_ok.ssi"; else return "/set_oka.ssi"; } else { error = 1; } if (FindCGIParameter("ajax", pcParam, iNumParams) == -1) return "/set_ok.ssi"; else return "/set_oka.ssi"; }