aboutsummaryrefslogtreecommitdiffstats
path: root/src/blogc-git-receiver
diff options
context:
space:
mode:
Diffstat (limited to 'src/blogc-git-receiver')
-rw-r--r--src/blogc-git-receiver/main.c1
-rw-r--r--src/blogc-git-receiver/post-receive.c41
-rw-r--r--src/blogc-git-receiver/post-receive.h4
-rw-r--r--src/blogc-git-receiver/pre-receive-parser.c5
-rw-r--r--src/blogc-git-receiver/pre-receive.c32
-rw-r--r--src/blogc-git-receiver/shell-command-parser.c13
-rw-r--r--src/blogc-git-receiver/shell.c13
7 files changed, 55 insertions, 54 deletions
diff --git a/src/blogc-git-receiver/main.c b/src/blogc-git-receiver/main.c
index c18bb14..76d3bdb 100644
--- a/src/blogc-git-receiver/main.c
+++ b/src/blogc-git-receiver/main.c
@@ -9,6 +9,7 @@
#include <stdio.h>
#include <string.h>
#include <libgen.h>
+
#include "shell.h"
#include "pre-receive.h"
#include "post-receive.h"
diff --git a/src/blogc-git-receiver/post-receive.c b/src/blogc-git-receiver/post-receive.c
index 3593bb5..a422b43 100644
--- a/src/blogc-git-receiver/post-receive.c
+++ b/src/blogc-git-receiver/post-receive.c
@@ -12,34 +12,31 @@
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
-#include "../common/utils.h"
-#include "../common/config-parser.h"
-#include "../common/error.h"
-#include "../common/file.h"
+#include <squareball.h>
char*
-bgr_post_receive_get_config_section(bc_config_t *config, const char *repo_path,
+bgr_post_receive_get_config_section(sb_config_t *config, const char *repo_path,
const char *home)
{
char *rv = NULL;
- char** sections = bc_config_list_sections(config);
+ char** sections = sb_config_list_sections(config);
for (size_t i = 0; sections[i] != NULL; i++) {
- if (bc_str_starts_with(sections[i], "repo:")) {
- char *tmp_repo = bc_strdup_printf("%s/repos/%s", home, sections[i] + 5);
+ if (sb_str_starts_with(sections[i], "repo:")) {
+ char *tmp_repo = sb_strdup_printf("%s/repos/%s", home, sections[i] + 5);
char *real_tmp_repo = realpath(tmp_repo, NULL); // maybe not needed
free(tmp_repo);
if (real_tmp_repo == NULL)
continue;
if (0 == strcmp(real_tmp_repo, repo_path)) {
- rv = bc_strdup(sections[i]);
+ rv = sb_strdup(sections[i]);
free(real_tmp_repo);
break;
}
free(real_tmp_repo);
}
}
- bc_strv_free(sections);
+ sb_strv_free(sections);
return rv;
}
@@ -57,7 +54,7 @@ bgr_post_receive_hook(int argc, char *argv[])
return 3;
}
- char *repo_path = bc_strdup(dirname(real_hooks_dir));
+ char *repo_path = sb_strdup(dirname(real_hooks_dir));
free(real_hooks_dir);
if (0 != chdir(repo_path)) {
fprintf(stderr, "error: failed to change to repository root\n");
@@ -72,7 +69,7 @@ bgr_post_receive_hook(int argc, char *argv[])
if ((0 == system("git config --local remote.mirror.pushurl > /dev/null")) ||
(0 == system("git config --local remote.mirror.url > /dev/null")))
{
- mirror = bc_strdup("mirror");
+ mirror = sb_strdup("mirror");
goto push;
}
@@ -83,7 +80,7 @@ bgr_post_receive_hook(int argc, char *argv[])
goto cleanup;
}
- char *config_file = bc_strdup_printf("%s/blogc-git-receiver.ini", home);
+ char *config_file = sb_strdup_printf("%s/blogc-git-receiver.ini", home);
if ((0 != access(config_file, F_OK))) {
fprintf(stderr, "warning: repository mirroring disabled\n");
free(config_file);
@@ -91,23 +88,23 @@ bgr_post_receive_hook(int argc, char *argv[])
}
size_t len;
- bc_error_t *err = NULL;
- char* config_content = bc_file_get_contents(config_file, true, &len, &err);
+ sb_error_t *err = NULL;
+ char* config_content = sb_file_get_contents_utf8(config_file, &len, &err);
if (err != NULL) {
fprintf(stderr, "warning: failed to read configuration file (%s), "
"mirroring disabled: %s\n", config_file, err->msg);
- bc_error_free(err);
+ sb_error_free(err);
free(config_file);
free(config_content);
goto cleanup;
}
- bc_config_t *config = bc_config_parse(config_content, len, NULL, &err);
+ sb_config_t *config = sb_config_parse(config_content, len, NULL, &err);
free(config_content);
if (err != NULL) {
fprintf(stderr, "warning: failed to parse configuration file (%s), "
"mirroring disabled: %s\n", config_file, err->msg);
- bc_error_free(err);
+ sb_error_free(err);
free(config_file);
goto cleanup;
}
@@ -117,13 +114,13 @@ bgr_post_receive_hook(int argc, char *argv[])
home);
if (config_section == NULL) {
fprintf(stderr, "warning: repository mirroring disabled\n");
- bc_config_free(config);
+ sb_config_free(config);
goto cleanup;
}
- mirror = bc_strdup(bc_config_get(config, config_section, "mirror"));
+ mirror = sb_strdup(sb_config_get(config, config_section, "mirror"));
free(config_section);
- bc_config_free(config);
+ sb_config_free(config);
if (mirror == NULL) {
fprintf(stderr, "warning: repository mirroring disabled\n");
@@ -133,7 +130,7 @@ bgr_post_receive_hook(int argc, char *argv[])
push:
{
- char *git_cmd = bc_strdup_printf("git push --mirror %s", mirror);
+ char *git_cmd = sb_strdup_printf("git push --mirror %s", mirror);
if (0 != system(git_cmd))
fprintf(stderr, "warning: failed push to git mirror\n");
free(git_cmd);
diff --git a/src/blogc-git-receiver/post-receive.h b/src/blogc-git-receiver/post-receive.h
index 97f7c82..2b549b1 100644
--- a/src/blogc-git-receiver/post-receive.h
+++ b/src/blogc-git-receiver/post-receive.h
@@ -9,9 +9,9 @@
#ifndef _POST_RECEIVE_H
#define _POST_RECEIVE_H
-#include "../common/config-parser.h"
+#include <squareball.h>
-char* bgr_post_receive_get_config_section(bc_config_t *config,
+char* bgr_post_receive_get_config_section(sb_config_t *config,
const char *repo_path, const char *home);
int bgr_post_receive_hook(int argc, char *argv[]);
diff --git a/src/blogc-git-receiver/pre-receive-parser.c b/src/blogc-git-receiver/pre-receive-parser.c
index b379903..a335daa 100644
--- a/src/blogc-git-receiver/pre-receive-parser.c
+++ b/src/blogc-git-receiver/pre-receive-parser.c
@@ -8,7 +8,8 @@
#include <stdlib.h>
#include <string.h>
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "pre-receive-parser.h"
typedef enum {
@@ -67,7 +68,7 @@ bgr_pre_receive_parse(const char *input)
if ((current - start == 17) &&
(0 == strncmp("refs/heads/master", input + start, 17)))
{
- return bc_strndup(input + start_new, start - 1 - start_new);
+ return sb_strndup(input + start_new, start - 1 - start_new);
}
break;
}
diff --git a/src/blogc-git-receiver/pre-receive.c b/src/blogc-git-receiver/pre-receive.c
index e8ac1d3..b785e6d 100644
--- a/src/blogc-git-receiver/pre-receive.c
+++ b/src/blogc-git-receiver/pre-receive.c
@@ -15,8 +15,8 @@
#include <dirent.h>
#include <time.h>
#include <libgen.h>
-#include "../common/utils.h"
-#include "../common/stdin.h"
+#include <squareball.h>
+
#include "pre-receive-parser.h"
#include "pre-receive.h"
@@ -56,7 +56,7 @@ rmdir_recursive(const char *dir)
while (NULL != (e = readdir(d))) {
if ((0 == strcmp(e->d_name, ".")) || (0 == strcmp(e->d_name, "..")))
continue;
- char *f = bc_strdup_printf("%s/%s", dir, e->d_name);
+ char *f = sb_strdup_printf("%s/%s", dir, e->d_name);
if (0 != stat(f, &buf)) {
fprintf(stderr, "error: failed to stat directory entry (%s): %s\n",
e->d_name, strerror(errno));
@@ -102,7 +102,7 @@ bgr_pre_receive_hook(int argc, char *argv[])
return 3;
}
- char *repo_dir = bc_strdup(dirname(real_hooks_dir));
+ char *repo_dir = sb_strdup(dirname(real_hooks_dir));
free(real_hooks_dir);
if (0 != chdir(repo_dir)) {
fprintf(stderr, "error: failed to change to repository root\n");
@@ -111,7 +111,7 @@ bgr_pre_receive_hook(int argc, char *argv[])
}
if (NULL == getenv("GIT_DIR")) {
- char *htdocs_sym = bc_strdup_printf("%s/htdocs", repo_dir);
+ char *htdocs_sym = sb_strdup_printf("%s/htdocs", repo_dir);
if (0 != access(htdocs_sym, R_OK)) {
fprintf(stderr, "error: no previous build found. nothing to "
"rebuild.\n");
@@ -127,20 +127,20 @@ bgr_pre_receive_hook(int argc, char *argv[])
rv = 3;
goto cleanup;
}
- char **pieces = bc_str_split(basename(build_dir), '-', 2);
+ char **pieces = sb_str_split(basename(build_dir), '-', 2);
free(build_dir);
- if (bc_strv_length(pieces) != 2) {
+ if (sb_strv_length(pieces) != 2) {
fprintf(stderr, "error: failed to parse the hash of last built "
"commit.\n");
- bc_strv_free(pieces);
+ sb_strv_free(pieces);
rv = 3;
goto cleanup;
}
- master = bc_strdup(pieces[0]);
- bc_strv_free(pieces);
+ master = sb_strdup(pieces[0]);
+ sb_strv_free(pieces);
}
else {
- char *input = bc_stdin_read();
+ char *input = sb_stdin_get_contents();
master = bgr_pre_receive_parse(input);
free(input);
}
@@ -158,7 +158,7 @@ bgr_pre_receive_hook(int argc, char *argv[])
}
tmpdir = dir;
- char *git_archive_cmd = bc_strdup_printf(
+ char *git_archive_cmd = sb_strdup_printf(
"git archive \"%s\" | tar -x -C \"%s\" -f -", master, tmpdir);
if (0 != system(git_archive_cmd)) {
fprintf(stderr, "error: failed to extract git content to temporary "
@@ -184,11 +184,11 @@ bgr_pre_receive_hook(int argc, char *argv[])
}
unsigned long epoch = time(NULL);
- output_dir = bc_strdup_printf("%s/builds/%s-%lu", home, master, epoch);
+ output_dir = sb_strdup_printf("%s/builds/%s-%lu", home, master, epoch);
if (0 == access(output_dir, F_OK)) {
char *tmp = output_dir;
- output_dir = bc_strdup_printf("%s-", tmp);
+ output_dir = sb_strdup_printf("%s-", tmp);
free(tmp);
}
@@ -202,7 +202,7 @@ bgr_pre_receive_hook(int argc, char *argv[])
rv = 3;
goto cleanup;
}
- build_cmd = bc_strdup_printf("OUTPUT_DIR=\"%s\" blogc-make -V all",
+ build_cmd = sb_strdup_printf("OUTPUT_DIR=\"%s\" blogc-make -V all",
output_dir);
}
else if ((0 == access("Makefile", F_OK)) || (0 == access("GNUMakefile", F_OK))) {
@@ -224,7 +224,7 @@ bgr_pre_receive_hook(int argc, char *argv[])
rv = 3;
goto cleanup;
}
- build_cmd = bc_strdup_printf(
+ build_cmd = sb_strdup_printf(
"%s -j%d OUTPUT_DIR=\"%s\" BLOGC_GIT_RECEIVER=1", make_impl,
cpu_count(), output_dir);
}
diff --git a/src/blogc-git-receiver/shell-command-parser.c b/src/blogc-git-receiver/shell-command-parser.c
index 05a68fd..842c67a 100644
--- a/src/blogc-git-receiver/shell-command-parser.c
+++ b/src/blogc-git-receiver/shell-command-parser.c
@@ -9,7 +9,8 @@
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "shell-command-parser.h"
typedef enum {
@@ -28,7 +29,7 @@ bgr_shell_command_parse(const char *command)
size_t start = 0;
size_t command_len = strlen(command);
- bc_string_t *rv = bc_string_new();
+ sb_string_t *rv = sb_string_new();
for (size_t current = 0; current < command_len; current++) {
@@ -76,7 +77,7 @@ bgr_shell_command_parse(const char *command)
case START_ESCAPED:
if (c == '!' || c == '\'') {
- bc_string_append_c(rv, c);
+ sb_string_append_c(rv, c);
state = START_REPO;
break;
}
@@ -84,7 +85,7 @@ bgr_shell_command_parse(const char *command)
case REPO:
if (c == '\'') {
- bc_string_append_len(rv, command + start, current - start);
+ sb_string_append_len(rv, command + start, current - start);
state = START_REPO;
break;
}
@@ -93,9 +94,9 @@ bgr_shell_command_parse(const char *command)
}
if (rv->len > 0)
- return bc_string_free(rv, false);
+ return sb_string_free(rv, false);
error:
- bc_string_free(rv, true);
+ sb_string_free(rv, true);
return NULL;
}
diff --git a/src/blogc-git-receiver/shell.c b/src/blogc-git-receiver/shell.c
index 1ad8f20..8ed08d0 100644
--- a/src/blogc-git-receiver/shell.c
+++ b/src/blogc-git-receiver/shell.c
@@ -13,7 +13,8 @@
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "shell-command-parser.h"
#include "shell.h"
@@ -50,15 +51,15 @@ bgr_shell(int argc, char *argv[])
goto cleanup;
}
- repo = bc_strdup_printf("%s/repos/%s", home, tmp_repo);
- quoted_repo = bc_shell_quote(repo);
+ repo = sb_strdup_printf("%s/repos/%s", home, tmp_repo);
+ quoted_repo = sb_shell_quote(repo);
free(tmp_repo);
if (0 == strncmp(argv[2], "git-upload-", 11)) // no need to check len here
goto git_exec;
if (0 != access(repo, F_OK)) {
- char *git_init_cmd = bc_strdup_printf(
+ char *git_init_cmd = sb_strdup_printf(
"git init --bare %s > /dev/null", quoted_repo);
if (0 != system(git_init_cmd)) {
fprintf(stderr, "error: failed to create git repository: %s\n",
@@ -136,9 +137,9 @@ git_exec:
goto cleanup;
}
- // static allocation instead of bc_strdup_printf to avoid leaks
+ // static allocation instead of sb_strdup_printf to avoid leaks
char buffer[4096];
- char *command = bc_strdup(argv[2]);
+ char *command = sb_strdup(argv[2]);
char *p;
for (p = command; *p != ' ' && *p != '\0'; p++);
if (*p == ' ')