aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt12
-rw-r--r--src/build.c9
-rw-r--r--src/config.c35
-rw-r--r--src/config.h4
-rw-r--r--src/context.c18
-rw-r--r--src/context.h2
-rw-r--r--src/parser.c35
-rw-r--r--src/ui.c25
8 files changed, 75 insertions, 65 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9f7e945..61606ba 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -21,13 +21,17 @@ list(APPEND
)
set(CFLAGS
- -Wall -Wextra -pedantic
- -Wconversion -Wshadow -Wstrict-aliasing
- -Winit-self -Wcast-align -Wpointer-arith
- -Wmissing-declarations -Wmissing-include-dirs
+ -Wall -Wextra -Wfloat-equal
+ -Wstrict-overflow=5 -Wunreachable-code
+ -Wundef -Wcast-qual -Wconversion
+ -Wswitch-default -Wmissing-include-dirs
+ -Wshadow -Wstrict-aliasing -Winit-self
+ -Wcast-align -Wpointer-arith
-Wno-unused-parameter -Wuninitialized
)
+
+
set(CMAKE_EXECUTABLE_SUFFIX ".cgi")
add_executable(${CMAKE_PROJECT_NAME} ${SOURCES})
diff --git a/src/build.c b/src/build.c
index 0c4214f..8d7f369 100644
--- a/src/build.c
+++ b/src/build.c
@@ -4,6 +4,7 @@
#include <string.h>
#include <stdio.h>
#include <math.h>
+#include <inttypes.h>
#include "config.h"
#include "fs.h"
@@ -59,10 +60,10 @@ void create_build()
if (!current_project)
return;
- int build_id = 0;
+ uintmax_t build_id = 0;
if (current_project->build_count > 0)
- build_id = atoi(current_project->builds[0].name)+1;
+ build_id = strtoumax(current_project->builds[0].name, NULL, 10)+1;
if (build_id <= 0)
build_id = 1;
@@ -74,7 +75,7 @@ void create_build()
build.status = STATUS_INPROGRESS;
size_t name_len = 1;
- int temp = build_id;
+ uintmax_t temp = build_id;
while (temp > 10)
{
@@ -83,7 +84,7 @@ void create_build()
}
build.name = malloc((name_len + 1) * sizeof(char));
- sprintf(build.name, "%d", build_id);
+ sprintf(build.name, "%ld", build_id);
write_build(current_project->name, build.name, &build);
diff --git a/src/config.c b/src/config.c
index 4eb5621..06d82f4 100644
--- a/src/config.c
+++ b/src/config.c
@@ -29,9 +29,10 @@ struct build_t* current_build = NULL;
void init_config()
{
- config.cache_dir = NULL;
+ config.path_prefix = NULL;
config.token = NULL;
- config.projects = malloc(1);
+
+ config.projects = NULL;
config.project_count = 0;
parse_config();
@@ -67,34 +68,26 @@ void init_config()
void deinit_config()
{
- if (config.cache_dir)
- free(config.cache_dir);
-
- if (config.token)
- free(config.token);
+ free(config.path_prefix);
+ free(config.token);
if (config.projects)
{
for (size_t i = 0; i < config.project_count; ++i)
{
- if (config.projects[i].name)
- free(config.projects[i].name);
+ free(config.projects[i].name);
- if (config.projects[i].script_path)
- free(config.projects[i].script_path);
+ free(config.projects[i].script_path);
- if (config.projects[i].description)
- free(config.projects[i].description);
+ free(config.projects[i].description);
if (config.projects[i].builds)
{
for (size_t j = 0; j < config.projects[i].build_count; ++j)
{
- if (config.projects[i].builds[j].name)
- free(config.projects[i].builds[j].name);
+ free(config.projects[i].builds[j].name);
- if (config.projects[i].builds[j].log)
- free(config.projects[i].builds[j].log);
+ free(config.projects[i].builds[j].log);
}
free(config.projects[i].builds);
@@ -130,10 +123,10 @@ char* project_dir(char* project)
if (!cache)
return cache;
- size_t size = strlen(cache) + 1 + strlen(project) ;
- cache = realloc(cache, size+1);
- strncat(cache, "/", size);
- strncat(cache, project, size);
+ size_t size = strlen(cache) + 1 + strlen(project) + 1;
+ cache = realloc(cache, size);
+ strncat(cache, "/", size - strlen(cache) - 1);
+ strncat(cache, project, size - strlen(cache) - 1);
cache[size] = '\0';
return cache;
diff --git a/src/config.h b/src/config.h
index 8cc27a0..6997c03 100644
--- a/src/config.h
+++ b/src/config.h
@@ -25,14 +25,16 @@ struct project_t {
char* name;
char* script_path;
char* description;
+ char* token;
struct build_t* builds;
size_t build_count;
};
struct config_t {
- char* cache_dir;
+ char* path_prefix;
char* token;
+
struct project_t* projects;
size_t project_count;
};
diff --git a/src/context.c b/src/context.c
index 4b99bea..c8f36e1 100644
--- a/src/context.c
+++ b/src/context.c
@@ -1,3 +1,6 @@
+#include <stdlib.h>
+#include <string.h>
+
#include "env.h"
#include "parser.h"
#include "context.h"
@@ -6,9 +9,11 @@ struct context_t context;
void init_context()
{
- context.document_root = getenv_default("DOCUMENT_ROOT", "/");
- context.raw_path = getenv_default("PATH_INFO", "/");
- context.path = malloc(1);
+ context.raw_path = getenv("PATH_INFO");
+ if (!context.raw_path || !strlen(context.raw_path))
+ context.raw_path = getenv_default("SCRIPT_NAME", "/");
+
+ context.path = NULL;
context.path_length = 0;
context.project = NULL;
@@ -55,13 +60,10 @@ void deinit_context()
{
for (size_t i = 0; i < context.path_length; ++i)
{
- if (context.path[i])
- free(context.path[i]);
+ free(context.path[i]);
}
free(context.path);
-
- if (context.token)
- free(context.token);
+ free(context.token);
}
}
diff --git a/src/context.h b/src/context.h
index 80c7e72..4d89497 100644
--- a/src/context.h
+++ b/src/context.h
@@ -5,8 +5,6 @@
#include <stdlib.h>
struct context_t {
- char* document_root;
-
char* raw_path;
char** path; /* NULLABLE */
diff --git a/src/parser.c b/src/parser.c
index f13cbe5..90705ce 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -74,7 +74,7 @@ void parse_config()
++tail;
}
- head = tail++;
+ head = ++tail;
continue;
}
else if (*tail == '=')
@@ -97,16 +97,16 @@ void parse_config()
if (key && value)
{
- if (!strcmp(key, "cache-dir"))
- {
- assert(!config.cache_dir);
- config.cache_dir = strdup(value);
- }
if (!strcmp(key, "token"))
{
- assert(!config.token);
+ free(config.token);
config.token = strdup(value);
}
+ else if (!strcmp(key, "path-prefix"))
+ {
+ free(config.path_prefix);
+ config.path_prefix = strdup(value);
+ }
else if (!strcmp(key, "project.name"))
{
++config.project_count;
@@ -117,14 +117,13 @@ void parse_config()
config.projects[config.project_count-1].name = strdup(value);
config.projects[config.project_count-1].script_path = NULL;
config.projects[config.project_count-1].description = NULL;
+ config.projects[config.project_count-1].token = NULL;
}
else if (!strcmp(key, "project.script"))
{
if (config.project_count > 0)
{
- if (config.projects[config.project_count-1].script_path)
- free(config.projects[config.project_count-1].script_path);
-
+ free(config.projects[config.project_count-1].script_path);
config.projects[config.project_count-1].script_path = strdup(value);
}
}
@@ -132,12 +131,18 @@ void parse_config()
{
if (config.project_count > 0)
{
- if (config.projects[config.project_count-1].description)
- free(config.projects[config.project_count-1].description);
-
+ free(config.projects[config.project_count-1].description);
config.projects[config.project_count-1].description = strdup(value);
}
}
+ else if (!strcmp(key, "project.token"))
+ {
+ if (config.project_count > 0)
+ {
+ free(config.projects[config.project_count-1].token);
+ config.projects[config.project_count-1].token = strdup(value);
+ }
+ }
key = NULL;
value = NULL;
@@ -265,9 +270,6 @@ void load_full_build(struct project_t* project, struct build_t* build)
void parse_path(const char* path)
{
- size_t path_len = strlen(path) + 1;
- const char* const orig_path = path;
-
if (path[0] != '/')
return;
@@ -275,7 +277,6 @@ void parse_path(const char* path)
while(*path)
{
- assert(orig_path+path_len >= path);
++path;
if (*path == '/' || *path == '\0')
{
diff --git a/src/ui.c b/src/ui.c
index 027e5de..fdfc945 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -57,7 +57,11 @@ void print_html()
}
else if (!strcmp(context.action, "trigger"))
{
- if (context.token && config.token && !strcmp(context.token, config.token))
+ char* token = current_project->token;
+ if (!token)
+ token = config.token;
+
+ if (context.token && token && !strcmp(context.token, token))
{
create_build();
@@ -119,7 +123,7 @@ void print_head()
&& context.token && config.token && !strcmp(context.token, config.token))
printf("<meta http-equiv=\"refresh\" content=\"0; url=/%s\"/>", current_project->name);
- printf("<link rel=\"stylesheet\" type=\"text/css\" href=\"/assets/base.css\"/>");
+ printf("<link rel=\"stylesheet\" type=\"text/css\" href=\"%s/assets/base.css\"/>", config.path_prefix ? config.path_prefix : "");
printf("</head>");
}
@@ -127,11 +131,14 @@ void print_title()
{
printf("<h1 class=\"title\">");
- printf("<a %s>CGCI</a>", context.project != NULL ? "href=\"/\"" : "");
+ printf("<a ");
+ if (context.project)
+ printf("href=%s/", config.path_prefix ? config.path_prefix : "");
+ printf(">CGCI</a>");
if (context.project)
{
- printf(" : <a href=\"/%s\">%s</a>", context.project, context.project);
+ printf(" : <a href=\"%s/%s\">%s</a>", config.path_prefix ? config.path_prefix : "", context.project, context.project);
if (context.action)
{
printf(" : %s", context.action);
@@ -152,7 +159,7 @@ void print_build_nav()
current_project->name
);
- if (config.token && current_project->script_path && strlen(current_project->script_path))
+ if ((config.token || current_project->token) && current_project->script_path && strlen(current_project->script_path))
{
printf(
"<td class=\"align-right\">"
@@ -296,11 +303,12 @@ void print_project_nav()
"<tbody>"
"<tr>"
"<td>"
- "<a href=\"/\" class=\"active\">Projects</a>"
+ "<a href=\"%s/\" class=\"active\">Projects</a>"
"</td>"
"</tr>"
"</tbody>"
- "</table>"
+ "</table>",
+ config.path_prefix ? config.path_prefix : ""
);
}
@@ -339,13 +347,14 @@ void print_project_list()
printf(
"<tr>"
"<td>"
- "<a href=\"/%s\">%s</a>"
+ "<a href=\"%s/%s\">%s</a>"
"</td>"
"<td>%s</td>"
"<td>%s</td>"
"<td>%s</td>"
"<td class=\"%s\">%s</td>"
"</tr>",
+ config.path_prefix ? config.path_prefix : "",
project->name, project->name,
project->description ? project->description : "",
time, buildtime,