#ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #ifdef HAVE_INTTYPES_H #include #else #include #endif #include /* offsetof(3) */ #include #include /* chmod(2) */ #include #include #include #include #include /* strdup(3) */ #include /* basename(3) */ #include /* tolower(3) */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void cgit_print_direction( struct strbuf *sb, int prev, int next ) { strbuf_addf( sb, "
\n" ); strbuf_addf( sb, "
\n" ); strbuf_addf( sb, "
\n" ); strbuf_addf( sb, "
\n" ); if( prev ) { if( ctx.env.query_string && *ctx.env.query_string ) strbuf_addf( sb, " ≪  Prev\n", ctx.repo.relative_href, prev, ctx.env.query_string ); else strbuf_addf( sb, " ≪  Prev\n", ctx.repo.relative_href, prev ); } else { if( ctx.env.query_string && *ctx.env.query_string ) strbuf_addf( sb, " ≪  Prev\n", ctx.repo.relative_href, ctx.env.query_string ); else strbuf_addf( sb, " ≪  Prev\n", ctx.repo.relative_href ); } strbuf_addf( sb, "
\n" ); strbuf_addf( sb, "
\n" ); strbuf_addf( sb, "
\n" ); strbuf_addf( sb, "
\n" ); if( next ) { if( ctx.env.query_string && *ctx.env.query_string ) strbuf_addf( sb, " Next  ≫\n", ctx.repo.relative_href, next, ctx.env.query_string ); else strbuf_addf( sb, " Next  ≫\n", ctx.repo.relative_href, next ); } else { if( ctx.env.query_string && *ctx.env.query_string ) strbuf_addf( sb, " Next  ≫\n", ctx.repo.relative_href, ctx.env.query_string ); else strbuf_addf( sb, " Next  ≫\n", ctx.repo.relative_href ); } strbuf_addf( sb, "
\n" ); strbuf_addf( sb, "
\n" ); strbuf_addf( sb, "
\n" ); strbuf_addf( sb, "
\n" ); } void cgit_print_repolist_header( struct strbuf *sb ) { strbuf_addf( sb, "
\n" ); strbuf_addf( sb, "
\n" ); strbuf_addf( sb, "
Name
\n" ); strbuf_addf( sb, "
Description
\n" ); strbuf_addf( sb, "
Owner
\n" ); strbuf_addf( sb, "
Rev
\n" ); strbuf_addf( sb, "
Idle
\n" ); strbuf_addf( sb, "
\n" ); strbuf_addf( sb, "
\n" ); } void cgit_print_section_start( struct strbuf *sb, const char *name ) { if( !sb ) return; strbuf_addf( sb, "
\n" ); if( name && *name ) strbuf_addf( sb, "
%s
\n\n", name ); else strbuf_addf( sb, "
\n\n" ); } void cgit_print_section_stop( struct strbuf *sb ) { if( !sb ) return; strbuf_addf( sb, "
\n\n" ); } void cgit_print_repo( struct strbuf *sb, struct repo *repo ) { struct variable git_root = { (unsigned char *)"git-root", { 0 }, DT_PATH }, repo_root = { (unsigned char *)"repo-root", { 0 }, DT_PATH }, owner = { (unsigned char *)"owner", { 0 }, DT_STRING }, description = { (unsigned char *)"description", { 0 }, DT_STRING }; struct variable *groot = NULL; struct variable *rroot = NULL; struct variable *auth = NULL; struct variable *desc = NULL; struct short_commit_info info = { .rev = { 0 }, .date = -1, .offset = 0 }; char path[PATH_MAX] = { 0 }; if( !sb || !repo || !repo->path ) return; groot = lookup( repo, &git_root ); rroot = lookup( repo, &repo_root ); auth = lookup( repo, &owner ); desc = lookup( repo, &description ); if( rroot ) sprintf( path, "%s/%s/%s", (const char *)groot->_v.vptr, (const char *)rroot->_v.vptr, repo->path ); else sprintf( path, "%s/%s", (const char *)groot->_v.vptr, repo->path ); fill_short_commit_info( &info, (const char *)&path[0] ); strbuf_addf( sb, "
\n" ); if( rroot ) strbuf_addf( sb, " \n", (const char *)rroot->_v.vptr, repo->path, repo->path ); else strbuf_addf( sb, " \n", repo->path, repo->path ); if( desc ) strbuf_addf( sb, "
%s
\n", (const char *)desc->_v.vptr ); else strbuf_addf( sb, "
none
\n" ); if( auth ) strbuf_addf( sb, "
%s
\n", (const char *)auth->_v.vptr ); else strbuf_addf( sb, "
none
\n" ); if( info.rev[0] ) strbuf_addf( sb, "
%0.8s
\n", (const char *)&info.rev[0], (const char *)&info.rev[0] ); else strbuf_addf( sb, "
%s
\n", "0" ); if( info.date != -1 ) { struct strbuf buf = STRBUF_INIT; cgit_print_age( &buf, (time_t)info.date, info.offset, TM_YEAR ); strbuf_addf( sb, "
%s
\n", buf.buf ); strbuf_release( &buf ); } else strbuf_addf( sb, "
%s
\n", "unknown" ); strbuf_addf( sb, "
\n\n" ); } int cgit_print_page_repolist( struct strbuf *sb, struct dlist *config, int start_no, int n ) { struct dlist *list = NULL; int length = 0; if( !config || !sb ) return length; list = config; if( start_no > 0 ) { list = parent_section_node_repolist_nth( config, start_no ); { struct section *section = (struct section *)list->data; struct dlist *rlist = parent_rlist_node_repolist_nth( config, start_no ); cgit_print_section_start( sb, (const char *)section->name ); while( rlist ) { struct repo *repo = (struct repo *)rlist->data; cgit_print_repo( sb, repo ); if( n && ++length == n ) { cgit_print_section_stop( sb ); return length; } rlist = dlist_next( rlist ); } cgit_print_section_stop( sb ); } list = dlist_next( list ); } while( list ) { struct section *section = (struct section *)list->data; if( section->type == ST_REPOS ) { cgit_print_section_start( sb, (const char *)section->name ); struct dlist *rlist = section->list; while( rlist ) { struct repo *repo = (struct repo *)rlist->data; cgit_print_repo( sb, repo ); if( n && ++length == n ) { cgit_print_section_stop( sb ); return length; } rlist = dlist_next( rlist ); } cgit_print_section_stop( sb ); } list = dlist_next( list ); } return length; } void cgit_print_repolist_page( void ) { FILE *fp; struct strbuf buf = STRBUF_INIT; int psize = 200, rnum = 0, pos = 0, prev, next; fp = xfopen( ctx.page.header, "r" ); (void)strbuf_env_fread( &buf, fp ); fclose( fp ); strbuf_addf( &buf, "
\n" ); strbuf_addf( &buf, "
\n" ); strbuf_addf( &buf, "
\n" ); if( ctx.vars.page_size && *ctx.vars.page_size ) sscanf( ctx.vars.page_size, "%d", &psize ); if( ctx.vars.num_of_repos && *ctx.vars.num_of_repos ) sscanf( ctx.vars.num_of_repos, "%d", &rnum ); if( ctx.query.ofs > 0) pos = ctx.query.ofs; if( ctx.query.ofs > rnum-1 ) pos = rnum - rnum % psize; if( pos < 0 ) pos = 0; prev = pos - psize; if( prev < 0 ) prev = 0; next = pos + psize; if( next > rnum-1 ) next = rnum - rnum % psize; if( next < 0 ) next = 0; cgit_print_repolist_header( &buf ); (void)cgit_print_page_repolist( &buf, config, pos, psize ); cgit_print_direction( &buf, prev, next ); strbuf_addf( &buf, "
\n" ); strbuf_addf( &buf, "
\n" ); strbuf_addf( &buf, "
\n" ); fp = xfopen( ctx.page.footer, "r" ); (void)strbuf_env_fread( &buf, fp ); fclose( fp ); ctx.page.size = buf.len; cgit_print_http_headers(); strbuf_write( &buf, STDOUT_FILENO ); strbuf_release( &buf ); }