summaryrefslogtreecommitdiff
path: root/csvncgi/csvn-cgi.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/csvn-cgi.c
parentc836ae3775cf72f17e0b7e3792d156fdb389bee3 (diff)
downloadcsvn-ui-bfc1508d26c89c9a36d2d9a827fe2c4ed128884d.tar.xz
Version 0.1.4
Diffstat (limited to 'csvncgi/csvn-cgi.c')
-rw-r--r--csvncgi/csvn-cgi.c266
1 files changed, 266 insertions, 0 deletions
diff --git a/csvncgi/csvn-cgi.c b/csvncgi/csvn-cgi.c
new file mode 100644
index 0000000..3a2688b
--- /dev/null
+++ b/csvncgi/csvn-cgi.c
@@ -0,0 +1,266 @@
+
+#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>
+
+#define _GNU_SOURCE
+#include <getopt.h>
+
+#include <nls.h>
+
+#include <defs.h>
+#include <cscm/bcf.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>
+#include <ui-file.h>
+#include <ui-tree.h>
+#include <ui-diff.h>
+#include <ui-blame.h>
+#include <ui-log.h>
+
+
+static void free_resources( void )
+{
+ if( config ) free_config();
+}
+
+int main( int argc, char *argv[] )
+{
+
+ __mctx_init();
+
+ setlocale( LC_ALL, "" );
+#if ENABLE_NLS == 1
+ bindtextdomain( PACKAGE, LOCALEDIR );
+ textdomain( PACKAGE );
+#endif
+
+ csvn_prepare_context();
+
+ /************************
+ define error handlers:
+ */
+ system_fatal = fatal_html;
+ wrapper_fatal = fatal_html;
+ dlist_fatal = fatal_html;
+ rlist_fatal = fatal_html;
+ http_fatal = fatal_html;
+ html_fatal = fatal_html;
+
+ if( !(config = read_config()) )
+ {
+ fatal_html( "cannot read config file: /dev/shm%s", CSVN_SHM_BCF );
+ free_resources();
+ exit( 1 );
+ }
+
+ csvn_parse_query();
+
+ csvn_prepare_template_variables();
+
+ if( ctx.page.status == 404 )
+ {
+ csvn_print_404_page();
+ csvn_release_template_variables();
+ free_resources();
+ return 0;
+ }
+
+ if( !strcmp( ctx.vars.page_type, ptype_repolist ) )
+ {
+ if( ctx.query.search && *ctx.query.search )
+ {
+ csvn_search_repo( ctx.query.search );
+ }
+ csvn_print_repolist_page();
+ }
+ else if( !strcmp( ctx.vars.page_type, ptype_repo ) )
+ {
+ if( ctx.query.operation && *ctx.query.operation && !strcmp( ctx.query.operation, "diff" ) )
+ {
+ csvn_print_diff_page();
+ }
+ else if( ctx.query.operation && *ctx.query.operation && !strcmp( ctx.query.operation, "log" ) )
+ {
+ csvn_print_log_page();
+ }
+ else if( ctx.repo.relative_info.kind == KIND_FILE )
+ {
+ if( ctx.query.operation && *ctx.query.operation && !strcmp( ctx.query.operation, "blame" ) )
+ {
+ csvn_print_blame_page();
+ }
+ else
+ {
+ csvn_print_file_page();
+ }
+ }
+ else if( ctx.repo.relative_info.kind == KIND_DIR )
+ {
+ csvn_print_tree_page();
+ }
+ else
+ {
+ csvn_print_repolist_page();
+ }
+ }
+
+#if 0
+ {
+ struct strbuf buf = STRBUF_INIT;
+
+ strbuf_addf( &buf, " <div class=\"content segment\">\n" );
+ strbuf_addf( &buf, " <div class=\"container\">\n" );
+ strbuf_addf( &buf, " <div class=\"csvn-main-content\">\n" );
+
+ strbuf_addf( &buf, "<pre><code class='language-text'>HTTP_HOST = %s\n", ctx.env.http_host );
+ strbuf_addf( &buf, "HTTPS = %s\n", ctx.env.https );
+ strbuf_addf( &buf, "NO_HTTP = %s\n", ctx.env.no_http );
+ strbuf_addf( &buf, "PATH_INFO = %s\n", ctx.env.path_info );
+ strbuf_addf( &buf, "QUERY_STRING = %s\n", ctx.env.query_string );
+ strbuf_addf( &buf, "REQUEST_URI = %s\n", ctx.env.request_uri );
+ strbuf_addf( &buf, "REQUEST_SCHEME = %s\n", ctx.env.request_scheme );
+ strbuf_addf( &buf, "REQUEST_METHOD = %s\n", ctx.env.request_method );
+ strbuf_addf( &buf, "SCRIPT_NAME = %s\n", ctx.env.script_name );
+ strbuf_addf( &buf, "SERVER_NAME = %s\n", ctx.env.server_name );
+ strbuf_addf( &buf, "SERVER_PORT = %s\n", ctx.env.server_port );
+ strbuf_addf( &buf, "HTTP_COOKIE = %s\n", ctx.env.http_cookie );
+ strbuf_addf( &buf, "CONTENT_LENGTH = %d\n", ctx.env.content_lenght );
+ strbuf_addf( &buf, "HTTP_ROOT = %s\n", ctx.env.http_root );
+
+ strbuf_addf( &buf, "\naddition:\n" );
+ strbuf_addf( &buf, "DOCUMENT_ROOT = %s\n", getenv("DOCUMENT_ROOT") );
+ strbuf_addf( &buf, "DOCUMENT_URI = %s\n", getenv("DOCUMENT_URI") );
+ strbuf_addf( &buf, "PATH_TRANSLATED = %s\n", getenv("PATH_TRANSLATED") );
+ strbuf_addf( &buf, "SERVER_SOFTWARE = %s\n", getenv("SERVER_SOFTWARE") );
+ strbuf_addf( &buf, "SERVER_PROTOCOL = %s\n", getenv("SERVER_PROTOCOL") );
+ strbuf_addf( &buf, "SERVER_ADDR = %s\n", getenv("SERVER_ADDR") );
+ strbuf_addf( &buf, "REMOTE_ADDR = %s\n", getenv("REMOTE_ADDR") );
+ strbuf_addf( &buf, "GATEWAY_INTERFACE = %s\n", getenv("GATEWAY_INTERFACE") );
+ strbuf_addf( &buf, "SERVER_PROTOCOL = %s\n", getenv("SERVER_PROTOCOL") );
+
+ strbuf_addf( &buf, "\nctx:\n" );
+ strbuf_addf( &buf, "ctx.query.ofs = %d;\n", ctx.query.ofs );
+ strbuf_addf( &buf, "ctx.query.rev = %d;\n", ctx.query.rev );
+ strbuf_addf( &buf, "ctx.query.revision = '%s';\n", ctx.query.revision );
+ strbuf_addf( &buf, "ctx.query.operation = '%s';\n", ctx.query.operation );
+ strbuf_addf( &buf, "ctx.query.search = '%s';\n", ctx.query.search );
+ strbuf_addf( &buf, "\n" );
+ strbuf_addf( &buf, "ctx.repo.name = %s\n", ctx.repo.name );
+ strbuf_addf( &buf, "ctx.repo.info = {\n" );
+ switch( ctx.repo.info.kind )
+ {
+ case KIND_DIR:
+ strbuf_addf( &buf, " kind = '%s';\n", "dir" );
+ break;
+ case KIND_FILE:
+ strbuf_addf( &buf, " kind = '%s';\n", "file" );
+ break;
+ default:
+ strbuf_addf( &buf, " kind = '%s';\n", "unknown" );
+ break;
+ }
+ strbuf_addf( &buf, " revision = %d;\n", ctx.repo.info.revision );
+ strbuf_addf( &buf, " author = '%s';\n", ctx.repo.info.author );
+ strbuf_addf( &buf, " date = %"PRIdMAX";\n", ctx.repo.info.date );
+ strbuf_addf( &buf, " mime = '%s';\n", ctx.repo.info.mime );
+ strbuf_addf( &buf, " lang = '%s';\n", ctx.repo.info.lang );
+ strbuf_addf( &buf, "}\n" );
+
+ strbuf_addf( &buf, "ctx.repo.relative_path = %s\n", ctx.repo.relative_path );
+ strbuf_addf( &buf, "ctx.repo.relative_info = {\n" );
+ switch( ctx.repo.relative_info.kind )
+ {
+ case KIND_DIR:
+ strbuf_addf( &buf, " kind = '%s';\n", "dir" );
+ break;
+ case KIND_FILE:
+ strbuf_addf( &buf, " kind = '%s';\n", "file" );
+ break;
+ default:
+ strbuf_addf( &buf, " kind = '%s';\n", "unknown" );
+ break;
+ }
+ strbuf_addf( &buf, " revision = %d;\n", ctx.repo.relative_info.revision );
+ strbuf_addf( &buf, " author = '%s';\n", ctx.repo.relative_info.author );
+ strbuf_addf( &buf, " date = %"PRIdMAX";\n", ctx.repo.relative_info.date );
+ strbuf_addf( &buf, " mime = '%s';\n", ctx.repo.relative_info.mime );
+ strbuf_addf( &buf, " lang = '%s';\n", ctx.repo.relative_info.lang );
+ strbuf_addf( &buf, "}\n" );
+
+ strbuf_addf( &buf, "ctx.repo.relative_href = %s\n", ctx.repo.relative_href );
+ strbuf_addf( &buf, "ctx.repo.relative_html = %s\n", ctx.repo.relative_html );
+
+ strbuf_addf( &buf, "ctx.repo.trunk = %s\n", ctx.repo.trunk );
+ strbuf_addf( &buf, "ctx.repo.branches = %s\n", ctx.repo.branches );
+ strbuf_addf( &buf, "ctx.repo.tags = %s\n", ctx.repo.tags );
+ strbuf_addf( &buf, "ctx.repo.checkout_ro_prefix = %s\n", ctx.repo.checkout_ro_prefix );
+ strbuf_addf( &buf, "ctx.repo.checkout_prefix = %s\n", ctx.repo.checkout_prefix );
+ strbuf_addf( &buf, "ctx.repo.nbranches = %d\n", ctx.repo.nbranches );
+ strbuf_addf( &buf, "ctx.repo.ntags = %d\n", ctx.repo.ntags );
+
+ strbuf_addf( &buf, "ctx.vers.subversion = %s\n", ctx.vers.subversion );
+ strbuf_addf( &buf, "ctx.vers.nginx = %s\n", ctx.vers.nginx );
+ strbuf_addf( &buf, "ctx.vers.csvn = %s\n", ctx.vers.csvn );
+
+ strbuf_addf( &buf, "</code></pre>\n" );
+
+ print_config( &buf, config );
+
+ 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" );
+
+ ctx.page.size = buf.len;
+
+ strbuf_write( &buf, STDOUT_FILENO );
+ strbuf_release( &buf );
+ }
+#endif
+
+ csvn_release_template_variables();
+ free_resources();
+
+ return 0;
+}