cSvn-UI for SVN Repositories

cGit-UI – is a web interface for Subversion (SVN) Repositories. cSvn CGI script is writen in C and therefore it's fast enough

6 Commits   0 Branches   2 Tags
bfc1508d (kx 2023-03-24 03:55:33 +0300   1) 
bfc1508d (kx 2023-03-24 03:55:33 +0300   2) #ifdef HAVE_CONFIG_H
bfc1508d (kx 2023-03-24 03:55:33 +0300   3) #include <config.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300   4) #endif
bfc1508d (kx 2023-03-24 03:55:33 +0300   5) 
bfc1508d (kx 2023-03-24 03:55:33 +0300   6) #include <stdlib.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300   7) #include <stdio.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300   8) #include <sys/sysinfo.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300   9) #include <sys/types.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  10) #ifdef HAVE_INTTYPES_H
bfc1508d (kx 2023-03-24 03:55:33 +0300  11) #include <inttypes.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  12) #else
bfc1508d (kx 2023-03-24 03:55:33 +0300  13) #include <stdint.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  14) #endif
bfc1508d (kx 2023-03-24 03:55:33 +0300  15) #include <stddef.h>   /* offsetof(3) */
bfc1508d (kx 2023-03-24 03:55:33 +0300  16) #include <dirent.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  17) #include <sys/stat.h> /* chmod(2)    */
bfc1508d (kx 2023-03-24 03:55:33 +0300  18) #include <sys/file.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  19) #include <sys/mman.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  20) #include <fcntl.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  21) #include <limits.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  22) #include <string.h>   /* strdup(3)   */
bfc1508d (kx 2023-03-24 03:55:33 +0300  23) #include <libgen.h>   /* basename(3) */
bfc1508d (kx 2023-03-24 03:55:33 +0300  24) #include <ctype.h>    /* tolower(3)  */
bfc1508d (kx 2023-03-24 03:55:33 +0300  25) #include <errno.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  26) #include <time.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  27) #include <sys/time.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  28) #include <pwd.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  29) #include <grp.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  30) #include <stdarg.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  31) #include <locale.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  32) #include <unistd.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  33) 
bfc1508d (kx 2023-03-24 03:55:33 +0300  34) #include <nls.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  35) 
bfc1508d (kx 2023-03-24 03:55:33 +0300  36) #include <defs.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  37) 
bfc1508d (kx 2023-03-24 03:55:33 +0300  38) #include <fatal.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  39) #include <http.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  40) #include <html.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  41) 
bfc1508d (kx 2023-03-24 03:55:33 +0300  42) #include <dlist.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  43) #include <strbuf.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  44) #include <repolist.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  45) #include <wrapper.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  46) #include <system.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  47) #include <date.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  48) 
bfc1508d (kx 2023-03-24 03:55:33 +0300  49) #include <ctx.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  50) #include <ui-shared.h>
bfc1508d (kx 2023-03-24 03:55:33 +0300  51) 
bfc1508d (kx 2023-03-24 03:55:33 +0300  52) 
bfc1508d (kx 2023-03-24 03:55:33 +0300  53) static void csvn_print_diff( struct strbuf *sb, const char *relative_path, int revision )
bfc1508d (kx 2023-03-24 03:55:33 +0300  54) {
bfc1508d (kx 2023-03-24 03:55:33 +0300  55)   const char *co_prefix = ctx.repo.checkout_ro_prefix;
c7693c71 (kx 2023-04-12 19:21:06 +0300  56)   const char *name      = ctx.repo.name;
c7693c71 (kx 2023-04-12 19:21:06 +0300  57)   const char *repo_root = ctx.repo.repo_root;
bfc1508d (kx 2023-03-24 03:55:33 +0300  58) 
bfc1508d (kx 2023-03-24 03:55:33 +0300  59)   if( !sb || !relative_path || !revision ) return;
bfc1508d (kx 2023-03-24 03:55:33 +0300  60) 
bfc1508d (kx 2023-03-24 03:55:33 +0300  61)   strbuf_addf( sb, "<pre><code class='language-Diff'>" );
bfc1508d (kx 2023-03-24 03:55:33 +0300  62) 
bfc1508d (kx 2023-03-24 03:55:33 +0300  63)   if( co_prefix )
bfc1508d (kx 2023-03-24 03:55:33 +0300  64)   {
c7693c71 (kx 2023-04-12 19:21:06 +0300  65)     char repo_path[PATH_MAX] = { 0 };
c7693c71 (kx 2023-04-12 19:21:06 +0300  66)     char cmd[PATH_MAX];
bfc1508d (kx 2023-03-24 03:55:33 +0300  67)     struct strbuf buf = STRBUF_INIT;
bfc1508d (kx 2023-03-24 03:55:33 +0300  68)     char  *raw = NULL;
bfc1508d (kx 2023-03-24 03:55:33 +0300  69)     pid_t  p = (pid_t) -1;
bfc1508d (kx 2023-03-24 03:55:33 +0300  70)     int    rc;
bfc1508d (kx 2023-03-24 03:55:33 +0300  71) 
c7693c71 (kx 2023-04-12 19:21:06 +0300  72)     if( repo_root && *repo_root )
c7693c71 (kx 2023-04-12 19:21:06 +0300  73)     {
c7693c71 (kx 2023-04-12 19:21:06 +0300  74)       strcat( (char *)&repo_path[0], repo_root );
c7693c71 (kx 2023-04-12 19:21:06 +0300  75)       strcat( (char *)&repo_path[0], "/" );
c7693c71 (kx 2023-04-12 19:21:06 +0300  76)     }
c7693c71 (kx 2023-04-12 19:21:06 +0300  77)     strcat( (char *)&repo_path[0], name );
c7693c71 (kx 2023-04-12 19:21:06 +0300  78) 
bfc1508d (kx 2023-03-24 03:55:33 +0300  79)     snprintf( (char *)&cmd[0], 1024,
bfc1508d (kx 2023-03-24 03:55:33 +0300  80)               "svn diff --revision %d:%d %s/%s/%s 2>/dev/null",
c7693c71 (kx 2023-04-12 19:21:06 +0300  81)               revision-1, revision, co_prefix, (char *)&repo_path[0], relative_path );
bfc1508d (kx 2023-03-24 03:55:33 +0300  82)     p = sys_exec_command( &buf, cmd );
bfc1508d (kx 2023-03-24 03:55:33 +0300  83)     rc = sys_wait_command( p, NULL );
bfc1508d (kx 2023-03-24 03:55:33 +0300  84)     if( rc != 0 )
bfc1508d (kx 2023-03-24 03:55:33 +0300  85)     {
bfc1508d (kx 2023-03-24 03:55:33 +0300  86)       strbuf_release( &buf );
bfc1508d (kx 2023-03-24 03:55:33 +0300  87)       return;
bfc1508d (kx 2023-03-24 03:55:33 +0300  88)     }
bfc1508d (kx 2023-03-24 03:55:33 +0300  89) 
bfc1508d (kx 2023-03-24 03:55:33 +0300  90)     raw = strbuf_detach( &buf, NULL );
bfc1508d (kx 2023-03-24 03:55:33 +0300  91)     strbuf_addstr_xml_quoted( &buf, (const char *)raw );
bfc1508d (kx 2023-03-24 03:55:33 +0300  92)     free( raw );
bfc1508d (kx 2023-03-24 03:55:33 +0300  93) 
bfc1508d (kx 2023-03-24 03:55:33 +0300  94)     strbuf_addbuf( sb, (const struct strbuf *)&buf );
bfc1508d (kx 2023-03-24 03:55:33 +0300  95)     strbuf_release( &buf );
bfc1508d (kx 2023-03-24 03:55:33 +0300  96)   }
bfc1508d (kx 2023-03-24 03:55:33 +0300  97) 
bfc1508d (kx 2023-03-24 03:55:33 +0300  98)   strbuf_addstr( sb, "\n</code></pre>\n" );
bfc1508d (kx 2023-03-24 03:55:33 +0300  99) 
bfc1508d (kx 2023-03-24 03:55:33 +0300 100)   return;
bfc1508d (kx 2023-03-24 03:55:33 +0300 101) }
bfc1508d (kx 2023-03-24 03:55:33 +0300 102) 
bfc1508d (kx 2023-03-24 03:55:33 +0300 103) void csvn_print_diff_page( void )
bfc1508d (kx 2023-03-24 03:55:33 +0300 104) {
bfc1508d (kx 2023-03-24 03:55:33 +0300 105)   FILE  *fp;
bfc1508d (kx 2023-03-24 03:55:33 +0300 106)   struct strbuf buf = STRBUF_INIT;
bfc1508d (kx 2023-03-24 03:55:33 +0300 107) 
bfc1508d (kx 2023-03-24 03:55:33 +0300 108)   fp = xfopen( ctx.page.header, "r" );
bfc1508d (kx 2023-03-24 03:55:33 +0300 109)   (void)strbuf_env_fread( &buf, fp );
bfc1508d (kx 2023-03-24 03:55:33 +0300 110)   fclose( fp );
bfc1508d (kx 2023-03-24 03:55:33 +0300 111) 
bfc1508d (kx 2023-03-24 03:55:33 +0300 112)   strbuf_addf( &buf, "        <div class=\"content segment\">\n" );
bfc1508d (kx 2023-03-24 03:55:33 +0300 113)   strbuf_addf( &buf, "          <div class=\"container\">\n" );
bfc1508d (kx 2023-03-24 03:55:33 +0300 114)   strbuf_addf( &buf, "            <div class=\"csvn-main-content\">\n" );
bfc1508d (kx 2023-03-24 03:55:33 +0300 115) 
bfc1508d (kx 2023-03-24 03:55:33 +0300 116)   if( ctx.repo.name )
bfc1508d (kx 2023-03-24 03:55:33 +0300 117)   {
bfc1508d (kx 2023-03-24 03:55:33 +0300 118)     if( ctx.query.rev )
bfc1508d (kx 2023-03-24 03:55:33 +0300 119)     {
bfc1508d (kx 2023-03-24 03:55:33 +0300 120)       csvn_print_diff( &buf, ctx.repo.relative_path, ctx.query.rev );
bfc1508d (kx 2023-03-24 03:55:33 +0300 121)     }
bfc1508d (kx 2023-03-24 03:55:33 +0300 122)     else
bfc1508d (kx 2023-03-24 03:55:33 +0300 123)     {
bfc1508d (kx 2023-03-24 03:55:33 +0300 124)       strbuf_addf( &buf, "              <h1>Requested diff cannot be shown</h1>\n" );
bfc1508d (kx 2023-03-24 03:55:33 +0300 125)       strbuf_addf( &buf, "              <p class='leading'>Revision for diff operation is not defined.</p>\n" );
bfc1508d (kx 2023-03-24 03:55:33 +0300 126)     }
bfc1508d (kx 2023-03-24 03:55:33 +0300 127)   }
bfc1508d (kx 2023-03-24 03:55:33 +0300 128)   else
bfc1508d (kx 2023-03-24 03:55:33 +0300 129)   {
bfc1508d (kx 2023-03-24 03:55:33 +0300 130)     strbuf_addf( &buf, "              <h1>Requested resource cannot be shown</h1>\n" );
bfc1508d (kx 2023-03-24 03:55:33 +0300 131)     strbuf_addf( &buf, "              <p class='leading'>Repository '%s' not found.</p>\n", ctx.repo.name );
bfc1508d (kx 2023-03-24 03:55:33 +0300 132)   }
bfc1508d (kx 2023-03-24 03:55:33 +0300 133) 
bfc1508d (kx 2023-03-24 03:55:33 +0300 134)   strbuf_addf( &buf, "            </div> <!-- End of csvn-main-content -->\n" );
bfc1508d (kx 2023-03-24 03:55:33 +0300 135)   strbuf_addf( &buf, "          </div> <!-- End of container -->\n" );
bfc1508d (kx 2023-03-24 03:55:33 +0300 136)   strbuf_addf( &buf, "        </div> <!-- End of content segment -->\n" );
bfc1508d (kx 2023-03-24 03:55:33 +0300 137) 
bfc1508d (kx 2023-03-24 03:55:33 +0300 138)   fp = xfopen( ctx.page.footer, "r" );
bfc1508d (kx 2023-03-24 03:55:33 +0300 139)   (void)strbuf_env_fread( &buf, fp );
bfc1508d (kx 2023-03-24 03:55:33 +0300 140)   fclose( fp );
bfc1508d (kx 2023-03-24 03:55:33 +0300 141) 
bfc1508d (kx 2023-03-24 03:55:33 +0300 142)   ctx.page.size = buf.len;
bfc1508d (kx 2023-03-24 03:55:33 +0300 143)   csvn_print_http_headers();
bfc1508d (kx 2023-03-24 03:55:33 +0300 144)   strbuf_write( &buf, STDOUT_FILENO );
bfc1508d (kx 2023-03-24 03:55:33 +0300 145)   strbuf_release( &buf );
bfc1508d (kx 2023-03-24 03:55:33 +0300 146) }