int UnzOpr::find_ecrec64(ZInt64 searchlen) /* return PK-class error */ { uch byterec[ECREC64_SIZE + 4]; switch(rec_find(searchlen, EndCentral64Sig /* fend_central64_sig */ , ECREC64_SIZE)) { case 1: return PK_OK; case 2: // if (uO.qflag || uO.zipinfo_mode) // Info(slide, 0x401, ((char *)slide, "[%s]\n", fzipfn)); Notify(IERROR, _T("end-of-central-dir64 signature not found [%s]"), fzipfn.c_str()); // Info(slide, 0x401, ((char *)slide, // LoadFarString(Cent64EndSigSearchErr))); return PK_ERR; /* else: found ECREC64, continue! */ } freal_ecrec_offset = fcur_zipfile_bufstart + (finptr - finbuf); if (readbuf((char*)byterec, ECREC64_SIZE + 4) == 0) return PK_EOF; if (fecrec.number_this_disk == 0xffff) fecrec.number_this_disk = makelong(&byterec[NUMBER_THIS_DISK64]); if (fecrec.num_disk_start_cdir == 0xffff) fecrec.num_disk_start_cdir = makelong (&byterec[NUM_DISK_WITH_START_CEN_DIR64]); if (fecrec.num_entries_centrl_dir_ths_disk == 0xffff) fecrec.num_entries_centrl_dir_ths_disk = makeint64 (&byterec[NUM_ENTRIES_CEN_DIR_THS_DISK64]); if (fecrec.total_entries_central_dir == 0xffff) fecrec.total_entries_central_dir = makeint64 (&byterec[TOTAL_ENTRIES_CENTRAL_DIR64]); if (fecrec.size_central_directory == 0xffffffff) fecrec.size_central_directory = makeint64 (&byterec[SIZE_CENTRAL_DIRECTORY64]); if (fecrec.offset_start_central_directory == 0xffffffff) fecrec.offset_start_central_directory = makeint64 (&byterec[OFFSET_START_CENTRAL_DIRECTORY64]); /* We know its a big file now. The "end of the central directory" mark used as break condition for the central-directory scan is the "end_central64" signature. */ fecrec.is_zip64_archive = TRUE; return PK_COOL; } /* end function find_ecrec64() */
SC_FUNC int error_suggest(int number,const char *name,int ident) { symbol *closestsym=find_closestsymbol(name,ident); if (closestsym!=NULL && strcmp(name,closestsym->name)!=0) error(makelong(number,1),name,closestsym->name); else error(number,name); return 0; }
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; }
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; }
SC_FUNC int error_suggest_list(int number,const char *name,constvalue *list) { assert(name!=NULL); assert(list!=NULL); if (sc_status==statWRITE) { constvalue *closest=NULL; if (strlen(name)>0) { int dist,closestdist=INT_MAX; while (list->next!=NULL) { list=list->next; dist=levenshtein_distance(list->name,name); if (dist<closestdist && dist<=MAX_EDIT_DIST) { closest=list; closestdist=dist; } /* if */ } /* while */ } /* if */ if (closest!=NULL && strcmp(name,closest->name)!=0) error(makelong(number,1),name,closest->name); else error(number,name); } /* if */ return 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() */
/* =========================================================================== * 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; }
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; }
int main (int argc, char **argv) { int sd; int result; struct SysInfo s; struct PilotUser u1, u2; struct NetSyncInfo n1, n2; struct CardInfo c; struct DBInfo dbi; struct DBSizeInfo dbsi; unsigned long romVersion; time_t t1, t2; int handle; unsigned char pref1[256], pref2[256]; unsigned char ablock1[256]; unsigned char sblock1[256]; unsigned char ires1[256]; unsigned char dres1[256]; unsigned char record1[256], record2[256], record3[256]; recordid_t rid1, rid2, rid3, rlist[4]; int index, id_, count; unsigned long type; int cardno; int i; pi_buffer_t *record4, *dres2, *ires2, *appblock; record4 = pi_buffer_new (sizeof(record1)); ires2 = pi_buffer_new (sizeof (ires1)); dres2 = pi_buffer_new (sizeof (dres1)); appblock = pi_buffer_new(256); sd = pilot_connect (argv[1]); t1 = time (NULL); LOG((PI_DBG_USER, PI_DBG_LVL_INFO, "DLPTEST Starting at %s", ctime (&t1))); /********************************************************************* * * Test: Open Conduit * * Direct Testing Functions: * dlp_OpenConduit * * Indirect Testing Functions: * None * *********************************************************************/ result = dlp_OpenConduit (sd); CHECK_RESULT(dlp_OpenConduit); /********************************************************************* * * Test: System Information * * Direct Testing Functions: * dlp_ReadSysInfo * * Indirect Testing Functions: * None * *********************************************************************/ result = dlp_ReadSysInfo (sd, &s); CHECK_RESULT(dlp_ReadSysInfo); /********************************************************************* * * Test: User Info * * Direct Testing Functions: * dlp_WriteUserInfo * dlp_ReadUserInfo * * Indirect Testing Functions: * None * *********************************************************************/ memset (&u1, '\0', sizeof (struct PilotUser)); memset (&u2, '\0', sizeof (struct PilotUser)); u1.passwordLength = 0; strcpy (u1.username, "Test User"); strcpy (u1.password, ""); u1.userID = 500; u1.viewerID = 5000; u1.lastSyncPC = 111111; u1.successfulSyncDate = time(NULL); u1.lastSyncDate = time(NULL) + 100; result = dlp_WriteUserInfo (sd, &u1); CHECK_RESULT(dlp_WriteUserInfo); result = dlp_ReadUserInfo (sd, &u2); CHECK_RESULT(dlp_ReadUserInfo); if (memcmp(&u1, &u2, sizeof(struct PilotUser) != 0)) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST User info mismatch\n")); goto error; } /********************************************************************* * * Test: Feature * * Direct Testing Functions: * dlp_ReadFeature * * Indirect Testing Functions: * None * *********************************************************************/ romVersion = 0; result = dlp_ReadFeature(sd, makelong("psys"), 1, &romVersion); CHECK_RESULT(dlp_ReadFeature); if (romVersion != s.romVersion) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Rom Version mismatch\n")); goto error; } /********************************************************************* * * Test: Net Sync Info * * Direct Testing Functions: * dlp_WriteNetSyncInfo * dlp_ReadNetSyncInfo * * Indirect Testing Functions: * None * *********************************************************************/ #if DLP_1_1 memset (&n1, '\0', sizeof (struct NetSyncInfo)); memset (&n2, '\0', sizeof (struct NetSyncInfo)); n1.lanSync = 0; strcpy (n1.hostName, "localhost"); strcpy (n1.hostAddress, "192.168.1.1"); strcpy (n1.hostSubnetMask, "255.255.255.0"); result = dlp_WriteNetSyncInfo (sd, &n1); CHECK_RESULT(dlp_WriteNetSyncInfo); result = dlp_ReadNetSyncInfo (sd, &n2); CHECK_RESULT(dlp_ReadNetSyncInfo); if (memcmp(&n1, &n2, sizeof(struct NetSyncInfo) != 0)) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Net sync info mismatch\n")); goto error; } #endif /********************************************************************* * * Test: Time * * Direct Testing Functions: * dlp_SetSysDateTime * dlp_GetSysDateTime * * Indirect Testing Functions: * None * *********************************************************************/ t1 = time(NULL); dlp_SetSysDateTime (sd, t1); CHECK_RESULT(dlp_SetSysDateTime); dlp_GetSysDateTime (sd, &t2); CHECK_RESULT(dlp_GetSysDateTime); if (t2 > t1 + 1) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST System Time Mismatch\n")); goto error; } /********************************************************************* * * Test: Storage Information * * Direct Testing Functions: * dlp_ReadStorageInfo * * Indirect Testing Functions: * None * *********************************************************************/ c.more = 1; for (i = 0; c.more != 0; i++) { result = dlp_ReadStorageInfo (sd, i, &c); CHECK_RESULT(dlp_ReadStorageInfo); } /********************************************************************* * * Test: Database List * * Direct Testing Functions: * dlp_ReadDBList * * Indirect Testing Functions: * None * *********************************************************************/ dbi.more = 1; for (i = 0; dbi.more != 0; i++) { result = dlp_ReadDBList (sd, 0, dlpDBListRAM | dlpDBListROM, i, record4); CHECK_RESULT(dlp_ReadDBList); memcpy(&dbi, record4->data, sizeof(struct DBInfo)); } /********************************************************************* * * Test: Existing Database * * Direct Testing Functions: * dlp_OpenDB * dlp_CloseDB * * Indirect Testing Functions: * None * *********************************************************************/ result = dlp_OpenDB (sd, 0, dlpOpenReadWrite, "ToDoDB", &handle); CHECK_RESULT(dlp_OpenDB); result = dlp_CloseDB (sd, handle); CHECK_RESULT(dlp_CloseDB); /********************************************************************* * * Test: New Database * * Direct Testing Functions: * dlp_CreateDB * dlp_CloseDB * dlp_DeleteDB * * Indirect Testing Functions: * None * *********************************************************************/ result = dlp_CreateDB (sd, CREATOR, DATA, 0, dlpDBFlagResource, 1, "TestResource", &handle); CHECK_RESULT(dlp_CreateDB); result = dlp_CloseDB (sd, handle); CHECK_RESULT(dlp_CloseDB); result = dlp_DeleteDB (sd, 0, "TestResource"); CHECK_RESULT(dlp_DeleteDB); /********************************************************************* * * Test: Database Info and Searching * * Direct Testing Functions: * dlp_SetDBInfo * dlp_FindDBByName * dlp_FindDBByOpenHandle * dlp_FindDBByTypeCreator * * Indirect Testing Functions: * dlp_CreateDB * dlp_OpenDB * dlp_ReadDBList * dlp_CloseDB * dlp_DeleteDB * *********************************************************************/ #if DLP_1_2 result = dlp_CreateDB (sd, CREATOR, DATA, 0, 0, 1, "TestRecord", &handle); CHECK_RESULT(dlp_CreateDB); result = dlp_SetDBInfo (sd, handle, dlpDBFlagBackup, dlpDBFlagCopyPrevention, 0, 0, 0, 0, 0, 0); CHECK_RESULT(dlp_SetDBInfo); result = dlp_CloseDB (sd, handle); CHECK_RESULT(dlp_CloseDB); result = dlp_OpenDB (sd, 0, dlpOpenReadWrite, "TestRecord", &handle); CHECK_RESULT(dlp_OpenDB); result = dlp_FindDBByOpenHandle (sd, handle, &cardno, NULL, &dbi, &dbsi); CHECK_RESULT(dlp_FindDBByOpenHandle); if (strcmp (dbi.name, "TestRecord") || !(dbi.flags & dlpDBFlagBackup)) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Database info mismatch with openhandle\n")); goto error; } result = dlp_CloseDB (sd, handle); CHECK_RESULT(dlp_CloseDB); result = dlp_FindDBByName (sd, 0, "TestRecord", NULL, NULL, &dbi, &dbsi); CHECK_RESULT(dlp_FindDBByName); if (strcmp (dbi.name, "TestRecord") || !(dbi.flags & dlpDBFlagBackup)) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Database info mismatch with name\n")); goto error; } result = dlp_FindDBByTypeCreator (sd, DATA, CREATOR, 1, 0, &cardno, NULL, NULL, &dbi, &dbsi); CHECK_RESULT(dlp_FindDBByName); if (strcmp (dbi.name, "TestRecord") || !(dbi.flags & dlpDBFlagBackup)) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Database info mismatch with type/creator\n")); goto error; } result = dlp_DeleteDB (sd, 0, "TestRecord"); CHECK_RESULT(dlp_DeleteDB); #endif /********************************************************************* * * Test: App Preference * * Direct Testing Functions: * dlp_WriteAppPreference * dlp_ReadAppPreference * * Indirect Testing Functions: * None * *********************************************************************/ memset (pref1, '\0', sizeof (pref1)); memset (pref2, '\0', sizeof (pref2)); pref1[9] = 'T'; pref2[10] = 'T'; result = dlp_WriteAppPreference (sd, CREATOR, 0, 1, 1, pref1, sizeof(pref1)); CHECK_RESULT(dlp_WriteAppPrefence); result = dlp_ReadAppPreference (sd, CREATOR, 0, 1, sizeof(pref2), pref2, NULL, NULL); CHECK_RESULT(dlp_ReadAppPreference); if (memcmp(&pref1, &pref2, sizeof(pref1) != 0)) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Preference mismatch\n")); goto error; } /********************************************************************* * * Test: Record * * Direct Testing Functions: * dlp_WriteAppBlock * dlp_ReadAppBlock * dlp_WriteSortBlock * dlp_ReadSortBlock * dlp_WriteRecord * dlp_ReadOpenDBInfo * dlp_ReadRecordById * dlp_ReadRecordByIndex * dlp_ReadNextModifiedRec * dlp_ReadNextRecInCategory * dlp_ReadNextModifiedRecInCategory * dlp_MoveCategory * dlp_DeleteRecord * dlp_DeleteCategory * dlp_ResetDBIndex * * Indirect Testing Functions: * dlp_CreateDB * dlp_CloseDB * dlp_DeleteDB * *********************************************************************/ memset (ablock1, '\0', sizeof (ablock1)); memset (sblock1, '\0', sizeof (sblock1)); memset (record1, '\0', sizeof (record1)); memset (record2, '\0', sizeof (record2)); memset (record3, '\0', sizeof (record3)); ablock1[3] = 'T'; sblock1[17] = 'T'; record1[32] = 'T'; record2[33] = 'T'; record3[34] = 'T'; result = dlp_CreateDB (sd, CREATOR, DATA, 0, 0, 1, "TestRecord", &handle); CHECK_RESULT(dlp_CreateDB); /* Write and read back an app block */ result = dlp_WriteAppBlock (sd, handle, ablock1, sizeof(ablock1)); CHECK_RESULT(dlp_WriteAppBlock); result = dlp_ReadAppBlock (sd, handle, 0, sizeof(ablock1), appblock); CHECK_RESULT(dlp_ReadAppBlock); if (result != sizeof(ablock1) || memcmp(ablock1, appblock->data, sizeof(ablock1) != 0)) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST App block mismatch\n")); goto error; } /* Write and read back a sort block */ result = dlp_WriteSortBlock (sd, handle, sblock1, sizeof(sblock1)); CHECK_RESULT(dlp_WriteSortBlock); result = dlp_ReadSortBlock (sd, handle, 0, sizeof(sblock1), appblock); CHECK_RESULT(dlp_ReadSortBlock); if (result != sizeof(sblock1) || memcmp(sblock1, appblock->data, sizeof(sblock1) != 0)) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST App block mismatch\n")); goto error; } /* Write some records out */ result = dlp_WriteRecord (sd, handle, 0, 0, 1, record1, sizeof(record1), &rid1); CHECK_RESULT(dlp_WriteRecord); result = dlp_WriteRecord (sd, handle, dlpRecAttrDirty, 0, 2, record2, sizeof(record2), &rid2); CHECK_RESULT(dlp_WriteRecord); result = dlp_WriteRecord (sd, handle, 0, 0, 3, record3, sizeof(record3), &rid3); CHECK_RESULT(dlp_WriteRecord); /* Get the db info */ result = dlp_ReadOpenDBInfo (sd, handle, &count); CHECK_RESULT(dlp_ReadOpenDBInfo); if (count != 3) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Read wrong open database info\n")); goto error; } /* Get the id list */ result = dlp_ReadRecordIDList (sd, handle, 0, 0, 4, rlist, &count); CHECK_RESULT(dlp_ReadRecordIDList); if (count != 3) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Read wrong record id list length\n")); goto error; } for (i = 0; i < 3; i++) { if (rlist[i] != rid1 && rlist[i] != rid2 && rlist[i] != rid3) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Read wrong record id\n")); goto error; } } /* Try reading the records in various ways */ result = dlp_ReadRecordById (sd, handle, rid1, record4, &index, NULL, NULL); CHECK_RESULT(dlp_ReadRecordById); if (memcmp(record1, record4->data, sizeof(record1) != 0)) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Record by Id mismatch\n")); goto error; } result = dlp_ReadRecordByIndex (sd, handle, index, record4, NULL, NULL, NULL); CHECK_RESULT(dlp_ReadRecordByIndex); if (memcmp(record1, record4->data, sizeof(record1) != 0)) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Record by index mismatch\n")); goto error; } result = dlp_ReadNextModifiedRec (sd, handle, record4, NULL, NULL, NULL, NULL); CHECK_RESULT(dlp_ReadNextModifiedRec); if (memcmp(record2, record4->data, sizeof(record2) != 0)) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Next modified record mismatch\n")); goto error; } /* Reset because of the above next modified record call */ result = dlp_ResetDBIndex (sd, handle); CHECK_RESULT(dlp_ResetDBIndex) /* This is a DLP 1.1 call, but pilot-link has a 1.0 implementation */ result = dlp_ReadNextRecInCategory (sd, handle, 3, record4, NULL, NULL, NULL); CHECK_RESULT(dlp_ReadNextRecInCategory) if (memcmp(record3, record4->data, sizeof(record3) != 0)) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST dlp_ReadNextRecInCategory mismatch\n")); goto error; } /* Reset because of the above next record in category call */ result = dlp_ResetDBIndex (sd, handle); CHECK_RESULT(dlp_ResetDBIndex) /* This is a DLP 1.1 call, but pilot-link has a 1.0 implementation */ result = dlp_ReadNextModifiedRecInCategory (sd, handle, 2, record4, NULL, NULL, NULL); CHECK_RESULT(dlp_ReadNextModifiedRecInCategory) if (memcmp(record2, record4->data, sizeof(record2) != 0)) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST dlp_ReadNextModifiedRecInCategory mismatch\n")); goto error; } /* Reset because of the above next modified record in category call */ result = dlp_ResetDBIndex (sd, handle); CHECK_RESULT(dlp_ResetDBIndex) /* Move a category and try to read the record back in */ result = dlp_MoveCategory (sd, handle, 1, 4); CHECK_RESULT(dlp_MoveCategory) result = dlp_ReadNextRecInCategory (sd, handle, 4, record4, NULL, NULL, NULL); CHECK_RESULT(dlp_ReadNextRecInCategory) if (memcmp(record1, record4->data, sizeof(record1) != 0)) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST dlp_ReadNextRecInCategory mismatch\n")); goto error; } /* Delete records in various ways */ result = dlp_DeleteRecord (sd, handle, 0, rid1); CHECK_RESULT(dlp_DeleteRecord <Single>); result = dlp_ReadRecordById (sd, handle, rid1, record4, NULL, NULL, NULL); if (result >= 0) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Deleted record could still be read\n")); goto error; } result = dlp_DeleteCategory (sd, handle, 3); CHECK_RESULT(dlp_DeleteCategory); result = dlp_ReadRecordById (sd, handle, rid3, record4, NULL, NULL, NULL); if (result >= 0) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Deleted category could still be read\n")); goto error; } result = dlp_DeleteRecord (sd, handle, 1, 0); CHECK_RESULT(dlp_DeleteRecord <All>); result = dlp_ReadRecordById (sd, handle, rid2, record4, NULL, NULL, NULL); if (result >= 0) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Deleted all record could still be read\n")); goto error; } result = dlp_CloseDB (sd, handle); CHECK_RESULT(dlp_CloseDB); result = dlp_DeleteDB (sd, 0, "TestRecord"); CHECK_RESULT(dlp_DeleteDB); /********************************************************************* * * Test: Resource * * Direct Testing Functions: * dlp_WriteResource * dlp_ReadResourceByType * dlp_ReadResourceByIndex * dlp_DeleteResource * * Indirect Testing Functions: * dlp_CreateDB * dlp_CloseDB * dlp_DeleteDB * *********************************************************************/ memset (ires1, '\0', sizeof (ires1)); memset (dres1, '\0', sizeof (dres1)); ires1[3] = 'T'; dres1[4] = 'T'; result = dlp_CreateDB (sd, CREATOR, DATA, 0, dlpDBFlagResource, 1, "TestResource", &handle); CHECK_RESULT(dlp_CreateDB); /* Write out some resources */ result = dlp_WriteResource (sd, handle, INFO, 1, ires1, sizeof(ires1)); CHECK_RESULT(dlp_WriteResource); result = dlp_WriteResource (sd, handle, DATA, 0, dres1, sizeof(dres1)); CHECK_RESULT(dlp_WriteResource); /* Read in the resources by various methods */ result = dlp_ReadResourceByType (sd, handle, INFO, 1, ires2, &index); CHECK_RESULT(dlp_ReadResourceByType) if (memcmp(ires1, ires2->data, sizeof(ires1) != 0)) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Resource by type mismatch\n")); goto error; } result = dlp_ReadResourceByIndex (sd, handle, index, ires2, &type, &id_); CHECK_RESULT(dlp_ReadResourceByIndex) if (memcmp(ires1, ires2->data, sizeof(ires1) != 0)) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Resource by index mismatch\n")); goto error; } if (type != INFO) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Resource by index return type mismatch\n")); goto error; } if (id_ != 1) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Resource by index return id mismatch\n")); goto error; } /* Delete resources by the various methods */ result = dlp_DeleteResource (sd, handle, 0, INFO, 1); CHECK_RESULT(dlp_DeleteResource <Single>) result = dlp_ReadResourceByType (sd, handle, INFO, 1, ires2, &index); if (result >= 0) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Deleted resource could still be read\n")); goto error; } result = dlp_DeleteResource (sd, handle, 1, INFO, 1); CHECK_RESULT(dlp_DeleteResource <All>) result = dlp_ReadResourceByType (sd, handle, DATA, 0, dres2, &index); if (result >= 0) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Deleted all resource could still be read\n")); goto error; } result = dlp_CloseDB (sd, handle); CHECK_RESULT(dlp_CloseDB) result = dlp_DeleteDB (sd, 0, "TestResource"); CHECK_RESULT(dlp_DeleteDB) /********************************************************************* * * Test: Database Cleanup * * Direct Testing Functions: * dlp_CleanUpDatabase * dlp_ResetSyncFlags * * Indirect Testing Functions: * dlp_CreateDB * dlp_WriteRecord * dlp_CloseDB * dlp_DeleteDB * *********************************************************************/ result = dlp_CreateDB (sd, CREATOR, DATA, 0, 0, 1, "TestRecord", &handle); CHECK_RESULT(dlp_CreateDB); /* Create dummy records */ result = dlp_WriteRecord (sd, handle, dlpRecAttrDeleted, 0, 0, record1, sizeof(record1), &rid1); CHECK_RESULT(dlp_WriteRecord); result = dlp_WriteRecord (sd, handle, dlpRecAttrDirty, 0, 0, record2, sizeof(record2), &rid2); CHECK_RESULT(dlp_WriteRecord); /* Call the test functions */ result = dlp_CleanUpDatabase (sd, handle); CHECK_RESULT(dlp_CleanUpDatabase); result = dlp_ResetSyncFlags (sd, handle); CHECK_RESULT(dlp_ResetSyncFlags); result = dlp_CloseDB (sd, handle); CHECK_RESULT(dlp_CloseDB); /* Confirm the test functions worked */ result = dlp_OpenDB (sd, 0, dlpOpenReadWrite, "TestRecord", &handle); CHECK_RESULT(dlp_OpenDB); result = dlp_ReadRecordById (sd, handle, rid1, record4, NULL, NULL, NULL); if (result >= 0) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Cleaned up record could still be read\n")); goto error; } result = dlp_ReadNextModifiedRec (sd, handle, record4, NULL, NULL, NULL, NULL); if (result >= 0) { LOG((PI_DBG_USER, PI_DBG_LVL_ERR, "DLPTEST Modified recorded could still be read\n")); goto error; } result = dlp_CloseDB (sd, handle); CHECK_RESULT(dlp_CloseDB); result = dlp_DeleteDB (sd, 0, "TestRecord"); CHECK_RESULT(dlp_DeleteDB); /********************************************************************* * * Test: Sync Log * * Direct Testing Functions: * dlp_AddSyncLogEntry * * Indirect Testing Functions: * None * *********************************************************************/ result = dlp_AddSyncLogEntry (sd, "dlp-test added sync log entry"); CHECK_RESULT(dlp_AddSyncLogEntry); /********************************************************************* * * Test: End Sync * * Direct Testing Functions: * dlp_EndOfSync * * Indirect Testing Functions: * None * *********************************************************************/ result = dlp_EndOfSync (sd, dlpEndCodeNormal); CHECK_RESULT(dlp_EndOfSync); t1 = time (NULL); LOG((PI_DBG_USER, PI_DBG_LVL_INFO, "DLPTEST Ending at %s", ctime (&t1))); error: pi_close (sd); pi_buffer_free (record4); pi_buffer_free (ires2); pi_buffer_free (dres2); pi_buffer_free(appblock); return 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 ; }