void KURLBar::readConfig(KConfig *appConfig, const QString &itemGroup) { m_isImmutable = appConfig->groupIsImmutable(itemGroup); KConfigGroupSaver cs(appConfig, itemGroup); d->defaultIconSize = m_iconSize; m_iconSize = appConfig->readNumEntry("Speedbar IconSize", m_iconSize); if(m_useGlobal) { // read global items KConfig *globalConfig = KGlobal::config(); KConfigGroupSaver cs(globalConfig, (QString)(itemGroup + " (Global)")); int num = globalConfig->readNumEntry("Number of Entries"); for(int i = 0; i < num; i++) { readItem(i, globalConfig, false); } } // read application local items int num = appConfig->readNumEntry("Number of Entries"); for(int i = 0; i < num; i++) { readItem(i, appConfig, true); } }
bool Loader::readItemsAt(Node* parent, off_t offset) { uint32_t itemCount; if (!m_file->seek(offset)) { return false; } if (m_file->read(&itemCount, 4) != 4) { return false; } for (uint32_t i = 0; i < itemCount; i++) { readItem(parent); } std::vector<Node*> children; parent->getChildren(children); for (std::vector<Node*>::const_iterator it = children.begin(); it != children.end(); ++it) { Node* child = *it; readItemsAt(child, child->getFileOffset()); } return true; }
void specResizeSVGcommand::readCommand(QDataStream& in) { qint8 newAnchor ; in >> other ; readItem(in) ; in >> newAnchor ; anchor = (specSVGItem::SVGCornerPoint) newAnchor ; }
void Connection::update() { while(bytesAvailable()) { QDataStream s(this); if (packetSize<0) { if (bytesAvailable()<4) break; s>>packetSize; // if (packetSize>1<<20) //qDebug()<<"big packet"<<packetSize; } if (bytesAvailable()<packetSize) break; // //qDebug()<<"packet size"<<packetSize; packetSize=-1; quint8 type; s>>type; // //qDebug()<<"available: "<<type; switch(type) { case MSG_INITIAL: readInitial(s); break; case MSG_STATE: readState(s); break; case MSG_SHOOT: readShoot(s); break; case MSG_HIT: readHit(s); break; case MSG_ENEMY: readEnemy(s); break; case MSG_ITEM: readItem(s); break; case MSG_GET: readGet(s); break; case MSG_DIE: for(int i=0; i<engine.bulletCounts.size(); ++i) engine.bulletCounts[i]=0; player->weapon = 1; break; case MSG_LIGHTNING: readLightning(s); break; case MSG_STATS: readStats(s); break; case MSG_CHAT: readChat(s); break; default: //qDebug()<<type; abort(); } ++packetCount; } }
int loadItems(struct Item* Iptr, FILE* fptr){ int i = 0; while (!feof(fptr)){ readItem(&Iptr[i], fptr); if (!feof(fptr)){ i++; } } return i; }
void *TCollection::read( ipstream& is ) { int limit; is >> count >> limit >> delta; limit = 0; setLimit(limit); for( ccIndex idx = 0; idx < count; idx++ ) items[idx] = readItem( is ); return this; }
int32_t Config::setConfStr(const string& name, const string& default_value) { string value = readItem(name); if (value.empty() && default_value.empty()) return -1; else if (value.empty() && !default_value.empty()) value = default_value; _conf_str[name] = value; return 0; }
void Dynamics::gainIntern(double gainFactor) { for (int frame=0; frame<sfInfo.frames; frame++) { for (int channel=0; channel<sfInfo.channels; channel++) { writeItem(frame, channel, readItem(frame, channel)*gainFactor); } } }
void Ingridients::loadItems(const QJsonArray& jsonArray) { PRINT_DEBUG("Loading items"); for ( int i = 0; i < jsonArray.size(); i++ ) { Item* newItem = readItem(jsonArray[i].toObject()); std::list<Item*>::iterator it = std::find(avaliableItems.begin(), avaliableItems.end(), newItem); if ( it == avaliableItems.end() ) { avaliableItems.push_back(newItem); newItem->addItemList(&avaliableItems); } } }
QM3uPlaylistReader(const QUrl& location) :m_ownDevice(true) { QFile *f = new QFile(location.toLocalFile()); if (f->open(QIODevice::ReadOnly | QIODevice::Text)) { m_device = f; m_textStream = new QTextStream(m_device); readItem(); } else { delete f; m_device = 0; m_textStream = 0; } }
Template* readTemplate(char* filename,int type,int numT ) { //get file char* newname=(char*)malloc(sizeof(char)*ARRAY_SIZE_NAME); int indice=0; srand((int)time(NULL)); if(numT!=0)indice=rand() % numT; sprintf(newname, "%s_%d_%d.txt",filename,type, indice); FILE* file = fopen(newname,"r"); if(file == NULL) printf("Error al abrir archivo"); //data char* id=(char*)malloc(sizeof(char)*ARRAY_SIZE_ID); int numItems=0; int type2=0; char** itemPath=NULL; Item** items = NULL; //read fscanf(file, "%s", id); fscanf (file, "%d", &type2); fscanf (file, "%d", &numItems); //memory items=(Item**)malloc(sizeof(Item*)* numItems); itemPath=(char**)malloc(sizeof(char*)*ARRAY_SIZE_NAME); for(int i=0;i<numItems;i++){ itemPath[i]=(char*)malloc(sizeof(char)*ARRAY_SIZE_NAME); } //read Items for(int i=0;i<numItems;i++){ fscanf(file,"%s", itemPath[i]); items[i]=readItem(itemPath[i]); } //fill Template* templ=(Template*)malloc(sizeof(Template)); templ->id=id; templ->type=type2; templ->numItems=numItems; templ->items=items; //free for(int i=0;i<numItems;i++){ free(itemPath[i]); } free(itemPath); fclose(file); return templ; }
int32_t Config::setConfInt(const string& name, int32_t default_value) { string value = readItem(name); int32_t v; if (value.empty()) v = default_value; else if (0 == isNumber(value.c_str())) v = atoi(value.c_str()); else return -1; if (v < 0) return -1; _conf_int[name] = v; return 0; }
void Dynamics::normalize() { double max = 0.0; for (int frame=0; frame<sfInfo.frames; frame++) { for (int channel=0; channel<sfInfo.channels; channel++) { double value = abs(readItem(frame, channel)); if (max < value) { max = value; } } } gainIntern(1.0/max); this->writeFile("_norm"); }
bool DescriptorList::load(IteratorBase *data) { int itemCount = data->getInt32(); items.reserve(itemCount); for (int i = 0; i < itemCount; i++) { DescriptorItem *item = readItem(data); if (item && item->isValid) { items.push_back(item); } else { // 解釈不能が出てきたら構造上スキップできないのでここで終了する if (item->isValid) { delete item; } isValid = false; break; } } return isValid; }
void InstanceParser::readData() { Q_ASSERT(isStartElement() && name() == "data"); while(!atEnd()) { readNext(); if(isEndElement()) break; if(isStartElement()) { if(name() == "bin") readBin(); else if(name() == "item") readItem(); else readUnknownElement(); } } }
// -------------------------------------------------------------------------- // ローダ // -------------------------------------------------------------------------- bool Descriptor::load(IteratorBase *data) { data->getUnicodeString(name); readId(data, classId); int itemCount = data->getInt32(); for (int i = 0; i < itemCount; i++) { std::string key; readId(data, key); DescriptorItem *item = readItem(data); if (item && item->isValid) { itemMap[key] = item; } else { // 解釈不能が出てきたら構造上スキップできないのでここで終了する if (item) { delete item; } isValid = false; break; } } return isValid; }
QM3uPlaylistReader(QIODevice *device) :m_ownDevice(false), m_device(device), m_textStream(new QTextStream(m_device)) { readItem(); }
void TrackingSyncSource::readItemRaw(const std::string &luid, std::string &item) { readItem(luid, item, true); }
void TrackingSyncSource::readItem(const std::string &luid, std::string &item) { readItem(luid, item, false); }
/// /// C-tor /// Armor::Armor(const char* filePath, bool isEquipped) : Item(filePath, ARMOR_ID, isEquipped) { readItem(filePath); }
bool PlaylistSaver::loadPLS(const KURL &file, int /*opt*/) { kdDebug(66666) << k_funcinfo << "file='" << file.path() << endl; QString localFile; if(!KIO::NetAccess::download(file, localFile, 0L)) return false; QFile checkFile(localFile); checkFile.open(IO_ReadOnly); QTextStream t(&checkFile); QString firstLine = t.readLine(); if(firstLine.lower() != "[playlist]") { kdDebug(66666) << k_funcinfo << "PLS didn't start with '[playlist]', aborting" << endl; return false; } KSimpleConfig list(localFile, true); //list.setGroup("playlist"); // some stupid Windows lusers like to be case insensitive QStringList groups = list.groupList().grep(QRegExp("^playlist$", false)); /* if (!groups.count()) // didn't find "[playlist]", it's not a .pls file return false; */ QMap<QString,QString> group = list.entryMap(groups[0]); QString numOfEntries = findNoCase(group, "numberofentries"); if(numOfEntries.isEmpty()) return false; reset(); unsigned int nEntries = numOfEntries.toInt(); for(unsigned int entry = 1; entry <= nEntries; ++entry ) { QString str; str.sprintf("file%d", entry); QString cast = findNoCase(group, str.utf8()); str.sprintf("title%d", entry); QString title = findNoCase(group, str.utf8()); // assume that everything in a pls is a streamable file QMap<QString,QString> map; KURL url(cast); if (!url.hasPath()) url.setPath("/"); map["playObject"]="SplayPlayObject"; if (title.isEmpty()) map["title"] = i18n("Stream from %1 (port: %2)").arg( url.host() ).arg( url.port() ); else map["title"] = i18n("Stream from %1, (ip: %2, port: %3)").arg( title ).arg( url.host() ).arg(url.port() ); map["url"] = map["stream_"]= url.url(); readItem(map); } return true; }
bool PlaylistSaver::metalist(const KURL &url) { kdDebug(66666) << k_funcinfo << "url=" << url.url() << endl; QString end=url.filename().right(3).lower(); /* if (end=="mp3" || end=="ogg") // we want to download streams only { kdDebug(66666) << k_funcinfo << "I can only load playlists" << endl; return false; } */ /* .wax audio/x-ms-wax Metafiles that reference Windows Media files with the .asf, .wma or .wax file extensions. .wvx video/x-ms-wvx Metafiles that reference Windows Media files with the .wma, .wmv, .wvx or .wax file extensions. .asx video/x-ms-asf Metafiles that reference Windows Media files with the .wma, .wax, .wmv, .wvx, .asf, or .asx file extensions. */ // it's actually a stream! if (end!="pls" && end!="m3u" && end!="wax" && // windows mediaplayer metafile end!="wvx" && // windows mediaplayer metafile end!="asx" && // windows mediaplayer metafile url.protocol().lower()=="http") { KMimeType::Ptr mimetype = KMimeType::findByURL(url); QString type=mimetype->name(); if (type!="application/octet-stream") return false; QMap<QString,QString> map; map["playObject"]="Arts::StreamPlayObject"; map["title"] = i18n("Stream from %1").arg(url.host()); KURL u(url); if (!u.hasPath()) u.setPath("/"); map["stream_"] = map["url"] = u.url(); reset(); readItem(map); return true; } // it is a pls, m3u or ms-media-player file by now if(loadXML(url, XMLPlaylist)) return true; if(loadXML(url,ASX)) return true; if(loadPLS(url)) return true; if(loadM3U(url)) return true; return false; }
bool PlaylistSaver::loadM3U(const KURL &file, int /*opt*/) { kdDebug(66666) << k_funcinfo << "file='" << file.path() << endl; QString localFile; if(!KIO::NetAccess::download(file, localFile, 0L)) return false; // if it's a PLS, transfer control, again (KIO bug?) #if 0 { KSimpleConfig list(local, true); list.setGroup("playlist"); // some stupid Windows lusers like to be case insensitive QStringList groups=list.groupList().grep(QRegExp("^playlist$", false)); if (groups.count()) { KURL l; l.setPath(local); return loadPLS(l); } } #endif QFile saver(localFile); saver.open(IO_ReadOnly); QTextStream t(&saver); bool isExt = false; // flag telling if we load an EXTM3U file QString filename; QString extinf; QMap<QString,QString> prop; reset(); while (!t.eof()) { if (isExt) { extinf = t.readLine(); if (!extinf.startsWith("#EXTINF:")) { // kdDebug(66666) << "EXTM3U extinf line != extinf, assuming it's a filename." << endl; filename = extinf; extinf=""; } else { filename = t.readLine(); // read in second line containing the filename } //kdDebug(66666) << "EXTM3U filename = '" << filename << "'" << endl; } else // old style m3u { filename = t.readLine(); } if (filename == "#EXTM3U") // on first line { // kdDebug(66666) << "FOUND '#EXTM3U' @ " << saver.at() << "." << endl; isExt=true; continue; // skip parsing the first (i.e. this) line } if (filename.isEmpty()) continue; if (filename.find(QRegExp("^[a-zA-Z0-9]+:/"))==0) { //kdDebug(66666) << k_funcinfo << "url filename = " << filename << endl; KURL protourl(filename); KMimeType::Ptr mimetype = KMimeType::findByURL(protourl); if (mimetype->name() != "application/octet-stream") { prop["url"] = filename; } else { prop["playObject"]="SplayPlayObject"; // Default title, might be overwritten by #EXTINF later prop["title"] = i18n("Stream from %1").arg(protourl.host()); if (!protourl.hasPath()) protourl.setPath("/"); prop["url"] = protourl.url(); prop["stream_"] = prop["url"]; } } else // filename that is not of URL style (i.e. NOT "proto:/path/somefile") { KURL u1; // we have to deal with a relative path if (filename.find('/')) { u1.setPath(file.path(0)); u1.setFileName(filename); } else { u1.setPath(filename); } prop["url"] = u1.url(); } // parse line of the following format: //#EXTINF:length,displayed_title if (isExt) { extinf.remove(0,8); // remove "#EXTINF:" //kdDebug(66666) << "EXTM3U extinf = '" << extinf << "'" << endl; int timeTitleSep = extinf.find(',', 0); int length = (extinf.left(timeTitleSep)).toInt(); if (length>0) prop["length"]=QString::number(length*1000); QString displayTitle=extinf.mid(timeTitleSep+1); if (!displayTitle.isEmpty()) { int artistTitleSep = displayTitle.find(" - ",0); if (artistTitleSep == -1) // no "artist - title" like format, just set it as title { prop["title"] = displayTitle; } else { prop["author"] = displayTitle.left(artistTitleSep); prop["title"] = displayTitle.mid(artistTitleSep+3); } /*kdDebug(66666) << "EXTM3U author/artist='" << prop["author"] << "', title='" << prop["title"] << "'" << endl;*/ } // END !displayTitle.isEmpty() } // END if(isExt) // kdDebug(66666) << k_funcinfo << "adding file '" << prop["url"] << "' to playlist" << endl; readItem(prop); prop.clear(); } // END while() KIO::NetAccess::removeTempFile(localFile); // kdDebug(66666) << k_funcinfo << "END" << endl; return true; }
/* * buildShDetDisp - Clears the existing contents of the ship detail * window and redraws it based on current known * ships. */ void buildShDetDisp(void) { ULONG itNum; USHORT num_comp=0, num_eng=0, num_life=0, num_wpn=0, num_elect=0; FeShip_t tmpShip; FeItem_t tmpItem; int compChar, engChar, lifeChar, photChar, blasChar, sensChar, shldChar, telepChar, tractChar; char workBuf[90], nameBuf[10], itType, location[15], tBuff[28], inst; /* Speed up output */ fl_freeze_form(fd_ShipDetailForm->ShipDetailForm); /* Clear the existing contents, if any */ fl_clear_browser(fd_ShipDetailForm->ShDetItem); compChar = (int) BIG_PART_CHAR[bp_computer]; engChar = (int) BIG_PART_CHAR[bp_engines]; lifeChar = (int) BIG_PART_CHAR[bp_lifeSupp]; photChar = (int) BIG_PART_CHAR[bp_photon]; blasChar = (int) BIG_PART_CHAR[bp_blaser]; sensChar = (int) BIG_PART_CHAR[bp_sensors]; shldChar = (int) BIG_PART_CHAR[bp_shield]; telepChar = (int) BIG_PART_CHAR[bp_teleport]; tractChar = (int) BIG_PART_CHAR[bp_tractor]; /* Loop for each known big item */ for (itNum=0; itNum < next_item; itNum++) { /* Make sure the item has been seen and is on the ship */ if (!readItem(&tmpItem, itNum)) { continue; } if ((tmpItem.last_seen != 0) && (tmpItem.where == LastShip) && !(tmpItem.flags & BF_ONPLAN)) { if (tmpItem.owner != 0) { strncpy(nameBuf, Player[tmpItem.owner].name, 9); nameBuf[9] = '\0'; } else { strcpy(nameBuf, "???"); } if (tmpItem.type != 0) { itType=tmpItem.type; } else { itType='?'; } /* Check if it is installed, or just cargo */ if (tmpItem.flags & BF_INSTALL) { /* Installed */ inst='Y'; /* Increment our running counts */ if (itType == tractChar) { num_comp++; } else if (itType == engChar) { num_eng++; } else if (itType == lifeChar) { num_life++; } else if ((itType == photChar) || (itType == blasChar)) { num_wpn++; } else if ((itType == sensChar) || (itType == shldChar) || (itType == telepChar) || (itType == tractChar)) { num_elect++; } } else { /* Not installed, just being carried */ inst=' '; } sprintf(workBuf, "%8u %c %3u %3u %5u %c", itNum, itType, tmpItem.it_tf, tmpItem.efficiency, tmpItem.weight, inst); fl_add_browser_line(fd_ShipDetailForm->ShDetItem, workBuf); } } /* read the ship in */ (void) readShip(&tmpShip, LastShip); /* Update using the counts we saw before */ tmpShip.num_comp = num_comp; tmpShip.num_eng = num_eng; tmpShip.num_life = num_life; tmpShip.num_wpn = num_wpn; tmpShip.num_elect = num_elect; /* Write ship back */ (void) writeShip(&tmpShip, LastShip); sprintf(workBuf, "%u", tmpShip.fuelLeft); fl_set_object_label(fd_ShipDetailForm->Fuel, workBuf); sprintf(workBuf, "%u", tmpShip.energy); fl_set_object_label(fd_ShipDetailForm->Energy, workBuf); sprintf(workBuf, "%u", tmpShip.armourLeft); fl_set_object_label(fd_ShipDetailForm->Armor, workBuf); sprintf(workBuf, "%u", tmpShip.shields); fl_set_object_label(fd_ShipDetailForm->Shields, workBuf); sprintf(workBuf, "%u", tmpShip.shieldsKeep); fl_set_object_label(fd_ShipDetailForm->ShKeep, workBuf); sprintf(workBuf, "%u", tmpShip.airLeft); fl_set_object_label(fd_ShipDetailForm->Air, workBuf); sprintf(workBuf, "%u", tmpShip.efficiency); fl_set_object_label(fd_ShipDetailForm->Effic, workBuf); sprintf(workBuf, "%u", tmpShip.sh_tf); fl_set_object_label(fd_ShipDetailForm->TF, workBuf); sprintf(workBuf, "%u", tmpShip.hullTF); fl_set_object_label(fd_ShipDetailForm->HullTF, workBuf); sprintf(workBuf, "%u", tmpShip.engTF); fl_set_object_label(fd_ShipDetailForm->EngTF, workBuf); sprintf(workBuf, "%u", tmpShip.engEff); fl_set_object_label(fd_ShipDetailForm->EngEff, workBuf); if (tmpShip.plagueStage != 0) { fl_set_object_label(fd_ShipDetailForm->Plague, "YES"); } else { fl_set_object_label(fd_ShipDetailForm->Plague, "NO"); } sprintf(workBuf, "%u", tmpShip.num_civ); fl_set_object_label(fd_ShipDetailForm->Civ, workBuf); sprintf(workBuf, "%u", tmpShip.num_sci); fl_set_object_label(fd_ShipDetailForm->Sci, workBuf); sprintf(workBuf, "%u", tmpShip.num_mil); fl_set_object_label(fd_ShipDetailForm->Mil, workBuf); sprintf(workBuf, "%u", tmpShip.num_ofc); fl_set_object_label(fd_ShipDetailForm->Ofc, workBuf); sprintf(workBuf, "%u", tmpShip.num_torp); fl_set_object_label(fd_ShipDetailForm->Torp, workBuf); sprintf(workBuf, "%u", tmpShip.num_ore); fl_set_object_label(fd_ShipDetailForm->Ore, workBuf); sprintf(workBuf, "%u", tmpShip.num_gold); fl_set_object_label(fd_ShipDetailForm->Bars, workBuf); sprintf(workBuf, "%u", tmpShip.num_airt); fl_set_object_label(fd_ShipDetailForm->AirTnk, workBuf); sprintf(workBuf, "%u", tmpShip.num_ftnk); fl_set_object_label(fd_ShipDetailForm->FuelTnk, workBuf); sprintf(workBuf, "%u", tmpShip.cargo); fl_set_object_label(fd_ShipDetailForm->Cargo, workBuf); strcpy(workBuf, ctime(&tmpShip.last_seen)); workBuf[24]='\0'; /* strip off NL */ fl_set_object_label(fd_ShipDetailForm->Seen, workBuf); sprintf(workBuf, "%u", LastShip); fl_set_object_label(fd_ShipDetailForm->ShNum, workBuf); sprintf(workBuf, "%u,%u", tmpShip.sh_row, tmpShip.sh_col); fl_set_object_label(fd_ShipDetailForm->RowCol, workBuf); if (tmpShip.owner != 0) { strcpy(workBuf, Player[tmpShip.owner].name); } else { strcpy(workBuf, "???"); } fl_set_object_label(fd_ShipDetailForm->Owner, workBuf); if (tmpShip.flags & BF_ONPLAN) { sprintf(workBuf, "Ship is on planet %u", tmpShip.planet); fl_set_object_label(fd_ShipDetailForm->Where, workBuf); } else { fl_set_object_label(fd_ShipDetailForm->Where, "Ship is in space"); } fl_unfreeze_form(fd_ShipDetailForm->ShipDetailForm); }
static PRBool blapi_SHVerifyFile(const char *shName, PRBool self) { char *checkName = NULL; PRFileDesc *checkFD = NULL; PRFileDesc *shFD = NULL; void *hashcx = NULL; const SECHashObject *hashObj = NULL; SECItem signature = { 0, NULL, 0 }; SECItem hash; int bytesRead, offset; SECStatus rv; DSAPublicKey key; int count; #ifdef FREEBL_USE_PRELINK int pid = 0; #endif PRBool result = PR_FALSE; /* if anything goes wrong, * the signature does not verify */ unsigned char buf[4096]; unsigned char hashBuf[HASH_LENGTH_MAX]; PORT_Memset(&key,0,sizeof(key)); hash.data = hashBuf; hash.len = sizeof(hashBuf); /* If our integrity check was never ran or failed, fail any other * integrity checks to prevent any token going into FIPS mode. */ if (!self && (BL_FIPSEntryOK(PR_FALSE) != SECSuccess)) { return PR_FALSE; } if (!shName) { goto loser; } /* figure out the name of our check file */ checkName = mkCheckFileName(shName); if (!checkName) { goto loser; } /* open the check File */ checkFD = PR_Open(checkName, PR_RDONLY, 0); if (checkFD == NULL) { #ifdef DEBUG_SHVERIFY fprintf(stderr, "Failed to open the check file %s: (%d, %d)\n", checkName, (int)PR_GetError(), (int)PR_GetOSError()); #endif /* DEBUG_SHVERIFY */ goto loser; } /* read and Verify the headerthe header */ bytesRead = PR_Read(checkFD, buf, 12); if (bytesRead != 12) { goto loser; } if ((buf[0] != NSS_SIGN_CHK_MAGIC1) || (buf[1] != NSS_SIGN_CHK_MAGIC2)) { goto loser; } if ((buf[2] != NSS_SIGN_CHK_MAJOR_VERSION) || (buf[3] < NSS_SIGN_CHK_MINOR_VERSION)) { goto loser; } #ifdef notdef if (decodeInt(&buf[8]) != CKK_DSA) { goto loser; } #endif /* seek past any future header extensions */ offset = decodeInt(&buf[4]); if (PR_Seek(checkFD, offset, PR_SEEK_SET) < 0) { goto loser; } /* read the key */ rv = readItem(checkFD,&key.params.prime); if (rv != SECSuccess) { goto loser; } rv = readItem(checkFD,&key.params.subPrime); if (rv != SECSuccess) { goto loser; } rv = readItem(checkFD,&key.params.base); if (rv != SECSuccess) { goto loser; } rv = readItem(checkFD,&key.publicValue); if (rv != SECSuccess) { goto loser; } /* read the siganture */ rv = readItem(checkFD,&signature); if (rv != SECSuccess) { goto loser; } /* done with the check file */ PR_Close(checkFD); checkFD = NULL; hashObj = HASH_GetRawHashObject(PQG_GetHashType(&key.params)); if (hashObj == NULL) { goto loser; } /* open our library file */ #ifdef FREEBL_USE_PRELINK shFD = bl_OpenUnPrelink(shName,&pid); #else shFD = PR_Open(shName, PR_RDONLY, 0); #endif if (shFD == NULL) { #ifdef DEBUG_SHVERIFY fprintf(stderr, "Failed to open the library file %s: (%d, %d)\n", shName, (int)PR_GetError(), (int)PR_GetOSError()); #endif /* DEBUG_SHVERIFY */ goto loser; } /* hash our library file with SHA1 */ hashcx = hashObj->create(); if (hashcx == NULL) { goto loser; } hashObj->begin(hashcx); count = 0; while ((bytesRead = PR_Read(shFD, buf, sizeof(buf))) > 0) { hashObj->update(hashcx, buf, bytesRead); count += bytesRead; } #ifdef FREEBL_USE_PRELINK bl_CloseUnPrelink(shFD, pid); #else PR_Close(shFD); #endif shFD = NULL; hashObj->end(hashcx, hash.data, &hash.len, hash.len); /* verify the hash against the check file */ if (DSA_VerifyDigest(&key, &signature, &hash) == SECSuccess) { result = PR_TRUE; } #ifdef DEBUG_SHVERIFY { int i,j; fprintf(stderr,"File %s: %d bytes\n",shName, count); fprintf(stderr," hash: %d bytes\n", hash.len); #define STEP 10 for (i=0; i < hash.len; i += STEP) { fprintf(stderr," "); for (j=0; j < STEP && (i+j) < hash.len; j++) { fprintf(stderr," %02x", hash.data[i+j]); } fprintf(stderr,"\n"); } fprintf(stderr," signature: %d bytes\n", signature.len); for (i=0; i < signature.len; i += STEP) { fprintf(stderr," "); for (j=0; j < STEP && (i+j) < signature.len; j++) { fprintf(stderr," %02x", signature.data[i+j]); } fprintf(stderr,"\n"); } fprintf(stderr,"Verified : %s\n",result?"TRUE": "FALSE"); } #endif /* DEBUG_SHVERIFY */ loser: if (checkName != NULL) { PORT_Free(checkName); } if (checkFD != NULL) { PR_Close(checkFD); } if (shFD != NULL) { PR_Close(shFD); } if (hashcx != NULL) { if (hashObj) { hashObj->destroy(hashcx,PR_TRUE); } } if (signature.data != NULL) { PORT_Free(signature.data); } if (key.params.prime.data != NULL) { PORT_Free(key.params.prime.data); } if (key.params.subPrime.data != NULL) { PORT_Free(key.params.subPrime.data); } if (key.params.base.data != NULL) { PORT_Free(key.params.base.data); } if (key.publicValue.data != NULL) { PORT_Free(key.publicValue.data); } return result; }