/* * rdf.c : implementation for the RDF encoding/decoding of RPM informations. */ #include "config.h" #ifdef HAVE_FCNTL_H #include #endif #include #include #include #ifdef HAVE_UNISTD_H #include #endif #include #include #include #include "rpm2html.h" #include "rpmdata.h" #include "html.h" #include "rdf_api.h" #include "rdf.h" /* * Open an RDF file call the parser to create a XML tree * Then walk the tree and build an rpmData structure for * the corresponding package. */ rpmDataPtr rpmOpenRdf(char *nameRpm, rpmDirPtr dir, rpmSubdirPtr tree) { return(NULL); } /* * Create and RDF file containing the description for the given RPM data. */ void dumpRpmRdf(rpmDataPtr rpm, rpmSubdirPtr tree) { struct tm * tstruct; rpmDirPtr dir = rpm->dir; char *base = dir->dir; int i; char buf[10000]; char file[1000]; rdfSchema rdf; rdfNamespace rpmNs; rdfDescription desc; rdfBag bag; if (rpm2html_rdf_dir != NULL) base = rpm2html_rdf_dir; if ((dir->subdir != NULL) && (dir->subdir[0] != '\0')) { if ((rpm->subdir != NULL) && (rpm->subdir[0] != '\0')) sprintf(file, "%s/%s/%s/%s.rdf", base, dir->subdir, rpm->subdir, rpmName(rpm)); else sprintf(file, "%s/%s/%s.rdf", base, dir->subdir, rpmName(rpm)); } else { if ((rpm->subdir != NULL) && (rpm->subdir[0] != '\0')) sprintf(file, "%s/%s/%s.rdf", base, rpm->subdir, rpmName(rpm)); else sprintf(file, "%s/%s.rdf", base, rpmName(rpm)); } if (checkDate(file, rpm->stamp)) return; if (verbose > 1) { printf("Dumping %s\n", file); } /* * build the RDF document tree * Note : the order is not important but following the rpmData * structure order is easier to check. */ rdf = rdfNewSchema(); rpmNs = rdfNewNamespace(rdf, "http://www.rpm.org/", "RPM"); if ((rpm->subdir != NULL) && (rpm->subdir[0] != '\0')) { if (dir->mirrors[0] != NULL) sprintf(buf, "%s/%s/%s", dir->mirrors[0], rpm->subdir, rpm->filename); else sprintf(buf, "%s/%s/%s", dir->ftp, rpm->subdir, rpm->filename); } else { if (dir->mirrors[0] != NULL) sprintf(buf, "%s/%s", dir->mirrors[0], rpm->filename); else sprintf(buf, "%s/%s", dir->ftp, rpm->filename); } desc = rdfAddDescription(rdf, NULL, buf); rdfSetValue(desc, "Name", rpmNs, rpm->name); rdfSetValue(desc, "Version", rpmNs, rpm->version); rdfSetValue(desc, "Release", rpmNs, rpm->release); if (rpm->url) rdfSetValue(desc, "URL", rpmNs, rpm->url); if (rpm->arch) rdfSetValue(desc, "Arch", rpmNs, rpm->arch); if (rpm->os) rdfSetValue(desc, "Os", rpmNs, rpm->os); if (rpm->distribution) rdfSetValue(desc, "Distribution", rpmNs, rpm->distribution); if (rpm->vendor) rdfSetValue(desc, "Vendor", rpmNs, rpm->vendor); if (rpm->packager) rdfSetValue(desc, "Packager", rpmNs, rpm->packager); if (rpm->group) rdfSetValue(desc, "Group", rpmNs, rpm->group); if (rpm->summary) rdfSetValue(desc, "Summary", rpmNs, rpm->summary); if (rpm->description) rdfSetValue(desc, "Description", rpmNs, rpm->description); if (rpm->copyright) rdfSetValue(desc, "Copyright", rpmNs, rpm->copyright); if (rpm->changelog) rdfSetValue(desc, "Changelog", rpmNs, rpm->changelog); if (rpm->srcrpm) { if (dir->ftpsrc) { sprintf(buf, "%s/%s", dir->ftpsrc, rpm->srcrpm); rdfSetValue(desc, "Sources", rpmNs, buf); } else { rdfSetValue(desc, "Sources", rpmNs, rpm->srcrpm); } } tstruct = localtime(&(rpm->date)); #ifdef HAVE_STRFTIME strftime(buf, sizeof(buf) - 1, "%c", tstruct); #else #error "no strftime, please check !" #endif rdfSetValue(desc, "BuildDate", rpmNs, buf); sprintf(buf, "%d", rpm->size); rdfSetValue(desc, "Size", rpmNs, buf); if (rpm->host) rdfSetValue(desc, "BuildHost", rpmNs, rpm->host); if (rpm->nb_resources > 0) { bag = rdfBagCreate(rdf, desc, "Provides", rpmNs); for (i = 0;i < rpm->nb_resources;i++) { rdfBagAddValue(bag, "Resource", rpmNs, rpm->resources[i]->name, NULL); } } if (rpm->nb_requires > 0) { bag = rdfBagCreate(rdf, desc, "Requires", rpmNs); for (i = 0;i < rpm->nb_requires;i++) { rdfBagAddValue(bag, "Resource", rpmNs, rpm->requires[i]->name, NULL); } } if (rpm->filelist) rdfSetValue(desc, "Files", rpmNs, rpm->filelist); /* * Save the RDF file and cleanup the tree. */ rdfWrite(rdf, file); rdfDestroySchema(rdf); }