summaryrefslogtreecommitdiff
path: root/csvncgi/ui-repolist.c
diff options
context:
space:
mode:
authorkx <kx@radix.pro>2023-03-24 03:55:33 +0300
committerkx <kx@radix.pro>2023-03-24 03:55:33 +0300
commitbfc1508d26c89c9a36d2d9a827fe2c4ed128884d (patch)
tree8d41298a7072a3e289e4912f77ece75cbea1bd54 /csvncgi/ui-repolist.c
parentc836ae3775cf72f17e0b7e3792d156fdb389bee3 (diff)
downloadcsvn-ui-bfc1508d26c89c9a36d2d9a827fe2c4ed128884d.tar.xz
Version 0.1.4
Diffstat (limited to 'csvncgi/ui-repolist.c')
-rw-r--r--csvncgi/ui-repolist.c300
1 files changed, 300 insertions, 0 deletions
diff --git a/csvncgi/ui-repolist.c b/csvncgi/ui-repolist.c
new file mode 100644
index 0000000..44795c2
--- /dev/null
+++ b/csvncgi/ui-repolist.c
@@ -0,0 +1,300 @@
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/sysinfo.h>
+#include <sys/types.h>
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#else
+#include <stdint.h>
+#endif
+#include <stddef.h> /* offsetof(3) */
+#include <dirent.h>
+#include <sys/stat.h> /* chmod(2) */
+#include <sys/file.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <string.h> /* strdup(3) */
+#include <libgen.h> /* basename(3) */
+#include <ctype.h> /* tolower(3) */
+#include <errno.h>
+#include <time.h>
+#include <sys/time.h>
+#include <pwd.h>
+#include <grp.h>
+#include <stdarg.h>
+#include <locale.h>
+#include <unistd.h>
+
+#include <nls.h>
+
+#include <defs.h>
+
+#include <fatal.h>
+#include <http.h>
+#include <html.h>
+
+#include <dlist.h>
+#include <strbuf.h>
+#include <repolist.h>
+#include <wrapper.h>
+#include <system.h>
+#include <date.h>
+
+#include <ctx.h>
+#include <ui-shared.h>
+#include <ui-repolist.h>
+
+
+
+void csvn_print_direction( struct strbuf *sb, int prev, int next )
+{
+ strbuf_addf( sb, " <div class=\"direction\">\n" );
+ strbuf_addf( sb, " <div class=\"row\">\n" );
+ strbuf_addf( sb, " <div class=\"left col-prev\">\n" );
+ strbuf_addf( sb, " <div class=\"prev-direction\">\n" );
+
+ if( prev )
+ {
+ if( ctx.env.query_string && *ctx.env.query_string )
+ strbuf_addf( sb, " <a href=\"%s?ofs=%d&%s\">&#x226a;&nbsp; Prev</a>\n", ctx.repo.relative_href, prev, ctx.env.query_string );
+ else
+ strbuf_addf( sb, " <a href=\"%s?ofs=%d\">&#x226a;&nbsp; Prev</a>\n", ctx.repo.relative_href, prev );
+ }
+ else
+ {
+ if( ctx.env.query_string && *ctx.env.query_string )
+ strbuf_addf( sb, " <a href=\"%s?%s\">&#x226a;&nbsp; Prev</a>\n", ctx.repo.relative_href, ctx.env.query_string );
+ else
+ strbuf_addf( sb, " <a href=\"%s\">&#x226a;&nbsp; Prev</a>\n", ctx.repo.relative_href );
+ }
+
+ strbuf_addf( sb, " </div>\n" );
+ strbuf_addf( sb, " </div>\n" );
+ strbuf_addf( sb, " <div class=\"right col-next\">\n" );
+ strbuf_addf( sb, " <div class=\"next-direction\">\n" );
+
+ if( next )
+ {
+ if( ctx.env.query_string && *ctx.env.query_string )
+ strbuf_addf( sb, " <a href=\"%s?ofs=%d&%s\">Next &nbsp;&#x226b;</a>\n", ctx.repo.relative_href, next, ctx.env.query_string );
+ else
+ strbuf_addf( sb, " <a href=\"%s?ofs=%d\">Next &nbsp;&#x226b;</a>\n", ctx.repo.relative_href, next );
+ }
+ else
+ {
+ if( ctx.env.query_string && *ctx.env.query_string )
+ strbuf_addf( sb, " <a href=\"%s?%s\">Next &nbsp;&#x226b;</a>\n", ctx.repo.relative_href, ctx.env.query_string );
+ else
+ strbuf_addf( sb, " <a href=\"%s\">Next &nbsp;&#x226b;</a>\n", ctx.repo.relative_href );
+ }
+
+ strbuf_addf( sb, " </div>\n" );
+ strbuf_addf( sb, " </div>\n" );
+ strbuf_addf( sb, " </div>\n" );
+ strbuf_addf( sb, " </div>\n" );
+}
+
+void csvn_print_repolist_header( struct strbuf *sb )
+{
+ strbuf_addf( sb, " <div class=\"repo-list-header\">\n" );
+ strbuf_addf( sb, " <div class=\"row\">\n" );
+ strbuf_addf( sb, " <div class=\"col-name\">Name</div>\n" );
+ strbuf_addf( sb, " <div class=\"col-desc\">Description</div>\n" );
+ strbuf_addf( sb, " <div class=\"col-owner\"><div class=\"repo-owner trunc\">Owner</div></div>\n" );
+ strbuf_addf( sb, " <div class=\"col-rev\"><div class=\"repo-rev trunc\">Rev</div></div>\n" );
+ strbuf_addf( sb, " <div class=\"col-idle\"><div class=\"repo-idle trunc\">Idle</div></div>\n" );
+ strbuf_addf( sb, " </div>\n" );
+ strbuf_addf( sb, " </div>\n" );
+}
+
+void csvn_print_section_start( struct strbuf *sb, const char *name )
+{
+ if( !sb ) return;
+
+ strbuf_addf( sb, " <div class=\"section\">\n" );
+ if( name && *name )
+ strbuf_addf( sb, " <div class=\"section-header\">%s</div>\n\n", name );
+ else
+ strbuf_addf( sb, " <div class=\"section-header\"></div>\n\n" );
+}
+
+void csvn_print_section_stop( struct strbuf *sb )
+{
+ if( !sb ) return;
+ strbuf_addf( sb, " </div> <!-- end of section -->\n\n" );
+}
+
+void csvn_print_repo( struct strbuf *sb, struct repo *repo )
+{
+ struct variable owner = { (unsigned char *)"owner", { 0 }, DT_STRING },
+ description = { (unsigned char *)"description", { 0 }, DT_STRING };
+ struct variable *auth = NULL;
+ struct variable *desc = NULL;
+
+ struct strbuf buf = STRBUF_INIT;
+ size_t revision = csvn_repo_last_changed_revision( &buf, repo );
+
+ time_t time = 0;
+
+ if( !sb || !repo || !repo->path ) return;
+
+ auth = lookup( repo, &owner );
+ desc = lookup( repo, &description );
+ time = csvn_repo_last_changed_time( repo );
+
+ strbuf_addf( sb, " <div class=\"row\">\n" );
+ strbuf_addf( sb, " <div class=\"col-name\"><a href=\"/%s/\"><div class=\"repo-name\">%s</div></a></div>\n", repo->path, repo->path );
+
+ if( desc )
+ strbuf_addf( sb, " <div class=\"col-desc\"><div onclick=\"trunc(this)\" class=\"repo-desc trunc\">%s</div></div>\n", (const char *)desc->_v.vptr );
+ else
+ strbuf_addf( sb, " <div class=\"col-desc\"><div onclick=\"trunc(this)\" class=\"repo-desc trunc\">none</div></div>\n" );
+
+ if( auth )
+ strbuf_addf( sb, " <div class=\"col-owner\"><div onclick=\"trunc(this)\" class=\"repo-owner trunc\">%s</div></div>\n", (const char *)auth->_v.vptr );
+ else
+ strbuf_addf( sb, " <div class=\"col-owner\"><div onclick=\"trunc(this)\" class=\"repo-owner trunc\">none</div></div>\n" );
+
+ if( revision )
+ strbuf_addf( sb, " <div class=\"col-rev\"><div onclick=\"trunc(this)\" class=\"repo-rev trunc\">%s</div></div>\n", buf.buf );
+ else
+ strbuf_addf( sb, " <div class=\"col-rev\"><div onclick=\"trunc(this)\" class=\"repo-rev trunc\">%s</div></div>\n", "0" );
+
+ strbuf_release( &buf );
+
+ if( time != -1 )
+ {
+ struct strbuf buf = STRBUF_INIT;
+ csvn_print_age( &buf, time, 0, TM_YEAR );
+ strbuf_addf( sb, " <div class=\"col-idle\"><div onclick=\"trunc(this)\" class=\"repo-idle trunc\">%s</div></div>\n", buf.buf );
+ strbuf_release( &buf );
+ }
+ else
+ strbuf_addf( sb, " <div class=\"col-idle\"><div onclick=\"trunc(this)\" class=\"repo-idle trunc\">%s</div></div>\n", "unknown" );
+
+ strbuf_addf( sb, " </div>\n\n" );
+}
+
+
+int csvn_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 );
+
+ csvn_print_section_start( sb, (const char *)section->name );
+
+ while( rlist )
+ {
+ struct repo *repo = (struct repo *)rlist->data;
+
+ csvn_print_repo( sb, repo );
+ if( n && ++length == n )
+ {
+ csvn_print_section_stop( sb );
+ return length;
+ }
+
+ rlist = dlist_next( rlist );
+ }
+ csvn_print_section_stop( sb );
+ }
+ list = dlist_next( list );
+ }
+
+ while( list )
+ {
+ struct section *section = (struct section *)list->data;
+
+ if( section->type == ST_REPOS )
+ {
+ csvn_print_section_start( sb, (const char *)section->name );
+
+ struct dlist *rlist = section->list;
+ while( rlist )
+ {
+ struct repo *repo = (struct repo *)rlist->data;
+
+ csvn_print_repo( sb, repo );
+ if( n && ++length == n )
+ {
+ csvn_print_section_stop( sb );
+ return length;
+ }
+
+ rlist = dlist_next( rlist );
+ }
+
+ csvn_print_section_stop( sb );
+ }
+ list = dlist_next( list );
+ }
+
+ return length;
+}
+
+
+void csvn_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, " <div class=\"content segment\">\n" );
+ strbuf_addf( &buf, " <div class=\"container\">\n" );
+ strbuf_addf( &buf, " <div class=\"csvn-main-content\">\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;
+
+ csvn_print_repolist_header( &buf );
+ (void)csvn_print_page_repolist( &buf, config, pos, psize );
+ csvn_print_direction( &buf, prev, next );
+
+ strbuf_addf( &buf, " </div> <!-- End of csvn-main-content -->\n" );
+ strbuf_addf( &buf, " </div> <!-- End of container -->\n" );
+ strbuf_addf( &buf, " </div> <!-- End of content segment -->\n" );
+
+ fp = xfopen( ctx.page.footer, "r" );
+ (void)strbuf_env_fread( &buf, fp );
+ fclose( fp );
+
+ ctx.page.size = buf.len;
+ csvn_print_http_headers();
+ strbuf_write( &buf, STDOUT_FILENO );
+ strbuf_release( &buf );
+}