map<string,string> frameParserFunc(cma_frame_legacy& frm)
{
	map<string,string> ret;

	char sensorId[2];

    const uint8_t* data = const_cast<cma_frame_legacy*>(&frm)->getPduData();
    memcpy(sensorId, data, 2);
    
    uint32_t timestamp = makelong(makeword(data[2], data[3]),
        makeword(data[4], data[5]));

    uint16_t windage_yaw_angle = makeword(data[6], data[7]);
    uint16_t deflection_angle = makeword(data[8], data[9]);
    uint16_t line_temperature1 = makeword(data[10], data[11]);
    uint16_t line_temperature2 = makeword(data[12], data[13]);
    uint16_t battery_voltage = makeword(data[14], data[15]);
    uint16_t operation_temperature = makeword(data[16], data[17]);
    uint16_t reserve1 = makeword(data[18], data[19]);
    uint16_t reserve2 = makeword(data[20], data[21]);

    try
    {
        uint64_t ms = timestamp;
        ms *= 1000;
        ms *= 1000;

        Timestamp ts(ms);

        string sTimestamp = ts.toFormattedStringDash();
        string sWindage_yaw_angle = boost::lexical_cast<string>(deflection_angle);
        string sDeflection_angle = boost::lexical_cast<string>(deflection_angle);
        string sLine_temperature1 = boost::lexical_cast<string>(line_temperature1);
        string sLine_temperature2 = boost::lexical_cast<string>(line_temperature2);
        string sBattery_voltage = boost::lexical_cast<string>(battery_voltage);
        string sOperation_temperature = boost::lexical_cast<string>(operation_temperature);
        string sReserve1 = boost::lexical_cast<string>(reserve1);
        string sReserve2 = boost::lexical_cast<string>(reserve2);

        ret.insert(make_pair<string,string>("Time_Stamp", sTimestamp));
        ret.insert(make_pair<string,string>("Windage_Yaw_Angle", sWindage_yaw_angle));
        ret.insert(make_pair<string,string>("Deflection_Angle", sDeflection_angle));
        ret.insert(make_pair<string,string>("Line_Temperature1", sLine_temperature1));
        ret.insert(make_pair<string,string>("Line_Temperature2", sLine_temperature2));
        ret.insert(make_pair<string,string>("Battery_Voltage", sBattery_voltage));
        ret.insert(make_pair<string,string>("Operation_Temperature", sOperation_temperature));
        ret.insert(make_pair<string,string>("Reserve1", sReserve1));
        ret.insert(make_pair<string,string>("Reserve2", sReserve2));

    }
    catch (boost::bad_lexical_cast& e)
    {
        return ret;
    }

	return ret;
}
Exemple #2
0
listtable* parseQueries(listtable* tbl, const char* query, char equalchar, char sepchar, int* count) {

	if (tbl == NULL && (tbl = listTable(0)) == NULL) {
		return NULL;
	}

	if (query == NULL) {
		return tbl;
	}

	int cnt			= 0;
	char* newquery	= strdup(query);

	while (newquery && *newquery) {

		char* value	= makeword(newquery, sepchar);
		char* name	= strTrim(makeword(value, equalchar));

		urlDecode(name);
		urlDecode(value);

		if (tbl->putstr(tbl, name, value) == true) {
			cnt++;
		}

		free(name);
		free(value);
	}

	if (count != NULL) {
		*count = cnt;
	}

	free(newquery);

	return tbl;
}
Exemple #3
0
main(int argc, char *argv[]) {
    entry entries[MAX_ENTRIES];
    register int x,m=0;
    int cl;

    printf("Content-type: text/html%c%c",10,10);

    if(strcmp(getenv("REQUEST_METHOD"),"POST")) {
        printf("This script should be referenced with a METHOD of POST.\n");
        printf("If you don't understand this, see this ");
        printf("<A HREF=\"http://www.ncsa.uiuc.edu/SDG/Software/Mosaic/Docs/fill-out-forms/overview.html\">forms overview</A>.%c",10);
        exit(1);
    }
    if(strcmp(getenv("CONTENT_TYPE"),"application/x-www-form-urlencoded")) {
        printf("This script can only be used to decode form results. \n");
        exit(1);
    }
    cl = atoi(getenv("CONTENT_LENGTH"));

    for(x=0;cl && (!feof(stdin));x++) {
        m=x;
        entries[x].val = fmakeword(stdin,'&',&cl);
        plustospace(entries[x].val);
        unescape_url(entries[x].val);
        entries[x].name = makeword(entries[x].val,'=');
    }

    printf("<H1>Query Results</H1>");
    printf("You submitted the following name/value pairs:<p>%c",10);
    printf("<ul>%c",10);

    for(x=0; x <= m; x++)
        printf("<li> <code>%s : %s</code>%c",entries[x].name,
               entries[x].val,10);
    printf("</ul>%c",10);
}
Exemple #4
0
int getEntries( inStruct Sentries ) {
    register int x;
    char *stquery, *tmpq, *tmpStr, *tmpStr1, *tmpPtr;
    char reqMethod[100];
    int msgLength;
    char contentType[100];
    char boundary[MAX_TOKEN];
    int i;


    putenv( "HOME=/" );


    if ( getenv( "CONTENT_TYPE" ) != NULL ) {
        strcpy( contentType, getenv( "CONTENT_TYPE" ) );
    }
    else {
        strcpy( contentType, "" );
    }
    if ( getenv( "REQUEST_METHOD" ) != NULL ) {
        strcpy( reqMethod, getenv( "REQUEST_METHOD" ) );
    }
    else {
        strcpy( reqMethod, "" );
    }
    if ( getenv( "HTTP_COOKIE" ) != NULL ) {
        strcpy( Sentries->cookieStr, getenv( "HTTP_COOKIE" ) );
    }

    else {
        strcpy( Sentries->cookieStr, "" );
    }
    if ( strstr( Sentries->cookieStr, "*" ) != NULL ||
            strstr( Sentries->cookieStr, ".." ) != NULL ||
            strstr( Sentries->cookieStr, "?" ) != NULL ||
            strstr( Sentries->cookieStr, "/" ) != NULL ||
            strstr( Sentries->cookieStr, "\\" ) != NULL ) {

        Sentries->op = -1;
        return 1;


    }


    if ( !strcmp( reqMethod, "POST" ) || !strcmp( reqMethod, "post" ) ) {
        msgLength = atoi( getenv( "CONTENT_LENGTH" ) ) + 10;
        stquery =  malloc( msgLength );
        if ( fread( stquery, 1, msgLength, stdin ) != ( msgLength - 10 ) ) {
            webErrorExit( "short fread", 0 );
        }
        stquery[msgLength] = '\0';
    }
    else {
        stquery =  malloc( QSIZE );
        if ( getenv( "QUERY_STRING" ) != NULL ) {
            strcpy( stquery, getenv( "QUERY_STRING" ) );
        }
        else {
            strcpy( stquery, "" );
        }
    }

    if ( strstr( contentType, "multipart/form-data" ) != NULL ) {

        i = msgLength - 10;
        getBoundary( &stquery, boundary );
        /***     printf("Boundary:**%s**<BR>\n",boundary);fflush(stdout); ***/
        for ( x = 0;  *stquery != '\0'; x++ ) {
            if ( x == MAX_ENTRIES ) {
                webErrorExit( "MaxEntries Exceeded", x );
            }
            Sentries->m = x;
            /***     printf("GettingX:%i....\n",x);fflush(stdout); ***/
            tmpPtr = stquery;
            if ( getmultipartword( &Sentries->entries[x], &stquery, boundary, i ) != 0 ) {
                break;
            }
            i -= stquery - tmpPtr;
            /***     printf("%i:%s=%s<BR>\n",entries[x].size,entries[x].name,entries[x].val);fflush(stdout);***/
        }
        Sentries->m--;
    }
    else {

        /**  the following is to take care of the
         home col. name bad length pb Linux on RedHat7  *******/
        fixstr1 = malloc( 10 );
        free( fixstr1 );
        /******************************************************/

        for ( x = 0;  stquery[0] != '\0'; x++ ) {
            if ( x == MAX_ENTRIES ) {
                webErrorExit( "MaxEntries Exceeded", x );
            }
            Sentries->m = x;
            Sentries->entries[x].val =  malloc( HUGE_STRING );
            getword( Sentries->entries[x].val, stquery, '&' );
            plustospace( Sentries->entries[x].val );
            unescape_url( Sentries->entries[x].val );
            char* wd = ( char * ) makeword( Sentries->entries[x].val, '=' ); // JMC cppcheck - leak
            sprintf( Sentries->entries[x].name, wd );
            free( wd ); // JMC cppcheck - leak
        }
    }

    return 0;

}
Exemple #5
0
int __fastcall UnzOpr::getZip64Data(const DZRawData& extra)
// uch *ef_buf, unsigned ef_len)
{
	unsigned eb_id;
	unsigned eb_len;

	/* ---------------------------------------------------------------------------
	This function scans the extra field for zip64 information, ie 8-byte
	versions of compressed file size, uncompressed file size, relative offset
	and a 4-byte version of disk start number.
	Sets both local header and central header fields.  Not terribly clever,
	but it means that this procedure is only called in one place.
	--------------------------------------------------------------------------- */

	if (!extra)
		return PK_COOL;

	const uch* ef_buf = extra.begin();
	unsigned ef_len = extra.Length();

	// TTrace((stderr,"\ngetZip64Data: scanning extra field of length %u\n", ef_len));

	while (ef_len >= EB_HEADSIZE)
	{
		eb_id = makeword(EB_ID + ef_buf);
		eb_len = makeword(EB_LEN + ef_buf);

		if (eb_len > (ef_len - EB_HEADSIZE))
		{
			/* discovered some extra field inconsistency! */
			if (Verbose) // < 0)
				Notify(ITRACE, _T(
					"Invalid extra data: block length %u > rest of block %u"),
				eb_len, ef_len - EB_HEADSIZE);
			break;
		}
		if (eb_id == ZIP64_XDATA_TAG)
		{

			int offset = EB_HEADSIZE;

			if (fcrec.ucsize == MAX_UNSIGNED || flrec.ucsize == MAX_UNSIGNED)
			{
				flrec.ucsize = fcrec.ucsize = makeint64(offset + ef_buf);
				offset += sizeof(fcrec.ucsize);
			}
			if (fcrec.csize == MAX_UNSIGNED || flrec.csize == MAX_UNSIGNED)
			{
				fcsize = flrec.csize = fcrec.csize = makeint64(offset + ef_buf);
				offset += sizeof(fcrec.csize);
			}
			if (fcrec.relative_offset_local_header == MAX_UNSIGNED)
			{
				fcrec.relative_offset_local_header = makeint64(offset + ef_buf);
				offset += sizeof(fcrec.relative_offset_local_header);
			}
			if (fcrec.disk_number_start == MAX_WORD)
			{
				fcrec.disk_number_start = makelong(offset + ef_buf);
				// offset += sizeof(fcrec.disk_number_start);
			}
		}

		/* Skip this extra field block */
		ef_buf += (eb_len + EB_HEADSIZE);
		ef_len -= (eb_len + EB_HEADSIZE);
	}

	return PK_COOL;
} /* end function getZip64Data() */
Exemple #6
0
/* ===========================================================================
 *                    Function find_ecrec()
 */
