printpkgicon: check if package has Changelog instead of segfaulting if not

printpkgicon: use new function htmlcleanNoBr() to work correctly as title= descriptions
This commit is contained in:
Silvan Calarco 2012-04-15 14:41:31 +02:00
parent b1d3e0b22d
commit 452fcef5f0
4 changed files with 37 additions and 10 deletions

View File

@ -262,6 +262,31 @@ char *htmlclean(char *source,char *dest,unsigned int max)
return dest;
}
char *htmlcleanNoBr(char *source,char *dest,unsigned int max)
{
unsigned int i=0,j=0;
char subst[10];
while (source[i] && i<max) {
switch (source[i]) {
case '<': strcpy(subst,"&lt;"); break;
case '>': strcpy(subst,"&gt;"); break;
case '&': strcpy(subst,"&amp;"); break;
case '"': strcpy(subst,"&quot;"); break;
default: subst[0]=source[i]; subst[1]='\0'; break;
}
if (j+strlen(subst)<max) {
strcpy((char*)&dest[j],subst);
j+=strlen(subst);
} else {
fprintf(stderr,"Warning: can't tidy HTML string due to limited buffer.\n");
return source;
}
i++;
}
return dest;
}
/*
scansdir is like scandir with the difference that it uses stat()
to get entry file types

View File

@ -31,6 +31,7 @@ humanDate *simpleTimeToHuman(long calendartime, humanDate * strdate);
char *humanSize(long long sbytes, sizeString *s);
void fprintf_depstable_filtered_var(FILE* f,char* st);
char *htmlclean(char *source,char *dest,unsigned int max);
char *htmlcleanNoBr(char *source,char *dest,unsigned int max);
int scansdir(const char *dir, struct dirent ***namelist,
int (*select)(const struct dirent *),
int (*compar)(const struct dirent **, const struct dirent **));

View File

@ -18,7 +18,7 @@
int comparePackagers(const void *ptr1, const void *ptr2);
int generateMaintainersPages(struct configTag *configtag);
int printHTMLWarnings(FILE *fout,struct configTag *configtag, struct headerSourceList* pkg, int mode);
void printpkgicon(FILE *fout, struct configTag *configtag, struct headerSourceList *s, int descr );
void printpkgicon(FILE *fout, struct configTag *configtag, struct headerSourceList *s);
int generateStats(struct configTag *configtag,int arch);
int cleanHTMLFilesInc(char* dir);
int cleanHTMLFiles(struct configTag *ct);

View File

@ -147,12 +147,12 @@ printHTMLWarnings(FILE *fout,struct configTag *configtag, struct headerSourceLis
return 0;
}
void printpkgicon(FILE *fout, struct configTag *configtag, struct headerSourceList *s, int descr ) {
void printpkgicon(FILE *fout, struct configTag *configtag, struct headerSourceList *s) {
char buffer[PATH_MAX];
char strdate[16];
if (descr) {
if (s->changelog) {
simpleTimeToHuman(s->changelog->time, (humanDate *) & strdate);
if (s->updrepository >= 0) {
fprintf(fout,
@ -161,7 +161,7 @@ void printpkgicon(FILE *fout, struct configTag *configtag, struct headerSourceLi
strdate,
s->changelog->pkg->name,
s->changelog->release,
htmlclean(s->changelog->text,buffer,PATH_MAX),
htmlcleanNoBr(s->changelog->text,buffer,PATH_MAX),
configtag->repository[s->updrepository]->tag);
} else {
fprintf(fout,
@ -170,16 +170,17 @@ void printpkgicon(FILE *fout, struct configTag *configtag, struct headerSourceLi
strdate,
s->changelog->pkg->name,
s->changelog->release,
htmlclean(s->changelog->text,buffer,PATH_MAX));
htmlcleanNoBr(s->changelog->text,buffer,PATH_MAX));
}
} else {
if (s->updrepository >= 0) {
fprintf(fout,
"<img src=\"%s/pkgup.png\">",
configtag->configdefaults->url_dir);
"<img src=\"%s/pkgup.png\" title=\"WARNING: missing changelog\n\nUpdates package in %s\">",
configtag->configdefaults->url_dir,
configtag->repository[s->updrepository]->tag);
} else {
fprintf(fout,
"<img src=\"%s/pkg.png\">",
"<img src=\"%s/pkg.png\" title=\"WARNING: missing changelog\">",
configtag->configdefaults->url_dir);
}
}
@ -548,7 +549,7 @@ generateStats(struct configTag *configtag,int arch)
}
if (i < HTMLSTATS_NUM) {
// HTML statistics
printpkgicon(htmlout, configtag, (configtag->stats.headersourcelistvec)[i],1);
printpkgicon(htmlout, configtag, (configtag->stats.headersourcelistvec)[i]);
fprintf(htmlout,
"<a href=\"%stag=%s&amp;pkg=%s.source\" title=\"%s\">%s %s %s-%s</a>&nbsp;",
configtag->configdefaults->url_prefix,
@ -1083,7 +1084,7 @@ generateHTML_SRPMSFiles(struct configTag *configtag)
fprintf(findexout[idx],"</td></tr>");
}
fprintf(findexout[idx],"<tr><td>");
printpkgicon(findexout[idx], configtag, currheadersourcelist,1);
printpkgicon(findexout[idx], configtag, currheadersourcelist);
fprintf(findexout[idx],"</td><td><b>%s</b>: <i>%s</i>",currheadersourcelist->name,htmlclean(currheadersourcelist->summary,buffer,PATH_MAX));
st=strstr(currheadersourcelist->url,"://");
if (st) {