diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2019-09-02 23:38:48 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2019-09-02 23:51:15 +0200 |
commit | 4763814c683c50f8a3697b74e764f19c3dacccd5 (patch) | |
tree | 386ff43f024705a32310b882f2161b5f86d8820a /src/blogc-git-receiver | |
parent | c12bdb94ecdc44f200a8030dfde4a5ec46053ea6 (diff) | |
download | blogc-feature/squareball.tar.gz blogc-feature/squareball.tar.bz2 blogc-feature/squareball.zip |
migrate codebase to use squareball. again :)feature/squareball
Diffstat (limited to 'src/blogc-git-receiver')
-rw-r--r-- | src/blogc-git-receiver/post-receive.c | 18 | ||||
-rw-r--r-- | src/blogc-git-receiver/pre-receive-parser.c | 5 | ||||
-rw-r--r-- | src/blogc-git-receiver/pre-receive.c | 53 | ||||
-rw-r--r-- | src/blogc-git-receiver/settings.c | 40 | ||||
-rw-r--r-- | src/blogc-git-receiver/settings.h | 6 | ||||
-rw-r--r-- | src/blogc-git-receiver/shell-command-parser.c | 13 | ||||
-rw-r--r-- | src/blogc-git-receiver/shell.c | 13 |
7 files changed, 74 insertions, 74 deletions
diff --git a/src/blogc-git-receiver/post-receive.c b/src/blogc-git-receiver/post-receive.c index 17a8aa7..5cdd0ce 100644 --- a/src/blogc-git-receiver/post-receive.c +++ b/src/blogc-git-receiver/post-receive.c @@ -12,8 +12,8 @@ #include <libgen.h> #include <unistd.h> #include <stdlib.h> -#include "../common/utils.h" -#include "../common/config-parser.h" +#include <squareball.h> + #include "settings.h" #include "post-receive.h" @@ -32,7 +32,7 @@ bgr_post_receive_hook(int argc, char *argv[]) return 1; } - 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"); @@ -47,11 +47,11 @@ 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; } - bc_config_t *config = bgr_settings_parse(); + sb_config_t *config = bgr_settings_parse(); if (config == NULL) { fprintf(stderr, "warning: repository mirroring disabled\n"); goto cleanup; @@ -60,13 +60,13 @@ bgr_post_receive_hook(int argc, char *argv[]) char *section = bgr_settings_get_section(config, repo_path); if (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, section, "mirror")); + mirror = sb_strdup(sb_config_get(config, section, "mirror")); free(section); - bc_config_free(config); + sb_config_free(config); if (mirror == NULL) { fprintf(stderr, "warning: repository mirroring disabled\n"); @@ -76,7 +76,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/pre-receive-parser.c b/src/blogc-git-receiver/pre-receive-parser.c index fb4c4d5..0e18ae7 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 03b5b21..69fec27 100644 --- a/src/blogc-git-receiver/pre-receive.c +++ b/src/blogc-git-receiver/pre-receive.c @@ -15,9 +15,8 @@ #include <dirent.h> #include <time.h> #include <libgen.h> -#include "../common/compat.h" -#include "../common/utils.h" -#include "../common/stdin.h" +#include <squareball.h> + #include "settings.h" #include "pre-receive-parser.h" #include "pre-receive.h" @@ -58,7 +57,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)); @@ -106,7 +105,7 @@ bgr_pre_receive_hook(int argc, char *argv[]) return 1; } - 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"); @@ -114,33 +113,33 @@ bgr_pre_receive_hook(int argc, char *argv[]) goto cleanup; } - bc_config_t *config = bgr_settings_parse(); + sb_config_t *config = bgr_settings_parse(); if (config == NULL) { goto default_sym; } char *section = bgr_settings_get_section(config, repo_dir); if (section == NULL) { - bc_config_free(config); + sb_config_free(config); goto default_sym; } - const char *sym_tmp = bc_config_get(config, section, "symlink"); + const char *sym_tmp = sb_config_get(config, section, "symlink"); if (sym_tmp == NULL) { free(section); - bc_config_free(config); + sb_config_free(config); goto default_sym; } - sym = bc_str_starts_with(sym_tmp, "/") ? bc_strdup(sym_tmp) : - bc_strdup_printf("%s/%s", repo_dir, sym_tmp); + sym = sb_str_starts_with(sym_tmp, "/") ? sb_strdup(sym_tmp) : + sb_strdup_printf("%s/%s", repo_dir, sym_tmp); free(section); - bc_config_free(config); + sb_config_free(config); default_sym: if (sym == NULL) { - sym = bc_strdup_printf("%s/htdocs", repo_dir); + sym = sb_strdup_printf("%s/htdocs", repo_dir); } if (NULL == getenv("GIT_DIR")) { @@ -157,20 +156,20 @@ default_sym: rv = 1; 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 = 1; 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); } @@ -188,7 +187,7 @@ default_sym: } 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 " @@ -214,12 +213,12 @@ default_sym: } unsigned long epoch = time(NULL); - output_dir = bc_strdup_printf("%s/%s-%lu", buildsd, master, epoch); + output_dir = sb_strdup_printf("%s/%s-%lu", buildsd, master, epoch); free(buildsd); 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); } @@ -228,24 +227,24 @@ default_sym: char *build_cmd = NULL; if (0 == access("blogcfile", F_OK)) { int status_bmake = system("blogc-make -v 2> /dev/null > /dev/null"); - if (127 == bc_compat_status_code(status_bmake)) { + if (127 == sb_compat_status_code(status_bmake)) { fprintf(stderr, "error: failed to find blogc-make binary\n"); rv = 1; 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))) { const char *make_impl = NULL; int status_gmake = system("gmake -f /dev/null 2> /dev/null > /dev/null"); - if (127 != bc_compat_status_code(status_gmake)) { + if (127 != sb_compat_status_code(status_gmake)) { make_impl = "gmake"; } else { int status_make = system("make -f /dev/null 2> /dev/null > /dev/null"); - if (127 != bc_compat_status_code(status_make)) { + if (127 != sb_compat_status_code(status_make)) { make_impl = "make"; } } @@ -255,7 +254,7 @@ default_sym: rv = 1; 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/settings.c b/src/blogc-git-receiver/settings.c index db29b18..6de1042 100644 --- a/src/blogc-git-receiver/settings.c +++ b/src/blogc-git-receiver/settings.c @@ -12,10 +12,8 @@ #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> + #include "settings.h" @@ -35,72 +33,72 @@ bgr_settings_get_builds_dir(void) { char *rv = getenv("BLOGC_GIT_RECEIVER_BUILDS_DIR"); if (rv != NULL) { - return bc_strdup(rv); + return sb_strdup(rv); } - return bc_strdup_printf("%s/builds", bgr_settings_get_base_dir()); + return sb_strdup_printf("%s/builds", bgr_settings_get_base_dir()); } char* -bgr_settings_get_section(bc_config_t *config, const char *repo_path) +bgr_settings_get_section(sb_config_t *config, const char *repo_path) { const char *bd = bgr_settings_get_base_dir(); if (bd == NULL) { return NULL; } 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", bd, sections[i] + 5); + if (sb_str_starts_with(sections[i], "repo:")) { + char *tmp_repo = sb_strdup_printf("%s/repos/%s", bd, 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; } -bc_config_t* +sb_config_t* bgr_settings_parse(void) { const char *bd = bgr_settings_get_base_dir(); if (bd == NULL) { return NULL; } - char *config_file = bc_strdup_printf("%s/blogc-git-receiver.ini", bd); + char *config_file = sb_strdup_printf("%s/blogc-git-receiver.ini", bd); if ((0 != access(config_file, F_OK))) { free(config_file); return NULL; } 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(config_file, &len, &err); if (err != NULL) { fprintf(stderr, "warning: failed to read configuration file (%s): %s\n", - config_file, err->msg); - bc_error_free(err); + config_file, sb_error_to_string(err)); + sb_error_free(err); free(config_file); free(config_content); return NULL; } - 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): %s\n", - config_file, err->msg); - bc_error_free(err); + config_file, sb_error_to_string(err)); + sb_error_free(err); free(config_file); return NULL; } diff --git a/src/blogc-git-receiver/settings.h b/src/blogc-git-receiver/settings.h index 04c1a2b..012dfaf 100644 --- a/src/blogc-git-receiver/settings.h +++ b/src/blogc-git-receiver/settings.h @@ -9,11 +9,11 @@ #ifndef _SETTINGS_H #define _SETTINGS_H -#include "../common/config-parser.h" +#include <squareball.h> const char* bgr_settings_get_base_dir(void); char* bgr_settings_get_builds_dir(void); -char* bgr_settings_get_section(bc_config_t *config, const char *repo_path); -bc_config_t* bgr_settings_parse(void); +char* bgr_settings_get_section(sb_config_t *config, const char *repo_path); +sb_config_t* bgr_settings_parse(void); #endif /* _SETTINGS_H */ diff --git a/src/blogc-git-receiver/shell-command-parser.c b/src/blogc-git-receiver/shell-command-parser.c index 0091e0b..2b99e33 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 a460ac2..a9e5c45 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 "settings.h" #include "shell-command-parser.h" #include "shell.h" @@ -62,15 +63,15 @@ bgr_shell(int argc, char *argv[]) goto cleanup; } - repo = bc_strdup_printf("%s/repos/%s", bd, tmp_repo); - quoted_repo = bc_shell_quote(repo); + repo = sb_strdup_printf("%s/repos/%s", bd, 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", @@ -147,9 +148,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 == ' ') |