int UnzOpr::find_ecrec(ZInt64 searchlen)
{
	/* return PK-class error */
	int // i, numblks,
	found = false;
	int result;
	// /*long*/ZInt64 tail_len;
	ec_byte_rec byterec;

	if (Verbose < 0)
		Notify(ITRACE, _T("in find_ecrec (end of central dir)"));

	/* ---------------------------------------------------------------------------
	 *    Treat case of short zipfile separately.
	 *-------------------------------------------------------------------------- */
	if (fziplen <= INBUFSIZ)
	{
		fUnzInfile->SetPosition(0L, SEEK_SET);
		if ((fincnt = vclRead((char*)finbuf, (unsigned int)fziplen)) == (int)
			fziplen)
		/* 'P' must be at least 22 bytes from end of zipfile */
			for (finptr = finbuf + (int)fziplen - 22; finptr >= finbuf;
				--finptr)
				if (*(ulg*)finptr == EndCentralDirSig)
				// if ((native(* finptr) == 'P') && !strncmp((char *) finptr, fend_central_sig, 4))
				{
					fincnt -= (int)(finptr - finbuf);
					found = true;
					break;
				}

		/* ---------------------------------------------------------------------------
		 *  Zipfile is longer than INBUFSIZ:  may need to loop.  Start with short
		 *  block at end of zipfile (if not TOO short).
		 *--------------------------------------------------------------------------- */
	}
	else
	{
		found = rec_find(searchlen, EndCentralDirSig /* fend_central_sig */ ,
			ECREC_SIZE) == 0;
	}
	/* end if (ziplen > INBUFSIZ) */

	/* ---------------------------------------------------------------------------
	 * Searched through whole region where signature should be without finding
	 * it.  Print informational message and die a horrible death.
	 *--------------------------------------------------------------------------- */
	// fail:
	if (!found)
	{
		// UnzErr(UEN_EOF01);
		DZError(DZ_ERM_NO_CENTRAL);
		return PK_ERR;
		/* failed */
	}

	/* ---------------------------------------------------------------------------
	 * Found the signature, so get the end-central data before returning.  Do
	 * any necessary machine-type conversions (byte ordering, structure padding
	 * compensation) by reading data into character array and copying to struct.
	 *--------------------------------------------------------------------------- */
	freal_ecrec_offset = fcur_zipfile_bufstart + (finptr - finbuf);

	if (Verbose < 0)
	{
		Notify(ITRACE, _T(
				"Found end-of-central-dir signature at offset %Ld (%.8LXh)"),
			freal_ecrec_offset, freal_ecrec_offset);
		Notify(ITRACE, _T(
				"    from beginning of file; offset %d (%.4Xh) within block"),
			finptr - finbuf, finptr - finbuf);
	}

	if (readbuf((char*)byterec, ECREC_SIZE + 4) == 0)
		return PK_EOF;
	fecrec.number_this_disk = makeword(&byterec[NUMBER_THIS_DISK]);
	fecrec.num_disk_start_cdir = makeword
		(&byterec[NUM_DISK_WITH_START_CENTRAL_DIR]);
	fecrec.num_entries_centrl_dir_ths_disk = makeword
		(&byterec[NUM_ENTRIES_CENTRL_DIR_THS_DISK]);
	fecrec.total_entries_central_dir = makeword
		(&byterec[TOTAL_ENTRIES_CENTRAL_DIR]);
	fecrec.size_central_directory = makelong(&byterec[SIZE_CENTRAL_DIRECTORY]);
	fecrec.offset_start_central_directory = makelong
		(&byterec[OFFSET_START_CENTRAL_DIRECTORY]);
	fecrec.zipfile_comment_length = makeword(&byterec[ZIPFILE_COMMENT_LENGTH]);

	if (check_ecrec_zip64())
	{
		result = find_ecrec64(searchlen + 76);
		/* 76 bytes for zip64ec & zip64 locator */
		if (result != PK_COOL)
			return result;
	}

	fexpect_ecrec_offset = fecrec.offset_start_central_directory +
		fecrec.size_central_directory;
	return PK_COOL;
}
Exemple #7
0
int loadParams(cgiRequestObj *request,
               char* (*getenv2)(const char*, void* thread_context),
               char *raw_post_data,
               ms_uint32 raw_post_data_length,
               void* thread_context)
{
  register int x,m=0;
  char *s, *queryString = NULL, *httpCookie = NULL;
  int debuglevel;
  int maxParams = MS_DEFAULT_CGI_PARAMS;

  if (getenv2==NULL)
    getenv2 = &msGetEnv;

  if(getenv2("REQUEST_METHOD", thread_context)==NULL) {
    msIO_printf("This script can only be used to decode form results and \n");
    msIO_printf("should be initiated as a CGI process via a httpd server.\n");
    return -1;
  }

  debuglevel = (int)msGetGlobalDebugLevel();

  if(strcmp(getenv2("REQUEST_METHOD", thread_context),"POST") == 0) { /* we've got a post from a form */
    char *post_data;
    int data_len;
    request->type = MS_POST_REQUEST;

    s = getenv2("CONTENT_TYPE", thread_context);
    if (s != NULL)
      request->contenttype = msStrdup(s);
    /* we've to set default Content-Type which is
     * application/octet-stream according to
     * W3 RFC 2626 section 7.2.1 */
    else request->contenttype = msStrdup("application/octet-stream");

    if (raw_post_data) {
      post_data = msStrdup(raw_post_data);
      data_len = raw_post_data_length;
    } else {
      if(MS_SUCCESS != readPostBody( request, &post_data ))
        return -1;
      data_len = strlen(post_data);
    }

    /* if the content_type is application/x-www-form-urlencoded,
       we have to parse it like the QUERY_STRING variable */
    if(strncmp(request->contenttype, "application/x-www-form-urlencoded", strlen("application/x-www-form-urlencoded")) == 0) {
      while( data_len > 0 && isspace(post_data[data_len-1]) )
        post_data[--data_len] = '\0';

      while( post_data[0] ) {
        if(m >= maxParams) {
          maxParams *= 2;
          request->ParamNames = (char **) msSmallRealloc(request->ParamNames,sizeof(char *) * maxParams);
          request->ParamValues = (char **) msSmallRealloc(request->ParamValues,sizeof(char *) * maxParams);
        }
        request->ParamValues[m] = makeword(post_data,'&');
        plustospace(request->ParamValues[m]);
        unescape_url(request->ParamValues[m]);
        request->ParamNames[m] = makeword(request->ParamValues[m],'=');
        m++;
      }
      free( post_data );
    } else
      request->postrequest = post_data;

    /* check the QUERY_STRING even in the post request since it can contain
       information. Eg a wfs request with  */
    s = getenv2("QUERY_STRING", thread_context);
    if(s) {
      if (debuglevel >= MS_DEBUGLEVEL_DEBUG)
        msDebug("loadParams() QUERY_STRING: %s\n", s);

      queryString = msStrdup(s);
      for(x=0; queryString[0] != '\0'; x++) {
        if(m >= maxParams) {
          maxParams *= 2;
          request->ParamNames = (char **) msSmallRealloc(request->ParamNames,sizeof(char *) * maxParams);
          request->ParamValues = (char **) msSmallRealloc(request->ParamValues,sizeof(char *) * maxParams);
        }
        request->ParamValues[m] = makeword(queryString,'&');
        plustospace(request->ParamValues[m]);
        unescape_url(request->ParamValues[m]);
        request->ParamNames[m] = makeword(request->ParamValues[m],'=');
        m++;
      }
    }
  } else {
    if(strcmp(getenv2("REQUEST_METHOD", thread_context),"GET") == 0) { /* we've got a get request */
      request->type = MS_GET_REQUEST;

      s = getenv2("QUERY_STRING", thread_context);
      if(s == NULL) {
        msIO_setHeader("Content-Type","text/html");
        msIO_sendHeaders();
        msIO_printf("No query information to decode. QUERY_STRING not set.\n");
        return -1;
      }

      if (debuglevel >= MS_DEBUGLEVEL_DEBUG)
        msDebug("loadParams() QUERY_STRING: %s\n", s);

      if(strlen(s)==0) {
        msIO_setHeader("Content-Type","text/html");
        msIO_sendHeaders();
        msIO_printf("No query information to decode. QUERY_STRING is set, but empty.\n");
        return -1;
      }

      /* don't modify the string returned by getenv2 */
      queryString = msStrdup(s);
      for(x=0; queryString[0] != '\0'; x++) {
        if(m >= maxParams) {
          maxParams *= 2;
          request->ParamNames = (char **) msSmallRealloc(request->ParamNames,sizeof(char *) * maxParams);
          request->ParamValues = (char **) msSmallRealloc(request->ParamValues,sizeof(char *) * maxParams);
        }
        request->ParamValues[m] = makeword(queryString,'&');
        plustospace(request->ParamValues[m]);
        unescape_url(request->ParamValues[m]);
        request->ParamNames[m] = makeword(request->ParamValues[m],'=');
        m++;
      }
    } else {
      msIO_setHeader("Content-Type","text/html");
      msIO_sendHeaders();
      msIO_printf("This script should be referenced with a METHOD of GET or METHOD of POST.\n");
      return -1;
    }
  }

  /* check for any available cookies */
  s = getenv2("HTTP_COOKIE", thread_context);
  if(s != NULL) {
    httpCookie = msStrdup(s);
    request->httpcookiedata = msStrdup(s);
    for(x=0; httpCookie[0] != '\0'; x++) {
      if(m >= maxParams) {
        maxParams *= 2;
        request->ParamNames = (char **) msSmallRealloc(request->ParamNames,sizeof(char *) * maxParams);
        request->ParamValues = (char **) msSmallRealloc(request->ParamValues,sizeof(char *) * maxParams);
      }
      request->ParamValues[m] = makeword(httpCookie,';');
      plustospace(request->ParamValues[m]);
      unescape_url(request->ParamValues[m]);
      request->ParamNames[m] = makeword_skip(request->ParamValues[m],'=',' ');
      m++;
    }
  }

  if (queryString)
    free(queryString);
  if (httpCookie)
    free(httpCookie);

  return(m);
}
Exemple #8
0
map<string,string> frameParserFunc(cma_frame& frm)
{
    map<string,string> ret;
    //Chen Hongquan modify, begin
    //char*  componentId[17];
    char componentId[17];
    //Chen Hongquan modify, end
    const uint8_t* data = const_cast<cma_frame*>(&frm)->getPduData();
    memcpy(componentId, data, 17);

    uint32_t timestamp = makelong(makeword(data[17],data[18]),makeword(data[19],data[20]));
    uint16_t alertflag = makeword(data[21],data[22]);
    uint32_t equalicethickness = makelong(makeword(data[23],data[24]),makeword(data[25],data[26]));
    uint32_t tension = makelong(makeword(data[27],data[28]),makeword(data[29],data[30]));
    uint32_t tensiondifference = makelong(makeword(data[31],data[32]),makeword(data[33],data[34]));
    uint32_t windageyawangle = makelong(makeword(data[35],data[36]),makeword(data[37],data[38]));
    uint32_t deflectionangle = makelong(makeword(data[39],data[40]),makeword(data[41],data[42]));
    uint32_t reverse1 = makelong(makeword(data[43],data[44]),makeword(data[45],data[46]));
    uint32_t reverse2 = makelong(makeword(data[47],data[48]),makeword(data[49],data[50]));

    try
    {
    //    string sTimestamp = boost::lexical_cast<string>(timestamp);
        uint64_t ms = timestamp;
        ms *= 1000;
        ms *= 1000;
        Timestamp ts(ms);
        string sTimestamp = ts.toFormattedStringDash(); 
        string sAlertflag = boost::lexical_cast<string>(alertflag);
        string sEqualicethickness = boost::lexical_cast<string>(equalicethickness);
        string sTension = boost::lexical_cast<string>(tension);
        string sTensiondifference = boost::lexical_cast<string>(tensiondifference);
        string sWindageyawangle = boost::lexical_cast<string>(windageyawangle);
        string sDeflectionangle = boost::lexical_cast<string>(deflectionangle);
        string sReverse1 = boost::lexical_cast<string>(reverse1);
        string sReverse2 = boost::lexical_cast<string>(reverse2);

        ret.insert(make_pair<string,string>("Time_Stamp",sTimestamp));
        ret.insert(make_pair<string,string>("Alert_Flag",sAlertflag));
        ret.insert(make_pair<string,string>("Equal_IceThickness",sEqualicethickness));
        ret.insert(make_pair<string,string>("Tension",sTension));
        ret.insert(make_pair<string,string>("Tension_Difference",sTensiondifference));
        ret.insert(make_pair<string,string>("Windage_Yaw_Angle",sWindageyawangle));
        ret.insert(make_pair<string,string>("Deflection_Angle",sDeflectionangle));
        ret.insert(make_pair<string,string>("Reverse1",sReverse1));
        ret.insert(make_pair<string,string>("Reverse2",sReverse2));
    }
    catch (boost::bad_lexical_cast& e)
    {
        return ret;
    }

    return ret;
}
Exemple #9
0
map<string,string> frameParserFunc(cma_frame& frm)
{
   	map<string,string> ret;
   	//Chen Hongquan modify, begin
    	//char*  componentId[17];
   	char componentId[17];
    //Chen Hongquan modify, end
    	const uint8_t* data = const_cast<cma_frame*>(&frm)->getPduData();
    	memcpy(componentId, data, 17);

    	uint32_t timestamp = makelong(makeword(data[17], data[18]), makeword(data[19], data[20]));
	uint16_t alertflag = makeword(data[21], data[22]);

	uint32_t average_WindSpeed_10min_tmp = makelong(makeword(data[23], data[24]), makeword(data[25], data[26]));	//xinsy20140326
	float 	 average_WindSpeed_10min = getDecNumber(average_WindSpeed_10min_tmp);					//xinsy20140326

	uint16_t average_WindDirection_10min = makeword(data[27], data[28]);

	uint32_t max_WindSpeed_tmp = makelong(makeword(data[29], data[30]), makeword(data[31], data[32]));		//xinsy20140326
	float 	 max_WindSpeed = getDecNumber(max_WindSpeed_tmp);							//xinsy20140326

	uint32_t extreme_WindSpeed_tmp = makelong(makeword(data[33], data[34]), makeword(data[35], data[36]));		//xinsy20140326
	float 	 extreme_WindSpeed = getDecNumber(extreme_WindSpeed_tmp);						//xinsy20140326

	uint32_t standard_WindSpeed_tmp = makelong(makeword(data[37], data[38]), makeword(data[39], data[40]));		//xinsy20140326
	float 	 standard_WindSpeed = getDecNumber(standard_WindSpeed_tmp);						//xinsy20140326

	uint32_t air_Temperature_tmp = makelong(makeword(data[41], data[42]), makeword(data[43], data[44]));		//xinsy20140326
	float 	 air_Temperature = getDecNumber(air_Temperature_tmp);							//xinsy20140326

	uint16_t humidity = makeword(data[45], data[46]);

	uint32_t air_Pressure_tmp= makelong(makeword(data[47], data[48]), makeword(data[49], data[50]));		//xinsy20140326
	float 	 air_Pressure = getDecNumber(air_Pressure_tmp);								//xinsy20140326

	uint32_t precipitation_tmp= makelong(makeword(data[51], data[52]), makeword(data[53], data[54]));		//xinsy20140326
	float 	 precipitation = getDecNumber(precipitation_tmp);							//xinsy20140326

	uint32_t precipitation_Intensity_tmp= makelong(makeword(data[55], data[56]), makeword(data[57], data[58]));	//xinsy20140326
	float 	 precipitation_Intensity = getDecNumber(precipitation_Intensity_tmp);					//xinsy20140326

	uint16_t radiation_Intensity = makeword(data[59], data[60]);

	uint32_t reserve1 = makelong(makeword(data[61], data[62]), makeword(data[63], data[64]));
	uint32_t reserve2 = makelong(makeword(data[65], data[66]), makeword(data[67], data[68]));

    	try
    	{
		uint64_t ms = timestamp;
		ms *= 1000;
		ms *= 1000;
		Timestamp ts(ms);
		string sTimestamp = ts.toFormattedStringDash(); 
		string sAlertflag = boost::lexical_cast<string>(alertflag);
		string sAverage_WindSpeed_10min = boost::lexical_cast<string>(average_WindSpeed_10min);
		string sAverage_WindDirection_10min= boost::lexical_cast<string>(average_WindDirection_10min);
		string sMax_WindSpeed = boost::lexical_cast<string>(max_WindSpeed);
		string sExtreme_WindSpeed = boost::lexical_cast<string>(extreme_WindSpeed);
		string sStandard_WindSpeed = boost::lexical_cast<string>(standard_WindSpeed);
		string sAir_Temperature = boost::lexical_cast<string>(air_Temperature);
		string sHumidity = boost::lexical_cast<string>(humidity);
		string sAir_Pressure = boost::lexical_cast<string>(air_Pressure);
		string sPrecipitation = boost::lexical_cast<string>(precipitation);
		string sPrecipitation_Intensity = boost::lexical_cast<string>(precipitation_Intensity);
		string sRadiation_Intensity = boost::lexical_cast<string>(radiation_Intensity);

		string sReverse1 = boost::lexical_cast<string>(reserve1);
		string sReverse2 = boost::lexical_cast<string>(reserve2);


	#if 1	//xinsy20140326
		LOG_INFO << "Average_WindSpeed_10min : " << sAverage_WindSpeed_10min;
		LOG_INFO << "Average_WindDirection_10min : " << sAverage_WindDirection_10min;
		LOG_INFO << "Max_WindSpeed : " << sMax_WindSpeed;
		LOG_INFO << "Extreme_WindSpeed : " << sExtreme_WindSpeed;
		LOG_INFO << "Standard_WindSpeed : " << sStandard_WindSpeed;
		LOG_INFO << "Air_Temperature : " << sAir_Temperature;
		LOG_INFO << "Humidity : " << sHumidity;
		LOG_INFO << "Air_Pressure : " << sAir_Pressure;
		LOG_INFO << "Precipitation : " << sPrecipitation;
		LOG_INFO << "Precipitation_Intensity : " << sPrecipitation_Intensity;
		LOG_INFO << "Radiation_Intensity : " << sRadiation_Intensity;
		LOG_INFO << "Precipitation : " << sPrecipitation;
	#endif 

		ret.insert(make_pair<string,string>("Time_Stamp",sTimestamp));
		ret.insert(make_pair<string,string>("Alert_Flag",sAlertflag));
		ret.insert(make_pair<string,string>("Average_WindSpeed_10min",sAverage_WindSpeed_10min));
		ret.insert(make_pair<string,string>("Average_WindDirection_10min",sAverage_WindDirection_10min));
		ret.insert(make_pair<string,string>("Max_WindSpeed",sMax_WindSpeed));
		ret.insert(make_pair<string,string>("Extreme_WindSpeed",sExtreme_WindSpeed));
		ret.insert(make_pair<string,string>("Standard_WindSpeed",sStandard_WindSpeed));
		ret.insert(make_pair<string,string>("Air_Temperature",sAir_Temperature));
		ret.insert(make_pair<string,string>("Humidity",sHumidity));
		ret.insert(make_pair<string,string>("Air_Pressure",sAir_Pressure));
		ret.insert(make_pair<string,string>("Precipitation",sPrecipitation));
		ret.insert(make_pair<string,string>("Precipitation_Intensity",sPrecipitation_Intensity));
		ret.insert(make_pair<string,string>("Radiation_Intensity",sRadiation_Intensity));

		ret.insert(make_pair<string,string>("Reverse1",sReverse1));
		ret.insert(make_pair<string,string>("Reverse2",sReverse2));
    	}
    	catch (boost::bad_lexical_cast& e)
    	{
        	return ret;
    	}

    	return ret;
}
Exemple #10
0
int main(int argc, char *argv[])
{
	pentry entries[MAXPOSTVARS];
	entry gentries[MAXGETVARS];
	char *gcl;
	register int i;
	int cl=0;


	ConnectDb();

	if(getenv("REMOTE_ADDR")!=NULL)
		sprintf(gcHost,"%.99s",getenv("REMOTE_ADDR"));

	if(getenv("HTTP_USER_AGENT")!=NULL)
	{
		if(strstr(getenv("HTTP_USER_AGENT"),"Firefox"))
			guBrowserFirefox=1;
	}

#if defined(Linux)
	gethostname(gcHostname, 98);
#else
	//Solaris
	sysinfo(SI_HOSTNAME, gcHostname, 98);
#endif
	
	if(strcmp(getenv("REQUEST_METHOD"),"POST"))
	{
		//Get	
		//SSLCookieLogin();
		
		gcl = getenv("QUERY_STRING");
		for(i=0;gcl[0] != '\0' && i<MAXGETVARS;i++)
		{
			getword(gentries[i].val,gcl,'&');
			plustospace(gentries[i].val);
			unescape_url(gentries[i].val);
			getword(gentries[i].name,gentries[i].val,'=');

			if(!strcmp(gentries[i].name,"gcFunction"))
				sprintf(gcFunction,"%.99s",gentries[i].val);
			else if(!strcmp(gentries[i].name,"gcPage"))
				sprintf(gcPage,"%.99s",gentries[i].val);
		}
		if(gcPage[0])
		{
			if(!strcmp(gcPage,"MyAccount"))
				MyAccountGetHook(gentries,i);
		}
	}
	else
	{
		//Post
		
		cl = atoi(getenv("CONTENT_LENGTH"));
		for(i=0;cl && (!feof(stdin)) && i<MAXPOSTVARS ;i++)
		{
			entries[i].val = fmakeword(stdin,'&',&cl);
			plustospace(entries[i].val);
			unescape_url(entries[i].val);
			entries[i].name = makeword(entries[i].val,'=');
			
			if(!strcmp(entries[i].name,"gcFunction"))
				sprintf(gcFunction,"%.99s",entries[i].val);
			else if(!strcmp(entries[i].name,"gcPage"))
				sprintf(gcPage,"%.99s",entries[i].val);
			else if(!strcmp(entries[i].name,"gcLogin"))
				sprintf(gcLogin,"%.99s",entries[i].val);
			else if(!strcmp(entries[i].name,"gcPasswd"))
				sprintf(gcPasswd,"%.99s",entries[i].val);
		}
	}

	//Not required to be logged in gcFunction section
	if(gcFunction[0])
	{
		if(!strncmp(gcFunction,"Logout",5))
		{
		printf("Set-Cookie: iRadiusLogin=; expires=\"Mon, 01-Jan-1971 00:10:10 GMT\"\n");
		printf("Set-Cookie: iRadiusPasswd=; expires=\"Mon, 01-Jan-1971 00:10:10 GMT\"\n");
        		guPermLevel=0;
			gcUser[0]=0;
			guLoginClient=0;
			htmlLogin();
		}
	}

        /*if(!strcmp(gcFunction,"Login")) SetLogin();

        if(!guPermLevel || !gcUser[0] || !guLoginClient)
                SSLCookieLogin()¨;

	//First page after valid login
	if(!strcmp(gcFunction,"Login"))
		htmlMyAccountd();*/

	//Per page command tree
	MyAccountCommands(entries,i);
	
	//default logged in page
	htmlMyAccount();
	return(0);

}//end of main()
Exemple #11
0
BOOL File::ReadHeader()
{
	FILE* fzip = fopen( strZipPath.c_str(), "rb") ;
	if( !fzip)
	{
		return FALSE ;
	}
	if( fseek( fzip, ulCentralDir, SEEK_SET) != 0)
	{
		fclose( fzip) ;
		return FALSE ;
	}

	// ヘッダのチェック
	if( fgetc( fzip) == 0x50 && 
	    fgetc( fzip) == 0x4b && 
	    fgetc( fzip) == 0x01 && 
	    fgetc( fzip) == 0x02)
	{
		// no problem
	}
	else
	{
		fclose( fzip) ;
		return FALSE ;
	}

	// 読みとり開始
	BYTE byte[ CENTRAL_DIR_SIZE] ;
	fread( byte, sizeof( BYTE), CENTRAL_DIR_SIZE, fzip) ;

	// ヘッダの読みとり
	zipheader.usVersionMadeBy 		= makeword( &byte[ C_VERSION_MADE_BY_0]) ;
	zipheader.usVersionNeededToExtract	= makeword( &byte[ C_VERSION_NEEDED_TO_EXTRACT_0]) ;
	zipheader.usGeneralPurposeBitFlag	= makeword( &byte[ C_GENERAL_PURPOSE_BIT_FLAG]) ;
	zipheader.usCompressionMethod		= makeword( &byte[ C_COMPRESSION_METHOD]) ;
	zipheader.usLastModFileTime		= makeword( &byte[ C_LAST_MOD_FILE_TIME]) ;
	zipheader.usLastModFileDate		= makeword( &byte[ C_LAST_MOD_FILE_DATE]) ;
	zipheader.ulCrc32			= makelong( &byte[ C_CRC32]) ;
	zipheader.ulCompressedSize		= makelong( &byte[ C_COMPRESSED_SIZE]) ;
	zipheader.ulUncompressedSize		= makelong( &byte[ C_UNCOMPRESSED_SIZE]) ;
	zipheader.usFilenameLength		= makeword( &byte[ C_FILENAME_LENGTH]) ;
	zipheader.usExtraFieldLength		= makeword( &byte[ C_EXTRA_FIELD_LENGTH]) ;
	zipheader.usFileCommentLength		= makeword( &byte[ C_FILE_COMMENT_LENGTH]) ;
	zipheader.usDiskNumberStart		= makeword( &byte[ C_DISK_NUMBER_START]) ;
	zipheader.usInternalFileAttributes	= makeword( &byte[ C_INTERNAL_FILE_ATTRIBUTES]) ;
	zipheader.ulExternalFileAttributes	= makelong( &byte[ C_EXTERNAL_FILE_ATTRIBUTES]) ;
	zipheader.ulRelativeOffsetLocalHeader	= makelong( &byte[ C_RELATIVE_OFFSET_LOCAL_HEADER]) ;

	// ファイル名読みとり
	if( zipheader.usFilenameLength > 0)
	{
		char* pszFilename = new char[ zipheader.usFilenameLength + 1] ;
		fread( pszFilename, sizeof( char), zipheader.usFilenameLength, fzip) ;
		pszFilename[ zipheader.usFilenameLength] = '\0' ;
		zipheader.strFilename = pszFilename ;
		delete[] pszFilename ;
	}

	// 拡張領域
	if( zipheader.usExtraFieldLength > 0)
	{
		BYTE* pbyte = new BYTE[ zipheader.usExtraFieldLength] ;
		fread( pbyte, sizeof( BYTE), zipheader.usExtraFieldLength, fzip) ;
		zipheader.pbyteExtra = pbyte ;
	}

	// コメント
	if( zipheader.usFileCommentLength > 0)
	{
		char* pszComment = new char[ zipheader.usFileCommentLength + 1] ;
		fread( pszComment, sizeof( char), zipheader.usFileCommentLength, fzip) ;
		pszComment[ zipheader.usFileCommentLength] = '\0' ;
		zipheader.strComment = pszComment ;
		delete[] pszComment ;
	}

	// ローカルヘッダ
	fseek( fzip, zipheader.ulRelativeOffsetLocalHeader, SEEK_SET) ;
	if( fgetc( fzip) == 0x50 && 
	    fgetc( fzip) == 0x4b && 
	    fgetc( fzip) == 0x03 && 
	    fgetc( fzip) == 0x04)
	{
		// no problem
	}
	else
	{
		fclose( fzip) ;
		return FALSE ;
	}
	fread( byte, sizeof( BYTE), LOCAL_HEADER_SIZE, fzip) ;
	USHORT usFilenameLength2	= makeword( &byte[ L_FILENAME_LENGTH]) ;
	USHORT	usExtraFieldLength2	= makeword( &byte[ L_EXTRA_FIELD_LENGTH]) ;
	ulFileHead = zipheader.ulRelativeOffsetLocalHeader + 4 + LOCAL_HEADER_SIZE
		   + usFilenameLength2 + usExtraFieldLength2 ;

	fclose( fzip) ;
	return TRUE ;
}
int read_encoder(FT_HANDLE ftHandleDYNA, int motorNum)
{
    unsigned char InstructionPacket[160] = {0};
    unsigned char StatusPacket[70]= {0};
    FT_STATUS ft_status;

    //make the packet
    InstructionPacket[0] = 0xff;
    InstructionPacket[1] = 0xff;
    InstructionPacket[ID] = (unsigned char)motorNum;
    InstructionPacket[LENGTH] = 4;
    InstructionPacket[INSTRUCTION] = INST_READ;
    InstructionPacket[PARAMETER] = (unsigned char)36;//address for encoder
    InstructionPacket[PARAMETER+1] = 2;

    unsigned char checksum = 0;
    for(unsigned char i=0; i<(InstructionPacket[LENGTH]+1); i++ )
        checksum += InstructionPacket[i+2];
    InstructionPacket[InstructionPacket[LENGTH]+3] = ~checksum;

    //send the packet
    unsigned char *pPacket = InstructionPacket;
    int numPacket = 8; //length plus 4
    DWORD dwNumToWrite = (DWORD)numPacket;
    DWORD dwNumWritten;

    ft_status = FT_Write(ftHandleDYNA, (LPVOID)pPacket, dwNumToWrite, &dwNumWritten );
    if( ft_status == FT_IO_ERROR )
    {
        qDebug() << "\n\nError sending encoder packet to motor!";
        return -1;
    }
    if(numPacket != dwNumWritten)
    {
        qDebug() << "\n\nAll Bytes of encoder packet were not written to device!";
        return -1;
    }

    //get status packet
    unsigned char *ppPacket = StatusPacket;
    DWORD dwNumToRead;
    DWORD dwNumRead = 0;

    ft_status = FT_GetQueueStatus(ftHandleDYNA, &dwNumToRead );
    if( ft_status != FT_OK )
    {
        qDebug() << "\n\nError receiving encoder status packet, Queue not empty!";
        return -1;
    }
    if( dwNumToRead > 0 )
    {
        ft_status = FT_Read(ftHandleDYNA, (LPVOID)ppPacket, dwNumToRead, &dwNumRead );
        if( ft_status == FT_IO_ERROR )
        {
            qDebug() << "\n\nError reading encoder value!";
            return -1;
        }
    } else {
        qDebug()<<"\n\nERROR: dwNumToRead = 0";
        return -1;
    }

    return makeword((int)StatusPacket[PARAMETER], (int)StatusPacket[PARAMETER+1]);

}
main(int argc, char *argv[])
{
	entry entries[MAXENTRIES];
	register int x, m = 0;
	int cl, invalid = 0, didroot = 0, didhtml = 0;
	
	char protocol;

	if (strcmp(getenv("REQUEST_METHOD"), "POST")) {
		printf("We can't do much with a blank subscription card, ");
		printf("can we?\n");
		exit(1);
	}

	if (strcmp(getenv("CONTENT_TYPE"),
	"application/x-www-form-urlencoded")) {
		printf("This script can only be used to decode form ");
		printf("results.\n");
		exit(1);
	}

	cl = atoi(getenv("CONTENT_LENGTH"));
	
	sprintf(command, "%s ", GETSTATS);

	for(x = 0; cl && (!feof(stdin)); x++) {
		m = x;
		entries[x].val = fmakeword(stdin, '&', &cl);
		plustospace(entries[x].val);
		unescape_url(entries[x].val);
		entries[x].name = makeword(entries[x].val,'=');

		if (!strcmp(entries[x].name, "protocol")) {
			protocol = entries[x].val[0];

			if (protocol == 'G') 
				sprintf(command, "%s -G %s", command);
			else if (protocol == 'N')
				sprintf(command, "%s -N %s", command);
			else if (protocol == 'C')
				sprintf(command, "%s -C %s", command);
			else if (protocol == 'P')
				sprintf(command, "%s -P %s", command);
			else if (protocol == 'M')
				sprintf(command, "%s -A %s", command);
			else if (protocol == 'U')
				sprintf(command, "%s -O %s", command);
		}

		if (!didroot) {
			sprintf(command, "%s -dr %s", command, ROOTDIR);
			didroot = 1;
		}

		if (!strcmp(entries[x].name, "logfilename"))
			if (strlen(entries[x].val)) 
				sprintf(command, "%s -l %s", command,
				entries[x].val);
			else 
				sprintf(command, "%s -l %s", command, LOGFILE);

		if (!strcmp(entries[x].name, "common") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -M", command);

		if (!strcmp(entries[x].name, "concise") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -c", command);

		if (!strcmp(entries[x].name, "toplines") && 
		strlen(entries[x].val))
			sprintf(command, "%s -t %s ", command, entries[x].val);

		if (!strcmp(entries[x].name, "all") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -a ", command);

		if (!strcmp(entries[x].name, "monthly") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -m ", command);

		if (!strcmp(entries[x].name, "weekly") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -w ", command);

		if (!strcmp(entries[x].name, "daysweek") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -ds ", command);

		if (!strcmp(entries[x].name, "daily") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -d ", command);

		if (!strcmp(entries[x].name, "hoursday") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -hs ", command);

		if (!strcmp(entries[x].name, "hourly") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -h ", command);

		if (!strcmp(entries[x].name, "full-hostname") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -f ", command);

		if (!strcmp(entries[x].name, "full-access") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -fa ", command);

		if (!strcmp(entries[x].name, "full-lastaccess") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -fd ", command);

		if (!strcmp(entries[x].name, "full-bytes") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -fb ", command);

		if (!strcmp(entries[x].name, "request-name") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -r ", command);

		if (!strcmp(entries[x].name, "request-accesses") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -ra ", command);

		if (!strcmp(entries[x].name, "request-lastaccesses") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -rd ", command);

		if (!strcmp(entries[x].name, "request-bytes") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -rb ", command);

		if (!strcmp(entries[x].name, "request-filesize") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -rf ", command);

		if (!strcmp(entries[x].name, "domain-name") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -dn ", command);

		if (!strcmp(entries[x].name, "domain-requests") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -da ", command);

		if (!strcmp(entries[x].name, "domain-lastaccesses") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -dd ", command);

		if (!strcmp(entries[x].name, "domain-bytes") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -db ", command);

		if (!strcmp(entries[x].name, "domain-sub") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -du ", command);

		if (!strcmp(entries[x].name, "filetree") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -dt ", command);

		if (!strcmp(entries[x].name, "error") && 
		!strcmp(entries[x].val, "on"))
			sprintf(command, "%s -e ", command);

		if (!strcmp(entries[x].name, "samask"))
			if (strlen(entries[x].val) != 0)
				sprintf(command, "%s -sa \"%s\"", command,
				entries[x].val);
			
		if (!strcmp(entries[x].name, "ssmask"))
			if (strlen(entries[x].val) != 0)
				sprintf(command, "%s -ss \"%s\"", command,
				entries[x].val);
			
		if (!strcmp(entries[x].name, "srmask"))
			if (strlen(entries[x].val) != 0)
				sprintf(command, "%s -sr \"%s\"", command,
				entries[x].val);
			
		if (!strcmp(entries[x].name, "spmask"))
			if (strlen(entries[x].val) != 0)
				sprintf(command, "%s -sp \"%s\"", command,
				entries[x].val);
			
		if (!strcmp(entries[x].name, "sdmask"))
			if (strlen(entries[x].val) != 0)
				sprintf(command, "%s -sd \"%s\"", command,
				entries[x].val);
			
		if (!strcmp(entries[x].name, "shmask"))
			if (strlen(entries[x].val) != 0)
				sprintf(command, "%s -sh \"%s\"", command,
				entries[x].val);
			
		if (!strcmp(entries[x].name, "swmask"))
			if (strlen(entries[x].val) != 0)
				sprintf(command, "%s -sw \"%s\"", command,
				entries[x].val);
			
		if (!strcmp(entries[x].name, "mailme") && 
		strlen(entries[x].val) != 0) {
			sprintf(command, "%s | /usr/ucb/mail -s \"%s\" %s",
			command, SUBJECT, entries[x].val);
			printf("Content-type: text/html\n\n");
			printf("<title>It's in the mail...</title>\n<p>\n");
			printf("<h1>Your log request is being mailed to ");
			printf("you.</h1>\n");
			printf("The following command was executed:\n");
			printf("<p>\n<code>%s</code>\n", command);
		}
		else if (!strcmp(entries[x].name, "mailme") &&
		strlen(entries[x].val) == 0 && !didhtml) {
			sprintf(command, "%s -ht", command);
			didhtml = 1;
		}
	}
	sprintf(command, "%s &\n", command);
	system(command);

	exit(0);
}